The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(cli): a Buddy's guard refuses a post or proposal read from stdin (#2358)
0xken15f372c499d3c2
diff --git a/cli/src/lib/buddyGuard.claude.spec.ts b/cli/src/lib/buddyGuard.claude.spec.tsindex af2e12ea4..c885e2464 100644--- a/cli/src/lib/buddyGuard.claude.spec.ts+++ b/cli/src/lib/buddyGuard.claude.spec.ts@@ -97,6 +97,9 @@ describe.skipIf(!hasClaude).each([curlPost: bash(''),joined: bash('git log && git push origin HEAD:main'),harnessNew: bash('harness new codex'),+ // Since #2355 a post's TEXT - reads stdin, which the guard cannot check for secrets; a proposal's JSON - likewise.+ postStdin: bash('harness super-tab --tab t post chat - op-2'),+ proposeStdin: bash("harness super-tab --tab t propose op-3 '-'"),// The waits Scholes's Buddy started for its chat, which stopped it at "Do you want to proceed?" (10-29): a Monitor// polling it, the same loop in the shell, and a read left running in the background.monitorLoop: { name: 'Monitor', input: { command: 'while true; do harness super-tab --tab t messages chat; sleep 30; done',@@ -291,6 +294,12 @@ describe.skipIf(!hasClaude).each([expect(result?.is_error).toBe(true)})+ it.skipIf(skip)('tells it to pass a post or a proposal as its argument, not on stdin', () => {+ for (const call of [refused.postStdin, refused.proposeStdin]) {+ expect(JSON.stringify(api.results.get(api.id(call))?.content)).toContain('Harness cannot check it for secrets')+ }+ })+it.skipIf(skip)('pushed nothing', () => {expect(execFileSync('git', ['--git-dir', remote, 'for-each-ref'], { encoding: 'utf8' })).toBe('')})diff --git a/cli/src/lib/buddyGuard.spec.ts b/cli/src/lib/buddyGuard.spec.tsindex 8d119d3eb..fbc7de5a0 100644--- a/cli/src/lib/buddyGuard.spec.ts+++ b/cli/src/lib/buddyGuard.spec.ts@@ -308,6 +308,54 @@ describe('a Buddy\'s guard (Ken, 10-29: reads without a prompt, refuses everythiexpect(reason).toContain('an Artifact link they sent, with the Artifact tool\'s read and that link')})+ // Since #2355 a post's TEXT - reads the message from stdin, as a proposal's JSON - always has: the guard sees only the dash,+ // so it could not check what is sent for secrets. A Buddy cannot feed stdin today (no pipes, redirects or heredocs), but+ // its guard must not depend on that.+ function refusal(command: string): { permissionDecision: string; permissionDecisionReason: string } {+ const run = hook(JSON.stringify({ hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command, description: 'x' }, cwd: root }))+ expect(run.status).toBe(0)+ return JSON.parse(run.stdout).hookSpecificOutput+ }+ it.each([+ 'harness super-tab --tab t post chat - op-1',+ 'harness super-tab post chat - op-1',+ "harness super-tab --tab t post chat '-' op-1",+ 'harness super-tab --tab t post chat "-" op-1',+ "harness super-tab --tab t post chat ''- op-1",+ "harness super-tab --tab t post chat -'' op-1",+ 'harness super-tab --tab t --tab t post chat - op-1',+ 'harness super-tab --tab t post chat - op-1 --reply-to m1',+ 'harness super-tab --tab t post chat - op-1 --attach notes/plan.md',+ 'harness super-tab --tab t post chat - op-1 --mention ken',+ ])('refuses a post whose message would come from stdin, naming the fix: %s', command => {+ const { permissionDecision, permissionDecisionReason } = refusal(command)+ expect(permissionDecision).toBe('deny')+ expect(permissionDecisionReason).toContain('nobody will be asked')+ expect(permissionDecisionReason).toContain('Harness cannot check it for secrets')+ expect(permissionDecisionReason).toContain("harness super-tab post GROUP 'your message' OPERATION_ID")+ expect(permissionDecisionReason).toContain('in double quotes when it holds an apostrophe')+ })+ // The fix it names goes through: a message with an apostrophe, the one a Buddy might have sent on stdin, in double quotes.+ it('sends the message the refusal tells it to, in double quotes when it holds an apostrophe', () => {+ expect(bash('harness super-tab --tab t post chat "it\'s done: the - case is refused" op-1 --reply-to m1')).toBe('allow')+ })+ it.each([+ 'harness super-tab --tab t propose op-1 -',+ "harness super-tab --tab t propose op-1 '-'",+ 'harness super-tab --tab t propose op-1 - --attach notes/plan.md',+ ])('refuses a proposal whose JSON would come from stdin, naming the fix: %s', command => {+ const { permissionDecision, permissionDecisionReason } = refusal(command)+ expect(permissionDecision).toBe('deny')+ expect(permissionDecisionReason).toContain('nobody will be asked')+ expect(permissionDecisionReason).toContain('Harness cannot check it for secrets')+ expect(permissionDecisionReason).toContain("harness super-tab propose OPERATION_ID '{")+ })+ // Only a TEXT that is exactly - reads stdin (superTabs/command.ts): any other is the message, dashes and all.+ it.each(['--', '---', '- ', ' -', '-x', '- P1: fixed in 3f2a', '-1 is the exit code', 'a - b', '- '])('still sends a post whose text is %j', text => {+ expect(bash(`harness super-tab --tab t post chat '${text}' op-1`)).toBe('allow')+ expect(bash(`harness super-tab --tab t post chat '${text}' op-1 --reply-to m1`)).toBe('allow')+ })+it('fails closed: a guard that cannot run blocks the call (exit 2) instead of falling back to other rules', () => {const missing = buddyGuardCommand(join(root, 'no-node'), script)expect(spawnSync('/bin/sh', ['-c', missing], { input: '{}', encoding: 'utf8' }).status).toBe(2)diff --git a/cli/src/lib/buddyGuard.ts b/cli/src/lib/buddyGuard.tsindex 0e995cfb3..167605cb1 100644--- a/cli/src/lib/buddyGuard.ts+++ b/cli/src/lib/buddyGuard.ts@@ -580,7 +580,11 @@ function pastedOutput(json) {const text = [proposal?.goal, proposal?.scope].filter((part) => typeof part === 'string').join('\n')return text.includes('\x60\x60\x60') || text.split('\n').length > 10}-const SUMMARIZE = 'A proposal carries your summary of what you read, never its output: no code block and at most 10 lines. Nothing ' ++const STDIN = (action) => (action === 'post' ? 'A Buddy passes its message as TEXT itself' : 'A Buddy passes its proposal\'s JSON itself') ++ ': - in its place reads it from stdin, where Harness cannot check it for secrets. Nothing was sent, and nobody will be asked. ' ++ 'Send again with it in quotes where the - was: ' + (action === 'post' ? 'harness super-tab post GROUP \'your message\' OPERATION_ID'+ + ', or in double quotes when it holds an apostrophe: "it\'s done"' : 'harness super-tab propose OPERATION_ID \'{"conversationId":"...","goal":"..."}\'') + '.'+const SUMMARIZE ='A proposal carries your summary of what you read, never its output: no code block and at most 10 lines. Nothing ' +'was sent, and nobody will be asked. Summarize the numbers and findings in a few lines and send again.'// harness super-tab [--tab ID] ACTION ...: only a Buddy's actions, an --attach only from its folder, and nothing it sends@@ -593,6 +597,11 @@ function superTabAllowed(rest) {if (after.some((word, at) => (word === '--attach' && (after[at + 1] === undefined || outward(after[at + 1])))|| ['--agent', '--port', '--machine'].includes(word))) return falseif (rest[i] !== 'post' && rest[i] !== 'propose') return true+ // A post's TEXT or a proposal's JSON that is exactly - is read from stdin (superTabs/command.ts, post since #2355), where+ // this guard sees only the dash and cannot check what is sent for secrets. A Buddy cannot feed stdin today (no pipes,+ // redirects or heredocs above), but the secret check must not rest on that. Any other text, -- or "- P1" among them, is+ // the message itself and is checked as it is.+ if (after[1] === '-') { reason = STDIN(rest[i]); return false }const attached = after.flatMap((word, at) => after[at - 1] === '--attach' ? [fileText(word)] : [])if (attached.includes(null)) return false// Its words one by one, and what it says run together: the post's text or the proposal's decoded fields, with its files.diff --git a/cli/src/lib/buddyGuard.wide.spec.ts b/cli/src/lib/buddyGuard.wide.spec.tsindex b5dac4496..6a360a469 100644--- a/cli/src/lib/buddyGuard.wide.spec.ts+++ b/cli/src/lib/buddyGuard.wide.spec.ts@@ -494,6 +494,17 @@ describe('no secret leaves in a post or a proposal', () => {expect(bash(`harness super-tab post chat '${text}' op-1`)).toBe('allow')})+ // Since #2355 a post's TEXT - reads stdin, which the secret check above cannot see: refused in wide mode as in its folder.+ it('refuses a post or a proposal read from stdin, wide or not', () => {+ for (const guard of [script, narrow]) {+ for (const command of ['harness super-tab post chat - op-1', "harness super-tab post chat '-' op-1 --reply-to m1", 'harness super-tab propose op-1 -']) {+ const refused = answer('Bash', { command, description: 'x' }, guard)+ expect(refused.permissionDecision).toBe('deny')+ expect(refused.permissionDecisionReason).toContain('Harness cannot check it for secrets')+ }+ }+ })+it.each([['a code block', 'Logs:\n```\nerror at line 1\n```'],['more than 10 lines', Array.from({ length: 11 }, (_, i) => `line ${i}`).join('\n')],