@cccarv82/freya 3.8.3 → 3.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -117,10 +117,20 @@ function extractFirstJsonObject(text) {
117
117
  const start = text.indexOf('{');
118
118
  if (start === -1) return null;
119
119
  let depth = 0;
120
+ let inString = false;
121
+ let escape = false;
120
122
  for (let i = start; i < text.length; i++) {
121
- if (text[i] === '{') depth++;
122
- else if (text[i] === '}') { depth--; if (depth === 0) return text.slice(start, i + 1); }
123
+ const ch = text[i];
124
+ if (escape) { escape = false; continue; }
125
+ if (ch === '\\' && inString) { escape = true; continue; }
126
+ if (ch === '"') { inString = !inString; continue; }
127
+ if (inString) continue;
128
+ if (ch === '{') depth++;
129
+ else if (ch === '}') { depth--; if (depth === 0) return text.slice(start, i + 1); }
123
130
  }
131
+ // If brace matching failed, try a greedy approach — find the last }
132
+ const lastBrace = text.lastIndexOf('}');
133
+ if (lastBrace > start) return text.slice(start, lastBrace + 1);
124
134
  return null;
125
135
  }
126
136
 
@@ -332,8 +342,14 @@ IMPORTANTE: Extraia APENAS informações explícitas do log. NÃO invente dados.
332
342
  totalErrors++;
333
343
  if (totalErrors <= 2) {
334
344
  console.log(`\n ⚠ JSON parse diagnostic for ${date}:`);
335
- console.log(` Raw output (first 500 chars): ${out.slice(0, 500)}`);
336
- console.log(` Extracted JSON attempt: ${(jsonText || '').slice(0, 300)}`);
345
+ console.log(` Raw output length: ${out.length} chars`);
346
+ console.log(` Raw output (first 300 chars): ${out.slice(0, 300)}`);
347
+ console.log(` Raw output (last 200 chars): ${out.slice(-200)}`);
348
+ console.log(` Extracted JSON length: ${(jsonText || '').length}`);
349
+ console.log(` Extracted JSON (last 200 chars): ${(jsonText || '').slice(-200)}`);
350
+ try { JSON.parse(jsonText); } catch (parseErr) {
351
+ console.log(` Parse error: ${parseErr.message}`);
352
+ }
337
353
  }
338
354
  process.stdout.write(`\r [${i + 1}/${files.length}] ${date} — ❌ invalid JSON `);
339
355
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cccarv82/freya",
3
- "version": "3.8.3",
3
+ "version": "3.8.4",
4
4
  "description": "Personal AI Assistant with local-first persistence",
5
5
  "scripts": {
6
6
  "health": "node scripts/validate-data.js && node scripts/validate-structure.js",