@winspan/claude-forge 8.34.0 → 8.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -30
- package/dist/capability/index.d.ts +6 -5
- package/dist/capability/index.d.ts.map +1 -1
- package/dist/capability/index.js +6 -5
- package/dist/capability/index.js.map +1 -1
- package/dist/capability/types.d.ts +5 -74
- package/dist/capability/types.d.ts.map +1 -1
- package/dist/capability/types.js +4 -1
- package/dist/capability/types.js.map +1 -1
- package/dist/core/ai/provider.d.ts +23 -1
- package/dist/core/ai/provider.d.ts.map +1 -1
- package/dist/core/ai/provider.js +67 -1
- package/dist/core/ai/provider.js.map +1 -1
- package/dist/core/ai/types.d.ts +28 -0
- package/dist/core/ai/types.d.ts.map +1 -1
- package/dist/core/storage/rows.d.ts +0 -36
- package/dist/core/storage/rows.d.ts.map +1 -1
- package/dist/core/storage/schema.sql +1 -45
- package/dist/core/storage/sqlite.d.ts +2 -79
- package/dist/core/storage/sqlite.d.ts.map +1 -1
- package/dist/core/storage/sqlite.js +3 -362
- package/dist/core/storage/sqlite.js.map +1 -1
- package/dist/core/utils/token-tracker.d.ts +0 -1
- package/dist/core/utils/token-tracker.d.ts.map +1 -1
- package/dist/core/utils/token-tracker.js +0 -1
- package/dist/core/utils/token-tracker.js.map +1 -1
- package/dist/daemon/handlers/post-tool-use.d.ts +1 -9
- package/dist/daemon/handlers/post-tool-use.d.ts.map +1 -1
- package/dist/daemon/handlers/post-tool-use.js +2 -99
- package/dist/daemon/handlers/post-tool-use.js.map +1 -1
- package/dist/daemon/handlers/stop.d.ts +1 -15
- package/dist/daemon/handlers/stop.d.ts.map +1 -1
- package/dist/daemon/handlers/stop.js +1 -95
- package/dist/daemon/handlers/stop.js.map +1 -1
- package/dist/daemon/handlers/user-prompt.d.ts +1 -5
- package/dist/daemon/handlers/user-prompt.d.ts.map +1 -1
- package/dist/daemon/handlers/user-prompt.js +29 -99
- package/dist/daemon/handlers/user-prompt.js.map +1 -1
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +9 -56
- package/dist/daemon/index.js.map +1 -1
- package/dist/engine/agent-router.d.ts +37 -0
- package/dist/engine/agent-router.d.ts.map +1 -1
- package/dist/engine/agent-router.js +58 -0
- package/dist/engine/agent-router.js.map +1 -1
- package/dist/engine/conventions/routing.yaml +31 -2
- package/dist/intelligence/classifier.d.ts +63 -43
- package/dist/intelligence/classifier.d.ts.map +1 -1
- package/dist/intelligence/classifier.js +256 -191
- package/dist/intelligence/classifier.js.map +1 -1
- package/dist/intelligence/context-gatherer.d.ts +101 -0
- package/dist/intelligence/context-gatherer.d.ts.map +1 -0
- package/dist/intelligence/context-gatherer.js +417 -0
- package/dist/intelligence/context-gatherer.js.map +1 -0
- package/dist/intelligence/cot-classifier.d.ts +95 -0
- package/dist/intelligence/cot-classifier.d.ts.map +1 -0
- package/dist/intelligence/cot-classifier.js +391 -0
- package/dist/intelligence/cot-classifier.js.map +1 -0
- package/dist/intelligence/execution-doc-builder.d.ts +90 -0
- package/dist/intelligence/execution-doc-builder.d.ts.map +1 -1
- package/dist/intelligence/execution-doc-builder.js +459 -42
- package/dist/intelligence/execution-doc-builder.js.map +1 -1
- package/dist/intelligence/intent-types.d.ts +13 -0
- package/dist/intelligence/intent-types.d.ts.map +1 -0
- package/dist/intelligence/intent-types.js +19 -0
- package/dist/intelligence/intent-types.js.map +1 -0
- package/dist/intelligence/multimodal-parser.d.ts +105 -0
- package/dist/intelligence/multimodal-parser.d.ts.map +1 -0
- package/dist/intelligence/multimodal-parser.js +425 -0
- package/dist/intelligence/multimodal-parser.js.map +1 -0
- package/dist/skills/official-skills.d.ts.map +1 -1
- package/dist/skills/official-skills.js +218 -20
- package/dist/skills/official-skills.js.map +1 -1
- package/dist/web/routes/status.d.ts.map +1 -1
- package/dist/web/routes/status.js +8 -10
- package/dist/web/routes/status.js.map +1 -1
- package/dist/web/routes/token-usage.d.ts +1 -1
- package/dist/web/routes/token-usage.d.ts.map +1 -1
- package/dist/web/routes/token-usage.js +1 -16
- package/dist/web/routes/token-usage.js.map +1 -1
- package/dist/web/routes/types.d.ts +0 -6
- package/dist/web/routes/types.d.ts.map +1 -1
- package/dist/web/routes/types.js.map +1 -1
- package/dist/web/server.d.ts +0 -6
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +0 -5
- package/dist/web/server.js.map +1 -1
- package/dist/web/static/assets/{AIConfig-DiUFET_Q.js → AIConfig-D4VglzCl.js} +2 -2
- package/dist/web/static/assets/{AIConfig-DiUFET_Q.js.map → AIConfig-D4VglzCl.js.map} +1 -1
- package/dist/web/static/assets/{Agents-bNNGbQnL.js → Agents-ne5lXc7V.js} +2 -2
- package/dist/web/static/assets/{Agents-bNNGbQnL.js.map → Agents-ne5lXc7V.js.map} +1 -1
- package/dist/web/static/assets/Dashboard-D4j0Zmek.js +2 -0
- package/dist/web/static/assets/Dashboard-D4j0Zmek.js.map +1 -0
- package/dist/web/static/assets/{Drawer-DOUcx6m1.js → Drawer-Lo5ihVP-.js} +2 -2
- package/dist/web/static/assets/{Drawer-DOUcx6m1.js.map → Drawer-Lo5ihVP-.js.map} +1 -1
- package/dist/web/static/assets/{Events-DQHP6Uaq.js → Events-DBJ1B7OW.js} +2 -2
- package/dist/web/static/assets/{Events-DQHP6Uaq.js.map → Events-DBJ1B7OW.js.map} +1 -1
- package/dist/web/static/assets/{ExecutionTrace-Co8ARdg-.js → ExecutionTrace-Du9XADc1.js} +2 -2
- package/dist/web/static/assets/{ExecutionTrace-Co8ARdg-.js.map → ExecutionTrace-Du9XADc1.js.map} +1 -1
- package/dist/web/static/assets/{Routing-BW3eGD-8.js → Routing-BNQ09OlH.js} +2 -2
- package/dist/web/static/assets/{Routing-BW3eGD-8.js.map → Routing-BNQ09OlH.js.map} +1 -1
- package/dist/web/static/assets/{SessionDetail-Cbd7Jwox.js → SessionDetail-BPrPyMNa.js} +2 -2
- package/dist/web/static/assets/{SessionDetail-Cbd7Jwox.js.map → SessionDetail-BPrPyMNa.js.map} +1 -1
- package/dist/web/static/assets/{Sessions-ZQSCgXyy.js → Sessions-o3EXsXz9.js} +2 -2
- package/dist/web/static/assets/{Sessions-ZQSCgXyy.js.map → Sessions-o3EXsXz9.js.map} +1 -1
- package/dist/web/static/assets/{Skills-C5-5zOSH.js → Skills-Czt5mkyc.js} +2 -2
- package/dist/web/static/assets/{Skills-C5-5zOSH.js.map → Skills-Czt5mkyc.js.map} +1 -1
- package/dist/web/static/assets/{export-CbQTOt71.js → export-C0mlC4AT.js} +2 -2
- package/dist/web/static/assets/{export-CbQTOt71.js.map → export-C0mlC4AT.js.map} +1 -1
- package/dist/web/static/assets/index-B1J7nBu0.js +3 -0
- package/dist/web/static/assets/index-B1J7nBu0.js.map +1 -0
- package/dist/web/static/assets/index-BVqk4bSO.css +1 -0
- package/dist/web/static/assets/{lucide-BanPULT1.js → lucide-Bu44HVAM.js} +33 -73
- package/dist/web/static/assets/lucide-Bu44HVAM.js.map +1 -0
- package/dist/web/static/index.html +3 -3
- package/package.json +2 -2
- package/dist/capability/execution-manager.d.ts +0 -96
- package/dist/capability/execution-manager.d.ts.map +0 -1
- package/dist/capability/execution-manager.js +0 -260
- package/dist/capability/execution-manager.js.map +0 -1
- package/dist/capability/executor/background-executor.d.ts +0 -58
- package/dist/capability/executor/background-executor.d.ts.map +0 -1
- package/dist/capability/executor/background-executor.js +0 -322
- package/dist/capability/executor/background-executor.js.map +0 -1
- package/dist/capability/executor/foreground-executor.d.ts +0 -26
- package/dist/capability/executor/foreground-executor.d.ts.map +0 -1
- package/dist/capability/executor/foreground-executor.js +0 -82
- package/dist/capability/executor/foreground-executor.js.map +0 -1
- package/dist/capability/executor/orchestrator.d.ts +0 -38
- package/dist/capability/executor/orchestrator.d.ts.map +0 -1
- package/dist/capability/executor/orchestrator.js +0 -158
- package/dist/capability/executor/orchestrator.js.map +0 -1
- package/dist/capability/executor/stream-parser.d.ts +0 -73
- package/dist/capability/executor/stream-parser.d.ts.map +0 -1
- package/dist/capability/executor/stream-parser.js +0 -56
- package/dist/capability/executor/stream-parser.js.map +0 -1
- package/dist/capability/executor/types.d.ts +0 -44
- package/dist/capability/executor/types.d.ts.map +0 -1
- package/dist/capability/executor/types.js +0 -9
- package/dist/capability/executor/types.js.map +0 -1
- package/dist/capability/executor/worker-auth-probe.d.ts +0 -30
- package/dist/capability/executor/worker-auth-probe.d.ts.map +0 -1
- package/dist/capability/executor/worker-auth-probe.js +0 -108
- package/dist/capability/executor/worker-auth-probe.js.map +0 -1
- package/dist/capability/methodologies/bmad.yaml +0 -81
- package/dist/capability/methodologies/code-quality-audit.yaml +0 -26
- package/dist/capability/methodologies/harness-engineering.yaml +0 -75
- package/dist/capability/methodologies/test-coverage-scan.yaml +0 -26
- package/dist/capability/methodology-planner.d.ts +0 -49
- package/dist/capability/methodology-planner.d.ts.map +0 -1
- package/dist/capability/methodology-planner.js +0 -306
- package/dist/capability/methodology-planner.js.map +0 -1
- package/dist/capability/methodology-registry.d.ts +0 -32
- package/dist/capability/methodology-registry.d.ts.map +0 -1
- package/dist/capability/methodology-registry.js +0 -113
- package/dist/capability/methodology-registry.js.map +0 -1
- package/dist/daemon/handlers/methodology-formatter.d.ts +0 -16
- package/dist/daemon/handlers/methodology-formatter.d.ts.map +0 -1
- package/dist/daemon/handlers/methodology-formatter.js +0 -119
- package/dist/daemon/handlers/methodology-formatter.js.map +0 -1
- package/dist/daemon/idle-detector.d.ts +0 -35
- package/dist/daemon/idle-detector.d.ts.map +0 -1
- package/dist/daemon/idle-detector.js +0 -56
- package/dist/daemon/idle-detector.js.map +0 -1
- package/dist/daemon/idle-trigger.d.ts +0 -53
- package/dist/daemon/idle-trigger.d.ts.map +0 -1
- package/dist/daemon/idle-trigger.js +0 -153
- package/dist/daemon/idle-trigger.js.map +0 -1
- package/dist/daemon/methodology-pending-queue.d.ts +0 -33
- package/dist/daemon/methodology-pending-queue.d.ts.map +0 -1
- package/dist/daemon/methodology-pending-queue.js +0 -120
- package/dist/daemon/methodology-pending-queue.js.map +0 -1
- package/dist/web/routes/methodology.d.ts +0 -12
- package/dist/web/routes/methodology.d.ts.map +0 -1
- package/dist/web/routes/methodology.js +0 -228
- package/dist/web/routes/methodology.js.map +0 -1
- package/dist/web/static/assets/Dashboard-Ciyyw6ph.js +0 -2
- package/dist/web/static/assets/Dashboard-Ciyyw6ph.js.map +0 -1
- package/dist/web/static/assets/Methodologies-CXNrDXwG.js +0 -5
- package/dist/web/static/assets/Methodologies-CXNrDXwG.js.map +0 -1
- package/dist/web/static/assets/MethodologyDetail-rV3W1utf.js +0 -2
- package/dist/web/static/assets/MethodologyDetail-rV3W1utf.js.map +0 -1
- package/dist/web/static/assets/index-DJK5beK6.js +0 -3
- package/dist/web/static/assets/index-DJK5beK6.js.map +0 -1
- package/dist/web/static/assets/index-phpuytMI.css +0 -1
- package/dist/web/static/assets/lucide-BanPULT1.js.map +0 -1
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import Database from 'better-sqlite3';
|
|
6
6
|
import { EventEmitter } from 'node:events';
|
|
7
7
|
import type { ForgeEvent } from '../types.js';
|
|
8
|
-
import type {
|
|
9
|
-
export type { EventRow, SessionRow, QualityIssueRow, DistillResultRow, ToolEventRow, DecisionRow, InjectionRow, TaskRow,
|
|
8
|
+
import type { SkillInvocationRow } from './rows.js';
|
|
9
|
+
export type { EventRow, SessionRow, QualityIssueRow, DistillResultRow, ToolEventRow, DecisionRow, InjectionRow, TaskRow, TokenUsageRow, SkillInvocationRow, } from './rows.js';
|
|
10
10
|
type DecisionLevel = 'allow' | 'warn' | 'confirm' | 'block';
|
|
11
11
|
export interface SessionSummary {
|
|
12
12
|
session_id: string;
|
|
@@ -117,24 +117,6 @@ export declare class SQLiteStorage extends EventEmitter {
|
|
|
117
117
|
* upsert 过的数据。
|
|
118
118
|
*/
|
|
119
119
|
private backfillSessionsIfNeeded;
|
|
120
|
-
/**
|
|
121
|
-
* SQLite 无法直接修改 CHECK 约束。若旧库的 phase_executions.status CHECK
|
|
122
|
-
* 还没有 'cancelled',走经典的"新表 + 拷数据 + 重命名"路径升级。
|
|
123
|
-
*
|
|
124
|
-
* 幂等:检测到当前 CREATE TABLE 语句里已有 'cancelled' 就跳过。fresh install
|
|
125
|
-
* 的库会直接命中 schema.sql 里的新定义,这里也直接跳过。
|
|
126
|
-
*/
|
|
127
|
-
private rebuildPhaseExecutionsIfNeeded;
|
|
128
|
-
/**
|
|
129
|
-
* methodology_executions.status CHECK 升级:加入 'stale' 枚举值。
|
|
130
|
-
* 幂等:CREATE TABLE 语句里已含 'stale' 则跳过;fresh install 会命中 schema.sql
|
|
131
|
-
* 的新定义,这里也跳过。
|
|
132
|
-
*
|
|
133
|
-
* 注意:必须在 addColumnIfMissing('last_progress_at' / 'retry_count' /
|
|
134
|
-
* 'original_plan_json' / 'trigger_type', ...) 之后执行,重建表时才能把它们一起
|
|
135
|
-
* 拷贝过去。重建方法内部再做一次兜底 addColumnIfMissing,避免未来新列漏同步。
|
|
136
|
-
*/
|
|
137
|
-
private rebuildMethodologyExecutionsIfNeeded;
|
|
138
120
|
getDatabase(): Database.Database;
|
|
139
121
|
getDbPath(): string;
|
|
140
122
|
writeEvent(event: ForgeEvent): void;
|
|
@@ -258,60 +240,8 @@ export declare class SQLiteStorage extends EventEmitter {
|
|
|
258
240
|
close(): void;
|
|
259
241
|
private getDbSizeMb;
|
|
260
242
|
private rowToEvent;
|
|
261
|
-
createMethodologyExecution(data: {
|
|
262
|
-
session_id: string;
|
|
263
|
-
methodology_id: string;
|
|
264
|
-
plan_json: string;
|
|
265
|
-
mode?: 'foreground' | 'background';
|
|
266
|
-
trigger_type?: 'manual' | 'idle' | 'scheduled';
|
|
267
|
-
}): number;
|
|
268
|
-
getActiveMethodologyExecution(session_id: string): MethodologyExecutionRow | null;
|
|
269
|
-
updateMethodologyExecution(id: number, data: {
|
|
270
|
-
current_phase_index?: number;
|
|
271
|
-
status?: MethodologyExecutionRow['status'];
|
|
272
|
-
completed_at?: number;
|
|
273
|
-
worker_pid?: number | null;
|
|
274
|
-
worker_session_id?: string | null;
|
|
275
|
-
last_progress_at?: number;
|
|
276
|
-
plan_json?: string;
|
|
277
|
-
retry_count?: number;
|
|
278
|
-
}): void;
|
|
279
|
-
getMethodologyExecution(id: number): MethodologyExecutionRow | null;
|
|
280
|
-
/**
|
|
281
|
-
* List all methodology_executions with status='running' and mode='background'.
|
|
282
|
-
* Used at daemon startup to detect crashed workers (worker_pid not alive).
|
|
283
|
-
*/
|
|
284
|
-
listRunningBackgroundExecutions(): MethodologyExecutionRow[];
|
|
285
|
-
/**
|
|
286
|
-
* List all methodology_executions with status='running' and mode='foreground'.
|
|
287
|
-
* Used at daemon startup to sweep stale foreground executions — rows left
|
|
288
|
-
* behind when the originating Claude session ended without Stop hook firing
|
|
289
|
-
* (crash / detach / pre-guard legacy data).
|
|
290
|
-
*/
|
|
291
|
-
listRunningForegroundExecutions(): MethodologyExecutionRow[];
|
|
292
|
-
createPhaseExecution(data: {
|
|
293
|
-
methodology_execution_id: number;
|
|
294
|
-
phase_id: string;
|
|
295
|
-
phase_index: number;
|
|
296
|
-
agent_name: string;
|
|
297
|
-
prompt: string;
|
|
298
|
-
}): number;
|
|
299
|
-
updatePhaseExecution(id: number, data: {
|
|
300
|
-
status?: PhaseExecutionRow['status'];
|
|
301
|
-
completed_at?: number;
|
|
302
|
-
artifacts_json?: string;
|
|
303
|
-
output_text?: string | null;
|
|
304
|
-
error_message?: string | null;
|
|
305
|
-
stream_log_path?: string | null;
|
|
306
|
-
}): void;
|
|
307
|
-
getPhaseExecutions(methodology_execution_id: number): PhaseExecutionRow[];
|
|
308
|
-
/**
|
|
309
|
-
* 获取指定 session 和 methodology 的最后一次 idle 触发时间
|
|
310
|
-
*/
|
|
311
|
-
getLastIdleTrigger(session_id: string, methodology_id: string): number | null;
|
|
312
243
|
recordTokenUsage(params: {
|
|
313
244
|
session_id: string;
|
|
314
|
-
methodology_execution_id?: number;
|
|
315
245
|
input_tokens: number;
|
|
316
246
|
output_tokens: number;
|
|
317
247
|
model?: string;
|
|
@@ -322,19 +252,12 @@ export declare class SQLiteStorage extends EventEmitter {
|
|
|
322
252
|
input_tokens: number;
|
|
323
253
|
output_tokens: number;
|
|
324
254
|
};
|
|
325
|
-
getTokenUsageByMethodology(methodology_execution_id: number): {
|
|
326
|
-
total_tokens: number;
|
|
327
|
-
input_tokens: number;
|
|
328
|
-
output_tokens: number;
|
|
329
|
-
};
|
|
330
255
|
listTokenUsage(filter?: {
|
|
331
256
|
session_id?: string;
|
|
332
|
-
methodology_execution_id?: number;
|
|
333
257
|
limit?: number;
|
|
334
258
|
}): Array<{
|
|
335
259
|
id: number;
|
|
336
260
|
session_id: string;
|
|
337
|
-
methodology_execution_id: number | null;
|
|
338
261
|
timestamp: number;
|
|
339
262
|
input_tokens: number;
|
|
340
263
|
output_tokens: number;
|
|
@@ -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;AAG9C,OAAO,KAAK,
|
|
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,EAEV,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ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 -78,30 +78,12 @@ 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 / last_progress_at
|
|
82
|
-
this.addColumnIfMissing('methodology_executions', 'mode', "TEXT NOT NULL DEFAULT 'foreground'");
|
|
83
|
-
this.addColumnIfMissing('methodology_executions', 'worker_pid', 'INTEGER');
|
|
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
81
|
// sessions: first_prompt — 避免 querySessions 再对 events 表做 O(sessions × events)
|
|
92
82
|
// 的相关子查询;新增列后若库里已有 sessions 但无 first_prompt,后续 backfill 会补齐。
|
|
93
83
|
this.addColumnIfMissing('sessions', 'first_prompt', 'TEXT');
|
|
94
|
-
// phase_executions: output_text / error_message / stream_log_path
|
|
95
|
-
this.addColumnIfMissing('phase_executions', 'output_text', 'TEXT');
|
|
96
|
-
this.addColumnIfMissing('phase_executions', 'error_message', 'TEXT');
|
|
97
|
-
this.addColumnIfMissing('phase_executions', 'stream_log_path', 'TEXT');
|
|
98
84
|
// routing_events: skill_confidence / skill_source (Skill 监控字段)
|
|
99
85
|
this.addColumnIfMissing('routing_events', 'skill_confidence', 'REAL');
|
|
100
86
|
this.addColumnIfMissing('routing_events', 'skill_source', 'TEXT');
|
|
101
|
-
// phase_executions.status: 升级 CHECK 约束以支持 'cancelled'
|
|
102
|
-
this.rebuildPhaseExecutionsIfNeeded();
|
|
103
|
-
// methodology_executions.status: 升级 CHECK 约束以支持 'stale'
|
|
104
|
-
this.rebuildMethodologyExecutionsIfNeeded();
|
|
105
87
|
// sessions 聚合表性能索引(幂等):start_time 用于 querySessions 的 ORDER BY
|
|
106
88
|
try {
|
|
107
89
|
this.db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_start_time ON sessions(start_time DESC)');
|
|
@@ -171,169 +153,6 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
171
153
|
logger.warn(`[SQLiteStorage] backfillSessionsIfNeeded failed: ${err}`);
|
|
172
154
|
}
|
|
173
155
|
}
|
|
174
|
-
/**
|
|
175
|
-
* SQLite 无法直接修改 CHECK 约束。若旧库的 phase_executions.status CHECK
|
|
176
|
-
* 还没有 'cancelled',走经典的"新表 + 拷数据 + 重命名"路径升级。
|
|
177
|
-
*
|
|
178
|
-
* 幂等:检测到当前 CREATE TABLE 语句里已有 'cancelled' 就跳过。fresh install
|
|
179
|
-
* 的库会直接命中 schema.sql 里的新定义,这里也直接跳过。
|
|
180
|
-
*/
|
|
181
|
-
rebuildPhaseExecutionsIfNeeded() {
|
|
182
|
-
const row = this.db
|
|
183
|
-
.prepare(`SELECT sql FROM sqlite_master WHERE type='table' AND name='phase_executions'`)
|
|
184
|
-
.get();
|
|
185
|
-
if (!row || typeof row.sql !== 'string')
|
|
186
|
-
return;
|
|
187
|
-
if (row.sql.includes(`'cancelled'`))
|
|
188
|
-
return;
|
|
189
|
-
// 兜底列齐校验:rebuild 的新表定义必须覆盖所有期望列;如果前面 addColumnIfMissing
|
|
190
|
-
// 漏补,这里最后再补一次,避免"列在旧表不存在 → 拷数据 SELECT 报 no such column"。
|
|
191
|
-
const expectedPhaseColumns = [
|
|
192
|
-
['output_text', 'TEXT'],
|
|
193
|
-
['error_message', 'TEXT'],
|
|
194
|
-
['stream_log_path', 'TEXT'],
|
|
195
|
-
];
|
|
196
|
-
for (const [col, def] of expectedPhaseColumns) {
|
|
197
|
-
this.addColumnIfMissing('phase_executions', col, def);
|
|
198
|
-
}
|
|
199
|
-
logger.info('[SQLiteStorage] migration: rebuilding phase_executions to extend status CHECK with cancelled');
|
|
200
|
-
// 列列表来自最新 schema —— 新增过的列(output_text / error_message / stream_log_path)
|
|
201
|
-
// 在前面的 addColumnIfMissing 已经补齐,这里可以安全地全量拷贝。
|
|
202
|
-
const migrate = this.db.transaction(() => {
|
|
203
|
-
this.db.exec(`
|
|
204
|
-
CREATE TABLE phase_executions_new (
|
|
205
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
206
|
-
methodology_execution_id INTEGER NOT NULL,
|
|
207
|
-
phase_id TEXT NOT NULL,
|
|
208
|
-
phase_index INTEGER NOT NULL,
|
|
209
|
-
agent_name TEXT NOT NULL,
|
|
210
|
-
prompt TEXT NOT NULL,
|
|
211
|
-
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'running', 'completed', 'failed', 'cancelled')),
|
|
212
|
-
started_at INTEGER,
|
|
213
|
-
completed_at INTEGER,
|
|
214
|
-
duration_ms INTEGER,
|
|
215
|
-
artifacts_json TEXT,
|
|
216
|
-
output_text TEXT,
|
|
217
|
-
error_message TEXT,
|
|
218
|
-
stream_log_path TEXT,
|
|
219
|
-
created_at TEXT DEFAULT (datetime('now')),
|
|
220
|
-
FOREIGN KEY (methodology_execution_id) REFERENCES methodology_executions(id)
|
|
221
|
-
);
|
|
222
|
-
`);
|
|
223
|
-
this.db.exec(`
|
|
224
|
-
INSERT INTO phase_executions_new (
|
|
225
|
-
id, methodology_execution_id, phase_id, phase_index, agent_name, prompt,
|
|
226
|
-
status, started_at, completed_at, duration_ms, artifacts_json,
|
|
227
|
-
output_text, error_message, stream_log_path, created_at
|
|
228
|
-
)
|
|
229
|
-
SELECT
|
|
230
|
-
id, methodology_execution_id, phase_id, phase_index, agent_name, prompt,
|
|
231
|
-
status, started_at, completed_at, duration_ms, artifacts_json,
|
|
232
|
-
output_text, error_message, stream_log_path, created_at
|
|
233
|
-
FROM phase_executions;
|
|
234
|
-
`);
|
|
235
|
-
this.db.exec(`DROP TABLE phase_executions;`);
|
|
236
|
-
this.db.exec(`ALTER TABLE phase_executions_new RENAME TO phase_executions;`);
|
|
237
|
-
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_phase_exec_methodology ON phase_executions(methodology_execution_id);`);
|
|
238
|
-
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_phase_exec_status ON phase_executions(status);`);
|
|
239
|
-
});
|
|
240
|
-
try {
|
|
241
|
-
migrate();
|
|
242
|
-
logger.info('[SQLiteStorage] migration: phase_executions rebuild complete');
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
logger.warn(`[SQLiteStorage] migration: phase_executions rebuild failed: ${err}`);
|
|
246
|
-
throw err;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* methodology_executions.status CHECK 升级:加入 'stale' 枚举值。
|
|
251
|
-
* 幂等:CREATE TABLE 语句里已含 'stale' 则跳过;fresh install 会命中 schema.sql
|
|
252
|
-
* 的新定义,这里也跳过。
|
|
253
|
-
*
|
|
254
|
-
* 注意:必须在 addColumnIfMissing('last_progress_at' / 'retry_count' /
|
|
255
|
-
* 'original_plan_json' / 'trigger_type', ...) 之后执行,重建表时才能把它们一起
|
|
256
|
-
* 拷贝过去。重建方法内部再做一次兜底 addColumnIfMissing,避免未来新列漏同步。
|
|
257
|
-
*/
|
|
258
|
-
rebuildMethodologyExecutionsIfNeeded() {
|
|
259
|
-
const row = this.db
|
|
260
|
-
.prepare(`SELECT sql FROM sqlite_master WHERE type='table' AND name='methodology_executions'`)
|
|
261
|
-
.get();
|
|
262
|
-
if (!row || typeof row.sql !== 'string')
|
|
263
|
-
return;
|
|
264
|
-
if (row.sql.includes(`'stale'`))
|
|
265
|
-
return;
|
|
266
|
-
// 兜底列齐校验:重建涉及到 INSERT ... SELECT,任何漏列都会让旧列被丢弃或
|
|
267
|
-
// 新列 SELECT 报 `no such column`。所有期望列这里再确认一次。
|
|
268
|
-
const expectedMethodologyColumns = [
|
|
269
|
-
['mode', "TEXT NOT NULL DEFAULT 'foreground'"],
|
|
270
|
-
['worker_pid', 'INTEGER'],
|
|
271
|
-
['worker_session_id', 'TEXT'],
|
|
272
|
-
['last_progress_at', 'INTEGER'],
|
|
273
|
-
['retry_count', 'INTEGER DEFAULT 0'],
|
|
274
|
-
['original_plan_json', 'TEXT'],
|
|
275
|
-
['trigger_type', "TEXT DEFAULT 'manual'"],
|
|
276
|
-
];
|
|
277
|
-
for (const [col, def] of expectedMethodologyColumns) {
|
|
278
|
-
this.addColumnIfMissing('methodology_executions', col, def);
|
|
279
|
-
}
|
|
280
|
-
logger.info('[SQLiteStorage] migration: rebuilding methodology_executions to extend status CHECK with stale');
|
|
281
|
-
// 重建母表会触发依赖它的外键(phase_executions.methodology_execution_id)。
|
|
282
|
-
// PRAGMA foreign_keys 不能在事务内改,所以在事务外临时关闭,完成后恢复。
|
|
283
|
-
const fkBefore = this.db.pragma('foreign_keys', { simple: true });
|
|
284
|
-
if (fkBefore)
|
|
285
|
-
this.db.pragma('foreign_keys = OFF');
|
|
286
|
-
const migrate = this.db.transaction(() => {
|
|
287
|
-
this.db.exec(`
|
|
288
|
-
CREATE TABLE methodology_executions_new (
|
|
289
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
290
|
-
session_id TEXT NOT NULL,
|
|
291
|
-
methodology_id TEXT NOT NULL,
|
|
292
|
-
plan_json TEXT NOT NULL,
|
|
293
|
-
current_phase_index INTEGER DEFAULT 0,
|
|
294
|
-
status TEXT NOT NULL DEFAULT 'running' CHECK(status IN ('running', 'completed', 'failed', 'cancelled', 'stale')),
|
|
295
|
-
started_at INTEGER NOT NULL,
|
|
296
|
-
completed_at INTEGER,
|
|
297
|
-
mode TEXT NOT NULL DEFAULT 'foreground',
|
|
298
|
-
worker_pid INTEGER,
|
|
299
|
-
worker_session_id TEXT,
|
|
300
|
-
last_progress_at INTEGER,
|
|
301
|
-
retry_count INTEGER DEFAULT 0,
|
|
302
|
-
original_plan_json TEXT,
|
|
303
|
-
trigger_type TEXT DEFAULT 'manual',
|
|
304
|
-
created_at TEXT DEFAULT (datetime('now'))
|
|
305
|
-
);
|
|
306
|
-
`);
|
|
307
|
-
this.db.exec(`
|
|
308
|
-
INSERT INTO methodology_executions_new (
|
|
309
|
-
id, session_id, methodology_id, plan_json, current_phase_index,
|
|
310
|
-
status, started_at, completed_at, mode, worker_pid, worker_session_id,
|
|
311
|
-
last_progress_at, retry_count, original_plan_json, trigger_type, created_at
|
|
312
|
-
)
|
|
313
|
-
SELECT
|
|
314
|
-
id, session_id, methodology_id, plan_json, current_phase_index,
|
|
315
|
-
status, started_at, completed_at, mode, worker_pid, worker_session_id,
|
|
316
|
-
last_progress_at, retry_count, original_plan_json, trigger_type, created_at
|
|
317
|
-
FROM methodology_executions;
|
|
318
|
-
`);
|
|
319
|
-
this.db.exec(`DROP TABLE methodology_executions;`);
|
|
320
|
-
this.db.exec(`ALTER TABLE methodology_executions_new RENAME TO methodology_executions;`);
|
|
321
|
-
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_methodology_exec_session ON methodology_executions(session_id);`);
|
|
322
|
-
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_methodology_exec_status ON methodology_executions(status);`);
|
|
323
|
-
});
|
|
324
|
-
try {
|
|
325
|
-
migrate();
|
|
326
|
-
logger.info('[SQLiteStorage] migration: methodology_executions rebuild complete');
|
|
327
|
-
}
|
|
328
|
-
catch (err) {
|
|
329
|
-
logger.warn(`[SQLiteStorage] migration: methodology_executions rebuild failed: ${err}`);
|
|
330
|
-
throw err;
|
|
331
|
-
}
|
|
332
|
-
finally {
|
|
333
|
-
if (fkBefore)
|
|
334
|
-
this.db.pragma('foreign_keys = ON');
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
156
|
getDatabase() {
|
|
338
157
|
return this.db;
|
|
339
158
|
}
|
|
@@ -828,178 +647,15 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
828
647
|
ai_response: row.ai_response || undefined,
|
|
829
648
|
};
|
|
830
649
|
}
|
|
831
|
-
// ── Methodology Executions ─────────────────────────────────────────────
|
|
832
|
-
createMethodologyExecution(data) {
|
|
833
|
-
const mode = data.mode ?? 'foreground';
|
|
834
|
-
const trigger_type = data.trigger_type ?? 'manual';
|
|
835
|
-
const now = Date.now();
|
|
836
|
-
const result = this.db.prepare(`
|
|
837
|
-
INSERT INTO methodology_executions (session_id, methodology_id, plan_json, original_plan_json, mode, trigger_type, started_at, last_progress_at, retry_count)
|
|
838
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)
|
|
839
|
-
`).run(data.session_id, data.methodology_id, data.plan_json, data.plan_json, mode, trigger_type, now, now);
|
|
840
|
-
return result.lastInsertRowid;
|
|
841
|
-
}
|
|
842
|
-
getActiveMethodologyExecution(session_id) {
|
|
843
|
-
const row = this.db.prepare(`
|
|
844
|
-
SELECT * FROM methodology_executions
|
|
845
|
-
WHERE session_id = ? AND status = 'running'
|
|
846
|
-
ORDER BY id DESC LIMIT 1
|
|
847
|
-
`).get(session_id);
|
|
848
|
-
return row ?? null;
|
|
849
|
-
}
|
|
850
|
-
updateMethodologyExecution(id, data) {
|
|
851
|
-
const updates = [];
|
|
852
|
-
const values = [];
|
|
853
|
-
if (data.current_phase_index !== undefined) {
|
|
854
|
-
updates.push('current_phase_index = ?');
|
|
855
|
-
values.push(data.current_phase_index);
|
|
856
|
-
}
|
|
857
|
-
if (data.status) {
|
|
858
|
-
updates.push('status = ?');
|
|
859
|
-
values.push(data.status);
|
|
860
|
-
}
|
|
861
|
-
if (data.completed_at) {
|
|
862
|
-
updates.push('completed_at = ?');
|
|
863
|
-
values.push(data.completed_at);
|
|
864
|
-
}
|
|
865
|
-
if (data.worker_pid !== undefined) {
|
|
866
|
-
updates.push('worker_pid = ?');
|
|
867
|
-
values.push(data.worker_pid);
|
|
868
|
-
}
|
|
869
|
-
if (data.worker_session_id !== undefined) {
|
|
870
|
-
updates.push('worker_session_id = ?');
|
|
871
|
-
values.push(data.worker_session_id);
|
|
872
|
-
}
|
|
873
|
-
if (data.last_progress_at !== undefined) {
|
|
874
|
-
updates.push('last_progress_at = ?');
|
|
875
|
-
values.push(data.last_progress_at);
|
|
876
|
-
}
|
|
877
|
-
if (data.plan_json !== undefined) {
|
|
878
|
-
updates.push('plan_json = ?');
|
|
879
|
-
values.push(data.plan_json);
|
|
880
|
-
}
|
|
881
|
-
if (data.retry_count !== undefined) {
|
|
882
|
-
updates.push('retry_count = ?');
|
|
883
|
-
values.push(data.retry_count);
|
|
884
|
-
}
|
|
885
|
-
if (updates.length > 0) {
|
|
886
|
-
values.push(id);
|
|
887
|
-
this.db.prepare(`
|
|
888
|
-
UPDATE methodology_executions
|
|
889
|
-
SET ${updates.join(', ')}
|
|
890
|
-
WHERE id = ?
|
|
891
|
-
`).run(...values);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
getMethodologyExecution(id) {
|
|
895
|
-
const row = this.db.prepare(`
|
|
896
|
-
SELECT * FROM methodology_executions WHERE id = ?
|
|
897
|
-
`).get(id);
|
|
898
|
-
return row ?? null;
|
|
899
|
-
}
|
|
900
|
-
/**
|
|
901
|
-
* List all methodology_executions with status='running' and mode='background'.
|
|
902
|
-
* Used at daemon startup to detect crashed workers (worker_pid not alive).
|
|
903
|
-
*/
|
|
904
|
-
listRunningBackgroundExecutions() {
|
|
905
|
-
return this.db.prepare(`
|
|
906
|
-
SELECT * FROM methodology_executions
|
|
907
|
-
WHERE status = 'running' AND mode = 'background'
|
|
908
|
-
ORDER BY id DESC
|
|
909
|
-
`).all();
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* List all methodology_executions with status='running' and mode='foreground'.
|
|
913
|
-
* Used at daemon startup to sweep stale foreground executions — rows left
|
|
914
|
-
* behind when the originating Claude session ended without Stop hook firing
|
|
915
|
-
* (crash / detach / pre-guard legacy data).
|
|
916
|
-
*/
|
|
917
|
-
listRunningForegroundExecutions() {
|
|
918
|
-
return this.db.prepare(`
|
|
919
|
-
SELECT * FROM methodology_executions
|
|
920
|
-
WHERE status = 'running' AND mode = 'foreground'
|
|
921
|
-
ORDER BY id DESC
|
|
922
|
-
`).all();
|
|
923
|
-
}
|
|
924
|
-
// ── Phase Executions ───────────────────────────────────────────────────
|
|
925
|
-
createPhaseExecution(data) {
|
|
926
|
-
const result = this.db.prepare(`
|
|
927
|
-
INSERT INTO phase_executions
|
|
928
|
-
(methodology_execution_id, phase_id, phase_index, agent_name, prompt, status, started_at)
|
|
929
|
-
VALUES (?, ?, ?, ?, ?, 'running', ?)
|
|
930
|
-
`).run(data.methodology_execution_id, data.phase_id, data.phase_index, data.agent_name, data.prompt, Date.now());
|
|
931
|
-
return result.lastInsertRowid;
|
|
932
|
-
}
|
|
933
|
-
updatePhaseExecution(id, data) {
|
|
934
|
-
const updates = [];
|
|
935
|
-
const values = [];
|
|
936
|
-
if (data.status) {
|
|
937
|
-
updates.push('status = ?');
|
|
938
|
-
values.push(data.status);
|
|
939
|
-
}
|
|
940
|
-
if (data.completed_at) {
|
|
941
|
-
updates.push('completed_at = ?');
|
|
942
|
-
values.push(data.completed_at);
|
|
943
|
-
if (data.status === 'completed') {
|
|
944
|
-
// SQLite UPDATE 的 SET 子句里引用列名取的是更新前的值,
|
|
945
|
-
// 不能写 `duration_ms = completed_at - started_at`(RHS 的 completed_at 仍是 NULL)。
|
|
946
|
-
// 用参数占位符复写一次 completed_at 的值,减去旧的 started_at。
|
|
947
|
-
updates.push('duration_ms = ? - started_at');
|
|
948
|
-
values.push(data.completed_at);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
if (data.artifacts_json) {
|
|
952
|
-
updates.push('artifacts_json = ?');
|
|
953
|
-
values.push(data.artifacts_json);
|
|
954
|
-
}
|
|
955
|
-
if (data.output_text !== undefined) {
|
|
956
|
-
updates.push('output_text = ?');
|
|
957
|
-
values.push(data.output_text);
|
|
958
|
-
}
|
|
959
|
-
if (data.error_message !== undefined) {
|
|
960
|
-
updates.push('error_message = ?');
|
|
961
|
-
values.push(data.error_message);
|
|
962
|
-
}
|
|
963
|
-
if (data.stream_log_path !== undefined) {
|
|
964
|
-
updates.push('stream_log_path = ?');
|
|
965
|
-
values.push(data.stream_log_path);
|
|
966
|
-
}
|
|
967
|
-
if (updates.length > 0) {
|
|
968
|
-
values.push(id);
|
|
969
|
-
this.db.prepare(`
|
|
970
|
-
UPDATE phase_executions
|
|
971
|
-
SET ${updates.join(', ')}
|
|
972
|
-
WHERE id = ?
|
|
973
|
-
`).run(...values);
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
getPhaseExecutions(methodology_execution_id) {
|
|
977
|
-
return this.db.prepare(`
|
|
978
|
-
SELECT * FROM phase_executions
|
|
979
|
-
WHERE methodology_execution_id = ?
|
|
980
|
-
ORDER BY phase_index ASC
|
|
981
|
-
`).all(methodology_execution_id);
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* 获取指定 session 和 methodology 的最后一次 idle 触发时间
|
|
985
|
-
*/
|
|
986
|
-
getLastIdleTrigger(session_id, methodology_id) {
|
|
987
|
-
const row = this.db.prepare(`
|
|
988
|
-
SELECT MAX(started_at) as last_trigger
|
|
989
|
-
FROM methodology_executions
|
|
990
|
-
WHERE session_id = ? AND methodology_id = ? AND trigger_type = 'idle'
|
|
991
|
-
`).get(session_id, methodology_id);
|
|
992
|
-
return row?.last_trigger ?? null;
|
|
993
|
-
}
|
|
994
650
|
// ── Token Usage ────────────────────────────────────────────────────────
|
|
995
651
|
recordTokenUsage(params) {
|
|
996
652
|
const total_tokens = params.input_tokens + params.output_tokens;
|
|
997
653
|
try {
|
|
998
654
|
this.db.prepare(`
|
|
999
|
-
INSERT INTO token_usage (session_id,
|
|
655
|
+
INSERT INTO token_usage (session_id, timestamp,
|
|
1000
656
|
input_tokens, output_tokens, total_tokens, model, tool_name)
|
|
1001
|
-
VALUES (?, ?, ?, ?, ?, ?,
|
|
1002
|
-
`).run(params.session_id,
|
|
657
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
658
|
+
`).run(params.session_id, Date.now(), params.input_tokens, params.output_tokens, total_tokens, params.model ?? null, params.tool_name ?? null);
|
|
1003
659
|
}
|
|
1004
660
|
catch (err) {
|
|
1005
661
|
logger.debug(`[Storage] Failed to record token usage: ${err}`);
|
|
@@ -1015,16 +671,6 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
1015
671
|
`).get(session_id);
|
|
1016
672
|
return result;
|
|
1017
673
|
}
|
|
1018
|
-
getTokenUsageByMethodology(methodology_execution_id) {
|
|
1019
|
-
const result = this.db.prepare(`
|
|
1020
|
-
SELECT
|
|
1021
|
-
COALESCE(SUM(input_tokens), 0) as input_tokens,
|
|
1022
|
-
COALESCE(SUM(output_tokens), 0) as output_tokens,
|
|
1023
|
-
COALESCE(SUM(total_tokens), 0) as total_tokens
|
|
1024
|
-
FROM token_usage WHERE methodology_execution_id = ?
|
|
1025
|
-
`).get(methodology_execution_id);
|
|
1026
|
-
return result;
|
|
1027
|
-
}
|
|
1028
674
|
listTokenUsage(filter = {}) {
|
|
1029
675
|
const conditions = [];
|
|
1030
676
|
const params = [];
|
|
@@ -1032,10 +678,6 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
1032
678
|
conditions.push('session_id = ?');
|
|
1033
679
|
params.push(filter.session_id);
|
|
1034
680
|
}
|
|
1035
|
-
if (filter.methodology_execution_id !== undefined) {
|
|
1036
|
-
conditions.push('methodology_execution_id = ?');
|
|
1037
|
-
params.push(filter.methodology_execution_id);
|
|
1038
|
-
}
|
|
1039
681
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
1040
682
|
const limit = filter.limit ?? 100;
|
|
1041
683
|
const sql = `SELECT * FROM token_usage ${where} ORDER BY timestamp DESC LIMIT ${limit}`;
|
|
@@ -1043,7 +685,6 @@ export class SQLiteStorage extends EventEmitter {
|
|
|
1043
685
|
return rows.map(r => ({
|
|
1044
686
|
id: r.id,
|
|
1045
687
|
session_id: r.session_id,
|
|
1046
|
-
methodology_execution_id: r.methodology_execution_id || null,
|
|
1047
688
|
timestamp: r.timestamp,
|
|
1048
689
|
input_tokens: r.input_tokens,
|
|
1049
690
|
output_tokens: r.output_tokens,
|