@vibgrate/cli 2026.4.10-2 → 2026.4.10
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.
- package/dist/cli.js +90 -44
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -572,61 +572,113 @@ function validateFactLine(line) {
|
|
|
572
572
|
} catch {
|
|
573
573
|
return { valid: false, error: `Invalid JSON: ${line.substring(0, 80)}...` };
|
|
574
574
|
}
|
|
575
|
-
const
|
|
576
|
-
if (
|
|
577
|
-
if (obj.payload === void 0 || obj.payload === null) {
|
|
578
|
-
return { valid: false, error: `Preamble ${obj.factType} missing payload` };
|
|
579
|
-
}
|
|
580
|
-
return { valid: true };
|
|
581
|
-
}
|
|
582
|
-
if (typeof obj.factId !== "string" || !obj.factId) {
|
|
575
|
+
const envelope = parsed;
|
|
576
|
+
if (typeof envelope.factId !== "string" || !envelope.factId) {
|
|
583
577
|
return { valid: false, error: "Missing or invalid factId" };
|
|
584
578
|
}
|
|
585
|
-
if (typeof
|
|
586
|
-
if (obj.payload === void 0 || obj.payload === null) {
|
|
587
|
-
return { valid: false, error: "Compressed fact missing payload" };
|
|
588
|
-
}
|
|
589
|
-
return { valid: true };
|
|
590
|
-
}
|
|
591
|
-
if (typeof obj.factType !== "string" || !obj.factType) {
|
|
579
|
+
if (typeof envelope.factType !== "string" || !envelope.factType) {
|
|
592
580
|
return { valid: false, error: "Missing or invalid factType" };
|
|
593
581
|
}
|
|
594
|
-
if (typeof
|
|
582
|
+
if (typeof envelope.language !== "string") {
|
|
595
583
|
return { valid: false, error: "Missing or invalid language" };
|
|
596
584
|
}
|
|
597
|
-
if (typeof
|
|
585
|
+
if (typeof envelope.scanner !== "string") {
|
|
598
586
|
return { valid: false, error: "Missing or invalid scanner" };
|
|
599
587
|
}
|
|
600
|
-
if (typeof
|
|
588
|
+
if (typeof envelope.scannerVersion !== "string") {
|
|
601
589
|
return { valid: false, error: "Missing or invalid scannerVersion" };
|
|
602
590
|
}
|
|
603
|
-
if (typeof
|
|
591
|
+
if (typeof envelope.emittedAt !== "string") {
|
|
604
592
|
return { valid: false, error: "Missing or invalid emittedAt" };
|
|
605
593
|
}
|
|
606
|
-
if (
|
|
594
|
+
if (envelope.payload === void 0 || envelope.payload === null) {
|
|
607
595
|
return { valid: false, error: "Missing payload" };
|
|
608
596
|
}
|
|
609
|
-
return { valid: true };
|
|
597
|
+
return { valid: true, fact: envelope };
|
|
610
598
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
613
|
-
|
|
599
|
+
function decompressHcsLines(lines) {
|
|
600
|
+
if (lines.length === 0) return lines;
|
|
601
|
+
let modelsLine = null;
|
|
602
|
+
let refsLine = null;
|
|
603
|
+
const contentLines = [];
|
|
614
604
|
for (const line of lines) {
|
|
615
605
|
let parsed;
|
|
616
606
|
try {
|
|
617
607
|
parsed = JSON.parse(line);
|
|
618
608
|
} catch {
|
|
619
|
-
|
|
609
|
+
contentLines.push(line);
|
|
620
610
|
continue;
|
|
621
611
|
}
|
|
622
612
|
const obj = parsed;
|
|
623
|
-
if (obj.factType === "Models"
|
|
624
|
-
|
|
613
|
+
if (obj.factType === "Models" && !modelsLine) {
|
|
614
|
+
modelsLine = obj;
|
|
615
|
+
} else if (obj.factType === "References" && !refsLine) {
|
|
616
|
+
refsLine = obj;
|
|
625
617
|
} else {
|
|
626
|
-
|
|
618
|
+
contentLines.push(line);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (!modelsLine) return lines;
|
|
622
|
+
const emittedAt = typeof modelsLine.emittedAt === "string" ? modelsLine.emittedAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
623
|
+
const modelsPayload = modelsLine.payload;
|
|
624
|
+
const modelMap = /* @__PURE__ */ new Map();
|
|
625
|
+
for (const m of modelsPayload?.models ?? []) {
|
|
626
|
+
if (m.id) modelMap.set(m.id, m);
|
|
627
|
+
}
|
|
628
|
+
const refsPayload = refsLine?.payload;
|
|
629
|
+
const refMap = /* @__PURE__ */ new Map();
|
|
630
|
+
for (const r of refsPayload?.references ?? []) {
|
|
631
|
+
if (r.id && r.value) refMap.set(r.id, r.value);
|
|
632
|
+
}
|
|
633
|
+
const sortedRefs = [...refMap.entries()].sort((a, b) => b[0].length - a[0].length);
|
|
634
|
+
function expandRefs(text) {
|
|
635
|
+
for (const [token, value] of sortedRefs) {
|
|
636
|
+
text = text.split(token).join(value);
|
|
637
|
+
}
|
|
638
|
+
return text;
|
|
639
|
+
}
|
|
640
|
+
const expanded = [];
|
|
641
|
+
for (const line of contentLines) {
|
|
642
|
+
let parsed;
|
|
643
|
+
try {
|
|
644
|
+
parsed = JSON.parse(line);
|
|
645
|
+
} catch {
|
|
646
|
+
expanded.push(line);
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
const obj = parsed;
|
|
650
|
+
if (typeof obj.factType === "string") {
|
|
651
|
+
expanded.push(line);
|
|
652
|
+
continue;
|
|
627
653
|
}
|
|
654
|
+
if (typeof obj.factId !== "string" || typeof obj.m !== "string") {
|
|
655
|
+
expanded.push(line);
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
const model = modelMap.get(obj.m);
|
|
659
|
+
if (!model) {
|
|
660
|
+
expanded.push(line);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const payloadJson = expandRefs(JSON.stringify(obj.payload));
|
|
664
|
+
let payload;
|
|
665
|
+
try {
|
|
666
|
+
payload = JSON.parse(payloadJson);
|
|
667
|
+
} catch {
|
|
668
|
+
payload = obj.payload;
|
|
669
|
+
}
|
|
670
|
+
const fullEnvelope = {
|
|
671
|
+
factId: obj.factId,
|
|
672
|
+
factType: model.factType ?? "",
|
|
673
|
+
language: model.language ?? "",
|
|
674
|
+
scanner: model.scanner ?? "",
|
|
675
|
+
scannerVersion: model.scannerVersion ?? "",
|
|
676
|
+
emittedAt: model.emittedAt ?? emittedAt,
|
|
677
|
+
payload
|
|
678
|
+
};
|
|
679
|
+
expanded.push(JSON.stringify(fullEnvelope));
|
|
628
680
|
}
|
|
629
|
-
return
|
|
681
|
+
return expanded;
|
|
630
682
|
}
|
|
631
683
|
function resolveHcsWorkerBin() {
|
|
632
684
|
const base = import.meta.dirname ?? path6.dirname(new URL(import.meta.url).pathname);
|
|
@@ -1244,7 +1296,6 @@ var extractCommand = new Command5("extract").description("Analyze source code an
|
|
|
1244
1296
|
);
|
|
1245
1297
|
const progress = new ProgressTracker(runnableLanguages);
|
|
1246
1298
|
const sem = new Semaphore(concurrency);
|
|
1247
|
-
const allPreamble = [];
|
|
1248
1299
|
const allFacts = [];
|
|
1249
1300
|
const allErrors = [];
|
|
1250
1301
|
let hasSchemaFailure = false;
|
|
@@ -1270,12 +1321,15 @@ var extractCommand = new Command5("extract").description("Analyze source code an
|
|
|
1270
1321
|
if (result.exitCode === EXIT_TIMEOUT) {
|
|
1271
1322
|
hasTimeout = true;
|
|
1272
1323
|
}
|
|
1273
|
-
const
|
|
1274
|
-
allPreamble.push(...preamble);
|
|
1324
|
+
const decompressedFacts = decompressHcsLines(result.facts);
|
|
1275
1325
|
let langFactCount = 0;
|
|
1276
|
-
for (const line of
|
|
1326
|
+
for (const line of decompressedFacts) {
|
|
1277
1327
|
const validation = validateFactLine(line);
|
|
1278
|
-
if (
|
|
1328
|
+
if (validation.valid) {
|
|
1329
|
+
allFacts.push(line);
|
|
1330
|
+
langFactCount++;
|
|
1331
|
+
progress.onFact();
|
|
1332
|
+
} else {
|
|
1279
1333
|
hasSchemaFailure = true;
|
|
1280
1334
|
allErrors.push(`[${language}] Schema validation: ${validation.error}`);
|
|
1281
1335
|
if (opts.verbose) {
|
|
@@ -1284,13 +1338,6 @@ var extractCommand = new Command5("extract").description("Analyze source code an
|
|
|
1284
1338
|
}
|
|
1285
1339
|
}
|
|
1286
1340
|
}
|
|
1287
|
-
for (const line of facts) {
|
|
1288
|
-
if (validateFactLine(line).valid) {
|
|
1289
|
-
allFacts.push(line);
|
|
1290
|
-
langFactCount++;
|
|
1291
|
-
progress.onFact();
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
1341
|
progress.setLanguageFactCount(language, langFactCount);
|
|
1295
1342
|
if (result.errors.length > 0) {
|
|
1296
1343
|
allErrors.push(...result.errors.map((e) => `[${language}] ${e}`));
|
|
@@ -1304,8 +1351,7 @@ var extractCommand = new Command5("extract").description("Analyze source code an
|
|
|
1304
1351
|
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
1305
1352
|
progress.finish(elapsed);
|
|
1306
1353
|
allFacts.sort();
|
|
1307
|
-
const
|
|
1308
|
-
const ndjsonOutput = allLines.join("\n") + (allLines.length > 0 ? "\n" : "");
|
|
1354
|
+
const ndjsonOutput = allFacts.map((f) => f).join("\n") + (allFacts.length > 0 ? "\n" : "");
|
|
1309
1355
|
if (opts.out) {
|
|
1310
1356
|
const outPath = path6.resolve(opts.out);
|
|
1311
1357
|
await fs2.writeFile(outPath, ndjsonOutput, "utf-8");
|
|
@@ -1315,7 +1361,7 @@ var extractCommand = new Command5("extract").description("Analyze source code an
|
|
|
1315
1361
|
process.stdout.write(ndjsonOutput);
|
|
1316
1362
|
}
|
|
1317
1363
|
if (opts.push && dsn && allFacts.length > 0) {
|
|
1318
|
-
const pushOk = await pushFacts(
|
|
1364
|
+
const pushOk = await pushFacts(allFacts, dsn, opts.verbose ?? false);
|
|
1319
1365
|
if (!pushOk) {
|
|
1320
1366
|
process.exit(EXIT_PUSH_FAILURE);
|
|
1321
1367
|
}
|