@swarmvaultai/engine 0.6.1 → 0.6.3

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/README.md CHANGED
@@ -195,7 +195,7 @@ This matters because many "OpenAI-compatible" backends only implement part of th
195
195
  - EPUB inputs split into chapter-level manifests with shared group metadata so books stay navigable instead of becoming one giant source
196
196
  - CSV and TSV inputs produce bounded tabular summaries with delimiter-aware previews and compact column hints
197
197
  - XLSX inputs extract workbook-level and sheet-level previews, while PPTX inputs extract slide text plus speaker notes when present
198
- - JavaScript, JSX, TypeScript, TSX, Python, Go, Rust, Java, Kotlin, Scala, Lua, Zig, C#, C, C++, PHP, Ruby, and PowerShell inputs are treated as code sources and compiled into both source pages and `wiki/code/` module pages
198
+ - JavaScript, JSX, TypeScript, TSX, Bash/shell script, Python, Go, Rust, Java, Kotlin, Scala, Dart, Lua, Zig, C#, C, C++, PHP, Ruby, and PowerShell inputs are treated as code sources and compiled into both source pages and `wiki/code/` module pages
199
199
  - `.rst` and `.rest` inputs are treated as first-class text sources with lightweight heading and directive normalization before analysis
200
200
  - code manifests can carry `repoRelativePath`, and compile writes `state/code-index.json` so local imports can resolve across an ingested repo tree
201
201
  - repo-aware manifests, graph nodes, and graph pages can also carry `sourceClass` so first-party, third-party, resource, and generated material can be filtered and reported separately
package/dist/index.d.ts CHANGED
@@ -65,7 +65,7 @@ type SourceCaptureType = "arxiv" | "doi" | "tweet" | "article" | "url";
65
65
  type SourceClass = "first_party" | "third_party" | "resource" | "generated";
66
66
  type ManagedSourceKind = "directory" | "file" | "github_repo" | "crawl_url";
67
67
  type ManagedSourceStatus = "ready" | "missing" | "error";
68
- type CodeLanguage = "javascript" | "jsx" | "typescript" | "tsx" | "python" | "go" | "rust" | "java" | "kotlin" | "scala" | "lua" | "zig" | "csharp" | "c" | "cpp" | "php" | "ruby" | "powershell";
68
+ type CodeLanguage = "javascript" | "jsx" | "typescript" | "tsx" | "bash" | "python" | "go" | "rust" | "java" | "kotlin" | "scala" | "dart" | "lua" | "zig" | "csharp" | "c" | "cpp" | "php" | "ruby" | "powershell";
69
69
  type CodeSymbolKind = "function" | "class" | "interface" | "type_alias" | "enum" | "variable" | "struct" | "trait";
70
70
  type OrchestrationRole = "research" | "audit" | "context" | "safety";
