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: skip comments and add runStageScopedInlineLLM when scanning stage call sites (#3335)
[._.]/ Adam Eivyf1c49f29ce43
diff --git a/client/src/lib/promptStageGroups.js b/client/src/lib/promptStageGroups.jsindex 39336411f5..739bd1362f 100644--- a/client/src/lib/promptStageGroups.js+++ b/client/src/lib/promptStageGroups.js@@ -108,9 +108,11 @@ export function stageHaystack(key, config) {* Groups sort alphabetically with `Other` pinned last, stages by display name.** `systemStageKeys` is the `systemStages` list `GET /api/prompts` ships — the- * server's own table (`server/lib/promptSystemStages.js`), not a client mirror,- * so the "System only" filter can never disagree with the stages the server- * actually protects from deletion (#3314).+ * server's own CURATED table (`server/lib/promptSystemStages.js`), not a client+ * mirror, so the "System only" filter can never disagree with what the server+ * badges (#3314). Deletion protection is deliberately WIDER than this list+ * (every stage `server/` names by literal key, #3335) — the filter intentionally+ * does not surface that set, since ~100 of 127 rows would match.** An empty query and `systemOnly: false` return everything, so the same call* drives both the unfiltered and the filtered render.diff --git a/client/src/pages/PromptManager.jsx b/client/src/pages/PromptManager.jsxindex 17c70706dc..d5c2395609 100644--- a/client/src/pages/PromptManager.jsx+++ b/client/src/pages/PromptManager.jsx@@ -52,10 +52,11 @@ export default function PromptManager() {const setSelectedStage = (name) => setParam('stage', name);const setSelectedVar = (key) => setParam('var', key);const [stages, setStages] = useState({});- // Which stage keys PortOS features call by name. Served by GET /api/prompts+ // The CURATED system-stage keys. Served by GET /api/prompts// (`server/lib/promptSystemStages.js`) rather than mirrored client-side, so// the SYSTEM badge and the "System only" filter can never disagree with the- // stages the server actually force-guards on delete (#3314).+ // server's own table (#3314). This is NOT the full delete-protected set —+ // that one is wider and per-stage, and only `/usage` reports it (#3335).const [systemStageKeys, setSystemStageKeys] = useState([]);const [variables, setVariables] = useState({});const [loading, setLoading] = useState(true);diff --git a/docs/features/prompt-manager.md b/docs/features/prompt-manager.mdindex a17878a957..84c69c3775 100644--- a/docs/features/prompt-manager.md+++ b/docs/features/prompt-manager.md@@ -40,9 +40,11 @@ Templates use Mustache-like syntax:| Route | Description ||-------|-------------|-| GET /api/prompts | List all prompt stages — `{ stages, systemStages }`, where `systemStages` is the key list from `server/lib/promptSystemStages.js` (the stages PortOS features call by name, which the client badges and DELETE force-guards) |+| GET /api/prompts | List all prompt stages — `{ stages, systemStages }`, where `systemStages` is the CURATED key list from `server/lib/promptSystemStages.js` that the client badges `SYSTEM` and filters on. It is NOT the delete-protected set, which is wider (see below) || GET /api/prompts/:stage | Get stage template || PUT /api/prompts/:stage | Update stage/template |+| GET /api/prompts/:stage/usage | Delete-safety report — `{ isSystemStage, usedBy, referencedBy, canDelete, warning }`. `isSystemStage`/`usedBy` come from the curated table; `referencedBy` lists the `server/` sources that name the stage, from the generated `server/lib/promptStageCallSites.generated.json`; `canDelete` is false for either (#3335) |+| DELETE /api/prompts/:stage | Delete a stage. Returns 400 `SYSTEM_STAGE_PROTECTED` without `?force=true` when the stage is curated OR referenced by source || POST /api/prompts/:stage/preview | Preview compiled prompt || GET /api/prompts/variables | List all variables || PUT /api/prompts/variables/:key | Update variable |diff --git a/scripts/generate-prompt-stage-call-sites.js b/scripts/generate-prompt-stage-call-sites.jsindex f6f9977156..85bc03e590 100644--- a/scripts/generate-prompt-stage-call-sites.js+++ b/scripts/generate-prompt-stage-call-sites.js@@ -49,29 +49,37 @@ export const REGENERATE_COMMAND = 'node scripts/generate-prompt-stage-call-sites* lookup table, a `const STAGE = '…'` module constant, …).*/const LITERAL_CALL_RE =- /\b(?:getStage|getStageTemplate|buildPrompt|runStage|runStagedLLM|previewPrompt|resolveStageContext|resolveJudgeForStage)\(\s*(['"])([^'"\n]+)\1/g;+ /\b(?:getStage|getStageTemplate|buildPrompt|runStage|runStagedLLM|runStageScopedInlineLLM|previewPrompt|resolveStageContext|resolveJudgeForStage)\(\s*(['"])([^'"\n]+)\1/g;/**- * Every quoted string literal in a JS source. Stage keys are plain- * `[a-z0-9-]` words, so a literal containing an escape, a newline, or a `${`- * interpolation is never one — excluding those keeps the match cheap and- * avoids mis-parsing multi-line template bodies.+ * One pass over a JS source, in precedence order: block comment, line comment,+ * single-quoted, double-quoted, template literal.+ *+ * Comments are in the alternation only so they can be SKIPPED — a stage key+ * named in a `//` note or a JSDoc block is prose, not a call site, and listing+ * that file under "Referenced in" in the delete dialog would be a lie.+ * Matching them here rather than pre-stripping is what keeps a `'http://…'`+ * literal from being mistaken for the start of a comment.+ *+ * A regex literal containing a quote could still desync the scan. That would+ * be stable, not flaky (the drift test compares two runs of the same scanner),+ * and no `server/` source does it today.*/-const STRING_LITERAL_RE = /'([^'\\\n]*)'|"([^"\\\n]*)"|`([^`\\\n$]*)`/g;+const TOKEN_RE = /\/\*[\s\S]*?\*\/|\/\/[^\n]*|'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\[\s\S])*`/g;/**- * A template literal with a static hyphenated prefix followed by an+ * A static hyphenated prefix inside a template literal, followed by an* interpolation — `` `pipeline-panel-${personaId}` ``. Stages reached this way* (the reader-panel personas) have NO literal key anywhere in source, so a* literal-only scan would leave them unprotected. Every known key under the* prefix counts as referenced by that file.*- * This deliberately over-matches: a `source: `writers-room-${kind}`` telemetry- * tag counts too. Over-protection is the safe failure mode here — the cost is- * an extra path in the delete-confirm dialog, versus a silently deletable- * stage that breaks a feature.+ * This deliberately over-matches: a `` source: `writers-room-${kind}` ``+ * telemetry tag counts too. Over-protection is the safe failure mode here —+ * the cost is an extra path in the delete-confirm dialog, versus a silently+ * deletable stage that breaks a feature.*/-const TEMPLATE_PREFIX_RE = /`([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)+-)\$\{/g;+const TEMPLATE_PREFIX_RE = /(?:^|[^A-Za-z0-9_-])([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)+-)\$\{/g;/*** Files excluded from the scan. `promptSystemStages.js` is the curated@@ -130,14 +138,19 @@ export function buildStageCallSites({ shippedStageKeys, sources }) {};for (const { path, source } of sources) {- for (const match of source.matchAll(STRING_LITERAL_RE)) {- const literal = match[1] ?? match[2] ?? match[3];- if (keys.has(literal)) record(literal, path);- }- for (const [, prefix] of source.matchAll(TEMPLATE_PREFIX_RE)) {- for (const key of keys) {- if (key.length > prefix.length && key.startsWith(prefix)) record(key, path);+ for (const [token] of source.matchAll(TOKEN_RE)) {+ if (token.startsWith('/')) continue; // comment — prose, not a call site+ if (token.startsWith('`')) {+ for (const [, prefix] of token.matchAll(TEMPLATE_PREFIX_RE)) {+ for (const key of keys) {+ if (key.length > prefix.length && key.startsWith(prefix)) record(key, path);+ }+ }}+ // An interpolated or escaped literal is never a bare stage key, so the+ // same unwrap covers all three quote styles.+ const literal = token.slice(1, -1);+ if (keys.has(literal)) record(literal, path);}}diff --git a/scripts/generate-prompt-stage-call-sites.test.js b/scripts/generate-prompt-stage-call-sites.test.jsindex 6282cbd980..3c98d4e2cc 100644--- a/scripts/generate-prompt-stage-call-sites.test.js+++ b/scripts/generate-prompt-stage-call-sites.test.js@@ -30,13 +30,38 @@ describe('prompt stage call-site scanner', () => {src('server/services/b.js', 'await buildPrompt("demo-beta", {});'),src('server/services/c.js', "await runStage('demo-alpha', {});"),src('server/services/d.js', "await runStagedLLM('demo-beta', {});"),+ src('server/services/e.js', "await runStageScopedInlineLLM('demo-alpha', body);"),],});- expect(index['demo-alpha']).toEqual(['server/services/a.js', 'server/services/c.js']);+ expect(index['demo-alpha']).toEqual(['server/services/a.js', 'server/services/c.js', 'server/services/e.js']);expect(index['demo-beta']).toEqual(['server/services/b.js', 'server/services/d.js']);});+ it('ignores a stage key that only appears in a comment', () => {+ // A JSDoc block naming `cd-plan` is prose, not a call site — listing that+ // file under "Referenced in" in the delete dialog would be a lie.+ const index = buildStageCallSites({+ shippedStageKeys,+ sources: [+ src('server/lib/note.js', "/**\n * The planner ('demo-alpha') writes this.\n */\nexport const x = 1;"),+ src('server/lib/line.js', "// falls back to 'demo-alpha' when unset\nexport const y = 2;"),+ src('server/lib/real.js', "getStage('demo-alpha');"),+ ],+ });++ expect(index['demo-alpha']).toEqual(['server/lib/real.js']);+ });++ it('does not mistake a URL inside a literal for the start of a comment', () => {+ const index = buildStageCallSites({+ shippedStageKeys,+ sources: [src('server/services/a.js', "const url = 'https://example.com/x';\ngetStage('demo-alpha');")],+ });++ expect(index['demo-alpha']).toEqual(['server/services/a.js']);+ });+it('catches keys reached indirectly through a lookup table or module constant', () => {// The shapes a call-shape-only regex would miss: textStages.js's// `{ idea: 'pipeline-idea-expansion' }` map and liveDirector.js's@@ -68,6 +93,24 @@ describe('prompt stage call-site scanner', () => {expect(index['demo-alpha']).toBeUndefined();});+ it('finds an interpolated prefix that is not at the start of the template', () => {+ const index = buildStageCallSites({+ shippedStageKeys,+ sources: [src('server/services/panel.js', 'const stage = `${scope}:demo-panel-${id}`;')],+ });++ expect(index['demo-panel-one']).toEqual(['server/services/panel.js']);+ });++ it('ignores an interpolated prefix inside a comment', () => {+ const index = buildStageCallSites({+ shippedStageKeys,+ sources: [src('server/services/panel.js', '// resolves `demo-panel-${id}` at runtime\nexport const x = 1;')],+ });++ expect(index['demo-panel-one']).toBeUndefined();+ });+it('does not match a longer key that merely starts with a shorter one', () => {const index = buildStageCallSites({shippedStageKeys: ['demo-alpha', 'demo-alpha-extended'],diff --git a/server/lib/promptStageCallSites.generated.json b/server/lib/promptStageCallSites.generated.jsonindex 747e82425d..d5a55a9d2d 100644--- a/server/lib/promptStageCallSites.generated.json+++ b/server/lib/promptStageCallSites.generated.json@@ -18,9 +18,7 @@"server/lib/creativeDirectorPrompts.js"],"cd-plan": [- "server/lib/creativeDirectorPrompts.js",- "server/lib/creativeDirectorValidation.js",- "server/lib/schemaVersions.js"+ "server/lib/creativeDirectorPrompts.js"],"cd-treatment": ["server/lib/creativeDirectorPrompts.js"@@ -228,9 +226,7 @@"server/lib/editorial/checkInfra/structureStages.js"],"pipeline-extract-scenes": [- "server/lib/sceneExtractor.js",- "server/routes/pipeline/issues.js",- "server/services/importer.js"+ "server/lib/sceneExtractor.js"],"pipeline-idea-expansion": ["server/services/pipeline/textStages.js"@@ -245,7 +241,6 @@"server/services/pipeline/pipelineJudge.js"],"pipeline-manuscript-completeness": [- "server/lib/promptRunner.js","server/services/pipeline/arcPlanner/completenessPass.js"],"pipeline-manuscript-fix": [@@ -277,8 +272,7 @@"server/services/pipeline/reverseOutline.js"],"pipeline-script-verify": [- "server/services/pipeline/scriptVerify.js",- "server/services/pipeline/seriesAutopilot.js"+ "server/services/pipeline/scriptVerify.js"],"pipeline-season-episodes": ["server/services/pipeline/arcPlanner/episodeSeedPass.js"@@ -290,7 +284,6 @@"server/services/pipeline/seriesGenerate.js"],"pipeline-series-title-logo": [- "server/routes/pipeline/series.js","server/services/pipeline/seriesTitleLogo.js"],"pipeline-series-voice-discover": [@@ -364,7 +357,6 @@"server/services/digital-twin-values-testing.js"],"writers-room-cd-bridge": [- "server/services/creativeDirector/bridgeFromIssue.js","server/services/writersRoom/evaluator.js","server/services/writersRoom/liveDirector.js"],@@ -380,7 +372,6 @@"server/services/writersRoom/evaluator.js"],"writers-room-evaluate": [- "server/lib/stageRunner.js","server/services/writersRoom/evaluator.js"],"writers-room-format": [@@ -399,7 +390,6 @@],"writers-room-script": ["server/lib/sceneExtractor.js",- "server/routes/pipeline/issues.js","server/services/writersRoom/evaluator.js"]}