kotadb 2.0.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 (52) hide show
  1. package/README.md +79 -0
  2. package/package.json +75 -0
  3. package/src/api/auto-reindex.ts +55 -0
  4. package/src/api/openapi/builder.ts +209 -0
  5. package/src/api/openapi/paths.ts +354 -0
  6. package/src/api/openapi/schemas.ts +608 -0
  7. package/src/api/queries.ts +1168 -0
  8. package/src/api/routes.ts +339 -0
  9. package/src/auth/middleware.ts +83 -0
  10. package/src/cli.ts +221 -0
  11. package/src/config/constants.ts +96 -0
  12. package/src/config/environment.ts +96 -0
  13. package/src/config/gitignore.ts +68 -0
  14. package/src/config/index.ts +20 -0
  15. package/src/config/project-root.ts +52 -0
  16. package/src/db/client.ts +72 -0
  17. package/src/db/sqlite/index.ts +35 -0
  18. package/src/db/sqlite/jsonl-exporter.ts +416 -0
  19. package/src/db/sqlite/jsonl-importer.ts +361 -0
  20. package/src/db/sqlite/sqlite-client.ts +536 -0
  21. package/src/index.ts +66 -0
  22. package/src/indexer/ast-parser.ts +146 -0
  23. package/src/indexer/ast-types.ts +54 -0
  24. package/src/indexer/circular-detector.ts +262 -0
  25. package/src/indexer/dependency-extractor.ts +352 -0
  26. package/src/indexer/extractors.ts +54 -0
  27. package/src/indexer/import-resolver.ts +167 -0
  28. package/src/indexer/parsers.ts +177 -0
  29. package/src/indexer/reference-extractor.ts +488 -0
  30. package/src/indexer/repos.ts +245 -0
  31. package/src/indexer/storage.ts +277 -0
  32. package/src/indexer/symbol-extractor.ts +660 -0
  33. package/src/instrument.ts +88 -0
  34. package/src/logging/context.ts +46 -0
  35. package/src/logging/logger.ts +193 -0
  36. package/src/logging/middleware.ts +107 -0
  37. package/src/mcp/github-integration.ts +293 -0
  38. package/src/mcp/headers.ts +101 -0
  39. package/src/mcp/impact-analysis.ts +495 -0
  40. package/src/mcp/jsonrpc.ts +141 -0
  41. package/src/mcp/lifecycle.ts +73 -0
  42. package/src/mcp/server.ts +202 -0
  43. package/src/mcp/session.ts +44 -0
  44. package/src/mcp/spec-validation.ts +491 -0
  45. package/src/mcp/tools.ts +889 -0
  46. package/src/sync/deletion-manifest.ts +210 -0
  47. package/src/sync/index.ts +16 -0
  48. package/src/sync/merge-driver.ts +172 -0
  49. package/src/sync/watcher.ts +221 -0
  50. package/src/types/rate-limit.ts +88 -0
  51. package/src/validation/common-schemas.ts +96 -0
  52. package/src/validation/schemas.ts +187 -0
