@ai-setting/roy-agent-core 1.5.13-test → 1.5.15-test

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.
Files changed (141) hide show
  1. package/package.json +1 -1
  2. package/dist/config/index.d.ts +0 -1250
  3. package/dist/config/index.js +0 -32
  4. package/dist/env/agent/index.d.ts +0 -2279
  5. package/dist/env/agent/index.js +0 -24
  6. package/dist/env/commands/index.d.ts +0 -1131
  7. package/dist/env/commands/index.js +0 -14
  8. package/dist/env/debug/formatters/index.d.ts +0 -236
  9. package/dist/env/debug/formatters/index.js +0 -11
  10. package/dist/env/debug/index.d.ts +0 -1652
  11. package/dist/env/debug/index.js +0 -26
  12. package/dist/env/hook/index.d.ts +0 -279
  13. package/dist/env/hook/index.js +0 -29
  14. package/dist/env/index.d.ts +0 -3481
  15. package/dist/env/index.js +0 -82
  16. package/dist/env/llm/index.d.ts +0 -1760
  17. package/dist/env/llm/index.js +0 -40
  18. package/dist/env/log-trace/index.d.ts +0 -1574
  19. package/dist/env/log-trace/index.js +0 -83
  20. package/dist/env/mcp/index.d.ts +0 -1331
  21. package/dist/env/mcp/index.js +0 -39
  22. package/dist/env/mcp/tool/index.d.ts +0 -183
  23. package/dist/env/mcp/tool/index.js +0 -14
  24. package/dist/env/memory/built-in/index.d.ts +0 -232
  25. package/dist/env/memory/built-in/index.js +0 -11
  26. package/dist/env/memory/index.d.ts +0 -1799
  27. package/dist/env/memory/index.js +0 -56
  28. package/dist/env/memory/plugin/index.d.ts +0 -747
  29. package/dist/env/memory/plugin/index.js +0 -36
  30. package/dist/env/prompt/index.d.ts +0 -1164
  31. package/dist/env/prompt/index.js +0 -20
  32. package/dist/env/session/index.d.ts +0 -1908
  33. package/dist/env/session/index.js +0 -25
  34. package/dist/env/session/storage/index.d.ts +0 -564
  35. package/dist/env/session/storage/index.js +0 -18
  36. package/dist/env/skill/index.d.ts +0 -1266
  37. package/dist/env/skill/index.js +0 -34
  38. package/dist/env/skill/tool/index.d.ts +0 -193
  39. package/dist/env/skill/tool/index.js +0 -9
  40. package/dist/env/task/delegate/index.d.ts +0 -1612
  41. package/dist/env/task/delegate/index.js +0 -18
  42. package/dist/env/task/events/index.d.ts +0 -171
  43. package/dist/env/task/events/index.js +0 -7
  44. package/dist/env/task/hooks/index.d.ts +0 -624
  45. package/dist/env/task/hooks/index.js +0 -7
  46. package/dist/env/task/index.d.ts +0 -1553
  47. package/dist/env/task/index.js +0 -34
  48. package/dist/env/task/plugins/index.d.ts +0 -466
  49. package/dist/env/task/plugins/index.js +0 -23
  50. package/dist/env/task/storage/index.d.ts +0 -241
  51. package/dist/env/task/storage/index.js +0 -14
  52. package/dist/env/task/tools/index.d.ts +0 -1485
  53. package/dist/env/task/tools/index.js +0 -17
  54. package/dist/env/task/tools/operation/index.d.ts +0 -1484
  55. package/dist/env/task/tools/operation/index.js +0 -15
  56. package/dist/env/tool/built-in/index.d.ts +0 -218
  57. package/dist/env/tool/built-in/index.js +0 -25
  58. package/dist/env/tool/index.d.ts +0 -1396
  59. package/dist/env/tool/index.js +0 -39
  60. package/dist/env/workflow/decorators/index.d.ts +0 -2161
  61. package/dist/env/workflow/decorators/index.js +0 -27
  62. package/dist/env/workflow/engine/index.d.ts +0 -3453
  63. package/dist/env/workflow/engine/index.js +0 -28
  64. package/dist/env/workflow/index.d.ts +0 -3546
  65. package/dist/env/workflow/index.js +0 -136
  66. package/dist/env/workflow/nodes/index.d.ts +0 -2092
  67. package/dist/env/workflow/nodes/index.js +0 -19
  68. package/dist/env/workflow/service/index.d.ts +0 -227
  69. package/dist/env/workflow/service/index.js +0 -13
  70. package/dist/env/workflow/storage/index.d.ts +0 -165
  71. package/dist/env/workflow/storage/index.js +0 -27
  72. package/dist/env/workflow/tools/index.d.ts +0 -416
  73. package/dist/env/workflow/tools/index.js +0 -159
  74. package/dist/env/workflow/types/index.d.ts +0 -2255
  75. package/dist/env/workflow/types/index.js +0 -98
  76. package/dist/env/workflow/utils/index.d.ts +0 -2031
  77. package/dist/env/workflow/utils/index.js +0 -637
  78. package/dist/index.d.ts +0 -7858
  79. package/dist/index.js +0 -399
  80. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
  81. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
  82. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
  83. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
  84. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
  85. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
  86. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
  87. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
  88. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  89. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
  90. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
  91. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
  92. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
  93. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
  94. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
  95. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
  96. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
  97. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
  98. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
  99. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
  100. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
  101. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
  102. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
  103. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
  104. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
  105. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
  106. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
  107. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
  108. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
  109. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
  110. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
  111. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
  112. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
  113. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
  114. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
  115. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
  116. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
  117. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
  118. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
  119. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
  120. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
  121. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
  122. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
  123. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
  124. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
  125. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
  126. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
  127. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
  128. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
  129. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
  130. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  131. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
  132. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
  133. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
  134. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
  135. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
  136. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
  137. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
  138. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
  139. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
  140. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
  141. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
