fleetbo-cockpit-cli 1.0.75 → 1.0.76

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.
Files changed (2) hide show
  1. package/cli.js +33 -21
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -310,9 +310,38 @@ if (command === 'alex') {
310
310
 
311
311
  let aiData = result.data;
312
312
 
313
- if (typeof aiData === 'string') {
314
- try { aiData = JSON.parse(aiData); } catch (_) {}
315
- }
313
+ // 🛡️ ROBUST PARSER: Unwrap all nesting levels until we find a valid aiData object
314
+ const deepUnwrap = (raw, depth = 0) => {
315
+ if (depth > 5) return raw; // Safety: max 5 nesting levels
316
+ if (typeof raw === 'string') {
317
+ // Try to extract a JSON object even if there's trailing garbage (truncation)
318
+ const jsonMatch = raw.match(/\{[\s\S]*\}/);
319
+ if (jsonMatch) {
320
+ try {
321
+ return deepUnwrap(JSON.parse(jsonMatch[0]), depth + 1);
322
+ } catch (_) {}
323
+ }
324
+ return raw;
325
+ }
326
+ if (typeof raw === 'object' && raw !== null) {
327
+ // If the message field itself is a JSON string, unwrap it and merge moduleData
328
+ if (typeof raw.message === 'string' && raw.message.trimStart().startsWith('{')) {
329
+ try {
330
+ const nested = JSON.parse(raw.message);
331
+ if (nested && typeof nested === 'object' && nested.status) {
332
+ // Merge: keep top-level moduleData if present, else take nested one
333
+ if (!raw.moduleData && nested.moduleData) raw.moduleData = nested.moduleData;
334
+ raw.message = nested.message || raw.message;
335
+ if (!raw.status && nested.status) raw.status = nested.status;
336
+ }
337
+ } catch (_) {}
338
+ }
339
+ return raw;
340
+ }
341
+ return raw;
342
+ };
343
+
344
+ aiData = deepUnwrap(aiData);
316
345
 
317
346
  // 🟢 DISPLAY REASONING IN TERMINAL
318
347
  if (aiData.thinking_process) {
@@ -331,27 +360,10 @@ if (command === 'alex') {
331
360
  console.log('');
332
361
  let rawMsg = aiData.message || "I'm ready.";
333
362
 
334
- if (typeof rawMsg === 'string' && rawMsg.trimStart().startsWith('{')) {
335
- try {
336
- const nested = JSON.parse(rawMsg);
337
- if (nested && nested.message) {
338
- rawMsg = nested.message;
339
- if (!aiData.moduleData && nested.moduleData) {
340
- aiData.moduleData = nested.moduleData;
341
- }
342
- }
343
- } catch (_) {}
344
- }
345
-
363
+ // Final safety: if rawMsg is still an object
346
364
  if (typeof rawMsg === 'object') {
347
365
  rawMsg = rawMsg.message || rawMsg.text || "Module generated.";
348
366
  }
349
- try {
350
- const testParse = JSON.parse(rawMsg);
351
- if (testParse && typeof testParse === 'object' && testParse.status) {
352
- rawMsg = testParse.message || "Module generated.";
353
- }
354
- } catch (_) { }
355
367
 
356
368
  const formattedMsg = wrapText(rawMsg, 85);
357
369
  console.log('\x1b[32mAlex ❯\x1b[0m ' + formattedMsg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbo-cockpit-cli",
3
- "version": "1.0.75",
3
+ "version": "1.0.76",
4
4
  "description": "Fleetbo CLI - Build native mobile apps with React",
5
5
  "author": "Fleetbo",
6
6
  "license": "MIT",