@@ -0,0 +1,354 @@
1
+ /**
2
+ * OpenAPI path operations for KotaDB API.
3
+ *
4
+ * Defines all public API endpoints with request/response schemas,
5
+ * parameters, security requirements, and documentation.
6
+ */
7
+
8
+ import type { OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
9
+ import {
10
+ IndexRequestSchema,
11
+ IndexResponseSchema,
12
+ SearchRequestSchema,
13
+ SearchResponseSchema,
14
+ RecentFilesResponseSchema,
15
+ HealthResponseSchema,
16
+ ErrorResponseSchema,
17
+ RateLimitErrorResponseSchema,
18
+ McpRequestSchema,
19
+ McpResponseSchema,
20
+ McpHealthResponseSchema,
21
+ } from './schemas.js';
22
+ /**
23
+ * Standard rate limit response headers
24
+ * Included in all authenticated endpoint responses
25
+ */
26
+ const rateLimitHeaders = {
27
+ 'X-RateLimit-Limit-Hour': {
28
+ description: 'Total requests allowed per hour for the tier',
29
+ schema: { type: 'string' as const },
30
+ example: '100',
31
+ },
32
+ 'X-RateLimit-Remaining-Hour': {
33
+ description: 'Requests remaining in current hour window',
34
+ schema: { type: 'string' as const },
35
+ example: '95',
36
+ },
37
+ 'X-RateLimit-Reset-Hour': {
38
+ description: 'Unix timestamp when the hourly limit resets',
39
+ schema: { type: 'string' as const },
40
+ example: '1702742400',
41
+ },
42
+ 'X-RateLimit-Limit-Day': {
43
+ description: 'Total requests allowed per day for the tier',
44
+ schema: { type: 'string' as const },
45
+ example: '1000',
46
+ },
47
+ 'X-RateLimit-Remaining-Day': {
48
+ description: 'Requests remaining in current day window',
49
+ schema: { type: 'string' as const },
50
+ example: '950',
51
+ },
52
+ 'X-RateLimit-Reset-Day': {
53
+ description: 'Unix timestamp when the daily limit resets',
54
+ schema: { type: 'string' as const },
55
+ example: '1702828800',
56
+ },
57
+ };
58
+
59
+
60
+ /**
61
+ * Register all API path operations with the OpenAPI registry
62
+ */
63
+ export function registerPaths(registry: OpenAPIRegistry): void {
64
+ // ===== Health Check =====
65
+ registry.registerPath({
66
+ method: 'get',
67
+ path: '/health',
68
+ summary: 'Health check',
69
+ description: 'Simple health check endpoint to verify service availability',
70
+ tags: ['Health'],
71
+ security: [], // Public endpoint
72
+ responses: {
73
+ 200: {
74
+ description: 'Service is healthy',
75
+ content: {
76
+ 'application/json': {
77
+ schema: HealthResponseSchema,
78
+ },
79
+ },
80
+ },
81
+ },
82
+ });
83
+
84
+ // ===== Indexing =====
85
+ registry.registerPath({
86
+ method: 'post',
87
+ path: '/index',
88
+ summary: 'Index repository',
89
+ description: 'Trigger indexing of a repository. Creates a background job to clone, parse, and index the repository code.',
90
+ tags: ['Indexing'],
91
+ security: [{ apiKey: [] }, { bearerAuth: [] }],
92
+ request: {
93
+ body: {
94
+ description: 'Repository indexing request',
95
+ content: {
96
+ 'application/json': {
97
+ schema: IndexRequestSchema,
98
+ },
99
+ },
100
+ },
101
+ },
102
+ responses: {
103
+ 200: {
104
+ description: 'Indexing job created successfully. Rate limit headers are included in the response.',
105
+ headers: rateLimitHeaders,
106
+ content: {
107
+ 'application/json': {
108
+ schema: IndexResponseSchema,
109
+ },
110
+ },
111
+ },
112
+ 400: {
113
+ description: 'Invalid request parameters',
114
+ content: {
115
+ 'application/json': {
116
+ schema: ErrorResponseSchema,
117
+ },
118
+ },
119
+ },
120
+ 401: {
121
+ description: 'Unauthorized - Invalid or missing authentication',
122
+ content: {
123
+ 'application/json': {
124
+ schema: ErrorResponseSchema,
125
+ },
126
+ },
127
+ },
128
+ 429: {
129
+ description: 'Rate limit exceeded',
130
+ content: {
131
+ 'application/json': {
132
+ schema: RateLimitErrorResponseSchema,
133
+ },
134
+ },
135
+ },
136
+ 500: {
137
+ description: 'Internal server error',
138
+ content: {
139
+ 'application/json': {
140
+ schema: ErrorResponseSchema,
141
+ },
142
+ },
143
+ },
144
+ },
145
+ });
146
+
147
+ // ===== Search =====
148
+ registry.registerPath({
149
+ method: 'get',
150
+ path: '/search',
151
+ summary: 'Search code',
152
+ description: 'Search indexed file content with optional repository filtering',
153
+ tags: ['Search'],
154
+ security: [{ apiKey: [] }, { bearerAuth: [] }],
155
+ request: {
156
+ query: SearchRequestSchema,
157
+ },
158
+ responses: {
159
+ 200: {
160
+ description: 'Search results retrieved successfully',
161
+ headers: rateLimitHeaders,
162
+ content: {
163
+ 'application/json': {
164
+ schema: SearchResponseSchema,
165
+ },
166
+ },
167
+ },
168
+ 400: {
169
+ description: 'Invalid search parameters',
170
+ content: {
171
+ 'application/json': {
172
+ schema: ErrorResponseSchema,
173
+ },
174
+ },
175
+ },
176
+ 401: {
177
+ description: 'Unauthorized - Invalid or missing authentication',
178
+ content: {
179
+ 'application/json': {
180
+ schema: ErrorResponseSchema,
181
+ },
182
+ },
183
+ },
184
+ 429: {
185
+ description: 'Rate limit exceeded',
186
+ content: {
187
+ 'application/json': {
188
+ schema: RateLimitErrorResponseSchema,
189
+ },
190
+ },
191
+ },
192
+ 500: {
193
+ description: 'Internal server error',
194
+ content: {
195
+ 'application/json': {
196
+ schema: ErrorResponseSchema,
197
+ },
198
+ },
199
+ },
200
+ },
201
+ });
202
+
203
+ // ===== Recent Files =====
204
+ registry.registerPath({
205
+ method: 'get',
206
+ path: '/files/recent',
207
+ summary: 'Get recent files',
208
+ description: 'Retrieve recently indexed files',
209
+ tags: ['Files'],
210
+ security: [{ apiKey: [] }, { bearerAuth: [] }],
211
+ responses: {
212
+ 200: {
213
+ description: 'Recent files retrieved successfully',
214
+ headers: rateLimitHeaders,
215
+ content: {
216
+ 'application/json': {
217
+ schema: RecentFilesResponseSchema,
218
+ },
219
+ },
220
+ },
221
+ 401: {
222
+ description: 'Unauthorized - Invalid or missing authentication',
223
+ content: {
224
+ 'application/json': {
225
+ schema: ErrorResponseSchema,
226
+ },
227
+ },
228
+ },
229
+ 429: {
230
+ description: 'Rate limit exceeded',
231
+ content: {
232
+ 'application/json': {
233
+ schema: RateLimitErrorResponseSchema,
234
+ },
235
+ },
236
+ },
237
+ 500: {
238
+ description: 'Internal server error',
239
+ content: {
240
+ 'application/json': {
241
+ schema: ErrorResponseSchema,
242
+ },
243
+ },
244
+ },
245
+ },
246
+ });
247
+
248
+ // ===== MCP (Model Context Protocol) =====
249
+ registry.registerPath({
250
+ method: 'get',
251
+ path: '/mcp',
252
+ summary: 'MCP health check',
253
+ description: 'Health check endpoint for MCP protocol availability. Returns MCP server metadata and protocol version.',
254
+ tags: ['MCP'],
255
+ security: [{ apiKey: [] }, { bearerAuth: [] }],
256
+ responses: {
257
+ 200: {
258
+ description: 'MCP server is available',
259
+ headers: rateLimitHeaders,
260
+ content: {
261
+ 'application/json': {
262
+ schema: McpHealthResponseSchema,
263
+ },
264
+ },
265
+ },
266
+ 401: {
267
+ description: 'Unauthorized - Invalid or missing authentication',
268
+ content: {
269
+ 'application/json': {
270
+ schema: ErrorResponseSchema,
271
+ },
272
+ },
273
+ },
274
+ 429: {
275
+ description: 'Rate limit exceeded',
276
+ content: {
277
+ 'application/json': {
278
+ schema: RateLimitErrorResponseSchema,
279
+ },
280
+ },
281
+ },
282
+ },
283
+ });
284
+
285
+ registry.registerPath({
286
+ method: 'post',
287
+ path: '/mcp',
288
+ summary: 'Execute MCP tool',
289
+ description: 'Execute Model Context Protocol (MCP) tools for code intelligence operations. Uses JSON-RPC 2.0 protocol for request/response messaging. Available tools: search_code, index_repository, list_recent_files, search_dependencies, analyze_change_impact, validate_implementation_spec, kota_sync_export, kota_sync_import. The endpoint requires both application/json and text/event-stream in the Accept header. Responses follow JSON-RPC 2.0 format with result on success or error on failure.',
290
+ tags: ['MCP'],
291
+ security: [{ apiKey: [] }, { bearerAuth: [] }],
292
+ request: {
293
+ body: {
294
+ description: 'JSON-RPC 2.0 request with MCP tool invocation',
295
+ content: {
296
+ 'application/json': {
297
+ schema: McpRequestSchema,
298
+ },
299
+ },
300
+ },
301
+ },
302
+ responses: {
303
+ 200: {
304
+ description: 'Tool executed successfully. Rate limit headers are included in the response.',
305
+ headers: rateLimitHeaders,
306
+ content: {
307
+ 'application/json': {
308
+ schema: McpResponseSchema,
309
+ },
310
+ },
311
+ },
312
+ 400: {
313
+ description: 'Invalid JSON-RPC request format',
314
+ content: {
315
+ 'application/json': {
316
+ schema: ErrorResponseSchema,
317
+ },
318
+ },
319
+ },
320
+ 401: {
321
+ description: 'Unauthorized - Invalid or missing authentication',
322
+ content: {
323
+ 'application/json': {
324
+ schema: ErrorResponseSchema,
325
+ },
326
+ },
327
+ },
328
+ 406: {
329
+ description: 'Not Acceptable - Must accept both application/json and text/event-stream',
330
+ content: {
331
+ 'application/json': {
332
+ schema: ErrorResponseSchema,
333
+ },
334
+ },
335
+ },
336
+ 429: {
337
+ description: 'Rate limit exceeded',
338
+ content: {
339
+ 'application/json': {
340
+ schema: RateLimitErrorResponseSchema,
341
+ },
342
+ },
343
+ },
344
+ 500: {
345
+ description: 'Internal server error during tool execution',
346
+ content: {
347
+ 'application/json': {
348
+ schema: ErrorResponseSchema,
349
+ },
350
+ },
351
+ },
352
+ },
353
+ });
354
+ }