src/vs/platform/agentHost/common/agentHostCheckpointService.ts
114 LOC · 112 covered · 2 uncovered · 2 ranges · 1462 concepts · 1 introducers · 677 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
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 related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
agentHostCheckpointService.ts ×2
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from '../../../base/common/uri.js';
import { createDecorator } from '../../instantiation/common/instantiation.js';
export const IAgentHostCheckpointService = createDecorator<IAgentHostCheckpointService>('agentHostCheckpointService');
/**
* `session_metadata` key under which the per-session baseline (turn/0)
* checkpoint ref is stored.
*/
export const META_CHECKPOINT_BASE_REF = 'checkpoint.baseRef';
/**
* Returns the canonical name for a per-turn checkpoint ref.
* Distinct from the chat extension's `refs/sessions/...` so the two can
* coexist safely in the same repository.
*/
export function buildCheckpointRefName(sanitizedSessionId: string, turnNumber: number): string {
return `refs/agents/${sanitizedSessionId}/checkpoints/turn/${turnNumber}`;
}
/**
* Captures per-turn git **checkpoint refs** for Agent Host sessions so
* end-of-turn diffs reflect the entire working-tree delta (including
* terminal-tool edits that are invisible to the FileEditTracker pipeline).
*
* Each checkpoint is a parentless or parent-chained commit (commit-tree)
* pointing at a tree captured via the temp-index trick, anchored under
* `refs/agents/<sid>/checkpoints/turn/<N>`. The session-private ref
* namespace means the commits stay reachable for the lifetime of the
* session and survive process restarts (refs live on disk in
* `<repo>/.git/refs/`), while never appearing as branches/tags to the
* user. Cleanup is driven by `ISessionDataService.onWillDeleteSessionData`
* — the service deletes every ref it created for the destroyed session
* before the data directory is removed.
*/
export interface IAgentHostCheckpointService {
readonly _serviceBrand: undefined;
/**
* Captures the session's baseline (turn/0) checkpoint. Idempotent: if
* a baseline already exists for the session, returns the existing ref.
* Returns `undefined` when the working directory is not a git work tree
* (folder-isolation against a non-git folder) or when checkpoint
* capture fails.
*
* Called once per session, immediately after the session's working
* directory has been resolved and any worktree metadata has been
* persisted (e.g. `CopilotAgent._materializeProvisional`).
*/
captureBaseline(sessionUri: URI, workingDirectory: URI | undefined): Promise<string | undefined>;
/**
* Captures an end-of-turn checkpoint, chained to the previous turn's
* checkpoint (or the baseline for turn 1). Persists the ref against
* the turn via `ISessionDatabase.setTurnCheckpointRef`. Returns
* `undefined` when the session is not git-backed, the baseline is
* missing, or capture fails.
*
* If the captured tree OID matches the parent's tree OID (no-op turn)
* the parent ref is recorded against the turn rather than creating a
* redundant commit / new ref.
*
* Called from `AgentSideEffects` when a `ChatTurnComplete` action
* fires, BEFORE the changeset service's `onTurnComplete` hook so the
* per-turn changeset compute can pick up the new refs.
*/
captureTurnCheckpoint(sessionUri: URI, turnId: string): Promise<string | undefined>;
/**
* Returns the `{ parent, current }` checkpoint refs for a turn, or
* `undefined` when either is missing. Used by the changeset service
* to decide whether to take the git-diff fast path for per-turn diffs.
*/
getTurnCheckpointPair(sessionUri: URI, turnId: string): Promise<{ parent: string; current: string } | undefined>;
/**
* Returns the session's baseline checkpoint ref, or `undefined` when
* the baseline was never captured (non-git-backed session, or capture
* failed). Used by the changeset service to resolve compare-turns
* URIs whose `originalTurnId` is the `BASELINE_TURN_ID` sentinel.
*/
getBaselineCheckpointRef(sessionUri: URI): Promise<string | undefined>;
/**
* Deletes every checkpoint ref this service created for the session
* (baseline + all turn refs), reading the precise list from the
* session database. Tolerates missing refs.
*
* Called from a subscriber to `ISessionDataService.onWillDeleteSessionData`
* before the session's data directory is removed.
*/
disposeSessionData(sessionUri: URI): Promise<void>;
}
/**
* A no-op implementation of {@link IAgentHostCheckpointService} used as a
* fallback in test fixtures that don't exercise checkpoint capture, and
* as the default value for the optional `_checkpointService` parameter
* on `AgentService` so existing test callsites keep compiling without
* forced fixture updates.
*/
export const NULL_CHECKPOINT_SERVICE: IAgentHostCheckpointService = {
_serviceBrand: undefined,
captureBaseline: async () => undefined,
captureTurnCheckpoint: async () => undefined,
getTurnCheckpointPair: async () => undefined,
getBaselineCheckpointRef: async () => undefined,
disposeSessionData: async () => { },
};