fix: harden windows argv parsing

This commit is contained in:
Peter Steinberger
2026-01-19 10:36:33 +00:00
parent 44c61a77c5
commit c6ef7ff921
2 changed files with 13 additions and 13 deletions

View File

@@ -59,7 +59,7 @@ function ensureExperimentalWarningSuppressed(): boolean {
function normalizeWindowsArgv(argv: string[]): string[] { function normalizeWindowsArgv(argv: string[]): string[] {
if (process.platform !== "win32") return argv; if (process.platform !== "win32") return argv;
if (argv.length < 3) return argv; if (argv.length < 2) return argv;
const stripControlChars = (value: string): string => { const stripControlChars = (value: string): string => {
let out = ""; let out = "";
for (let i = 0; i < value.length; i += 1) { for (let i = 0; i < value.length; i += 1) {
@@ -90,16 +90,14 @@ function normalizeWindowsArgv(argv: string[]): string[] {
lower.includes("node.exe") lower.includes("node.exe")
); );
}; };
const arg1 = path.basename(argv[1] ?? "").toLowerCase(); const next = [...argv];
const arg2 = path.basename(argv[2] ?? "").toLowerCase(); for (let i = 1; i <= 3 && i < next.length; ) {
const looksLikeEntry = arg1 === "entry.ts" || arg1 === "entry.js"; if (isExecPath(next[i])) {
let next = argv; next.splice(i, 1);
if (arg1 === execBase) { continue;
next = [argv[0], ...argv.slice(2)]; }
} else if (looksLikeEntry && arg2 === execBase) { i += 1;
next = [argv[0], argv[1], ...argv.slice(3)];
} }
const filtered = next.filter((arg, index) => index === 0 || !isExecPath(arg)); const filtered = next.filter((arg, index) => index === 0 || !isExecPath(arg));
if (filtered.length < 3) return filtered; if (filtered.length < 3) return filtered;
const cleaned = [...filtered]; const cleaned = [...filtered];

View File

@@ -51,6 +51,8 @@ describe("gateway server sessions", () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-")); const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
const storePath = path.join(dir, "sessions.json"); const storePath = path.join(dir, "sessions.json");
const now = Date.now(); const now = Date.now();
const recent = now - 30_000;
const stale = now - 15 * 60_000;
testState.sessionStorePath = storePath; testState.sessionStorePath = storePath;
await fs.writeFile( await fs.writeFile(
@@ -70,7 +72,7 @@ describe("gateway server sessions", () => {
entries: { entries: {
main: { main: {
sessionId: "sess-main", sessionId: "sess-main",
updatedAt: now - 30_000, updatedAt: recent,
inputTokens: 10, inputTokens: 10,
outputTokens: 20, outputTokens: 20,
thinkingLevel: "low", thinkingLevel: "low",
@@ -81,12 +83,12 @@ describe("gateway server sessions", () => {
}, },
"discord:group:dev": { "discord:group:dev": {
sessionId: "sess-group", sessionId: "sess-group",
updatedAt: now - 10 * 60_000, updatedAt: stale,
totalTokens: 50, totalTokens: 50,
}, },
"agent:main:subagent:one": { "agent:main:subagent:one": {
sessionId: "sess-subagent", sessionId: "sess-subagent",
updatedAt: now - 10 * 60_000, updatedAt: stale,
spawnedBy: "agent:main:main", spawnedBy: "agent:main:main",
}, },
global: { global: {