feat(tool-fs): result-time applied-hunk diffs for write/edit

fs write/edit now emit a result-time contextual-diff tool_call_update
(the applied hunk with ±3 context lines, one hunk per replace_all site),
matching what claude-agent-acp sends and what makes an editor render the
change in place. The call-time snippet diff stays; the result hunk
supersedes it (ACP content-replace).

Mechanism:
- A persisted tool-private `meta` channel: execute may return
  `{ content, meta }`; `meta` (JsonValue) rides on the tool/result event
  and is handed back to presentResult, so the diff reproduces on replay
  (event-sourced). JsonValue is now exported from dsh-session.
- The backend returns raw before/after text (storage facts) on
  FsWriteOutcome/FsEditOutcome; the tool computes the hunk via the npm
  `diff` package's structuredPatch. A create has no before → no result
  diff; a failed/aborted mutation carries no meta.
- ToolResultView gains a DiffResultView; the bridge's result-side switch
  renders it as {type:'diff'} content blocks.

RFC: docs/rfc/implemented/architecture/2026-07-02-result-time-applied-hunk-diffs.md
(justifies the npm `diff` runtime dep over vendoring and the meta channel);
the render-intent-union RFC's Non-goal is updated to record this shipped.
All fs snapshot goldens re-recorded; edit/overwrite gain the contextual
result diff, create/read/policy-reject unchanged in structure.
This commit is contained in:
Tianyi Cui
2026-07-03 17:12:00 +08:00
parent af79ceea1c
commit d8fd3225af
48 changed files with 2217 additions and 1073 deletions
+7 -7
View File
@@ -259,7 +259,7 @@ A session was created in the store.
'session/created'(session: Session): void
```
Source: [`packages/core/session/src/index.ts:34`](../../packages/core/session/src/index.ts)
Source: [`packages/core/session/src/index.ts:35`](../../packages/core/session/src/index.ts)
#### `session/event` — emit
@@ -271,7 +271,7 @@ An event was appended to a session log (sync, fire-and-forget). This is the per-
Types: [SessionEvent](../core-data-structures/core.md)
Source: [`packages/core/session/src/index.ts:40`](../../packages/core/session/src/index.ts)
Source: [`packages/core/session/src/index.ts:41`](../../packages/core/session/src/index.ts)
#### `session/flush` — parallel
@@ -281,7 +281,7 @@ Awaited durability checkpoint. The agent loop awaits `ctx.parallel('session/flus
'session/flush'(session: Session): Promise<void> | void
```
Source: [`packages/core/session/src/index.ts:49`](../../packages/core/session/src/index.ts)
Source: [`packages/core/session/src/index.ts:50`](../../packages/core/session/src/index.ts)
### `subagent/*`
@@ -337,7 +337,7 @@ A tool was registered or unregistered (the available tool set changed).
'tools/change'(): void
```
Source: [`packages/core/tools/src/index.ts:48`](../../packages/core/tools/src/index.ts)
Source: [`packages/core/tools/src/index.ts:49`](../../packages/core/tools/src/index.ts)
#### `tools/execute` — waterfall
@@ -349,7 +349,7 @@ Waterfall around every tool execution — the single seam where sandbox, permiss
Types: [ToolExecution](../core-data-structures/tools.md) · [ToolExecutionResult](../core-data-structures/tools.md)
Source: [`packages/core/tools/src/index.ts:43`](../../packages/core/tools/src/index.ts)
Source: [`packages/core/tools/src/index.ts:44`](../../packages/core/tools/src/index.ts)
## Services
@@ -507,7 +507,7 @@ get(id: SessionId): Session | undefined
list(): Session[]
```
Source: [`packages/core/session/src/index.ts:322`](../../packages/core/session/src/index.ts)
Source: [`packages/core/session/src/index.ts:323`](../../packages/core/session/src/index.ts)
### `ctx.subagents` — `SubagentService`
@@ -547,7 +547,7 @@ async execute(exec: ToolExecution): Promise<ToolExecutionResult>
Types: [ToolDefinition](../core-data-structures/tools.md) · [ToolExecution](../core-data-structures/tools.md) · [ToolExecutionResult](../core-data-structures/tools.md)
Source: [`packages/core/tools/src/index.ts:319`](../../packages/core/tools/src/index.ts)
Source: [`packages/core/tools/src/index.ts:370`](../../packages/core/tools/src/index.ts)
## Inherited tier (cordis core + loader/hmr/timer)