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
simplify the TUI recovery gates and the lens placeholder after review
[._.]/ Adam Eivy064eddd19482
diff --git a/server/lib/cliChildEnv.js b/server/lib/cliChildEnv.jsindex b37ad0b45f..7a37dcabe7 100644--- a/server/lib/cliChildEnv.js+++ b/server/lib/cliChildEnv.js@@ -85,17 +85,12 @@ const CLAUDE_LOCAL_MAX_OUTPUT_TOKENS = '65536';// • the stream idle timeout — 300s; `CLAUDE_STREAM_IDLE_TIMEOUT_MS`, floor// 300s, likewise clamped to 30 minutes.//-// All four are widened for a Claude harness pointed at a LOCAL daemon: the-// two idle knobs at Claude Code's own 30-minute ceiling (a local model can go-// quiet mid-turn while a tool-heavy conversation re-prefills its uncached-// tail), the first-byte window at an hour. The ceilings exist to bound a retry-// storm, not to budget a healthy run: a request that never answers still ends,-// because the child prints nothing and the run's own supervision reaps it —-// and `createRetryStallGate` (tuiHandshake.js) fails a TUI over once a retry-// ladder outlives its window. `localPromptBudget.js` predicts the prefill for-// the run card; this is the harness half of the same fact. Cloud Claude-// answers in seconds and keeps every stock value. A value in provider.envVars-// still wins below.+// All four are widened for a Claude harness pointed at a LOCAL daemon — the+// idle knobs at Claude Code's own 30-minute ceiling, the first-byte window at+// an hour. A request that never answers still ends: `createRetryStallGate`+// (tuiHandshake.js) fails a TUI over once its retry ladder outlives the window,+// and the run's own supervision reaps a silent child. Cloud Claude keeps every+// stock value.const CLAUDE_LOCAL_API_TIMEOUT_MS = '3600000';const CLAUDE_LOCAL_FORCE_IDLE_TIMEOUT = '0';const CLAUDE_LOCAL_STREAM_IDLE_TIMEOUT_MS = '1800000';diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex acefd1dd95..9acc145105 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -1046,30 +1046,58 @@ export const OOM_NUDGE_TEXT = 'continue';* takeNudge: (nowMs: number, lastOutputAtMs: number) => number }}*/export function createOomNudgeGate() {- let armed = null; // { analysis, armedAt }+ const gate = createSilenceNudgeGate({+ cooldownMs: OOM_NUDGE_COOLDOWN_MS,+ settleMs: OOM_NUDGE_SETTLE_MS,+ armWindowMs: OOM_NUDGE_ARM_WINDOW_MS,+ maxAttempts: OOM_NUDGE_MAX_ATTEMPTS,+ });+ return {+ arm: (analysis, nowMs) => (analysis ? gate.arm(nowMs) : null),+ takeNudge: gate.takeNudge,+ };+}++/**+ * The "wait for silence, then nudge" policy the OOM gate and the+ * tool-permission gate share: dedupe sightings inside `cooldownMs` (a TUI+ * repaints an error box for many chunks), fire once the session has been quiet+ * for `settleMs`, drop an arm the session outran (`armWindowMs` — it recovered+ * on its own), and report `'exhausted'` once `maxAttempts` nudges have already+ * been spent on a condition that keeps coming back.+ *+ * `arm(nowMs)` returns `'armed'`, `'exhausted'`, or null for a sighting inside+ * the cooldown or while a nudge is already pending. `inCooldown(nowMs)` lets a consumer skip its detector while a+ * just-handled sighting is still repainting. `takeNudge(nowMs, lastOutputAtMs)`+ * returns the 1-based nudge number when one is due, or 0 — disarming either+ * way, on a nudge because it fired and on an expired window because the+ * session never went quiet.+ */+export function createSilenceNudgeGate({ cooldownMs, settleMs, armWindowMs, maxAttempts }) {+ let armedAt = null;let lastArmedAt = null;let attempts = 0;return {- arm(analysis, nowMs) {- if (!analysis || armed) return null;- if (lastArmedAt !== null && nowMs - lastArmedAt < OOM_NUDGE_COOLDOWN_MS) return null;+ inCooldown: (nowMs) => lastArmedAt !== null && nowMs - lastArmedAt < cooldownMs,+ arm(nowMs) {+ if (lastArmedAt !== null && nowMs - lastArmedAt < cooldownMs) return null;lastArmedAt = nowMs;- // Budget spent: this is a genuinely NEW OOM (it cleared the cooldown)+ // 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.+ if (armedAt !== null) return null;+ // 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.- if (attempts >= OOM_NUDGE_MAX_ATTEMPTS) return 'exhausted';- armed = { analysis, armedAt: nowMs };+ if (attempts >= maxAttempts) return 'exhausted';+ armedAt = nowMs;return 'armed';},- // Returns the 1-based attempt number when the session has been quiet long- // enough to nudge, or 0. Disarms either way — on a nudge because it fired,- // and on an expired window because the session never went quiet, which is- // itself evidence it recovered without help.takeNudge(nowMs, lastOutputAtMs) {- if (!armed) return 0;- if (nowMs - armed.armedAt > OOM_NUDGE_ARM_WINDOW_MS) { armed = null; return 0; }- if (nowMs - lastOutputAtMs < OOM_NUDGE_SETTLE_MS) return 0;- armed = null;+ if (armedAt === null) return 0;+ if (nowMs - armedAt > armWindowMs) { armedAt = null; return 0; }+ if (nowMs - lastOutputAtMs < settleMs) return 0;+ armedAt = null;attempts += 1;return attempts;},@@ -1096,8 +1124,8 @@ const RETRY_STALL_CARRY_CAP = 96;/*** State machine for "the TUI keeps retrying the same request and it never- * answers" — see TUI_RETRY_BANNER_PATTERN in aiToolkit/errorDetection.js for- * the 2026-09-04 incident it exists for.+ * answers" — the incident is told once, on TUI_RETRY_BANNER_PATTERN in+ * aiToolkit/errorDetection.js.** Feed it every ANSI-stripped chunk after the prompt is in via* `observe(strippedText, nowMs)`; poll `takeStall(nowMs)` on whatever timer the@@ -1168,17 +1196,20 @@ export function createRetryStallGate() {// pre-approved — under the hardened public-review recipe (`--permission-mode// acceptEdits` + sandbox) that is any read or write outside the worktree, which// a local model reaches for the moment it hallucinates an absolute path-// (agent-e057cca7, 2026-09-04: `Read(/data.reference/providers.json)` sat-// unanswered for 30+ minutes while the spinner kept the idle reaper happy).-// Nobody is at the keyboard, and the posture already decided the answer: an-// unattended run never widens its own scope, so the dialog is DECLINED. "No" is-// always the last numbered option, but its number varies with the tool (a-// two-option dialog for some, three for most), so it is read off the screen.+// (agent-e057cca7, 2026-09-04, sat on one for 30+ minutes while the spinner kept+// the idle reaper happy). Nobody is at the keyboard, and the posture already+// decided the answer: an unattended run never widens its own scope, so the+// dialog is DECLINED. "No" is always the last numbered option, but its number+// varies with the tool (two options for some, three for most), so it is read+// off the screen. The question pattern is shared with the post-mortem+// analyzer's AWAITING_INPUT_MARKERS so live and after-the-fact detection cannot+// drift apart.export const TUI_TOOL_PERMISSION_PROMPT_PATTERN = /do\s*you\s*want\s*to\s*proceed\?/i;const TUI_TOOL_PERMISSION_NO_OPTION_PATTERN = /(\d+)\.\s*No\b/i;const TUI_TOOL_PERMISSION_CALL_PATTERN = /([A-Z][A-Za-z]*\([^\n]{0,300}?\))\s*do\s*you\s*want\s*to\s*proceed\?/i;-// How much screen after the question the option list may span before it is-// judged not painted yet.+// Screen around the question: how far back the tool-call header may sit, and+// how far ahead the option list may span before it is judged not painted yet.+const TUI_TOOL_PERMISSION_CALL_LEAD = 400;const TUI_TOOL_PERMISSION_OPTIONS_SPAN = 600;/**@@ -1195,7 +1226,7 @@ export function detectToolPermissionPrompt(strippedText) {const options = strippedText.slice(question.index, question.index + TUI_TOOL_PERMISSION_OPTIONS_SPAN);const no = TUI_TOOL_PERMISSION_NO_OPTION_PATTERN.exec(options);if (!no) return null;- const lead = strippedText.slice(Math.max(0, question.index - 400), question.index + question[0].length);+ const lead = strippedText.slice(Math.max(0, question.index - TUI_TOOL_PERMISSION_CALL_LEAD), question.index + question[0].length);const call = TUI_TOOL_PERMISSION_CALL_PATTERN.exec(lead);return { noOption: Number(no[1]), toolCall: call ? call[1].replace(/\s+/g, ' ') : null };}@@ -1205,61 +1236,47 @@ export function detectToolPermissionPrompt(strippedText) {export const TOOL_PERMISSION_REPAINT_COOLDOWN_MS = 15000;// Declining a tool call ends the assistant turn in current Claude Code builds// ("What should Claude do instead?"), so the session then needs a message to-// carry on. Sent once the session has been SILENT this long after a decline —-// the same provider-agnostic silence test the OOM nudge uses — so a build that-// instead hands the model a rejection and lets it continue is left alone.-export const TOOL_PERMISSION_NUDGE_SETTLE_MS = 25000;-// A decline whose session never went quiet inside this window continued on its-// own; drop the pending nudge rather than fire it into a later quiet stretch.-export const TOOL_PERMISSION_NUDGE_ARM_WINDOW_MS = 120000;-// A model that keeps reaching outside its scope after this many declines is not+// 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.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.';/**- * State machine for "decline every tool-permission dialog, then get the- * session moving again". Feed it every ANSI-stripped chunk after the prompt is- * in via `observe(strippedText, nowMs)`: it returns the dialog to decline+ * "Decline every tool-permission dialog, then get the session moving again":+ * 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 decline budget is spent, or null. Poll `takeNudge(nowMs, lastOutputAtMs)`- * on the consumer's existing timer; it returns the decline number a nudge is- * due for, or 0.- *- * Carries a screen tail across chunks so a dialog split by a PTY chunk- * boundary still matches; the tail is dropped after a decline so the same- * dialog cannot be re-sighted from the carry-over.+ * 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.** @returns {{ observe: (strippedText: string, nowMs: number) => object|'exhausted'|null,* takeNudge: (nowMs: number, lastOutputAtMs: number) => number }}*/export function createToolPermissionGate() {+ const nudge = createSilenceNudgeGate({+ cooldownMs: TOOL_PERMISSION_REPAINT_COOLDOWN_MS,+ settleMs: OOM_NUDGE_SETTLE_MS,+ armWindowMs: OOM_NUDGE_ARM_WINDOW_MS,+ maxAttempts: TOOL_PERMISSION_DECLINE_MAX,+ });let tail = '';let declines = 0;- let lastDeclineAt = null;- let pendingNudge = null; // { declinedAt, count }return {observe(strippedText, nowMs) {- if (typeof strippedText !== 'string' || !strippedText) return null;- const window = (tail + strippedText).slice(-1024);- tail = window;- if (lastDeclineAt !== null && nowMs - lastDeclineAt < TOOL_PERMISSION_REPAINT_COOLDOWN_MS) return null;- const dialog = detectToolPermissionPrompt(window);+ if (typeof strippedText !== 'string' || !strippedText || nudge.inCooldown(nowMs)) return null;+ tail = (tail + strippedText).slice(-1024);+ const dialog = detectToolPermissionPrompt(tail);if (!dialog) return null;tail = '';- lastDeclineAt = nowMs;- if (declines >= TOOL_PERMISSION_DECLINE_MAX) return 'exhausted';+ if (nudge.arm(nowMs) === 'exhausted') return 'exhausted';declines += 1;- pendingNudge = { declinedAt: nowMs, count: declines };return { ...dialog, count: declines };},- takeNudge(nowMs, lastOutputAtMs) {- if (!pendingNudge) return 0;- if (nowMs - pendingNudge.declinedAt > TOOL_PERMISSION_NUDGE_ARM_WINDOW_MS) { pendingNudge = null; return 0; }- if (nowMs - lastOutputAtMs < TOOL_PERMISSION_NUDGE_SETTLE_MS) return 0;- const { count } = pendingNudge;- pendingNudge = null;- return count;- },+ takeNudge: nudge.takeNudge,};}diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex f891c45fcb..2a489a5bf8 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -50,8 +50,6 @@ import {detectToolPermissionPrompt,createToolPermissionGate,TOOL_PERMISSION_REPAINT_COOLDOWN_MS,- TOOL_PERMISSION_NUDGE_SETTLE_MS,- TOOL_PERMISSION_NUDGE_ARM_WINDOW_MS,TOOL_PERMISSION_DECLINE_MAX,TOOL_PERMISSION_NUDGE_TEXT,} from './tuiHandshake.js';@@ -1729,8 +1727,8 @@ describe('tool-permission dialog (agent-e057cca7)', () => {expect(gate.takeNudge(5000, 4000)).toBe(0);// Quiet for the settle window: nudge, exactly once.const quietAt = 5000;- expect(gate.takeNudge(quietAt + TOOL_PERMISSION_NUDGE_SETTLE_MS, quietAt)).toBe(1);- expect(gate.takeNudge(quietAt + TOOL_PERMISSION_NUDGE_SETTLE_MS + 5000, quietAt)).toBe(0);+ expect(gate.takeNudge(quietAt + OOM_NUDGE_SETTLE_MS, quietAt)).toBe(1);+ expect(gate.takeNudge(quietAt + OOM_NUDGE_SETTLE_MS + 5000, quietAt)).toBe(0);});it('drops the nudge when the session carried on by itself', () => {@@ -1738,17 +1736,20 @@ describe('tool-permission dialog (agent-e057cca7)', () => {gate.observe(READ_DIALOG, 0);// Output never stops for the whole arm window — the build handed the model// a rejection and it kept working — so a later quiet stretch gets no nudge.- const late = TOOL_PERMISSION_NUDGE_ARM_WINDOW_MS + 1000;+ const late = OOM_NUDGE_ARM_WINDOW_MS + 1000;expect(gate.takeNudge(late, late - 100)).toBe(0);- expect(gate.takeNudge(late + TOOL_PERMISSION_NUDGE_SETTLE_MS, late)).toBe(0);+ expect(gate.takeNudge(late + OOM_NUDGE_SETTLE_MS, late)).toBe(0);});- it('reports exhaustion after TOOL_PERMISSION_DECLINE_MAX distinct dialogs', () => {+ it('reports exhaustion once TOOL_PERMISSION_DECLINE_MAX nudges have been spent', () => {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');diff --git a/server/services/agentErrorAnalysis.js b/server/services/agentErrorAnalysis.jsindex 99cabd0ba8..7041951b2b 100644--- a/server/services/agentErrorAnalysis.js+++ b/server/services/agentErrorAnalysis.js@@ -13,6 +13,7 @@ import { redactOutput } from '../lib/commandSecurity.js';import { stripAnsi } from '../lib/ansiStrip.js';import { describeOllamaContextOverflow, parseOllamaContextOverflow } from '../lib/ollamaContext.js';import { retryHoldMetadata } from '../lib/taskRetryHold.js';+import { TUI_TOOL_PERMISSION_PROMPT_PATTERN } from '../lib/tuiHandshake.js';import {INVESTIGATION_CIRCUIT_MAX_CREATIONS,INVESTIGATION_HEADLINE_PREFIX,@@ -1015,7 +1016,9 @@ export const AWAITING_INPUT_MARKERS = [/Enter to select/i,/↑\/↓ to navigate/,/❯\s*1\./,- /Do you want to proceed\?/i,+ // Claude Code's tool-permission dialog — the live gate that declines it+ // (createToolPermissionGate) reads the same pattern.+ TUI_TOOL_PERMISSION_PROMPT_PATTERN,/Press Enter to continue/i];diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex 5224875a65..003138337b 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -122,6 +122,8 @@ function resolveSentinelPath(worktreeInfo, workspaceDir, agentId) {return `${worktreeInfo?.worktreePath || workspaceDir}/${doneSentinelName(agentId)}`;}+const PREVIOUS_STAGE_OUTPUT_INLINE_CAP = 12_000;+function pipelineContextLines(pipelineCtx) {if (!pipelineCtx || (!pipelineCtx.previousStageAgentId && !pipelineCtx.previousStageOutput)) return [];@@ -133,15 +135,18 @@ function pipelineContextLines(pipelineCtx) {const rawPreviousOutput = typeof pipelineCtx.previousStageOutput === 'string'? pipelineCtx.previousStageOutput.trim(): '';- const previousOutput = rawPreviousOutput.slice(0, 12_000).replace(/~+/g, "'");- const truncated = rawPreviousOutput.length > previousOutput.length;+ const clipped = rawPreviousOutput.length > PREVIOUS_STAGE_OUTPUT_INLINE_CAP;+ const previousOutput = rawPreviousOutput.slice(0, PREVIOUS_STAGE_OUTPUT_INLINE_CAP).replace(/~+/g, "'");if (!pipelineCtx.previousStageAgentId) {lines.push('The previous stage completed as a direct preflight; its summary is included below.');- } else if (previousOutput && !truncated) {- // The whole output is inlined below, so the file pointer would only send- // the agent OUTSIDE its worktree — which, under a sandboxed permission- // posture, is a tool-permission dialog nobody is present to answer.- lines.push("The previous stage's complete output is inlined below; there is nothing further to read from disk.");+ } else if (previousOutput) {+ // A producer that hands over the output chose the inline hand-off; the file+ // pointer would only send the agent OUTSIDE its worktree — which, under a+ // 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.");} else {lines.push("Read the previous stage's output from:",diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 3cd40239aa..692f6df5ab 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -2336,7 +2336,7 @@ describe('buildLightContextPrompt', () => {expect(inlined).not.toMatch(/output\.txt/);expect(inlined).toMatch(/"eligibleNumbers":\[6223\]/);- // A clipped inline still needs the pointer: the rest is only on disk.+ // A clipped inline says so, and still never points outside the worktree.const clipped = buildLightContextPrompt(makeTask({metadata: { pipeline: {previousStageAgentId: 'agent-prev-1',@@ -2345,7 +2345,8 @@ describe('buildLightContextPrompt', () => {stages: [{ name: 'scan' }, { name: 'gate' }, { name: 'review' }],}}}), '/r', null, isTruthyMeta);- expect(clipped).toMatch(/agent-prev-1[\\/]output\.txt/);+ expect(clipped).toMatch(/clipped to its first 12000 characters/);+ expect(clipped).not.toMatch(/output\.txt/);});it('renders a direct preflight summary when the previous stage has no agent', () => {diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 640becf255..79c27ffadb 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -1449,7 +1449,7 @@ export async function spawnTuiAgent({// "No" is the last option and option 1 is highlighted: arrow down to it,// then Enter — lands under both of Ink's selection models, whereas a bare// digit is immediate-select in some builds and ignored in others.- shellService.writeToSession(sessionId, `${'\x1b[B'.repeat(Math.max(0, permissionDialog.noOption - 1))}\r`);+ shellService.writeToSession(sessionId, `${'\x1b[B'.repeat(Math.max(0, permissionDialog.noOption - 1))}${SUBMIT_KEY}`);appendLine(`🚫 Declined ${tuiConfig.command} permission prompt for ${permissionDialog.toolCall || 'a tool call'} — an unattended run never widens its scope (${permissionDialog.count}/${TOOL_PERMISSION_DECLINE_MAX})`);}diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex c317adadc1..2c5f4a74a2 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -252,7 +252,6 @@ import {OOM_NUDGE_MAX_ATTEMPTS,OOM_NUDGE_TEXT,RETRY_STALL_MS,- TOOL_PERMISSION_NUDGE_SETTLE_MS,TOOL_PERMISSION_NUDGE_TEXT,} from '../lib/tuiHandshake.js';// Real module, not a mock: the flag is a plain process-local boolean, so driving@@ -1836,7 +1835,7 @@ describe('spawnTuiAgent runtime', () => {expect(shellService.writeToSession).toHaveBeenCalledWith(SESSION_ID, '\x1b[B\x1b[B\r');// The decline ends the turn; once the session is quiet the nudge goes out.- await vi.advanceTimersByTimeAsync(TOOL_PERMISSION_NUDGE_SETTLE_MS + 10000);+ await vi.advanceTimersByTimeAsync(OOM_NUDGE_SETTLE_MS + 10000);await flushMicrotasks();expect(shellService.pasteToSession).toHaveBeenCalledWith(SESSION_ID,diff --git a/server/services/taskPromptDefaults/integrity.snapshot.json b/server/services/taskPromptDefaults/integrity.snapshot.jsonindex 83e7575e56..597c173be1 100644--- a/server/services/taskPromptDefaults/integrity.snapshot.json+++ b/server/services/taskPromptDefaults/integrity.snapshot.json@@ -29,7 +29,7 @@"plan-task": "b85fe92999aa4ee4a8910320457c4242","pr-reviewer": "679680b3b382aeb6786df01c4d1a90c6","pr-reviewer-eligibility": "a5652f7bcb7e2e50b1cfb9a54a6fabe0",- "pr-reviewer-review": "f1dbfcf76971b30b4ee34b2cde73c40c",+ "pr-reviewer-review": "69fcafcda48279fe325d34f8cef4668c","pr-reviewer-security": "d1e99626b12939ee39ab38eaa7d23f59","pr-watcher": "53ead8e26d396849bfa78f28550bd691","react-lifecycle": "14b3816d1bcc10f0d7d6357e55cc5e69",diff --git a/server/services/taskPromptDefaults/prompts.js b/server/services/taskPromptDefaults/prompts.jsindex 3ea7ac9aad..6b1006ff0f 100644--- a/server/services/taskPromptDefaults/prompts.js+++ b/server/services/taskPromptDefaults/prompts.js@@ -2501,7 +2501,7 @@ not sufficient.## Review checklist-{reviewChecklist}`,+{reviewLenses}`,'reference-watch': `[Improvement: {appName}] Reference Repo Reviewdiff --git a/server/services/taskPromptService.js b/server/services/taskPromptService.jsindex 0b0bcd1240..e0a7cfd5c0 100644--- a/server/services/taskPromptService.js+++ b/server/services/taskPromptService.js@@ -75,8 +75,10 @@ async function loadSlashdoCommandBody(commandName) {/*** The slashdo review LENSES — the per-file / cross-file checklists that- * `/do:review` dispatches its focused reviewers with. This is the whole of- * `{reviewChecklist}` for the public-review actions stage (`pr-reviewer-review`).+ * `/do:review` dispatches its focused reviewers with — behind the+ * `{reviewLenses}` placeholder the public-review actions stage+ * (`pr-reviewer-review`) carries. `review-structural-ambition` is left out on+ * purpose: `/do:review` itself only selects it under `--strict`.** That stage runs a single sandboxed agent with no network, no forge* credential, no sub-agent dispatch, and — on the local wrappers it is@@ -98,9 +100,7 @@ const PUBLIC_REVIEW_LENS_LIBS = ['review-cross-file-tracing','review-cross-file-contract',];-const LENS_ONLY_CHECKLIST_PROMPT_KEYS = new Set(['pr-reviewer-review']);--async function loadPublicReviewChecklist() {+async function loadReviewLenses() {const lenses = await Promise.all(PUBLIC_REVIEW_LENS_LIBS.map((name) => loadSlashdoLib(name).catch(() => null)));return lenses.filter(Boolean).join('\n\n');}@@ -115,12 +115,8 @@ async function loadPublicReviewChecklist() {* BEFORE THE PLACEHOLDER back into the prompt at that point — seven copies of* the stage prompt inside one Stage 3 body, the same footgun* `resolveSlashdoIncludes` documents for its own includes.- *- * `promptKey` names the catalog entry being rendered (a pipeline stage's- * `promptKey`; absent for a task-level prompt) so a placeholder can resolve- * differently for a stage whose runtime cannot use the general body.*/-async function resolvePromptPlaceholders(prompt, { promptKey = null } = {}) {+async function resolvePromptPlaceholders(prompt) {// {worktreesRoot} → PortOS's shared worktrees dir (absolute). The claim flows// (plan-task, claim-issue, claim-issue-gitlab, claim-issue-jira) create their// agent worktree here rather than inside the managed app repo, so a worktree@@ -129,11 +125,13 @@ async function resolvePromptPlaceholders(prompt, { promptKey = null } = {}) {prompt = prompt.replace(/\{worktreesRoot\}/g, () => PATHS.worktrees);}if (prompt.includes('{reviewChecklist}')) {- const checklist = LENS_ONLY_CHECKLIST_PROMPT_KEYS.has(promptKey)- ? await loadPublicReviewChecklist()- : await loadSlashdoCommandBody('review').catch(() => '');+ const checklist = await loadSlashdoCommandBody('review').catch(() => '');prompt = prompt.replace(/\{reviewChecklist\}/g, () => checklist);}+ if (prompt.includes('{reviewLenses}')) {+ const lenses = await loadReviewLenses();+ prompt = prompt.replace(/\{reviewLenses\}/g, () => lenses);+ }if (prompt.includes('{slashdoReplan}')) {const replan = await loadSlashdoCommandBody('replan').catch(() => '');prompt = prompt.replace(/\{slashdoReplan\}/g, () => replan);@@ -168,5 +166,5 @@ export async function getStagePrompt(taskType, stageIndex) {if (!stage?.promptKey) return getTaskPrompt(taskType);const prompt = DEFAULT_TASK_PROMPTS[stage.promptKey];if (!prompt) return getTaskPrompt(taskType);- return resolvePromptPlaceholders(prompt, { promptKey: stage.promptKey });+ return resolvePromptPlaceholders(prompt);}diff --git a/server/services/taskPromptService.test.js b/server/services/taskPromptService.test.jsindex a37c39da9a..3ec4710056 100644--- a/server/services/taskPromptService.test.js+++ b/server/services/taskPromptService.test.js@@ -13,16 +13,16 @@ vi.mock('./taskSchedule.js', () => ({// `$&` (the match), `$1`, and the "text before / after the match" forms — so a// regression to string-form replacement shows up as spliced prompt text rather// than passing by luck on a body that happens to contain no `$`.-const BACKREFERENCE_BAIT = "regex `^[^/]+#[0-9]+$` and $& and $1 and $' end";+const { BACKREFERENCE_BAIT } = vi.hoisted(() => ({ BACKREFERENCE_BAIT: "regex `^[^/]+#[0-9]+$` and $& and $1 and $' end" }));vi.mock('../lib/slashdoLoader.js', () => ({loadSlashdoFile: vi.fn(async (name) => (name === 'review'- ? `FULL /do:review BODY ## Parse Arguments ## Copilot Code Review Loop ${"regex `^[^/]+#[0-9]+$` and $& and $1 and $' end"}`+ ? `FULL /do:review BODY ## Parse Arguments ## Copilot Code Review Loop ${BACKREFERENCE_BAIT}`: name === 'replan'- ? `REPLAN BODY ${"regex `^[^/]+#[0-9]+$` and $& and $1 and $' end"}`+ ? `REPLAN BODY ${BACKREFERENCE_BAIT}`: '')),- loadSlashdoLib: vi.fn(async (name) => `# ${name} lens\n${"regex `^[^/]+#[0-9]+$` and $& and $1 and $' end"}`),+ loadSlashdoLib: vi.fn(async (name) => `# ${name} lens\n${BACKREFERENCE_BAIT}`),}));import { getTaskPrompt, getStagePrompt, DEFAULT_TASK_PROMPTS, PREVIOUS_DEFAULT_PROMPTS } from './taskPromptService.js';@@ -70,7 +70,7 @@ describe('slashdo placeholder substitution', () => {expect(out.match(/HEAD/g)).toHaveLength(1);});- it('gives the public-review actions stage the review LENSES only, never the whole /do:review procedure', async () => {+ it('gives the public-review actions stage the review LENSES ({reviewLenses}), never the whole /do:review procedure', async () => {getTaskInterval.mockResolvedValueOnce(PR_REVIEWER_INTERVAL);vi.mocked(loadSlashdoFile).mockClear();vi.mocked(loadSlashdoLib).mockClear();@@ -81,7 +81,7 @@ describe('slashdo placeholder substitution', () => {// set — the argument parser, reviewer loops and PR-posting procedure of the// full body are a runtime this sandboxed, network-less stage cannot use.expect(stage.match(/PR Code Review & Actions \(Stage 3\)/g)).toHaveLength(1);- expect(stage).not.toContain('{reviewChecklist}');+ expect(stage).not.toContain('{reviewLenses}');expect(stage).not.toContain('FULL /do:review BODY');expect(stage).toContain('# review-surface-scan lens');expect(stage).toContain('# review-security-audit lens');@@ -97,7 +97,7 @@ describe('slashdo placeholder substitution', () => {]);});- it('still hands every other consumer the full /do:review body', async () => {+ it('keeps {reviewChecklist} as the full /do:review body for stored and prior-default prompts', async () => {getTaskInterval.mockResolvedValueOnce({ prompt: 'X {reviewChecklist} Y' });const out = await getTaskPrompt('code-reviewer');