Skip to content

feat(tools): route the remaining write tools through the guard (U7, #1375) - #1918

Open
easonLiangWorldedtech wants to merge 201 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:fws/u7-tool-wiring
Open

easonLiangWorldedtech wants to merge 201 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:fws/u7-tool-wiring

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

This unit routes the five remaining write tools — apply_diff, write_to_file, edit, edit_file, search_replace — through the shared write guard. After this unit no tool path overwrites a file the model has not read: an unearned write fails with the re-read remediation instead of publishing.

A write outside every workspace root is no longer rejected outright. The tool layer classifies the path against all workspace folders, asks the user, and forwards the approval to the guard, which re-checks containment against the approved roots before it publishes.

This unit is the seventh of nine pull requests for epic #1375. The chain is tracked on #1991.

Related GitHub Issue

Closes: #2426 (this unit's tracking issue). Refs: #1991 (chain tracking), #1375 (epic), #2317 (directory-identity binding, which the staging guard in this unit addresses). The template form is used for the unit's own tracking issue; no closing reference is used for the chain or the epic, because the maintainer closes those when the series lands.

Description

What this pull request changes:

  1. The five write tools save through DiffViewProvider.saveDirectly() and guardedWrite() with an explicit write kind, so a targeted edit is never treated as a full-file replacement.
  2. Each tool read brackets the file with a bigint fs.stat pair and observes it only when both tokens match, so a publish is authorized by the exact bytes the hunks were computed from. A stat failure leaves the file unobserved and does not fail the read.
  3. An approved outside-workspace write is bound to the canonical directory identity captured before the approval was requested. The guard compares against that capture and refuses when it is missing.
  4. A containment decision no longer falls back to a lexical-only judgement when a workspace root cannot be resolved, and a path that runs through a dangling symlink ancestor is refused rather than re-joined lexically.

Diff size. The branch carries its own copies of the earlier units' content, so the GitHub diff shows that content as context. Measured over base...head from the merge base 41cf71a72c45fefb69b6be785c4620669f41c1e9 to head 284f1309bdca: 80 files, of which 51 sit outside the test directories, 27924 additions and 431 deletions over 201 commits; the pull-request fields read 80 files, 27924 additions, 431 deletions and 200 commits, so the two agree. The merge base equals the base commit, so the head is 200 commits ahead and 0 behind: no refresh is pending.

Test-file scope. No webview-ui file remains in the diff: measured at head 284f1309bdca, 0 of the 80 changed files sit under webview-ui/. The five webview-ui test files that were in this diff earlier in the chain were removed from it, the last of them answering review row 4568686689.

Review focus: the tool classes named above, src/core/tools/guardedWrite.ts, and the specs named below.

Test Procedure

From the repository root, with dependencies installed:

pnpm --dir src test -- core/tools/__tests__/guardedWrite.spec.ts core/tools/__tests__/applyPatchTool.execute.spec.ts core/tools/__tests__/applyPatchTool.partial.spec.ts core/tools/__tests__/applyDiffTool.guardedWrite.spec.ts core/tools/__tests__/writeToFileTool.spec.ts core/tools/__tests__/editTool.spec.ts core/tools/__tests__/searchAndReplaceTool.spec.ts
pnpm --dir src test -- integrations/editor/__tests__/DiffViewProvider.spec.ts utils/__tests__/safeWriteJson.test.ts utils/__tests__/safeWriteJson.lockKey.spec.ts
pnpm --dir src test:core
pnpm --dir src test:misc
pnpm --dir webview-ui test

Measured at head f3496c6e9295 on 2026-12-04 by the pull request author's lead, on the same bytes as the checks below. The only commit since then, 284f1309bdca, changes files under docs/architecture/tla only, so the suite figures below apply to the current head unchanged:

  • core suite: 226 test files, 5494 tests passed, 17 skipped, 0 failed.
  • misc suite: 128 test files, 2789 tests passed, 25 skipped, 0 failed.
  • webview-ui suite: not re-measured at this head, because no webview-ui file is in the diff and the vitest entry point does not resolve in the worktree this measurement was taken in; the last recorded measurement of it is 207 test files and 2736 tests at head 6e0c6db634f6.
    The repository gates all exit 0 on the same bytes: format check, root lint, root type check, src lint, src type check, Code QA workflow (7 tests), translations (68 tests), knip, knip-production, knip-policy (8 tests), MCP integration, lifecycle model check, and the mutation channel unit tests (106 tests).
    One lint invocation in that run exited 2 because it was given root-relative paths; re-run with source-relative paths it exited 0 and left src/eslint-suppressions.json byte-identical to the committed blob. The correction is recorded in the run log rather than dropped.
    Environment: Windows, unit layer only. The end-to-end and visual lanes run in CI.

Pre-Submission Checklist

  • Scope is one gate scope and matches the unit.
  • No changeset or changelog change (AGENTS.md).
  • src/eslint-suppressions.json unchanged: no suppression count increased.
  • New code lints clean with --max-warnings=0 rather than relying on suppressions.
  • Tests added at the lowest layer that would have caught each finding.
  • Visual snapshot item considered: not applicable, no rendered surface.

Visual Snapshots

Not applicable. No rendered surface changed; the approval prompt is the existing one.

Videos (interaction / animation only)

Not applicable.

Documentation Updates

No user-facing documentation change. The guard is internal behaviour of the write tools, and the model-facing remediation text already existed in earlier units. No changeset and no changelog edit, per AGENTS.md.

Additional Notes

  • Out-of-scope disclosure: measured at head 284f1309bdca, no webview-ui file is in the diff at all, so there is no out-of-scope webview-ui file to explain. Of the 80 changed files, 30 are under docs/ (the TLA+ models this unit writes alongside the code) and 49 sit outside test directories - webview-ui/src/utils/validate.ts is the same blob at the base and at this head (aa34fa4e8d39, 11,598 bytes) - and that file is the only place in this campaign where review row 4568686689 (Major, maintainability, anchored at line 140 of the file, now marked addressed by the reviewer) is answered: it asks that each credential-rejection case be paired with a valid configuration asserted through validateApiConfigurationExcludingModelErrors, and the answer is commit e632244. A census of the 79 open pull requests authored by this account found none that changes webview-ui/src/utils/validate.ts and none other that carries this file, so no open pull request exists to move it to. The scope check has failed twice while this disclosure was already in the description, which is measured evidence that prose does not clear it; a routing request covering this file and the groups named on fix(webview): send stable view-state id on launch and re-pin per-view state #1552 is recorded in comment 7294670772, which lives on fix(webview): send stable view-state id on launch and re-pin per-view state #1552 rather than here.
  • The mutation-diff check is advisory for stacked units: it reports the changed-line count of the whole branch diff rather than this unit's own delta, and the count is taken per package rather than summed. Measured at head 284f1309bdca the extension package holds 2626 changed executable lines and no other package is over 500, so the check fails on this head as it did on its predecessors while all seven required contexts pass. Two ways out need a maintainer: a narrow exclusion for the packages the check names, or authorization to split the chain further with a tracking issue that carries the plan before a split pull request opens. No Stryker disable comment and no suppression change is used in place of that decision.
  • Content source of record: the superseded umbrella pull request feat(tools): track read completeness and guard the diff-view save path (S4b, #1375) #1833 (closed), replayed onto the main tip. Split plan of record: comments 5993969784, 5994039786 and 5994053776 on [Tracking] guarded-write chain (epic 1375): rules, port sources, chain-level rows #1991.

Get in Touch

Reviewer and maintainer questions are welcome as comments on this pull request or on #1991.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking fws U7: remaining write tools publish through the guard

2 participants