@goondocks/myco 0.14.3 → 0.15.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.
Files changed (172) hide show
  1. package/dist/{agent-run-A7YYMN6S.js → agent-run-DUOJ3KDI.js} +6 -6
  2. package/dist/{agent-tasks-MDVJW5SV.js → agent-tasks-LUWBY5JD.js} +6 -6
  3. package/dist/{chunk-X34OFKYU.js → chunk-23FJUKCN.js} +2 -2
  4. package/dist/{chunk-KNTJOMWY.js → chunk-3MEOYXOW.js} +2 -2
  5. package/dist/{chunk-PSYLKCWQ.js → chunk-4BQ5QE76.js} +24 -5
  6. package/dist/chunk-4BQ5QE76.js.map +1 -0
  7. package/dist/{chunk-JTYZRPX5.js → chunk-5ZT2Q6P5.js} +1 -1
  8. package/dist/{chunk-JJXVDCEX.js → chunk-75J2BR4P.js} +486 -488
  9. package/dist/chunk-75J2BR4P.js.map +1 -0
  10. package/dist/{chunk-XRVLSSJY.js → chunk-B3SF2CCW.js} +3 -3
  11. package/dist/{chunk-S6I62FAH.js → chunk-CUADDHHU.js} +4 -2
  12. package/dist/{chunk-S6I62FAH.js.map → chunk-CUADDHHU.js.map} +1 -1
  13. package/dist/{chunk-4VF6KQ2Z.js → chunk-DJQOYEK3.js} +87 -84
  14. package/dist/chunk-DJQOYEK3.js.map +1 -0
  15. package/dist/{chunk-LD6U3L6O.js → chunk-DK5VEBB5.js} +5 -5
  16. package/dist/{chunk-NBPZI5UD.js → chunk-DKGUCEWU.js} +6 -6
  17. package/dist/{chunk-OQVKLTQY.js → chunk-EYMKBNRP.js} +2 -2
  18. package/dist/{chunk-KH64DHOY.js → chunk-GDY63YAW.js} +279 -277
  19. package/dist/chunk-GDY63YAW.js.map +1 -0
  20. package/dist/{chunk-ZESTWGJT.js → chunk-GYIA6XLB.js} +2 -2
  21. package/dist/{chunk-HSMD2COQ.js → chunk-GZ7MXWYX.js} +3 -3
  22. package/dist/{chunk-S66YG6QK.js → chunk-LF5Z62X6.js} +46 -7
  23. package/dist/chunk-LF5Z62X6.js.map +1 -0
  24. package/dist/{chunk-PGYJSXSK.js → chunk-OMZCVRX6.js} +2 -2
  25. package/dist/{chunk-QMGQSA5A.js → chunk-R3YW7XVF.js} +2 -2
  26. package/dist/{chunk-PX5KIOKY.js → chunk-SPJGJEFV.js} +10 -2
  27. package/dist/{chunk-PX5KIOKY.js.map → chunk-SPJGJEFV.js.map} +1 -1
  28. package/dist/{chunk-QFMBZ72S.js → chunk-SV6UCB2Z.js} +2 -2
  29. package/dist/{chunk-NVCGF2DS.js → chunk-X4XFJG6I.js} +10 -6
  30. package/dist/chunk-X4XFJG6I.js.map +1 -0
  31. package/dist/{chunk-TNCBMGWB.js → chunk-X5IXK5KO.js} +262 -226
  32. package/dist/chunk-X5IXK5KO.js.map +1 -0
  33. package/dist/{chunk-TVV6PZOC.js → chunk-Z7TZJ2SP.js} +2 -2
  34. package/dist/{cli-HEPHQSLV.js → cli-YBD2GPK4.js} +45 -44
  35. package/dist/cli-YBD2GPK4.js.map +1 -0
  36. package/dist/{client-ZXC6IY63.js → client-CJ3X252K.js} +4 -4
  37. package/dist/{config-H657SF6B.js → config-MOWCOJJ4.js} +4 -4
  38. package/dist/{detect-27DN6UTL.js → detect-GFYKKHLJ.js} +3 -3
  39. package/dist/{detect-providers-PAVE2X6O.js → detect-providers-EU35RUL3.js} +2 -2
  40. package/dist/{doctor-Q5WJBNSZ.js → doctor-JR7NEL7K.js} +38 -19
  41. package/dist/doctor-JR7NEL7K.js.map +1 -0
  42. package/dist/{executor-YX2MA4T3.js → executor-7XOKS6HS.js} +442 -248
  43. package/dist/executor-7XOKS6HS.js.map +1 -0
  44. package/dist/{init-KWCGGLP3.js → init-PDLKYWQ4.js} +41 -23
  45. package/dist/init-PDLKYWQ4.js.map +1 -0
  46. package/dist/{init-wizard-YUT7MIYZ.js → init-wizard-WH3SXNMB.js} +7 -7
  47. package/dist/{installer-25TSX4SR.js → installer-BTUNKWOU.js} +2 -2
  48. package/dist/{llm-T3QVHC3Y.js → llm-DK44LYO6.js} +4 -4
  49. package/dist/{loader-WQKVWL5D.js → loader-WC4U5NM5.js} +4 -4
  50. package/dist/{loader-JQLO6K44.js → loader-WGDVRGLM.js} +6 -4
  51. package/dist/{logs-LXHPDKUA.js → logs-WFBX2I7C.js} +3 -3
  52. package/dist/{main-WHGJ6UV7.js → main-JB3R3DQE.js} +2346 -1912
  53. package/dist/main-JB3R3DQE.js.map +1 -0
  54. package/dist/{open-CBNGDM32.js → open-AADZPSLW.js} +6 -6
  55. package/dist/{openai-embeddings-5T5ZP7LO.js → openai-embeddings-SEIV7AM3.js} +2 -2
  56. package/dist/{openrouter-RD2COFC7.js → openrouter-ELODIZRP.js} +2 -2
  57. package/dist/{post-compact-AANLN7TR.js → post-compact-KNQ4DYLM.js} +9 -9
  58. package/dist/{post-tool-use-X3IFZEMV.js → post-tool-use-OMWHFQLM.js} +10 -10
  59. package/dist/{post-tool-use-failure-T6KAFDFF.js → post-tool-use-failure-KFP6MB7Z.js} +9 -9
  60. package/dist/{pre-compact-FY7BPS4J.js → pre-compact-2ZYE2HRB.js} +9 -9
  61. package/dist/{provider-check-QN7OGXZA.js → provider-check-B66E5PWS.js} +2 -2
  62. package/dist/{registry-2XQMCPA6.js → registry-DHWVHXWY.js} +5 -5
  63. package/dist/{remove-TN3BLJEC.js → remove-QT7634L5.js} +52 -20
  64. package/dist/remove-QT7634L5.js.map +1 -0
  65. package/dist/{resolution-events-5EVUEWHS.js → resolution-events-DBCRVZGU.js} +4 -4
  66. package/dist/{restart-KT4R3QN5.js → restart-YQNQEHOU.js} +7 -7
  67. package/dist/{search-NQFXQUUQ.js → search-C6JTQDWY.js} +6 -6
  68. package/dist/{server-6QIP325R.js → server-QJ3RWZZZ.js} +8 -8
  69. package/dist/{session-E7B3B4ZQ.js → session-JLVL5TYX.js} +8 -8
  70. package/dist/{session-end-H2E42BZG.js → session-end-XFZRRP5H.js} +10 -10
  71. package/dist/{session-start-FLND66CU.js → session-start-XGINISXO.js} +15 -15
  72. package/dist/{setup-llm-YAXEM23S.js → setup-llm-X2OCM6R7.js} +8 -8
  73. package/dist/src/agent/definitions/tasks/full-intelligence.yaml +8 -7
  74. package/dist/src/agent/definitions/tasks/skill-evolve.yaml +71 -144
  75. package/dist/src/agent/definitions/tasks/skill-generate.yaml +10 -62
  76. package/dist/src/agent/definitions/tasks/skill-survey.yaml +87 -53
  77. package/dist/src/agent/prompts/agent.md +1 -0
  78. package/dist/src/cli.js +1 -1
  79. package/dist/src/daemon/main.js +1 -1
  80. package/dist/src/hooks/post-tool-use.js +1 -1
  81. package/dist/src/hooks/session-end.js +1 -1
  82. package/dist/src/hooks/session-start.js +1 -1
  83. package/dist/src/hooks/stop.js +1 -1
  84. package/dist/src/hooks/user-prompt-submit.js +1 -1
  85. package/dist/src/mcp/server.js +1 -1
  86. package/dist/src/worker/src/schema.ts +14 -0
  87. package/dist/{stats-MD4PUVRL.js → stats-2EAETG2T.js} +9 -9
  88. package/dist/{stop-CFUWXMNB.js → stop-WOBDYTSA.js} +10 -10
  89. package/dist/{stop-failure-ZOHR2EUI.js → stop-failure-QEC7ZGBQ.js} +9 -9
  90. package/dist/{subagent-start-AXZAVBJU.js → subagent-start-H6DVRVOE.js} +9 -9
  91. package/dist/{subagent-stop-FVQGEEZ4.js → subagent-stop-LKENKJ65.js} +9 -9
  92. package/dist/{task-completed-NKJU2SRN.js → task-completed-ZZ47PRPD.js} +9 -9
  93. package/dist/{team-SJPDXELY.js → team-J62N7VMG.js} +34 -26
  94. package/dist/team-J62N7VMG.js.map +1 -0
  95. package/dist/ui/assets/index-Bx9l8uxa.js +837 -0
  96. package/dist/ui/assets/{index-BmsHIwjl.css → index-DlEQ8A8Y.css} +1 -1
  97. package/dist/ui/index.html +2 -2
  98. package/dist/{update-2C4WQ4WP.js → update-LX3CJ4TJ.js} +30 -14
  99. package/dist/update-LX3CJ4TJ.js.map +1 -0
  100. package/dist/{user-prompt-submit-RRSLN6LA.js → user-prompt-submit-NNMLY3EW.js} +10 -10
  101. package/dist/{verify-JHIMXTY5.js → verify-AMRQXQ3K.js} +6 -6
  102. package/dist/{version-CGFXQBSI.js → version-6OJH5HLZ.js} +2 -2
  103. package/package.json +2 -2
  104. package/dist/chunk-4VF6KQ2Z.js.map +0 -1
  105. package/dist/chunk-JJXVDCEX.js.map +0 -1
  106. package/dist/chunk-KH64DHOY.js.map +0 -1
  107. package/dist/chunk-NVCGF2DS.js.map +0 -1
  108. package/dist/chunk-PSYLKCWQ.js.map +0 -1
  109. package/dist/chunk-S66YG6QK.js.map +0 -1
  110. package/dist/chunk-TNCBMGWB.js.map +0 -1
  111. package/dist/cli-HEPHQSLV.js.map +0 -1
  112. package/dist/doctor-Q5WJBNSZ.js.map +0 -1
  113. package/dist/executor-YX2MA4T3.js.map +0 -1
  114. package/dist/init-KWCGGLP3.js.map +0 -1
  115. package/dist/main-WHGJ6UV7.js.map +0 -1
  116. package/dist/remove-TN3BLJEC.js.map +0 -1
  117. package/dist/resolve-3FEUV462.js +0 -9
  118. package/dist/team-SJPDXELY.js.map +0 -1
  119. package/dist/ui/assets/index-Cn6cQwJy.js +0 -842
  120. package/dist/update-2C4WQ4WP.js.map +0 -1
  121. package/dist/version-CGFXQBSI.js.map +0 -1
  122. /package/dist/{agent-run-A7YYMN6S.js.map → agent-run-DUOJ3KDI.js.map} +0 -0
  123. /package/dist/{agent-tasks-MDVJW5SV.js.map → agent-tasks-LUWBY5JD.js.map} +0 -0
  124. /package/dist/{chunk-X34OFKYU.js.map → chunk-23FJUKCN.js.map} +0 -0
  125. /package/dist/{chunk-KNTJOMWY.js.map → chunk-3MEOYXOW.js.map} +0 -0
  126. /package/dist/{chunk-JTYZRPX5.js.map → chunk-5ZT2Q6P5.js.map} +0 -0
  127. /package/dist/{chunk-XRVLSSJY.js.map → chunk-B3SF2CCW.js.map} +0 -0
  128. /package/dist/{chunk-LD6U3L6O.js.map → chunk-DK5VEBB5.js.map} +0 -0
  129. /package/dist/{chunk-NBPZI5UD.js.map → chunk-DKGUCEWU.js.map} +0 -0
  130. /package/dist/{chunk-OQVKLTQY.js.map → chunk-EYMKBNRP.js.map} +0 -0
  131. /package/dist/{chunk-ZESTWGJT.js.map → chunk-GYIA6XLB.js.map} +0 -0
  132. /package/dist/{chunk-HSMD2COQ.js.map → chunk-GZ7MXWYX.js.map} +0 -0
  133. /package/dist/{chunk-PGYJSXSK.js.map → chunk-OMZCVRX6.js.map} +0 -0
  134. /package/dist/{chunk-QMGQSA5A.js.map → chunk-R3YW7XVF.js.map} +0 -0
  135. /package/dist/{chunk-QFMBZ72S.js.map → chunk-SV6UCB2Z.js.map} +0 -0
  136. /package/dist/{chunk-TVV6PZOC.js.map → chunk-Z7TZJ2SP.js.map} +0 -0
  137. /package/dist/{client-ZXC6IY63.js.map → client-CJ3X252K.js.map} +0 -0
  138. /package/dist/{config-H657SF6B.js.map → config-MOWCOJJ4.js.map} +0 -0
  139. /package/dist/{detect-27DN6UTL.js.map → detect-GFYKKHLJ.js.map} +0 -0
  140. /package/dist/{detect-providers-PAVE2X6O.js.map → detect-providers-EU35RUL3.js.map} +0 -0
  141. /package/dist/{init-wizard-YUT7MIYZ.js.map → init-wizard-WH3SXNMB.js.map} +0 -0
  142. /package/dist/{installer-25TSX4SR.js.map → installer-BTUNKWOU.js.map} +0 -0
  143. /package/dist/{llm-T3QVHC3Y.js.map → llm-DK44LYO6.js.map} +0 -0
  144. /package/dist/{loader-JQLO6K44.js.map → loader-WC4U5NM5.js.map} +0 -0
  145. /package/dist/{loader-WQKVWL5D.js.map → loader-WGDVRGLM.js.map} +0 -0
  146. /package/dist/{logs-LXHPDKUA.js.map → logs-WFBX2I7C.js.map} +0 -0
  147. /package/dist/{open-CBNGDM32.js.map → open-AADZPSLW.js.map} +0 -0
  148. /package/dist/{openai-embeddings-5T5ZP7LO.js.map → openai-embeddings-SEIV7AM3.js.map} +0 -0
  149. /package/dist/{openrouter-RD2COFC7.js.map → openrouter-ELODIZRP.js.map} +0 -0
  150. /package/dist/{post-compact-AANLN7TR.js.map → post-compact-KNQ4DYLM.js.map} +0 -0
  151. /package/dist/{post-tool-use-X3IFZEMV.js.map → post-tool-use-OMWHFQLM.js.map} +0 -0
  152. /package/dist/{post-tool-use-failure-T6KAFDFF.js.map → post-tool-use-failure-KFP6MB7Z.js.map} +0 -0
  153. /package/dist/{pre-compact-FY7BPS4J.js.map → pre-compact-2ZYE2HRB.js.map} +0 -0
  154. /package/dist/{provider-check-QN7OGXZA.js.map → provider-check-B66E5PWS.js.map} +0 -0
  155. /package/dist/{registry-2XQMCPA6.js.map → registry-DHWVHXWY.js.map} +0 -0
  156. /package/dist/{resolution-events-5EVUEWHS.js.map → resolution-events-DBCRVZGU.js.map} +0 -0
  157. /package/dist/{restart-KT4R3QN5.js.map → restart-YQNQEHOU.js.map} +0 -0
  158. /package/dist/{search-NQFXQUUQ.js.map → search-C6JTQDWY.js.map} +0 -0
  159. /package/dist/{server-6QIP325R.js.map → server-QJ3RWZZZ.js.map} +0 -0
  160. /package/dist/{session-E7B3B4ZQ.js.map → session-JLVL5TYX.js.map} +0 -0
  161. /package/dist/{session-end-H2E42BZG.js.map → session-end-XFZRRP5H.js.map} +0 -0
  162. /package/dist/{session-start-FLND66CU.js.map → session-start-XGINISXO.js.map} +0 -0
  163. /package/dist/{setup-llm-YAXEM23S.js.map → setup-llm-X2OCM6R7.js.map} +0 -0
  164. /package/dist/{stats-MD4PUVRL.js.map → stats-2EAETG2T.js.map} +0 -0
  165. /package/dist/{stop-CFUWXMNB.js.map → stop-WOBDYTSA.js.map} +0 -0
  166. /package/dist/{stop-failure-ZOHR2EUI.js.map → stop-failure-QEC7ZGBQ.js.map} +0 -0
  167. /package/dist/{subagent-start-AXZAVBJU.js.map → subagent-start-H6DVRVOE.js.map} +0 -0
  168. /package/dist/{subagent-stop-FVQGEEZ4.js.map → subagent-stop-LKENKJ65.js.map} +0 -0
  169. /package/dist/{task-completed-NKJU2SRN.js.map → task-completed-ZZ47PRPD.js.map} +0 -0
  170. /package/dist/{user-prompt-submit-RRSLN6LA.js.map → user-prompt-submit-NNMLY3EW.js.map} +0 -0
  171. /package/dist/{verify-JHIMXTY5.js.map → verify-AMRQXQ3K.js.map} +0 -0
  172. /package/dist/{resolve-3FEUV462.js.map → version-6OJH5HLZ.js.map} +0 -0