@@ -1,14 +0,0 @@
1
- import {
2
- WorkflowRepository,
3
- rowToWorkflow
4
- } from "./roy-agent-core-3rr5k71j.js";
5
- import"./roy-agent-core-zpn0bqa8.js";
6
- import"./roy-agent-core-rvxg1wps.js";
7
- import"./roy-agent-core-44hnfb02.js";
8
- import"./roy-agent-core-xs5rsgat.js";
9
- import"./roy-agent-core-psv4v63c.js";
10
- import"./roy-agent-core-fs0mn2jk.js";
11
- export {
12
- rowToWorkflow,
13
- WorkflowRepository
14
- };
@@ -1,653 +0,0 @@
1
- import {
2
- createLogger,
3
- init_logger
4
- } from "./roy-agent-core-44hnfb02.js";
5
- import {
6
- __require
7
- } from "./roy-agent-core-fs0mn2jk.js";
8
-
9
- // src/env/task/storage/sqlite-task-store.ts
10
- init_logger();
11
- import { join } from "path";
12
- function getDatabaseClass() {
13
- if (typeof Bun !== "undefined") {
14
- const { Database } = __require("bun:sqlite");
15
- return Database;
16
- } else {
17
- return __require("better-sqlite3");
18
- }
19
- }
20
- function createCompatibleDatabase(path) {
21
- const Database = getDatabaseClass();
22
- const db = new Database(path);
23
- if (typeof db.run !== "function") {
24
- db.run = function(sql, ...params) {
25
- if (params.length > 0) {
26
- return this.prepare(sql).run(...params);
27
- } else {
28
- return this.exec(sql);
29
- }
30
- };
31
- }
32
- return db;
33
- }
34
- var logger = createLogger("task:store");
35
- function getDefaultDataDir() {
36
- const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
37
- return join(home, ".local", "share");
38
- }
39
- function getDefaultTaskDbPath() {
40
- return join(getDefaultDataDir(), "roy-agent", "tasks.db");
41
- }
42
-
43
- class SQLiteTaskStore {
44
- db = null;
45
- dbPath;
46
- initialized = false;
47
- tasksCache = new Map;
48
- operationsCache = new Map;
49
- constructor(dbPath) {
50
- this.dbPath = dbPath || getDefaultTaskDbPath();
51
- }
52
- async initialize() {
53
- if (this.initialized)
54
- return;
55
- if (this.dbPath !== ":memory:") {
56
- const fs = __require("fs");
57
- const path = __require("path");
58
- const dir = path.dirname(this.dbPath);
59
- if (!fs.existsSync(dir)) {
60
- fs.mkdirSync(dir, { recursive: true });
61
- }
62
- }
63
- this.db = createCompatibleDatabase(this.dbPath);
64
- this.db.run(`
65
- CREATE TABLE IF NOT EXISTS task (
66
- id INTEGER PRIMARY KEY AUTOINCREMENT,
67
- title TEXT NOT NULL,
68
- description TEXT DEFAULT '',
69
- status TEXT DEFAULT 'todo',
70
- priority TEXT DEFAULT 'medium',
71
- progress INTEGER DEFAULT 0,
72
- current_status TEXT DEFAULT '',
73
- goals_and_expected_deliverables TEXT DEFAULT '',
74
- parent_task_id INTEGER,
75
- created_at INTEGER NOT NULL,
76
- updated_at INTEGER NOT NULL,
77
- due_date TEXT,
78
- tags TEXT,
79
- project_path TEXT NOT NULL DEFAULT 'unknown',
80
- context TEXT NOT NULL DEFAULT '{}'
81
- )
82
- `);
83
- this.db.run(`
84
- CREATE TABLE IF NOT EXISTS task_operation (
85
- id INTEGER PRIMARY KEY AUTOINCREMENT,
86
- task_id INTEGER NOT NULL,
87
- session_id TEXT NOT NULL,
88
- action_type TEXT NOT NULL,
89
- action_title TEXT NOT NULL,
90
- action_description TEXT DEFAULT '',
91
- timestamp INTEGER NOT NULL,
92
- md_path TEXT,
93
- FOREIGN KEY (task_id) REFERENCES task(id) ON DELETE CASCADE
94
- )
95
- `);
96
- this.db.run("CREATE INDEX IF NOT EXISTS idx_task_operation_task_id ON task_operation(task_id)");
97
- this.db.run("CREATE INDEX IF NOT EXISTS idx_task_operation_session_id ON task_operation(session_id)");
98
- this.db.run(`
99
- CREATE TABLE IF NOT EXISTS task_tag (
100
- id INTEGER PRIMARY KEY AUTOINCREMENT,
101
- name TEXT NOT NULL UNIQUE,
102
- created_at INTEGER NOT NULL,
103
- task_count INTEGER DEFAULT 0
104
- )
105
- `);
106
- this.db.run(`
107
- CREATE TABLE IF NOT EXISTS task_tag_relation (
108
- task_id INTEGER NOT NULL,
109
- tag_id INTEGER NOT NULL,
110
- created_at INTEGER NOT NULL,
111
- PRIMARY KEY (task_id, tag_id),
112
- FOREIGN KEY (task_id) REFERENCES task(id) ON DELETE CASCADE,
113
- FOREIGN KEY (tag_id) REFERENCES task_tag(id) ON DELETE CASCADE
114
- )
115
- `);
116
- this.db.run("CREATE INDEX IF NOT EXISTS idx_task_tag_relation_tag_id ON task_tag_relation(tag_id)");
117
- this.initialized = true;
118
- logger.info(`TaskStore initialized at ${this.dbPath}`);
119
- }
120
- async createTask(options) {
121
- await this.initialize();
122
- const now = Date.now();
123
- const stmt = this.db.prepare(`
124
- INSERT INTO task (title, description, priority, parent_task_id,
125
- goals_and_expected_deliverables, due_date, tags, status,
126
- current_status, created_at, updated_at, project_path, context)
127
- VALUES (?, ?, ?, ?, ?, ?, ?, 'todo', '', ?, ?, ?, ?)
128
- `);
129
- const result = stmt.run(options.title, options.description || "", options.priority || "medium", options.parent_task_id || null, options.goals_and_expected_deliverables || "", options.due_date || null, options.tags ? JSON.stringify(options.tags) : null, now, now, options.project_path, options.context);
130
- const task = await this.getTask(result.lastInsertRowid);
131
- if (task) {
132
- this.tasksCache.set(task.id, task);
133
- return task;
134
- }
135
- throw new Error("Failed to create task");
136
- }
137
- async getTask(id) {
138
- await this.initialize();
139
- if (this.tasksCache.has(id)) {
140
- return this.tasksCache.get(id);
141
- }
142
- const stmt = this.db.prepare("SELECT * FROM task WHERE id = ?");
143
- const row = stmt.get(id);
144
- if (!row)
145
- return;
146
- const task = this.rowToTask(row);
147
- this.tasksCache.set(id, task);
148
- return task;
149
- }
150
- async updateTask(id, options) {
151
- await this.initialize();
152
- const task = await this.getTask(id);
153
- if (!task)
154
- return;
155
- const updates = [];
156
- const values = [];
157
- if (options.title !== undefined) {
158
- updates.push("title = ?");
159
- values.push(options.title);
160
- }
161
- if (options.description !== undefined) {
162
- updates.push("description = ?");
163
- values.push(options.description);
164
- }
165
- if (options.status !== undefined) {
166
- updates.push("status = ?");
167
- values.push(options.status);
168
- }
169
- if (options.priority !== undefined) {
170
- updates.push("priority = ?");
171
- values.push(options.priority);
172
- }
173
- if (options.progress !== undefined) {
174
- updates.push("progress = ?");
175
- values.push(options.progress);
176
- }
177
- if (options.current_status !== undefined) {
178
- updates.push("current_status = ?");
179
- values.push(options.current_status);
180
- }
181
- if (options.goals_and_expected_deliverables !== undefined) {
182
- updates.push("goals_and_expected_deliverables = ?");
183
- values.push(options.goals_and_expected_deliverables);
184
- }
185
- if (options.due_date !== undefined) {
186
- updates.push("due_date = ?");
187
- values.push(options.due_date);
188
- }
189
- if (options.tags !== undefined) {
190
- updates.push("tags = ?");
191
- values.push(JSON.stringify(options.tags));
192
- }
193
- if (options.project_path !== undefined) {
194
- updates.push("project_path = ?");
195
- values.push(options.project_path);
196
- }
197
- if (options.context !== undefined) {
198
- updates.push("context = ?");
199
- values.push(options.context);
200
- }
201
- if (updates.length === 0)
202
- return task;
203
- updates.push("updated_at = ?");
204
- values.push(Date.now());
205
- values.push(id);
206
- const stmt = this.db.prepare(`UPDATE task SET ${updates.join(", ")} WHERE id = ?`);
207
- stmt.run(...values);
208
- this.tasksCache.delete(id);
209
- return this.getTask(id);
210
- }
211
- async deleteTask(id) {
212
- await this.initialize();
213
- const stmt = this.db.prepare("DELETE FROM task WHERE id = ?");
214
- const result = stmt.run(id);
215
- if (result.changes > 0) {
216
- this.tasksCache.delete(id);
217
- this.operationsCache.delete(id);
218
- }
219
- return result.changes > 0;
220
- }
221
- async listTasks(options) {
222
- await this.initialize();
223
- let sql = "SELECT * FROM task WHERE 1=1";
224
- const params = [];
225
- if (options?.status) {
226
- sql += " AND status = ?";
227
- params.push(options.status);
228
- }
229
- if (options?.priority) {
230
- sql += " AND priority = ?";
231
- params.push(options.priority);
232
- }
233
- if (options?.parent_task_id !== undefined) {
234
- sql += " AND parent_task_id = ?";
235
- params.push(options.parent_task_id);
236
- }
237
- sql += " ORDER BY updated_at DESC";
238
- if (options?.limit) {
239
- sql += " LIMIT ?";
240
- params.push(options.limit);
241
- }
242
- if (options?.offset) {
243
- sql += " OFFSET ?";
244
- params.push(options.offset);
245
- }
246
- const stmt = this.db.prepare(sql);
247
- const rows = stmt.all(...params);
248
- return rows.map((row) => {
249
- const task = this.rowToTask(row);
250
- this.tasksCache.set(task.id, task);
251
- return task;
252
- });
253
- }
254
- async createOperation(options) {
255
- await this.initialize();
256
- const now = Date.now();
257
- const stmt = this.db.prepare(`
258
- INSERT INTO task_operation (task_id, session_id, action_type, action_title,
259
- action_description, timestamp, md_path)
260
- VALUES (?, ?, ?, ?, ?, ?, ?)
261
- `);
262
- const result = stmt.run(options.taskId, options.sessionId, options.actionType, options.actionTitle, options.actionDescription || "", now, options.mdPath || null);
263
- this.operationsCache.delete(options.taskId);
264
- const operation = await this.getOperation(result.lastInsertRowid);
265
- if (!operation) {
266
- throw new Error("Failed to create operation");
267
- }
268
- return operation;
269
- }
270
- async getOperation(id) {
271
- await this.initialize();
272
- const stmt = this.db.prepare("SELECT * FROM task_operation WHERE id = ?");
273
- const row = stmt.get(id);
274
- if (!row)
275
- return;
276
- return this.rowToOperation(row);
277
- }
278
- async updateOperation(id, updates) {
279
- await this.initialize();
280
- const op = await this.getOperation(id);
281
- if (!op)
282
- return;
283
- const setClauses = [];
284
- const values = [];
285
- if (updates.actionTitle !== undefined) {
286
- setClauses.push("action_title = ?");
287
- values.push(updates.actionTitle);
288
- }
289
- if (updates.actionDescription !== undefined) {
290
- setClauses.push("action_description = ?");
291
- values.push(updates.actionDescription);
292
- }
293
- if (setClauses.length === 0)
294
- return op;
295
- const stmt = this.db.prepare(`UPDATE task_operation SET ${setClauses.join(", ")} WHERE id = ?`);
296
- stmt.run(...values, id);
297
- this.operationsCache.delete(op.taskId);
298
- return this.getOperation(id);
299
- }
300
- async deleteOperation(id) {
301
- await this.initialize();
302
- const op = await this.getOperation(id);
303
- if (!op)
304
- return false;
305
- const stmt = this.db.prepare("DELETE FROM task_operation WHERE id = ?");
306
- const result = stmt.run(id);
307
- if (result.changes > 0) {
308
- this.operationsCache.delete(op.taskId);
309
- }
310
- return result.changes > 0;
311
- }
312
- async listOperations(options) {
313
- await this.initialize();
314
- const cacheKey = options.taskId;
315
- if (!this.operationsCache.has(cacheKey)) {
316
- const stmt = this.db.prepare("SELECT * FROM task_operation WHERE task_id = ? ORDER BY timestamp DESC");
317
- const rows = stmt.all(options.taskId);
318
- this.operationsCache.set(cacheKey, rows.map((row) => this.rowToOperation(row)));
319
- }
320
- let ops = this.operationsCache.get(cacheKey);
321
- if (options.actionType) {
322
- ops = ops.filter((op) => op.actionType === options.actionType);
323
- }
324
- const offset = options.offset || 0;
325
- const limit = options.limit || 20;
326
- return ops.slice(offset, offset + limit);
327
- }
328
- rowToTask(row) {
329
- return {
330
- id: row.id,
331
- title: row.title,
332
- description: row.description,
333
- status: row.status,
334
- priority: row.priority,
335
- progress: row.progress,
336
- current_status: row.current_status,
337
- goals_and_expected_deliverables: row.goals_and_expected_deliverables,
338
- parent_task_id: row.parent_task_id || undefined,
339
- createdAt: new Date(row.created_at).toISOString(),
340
- updatedAt: new Date(row.updated_at).toISOString(),
341
- due_date: row.due_date || undefined,
342
- tags: row.tags ? JSON.parse(row.tags) : undefined,
343
- project_path: row.project_path,
344
- context: row.context
345
- };
346
- }
347
- rowToOperation(row) {
348
- return {
349
- id: row.id,
350
- taskId: row.task_id,
351
- sessionId: row.session_id,
352
- actionType: row.action_type,
353
- actionTitle: row.action_title,
354
- actionDescription: row.action_description,
355
- timestamp: new Date(row.timestamp).toISOString(),
356
- mdPath: row.md_path || undefined
357
- };
358
- }
359
- async createTag(name) {
360
- await this.initialize();
361
- const now = Date.now();
362
- const existing = await this.getTagByName(name);
363
- if (existing) {
364
- return existing;
365
- }
366
- const stmt = this.db.prepare(`
367
- INSERT INTO task_tag (name, created_at, task_count)
368
- VALUES (?, ?, 0)
369
- `);
370
- const result = stmt.run(name, now);
371
- return {
372
- id: result.lastInsertRowid,
373
- name,
374
- createdAt: new Date(now).toISOString(),
375
- taskCount: 0
376
- };
377
- }
378
- async getTag(id) {
379
- await this.initialize();
380
- const stmt = this.db.prepare("SELECT * FROM task_tag WHERE id = ?");
381
- const row = stmt.get(id);
382
- if (!row)
383
- return;
384
- return this.rowToTag(row);
385
- }
386
- async getTagByName(name) {
387
- await this.initialize();
388
- const stmt = this.db.prepare("SELECT * FROM task_tag WHERE name = ?");
389
- const row = stmt.get(name);
390
- if (!row)
391
- return;
392
- return this.rowToTag(row);
393
- }
394
- async listTags(options) {
395
- await this.initialize();
396
- let sql = "SELECT * FROM task_tag";
397
- const params = [];
398
- const orderBy = options?.orderBy || "count";
399
- if (orderBy === "count") {
400
- sql += " ORDER BY task_count DESC";
401
- } else if (orderBy === "name") {
402
- sql += " ORDER BY name ASC";
403
- } else {
404
- sql += " ORDER BY created_at DESC";
405
- }
406
- if (options?.limit) {
407
- sql += " LIMIT ?";
408
- params.push(options.limit);
409
- }
410
- if (options?.offset) {
411
- sql += " OFFSET ?";
412
- params.push(options.offset);
413
- }
414
- const stmt = this.db.prepare(sql);
415
- const rows = stmt.all(...params);
416
- return rows.map((row) => this.rowToTag(row));
417
- }
418
- async searchTags(options) {
419
- await this.initialize();
420
- const sql = `
421
- SELECT * FROM task_tag
422
- WHERE name LIKE ?
423
- ORDER BY task_count DESC
424
- LIMIT ?
425
- `;
426
- const stmt = this.db.prepare(sql);
427
- const rows = stmt.all(`%${options.query}%`, options.limit || 20);
428
- return rows.map((row) => this.rowToTag(row));
429
- }
430
- async deleteTag(id) {
431
- await this.initialize();
432
- const stmt = this.db.prepare("DELETE FROM task_tag WHERE id = ?");
433
- const result = stmt.run(id);
434
- return result.changes > 0;
435
- }
436
- async addTagsToTask(taskId, tagIds) {
437
- await this.initialize();
438
- const now = Date.now();
439
- const stmt = this.db.prepare(`
440
- INSERT OR IGNORE INTO task_tag_relation (task_id, tag_id, created_at)
441
- VALUES (?, ?, ?)
442
- `);
443
- for (const tagId of tagIds) {
444
- stmt.run(taskId, tagId, now);
445
- this.db.run(`
446
- UPDATE task_tag SET task_count = task_count + 1 WHERE id = ?
447
- `, tagId);
448
- }
449
- await this.syncTaskTagsJson(taskId);
450
- }
451
- async removeTagsFromTask(taskId, tagIds) {
452
- await this.initialize();
453
- const stmt = this.db.prepare("DELETE FROM task_tag_relation WHERE task_id = ? AND tag_id = ?");
454
- for (const tagId of tagIds) {
455
- stmt.run(taskId, tagId);
456
- this.db.run(`
457
- UPDATE task_tag SET task_count = MAX(0, task_count - 1) WHERE id = ?
458
- `, tagId);
459
- }
460
- await this.syncTaskTagsJson(taskId);
461
- }
462
- async getTagsForTask(taskId) {
463
- await this.initialize();
464
- const sql = `
465
- SELECT t.* FROM task_tag t
466
- INNER JOIN task_tag_relation r ON t.id = r.tag_id
467
- WHERE r.task_id = ?
468
- ORDER BY t.name ASC
469
- `;
470
- const stmt = this.db.prepare(sql);
471
- const rows = stmt.all(taskId);
472
- return rows.map((row) => this.rowToTag(row));
473
- }
474
- async getTaskIdsByTags(tagNames) {
475
- await this.initialize();
476
- if (tagNames.length === 0)
477
- return [];
478
- const placeholders = tagNames.map(() => "?").join(", ");
479
- const sql = `
480
- SELECT DISTINCT r.task_id FROM task_tag_relation r
481
- INNER JOIN task_tag t ON r.tag_id = t.id
482
- WHERE t.name IN (${placeholders})
483
- `;
484
- const stmt = this.db.prepare(sql);
485
- const rows = stmt.all(...tagNames);
486
- return rows.map((row) => row.task_id);
487
- }
488
- async updateTaskTags(taskId, tagNames) {
489
- await this.initialize();
490
- const currentTags = await this.getTagsForTask(taskId);
491
- if (currentTags.length > 0) {
492
- await this.removeTagsFromTask(taskId, currentTags.map((t) => t.id));
493
- }
494
- const tagIds = [];
495
- for (const name of tagNames) {
496
- let tag = await this.getTagByName(name);
497
- if (!tag) {
498
- tag = await this.createTag(name);
499
- }
500
- tagIds.push(tag.id);
501
- }
502
- if (tagIds.length > 0) {
503
- await this.addTagsToTask(taskId, tagIds);
504
- }
505
- }
506
- async searchTasksByKeywords(keywords, options = {}) {
507
- await this.initialize();
508
- if (!keywords || keywords.length === 0) {
509
- return [];
510
- }
511
- const { limit = 20, excludeTaskId } = options;
512
- const tasks = new Map;
513
- let taskSql = "SELECT * FROM task WHERE 1=1";
514
- const taskParams = [];
515
- if (excludeTaskId) {
516
- taskSql += " AND id != ?";
517
- taskParams.push(excludeTaskId);
518
- }
519
- taskSql += " ORDER BY updated_at DESC LIMIT ?";
520
- taskParams.push(limit * 2);
521
- const taskRows = this.db.prepare(taskSql).all(...taskParams);
522
- for (const row of taskRows) {
523
- const task = this.rowToTask(row);
524
- let matchCount = 0;
525
- if (task.title) {
526
- const lowerTitle = task.title.toLowerCase();
527
- for (const keyword of keywords) {
528
- if (lowerTitle.includes(keyword.toLowerCase())) {
529
- matchCount++;
530
- }
531
- }
532
- }
533
- if (task.tags && Array.isArray(task.tags)) {
534
- for (const keyword of keywords) {
535
- const lowerKeyword = keyword.toLowerCase();
536
- if (task.tags.some((tag) => tag.toLowerCase().includes(lowerKeyword))) {
537
- matchCount += 2;
538
- }
539
- }
540
- }
541
- if (task.description) {
542
- const lowerDesc = task.description.toLowerCase();
543
- for (const keyword of keywords) {
544
- if (lowerDesc.includes(keyword.toLowerCase())) {
545
- matchCount++;
546
- }
547
- }
548
- }
549
- if (task.goals_and_expected_deliverables) {
550
- const lowerGoals = task.goals_and_expected_deliverables.toLowerCase();
551
- for (const keyword of keywords) {
552
- if (lowerGoals.includes(keyword.toLowerCase())) {
553
- matchCount++;
554
- }
555
- }
556
- }
557
- if (matchCount > 0) {
558
- tasks.set(task.id, { task, matchCount });
559
- }
560
- }
561
- const allOps = this.db.prepare("SELECT DISTINCT task_id FROM task_operation WHERE 1=1").all();
562
- for (const opRow of allOps) {
563
- const opSql = `
564
- SELECT * FROM task_operation
565
- WHERE task_id = ?
566
- AND (action_title LIKE ? OR action_description LIKE ?)
567
- LIMIT 10
568
- `;
569
- for (const keyword of keywords) {
570
- const pattern = `%${keyword}%`;
571
- const ops = this.db.prepare(opSql).all(opRow.task_id, pattern, pattern);
572
- if (ops.length > 0) {
573
- const taskRow = this.db.prepare("SELECT * FROM task WHERE id = ?").get(opRow.task_id);
574
- if (taskRow) {
575
- const task = this.rowToTask(taskRow);
576
- if (excludeTaskId && task.id === excludeTaskId)
577
- continue;
578
- const existing = tasks.get(task.id);
579
- if (existing) {
580
- existing.matchCount += 2;
581
- } else {
582
- tasks.set(task.id, { task, matchCount: 2 });
583
- }
584
- }
585
- }
586
- }
587
- }
588
- const results = Array.from(tasks.values()).sort((a, b) => b.matchCount - a.matchCount).slice(0, limit).map((item) => item.task);
589
- return results;
590
- }
591
- async findSimilarTasksByKeywords(keywords, options = {}) {
592
- const mergedOptions = { ...options, limit: options.limit ?? 5 };
593
- return this.searchTasksByKeywords(keywords, mergedOptions);
594
- }
595
- async findSimilarTasks(taskId, limit = 5) {
596
- await this.initialize();
597
- const taskTags = await this.getTagsForTask(taskId);
598
- if (taskTags.length === 0) {
599
- return [];
600
- }
601
- const tagIds = taskTags.map((t) => t.id);
602
- const placeholders = tagIds.map(() => "?").join(", ");
603
- const sql = `
604
- SELECT t.*, COUNT(r2.tag_id) as match_count
605
- FROM task t
606
- INNER JOIN task_tag_relation r ON t.id = r.task_id
607
- INNER JOIN task_tag_relation r2 ON t.id = r2.task_id
608
- WHERE r.tag_id IN (${placeholders})
609
- AND t.id != ?
610
- GROUP BY t.id
611
- ORDER BY match_count DESC, t.updated_at DESC
612
- LIMIT ?
613
- `;
614
- const stmt = this.db.prepare(sql);
615
- const rows = stmt.all(...tagIds, taskId, limit);
616
- return rows.map((row) => this.rowToTask(row));
617
- }
618
- async searchTasks(query, limit = 20) {
619
- await this.initialize();
620
- const sql = `
621
- SELECT * FROM task
622
- WHERE title LIKE ? OR description LIKE ?
623
- ORDER BY updated_at DESC
624
- LIMIT ?
625
- `;
626
- const stmt = this.db.prepare(sql);
627
- const rows = stmt.all(`%${query}%`, `%${query}%`, limit);
628
- return rows.map((row) => this.rowToTask(row));
629
- }
630
- rowToTag(row) {
631
- return {
632
- id: row.id,
633
- name: row.name,
634
- createdAt: new Date(row.created_at).toISOString(),
635
- taskCount: row.task_count
636
- };
637
- }
638
- async syncTaskTagsJson(taskId) {
639
- const tags = await this.getTagsForTask(taskId);
640
- const tagNames = tags.map((t) => t.name);
641
- const stmt = this.db.prepare("UPDATE task SET tags = ? WHERE id = ?");
642
- stmt.run(tagNames.length > 0 ? JSON.stringify(tagNames) : null, taskId);
643
- this.tasksCache.delete(taskId);
644
- }
645
- async close() {
646
- if (this.db) {
647
- this.db.close();
648
- this.db = null;
649
- this.initialized = false;
650
- }
651
- }
652
- }
653
- export { getDefaultDataDir, getDefaultTaskDbPath, SQLiteTaskStore };