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 review: cap extract corpus at 200K + use stage labels in tooltip
[._.]/ Adam Eivyedf31c3ddc5d
diff --git a/client/src/components/pipeline/stages/ExtractCanonButton.jsx b/client/src/components/pipeline/stages/ExtractCanonButton.jsxindex 99abe66a0c..26bcd1ac6a 100644--- a/client/src/components/pipeline/stages/ExtractCanonButton.jsx+++ b/client/src/components/pipeline/stages/ExtractCanonButton.jsx@@ -1,15 +1,15 @@import { useState } from 'react';import { Loader2, BookOpen } from 'lucide-react';import toast from '../../ui/Toast';-import { extractPipelineCanonFromScript } from '../../../services/apiPipeline';+import { extractPipelineCanonFromScript, PIPELINE_STAGE_LABELS } from '../../../services/apiPipeline';// Manual canon-extraction trigger for the comicScript / teleplay stages.// Auto-extract runs only after `prose` (server/services/pipeline/textStages.js),// so characters/places/objects introduced only in panel directions or// dialogue cues never make it into the bible until the writer clicks this.-function getTooltip({ gated, hasContent, hasUniverse, busy, stageId }) {+function getTooltip({ gated, hasContent, hasUniverse, busy, stageLabel }) {if (gated) return 'Saving settings…';- if (!hasContent) return `Generate the ${stageId} stage first`;+ if (!hasContent) return `Generate the ${stageLabel} stage first`;if (!hasUniverse) return 'Link a universe to the series first — extraction needs a target bible.';if (busy) return 'Extraction in progress…';return 'Extract characters / places / objects from this script and merge into the linked universe.';@@ -20,7 +20,8 @@ export default function ExtractCanonButton({ issue, series, stageId, gated = falconst hasContent = !!(issue.stages?.[stageId]?.output || '').trim();const hasUniverse = !!series?.universeId;const disabled = busy || gated || !hasContent || !hasUniverse;- const tooltip = getTooltip({ gated, hasContent, hasUniverse, busy, stageId });+ const stageLabel = PIPELINE_STAGE_LABELS[stageId] || stageId;+ const tooltip = getTooltip({ gated, hasContent, hasUniverse, busy, stageLabel });const handleClick = async () => {setBusy(true);@@ -34,8 +35,9 @@ export default function ExtractCanonButton({ issue, series, stageId, gated = falconst c = result.extracted?.characters || 0;const p = result.extracted?.places || 0;const o = result.extracted?.objects || 0;+ const suffix = result.truncated ? ' (script truncated to fit context window)' : '';toast.success(- `Extracted ${c} character${c === 1 ? '' : 's'}, ${p} place${p === 1 ? '' : 's'}, ${o} object${o === 1 ? '' : 's'} into the universe`,+ `Extracted ${c} character${c === 1 ? '' : 's'}, ${p} place${p === 1 ? '' : 's'}, ${o} object${o === 1 ? '' : 's'} into the universe${suffix}`,);};diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex 1b5673720f..79e51e271f 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -453,6 +453,12 @@ const extractCanonFromScriptSchema = z.object({providerOverride: z.string().trim().max(80).optional(),});+// Matches `IMPORTER_SOURCE_CHAR_LIMIT` in `server/routes/universeBuilder.js` —+// the safe ceiling we've already settled on for canon-extraction LLM prompts.+// `STAGE_OUTPUT_MAX` (400KB) is large enough that long scripts can exceed+// most provider context windows; clamp before forwarding.+const EXTRACT_CANON_CORPUS_MAX = 200_000;+// Collapses the `extractCanonFromProse` result-shape trio used by both the// season-episodes continuity extract and the manual script-stage extract.const countExtractedCanon = (results) => ({@@ -1385,13 +1391,18 @@ router.post('/issues/:id/stages/:stageId/extract-canon', asyncHandler(async (req}const body = validateRequest(extractCanonFromScriptSchema, req.body ?? {});const issue = await issuesSvc.getIssue(id).catch((err) => { throw mapServiceError(err); });- const corpus = (issue.stages?.[stageId]?.output || '').trim();- if (!corpus) {+ const rawCorpus = (issue.stages?.[stageId]?.output || '').trim();+ if (!rawCorpus) {throw new ServerError(`Cannot extract canon — issue's ${stageId} stage is empty`,{ status: 400, code: 'PIPELINE_CANON_EXTRACT_NO_CORPUS' },);}+ const truncated = rawCorpus.length > EXTRACT_CANON_CORPUS_MAX;+ const corpus = truncated ? rawCorpus.slice(0, EXTRACT_CANON_CORPUS_MAX) : rawCorpus;+ if (truncated) {+ console.warn(`⚠️ Pipeline canon extract — issue=${id.slice(0, 8)} stage=${stageId} corpus truncated ${rawCorpus.length}→${EXTRACT_CANON_CORPUS_MAX}`);+ }const series = await seriesSvc.getSeries(issue.seriesId).catch((err) => { throw mapServiceError(err); });if (!series.universeId) {throw new ServerError(@@ -1411,6 +1422,7 @@ router.post('/issues/:id/stages/:stageId/extract-canon', asyncHandler(async (requniverse: result.universe,extracted: countExtractedCanon(result.results),sourceStage: stageId,+ truncated,});}));diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.jsindex b9f918e0e3..ff06ba3e2e 100644--- a/server/routes/pipeline.test.js+++ b/server/routes/pipeline.test.js@@ -244,7 +244,10 @@ const universeSvc = await import('../services/universeBuilder.js');function makeApp() {const app = express();- app.use(express.json());+ // Mirror production's `express.json({ limit: '55mb' })` in server/index.js so+ // tests can exercise the route's own size handling (e.g. 200K-char extract+ // corpus truncation) without hitting the default 100KB body cap first.+ app.use(express.json({ limit: '55mb' }));app.use('/api/pipeline', pipelineRouter);app.use(errorMiddleware);return app;@@ -835,6 +838,7 @@ describe('pipeline routes', () => {expect(r.body.sourceStage).toBe('comicScript');expect(r.body.extracted).toEqual({ characters: 1, places: 0, objects: 0 });expect(r.body.universe.id).toBe(uni.id);+ expect(r.body.truncated).toBe(false);// Service was called with the script's output as corpus + stamp opts.expect(spy).toHaveBeenCalledTimes(1);@@ -847,6 +851,37 @@ describe('pipeline routes', () => {spy.mockRestore();});+ it('POST /issues/:id/stages/:stageId/extract-canon truncates corpus over 200K chars and flags it', async () => {+ const canonSvc = await import('../services/universeCanon.js');+ const spy = vi.spyOn(canonSvc, 'extractCanonFromProse').mockResolvedValue({+ universe: { id: 'u-mock', characters: [], places: [], objects: [] },+ results: {+ characters: { extracted: [] },+ places: { extracted: [] },+ objects: { extracted: [] },+ },+ });++ const app = makeApp();+ const uni = await universeSvc.createUniverse({ name: 'U' });+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S', universeId: uni.id });+ const iss = await request(app).post(`/api/pipeline/series/${ser.body.id}/issues`).send({ title: 'I' });+ // 250K chars — exceeds the 200K extract cap (well under STAGE_OUTPUT_MAX=400K).+ const oversized = 'PANEL DESCRIPTION. '.repeat(14_000);+ expect(oversized.length).toBeGreaterThan(200_000);+ await request(app).patch(`/api/pipeline/issues/${iss.body.id}`).send({+ stages: { comicScript: { status: 'ready', output: oversized } },+ });+ const r = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicScript/extract-canon`)+ .send({});+ expect(r.status).toBe(200);+ expect(r.body.truncated).toBe(true);+ // Service receives a clamped corpus, not the full 250K input.+ expect(spy.mock.calls[0][1].corpus.length).toBe(200_000);+ spy.mockRestore();+ });+it('POST /issues/:id/stages/teleplay/extract-canon reads the teleplay stage output', async () => {const canonSvc = await import('../services/universeCanon.js');const spy = vi.spyOn(canonSvc, 'extractCanonFromProse').mockResolvedValue({