@swarmvaultai/engine 0.2.0 → 0.2.1

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
@@ -191,7 +191,7 @@ This matters because many "OpenAI-compatible" backends only implement part of th
191
191
  - `importInbox(rootDir, inputDir?)` recursively imports supported inbox files plus markdown and HTML browser-clipper style bundles
192
192
  - managed sources support local directories, public GitHub repo root URLs, and bounded same-domain docs hubs
193
193
  - registry data lives in `state/sources.json`, working state lives under `state/sources/<id>/`, and source briefs are written to `wiki/outputs/source-briefs/<id>.md`
194
- - JavaScript, TypeScript, Python, Go, Rust, Java, C#, C, C++, PHP, Ruby, PowerShell, Kotlin, and Scala inputs are treated as code sources and compiled into both source pages and `wiki/code/` module pages
194
+ - 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
195
195
  - `.rst` and `.rest` inputs are treated as first-class text sources with lightweight heading and directive normalization before analysis
196
196
  - code manifests can carry `repoRelativePath`, and compile writes `state/code-index.json` so local imports can resolve across an ingested repo tree
197
197
  - 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
@@ -59,7 +59,7 @@ type SourceCaptureType = "arxiv" | "doi" | "tweet" | "article" | "url";
59
59
  type SourceClass = "first_party" | "third_party" | "resource" | "generated";
60
60
  type ManagedSourceKind = "directory" | "github_repo" | "crawl_url";
61
61
  type ManagedSourceStatus = "ready" | "missing" | "error";
62
- type CodeLanguage = "javascript" | "jsx" | "typescript" | "tsx" | "python" | "go" | "rust" | "java" | "kotlin" | "scala" | "csharp" | "c" | "cpp" | "php" | "ruby" | "powershell";
62
+ type CodeLanguage = "javascript" | "jsx" | "typescript" | "tsx" | "python" | "go" | "rust" | "java" | "kotlin" | "scala" | "lua" | "zig" | "csharp" | "c" | "cpp" | "php" | "ruby" | "powershell";
63
63
  type CodeSymbolKind = "function" | "class" | "interface" | "type_alias" | "enum" | "variable" | "struct" | "trait";
64
64
  type OrchestrationRole = "research" | "audit" | "context" | "safety";
