changesetUri.ts ×16

Frontier kind: Code frontier

unlabeled · c_bb61b54687f6

1406 tests · 10352 LOC · 36 files · introduces 0 tests · 185 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges185 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
645 ranges10352 lines · 36 files · Browse complete extent
All tests (intent)
1406 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: 185 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/changesetUri.ts 185 introduced LOC · 16 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- changesetUri.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 { localize } from '../../../nls.js';
7 > import { readSessionGitState, readSessionWorkspaceless, SessionLifecycle, type Changeset, type ISessionGitState, type ISessionWithDefaultChat, type URI } from './state/sessionState.js';
8 >
9 > /**
10 > * Helpers for building / parsing the URI clients subscribe to in order to
11 > * receive a {@link import('./state/protocol/state.js').ChangesetState}.
12 > *
13 > * Shapes recognised by this module:
14 > *
15 > * <sessionUri>/changeset/uncommitted
16 > * <sessionUri>/changeset/session
17 > * <sessionUri>/changeset/turn/<turnId>
18 > * <sessionUri>/changeset/compare/<originalTurnId>/<modifiedTurnId>
19 > *
20 > * Catalogue entries on `summary.changesets` may also advertise the
21 > * URI-template forms `<sessionUri>/changeset/turn/{turnId}` and
22 > * `<sessionUri>/changeset/compare/{originalTurnId}/{modifiedTurnId}`;
23 > * clients expand the template before subscribing.
24 > *
25 > * Keeping changeset URIs nested under the session URI namespace lets the
26 > * server cleanly tear down every changeset for a session when that session
27 > * is disposed (the reverse-lookup is just a string-prefix scan).
28 > */
29 >
30 > /** /** Stable id of the catalogue entry for the branch changeset. */
31 > const BRANCH_CHANGESET_ID = 'branch';
32 >
33 > /** Stable id of the catalogue entry for the uncommitted-changes changeset. */
34 > const UNCOMMITTED_CHANGESET_ID = 'uncommitted';
35 >
36 > /** Stable id of the catalogue entry for the session-wide changeset. */
37 > const SESSION_CHANGESET_ID = 'session';
38 >
39 > /** Path prefix used by per-turn changeset URIs (`turn/<turnId>`). */
40 > const TURN_CHANGESET_PREFIX = 'turn/';
41 >
42 > /** Template variable name used inside the per-turn URI template. */
43 > const TURN_TEMPLATE_VARIABLE = '{turnId}';
44 >
45 > /** Path prefix used by compare-turns changeset URIs (`compare/<originalTurnId>/<modifiedTurnId>`). */
46 > const COMPARE_CHANGESET_PREFIX = 'compare/';
47 >
48 > /** Template variable name for the original turn in the compare-turns URI template. */
49 > const COMPARE_ORIGINAL_TEMPLATE_VARIABLE = '{originalTurnId}';
50 >
51 > /** Template variable name for the modified turn in the compare-turns URI template. */
52 > const COMPARE_MODIFIED_TEMPLATE_VARIABLE = '{modifiedTurnId}';
53 >
54 > /** Localized human-readable label for the branch changeset entry. */
55 > export const branchChangesetLabel = (): string => localize('branchChangeset.label', "Branch Changes");
56 >
57 > /** Localized human-readable label for the session-wide changeset entry. */
58 > export const sessionChangesetLabel = (): string => localize('sessionChangeset.label', "All Changes");
59 >
60 > /** Localized human-readable description for the session-wide changeset entry. */
61 > export const sessionChangesetDescription = (): string => localize('sessionChangeset.description', "Show all changes made in this session");
62 >
63 > /** Localized human-readable label for the uncommitted-changes changeset entry. */
64 > export const uncommittedChangesetLabel = (): string => localize('uncommittedChangeset.label', "Uncommitted Changes");
65 >
66 > /** Localized human-readable description for the uncommitted-changes changeset entry. */
67 > export const uncommittedChangesetDescription = (): string => localize('uncommittedChangeset.description', "Show uncommitted changes in this session");
68 >
69 > /** Localized human-readable label for the per-turn changeset template entry. */
70 > export const thisTurnChangesetLabel = (): string => localize('thisTurnChangeset.label', "This Turn");
71 >
72 > /** Localized human-readable description for the per-turn changeset template entry. */
73 > export const thisTurnChangesetDescription = (): string => localize('thisTurnChangeset.description', "Show changes made in this turn");
74 >
75 > /** Localized human-readable label for the compare-turns changeset template entry. */
76 > export const compareTurnsChangesetLabel = (): string => localize('compareTurnsChangeset.label', "Compare Turns");
77 >
78 > /** Localized human-readable description for the compare-turns changeset template entry. */
79 > export const compareTurnsChangesetDescription = (): string => localize('compareTurnsChangeset.description', "Show changes made between different turns");
80 >
81 > /**
82 > * Returns the description shown next to the `Branch Changes` catalogue
83 > * entry. Prefers `${branchName} → ${baseBranchName}` when both values
84 > * are known (typical worktree-isolation case). If `baseBranchName` is
85 > * unknown, falls back to `${branchName} → ${upstreamBranchName}` when an
86 > * upstream is available. Finally falls back to `branchName` alone.
87 > * Returns `undefined` only when no branch name is known at all, so
88 > * callers can omit the description entirely.
89 > */
90 > export function formatBranchChangesetDescription(gitState: ISessionGitState): string | undefined {
91 const { baseBranchName, branchName, upstreamBranchName } = gitState;
92
103 return branchName;
104 }
106 > /** Marker injected into a changeset URI's path. */
107 > const CHANGESET_PATH_SEGMENT = '/changeset/';
108 >
109 > /** Discriminates the well-known changeset URI shapes. */
110 > export const enum ChangesetKind {
111 > Branch = 'branch',
112 > Uncommitted = 'uncommitted',
113 > Session = 'session',
114 > Turn = 'turn',
115 > Compare = 'compare-turns',
116 > /** Producer-defined id we don't recognise (single-segment only). */
117 > Unknown = 'unknown',
118 > }
119 >
120 > export function buildBranchChangesetUri(sessionUri: URI): URI {
121 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${BRANCH_CHANGESET_ID}`;
122 }
124 > /** Returns the subscribable URI for the session-wide changeset. */
125 > export function buildSessionChangesetUri(sessionUri: URI): URI {
126 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${SESSION_CHANGESET_ID}`;
127 }
129 > /** Returns the subscribable URI for the uncommitted-changes changeset. */
130 > export function buildUncommittedChangesetUri(sessionUri: URI): URI {
131 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${UNCOMMITTED_CHANGESET_ID}`;
132 }
134 > /**
135 > * Returns the URI _template_ that catalogue entries advertise for the
136 > * per-turn changeset; clients expand `{turnId}` to build the
137 > * subscribable URI via {@link buildTurnChangesetUri}.
138 > */
139 > export function buildTurnChangesetUriTemplate(sessionUri: URI): URI {
140 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${TURN_CHANGESET_PREFIX}${TURN_TEMPLATE_VARIABLE}`;
141 }
143 > /** Returns the subscribable URI for the per-turn changeset of `turnId`. */
144 > export function buildTurnChangesetUri(sessionUri: URI, turnId: string): URI {
145 if (!turnId || turnId.includes('/')) {
146 throw new Error(`buildTurnChangesetUri: turnId must be non-empty and not contain '/' (got ${JSON.stringify(turnId)})`);
148 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${TURN_CHANGESET_PREFIX}${turnId}`;
149 }
151 > /**
152 > * Returns the URI _template_ that catalogue entries advertise for the
153 > * compare-turns changeset; clients expand both `{originalTurnId}` and
154 > * `{modifiedTurnId}` to build the subscribable URI via
155 > * {@link buildCompareTurnsChangesetUri}.
156 > */
157 > export function buildCompareTurnsChangesetUriTemplate(sessionUri: URI): URI {
158 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${COMPARE_CHANGESET_PREFIX}${COMPARE_ORIGINAL_TEMPLATE_VARIABLE}/${COMPARE_MODIFIED_TEMPLATE_VARIABLE}`;
159 }
161 > /**
162 > * Returns the subscribable URI for the compare-turns changeset between
163 > * `originalTurnId` (the "from" endpoint) and `modifiedTurnId` (the "to"
164 > * endpoint). Diff direction is `originalTurnId → modifiedTurnId`.
165 > */
166 > export function buildCompareTurnsChangesetUri(sessionUri: URI, originalTurnId: string, modifiedTurnId: string): URI {
167 if (!originalTurnId || originalTurnId.includes('/')) {
168 throw new Error(`buildCompareTurnsChangesetUri: originalTurnId must be non-empty and not contain '/' (got ${JSON.stringify(originalTurnId)})`);
173 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${COMPARE_CHANGESET_PREFIX}${originalTurnId}/${modifiedTurnId}`;
174 }
176 > /**
177 > * Returns the subscribable URI for an opaque, producer-defined
178 > * `changesetId`. The id must not contain `/` — well-known multi-segment
179 > * shapes have dedicated builders (e.g. {@link buildTurnChangesetUri}).
180 > */
181 > export function buildChangesetUri(sessionUri: URI, changesetId: string): URI {
182 if (!changesetId) {
183 throw new Error('buildChangesetUri: changesetId must be non-empty');
188 return `${sessionUri}${CHANGESET_PATH_SEGMENT}${changesetId}`;
189 }
191 > /**
192 > * Parses a changeset URI back into `(sessionUri, changesetId, kind)`,
193 > * or returns `undefined` if `uri` is not a changeset URI we recognise.
194 > */
195 > export function parseChangesetUri(uri: URI): { sessionUri: URI; changesetId: string; kind: ChangesetKind; turnId?: string; originalTurnId?: string; modifiedTurnId?: string } | undefined {
196 const idx = uri.lastIndexOf(CHANGESET_PATH_SEGMENT);
197 if (idx < 0) {
241 return { sessionUri, changesetId, kind: ChangesetKind.Unknown };
242 }
244 > /** Returns `true` iff `uri` looks like a changeset URI we recognise. */
245 > export function isChangesetUri(uri: URI): boolean {
246 return parseChangesetUri(uri) !== undefined;
247 }
249 > /** Returns `true` iff `uri` is the session-wide changeset URI. */
250 > export function isSessionChangesetUri(uri: URI): boolean {
251 return parseChangesetUri(uri)?.kind === ChangesetKind.Session;
252 }
254 > /** Returns `true` iff `uri` is the uncommitted-changes changeset URI. */
255 > export function isUncommittedChangesetUri(uri: URI): boolean {
256 return parseChangesetUri(uri)?.kind === ChangesetKind.Uncommitted;
257 }
259 > /** Returns the parsed turn id when `uri` is a per-turn changeset URI. */
260 > export function parseTurnChangesetUri(uri: URI): { sessionUri: URI; turnId: string } | undefined {
261 const parsed = parseChangesetUri(uri);
262 if (parsed?.kind !== ChangesetKind.Turn || parsed.turnId === undefined) {
265 return { sessionUri: parsed.sessionUri, turnId: parsed.turnId };
266 }
268 > /** Returns the parsed turn ids when `uri` is a compare-turns changeset URI. */
269 > export function parseCompareTurnsChangesetUri(uri: URI): { sessionUri: URI; originalTurnId: string; modifiedTurnId: string } | undefined {
270 const parsed = parseChangesetUri(uri);
271 if (parsed?.kind !== ChangesetKind.Compare || parsed.originalTurnId === undefined || parsed.modifiedTurnId === undefined) {
274 return { sessionUri: parsed.sessionUri, originalTurnId: parsed.originalTurnId, modifiedTurnId: parsed.modifiedTurnId };
275 }
277 > /**
278 > * Builds the default ordered `summary.changesets` catalogue for a
279 > * session (`Branch Changes`, `Uncommitted Changes`, `This Turn`) with
280 > * label + uriTemplate only. Aggregate counts are filled in later by the
281 > * diff producer as compute passes complete.
282 > *
283 > * The first two entries (`Branch Changes`, `Uncommitted Changes`) are
284 > * git-only; `AgentService._attachGitState` strips them asynchronously
285 > * for sessions whose working directory is not a git repo. The backing
286 > * per-changeset states are still registered for every session — only
287 > * the catalogue advertisements are stripped.
288 > *
289 > * The compare-turns changeset (built by
290 > * {@link buildCompareTurnsChangesetUri}) is intentionally NOT included
291 > * in the default catalogue: it is subscribe-only. Clients that want
292 > * compare-turns diffs construct the URI themselves from two known
293 > * turn ids and subscribe directly.
294 > */
295 > export function buildDefaultChangesetCatalog(sessionUri: URI, state?: ISessionWithDefaultChat): Changeset[] {
296 // Session that failed to create
297 if (!state || state.lifecycle === SessionLifecycle.CreationFailed) {