1
>
/*---------------------------------------------------------------------------------------------
agentHostReviewService.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 { URI as ProtocolURI } from './state/sessionState.js';
8
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
9
>
10
>
export const IAgentHostReviewService = createDecorator<IAgentHostReviewService>('agentHostReviewService');
11
>
12
>
/**
13
>
* Returns the canonical name for a session's synthetic **reviewed** ref.
14
>
* Lives under the same `refs/agents/<sid>/…` namespace as checkpoint refs so
15
>
* the two coexist safely and never surface to the user as branches/tags.
16
>
*/
17
>
export function buildReviewedRefName(sanitizedSessionId: string): string {
18
return `refs/agents/${sanitizedSessionId}/reviewed`;
19
}
21
>
/**
22
>
* Tracks which files in a session's **Branch Changes** the user has reviewed,
23
>
* as a session-private synthetic git ref (`refs/agents/<sid>/reviewed`) whose
24
>
* tree snapshots the reviewed content. A file is reviewed when its content in
25
>
* the reviewed tree matches the current working tree; re-editing a reviewed
26
>
* file therefore auto-unreviews it.
27
>
*
28
>
* All operations are keyed on the Branch Changes baseline (the merge-base of
29
>
* `HEAD` and the session's base branch). The `baseBranch` argument is the
30
>
* already-resolved base-branch **name** (see `resolveDiffBaseBranchName`),
31
>
* shared with the changeset service so both agree on the baseline.
32
>
*
33
>
* Operations are no-ops when the working directory is not inside a git
34
>
* repository; a future milestone will add a non-git fallback (see the
35
>
* DB-backed reviewed-file store on `ISessionDatabase`).
36
>
*/
37
>
export interface IAgentHostReviewService {
38
>
readonly _serviceBrand: undefined;
39
>
40
>
/**
41
>
* Persists the review state for files in a local Branch Changes changeset.
42
>
*/
43
>
setReviewState(channel: ProtocolURI, resources: readonly ProtocolURI[], reviewed: boolean): Promise<void>;
44
>
45
>
/**
46
>
* Marks a single file reviewed at its current working-tree content by
47
>
* overlaying that content into the reviewed tree and advancing the
48
>
* reviewed ref. No-op when the file is already reviewed at that content.
49
>
*/
50
>
markFileReviewed(session: ProtocolURI, workingDirectory: URI, baseBranch: string | undefined, resource: URI): Promise<void>;
51
>
52
>
/**
53
>
* Marks a single file as unreviewed by resetting its entry in the
54
>
* reviewed tree back to the baseline content and advancing the reviewed
55
>
* ref. No-op when the file is not currently reviewed.
56
>
*/
57
>
markFileUnreviewed(session: ProtocolURI, workingDirectory: URI, baseBranch: string | undefined, resource: URI): Promise<void>;
58
>
59
>
/**
60
>
* Returns the set of reviewed repo-relative paths within the current Branch
61
>
* Changes: the changed files whose reviewed-tree content matches the
62
>
* working tree. Empty when nothing is reviewed or the directory is not a
63
>
* git work tree.
64
>
*/
65
>
getReviewedPaths(session: ProtocolURI, workingDirectory: URI, baseBranch: string | undefined): Promise<ReadonlySet<string>>;
66
>
67
>
/**
68
>
* Copies the reviewed ref from `sourceSessionUri` to `targetSessionUri` so a
69
>
* forked session starts with the parent's review progress. Points the
70
>
* target's reviewed ref at the same commit as the source's (git objects are
71
>
* shared within the repository). No-op when the source has no reviewed ref or
72
>
* the directory is not a git work tree.
73
>
*/
74
>
copyReviewedRef(sourceSession: ProtocolURI, targetSession: ProtocolURI, workingDirectory: URI): Promise<void>;
75
>
}
76
>
77
>
/**
78
>
* A no-op {@link IAgentHostReviewService} used as the default for the optional
79
>
* `_reviewService` parameter on `AgentService` so existing test callsites keep
80
>
* compiling without forced fixture updates.
81
>
*/
82
>
export const NULL_REVIEW_SERVICE: IAgentHostReviewService = {
83
>
_serviceBrand: undefined,
84
>
setReviewState: async () => { },
85
>
markFileReviewed: async () => { },
86
>
markFileUnreviewed: async () => { },
87
>
getReviewedPaths: async () => new Set(),
88
>
copyReviewedRef: async () => { },
89
>
};