clast-ai 0.1.2 → 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 (290) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.claude-plugin/plugin.json +11 -9
  3. package/README.md +447 -401
  4. package/bench/ab/onair-concept.json +22 -0
  5. package/bench/ab/onair-deadcode.json +7 -0
  6. package/bench/ab/onair-hard.json +32 -0
  7. package/bench/ab/onair-impact.json +17 -0
  8. package/bench/ab/onair-refactors.json +18 -0
  9. package/bench/ab/onair-survey.json +17 -0
  10. package/bench/ab/onair-tasks.json +20 -0
  11. package/bench/ab/onair.json +52 -0
  12. package/bench/ab/vscode-concept.json +22 -0
  13. package/bench/ab/vscode-hard.json +32 -0
  14. package/bench/ab/vscode-impact.json +17 -0
  15. package/bench/ab/vscode-refactors.json +18 -0
  16. package/bench/ab/vscode-tasks.json +20 -0
  17. package/bench/ab/vscode.json +52 -0
  18. package/bench/ab.mjs +213 -0
  19. package/bench/bench.mjs +98 -0
  20. package/bench/resolution.mjs +75 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +257 -0
  23. package/dist/cli.js.map +1 -0
  24. package/dist/config/defaults.d.ts +12 -2
  25. package/dist/config/defaults.js +38 -31
  26. package/dist/config/defaults.js.map +1 -1
  27. package/dist/config/index.d.ts +1 -1
  28. package/dist/config/index.js +26 -14
  29. package/dist/config/index.js.map +1 -1
  30. package/dist/db/index.d.ts +73 -13
  31. package/dist/db/index.js +481 -39
  32. package/dist/db/index.js.map +1 -1
  33. package/dist/engine.d.ts +15 -0
  34. package/dist/engine.js +28 -0
  35. package/dist/engine.js.map +1 -0
  36. package/dist/indexer/imports.d.ts +6 -0
  37. package/dist/indexer/imports.js +254 -0
  38. package/dist/indexer/imports.js.map +1 -0
  39. package/dist/indexer/index.d.ts +63 -0
  40. package/dist/indexer/index.js +360 -0
  41. package/dist/indexer/index.js.map +1 -0
  42. package/dist/indexer/process.d.ts +22 -0
  43. package/dist/indexer/process.js +42 -0
  44. package/dist/indexer/process.js.map +1 -0
  45. package/dist/indexer/scan.d.ts +43 -0
  46. package/dist/indexer/scan.js +223 -0
  47. package/dist/indexer/scan.js.map +1 -0
  48. package/dist/indexer/worker.d.ts +1 -0
  49. package/dist/indexer/worker.js +23 -0
  50. package/dist/indexer/worker.js.map +1 -0
  51. package/dist/llm/comment-generator.d.ts +17 -19
  52. package/dist/llm/comment-generator.js +46 -80
  53. package/dist/llm/comment-generator.js.map +1 -1
  54. package/dist/llm/index.d.ts +0 -1
  55. package/dist/llm/index.js.map +1 -1
  56. package/dist/llm/prompts.d.ts +0 -1
  57. package/dist/llm/prompts.js +16 -16
  58. package/dist/parser/extractor.d.ts +21 -16
  59. package/dist/parser/extractor.js +700 -228
  60. package/dist/parser/extractor.js.map +1 -1
  61. package/dist/parser/index.d.ts +17 -21
  62. package/dist/parser/index.js +115 -171
  63. package/dist/parser/index.js.map +1 -1
  64. package/dist/parser/langs/c.d.ts +3 -0
  65. package/dist/parser/langs/c.js +879 -0
  66. package/dist/parser/langs/c.js.map +1 -0
  67. package/dist/parser/langs/csharp.d.ts +2 -0
  68. package/dist/parser/langs/csharp.js +548 -0
  69. package/dist/parser/langs/csharp.js.map +1 -0
  70. package/dist/parser/langs/dart.d.ts +2 -0
  71. package/dist/parser/langs/dart.js +893 -0
  72. package/dist/parser/langs/dart.js.map +1 -0
  73. package/dist/parser/langs/go.d.ts +2 -0
  74. package/dist/parser/langs/go.js +455 -0
  75. package/dist/parser/langs/go.js.map +1 -0
  76. package/dist/parser/langs/java.d.ts +2 -0
  77. package/dist/parser/langs/java.js +390 -0
  78. package/dist/parser/langs/java.js.map +1 -0
  79. package/dist/parser/langs/php.d.ts +2 -0
  80. package/dist/parser/langs/php.js +486 -0
  81. package/dist/parser/langs/php.js.map +1 -0
  82. package/dist/parser/langs/python.d.ts +2 -0
  83. package/dist/parser/langs/python.js +216 -0
  84. package/dist/parser/langs/python.js.map +1 -0
  85. package/dist/parser/langs/ruby.d.ts +2 -0
  86. package/dist/parser/langs/ruby.js +602 -0
  87. package/dist/parser/langs/ruby.js.map +1 -0
  88. package/dist/parser/langs/rust.d.ts +2 -0
  89. package/dist/parser/langs/rust.js +931 -0
  90. package/dist/parser/langs/rust.js.map +1 -0
  91. package/dist/parser/langs/swift.d.ts +2 -0
  92. package/dist/parser/langs/swift.js +616 -0
  93. package/dist/parser/langs/swift.js.map +1 -0
  94. package/dist/parser/langs/typescript.d.ts +4 -0
  95. package/dist/parser/langs/typescript.js +535 -0
  96. package/dist/parser/langs/typescript.js.map +1 -0
  97. package/dist/parser/registry.d.ts +16 -0
  98. package/dist/parser/registry.js +87 -0
  99. package/dist/parser/registry.js.map +1 -0
  100. package/dist/parser/returns.d.ts +9 -0
  101. package/dist/parser/returns.js +152 -0
  102. package/dist/parser/returns.js.map +1 -0
  103. package/dist/parser/spec.d.ts +165 -0
  104. package/dist/parser/spec.js +188 -0
  105. package/dist/parser/spec.js.map +1 -0
  106. package/dist/query/arity.d.ts +27 -0
  107. package/dist/query/arity.js +187 -0
  108. package/dist/query/arity.js.map +1 -0
  109. package/dist/query/callgraph.d.ts +113 -0
  110. package/dist/query/callgraph.js +332 -0
  111. package/dist/query/callgraph.js.map +1 -0
  112. package/dist/query/format.d.ts +36 -0
  113. package/dist/query/format.js +136 -0
  114. package/dist/query/format.js.map +1 -0
  115. package/dist/query/hierarchy.d.ts +44 -0
  116. package/dist/query/hierarchy.js +441 -0
  117. package/dist/query/hierarchy.js.map +1 -0
  118. package/dist/query/resolve.d.ts +265 -0
  119. package/dist/query/resolve.js +1957 -0
  120. package/dist/query/resolve.js.map +1 -0
  121. package/dist/query/search.d.ts +35 -0
  122. package/dist/query/search.js +379 -0
  123. package/dist/query/search.js.map +1 -0
  124. package/dist/query/words.d.ts +30 -0
  125. package/dist/query/words.js +201 -0
  126. package/dist/query/words.js.map +1 -0
  127. package/dist/server/index.d.ts +1 -3
  128. package/dist/server/index.js +313 -73
  129. package/dist/server/index.js.map +1 -1
  130. package/dist/tools/context.d.ts +35 -0
  131. package/dist/tools/context.js +79 -0
  132. package/dist/tools/context.js.map +1 -0
  133. package/dist/tools/explore.d.ts +51 -0
  134. package/dist/tools/explore.js +779 -0
  135. package/dist/tools/explore.js.map +1 -0
  136. package/dist/tools/impact.d.ts +21 -0
  137. package/dist/tools/impact.js +743 -0
  138. package/dist/tools/impact.js.map +1 -0
  139. package/dist/tools/search.d.ts +59 -0
  140. package/dist/tools/search.js +843 -0
  141. package/dist/tools/search.js.map +1 -0
  142. package/dist/tools/stats.d.ts +26 -0
  143. package/dist/tools/stats.js +604 -0
  144. package/dist/tools/stats.js.map +1 -0
  145. package/dist/types.d.ts +95 -40
  146. package/dist/types.js +9 -1
  147. package/dist/types.js.map +1 -1
  148. package/dist/version.d.ts +2 -0
  149. package/dist/version.js +3 -0
  150. package/dist/version.js.map +1 -0
  151. package/dist/watcher/index.d.ts +18 -16
  152. package/dist/watcher/index.js +94 -77
  153. package/dist/watcher/index.js.map +1 -1
  154. package/package.json +21 -24
  155. package/plugin/server.mjs +50 -0
  156. package/skills/audit/SKILL.md +37 -0
  157. package/skills/deadcode/SKILL.md +33 -0
  158. package/skills/explore/SKILL.md +54 -0
  159. package/skills/impact/SKILL.md +24 -0
  160. package/skills/status/SKILL.md +11 -0
  161. package/src/cli.ts +256 -0
  162. package/src/config/defaults.ts +50 -32
  163. package/src/config/index.ts +23 -14
  164. package/src/db/index.ts +540 -43
  165. package/src/engine.ts +30 -0
  166. package/src/indexer/imports.ts +241 -0
  167. package/src/indexer/index.ts +369 -0
  168. package/src/indexer/process.ts +63 -0
  169. package/src/indexer/scan.ts +226 -0
  170. package/src/indexer/worker.ts +24 -0
  171. package/src/llm/comment-generator.ts +52 -103
  172. package/src/llm/index.ts +80 -80
  173. package/src/llm/prompts.ts +95 -95
  174. package/src/parser/extractor.ts +643 -256
  175. package/src/parser/index.ts +105 -205
  176. package/src/parser/langs/c.ts +860 -0
  177. package/src/parser/langs/csharp.ts +519 -0
  178. package/src/parser/langs/dart.ts +820 -0
  179. package/src/parser/langs/go.ts +437 -0
  180. package/src/parser/langs/java.ts +361 -0
  181. package/src/parser/langs/php.ts +450 -0
  182. package/src/parser/langs/python.ts +206 -0
  183. package/src/parser/langs/ruby.ts +554 -0
  184. package/src/parser/langs/rust.ts +904 -0
  185. package/src/parser/langs/swift.ts +590 -0
  186. package/src/parser/langs/typescript.ts +499 -0
  187. package/src/parser/registry.ts +88 -0
  188. package/src/parser/returns.ts +137 -0
  189. package/src/parser/spec.ts +309 -0
  190. package/src/query/arity.ts +173 -0
  191. package/src/query/callgraph.ts +473 -0
  192. package/src/query/format.ts +136 -0
  193. package/src/query/hierarchy.ts +447 -0
  194. package/src/query/resolve.ts +1972 -0
  195. package/src/query/search.ts +430 -0
  196. package/src/query/words.ts +183 -0
  197. package/src/server/index.ts +390 -79
  198. package/src/tools/context.ts +82 -0
  199. package/src/tools/explore.ts +860 -0
  200. package/src/tools/impact.ts +748 -0
  201. package/src/tools/search.ts +886 -0
  202. package/src/tools/stats.ts +633 -0
  203. package/src/types.ts +113 -45
  204. package/src/version.ts +2 -0
  205. package/src/watcher/index.ts +82 -88
  206. package/tsconfig.json +7 -4
  207. package/.mcp.json +0 -8
  208. package/commands/clast-status.md +0 -9
  209. package/dist/config/defaults.d.ts.map +0 -1
  210. package/dist/config/index.d.ts.map +0 -1
  211. package/dist/db/index.d.ts.map +0 -1
  212. package/dist/db/queries.d.ts +0 -44
  213. package/dist/db/queries.d.ts.map +0 -1
  214. package/dist/db/queries.js +0 -251
  215. package/dist/db/queries.js.map +0 -1
  216. package/dist/db/schema.d.ts +0 -3
  217. package/dist/db/schema.d.ts.map +0 -1
  218. package/dist/db/schema.js +0 -94
  219. package/dist/db/schema.js.map +0 -1
  220. package/dist/db/types.d.ts +0 -44
  221. package/dist/db/types.d.ts.map +0 -1
  222. package/dist/db/types.js +0 -2
  223. package/dist/db/types.js.map +0 -1
  224. package/dist/llm/comment-generator.d.ts.map +0 -1
  225. package/dist/llm/index.d.ts.map +0 -1
  226. package/dist/llm/prompts.d.ts.map +0 -1
  227. package/dist/parser/call-resolver.d.ts +0 -15
  228. package/dist/parser/call-resolver.d.ts.map +0 -1
  229. package/dist/parser/call-resolver.js +0 -16
  230. package/dist/parser/call-resolver.js.map +0 -1
  231. package/dist/parser/extractor.d.ts.map +0 -1
  232. package/dist/parser/index.d.ts.map +0 -1
  233. package/dist/parser/languages.d.ts +0 -11
  234. package/dist/parser/languages.d.ts.map +0 -1
  235. package/dist/parser/languages.js +0 -74
  236. package/dist/parser/languages.js.map +0 -1
  237. package/dist/server/index.d.ts.map +0 -1
  238. package/dist/server/register-tools.d.ts +0 -7
  239. package/dist/server/register-tools.d.ts.map +0 -1
  240. package/dist/server/register-tools.js +0 -17
  241. package/dist/server/register-tools.js.map +0 -1
  242. package/dist/server/tools/clast-call-graph.d.ts +0 -4
  243. package/dist/server/tools/clast-call-graph.d.ts.map +0 -1
  244. package/dist/server/tools/clast-call-graph.js +0 -70
  245. package/dist/server/tools/clast-call-graph.js.map +0 -1
  246. package/dist/server/tools/clast-comment.d.ts +0 -5
  247. package/dist/server/tools/clast-comment.d.ts.map +0 -1
  248. package/dist/server/tools/clast-comment.js +0 -64
  249. package/dist/server/tools/clast-comment.js.map +0 -1
  250. package/dist/server/tools/clast-file-summary.d.ts +0 -4
  251. package/dist/server/tools/clast-file-summary.d.ts.map +0 -1
  252. package/dist/server/tools/clast-file-summary.js +0 -42
  253. package/dist/server/tools/clast-file-summary.js.map +0 -1
  254. package/dist/server/tools/clast-get-context.d.ts +0 -4
  255. package/dist/server/tools/clast-get-context.d.ts.map +0 -1
  256. package/dist/server/tools/clast-get-context.js +0 -80
  257. package/dist/server/tools/clast-get-context.js.map +0 -1
  258. package/dist/server/tools/clast-reindex.d.ts +0 -5
  259. package/dist/server/tools/clast-reindex.d.ts.map +0 -1
  260. package/dist/server/tools/clast-reindex.js +0 -36
  261. package/dist/server/tools/clast-reindex.js.map +0 -1
  262. package/dist/server/tools/clast-search.d.ts +0 -4
  263. package/dist/server/tools/clast-search.d.ts.map +0 -1
  264. package/dist/server/tools/clast-search.js +0 -29
  265. package/dist/server/tools/clast-search.js.map +0 -1
  266. package/dist/server/tools/clast-status.d.ts +0 -5
  267. package/dist/server/tools/clast-status.d.ts.map +0 -1
  268. package/dist/server/tools/clast-status.js +0 -23
  269. package/dist/server/tools/clast-status.js.map +0 -1
  270. package/dist/types.d.ts.map +0 -1
  271. package/dist/watcher/gitignore.d.ts +0 -9
  272. package/dist/watcher/gitignore.d.ts.map +0 -1
  273. package/dist/watcher/gitignore.js +0 -38
  274. package/dist/watcher/gitignore.js.map +0 -1
  275. package/dist/watcher/index.d.ts.map +0 -1
  276. package/skills/clast-explore/SKILL.md +0 -41
  277. package/src/db/queries.ts +0 -332
  278. package/src/db/schema.ts +0 -106
  279. package/src/db/types.ts +0 -47
  280. package/src/parser/call-resolver.ts +0 -17
  281. package/src/parser/languages.ts +0 -86
  282. package/src/server/register-tools.ts +0 -30
  283. package/src/server/tools/clast-call-graph.ts +0 -82
  284. package/src/server/tools/clast-comment.ts +0 -76
  285. package/src/server/tools/clast-file-summary.ts +0 -59
  286. package/src/server/tools/clast-get-context.ts +0 -97
  287. package/src/server/tools/clast-reindex.ts +0 -52
  288. package/src/server/tools/clast-search.ts +0 -38
  289. package/src/server/tools/clast-status.ts +0 -37
  290. package/src/watcher/gitignore.ts +0 -42
