kotadb 2.1.0-next.20260203213653 → 2.1.0-next.20260203220618
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.
- package/package.json +6 -3
- package/src/indexer/ast-parser.ts +43 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kotadb",
|
|
3
|
-
"version": "2.1.0-next.
|
|
3
|
+
"version": "2.1.0-next.20260203220618",
|
|
4
4
|
"description": "Local-only code intelligence tool for CLI agents. SQLite-backed repository indexing and code search via MCP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@asteasolutions/zod-to-openapi": "^8.4.0",
|
|
55
55
|
"@modelcontextprotocol/sdk": "^1.25.0",
|
|
56
56
|
"@sentry/node": "^10.25.0",
|
|
57
|
-
"@typescript-eslint/parser": "
|
|
58
|
-
"@typescript-eslint/types": "
|
|
57
|
+
"@typescript-eslint/parser": "8.54.0",
|
|
58
|
+
"@typescript-eslint/types": "8.54.0",
|
|
59
59
|
"bcryptjs": "^2.4.3",
|
|
60
60
|
"chokidar": "^5.0.0",
|
|
61
61
|
"cors": "^2.8.6",
|
|
@@ -75,5 +75,8 @@
|
|
|
75
75
|
"lint-staged": "^16.2.4",
|
|
76
76
|
"supertest": "^7.1.4",
|
|
77
77
|
"typescript": "^5.9.3"
|
|
78
|
+
},
|
|
79
|
+
"overrides": {
|
|
80
|
+
"@typescript-eslint/types": "8.54.0"
|
|
78
81
|
}
|
|
79
82
|
}
|
|
@@ -42,6 +42,24 @@ export interface ParseError {
|
|
|
42
42
|
column?: number;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to validate that an AST node is a valid Program.
|
|
47
|
+
* Provides runtime type validation to prevent version compatibility issues.
|
|
48
|
+
*
|
|
49
|
+
* @param ast - Unknown AST node to validate
|
|
50
|
+
* @returns true if ast is a valid Program node
|
|
51
|
+
*/
|
|
52
|
+
function isValidProgram(ast: unknown): ast is TSESTree.Program {
|
|
53
|
+
return (
|
|
54
|
+
ast !== null &&
|
|
55
|
+
typeof ast === "object" &&
|
|
56
|
+
"type" in ast &&
|
|
57
|
+
ast.type === "Program" &&
|
|
58
|
+
"body" in ast &&
|
|
59
|
+
Array.isArray(ast.body)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
/**
|
|
46
64
|
* Result of parsing a file, including partial AST recovery information.
|
|
47
65
|
*/
|
|
@@ -103,7 +121,7 @@ function createParseError(error: unknown): ParseError {
|
|
|
103
121
|
|
|
104
122
|
/**
|
|
105
123
|
* Parse a file with error-tolerant options enabled.
|
|
106
|
-
* Uses allowInvalidAST to attempt partial recovery.
|
|
124
|
+
* Uses allowInvalidAST to attempt partial recovery and validates result.
|
|
107
125
|
*/
|
|
108
126
|
function parseWithRecoveryOptions(filePath: string, content: string): TSESTree.Program | null {
|
|
109
127
|
try {
|
|
@@ -119,6 +137,18 @@ function parseWithRecoveryOptions(filePath: string, content: string): TSESTree.P
|
|
|
119
137
|
allowInvalidAST: true,
|
|
120
138
|
errorOnUnknownASTType: false,
|
|
121
139
|
});
|
|
140
|
+
|
|
141
|
+
// Validate the returned AST is actually a Program node
|
|
142
|
+
if (!isValidProgram(ast)) {
|
|
143
|
+
const astType = typeof ast === "object" && ast !== null && "type" in ast ? (ast as any).type : typeof ast;
|
|
144
|
+
logger.warn(`Parser returned invalid Program type for ${filePath}`, {
|
|
145
|
+
file_path: filePath,
|
|
146
|
+
ast_type: astType,
|
|
147
|
+
recovery: "failed_validation",
|
|
148
|
+
});
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
122
152
|
return ast;
|
|
123
153
|
} catch {
|
|
124
154
|
// Even with recovery options, parsing can still fail
|
|
@@ -159,6 +189,18 @@ export function parseFileWithRecovery(filePath: string, content: string): ParseR
|
|
|
159
189
|
tokens: true,
|
|
160
190
|
filePath,
|
|
161
191
|
});
|
|
192
|
+
|
|
193
|
+
// Validate the returned AST is actually a Program node
|
|
194
|
+
if (!isValidProgram(ast)) {
|
|
195
|
+
const astType = typeof ast === "object" && ast !== null && "type" in ast ? (ast as any).type : typeof ast;
|
|
196
|
+
logger.warn(`Parser returned invalid Program type for ${filePath}`, {
|
|
197
|
+
file_path: filePath,
|
|
198
|
+
ast_type: astType,
|
|
199
|
+
recovery: "failed_validation",
|
|
200
|
+
});
|
|
201
|
+
throw new Error(`Invalid AST type returned: expected Program, got ${astType}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
162
204
|
return {
|
|
163
205
|
ast,
|
|
164
206
|
errors: [],
|