@yuaone/core 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 (235) hide show
  1. package/LICENSE +663 -0
  2. package/README.md +15 -0
  3. package/dist/__tests__/context-manager.test.d.ts +6 -0
  4. package/dist/__tests__/context-manager.test.d.ts.map +1 -0
  5. package/dist/__tests__/context-manager.test.js +220 -0
  6. package/dist/__tests__/context-manager.test.js.map +1 -0
  7. package/dist/__tests__/governor.test.d.ts +6 -0
  8. package/dist/__tests__/governor.test.d.ts.map +1 -0
  9. package/dist/__tests__/governor.test.js +210 -0
  10. package/dist/__tests__/governor.test.js.map +1 -0
  11. package/dist/__tests__/model-router.test.d.ts +6 -0
  12. package/dist/__tests__/model-router.test.d.ts.map +1 -0
  13. package/dist/__tests__/model-router.test.js +329 -0
  14. package/dist/__tests__/model-router.test.js.map +1 -0
  15. package/dist/agent-logger.d.ts +384 -0
  16. package/dist/agent-logger.d.ts.map +1 -0
  17. package/dist/agent-logger.js +820 -0
  18. package/dist/agent-logger.js.map +1 -0
  19. package/dist/agent-loop.d.ts +163 -0
  20. package/dist/agent-loop.d.ts.map +1 -0
  21. package/dist/agent-loop.js +609 -0
  22. package/dist/agent-loop.js.map +1 -0
  23. package/dist/agent-modes.d.ts +85 -0
  24. package/dist/agent-modes.d.ts.map +1 -0
  25. package/dist/agent-modes.js +418 -0
  26. package/dist/agent-modes.js.map +1 -0
  27. package/dist/approval.d.ts +137 -0
  28. package/dist/approval.d.ts.map +1 -0
  29. package/dist/approval.js +299 -0
  30. package/dist/approval.js.map +1 -0
  31. package/dist/async-completion-queue.d.ts +56 -0
  32. package/dist/async-completion-queue.d.ts.map +1 -0
  33. package/dist/async-completion-queue.js +77 -0
  34. package/dist/async-completion-queue.js.map +1 -0
  35. package/dist/auto-fix.d.ts +174 -0
  36. package/dist/auto-fix.d.ts.map +1 -0
  37. package/dist/auto-fix.js +319 -0
  38. package/dist/auto-fix.js.map +1 -0
  39. package/dist/codebase-context.d.ts +396 -0
  40. package/dist/codebase-context.d.ts.map +1 -0
  41. package/dist/codebase-context.js +1260 -0
  42. package/dist/codebase-context.js.map +1 -0
  43. package/dist/conflict-resolver.d.ts +191 -0
  44. package/dist/conflict-resolver.d.ts.map +1 -0
  45. package/dist/conflict-resolver.js +524 -0
  46. package/dist/conflict-resolver.js.map +1 -0
  47. package/dist/constants.d.ts +52 -0
  48. package/dist/constants.d.ts.map +1 -0
  49. package/dist/constants.js +141 -0
  50. package/dist/constants.js.map +1 -0
  51. package/dist/context-budget.d.ts +435 -0
  52. package/dist/context-budget.d.ts.map +1 -0
  53. package/dist/context-budget.js +903 -0
  54. package/dist/context-budget.js.map +1 -0
  55. package/dist/context-compressor.d.ts +143 -0
  56. package/dist/context-compressor.d.ts.map +1 -0
  57. package/dist/context-compressor.js +511 -0
  58. package/dist/context-compressor.js.map +1 -0
  59. package/dist/context-manager.d.ts +112 -0
  60. package/dist/context-manager.d.ts.map +1 -0
  61. package/dist/context-manager.js +247 -0
  62. package/dist/context-manager.js.map +1 -0
  63. package/dist/continuous-reflection.d.ts +267 -0
  64. package/dist/continuous-reflection.d.ts.map +1 -0
  65. package/dist/continuous-reflection.js +338 -0
  66. package/dist/continuous-reflection.js.map +1 -0
  67. package/dist/cross-file-refactor.d.ts +352 -0
  68. package/dist/cross-file-refactor.d.ts.map +1 -0
  69. package/dist/cross-file-refactor.js +1544 -0
  70. package/dist/cross-file-refactor.js.map +1 -0
  71. package/dist/dag-orchestrator.d.ts +138 -0
  72. package/dist/dag-orchestrator.d.ts.map +1 -0
  73. package/dist/dag-orchestrator.js +379 -0
  74. package/dist/dag-orchestrator.js.map +1 -0
  75. package/dist/debate-orchestrator.d.ts +301 -0
  76. package/dist/debate-orchestrator.d.ts.map +1 -0
  77. package/dist/debate-orchestrator.js +719 -0
  78. package/dist/debate-orchestrator.js.map +1 -0
  79. package/dist/dependency-analyzer.d.ts +113 -0
  80. package/dist/dependency-analyzer.d.ts.map +1 -0
  81. package/dist/dependency-analyzer.js +444 -0
  82. package/dist/dependency-analyzer.js.map +1 -0
  83. package/dist/design-loop.d.ts +59 -0
  84. package/dist/design-loop.d.ts.map +1 -0
  85. package/dist/design-loop.js +344 -0
  86. package/dist/design-loop.js.map +1 -0
  87. package/dist/doc-intelligence.d.ts +383 -0
  88. package/dist/doc-intelligence.d.ts.map +1 -0
  89. package/dist/doc-intelligence.js +1307 -0
  90. package/dist/doc-intelligence.js.map +1 -0
  91. package/dist/dynamic-role-generator.d.ts +76 -0
  92. package/dist/dynamic-role-generator.d.ts.map +1 -0
  93. package/dist/dynamic-role-generator.js +194 -0
  94. package/dist/dynamic-role-generator.js.map +1 -0
  95. package/dist/errors.d.ts +69 -0
  96. package/dist/errors.d.ts.map +1 -0
  97. package/dist/errors.js +102 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/event-bus.d.ts +159 -0
  100. package/dist/event-bus.d.ts.map +1 -0
  101. package/dist/event-bus.js +305 -0
  102. package/dist/event-bus.js.map +1 -0
  103. package/dist/execution-engine.d.ts +425 -0
  104. package/dist/execution-engine.d.ts.map +1 -0
  105. package/dist/execution-engine.js +1555 -0
  106. package/dist/execution-engine.js.map +1 -0
  107. package/dist/git-intelligence.d.ts +306 -0
  108. package/dist/git-intelligence.d.ts.map +1 -0
  109. package/dist/git-intelligence.js +1099 -0
  110. package/dist/git-intelligence.js.map +1 -0
  111. package/dist/governor.d.ts +77 -0
  112. package/dist/governor.d.ts.map +1 -0
  113. package/dist/governor.js +161 -0
  114. package/dist/governor.js.map +1 -0
  115. package/dist/hierarchical-planner.d.ts +313 -0
  116. package/dist/hierarchical-planner.d.ts.map +1 -0
  117. package/dist/hierarchical-planner.js +981 -0
  118. package/dist/hierarchical-planner.js.map +1 -0
  119. package/dist/index.d.ts +121 -0
  120. package/dist/index.d.ts.map +1 -0
  121. package/dist/index.js +123 -0
  122. package/dist/index.js.map +1 -0
  123. package/dist/intent-inference.d.ts +103 -0
  124. package/dist/intent-inference.d.ts.map +1 -0
  125. package/dist/intent-inference.js +605 -0
  126. package/dist/intent-inference.js.map +1 -0
  127. package/dist/interrupt-manager.d.ts +143 -0
  128. package/dist/interrupt-manager.d.ts.map +1 -0
  129. package/dist/interrupt-manager.js +196 -0
  130. package/dist/interrupt-manager.js.map +1 -0
  131. package/dist/kernel.d.ts +564 -0
  132. package/dist/kernel.d.ts.map +1 -0
  133. package/dist/kernel.js +1419 -0
  134. package/dist/kernel.js.map +1 -0
  135. package/dist/language-support.d.ts +232 -0
  136. package/dist/language-support.d.ts.map +1 -0
  137. package/dist/language-support.js +1134 -0
  138. package/dist/language-support.js.map +1 -0
  139. package/dist/llm-client.d.ts +82 -0
  140. package/dist/llm-client.d.ts.map +1 -0
  141. package/dist/llm-client.js +475 -0
  142. package/dist/llm-client.js.map +1 -0
  143. package/dist/mcp-client.d.ts +232 -0
  144. package/dist/mcp-client.d.ts.map +1 -0
  145. package/dist/mcp-client.js +718 -0
  146. package/dist/mcp-client.js.map +1 -0
  147. package/dist/memory-manager.d.ts +200 -0
  148. package/dist/memory-manager.d.ts.map +1 -0
  149. package/dist/memory-manager.js +568 -0
  150. package/dist/memory-manager.js.map +1 -0
  151. package/dist/memory.d.ts +87 -0
  152. package/dist/memory.d.ts.map +1 -0
  153. package/dist/memory.js +341 -0
  154. package/dist/memory.js.map +1 -0
  155. package/dist/model-router.d.ts +245 -0
  156. package/dist/model-router.d.ts.map +1 -0
  157. package/dist/model-router.js +632 -0
  158. package/dist/model-router.js.map +1 -0
  159. package/dist/parallel-executor.d.ts +125 -0
  160. package/dist/parallel-executor.d.ts.map +1 -0
  161. package/dist/parallel-executor.js +201 -0
  162. package/dist/parallel-executor.js.map +1 -0
  163. package/dist/perf-optimizer.d.ts +212 -0
  164. package/dist/perf-optimizer.d.ts.map +1 -0
  165. package/dist/perf-optimizer.js +721 -0
  166. package/dist/perf-optimizer.js.map +1 -0
  167. package/dist/persona.d.ts +305 -0
  168. package/dist/persona.d.ts.map +1 -0
  169. package/dist/persona.js +887 -0
  170. package/dist/persona.js.map +1 -0
  171. package/dist/planner.d.ts +70 -0
  172. package/dist/planner.d.ts.map +1 -0
  173. package/dist/planner.js +264 -0
  174. package/dist/planner.js.map +1 -0
  175. package/dist/qa-pipeline.d.ts +365 -0
  176. package/dist/qa-pipeline.d.ts.map +1 -0
  177. package/dist/qa-pipeline.js +1352 -0
  178. package/dist/qa-pipeline.js.map +1 -0
  179. package/dist/reasoning-adapter.d.ts +116 -0
  180. package/dist/reasoning-adapter.d.ts.map +1 -0
  181. package/dist/reasoning-adapter.js +187 -0
  182. package/dist/reasoning-adapter.js.map +1 -0
  183. package/dist/role-registry.d.ts +55 -0
  184. package/dist/role-registry.d.ts.map +1 -0
  185. package/dist/role-registry.js +192 -0
  186. package/dist/role-registry.js.map +1 -0
  187. package/dist/sandbox-tiers.d.ts +327 -0
  188. package/dist/sandbox-tiers.d.ts.map +1 -0
  189. package/dist/sandbox-tiers.js +928 -0
  190. package/dist/sandbox-tiers.js.map +1 -0
  191. package/dist/security-scanner.d.ts +222 -0
  192. package/dist/security-scanner.d.ts.map +1 -0
  193. package/dist/security-scanner.js +1129 -0
  194. package/dist/security-scanner.js.map +1 -0
  195. package/dist/security.d.ts +93 -0
  196. package/dist/security.d.ts.map +1 -0
  197. package/dist/security.js +393 -0
  198. package/dist/security.js.map +1 -0
  199. package/dist/self-reflection.d.ts +397 -0
  200. package/dist/self-reflection.d.ts.map +1 -0
  201. package/dist/self-reflection.js +908 -0
  202. package/dist/self-reflection.js.map +1 -0
  203. package/dist/session-persistence.d.ts +191 -0
  204. package/dist/session-persistence.d.ts.map +1 -0
  205. package/dist/session-persistence.js +395 -0
  206. package/dist/session-persistence.js.map +1 -0
  207. package/dist/speculative-executor.d.ts +210 -0
  208. package/dist/speculative-executor.d.ts.map +1 -0
  209. package/dist/speculative-executor.js +618 -0
  210. package/dist/speculative-executor.js.map +1 -0
  211. package/dist/state-machine.d.ts +289 -0
  212. package/dist/state-machine.d.ts.map +1 -0
  213. package/dist/state-machine.js +695 -0
  214. package/dist/state-machine.js.map +1 -0
  215. package/dist/sub-agent.d.ts +177 -0
  216. package/dist/sub-agent.d.ts.map +1 -0
  217. package/dist/sub-agent.js +303 -0
  218. package/dist/sub-agent.js.map +1 -0
  219. package/dist/system-prompt.d.ts +26 -0
  220. package/dist/system-prompt.d.ts.map +1 -0
  221. package/dist/system-prompt.js +84 -0
  222. package/dist/system-prompt.js.map +1 -0
  223. package/dist/test-intelligence.d.ts +439 -0
  224. package/dist/test-intelligence.d.ts.map +1 -0
  225. package/dist/test-intelligence.js +1165 -0
  226. package/dist/test-intelligence.js.map +1 -0
  227. package/dist/types.d.ts +632 -0
  228. package/dist/types.d.ts.map +1 -0
  229. package/dist/types.js +6 -0
  230. package/dist/types.js.map +1 -0
  231. package/dist/vector-index.d.ts +314 -0
  232. package/dist/vector-index.d.ts.map +1 -0
  233. package/dist/vector-index.js +618 -0
  234. package/dist/vector-index.js.map +1 -0
  235. package/package.json +41 -0