@@ -2,10 +2,10 @@ import { createRequire as __cr } from 'node:module'; const require = __cr(import
2
2
  import {
3
3
  getTeamMachineId,
4
4
  syncRow
5
- } from "./chunk-S66YG6QK.js";
5
+ } from "./chunk-LF5Z62X6.js";
6
6
  import {
7
7
  loadConfig
8
- } from "./chunk-PSYLKCWQ.js";
8
+ } from "./chunk-4BQ5QE76.js";
9
9
  import {
10
10
  getDatabase
11
11
  } from "./chunk-MYX5NCRH.js";
@@ -21,207 +21,206 @@ import {
21
21
  epochSeconds
22
22
  } from "./chunk-TRA3R4EC.js";
23
23
 
24
- // src/db/queries/batches.ts
25
- var DEFAULT_UNPROCESSED_LIMIT = 100;
26
- var BATCHES_DEFAULT_LIMIT = 200;
24
+ // src/utils/error-message.ts
25
+ function errorMessage(err) {
26
+ if (err instanceof Error) return err.message || err.constructor.name || "Error";
27
+ if (typeof err === "string") return err || "Empty string error";
28
+ try {
29
+ return JSON.stringify(err);
30
+ } catch {
31
+ return "Unserializable error";
32
+ }
33
+ }
34
+
35
+ // src/db/queries/runs.ts
36
+ var DEFAULT_LIST_LIMIT2 = 100;
37
+ var DEFAULT_STATUS = "pending";
38
+ var STATUS_RUNNING = "running";
27
39
  var STATUS_COMPLETED = "completed";
