Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(tool-summary): an error past the budget skips secret-named keys, and an error object loses its secret-named values
milind-soni1a4deaba8026
diff --git a/server/tool-summary.test.ts b/server/tool-summary.test.tsindex f72fd80fd3..4d468bf553 100644--- a/server/tool-summary.test.ts+++ b/server/tool-summary.test.ts@@ -54,6 +54,14 @@ describe("toolDetailPreview", () => {expect(toolDetailPreview({ ok: false, error: { message: "denied", password: "tiny" } })).not.toContain("tiny");expect(toolDetailPreview({ ok: false, error: JSON.stringify({ message: "denied", password: "tiny" }) })).not.toContain("tiny");expect(toolDetailPreview({ ok: false, errorToken: "tiny" })).not.toContain("tiny");+ expect(toolDetailPreview({ ok: false, error: { message: "denied", api_key: 1234 } })).not.toContain("1234");+ const row = Object.fromEntries(Array.from({ length: 40 }, (_, i) => [`f${i}`, "x"]));+ const pastBudget = (tail: Record<string, unknown>) => ({ response: Array.from({ length: 6 }, () => row), tail });+ expect(toolDetailPreview(pastBudget({ error: "connection refused" }))).toContain("connection refused");+ expect(toolDetailPreview(pastBudget({ errorToken: "tiny" }))).not.toContain("tiny");+ expect(toolDetailPreview(pastBudget({ token: { error: "tiny" } }))).not.toContain("tiny");+ expect(toolDetailPreview(pastBudget({ error: { message: "denied", api_key: 1234 } }))).toContain("denied");+ expect(toolDetailPreview(pastBudget({ error: { message: "denied", api_key: 1234 } }))).not.toContain("1234");});it("scrubs structured JSON inside native text results without changing ordinary prose", () => {const preview = toolDetailPreview([{ type: "text", text: JSON.stringify({ message: "request completed", password: "tiny", headers: { Cookie: "sid=x" }, env: [{ name: "API_KEY", value: "small" }] }) }]);diff --git a/server/tool-summary.ts b/server/tool-summary.tsindex 714bec7059..143b4bae9e 100644--- a/server/tool-summary.ts+++ b/server/tool-summary.ts@@ -8,6 +8,12 @@ export function toolDetailPreview(value: unknown): string | undefined {let textBudget = 256_000;/** A failed call's error is the cause the model must read; it is kept whole even where the rest is omitted. */const ERROR_KEY = /^error/i;+ const SECRET_KEY = /token|secret|password|passwd|cookie|authorization|api.?key|(^|[_.-])keys?$/i;+ const secretKeysOut = (item: unknown, depth = 0): unknown => {+ if (depth > 12 || item === null || typeof item !== "object") return item;+ if (Array.isArray(item)) return item.map((child) => secretKeysOut(child, depth + 1));+ return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, SECRET_KEY.test(key) ? "[redacted]" : secretKeysOut(child, depth + 1)]));+ };const ERROR_TEXT_MAX = 500;const errorText = (value: unknown): string => {let parsed = value;@@ -18,7 +24,7 @@ export function toolDetailPreview(value: unknown): string | undefined {let text: string;if (typeof parsed === "string") text = parsed;else {- try { text = JSON.stringify(redactSecrets(parsed)) ?? ""; }+ try { text = JSON.stringify(redactSecrets(secretKeysOut(parsed))) ?? ""; }catch { return "[error not serializable]"; }}// Redact before the cut, like commandSummary, so a sliced credential cannot slip through.@@ -27,10 +33,11 @@ export function toolDetailPreview(value: unknown): string | undefined {/** The first /^error/i value anywhere below an omitted object: the cause a failed call must still give up. */const findError = (item: Record<string, unknown> | object, depth = 0): unknown => {if (depth > 12) return undefined;- for (const [key, child] of Object.entries(item).slice(0, 40)) {+ const entries = Object.entries(item).slice(0, 40).filter(([key]) => !SECRET_KEY.test(key));+ for (const [key, child] of entries) {if (ERROR_KEY.test(key) && isErrorValue(child)) return child;}- for (const child of Object.values(item).slice(0, 40)) {+ for (const [, child] of entries) {if (child !== null && typeof child === "object" && !Array.isArray(child)) {const found = findError(child, depth + 1);if (found !== undefined) return found;@@ -64,7 +71,7 @@ export function toolDetailPreview(value: unknown): string | undefined {const entries = Object.entries(item);const result: Record<string, unknown> = Object.create(null);for (const [key, child] of entries.slice(0, 40)) {- result[key] = /token|secret|password|passwd|cookie|authorization|api.?key|(^|[_.-])keys?$/i.test(key)+ result[key] = SECRET_KEY.test(key)? "[redacted]": ERROR_KEY.test(key) && isErrorValue(child)? errorText(child)