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
shrink the pr-reviewer Stage 3 prompt from ~400KB to ~50KB and stop a backreference splice duplicating it
[._.]/ Adam Eivyba0e6cbcd86b
diff --git a/server/services/taskPromptService.js b/server/services/taskPromptService.jsindex 72155515c7..0b0bcd1240 100644--- a/server/services/taskPromptService.js+++ b/server/services/taskPromptService.js@@ -28,7 +28,7 @@*/import { PATHS } from '../lib/fileUtils.js';-import { loadSlashdoFile } from '../lib/slashdoLoader.js';+import { loadSlashdoFile, loadSlashdoLib } from '../lib/slashdoLoader.js';import { getTaskInterval } from './taskSchedule.js';import {DEFAULT_TASK_PROMPTS,@@ -73,22 +73,70 @@ async function loadSlashdoCommandBody(commandName) {return _slashdoCache[commandName];}-async function resolvePromptPlaceholders(prompt) {+/**+ * 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`).+ *+ * That stage runs a single sandboxed agent with no network, no forge+ * credential, no sub-agent dispatch, and — on the local wrappers it is+ * commonly pinned to — a model server that prefills at a few hundred tokens per+ * second. The full `/do:review` body it used to receive is ~260KB: argument+ * parsing, reviewer-selection protocol, five reviewer LOOPS (Copilot, GitHub+ * `@login`, local agent, Ollama, multi-reviewer), issue filing and PR posting —+ * every one of them a procedure the stage's own contract forbids, and together+ * ~75K prompt tokens the model had to chew through before reading the PR. On+ * 2026-09-04 that prefill outlived Claude Code's stream-idle watchdog on every+ * attempt, so Stage 3 sat at `API error · Retrying … attempt 1/10` forever+ * (agent-e057cca7). The lenses are the review; the rest was the harness for a+ * different runtime.+ */+const PUBLIC_REVIEW_LENS_LIBS = [+ 'review-surface-scan',+ 'review-surface-quality',+ 'review-security-audit',+ 'review-cross-file-tracing',+ 'review-cross-file-contract',+];+const LENS_ONLY_CHECKLIST_PROMPT_KEYS = new Set(['pr-reviewer-review']);++async function loadPublicReviewChecklist() {+ const lenses = await Promise.all(PUBLIC_REVIEW_LENS_LIBS.map((name) => loadSlashdoLib(name).catch(() => null)));+ return lenses.filter(Boolean).join('\n\n');+}++/**+ * Substitute the prompt-level placeholders. Every replacement is FUNCTION-form:+ * a string replacement makes `String.replace` interpret its `$`-prefixed+ * tokens (`$&`, `$n`, the "text before the match" and "text after the match"+ * forms) in the replacement text, and the shell-heavy slashdo bodies are full+ * of `$`. One "text before the match" token inside the inlined `/do:review` (a+ * regex like `^[^/]+/[^/]+#[0-9]+$` followed by a backtick) spliced EVERYTHING+ * 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 } = {}) {// {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- // checkout never pollutes the target repo's working tree. Function-form- // replacer so a literal `$` in the path can't be read as a backreference.+ // checkout never pollutes the target repo's working tree.if (prompt.includes('{worktreesRoot}')) {prompt = prompt.replace(/\{worktreesRoot\}/g, () => PATHS.worktrees);}if (prompt.includes('{reviewChecklist}')) {- const checklist = await loadSlashdoCommandBody('review').catch(() => '');- prompt = prompt.replace(/\{reviewChecklist\}/g, checklist);+ const checklist = LENS_ONLY_CHECKLIST_PROMPT_KEYS.has(promptKey)+ ? await loadPublicReviewChecklist()+ : await loadSlashdoCommandBody('review').catch(() => '');+ prompt = prompt.replace(/\{reviewChecklist\}/g, () => checklist);}if (prompt.includes('{slashdoReplan}')) {const replan = await loadSlashdoCommandBody('replan').catch(() => '');- prompt = prompt.replace(/\{slashdoReplan\}/g, replan);+ prompt = prompt.replace(/\{slashdoReplan\}/g, () => replan);}return prompt;}@@ -120,5 +168,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);+ return resolvePromptPlaceholders(prompt, { promptKey: stage.promptKey });}diff --git a/server/services/taskPromptService.test.js b/server/services/taskPromptService.test.jsindex f2db88b9b2..a37c39da9a 100644--- a/server/services/taskPromptService.test.js+++ b/server/services/taskPromptService.test.js@@ -8,8 +8,26 @@ vi.mock('./taskSchedule.js', () => ({getTaskInterval: vi.fn(async () => ({ prompt: 'before {worktreesRoot}/claim-x after' })),}));+// Stand-in slashdo bodies. Every one carries the `$`-prefixed tokens that+// String.replace treats as backreferences when handed a STRING replacement —+// `$&` (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";+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"}`+ : name === 'replan'+ ? `REPLAN BODY ${"regex `^[^/]+#[0-9]+$` and $& and $1 and $' end"}`+ : ''+ )),+ loadSlashdoLib: vi.fn(async (name) => `# ${name} lens\n${"regex `^[^/]+#[0-9]+$` and $& and $1 and $' end"}`),+}));+import { getTaskPrompt, getStagePrompt, DEFAULT_TASK_PROMPTS, PREVIOUS_DEFAULT_PROMPTS } from './taskPromptService.js';import { getTaskInterval } from './taskSchedule.js';+import { loadSlashdoFile, loadSlashdoLib } from '../lib/slashdoLoader.js';import { PATHS } from '../lib/fileUtils.js';describe('taskPromptService {worktreesRoot} substitution', () => {@@ -26,6 +44,69 @@ describe('taskPromptService {worktreesRoot} substitution', () => {});});+describe('slashdo placeholder substitution', () => {+ const PR_REVIEWER_INTERVAL = {+ prompt: null,+ taskMetadata: {+ pipeline: {+ stages: [+ { name: 'Security Scan', promptKey: 'pr-reviewer-security' },+ { name: 'Eligibility Gate', promptKey: 'pr-reviewer-eligibility' },+ { name: 'Code Review & Merge', promptKey: 'pr-reviewer-review' },+ ],+ },+ },+ };++ it('inlines a slashdo body verbatim — backreference tokens in it never splice the prompt', async () => {+ getTaskInterval.mockResolvedValueOnce({ prompt: 'HEAD {reviewChecklist} TAIL {slashdoReplan} END' });++ const out = await getTaskPrompt('code-reviewer');++ // The 2026-09-04 shape of this bug: a `$` + backtick inside the inlined+ // /do:review re-inserted everything before the placeholder, so one Stage 3+ // prompt carried seven copies of its own header (~400KB, ~100K tokens).+ expect(out).toBe(`HEAD FULL /do:review BODY ## Parse Arguments ## Copilot Code Review Loop ${BACKREFERENCE_BAIT} TAIL REPLAN BODY ${BACKREFERENCE_BAIT} END`);+ 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 () => {+ getTaskInterval.mockResolvedValueOnce(PR_REVIEWER_INTERVAL);+ vi.mocked(loadSlashdoFile).mockClear();+ vi.mocked(loadSlashdoLib).mockClear();++ const stage = await getStagePrompt('pr-reviewer', 2);++ // The stage header appears once (no splice) and the checklist is the lens+ // 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('FULL /do:review BODY');+ expect(stage).toContain('# review-surface-scan lens');+ expect(stage).toContain('# review-security-audit lens');+ expect(stage).toContain('# review-cross-file-contract lens');+ expect(stage).toContain(BACKREFERENCE_BAIT);+ expect(vi.mocked(loadSlashdoFile)).not.toHaveBeenCalledWith('review', expect.anything());+ expect(vi.mocked(loadSlashdoLib).mock.calls.map(([name]) => name)).toEqual([+ 'review-surface-scan',+ 'review-surface-quality',+ 'review-security-audit',+ 'review-cross-file-tracing',+ 'review-cross-file-contract',+ ]);+ });++ it('still hands every other consumer the full /do:review body', async () => {+ getTaskInterval.mockResolvedValueOnce({ prompt: 'X {reviewChecklist} Y' });++ const out = await getTaskPrompt('code-reviewer');++ expect(out).toContain('FULL /do:review BODY');+ expect(out).not.toContain('lens');+ });+});+describe('claim-flow prompt variants', () => {it('keeps scheduled plan-task review-free while manual PLAN claims retain review guidance', async () => {getTaskInterval.mockResolvedValue({ prompt: null });