flavor-code 1.2.13 → 1.2.14

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.
Files changed (131) hide show
  1. package/README.md +3 -0
  2. package/README.zh-CN.md +3 -0
  3. package/dist/{app-Z3YWFIBB.js → app-UJAGMKD5.js} +2 -2
  4. package/dist/astgraph/db.mjs +237 -237
  5. package/dist/astgraph/extract.mjs +239 -239
  6. package/dist/astgraph/flavor-plugin.json +25 -25
  7. package/dist/astgraph/grammars.mjs +68 -68
  8. package/dist/astgraph/index.js +301 -301
  9. package/dist/astgraph/indexer.mjs +175 -175
  10. package/dist/astgraph/query.mjs +165 -165
  11. package/dist/astgraph/resolve.mjs +93 -93
  12. package/dist/astgraph/vendor/tree-sitter.js +3980 -3980
  13. package/dist/astgraph/vendor/zod/LICENSE +21 -21
  14. package/dist/astgraph/vendor/zod/index.js +4 -4
  15. package/dist/astgraph/vendor/zod/locales/index.js +1 -1
  16. package/dist/astgraph/vendor/zod/locales/package.json +7 -7
  17. package/dist/astgraph/vendor/zod/package.json +135 -135
  18. package/dist/astgraph/vendor/zod/v4/classic/checks.js +1 -1
  19. package/dist/astgraph/vendor/zod/v4/classic/coerce.js +17 -17
  20. package/dist/astgraph/vendor/zod/v4/classic/compat.js +31 -31
  21. package/dist/astgraph/vendor/zod/v4/classic/errors.js +48 -48
  22. package/dist/astgraph/vendor/zod/v4/classic/external.js +20 -20
  23. package/dist/astgraph/vendor/zod/v4/classic/from-json-schema.js +599 -599
  24. package/dist/astgraph/vendor/zod/v4/classic/index.js +4 -4
  25. package/dist/astgraph/vendor/zod/v4/classic/iso.js +30 -30
  26. package/dist/astgraph/vendor/zod/v4/classic/package.json +7 -7
  27. package/dist/astgraph/vendor/zod/v4/classic/parse.js +15 -15
  28. package/dist/astgraph/vendor/zod/v4/classic/schemas.js +1395 -1395
  29. package/dist/astgraph/vendor/zod/v4/core/api.js +1087 -1087
  30. package/dist/astgraph/vendor/zod/v4/core/checks.js +575 -575
  31. package/dist/astgraph/vendor/zod/v4/core/core.js +78 -78
  32. package/dist/astgraph/vendor/zod/v4/core/doc.js +35 -35
  33. package/dist/astgraph/vendor/zod/v4/core/errors.js +185 -185
  34. package/dist/astgraph/vendor/zod/v4/core/index.js +16 -16
  35. package/dist/astgraph/vendor/zod/v4/core/json-schema-generator.js +95 -95
  36. package/dist/astgraph/vendor/zod/v4/core/json-schema-processors.js +601 -601
  37. package/dist/astgraph/vendor/zod/v4/core/json-schema.js +1 -1
  38. package/dist/astgraph/vendor/zod/v4/core/package.json +7 -7
  39. package/dist/astgraph/vendor/zod/v4/core/parse.js +93 -93
  40. package/dist/astgraph/vendor/zod/v4/core/regexes.js +139 -139
  41. package/dist/astgraph/vendor/zod/v4/core/registries.js +51 -51
  42. package/dist/astgraph/vendor/zod/v4/core/schemas.js +2239 -2239
  43. package/dist/astgraph/vendor/zod/v4/core/standard-schema.js +1 -1
  44. package/dist/astgraph/vendor/zod/v4/core/to-json-schema.js +448 -448
  45. package/dist/astgraph/vendor/zod/v4/core/util.js +674 -674
  46. package/dist/astgraph/vendor/zod/v4/core/versions.js +5 -5
  47. package/dist/astgraph/vendor/zod/v4/index.js +3 -3
  48. package/dist/astgraph/vendor/zod/v4/locales/ar.js +106 -106
  49. package/dist/astgraph/vendor/zod/v4/locales/az.js +105 -105
  50. package/dist/astgraph/vendor/zod/v4/locales/be.js +156 -156
  51. package/dist/astgraph/vendor/zod/v4/locales/bg.js +120 -120
  52. package/dist/astgraph/vendor/zod/v4/locales/ca.js +107 -107
  53. package/dist/astgraph/vendor/zod/v4/locales/cs.js +111 -111
  54. package/dist/astgraph/vendor/zod/v4/locales/da.js +115 -115
  55. package/dist/astgraph/vendor/zod/v4/locales/de.js +108 -108
  56. package/dist/astgraph/vendor/zod/v4/locales/el.js +109 -109
  57. package/dist/astgraph/vendor/zod/v4/locales/en.js +113 -113
  58. package/dist/astgraph/vendor/zod/v4/locales/eo.js +109 -109
  59. package/dist/astgraph/vendor/zod/v4/locales/es.js +132 -132
  60. package/dist/astgraph/vendor/zod/v4/locales/fa.js +114 -114
  61. package/dist/astgraph/vendor/zod/v4/locales/fi.js +112 -112
  62. package/dist/astgraph/vendor/zod/v4/locales/fr-CA.js +107 -107
  63. package/dist/astgraph/vendor/zod/v4/locales/fr.js +125 -125
  64. package/dist/astgraph/vendor/zod/v4/locales/he.js +214 -214
  65. package/dist/astgraph/vendor/zod/v4/locales/hr.js +122 -122
  66. package/dist/astgraph/vendor/zod/v4/locales/hu.js +108 -108
  67. package/dist/astgraph/vendor/zod/v4/locales/hy.js +147 -147
  68. package/dist/astgraph/vendor/zod/v4/locales/id.js +106 -106
  69. package/dist/astgraph/vendor/zod/v4/locales/index.js +52 -52
  70. package/dist/astgraph/vendor/zod/v4/locales/is.js +109 -109
  71. package/dist/astgraph/vendor/zod/v4/locales/it.js +108 -108
  72. package/dist/astgraph/vendor/zod/v4/locales/ja.js +107 -107
  73. package/dist/astgraph/vendor/zod/v4/locales/ka.js +112 -112
  74. package/dist/astgraph/vendor/zod/v4/locales/kh.js +5 -5
  75. package/dist/astgraph/vendor/zod/v4/locales/km.js +110 -110
  76. package/dist/astgraph/vendor/zod/v4/locales/ko.js +111 -111
  77. package/dist/astgraph/vendor/zod/v4/locales/lt.js +203 -203
  78. package/dist/astgraph/vendor/zod/v4/locales/mk.js +109 -109
  79. package/dist/astgraph/vendor/zod/v4/locales/ms.js +107 -107
  80. package/dist/astgraph/vendor/zod/v4/locales/nl.js +110 -110
  81. package/dist/astgraph/vendor/zod/v4/locales/no.js +108 -108
  82. package/dist/astgraph/vendor/zod/v4/locales/ota.js +109 -109
  83. package/dist/astgraph/vendor/zod/v4/locales/package.json +7 -7
  84. package/dist/astgraph/vendor/zod/v4/locales/pl.js +109 -109
  85. package/dist/astgraph/vendor/zod/v4/locales/ps.js +114 -114
  86. package/dist/astgraph/vendor/zod/v4/locales/pt.js +108 -108
  87. package/dist/astgraph/vendor/zod/v4/locales/ro.js +119 -119
  88. package/dist/astgraph/vendor/zod/v4/locales/ru.js +156 -156
  89. package/dist/astgraph/vendor/zod/v4/locales/sl.js +109 -109
  90. package/dist/astgraph/vendor/zod/v4/locales/sv.js +110 -110
  91. package/dist/astgraph/vendor/zod/v4/locales/ta.js +110 -110
  92. package/dist/astgraph/vendor/zod/v4/locales/th.js +110 -110
  93. package/dist/astgraph/vendor/zod/v4/locales/tr.js +105 -105
  94. package/dist/astgraph/vendor/zod/v4/locales/ua.js +5 -5
  95. package/dist/astgraph/vendor/zod/v4/locales/uk.js +108 -108
  96. package/dist/astgraph/vendor/zod/v4/locales/ur.js +110 -110
  97. package/dist/astgraph/vendor/zod/v4/locales/uz.js +110 -110
  98. package/dist/astgraph/vendor/zod/v4/locales/vi.js +108 -108
  99. package/dist/astgraph/vendor/zod/v4/locales/yo.js +107 -107
  100. package/dist/astgraph/vendor/zod/v4/locales/zh-CN.js +109 -109
  101. package/dist/astgraph/vendor/zod/v4/locales/zh-TW.js +107 -107
  102. package/dist/astgraph/vendor/zod/v4/mini/checks.js +1 -1
  103. package/dist/astgraph/vendor/zod/v4/mini/coerce.js +22 -22
  104. package/dist/astgraph/vendor/zod/v4/mini/external.js +14 -14
  105. package/dist/astgraph/vendor/zod/v4/mini/index.js +3 -3
  106. package/dist/astgraph/vendor/zod/v4/mini/iso.js +34 -34
  107. package/dist/astgraph/vendor/zod/v4/mini/package.json +7 -7
  108. package/dist/astgraph/vendor/zod/v4/mini/parse.js +1 -1
  109. package/dist/astgraph/vendor/zod/v4/mini/schemas.js +961 -961
  110. package/dist/astgraph/vendor/zod/v4/package.json +7 -7
  111. package/dist/{chunk-Y5MZDG7I.js → chunk-4YXDGGIC.js} +4611 -3754
  112. package/dist/{chunk-XFCJXRJ2.js → chunk-IG4Z23CL.js} +6 -0
  113. package/dist/{chunk-G6Q2Y2A7.js → chunk-KL6TR2KG.js} +1 -1
  114. package/dist/cli.js +5 -5
  115. package/dist/config/schema.d.ts +6 -0
  116. package/dist/desktop/main.js +4900 -4038
  117. package/dist/desktop-renderer/assets/{index-CCnSpff0.js → index-CcD0D6x0.js} +1 -1
  118. package/dist/desktop-renderer/index.html +1 -1
  119. package/dist/evolve/loader.d.ts +21 -0
  120. package/dist/evolve/service.d.ts +37 -0
  121. package/dist/evolve/store.d.ts +91 -0
  122. package/dist/hooks/types.d.ts +5 -1
  123. package/dist/{load-6ZMEBHSG.js → load-GKA7P6RJ.js} +1 -1
  124. package/dist/plugins/host.d.ts +9 -0
  125. package/dist/plugins/types.d.ts +1 -0
  126. package/dist/sdk/index.js +3 -3
  127. package/dist/tools/shell.d.ts +13 -0
  128. package/dist/ui/commands.d.ts +5 -2
  129. package/dist/ui/session.d.ts +1 -0
  130. package/package.json +1 -1
  131. package//346/212/200/346/234/257/346/226/271/346/241/210/346/212/245/345/221/212.md +303 -1
