musubix2 0.5.44 → 0.5.45
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/.claude/.musubix-managed +1 -1
- package/dist/application/install/claude-skill-index-builder.js +2 -1
- package/dist/application/install/claude-skill-index-builder.js.map +1 -1
- package/dist/assets/skills-manifest.json +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +790 -373
- package/dist/cli.js.map +1 -1
- package/dist/index.js +790 -373
- package/dist/infrastructure/assets/package-asset-catalog.js +2 -1
- package/dist/infrastructure/assets/package-asset-catalog.js.map +1 -1
- package/dist/infrastructure/assets/package-root-locator.js +4 -2
- package/dist/infrastructure/assets/package-root-locator.js.map +1 -1
- package/dist/infrastructure/templates/template-renderer.js +2 -1
- package/dist/infrastructure/templates/template-renderer.js.map +1 -1
- package/dist/interface/cli/confirmation-resolver.js +2 -1
- package/dist/interface/cli/confirmation-resolver.js.map +1 -1
- package/dist/interface/cli/init-mode-resolver.js +2 -1
- package/dist/interface/cli/init-mode-resolver.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1921,8 +1921,9 @@ var init_interviewer = __esm({
|
|
|
1921
1921
|
}
|
|
1922
1922
|
// ─── Private Helpers ──────────────────────────────────────────────────────
|
|
1923
1923
|
extractFromInput(input) {
|
|
1924
|
-
if (!input.trim())
|
|
1924
|
+
if (!input.trim()) {
|
|
1925
1925
|
return;
|
|
1926
|
+
}
|
|
1926
1927
|
const lines = input.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
1927
1928
|
if (!this.state.context.projectName) {
|
|
1928
1929
|
const nameMatch = input.match(/(?:プロジェクト名|project\s*name|システム名|system\s*name)[::\s]+(.+)/i);
|
|
@@ -2026,8 +2027,9 @@ var init_interviewer = __esm({
|
|
|
2026
2027
|
[/\bJava\b/, "Java"]
|
|
2027
2028
|
];
|
|
2028
2029
|
for (const [pat, name] of techPatterns) {
|
|
2029
|
-
if (pat.test(input))
|
|
2030
|
+
if (pat.test(input)) {
|
|
2030
2031
|
techs.push(name);
|
|
2032
|
+
}
|
|
2031
2033
|
}
|
|
2032
2034
|
if (techs.length > 0) {
|
|
2033
2035
|
this.state.context.techStack = techs;
|
|
@@ -2090,11 +2092,13 @@ var init_interviewer = __esm({
|
|
|
2090
2092
|
}
|
|
2091
2093
|
applyAnswer(questionId, response) {
|
|
2092
2094
|
const question = this.questions.find((q) => q.id === questionId);
|
|
2093
|
-
if (!question)
|
|
2095
|
+
if (!question) {
|
|
2094
2096
|
return;
|
|
2097
|
+
}
|
|
2095
2098
|
const trimmed = response.trim();
|
|
2096
|
-
if (!trimmed)
|
|
2099
|
+
if (!trimmed) {
|
|
2097
2100
|
return;
|
|
2101
|
+
}
|
|
2098
2102
|
switch (question.category) {
|
|
2099
2103
|
case "projectName":
|
|
2100
2104
|
this.state.context.projectName = trimmed;
|
|
@@ -2223,7 +2227,7 @@ var init_generator = __esm({
|
|
|
2223
2227
|
const earsText = this.buildEARSText(pattern, feature.name, feature.description);
|
|
2224
2228
|
const acceptanceCriteria = [
|
|
2225
2229
|
`- [ ] ${feature.name} \u304C\u6B63\u5E38\u306B\u52D5\u4F5C\u3059\u308B\u3053\u3068`,
|
|
2226
|
-
|
|
2230
|
+
"- [ ] \u30A8\u30E9\u30FC\u6642\u306B\u9069\u5207\u306A\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u8868\u793A\u3055\u308C\u308B\u3053\u3068",
|
|
2227
2231
|
"- [ ] \u30C6\u30B9\u30C8\u304C\u4F5C\u6210\u3055\u308C\u3066\u3044\u308B\u3053\u3068"
|
|
2228
2232
|
];
|
|
2229
2233
|
const markdown = this.formatReqMarkdown(id, feature.name, earsText, pattern, acceptanceCriteria, feature.priority);
|
|
@@ -2273,14 +2277,18 @@ var init_generator = __esm({
|
|
|
2273
2277
|
return feature.earsPattern;
|
|
2274
2278
|
}
|
|
2275
2279
|
const text = `${feature.name} ${feature.description}`.toLowerCase();
|
|
2276
|
-
if (/\b(when|event|trigger|イベント|トリガー)\b/.test(text))
|
|
2280
|
+
if (/\b(when|event|trigger|イベント|トリガー)\b/.test(text)) {
|
|
2277
2281
|
return "event-driven";
|
|
2278
|
-
|
|
2282
|
+
}
|
|
2283
|
+
if (/\b(while|state|状態|モード)\b/.test(text)) {
|
|
2279
2284
|
return "state-driven";
|
|
2280
|
-
|
|
2285
|
+
}
|
|
2286
|
+
if (/\b(not|禁止|しない|制限|error|エラー)\b/.test(text)) {
|
|
2281
2287
|
return "unwanted";
|
|
2282
|
-
|
|
2288
|
+
}
|
|
2289
|
+
if (/\b(if|optional|オプション|有効)\b/.test(text)) {
|
|
2283
2290
|
return "optional";
|
|
2291
|
+
}
|
|
2284
2292
|
return "ubiquitous";
|
|
2285
2293
|
}
|
|
2286
2294
|
buildEARSText(pattern, name, description) {
|
|
@@ -2546,30 +2554,76 @@ var init_requirements = __esm({
|
|
|
2546
2554
|
});
|
|
2547
2555
|
|
|
2548
2556
|
// ../core/dist/design/index.js
|
|
2557
|
+
function deriveOperation(text, fallbackTitle = "") {
|
|
2558
|
+
const shall = /\bSHALL\s+(NOT\s+)?([^.。\n]+)/i.exec(text);
|
|
2559
|
+
const negated = Boolean(shall?.[1]);
|
|
2560
|
+
const phrase = (shall?.[2] ?? fallbackTitle ?? "").trim();
|
|
2561
|
+
const words = phrase.split(/[\s,、]+/).map((w) => w.replace(/[^A-Za-z0-9]/g, "")).filter((w) => w.length > 0 && !OPERATION_STOPWORDS.has(w.toLowerCase())).slice(0, 4);
|
|
2562
|
+
const parts = negated ? ["reject", ...words] : words;
|
|
2563
|
+
if (parts.length === 0) {
|
|
2564
|
+
return "execute";
|
|
2565
|
+
}
|
|
2566
|
+
return parts.map((w, i) => i === 0 ? w.charAt(0).toLowerCase() + w.slice(1) : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
2567
|
+
}
|
|
2549
2568
|
function createDesignGenerator() {
|
|
2550
2569
|
return new DesignGenerator();
|
|
2551
2570
|
}
|
|
2552
2571
|
function createSOLIDValidator() {
|
|
2553
2572
|
return new SOLIDValidator();
|
|
2554
2573
|
}
|
|
2555
|
-
var DesignGenerator, SOLIDValidator;
|
|
2574
|
+
var OPERATION_STOPWORDS, DesignGenerator, SOLIDValidator;
|
|
2556
2575
|
var init_design = __esm({
|
|
2557
2576
|
"../core/dist/design/index.js"() {
|
|
2558
2577
|
"use strict";
|
|
2578
|
+
OPERATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
2579
|
+
"a",
|
|
2580
|
+
"an",
|
|
2581
|
+
"the",
|
|
2582
|
+
"to",
|
|
2583
|
+
"of",
|
|
2584
|
+
"with",
|
|
2585
|
+
"for",
|
|
2586
|
+
"and",
|
|
2587
|
+
"or",
|
|
2588
|
+
"its",
|
|
2589
|
+
"their",
|
|
2590
|
+
"on",
|
|
2591
|
+
"in",
|
|
2592
|
+
"into",
|
|
2593
|
+
"from",
|
|
2594
|
+
"that",
|
|
2595
|
+
"this",
|
|
2596
|
+
"these",
|
|
2597
|
+
"those",
|
|
2598
|
+
"all",
|
|
2599
|
+
"any",
|
|
2600
|
+
"each",
|
|
2601
|
+
"system",
|
|
2602
|
+
"shall",
|
|
2603
|
+
"will",
|
|
2604
|
+
"must",
|
|
2605
|
+
"should"
|
|
2606
|
+
]);
|
|
2559
2607
|
DesignGenerator = class {
|
|
2560
2608
|
counter = 0;
|
|
2561
2609
|
generate(requirements) {
|
|
2562
2610
|
this.counter++;
|
|
2563
2611
|
const docId = `DES-DOC-${String(this.counter).padStart(3, "0")}`;
|
|
2564
2612
|
const groups = this.groupRequirements(requirements);
|
|
2565
|
-
const sections = groups.map((group, idx) =>
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2613
|
+
const sections = groups.map((group, idx) => {
|
|
2614
|
+
const components = this.deriveComponents(group.requirements);
|
|
2615
|
+
return {
|
|
2616
|
+
id: `${docId}-SEC-${String(idx + 1).padStart(3, "0")}`,
|
|
2617
|
+
title: group.title,
|
|
2618
|
+
requirementIds: group.requirements.map((r) => r.id),
|
|
2619
|
+
description: this.generateDescription(group.title, group.requirements, components),
|
|
2620
|
+
interfaces: this.suggestInterfaces(group.requirements),
|
|
2621
|
+
patterns: this.suggestPatterns(group.requirements),
|
|
2622
|
+
responsibilities: this.deriveResponsibilities(group.requirements),
|
|
2623
|
+
components,
|
|
2624
|
+
dataEntities: this.deriveDataEntities(group.requirements)
|
|
2625
|
+
};
|
|
2626
|
+
});
|
|
2573
2627
|
return {
|
|
2574
2628
|
id: docId,
|
|
2575
2629
|
title: `Design Document for ${requirements.length} Requirements`,
|
|
@@ -2623,8 +2677,57 @@ var init_design = __esm({
|
|
|
2623
2677
|
requirements
|
|
2624
2678
|
}));
|
|
2625
2679
|
}
|
|
2626
|
-
generateDescription(reqs) {
|
|
2627
|
-
|
|
2680
|
+
generateDescription(title, reqs, components) {
|
|
2681
|
+
const lines = [];
|
|
2682
|
+
lines.push(`Design for ${title}, realising ${reqs.length} requirement(s): ${reqs.map((r) => r.id).join(", ")}.`);
|
|
2683
|
+
lines.push("");
|
|
2684
|
+
lines.push("Responsibilities:");
|
|
2685
|
+
for (const r of reqs) {
|
|
2686
|
+
lines.push(`- ${r.id}: ${r.title || r.text}`);
|
|
2687
|
+
}
|
|
2688
|
+
lines.push("");
|
|
2689
|
+
lines.push("Components:");
|
|
2690
|
+
for (const c of components) {
|
|
2691
|
+
const sigs = c.methods.map((m) => `${m.name}()`).join(", ") || "(no operations inferred)";
|
|
2692
|
+
lines.push(`- ${c.name} \u2014 ${c.responsibility} [${sigs}]`);
|
|
2693
|
+
}
|
|
2694
|
+
return lines.join("\n");
|
|
2695
|
+
}
|
|
2696
|
+
deriveResponsibilities(reqs) {
|
|
2697
|
+
return reqs.map((r) => {
|
|
2698
|
+
const op = deriveOperation(r.text, r.title);
|
|
2699
|
+
return `${r.id}: ${op}${r.title ? ` \u2014 ${r.title}` : ""}`;
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
deriveComponents(reqs) {
|
|
2703
|
+
return reqs.map((r) => {
|
|
2704
|
+
const op = deriveOperation(r.text, r.title);
|
|
2705
|
+
const compName = this.pascal(r.title || op) + (/(service|manager|controller|repository)$/i.test(r.title) ? "" : "Service");
|
|
2706
|
+
return {
|
|
2707
|
+
name: compName,
|
|
2708
|
+
responsibility: r.title || `Handle ${r.id}`,
|
|
2709
|
+
methods: [{ name: op, params: "", returnType: "void" }],
|
|
2710
|
+
requirementIds: [r.id]
|
|
2711
|
+
};
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
deriveDataEntities(reqs) {
|
|
2715
|
+
const entities = /* @__PURE__ */ new Set();
|
|
2716
|
+
for (const req of reqs) {
|
|
2717
|
+
for (const m of (req.title ?? "").matchAll(/\b([A-Z][a-z]+)\b/g)) {
|
|
2718
|
+
if (!OPERATION_STOPWORDS.has(m[1].toLowerCase())) {
|
|
2719
|
+
entities.add(m[1]);
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return [...entities];
|
|
2724
|
+
}
|
|
2725
|
+
pascal(text) {
|
|
2726
|
+
const words = text.split(/[\s_\-,、]+/).filter(Boolean);
|
|
2727
|
+
if (words.length === 0) {
|
|
2728
|
+
return "Component";
|
|
2729
|
+
}
|
|
2730
|
+
return words.map((w) => w.replace(/[^A-Za-z0-9]/g, "")).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
2628
2731
|
}
|
|
2629
2732
|
suggestInterfaces(reqs) {
|
|
2630
2733
|
const interfaces = [];
|
|
@@ -4022,10 +4125,7 @@ var init_test_generator = __esm({
|
|
|
4022
4125
|
for (const cls of classes) {
|
|
4023
4126
|
const methods = this.extractMethods(sourceCode, cls);
|
|
4024
4127
|
const its = [
|
|
4025
|
-
|
|
4026
|
-
// TODO: implement
|
|
4027
|
-
expect(true).toBe(true);
|
|
4028
|
-
});`
|
|
4128
|
+
" it('should be instantiable', () => {\n // TODO: implement\n expect(true).toBe(true);\n });"
|
|
4029
4129
|
];
|
|
4030
4130
|
for (const m of methods) {
|
|
4031
4131
|
its.push(` it('${m}() should work', () => {
|
|
@@ -4093,17 +4193,19 @@ ${its.join("\n")}
|
|
|
4093
4193
|
*/
|
|
4094
4194
|
extractMethods(code, className) {
|
|
4095
4195
|
const start = code.search(new RegExp(`\\bclass\\s+${className}\\b`));
|
|
4096
|
-
if (start < 0)
|
|
4196
|
+
if (start < 0) {
|
|
4097
4197
|
return [];
|
|
4198
|
+
}
|
|
4098
4199
|
const open = code.indexOf("{", start);
|
|
4099
|
-
if (open < 0)
|
|
4200
|
+
if (open < 0) {
|
|
4100
4201
|
return [];
|
|
4202
|
+
}
|
|
4101
4203
|
let depth = 0;
|
|
4102
4204
|
let end = open;
|
|
4103
4205
|
for (let i = open; i < code.length; i++) {
|
|
4104
|
-
if (code[i] === "{")
|
|
4206
|
+
if (code[i] === "{") {
|
|
4105
4207
|
depth++;
|
|
4106
|
-
else if (code[i] === "}") {
|
|
4208
|
+
} else if (code[i] === "}") {
|
|
4107
4209
|
depth--;
|
|
4108
4210
|
if (depth === 0) {
|
|
4109
4211
|
end = i;
|
|
@@ -4120,10 +4222,12 @@ ${its.join("\n")}
|
|
|
4120
4222
|
while ((m = methodRe.exec(body)) !== null) {
|
|
4121
4223
|
const prefix = m[1];
|
|
4122
4224
|
const name = m[2];
|
|
4123
|
-
if (/\b(private|protected)\b/.test(prefix))
|
|
4225
|
+
if (/\b(private|protected)\b/.test(prefix)) {
|
|
4124
4226
|
continue;
|
|
4125
|
-
|
|
4227
|
+
}
|
|
4228
|
+
if (KEYWORDS3.has(name) || seen.has(name)) {
|
|
4126
4229
|
continue;
|
|
4230
|
+
}
|
|
4127
4231
|
seen.add(name);
|
|
4128
4232
|
methods.push(name);
|
|
4129
4233
|
}
|
|
@@ -5499,6 +5603,7 @@ __export(dist_exports, {
|
|
|
5499
5603
|
createTraceabilityManager: () => createTraceabilityManager,
|
|
5500
5604
|
createTraceabilityValidator: () => createTraceabilityValidator,
|
|
5501
5605
|
createUnitTestGenerator: () => createUnitTestGenerator,
|
|
5606
|
+
deriveOperation: () => deriveOperation,
|
|
5502
5607
|
formatError: () => formatError,
|
|
5503
5608
|
formatInfo: () => formatInfo,
|
|
5504
5609
|
formatSuccess: () => formatSuccess,
|
|
@@ -6167,11 +6272,13 @@ var init_dist3 = __esm({
|
|
|
6167
6272
|
// ../codegraph/dist/multi-lang-parser.js
|
|
6168
6273
|
function extractParams(sig) {
|
|
6169
6274
|
const match = sig.match(/\(([^)]*)\)/);
|
|
6170
|
-
if (!match)
|
|
6275
|
+
if (!match) {
|
|
6171
6276
|
return void 0;
|
|
6277
|
+
}
|
|
6172
6278
|
const inner = match[1].trim();
|
|
6173
|
-
if (!inner)
|
|
6279
|
+
if (!inner) {
|
|
6174
6280
|
return [];
|
|
6281
|
+
}
|
|
6175
6282
|
return inner.split(",").map((p) => p.trim()).filter(Boolean);
|
|
6176
6283
|
}
|
|
6177
6284
|
function getIndent(line) {
|
|
@@ -6269,8 +6376,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6269
6376
|
const line = lines[i];
|
|
6270
6377
|
const lineNum = i + 1;
|
|
6271
6378
|
const trimmed = line.trim();
|
|
6272
|
-
if (trimmed === "" || trimmed.startsWith("#"))
|
|
6379
|
+
if (trimmed === "" || trimmed.startsWith("#")) {
|
|
6273
6380
|
continue;
|
|
6381
|
+
}
|
|
6274
6382
|
const indent = getIndent(line);
|
|
6275
6383
|
const { closed } = tracker.processLine(line, lineNum);
|
|
6276
6384
|
for (const blk of closed) {
|
|
@@ -6347,14 +6455,16 @@ var init_multi_lang_parser = __esm({
|
|
|
6347
6455
|
const isMethod = parentNode !== void 0 && parentNode.type === "class";
|
|
6348
6456
|
const isConstructor = isMethod && name === "__init__";
|
|
6349
6457
|
const modifiers = [];
|
|
6350
|
-
if (isAsync)
|
|
6458
|
+
if (isAsync) {
|
|
6351
6459
|
modifiers.push("async");
|
|
6460
|
+
}
|
|
6352
6461
|
const consumedDecorators = pendingDecorators.splice(0);
|
|
6353
6462
|
for (const d of consumedDecorators) {
|
|
6354
6463
|
modifiers.push(`@${d.name}`);
|
|
6355
6464
|
}
|
|
6356
|
-
if (isConstructor)
|
|
6465
|
+
if (isConstructor) {
|
|
6357
6466
|
modifiers.push("constructor");
|
|
6467
|
+
}
|
|
6358
6468
|
const params = paramStr ? paramStr.split(",").map((p) => p.trim()).filter(Boolean) : [];
|
|
6359
6469
|
const node = {
|
|
6360
6470
|
type: isMethod ? "method" : "function",
|
|
@@ -6410,8 +6520,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6410
6520
|
const line = lines[i];
|
|
6411
6521
|
const lineNum = i + 1;
|
|
6412
6522
|
const trimmed = line.trim();
|
|
6413
|
-
if (trimmed === "" || trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
|
|
6523
|
+
if (trimmed === "" || trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*")) {
|
|
6414
6524
|
continue;
|
|
6525
|
+
}
|
|
6415
6526
|
const pkgMatch = trimmed.match(/^package\s+([\w.]+)\s*;/);
|
|
6416
6527
|
if (pkgMatch) {
|
|
6417
6528
|
continue;
|
|
@@ -6442,12 +6553,15 @@ var init_multi_lang_parser = __esm({
|
|
|
6442
6553
|
const kind = classMatch[4];
|
|
6443
6554
|
const name = classMatch[5];
|
|
6444
6555
|
const modifiers = [];
|
|
6445
|
-
if (vis)
|
|
6556
|
+
if (vis) {
|
|
6446
6557
|
modifiers.push(vis);
|
|
6447
|
-
|
|
6558
|
+
}
|
|
6559
|
+
if (mod1) {
|
|
6448
6560
|
modifiers.push(mod1);
|
|
6449
|
-
|
|
6561
|
+
}
|
|
6562
|
+
if (mod2) {
|
|
6450
6563
|
modifiers.push(mod2);
|
|
6564
|
+
}
|
|
6451
6565
|
const consumedAnnos = pendingAnnotations.splice(0);
|
|
6452
6566
|
for (const a of consumedAnnos) {
|
|
6453
6567
|
modifiers.push(`@${a.name}`);
|
|
@@ -6476,8 +6590,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6476
6590
|
if (closed2) {
|
|
6477
6591
|
for (const c of closed2) {
|
|
6478
6592
|
const n = blockNodeMap.get(c);
|
|
6479
|
-
if (n)
|
|
6593
|
+
if (n) {
|
|
6480
6594
|
n.endLine = lineNum;
|
|
6595
|
+
}
|
|
6481
6596
|
}
|
|
6482
6597
|
}
|
|
6483
6598
|
blockNodeMap.set(blk, node);
|
|
@@ -6495,14 +6610,18 @@ var init_multi_lang_parser = __esm({
|
|
|
6495
6610
|
const returnType = methodMatch[5];
|
|
6496
6611
|
const name = methodMatch[6];
|
|
6497
6612
|
const modifiers = [];
|
|
6498
|
-
if (vis)
|
|
6613
|
+
if (vis) {
|
|
6499
6614
|
modifiers.push(vis);
|
|
6500
|
-
|
|
6615
|
+
}
|
|
6616
|
+
if (isStatic) {
|
|
6501
6617
|
modifiers.push("static");
|
|
6502
|
-
|
|
6618
|
+
}
|
|
6619
|
+
if (mod1) {
|
|
6503
6620
|
modifiers.push(mod1);
|
|
6504
|
-
|
|
6621
|
+
}
|
|
6622
|
+
if (mod2) {
|
|
6505
6623
|
modifiers.push(mod2);
|
|
6624
|
+
}
|
|
6506
6625
|
const consumedAnnos = pendingAnnotations.splice(0);
|
|
6507
6626
|
for (const a of consumedAnnos) {
|
|
6508
6627
|
modifiers.push(`@${a.name}`);
|
|
@@ -6534,8 +6653,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6534
6653
|
if (closed2) {
|
|
6535
6654
|
for (const c of closed2) {
|
|
6536
6655
|
const n = blockNodeMap.get(c);
|
|
6537
|
-
if (n)
|
|
6656
|
+
if (n) {
|
|
6538
6657
|
n.endLine = lineNum;
|
|
6658
|
+
}
|
|
6539
6659
|
}
|
|
6540
6660
|
}
|
|
6541
6661
|
continue;
|
|
@@ -6546,8 +6666,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6546
6666
|
if (closed) {
|
|
6547
6667
|
for (const c of closed) {
|
|
6548
6668
|
const n = blockNodeMap.get(c);
|
|
6549
|
-
if (n)
|
|
6669
|
+
if (n) {
|
|
6550
6670
|
n.endLine = lineNum;
|
|
6671
|
+
}
|
|
6551
6672
|
}
|
|
6552
6673
|
}
|
|
6553
6674
|
}
|
|
@@ -6570,8 +6691,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6570
6691
|
const line = lines[i];
|
|
6571
6692
|
const lineNum = i + 1;
|
|
6572
6693
|
const trimmed = line.trim();
|
|
6573
|
-
if (trimmed === "" || trimmed.startsWith("//"))
|
|
6694
|
+
if (trimmed === "" || trimmed.startsWith("//")) {
|
|
6574
6695
|
continue;
|
|
6696
|
+
}
|
|
6575
6697
|
const pkgMatch = trimmed.match(/^package\s+(\w+)/);
|
|
6576
6698
|
if (pkgMatch) {
|
|
6577
6699
|
const node = {
|
|
@@ -6636,8 +6758,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6636
6758
|
if (closed2) {
|
|
6637
6759
|
for (const c of closed2) {
|
|
6638
6760
|
const n = blockNodeMap.get(c);
|
|
6639
|
-
if (n)
|
|
6761
|
+
if (n) {
|
|
6640
6762
|
n.endLine = lineNum;
|
|
6763
|
+
}
|
|
6641
6764
|
}
|
|
6642
6765
|
}
|
|
6643
6766
|
continue;
|
|
@@ -6668,8 +6791,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6668
6791
|
if (closed2) {
|
|
6669
6792
|
for (const c of closed2) {
|
|
6670
6793
|
const n = blockNodeMap.get(c);
|
|
6671
|
-
if (n)
|
|
6794
|
+
if (n) {
|
|
6672
6795
|
n.endLine = lineNum;
|
|
6796
|
+
}
|
|
6673
6797
|
}
|
|
6674
6798
|
}
|
|
6675
6799
|
continue;
|
|
@@ -6692,8 +6816,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6692
6816
|
if (closed2) {
|
|
6693
6817
|
for (const c of closed2) {
|
|
6694
6818
|
const n = blockNodeMap.get(c);
|
|
6695
|
-
if (n)
|
|
6819
|
+
if (n) {
|
|
6696
6820
|
n.endLine = lineNum;
|
|
6821
|
+
}
|
|
6697
6822
|
}
|
|
6698
6823
|
}
|
|
6699
6824
|
continue;
|
|
@@ -6741,8 +6866,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6741
6866
|
if (closed2) {
|
|
6742
6867
|
for (const c of closed2) {
|
|
6743
6868
|
const n = blockNodeMap.get(c);
|
|
6744
|
-
if (n)
|
|
6869
|
+
if (n) {
|
|
6745
6870
|
n.endLine = lineNum;
|
|
6871
|
+
}
|
|
6746
6872
|
}
|
|
6747
6873
|
}
|
|
6748
6874
|
continue;
|
|
@@ -6782,8 +6908,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6782
6908
|
if (closed2) {
|
|
6783
6909
|
for (const c of closed2) {
|
|
6784
6910
|
const n = blockNodeMap.get(c);
|
|
6785
|
-
if (n)
|
|
6911
|
+
if (n) {
|
|
6786
6912
|
n.endLine = lineNum;
|
|
6913
|
+
}
|
|
6787
6914
|
}
|
|
6788
6915
|
}
|
|
6789
6916
|
continue;
|
|
@@ -6806,8 +6933,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6806
6933
|
if (closed2) {
|
|
6807
6934
|
for (const c of closed2) {
|
|
6808
6935
|
const n = blockNodeMap.get(c);
|
|
6809
|
-
if (n)
|
|
6936
|
+
if (n) {
|
|
6810
6937
|
n.endLine = lineNum;
|
|
6938
|
+
}
|
|
6811
6939
|
}
|
|
6812
6940
|
}
|
|
6813
6941
|
continue;
|
|
@@ -6816,8 +6944,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6816
6944
|
if (closed) {
|
|
6817
6945
|
for (const c of closed) {
|
|
6818
6946
|
const n = blockNodeMap.get(c);
|
|
6819
|
-
if (n)
|
|
6947
|
+
if (n) {
|
|
6820
6948
|
n.endLine = lineNum;
|
|
6949
|
+
}
|
|
6821
6950
|
}
|
|
6822
6951
|
}
|
|
6823
6952
|
}
|
|
@@ -6840,8 +6969,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6840
6969
|
const line = lines[i];
|
|
6841
6970
|
const lineNum = i + 1;
|
|
6842
6971
|
const trimmed = line.trim();
|
|
6843
|
-
if (trimmed === "" || trimmed.startsWith("//"))
|
|
6972
|
+
if (trimmed === "" || trimmed.startsWith("//")) {
|
|
6844
6973
|
continue;
|
|
6974
|
+
}
|
|
6845
6975
|
const attrMatch = trimmed.match(/^#\[(\w+(?:\([^)]*\))?)\]/);
|
|
6846
6976
|
if (attrMatch && !trimmed.match(/^#\[.*\]\s*(?:pub\s+)?(?:fn|struct|enum|trait|mod|impl)/)) {
|
|
6847
6977
|
pendingAttrs.push({ name: attrMatch[1], line: lineNum });
|
|
@@ -6870,8 +7000,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6870
7000
|
const name = modMatch[1];
|
|
6871
7001
|
const modifiers = trimmed.startsWith("pub") ? ["pub"] : [];
|
|
6872
7002
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
6873
|
-
for (const a of consumedAttrs)
|
|
7003
|
+
for (const a of consumedAttrs) {
|
|
6874
7004
|
modifiers.push(`#[${a.name}]`);
|
|
7005
|
+
}
|
|
6875
7006
|
const node = {
|
|
6876
7007
|
type: "module",
|
|
6877
7008
|
name,
|
|
@@ -6889,8 +7020,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6889
7020
|
if (closed2) {
|
|
6890
7021
|
for (const c of closed2) {
|
|
6891
7022
|
const n = blockNodeMap.get(c);
|
|
6892
|
-
if (n)
|
|
7023
|
+
if (n) {
|
|
6893
7024
|
n.endLine = lineNum;
|
|
7025
|
+
}
|
|
6894
7026
|
}
|
|
6895
7027
|
}
|
|
6896
7028
|
continue;
|
|
@@ -6900,8 +7032,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6900
7032
|
const name = structMatch[1];
|
|
6901
7033
|
const modifiers = trimmed.match(/^pub/) ? ["pub"] : [];
|
|
6902
7034
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
6903
|
-
for (const a of consumedAttrs)
|
|
7035
|
+
for (const a of consumedAttrs) {
|
|
6904
7036
|
modifiers.push(`#[${a.name}]`);
|
|
7037
|
+
}
|
|
6905
7038
|
const parentBlock = tracker.getCurrentBlock();
|
|
6906
7039
|
const parentNode = parentBlock ? blockNodeMap.get(parentBlock) : void 0;
|
|
6907
7040
|
const node = {
|
|
@@ -6932,8 +7065,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6932
7065
|
if (closed2) {
|
|
6933
7066
|
for (const c of closed2) {
|
|
6934
7067
|
const n = blockNodeMap.get(c);
|
|
6935
|
-
if (n)
|
|
7068
|
+
if (n) {
|
|
6936
7069
|
n.endLine = lineNum;
|
|
7070
|
+
}
|
|
6937
7071
|
}
|
|
6938
7072
|
}
|
|
6939
7073
|
continue;
|
|
@@ -6943,8 +7077,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6943
7077
|
const name = enumMatch[1];
|
|
6944
7078
|
const modifiers = trimmed.match(/^pub/) ? ["pub"] : [];
|
|
6945
7079
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
6946
|
-
for (const a of consumedAttrs)
|
|
7080
|
+
for (const a of consumedAttrs) {
|
|
6947
7081
|
modifiers.push(`#[${a.name}]`);
|
|
7082
|
+
}
|
|
6948
7083
|
const node = {
|
|
6949
7084
|
type: "enum",
|
|
6950
7085
|
name,
|
|
@@ -6968,8 +7103,9 @@ var init_multi_lang_parser = __esm({
|
|
|
6968
7103
|
if (closed2) {
|
|
6969
7104
|
for (const c of closed2) {
|
|
6970
7105
|
const n = blockNodeMap.get(c);
|
|
6971
|
-
if (n)
|
|
7106
|
+
if (n) {
|
|
6972
7107
|
n.endLine = lineNum;
|
|
7108
|
+
}
|
|
6973
7109
|
}
|
|
6974
7110
|
}
|
|
6975
7111
|
continue;
|
|
@@ -6978,11 +7114,13 @@ var init_multi_lang_parser = __esm({
|
|
|
6978
7114
|
if (traitMatch) {
|
|
6979
7115
|
const name = traitMatch[1];
|
|
6980
7116
|
const modifiers = trimmed.match(/^pub/) ? ["pub"] : [];
|
|
6981
|
-
if (trimmed.includes("unsafe"))
|
|
7117
|
+
if (trimmed.includes("unsafe")) {
|
|
6982
7118
|
modifiers.push("unsafe");
|
|
7119
|
+
}
|
|
6983
7120
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
6984
|
-
for (const a of consumedAttrs)
|
|
7121
|
+
for (const a of consumedAttrs) {
|
|
6985
7122
|
modifiers.push(`#[${a.name}]`);
|
|
7123
|
+
}
|
|
6986
7124
|
const node = {
|
|
6987
7125
|
type: "trait",
|
|
6988
7126
|
name,
|
|
@@ -7000,8 +7138,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7000
7138
|
if (closed2) {
|
|
7001
7139
|
for (const c of closed2) {
|
|
7002
7140
|
const n = blockNodeMap.get(c);
|
|
7003
|
-
if (n)
|
|
7141
|
+
if (n) {
|
|
7004
7142
|
n.endLine = lineNum;
|
|
7143
|
+
}
|
|
7005
7144
|
}
|
|
7006
7145
|
}
|
|
7007
7146
|
continue;
|
|
@@ -7012,11 +7151,13 @@ var init_multi_lang_parser = __esm({
|
|
|
7012
7151
|
const typeName = implMatch[2];
|
|
7013
7152
|
const name = traitName ? `${traitName} for ${typeName}` : typeName;
|
|
7014
7153
|
const modifiers = [];
|
|
7015
|
-
if (traitName)
|
|
7154
|
+
if (traitName) {
|
|
7016
7155
|
modifiers.push("impl_trait");
|
|
7156
|
+
}
|
|
7017
7157
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
7018
|
-
for (const a of consumedAttrs)
|
|
7158
|
+
for (const a of consumedAttrs) {
|
|
7019
7159
|
modifiers.push(`#[${a.name}]`);
|
|
7160
|
+
}
|
|
7020
7161
|
const node = {
|
|
7021
7162
|
type: "class",
|
|
7022
7163
|
// impl blocks act like class extensions
|
|
@@ -7035,8 +7176,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7035
7176
|
if (closed2) {
|
|
7036
7177
|
for (const c of closed2) {
|
|
7037
7178
|
const n = blockNodeMap.get(c);
|
|
7038
|
-
if (n)
|
|
7179
|
+
if (n) {
|
|
7039
7180
|
n.endLine = lineNum;
|
|
7181
|
+
}
|
|
7040
7182
|
}
|
|
7041
7183
|
}
|
|
7042
7184
|
continue;
|
|
@@ -7049,15 +7191,19 @@ var init_multi_lang_parser = __esm({
|
|
|
7049
7191
|
const paramStr = fnMatch[4];
|
|
7050
7192
|
const retType = fnMatch[5]?.trim().replace(/\{$/, "").trim();
|
|
7051
7193
|
const modifiers = [];
|
|
7052
|
-
if (trimmed.match(/^pub/))
|
|
7194
|
+
if (trimmed.match(/^pub/)) {
|
|
7053
7195
|
modifiers.push("pub");
|
|
7054
|
-
|
|
7196
|
+
}
|
|
7197
|
+
if (isAsync) {
|
|
7055
7198
|
modifiers.push("async");
|
|
7056
|
-
|
|
7199
|
+
}
|
|
7200
|
+
if (isUnsafe) {
|
|
7057
7201
|
modifiers.push("unsafe");
|
|
7202
|
+
}
|
|
7058
7203
|
const consumedAttrs = pendingAttrs.splice(0);
|
|
7059
|
-
for (const a of consumedAttrs)
|
|
7204
|
+
for (const a of consumedAttrs) {
|
|
7060
7205
|
modifiers.push(`#[${a.name}]`);
|
|
7206
|
+
}
|
|
7061
7207
|
const params = paramStr ? paramStr.split(",").map((p) => p.trim()).filter(Boolean) : [];
|
|
7062
7208
|
const parentBlock = tracker.getCurrentBlock();
|
|
7063
7209
|
const parentNode = parentBlock ? blockNodeMap.get(parentBlock) : void 0;
|
|
@@ -7092,8 +7238,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7092
7238
|
if (closed2) {
|
|
7093
7239
|
for (const c of closed2) {
|
|
7094
7240
|
const n = blockNodeMap.get(c);
|
|
7095
|
-
if (n)
|
|
7241
|
+
if (n) {
|
|
7096
7242
|
n.endLine = lineNum;
|
|
7243
|
+
}
|
|
7097
7244
|
}
|
|
7098
7245
|
}
|
|
7099
7246
|
continue;
|
|
@@ -7103,8 +7250,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7103
7250
|
if (closed) {
|
|
7104
7251
|
for (const c of closed) {
|
|
7105
7252
|
const n = blockNodeMap.get(c);
|
|
7106
|
-
if (n)
|
|
7253
|
+
if (n) {
|
|
7107
7254
|
n.endLine = lineNum;
|
|
7255
|
+
}
|
|
7108
7256
|
}
|
|
7109
7257
|
}
|
|
7110
7258
|
}
|
|
@@ -7125,8 +7273,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7125
7273
|
const line = lines[i];
|
|
7126
7274
|
const lineNum = i + 1;
|
|
7127
7275
|
const trimmed = line.trim();
|
|
7128
|
-
if (trimmed === "" || trimmed.startsWith("#"))
|
|
7276
|
+
if (trimmed === "" || trimmed.startsWith("#")) {
|
|
7129
7277
|
continue;
|
|
7278
|
+
}
|
|
7130
7279
|
const reqMatch = trimmed.match(/^require(?:_relative)?\s+['"](.[^'"]*)['"]/);
|
|
7131
7280
|
if (reqMatch) {
|
|
7132
7281
|
imports.push({
|
|
@@ -7220,8 +7369,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7220
7369
|
const name = defMatch[2];
|
|
7221
7370
|
const paramStr = defMatch[3];
|
|
7222
7371
|
const modifiers = [];
|
|
7223
|
-
if (isSelf)
|
|
7372
|
+
if (isSelf) {
|
|
7224
7373
|
modifiers.push("static");
|
|
7374
|
+
}
|
|
7225
7375
|
const params = paramStr ? paramStr.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
7226
7376
|
const parentBlock = blockStack.length > 0 ? blockStack[blockStack.length - 1] : void 0;
|
|
7227
7377
|
const isMethod = parentBlock !== void 0 && (parentBlock.type === "class" || parentBlock.type === "module");
|
|
@@ -7295,8 +7445,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7295
7445
|
const line = lines[i];
|
|
7296
7446
|
const lineNum = i + 1;
|
|
7297
7447
|
const trimmed = line.trim();
|
|
7298
|
-
if (trimmed === "" || trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*") || trimmed === "<?php")
|
|
7448
|
+
if (trimmed === "" || trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*") || trimmed === "<?php") {
|
|
7299
7449
|
continue;
|
|
7450
|
+
}
|
|
7300
7451
|
const nsMatch = trimmed.match(/^namespace\s+([\w\\]+)\s*;/);
|
|
7301
7452
|
if (nsMatch) {
|
|
7302
7453
|
const node = {
|
|
@@ -7329,10 +7480,12 @@ var init_multi_lang_parser = __esm({
|
|
|
7329
7480
|
const kind = classMatch[3];
|
|
7330
7481
|
const name = classMatch[4];
|
|
7331
7482
|
const modifiers = [];
|
|
7332
|
-
if (mod1)
|
|
7483
|
+
if (mod1) {
|
|
7333
7484
|
modifiers.push(mod1);
|
|
7334
|
-
|
|
7485
|
+
}
|
|
7486
|
+
if (mod2) {
|
|
7335
7487
|
modifiers.push(mod2);
|
|
7488
|
+
}
|
|
7336
7489
|
const type = kind === "interface" ? "interface" : kind === "trait" ? "trait" : kind === "enum" ? "enum" : "class";
|
|
7337
7490
|
const parentBlock = tracker.getCurrentBlock();
|
|
7338
7491
|
const parentNode = parentBlock ? blockNodeMap.get(parentBlock) : void 0;
|
|
@@ -7358,8 +7511,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7358
7511
|
if (closed2) {
|
|
7359
7512
|
for (const c of closed2) {
|
|
7360
7513
|
const n = blockNodeMap.get(c);
|
|
7361
|
-
if (n)
|
|
7514
|
+
if (n) {
|
|
7362
7515
|
n.endLine = lineNum;
|
|
7516
|
+
}
|
|
7363
7517
|
}
|
|
7364
7518
|
}
|
|
7365
7519
|
continue;
|
|
@@ -7372,10 +7526,12 @@ var init_multi_lang_parser = __esm({
|
|
|
7372
7526
|
const paramStr = funcMatch[4];
|
|
7373
7527
|
const retType = funcMatch[5]?.trim().replace(/\{$/, "").trim();
|
|
7374
7528
|
const modifiers = [];
|
|
7375
|
-
if (vis)
|
|
7529
|
+
if (vis) {
|
|
7376
7530
|
modifiers.push(vis);
|
|
7377
|
-
|
|
7531
|
+
}
|
|
7532
|
+
if (isStatic) {
|
|
7378
7533
|
modifiers.push("static");
|
|
7534
|
+
}
|
|
7379
7535
|
const params = paramStr ? paramStr.split(",").map((p) => p.trim()).filter(Boolean) : [];
|
|
7380
7536
|
const parentBlock = tracker.getCurrentBlock();
|
|
7381
7537
|
const parentNode = parentBlock ? blockNodeMap.get(parentBlock) : void 0;
|
|
@@ -7410,8 +7566,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7410
7566
|
if (closed2) {
|
|
7411
7567
|
for (const c of closed2) {
|
|
7412
7568
|
const n = blockNodeMap.get(c);
|
|
7413
|
-
if (n)
|
|
7569
|
+
if (n) {
|
|
7414
7570
|
n.endLine = lineNum;
|
|
7571
|
+
}
|
|
7415
7572
|
}
|
|
7416
7573
|
}
|
|
7417
7574
|
continue;
|
|
@@ -7424,12 +7581,15 @@ var init_multi_lang_parser = __esm({
|
|
|
7424
7581
|
const name = propMatch[4];
|
|
7425
7582
|
if (vis || isStatic || isReadonly) {
|
|
7426
7583
|
const modifiers = [];
|
|
7427
|
-
if (vis)
|
|
7584
|
+
if (vis) {
|
|
7428
7585
|
modifiers.push(vis);
|
|
7429
|
-
|
|
7586
|
+
}
|
|
7587
|
+
if (isStatic) {
|
|
7430
7588
|
modifiers.push("static");
|
|
7431
|
-
|
|
7589
|
+
}
|
|
7590
|
+
if (isReadonly) {
|
|
7432
7591
|
modifiers.push("readonly");
|
|
7592
|
+
}
|
|
7433
7593
|
const parentBlock = tracker.getCurrentBlock();
|
|
7434
7594
|
const parentNode = parentBlock ? blockNodeMap.get(parentBlock) : void 0;
|
|
7435
7595
|
const node = {
|
|
@@ -7453,8 +7613,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7453
7613
|
if (closed) {
|
|
7454
7614
|
for (const c of closed) {
|
|
7455
7615
|
const n = blockNodeMap.get(c);
|
|
7456
|
-
if (n)
|
|
7616
|
+
if (n) {
|
|
7457
7617
|
n.endLine = lineNum;
|
|
7618
|
+
}
|
|
7458
7619
|
}
|
|
7459
7620
|
}
|
|
7460
7621
|
}
|
|
@@ -7471,8 +7632,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7471
7632
|
}
|
|
7472
7633
|
parse(source, language) {
|
|
7473
7634
|
const parser = this.parsers.get(language);
|
|
7474
|
-
if (!parser)
|
|
7635
|
+
if (!parser) {
|
|
7475
7636
|
return this.fallbackParse(source, language);
|
|
7637
|
+
}
|
|
7476
7638
|
return parser.parse(source);
|
|
7477
7639
|
}
|
|
7478
7640
|
getSupportedLanguages() {
|
|
@@ -7510,8 +7672,9 @@ var init_multi_lang_parser = __esm({
|
|
|
7510
7672
|
const line = lines[i];
|
|
7511
7673
|
const lineNum = i + 1;
|
|
7512
7674
|
const trimmed = line.trim();
|
|
7513
|
-
if (trimmed === "")
|
|
7675
|
+
if (trimmed === "") {
|
|
7514
7676
|
continue;
|
|
7677
|
+
}
|
|
7515
7678
|
for (const { type, regex } of patterns) {
|
|
7516
7679
|
const match = regex.exec(trimmed);
|
|
7517
7680
|
if (match) {
|
|
@@ -7637,19 +7800,22 @@ function stripCommentsAndStrings(source, language) {
|
|
|
7637
7800
|
const c = source[i];
|
|
7638
7801
|
const next = i + 1 < n ? source[i + 1] : "";
|
|
7639
7802
|
if (c === "/" && next === "/") {
|
|
7640
|
-
while (i < n && source[i] !== "\n")
|
|
7803
|
+
while (i < n && source[i] !== "\n") {
|
|
7641
7804
|
i++;
|
|
7805
|
+
}
|
|
7642
7806
|
continue;
|
|
7643
7807
|
}
|
|
7644
7808
|
if (hashComments && c === "#") {
|
|
7645
|
-
while (i < n && source[i] !== "\n")
|
|
7809
|
+
while (i < n && source[i] !== "\n") {
|
|
7646
7810
|
i++;
|
|
7811
|
+
}
|
|
7647
7812
|
continue;
|
|
7648
7813
|
}
|
|
7649
7814
|
if (c === "/" && next === "*") {
|
|
7650
7815
|
i += 2;
|
|
7651
|
-
while (i < n && !(source[i] === "*" && source[i + 1] === "/"))
|
|
7816
|
+
while (i < n && !(source[i] === "*" && source[i + 1] === "/")) {
|
|
7652
7817
|
i++;
|
|
7818
|
+
}
|
|
7653
7819
|
i += 2;
|
|
7654
7820
|
continue;
|
|
7655
7821
|
}
|
|
@@ -7657,8 +7823,9 @@ function stripCommentsAndStrings(source, language) {
|
|
|
7657
7823
|
const quote = c;
|
|
7658
7824
|
i++;
|
|
7659
7825
|
while (i < n && source[i] !== quote) {
|
|
7660
|
-
if (source[i] === "\\")
|
|
7826
|
+
if (source[i] === "\\") {
|
|
7661
7827
|
i++;
|
|
7828
|
+
}
|
|
7662
7829
|
i++;
|
|
7663
7830
|
}
|
|
7664
7831
|
i++;
|
|
@@ -7897,8 +8064,9 @@ var init_dist4 = __esm({
|
|
|
7897
8064
|
const nextNonEmptyIsBrace = (from) => {
|
|
7898
8065
|
for (let j = from; j < lines.length && j < from + 3; j++) {
|
|
7899
8066
|
const t = lines[j].trim();
|
|
7900
|
-
if (t === "")
|
|
8067
|
+
if (t === "") {
|
|
7901
8068
|
continue;
|
|
8069
|
+
}
|
|
7902
8070
|
return t.startsWith("{");
|
|
7903
8071
|
}
|
|
7904
8072
|
return false;
|
|
@@ -7958,8 +8126,9 @@ var init_dist4 = __esm({
|
|
|
7958
8126
|
const nodes = [];
|
|
7959
8127
|
for (const statement of sourceFile.statements) {
|
|
7960
8128
|
const node = this.visitTsNode(statement, sourceFile);
|
|
7961
|
-
if (node)
|
|
8129
|
+
if (node) {
|
|
7962
8130
|
nodes.push(node);
|
|
8131
|
+
}
|
|
7963
8132
|
}
|
|
7964
8133
|
return nodes;
|
|
7965
8134
|
}
|
|
@@ -8091,8 +8260,9 @@ var init_dist4 = __esm({
|
|
|
8091
8260
|
let m;
|
|
8092
8261
|
while ((m = re.exec(cleaned)) !== null) {
|
|
8093
8262
|
const name = m[1];
|
|
8094
|
-
if (!KW.has(name))
|
|
8263
|
+
if (!KW.has(name)) {
|
|
8095
8264
|
out.add(name);
|
|
8265
|
+
}
|
|
8096
8266
|
}
|
|
8097
8267
|
return [...out];
|
|
8098
8268
|
}
|
|
@@ -8307,11 +8477,13 @@ function escapeRe(s) {
|
|
|
8307
8477
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8308
8478
|
}
|
|
8309
8479
|
function shannonEntropy(s) {
|
|
8310
|
-
if (s.length === 0)
|
|
8480
|
+
if (s.length === 0) {
|
|
8311
8481
|
return 0;
|
|
8482
|
+
}
|
|
8312
8483
|
const freq = /* @__PURE__ */ new Map();
|
|
8313
|
-
for (const ch of s)
|
|
8484
|
+
for (const ch of s) {
|
|
8314
8485
|
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
8486
|
+
}
|
|
8315
8487
|
let h = 0;
|
|
8316
8488
|
for (const n of freq.values()) {
|
|
8317
8489
|
const p = n / s.length;
|
|
@@ -8323,8 +8495,9 @@ function hasSequentialRun(s, len = 6) {
|
|
|
8323
8495
|
let run = 1;
|
|
8324
8496
|
for (let i = 1; i < s.length; i++) {
|
|
8325
8497
|
if (s.charCodeAt(i) === s.charCodeAt(i - 1) + 1) {
|
|
8326
|
-
if (++run >= len)
|
|
8498
|
+
if (++run >= len) {
|
|
8327
8499
|
return true;
|
|
8500
|
+
}
|
|
8328
8501
|
} else {
|
|
8329
8502
|
run = 1;
|
|
8330
8503
|
}
|
|
@@ -8333,45 +8506,58 @@ function hasSequentialRun(s, len = 6) {
|
|
|
8333
8506
|
}
|
|
8334
8507
|
function isLikelySecret(raw) {
|
|
8335
8508
|
const s = raw.replace(/^['"]|['"]$/g, "");
|
|
8336
|
-
if (!/[0-9]/.test(s) || !/[a-zA-Z]/.test(s))
|
|
8509
|
+
if (!/[0-9]/.test(s) || !/[a-zA-Z]/.test(s)) {
|
|
8337
8510
|
return false;
|
|
8338
|
-
|
|
8511
|
+
}
|
|
8512
|
+
if (shannonEntropy(s) < 3) {
|
|
8339
8513
|
return false;
|
|
8340
|
-
|
|
8514
|
+
}
|
|
8515
|
+
if (hasSequentialRun(s)) {
|
|
8341
8516
|
return false;
|
|
8342
|
-
|
|
8517
|
+
}
|
|
8518
|
+
if (/^[0-9a-f]{32}$|^[0-9a-f]{40}$|^[0-9a-f]{64}$|^[0-9a-f]{128}$/.test(s)) {
|
|
8343
8519
|
return false;
|
|
8520
|
+
}
|
|
8344
8521
|
return true;
|
|
8345
8522
|
}
|
|
8346
8523
|
function isNotFormatMarker(matchText) {
|
|
8347
8524
|
const lit = matchText.match(/['"]([^'"]*)['"]\s*$/)?.[1] ?? "";
|
|
8348
|
-
if (/^\{[^}]*\}$/.test(lit))
|
|
8525
|
+
if (/^\{[^}]*\}$/.test(lit)) {
|
|
8349
8526
|
return false;
|
|
8350
|
-
|
|
8527
|
+
}
|
|
8528
|
+
if (lit.trim().length < 3) {
|
|
8351
8529
|
return false;
|
|
8352
|
-
|
|
8530
|
+
}
|
|
8531
|
+
if (/%\(?\w*\)?[sd]|%[sd]|\$\{[^}]*\}|#\{[^}]*\}|\{\d*\}|:\w+\b/.test(lit)) {
|
|
8353
8532
|
return false;
|
|
8354
|
-
|
|
8533
|
+
}
|
|
8534
|
+
if (/^--?[\w-]+=?$/.test(lit.trim())) {
|
|
8355
8535
|
return false;
|
|
8356
|
-
|
|
8536
|
+
}
|
|
8537
|
+
if (/\$\w|\.\$/.test(lit)) {
|
|
8357
8538
|
return false;
|
|
8539
|
+
}
|
|
8358
8540
|
return true;
|
|
8359
8541
|
}
|
|
8360
8542
|
function isNotUrlPlaceholder(matchText) {
|
|
8361
8543
|
const pass = matchText.match(/:\/\/[^:@/]+:([^:@/]+)@/)?.[1] ?? "";
|
|
8362
|
-
if (/^(pass(word)?|secret|changeme|example|xxx+|\*+|test)$/i.test(pass))
|
|
8544
|
+
if (/^(pass(word)?|secret|changeme|example|xxx+|\*+|test)$/i.test(pass)) {
|
|
8363
8545
|
return false;
|
|
8364
|
-
|
|
8546
|
+
}
|
|
8547
|
+
if (/[$#]\{|<|%s|:\w+$/.test(pass)) {
|
|
8365
8548
|
return false;
|
|
8549
|
+
}
|
|
8366
8550
|
return true;
|
|
8367
8551
|
}
|
|
8368
8552
|
function blankNonCode(code, hashComments) {
|
|
8369
8553
|
const out = code.split("");
|
|
8370
8554
|
const n = code.length;
|
|
8371
8555
|
const blank = (from, to) => {
|
|
8372
|
-
for (let k = from; k < to && k < n; k++)
|
|
8373
|
-
if (out[k] !== "\n")
|
|
8556
|
+
for (let k = from; k < to && k < n; k++) {
|
|
8557
|
+
if (out[k] !== "\n") {
|
|
8374
8558
|
out[k] = " ";
|
|
8559
|
+
}
|
|
8560
|
+
}
|
|
8375
8561
|
};
|
|
8376
8562
|
let i = 0;
|
|
8377
8563
|
while (i < n) {
|
|
@@ -8379,24 +8565,27 @@ function blankNonCode(code, hashComments) {
|
|
|
8379
8565
|
const next = i + 1 < n ? code[i + 1] : "";
|
|
8380
8566
|
if (c === "/" && next === "/") {
|
|
8381
8567
|
let j = i;
|
|
8382
|
-
while (j < n && code[j] !== "\n")
|
|
8568
|
+
while (j < n && code[j] !== "\n") {
|
|
8383
8569
|
j++;
|
|
8570
|
+
}
|
|
8384
8571
|
blank(i, j);
|
|
8385
8572
|
i = j;
|
|
8386
8573
|
continue;
|
|
8387
8574
|
}
|
|
8388
8575
|
if (hashComments && c === "#") {
|
|
8389
8576
|
let j = i;
|
|
8390
|
-
while (j < n && code[j] !== "\n")
|
|
8577
|
+
while (j < n && code[j] !== "\n") {
|
|
8391
8578
|
j++;
|
|
8579
|
+
}
|
|
8392
8580
|
blank(i, j);
|
|
8393
8581
|
i = j;
|
|
8394
8582
|
continue;
|
|
8395
8583
|
}
|
|
8396
8584
|
if (c === "/" && next === "*") {
|
|
8397
8585
|
let j = i + 2;
|
|
8398
|
-
while (j < n && !(code[j] === "*" && code[j + 1] === "/"))
|
|
8586
|
+
while (j < n && !(code[j] === "*" && code[j + 1] === "/")) {
|
|
8399
8587
|
j++;
|
|
8588
|
+
}
|
|
8400
8589
|
j = Math.min(j + 2, n);
|
|
8401
8590
|
blank(i, j);
|
|
8402
8591
|
i = j;
|
|
@@ -8406,8 +8595,9 @@ function blankNonCode(code, hashComments) {
|
|
|
8406
8595
|
const q = c;
|
|
8407
8596
|
let j = i + 1;
|
|
8408
8597
|
while (j < n && code[j] !== q) {
|
|
8409
|
-
if (code[j] === "\\")
|
|
8598
|
+
if (code[j] === "\\") {
|
|
8410
8599
|
j++;
|
|
8600
|
+
}
|
|
8411
8601
|
j++;
|
|
8412
8602
|
}
|
|
8413
8603
|
blank(i + 1, j);
|
|
@@ -8424,8 +8614,9 @@ function runPatterns(patterns, code, filePath, snippetSource = code) {
|
|
|
8424
8614
|
const regex = new RegExp(p.regex.source, p.regex.flags);
|
|
8425
8615
|
let match;
|
|
8426
8616
|
while ((match = regex.exec(code)) !== null) {
|
|
8427
|
-
if (p.validate && !p.validate(match[0]))
|
|
8617
|
+
if (p.validate && !p.validate(match[0])) {
|
|
8428
8618
|
continue;
|
|
8619
|
+
}
|
|
8429
8620
|
const line = getLineNumber(code, match.index);
|
|
8430
8621
|
findings.push({
|
|
8431
8622
|
type: p.type,
|
|
@@ -8531,7 +8722,7 @@ var init_dist5 = __esm({
|
|
|
8531
8722
|
},
|
|
8532
8723
|
{
|
|
8533
8724
|
// Google API key.
|
|
8534
|
-
regex: /\bAIza[A-Za-z0-9_
|
|
8725
|
+
regex: /\bAIza[A-Za-z0-9_-]{35}\b/g,
|
|
8535
8726
|
severity: "high",
|
|
8536
8727
|
type: "secret-leak",
|
|
8537
8728
|
description: "Google API key detected",
|
|
@@ -8809,10 +9000,12 @@ var init_dist5 = __esm({
|
|
|
8809
9000
|
*/
|
|
8810
9001
|
static SANITIZERS = /\b(?:shlex\.quote|pipes\.quote|escapeshellarg|escapeshellcmd|mysqli_real_escape_string|real_escape_string|pg_escape_(?:string|literal|identifier)|quote_ident(?:ifier)?|re\.escape|html\.escape|htmlspecialchars|htmlentities|int|float|Number|parseInt|parseFloat|Integer\.parseInt)\s*\(/;
|
|
8811
9002
|
isDynamicRhs(rhs) {
|
|
8812
|
-
if (/^\s*\[/.test(rhs))
|
|
9003
|
+
if (/^\s*\[/.test(rhs)) {
|
|
8813
9004
|
return false;
|
|
8814
|
-
|
|
9005
|
+
}
|
|
9006
|
+
if (_TaintDataflowAnalyzer.SANITIZERS.test(rhs)) {
|
|
8815
9007
|
return false;
|
|
9008
|
+
}
|
|
8816
9009
|
return /\.\s*format\s*\(/.test(rhs) || // "…".format(x)
|
|
8817
9010
|
/\bf['"]/.test(rhs) || // f-string
|
|
8818
9011
|
/['"]\s*%\s*[\w([]/.test(rhs) || // "…" % x
|
|
@@ -8829,12 +9022,14 @@ var init_dist5 = __esm({
|
|
|
8829
9022
|
let changed = false;
|
|
8830
9023
|
lines.forEach((line, i) => {
|
|
8831
9024
|
const m = assignRe.exec(line);
|
|
8832
|
-
if (!m)
|
|
9025
|
+
if (!m) {
|
|
8833
9026
|
return;
|
|
9027
|
+
}
|
|
8834
9028
|
const name = m[1];
|
|
8835
9029
|
const rhs = m[2];
|
|
8836
|
-
if (tainted.has(name))
|
|
9030
|
+
if (tainted.has(name)) {
|
|
8837
9031
|
return;
|
|
9032
|
+
}
|
|
8838
9033
|
let taint = this.isDynamicRhs(rhs);
|
|
8839
9034
|
if (!taint && !_TaintDataflowAnalyzer.SANITIZERS.test(rhs)) {
|
|
8840
9035
|
for (const t of tainted.keys()) {
|
|
@@ -8849,11 +9044,13 @@ var init_dist5 = __esm({
|
|
|
8849
9044
|
changed = true;
|
|
8850
9045
|
}
|
|
8851
9046
|
});
|
|
8852
|
-
if (!changed)
|
|
9047
|
+
if (!changed) {
|
|
8853
9048
|
break;
|
|
9049
|
+
}
|
|
8854
9050
|
}
|
|
8855
|
-
if (tainted.size === 0)
|
|
9051
|
+
if (tainted.size === 0) {
|
|
8856
9052
|
return [];
|
|
9053
|
+
}
|
|
8857
9054
|
const findings = [];
|
|
8858
9055
|
const seen = /* @__PURE__ */ new Set();
|
|
8859
9056
|
lines.forEach((line, i) => {
|
|
@@ -8863,11 +9060,13 @@ var init_dist5 = __esm({
|
|
|
8863
9060
|
while ((m = re.exec(line)) !== null) {
|
|
8864
9061
|
const arg = m[1];
|
|
8865
9062
|
const def = tainted.get(arg);
|
|
8866
|
-
if (def === void 0 || def >= i + 1)
|
|
9063
|
+
if (def === void 0 || def >= i + 1) {
|
|
8867
9064
|
continue;
|
|
9065
|
+
}
|
|
8868
9066
|
const key = `${i}:${arg}`;
|
|
8869
|
-
if (seen.has(key))
|
|
9067
|
+
if (seen.has(key)) {
|
|
8870
9068
|
continue;
|
|
9069
|
+
}
|
|
8871
9070
|
seen.add(key);
|
|
8872
9071
|
findings.push({
|
|
8873
9072
|
type: sink.type,
|
|
@@ -9457,8 +9656,9 @@ var init_dist6 = __esm({
|
|
|
9457
9656
|
}
|
|
9458
9657
|
/** Restore tracker state produced by {@link toJSON}. Ignores malformed input. */
|
|
9459
9658
|
restore(data) {
|
|
9460
|
-
if (!data || typeof data !== "object")
|
|
9659
|
+
if (!data || typeof data !== "object") {
|
|
9461
9660
|
return;
|
|
9661
|
+
}
|
|
9462
9662
|
const d = data;
|
|
9463
9663
|
if (typeof d.currentPhase === "string") {
|
|
9464
9664
|
this.state.currentPhase = d.currentPhase;
|
|
@@ -10424,13 +10624,15 @@ var init_dist10 = __esm({
|
|
|
10424
10624
|
}
|
|
10425
10625
|
for (let round = 1; round < maxRounds; round++) {
|
|
10426
10626
|
const subQueries = this.getNextSubQueries(allResults, query);
|
|
10427
|
-
if (subQueries.length === 0)
|
|
10627
|
+
if (subQueries.length === 0) {
|
|
10428
10628
|
break;
|
|
10629
|
+
}
|
|
10429
10630
|
let foundNew = false;
|
|
10430
10631
|
for (const subQuery of subQueries.slice(0, 3)) {
|
|
10431
10632
|
const subSources = sourceProvider(subQuery);
|
|
10432
|
-
if (subSources.length === 0)
|
|
10633
|
+
if (subSources.length === 0) {
|
|
10433
10634
|
continue;
|
|
10635
|
+
}
|
|
10434
10636
|
const subResult = this.research({ topic: subQuery, depth: query.depth, maxSources: query.maxSources }, subSources);
|
|
10435
10637
|
allResults.push(subResult);
|
|
10436
10638
|
for (const s of subResult.sources) {
|
|
@@ -10441,11 +10643,13 @@ var init_dist10 = __esm({
|
|
|
10441
10643
|
}
|
|
10442
10644
|
}
|
|
10443
10645
|
}
|
|
10444
|
-
if (!foundNew)
|
|
10646
|
+
if (!foundNew) {
|
|
10445
10647
|
break;
|
|
10648
|
+
}
|
|
10446
10649
|
const avgConfidence = allResults.reduce((sum, r) => sum + r.confidence, 0) / allResults.length;
|
|
10447
|
-
if (avgConfidence >= 0.8)
|
|
10650
|
+
if (avgConfidence >= 0.8) {
|
|
10448
10651
|
break;
|
|
10652
|
+
}
|
|
10449
10653
|
}
|
|
10450
10654
|
return this.mergeResults(query, allSources, allResults);
|
|
10451
10655
|
}
|
|
@@ -10454,8 +10658,9 @@ var init_dist10 = __esm({
|
|
|
10454
10658
|
const topicTerms = tokenize(topic);
|
|
10455
10659
|
for (const term of topicTerms) {
|
|
10456
10660
|
const related = this.crossReferenceIndex.get(term);
|
|
10457
|
-
if (!related)
|
|
10661
|
+
if (!related) {
|
|
10458
10662
|
continue;
|
|
10663
|
+
}
|
|
10459
10664
|
for (const relatedTerm of related) {
|
|
10460
10665
|
if (!topicTerms.includes(relatedTerm)) {
|
|
10461
10666
|
result.set(relatedTerm, (result.get(relatedTerm) ?? 0) + 1);
|
|
@@ -10466,16 +10671,18 @@ var init_dist10 = __esm({
|
|
|
10466
10671
|
}
|
|
10467
10672
|
generateEvidenceChain(topic) {
|
|
10468
10673
|
const results = this.accumulator.query(topic);
|
|
10469
|
-
if (results.length === 0)
|
|
10674
|
+
if (results.length === 0) {
|
|
10470
10675
|
return [];
|
|
10676
|
+
}
|
|
10471
10677
|
const allSources = [];
|
|
10472
10678
|
for (const result of results) {
|
|
10473
10679
|
for (const source of result.sources) {
|
|
10474
10680
|
allSources.push(source);
|
|
10475
10681
|
}
|
|
10476
10682
|
}
|
|
10477
|
-
if (allSources.length === 0)
|
|
10683
|
+
if (allSources.length === 0) {
|
|
10478
10684
|
return [];
|
|
10685
|
+
}
|
|
10479
10686
|
const claimGroups = this.clusterSourcesByClaim(allSources, topic);
|
|
10480
10687
|
return claimGroups.map((group) => ({
|
|
10481
10688
|
claim: group.claim,
|
|
@@ -10516,8 +10723,9 @@ var init_dist10 = __esm({
|
|
|
10516
10723
|
}
|
|
10517
10724
|
}
|
|
10518
10725
|
computeConfidence(sources, query) {
|
|
10519
|
-
if (sources.length === 0)
|
|
10726
|
+
if (sources.length === 0) {
|
|
10520
10727
|
return 0;
|
|
10728
|
+
}
|
|
10521
10729
|
const avgRelevance = sources.reduce((sum, s) => sum + s.relevance, 0) / sources.length;
|
|
10522
10730
|
const types = new Set(sources.map((s) => s.type));
|
|
10523
10731
|
const diversityBonus = Math.min(0.15, (types.size - 1) * 0.05);
|
|
@@ -10527,8 +10735,9 @@ var init_dist10 = __esm({
|
|
|
10527
10735
|
return Math.min(1, avgRelevance + diversityBonus + coverageBonus);
|
|
10528
10736
|
}
|
|
10529
10737
|
extractKeyFindings(sources, query) {
|
|
10530
|
-
if (sources.length === 0)
|
|
10738
|
+
if (sources.length === 0) {
|
|
10531
10739
|
return [];
|
|
10740
|
+
}
|
|
10532
10741
|
const findings = [];
|
|
10533
10742
|
const queryTerms = new Set(tokenize(query.topic));
|
|
10534
10743
|
for (const source of sources.slice(0, 5)) {
|
|
@@ -10566,8 +10775,9 @@ var init_dist10 = __esm({
|
|
|
10566
10775
|
}
|
|
10567
10776
|
}
|
|
10568
10777
|
getNextSubQueries(results, query) {
|
|
10569
|
-
if (this.strategies.length === 0)
|
|
10778
|
+
if (this.strategies.length === 0) {
|
|
10570
10779
|
return [];
|
|
10780
|
+
}
|
|
10571
10781
|
const allSuggestions = [];
|
|
10572
10782
|
for (const strategy of this.strategies) {
|
|
10573
10783
|
const suggestions = strategy.suggestNextSteps(results, query);
|
|
@@ -10608,8 +10818,9 @@ var init_dist10 = __esm({
|
|
|
10608
10818
|
return findings.slice(0, 10);
|
|
10609
10819
|
}
|
|
10610
10820
|
clusterSourcesByClaim(sources, topic) {
|
|
10611
|
-
if (sources.length === 0)
|
|
10821
|
+
if (sources.length === 0) {
|
|
10612
10822
|
return [];
|
|
10823
|
+
}
|
|
10613
10824
|
const byType = /* @__PURE__ */ new Map();
|
|
10614
10825
|
for (const source of sources) {
|
|
10615
10826
|
const existing = byType.get(source.type) ?? [];
|
|
@@ -10676,8 +10887,9 @@ function parseSignatures(snippet) {
|
|
|
10676
10887
|
let match;
|
|
10677
10888
|
while ((match = re.exec(snippet)) !== null) {
|
|
10678
10889
|
const name = match[1];
|
|
10679
|
-
if (seen.has(name))
|
|
10890
|
+
if (seen.has(name)) {
|
|
10680
10891
|
continue;
|
|
10892
|
+
}
|
|
10681
10893
|
seen.add(name);
|
|
10682
10894
|
const paramStr = match[2] ?? "";
|
|
10683
10895
|
const params = paramStr.split(",").map((p) => p.trim()).filter((p) => p.length > 0);
|
|
@@ -10692,14 +10904,17 @@ function parseSignatures(snippet) {
|
|
|
10692
10904
|
return sigs;
|
|
10693
10905
|
}
|
|
10694
10906
|
function structurallySimilar(a, b) {
|
|
10695
|
-
if (a.arity !== b.arity)
|
|
10907
|
+
if (a.arity !== b.arity) {
|
|
10696
10908
|
return false;
|
|
10697
|
-
|
|
10909
|
+
}
|
|
10910
|
+
if (a.name === b.name) {
|
|
10698
10911
|
return true;
|
|
10912
|
+
}
|
|
10699
10913
|
const paramsA = new Set(a.params);
|
|
10700
10914
|
for (const p of b.params) {
|
|
10701
|
-
if (paramsA.has(p))
|
|
10915
|
+
if (paramsA.has(p)) {
|
|
10702
10916
|
return true;
|
|
10917
|
+
}
|
|
10703
10918
|
}
|
|
10704
10919
|
const shorter = a.name.length <= b.name.length ? a.name.toLowerCase() : b.name.toLowerCase();
|
|
10705
10920
|
const longer = a.name.length <= b.name.length ? b.name.toLowerCase() : a.name.toLowerCase();
|
|
@@ -10826,8 +11041,9 @@ var init_dist11 = __esm({
|
|
|
10826
11041
|
const learned = [];
|
|
10827
11042
|
const seenNames = /* @__PURE__ */ new Set();
|
|
10828
11043
|
for (const sig of allSigs) {
|
|
10829
|
-
if (seenNames.has(sig.name))
|
|
11044
|
+
if (seenNames.has(sig.name)) {
|
|
10830
11045
|
continue;
|
|
11046
|
+
}
|
|
10831
11047
|
seenNames.add(sig.name);
|
|
10832
11048
|
const nodeKey = `${sig.name}/${sig.arity}`;
|
|
10833
11049
|
const eclassId = sigToEClass.get(nodeKey);
|
|
@@ -10853,8 +11069,9 @@ var init_dist11 = __esm({
|
|
|
10853
11069
|
if (inputSigs.length > 0) {
|
|
10854
11070
|
for (const inputSig of inputSigs) {
|
|
10855
11071
|
for (const p of this.patterns) {
|
|
10856
|
-
if (matched.has(p.name))
|
|
11072
|
+
if (matched.has(p.name)) {
|
|
10857
11073
|
continue;
|
|
11074
|
+
}
|
|
10858
11075
|
const pSig = {
|
|
10859
11076
|
name: p.name,
|
|
10860
11077
|
arity: p.abstraction.split("/").length > 1 ? parseInt(p.abstraction.split("/")[1], 10) || 0 : 0,
|
|
@@ -11165,8 +11382,9 @@ var init_dist12 = __esm({
|
|
|
11165
11382
|
return input.length === 0 ? input : input[0].toUpperCase() + input.slice(1).toLowerCase();
|
|
11166
11383
|
case "camelCase": {
|
|
11167
11384
|
const words = input.replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/).filter((w) => w.length > 0);
|
|
11168
|
-
if (words.length === 0)
|
|
11385
|
+
if (words.length === 0) {
|
|
11169
11386
|
return "";
|
|
11387
|
+
}
|
|
11170
11388
|
return words[0].toLowerCase() + words.slice(1).map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
11171
11389
|
}
|
|
11172
11390
|
case "snakeCase": {
|
|
@@ -11226,11 +11444,13 @@ var init_dist12 = __esm({
|
|
|
11226
11444
|
throw new Error(`Version space "${name}" not found`);
|
|
11227
11445
|
}
|
|
11228
11446
|
const total = space.hypotheses.length;
|
|
11229
|
-
if (total === 0)
|
|
11447
|
+
if (total === 0) {
|
|
11230
11448
|
return 0;
|
|
11449
|
+
}
|
|
11231
11450
|
const consistent = space.hypotheses.filter((h) => this.isConsistent(h, space)).length;
|
|
11232
|
-
if (consistent === 0)
|
|
11451
|
+
if (consistent === 0) {
|
|
11233
11452
|
return 0;
|
|
11453
|
+
}
|
|
11234
11454
|
const exampleCount = space.positiveExamples.length + space.negativeExamples.length;
|
|
11235
11455
|
const selectivity = 1 - consistent / total;
|
|
11236
11456
|
const exampleFactor = Math.min(1, exampleCount / 5);
|
|
@@ -11273,23 +11493,27 @@ var init_dist12 = __esm({
|
|
|
11273
11493
|
}
|
|
11274
11494
|
if (/^[A-Z]/.test(example)) {
|
|
11275
11495
|
const h = "pattern:startsWithUpper";
|
|
11276
|
-
if (!space.hypotheses.includes(h))
|
|
11496
|
+
if (!space.hypotheses.includes(h)) {
|
|
11277
11497
|
space.hypotheses.push(h);
|
|
11498
|
+
}
|
|
11278
11499
|
}
|
|
11279
11500
|
if (/^[a-z]/.test(example)) {
|
|
11280
11501
|
const h = "pattern:startsWithLower";
|
|
11281
|
-
if (!space.hypotheses.includes(h))
|
|
11502
|
+
if (!space.hypotheses.includes(h)) {
|
|
11282
11503
|
space.hypotheses.push(h);
|
|
11504
|
+
}
|
|
11283
11505
|
}
|
|
11284
11506
|
if (/\d/.test(example)) {
|
|
11285
11507
|
const h = "pattern:containsDigit";
|
|
11286
|
-
if (!space.hypotheses.includes(h))
|
|
11508
|
+
if (!space.hypotheses.includes(h)) {
|
|
11287
11509
|
space.hypotheses.push(h);
|
|
11510
|
+
}
|
|
11288
11511
|
}
|
|
11289
11512
|
if (/^[a-zA-Z]+$/.test(example)) {
|
|
11290
11513
|
const h = "pattern:alphaOnly";
|
|
11291
|
-
if (!space.hypotheses.includes(h))
|
|
11514
|
+
if (!space.hypotheses.includes(h)) {
|
|
11292
11515
|
space.hypotheses.push(h);
|
|
11516
|
+
}
|
|
11293
11517
|
}
|
|
11294
11518
|
}
|
|
11295
11519
|
}
|
|
@@ -11355,11 +11579,13 @@ var init_dist12 = __esm({
|
|
|
11355
11579
|
return "capitalize";
|
|
11356
11580
|
}
|
|
11357
11581
|
const camelRule = this.tryCamelCase(examples);
|
|
11358
|
-
if (camelRule)
|
|
11582
|
+
if (camelRule) {
|
|
11359
11583
|
return camelRule;
|
|
11584
|
+
}
|
|
11360
11585
|
const snakeRule = this.trySnakeCase(examples);
|
|
11361
|
-
if (snakeRule)
|
|
11586
|
+
if (snakeRule) {
|
|
11362
11587
|
return snakeRule;
|
|
11588
|
+
}
|
|
11363
11589
|
const substringRule = this.trySubstringRule(examples);
|
|
11364
11590
|
if (substringRule && this.verify(substringRule, examples)) {
|
|
11365
11591
|
return substringRule;
|
|
@@ -11369,11 +11595,13 @@ var init_dist12 = __esm({
|
|
|
11369
11595
|
return repeatRule;
|
|
11370
11596
|
}
|
|
11371
11597
|
const compositional = this.synthesizeCompositional(examples);
|
|
11372
|
-
if (compositional)
|
|
11598
|
+
if (compositional) {
|
|
11373
11599
|
return compositional;
|
|
11600
|
+
}
|
|
11374
11601
|
const conditional = this.synthesizeConditional(examples);
|
|
11375
|
-
if (conditional)
|
|
11602
|
+
if (conditional) {
|
|
11376
11603
|
return conditional;
|
|
11604
|
+
}
|
|
11377
11605
|
return null;
|
|
11378
11606
|
}
|
|
11379
11607
|
verify(rule, examples) {
|
|
@@ -11411,8 +11639,9 @@ var init_dist12 = __esm({
|
|
|
11411
11639
|
}
|
|
11412
11640
|
if (rule === "camelCase") {
|
|
11413
11641
|
const words = input.replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/).filter((w) => w.length > 0);
|
|
11414
|
-
if (words.length === 0)
|
|
11642
|
+
if (words.length === 0) {
|
|
11415
11643
|
return "";
|
|
11644
|
+
}
|
|
11416
11645
|
return words[0].toLowerCase() + words.slice(1).map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
11417
11646
|
}
|
|
11418
11647
|
if (rule === "snakeCase") {
|
|
@@ -11473,8 +11702,9 @@ var init_dist12 = __esm({
|
|
|
11473
11702
|
const branches = body.split(";");
|
|
11474
11703
|
for (const branch of branches) {
|
|
11475
11704
|
const [condition, branchRule] = branch.split("=>");
|
|
11476
|
-
if (!branchRule)
|
|
11705
|
+
if (!branchRule) {
|
|
11477
11706
|
continue;
|
|
11707
|
+
}
|
|
11478
11708
|
if (condition === "default") {
|
|
11479
11709
|
return this.applySingleRule(branchRule, input);
|
|
11480
11710
|
}
|
|
@@ -11554,8 +11784,9 @@ var init_dist12 = __esm({
|
|
|
11554
11784
|
}
|
|
11555
11785
|
tryRepeatRule(examples) {
|
|
11556
11786
|
const first = examples[0];
|
|
11557
|
-
if (first.input.length === 0)
|
|
11787
|
+
if (first.input.length === 0) {
|
|
11558
11788
|
return null;
|
|
11789
|
+
}
|
|
11559
11790
|
if (first.output.length % first.input.length === 0) {
|
|
11560
11791
|
const times = first.output.length / first.input.length;
|
|
11561
11792
|
if (times >= 2 && first.output === first.input.repeat(times)) {
|
|
@@ -11570,8 +11801,9 @@ var init_dist12 = __esm({
|
|
|
11570
11801
|
tryCamelCase(examples) {
|
|
11571
11802
|
if (examples.every((e) => {
|
|
11572
11803
|
const words = e.input.replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/).filter((w) => w.length > 0);
|
|
11573
|
-
if (words.length === 0)
|
|
11804
|
+
if (words.length === 0) {
|
|
11574
11805
|
return e.output === "";
|
|
11806
|
+
}
|
|
11575
11807
|
const expected = words[0].toLowerCase() + words.slice(1).map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
11576
11808
|
return e.output === expected;
|
|
11577
11809
|
})) {
|
|
@@ -11601,8 +11833,9 @@ var init_dist12 = __esm({
|
|
|
11601
11833
|
];
|
|
11602
11834
|
for (const r1 of singleRules) {
|
|
11603
11835
|
for (const r2 of singleRules) {
|
|
11604
|
-
if (r1 === r2)
|
|
11836
|
+
if (r1 === r2) {
|
|
11605
11837
|
continue;
|
|
11838
|
+
}
|
|
11606
11839
|
const composite = `${r1} |> ${r2}`;
|
|
11607
11840
|
if (this.verify(composite, examples)) {
|
|
11608
11841
|
return composite;
|
|
@@ -11610,8 +11843,9 @@ var init_dist12 = __esm({
|
|
|
11610
11843
|
}
|
|
11611
11844
|
}
|
|
11612
11845
|
const replaceRule = this.findReplacePart(examples, singleRules);
|
|
11613
|
-
if (replaceRule)
|
|
11846
|
+
if (replaceRule) {
|
|
11614
11847
|
return replaceRule;
|
|
11848
|
+
}
|
|
11615
11849
|
return null;
|
|
11616
11850
|
}
|
|
11617
11851
|
findReplacePart(examples, singleRules) {
|
|
@@ -11642,8 +11876,9 @@ var init_dist12 = __esm({
|
|
|
11642
11876
|
return null;
|
|
11643
11877
|
}
|
|
11644
11878
|
synthesizeConditional(examples) {
|
|
11645
|
-
if (examples.length < 2)
|
|
11879
|
+
if (examples.length < 2) {
|
|
11646
11880
|
return null;
|
|
11881
|
+
}
|
|
11647
11882
|
const singleRules = [
|
|
11648
11883
|
"uppercase",
|
|
11649
11884
|
"lowercase",
|
|
@@ -11653,12 +11888,14 @@ var init_dist12 = __esm({
|
|
|
11653
11888
|
];
|
|
11654
11889
|
for (const r1 of singleRules) {
|
|
11655
11890
|
const r1Matches = examples.filter((e) => this.applySingleRule(r1, e.input) === e.output);
|
|
11656
|
-
if (r1Matches.length === 0 || r1Matches.length === examples.length)
|
|
11891
|
+
if (r1Matches.length === 0 || r1Matches.length === examples.length) {
|
|
11657
11892
|
continue;
|
|
11893
|
+
}
|
|
11658
11894
|
const remaining = examples.filter((e) => this.applySingleRule(r1, e.input) !== e.output);
|
|
11659
11895
|
for (const r2 of singleRules) {
|
|
11660
|
-
if (r1 === r2)
|
|
11896
|
+
if (r1 === r2) {
|
|
11661
11897
|
continue;
|
|
11898
|
+
}
|
|
11662
11899
|
const r2Matches = remaining.filter((e) => this.applySingleRule(r2, e.input) === e.output);
|
|
11663
11900
|
if (r2Matches.length === remaining.length) {
|
|
11664
11901
|
const condition = this.findDistinguishingCondition(r1Matches, remaining);
|
|
@@ -11702,16 +11939,19 @@ var init_dist12 = __esm({
|
|
|
11702
11939
|
return null;
|
|
11703
11940
|
}
|
|
11704
11941
|
generalizePattern(examples) {
|
|
11705
|
-
if (examples.length < 2)
|
|
11942
|
+
if (examples.length < 2) {
|
|
11706
11943
|
return this.synthesize(examples);
|
|
11944
|
+
}
|
|
11707
11945
|
const rules = [];
|
|
11708
11946
|
for (let i = 0; i < examples.length - 1; i++) {
|
|
11709
11947
|
const pairRule = this.synthesize([examples[i], examples[i + 1]]);
|
|
11710
|
-
if (pairRule)
|
|
11948
|
+
if (pairRule) {
|
|
11711
11949
|
rules.push(pairRule);
|
|
11950
|
+
}
|
|
11712
11951
|
}
|
|
11713
|
-
if (rules.length === 0)
|
|
11952
|
+
if (rules.length === 0) {
|
|
11714
11953
|
return null;
|
|
11954
|
+
}
|
|
11715
11955
|
for (const rule of rules) {
|
|
11716
11956
|
if (this.verify(rule, examples)) {
|
|
11717
11957
|
return rule;
|
|
@@ -11749,8 +11989,9 @@ var init_init_mode_resolver = __esm({
|
|
|
11749
11989
|
InitModeResolver = class {
|
|
11750
11990
|
resolve(flags) {
|
|
11751
11991
|
for (const flag of BOOTSTRAP_FLAGS) {
|
|
11752
|
-
if (flag in flags)
|
|
11992
|
+
if (flag in flags) {
|
|
11753
11993
|
return "platform-bootstrap";
|
|
11994
|
+
}
|
|
11754
11995
|
}
|
|
11755
11996
|
return "legacy-project-init";
|
|
11756
11997
|
}
|
|
@@ -12220,8 +12461,9 @@ var init_claude_skill_index_builder = __esm({
|
|
|
12220
12461
|
"use strict";
|
|
12221
12462
|
ClaudeSkillIndexBuilder = class {
|
|
12222
12463
|
build(items) {
|
|
12223
|
-
if (items.length === 0)
|
|
12464
|
+
if (items.length === 0) {
|
|
12224
12465
|
return "";
|
|
12466
|
+
}
|
|
12225
12467
|
const lines = [
|
|
12226
12468
|
"## \u30B9\u30AD\u30EB\u4E00\u89A7",
|
|
12227
12469
|
"",
|
|
@@ -12251,11 +12493,13 @@ var init_package_root_locator = __esm({
|
|
|
12251
12493
|
const thisFile = fileURLToPath(importMetaUrl);
|
|
12252
12494
|
let dir = dirname2(thisFile);
|
|
12253
12495
|
for (let i = 0; i < 10; i++) {
|
|
12254
|
-
if (existsSync5(resolve6(dir, "package.json")))
|
|
12496
|
+
if (existsSync5(resolve6(dir, "package.json"))) {
|
|
12255
12497
|
return dir;
|
|
12498
|
+
}
|
|
12256
12499
|
const parent = dirname2(dir);
|
|
12257
|
-
if (parent === dir)
|
|
12500
|
+
if (parent === dir) {
|
|
12258
12501
|
break;
|
|
12502
|
+
}
|
|
12259
12503
|
dir = parent;
|
|
12260
12504
|
}
|
|
12261
12505
|
return dir;
|
|
@@ -12278,8 +12522,9 @@ var init_package_asset_catalog = __esm({
|
|
|
12278
12522
|
this.locator = locator;
|
|
12279
12523
|
}
|
|
12280
12524
|
load() {
|
|
12281
|
-
if (this.manifest)
|
|
12525
|
+
if (this.manifest) {
|
|
12282
12526
|
return this.manifest;
|
|
12527
|
+
}
|
|
12283
12528
|
const root = this.locator.resolve(import.meta.url);
|
|
12284
12529
|
const manifestPath = resolve7(root, "dist", "assets", "skills-manifest.json");
|
|
12285
12530
|
if (!existsSync6(manifestPath)) {
|
|
@@ -12328,8 +12573,9 @@ var init_template_renderer = __esm({
|
|
|
12328
12573
|
return template.replace(/\{\{PROJECT_NAME\}\}/g, ctx.projectName).replace(/\{\{ROOT_STRUCTURE\}\}/g, ctx.rootStructure.join("\n")).replace(/\{\{CONSTITUTION_SUMMARY\}\}/g, ctx.constitutionSummary.join("\n")).replace(/\{\{SKILL_SECTION\}\}/g, this.buildSkillSection(ctx.skillNames));
|
|
12329
12574
|
}
|
|
12330
12575
|
buildSkillSection(skillNames) {
|
|
12331
|
-
if (skillNames.length === 0)
|
|
12576
|
+
if (skillNames.length === 0) {
|
|
12332
12577
|
return "_No skills configured._";
|
|
12578
|
+
}
|
|
12333
12579
|
return skillNames.map((n) => `- **${n}**`).join("\n");
|
|
12334
12580
|
}
|
|
12335
12581
|
};
|
|
@@ -12424,8 +12670,9 @@ var init_confirmation_resolver = __esm({
|
|
|
12424
12670
|
"use strict";
|
|
12425
12671
|
ConfirmationResolver = class {
|
|
12426
12672
|
async resolveCandidate(selection, interactive) {
|
|
12427
|
-
if (!selection.needsConfirmation)
|
|
12673
|
+
if (!selection.needsConfirmation) {
|
|
12428
12674
|
return selection;
|
|
12675
|
+
}
|
|
12429
12676
|
if (!interactive) {
|
|
12430
12677
|
return {
|
|
12431
12678
|
copilot: false,
|
|
@@ -12723,8 +12970,9 @@ function createJsonRpcError(id, code, message, data) {
|
|
|
12723
12970
|
return { jsonrpc: "2.0", id, error: { code, message, data } };
|
|
12724
12971
|
}
|
|
12725
12972
|
function isJsonRpcRequest(value) {
|
|
12726
|
-
if (typeof value !== "object" || value === null)
|
|
12973
|
+
if (typeof value !== "object" || value === null) {
|
|
12727
12974
|
return false;
|
|
12975
|
+
}
|
|
12728
12976
|
const obj = value;
|
|
12729
12977
|
return obj["jsonrpc"] === "2.0" && (typeof obj["id"] === "string" || typeof obj["id"] === "number") && typeof obj["method"] === "string";
|
|
12730
12978
|
}
|
|
@@ -12772,10 +13020,12 @@ var init_transport = __esm({
|
|
|
12772
13020
|
}
|
|
12773
13021
|
async processLine(line) {
|
|
12774
13022
|
const trimmed = line.trim();
|
|
12775
|
-
if (!trimmed)
|
|
13023
|
+
if (!trimmed) {
|
|
12776
13024
|
return;
|
|
12777
|
-
|
|
13025
|
+
}
|
|
13026
|
+
if (!this.handler) {
|
|
12778
13027
|
return;
|
|
13028
|
+
}
|
|
12779
13029
|
try {
|
|
12780
13030
|
const parsed = JSON.parse(trimmed);
|
|
12781
13031
|
const response = await this.handler(parsed);
|
|
@@ -12802,8 +13052,9 @@ var init_transport = __esm({
|
|
|
12802
13052
|
* can begin writing, so a separate wait hook is needed to block on.
|
|
12803
13053
|
*/
|
|
12804
13054
|
async waitForClose() {
|
|
12805
|
-
if (!this.rl)
|
|
13055
|
+
if (!this.rl) {
|
|
12806
13056
|
return;
|
|
13057
|
+
}
|
|
12807
13058
|
await new Promise((resolve9) => {
|
|
12808
13059
|
this.rl.once("close", () => resolve9());
|
|
12809
13060
|
});
|
|
@@ -12917,8 +13168,9 @@ var init_transport = __esm({
|
|
|
12917
13168
|
this.handler = handler;
|
|
12918
13169
|
}
|
|
12919
13170
|
async simulateRequest(request) {
|
|
12920
|
-
if (!this.handler)
|
|
13171
|
+
if (!this.handler) {
|
|
12921
13172
|
throw new Error("No handler registered");
|
|
13173
|
+
}
|
|
12922
13174
|
return this.handler(request);
|
|
12923
13175
|
}
|
|
12924
13176
|
getSentMessages() {
|
|
@@ -13389,8 +13641,9 @@ var init_dist14 = __esm({
|
|
|
13389
13641
|
_computeVector(text) {
|
|
13390
13642
|
const tokens = tokenize2(text);
|
|
13391
13643
|
const vec = new Array(this.dimensions).fill(0);
|
|
13392
|
-
if (tokens.length === 0)
|
|
13644
|
+
if (tokens.length === 0) {
|
|
13393
13645
|
return vec;
|
|
13646
|
+
}
|
|
13394
13647
|
const tf = /* @__PURE__ */ new Map();
|
|
13395
13648
|
for (const token of tokens) {
|
|
13396
13649
|
tf.set(token, (tf.get(token) ?? 0) + 1);
|
|
@@ -13481,8 +13734,9 @@ function computePMI(ngramFreq, unigramFreq, totalUnigrams, totalBigrams) {
|
|
|
13481
13734
|
const pmi = /* @__PURE__ */ new Map();
|
|
13482
13735
|
for (const [ngram, count] of ngramFreq) {
|
|
13483
13736
|
const parts = ngram.split(" ");
|
|
13484
|
-
if (parts.length < 2)
|
|
13737
|
+
if (parts.length < 2) {
|
|
13485
13738
|
continue;
|
|
13739
|
+
}
|
|
13486
13740
|
const pXY = count / totalBigrams;
|
|
13487
13741
|
let pIndep = 1;
|
|
13488
13742
|
for (const part of parts) {
|
|
@@ -13499,8 +13753,9 @@ function jaccardSimilarity(a, b) {
|
|
|
13499
13753
|
const setB = new Set(b.split(/\s+/));
|
|
13500
13754
|
let intersection = 0;
|
|
13501
13755
|
for (const x of setA) {
|
|
13502
|
-
if (setB.has(x))
|
|
13756
|
+
if (setB.has(x)) {
|
|
13503
13757
|
intersection++;
|
|
13758
|
+
}
|
|
13504
13759
|
}
|
|
13505
13760
|
const union = setA.size + setB.size - intersection;
|
|
13506
13761
|
return union === 0 ? 0 : intersection / union;
|
|
@@ -13610,13 +13865,15 @@ var init_dist15 = __esm({
|
|
|
13610
13865
|
const clusters = [];
|
|
13611
13866
|
const assigned = /* @__PURE__ */ new Set();
|
|
13612
13867
|
for (let i = 0; i < surviving.length; i++) {
|
|
13613
|
-
if (assigned.has(i))
|
|
13868
|
+
if (assigned.has(i)) {
|
|
13614
13869
|
continue;
|
|
13870
|
+
}
|
|
13615
13871
|
const cluster = [surviving[i]];
|
|
13616
13872
|
assigned.add(i);
|
|
13617
13873
|
for (let j = i + 1; j < surviving.length; j++) {
|
|
13618
|
-
if (assigned.has(j))
|
|
13874
|
+
if (assigned.has(j)) {
|
|
13619
13875
|
continue;
|
|
13876
|
+
}
|
|
13620
13877
|
if (jaccardSimilarity(surviving[i], surviving[j]) >= SIMILARITY_THRESHOLD) {
|
|
13621
13878
|
cluster.push(surviving[j]);
|
|
13622
13879
|
assigned.add(j);
|
|
@@ -14290,26 +14547,30 @@ var init_dist17 = __esm({
|
|
|
14290
14547
|
parseDiagnostics(stdout, stderr) {
|
|
14291
14548
|
const diagnostics = [];
|
|
14292
14549
|
const combined = (stdout + "\n" + stderr).trim();
|
|
14293
|
-
if (!combined)
|
|
14550
|
+
if (!combined) {
|
|
14294
14551
|
return diagnostics;
|
|
14552
|
+
}
|
|
14295
14553
|
for (const line of combined.split("\n")) {
|
|
14296
14554
|
const diag = this.parseDiagnosticLine(line);
|
|
14297
|
-
if (diag)
|
|
14555
|
+
if (diag) {
|
|
14298
14556
|
diagnostics.push(diag);
|
|
14557
|
+
}
|
|
14299
14558
|
}
|
|
14300
14559
|
return diagnostics;
|
|
14301
14560
|
}
|
|
14302
14561
|
parseDiagnosticsFromError(err) {
|
|
14303
|
-
if (!err || typeof err !== "object")
|
|
14562
|
+
if (!err || typeof err !== "object") {
|
|
14304
14563
|
return [];
|
|
14564
|
+
}
|
|
14305
14565
|
const stderr = ("stderr" in err ? String(err.stderr) : "").trim();
|
|
14306
14566
|
const stdout = ("stdout" in err ? String(err.stdout) : "").trim();
|
|
14307
14567
|
return this.parseDiagnostics(stdout, stderr);
|
|
14308
14568
|
}
|
|
14309
14569
|
parseDiagnosticLine(line) {
|
|
14310
14570
|
const trimmed = line.trim();
|
|
14311
|
-
if (!trimmed)
|
|
14571
|
+
if (!trimmed) {
|
|
14312
14572
|
return null;
|
|
14573
|
+
}
|
|
14313
14574
|
const match = /^[^:]+:(\d+):(\d+):\s*(error|warning|info(?:rmation)?)\s*:\s*(.+)$/.exec(trimmed);
|
|
14314
14575
|
if (match) {
|
|
14315
14576
|
const severity = match[3].startsWith("info") ? "info" : match[3];
|
|
@@ -14505,6 +14766,9 @@ function ok(data) {
|
|
|
14505
14766
|
function fail(error) {
|
|
14506
14767
|
return { success: false, error };
|
|
14507
14768
|
}
|
|
14769
|
+
function errMsg(err) {
|
|
14770
|
+
return err instanceof Error ? err.message : String(err);
|
|
14771
|
+
}
|
|
14508
14772
|
function sddCoreTools() {
|
|
14509
14773
|
return [
|
|
14510
14774
|
tool("sdd.requirements.create", "Create and classify an EARS requirement (Easy Approach to Requirements Syntax)", "sdd-core", [
|
|
@@ -14526,7 +14790,7 @@ function sddCoreTools() {
|
|
|
14526
14790
|
issues: validation.issues
|
|
14527
14791
|
});
|
|
14528
14792
|
} catch (err) {
|
|
14529
|
-
return fail(
|
|
14793
|
+
return fail(errMsg(err));
|
|
14530
14794
|
}
|
|
14531
14795
|
}),
|
|
14532
14796
|
tool("sdd.requirements.validate", "Validate requirements (EARS pattern + issues) for a list of requirement texts", "sdd-core", [param("requirements", "array", "Array of requirement texts or {text} objects")], async (params) => {
|
|
@@ -14542,7 +14806,7 @@ function sddCoreTools() {
|
|
|
14542
14806
|
});
|
|
14543
14807
|
return ok({ results, allValid: results.every((r) => r.valid) });
|
|
14544
14808
|
} catch (err) {
|
|
14545
|
-
return fail(
|
|
14809
|
+
return fail(errMsg(err));
|
|
14546
14810
|
}
|
|
14547
14811
|
}),
|
|
14548
14812
|
tool("sdd.requirements.list", "Parse and list requirements from a Markdown requirements document", "sdd-core", [param("markdown", "string", "Requirements document contents (Markdown)")], async (params) => {
|
|
@@ -14551,7 +14815,7 @@ function sddCoreTools() {
|
|
|
14551
14815
|
const parsed = new MarkdownEARSParser2().parse(params["markdown"] ?? "");
|
|
14552
14816
|
return ok(parsed.map((r) => ({ id: r.id, title: r.title, pattern: r.pattern, text: r.text })));
|
|
14553
14817
|
} catch (err) {
|
|
14554
|
-
return fail(
|
|
14818
|
+
return fail(errMsg(err));
|
|
14555
14819
|
}
|
|
14556
14820
|
}),
|
|
14557
14821
|
tool("sdd.design.generate", "Generate a design document from parsed requirements", "sdd-core", [param("requirements", "array", "Requirements as {id,title,text,pattern} objects")], async (params) => {
|
|
@@ -14566,7 +14830,7 @@ function sddCoreTools() {
|
|
|
14566
14830
|
}));
|
|
14567
14831
|
return ok(createDesignGenerator2().generate(mapped));
|
|
14568
14832
|
} catch (err) {
|
|
14569
|
-
return fail(
|
|
14833
|
+
return fail(errMsg(err));
|
|
14570
14834
|
}
|
|
14571
14835
|
}),
|
|
14572
14836
|
tool("sdd.design.verify", "Verify a design against SOLID principles", "sdd-core", [param("requirements", "array", "Requirements the design is generated from")], async (params) => {
|
|
@@ -14582,7 +14846,7 @@ function sddCoreTools() {
|
|
|
14582
14846
|
const design = createDesignGenerator2().generate(mapped);
|
|
14583
14847
|
return ok(createSOLIDValidator2().validate(design));
|
|
14584
14848
|
} catch (err) {
|
|
14585
|
-
return fail(
|
|
14849
|
+
return fail(errMsg(err));
|
|
14586
14850
|
}
|
|
14587
14851
|
}),
|
|
14588
14852
|
tool("sdd.codegen.generate", "Generate a code skeleton (class/interface/function) from a name", "sdd-core", [
|
|
@@ -14599,7 +14863,7 @@ function sddCoreTools() {
|
|
|
14599
14863
|
});
|
|
14600
14864
|
return ok(code);
|
|
14601
14865
|
} catch (err) {
|
|
14602
|
-
return fail(
|
|
14866
|
+
return fail(errMsg(err));
|
|
14603
14867
|
}
|
|
14604
14868
|
}),
|
|
14605
14869
|
tool("sdd.test.generate", "Generate a unit-test skeleton from source code", "sdd-core", [
|
|
@@ -14611,7 +14875,7 @@ function sddCoreTools() {
|
|
|
14611
14875
|
const suite = createUnitTestGenerator2().generate(params["code"] ?? "", params["style"] ?? "unit");
|
|
14612
14876
|
return ok(suite);
|
|
14613
14877
|
} catch (err) {
|
|
14614
|
-
return fail(
|
|
14878
|
+
return fail(errMsg(err));
|
|
14615
14879
|
}
|
|
14616
14880
|
}),
|
|
14617
14881
|
tool("sdd.trace.verify", "Verify requirement \u2192 code coverage by scanning source references (REQ-XXX-NNN)", "sdd-core", [
|
|
@@ -14625,8 +14889,9 @@ function sddCoreTools() {
|
|
|
14625
14889
|
const covered = /* @__PURE__ */ new Set();
|
|
14626
14890
|
for (const s of sources) {
|
|
14627
14891
|
for (const m of (s.code ?? "").matchAll(refRe)) {
|
|
14628
|
-
if (reqIds.includes(m[0]))
|
|
14892
|
+
if (reqIds.includes(m[0])) {
|
|
14629
14893
|
covered.add(m[0]);
|
|
14894
|
+
}
|
|
14630
14895
|
}
|
|
14631
14896
|
}
|
|
14632
14897
|
const gaps = reqIds.filter((r) => !covered.has(r));
|
|
@@ -14639,7 +14904,7 @@ function sddCoreTools() {
|
|
|
14639
14904
|
complete: gaps.length === 0 && reqIds.length > 0
|
|
14640
14905
|
});
|
|
14641
14906
|
} catch (err) {
|
|
14642
|
-
return fail(
|
|
14907
|
+
return fail(errMsg(err));
|
|
14643
14908
|
}
|
|
14644
14909
|
}),
|
|
14645
14910
|
// ── Requirements Interview tools ──
|
|
@@ -14650,7 +14915,7 @@ function sddCoreTools() {
|
|
|
14650
14915
|
const result = interviewer.analyzeInput(params["input"]);
|
|
14651
14916
|
return ok(result);
|
|
14652
14917
|
} catch (err) {
|
|
14653
|
-
return fail(
|
|
14918
|
+
return fail(errMsg(err));
|
|
14654
14919
|
}
|
|
14655
14920
|
}),
|
|
14656
14921
|
tool("sdd.requirements.interview.answer", "Answer a requirements interview question", "sdd-core", [
|
|
@@ -14669,7 +14934,7 @@ function sddCoreTools() {
|
|
|
14669
14934
|
const result = interviewer.answer(params["questionId"], params["response"]);
|
|
14670
14935
|
return ok(result);
|
|
14671
14936
|
} catch (err) {
|
|
14672
|
-
return fail(
|
|
14937
|
+
return fail(errMsg(err));
|
|
14673
14938
|
}
|
|
14674
14939
|
}),
|
|
14675
14940
|
tool("sdd.requirements.interview.state", "Get the current requirements interview state", "sdd-core", [], async () => {
|
|
@@ -14678,7 +14943,7 @@ function sddCoreTools() {
|
|
|
14678
14943
|
const interviewer = core.createRequirementsInterviewer();
|
|
14679
14944
|
return ok(interviewer.getState());
|
|
14680
14945
|
} catch (err) {
|
|
14681
|
-
return fail(
|
|
14946
|
+
return fail(errMsg(err));
|
|
14682
14947
|
}
|
|
14683
14948
|
}),
|
|
14684
14949
|
tool("sdd.requirements.interview.generate", "Generate a requirements document from gathered interview context", "sdd-core", [param("context", "object", "RequirementsContext gathered from interview")], async (params) => {
|
|
@@ -14689,7 +14954,7 @@ function sddCoreTools() {
|
|
|
14689
14954
|
const doc = generator.generate(context);
|
|
14690
14955
|
return ok(doc);
|
|
14691
14956
|
} catch (err) {
|
|
14692
|
-
return fail(
|
|
14957
|
+
return fail(errMsg(err));
|
|
14693
14958
|
}
|
|
14694
14959
|
})
|
|
14695
14960
|
];
|
|
@@ -14707,7 +14972,7 @@ function knowledgeTools() {
|
|
|
14707
14972
|
const entity = await store.getEntity(params["id"]);
|
|
14708
14973
|
return entity ? ok(entity) : fail("Entity not found");
|
|
14709
14974
|
} catch (err) {
|
|
14710
|
-
return fail(
|
|
14975
|
+
return fail(errMsg(err));
|
|
14711
14976
|
}
|
|
14712
14977
|
}),
|
|
14713
14978
|
tool("knowledge.entity.put", "Create or update an entity in the knowledge graph", "knowledge", [
|
|
@@ -14728,7 +14993,7 @@ function knowledgeTools() {
|
|
|
14728
14993
|
await store.save();
|
|
14729
14994
|
return ok({ id: params["id"], type: params["type"], saved: true });
|
|
14730
14995
|
} catch (err) {
|
|
14731
|
-
return fail(
|
|
14996
|
+
return fail(errMsg(err));
|
|
14732
14997
|
}
|
|
14733
14998
|
}),
|
|
14734
14999
|
tool("knowledge.entity.delete", "Delete an entity from the knowledge graph", "knowledge", [
|
|
@@ -14740,11 +15005,12 @@ function knowledgeTools() {
|
|
|
14740
15005
|
const store = createKnowledgeStore2(params["basePath"] ?? ".knowledge");
|
|
14741
15006
|
await store.load();
|
|
14742
15007
|
const deleted = await store.deleteEntity(params["id"]);
|
|
14743
|
-
if (deleted)
|
|
15008
|
+
if (deleted) {
|
|
14744
15009
|
await store.save();
|
|
15010
|
+
}
|
|
14745
15011
|
return ok({ id: params["id"], deleted });
|
|
14746
15012
|
} catch (err) {
|
|
14747
|
-
return fail(
|
|
15013
|
+
return fail(errMsg(err));
|
|
14748
15014
|
}
|
|
14749
15015
|
}),
|
|
14750
15016
|
tool("knowledge.relation.add", "Add a relation between entities in the knowledge graph", "knowledge", [
|
|
@@ -14765,7 +15031,7 @@ function knowledgeTools() {
|
|
|
14765
15031
|
await store.save();
|
|
14766
15032
|
return ok({ from: params["from"], to: params["to"], type: params["type"], added: true });
|
|
14767
15033
|
} catch (err) {
|
|
14768
|
-
return fail(
|
|
15034
|
+
return fail(errMsg(err));
|
|
14769
15035
|
}
|
|
14770
15036
|
}),
|
|
14771
15037
|
tool("knowledge.search", "Search the knowledge graph by query string", "knowledge", [
|
|
@@ -14780,7 +15046,7 @@ function knowledgeTools() {
|
|
|
14780
15046
|
const results = await store.search(params["query"], { limit: params["limit"] ?? 10 });
|
|
14781
15047
|
return ok(results);
|
|
14782
15048
|
} catch (err) {
|
|
14783
|
-
return fail(
|
|
15049
|
+
return fail(errMsg(err));
|
|
14784
15050
|
}
|
|
14785
15051
|
}),
|
|
14786
15052
|
tool("knowledge.traverse", "Traverse the knowledge graph from a starting entity", "knowledge", [
|
|
@@ -14795,7 +15061,7 @@ function knowledgeTools() {
|
|
|
14795
15061
|
const result = await store.traverse(params["startId"], { depth: params["depth"] ?? 2 });
|
|
14796
15062
|
return ok(result);
|
|
14797
15063
|
} catch (err) {
|
|
14798
|
-
return fail(
|
|
15064
|
+
return fail(errMsg(err));
|
|
14799
15065
|
}
|
|
14800
15066
|
}),
|
|
14801
15067
|
tool("knowledge.stats", "Get knowledge graph statistics", "knowledge", [param("basePath", "string", "Knowledge graph base path", false, ".knowledge")], async (params) => {
|
|
@@ -14806,7 +15072,7 @@ function knowledgeTools() {
|
|
|
14806
15072
|
const stats = store.getStats();
|
|
14807
15073
|
return ok(stats);
|
|
14808
15074
|
} catch (err) {
|
|
14809
|
-
return fail(
|
|
15075
|
+
return fail(errMsg(err));
|
|
14810
15076
|
}
|
|
14811
15077
|
})
|
|
14812
15078
|
];
|
|
@@ -14889,7 +15155,7 @@ function ontologyTools() {
|
|
|
14889
15155
|
await saveTripleStore(store, file);
|
|
14890
15156
|
return ok({ added: true, total: store.size() });
|
|
14891
15157
|
} catch (err) {
|
|
14892
|
-
return fail(
|
|
15158
|
+
return fail(errMsg(err));
|
|
14893
15159
|
}
|
|
14894
15160
|
}),
|
|
14895
15161
|
tool("ontology.triple.query", "Query triples by pattern (omit a term to wildcard it)", "ontology", [
|
|
@@ -14907,7 +15173,7 @@ function ontologyTools() {
|
|
|
14907
15173
|
});
|
|
14908
15174
|
return ok({ results, count: results.length });
|
|
14909
15175
|
} catch (err) {
|
|
14910
|
-
return fail(
|
|
15176
|
+
return fail(errMsg(err));
|
|
14911
15177
|
}
|
|
14912
15178
|
}),
|
|
14913
15179
|
tool("ontology.rules.apply", "Apply the default OWL 2 RL rule engine to infer new triples", "ontology", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
|
|
@@ -14918,7 +15184,7 @@ function ontologyTools() {
|
|
|
14918
15184
|
await saveTripleStore(store, file);
|
|
14919
15185
|
return ok(result);
|
|
14920
15186
|
} catch (err) {
|
|
14921
|
-
return fail(
|
|
15187
|
+
return fail(errMsg(err));
|
|
14922
15188
|
}
|
|
14923
15189
|
}),
|
|
14924
15190
|
tool("ontology.consistency.check", "Check ontology consistency against the persisted store", "ontology", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
|
|
@@ -14927,7 +15193,7 @@ function ontologyTools() {
|
|
|
14927
15193
|
const { store } = await loadTripleStore(params["basePath"] ?? ".");
|
|
14928
15194
|
return ok(createConsistencyValidator2().validate(store));
|
|
14929
15195
|
} catch (err) {
|
|
14930
|
-
return fail(
|
|
15196
|
+
return fail(errMsg(err));
|
|
14931
15197
|
}
|
|
14932
15198
|
}),
|
|
14933
15199
|
tool("ontology.sparql.query", "Pattern query over the store (basic subject/predicate/object matching)", "ontology", [
|
|
@@ -14945,7 +15211,7 @@ function ontologyTools() {
|
|
|
14945
15211
|
});
|
|
14946
15212
|
return ok({ bindings, count: bindings.length });
|
|
14947
15213
|
} catch (err) {
|
|
14948
|
-
return fail(
|
|
15214
|
+
return fail(errMsg(err));
|
|
14949
15215
|
}
|
|
14950
15216
|
})
|
|
14951
15217
|
];
|
|
@@ -14961,7 +15227,7 @@ function codeAnalysisTools() {
|
|
|
14961
15227
|
const nodes = createASTParser2().parse(params["source"] ?? "", params["language"] ?? "typescript");
|
|
14962
15228
|
return ok({ nodes, count: nodes.length });
|
|
14963
15229
|
} catch (err) {
|
|
14964
|
-
return fail(
|
|
15230
|
+
return fail(errMsg(err));
|
|
14965
15231
|
}
|
|
14966
15232
|
}),
|
|
14967
15233
|
tool("code.graph.build", "Build a code graph (nodes) from inline sources", "code-analysis", [param("sources", "array", "Sources as {code, language, filePath} objects")], async (params) => {
|
|
@@ -14987,7 +15253,7 @@ function codeAnalysisTools() {
|
|
|
14987
15253
|
const stats = engine.getStats();
|
|
14988
15254
|
return ok({ nodeCount: stats.nodeCount, edgeCount: stats.edgeCount, languages: [...stats.languages] });
|
|
14989
15255
|
} catch (err) {
|
|
14990
|
-
return fail(
|
|
15256
|
+
return fail(errMsg(err));
|
|
14991
15257
|
}
|
|
14992
15258
|
}),
|
|
14993
15259
|
tool("code.graph.search", "Search a code graph built from inline sources using GraphRAG", "code-analysis", [
|
|
@@ -15016,7 +15282,7 @@ function codeAnalysisTools() {
|
|
|
15016
15282
|
const results = new GraphRAGSearch2(engine).globalSearch(params["query"] ?? "");
|
|
15017
15283
|
return ok({ query: params["query"], results });
|
|
15018
15284
|
} catch (err) {
|
|
15019
|
-
return fail(
|
|
15285
|
+
return fail(errMsg(err));
|
|
15020
15286
|
}
|
|
15021
15287
|
}),
|
|
15022
15288
|
tool("code.dfg.analyze", "Build a data-flow graph from structured statements and report reaching definitions", "code-analysis", [
|
|
@@ -15028,7 +15294,7 @@ function codeAnalysisTools() {
|
|
|
15028
15294
|
const dfg = createDataFlowAnalyzer2().buildDFG(params["statements"] ?? [], params["scope"] ?? "global");
|
|
15029
15295
|
return ok(dfg);
|
|
15030
15296
|
} catch (err) {
|
|
15031
|
-
return fail(
|
|
15297
|
+
return fail(errMsg(err));
|
|
15032
15298
|
}
|
|
15033
15299
|
})
|
|
15034
15300
|
];
|
|
@@ -15038,9 +15304,11 @@ function sourceOf(params) {
|
|
|
15038
15304
|
}
|
|
15039
15305
|
function severityOf(findings) {
|
|
15040
15306
|
const order = ["critical", "high", "medium", "low", "info"];
|
|
15041
|
-
for (const s of order)
|
|
15042
|
-
if (findings.some((f) => f.severity === s))
|
|
15307
|
+
for (const s of order) {
|
|
15308
|
+
if (findings.some((f) => f.severity === s)) {
|
|
15043
15309
|
return s;
|
|
15310
|
+
}
|
|
15311
|
+
}
|
|
15044
15312
|
return "none";
|
|
15045
15313
|
}
|
|
15046
15314
|
function securityTools() {
|
|
@@ -15054,7 +15322,7 @@ function securityTools() {
|
|
|
15054
15322
|
const result = createSecurityScanner2().scan(sourceOf(params), params["filePath"] ?? "inline");
|
|
15055
15323
|
return ok({ findings: result.findings, severity: severityOf(result.findings) });
|
|
15056
15324
|
} catch (err) {
|
|
15057
|
-
return fail(
|
|
15325
|
+
return fail(errMsg(err));
|
|
15058
15326
|
}
|
|
15059
15327
|
}),
|
|
15060
15328
|
tool("security.secrets.detect", "Detect secrets and credentials in source code", "security", [
|
|
@@ -15066,7 +15334,7 @@ function securityTools() {
|
|
|
15066
15334
|
const secrets = createSecretDetector2().scan(sourceOf(params), params["filePath"] ?? "inline");
|
|
15067
15335
|
return ok({ secrets, count: secrets.length });
|
|
15068
15336
|
} catch (err) {
|
|
15069
|
-
return fail(
|
|
15337
|
+
return fail(errMsg(err));
|
|
15070
15338
|
}
|
|
15071
15339
|
}),
|
|
15072
15340
|
tool("security.taint.analyze", "Perform taint analysis to track untrusted data flow", "security", [
|
|
@@ -15078,7 +15346,7 @@ function securityTools() {
|
|
|
15078
15346
|
const tainted = new TaintAnalyzer2().analyze(sourceOf(params), params["filePath"] ?? "inline");
|
|
15079
15347
|
return ok({ tainted, count: tainted.length });
|
|
15080
15348
|
} catch (err) {
|
|
15081
|
-
return fail(
|
|
15349
|
+
return fail(errMsg(err));
|
|
15082
15350
|
}
|
|
15083
15351
|
}),
|
|
15084
15352
|
tool("security.compliance.check", "Check code compliance against registered security policies", "security", [
|
|
@@ -15090,7 +15358,7 @@ function securityTools() {
|
|
|
15090
15358
|
const result = createComplianceChecker2().check(sourceOf(params), params["filePath"] ?? "inline", []);
|
|
15091
15359
|
return ok(result);
|
|
15092
15360
|
} catch (err) {
|
|
15093
|
-
return fail(
|
|
15361
|
+
return fail(errMsg(err));
|
|
15094
15362
|
}
|
|
15095
15363
|
})
|
|
15096
15364
|
];
|
|
@@ -15107,7 +15375,7 @@ function researchTools() {
|
|
|
15107
15375
|
const result = createResearchEngine2().research({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, sources);
|
|
15108
15376
|
return ok(result);
|
|
15109
15377
|
} catch (err) {
|
|
15110
|
-
return fail(
|
|
15378
|
+
return fail(errMsg(err));
|
|
15111
15379
|
}
|
|
15112
15380
|
}),
|
|
15113
15381
|
tool("research.iterative", "Perform iterative research with progressive refinement over provided sources", "research", [
|
|
@@ -15121,7 +15389,7 @@ function researchTools() {
|
|
|
15121
15389
|
const result = createResearchEngine2().researchIterative({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, () => sources);
|
|
15122
15390
|
return ok(result);
|
|
15123
15391
|
} catch (err) {
|
|
15124
|
-
return fail(
|
|
15392
|
+
return fail(errMsg(err));
|
|
15125
15393
|
}
|
|
15126
15394
|
}),
|
|
15127
15395
|
tool("research.evidence", "Accumulate research results and retrieve evidence for a topic", "research", [
|
|
@@ -15137,7 +15405,7 @@ function researchTools() {
|
|
|
15137
15405
|
acc.accumulate(result);
|
|
15138
15406
|
return ok({ evidence: acc.query(topic), summary: result.summary, confidence: result.confidence });
|
|
15139
15407
|
} catch (err) {
|
|
15140
|
-
return fail(
|
|
15408
|
+
return fail(errMsg(err));
|
|
15141
15409
|
}
|
|
15142
15410
|
})
|
|
15143
15411
|
];
|
|
@@ -15182,7 +15450,7 @@ function neuralTools() {
|
|
|
15182
15450
|
const hits = engine.search(await embedder.embed(params["query"] ?? ""), params["topK"] ?? 10);
|
|
15183
15451
|
return ok({ query: params["query"], hits });
|
|
15184
15452
|
} catch (err) {
|
|
15185
|
-
return fail(
|
|
15453
|
+
return fail(errMsg(err));
|
|
15186
15454
|
}
|
|
15187
15455
|
}),
|
|
15188
15456
|
tool("neural.embed", "Generate a TF-IDF embedding vector for text", "neural", [param("text", "string", "Text to embed")], async (params) => {
|
|
@@ -15196,7 +15464,7 @@ function neuralTools() {
|
|
|
15196
15464
|
const vector = await model.embed(text);
|
|
15197
15465
|
return ok({ vector, dimensions: Array.isArray(vector) ? vector.length : vector.values?.length ?? 0 });
|
|
15198
15466
|
} catch (err) {
|
|
15199
|
-
return fail(
|
|
15467
|
+
return fail(errMsg(err));
|
|
15200
15468
|
}
|
|
15201
15469
|
}),
|
|
15202
15470
|
tool("neural.patterns.extract", "Wake phase: extract patterns from a list of items", "neural", [param("items", "array", "Items (strings) to process for pattern extraction")], async (params) => {
|
|
@@ -15205,7 +15473,7 @@ function neuralTools() {
|
|
|
15205
15473
|
const items = (params["items"] ?? []).map(String);
|
|
15206
15474
|
return ok(createWakePhase2().process(items));
|
|
15207
15475
|
} catch (err) {
|
|
15208
|
-
return fail(
|
|
15476
|
+
return fail(errMsg(err));
|
|
15209
15477
|
}
|
|
15210
15478
|
}),
|
|
15211
15479
|
tool("neural.patterns.consolidate", "Sleep phase: consolidate and compress learned patterns", "neural", [param("patterns", "array", "Pattern strings to consolidate")], async (params) => {
|
|
@@ -15214,7 +15482,7 @@ function neuralTools() {
|
|
|
15214
15482
|
const patterns = (params["patterns"] ?? []).map(String);
|
|
15215
15483
|
return ok(createSleepPhase2().consolidate(patterns));
|
|
15216
15484
|
} catch (err) {
|
|
15217
|
-
return fail(
|
|
15485
|
+
return fail(errMsg(err));
|
|
15218
15486
|
}
|
|
15219
15487
|
}),
|
|
15220
15488
|
tool("neural.library.learn", "Learn reusable patterns from code snippets (E-graph library learning)", "neural", [param("snippets", "array", "Array of code snippet strings to learn from")], async (params) => {
|
|
@@ -15224,7 +15492,7 @@ function neuralTools() {
|
|
|
15224
15492
|
const patterns = createLibraryLearner2().learn(snippets);
|
|
15225
15493
|
return ok({ patterns, count: patterns.length });
|
|
15226
15494
|
} catch (err) {
|
|
15227
|
-
return fail(
|
|
15495
|
+
return fail(errMsg(err));
|
|
15228
15496
|
}
|
|
15229
15497
|
})
|
|
15230
15498
|
];
|
|
@@ -15283,7 +15551,7 @@ function synthesisTools() {
|
|
|
15283
15551
|
const result = builder.execute(params["input"] ?? "");
|
|
15284
15552
|
return ok({ input: params["input"], ops, result });
|
|
15285
15553
|
} catch (err) {
|
|
15286
|
-
return fail(
|
|
15554
|
+
return fail(errMsg(err));
|
|
15287
15555
|
}
|
|
15288
15556
|
}),
|
|
15289
15557
|
tool("synthesis.synthesize", "Synthesize a transformation rule from input/output examples", "synthesis", [param("examples", "array", "Array of {input, output} example pairs")], async (params) => {
|
|
@@ -15296,7 +15564,7 @@ function synthesisTools() {
|
|
|
15296
15564
|
const rule = createSynthesisEngine2().synthesize(examples);
|
|
15297
15565
|
return ok({ rule, synthesized: rule !== null });
|
|
15298
15566
|
} catch (err) {
|
|
15299
|
-
return fail(
|
|
15567
|
+
return fail(errMsg(err));
|
|
15300
15568
|
}
|
|
15301
15569
|
}),
|
|
15302
15570
|
tool("synthesis.version-space", "Build a version space from positive/negative examples and get consistent hypotheses", "synthesis", [
|
|
@@ -15309,13 +15577,15 @@ function synthesisTools() {
|
|
|
15309
15577
|
const mgr = createVersionSpaceManager2();
|
|
15310
15578
|
const name = params["name"] ?? "default";
|
|
15311
15579
|
mgr.create(name);
|
|
15312
|
-
for (const p of params["positive"] ?? [])
|
|
15580
|
+
for (const p of params["positive"] ?? []) {
|
|
15313
15581
|
mgr.addPositive(name, p);
|
|
15314
|
-
|
|
15582
|
+
}
|
|
15583
|
+
for (const n of params["negative"] ?? []) {
|
|
15315
15584
|
mgr.addNegative(name, n);
|
|
15585
|
+
}
|
|
15316
15586
|
return ok({ name, hypotheses: mgr.getConsistentHypotheses(name), spaces: mgr.getSpaces().size });
|
|
15317
15587
|
} catch (err) {
|
|
15318
|
-
return fail(
|
|
15588
|
+
return fail(errMsg(err));
|
|
15319
15589
|
}
|
|
15320
15590
|
})
|
|
15321
15591
|
];
|
|
@@ -15351,7 +15621,7 @@ function formalVerifyTools() {
|
|
|
15351
15621
|
const { createEarsToSmtConverter: createEarsToSmtConverter2 } = await Promise.resolve().then(() => (init_dist16(), dist_exports16));
|
|
15352
15622
|
return ok(createEarsToSmtConverter2().convert(await buildSpecFromParams(params)));
|
|
15353
15623
|
} catch (err) {
|
|
15354
|
-
return fail(
|
|
15624
|
+
return fail(errMsg(err));
|
|
15355
15625
|
}
|
|
15356
15626
|
}),
|
|
15357
15627
|
tool("verify.z3.solve", "Solve an SMT-LIB2 script with the Z3 adapter", "formal-verify", [param("formula", "string", "SMT-LIB2 script")], async (params) => {
|
|
@@ -15359,7 +15629,7 @@ function formalVerifyTools() {
|
|
|
15359
15629
|
const { createZ3Adapter: createZ3Adapter2 } = await Promise.resolve().then(() => (init_dist16(), dist_exports16));
|
|
15360
15630
|
return ok(await createZ3Adapter2().solve(params["formula"] ?? ""));
|
|
15361
15631
|
} catch (err) {
|
|
15362
|
-
return fail(`Z3 solve failed: ${
|
|
15632
|
+
return fail(`Z3 solve failed: ${errMsg(err)}`);
|
|
15363
15633
|
}
|
|
15364
15634
|
}),
|
|
15365
15635
|
tool("verify.lean.convert", "Convert a requirement specification to a Lean 4 theorem", "formal-verify", [
|
|
@@ -15371,7 +15641,7 @@ function formalVerifyTools() {
|
|
|
15371
15641
|
const { createEarsToLeanConverter: createEarsToLeanConverter2 } = await Promise.resolve().then(() => (init_dist17(), dist_exports17));
|
|
15372
15642
|
return ok(createEarsToLeanConverter2().convert(await buildSpecFromParams(params)));
|
|
15373
15643
|
} catch (err) {
|
|
15374
|
-
return fail(
|
|
15644
|
+
return fail(errMsg(err));
|
|
15375
15645
|
}
|
|
15376
15646
|
}),
|
|
15377
15647
|
tool("verify.lean.run", "Run a Lean 4 proof (requires a Lean toolchain; reports availability otherwise)", "formal-verify", [param("proof", "string", "Lean 4 proof code")], async (params) => {
|
|
@@ -15379,7 +15649,7 @@ function formalVerifyTools() {
|
|
|
15379
15649
|
const { createLeanProofRunner: createLeanProofRunner2 } = await Promise.resolve().then(() => (init_dist17(), dist_exports17));
|
|
15380
15650
|
return ok(await createLeanProofRunner2().runProof(params["proof"] ?? ""));
|
|
15381
15651
|
} catch (err) {
|
|
15382
|
-
return fail(`Lean proof run failed: ${
|
|
15652
|
+
return fail(`Lean proof run failed: ${errMsg(err)}`);
|
|
15383
15653
|
}
|
|
15384
15654
|
}),
|
|
15385
15655
|
tool("verify.hybrid", "Run hybrid (Z3 + Lean) verification on a requirement specification", "formal-verify", [
|
|
@@ -15390,7 +15660,7 @@ function formalVerifyTools() {
|
|
|
15390
15660
|
const { createHybridVerifier: createHybridVerifier2 } = await Promise.resolve().then(() => (init_dist17(), dist_exports17));
|
|
15391
15661
|
return ok(await createHybridVerifier2().verify(await buildSpecFromParams(params)));
|
|
15392
15662
|
} catch (err) {
|
|
15393
|
-
return fail(`Hybrid verification failed: ${
|
|
15663
|
+
return fail(`Hybrid verification failed: ${errMsg(err)}`);
|
|
15394
15664
|
}
|
|
15395
15665
|
})
|
|
15396
15666
|
];
|
|
@@ -15402,8 +15672,9 @@ async function loadTracker(basePath) {
|
|
|
15402
15672
|
const tracker = createStateTracker2();
|
|
15403
15673
|
const file = join8(basePath, ".musubix", "workflow-state.json");
|
|
15404
15674
|
try {
|
|
15405
|
-
if (existsSync12(file))
|
|
15675
|
+
if (existsSync12(file)) {
|
|
15406
15676
|
tracker.restore(JSON.parse(readFileSync7(file, "utf-8")));
|
|
15677
|
+
}
|
|
15407
15678
|
} catch {
|
|
15408
15679
|
}
|
|
15409
15680
|
return { tracker, file };
|
|
@@ -15426,7 +15697,7 @@ function workflowTools() {
|
|
|
15426
15697
|
approvals: PHASE_ORDER2.map((p) => ({ phase: p, approved: tracker.isApproved(p) }))
|
|
15427
15698
|
});
|
|
15428
15699
|
} catch (err) {
|
|
15429
|
-
return fail(
|
|
15700
|
+
return fail(errMsg(err));
|
|
15430
15701
|
}
|
|
15431
15702
|
}),
|
|
15432
15703
|
tool("workflow.phase.transition", "Transition to a target SDD workflow phase (persisted)", "workflow", [
|
|
@@ -15437,11 +15708,12 @@ function workflowTools() {
|
|
|
15437
15708
|
const { createPhaseController: createPhaseController2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
|
|
15438
15709
|
const { tracker, file } = await loadTracker(params["basePath"] ?? ".");
|
|
15439
15710
|
const result = await createPhaseController2(tracker).transitionTo(params["targetPhase"]);
|
|
15440
|
-
if (result.success)
|
|
15711
|
+
if (result.success) {
|
|
15441
15712
|
await saveTracker(tracker, file);
|
|
15713
|
+
}
|
|
15442
15714
|
return ok(result);
|
|
15443
15715
|
} catch (err) {
|
|
15444
|
-
return fail(
|
|
15716
|
+
return fail(errMsg(err));
|
|
15445
15717
|
}
|
|
15446
15718
|
}),
|
|
15447
15719
|
tool("workflow.gate.check", "Check whether the workflow can transition to a target phase (quality gates)", "workflow", [
|
|
@@ -15455,7 +15727,7 @@ function workflowTools() {
|
|
|
15455
15727
|
const canTransition = await createPhaseController2(tracker).canTransition(target);
|
|
15456
15728
|
return ok({ targetPhase: target, canTransition });
|
|
15457
15729
|
} catch (err) {
|
|
15458
|
-
return fail(
|
|
15730
|
+
return fail(errMsg(err));
|
|
15459
15731
|
}
|
|
15460
15732
|
}),
|
|
15461
15733
|
tool("workflow.approve", "Approve the current (or a named) SDD phase (persisted)", "workflow", [
|
|
@@ -15469,7 +15741,7 @@ function workflowTools() {
|
|
|
15469
15741
|
await saveTracker(tracker, file);
|
|
15470
15742
|
return ok({ phase, approved: true });
|
|
15471
15743
|
} catch (err) {
|
|
15472
|
-
return fail(
|
|
15744
|
+
return fail(errMsg(err));
|
|
15473
15745
|
}
|
|
15474
15746
|
})
|
|
15475
15747
|
];
|
|
@@ -15494,7 +15766,7 @@ function decisionsTools() {
|
|
|
15494
15766
|
});
|
|
15495
15767
|
return ok(adr);
|
|
15496
15768
|
} catch (err) {
|
|
15497
|
-
return fail(
|
|
15769
|
+
return fail(errMsg(err));
|
|
15498
15770
|
}
|
|
15499
15771
|
}),
|
|
15500
15772
|
tool("decisions.list", "List all Architecture Decision Records", "decisions", [param("basePath", "string", "ADR base path", false, ".decisions")], async (params) => {
|
|
@@ -15504,7 +15776,7 @@ function decisionsTools() {
|
|
|
15504
15776
|
await mgr.load();
|
|
15505
15777
|
return ok(await mgr.list());
|
|
15506
15778
|
} catch (err) {
|
|
15507
|
-
return fail(
|
|
15779
|
+
return fail(errMsg(err));
|
|
15508
15780
|
}
|
|
15509
15781
|
}),
|
|
15510
15782
|
tool("decisions.search", "Search Architecture Decision Records by keyword", "decisions", [
|
|
@@ -15517,7 +15789,7 @@ function decisionsTools() {
|
|
|
15517
15789
|
await mgr.load();
|
|
15518
15790
|
return ok(await mgr.search(params["query"]));
|
|
15519
15791
|
} catch (err) {
|
|
15520
|
-
return fail(
|
|
15792
|
+
return fail(errMsg(err));
|
|
15521
15793
|
}
|
|
15522
15794
|
})
|
|
15523
15795
|
];
|
|
@@ -15536,7 +15808,7 @@ function skillsTools() {
|
|
|
15536
15808
|
const mgr = await getSkillManager();
|
|
15537
15809
|
return ok(mgr.getAvailableSkills().map((s) => ({ id: s.id, name: s.metadata.name, status: s.status })));
|
|
15538
15810
|
} catch (err) {
|
|
15539
|
-
return fail(
|
|
15811
|
+
return fail(errMsg(err));
|
|
15540
15812
|
}
|
|
15541
15813
|
}),
|
|
15542
15814
|
tool("skills.register", "Register a skill (echo-executor) for this server session", "skills", [
|
|
@@ -15555,7 +15827,7 @@ function skillsTools() {
|
|
|
15555
15827
|
}, async (input) => ({ skill: name, output: input }));
|
|
15556
15828
|
return ok({ id: skill.id, name, registered: true });
|
|
15557
15829
|
} catch (err) {
|
|
15558
|
-
return fail(
|
|
15830
|
+
return fail(errMsg(err));
|
|
15559
15831
|
}
|
|
15560
15832
|
}),
|
|
15561
15833
|
tool("skills.execute", "Execute a session skill by name (must be registered in this session first)", "skills", [
|
|
@@ -15566,12 +15838,13 @@ function skillsTools() {
|
|
|
15566
15838
|
const mgr = await getSkillManager();
|
|
15567
15839
|
const name = params["name"] ?? "";
|
|
15568
15840
|
const match = mgr.getAvailableSkills().find((s) => s.metadata.name === name);
|
|
15569
|
-
if (!match)
|
|
15841
|
+
if (!match) {
|
|
15570
15842
|
return fail(`Skill not registered in this session: ${name}`);
|
|
15843
|
+
}
|
|
15571
15844
|
const output = await match.execute(params["input"] ?? {});
|
|
15572
15845
|
return ok({ executed: true, name, output });
|
|
15573
15846
|
} catch (err) {
|
|
15574
|
-
return fail(
|
|
15847
|
+
return fail(errMsg(err));
|
|
15575
15848
|
}
|
|
15576
15849
|
})
|
|
15577
15850
|
];
|
|
@@ -16643,12 +16916,14 @@ function buildCodeTraceData(specsFile, srcDir) {
|
|
|
16643
16916
|
const content = readFileSync6(specsFile, "utf-8");
|
|
16644
16917
|
for (const line of content.split("\n")) {
|
|
16645
16918
|
const m = line.match(/^#{1,4}\s+(REQ-[A-Z]{3}-\d{3})\b/);
|
|
16646
|
-
if (m)
|
|
16919
|
+
if (m) {
|
|
16647
16920
|
reqIds.push(m[1]);
|
|
16921
|
+
}
|
|
16648
16922
|
}
|
|
16649
16923
|
if (reqIds.length === 0) {
|
|
16650
|
-
for (const m of content.matchAll(REQ_ID_RE))
|
|
16924
|
+
for (const m of content.matchAll(REQ_ID_RE)) {
|
|
16651
16925
|
reqIds.push(m[0]);
|
|
16926
|
+
}
|
|
16652
16927
|
}
|
|
16653
16928
|
}
|
|
16654
16929
|
const requirementIds = [...new Set(reqIds)];
|
|
@@ -16658,11 +16933,17 @@ function buildCodeTraceData(specsFile, srcDir) {
|
|
|
16658
16933
|
const links = [];
|
|
16659
16934
|
if (existsSync11(srcDir)) {
|
|
16660
16935
|
for (const file of collectFiles(srcDir, (ext) => ext in EXT_TO_LANG)) {
|
|
16661
|
-
|
|
16936
|
+
let code;
|
|
16937
|
+
try {
|
|
16938
|
+
code = readFileSync6(file, "utf-8");
|
|
16939
|
+
} catch {
|
|
16940
|
+
continue;
|
|
16941
|
+
}
|
|
16662
16942
|
const refs = /* @__PURE__ */ new Set();
|
|
16663
16943
|
for (const m of code.matchAll(REQ_ID_RE)) {
|
|
16664
|
-
if (reqSet.has(m[0]))
|
|
16944
|
+
if (reqSet.has(m[0])) {
|
|
16665
16945
|
refs.add(m[0]);
|
|
16946
|
+
}
|
|
16666
16947
|
}
|
|
16667
16948
|
for (const reqId of refs) {
|
|
16668
16949
|
fileSet.add(file);
|
|
@@ -16714,8 +16995,9 @@ Requirements: ${data.requirementIds.length}, referenced in code: ${covered.lengt
|
|
|
16714
16995
|
console.log(` Requirements: ${data.requirementIds.length}, covered: ${covered}, uncovered: ${uncovered.length}`);
|
|
16715
16996
|
if (uncovered.length > 0) {
|
|
16716
16997
|
console.log("\n Uncovered requirements (no code reference):");
|
|
16717
|
-
for (const r of uncovered)
|
|
16998
|
+
for (const r of uncovered) {
|
|
16718
16999
|
console.log(` \u2717 ${r}`);
|
|
17000
|
+
}
|
|
16719
17001
|
const strict = flags["strict"] === true;
|
|
16720
17002
|
console.log(strict ? "\n\u274C Traceability incomplete." : "\n\u26A0 Traceability incomplete (use --strict to fail the command).");
|
|
16721
17003
|
return strict ? ExitCode.GENERAL_ERROR : ExitCode.SUCCESS;
|
|
@@ -16764,10 +17046,12 @@ async function handleTraceVerify(flags = {}) {
|
|
|
16764
17046
|
console.log(`Requirements: ${covered.length}/${data.requirementIds.length} referenced in ${srcDir}`);
|
|
16765
17047
|
if (gaps.length > 0) {
|
|
16766
17048
|
console.log("Gaps (requirements not referenced in code):");
|
|
16767
|
-
for (const id of gaps)
|
|
17049
|
+
for (const id of gaps) {
|
|
16768
17050
|
console.log(` - ${id}`);
|
|
16769
|
-
|
|
17051
|
+
}
|
|
17052
|
+
if (flags["strict"] === true) {
|
|
16770
17053
|
return ExitCode.VALIDATION_ERROR;
|
|
17054
|
+
}
|
|
16771
17055
|
} else {
|
|
16772
17056
|
console.log("No gaps found \u2014 every requirement is referenced in code.");
|
|
16773
17057
|
}
|
|
@@ -16910,22 +17194,32 @@ var EXT_TO_LANG = {
|
|
|
16910
17194
|
var WALK_IGNORE = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "coverage", ".next", "build"]);
|
|
16911
17195
|
function collectFiles(target, extFilter) {
|
|
16912
17196
|
const stat = statSync(target);
|
|
16913
|
-
if (stat.isFile())
|
|
17197
|
+
if (stat.isFile()) {
|
|
16914
17198
|
return [target];
|
|
17199
|
+
}
|
|
16915
17200
|
const out = [];
|
|
16916
17201
|
const walk = (dir) => {
|
|
16917
|
-
|
|
16918
|
-
|
|
17202
|
+
let entries;
|
|
17203
|
+
try {
|
|
17204
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
17205
|
+
} catch {
|
|
17206
|
+
return;
|
|
17207
|
+
}
|
|
17208
|
+
for (const entry of entries) {
|
|
17209
|
+
if (entry.name.startsWith(".") && entry.name !== ".") {
|
|
16919
17210
|
continue;
|
|
16920
|
-
|
|
17211
|
+
}
|
|
17212
|
+
if (WALK_IGNORE.has(entry.name)) {
|
|
16921
17213
|
continue;
|
|
17214
|
+
}
|
|
16922
17215
|
const full = joinPath(dir, entry.name);
|
|
16923
17216
|
if (entry.isDirectory()) {
|
|
16924
17217
|
walk(full);
|
|
16925
17218
|
} else if (entry.isFile()) {
|
|
16926
17219
|
const ext = entry.name.split(".").pop() ?? "";
|
|
16927
|
-
if (!extFilter || extFilter(ext))
|
|
17220
|
+
if (!extFilter || extFilter(ext)) {
|
|
16928
17221
|
out.push(full);
|
|
17222
|
+
}
|
|
16929
17223
|
}
|
|
16930
17224
|
}
|
|
16931
17225
|
};
|
|
@@ -16955,10 +17249,12 @@ function loadCodeGraph() {
|
|
|
16955
17249
|
try {
|
|
16956
17250
|
if (existsSync11(CODEGRAPH_STATE_FILE)) {
|
|
16957
17251
|
const data = JSON.parse(readFileSync6(CODEGRAPH_STATE_FILE, "utf-8"));
|
|
16958
|
-
for (const node of data.nodes ?? [])
|
|
17252
|
+
for (const node of data.nodes ?? []) {
|
|
16959
17253
|
engine.addNode(node);
|
|
16960
|
-
|
|
17254
|
+
}
|
|
17255
|
+
for (const edge of data.edges ?? []) {
|
|
16961
17256
|
engine.addEdge(edge);
|
|
17257
|
+
}
|
|
16962
17258
|
}
|
|
16963
17259
|
} catch {
|
|
16964
17260
|
}
|
|
@@ -17270,11 +17566,13 @@ function resolveImportToFiles(moduleName, defFilesByName, filesByBasename) {
|
|
|
17270
17566
|
if (candidates.length === 0 && filesByBasename) {
|
|
17271
17567
|
return [...filesByBasename.get(last.replace(/\.[a-z]+$/i, "")) ?? []];
|
|
17272
17568
|
}
|
|
17273
|
-
if (candidates.length <= 1)
|
|
17569
|
+
if (candidates.length <= 1) {
|
|
17274
17570
|
return candidates;
|
|
17571
|
+
}
|
|
17275
17572
|
const middle = segs.slice(0, -1).map((s) => s.toLowerCase());
|
|
17276
|
-
if (middle.length === 0)
|
|
17573
|
+
if (middle.length === 0) {
|
|
17277
17574
|
return candidates;
|
|
17575
|
+
}
|
|
17278
17576
|
const scored = candidates.map((f) => {
|
|
17279
17577
|
const parts = f.toLowerCase().split(/[\\/]/);
|
|
17280
17578
|
const score = middle.filter((m) => parts.some((p) => p === m || p.includes(m) || m.includes(p))).length;
|
|
@@ -17288,8 +17586,9 @@ function resolveFileEdges(nodes, edges) {
|
|
|
17288
17586
|
const fileEdges = /* @__PURE__ */ new Map();
|
|
17289
17587
|
for (const e of edges) {
|
|
17290
17588
|
for (const to of resolveImportToFiles(e.to, defFiles, filesByBasename)) {
|
|
17291
|
-
if (to === e.from)
|
|
17589
|
+
if (to === e.from) {
|
|
17292
17590
|
continue;
|
|
17591
|
+
}
|
|
17293
17592
|
fileEdges.set(`${e.from} ${to} ${e.kind}`, { from: e.from, to, kind: e.kind });
|
|
17294
17593
|
}
|
|
17295
17594
|
}
|
|
@@ -17300,8 +17599,9 @@ function findDependencyCycles(nodes, edges) {
|
|
|
17300
17599
|
const adj = /* @__PURE__ */ new Map();
|
|
17301
17600
|
for (const e of edges) {
|
|
17302
17601
|
for (const to of resolveImportToFiles(e.to, defFiles, filesByBasename)) {
|
|
17303
|
-
if (to === e.from)
|
|
17602
|
+
if (to === e.from) {
|
|
17304
17603
|
continue;
|
|
17604
|
+
}
|
|
17305
17605
|
const set = adj.get(e.from) ?? /* @__PURE__ */ new Set();
|
|
17306
17606
|
set.add(to);
|
|
17307
17607
|
adj.set(e.from, set);
|
|
@@ -17314,12 +17614,15 @@ function findDependencyCycles(nodes, edges) {
|
|
|
17314
17614
|
const sccs = [];
|
|
17315
17615
|
let idx = 0;
|
|
17316
17616
|
const allNodes = /* @__PURE__ */ new Set([...adj.keys()]);
|
|
17317
|
-
for (const set of adj.values())
|
|
17318
|
-
for (const t of set)
|
|
17617
|
+
for (const set of adj.values()) {
|
|
17618
|
+
for (const t of set) {
|
|
17319
17619
|
allNodes.add(t);
|
|
17620
|
+
}
|
|
17621
|
+
}
|
|
17320
17622
|
for (const start of allNodes) {
|
|
17321
|
-
if (index.has(start))
|
|
17623
|
+
if (index.has(start)) {
|
|
17322
17624
|
continue;
|
|
17625
|
+
}
|
|
17323
17626
|
const work = [];
|
|
17324
17627
|
const pushNode = (v) => {
|
|
17325
17628
|
index.set(v, idx);
|
|
@@ -17349,13 +17652,15 @@ function findDependencyCycles(nodes, edges) {
|
|
|
17349
17652
|
onStack.delete(w);
|
|
17350
17653
|
comp.push(w);
|
|
17351
17654
|
} while (w !== frame.v);
|
|
17352
|
-
if (comp.length > 1)
|
|
17655
|
+
if (comp.length > 1) {
|
|
17353
17656
|
sccs.push(comp);
|
|
17657
|
+
}
|
|
17354
17658
|
}
|
|
17355
17659
|
work.pop();
|
|
17356
17660
|
const parent = work[work.length - 1];
|
|
17357
|
-
if (parent)
|
|
17661
|
+
if (parent) {
|
|
17358
17662
|
low.set(parent.v, Math.min(low.get(parent.v), low.get(frame.v)));
|
|
17663
|
+
}
|
|
17359
17664
|
}
|
|
17360
17665
|
}
|
|
17361
17666
|
}
|
|
@@ -17363,8 +17668,9 @@ function findDependencyCycles(nodes, edges) {
|
|
|
17363
17668
|
}
|
|
17364
17669
|
function loadGraphFromPath(path) {
|
|
17365
17670
|
try {
|
|
17366
|
-
if (!existsSync11(path))
|
|
17671
|
+
if (!existsSync11(path)) {
|
|
17367
17672
|
return null;
|
|
17673
|
+
}
|
|
17368
17674
|
const data = JSON.parse(readFileSync6(path, "utf-8"));
|
|
17369
17675
|
return { nodes: data.nodes ?? [], edges: data.edges ?? [] };
|
|
17370
17676
|
} catch {
|
|
@@ -17386,8 +17692,9 @@ var CG_SUBCOMMAND_HELP = {
|
|
|
17386
17692
|
languages: "musubix cg languages\n List the source languages the parser supports."
|
|
17387
17693
|
};
|
|
17388
17694
|
function cgSubcommandHelp(sub) {
|
|
17389
|
-
if (sub && CG_SUBCOMMAND_HELP[sub])
|
|
17695
|
+
if (sub && CG_SUBCOMMAND_HELP[sub]) {
|
|
17390
17696
|
return CG_SUBCOMMAND_HELP[sub];
|
|
17697
|
+
}
|
|
17391
17698
|
return showHelp("cg") + "\n\nSubcommands: " + Object.keys(CG_SUBCOMMAND_HELP).join(", ") + "\nRun `musubix cg <subcommand> --help` for details.";
|
|
17392
17699
|
}
|
|
17393
17700
|
async function handleCodegraph(sub, args) {
|
|
@@ -17419,8 +17726,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17419
17726
|
for (const file of files) {
|
|
17420
17727
|
const ext = file.split(".").pop() ?? "";
|
|
17421
17728
|
const lang = EXT_TO_LANG[ext];
|
|
17422
|
-
if (!lang)
|
|
17729
|
+
if (!lang) {
|
|
17423
17730
|
continue;
|
|
17731
|
+
}
|
|
17424
17732
|
const content = readFileSync6(file, "utf-8");
|
|
17425
17733
|
const nodes = parser.parse(content, lang);
|
|
17426
17734
|
for (const node of nodes) {
|
|
@@ -17453,8 +17761,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17453
17761
|
savedEdges.push(edge);
|
|
17454
17762
|
}
|
|
17455
17763
|
for (const child of node.children ?? []) {
|
|
17456
|
-
if (child.kind !== "method" || !child.name)
|
|
17764
|
+
if (child.kind !== "method" || !child.name) {
|
|
17457
17765
|
continue;
|
|
17766
|
+
}
|
|
17458
17767
|
const mEntry = {
|
|
17459
17768
|
id: `${file}:${node.name}.${child.name}`,
|
|
17460
17769
|
name: child.name,
|
|
@@ -17481,23 +17790,27 @@ async function handleCodegraph(sub, args) {
|
|
|
17481
17790
|
const localDefs = fileDefines.get(file);
|
|
17482
17791
|
const denylist = BUILTINS_BY_LANG[lang];
|
|
17483
17792
|
for (const name of calls) {
|
|
17484
|
-
if (denylist?.has(name))
|
|
17793
|
+
if (denylist?.has(name)) {
|
|
17485
17794
|
continue;
|
|
17486
|
-
|
|
17795
|
+
}
|
|
17796
|
+
if (localDefs?.has(name)) {
|
|
17487
17797
|
continue;
|
|
17798
|
+
}
|
|
17488
17799
|
const defs = globalFnToFiles.get(name);
|
|
17489
|
-
if (!defs || defs.size !== 1)
|
|
17800
|
+
if (!defs || defs.size !== 1) {
|
|
17490
17801
|
continue;
|
|
17802
|
+
}
|
|
17491
17803
|
const target = [...defs][0];
|
|
17492
|
-
if (target === file)
|
|
17804
|
+
if (target === file) {
|
|
17493
17805
|
continue;
|
|
17806
|
+
}
|
|
17494
17807
|
const edge = { from: file, to: name, kind: "calls" };
|
|
17495
17808
|
engine.addEdge(edge);
|
|
17496
17809
|
savedEdges.push(edge);
|
|
17497
17810
|
}
|
|
17498
17811
|
}
|
|
17499
17812
|
const uniqueNodes = Array.from(new Map(savedNodes.map((n) => [n.id, n])).values());
|
|
17500
|
-
const uniqueEdges = Array.from(new Map(savedEdges.map((e) => [`${e.from}
|
|
17813
|
+
const uniqueEdges = Array.from(new Map(savedEdges.map((e) => [`${e.from} ${e.to} ${e.kind}`, e])).values());
|
|
17501
17814
|
saveCodeGraph(uniqueNodes, uniqueEdges);
|
|
17502
17815
|
console.log(`\u2705 Indexed ${targetPath}: ${indexedFiles} file(s), ${uniqueNodes.length} nodes, ${uniqueEdges.length} edges`);
|
|
17503
17816
|
console.log(` Saved to ${CODEGRAPH_STATE_FILE}`);
|
|
@@ -17520,8 +17833,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17520
17833
|
console.log(`Results for "${query}": ${results.length} found`);
|
|
17521
17834
|
for (const r of results.slice(0, 20)) {
|
|
17522
17835
|
const node = r.node ?? r;
|
|
17523
|
-
if (node?.name)
|
|
17836
|
+
if (node?.name) {
|
|
17524
17837
|
console.log(` ${node.name}${node.filePath ? ` (${node.filePath})` : ""}`);
|
|
17838
|
+
}
|
|
17525
17839
|
}
|
|
17526
17840
|
return ExitCode.SUCCESS;
|
|
17527
17841
|
}
|
|
@@ -17539,8 +17853,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17539
17853
|
files.add(n.filePath);
|
|
17540
17854
|
}
|
|
17541
17855
|
const edgeKinds = /* @__PURE__ */ new Map();
|
|
17542
|
-
for (const e of edges)
|
|
17856
|
+
for (const e of edges) {
|
|
17543
17857
|
edgeKinds.set(e.kind, (edgeKinds.get(e.kind) ?? 0) + 1);
|
|
17858
|
+
}
|
|
17544
17859
|
console.log(`Files: ${files.size}`);
|
|
17545
17860
|
if (nodeKinds.size > 0) {
|
|
17546
17861
|
const parts = [...nodeKinds.entries()].sort((a, b) => b[1] - a[1]).map(([k, v]) => `${k}=${v}`);
|
|
@@ -17552,14 +17867,16 @@ async function handleCodegraph(sub, args) {
|
|
|
17552
17867
|
}
|
|
17553
17868
|
const callInDegree = /* @__PURE__ */ new Map();
|
|
17554
17869
|
for (const e of edges) {
|
|
17555
|
-
if (e.kind === "calls")
|
|
17870
|
+
if (e.kind === "calls") {
|
|
17556
17871
|
callInDegree.set(e.to, (callInDegree.get(e.to) ?? 0) + 1);
|
|
17872
|
+
}
|
|
17557
17873
|
}
|
|
17558
17874
|
const top = [...callInDegree.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
17559
17875
|
if (top.length > 0) {
|
|
17560
|
-
console.log(
|
|
17561
|
-
for (const [name, deg] of top)
|
|
17876
|
+
console.log("Top called functions:");
|
|
17877
|
+
for (const [name, deg] of top) {
|
|
17562
17878
|
console.log(` ${name} \u2014 ${deg} caller(s)`);
|
|
17879
|
+
}
|
|
17563
17880
|
}
|
|
17564
17881
|
return ExitCode.SUCCESS;
|
|
17565
17882
|
}
|
|
@@ -17572,8 +17889,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17572
17889
|
}
|
|
17573
17890
|
const fnCount = /* @__PURE__ */ new Map();
|
|
17574
17891
|
for (const n of nodes) {
|
|
17575
|
-
if (n.kind === "function")
|
|
17892
|
+
if (n.kind === "function") {
|
|
17576
17893
|
fnCount.set(n.filePath, (fnCount.get(n.filePath) ?? 0) + 1);
|
|
17894
|
+
}
|
|
17577
17895
|
}
|
|
17578
17896
|
const extDeps = /* @__PURE__ */ new Map();
|
|
17579
17897
|
for (const e of edges) {
|
|
@@ -17586,27 +17904,32 @@ async function handleCodegraph(sub, args) {
|
|
|
17586
17904
|
const { defFiles } = buildResolutionMaps(nodes);
|
|
17587
17905
|
const dependents = /* @__PURE__ */ new Map();
|
|
17588
17906
|
for (const e of edges) {
|
|
17589
|
-
if (e.kind !== "calls")
|
|
17907
|
+
if (e.kind !== "calls") {
|
|
17590
17908
|
continue;
|
|
17909
|
+
}
|
|
17591
17910
|
const defs = defFiles.get(e.to);
|
|
17592
|
-
if (!defs || defs.size !== 1)
|
|
17911
|
+
if (!defs || defs.size !== 1) {
|
|
17593
17912
|
continue;
|
|
17913
|
+
}
|
|
17594
17914
|
const target = [...defs][0];
|
|
17595
|
-
if (target === e.from)
|
|
17915
|
+
if (target === e.from) {
|
|
17596
17916
|
continue;
|
|
17917
|
+
}
|
|
17597
17918
|
const set = dependents.get(target) ?? /* @__PURE__ */ new Set();
|
|
17598
17919
|
set.add(e.from);
|
|
17599
17920
|
dependents.set(target, set);
|
|
17600
17921
|
}
|
|
17601
17922
|
const cyclePenalty = /* @__PURE__ */ new Map();
|
|
17602
17923
|
for (const scc of findDependencyCycles(nodes, edges)) {
|
|
17603
|
-
for (const f of scc)
|
|
17924
|
+
for (const f of scc) {
|
|
17604
17925
|
cyclePenalty.set(f, scc.length - 1);
|
|
17926
|
+
}
|
|
17605
17927
|
}
|
|
17606
17928
|
const cands = [];
|
|
17607
17929
|
for (const [file, fns] of fnCount) {
|
|
17608
|
-
if (fns < 1 || isTestFile(file))
|
|
17930
|
+
if (fns < 1 || isTestFile(file)) {
|
|
17609
17931
|
continue;
|
|
17932
|
+
}
|
|
17610
17933
|
const deps = extDeps.get(file)?.size ?? 0;
|
|
17611
17934
|
const users = dependents.get(file)?.size ?? 0;
|
|
17612
17935
|
const cycle = cyclePenalty.get(file) ?? 0;
|
|
@@ -17656,8 +17979,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17656
17979
|
console.log(`Dependencies (${matched.length} edges across ${byFile.size} file(s)):`);
|
|
17657
17980
|
for (const [file, targets] of byFile) {
|
|
17658
17981
|
console.log(` ${file}`);
|
|
17659
|
-
for (const t of [...new Set(targets)].sort())
|
|
17982
|
+
for (const t of [...new Set(targets)].sort()) {
|
|
17660
17983
|
console.log(` \u2192 ${t}`);
|
|
17984
|
+
}
|
|
17661
17985
|
}
|
|
17662
17986
|
return ExitCode.SUCCESS;
|
|
17663
17987
|
}
|
|
@@ -17667,19 +17991,23 @@ async function handleCodegraph(sub, args) {
|
|
|
17667
17991
|
let filter;
|
|
17668
17992
|
for (let i = 0; i < args.length; i++) {
|
|
17669
17993
|
const a = args[i];
|
|
17670
|
-
if (a === "--direct")
|
|
17994
|
+
if (a === "--direct") {
|
|
17671
17995
|
continue;
|
|
17996
|
+
}
|
|
17672
17997
|
if (a === "--depth") {
|
|
17673
17998
|
const v = Number(args[++i]);
|
|
17674
|
-
if (Number.isFinite(v) && v >= 1)
|
|
17999
|
+
if (Number.isFinite(v) && v >= 1) {
|
|
17675
18000
|
maxDepth = Math.floor(v);
|
|
18001
|
+
}
|
|
17676
18002
|
continue;
|
|
17677
18003
|
}
|
|
17678
|
-
if (!a.startsWith("--") && filter === void 0)
|
|
18004
|
+
if (!a.startsWith("--") && filter === void 0) {
|
|
17679
18005
|
filter = a;
|
|
18006
|
+
}
|
|
17680
18007
|
}
|
|
17681
|
-
if (maxDepth === 1)
|
|
18008
|
+
if (maxDepth === 1) {
|
|
17682
18009
|
directOnly = true;
|
|
18010
|
+
}
|
|
17683
18011
|
if (!filter) {
|
|
17684
18012
|
console.error("\u274C Usage: musubix cg impact <path-fragment> [--direct] [--depth N]");
|
|
17685
18013
|
return ExitCode.VALIDATION_ERROR;
|
|
@@ -17693,8 +18021,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17693
18021
|
const dependents = /* @__PURE__ */ new Map();
|
|
17694
18022
|
for (const e of edges) {
|
|
17695
18023
|
for (const defFile of resolveImportToFiles(e.to, defFiles, filesByBasename)) {
|
|
17696
|
-
if (defFile === e.from)
|
|
18024
|
+
if (defFile === e.from) {
|
|
17697
18025
|
continue;
|
|
18026
|
+
}
|
|
17698
18027
|
const set = dependents.get(defFile) ?? /* @__PURE__ */ new Set();
|
|
17699
18028
|
set.add(e.from);
|
|
17700
18029
|
dependents.set(defFile, set);
|
|
@@ -17709,8 +18038,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17709
18038
|
const direct = /* @__PURE__ */ new Set();
|
|
17710
18039
|
for (const s of seeds) {
|
|
17711
18040
|
for (const dep of dependents.get(s) ?? []) {
|
|
17712
|
-
if (!seedSet.has(dep))
|
|
18041
|
+
if (!seedSet.has(dep)) {
|
|
17713
18042
|
direct.add(dep);
|
|
18043
|
+
}
|
|
17714
18044
|
}
|
|
17715
18045
|
}
|
|
17716
18046
|
const affected = /* @__PURE__ */ new Set();
|
|
@@ -17718,11 +18048,13 @@ async function handleCodegraph(sub, args) {
|
|
|
17718
18048
|
const queue = seeds.map((s) => [s, 0]);
|
|
17719
18049
|
while (queue.length > 0) {
|
|
17720
18050
|
const [f, d] = queue.shift();
|
|
17721
|
-
if (d >= maxDepth)
|
|
18051
|
+
if (d >= maxDepth) {
|
|
17722
18052
|
continue;
|
|
18053
|
+
}
|
|
17723
18054
|
for (const dep of dependents.get(f) ?? []) {
|
|
17724
|
-
if (seedSet.has(dep))
|
|
18055
|
+
if (seedSet.has(dep)) {
|
|
17725
18056
|
continue;
|
|
18057
|
+
}
|
|
17726
18058
|
affected.add(dep);
|
|
17727
18059
|
if (!seen.has(dep)) {
|
|
17728
18060
|
seen.add(dep);
|
|
@@ -17744,16 +18076,18 @@ async function handleCodegraph(sub, args) {
|
|
|
17744
18076
|
return ExitCode.SUCCESS;
|
|
17745
18077
|
}
|
|
17746
18078
|
console.log(`Impact of ${seeds.length} file(s) matching '${filter}':`);
|
|
17747
|
-
for (const s of seeds)
|
|
18079
|
+
for (const s of seeds) {
|
|
17748
18080
|
console.log(` \u29BF ${s}`);
|
|
18081
|
+
}
|
|
17749
18082
|
if (affected.size === 0) {
|
|
17750
18083
|
console.log(" No other indexed files depend on these (no transitive impact found).");
|
|
17751
18084
|
return ExitCode.SUCCESS;
|
|
17752
18085
|
}
|
|
17753
18086
|
console.log(`
|
|
17754
18087
|
${direct.size} direct dependent(s):`);
|
|
17755
|
-
for (const a of [...direct].sort())
|
|
18088
|
+
for (const a of [...direct].sort()) {
|
|
17756
18089
|
console.log(` \u2190 ${a}`);
|
|
18090
|
+
}
|
|
17757
18091
|
if (directOnly) {
|
|
17758
18092
|
if (indirect.length > 0) {
|
|
17759
18093
|
console.log(`
|
|
@@ -17763,8 +18097,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17763
18097
|
const depthNote = Number.isFinite(maxDepth) ? ` (within depth ${maxDepth})` : "";
|
|
17764
18098
|
console.log(`
|
|
17765
18099
|
${indirect.length} indirect (transitive) dependent(s)${depthNote}:`);
|
|
17766
|
-
for (const a of indirect.sort())
|
|
18100
|
+
for (const a of indirect.sort()) {
|
|
17767
18101
|
console.log(` \u2190 ${a}`);
|
|
18102
|
+
}
|
|
17768
18103
|
}
|
|
17769
18104
|
const scope = Number.isFinite(maxDepth) ? ` within depth ${maxDepth}` : "";
|
|
17770
18105
|
console.log(`
|
|
@@ -17825,17 +18160,19 @@ async function handleCodegraph(sub, args) {
|
|
|
17825
18160
|
const minDist = targets.length ? Math.min(...targets.map((f) => dist.get(f))) : Infinity;
|
|
17826
18161
|
const nearest = targets.filter((f) => dist.get(f) === minDist);
|
|
17827
18162
|
if (nearest.length === 0) {
|
|
17828
|
-
if (asJson)
|
|
18163
|
+
if (asJson) {
|
|
17829
18164
|
console.log(JSON.stringify({ from: fromFrag, to: toFrag, paths: [] }, null, 2));
|
|
17830
|
-
else
|
|
18165
|
+
} else {
|
|
17831
18166
|
console.log(`No dependency path from '${fromFrag}' to '${toFrag}'.`);
|
|
18167
|
+
}
|
|
17832
18168
|
return ExitCode.SUCCESS;
|
|
17833
18169
|
}
|
|
17834
18170
|
const CAP = showAll ? 20 : 1;
|
|
17835
18171
|
const paths = [];
|
|
17836
18172
|
const build = (node, tail) => {
|
|
17837
|
-
if (paths.length >= CAP)
|
|
18173
|
+
if (paths.length >= CAP) {
|
|
17838
18174
|
return;
|
|
18175
|
+
}
|
|
17839
18176
|
const chain = [node, ...tail];
|
|
17840
18177
|
const ps = preds.get(node) ?? [];
|
|
17841
18178
|
if (ps.length === 0) {
|
|
@@ -17843,14 +18180,16 @@ async function handleCodegraph(sub, args) {
|
|
|
17843
18180
|
return;
|
|
17844
18181
|
}
|
|
17845
18182
|
for (const p of ps) {
|
|
17846
|
-
if (paths.length >= CAP)
|
|
18183
|
+
if (paths.length >= CAP) {
|
|
17847
18184
|
return;
|
|
18185
|
+
}
|
|
17848
18186
|
build(p, chain);
|
|
17849
18187
|
}
|
|
17850
18188
|
};
|
|
17851
18189
|
for (const t of nearest) {
|
|
17852
|
-
if (paths.length >= CAP)
|
|
18190
|
+
if (paths.length >= CAP) {
|
|
17853
18191
|
break;
|
|
18192
|
+
}
|
|
17854
18193
|
build(t, []);
|
|
17855
18194
|
}
|
|
17856
18195
|
if (asJson) {
|
|
@@ -17878,10 +18217,11 @@ async function handleCodegraph(sub, args) {
|
|
|
17878
18217
|
let limit = 20;
|
|
17879
18218
|
let filter;
|
|
17880
18219
|
for (const a of args) {
|
|
17881
|
-
if (/^\d+$/.test(a))
|
|
18220
|
+
if (/^\d+$/.test(a)) {
|
|
17882
18221
|
limit = Number(a);
|
|
17883
|
-
else if (!a.startsWith("--") && filter === void 0)
|
|
18222
|
+
} else if (!a.startsWith("--") && filter === void 0) {
|
|
17884
18223
|
filter = a;
|
|
18224
|
+
}
|
|
17885
18225
|
}
|
|
17886
18226
|
const { nodes, edges } = loadCodeGraphData();
|
|
17887
18227
|
if (nodes.length === 0) {
|
|
@@ -17889,8 +18229,9 @@ async function handleCodegraph(sub, args) {
|
|
|
17889
18229
|
return ExitCode.SUCCESS;
|
|
17890
18230
|
}
|
|
17891
18231
|
let cycles = findDependencyCycles(nodes, edges);
|
|
17892
|
-
if (filter)
|
|
18232
|
+
if (filter) {
|
|
17893
18233
|
cycles = cycles.filter((c) => c.some((f) => f.includes(filter)));
|
|
18234
|
+
}
|
|
17894
18235
|
if (args.includes("--json")) {
|
|
17895
18236
|
console.log(JSON.stringify({
|
|
17896
18237
|
count: cycles.length,
|
|
@@ -17909,10 +18250,12 @@ async function handleCodegraph(sub, args) {
|
|
|
17909
18250
|
const sorted = [...c].sort();
|
|
17910
18251
|
console.log(`
|
|
17911
18252
|
Cycle ${i + 1} (${c.length} files):`);
|
|
17912
|
-
for (const f of sorted.slice(0, PER_CYCLE))
|
|
18253
|
+
for (const f of sorted.slice(0, PER_CYCLE)) {
|
|
17913
18254
|
console.log(` \u21BB ${f}`);
|
|
17914
|
-
|
|
18255
|
+
}
|
|
18256
|
+
if (sorted.length > PER_CYCLE) {
|
|
17915
18257
|
console.log(` \u2026 and ${sorted.length - PER_CYCLE} more`);
|
|
18258
|
+
}
|
|
17916
18259
|
});
|
|
17917
18260
|
return ExitCode.SUCCESS;
|
|
17918
18261
|
}
|
|
@@ -17924,13 +18267,15 @@ async function handleCodegraph(sub, args) {
|
|
|
17924
18267
|
const a = args[i];
|
|
17925
18268
|
if (a === "--max-cycles") {
|
|
17926
18269
|
const v = Number(args[++i]);
|
|
17927
|
-
if (Number.isFinite(v) && v >= 0)
|
|
18270
|
+
if (Number.isFinite(v) && v >= 0) {
|
|
17928
18271
|
maxCycles = Math.floor(v);
|
|
18272
|
+
}
|
|
17929
18273
|
} else if (a === "--forbid") {
|
|
17930
18274
|
for (const spec of (args[++i] ?? "").split(",")) {
|
|
17931
18275
|
const [from, to] = spec.split(":");
|
|
17932
|
-
if (from && to)
|
|
18276
|
+
if (from && to) {
|
|
17933
18277
|
forbidRules.push({ from: from.trim(), to: to.trim() });
|
|
18278
|
+
}
|
|
17934
18279
|
}
|
|
17935
18280
|
}
|
|
17936
18281
|
}
|
|
@@ -17971,9 +18316,11 @@ async function handleCodegraph(sub, args) {
|
|
|
17971
18316
|
} else {
|
|
17972
18317
|
for (const c of checks) {
|
|
17973
18318
|
console.log(` ${c.pass ? "\u2705" : "\u274C"} ${c.rule} \u2014 ${c.detail}`);
|
|
17974
|
-
if (!c.pass)
|
|
17975
|
-
for (const o of c.offenders ?? [])
|
|
18319
|
+
if (!c.pass) {
|
|
18320
|
+
for (const o of c.offenders ?? []) {
|
|
17976
18321
|
console.log(` ${o}`);
|
|
18322
|
+
}
|
|
18323
|
+
}
|
|
17977
18324
|
}
|
|
17978
18325
|
console.log(failed.length === 0 ? `
|
|
17979
18326
|
\u2705 Gate passed (${checks.length} check(s)).` : `
|
|
@@ -18031,14 +18378,17 @@ async function handleCodegraph(sub, args) {
|
|
|
18031
18378
|
}
|
|
18032
18379
|
const CAP = 25;
|
|
18033
18380
|
const list = (label, items) => {
|
|
18034
|
-
if (items.length === 0)
|
|
18381
|
+
if (items.length === 0) {
|
|
18035
18382
|
return;
|
|
18383
|
+
}
|
|
18036
18384
|
console.log(`
|
|
18037
18385
|
${label} (${items.length}):`);
|
|
18038
|
-
for (const s of items.slice(0, CAP))
|
|
18386
|
+
for (const s of items.slice(0, CAP)) {
|
|
18039
18387
|
console.log(` ${s}`);
|
|
18040
|
-
|
|
18388
|
+
}
|
|
18389
|
+
if (items.length > CAP) {
|
|
18041
18390
|
console.log(` \u2026 and ${items.length - CAP} more`);
|
|
18391
|
+
}
|
|
18042
18392
|
};
|
|
18043
18393
|
console.log(`Diff ${baselinePath} \u2192 ${currentPath ?? ".musubix/codegraph.json"}`);
|
|
18044
18394
|
console.log(` Files: +${filesAdded.length} / -${filesRemoved.length} Dependency edges: +${edgesAdded.length} / -${edgesRemoved.length}`);
|
|
@@ -18066,8 +18416,9 @@ async function handleCodegraph(sub, args) {
|
|
|
18066
18416
|
outPath = args[++i];
|
|
18067
18417
|
continue;
|
|
18068
18418
|
}
|
|
18069
|
-
if (!a.startsWith("--") && filter === void 0)
|
|
18419
|
+
if (!a.startsWith("--") && filter === void 0) {
|
|
18070
18420
|
filter = a;
|
|
18421
|
+
}
|
|
18071
18422
|
}
|
|
18072
18423
|
if (format !== "dot" && format !== "json") {
|
|
18073
18424
|
console.error(`\u274C Unknown format '${format}'. Use dot or json.`);
|
|
@@ -18082,11 +18433,13 @@ async function handleCodegraph(sub, args) {
|
|
|
18082
18433
|
const fileEdges = /* @__PURE__ */ new Map();
|
|
18083
18434
|
for (const e of edges) {
|
|
18084
18435
|
for (const to of resolveImportToFiles(e.to, defFiles, filesByBasename)) {
|
|
18085
|
-
if (to === e.from)
|
|
18436
|
+
if (to === e.from) {
|
|
18086
18437
|
continue;
|
|
18087
|
-
|
|
18438
|
+
}
|
|
18439
|
+
if (filter && !e.from.includes(filter) && !to.includes(filter)) {
|
|
18088
18440
|
continue;
|
|
18089
|
-
|
|
18441
|
+
}
|
|
18442
|
+
fileEdges.set(`${e.from} ${to} ${e.kind}`, { from: e.from, to, kind: e.kind });
|
|
18090
18443
|
}
|
|
18091
18444
|
}
|
|
18092
18445
|
const rels = [...fileEdges.values()];
|
|
@@ -18116,13 +18469,15 @@ async function handleCodegraph(sub, args) {
|
|
|
18116
18469
|
lines.push(` subgraph "cluster_${ci++}" {`);
|
|
18117
18470
|
lines.push(` label="${dir.replace(/"/g, "")}";`);
|
|
18118
18471
|
lines.push(' style=rounded; color="#999999";');
|
|
18119
|
-
for (const f of files)
|
|
18472
|
+
for (const f of files) {
|
|
18120
18473
|
lines.push(` "${f}" [label="${label(f)}"];`);
|
|
18474
|
+
}
|
|
18121
18475
|
lines.push(" }");
|
|
18122
18476
|
}
|
|
18123
18477
|
} else {
|
|
18124
|
-
for (const f of [...fileSet].sort())
|
|
18478
|
+
for (const f of [...fileSet].sort()) {
|
|
18125
18479
|
lines.push(` "${f}" [label="${label(f)}"];`);
|
|
18480
|
+
}
|
|
18126
18481
|
}
|
|
18127
18482
|
for (const r of rels) {
|
|
18128
18483
|
const style = r.kind === "imports" ? " [style=dashed]" : "";
|
|
@@ -18352,8 +18707,9 @@ async function handleReqWizard() {
|
|
|
18352
18707
|
}
|
|
18353
18708
|
var _interviewer = null;
|
|
18354
18709
|
function getInterviewer() {
|
|
18355
|
-
if (!_interviewer)
|
|
18710
|
+
if (!_interviewer) {
|
|
18356
18711
|
_interviewer = createRequirementsInterviewer();
|
|
18712
|
+
}
|
|
18357
18713
|
return _interviewer;
|
|
18358
18714
|
}
|
|
18359
18715
|
async function handleReqInterview(args) {
|
|
@@ -18467,7 +18823,33 @@ async function handleDesignGenerate(filePath, outPath) {
|
|
|
18467
18823
|
for (const section of design.sections) {
|
|
18468
18824
|
console.log(`
|
|
18469
18825
|
## ${section.title}`);
|
|
18470
|
-
console.log(section.
|
|
18826
|
+
console.log(`Requirements: ${section.requirementIds.join(", ")}`);
|
|
18827
|
+
if (section.responsibilities.length > 0) {
|
|
18828
|
+
console.log("\nResponsibilities:");
|
|
18829
|
+
for (const r of section.responsibilities) {
|
|
18830
|
+
console.log(` - ${r}`);
|
|
18831
|
+
}
|
|
18832
|
+
}
|
|
18833
|
+
if (section.components.length > 0) {
|
|
18834
|
+
console.log("\nComponents:");
|
|
18835
|
+
for (const c of section.components) {
|
|
18836
|
+
const sigs = c.methods.map((m) => `${m.name}(${m.params}): ${m.returnType}`).join(", ");
|
|
18837
|
+
console.log(` - ${c.name} \u2014 ${c.responsibility}`);
|
|
18838
|
+
if (sigs) {
|
|
18839
|
+
console.log(` methods: ${sigs}`);
|
|
18840
|
+
}
|
|
18841
|
+
}
|
|
18842
|
+
}
|
|
18843
|
+
if (section.interfaces.length > 0) {
|
|
18844
|
+
console.log(`
|
|
18845
|
+
Interfaces: ${section.interfaces.join(", ")}`);
|
|
18846
|
+
}
|
|
18847
|
+
if (section.patterns.length > 0) {
|
|
18848
|
+
console.log(`Patterns: ${section.patterns.join(", ")}`);
|
|
18849
|
+
}
|
|
18850
|
+
if (section.dataEntities.length > 0) {
|
|
18851
|
+
console.log(`Data entities: ${section.dataEntities.join(", ")}`);
|
|
18852
|
+
}
|
|
18471
18853
|
}
|
|
18472
18854
|
return ExitCode.SUCCESS;
|
|
18473
18855
|
} catch (err) {
|
|
@@ -18567,22 +18949,34 @@ function extractCodegenTargets(content) {
|
|
|
18567
18949
|
if (trimmed.startsWith("{")) {
|
|
18568
18950
|
try {
|
|
18569
18951
|
const data = JSON.parse(content);
|
|
18952
|
+
const comps = (data.sections ?? []).flatMap((s) => s.components ?? []);
|
|
18953
|
+
if (comps.length > 0) {
|
|
18954
|
+
return comps.map((c) => ({
|
|
18955
|
+
name: toPascalCase(c.name ?? "Component"),
|
|
18956
|
+
type: "class",
|
|
18957
|
+
methods: c.methods ?? []
|
|
18958
|
+
}));
|
|
18959
|
+
}
|
|
18570
18960
|
const els = (data.elements ?? []).filter((e) => e.type === "component" || e.type === "container");
|
|
18571
18961
|
if (els.length > 0) {
|
|
18572
|
-
return els.map((e) => ({ name: toPascalCase(e.name ?? e.id ?? "Component"), type: "class" }));
|
|
18962
|
+
return els.map((e) => ({ name: toPascalCase(e.name ?? e.id ?? "Component"), type: "class", methods: [] }));
|
|
18573
18963
|
}
|
|
18574
18964
|
if (data.sections?.length) {
|
|
18575
|
-
return data.sections.map((s) => ({ name: toPascalCase(s.title ?? s.id ?? "Section"), type: "class" }));
|
|
18965
|
+
return data.sections.map((s) => ({ name: toPascalCase(s.title ?? s.id ?? "Section"), type: "class", methods: [] }));
|
|
18576
18966
|
}
|
|
18577
18967
|
} catch {
|
|
18578
18968
|
}
|
|
18579
18969
|
return [];
|
|
18580
18970
|
}
|
|
18581
|
-
const
|
|
18971
|
+
const parser = new MarkdownEARSParser();
|
|
18582
18972
|
const targets = [];
|
|
18583
|
-
|
|
18584
|
-
|
|
18585
|
-
targets.push({
|
|
18973
|
+
for (const req of parser.parse(content)) {
|
|
18974
|
+
const op = deriveOperation(req.text, req.title);
|
|
18975
|
+
targets.push({
|
|
18976
|
+
name: toPascalCase(req.title || req.id),
|
|
18977
|
+
type: "class",
|
|
18978
|
+
methods: [{ name: op, params: "", returnType: "void" }]
|
|
18979
|
+
});
|
|
18586
18980
|
}
|
|
18587
18981
|
return targets;
|
|
18588
18982
|
}
|
|
@@ -18599,7 +18993,8 @@ async function handleCodegen(nameOrFile, type = "class") {
|
|
|
18599
18993
|
for (const t of targets) {
|
|
18600
18994
|
const result2 = generator.generate({
|
|
18601
18995
|
templateType: t.type,
|
|
18602
|
-
name: t.name
|
|
18996
|
+
name: t.name,
|
|
18997
|
+
methods: t.methods.length > 0 ? t.methods : void 0
|
|
18603
18998
|
});
|
|
18604
18999
|
console.log(result2.code);
|
|
18605
19000
|
console.log("");
|
|
@@ -18636,8 +19031,9 @@ async function handleTestGen(filePath) {
|
|
|
18636
19031
|
for (const file of files) {
|
|
18637
19032
|
const content = readFileSync6(file, "utf-8");
|
|
18638
19033
|
const suite = generator.generate(content, "unit");
|
|
18639
|
-
if (!single)
|
|
19034
|
+
if (!single) {
|
|
18640
19035
|
console.log(`// \u2500\u2500 ${file} \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
|
|
19036
|
+
}
|
|
18641
19037
|
console.log(suite.code);
|
|
18642
19038
|
}
|
|
18643
19039
|
return ExitCode.SUCCESS;
|
|
@@ -18673,15 +19069,19 @@ async function handleSkills(sub, args) {
|
|
|
18673
19069
|
const content = readFileSync6(path, "utf-8");
|
|
18674
19070
|
const definition = JSON.parse(content);
|
|
18675
19071
|
const errors = [];
|
|
18676
|
-
if (!definition["name"])
|
|
19072
|
+
if (!definition["name"]) {
|
|
18677
19073
|
errors.push("Missing required field: name");
|
|
18678
|
-
|
|
19074
|
+
}
|
|
19075
|
+
if (!definition["description"]) {
|
|
18679
19076
|
errors.push("Missing required field: description");
|
|
18680
|
-
|
|
19077
|
+
}
|
|
19078
|
+
if (!definition["action"]) {
|
|
18681
19079
|
errors.push("Missing required field: action");
|
|
19080
|
+
}
|
|
18682
19081
|
if (errors.length > 0) {
|
|
18683
|
-
for (const e of errors)
|
|
19082
|
+
for (const e of errors) {
|
|
18684
19083
|
console.error(` \u274C ${e}`);
|
|
19084
|
+
}
|
|
18685
19085
|
return ExitCode.VALIDATION_ERROR;
|
|
18686
19086
|
}
|
|
18687
19087
|
console.log(`\u2705 Skill definition valid: ${definition["name"]}`);
|
|
@@ -18807,11 +19207,13 @@ async function handleKnowledge(sub, args, flags) {
|
|
|
18807
19207
|
const byType = await store.query({ type: filter });
|
|
18808
19208
|
const byText = await store.query({ text: filter });
|
|
18809
19209
|
const merged = /* @__PURE__ */ new Map();
|
|
18810
|
-
for (const e of [...byType, ...byText])
|
|
19210
|
+
for (const e of [...byType, ...byText]) {
|
|
18811
19211
|
merged.set(e.id, e);
|
|
19212
|
+
}
|
|
18812
19213
|
for (const e of await store.query({})) {
|
|
18813
|
-
if (e.id.toLowerCase().includes(filter.toLowerCase()))
|
|
19214
|
+
if (e.id.toLowerCase().includes(filter.toLowerCase())) {
|
|
18814
19215
|
merged.set(e.id, e);
|
|
19216
|
+
}
|
|
18815
19217
|
}
|
|
18816
19218
|
const results = [...merged.values()];
|
|
18817
19219
|
console.log(`Results: ${results.length} entities`);
|
|
@@ -18961,8 +19363,9 @@ async function knowledgeSourcesForTopic(topic, basePath = ".knowledge") {
|
|
|
18961
19363
|
const byText = await store.query({ text: topic });
|
|
18962
19364
|
const bySearch = await store.search(topic);
|
|
18963
19365
|
const merged = /* @__PURE__ */ new Map();
|
|
18964
|
-
for (const e of [...byText, ...bySearch])
|
|
19366
|
+
for (const e of [...byText, ...bySearch]) {
|
|
18965
19367
|
merged.set(e.id, e);
|
|
19368
|
+
}
|
|
18966
19369
|
return [...merged.values()].map((e) => ({
|
|
18967
19370
|
title: e.name ?? e.id,
|
|
18968
19371
|
type: "documentation",
|
|
@@ -18987,7 +19390,7 @@ async function handleDeepResearch(sub, args) {
|
|
|
18987
19390
|
const result = engine.research({ topic: question, depth: "medium" }, sources);
|
|
18988
19391
|
console.log(`Question: ${question}`);
|
|
18989
19392
|
console.log(`Confidence: ${result.confidence}`);
|
|
18990
|
-
console.log(`Sources: ${result.sources.length}${sources.length ?
|
|
19393
|
+
console.log(`Sources: ${result.sources.length}${sources.length ? " (from knowledge graph)" : ""}`);
|
|
18991
19394
|
console.log(`Answer: ${result.summary}`);
|
|
18992
19395
|
return ExitCode.SUCCESS;
|
|
18993
19396
|
}
|
|
@@ -19053,8 +19456,9 @@ async function handleScaffold(sub, args) {
|
|
|
19053
19456
|
console.log(` ${f}`);
|
|
19054
19457
|
}
|
|
19055
19458
|
} else {
|
|
19056
|
-
for (const e of result.errors)
|
|
19459
|
+
for (const e of result.errors) {
|
|
19057
19460
|
console.error(`\u274C ${e}`);
|
|
19461
|
+
}
|
|
19058
19462
|
return ExitCode.GENERAL_ERROR;
|
|
19059
19463
|
}
|
|
19060
19464
|
return ExitCode.SUCCESS;
|
|
@@ -19091,8 +19495,9 @@ describe('${name}', () => {
|
|
|
19091
19495
|
`
|
|
19092
19496
|
});
|
|
19093
19497
|
console.log(`\u2705 Scaffolded package: ${name}`);
|
|
19094
|
-
for (const f of created)
|
|
19498
|
+
for (const f of created) {
|
|
19095
19499
|
console.log(` ${f}`);
|
|
19500
|
+
}
|
|
19096
19501
|
} catch (err) {
|
|
19097
19502
|
console.error(`\u274C ${err instanceof Error ? err.message : String(err)}`);
|
|
19098
19503
|
return ExitCode.GENERAL_ERROR;
|
|
@@ -19126,8 +19531,9 @@ describe('${name}', () => {
|
|
|
19126
19531
|
`
|
|
19127
19532
|
});
|
|
19128
19533
|
console.log(`\u2705 Scaffolded skill: ${name}`);
|
|
19129
|
-
for (const f of created)
|
|
19534
|
+
for (const f of created) {
|
|
19130
19535
|
console.log(` ${f}`);
|
|
19536
|
+
}
|
|
19131
19537
|
} catch (err) {
|
|
19132
19538
|
console.error(`\u274C ${err instanceof Error ? err.message : String(err)}`);
|
|
19133
19539
|
return ExitCode.GENERAL_ERROR;
|
|
@@ -19240,7 +19646,7 @@ async function handleSynthesis(sub, args, flags = {}) {
|
|
|
19240
19646
|
return { input: input ?? "", output: output ?? "" };
|
|
19241
19647
|
});
|
|
19242
19648
|
const result = engine.synthesize(examples);
|
|
19243
|
-
console.log(
|
|
19649
|
+
console.log("Synthesized program:");
|
|
19244
19650
|
if (result) {
|
|
19245
19651
|
console.log(` Rule: ${result}`);
|
|
19246
19652
|
} else {
|
|
@@ -19310,7 +19716,7 @@ async function handleSynthesis(sub, args, flags = {}) {
|
|
|
19310
19716
|
}
|
|
19311
19717
|
}
|
|
19312
19718
|
const result = builder.execute(input);
|
|
19313
|
-
console.log(
|
|
19719
|
+
console.log("DSL output:");
|
|
19314
19720
|
console.log(` Input: ${input}`);
|
|
19315
19721
|
console.log(` Ops: ${ops.join(" \u2192 ")}`);
|
|
19316
19722
|
console.log(` Result: ${result}`);
|
|
@@ -19320,7 +19726,7 @@ async function handleSynthesis(sub, args, flags = {}) {
|
|
|
19320
19726
|
const { createVersionSpaceManager: createVersionSpaceManager2 } = await Promise.resolve().then(() => (init_dist12(), dist_exports12));
|
|
19321
19727
|
const manager = createVersionSpaceManager2();
|
|
19322
19728
|
const spaces = manager.getSpaces();
|
|
19323
|
-
console.log(
|
|
19729
|
+
console.log("Version space:");
|
|
19324
19730
|
console.log(` Spaces: ${spaces.size}`);
|
|
19325
19731
|
return ExitCode.SUCCESS;
|
|
19326
19732
|
}
|
|
@@ -19347,8 +19753,9 @@ function resolveTarget(args, verbs) {
|
|
|
19347
19753
|
const positional = args["args"] ?? [];
|
|
19348
19754
|
const sub = args["subcommand"];
|
|
19349
19755
|
const explicitFile = args["file"];
|
|
19350
|
-
if (explicitFile)
|
|
19756
|
+
if (explicitFile) {
|
|
19351
19757
|
return explicitFile;
|
|
19758
|
+
}
|
|
19352
19759
|
if (sub && verbs.includes(sub.toLowerCase())) {
|
|
19353
19760
|
return positional[0];
|
|
19354
19761
|
}
|
|
@@ -19403,15 +19810,19 @@ function getDefaultCommands() {
|
|
|
19403
19810
|
console.log(`
|
|
19404
19811
|
\u2705 Platform setup complete (${summary.durationMs}ms)`);
|
|
19405
19812
|
console.log(` Platforms: copilot=${summary.detectedPlatforms.copilot}, claude=${summary.detectedPlatforms.claude}`);
|
|
19406
|
-
if (summary.created.length)
|
|
19813
|
+
if (summary.created.length) {
|
|
19407
19814
|
console.log(` Created: ${summary.created.length} files`);
|
|
19408
|
-
|
|
19815
|
+
}
|
|
19816
|
+
if (summary.updated.length) {
|
|
19409
19817
|
console.log(` Updated: ${summary.updated.length} files`);
|
|
19410
|
-
|
|
19818
|
+
}
|
|
19819
|
+
if (summary.skipped.length) {
|
|
19411
19820
|
console.log(` Skipped: ${summary.skipped.length} files`);
|
|
19821
|
+
}
|
|
19412
19822
|
}
|
|
19413
|
-
for (const w of summary.warnings)
|
|
19823
|
+
for (const w of summary.warnings) {
|
|
19414
19824
|
console.warn(` \u26A0 ${w}`);
|
|
19825
|
+
}
|
|
19415
19826
|
return;
|
|
19416
19827
|
}
|
|
19417
19828
|
const targetPath = args["subcommand"] ?? args["args"]?.[0] ?? ".";
|
|
@@ -19436,13 +19847,10 @@ function getDefaultCommands() {
|
|
|
19436
19847
|
return ExitCode.VALIDATION_ERROR;
|
|
19437
19848
|
}
|
|
19438
19849
|
return await handleTasksValidate(filePath);
|
|
19439
|
-
break;
|
|
19440
19850
|
case "list":
|
|
19441
19851
|
return await handleTasksList(filePath);
|
|
19442
|
-
break;
|
|
19443
19852
|
case "stats":
|
|
19444
19853
|
return await handleTasksStats(filePath);
|
|
19445
|
-
break;
|
|
19446
19854
|
default:
|
|
19447
19855
|
console.log(showHelp("tasks"));
|
|
19448
19856
|
return;
|
|
@@ -19635,24 +20043,33 @@ function getDefaultCommands() {
|
|
|
19635
20043
|
return;
|
|
19636
20044
|
}
|
|
19637
20045
|
const positionalArgs = [...args["args"] ?? []];
|
|
19638
|
-
if (args["direct"] === true)
|
|
20046
|
+
if (args["direct"] === true) {
|
|
19639
20047
|
positionalArgs.push("--direct");
|
|
19640
|
-
|
|
20048
|
+
}
|
|
20049
|
+
if (args["depth"] !== void 0) {
|
|
19641
20050
|
positionalArgs.push("--depth", String(args["depth"]));
|
|
19642
|
-
|
|
20051
|
+
}
|
|
20052
|
+
if (args["format"] !== void 0) {
|
|
19643
20053
|
positionalArgs.push("--format", String(args["format"]));
|
|
19644
|
-
|
|
20054
|
+
}
|
|
20055
|
+
if (args["out"] !== void 0) {
|
|
19645
20056
|
positionalArgs.push("--out", String(args["out"]));
|
|
19646
|
-
|
|
20057
|
+
}
|
|
20058
|
+
if (args["json"] === true) {
|
|
19647
20059
|
positionalArgs.push("--json");
|
|
19648
|
-
|
|
20060
|
+
}
|
|
20061
|
+
if (args["max-cycles"] !== void 0) {
|
|
19649
20062
|
positionalArgs.push("--max-cycles", String(args["max-cycles"]));
|
|
19650
|
-
|
|
20063
|
+
}
|
|
20064
|
+
if (args["forbid"] !== void 0) {
|
|
19651
20065
|
positionalArgs.push("--forbid", String(args["forbid"]));
|
|
19652
|
-
|
|
20066
|
+
}
|
|
20067
|
+
if (args["cluster"] === true) {
|
|
19653
20068
|
positionalArgs.push("--cluster");
|
|
19654
|
-
|
|
20069
|
+
}
|
|
20070
|
+
if (args["all"] === true) {
|
|
19655
20071
|
positionalArgs.push("--all");
|
|
20072
|
+
}
|
|
19656
20073
|
return await handleCodegraph(sub, positionalArgs);
|
|
19657
20074
|
}
|
|
19658
20075
|
},
|