Skip to content

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

fix: select affirmative TUI trust choice

[._.]/ Adam Eivyfa129fd4d3e7
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index 93c5f085a6..8685fe6781 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -288,6 +288,24 @@ export const BRACKETED_PASTE_MODE_PATTERN = /\x1b\[\?2004([hl])/g;
export const TUI_TRUST_PROMPT_PATTERN =
/trustthisfolder|isthisaprojectyou(?:created|trust)|doyoutrustthecontentsofthis(?:directory|project|folder)/i;
+// Trust selectors have changed ordering across Claude Code releases. Older
+// builds (and Codex/agy) highlight the affirmative choice first, while newer
+// Claude Code builds can render "No, exit" first and highlight it. Consumers must
+// wait until the choices themselves have painted, then move off a highlighted
+// decline choice instead of assuming a bare Enter always accepts the folder.
+// These patterns run against createInputReadyTracker's whitespace-free tail.
+const TUI_TRUST_ACCEPT_OPTION_PATTERN = /(?:yes,?itrustthisfolder|yes,?continue)/i;
+const TUI_TRUST_DECLINE_OPTION_PATTERN = /no,?(?:exit|quit)/i;
+const TUI_HIGHLIGHT_PATTERN_PREFIX = String.raw`(?:❯|›|>)\d*\.?`;
+const TUI_TRUST_HIGHLIGHTED_ACCEPT_PATTERN = new RegExp(
+ `${TUI_HIGHLIGHT_PATTERN_PREFIX}(?:yes,?itrustthisfolder|yes,?continue)`,
+ 'i',
+);
+const TUI_TRUST_HIGHLIGHTED_DECLINE_PATTERN = new RegExp(
+ `${TUI_HIGHLIGHT_PATTERN_PREFIX}no,?(?:exit|quit)`,
+ '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, keep
// don't ask"), added in v2.1.233. Like the trust gate it is NOT bypassed by
@@ -367,6 +385,8 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunch
// launches, where the TUI owns the PTY from byte zero and no shell OFF exists.
let sawCommandRun = directLaunch;
let needsTrust = false;
+ let trustChoiceReady = false;
+ let trustNeedsSelectionAdvance = false;
let sawReadyText = false;
// Auto-mode offer: latched when seen, cleared once answered. `autoModeAnswered`
// makes the ack TERMINAL — `tail` is a rolling 4000-char window, so the modal's
@@ -407,6 +427,8 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunch
&& (!readyTextPattern || sawReadyText);
},
get needsTrust() { return needsTrust; },
+ get trustChoiceReady() { return trustChoiceReady; },
+ get trustNeedsSelectionAdvance() { return trustNeedsSelectionAdvance; },
get needsAutoModeChoice() { return needsAutoModeChoice; },
get needsExternalImportsChoice() { return needsExternalImportsChoice; },
get needsHookReview() { return needsHookReview; },
@@ -435,6 +457,23 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunch
if (strippedText) {
tail = (tail + strippedText.replace(/\s+/g, '')).slice(-OBSERVE_TAIL_MAX_LEN);
if (!needsTrust && TUI_TRUST_PROMPT_PATTERN.test(tail)) needsTrust = true;
+ if (needsTrust && !trustChoiceReady) {
+ const acceptMatch = TUI_TRUST_ACCEPT_OPTION_PATTERN.exec(tail);
+ const declineMatch = TUI_TRUST_DECLINE_OPTION_PATTERN.exec(tail);
+ if (acceptMatch) {
+ trustChoiceReady = true;
+ if (TUI_TRUST_HIGHLIGHTED_DECLINE_PATTERN.test(tail)) {
+ trustNeedsSelectionAdvance = true;
+ } else if (TUI_TRUST_HIGHLIGHTED_ACCEPT_PATTERN.test(tail)) {
+ trustNeedsSelectionAdvance = false;
+ } else if (declineMatch) {
+ // Ink highlights the first rendered option when its cursor glyph
+ // is unavailable in a captured transcript. Use ordering only as
+ // that fallback; explicit highlight chrome wins above.
+ trustNeedsSelectionAdvance = declineMatch.index < acceptMatch.index;
+ }
+ }
+ }
if (!needsAutoModeChoice && !autoModeAnswered && TUI_AUTO_MODE_PROMPT_PATTERN.test(tail)) needsAutoModeChoice = true;
if (!needsExternalImportsChoice && !externalImportsAnswered && TUI_EXTERNAL_IMPORTS_PROMPT_PATTERN.test(tail)) {
needsExternalImportsChoice = true;
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index e6dd4c003c..b611ea1ae7 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -1031,12 +1031,15 @@ describe('createInputReadyTracker', () => {
it('latches needsTrust on every vendor trust-gate wording', () => {
const claude = createInputReadyTracker();
- claude.observe('', 'Is this a project you trust?');
+ claude.observe('', 'Is this a project you trust?\n❯ 1. Yes, I trust this folder\n2. No, exit\n');
expect(claude.needsTrust).toBe(true);
+ expect(claude.trustChoiceReady).toBe(true);
+ expect(claude.trustNeedsSelectionAdvance).toBe(false);
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);
+ expect(agy.trustChoiceReady).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
@@ -1046,6 +1049,20 @@ describe('createInputReadyTracker', () => {
+ ' 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);
+ expect(codex.trustChoiceReady).toBe(true);
+ expect(codex.trustNeedsSelectionAdvance).toBe(false);
+ });
+
+ it('detects when Claude highlights the decline choice before trust acceptance', () => {
+ const tracker = createInputReadyTracker({ directLaunch: true });
+ tracker.observe('', 'Quick safety check: Is this a project you created or one you trust?\n'
+ + '❯ No, exit\n'
+ + ' Yes, I trust this folder\n'
+ + 'Enter to confirm · Esc to cancel\n');
+
+ expect(tracker.needsTrust).toBe(true);
+ expect(tracker.trustChoiceReady).toBe(true);
+ expect(tracker.trustNeedsSelectionAdvance).toBe(true);
});
// Claude Code v2.1.233's auto-mode offer. Unlike the trust gate it paints with
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index d850c7fc42..98c7002aed 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -1477,9 +1477,11 @@ export async function spawnTuiAgent({
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.
+ // Auto-confirm the first-run "trust this folder?" gate so agents can run in
+ // fresh worktrees. Wait for the choices themselves to paint: Claude Code
+ // releases disagree about their ordering, and newer builds can highlight
+ // "No, exit" by default. Move to the affirmative option when necessary,
+ // then submit it 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,
@@ -1488,9 +1490,10 @@ export async function spawnTuiAgent({
// 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) {
+ if (inputReady.needsTrust && inputReady.trustChoiceReady && !trustAccepted) {
trustAccepted = true;
- shellService.writeToSession(sessionId, SUBMIT_KEY);
+ const trustInput = `${inputReady.trustNeedsSelectionAdvance ? '\x1b[B' : ''}${SUBMIT_KEY}`;
+ shellService.writeToSession(sessionId, trustInput);
lastOutputAt = now;
firstOutputAt = null;
appendLine(`📟 Auto-confirmed ${tuiConfig.command} folder-trust prompt for session ${sessionId.slice(0, 8)}`);
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index 0ed20a7121..4230af3f7d 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -1084,6 +1084,25 @@ describe('spawnTuiAgent runtime', () => {
expect(pasteCount()).toBe(1);
});
+ it('claude trust gate: moves from a highlighted No choice before confirming', async () => {
+ runSpawn({ tuiConfig: claudeTuiConfig, useDurableRunner: true });
+ await flushMicrotasks();
+
+ await capturedOnData(Buffer.from(
+ 'Quick safety check: Is this a project you created or one you trust?\n'
+ + '❯ No, exit\n'
+ + ' Yes, I trust this folder\n'
+ + 'Enter to confirm · Esc to cancel\n',
+ ));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(400);
+ await flushMicrotasks();
+
+ expect(vi.mocked(shellService.writeToSession).mock.calls.map(([, data]) => data))
+ .toContain('\x1b[B\r');
+ expect(pasteCount()).toBe(0);
+ });
+
// Claude Code v2.1.233's auto-mode offer. The trust gate above paints BEFORE
// the composer; this one paints after, with paste mode already on — so the old
// gate said "ready" and the prompt went into a modal that ignored it. All four
diff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.js
index 31bf04e08f..48b3937e29 100644
--- a/server/services/tuiPromptRunner.js
+++ b/server/services/tuiPromptRunner.js
@@ -877,11 +877,13 @@ ${prompt}`;
// 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) {
+ // Wait for the options to paint before acting. Claude Code versions do
+ // not agree on their order: when "No, exit" is highlighted, select the
+ // next option before submitting. `trustAccepted` keeps this to one input.
+ if (inputReady.needsTrust && inputReady.trustChoiceReady && !trustAccepted) {
trustAccepted = true;
- dismissStartupDialog('\r', 'folder-trust prompt');
+ const trustInput = `${inputReady.trustNeedsSelectionAdvance ? '\x1b[B' : ''}${SUBMIT_KEY}`;
+ dismissStartupDialog(trustInput, 'folder-trust prompt');
lastOutputAt = now;
firstOutputAt = null;
return;
diff --git a/server/services/tuiPromptRunner.test.js b/server/services/tuiPromptRunner.test.js
index df0e20fe88..8965ad32da 100644
--- a/server/services/tuiPromptRunner.test.js
+++ b/server/services/tuiPromptRunner.test.js
@@ -617,6 +617,31 @@ describe('executeTuiRun', () => {
await promise;
});
+ it('moves off Claude\'s highlighted decline choice before accepting trust', async () => {
+ vi.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],
+ });
+ const provider = { id: 'claude', type: 'tui', command: 'claude', tuiPromptDelayMs: 50 };
+ const promise = executeTuiRun({
+ runId: 'run-claude-decline-default', provider, prompt: 'return one structured response',
+ workspacePath: TEST_WORKSPACE, timeout: 60000,
+ });
+ await flushAsync();
+
+ const pty = ptyInstances[0];
+ pty.emitData('Quick safety check: Is this a project you created or one you trust?\n'
+ + '❯ No, exit\n'
+ + ' Yes, I trust this folder\n'
+ + 'Enter to confirm · Esc to cancel\n');
+ await vi.advanceTimersByTimeAsync(400);
+
+ expect(pty.write).toHaveBeenCalledWith('\x1b[B\r');
+ expect(pty.write).not.toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));
+
+ pty.emitExit({ exitCode: 0 });
+ await promise;
+ });
+
it('declines Claude auto-mode and pastes only after dismissing the offer', async () => {
vi.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],