Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(embed): shell-quote the cost-cap resume command (W13 P1.18, CSO review)

time-attackaeea11601e49
diff --git a/src/core/embed-cost-cap.ts b/src/core/embed-cost-cap.ts
index 0311e742d4..25904e8e1b 100644
--- a/src/core/embed-cost-cap.ts
+++ b/src/core/embed-cost-cap.ts
@@ -11,6 +11,7 @@
import type { CapSource } from './consent.ts';
import { BudgetExhausted, BudgetTracker } from './budget/budget-tracker.ts';
import { withBudgetTracker } from './ai/gateway.ts';
+import { shellQuote } from './shell-quote.ts';
export interface EmbedCostCap {
readonly signal: AbortSignal;
@@ -66,7 +67,7 @@ export function noteEmbedCostStop(result: EmbedCostStopFields, refusal: BudgetEx
result.budget_reason = refusal.reason;
result.cap_usd = refusal.cap;
result.spent_usd = refusal.spent;
- result.resume_command = ['gbrain', 'embed', ...resume].join(' ');
+ result.resume_command = ['gbrain', 'embed', ...resume].map(shellQuote).join(' ');
}
/** The stdout verdict line for a cost-cap stop. */
diff --git a/test/embed-max-usd-metered.serial.test.ts b/test/embed-max-usd-metered.serial.test.ts
index fca98c0334..ecdf7aac3d 100644
--- a/test/embed-max-usd-metered.serial.test.ts
+++ b/test/embed-max-usd-metered.serial.test.ts
@@ -21,6 +21,8 @@ import { importFromContent, importImageFile } from '../src/core/import-file.ts';
import { run as runEmbedCli } from '../src/cli/commands/embed.ts';
import { runEmbed } from '../src/commands/embed.ts';
import { requireEmbedBackfillConsent } from '../src/core/embed-consent.ts';
+import { noteEmbedCostStop } from '../src/core/embed-cost-cap.ts';
+import { BudgetExhausted } from '../src/core/budget/budget-tracker.ts';
import { _resetCliExitVerdictForTests, currentExitCode } from '../src/core/cli-force-exit.ts';
import { BUDGET_STOP_EXIT_CODE } from '../src/core/exit-codes.ts';
import { runSources } from '../src/commands/sources.ts';
@@ -84,6 +86,9 @@ describe('embed --max-usd is metered', () => {
expect(result).toMatchObject({ reason: 'cost_cap', budget_reason: 'cost', cap_usd: 0.1, failures: 0, embedded: 1, failure_samples: [],
resume_command: `gbrain embed --slugs ${SLUGS.join(' ')}` });
expect(calls).toBe(1);
+ const quoted = { reason: 'x' } as { reason?: string; resume_command?: string };
+ noteEmbedCostStop(quoted, new BudgetExhausted('cap', { reason: 'cost', spent: 0.2, cap: 0.1 }), ['--slugs', 'notes/$(id)', '--max-usd', '0.1', '--yes']);
+ expect(quoted.resume_command).toBe("gbrain embed --slugs 'notes/$(id)'");
});
test('--stale with multi-chunk pages: one provider call, then a clean stop (no per-chunk fan-out, no failures)', async () => {