From f2795754e9a659c7ab9bc4eec6c211d247257287 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 24 Jan 2026 07:10:23 +0000 Subject: [PATCH] fix: normalize Windows argv handling (#1564) (thanks @Takhoffman) --- CHANGELOG.md | 1 + src/agents/anthropic-payload-log.ts | 12 +++++++++--- src/plugins/commands.ts | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a2b1a99..1fa7b16e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Docs: https://docs.clawd.bot ### Fixes - Agents: ignore IDENTITY.md template placeholders when parsing identity to avoid placeholder replies. (#1556) +- CLI: normalize Windows argv to drop duplicate node.exe entries before commands. (#1564) Thanks @Takhoffman. - Docker: update gateway command in docker-compose and Hetzner guide. (#1514) - Sessions: reject array-backed session stores to prevent silent wipes. (#1469) - Voice wake: auto-save wake words on blur/submit across iOS/Android and align limits with macOS. diff --git a/src/agents/anthropic-payload-log.ts b/src/agents/anthropic-payload-log.ts index 8b39d2f1a..9064b51da 100644 --- a/src/agents/anthropic-payload-log.ts +++ b/src/agents/anthropic-payload-log.ts @@ -90,6 +90,12 @@ function safeJsonStringify(value: unknown): string | null { } } +function formatError(error: unknown): string { + if (typeof error === "string") return error; + if (error instanceof Error) return error.stack ?? error.message; + return safeJsonStringify(error) ?? "[unknown error]"; +} + function digest(value: unknown): string | undefined { const serialized = safeJsonStringify(value); if (!serialized) return undefined; @@ -163,7 +169,7 @@ export function createAnthropicPayloadLogger(params: { options?.onPayload?.(payload); }; return streamFn(model, context, { - ...(options ?? {}), + ...options, onPayload: nextOnPayload, }); }; @@ -178,7 +184,7 @@ export function createAnthropicPayloadLogger(params: { ...base, ts: new Date().toISOString(), stage: "usage", - error: String(error), + error: formatError(error), }); } return; @@ -188,7 +194,7 @@ export function createAnthropicPayloadLogger(params: { ts: new Date().toISOString(), stage: "usage", usage, - error: error ? String(error) : undefined, + error: error ? formatError(error) : undefined, }); log.info("anthropic usage", { runId: params.runId, diff --git a/src/plugins/commands.ts b/src/plugins/commands.ts index 68f232b39..ee46f195e 100644 --- a/src/plugins/commands.ts +++ b/src/plugins/commands.ts @@ -194,8 +194,22 @@ function sanitizeArgs(args: string | undefined): string | undefined { return args.slice(0, MAX_ARGS_LENGTH); } + const stripControlChars = (value: string): string => { + let out = ""; + for (let i = 0; i < value.length; i += 1) { + const code = value.charCodeAt(i); + if (code === 9 || code === 10) { + out += value[i]; + continue; + } + if (code < 32 || code === 127) continue; + out += value[i]; + } + return out; + }; + // Remove control characters (except newlines and tabs which may be intentional) - return args.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ""); + return stripControlChars(args); } /**