@devries-cameron20 / t3code Mirror · read-only / commits / eb90b79217
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(client-runtime): command rows unwrap Windows pwsh -Command and cmd /c launchers (#38946)

Julius Marminge committed Nov 18, 2026 at 21:39 UTC eb90b7921721217b26282ca4bab628976a00c1af
2 files changed +42 -6
packages/client-runtime/src/work-log/commandLabel.test.ts
+16
@@ -158,6 +158,22 @@ describe("commandDisplayText with redacted Codex commands", () => {
158 });
159 });
160
161 +describe("commandDisplayText with Windows shell wrappers", () => {
162 + it.each([
163 + [
164 + `"C:\\Program Files\\PowerShell\\7\\pwsh.exe" -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss'"`,
165 + "Get-Date -Format 'yyyy-MM-dd HH:mm:ss'",
166 + ],
167 + [
168 + `"C:\\Program Files\\PowerShell\\7\\pwsh.exe" -NoLogo -NoProfile -Command 'rg -n -F "new Date()" .'`,
169 + 'rg -n -F "new Date()" .',
170 + ],
171 + ['cmd.exe /c "npm test"', "npm test"],
172 + ])("shows %j as %j", (input, expected) => {
173 + expect(commandDisplayText(input)).toBe(expected);
174 + });
175 +});
176 +
177 describe("commandDisplayText control characters", () => {
178 it.each([
179 ["printf '\u001b[31mred\u001b[0m'", "printf '␛[31mred␛[0m'"],
packages/client-runtime/src/work-log/commandLabel.ts
+26 -6
@@ -1381,17 +1381,37 @@ function withoutShellWrapper(command: string): string {
1381 const split = splitFirstShellCommand(trimmed);
1382 if (split.remainingCommand !== null) return trimmed;
1383 const tokens = tokenizeShellCommand(trimmed);
1384 - const program = tokens?.[0]
1385 - ?.split(/[\\/]/u)
1386 - .at(-1)
1387 - ?.replace(/\.exe$/iu, "");
1388 - if (!tokens || !program || !SHELL_PROGRAMS.has(program)) return trimmed;
1389 - const scriptIndex = shellCommandArgumentIndex(tokens, 1);
1384 + const executable = tokens?.[0]?.split(/[\\/]/u).at(-1);
1385 + const program = executable?.replace(/\.exe$/iu, "");
1386 + if (!tokens || !executable || !program) return trimmed;
1387 + const scriptIndex = SHELL_PROGRAMS.has(program)
1388 + ? shellCommandArgumentIndex(tokens, 1)
1389 + : WINDOWS_SHELL_PROGRAMS.has(executable.toLowerCase())
1390 + ? windowsShellScriptIndex(program.toLowerCase(), tokens)
1391 + : null;
1392 // Positional arguments can affect the script; keep those invocations intact.
1393 if (scriptIndex === null || scriptIndex !== tokens.length - 1) return trimmed;
1394 return tokens[scriptIndex]?.trim() || trimmed;
1395 }
1396
1397 +function windowsShellScriptIndex(shell: string, tokens: ReadonlyArray<string>): number | null {
1398 + for (let index = 1; index < tokens.length; index += 1) {
1399 + const option = tokens[index]!.toLowerCase();
1400 + if (shell === "cmd") {
1401 + if (option === "/c") return index + 1;
1402 + if (!option.startsWith("/")) return null;
1403 + continue;
1404 + }
1405 + if (option === "-command" || option === "-c") return index + 1;
1406 + if (POWERSHELL_OPTIONS_WITH_VALUE.has(option)) {
1407 + index += 1;
1408 + continue;
1409 + }
1410 + if (!POWERSHELL_FLAGS.has(option)) return null;
1411 + }
1412 + return null;
1413 +}
1414 +
1415 const POWERSHELL_PROGRAMS = new Set(["powershell", "pwsh"]);
1416
1417 const POWERSHELL_VERBS = new Set(