Unit U4 of the PR #1066 split (2/6).
Split plan: #703
PR: #1929
Content source of record: tag pr1066-source = 46d1d218701f0ce2d675b1b315489bacb6b0f77d (easonLiangWorldedtech/Zoo-Code).
Unit contract
Per-task partial stream state keyed by taskId.instanceId, the TaskAborted teardown listener registered once per task, clearTaskState(), per-task path stabilization, the cleanup primitives (resetDiffViewAfterWrite, revertDiffChangesBeforeReset, finalizePartialToolAskAfterFailure), and the ClineProvider disposal wiring that releases the state for a task disposed without an abort.
Why this unit exists on its own
Single provider group (WriteToFileTool streaming state + provider wiring) + single gate scope. Everything downstream depends on this unit's state keying, so it must land first.
Boundary
Files and budget
src/core/tools/WriteToFileTool.ts +163/-2 — content subset of source
src/core/tools/__tests__/writeToFileTool.spec.ts +116/-0 — byte-identical to source
src/core/tools/__tests__/writeToFileTool-partial-state-cleanup.spec.ts +100/-0 — allowNew (sanctioned new content)
src/__tests__/removeClineFromStack-delegation.spec.ts +41/-0 — byte-identical to source
src/core/webview/ClineProvider.ts +6/-0 — byte-identical to source
- budget: 428 a+d / 5 files — SOFT-OVERSHOOT (rationale: the focused cleanup spec is new content; under the 1000 hard cap)
- mutation gate: 63 changed executable lines (58 WriteToFileTool + 5 ClineProvider) — under the 500 cap; valid mutants for the whole PR are 116 / 400, so no directive was added by this unit.
Verification (must pass by once, binary)
zdt split verify --contract U4.json --worktree <wt> --head 52699c6cdc7d — PASS (every changed file is a content subset of the source of record, or an explicitly sanctioned allowNew file).
- Tests: 230 passed / 5 skipped, exit 0 (narrowest relevant suites:
Task.spec.ts, writeToFileTool.spec.ts, writeToFileTool-partial-state-cleanup.spec.ts, removeClineFromStack-delegation.spec.ts, presentAssistantMessage-custom-tool.spec.ts).
- Changed-line coverage: 34 covered / 0 uncovered — PASS.
- ESLint
--prune-suppressions --max-warnings=0: clean on every touched file; suppression counts unchanged.
- No
.changeset file, no CHANGELOG edit (AGENTS.md).
Deviations recorded
- Accepted mechanism divergence: sibling streaming tools (ApplyDiffTool, EditFileTool, SearchReplaceTool, EditTool) still use BaseTool's singleton
lastSeenPartialPath/resetPartialState. Lifting the per-task keying to BaseTool is a follow-up PR, deliberately not done here.
- New focused spec added so the primitives' catch arms are proven at this layer: they are only reachable by calling the primitives directly, because the tests that trigger them through execute()/onParameterParseFailure() belong to U5/U6.
Reproduce
git fetch https://github.com/easonLiangWorldedtech/Zoo-Code p1066/u4-per-task-stream-state
node zdt.mjs split verify --contract U4.json --worktree <wt> --head 52699c6cdc7d
node zdt.mjs split measure --worktree <wt> --base cf5abe64d6e8 --head 52699c6cdc7d
pnpm --dir src exec eslint --prune-suppressions --max-warnings=0 <touched file>
Unit U4 of the PR #1066 split (2/6).
Split plan: #703
PR: #1929
Content source of record: tag
pr1066-source=46d1d218701f0ce2d675b1b315489bacb6b0f77d(easonLiangWorldedtech/Zoo-Code).Unit contract
Per-task partial stream state keyed by
taskId.instanceId, theTaskAbortedteardown listener registered once per task,clearTaskState(), per-task path stabilization, the cleanup primitives (resetDiffViewAfterWrite,revertDiffChangesBeforeReset,finalizePartialToolAskAfterFailure), and theClineProviderdisposal wiring that releases the state for a task disposed without an abort.Why this unit exists on its own
Single provider group (WriteToFileTool streaming state + provider wiring) + single gate scope. Everything downstream depends on this unit's state keying, so it must land first.
Boundary
cf5abe64d6e8(previous unit head, U12)52699c6cdc7dFiles and budget
src/core/tools/WriteToFileTool.ts+163/-2 — content subset of sourcesrc/core/tools/__tests__/writeToFileTool.spec.ts+116/-0 — byte-identical to sourcesrc/core/tools/__tests__/writeToFileTool-partial-state-cleanup.spec.ts+100/-0 — allowNew (sanctioned new content)src/__tests__/removeClineFromStack-delegation.spec.ts+41/-0 — byte-identical to sourcesrc/core/webview/ClineProvider.ts+6/-0 — byte-identical to sourceVerification (must pass by once, binary)
zdt split verify --contract U4.json --worktree <wt> --head 52699c6cdc7d— PASS (every changed file is a content subset of the source of record, or an explicitly sanctionedallowNewfile).Task.spec.ts,writeToFileTool.spec.ts,writeToFileTool-partial-state-cleanup.spec.ts,removeClineFromStack-delegation.spec.ts,presentAssistantMessage-custom-tool.spec.ts).--prune-suppressions --max-warnings=0: clean on every touched file; suppression counts unchanged..changesetfile, no CHANGELOG edit (AGENTS.md).Deviations recorded
lastSeenPartialPath/resetPartialState. Lifting the per-task keying to BaseTool is a follow-up PR, deliberately not done here.Reproduce