claudeFileEditObserver.ts ×4

Frontier kind: Code frontier

unlabeled · c_8bd7b4a9e40b

225 tests · 27523 LOC · 124 files · introduces 0 tests · 78 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
4 ranges78 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2245 ranges27523 lines · 124 files · Browse complete extent
All tests (intent)
225 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 78 introduced LOC across 4 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/claude/claudeFileEditObserver.ts 78 introduced LOC · 4 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- claudeFileEditObserver.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
7 > import { Disposable, IReference } from '../../../../base/common/lifecycle.js';
8 > import { IInstantiationService } from '../../../instantiation/common/instantiation.js';
9 > import { ILogService } from '../../../log/common/log.js';
10 > import { ISessionDatabase } from '../../common/sessionDataService.js';
11 > import { FileEditTracker } from '../shared/fileEditTracker.js';
12 > import type { ClaudeMapperState } from './claudeMapSessionEvents.js';
13 > import { getClaudeToolPath, isClaudeFileEditTool } from './claudeToolDisplay.js';
14 >
15 > /**
16 > * Phase 8 — file-edit observation off the SDK message stream.
17 > *
18 > * Owns the {@link FileEditTracker}, the in-flight `tool_use_id → path`
19 > * map, and the dbRef whose lifetime gates persistence writes. Snapshots
20 > * before-content when an assistant `tool_use` block arrives, snapshots
21 > * after-content when the matching synthetic `tool_result` arrives, and
22 > * stages a {@link ToolResultFileEditContent} on the session's
23 > * {@link ClaudeMapperState} so the synchronous mapper can attach it to
24 > * the `ChatToolCallComplete` action.
25 > *
26 > * Hooks (`Options.hooks.PreToolUse` / `Options.hooks.PostToolUse`) are
27 > * deliberately NOT used: they are user-bypassable via settings, whereas
28 > * the SDK message stream is the canonical, non-bypassable signal that
29 > * a tool will run. Mirrors the production extension's dispatch-time
30 > * observation (extensions/copilot/.../claudeMessageDispatch.ts:200) —
31 > * see the comment there about `bypassPermissions` and internal SDK
32 > * paths that skip `canUseTool`.
33 > *
34 > * Best-effort: the SDK proceeds to run the tool concurrently after
35 > * yielding the `tool_use` block, so {@link observeAssistant}'s before-
36 > * snapshot races against tool execution. Tool execution involves disk
37 > * I/O before the write, which gives enough microtask headroom in
38 > * practice; same guarantee the production extension relies on with
39 > * `stream.externalEdit`.
40 > */
41 > export class ClaudeFileEditObserver extends Disposable {
42 >
43 > private readonly _editTracker: FileEditTracker;
44 >
45 > /**
46 > * Maps SDK `tool_use_id` → file path + raw tool input + model
47 > * captured when the SDK yields the assistant `tool_use` block in
48 > * {@link observeAssistant}. Consumed (and removed) by
49 > * {@link observeUser} when the matching `tool_result` arrives.
50 > * The raw input is forwarded to
51 > * {@link FileEditTracker.takeCompletedEdit} so it can extract the
52 > * AI-written text chunks for the edit-survival reporter. The
53 > * model is read off the assistant message body and is naturally
54 > * per-subagent: when a subagent emits the `tool_use`, its model
55 > * (not the parent's) is what we record.
56 > */
57 > private readonly _editToolPaths = new Map<string, { readonly filePath: string; readonly toolName: string; readonly toolInput: unknown; readonly modelId: string | undefined }>();
58 >
59 > constructor(
60 sessionUri: string,
61 dbRef: IReference<ISessionDatabase>,
76 );
77 }
79 > /**
80 > * Snapshot before-content for any file-edit `tool_use` blocks
81 > * carried by an SDK assistant message. Caller must invoke this when
82 > * the SDK yields a canonical `'assistant'` message (full
83 > * `tool_use.input` available).
84 > */
85 > observeAssistant(message: Extract<SDKMessage, { type: 'assistant' }>): void {
86 const content = message.message.content;
87 if (!Array.isArray(content)) {
102 }
103 }
105 > /**
106 > * Take after-content snapshots and stage
107 > * {@link ToolResultFileEditContent} entries on `mapperState` for any
108 > * `tool_result` blocks carried by an SDK user message. Caller MUST
109 > * await this BEFORE invoking the synchronous mapper, so the cached
110 > * file edit is already on `mapperState` when `mapUserMessage` calls
111 > * `state.takeFileEdit`.
112 > */
113 > async observeUser(
114 message: Extract<SDKMessage, { type: 'user' }>,
115 turnId: string,