sessionDiffAggregator.ts ×5

Frontier kind: Code frontier

unlabeled · c_c8f6261aafc3

502 tests · 19807 LOC · 64 files · introduces 0 tests · 116 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
5 ranges116 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1716 ranges19807 lines · 64 files · Browse complete extent
All tests (intent)
502 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: 116 introduced LOC across 5 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/sessionDiffAggregator.ts 116 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- sessionDiffAggregator.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 { URI } from '../../../base/common/uri.js';
7 > import type { IFileEditRecord, ISessionDatabase } from '../common/sessionDataService.js';
8 > import type { IDiffComputeService } from '../common/diffComputeService.js';
9 > import { FileEditKind, type ISessionFileDiff } from '../common/state/sessionState.js';
10 > import { buildSessionDbUri } from './shared/fileEditTracker.js';
11 >
12 function getFileEditUri(diff: ISessionFileDiff): string | undefined {
13 return diff.after?.uri ?? diff.before?.uri;
14 }
16 function createSessionFileDiff(beforeSessionUri: string, afterSessionUri: string, identity: IFileIdentity, added: number, removed: number): ISessionFileDiff {
17 const hasBefore = identity.firstKind !== FileEditKind.Create;
33 };
34 }
36 > /**
37 > * Represents a file's identity across renames, tracking its first and last
38 > * snapshots in the session for diff computation.
39 > */
40 > interface IFileIdentity {
41 > /** The last known URI for this file. */
42 > terminalPath: string;
43 > /** Tool call ID of the first edit (for fetching "before" content). */
44 > firstToolCallId: string;
45 > /** File path used in the first edit's database record. */
46 > firstFilePath: string;
47 > /** The kind of the first edit (Create means no "before" content). */
48 > firstKind: FileEditKind;
49 > /** Index into the sources array of the DB that owns the first edit. */
50 > firstSourceIdx: number;
51 > /** Tool call ID of the last edit (for fetching "after" content). */
52 > lastToolCallId: string;
53 > /** File path used in the last edit's database record. */
54 > lastFilePath: string;
55 > /** The kind of the last edit (Delete means no "after" content). */
56 > lastKind: FileEditKind;
57 > /** Index into the sources array of the DB that owns the last edit. */
58 > lastSourceIdx: number;
59 > }
60 >
61 > /**
62 > * A single database whose file edits contribute to a session's aggregated
63 > * diff. For single-chat sessions there is one source (the session DB); for
64 > * multi-chat sessions each peer chat records edits into its own DB, so the
65 > * session changeset unions the session DB with every peer chat DB.
66 > */
67 > export interface ISessionDiffSource {
68 > /**
69 > * The session / peer-chat URI that owns {@link db}. Encoded into the
70 > * `session-db:` content URIs so the resource resolver opens the correct
71 > * database when fetching before/after blobs.
72 > */
73 > sessionUri: string;
74 > /** The database holding this source's file edits. */
75 > db: ISessionDatabase;
76 > }
77 >
78 > /**
79 > * Options for incremental diff computation. When provided,
80 > * {@link computeSessionDiffs} reuses previous diff results for file
81 > * identities that were not touched in the given turn.
82 > */
83 > export interface IIncrementalDiffOptions {
84 > /** The turn ID that just completed — only identities touched by edits
85 > * in this turn will be recomputed. */
86 > changedTurnId: string;
87 > /** Previously computed diffs (from the last dispatch). Entries for
88 > * untouched identities are carried over without recomputation. */
89 > previousDiffs: ISessionFileDiff[];
90 > }
91 >
92 > /**
93 > * Computes aggregated diff statistics for a session by comparing each file's
94 > * first snapshot to its last snapshot, tracking renames across the chain.
95 > *
96 > * When {@link incremental} is provided, only identities that were touched
97 > * by edits in the given turn are recomputed; all other identities reuse
98 > * the previous diff results. This avoids expensive content fetches and
99 > * diff computations for unchanged files.
100 > *
101 > * Returns an {@link ISessionFileDiff} array with the "last known URI" for each
102 > * file and the total lines added/removed across the session.
103 > */
104 export async function computeSessionDiffs(
105 sessionUri: string,
259 return results;
260 }
262 > /**
263 > * Computes aggregated diff statistics across one or more {@link ISessionDiffSource}
264 > * databases by unioning their file edits and comparing each file's first
265 > * snapshot to its last snapshot, tracking renames across the chain.
266 > *
267 > * Single-chat sessions pass one source (the session DB). Multi-chat sessions
268 > * pass the session DB plus every peer chat DB so peer-chat edits (recorded into
269 > * their own databases) roll up into the session-level changes. Each file
270 > * identity remembers which source owns its first and last snapshots so the
271 > * before/after content is read from — and its `session-db:` content URI encodes —
272 > * the correct database.
273 > *
274 > * Sources are unioned in array order (session first, peers next); within a
275 > * source, edits keep their insertion order. When a file is touched by more than
276 > * one source the "before" comes from the earliest source that touched it and the
277 > * "after" from the latest, which matches the shared working tree the chats edit.
278 > *
279 > * TODO (debt): this always does a full recompute — it ignores the
280 > * {@link IIncrementalDiffOptions} fast/slow paths that {@link computeSessionDiffs}
281 > * uses for single-source sessions. An incremental union is a safe follow-up:
282 > * the per-identity `firstSourceIdx`/`lastSourceIdx` already carry the provenance
283 > * needed to recompute only the turn's owning source plus cross-source files and
284 > * carry over the rest. Requires plumbing the owning source of `changedTurnId`
285 > * through `onTurnComplete` → `_doComputeStaticChangeset`. See tracking issue.
286 > */
287 export async function computeUnionedDiffs(
288 sources: readonly ISessionDiffSource[],
376 return results;
377 }
379 > /**
380 > * Computes the diff statistics for a single turn — files touched only
381 > * within `turnId`, with their `before` snapshot taken from the first edit
382 > * record in that turn and their `after` snapshot from the last. Used by
383 > * the per-turn changeset (`<session>/changeset/turn/<turnId>`).
384 > *
385 > * Returns an empty array when the turn touched no files.
386 > */
387 export async function computeTurnDiffs(
388 sessionUri: string,