Skip to content

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

say what the gated prompt sections actually guarantee

[._.]/ Adam Eivy8b8ee5187992
diff --git a/scripts/migrations/394-factual-extraction-lens-prompts.js b/scripts/migrations/394-factual-extraction-lens-prompts.js
index 74523e98ac..151cf153d8 100644
--- a/scripts/migrations/394-factual-extraction-lens-prompts.js
+++ b/scripts/migrations/394-factual-extraction-lens-prompts.js
@@ -15,8 +15,9 @@
* both lenses — the catalog path previously rendered every framing slot empty.
*
* Both blocks are mustache-gated, so an install extracting invented fiction
- * renders the same prompts it rendered before this migration. Hash replacement
- * preserves a user-customized template.
+ * gets the same instructions it got before this migration — a closed section
+ * collapses to a blank line, which is how every other gated section in these
+ * prompts already behaves. Hash replacement preserves a customized template.
*/
import { makePromptReplaceMigration } from './_lib.js';
diff --git a/server/services/catalogExtraction.js b/server/services/catalogExtraction.js
index f9a5c6b83f..7721854404 100644
--- a/server/services/catalogExtraction.js
+++ b/server/services/catalogExtraction.js
@@ -52,7 +52,10 @@ const REAL_PERSON_TAG = 'real-person';
/**
* Derive the extraction lens from a stored scrap row. Empty strings (not
* omitted keys) are what keep the prompts' mustache sections closed, so a
- * title-less paste renders exactly the prompt it renders today.
+ * title-less paste gets the same instructions it gets today. (`promptTemplate`
+ * does not strip a standalone section line, so a closed section collapses to a
+ * blank line rather than to nothing — same convention as the `{{#sceneMap}}` /
+ * `{{#characterEvolution}}` sections in the editorial prompts.)
*
* @param {{ title?: string, sourceKind?: string }} scrap
* @returns {{ title: string, sourceKind: string, factual: boolean }}
@@ -66,15 +69,15 @@ function scrapExtractionContext(scrap) {
/**
* Append tags to a sanitized entry list without mutating the entries or
* duplicating a tag the model already emitted. An empty tag list returns the
- * list unchanged, so every fiction-lens extraction keeps today's tags
- * byte-for-byte and allocates nothing.
+ * SAME array reference, so every fiction-lens extraction carries exactly the
+ * tags it carries today and allocates nothing.
*/
const stampTags = (entries, tags) => {
if (tags.length === 0) return entries;
return entries.map((entry) => {
const existing = Array.isArray(entry.tags) ? entry.tags : [];
// Compare by the catalog's own tag identity, so a model that emitted
- // `Real-Person` or `factual ` doesn't put a visible duplicate in the
+ // `Real-Person` or a trailing-space `factual` doesn't put a visible duplicate in the
// review draft that `normalizeTags` would only collapse at persist time.
const seen = new Set(existing.map(canonicalTagKey));
const missing = tags.filter((tag) => !seen.has(canonicalTagKey(tag)));
diff --git a/server/services/catalogExtraction.test.js b/server/services/catalogExtraction.test.js
index af87981871..d031875b1f 100644
--- a/server/services/catalogExtraction.test.js
+++ b/server/services/catalogExtraction.test.js
@@ -481,16 +481,34 @@ describe('catalogExtraction — extraction lens (#7609)', () => {
expect(light).not.toMatch(/\{\{/);
});
- it('renders a title-less paste exactly as it renders today', async () => {
+ it('gives a title-less paste the same instructions it got before the lens existed', async () => {
+ // A scrap with neither field (a peer-synced row can have both null) must
+ // not render a half-empty framing stub or leak the non-fiction rules.
catalogDB.getScrap.mockResolvedValue(scrap({ title: null, sourceKind: null }));
await extractIngredientsForScrap({ scrapId: 'cat-scrap-p' });
- // Empty strings keep the mustache sections closed, so the prompt body is
- // byte-identical to the pre-#7609 render.
const { context } = bibleExtractor.extractBible.mock.calls[0][0];
expect(context.work).toEqual({ title: '', kind: '', wordCount: 2 });
expect(context.factual).toBe(false);
+
+ // Empty strings are what keep the mustache sections CLOSED. The guarantee
+ // is instruction-level, not byte-level: promptTemplate deliberately does
+ // not strip a standalone section line, so a closed section collapses to a
+ // blank line (the same convention {{#sceneMap}} already uses). What must
+ // hold is that none of the non-fiction rules reach a fiction extraction.
+ for (const name of ['writers-room-characters', 'writers-room-places', 'writers-room-objects']) {
+ const rendered = applyTemplate(stagePrompt(name), { ...context, draftBody: 'x' });
+ expect(rendered).not.toContain('## Lens: non-fiction');
+ expect(rendered).not.toMatch(/\{\{/);
+ }
+ const [, lightVars] = stageRunner.runStagedLLM.mock.calls[0];
+ const light = applyTemplate(stagePrompt('catalog-ideas-scenes-concepts'), lightVars);
+ expect(light).not.toContain('## Lens: non-fiction');
+ // The Source block is gated on the capture kind, so a kind-less scrap gets
+ // no empty "## Source" stub either.
+ expect(light).not.toContain('## Source\n');
+ expect(light).not.toMatch(/\{\{/);
});
});