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[] {
if (process.platform !== "win32") return argv;
if (argv.length < 3) return argv;
if (argv.length < 2) return argv;
const stripControlChars = (value: string): string => {
let out = "";
for (let i = 0; i < value.length; i += 1) {
@@ -90,16 +90,14 @@ function normalizeWindowsArgv(argv: string[]): string[] {
lower.includes("node.exe")
);
};
const arg1 = path.basename(argv[1] ?? "").toLowerCase();
const arg2 = path.basename(argv[2] ?? "").toLowerCase();
const looksLikeEntry = arg1 === "entry.ts" || arg1 === "entry.js";
let next = argv;
if (arg1 === execBase) {
next = [argv[0], ...argv.slice(2)];
} else if (looksLikeEntry && arg2 === execBase) {
next = [argv[0], argv[1], ...argv.slice(3)];
const next = [...argv];
for (let i = 1; i <= 3 && i < next.length; ) {
if (isExecPath(next[i])) {
next.splice(i, 1);
continue;
}
i += 1;
}
const filtered = next.filter((arg, index) => index === 0 || !isExecPath(arg));
if (filtered.length < 3) return 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 storePath = path.join(dir, "sessions.json");
const now = Date.now();
const recent = now - 30_000;
const stale = now - 15 * 60_000;
testState.sessionStorePath = storePath;
await fs.writeFile(
@@ -70,7 +72,7 @@ describe("gateway server sessions", () => {
entries: {
main: {
sessionId: "sess-main",
updatedAt: now - 30_000,
updatedAt: recent,
inputTokens: 10,
outputTokens: 20,
thinkingLevel: "low",
@@ -81,12 +83,12 @@ describe("gateway server sessions", () => {
},
"discord:group:dev": {
sessionId: "sess-group",
updatedAt: now - 10 * 60_000,
updatedAt: stale,
totalTokens: 50,
},
"agent:main:subagent:one": {
sessionId: "sess-subagent",
updatedAt: now - 10 * 60_000,
updatedAt: stale,
spawnedBy: "agent:main:main",
},
global: {