Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: answer Codex's directory-trust dialog instead of pasting the task into it
[._.]/ Adam Eivy0fdd949abe19
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex be4c37676a..e913d8e056 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -269,13 +269,24 @@ export function isPasteConfirmed(strippedBuffer, { verifiablePrefix = null, prom// text is not reliably matchable. Terminal-mode toggles survive intact.)export const BRACKETED_PASTE_MODE_PATTERN = /\x1b\[\?2004([hl])/g;-// Claude Code's first-run folder-trust gate ("Is this a project you trust? →-// 1. Yes, I trust this folder / 2. No, exit"). `--dangerously-skip-permissions`-// does NOT bypass it, and CoS agents can start in folders claude hasn't seen.+// First-run folder-trust gates. Claude Code's ("Is this a project you trust? →+// 1. Yes, I trust this folder / 2. No, exit"), agy's ("Do you trust the contents+// of this project?"), and Codex's ("You are in <dir> / Do you trust the contents+// of this directory? → 1. Yes, continue / 2. No, quit"). NONE of them is bypassed+// by the vendor's own danger flag (`--dangerously-skip-permissions`,+// `--dangerously-bypass-approvals-and-sandbox`), and CoS agents routinely start+// in folders the CLI has never seen — a fresh worktree, or the per-agent temp cwd+// creative-director tasks run in, which is a NEW directory on every single run.// Matched against the WHITESPACE-STRIPPED text (same inter-glyph-spacing caveat-// as the footer). The spawner auto-confirms the default ("Yes, I trust").+// as the footer). The spawner auto-confirms the default (claude/agy "Yes, I+// trust"; codex "Yes, continue").+//+// Codex's wording carries neither "trust this folder" nor "is this a project+// you…", so before the third alternative it matched nothing: the dialog sat+// unanswered, the idle heuristic pasted the task into it, and the run died+// `paste-not-rendered` (agent-671af38f, 2026-08-21).export const TUI_TRUST_PROMPT_PATTERN =- /trustthisfolder|isthisaprojectyou(?:created|trust)/i;+ /trustthisfolder|isthisaprojectyou(?:created|trust)|doyoutrustthecontentsofthis(?:directory|project|folder)/i;// Claude Code's auto-mode opt-in offer ("Make auto mode your default permission// mode? → 1. Yes, set auto mode as my default permission mode / 2. No, keepdiff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex 548ef2a694..4a3804680e 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -1024,7 +1024,7 @@ describe('createInputReadyTracker', () => {expect(tracker.ready).toBe(true);});- it('latches needsTrust on either trust-gate wording', () => {+ it('latches needsTrust on every vendor trust-gate wording', () => {const claude = createInputReadyTracker();claude.observe('', 'Is this a project you trust?');expect(claude.needsTrust).toBe(true);@@ -1032,6 +1032,15 @@ describe('createInputReadyTracker', () => {const agy = createInputReadyTracker();agy.observe('', 'Do you trust the contents of this project?\n> Yes, I trust this folder\n');expect(agy.needsTrust).toBe(true);++ // Codex says "directory", and its options are "Yes, continue / No, quit" —+ // neither of the two older alternatives appears anywhere in the dialog, so it+ // went unmatched and the run pasted its task into the menu (agent-671af38f).+ const codex = createInputReadyTracker();+ codex.observe('', 'You are in /tmp/portos-cd-cwd/agent-abc\nDo you trust the contents of this directory?'+ + ' Working with untrusted contents comes with higher risk of prompt injection.\n'+ + '› 1. Yes, continue\n2. No, quit\nPress enter to continue\n');+ expect(codex.needsTrust).toBe(true);});// Claude Code v2.1.233's auto-mode offer. Unlike the trust gate it paints withdiff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.jsindex 99ff264dab..716f8c8217 100644--- a/server/lib/tuiPromptRunner.js+++ b/server/lib/tuiPromptRunner.js@@ -773,9 +773,10 @@ ${prompt}`;}};- // Ready watch — Claude dismisses known startup dialogs before sending- // anything, then waits for its positive input-ready signal. Other providers- // retain the existing idle/deadline fallback unchanged.+ // Ready watch — known startup dialogs (folder trust, Codex's hook review)+ // are dismissed for EVERY provider before anything is sent, since each of+ // them swallows a paste. Claude then waits for its positive input-ready+ // signal; other providers retain the idle/deadline fallback for delivery.readyTimer = setInterval(() => {if (finalized || promptSentAt) {clearInterval(readyTimer);@@ -784,6 +785,14 @@ ${prompt}`;}const now = Date.now();const elapsed = now - startTime;+ // Both dismissals below rewind the idle clock and clear `firstOutputAt`:+ // the idle path further down reads silence as readiness, and a dialog is+ // quietest right after it paints, so otherwise the keystroke and an idle+ // paste go out inside the same window and the prompt lands in a menu that+ // has not repainted. Requiring fresh output-then-silence after the+ // keystroke makes delivery wait for what the dismissal reveals;+ // PASTE_DEADLINE_MS still backstops a dismissal the TUI ignores entirely.+// Codex's hook-review selector precedes its composer. An unattended run// must not grant hooks permission to execute outside the sandbox, so take// the explicit "Continue without trusting" option before ordinary@@ -793,14 +802,25 @@ ${prompt}`;if (dismissStartupDialog('\x1b[B\x1b[B\r', 'hook-review prompt')) {inputReady.ackHookReview();}+ lastOutputAt = now;+ firstOutputAt = null;+ return;+ }+ // The first-run folder-trust gate, like the hook-review selector above,+ // must be answered for EVERY provider rather than only the input-ready+ // ones: codex takes the idle/deadline path below, and its trust dialog+ // paints and then goes silent — which that path reads as "ready" and+ // pastes into, losing the prompt and every retry with it (agent-671af38f).+ // Enter takes the highlighted default (claude/agy "Yes, I trust", codex+ // "Yes, continue"); `trustAccepted` keeps it to one keystroke.+ if (inputReady.needsTrust && !trustAccepted) {+ trustAccepted = true;+ dismissStartupDialog('\r', 'folder-trust prompt');+ lastOutputAt = now;+ firstOutputAt = null;return;}if (requiresInputReady) {- if (inputReady.needsTrust && !trustAccepted) {- trustAccepted = true;- dismissStartupDialog('\r', 'folder-trust prompt');- return;- }if (inputReady.needsAutoModeChoice) {// Select "No, keep don't ask" so a one-shot run never rewrites the// user's global Claude permission default as a startup side effect.diff --git a/server/lib/tuiPromptRunner.test.js b/server/lib/tuiPromptRunner.test.jsindex 5a2797cdee..cefae78712 100644--- a/server/lib/tuiPromptRunner.test.js+++ b/server/lib/tuiPromptRunner.test.js@@ -568,6 +568,38 @@ describe('executeTuiRun', () => {await promise;});+ it('confirms the Codex directory-trust gate before its idle path can paste', async () => {+ vi.useFakeTimers({+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],+ });+ const provider = { id: 'codex', type: 'tui', command: 'codex', tuiPromptDelayMs: 50 };+ const promise = executeTuiRun({+ runId: 'run-codex-trust-gate', provider, prompt: 'return one structured response',+ workspacePath: TEST_WORKSPACE, timeout: 60000,+ });+ await flushAsync();++ const pty = ptyInstances[0];+ pty.emitData(+ 'You are in /tmp/portos-cd-cwd/agent-abc\n'+ + 'Do you trust the contents of this directory? Working with untrusted contents comes with'+ + ' higher risk of prompt injection.\n'+ + '› 1. Yes, continue\n2. No, quit\nPress enter to continue\n',+ );+ // Past the idle threshold — the window the prompt used to be pasted in.+ await vi.advanceTimersByTimeAsync(2000);++ expect(pty.write).toHaveBeenCalledWith('\r');+ expect(pty.write).not.toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));++ pty.emitData('OpenAI Codex ready\n');+ await vi.advanceTimersByTimeAsync(2000);+ expect(pty.write).toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));++ pty.emitExit({ exitCode: 0 });+ await promise;+ });+it('declines Codex hook trust and pastes only after its selector clears', async () => {vi.useFakeTimers({toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],@@ -600,7 +632,10 @@ describe('executeTuiRun', () => {await promise;});- it('keeps non-Claude TUIs on the existing idle fallback when startup output resembles Claude trust text', async () => {+ // A non-Claude TUI keeps the idle fallback for DELIVERY, but a trust gate is+ // still answered first — every vendor's gate swallows the paste the same way,+ // and leaving it up only guarantees the prompt is lost (agent-671af38f).+ it('answers a trust gate for a non-Claude TUI, then delivers on the existing idle fallback', async () => {vi.useFakeTimers({toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],});@@ -615,7 +650,13 @@ describe('executeTuiRun', () => {pty.emitData('Is this a project you trust?\n1. Yes, I trust this folder\n2. No, exit\n');await vi.advanceTimersByTimeAsync(2000);- expect(pty.write).not.toHaveBeenCalledWith('\r');+ expect(pty.write).toHaveBeenCalledWith('\r');+ // No composer repaint followed the keystroke, so the idle clock restarted+ // from it — delivery still happens, via the blind PASTE_DEADLINE_MS+ // fallback that governs non-input-ready providers.+ expect(pty.write).not.toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));+ pty.emitData('opencode ready\n');+ await vi.advanceTimersByTimeAsync(2000);expect(pty.write).toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));pty.emitExit({ exitCode: 0 });diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 998a1d7e34..7d8735d90c 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -1396,6 +1396,16 @@ export async function spawnTuiAgent({const now = Date.now();const elapsed = now - startedAt;+ // Every dismissal below rewinds the idle clock (`lastOutputAt`) AND clears+ // `firstOutputAt`, which re-arms the idle path's "has it printed anything?"+ // gate. The idle heuristic that governs codex reads silence as readiness,+ // and a dialog is at its quietest right after it paints — so the dismissal+ // keystroke and an idle paste can otherwise go out inside the same window,+ // landing the prompt in a menu that has not repainted. Demanding fresh+ // output-then-silence AFTER the keystroke makes the paste wait for whatever+ // the dismissal reveals; if the TUI ignores the keystroke entirely,+ // PASTE_DEADLINE_MS still backstops delivery.+// Codex can present a hook-review selector before its composer exists.// Do not trust hooks from an unattended run: option 3 keeps them disabled// for this session and lets the agent continue without executing code@@ -1405,20 +1415,33 @@ export async function spawnTuiAgent({hookReviewDeclined = true;shellService.writeToSession(sessionId, '\x1b[B\x1b[B\r');inputReady.ackHookReview();+ lastOutputAt = now;+ firstOutputAt = null;appendLine(`📟 Continued ${tuiConfig.command} without trusting startup hooks for session ${sessionId.slice(0, 8)}`);return;}+ // Auto-confirm the first-run "trust this folder?" gate (claude's, agy's and+ // codex's all default to yes) so agents can run in fresh worktrees. Send+ // Enter once.+ //+ // Like the hook-review selector this runs for EVERY TUI, not only the+ // positive input-ready providers below: codex takes the idle/deadline path,+ // and its trust dialog goes quiet the instant it paints, so the idle+ // heuristic reads that silence as "ready" and pastes the task straight into+ // the menu — which swallows it and all three paste retries+ // (agent-671af38f, 2026-08-21, `paste-not-rendered`). Answering the dialog+ // first is what lets the composer appear at all.+ if (inputReady.needsTrust && !trustAccepted) {+ trustAccepted = true;+ shellService.writeToSession(sessionId, SUBMIT_KEY);+ lastOutputAt = now;+ firstOutputAt = null;+ appendLine(`📟 Auto-confirmed ${tuiConfig.command} folder-trust prompt for session ${sessionId.slice(0, 8)}`);+ return;+ }+if (requireInputReady) {- // Auto-confirm the first-run "trust this folder?" gate (claude's and agy's- // both default to "Yes, I trust") so claims can run in fresh worktrees.- // Send Enter once.- if (inputReady.needsTrust && !trustAccepted) {- trustAccepted = true;- shellService.writeToSession(sessionId, SUBMIT_KEY);- appendLine(`📟 Auto-confirmed ${tuiConfig.command} folder-trust prompt for session ${sessionId.slice(0, 8)}`);- return;- }// Decline claude's "make auto mode your default permission mode?" offer// (v2.1.233+). Unlike the trust gate this one paints AFTER the composer is// live, so it swallows the paste and every retry unless it is cleareddiff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex c71602cac3..1916063608 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -1123,6 +1123,41 @@ describe('spawnTuiAgent runtime', () => {expect(pasteCount()).toBe(1);});+ // Regression (agent-671af38f, 2026-08-21): codex takes the idle/deadline path,+ // and its first-run directory-trust dialog paints and then goes SILENT — which+ // that path read as "ready". The task went into the menu, all three paste+ // retries with it, and the run died `paste-not-rendered`. Creative-director+ // tasks run in a fresh per-agent temp cwd, so codex asked on every single run.+ it('codex folder-trust gate: confirms it before the idle heuristic can paste', async () => {+ runSpawn();+ await flushMicrotasks();++ await capturedOnData(Buffer.from(+ 'You are in /tmp/portos-cd-cwd/agent-1\n'+ + 'Do you trust the contents of this directory? Working with untrusted contents comes with'+ + ' higher risk of prompt injection.\n'+ + '› 1. Yes, continue\n'+ + '2. No, quit\n'+ + 'Press enter to continue\n',+ ));+ await flushMicrotasks();+ // Past the 1200ms idle threshold — the window in which the prompt used to go+ // into the dialog.+ await vi.advanceTimersByTimeAsync(2000);+ await flushMicrotasks();++ // A bare Enter takes the highlighted "1. Yes, continue" — sent ONCE, not on+ // every poll tick — and nothing pasted.+ expect(vi.mocked(shellService.writeToSession).mock.calls.filter(([, d]) => d === '\r').length).toBe(1);+ expect(pasteCount()).toBe(0);++ // Trust accepted → codex paints its composer → the ordinary idle path pastes.+ await capturedOnData(Buffer.from('OpenAI Codex ready\n'));+ await vi.advanceTimersByTimeAsync(2000);+ await flushMicrotasks();+ expect(pasteCount()).toBe(1);+ });+it('tui-not-ready: claude that never shows an input prompt finalizes failure without pasting', async () => {let resolveComplete;const completeDone = new Promise((r) => { resolveComplete = r; });