Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: paid-consent lint wording, shell-quoted pollCommand, normalized LLMS_REPO_BASE (W13 P1.14-P1.16)
time-attackeeb6100b19aa
diff --git a/scripts/check-skill-refs.mjs b/scripts/check-skill-refs.mjsindex 221128aec5..a450c3186a 100755--- a/scripts/check-skill-refs.mjs+++ b/scripts/check-skill-refs.mjs@@ -38,7 +38,10 @@// jobs submit, doctor --remediate, dream) needs approval wording (ask,// agree, approve, consent, confirm, permission) on its line or in the 8// lines before it. This lane covers skills/migrations/** too: migration-// notes are agent-executed during upgrades.+// notes are agent-executed during upgrades. It is a lexical tripwire for+// documentation, not an enforcement point: the runtime spend-consent check+// is what stops unapproved paid work, and this lane only keeps skills from+// teaching an agent to skip it.//// The CLI-ref lane fails closed (W4.7): when the CLI surface cannot be// loaded the check FAILS instead of warning; pass --no-cli-refs to skip it@@ -367,7 +370,7 @@ for (const root of generatedRoots.filter((r) => existsSync(r))) {}}-// --- 5. paid consent (fail, W4.7; migrations included) ---+// --- 5. paid consent (fail, W4.7; migrations included): a documentation tripwire, not enforcement ---const PAID_COMMAND_RE = /(?:^|[|&;(]|\$)\s*(?:(?:nohup|exec|time)\s+|[A-Z_][A-Z0-9_]*=\S*\s+)*gbrain\s+(embed|reindex|reindex-code|enrich|extract-conversation-facts|book-mirror|dream|jobs\s+submit|doctor)(?![\w-])([^\n`]*)/;const PREAPPROVAL_RE = /(?:^|\s)--(?:yes|max-usd|max-cost|max-cost-usd)(?:[=\s]|$)/;const APPROVAL_WORDING_RE = /\b(?:ask|asks|asked|agree|agrees|agreed|approv\w*|consent\w*|confirm\w*|permission)\b/i;@@ -387,7 +390,7 @@ for (const file of files) {if (m[1] === 'dream' && !/--phase\s+(?:synthesize|patterns|chronicle)\b/.test(m[2]) && /--phase\b/.test(m[2])) continue;const context = lines.slice(Math.max(0, i - 8), i + 1).join('\n');if (APPROVAL_WORDING_RE.test(context)) continue;- failures.push(`[paid-consent] ${rel}:${i + 1} — \`${snippet}\` pre-approves paid work with no approval step near it, so an agent following this would spend without asking. Fix: say to ask the user first (for example "only after the user agrees:" on the line above), and show the free preview (--dry-run) before it`);+ failures.push(`[paid-consent] ${rel}:${i + 1} — \`${snippet}\` pre-approves paid work with no approval step near it, so an agent following this doc would be taught to spend without asking (the runtime consent check still applies; this lint only checks the wording). Fix: say to ask the user first (for example "only after the user agrees:" on the line above), and show the free preview (--dry-run) before it`);}});}diff --git a/src/core/persistence/write-wait.ts b/src/core/persistence/write-wait.tsindex 81c4da34c9..f0e637377b 100644--- a/src/core/persistence/write-wait.ts+++ b/src/core/persistence/write-wait.ts@@ -11,6 +11,7 @@ import { OperationError } from '../ops/contract.ts';import { pinRouting, type FixRouting } from '../fix-routing.ts';import { admittedPendingReceipt, type WriteReceipt } from './types.ts';import { WIRE_WRITE_WAIT_MAX_MS } from './params.ts';+import { shellQuote } from '../shell-quote.ts';/** Agent and server callers keep the historical bounded wait. */export const AGENT_WRITE_WAIT_MS = 5_000;@@ -126,11 +127,12 @@ export function writeErrorExitCode(error: unknown, acceptPending: boolean): numb* `gbrain write-request [--brain <id>] -- <request_id>` argv the error* envelope's `fix` carries. A `fix.argv` that reads this receipt wins, so the* two never disagree; otherwise the receipt command is pinned to `routing`.+ * Each argument is shell-quoted, so the line pastes as the argv it names.*/export function pollCommand(requestId: string, fix?: { argv?: readonly string[] }, routing?: FixRouting): string {const argv = fix?.argv?.[0] === 'gbrain' && fix.argv[1] === 'write-request' && fix.argv.includes(requestId)? fix.argv : pinRouting(['gbrain', 'write-request', '--', requestId], routing);- return argv.join(' ');+ return argv.map(shellQuote).join(' ');}/**diff --git a/src/core/repo-base.ts b/src/core/repo-base.tsindex 7dcf5c50e8..2c91f6e25f 100644--- a/src/core/repo-base.ts+++ b/src/core/repo-base.ts@@ -6,15 +6,15 @@* credentials, query or fragment, and no whitespace or control characters.*/-/** The override with trailing slashes removed; null when unset or blank; `{ invalid }` when it is not a plain https URL. */+/** The override as the URL parser normalizes it, trailing slashes removed; null when unset or blank; `{ invalid }` when it is not a plain https URL. */export function parseRepoBase(raw: string | undefined): string | null | { invalid: string } {const value = raw?.trim().replace(/\/+$/, '');if (!value) return null;- if (/[\s\x00-\x1f\x7f]/.test(value)) return { invalid: value };+ if (/[\s\x00-\x1f\x7f?#]/.test(value)) return { invalid: value };let url: URL;try { url = new URL(value); } catch { return { invalid: value }; }if (url.protocol !== 'https:' || !url.hostname || url.username || url.password || url.search || url.hash) return { invalid: value };- return value;+ return url.href.replace(/\/+$/, '');}/** Build scripts: the override, or `fallback` when unset; an invalid value throws. */diff --git a/test/w13-small-hardening.test.ts b/test/w13-small-hardening.test.tsnew file mode 100644index 0000000000..5ecdce85fe--- /dev/null+++ b/test/w13-small-hardening.test.ts@@ -0,0 +1,52 @@+/**+ * Fix wave 13 P1.14-P1.16 (CSO lows, lane E).+ * Protects: the paid-consent skill lint names itself a documentation tripwire+ * (the runtime consent check is the gate); `pollCommand` renders a server-supplied+ * `fix.argv` shell-quoted, so `$(…)` and spaces paste inert; `parseRepoBase` emits+ * the URL it validated (parser-normalized), not the raw string, and refuses a bare+ * `?`/`#` the parser would drop.+ * Seams: none.+ */+import { describe, expect, test } from 'bun:test';+import { spawnSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { pollCommand } from '../src/core/persistence/write-wait.ts';+import { parseRepoBase } from '../src/core/repo-base.ts';++describe('P1.14 paid-consent lint wording', () => {+ test('the failure says the lint checks wording and the runtime consent check still applies', () => {+ const dir = mkdtempSync(join(tmpdir(), 'w13-lint-'));+ try {+ mkdirSync(join(dir, 'skills', 'alpha'), { recursive: true });+ writeFileSync(join(dir, 'skills', 'alpha', 'SKILL.md'), '```bash\ngbrain reindex-code --yes\n```\n');+ writeFileSync(join(dir, 'allow.txt'), '');+ const res = spawnSync('bun', ['scripts/check-skill-refs.mjs', '--skills-dir', join(dir, 'skills'), '--allowlist', join(dir, 'allow.txt'), '--no-cli-refs'], { encoding: 'utf8' });+ const out = `${res.stdout}${res.stderr}`;+ expect(res.status).toBe(1);+ expect(out).toContain('[paid-consent] skills/alpha/SKILL.md:2');+ expect(out).toContain('the runtime consent check still applies; this lint only checks the wording');+ } finally { rmSync(dir, { recursive: true, force: true }); }+ });+});++describe('P1.15 pollCommand quoting', () => {+ test('a fix.argv element with a space or $(…) is single-quoted', () => {+ const id = 'req 1$(touch /tmp/pwned)';+ expect(pollCommand(id, { argv: ['gbrain', 'write-request', '--brain', 'my brain', '--', id] }))+ .toBe("gbrain write-request --brain 'my brain' -- 'req 1$(touch /tmp/pwned)'");+ expect(pollCommand('0b1c-uuid')).toBe('gbrain write-request -- 0b1c-uuid');+ });+});++describe('P1.16 parseRepoBase returns the parsed URL', () => {+ test('a value the parser normalizes is emitted normalized', () => {+ expect(parseRepoBase('https://Docs.Example.test:443/fork/./gbrain/x/../main/')).toBe('https://docs.example.test/fork/gbrain/main');+ expect(parseRepoBase('https://raw.githubusercontent.com/fork-org/gbrain/main')).toBe('https://raw.githubusercontent.com/fork-org/gbrain/main');+ });+ test('an empty query or fragment marker is refused rather than silently dropped', () => {+ expect(parseRepoBase('https://docs.example.test/x?')).toEqual({ invalid: 'https://docs.example.test/x?' });+ expect(parseRepoBase('https://docs.example.test/x#')).toEqual({ invalid: 'https://docs.example.test/x#' });+ });+});