@easbot/codebase 0.3.27 → 0.3.29
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/README.en.md +75 -74
- package/README.md +75 -74
- package/dist/chunks/chunk-23YR2LAM.cjs +1 -0
- package/dist/chunks/chunk-3RVRPGJC.mjs +1 -0
- package/dist/chunks/chunk-3UGOMK4F.cjs +62 -0
- package/dist/chunks/chunk-4XKCGYFF.mjs +158 -0
- package/dist/chunks/chunk-5M2N7JFP.cjs +1 -0
- package/dist/chunks/chunk-A4YJ5ZVE.cjs +203 -0
- package/dist/chunks/chunk-J7AIRI5N.mjs +203 -0
- package/dist/chunks/chunk-LLO6DDXU.mjs +48 -0
- package/dist/chunks/{chunk-GWCRGM4D.mjs → chunk-LQVKXVBS.mjs} +3 -3
- package/dist/chunks/chunk-LZLPJAB6.mjs +62 -0
- package/dist/chunks/chunk-MZHDSOD7.mjs +1 -0
- package/dist/chunks/{chunk-VPWALTY7.cjs → chunk-OGTQ7MWV.cjs} +3 -3
- package/dist/chunks/chunk-V6PHJ4DG.cjs +48 -0
- package/dist/chunks/chunk-YJK7F6NJ.cjs +158 -0
- package/dist/chunks/cli-handler-B7WPIZRE.cjs +1 -0
- package/dist/chunks/cli-handler-EJX27R4Q.mjs +1 -0
- package/dist/chunks/code-base-FSOSU46G.mjs +1 -0
- package/dist/chunks/code-base-OWYMNEQG.cjs +1 -0
- package/dist/chunks/database-manager-7D7NDXJK.mjs +1 -0
- package/dist/chunks/database-manager-X4DMAUWC.cjs +1 -0
- package/dist/chunks/file-watcher-E2JROVI7.cjs +1 -0
- package/dist/chunks/file-watcher-KSLBUUPP.mjs +1 -0
- package/dist/chunks/{interfaces-DPFLQBQ6.mjs → interfaces-S7TJGWWS.mjs} +1 -1
- package/dist/chunks/interfaces-URUTHSR2.cjs +1 -0
- package/dist/chunks/llm-R2ZLKZDO.cjs +1 -0
- package/dist/chunks/llm-U57HNTZO.mjs +1 -0
- package/dist/chunks/stdio-server-DFKFFRSM.cjs +30 -0
- package/dist/chunks/stdio-server-NV5YAXJD.mjs +30 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1098 -80
- package/dist/index.d.ts +1098 -80
- package/dist/index.mjs +1 -1
- package/package.json +9 -9
- package/dist/chunks/chunk-34CU2EU4.mjs +0 -1
- package/dist/chunks/chunk-4HJ7RFP7.cjs +0 -1
- package/dist/chunks/chunk-4TCNRCEK.mjs +0 -48
- package/dist/chunks/chunk-7CL37IYG.mjs +0 -158
- package/dist/chunks/chunk-7N7UVPKB.cjs +0 -48
- package/dist/chunks/chunk-ICEJ23S3.mjs +0 -203
- package/dist/chunks/chunk-JCJFUUU2.cjs +0 -203
- package/dist/chunks/chunk-JVX6PHPN.cjs +0 -1
- package/dist/chunks/chunk-TGCR6O3S.cjs +0 -62
- package/dist/chunks/chunk-UHNJOT5S.cjs +0 -158
- package/dist/chunks/chunk-WRM2FP4O.mjs +0 -62
- package/dist/chunks/chunk-ZPEE2LSX.mjs +0 -1
- package/dist/chunks/cli-handler-DXLDGJFQ.mjs +0 -1
- package/dist/chunks/cli-handler-KKNIISIE.cjs +0 -1
- package/dist/chunks/code-base-BFLIOZXA.cjs +0 -1
- package/dist/chunks/code-base-DMVLROV6.mjs +0 -1
- package/dist/chunks/database-manager-GT3LOQUV.cjs +0 -1
- package/dist/chunks/database-manager-N5WLNG3F.mjs +0 -1
- package/dist/chunks/file-watcher-QS442D52.cjs +0 -1
- package/dist/chunks/file-watcher-X56TEWNY.mjs +0 -1
- package/dist/chunks/interfaces-YX56SVRQ.cjs +0 -1
- package/dist/chunks/llm-ADBGTSCV.mjs +0 -1
- package/dist/chunks/llm-BDMNIGOH.cjs +0 -1
- package/dist/chunks/stdio-server-4X7YFQA2.mjs +0 -30
- package/dist/chunks/stdio-server-5UQVBBZP.cjs +0 -30
package/README.en.md
CHANGED
|
@@ -6,8 +6,7 @@ Code Knowledge Graph SDK - A code indexing and querying system based on the Prop
|
|
|
6
6
|
|
|
7
7
|
## Version
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
10
|
-
|
|
9
|
+
v0.3.29
|
|
11
10
|
## Features
|
|
12
11
|
|
|
13
12
|
- **Property Graph Model**: Store code entities and their relationships using nodes and edges
|
|
@@ -158,13 +157,13 @@ $ easbot codebase doctor
|
|
|
158
157
|
|
|
159
158
|
### Key Fields
|
|
160
159
|
|
|
161
|
-
| Field
|
|
162
|
-
|
|
163
|
-
| `LLM.initialized`
|
|
164
|
-
| `LLM.capabilities`
|
|
165
|
-
| `Vector enabled`
|
|
166
|
-
| `Embedding dims`
|
|
167
|
-
| `embedding_dims_consistency` | Doctor check #9: compares meta / probe / config dimensions for consistency
|
|
160
|
+
| Field | Description |
|
|
161
|
+
| ---------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
162
|
+
| `LLM.initialized` | Whether LLM is initialized (valid config + reachable) |
|
|
163
|
+
| `LLM.capabilities` | Three capabilities: `embedding` / `graphLlm` / `rerankLlm`, each shows model name or ✗ |
|
|
164
|
+
| `Vector enabled` | Whether vector index is enabled |
|
|
165
|
+
| `Embedding dims` | **Probed** embedding dimension (not just from config), probed at status end and written back to meta table |
|
|
166
|
+
| `embedding_dims_consistency` | Doctor check #9: compares meta / probe / config dimensions for consistency |
|
|
168
167
|
|
|
169
168
|
### JSON Output (`--json`)
|
|
170
169
|
|
|
@@ -204,52 +203,52 @@ Main class providing complete code knowledge graph functionality.
|
|
|
204
203
|
|
|
205
204
|
```typescript
|
|
206
205
|
interface CodeKnowledgeGraphConfig {
|
|
207
|
-
workspaceDir: string;
|
|
206
|
+
workspaceDir: string; // Workspace directory
|
|
208
207
|
database?: {
|
|
209
|
-
path: string;
|
|
210
|
-
walMode?: boolean;
|
|
208
|
+
path: string; // Database path
|
|
209
|
+
walMode?: boolean; // WAL mode
|
|
211
210
|
};
|
|
212
211
|
parser?: {
|
|
213
|
-
languages?: Language[];
|
|
214
|
-
lazyLoad?: boolean;
|
|
212
|
+
languages?: Language[]; // Supported languages
|
|
213
|
+
lazyLoad?: boolean; // Lazy loading
|
|
215
214
|
};
|
|
216
215
|
indexer?: {
|
|
217
|
-
batchSize: number;
|
|
218
|
-
ignorePatterns: string[];
|
|
219
|
-
incremental: boolean;
|
|
216
|
+
batchSize: number; // Batch size
|
|
217
|
+
ignorePatterns: string[]; // Ignore patterns
|
|
218
|
+
incremental: boolean; // Incremental updates
|
|
220
219
|
};
|
|
221
220
|
}
|
|
222
221
|
```
|
|
223
222
|
|
|
224
223
|
#### Main Methods
|
|
225
224
|
|
|
226
|
-
| Method
|
|
227
|
-
|
|
228
|
-
| `initialize()`
|
|
229
|
-
| `indexFile(path)`
|
|
230
|
-
| `indexDirectory(dir?)`
|
|
231
|
-
| `sync()`
|
|
232
|
-
| `search(query, options?)`
|
|
233
|
-
| `queryNodes(filter)`
|
|
234
|
-
| `queryEdges(filter)`
|
|
235
|
-
| `queryNeighbors(nodeId, options?)` | Query neighbors
|
|
236
|
-
| `queryCallGraph(nodeId, depth?)`
|
|
237
|
-
| `queryInheritance(nodeId)`
|
|
238
|
-
| `getStatus()`
|
|
239
|
-
| `healthCheck()`
|
|
240
|
-
| `close()`
|
|
225
|
+
| Method | Description |
|
|
226
|
+
| ---------------------------------- | ----------------- |
|
|
227
|
+
| `initialize()` | Initialize graph |
|
|
228
|
+
| `indexFile(path)` | Index single file |
|
|
229
|
+
| `indexDirectory(dir?)` | Index directory |
|
|
230
|
+
| `sync()` | Incremental sync |
|
|
231
|
+
| `search(query, options?)` | Hybrid search |
|
|
232
|
+
| `queryNodes(filter)` | Query nodes |
|
|
233
|
+
| `queryEdges(filter)` | Query edges |
|
|
234
|
+
| `queryNeighbors(nodeId, options?)` | Query neighbors |
|
|
235
|
+
| `queryCallGraph(nodeId, depth?)` | Query call graph |
|
|
236
|
+
| `queryInheritance(nodeId)` | Query inheritance |
|
|
237
|
+
| `getStatus()` | Get status |
|
|
238
|
+
| `healthCheck()` | Health check |
|
|
239
|
+
| `close()` | Close graph |
|
|
241
240
|
|
|
242
241
|
### Search Options
|
|
243
242
|
|
|
244
243
|
```typescript
|
|
245
244
|
interface SearchOptions {
|
|
246
|
-
maxResults?: number;
|
|
247
|
-
minScore?: number;
|
|
248
|
-
language?: Language;
|
|
249
|
-
filePath?: string;
|
|
250
|
-
astType?: string;
|
|
251
|
-
enableFts?: boolean;
|
|
252
|
-
ftsWeight?: number;
|
|
245
|
+
maxResults?: number; // Max results
|
|
246
|
+
minScore?: number; // Min score
|
|
247
|
+
language?: Language; // Language filter
|
|
248
|
+
filePath?: string; // File path filter
|
|
249
|
+
astType?: string; // AST type filter
|
|
250
|
+
enableFts?: boolean; // Enable FTS
|
|
251
|
+
ftsWeight?: number; // FTS weight
|
|
253
252
|
}
|
|
254
253
|
```
|
|
255
254
|
|
|
@@ -259,11 +258,11 @@ The 5 graph operations (`node` / `callers` / `callees` / `impact` / `context`) s
|
|
|
259
258
|
|
|
260
259
|
### 3-tier SQL fallback (priority order)
|
|
261
260
|
|
|
262
|
-
| Tier
|
|
263
|
-
|
|
264
|
-
| 1. **exact**
|
|
265
|
-
| 2. **qualified** | `name` contains target string (fallback)
|
|
266
|
-
| 3. **substring** | When tier 1-2 return 0 + `file`/`kind` filter | `WHERE name LIKE %?% AND file_path/kind` | Extreme edge cases (e.g., typo in class name)
|
|
261
|
+
| Tier | Match Mode | SQL Condition | Use Case |
|
|
262
|
+
| ---------------- | --------------------------------------------- | ---------------------------------------- | ----------------------------------------------------------------------- |
|
|
263
|
+
| 1. **exact** | `name` field equality | `WHERE name = ?` | Short class names / namespaces / fully qualified names (with `@<line>`) |
|
|
264
|
+
| 2. **qualified** | `name` contains target string (fallback) | `WHERE name LIKE %?%` | Short method names / class name prefix mismatch |
|
|
265
|
+
| 3. **substring** | When tier 1-2 return 0 + `file`/`kind` filter | `WHERE name LIKE %?% AND file_path/kind` | Extreme edge cases (e.g., typo in class name) |
|
|
267
266
|
|
|
268
267
|
### Recommended LLM Workflow
|
|
269
268
|
|
|
@@ -285,7 +284,9 @@ await service.callers(ctx, { name: 'AuthService', file: 'auth-service.ts' });
|
|
|
285
284
|
await service.callers(ctx, { name: 'AuthService.login@20' });
|
|
286
285
|
|
|
287
286
|
// ✅ Recommended: nodeId direct lookup (zero ambiguity)
|
|
288
|
-
await service.callers(ctx, {
|
|
287
|
+
await service.callers(ctx, {
|
|
288
|
+
nodeId: 'ts:src/auth-service.ts:method_definition:AuthService.login@20',
|
|
289
|
+
});
|
|
289
290
|
|
|
290
291
|
// ❌ Anti-pattern: short class name without file
|
|
291
292
|
await service.callers(ctx, { name: 'AuthService' });
|
|
@@ -294,47 +295,47 @@ await service.callers(ctx, { name: 'AuthService' });
|
|
|
294
295
|
|
|
295
296
|
### Error Handling
|
|
296
297
|
|
|
297
|
-
| Error
|
|
298
|
-
|
|
299
|
-
| `NotFoundError`
|
|
298
|
+
| Error | Trigger | Fix |
|
|
299
|
+
| ---------------- | ------------------------------------------ | ---------------------------------------------------------------------- |
|
|
300
|
+
| `NotFoundError` | 0 candidates | Check `name` spelling / typo / non-existent symbol |
|
|
300
301
|
| `AmbiguousError` | ≥2 candidates and no `file` disambiguation | Pick one `name + file` from the returned `candidates[]` list and retry |
|
|
301
302
|
|
|
302
303
|
## Data Model
|
|
303
304
|
|
|
304
305
|
### Node
|
|
305
306
|
|
|
306
|
-
| Field
|
|
307
|
-
|
|
308
|
-
| id
|
|
309
|
-
| name
|
|
310
|
-
| ast_type
|
|
311
|
-
| language
|
|
312
|
-
| file_path
|
|
313
|
-
| start_line | number | Start line
|
|
314
|
-
| start_col
|
|
315
|
-
| end_line
|
|
316
|
-
| end_col
|
|
317
|
-
| text
|
|
307
|
+
| Field | Type | Description |
|
|
308
|
+
| ---------- | ------ | ----------------- |
|
|
309
|
+
| id | string | Unique identifier |
|
|
310
|
+
| name | string | Name |
|
|
311
|
+
| ast_type | string | AST type |
|
|
312
|
+
| language | string | Language |
|
|
313
|
+
| file_path | string | File path |
|
|
314
|
+
| start_line | number | Start line |
|
|
315
|
+
| start_col | number | Start column |
|
|
316
|
+
| end_line | number | End line |
|
|
317
|
+
| end_col | number | End column |
|
|
318
|
+
| text | string | Code text |
|
|
318
319
|
|
|
319
320
|
### Edge
|
|
320
321
|
|
|
321
|
-
| Field
|
|
322
|
-
|
|
323
|
-
| id
|
|
324
|
-
| source
|
|
325
|
-
| target
|
|
326
|
-
| relation | string | Relation type
|
|
322
|
+
| Field | Type | Description |
|
|
323
|
+
| -------- | ------ | ----------------- |
|
|
324
|
+
| id | string | Unique identifier |
|
|
325
|
+
| source | string | Source node ID |
|
|
326
|
+
| target | string | Target node ID |
|
|
327
|
+
| relation | string | Relation type |
|
|
327
328
|
|
|
328
329
|
### Relation Types
|
|
329
330
|
|
|
330
|
-
| Relation
|
|
331
|
-
|
|
332
|
-
| CONTAINS
|
|
333
|
-
| CALLS
|
|
334
|
-
| INHERITS_FROM | Class inheritance
|
|
335
|
-
| IMPLEMENTS
|
|
336
|
-
| IMPORTS
|
|
337
|
-
| REFERENCES
|
|
331
|
+
| Relation | Description |
|
|
332
|
+
| ------------- | ----------------------------- |
|
|
333
|
+
| CONTAINS | Parent-child AST relationship |
|
|
334
|
+
| CALLS | Function call relationship |
|
|
335
|
+
| INHERITS_FROM | Class inheritance |
|
|
336
|
+
| IMPLEMENTS | Interface implementation |
|
|
337
|
+
| IMPORTS | Module import |
|
|
338
|
+
| REFERENCES | Variable/identifier reference |
|
|
338
339
|
|
|
339
340
|
## Architecture
|
|
340
341
|
|
package/README.md
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## 版本
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
10
|
-
|
|
9
|
+
v0.3.29
|
|
11
10
|
## 特性
|
|
12
11
|
|
|
13
12
|
- **Property Graph 模型**: 使用节点和边存储代码实体及其关系
|
|
@@ -156,13 +155,13 @@ $ easbot codebase doctor
|
|
|
156
155
|
|
|
157
156
|
### 关键字段说明
|
|
158
157
|
|
|
159
|
-
| 字段
|
|
160
|
-
|
|
161
|
-
| `LLM.initialized`
|
|
162
|
-
| `LLM.capabilities`
|
|
163
|
-
| `Vector enabled`
|
|
164
|
-
| `Embedding dims`
|
|
165
|
-
| `embedding_dims_consistency` | doctor 第 9 项检查:对比 meta / probe / config 三方维度是否一致
|
|
158
|
+
| 字段 | 说明 |
|
|
159
|
+
| ---------------------------- | ----------------------------------------------------------------------- |
|
|
160
|
+
| `LLM.initialized` | LLM 是否已初始化(配置有效且可达) |
|
|
161
|
+
| `LLM.capabilities` | 三大能力:`embedding` / `graphLlm` / `rerankLlm`,各显示模型名或 ✗ |
|
|
162
|
+
| `Vector enabled` | 向量索引是否启用 |
|
|
163
|
+
| `Embedding dims` | **实测** embedding 维度(非仅读 config),status 末尾探测并回填 meta 表 |
|
|
164
|
+
| `embedding_dims_consistency` | doctor 第 9 项检查:对比 meta / probe / config 三方维度是否一致 |
|
|
166
165
|
|
|
167
166
|
### JSON 输出(`--json`)
|
|
168
167
|
|
|
@@ -238,52 +237,52 @@ await graph.close();
|
|
|
238
237
|
|
|
239
238
|
```typescript
|
|
240
239
|
interface CodeKnowledgeGraphConfig {
|
|
241
|
-
workspaceDir: string;
|
|
240
|
+
workspaceDir: string; // 工作区目录
|
|
242
241
|
database?: {
|
|
243
|
-
path: string;
|
|
244
|
-
walMode?: boolean;
|
|
242
|
+
path: string; // 数据库路径
|
|
243
|
+
walMode?: boolean; // WAL 模式
|
|
245
244
|
};
|
|
246
245
|
parser?: {
|
|
247
|
-
languages?: Language[];
|
|
248
|
-
lazyLoad?: boolean;
|
|
246
|
+
languages?: Language[]; // 支持的语言
|
|
247
|
+
lazyLoad?: boolean; // 延迟加载
|
|
249
248
|
};
|
|
250
249
|
indexer?: {
|
|
251
|
-
batchSize: number;
|
|
252
|
-
ignorePatterns: string[];
|
|
253
|
-
incremental: boolean;
|
|
250
|
+
batchSize: number; // 批处理大小
|
|
251
|
+
ignorePatterns: string[]; // 忽略模式
|
|
252
|
+
incremental: boolean; // 增量更新
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
255
|
```
|
|
257
256
|
|
|
258
257
|
#### 主要方法
|
|
259
258
|
|
|
260
|
-
| 方法
|
|
261
|
-
|
|
262
|
-
| `initialize()`
|
|
263
|
-
| `indexFile(path)`
|
|
264
|
-
| `indexDirectory(dir?)`
|
|
265
|
-
| `sync()`
|
|
266
|
-
| `search(query, options?)`
|
|
267
|
-
| `queryNodes(filter)`
|
|
268
|
-
| `queryEdges(filter)`
|
|
269
|
-
| `queryNeighbors(nodeId, options?)` | 查询邻居
|
|
270
|
-
| `queryCallGraph(nodeId, depth?)`
|
|
271
|
-
| `queryInheritance(nodeId)`
|
|
272
|
-
| `getStatus()`
|
|
273
|
-
| `healthCheck()`
|
|
274
|
-
| `close()`
|
|
259
|
+
| 方法 | 说明 |
|
|
260
|
+
| ---------------------------------- | ------------ |
|
|
261
|
+
| `initialize()` | 初始化图谱 |
|
|
262
|
+
| `indexFile(path)` | 索引单个文件 |
|
|
263
|
+
| `indexDirectory(dir?)` | 索引目录 |
|
|
264
|
+
| `sync()` | 增量同步 |
|
|
265
|
+
| `search(query, options?)` | 混合搜索 |
|
|
266
|
+
| `queryNodes(filter)` | 查询节点 |
|
|
267
|
+
| `queryEdges(filter)` | 查询边 |
|
|
268
|
+
| `queryNeighbors(nodeId, options?)` | 查询邻居 |
|
|
269
|
+
| `queryCallGraph(nodeId, depth?)` | 查询调用图 |
|
|
270
|
+
| `queryInheritance(nodeId)` | 查询继承关系 |
|
|
271
|
+
| `getStatus()` | 获取状态 |
|
|
272
|
+
| `healthCheck()` | 健康检查 |
|
|
273
|
+
| `close()` | 关闭图谱 |
|
|
275
274
|
|
|
276
275
|
### 搜索选项
|
|
277
276
|
|
|
278
277
|
```typescript
|
|
279
278
|
interface SearchOptions {
|
|
280
|
-
maxResults?: number;
|
|
281
|
-
minScore?: number;
|
|
282
|
-
language?: Language;
|
|
283
|
-
filePath?: string;
|
|
284
|
-
astType?: string;
|
|
285
|
-
enableFts?: boolean;
|
|
286
|
-
ftsWeight?: number;
|
|
279
|
+
maxResults?: number; // 最大结果数
|
|
280
|
+
minScore?: number; // 最小分数
|
|
281
|
+
language?: Language; // 语言过滤
|
|
282
|
+
filePath?: string; // 文件路径过滤
|
|
283
|
+
astType?: string; // AST 类型过滤
|
|
284
|
+
enableFts?: boolean; // 启用 FTS
|
|
285
|
+
ftsWeight?: number; // FTS 权重
|
|
287
286
|
}
|
|
288
287
|
```
|
|
289
288
|
|
|
@@ -293,11 +292,11 @@ interface SearchOptions {
|
|
|
293
292
|
|
|
294
293
|
### 3 层 SQL fallback(按优先级)
|
|
295
294
|
|
|
296
|
-
| 层级
|
|
297
|
-
|
|
298
|
-
| 1. **exact**
|
|
299
|
-
| 2. **qualified** | `name` 含目标字符串(兜底)
|
|
300
|
-
| 3. **substring** | 前两层全空 + `file`/`kind` 过滤 | `WHERE name LIKE %?% AND file_path/kind` | 极端罕见场景(如类名拼写模糊)
|
|
295
|
+
| 层级 | 匹配模式 | SQL 条件 | 适用场景 |
|
|
296
|
+
| ---------------- | ------------------------------- | ---------------------------------------- | ----------------------------------------------- |
|
|
297
|
+
| 1. **exact** | `name` 字段全等 | `WHERE name = ?` | 短类名 / namespace / 完全限定名(含 `@<line>`) |
|
|
298
|
+
| 2. **qualified** | `name` 含目标字符串(兜底) | `WHERE name LIKE %?%` | 短方法名 / 类名前缀不匹配 |
|
|
299
|
+
| 3. **substring** | 前两层全空 + `file`/`kind` 过滤 | `WHERE name LIKE %?% AND file_path/kind` | 极端罕见场景(如类名拼写模糊) |
|
|
301
300
|
|
|
302
301
|
### LLM 推荐用法(workflow)
|
|
303
302
|
|
|
@@ -319,7 +318,9 @@ await service.callers(ctx, { name: 'AuthService', file: 'auth-service.ts' });
|
|
|
319
318
|
await service.callers(ctx, { name: 'AuthService.login@20' });
|
|
320
319
|
|
|
321
320
|
// ✅ 推荐:nodeId 直接定位(零歧义)
|
|
322
|
-
await service.callers(ctx, {
|
|
321
|
+
await service.callers(ctx, {
|
|
322
|
+
nodeId: 'ts:src/auth-service.ts:method_definition:AuthService.login@20',
|
|
323
|
+
});
|
|
323
324
|
|
|
324
325
|
// ❌ 反模式:短类名 + 无 file
|
|
325
326
|
await service.callers(ctx, { name: 'AuthService' });
|
|
@@ -328,47 +329,47 @@ await service.callers(ctx, { name: 'AuthService' });
|
|
|
328
329
|
|
|
329
330
|
### 错误处理
|
|
330
331
|
|
|
331
|
-
| 错误
|
|
332
|
-
|
|
333
|
-
| `NotFoundError`
|
|
332
|
+
| 错误 | 触发条件 | 修复 |
|
|
333
|
+
| ---------------- | ----------------------- | ----------------------------------------------------------- |
|
|
334
|
+
| `NotFoundError` | 0 候选 | 检查 `name` 拼写 / 拼写错误 / 不存在的符号 |
|
|
334
335
|
| `AmbiguousError` | ≥2 候选且无 `file` 消歧 | 从错误返回的 `candidates[]` 列表中选一个 `name + file` 重试 |
|
|
335
336
|
|
|
336
337
|
## 数据模型
|
|
337
338
|
|
|
338
339
|
### 节点 (Node)
|
|
339
340
|
|
|
340
|
-
| 字段
|
|
341
|
-
|
|
342
|
-
| id
|
|
343
|
-
| name
|
|
344
|
-
| ast_type
|
|
345
|
-
| language
|
|
346
|
-
| file_path
|
|
347
|
-
| start_line | number | 起始行
|
|
348
|
-
| start_col
|
|
349
|
-
| end_line
|
|
350
|
-
| end_col
|
|
351
|
-
| text
|
|
341
|
+
| 字段 | 类型 | 说明 |
|
|
342
|
+
| ---------- | ------ | -------- |
|
|
343
|
+
| id | string | 唯一标识 |
|
|
344
|
+
| name | string | 名称 |
|
|
345
|
+
| ast_type | string | AST 类型 |
|
|
346
|
+
| language | string | 语言 |
|
|
347
|
+
| file_path | string | 文件路径 |
|
|
348
|
+
| start_line | number | 起始行 |
|
|
349
|
+
| start_col | number | 起始列 |
|
|
350
|
+
| end_line | number | 结束行 |
|
|
351
|
+
| end_col | number | 结束列 |
|
|
352
|
+
| text | string | 代码文本 |
|
|
352
353
|
|
|
353
354
|
### 边 (Edge)
|
|
354
355
|
|
|
355
|
-
| 字段
|
|
356
|
-
|
|
357
|
-
| id
|
|
358
|
-
| source
|
|
359
|
-
| target
|
|
360
|
-
| relation | string | 关系类型
|
|
356
|
+
| 字段 | 类型 | 说明 |
|
|
357
|
+
| -------- | ------ | ----------- |
|
|
358
|
+
| id | string | 唯一标识 |
|
|
359
|
+
| source | string | 源节点 ID |
|
|
360
|
+
| target | string | 目标节点 ID |
|
|
361
|
+
| relation | string | 关系类型 |
|
|
361
362
|
|
|
362
363
|
### 关系类型
|
|
363
364
|
|
|
364
|
-
| 关系
|
|
365
|
-
|
|
366
|
-
| CONTAINS
|
|
367
|
-
| CALLS
|
|
368
|
-
| INHERITS_FROM | 继承关系
|
|
369
|
-
| IMPLEMENTS
|
|
370
|
-
| IMPORTS
|
|
371
|
-
| REFERENCES
|
|
365
|
+
| 关系 | 说明 |
|
|
366
|
+
| ------------- | ---------------------- |
|
|
367
|
+
| CONTAINS | 包含关系(类包含方法) |
|
|
368
|
+
| CALLS | 调用关系(函数调用) |
|
|
369
|
+
| INHERITS_FROM | 继承关系 |
|
|
370
|
+
| IMPLEMENTS | 实现接口 |
|
|
371
|
+
| IMPORTS | 导入模块 |
|
|
372
|
+
| REFERENCES | 引用关系 |
|
|
372
373
|
|
|
373
374
|
## 架构
|
|
374
375
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var os=require('os'),utils=require('@easbot/utils'),xdgBasedir=require('xdg-basedir');var o=null,r=null;function I(t){o=t;}function h(){o=null;}function n(){if(o)return o;let t=utils.Filesystem.normalize(os.homedir()),i=xdgBasedir.xdgData??utils.Filesystem.join(t,".local","share");return {Path:{home:t,data:process.env.EASBOT_DATA_PATH?.trim()||utils.Filesystem.join(i,"easbot"),config:process.env.EASBOT_CONFIG_PATH?.trim()||(xdgBasedir.xdgConfig?utils.Filesystem.join(xdgBasedir.xdgConfig,"easbot"):utils.Filesystem.join(t,".config","easbot")),state:process.env.EASBOT_STATE_PATH?.trim()||(xdgBasedir.xdgState??utils.Filesystem.join(i,"easbot","state")),cache:process.env.EASBOT_CACHE_PATH?.trim()||(xdgBasedir.xdgCache?utils.Filesystem.join(xdgBasedir.xdgCache,"easbot"):utils.Filesystem.join(t,".cache","easbot")),log:process.env.EASBOT_LOG_PATH?.trim()||(xdgBasedir.xdgState??utils.Filesystem.join(i,"easbot","log")),bin:process.env.EASBOT_BIN_PATH?.trim()||utils.Filesystem.join(t,".local","bin")}}}function j(t){r=t;}function x(){r=null;}function g(){if(r)return r;let t=utils.Filesystem.normalize(process.cwd());return {directory:t,worktree:t}}function l(){return n().Path.home||utils.Filesystem.normalize(os.homedir())}function d(){let t=n().Path.data;return t||(xdgBasedir.xdgData??utils.Filesystem.join(l(),".local","share"))}function T(){let t=n().Path.config;return t||(xdgBasedir.xdgConfig??utils.Filesystem.join(l(),".config"))}function _(){let t=n().Path.state;return t||(xdgBasedir.xdgState??utils.Filesystem.join(d(),"state"))}function P(){let t=n().Path.cache;return t||(xdgBasedir.xdgCache??utils.Filesystem.join(l(),".cache"))}function v(){return utils.Filesystem.normalize(g().directory||process.cwd())}exports.a=I;exports.b=h;exports.c=n;exports.d=j;exports.e=x;exports.f=g;exports.g=l;exports.h=d;exports.i=T;exports.j=_;exports.k=P;exports.l=v;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-2YMB6W5S.mjs';import {existsSync,readFileSync,promises}from'fs';import {isAbsolute,normalize,join}from'path';import {createRequire}from'module';import {Log,Ignore,errorMeta,NameErrors,PKG,Shell}from'@easbot/utils';var o=Log.create({service:"codebase-file-watcher"});function A(){return process.env.EASBOT_CACHE_PATH||join(process.cwd(),".easbot","cache")}var C=["node_modules/**",".git/**","dist/**","build/**","__pycache__/**","*.min.js","*.min.ts",".easbot/**",".codebase/**"],s=class s{constructor(){a(this,"wrapper",null);a(this,"error",null);}static get(){return s.instance||(s.instance=new s),s.instance}static clearCache(){s.instance&&(s.instance.wrapper=null,s.instance.error=null);}};a(s,"instance",null);var b=s;function R(){let r=process.platform==="linux"?`-${globalThis.EASBOT_LIBC||"glibc"}`:"";return `@parcel/watcher-${process.platform}-${process.arch}${r}`}async function T(){let r=b.get();if(r.wrapper)return r.wrapper;if(r.error)throw new NameErrors.OperationFailedError({message:r.error,operation:"parcel-watcher-binding-cache"});let e=R(),t=A(),i;try{await $(e,t)?i=join(t,"node_modules",e):(o.info("Parcel watcher binding not found, attempting to install",{binding:e,cachePath:t}),i=await q(e,t));}catch(u){let p=errorMeta(u).message,f=`binding "${e}" not found and auto-install failed. Run manually: pnpm install ${e}. Error: ${p}`;throw r.error=f,o.error("failed to install parcel watcher binding",{error:errorMeta(u),binding:e}),new NameErrors.OperationFailedError({message:f,operation:"parcel-watcher-binding-install"})}o.info("Loading Parcel watcher binding",{binding:e,modulePath:i});let{createWrapper:g}=await import('@parcel/watcher/wrapper.js'),l=createRequire(join(i,"package.json"))(e),c=g(l);return r.wrapper=c,c}async function $(r,e){try{return !!await PKG.resolve(r,void 0,{extraPaths:[e]})}catch{return false}}async function q(r,e){return o.info("Installing Parcel watcher binding",{binding:r,cachePath:e}),await Shell.install(r,"latest",e),join(e,"node_modules",r)}function P(){return process.platform==="darwin"?"fs-events":process.platform==="linux"?"inotify":process.platform==="win32"?"windows":"brute-force"}var v=class{constructor(e){a(this,"workspaceDir");a(this,"backendOpt");a(this,"ignorePatterns");a(this,"onLoadFailure");a(this,"ignoreInstance");a(this,"listeners",new Set);a(this,"unsubscribe",null);a(this,"disposed",false);a(this,"running",false);this.workspaceDir=isAbsolute(e.workspaceDir)?e.workspaceDir:normalize(e.workspaceDir),this.backendOpt=e.backend??"auto",this.ignorePatterns=e.ignorePatterns??[...C],this.onLoadFailure=e.onLoadFailure??"throw",this.ignoreInstance=Ignore.create().add(this.ignorePatterns);}getIgnoreInstance(){return this.ignoreInstance}getIgnorePatterns(){return this.ignorePatterns}getActiveBackend(){return this.backendOpt==="auto"?P():this.backendOpt}on(e){return this.listeners.add(e),()=>this.listeners.delete(e)}async start(){if(this.running)return;this.running=true;let e=this.backendOpt==="auto"?P():this.backendOpt;o.info("FileWatcher start",{workspaceDir:this.workspaceDir,backend:e});let t;try{t=await T();}catch(i){if(this.running=false,this.onLoadFailure==="warn")return;throw i}await this.subscribeWithParcel(t,e);}async stop(){if(this.unsubscribe){try{await this.unsubscribe();}catch(e){o.warn("parcel unsubscribe error",{error:errorMeta(e)});}this.unsubscribe=null;}this.running=false;}async dispose(){await this.stop(),this.disposed=true,this.listeners.clear();}isRunning(){return this.running}isDisposed(){return this.disposed}static clearParcelWrapperCache(){b.clearCache();}async subscribeWithParcel(e,t){if(this.disposed)throw new NameErrors.OperationFailedError({message:"FileWatcher disposed before subscribe",operation:"file-watcher-disposed"});let i=(a,l)=>{if(this.disposed)return;let c=this.workspaceDir.replace(/\\/g,"/").replace(/\/$/,""),u=l.replace(/\\/g,"/"),p=l;if(u.startsWith(c+"/")&&(p=u.slice(c.length+1)),this.ignoreInstance.ignores(p,a==="create"&&p.endsWith("/")))return;let f=a==="create"?"add":a==="delete"?"unlink":"change";for(let y of this.listeners)try{y(f,p);}catch(W){o.warn("listener threw",{error:errorMeta(W)});}},g=await e.subscribe(this.workspaceDir,(a,l)=>{if(a){o.error("parcel subscribe callback error",{error:errorMeta(a)});return}for(let c of l)i(c.type,c.path);},{ignore:[...this.ignorePatterns],backend:t});if(this.disposed){await g.unsubscribe().catch(()=>{});return}this.unsubscribe=async()=>{await g.unsubscribe().catch(a=>{o.warn("parcel unsubscribe error",{error:errorMeta(a)});});};}};function m(r){return join(r,".watcher.pid")}function z(r){let e=m(r);if(!existsSync(e))return null;try{let t=readFileSync(e,"utf-8").trim(),i=parseInt(t,10);return Number.isFinite(i)?i:null}catch{return null}}async function K(r,e){let t=m(r);await promises.writeFile(t,String(e),"utf-8");}async function U(r){let e=m(r);try{await promises.unlink(e);}catch{}}export{v as a,m as b,z as c,K as d,U as e};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';var chunkA4YJ5ZVE_cjs=require('./chunk-A4YJ5ZVE.cjs'),chunkYJK7F6NJ_cjs=require('./chunk-YJK7F6NJ.cjs'),utils=require('@easbot/utils'),types=require('@easbot/types'),fs=require('fs');var J=utils.Log.create({service:"codebase-service"}),N=utils.Filesystem.toUnixPath;function xe(e,t){let r={exact:1,qualified:.85,substring:.5}[e];return t?Math.min(1,r+.2):r}function Ne(e,t){if(!t)return false;if(e===t)return true;let r=e.split(/[/\\]/).pop()??"",o=t.split(/[/\\]/).pop()??"";return !!(r&&o&&r===o||t.includes("/")&&e.endsWith("/"+t))}async function T(e,t,r){if(r.nodeId){let i=e.getNode(r.nodeId);if(!i)throw new utils.ServiceError({code:"NOT_FOUND",message:`Node not found: nodeId=${r.nodeId}`,details:{name:r.nodeId}});return {node:i,candidates:[]}}if(!r.name)throw new utils.ServiceError({code:"NOT_FOUND",message:"Either name or nodeId is required",details:{...r}});let l=e.getDatabase().findNodesByName({name:r.name,file:r.file,kind:r.kind,limit:50});if(l.length===0)throw new utils.ServiceError({code:"NOT_FOUND",message:`Node not found: ${r.name}`,details:{name:r.name,candidates:[]}});let a=!!r.file,c=r.file?N(r.file):null,s=l.map(i=>{let m=c?Ne(N(i.node.file_path),c):false;return {node:i.node,score:xe(i.matchKind,m),matchKind:i.matchKind,inFile:m}});if(s.sort((i,m)=>m.score-i.score),s.length===1)return {node:s[0].node,candidates:s.map(i=>({node:i.node,score:i.score}))};let d=s[0].score,n=s.filter(i=>i.score===d);if(n.length===1)return {node:n[0].node,candidates:s.slice(0,10).map(i=>({node:i.node,score:i.score}))};if(a&&n.length>1){let i=n.filter(m=>m.inFile);if(i.length===1)return {node:i[0].node,candidates:s.slice(0,10).map(m=>({node:m.node,score:m.score}))}}throw new utils.ServiceError({code:"AMBIGUOUS",message:`Ambiguous name "${r.name}" \u2014 ${s.length} candidates`,details:{name:r.name,candidates:s.slice(0,10).map(i=>({node:i.node,score:i.score}))}})}async function P(e){let t=chunkA4YJ5ZVE_cjs.c(e.rootDir),r=new chunkA4YJ5ZVE_cjs.x({workspaceDir:e.workspaceDir,database:{path:t,walMode:true},embedding:types.DEFAULT_EMBEDDING_CONFIG,indexer:types.DEFAULT_INDEXER_CONFIG,parser:types.DEFAULT_PARSER_CONFIG,search:types.DEFAULT_SEARCH_CONFIG,sync:{onBoot:false,onSearch:false,onSessionStart:false,intervalMs:0}});return await r.initialize(),r}function U(e,t,r,o){let l=r.map(()=>"?").join(","),a=t.name.split("@")[0]??t.name,c=a.includes(".")?a.split(".").pop()??a:a,s=new Set([`${t.language}:*:*:${a}`]);c!==a&&s.add(`${t.language}:*:*:${c}`);let d=[];c!==a&&d.push(`${t.language}:*:*:%${c}`);let n=Array.from(s),i=n.map(()=>"?").join(","),u=d.length>0?"OR LOWER(target) LIKE LOWER(?)":"";n.length>1&&J.warn("queryIncomingEdgesWithWildcard: multi-variant wildcards (bare+namespaced)",{rootName:t.name,wildcards:n,hint:"\u540C\u540D\u540C namespace \u4E0D\u540C file \u7684\u65B9\u6CD5\u53EF\u80FD\u90FD\u88AB\u547D\u4E2D\uFF0CLLM \u63A8\u7406\u8BF7\u7528 file \u8FC7\u6EE4\u8F85\u4F50"});let g=`
|
|
2
|
+
SELECT id, source, target, relation, created_at FROM edges
|
|
3
|
+
WHERE relation IN (${l})
|
|
4
|
+
AND source != target
|
|
5
|
+
AND (
|
|
6
|
+
target = ?
|
|
7
|
+
OR target IN (${i})
|
|
8
|
+
${u}
|
|
9
|
+
)
|
|
10
|
+
GROUP BY id
|
|
11
|
+
LIMIT ?
|
|
12
|
+
`;return e.queryAll(g,[...r,t.id,...n,...d,o])}function Pe(e){return e==="class_declaration"||e==="class_definition"||e==="interface_declaration"||e==="struct_declaration"||e==="struct_specifier"||e==="record_declaration"}function Re(e,t,r,o,l){let c=e.queryAll("SELECT id FROM nodes WHERE file_path = ? AND start_line >= ? AND end_line <= ? AND ast_type IN ('method_definition', 'method_declaration') LIMIT 1000",[t.file_path,t.start_line,t.end_line]).map(n=>n.id),s=new Set,d=[];for(let n of r)n.id&&!s.has(n.id)&&(s.add(n.id),d.push(n));if(c.length>0){let n=o.map(()=>"?").join(","),i=c.map(()=>"?").join(","),m=`
|
|
13
|
+
SELECT id, source, target, relation, created_at FROM edges
|
|
14
|
+
WHERE relation IN (${n})
|
|
15
|
+
AND source != target
|
|
16
|
+
AND source IN (${i})
|
|
17
|
+
GROUP BY id
|
|
18
|
+
LIMIT ?
|
|
19
|
+
`,u=e.queryAll(m,[...o,...c,l]);for(let g of u)g.id&&!s.has(g.id)&&(s.add(g.id),d.push(g));}return d.slice(0,l)}function Z(e,t,r,o){let a=`
|
|
20
|
+
SELECT id, source, target, relation, created_at FROM edges
|
|
21
|
+
WHERE relation IN (${r.map(()=>"?").join(",")})
|
|
22
|
+
AND source != target
|
|
23
|
+
AND source = ?
|
|
24
|
+
LIMIT ?
|
|
25
|
+
`;return e.queryAll(a,[...r,t.id,o])}function ee(e,t,r,o){let l=o==="in"?e.source:e.target;t.id;let c=r.getNodeById(l);if(!c&&l.includes(":*:")){let s=l.split(":").pop()??l,d=s.split("@")[0]??s;if(d&&d!==l){let n=r.findNodesByName({name:d}),i=t.file_path??"",m=i.split(/[/\\]/).pop()??"",u=i.split(/[/\\]/).filter(Boolean),g=n.find(p=>p.node.file_path?p.node.file_path===i:false)??n.find(p=>!p.node.file_path||!m?false:p.node.file_path.split(/[/\\]/).pop()===m)??n.find(p=>{if(!p.node.file_path)return false;let f=p.node.file_path.split(/[/\\]/).filter(Boolean);return u.length<2||f.length<2?false:u[0]===f[0]&&u[1]===f[1]})??null;g&&(c=g.node);}}if(!c){let s=l.split(":").pop()??l;return {id:l,name:s,astType:"unresolved",filePath:"(unresolved)",startLine:0,relation:e.relation}}return {id:c.id,name:c.name,astType:c.ast_type,filePath:N(c.file_path),startLine:c.start_line??0,relation:e.relation}}async function te(e,t){let r=Date.now(),c=await(await P(e)).getQuery().search(t.query??"",{maxResults:t.maxResults??10,language:t.language,filePath:t.file,astType:t.astType,includeEdges:true,enableFts:t.enableFts!==false,enableEmbedding:t.enableEmbedding!==false});if(t.kind){let n=t.kind.toLowerCase();c=c.filter(i=>i.ast_type.includes(n)||i.name.toLowerCase().includes(n));}if(t.file){let n=N(t.file);c=c.filter(i=>N(i.file_path).endsWith(n)||N(i.file_path).includes(n));}let s=t.maxEdgesPerNode??10,d=c.map(n=>({nodeId:n.id,name:n.name,kind:n.ast_type??"unknown",filePath:N(n.file_path),startLine:n.start_line,endLine:n.end_line,edges:(n.edges??[]).slice(0,s),source:"basic",score:0,snippet:(n.text??"").slice(0,200).replace(/\s+/g," ").trim()}));return {total:d.length,hits:d,durationMs:Date.now()-r,truncated:false}}async function Se(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t),c=[];if(t.includeEdges){let s=t.maxEdgesPerNode??10,d=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","HAS_METHOD","HAS_PROPERTY","METHOD_OVERRIDES"],n=U(l,a,d,s+1),i=Z(l,a,d,s+1),m=new Set,u=[];for(let g of [...n,...i])g.id&&!m.has(g.id)&&(m.add(g.id),u.push(g));c=u.slice(0,s);}return {node:a,edges:c}}var Ce=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","HAS_METHOD","HAS_PROPERTY","METHOD_OVERRIDES"];async function Ie(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,nodes:[],edges:[],truncated:false,totalNodes:0,totalEdges:0};let c=t.depth??2,s=t.maxNodes??100,d=t.direction??"both";t.maxEdgesPerNode??10;let i=new Map,m=[{nodeId:a.id,depth:0}];i.set(a.id,0);let u=[],g=false;for(;m.length>0;){let h=m.shift();if(h.depth>=c)continue;if(i.size>=s){g=true;break}let F=o.queryNeighbors(h.nodeId,{direction:d,relationTypes:t.relationTypes??Ce,limit:s-i.size+1});for(let y of F.edges){u.push(y);let I=y.source===h.nodeId?y.target:y.source;if(!i.has(I)&&(i.set(I,h.depth+1),m.push({nodeId:I,depth:h.depth+1}),i.size>=s)){g=true;break}}if(g)break}let p=new Set,f=[];for(let h of u)!h.id||p.has(h.id)||(p.add(h.id),f.push(h));let b=Array.from(i.keys()),E=b.length>0?l.queryNodes({ids:b}):[],C=new Map(E.map(h=>[h.id,h])),x=[];for(let[h,F]of i.entries()){let y=C.get(h);y&&x.push({node:y,depth:F});}return {root:a,nodes:x,edges:f,truncated:g,totalNodes:x.length,totalEdges:u.length}}var Le=["CALLS","IMPORTS","TYPE_REFERENCES"];async function Te(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,totalImpacted:0,buckets:[]};let c=t.depth??2,s=t.maxResults??10,d=t.relationTypes??Le,n=t.maxEdgesPerNode??10,i=new Set([a.id]),m=[],u=[a.id];for(let g=1;g<=c&&!(u.length===0||i.size-1>=s);g++){let p=U(l,a,d,n+1),f=[],b=new Set;for(let E of p)if(!i.has(E.source)&&!b.has(E.source)&&(b.add(E.source),i.add(E.source),f.push(E.source),i.size-1>=s))break;if(f.length>0){let E=f.slice(0,10),C=l.queryNodes({ids:E}),x=new Map(C.map(y=>[y.id,y])),h=new Map;for(let y of p)h.has(y.source)||h.set(y.source,y.relation);let F=E.map(y=>{let I=x.get(y);return {id:y,name:I?.name??"(unknown)",filePath:I?N(I.file_path):"(unknown)",relation:h.get(y)??"CALLS"}});m.push({depth:g,count:f.length,sample:F});}u=f;}return m.length===0&&J.warn("impact: no incoming edges found",{root:a.name,depth:c,relationTypes:d}),{root:a,totalImpacted:i.size-1,buckets:m}}var ne=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","METHOD_OVERRIDES"];async function $e(e,t){return re(e,t)}async function _e(e,t){return oe(e,t)}async function re(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,callers:[],truncated:false};let c=t.maxResults??10,s=t.maxEdgesPerNode??c,d=t.relationTypes??ne,n=U(l,a,d,s+1),i=[];for(let u of n){let g=ee(u,a,l,"in");g&&i.push(g);}let m=i.length>c;return {root:a,callers:m?i.slice(0,c):i,truncated:m}}async function oe(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,callees:[],truncated:false};let c=t.maxResults??10,s=t.maxEdgesPerNode??c,d=t.relationTypes??ne,n=Z(l,a,d,s+1),i=Pe(a.ast_type)?Re(l,a,n,d,s+1):n,m=[];for(let g of i){let p=ee(g,a,l,"out");p&&m.push(p);}let u=m.length>c;return {root:a,callees:u?m.slice(0,c):m,truncated:u}}async function we(e,t){if(!t.query)throw new utils.ServiceError({code:"NOT_FOUND",message:"explore requires a non-empty query",details:{query:t.query}});let o=await P(e),l=o.getQuery(),a=o.getDatabase(),s=(await te(e,{query:t.query,file:t.file,kind:t.kind,intent:t.intent,maxResults:t.maxFiles??5,enableFts:true,enableEmbedding:true})).hits;if(t.file||t.kind)try{let u=await T(l,e,{name:t.query,file:t.file,kind:t.kind});if(u?.node){let g={nodeId:u.node.id,name:u.node.name,kind:u.node.ast_type,filePath:N(u.node.file_path),startLine:u.node.start_line,endLine:u.node.end_line,edges:[],source:"basic",score:0,snippet:(u.node.text??"").slice(0,200).replace(/\s+/g," ").trim()},p=s.filter(f=>f.nodeId!==g.nodeId);s=[g,...p];}}catch{}let d=new Map;for(let u of s){let g=N(u.filePath),p=d.get(g);p?p.push(u):d.set(g,[u]);}let n=t.maxSymbols??3,i=t.maxEdgesPerNode??10,m=[];for(let[u,g]of d){let p=g.slice(0,n),f=[];for(let b of p){let E=await re(e,{name:b.name,file:u,kind:t.kind,maxResults:i,maxEdgesPerNode:i}),C=await oe(e,{name:b.name,file:u,kind:t.kind,maxResults:i,maxEdgesPerNode:i});f.push({node:(()=>{let x={id:b.nodeId,name:b.name,ast_type:b.kind,language:"ts",file_path:b.filePath,start_line:b.startLine??0,end_line:b.endLine??0};try{let h=a.getNodeById(b.nodeId);return {...x,text:h?.text??""}}catch{return {...x,text:""}}})(),callers:E.callers,callees:C.callees});}m.push({file:u,symbols:f});}return {query:t.query,entryPoints:m,totalHits:s.length}}async function Fe(e,t){let o=await(await P(e)).getStatus();o.package="codebase",o.workspaceDir=e.workspaceDir;let l=chunkA4YJ5ZVE_cjs.b(e.workspaceDir),a=fs.existsSync(l),c=fs.existsSync(o.dbPath),s;if(c)try{s=fs.statSync(o.dbPath).size;}catch{}o.configPath=l,o.configExists=a,o.dbExists=c,o.dbSize=s,o.vectorEnabled=o.meta?.vector_enabled==="true"||o.meta?.vector_enabled==="1";let d=o.meta?.embeddingDims;d&&Number.isFinite(Number.parseInt(d,10))&&(o.embeddingDims=Number.parseInt(d,10));let n={initialized:false,capabilities:{embedding:false,graphLlm:false}};try{let{Llm:i}=await import('./llm-R2ZLKZDO.cjs');if(i.isInitialized()){n.initialized=!0;let m=i.capabilities();n.capabilities={embedding:m.embedding===!0,graphLlm:m.graphLlm===!0},n.embeddingModel=n.capabilities.embedding?"configured":void 0,n.graphModel=n.capabilities.graphLlm?"configured":void 0;}}catch{}o.llm=n;try{let{DatabaseManager:i}=await import('./database-manager-X4DMAUWC.cjs'),m=new i(o.dbPath);try{let{stats:u}=m.checkIntegrity();o.dbStats=u,o.ftsAvailable=m.isFtsAvailable();}finally{m.close();}}catch{}return o}async function Ae(e,t){return await(await P(e)).healthCheck()}var ke=utils.Log.create({service:"codebase-service-init"}),se=false;async function ve(){se||(se=true,ke.info("codebase service init"),await utils.ServiceErrorBus.init(),await chunkYJK7F6NJ_cjs.e());}var ie=utils.Filesystem.toUnixPath;function He(e){let t=e.text??"";if(!t)return false;let r=t.slice(0,80);return /\bexport\s/.test(r)||/\bpublic\s/.test(r)?true:(false)}function qe(e){let t=e.text??"";if(!t)return [];let r=t.slice(0,80),o=[];return /\basync\s/.test(r)&&o.push("async"),/\bstatic\s/.test(r)&&o.push("static"),/\babstract\s/.test(r)&&o.push("abstract"),/\breadonly\s/.test(r)&&o.push("readonly"),/\bconst\s/.test(r)&&o.push("const"),/\blet\s/.test(r)&&o.push("let"),o}function R(e){return {id:e.id,name:e.name,astType:e.ast_type,language:e.language,filePath:ie(e.file_path),startLine:e.start_line??0,endLine:e.end_line??0,isExported:He(e),modifiers:qe(e)}}function $(e,t){return {id:e.id,source:e.source,target:e.target,relation:e.relation,direction:t}}function z(e){return e.map(t=>({node:{id:t.nodeId,name:t.name,astType:t.kind,language:"typescript",filePath:ie(t.filePath),startLine:t.startLine??0,endLine:t.endLine??0,isExported:false,modifiers:[]},source:t.source,score:t.score,snippet:(t.snippet??"").slice(0,200),edges:(t.edges??[]).slice(0,10).map(r=>$({...r}))}))}function K(){return {id:"",name:"",astType:"",language:"",filePath:"",startLine:0,endLine:0,isExported:false,modifiers:[]}}var ze=utils.Log.create({service:"codebase-format-truncate"}),j="**`",Ke="**",le=24e3,de=25e3;async function D(e,t={}){let r=t.softLimit??le,o=t.hardCeiling??de,l=t.toolName??"codebase",a=t.writeToDisk!==false;if(e.length<=r)return {content:e,truncated:false};let c=e.slice(0,o),s=c.lastIndexOf(`
|
|
26
|
+
${j}`),d=c.lastIndexOf(`
|
|
27
|
+
`),n;s>o*.5?n=s:d>0?n=d:n=-1;let i=n>0?c.slice(0,n):c,u=i+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!a)return {content:u,truncated:true,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`};try{let g=await utils.TruncateContent.truncate(e,{maxChars:i.length,direction:"head",label:`${l}-output`});return g.truncated?{content:u,truncated:!0,outputPath:g.outputPath,hint:utils.TruncateContent.formatHint(g),info:`... ${g.removedLength}/${g.originalLength} characters truncated ...`}:{content:u,truncated:!0,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`}}catch(g){return ze.warn("TruncateContent.truncate failed, returning without disk hint",{error:utils.errorMeta(g)}),{content:u,truncated:true,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`}}}function O(e,t={}){let r=t.softLimit??le,o=t.hardCeiling??de;if(e.length<=r)return {content:e,truncated:false};let l=e.slice(0,o),a=l.lastIndexOf(`
|
|
28
|
+
${j}`),c=l.lastIndexOf(`
|
|
29
|
+
`),s;a>o*.5?s=a:c>0?s=c:s=-1;let d=s>0?l.slice(0,s):l;return {content:d+`
|
|
30
|
+
|
|
31
|
+
... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-d.length}/${e.length} characters truncated ...`}}function je(e,t=Date.now()){let r=Math.max(0,Math.floor((t-e)/1e3));return r>60?">60s ago":`${r}s ago`}function k(e,t){if(!e||e.length===0)return null;let r=e.filter(l=>t.has(l.path));return r.length===0?null:`\u26A0\uFE0F Index may be stale for: ${r.map(l=>`${l.path} (edited ${je(l.lastEventAt)})`).join(", ")}
|
|
32
|
+
|
|
33
|
+
`}function A(e,t,r={}){return (ce[e]??ce.default).replace(/<(\w+)>/g,(l,a)=>a==="tool"?t:r[a]??`<${a}>`)}var ce={search:`---
|
|
34
|
+
|
|
35
|
+
> **Complete source for N files is included above \u2014 do NOT re-read them.**
|
|
36
|
+
> If your question also needs files/symbols listed under "Not shown above" (or any area this call didn't cover), make ANOTHER \`<tool>\` targeting those names \u2014 it returns the same source with line numbers and is cheaper and more complete than reading.`,impact:"---\n\n> **Risk: <riskLevel>**. Before editing `<root>`, review d=1 first \u2014 those WILL BREAK.\n> Use `<tool>` to read full source of any direct caller.",context:"---\n\n> **Use `impact` for blast-radius analysis. Use `explore` to read source.**",default:`---
|
|
37
|
+
|
|
38
|
+
> **Output truncated to budget; the content above is the source of truth.**
|
|
39
|
+
> For more detail, call \`<tool>\` with refined parameters.`};async function v(e,t){let{pendingFiles:r,toolName:o,sync:l=false}=t;if(e.length===0)return _(o,"No matches found.","Try broader search terms, or use `explore` to read source.");let a=Ge(e),c=new Set(a.keys()),s=[];s.push(k(r,c)??"");let d="[[codebase-search-summary]]";s.push(d+`
|
|
40
|
+
`);let n=e.length;s.push(`**Files with matches:** ${a.size}
|
|
41
|
+
`);for(let[g,p]of a){let f=p.map(x=>x.node.name),b=f.slice(0,5).join(", "),E=f.length>5?`, +${f.length-5} more`:"";s.push(`**\`${g}\`** \u2014 ${b}${E}
|
|
42
|
+
`);let C=p[0]?.node.language??"";s.push("```"+C);for(let x of p)s.push(`L${x.node.startLine} ${x.snippet}`);s.push("```\n");}s.push(A("search",o,{}));let i=s.join(`
|
|
43
|
+
`),m=`Found ${n} symbol${n===1?"":"s"} across ${a.size} file${a.size===1?"":"s"}.`,u=i.replace(d,m);return w(u,t,l)}async function M(e,t,r){let{pendingFiles:o,toolName:l,sync:a=false}=r;if(t.length===0||t.every(n=>n.count===0))return _(l,`No incoming edges for \`${e.name}\`.`,"This symbol has no callers \u2014 safe to refactor.");let c=t.reduce((n,i)=>n+i.count,0),s=We(c),d=[];d.push(k(o,new Set([e.filePath]))??""),d.push(`**Impact for \`${e.name}\`** (root: ${e.filePath}:${e.startLine}, total impacted: ${c})
|
|
44
|
+
`);for(let n of t){d.push(`- **d=${n.depth}** (${n.count} nodes) \u2014 ${n.riskLabel}`);for(let i of n.samples.slice(0,5))d.push(` - \`${i.name}\` ${i.file}:${i.line} [${i.relation}]`);n.samples.length>5&&d.push(` - ... and ${n.samples.length-5} more`);}return d.push(A("impact",l,{root:e.name,riskLevel:s})),w(d.join(`
|
|
45
|
+
`),r,a)}function We(e){return e>=100?"CRITICAL":e>=50?"HIGH":e>=10?"MEDIUM":"LOW"}function W(e){return e===1?"WILL BREAK (direct callers)":e===2?"LIKELY AFFECTED (indirect)":"MAY NEED TESTING (transitive)"}async function G(e,t){let{root:r,incoming:o,outgoing:l,neighbors:a}=e,{pendingFiles:c,toolName:s,sync:d=false}=t;if(o.length===0&&l.length===0&&a.length===0)return _(s,`No relations found for \`${r.name}\`.`,"This is a leaf node.");let n=[];n.push(k(c,new Set([r.filePath]))??""),n.push(`**Context for \`${r.name}\`** (${r.astType}, ${r.language}, ${r.filePath}:${r.startLine})
|
|
46
|
+
`),n.push(`**Incoming** (${o.length}):`);for(let i of o.slice(0,10))n.push(`- ${i.source} \u2192 [${i.relation}] \u2192 \`${r.name}\``);o.length>10&&n.push(`- ... and ${o.length-10} more`),n.push(""),n.push(`**Outgoing** (${l.length}):`);for(let i of l.slice(0,10))n.push(`- \`${r.name}\` \u2192 [${i.relation}] \u2192 ${i.target}`);if(l.length>10&&n.push(`- ... and ${l.length-10} more`),n.push(""),a.length>0){n.push(`**Neighbors** (${a.length}):`);for(let i of a.slice(0,20))n.push(`- [d=${i.depth}] \`${i.node.name}\` (${i.node.astType}) ${i.node.filePath}:${i.node.startLine}`);a.length>20&&n.push(`- ... and ${a.length-20} more`),n.push("");}return n.push(A("context",s,{})),w(n.join(`
|
|
47
|
+
`),t,d)}async function H(e,t,r){let{pendingFiles:o,toolName:l,sync:a=false}=r;if(!e.id)return _(l,"Node not found.","Check the node ID or use `search` to find it.");let c=t.filter(n=>n.direction==="in"),s=t.filter(n=>n.direction==="out"),d=[];d.push(k(o,new Set([e.filePath]))??""),d.push(`**Node: \`${e.name}\`**
|
|
48
|
+
`),d.push(`- ID: \`${e.id}\``),d.push(`- Kind: ${e.astType}`),d.push(`- Language: ${e.language}`),d.push(`- Location: ${e.filePath}:${e.startLine}-${e.endLine}`),d.push(`- Exported: ${e.isExported}`),e.modifiers.length>0&&d.push(`- Modifiers: ${e.modifiers.join(", ")}`),d.push(""),d.push(`**Edges** (incoming: ${c.length} / outgoing: ${s.length}):`);for(let n of c.slice(0,5))d.push(`- \u2190 [${n.relation}] ${n.source}`);for(let n of s.slice(0,5))d.push(`- \u2192 [${n.relation}] ${n.target}`);return t.length>10&&d.push(`- ... and ${t.length-10} more`),d.push(A("default",l,{})),w(d.join(`
|
|
49
|
+
`),r,a)}async function q(e,t,r,o,l){let{toolName:a,sync:c=false}=l,s=r==="callers"?"Callers":"Callees",d="of",n=r==="callers"?"Use `node <name>` to read full source of any caller.":"Use `node <name>` to read full source of any callee.",i=t?.name??"?";if(e.length===0)return _(a,`**${s} ${d} \`${i}\`** (0)`,r==="callers"?"This symbol has no callers \u2014 safe to refactor.":"This symbol has no outgoing calls \u2014 leaf node.");let m=[];m.push(`**${s} ${d} \`${i}\`** (${e.length}${o?"+":""})
|
|
50
|
+
`);for(let u of e.slice(0,10)){let g=u.filePath==="(unresolved)",p=g?u.filePath:`${u.filePath}:${u.startLine}`,f=g?" _(wildcard)_":"";m.push(`- [${u.relation}] \`${u.name}\` ${p}${f}`);}return e.length>10&&m.push(`- ... and ${e.length-10} more`),m.push(`
|
|
51
|
+
---
|
|
52
|
+
> ${n}`),w(m.join(`
|
|
53
|
+
`),l,c)}async function ue(e,t){let{entryPoints:r,totalHits:o,query:l}=e,{toolName:a,sync:c=false}=t;if(r.length===0)return _(a,`No matches for \`${l}\`.`,"Try broader search terms, or use `callers` / `callees` to traverse from a known symbol.");let s=[];s.push(`## Code Context
|
|
54
|
+
`),s.push(`**Query:** ${l} `),s.push(`**Total hits:** ${o} `),s.push(`**Entry points:** ${r.length}
|
|
55
|
+
`);for(let d of r){s.push(`**\`${d.file}\`** \u2014 ${d.symbols.length} symbol${d.symbols.length===1?"":"s"}
|
|
56
|
+
`);for(let n of d.symbols){let i=(n.source??"").trim()||"(source not included)",m=n.node.language;if(s.push("```"+m),s.push(`L${n.node.startLine}-L${n.node.endLine} ${n.node.name} (${n.node.astType}${n.node.modifiers.length>0?`, ${n.node.modifiers.join(" ")}`:""})`),s.push(""),s.push(i),s.push("```\n"),n.callers.length>0){s.push(`**Callers of \`${n.node.name}\` (${n.callers.length}):**`);for(let u of n.callers.slice(0,5))s.push(`- [${u.relation}] \`${u.name}\` ${u.filePath}:${u.startLine}`);n.callers.length>5&&s.push(`- ... and ${n.callers.length-5} more`),s.push("");}if(n.callees.length>0){s.push(`**Callees of \`${n.node.name}\` (${n.callees.length}):**`);for(let u of n.callees.slice(0,5))s.push(`- [${u.relation}] \`${u.name}\` ${u.filePath}:${u.startLine}`);n.callees.length>5&&s.push(`- ... and ${n.callees.length-5} more`),s.push("");}}}return s.push(`---
|
|
57
|
+
`),s.push(A("context",a,{})),w(s.join(`
|
|
58
|
+
`),t,c)}function Ge(e){let t=new Map;for(let r of e){let o=r.node.filePath,l=t.get(o);l?l.push(r):t.set(o,[r]);}return t}function _(e,t,r){return `**${e}**
|
|
59
|
+
|
|
60
|
+
${t}
|
|
61
|
+
|
|
62
|
+
> **Tip:** ${r}`}async function w(e,t,r){let o={softLimit:t.softLimit,hardCeiling:t.hardCeiling,toolName:t.toolName,writeToDisk:r?false:t.writeToDisk};return (r?O(e,o):await D(e,o)).content}var Ye=utils.Log.create({service:"codebase-format-render"});async function Ve(e,t){if(e.length===0)return v([],t);let r=z(e);return v(r,t)}async function Xe(e,t,r){if(t.length===0)return M(R(e),[],r);let o=[{depth:1,count:t.length,riskLabel:W(1),samples:t.slice(0,10).map(l=>({name:l.source.name,file:R(l.source).filePath,line:l.source.start_line??0,relation:l.relation}))}];return M(R(e),o,r)}async function Je(e,t,r,o,l){let a=R(e),c=t.map(n=>$(n,"in")),s=r.map(n=>$(n,"out")),d=o.map(n=>({node:R(n),depth:1}));return G({root:a,incoming:c,outgoing:s,neighbors:d},l)}async function Ze(e,t){return q(e.callers,e.root,"callers",e.truncated,t)}async function et(e,t){return q(e.callees,e.root,"callees",e.truncated,t)}async function tt(e,t){let{renderKnowledgeStatus:r}=await import('@easbot/terminal');return r({packageName:"codebase",rootDir:e.workspaceDir,configPath:e.configPath??"",configExists:typeof e.configExists=="boolean"?e.configExists:false,dbPath:e.dbPath,dbExists:typeof e.dbExists=="boolean"?e.dbExists:true,dbSize:e.dbSize,indexState:e.indexState,schemaVersion:(()=>{let o=e.meta?.schema_version;return o&&Number.isFinite(Number.parseInt(o,10))?Number.parseInt(o,10):void 0})(),extractionVersion:e.extractionVersion,lastSyncAt:e.lastSync,vectorEnabled:typeof e.vectorEnabled=="boolean"?e.vectorEnabled:false,embeddingDims:typeof e.embeddingDims=="number"?e.embeddingDims:void 0,llm:e.llm??{initialized:false,capabilities:{}},healthy:e.healthy,dbStats:e.dbStats,extras:(()=>{let o={};if(e.isStale===true&&(o.stale="yes \u2014 reindex recommended"),typeof e.ftsAvailable=="boolean"&&(o.fts_available=e.ftsAvailable?"yes":"no"),e.meta&&typeof e.meta=="object")for(let[l,a]of Object.entries(e.meta))a!=null&&(o[`meta/${l}`]=String(a));return Object.keys(o).length>0?o:void 0})()})}async function nt(e,t,r){if(!e)return H(K(),[],r);let o=R(e),l=t.map(a=>{let c=a.target===e.id?"in":"out";return $(a,c)});return H(o,l,r)}async function rt(e,t){let r={query:e.query,totalHits:e.totalHits,entryPoints:e.entryPoints.map(o=>({file:o.file,symbols:o.symbols.map(l=>({node:R(l.node),source:l.node.text??"",callers:l.callers.map(a=>({name:a.name,filePath:a.filePath,startLine:a.startLine,relation:a.relation})),callees:l.callees.map(a=>({name:a.name,filePath:a.filePath,startLine:a.startLine,relation:a.relation}))}))}))};return ue(r,t)}Ye.debug("format/render.ts loaded");exports.A=Je;exports.B=Ze;exports.C=et;exports.D=tt;exports.E=nt;exports.F=rt;exports.a=te;exports.b=Se;exports.c=Ie;exports.d=Te;exports.e=$e;exports.f=_e;exports.g=we;exports.h=Fe;exports.i=Ae;exports.j=ve;exports.k=R;exports.l=$;exports.m=z;exports.n=K;exports.o=j;exports.p=Ke;exports.q=D;exports.r=O;exports.s=v;exports.t=M;exports.u=W;exports.v=G;exports.w=H;exports.x=q;exports.y=Ve;exports.z=Xe;
|