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 local review: count declines not nudges, keep the dialog tail through the cooldown, watch only claude sessions
[._.]/ Adam Eivyc7b77d5605e7
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex 9acc145105..c4de90663a 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -1080,12 +1080,13 @@ export function createSilenceNudgeGate({ cooldownMs, settleMs, armWindowMs, maxAreturn {inCooldown: (nowMs) => lastArmedAt !== null && nowMs - lastArmedAt < cooldownMs,arm(nowMs) {- if (lastArmedAt !== null && nowMs - lastArmedAt < cooldownMs) return null;- lastArmedAt = nowMs;// A sighting while a nudge is already pending is the same condition- // still on screen: it refreshes the cooldown (above) but never restarts- // the window, or a box that repaints forever would never expire it.+ // still on screen: it neither restarts the window (a box that repaints+ // forever must still expire it) nor refreshes the cooldown (or a repaint+ // outlasting the window could never re-arm once it stops).if (armedAt !== null) return null;+ if (lastArmedAt !== null && nowMs - lastArmedAt < cooldownMs) return null;+ lastArmedAt = nowMs;// Budget spent: this is a genuinely NEW sighting (it cleared the cooldown)// after the nudges already bought the run more than one recovery. Hand the// verdict back rather than arming a window nobody will act on.@@ -1239,8 +1240,9 @@ export const TOOL_PERMISSION_REPAINT_COOLDOWN_MS = 15000;// carry on. It rides the OOM nudge's silence policy (OOM_NUDGE_SETTLE_MS /// OOM_NUDGE_ARM_WINDOW_MS): sent only once the session has gone quiet, so a// build that instead hands the model a rejection and lets it continue is left-// alone. A model still reaching outside its scope after this many nudges is not-// going to finish inside it; the caller fails the run rather than looping.+// alone. A model still reaching outside its scope after this many DECLINES —+// whether or not each one needed a nudge — is not going to finish inside it;+// the caller fails the run rather than looping until the max-runtime ceiling.export const TOOL_PERMISSION_DECLINE_MAX = 8;export const TOOL_PERMISSION_NUDGE_TEXT = 'That tool call reached outside this run\'s allowed scope, so it was declined. Nobody is watching this session and no permission can be granted. Everything you need is inside your worktree and your prompt; continue using paths under the worktree only, and write the completion sentinel when you are done.';@@ -1249,10 +1251,14 @@ export const TOOL_PERMISSION_NUDGE_TEXT = 'That tool call reached outside this r* the dialog detector with a carry-over tail, on top of createSilenceNudgeGate.* Feed it every ANSI-stripped chunk after the prompt is in via* `observe(strippedText, nowMs)`: it returns the dialog to decline- * (`{ noOption, toolCall, count }`) exactly once per dialog, `'exhausted'` when- * the nudge budget is spent, or null. Poll `takeNudge(nowMs, lastOutputAtMs)`- * on the consumer's existing timer. The tail is dropped after a decline so the- * same dialog cannot be re-sighted from the carry-over.+ * (`{ noOption, toolCall, count }`) once per dialog, `'exhausted'` once+ * TOOL_PERMISSION_DECLINE_MAX dialogs have been declined, or null. Poll+ * `takeNudge(nowMs, lastOutputAtMs)` on the consumer's existing timer. The+ * tail is dropped after a decline so that dialog cannot be re-sighted from the+ * carry-over, but keeps accumulating through the repaint cooldown: a DIFFERENT+ * dialog painted seconds after a decline (the model's very next call is also+ * out of scope) must still be seen once the cooldown lifts, or the session+ * hangs on it exactly as it did before this gate existed.** @returns {{ observe: (strippedText: string, nowMs: number) => object|'exhausted'|null,* takeNudge: (nowMs: number, lastOutputAtMs: number) => number }}@@ -1262,19 +1268,26 @@ export function createToolPermissionGate() {cooldownMs: TOOL_PERMISSION_REPAINT_COOLDOWN_MS,settleMs: OOM_NUDGE_SETTLE_MS,armWindowMs: OOM_NUDGE_ARM_WINDOW_MS,- maxAttempts: TOOL_PERMISSION_DECLINE_MAX,+ // The budget is counted in declines (below), not nudges: a build that lets+ // the model continue after a rejection never goes quiet, so a nudge budget+ // would never be spent while the declines climbed forever.+ maxAttempts: Infinity,});let tail = '';let declines = 0;return {observe(strippedText, nowMs) {- if (typeof strippedText !== 'string' || !strippedText || nudge.inCooldown(nowMs)) return null;+ if (typeof strippedText !== 'string' || !strippedText) return null;tail = (tail + strippedText).slice(-1024);+ if (nudge.inCooldown(nowMs)) return null;const dialog = detectToolPermissionPrompt(tail);if (!dialog) return null;tail = '';- if (nudge.arm(nowMs) === 'exhausted') return 'exhausted';+ if (declines >= TOOL_PERMISSION_DECLINE_MAX) return 'exhausted';declines += 1;+ // A null here means a nudge is already pending from the previous decline;+ // it will fire on the same silence and covers this one too.+ nudge.arm(nowMs);return { ...dialog, count: declines };},takeNudge: nudge.takeNudge,diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex 2a489a5bf8..7eb8e54caf 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -1741,23 +1741,45 @@ describe('tool-permission dialog (agent-e057cca7)', () => {expect(gate.takeNudge(late + OOM_NUDGE_SETTLE_MS, late)).toBe(0);});- it('reports exhaustion once TOOL_PERMISSION_DECLINE_MAX nudges have been spent', () => {+ it('reports exhaustion after TOOL_PERMISSION_DECLINE_MAX declines, nudged or not', () => {+ // A build that hands the model a rejection and lets it continue never+ // goes quiet, so no nudge ever fires — the declines alone must cap it.const gate = createToolPermissionGate();let now = 0;for (let i = 1; i <= TOOL_PERMISSION_DECLINE_MAX; i += 1) {now += TOOL_PERMISSION_REPAINT_COOLDOWN_MS + 1;expect(gate.observe(READ_DIALOG, now)).toMatchObject({ count: i });- // The decline ends the turn, the session goes quiet, the nudge fires.- expect(gate.takeNudge(now + OOM_NUDGE_SETTLE_MS, now)).toBe(i);- now += OOM_NUDGE_SETTLE_MS;}now += TOOL_PERMISSION_REPAINT_COOLDOWN_MS + 1;expect(gate.observe(TWO_OPTION_DIALOG, now)).toBe('exhausted');});++ it('still sees a different dialog painted inside the repaint cooldown', () => {+ const gate = createToolPermissionGate();+ expect(gate.observe(READ_DIALOG, 0)).toMatchObject({ count: 1 });+ // The model's very next call is also out of scope: its dialog lands+ // seconds after the decline and is never repainted afterwards.+ expect(gate.observe(TWO_OPTION_DIALOG, 3000)).toBeNull();+ expect(gate.observe('\n', TOOL_PERMISSION_REPAINT_COOLDOWN_MS + 1000)).toMatchObject({ noOption: 2, count: 2 });+ });});});describe('createOomNudgeGate', () => {+ it('re-arms from a box that outlasted its window, once the repaint stops', () => {+ // The OOM box repaints past the arm window (the session never went quiet),+ // then finally does: the expired arm must be replaceable by a sighting+ // AFTER the cooldown, so a sighting while armed must not refresh it.+ const gate = createOomNudgeGate();+ const analysis = { message: 'oom' };+ expect(gate.arm(analysis, 0)).toBe('armed');+ expect(gate.arm(analysis, 60_000)).toBeNull();+ expect(gate.takeNudge(OOM_NUDGE_ARM_WINDOW_MS + 5_000, OOM_NUDGE_ARM_WINDOW_MS + 4_000)).toBe(0);+ expect(gate.arm(analysis, OOM_NUDGE_COOLDOWN_MS + 10_000)).toBe('armed');+ const quietAt = OOM_NUDGE_COOLDOWN_MS + 10_000;+ expect(gate.takeNudge(quietAt + OOM_NUDGE_SETTLE_MS, quietAt)).toBe(1);+ });+const analysis = { category: 'resource-exhausted', message: 'Local inference runtime ran out of GPU memory' };it('nudges only once the session has actually gone quiet', () => {diff --git a/server/services/agentErrorAnalysis.js b/server/services/agentErrorAnalysis.jsindex 7041951b2b..a8954bb9c8 100644--- a/server/services/agentErrorAnalysis.js+++ b/server/services/agentErrorAnalysis.js@@ -951,6 +951,16 @@ export const COMPLETION_REASON_ANALYSES = {message: 'Agent session was terminated by a signal',suggestedFix: 'The TUI session was killed rather than exiting on its own — usually a PortOS restart taking its child processes down. The task resumes from the preserved worktree; no agent-side fix is needed.'},+ // The TUI spawner declined TOOL_PERMISSION_DECLINE_MAX permission dialogs+ // (createToolPermissionGate) and the model was still reaching outside the+ // run's scope. Registered so the post-mortem does not fall through to the+ // transcript keyword sweep — which would scrape the dialog chrome itself.+ 'permission-prompt-loop': {+ category: 'timeout',+ actionable: false,+ message: 'Agent kept asking for tool permissions an unattended run cannot grant',+ suggestedFix: 'Every permission dialog was declined and the model kept reaching outside the run\'s allowed scope (paths outside the worktree, tools the posture forbids). A fallback provider retries the task; if it recurs, pin the stage to a stronger model or remove the outside-path references from its prompt.'+ },'command-not-found': {category: 'spawn-error',actionable: true,diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex 003138337b..10c3332d0f 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -145,8 +145,8 @@ function pipelineContextLines(pipelineCtx) {// sandboxed permission posture, is a tool-permission dialog nobody is// present to answer.lines.push(clipped- ? `The previous stage's output is inlined below, clipped to its first ${PREVIOUS_STAGE_OUTPUT_INLINE_CAP} characters.`- : "The previous stage's complete output is inlined below; there is nothing further to read from disk.");+ ? `The previous stage's hand-off is inlined below, clipped to its first ${PREVIOUS_STAGE_OUTPUT_INLINE_CAP} characters.`+ : "The previous stage's hand-off is inlined below in full; there is nothing further to read from disk.");} else {lines.push("Read the previous stage's output from:",diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 692f6df5ab..2435f90510 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -2332,7 +2332,7 @@ describe('buildLightContextPrompt', () => {stages: [{ name: 'scan' }, { name: 'gate' }, { name: 'review' }],}}}), '/r', null, isTruthyMeta);- expect(inlined).toMatch(/complete output is inlined below/);+ expect(inlined).toMatch(/hand-off is inlined below in full/);expect(inlined).not.toMatch(/output\.txt/);expect(inlined).toMatch(/"eligibleNumbers":\[6223\]/);diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 79c27ffadb..b7dfd66065 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -1435,7 +1435,14 @@ export async function spawnTuiAgent({// provider-signal timer, on its own poll, like the other gates.if (promptSubmittedAt) retryStallGate.observe(stripped, now);- const permissionDialog = promptSubmittedAt ? toolPermissionGate.observe(stripped, now) : null;+ // The permission dialog is Claude Code chrome. Watching another vendor's+ // session for it would only ever match an ECHO — a Codex or agy agent+ // investigating a stalled run cats its raw.txt straight into this stream+ // — and answer a dialog that is not there with keystrokes into a working+ // composer.+ const permissionDialog = promptSubmittedAt && isClaudeCommand(tuiConfig.command)+ ? toolPermissionGate.observe(stripped, now)+ : null;if (permissionDialog === 'exhausted') {await finish({success: false,diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex 2c5f4a74a2..67c37977a4 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -1825,7 +1825,21 @@ describe('spawnTuiAgent runtime', () => {// model asked to Read an absolute path outside the worktree, and the dialog// sat unanswered for the rest of the run.it('declines a tool-permission dialog and nudges the session once it goes quiet', async () => {- await driveAgyToSubmittedPrompt();+ // A claude session: the dialog is Claude Code chrome, and the spawner only+ // watches claude sessions for it.+ runSpawn({ tuiConfig: claudeTuiConfig });+ await flushMicrotasks();+ await capturedOnData(Buffer.from(`${PASTE_OFF}Claude Code v2.1.260\n`));+ await flushMicrotasks();+ await capturedOnData(Buffer.from(PASTE_ON));+ await flushMicrotasks();+ await vi.advanceTimersByTimeAsync(400);+ await flushMicrotasks();+ expect(pasteCount()).toBe(1);+ await capturedOnData(Buffer.from('do the thing\n'));+ await flushMicrotasks();+ await vi.advanceTimersByTimeAsync(4000);+ await flushMicrotasks();vi.mocked(shellService.writeToSession).mockClear();vi.mocked(shellService.pasteToSession).mockClear();