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: decline external Claude imports at startup
Adam Eivyffb8fc41f7f2
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex d293cab334..1a5c0887d5 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -306,6 +306,17 @@ export const TUI_TRUST_PROMPT_PATTERN =export const TUI_AUTO_MODE_PROMPT_PATTERN =/automodeyourdefaultpermissionmode|setautomodeasmydefaultpermissionmode/i;+// Claude Code can discover a parent workspace's CLAUDE.md when PortOS places a+// managed-app worktree below its own data/cos/worktrees directory. If that file+// imports an instruction file outside the managed app's checkout, Claude stops+// on an "allow external imports" selector before its composer exists. Importing+// the parent repository's instructions would cross the managed-app boundary, so+// unattended runs choose "No, disable external imports". Without recognizing+// this gate, the normal task paste is swallowed and the agent never starts.+// Match the stable heading and choice wording after whitespace stripping.+export const TUI_EXTERNAL_IMPORTS_PROMPT_PATTERN =+ /claude\.mdimportsfilesoutsidethecurrentworkingdirectory|disableexternalimports/i;+// Codex can stop before its composer on a hook-review selector when a newly// configured hook has not yet been trusted. `--dangerously-bypass-approvals-and-// sandbox` deliberately does not answer this prompt: trusting a hook permits@@ -364,6 +375,11 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunch// false until the 45s deadline. Arm-once, same as the gates above it.let needsAutoModeChoice = false;let autoModeAnswered = false;+ // External-import selector: latched until the consumer sends the conservative+ // "disable" choice, then terminally acknowledged so its stale screen text+ // cannot re-arm the gate from the rolling tail.+ let needsExternalImportsChoice = false;+ let externalImportsAnswered = false;// Like the auto-mode offer, hook-review text remains in the rolling tail// after its selector closes. A terminal acknowledgement prevents a repaint// from re-arming the dialog and blocking delivery forever.@@ -386,14 +402,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 && !needsHookReview+ return sawCommandRun && pasteModeOn && !needsAutoModeChoice+ && !needsExternalImportsChoice && !needsHookReview&& (!readyTextPattern || sawReadyText);},get needsTrust() { return needsTrust; },get needsAutoModeChoice() { return needsAutoModeChoice; },+ get needsExternalImportsChoice() { return needsExternalImportsChoice; },get needsHookReview() { return needsHookReview; },/** Spawner reports the dismissal keystrokes went out; re-arms `ready`. */ackAutoModeChoice() { needsAutoModeChoice = false; autoModeAnswered = true; },+ /** Spawner selected Claude's "No, disable external imports" option. */+ ackExternalImportsChoice() { needsExternalImportsChoice = false; externalImportsAnswered = true; },/** Spawner selected Codex's safe "Continue without trusting" option. */ackHookReview() { needsHookReview = false; hookReviewAnswered = true; },// rawText: un-stripped chunk (paste-mode toggles live here);@@ -416,6 +436,9 @@ export function createInputReadyTracker({ readyTextPattern = null, directLaunchtail = (tail + strippedText.replace(/\s+/g, '')).slice(-OBSERVE_TAIL_MAX_LEN);if (!needsTrust && TUI_TRUST_PROMPT_PATTERN.test(tail)) needsTrust = true;if (!needsAutoModeChoice && !autoModeAnswered && TUI_AUTO_MODE_PROMPT_PATTERN.test(tail)) needsAutoModeChoice = true;+ if (!needsExternalImportsChoice && !externalImportsAnswered && TUI_EXTERNAL_IMPORTS_PROMPT_PATTERN.test(tail)) {+ needsExternalImportsChoice = true;+ }if (!needsHookReview && !hookReviewAnswered && TUI_HOOK_REVIEW_PROMPT_PATTERN.test(tail)) needsHookReview = true;if (readyTextPattern && !sawReadyText && readyTextPattern.test(tail)) sawReadyText = true;}diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex 3f4c46a031..bcf67dc97e 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -1101,6 +1101,30 @@ describe('createInputReadyTracker', () => {});});+ describe('Claude external-imports offer', () => {+ const OFFER = "This project's CLAUDE.md imports files outside the current working directory.\n"+ + 'Never allow this for third-party repositories.\n'+ + 'External imports:\n'+ + ' /workspace-parent/AGENTS.md\n'+ + '1. Yes, allow external imports\n'+ + '2. No, disable external imports\n';++ it('suppresses ready and does not re-arm after external imports are disabled', () => {+ const tracker = createInputReadyTracker();+ tracker.observe(`${PASTE_OFF}${PASTE_ON}`, OFFER);+ expect(tracker.needsExternalImportsChoice).toBe(true);+ expect(tracker.ready).toBe(false);++ tracker.ackExternalImportsChoice();+ expect(tracker.needsExternalImportsChoice).toBe(false);+ expect(tracker.ready).toBe(true);++ tracker.observe('', 'Claude ready'); // rolling tail still contains the offer+ expect(tracker.needsExternalImportsChoice).toBe(false);+ expect(tracker.ready).toBe(true);+ });+ });+describe('Codex hook-review offer', () => {const OFFER = 'Hooks need review\n'+ '1 hook is new or changed.\n'diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 079b328a31..fb3edb1f65 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -635,6 +635,7 @@ export async function spawnTuiAgent({});let trustAccepted = false;let autoModeDeclined = false;+ let externalImportsDeclined = false;let hookReviewDeclined = false;// True once shell.js actually injects the `claude` command (after its// round-trip readiness probe). The probe runs its OWN shell command first,@@ -1443,6 +1444,22 @@ export async function spawnTuiAgent({// the dismissal reveals; if the TUI ignores the keystroke entirely,// PASTE_DEADLINE_MS still backstops delivery.+ // Claude can discover PortOS's parent CLAUDE.md from a managed-app worktree+ // nested under data/cos/worktrees, then ask whether to allow that file's+ // external AGENTS.md import. Decline it: the parent repository's instructions+ // must not leak into the target app, and option 2 leaves the target's own+ // instruction files intact. Like the auto-mode offer, arrow-down + Enter+ // avoids accepting the highlighted option 1.+ if (inputReady.needsExternalImportsChoice && !externalImportsDeclined) {+ externalImportsDeclined = true;+ shellService.writeToSession(sessionId, '\x1b[B\r');+ inputReady.ackExternalImportsChoice();+ lastOutputAt = now;+ firstOutputAt = null;+ appendLine(`📟 Declined ${tuiConfig.command} external instruction imports for session ${sessionId.slice(0, 8)}`);+ return;+ }+// 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 codediff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex 19f32f5720..34c8273e17 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -1110,6 +1110,36 @@ describe('spawnTuiAgent runtime', () => {expect(pasteCount()).toBe(1);});+ it('claude external-imports offer: disables parent imports before pasting the prompt', async () => {+ runSpawn({ tuiConfig: claudeTuiConfig });+ await flushMicrotasks();++ await capturedOnData(Buffer.from(+ `${PASTE_OFF}This project's CLAUDE.md imports files outside the current working directory.\n`+ + 'Never allow this for third-party repositories.\n'+ + 'External imports:\n'+ + ' /workspace-parent/AGENTS.md\n'+ + '❯ 1. Yes, allow external imports\n'+ + '2. No, disable external imports\n',+ ));+ await flushMicrotasks();+ await vi.advanceTimersByTimeAsync(700);+ await flushMicrotasks();++ // Down+Enter takes the conservative option 2. A bare Enter would import+ // instructions from PortOS's parent workspace into the managed app.+ const writes = vi.mocked(shellService.writeToSession).mock.calls.map(([, data]) => data);+ expect(writes).toContain('\x1b[B\r');+ expect(writes).not.toContain('\r');+ expect(pasteCount()).toBe(0);++ await capturedOnData(Buffer.from(PASTE_ON));+ await flushMicrotasks();+ await vi.advanceTimersByTimeAsync(400);+ await flushMicrotasks();+ expect(pasteCount()).toBe(1);+ });+it('codex hook-review offer: continues without trusting hooks before pasting the prompt', async () => {runSpawn();await flushMicrotasks();diff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.jsindex 9172d085bc..f87dffd4cf 100644--- a/server/services/tuiPromptRunner.js+++ b/server/services/tuiPromptRunner.js@@ -776,10 +776,11 @@ ${prompt}`;}};- // 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.+ // Ready watch — known startup dialogs (folder trust, external imports,+ // 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);@@ -796,6 +797,19 @@ ${prompt}`;// keystroke makes delivery wait for what the dismissal reveals;// PASTE_DEADLINE_MS still backstops a dismissal the TUI ignores entirely.+ // A managed-app worktree nested below PortOS can make Claude discover the+ // parent PortOS CLAUDE.md and offer to import its external AGENTS.md.+ // Decline option 1 rather than crossing that repository boundary. The+ // target checkout's own instructions remain available after option 2.+ if (inputReady.needsExternalImportsChoice) {+ if (dismissStartupDialog('\x1b[B\r', 'external-imports prompt')) {+ inputReady.ackExternalImportsChoice();+ }+ lastOutputAt = now;+ firstOutputAt = null;+ return;+ }+// 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 ordinarydiff --git a/server/services/tuiPromptRunner.test.js b/server/services/tuiPromptRunner.test.jsindex 69d439f730..1a7629d013 100644--- a/server/services/tuiPromptRunner.test.js+++ b/server/services/tuiPromptRunner.test.js@@ -568,6 +568,41 @@ describe('executeTuiRun', () => {await promise;});+ it('disables Claude external imports before waiting for input readiness', 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-external-imports', provider, prompt: 'return one structured response',+ workspacePath: TEST_WORKSPACE, timeout: 60000,+ });+ await flushAsync();++ const pty = ptyInstances[0];+ pty.emitData(+ "This project's CLAUDE.md imports files outside the current working directory.\n"+ + 'Never allow this for third-party repositories.\n'+ + 'External imports:\n'+ + ' /workspace-parent/AGENTS.md\n'+ + '1. Yes, allow external imports\n'+ + '2. No, disable external imports\n',+ );+ await vi.advanceTimersByTimeAsync(400);++ expect(pty.write).toHaveBeenCalledWith('\x1b[B\r');+ expect(pty.write).not.toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));++ // The dialog precedes Claude's composer. Paste only after Claude paints+ // the input box and enables bracketed-paste mode.+ pty.emitData('\x1b[?2004h');+ await vi.advanceTimersByTimeAsync(400);+ expect(pty.write).toHaveBeenCalledWith(expect.stringContaining('\x1b[200~'));++ pty.emitExit({ exitCode: 0 });+ await promise;+ });+it('confirms the Codex directory-trust gate before its idle path can paste', async () => {vi.useFakeTimers({toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],