commandLineHelpers.ts ×3

Frontier kind: Code frontier

unlabeled · c_816d59c98c44

899 tests · 5698 LOC · 30 files · introduces 0 tests · 60 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
3 ranges60 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
790 ranges5698 lines · 30 files · Browse complete extent
All tests (intent)
899 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: 60 introduced LOC across 3 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/commandLineHelpers.ts 60 introduced LOC · 3 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- commandLineHelpers.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 { extUriBiasedIgnorePathCase } from '../../../base/common/resources.js';
7 > import { URI } from '../../../base/common/uri.js';
8 >
9 > /**
10 > * Result of {@link extractCdPrefix}: the directory the `cd` jumps to and the
11 > * remaining command after the chain operator.
12 > */
13 > export interface IExtractedCdPrefix {
14 > readonly directory: string;
15 > readonly command: string;
16 > }
17 >
18 > /**
19 > * Extracts a `cd <dir> &&` (or PowerShell equivalent) prefix from a command
20 > * line, returning the directory and remaining command. Does not check whether
21 > * the directory matches anything — callers do that comparison themselves.
22 > *
23 > * The separator between the `cd` and the remaining command may be `&&` or a
24 > * newline (bash treats a bare newline as a command separator like `;`).
25 > * PowerShell additionally accepts `;`. The remaining command may span multiple
26 > * lines (the model frequently emits `cd <dir>` on its own line followed by a
27 > * multi-line script).
28 > *
29 > * Recognized forms:
30 > * - bash: `cd <dir> && <suffix>`, `cd <dir>\n<suffix>`
31 > * - powershell: `cd <dir> && <suffix>`, `cd <dir>; <suffix>`, `cd <dir>\n<suffix>`
32 > * `cd /d <dir> && <suffix>`, `cd /d <dir>; <suffix>`
33 > * `Set-Location <dir> && <suffix>`, `Set-Location <dir>; <suffix>`
34 > * `Set-Location -Path <dir> && <suffix>`, `Set-Location -Path <dir>; <suffix>`
35 > *
36 > * Surrounding double quotes around `<dir>` are stripped.
37 > */
38 > export function extractCdPrefix(commandLine: string, isPowerShell: boolean): IExtractedCdPrefix | undefined {
39 const cdPrefixMatch = commandLine.match(
40 isPowerShell
53 return undefined;
54 }
56 > /**
57 > * If `toolName` is a shell tool (`bash` or `powershell`) and
58 > * `parameters.command` starts with a `cd <workingDirectory> && …` (or
59 > * PowerShell equivalent) prefix, mutate `parameters.command` to drop the
60 > * prefix and return `true`. Returns `false` otherwise.
61 > *
62 > * Path comparison normalizes trailing slashes and is case-insensitive on
63 > * Windows.
64 > */
65 > export function stripRedundantCdPrefix(
66 toolName: string,
67 parameters: Record<string, unknown> | undefined,
90 return true;
91 }
93 > /**
94 > * Compares an extracted `cd <dir>` argument (a raw filesystem path string,
95 > * possibly using either `/` or `\` separators) to a working-directory URI.
96 > * Normalizes separators by routing the extracted string through `URI.file`,
97 > * which converts to the platform-native `fsPath` shape, so that e.g.
98 > * `cd C:/repo` matches a working directory of `C:\repo` on Windows.
99 > *
100 > * Path comparison uses {@link extUriBiasedIgnorePathCase}, which is
101 > * case-insensitive on Windows / macOS.
102 > */
103 function sameDirectory(extractedDir: string, workingDirectory: URI): boolean {
104 if (!extractedDir) {