@jafreck/lore 0.1.0
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/LICENSE +21 -0
- package/README.md +405 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +345 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/call-graph.d.ts +39 -0
- package/dist/indexer/call-graph.d.ts.map +1 -0
- package/dist/indexer/call-graph.js +193 -0
- package/dist/indexer/call-graph.js.map +1 -0
- package/dist/indexer/complexity.d.ts +9 -0
- package/dist/indexer/complexity.d.ts.map +1 -0
- package/dist/indexer/complexity.js +66 -0
- package/dist/indexer/complexity.js.map +1 -0
- package/dist/indexer/config-parser.d.ts +16 -0
- package/dist/indexer/config-parser.d.ts.map +1 -0
- package/dist/indexer/config-parser.js +261 -0
- package/dist/indexer/config-parser.js.map +1 -0
- package/dist/indexer/coverage.d.ts +13 -0
- package/dist/indexer/coverage.d.ts.map +1 -0
- package/dist/indexer/coverage.js +84 -0
- package/dist/indexer/coverage.js.map +1 -0
- package/dist/indexer/db.d.ts +38 -0
- package/dist/indexer/db.d.ts.map +1 -0
- package/dist/indexer/db.js +275 -0
- package/dist/indexer/db.js.map +1 -0
- package/dist/indexer/embedder.d.ts +70 -0
- package/dist/indexer/embedder.d.ts.map +1 -0
- package/dist/indexer/embedder.js +186 -0
- package/dist/indexer/embedder.js.map +1 -0
- package/dist/indexer/ensure-python-deps.d.ts +22 -0
- package/dist/indexer/ensure-python-deps.d.ts.map +1 -0
- package/dist/indexer/ensure-python-deps.js +47 -0
- package/dist/indexer/ensure-python-deps.js.map +1 -0
- package/dist/indexer/extractors/bash.d.ts +12 -0
- package/dist/indexer/extractors/bash.d.ts.map +1 -0
- package/dist/indexer/extractors/bash.js +57 -0
- package/dist/indexer/extractors/bash.js.map +1 -0
- package/dist/indexer/extractors/c.d.ts +12 -0
- package/dist/indexer/extractors/c.d.ts.map +1 -0
- package/dist/indexer/extractors/c.js +106 -0
- package/dist/indexer/extractors/c.js.map +1 -0
- package/dist/indexer/extractors/cpp.d.ts +12 -0
- package/dist/indexer/extractors/cpp.d.ts.map +1 -0
- package/dist/indexer/extractors/cpp.js +84 -0
- package/dist/indexer/extractors/cpp.js.map +1 -0
- package/dist/indexer/extractors/csharp.d.ts +12 -0
- package/dist/indexer/extractors/csharp.d.ts.map +1 -0
- package/dist/indexer/extractors/csharp.js +79 -0
- package/dist/indexer/extractors/csharp.js.map +1 -0
- package/dist/indexer/extractors/dart.d.ts +12 -0
- package/dist/indexer/extractors/dart.d.ts.map +1 -0
- package/dist/indexer/extractors/dart.js +80 -0
- package/dist/indexer/extractors/dart.js.map +1 -0
- package/dist/indexer/extractors/elixir.d.ts +12 -0
- package/dist/indexer/extractors/elixir.d.ts.map +1 -0
- package/dist/indexer/extractors/elixir.js +87 -0
- package/dist/indexer/extractors/elixir.js.map +1 -0
- package/dist/indexer/extractors/elm.d.ts +12 -0
- package/dist/indexer/extractors/elm.d.ts.map +1 -0
- package/dist/indexer/extractors/elm.js +87 -0
- package/dist/indexer/extractors/elm.js.map +1 -0
- package/dist/indexer/extractors/go.d.ts +12 -0
- package/dist/indexer/extractors/go.d.ts.map +1 -0
- package/dist/indexer/extractors/go.js +158 -0
- package/dist/indexer/extractors/go.js.map +1 -0
- package/dist/indexer/extractors/haskell.d.ts +12 -0
- package/dist/indexer/extractors/haskell.d.ts.map +1 -0
- package/dist/indexer/extractors/haskell.js +104 -0
- package/dist/indexer/extractors/haskell.js.map +1 -0
- package/dist/indexer/extractors/java.d.ts +12 -0
- package/dist/indexer/extractors/java.d.ts.map +1 -0
- package/dist/indexer/extractors/java.js +68 -0
- package/dist/indexer/extractors/java.js.map +1 -0
- package/dist/indexer/extractors/javascript.d.ts +13 -0
- package/dist/indexer/extractors/javascript.d.ts.map +1 -0
- package/dist/indexer/extractors/javascript.js +180 -0
- package/dist/indexer/extractors/javascript.js.map +1 -0
- package/dist/indexer/extractors/julia.d.ts +12 -0
- package/dist/indexer/extractors/julia.d.ts.map +1 -0
- package/dist/indexer/extractors/julia.js +94 -0
- package/dist/indexer/extractors/julia.js.map +1 -0
- package/dist/indexer/extractors/kotlin.d.ts +12 -0
- package/dist/indexer/extractors/kotlin.d.ts.map +1 -0
- package/dist/indexer/extractors/kotlin.js +71 -0
- package/dist/indexer/extractors/kotlin.js.map +1 -0
- package/dist/indexer/extractors/lua.d.ts +12 -0
- package/dist/indexer/extractors/lua.d.ts.map +1 -0
- package/dist/indexer/extractors/lua.js +68 -0
- package/dist/indexer/extractors/lua.js.map +1 -0
- package/dist/indexer/extractors/objc.d.ts +12 -0
- package/dist/indexer/extractors/objc.d.ts.map +1 -0
- package/dist/indexer/extractors/objc.js +129 -0
- package/dist/indexer/extractors/objc.js.map +1 -0
- package/dist/indexer/extractors/ocaml.d.ts +12 -0
- package/dist/indexer/extractors/ocaml.d.ts.map +1 -0
- package/dist/indexer/extractors/ocaml.js +92 -0
- package/dist/indexer/extractors/ocaml.js.map +1 -0
- package/dist/indexer/extractors/php.d.ts +12 -0
- package/dist/indexer/extractors/php.d.ts.map +1 -0
- package/dist/indexer/extractors/php.js +99 -0
- package/dist/indexer/extractors/php.js.map +1 -0
- package/dist/indexer/extractors/python.d.ts +12 -0
- package/dist/indexer/extractors/python.d.ts.map +1 -0
- package/dist/indexer/extractors/python.js +129 -0
- package/dist/indexer/extractors/python.js.map +1 -0
- package/dist/indexer/extractors/ruby.d.ts +12 -0
- package/dist/indexer/extractors/ruby.d.ts.map +1 -0
- package/dist/indexer/extractors/ruby.js +100 -0
- package/dist/indexer/extractors/ruby.js.map +1 -0
- package/dist/indexer/extractors/rust.d.ts +12 -0
- package/dist/indexer/extractors/rust.d.ts.map +1 -0
- package/dist/indexer/extractors/rust.js +82 -0
- package/dist/indexer/extractors/rust.js.map +1 -0
- package/dist/indexer/extractors/scala.d.ts +12 -0
- package/dist/indexer/extractors/scala.d.ts.map +1 -0
- package/dist/indexer/extractors/scala.js +91 -0
- package/dist/indexer/extractors/scala.js.map +1 -0
- package/dist/indexer/extractors/swift.d.ts +12 -0
- package/dist/indexer/extractors/swift.d.ts.map +1 -0
- package/dist/indexer/extractors/swift.js +90 -0
- package/dist/indexer/extractors/swift.js.map +1 -0
- package/dist/indexer/extractors/types.d.ts +118 -0
- package/dist/indexer/extractors/types.d.ts.map +1 -0
- package/dist/indexer/extractors/types.js +43 -0
- package/dist/indexer/extractors/types.js.map +1 -0
- package/dist/indexer/extractors/typescript.d.ts +14 -0
- package/dist/indexer/extractors/typescript.d.ts.map +1 -0
- package/dist/indexer/extractors/typescript.js +172 -0
- package/dist/indexer/extractors/typescript.js.map +1 -0
- package/dist/indexer/extractors/zig.d.ts +12 -0
- package/dist/indexer/extractors/zig.d.ts.map +1 -0
- package/dist/indexer/extractors/zig.js +95 -0
- package/dist/indexer/extractors/zig.js.map +1 -0
- package/dist/indexer/git-history.d.ts +23 -0
- package/dist/indexer/git-history.d.ts.map +1 -0
- package/dist/indexer/git-history.js +144 -0
- package/dist/indexer/git-history.js.map +1 -0
- package/dist/indexer/git-hooks.d.ts +19 -0
- package/dist/indexer/git-hooks.d.ts.map +1 -0
- package/dist/indexer/git-hooks.js +74 -0
- package/dist/indexer/git-hooks.js.map +1 -0
- package/dist/indexer/index.d.ts +83 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +431 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/parser.d.ts +30 -0
- package/dist/indexer/parser.d.ts.map +1 -0
- package/dist/indexer/parser.js +114 -0
- package/dist/indexer/parser.js.map +1 -0
- package/dist/indexer/poller.d.ts +50 -0
- package/dist/indexer/poller.d.ts.map +1 -0
- package/dist/indexer/poller.js +140 -0
- package/dist/indexer/poller.js.map +1 -0
- package/dist/indexer/resolver.d.ts +52 -0
- package/dist/indexer/resolver.d.ts.map +1 -0
- package/dist/indexer/resolver.js +271 -0
- package/dist/indexer/resolver.js.map +1 -0
- package/dist/indexer/test-mapper.d.ts +6 -0
- package/dist/indexer/test-mapper.d.ts.map +1 -0
- package/dist/indexer/test-mapper.js +48 -0
- package/dist/indexer/test-mapper.js.map +1 -0
- package/dist/indexer/walker.d.ts +51 -0
- package/dist/indexer/walker.d.ts.map +1 -0
- package/dist/indexer/walker.js +100 -0
- package/dist/indexer/walker.js.map +1 -0
- package/dist/indexer/watcher.d.ts +51 -0
- package/dist/indexer/watcher.d.ts.map +1 -0
- package/dist/indexer/watcher.js +107 -0
- package/dist/indexer/watcher.js.map +1 -0
- package/dist/kb-server/db.d.ts +241 -0
- package/dist/kb-server/db.d.ts.map +1 -0
- package/dist/kb-server/db.js +659 -0
- package/dist/kb-server/db.js.map +1 -0
- package/dist/kb-server/server.d.ts +35 -0
- package/dist/kb-server/server.d.ts.map +1 -0
- package/dist/kb-server/server.js +240 -0
- package/dist/kb-server/server.js.map +1 -0
- package/dist/kb-server/tools/annotations.d.ts +40 -0
- package/dist/kb-server/tools/annotations.d.ts.map +1 -0
- package/dist/kb-server/tools/annotations.js +35 -0
- package/dist/kb-server/tools/annotations.js.map +1 -0
- package/dist/kb-server/tools/architecture.d.ts +60 -0
- package/dist/kb-server/tools/architecture.d.ts.map +1 -0
- package/dist/kb-server/tools/architecture.js +174 -0
- package/dist/kb-server/tools/architecture.js.map +1 -0
- package/dist/kb-server/tools/blame.d.ts +67 -0
- package/dist/kb-server/tools/blame.d.ts.map +1 -0
- package/dist/kb-server/tools/blame.js +162 -0
- package/dist/kb-server/tools/blame.js.map +1 -0
- package/dist/kb-server/tools/coverage.d.ts +67 -0
- package/dist/kb-server/tools/coverage.d.ts.map +1 -0
- package/dist/kb-server/tools/coverage.js +74 -0
- package/dist/kb-server/tools/coverage.js.map +1 -0
- package/dist/kb-server/tools/graph.d.ts +56 -0
- package/dist/kb-server/tools/graph.d.ts.map +1 -0
- package/dist/kb-server/tools/graph.js +188 -0
- package/dist/kb-server/tools/graph.js.map +1 -0
- package/dist/kb-server/tools/history.d.ts +47 -0
- package/dist/kb-server/tools/history.d.ts.map +1 -0
- package/dist/kb-server/tools/history.js +91 -0
- package/dist/kb-server/tools/history.js.map +1 -0
- package/dist/kb-server/tools/lookup.d.ts +36 -0
- package/dist/kb-server/tools/lookup.d.ts.map +1 -0
- package/dist/kb-server/tools/lookup.js +45 -0
- package/dist/kb-server/tools/lookup.js.map +1 -0
- package/dist/kb-server/tools/metrics.d.ts +73 -0
- package/dist/kb-server/tools/metrics.d.ts.map +1 -0
- package/dist/kb-server/tools/metrics.js +79 -0
- package/dist/kb-server/tools/metrics.js.map +1 -0
- package/dist/kb-server/tools/notes.d.ts +165 -0
- package/dist/kb-server/tools/notes.d.ts.map +1 -0
- package/dist/kb-server/tools/notes.js +175 -0
- package/dist/kb-server/tools/notes.js.map +1 -0
- package/dist/kb-server/tools/routes.d.ts +38 -0
- package/dist/kb-server/tools/routes.d.ts.map +1 -0
- package/dist/kb-server/tools/routes.js +38 -0
- package/dist/kb-server/tools/routes.js.map +1 -0
- package/dist/kb-server/tools/search.d.ts +60 -0
- package/dist/kb-server/tools/search.d.ts.map +1 -0
- package/dist/kb-server/tools/search.js +170 -0
- package/dist/kb-server/tools/search.js.map +1 -0
- package/dist/kb-server/tools/snippet.d.ts +44 -0
- package/dist/kb-server/tools/snippet.d.ts.map +1 -0
- package/dist/kb-server/tools/snippet.js +49 -0
- package/dist/kb-server/tools/snippet.js.map +1 -0
- package/dist/kb-server/tools/test-map.d.ts +38 -0
- package/dist/kb-server/tools/test-map.d.ts.map +1 -0
- package/dist/kb-server/tools/test-map.js +32 -0
- package/dist/kb-server/tools/test-map.js.map +1 -0
- package/dist/kb-server/tools/writeback.d.ts +49 -0
- package/dist/kb-server/tools/writeback.d.ts.map +1 -0
- package/dist/kb-server/tools/writeback.js +68 -0
- package/dist/kb-server/tools/writeback.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/extractors/zig
|
|
3
|
+
*
|
|
4
|
+
* Zig language extractor. Extracts function declarations (fn), struct/enum/union
|
|
5
|
+
* declarations, and @import() calls.
|
|
6
|
+
*/
|
|
7
|
+
import { emptyResult, nodeSignature, walk, } from './types.js';
|
|
8
|
+
// ─── ZigExtractor ─────────────────────────────────────────────────────────────
|
|
9
|
+
export class ZigExtractor {
|
|
10
|
+
extract(tree, _source, _filePath) {
|
|
11
|
+
const result = emptyResult();
|
|
12
|
+
for (const node of walk(tree.rootNode)) {
|
|
13
|
+
switch (node.type) {
|
|
14
|
+
case 'FnProto':
|
|
15
|
+
result.symbols.push(extractFn(node));
|
|
16
|
+
break;
|
|
17
|
+
case 'TestDecl':
|
|
18
|
+
result.symbols.push(extractTest(node));
|
|
19
|
+
break;
|
|
20
|
+
case 'ContainerDecl':
|
|
21
|
+
// struct/enum/union — try to find enclosing VarDecl for the name
|
|
22
|
+
break;
|
|
23
|
+
case 'VarDecl': {
|
|
24
|
+
const sym = extractVarDecl(node);
|
|
25
|
+
if (sym)
|
|
26
|
+
result.symbols.push(sym);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case 'BUILTIN': {
|
|
30
|
+
if (node.text === '@import') {
|
|
31
|
+
const imp = tryExtractImport(node);
|
|
32
|
+
if (imp)
|
|
33
|
+
result.imports.push(imp);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
43
|
+
function extractFn(node) {
|
|
44
|
+
const nameNode = node.namedChildren.find(c => c.type === 'IDENTIFIER');
|
|
45
|
+
return {
|
|
46
|
+
name: nameNode?.text ?? '',
|
|
47
|
+
kind: 'function',
|
|
48
|
+
startLine: node.startPosition.row,
|
|
49
|
+
endLine: node.endPosition.row,
|
|
50
|
+
signature: nodeSignature(node),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function extractTest(node) {
|
|
54
|
+
// test "name" { ... }
|
|
55
|
+
const nameNode = node.namedChildren.find(c => c.type === 'STRINGLITERALSINGLE');
|
|
56
|
+
return {
|
|
57
|
+
name: nameNode?.text.replace(/^"|"$/g, '') ?? 'test',
|
|
58
|
+
kind: 'test',
|
|
59
|
+
startLine: node.startPosition.row,
|
|
60
|
+
endLine: node.endPosition.row,
|
|
61
|
+
signature: nodeSignature(node),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `const Foo = struct { ... }` or `pub const bar = ...`
|
|
66
|
+
* We extract top-level const/var declarations that have container bodies or
|
|
67
|
+
* are otherwise significant.
|
|
68
|
+
*/
|
|
69
|
+
function extractVarDecl(node) {
|
|
70
|
+
const nameNode = node.namedChildren.find(c => c.type === 'IDENTIFIER');
|
|
71
|
+
if (!nameNode)
|
|
72
|
+
return null;
|
|
73
|
+
// Check if this is a type definition (assigned a struct/enum/union)
|
|
74
|
+
const hasContainer = node.namedChildren.some(c => c.type === 'ContainerDecl' || c.type === 'ErrorSetDecl');
|
|
75
|
+
const kind = hasContainer ? 'type' : 'const';
|
|
76
|
+
return {
|
|
77
|
+
name: nameNode.text,
|
|
78
|
+
kind,
|
|
79
|
+
startLine: node.startPosition.row,
|
|
80
|
+
endLine: node.endPosition.row,
|
|
81
|
+
signature: nodeSignature(node),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function tryExtractImport(node) {
|
|
85
|
+
// @import("std") — the parent is typically a BuiltinCallExpr
|
|
86
|
+
const parent = node.parent;
|
|
87
|
+
if (!parent)
|
|
88
|
+
return null;
|
|
89
|
+
const argNode = parent.namedChildren.find(c => c.type === 'STRINGLITERALSINGLE');
|
|
90
|
+
if (!argNode)
|
|
91
|
+
return null;
|
|
92
|
+
const source = argNode.text.replace(/^"|"$/g, '');
|
|
93
|
+
return { source, importedNames: [] };
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=zig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zig.js","sourceRoot":"","sources":["../../../src/indexer/extractors/zig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAKL,WAAW,EACX,aAAa,EACb,IAAI,GACL,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AAEjF,MAAM,OAAO,YAAY;IACvB,OAAO,CAAC,IAAiB,EAAE,OAAe,EAAE,SAAiB;QAC3D,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAE7B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,SAAS;oBACZ,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;oBACrC,MAAM;gBACR,KAAK,UAAU;oBACb,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;oBACvC,MAAM;gBACR,KAAK,eAAe;oBAClB,iEAAiE;oBACjE,MAAM;gBACR,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;oBACjC,IAAI,GAAG;wBAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAClC,MAAM;gBACR,CAAC;gBACD,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;wBAC5B,MAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;wBACnC,IAAI,GAAG;4BAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACpC,CA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AAY,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAC1C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,CAC7D,CAAC;IAEF,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,IAAI;QACJ,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG;QACjC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG;QAC7B,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAuB;IAC/C,6DAA6D;IAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;IACjF,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/git-history
|
|
3
|
+
*
|
|
4
|
+
* Ingests git commit history into the `commits` and `commit_files` tables
|
|
5
|
+
* using simple-git to read commit metadata and per-file diff stats.
|
|
6
|
+
*/
|
|
7
|
+
import { type Database } from './db.js';
|
|
8
|
+
export interface GitHistoryOptions {
|
|
9
|
+
depth?: number;
|
|
10
|
+
all?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads commit history from the git repository at `repoRoot` and upserts each
|
|
14
|
+
* commit and its associated file changes into the `commits` and
|
|
15
|
+
* `commit_files` tables. By default, Lore traverses all refs (`--all`) with
|
|
16
|
+
* no depth limit; `options.depth` can be used to cap the number of ingested
|
|
17
|
+
* commits.
|
|
18
|
+
*
|
|
19
|
+
* The function is idempotent: rows are inserted with INSERT OR IGNORE so
|
|
20
|
+
* re-running it on the same repository will not produce duplicates.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ingestGitHistory(db: Database.Database, repoRoot: string, options?: GitHistoryOptions): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=git-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-history.d.ts","sourceRoot":"","sources":["../../src/indexer/git-history.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAwB,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAKD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAoJf"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/git-history
|
|
3
|
+
*
|
|
4
|
+
* Ingests git commit history into the `commits` and `commit_files` tables
|
|
5
|
+
* using simple-git to read commit metadata and per-file diff stats.
|
|
6
|
+
*/
|
|
7
|
+
import { simpleGit } from 'simple-git';
|
|
8
|
+
import { getKbMeta, setKbMeta } from './db.js';
|
|
9
|
+
const DEFAULT_ALL = true;
|
|
10
|
+
const GIT_HISTORY_WATERMARK_KEY = 'git_history_last_ingested_sha';
|
|
11
|
+
/**
|
|
12
|
+
* Reads commit history from the git repository at `repoRoot` and upserts each
|
|
13
|
+
* commit and its associated file changes into the `commits` and
|
|
14
|
+
* `commit_files` tables. By default, Lore traverses all refs (`--all`) with
|
|
15
|
+
* no depth limit; `options.depth` can be used to cap the number of ingested
|
|
16
|
+
* commits.
|
|
17
|
+
*
|
|
18
|
+
* The function is idempotent: rows are inserted with INSERT OR IGNORE so
|
|
19
|
+
* re-running it on the same repository will not produce duplicates.
|
|
20
|
+
*/
|
|
21
|
+
export async function ingestGitHistory(db, repoRoot, options) {
|
|
22
|
+
const all = options?.all ?? DEFAULT_ALL;
|
|
23
|
+
const depth = typeof options?.depth === 'number' && Number.isFinite(options.depth) && options.depth > 0
|
|
24
|
+
? Math.floor(options.depth)
|
|
25
|
+
: undefined;
|
|
26
|
+
const git = simpleGit(repoRoot);
|
|
27
|
+
const storedWatermark = getKbMeta(db, GIT_HISTORY_WATERMARK_KEY);
|
|
28
|
+
let watermark;
|
|
29
|
+
if (storedWatermark) {
|
|
30
|
+
try {
|
|
31
|
+
await git.raw(['cat-file', '-e', `${storedWatermark}^{commit}`]);
|
|
32
|
+
watermark = storedWatermark;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
watermark = undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const logArgs = [
|
|
39
|
+
'log',
|
|
40
|
+
'--numstat',
|
|
41
|
+
'--format=COMMIT_SEP%n%H%n%an%n%ae%n%at%n%P%n%s',
|
|
42
|
+
];
|
|
43
|
+
if (watermark) {
|
|
44
|
+
logArgs.push(`${watermark}..`);
|
|
45
|
+
}
|
|
46
|
+
if (all) {
|
|
47
|
+
logArgs.push('--all');
|
|
48
|
+
}
|
|
49
|
+
if (depth !== undefined) {
|
|
50
|
+
logArgs.push(`--max-count=${depth}`);
|
|
51
|
+
}
|
|
52
|
+
// Fetch log with numstat for diff stats.
|
|
53
|
+
// --numstat outputs insertion/deletion counts per file after each commit header.
|
|
54
|
+
const logResult = await git.raw(logArgs);
|
|
55
|
+
// Capture heads/tags that currently point to commits so branch/tag metadata
|
|
56
|
+
// is also available in the KB.
|
|
57
|
+
let refsRaw = '';
|
|
58
|
+
try {
|
|
59
|
+
refsRaw = await git.raw(['show-ref', '--heads', '--tags']);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
refsRaw = '';
|
|
63
|
+
}
|
|
64
|
+
const insertCommit = db.prepare(`INSERT OR IGNORE INTO commits (sha, author, author_email, timestamp, message, parents)
|
|
65
|
+
VALUES (?, ?, ?, ?, ?, ?)`);
|
|
66
|
+
const insertCommitFile = db.prepare(`INSERT OR IGNORE INTO commit_files (commit_sha, file_path, change_type, insertions, deletions)
|
|
67
|
+
VALUES (?, ?, ?, ?, ?)`);
|
|
68
|
+
const insertCommitRef = db.prepare(`INSERT OR IGNORE INTO commit_refs (commit_sha, ref_name, ref_type)
|
|
69
|
+
SELECT ?, ?, ?
|
|
70
|
+
WHERE EXISTS (SELECT 1 FROM commits WHERE sha = ?)`);
|
|
71
|
+
const deleteCommitRefs = db.prepare('DELETE FROM commit_refs');
|
|
72
|
+
// Parse the raw git log output into commit blocks.
|
|
73
|
+
// Each block starts with "COMMIT_SEP" followed by commit metadata lines,
|
|
74
|
+
// then an empty line, then numstat lines (insertions<TAB>deletions<TAB>path).
|
|
75
|
+
const blocks = logResult.split('COMMIT_SEP\n').filter((b) => b.trim().length > 0);
|
|
76
|
+
const latestShaInRun = blocks[0]?.split('\n')[0]?.trim();
|
|
77
|
+
db.transaction(() => {
|
|
78
|
+
for (const block of blocks) {
|
|
79
|
+
const lines = block.split('\n');
|
|
80
|
+
const sha = lines[0]?.trim();
|
|
81
|
+
const author = lines[1]?.trim();
|
|
82
|
+
const authorEmail = lines[2]?.trim();
|
|
83
|
+
const timestampStr = lines[3]?.trim();
|
|
84
|
+
const parentsStr = lines[4]?.trim() ?? '';
|
|
85
|
+
const message = lines[5]?.trim() ?? '';
|
|
86
|
+
if (!sha || !author || !authorEmail || !timestampStr)
|
|
87
|
+
continue;
|
|
88
|
+
const timestamp = parseInt(timestampStr, 10);
|
|
89
|
+
const parents = JSON.stringify(parentsStr.length > 0 ? parentsStr.split(' ') : []);
|
|
90
|
+
insertCommit.run(sha, author, authorEmail, timestamp, message, parents);
|
|
91
|
+
// Numstat lines start after the blank line (index 6 onward)
|
|
92
|
+
for (let i = 7; i < lines.length; i++) {
|
|
93
|
+
const line = lines[i]?.trim();
|
|
94
|
+
if (!line)
|
|
95
|
+
continue;
|
|
96
|
+
// numstat format: <insertions>\t<deletions>\t<path>
|
|
97
|
+
// Binary files show "-" for both insertions and deletions.
|
|
98
|
+
const parts = line.split('\t');
|
|
99
|
+
if (parts.length < 3)
|
|
100
|
+
continue;
|
|
101
|
+
const [insStr, delStr, ...pathParts] = parts;
|
|
102
|
+
const filePath = pathParts.join('\t'); // handle tab-in-path edge case
|
|
103
|
+
const insertions = insStr === '-' ? null : parseInt(insStr, 10);
|
|
104
|
+
const deletions = delStr === '-' ? null : parseInt(delStr, 10);
|
|
105
|
+
// Determine change type based on diff stats presence.
|
|
106
|
+
// Rename detection (e.g. "old => new") is noted as a renamed file.
|
|
107
|
+
let changeType = 'modified';
|
|
108
|
+
if (filePath.includes('{') && filePath.includes('=>')) {
|
|
109
|
+
changeType = 'renamed';
|
|
110
|
+
}
|
|
111
|
+
else if (insertions !== null && deletions === 0 && insertions > 0) {
|
|
112
|
+
changeType = 'added';
|
|
113
|
+
}
|
|
114
|
+
else if (deletions !== null && insertions === 0 && deletions > 0) {
|
|
115
|
+
changeType = 'deleted';
|
|
116
|
+
}
|
|
117
|
+
insertCommitFile.run(sha, filePath, changeType, insertions, deletions);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const refLines = refsRaw
|
|
121
|
+
.split('\n')
|
|
122
|
+
.map((line) => line.trim())
|
|
123
|
+
.filter((line) => line.length > 0);
|
|
124
|
+
const refs = refLines
|
|
125
|
+
.map((line) => line.split(/\s+/, 2))
|
|
126
|
+
.filter((parts) => Boolean(parts[0]) && Boolean(parts[1]))
|
|
127
|
+
.map(([sha, refName]) => ({ sha, refName }));
|
|
128
|
+
deleteCommitRefs.run();
|
|
129
|
+
for (const { sha, refName } of refs) {
|
|
130
|
+
let refType = 'other';
|
|
131
|
+
if (refName.startsWith('refs/heads/')) {
|
|
132
|
+
refType = 'branch';
|
|
133
|
+
}
|
|
134
|
+
else if (refName.startsWith('refs/tags/')) {
|
|
135
|
+
refType = 'tag';
|
|
136
|
+
}
|
|
137
|
+
insertCommitRef.run(sha, refName, refType, sha);
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
if (latestShaInRun) {
|
|
141
|
+
setKbMeta(db, GIT_HISTORY_WATERMARK_KEY, latestShaInRun);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=git-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-history.js","sourceRoot":"","sources":["../../src/indexer/git-history.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAiB,MAAM,SAAS,CAAC;AAO9D,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,EAAqB,EACrB,QAAgB,EAChB,OAA2B;IAE3B,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,WAAW,CAAC;IACxC,MAAM,KAAK,GACT,OAAO,OAAO,EAAE,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC;QACvF,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK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BAAgB,CAAC,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;YACpC,IAAI,OAAO,GAAG,OAAO,CAAC;YACtB,IAAI,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBACtC,OAAO,GAAG,QAAQ,CAAC;YACrB,CAAC;iBAAM,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5C,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;YAED,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI,cAAc,EAAE,CAAC;QACnB,SAAS,CAAC,EAAE,EAAE,yBAAyB,EAAE,cAAc,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/git-hooks
|
|
3
|
+
*
|
|
4
|
+
* Utilities for installing Git hooks that keep a Lore index up to date.
|
|
5
|
+
*/
|
|
6
|
+
export interface InstallGitHooksOptions {
|
|
7
|
+
repoRoot: string;
|
|
8
|
+
rootDir: string;
|
|
9
|
+
dbPath: string;
|
|
10
|
+
includeHistory?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Install Lore-refresh git hooks in `.git/hooks` for common lifecycle events.
|
|
14
|
+
* Existing non-Lore hooks are preserved by prepending a Lore block.
|
|
15
|
+
*/
|
|
16
|
+
export declare function installGitHooks(options: InstallGitHooksOptions): {
|
|
17
|
+
installed: string[];
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=git-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-hooks.d.ts","sourceRoot":"","sources":["../../src/indexer/git-hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA4BD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CA4CxF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/git-hooks
|
|
3
|
+
*
|
|
4
|
+
* Utilities for installing Git hooks that keep a Lore index up to date.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
const HOOK_NAMES = ['post-commit', 'post-merge', 'post-checkout', 'post-rewrite'];
|
|
10
|
+
function shellEscapeSingle(value) {
|
|
11
|
+
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
12
|
+
}
|
|
13
|
+
function makeHookScript(rootDir, dbPath, includeHistory) {
|
|
14
|
+
const cmd = [
|
|
15
|
+
'npx',
|
|
16
|
+
'@jafreck/lore',
|
|
17
|
+
'refresh',
|
|
18
|
+
'--root',
|
|
19
|
+
shellEscapeSingle(rootDir),
|
|
20
|
+
'--db',
|
|
21
|
+
shellEscapeSingle(dbPath),
|
|
22
|
+
...(includeHistory ? ['--history'] : []),
|
|
23
|
+
].join(' ');
|
|
24
|
+
return [
|
|
25
|
+
'#!/usr/bin/env sh',
|
|
26
|
+
'set -e',
|
|
27
|
+
`${cmd} >/dev/null 2>&1 || true`,
|
|
28
|
+
'',
|
|
29
|
+
].join('\n');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Install Lore-refresh git hooks in `.git/hooks` for common lifecycle events.
|
|
33
|
+
* Existing non-Lore hooks are preserved by prepending a Lore block.
|
|
34
|
+
*/
|
|
35
|
+
export function installGitHooks(options) {
|
|
36
|
+
const repoRoot = options.repoRoot;
|
|
37
|
+
const hookDir = path.join(repoRoot, '.git', 'hooks');
|
|
38
|
+
if (!fs.existsSync(path.join(repoRoot, '.git'))) {
|
|
39
|
+
throw new Error(`Not a git repository: ${repoRoot}`);
|
|
40
|
+
}
|
|
41
|
+
fs.mkdirSync(hookDir, { recursive: true });
|
|
42
|
+
const loreBlock = [
|
|
43
|
+
'# --- lore auto-refresh (start) ---',
|
|
44
|
+
makeHookScript(options.rootDir, options.dbPath, options.includeHistory ?? false).trimEnd(),
|
|
45
|
+
'# --- lore auto-refresh (end) ---',
|
|
46
|
+
'',
|
|
47
|
+
].join('\n');
|
|
48
|
+
const installed = [];
|
|
49
|
+
for (const hookName of HOOK_NAMES) {
|
|
50
|
+
const hookPath = path.join(hookDir, hookName);
|
|
51
|
+
let existing = '';
|
|
52
|
+
if (fs.existsSync(hookPath)) {
|
|
53
|
+
existing = fs.readFileSync(hookPath, 'utf8');
|
|
54
|
+
existing = existing.replace(/# --- lore auto-refresh \(start\) ---[\s\S]*?# --- lore auto-refresh \(end\) ---\n?/g, '');
|
|
55
|
+
}
|
|
56
|
+
let content = '';
|
|
57
|
+
if (existing.trim().length > 0) {
|
|
58
|
+
content = `${existing.trimEnd()}\n\n${loreBlock}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
content = loreBlock;
|
|
62
|
+
}
|
|
63
|
+
fs.writeFileSync(hookPath, content, 'utf8');
|
|
64
|
+
try {
|
|
65
|
+
execFileSync('chmod', ['+x', hookPath]);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
fs.chmodSync(hookPath, 0o755);
|
|
69
|
+
}
|
|
70
|
+
installed.push(hookName);
|
|
71
|
+
}
|
|
72
|
+
return { installed };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=git-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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E,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexer/index
|
|
3
|
+
*
|
|
4
|
+
* The `IndexBuilder` class orchestrates the full indexing pipeline:
|
|
5
|
+
* walk → parse → extract → resolve → persist
|
|
6
|
+
*
|
|
7
|
+
* It also supports incremental updates (`update()`) and a stub for
|
|
8
|
+
* LLM-summary ingestion (`ingestSummary()`).
|
|
9
|
+
*/
|
|
10
|
+
import type { WalkerConfig } from './walker.js';
|
|
11
|
+
import type { EmbeddingProvider } from './embedder.js';
|
|
12
|
+
import { type CoverageFormat } from './coverage.js';
|
|
13
|
+
/**
|
|
14
|
+
* Orchestrates the full M1 indexing pipeline.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const builder = new IndexBuilder('/path/to/kb.db', { rootDir: '/path/to/src' });
|
|
19
|
+
* await builder.build();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class IndexBuilder {
|
|
23
|
+
private readonly dbPath;
|
|
24
|
+
private readonly walkerConfig;
|
|
25
|
+
private readonly pool;
|
|
26
|
+
private readonly resolver;
|
|
27
|
+
private readonly embedder;
|
|
28
|
+
private readonly history;
|
|
29
|
+
private readonly embeddingModel;
|
|
30
|
+
constructor(dbPath: string, walkerConfig: WalkerConfig, embedder?: EmbeddingProvider, embeddingModelOrOptions?: string | {
|
|
31
|
+
history?: boolean | {
|
|
32
|
+
depth?: number;
|
|
33
|
+
all?: boolean;
|
|
34
|
+
};
|
|
35
|
+
embeddingModel?: string;
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Performs a full build: walks all files, parses them, extracts
|
|
39
|
+
* symbols/imports/callRefs, resolves imports, and persists everything to
|
|
40
|
+
* the database.
|
|
41
|
+
*/
|
|
42
|
+
build(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Incrementally re-processes only the listed files and updates the DB.
|
|
45
|
+
* Symbols and imports for changed files are deleted then re-inserted.
|
|
46
|
+
*
|
|
47
|
+
* @param changedFiles Absolute paths of files that have changed.
|
|
48
|
+
*/
|
|
49
|
+
update(changedFiles: string[]): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Writes an LLM-generated summary for a symbol to `symbol_summaries`.
|
|
52
|
+
* If an `EmbeddingProvider` was configured, also embeds the summary text
|
|
53
|
+
* and persists it to `symbol_semantic_embeddings`.
|
|
54
|
+
*
|
|
55
|
+
* @param symbolId Row ID of the symbol in the `symbols` table.
|
|
56
|
+
* @param summary Natural-language summary text.
|
|
57
|
+
* @param model Name of the model that produced the summary.
|
|
58
|
+
*/
|
|
59
|
+
ingestSummary(symbolId: number, summary: string, model?: string): Promise<void>;
|
|
60
|
+
ingestCoverage(reportPath: string, format: CoverageFormat, commitSha?: string): Promise<void>;
|
|
61
|
+
/** Parse one file, extract symbols/imports/callRefs, and insert into the DB. */
|
|
62
|
+
private processFile;
|
|
63
|
+
/**
|
|
64
|
+
* Second pass: resolve raw_import strings to file IDs in the
|
|
65
|
+
* `file_imports.resolved_id` column. Also populates `external_deps` for
|
|
66
|
+
* any import that resolves to an external package.
|
|
67
|
+
*/
|
|
68
|
+
private resolveImports;
|
|
69
|
+
private resolveBranch;
|
|
70
|
+
private saveLastKnownHead;
|
|
71
|
+
private readGitValue;
|
|
72
|
+
private loadBuildCheckpoint;
|
|
73
|
+
private saveBuildCheckpoint;
|
|
74
|
+
/**
|
|
75
|
+
* Embed structural symbol signatures in batches and persist results to
|
|
76
|
+
* the `symbol_embeddings` vec0 virtual table.
|
|
77
|
+
*
|
|
78
|
+
* Also stores the embedding model name and dims in `kb_meta` and
|
|
79
|
+
* creates the vec0 tables if they don't exist yet.
|
|
80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