bangLocalCommand.ts ×10

Frontier kind: Code frontier

unlabeled · c_7913cbdd8721

7 tests · 50468 LOC · 291 files · introduces 0 tests · 95 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges95 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5285 ranges50468 lines · 291 files · Browse complete extent
All tests (intent)
7 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.

3 files ranked by introduced lines: 95 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/localCommands/bangLocalCommand.ts 83 introduced LOC · 10 ranges

Open complete file

34 this._register(toDisposable(() => {
35 for (const terminalUri of this._terminals) {
36 > this._context.terminalManager.disposeTerminal(terminalUri); bangLocalCommand.ts
37 > }
38 this._terminals.clear();
39 }));
45 return undefined;
46 }
47 > // The raw command doubles as a provisional title so a brand-new session bangLocalCommand.ts
48 > // isn't left untitled until the first real (non-command) request.
49 > return { run: () => this._run(request.turnChannel, request.turnId, command), suggestedTitle: command };
50 }
51
52 private async _run(turnChannel: ProtocolURI, turnId: string, command: string): Promise<void> {
53 > const ctx = this._context; bangLocalCommand.ts
54 > const sessionChannel = isAhpChatChannel(turnChannel) ? parseRequiredSessionUriFromChatUri(turnChannel) : turnChannel;
55 > const toolCallId = generateUuid();
56 > const terminalUri = `agenthost-terminal://bang/${generateUuid()}`;
57 > const displayName = localize('agentHostBang.terminal', "Terminal");
58 > let terminalCreated = false;
59 > try {
60 > const workingDirStr = ctx.getState(sessionChannel)?.workingDirectories?.[0];
61 > const cwd = workingDirStr ? URI.parse(workingDirStr).fsPath : undefined;
62 > const shellPath = await ctx.terminalManager.getDefaultShell();
63 > const shellType = shellTypeForExecutable(shellPath);
64 >
65 > // Surface the command as a tool call and transition it straight to
66 > // running — the user typed it explicitly, so no confirmation.
67 > ctx.dispatch(turnChannel, {
68 > type: ActionType.ChatToolCallStart,
69 > turnId,
70 > toolCallId,
71 > toolName: 'terminal',
72 > displayName,
73 > intention: command,
74 > });
75 > ctx.dispatch(turnChannel, {
76 > type: ActionType.ChatToolCallReady,
77 > turnId,
78 > toolCallId,
79 > invocationMessage: command,
80 > toolInput: command,
81 > confirmed: ToolCallConfirmationReason.NotNeeded,
82 > });
83 >
84 > const claim: TerminalSessionClaim = {
85 > kind: TerminalClaimKind.Session,
86 > session: sessionChannel,
87 > turnId,
88 > toolCallId,
89 > };
90 > const params: CreateTerminalParams = { channel: terminalUri, claim, name: displayName, cwd };
91 > await ctx.terminalManager.createTerminal(params, { shell: shellPath, preventShellHistory: true, nonInteractive: true });
92 > terminalCreated = true;
93 > this._terminals.add(terminalUri);
94 >
95 > // Reference the terminal so the client can stream live output while
96 > // the command runs.
97 > const terminalContent: ToolResultContent = { type: ToolResultContentType.Terminal, resource: terminalUri, title: displayName };
98 > ctx.dispatch(turnChannel, {
99 > type: ActionType.ChatToolCallContentChanged,
100 > turnId,
101 > toolCallId,
102 > content: [terminalContent],
103 > });
104 >
105 > const result = await executeShellCommand({ terminalUri, shellType }, command, DEFAULT_SHELL_COMMAND_TIMEOUT_MS, ctx.terminalManager, ctx.logService);
106 > const { success, pastTenseMessage } = this._summarizeResult(result);
107 > const content: ToolResultContent[] = [terminalContent];
108 > if (result.output) {
109 > content.push({ type: ToolResultContentType.Text, text: result.output });
110 > }
111 > ctx.dispatch(turnChannel, {
112 > type: ActionType.ChatToolCallComplete,
113 > turnId,
114 > toolCallId,
115 > result: { success, pastTenseMessage, content },
116 > });
117 > } catch (err) {
118 ctx.logService.error(`[BangLocalCommand] Command failed for session=${sessionChannel}: ${err instanceof Error ? err.message : String(err)}`, err);
119 if (terminalCreated) {
139 */
140 private _summarizeResult(result: IShellCommandResult): { success: boolean; pastTenseMessage: string } {
141 > switch (result.status) { bangLocalCommand.ts
142 > case 'completed': {
143 > const exitCode = result.exitCode ?? 0;
144 > return exitCode === 0
145 > ? { success: true, pastTenseMessage: localize('agentHostBang.ran', "Ran command") }
146 : { success: false, pastTenseMessage: localize('agentHostBang.exited', "Command exited with code {0}", exitCode) };
148 > case 'timeout':
149 return { success: false, pastTenseMessage: localize('agentHostBang.timedOut', "Command timed out") };
150 > case 'shellExited': bangLocalCommand.ts
151 return { success: false, pastTenseMessage: localize('agentHostBang.shellExited', "Shell exited unexpectedly") };
152 > case 'background': bangLocalCommand.ts
153 return { success: true, pastTenseMessage: localize('agentHostBang.background', "Command is running in the background") };
154 > case 'altBuffer': bangLocalCommand.ts
155 return { success: true, pastTenseMessage: localize('agentHostBang.interactive', "Command opened an interactive terminal") };
157 > }
158 }
159
src/vs/platform/agentHost/node/localCommands/localChatCommand.ts 6 introduced LOC · 4 ranges

Open complete file

234 return part;
235 }
236 > const tc = part.toolCall; localChatCommand.ts
237 > // Only these tool-call states carry `content` (a live terminal ref lives here).
238 if (tc.status !== ToolCallStatus.Running && tc.status !== ToolCallStatus.Completed && tc.status !== ToolCallStatus.PendingResultConfirmation) {
239 return part;
240 }
241 > if (!tc.content) { localChatCommand.ts
242 return part;
243 }
244 > const content = tc.content.filter(c => c.type !== ToolResultContentType.Terminal); localChatCommand.ts
245 > if (content.length === tc.content.length) {
246 return part;
247 }
248 > return { ...part, toolCall: { ...tc, content } }; localChatCommand.ts
249 });
250 return { ...turn, responseParts };
src/vs/platform/agentHost/test/node/testAgentHostTerminalManager.ts 6 introduced LOC · 2 ranges

Open complete file

42
43 async createTerminal(params: CreateTerminalParams): Promise<void> {
44 > this.created.push(params); testAgentHostTerminalManager.ts
45 > this._onDidCreateTerminal.fire(params.channel);
46 > }
47 writeInput(): void { }
48 async sendText(uri: string, data: string): Promise<void> { this.sentTexts.push({ uri, data }); }
51 onClaimChanged(_uri: string, cb: (claim: TerminalClaim) => void): IDisposable { return this._onClaimChanged.event(cb); }
52 onCommandFinished(_uri: string, cb: (event: ICommandFinishedEvent) => void): IDisposable {
53 > this.commandFinishedListenerRegistered.complete(); testAgentHostTerminalManager.ts
54 > return this._onCommandFinished.event(cb);
55 > }
56 createAltBufferPromise(): Promise<void> { return new Promise<void>(() => { }); }
57 getContent(): string | undefined { return undefined; }