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): non-enumerable scraps (strict-gate safe) + only treat ```json as a payload fence

[._.]/ Adam Eivy70d95991c083
diff --git a/server/lib/catalogBulkParsers.js b/server/lib/catalogBulkParsers.js
index 8ddc6555c8..533faf1fe0 100644
--- a/server/lib/catalogBulkParsers.js
+++ b/server/lib/catalogBulkParsers.js
@@ -333,12 +333,15 @@ export function parseMarkdownBulk(payload) {
}
continue;
}
- // Open a ```json (or bare ```) fence — terminates the body section.
+ // Open a ```json fence — the ONLY fence `ingredientToMarkdown` emits,
+ // carrying the non-primary payload keys. Other fences (```js, ```text,
+ // bare ```) are intentionally left in the body so a hand-authored markdown
+ // import doesn't silently lose fenced content. Fence state is driven by
+ // `current.fence`; `section` only gates scraps, so the body resumes after
+ // the closing ```.
const fenceOpen = /^```(\w*)\s*$/.exec(line);
- if (fenceOpen) {
- // Fence state is driven by `current.fence`; `section` only gates the
- // scraps branch, so the body resumes (section stays 'body') after close.
- current.fence = { lang: fenceOpen[1] || '', lines: [] };
+ if (fenceOpen && fenceOpen[1].toLowerCase() === 'json') {
+ current.fence = { lines: [] };
continue;
}
// `### Scraps` switches us into the scraps subsection — body is done.
@@ -370,11 +373,13 @@ export function parseMarkdownBulk(payload) {
}
const entries = out.map((entry, i) => {
const normalized = normalizeEntry(entry, i);
- // Carry parsed scraps as a sibling array for a lossless round-trip. The
- // bulk-import route ignores it today (the ref-link path is what it acts
- // on), but the round-trip stays faithful for any consumer that reads it.
+ // Carry parsed scraps as a NON-enumerable sibling for a faithful
+ // round-trip. It must be non-enumerable: the bulk-import route spreads
+ // each entry into the `.strict()` catalogIngredientCreateSchema, which has
+ // no `scraps` field — an enumerable key would reject every re-imported
+ // export that has scraps. Consumers read `entry.scraps` explicitly.
if (Array.isArray(entry.scraps) && entry.scraps.length > 0) {
- normalized.scraps = entry.scraps;
+ attachNonEnumerable(normalized, 'scraps', entry.scraps);
}
return normalized;
});
diff --git a/server/lib/catalogBulkParsers.test.js b/server/lib/catalogBulkParsers.test.js
index d9cf0f50e6..21eba3b7d9 100644
--- a/server/lib/catalogBulkParsers.test.js
+++ b/server/lib/catalogBulkParsers.test.js
@@ -310,13 +310,34 @@ describe('parseMarkdownBulk', () => {
};
const md = ingredientToMarkdown(ing);
const out = parseMarkdownBulk(md);
+ // scraps ride NON-enumerable so the strict bulk-import gate
+ // (catalogIngredientCreateSchema has no `scraps` field) accepts the
+ // re-import; assert the enumerable shape and the scraps sibling separately.
expect(out[0]).toEqual({
type: 'character',
name: 'Alice',
payload: { physicalDescription: 'a curious sleuth', personality: 'quiet', role: 'detective' },
tags: ['noir'],
- scraps: [{ sourceKind: 'paste', rawText: 'first sighting in chapter 1' }],
});
+ expect(Object.keys(out[0])).not.toContain('scraps');
+ expect(out[0].scraps).toEqual([{ sourceKind: 'paste', rawText: 'first sighting in chapter 1' }]);
+ });
+
+ it('leaves a non-JSON fence (```js/```text) intact in the body instead of dropping it', () => {
+ const md = [
+ '## Idea: snippet',
+ 'here is code:',
+ '```js',
+ 'const x = 1;',
+ '```',
+ 'after the fence',
+ '',
+ ].join('\n');
+ const out = parseMarkdownBulk(md);
+ expect(out[0].payload.summary).toContain('```js');
+ expect(out[0].payload.summary).toContain('const x = 1;');
+ expect(out[0].payload.summary).toContain('after the fence');
+ expect(out.warnings).toEqual([]);
});
});