Tools: files

Tools for reading and editing the files of the working copy. Nothing they do is public until you publish the site.

Path and file rules

  • Name
    Paths
    Description

    Relative only, made of letters, digits and the characters ., _, - and /, for example index.html, css/styles.css, blog/first-post.html. No leading / and no ...

  • Name
    Text files
    Description

    html, css, js, json, xml, txt, svg, webmanifest. Up to 512 KB per file.

  • Name
    Binary files
    Description

    Images (png, jpg, jpeg, gif, webp, avif, ico) and fonts (woff, woff2). You store them with the tools from the Images group; they cannot be read with file_read.

  • Name
    Site limits
    Description
    Up to 50 MB and 500 files per site.

file_list

Lists the files of the working copy with their sizes in bytes, sorted by path. site_get already includes the full tree, so this tool is useful when you only need the file list or a single folder.

read-only, changes nothing

Parameters

  • slugtextrequired

    The site slug.

  • prefixtextoptional

    List only paths starting with this prefix, for example css/.

Example request to the assistant

Show the files in the css folder.

file_read

Reads the full content of one text file (html, css, js, json, xml, txt, svg, webmanifest) from the working copy. Images and fonts cannot be read. The assistant reads a file before changing it, so its edit matches the real content.

read-only, changes nothing

Parameters

  • slugtextrequired

    The site slug.

  • pathtextrequired

    A relative path inside the site, using only letters, digits and the characters . _ - and /, for example index.html, css/styles.css or blog/first-post.html. No leading / and no ...

Example request to the assistant

Read index.html and tell me which sections the site has.

file_write

Creates a file or replaces it completely with the given content. It is for new files and rewrites; for a small change to an existing file file_patch is better. Parent folders are created automatically.

Parameters

  • slugtextrequired

    The site slug.

  • pathtextrequired

    The relative path of the file, from the allowed characters (letters, digits, . _ - /).

  • contenttextrequired

    The complete new content of the file (not a diff).

  • Allowed text types: html, css, js, json, xml, txt, svg, webmanifest.
  • File size and total site size limits apply; the error message states the limit.
  • Your own sitemap.xml or robots.txt replaces the automatically generated version.

Example request to the assistant

Create a contact page, contact.html, with the phone number and address.

file_patch

Changes part of an existing text file by exact string replacement, like str_replace. The old text must occur in the file exactly once, character for character, including whitespace and line breaks. If it is not found or occurs several times, the file is left unchanged and the error gives the number of matches: add more surrounding text to make the fragment unambiguous.

Parameters

  • slugtextrequired

    The site slug.

  • pathtextrequired

    The relative path of the file to change.

  • oldTexttextrequired

    The exact existing text to replace. It must match exactly one place in the file.

  • newTexttextrequired

    The replacement text. May be empty, which deletes oldText.

  • An error with 0 matches usually means the text differs in whitespace or characters: the assistant should read the file first.

Example request to the assistant

Change the phone number in the header from 18 123 45 67 to 18 765 43 21.

file_delete

Deletes a file from the working copy. The public site does not change until the next publish, and earlier versions keep the file, so a rollback can bring it back.

Parameters

  • slugtextrequired

    The site slug.

  • pathtextrequired

    The relative path of the file to delete.

Example request to the assistant

Delete the unused file old-offer.html.

file_move

Renames or moves a file inside the site. It fails if the destination already exists (delete it first if you want to replace it). Links in other files are not updated: after a move, the assistant must fix every reference to the old path with file_patch.

Parameters

  • slugtextrequired

    The site slug.

  • fromtextrequired

    The current path of the file.

  • totextrequired

    The new path of the file.

Example request to the assistant

Rename offer.html to menu.html and fix the links.

Was this page helpful?