fileEditTracker.ts ×9

Frontier kind: Code frontier

unlabeled · c_18b097e4604d

1043 tests · 19568 LOC · 62 files · introduces 0 tests · 129 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges129 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1678 ranges19568 lines · 62 files · Browse complete extent
All tests (intent)
1043 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.

2 files ranked by introduced lines: 129 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/fileEditTracker.ts 96 introduced LOC · 9 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- fileEditTracker.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 { decodeHex, encodeHex, VSBuffer } from '../../../../base/common/buffer.js';
7 > import { basename } from '../../../../base/common/path.js';
8 > import { URI } from '../../../../base/common/uri.js';
9 > import { IFileService } from '../../../files/common/files.js';
10 > import { ILogService } from '../../../log/common/log.js';
11 > import { IDiffComputeService } from '../../common/diffComputeService.js';
12 > import { ISessionDatabase } from '../../common/sessionDataService.js';
13 > import { FileEditKind, ToolResultContentType, type ToolResultFileEditContent } from '../../common/state/sessionState.js';
14 > import { extractAiChunks } from './editChunkExtractor.js';
15 > import { IEditSurvivalReporterFactory } from './editSurvivalReporter.js';
16 >
17 > const SESSION_DB_SCHEME = 'session-db';
18 >
19 > /**
20 > * Builds a `session-db:` URI that references a file-edit content blob
21 > * stored in the session database. Parsed by {@link parseSessionDbUri}.
22 > */
23 > export function buildSessionDbUri(sessionUri: string, toolCallId: string, filePath: string, part: 'before' | 'after'): string {
24 return URI.from({
25 scheme: SESSION_DB_SCHEME,
28 }).toString();
29 }
31 > /** Parsed fields from a `session-db:` content URI. */
32 > export interface ISessionDbUriFields {
33 > sessionUri: string;
34 > toolCallId: string;
35 > filePath: string;
36 > part: 'before' | 'after';
37 > }
38 >
39 > /**
40 > * Parses a `session-db:` URI produced by {@link buildSessionDbUri}.
41 > * Returns `undefined` if the URI is not a valid `session-db:` URI.
42 > */
43 > export function parseSessionDbUri(raw: string): ISessionDbUriFields | undefined {
44 const parsed = URI.parse(raw);
45 if (parsed.scheme !== SESSION_DB_SCHEME) {
61 }
62 }
64 > /**
65 > * Tracks file edits made by tools in a session by snapshotting file content
66 > * before and after each edit tool invocation, persisting snapshots into the
67 > * session database.
68 > */
69 > export class FileEditTracker {
70 >
71 > /**
72 > * Pending edits keyed by file path. Populated by {@link trackEditStart}
73 > * before the edit tool runs; popped by {@link completeEdit} when it
74 > * finishes.
75 > */
76 > private readonly _pendingEdits = new Map<string, { beforeContent: VSBuffer; beforeExisted: boolean; snapshotDone: Promise<void> }>();
77 >
78 > /**
79 > * Completed edits keyed by file path. Populated by {@link completeEdit};
80 > * drained by {@link takeCompletedEdit}, which persists the entry to
81 > * the database.
82 > */
83 > private readonly _completedEdits = new Map<string, { beforeContent: VSBuffer; beforeExisted: boolean; afterContent: VSBuffer }>();
84 >
85 > constructor(
86 private readonly _sessionUri: string,
87 private readonly _db: ISessionDatabase,
91 @IEditSurvivalReporterFactory private readonly _editSurvivalReporterFactory: IEditSurvivalReporterFactory,
92 ) { }
94 > /**
95 > * Call before an edit tool runs. Reads the file's current content
96 > * into memory as the "before" state. Callers should await this so
97 > * the snapshot captures pre-edit content before the tool writes to
98 > * disk.
99 > *
100 > * @param filePath - Absolute path of the file being edited.
101 > */
102 > async trackEditStart(filePath: string): Promise<void> {
103 const snapshotDone = this._readFileWithExistence(filePath);
104 const entry = {
113 await entry.snapshotDone;
114 }
116 > /**
117 > * Call after an edit tool finishes. Reads the file content again as
118 > * the "after" state and stores the result for later retrieval via
119 > * {@link takeCompletedEdit}.
120 > *
121 > * @param filePath - Absolute path of the file that was edited.
122 > */
123 > async completeEdit(filePath: string): Promise<void> {
124 const pending = this._pendingEdits.get(filePath);
125 if (!pending) {
137 });
138 }
140 > /**
141 > * Retrieves and removes a completed edit for the given file path,
142 > * persists it to the session database with computed diff counts,
143 > * and returns the result as an {@link ToolResultFileEditContent}
144 > * for inclusion in the tool result.
145 > *
146 > * `toolName` and `toolInput` are forwarded to {@link extractAiChunks}
147 > * for region-based survival scoring; unknown shapes fall back to
148 > * whole-file scoring.
149 > */
150 > async takeCompletedEdit(turnId: string, toolCallId: string, filePath: string, toolName: string, toolInput: unknown, modelId: string | undefined): Promise<ToolResultFileEditContent | undefined> {
151 const edit = this._completedEdits.get(filePath);
152 if (!edit) {
217 };
218 }
220 > private async _readFile(filePath: string): Promise<VSBuffer> {
221 try {
222 const content = await this._fileService.readFile(URI.file(filePath));
227 }
228 }
230 > private async _readFileWithExistence(filePath: string): Promise<{ content: VSBuffer; existed: boolean }> {
231 try {
232 const content = await this._fileService.readFile(URI.file(filePath));
src/vs/platform/agentHost/common/diffComputeService.ts 33 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- diffComputeService.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 { createDecorator } from '../../instantiation/common/instantiation.js';
7 >
8 > export interface IDiffCountResult {
9 > added: number;
10 > removed: number;
11 > }
12 >
13 > export const IDiffComputeService = createDecorator<IDiffComputeService>('diffComputeService');
14 >
15 > /** Default timeout for diff computation in milliseconds. */
16 > export const DEFAULT_DIFF_TIMEOUT_MS = 5000;
17 >
18 > /**
19 > * Service that computes line diff counts (added/removed) between two
20 > * text strings. Implementations may offload computation to a worker
21 > * thread to avoid blocking the main thread.
22 > */
23 > export interface IDiffComputeService {
24 > readonly _serviceBrand: undefined;
25 >
26 > /**
27 > * Computes line-level diff counts between two text strings.
28 > * @param original - The original text.
29 > * @param modified - The modified text to compare against the original.
30 > * @param timeoutMs - Maximum time in milliseconds before aborting. Defaults to {@link DEFAULT_DIFF_TIMEOUT_MS}.
31 > */
32 > computeDiffCounts(original: string, modified: string, timeoutMs?: number): Promise<IDiffCountResult>;
33 > }