@@ -0,0 +1,396 @@
1
+ /**
2
+ * @module codebase-context
3
+ * @description Codebase Context Engine — indexes TypeScript/JavaScript projects,
4
+ * extracts symbols, builds call graphs, and provides semantic search + blast radius analysis.
5
+ *
6
+ * Uses regex-based AST analysis (no ts-morph dependency). Designed for the YUAN coding agent
7
+ * to understand project structure before making changes.
8
+ */
9
+ import type { ImportRef } from "./dependency-analyzer.js";
10
+ import { LanguageSupport } from "./language-support.js";
11
+ import type { SupportedLanguage } from "./language-support.js";
12
+ /** Information about a function/method parameter. */
13
+ export interface ParamInfo {
14
+ /** Parameter name */
15
+ name: string;
16
+ /** TypeScript type annotation */
17
+ type: string;
18
+ /** Whether the parameter is optional (has `?`) */
19
+ optional: boolean;
20
+ /** Default value expression, if any */
21
+ defaultValue?: string;
22
+ }
23
+ /** A symbol extracted from source code. */
24
+ export interface SymbolInfo {
25
+ /** Symbol name */
26
+ name: string;
27
+ /** Symbol kind */
28
+ kind: "function" | "class" | "interface" | "type" | "enum" | "variable" | "method";
29
+ /** Absolute file path where the symbol is defined */
30
+ file: string;
31
+ /** Start line number (1-based) */
32
+ line: number;
33
+ /** End line number (1-based, estimated) */
34
+ endLine: number;
35
+ /** Parameters (for functions/methods) */
36
+ params?: ParamInfo[];
37
+ /** Return type annotation (for functions/methods) */
38
+ returnType?: string;
39
+ /** Superclass name (for classes) */
40
+ extends?: string;
41
+ /** Implemented interfaces (for classes) */
42
+ implements?: string[];
43
+ /** Members (for classes/interfaces) */
44
+ members?: SymbolInfo[];
45
+ /** Whether the symbol is exported */
46
+ exported: boolean;
47
+ /** Whether this is a default export */
48
+ isDefault: boolean;
49
+ /** Whether the function/method is async */
50
+ isAsync: boolean;
51
+ /** JSDoc comment, if present */
52
+ jsdoc?: string;
53
+ }
54
+ /** A directed edge in the call graph. */
55
+ export interface CallEdge {
56
+ /** Caller identifier: "file:functionName" */
57
+ caller: string;
58
+ /** Callee identifier: "file:functionName" or "external:moduleName" */
59
+ callee: string;
60
+ /** Line number of the call site */
61
+ line: number;
62
+ /** Absolute file path containing the call */
63
+ file: string;
64
+ }
65
+ /** Complete analysis of a single source file. */
66
+ export interface FileAnalysis {
67
+ /** Absolute file path */
68
+ file: string;
69
+ /** Detected language */
70
+ language: "typescript" | "javascript" | SupportedLanguage;
71
+ /** Symbols defined in this file */
72
+ symbols: SymbolInfo[];
73
+ /** Import references */
74
+ imports: ImportRef[];
75
+ /** Exported symbol names */
76
+ exports: string[];
77
+ /** Call edges originating from this file */
78
+ callEdges: CallEdge[];
79
+ /** Complexity metrics */
80
+ complexity: {
81
+ /** Cyclomatic complexity estimate */
82
+ cyclomatic: number;
83
+ /** Cognitive complexity (nesting-aware) */
84
+ cognitive: number;
85
+ /** Lines of code (non-blank, non-comment) */
86
+ loc: number;
87
+ /** Blank line count */
88
+ blankLines: number;
89
+ /** Comment line count */
90
+ commentLines: number;
91
+ /** Number of import dependencies */
92
+ dependencies: number;
93
+ };
94
+ }
95
+ /** Full codebase index — the primary data structure. */
96
+ export interface CodebaseIndex {
97
+ /** Per-file analysis results */
98
+ files: Map<string, FileAnalysis>;
99
+ /** Symbol name → all matching SymbolInfo across the codebase */
100
+ symbolTable: Map<string, SymbolInfo[]>;
101
+ /** All call edges across the codebase */
102
+ callGraph: CallEdge[];
103
+ /** Epoch ms when the index was last built */
104
+ lastIndexedAt: number;
105
+ /** Total number of indexed files */
106
+ totalFiles: number;
107
+ /** Total number of extracted symbols */
108
+ totalSymbols: number;
109
+ }
110
+ /** A search result from semantic symbol search. */
111
+ export interface SemanticSearchResult {
112
+ /** Matched symbol */
113
+ symbol: SymbolInfo;
114
+ /** File containing the symbol */
115
+ file: string;
116
+ /** Relevance score (0–1) */
117
+ relevance: number;
118
+ /** Code snippet around the symbol */
119
+ snippet: string;
120
+ }
121
+ /** Blast radius analysis for a file change. */
122
+ export interface BlastRadiusResult {
123
+ /** Files that directly import the changed file */
124
+ directDependents: string[];
125
+ /** Files transitively affected */
126
+ transitiveDependents: string[];
127
+ /** Test files that may be affected */
128
+ affectedTests: string[];
129
+ /** Exported symbols from the changed file */
130
+ affectedExports: string[];
131
+ /** Overall risk assessment */
132
+ riskLevel: "low" | "medium" | "high";
133
+ }
134
+ /**
135
+ * Codebase Context Engine — indexes TypeScript/JavaScript projects and provides
136
+ * symbol lookup, call graph analysis, blast radius estimation, and semantic search.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const ctx = new CodebaseContext("/path/to/project");
141
+ * await ctx.buildIndex();
142
+ *
143
+ * const symbols = ctx.findSymbol("handleRequest");
144
+ * const blast = ctx.getBlastRadius("/path/to/project/src/router.ts");
145
+ * const results = ctx.searchSymbols("auth middleware", 5);
146
+ * ```
147
+ */
148
+ export declare class CodebaseContext {
149
+ private index;
150
+ private projectPath;
151
+ /** Cached file contents for snippet extraction */
152
+ private fileContents;
153
+ /** Reverse dependency map (file → files that import it) */
154
+ private reverseDepMap;
155
+ /** Optional multi-language support for non-TS/JS files */
156
+ private languageSupport;
157
+ constructor(projectPath: string, languageSupport?: LanguageSupport);
158
+ /**
159
+ * Build a full index of the project. Scans all source files,
160
+ * extracts symbols, builds call graph, and creates the symbol table.
161
+ *
162
+ * @returns The complete codebase index
163
+ */
164
+ buildIndex(): Promise<CodebaseIndex>;
165
+ /**
166
+ * Incrementally update the index for a single changed file.
167
+ * Re-analyzes only that file and updates the symbol table.
168
+ *
169
+ * @param filePath - Absolute path of the changed file
170
+ */
171
+ updateFile(filePath: string): Promise<void>;
172
+ /**
173
+ * Remove a file from the index (e.g., after deletion).
174
+ *
175
+ * @param filePath - Absolute path of the removed file
176
+ */
177
+ removeFile(filePath: string): void;
178
+ /**
179
+ * Find all symbols matching the given name across the codebase.
180
+ *
181
+ * @param name - Symbol name to search for (exact match)
182
+ * @returns Array of matching SymbolInfo
183
+ */
184
+ findSymbol(name: string): SymbolInfo[];
185
+ /**
186
+ * Find the symbol defined at a specific file and line.
187
+ *
188
+ * @param file - Absolute file path
189
+ * @param line - Line number (1-based)
190
+ * @returns The symbol at that location, or undefined
191
+ */
192
+ findSymbolAt(file: string, line: number): SymbolInfo | undefined;
193
+ /**
194
+ * Find all symbols of a given kind across the codebase.
195
+ *
196
+ * @param kind - Symbol kind to filter by
197
+ * @returns Array of matching SymbolInfo
198
+ */
199
+ findSymbolsByKind(kind: SymbolInfo["kind"]): SymbolInfo[];
200
+ /**
201
+ * Find all exported symbols in a specific file.
202
+ *
203
+ * @param file - Absolute file path
204
+ * @returns Array of exported SymbolInfo
205
+ */
206
+ findExportedSymbols(file: string): SymbolInfo[];
207
+ /**
208
+ * Get all call edges where the given symbol is the callee.
209
+ *
210
+ * @param symbolName - Name of the called function/method
211
+ * @param file - Optional file path to narrow the search
212
+ * @returns Call edges targeting this symbol
213
+ */
214
+ getCallersOf(symbolName: string, file?: string): CallEdge[];
215
+ /**
216
+ * Get all call edges originating from the given symbol.
217
+ *
218
+ * @param symbolName - Name of the calling function/method
219
+ * @param file - Optional file path to narrow the search
220
+ * @returns Call edges originating from this symbol
221
+ */
222
+ getCalleesOf(symbolName: string, file?: string): CallEdge[];
223
+ /**
224
+ * Calculate the blast radius of changing a file — which files are affected,
225
+ * which tests may break, and what's the risk level.
226
+ *
227
+ * @param file - Absolute file path being changed
228
+ * @returns Blast radius analysis
229
+ */
230
+ getBlastRadius(file: string): BlastRadiusResult;
231
+ /**
232
+ * Search symbols by a query string using token-based fuzzy matching.
233
+ * Splits the query into tokens and scores symbols by match count against
234
+ * name, kind, file path, and JSDoc.
235
+ *
236
+ * @param query - Search query (space-separated tokens)
237
+ * @param limit - Maximum results to return (default 10)
238
+ * @returns Ranked search results with relevance scores
239
+ */
240
+ searchSymbols(query: string, limit?: number): SemanticSearchResult[];
241
+ /**
242
+ * Search for symbols whose return type or type annotation matches a pattern.
243
+ *
244
+ * @param typePattern - Regex pattern to match against types
245
+ * @returns Matching symbols
246
+ */
247
+ searchByType(typePattern: string): SymbolInfo[];
248
+ /**
249
+ * Get the analysis for a specific file.
250
+ *
251
+ * @param file - Absolute file path
252
+ * @returns FileAnalysis or undefined if not indexed
253
+ */
254
+ getFileAnalysis(file: string): FileAnalysis | undefined;
255
+ /**
256
+ * Get files exceeding a cyclomatic complexity threshold.
257
+ *
258
+ * @param threshold - Minimum cyclomatic complexity (default 20)
259
+ * @returns Files exceeding the threshold, sorted by complexity descending
260
+ */
261
+ getComplexFiles(threshold?: number): FileAnalysis[];
262
+ /**
263
+ * Identify hotspots — files with high complexity AND many dependents.
264
+ *
265
+ * @returns Hotspot entries sorted by combined score descending
266
+ */
267
+ getHotspots(): {
268
+ file: string;
269
+ complexity: number;
270
+ dependencies: number;
271
+ }[];
272
+ /**
273
+ * Get summary statistics for the indexed codebase.
274
+ *
275
+ * @returns Aggregate stats
276
+ */
277
+ getStats(): {
278
+ totalFiles: number;
279
+ totalSymbols: number;
280
+ avgComplexity: number;
281
+ };
282
+ /**
283
+ * Recursively collect all source files under a directory,
284
+ * skipping excluded directories.
285
+ */
286
+ private collectSourceFiles;
287
+ /**
288
+ * Check if a file is a supported source file.
289
+ * Uses LanguageSupport for multi-language detection when available,
290
+ * otherwise falls back to built-in TS/JS extensions.
291
+ */
292
+ private isSupportedSourceFile;
293
+ /**
294
+ * Analyze a single source file — extract symbols, imports, exports,
295
+ * and compute complexity metrics.
296
+ *
297
+ * When LanguageSupport is available and the file is not TS/JS,
298
+ * uses language-specific patterns for symbol extraction.
299
+ */
300
+ private analyzeFile;
301
+ /**
302
+ * Extract all symbol definitions from file content using regex patterns.
303
+ */
304
+ private extractSymbols;
305
+ /**
306
+ * Extract symbols from non-TS/JS files using LanguageSupport patterns.
307
+ * Provides basic function and class extraction for any language
308
+ * that LanguageSupport has patterns for.
309
+ *
310
+ * Falls back to an empty array if patterns produce no matches — this is
311
+ * safe because the caller only reaches here for non-TS/JS files.
312
+ */
313
+ private extractSymbolsWithLanguageSupport;
314
+ /**
315
+ * Extract class method members from a class body.
316
+ */
317
+ private extractClassMembers;
318
+ /**
319
+ * Extract import references from file content.
320
+ */
321
+ private extractImports;
322
+ /**
323
+ * Extract exported symbol names from file content.
324
+ */
325
+ private extractExports;
326
+ /**
327
+ * Extract call edges from function bodies.
328
+ * Maps each function's body to the functions it calls.
329
+ */
330
+ private extractCallEdges;
331
+ /**
332
+ * Compute complexity metrics for file content.
333
+ */
334
+ private computeComplexity;
335
+ /**
336
+ * Compute cognitive complexity — increments with nesting depth.
337
+ */
338
+ private computeCognitiveComplexity;
339
+ /**
340
+ * Build the symbol table from all file analyses.
341
+ * Maps symbol name → all SymbolInfo across the codebase.
342
+ */
343
+ private buildSymbolTable;
344
+ /**
345
+ * Build the global call graph from per-file call edges.
346
+ */
347
+ private buildCallGraph;
348
+ /**
349
+ * Build the reverse dependency map (file → files that import it).
350
+ * Resolves relative import paths to absolute file paths.
351
+ */
352
+ private buildReverseDependencyMap;
353
+ /**
354
+ * Resolve a relative import specifier to an absolute file path.
355
+ */
356
+ private resolveImportPath;
357
+ /**
358
+ * Get 1-based line number for a character offset within content.
359
+ */
360
+ private getLineNumber;
361
+ /**
362
+ * Estimate the end line of a function/arrow function by scanning for matching braces.
363
+ */
364
+ private estimateEndLine;
365
+ /**
366
+ * Estimate the end line of a brace-delimited block (class, function, enum, interface).
367
+ * Tracks `{` and `}` to find the matching close brace.
368
+ */
369
+ private estimateBlockEnd;
370
+ /**
371
+ * Estimate the end line of a type alias (ends with `;` at depth 0).
372
+ */
373
+ private estimateTypeEnd;
374
+ /**
375
+ * Parse a raw parameter string into ParamInfo array.
376
+ * Handles `name: Type`, `name?: Type`, `name = defaultVal`.
377
+ */
378
+ private parseParams;
379
+ /**
380
+ * Split parameter string by commas, respecting nested angle brackets and parentheses.
381
+ */
382
+ private splitParams;
383
+ /**
384
+ * Clean a JSDoc comment — strip leading `*` and `/** ... * /`.
385
+ */
386
+ private cleanJsdoc;
387
+ /**
388
+ * Score a symbol against search tokens for relevance ranking.
389
+ */
390
+ private scoreSymbol;
391
+ /**
392
+ * Get a code snippet around a symbol for search result display.
393
+ */
394
+ private getSnippet;
395
+ }
396
+ //# sourceMappingURL=codebase-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codebase-context.d.ts","sourceRoot":"","sources":["../src/codebase-context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,uBAAuB,CAAC;AAIjF,qDAAqD;AACrD,MAAM,WAAW,SAAS;IACxB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,kBAAkB;IAClB,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