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
combine the code-section JSON repairs so an unclosed section with stray characters still parses
[._.]/ Adam Eivy5b8f8cb91a03
diff --git a/server/services/codeAnimation/prompt.js b/server/services/codeAnimation/prompt.jsindex ad21d36a9c..04de4251d7 100644--- a/server/services/codeAnimation/prompt.js+++ b/server/services/codeAnimation/prompt.js@@ -441,11 +441,13 @@ export function extractCodeSections(text) {// `]}` (`..."}]}"}`) or a section object left unclosed (`..."]}`). Try the text as given,// then a few bounded repairs, and return the first that parses (or null).function parseSectionsJson(json) {- const attempts = [json];+ const trimmed = [json];for (let end = json.length - 1, tries = 0; end > 0 && tries < 8; end = json.lastIndexOf('}', end - 1), tries += 1) {- if (json[end] === '}' && end < json.length - 1) attempts.push(json.slice(0, end + 1));+ if (json[end] === '}' && end < json.length - 1) trimmed.push(json.slice(0, end + 1));}- if (/"\s*\]\s*\}\s*$/.test(json)) attempts.push(json.replace(/"\s*\]\s*\}\s*$/, '"}]}'));+ // Each cut-back also gets the unclosed-object repair, so both slips together still parse.+ const closeLast = (text) => (/"\s*\]\s*\}\s*$/.test(text) ? [text.replace(/"\s*\]\s*\}\s*$/, '"}]}')] : []);+ const attempts = [...trimmed, ...trimmed.flatMap(closeLast)];for (const attempt of attempts) {try { return JSON.parse(attempt); } catch { /* try the next repair */ }}diff --git a/server/services/codeAnimation/prompt.test.js b/server/services/codeAnimation/prompt.test.jsindex f523f00cc4..f8aff7dc65 100644--- a/server/services/codeAnimation/prompt.test.js+++ b/server/services/codeAnimation/prompt.test.js@@ -267,6 +267,10 @@ describe('extractCodeSections', () => {const unclosed = `{"sections":[{"id":"beat-3","source":${JSON.stringify(fn)}]}`;expect(extractCodeSections(`\`\`\`json\n${unclosed}\n\`\`\``)).toEqual([{ id: 'beat-3', source: fn }]);});+ it('recovers an unclosed last section followed by stray characters', () => {+ const both = `{"sections":[{"id":"beat-3","source":${JSON.stringify(fn)}]}"}`;+ expect(extractCodeSections(`\`\`\`json\n${both}\n\`\`\``)).toEqual([{ id: 'beat-3', source: fn }]);+ });it('returns nothing for text with no usable JSON', () => {expect(extractCodeSections('no json here')).toEqual([]);expect(extractCodeSections('```json\n{"sections": [ {"id": \n```')).toEqual([]);