@@ -1,76 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { ClastDatabase } from '../../db/index.js';
4
- import type { CommentGenerator } from '../../llm/comment-generator.js';
5
-
6
- export function registerCommentTool(
7
- server: McpServer,
8
- db: ClastDatabase,
9
- commentGen: CommentGenerator
10
- ): void {
11
- server.tool(
12
- 'clast_comment',
13
- 'Get or generate documentation comments for a symbol. By default returns existing comments. Set generate=true to create a new comment via LLM if none exists.',
14
- {
15
- name: z.string().describe('Symbol name to get/generate comment for'),
16
- generate: z.boolean().default(false).describe('If true and no comment exists, generate one via LLM'),
17
- },
18
- async ({ name, generate }) => {
19
- const nodes = db.queries.getNodeByName(name);
20
- if (nodes.length === 0) {
21
- return {
22
- content: [{
23
- type: 'text' as const,
24
- text: JSON.stringify({ error: `No symbol found with name "${name}"` }),
25
- }],
26
- };
27
- }
28
-
29
- const results = [];
30
- for (const node of nodes) {
31
- const comments = db.queries.getCommentsForNode(node.id);
32
- const original = comments.find(c => c.source === 'original');
33
- const generated = comments.find(c => c.source === 'generated');
34
-
35
- const entry: Record<string, unknown> = {
36
- name: node.name,
37
- type: node.type,
38
- filePath: node.file_path,
39
- startLine: node.start_line,
40
- };
41
-
42
- if (original) {
43
- entry.comment = original.text;
44
- entry.source = 'original';
45
- } else if (generated) {
46
- entry.comment = generated.text;
47
- entry.source = 'generated';
48
- } else if (generate) {
49
- if (!commentGen.isAvailable) {
50
- entry.error = 'LLM not configured. Set llm.model in clast.config.json.';
51
- } else {
52
- const result = await commentGen.generateForNode(node.id);
53
- if (result) {
54
- entry.comment = result;
55
- entry.source = 'generated';
56
- } else {
57
- entry.error = 'Failed to generate comment';
58
- }
59
- }
60
- } else {
61
- entry.comment = null;
62
- entry.source = null;
63
- }
64
-
65
- results.push(entry);
66
- }
67
-
68
- return {
69
- content: [{
70
- type: 'text' as const,
71
- text: JSON.stringify(results, null, 2),
72
- }],
73
- };
74
- }
75
- );
76
- }
@@ -1,59 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { ClastDatabase } from '../../db/index.js';
4
-
5
- export function registerFileSummaryTool(server: McpServer, db: ClastDatabase): void {
6
- server.tool(
7
- 'clast_file_summary',
8
- 'Get a structured summary of all symbols in a file, grouped by type (imports, classes, functions, exports, etc.). PREFER THIS over reading an entire file when you need to understand its structure — returns all symbols with line numbers without the noise of implementation details.',
9
- {
10
- filePath: z.string().describe('Relative file path (forward slashes, e.g. "src/parser/index.ts")'),
11
- },
12
- async ({ filePath }) => {
13
- // Normalize path
14
- const normalized = filePath.replace(/\\/g, '/');
15
- const nodes = db.queries.getNodesByFile(normalized);
16
-
17
- if (nodes.length === 0) {
18
- return {
19
- content: [{
20
- type: 'text' as const,
21
- text: JSON.stringify({ error: `No indexed data for file "${normalized}". Try clast_reindex first.` }),
22
- }],
23
- };
24
- }
25
-
26
- // Group by type
27
- const grouped: Record<string, Array<{
28
- name: string;
29
- signature: string;
30
- startLine: number;
31
- endLine: number;
32
- }>> = {};
33
-
34
- for (const node of nodes) {
35
- const group = grouped[node.type] ??= [];
36
- group.push({
37
- name: node.name,
38
- signature: node.signature,
39
- startLine: node.start_line,
40
- endLine: node.end_line,
41
- });
42
- }
43
-
44
- const summary = {
45
- filePath: normalized,
46
- language: nodes[0]?.language,
47
- totalSymbols: nodes.length,
48
- symbols: grouped,
49
- };
50
-
51
- return {
52
- content: [{
53
- type: 'text' as const,
54
- text: JSON.stringify(summary, null, 2),
55
- }],
56
- };
57
- }
58
- );
59
- }
@@ -1,97 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { ClastDatabase } from '../../db/index.js';
4
-
5
- export function registerGetContextTool(server: McpServer, db: ClastDatabase): void {
6
- server.tool(
7
- 'clast_get_context',
8
- 'Get full context for a symbol: definition, comments/documentation, callers, callees, and parent class. PREFER THIS over reading entire files when you need to understand a specific function or class before editing. Returns everything needed to make informed code changes.',
9
- {
10
- name: z.string().describe('Symbol name to look up'),
11
- includeBody: z.boolean().default(false).describe('Include the full function/class body text'),
12
- },
13
- async ({ name, includeBody }) => {
14
- const ctx = db.queries.getNodeWithContext(name);
15
-
16
- if (ctx.nodes.length === 0) {
17
- return {
18
- content: [{
19
- type: 'text' as const,
20
- text: JSON.stringify({ error: `No symbol found with name "${name}"` }),
21
- }],
22
- };
23
- }
24
-
25
- const result = ctx.nodes.map(node => {
26
- const nodeComments = ctx.comments.filter(c => c.node_id === node.id);
27
- const entry: Record<string, unknown> = {
28
- name: node.name,
29
- type: node.type,
30
- filePath: node.file_path,
31
- location: `${node.file_path}:${node.start_line}-${node.end_line}`,
32
- signature: node.signature,
33
- language: node.language,
34
- };
35
-
36
- if (includeBody) {
37
- entry.body = node.body_text;
38
- }
39
-
40
- // Comments: prioritize original, also show generated
41
- const originalComment = nodeComments.find(c => c.source === 'original');
42
- const generatedComment = nodeComments.find(c => c.source === 'generated');
43
-
44
- if (originalComment) {
45
- entry.comment = originalComment.text;
46
- entry.commentSource = 'original';
47
- }
48
- if (generatedComment) {
49
- entry.generatedDescription = generatedComment.text;
50
- }
51
-
52
- // Parent (for methods inside classes)
53
- if (node.parent_id) {
54
- const parent = db.queries.getNodeById(node.parent_id);
55
- if (parent) {
56
- entry.parentClass = {
57
- name: parent.name,
58
- type: parent.type,
59
- filePath: parent.file_path,
60
- startLine: parent.start_line,
61
- };
62
- }
63
- }
64
-
65
- return entry;
66
- });
67
-
68
- // Callers and callees (deduplicated across all matching nodes)
69
- const callers = ctx.callers.map(n => ({
70
- name: n.name,
71
- type: n.type,
72
- filePath: n.file_path,
73
- startLine: n.start_line,
74
- signature: n.signature,
75
- }));
76
-
77
- const callees = ctx.callees.map(n => ({
78
- name: n.name,
79
- type: n.type,
80
- filePath: n.file_path,
81
- startLine: n.start_line,
82
- signature: n.signature,
83
- }));
84
-
85
- return {
86
- content: [{
87
- type: 'text' as const,
88
- text: JSON.stringify({
89
- definitions: result,
90
- callers,
91
- callees,
92
- }, null, 2),
93
- }],
94
- };
95
- }
96
- );
97
- }
@@ -1,52 +0,0 @@
1
- import { z } from 'zod';
2
- import { join } from 'node:path';
3
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
- import type { ClastDatabase } from '../../db/index.js';
5
- import type { ParserManager } from '../../parser/index.js';
6
-
7
- export function registerReindexTool(
8
- server: McpServer,
9
- db: ClastDatabase,
10
- parser: ParserManager,
11
- projectRoot: string
12
- ): void {
13
- server.tool(
14
- 'clast_reindex',
15
- 'Force re-index a specific file or the entire repository. Use when the index seems stale or after large changes.',
16
- {
17
- filePath: z.string().optional().describe('Specific file to reindex (relative path). Omit to reindex the entire repo.'),
18
- },
19
- async ({ filePath }) => {
20
- if (filePath) {
21
- const absPath = join(projectRoot, filePath);
22
- const parsed = await parser.incrementalUpdate(absPath, projectRoot, db);
23
-
24
- return {
25
- content: [{
26
- type: 'text' as const,
27
- text: JSON.stringify({
28
- file: filePath,
29
- reindexed: parsed,
30
- message: parsed ? 'File reindexed successfully' : 'File unchanged or unsupported',
31
- }),
32
- }],
33
- };
34
- }
35
-
36
- const result = await parser.fullIndex(projectRoot, db);
37
-
38
- return {
39
- content: [{
40
- type: 'text' as const,
41
- text: JSON.stringify({
42
- filesProcessed: result.filesProcessed,
43
- nodesFound: result.nodesFound,
44
- edgesResolved: result.edgesResolved,
45
- durationMs: result.durationMs,
46
- message: `Full reindex completed in ${result.durationMs}ms`,
47
- }),
48
- }],
49
- };
50
- }
51
- );
52
- }
@@ -1,38 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { ClastDatabase } from '../../db/index.js';
4
-
5
- export function registerSearchTool(server: McpServer, db: ClastDatabase): void {
6
- server.tool(
7
- 'clast_search',
8
- 'Search the pre-built AST index for functions, classes, methods, and other symbols by name pattern. PREFER THIS over grep/file search when looking for symbol definitions — it is faster and returns structured results with exact file paths, line numbers, and signatures.',
9
- {
10
- query: z.string().describe('Search pattern (matches against symbol names, supports partial matches)'),
11
- type: z.enum([
12
- 'function', 'method', 'class', 'interface', 'enum',
13
- 'import', 'export', 'variable', 'type_alias', 'struct', 'trait', 'module',
14
- ]).optional().describe('Filter by symbol type'),
15
- limit: z.number().int().min(1).max(100).default(20).describe('Maximum results to return'),
16
- },
17
- async ({ query, type, limit }) => {
18
- const results = db.queries.searchNodes(query, type, limit);
19
-
20
- const formatted = results.map(n => ({
21
- name: n.name,
22
- type: n.type,
23
- filePath: n.file_path,
24
- startLine: n.start_line,
25
- endLine: n.end_line,
26
- signature: n.signature,
27
- language: n.language,
28
- }));
29
-
30
- return {
31
- content: [{
32
- type: 'text' as const,
33
- text: JSON.stringify(formatted, null, 2),
34
- }],
35
- };
36
- }
37
- );
38
- }
@@ -1,37 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { ClastDatabase } from '../../db/index.js';
3
- import type { FileWatcher } from '../../watcher/index.js';
4
-
5
- export function registerStatusTool(
6
- server: McpServer,
7
- db: ClastDatabase,
8
- watcher: FileWatcher
9
- ): void {
10
- server.tool(
11
- 'clast_status',
12
- 'Show the current indexing status: files indexed, total symbols, total call edges, watcher state, and pending updates.',
13
- {},
14
- async () => {
15
- const status = db.queries.getStatus();
16
-
17
- const result = {
18
- filesIndexed: status.files_indexed,
19
- totalNodes: status.total_nodes,
20
- totalEdges: status.total_edges,
21
- totalComments: status.total_comments,
22
- lastIndexed: status.last_indexed
23
- ? new Date(status.last_indexed).toISOString()
24
- : null,
25
- watcherActive: watcher.isActive,
26
- pendingFiles: watcher.pendingCount,
27
- };
28
-
29
- return {
30
- content: [{
31
- type: 'text' as const,
32
- text: JSON.stringify(result, null, 2),
33
- }],
34
- };
35
- }
36
- );
37
- }
@@ -1,42 +0,0 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
-
4
- /**
5
- * Parse .gitignore files into glob patterns suitable for chokidar's `ignored` option.
6
- */
7
- export function loadGitignorePatterns(projectRoot: string): string[] {
8
- const patterns: string[] = [];
9
- const gitignorePath = join(projectRoot, '.gitignore');
10
-
11
- if (!existsSync(gitignorePath)) return patterns;
12
-
13
- try {
14
- const content = readFileSync(gitignorePath, 'utf-8');
15
- for (const line of content.split('\n')) {
16
- const trimmed = line.trim();
17
- // Skip comments and empty lines
18
- if (!trimmed || trimmed.startsWith('#')) continue;
19
- // Negation patterns are not supported by chokidar's simple ignored
20
- if (trimmed.startsWith('!')) continue;
21
-
22
- patterns.push(trimmed);
23
- }
24
- } catch {
25
- // Silently ignore read errors
26
- }
27
-
28
- return patterns;
29
- }
30
-
31
- /**
32
- * Build the full ignored patterns list combining .gitignore and config.
33
- */
34
- export function buildIgnorePatterns(
35
- projectRoot: string,
36
- configIgnored: string[]
37
- ): string[] {
38
- const gitignorePatterns = loadGitignorePatterns(projectRoot);
39
- // Deduplicate
40
- const all = new Set([...configIgnored, ...gitignorePatterns]);
41
- return Array.from(all);
42
- }