sessionDiffAggregator.ts ×17

Frontier kind: Code frontier

unlabeled · c_c3547c7f8cab

8 tests · 20091 LOC · 64 files · introduces 0 tests · 85 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges85 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1795 ranges20091 lines · 64 files · Browse complete extent
All tests (intent)
8 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: 85 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/sessionDiffAggregator.ts 85 introduced LOC · 17 ranges

Open complete file

10 import { buildSessionDbUri } from './shared/fileEditTracker.js';
11
12 > function getFileEditUri(diff: ISessionFileDiff): string | undefined { sessionDiffAggregator.ts
13 > return diff.after?.uri ?? diff.before?.uri;
14 > }
15
16 function createSessionFileDiff(beforeSessionUri: string, afterSessionUri: string, identity: IFileIdentity, added: number, removed: number): ISessionFileDiff {
125 return [...incremental.previousDiffs];
126 }
128 > const previousDiffsUris = new Set(incremental.previousDiffs.map(getFileEditUri));
129 > const needsFullHistory = turnEdits.some(e =>
130 > e.kind === FileEditKind.Rename ||
131 previousDiffsUris.has(URI.file(e.filePath).toString())
133 >
134 > if (needsFullHistory) {
135 edits = await db.getAllFileEdits();
136 > } else { sessionDiffAggregator.ts
137 edits = turnEdits;
138 fastPath = true;
139 }
141 > if (edits.length === 0) {
142 return [];
143 }
145 > // Build file identity graph. We need to:
146 > // 1. Track renames: when a file is renamed A→B, its identity follows to B
147 > // 2. Find the first "before" snapshot and last "after" snapshot per identity
148 >
149 > // Maps a file path to its canonical identity key (follows rename chains)
150 > const pathToIdentityKey = new Map<string, string>();
151 > // Maps identity keys to their accumulated data
152 > const identities = new Map<string, IFileIdentity>();
153 > // Track which identity keys were touched by the incremental turn.
154 > // In fast-path mode all identities are from the current turn, so no tracking needed.
155 const touchedIdentityKeys = !fastPath ? new Set<string>() : undefined;
156
157 for (const edit of edits) {
158 > let identityKey: string; sessionDiffAggregator.ts
159 >
160 > if (edit.kind === FileEditKind.Rename && edit.originalPath) {
161 // Rename: follow the chain from originalPath to find the identity
162 identityKey = pathToIdentityKey.get(edit.originalPath) ?? edit.originalPath;
165 // Remove old path mapping (the file no longer exists at that path)
166 pathToIdentityKey.delete(edit.originalPath);
167 > } else { sessionDiffAggregator.ts
168 > // Regular edit, create, or delete: look up or create identity
169 > identityKey = pathToIdentityKey.get(edit.filePath) ?? edit.filePath;
170 > pathToIdentityKey.set(edit.filePath, identityKey);
171 > }
172 >
173 > if (touchedIdentityKeys && edit.turnId === incremental.changedTurnId) {
174 touchedIdentityKeys.add(identityKey);
175 }
177 > const existing = identities.get(identityKey);
178 > if (!existing) {
179 > // First time seeing this file identity
180 > identities.set(identityKey, {
181 > terminalPath: edit.filePath,
182 > firstToolCallId: edit.toolCallId,
183 > firstFilePath: edit.kind === FileEditKind.Rename && edit.originalPath ? edit.originalPath : edit.filePath,
184 > firstKind: edit.kind,
185 > firstSourceIdx: 0,
186 > lastToolCallId: edit.toolCallId,
187 > lastFilePath: edit.filePath,
188 > lastKind: edit.kind,
189 > lastSourceIdx: 0,
190 > });
191 > } else {
192 // Update last snapshot info and terminal path
193 existing.terminalPath = edit.filePath;
196 existing.lastKind = edit.kind;
197 }
199 >
200 > // In incremental slow-path mode, build a lookup map from URI string →
201 > // previous diff so untouched identities can carry over their previous results.
202 > const previousDiffsMap = !fastPath
203 ? new Map(incremental.previousDiffs.map(d => [getFileEditUri(d), d]))
204 : undefined;
209
210 for (const [identityKey, identity] of identities) {
211 > // In incremental slow-path mode, skip recomputation for untouched identities sessionDiffAggregator.ts
212 > if (touchedIdentityKeys && !touchedIdentityKeys.has(identityKey)) {
213 const uri = URI.file(identity.terminalPath).toString();
214 const prev = previousDiffsMap!.get(uri);
219 continue;
220 }
222 > diffPromises.push((async () => {
223 > // Determine "before" text
224 > let beforeText: string;
225 > if (identity.firstKind === FileEditKind.Create) {
226 beforeText = '';
227 > } else { sessionDiffAggregator.ts
228 const content = await db.readFileEditContent(identity.firstToolCallId, identity.firstFilePath);
229 beforeText = content?.beforeContent ? new TextDecoder().decode(content.beforeContent) : '';
230 }
232 > // Determine "after" text
233 > let afterText: string;
234 > if (identity.lastKind === FileEditKind.Delete) {
235 afterText = '';
236 > } else { sessionDiffAggregator.ts
237 > const content = await db.readFileEditContent(identity.lastToolCallId, identity.lastFilePath);
238 > afterText = content?.afterContent ? new TextDecoder().decode(content.afterContent) : '';
239 > }
240 >
241 > // Skip files with no net change
242 > if (beforeText === afterText) {
243 return;
244 }
246 const counts = await diffService.computeDiffCounts(beforeText, afterText);
247 results.push(createSessionFileDiff(sessionUri, sessionUri, identity, counts.added, counts.removed));
249 > }
250 >
251 > await Promise.allSettled(diffPromises);
252 >
253 > // In fast-path mode, carry over previous diffs for untouched files
254 > // (they were not in the identity graph since we only loaded the current turn)
255 > if (fastPath) {
256 results.push(...incremental.previousDiffs);
257 }
259 > return results;
260 > }
261
262 /**