71
71
  declare const webSearchProviderTypeSchema: z.ZodEnum<{
package/dist/index.js CHANGED
@@ -1735,6 +1735,7 @@ import TurndownService2 from "turndown";
1735
1735
  import fs6 from "fs/promises";
1736
1736
  import path6 from "path";
1737
1737
  import ts from "typescript";
1738
+ import YAML2 from "yaml";
1738
1739
 
1739
1740
  // src/code-tree-sitter.ts
1740
1741
  import fs5 from "fs/promises";
@@ -1758,12 +1759,14 @@ var treeSitterModulePromise;
1758
1759
  var treeSitterInitPromise;
1759
1760
  var languageCache = /* @__PURE__ */ new Map();
1760
1761
  var grammarAssetByLanguage = {
1762
+ bash: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-bash.wasm" },
1761
1763
  python: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-python.wasm" },
1762
1764
  go: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-go.wasm" },
1763
1765
  rust: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-rust.wasm" },
1764
1766
  java: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-java.wasm" },
1765
1767
  kotlin: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-kotlin.wasm" },
1766
1768
  scala: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-scala.wasm" },
1769
+ dart: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-dart.wasm" },
1767
1770
  lua: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-lua.wasm" },
1768
1771
  zig: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-zig.wasm" },
1769
1772
  csharp: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-c-sharp.wasm" },
@@ -1830,7 +1833,10 @@ function normalizeSymbolReference(value) {
1830
1833
  return lastSegment.replace(/[,:;]+$/g, "").trim();
1831
1834
  }
1832
1835
  function stripCodeExtension(filePath) {
1833
- return filePath.replace(/\.(?:[cm]?jsx?|tsx?|mts|cts|py|go|rs|java|kt|kts|scala|sc|lua|zig|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i, "");
1836
+ return filePath.replace(
1837
+ /\.(?:[cm]?jsx?|tsx?|mts|cts|sh|bash|zsh|py|go|rs|java|kt|kts|scala|sc|dart|lua|zig|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i,
1838
+ ""
1839
+ );
1834
1840
  }
1835
1841
  function manifestModuleName(manifest, language) {
1836
1842
  const repoPath = manifest.repoRelativePath ?? path5.basename(manifest.originalPath ?? manifest.storedPath);
@@ -2264,6 +2270,89 @@ function parseScalaImport(text) {
2264
2270
  reExport: false
2265
2271
  }));
2266
2272
  }
2273
+ function bashCommandName(commandNode) {
2274
+ if (!commandNode) {
2275
+ return void 0;
2276
+ }
2277
+ const nameNode = commandNode.childForFieldName("name") ?? findNamedChild(commandNode, "command_name") ?? commandNode.namedChildren.at(0) ?? null;
2278
+ if (!nameNode) {
2279
+ return void 0;
2280
+ }
2281
+ return nodeText(findNamedChild(nameNode, "word") ?? nameNode.namedChildren.at(0) ?? nameNode).trim() || void 0;
2282
+ }
2283
+ function bashSpecifierLooksLocal(specifier) {
2284
+ return specifier.startsWith(".") || specifier.startsWith("/") || specifier.includes("/") || /\.(?:sh|bash|zsh)$/i.test(specifier);
2285
+ }
2286
+ function parseBashImport(commandNode) {
2287
+ const commandName = bashCommandName(commandNode);
2288
+ if (commandName !== "source" && commandName !== ".") {
2289
+ return void 0;
2290
+ }
2291
+ const argumentNode = commandNode.childForFieldName("argument") ?? commandNode.namedChildren.find((child) => child && child !== (commandNode.childForFieldName("name") ?? null)) ?? null;
2292
+ const specifier = quotedPath(nodeText(argumentNode));
2293
+ if (!specifier) {
2294
+ return void 0;
2295
+ }
2296
+ return {
2297
+ specifier,
2298
+ importedSymbols: [],
2299
+ isExternal: !bashSpecifierLooksLocal(specifier),
2300
+ reExport: false
2301
+ };
2302
+ }
2303
+ function parseDartUri(node) {
2304
+ const stringNode = node?.descendantsOfType("string_literal").find((item) => item !== null) ?? null;
2305
+ return stringNode ? quotedPath(stringNode.text) : void 0;
2306
+ }
2307
+ function dartSpecifierLooksLocal(specifier) {
2308
+ return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || !specifier.startsWith("package:") && !specifier.includes(":") && specifier.endsWith(".dart");
2309
+ }
2310
+ function parseDartDirective(node) {
2311
+ if (node.type === "import_or_export") {
2312
+ const importNode = findNamedChild(node, "library_import");
2313
+ if (importNode) {
2314
+ const specifier2 = parseDartUri(
2315
+ findNamedChild(importNode, "configurable_uri") ?? findNamedChild(findNamedChild(importNode, "import_specification"), "configurable_uri") ?? importNode
2316
+ );
2317
+ if (!specifier2) {
2318
+ return void 0;
2319
+ }
2320
+ return {
2321
+ specifier: specifier2,
2322
+ importedSymbols: [],
2323
+ isExternal: !dartSpecifierLooksLocal(specifier2) && !specifier2.startsWith("package:"),
2324
+ reExport: false
2325
+ };
2326
+ }
2327
+ const exportNode = findNamedChild(node, "library_export");
2328
+ if (exportNode) {
2329
+ const specifier2 = parseDartUri(findNamedChild(exportNode, "configurable_uri") ?? exportNode);
2330
+ if (!specifier2) {
2331
+ return void 0;
2332
+ }
2333
+ return {
2334
+ specifier: specifier2,
2335
+ importedSymbols: [],
2336
+ isExternal: !dartSpecifierLooksLocal(specifier2) && !specifier2.startsWith("package:"),
2337
+ reExport: true
2338
+ };
2339
+ }
2340
+ return void 0;
2341
+ }
2342
+ if (node.type !== "part_directive") {
2343
+ return void 0;
2344
+ }
2345
+ const specifier = parseDartUri(findNamedChild(node, "uri") ?? node);
2346
+ if (!specifier) {
2347
+ return void 0;
2348
+ }
2349
+ return {
2350
+ specifier,
2351
+ importedSymbols: [],
2352
+ isExternal: false,
2353
+ reExport: false
2354
+ };
2355
+ }
2267
2356
  function parseLuaRequire(node) {
2268
2357
  const stringNode = node.descendantsOfType("string").find((item) => item !== null);
2269
2358
  const identifiers = node.descendantsOfType("identifier").filter((item) => item !== null).map((item) => item.text.trim());
@@ -2425,6 +2514,29 @@ function scalaDefinitionKind(node) {
2425
2514
  }
2426
2515
  return void 0;
2427
2516
  }
2517
+ function bashCallNamesFromBody(bodyNode, selfName) {
2518
+ if (!bodyNode) {
2519
+ return [];
2520
+ }
2521
+ return uniqueBy(
2522
+ bodyNode.descendantsOfType("command").filter((item) => item !== null).map((item) => bashCommandName(item)).filter((name) => Boolean(name)).filter((name) => name !== "source" && name !== "." && name !== selfName),
2523
+ (name) => name
2524
+ );
2525
+ }
2526
+ function dartCallableName(node) {
2527
+ if (!node) {
2528
+ return void 0;
2529
+ }
2530
+ if (node.type === "function_signature") {
2531
+ return extractIdentifier(node.childForFieldName("name") ?? findNamedChild(node, "identifier"));
2532
+ }
2533
+ if (node.type === "constructor_signature") {
2534
+ return extractIdentifier(node.childForFieldName("name") ?? findNamedChild(node, "identifier"));
2535
+ }
2536
+ return extractIdentifier(
2537
+ node.childForFieldName("name") ?? findNamedChild(node, "function_signature") ?? findNamedChild(node, "identifier")
2538
+ );
2539
+ }
2428
2540
  function luaFunctionName(node) {
2429
2541
  if (!node) {
2430
2542
  return void 0;
@@ -2447,6 +2559,237 @@ function zigDeclarationKind(node) {
2447
2559
  }
2448
2560
  return void 0;
2449
2561
  }
2562
+ function bashCodeAnalysis(manifest, rootNode, diagnostics) {
2563
+ const imports = [];
2564
+ const draftSymbols = [];
2565
+ const exportLabels = [];
2566
+ for (const child of rootNode.namedChildren) {
2567
+ if (!child) {
2568
+ continue;
2569
+ }
2570
+ if (child.type === "command") {
2571
+ const parsed = parseBashImport(child);
2572
+ if (parsed) {
2573
+ imports.push(parsed);
2574
+ }
2575
+ continue;
2576
+ }
2577
+ if (child.type !== "function_definition") {
2578
+ continue;
2579
+ }
2580
+ const name = nodeText(child.childForFieldName("name") ?? child.namedChildren.at(0) ?? null).trim();
2581
+ if (!name) {
2582
+ continue;
2583
+ }
2584
+ draftSymbols.push({
2585
+ name,
2586
+ kind: "function",
2587
+ signature: singleLineSignature(child.text),
2588
+ exported: true,
2589
+ callNames: [],
2590
+ extendsNames: [],
2591
+ implementsNames: [],
2592
+ bodyText: nodeText(child.childForFieldName("body") ?? findNamedChild(child, "compound_statement"))
2593
+ });
2594
+ exportLabels.push(name);
2595
+ }
2596
+ for (let index = 0; index < draftSymbols.length; index += 1) {
2597
+ const functionNode = rootNode.namedChildren.find(
2598
+ (child) => child?.type === "function_definition" && nodeText(child.childForFieldName("name") ?? child.namedChildren.at(0) ?? null).trim() === draftSymbols[index]?.name
2599
+ );
2600
+ draftSymbols[index].callNames = bashCallNamesFromBody(
2601
+ functionNode?.childForFieldName("body") ?? findNamedChild(functionNode, "compound_statement"),
2602
+ draftSymbols[index].name
2603
+ );
2604
+ }
2605
+ return finalizeCodeAnalysis(manifest, "bash", imports, draftSymbols, exportLabels, diagnostics);
2606
+ }
2607
+ function dartCodeAnalysis(manifest, rootNode, diagnostics) {
2608
+ const imports = [];
2609
+ const draftSymbols = [];
2610
+ const exportLabels = [];
2611
+ let libraryName;
2612
+ const pushScopedFunctions = (bodyNode, scopeName) => {
2613
+ if (!bodyNode) {
2614
+ return;
2615
+ }
2616
+ const children = bodyNode.namedChildren.filter((item) => item !== null);
2617
+ for (let index = 0; index < children.length; index += 1) {
2618
+ const child = children[index];
2619
+ if (!child) {
2620
+ continue;
2621
+ }
2622
+ if (child.type === "method_signature") {
2623
+ const signatureNode = findNamedChild(child, "function_signature") ?? child;
2624
+ const methodName = dartCallableName(signatureNode);
2625
+ if (!methodName) {
2626
+ continue;
2627
+ }
2628
+ const bodyNode2 = children[index + 1]?.type === "function_body" ? children[index + 1] : null;
2629
+ const symbolName2 = `${scopeName}.${methodName}`;
2630
+ const exported2 = !scopeName.startsWith("_") && !methodName.startsWith("_");
2631
+ draftSymbols.push({
2632
+ name: symbolName2,
2633
+ kind: "function",
2634
+ signature: singleLineSignature(`${child.text} ${nodeText(bodyNode2)}`),
2635
+ exported: exported2,
2636
+ callNames: [],
2637
+ extendsNames: [],
2638
+ implementsNames: [],
2639
+ bodyText: nodeText(bodyNode2)
2640
+ });
2641
+ if (exported2) {
2642
+ exportLabels.push(symbolName2);
2643
+ }
2644
+ continue;
2645
+ }
2646
+ if (child.type !== "declaration") {
2647
+ continue;
2648
+ }
2649
+ const constructorNode = findNamedChild(child, "constructor_signature");
2650
+ const constructorName = dartCallableName(constructorNode);
2651
+ if (!constructorName) {
2652
+ continue;
2653
+ }
2654
+ const symbolName = `${scopeName}.${constructorName}`;
2655
+ const exported = !scopeName.startsWith("_") && !constructorName.startsWith("_");
2656
+ draftSymbols.push({
2657
+ name: symbolName,
2658
+ kind: "function",
2659
+ signature: singleLineSignature(child.text),
2660
+ exported,
2661
+ callNames: [],
2662
+ extendsNames: [],
2663
+ implementsNames: [],
2664
+ bodyText: child.text
2665
+ });
2666
+ if (exported) {
2667
+ exportLabels.push(symbolName);
2668
+ }
2669
+ }
2670
+ };
2671
+ const topLevelChildren = rootNode.namedChildren.filter((item) => item !== null);
2672
+ for (let index = 0; index < topLevelChildren.length; index += 1) {
2673
+ const child = topLevelChildren[index];
2674
+ if (!child) {
2675
+ continue;
2676
+ }
2677
+ if (child.type === "library_name") {
2678
+ libraryName = nodeText(findNamedChild(child, "dotted_identifier_list") ?? child.namedChildren.at(-1) ?? null) || libraryName;
2679
+ continue;
2680
+ }
2681
+ if (child.type === "import_or_export" || child.type === "part_directive") {
2682
+ const parsed = parseDartDirective(child);
2683
+ if (parsed) {
2684
+ imports.push(parsed);
2685
+ }
2686
+ continue;
2687
+ }
2688
+ if (child.type === "function_signature") {
2689
+ const functionName = dartCallableName(child);
2690
+ if (!functionName) {
2691
+ continue;
2692
+ }
2693
+ const bodyNode2 = topLevelChildren[index + 1]?.type === "function_body" ? topLevelChildren[index + 1] : null;
2694
+ const exported2 = !functionName.startsWith("_");
2695
+ draftSymbols.push({
2696
+ name: functionName,
2697
+ kind: "function",
2698
+ signature: singleLineSignature(`${child.text} ${nodeText(bodyNode2)}`),
2699
+ exported: exported2,
2700
+ callNames: [],
2701
+ extendsNames: [],
2702
+ implementsNames: [],
2703
+ bodyText: nodeText(bodyNode2)
2704
+ });
2705
+ if (exported2) {
2706
+ exportLabels.push(functionName);
2707
+ }
2708
+ continue;
2709
+ }
2710
+ if (child.type === "mixin_declaration") {
2711
+ const mixinName = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2712
+ if (!mixinName) {
2713
+ continue;
2714
+ }
2715
+ const bodyNode2 = child.childForFieldName("body") ?? findNamedChild(child, "class_body");
2716
+ const exported2 = !mixinName.startsWith("_");
2717
+ draftSymbols.push({
2718
+ name: mixinName,
2719
+ kind: "trait",
2720
+ signature: singleLineSignature(child.text),
2721
+ exported: exported2,
2722
+ callNames: [],
2723
+ extendsNames: [],
2724
+ implementsNames: [],
2725
+ bodyText: nodeText(bodyNode2) || child.text
2726
+ });
2727
+ if (exported2) {
2728
+ exportLabels.push(mixinName);
2729
+ }
2730
+ pushScopedFunctions(bodyNode2, mixinName);
2731
+ continue;
2732
+ }
2733
+ if (child.type === "enum_declaration") {
2734
+ const enumName = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2735
+ if (!enumName) {
2736
+ continue;
2737
+ }
2738
+ const exported2 = !enumName.startsWith("_");
2739
+ draftSymbols.push({
2740
+ name: enumName,
2741
+ kind: "enum",
2742
+ signature: singleLineSignature(child.text),
2743
+ exported: exported2,
2744
+ callNames: [],
2745
+ extendsNames: [],
2746
+ implementsNames: [],
2747
+ bodyText: nodeText(child.childForFieldName("body") ?? findNamedChild(child, "enum_body")) || child.text
2748
+ });
2749
+ if (exported2) {
2750
+ exportLabels.push(enumName);
2751
+ }
2752
+ continue;
2753
+ }
2754
+ if (child.type === "extension_declaration") {
2755
+ const extensionName = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2756
+ const targetType = extractIdentifier(child.childForFieldName("type") ?? findNamedChild(child, "type_identifier")) ?? extensionName;
2757
+ const bodyNode2 = child.childForFieldName("body") ?? findNamedChild(child, "extension_body");
2758
+ if (targetType) {
2759
+ pushScopedFunctions(bodyNode2, targetType);
2760
+ }
2761
+ continue;
2762
+ }
2763
+ if (child.type !== "class_definition") {
2764
+ continue;
2765
+ }
2766
+ const className = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2767
+ if (!className) {
2768
+ continue;
2769
+ }
2770
+ const superTypes = descendantTypeNames(child.childForFieldName("superclass"));
2771
+ const interfaceTypes = descendantTypeNames(child.childForFieldName("interfaces"));
2772
+ const bodyNode = child.childForFieldName("body") ?? findNamedChild(child, "class_body");
2773
+ const exported = !className.startsWith("_");
2774
+ draftSymbols.push({
2775
+ name: className,
2776
+ kind: "class",
2777
+ signature: singleLineSignature(child.text),
2778
+ exported,
2779
+ callNames: [],
2780
+ extendsNames: superTypes.slice(0, 1),
2781
+ implementsNames: [...superTypes.slice(1), ...interfaceTypes],
2782
+ bodyText: nodeText(bodyNode) || child.text
2783
+ });
2784
+ if (exported) {
2785
+ exportLabels.push(className);
2786
+ }
2787
+ pushScopedFunctions(bodyNode, className);
2788
+ }
2789
+ return finalizeCodeAnalysis(manifest, "dart", imports, draftSymbols, exportLabels, diagnostics, {
2790
+ namespace: libraryName
2791
+ });
2792
+ }
2450
2793
  function pythonCodeAnalysis(manifest, rootNode, diagnostics) {
2451
2794
  const imports = [];
2452
2795
  const draftSymbols = [];
@@ -3425,6 +3768,8 @@ async function analyzeTreeSitterCode(manifest, content, language) {
3425
3768
  const diagnostics = diagnosticsFromTree(tree.rootNode);
3426
3769
  const rationales = extractTreeSitterRationales(manifest, language, tree.rootNode);
3427
3770
  switch (language) {
3771
+ case "bash":
3772
+ return { code: bashCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3428
3773
  case "python":
3429
3774
  return { code: pythonCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3430
3775
  case "go":
@@ -3437,6 +3782,8 @@ async function analyzeTreeSitterCode(manifest, content, language) {
3437
3782
  return { code: kotlinCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3438
3783
  case "scala":
3439
3784
  return { code: scalaCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3785
+ case "dart":
3786
+ return { code: dartCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3440
3787
  case "lua":
3441
3788
  return { code: luaCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3442
3789
  case "zig":
@@ -3497,6 +3844,34 @@ function isRelativeSpecifier(specifier) {
3497
3844
  function isLocalIncludeSpecifier(specifier) {
3498
3845
  return specifier.startsWith(".") || specifier.startsWith("/") || specifier.includes("/");
3499
3846
  }
3847
+ function bashSpecifierLooksLocal2(specifier) {
3848
+ return isLocalIncludeSpecifier(specifier) || /\.(?:sh|bash|zsh)$/i.test(specifier);
3849
+ }
3850
+ function dartSpecifierLooksLocal2(specifier) {
3851
+ return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || !specifier.startsWith("package:") && !specifier.includes(":") && specifier.endsWith(".dart");
3852
+ }
3853
+ function interpreterFromShebang(content) {
3854
+ if (!content?.startsWith("#!")) {
3855
+ return void 0;
3856
+ }
3857
+ const firstLine = content.split(/\r?\n/, 1)[0]?.slice(2).trim() ?? "";
3858
+ if (!firstLine) {
3859
+ return void 0;
3860
+ }
3861
+ const parts = firstLine.split(/\s+/).filter(Boolean);
3862
+ if (parts.length === 0) {
3863
+ return void 0;
3864
+ }
3865
+ const basename = (value) => path6.posix.basename(value.trim());
3866
+ if (basename(parts[0] ?? "") === "env") {
3867
+ const interpreter = parts.slice(1).find((part) => !part.startsWith("-"));
3868
+ return interpreter ? basename(interpreter) : void 0;
3869
+ }
3870
+ return basename(parts[0] ?? "");
3871
+ }
3872
+ function isShellInterpreter(value) {
3873
+ return value === "sh" || value === "bash" || value === "zsh";
3874
+ }
3500
3875
  function formatDiagnosticCategory(category) {
3501
3876
  switch (category) {
3502
3877
  case ts.DiagnosticCategory.Error:
@@ -3727,7 +4102,10 @@ function makeRationale2(manifest, index, text, kind, symbolName) {
3727
4102
  };
3728
4103
  }
3729
4104
  function stripCodeExtension2(filePath) {
3730
- return filePath.replace(/\.(?:[cm]?jsx?|tsx?|mts|cts|py|go|rs|java|kt|kts|scala|sc|lua|zig|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i, "");
4105
+ return filePath.replace(
4106
+ /\.(?:[cm]?jsx?|tsx?|mts|cts|sh|bash|zsh|py|go|rs|java|kt|kts|scala|sc|dart|lua|zig|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i,
4107
+ ""
4108
+ );
3731
4109
  }
3732
4110
  function manifestModuleName2(manifest, language) {
3733
4111
  const repoPath = manifest.repoRelativePath ?? path6.basename(manifest.originalPath ?? manifest.storedPath);
@@ -4032,7 +4410,7 @@ function analyzeTypeScriptLikeCode(manifest, content) {
4032
4410
  rationales: extractTypeScriptRationales(manifest, content, sourceFile)
4033
4411
  };
4034
4412
  }
4035
- function inferCodeLanguage(filePath, mimeType = "") {
4413
+ function inferCodeLanguage(filePath, mimeType = "", options = {}) {
4036
4414
  const extension = path6.extname(filePath).toLowerCase();
4037
4415
  if (extension === ".ts" || extension === ".mts" || extension === ".cts") {
4038
4416
  return "typescript";
@@ -4046,6 +4424,9 @@ function inferCodeLanguage(filePath, mimeType = "") {
4046
4424
  if (extension === ".js" || extension === ".mjs" || extension === ".cjs" || mimeType.includes("javascript")) {
4047
4425
  return "javascript";
4048
4426
  }
4427
+ if (extension === ".sh" || extension === ".bash" || extension === ".zsh" || mimeType === "application/x-sh") {
4428
+ return "bash";
4429
+ }
4049
4430
  if (extension === ".py") {
4050
4431
  return "python";
4051
4432
  }
@@ -4064,6 +4445,9 @@ function inferCodeLanguage(filePath, mimeType = "") {
4064
4445
  if (extension === ".scala" || extension === ".sc") {
4065
4446
  return "scala";
4066
4447
  }
4448
+ if (extension === ".dart") {
4449
+ return "dart";
4450
+ }
4067
4451
  if (extension === ".lua") {
4068
4452
  return "lua";
4069
4453
  }
@@ -4088,6 +4472,9 @@ function inferCodeLanguage(filePath, mimeType = "") {
4088
4472
  if ([".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx"].includes(extension)) {
4089
4473
  return "cpp";
4090
4474
  }
4475
+ if (!extension && options.executable && isShellInterpreter(interpreterFromShebang(options.content))) {
4476
+ return "bash";
4477
+ }
4091
4478
  return void 0;
4092
4479
  }
4093
4480
  function modulePageTitle(manifest) {
@@ -4120,6 +4507,43 @@ function manifestBasenameWithoutExtension(manifest) {
4120
4507
  const target = manifest.repoRelativePath ?? manifest.originalPath ?? manifest.storedPath;
4121
4508
  return path6.posix.basename(stripCodeExtension2(normalizeAlias(target)));
4122
4509
  }
4510
+ async function readNearestDartPackageInfo(startPath, cache) {
4511
+ let current = path6.resolve(startPath);
4512
+ try {
4513
+ const stat = await fs6.stat(current);
4514
+ if (!stat.isDirectory()) {
4515
+ current = path6.dirname(current);
4516
+ }
4517
+ } catch {
4518
+ current = path6.dirname(current);
4519
+ }
4520
+ while (true) {
4521
+ if (cache.has(current)) {
4522
+ const cached = cache.get(current);
4523
+ return cached === null ? void 0 : cached;
4524
+ }
4525
+ const pubspecPath = path6.join(current, "pubspec.yaml");
4526
+ if (await fs6.access(pubspecPath).then(() => true).catch(() => false)) {
4527
+ try {
4528
+ const content = await fs6.readFile(pubspecPath, "utf8");
4529
+ const parsed = YAML2.parse(content);
4530
+ const packageName = typeof parsed?.name === "string" ? parsed.name.trim() : "";
4531
+ const info = packageName ? { rootDir: current, name: packageName } : null;
4532
+ cache.set(current, info);
4533
+ return info ?? void 0;
4534
+ } catch {
4535
+ cache.set(current, null);
4536
+ return void 0;
4537
+ }
4538
+ }
4539
+ const parent = path6.dirname(current);
4540
+ if (parent === current) {
4541
+ cache.set(current, null);
4542
+ return void 0;
4543
+ }
4544
+ current = parent;
4545
+ }
4546
+ }
4123
4547
  async function readNearestGoModulePath(startPath, cache) {
4124
4548
  let current = path6.resolve(startPath);
4125
4549
  try {
@@ -4166,6 +4590,8 @@ function candidateExtensionsFor(language) {
4166
4590
  case "typescript":
4167
4591
  case "tsx":
4168
4592
  return [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"];
4593
+ case "bash":
4594
+ return [".sh", ".bash", ".zsh"];
4169
4595
  case "python":
4170
4596
  return [".py"];
4171
4597
  case "go":
@@ -4178,6 +4604,8 @@ function candidateExtensionsFor(language) {
4178
4604
  return [".kt", ".kts"];
4179
4605
  case "scala":
4180
4606
  return [".scala", ".sc"];
4607
+ case "dart":
4608
+ return [".dart"];
4181
4609
  case "lua":
4182
4610
  return [".lua"];
4183
4611
  case "zig":
@@ -4199,6 +4627,7 @@ function candidateExtensionsFor(language) {
4199
4627
  async function buildCodeIndex(rootDir, manifests, analyses) {
4200
4628
  const analysesBySourceId = new Map(analyses.map((analysis) => [analysis.sourceId, analysis]));
4201
4629
  const goModuleCache = /* @__PURE__ */ new Map();
4630
+ const dartPackageCache = /* @__PURE__ */ new Map();
4202
4631
  const entries = [];
4203
4632
  for (const manifest of manifests) {
4204
4633
  const analysis = analysesBySourceId.get(manifest.sourceId);
@@ -4223,6 +4652,9 @@ async function buildCodeIndex(rootDir, manifests, analyses) {
4223
4652
  case "python":
4224
4653
  recordAlias(aliases, normalizedModuleName?.replace(/\//g, "."));
4225
4654
  break;
4655
+ case "bash":
4656
+ recordAlias(aliases, basename);
4657
+ break;
4226
4658
  case "rust":
4227
4659
  if (repoRelativePath) {
4228
4660
  recordAlias(aliases, rustModuleAlias(repoRelativePath));
@@ -4244,6 +4676,7 @@ async function buildCodeIndex(rootDir, manifests, analyses) {
4244
4676
  case "java":
4245
4677
  case "kotlin":
4246
4678
  case "scala":
4679
+ case "dart":
4247
4680
  case "csharp":
4248
4681
  if (normalizedNamespace) {
4249
4682
  recordAlias(aliases, `${normalizedNamespace}.${basename}`);
@@ -4253,6 +4686,19 @@ async function buildCodeIndex(rootDir, manifests, analyses) {
4253
4686
  recordAlias(aliases, `${normalizedNamespace}.${symbol.name}`);
4254
4687
  }
4255
4688
  }
4689
+ if (analysis.code.language === "dart" && repoRelativePath) {
4690
+ recordAlias(aliases, basename);
4691
+ const originalPath = manifest.originalPath ? path6.resolve(manifest.originalPath) : path6.resolve(rootDir, manifest.storedPath);
4692
+ const packageInfo = await readNearestDartPackageInfo(originalPath, dartPackageCache);
4693
+ if (packageInfo) {
4694
+ const packageRelativePath = toPosix(path6.relative(packageInfo.rootDir, originalPath));
4695
+ if (packageRelativePath.startsWith("lib/")) {
4696
+ const packagePath = packageRelativePath.slice("lib/".length);
4697
+ recordAlias(aliases, `package:${packageInfo.name}/${packagePath}`);
4698
+ recordAlias(aliases, `package:${packageInfo.name}/${stripCodeExtension2(packagePath)}`);
4699
+ }
4700
+ }
4701
+ }
4256
4702
  break;
4257
4703
  case "lua":
4258
4704
  recordAlias(aliases, basename);
@@ -4387,14 +4833,17 @@ function findImportCandidates(manifest, codeImport, lookup) {
4387
4833
  case "scala":
4388
4834
  case "csharp":
4389
4835
  return aliasMatches(lookup, codeImport.specifier);
4836
+ case "dart":
4837
+ return repoRelativePath && dartSpecifierLooksLocal2(codeImport.specifier) ? repoPathMatches(lookup, ...importResolutionCandidates(repoRelativePath, codeImport.specifier, candidateExtensionsFor(language))) : aliasMatches(lookup, codeImport.specifier);
4390
4838
  case "lua":
4391
4839
  return luaSpecifierLooksLocal(codeImport.specifier) ? repoPathMatches(lookup, ...resolveLuaModuleCandidates(codeImport.specifier)) : aliasMatches(lookup, codeImport.specifier, codeImport.specifier.replace(/\./g, "/"));
4392
4840
  case "zig":
4393
4841
  return repoRelativePath && (!codeImport.isExternal || codeImport.specifier.endsWith(".zig")) ? repoPathMatches(lookup, ...importResolutionCandidates(repoRelativePath, codeImport.specifier, candidateExtensionsFor(language))) : aliasMatches(lookup, codeImport.specifier);
4394
4842
  case "php":
4395
4843
  case "ruby":
4844
+ case "bash":
4396
4845
  case "powershell":
4397
- if (repoRelativePath && isLocalIncludeSpecifier(codeImport.specifier)) {
4846
+ if (repoRelativePath && (language === "bash" ? bashSpecifierLooksLocal2(codeImport.specifier) : isLocalIncludeSpecifier(codeImport.specifier))) {
4398
4847
  return repoPathMatches(
4399
4848
  lookup,
4400
4849
  ...importResolutionCandidates(repoRelativePath, codeImport.specifier, candidateExtensionsFor(language))
@@ -4438,6 +4887,10 @@ function importLooksLocal(manifest, codeImport, candidates) {
4438
4887
  case "kotlin":
4439
4888
  case "scala":
4440
4889
  return !codeImport.isExternal;
4890
+ case "bash":
4891
+ return bashSpecifierLooksLocal2(codeImport.specifier);
4892
+ case "dart":
4893
+ return dartSpecifierLooksLocal2(codeImport.specifier);
4441
4894
  case "lua":
4442
4895
  return luaSpecifierLooksLocal(codeImport.specifier);
4443
4896
  case "zig":
@@ -6096,8 +6549,8 @@ var MARKDOWN_SEMANTIC_FRONTMATTER_KEYS = [
6096
6549
  function uniqueStrings(values) {
6097
6550
  return [...new Set(values.filter(Boolean))];
6098
6551
  }
6099
- function inferKind(mimeType, filePath) {
6100
- if (inferCodeLanguage(filePath, mimeType)) {
6552
+ function inferKind(mimeType, filePath, detectionOptions = {}) {
6553
+ if (inferCodeLanguage(filePath, mimeType, detectionOptions)) {
6101
6554
  return "code";
6102
6555
  }
6103
6556
  if (isRstFilePath(filePath)) {
@@ -6144,6 +6597,25 @@ function inferKind(mimeType, filePath) {
6144
6597
  }
6145
6598
  return "binary";
6146
6599
  }
6600
+ async function localCodeDetectionOptions(absolutePath, payloadBytes) {
6601
+ if (path12.extname(absolutePath)) {
6602
+ return {};
6603
+ }
6604
+ try {
6605
+ const stat = await fs11.stat(absolutePath);
6606
+ const executable = Boolean(stat.mode & 73);
6607
+ if (!executable) {
6608
+ return { executable: false };
6609
+ }
6610
+ const bytes = payloadBytes ?? await fs11.readFile(absolutePath);
6611
+ return {
6612
+ executable,
6613
+ content: bytes.subarray(0, 256).toString("utf8")
6614
+ };
6615
+ } catch {
6616
+ return {};
6617
+ }
6618
+ }
6147
6619
  function isRstFilePath(filePath) {
6148
6620
  const extension = path12.extname(filePath).toLowerCase();
6149
6621
  return extension === ".rst" || extension === ".rest";
@@ -7017,7 +7489,8 @@ async function collectDirectoryFiles(rootDir, inputDir, repoRoot, options) {
7017
7489
  continue;
7018
7490
  }
7019
7491
  const mimeType = guessMimeType(absolutePath);
7020
- let sourceKind = inferKind(mimeType, absolutePath);
7492
+ const detectionOptions = await localCodeDetectionOptions(absolutePath);
7493
+ let sourceKind = inferKind(mimeType, absolutePath, detectionOptions);
7021
7494
  if (sourceKind === "binary" && path12.extname(absolutePath).toLowerCase() === ".zip") {
7022
7495
  const bytes = await fs11.readFile(absolutePath);
7023
7496
  if (isSlackExportArchive(bytes)) {
@@ -7644,8 +8117,9 @@ async function prepareFileInputs(rootDir, absoluteInput, repoRoot, sourceClass)
7644
8117
  }
7645
8118
  }
7646
8119
  const mimeType = guessMimeType(absoluteInput);
7647
- const sourceKind = inferKind(mimeType, absoluteInput);
7648
- const language = inferCodeLanguage(absoluteInput, mimeType);
8120
+ const detectionOptions = await localCodeDetectionOptions(absoluteInput, payloadBytes);
8121
+ const sourceKind = inferKind(mimeType, absoluteInput, detectionOptions);
8122
+ const language = inferCodeLanguage(absoluteInput, mimeType, detectionOptions);
7649
8123
  const storedExtension = path12.extname(absoluteInput) || `.${mime.extension(mimeType) || "bin"}`;
7650
8124
  let title;
7651
8125
  let extractedText;
@@ -8077,7 +8551,8 @@ async function collectInboxAttachmentRefs(inputDir, files) {
8077
8551
  const refsBySource = /* @__PURE__ */ new Map();
8078
8552
  for (const absolutePath of files) {
8079
8553
  const mimeType = guessMimeType(absolutePath);
8080
- const sourceKind = inferKind(mimeType, absolutePath);
8554
+ const detectionOptions = await localCodeDetectionOptions(absolutePath);
8555
+ const sourceKind = inferKind(mimeType, absolutePath, detectionOptions);
8081
8556
  if (sourceKind !== "markdown" && sourceKind !== "html") {
8082
8557
  continue;
8083
8558
  }
@@ -8419,7 +8894,8 @@ async function importInbox(rootDir, inputDir) {
8419
8894
  continue;
8420
8895
  }
8421
8896
  const mimeType = guessMimeType(absolutePath);
8422
- let sourceKind = inferKind(mimeType, absolutePath);
8897
+ const detectionOptions = await localCodeDetectionOptions(absolutePath);
8898
+ let sourceKind = inferKind(mimeType, absolutePath, detectionOptions);
8423
8899
  if (sourceKind === "binary" && path12.extname(absolutePath).toLowerCase() === ".zip") {
8424
8900
  const bytes = await fs11.readFile(absolutePath);
8425
8901
  if (isSlackExportArchive(bytes)) {
@@ -17212,7 +17688,7 @@ async function bootstrapDemo(rootDir, input) {
17212
17688
  }
17213
17689
 
17214
17690
  // src/mcp.ts
17215
- var SERVER_VERSION = "0.6.1";
17691
+ var SERVER_VERSION = "0.6.3";
17216
17692
  async function createMcpServer(rootDir) {
17217
17693
  const server = new McpServer({
17218
17694
  name: "swarmvault",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarmvaultai/engine",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Core engine for SwarmVault: ingest, compile, query, lint, and provider abstractions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,8 @@
42
42
  "scripts": {
43
43
  "build": "test -f ../viewer/dist/index.html || pnpm --dir ../viewer build; tsup src/index.ts --format esm --dts && rm -rf dist/viewer && mkdir -p dist/viewer && cp -R ../viewer/dist/. dist/viewer/",
44
44
  "test": "SWARMVAULT_ALLOW_PRIVATE_URLS=1 vitest run",
45
- "typecheck": "tsc --noEmit"
45
+ "typecheck": "tsc --noEmit",
46
+ "prepublishOnly": "node ../../scripts/check-release-sync.mjs && node ../../scripts/check-published-manifests.mjs"
46
47
  },
47
48
  "dependencies": {
48
49
  "@modelcontextprotocol/sdk": "^1.29.0",