@easbot/codebase 0.3.16 → 0.3.19
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 +100 -0
- package/README.md +109 -1
- package/dist/chunks/{chunk-P6QT72IP.mjs → chunk-22PKTMO5.mjs} +14 -14
- package/dist/chunks/chunk-AGZFRKQ4.mjs +188 -0
- package/dist/chunks/{chunk-W2JWBAHR.mjs → chunk-CSMSBVAG.mjs} +1 -1
- package/dist/chunks/chunk-GWCRGM4D.mjs +51 -0
- package/dist/chunks/{chunk-UTPNELRD.cjs → chunk-JWTI3BWI.cjs} +14 -14
- package/dist/chunks/{chunk-6ENRFRCH.cjs → chunk-R74KIJM2.cjs} +1 -1
- package/dist/chunks/chunk-TR3DFBJH.mjs +47 -0
- package/dist/chunks/chunk-VFTVDTEY.cjs +188 -0
- package/dist/chunks/chunk-VPWALTY7.cjs +51 -0
- package/dist/chunks/chunk-YYF5OQDS.cjs +47 -0
- package/dist/chunks/cli-handler-3I5JC3HY.cjs +1 -0
- package/dist/chunks/cli-handler-IJ2PNNTK.mjs +1 -0
- package/dist/chunks/code-base-6TM7JDJ6.cjs +1 -0
- package/dist/chunks/code-base-BSRUQYXN.mjs +1 -0
- package/dist/chunks/database-manager-26PY6VTD.mjs +1 -0
- package/dist/chunks/database-manager-U7D7QIHC.cjs +1 -0
- package/dist/chunks/llm-JQV6XWGD.cjs +1 -0
- package/dist/chunks/llm-MPD7FHPM.mjs +1 -0
- package/dist/chunks/{stdio-server-EQGSXAMO.cjs → stdio-server-2GBPZY6J.cjs} +6 -6
- package/dist/chunks/{stdio-server-OFN76NZA.mjs → stdio-server-BZYPM34X.mjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +62 -1
- package/dist/index.d.ts +62 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -8
- package/dist/chunks/chunk-6CD6Y4F7.cjs +0 -48
- package/dist/chunks/chunk-7XCIIOM6.cjs +0 -1
- package/dist/chunks/chunk-BUHCT5PM.mjs +0 -48
- package/dist/chunks/chunk-CS4EBN3N.mjs +0 -2
- package/dist/chunks/chunk-K5CRL5DC.cjs +0 -234
- package/dist/chunks/chunk-LFH3RTD3.mjs +0 -234
- package/dist/chunks/chunk-UTKA3WG3.mjs +0 -1
- package/dist/chunks/chunk-WSFETZ24.cjs +0 -2
- package/dist/chunks/cli-handler-IDMIMEKA.cjs +0 -1
- package/dist/chunks/cli-handler-ZLJJGHMV.mjs +0 -1
- package/dist/chunks/code-base-2TXG4VK3.mjs +0 -1
- package/dist/chunks/code-base-32T6G2FF.cjs +0 -1
- package/dist/chunks/database-manager-YEWLT7QF.mjs +0 -1
- package/dist/chunks/database-manager-YNQZSUVP.cjs +0 -1
- package/dist/chunks/sync-6CALMRLC.mjs +0 -1
- package/dist/chunks/sync-TICACY4G.cjs +0 -1
package/README.en.md
CHANGED
|
@@ -90,6 +90,106 @@ easbot-codebase path <missing> --json
|
|
|
90
90
|
|
|
91
91
|
**Exemptions**: `watch` (service-mode) / `mcp` (JSON-RPC). See [decision 0051](file:///e:/work/apps/eas/easbot/docs/decisions/0051-cli-human-output-unify.md) and [CLI Output Spec v1.3](file:///e:/work/apps/eas/easbot/docs/spec/cli-output-spec.md).
|
|
92
92
|
|
|
93
|
+
## Status / Doctor Unified Output Format (Decision 0073 / CLI Spec v1.4)
|
|
94
|
+
|
|
95
|
+
`codebase status` / `codebase doctor` share the same rendering as `note` / `memory` via `@easbot/terminal`'s `formatKnowledgeStatus` / `formatKnowledgeDoctor`, ensuring consistent visual and field structure across all three packages.
|
|
96
|
+
|
|
97
|
+
### Status Output Example
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
$ easbot codebase status
|
|
101
|
+
─ codebase status ─────────────────────────────────────────────────
|
|
102
|
+
Root directory E:/work/my-project
|
|
103
|
+
Config ✓ E:/work/my-project/.easbot/codebase.json
|
|
104
|
+
DB ✓ E:/work/my-project/.easbot/db/codebase.db (12582912 bytes)
|
|
105
|
+
Index state ready
|
|
106
|
+
Schema version 1
|
|
107
|
+
Extraction version 1
|
|
108
|
+
Backend better-sqlite3
|
|
109
|
+
Last sync 2026-08-31T14:23:11.000Z
|
|
110
|
+
Vector enabled ✓
|
|
111
|
+
Embedding dims 1536
|
|
112
|
+
LLM:
|
|
113
|
+
Initialized ✓
|
|
114
|
+
Provider openai
|
|
115
|
+
Capabilities:
|
|
116
|
+
Embedding ✓ text-embedding-3-small
|
|
117
|
+
Graph LLM ✓ gpt-4o-mini
|
|
118
|
+
Rerank LLM ✗
|
|
119
|
+
Counts:
|
|
120
|
+
nodes 1247
|
|
121
|
+
edges 3891
|
|
122
|
+
Healthy ✓
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Doctor Output Example
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
$ easbot codebase doctor
|
|
129
|
+
─ codebase doctor ─────────────────────────────────────────────────
|
|
130
|
+
Healthy ✓
|
|
131
|
+
Duration 127 ms
|
|
132
|
+
Backend availability:
|
|
133
|
+
- better-sqlite3 ✓
|
|
134
|
+
- node:sqlite ✗
|
|
135
|
+
- @tursodatabase/database ✗
|
|
136
|
+
DB stats:
|
|
137
|
+
page_count 768
|
|
138
|
+
page_size 4096
|
|
139
|
+
freelist_count 0
|
|
140
|
+
Checks 12 total (0 error, 0 warn, 1 info, 11 ok)
|
|
141
|
+
[ok] ✓ database: database file exists and accessible (12 ms)
|
|
142
|
+
[ok] ✓ fts: FTS5 available (8 ms)
|
|
143
|
+
[ok] ✓ vector: vector index usable (23 ms)
|
|
144
|
+
[ok] ✓ schema: schema version matches (2 ms)
|
|
145
|
+
[ok] ✓ lock: no lock contention (1 ms)
|
|
146
|
+
[ok] ✓ disk_space: sufficient (156 MB free) (3 ms)
|
|
147
|
+
[ok] ✓ orphan: no orphan records (18 ms)
|
|
148
|
+
[info] ℹ llm: LLM reachable (ping 42 ms) (42 ms)
|
|
149
|
+
[ok] ✓ fk_integrity: foreign keys consistent (15 ms)
|
|
150
|
+
[ok] ✓ parse_errors: no parse errors in index (21 ms)
|
|
151
|
+
[ok] ✓ extraction_version: extraction version matches config (2 ms)
|
|
152
|
+
[ok] ✓ embedding_dims_consistency: meta=1536 probe=1536 config=1536 (35 ms)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Key Fields
|
|
156
|
+
|
|
157
|
+
| Field | Description |
|
|
158
|
+
|-------|-------------|
|
|
159
|
+
| `LLM.initialized` | Whether LLM is initialized (valid config + reachable) |
|
|
160
|
+
| `LLM.capabilities` | Three capabilities: `embedding` / `graphLlm` / `rerankLlm`, each shows model name or ✗ |
|
|
161
|
+
| `Vector enabled` | Whether vector index is enabled |
|
|
162
|
+
| `Embedding dims` | **Probed** embedding dimension (not just from config), probed at status end and written back to meta table |
|
|
163
|
+
| `embedding_dims_consistency` | Doctor check #9: compares meta / probe / config dimensions for consistency |
|
|
164
|
+
|
|
165
|
+
### JSON Output (`--json`)
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
$ easbot codebase status --json
|
|
169
|
+
{
|
|
170
|
+
"ok": true,
|
|
171
|
+
"data": {
|
|
172
|
+
"rootDir": "E:/work/my-project",
|
|
173
|
+
"configExists": true,
|
|
174
|
+
"dbExists": true,
|
|
175
|
+
"indexState": "ready",
|
|
176
|
+
"schemaVersion": 1,
|
|
177
|
+
"llm": {
|
|
178
|
+
"initialized": true,
|
|
179
|
+
"capabilities": { "embedding": true, "graphLlm": true, "rerankLlm": false },
|
|
180
|
+
"embeddingModel": "text-embedding-3-small",
|
|
181
|
+
"graphModel": "gpt-4o-mini",
|
|
182
|
+
"providerId": "openai"
|
|
183
|
+
},
|
|
184
|
+
"counts": { "nodes": 1247, "edges": 3891 },
|
|
185
|
+
"healthy": true
|
|
186
|
+
},
|
|
187
|
+
"meta": { "scope": "all" }
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Compatible with [CLI Output Spec v1.4](file:///e:/work/apps/eas/easbot/docs/spec/cli-output-spec.md) / [Decision 0040](file:///e:/work/apps/eas/easbot/docs/decisions/0040-cli-output-unified-json.md).
|
|
192
|
+
|
|
93
193
|
## API Documentation
|
|
94
194
|
|
|
95
195
|
### CodeKnowledgeGraph
|
package/README.md
CHANGED
|
@@ -61,14 +61,22 @@ easbot codebase init --json
|
|
|
61
61
|
# "ok": true,
|
|
62
62
|
# "data": {
|
|
63
63
|
# "configPath": "<worktree>/.easbot/codebase.json",
|
|
64
|
+
# "dbPath": "<worktree>/.easbot/db/codebase.db",
|
|
64
65
|
# "backend": "better-sqlite3",
|
|
65
66
|
# "schemaVersion": 1,
|
|
66
67
|
# "created": true,
|
|
67
68
|
# "skipped": false,
|
|
68
|
-
# "
|
|
69
|
+
# "metaInitialized": true
|
|
69
70
|
# },
|
|
70
71
|
# "meta": { "action": "created" }
|
|
71
72
|
# }
|
|
73
|
+
#
|
|
74
|
+
# 决策 0076:init 现在落地三件套契约(与 memory/note 对齐):
|
|
75
|
+
# 1. <worktree>/.easbot/codebase.json — JSON config
|
|
76
|
+
# 2. <worktree>/.easbot/db/codebase.db — SQLite db(含 schema + meta 表 5 个 KV)
|
|
77
|
+
# 3. db meta 表:version / createdAt / index_state=uninitialized / indexed_with_version=unknown / schema_version
|
|
78
|
+
# 二次 init 不带 --force 时 idempotent 跳过;带 --force 时删旧 db 重建三件套。
|
|
79
|
+
# 不主动跑 sync;用户显式跑 `easbot codebase sync` 触发首次同步。
|
|
72
80
|
|
|
73
81
|
# 错误响应 schema
|
|
74
82
|
easbot codebase path <missing> --json
|
|
@@ -80,6 +88,106 @@ easbot codebase path <missing> --json
|
|
|
80
88
|
|
|
81
89
|
**豁免清单**:`watch`(服务型启动)/ `mcp`(JSON-RPC 协议)。详见 [决策 0051](file:///e:/work/apps/eas/easbot/docs/decisions/0051-cli-human-output-unify.md) + [CLI 输出规范 v1.3](file:///e:/work/apps/eas/easbot/docs/spec/cli-output-spec.md)。
|
|
82
90
|
|
|
91
|
+
## Status / Doctor 统一输出格式(决策 0073 / CLI 规范 v1.4)
|
|
92
|
+
|
|
93
|
+
`codebase status` / `codebase doctor` 与 `note` / `memory` 三包统一走 `@easbot/terminal` 的 `formatKnowledgeStatus` / `formatKnowledgeDoctor` 渲染,视觉与字段结构完全一致。
|
|
94
|
+
|
|
95
|
+
### status 输出示例
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
$ easbot codebase status
|
|
99
|
+
─ codebase status ─────────────────────────────────────────────────
|
|
100
|
+
Root directory E:/work/my-project
|
|
101
|
+
Config ✓ E:/work/my-project/.easbot/codebase.json
|
|
102
|
+
DB ✓ E:/work/my-project/.easbot/db/codebase.db (12582912 bytes)
|
|
103
|
+
Index state ready
|
|
104
|
+
Schema version 1
|
|
105
|
+
Extraction version 1
|
|
106
|
+
Backend better-sqlite3
|
|
107
|
+
Last sync 2026-08-31T14:23:11.000Z
|
|
108
|
+
Vector enabled ✓
|
|
109
|
+
Embedding dims 1536
|
|
110
|
+
LLM:
|
|
111
|
+
Initialized ✓
|
|
112
|
+
Provider openai
|
|
113
|
+
Capabilities:
|
|
114
|
+
Embedding ✓ text-embedding-3-small
|
|
115
|
+
Graph LLM ✓ gpt-4o-mini
|
|
116
|
+
Rerank LLM ✗
|
|
117
|
+
Counts:
|
|
118
|
+
nodes 1247
|
|
119
|
+
edges 3891
|
|
120
|
+
Healthy ✓
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### doctor 输出示例
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
$ easbot codebase doctor
|
|
127
|
+
─ codebase doctor ─────────────────────────────────────────────────
|
|
128
|
+
Healthy ✓
|
|
129
|
+
Duration 127 ms
|
|
130
|
+
Backend availability:
|
|
131
|
+
- better-sqlite3 ✓
|
|
132
|
+
- node:sqlite ✗
|
|
133
|
+
- @tursodatabase/database ✗
|
|
134
|
+
DB stats:
|
|
135
|
+
page_count 768
|
|
136
|
+
page_size 4096
|
|
137
|
+
freelist_count 0
|
|
138
|
+
Checks 12 total (0 error, 0 warn, 1 info, 11 ok)
|
|
139
|
+
[ok] ✓ database: database file exists and accessible (12 ms)
|
|
140
|
+
[ok] ✓ fts: FTS5 available (8 ms)
|
|
141
|
+
[ok] ✓ vector: vector index usable (23 ms)
|
|
142
|
+
[ok] ✓ schema: schema version matches (2 ms)
|
|
143
|
+
[ok] ✓ lock: no lock contention (1 ms)
|
|
144
|
+
[ok] ✓ disk_space: sufficient (156 MB free) (3 ms)
|
|
145
|
+
[ok] ✓ orphan: no orphan records (18 ms)
|
|
146
|
+
[info] ℹ llm: LLM reachable (ping 42 ms) (42 ms)
|
|
147
|
+
[ok] ✓ fk_integrity: foreign keys consistent (15 ms)
|
|
148
|
+
[ok] ✓ parse_errors: no parse errors in index (21 ms)
|
|
149
|
+
[ok] ✓ extraction_version: extraction version matches config (2 ms)
|
|
150
|
+
[ok] ✓ embedding_dims_consistency: meta=1536 probe=1536 config=1536 (35 ms)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 关键字段说明
|
|
154
|
+
|
|
155
|
+
| 字段 | 说明 |
|
|
156
|
+
|------|------|
|
|
157
|
+
| `LLM.initialized` | LLM 是否已初始化(配置有效且可达) |
|
|
158
|
+
| `LLM.capabilities` | 三大能力:`embedding` / `graphLlm` / `rerankLlm`,各显示模型名或 ✗ |
|
|
159
|
+
| `Vector enabled` | 向量索引是否启用 |
|
|
160
|
+
| `Embedding dims` | **实测** embedding 维度(非仅读 config),status 末尾探测并回填 meta 表 |
|
|
161
|
+
| `embedding_dims_consistency` | doctor 第 9 项检查:对比 meta / probe / config 三方维度是否一致 |
|
|
162
|
+
|
|
163
|
+
### JSON 输出(`--json`)
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
$ easbot codebase status --json
|
|
167
|
+
{
|
|
168
|
+
"ok": true,
|
|
169
|
+
"data": {
|
|
170
|
+
"rootDir": "E:/work/my-project",
|
|
171
|
+
"configExists": true,
|
|
172
|
+
"dbExists": true,
|
|
173
|
+
"indexState": "ready",
|
|
174
|
+
"schemaVersion": 1,
|
|
175
|
+
"llm": {
|
|
176
|
+
"initialized": true,
|
|
177
|
+
"capabilities": { "embedding": true, "graphLlm": true, "rerankLlm": false },
|
|
178
|
+
"embeddingModel": "text-embedding-3-small",
|
|
179
|
+
"graphModel": "gpt-4o-mini",
|
|
180
|
+
"providerId": "openai"
|
|
181
|
+
},
|
|
182
|
+
"counts": { "nodes": 1247, "edges": 3891 },
|
|
183
|
+
"healthy": true
|
|
184
|
+
},
|
|
185
|
+
"meta": { "scope": "all" }
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
兼容 [CLI 输出规范 v1.4](file:///e:/work/apps/eas/easbot/docs/spec/cli-output-spec.md) / [决策 0040](file:///e:/work/apps/eas/easbot/docs/decisions/0040-cli-output-unified-json.md)。
|
|
190
|
+
|
|
83
191
|
## 安装
|
|
84
192
|
|
|
85
193
|
```bash
|
|
@@ -67,19 +67,19 @@ import {a}from'./chunk-TMICZT3L.mjs';import {Log,Filesystem}from'@easbot/utils';
|
|
|
67
67
|
)`,"CREATE INDEX IF NOT EXISTS idx_parse_errors_file_path ON parse_errors(file_path)","CREATE INDEX IF NOT EXISTS idx_nodes_file_path ON nodes(file_path)","CREATE INDEX IF NOT EXISTS idx_edges_source ON edges(source)","CREATE INDEX IF NOT EXISTS idx_edges_target ON edges(target)"]}];function X(o,e=p,t={}){o.exec(`CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
68
68
|
id INTEGER PRIMARY KEY,
|
|
69
69
|
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
70
|
-
)`);let s=o.prepare("SELECT id FROM schema_migrations").all(),r=new Set(s.map(a=>a.id)),n={applied:[],pending:[],errors:[],currentVersion:Math.max(0,...s.map(a=>a.id)),targetVersion:e};for(let a of V){if(a.id>e)break;if(r.has(a.id)){n.pending.push(a.id);continue}if(t.dryRun){n.applied.push(a.id);continue}try{o.execBatch([...a.up]),o.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(a.id),r.add(a.id),n.applied.push(a.id),D.info("migration applied",{id:a.id,description:a.description});}catch(i){let
|
|
70
|
+
)`);let s=o.prepare("SELECT id FROM schema_migrations").all(),r=new Set(s.map(a=>a.id)),n={applied:[],pending:[],errors:[],currentVersion:Math.max(0,...s.map(a=>a.id)),targetVersion:e};for(let a of V){if(a.id>e)break;if(r.has(a.id)){n.pending.push(a.id);continue}if(t.dryRun){n.applied.push(a.id);continue}try{o.execBatch([...a.up]),o.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(a.id),r.add(a.id),n.applied.push(a.id),D.info("migration applied",{id:a.id,description:a.description});}catch(i){let l=i instanceof Error?i.message:String(i),T=a.up[0]??"";n.errors.push({migrationId:a.id,sql:T,error:l}),D.warn("migration step failed (may be idempotent)",{id:a.id,error:l,sqlCount:a.up.length});}}return n}function H(o){try{let e=o.prepare("SELECT id FROM schema_migrations").all();return e.length===0?0:Math.max(...e.map(t=>t.id))}catch{return 0}}var c=Filesystem.toUnixPath,E=Log.create({service:"codebase-database"}),m=2,$=class{constructor(e){a(this,"db");a(this,"dbPath");a(this,"closed",false);a(this,"ftsAvailable",false);this.dbPath=e===":memory:"?e:Filesystem.normalize(e),this.db=createSyncSqliteConnection({path:this.dbPath,backend:"better-sqlite3",walMode:true,foreignKeys:true,busyTimeoutMs:5e3}),this.db.initialize();try{this.db.pragma("synchronous = NORMAL"),this.db.pragma("cache_size = -64000"),this.db.pragma("foreign_keys = ON");}catch(t){E.warn("Failed to apply codebase PRAGMAs (synchronous / cache_size / foreign_keys)",{error:String(t)});}try{this.ensureSchema();let t=H(this.db);t>0&&this.setMeta("schema_version",String(t)),this.ftsAvailable=this.checkFtsAvailability(),this.detectAndMarkStaleOnInit();}catch(t){try{this.db.close();}catch{}throw this.closed=true,t}}ensureSchema(){try{X(this.db,p);let e=[["version","1.0.0"],["createdAt",new Date().toISOString()],["index_state","uninitialized"],["indexed_with_version","unknown"]],t=this.db.prepare("INSERT OR IGNORE INTO meta (key, value) VALUES (?, ?)");for(let[s,r]of e)t.run(s,r);}catch(e){throw E.error("ensureSchema failed",{message:e instanceof Error?e.message:String(e),cause:e instanceof Error?e.cause:void 0,stack:e instanceof Error?e.stack:void 0}),new u("Failed to create database schema",e instanceof Error?[e.message]:[String(e)])}}checkFtsAvailability(){try{return this.db.exec("SELECT * FROM nodes_fts WHERE nodes_fts MATCH 'test' LIMIT 1"),!0}catch{return false}}isFtsAvailable(){return this.ftsAvailable}insertNode(e){let t={...e,file_path:c(e.file_path)};this.db.prepare(`
|
|
71
71
|
INSERT OR REPLACE INTO nodes (id, name, ast_type, language, file_path, start_line, start_col, end_line, end_col, text, created_at)
|
|
72
72
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
73
|
-
`).run(t.id,t.name,t.ast_type,t.language,t.file_path,t.start_line,t.start_col,t.end_line,t.end_col,t.text,t.created_at),this.ftsAvailable&&this.updateFtsNode(t);}insertNodes(e){if(e.length===0)return;let t=e.map(n=>({...n,file_path:
|
|
73
|
+
`).run(t.id,t.name,t.ast_type,t.language,t.file_path,t.start_line,t.start_col,t.end_line,t.end_col,t.text,t.created_at),this.ftsAvailable&&this.updateFtsNode(t);}insertNodes(e){if(e.length===0)return;let t=e.map(n=>({...n,file_path:c(n.file_path)})),s=this.db.prepare(`
|
|
74
74
|
INSERT OR REPLACE INTO nodes (id, name, ast_type, language, file_path, start_line, start_col, end_line, end_col, text, created_at)
|
|
75
75
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
76
|
-
`);this.db.transaction(n=>{for(let a of n)s.run(a.id,a.name,a.ast_type,a.language,a.file_path,a.start_line,a.start_col,a.end_line,a.end_col,a.text,a.created_at);this.ftsAvailable&&this.updateFtsNodesInternal(n);})(t);}updateFtsNodesInternal(e){let t=this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?"),s=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?"),r=this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)");for(let n of e)try{let a=s.get(n.id);a&&t.run(a.rowid),r.run(n.id,n.name,n.ast_type,n.language,n.file_path,n.text);}catch(a){E.warn("FTS update failed for node",{nodeId:n.id,error:String(a)});}}updateFtsNode(e){try{let t=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?").get(e.id);t&&this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?").run(t.rowid),this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)").run(e.id,e.name,e.ast_type,e.language,e.file_path,e.text);}catch(t){E.warn("FTS update failed for node",{nodeId:e.id,error:String(t)});}}updateFtsNodes(e){let t=this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?"),s=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?"),r=this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)");this.db.transaction(a=>{for(let i of a)try{let
|
|
76
|
+
`);this.db.transaction(n=>{for(let a of n)s.run(a.id,a.name,a.ast_type,a.language,a.file_path,a.start_line,a.start_col,a.end_line,a.end_col,a.text,a.created_at);this.ftsAvailable&&this.updateFtsNodesInternal(n);})(t);}updateFtsNodesInternal(e){let t=this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?"),s=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?"),r=this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)");for(let n of e)try{let a=s.get(n.id);a&&t.run(a.rowid),r.run(n.id,n.name,n.ast_type,n.language,n.file_path,n.text);}catch(a){E.warn("FTS update failed for node",{nodeId:n.id,error:String(a)});}}updateFtsNode(e){try{let t=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?").get(e.id);t&&this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?").run(t.rowid),this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)").run(e.id,e.name,e.ast_type,e.language,e.file_path,e.text);}catch(t){E.warn("FTS update failed for node",{nodeId:e.id,error:String(t)});}}updateFtsNodes(e){let t=this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?"),s=this.db.prepare("SELECT rowid FROM nodes_fts WHERE id = ?"),r=this.db.prepare("INSERT INTO nodes_fts(id, name, ast_type, language, file_path, text) VALUES (?, ?, ?, ?, ?, ?)");this.db.transaction(a=>{for(let i of a)try{let l=s.get(i.id);l&&t.run(l.rowid),r.run(i.id,i.name,i.ast_type,i.language,i.file_path,i.text);}catch(l){E.warn("FTS update failed for node",{nodeId:i.id,error:String(l)});}})(e);}insertEdge(e){this.db.prepare(`
|
|
77
77
|
INSERT OR REPLACE INTO edges (id, source, target, relation, created_at)
|
|
78
78
|
VALUES (?, ?, ?, ?, ?)
|
|
79
79
|
`).run(e.id,e.source,e.target,e.relation,e.created_at);}insertEdges(e){if(e.length===0)return;let t=this.db.prepare(`
|
|
80
80
|
INSERT OR REPLACE INTO edges (id, source, target, relation, created_at)
|
|
81
81
|
VALUES (?, ?, ?, ?, ?)
|
|
82
|
-
`);this.db.transaction(r=>{for(let n of r)t.run(n.id,n.source,n.target,n.relation,n.created_at);})(e);}queryNodes(e){let t=[],s=[];e.filePath&&(t.push("file_path LIKE ?"),s.push(`%${
|
|
82
|
+
`);this.db.transaction(r=>{for(let n of r)t.run(n.id,n.source,n.target,n.relation,n.created_at);})(e);}queryNodes(e){let t=[],s=[];e.filePath&&(t.push("file_path LIKE ?"),s.push(`%${c(e.filePath)}%`)),e.astType&&(t.push("ast_type = ?"),s.push(e.astType)),e.name&&(t.push("name = ?"),s.push(e.name)),e.language&&(t.push("language = ?"),s.push(e.language));let r="SELECT * FROM nodes";t.length>0&&(r+=` WHERE ${t.join(" AND ")}`),r+=" ORDER BY file_path, start_line",e.limit&&(r+=" LIMIT ?",s.push(e.limit)),e.offset&&(r+=" OFFSET ?",s.push(e.offset));try{return this.db.prepare(r).all(...s)}catch(n){throw new g("Failed to query nodes","queryNodes",n instanceof Error?n:new Error(String(n)))}}queryEdges(e){let t=[],s=[];if(e.sourceOrTarget&&e.sourceOrTarget.length>0){let n=e.sourceOrTarget.map(()=>"?").join(",");t.push(`(source IN (${n}) OR target IN (${n}))`),s.push(...e.sourceOrTarget,...e.sourceOrTarget);}else e.source&&(t.push("source = ?"),s.push(e.source)),e.target&&(t.push("target = ?"),s.push(e.target));e.relation&&(t.push("relation = ?"),s.push(e.relation));let r="SELECT * FROM edges";t.length>0&&(r+=` WHERE ${t.join(" AND ")}`),r+=" ORDER BY created_at DESC",e.limit&&(r+=" LIMIT ?",s.push(e.limit)),e.offset&&(r+=" OFFSET ?",s.push(e.offset));try{return this.db.prepare(r).all(...s)}catch(n){throw new g("Failed to query edges","queryEdges",n instanceof Error?n:new Error(String(n)))}}queryAll(e,t){try{let s=this.db.prepare(e);return t?s.all(...t):s.all()}catch(s){throw new g("Failed to execute query","queryAll",s instanceof Error?s:new Error(String(s)))}}searchNodesFts(e,t=20){if(E.debug("searchNodesFts start",{query:e,limit:t,ftsAvailable:this.ftsAvailable}),!this.ftsAvailable)return E.debug("searchNodesFts skip - FTS not available"),[];try{let s=e.split(/\s+/).map(i=>`${i}*`).join(" ");E.debug("searchNodesFts query",{ftsQuery:s});let a=this.db.prepare(`
|
|
83
83
|
SELECT
|
|
84
84
|
nodes_fts.id,
|
|
85
85
|
nodes_fts.name,
|
|
@@ -97,21 +97,21 @@ import {a}from'./chunk-TMICZT3L.mjs';import {Log,Filesystem}from'@easbot/utils';
|
|
|
97
97
|
WHERE nodes_fts.text MATCH ?
|
|
98
98
|
ORDER BY score DESC
|
|
99
99
|
LIMIT ?
|
|
100
|
-
`).all(s,t);return E.debug("searchNodesFts done",{resultCount:a.length}),a}catch(s){return E.warn("searchNodesFts failed",{error:String(s)}),[]}}deleteNodesByFile(e){let t=
|
|
100
|
+
`).all(s,t);return E.debug("searchNodesFts done",{resultCount:a.length}),a}catch(s){return E.warn("searchNodesFts failed",{error:String(s)}),[]}}deleteNodesByFile(e){let t=c(e);if(this.ftsAvailable)try{let r=this.db.prepare("SELECT rowid FROM nodes_fts WHERE file_path = ?").all(t);for(let n of r)this.db.prepare("DELETE FROM nodes_fts WHERE rowid = ?").run(n.rowid);}catch(r){E.warn("FTS delete failed for file",{filePath:t,error:String(r)});}return this.db.prepare("DELETE FROM nodes WHERE file_path = ?").run(t).changes}deleteEdgesByFile(e){let t=c(e);return this.db.prepare(`
|
|
101
101
|
DELETE FROM edges
|
|
102
102
|
WHERE source IN (SELECT id FROM nodes WHERE file_path = ?)
|
|
103
103
|
OR target IN (SELECT id FROM nodes WHERE file_path = ?)
|
|
104
|
-
`).run(t,t).changes}getFileHash(e){return this.db.prepare("SELECT content_hash FROM file_hashes WHERE file_path = ?").get(
|
|
104
|
+
`).run(t,t).changes}getFileHash(e){return this.db.prepare("SELECT content_hash FROM file_hashes WHERE file_path = ?").get(c(e))?.content_hash??null}setFileHash(e,t){this.db.prepare(`
|
|
105
105
|
INSERT OR REPLACE INTO file_hashes (file_path, content_hash, last_modified)
|
|
106
106
|
VALUES (?, ?, ?)
|
|
107
|
-
`).run(
|
|
107
|
+
`).run(c(e),t,new Date().toISOString());}deleteFileHash(e){this.db.prepare("DELETE FROM file_hashes WHERE file_path = ?").run(c(e));}getAllFileHashes(){return this.db.prepare("SELECT * FROM file_hashes").all()}checkIntegrity(){let e=h=>this.db.prepare(h).get().c,t=h=>e(h),s={nodes:t("SELECT COUNT(*) as c FROM nodes"),edges:t("SELECT COUNT(*) as c FROM edges"),file_hashes:t("SELECT COUNT(*) as c FROM file_hashes"),fts:t("SELECT COUNT(*) as c FROM nodes_fts"),node_embeddings:t("SELECT COUNT(*) as c FROM node_embeddings"),embedding_cache:t("SELECT COUNT(*) as c FROM embedding_cache"),parse_errors:t("SELECT COUNT(*) as c FROM parse_errors"),unresolved_refs:t("SELECT COUNT(*) as c FROM unresolved_refs"),name_segment_vocab:t("SELECT COUNT(*) as c FROM name_segment_vocab"),project_metadata:t("SELECT COUNT(*) as c FROM project_metadata"),meta:t("SELECT COUNT(*) as c FROM meta")},r=[],n=t(`
|
|
108
108
|
SELECT COUNT(*) as c FROM node_embeddings e
|
|
109
109
|
LEFT JOIN nodes n ON n.id = e.node_id WHERE n.id IS NULL
|
|
110
110
|
`);n>0&&r.push({severity:"error",message:`orphan node_embeddings: ${n}`});let a=t(`
|
|
111
111
|
SELECT COUNT(*) as c FROM edges e WHERE NOT EXISTS (SELECT 1 FROM nodes n WHERE n.id = e.source)
|
|
112
112
|
`);a>0&&r.push({severity:"error",message:`orphan edges (source): ${a}`});let i=t(`
|
|
113
113
|
SELECT COUNT(*) as c FROM edges e WHERE NOT EXISTS (SELECT 1 FROM nodes n WHERE n.id = e.target)
|
|
114
|
-
`);i>0&&r.push({severity:"error",message:`orphan edges (target): ${i}`});let
|
|
114
|
+
`);i>0&&r.push({severity:"error",message:`orphan edges (target): ${i}`});let l=t("SELECT COUNT(*) as c FROM edges WHERE source = target");l>0&&r.push({severity:"error",message:`self-loop edges: ${l} \u2014 re-run \`easbot codebase sync\` to filter (fixed in Wave 4 R3-2)`});t("SELECT COUNT(DISTINCT file_path) as c FROM nodes");let f=t(`
|
|
115
115
|
SELECT COUNT(*) as c FROM file_hashes fh
|
|
116
116
|
WHERE NOT EXISTS (SELECT 1 FROM nodes n WHERE n.file_path = fh.file_path)
|
|
117
117
|
`);f>0&&r.push({severity:"warn",message:`orphan file_hashes (no nodes): ${f} \u2014 run \`easbot codebase sync\` to cleanup`});let _=t(`
|
|
@@ -128,7 +128,7 @@ import {a}from'./chunk-TMICZT3L.mjs';import {Log,Filesystem}from'@easbot/utils';
|
|
|
128
128
|
`).get(e);return s?new Float32Array(s.embedding.buffer,s.embedding.byteOffset,s.embedding.length/4):null}getVectorDims(){let e=this.db.prepare("SELECT value FROM meta WHERE key = ?").get("vectorDims");return e?parseInt(e.value,10):void 0}ensureVectorDims(e){this.db.prepare("SELECT value FROM meta WHERE key = ?").get("vectorDims")||this.db.prepare("INSERT OR IGNORE INTO meta (key, value) VALUES (?, ?)").run("vectorDims",String(e));}cacheEmbedding(e,t){if(this.db.prepare("SELECT embedding FROM embedding_cache WHERE content_hash = ?").get(e))return;this.ensureVectorDims(t.length),this.db.prepare(`
|
|
129
129
|
INSERT OR REPLACE INTO embedding_cache (content_hash, embedding)
|
|
130
130
|
VALUES (?, ?)
|
|
131
|
-
`).run(e,t);}deleteEmbeddingsByFile(e){let t=
|
|
131
|
+
`).run(e,t);}deleteEmbeddingsByFile(e){let t=c(e);return this.db.prepare(`
|
|
132
132
|
DELETE FROM node_embeddings WHERE node_id IN (SELECT id FROM nodes WHERE file_path = ?)
|
|
133
133
|
`).run(t).changes}getAllNodeEmbeddings(){return this.db.prepare("SELECT node_id, embedding FROM node_embeddings").all()}storeNodeEmbeddings(e){if(e.length===0)return;this.ensureVectorDims(e[0].embedding.length);let t=this.db.prepare(`
|
|
134
134
|
INSERT OR REPLACE INTO node_embeddings (node_id, embedding_text, embedding)
|
|
@@ -136,19 +136,19 @@ import {a}from'./chunk-TMICZT3L.mjs';import {Log,Filesystem}from'@easbot/utils';
|
|
|
136
136
|
`);this.db.transaction(r=>{for(let n of r)try{t.run(n.nodeId,n.embeddingText,n.embedding);}catch(a){E.warn("Failed to store embedding for node",{nodeId:n.nodeId,error:String(a)});}})(e);}insertParseError(e){return this.db.prepare(`
|
|
137
137
|
INSERT INTO parse_errors (file_path, language, stage, message, line)
|
|
138
138
|
VALUES (?, ?, ?, ?, ?)
|
|
139
|
-
`).run(e.filePath
|
|
139
|
+
`).run(c(e.filePath),e.language,e.stage,e.message,e.line??null).changes}insertUnresolvedRef(e){return this.db.prepare(`
|
|
140
140
|
INSERT INTO unresolved_refs
|
|
141
141
|
(from_node_id, reference_name, reference_kind, line, col, file_path, language, candidates)
|
|
142
142
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
143
|
-
`).run(e.fromNodeId??null,e.referenceName,e.referenceKind,e.line??null,e.col??null,e.filePath
|
|
143
|
+
`).run(e.fromNodeId??null,e.referenceName,e.referenceKind,e.line??null,e.col??null,c(e.filePath),e.language,e.candidates?JSON.stringify(e.candidates):null).changes}insertUnresolvedRefsBatch(e){if(e.length===0)return 0;let s=`
|
|
144
144
|
INSERT INTO unresolved_refs
|
|
145
145
|
(from_node_id, reference_name, reference_kind, line, col, file_path, language, candidates)
|
|
146
146
|
VALUES ${e.map(()=>"(?, ?, ?, ?, ?, ?, ?, ?)").join(", ")}
|
|
147
|
-
`,r=[];for(let i of e)r.push(i.fromNodeId??null,i.referenceName,i.referenceKind,i.line??null,i.col??null,i.filePath
|
|
147
|
+
`,r=[];for(let i of e)r.push(i.fromNodeId??null,i.referenceName,i.referenceKind,i.line??null,i.col??null,c(i.filePath),i.language,i.candidates?JSON.stringify(i.candidates):null);return this.db.prepare(s).run(...r).changes}insertNameSegment(e,t){return this.db.prepare(`
|
|
148
148
|
INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES (?, ?)
|
|
149
149
|
`).run(e,t).changes}insertNameSegmentsBatch(e){if(e.length===0)return 0;let s=`
|
|
150
150
|
INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ${e.map(()=>"(?, ?)").join(", ")}
|
|
151
|
-
`,r=[];for(let i of e)r.push(i.segment,i.name);return this.db.prepare(s).run(...r).changes}setProjectMetadata(e,t){return this.db.prepare(`
|
|
151
|
+
`,r=[];for(let i of e)r.push(i.segment,i.name);return this.db.prepare(s).run(...r).changes}setProjectMetadata(e,t){let s=e==="worktree"||e==="project"?c(t):t;return this.db.prepare(`
|
|
152
152
|
INSERT OR REPLACE INTO project_metadata (key, value, updated_at)
|
|
153
153
|
VALUES (?, ?, CURRENT_TIMESTAMP)
|
|
154
|
-
`).run(e,
|
|
154
|
+
`).run(e,s).changes}getNodeIdsByFile(e){let t=e.replace(/\\/g,"/");return this.db.prepare("SELECT id FROM nodes WHERE file_path = ?").all(t).map(r=>r.id)}deleteFtsByFile(e){let t=e.replace(/\\/g,"/"),s=this.getNodeIdsByFile(t);if(s.length===0)return 0;let r=this.db.prepare("DELETE FROM nodes_fts WHERE id = ?");return this.db.transaction(a=>{for(let i of a)r.run(i);})(s),s.length}initialize(){if(this.closed)throw new g("Cannot initialize closed database","initialize")}close(){if(!this.closed){this.closed=true;try{this.db.close();}catch(e){E.warn("Database close error",{error:String(e)});}}}isClosed(){return this.closed}getDbPath(){return this.dbPath}transaction(e){return this.db.transaction(e)()}getMeta(e){if(!this.db)throw new Error("Database not initialized");return this.db.prepare("SELECT value FROM meta WHERE key = ?").get(e)?.value??null}setMeta(e,t){if(!this.db)throw new Error("Database not initialized");this.db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES (?, ?)").run(e,t);}countSqliteObjects(){if(!this.db)throw new Error("Database not initialized");return this.db.prepare("SELECT COUNT(*) as n FROM sqlite_master WHERE type IN ('table', 'index', 'trigger', 'view')").get()?.n??0}deleteMeta(e){if(!this.db)throw new Error("Database not initialized");this.db.prepare("DELETE FROM meta WHERE key = ?").run(e);}};function se(o){return o.isClosed()}function re(o){return o.getDbPath()}function ne(o,e){return o.transaction(e)}export{F as a,g as b,M as c,u as d,A as e,v as f,x as g,w as h,p as i,V as j,X as k,H as l,m,$ as n,se as o,re as p,ne as q};
|