@devflow-tools/database 0.8.10 → 0.9.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/CHANGELOG.md CHANGED
@@ -3,6 +3,42 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.9.0](https://github.com/shilongfeicool/dev-flow/compare/v0.8.11...v0.9.0) (2026-07-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * auto-checker interface mismatch, memory cleanup, type safety, and L3 extraction ([bf3b6db](https://github.com/shilongfeicool/dev-flow/commit/bf3b6dbbabae9246b919461b40ad7e35352378b7))
12
+ * **mcp:** route devflow_report_event to correct telemetry endpoint ([e7a4b2f](https://github.com/shilongfeicool/dev-flow/commit/e7a4b2f9a1515c199675768fb4a549fe5a00054c))
13
+ * **telemetry:** resolve FK constraint blocking tool-call events from reaching DB ([cbfb9c3](https://github.com/shilongfeicool/dev-flow/commit/cbfb9c31d345e83fc81732053ae67a3c3c193bb7))
14
+
15
+
16
+ ### Features
17
+
18
+ * add query logger + accuracy_queries table + annotation API ([a2ccc59](https://github.com/shilongfeicool/dev-flow/commit/a2ccc592b82fbc81bb25dd5c88212d7e10bde896))
19
+ * add tool metrics pipeline — tool_metrics table, collection in post-tool-use, aggregation API ([d3452aa](https://github.com/shilongfeicool/dev-flow/commit/d3452aa195b8ec6414846432047c43bf64117c30))
20
+
21
+
22
+
23
+
24
+
25
+ ## [0.8.11](https://github.com/shilongfeicool/dev-flow/compare/v0.8.10...v0.8.11) (2026-07-10)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * **database:** add kind and workflow_run_id columns, add cleanupStaleRecords method ([b93ca4e](https://github.com/shilongfeicool/dev-flow/commit/b93ca4ede19aff7ea249c1cbca05e4b6c507d628))
31
+ * **database:** drop FK constraint, closeSession dual-path query, idempotent listSkillExecutions, session_id index ([5d9091a](https://github.com/shilongfeicool/dev-flow/commit/5d9091a9f0586c0dee247e1d8b778e4b3fa07653))
32
+
33
+
34
+ ### Features
35
+
36
+ * **database:** add sessions table, add session_id to skill_executions and tool_call_events, remove tokens_used ([1decff8](https://github.com/shilongfeicool/dev-flow/commit/1decff8ff68f3581228f4f3dc31414e0acdcac66))
37
+
38
+
39
+
40
+
41
+
6
42
  ## [0.8.10](https://github.com/shilongfeicool/dev-flow/compare/v0.8.6...v0.8.10) (2026-07-10)
7
43
 
8
44
 
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @devflow-tools/database
2
+
3
+ DevFlow 数据库层 — 基于 better-sqlite3 的 SQLite + WAL 模式持久化存储,管理 runs、tool call events、skill executions、project stats 和 settings。
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @devflow-tools/database
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { DevFlowDatabase } from '@devflow-tools/database';
15
+
16
+ const db = new DevFlowDatabase('/path/to/project');
17
+
18
+ // 记录 tool call 事件
19
+ db.insertToolCallEvent({
20
+ eventId: 'evt:123',
21
+ executionId: 'exec:456',
22
+ toolName: 'bash',
23
+ command: 'npm test',
24
+ exitCode: 0,
25
+ durationMs: 1200,
26
+ });
27
+
28
+ // 查询事件
29
+ const events = db.listToolCallEvents('exec:456');
30
+
31
+ // 项目统计
32
+ const stats = db.getProjectStats('/path/to/project');
33
+ ```
34
+
35
+ ## Features
36
+
37
+ - **SQLite + WAL 模式** — 高并发读写的本地持久化存储
38
+ - **runs 表** — AI agent 执行运行记录
39
+ - **tool_call_events 表** — 每次 tool 调用的详细事件(exitCode、stderr、output、durationMs)
40
+ - **skill_executions 表** — skill 执行生命周期管理(start → running → completed/failed)
41
+ - **project_stats 表** — 项目维度的聚合统计
42
+ - **settings 表** — KV 配置存储
43
+
44
+ ## Tables
45
+
46
+ | 表名 | 说明 |
47
+ |------|------|
48
+ | `runs` | Agent 运行记录(id、source、tool、status、token_used) |
49
+ | `tool_call_events` | Tool 调用事件(event_id、execution_id、tool_name、command、exit_code、stderr、output、is_mcp_tool) |
50
+ | `skill_executions` | Skill 执行记录(execution_id、skill_name、status、total_tool_calls、mcp_compliance_rate) |
51
+ | `project_stats` | 项目聚合统计(total_runs、successful_runs、total_tokens) |
52
+ | `settings` | KV 配置(key、value) |
53
+
54
+ ## API
55
+
56
+ - `new DevFlowDatabase(projectRoot)` — 构造函数,自动创建 `.devflow/devflow.db` 并初始化 schema
57
+ - `.insertToolCallEvent(data)` — 记录工具调用事件
58
+ - `.updateToolCallEvent(eventId, updates)` — 更新事件(如回填 output)
59
+ - `.listToolCallEvents(executionId)` — 列出某次执行的所有事件
60
+ - `.insertSkillExecution(data)` — 创建 skill 执行记录
61
+ - `.updateSkillExecution(id, data)` — 更新 skill 执行状态
62
+ - `.getProjectStats(root)` — 获取项目统计
63
+ - `.upsertProjectStats(root, data)` — 更新或插入项目统计
64
+ - `.getSetting(key)` / `.setSetting(key, value)` — KV 配置读写
65
+
66
+ ## License
67
+
68
+ MIT
@@ -15,8 +15,20 @@ export declare class DevFlowDatabase {
15
15
  setSetting(key: string, value: string): void;
16
16
  getSetting(key: string): string | null;
17
17
  deleteSetting(key: string): void;
18
+ insertSession(params: {
19
+ id: string;
20
+ projectRoot: string;
21
+ label?: string;
22
+ startedAt: number;
23
+ }): void;
24
+ getSession(id: string): any | null;
25
+ listSessions(limit: number, offset: number, projectRoot?: string): any[];
26
+ closeSession(id: string, finishedAt?: number): void;
27
+ listToolCallEventsBySession(sessionId: string): any[];
28
+ listToolCallEventsBySessions(sessionIds: string[]): Record<string, any[]>;
18
29
  insertSkillExecution(params: {
19
30
  executionId: string;
31
+ sessionId?: string;
20
32
  skillName: string;
21
33
  startedAt: number;
22
34
  status: string;
@@ -28,7 +40,6 @@ export declare class DevFlowDatabase {
28
40
  status?: string;
29
41
  finishedAt?: number;
30
42
  totalDuration?: number;
31
- totalTokens?: number;
32
43
  mcpComplianceRate?: number;
33
44
  missedMcpTools?: string[];
34
45
  totalToolCalls?: number;
@@ -40,6 +51,7 @@ export declare class DevFlowDatabase {
40
51
  insertToolCallEvent(params: {
41
52
  eventId: string;
42
53
  executionId: string;
54
+ sessionId?: string;
43
55
  timestamp: number;
44
56
  toolName: string;
45
57
  toolType: string;
@@ -47,25 +59,67 @@ export declare class DevFlowDatabase {
47
59
  mcpToolName?: string;
48
60
  mcpEnforced: boolean;
49
61
  mcpFallback: boolean;
62
+ kind?: string;
50
63
  input: unknown;
51
64
  output?: unknown;
52
- tokensUsed: number;
53
65
  duration: number;
54
66
  parentToolCallId?: string;
55
67
  subagentId?: string;
56
68
  error?: string;
57
69
  blocked: boolean;
58
70
  blockReason?: string;
71
+ workflowRunId?: string;
59
72
  }): void;
60
73
  listToolCallEvents(executionId: string): any[];
61
74
  updateToolCallEvent(eventId: string, updates: {
62
75
  output?: string;
63
76
  error?: string;
77
+ duration?: number;
64
78
  }): void;
65
79
  getMcpCompliance(): {
66
80
  overall: number;
67
81
  bySkill: Record<string, number>;
68
82
  missedTools: string[];
69
83
  };
84
+ cleanupStaleRecords(): void;
85
+ insertToolMetric(metric: {
86
+ id: string;
87
+ toolCallEventId: string;
88
+ sessionId: string;
89
+ toolName: string;
90
+ query?: string;
91
+ status?: string;
92
+ resultCount?: number;
93
+ resultSizeBytes?: number;
94
+ latencyMs?: number;
95
+ engine?: string;
96
+ accuracyQueryId?: string;
97
+ metadata?: string;
98
+ createdAt: number;
99
+ }): void;
100
+ getToolMetrics(sessionId?: string, toolName?: string, limit?: number, offset?: number): any[];
101
+ getToolMetricsSummary(days?: number): any[];
102
+ insertAccuracyQuery(q: {
103
+ id: string;
104
+ sessionId: string;
105
+ engine: string;
106
+ query: string;
107
+ topKResults: string;
108
+ selectedIds?: string;
109
+ createdAt: number;
110
+ }): void;
111
+ getAccuracyQueries(options: {
112
+ engine?: string;
113
+ status?: string;
114
+ limit?: number;
115
+ offset?: number;
116
+ }): any[];
117
+ updateAccuracyFeedback(id: string, feedback: {
118
+ relevance: 'hit' | 'partial' | 'miss';
119
+ note?: string;
120
+ }): void;
121
+ getAccuracyStats(engine?: string, since?: number): any;
122
+ all(sql: string, ...params: unknown[]): unknown[];
123
+ get(sql: string, ...params: unknown[]): unknown;
70
124
  close(): void;
71
125
  }