28
- var DEFAULT_STATUS = "active";
29
- var DEFAULT_ACTIVITY_COUNT = 0;
30
- var DEFAULT_PROCESSED = 0;
31
- var PROCESSED_FLAG = 1;
32
- var PROMPT_PREFIX_MATCH_CHARS = 60;
33
- var BATCH_COLUMNS = [
40
+ var STATUS_FAILED = "failed";
41
+ var RUN_COLUMNS = [
34
42
  "id",
35
- "session_id",
36
- "prompt_number",
37
- "user_prompt",
38
- "response_summary",
39
- "classification",
40
- "started_at",
41
- "ended_at",
43
+ "agent_id",
44
+ "task",
45
+ "instruction",
42
46
  "status",
43
- "activity_count",
44
- "processed",
45
- "content_hash",
46
- "created_at",
47
- "machine_id",
48
- "synced_at"
47
+ "started_at",
48
+ "completed_at",
49
+ "tokens_used",
50
+ "cost_usd",
51
+ "actions_taken",
52
+ "error"
49
53
  ];
50
- var SELECT_COLUMNS = BATCH_COLUMNS.join(", ");
51
- function toBatchRow(row) {
54
+ var SELECT_COLUMNS = RUN_COLUMNS.join(", ");
55
+ function toRunRow(row) {
52
56
  return {
53
57
  id: row.id,
54
- session_id: row.session_id,
55
- prompt_number: row.prompt_number ?? null,
56
- user_prompt: row.user_prompt ?? null,
57
- response_summary: row.response_summary ?? null,
58
- classification: row.classification ?? null,
59
- started_at: row.started_at ?? null,
60
- ended_at: row.ended_at ?? null,
58
+ agent_id: row.agent_id,
59
+ task: row.task ?? null,
60
+ instruction: row.instruction ?? null,
61
61
  status: row.status,
62
- activity_count: row.activity_count,
63
- processed: row.processed,
64
- content_hash: row.content_hash ?? null,
65
- created_at: row.created_at,
66
- machine_id: row.machine_id ?? "local",
67
- synced_at: row.synced_at ?? null
62
+ started_at: row.started_at ?? null,
63
+ completed_at: row.completed_at ?? null,
64
+ tokens_used: row.tokens_used ?? null,
65
+ cost_usd: row.cost_usd ?? null,
66
+ actions_taken: row.actions_taken ?? null,
67
+ error: row.error ?? null
68
68
  };
69
69
  }
70
- function populateBatchResponses(sessionId, responses) {
71
- const db = getDatabase();
72
- const batches = db.prepare(
73
- `SELECT id FROM prompt_batches WHERE session_id = ? ORDER BY id ASC`
74
- ).all(sessionId);
75
- for (const { turnIndex, response } of responses) {
76
- const batchIndex = turnIndex - 1;
77
- if (batchIndex >= 0 && batchIndex < batches.length) {
78
- const batchId = batches[batchIndex].id;
79
- db.prepare(
80
- `UPDATE prompt_batches SET response_summary = ? WHERE id = ? AND response_summary IS NULL`
81
- ).run(response, batchId);
82
- }
83
- }
84
- }
85
- function getUnprocessedBatches(options = {}) {
86
- const db = getDatabase();
87
- const conditions = [`processed = ?`];
88
- const params = [DEFAULT_PROCESSED];
89
- if (options.after_id !== void 0) {
90
- conditions.push(`id > ?`);
91
- params.push(options.after_id);
92
- }
93
- const limit = options.limit ?? DEFAULT_UNPROCESSED_LIMIT;
94
- params.push(limit);
95
- const where = conditions.join(" AND ");
96
- const rows = db.prepare(
97
- `SELECT ${SELECT_COLUMNS}
98
- FROM prompt_batches
99
- WHERE ${where}
100
- ORDER BY id ASC
101
- LIMIT ?`
102
- ).all(...params);
103
- return rows.map(toBatchRow);
104
- }
105
- function incrementActivityCount(id) {
106
- const db = getDatabase();
107
- const info = db.prepare(
108
- `UPDATE prompt_batches
109
- SET activity_count = activity_count + 1
110
- WHERE id = ?`
111
- ).run(id);
112
- if (info.changes === 0) return null;
113
- return toBatchRow(
114
- db.prepare(`SELECT ${SELECT_COLUMNS} FROM prompt_batches WHERE id = ?`).get(id)
115
- );
116
- }
117
- function markBatchProcessed(id) {
118
- const db = getDatabase();
119
- const info = db.prepare(
120
- `UPDATE prompt_batches
121
- SET processed = ?
122
- WHERE id = ?`
123
- ).run(PROCESSED_FLAG, id);
124
- if (info.changes === 0) return null;
125
- return toBatchRow(
126
- db.prepare(`SELECT ${SELECT_COLUMNS} FROM prompt_batches WHERE id = ?`).get(id)
127
- );
128
- }
129
- function findBatchByPromptPrefix(sessionId, promptPrefix) {
130
- const db = getDatabase();
131
- const prefix = promptPrefix.slice(0, PROMPT_PREFIX_MATCH_CHARS);
132
- const row = db.prepare(
133
- `SELECT id, prompt_number FROM prompt_batches
134
- WHERE session_id = ? AND user_prompt LIKE ? || '%'
135
- LIMIT 1`
136
- ).get(sessionId, prefix);
137
- return row ?? null;
138
- }
139
- function insertBatchStateless(data) {
70
+ function insertRun(data) {
140
71
  const db = getDatabase();
141
- const info = db.prepare(
142
- `INSERT INTO prompt_batches (
143
- session_id, prompt_number, user_prompt, response_summary,
144
- classification, started_at, ended_at, status,
145
- activity_count, processed, content_hash, created_at, machine_id
72
+ db.prepare(
73
+ `INSERT INTO agent_runs (
74
+ id, agent_id, task, instruction, status,
75
+ started_at, completed_at, tokens_used, cost_usd,
76
+ actions_taken, error
146
77
  ) VALUES (
147
- ?,
148
- (SELECT COALESCE(MAX(prompt_number), 0) + 1 FROM prompt_batches WHERE session_id = ?),
149
- ?, NULL,
150
- NULL, ?, NULL, ?,
151
- ?, ?, NULL, ?, ?
78
+ ?, ?, ?, ?, ?,
79
+ ?, ?, ?, ?,
80
+ ?, ?
152
81
  )`
153
82
  ).run(
154
- data.session_id,
155
- data.session_id,
156
- data.user_prompt ?? null,
157
- data.started_at ?? null,
83
+ data.id,
84
+ data.agent_id,
85
+ data.task ?? null,
86
+ data.instruction ?? null,
158
87
  data.status ?? DEFAULT_STATUS,
159
- DEFAULT_ACTIVITY_COUNT,
160
- DEFAULT_PROCESSED,
161
- data.created_at,
162
- data.machine_id ?? getTeamMachineId()
88
+ data.started_at ?? null,
89
+ data.completed_at ?? null,
90
+ data.tokens_used ?? null,
91
+ data.cost_usd ?? null,
92
+ data.actions_taken ?? null,
93
+ data.error ?? null
163
94
  );
164
- const batchId = Number(info.lastInsertRowid);
165
- return toBatchRow(
166
- db.prepare(`SELECT ${SELECT_COLUMNS} FROM prompt_batches WHERE id = ?`).get(batchId)
95
+ return toRunRow(
96
+ db.prepare(`SELECT ${SELECT_COLUMNS} FROM agent_runs WHERE id = ?`).get(data.id)
167
97
  );
168
98
  }
169
- function closeOpenBatches(sessionId, endedAt) {
170
- const db = getDatabase();
171
- const info = db.prepare(
172
- `UPDATE prompt_batches
173
- SET status = ?, ended_at = ?
174
- WHERE session_id = ? AND ended_at IS NULL`
175
- ).run(STATUS_COMPLETED, endedAt, sessionId);
176
- return info.changes;
177
- }
178
- function setResponseSummary(batchId, summary) {
179
- const db = getDatabase();
180
- db.prepare(
181
- `UPDATE prompt_batches SET response_summary = ? WHERE id = ? AND response_summary IS NULL`
182
- ).run(summary, batchId);
183
- }
184
- function getLatestBatch(sessionId) {
99
+ function getRun(id) {
185
100
  const db = getDatabase();
186
101
  const row = db.prepare(
187
- `SELECT ${SELECT_COLUMNS} FROM prompt_batches
188
- WHERE session_id = ?
189
- ORDER BY id DESC LIMIT 1`
190
- ).get(sessionId);
102
+ `SELECT ${SELECT_COLUMNS} FROM agent_runs WHERE id = ?`
103
+ ).get(id);
191
104
  if (!row) return null;
192
- return toBatchRow(row);
105
+ return toRunRow(row);
193
106
  }
194
- function listBatchesBySession(sessionId, options = {}) {
107
+ function buildRunsWhere(options) {
108
+ const conditions = [];
109
+ const params = [];
110
+ if (options.agent_id !== void 0) {
111
+ conditions.push(`agent_id = ?`);
112
+ params.push(options.agent_id);
113
+ }
114
+ if (options.status !== void 0) {
115
+ conditions.push(`status = ?`);
116
+ params.push(options.status);
117
+ }
118
+ if (options.task !== void 0) {
119
+ conditions.push(`task = ?`);
120
+ params.push(options.task);
121
+ }
122
+ if (options.search !== void 0 && options.search.length > 0) {
123
+ conditions.push(`task LIKE ?`);
124
+ params.push(`%${options.search}%`);
125
+ }
126
+ return {
127
+ where: conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "",
128
+ params
129
+ };
130
+ }
131
+ function listRuns(options = {}) {
195
132
  const db = getDatabase();
196
- const limit = options.limit ?? BATCHES_DEFAULT_LIMIT;
133
+ const { where, params } = buildRunsWhere(options);
134
+ const limit = options.limit ?? DEFAULT_LIST_LIMIT2;
197
135
  const offset = options.offset ?? 0;
198
136
  const rows = db.prepare(
199
137
  `SELECT ${SELECT_COLUMNS}
200
- FROM prompt_batches
201
- WHERE session_id = ?
202
- ORDER BY prompt_number ASC
138
+ FROM agent_runs
139
+ ${where}
140
+ ORDER BY started_at DESC NULLS LAST
203
141
  LIMIT ?
204
142
  OFFSET ?`
205
- ).all(sessionId, limit, offset);
206
- return rows.map(toBatchRow);
143
+ ).all(...params, limit, offset);
144
+ return rows.map(toRunRow);
207
145
  }
208
- function countBatchesBySession(sessionId) {
146
+ function countRuns(options = {}) {
209
147
  const db = getDatabase();
148
+ const { where, params } = buildRunsWhere(options);
210
149
  const row = db.prepare(
211
- `SELECT COUNT(*) as count FROM prompt_batches WHERE session_id = ?`
212
- ).get(sessionId);
150
+ `SELECT COUNT(*) as count FROM agent_runs ${where}`
151
+ ).get(...params);
213
152
  return row.count;
214
153
  }
215
-
216
- // src/notifications/notify.ts
217
- import crypto from "crypto";
218
-
219
- // src/db/queries/notifications.ts
220
- var DEFAULT_LIMIT = 50;
221
- var NOTIFICATION_PRUNE_AGE_SECONDS = 30 * 24 * 60 * 60;
222
- function insertNotification(n) {
154
+ function updateRunStatus(id, status, completion) {
223
155
  const db = getDatabase();
224
- db.prepare(
156
+ const setClauses = ["status = ?"];
157
+ const params = [status];
158
+ if (completion?.completed_at !== void 0) {
159
+ setClauses.push(`completed_at = ?`);
160
+ params.push(completion.completed_at);
161
+ }
162
+ if (completion?.tokens_used !== void 0) {
163
+ setClauses.push(`tokens_used = ?`);
164
+ params.push(completion.tokens_used);
165
+ }
166
+ if (completion?.cost_usd !== void 0) {
167
+ setClauses.push(`cost_usd = ?`);
168
+ params.push(completion.cost_usd);
169
+ }
170
+ if (completion?.actions_taken !== void 0) {
171
+ setClauses.push(`actions_taken = ?`);
172
+ params.push(completion.actions_taken);
173
+ }
174
+ if (completion?.error !== void 0) {
175
+ setClauses.push(`error = ?`);
176
+ params.push(completion.error);
177
+ }
178
+ params.push(id);
179
+ const info = db.prepare(
180
+ `UPDATE agent_runs
181
+ SET ${setClauses.join(", ")}
182
+ WHERE id = ?`
183
+ ).run(...params);
184
+ if (info.changes === 0) return null;
185
+ return toRunRow(
186
+ db.prepare(`SELECT ${SELECT_COLUMNS} FROM agent_runs WHERE id = ?`).get(id)
187
+ );
188
+ }
189
+ function getRunningRunForTask(agentId, taskName) {
190
+ const db = getDatabase();
191
+ const row = db.prepare(
192
+ `SELECT id FROM agent_runs
193
+ WHERE agent_id = ? AND task = ? AND status = ?
194
+ LIMIT 1`
195
+ ).get(agentId, taskName, STATUS_RUNNING);
196
+ return row?.id ?? null;
197
+ }
198
+ function getLatestRunId(agentId, taskName) {
199
+ const db = getDatabase();
200
+ if (taskName) {
201
+ const row2 = db.prepare(
202
+ `SELECT id FROM agent_runs
203
+ WHERE agent_id = ? AND task = ?
204
+ ORDER BY started_at DESC
205
+ LIMIT 1`
206
+ ).get(agentId, taskName);
207
+ return row2?.id ?? null;
208
+ }
209
+ const row = db.prepare(
210
+ `SELECT id FROM agent_runs
211
+ WHERE agent_id = ?
212
+ ORDER BY started_at DESC
213
+ LIMIT 1`
214
+ ).get(agentId);
215
+ return row?.id ?? null;
216
+ }
217
+
218
+ // src/db/queries/notifications.ts
219
+ var DEFAULT_LIMIT = 50;
220
+ var NOTIFICATION_PRUNE_AGE_SECONDS = 30 * 24 * 60 * 60;
221
+ function insertNotification(n) {
222
+ const db = getDatabase();
223
+ db.prepare(
225
224
  `INSERT INTO notifications (id, domain, type, level, title, message, mode, status, link, metadata, created_at)
226
225
  VALUES (?, ?, ?, ?, ?, ?, ?, 'unread', ?, ?, ?)`
227
226
  ).run(n.id, n.domain, n.type, n.level, n.title, n.message, n.mode, n.link, n.metadata, epochSeconds());
@@ -303,6 +302,7 @@ function getType(typeId) {
303
302
  }
304
303
 
305
304
  // src/notifications/notify.ts
305
+ import crypto from "crypto";
306
306
  function notify(vaultDir, payload, config) {
307
307
  if (!vaultDir) return null;
308
308
  try {
@@ -332,17 +332,6 @@ function notify(vaultDir, payload, config) {
332
332
  }
333
333
  }
334
334
 
335
- // src/utils/error-message.ts
336
- function errorMessage(err) {
337
- if (err instanceof Error) return err.message || err.constructor.name || "Error";
338
- if (typeof err === "string") return err || "Empty string error";
339
- try {
340
- return JSON.stringify(err);
341
- } catch {
342
- return "Unserializable error";
343
- }
344
- }
345
-
346
335
  // src/db/queries/skill-candidates.ts
347
336
  var DEFAULT_CONFIDENCE = 0;
348
337
  var DEFAULT_STATUS2 = "identified";
@@ -693,241 +682,256 @@ function deleteSkillRecordCascade(idOrName) {
693
682
  return { id: record.id, name: record.name };
694
683
  }
695
684
 
696
- // src/db/queries/runs.ts
697
- var DEFAULT_LIST_LIMIT2 = 100;
698
- var DEFAULT_STATUS4 = "pending";
699
- var STATUS_RUNNING = "running";
700
- var STATUS_COMPLETED2 = "completed";
701
- var STATUS_FAILED = "failed";
702
- var RUN_COLUMNS = [
685
+ // src/db/queries/skill-lineage.ts
686
+ var LINEAGE_COLUMNS = [
703
687
  "id",
704
- "agent_id",
705
- "task",
706
- "instruction",
707
- "status",
708
- "started_at",
709
- "completed_at",
710
- "tokens_used",
711
- "cost_usd",
712
- "actions_taken",
713
- "error"
688
+ "skill_id",
689
+ "generation",
690
+ "action",
691
+ "rationale",
692
+ "source_ids_added",
693
+ "content_snapshot",
694
+ "created_at"
714
695
  ];
715
- var SELECT_COLUMNS4 = RUN_COLUMNS.join(", ");
716
- function toRunRow(row) {
696
+ var SELECT_COLUMNS4 = LINEAGE_COLUMNS.join(", ");
697
+ function toLineageRow(row) {
717
698
  return {
718
699
  id: row.id,
719
- agent_id: row.agent_id,
720
- task: row.task ?? null,
721
- instruction: row.instruction ?? null,
722
- status: row.status,
723
- started_at: row.started_at ?? null,
724
- completed_at: row.completed_at ?? null,
725
- tokens_used: row.tokens_used ?? null,
726
- cost_usd: row.cost_usd ?? null,
727
- actions_taken: row.actions_taken ?? null,
728
- error: row.error ?? null
700
+ skill_id: row.skill_id,
701
+ generation: row.generation,
702
+ action: row.action,
703
+ rationale: row.rationale,
704
+ source_ids_added: row.source_ids_added ?? "[]",
705
+ content_snapshot: row.content_snapshot,
706
+ created_at: row.created_at
729
707
  };
730
708
  }
731
- function insertRun(data) {
709
+ function insertLineage(data) {
732
710
  const db = getDatabase();
733
711
  db.prepare(
734
- `INSERT INTO agent_runs (
735
- id, agent_id, task, instruction, status,
736
- started_at, completed_at, tokens_used, cost_usd,
737
- actions_taken, error
712
+ `INSERT INTO skill_lineage (
713
+ id, skill_id, generation, action, rationale,
714
+ source_ids_added, content_snapshot, created_at
738
715
  ) VALUES (
739
716
  ?, ?, ?, ?, ?,
740
- ?, ?, ?, ?,
741
- ?, ?
717
+ ?, ?, ?
742
718
  )`
743
719
  ).run(
744
720
  data.id,
745
- data.agent_id,
746
- data.task ?? null,
747
- data.instruction ?? null,
748
- data.status ?? DEFAULT_STATUS4,
749
- data.started_at ?? null,
750
- data.completed_at ?? null,
751
- data.tokens_used ?? null,
752
- data.cost_usd ?? null,
753
- data.actions_taken ?? null,
754
- data.error ?? null
721
+ data.skill_id,
722
+ data.generation,
723
+ data.action,
724
+ data.rationale,
725
+ data.source_ids_added ?? "[]",
726
+ data.content_snapshot,
727
+ data.created_at
755
728
  );
756
- return toRunRow(
757
- db.prepare(`SELECT ${SELECT_COLUMNS4} FROM agent_runs WHERE id = ?`).get(data.id)
729
+ return toLineageRow(
730
+ db.prepare(`SELECT ${SELECT_COLUMNS4} FROM skill_lineage WHERE id = ?`).get(data.id)
758
731
  );
759
732
  }
760
- function getRun(id) {
733
+ function listLineageForSkill(skillId, limit = 50) {
761
734
  const db = getDatabase();
762
- const row = db.prepare(
763
- `SELECT ${SELECT_COLUMNS4} FROM agent_runs WHERE id = ?`
764
- ).get(id);
765
- if (!row) return null;
766
- return toRunRow(row);
735
+ const rows = db.prepare(
736
+ `SELECT ${SELECT_COLUMNS4}
737
+ FROM skill_lineage
738
+ WHERE skill_id = ?
739
+ ORDER BY generation DESC
740
+ LIMIT ?`
741
+ ).all(skillId, limit);
742
+ return rows.map(toLineageRow);
767
743
  }
768
- function buildRunsWhere(options) {
769
- const conditions = [];
770
- const params = [];
771
- if (options.agent_id !== void 0) {
772
- conditions.push(`agent_id = ?`);
773
- params.push(options.agent_id);
774
- }
775
- if (options.status !== void 0) {
776
- conditions.push(`status = ?`);
777
- params.push(options.status);
778
- }
779
- if (options.task !== void 0) {
780
- conditions.push(`task = ?`);
781
- params.push(options.task);
782
- }
783
- if (options.search !== void 0 && options.search.length > 0) {
784
- conditions.push(`task LIKE ?`);
785
- params.push(`%${options.search}%`);
786
- }
744
+
745
+ // src/db/queries/batches.ts
746
+ var DEFAULT_UNPROCESSED_LIMIT = 100;
747
+ var BATCHES_DEFAULT_LIMIT = 200;
748
+ var STATUS_COMPLETED2 = "completed";
749
+ var DEFAULT_STATUS4 = "active";
750
+ var DEFAULT_ACTIVITY_COUNT = 0;
751
+ var DEFAULT_PROCESSED = 0;
752
+ var PROCESSED_FLAG = 1;
753
+ var PROMPT_PREFIX_MATCH_CHARS = 60;
754
+ var BATCH_COLUMNS = [
755
+ "id",
756
+ "session_id",
757
+ "prompt_number",
758
+ "user_prompt",
759
+ "response_summary",
760
+ "classification",
761
+ "started_at",
762
+ "ended_at",
763
+ "status",
764
+ "activity_count",
765
+ "processed",
766
+ "content_hash",
767
+ "created_at",
768
+ "machine_id",
769
+ "synced_at"
770
+ ];
771
+ var SELECT_COLUMNS5 = BATCH_COLUMNS.join(", ");
772
+ function toBatchRow(row) {
787
773
  return {
788
- where: conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "",
789
- params
774
+ id: row.id,
775
+ session_id: row.session_id,
776
+ prompt_number: row.prompt_number ?? null,
777
+ user_prompt: row.user_prompt ?? null,
778
+ response_summary: row.response_summary ?? null,
779
+ classification: row.classification ?? null,
780
+ started_at: row.started_at ?? null,
781
+ ended_at: row.ended_at ?? null,
782
+ status: row.status,
783
+ activity_count: row.activity_count,
784
+ processed: row.processed,
785
+ content_hash: row.content_hash ?? null,
786
+ created_at: row.created_at,
787
+ machine_id: row.machine_id ?? "local",
788
+ synced_at: row.synced_at ?? null
790
789
  };
791
790
  }
792
- function listRuns(options = {}) {
791
+ function populateBatchResponses(sessionId, responses) {
793
792
  const db = getDatabase();
794
- const { where, params } = buildRunsWhere(options);
795
- const limit = options.limit ?? DEFAULT_LIST_LIMIT2;
796
- const offset = options.offset ?? 0;
797
- const rows = db.prepare(
798
- `SELECT ${SELECT_COLUMNS4}
799
- FROM agent_runs
800
- ${where}
801
- ORDER BY started_at DESC NULLS LAST
802
- LIMIT ?
803
- OFFSET ?`
804
- ).all(...params, limit, offset);
805
- return rows.map(toRunRow);
793
+ const batches = db.prepare(
794
+ `SELECT id FROM prompt_batches WHERE session_id = ? ORDER BY id ASC`
795
+ ).all(sessionId);
796
+ for (const { turnIndex, response } of responses) {
797
+ const batchIndex = turnIndex - 1;
798
+ if (batchIndex >= 0 && batchIndex < batches.length) {
799
+ const batchId = batches[batchIndex].id;
800
+ db.prepare(
801
+ `UPDATE prompt_batches SET response_summary = ? WHERE id = ? AND response_summary IS NULL`
802
+ ).run(response, batchId);
803
+ }
804
+ }
806
805
  }
807
- function countRuns(options = {}) {
806
+ function getUnprocessedBatches(options = {}) {
808
807
  const db = getDatabase();
809
- const { where, params } = buildRunsWhere(options);
810
- const row = db.prepare(
811
- `SELECT COUNT(*) as count FROM agent_runs ${where}`
812
- ).get(...params);
813
- return row.count;
808
+ const conditions = [`processed = ?`];
809
+ const params = [DEFAULT_PROCESSED];
810
+ if (options.after_id !== void 0) {
811
+ conditions.push(`id > ?`);
812
+ params.push(options.after_id);
813
+ }
814
+ const limit = options.limit ?? DEFAULT_UNPROCESSED_LIMIT;
815
+ params.push(limit);
816
+ const where = conditions.join(" AND ");
817
+ const rows = db.prepare(
818
+ `SELECT ${SELECT_COLUMNS5}
819
+ FROM prompt_batches
820
+ WHERE ${where}
821
+ ORDER BY id ASC
822
+ LIMIT ?`
823
+ ).all(...params);
824
+ return rows.map(toBatchRow);
814
825
  }
815
- function updateRunStatus(id, status, completion) {
826
+ function incrementActivityCount(id) {
816
827
  const db = getDatabase();
817
- const setClauses = ["status = ?"];
818
- const params = [status];
819
- if (completion?.completed_at !== void 0) {
820
- setClauses.push(`completed_at = ?`);
821
- params.push(completion.completed_at);
822
- }
823
- if (completion?.tokens_used !== void 0) {
824
- setClauses.push(`tokens_used = ?`);
825
- params.push(completion.tokens_used);
826
- }
827
- if (completion?.cost_usd !== void 0) {
828
- setClauses.push(`cost_usd = ?`);
829
- params.push(completion.cost_usd);
830
- }
831
- if (completion?.actions_taken !== void 0) {
832
- setClauses.push(`actions_taken = ?`);
833
- params.push(completion.actions_taken);
834
- }
835
- if (completion?.error !== void 0) {
836
- setClauses.push(`error = ?`);
837
- params.push(completion.error);
838
- }
839
- params.push(id);
840
828
  const info = db.prepare(
841
- `UPDATE agent_runs
842
- SET ${setClauses.join(", ")}
829
+ `UPDATE prompt_batches
830
+ SET activity_count = activity_count + 1
843
831
  WHERE id = ?`
844
- ).run(...params);
832
+ ).run(id);
845
833
  if (info.changes === 0) return null;
846
- return toRunRow(
847
- db.prepare(`SELECT ${SELECT_COLUMNS4} FROM agent_runs WHERE id = ?`).get(id)
834
+ return toBatchRow(
835
+ db.prepare(`SELECT ${SELECT_COLUMNS5} FROM prompt_batches WHERE id = ?`).get(id)
848
836
  );
849
837
  }
850
- function getRunningRunForTask(agentId, taskName) {
838
+ function markBatchProcessed(id) {
851
839
  const db = getDatabase();
852
- const row = db.prepare(
853
- `SELECT id FROM agent_runs
854
- WHERE agent_id = ? AND task = ? AND status = ?
855
- LIMIT 1`
856
- ).get(agentId, taskName, STATUS_RUNNING);
857
- return row?.id ?? null;
840
+ const info = db.prepare(
841
+ `UPDATE prompt_batches
842
+ SET processed = ?
843
+ WHERE id = ?`
844
+ ).run(PROCESSED_FLAG, id);
845
+ if (info.changes === 0) return null;
846
+ return toBatchRow(
847
+ db.prepare(`SELECT ${SELECT_COLUMNS5} FROM prompt_batches WHERE id = ?`).get(id)
848
+ );
858
849
  }
859
- function getLatestRunId(agentId, taskName) {
850
+ function findBatchByPromptPrefix(sessionId, promptPrefix) {
860
851
  const db = getDatabase();
861
- if (taskName) {
862
- const row2 = db.prepare(
863
- `SELECT id FROM agent_runs
864
- WHERE agent_id = ? AND task = ?
865
- ORDER BY started_at DESC
866
- LIMIT 1`
867
- ).get(agentId, taskName);
868
- return row2?.id ?? null;
869
- }
852
+ const prefix = promptPrefix.slice(0, PROMPT_PREFIX_MATCH_CHARS);
870
853
  const row = db.prepare(
871
- `SELECT id FROM agent_runs
872
- WHERE agent_id = ?
873
- ORDER BY started_at DESC
854
+ `SELECT id, prompt_number FROM prompt_batches
855
+ WHERE session_id = ? AND user_prompt LIKE ? || '%'
874
856
  LIMIT 1`
875
- ).get(agentId);
876
- return row?.id ?? null;
877
- }
878
-
879
- // src/db/queries/reports.ts
880
- var REPORT_COLUMNS = [
881
- "id",
882
- "run_id",
883
- "agent_id",
884
- "action",
885
- "summary",
886
- "details",
887
- "created_at"
888
- ];
889
- var SELECT_COLUMNS5 = REPORT_COLUMNS.join(", ");
890
- function toReportRow(row) {
891
- return {
892
- id: row.id,
893
- run_id: row.run_id,
894
- agent_id: row.agent_id,
895
- action: row.action,
896
- summary: row.summary,
897
- details: row.details ?? null,
898
- created_at: row.created_at
899
- };
857
+ ).get(sessionId, prefix);
858
+ return row ?? null;
900
859
  }
901
- function insertReport(data) {
860
+ function insertBatchStateless(data) {
902
861
  const db = getDatabase();
903
862
  const info = db.prepare(
904
- `INSERT INTO agent_reports (
905
- run_id, agent_id, action, summary, details, created_at
863
+ `INSERT INTO prompt_batches (
864
+ session_id, prompt_number, user_prompt, response_summary,
865
+ classification, started_at, ended_at, status,
866
+ activity_count, processed, content_hash, created_at, machine_id
906
867
  ) VALUES (
907
- ?, ?, ?, ?, ?, ?
868
+ ?,
869
+ (SELECT COALESCE(MAX(prompt_number), 0) + 1 FROM prompt_batches WHERE session_id = ?),
870
+ ?, NULL,
871
+ NULL, ?, NULL, ?,
872
+ ?, ?, NULL, ?, ?
908
873
  )`
909
874
  ).run(
910
- data.run_id,
911
- data.agent_id,
912
- data.action,
913
- data.summary,
914
- data.details ?? null,
915
- data.created_at
875
+ data.session_id,
876
+ data.session_id,
877
+ data.user_prompt ?? null,
878
+ data.started_at ?? null,
879
+ data.status ?? DEFAULT_STATUS4,
880
+ DEFAULT_ACTIVITY_COUNT,
881
+ DEFAULT_PROCESSED,
882
+ data.created_at,
883
+ data.machine_id ?? getTeamMachineId()
916
884
  );
917
- const reportId = Number(info.lastInsertRowid);
918
- return toReportRow(
919
- db.prepare(`SELECT ${SELECT_COLUMNS5} FROM agent_reports WHERE id = ?`).get(reportId)
885
+ const batchId = Number(info.lastInsertRowid);
886
+ return toBatchRow(
887
+ db.prepare(`SELECT ${SELECT_COLUMNS5} FROM prompt_batches WHERE id = ?`).get(batchId)
920
888
  );
921
889
  }
922
- function listReports(runId) {
890
+ function closeOpenBatches(sessionId, endedAt) {
891
+ const db = getDatabase();
892
+ const info = db.prepare(
893
+ `UPDATE prompt_batches
894
+ SET status = ?, ended_at = ?
895
+ WHERE session_id = ? AND ended_at IS NULL`
896
+ ).run(STATUS_COMPLETED2, endedAt, sessionId);
897
+ return info.changes;
898
+ }
899
+ function setResponseSummary(batchId, summary) {
900
+ const db = getDatabase();
901
+ db.prepare(
902
+ `UPDATE prompt_batches SET response_summary = ? WHERE id = ? AND response_summary IS NULL`
903
+ ).run(summary, batchId);
904
+ }
905
+ function getLatestBatch(sessionId) {
906
+ const db = getDatabase();
907
+ const row = db.prepare(
908
+ `SELECT ${SELECT_COLUMNS5} FROM prompt_batches
909
+ WHERE session_id = ?
910
+ ORDER BY id DESC LIMIT 1`
911
+ ).get(sessionId);
912
+ if (!row) return null;
913
+ return toBatchRow(row);
914
+ }
915
+ function listBatchesBySession(sessionId, options = {}) {
923
916
  const db = getDatabase();
917
+ const limit = options.limit ?? BATCHES_DEFAULT_LIMIT;
918
+ const offset = options.offset ?? 0;
924
919
  const rows = db.prepare(
925
920
  `SELECT ${SELECT_COLUMNS5}
926
- FROM agent_reports
927
- WHERE run_id = ?
928
- ORDER BY created_at ASC`
929
- ).all(runId);
930
- return rows.map(toReportRow);
921
+ FROM prompt_batches
922
+ WHERE session_id = ?
923
+ ORDER BY prompt_number ASC
924
+ LIMIT ?
925
+ OFFSET ?`
926
+ ).all(sessionId, limit, offset);
927
+ return rows.map(toBatchRow);
928
+ }
929
+ function countBatchesBySession(sessionId) {
930
+ const db = getDatabase();
931
+ const row = db.prepare(
932
+ `SELECT COUNT(*) as count FROM prompt_batches WHERE session_id = ?`
933
+ ).get(sessionId);
934
+ return row.count;
931
935
  }
932
936
 
933
937
  // src/db/queries/graph-edges.ts
@@ -1066,62 +1070,6 @@ function getGraphForNode(nodeId, nodeType, options) {
1066
1070
  return { edges: collectedEdges };
1067
1071
  }
1068
1072
 
1069
- // src/db/queries/lineage.ts
1070
- function createSporeLineage(spore) {
1071
- if (spore.session_id) {
1072
- insertGraphEdge({
1073
- agent_id: spore.agent_id,
1074
- source_id: spore.id,
1075
- source_type: "spore",
1076
- target_id: spore.session_id,
1077
- target_type: "session",
1078
- type: EDGE_TYPE_FROM_SESSION,
1079
- created_at: spore.created_at
1080
- });
1081
- }
1082
- if (spore.prompt_batch_id != null) {
1083
- insertGraphEdge({
1084
- agent_id: spore.agent_id,
1085
- source_id: spore.id,
1086
- source_type: "spore",
1087
- target_id: String(spore.prompt_batch_id),
1088
- target_type: "batch",
1089
- type: EDGE_TYPE_EXTRACTED_FROM,
1090
- created_at: spore.created_at
1091
- });
1092
- }
1093
- if (spore.observation_type === "wisdom" && spore.properties) {
1094
- try {
1095
- const props = JSON.parse(spore.properties);
1096
- if (Array.isArray(props.consolidated_from)) {
1097
- for (const sourceId of props.consolidated_from) {
1098
- insertGraphEdge({
1099
- agent_id: spore.agent_id,
1100
- source_id: spore.id,
1101
- source_type: "spore",
1102
- target_id: sourceId,
1103
- target_type: "spore",
1104
- type: EDGE_TYPE_DERIVED_FROM,
1105
- created_at: spore.created_at
1106
- });
1107
- }
1108
- }
1109
- } catch {
1110
- }
1111
- }
1112
- }
1113
- function createBatchLineage(agentId, sessionId, batchId, createdAt) {
1114
- insertGraphEdge({
1115
- agent_id: agentId,
1116
- source_id: sessionId,
1117
- source_type: "session",
1118
- target_id: String(batchId),
1119
- target_type: "batch",
1120
- type: EDGE_TYPE_HAS_BATCH,
1121
- created_at: createdAt
1122
- });
1123
- }
1124
-
1125
1073
  // src/db/queries/entities.ts
1126
1074
  var DEFAULT_LIST_LIMIT3 = 100;
1127
1075
  var ENTITY_COLUMNS = [
@@ -1292,97 +1240,126 @@ function listDigestExtracts(agentId) {
1292
1240
  return rows.map(toDigestExtractRow);
1293
1241
  }
1294
1242
 
1295
- // src/db/queries/skill-lineage.ts
1296
- var LINEAGE_COLUMNS = [
1243
+ // src/db/queries/lineage.ts
1244
+ function createSporeLineage(spore) {
1245
+ if (spore.session_id) {
1246
+ insertGraphEdge({
1247
+ agent_id: spore.agent_id,
1248
+ source_id: spore.id,
1249
+ source_type: "spore",
1250
+ target_id: spore.session_id,
1251
+ target_type: "session",
1252
+ type: EDGE_TYPE_FROM_SESSION,
1253
+ created_at: spore.created_at
1254
+ });
1255
+ }
1256
+ if (spore.prompt_batch_id != null) {
1257
+ insertGraphEdge({
1258
+ agent_id: spore.agent_id,
1259
+ source_id: spore.id,
1260
+ source_type: "spore",
1261
+ target_id: String(spore.prompt_batch_id),
1262
+ target_type: "batch",
1263
+ type: EDGE_TYPE_EXTRACTED_FROM,
1264
+ created_at: spore.created_at
1265
+ });
1266
+ }
1267
+ if (spore.observation_type === "wisdom" && spore.properties) {
1268
+ try {
1269
+ const props = JSON.parse(spore.properties);
1270
+ if (Array.isArray(props.consolidated_from)) {
1271
+ for (const sourceId of props.consolidated_from) {
1272
+ insertGraphEdge({
1273
+ agent_id: spore.agent_id,
1274
+ source_id: spore.id,
1275
+ source_type: "spore",
1276
+ target_id: sourceId,
1277
+ target_type: "spore",
1278
+ type: EDGE_TYPE_DERIVED_FROM,
1279
+ created_at: spore.created_at
1280
+ });
1281
+ }
1282
+ }
1283
+ } catch {
1284
+ }
1285
+ }
1286
+ }
1287
+ function createBatchLineage(agentId, sessionId, batchId, createdAt) {
1288
+ insertGraphEdge({
1289
+ agent_id: agentId,
1290
+ source_id: sessionId,
1291
+ source_type: "session",
1292
+ target_id: String(batchId),
1293
+ target_type: "batch",
1294
+ type: EDGE_TYPE_HAS_BATCH,
1295
+ created_at: createdAt
1296
+ });
1297
+ }
1298
+
1299
+ // src/db/queries/reports.ts
1300
+ var REPORT_COLUMNS = [
1297
1301
  "id",
1298
- "skill_id",
1299
- "generation",
1302
+ "run_id",
1303
+ "agent_id",
1300
1304
  "action",
1301
- "rationale",
1302
- "source_ids_added",
1303
- "content_snapshot",
1305
+ "summary",
1306
+ "details",
1304
1307
  "created_at"
1305
1308
  ];
1306
- var SELECT_COLUMNS9 = LINEAGE_COLUMNS.join(", ");
1307
- function toLineageRow(row) {
1309
+ var SELECT_COLUMNS9 = REPORT_COLUMNS.join(", ");
1310
+ function toReportRow(row) {
1308
1311
  return {
1309
1312
  id: row.id,
1310
- skill_id: row.skill_id,
1311
- generation: row.generation,
1313
+ run_id: row.run_id,
1314
+ agent_id: row.agent_id,
1312
1315
  action: row.action,
1313
- rationale: row.rationale,
1314
- source_ids_added: row.source_ids_added ?? "[]",
1315
- content_snapshot: row.content_snapshot,
1316
+ summary: row.summary,
1317
+ details: row.details ?? null,
1316
1318
  created_at: row.created_at
1317
1319
  };
1318
1320
  }
1319
- function insertLineage(data) {
1321
+ function insertReport(data) {
1320
1322
  const db = getDatabase();
1321
- db.prepare(
1322
- `INSERT INTO skill_lineage (
1323
- id, skill_id, generation, action, rationale,
1324
- source_ids_added, content_snapshot, created_at
1323
+ const info = db.prepare(
1324
+ `INSERT INTO agent_reports (
1325
+ run_id, agent_id, action, summary, details, created_at
1325
1326
  ) VALUES (
1326
- ?, ?, ?, ?, ?,
1327
- ?, ?, ?
1327
+ ?, ?, ?, ?, ?, ?
1328
1328
  )`
1329
1329
  ).run(
1330
- data.id,
1331
- data.skill_id,
1332
- data.generation,
1330
+ data.run_id,
1331
+ data.agent_id,
1333
1332
  data.action,
1334
- data.rationale,
1335
- data.source_ids_added ?? "[]",
1336
- data.content_snapshot,
1333
+ data.summary,
1334
+ data.details ?? null,
1337
1335
  data.created_at
1338
1336
  );
1339
- return toLineageRow(
1340
- db.prepare(`SELECT ${SELECT_COLUMNS9} FROM skill_lineage WHERE id = ?`).get(data.id)
1337
+ const reportId = Number(info.lastInsertRowid);
1338
+ return toReportRow(
1339
+ db.prepare(`SELECT ${SELECT_COLUMNS9} FROM agent_reports WHERE id = ?`).get(reportId)
1341
1340
  );
1342
1341
  }
1343
- function listLineageForSkill(skillId, limit = 50) {
1342
+ function listReports(runId) {
1344
1343
  const db = getDatabase();
1345
1344
  const rows = db.prepare(
1346
1345
  `SELECT ${SELECT_COLUMNS9}
1347
- FROM skill_lineage
1348
- WHERE skill_id = ?
1349
- ORDER BY generation DESC
1350
- LIMIT ?`
1351
- ).all(skillId, limit);
1352
- return rows.map(toLineageRow);
1346
+ FROM agent_reports
1347
+ WHERE run_id = ?
1348
+ ORDER BY created_at ASC`
1349
+ ).all(runId);
1350
+ return rows.map(toReportRow);
1353
1351
  }
1354
1352
 
1355
1353
  export {
1356
- populateBatchResponses,
1357
- getUnprocessedBatches,
1358
- incrementActivityCount,
1359
- markBatchProcessed,
1360
- findBatchByPromptPrefix,
1361
- insertBatchStateless,
1362
- closeOpenBatches,
1363
- setResponseSummary,
1364
- getLatestBatch,
1365
- listBatchesBySession,
1366
- countBatchesBySession,
1367
- insertGraphEdge,
1368
- listGraphEdges,
1369
- getGraphForNode,
1370
- insertEntity,
1371
- getEntity,
1372
- listEntities,
1373
- upsertDigestExtract,
1374
- getDigestExtract,
1375
- listDigestExtracts,
1376
- register,
1377
- getAllDomains,
1378
1354
  listNotifications,
1379
1355
  countNotifications,
1380
1356
  getNotification,
1381
1357
  updateNotificationStatus,
1382
1358
  dismissAllNotifications,
1383
1359
  markAllRead,
1360
+ register,
1361
+ getAllDomains,
1384
1362
  notify,
1385
- errorMessage,
1386
1363
  insertCandidate,
1387
1364
  getCandidate,
1388
1365
  listCandidates,
@@ -1401,8 +1378,29 @@ export {
1401
1378
  deleteSkillRecordCascade,
1402
1379
  insertLineage,
1403
1380
  listLineageForSkill,
1381
+ populateBatchResponses,
1382
+ getUnprocessedBatches,
1383
+ incrementActivityCount,
1384
+ markBatchProcessed,
1385
+ findBatchByPromptPrefix,
1386
+ insertBatchStateless,
1387
+ closeOpenBatches,
1388
+ setResponseSummary,
1389
+ getLatestBatch,
1390
+ listBatchesBySession,
1391
+ countBatchesBySession,
1392
+ insertGraphEdge,
1393
+ listGraphEdges,
1394
+ getGraphForNode,
1395
+ insertEntity,
1396
+ getEntity,
1397
+ listEntities,
1398
+ upsertDigestExtract,
1399
+ getDigestExtract,
1400
+ listDigestExtracts,
1401
+ errorMessage,
1404
1402
  STATUS_RUNNING,
1405
- STATUS_COMPLETED2 as STATUS_COMPLETED,
1403
+ STATUS_COMPLETED,
1406
1404
  STATUS_FAILED,
1407
1405
  insertRun,
1408
1406
  getRun,
@@ -1411,9 +1409,9 @@ export {
1411
1409
  updateRunStatus,
1412
1410
  getRunningRunForTask,
1413
1411
  getLatestRunId,
1414
- insertReport,
1415
- listReports,
1416
1412
  createSporeLineage,
1417
- createBatchLineage
1413
+ createBatchLineage,
1414
+ insertReport,
1415
+ listReports
1418
1416
  };
1419
- //# sourceMappingURL=chunk-JJXVDCEX.js.map
1417
+ //# sourceMappingURL=chunk-75J2BR4P.js.map