@winspan/claude-forge 8.30.0 → 8.33.2
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.md +4 -4
- package/dist/capability/execution-manager.d.ts +38 -1
- package/dist/capability/execution-manager.d.ts.map +1 -1
- package/dist/capability/execution-manager.js +93 -1
- package/dist/capability/execution-manager.js.map +1 -1
- package/dist/capability/executor/background-executor.d.ts +1 -0
- package/dist/capability/executor/background-executor.d.ts.map +1 -1
- package/dist/capability/executor/background-executor.js +27 -4
- package/dist/capability/executor/background-executor.js.map +1 -1
- package/dist/capability/executor/orchestrator.d.ts +15 -2
- package/dist/capability/executor/orchestrator.d.ts.map +1 -1
- package/dist/capability/executor/orchestrator.js +82 -3
- package/dist/capability/executor/orchestrator.js.map +1 -1
- package/dist/capability/executor/worker-auth-probe.d.ts.map +1 -1
- package/dist/capability/executor/worker-auth-probe.js +11 -2
- package/dist/capability/executor/worker-auth-probe.js.map +1 -1
- package/dist/capability/methodologies/bmad.yaml +17 -5
- package/dist/capability/methodologies/code-quality-audit.yaml +26 -0
- package/dist/capability/methodologies/harness-engineering.yaml +12 -6
- package/dist/capability/methodologies/test-coverage-scan.yaml +26 -0
- package/dist/capability/methodology-planner.d.ts +17 -1
- package/dist/capability/methodology-planner.d.ts.map +1 -1
- package/dist/capability/methodology-planner.js +125 -0
- package/dist/capability/methodology-planner.js.map +1 -1
- package/dist/capability/methodology-registry.d.ts.map +1 -1
- package/dist/capability/methodology-registry.js +21 -5
- package/dist/capability/methodology-registry.js.map +1 -1
- package/dist/capability/types.d.ts +2 -0
- package/dist/capability/types.d.ts.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +82 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/core/ai/provider.d.ts +17 -9
- package/dist/core/ai/provider.d.ts.map +1 -1
- package/dist/core/ai/provider.js +130 -23
- package/dist/core/ai/provider.js.map +1 -1
- package/dist/core/ai/types.d.ts +26 -5
- package/dist/core/ai/types.d.ts.map +1 -1
- package/dist/core/storage/rows.d.ts +153 -0
- package/dist/core/storage/rows.d.ts.map +1 -0
- package/dist/core/storage/rows.js +14 -0
- package/dist/core/storage/rows.js.map +1 -0
- package/dist/core/storage/schema.sql +26 -2
- package/dist/core/storage/sqlite.d.ts +95 -7
- package/dist/core/storage/sqlite.d.ts.map +1 -1
- package/dist/core/storage/sqlite.js +409 -22
- package/dist/core/storage/sqlite.js.map +1 -1
- package/dist/core/utils/token-tracker.d.ts +40 -0
- package/dist/core/utils/token-tracker.d.ts.map +1 -0
- package/dist/core/utils/token-tracker.js +70 -0
- package/dist/core/utils/token-tracker.js.map +1 -0
- package/dist/daemon/handlers/post-tool-use.d.ts +1 -0
- package/dist/daemon/handlers/post-tool-use.d.ts.map +1 -1
- package/dist/daemon/handlers/post-tool-use.js +7 -0
- package/dist/daemon/handlers/post-tool-use.js.map +1 -1
- package/dist/daemon/handlers/stop.d.ts +11 -0
- package/dist/daemon/handlers/stop.d.ts.map +1 -1
- package/dist/daemon/handlers/stop.js +52 -0
- package/dist/daemon/handlers/stop.js.map +1 -1
- package/dist/daemon/handlers/user-prompt.d.ts.map +1 -1
- package/dist/daemon/handlers/user-prompt.js +63 -4
- package/dist/daemon/handlers/user-prompt.js.map +1 -1
- package/dist/daemon/idle-detector.d.ts +35 -0
- package/dist/daemon/idle-detector.d.ts.map +1 -0
- package/dist/daemon/idle-detector.js +56 -0
- package/dist/daemon/idle-detector.js.map +1 -0
- package/dist/daemon/idle-trigger.d.ts +53 -0
- package/dist/daemon/idle-trigger.d.ts.map +1 -0
- package/dist/daemon/idle-trigger.js +153 -0
- package/dist/daemon/idle-trigger.js.map +1 -0
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +30 -2
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/routing-observer.d.ts +2 -1
- package/dist/daemon/routing-observer.d.ts.map +1 -1
- package/dist/daemon/routing-observer.js +117 -39
- package/dist/daemon/routing-observer.js.map +1 -1
- package/dist/engine/agent-router.d.ts +6 -0
- package/dist/engine/agent-router.d.ts.map +1 -1
- package/dist/engine/agent-router.js +13 -1
- package/dist/engine/agent-router.js.map +1 -1
- package/dist/engine/conventions/routing.yaml +15 -0
- package/dist/engine/dsl/compiler.d.ts.map +1 -1
- package/dist/engine/dsl/compiler.js +85 -3
- package/dist/engine/dsl/compiler.js.map +1 -1
- package/dist/engine/recommender.d.ts.map +1 -1
- package/dist/engine/recommender.js +10 -1
- package/dist/engine/recommender.js.map +1 -1
- package/dist/intelligence/classifier.d.ts +6 -0
- package/dist/intelligence/classifier.d.ts.map +1 -1
- package/dist/intelligence/classifier.js +57 -0
- package/dist/intelligence/classifier.js.map +1 -1
- package/dist/skills/registry.d.ts +6 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +49 -14
- package/dist/skills/registry.js.map +1 -1
- package/dist/skills/semantic-matcher.d.ts +1 -0
- package/dist/skills/semantic-matcher.d.ts.map +1 -1
- package/dist/skills/semantic-matcher.js +6 -1
- package/dist/skills/semantic-matcher.js.map +1 -1
- package/dist/web/auth-middleware.d.ts +22 -0
- package/dist/web/auth-middleware.d.ts.map +1 -0
- package/dist/web/auth-middleware.js +51 -0
- package/dist/web/auth-middleware.js.map +1 -0
- package/dist/web/routes/agents.d.ts +7 -0
- package/dist/web/routes/agents.d.ts.map +1 -0
- package/dist/web/routes/agents.js +192 -0
- package/dist/web/routes/agents.js.map +1 -0
- package/dist/web/routes/ai.d.ts +10 -0
- package/dist/web/routes/ai.d.ts.map +1 -0
- package/dist/web/routes/ai.js +197 -0
- package/dist/web/routes/ai.js.map +1 -0
- package/dist/web/routes/auth.d.ts +12 -0
- package/dist/web/routes/auth.d.ts.map +1 -0
- package/dist/web/routes/auth.js +20 -0
- package/dist/web/routes/auth.js.map +1 -0
- package/dist/web/routes/events.d.ts +11 -0
- package/dist/web/routes/events.d.ts.map +1 -0
- package/dist/web/routes/events.js +43 -0
- package/dist/web/routes/events.js.map +1 -0
- package/dist/web/routes/execution-trace.d.ts +13 -0
- package/dist/web/routes/execution-trace.d.ts.map +1 -0
- package/dist/web/routes/execution-trace.js +308 -0
- package/dist/web/routes/execution-trace.js.map +1 -0
- package/dist/web/routes/experiments.d.ts +15 -0
- package/dist/web/routes/experiments.d.ts.map +1 -0
- package/dist/web/routes/experiments.js +187 -0
- package/dist/web/routes/experiments.js.map +1 -0
- package/dist/web/routes/methodology.d.ts +12 -0
- package/dist/web/routes/methodology.d.ts.map +1 -0
- package/dist/web/routes/methodology.js +228 -0
- package/dist/web/routes/methodology.js.map +1 -0
- package/dist/web/routes/patch.d.ts +7 -0
- package/dist/web/routes/patch.d.ts.map +1 -0
- package/dist/web/routes/patch.js +106 -0
- package/dist/web/routes/patch.js.map +1 -0
- package/dist/web/routes/routing.d.ts +17 -0
- package/dist/web/routes/routing.d.ts.map +1 -0
- package/dist/web/routes/routing.js +582 -0
- package/dist/web/routes/routing.js.map +1 -0
- package/dist/web/routes/rules.d.ts +7 -0
- package/dist/web/routes/rules.d.ts.map +1 -0
- package/dist/web/routes/rules.js +105 -0
- package/dist/web/routes/rules.js.map +1 -0
- package/dist/web/routes/sessions.d.ts +10 -0
- package/dist/web/routes/sessions.d.ts.map +1 -0
- package/dist/web/routes/sessions.js +234 -0
- package/dist/web/routes/sessions.js.map +1 -0
- package/dist/web/routes/skills.d.ts +10 -0
- package/dist/web/routes/skills.d.ts.map +1 -0
- package/dist/web/routes/skills.js +272 -0
- package/dist/web/routes/skills.js.map +1 -0
- package/dist/web/routes/static.d.ts +19 -0
- package/dist/web/routes/static.d.ts.map +1 -0
- package/dist/web/routes/static.js +61 -0
- package/dist/web/routes/static.js.map +1 -0
- package/dist/web/routes/status.d.ts +7 -0
- package/dist/web/routes/status.d.ts.map +1 -0
- package/dist/web/routes/status.js +28 -0
- package/dist/web/routes/status.js.map +1 -0
- package/dist/web/routes/token-usage.d.ts +7 -0
- package/dist/web/routes/token-usage.d.ts.map +1 -0
- package/dist/web/routes/token-usage.js +33 -0
- package/dist/web/routes/token-usage.js.map +1 -0
- package/dist/web/routes/types.d.ts +40 -0
- package/dist/web/routes/types.d.ts.map +1 -0
- package/dist/web/routes/types.js +52 -0
- package/dist/web/routes/types.js.map +1 -0
- package/dist/web/server.d.ts +7 -4
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +60 -2330
- package/dist/web/server.js.map +1 -1
- package/dist/web/ssrf-guard.d.ts +35 -0
- package/dist/web/ssrf-guard.d.ts.map +1 -0
- package/dist/web/ssrf-guard.js +93 -0
- package/dist/web/ssrf-guard.js.map +1 -0
- package/dist/web/static/assets/AIConfig-Dw13rVtT.js +2 -0
- package/dist/web/static/assets/AIConfig-Dw13rVtT.js.map +1 -0
- package/dist/web/static/assets/Agents-D1p3JhQs.js +2 -0
- package/dist/web/static/assets/Agents-D1p3JhQs.js.map +1 -0
- package/dist/web/static/assets/{Events-CnA3f740.js → Events-DqzBTrly.js} +2 -2
- package/dist/web/static/assets/{Events-CnA3f740.js.map → Events-DqzBTrly.js.map} +1 -1
- package/dist/web/static/assets/{ExecutionTrace-ClPfFIQa.js → ExecutionTrace-Z-zlH0KH.js} +2 -2
- package/dist/web/static/assets/{ExecutionTrace-ClPfFIQa.js.map → ExecutionTrace-Z-zlH0KH.js.map} +1 -1
- package/dist/web/static/assets/Methodologies-Br5KOWuF.js +5 -0
- package/dist/web/static/assets/Methodologies-Br5KOWuF.js.map +1 -0
- package/dist/web/static/assets/{Sessions-DwWOKgnl.js → Sessions-DOd65EkN.js} +2 -2
- package/dist/web/static/assets/{Sessions-DwWOKgnl.js.map → Sessions-DOd65EkN.js.map} +1 -1
- package/dist/web/static/assets/Skills-zacj_uSW.js +2 -0
- package/dist/web/static/assets/Skills-zacj_uSW.js.map +1 -0
- package/dist/web/static/assets/auth-Bnf8ZcqN.js +2 -0
- package/dist/web/static/assets/auth-Bnf8ZcqN.js.map +1 -0
- package/dist/web/static/assets/index-BVpUTHdp.js +3 -0
- package/dist/web/static/assets/{index-DUYj2ek1.js.map → index-BVpUTHdp.js.map} +1 -1
- package/dist/web/static/assets/index-Drpf7sLl.css +1 -0
- package/dist/web/static/index.html +2 -2
- package/package.json +4 -3
- package/dist/web/static/assets/AIConfig-nZgwaowr.js +0 -2
- package/dist/web/static/assets/AIConfig-nZgwaowr.js.map +0 -1
- package/dist/web/static/assets/Agents-BZGXKWC7.js +0 -2
- package/dist/web/static/assets/Agents-BZGXKWC7.js.map +0 -1
- package/dist/web/static/assets/Methodologies-CAXUXeox.js +0 -2
- package/dist/web/static/assets/Methodologies-CAXUXeox.js.map +0 -1
- package/dist/web/static/assets/Skills-DhM6ALhr.js +0 -2
- package/dist/web/static/assets/Skills-DhM6ALhr.js.map +0 -1
- package/dist/web/static/assets/index-CVWult53.css +0 -1
- package/dist/web/static/assets/index-DUYj2ek1.js +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../src/core/storage/sqlite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAKtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../src/core/storage/sqlite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAKtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EACV,uBAAuB,EACvB,iBAAiB,EAElB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX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C;KACX,GAAG,KAAK,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,wBAAwB,EAAE,MAAM,GAAG,IAAI,CAAC;QACxC,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;KAC1B,CAAC;CA8BH"}
|
|
@@ -78,14 +78,258 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
78
78
|
* New columns since the base schema.sql go here.
|
|
79
79
|
*/
|
|
80
80
|
runMigrations() {
|
|
81
|
-
// methodology_executions: mode / worker_pid / worker_session_id
|
|
81
|
+
// methodology_executions: mode / worker_pid / worker_session_id / last_progress_at
|
|
82
82
|
this.addColumnIfMissing('methodology_executions', 'mode', "TEXT NOT NULL DEFAULT 'foreground'");
|
|
83
83
|
this.addColumnIfMissing('methodology_executions', 'worker_pid', 'INTEGER');
|
|
84
84
|
this.addColumnIfMissing('methodology_executions', 'worker_session_id', 'TEXT');
|
|
85
|
+
this.addColumnIfMissing('methodology_executions', 'last_progress_at', 'INTEGER');
|
|
86
|
+
// methodology_executions: retry_count / original_plan_json (failure feedback loop)
|
|
87
|
+
this.addColumnIfMissing('methodology_executions', 'retry_count', 'INTEGER DEFAULT 0');
|
|
88
|
+
this.addColumnIfMissing('methodology_executions', 'original_plan_json', 'TEXT');
|
|
89
|
+
// methodology_executions: trigger_type (idle trigger support)
|
|
90
|
+
this.addColumnIfMissing('methodology_executions', 'trigger_type', "TEXT DEFAULT 'manual'");
|
|
91
|
+
// sessions: first_prompt — 避免 querySessions 再对 events 表做 O(sessions × events)
|
|
92
|
+
// 的相关子查询;新增列后若库里已有 sessions 但无 first_prompt,后续 backfill 会补齐。
|
|
93
|
+
this.addColumnIfMissing('sessions', 'first_prompt', 'TEXT');
|
|
85
94
|
// phase_executions: output_text / error_message / stream_log_path
|
|
86
95
|
this.addColumnIfMissing('phase_executions', 'output_text', 'TEXT');
|
|
87
96
|
this.addColumnIfMissing('phase_executions', 'error_message', 'TEXT');
|
|
88
97
|
this.addColumnIfMissing('phase_executions', 'stream_log_path', 'TEXT');
|
|
98
|
+
// phase_executions.status: 升级 CHECK 约束以支持 'cancelled'
|
|
99
|
+
this.rebuildPhaseExecutionsIfNeeded();
|
|
100
|
+
// methodology_executions.status: 升级 CHECK 约束以支持 'stale'
|
|
101
|
+
this.rebuildMethodologyExecutionsIfNeeded();
|
|
102
|
+
// sessions 聚合表性能索引(幂等):start_time 用于 querySessions 的 ORDER BY
|
|
103
|
+
try {
|
|
104
|
+
this.db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_start_time ON sessions(start_time DESC)');
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
logger.warn(`[SQLiteStorage] migration: create idx_sessions_start_time failed: ${err}`);
|
|
108
|
+
}
|
|
109
|
+
// 一次性回填 sessions 聚合表(仅在 sessions 尚未对齐时触发)
|
|
110
|
+
this.backfillSessionsIfNeeded();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 将 events 表按 session_id 聚合回填到 sessions 表,仅在 sessions 尚未对齐
|
|
114
|
+
* (没有任何一行带 first_prompt)时触发。旧库升级场景:引入 sessions 聚合表 +
|
|
115
|
+
* upsert 写入路径后,历史 events 不会自动同步到 sessions,必须通过一次性回填补齐。
|
|
116
|
+
*
|
|
117
|
+
* 幂等策略:检测到已有 first_prompt 非空的聚合行就跳过;避免覆盖已被新写路径
|
|
118
|
+
* upsert 过的数据。
|
|
119
|
+
*/
|
|
120
|
+
backfillSessionsIfNeeded() {
|
|
121
|
+
const eventsExists = this.db
|
|
122
|
+
.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='events'`)
|
|
123
|
+
.get();
|
|
124
|
+
if (!eventsExists)
|
|
125
|
+
return;
|
|
126
|
+
const aggRow = this.db
|
|
127
|
+
.prepare(`SELECT COUNT(*) AS total, COUNT(first_prompt) AS with_prompt FROM sessions`)
|
|
128
|
+
.get();
|
|
129
|
+
if (aggRow.with_prompt > 0)
|
|
130
|
+
return;
|
|
131
|
+
logger.info('[SQLiteStorage] backfilling sessions aggregate from events...');
|
|
132
|
+
try {
|
|
133
|
+
const backfill = this.db.transaction(() => {
|
|
134
|
+
this.db.exec(`
|
|
135
|
+
INSERT INTO sessions (
|
|
136
|
+
session_id, project_path, status, first_prompt,
|
|
137
|
+
start_time, end_time, last_event_time, event_count
|
|
138
|
+
)
|
|
139
|
+
SELECT
|
|
140
|
+
e.session_id,
|
|
141
|
+
e.project_path,
|
|
142
|
+
'active' AS status,
|
|
143
|
+
(SELECT substr(COALESCE(e2.user_prompt, json_extract(e2.tool_input, '$.user_prompt')), 1, 200)
|
|
144
|
+
FROM events e2
|
|
145
|
+
WHERE e2.session_id = e.session_id
|
|
146
|
+
AND e2.hook_type = 'UserPromptSubmit'
|
|
147
|
+
AND (e2.user_prompt IS NOT NULL OR json_extract(e2.tool_input, '$.user_prompt') IS NOT NULL)
|
|
148
|
+
ORDER BY e2.timestamp ASC LIMIT 1) AS first_prompt,
|
|
149
|
+
MIN(e.timestamp) AS start_time,
|
|
150
|
+
MAX(e.timestamp) AS end_time,
|
|
151
|
+
MAX(e.timestamp) AS last_event_time,
|
|
152
|
+
COUNT(*) AS event_count
|
|
153
|
+
FROM events e
|
|
154
|
+
GROUP BY e.session_id, e.project_path
|
|
155
|
+
ON CONFLICT(session_id) DO UPDATE SET
|
|
156
|
+
first_prompt = COALESCE(sessions.first_prompt, excluded.first_prompt),
|
|
157
|
+
end_time = MAX(COALESCE(sessions.end_time, ''), excluded.end_time),
|
|
158
|
+
last_event_time = MAX(COALESCE(sessions.last_event_time, ''), excluded.last_event_time),
|
|
159
|
+
event_count = excluded.event_count,
|
|
160
|
+
updated_at = datetime('now')
|
|
161
|
+
`);
|
|
162
|
+
});
|
|
163
|
+
backfill();
|
|
164
|
+
const migrated = this.db.prepare('SELECT COUNT(*) AS c FROM sessions').get();
|
|
165
|
+
logger.info(`[SQLiteStorage] backfilled ${migrated.c} sessions from events`);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
logger.warn(`[SQLiteStorage] backfillSessionsIfNeeded failed: ${err}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* SQLite 无法直接修改 CHECK 约束。若旧库的 phase_executions.status CHECK
|
|
173
|
+
* 还没有 'cancelled',走经典的"新表 + 拷数据 + 重命名"路径升级。
|
|
174
|
+
*
|
|
175
|
+
* 幂等:检测到当前 CREATE TABLE 语句里已有 'cancelled' 就跳过。fresh install
|
|
176
|
+
* 的库会直接命中 schema.sql 里的新定义,这里也直接跳过。
|
|
177
|
+
*/
|
|
178
|
+
rebuildPhaseExecutionsIfNeeded() {
|
|
179
|
+
const row = this.db
|
|
180
|
+
.prepare(`SELECT sql FROM sqlite_master WHERE type='table' AND name='phase_executions'`)
|
|
181
|
+
.get();
|
|
182
|
+
if (!row || typeof row.sql !== 'string')
|
|
183
|
+
return;
|
|
184
|
+
if (row.sql.includes(`'cancelled'`))
|
|
185
|
+
return;
|
|
186
|
+
// 兜底列齐校验:rebuild 的新表定义必须覆盖所有期望列;如果前面 addColumnIfMissing
|
|
187
|
+
// 漏补,这里最后再补一次,避免"列在旧表不存在 → 拷数据 SELECT 报 no such column"。
|
|
188
|
+
const expectedPhaseColumns = [
|
|
189
|
+
['output_text', 'TEXT'],
|
|
190
|
+
['error_message', 'TEXT'],
|
|
191
|
+
['stream_log_path', 'TEXT'],
|
|
192
|
+
];
|
|
193
|
+
for (const [col, def] of expectedPhaseColumns) {
|
|
194
|
+
this.addColumnIfMissing('phase_executions', col, def);
|
|
195
|
+
}
|
|
196
|
+
logger.info('[SQLiteStorage] migration: rebuilding phase_executions to extend status CHECK with cancelled');
|
|
197
|
+
// 列列表来自最新 schema —— 新增过的列(output_text / error_message / stream_log_path)
|
|
198
|
+
// 在前面的 addColumnIfMissing 已经补齐,这里可以安全地全量拷贝。
|
|
199
|
+
const migrate = this.db.transaction(() => {
|
|
200
|
+
this.db.exec(`
|
|
201
|
+
CREATE TABLE phase_executions_new (
|
|
202
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
203
|
+
methodology_execution_id INTEGER NOT NULL,
|
|
204
|
+
phase_id TEXT NOT NULL,
|
|
205
|
+
phase_index INTEGER NOT NULL,
|
|
206
|
+
agent_name TEXT NOT NULL,
|
|
207
|
+
prompt TEXT NOT NULL,
|
|
208
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'running', 'completed', 'failed', 'cancelled')),
|
|
209
|
+
started_at INTEGER,
|
|
210
|
+
completed_at INTEGER,
|
|
211
|
+
duration_ms INTEGER,
|
|
212
|
+
artifacts_json TEXT,
|
|
213
|
+
output_text TEXT,
|
|
214
|
+
error_message TEXT,
|
|
215
|
+
stream_log_path TEXT,
|
|
216
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
217
|
+
FOREIGN KEY (methodology_execution_id) REFERENCES methodology_executions(id)
|
|
218
|
+
);
|
|
219
|
+
`);
|
|
220
|
+
this.db.exec(`
|
|
221
|
+
INSERT INTO phase_executions_new (
|
|
222
|
+
id, methodology_execution_id, phase_id, phase_index, agent_name, prompt,
|
|
223
|
+
status, started_at, completed_at, duration_ms, artifacts_json,
|
|
224
|
+
output_text, error_message, stream_log_path, created_at
|
|
225
|
+
)
|
|
226
|
+
SELECT
|
|
227
|
+
id, methodology_execution_id, phase_id, phase_index, agent_name, prompt,
|
|
228
|
+
status, started_at, completed_at, duration_ms, artifacts_json,
|
|
229
|
+
output_text, error_message, stream_log_path, created_at
|
|
230
|
+
FROM phase_executions;
|
|
231
|
+
`);
|
|
232
|
+
this.db.exec(`DROP TABLE phase_executions;`);
|
|
233
|
+
this.db.exec(`ALTER TABLE phase_executions_new RENAME TO phase_executions;`);
|
|
234
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_phase_exec_methodology ON phase_executions(methodology_execution_id);`);
|
|
235
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_phase_exec_status ON phase_executions(status);`);
|
|
236
|
+
});
|
|
237
|
+
try {
|
|
238
|
+
migrate();
|
|
239
|
+
logger.info('[SQLiteStorage] migration: phase_executions rebuild complete');
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
logger.warn(`[SQLiteStorage] migration: phase_executions rebuild failed: ${err}`);
|
|
243
|
+
throw err;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* methodology_executions.status CHECK 升级:加入 'stale' 枚举值。
|
|
248
|
+
* 幂等:CREATE TABLE 语句里已含 'stale' 则跳过;fresh install 会命中 schema.sql
|
|
249
|
+
* 的新定义,这里也跳过。
|
|
250
|
+
*
|
|
251
|
+
* 注意:必须在 addColumnIfMissing('last_progress_at' / 'retry_count' /
|
|
252
|
+
* 'original_plan_json' / 'trigger_type', ...) 之后执行,重建表时才能把它们一起
|
|
253
|
+
* 拷贝过去。重建方法内部再做一次兜底 addColumnIfMissing,避免未来新列漏同步。
|
|
254
|
+
*/
|
|
255
|
+
rebuildMethodologyExecutionsIfNeeded() {
|
|
256
|
+
const row = this.db
|
|
257
|
+
.prepare(`SELECT sql FROM sqlite_master WHERE type='table' AND name='methodology_executions'`)
|
|
258
|
+
.get();
|
|
259
|
+
if (!row || typeof row.sql !== 'string')
|
|
260
|
+
return;
|
|
261
|
+
if (row.sql.includes(`'stale'`))
|
|
262
|
+
return;
|
|
263
|
+
// 兜底列齐校验:重建涉及到 INSERT ... SELECT,任何漏列都会让旧列被丢弃或
|
|
264
|
+
// 新列 SELECT 报 `no such column`。所有期望列这里再确认一次。
|
|
265
|
+
const expectedMethodologyColumns = [
|
|
266
|
+
['mode', "TEXT NOT NULL DEFAULT 'foreground'"],
|
|
267
|
+
['worker_pid', 'INTEGER'],
|
|
268
|
+
['worker_session_id', 'TEXT'],
|
|
269
|
+
['last_progress_at', 'INTEGER'],
|
|
270
|
+
['retry_count', 'INTEGER DEFAULT 0'],
|
|
271
|
+
['original_plan_json', 'TEXT'],
|
|
272
|
+
['trigger_type', "TEXT DEFAULT 'manual'"],
|
|
273
|
+
];
|
|
274
|
+
for (const [col, def] of expectedMethodologyColumns) {
|
|
275
|
+
this.addColumnIfMissing('methodology_executions', col, def);
|
|
276
|
+
}
|
|
277
|
+
logger.info('[SQLiteStorage] migration: rebuilding methodology_executions to extend status CHECK with stale');
|
|
278
|
+
// 重建母表会触发依赖它的外键(phase_executions.methodology_execution_id)。
|
|
279
|
+
// PRAGMA foreign_keys 不能在事务内改,所以在事务外临时关闭,完成后恢复。
|
|
280
|
+
const fkBefore = this.db.pragma('foreign_keys', { simple: true });
|
|
281
|
+
if (fkBefore)
|
|
282
|
+
this.db.pragma('foreign_keys = OFF');
|
|
283
|
+
const migrate = this.db.transaction(() => {
|
|
284
|
+
this.db.exec(`
|
|
285
|
+
CREATE TABLE methodology_executions_new (
|
|
286
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
287
|
+
session_id TEXT NOT NULL,
|
|
288
|
+
methodology_id TEXT NOT NULL,
|
|
289
|
+
plan_json TEXT NOT NULL,
|
|
290
|
+
current_phase_index INTEGER DEFAULT 0,
|
|
291
|
+
status TEXT NOT NULL DEFAULT 'running' CHECK(status IN ('running', 'completed', 'failed', 'cancelled', 'stale')),
|
|
292
|
+
started_at INTEGER NOT NULL,
|
|
293
|
+
completed_at INTEGER,
|
|
294
|
+
mode TEXT NOT NULL DEFAULT 'foreground',
|
|
295
|
+
worker_pid INTEGER,
|
|
296
|
+
worker_session_id TEXT,
|
|
297
|
+
last_progress_at INTEGER,
|
|
298
|
+
retry_count INTEGER DEFAULT 0,
|
|
299
|
+
original_plan_json TEXT,
|
|
300
|
+
trigger_type TEXT DEFAULT 'manual',
|
|
301
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
302
|
+
);
|
|
303
|
+
`);
|
|
304
|
+
this.db.exec(`
|
|
305
|
+
INSERT INTO methodology_executions_new (
|
|
306
|
+
id, session_id, methodology_id, plan_json, current_phase_index,
|
|
307
|
+
status, started_at, completed_at, mode, worker_pid, worker_session_id,
|
|
308
|
+
last_progress_at, retry_count, original_plan_json, trigger_type, created_at
|
|
309
|
+
)
|
|
310
|
+
SELECT
|
|
311
|
+
id, session_id, methodology_id, plan_json, current_phase_index,
|
|
312
|
+
status, started_at, completed_at, mode, worker_pid, worker_session_id,
|
|
313
|
+
last_progress_at, retry_count, original_plan_json, trigger_type, created_at
|
|
314
|
+
FROM methodology_executions;
|
|
315
|
+
`);
|
|
316
|
+
this.db.exec(`DROP TABLE methodology_executions;`);
|
|
317
|
+
this.db.exec(`ALTER TABLE methodology_executions_new RENAME TO methodology_executions;`);
|
|
318
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_methodology_exec_session ON methodology_executions(session_id);`);
|
|
319
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_methodology_exec_status ON methodology_executions(status);`);
|
|
320
|
+
});
|
|
321
|
+
try {
|
|
322
|
+
migrate();
|
|
323
|
+
logger.info('[SQLiteStorage] migration: methodology_executions rebuild complete');
|
|
324
|
+
}
|
|
325
|
+
catch (err) {
|
|
326
|
+
logger.warn(`[SQLiteStorage] migration: methodology_executions rebuild failed: ${err}`);
|
|
327
|
+
throw err;
|
|
328
|
+
}
|
|
329
|
+
finally {
|
|
330
|
+
if (fkBefore)
|
|
331
|
+
this.db.pragma('foreign_keys = ON');
|
|
332
|
+
}
|
|
89
333
|
}
|
|
90
334
|
getDatabase() {
|
|
91
335
|
return this.db;
|
|
@@ -102,8 +346,52 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
102
346
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
|
|
103
347
|
`);
|
|
104
348
|
stmt.run(eventId, event.session_id, event.project_path, event.timestamp, event.hook_type, event.tool_name ?? null, event.tool_input ? JSON.stringify(event.tool_input) : null, event.tool_output ? JSON.stringify(event.tool_output) : null, event.user_prompt ?? null, event.ai_response ?? null);
|
|
349
|
+
// 聚合到 sessions 表。单独 try/catch:一旦聚合失败(比如 schema 升级过程中
|
|
350
|
+
// 的短暂窗口),也不能影响原事件的持久化,上层已经 commit 过 events 了。
|
|
351
|
+
try {
|
|
352
|
+
this.upsertSession(event);
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
logger.warn(`[SQLiteStorage] upsertSession failed (event still written): ${err}`);
|
|
356
|
+
}
|
|
105
357
|
this.emit('event', { ...event, event_id: eventId });
|
|
106
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* 将事件聚合到 sessions 表,供 querySessions 直接读取,避免对 events 做 O(n²)
|
|
361
|
+
* 的 GROUP BY + 相关子查询。
|
|
362
|
+
*
|
|
363
|
+
* 语义:
|
|
364
|
+
* - 首次出现 session_id → 插入一行,start/end/last_event_time 都取当前事件时间戳
|
|
365
|
+
* - 已存在 → event_count += 1,end/last_event_time 取更晚的,first_prompt 只在
|
|
366
|
+
* 原值为 NULL 时才被 UserPromptSubmit 的前 200 字填充(保留"首条"语义)
|
|
367
|
+
* - 非 UserPromptSubmit 事件或 user_prompt 为空时 first_prompt 传 NULL,不会
|
|
368
|
+
* 覆盖已有值
|
|
369
|
+
*/
|
|
370
|
+
upsertSession(event) {
|
|
371
|
+
const firstPrompt = event.hook_type === 'UserPromptSubmit' && event.user_prompt
|
|
372
|
+
? event.user_prompt.slice(0, 200)
|
|
373
|
+
: null;
|
|
374
|
+
const stmt = this.db.prepare(`
|
|
375
|
+
INSERT INTO sessions (
|
|
376
|
+
session_id, project_path, status, first_prompt,
|
|
377
|
+
start_time, end_time, last_event_time, event_count
|
|
378
|
+
)
|
|
379
|
+
VALUES (?, ?, 'active', ?, ?, ?, ?, 1)
|
|
380
|
+
ON CONFLICT(session_id) DO UPDATE SET
|
|
381
|
+
end_time = CASE
|
|
382
|
+
WHEN excluded.end_time > COALESCE(sessions.end_time, '') THEN excluded.end_time
|
|
383
|
+
ELSE sessions.end_time
|
|
384
|
+
END,
|
|
385
|
+
last_event_time = CASE
|
|
386
|
+
WHEN excluded.last_event_time > COALESCE(sessions.last_event_time, '') THEN excluded.last_event_time
|
|
387
|
+
ELSE sessions.last_event_time
|
|
388
|
+
END,
|
|
389
|
+
event_count = COALESCE(sessions.event_count, 0) + 1,
|
|
390
|
+
first_prompt = COALESCE(sessions.first_prompt, excluded.first_prompt),
|
|
391
|
+
updated_at = datetime('now')
|
|
392
|
+
`);
|
|
393
|
+
stmt.run(event.session_id, event.project_path, firstPrompt, event.timestamp, event.timestamp, event.timestamp);
|
|
394
|
+
}
|
|
107
395
|
writeToolEvent(event) {
|
|
108
396
|
const stmt = this.db.prepare(`
|
|
109
397
|
INSERT INTO v2_tool_events (session_id, route_request_id, tool, args, result, success, error, timestamp)
|
|
@@ -181,33 +469,31 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
181
469
|
const conditions = [];
|
|
182
470
|
const params = [];
|
|
183
471
|
if (filter.project_path) {
|
|
184
|
-
conditions.push('
|
|
472
|
+
conditions.push('project_path = ?');
|
|
185
473
|
params.push(filter.project_path);
|
|
186
474
|
}
|
|
187
475
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
188
476
|
const limit = filter.limit ?? 10;
|
|
477
|
+
// 直接读 sessions 聚合表 → O(sessions)。writeEvent 的 upsertSession 路径保证
|
|
478
|
+
// 每次事件写入都会同步更新此表;旧库在 runMigrations 里由 backfillSessionsIfNeeded
|
|
479
|
+
// 一次性回填,确保历史 session 也可见。
|
|
189
480
|
const sql = `
|
|
190
481
|
SELECT
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
WHERE e2.session_id = e.session_id AND e2.hook_type = 'UserPromptSubmit'
|
|
198
|
-
AND (e2.user_prompt IS NOT NULL OR json_extract(e2.tool_input, '$.user_prompt') IS NOT NULL)
|
|
199
|
-
ORDER BY e2.timestamp ASC LIMIT 1) as first_prompt
|
|
200
|
-
FROM events e
|
|
482
|
+
session_id,
|
|
483
|
+
first_prompt,
|
|
484
|
+
event_count,
|
|
485
|
+
start_time,
|
|
486
|
+
COALESCE(end_time, last_event_time, start_time) AS end_time
|
|
487
|
+
FROM sessions
|
|
201
488
|
${where}
|
|
202
|
-
|
|
203
|
-
ORDER BY MAX(e.timestamp) DESC
|
|
489
|
+
ORDER BY start_time DESC
|
|
204
490
|
LIMIT ${limit}
|
|
205
491
|
`;
|
|
206
492
|
const rows = this.db.prepare(sql).all(...params);
|
|
207
493
|
return rows.map(r => ({
|
|
208
494
|
session_id: r.session_id,
|
|
209
495
|
first_prompt: r.first_prompt || '',
|
|
210
|
-
event_count: r.event_count,
|
|
496
|
+
event_count: r.event_count ?? 0,
|
|
211
497
|
start_time: r.start_time,
|
|
212
498
|
end_time: r.end_time,
|
|
213
499
|
}));
|
|
@@ -542,18 +828,21 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
542
828
|
// ── Methodology Executions ─────────────────────────────────────────────
|
|
543
829
|
createMethodologyExecution(data) {
|
|
544
830
|
const mode = data.mode ?? 'foreground';
|
|
831
|
+
const trigger_type = data.trigger_type ?? 'manual';
|
|
832
|
+
const now = Date.now();
|
|
545
833
|
const result = this.db.prepare(`
|
|
546
|
-
INSERT INTO methodology_executions (session_id, methodology_id, plan_json, mode, started_at)
|
|
547
|
-
VALUES (?, ?, ?, ?,
|
|
548
|
-
`).run(data.session_id, data.methodology_id, data.plan_json, mode,
|
|
834
|
+
INSERT INTO methodology_executions (session_id, methodology_id, plan_json, original_plan_json, mode, trigger_type, started_at, last_progress_at, retry_count)
|
|
835
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)
|
|
836
|
+
`).run(data.session_id, data.methodology_id, data.plan_json, data.plan_json, mode, trigger_type, now, now);
|
|
549
837
|
return result.lastInsertRowid;
|
|
550
838
|
}
|
|
551
839
|
getActiveMethodologyExecution(session_id) {
|
|
552
|
-
|
|
840
|
+
const row = this.db.prepare(`
|
|
553
841
|
SELECT * FROM methodology_executions
|
|
554
842
|
WHERE session_id = ? AND status = 'running'
|
|
555
843
|
ORDER BY id DESC LIMIT 1
|
|
556
|
-
`).get(session_id)
|
|
844
|
+
`).get(session_id);
|
|
845
|
+
return row ?? null;
|
|
557
846
|
}
|
|
558
847
|
updateMethodologyExecution(id, data) {
|
|
559
848
|
const updates = [];
|
|
@@ -578,6 +867,18 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
578
867
|
updates.push('worker_session_id = ?');
|
|
579
868
|
values.push(data.worker_session_id);
|
|
580
869
|
}
|
|
870
|
+
if (data.last_progress_at !== undefined) {
|
|
871
|
+
updates.push('last_progress_at = ?');
|
|
872
|
+
values.push(data.last_progress_at);
|
|
873
|
+
}
|
|
874
|
+
if (data.plan_json !== undefined) {
|
|
875
|
+
updates.push('plan_json = ?');
|
|
876
|
+
values.push(data.plan_json);
|
|
877
|
+
}
|
|
878
|
+
if (data.retry_count !== undefined) {
|
|
879
|
+
updates.push('retry_count = ?');
|
|
880
|
+
values.push(data.retry_count);
|
|
881
|
+
}
|
|
581
882
|
if (updates.length > 0) {
|
|
582
883
|
values.push(id);
|
|
583
884
|
this.db.prepare(`
|
|
@@ -588,9 +889,10 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
588
889
|
}
|
|
589
890
|
}
|
|
590
891
|
getMethodologyExecution(id) {
|
|
591
|
-
|
|
892
|
+
const row = this.db.prepare(`
|
|
592
893
|
SELECT * FROM methodology_executions WHERE id = ?
|
|
593
|
-
`).get(id)
|
|
894
|
+
`).get(id);
|
|
895
|
+
return row ?? null;
|
|
594
896
|
}
|
|
595
897
|
/**
|
|
596
898
|
* List all methodology_executions with status='running' and mode='background'.
|
|
@@ -603,6 +905,19 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
603
905
|
ORDER BY id DESC
|
|
604
906
|
`).all();
|
|
605
907
|
}
|
|
908
|
+
/**
|
|
909
|
+
* List all methodology_executions with status='running' and mode='foreground'.
|
|
910
|
+
* Used at daemon startup to sweep stale foreground executions — rows left
|
|
911
|
+
* behind when the originating Claude session ended without Stop hook firing
|
|
912
|
+
* (crash / detach / pre-guard legacy data).
|
|
913
|
+
*/
|
|
914
|
+
listRunningForegroundExecutions() {
|
|
915
|
+
return this.db.prepare(`
|
|
916
|
+
SELECT * FROM methodology_executions
|
|
917
|
+
WHERE status = 'running' AND mode = 'foreground'
|
|
918
|
+
ORDER BY id DESC
|
|
919
|
+
`).all();
|
|
920
|
+
}
|
|
606
921
|
// ── Phase Executions ───────────────────────────────────────────────────
|
|
607
922
|
createPhaseExecution(data) {
|
|
608
923
|
const result = this.db.prepare(`
|
|
@@ -662,5 +977,77 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
662
977
|
ORDER BY phase_index ASC
|
|
663
978
|
`).all(methodology_execution_id);
|
|
664
979
|
}
|
|
980
|
+
/**
|
|
981
|
+
* 获取指定 session 和 methodology 的最后一次 idle 触发时间
|
|
982
|
+
*/
|
|
983
|
+
getLastIdleTrigger(session_id, methodology_id) {
|
|
984
|
+
const row = this.db.prepare(`
|
|
985
|
+
SELECT MAX(started_at) as last_trigger
|
|
986
|
+
FROM methodology_executions
|
|
987
|
+
WHERE session_id = ? AND methodology_id = ? AND trigger_type = 'idle'
|
|
988
|
+
`).get(session_id, methodology_id);
|
|
989
|
+
return row?.last_trigger ?? null;
|
|
990
|
+
}
|
|
991
|
+
// ── Token Usage ────────────────────────────────────────────────────────
|
|
992
|
+
recordTokenUsage(params) {
|
|
993
|
+
const total_tokens = params.input_tokens + params.output_tokens;
|
|
994
|
+
try {
|
|
995
|
+
this.db.prepare(`
|
|
996
|
+
INSERT INTO token_usage (session_id, methodology_execution_id, timestamp,
|
|
997
|
+
input_tokens, output_tokens, total_tokens, model, tool_name)
|
|
998
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
999
|
+
`).run(params.session_id, params.methodology_execution_id ?? null, Date.now(), params.input_tokens, params.output_tokens, total_tokens, params.model ?? null, params.tool_name ?? null);
|
|
1000
|
+
}
|
|
1001
|
+
catch (err) {
|
|
1002
|
+
logger.debug(`[Storage] Failed to record token usage: ${err}`);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
getTokenUsageBySession(session_id) {
|
|
1006
|
+
const result = this.db.prepare(`
|
|
1007
|
+
SELECT
|
|
1008
|
+
COALESCE(SUM(input_tokens), 0) as input_tokens,
|
|
1009
|
+
COALESCE(SUM(output_tokens), 0) as output_tokens,
|
|
1010
|
+
COALESCE(SUM(total_tokens), 0) as total_tokens
|
|
1011
|
+
FROM token_usage WHERE session_id = ?
|
|
1012
|
+
`).get(session_id);
|
|
1013
|
+
return result;
|
|
1014
|
+
}
|
|
1015
|
+
getTokenUsageByMethodology(methodology_execution_id) {
|
|
1016
|
+
const result = this.db.prepare(`
|
|
1017
|
+
SELECT
|
|
1018
|
+
COALESCE(SUM(input_tokens), 0) as input_tokens,
|
|
1019
|
+
COALESCE(SUM(output_tokens), 0) as output_tokens,
|
|
1020
|
+
COALESCE(SUM(total_tokens), 0) as total_tokens
|
|
1021
|
+
FROM token_usage WHERE methodology_execution_id = ?
|
|
1022
|
+
`).get(methodology_execution_id);
|
|
1023
|
+
return result;
|
|
1024
|
+
}
|
|
1025
|
+
listTokenUsage(filter = {}) {
|
|
1026
|
+
const conditions = [];
|
|
1027
|
+
const params = [];
|
|
1028
|
+
if (filter.session_id) {
|
|
1029
|
+
conditions.push('session_id = ?');
|
|
1030
|
+
params.push(filter.session_id);
|
|
1031
|
+
}
|
|
1032
|
+
if (filter.methodology_execution_id !== undefined) {
|
|
1033
|
+
conditions.push('methodology_execution_id = ?');
|
|
1034
|
+
params.push(filter.methodology_execution_id);
|
|
1035
|
+
}
|
|
1036
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
1037
|
+
const limit = filter.limit ?? 100;
|
|
1038
|
+
const sql = `SELECT * FROM token_usage ${where} ORDER BY timestamp DESC LIMIT ${limit}`;
|
|
1039
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
1040
|
+
return rows.map(r => ({
|
|
1041
|
+
id: r.id,
|
|
1042
|
+
session_id: r.session_id,
|
|
1043
|
+
methodology_execution_id: r.methodology_execution_id || null,
|
|
1044
|
+
timestamp: r.timestamp,
|
|
1045
|
+
input_tokens: r.input_tokens,
|
|
1046
|
+
output_tokens: r.output_tokens,
|
|
1047
|
+
total_tokens: r.total_tokens,
|
|
1048
|
+
model: r.model || null,
|
|
1049
|
+
tool_name: r.tool_name || null,
|
|
1050
|
+
}));
|
|
1051
|
+
}
|
|
665
1052
|
}
|
|
666
1053
|
//# sourceMappingURL=sqlite.js.map
|