Skip to main content
Blitz
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

006 · Filetools

File sandbox, file tools, patches and checkpoints (spec_006_filetools)

Status Implemented. Reverse-engineered from 53f8c53 (2026-09-24) and kept with the code since; its paths checked 2026-09-27 (//tools/specs).
Source pkg/engine/tools/workspace.go, pathpolicy.go, pathlock.go, file_ops.go, file_edit.go, patch.go, grep.go, checkpoint.go, diff.go, export_pdf.go, documents.go, audio.go, draw.go, pkg/engine/mdpdf/mdpdf.go, pkg/pdftext/pdftext.go, pkg/engine/runtime/speech.go, painter.go
Tests pkg/engine/tools/workspace_test.go, sandbox_paths_test.go, file_tools_test.go, edit_race_test.go, patch_test.go, grep_test.go, approvals_checkpoints_test.go, export_pdf_test.go, documents_test.go, audio_test.go, draw_test.go, pkg/engine/mdpdf/mdpdf_test.go, pkg/pdftext/pdftext_test.go, pkg/engine/runtime/speech_test.go, painter_test.go
Depends on spec_002_config, spec_005_approvals (approval gate)

1. Purpose

Every file tool goes through one Workspace sandbox: paths must fall under a configured root, writes need a writable root, and blocked patterns are refused everywhere — including through symlinks. Edits show a diff for approval, are serialised per file, are refused if the file changed while waiting for approval, are written atomically, and are checkpointed so each turn can be undone.

2. Roots

  • FS-01 Roots: the workspace (read-write, roots[0]), sandbox.allowed_paths (read-write) and sandbox.read_only_paths. Extra roots are resolved relative to the workspace (after ~ expansion) and must exist — a typo must not silently widen or narrow the sandbox.
  • FS-01a blitz --add-dir <dir> (repeatable) adds a read-write root for the run, as sandbox.allowed_paths does (the file tools’ roots and the OS sandbox’s writable directories); blocked_paths still apply inside it, /sandbox lists it (“allowed (rw)”), and it isn’t saved. It must be an existing directory (a usage error otherwise), and it runs the workspace in the CLI’s own process, as --append-system-prompt does, since the service’s workspace has its own sandbox (BL-FS-01).
  • FS-02 Every root is canonical (absolute, symlinks resolved) and opened as an os.Root, which rejects .. traversal and symlinks leaving the root at the OS level.
  • FS-02a 2026-11-05 (scan N26-engine-tools-2#12: plans, skill output folders and the secret-scanning git hook were written with os calls, so a Viewer’s read-only clone got them, and a .blitz or .githooks link led them out of the workspace). Blitz’s own files in the workspace go through the workspace too: exit_plan_mode’s plan is CreateExclusived, a skill script’s output folder is made by Workspace.OwnDir (through os.Root), and install_secret_hook first checks the hook’s path with Workspace.CheckOwnFile (as a write, and its real location inside the workspace). Each is refused in a read-only workspace or root, on a blocked path, or through a link out of the workspace.
  • FS-03 Relative paths are relative to the workspace; a relative path that lexically escapes (..) is ErrOutsideWorkspace. Absolute paths map to the deepest containing root (so a read-only root nested inside the workspace wins). A non-canonical spelling of a root (/var vs /private/var) is retried after resolving its longest existing prefix.
  • FS-03a 2026-11-05 (scan N26-engine-tools-2#2: VENDOR/x.go on macOS mapped to the writable workspace instead of the read-only vendor and was written). Where the file system ignores case (macOS, Windows), a path is matched to its root ignoring case too, so a read-only root nested in the workspace wins whatever case the path uses; the desktop’s rule for a path (AgentRule) says the same.
  • FS-04 Write to a read-only root → ErrReadOnlyPath. A path matching a blocked pattern → ErrBlockedPath (pattern). If the path is a symlink, its real target is checked too: blocked → refused “via symlink”; for writes, a read-only target → refused.
  • FS-04a 2026-11-05 (scan N26-engine-tools-2#3: a new file made through a linked folder, lib -> vendor, was never checked, since only an existing file’s link was resolved). A path that doesn’t exist yet is checked where its nearest existing folder really is: a new file through a link into a read-only root is ErrReadOnlyPath, into a blocked folder ErrBlockedPath.
  • FS-05 Display form: workspace-relative inside the workspace, absolute elsewhere.
  • FS-06 Files over tools.max_file_size_bytes (default 10 MiB) are refused for reading; reads guard against growth between stat and read.

3. Blocked-path patterns

  • FS-10 Pattern forms (each matches the path itself and everything beneath it): no slash (.env, *.pem) — that name at any depth; absolute (~/.ssh, /etc/x) — that location, also its symlink-resolved spelling; relative with a slash (config/prod/*.yaml) — relative to every root.
  • FS-78 2026-11-05 (scan N26-pkg-small-2#16: **/*.{pem,key} and id_[rd]sa were taken literally and blocked nothing, without a word). A pattern’s {a,b} alternatives are a pattern each (textutil.ExpandBraces, nested ones too, at most 64), and [abc], [a-z] and [!abc] are classes (never a slash); an unclosed or impossible one stays literal. The same holds for read/write/delete permission rules, in-process and in the macOS profile.
  • FS-11 * matches within one segment, ** across segments (**/ optional), ? one character. Patterns containing " or newline are invalid.
  • FS-12 Matching is case-insensitive on macOS and Windows (so .ENV is .env).
  • FS-13 The same expressions (without Go-only syntax) are emitted for the macOS Seatbelt profile (spec_007_shell).
  • FS-14 Walks (list_files, grep) skip blocked entries and do not descend into blocked directories.
  • FS-15 2026-11-13 (the owner: pip couldn’t read the system’s CA bundle, /etc/ssl/cert.pem, in the sandbox, and an allow rule didn’t help; a project couldn’t make its own .env.*.toml; Bazel couldn’t unpack rules_go, whose archive holds a test .env). sandbox.hidden_paths are files whose contents the model never gets, while commands use them as any program does: the file tools refuse to read them (ErrHiddenPath, an ErrBlockedPath too) and skip them in walks, memory imports and the file tree’s sharing (the file tree shows them as blocked to the agent), but may make one (create_file); the OS sandbox doesn’t hide them. Defaults: .env, .env.local, .env.*.local, *.pem, *.key, *.p12, id_rsa*, id_ecdsa*, id_ed25519*. blocked_paths keep the secret stores (~/.ssh, cloud credentials) and Blitz’s own settings (~/.blitz/.env.toml, ~/.blitz/.env.*.toml, and the workspaces’ under ~/.blitz/workspaces/), so a project’s .env.*.toml is its own. A private key (-----BEGIN … PRIVATE KEY-----) in a command’s output, or a background process’s, is masked before the model gets it ("[a private key, kept from the model]"). A skill’s script still gets no hidden files in its copy of the workspace, and its changes to one aren’t kept. A project’s .blitz/settings.toml may add hidden paths (A, as blocked paths).

4. Writes

  • FS-20 WriteFileAtomic: temp file .<name>.tmp-<hex> in the same directory, fsync, chmod to the existing file’s mode (new files 0644), rename. A symlinked file is rewritten in place through the root instead of replacing the link. Parent directories are created (0755). Writing a directory or the root itself is refused.
  • FS-20a 2026-11-05 (scan N26-engine-tools-2#26: a file apply_patch moved was created 0644, so a moved script lost its +x). A file apply_patch moves (*** Move to: or a renamed unified diff) is created with the source’s mode.
  • FS-21 CreateExclusive fails with fs.ErrExist if the file exists.
  • FS-22 RemoveFile removes only non-directories and never a root.
  • FS-23 Every write/delete first snapshots the prior state for checkpoints; if the operation fails the snapshot entry is discarded.

5. Concurrency and approval races

  • FS-30 The ADK runs a model response’s tool calls concurrently. Read–approve–write sequences are serialised per file by a lock keyed on the display path. Multi-file operations lock paths in sorted, de-duplicated order (no deadlock). Waiting honours context cancellation.
  • FS-31 After approval and under the lock, the tool re-reads the file; if it differs from what was shown (or now exists/no longer exists), nothing is written and the tool returns “ changed while waiting for approval (edited outside this tool); nothing was written — read it again and redo the edit”.

6. Tools

All tools return errors in an error field of the result (never a Go error), so the model sees them.

Tool Arguments Behaviour
read_file path, start_line?, end_line? (1-based) Lines numbered %4d: ; output capped at 512 KiB with a truncation note suggesting paging; total_lines; a start beyond EOF clamps to the last line; end < start becomes start. A .pdf reads as its text (FS-72). force?: the content even when unchanged. A range of a file of up to 400 lines gives the whole file, noted; an unranged read of a file over 500 lines (defaultReadMaxLines) returns lines 1–500 with truncated: true, lines: "1-500", digest and a paging note (FS-83b); a non-byte-truncated result names its lines (1-220) and digest; a read of lines the agent was already shown, the file unchanged, answers unchanged (FS-83); a missing file suggests up to five near paths
list_files directory? (.), recursive?, max_entries? (default 200, max 500: more is 500; truncated when it stopped there) Entries path, is_dir, size_bytes; dot-files skipped and dot-dirs not descended
glob pattern, path?, max_results? (default 200, max 1000) ** crosses segments, */? stay within one, {a,b} alternatives (nested, ≤ 64); relative patterns only (.., absolute and ~ refused); dot and dependency directories (node_modules, vendor, target, __pycache__) skipped unless a pattern segment names them; regular files only, symlinks not followed; newest first by modification time, then by path; truncated when capped; case-insensitive on macOS/Windows
grep query, path?, is_regex?, case_insensitive?, mode? (content (default), files_only, count), max_matches? (default 20, max 500: more is 500; truncated when it stopped there) Skips dot-dirs, node_modules, vendor, target, __pycache__, files > 5 MiB (counted in a note, since 2026-11-05, scan N26-engine-tools-1#18) and binaries (NUL in first 8000 bytes); lines trimmed and ellipsized to 500 bytes; parallel scan (≤ min(GOMAXPROCS, 8)) but results in walk order so the first N are deterministic; CRLF tolerated. files_only returns unique matching file paths (files, total_files); count returns per-file and total match counts (counts, total_matches, total_files) without line content; when content mode truncates at max_matches, note reports the total matches and files found across the scan so the agent can narrow path or query
create_file path, content, overwrite? Existing file without overwrite fails; approval shows a diff (“Create”/“Overwrite (N bytes)”)
replace_in_file (alias edit) path, target_content, replacement_content, allow_multiple? Empty target, no match, or multiple matches without allow_multiple fail with guidance; approval with diff
delete_snippet path, snippet Removes the first exact occurrence; approval with diff
delete_file path Approval with a removal diff; kind delete
apply_patch patch See §7
export_pdf path (.md, .markdown) or markdown, output? (default the file’s name with .pdf; required with markdown), overwrite? FS-70, FS-71
export_docx as export_pdf, writing .docx FS-75
view_document path (a PDF) FS-73
view_media path (audio or video) FS-77
generate_audio text or text_path, path, voice?, speakers? (two {name, voice}), overwrite? FS-74 – FS-76
notebook_edit path (.ipynb), cell (an id, or an index from 0; for insert, the cell to follow, -1 for first), action (replace, insert, delete), source?, cell_type? (code, markdown, raw) PAR-TOOL-02. The notebook is decoded keeping unknown fields and numbers as written and re-encoded as Jupyter does (keys sorted, one-space indent, final newline). Replacing a code cell clears its outputs and execution count; changing a cell to markdown or raw drops them; an inserted cell gets an 8-hex id when the notebook is nbformat 4.5 or later. As replace_in_file: writable path first, locked, approval with the diff, unchanged-since check, atomic write (and so checkpoints). read_file on an .ipynb without a line range shows it as cells (## Cell <i> [<type>] id=<id>, code fenced in the kernel’s language, then each output: stream text, text/plain, ename: evalue, [image/png image], 2,000 characters each); a notebook that doesn’t parse, or a line range, shows the file
  • FS-40 Edit approvals: kind write_file, key write:<workspace> (“file edits in ”), targets = workspace-relative paths. Deletions: kind delete_file, key delete:<workspace>.
  • FS-41 The path is resolved as writable before asking, so the user is never asked to approve a write the sandbox would refuse.

6a. PDFs and sound

  • FS-70 export_pdf typesets a Markdown file as a PDF in pure Go (pkg/engine/mdpdf): GitHub-flavoured Markdown (goldmark), laid out with fpdf in embedded Noto Sans, Noto Sans Mono and, character by character where those lack a glyph, Noto Sans Math (arrows, operators, ∇; OFL, gzipped, about 1.4 MB). Headings make the PDF’s outline (levels never skip); paragraphs keep bold, italic, code and links; ordered, bulleted and task lists; block quotes with a bar on each page they span; tables fitted to their text, cells wrapped, the header repeated after a page break; code blocks on a tinted panel coloured by chroma (GitHub’s light colours), long lines wrapped; rules; page numbers (“3 / 12”). Raw HTML and front matter are left out, a Mermaid block prints as its code with a note to export from the desktop app, and characters beyond the Basic Multilingual Plane (emoji) become U+FFFD. Images (PNG, JPEG, GIF) are read through the workspace (relative to the file, never outside it or blocked, at most 20 MB), checked and re-encoded, and scaled to the page; others print as [image: alt]. The page is A4 or Letter: [pdf] page_size a4, letter, or auto (the default: Letter where LC_ALL, LC_PAPER or LANG names a country that uses it, A4 otherwise).
  • FS-71 export_pdf takes an existing Markdown file (path) or Markdown itself (markdown, with output; one or the other), so a PDF of something that isn’t a file, such as a summary of the conversation, leaves no Markdown file behind; its description tells the model not to write one first. Images in given Markdown are relative to the PDF. It writes as create_file does: the output resolved writable first, then locked, an existing file refused without overwrite, one write approval (kind write_file, key write:<workspace>, “Create notes.pdf from notes.md (3 pages, 84 KB)”, no diff), the unchanged-since check, and an atomic write, so a checkpoint can undo it. The result is {path, output, pages, bytes}. Hooks and permission rules see path as read and the output as written; plan mode refuses it.
  • FS-75 2026-10-14 (#38). export_docx writes Markdown as a Word document (Office Open XML, .docx) in pure Go (pkg/docx, sharing the parsing in pkg/markdown with mdpdf), with export_pdf’s arguments, checks, approval (“Create notes.docx from notes.md (12 KB)”), checkpoint and rules (FS-71); the result has no pages. The document uses Word’s own styles, so the navigation pane, a table of contents and a template’s restyling work: headings as Heading 1–6 (in the outline, each with a bookmark named from its GitHub-style anchor, so [jump](#usage) links to it); paragraphs with bold, italic, strikethrough, inline code (Code Char) and links (external as hyperlinks, #anchor to the heading); bulleted and numbered lists, nested, each numbered list counting from its own start; task lists as ☐/☒; block quotes (Quote); code blocks a line per paragraph in a Code style, tabs and spaces kept; GFM tables (Table Grid) with the header row repeated across pages, column alignment, short rows filled out; rules; pictures embedded and scaled to the text width: PNG, JPEG, GIF and SVG (with a blank PNG fallback, as Word’s own files carry), written as Markdown or as a lone HTML <img> (its width kept), others as [image: alt]. 2026-10-15 (the owner’s testing): pictures resolve as the desktop preview resolves them (markdown.LocalPath: percent-escapes decoded, a query and fragment dropped, a leading / from the workspace’s root), so a my%20figs/plot.png or /figs/plot.png that shows in the preview is in the document; export_pdf resolves them the same way and draws a lone <img> too. Maths ($…$, $$…$$, as the preview reads it; $5 and $10 stay text) becomes Office Math equations Word can edit (pkg/docx/math.go: fractions, roots, sub- and superscripts, sums and integrals with limits, \lim, accents, \mathbf/\mathcal/\mathbb/\text, \left…\right, matrices, cases and aligned equations, Greek and the usual symbols; a command it doesn’t know is kept as written); export_pdf prints maths as its LaTeX. A Mermaid block is kept as its code with a note, unless the caller drew it (Options.Diagram: the desktop app does, DSK-93b). Raw HTML otherwise and front matter are left out. The page is A4 or Letter as [pdf] page_size says. The same Markdown gives the same bytes (parts in a fixed order, dated by Options.Time). The same writer serves the desktop app’s Export as Word (spec_024_desktop DSK-93b, through FileService.RenderDocx), /export <name>.docx in a session and in the app, and blitz sessions export <id> -o <name>.docx. A test writes every page of the user guide and checks each part is well-formed XML; Word, Pages and Quick Look were checked by hand (development/manual-verification).
  • FS-75 2026-11-05 (scan N26-pkg-small-1#6, #11, #19, #20: nesting without braces (\sqrt\sqrt…, ^^^…) wasn’t bounded, so a hostile formula could overflow the stack and end the service; a long line of $ that never close took the square of its length; a document over the preview’s limit said “not a Word document”; a list nested past nine levels wrote a level the numbering doesn’t define). Every atom counts toward the formula’s nesting bound (64), as groups do; an inline $ looks at most 2,048 bytes along its line for its close (a longer formula stays text); a Word document whose text is over 64 MB is too large to preview; a list nested deeper than nine levels is drawn at the ninth.
  • FS-72 read_file on a .pdf gives its text (pkg/pdftext: each page headed --- Page N ---, a page with none says it may be a scan), paged like any file, with a note that layout and figures may be lost and view_document shows them; up to 32 MB, the last eight PDFs’ text kept in memory. A file named .pdf that isn’t one reads as it is. The reader (github.com/ledongthuc/pdf, patched for CMap ranges wider than 256 codes: third_party/ledongthuc_pdf/bfrange.patch) has its panics turned into errors and a 20-second limit.
  • FS-73 view_document loads a PDF as view_image loads a picture (spec_011_images IMG-50): the workspace’s path rules, then stored; the result is {path, image_uri, pages, bytes} and the document follows it, as the PDF for a model that reads PDFs and as its text for others. A picture is refused (“use view_image”). It exists only when images are on, is allowed in plan mode, and is offered to blitz, qa, the planning agent and helios.
  • FS-77 view_media loads audio or video from the workspace (streamed into the store, up to what the model takes: spec_011_images IMG-62) and returns {path, image_uri, mime_type, seconds, bytes}; the file follows the result, inline or through Gemini’s Files API. It’s refused before anything is stored when the active agent’s model takes no audio or video (IMG-63), and for other files (“isn’t audio or video”). It exists when images are on, is allowed in plan mode, and is offered to blitz, qa, the planning agent and helios.
  • FS-74 generate_audio reads text aloud with the [audio] model (spec_015_models MDL-90) and writes the sound into the workspace. The text is text, or the file text_path (inside the workspace, text only); either is made speakable first (front matter, heading and list marks, emphasis, link targets, rules and HTML tags removed; a “Name: line” kept). It’s refused when empty, over [audio] max_chars (9,000 by default, about ten minutes), with more than two speakers, or with sandbox.allow_network = false. The file’s extension follows the model (.wav for Gemini, .mp3 for OpenAI; another is replaced and the result says so).
  • FS-75 One approval covers the call and the file: kind network, key audio:<provider>/<model>, target the API’s host (so web rules apply), “Speak 4812 characters with gemini/… (Ana and Ben) → audio/overview.wav”. Nothing is sent before it. The file is then written as create_file writes (locked, overwrite, atomic, checkpointed), and the result is {path, bytes, seconds, model, note}. Each call’s usage, even a failed one’s, goes in the session’s cost (spec_015_models MDL-93). Hooks and permission rules see text_path as read and path as written; plan mode refuses it.
  • FS-75a 2026-11-05 (scan N26-engine-tools-1#12: deny write(…) didn’t stop generate_audio’s file). generate_audio’s output path is decided by write rules before the approval: a deny rule refuses the call (nothing is sent), and an ask rule makes the approval MustAsk.
  • FS-76 generate_audio is always registered, so a speech model set while the workspace is open takes effect, but agents have it only while there’s a speaker (Registry.SetSpeaker); without one it says why (“speech isn’t available: …”). It’s offered to blitz.
  • FS-80 2026-11-06 (the owner asked blitz on gemini-4-argon for an image; no tool could make one, AG-14b). generate_image draws a picture with the [images] model (spec_015_models MDL-95; an organization’s image model through its service, MDL-95a) and writes it into the workspace (pkg/engine/tools/draw.go). Arguments: prompt (required), path, images (up to 3 workspace pictures to edit or match, PNG, JPEG or WebP by their content, 7 MB each), aspect_ratio (1:1, 2:3, 3:2, 3:4, 4:3, 9:16, 16:9, 21:9) and size (1K, 2K, 4K), the model’s own when empty, and overwrite. It’s refused for an empty prompt, another shape or size, more pictures, a picture it can’t read or that isn’t one, or sandbox.allow_network = false. Since v0.9.7: for a model the picture catalog knows, the references, shapes and sizes are the model’s, and count asks for several pictures (spec_058_pictures PIC-81).
  • FS-80a 2026-11-21 (security review tools#8). overwrite replaces only the path approved. A name of the tool’s making (another extension than asked, or the numbered names of several pictures) never replaces a file: taken, it’s the first free one beside it (fox-2-2.png), and the result’s note says so.
  • FS-81 One approval covers the call and the file, as FS-75: kind network, key image:<provider>/<model>, target the API’s host, “Draw with gemini/… → images/fox.png: <the prompt, clipped to 160 characters> (from logo.png)”. Before it, the pictures sent are decided by read rules and the file by write rules (deny refuses, nothing sent; ask makes the approval MustAsk). The file’s extension follows the picture the model made (.png, .jpg, .webp; .jpeg is a JPEG’s), the new name checked against existing files and write rules, and the result says so. It’s written as create_file writes (locked, overwrite, atomic, checkpointed). The result is {path, image_uri, mime_type, bytes, model, text, note}: image_uri refers to the stored picture, so the model sees what it drew (spec_011_images IMG-03’s route) and the desktop app shows it (spec_024_desktop DSK-94b); text is what the image model said with it. Each call’s usage, a failed one’s too, goes in the session’s cost as an image call (MDL-96). Hooks and permission rules see images as read and path as written; plan mode refuses it.
  • FS-82 generate_image is always registered, but agents have it only while there’s an image model (Registry.SetPainter); without one it says why (“drawing isn’t available: …”). It’s offered to blitz.
  • FS-83 2026-11-10 (the owner: read_file was called again and again on the same file; of 823 reads in 121 conversations, 55 repeated a read whole, 31 re-read lines of a file read whole, 153 of 207 ranged reads paged files under 400 lines, and 83 named a missing path). Reads aren’t repeated. A tool can’t see the conversation, so the engine’s before-model hook gives each request to the workspace’s read log (tools.ReadLog.Shown), which keeps, per conversation, branch and agent, the read_file results the request carries (its own, and those of the agents before a handoff, which ADK sends whole as text: “[blitz] read_file tool returned result: {…}”), by the digest (the first 16 hex of SHA-256 over the path and content) and lines each non-byte-truncated result names; call IDs aren’t used, as ADK takes its own out of requests and Gemini sends none. A read of lines inside one the agent was last shown, the file’s digest the same, returns no content: unchanged: true and a note naming the lines read before, and pass force to have it again. So a summary or a rewind that drops the earlier read, a change to the file, another agent that wasn’t shown the read (one invoked as a tool starts without it), a byte-truncated read, a call outside a conversation, or a service restart before the next request all give the content. The log keeps 64 agents, the oldest forgotten first. Also: a range of a file of up to 400 lines (wholeFileLines) gives the whole file, noted (“The file is 12 lines, so here it is whole.”), a PDF’s text included; a missing file’s error suggests up to five workspace files, those with its name first, then those whose name holds its stem, shortest first, skipping hidden folders and node_modules and looking at 20,000 entries at most; read_file’s description says not to read unchanged lines again; blitz, coder and harness-update say a read earlier in the conversation (theirs or the agent’s before them) counts.
  • FS-83b Default 500-line read window (defaultReadMaxLines = 500). An unranged read_file call (start_line == 0 && end_line == 0) on a file with more than 500 lines returns lines 1-500 with truncated: true, total_lines, lines: "1-500", the full-file SHA-256 digest, and a note instructing the agent to pass start_line and end_line (or use search_workspace / grep to locate the relevant section) to read further. Because lines and digest are still recorded on a line-capped read (when not byte-truncated at 512 KiB), ReadLog deduplicates subsequent reads of lines within 1-500 while letting ranged reads beyond line 500 proceed.
  • FS-83a Directory and glob deduplication. ReadLog also tracks non-truncated list_files and glob results carried in the model’s request by their query parameters and a 16-hex SHA-256 digest of the returned entry list (path, is_dir, size_bytes for list_files; matched paths and mtimes for glob). When the agent calls list_files or glob with the same parameters and the computed digest is unchanged and still present in the conversation (ReadLog.Shown), the tool omits the files array and returns unchanged: true, total_count (or count), and a note pointing to the earlier result in the conversation (unless force: true is passed).
  • FS-84 grep progressive discovery and match capping. grep supports mode: "content" (the default: matching lines with file, line_number, content), "files_only" (unique matching file paths in files and total_files, stopping at at most one match per file), and "count" (per-file match counts in counts plus total_matches and total_files, with no line text). In "content" mode, max_matches defaults to 20 (maximum 500); when truncated, the scan continues counting (or notes the count reached) so note states "Found N matches across M files; showing first K. Narrow path/query or use mode: \"files_only\" or \"count\"."

7. apply_patch

  • FS-50 Accepts a unified diff (git or plain, ---/+++/@@, a//b/ prefixes and timestamps stripped, git metadata and prose between files ignored, \ No newline at end of file respected, blank context lines missing their leading space tolerated) or a *** Begin Patch … *** End Patch block (add/delete/update/move).
  • FS-51 Validation happens before anything is written: every file resolved writable, a file may appear only once, add requires absence, delete/update require presence, move requires the destination to be absent.
  • FS-52 Hunk matching: exact, then ignoring trailing whitespace, then ignoring surrounding whitespace; nearest occurrence to the hinted line; anchors (@@ context) supported; pure insertions at hint/after anchor/EOF. Matching is on LF-normalised text and CRLF is restored. Failures name the hunk and preview the lines not found.
  • FS-52a 2026-11-05 (scan N26-engine-tools-2#27: a patch to a file with any CRLF turned every line into CRLF). Endings are normalised (and CRLF restored after) only when every line ends in CRLF; in a file with mixed endings a line’s CR is trailing space to the matcher. A hunk’s leading and trailing context lines are kept as the file has them (whitespace, a CR), so only the lines that change are rewritten.
  • FS-53 One approval for the whole patch (“Apply patch to N file(s): …”) with a combined diff (renames shown rename a -> b), targets = every touched path.
  • FS-54 Atomic: if any write fails, already-changed files are restored; the error says “(no files were changed)” or reports a rollback failure. The result lists per-file summaries.

7a. Code intelligence (lsp)

  • FS-60 The lsp tool (PAR-TOOL-03; pkg/engine/lsp, pkg/engine/tools/lsp.go): operation definition, references (declaration included), hover, symbols (workspace/symbol with query, from the server for path’s language) or diagnostics (of path, waiting up to 10 s); line and column are 1-based, the column in characters (converted to and from LSP’s UTF-16 offsets). Locations come back with the path (relative to the workspace when inside it), line, column and the line’s text; at most 100 locations or symbols. The path must be one the workspace may read (blocked paths refused). Allowed in plan mode, and offered to blitz and the planning agent.
  • FS-61 Servers: built in go (gopls), typescript (typescript-language-server --stdio: .ts .tsx .js .jsx .mjs .cjs), python (pyright-langserver --stdio), rust (rust-analyzer); [lsp.<language>] changes command or extensions, disabled = true turns one off, and a new language needs both (never from a project). A server starts the first time a file of its language is asked about, as shell commands run (guarded, in the OS sandbox, scrubbed environment, in the workspace), with initialize (workspace folder, hover in Markdown, location links) within 60 s; a server that can’t start (not installed: “<command> isn’t installed”) is reported and not retried until the workspace reopens; one that died is started again. Requests the server makes are answered (configuration: none). Files are sent as they are on disk: opened the first time, their full text again when it changed. 2026-10-03: a server starts on its own (60 s, or until the workspace closes), not on the asking call: callers wait for it, each giving up with its own deadline, and other languages start meanwhile; a start that failed is reported for a minute, then tried again; a request to a server that stopped reading gives up with its caller.
  • FS-61a 2026-11-05 (the owner: in a monorepo with frontend/node_modules/typescript and no node_modules at the top, the typescript server started at the workspace root and failed: “Could not find a valid TypeScript installation”). A server runs per language and project root: the nearest folder at or above the file, inside the workspace, holding one of its language’s markers (rootMarkers: Go go.work, else go.mod; TypeScript and JavaScript tsconfig.json, jsconfig.json or package.json; Python pyrightconfig.json, pyproject.toml, setup.py, setup.cfg or .venv; Rust Cargo.toml), else the workspace’s root (a language without markers, a file with none above it, a code block’s scratch folder). It starts in that folder, with it as rootUri and its only workspace folder; files in one root share its server, and a failed start holds back only its root (“starting the typescript language server (…) in frontend: …”). The typescript server is given initializationOptions.tsserver.path: node_modules/typescript/lib at the root or a folder above it in the workspace (hoisted), else the TypeScript beside tsc on PATH or beside the server’s command (a global npm install); with none, the server looks for itself. Status and Restart stay per language: ready when any root’s server runs; a restart stops them all.
  • FS-61b 2026-11-07 (the owner: a workspace with go, python and typescript folders, several projects in each; FS-61a’s Python markers missed projects known only by their requirements.txt, and pyright used the python on PATH, not the project’s environment). Python’s markers also take requirements.txt, Pipfile and a venv folder. The python server’s configuration requests are answered for its root: section python gets pythonPath, the interpreter of a virtual environment (.venv or venv, bin/python or on Windows Scripts/python.exe) at the root or a folder above it in the workspace (one shared by several projects); with none, the server’s defaults (null), as for every other section and language. A project’s pyrightconfig.json venv/venvPath still wins (pyright’s order).
  • FS-61c 2026-11-13 (the owner, who builds almost everything with Bazel: language servers didn’t start in Bazel workspaces; the go.mod, pnpm-lock.yaml and pyproject.toml files aren’t always at the root). A workspace whose MODULE.bazel (else WORKSPACE.bazel or WORKSPACE) uses rules_go, rules_python or rules_js gets the servers Bazel can feed: Go sources with no go.work or go.mod above them get rules_go’s package driver (GOPACKAGESDRIVER): the workspace’s own tools/gopackagesdriver.sh when it has one, else Blitz’s (in the user’s cache folder, bazel run @rules_go//go/tools/gopackagesdriver, rules_go by its repo_name), run with Bazel’s own output base (GOPACKAGESDRIVER_BAZEL_FLAGS=--output_base=<cache>/blitz/bazel/<hash> --max_idle_secs=1800), so the sandboxed server never starts or shares the person’s Bazel server; gopls skips bazel-bin, bazel-out, bazel-testlogs and bazel-<name>. TypeScript with no node_modules/typescript of its own comes from Bazel’s output (bazel-bin/<folder>/node_modules/typescript/lib, rules_js), at the root or a folder above it. With rules_python, imports start at the workspace: only pyrightconfig.json and pyproject.toml make a Python root, and pip’s packages in Bazel’s external repositories (bazel-<name>/external/*/site-packages) are pyright’s python.analysis.extraPaths. Language servers run in the OS sandbox as before (FS-15 lets Bazel unpack archives holding a .env).
  • FS-62 After create_file, replace_in_file/edit, delete_snippet or notebook_edit succeeds on a file whose language’s server is running (the lsp tool started it), the file’s errors and warnings (up to 20, waiting up to 3 s) come with the result as diagnostics. Servers shut down with the workspace (shutdown, exit, then killed).

8. Checkpoints and undo

  • FS-60 A checkpoint (turn) begins with each prompt (spec_018_workspace WS-22); an empty current turn is reused rather than stacking empty ones. Changes outside any turn go into “(no prompt)”.
  • FS-60a A change goes to the latest turn of the session making it (the tool call’s session, or its owner’s for sub-agents and tasks; Workspace.WriteFileAtomic, CreateExclusive and RemoveFile take the call’s context), so turns running at once keep their own changes; with no session, or none of its turns, the latest turn takes it. An empty turn is reused only by the same session. Job runs’ turns are their own (spec_023_workers WK-54).
  • FS-61 For each file, the state before the turn’s first change is kept (content, existence, mode; symlinks record the target’s mode), plus a hash of what the tool left.
  • FS-62 Memory budget checkpoints.max_bytes (default 64 MiB): oldest turns are dropped, always keeping the latest. Files larger than the max file size are marked too-large (not restorable).
  • FS-63 Undo(force) reverts the latest turn with changes, in reverse order. Without force it refuses when a file no longer matches what the tool wrote (ErrUndoConflict, listing files, “use /undo –force”) or when a file was too large to snapshot. Restores are atomic writes with the original mode; files that did not exist are removed. The turn is removed; restored paths are sorted.
  • FS-63a 2026-11-05 (the owner: /undo undoes the latest turn of the chat it’s run from, not the workspace’s latest turn whoever made it; with two chats open in one workspace, one chat’s /undo took back the other’s work). Undo(session, force) reverts session’s latest turn with changes, which includes its sub-agents’ and background tasks’ changes (FS-60a). Other sessions’ turns are left alone, even later ones; when session has none, Undo says “nothing to undo in this chat” (ErrNothingToUndo) though other chats have changes. Conflicts and --force are as FS-63, so another chat’s later edit to the same file is a conflict. UndoRequest.session_id carries the chat (empty: the workspace’s active session); the CLI’s /undo passes its active session, the desktop’s /undo its chat and Changes’ Undo last turn the active session. A job run’s undo (blitz jobs undo) is unchanged.
  • FS-64 Only changes made through file tools are tracked; shell side effects appear as conflicts.
  • FS-65 SessionDiff renders a unified diff from each file’s earliest snapshot this session to its current content (# <path>: too large to diff otherwise); sorted by path.
  • FS-67 Checkpoints persist ([checkpoints] dir, default ~/.blitz/checkpoints, one directory per workspace named after a hash of its path; dir = "" keeps them in memory). The directory holds index.json (turns with their session, the prompt’s transcript index, label, time and per-file before-state by hash, after-existence and after-hash) and blobs/<sha256>, all owner-only, written atomically. Snapshots live only in blobs (memory holds hashes). On open, turns older than max_age_days (30) and past the size budget are dropped, a snapshot whose blob is missing (or doesn’t match its hash) is marked unrestorable, and an unreadable index is renamed index.json.damaged (the store starts empty, with a warning). Unreferenced blobs are removed after turns are dropped and on open. The workspace lock (one process per workspace) is what makes one index safe. A save failure warns once; checkpoints then last only for the process.
  • FS-67a 2026-11-05 (scan N26-engine-tools-2#18: when the checkpoint directory couldn’t be opened, only the service log said so, and the user found out at /undo). The workspace warns as it opens (Registry.CheckpointsErr): “checkpoints are kept in memory only, so /undo can’t reach earlier sessions’ changes or keep this one’s: …”.
  • FS-68 Rewind(session, prompt, force) restores, as one operation, every file changed by session’s turns from transcript index prompt on: each file goes back to its state before the earliest of those turns, after checking every file first against the latest turn’s after-state (conflicts as FS-63, “use –force”). Other sessions’ turns are left alone. Detach(session, prompt) moves such turns to prompt-1 after the conversation alone is rewound, so a rewind to the next new prompt leaves them, and one to an earlier prompt still includes them. SessionDiff(session) diffs from each file’s earliest snapshot among that session’s turns ("": all).
  • FS-66 Diffs use a/<path>/b/<path> and /dev/null for creation/deletion.