65
65
  declare const webSearchProviderTypeSchema: z.ZodEnum<{
package/dist/index.js CHANGED
@@ -1764,6 +1764,8 @@ var grammarAssetByLanguage = {
1764
1764
  java: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-java.wasm" },
1765
1765
  kotlin: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-kotlin.wasm" },
1766
1766
  scala: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-scala.wasm" },
1767
+ lua: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-lua.wasm" },
1768
+ zig: { packageName: TREE_SITTER_EXTRA_GRAMMARS_PACKAGE, relativePath: "out/tree-sitter-zig.wasm" },
1767
1769
  csharp: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-c-sharp.wasm" },
1768
1770
  c: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-cpp.wasm" },
1769
1771
  cpp: { packageName: TREE_SITTER_RUNTIME_PACKAGE, relativePath: "wasm/tree-sitter-cpp.wasm" },
@@ -1828,7 +1830,7 @@ function normalizeSymbolReference(value) {
1828
1830
  return lastSegment.replace(/[,:;]+$/g, "").trim();
1829
1831
  }
1830
1832
  function stripCodeExtension(filePath) {
1831
- return filePath.replace(/\.(?:[cm]?jsx?|tsx?|mts|cts|py|go|rs|java|kt|kts|scala|sc|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i, "");
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, "");
1832
1834
  }
1833
1835
  function manifestModuleName(manifest, language) {
1834
1836
  const repoPath = manifest.repoRelativePath ?? path5.basename(manifest.originalPath ?? manifest.storedPath);
@@ -2112,7 +2114,7 @@ function descendantTypeNames(node) {
2112
2114
  );
2113
2115
  }
2114
2116
  function quotedPath(value) {
2115
- return value.replace(/^["'<]+|[">]+$/g, "").trim();
2117
+ return value.replace(/^['"<]+|['">]+$/g, "").trim();
2116
2118
  }
2117
2119
  function diagnosticsFromTree(rootNode) {
2118
2120
  if (!rootNode.hasError) {
@@ -2262,6 +2264,43 @@ function parseScalaImport(text) {
2262
2264
  reExport: false
2263
2265
  }));
2264
2266
  }
2267
+ function parseLuaRequire(node) {
2268
+ const stringNode = node.descendantsOfType("string").find((item) => item !== null);
2269
+ const identifiers = node.descendantsOfType("identifier").filter((item) => item !== null).map((item) => item.text.trim());
2270
+ if (!stringNode || !identifiers.includes("require")) {
2271
+ return void 0;
2272
+ }
2273
+ const specifier = quotedPath(stringNode.text);
2274
+ if (!specifier) {
2275
+ return void 0;
2276
+ }
2277
+ return {
2278
+ specifier,
2279
+ importedSymbols: [],
2280
+ isExternal: !/^[A-Za-z_][A-Za-z0-9_]*(?:[./][A-Za-z_][A-Za-z0-9_]*)*$/.test(specifier),
2281
+ reExport: false
2282
+ };
2283
+ }
2284
+ function parseZigImport(node) {
2285
+ if (node.type !== "variable_declaration") {
2286
+ return void 0;
2287
+ }
2288
+ const importCall = findNamedChild(node, "builtin_function");
2289
+ if (!importCall || nodeText(findNamedChild(importCall, "builtin_identifier") ?? importCall.namedChildren.at(0) ?? null) !== "@import") {
2290
+ return void 0;
2291
+ }
2292
+ const stringNode = importCall.descendantsOfType("string_content").find((item) => item !== null);
2293
+ const specifier = stringNode?.text.trim();
2294
+ if (!specifier) {
2295
+ return void 0;
2296
+ }
2297
+ return {
2298
+ specifier,
2299
+ importedSymbols: [],
2300
+ isExternal: !specifier.endsWith(".zig") && !specifier.includes("/") && !specifier.startsWith("."),
2301
+ reExport: false
2302
+ };
2303
+ }
2265
2304
  function parseCSharpUsing(text) {
2266
2305
  const aliasMatch = text.trim().match(/^using\s+([A-Za-z_]\w*)\s*=\s*([^;]+);$/);
2267
2306
  if (aliasMatch) {
@@ -2386,6 +2425,28 @@ function scalaDefinitionKind(node) {
2386
2425
  }
2387
2426
  return void 0;
2388
2427
  }
2428
+ function luaFunctionName(node) {
2429
+ if (!node) {
2430
+ return void 0;
2431
+ }
2432
+ if (node.type === "identifier") {
2433
+ return node.text.trim();
2434
+ }
2435
+ if (node.type === "variable") {
2436
+ const identifiers = node.descendantsOfType("identifier").filter((item) => item !== null).map((item) => item.text.trim()).filter(Boolean);
2437
+ return identifiers.length > 0 ? identifiers.join(".") : void 0;
2438
+ }
2439
+ return extractIdentifier(node);
2440
+ }
2441
+ function zigDeclarationKind(node) {
2442
+ if (findNamedChild(node, "struct_declaration")) {
2443
+ return "struct";
2444
+ }
2445
+ if (findNamedChild(node, "enum_declaration")) {
2446
+ return "enum";
2447
+ }
2448
+ return void 0;
2449
+ }
2389
2450
  function pythonCodeAnalysis(manifest, rootNode, diagnostics) {
2390
2451
  const imports = [];
2391
2452
  const draftSymbols = [];
@@ -2814,6 +2875,136 @@ function scalaCodeAnalysis(manifest, rootNode, diagnostics) {
2814
2875
  namespace: packageName
2815
2876
  });
2816
2877
  }
2878
+ function luaCodeAnalysis(manifest, rootNode, diagnostics) {
2879
+ const imports = [];
2880
+ const draftSymbols = [];
2881
+ const exportLabels = [];
2882
+ for (const child of rootNode.namedChildren) {
2883
+ if (!child) {
2884
+ continue;
2885
+ }
2886
+ if (child.type === "local_variable_declaration" || child.type === "assignment_statement") {
2887
+ const parsed = parseLuaRequire(child);
2888
+ if (parsed) {
2889
+ imports.push(parsed);
2890
+ }
2891
+ continue;
2892
+ }
2893
+ if (!["function_definition_statement", "local_function_definition_statement"].includes(child.type)) {
2894
+ continue;
2895
+ }
2896
+ const name = luaFunctionName(child.childForFieldName("name") ?? child.namedChildren.at(0) ?? null);
2897
+ if (!name) {
2898
+ continue;
2899
+ }
2900
+ draftSymbols.push({
2901
+ name,
2902
+ kind: "function",
2903
+ signature: singleLineSignature(child.text),
2904
+ exported: child.type !== "local_function_definition_statement",
2905
+ callNames: [],
2906
+ extendsNames: [],
2907
+ implementsNames: [],
2908
+ bodyText: nodeText(findNamedChild(child, "block") ?? child.childForFieldName("body")) || child.text
2909
+ });
2910
+ if (child.type !== "local_function_definition_statement") {
2911
+ exportLabels.push(name);
2912
+ }
2913
+ }
2914
+ return finalizeCodeAnalysis(manifest, "lua", imports, draftSymbols, exportLabels, diagnostics);
2915
+ }
2916
+ function zigCodeAnalysis(manifest, rootNode, diagnostics) {
2917
+ const imports = [];
2918
+ const draftSymbols = [];
2919
+ const exportLabels = [];
2920
+ const pushStructMembers = (structNode, scopeName) => {
2921
+ if (!structNode) {
2922
+ return;
2923
+ }
2924
+ for (const child of structNode.namedChildren) {
2925
+ if (!child || child.type !== "function_declaration") {
2926
+ continue;
2927
+ }
2928
+ const functionName = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2929
+ if (!functionName) {
2930
+ continue;
2931
+ }
2932
+ const exported = /\bpub\b/.test(child.text);
2933
+ const symbolName = `${scopeName}.${functionName}`;
2934
+ draftSymbols.push({
2935
+ name: symbolName,
2936
+ kind: "function",
2937
+ signature: singleLineSignature(child.text),
2938
+ exported,
2939
+ callNames: [],
2940
+ extendsNames: [],
2941
+ implementsNames: [],
2942
+ bodyText: nodeText(findNamedChild(child, "block") ?? child.childForFieldName("body")) || child.text
2943
+ });
2944
+ if (exported) {
2945
+ exportLabels.push(symbolName);
2946
+ }
2947
+ }
2948
+ };
2949
+ for (const child of rootNode.namedChildren) {
2950
+ if (!child) {
2951
+ continue;
2952
+ }
2953
+ if (child.type === "variable_declaration") {
2954
+ const parsedImport = parseZigImport(child);
2955
+ if (parsedImport) {
2956
+ imports.push(parsedImport);
2957
+ continue;
2958
+ }
2959
+ const name = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2960
+ const kind = zigDeclarationKind(child);
2961
+ if (!name || !kind) {
2962
+ continue;
2963
+ }
2964
+ const declarationNode = findNamedChild(child, "struct_declaration") ?? findNamedChild(child, "enum_declaration");
2965
+ const exported2 = /\bpub\b/.test(child.text);
2966
+ draftSymbols.push({
2967
+ name,
2968
+ kind,
2969
+ signature: singleLineSignature(child.text),
2970
+ exported: exported2,
2971
+ callNames: [],
2972
+ extendsNames: [],
2973
+ implementsNames: [],
2974
+ bodyText: nodeText(declarationNode) || child.text
2975
+ });
2976
+ if (exported2) {
2977
+ exportLabels.push(name);
2978
+ }
2979
+ if (kind === "struct") {
2980
+ pushStructMembers(declarationNode, name);
2981
+ }
2982
+ continue;
2983
+ }
2984
+ if (child.type !== "function_declaration") {
2985
+ continue;
2986
+ }
2987
+ const functionName = extractIdentifier(child.childForFieldName("name") ?? findNamedChild(child, "identifier"));
2988
+ if (!functionName) {
2989
+ continue;
2990
+ }
2991
+ const exported = /\bpub\b/.test(child.text);
2992
+ draftSymbols.push({
2993
+ name: functionName,
2994
+ kind: "function",
2995
+ signature: singleLineSignature(child.text),
2996
+ exported,
2997
+ callNames: [],
2998
+ extendsNames: [],
2999
+ implementsNames: [],
3000
+ bodyText: nodeText(findNamedChild(child, "block") ?? child.childForFieldName("body")) || child.text
3001
+ });
3002
+ if (exported) {
3003
+ exportLabels.push(functionName);
3004
+ }
3005
+ }
3006
+ return finalizeCodeAnalysis(manifest, "zig", imports, draftSymbols, exportLabels, diagnostics);
3007
+ }
2817
3008
  function csharpCodeAnalysis(manifest, rootNode, diagnostics) {
2818
3009
  const imports = [];
2819
3010
  const draftSymbols = [];
@@ -3246,6 +3437,10 @@ async function analyzeTreeSitterCode(manifest, content, language) {
3246
3437
  return { code: kotlinCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3247
3438
  case "scala":
3248
3439
  return { code: scalaCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3440
+ case "lua":
3441
+ return { code: luaCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3442
+ case "zig":
3443
+ return { code: zigCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3249
3444
  case "csharp":
3250
3445
  return { code: csharpCodeAnalysis(manifest, tree.rootNode, diagnostics), rationales };
3251
3446
  case "php":
@@ -3532,7 +3727,7 @@ function makeRationale2(manifest, index, text, kind, symbolName) {
3532
3727
  };
3533
3728
  }
3534
3729
  function stripCodeExtension2(filePath) {
3535
- return filePath.replace(/\.(?:[cm]?jsx?|tsx?|mts|cts|py|go|rs|java|kt|kts|scala|sc|cs|php|c|cc|cpp|cxx|h|hh|hpp|hxx)$/i, "");
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, "");
3536
3731
  }
3537
3732
  function manifestModuleName2(manifest, language) {
3538
3733
  const repoPath = manifest.repoRelativePath ?? path6.basename(manifest.originalPath ?? manifest.storedPath);
@@ -3869,6 +4064,12 @@ function inferCodeLanguage(filePath, mimeType = "") {
3869
4064
  if (extension === ".scala" || extension === ".sc") {
3870
4065
  return "scala";
3871
4066
  }
4067
+ if (extension === ".lua") {
4068
+ return "lua";
4069
+ }
4070
+ if (extension === ".zig") {
4071
+ return "zig";
4072
+ }
3872
4073
  if (extension === ".cs") {
3873
4074
  return "csharp";
3874
4075
  }
@@ -3977,6 +4178,10 @@ function candidateExtensionsFor(language) {
3977
4178
  return [".kt", ".kts"];
3978
4179
  case "scala":
3979
4180
  return [".scala", ".sc"];
4181
+ case "lua":
4182
+ return [".lua"];
4183
+ case "zig":
4184
+ return [".zig"];
3980
4185
  case "csharp":
3981
4186
  return [".cs"];
3982
4187
  case "php":
@@ -4049,6 +4254,20 @@ async function buildCodeIndex(rootDir, manifests, analyses) {
4049
4254
  }
4050
4255
  }
4051
4256
  break;
4257
+ case "lua":
4258
+ recordAlias(aliases, basename);
4259
+ if (repoRelativePath) {
4260
+ const repoWithoutExt = stripCodeExtension2(repoRelativePath);
4261
+ recordAlias(aliases, repoWithoutExt.replace(/\//g, "."));
4262
+ if (repoWithoutExt.endsWith("/init")) {
4263
+ recordAlias(aliases, repoWithoutExt.slice(0, -"/init".length));
4264
+ recordAlias(aliases, repoWithoutExt.slice(0, -"/init".length).replace(/\//g, "."));
4265
+ }
4266
+ }
4267
+ break;
4268
+ case "zig":
4269
+ recordAlias(aliases, basename);
4270
+ break;
4052
4271
  case "php":
4053
4272
  if (normalizedNamespace) {
4054
4273
  recordAlias(aliases, `${normalizedNamespace}\\${basename}`);
@@ -4135,6 +4354,16 @@ function resolveRustAliases(manifest, specifier) {
4135
4354
  `crate${currentParts.length > 1 ? `::${currentParts.slice(0, -1).join("::")}` : ""}::${specifier.slice("super::".length)}`.replace(/::+/g, "::").replace(/::$/, "")
4136
4355
  ];
4137
4356
  }
4357
+ function luaSpecifierLooksLocal(specifier) {
4358
+ return /^[A-Za-z_][A-Za-z0-9_]*(?:[./][A-Za-z_][A-Za-z0-9_]*)*$/.test(specifier);
4359
+ }
4360
+ function resolveLuaModuleCandidates(specifier) {
4361
+ const normalized = normalizeAlias(specifier.replace(/\./g, "/"));
4362
+ if (!normalized) {
4363
+ return [];
4364
+ }
4365
+ return uniqueBy([`${normalized}.lua`, path6.posix.join(normalized, "init.lua")], (item) => item);
4366
+ }
4138
4367
  function findImportCandidates(manifest, codeImport, lookup) {
4139
4368
  const language = manifest.language ?? inferCodeLanguage(manifest.originalPath ?? manifest.storedPath, manifest.mimeType);
4140
4369
  const repoRelativePath = manifest.repoRelativePath ? normalizeAlias(manifest.repoRelativePath) : void 0;
@@ -4158,6 +4387,10 @@ function findImportCandidates(manifest, codeImport, lookup) {
4158
4387
  case "scala":
4159
4388
  case "csharp":
4160
4389
  return aliasMatches(lookup, codeImport.specifier);
4390
+ case "lua":
4391
+ return luaSpecifierLooksLocal(codeImport.specifier) ? repoPathMatches(lookup, ...resolveLuaModuleCandidates(codeImport.specifier)) : aliasMatches(lookup, codeImport.specifier, codeImport.specifier.replace(/\./g, "/"));
4392
+ case "zig":
4393
+ return repoRelativePath && (!codeImport.isExternal || codeImport.specifier.endsWith(".zig")) ? repoPathMatches(lookup, ...importResolutionCandidates(repoRelativePath, codeImport.specifier, candidateExtensionsFor(language))) : aliasMatches(lookup, codeImport.specifier);
4161
4394
  case "php":
4162
4395
  case "ruby":
4163
4396
  case "powershell":
@@ -4205,6 +4438,10 @@ function importLooksLocal(manifest, codeImport, candidates) {
4205
4438
  case "kotlin":
4206
4439
  case "scala":
4207
4440
  return !codeImport.isExternal;
4441
+ case "lua":
4442
+ return luaSpecifierLooksLocal(codeImport.specifier);
4443
+ case "zig":
4444
+ return !codeImport.isExternal || codeImport.specifier.endsWith(".zig");
4208
4445
  default:
4209
4446
  return false;
4210
4447
  }
@@ -14611,7 +14848,7 @@ async function bootstrapDemo(rootDir, input) {
14611
14848
  }
14612
14849
 
14613
14850
  // src/mcp.ts
14614
- var SERVER_VERSION = "0.2.0";
14851
+ var SERVER_VERSION = "0.2.1";
14615
14852
  async function createMcpServer(rootDir) {
14616
14853
  const server = new McpServer({
14617
14854
  name: "swarmvault",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarmvaultai/engine",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Core engine for SwarmVault: ingest, compile, query, lint, and provider abstractions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",