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 (claude): trim prior-issue prose tail from the head so the closing survives
[._.]/ Adam Eivydea01e0fa117
diff --git a/server/services/pipeline/textStages.js b/server/services/pipeline/textStages.jsindex 1b44035901..d8b5e16b75 100644--- a/server/services/pipeline/textStages.js+++ b/server/services/pipeline/textStages.js@@ -274,9 +274,9 @@ async function buildProseContextAugment(series, issue, options = {}) {const empty = { priorIssueProseTail: '', nextIssueBeats: '', hasNeighborContinuity: false };const { prior, next } = await resolveVolumeNeighbors(series, issue);- const rawTail = prior ? extractProseTail(stageContentOf(prior.stages?.prose)) : '';+ const priorProse = prior ? stageContentOf(prior.stages?.prose) : '';const rawBeats = extractNextIssueBeats(next);- if (!rawTail && !rawBeats) return empty;+ if (!priorProse && !rawBeats) return empty;// Token-budget both blocks so they degrade by trimming on a small window// rather than blowing the prompt. Resolve the prose stage's planning window@@ -294,8 +294,15 @@ async function buildProseContextAugment(series, issue, options = {}) {const continuityChars = Math.max(0, Math.floor(usableTokens * CONTINUITY_BUDGET_FRACTION)) * CHARS_PER_TOKEN;// Prose tail keeps priority; next beats reclaim whatever the tail doesn't use.+ // The tail must be trimmed from its HEAD (keep the actual CLOSING of the prior+ // issue — the seam the template tells the model to flow from), so size it via+ // extractProseTail (which keeps the end) rather than trimContextToBudget (which+ // keeps the head and would discard the literal final lines on a small window).+ // Never grow past PRIOR_PROSE_TAIL_CHARS just because the window is large.const tailBudget = rawBeats ? Math.floor(continuityChars * PRIOR_TAIL_SHARE) : continuityChars;- const priorIssueProseTail = rawTail ? trimContextToBudget(rawTail, tailBudget) : '';+ const priorIssueProseTail = priorProse+ ? extractProseTail(priorProse, Math.min(PRIOR_PROSE_TAIL_CHARS, tailBudget))+ : '';const beatsBudget = continuityChars - priorIssueProseTail.length;const nextIssueBeats = rawBeats ? trimContextToBudget(rawBeats, Math.max(0, beatsBudget)) : '';diff --git a/server/services/pipeline/textStages.test.js b/server/services/pipeline/textStages.test.jsindex 5874f95bc8..5a46914f20 100644--- a/server/services/pipeline/textStages.test.js+++ b/server/services/pipeline/textStages.test.js@@ -634,7 +634,9 @@ describe('pipeline text stage generator', () => {});const { series } = await seed();const sea = await seasonsSvc.createSeason(series.id, { title: 'V1' });- const bigTail = 'The tide rolls in. '.repeat(2000); // ~38K chars — far over the window+ // Distinct opening vs closing markers so we can prove the trim keeps the END+ // (the actual close the model must flow from), not the head.+ const bigTail = `PRIOR_OPENING. ${'The tide rolls in. '.repeat(2000)}PRIOR_CLOSING.`;await issuesSvc.createIssue({seriesId: series.id, title: 'A', seasonId: sea.id, arcPosition: 1,stages: { prose: { status: 'ready', output: bigTail } },@@ -646,6 +648,10 @@ describe('pipeline text stage generator', () => {// Present but trimmed below the raw ~2000-char tail cap — degraded, not dropped or errored.expect(ctx.priorIssueProseTail.length).toBeGreaterThan(0);expect(ctx.priorIssueProseTail.length).toBeLessThan(2_000);+ // Regression guard: the trim must keep the CLOSING of the prior issue (the+ // seam the prose template tells the model to open from), not its opening.+ expect(ctx.priorIssueProseTail).toContain('PRIOR_CLOSING');+ expect(ctx.priorIssueProseTail).not.toContain('PRIOR_OPENING');});it('prompt context carries derived lengthTargets for the custom profile', async () => {