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
address review (claude): harden trust selection
[._.]/ Adam Eivy605bc0f7fa21
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex 8685fe6781..19e6c2ed2f 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -385,8 +385,9 @@ 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 trustAnswered = false;let trustChoiceReady = false;- let trustNeedsSelectionAdvance = false;+ let trustSelectionKey = '';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@@ -422,16 +423,18 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunch// modal is still swallowing input. Cleared by ackAutoModeChoice() once the// spawner has answered it.get ready() {- return sawCommandRun && pasteModeOn && !needsAutoModeChoice+ return sawCommandRun && pasteModeOn && !needsTrust && !needsAutoModeChoice&& !needsExternalImportsChoice && !needsHookReview&& (!readyTextPattern || sawReadyText);},get needsTrust() { return needsTrust; },get trustChoiceReady() { return trustChoiceReady; },- get trustNeedsSelectionAdvance() { return trustNeedsSelectionAdvance; },+ get trustSelectionKey() { return trustSelectionKey; },get needsAutoModeChoice() { return needsAutoModeChoice; },get needsExternalImportsChoice() { return needsExternalImportsChoice; },get needsHookReview() { return needsHookReview; },+ /** Spawner selected the affirmative trust choice. */+ ackTrustChoice() { needsTrust = false; trustAnswered = true; },/** Spawner reports the dismissal keystrokes went out; re-arms `ready`. */ackAutoModeChoice() { needsAutoModeChoice = false; autoModeAnswered = true; },/** Spawner selected Claude's "No, disable external imports" option. */@@ -456,21 +459,21 @@ 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 && !trustAnswered && 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;+ trustSelectionKey = declineMatch && declineMatch.index < acceptMatch.index ? '\x1b[B' : '\x1b[A';} else if (TUI_TRUST_HIGHLIGHTED_ACCEPT_PATTERN.test(tail)) {- trustNeedsSelectionAdvance = false;+ trustSelectionKey = '';} 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;+ trustSelectionKey = declineMatch.index < acceptMatch.index ? '\x1b[B' : '';}}}diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex b611ea1ae7..7e50af6627 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -1034,7 +1034,7 @@ describe('createInputReadyTracker', () => {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);+ expect(claude.trustSelectionKey).toBe('');const agy = createInputReadyTracker();agy.observe('', 'Do you trust the contents of this project?\n> Yes, I trust this folder\n');@@ -1050,7 +1050,7 @@ describe('createInputReadyTracker', () => {+ '› 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);+ expect(codex.trustSelectionKey).toBe('');});it('detects when Claude highlights the decline choice before trust acceptance', () => {@@ -1062,7 +1062,37 @@ describe('createInputReadyTracker', () => {expect(tracker.needsTrust).toBe(true);expect(tracker.trustChoiceReady).toBe(true);- expect(tracker.trustNeedsSelectionAdvance).toBe(true);+ expect(tracker.trustSelectionKey).toBe('\x1b[B');+ });++ it('uses option ordering when trust-choice highlight chrome is absent', () => {+ const declineFirst = createInputReadyTracker();+ declineFirst.observe('', 'Is this a project you trust?\nNo, exit\nYes, I trust this folder\n');+ expect(declineFirst.trustChoiceReady).toBe(true);+ expect(declineFirst.trustSelectionKey).toBe('\x1b[B');++ const acceptFirst = createInputReadyTracker();+ acceptFirst.observe('', 'Is this a project you trust?\nYes, I trust this folder\nNo, exit\n');+ expect(acceptFirst.trustChoiceReady).toBe(true);+ expect(acceptFirst.trustSelectionKey).toBe('');+ });++ it('moves upward when the highlighted decline choice follows the accept choice', () => {+ const tracker = createInputReadyTracker();+ tracker.observe('', 'Is this a project you trust?\nYes, I trust this folder\n❯ No, exit\n');+ expect(tracker.trustSelectionKey).toBe('\x1b[A');+ });++ it('suppresses readiness until the trust choice is identified and acknowledged', () => {+ const tracker = createInputReadyTracker({ directLaunch: true });+ tracker.observe(PASTE_ON, 'Is this a project you trust?');+ expect(tracker.needsTrust).toBe(true);+ expect(tracker.trustChoiceReady).toBe(false);+ expect(tracker.ready).toBe(false);++ tracker.observe('', 'Yes, I trust this folder\nNo, exit\n');+ tracker.ackTrustChoice();+ expect(tracker.ready).toBe(true);});// Claude Code v2.1.233's auto-mode offer. Unlike the trust gate it paints with@@ -1184,6 +1214,7 @@ describe('createInputReadyTracker', () => {tracker.observe('', 'Do you trust the contents of this project?\n> Yes, I trust this folder\n');expect(tracker.needsTrust).toBe(true);expect(tracker.ready).toBe(false); // still not ready while the trust menu is up+ tracker.ackTrustChoice();tracker.observe('', '>\n? for shortcutsGemini 3.6 Flash · medium');expect(tracker.ready).toBe(true);diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 98c7002aed..daf0414693 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -1492,14 +1492,32 @@ export async function spawnTuiAgent({// first is what lets the composer appear at all.if (inputReady.needsTrust && inputReady.trustChoiceReady && !trustAccepted) {trustAccepted = true;- const trustInput = `${inputReady.trustNeedsSelectionAdvance ? '\x1b[B' : ''}${SUBMIT_KEY}`;+ const trustInput = `${inputReady.trustSelectionKey}${SUBMIT_KEY}`;shellService.writeToSession(sessionId, trustInput);+ inputReady.ackTrustChoice();lastOutputAt = now;firstOutputAt = null;appendLine(`📟 Auto-confirmed ${tuiConfig.command} folder-trust prompt for session ${sessionId.slice(0, 8)}`);return;}+ // A recognized trust heading with unknown choices is not an input prompt.+ // Never fall through to either positive-readiness or idle delivery and paste+ // the task into it. Fail explicitly at the provider's normal readiness cap+ // so a future wording change is diagnosable without accepting an unknown+ // highlighted default (which may be "No, exit").+ if (inputReady.needsTrust && !inputReady.trustChoiceReady) {+ const trustDeadlineMs = requireInputReady ? TUI_INPUT_READY_DEADLINE_MS : PASTE_DEADLINE_MS;+ if (elapsed >= trustDeadlineMs) {+ clearInterval(promptTimer);+ safeFinishStartupFailure(+ 'tui-trust-choice-unrecognized',+ `${tuiConfig.command} presented a folder-trust prompt whose affirmative choice PortOS could not identify, so no prompt was sent.`,+ );+ }+ return;+ }+if (requireInputReady) {// Decline claude's "make auto mode your default permission mode?" offer// (v2.1.233+). Unlike the trust gate this one paints AFTER the composer isdiff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.jsindex 48b3937e29..97a7cc7a30 100644--- a/server/services/tuiPromptRunner.js+++ b/server/services/tuiPromptRunner.js@@ -350,10 +350,8 @@ ${prompt}`;// retain their existing idle/deadline behavior.const inputReady = createInputReadyTracker({ directLaunch: true });const requiresInputReady = isClaudeCommand(command);- // needsTrust has no self-clearing latch in the tracker, so this flag is- // load-bearing to avoid re-sending Enter on every poll tick. needsAutoModeChoice- // doesn't need a matching flag below — ackAutoModeChoice() latches it false- // permanently on the tracker itself (see autoModeAnswered in tuiHandshake.js).+ // Keep local one-shot flags alongside the tracker's terminal acknowledgements+ // so a failed/delayed PTY write cannot cause repeated selector navigation.let trustAccepted = false;let hookReviewDeclined = false;@@ -882,12 +880,26 @@ ${prompt}`;// next option before submitting. `trustAccepted` keeps this to one input.if (inputReady.needsTrust && inputReady.trustChoiceReady && !trustAccepted) {trustAccepted = true;- const trustInput = `${inputReady.trustNeedsSelectionAdvance ? '\x1b[B' : ''}${SUBMIT_KEY}`;- dismissStartupDialog(trustInput, 'folder-trust prompt');+ const trustInput = `${inputReady.trustSelectionKey}${SUBMIT_KEY}`;+ if (dismissStartupDialog(trustInput, 'folder-trust prompt')) inputReady.ackTrustChoice();lastOutputAt = now;firstOutputAt = null;return;}+ if (inputReady.needsTrust && !inputReady.trustChoiceReady) {+ const trustDeadlineMs = requiresInputReady ? TUI_INPUT_READY_DEADLINE_MS : PASTE_DEADLINE_MS;+ if (elapsed >= trustDeadlineMs) {+ clearInterval(readyTimer);+ readyTimer = null;+ finish({+ success: false,+ exitCode: 1,+ error: `${command} presented a folder-trust prompt whose affirmative choice PortOS could not identify, so no prompt was sent.`,+ reason: 'tui-trust-choice-unrecognized',+ });+ }+ return;+ }if (requiresInputReady) {if (inputReady.needsAutoModeChoice) {// Select "No, keep don't ask" so a one-shot run never rewrites the