@saluzi/codegraph 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.
Files changed (189) hide show
  1. package/dist/bin/codegraph.d.ts +25 -0
  2. package/dist/bin/node-version-check.d.ts +37 -0
  3. package/dist/bin/uninstall.d.ts +14 -0
  4. package/dist/context/formatter.d.ts +33 -0
  5. package/dist/context/formatter.js +244 -0
  6. package/dist/context/index.d.ts +117 -0
  7. package/dist/context/index.js +1050 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/index.js +250 -0
  10. package/dist/db/migrations.d.ts +47 -0
  11. package/dist/db/migrations.js +131 -0
  12. package/dist/db/queries.d.ts +291 -0
  13. package/dist/db/queries.js +1349 -0
  14. package/dist/db/schema.sql +151 -0
  15. package/dist/db/sqlite-adapter.d.ts +49 -0
  16. package/dist/db/sqlite-adapter.js +141 -0
  17. package/dist/directory.d.ts +62 -0
  18. package/dist/directory.js +264 -0
  19. package/dist/errors.d.ts +149 -0
  20. package/dist/errors.js +219 -0
  21. package/dist/extraction/dfm-extractor.d.ts +31 -0
  22. package/dist/extraction/dfm-extractor.js +151 -0
  23. package/dist/extraction/grammars.d.ts +94 -0
  24. package/dist/extraction/grammars.js +357 -0
  25. package/dist/extraction/index.d.ts +148 -0
  26. package/dist/extraction/index.js +1286 -0
  27. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  28. package/dist/extraction/languages/c-cpp.js +126 -0
  29. package/dist/extraction/languages/csharp.d.ts +3 -0
  30. package/dist/extraction/languages/csharp.js +72 -0
  31. package/dist/extraction/languages/dart.d.ts +3 -0
  32. package/dist/extraction/languages/dart.js +192 -0
  33. package/dist/extraction/languages/go.d.ts +3 -0
  34. package/dist/extraction/languages/go.js +58 -0
  35. package/dist/extraction/languages/index.d.ts +10 -0
  36. package/dist/extraction/languages/index.js +49 -0
  37. package/dist/extraction/languages/java.d.ts +3 -0
  38. package/dist/extraction/languages/java.js +64 -0
  39. package/dist/extraction/languages/javascript.d.ts +3 -0
  40. package/dist/extraction/languages/javascript.js +90 -0
  41. package/dist/extraction/languages/kotlin.d.ts +3 -0
  42. package/dist/extraction/languages/kotlin.js +253 -0
  43. package/dist/extraction/languages/lua.d.ts +3 -0
  44. package/dist/extraction/languages/lua.js +150 -0
  45. package/dist/extraction/languages/luau.d.ts +3 -0
  46. package/dist/extraction/languages/luau.js +37 -0
  47. package/dist/extraction/languages/pascal.d.ts +3 -0
  48. package/dist/extraction/languages/pascal.js +66 -0
  49. package/dist/extraction/languages/php.d.ts +3 -0
  50. package/dist/extraction/languages/php.js +107 -0
  51. package/dist/extraction/languages/python.d.ts +3 -0
  52. package/dist/extraction/languages/python.js +56 -0
  53. package/dist/extraction/languages/ruby.d.ts +3 -0
  54. package/dist/extraction/languages/ruby.js +114 -0
  55. package/dist/extraction/languages/rust.d.ts +3 -0
  56. package/dist/extraction/languages/rust.js +109 -0
  57. package/dist/extraction/languages/scala.d.ts +3 -0
  58. package/dist/extraction/languages/scala.js +139 -0
  59. package/dist/extraction/languages/swift.d.ts +3 -0
  60. package/dist/extraction/languages/swift.js +91 -0
  61. package/dist/extraction/languages/typescript.d.ts +3 -0
  62. package/dist/extraction/languages/typescript.js +129 -0
  63. package/dist/extraction/liquid-extractor.d.ts +52 -0
  64. package/dist/extraction/liquid-extractor.js +313 -0
  65. package/dist/extraction/parse-worker.d.ts +8 -0
  66. package/dist/extraction/parse-worker.js +94 -0
  67. package/dist/extraction/svelte-extractor.d.ts +56 -0
  68. package/dist/extraction/svelte-extractor.js +272 -0
  69. package/dist/extraction/tree-sitter-helpers.d.ts +39 -0
  70. package/dist/extraction/tree-sitter-helpers.js +103 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +191 -0
  72. package/dist/extraction/tree-sitter-types.js +10 -0
  73. package/dist/extraction/tree-sitter.d.ts +238 -0
  74. package/dist/extraction/tree-sitter.js +2430 -0
  75. package/dist/extraction/vue-extractor.d.ts +36 -0
  76. package/dist/extraction/vue-extractor.js +163 -0
  77. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  79. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  80. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  81. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  82. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  83. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  84. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  85. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  86. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  87. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  88. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  89. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  90. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  91. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  92. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  93. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  94. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  95. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  96. package/dist/extraction/wasm-runtime-flags.d.ts +46 -0
  97. package/dist/extraction/wasm-runtime-flags.js +105 -0
  98. package/dist/graph/index.d.ts +8 -0
  99. package/dist/graph/index.js +13 -0
  100. package/dist/graph/queries.d.ts +109 -0
  101. package/dist/graph/queries.js +366 -0
  102. package/dist/graph/traversal.d.ts +137 -0
  103. package/dist/graph/traversal.js +528 -0
  104. package/dist/index.d.ts +509 -0
  105. package/dist/index.js +800 -0
  106. package/dist/installer/claude-md-template.d.ts +19 -0
  107. package/dist/installer/config-writer.d.ts +29 -0
  108. package/dist/installer/index.d.ts +140 -0
  109. package/dist/installer/instructions-template.d.ts +30 -0
  110. package/dist/installer/targets/claude.d.ts +55 -0
  111. package/dist/installer/targets/codex.d.ts +18 -0
  112. package/dist/installer/targets/cursor.d.ts +35 -0
  113. package/dist/installer/targets/hermes.d.ts +18 -0
  114. package/dist/installer/targets/opencode.d.ts +30 -0
  115. package/dist/installer/targets/registry.d.ts +38 -0
  116. package/dist/installer/targets/shared.d.ts +92 -0
  117. package/dist/installer/targets/toml.d.ts +64 -0
  118. package/dist/installer/targets/types.d.ts +122 -0
  119. package/dist/mcp/index.d.ts +98 -0
  120. package/dist/mcp/server-instructions.d.ts +20 -0
  121. package/dist/mcp/tools.d.ts +269 -0
  122. package/dist/mcp/transport.d.ts +117 -0
  123. package/dist/resolution/frameworks/cargo-workspace.d.ts +20 -0
  124. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  125. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  126. package/dist/resolution/frameworks/csharp.js +213 -0
  127. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  128. package/dist/resolution/frameworks/drupal.js +335 -0
  129. package/dist/resolution/frameworks/express.d.ts +8 -0
  130. package/dist/resolution/frameworks/express.js +225 -0
  131. package/dist/resolution/frameworks/go.d.ts +8 -0
  132. package/dist/resolution/frameworks/go.js +158 -0
  133. package/dist/resolution/frameworks/index.d.ts +52 -0
  134. package/dist/resolution/frameworks/index.js +137 -0
  135. package/dist/resolution/frameworks/java.d.ts +8 -0
  136. package/dist/resolution/frameworks/java.js +177 -0
  137. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  138. package/dist/resolution/frameworks/laravel.js +248 -0
  139. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  140. package/dist/resolution/frameworks/nestjs.js +374 -0
  141. package/dist/resolution/frameworks/python.d.ts +10 -0
  142. package/dist/resolution/frameworks/python.js +278 -0
  143. package/dist/resolution/frameworks/react.d.ts +8 -0
  144. package/dist/resolution/frameworks/react.js +272 -0
  145. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  146. package/dist/resolution/frameworks/ruby.js +198 -0
  147. package/dist/resolution/frameworks/rust.d.ts +8 -0
  148. package/dist/resolution/frameworks/rust.js +207 -0
  149. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  150. package/dist/resolution/frameworks/svelte.js +249 -0
  151. package/dist/resolution/frameworks/swift.d.ts +10 -0
  152. package/dist/resolution/frameworks/swift.js +376 -0
  153. package/dist/resolution/frameworks/vue.d.ts +9 -0
  154. package/dist/resolution/frameworks/vue.js +306 -0
  155. package/dist/resolution/import-resolver.d.ts +61 -0
  156. package/dist/resolution/import-resolver.js +663 -0
  157. package/dist/resolution/index.d.ts +118 -0
  158. package/dist/resolution/index.js +744 -0
  159. package/dist/resolution/lru-cache.d.ts +24 -0
  160. package/dist/resolution/lru-cache.js +62 -0
  161. package/dist/resolution/name-matcher.d.ts +50 -0
  162. package/dist/resolution/name-matcher.js +384 -0
  163. package/dist/resolution/path-aliases.d.ts +72 -0
  164. package/dist/resolution/path-aliases.js +238 -0
  165. package/dist/resolution/strip-comments.d.ts +40 -0
  166. package/dist/resolution/strip-comments.js +441 -0
  167. package/dist/resolution/types.d.ts +181 -0
  168. package/dist/resolution/types.js +8 -0
  169. package/dist/search/query-parser.d.ts +61 -0
  170. package/dist/search/query-parser.js +177 -0
  171. package/dist/search/query-utils.d.ts +59 -0
  172. package/dist/search/query-utils.js +383 -0
  173. package/dist/sync/git-hooks.d.ts +54 -0
  174. package/dist/sync/git-hooks.js +223 -0
  175. package/dist/sync/index.d.ts +25 -0
  176. package/dist/sync/index.js +28 -0
  177. package/dist/sync/watch-policy.d.ts +51 -0
  178. package/dist/sync/watch-policy.js +124 -0
  179. package/dist/sync/watcher.d.ts +83 -0
  180. package/dist/sync/watcher.js +192 -0
  181. package/dist/types.d.ts +433 -0
  182. package/dist/types.js +75 -0
  183. package/dist/ui/glyphs.d.ts +42 -0
  184. package/dist/ui/shimmer-progress.d.ts +11 -0
  185. package/dist/ui/shimmer-worker.d.ts +2 -0
  186. package/dist/ui/types.d.ts +20 -0
  187. package/dist/utils.d.ts +231 -0
  188. package/dist/utils.js +549 -0
  189. package/package.json +24 -0
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CodeGraph CLI
4
+ *
5
+ * Command-line interface for CodeGraph code intelligence.
6
+ *
7
+ * Usage:
8
+ * codegraph Run interactive installer (when no args)
9
+ * codegraph install Run interactive installer
10
+ * codegraph uninstall Remove CodeGraph from your agents
11
+ * codegraph init [path] Initialize CodeGraph in a project
12
+ * codegraph uninit [path] Remove CodeGraph from a project
13
+ * codegraph index [path] Index all files in the project
14
+ * codegraph sync [path] Sync changes since last index
15
+ * codegraph status [path] Show index status
16
+ * codegraph query <search> Search for symbols
17
+ * codegraph files [options] Show project file structure
18
+ * codegraph context <task> Build context for a task
19
+ * codegraph callers <symbol> Find what calls a function/method
20
+ * codegraph callees <symbol> Find what a function/method calls
21
+ * codegraph impact <symbol> Analyze what code is affected by changing a symbol
22
+ * codegraph affected [files] Find test files affected by changes
23
+ */
24
+ export {};
25
+ //# sourceMappingURL=codegraph.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Node.js version compatibility check.
3
+ *
4
+ * Node 25.x has a V8 turboshaft WASM JIT Zone allocator bug that
5
+ * reliably crashes CodeGraph with `Fatal process out of memory: Zone`
6
+ * during tree-sitter grammar compilation. This module owns the
7
+ * user-facing banner shown before exit. Kept side-effect-free so it's
8
+ * safe to import from tests without triggering CLI bootstrap.
9
+ */
10
+ /**
11
+ * Build the bordered banner shown when CodeGraph detects an
12
+ * unsupported Node.js major version (currently 25+). Pinned via unit
13
+ * test so the recovery commands and override instructions can't be
14
+ * silently stripped by future edits.
15
+ *
16
+ * Uses ASCII glyphs to stay readable on Windows OEM-codepage consoles
17
+ * (see ../ui/glyphs.ts for the rationale).
18
+ */
19
+ export declare function buildNode25BlockBanner(nodeVersion: string): string;
20
+ /**
21
+ * Lowest supported Node.js major version. Matches the `engines` floor in
22
+ * package.json. Below this, CodeGraph relies on language features / native APIs
23
+ * that aren't present, and the combination is untested. `engines` alone only
24
+ * *warns* on install (unless the user set `engine-strict`), so the CLI bootstrap
25
+ * also hard-blocks here to actually enforce the floor.
26
+ */
27
+ export declare const MIN_NODE_MAJOR = 20;
28
+ /**
29
+ * Build the bordered banner shown when CodeGraph detects a Node.js major below
30
+ * {@link MIN_NODE_MAJOR}. Pinned via unit test so the recovery commands and the
31
+ * override env var can't be silently stripped by future edits.
32
+ *
33
+ * Uses ASCII glyphs to stay readable on Windows OEM-codepage consoles
34
+ * (see ../ui/glyphs.ts for the rationale).
35
+ */
36
+ export declare function buildNodeTooOldBanner(nodeVersion: string): string;
37
+ //# sourceMappingURL=node-version-check.d.ts.map
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CodeGraph preuninstall cleanup script
4
+ *
5
+ * Runs automatically when `npm uninstall -g @colbymchenry/codegraph`
6
+ * is called. Loops over every known agent target's `uninstall(loc)`
7
+ * for the global location only — local-location entries live inside
8
+ * project working trees and aren't ours to nuke at npm-uninstall
9
+ * time.
10
+ *
11
+ * This script must never throw — a failed cleanup must not block
12
+ * uninstall.
13
+ */
14
+ //# sourceMappingURL=uninstall.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Context Formatter
3
+ *
4
+ * Formats TaskContext as markdown or JSON for consumption by Claude.
5
+ */
6
+ import { Node, TaskContext, Subgraph } from '../types'
7
+ /**
8
+ * Format context as markdown
9
+ *
10
+ * Creates a compact markdown document optimized for Claude with minimal context usage:
11
+ * - Brief summary
12
+ * - Entry points with locations
13
+ * - Code blocks only for key symbols
14
+ */
15
+ export declare function formatContextAsMarkdown(context: TaskContext): string
16
+ /**
17
+ * Format context as JSON
18
+ *
19
+ * Returns a structured JSON representation suitable for programmatic use.
20
+ */
21
+ export declare function formatContextAsJson(context: TaskContext): string
22
+ /**
23
+ * Format a subgraph as an ASCII tree structure
24
+ */
25
+ export declare function formatSubgraphTree(
26
+ subgraph: Subgraph,
27
+ entryPoints: Node[],
28
+ ): string
29
+ /**
30
+ * Format bytes as human-readable string
31
+ */
32
+ export declare function formatBytes(bytes: number): string
33
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ /**
3
+ * Context Formatter
4
+ *
5
+ * Formats TaskContext as markdown or JSON for consumption by Claude.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.formatContextAsMarkdown = formatContextAsMarkdown;
9
+ exports.formatContextAsJson = formatContextAsJson;
10
+ exports.formatSubgraphTree = formatSubgraphTree;
11
+ exports.formatBytes = formatBytes;
12
+ /**
13
+ * Format context as markdown
14
+ *
15
+ * Creates a compact markdown document optimized for Claude with minimal context usage:
16
+ * - Brief summary
17
+ * - Entry points with locations
18
+ * - Code blocks only for key symbols
19
+ */
20
+ function formatContextAsMarkdown(context) {
21
+ const lines = [];
22
+ // Header with query
23
+ lines.push('## Code Context\n');
24
+ lines.push(`**Query:** ${context.query}\n`);
25
+ // Entry points - compact format
26
+ if (context.entryPoints.length > 0) {
27
+ lines.push('### Entry Points\n');
28
+ for (const node of context.entryPoints) {
29
+ const location = node.startLine ? `:${node.startLine}` : '';
30
+ lines.push(`- **${node.name}** (${node.kind}) - ${node.filePath}${location}`);
31
+ if (node.signature) {
32
+ lines.push(` \`${node.signature}\``);
33
+ }
34
+ }
35
+ lines.push('');
36
+ }
37
+ // Related symbols - compact list (skip verbose structure tree)
38
+ const otherSymbols = Array.from(context.subgraph.nodes.values())
39
+ .filter(n => !context.entryPoints.some(e => e.id === n.id))
40
+ .slice(0, 10); // Limit to 10 related symbols
41
+ if (otherSymbols.length > 0) {
42
+ lines.push('### Related Symbols\n');
43
+ const byFile = new Map();
44
+ for (const node of otherSymbols) {
45
+ const existing = byFile.get(node.filePath) || [];
46
+ existing.push(node);
47
+ byFile.set(node.filePath, existing);
48
+ }
49
+ for (const [file, nodes] of byFile) {
50
+ const nodeList = nodes.map(n => `${n.name}:${n.startLine}`).join(', ');
51
+ lines.push(`- ${file}: ${nodeList}`);
52
+ }
53
+ lines.push('');
54
+ }
55
+ // Code blocks - only for key entry points
56
+ if (context.codeBlocks.length > 0) {
57
+ lines.push('### Code\n');
58
+ for (const block of context.codeBlocks) {
59
+ const nodeName = block.node?.name ?? 'Unknown';
60
+ lines.push(`#### ${nodeName} (${block.filePath}:${block.startLine})\n`);
61
+ lines.push('```' + block.language);
62
+ lines.push(block.content);
63
+ lines.push('```\n');
64
+ }
65
+ }
66
+ return lines.join('\n');
67
+ }
68
+ /**
69
+ * Format context as JSON
70
+ *
71
+ * Returns a structured JSON representation suitable for programmatic use.
72
+ */
73
+ function formatContextAsJson(context) {
74
+ // Convert Map to array for JSON serialization
75
+ const serializable = {
76
+ query: context.query,
77
+ summary: context.summary,
78
+ entryPoints: context.entryPoints.map(serializeNode),
79
+ nodes: Array.from(context.subgraph.nodes.values()).map(serializeNode),
80
+ edges: context.subgraph.edges.map(serializeEdge),
81
+ codeBlocks: context.codeBlocks.map((block) => ({
82
+ filePath: block.filePath,
83
+ startLine: block.startLine,
84
+ endLine: block.endLine,
85
+ language: block.language,
86
+ content: block.content,
87
+ nodeName: block.node?.name,
88
+ nodeKind: block.node?.kind,
89
+ })),
90
+ relatedFiles: context.relatedFiles,
91
+ stats: context.stats,
92
+ };
93
+ return JSON.stringify(serializable, null, 2);
94
+ }
95
+ /**
96
+ * Format a subgraph as an ASCII tree structure
97
+ */
98
+ function formatSubgraphTree(subgraph, entryPoints) {
99
+ const lines = [];
100
+ const printed = new Set();
101
+ // Build adjacency list for outgoing edges
102
+ const outgoing = new Map();
103
+ for (const edge of subgraph.edges) {
104
+ const existing = outgoing.get(edge.source) ?? [];
105
+ existing.push(edge);
106
+ outgoing.set(edge.source, existing);
107
+ }
108
+ // Print each entry point as a tree root
109
+ for (const entry of entryPoints) {
110
+ formatNodeTree(entry, subgraph, outgoing, printed, lines, 0, '');
111
+ lines.push(''); // Blank line between trees
112
+ }
113
+ // Print any remaining nodes not reached from entry points
114
+ const remaining = [];
115
+ for (const node of subgraph.nodes.values()) {
116
+ if (!printed.has(node.id)) {
117
+ remaining.push(node);
118
+ }
119
+ }
120
+ if (remaining.length > 0 && remaining.length <= 10) {
121
+ lines.push('Other relevant symbols:');
122
+ for (const node of remaining) {
123
+ const location = node.startLine ? `:${node.startLine}` : '';
124
+ lines.push(` ${node.kind}: ${node.name} (${node.filePath}${location})`);
125
+ }
126
+ }
127
+ else if (remaining.length > 10) {
128
+ lines.push(`... and ${remaining.length} more related symbols`);
129
+ }
130
+ return lines.join('\n').trim();
131
+ }
132
+ /**
133
+ * Format a single node and its relationships
134
+ */
135
+ function formatNodeTree(node, subgraph, outgoing, printed, lines, depth, prefix) {
136
+ if (printed.has(node.id)) {
137
+ return;
138
+ }
139
+ printed.add(node.id);
140
+ // Node header
141
+ const location = node.startLine ? `:${node.startLine}` : '';
142
+ const signature = node.signature ? ` - ${truncate(node.signature, 50)}` : '';
143
+ lines.push(`${prefix}${node.kind}: ${node.name} (${node.filePath}${location})${signature}`);
144
+ // Outgoing edges
145
+ const edges = outgoing.get(node.id) ?? [];
146
+ const significantEdges = edges.filter((e) => ['calls', 'extends', 'implements', 'imports', 'references'].includes(e.kind));
147
+ // Group by kind
148
+ const edgesByKind = new Map();
149
+ for (const edge of significantEdges) {
150
+ const existing = edgesByKind.get(edge.kind) ?? [];
151
+ existing.push(edge);
152
+ edgesByKind.set(edge.kind, existing);
153
+ }
154
+ // Print edges grouped by kind
155
+ const newPrefix = prefix + ' ';
156
+ for (const [kind, kindEdges] of edgesByKind) {
157
+ if (kindEdges.length > 3) {
158
+ // Summarize if too many
159
+ const names = kindEdges
160
+ .slice(0, 3)
161
+ .map((e) => {
162
+ const target = subgraph.nodes.get(e.target);
163
+ return target?.name ?? 'unknown';
164
+ })
165
+ .join(', ');
166
+ lines.push(`${newPrefix}├── ${kind}: ${names} and ${kindEdges.length - 3} more`);
167
+ }
168
+ else {
169
+ for (let i = 0; i < kindEdges.length; i++) {
170
+ const edge = kindEdges[i];
171
+ const target = subgraph.nodes.get(edge.target);
172
+ const targetName = target?.name ?? 'unknown';
173
+ const connector = i === kindEdges.length - 1 ? '└──' : '├──';
174
+ lines.push(`${newPrefix}${connector} ${kind} → ${targetName}`);
175
+ }
176
+ }
177
+ }
178
+ // Recurse for directly connected nodes (limited depth)
179
+ if (depth < 1) {
180
+ for (const edge of significantEdges.slice(0, 3)) {
181
+ const target = subgraph.nodes.get(edge.target);
182
+ if (target && !printed.has(target.id)) {
183
+ formatNodeTree(target, subgraph, outgoing, printed, lines, depth + 1, newPrefix);
184
+ }
185
+ }
186
+ }
187
+ }
188
+ /**
189
+ * Serialize a node for JSON output
190
+ */
191
+ function serializeNode(node) {
192
+ return {
193
+ id: node.id,
194
+ kind: node.kind,
195
+ name: node.name,
196
+ qualifiedName: node.qualifiedName,
197
+ filePath: node.filePath,
198
+ language: node.language,
199
+ startLine: node.startLine,
200
+ endLine: node.endLine,
201
+ signature: node.signature,
202
+ docstring: node.docstring,
203
+ visibility: node.visibility,
204
+ isExported: node.isExported,
205
+ isAsync: node.isAsync,
206
+ isStatic: node.isStatic,
207
+ };
208
+ }
209
+ /**
210
+ * Serialize an edge for JSON output
211
+ */
212
+ function serializeEdge(edge) {
213
+ return {
214
+ source: edge.source,
215
+ target: edge.target,
216
+ kind: edge.kind,
217
+ line: edge.line,
218
+ column: edge.column,
219
+ };
220
+ }
221
+ /**
222
+ * Truncate a string with ellipsis
223
+ */
224
+ function truncate(str, maxLength) {
225
+ if (str.length <= maxLength) {
226
+ return str;
227
+ }
228
+ return str.slice(0, maxLength - 3) + '...';
229
+ }
230
+ /**
231
+ * Format bytes as human-readable string
232
+ */
233
+ function formatBytes(bytes) {
234
+ if (bytes < 1024) {
235
+ return `${bytes} bytes`;
236
+ }
237
+ else if (bytes < 1024 * 1024) {
238
+ return `${(bytes / 1024).toFixed(1)} KB`;
239
+ }
240
+ else {
241
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
242
+ }
243
+ }
244
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Context Builder
3
+ *
4
+ * Builds rich context for tasks by combining FTS search with graph traversal.
5
+ * Outputs structured context ready to inject into Claude.
6
+ */
7
+ import {
8
+ Subgraph,
9
+ TaskContext,
10
+ TaskInput,
11
+ BuildContextOptions,
12
+ FindRelevantContextOptions,
13
+ } from '../types'
14
+ import { QueryBuilder } from '../db/queries'
15
+ import { GraphTraverser } from '../graph'
16
+ /**
17
+ * Context Builder
18
+ *
19
+ * Coordinates semantic search and graph traversal to build
20
+ * comprehensive context for tasks.
21
+ */
22
+ export declare class ContextBuilder {
23
+ private projectRoot
24
+ private queries
25
+ private traverser
26
+ constructor(
27
+ projectRoot: string,
28
+ queries: QueryBuilder,
29
+ traverser: GraphTraverser,
30
+ )
31
+ /**
32
+ * Build context for a task
33
+ *
34
+ * Pipeline:
35
+ * 1. Parse task input (string or {title, description})
36
+ * 2. Run semantic search to find entry points
37
+ * 3. Expand graph around entry points
38
+ * 4. Extract code blocks for key nodes
39
+ * 5. Format output for Claude
40
+ *
41
+ * @param input - Task description or object with title/description
42
+ * @param options - Build options
43
+ * @returns TaskContext (structured) or formatted string
44
+ */
45
+ buildContext(
46
+ input: TaskInput,
47
+ options?: BuildContextOptions,
48
+ ): Promise<TaskContext | string>
49
+ /**
50
+ * Find relevant subgraph for a query
51
+ *
52
+ * Uses hybrid search combining exact symbol lookup with semantic search:
53
+ * 1. Extract potential symbol names from query
54
+ * 2. Look up exact matches for those symbols (high confidence)
55
+ * 3. Use semantic search for concept matching
56
+ * 4. Merge results, prioritizing exact matches
57
+ * 5. Traverse graph from entry points
58
+ *
59
+ * @param query - Natural language query
60
+ * @param options - Search and traversal options
61
+ * @returns Subgraph of relevant nodes and edges
62
+ */
63
+ findRelevantContext(
64
+ query: string,
65
+ options?: FindRelevantContextOptions,
66
+ ): Promise<Subgraph>
67
+ /**
68
+ * Get the source code for a node
69
+ *
70
+ * Reads the file and extracts the code between startLine and endLine.
71
+ *
72
+ * @param nodeId - ID of the node
73
+ * @returns Code string or null if not found
74
+ */
75
+ getCode(nodeId: string): Promise<string | null>
76
+ /**
77
+ * Extract code from a node's source file
78
+ */
79
+ private extractNodeCode
80
+ /**
81
+ * Get entry points from a subgraph (the root nodes)
82
+ */
83
+ private getEntryPoints
84
+ /**
85
+ * Extract code blocks for key nodes in the subgraph
86
+ */
87
+ private extractCodeBlocks
88
+ /**
89
+ * Get unique files from a subgraph
90
+ */
91
+ private getRelatedFiles
92
+ /**
93
+ * Generate a summary of the context
94
+ */
95
+ private generateSummary
96
+ /**
97
+ * Resolve import/export nodes to their actual definitions
98
+ *
99
+ * When search returns `import { TerminalPanel }`, users want the TerminalPanel
100
+ * class definition, not the import statement. This follows the `imports` edge
101
+ * to find and return the actual definition instead.
102
+ *
103
+ * @param results - Search results that may include import/export nodes
104
+ * @returns Results with imports resolved to definitions where possible
105
+ */
106
+ private resolveImportsToDefinitions
107
+ }
108
+ /**
109
+ * Create a context builder
110
+ */
111
+ export declare function createContextBuilder(
112
+ projectRoot: string,
113
+ queries: QueryBuilder,
114
+ traverser: GraphTraverser,
115
+ ): ContextBuilder
116
+ export { formatContextAsMarkdown, formatContextAsJson } from './formatter'
117
+ //# sourceMappingURL=index.d.ts.map