shellCommandExecution.ts ×14

Frontier kind: Code frontier

unlabeled · c_8d25a9c3bdaa

8 tests · 28961 LOC · 131 files · introduces 0 tests · 77 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges77 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2528 ranges28961 lines · 131 files · Browse complete extent
All tests (intent)
8 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: 77 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/shellCommandExecution.ts 77 introduced LOC · 14 ranges

Open complete file

96 }
97
98 > function makeSentinelId(): string { shellCommandExecution.ts
99 > return generateUuid().replace(/-/g, '');
100 > }
101
102 > function buildSentinelCommand(sentinelId: string, shellType: ShellType): string { shellCommandExecution.ts
103 > if (shellType === 'powershell') {
104 return `Write-Output "${SENTINEL_PREFIX}${sentinelId}_EXIT_$LASTEXITCODE>>>"`;
105 }
106 > return `echo "${SENTINEL_PREFIX}${sentinelId}_EXIT_$?>>>"`; shellCommandExecution.ts
107 > }
108
109 > function parseSentinel(content: string, sentinelId: string): { found: boolean; exitCode: number; outputBeforeSentinel: string } { shellCommandExecution.ts
110 > const marker = `${SENTINEL_PREFIX}${sentinelId}_EXIT_`;
111 > let markerIndex = content.lastIndexOf(marker);
112 > while (markerIndex !== -1) {
113 const outputBeforeSentinel = content.substring(0, markerIndex);
114 const afterMarker = content.substring(markerIndex + marker.length);
128 markerIndex = content.lastIndexOf(marker, markerIndex - 1);
129 }
131 > return { found: false, exitCode: -1, outputBeforeSentinel: content };
132 > }
133
134 /**
198 return terminalManager.supportsCommandDetection(target.terminalUri)
199 ? executeCommandWithShellIntegration(target, command, timeoutMs, terminalManager, logService)
200 > : executeCommandWithSentinel(target, command, timeoutMs, terminalManager, logService); shellCommandExecution.ts
201 }
202
287 * Used when shell integration is not available.
288 */
289 > async function executeCommandWithSentinel( shellCommandExecution.ts
290 > target: IShellCommandTarget,
291 > command: string,
292 > timeoutMs: number,
293 > terminalManager: IAgentHostTerminalManager,
294 > logService: ILogService,
295 > ): Promise<IShellCommandResult> {
296 > const sentinelId = makeSentinelId();
297 > const sentinelCmd = buildSentinelCommand(sentinelId, target.shellType);
298 > const disposables = new DisposableStore();
299 >
300 > const contentBefore = terminalManager.getContent(target.terminalUri) ?? '';
301 > const offsetBefore = contentBefore.length;
302 >
303 > const result = new Promise<IShellCommandResult>(resolve => {
304 > let resolved = false;
305 > const finish = (result: IShellCommandResult) => {
306 > if (resolved) {
307 return;
308 }
309 > resolved = true; shellCommandExecution.ts
310 > disposables.dispose();
311 > resolve(result);
312 > };
313 >
314 > const checkForSentinel = () => {
315 > const fullContent = terminalManager.getContent(target.terminalUri) ?? '';
316 > // Clamp offset: the terminal manager trims content when it exceeds
317 > // 100k chars (slices to last 80k). If trimming happened after we
318 > // captured offsetBefore, scan from the start of the current buffer.
319 > const clampedOffset = Math.min(offsetBefore, fullContent.length);
320 > const newContent = fullContent.substring(clampedOffset);
321 > const parsed = parseSentinel(newContent, sentinelId);
322 > if (parsed.found) {
323 const output = prepareOutputForModel(parsed.outputBeforeSentinel);
324 logService.info(`[ShellCommand] Command completed with exit code ${parsed.exitCode}`);
325 finish({ status: 'completed', exitCode: parsed.exitCode, output });
326 }
328 >
329 > disposables.add(terminalManager.onData(target.terminalUri, () => {
330 checkForSentinel();
332 >
333 > registerAltBufferHandler(target, terminalManager, logService, disposables, finish);
334 >
335 > disposables.add(terminalManager.onExit(target.terminalUri, (exitCode: number) => {
336 logService.info(`[ShellCommand] Shell exited unexpectedly with code ${exitCode}`);
337 const fullContent = terminalManager.getContent(target.terminalUri) ?? '';
338 const newContent = fullContent.substring(offsetBefore);
339 finish({ status: 'shellExited', exitCode, output: prepareOutputForModel(newContent) });
341 >
342 > disposables.add(terminalManager.onClaimChanged(target.terminalUri, (claim) => {
343 if (claim.kind === TerminalClaimKind.Session && !claim.toolCallId) {
344 logService.info(`[ShellCommand] Continuing in background (claim narrowed)`);
345 finish({ status: 'background', output: '' });
346 }
348 >
349 > const timer = setTimeout(() => {
350 logService.warn(`[ShellCommand] Command timed out after ${timeoutMs}ms`);
351 const fullContent = terminalManager.getContent(target.terminalUri) ?? '';
352 const newContent = fullContent.substring(offsetBefore);
353 finish({ status: 'timeout', output: prepareOutputForModel(newContent) });
354 > }, timeoutMs); shellCommandExecution.ts
355 > disposables.add(toDisposable(() => clearTimeout(timer)));
356 >
357 > checkForSentinel();
358 > });
359 >
360 > try {
361 > await terminalManager.sendText(target.terminalUri, `${prefixForHistorySuppression(target.shellType)}${command}`, {
362 > shouldExecute: true,
363 > bracketedPasteMode: shouldUseBracketedPasteMode(command),
364 > });
365 > await terminalManager.sendText(target.terminalUri, sentinelCmd, { shouldExecute: true });
366 > } catch (err) {
367 disposables.dispose();
368 throw err;
369 }
371 > return result;
372 > }