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