agentHostCommitOperationHandler.ts ×12

Frontier kind: Code frontier

unlabeled · c_f94dbec7ed24

2 tests · 24117 LOC · 103 files · introduces 0 tests · 71 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges71 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2162 ranges24117 lines · 103 files · Browse complete extent
All tests (intent)
2 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: 71 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentHostCommitOperationHandler.ts 71 introduced LOC · 12 ranges

Open complete file

76 return { message: { markdown: localize('agentHost.changeset.commit.noChanges', "No uncommitted changes to commit.") } };
77 }
78 > this._throwIfCancelled(token); agentHostCommitOperationHandler.ts
79 >
80 > const copilotResource = this._gitHubEndpointService.getCopilotResource();
81 > const authToken = this._agentService.getAuthToken({
82 > resource: copilotResource.resource,
83 > scopes: copilotResource.scopes_supported,
84 > });
85 > if (!authToken) {
86 throw new ProtocolError(
87 AHP_AUTH_REQUIRED,
90 );
91 }
93 > const diffs = await this._gitService.computeSessionFileDiffs(workingDirectory, { sessionUri });
94 if (!diffs || diffs.length === 0) {
95 throw new ProtocolError(JsonRpcErrorCodes.InternalError, localize('agentHost.changeset.commit.diffFailed', "Could not compute uncommitted changes to generate a commit message."));
96 }
97 > this._throwIfCancelled(token); agentHostCommitOperationHandler.ts
98 >
99 > let message: string;
100 > try {
101 > message = this._cleanCommitMessage(await this._copilotApiService.utilityChatCompletion(authToken, {
102 > messages: this._buildCommitMessagePrompt(workingDirectory, gitState.branchName, diffs),
103 > }, { signal }));
104 > } catch (err) {
105 > this._throwIfCancelled(token);
106 > if (this._isAuthFailure(err)) {
107 > throw new ProtocolError(
108 > AHP_AUTH_REQUIRED,
109 > localize('agentHost.changeset.commit.authExpired', "Authentication is required to generate a commit message. Please sign in to GitHub Copilot and try again."),
110 > [copilotResource],
111 > );
112 > }
113 throw err;
114 }
136
137 private _buildCommitMessagePrompt(workingDirectory: URI, branchName: string | undefined, diffs: readonly ISessionFileDiff[]): { role: 'system' | 'user'; content: string }[] {
138 > const changeSummary = this._summarizeDiffsForPrompt(diffs); agentHostCommitOperationHandler.ts
139 > return [
140 > {
141 > role: 'system',
142 > content: [
143 > 'You generate concise Git commit messages.',
144 > 'Return only the commit message text, with no markdown or code fences.',
145 > 'Use imperative mood. Keep the subject line under 72 characters.',
146 > 'Add a body only when it helps explain multiple related changes.',
147 > ].join(' '),
148 > },
149 > {
150 > role: 'user',
151 > content: [
152 > `Repository: ${basename(workingDirectory)}`,
153 > `Branch: ${branchName ?? 'unknown'}`,
154 > 'Changed files:',
155 > changeSummary,
156 > ].join('\n'),
157 > },
158 > ];
159 > }
160
161 private _summarizeDiffsForPrompt(diffs: readonly ISessionFileDiff[]): string {
162 > const lines: string[] = []; agentHostCommitOperationHandler.ts
163 > for (const diff of diffs) {
164 > const before = diff.before?.uri;
165 > const after = diff.after?.uri;
166 > const path = after ?? before ?? '(unknown)';
167 > let kind = 'Edit';
168 > if (!before && after) {
169 > kind = 'Create';
170 > } else if (before && !after) {
171 kind = 'Delete';
172 } else if (before && after && before !== after) {
173 kind = 'Rename';
174 }
175 > lines.push(`- ${kind}: ${this._displayUri(path)} (+${diff.diff?.added ?? 0} -${diff.diff?.removed ?? 0})`); agentHostCommitOperationHandler.ts
176 > if (lines.join('\n').length > MAX_CHANGE_SUMMARY_PROMPT_CHARS) {
177 lines.push('[file list truncated]');
178 break;
179 }
181 > return lines.join('\n');
182 > }
183
184 private _displayUri(uri: string): string {
186 > const parsed = URI.parse(uri);
187 > return parsed.scheme === 'file' ? parsed.fsPath : parsed.path || uri;
188 > } catch {
189 return uri;
190 }
192
193 private _cleanCommitMessage(raw: string): string {
201
202 private _isAuthFailure(err: unknown): boolean {
203 > if (err instanceof CopilotApiError) { agentHostCommitOperationHandler.ts
204 return err.status === 401 || err.status === 403;
205 }
206 > const message = err instanceof Error ? err.message : String(err); agentHostCommitOperationHandler.ts
207 > return /\b(401|403)\b/.test(message)
208 && /\b(auth|authorization|unauthorized|forbidden|token|copilot endpoint discovery|copilot session token mint)\b/i.test(message);
210
211 private _throwIfCancelled(token: CancellationToken): void {