@saluzi/codegraph 0.1.0 → 0.2.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.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/package.json +42 -10
  4. package/scripts/add-lang/bench.sh +60 -0
  5. package/scripts/add-lang/check-grammar.mjs +75 -0
  6. package/scripts/add-lang/dump-ast.mjs +103 -0
  7. package/scripts/add-lang/verify-extraction.mjs +70 -0
  8. package/scripts/agent-eval/ab-adoption.sh +91 -0
  9. package/scripts/agent-eval/ab-hook.sh +86 -0
  10. package/scripts/agent-eval/ab-impl.sh +78 -0
  11. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  12. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  13. package/scripts/agent-eval/arms-F.sh +21 -0
  14. package/scripts/agent-eval/arms-matrix.sh +37 -0
  15. package/scripts/agent-eval/audit.sh +68 -0
  16. package/scripts/agent-eval/bench-readme.sh +28 -0
  17. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  18. package/scripts/agent-eval/block-read-hook.sh +19 -0
  19. package/scripts/agent-eval/hook-settings.json +15 -0
  20. package/scripts/agent-eval/itrun.sh +120 -0
  21. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  22. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  23. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  24. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  25. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  26. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  27. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  28. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  29. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  30. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  31. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  32. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  33. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  34. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  35. package/scripts/agent-eval/offload-eval.md +76 -0
  36. package/scripts/agent-eval/parse-arms.mjs +116 -0
  37. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  38. package/scripts/agent-eval/parse-run.mjs +45 -0
  39. package/scripts/agent-eval/parse-session.mjs +93 -0
  40. package/scripts/agent-eval/probe-context.mjs +21 -0
  41. package/scripts/agent-eval/probe-explore.mjs +40 -0
  42. package/scripts/agent-eval/probe-node.mjs +20 -0
  43. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  44. package/scripts/agent-eval/probe-trace.mjs +20 -0
  45. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  46. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  47. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  48. package/scripts/agent-eval/run-agent.sh +34 -0
  49. package/scripts/agent-eval/run-all.sh +75 -0
  50. package/scripts/agent-eval/run-arms.sh +56 -0
  51. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  52. package/scripts/build-bundle.sh +123 -0
  53. package/scripts/extract-release-notes.mjs +130 -0
  54. package/scripts/local-install.sh +41 -0
  55. package/scripts/npm-sdk.js +75 -0
  56. package/scripts/npm-shim.js +275 -0
  57. package/scripts/pack-npm.sh +119 -0
  58. package/scripts/prepare-release.mjs +270 -0
  59. package/dist/bin/codegraph.d.ts +0 -25
  60. package/dist/bin/node-version-check.d.ts +0 -37
  61. package/dist/bin/uninstall.d.ts +0 -14
  62. package/dist/context/formatter.d.ts +0 -33
  63. package/dist/context/formatter.js +0 -244
  64. package/dist/context/index.d.ts +0 -117
  65. package/dist/context/index.js +0 -1050
  66. package/dist/db/index.d.ts +0 -101
  67. package/dist/db/index.js +0 -250
  68. package/dist/db/migrations.d.ts +0 -47
  69. package/dist/db/migrations.js +0 -131
  70. package/dist/db/queries.d.ts +0 -291
  71. package/dist/db/queries.js +0 -1349
  72. package/dist/db/schema.sql +0 -151
  73. package/dist/db/sqlite-adapter.d.ts +0 -49
  74. package/dist/db/sqlite-adapter.js +0 -141
  75. package/dist/directory.d.ts +0 -62
  76. package/dist/directory.js +0 -264
  77. package/dist/errors.d.ts +0 -149
  78. package/dist/errors.js +0 -219
  79. package/dist/extraction/dfm-extractor.d.ts +0 -31
  80. package/dist/extraction/dfm-extractor.js +0 -151
  81. package/dist/extraction/grammars.d.ts +0 -94
  82. package/dist/extraction/grammars.js +0 -357
  83. package/dist/extraction/index.d.ts +0 -148
  84. package/dist/extraction/index.js +0 -1286
  85. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  86. package/dist/extraction/languages/c-cpp.js +0 -126
  87. package/dist/extraction/languages/csharp.d.ts +0 -3
  88. package/dist/extraction/languages/csharp.js +0 -72
  89. package/dist/extraction/languages/dart.d.ts +0 -3
  90. package/dist/extraction/languages/dart.js +0 -192
  91. package/dist/extraction/languages/go.d.ts +0 -3
  92. package/dist/extraction/languages/go.js +0 -58
  93. package/dist/extraction/languages/index.d.ts +0 -10
  94. package/dist/extraction/languages/index.js +0 -49
  95. package/dist/extraction/languages/java.d.ts +0 -3
  96. package/dist/extraction/languages/java.js +0 -64
  97. package/dist/extraction/languages/javascript.d.ts +0 -3
  98. package/dist/extraction/languages/javascript.js +0 -90
  99. package/dist/extraction/languages/kotlin.d.ts +0 -3
  100. package/dist/extraction/languages/kotlin.js +0 -253
  101. package/dist/extraction/languages/lua.d.ts +0 -3
  102. package/dist/extraction/languages/lua.js +0 -150
  103. package/dist/extraction/languages/luau.d.ts +0 -3
  104. package/dist/extraction/languages/luau.js +0 -37
  105. package/dist/extraction/languages/pascal.d.ts +0 -3
  106. package/dist/extraction/languages/pascal.js +0 -66
  107. package/dist/extraction/languages/php.d.ts +0 -3
  108. package/dist/extraction/languages/php.js +0 -107
  109. package/dist/extraction/languages/python.d.ts +0 -3
  110. package/dist/extraction/languages/python.js +0 -56
  111. package/dist/extraction/languages/ruby.d.ts +0 -3
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/rust.d.ts +0 -3
  114. package/dist/extraction/languages/rust.js +0 -109
  115. package/dist/extraction/languages/scala.d.ts +0 -3
  116. package/dist/extraction/languages/scala.js +0 -139
  117. package/dist/extraction/languages/swift.d.ts +0 -3
  118. package/dist/extraction/languages/swift.js +0 -91
  119. package/dist/extraction/languages/typescript.d.ts +0 -3
  120. package/dist/extraction/languages/typescript.js +0 -129
  121. package/dist/extraction/liquid-extractor.d.ts +0 -52
  122. package/dist/extraction/liquid-extractor.js +0 -313
  123. package/dist/extraction/parse-worker.d.ts +0 -8
  124. package/dist/extraction/parse-worker.js +0 -94
  125. package/dist/extraction/svelte-extractor.d.ts +0 -56
  126. package/dist/extraction/svelte-extractor.js +0 -272
  127. package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
  128. package/dist/extraction/tree-sitter-helpers.js +0 -103
  129. package/dist/extraction/tree-sitter-types.d.ts +0 -191
  130. package/dist/extraction/tree-sitter-types.js +0 -10
  131. package/dist/extraction/tree-sitter.d.ts +0 -238
  132. package/dist/extraction/tree-sitter.js +0 -2430
  133. package/dist/extraction/vue-extractor.d.ts +0 -36
  134. package/dist/extraction/vue-extractor.js +0 -163
  135. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  136. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  137. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  138. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  139. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  140. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  141. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  142. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  143. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  144. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  145. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  146. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  147. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  148. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  149. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  150. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  151. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  152. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  153. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  154. package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
  155. package/dist/extraction/wasm-runtime-flags.js +0 -105
  156. package/dist/graph/index.d.ts +0 -8
  157. package/dist/graph/index.js +0 -13
  158. package/dist/graph/queries.d.ts +0 -109
  159. package/dist/graph/queries.js +0 -366
  160. package/dist/graph/traversal.d.ts +0 -137
  161. package/dist/graph/traversal.js +0 -528
  162. package/dist/index.d.ts +0 -509
  163. package/dist/index.js +0 -800
  164. package/dist/installer/claude-md-template.d.ts +0 -19
  165. package/dist/installer/config-writer.d.ts +0 -29
  166. package/dist/installer/index.d.ts +0 -140
  167. package/dist/installer/instructions-template.d.ts +0 -30
  168. package/dist/installer/targets/claude.d.ts +0 -55
  169. package/dist/installer/targets/codex.d.ts +0 -18
  170. package/dist/installer/targets/cursor.d.ts +0 -35
  171. package/dist/installer/targets/hermes.d.ts +0 -18
  172. package/dist/installer/targets/opencode.d.ts +0 -30
  173. package/dist/installer/targets/registry.d.ts +0 -38
  174. package/dist/installer/targets/shared.d.ts +0 -92
  175. package/dist/installer/targets/toml.d.ts +0 -64
  176. package/dist/installer/targets/types.d.ts +0 -122
  177. package/dist/mcp/index.d.ts +0 -98
  178. package/dist/mcp/server-instructions.d.ts +0 -20
  179. package/dist/mcp/tools.d.ts +0 -269
  180. package/dist/mcp/transport.d.ts +0 -117
  181. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
  182. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  183. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  184. package/dist/resolution/frameworks/csharp.js +0 -213
  185. package/dist/resolution/frameworks/drupal.d.ts +0 -51
  186. package/dist/resolution/frameworks/drupal.js +0 -335
  187. package/dist/resolution/frameworks/express.d.ts +0 -8
  188. package/dist/resolution/frameworks/express.js +0 -225
  189. package/dist/resolution/frameworks/go.d.ts +0 -8
  190. package/dist/resolution/frameworks/go.js +0 -158
  191. package/dist/resolution/frameworks/index.d.ts +0 -52
  192. package/dist/resolution/frameworks/index.js +0 -137
  193. package/dist/resolution/frameworks/java.d.ts +0 -8
  194. package/dist/resolution/frameworks/java.js +0 -177
  195. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  196. package/dist/resolution/frameworks/laravel.js +0 -248
  197. package/dist/resolution/frameworks/nestjs.d.ts +0 -26
  198. package/dist/resolution/frameworks/nestjs.js +0 -374
  199. package/dist/resolution/frameworks/python.d.ts +0 -10
  200. package/dist/resolution/frameworks/python.js +0 -278
  201. package/dist/resolution/frameworks/react.d.ts +0 -8
  202. package/dist/resolution/frameworks/react.js +0 -272
  203. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  204. package/dist/resolution/frameworks/ruby.js +0 -198
  205. package/dist/resolution/frameworks/rust.d.ts +0 -8
  206. package/dist/resolution/frameworks/rust.js +0 -207
  207. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  208. package/dist/resolution/frameworks/svelte.js +0 -249
  209. package/dist/resolution/frameworks/swift.d.ts +0 -10
  210. package/dist/resolution/frameworks/swift.js +0 -376
  211. package/dist/resolution/frameworks/vue.d.ts +0 -9
  212. package/dist/resolution/frameworks/vue.js +0 -306
  213. package/dist/resolution/import-resolver.d.ts +0 -61
  214. package/dist/resolution/import-resolver.js +0 -663
  215. package/dist/resolution/index.d.ts +0 -118
  216. package/dist/resolution/index.js +0 -744
  217. package/dist/resolution/lru-cache.d.ts +0 -24
  218. package/dist/resolution/lru-cache.js +0 -62
  219. package/dist/resolution/name-matcher.d.ts +0 -50
  220. package/dist/resolution/name-matcher.js +0 -384
  221. package/dist/resolution/path-aliases.d.ts +0 -72
  222. package/dist/resolution/path-aliases.js +0 -238
  223. package/dist/resolution/strip-comments.d.ts +0 -40
  224. package/dist/resolution/strip-comments.js +0 -441
  225. package/dist/resolution/types.d.ts +0 -181
  226. package/dist/resolution/types.js +0 -8
  227. package/dist/search/query-parser.d.ts +0 -61
  228. package/dist/search/query-parser.js +0 -177
  229. package/dist/search/query-utils.d.ts +0 -59
  230. package/dist/search/query-utils.js +0 -383
  231. package/dist/sync/git-hooks.d.ts +0 -54
  232. package/dist/sync/git-hooks.js +0 -223
  233. package/dist/sync/index.d.ts +0 -25
  234. package/dist/sync/index.js +0 -28
  235. package/dist/sync/watch-policy.d.ts +0 -51
  236. package/dist/sync/watch-policy.js +0 -124
  237. package/dist/sync/watcher.d.ts +0 -83
  238. package/dist/sync/watcher.js +0 -192
  239. package/dist/types.d.ts +0 -433
  240. package/dist/types.js +0 -75
  241. package/dist/ui/glyphs.d.ts +0 -42
  242. package/dist/ui/shimmer-progress.d.ts +0 -11
  243. package/dist/ui/shimmer-worker.d.ts +0 -2
  244. package/dist/ui/types.d.ts +0 -20
  245. package/dist/utils.d.ts +0 -231
  246. package/dist/utils.js +0 -549