@@ -1,175 +1,175 @@
1
- // astgraph indexer — full and incremental project indexing.
2
- // Walks the workspace, extracts symbols per file (content-hash incremental),
3
- // then resolves cross-file references into graph edges.
4
-
5
- import { createHash } from "node:crypto";
6
- import { readdirSync, readFileSync, statSync } from "node:fs";
7
- import { relative, sep } from "node:path";
8
-
9
- import {
10
- deleteEdgesForFile,
11
- deleteFileRecord,
12
- deleteUnresolvedRefsForFile,
13
- getFileRecord,
14
- insertEdge,
15
- insertUnresolvedRef,
16
- replaceNodes,
17
- setMetadata,
18
- upsertFileRecord,
19
- } from "./db.mjs";
20
- import { extract } from "./extract.mjs";
21
- import { languageForFile, SUPPORTED_LANGUAGES } from "./grammars.mjs";
22
- import { resolveImportPath, resolveRefs } from "./resolve.mjs";
23
-
24
- /** Directory names never indexed, regardless of depth. */
25
- const EXCLUDED_DIRS = new Set([
26
- "node_modules", "dist", "build", "out", "coverage", "release", ".git",
27
- ".flavor", ".claude", ".worktrees", ".cache", ".idea", ".vscode", "vendor",
28
- ]);
29
-
30
- function toPosix(path) {
31
- return path.split(sep).join("/");
32
- }
33
-
34
- /** Walk the workspace and return code files as workspace-relative posix paths. */
35
- export function listCodeFiles(workspace) {
36
- const files = [];
37
- const walk = (dir) => {
38
- let entries;
39
- try { entries = readdirSync(dir, { withFileTypes: true }); }
40
- catch { return; }
41
- for (const entry of entries) {
42
- const full = `${dir}/${entry.name}`;
43
- if (entry.isDirectory()) {
44
- if (!EXCLUDED_DIRS.has(entry.name)) walk(full);
45
- } else if (entry.isFile() && languageForFile(entry.name) !== undefined) {
46
- files.push(toPosix(relative(workspace, full)));
47
- }
48
- }
49
- };
50
- walk(workspace);
51
- return files.sort();
52
- }
53
-
54
- /** SHA-256 content hash used for incremental detection. */
55
- export function contentHash(content) {
56
- return createHash("sha256").update(content).digest("hex");
57
- }
58
-
59
- async function indexOneFile(db, workspace, relativePath) {
60
- const content = readFileSync(`${workspace}/${relativePath}`, "utf8");
61
- const language = languageForFile(relativePath);
62
- const { nodes, edges, refs } = await extract(content, relativePath, language);
63
-
64
- deleteEdgesForFile(db, relativePath);
65
- deleteUnresolvedRefsForFile(db, relativePath);
66
- replaceNodes(db, relativePath, nodes);
67
- for (const edge of edges) insertEdge(db, edge);
68
- for (const ref of refs) {
69
- insertUnresolvedRef(db, {
70
- fromNodeId: ref.fromNodeId, referenceName: ref.referenceName,
71
- referenceKind: ref.referenceKind, line: ref.line, col: ref.col,
72
- filePath: ref.filePath, moduleSpecifier: ref.moduleSpecifier,
73
- });
74
- }
75
- let size;
76
- try { size = statSync(`${workspace}/${relativePath}`).size; } catch { size = content.length; }
77
- upsertFileRecord(db, {
78
- path: relativePath, contentHash: contentHash(content), language, size, nodeCount: nodes.length,
79
- });
80
- return { nodeCount: nodes.length };
81
- }
82
-
83
- /** Resolve every pending unresolved_ref whose module specifier points at an indexed file. */
84
- function resolvePass(db, workspace) {
85
- const rows = db.prepare(`
86
- SELECT id, from_node_id, reference_name, reference_kind, line, col, file_path, module_specifier
87
- FROM unresolved_refs WHERE status = 'pending' AND module_specifier IS NOT NULL
88
- `).all();
89
- if (rows.length === 0) return 0;
90
-
91
- const nodesByFile = new Map();
92
- for (const file of db.prepare("SELECT DISTINCT file_path FROM nodes").all()) {
93
- nodesByFile.set(file.file_path, db.prepare(
94
- "SELECT id, name, is_exported FROM nodes WHERE file_path = ?",
95
- ).all(file.file_path).map((row) => ({ id: row.id, name: row.name, isExported: row.is_exported === 1 })));
96
- }
97
- const exists = (path) => {
98
- try { statSync(`${workspace}/${path}`); return true; } catch { return false; }
99
- };
100
-
101
- const refs = rows.map((row) => ({
102
- id: row.id, fromNodeId: row.from_node_id, referenceName: row.reference_name,
103
- referenceKind: row.reference_kind, line: row.line, col: row.col,
104
- filePath: row.file_path, moduleSpecifier: row.module_specifier,
105
- }));
106
- // Import statements live outside any function, so their refs carry no from-node.
107
- // Attribute them to a node that actually uses the binding (same file + name);
108
- // unused imports resolve silently without an edge.
109
- for (const ref of refs) {
110
- if (ref.fromNodeId !== null || ref.referenceKind !== "import") continue;
111
- const user = refs.find((other) => other.referenceKind !== "import"
112
- && other.referenceName === ref.referenceName
113
- && other.filePath === ref.filePath
114
- && other.fromNodeId !== null);
115
- ref.fromNodeId = user?.fromNodeId ?? null;
116
- }
117
- const { edges, resolvedIds } = resolveRefs(refs.filter((ref) => ref.fromNodeId !== null), nodesByFile, exists);
118
- for (const edge of edges) insertEdge(db, edge);
119
- if (resolvedIds.length > 0) {
120
- db.exec("BEGIN");
121
- try {
122
- const mark = db.prepare("DELETE FROM unresolved_refs WHERE id = ?");
123
- for (const id of resolvedIds) mark.run(id);
124
- db.exec("COMMIT");
125
- } catch (error) { db.exec("ROLLBACK"); throw error; }
126
- }
127
- return resolvedIds.length;
128
- }
129
-
130
- /**
131
- * Index (or re-index) a workspace into the graph database.
132
- *
133
- * Options:
134
- * onlyPaths — restrict the pass to these workspace-relative paths (hook-driven sync).
135
- * Disappeared files are still pruned; everything else is left untouched.
136
- * Returns { files, indexed, skipped, removed, resolved }.
137
- */
138
- export async function indexProject(workspace, { db, onlyPaths } = {}) {
139
- const restrict = onlyPaths === undefined ? undefined : new Set(onlyPaths.map(toPosix));
140
- const diskFiles = listCodeFiles(workspace).filter((path) => restrict === undefined || restrict.has(path));
141
-
142
- let indexed = 0;
143
- let skipped = 0;
144
- for (const path of diskFiles) {
145
- const current = readFileSync(`${workspace}/${path}`, "utf8");
146
- const hash = contentHash(current);
147
- const record = getFileRecord(db, path);
148
- if (record !== undefined && record.contentHash === hash) { skipped += 1; continue; }
149
- await indexOneFile(db, workspace, path);
150
- indexed += 1;
151
- }
152
-
153
- // Prune files that no longer exist on disk.
154
- let removed = 0;
155
- const known = db.prepare("SELECT path FROM files").all();
156
- const diskSet = new Set(diskFiles);
157
- for (const row of known) {
158
- if (restrict !== undefined && !restrict.has(row.path)) continue;
159
- if (!diskSet.has(row.path)) {
160
- deleteEdgesForFile(db, row.path);
161
- deleteUnresolvedRefsForFile(db, row.path);
162
- replaceNodes(db, row.path, []);
163
- deleteFileRecord(db, row.path);
164
- removed += 1;
165
- }
166
- }
167
-
168
- const resolved = resolvePass(db, workspace);
169
- setMetadata(db, "last_index", JSON.stringify({ at: Date.now(), files: diskFiles.length, indexed, removed }));
170
-
171
- return { files: diskFiles.length, indexed, skipped, removed, resolved };
172
- }
173
-
174
- /** Exposed for diagnostics. */
175
- export const INDEXER_LANGUAGES = SUPPORTED_LANGUAGES;
1
+ // astgraph indexer — full and incremental project indexing.
2
+ // Walks the workspace, extracts symbols per file (content-hash incremental),
3
+ // then resolves cross-file references into graph edges.
4
+
5
+ import { createHash } from "node:crypto";
6
+ import { readdirSync, readFileSync, statSync } from "node:fs";
7
+ import { relative, sep } from "node:path";
8
+
9
+ import {
10
+ deleteEdgesForFile,
11
+ deleteFileRecord,
12
+ deleteUnresolvedRefsForFile,
13
+ getFileRecord,
14
+ insertEdge,
15
+ insertUnresolvedRef,
16
+ replaceNodes,
17
+ setMetadata,
18
+ upsertFileRecord,
19
+ } from "./db.mjs";
20
+ import { extract } from "./extract.mjs";
21
+ import { languageForFile, SUPPORTED_LANGUAGES } from "./grammars.mjs";
22
+ import { resolveImportPath, resolveRefs } from "./resolve.mjs";
23
+
24
+ /** Directory names never indexed, regardless of depth. */
25
+ const EXCLUDED_DIRS = new Set([
26
+ "node_modules", "dist", "build", "out", "coverage", "release", ".git",
27
+ ".flavor", ".claude", ".worktrees", ".cache", ".idea", ".vscode", "vendor",
28
+ ]);
29
+
30
+ function toPosix(path) {
31
+ return path.split(sep).join("/");
32
+ }
33
+
34
+ /** Walk the workspace and return code files as workspace-relative posix paths. */
35
+ export function listCodeFiles(workspace) {
36
+ const files = [];
37
+ const walk = (dir) => {
38
+ let entries;
39
+ try { entries = readdirSync(dir, { withFileTypes: true }); }
40
+ catch { return; }
41
+ for (const entry of entries) {
42
+ const full = `${dir}/${entry.name}`;
43
+ if (entry.isDirectory()) {
44
+ if (!EXCLUDED_DIRS.has(entry.name)) walk(full);
45
+ } else if (entry.isFile() && languageForFile(entry.name) !== undefined) {
46
+ files.push(toPosix(relative(workspace, full)));
47
+ }
48
+ }
49
+ };
50
+ walk(workspace);
51
+ return files.sort();
52
+ }
53
+
54
+ /** SHA-256 content hash used for incremental detection. */
55
+ export function contentHash(content) {
56
+ return createHash("sha256").update(content).digest("hex");
57
+ }
58
+
59
+ async function indexOneFile(db, workspace, relativePath) {
60
+ const content = readFileSync(`${workspace}/${relativePath}`, "utf8");
61
+ const language = languageForFile(relativePath);
62
+ const { nodes, edges, refs } = await extract(content, relativePath, language);
63
+
64
+ deleteEdgesForFile(db, relativePath);
65
+ deleteUnresolvedRefsForFile(db, relativePath);
66
+ replaceNodes(db, relativePath, nodes);
67
+ for (const edge of edges) insertEdge(db, edge);
68
+ for (const ref of refs) {
69
+ insertUnresolvedRef(db, {
70
+ fromNodeId: ref.fromNodeId, referenceName: ref.referenceName,
71
+ referenceKind: ref.referenceKind, line: ref.line, col: ref.col,
72
+ filePath: ref.filePath, moduleSpecifier: ref.moduleSpecifier,
73
+ });
74
+ }
75
+ let size;
76
+ try { size = statSync(`${workspace}/${relativePath}`).size; } catch { size = content.length; }
77
+ upsertFileRecord(db, {
78
+ path: relativePath, contentHash: contentHash(content), language, size, nodeCount: nodes.length,
79
+ });
80
+ return { nodeCount: nodes.length };
81
+ }
82
+
83
+ /** Resolve every pending unresolved_ref whose module specifier points at an indexed file. */
84
+ function resolvePass(db, workspace) {
85
+ const rows = db.prepare(`
86
+ SELECT id, from_node_id, reference_name, reference_kind, line, col, file_path, module_specifier
87
+ FROM unresolved_refs WHERE status = 'pending' AND module_specifier IS NOT NULL
88
+ `).all();
89
+ if (rows.length === 0) return 0;
90
+
91
+ const nodesByFile = new Map();
92
+ for (const file of db.prepare("SELECT DISTINCT file_path FROM nodes").all()) {
93
+ nodesByFile.set(file.file_path, db.prepare(
94
+ "SELECT id, name, is_exported FROM nodes WHERE file_path = ?",
95
+ ).all(file.file_path).map((row) => ({ id: row.id, name: row.name, isExported: row.is_exported === 1 })));
96
+ }
97
+ const exists = (path) => {
98
+ try { statSync(`${workspace}/${path}`); return true; } catch { return false; }
99
+ };
100
+
101
+ const refs = rows.map((row) => ({
102
+ id: row.id, fromNodeId: row.from_node_id, referenceName: row.reference_name,
103
+ referenceKind: row.reference_kind, line: row.line, col: row.col,
104
+ filePath: row.file_path, moduleSpecifier: row.module_specifier,
105
+ }));
106
+ // Import statements live outside any function, so their refs carry no from-node.
107
+ // Attribute them to a node that actually uses the binding (same file + name);
108
+ // unused imports resolve silently without an edge.
109
+ for (const ref of refs) {
110
+ if (ref.fromNodeId !== null || ref.referenceKind !== "import") continue;
111
+ const user = refs.find((other) => other.referenceKind !== "import"
112
+ && other.referenceName === ref.referenceName
113
+ && other.filePath === ref.filePath
114
+ && other.fromNodeId !== null);
115
+ ref.fromNodeId = user?.fromNodeId ?? null;
116
+ }
117
+ const { edges, resolvedIds } = resolveRefs(refs.filter((ref) => ref.fromNodeId !== null), nodesByFile, exists);
118
+ for (const edge of edges) insertEdge(db, edge);
119
+ if (resolvedIds.length > 0) {
120
+ db.exec("BEGIN");
121
+ try {
122
+ const mark = db.prepare("DELETE FROM unresolved_refs WHERE id = ?");
123
+ for (const id of resolvedIds) mark.run(id);
124
+ db.exec("COMMIT");
125
+ } catch (error) { db.exec("ROLLBACK"); throw error; }
126
+ }
127
+ return resolvedIds.length;
128
+ }
129
+
130
+ /**
131
+ * Index (or re-index) a workspace into the graph database.
132
+ *
133
+ * Options:
134
+ * onlyPaths — restrict the pass to these workspace-relative paths (hook-driven sync).
135
+ * Disappeared files are still pruned; everything else is left untouched.
136
+ * Returns { files, indexed, skipped, removed, resolved }.
137
+ */
138
+ export async function indexProject(workspace, { db, onlyPaths } = {}) {
139
+ const restrict = onlyPaths === undefined ? undefined : new Set(onlyPaths.map(toPosix));
140
+ const diskFiles = listCodeFiles(workspace).filter((path) => restrict === undefined || restrict.has(path));
141
+
142
+ let indexed = 0;
143
+ let skipped = 0;
144
+ for (const path of diskFiles) {
145
+ const current = readFileSync(`${workspace}/${path}`, "utf8");
146
+ const hash = contentHash(current);
147
+ const record = getFileRecord(db, path);
148
+ if (record !== undefined && record.contentHash === hash) { skipped += 1; continue; }
149
+ await indexOneFile(db, workspace, path);
150
+ indexed += 1;
151
+ }
152
+
153
+ // Prune files that no longer exist on disk.
154
+ let removed = 0;
155
+ const known = db.prepare("SELECT path FROM files").all();
156
+ const diskSet = new Set(diskFiles);
157
+ for (const row of known) {
158
+ if (restrict !== undefined && !restrict.has(row.path)) continue;
159
+ if (!diskSet.has(row.path)) {
160
+ deleteEdgesForFile(db, row.path);
161
+ deleteUnresolvedRefsForFile(db, row.path);
162
+ replaceNodes(db, row.path, []);
163
+ deleteFileRecord(db, row.path);
164
+ removed += 1;
165
+ }
166
+ }
167
+
168
+ const resolved = resolvePass(db, workspace);
169
+ setMetadata(db, "last_index", JSON.stringify({ at: Date.now(), files: diskFiles.length, indexed, removed }));
170
+
171
+ return { files: diskFiles.length, indexed, skipped, removed, resolved };
172
+ }
173
+
174
+ /** Exposed for diagnostics. */
175
+ export const INDEXER_LANGUAGES = SUPPORTED_LANGUAGES;