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

address review (codex): carry referencedIngredientIds forward when snapshotting a draft

[._.]/ Adam Eivy037bc74b7281
diff --git a/server/services/writersRoom/local.js b/server/services/writersRoom/local.js
index d53b33deea..6fe95afc81 100644
--- a/server/services/writersRoom/local.js
+++ b/server/services/writersRoom/local.js
@@ -411,14 +411,21 @@ export async function snapshotDraft(workId, { label } = {}) {
const { manifest, body } = await getWorkWithBody(workId);
const newDraftId = `wr-draft-${randomUUID()}`;
const fromId = manifest.activeDraftVersionId;
+ const fromDraft = manifest.drafts.find((d) => d.id === fromId);
const draftLabel = label || `Draft ${manifest.drafts.length + 1}`;
await atomicWrite(draftPath(workId, newDraftId), body);
+ // The new draft copies the source's body verbatim, so carry its referenced
+ // ingredient ids forward — otherwise the freshly-snapshotted version would
+ // render no chips (despite identical prose) until the next save re-scans.
manifest.drafts.push(buildDraftMeta(body, {
id: newDraftId,
label: draftLabel,
contentFile: `drafts/${newDraftId}.md`,
createdAt: nowIso(),
createdFromVersionId: fromId,
+ ...(Array.isArray(fromDraft?.referencedIngredientIds)
+ ? { referencedIngredientIds: fromDraft.referencedIngredientIds }
+ : {}),
}));
manifest.activeDraftVersionId = newDraftId;
manifest.updatedAt = nowIso();
diff --git a/server/services/writersRoom/local.test.js b/server/services/writersRoom/local.test.js
index 10fe87c08a..8ff58694d4 100644
--- a/server/services/writersRoom/local.test.js
+++ b/server/services/writersRoom/local.test.js
@@ -223,6 +223,16 @@ describe('draft body and versioning', () => {
expect(after.drafts[1].createdFromVersionId).toBe(after.drafts[0].id);
});
+ it('snapshotDraft carries the source draft referencedIngredientIds forward (same body, same refs)', async () => {
+ const work = await createWork({ title: 'Versioned Refs' });
+ await saveDraftBody(work.id, 'Mira appears.', { referencedIngredientIds: ['cat-chr-mira'] });
+ const after = await snapshotDraft(work.id);
+ // Source version keeps its refs; the new active draft inherits them since
+ // it copies the body verbatim (so its chips aren't blank until re-saved).
+ expect(after.drafts[0].referencedIngredientIds).toEqual(['cat-chr-mira']);
+ expect(after.drafts[1].referencedIngredientIds).toEqual(['cat-chr-mira']);
+ });
+
it('setActiveDraft switches the pointer; subsequent saves write the new version', async () => {
const work = await createWork({ title: 'Switch' });
const firstId = work.activeDraftVersionId;