@@ -1,223 +0,0 @@
1
- "use strict";
2
- /**
3
- * Git Sync Hooks
4
- *
5
- * When the live file watcher is disabled (e.g. on WSL2 `/mnt/*` drives,
6
- * see watch-policy.ts), the CodeGraph index would otherwise go stale until
7
- * the user runs `codegraph sync` by hand. As an opt-in alternative, we can
8
- * install git hooks that refresh the index after the operations that change
9
- * files on disk: commit, merge (covers `git pull`), and checkout.
10
- *
11
- * The hooks run `codegraph sync` in the background so they never block git,
12
- * and are guarded by `command -v codegraph` so they no-op cleanly when the
13
- * CLI isn't on PATH. Our snippet is delimited by marker comments so install
14
- * is idempotent and removal preserves any user-authored hook content.
15
- */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || (function () {
33
- var ownKeys = function(o) {
34
- ownKeys = Object.getOwnPropertyNames || function (o) {
35
- var ar = [];
36
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
37
- return ar;
38
- };
39
- return ownKeys(o);
40
- };
41
- return function (mod) {
42
- if (mod && mod.__esModule) return mod;
43
- var result = {};
44
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
45
- __setModuleDefault(result, mod);
46
- return result;
47
- };
48
- })();
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.DEFAULT_SYNC_HOOKS = void 0;
51
- exports.isGitRepo = isGitRepo;
52
- exports.installGitSyncHook = installGitSyncHook;
53
- exports.removeGitSyncHook = removeGitSyncHook;
54
- exports.isSyncHookInstalled = isSyncHookInstalled;
55
- const fs = __importStar(require("fs"));
56
- const path = __importStar(require("path"));
57
- const child_process_1 = require("child_process");
58
- const MARKER_BEGIN = '# >>> codegraph sync hook >>>';
59
- const MARKER_END = '# <<< codegraph sync hook <<<';
60
- /** Hooks installed by default: commit, merge (git pull), and checkout. */
61
- exports.DEFAULT_SYNC_HOOKS = ['post-commit', 'post-merge', 'post-checkout'];
62
- /**
63
- * Whether `projectRoot` is inside a git working tree. Returns false if git
64
- * isn't installed or the path isn't a repo.
65
- */
66
- function isGitRepo(projectRoot) {
67
- try {
68
- const out = (0, child_process_1.execFileSync)('git', ['rev-parse', '--is-inside-work-tree'], {
69
- cwd: projectRoot,
70
- encoding: 'utf8',
71
- stdio: ['ignore', 'pipe', 'ignore'],
72
- }).trim();
73
- return out === 'true';
74
- }
75
- catch {
76
- return false;
77
- }
78
- }
79
- /**
80
- * Resolve the git hooks directory for a project, honoring `core.hooksPath`
81
- * and git worktrees. Returns an absolute path, or null when not a repo.
82
- */
83
- function gitHooksDir(projectRoot) {
84
- try {
85
- const out = (0, child_process_1.execFileSync)('git', ['rev-parse', '--git-path', 'hooks'], {
86
- cwd: projectRoot,
87
- encoding: 'utf8',
88
- stdio: ['ignore', 'pipe', 'ignore'],
89
- }).trim();
90
- if (!out)
91
- return null;
92
- return path.isAbsolute(out) ? out : path.resolve(projectRoot, out);
93
- }
94
- catch {
95
- return null;
96
- }
97
- }
98
- /** The shell snippet (between markers) injected into each hook. */
99
- function markerBlock() {
100
- return [
101
- MARKER_BEGIN,
102
- '# Keeps the CodeGraph index fresh while the live file watcher is off',
103
- '# (e.g. WSL2 /mnt drives). Runs in the background so it never blocks git.',
104
- '# Managed by codegraph; remove with `codegraph uninit` or delete this block.',
105
- 'if command -v codegraph >/dev/null 2>&1; then',
106
- ' ( codegraph sync >/dev/null 2>&1 & ) >/dev/null 2>&1',
107
- 'fi',
108
- MARKER_END,
109
- ].join('\n');
110
- }
111
- /** Remove our marker block (and the marker lines) from hook content. */
112
- function stripMarkerBlock(content) {
113
- const lines = content.split('\n');
114
- const kept = [];
115
- let inBlock = false;
116
- for (const line of lines) {
117
- const trimmed = line.trim();
118
- if (trimmed === MARKER_BEGIN) {
119
- inBlock = true;
120
- continue;
121
- }
122
- if (trimmed === MARKER_END) {
123
- inBlock = false;
124
- continue;
125
- }
126
- if (!inBlock)
127
- kept.push(line);
128
- }
129
- return kept.join('\n');
130
- }
131
- /** Whether a hook body is just a shebang / blank lines (i.e. only ever ours). */
132
- function isEffectivelyEmpty(content) {
133
- return content
134
- .split('\n')
135
- .map((l) => l.trim())
136
- .every((l) => l.length === 0 || l.startsWith('#!'));
137
- }
138
- function chmodExecutable(file) {
139
- try {
140
- fs.chmodSync(file, 0o755);
141
- }
142
- catch {
143
- /* chmod is a no-op / unsupported on some platforms (e.g. Windows) */
144
- }
145
- }
146
- /**
147
- * Install (or update) the CodeGraph sync hooks in a git repository.
148
- * Idempotent: re-running replaces our marker block rather than duplicating
149
- * it, and any user-authored hook content is preserved.
150
- */
151
- function installGitSyncHook(projectRoot, hooks = exports.DEFAULT_SYNC_HOOKS) {
152
- const hooksDir = gitHooksDir(projectRoot);
153
- if (!hooksDir) {
154
- return { installed: [], hooksDir: null, skipped: 'not a git repository' };
155
- }
156
- try {
157
- fs.mkdirSync(hooksDir, { recursive: true });
158
- }
159
- catch {
160
- return { installed: [], hooksDir, skipped: 'could not access the git hooks directory' };
161
- }
162
- const block = markerBlock();
163
- const installed = [];
164
- for (const hook of hooks) {
165
- const file = path.join(hooksDir, hook);
166
- let content;
167
- if (fs.existsSync(file)) {
168
- // Strip any prior block, then re-append the current one.
169
- const base = stripMarkerBlock(fs.readFileSync(file, 'utf8')).replace(/\s*$/, '');
170
- content = base.length > 0
171
- ? `${base}\n\n${block}\n`
172
- : `#!/bin/sh\n${block}\n`;
173
- }
174
- else {
175
- content = `#!/bin/sh\n${block}\n`;
176
- }
177
- fs.writeFileSync(file, content);
178
- chmodExecutable(file);
179
- installed.push(hook);
180
- }
181
- return { installed, hooksDir };
182
- }
183
- /**
184
- * Remove the CodeGraph sync hooks. Strips only our marker block; deletes the
185
- * hook file entirely when nothing but a shebang remains, otherwise rewrites
186
- * the user's content untouched.
187
- */
188
- function removeGitSyncHook(projectRoot, hooks = exports.DEFAULT_SYNC_HOOKS) {
189
- const hooksDir = gitHooksDir(projectRoot);
190
- if (!hooksDir) {
191
- return { installed: [], hooksDir: null, skipped: 'not a git repository' };
192
- }
193
- const removed = [];
194
- for (const hook of hooks) {
195
- const file = path.join(hooksDir, hook);
196
- if (!fs.existsSync(file))
197
- continue;
198
- const original = fs.readFileSync(file, 'utf8');
199
- if (!original.includes(MARKER_BEGIN))
200
- continue;
201
- const stripped = stripMarkerBlock(original);
202
- if (isEffectivelyEmpty(stripped)) {
203
- fs.unlinkSync(file);
204
- }
205
- else {
206
- fs.writeFileSync(file, `${stripped.replace(/\s*$/, '')}\n`);
207
- chmodExecutable(file);
208
- }
209
- removed.push(hook);
210
- }
211
- return { installed: removed, hooksDir };
212
- }
213
- /** Whether any CodeGraph sync hook is currently installed. */
214
- function isSyncHookInstalled(projectRoot, hooks = exports.DEFAULT_SYNC_HOOKS) {
215
- const hooksDir = gitHooksDir(projectRoot);
216
- if (!hooksDir)
217
- return false;
218
- return hooks.some((hook) => {
219
- const file = path.join(hooksDir, hook);
220
- return fs.existsSync(file) && fs.readFileSync(file, 'utf8').includes(MARKER_BEGIN);
221
- });
222
- }
223
- //# sourceMappingURL=git-hooks.js.map
@@ -1,25 +0,0 @@
1
- /**
2
- * Sync Module
3
- *
4
- * Provides synchronization functionality for keeping the code graph
5
- * up-to-date with file system changes.
6
- *
7
- * Components:
8
- * - FileWatcher: Debounced fs.watch that auto-triggers sync on file changes
9
- * - Watch policy: decides when the watcher must be disabled (e.g. WSL2 /mnt)
10
- * - Git sync hooks: opt-in commit/merge/checkout hooks when watching is off
11
- * - Content hashing for change detection (in extraction module)
12
- * - Incremental reindexing (in extraction module)
13
- */
14
- export { FileWatcher, WatchOptions } from './watcher'
15
- export { watchDisabledReason, detectWsl } from './watch-policy'
16
- export {
17
- installGitSyncHook,
18
- removeGitSyncHook,
19
- isSyncHookInstalled,
20
- isGitRepo,
21
- DEFAULT_SYNC_HOOKS,
22
- type GitHookName,
23
- type GitHookResult,
24
- } from './git-hooks'
25
- //# sourceMappingURL=index.d.ts.map
@@ -1,28 +0,0 @@
1
- "use strict";
2
- /**
3
- * Sync Module
4
- *
5
- * Provides synchronization functionality for keeping the code graph
6
- * up-to-date with file system changes.
7
- *
8
- * Components:
9
- * - FileWatcher: Debounced fs.watch that auto-triggers sync on file changes
10
- * - Watch policy: decides when the watcher must be disabled (e.g. WSL2 /mnt)
11
- * - Git sync hooks: opt-in commit/merge/checkout hooks when watching is off
12
- * - Content hashing for change detection (in extraction module)
13
- * - Incremental reindexing (in extraction module)
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.DEFAULT_SYNC_HOOKS = exports.isGitRepo = exports.isSyncHookInstalled = exports.removeGitSyncHook = exports.installGitSyncHook = exports.detectWsl = exports.watchDisabledReason = exports.FileWatcher = void 0;
17
- var watcher_1 = require("./watcher");
18
- Object.defineProperty(exports, "FileWatcher", { enumerable: true, get: function () { return watcher_1.FileWatcher; } });
19
- var watch_policy_1 = require("./watch-policy");
20
- Object.defineProperty(exports, "watchDisabledReason", { enumerable: true, get: function () { return watch_policy_1.watchDisabledReason; } });
21
- Object.defineProperty(exports, "detectWsl", { enumerable: true, get: function () { return watch_policy_1.detectWsl; } });
22
- var git_hooks_1 = require("./git-hooks");
23
- Object.defineProperty(exports, "installGitSyncHook", { enumerable: true, get: function () { return git_hooks_1.installGitSyncHook; } });
24
- Object.defineProperty(exports, "removeGitSyncHook", { enumerable: true, get: function () { return git_hooks_1.removeGitSyncHook; } });
25
- Object.defineProperty(exports, "isSyncHookInstalled", { enumerable: true, get: function () { return git_hooks_1.isSyncHookInstalled; } });
26
- Object.defineProperty(exports, "isGitRepo", { enumerable: true, get: function () { return git_hooks_1.isGitRepo; } });
27
- Object.defineProperty(exports, "DEFAULT_SYNC_HOOKS", { enumerable: true, get: function () { return git_hooks_1.DEFAULT_SYNC_HOOKS; } });
28
- //# sourceMappingURL=index.js.map
@@ -1,51 +0,0 @@
1
- /**
2
- * Watch Policy
3
- *
4
- * Decides whether the live file watcher should run for a given project.
5
- *
6
- * Native recursive `fs.watch` is pathologically slow on WSL2 `/mnt/*`
7
- * drives (NTFS exposed over the 9p/drvfs bridge): setting up the recursive
8
- * watch walks the directory tree, and every readdir/stat crosses the
9
- * Windows boundary. Inside an MCP server this stalls the event loop during
10
- * startup long enough to blow past host handshake timeouts (opencode's 30s),
11
- * so the tools never appear. See issue #199.
12
- *
13
- * This module centralizes the on/off decision so the watcher, the MCP
14
- * server (for diagnostics), and the installer all agree.
15
- */
16
- /**
17
- * Detect whether the current process is running under WSL (Windows
18
- * Subsystem for Linux). Result is cached after the first call.
19
- *
20
- * Checks the WSL-specific env vars first (no I/O), then falls back to
21
- * `/proc/version`, which contains "microsoft" on WSL kernels.
22
- */
23
- export declare function detectWsl(): boolean
24
- /**
25
- * Inputs that can be overridden in tests so the decision is deterministic
26
- * without touching real env vars or `/proc/version`.
27
- */
28
- export interface WatchProbe {
29
- /** Defaults to `process.env`. */
30
- env?: NodeJS.ProcessEnv
31
- /** Defaults to `detectWsl()`. */
32
- isWsl?: boolean
33
- }
34
- /**
35
- * Decide whether the file watcher should be disabled for a project, and why.
36
- *
37
- * Returns a short human-readable reason when watching should be skipped, or
38
- * `null` when it should run normally.
39
- *
40
- * Precedence (first match wins):
41
- * 1. `CODEGRAPH_NO_WATCH=1` → off (explicit opt-out always wins)
42
- * 2. `CODEGRAPH_FORCE_WATCH=1` → on (overrides auto-detection)
43
- * 3. WSL2 + `/mnt/*` drive → off (recursive fs.watch is too slow; #199)
44
- */
45
- export declare function watchDisabledReason(
46
- projectRoot: string,
47
- probe?: WatchProbe,
48
- ): string | null
49
- /** Test-only: reset the cached WSL detection. */
50
- export declare function __resetWslCacheForTests(): void
51
- //# sourceMappingURL=watch-policy.d.ts.map
@@ -1,124 +0,0 @@
1
- "use strict";
2
- /**
3
- * Watch Policy
4
- *
5
- * Decides whether the live file watcher should run for a given project.
6
- *
7
- * Native recursive `fs.watch` is pathologically slow on WSL2 `/mnt/*`
8
- * drives (NTFS exposed over the 9p/drvfs bridge): setting up the recursive
9
- * watch walks the directory tree, and every readdir/stat crosses the
10
- * Windows boundary. Inside an MCP server this stalls the event loop during
11
- * startup long enough to blow past host handshake timeouts (opencode's 30s),
12
- * so the tools never appear. See issue #199.
13
- *
14
- * This module centralizes the on/off decision so the watcher, the MCP
15
- * server (for diagnostics), and the installer all agree.
16
- */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.detectWsl = detectWsl;
52
- exports.watchDisabledReason = watchDisabledReason;
53
- exports.__resetWslCacheForTests = __resetWslCacheForTests;
54
- const fs = __importStar(require("fs"));
55
- const utils_1 = require("../utils");
56
- let wslChecked = false;
57
- let wslValue = false;
58
- /**
59
- * Detect whether the current process is running under WSL (Windows
60
- * Subsystem for Linux). Result is cached after the first call.
61
- *
62
- * Checks the WSL-specific env vars first (no I/O), then falls back to
63
- * `/proc/version`, which contains "microsoft" on WSL kernels.
64
- */
65
- function detectWsl() {
66
- if (wslChecked)
67
- return wslValue;
68
- wslChecked = true;
69
- if (process.platform !== 'linux') {
70
- wslValue = false;
71
- return wslValue;
72
- }
73
- if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) {
74
- wslValue = true;
75
- return wslValue;
76
- }
77
- try {
78
- const version = fs.readFileSync('/proc/version', 'utf8').toLowerCase();
79
- wslValue = version.includes('microsoft') || version.includes('wsl');
80
- }
81
- catch {
82
- wslValue = false;
83
- }
84
- return wslValue;
85
- }
86
- /**
87
- * True for WSL Windows-drive mounts like `/mnt/c` or `/mnt/d/project`.
88
- * Deliberately matches only single-letter drive mounts, so genuinely fast
89
- * Linux mounts such as `/mnt/wsl/...` are not flagged.
90
- */
91
- function isWindowsDriveMount(projectRoot) {
92
- return /^\/mnt\/[a-z](\/|$)/i.test((0, utils_1.normalizePath)(projectRoot));
93
- }
94
- /**
95
- * Decide whether the file watcher should be disabled for a project, and why.
96
- *
97
- * Returns a short human-readable reason when watching should be skipped, or
98
- * `null` when it should run normally.
99
- *
100
- * Precedence (first match wins):
101
- * 1. `CODEGRAPH_NO_WATCH=1` → off (explicit opt-out always wins)
102
- * 2. `CODEGRAPH_FORCE_WATCH=1` → on (overrides auto-detection)
103
- * 3. WSL2 + `/mnt/*` drive → off (recursive fs.watch is too slow; #199)
104
- */
105
- function watchDisabledReason(projectRoot, probe = {}) {
106
- const env = probe.env ?? process.env;
107
- if (env.CODEGRAPH_NO_WATCH === '1') {
108
- return 'CODEGRAPH_NO_WATCH=1 is set';
109
- }
110
- if (env.CODEGRAPH_FORCE_WATCH === '1') {
111
- return null;
112
- }
113
- const isWsl = probe.isWsl ?? detectWsl();
114
- if (isWsl && isWindowsDriveMount(projectRoot)) {
115
- return 'project is on a WSL2 /mnt/ drive, where recursive fs.watch is too slow to be reliable';
116
- }
117
- return null;
118
- }
119
- /** Test-only: reset the cached WSL detection. */
120
- function __resetWslCacheForTests() {
121
- wslChecked = false;
122
- wslValue = false;
123
- }
124
- //# sourceMappingURL=watch-policy.js.map
@@ -1,83 +0,0 @@
1
- /**
2
- * File Watcher
3
- *
4
- * Watches the project directory for file changes and triggers
5
- * debounced sync operations to keep the code graph up-to-date.
6
- *
7
- * Uses Node.js native fs.watch with recursive mode (macOS FSEvents,
8
- * Windows ReadDirectoryChangesW, Linux inotify on Node 19+).
9
- */
10
- /**
11
- * Options for the file watcher
12
- */
13
- export interface WatchOptions {
14
- /**
15
- * Debounce delay in milliseconds.
16
- * After the last file change, wait this long before triggering sync.
17
- * Default: 2000ms
18
- */
19
- debounceMs?: number
20
- /**
21
- * Callback when a sync completes (for logging/diagnostics).
22
- */
23
- onSyncComplete?: (result: {
24
- filesChanged: number
25
- durationMs: number
26
- }) => void
27
- /**
28
- * Callback when a sync errors (for logging/diagnostics).
29
- */
30
- onSyncError?: (error: Error) => void
31
- }
32
- /**
33
- * FileWatcher monitors a project directory for changes and triggers
34
- * debounced sync operations via a provided callback.
35
- *
36
- * Design goals:
37
- * - Minimal resource usage (native OS file events, no polling)
38
- * - Debounced to avoid thrashing on rapid saves
39
- * - Filters to supported source files by extension
40
- * - Ignores .codegraph/ directory changes
41
- */
42
- export declare class FileWatcher {
43
- private watcher
44
- private debounceTimer
45
- private hasChanges
46
- private syncing
47
- private stopped
48
- private readonly projectRoot
49
- private readonly debounceMs
50
- private readonly syncFn
51
- private readonly onSyncComplete?
52
- private readonly onSyncError?
53
- constructor(
54
- projectRoot: string,
55
- syncFn: () => Promise<{
56
- filesChanged: number
57
- durationMs: number
58
- }>,
59
- options?: WatchOptions,
60
- )
61
- /**
62
- * Start watching for file changes.
63
- * Returns true if watching started successfully, false otherwise.
64
- */
65
- start(): boolean
66
- /**
67
- * Stop watching for file changes.
68
- */
69
- stop(): void
70
- /**
71
- * Whether the watcher is currently active.
72
- */
73
- isActive(): boolean
74
- /**
75
- * Schedule a debounced sync.
76
- */
77
- private scheduleSync
78
- /**
79
- * Flush pending changes by running sync.
80
- */
81
- private flush
82
- }
83
- //# sourceMappingURL=watcher.d.ts.map