src/vs/platform/agentHost/node/codex/codexShellCommand.ts

42 LOC · 40 covered · 2 uncovered · 7 ranges · 123 concepts · 5 introducers · 64 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- codexShellCommand.ts ×2
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 > /**
7 > * Codex reports a shell command as the exact invocation it hands to the OS —
8 > * the user's login shell wrapping the actual script, e.g.
9 > * `/bin/zsh -lc 'touch ~/foo'`. That wrapper is noise in the chat UI and makes
10 > * Codex's terminal pills (and its approval / denial cards) look different from
11 > * Claude's (which surface the bare `touch ~/foo`). Peel off a leading
12 > * `<shell> -[l]c <script>` wrapper and return the inner script so both agents
13 > * render identically. Falls back to the raw command when it doesn't match the
14 > * wrapper shape.
15 > *
16 > * This is a display-only transform: callers must keep the raw command for any
17 > * identity/round-trip purpose (accept-for-session memo keys, re-sending the
18 > * exact action to the app-server, etc.).
19 > */
20 > export function unwrapShellInvocation(command: string): string {
21 > const match = /^\s*\S*sh(?:\.exe)?\s+-[a-z]*c\s+([\s\S]+)$/i.exec(command); codexShellCommand.ts ×1
22 > if (!match) {
23 > return command; codexShellCommand.ts ×1
24 > }
25 > return unquoteShellArg(match[1].trim()); codexShellCommand.ts ×2
26 > }
28 > /**
29 > * Strips the surrounding quotes the shell wrapper added around a script
30 > * argument and undoes the corresponding escaping (POSIX `'\''` for single
31 > * quotes; backslash escapes for double quotes). Returns the argument unchanged
32 > * when it is not quoted.
33 > */
34 > function unquoteShellArg(arg: string): string { codexShellCommand.ts ×2
35 > if (arg.length >= 2 && arg[0] === '\'' && arg[arg.length - 1] === '\'') {
36 > return arg.slice(1, -1).replace(/'\\''/g, '\'');
37 > }
38 > if (arg.length >= 2 && arg[0] === '"' && arg[arg.length - 1] === '"') {
39 return arg.slice(1, -1).replace(/\\(["\\$`])/g, '$1');
40 }
41 > return arg; codexGuardianReview.ts ×2
42 > }