@mndrk/agx 2.0.25 → 2.0.32

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 (844) hide show
  1. package/README.md +4 -6
  2. package/cloud-runtime/standalone/.next/BUILD_ID +1 -1
  3. package/cloud-runtime/standalone/.next/app-path-routes-manifest.json +6 -0
  4. package/cloud-runtime/standalone/.next/build-manifest.json +4 -4
  5. package/cloud-runtime/standalone/.next/prerender-manifest.json +3 -3
  6. package/cloud-runtime/standalone/.next/required-server-files.json +4 -4
  7. package/cloud-runtime/standalone/.next/routes-manifest.json +45 -0
  8. package/cloud-runtime/standalone/.next/server/app/_global-error/page/build-manifest.json +2 -2
  9. package/cloud-runtime/standalone/.next/server/app/_global-error.html +2 -2
  10. package/cloud-runtime/standalone/.next/server/app/_global-error.rsc +1 -1
  11. package/cloud-runtime/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  12. package/cloud-runtime/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  13. package/cloud-runtime/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  14. package/cloud-runtime/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  15. package/cloud-runtime/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/cloud-runtime/standalone/.next/server/app/_not-found/page/build-manifest.json +2 -2
  17. package/cloud-runtime/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/cloud-runtime/standalone/.next/server/app/_not-found.html +2 -2
  19. package/cloud-runtime/standalone/.next/server/app/_not-found.rsc +2 -2
  20. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  21. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  22. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  23. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  24. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  25. package/cloud-runtime/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  26. package/cloud-runtime/standalone/.next/server/app/agents/[id]/page/build-manifest.json +2 -2
  27. package/cloud-runtime/standalone/.next/server/app/agents/[id]/page.js.nft.json +1 -1
  28. package/cloud-runtime/standalone/.next/server/app/agents/[id]/page_client-reference-manifest.js +1 -1
  29. package/cloud-runtime/standalone/.next/server/app/agents/page/build-manifest.json +2 -2
  30. package/cloud-runtime/standalone/.next/server/app/agents/page.js.nft.json +1 -1
  31. package/cloud-runtime/standalone/.next/server/app/agents/page_client-reference-manifest.js +1 -1
  32. package/cloud-runtime/standalone/.next/server/app/agents.html +2 -2
  33. package/cloud-runtime/standalone/.next/server/app/agents.rsc +3 -3
  34. package/cloud-runtime/standalone/.next/server/app/agents.segments/_full.segment.rsc +3 -3
  35. package/cloud-runtime/standalone/.next/server/app/agents.segments/_head.segment.rsc +1 -1
  36. package/cloud-runtime/standalone/.next/server/app/agents.segments/_index.segment.rsc +2 -2
  37. package/cloud-runtime/standalone/.next/server/app/agents.segments/_tree.segment.rsc +2 -2
  38. package/cloud-runtime/standalone/.next/server/app/agents.segments/agents/__PAGE__.segment.rsc +2 -2
  39. package/cloud-runtime/standalone/.next/server/app/agents.segments/agents.segment.rsc +1 -1
  40. package/cloud-runtime/standalone/.next/server/app/api/agent-specs/route.js +2 -2
  41. package/cloud-runtime/standalone/.next/server/app/api/agent-specs/route.js.nft.json +1 -1
  42. package/cloud-runtime/standalone/.next/server/app/api/agents/[id]/profile/route.js +2 -2
  43. package/cloud-runtime/standalone/.next/server/app/api/agents/[id]/profile/route.js.nft.json +1 -1
  44. package/cloud-runtime/standalone/.next/server/app/api/agents/export/route.js +2 -2
  45. package/cloud-runtime/standalone/.next/server/app/api/agents/export/route.js.nft.json +1 -1
  46. package/cloud-runtime/standalone/.next/server/app/api/automations/create/route.js +4 -3
  47. package/cloud-runtime/standalone/.next/server/app/api/automations/create/route.js.nft.json +1 -1
  48. package/cloud-runtime/standalone/.next/server/app/api/automations/route.js +3 -3
  49. package/cloud-runtime/standalone/.next/server/app/api/automations/route.js.nft.json +1 -1
  50. package/cloud-runtime/standalone/.next/server/app/api/chat/route.js +7 -4
  51. package/cloud-runtime/standalone/.next/server/app/api/chat/route.js.nft.json +1 -1
  52. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route/app-paths-manifest.json +3 -0
  53. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route/build-manifest.json +11 -0
  54. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route/server-reference-manifest.json +4 -0
  55. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route.js +8 -0
  56. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route.js.map +5 -0
  57. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route.js.nft.json +1 -0
  58. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/route_client-reference-manifest.js +2 -0
  59. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route/app-paths-manifest.json +3 -0
  60. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route/build-manifest.json +11 -0
  61. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route/server-reference-manifest.json +4 -0
  62. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route.js +7 -0
  63. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route.js.map +5 -0
  64. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route.js.nft.json +1 -0
  65. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/[id]/signal/route_client-reference-manifest.js +2 -0
  66. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route/app-paths-manifest.json +3 -0
  67. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route/build-manifest.json +11 -0
  68. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route/server-reference-manifest.json +4 -0
  69. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route.js +8 -0
  70. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route.js.map +5 -0
  71. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route.js.nft.json +1 -0
  72. package/cloud-runtime/standalone/.next/server/app/api/chat-runs/route_client-reference-manifest.js +2 -0
  73. package/cloud-runtime/standalone/.next/server/app/api/file-search/route.js.nft.json +1 -1
  74. package/cloud-runtime/standalone/.next/server/app/api/graphs/[graphId]/nodes/[nodeId]/route.js +2 -2
  75. package/cloud-runtime/standalone/.next/server/app/api/graphs/[graphId]/nodes/[nodeId]/route.js.nft.json +1 -1
  76. package/cloud-runtime/standalone/.next/server/app/api/health/route.js +5 -4
  77. package/cloud-runtime/standalone/.next/server/app/api/health/route.js.nft.json +1 -1
  78. package/cloud-runtime/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  79. package/cloud-runtime/standalone/.next/server/app/api/history/status/route.js.nft.json +1 -1
  80. package/cloud-runtime/standalone/.next/server/app/api/learnings/route.js +5 -4
  81. package/cloud-runtime/standalone/.next/server/app/api/learnings/route.js.nft.json +1 -1
  82. package/cloud-runtime/standalone/.next/server/app/api/logs/route.js.nft.json +1 -1
  83. package/cloud-runtime/standalone/.next/server/app/api/logs/stream/route.js +2 -2
  84. package/cloud-runtime/standalone/.next/server/app/api/logs/stream/route.js.nft.json +1 -1
  85. package/cloud-runtime/standalone/.next/server/app/api/memories/route.js +2 -2
  86. package/cloud-runtime/standalone/.next/server/app/api/memories/route.js.nft.json +1 -1
  87. package/cloud-runtime/standalone/.next/server/app/api/messages/[id]/route.js.nft.json +1 -1
  88. package/cloud-runtime/standalone/.next/server/app/api/migrate/teams-to-projects/route.js +2 -2
  89. package/cloud-runtime/standalone/.next/server/app/api/migrate/teams-to-projects/route.js.nft.json +1 -1
  90. package/cloud-runtime/standalone/.next/server/app/api/migrate/workspaces-to-projects/route.js +2 -2
  91. package/cloud-runtime/standalone/.next/server/app/api/migrate/workspaces-to-projects/route.js.nft.json +1 -1
  92. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/cancel/route.js +3 -3
  93. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/cancel/route.js.nft.json +1 -1
  94. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/signal/route.js +3 -3
  95. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/signal/route.js.nft.json +1 -1
  96. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/start/route.js +5 -4
  97. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/start/route.js.nft.json +1 -1
  98. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/status/route.js +4 -3
  99. package/cloud-runtime/standalone/.next/server/app/api/orchestrator/tasks/[taskId]/status/route.js.nft.json +1 -1
  100. package/cloud-runtime/standalone/.next/server/app/api/participants/route.js +3 -3
  101. package/cloud-runtime/standalone/.next/server/app/api/participants/route.js.nft.json +1 -1
  102. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/agents/route.js +3 -3
  103. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/agents/route.js.nft.json +1 -1
  104. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/memory/route.js +4 -4
  105. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/memory/route.js.nft.json +1 -1
  106. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/migrate-v1/route.js +4 -4
  107. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/migrate-v1/route.js.nft.json +1 -1
  108. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/migrate-v2/route.js +4 -4
  109. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/migrate-v2/route.js.nft.json +1 -1
  110. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/route.js +4 -3
  111. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/route.js.nft.json +1 -1
  112. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/skills/route.js +3 -3
  113. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/skills/route.js.nft.json +1 -1
  114. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/threads/route.js +3 -3
  115. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/threads/route.js.nft.json +1 -1
  116. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/variables/route.js +3 -3
  117. package/cloud-runtime/standalone/.next/server/app/api/projects/[id]/variables/route.js.nft.json +1 -1
  118. package/cloud-runtime/standalone/.next/server/app/api/projects/route.js +4 -3
  119. package/cloud-runtime/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  120. package/cloud-runtime/standalone/.next/server/app/api/providers/route.js +1 -1
  121. package/cloud-runtime/standalone/.next/server/app/api/providers/route.js.nft.json +1 -1
  122. package/cloud-runtime/standalone/.next/server/app/api/queue/complete/route.js +3 -3
  123. package/cloud-runtime/standalone/.next/server/app/api/queue/complete/route.js.nft.json +1 -1
  124. package/cloud-runtime/standalone/.next/server/app/api/queue/route.js +5 -4
  125. package/cloud-runtime/standalone/.next/server/app/api/queue/route.js.nft.json +1 -1
  126. package/cloud-runtime/standalone/.next/server/app/api/reactions/route.js.nft.json +1 -1
  127. package/cloud-runtime/standalone/.next/server/app/api/repos/[id]/knowledge/route.js +3 -3
  128. package/cloud-runtime/standalone/.next/server/app/api/repos/[id]/knowledge/route.js.nft.json +1 -1
  129. package/cloud-runtime/standalone/.next/server/app/api/schedules/debug/route.js +5 -4
  130. package/cloud-runtime/standalone/.next/server/app/api/schedules/debug/route.js.nft.json +1 -1
  131. package/cloud-runtime/standalone/.next/server/app/api/schedules/poll/route.js +4 -3
  132. package/cloud-runtime/standalone/.next/server/app/api/schedules/poll/route.js.nft.json +1 -1
  133. package/cloud-runtime/standalone/.next/server/app/api/schedules/route.js +4 -3
  134. package/cloud-runtime/standalone/.next/server/app/api/schedules/route.js.nft.json +1 -1
  135. package/cloud-runtime/standalone/.next/server/app/api/search/route.js.nft.json +1 -1
  136. package/cloud-runtime/standalone/.next/server/app/api/status/route.js +1 -1
  137. package/cloud-runtime/standalone/.next/server/app/api/status/route.js.nft.json +1 -1
  138. package/cloud-runtime/standalone/.next/server/app/api/summarize/route.js +3 -3
  139. package/cloud-runtime/standalone/.next/server/app/api/summarize/route.js.nft.json +1 -1
  140. package/cloud-runtime/standalone/.next/server/app/api/system/db-status/route.js.nft.json +1 -1
  141. package/cloud-runtime/standalone/.next/server/app/api/task-drafts/route.js.nft.json +1 -1
  142. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/comments/[commentId]/route.js +6 -5
  143. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/comments/[commentId]/route.js.nft.json +1 -1
  144. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/comments/route.js +6 -5
  145. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/comments/route.js.nft.json +1 -1
  146. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/costs/route.js +5 -4
  147. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/costs/route.js.nft.json +1 -1
  148. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/dependencies/route.js +4 -3
  149. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/dependencies/route.js.nft.json +1 -1
  150. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/events/route.js +4 -4
  151. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/events/route.js.nft.json +1 -1
  152. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/history/route.js +5 -5
  153. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/history/route.js.nft.json +1 -1
  154. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/metrics/route.js +5 -5
  155. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/metrics/route.js.nft.json +1 -1
  156. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/pause/route.js +2 -2
  157. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/pause/route.js.nft.json +1 -1
  158. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/replan/route.js +5 -5
  159. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/replan/route.js.nft.json +1 -1
  160. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/restart/route.js +4 -3
  161. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/restart/route.js.nft.json +1 -1
  162. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/resume/route.js +4 -3
  163. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/resume/route.js.nft.json +1 -1
  164. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/rollback/route.js +4 -4
  165. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/rollback/route.js.nft.json +1 -1
  166. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/route.js +5 -5
  167. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/route.js.nft.json +1 -1
  168. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/schedule/route.js +6 -5
  169. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/schedule/route.js.nft.json +1 -1
  170. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/start/route.js +4 -3
  171. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/start/route.js.nft.json +1 -1
  172. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/stop/route.js +2 -2
  173. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/graph/stop/route.js.nft.json +1 -1
  174. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/heartbeat/route.js +2 -2
  175. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/heartbeat/route.js.nft.json +1 -1
  176. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/history/route.js +5 -4
  177. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/history/route.js.nft.json +1 -1
  178. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/logs/route.js +4 -3
  179. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/logs/route.js.nft.json +1 -1
  180. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/logs/stream/route.js +2 -2
  181. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/logs/stream/route.js.nft.json +1 -1
  182. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/comments/route.js +3 -3
  183. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/comments/route.js.nft.json +1 -1
  184. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/complete/route.js +7 -6
  185. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/complete/route.js.nft.json +1 -1
  186. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/fail/route.js +7 -6
  187. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/fail/route.js.nft.json +1 -1
  188. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/resume/route.js +6 -5
  189. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/resume/route.js.nft.json +1 -1
  190. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/start/route.js +6 -5
  191. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/start/route.js.nft.json +1 -1
  192. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/stop/route.js +7 -6
  193. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/stop/route.js.nft.json +1 -1
  194. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/verify/route.js +8 -6
  195. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/nodes/[nodeId]/verify/route.js.nft.json +1 -1
  196. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/route.js +4 -3
  197. package/cloud-runtime/standalone/.next/server/app/api/tasks/[id]/route.js.nft.json +1 -1
  198. package/cloud-runtime/standalone/.next/server/app/api/tasks/assign-orphans/route.js +5 -4
  199. package/cloud-runtime/standalone/.next/server/app/api/tasks/assign-orphans/route.js.nft.json +1 -1
  200. package/cloud-runtime/standalone/.next/server/app/api/tasks/extract/route.js +3 -3
  201. package/cloud-runtime/standalone/.next/server/app/api/tasks/extract/route.js.nft.json +1 -1
  202. package/cloud-runtime/standalone/.next/server/app/api/tasks/route.js +5 -4
  203. package/cloud-runtime/standalone/.next/server/app/api/tasks/route.js.nft.json +1 -1
  204. package/cloud-runtime/standalone/.next/server/app/api/tasks/stream/route.js +2 -2
  205. package/cloud-runtime/standalone/.next/server/app/api/tasks/stream/route.js.nft.json +1 -1
  206. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route/app-paths-manifest.json +3 -0
  207. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route/build-manifest.json +11 -0
  208. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route/server-reference-manifest.json +4 -0
  209. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route.js +10 -0
  210. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route.js.map +5 -0
  211. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route.js.nft.json +1 -0
  212. package/cloud-runtime/standalone/.next/server/app/api/threads/knowledge/route_client-reference-manifest.js +2 -0
  213. package/cloud-runtime/standalone/.next/server/app/api/threads/route.js +5 -2
  214. package/cloud-runtime/standalone/.next/server/app/api/threads/route.js.nft.json +1 -1
  215. package/cloud-runtime/standalone/.next/server/app/api/user-settings/route.js +5 -4
  216. package/cloud-runtime/standalone/.next/server/app/api/user-settings/route.js.nft.json +1 -1
  217. package/cloud-runtime/standalone/.next/server/app/automations/page/build-manifest.json +2 -2
  218. package/cloud-runtime/standalone/.next/server/app/automations/page.js.nft.json +1 -1
  219. package/cloud-runtime/standalone/.next/server/app/automations/page_client-reference-manifest.js +1 -1
  220. package/cloud-runtime/standalone/.next/server/app/automations.html +2 -2
  221. package/cloud-runtime/standalone/.next/server/app/automations.rsc +4 -4
  222. package/cloud-runtime/standalone/.next/server/app/automations.segments/_full.segment.rsc +4 -4
  223. package/cloud-runtime/standalone/.next/server/app/automations.segments/_head.segment.rsc +1 -1
  224. package/cloud-runtime/standalone/.next/server/app/automations.segments/_index.segment.rsc +2 -2
  225. package/cloud-runtime/standalone/.next/server/app/automations.segments/_tree.segment.rsc +3 -3
  226. package/cloud-runtime/standalone/.next/server/app/automations.segments/automations/__PAGE__.segment.rsc +3 -3
  227. package/cloud-runtime/standalone/.next/server/app/automations.segments/automations.segment.rsc +1 -1
  228. package/cloud-runtime/standalone/.next/server/app/board/page/build-manifest.json +2 -2
  229. package/cloud-runtime/standalone/.next/server/app/board/page_client-reference-manifest.js +1 -1
  230. package/cloud-runtime/standalone/.next/server/app/board.html +2 -2
  231. package/cloud-runtime/standalone/.next/server/app/board.rsc +2 -2
  232. package/cloud-runtime/standalone/.next/server/app/board.segments/_full.segment.rsc +2 -2
  233. package/cloud-runtime/standalone/.next/server/app/board.segments/_head.segment.rsc +1 -1
  234. package/cloud-runtime/standalone/.next/server/app/board.segments/_index.segment.rsc +2 -2
  235. package/cloud-runtime/standalone/.next/server/app/board.segments/_tree.segment.rsc +2 -2
  236. package/cloud-runtime/standalone/.next/server/app/board.segments/board/__PAGE__.segment.rsc +1 -1
  237. package/cloud-runtime/standalone/.next/server/app/board.segments/board.segment.rsc +1 -1
  238. package/cloud-runtime/standalone/.next/server/app/execution-graph/page/build-manifest.json +2 -2
  239. package/cloud-runtime/standalone/.next/server/app/execution-graph/page.js.nft.json +1 -1
  240. package/cloud-runtime/standalone/.next/server/app/execution-graph/page_client-reference-manifest.js +1 -1
  241. package/cloud-runtime/standalone/.next/server/app/execution-graph.html +2 -2
  242. package/cloud-runtime/standalone/.next/server/app/execution-graph.rsc +3 -3
  243. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/_full.segment.rsc +3 -3
  244. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/_head.segment.rsc +1 -1
  245. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/_index.segment.rsc +2 -2
  246. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/_tree.segment.rsc +2 -2
  247. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/execution-graph/__PAGE__.segment.rsc +2 -2
  248. package/cloud-runtime/standalone/.next/server/app/execution-graph.segments/execution-graph.segment.rsc +1 -1
  249. package/cloud-runtime/standalone/.next/server/app/index.html +2 -2
  250. package/cloud-runtime/standalone/.next/server/app/index.rsc +4 -4
  251. package/cloud-runtime/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  252. package/cloud-runtime/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
  253. package/cloud-runtime/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  254. package/cloud-runtime/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  255. package/cloud-runtime/standalone/.next/server/app/index.segments/_tree.segment.rsc +3 -3
  256. package/cloud-runtime/standalone/.next/server/app/page/build-manifest.json +2 -2
  257. package/cloud-runtime/standalone/.next/server/app/page.js.nft.json +1 -1
  258. package/cloud-runtime/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  259. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/graph/[taskId]/page/build-manifest.json +2 -2
  260. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/graph/[taskId]/page.js.nft.json +1 -1
  261. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/graph/[taskId]/page_client-reference-manifest.js +1 -1
  262. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page/app-paths-manifest.json +3 -0
  263. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page/build-manifest.json +18 -0
  264. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page/next-font-manifest.json +11 -0
  265. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page/react-loadable-manifest.json +1 -0
  266. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page/server-reference-manifest.json +4 -0
  267. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page.js +16 -0
  268. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page.js.map +5 -0
  269. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page.js.nft.json +1 -0
  270. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/knowledge/page_client-reference-manifest.js +2 -0
  271. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/page/build-manifest.json +2 -2
  272. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/page.js.nft.json +1 -1
  273. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/page_client-reference-manifest.js +1 -1
  274. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page/app-paths-manifest.json +3 -0
  275. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page/build-manifest.json +18 -0
  276. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page/next-font-manifest.json +11 -0
  277. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page/react-loadable-manifest.json +1 -0
  278. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page/server-reference-manifest.json +4 -0
  279. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page.js +16 -0
  280. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page.js.map +5 -0
  281. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page.js.nft.json +1 -0
  282. package/cloud-runtime/standalone/.next/server/app/projects/[slug]/thread/[threadId]/page_client-reference-manifest.js +2 -0
  283. package/cloud-runtime/standalone/.next/server/app/projects/orphans/page/build-manifest.json +2 -2
  284. package/cloud-runtime/standalone/.next/server/app/projects/orphans/page.js.nft.json +1 -1
  285. package/cloud-runtime/standalone/.next/server/app/projects/orphans/page_client-reference-manifest.js +1 -1
  286. package/cloud-runtime/standalone/.next/server/app/projects/orphans.html +2 -2
  287. package/cloud-runtime/standalone/.next/server/app/projects/orphans.rsc +3 -3
  288. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/_full.segment.rsc +3 -3
  289. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/_head.segment.rsc +1 -1
  290. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/_index.segment.rsc +2 -2
  291. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/_tree.segment.rsc +2 -2
  292. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/projects/orphans/__PAGE__.segment.rsc +2 -2
  293. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/projects/orphans.segment.rsc +1 -1
  294. package/cloud-runtime/standalone/.next/server/app/projects/orphans.segments/projects.segment.rsc +1 -1
  295. package/cloud-runtime/standalone/.next/server/app/projects/page/build-manifest.json +2 -2
  296. package/cloud-runtime/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  297. package/cloud-runtime/standalone/.next/server/app/projects.html +2 -2
  298. package/cloud-runtime/standalone/.next/server/app/projects.rsc +3 -3
  299. package/cloud-runtime/standalone/.next/server/app/projects.segments/_full.segment.rsc +3 -3
  300. package/cloud-runtime/standalone/.next/server/app/projects.segments/_head.segment.rsc +1 -1
  301. package/cloud-runtime/standalone/.next/server/app/projects.segments/_index.segment.rsc +2 -2
  302. package/cloud-runtime/standalone/.next/server/app/projects.segments/_tree.segment.rsc +2 -2
  303. package/cloud-runtime/standalone/.next/server/app/projects.segments/projects/__PAGE__.segment.rsc +2 -2
  304. package/cloud-runtime/standalone/.next/server/app/projects.segments/projects.segment.rsc +1 -1
  305. package/cloud-runtime/standalone/.next/server/app/settings/page/build-manifest.json +2 -2
  306. package/cloud-runtime/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  307. package/cloud-runtime/standalone/.next/server/app/settings.html +2 -2
  308. package/cloud-runtime/standalone/.next/server/app/settings.rsc +2 -2
  309. package/cloud-runtime/standalone/.next/server/app/settings.segments/_full.segment.rsc +2 -2
  310. package/cloud-runtime/standalone/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  311. package/cloud-runtime/standalone/.next/server/app/settings.segments/_index.segment.rsc +2 -2
  312. package/cloud-runtime/standalone/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  313. package/cloud-runtime/standalone/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +1 -1
  314. package/cloud-runtime/standalone/.next/server/app/settings.segments/settings.segment.rsc +1 -1
  315. package/cloud-runtime/standalone/.next/server/app/status/page/build-manifest.json +2 -2
  316. package/cloud-runtime/standalone/.next/server/app/status/page.js.nft.json +1 -1
  317. package/cloud-runtime/standalone/.next/server/app/status/page_client-reference-manifest.js +1 -1
  318. package/cloud-runtime/standalone/.next/server/app/status.html +2 -2
  319. package/cloud-runtime/standalone/.next/server/app/status.rsc +3 -3
  320. package/cloud-runtime/standalone/.next/server/app/status.segments/_full.segment.rsc +3 -3
  321. package/cloud-runtime/standalone/.next/server/app/status.segments/_head.segment.rsc +1 -1
  322. package/cloud-runtime/standalone/.next/server/app/status.segments/_index.segment.rsc +2 -2
  323. package/cloud-runtime/standalone/.next/server/app/status.segments/_tree.segment.rsc +2 -2
  324. package/cloud-runtime/standalone/.next/server/app/status.segments/status/__PAGE__.segment.rsc +2 -2
  325. package/cloud-runtime/standalone/.next/server/app/status.segments/status.segment.rsc +1 -1
  326. package/cloud-runtime/standalone/.next/server/app/thread/[id]/page/build-manifest.json +2 -2
  327. package/cloud-runtime/standalone/.next/server/app/thread/[id]/page.js.nft.json +1 -1
  328. package/cloud-runtime/standalone/.next/server/app/thread/[id]/page_client-reference-manifest.js +1 -1
  329. package/cloud-runtime/standalone/.next/server/app/welcome/page/build-manifest.json +2 -2
  330. package/cloud-runtime/standalone/.next/server/app/welcome/page.js.nft.json +1 -1
  331. package/cloud-runtime/standalone/.next/server/app/welcome/page_client-reference-manifest.js +1 -1
  332. package/cloud-runtime/standalone/.next/server/app/welcome.html +2 -2
  333. package/cloud-runtime/standalone/.next/server/app/welcome.rsc +3 -3
  334. package/cloud-runtime/standalone/.next/server/app/welcome.segments/_full.segment.rsc +3 -3
  335. package/cloud-runtime/standalone/.next/server/app/welcome.segments/_head.segment.rsc +1 -1
  336. package/cloud-runtime/standalone/.next/server/app/welcome.segments/_index.segment.rsc +2 -2
  337. package/cloud-runtime/standalone/.next/server/app/welcome.segments/_tree.segment.rsc +2 -2
  338. package/cloud-runtime/standalone/.next/server/app/welcome.segments/welcome/__PAGE__.segment.rsc +2 -2
  339. package/cloud-runtime/standalone/.next/server/app/welcome.segments/welcome.segment.rsc +1 -1
  340. package/cloud-runtime/standalone/.next/server/app-paths-manifest.json +6 -0
  341. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__017f03c3._.js +13 -0
  342. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__0925dd01._.js +46 -0
  343. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__10940c29._.js +3 -0
  344. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__12afd8a3._.js +3 -0
  345. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__12c7e188._.js +29 -0
  346. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__16dd1fd7._.js +13 -0
  347. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__17c2d68f._.js +52 -0
  348. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__1dd062c1._.js +1 -1
  349. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__20b3baea._.js +55 -0
  350. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__2388b2b3._.js +3 -0
  351. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__241a8bcf._.js +1 -1
  352. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__254e942f._.js +20 -0
  353. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__29ce9c60._.js +3 -0
  354. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__2e596cc8._.js +4 -4
  355. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__3198c5c8._.js +2 -2
  356. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__36d9edbd._.js +14 -14
  357. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__399b2ca9._.js +3 -0
  358. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__4761dc17._.js +8 -0
  359. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__4b1a512c._.js +52 -0
  360. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__4c50f159._.js +4 -4
  361. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__4c8624cc._.js +3 -0
  362. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__4d318eb0._.js +146 -0
  363. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__507a4363._.js +4 -0
  364. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__50ddd3ce._.js +3 -0
  365. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__543ba6c4._.js +5 -1
  366. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__59b5d4e5._.js +1 -1
  367. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__5ca87ba0._.js +3 -0
  368. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__5d359afa._.js +46 -0
  369. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__666f8712._.js +3 -0
  370. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6c187704._.js +3 -0
  371. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6c26221d._.js +7 -0
  372. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6e59b27c._.js +3 -0
  373. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__74b97f0a._.js +1 -1
  374. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__75bff965._.js +46 -0
  375. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__7be8f159._.js +8 -8
  376. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__80655727._.js +3 -0
  377. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__86f7d27b._.js +3 -0
  378. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__94fa1edc._.js +46 -0
  379. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__98535eb3._.js +3 -0
  380. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__9dfaaf72._.js +52 -0
  381. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__a189593a._.js +3 -0
  382. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ac3c2f7f._.js +52 -0
  383. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__b40c7aab._.js +1 -1
  384. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__b4d05543._.js +1 -1
  385. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__bfcedb7c._.js +52 -0
  386. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c08bef05._.js +3 -0
  387. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c5634f17._.js +112 -0
  388. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c5b8ceb7._.js +3 -0
  389. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ccfcbcd5._.js +42 -0
  390. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ceb02db8._.js +3 -0
  391. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__da20a0aa._.js +1 -1
  392. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__dede3dcd._.js +75 -0
  393. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e122cae2._.js +3 -0
  394. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e1e7dd1e._.js +25 -0
  395. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e446cb39._.js +3 -0
  396. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e6ad07c3._.js +1 -1
  397. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__f4b70b67._.js +46 -0
  398. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__f5a2358a._.js +7 -0
  399. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__f5b93200._.js +3 -0
  400. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__fa0ebee3._.js +13 -0
  401. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__fcd3e3b8._.js +15 -0
  402. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__fce2cdce._.js +3 -0
  403. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ff9c61da._.js +3 -0
  404. package/cloud-runtime/standalone/.next/server/chunks/_05fa3b89._.js +46 -0
  405. package/cloud-runtime/standalone/.next/server/chunks/_0a767dfe._.js +3 -0
  406. package/cloud-runtime/standalone/.next/server/chunks/_2f3e5ac1._.js +6 -0
  407. package/cloud-runtime/standalone/.next/server/chunks/_3e0d34cc._.js +97 -0
  408. package/cloud-runtime/standalone/.next/server/chunks/_4190f170._.js +46 -0
  409. package/cloud-runtime/standalone/.next/server/chunks/{[root-of-the-server]__a104cda8._.js → _42e9c8d5._.js} +7 -7
  410. package/cloud-runtime/standalone/.next/server/chunks/_5ca51127._.js +54 -0
  411. package/cloud-runtime/standalone/.next/server/chunks/_66e1ddec._.js +57 -0
  412. package/cloud-runtime/standalone/.next/server/chunks/_6bb93816._.js +6 -0
  413. package/cloud-runtime/standalone/.next/server/chunks/_7011db4f._.js +3 -0
  414. package/cloud-runtime/standalone/.next/server/chunks/_8b9fde82._.js +97 -0
  415. package/cloud-runtime/standalone/.next/server/chunks/_95ac98db._.js +49 -0
  416. package/cloud-runtime/standalone/.next/server/chunks/_994414cd._.js +54 -0
  417. package/cloud-runtime/standalone/.next/server/chunks/_99b78daf._.js +46 -0
  418. package/cloud-runtime/standalone/.next/server/chunks/_a877d34f._.js +6 -0
  419. package/cloud-runtime/standalone/.next/server/chunks/_affbdbb0._.js +46 -0
  420. package/cloud-runtime/standalone/.next/server/chunks/_c31ca6ab._.js +3 -0
  421. package/cloud-runtime/standalone/.next/server/chunks/_d225c04f._.js +1 -1
  422. package/cloud-runtime/standalone/.next/server/chunks/_ee99a36b._.js +6 -0
  423. package/cloud-runtime/standalone/.next/server/chunks/_efc73784._.js +46 -0
  424. package/cloud-runtime/standalone/.next/server/chunks/_fba13a4a._.js +6 -0
  425. package/cloud-runtime/standalone/.next/server/chunks/_next-internal_server_app_api_chat-runs_[id]_route_actions_033ac330.js +3 -0
  426. package/cloud-runtime/standalone/.next/server/chunks/_next-internal_server_app_api_chat-runs_[id]_signal_route_actions_4b56f1cd.js +3 -0
  427. package/cloud-runtime/standalone/.next/server/chunks/_next-internal_server_app_api_chat-runs_route_actions_0c8cd01c.js +3 -0
  428. package/cloud-runtime/standalone/.next/server/chunks/_next-internal_server_app_api_threads_knowledge_route_actions_c139bcf7.js +3 -0
  429. package/cloud-runtime/standalone/.next/server/chunks/lib_09aac4e7._.js +57 -0
  430. package/cloud-runtime/standalone/.next/server/chunks/lib_cli-runner_ts_dfcf3fda._.js +18 -0
  431. package/cloud-runtime/standalone/.next/server/chunks/lib_db_ts_e06c6085._.js +1 -1
  432. package/cloud-runtime/standalone/.next/server/chunks/lib_ea45fe73._.js +68 -23
  433. package/cloud-runtime/standalone/.next/server/chunks/lib_history-store_ts_2e721df2._.js +74 -30
  434. package/cloud-runtime/standalone/.next/server/chunks/lib_history-store_ts_74d1c060._.js +70 -31
  435. package/cloud-runtime/standalone/.next/server/chunks/lib_sqlite-query-adapter_ts_3ea4d849._.js +87 -17
  436. package/cloud-runtime/standalone/.next/server/chunks/lib_sqlite-query-adapter_ts_b0b1a9b2._.js +294 -0
  437. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_0f808fa3.js +3 -0
  438. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_2bdede98.js +3 -0
  439. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_371d0bff.js +50 -43
  440. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_3d31fed0.js +3 -0
  441. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_57a073eb.js +3 -0
  442. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_69b6b2e1.js +3 -0
  443. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_7f8022ab.js +3 -0
  444. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_84e28f38.js +3 -0
  445. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_8ec90680.js +3 -0
  446. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_a590fcd6.js +3 -0
  447. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_cc6c687d.js +3 -0
  448. package/cloud-runtime/standalone/.next/server/chunks/src_graph_14067235._.js +46 -0
  449. package/cloud-runtime/standalone/.next/server/chunks/src_graph_api-route-utils_ts_b7225a0e._.js +1 -1
  450. package/cloud-runtime/standalone/.next/server/chunks/src_graph_b63e2d39._.js +46 -0
  451. package/cloud-runtime/standalone/.next/server/chunks/src_graph_executor_ts_55c06268._.js +3 -3
  452. package/cloud-runtime/standalone/.next/server/chunks/src_graph_executor_ts_a8bc8d58._.js +1 -1
  453. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__1322ced8._.js +3 -0
  454. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__47caef59._.js +1 -1
  455. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__6e83bf83._.js +3 -0
  456. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__783669c3._.js +3 -0
  457. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__8973b16a._.js +3 -0
  458. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__9166c1d6._.js +3 -0
  459. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__a0a1cb74._.js +3 -0
  460. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__a8a8afdc._.js +3 -0
  461. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__fca7df40._.js +3 -0
  462. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__ffbc2e98._.js +2 -2
  463. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_27f9c020._.js → _0061ebd8._.js} +2 -2
  464. package/cloud-runtime/standalone/.next/server/chunks/ssr/_064370bc._.js +3 -0
  465. package/cloud-runtime/standalone/.next/server/chunks/ssr/_0f4e70b1._.js +3 -0
  466. package/cloud-runtime/standalone/.next/server/chunks/ssr/_0ff7c687._.js +2 -4
  467. package/cloud-runtime/standalone/.next/server/chunks/ssr/_16c45024._.js +3 -0
  468. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_27cb3359._.js → _5b2b8a85._.js} +2 -2
  469. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_a696e9b3._.js → _68ac991e._.js} +2 -2
  470. package/cloud-runtime/standalone/.next/server/chunks/ssr/_6de3f1de._.js +3 -0
  471. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_c838f593._.js → _6fc3736e._.js} +2 -2
  472. package/cloud-runtime/standalone/.next/server/chunks/ssr/_85ca101b._.js +8 -0
  473. package/cloud-runtime/standalone/.next/server/chunks/ssr/_a0cc0fe7._.js +3 -0
  474. package/cloud-runtime/standalone/.next/server/chunks/ssr/_a10eb951._.js +4 -0
  475. package/cloud-runtime/standalone/.next/server/chunks/ssr/_cb4d8a23._.js +4 -0
  476. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_6a367524._.js → _ccb409c5._.js} +2 -2
  477. package/cloud-runtime/standalone/.next/server/chunks/ssr/_cd5e154b._.js +1 -1
  478. package/cloud-runtime/standalone/.next/server/chunks/ssr/_e1769638._.js +2 -4
  479. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_d021529a._.js → _fb292eed._.js} +2 -2
  480. package/cloud-runtime/standalone/.next/server/chunks/ssr/{_4b5d7c9b._.js → _ff5799d6._.js} +2 -2
  481. package/cloud-runtime/standalone/.next/server/chunks/ssr/_next-internal_server_app_projects_[slug]_knowledge_page_actions_1037c40a.js +3 -0
  482. package/cloud-runtime/standalone/.next/server/chunks/ssr/app_execution-graph_page_tsx_f854185a._.js +2 -2
  483. package/cloud-runtime/standalone/.next/server/chunks/ssr/app_projects_[slug]_graph_[taskId]_page_tsx_d8b1d582._.js +1 -1
  484. package/cloud-runtime/standalone/.next/server/chunks/ssr/app_projects_[slug]_knowledge_page_tsx_e2a55cbd._.js +3 -0
  485. package/cloud-runtime/standalone/.next/server/chunks/ssr/app_welcome_page_tsx_6c79bc59._.js +3 -0
  486. package/cloud-runtime/standalone/.next/server/chunks/ssr/ce889_server_app_projects_[slug]_thread_[threadId]_page_actions_660a8857.js +3 -0
  487. package/cloud-runtime/standalone/.next/server/chunks/ssr/components_chat-ui_bfeda794._.js +5 -5
  488. package/cloud-runtime/standalone/.next/server/chunks/ssr/components_thread_WorkspaceSidebar_tsx_e660301b._.js +1 -1
  489. package/cloud-runtime/standalone/.next/server/chunks/ssr/node_modules_lucide-react_dist_esm_e70f9321._.js +3 -0
  490. package/cloud-runtime/standalone/.next/server/chunks/ssr/node_modules_lucide-react_dist_esm_icons_678fa868._.js +3 -0
  491. package/cloud-runtime/standalone/.next/server/functions-config-manifest.json +4 -0
  492. package/cloud-runtime/standalone/.next/server/middleware-build-manifest.js +2 -2
  493. package/cloud-runtime/standalone/.next/server/middleware-manifest.json +5 -5
  494. package/cloud-runtime/standalone/.next/server/next-font-manifest.js +1 -1
  495. package/cloud-runtime/standalone/.next/server/next-font-manifest.json +8 -0
  496. package/cloud-runtime/standalone/.next/server/pages/404.html +2 -2
  497. package/cloud-runtime/standalone/.next/server/pages/500.html +2 -2
  498. package/cloud-runtime/standalone/.next/server/server-reference-manifest.js +1 -1
  499. package/cloud-runtime/standalone/.next/server/server-reference-manifest.json +1 -1
  500. package/cloud-runtime/standalone/.next/static/chunks/010aff7b601302de.js +16 -0
  501. package/cloud-runtime/standalone/.next/static/chunks/0c467f54bc78a380.js +1 -0
  502. package/cloud-runtime/standalone/.next/static/chunks/10b0642440302e99.css +2 -0
  503. package/cloud-runtime/standalone/.next/static/chunks/1f415d0ce7ebbd08.js +8 -0
  504. package/cloud-runtime/standalone/.next/static/chunks/24a6ee21f430da93.js +1 -0
  505. package/cloud-runtime/standalone/.next/static/chunks/27129bea5b512ce8.js +1 -0
  506. package/cloud-runtime/standalone/.next/static/chunks/{e44264686aa5ecbf.js → 4200b512bdc226bc.js} +1 -1
  507. package/cloud-runtime/standalone/.next/static/chunks/463edf3533d27a56.js +1 -0
  508. package/cloud-runtime/standalone/.next/static/chunks/486bf7ff282b91a6.js +5 -0
  509. package/cloud-runtime/standalone/.next/static/chunks/{616d66dbec9e4b8b.js → 58025a80caa3629d.js} +1 -1
  510. package/cloud-runtime/standalone/.next/static/chunks/5cb0c885b085ea6c.js +1 -0
  511. package/cloud-runtime/standalone/.next/static/chunks/60c054bb8b2cffa6.css +1 -0
  512. package/cloud-runtime/standalone/.next/static/chunks/{da434b1ad885d636.js → 651c7c97d3bd77e0.js} +2 -4
  513. package/cloud-runtime/standalone/.next/static/chunks/{45b4d0ee5c92d45b.js → 6fbe08eab578c7d3.js} +1 -1
  514. package/cloud-runtime/standalone/.next/static/chunks/7e2edf97bd6c0874.js +1 -0
  515. package/cloud-runtime/standalone/.next/static/chunks/8249f202d33d0d95.js +1 -0
  516. package/cloud-runtime/standalone/.next/static/chunks/{b4e298542d366e31.js → 87f099ea02aa419d.js} +1 -1
  517. package/cloud-runtime/standalone/.next/static/chunks/8d15ced2dc70090a.js +1 -0
  518. package/cloud-runtime/standalone/.next/static/chunks/{2acd153dc5252e88.js → 99174504a201d23e.js} +2 -4
  519. package/cloud-runtime/standalone/.next/static/chunks/9f8f719c4aa25e3d.js +1 -0
  520. package/cloud-runtime/standalone/.next/static/chunks/a66e1891e808a664.js +1 -0
  521. package/cloud-runtime/standalone/.next/static/chunks/{3344004561eabdf8.js → bc3cad3c821b169b.js} +1 -1
  522. package/cloud-runtime/standalone/.next/static/chunks/bc727d3d9993e9be.js +1 -0
  523. package/cloud-runtime/standalone/.next/static/chunks/cd308f61797939cd.js +6 -0
  524. package/cloud-runtime/standalone/.next/static/chunks/d5d6be8239e57c56.js +1 -0
  525. package/cloud-runtime/standalone/.next/static/chunks/{ee5f1457fbc593e1.js → dfff51033c303fc7.js} +1 -1
  526. package/cloud-runtime/standalone/.next/static/chunks/e62d5fa120fdf21f.js +1 -0
  527. package/cloud-runtime/standalone/.next/static/chunks/{turbopack-5b5918f610666d2d.js → turbopack-97e846241a3a64af.js} +1 -1
  528. package/cloud-runtime/standalone/README.md +3 -3
  529. package/cloud-runtime/standalone/app/api/chat/route.ts +38 -28
  530. package/cloud-runtime/standalone/app/api/chat-runs/[id]/route.ts +19 -0
  531. package/cloud-runtime/standalone/app/api/chat-runs/[id]/signal/route.ts +32 -0
  532. package/cloud-runtime/standalone/app/api/chat-runs/route.ts +37 -0
  533. package/cloud-runtime/standalone/app/api/history/route.ts +6 -0
  534. package/cloud-runtime/standalone/app/api/projects/[id]/memory/route.ts +17 -0
  535. package/cloud-runtime/standalone/app/api/providers/route.ts +9 -13
  536. package/cloud-runtime/standalone/app/api/schedules/debug/route.ts +23 -3
  537. package/cloud-runtime/standalone/app/api/schedules/poll/route.ts +5 -3
  538. package/cloud-runtime/standalone/app/api/schedules/route.ts +12 -17
  539. package/cloud-runtime/standalone/app/api/status/route.ts +6 -5
  540. package/cloud-runtime/standalone/app/api/threads/knowledge/route.ts +91 -0
  541. package/cloud-runtime/standalone/app/api/threads/route.ts +18 -1
  542. package/cloud-runtime/standalone/app/globals.css +22 -22
  543. package/cloud-runtime/standalone/app/projects/[slug]/graph/[taskId]/page.tsx +0 -21
  544. package/cloud-runtime/standalone/app/projects/[slug]/knowledge/page.tsx +608 -0
  545. package/cloud-runtime/standalone/app/projects/[slug]/layout.tsx +18 -2
  546. package/cloud-runtime/standalone/app/projects/[slug]/page.tsx +1 -455
  547. package/cloud-runtime/standalone/app/projects/[slug]/thread/[threadId]/page.tsx +14 -0
  548. package/cloud-runtime/standalone/app/welcome/page.tsx +329 -107
  549. package/cloud-runtime/standalone/components/ActionToolbar.tsx +25 -0
  550. package/cloud-runtime/standalone/components/ConfirmDialog.tsx +133 -0
  551. package/cloud-runtime/standalone/components/IconButton.tsx +35 -0
  552. package/cloud-runtime/standalone/components/ProjectCard.tsx +2 -2
  553. package/cloud-runtime/standalone/components/ProjectModal.tsx +2 -2
  554. package/cloud-runtime/standalone/components/TaskCard.tsx +2 -4
  555. package/cloud-runtime/standalone/components/chat-ui/ChatContainer.tsx +415 -76
  556. package/cloud-runtime/standalone/components/chat-ui/Composer.tsx +152 -101
  557. package/cloud-runtime/standalone/components/chat-ui/FileMentionPopoverItem.tsx +2 -2
  558. package/cloud-runtime/standalone/components/chat-ui/MessageList.tsx +46 -43
  559. package/cloud-runtime/standalone/components/chat-ui/ThreadView.tsx +73 -34
  560. package/cloud-runtime/standalone/components/thread/WorkspaceSidebar.tsx +51 -23
  561. package/cloud-runtime/standalone/hooks/useComposerHistory.ts +130 -0
  562. package/cloud-runtime/standalone/hooks/useGroupChat.ts +24 -1
  563. package/cloud-runtime/standalone/hooks/useProcessPolling.ts +69 -6
  564. package/cloud-runtime/standalone/lib/history-store.ts +532 -38
  565. package/cloud-runtime/standalone/lib/knowledge-notes.ts +251 -0
  566. package/cloud-runtime/standalone/lib/knowledge-store.ts +233 -0
  567. package/cloud-runtime/standalone/lib/memory-extractor.ts +76 -60
  568. package/cloud-runtime/standalone/lib/mesh-core/journal.ts +30 -0
  569. package/cloud-runtime/standalone/lib/mesh-core/self.ts +94 -0
  570. package/cloud-runtime/standalone/lib/orchestrator/chat-activities.ts +60 -0
  571. package/cloud-runtime/standalone/lib/orchestrator/chat-processor.ts +168 -0
  572. package/cloud-runtime/standalone/lib/orchestrator/chat-types.ts +29 -0
  573. package/cloud-runtime/standalone/lib/orchestrator/runtime.ts +20 -0
  574. package/cloud-runtime/standalone/lib/provider-clis.ts +63 -0
  575. package/cloud-runtime/standalone/lib/queue/boss.ts +2 -1
  576. package/cloud-runtime/standalone/lib/repo-knowledge.ts +19 -2
  577. package/cloud-runtime/standalone/lib/sqlite-query-adapter.ts +78 -0
  578. package/cloud-runtime/standalone/lib/stream-multiplexer.ts +101 -14
  579. package/cloud-runtime/standalone/lib/task-context.ts +7 -4
  580. package/cloud-runtime/standalone/lib/thread-knowledge-runs.ts +227 -0
  581. package/cloud-runtime/standalone/lib/thread-knowledge.ts +419 -0
  582. package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64 → sharp-libvips-linux-x64}/README.md +2 -2
  583. package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64 → sharp-libvips-linux-x64}/lib/glib-2.0/include/glibconfig.h +9 -8
  584. package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.3.dylib → sharp-libvips-linux-x64/lib/libvips-cpp.so.8.17.3} +0 -0
  585. package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64 → sharp-libvips-linux-x64}/package.json +11 -5
  586. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/README.md +46 -0
  587. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/glib-2.0/include/glibconfig.h +221 -0
  588. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/index.js +1 -0
  589. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/libvips-cpp.so.8.17.3 +0 -0
  590. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/package.json +42 -0
  591. package/cloud-runtime/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/versions.json +30 -0
  592. package/cloud-runtime/standalone/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node +0 -0
  593. package/cloud-runtime/standalone/node_modules/@img/{sharp-darwin-arm64 → sharp-linux-x64}/package.json +13 -7
  594. package/cloud-runtime/standalone/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-x64.node +0 -0
  595. package/cloud-runtime/standalone/node_modules/@img/sharp-linuxmusl-x64/package.json +46 -0
  596. package/cloud-runtime/standalone/node_modules/better-sqlite3/build/Release/better_sqlite3.node +0 -0
  597. package/cloud-runtime/standalone/node_modules/better-sqlite3-90e2652d1716b047/build/Release/better_sqlite3.node +0 -0
  598. package/cloud-runtime/standalone/package-lock.json +13 -0
  599. package/cloud-runtime/standalone/package.json +1 -0
  600. package/cloud-runtime/standalone/server.js +1 -1
  601. package/cloud-runtime/standalone/src/graph/api-schemas.ts +2 -2
  602. package/cloud-runtime/standalone/src/graph/executor.ts +9 -7
  603. package/cloud-runtime/standalone/src/graph/function-executor.ts +4 -1
  604. package/cloud-runtime/standalone/src/graph/internal-function-dispatcher.ts +174 -0
  605. package/cloud-runtime/standalone/src/graph/types.ts +3 -3
  606. package/cloud-runtime/standalone/src/graph/work-dispatcher.ts +5 -1
  607. package/cloud-runtime/standalone/styles/workspaceSidebar.css +2 -0
  608. package/cloud-runtime/standalone/tsconfig.json +3 -1
  609. package/cloud-runtime/standalone/worker/index.js +2930 -137
  610. package/cloud-runtime/standalone/worker/index.ts +8 -1
  611. package/package.json +1 -1
  612. package/cloud-runtime/standalone/.next/server/chunks/[externals]_child_process_964038fc._.js +0 -3
  613. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__03a1bf91._.js +0 -6
  614. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__065c5114._.js +0 -3
  615. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__07dce481._.js +0 -3
  616. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__09f46c85._.js +0 -46
  617. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__149bcf6d._.js +0 -115
  618. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__14bad16e._.js +0 -3
  619. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__14e3bf74._.js +0 -3
  620. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__1632828c._.js +0 -46
  621. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__24b8ccd3._.js +0 -52
  622. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__284e1cbe._.js +0 -3
  623. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__28d6e806._.js +0 -3
  624. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__2bcb75a7._.js +0 -3
  625. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__32e5f341._.js +0 -4
  626. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__3b4a126a._.js +0 -46
  627. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__3c7464e8._.js +0 -46
  628. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__3d82dc78._.js +0 -46
  629. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__406bdd54._.js +0 -46
  630. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__40d6458a._.js +0 -3
  631. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__47ca4946._.js +0 -3
  632. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__49fb4a12._.js +0 -3
  633. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__5327e395._.js +0 -46
  634. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__55d75c3a._.js +0 -7
  635. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__592e81f9._.js +0 -13
  636. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__5a6a194c._.js +0 -52
  637. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__5af16b4f._.js +0 -3
  638. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__60ba5058._.js +0 -3
  639. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6716441c._.js +0 -3
  640. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__673aedc6._.js +0 -3
  641. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6a44c891._.js +0 -3
  642. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__6b680112._.js +0 -55
  643. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__7312fad4._.js +0 -46
  644. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__7456196c._.js +0 -52
  645. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__74d26856._.js +0 -3
  646. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__772c6fae._.js +0 -3
  647. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__787ba54b._.js +0 -3
  648. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__79157eef._.js +0 -3
  649. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__82d76712._.js +0 -3
  650. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__8311f060._.js +0 -6
  651. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__84e90655._.js +0 -46
  652. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__90a887dc._.js +0 -3
  653. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__9345d703._.js +0 -3
  654. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__98294450._.js +0 -3
  655. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__985f0d9f._.js +0 -51
  656. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__9b32295e._.js +0 -3
  657. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__a64d978e._.js +0 -6
  658. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__babcd1af._.js +0 -13
  659. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c16f03fb._.js +0 -13
  660. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c2767ca5._.js +0 -3
  661. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__c72c6d4a._.js +0 -25
  662. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ca851b15._.js +0 -3
  663. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__d25227df._.js +0 -29
  664. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e06820c3._.js +0 -6
  665. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e429a0bc._.js +0 -3
  666. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__e4397d43._.js +0 -7
  667. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ec8735f4._.js +0 -3
  668. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ef09ab99._.js +0 -13
  669. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__f366a937._.js +0 -46
  670. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__fdaa8a27._.js +0 -3
  671. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__fddde532._.js +0 -3
  672. package/cloud-runtime/standalone/.next/server/chunks/[root-of-the-server]__ff53f445._.js +0 -3
  673. package/cloud-runtime/standalone/.next/server/chunks/_1111d342._.js +0 -101
  674. package/cloud-runtime/standalone/.next/server/chunks/_4b60ba15._.js +0 -49
  675. package/cloud-runtime/standalone/.next/server/chunks/_54252651._.js +0 -49
  676. package/cloud-runtime/standalone/.next/server/chunks/_818a89c4._.js +0 -46
  677. package/cloud-runtime/standalone/.next/server/chunks/_a4a21d4f._.js +0 -3
  678. package/cloud-runtime/standalone/.next/server/chunks/_a759d52b._.js +0 -3
  679. package/cloud-runtime/standalone/.next/server/chunks/_e6b28eae._.js +0 -46
  680. package/cloud-runtime/standalone/.next/server/chunks/_e868e7c1._.js +0 -46
  681. package/cloud-runtime/standalone/.next/server/chunks/lib_23509137._.js +0 -196
  682. package/cloud-runtime/standalone/.next/server/chunks/lib_3273d5f9._.js +0 -196
  683. package/cloud-runtime/standalone/.next/server/chunks/lib_50ba0b4c._.js +0 -63
  684. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_33963d95.js +0 -3
  685. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_56c5acb3.js +0 -3
  686. package/cloud-runtime/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_888b3578.js +0 -3
  687. package/cloud-runtime/standalone/.next/server/chunks/src_graph_e3bb4da8._.js +0 -46
  688. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__113d6767._.js +0 -3
  689. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__6a9d3855._.js +0 -3
  690. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__942ca438._.js +0 -3
  691. package/cloud-runtime/standalone/.next/server/chunks/ssr/[root-of-the-server]__ce3b51aa._.js +0 -3
  692. package/cloud-runtime/standalone/.next/server/chunks/ssr/_1ec61dee._.js +0 -3
  693. package/cloud-runtime/standalone/.next/server/chunks/ssr/_27904584._.js +0 -3
  694. package/cloud-runtime/standalone/.next/server/chunks/ssr/_43472af3._.js +0 -3
  695. package/cloud-runtime/standalone/.next/server/chunks/ssr/_94effa0f._.js +0 -3
  696. package/cloud-runtime/standalone/.next/server/chunks/ssr/_d458d1eb._.js +0 -3
  697. package/cloud-runtime/standalone/.next/server/chunks/ssr/_fbced30b._.js +0 -3
  698. package/cloud-runtime/standalone/.next/server/chunks/ssr/app_projects_[slug]_page_tsx_e0fabf6e._.js +0 -8
  699. package/cloud-runtime/standalone/.next/server/chunks/ssr/node_modules_lucide-react_dist_esm_a8f86889._.js +0 -3
  700. package/cloud-runtime/standalone/.next/server/chunks/ssr/node_modules_lucide-react_dist_esm_icons_play_6595a532.js +0 -3
  701. package/cloud-runtime/standalone/.next/static/chunks/1184bf1bfdf97666.js +0 -1
  702. package/cloud-runtime/standalone/.next/static/chunks/5ace4b4f4475962a.js +0 -1
  703. package/cloud-runtime/standalone/.next/static/chunks/64f812259cf8c243.js +0 -18
  704. package/cloud-runtime/standalone/.next/static/chunks/6509f7fecbf44493.js +0 -1
  705. package/cloud-runtime/standalone/.next/static/chunks/6dbf5940e30fa9c7.js +0 -1
  706. package/cloud-runtime/standalone/.next/static/chunks/7e91f395ace1dd2c.js +0 -1
  707. package/cloud-runtime/standalone/.next/static/chunks/7f13efe9329d3f97.js +0 -1
  708. package/cloud-runtime/standalone/.next/static/chunks/80219bbddcf65109.js +0 -1
  709. package/cloud-runtime/standalone/.next/static/chunks/86ace6febb11ad71.js +0 -1
  710. package/cloud-runtime/standalone/.next/static/chunks/9d50c2514f72d926.css +0 -1
  711. package/cloud-runtime/standalone/.next/static/chunks/b079c677d9b39f98.js +0 -5
  712. package/cloud-runtime/standalone/.next/static/chunks/b88352740262931f.js +0 -6
  713. package/cloud-runtime/standalone/.next/static/chunks/bd6c5b5b4fbd6413.css +0 -2
  714. package/cloud-runtime/standalone/.next/static/chunks/c5609fd2abb65850.js +0 -1
  715. package/cloud-runtime/standalone/.next/static/chunks/d95cd010361834be.js +0 -1
  716. package/cloud-runtime/standalone/.next/static/chunks/eab1c7d0246592f8.js +0 -8
  717. package/cloud-runtime/standalone/.next/static/chunks/f7bbf5cfcfed8ba9.js +0 -1
  718. package/cloud-runtime/standalone/coverage/clover.xml +0 -1208
  719. package/cloud-runtime/standalone/coverage/coverage-final.json +0 -29
  720. package/cloud-runtime/standalone/coverage/lcov-report/app/api/audit/index.html +0 -116
  721. package/cloud-runtime/standalone/coverage/lcov-report/app/api/audit/route.ts.html +0 -208
  722. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/[...nextauth]/index.html +0 -116
  723. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/[...nextauth]/route.ts.html +0 -166
  724. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/daemon-secret/index.html +0 -116
  725. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/daemon-secret/route.ts.html +0 -532
  726. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/status/index.html +0 -116
  727. package/cloud-runtime/standalone/coverage/lcov-report/app/api/auth/status/route.ts.html +0 -178
  728. package/cloud-runtime/standalone/coverage/lcov-report/app/api/learnings/index.html +0 -116
  729. package/cloud-runtime/standalone/coverage/lcov-report/app/api/learnings/route.ts.html +0 -262
  730. package/cloud-runtime/standalone/coverage/lcov-report/app/api/logs/stream/index.html +0 -116
  731. package/cloud-runtime/standalone/coverage/lcov-report/app/api/logs/stream/route.ts.html +0 -448
  732. package/cloud-runtime/standalone/coverage/lcov-report/app/api/queue/complete/index.html +0 -116
  733. package/cloud-runtime/standalone/coverage/lcov-report/app/api/queue/complete/route.ts.html +0 -331
  734. package/cloud-runtime/standalone/coverage/lcov-report/app/api/queue/index.html +0 -116
  735. package/cloud-runtime/standalone/coverage/lcov-report/app/api/queue/route.ts.html +0 -505
  736. package/cloud-runtime/standalone/coverage/lcov-report/app/api/stage-prompts/index.html +0 -116
  737. package/cloud-runtime/standalone/coverage/lcov-report/app/api/stage-prompts/route.ts.html +0 -412
  738. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/advance/index.html +0 -116
  739. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/advance/route.ts.html +0 -304
  740. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/index.html +0 -116
  741. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/logs/index.html +0 -116
  742. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/logs/route.ts.html +0 -202
  743. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/[id]/route.ts.html +0 -373
  744. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/index.html +0 -116
  745. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/route.ts.html +0 -499
  746. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/stream/index.html +0 -116
  747. package/cloud-runtime/standalone/coverage/lcov-report/app/api/tasks/stream/route.ts.html +0 -349
  748. package/cloud-runtime/standalone/coverage/lcov-report/base.css +0 -224
  749. package/cloud-runtime/standalone/coverage/lcov-report/block-navigation.js +0 -87
  750. package/cloud-runtime/standalone/coverage/lcov-report/components/AuthProvider.tsx.html +0 -259
  751. package/cloud-runtime/standalone/coverage/lcov-report/components/ChatInterface.tsx.html +0 -1228
  752. package/cloud-runtime/standalone/coverage/lcov-report/components/KanbanBoard.tsx.html +0 -1024
  753. package/cloud-runtime/standalone/coverage/lcov-report/components/Layout.tsx.html +0 -211
  754. package/cloud-runtime/standalone/coverage/lcov-report/components/LearningsPanel.tsx.html +0 -535
  755. package/cloud-runtime/standalone/coverage/lcov-report/components/LogTimeline.tsx.html +0 -415
  756. package/cloud-runtime/standalone/coverage/lcov-report/components/SortableTaskCard.tsx.html +0 -358
  757. package/cloud-runtime/standalone/coverage/lcov-report/components/StagePills.tsx.html +0 -439
  758. package/cloud-runtime/standalone/coverage/lcov-report/components/TaskCard.tsx.html +0 -514
  759. package/cloud-runtime/standalone/coverage/lcov-report/components/TaskCardOverlay.tsx.html +0 -256
  760. package/cloud-runtime/standalone/coverage/lcov-report/components/TaskDetail.tsx.html +0 -622
  761. package/cloud-runtime/standalone/coverage/lcov-report/components/TaskList.tsx.html +0 -253
  762. package/cloud-runtime/standalone/coverage/lcov-report/components/index.html +0 -281
  763. package/cloud-runtime/standalone/coverage/lcov-report/favicon.png +0 -0
  764. package/cloud-runtime/standalone/coverage/lcov-report/hooks/index.html +0 -116
  765. package/cloud-runtime/standalone/coverage/lcov-report/hooks/useTasks.ts.html +0 -1042
  766. package/cloud-runtime/standalone/coverage/lcov-report/index.html +0 -341
  767. package/cloud-runtime/standalone/coverage/lcov-report/lib/auth-client.ts.html +0 -202
  768. package/cloud-runtime/standalone/coverage/lcov-report/lib/auth-server.ts.html +0 -172
  769. package/cloud-runtime/standalone/coverage/lcov-report/lib/auth.ts.html +0 -265
  770. package/cloud-runtime/standalone/coverage/lcov-report/lib/db.ts.html +0 -1252
  771. package/cloud-runtime/standalone/coverage/lcov-report/lib/index.html +0 -131
  772. package/cloud-runtime/standalone/coverage/lcov-report/lib/orchestrator.ts.html +0 -409
  773. package/cloud-runtime/standalone/coverage/lcov-report/lib/security.ts.html +0 -1165
  774. package/cloud-runtime/standalone/coverage/lcov-report/lib/supabase-server.ts.html +0 -175
  775. package/cloud-runtime/standalone/coverage/lcov-report/lib/supabase.ts.html +0 -157
  776. package/cloud-runtime/standalone/coverage/lcov-report/prettify.css +0 -1
  777. package/cloud-runtime/standalone/coverage/lcov-report/prettify.js +0 -2
  778. package/cloud-runtime/standalone/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  779. package/cloud-runtime/standalone/coverage/lcov-report/sorter.js +0 -210
  780. package/cloud-runtime/standalone/coverage/lcov.info +0 -2386
  781. package/cloud-runtime/standalone/docs/LIMITS.md +0 -63
  782. package/cloud-runtime/standalone/docs/architecture/ADR-001-hybrid-to-full-sqlite.md +0 -345
  783. package/cloud-runtime/standalone/docs/baseline/baseline-report.json +0 -1009
  784. package/cloud-runtime/standalone/docs/baseline/critical-queries.md +0 -105
  785. package/cloud-runtime/standalone/docs/baseline/lock-metrics.json +0 -21
  786. package/cloud-runtime/standalone/docs/baseline/read-latency.json +0 -146
  787. package/cloud-runtime/standalone/docs/baseline/restore-time.json +0 -10
  788. package/cloud-runtime/standalone/docs/baseline/write-metrics.json +0 -803
  789. package/cloud-runtime/standalone/docs/decisions/sqlite-migration-adr.md +0 -327
  790. package/cloud-runtime/standalone/docs/error-code-mapping.md +0 -74
  791. package/cloud-runtime/standalone/docs/migration-plan.md +0 -120
  792. package/cloud-runtime/standalone/docs/migration-spec.md +0 -345
  793. package/cloud-runtime/standalone/docs/pg-sqlite-compatibility-matrix.md +0 -554
  794. package/cloud-runtime/standalone/docs/project-agent-migration-status.md +0 -229
  795. package/cloud-runtime/standalone/docs/runbook-shadow-read.md +0 -66
  796. package/cloud-runtime/standalone/docs/runbook.md +0 -155
  797. package/cloud-runtime/standalone/docs/specs/cli-postgres-removal.md +0 -69
  798. package/cloud-runtime/standalone/docs/specs/thread-mentions.md +0 -53
  799. package/cloud-runtime/standalone/docs/ux/GlobalChatFlow.storyboard +0 -23
  800. package/cloud-runtime/standalone/docs/ux/assistant-chat-cli.md +0 -32
  801. package/cloud-runtime/standalone/mcp/dist/constants.js +0 -66
  802. package/cloud-runtime/standalone/mcp/dist/db.js +0 -220
  803. package/cloud-runtime/standalone/mcp/dist/index.js +0 -7
  804. package/cloud-runtime/standalone/mcp/dist/security.js +0 -18
  805. package/cloud-runtime/standalone/mcp/dist/server.js +0 -240
  806. package/cloud-runtime/standalone/mcp/dist/task-context.js +0 -287
  807. package/cloud-runtime/standalone/mcp/dist/test-client.js +0 -82
  808. package/cloud-runtime/standalone/mcp/dist/tools/audit.js +0 -69
  809. package/cloud-runtime/standalone/mcp/dist/tools/learnings.js +0 -88
  810. package/cloud-runtime/standalone/mcp/dist/tools/queue.js +0 -312
  811. package/cloud-runtime/standalone/mcp/dist/tools/tasks.js +0 -244
  812. package/cloud-runtime/standalone/mcp/dist/types.js +0 -74
  813. package/cloud-runtime/standalone/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node +0 -0
  814. package/cloud-runtime/standalone/notes/comments-context-demo.md +0 -141
  815. package/cloud-runtime/standalone/notes/comments-context-plan.md +0 -119
  816. package/cloud-runtime/standalone/notes/context-audit.md +0 -21
  817. package/cloud-runtime/standalone/notes/project-layer-plan.md +0 -30
  818. package/cloud-runtime/standalone/notes/project-layer.md +0 -123
  819. package/cloud-runtime/standalone/notes/temporal-migration-design.md +0 -199
  820. package/cloud-runtime/standalone/playwright-report/data/00d55996f37c1506b90144c85493dd85032c13e5.png +0 -0
  821. package/cloud-runtime/standalone/playwright-report/data/0b9d409e57237ae111d7ba258d3dfe64dc368456.png +0 -0
  822. package/cloud-runtime/standalone/playwright-report/data/b33d5e80a15bd1deda4415b9d318ef73f581c950.png +0 -0
  823. package/cloud-runtime/standalone/playwright-report/data/b55684161aa440d0614595e13c91338f0420abbb.md +0 -131
  824. package/cloud-runtime/standalone/playwright-report/data/b9913957ae07e7565c38ddd71215be79b1ceb017.png +0 -0
  825. package/cloud-runtime/standalone/playwright-report/data/c3538be8ebbebc9fe4a7df8f12f04483af4a0d91.png +0 -0
  826. package/cloud-runtime/standalone/playwright-report/data/fe638f64ff5e36f1c30325564565662d3f57da87.md +0 -180
  827. package/cloud-runtime/standalone/playwright-report/index.html +0 -85
  828. package/cloud-runtime/standalone/test-results/auth-Authentication-Flow-S-aff25-sion-across-page-navigation-chromium/test-failed-1.png +0 -0
  829. package/cloud-runtime/standalone/test-results/comments-Task-comments-add-4dc59-nd-persists-it-for-the-task-chromium/error-context.md +0 -131
  830. package/cloud-runtime/standalone/test-results/comments-Task-comments-add-4dc59-nd-persists-it-for-the-task-chromium/test-failed-1.png +0 -0
  831. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Stage--4082a-er-planning-after-ideation--chromium/error-context.md +0 -180
  832. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Stage--4082a-er-planning-after-ideation--chromium/test-failed-1.png +0 -0
  833. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Stage-Columns-displays-all-9-SDLC-stages-chromium/error-context.md +0 -180
  834. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Stage-Columns-displays-all-9-SDLC-stages-chromium/test-failed-1.png +0 -0
  835. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Task-D-b6d98-ys-tasks-in-correct-columns-chromium/error-context.md +0 -180
  836. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Task-D-b6d98-ys-tasks-in-correct-columns-chromium/test-failed-1.png +0 -0
  837. package/cloud-runtime/standalone/test-results/kanban-Kanban-Board-Task-Display-shows-task-count-per-column-chromium/test-failed-1.png +0 -0
  838. package/cloud-runtime/standalone/test-results/kanban-Task-Lifecycle-can-advance-task-through-all-stages-chromium/test-failed-1.png +0 -0
  839. package/cloud-runtime/standalone/tsconfig.tsbuildinfo +0 -1
  840. /package/cloud-runtime/standalone/.next/static/{HOfhTqGoYN6GjsW9CCf3t → i_9nSHyb52FGkCbRgv7EJ}/_buildManifest.js +0 -0
  841. /package/cloud-runtime/standalone/.next/static/{HOfhTqGoYN6GjsW9CCf3t → i_9nSHyb52FGkCbRgv7EJ}/_clientMiddlewareManifest.json +0 -0
  842. /package/cloud-runtime/standalone/.next/static/{HOfhTqGoYN6GjsW9CCf3t → i_9nSHyb52FGkCbRgv7EJ}/_ssgManifest.js +0 -0
  843. /package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64 → sharp-libvips-linux-x64}/lib/index.js +0 -0
  844. /package/cloud-runtime/standalone/node_modules/@img/{sharp-libvips-darwin-arm64 → sharp-libvips-linux-x64}/versions.json +0 -0
@@ -86,20 +86,20 @@ var require_file_uri_to_path = __commonJS({
86
86
  var rest = decodeURI(uri.substring(7));
87
87
  var firstSlash = rest.indexOf("/");
88
88
  var host = rest.substring(0, firstSlash);
89
- var path5 = rest.substring(firstSlash + 1);
89
+ var path8 = rest.substring(firstSlash + 1);
90
90
  if ("localhost" == host) host = "";
91
91
  if (host) {
92
92
  host = sep + sep + host;
93
93
  }
94
- path5 = path5.replace(/^(.+)\|/, "$1:");
94
+ path8 = path8.replace(/^(.+)\|/, "$1:");
95
95
  if (sep == "\\") {
96
- path5 = path5.replace(/\//g, "\\");
96
+ path8 = path8.replace(/\//g, "\\");
97
97
  }
98
- if (/^.+\:/.test(path5)) {
98
+ if (/^.+\:/.test(path8)) {
99
99
  } else {
100
- path5 = sep + path5;
100
+ path8 = sep + path8;
101
101
  }
102
- return host + path5;
102
+ return host + path8;
103
103
  }
104
104
  }
105
105
  });
@@ -107,19 +107,19 @@ var require_file_uri_to_path = __commonJS({
107
107
  // ../agx-cloud/node_modules/bindings/bindings.js
108
108
  var require_bindings = __commonJS({
109
109
  "../agx-cloud/node_modules/bindings/bindings.js"(exports2, module2) {
110
- var fs4 = require("fs");
111
- var path5 = require("path");
110
+ var fs5 = require("fs");
111
+ var path8 = require("path");
112
112
  var fileURLToPath = require_file_uri_to_path();
113
- var join5 = path5.join;
114
- var dirname = path5.dirname;
115
- var exists = fs4.accessSync && function(path6) {
113
+ var join6 = path8.join;
114
+ var dirname = path8.dirname;
115
+ var exists = fs5.accessSync && function(path9) {
116
116
  try {
117
- fs4.accessSync(path6);
117
+ fs5.accessSync(path9);
118
118
  } catch (e) {
119
119
  return false;
120
120
  }
121
121
  return true;
122
- } || fs4.existsSync || path5.existsSync;
122
+ } || fs5.existsSync || path8.existsSync;
123
123
  var defaults = {
124
124
  arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
125
125
  compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
@@ -164,13 +164,13 @@ var require_bindings = __commonJS({
164
164
  if (!opts.module_root) {
165
165
  opts.module_root = exports2.getRoot(exports2.getFileName());
166
166
  }
167
- if (path5.extname(opts.bindings) != ".node") {
167
+ if (path8.extname(opts.bindings) != ".node") {
168
168
  opts.bindings += ".node";
169
169
  }
170
170
  var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
171
171
  var tries = [], i = 0, l = opts.try.length, n, b, err;
172
172
  for (; i < l; i++) {
173
- n = join5.apply(
173
+ n = join6.apply(
174
174
  null,
175
175
  opts.try[i].map(function(p) {
176
176
  return opts[p] || p;
@@ -231,7 +231,7 @@ var require_bindings = __commonJS({
231
231
  if (dir === ".") {
232
232
  dir = process.cwd();
233
233
  }
234
- if (exists(join5(dir, "package.json")) || exists(join5(dir, "node_modules"))) {
234
+ if (exists(join6(dir, "package.json")) || exists(join6(dir, "node_modules"))) {
235
235
  return dir;
236
236
  }
237
237
  if (prev === dir) {
@@ -240,7 +240,7 @@ var require_bindings = __commonJS({
240
240
  );
241
241
  }
242
242
  prev = dir;
243
- dir = join5(dir, "..");
243
+ dir = join6(dir, "..");
244
244
  }
245
245
  };
246
246
  }
@@ -402,11 +402,11 @@ var require_pragma = __commonJS({
402
402
  var require_backup = __commonJS({
403
403
  "../agx-cloud/node_modules/better-sqlite3/lib/methods/backup.js"(exports2, module2) {
404
404
  "use strict";
405
- var fs4 = require("fs");
406
- var path5 = require("path");
405
+ var fs5 = require("fs");
406
+ var path8 = require("path");
407
407
  var { promisify } = require("util");
408
408
  var { cppdb } = require_util();
409
- var fsAccess = promisify(fs4.access);
409
+ var fsAccess = promisify(fs5.access);
410
410
  module2.exports = async function backup(filename, options) {
411
411
  if (options == null) options = {};
412
412
  if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
@@ -419,7 +419,7 @@ var require_backup = __commonJS({
419
419
  if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
420
420
  if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
421
421
  if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
422
- await fsAccess(path5.dirname(filename)).catch(() => {
422
+ await fsAccess(path8.dirname(filename)).catch(() => {
423
423
  throw new TypeError("Cannot save backup because the directory does not exist");
424
424
  });
425
425
  const isNewFile = await fsAccess(filename).then(() => false, () => true);
@@ -712,7 +712,7 @@ var require_table = __commonJS({
712
712
  var require_inspect = __commonJS({
713
713
  "../agx-cloud/node_modules/better-sqlite3/lib/methods/inspect.js"(exports2, module2) {
714
714
  "use strict";
715
- var DatabaseInspection = function Database4() {
715
+ var DatabaseInspection = function Database7() {
716
716
  };
717
717
  module2.exports = function inspect(depth, opts) {
718
718
  return Object.assign(new DatabaseInspection(), this);
@@ -724,14 +724,14 @@ var require_inspect = __commonJS({
724
724
  var require_database = __commonJS({
725
725
  "../agx-cloud/node_modules/better-sqlite3/lib/database.js"(exports2, module2) {
726
726
  "use strict";
727
- var fs4 = require("fs");
728
- var path5 = require("path");
727
+ var fs5 = require("fs");
728
+ var path8 = require("path");
729
729
  var util = require_util();
730
730
  var SqliteError = require_sqlite_error();
731
731
  var DEFAULT_ADDON;
732
- function Database4(filenameGiven, options) {
732
+ function Database7(filenameGiven, options) {
733
733
  if (new.target == null) {
734
- return new Database4(filenameGiven, options);
734
+ return new Database7(filenameGiven, options);
735
735
  }
736
736
  let buffer;
737
737
  if (Buffer.isBuffer(filenameGiven)) {
@@ -761,7 +761,7 @@ var require_database = __commonJS({
761
761
  addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
762
762
  } else if (typeof nativeBinding === "string") {
763
763
  const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : require;
764
- addon = requireFunc(path5.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
764
+ addon = requireFunc(path8.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
765
765
  } else {
766
766
  addon = nativeBinding;
767
767
  }
@@ -769,7 +769,7 @@ var require_database = __commonJS({
769
769
  addon.setErrorConstructor(SqliteError);
770
770
  addon.isInitialized = true;
771
771
  }
772
- if (!anonymous && !filename.startsWith("file:") && !fs4.existsSync(path5.dirname(filename))) {
772
+ if (!anonymous && !filename.startsWith("file:") && !fs5.existsSync(path8.dirname(filename))) {
773
773
  throw new TypeError("Cannot open database because the directory does not exist");
774
774
  }
775
775
  Object.defineProperties(this, {
@@ -778,21 +778,21 @@ var require_database = __commonJS({
778
778
  });
779
779
  }
780
780
  var wrappers = require_wrappers();
781
- Database4.prototype.prepare = wrappers.prepare;
782
- Database4.prototype.transaction = require_transaction();
783
- Database4.prototype.pragma = require_pragma();
784
- Database4.prototype.backup = require_backup();
785
- Database4.prototype.serialize = require_serialize();
786
- Database4.prototype.function = require_function();
787
- Database4.prototype.aggregate = require_aggregate();
788
- Database4.prototype.table = require_table();
789
- Database4.prototype.loadExtension = wrappers.loadExtension;
790
- Database4.prototype.exec = wrappers.exec;
791
- Database4.prototype.close = wrappers.close;
792
- Database4.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
793
- Database4.prototype.unsafeMode = wrappers.unsafeMode;
794
- Database4.prototype[util.inspect] = require_inspect();
795
- module2.exports = Database4;
781
+ Database7.prototype.prepare = wrappers.prepare;
782
+ Database7.prototype.transaction = require_transaction();
783
+ Database7.prototype.pragma = require_pragma();
784
+ Database7.prototype.backup = require_backup();
785
+ Database7.prototype.serialize = require_serialize();
786
+ Database7.prototype.function = require_function();
787
+ Database7.prototype.aggregate = require_aggregate();
788
+ Database7.prototype.table = require_table();
789
+ Database7.prototype.loadExtension = wrappers.loadExtension;
790
+ Database7.prototype.exec = wrappers.exec;
791
+ Database7.prototype.close = wrappers.close;
792
+ Database7.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
793
+ Database7.prototype.unsafeMode = wrappers.unsafeMode;
794
+ Database7.prototype[util.inspect] = require_inspect();
795
+ module2.exports = Database7;
796
796
  }
797
797
  });
798
798
 
@@ -976,10 +976,31 @@ var init_auth_mode = __esm({
976
976
  });
977
977
 
978
978
  // ../agx-cloud/lib/mesh-core/activity.ts
979
- var import_path3, import_os3, AGENTS_DIR;
979
+ function activityPath(agentId) {
980
+ return (0, import_path3.join)(AGENTS_DIR, agentId, "activity.jsonl");
981
+ }
982
+ function ensureDir(agentId) {
983
+ const dir = (0, import_path3.join)(AGENTS_DIR, agentId);
984
+ if (!(0, import_fs3.existsSync)(dir)) (0, import_fs3.mkdirSync)(dir, { recursive: true });
985
+ }
986
+ function logActivity(agentId, action, data) {
987
+ try {
988
+ ensureDir(agentId);
989
+ const event = {
990
+ t: (/* @__PURE__ */ new Date()).toISOString(),
991
+ agent: agentId,
992
+ action,
993
+ ...data
994
+ };
995
+ (0, import_fs3.appendFileSync)(activityPath(agentId), JSON.stringify(event) + "\n", "utf-8");
996
+ } catch {
997
+ }
998
+ }
999
+ var import_fs3, import_path3, import_os3, AGENTS_DIR;
980
1000
  var init_activity = __esm({
981
1001
  "../agx-cloud/lib/mesh-core/activity.ts"() {
982
1002
  "use strict";
1003
+ import_fs3 = require("fs");
983
1004
  import_path3 = require("path");
984
1005
  import_os3 = require("os");
985
1006
  AGENTS_DIR = (0, import_path3.join)((0, import_os3.homedir)(), ".agx", "agents");
@@ -987,10 +1008,156 @@ var init_activity = __esm({
987
1008
  });
988
1009
 
989
1010
  // ../agx-cloud/lib/mesh-core/self.ts
990
- var import_path4, import_os4, AGENTS_DIR2;
1011
+ function selfPath(agentId) {
1012
+ return (0, import_path4.join)(AGENTS_DIR2, agentId, "self.md");
1013
+ }
1014
+ function reflectionStatePath(agentId) {
1015
+ return (0, import_path4.join)(AGENTS_DIR2, agentId, "reflection-state.json");
1016
+ }
1017
+ function readSelf(agentId) {
1018
+ const path8 = selfPath(agentId);
1019
+ if (!(0, import_fs4.existsSync)(path8)) return null;
1020
+ const raw = (0, import_fs4.readFileSync)(path8, "utf-8");
1021
+ if (!raw.trim()) return null;
1022
+ const lines = raw.split("\n");
1023
+ let version = 0;
1024
+ let derivedAt = (/* @__PURE__ */ new Date()).toISOString();
1025
+ let contentStart = 0;
1026
+ if (lines[0] === "---") {
1027
+ for (let i = 1; i < lines.length; i++) {
1028
+ if (lines[i] === "---") {
1029
+ contentStart = i + 1;
1030
+ break;
1031
+ }
1032
+ const [key, ...rest] = lines[i].split(": ");
1033
+ const val = rest.join(": ");
1034
+ if (key === "version") version = parseInt(val, 10) || 0;
1035
+ if (key === "derivedAt") derivedAt = val;
1036
+ }
1037
+ }
1038
+ return {
1039
+ agentId,
1040
+ content: lines.slice(contentStart).join("\n").trim(),
1041
+ version,
1042
+ derivedAt
1043
+ };
1044
+ }
1045
+ function writeSelf(agentId, content, version) {
1046
+ const dir = (0, import_path4.join)(AGENTS_DIR2, agentId);
1047
+ if (!(0, import_fs4.existsSync)(dir)) (0, import_fs4.mkdirSync)(dir, { recursive: true });
1048
+ const derivedAt = (/* @__PURE__ */ new Date()).toISOString();
1049
+ const full = `---
1050
+ version: ${version}
1051
+ derivedAt: ${derivedAt}
1052
+ ---
1053
+ ${content}
1054
+ `;
1055
+ const tmp = selfPath(agentId) + ".tmp";
1056
+ (0, import_fs4.writeFileSync)(tmp, full, "utf-8");
1057
+ (0, import_fs4.renameSync)(tmp, selfPath(agentId));
1058
+ logActivity(agentId, "self-updated", { meta: { version } });
1059
+ }
1060
+ function readReflectionState(agentId) {
1061
+ const path8 = reflectionStatePath(agentId);
1062
+ if (!(0, import_fs4.existsSync)(path8)) return null;
1063
+ try {
1064
+ const parsed = JSON.parse((0, import_fs4.readFileSync)(path8, "utf-8"));
1065
+ const lastProcessedJournalId = typeof parsed?.lastProcessedJournalId === "string" && parsed.lastProcessedJournalId.trim() ? parsed.lastProcessedJournalId.trim() : null;
1066
+ const updatedAt = typeof parsed?.updatedAt === "string" && parsed.updatedAt.trim() ? parsed.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
1067
+ return { lastProcessedJournalId, updatedAt };
1068
+ } catch {
1069
+ return null;
1070
+ }
1071
+ }
1072
+ function writeReflectionState(agentId, state) {
1073
+ const dir = (0, import_path4.join)(AGENTS_DIR2, agentId);
1074
+ if (!(0, import_fs4.existsSync)(dir)) (0, import_fs4.mkdirSync)(dir, { recursive: true });
1075
+ const tmp = reflectionStatePath(agentId) + ".tmp";
1076
+ (0, import_fs4.writeFileSync)(tmp, JSON.stringify(state, null, 2), "utf-8");
1077
+ (0, import_fs4.renameSync)(tmp, reflectionStatePath(agentId));
1078
+ }
1079
+ function buildReflectionPrompt(identity, currentSelf, recentJournal, teamSelves) {
1080
+ const selfText = currentSelf?.content || `I am ${identity.name}. ${identity.seed}`;
1081
+ const journalText = recentJournal.map((e) => {
1082
+ const parts = [`- [${e.t}] ${e.observation}`];
1083
+ if (e.judgement) parts.push(` Judgement: ${e.judgement}`);
1084
+ if (e.comparison) parts.push(` Comparison: ${e.comparison}`);
1085
+ if (e.delta) parts.push(` Delta: ${e.delta}`);
1086
+ if (e.intent) parts.push(` Intent: ${e.intent}`);
1087
+ return parts.join("\n");
1088
+ }).join("\n");
1089
+ const teamText = teamSelves.filter((s) => s.agentId !== identity.name).map((s) => `### ${s.agentId}
1090
+ ${s.content}`).join("\n\n");
1091
+ return `You are ${identity.name}. Voice: ${identity.voice}.
1092
+
1093
+ ## Canonical Identity
1094
+ ${identity.seed}
1095
+
1096
+ ## Current Self-Model (v${currentSelf?.version ?? 0})
1097
+ ${selfText}
1098
+
1099
+ ## Recent Journal Entries (since last reflection)
1100
+ These entries are evidence about how you worked. Treat them as signals, not ground truth. Use them to identify patterns in execution, coordination, inquiry, and specialization. Do NOT repeat or reference specific technical content from past conversations.
1101
+ ${journalText || "(none)"}
1102
+
1103
+ ## Team \u2014 Other Agents' Current Self-Models
1104
+ ${teamText || "(no other agents)"}
1105
+
1106
+ ## Instructions
1107
+ Write your updated self-model. This is not canonical identity. It is your current understanding of how you best contribute, where you fit in the team, and what specialization you should lean into next.
1108
+
1109
+ Consider:
1110
+ - What patterns are emerging in your work?
1111
+ - What kind of work do you reliably do well?
1112
+ - Where are you overlapping too much with other agents?
1113
+ - What role or niche seems under-covered in this team?
1114
+ - How should you specialize further in this project context?
1115
+
1116
+ Do NOT reference specific files, functions, or technical details from past conversations. Focus on your evolving capabilities and working style.
1117
+
1118
+ Write in first person. Be specific about your strengths, gaps, comparative fit, and next direction. This is not a summary and not an autobiography. It is a concise specialization-oriented self-model. Keep it under 200 words.`;
1119
+ }
1120
+ function formatKnowledgeLines(existingMemories) {
1121
+ if (existingMemories.length === 0) return "(none)";
1122
+ return existingMemories.map((entry) => `- [${entry.kind}] ${entry.title}: ${entry.body}`).join("\n");
1123
+ }
1124
+ function buildStructuredReflectionPrompt(identity, currentSelf, recentJournal, teamSelves, existingMemories) {
1125
+ const selfPrompt = buildReflectionPrompt(identity, currentSelf, recentJournal, teamSelves);
1126
+ return `${selfPrompt}
1127
+
1128
+ ## Existing Agent Memories
1129
+ ${formatKnowledgeLines(existingMemories)}
1130
+
1131
+ ## Output Format
1132
+ Return ONLY a JSON object with this exact shape:
1133
+ {
1134
+ "self_model": "updated self-model text",
1135
+ "memories": [
1136
+ {
1137
+ "kind": "pattern" | "preference" | "constraint" | "decision" | "lesson" | "gotcha",
1138
+ "title": "short title",
1139
+ "body": "one concise durable behavior-level memory",
1140
+ "confidence": 0.0,
1141
+ "durability": 0.0,
1142
+ "tags": ["optional", "tags"],
1143
+ "evidence": [{"id":"journal-entry-id","note":"short evidence note"}]
1144
+ }
1145
+ ]
1146
+ }
1147
+
1148
+ Rules:
1149
+ - Emit 0-3 memories.
1150
+ - Memories must be durable behavior-level insights about how you work best, collaborate, decide, or fail repeatedly.
1151
+ - Do not include task-specific technical facts unless they clearly generalize into agent behavior.
1152
+ - Do not restate memories already covered in Existing Agent Memories.
1153
+ - If nothing genuinely new was learned, return an empty memories array.
1154
+ - Do not wrap the JSON in markdown fences.`;
1155
+ }
1156
+ var import_fs4, import_path4, import_os4, AGENTS_DIR2;
991
1157
  var init_self = __esm({
992
1158
  "../agx-cloud/lib/mesh-core/self.ts"() {
993
1159
  "use strict";
1160
+ import_fs4 = require("fs");
994
1161
  import_path4 = require("path");
995
1162
  import_os4 = require("os");
996
1163
  init_activity();
@@ -999,10 +1166,89 @@ var init_self = __esm({
999
1166
  });
1000
1167
 
1001
1168
  // ../agx-cloud/lib/mesh-core/journal.ts
1002
- var import_path5, import_os5, AGENTS_DIR3;
1169
+ function agentDir(agentId) {
1170
+ return (0, import_path5.join)(AGENTS_DIR3, agentId);
1171
+ }
1172
+ function journalPath(agentId) {
1173
+ return (0, import_path5.join)(agentDir(agentId), "journal.jsonl");
1174
+ }
1175
+ function ensureAgentDir(agentId) {
1176
+ const dir = agentDir(agentId);
1177
+ if (!(0, import_fs5.existsSync)(dir)) {
1178
+ (0, import_fs5.mkdirSync)(dir, { recursive: true });
1179
+ }
1180
+ }
1181
+ function readJournalLines(agentId) {
1182
+ const path8 = journalPath(agentId);
1183
+ if (!(0, import_fs5.existsSync)(path8)) return [];
1184
+ return (0, import_fs5.readFileSync)(path8, "utf-8").split("\n").filter((l) => l.trim());
1185
+ }
1186
+ function parseMaxSeq(agentId, lines) {
1187
+ let maxSeq = 0;
1188
+ for (const line of lines) {
1189
+ try {
1190
+ const parsed = JSON.parse(line);
1191
+ const [idAgent, seqRaw] = String(parsed.id || "").split(":");
1192
+ if (idAgent !== agentId) continue;
1193
+ const seq = parseInt(seqRaw || "0", 10);
1194
+ if (Number.isFinite(seq) && seq > maxSeq) maxSeq = seq;
1195
+ } catch {
1196
+ }
1197
+ }
1198
+ return maxSeq;
1199
+ }
1200
+ function parseEntrySeq(agentId, entryId) {
1201
+ const [idAgent, seqRaw] = String(entryId || "").split(":");
1202
+ if (idAgent !== agentId) return 0;
1203
+ const seq = parseInt(seqRaw || "0", 10);
1204
+ return Number.isFinite(seq) ? seq : 0;
1205
+ }
1206
+ function appendJournal(agentId, entry) {
1207
+ ensureAgentDir(agentId);
1208
+ const lines = readJournalLines(agentId);
1209
+ const maxSeq = parseMaxSeq(agentId, lines);
1210
+ const nextId = `${agentId}:${maxSeq + 1}`;
1211
+ const normalized = { ...entry, id: entry.id?.trim() || nextId };
1212
+ const line = JSON.stringify(normalized) + "\n";
1213
+ (0, import_fs5.appendFileSync)(journalPath(agentId), line, "utf-8");
1214
+ logActivity(agentId, entry.type === "reflection" ? "reflection" : "journal-post", {
1215
+ thread: normalized.thread,
1216
+ meta: { entryId: normalized.id }
1217
+ });
1218
+ return normalized;
1219
+ }
1220
+ function readJournal(agentId, limit) {
1221
+ const lines = readJournalLines(agentId);
1222
+ const entries = [];
1223
+ for (const line of lines) {
1224
+ try {
1225
+ entries.push(JSON.parse(line));
1226
+ } catch {
1227
+ }
1228
+ }
1229
+ entries.reverse();
1230
+ return limit ? entries.slice(0, limit) : entries;
1231
+ }
1232
+ function readJournalSince(agentId, afterEntryId) {
1233
+ const lines = readJournalLines(agentId);
1234
+ const afterSeq = parseEntrySeq(agentId, afterEntryId);
1235
+ const entries = [];
1236
+ for (const line of lines) {
1237
+ try {
1238
+ const parsed = JSON.parse(line);
1239
+ if (parseEntrySeq(agentId, parsed.id) > afterSeq) {
1240
+ entries.push(parsed);
1241
+ }
1242
+ } catch {
1243
+ }
1244
+ }
1245
+ return entries;
1246
+ }
1247
+ var import_fs5, import_path5, import_os5, AGENTS_DIR3;
1003
1248
  var init_journal = __esm({
1004
1249
  "../agx-cloud/lib/mesh-core/journal.ts"() {
1005
1250
  "use strict";
1251
+ import_fs5 = require("fs");
1006
1252
  import_path5 = require("path");
1007
1253
  import_os5 = require("os");
1008
1254
  init_activity();
@@ -1013,27 +1259,27 @@ var init_journal = __esm({
1013
1259
  // ../agx-cloud/lib/mesh-core/agent.ts
1014
1260
  function ensureAgent(agentId, options) {
1015
1261
  const dir = (0, import_path6.join)(AGENTS_DIR4, agentId);
1016
- if (!(0, import_fs3.existsSync)(dir)) {
1017
- (0, import_fs3.mkdirSync)(dir, { recursive: true });
1262
+ if (!(0, import_fs6.existsSync)(dir)) {
1263
+ (0, import_fs6.mkdirSync)(dir, { recursive: true });
1018
1264
  }
1019
1265
  const voice = options?.voice?.trim() || DEFAULT_VOICE;
1020
1266
  const seed = options?.seed?.trim() || DEFAULT_SEED;
1021
1267
  const identityPath = (0, import_path6.join)(dir, "identity.json");
1022
- if (!(0, import_fs3.existsSync)(identityPath)) {
1268
+ if (!(0, import_fs6.existsSync)(identityPath)) {
1023
1269
  const identity = { name: agentId, voice, seed };
1024
- (0, import_fs3.writeFileSync)(identityPath, JSON.stringify(identity, null, 2) + "\n", "utf-8");
1270
+ (0, import_fs6.writeFileSync)(identityPath, JSON.stringify(identity, null, 2) + "\n", "utf-8");
1025
1271
  }
1026
1272
  const journal = (0, import_path6.join)(dir, "journal.jsonl");
1027
1273
  const reactions = (0, import_path6.join)(dir, "reactions.jsonl");
1028
1274
  const comments = (0, import_path6.join)(dir, "comments.jsonl");
1029
1275
  const activity = (0, import_path6.join)(dir, "activity.jsonl");
1030
1276
  const self = (0, import_path6.join)(dir, "self.md");
1031
- if (!(0, import_fs3.existsSync)(journal)) (0, import_fs3.writeFileSync)(journal, "", "utf-8");
1032
- if (!(0, import_fs3.existsSync)(reactions)) (0, import_fs3.writeFileSync)(reactions, "", "utf-8");
1033
- if (!(0, import_fs3.existsSync)(comments)) (0, import_fs3.writeFileSync)(comments, "", "utf-8");
1034
- if (!(0, import_fs3.existsSync)(activity)) (0, import_fs3.writeFileSync)(activity, "", "utf-8");
1035
- if (!(0, import_fs3.existsSync)(self)) {
1036
- (0, import_fs3.writeFileSync)(
1277
+ if (!(0, import_fs6.existsSync)(journal)) (0, import_fs6.writeFileSync)(journal, "", "utf-8");
1278
+ if (!(0, import_fs6.existsSync)(reactions)) (0, import_fs6.writeFileSync)(reactions, "", "utf-8");
1279
+ if (!(0, import_fs6.existsSync)(comments)) (0, import_fs6.writeFileSync)(comments, "", "utf-8");
1280
+ if (!(0, import_fs6.existsSync)(activity)) (0, import_fs6.writeFileSync)(activity, "", "utf-8");
1281
+ if (!(0, import_fs6.existsSync)(self)) {
1282
+ (0, import_fs6.writeFileSync)(
1037
1283
  self,
1038
1284
  `---
1039
1285
  version: 0
@@ -1046,23 +1292,26 @@ I am ${agentId}. ${seed}
1046
1292
  }
1047
1293
  }
1048
1294
  function readIdentity(agentId) {
1049
- const path5 = (0, import_path6.join)(AGENTS_DIR4, agentId, "identity.json");
1050
- if (!(0, import_fs3.existsSync)(path5)) return null;
1295
+ const path8 = (0, import_path6.join)(AGENTS_DIR4, agentId, "identity.json");
1296
+ if (!(0, import_fs6.existsSync)(path8)) return null;
1051
1297
  try {
1052
- return JSON.parse((0, import_fs3.readFileSync)(path5, "utf-8"));
1298
+ return JSON.parse((0, import_fs6.readFileSync)(path8, "utf-8"));
1053
1299
  } catch {
1054
1300
  return null;
1055
1301
  }
1056
1302
  }
1057
1303
  function listAgents() {
1058
- if (!(0, import_fs3.existsSync)(AGENTS_DIR4)) return [];
1059
- return (0, import_fs3.readdirSync)(AGENTS_DIR4, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
1304
+ if (!(0, import_fs6.existsSync)(AGENTS_DIR4)) return [];
1305
+ return (0, import_fs6.readdirSync)(AGENTS_DIR4, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
1306
+ }
1307
+ function getTeamSelves(excludeAgent) {
1308
+ return listAgents().filter((id) => id !== excludeAgent).map((id) => readSelf(id)).filter((s) => s !== null);
1060
1309
  }
1061
- var import_fs3, import_path6, import_os6, AGENTS_DIR4, DEFAULT_VOICE, DEFAULT_SEED;
1310
+ var import_fs6, import_path6, import_os6, AGENTS_DIR4, DEFAULT_VOICE, DEFAULT_SEED;
1062
1311
  var init_agent = __esm({
1063
1312
  "../agx-cloud/lib/mesh-core/agent.ts"() {
1064
1313
  "use strict";
1065
- import_fs3 = require("fs");
1314
+ import_fs6 = require("fs");
1066
1315
  import_path6 = require("path");
1067
1316
  import_os6 = require("os");
1068
1317
  init_self();
@@ -1091,18 +1340,18 @@ function migrateAgentDirectory(oldId, newId, displayName) {
1091
1340
  if (!oldId || !newId || oldId === newId) return;
1092
1341
  const oldDir = import_path7.default.join(AGENTS_DIR5, oldId);
1093
1342
  const newDir = import_path7.default.join(AGENTS_DIR5, newId);
1094
- if (!(0, import_fs4.existsSync)(oldDir) || (0, import_fs4.existsSync)(newDir)) return;
1095
- (0, import_fs4.mkdirSync)(AGENTS_DIR5, { recursive: true });
1096
- (0, import_fs4.renameSync)(oldDir, newDir);
1343
+ if (!(0, import_fs7.existsSync)(oldDir) || (0, import_fs7.existsSync)(newDir)) return;
1344
+ (0, import_fs7.mkdirSync)(AGENTS_DIR5, { recursive: true });
1345
+ (0, import_fs7.renameSync)(oldDir, newDir);
1097
1346
  const identityPath = import_path7.default.join(newDir, "identity.json");
1098
- if (!(0, import_fs4.existsSync)(identityPath)) return;
1347
+ if (!(0, import_fs7.existsSync)(identityPath)) return;
1099
1348
  try {
1100
- const parsed = JSON.parse((0, import_fs4.readFileSync)(identityPath, "utf8"));
1349
+ const parsed = JSON.parse((0, import_fs7.readFileSync)(identityPath, "utf8"));
1101
1350
  const updated = {
1102
1351
  ...parsed,
1103
1352
  name: typeof displayName === "string" && displayName.trim() ? displayName.trim() : newId
1104
1353
  };
1105
- (0, import_fs4.writeFileSync)(identityPath, `${JSON.stringify(updated, null, 2)}
1354
+ (0, import_fs7.writeFileSync)(identityPath, `${JSON.stringify(updated, null, 2)}
1106
1355
  `, "utf8");
1107
1356
  } catch {
1108
1357
  }
@@ -1180,7 +1429,7 @@ function migrateLegacyParticipantIds(db2) {
1180
1429
  }
1181
1430
  }
1182
1431
  function getDb() {
1183
- (0, import_fs4.mkdirSync)(STORE_DIR, { recursive: true });
1432
+ (0, import_fs7.mkdirSync)(STORE_DIR, { recursive: true });
1184
1433
  const db2 = new import_better_sqlite32.default(DB_PATH);
1185
1434
  db2.pragma("journal_mode = WAL");
1186
1435
  db2.exec(`
@@ -1258,12 +1507,12 @@ function loadParticipants() {
1258
1507
  db2.close();
1259
1508
  }
1260
1509
  }
1261
- var import_better_sqlite32, import_fs4, import_path7, import_os7, STORE_DIR, DB_PATH, AGENTS_DIR5;
1510
+ var import_better_sqlite32, import_fs7, import_path7, import_os7, STORE_DIR, DB_PATH, AGENTS_DIR5;
1262
1511
  var init_participants_store = __esm({
1263
1512
  "../agx-cloud/lib/participants-store.ts"() {
1264
1513
  "use strict";
1265
1514
  import_better_sqlite32 = __toESM(require_lib());
1266
- import_fs4 = require("fs");
1515
+ import_fs7 = require("fs");
1267
1516
  import_path7 = __toESM(require("path"));
1268
1517
  import_os7 = __toESM(require("os"));
1269
1518
  STORE_DIR = process.env.AGX_GROUP_CHAT_DIR?.trim() || import_path7.default.join(import_os7.default.homedir(), ".agx", "group-chat");
@@ -1589,11 +1838,11 @@ ${msgs.join("\n")}`);
1589
1838
  }
1590
1839
  function initSQLiteSchema(db2) {
1591
1840
  const ddlPath = import_path8.default.join(process.cwd(), "db", "sqlite", "001_agx_board_schema.sql");
1592
- if (!import_fs5.default.existsSync(ddlPath)) {
1841
+ if (!import_fs8.default.existsSync(ddlPath)) {
1593
1842
  console.warn(`[sqlite] DDL not found at ${ddlPath}, skipping schema init`);
1594
1843
  return;
1595
1844
  }
1596
- const ddl = import_fs5.default.readFileSync(ddlPath, "utf-8");
1845
+ const ddl = import_fs8.default.readFileSync(ddlPath, "utf-8");
1597
1846
  db2.exec(ddl);
1598
1847
  }
1599
1848
  function dropLegacyTeamsTables(db2) {
@@ -1699,6 +1948,80 @@ function runMigrations(db2) {
1699
1948
  CREATE INDEX IF NOT EXISTS idx_repo_knowledge_repo ON repo_knowledge (repo_id, created_at);
1700
1949
  CREATE INDEX IF NOT EXISTS idx_repo_knowledge_producer ON repo_knowledge (producer);
1701
1950
  `);
1951
+ db2.exec(`
1952
+ CREATE TABLE IF NOT EXISTS knowledge_entries (
1953
+ id TEXT NOT NULL PRIMARY KEY,
1954
+ scope TEXT NOT NULL CHECK(scope IN ('agent', 'repo', 'project')),
1955
+ subject_id TEXT NOT NULL,
1956
+ source_type TEXT NOT NULL CHECK(source_type IN ('reflection', 'thread_transition', 'task_completion')),
1957
+ source_id TEXT NOT NULL,
1958
+ kind TEXT NOT NULL CHECK(kind IN ('outcome', 'decision', 'pattern', 'gotcha', 'preference', 'constraint', 'convention', 'lesson')),
1959
+ title TEXT NOT NULL,
1960
+ body TEXT NOT NULL,
1961
+ confidence REAL,
1962
+ durability REAL,
1963
+ tags JSON NOT NULL DEFAULT '[]',
1964
+ evidence JSON NOT NULL DEFAULT '[]',
1965
+ metadata JSON NOT NULL DEFAULT '{}',
1966
+ content_hash TEXT NOT NULL,
1967
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
1968
+ updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
1969
+ UNIQUE(scope, subject_id, content_hash)
1970
+ );
1971
+ CREATE INDEX IF NOT EXISTS idx_knowledge_entries_scope_subject ON knowledge_entries (scope, subject_id, updated_at);
1972
+ CREATE INDEX IF NOT EXISTS idx_knowledge_entries_source ON knowledge_entries (source_type, source_id);
1973
+ `);
1974
+ db2.exec(`
1975
+ CREATE TABLE IF NOT EXISTS knowledge_notes (
1976
+ id TEXT NOT NULL PRIMARY KEY,
1977
+ scope TEXT NOT NULL CHECK(scope IN ('agent', 'repo', 'project')),
1978
+ subject_id TEXT NOT NULL,
1979
+ content TEXT NOT NULL DEFAULT '',
1980
+ change_summary TEXT,
1981
+ source_type TEXT NOT NULL CHECK(source_type IN ('reflection', 'thread_transition', 'task_completion')),
1982
+ source_id TEXT NOT NULL,
1983
+ metadata JSON NOT NULL DEFAULT '{}',
1984
+ version INTEGER NOT NULL DEFAULT 1,
1985
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
1986
+ updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
1987
+ UNIQUE(scope, subject_id)
1988
+ );
1989
+ CREATE INDEX IF NOT EXISTS idx_knowledge_notes_scope_subject ON knowledge_notes (scope, subject_id);
1990
+ `);
1991
+ db2.exec(`
1992
+ CREATE TABLE IF NOT EXISTS knowledge_note_versions (
1993
+ id TEXT NOT NULL PRIMARY KEY,
1994
+ note_id TEXT NOT NULL REFERENCES knowledge_notes(id) ON DELETE CASCADE,
1995
+ version INTEGER NOT NULL,
1996
+ content TEXT NOT NULL,
1997
+ change_summary TEXT,
1998
+ source_type TEXT NOT NULL CHECK(source_type IN ('reflection', 'thread_transition', 'task_completion')),
1999
+ source_id TEXT NOT NULL,
2000
+ metadata JSON NOT NULL DEFAULT '{}',
2001
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
2002
+ );
2003
+ CREATE INDEX IF NOT EXISTS idx_knowledge_note_versions_note_version
2004
+ ON knowledge_note_versions (note_id, version DESC);
2005
+ `);
2006
+ db2.exec(`
2007
+ CREATE TABLE IF NOT EXISTS thread_knowledge_runs (
2008
+ id TEXT NOT NULL PRIMARY KEY,
2009
+ thread_id TEXT NOT NULL,
2010
+ root_message_id TEXT NOT NULL,
2011
+ status TEXT NOT NULL CHECK(status IN ('running', 'completed', 'failed')),
2012
+ requested_scopes JSON NOT NULL DEFAULT '[]',
2013
+ repo_inserted_count INTEGER NOT NULL DEFAULT 0,
2014
+ project_inserted_count INTEGER NOT NULL DEFAULT 0,
2015
+ error TEXT,
2016
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
2017
+ updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
2018
+ completed_at TEXT
2019
+ );
2020
+ CREATE INDEX IF NOT EXISTS idx_thread_knowledge_runs_root_created
2021
+ ON thread_knowledge_runs (root_message_id, created_at DESC);
2022
+ CREATE INDEX IF NOT EXISTS idx_thread_knowledge_runs_thread_created
2023
+ ON thread_knowledge_runs (thread_id, created_at DESC);
2024
+ `);
1702
2025
  db2.exec(`
1703
2026
  CREATE TABLE IF NOT EXISTS project_threads (
1704
2027
  project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
@@ -1921,12 +2244,12 @@ function createAdminDbClientSQLite() {
1921
2244
  }
1922
2245
  };
1923
2246
  }
1924
- var import_better_sqlite33, import_fs5, import_path8, import_os8, AGX_DATA_DIR2, SqlExpression, _db, JSON_COLUMNS, SQLiteQueryBuilder, KNOWN_JSON_COLUMNS;
2247
+ var import_better_sqlite33, import_fs8, import_path8, import_os8, AGX_DATA_DIR2, SqlExpression, _db, JSON_COLUMNS, SQLiteQueryBuilder, KNOWN_JSON_COLUMNS;
1925
2248
  var init_sqlite_query_adapter = __esm({
1926
2249
  "../agx-cloud/lib/sqlite-query-adapter.ts"() {
1927
2250
  "use strict";
1928
2251
  import_better_sqlite33 = __toESM(require_lib());
1929
- import_fs5 = __toESM(require("fs"));
2252
+ import_fs8 = __toESM(require("fs"));
1930
2253
  import_path8 = __toESM(require("path"));
1931
2254
  import_os8 = __toESM(require("os"));
1932
2255
  init_auth_mode();
@@ -3581,6 +3904,15 @@ async function getAgent(id, userId) {
3581
3904
  }
3582
3905
  return data;
3583
3906
  }
3907
+ async function getAgentSkills(agentId) {
3908
+ const db2 = createAdminDbClient();
3909
+ const { data, error } = await db2.from("agent_skills").select("*").eq("agent_id", agentId).order("created_at", { ascending: true });
3910
+ if (error) {
3911
+ if (isMissingRelationError2(error, "agent_skills")) return [];
3912
+ throw error;
3913
+ }
3914
+ return data || [];
3915
+ }
3584
3916
  async function createAgent(userId, input) {
3585
3917
  const db2 = createAdminDbClient();
3586
3918
  const payload = {
@@ -4431,6 +4763,7 @@ var SQLiteQueueAdapter = class {
4431
4763
  var queue = null;
4432
4764
  var QUEUE_NAMES = {
4433
4765
  TASK_PROCESS: "agx.task.process",
4766
+ CHAT_RUN_PROCESS: "agx.chat.process",
4434
4767
  TASK_CLEANUP: "agx.task.cleanup"
4435
4768
  };
4436
4769
  async function getQueue() {
@@ -4681,7 +5014,7 @@ async function resolveWorkflowTransition({
4681
5014
  init_db();
4682
5015
 
4683
5016
  // ../agx-cloud/lib/memory-extractor.ts
4684
- var import_crypto2 = require("crypto");
5017
+ var import_crypto4 = require("crypto");
4685
5018
 
4686
5019
  // ../agx-cloud/lib/cli-runner.ts
4687
5020
  var import_child_process = require("child_process");
@@ -5106,6 +5439,305 @@ ${prompt}` : prompt;
5106
5439
 
5107
5440
  // ../agx-cloud/lib/memory-extractor.ts
5108
5441
  init_sqlite_query_adapter();
5442
+
5443
+ // ../agx-cloud/lib/knowledge-store.ts
5444
+ var import_crypto2 = require("crypto");
5445
+ init_sqlite_query_adapter();
5446
+ function clampUnitNumber(value) {
5447
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
5448
+ return Math.max(0, Math.min(1, value));
5449
+ }
5450
+ function parseJsonArray(raw) {
5451
+ if (!raw) return [];
5452
+ try {
5453
+ const parsed = JSON.parse(raw);
5454
+ return Array.isArray(parsed) ? parsed : [];
5455
+ } catch {
5456
+ return [];
5457
+ }
5458
+ }
5459
+ function parseJsonObject(raw) {
5460
+ if (!raw) return {};
5461
+ try {
5462
+ const parsed = JSON.parse(raw);
5463
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
5464
+ } catch {
5465
+ return {};
5466
+ }
5467
+ }
5468
+ function normalizeTags(tags) {
5469
+ const seen = /* @__PURE__ */ new Set();
5470
+ const result = [];
5471
+ for (const tag of tags ?? []) {
5472
+ const trimmed = String(tag ?? "").trim().toLowerCase();
5473
+ if (!trimmed || seen.has(trimmed)) continue;
5474
+ seen.add(trimmed);
5475
+ result.push(trimmed);
5476
+ }
5477
+ return result;
5478
+ }
5479
+ function normalizeEvidence(evidence) {
5480
+ const result = [];
5481
+ for (const item of evidence ?? []) {
5482
+ const note = String(item?.note ?? "").trim();
5483
+ const id = typeof item?.id === "string" ? item.id.trim() : "";
5484
+ if (!note) continue;
5485
+ result.push(id ? { id, note } : { note });
5486
+ }
5487
+ return result;
5488
+ }
5489
+ function mapRow(row) {
5490
+ return {
5491
+ id: row.id,
5492
+ scope: row.scope,
5493
+ subjectId: row.subject_id,
5494
+ sourceType: row.source_type,
5495
+ sourceId: row.source_id,
5496
+ kind: row.kind,
5497
+ title: row.title,
5498
+ body: row.body,
5499
+ confidence: clampUnitNumber(row.confidence),
5500
+ durability: clampUnitNumber(row.durability),
5501
+ tags: parseJsonArray(row.tags),
5502
+ evidence: parseJsonArray(row.evidence),
5503
+ metadata: parseJsonObject(row.metadata),
5504
+ createdAt: row.created_at,
5505
+ updatedAt: row.updated_at
5506
+ };
5507
+ }
5508
+ function listKnowledgeEntries(input) {
5509
+ const db2 = getSQLiteDb();
5510
+ const rows = db2.prepare(
5511
+ `SELECT id, scope, subject_id, source_type, source_id, kind, title, body,
5512
+ confidence, durability, tags, evidence, metadata, created_at, updated_at
5513
+ FROM knowledge_entries
5514
+ WHERE scope = ? AND subject_id = ?
5515
+ ORDER BY updated_at DESC, created_at DESC
5516
+ LIMIT ?`
5517
+ ).all(input.scope, input.subjectId, input.limit ?? 50);
5518
+ return rows.map(mapRow);
5519
+ }
5520
+ function storeKnowledgeEntries(drafts) {
5521
+ if (drafts.length === 0) return 0;
5522
+ const db2 = getSQLiteDb();
5523
+ const now = (/* @__PURE__ */ new Date()).toISOString();
5524
+ const existingStmt = db2.prepare(
5525
+ `SELECT id
5526
+ FROM knowledge_entries
5527
+ WHERE scope = ? AND subject_id = ? AND content_hash = ?
5528
+ LIMIT 1`
5529
+ );
5530
+ const insertStmt = db2.prepare(
5531
+ `INSERT INTO knowledge_entries (
5532
+ id, scope, subject_id, source_type, source_id, kind, title, body,
5533
+ confidence, durability, tags, evidence, metadata, content_hash, created_at, updated_at
5534
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
5535
+ );
5536
+ let inserted = 0;
5537
+ const tx = db2.transaction((entries) => {
5538
+ for (const draft of entries) {
5539
+ const subjectId = draft.subjectId.trim();
5540
+ const title = draft.title.trim();
5541
+ const body = draft.body.trim();
5542
+ const sourceId = draft.sourceId.trim();
5543
+ if (!subjectId || !title || !body || !sourceId) continue;
5544
+ const contentHash = (0, import_crypto2.createHash)("sha256").update(`${draft.scope}
5545
+ ${subjectId}
5546
+ ${body}`).digest("hex");
5547
+ const existing = existingStmt.get(draft.scope, subjectId, contentHash);
5548
+ if (existing) continue;
5549
+ insertStmt.run(
5550
+ (0, import_crypto2.randomUUID)(),
5551
+ draft.scope,
5552
+ subjectId,
5553
+ draft.sourceType,
5554
+ sourceId,
5555
+ draft.kind,
5556
+ title,
5557
+ body,
5558
+ clampUnitNumber(draft.confidence),
5559
+ clampUnitNumber(draft.durability),
5560
+ JSON.stringify(normalizeTags(draft.tags)),
5561
+ JSON.stringify(normalizeEvidence(draft.evidence)),
5562
+ JSON.stringify(draft.metadata ?? {}),
5563
+ contentHash,
5564
+ now,
5565
+ now
5566
+ );
5567
+ inserted += 1;
5568
+ }
5569
+ });
5570
+ tx(drafts);
5571
+ return inserted;
5572
+ }
5573
+
5574
+ // ../agx-cloud/lib/knowledge-notes.ts
5575
+ var import_crypto3 = require("crypto");
5576
+ init_sqlite_query_adapter();
5577
+ function parseJsonObject2(raw) {
5578
+ if (!raw) return {};
5579
+ try {
5580
+ const parsed = JSON.parse(raw);
5581
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
5582
+ } catch {
5583
+ return {};
5584
+ }
5585
+ }
5586
+ function normalizeContent(content) {
5587
+ return content.replace(/\r\n/g, "\n").split("\n").map((line) => line.replace(/\s+$/g, "")).join("\n").trim();
5588
+ }
5589
+ function mapRow2(row) {
5590
+ return {
5591
+ id: row.id,
5592
+ scope: row.scope,
5593
+ subjectId: row.subject_id,
5594
+ content: row.content,
5595
+ changeSummary: row.change_summary ?? null,
5596
+ sourceType: row.source_type,
5597
+ sourceId: row.source_id,
5598
+ metadata: parseJsonObject2(row.metadata),
5599
+ version: Number(row.version ?? 1),
5600
+ createdAt: row.created_at,
5601
+ updatedAt: row.updated_at
5602
+ };
5603
+ }
5604
+ function getKnowledgeNoteRow(scope, subjectId) {
5605
+ const db2 = getSQLiteDb();
5606
+ return db2.prepare(
5607
+ `SELECT id, scope, subject_id, content, change_summary, source_type, source_id,
5608
+ metadata, version, created_at, updated_at
5609
+ FROM knowledge_notes
5610
+ WHERE scope = ? AND subject_id = ?
5611
+ LIMIT 1`
5612
+ ).get(scope, subjectId);
5613
+ }
5614
+ function listLegacySystemStatements(scope, subjectId) {
5615
+ const db2 = getSQLiteDb();
5616
+ if (scope === "repo") {
5617
+ const systemRepoRows = db2.prepare(
5618
+ `SELECT content
5619
+ FROM repo_knowledge
5620
+ WHERE repo_id = ? AND producer = 'system'
5621
+ ORDER BY created_at ASC`
5622
+ ).all(subjectId);
5623
+ const entryBodies2 = listKnowledgeEntries({ scope: "repo", subjectId, limit: 100 }).map((entry) => entry.body.trim());
5624
+ return [...systemRepoRows.map((row) => row.content.trim()), ...entryBodies2].filter(Boolean);
5625
+ }
5626
+ if (scope === "project") {
5627
+ const systemProjectRows = db2.prepare(
5628
+ `SELECT content
5629
+ FROM project_memory
5630
+ WHERE project_id = ? AND producer = 'system'
5631
+ ORDER BY created_at ASC`
5632
+ ).all(subjectId);
5633
+ const entryBodies2 = listKnowledgeEntries({ scope: "project", subjectId, limit: 100 }).map((entry) => entry.body.trim());
5634
+ return [...systemProjectRows.map((row) => row.content.trim()), ...entryBodies2].filter(Boolean);
5635
+ }
5636
+ const agentRows = db2.prepare(
5637
+ `SELECT content
5638
+ FROM agent_memory
5639
+ WHERE agent_id = ?
5640
+ ORDER BY created_at ASC
5641
+ LIMIT 100`
5642
+ ).all(subjectId);
5643
+ const entryBodies = listKnowledgeEntries({ scope: "agent", subjectId, limit: 100 }).map((entry) => entry.body.trim());
5644
+ return [...agentRows.map((row) => row.content.trim()), ...entryBodies].filter(Boolean);
5645
+ }
5646
+ function synthesizeLegacyNoteContent(scope, subjectId) {
5647
+ const unique = Array.from(new Set(listLegacySystemStatements(scope, subjectId)));
5648
+ if (unique.length === 0) return "";
5649
+ return unique.map((line) => `- ${line.replace(/^\-\s*/, "")}`).join("\n");
5650
+ }
5651
+ function ensureKnowledgeNote(scope, subjectId) {
5652
+ const existing = getKnowledgeNoteRow(scope, subjectId);
5653
+ if (existing) return mapRow2(existing);
5654
+ const synthesized = synthesizeLegacyNoteContent(scope, subjectId);
5655
+ if (!synthesized) return null;
5656
+ const db2 = getSQLiteDb();
5657
+ const now = (/* @__PURE__ */ new Date()).toISOString();
5658
+ const id = (0, import_crypto3.randomUUID)();
5659
+ db2.prepare(
5660
+ `INSERT INTO knowledge_notes (
5661
+ id, scope, subject_id, content, change_summary, source_type, source_id, metadata, version, created_at, updated_at
5662
+ ) VALUES (?, ?, ?, ?, ?, 'task_completion', 'legacy-synthesis', ?, 1, ?, ?)`
5663
+ ).run(
5664
+ id,
5665
+ scope,
5666
+ subjectId,
5667
+ synthesized,
5668
+ "Initial note synthesized from existing system knowledge",
5669
+ JSON.stringify({ synthesized_from_legacy: true }),
5670
+ now,
5671
+ now
5672
+ );
5673
+ db2.prepare(
5674
+ `INSERT INTO knowledge_note_versions (
5675
+ id, note_id, version, content, change_summary, source_type, source_id, metadata, created_at
5676
+ ) VALUES (?, ?, 1, ?, ?, 'task_completion', 'legacy-synthesis', ?, ?)`
5677
+ ).run(
5678
+ (0, import_crypto3.randomUUID)(),
5679
+ id,
5680
+ synthesized,
5681
+ "Initial note synthesized from existing system knowledge",
5682
+ JSON.stringify({ synthesized_from_legacy: true }),
5683
+ now
5684
+ );
5685
+ const created = getKnowledgeNoteRow(scope, subjectId);
5686
+ return created ? mapRow2(created) : null;
5687
+ }
5688
+ function getKnowledgeNote(scope, subjectId) {
5689
+ const trimmedSubjectId = subjectId.trim();
5690
+ if (!trimmedSubjectId) return null;
5691
+ return ensureKnowledgeNote(scope, trimmedSubjectId);
5692
+ }
5693
+ function upsertKnowledgeNote(input) {
5694
+ const db2 = getSQLiteDb();
5695
+ const subjectId = input.subjectId.trim();
5696
+ const sourceId = input.sourceId.trim();
5697
+ const content = normalizeContent(input.content);
5698
+ const changeSummary = input.changeSummary?.trim() || null;
5699
+ if (!subjectId || !sourceId) {
5700
+ throw new Error("subjectId and sourceId are required");
5701
+ }
5702
+ const existing = ensureKnowledgeNote(input.scope, subjectId);
5703
+ if (existing && normalizeContent(existing.content) === content) {
5704
+ return { note: existing, changed: false };
5705
+ }
5706
+ const now = (/* @__PURE__ */ new Date()).toISOString();
5707
+ const metadata = JSON.stringify(input.metadata ?? {});
5708
+ if (!existing) {
5709
+ const id = (0, import_crypto3.randomUUID)();
5710
+ db2.prepare(
5711
+ `INSERT INTO knowledge_notes (
5712
+ id, scope, subject_id, content, change_summary, source_type, source_id, metadata, version, created_at, updated_at
5713
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)`
5714
+ ).run(id, input.scope, subjectId, content, changeSummary, input.sourceType, sourceId, metadata, now, now);
5715
+ db2.prepare(
5716
+ `INSERT INTO knowledge_note_versions (
5717
+ id, note_id, version, content, change_summary, source_type, source_id, metadata, created_at
5718
+ ) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?)`
5719
+ ).run((0, import_crypto3.randomUUID)(), id, content, changeSummary, input.sourceType, sourceId, metadata, now);
5720
+ const created = getKnowledgeNote(input.scope, subjectId);
5721
+ if (!created) throw new Error("Failed to read created knowledge note");
5722
+ return { note: created, changed: true };
5723
+ }
5724
+ const nextVersion = existing.version + 1;
5725
+ db2.prepare(
5726
+ `UPDATE knowledge_notes
5727
+ SET content = ?, change_summary = ?, source_type = ?, source_id = ?, metadata = ?, version = ?, updated_at = ?
5728
+ WHERE id = ?`
5729
+ ).run(content, changeSummary, input.sourceType, sourceId, metadata, nextVersion, now, existing.id);
5730
+ db2.prepare(
5731
+ `INSERT INTO knowledge_note_versions (
5732
+ id, note_id, version, content, change_summary, source_type, source_id, metadata, created_at
5733
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
5734
+ ).run((0, import_crypto3.randomUUID)(), existing.id, nextVersion, content, changeSummary, input.sourceType, sourceId, metadata, now);
5735
+ const updated = getKnowledgeNote(input.scope, subjectId);
5736
+ if (!updated) throw new Error("Failed to read updated knowledge note");
5737
+ return { note: updated, changed: true };
5738
+ }
5739
+
5740
+ // ../agx-cloud/lib/memory-extractor.ts
5109
5741
  var VALID_TYPES = /* @__PURE__ */ new Set(["outcome", "decision", "pattern", "gotcha"]);
5110
5742
  var EXTRACTION_PROMPT = `You are a memory extractor for a task execution system.
5111
5743
  Given a completed task, extract 0-3 memories worth remembering for future tasks.
@@ -5120,24 +5752,28 @@ Each memory must be:
5120
5752
 
5121
5753
  Return ONLY a JSON array. Return [] if nothing worth remembering.
5122
5754
  Do not wrap in markdown code blocks. Just raw JSON.`;
5123
- var PROJECT_KNOWLEDGE_PROMPT = `You are a project knowledge extractor for a task execution system.
5124
- Given a completed or failed task, extract 0-2 concise project-scoped knowledge entries worth keeping.
5125
-
5126
- Each entry must be:
5127
- { "content": "one concise sentence" }
5755
+ var PROJECT_KNOWLEDGE_PROMPT = `You are maintaining a living project knowledge note for a task execution system.
5756
+ Given the current project note and a completed or failed task, decide whether the note should change.
5128
5757
 
5129
- Only include information that is likely useful across future work in the same project:
5130
- - workflows, conventions, recurring constraints
5131
- - stable gotchas or environment realities
5132
- - reusable project-specific practices
5133
-
5134
- Do not include:
5135
- - repo-specific durable truths that belong in repo knowledge
5136
- - one-off task status updates
5137
- - vague summaries
5758
+ Return ONLY a JSON object:
5759
+ {
5760
+ "updated_note": "full revised note in concise markdown",
5761
+ "change_summary": "short summary of what changed",
5762
+ "no_change": false
5763
+ }
5138
5764
 
5139
- Return ONLY a JSON array. Return [] if nothing project-scoped is worth keeping.
5140
- Do not wrap in markdown code blocks. Just raw JSON.`;
5765
+ Rules:
5766
+ - Revise the current note instead of appending isolated bullets.
5767
+ - Write like a person's living project notes, not an extracted fact list.
5768
+ - The note should help someone understand what the project is, what it does, what has been decided, and what lessons now shape future work.
5769
+ - Prefer short sections and narrative paragraphs in markdown. Bullets are fine only when they genuinely improve clarity.
5770
+ - Preserve strong existing content when still valid.
5771
+ - Merge duplicate ideas, sharpen wording, and remove stale or unsupported claims.
5772
+ - Only include project-scoped knowledge likely useful across future work in the same project.
5773
+ - Do not include repo-specific durable truths that belong in repo knowledge.
5774
+ - Avoid generic filler and avoid sounding like an audit log.
5775
+ - If nothing project-scoped changed, return {"no_change": true}.
5776
+ - Do not wrap in markdown code blocks. Just raw JSON.`;
5141
5777
  async function extractMemories(ctx) {
5142
5778
  const taskDescription = [
5143
5779
  `Goal: ${ctx.goal}`,
@@ -5183,18 +5819,16 @@ function parseProjectKnowledgeResponse(raw) {
5183
5819
  const cleaned = trimmed.replace(/^```(?:json)?\s*/i, "").replace(/\s*```\s*$/, "").trim();
5184
5820
  try {
5185
5821
  const parsed = JSON.parse(cleaned);
5186
- if (!Array.isArray(parsed)) return [];
5187
- const unique = /* @__PURE__ */ new Set();
5188
- const result = [];
5189
- for (const entry of parsed) {
5190
- const content = typeof entry === "object" && entry !== null && typeof entry.content === "string" ? entry.content.trim() : "";
5191
- if (!content) continue;
5192
- if (unique.has(content)) continue;
5193
- unique.add(content);
5194
- result.push({ content });
5195
- if (result.length >= 2) break;
5196
- }
5197
- return result;
5822
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return [];
5823
+ const updatedNote = typeof parsed.updated_note === "string" ? parsed.updated_note.trim() : "";
5824
+ const noChange = Boolean(parsed.no_change);
5825
+ if (noChange) return [];
5826
+ if (!updatedNote) return [];
5827
+ return [{
5828
+ updated_note: updatedNote,
5829
+ change_summary: typeof parsed.change_summary === "string" ? parsed.change_summary.trim() : void 0,
5830
+ no_change: false
5831
+ }];
5198
5832
  } catch {
5199
5833
  console.warn("[project-knowledge] Failed to parse LLM response:", cleaned.slice(0, 200));
5200
5834
  return [];
@@ -5235,10 +5869,26 @@ async function storeMemories(taskId, agentId, memories) {
5235
5869
  const now = Date.now();
5236
5870
  for (const mem of memories) {
5237
5871
  if (!VALID_TYPES_SET.has(mem.memory_type) || !mem.content?.trim()) continue;
5238
- const contentHash = (0, import_crypto2.createHash)("sha256").update(mem.content.trim()).digest("hex");
5239
- const result = stmt.run((0, import_crypto2.randomUUID)(), agentId, taskId, mem.memory_type, mem.content.trim(), contentHash, now);
5872
+ const contentHash = (0, import_crypto4.createHash)("sha256").update(mem.content.trim()).digest("hex");
5873
+ const result = stmt.run((0, import_crypto4.randomUUID)(), agentId, taskId, mem.memory_type, mem.content.trim(), contentHash, now);
5240
5874
  if (result.changes > 0) inserted++;
5241
5875
  }
5876
+ if (inserted > 0) {
5877
+ storeKnowledgeEntries(
5878
+ memories.map((mem) => ({
5879
+ scope: "agent",
5880
+ subjectId: agentId,
5881
+ sourceType: "task_completion",
5882
+ sourceId: taskId,
5883
+ kind: mem.memory_type,
5884
+ title: mem.content.trim().slice(0, 80),
5885
+ body: mem.content.trim(),
5886
+ confidence: 0.7,
5887
+ durability: 0.6,
5888
+ metadata: { task_id: taskId }
5889
+ }))
5890
+ );
5891
+ }
5242
5892
  return inserted;
5243
5893
  }
5244
5894
  async function extractAndStoreMemories(taskId, agentId, ctx) {
@@ -5259,7 +5909,7 @@ async function resolveProjectId(projectIdOrSlug) {
5259
5909
  const project = db2.prepare("SELECT id FROM projects WHERE slug = ? LIMIT 1").get(explicit);
5260
5910
  return project?.id ?? null;
5261
5911
  }
5262
- async function extractProjectKnowledge(ctx) {
5912
+ async function extractProjectKnowledge(ctx, currentNote) {
5263
5913
  const taskDescription = [
5264
5914
  `Goal: ${ctx.goal}`,
5265
5915
  `Status: ${ctx.status}`,
@@ -5267,6 +5917,9 @@ async function extractProjectKnowledge(ctx) {
5267
5917
  ].filter(Boolean).join("\n");
5268
5918
  const prompt = `${PROJECT_KNOWLEDGE_PROMPT}
5269
5919
 
5920
+ Current note:
5921
+ ${currentNote || "(empty)"}
5922
+
5270
5923
  Task:
5271
5924
  ${taskDescription}`;
5272
5925
  let raw = "";
@@ -5287,29 +5940,23 @@ ${taskDescription}`;
5287
5940
  }
5288
5941
  async function storeProjectKnowledge(projectId, taskId, entries) {
5289
5942
  if (entries.length === 0) return 0;
5290
- const db2 = getSQLiteDb();
5291
- const existingContents = new Set(
5292
- db2.prepare("SELECT content FROM project_memory WHERE project_id = ? AND producer = 'system'").all(projectId).map((row) => row.content.trim())
5293
- );
5294
- const insert = db2.prepare(
5295
- `INSERT INTO project_memory (id, project_id, content, source, producer, created_at)
5296
- VALUES (?, ?, ?, ?, 'system', ?)`
5297
- );
5298
- let inserted = 0;
5299
- const now = (/* @__PURE__ */ new Date()).toISOString();
5300
- for (const entry of entries) {
5301
- const content = entry.content.trim();
5302
- if (!content || existingContents.has(content)) continue;
5303
- insert.run((0, import_crypto2.randomUUID)(), projectId, content, `task:${taskId}`, now);
5304
- existingContents.add(content);
5305
- inserted++;
5306
- }
5307
- return inserted;
5943
+ const entry = entries[0];
5944
+ if (!entry || !entry.updated_note?.trim()) return 0;
5945
+ const result = upsertKnowledgeNote({
5946
+ scope: "project",
5947
+ subjectId: projectId,
5948
+ content: entry.updated_note.trim(),
5949
+ changeSummary: entry.change_summary,
5950
+ sourceType: "task_completion",
5951
+ sourceId: taskId,
5952
+ metadata: { task_id: taskId }
5953
+ });
5954
+ return result.changed ? 1 : 0;
5308
5955
  }
5309
5956
  async function extractAndStoreProjectKnowledge(taskId, projectIdOrSlug, ctx) {
5310
5957
  const projectId = await resolveProjectId(projectIdOrSlug);
5311
5958
  if (!projectId) return;
5312
- const knowledge = await extractProjectKnowledge(ctx);
5959
+ const knowledge = await extractProjectKnowledge(ctx, getKnowledgeNote("project", projectId)?.content ?? "");
5313
5960
  if (knowledge.length === 0) return;
5314
5961
  const inserted = await storeProjectKnowledge(projectId, taskId, knowledge);
5315
5962
  if (inserted > 0) {
@@ -5845,18 +6492,2164 @@ async function handleCancel(taskId, userId, reason) {
5845
6492
  await markCancelledActivity({ taskId, reason, userId });
5846
6493
  }
5847
6494
 
5848
- // ../agx-cloud/worker/index.ts
5849
- async function main() {
5850
- const requestedWorkers = Number(process.env.AGX_WORKER_COUNT) || 1;
5851
- assertWorkerCount(requestedWorkers);
5852
- console.log(`[worker] Starting SQLite worker (${requestedWorkers}/${MAX_WORKERS} max)...`);
5853
- const queue2 = await getQueue();
5854
- await queue2.work(
5855
- QUEUE_NAMES.TASK_PROCESS,
5856
- taskProcessor,
5857
- { batchSize: 5 }
6495
+ // ../agx-cloud/lib/stream-multiplexer.ts
6496
+ var import_promises = require("fs/promises");
6497
+
6498
+ // ../agx-cloud/lib/agent-process-registry.ts
6499
+ var import_better_sqlite34 = __toESM(require_lib());
6500
+ var import_path9 = __toESM(require("path"));
6501
+ var import_os9 = __toESM(require("os"));
6502
+ var import_fs9 = require("fs");
6503
+ var HISTORY_DIR = process.env.AGX_GROUP_CHAT_DIR?.trim() || import_path9.default.join(import_os9.default.homedir(), ".agx", "group-chat");
6504
+ var DB_PATH2 = import_path9.default.join(HISTORY_DIR, "history.sqlite");
6505
+ function toEntry(row) {
6506
+ return {
6507
+ id: row.id,
6508
+ workspaceId: row.workspace_id,
6509
+ threadId: row.thread_id,
6510
+ agentId: row.agent_id,
6511
+ pid: row.pid,
6512
+ state: row.state,
6513
+ sinceMessageId: row.since_message_id,
6514
+ responseMessageId: row.response_message_id || "",
6515
+ startedAt: row.started_at,
6516
+ lastActivity: row.last_activity,
6517
+ projectSlug: row.project_slug || ""
6518
+ };
6519
+ }
6520
+ function getDb2() {
6521
+ (0, import_fs9.mkdirSync)(HISTORY_DIR, { recursive: true });
6522
+ const db2 = new import_better_sqlite34.default(DB_PATH2);
6523
+ db2.pragma("journal_mode = WAL");
6524
+ db2.exec(`
6525
+ CREATE TABLE IF NOT EXISTS agent_processes (
6526
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6527
+ workspace_id TEXT NOT NULL,
6528
+ thread_id TEXT NOT NULL DEFAULT '',
6529
+ agent_id TEXT NOT NULL,
6530
+ pid INTEGER NOT NULL DEFAULT 0,
6531
+ state TEXT NOT NULL DEFAULT 'spawning',
6532
+ since_message_id TEXT NOT NULL DEFAULT '',
6533
+ started_at INTEGER NOT NULL,
6534
+ last_activity INTEGER NOT NULL,
6535
+ project_slug TEXT NOT NULL DEFAULT '',
6536
+ UNIQUE (workspace_id, agent_id)
6537
+ )
6538
+ `);
6539
+ db2.exec("CREATE INDEX IF NOT EXISTS idx_agent_processes_state ON agent_processes (state)");
6540
+ db2.exec("CREATE INDEX IF NOT EXISTS idx_agent_processes_thread ON agent_processes (thread_id)");
6541
+ db2.exec("CREATE INDEX IF NOT EXISTS idx_agent_processes_workspace ON agent_processes (workspace_id)");
6542
+ try {
6543
+ db2.exec("ALTER TABLE agent_processes ADD COLUMN project_slug TEXT NOT NULL DEFAULT ''");
6544
+ } catch {
6545
+ }
6546
+ try {
6547
+ db2.exec("ALTER TABLE agent_processes ADD COLUMN response_message_id TEXT NOT NULL DEFAULT ''");
6548
+ } catch {
6549
+ }
6550
+ return db2;
6551
+ }
6552
+ function withDb(fn) {
6553
+ const db2 = getDb2();
6554
+ try {
6555
+ return fn(db2);
6556
+ } finally {
6557
+ db2.close();
6558
+ }
6559
+ }
6560
+ function register(entry) {
6561
+ return withDb((db2) => {
6562
+ const result = db2.prepare(
6563
+ `INSERT INTO agent_processes (workspace_id, thread_id, agent_id, pid, state, since_message_id, response_message_id, started_at, last_activity, project_slug)
6564
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
6565
+ ON CONFLICT(workspace_id, agent_id)
6566
+ DO UPDATE SET
6567
+ thread_id = excluded.thread_id,
6568
+ pid = excluded.pid,
6569
+ state = excluded.state,
6570
+ since_message_id = excluded.since_message_id,
6571
+ response_message_id = excluded.response_message_id,
6572
+ started_at = excluded.started_at,
6573
+ last_activity = excluded.last_activity,
6574
+ project_slug = excluded.project_slug`
6575
+ ).run(
6576
+ entry.workspaceId,
6577
+ entry.threadId,
6578
+ entry.agentId,
6579
+ entry.pid,
6580
+ entry.state,
6581
+ entry.sinceMessageId,
6582
+ entry.responseMessageId || "",
6583
+ entry.startedAt,
6584
+ entry.lastActivity,
6585
+ entry.projectSlug || ""
6586
+ );
6587
+ if (result.changes === 1 && result.lastInsertRowid) {
6588
+ return Number(result.lastInsertRowid);
6589
+ }
6590
+ const row = db2.prepare(
6591
+ "SELECT id FROM agent_processes WHERE workspace_id = ? AND agent_id = ?"
6592
+ ).get(entry.workspaceId, entry.agentId);
6593
+ return row?.id ?? 0;
6594
+ });
6595
+ }
6596
+ function update(workspaceId, agentId, patch) {
6597
+ const sets = [];
6598
+ const values = [];
6599
+ if (patch.state !== void 0) {
6600
+ sets.push("state = ?");
6601
+ values.push(patch.state);
6602
+ }
6603
+ if (patch.lastActivity !== void 0) {
6604
+ sets.push("last_activity = ?");
6605
+ values.push(patch.lastActivity);
6606
+ }
6607
+ if (patch.pid !== void 0) {
6608
+ sets.push("pid = ?");
6609
+ values.push(patch.pid);
6610
+ }
6611
+ if (sets.length === 0) return;
6612
+ withDb(
6613
+ (db2) => db2.prepare(
6614
+ `UPDATE agent_processes SET ${sets.join(", ")} WHERE workspace_id = ? AND agent_id = ?`
6615
+ ).run(...values, workspaceId, agentId)
6616
+ );
6617
+ }
6618
+ function getByThread(threadId) {
6619
+ return withDb((db2) => {
6620
+ const rows = db2.prepare("SELECT * FROM agent_processes WHERE thread_id = ?").all(threadId);
6621
+ return rows.map(toEntry);
6622
+ });
6623
+ }
6624
+ function getByWorkspace(workspaceId) {
6625
+ return withDb((db2) => {
6626
+ const rows = db2.prepare("SELECT * FROM agent_processes WHERE workspace_id = ?").all(workspaceId);
6627
+ return rows.map(toEntry);
6628
+ });
6629
+ }
6630
+ function killEntries(entries) {
6631
+ let killed = 0;
6632
+ for (const entry of entries) {
6633
+ if (entry.pid > 0) {
6634
+ try {
6635
+ process.kill(entry.pid, "SIGTERM");
6636
+ } catch {
6637
+ }
6638
+ }
6639
+ killed++;
6640
+ }
6641
+ return killed;
6642
+ }
6643
+ function killByThread(threadId) {
6644
+ const entries = getByThread(threadId).filter(
6645
+ (e) => e.state === "running" || e.state === "spawning"
6646
+ );
6647
+ const killed = killEntries(entries);
6648
+ if (killed > 0) {
6649
+ withDb(
6650
+ (db2) => db2.prepare(
6651
+ `UPDATE agent_processes SET state = 'killed', last_activity = ?
6652
+ WHERE thread_id = ? AND state IN ('running', 'spawning')`
6653
+ ).run(Date.now(), threadId)
6654
+ );
6655
+ }
6656
+ return killed;
6657
+ }
6658
+ function killByWorkspace(workspaceId) {
6659
+ const entries = getByWorkspace(workspaceId).filter(
6660
+ (e) => e.state === "running" || e.state === "spawning"
6661
+ );
6662
+ const killed = killEntries(entries);
6663
+ if (killed > 0) {
6664
+ withDb(
6665
+ (db2) => db2.prepare(
6666
+ `UPDATE agent_processes SET state = 'killed', last_activity = ?
6667
+ WHERE workspace_id = ? AND state IN ('running', 'spawning')`
6668
+ ).run(Date.now(), workspaceId)
6669
+ );
6670
+ }
6671
+ return killed;
6672
+ }
6673
+
6674
+ // ../agx-cloud/lib/history-store.ts
6675
+ var import_better_sqlite35 = __toESM(require_lib());
6676
+ var import_fs10 = require("fs");
6677
+ var import_path10 = __toESM(require("path"));
6678
+ var import_os10 = __toESM(require("os"));
6679
+ var HISTORY_DIR2 = process.env.AGX_GROUP_CHAT_DIR?.trim() || import_path10.default.join(import_os10.default.homedir(), ".agx", "group-chat");
6680
+ var DB_PATH3 = import_path10.default.join(HISTORY_DIR2, "history.sqlite");
6681
+ var LEGACY_THREAD_ID = "global";
6682
+ var REACTION_TYPES = /* @__PURE__ */ new Set([
6683
+ "ack",
6684
+ "working",
6685
+ "done",
6686
+ "clarify",
6687
+ "blocked"
6688
+ ]);
6689
+ var ALLOWED_TRANSITIONS = {
6690
+ ack: /* @__PURE__ */ new Set(["ack", "working"]),
6691
+ working: /* @__PURE__ */ new Set(["ack", "working", "done", "clarify", "blocked"]),
6692
+ done: /* @__PURE__ */ new Set(["done", "ack", "working"]),
6693
+ clarify: /* @__PURE__ */ new Set(["ack", "clarify", "working"]),
6694
+ blocked: /* @__PURE__ */ new Set(["ack", "blocked", "working"])
6695
+ };
6696
+ var ReactionStoreError = class extends Error {
6697
+ status;
6698
+ constructor(message, status) {
6699
+ super(message);
6700
+ this.name = "ReactionStoreError";
6701
+ this.status = status;
6702
+ }
6703
+ };
6704
+ function hasSqliteObject(db2, type, name) {
6705
+ const row = db2.prepare(`SELECT 1 FROM sqlite_master WHERE type = ? AND name = ? LIMIT 1`).get(type, name);
6706
+ return Boolean(row);
6707
+ }
6708
+ function initializeMessageSearch(db2) {
6709
+ const hasFtsTable = hasSqliteObject(db2, "table", "messages_fts");
6710
+ db2.exec(`
6711
+ CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(
6712
+ content,
6713
+ content='messages',
6714
+ content_rowid='rowid',
6715
+ tokenize='porter unicode61'
6716
+ );
6717
+ `);
6718
+ db2.exec(`
6719
+ CREATE TRIGGER IF NOT EXISTS messages_ai AFTER INSERT ON messages BEGIN
6720
+ INSERT INTO messages_fts(rowid, content) VALUES (new.rowid, new.content);
6721
+ END;
6722
+ CREATE TRIGGER IF NOT EXISTS messages_ad AFTER DELETE ON messages BEGIN
6723
+ INSERT INTO messages_fts(messages_fts, rowid, content) VALUES('delete', old.rowid, old.content);
6724
+ END;
6725
+ CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE OF content ON messages BEGIN
6726
+ INSERT INTO messages_fts(messages_fts, rowid, content) VALUES('delete', old.rowid, old.content);
6727
+ INSERT INTO messages_fts(rowid, content) VALUES (new.rowid, new.content);
6728
+ END;
6729
+ `);
6730
+ const messageCount = db2.prepare(`SELECT COUNT(*) as count FROM messages`).get().count;
6731
+ if (messageCount === 0) return;
6732
+ const ftsCount = db2.prepare(`SELECT COUNT(*) as count FROM messages_fts`).get().count;
6733
+ const shouldBackfill = !hasFtsTable || ftsCount === 0;
6734
+ if (shouldBackfill) {
6735
+ db2.exec(`INSERT INTO messages_fts(rowid, content) SELECT rowid, content FROM messages;`);
6736
+ }
6737
+ }
6738
+ function isThreadScopedTable(db2, tableName) {
6739
+ const columns = db2.prepare(`PRAGMA table_info(${tableName})`).all();
6740
+ return columns.some((column) => column.name === "thread_id");
6741
+ }
6742
+ function migrateThreadReplyColumns(db2) {
6743
+ const columns = db2.prepare(`PRAGMA table_info(messages)`).all();
6744
+ const colNames = new Set(columns.map((c) => c.name));
6745
+ if (!colNames.has("root_message_id")) {
6746
+ db2.exec(`
6747
+ ALTER TABLE messages ADD COLUMN root_message_id TEXT;
6748
+ ALTER TABLE messages ADD COLUMN parent_message_id TEXT;
6749
+ ALTER TABLE messages ADD COLUMN depth INTEGER NOT NULL DEFAULT 0;
6750
+ CREATE INDEX IF NOT EXISTS idx_messages_root ON messages(thread_id, root_message_id);
6751
+ `);
6752
+ }
6753
+ }
6754
+ function migrateThreadStatusColumns(db2) {
6755
+ const columns = db2.prepare(`PRAGMA table_info(messages)`).all();
6756
+ const colNames = new Set(columns.map((c) => c.name));
6757
+ if (!colNames.has("thread_status")) {
6758
+ db2.exec(`
6759
+ ALTER TABLE messages ADD COLUMN thread_status TEXT;
6760
+ ALTER TABLE messages ADD COLUMN outcome_note TEXT;
6761
+ `);
6762
+ }
6763
+ }
6764
+ function migrateReactionHostPidColumn(db2) {
6765
+ const columns = db2.prepare(`PRAGMA table_info(message_reactions)`).all();
6766
+ const colNames = new Set(columns.map((c) => c.name));
6767
+ if (!colNames.has("host_pid")) {
6768
+ db2.exec(`ALTER TABLE message_reactions ADD COLUMN host_pid INTEGER`);
6769
+ }
6770
+ if (!colNames.has("response_message_id")) {
6771
+ db2.exec(`ALTER TABLE message_reactions ADD COLUMN response_message_id TEXT`);
6772
+ }
6773
+ }
6774
+ function migrateLogsToAgentProcessId(db2) {
6775
+ const columns = db2.prepare(`PRAGMA table_info(logs)`).all();
6776
+ const colNames = new Set(columns.map((c) => c.name));
6777
+ if (colNames.has("agent_process_id")) return;
6778
+ db2.exec(`
6779
+ DROP TABLE IF EXISTS logs;
6780
+ CREATE TABLE logs (
6781
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6782
+ agent_process_id INTEGER NOT NULL,
6783
+ stream TEXT NOT NULL,
6784
+ line TEXT NOT NULL,
6785
+ timestamp INTEGER NOT NULL
6786
+ );
6787
+ `);
6788
+ }
6789
+ function migrateAgentProcessesAddId(db2) {
6790
+ const columns = db2.prepare(`PRAGMA table_info(agent_processes)`).all();
6791
+ if (columns.length === 0) return;
6792
+ const colNames = new Set(columns.map((c) => c.name));
6793
+ if (colNames.has("id")) return;
6794
+ db2.exec(`
6795
+ DROP TABLE IF EXISTS agent_processes;
6796
+ CREATE TABLE agent_processes (
6797
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6798
+ workspace_id TEXT NOT NULL,
6799
+ thread_id TEXT NOT NULL DEFAULT '',
6800
+ agent_id TEXT NOT NULL,
6801
+ pid INTEGER NOT NULL DEFAULT 0,
6802
+ state TEXT NOT NULL DEFAULT 'spawning',
6803
+ since_message_id TEXT NOT NULL DEFAULT '',
6804
+ started_at INTEGER NOT NULL DEFAULT 0,
6805
+ last_activity INTEGER NOT NULL DEFAULT 0,
6806
+ project_slug TEXT NOT NULL DEFAULT '',
6807
+ UNIQUE (workspace_id, agent_id)
6808
+ );
6809
+ CREATE INDEX IF NOT EXISTS idx_agent_processes_state ON agent_processes (state);
6810
+ CREATE INDEX IF NOT EXISTS idx_agent_processes_thread ON agent_processes (thread_id);
6811
+ CREATE INDEX IF NOT EXISTS idx_agent_processes_workspace ON agent_processes (workspace_id);
6812
+ `);
6813
+ }
6814
+ function parseJsonObject3(value) {
6815
+ if (!value) return null;
6816
+ try {
6817
+ const parsed = JSON.parse(value);
6818
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
6819
+ } catch {
6820
+ return null;
6821
+ }
6822
+ }
6823
+ function parseJsonStringArray(value) {
6824
+ if (!value) return [];
6825
+ try {
6826
+ const parsed = JSON.parse(value);
6827
+ return Array.isArray(parsed) ? parsed.filter((item) => typeof item === "string") : [];
6828
+ } catch {
6829
+ return [];
6830
+ }
6831
+ }
6832
+ function toChatRunRecord(row) {
6833
+ return {
6834
+ id: row.id,
6835
+ threadId: row.thread_id,
6836
+ rootMessageId: row.root_message_id,
6837
+ userId: row.user_id,
6838
+ projectSlug: row.project_slug,
6839
+ status: row.status,
6840
+ currentStep: row.current_step,
6841
+ maxSteps: row.max_steps,
6842
+ stepsUsed: row.steps_used,
6843
+ lastError: row.last_error,
6844
+ activeParticipantIds: parseJsonStringArray(row.active_participant_ids),
6845
+ payload: parseJsonObject3(row.payload_json),
6846
+ result: parseJsonObject3(row.result_json),
6847
+ createdAt: row.created_at,
6848
+ updatedAt: row.updated_at,
6849
+ completedAt: row.completed_at
6850
+ };
6851
+ }
6852
+ function toChatRunStepRecord(row) {
6853
+ return {
6854
+ id: row.id,
6855
+ chatRunId: row.chat_run_id,
6856
+ stepIndex: row.step_index,
6857
+ kind: row.kind,
6858
+ status: row.status,
6859
+ participantId: row.participant_id,
6860
+ inputPayload: parseJsonObject3(row.input_payload_json),
6861
+ outputPayload: parseJsonObject3(row.output_payload_json),
6862
+ startedAt: row.started_at,
6863
+ completedAt: row.completed_at
6864
+ };
6865
+ }
6866
+ function migrateLegacyTables(db2) {
6867
+ if (!isThreadScopedTable(db2, "messages")) {
6868
+ db2.exec(`
6869
+ ALTER TABLE messages RENAME TO messages_legacy;
6870
+ CREATE TABLE messages (
6871
+ thread_id TEXT NOT NULL,
6872
+ id TEXT NOT NULL,
6873
+ role TEXT NOT NULL,
6874
+ participant_id TEXT,
6875
+ content TEXT NOT NULL,
6876
+ timestamp INTEGER NOT NULL,
6877
+ PRIMARY KEY (thread_id, id)
6878
+ );
6879
+ INSERT INTO messages (thread_id, id, role, participant_id, content, timestamp)
6880
+ SELECT '${LEGACY_THREAD_ID}', id, role, participant_id, content, timestamp
6881
+ FROM messages_legacy;
6882
+ DROP TABLE messages_legacy;
6883
+ `);
6884
+ }
6885
+ if (!isThreadScopedTable(db2, "message_reactions")) {
6886
+ db2.exec(`
6887
+ ALTER TABLE message_reactions RENAME TO message_reactions_legacy;
6888
+ CREATE TABLE message_reactions (
6889
+ thread_id TEXT NOT NULL,
6890
+ message_id TEXT NOT NULL,
6891
+ participant_id TEXT NOT NULL,
6892
+ type TEXT NOT NULL,
6893
+ reason TEXT,
6894
+ blocker_code TEXT,
6895
+ host_pid INTEGER,
6896
+ response_message_id TEXT,
6897
+ updated_at INTEGER NOT NULL,
6898
+ PRIMARY KEY (thread_id, message_id, participant_id)
6899
+ );
6900
+ INSERT INTO message_reactions (thread_id, message_id, participant_id, type, reason, blocker_code, host_pid, updated_at)
6901
+ SELECT '${LEGACY_THREAD_ID}', message_id, participant_id, type, reason, blocker_code, NULL, updated_at
6902
+ FROM message_reactions_legacy;
6903
+ DROP TABLE message_reactions_legacy;
6904
+ `);
6905
+ }
6906
+ migrateLogsToAgentProcessId(db2);
6907
+ }
6908
+ var withDatabase = async (run) => {
6909
+ await import_fs10.promises.mkdir(HISTORY_DIR2, { recursive: true });
6910
+ const db2 = new import_better_sqlite35.default(DB_PATH3);
6911
+ db2.pragma("journal_mode = WAL");
6912
+ try {
6913
+ db2.exec(`
6914
+ CREATE TABLE IF NOT EXISTS messages (
6915
+ thread_id TEXT NOT NULL,
6916
+ id TEXT NOT NULL,
6917
+ role TEXT NOT NULL,
6918
+ participant_id TEXT,
6919
+ content TEXT NOT NULL,
6920
+ timestamp INTEGER NOT NULL,
6921
+ PRIMARY KEY (thread_id, id)
6922
+ );
6923
+ CREATE TABLE IF NOT EXISTS message_reactions (
6924
+ thread_id TEXT NOT NULL,
6925
+ message_id TEXT NOT NULL,
6926
+ participant_id TEXT NOT NULL,
6927
+ type TEXT NOT NULL,
6928
+ reason TEXT,
6929
+ blocker_code TEXT,
6930
+ host_pid INTEGER,
6931
+ response_message_id TEXT,
6932
+ updated_at INTEGER NOT NULL,
6933
+ PRIMARY KEY (thread_id, message_id, participant_id)
6934
+ );
6935
+ CREATE TABLE IF NOT EXISTS agent_processes (
6936
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6937
+ workspace_id TEXT NOT NULL,
6938
+ thread_id TEXT NOT NULL DEFAULT '',
6939
+ agent_id TEXT NOT NULL,
6940
+ pid INTEGER NOT NULL DEFAULT 0,
6941
+ state TEXT NOT NULL DEFAULT 'spawning',
6942
+ since_message_id TEXT NOT NULL DEFAULT '',
6943
+ started_at INTEGER NOT NULL DEFAULT 0,
6944
+ last_activity INTEGER NOT NULL DEFAULT 0,
6945
+ project_slug TEXT NOT NULL DEFAULT '',
6946
+ UNIQUE (workspace_id, agent_id)
6947
+ );
6948
+ CREATE TABLE IF NOT EXISTS logs (
6949
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6950
+ agent_process_id INTEGER NOT NULL,
6951
+ stream TEXT NOT NULL,
6952
+ line TEXT NOT NULL,
6953
+ timestamp INTEGER NOT NULL
6954
+ );
6955
+ CREATE TABLE IF NOT EXISTS task_drafts (
6956
+ thread_id TEXT NOT NULL,
6957
+ message_id TEXT NOT NULL,
6958
+ data TEXT NOT NULL,
6959
+ updated_at INTEGER NOT NULL,
6960
+ PRIMARY KEY (thread_id, message_id)
6961
+ );
6962
+ CREATE TABLE IF NOT EXISTS chat_runs (
6963
+ id TEXT PRIMARY KEY,
6964
+ thread_id TEXT NOT NULL,
6965
+ root_message_id TEXT,
6966
+ user_id TEXT NOT NULL,
6967
+ project_slug TEXT,
6968
+ status TEXT NOT NULL,
6969
+ current_step INTEGER NOT NULL DEFAULT 0,
6970
+ max_steps INTEGER NOT NULL DEFAULT 10,
6971
+ steps_used INTEGER NOT NULL DEFAULT 0,
6972
+ last_error TEXT,
6973
+ active_participant_ids TEXT NOT NULL DEFAULT '[]',
6974
+ payload_json TEXT,
6975
+ result_json TEXT,
6976
+ created_at INTEGER NOT NULL,
6977
+ updated_at INTEGER NOT NULL,
6978
+ completed_at INTEGER
6979
+ );
6980
+ CREATE TABLE IF NOT EXISTS chat_run_steps (
6981
+ id TEXT PRIMARY KEY,
6982
+ chat_run_id TEXT NOT NULL,
6983
+ step_index INTEGER NOT NULL,
6984
+ kind TEXT NOT NULL,
6985
+ status TEXT NOT NULL,
6986
+ participant_id TEXT,
6987
+ input_payload_json TEXT,
6988
+ output_payload_json TEXT,
6989
+ started_at INTEGER NOT NULL,
6990
+ completed_at INTEGER
6991
+ );
6992
+ `);
6993
+ migrateLegacyTables(db2);
6994
+ migrateThreadReplyColumns(db2);
6995
+ migrateThreadStatusColumns(db2);
6996
+ migrateReactionHostPidColumn(db2);
6997
+ db2.exec("UPDATE messages SET thread_status = 'in-review' WHERE thread_status = 'parked'");
6998
+ db2.exec("UPDATE messages SET thread_status = 'active' WHERE thread_status = 'thinking'");
6999
+ db2.exec("UPDATE messages SET thread_status = 'done' WHERE thread_status = 'resolved'");
7000
+ db2.exec("UPDATE messages SET thread_status = 'active' WHERE thread_status = 'converged'");
7001
+ migrateAgentProcessesAddId(db2);
7002
+ initializeMessageSearch(db2);
7003
+ db2.exec(`
7004
+ CREATE INDEX IF NOT EXISTS idx_messages_thread_ts ON messages(thread_id, timestamp ASC);
7005
+ CREATE INDEX IF NOT EXISTS idx_reactions_thread_message ON message_reactions(thread_id, message_id, updated_at ASC);
7006
+ CREATE INDEX IF NOT EXISTS idx_logs_process_ts ON logs(agent_process_id, timestamp ASC);
7007
+ CREATE INDEX IF NOT EXISTS idx_chat_runs_thread_updated ON chat_runs(thread_id, updated_at DESC);
7008
+ CREATE INDEX IF NOT EXISTS idx_chat_runs_status_updated ON chat_runs(status, updated_at DESC);
7009
+ CREATE INDEX IF NOT EXISTS idx_chat_run_steps_run_step ON chat_run_steps(chat_run_id, step_index ASC);
7010
+ `);
7011
+ return run(db2);
7012
+ } finally {
7013
+ db2.close();
7014
+ }
7015
+ };
7016
+ function aggregateReactionRows(rows) {
7017
+ const perMessage = /* @__PURE__ */ new Map();
7018
+ for (const row of rows) {
7019
+ let byType = perMessage.get(row.message_id);
7020
+ if (!byType) {
7021
+ byType = /* @__PURE__ */ new Map();
7022
+ perMessage.set(row.message_id, byType);
7023
+ }
7024
+ let reaction = byType.get(row.type);
7025
+ if (!reaction) {
7026
+ reaction = { type: row.type, count: 0, participantIds: [] };
7027
+ byType.set(row.type, reaction);
7028
+ }
7029
+ reaction.count += 1;
7030
+ reaction.participantIds.push(row.participant_id);
7031
+ }
7032
+ const out = /* @__PURE__ */ new Map();
7033
+ for (const [messageId, byType] of perMessage.entries()) {
7034
+ const sorted = Array.from(byType.values()).sort((a, b) => {
7035
+ if (b.count !== a.count) return b.count - a.count;
7036
+ return a.type.localeCompare(b.type);
7037
+ });
7038
+ out.set(messageId, sorted);
7039
+ }
7040
+ return out;
7041
+ }
7042
+ function loadMessageReactions(db2, threadId, messageIds) {
7043
+ if (messageIds && messageIds.length === 0) return /* @__PURE__ */ new Map();
7044
+ if (messageIds) {
7045
+ const placeholders = messageIds.map(() => "?").join(", ");
7046
+ const rows2 = db2.prepare(
7047
+ `SELECT message_id, participant_id, type
7048
+ FROM message_reactions
7049
+ WHERE thread_id = ? AND message_id IN (${placeholders})
7050
+ ORDER BY updated_at ASC`
7051
+ ).all(threadId, ...messageIds);
7052
+ return aggregateReactionRows(rows2);
7053
+ }
7054
+ const rows = db2.prepare(
7055
+ `SELECT message_id, participant_id, type
7056
+ FROM message_reactions
7057
+ WHERE thread_id = ?
7058
+ ORDER BY updated_at ASC`
7059
+ ).all(threadId);
7060
+ return aggregateReactionRows(rows);
7061
+ }
7062
+ function normalizeOptionalText(value) {
7063
+ if (typeof value !== "string") return null;
7064
+ const trimmed = value.trim();
7065
+ return trimmed.length > 0 ? trimmed : null;
7066
+ }
7067
+ function normalizeOptionalHostPid(value) {
7068
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) return null;
7069
+ return value;
7070
+ }
7071
+ function isAllowedTransition(from, to) {
7072
+ if (!from) return true;
7073
+ return ALLOWED_TRANSITIONS[from].has(to);
7074
+ }
7075
+ async function saveMessages(threadId, messages) {
7076
+ if (messages.length === 0) return;
7077
+ const normalizedThreadId = threadId.trim() || LEGACY_THREAD_ID;
7078
+ await withDatabase((db2) => {
7079
+ const stmt = db2.prepare(
7080
+ `INSERT OR REPLACE INTO messages (thread_id, id, role, participant_id, content, timestamp, root_message_id, parent_message_id, depth, thread_status, outcome_note)
7081
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
7082
+ );
7083
+ const insertMany = db2.transaction((msgs) => {
7084
+ for (const m of msgs) {
7085
+ stmt.run(normalizedThreadId, m.id, m.role, m.participantId, m.content, m.timestamp, m.rootMessageId ?? null, m.parentMessageId ?? null, m.depth ?? 0, m.threadStatus ?? null, m.outcomeNote ?? null);
7086
+ }
7087
+ });
7088
+ insertMany(messages);
7089
+ });
7090
+ }
7091
+ async function getChatRun(chatRunId) {
7092
+ return withDatabase((db2) => {
7093
+ const row = db2.prepare("SELECT * FROM chat_runs WHERE id = ? LIMIT 1").get(chatRunId);
7094
+ return row ? toChatRunRecord(row) : null;
7095
+ });
7096
+ }
7097
+ async function updateChatRun(input) {
7098
+ return withDatabase((db2) => {
7099
+ const updates = ["updated_at = ?"];
7100
+ const params = [Date.now()];
7101
+ if (input.status) {
7102
+ updates.push("status = ?");
7103
+ params.push(input.status);
7104
+ }
7105
+ if (typeof input.currentStep === "number") {
7106
+ updates.push("current_step = ?");
7107
+ params.push(input.currentStep);
7108
+ }
7109
+ if (typeof input.stepsUsed === "number") {
7110
+ updates.push("steps_used = ?");
7111
+ params.push(input.stepsUsed);
7112
+ }
7113
+ if (input.lastError !== void 0) {
7114
+ updates.push("last_error = ?");
7115
+ params.push(normalizeOptionalText(input.lastError));
7116
+ }
7117
+ if (input.payload !== void 0) {
7118
+ updates.push("payload_json = ?");
7119
+ params.push(input.payload ? JSON.stringify(input.payload) : null);
7120
+ }
7121
+ if (input.result !== void 0) {
7122
+ updates.push("result_json = ?");
7123
+ params.push(input.result ? JSON.stringify(input.result) : null);
7124
+ }
7125
+ if (input.completedAt !== void 0) {
7126
+ updates.push("completed_at = ?");
7127
+ params.push(input.completedAt);
7128
+ }
7129
+ params.push(input.id);
7130
+ db2.prepare(`UPDATE chat_runs SET ${updates.join(", ")} WHERE id = ?`).run(...params);
7131
+ const row = db2.prepare("SELECT * FROM chat_runs WHERE id = ? LIMIT 1").get(input.id);
7132
+ return row ? toChatRunRecord(row) : null;
7133
+ });
7134
+ }
7135
+ async function appendChatRunStep(input) {
7136
+ const now = Date.now();
7137
+ return withDatabase((db2) => {
7138
+ db2.prepare(
7139
+ `INSERT INTO chat_run_steps (
7140
+ id, chat_run_id, step_index, kind, status, participant_id,
7141
+ input_payload_json, output_payload_json, started_at, completed_at
7142
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
7143
+ ).run(
7144
+ input.id,
7145
+ input.chatRunId,
7146
+ input.stepIndex,
7147
+ input.kind,
7148
+ input.status,
7149
+ normalizeOptionalText(input.participantId),
7150
+ input.inputPayload ? JSON.stringify(input.inputPayload) : null,
7151
+ input.outputPayload ? JSON.stringify(input.outputPayload) : null,
7152
+ now,
7153
+ input.status === "completed" || input.status === "failed" ? now : null
7154
+ );
7155
+ const row = db2.prepare("SELECT * FROM chat_run_steps WHERE id = ? LIMIT 1").get(input.id);
7156
+ if (!row) {
7157
+ throw new Error(`Failed to append chat run step ${input.id}`);
7158
+ }
7159
+ return toChatRunStepRecord(row);
7160
+ });
7161
+ }
7162
+ async function updateChatRunStep(input) {
7163
+ return withDatabase((db2) => {
7164
+ const updates = [];
7165
+ const params = [];
7166
+ if (input.status) {
7167
+ updates.push("status = ?");
7168
+ params.push(input.status);
7169
+ }
7170
+ if (input.outputPayload !== void 0) {
7171
+ updates.push("output_payload_json = ?");
7172
+ params.push(input.outputPayload ? JSON.stringify(input.outputPayload) : null);
7173
+ }
7174
+ if (input.completedAt !== void 0) {
7175
+ updates.push("completed_at = ?");
7176
+ params.push(input.completedAt);
7177
+ }
7178
+ if (updates.length === 0) {
7179
+ const existing = db2.prepare("SELECT * FROM chat_run_steps WHERE id = ? LIMIT 1").get(input.id);
7180
+ return existing ? toChatRunStepRecord(existing) : null;
7181
+ }
7182
+ params.push(input.id);
7183
+ db2.prepare(`UPDATE chat_run_steps SET ${updates.join(", ")} WHERE id = ?`).run(...params);
7184
+ const row = db2.prepare("SELECT * FROM chat_run_steps WHERE id = ? LIMIT 1").get(input.id);
7185
+ return row ? toChatRunStepRecord(row) : null;
7186
+ });
7187
+ }
7188
+ async function listChatRunSteps(chatRunId) {
7189
+ return withDatabase((db2) => {
7190
+ const rows = db2.prepare("SELECT * FROM chat_run_steps WHERE chat_run_id = ? ORDER BY step_index ASC, started_at ASC").all(chatRunId);
7191
+ return rows.map(toChatRunStepRecord);
7192
+ });
7193
+ }
7194
+ async function setReaction(input) {
7195
+ const threadId = input.threadId?.trim() || LEGACY_THREAD_ID;
7196
+ const messageId = input.messageId?.trim();
7197
+ const participantId = input.participantId?.trim();
7198
+ const type = input.type;
7199
+ if (!messageId) {
7200
+ throw new ReactionStoreError("messageId is required", 400);
7201
+ }
7202
+ if (!participantId) {
7203
+ throw new ReactionStoreError("participantId is required", 400);
7204
+ }
7205
+ if (!REACTION_TYPES.has(type)) {
7206
+ throw new ReactionStoreError(`Invalid reaction type: ${String(type)}`, 400);
7207
+ }
7208
+ const incomingReason = normalizeOptionalText(input.reason);
7209
+ const incomingBlockerCode = normalizeOptionalText(input.blockerCode);
7210
+ const hostPid = normalizeOptionalHostPid(input.hostPid);
7211
+ const responseMessageId = normalizeOptionalText(input.responseMessageId);
7212
+ const needsReason = type === "clarify" || type === "blocked";
7213
+ if (needsReason && !incomingReason) {
7214
+ throw new ReactionStoreError(`"${type}" reactions require a reason`, 400);
7215
+ }
7216
+ const reason = needsReason ? incomingReason : null;
7217
+ const blockerCode = type === "blocked" ? incomingBlockerCode : null;
7218
+ return withDatabase((db2) => {
7219
+ const messageExists = db2.prepare(`SELECT 1 FROM messages WHERE thread_id = ? AND id = ? LIMIT 1`).get(threadId, messageId);
7220
+ if (!messageExists) {
7221
+ throw new ReactionStoreError(`Message not found: ${messageId}`, 404);
7222
+ }
7223
+ const existing = db2.prepare(
7224
+ `SELECT type, reason, blocker_code, host_pid
7225
+ FROM message_reactions
7226
+ WHERE thread_id = ? AND message_id = ? AND participant_id = ?`
7227
+ ).get(threadId, messageId, participantId);
7228
+ if (!isAllowedTransition(existing?.type ?? null, type)) {
7229
+ throw new ReactionStoreError(
7230
+ `Cannot transition reaction from "${existing.type}" to "${type}"`,
7231
+ 409
7232
+ );
7233
+ }
7234
+ const unchanged = existing && existing.type === type && normalizeOptionalText(existing.reason) === reason && normalizeOptionalText(existing.blocker_code) === blockerCode && normalizeOptionalHostPid(existing.host_pid) === hostPid;
7235
+ if (unchanged) {
7236
+ return {
7237
+ updated: false,
7238
+ reactions: loadMessageReactions(db2, threadId, [messageId]).get(messageId) ?? []
7239
+ };
7240
+ }
7241
+ const now = Date.now();
7242
+ db2.prepare(
7243
+ `INSERT INTO message_reactions (thread_id, message_id, participant_id, type, reason, blocker_code, host_pid, response_message_id, updated_at)
7244
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
7245
+ ON CONFLICT(thread_id, message_id, participant_id)
7246
+ DO UPDATE SET
7247
+ type = excluded.type,
7248
+ reason = excluded.reason,
7249
+ blocker_code = excluded.blocker_code,
7250
+ host_pid = excluded.host_pid,
7251
+ response_message_id = COALESCE(excluded.response_message_id, message_reactions.response_message_id),
7252
+ updated_at = excluded.updated_at`
7253
+ ).run(threadId, messageId, participantId, type, reason, blockerCode, hostPid, responseMessageId, now);
7254
+ return {
7255
+ updated: true,
7256
+ reactions: loadMessageReactions(db2, threadId, [messageId]).get(messageId) ?? []
7257
+ };
7258
+ });
7259
+ }
7260
+ async function saveLogs(agentProcessId, entries) {
7261
+ if (entries.length === 0 || !agentProcessId) return;
7262
+ return withDatabase((db2) => {
7263
+ const stmt = db2.prepare(
7264
+ "INSERT INTO logs (agent_process_id, stream, line, timestamp) VALUES (?, ?, ?, ?)"
7265
+ );
7266
+ const tx = db2.transaction(() => {
7267
+ for (const e of entries) {
7268
+ stmt.run(agentProcessId, e.stream, e.line, e.timestamp);
7269
+ }
7270
+ });
7271
+ tx();
7272
+ });
7273
+ }
7274
+
7275
+ // ../agx-cloud/lib/reaction-protocol.ts
7276
+ var REACTION_TYPES2 = /* @__PURE__ */ new Set([
7277
+ "ack",
7278
+ "working",
7279
+ "done",
7280
+ "clarify",
7281
+ "blocked"
7282
+ ]);
7283
+ var TAG_REGEX = /\[reaction\s+([^\]]+)\]/gi;
7284
+ var ATTR_REGEX = /([a-zA-Z][a-zA-Z0-9_]*)=(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^\s\]]*?(?=\s|]|[a-zA-Z][a-zA-Z0-9_]*=|$)))/g;
7285
+ function decodeAttrValue(value) {
7286
+ return value.replace(/\\(["'\\])/g, "$1").trim();
7287
+ }
7288
+ function parseAttributes(raw) {
7289
+ const attrs = /* @__PURE__ */ new Map();
7290
+ ATTR_REGEX.lastIndex = 0;
7291
+ for (; ; ) {
7292
+ const match = ATTR_REGEX.exec(raw);
7293
+ if (!match) break;
7294
+ const key = match[1].toLowerCase();
7295
+ const quotedDouble = match[2];
7296
+ const quotedSingle = match[3];
7297
+ const bare = match[4];
7298
+ const value = decodeAttrValue(quotedDouble ?? quotedSingle ?? bare ?? "");
7299
+ attrs.set(key, value);
7300
+ }
7301
+ return attrs;
7302
+ }
7303
+ function parseReactionSignals(content) {
7304
+ const signals = [];
7305
+ const invalid = [];
7306
+ const cleanedText = content.replace(TAG_REGEX, (rawTag, attrsRaw) => {
7307
+ const attrs = parseAttributes(String(attrsRaw));
7308
+ const target = (attrs.get("target") || "").trim();
7309
+ const typeRaw = (attrs.get("type") || "").trim().toLowerCase();
7310
+ const reason = (attrs.get("reason") || "").trim();
7311
+ const blockerCode = (attrs.get("blockercode") || attrs.get("blocker_code") || "").trim();
7312
+ if (!target) {
7313
+ invalid.push({ raw: rawTag, error: "Missing target" });
7314
+ return "";
7315
+ }
7316
+ if (!REACTION_TYPES2.has(typeRaw)) {
7317
+ invalid.push({ raw: rawTag, error: `Invalid type: ${typeRaw || "(empty)"}` });
7318
+ return "";
7319
+ }
7320
+ const type = typeRaw;
7321
+ if ((type === "clarify" || type === "blocked") && !reason) {
7322
+ invalid.push({ raw: rawTag, error: `"${type}" requires reason` });
7323
+ return "";
7324
+ }
7325
+ signals.push({
7326
+ raw: rawTag,
7327
+ target,
7328
+ type,
7329
+ reason: reason || void 0,
7330
+ blockerCode: type === "blocked" ? blockerCode || void 0 : void 0
7331
+ });
7332
+ return "";
7333
+ }).replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
7334
+ return { signals, invalid, cleanedText };
7335
+ }
7336
+
7337
+ // ../agx-cloud/lib/attachment-store.ts
7338
+ var import_better_sqlite36 = __toESM(require_lib());
7339
+ var import_path11 = __toESM(require("path"));
7340
+ var import_os11 = __toESM(require("os"));
7341
+ var HISTORY_DIR3 = process.env.AGX_GROUP_CHAT_DIR?.trim() || import_path11.default.join(import_os11.default.homedir(), ".agx", "group-chat");
7342
+ var DB_PATH4 = import_path11.default.join(HISTORY_DIR3, "history.sqlite");
7343
+ var UPLOADS_DIR = import_path11.default.join(HISTORY_DIR3, "uploads");
7344
+ function getDb3() {
7345
+ const db2 = new import_better_sqlite36.default(DB_PATH4);
7346
+ db2.pragma("journal_mode = WAL");
7347
+ return db2;
7348
+ }
7349
+ function initAttachmentsTable(db2) {
7350
+ db2.exec(`
7351
+ CREATE TABLE IF NOT EXISTS attachments (
7352
+ id TEXT PRIMARY KEY,
7353
+ message_id TEXT,
7354
+ filename TEXT NOT NULL,
7355
+ disk_name TEXT NOT NULL,
7356
+ mime_type TEXT NOT NULL,
7357
+ size INTEGER NOT NULL,
7358
+ status TEXT NOT NULL DEFAULT 'uploaded',
7359
+ created_at INTEGER NOT NULL
7360
+ );
7361
+ CREATE INDEX IF NOT EXISTS idx_attachments_message ON attachments(message_id);
7362
+ `);
7363
+ const cols = db2.prepare("PRAGMA table_info(attachments)").all();
7364
+ if (!cols.some((c) => c.name === "disk_name")) {
7365
+ db2.exec(`ALTER TABLE attachments ADD COLUMN disk_name TEXT NOT NULL DEFAULT ''`);
7366
+ const rows = db2.prepare("SELECT id, filename FROM attachments WHERE disk_name = ''").all();
7367
+ const stmt = db2.prepare("UPDATE attachments SET disk_name = ? WHERE id = ?");
7368
+ for (const r of rows) {
7369
+ const ext = r.filename.includes(".") ? "." + r.filename.split(".").pop().toLowerCase() : "";
7370
+ stmt.run(r.id + ext, r.id);
7371
+ }
7372
+ }
7373
+ }
7374
+ async function getAttachmentMeta(id) {
7375
+ const db2 = getDb3();
7376
+ try {
7377
+ initAttachmentsTable(db2);
7378
+ const row = db2.prepare(
7379
+ `SELECT filename, disk_name, mime_type, size FROM attachments WHERE id = ?`
7380
+ ).get(id);
7381
+ if (!row) return null;
7382
+ const diskName = row.disk_name || id;
7383
+ return { filename: row.filename, mimeType: row.mime_type, size: row.size, diskPath: import_path11.default.join(UPLOADS_DIR, diskName) };
7384
+ } finally {
7385
+ db2.close();
7386
+ }
7387
+ }
7388
+
7389
+ // ../agx-cloud/lib/stream-multiplexer.ts
7390
+ init_sqlite_query_adapter();
7391
+ init_self();
7392
+ init_journal();
7393
+ init_agent();
7394
+
7395
+ // ../agx-cloud/lib/mesh-core/reactions.ts
7396
+ var import_fs11 = require("fs");
7397
+ var import_path12 = require("path");
7398
+ var import_os12 = require("os");
7399
+ init_journal();
7400
+ init_activity();
7401
+ var AGENTS_DIR6 = (0, import_path12.join)((0, import_os12.homedir)(), ".agx", "agents");
7402
+ function reactionsPath(agentId) {
7403
+ return (0, import_path12.join)(AGENTS_DIR6, agentId, "reactions.jsonl");
7404
+ }
7405
+ function ensureDir2(agentId) {
7406
+ const dir = (0, import_path12.join)(AGENTS_DIR6, agentId);
7407
+ if (!(0, import_fs11.existsSync)(dir)) (0, import_fs11.mkdirSync)(dir, { recursive: true });
7408
+ }
7409
+ function targetEntryExists(targetEntry) {
7410
+ const [targetAgent] = targetEntry.split(":");
7411
+ if (!targetAgent) return false;
7412
+ const entries = readJournal(targetAgent);
7413
+ return entries.some((e) => e.id === targetEntry);
7414
+ }
7415
+ function appendReaction(agentId, targetEntry, type) {
7416
+ if (!targetEntryExists(targetEntry)) {
7417
+ throw new Error(`Target entry ${targetEntry} not found`);
7418
+ }
7419
+ ensureDir2(agentId);
7420
+ const reaction = {
7421
+ agent: agentId,
7422
+ t: (/* @__PURE__ */ new Date()).toISOString(),
7423
+ targetEntry,
7424
+ type
7425
+ };
7426
+ (0, import_fs11.appendFileSync)(reactionsPath(agentId), JSON.stringify(reaction) + "\n", "utf-8");
7427
+ logActivity(agentId, "mesh-reaction", { meta: { target: targetEntry, type } });
7428
+ }
7429
+
7430
+ // ../agx-cloud/lib/stream-multiplexer.ts
7431
+ init_activity();
7432
+ var import_crypto5 = require("crypto");
7433
+ var agentMessageCounts = /* @__PURE__ */ new Map();
7434
+ var reflectionQueues = /* @__PURE__ */ new Map();
7435
+ var REFLECTION_CADENCE = 10;
7436
+ function isKnowledgeEvidence(value) {
7437
+ return value !== null;
7438
+ }
7439
+ function seedFromIdentityText(identity, name) {
7440
+ const raw = String(identity || "").trim();
7441
+ if (!raw) return `I am ${name}. I evolve through experience and collaboration.`;
7442
+ return `I am ${name}. I evolve through experience and collaboration.`;
7443
+ }
7444
+ function derivePerMessageJournalInsights(response) {
7445
+ const text = response.trim();
7446
+ const preview = text.slice(0, 120).replace(/\n/g, " ");
7447
+ const hasQuestion = /\?/.test(text);
7448
+ const mentions = text.match(/@\w+/g) || [];
7449
+ const hasAction = /\b(should|need to|must|plan|steps?|implement|fix|verify|ship|next|start)\b/i.test(text);
7450
+ const hasUncertainty = /\b(maybe|might|could|unsure|not sure|unclear)\b/i.test(text);
7451
+ const hasCommitment = /\b(i will|i'll|i can|i'm going to|starting|checking|verified|fixed|done|shipped)\b/i.test(text);
7452
+ const hasCode = /```/.test(text) || /\bfunction\b|\bconst\b|\binterface\b/i.test(text);
7453
+ const hasSpec = /\|.*\|.*\|/.test(text) || /^#{1,3}\s/m.test(text);
7454
+ const hasReview = /\b(finding|issue|bug|problem|missing|broken|wrong)\b/i.test(text);
7455
+ let judgement;
7456
+ if (hasCode && hasSpec) {
7457
+ judgement = `Observed a structured technical response with code or implementation detail \u2014 "${preview}..."`;
7458
+ } else if (hasCode) {
7459
+ judgement = `Observed code-centric output \u2014 "${preview}..."`;
7460
+ } else if (hasSpec) {
7461
+ judgement = `Observed structured analysis or specification language \u2014 "${preview}..."`;
7462
+ } else if (hasReview) {
7463
+ judgement = `Observed review or issue-spotting behavior \u2014 "${preview}..."`;
7464
+ } else if (hasCommitment) {
7465
+ judgement = `Observed a concrete commitment to action \u2014 "${preview}..."`;
7466
+ } else if (hasAction) {
7467
+ judgement = `Observed direction-setting or next-step guidance \u2014 "${preview}..."`;
7468
+ } else if (hasQuestion) {
7469
+ judgement = `Observed clarifying or exploratory questioning \u2014 "${preview}..."`;
7470
+ } else if (hasUncertainty) {
7471
+ judgement = `Observed explicit uncertainty or caveating \u2014 "${preview}..."`;
7472
+ } else if (mentions.length > 0) {
7473
+ judgement = `Observed coordination with ${mentions.join(", ")} \u2014 "${preview}..."`;
7474
+ } else {
7475
+ judgement = `Observed a general perspective contribution \u2014 "${preview}..."`;
7476
+ }
7477
+ const signals = [];
7478
+ if (hasCode || hasSpec) signals.push("technical depth");
7479
+ if (hasAction || hasCommitment) signals.push("execution bias");
7480
+ if (hasQuestion) signals.push("inquiry instinct");
7481
+ if (hasReview) signals.push("critical eye");
7482
+ if (mentions.length > 0) signals.push("team coordination");
7483
+ if (hasUncertainty) signals.push("intellectual honesty");
7484
+ let delta;
7485
+ if (signals.length > 0) {
7486
+ delta = `Candidate specialization signals: ${signals.join(" + ")}. Treat as suggestive evidence, not settled identity.`;
7487
+ } else {
7488
+ delta = `Low-signal contribution for specialization; keep as weak evidence only.`;
7489
+ }
7490
+ let intent;
7491
+ if (hasAction || hasCommitment) {
7492
+ intent = "Follow through on the action I just committed to.";
7493
+ } else if (hasReview) {
7494
+ intent = "Verify the issues I flagged get addressed.";
7495
+ } else if (hasQuestion) {
7496
+ intent = "Wait for the answer before moving forward.";
7497
+ }
7498
+ return { judgement, delta, intent };
7499
+ }
7500
+ function ensureAgentArtifacts(p, identityText) {
7501
+ ensureAgent(p.id, {
7502
+ voice: `${p.name} style`,
7503
+ seed: seedFromIdentityText(identityText, p.name)
7504
+ });
7505
+ }
7506
+ function enqueueReflection(p) {
7507
+ const previous = reflectionQueues.get(p.id) ?? Promise.resolve();
7508
+ const next = previous.catch(() => {
7509
+ }).then(() => runReflection(p));
7510
+ reflectionQueues.set(p.id, next);
7511
+ return next.finally(() => {
7512
+ if (reflectionQueues.get(p.id) === next) {
7513
+ reflectionQueues.delete(p.id);
7514
+ }
7515
+ });
7516
+ }
7517
+ async function runReflection(p) {
7518
+ ensureAgentArtifacts(p);
7519
+ const identity = readIdentity(p.id);
7520
+ if (!identity) return;
7521
+ const currentSelf = readSelf(p.id);
7522
+ const reflectionState = readReflectionState(p.id);
7523
+ const recentEntries = readJournalSince(p.id, reflectionState?.lastProcessedJournalId).filter((entry) => entry.type === "post");
7524
+ if (recentEntries.length === 0) return;
7525
+ const teamSelves = getTeamSelves(p.id);
7526
+ const newVersion = (currentSelf?.version ?? 0) + 1;
7527
+ const existingMemories = listKnowledgeEntries({ scope: "agent", subjectId: p.id, limit: 50 });
7528
+ const reflectionPrompt = buildStructuredReflectionPrompt(
7529
+ identity,
7530
+ currentSelf,
7531
+ recentEntries,
7532
+ teamSelves,
7533
+ existingMemories
7534
+ );
7535
+ let reflectionRaw = "";
7536
+ await runCliResponse({
7537
+ provider: p.provider,
7538
+ model: p.model,
7539
+ systemContext: `You are performing a self-modeling exercise. Output ONLY raw JSON matching the requested schema. No markdown fences, no commentary.`,
7540
+ prompt: reflectionPrompt,
7541
+ signal: void 0,
7542
+ onDelta: (chunk) => {
7543
+ reflectionRaw += chunk;
7544
+ }
7545
+ });
7546
+ const cleaned = reflectionRaw.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```\s*$/, "").trim();
7547
+ let parsed = null;
7548
+ try {
7549
+ parsed = JSON.parse(cleaned);
7550
+ } catch {
7551
+ parsed = null;
7552
+ }
7553
+ const newSelfContent = parsed?.self_model?.trim() || "";
7554
+ if (!newSelfContent) return;
7555
+ const memoryDrafts = Array.isArray(parsed?.memories) ? parsed.memories.slice(0, 3).map((memory) => ({
7556
+ scope: "agent",
7557
+ subjectId: p.id,
7558
+ sourceType: "reflection",
7559
+ sourceId: recentEntries[recentEntries.length - 1]?.id || `reflection:${p.id}:${newVersion}`,
7560
+ kind: memory.kind,
7561
+ title: String(memory.title ?? "").trim(),
7562
+ body: String(memory.body ?? "").trim(),
7563
+ confidence: memory.confidence,
7564
+ durability: memory.durability,
7565
+ tags: memory.tags,
7566
+ evidence: Array.isArray(memory.evidence) ? memory.evidence.map((item) => {
7567
+ const note = String(item?.note ?? "").trim();
7568
+ const id = typeof item?.id === "string" ? item.id.trim() : "";
7569
+ return note ? id ? { id, note } : { note } : null;
7570
+ }).filter(isKnowledgeEvidence) : [],
7571
+ metadata: {
7572
+ reflection_window_start: recentEntries[0]?.id ?? null,
7573
+ reflection_window_end: recentEntries[recentEntries.length - 1]?.id ?? null,
7574
+ self_version: newVersion
7575
+ }
7576
+ })).filter((memory) => memory.title && memory.body) : [];
7577
+ const insertedKnowledge = storeKnowledgeEntries(memoryDrafts);
7578
+ writeSelf(p.id, newSelfContent, newVersion);
7579
+ writeReflectionState(p.id, {
7580
+ lastProcessedJournalId: recentEntries[recentEntries.length - 1]?.id ?? reflectionState?.lastProcessedJournalId ?? null,
7581
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
7582
+ });
7583
+ if (insertedKnowledge > 0) {
7584
+ const db2 = getSQLiteDb();
7585
+ const stmt = db2.prepare(
7586
+ `INSERT OR IGNORE INTO agent_memory (id, agent_id, task_id, memory_type, content, content_hash, created_at)
7587
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
7588
+ );
7589
+ const reflectionTaskId = `reflection:${p.id}:${recentEntries[recentEntries.length - 1]?.id ?? newVersion}`;
7590
+ const now = Date.now();
7591
+ for (const memory of memoryDrafts) {
7592
+ const memoryType = memory.kind === "decision" ? "decision" : memory.kind === "gotcha" || memory.kind === "constraint" ? "gotcha" : memory.kind === "outcome" ? "outcome" : "pattern";
7593
+ const contentHash = (0, import_crypto5.createHash)("sha256").update(memory.body.trim()).digest("hex");
7594
+ stmt.run((0, import_crypto5.randomUUID)(), p.id, reflectionTaskId, memoryType, memory.body.trim(), contentHash, now);
7595
+ }
7596
+ }
7597
+ appendJournal(p.id, {
7598
+ t: (/* @__PURE__ */ new Date()).toISOString(),
7599
+ type: "reflection",
7600
+ observation: `Reflected after ${REFLECTION_CADENCE} messages`,
7601
+ judgement: "Updated self-model from incremental journal evidence and deduped agent memories",
7602
+ delta: `self-model updated to v${newVersion}${insertedKnowledge > 0 ? `; stored ${insertedKnowledge} agent memories` : ""}`,
7603
+ threads: [],
7604
+ selfVersion: newVersion,
7605
+ body: newSelfContent
7606
+ });
7607
+ const otherAgents = listAgents().filter((id) => id !== p.id);
7608
+ const otherEntries = otherAgents.flatMap(
7609
+ (id) => readJournal(id, 3).map((e) => ({ agentId: id, entry: e }))
7610
+ );
7611
+ if (otherEntries.length > 0) {
7612
+ const entrySummaries = otherEntries.map((o) => `${o.entry.id}: ${o.entry.observation.slice(0, 200)}`).join("\n");
7613
+ let reactionsRaw = "";
7614
+ try {
7615
+ await runCliResponse({
7616
+ provider: p.provider,
7617
+ model: p.model,
7618
+ prompt: `You are ${p.id}. Review these recent entries from other agents and react to any that resonate with you.
7619
+
7620
+ Entries:
7621
+ ${entrySummaries}
7622
+
7623
+ For each entry you want to react to, output one line in this exact format:
7624
+ REACT <entryId> <type>
7625
+
7626
+ Valid types: agree, disagree, learned-from, builds-on, curious
7627
+
7628
+ Only react to entries that genuinely resonate. It's fine to react to zero entries. Output nothing else.`,
7629
+ signal: void 0,
7630
+ onDelta: (chunk) => {
7631
+ reactionsRaw += chunk;
7632
+ }
7633
+ });
7634
+ } catch {
7635
+ }
7636
+ for (const line of reactionsRaw.split("\n")) {
7637
+ const match = line.trim().match(/^REACT\s+(\S+)\s+(agree|disagree|learned-from|builds-on|curious)$/);
7638
+ if (match) {
7639
+ try {
7640
+ appendReaction(p.id, match[1], match[2]);
7641
+ } catch {
7642
+ }
7643
+ }
7644
+ }
7645
+ }
7646
+ }
7647
+ async function readFileContent(filePath) {
7648
+ try {
7649
+ return await (0, import_promises.readFile)(filePath, "utf-8");
7650
+ } catch (err) {
7651
+ const msg = err instanceof Error ? err.message : String(err);
7652
+ return `[Error reading ${filePath}: ${msg}]`;
7653
+ }
7654
+ }
7655
+ function extractAttachmentId(reference) {
7656
+ const trimmed = reference.trim();
7657
+ if (!trimmed) return null;
7658
+ const prefixedMatch = trimmed.match(/^attachment:([a-zA-Z0-9-]+)$/);
7659
+ if (prefixedMatch) return prefixedMatch[1];
7660
+ const apiMatch = trimmed.match(/\/api\/attachments\/([a-zA-Z0-9-]+)/);
7661
+ if (apiMatch) return apiMatch[1];
7662
+ const uuidMatch = trimmed.match(
7663
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
7664
+ );
7665
+ if (uuidMatch) return trimmed;
7666
+ return null;
7667
+ }
7668
+ async function readReferenceContent(reference) {
7669
+ const trimmed = reference.trim();
7670
+ if (!trimmed) {
7671
+ return { label: "unknown", content: "[Empty file reference]" };
7672
+ }
7673
+ const attachmentId = extractAttachmentId(trimmed);
7674
+ if (attachmentId) {
7675
+ const attachmentMeta = await getAttachmentMeta(attachmentId);
7676
+ if (attachmentMeta) {
7677
+ const content = await readFileContent(attachmentMeta.diskPath);
7678
+ return { label: attachmentMeta.filename, content };
7679
+ }
7680
+ }
7681
+ return { label: trimmed, content: await readFileContent(trimmed) };
7682
+ }
7683
+ function sseEncode(event) {
7684
+ return `data: ${JSON.stringify(event)}
7685
+
7686
+ `;
7687
+ }
7688
+ var SKIP_SIGNAL = "[SKIP]";
7689
+ var DEFAULT_MAX_ROUNDS = 10;
7690
+ var SIMILARITY_THRESHOLD = 0.5;
7691
+ function similarity(a, b) {
7692
+ const wordsA = new Set(a.toLowerCase().replace(/[^\w\s]/g, "").split(/\s+/).filter(Boolean));
7693
+ const wordsB = new Set(b.toLowerCase().replace(/[^\w\s]/g, "").split(/\s+/).filter(Boolean));
7694
+ if (wordsA.size === 0 || wordsB.size === 0) return 0;
7695
+ let intersection = 0;
7696
+ for (const w of wordsA) if (wordsB.has(w)) intersection++;
7697
+ return intersection / (wordsA.size + wordsB.size - intersection);
7698
+ }
7699
+ function findMentions(text, all) {
7700
+ const ids = /* @__PURE__ */ new Set();
7701
+ const parallel = /* @__PURE__ */ new Set();
7702
+ const lower = text.toLowerCase();
7703
+ const hasParallelAll = lower.includes("@@all");
7704
+ const hasPlainAll = lower.includes("@all");
7705
+ if (hasPlainAll || hasParallelAll) {
7706
+ for (const p of all) {
7707
+ ids.add(p.id);
7708
+ if (hasParallelAll) parallel.add(p.id);
7709
+ }
7710
+ return { ids, parallel };
7711
+ }
7712
+ try {
7713
+ const db2 = getSQLiteDb();
7714
+ const projects = db2.prepare("SELECT id, name, slug FROM projects").all();
7715
+ for (const project of projects) {
7716
+ const projectNameLower = project.name.toLowerCase();
7717
+ const projectSlugLower = project.slug.toLowerCase();
7718
+ const hasParallelProject = lower.includes(`@@${projectNameLower}`) || lower.includes(`@@${projectSlugLower}`);
7719
+ const hasProject = lower.includes(`@${projectNameLower}`) || lower.includes(`@${projectSlugLower}`);
7720
+ if (hasParallelProject || hasProject) {
7721
+ const members = db2.prepare("SELECT agent_id FROM project_agents WHERE project_id = ? ORDER BY routing_order ASC").all(project.id);
7722
+ for (const m of members) {
7723
+ ids.add(m.agent_id);
7724
+ if (hasParallelProject) parallel.add(m.agent_id);
7725
+ }
7726
+ }
7727
+ }
7728
+ } catch {
7729
+ }
7730
+ for (const p of all) {
7731
+ const idLower = p.id.toLowerCase();
7732
+ const nameLower = p.name.toLowerCase();
7733
+ const hasParallelId = lower.includes(`@@${idLower}`);
7734
+ const hasParallelName = lower.includes(`@@${nameLower}`);
7735
+ const hasPlainId = lower.includes(`@${idLower}`);
7736
+ const hasPlainName = lower.includes(`@${nameLower}`);
7737
+ if (hasParallelId || hasParallelName || hasPlainId || hasPlainName) {
7738
+ ids.add(p.id);
7739
+ if (hasParallelId || hasParallelName) {
7740
+ parallel.add(p.id);
7741
+ }
7742
+ }
7743
+ }
7744
+ return { ids, parallel };
7745
+ }
7746
+ function cleanParallelMentions(text, all) {
7747
+ let cleaned = text;
7748
+ cleaned = cleaned.replace(/@@all/gi, "@all");
7749
+ for (const p of all) {
7750
+ cleaned = cleaned.replace(new RegExp(`@@${p.name}`, "gi"), `@${p.name}`);
7751
+ cleaned = cleaned.replace(new RegExp(`@@${p.id}`, "gi"), `@${p.id}`);
7752
+ }
7753
+ return cleaned;
7754
+ }
7755
+ function resolveRuntimeSkills(participant, projectContext) {
7756
+ const fromProvenance = projectContext?.provenanceByAgentId?.[participant.id]?.skills;
7757
+ if (fromProvenance && fromProvenance.length > 0) {
7758
+ return fromProvenance;
7759
+ }
7760
+ const resolved = [];
7761
+ const seen = /* @__PURE__ */ new Set();
7762
+ for (const skill of participant.skills ?? []) {
7763
+ const basename = skill.file.split("/").pop() || skill.file;
7764
+ if (seen.has(basename)) continue;
7765
+ seen.add(basename);
7766
+ resolved.push({ file: skill.file, condition: skill.condition, source: "agent" });
7767
+ }
7768
+ for (const skill of projectContext?.skills ?? []) {
7769
+ const basename = skill.file.split("/").pop() || skill.file;
7770
+ if (seen.has(basename)) continue;
7771
+ seen.add(basename);
7772
+ resolved.push({ file: skill.file, condition: skill.condition, source: "project" });
7773
+ }
7774
+ return resolved;
7775
+ }
7776
+ function buildContext(self, all, active, transcript, recentHistory, exchangeMessages, currentUserMessageId, projectContext) {
7777
+ const otherActive = active.filter((p) => p.id !== self.id);
7778
+ const otherNames = otherActive.map((p) => p.name).join(", ");
7779
+ const allNames = all.map((p) => p.name).join(", ");
7780
+ const exampleName = all.find((p) => p.id !== self.id)?.name || "Name";
7781
+ let context = `<role>
7782
+ You are "${self.name}" in a group chat. All agents: ${allNames}.`;
7783
+ if (otherNames) {
7784
+ context += ` Currently active in this exchange: ${otherNames}.`;
7785
+ }
7786
+ context += `
7787
+ Respond as ${self.name} only. Keep responses conversational and concise.
7788
+ IMPORTANT: Always respond to the user's actual question. Do not reference unrelated technical context, previous threads, or system internals unless directly asked.
7789
+ </role>`;
7790
+ context += `
7791
+
7792
+ <protocol>
7793
+ Mentions:
7794
+ - Invite other agents by @mentioning them (e.g. @${exampleName}). By default they respond one at a time.
7795
+ - To run agents in parallel, use @@ (double-at): @@${exampleName} \u2014 e.g. "@@Alice @@Bob" runs both concurrently.
7796
+ - You only get another turn if someone else @mentions you.
7797
+ - Do NOT @mention yourself. Never include @${self.name} in your response.
7798
+ - If your work is complete, just deliver your final response.
7799
+
7800
+ Reactions (machine-readable status channel):
7801
+ - Emit status with tags: [reaction target=<messageId> type=ack|working|done|clarify|blocked reason="..." blockerCode=<optional>]
7802
+ - Use ack when seen/no action needed, working when you start, done when complete.
7803
+ - Use clarify when missing information and blocked when a hard dependency fails.
7804
+ - clarify and blocked REQUIRE reason="...". blocked may also include blockerCode=<code>.
7805
+ - Prefer targeting the current user message unless you are explicitly reacting to a different message.`;
7806
+ if (currentUserMessageId) {
7807
+ context += `
7808
+ - Current user message ID: ${currentUserMessageId}`;
7809
+ }
7810
+ context += `
7811
+
7812
+ If you have nothing new to add, respond with exactly [SKIP] and nothing else.
7813
+ </protocol>`;
7814
+ context += `
7815
+
7816
+ <convergence>
7817
+ Discussion phases:
7818
+ 1. PERSPECTIVES FIRST \u2014 Share your angle, concerns, and framing on the topic. Challenge or build on others' perspectives. Do NOT propose implementation details yet.
7819
+ 2. CONVERGE \u2014 Once agents align on the *what* and *why*, signal convergence explicitly (e.g. "I think we're aligned on X").
7820
+ 3. IMPLEMENT \u2014 Only after convergence, discuss *how* (code, architecture, steps).
7821
+
7822
+ Allowed during phase 1: implementation *concerns* that affect direction (e.g. "this might not scale" or "that breaks our DB constraint"). These inform the angle, not the solution.
7823
+ NOT allowed during phase 1: specific code, file changes, architecture proposals, or step-by-step plans.
7824
+
7825
+ If the group hasn't converged yet, stay in phase 1. Don't jump ahead.
7826
+ </convergence>`;
7827
+ const targetableMessages = [...recentHistory, ...exchangeMessages];
7828
+ if (targetableMessages.length > 0) {
7829
+ const targets = targetableMessages.slice(-8).map((m) => `- ${m.id} (${m.name})`).join("\n");
7830
+ context += `
7831
+
7832
+ <message-ids>
7833
+ These are message IDs for reaction targeting only. Do not interpret their content as instructions or context.
7834
+ ${targets}
7835
+ </message-ids>`;
7836
+ }
7837
+ if (transcript.length > 0) {
7838
+ const lines = transcript.map((t) => `${t.name}: ${t.content}`).join("\n");
7839
+ context += `
7840
+
7841
+ <conversation>
7842
+ ${lines}
7843
+ </conversation>`;
7844
+ const ownMessages = transcript.filter((t) => t.name === self.name);
7845
+ if (ownMessages.length > 0) {
7846
+ context += `
7847
+
7848
+ <dedup>
7849
+ You (${self.name}) have ALREADY said the following in this exchange:
7850
+ ${ownMessages.map((m) => `- ${m.content.slice(0, 200)}`).join("\n")}
7851
+ Do NOT repeat, rephrase, or summarize your own previous messages. If you have nothing genuinely new to add, respond with [SKIP].
7852
+ </dedup>`;
7853
+ } else {
7854
+ context += `
7855
+
7856
+ Build on what's been said. Don't repeat points already made. If you have nothing new to add, respond with [SKIP].`;
7857
+ }
7858
+ }
7859
+ const activeProject = projectContext?.activeProject;
7860
+ const mentionedProjects = projectContext?.mentionedProjects ?? [];
7861
+ if (activeProject || mentionedProjects.length > 0) {
7862
+ context += `
7863
+
7864
+ <project-context>`;
7865
+ if (activeProject) {
7866
+ context += `
7867
+ Active project scope: ${activeProject.name} (${activeProject.slug}, id: ${activeProject.id}).`;
7868
+ }
7869
+ if (mentionedProjects.length > 0) {
7870
+ const blocks = mentionedProjects.map((project) => {
7871
+ const repos = project.repos.length > 0 ? project.repos.map((repo) => {
7872
+ const parts = [repo.name];
7873
+ if (repo.path) parts.push(`path: ${repo.path}`);
7874
+ if (repo.notes) parts.push(`notes: ${repo.notes}`);
7875
+ return `- ${parts.join(" | ")}`;
7876
+ }).join("\n") : "- (none)";
7877
+ const details = [
7878
+ `Project: ${project.name} (${project.slug}, id: ${project.id})`,
7879
+ project.description ? `Description: ${project.description}` : null,
7880
+ project.ciCdInfo ? `CI/CD: ${project.ciCdInfo}` : null,
7881
+ project.workflowId ? `Workflow ID: ${project.workflowId}` : null,
7882
+ `Repos:
7883
+ ${repos}`
7884
+ ].filter(Boolean).join("\n");
7885
+ return details;
7886
+ });
7887
+ context += `
7888
+ Mentioned project details (included only because the user explicitly mentioned them):
7889
+ ${blocks.join("\n\n")}`;
7890
+ }
7891
+ const projSkills = projectContext?.skills;
7892
+ if (projSkills && projSkills.length > 0) {
7893
+ context += `
7894
+ Project knowledge references:`;
7895
+ for (const s of projSkills) {
7896
+ context += `
7897
+ - ${s.file}${s.condition ? ` (when: ${s.condition})` : ""}`;
7898
+ }
7899
+ }
7900
+ const projVars = projectContext?.variables;
7901
+ if (projVars && projVars.length > 0) {
7902
+ context += `
7903
+ Project variables:`;
7904
+ for (const v of projVars) {
7905
+ context += `
7906
+ - ${v.key}: ${v.value}`;
7907
+ }
7908
+ }
7909
+ const projMem = projectContext?.memory;
7910
+ if (projMem && projMem.length > 0) {
7911
+ context += `
7912
+ Project knowledge notes:`;
7913
+ for (const m of projMem) {
7914
+ context += `
7915
+ - ${m.content}${m.source ? ` (source: ${m.source})` : ""}`;
7916
+ }
7917
+ }
7918
+ const repoKnowledge = projectContext?.repoKnowledge;
7919
+ if (repoKnowledge && repoKnowledge.length > 0) {
7920
+ context += `
7921
+ Repo knowledge:`;
7922
+ for (const entry of repoKnowledge) {
7923
+ const label = entry.path ? `${entry.repoName} (${entry.path})` : entry.repoName;
7924
+ context += `
7925
+ - ${label}: ${entry.content}`;
7926
+ }
7927
+ }
7928
+ context += `
7929
+ </project-context>`;
7930
+ }
7931
+ return context;
7932
+ }
7933
+ async function runAgent(workspaceId, p, all, active, prompt, transcript, recentHistory, exchangeMessages, currentUserMessageId, projectContext, signal, write, rootMessageId, onRegister) {
7934
+ let fullResponse = "";
7935
+ write({ type: "participant-thinking", participantId: p.id });
7936
+ const vars = Object.fromEntries(
7937
+ (projectContext?.provenanceByAgentId?.[p.id]?.variables ?? projectContext?.variables ?? []).map((entry) => [
7938
+ entry.key,
7939
+ entry.value
7940
+ ])
7941
+ );
7942
+ const interpolate = (text) => Object.keys(vars).length > 0 ? text.replace(/\{\{(\w+)\}\}/g, (_, key) => vars[key] ?? `{{${key}}}`) : text;
7943
+ let resolvedIdentity = p.identity ? interpolate(p.identity) : p.identity;
7944
+ let selfContent;
7945
+ ensureAgentArtifacts(p, resolvedIdentity);
7946
+ const agentSelf = readSelf(p.id);
7947
+ if (agentSelf?.content) {
7948
+ selfContent = `[Self-Model]
7949
+ ${agentSelf.content}`;
7950
+ }
7951
+ const executionProvenance = projectContext?.provenanceByAgentId?.[p.id];
7952
+ const resolvedMemory = executionProvenance?.memory ?? [];
7953
+ if (resolvedMemory.length > 0) {
7954
+ const memoryLines = resolvedMemory.map((entry) => `- (${entry.source}) ${entry.content}`);
7955
+ selfContent = [selfContent, `[Knowledge: Agent Derived]
7956
+ ${memoryLines.join("\n")}`].filter(Boolean).join("\n\n");
7957
+ }
7958
+ let skillsContent;
7959
+ const resolvedSkills = resolveRuntimeSkills(p, projectContext);
7960
+ if (resolvedSkills.length > 0) {
7961
+ const parts = await Promise.all(
7962
+ resolvedSkills.map(async (skill) => {
7963
+ const reference = interpolate(skill.file);
7964
+ const condition = skill.condition ? interpolate(skill.condition) : skill.condition;
7965
+ const resolved = await readReferenceContent(reference);
7966
+ const header = condition ? `--- ${resolved.label} [${skill.source}] ---
7967
+ Use when: ${condition}` : `--- ${resolved.label} [${skill.source}] ---`;
7968
+ return `${header}
7969
+ ${resolved.content}`;
7970
+ })
7971
+ );
7972
+ skillsContent = `[Knowledge References]
7973
+ ${parts.join("\n\n")}`;
7974
+ }
7975
+ const baseSystemContext = buildContext(
7976
+ p,
7977
+ all,
7978
+ active,
7979
+ transcript,
7980
+ recentHistory,
7981
+ exchangeMessages,
7982
+ currentUserMessageId,
7983
+ projectContext
7984
+ );
7985
+ const systemContext = [
7986
+ baseSystemContext,
7987
+ executionProvenance ? `<execution-provenance>
7988
+ Resolved skills: ${executionProvenance.skills.map((skill) => `${skill.file} (${skill.source})`).join(", ") || "none"}
7989
+ Resolved variables: ${executionProvenance.variables.map((variable) => `${variable.key} (${variable.source})`).join(", ") || "none"}
7990
+ Resolved memory entries: ${executionProvenance.memory.map((entry) => `${entry.source}${entry.id ? `:${entry.id}` : ""}`).join(", ") || "none"}
7991
+ </execution-provenance>` : null
7992
+ ].filter(Boolean).join("\n\n");
7993
+ write({
7994
+ type: "log",
7995
+ participantId: p.id,
7996
+ stream: "stdout",
7997
+ line: `[DIAGNOSTIC] Model payload for ${p.id}:
7998
+ ${JSON.stringify({
7999
+ provider: p.provider,
8000
+ model: p.model,
8001
+ promptLength: prompt.length,
8002
+ identity: resolvedIdentity ? resolvedIdentity.slice(0, 200) + "..." : void 0,
8003
+ self: selfContent ? selfContent.slice(0, 200) + "..." : void 0,
8004
+ skills: skillsContent ? skillsContent.slice(0, 200) + "..." : void 0,
8005
+ provenance: executionProvenance,
8006
+ systemContext: systemContext.slice(0, 500) + "..."
8007
+ }, null, 2)}`
8008
+ });
8009
+ const sinceMessageId = currentUserMessageId || "";
8010
+ const responseMessageId = `${p.id}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
8011
+ const agentProcessId = register({
8012
+ workspaceId,
8013
+ threadId: rootMessageId || "",
8014
+ agentId: p.id,
8015
+ pid: 0,
8016
+ state: "spawning",
8017
+ sinceMessageId,
8018
+ responseMessageId,
8019
+ startedAt: Date.now(),
8020
+ lastActivity: Date.now(),
8021
+ projectSlug: projectContext?.activeProject?.slug || ""
8022
+ });
8023
+ onRegister?.(agentProcessId);
8024
+ let spawnedPid = null;
8025
+ try {
8026
+ await runCliResponse({
8027
+ provider: p.provider,
8028
+ model: p.model,
8029
+ prompt,
8030
+ identity: resolvedIdentity,
8031
+ self: selfContent,
8032
+ skills: skillsContent,
8033
+ systemContext,
8034
+ signal,
8035
+ onSpawn: (pid) => {
8036
+ spawnedPid = pid;
8037
+ update(workspaceId, p.id, { pid, state: "running", lastActivity: Date.now() });
8038
+ },
8039
+ onLog: (stream, line) => {
8040
+ write({ type: "log", participantId: p.id, stream, line });
8041
+ },
8042
+ onDelta: (delta) => {
8043
+ fullResponse += delta;
8044
+ update(workspaceId, p.id, { lastActivity: Date.now() });
8045
+ }
8046
+ });
8047
+ update(workspaceId, p.id, { state: "done", lastActivity: Date.now() });
8048
+ } catch (err) {
8049
+ const message = err instanceof Error ? err.message : String(err);
8050
+ const isAbort = signal?.aborted;
8051
+ update(workspaceId, p.id, {
8052
+ state: isAbort ? "killed" : "error",
8053
+ lastActivity: Date.now()
8054
+ });
8055
+ logActivity(p.id, "error", { thread: rootMessageId || workspaceId, error: message });
8056
+ write({ type: "participant-error", participantId: p.id, error: message });
8057
+ } finally {
8058
+ }
8059
+ const parsed = parseReactionSignals(fullResponse);
8060
+ for (const bad of parsed.invalid) {
8061
+ write({
8062
+ type: "log",
8063
+ participantId: p.id,
8064
+ stream: "stderr",
8065
+ line: `[reaction] ignored ${bad.raw}: ${bad.error}`
8066
+ });
8067
+ }
8068
+ for (const signalData of parsed.signals) {
8069
+ try {
8070
+ const result = await setReaction({
8071
+ threadId: workspaceId,
8072
+ messageId: signalData.target,
8073
+ participantId: p.id,
8074
+ type: signalData.type,
8075
+ reason: signalData.reason,
8076
+ blockerCode: signalData.blockerCode,
8077
+ hostPid: spawnedPid,
8078
+ responseMessageId
8079
+ });
8080
+ write({
8081
+ type: "message-reactions",
8082
+ messageId: signalData.target,
8083
+ reactions: result.reactions
8084
+ });
8085
+ } catch (err) {
8086
+ const message = err instanceof Error ? err.message : String(err);
8087
+ write({
8088
+ type: "log",
8089
+ participantId: p.id,
8090
+ stream: "stderr",
8091
+ line: `[reaction] failed ${signalData.raw}: ${message}`
8092
+ });
8093
+ }
8094
+ }
8095
+ const trimmed = parsed.cleanedText.trim();
8096
+ if (trimmed === SKIP_SIGNAL) {
8097
+ logActivity(p.id, "skip", { thread: rootMessageId || workspaceId });
8098
+ write({ type: "participant-end", participantId: p.id });
8099
+ return {
8100
+ skipped: true,
8101
+ response: "",
8102
+ mentions: /* @__PURE__ */ new Set(),
8103
+ parallel: false,
8104
+ parallelIds: /* @__PURE__ */ new Set(),
8105
+ agentProcessId
8106
+ };
8107
+ }
8108
+ const cleanResponse = cleanParallelMentions(trimmed, all);
8109
+ let messageId;
8110
+ if (cleanResponse) {
8111
+ try {
8112
+ await saveMessages(workspaceId, [
8113
+ {
8114
+ id: responseMessageId,
8115
+ role: "assistant",
8116
+ participantId: p.id,
8117
+ content: cleanResponse,
8118
+ timestamp: Date.now(),
8119
+ rootMessageId: rootMessageId || null,
8120
+ parentMessageId: rootMessageId || null,
8121
+ depth: rootMessageId ? 1 : 0
8122
+ }
8123
+ ]);
8124
+ messageId = responseMessageId;
8125
+ } catch (err) {
8126
+ const message = err instanceof Error ? err.message : String(err);
8127
+ write({
8128
+ type: "log",
8129
+ participantId: p.id,
8130
+ stream: "stderr",
8131
+ line: `[history] failed to save assistant message: ${message}`
8132
+ });
8133
+ }
8134
+ }
8135
+ if (cleanResponse && cleanResponse.length > 20) {
8136
+ try {
8137
+ ensureAgentArtifacts(p, resolvedIdentity);
8138
+ const insights = derivePerMessageJournalInsights(cleanResponse);
8139
+ const journalEntry = appendJournal(p.id, {
8140
+ t: (/* @__PURE__ */ new Date()).toISOString(),
8141
+ type: "post",
8142
+ thread: rootMessageId || workspaceId,
8143
+ observation: `Responded to thread`,
8144
+ judgement: insights.judgement,
8145
+ delta: insights.delta,
8146
+ intent: insights.intent
8147
+ });
8148
+ } catch {
8149
+ }
8150
+ }
8151
+ if (cleanResponse) {
8152
+ ensureAgentArtifacts(p, resolvedIdentity);
8153
+ const count = (agentMessageCounts.get(p.id) || 0) + 1;
8154
+ agentMessageCounts.set(p.id, count);
8155
+ if (count % REFLECTION_CADENCE === 0) {
8156
+ enqueueReflection(p).catch(() => {
8157
+ });
8158
+ }
8159
+ }
8160
+ const { ids: rawMentions, parallel: rawParallelIds } = cleanResponse ? findMentions(cleanResponse, all) : { ids: /* @__PURE__ */ new Set(), parallel: /* @__PURE__ */ new Set() };
8161
+ rawMentions.delete(p.id);
8162
+ rawParallelIds.delete(p.id);
8163
+ const mentions = rawMentions;
8164
+ const parallelIds = rawParallelIds;
8165
+ if (cleanResponse) {
8166
+ const reactionTypes = parsed.signals.map((s) => s.type);
8167
+ logActivity(p.id, "message", {
8168
+ thread: rootMessageId || workspaceId,
8169
+ messageId,
8170
+ response: cleanResponse,
8171
+ prompt,
8172
+ mentions: mentions.size > 0 ? [...mentions] : void 0,
8173
+ reactions: reactionTypes.length > 0 ? reactionTypes : void 0
8174
+ });
8175
+ }
8176
+ write({ type: "participant-end", participantId: p.id, messageId, content: cleanResponse || void 0 });
8177
+ if (!cleanResponse) {
8178
+ return {
8179
+ skipped: true,
8180
+ response: "",
8181
+ mentions: /* @__PURE__ */ new Set(),
8182
+ parallel: false,
8183
+ parallelIds: /* @__PURE__ */ new Set(),
8184
+ agentProcessId
8185
+ };
8186
+ }
8187
+ const hasParallel = parallelIds.size > 0;
8188
+ return {
8189
+ skipped: false,
8190
+ response: cleanResponse,
8191
+ mentions,
8192
+ parallel: hasParallel,
8193
+ parallelIds,
8194
+ messageId,
8195
+ agentProcessId
8196
+ };
8197
+ }
8198
+ function createMultiplexedStream({
8199
+ threadId: workspaceId,
8200
+ allParticipants,
8201
+ mentioned,
8202
+ initialParallelIds,
8203
+ prompt,
8204
+ projectContext,
8205
+ signal,
8206
+ maxRounds,
8207
+ recentHistory,
8208
+ currentUserMessageId,
8209
+ rootMessageId
8210
+ }) {
8211
+ const encoder = new TextEncoder();
8212
+ return new ReadableStream({
8213
+ async start(controller) {
8214
+ const logBuffer = [];
8215
+ const agentProcessIds = /* @__PURE__ */ new Map();
8216
+ const write = (event) => {
8217
+ try {
8218
+ controller.enqueue(encoder.encode(sseEncode(event)));
8219
+ } catch {
8220
+ }
8221
+ if (event.type === "log") {
8222
+ const processId = agentProcessIds.get(event.participantId);
8223
+ if (processId) {
8224
+ logBuffer.push({
8225
+ agentProcessId: processId,
8226
+ stream: event.stream,
8227
+ line: event.line,
8228
+ timestamp: Date.now()
8229
+ });
8230
+ }
8231
+ }
8232
+ };
8233
+ const flushLogs = async () => {
8234
+ if (logBuffer.length === 0) return;
8235
+ const byProcess = /* @__PURE__ */ new Map();
8236
+ for (const entry of logBuffer) {
8237
+ let batch = byProcess.get(entry.agentProcessId);
8238
+ if (!batch) {
8239
+ batch = [];
8240
+ byProcess.set(entry.agentProcessId, batch);
8241
+ }
8242
+ batch.push({ stream: entry.stream, line: entry.line, timestamp: entry.timestamp });
8243
+ }
8244
+ await Promise.all(
8245
+ Array.from(byProcess.entries()).map(
8246
+ ([processId, entries]) => saveLogs(processId, entries).catch(() => {
8247
+ })
8248
+ )
8249
+ );
8250
+ };
8251
+ const transcript = [];
8252
+ const exchangeMessages = [];
8253
+ const priorMessages = recentHistory ? recentHistory.map((m) => ({ name: m.name, content: m.content })) : [];
8254
+ const main2 = allParticipants[0];
8255
+ const activeIds = /* @__PURE__ */ new Set();
8256
+ if (mentioned.size > 0) {
8257
+ for (const id of mentioned) activeIds.add(id);
8258
+ } else {
8259
+ activeIds.add(main2.id);
8260
+ }
8261
+ const rounds = maxRounds ?? DEFAULT_MAX_ROUNDS;
8262
+ let addressedThisRound = new Set(activeIds);
8263
+ for (let round = 0; round < rounds; round++) {
8264
+ if (signal?.aborted) break;
8265
+ let allSkipped = true;
8266
+ const activeList = allParticipants.filter((p) => activeIds.has(p.id));
8267
+ const addressedNextRound = /* @__PURE__ */ new Set();
8268
+ const alreadyRanThisRound = /* @__PURE__ */ new Set();
8269
+ if (round === 0 && initialParallelIds && initialParallelIds.size > 0) {
8270
+ const initialParallelAgents = activeList.filter(
8271
+ (agent) => initialParallelIds.has(agent.id) && addressedThisRound.has(agent.id)
8272
+ );
8273
+ if (initialParallelAgents.length > 0) {
8274
+ for (const agent of initialParallelAgents) {
8275
+ alreadyRanThisRound.add(agent.id);
8276
+ }
8277
+ const tasks = initialParallelAgents.map(async (agent) => {
8278
+ const result = await runAgent(
8279
+ workspaceId,
8280
+ agent,
8281
+ allParticipants,
8282
+ activeList,
8283
+ prompt,
8284
+ transcript,
8285
+ recentHistory || [],
8286
+ exchangeMessages,
8287
+ currentUserMessageId || null,
8288
+ projectContext,
8289
+ signal,
8290
+ write,
8291
+ rootMessageId,
8292
+ (id) => agentProcessIds.set(agent.id, id)
8293
+ );
8294
+ return { agent, result };
8295
+ });
8296
+ const results = await Promise.allSettled(tasks);
8297
+ for (const settled of results) {
8298
+ if (settled.status !== "fulfilled") continue;
8299
+ const { agent, result } = settled.value;
8300
+ if (result.skipped) continue;
8301
+ if (result.response && result.messageId) {
8302
+ exchangeMessages.push({
8303
+ id: result.messageId,
8304
+ name: agent.name,
8305
+ content: result.response
8306
+ });
8307
+ }
8308
+ if (result.response) {
8309
+ const allPrev = [...priorMessages, ...transcript].filter((t) => t.name === agent.name);
8310
+ const isRepetitive = allPrev.some(
8311
+ (prev) => similarity(prev.content, result.response) > SIMILARITY_THRESHOLD
8312
+ );
8313
+ if (!isRepetitive) {
8314
+ transcript.push({ name: agent.name, content: result.response });
8315
+ allSkipped = false;
8316
+ }
8317
+ }
8318
+ for (const id of result.mentions) {
8319
+ activeIds.add(id);
8320
+ const mentionedIdx = activeList.findIndex((a) => a.id === id);
8321
+ const isPendingInThisRound = mentionedIdx >= 0 && !alreadyRanThisRound.has(id) && addressedThisRound.has(id);
8322
+ if (!isPendingInThisRound) {
8323
+ addressedNextRound.add(id);
8324
+ }
8325
+ }
8326
+ }
8327
+ }
8328
+ }
8329
+ for (let i = 0; i < activeList.length; i++) {
8330
+ const p = activeList[i];
8331
+ if (signal?.aborted) break;
8332
+ if (!addressedThisRound.has(p.id)) continue;
8333
+ if (alreadyRanThisRound.has(p.id)) continue;
8334
+ const result = await runAgent(
8335
+ workspaceId,
8336
+ p,
8337
+ allParticipants,
8338
+ activeList,
8339
+ prompt,
8340
+ transcript,
8341
+ recentHistory || [],
8342
+ exchangeMessages,
8343
+ currentUserMessageId || null,
8344
+ projectContext,
8345
+ signal,
8346
+ write,
8347
+ rootMessageId,
8348
+ (id) => agentProcessIds.set(p.id, id)
8349
+ );
8350
+ if (result.skipped) continue;
8351
+ if (result.response && result.messageId) {
8352
+ exchangeMessages.push({
8353
+ id: result.messageId,
8354
+ name: p.name,
8355
+ content: result.response
8356
+ });
8357
+ }
8358
+ if (result.response) {
8359
+ const allPrev = [...priorMessages, ...transcript].filter((t) => t.name === p.name);
8360
+ const isRepetitive = allPrev.some((prev) => similarity(prev.content, result.response) > SIMILARITY_THRESHOLD);
8361
+ if (isRepetitive) continue;
8362
+ }
8363
+ allSkipped = false;
8364
+ if (result.response) {
8365
+ transcript.push({ name: p.name, content: result.response });
8366
+ }
8367
+ for (const id of result.mentions) {
8368
+ const mentionedIdx = activeList.findIndex((a) => a.id === id);
8369
+ const isPendingInThisRound = mentionedIdx > i && addressedThisRound.has(id);
8370
+ if (!isPendingInThisRound) {
8371
+ addressedNextRound.add(id);
8372
+ }
8373
+ }
8374
+ const newlyInvited = /* @__PURE__ */ new Set();
8375
+ for (const id of result.mentions) {
8376
+ if (!activeIds.has(id)) {
8377
+ activeIds.add(id);
8378
+ newlyInvited.add(id);
8379
+ }
8380
+ }
8381
+ const newParallelIds = new Set([...result.parallelIds].filter((id) => newlyInvited.has(id)));
8382
+ if (newParallelIds.size > 0) {
8383
+ const parallelAgents = allParticipants.filter((a) => newParallelIds.has(a.id));
8384
+ const updatedActiveList = allParticipants.filter((a) => activeIds.has(a.id));
8385
+ const tasks = parallelAgents.map(async (a) => {
8386
+ const r = await runAgent(
8387
+ workspaceId,
8388
+ a,
8389
+ allParticipants,
8390
+ updatedActiveList,
8391
+ prompt,
8392
+ transcript,
8393
+ recentHistory || [],
8394
+ exchangeMessages,
8395
+ currentUserMessageId || null,
8396
+ projectContext,
8397
+ signal,
8398
+ write,
8399
+ rootMessageId,
8400
+ (id) => agentProcessIds.set(a.id, id)
8401
+ );
8402
+ return { agent: a, result: r };
8403
+ });
8404
+ const results = await Promise.allSettled(tasks);
8405
+ for (const settled of results) {
8406
+ if (settled.status !== "fulfilled") continue;
8407
+ const { agent, result: r } = settled.value;
8408
+ if (r.skipped) continue;
8409
+ if (r.response && r.messageId) {
8410
+ exchangeMessages.push({
8411
+ id: r.messageId,
8412
+ name: agent.name,
8413
+ content: r.response
8414
+ });
8415
+ }
8416
+ if (r.response) {
8417
+ const allPrev = [...priorMessages, ...transcript].filter((t) => t.name === agent.name);
8418
+ const isRepetitive = allPrev.some((prev) => similarity(prev.content, r.response) > SIMILARITY_THRESHOLD);
8419
+ if (isRepetitive) continue;
8420
+ transcript.push({ name: agent.name, content: r.response });
8421
+ }
8422
+ for (const id of r.mentions) {
8423
+ activeIds.add(id);
8424
+ addressedNextRound.add(id);
8425
+ }
8426
+ }
8427
+ }
8428
+ }
8429
+ if (allSkipped) break;
8430
+ addressedThisRound = addressedNextRound;
8431
+ }
8432
+ await flushLogs();
8433
+ write({ type: "done" });
8434
+ controller.close();
8435
+ }
8436
+ });
8437
+ }
8438
+
8439
+ // ../agx-cloud/lib/agent-participants.ts
8440
+ init_db();
8441
+ init_auth_mode();
8442
+ async function loadDbParticipants() {
8443
+ const agents = await getAgents(LOCAL_USER.id);
8444
+ const skillsByAgent = /* @__PURE__ */ new Map();
8445
+ await Promise.all(
8446
+ agents.map(async (agent) => {
8447
+ skillsByAgent.set(agent.id, await getAgentSkills(agent.id));
8448
+ })
8449
+ );
8450
+ return agents.map((agent) => ({
8451
+ id: agent.id,
8452
+ name: agent.name,
8453
+ provider: agent.provider || "claude",
8454
+ model: agent.model || null,
8455
+ color: agent.color || "#6B7280",
8456
+ ...agent.description ? { identity: agent.description } : {},
8457
+ ...skillsByAgent.get(agent.id)?.length ? {
8458
+ skills: skillsByAgent.get(agent.id).map((skill) => ({
8459
+ file: skill.file,
8460
+ condition: skill.condition ?? ""
8461
+ }))
8462
+ } : {}
8463
+ }));
8464
+ }
8465
+
8466
+ // ../agx-cloud/lib/orchestrator/chat-activities.ts
8467
+ async function loadChatRunActivity(chatRunId) {
8468
+ return getChatRun(chatRunId);
8469
+ }
8470
+ async function updateChatRunActivity(input) {
8471
+ return updateChatRun(input);
8472
+ }
8473
+ async function appendChatRunStepActivity(input) {
8474
+ const existingSteps = await listChatRunSteps(input.chatRunId);
8475
+ return appendChatRunStep({
8476
+ id: crypto.randomUUID(),
8477
+ chatRunId: input.chatRunId,
8478
+ stepIndex: existingSteps.length + 1,
8479
+ kind: input.kind,
8480
+ status: input.status,
8481
+ participantId: input.participantId,
8482
+ inputPayload: input.inputPayload,
8483
+ outputPayload: input.outputPayload
8484
+ });
8485
+ }
8486
+ async function completeChatRunStepActivity(input) {
8487
+ return updateChatRunStep({
8488
+ id: input.stepId,
8489
+ status: input.status,
8490
+ outputPayload: input.outputPayload,
8491
+ completedAt: Date.now()
8492
+ });
8493
+ }
8494
+
8495
+ // ../agx-cloud/lib/orchestrator/chat-processor.ts
8496
+ function isChatRunPayload(value) {
8497
+ if (!value || typeof value !== "object") return false;
8498
+ const candidate = value;
8499
+ return Boolean(
8500
+ typeof candidate.threadId === "string" && typeof candidate.prompt === "string" && Array.isArray(candidate.participantIds)
8501
+ );
8502
+ }
8503
+ async function handleStart2(job) {
8504
+ const chatRun = await loadChatRunActivity(job.data.chatRunId);
8505
+ if (!chatRun) {
8506
+ console.warn(`[chat-processor] Chat run ${job.data.chatRunId} not found, skipping`);
8507
+ return;
8508
+ }
8509
+ if (chatRun.status === "completed" || chatRun.status === "failed" || chatRun.status === "cancelled") {
8510
+ return;
8511
+ }
8512
+ if (!isChatRunPayload(chatRun.payload)) {
8513
+ await updateChatRunActivity({
8514
+ id: chatRun.id,
8515
+ status: "failed",
8516
+ lastError: "Chat run payload is missing or invalid",
8517
+ completedAt: Date.now()
8518
+ });
8519
+ return;
8520
+ }
8521
+ const step = await appendChatRunStepActivity({
8522
+ chatRunId: chatRun.id,
8523
+ kind: "model_turn",
8524
+ status: "running",
8525
+ inputPayload: {
8526
+ participantIds: chatRun.payload.participantIds,
8527
+ rootMessageId: chatRun.payload.rootMessageId,
8528
+ maxRounds: chatRun.payload.maxRounds
8529
+ }
8530
+ });
8531
+ await updateChatRunActivity({
8532
+ id: chatRun.id,
8533
+ status: "running",
8534
+ currentStep: step.stepIndex,
8535
+ stepsUsed: step.stepIndex,
8536
+ lastError: null
8537
+ });
8538
+ try {
8539
+ const library = await loadDbParticipants();
8540
+ const participantIdSet = new Set(chatRun.payload.participantIds);
8541
+ const participants = chatRun.payload.participantIds.map((participantId) => library.find((participant) => participant.id === participantId)).filter((participant) => Boolean(participant));
8542
+ if (participants.length === 0) {
8543
+ throw new Error("No participants resolved for chat run");
8544
+ }
8545
+ const mentioned = new Set(
8546
+ chatRun.payload.mentionedIds.filter((participantId) => participantIdSet.has(participantId))
8547
+ );
8548
+ const initialParallelIds = new Set(
8549
+ chatRun.payload.initialParallelIds.filter((participantId) => participantIdSet.has(participantId))
8550
+ );
8551
+ const stream = createMultiplexedStream({
8552
+ threadId: chatRun.payload.threadId,
8553
+ allParticipants: participants,
8554
+ mentioned,
8555
+ initialParallelIds,
8556
+ prompt: chatRun.payload.prompt,
8557
+ projectContext: chatRun.payload.projectContext,
8558
+ maxRounds: chatRun.payload.maxRounds,
8559
+ recentHistory: chatRun.payload.recentHistory,
8560
+ currentUserMessageId: chatRun.payload.currentUserMessageId,
8561
+ rootMessageId: chatRun.payload.rootMessageId
8562
+ });
8563
+ const reader = stream.getReader();
8564
+ while (true) {
8565
+ const { done } = await reader.read();
8566
+ if (done) break;
8567
+ }
8568
+ await completeChatRunStepActivity({
8569
+ stepId: step.id,
8570
+ status: "completed",
8571
+ outputPayload: {
8572
+ completed: true,
8573
+ participantCount: participants.length
8574
+ }
8575
+ });
8576
+ await updateChatRunActivity({
8577
+ id: chatRun.id,
8578
+ status: "completed",
8579
+ completedAt: Date.now(),
8580
+ result: {
8581
+ participantIds: participants.map((participant) => participant.id),
8582
+ rootMessageId: chatRun.payload.rootMessageId
8583
+ }
8584
+ });
8585
+ } catch (error) {
8586
+ const message = error instanceof Error ? error.message : String(error);
8587
+ await completeChatRunStepActivity({
8588
+ stepId: step.id,
8589
+ status: "failed",
8590
+ outputPayload: { error: message }
8591
+ });
8592
+ await updateChatRunActivity({
8593
+ id: chatRun.id,
8594
+ status: "failed",
8595
+ lastError: message,
8596
+ completedAt: Date.now(),
8597
+ result: { error: message }
8598
+ });
8599
+ }
8600
+ }
8601
+ async function handleCancel2(job) {
8602
+ const chatRun = await loadChatRunActivity(job.data.chatRunId);
8603
+ if (!chatRun) return;
8604
+ if (chatRun.rootMessageId) {
8605
+ killByThread(chatRun.rootMessageId);
8606
+ } else {
8607
+ killByWorkspace(chatRun.threadId);
8608
+ }
8609
+ await updateChatRunActivity({
8610
+ id: chatRun.id,
8611
+ status: "cancelled",
8612
+ lastError: job.data.payload?.reason || "Cancelled",
8613
+ completedAt: Date.now(),
8614
+ result: { cancelled: true }
8615
+ });
8616
+ }
8617
+ async function processSingleJob2(job) {
8618
+ switch (job.data.signal) {
8619
+ case "start":
8620
+ await handleStart2(job);
8621
+ break;
8622
+ case "cancel":
8623
+ await handleCancel2(job);
8624
+ break;
8625
+ default:
8626
+ console.warn(`[chat-processor] Unknown signal: ${job.data.signal}`);
8627
+ }
8628
+ }
8629
+ async function chatProcessor(jobs) {
8630
+ for (const job of jobs) {
8631
+ await processSingleJob2(job);
8632
+ }
8633
+ }
8634
+
8635
+ // ../agx-cloud/worker/index.ts
8636
+ async function main() {
8637
+ const requestedWorkers = Number(process.env.AGX_WORKER_COUNT) || 1;
8638
+ assertWorkerCount(requestedWorkers);
8639
+ console.log(`[worker] Starting SQLite worker (${requestedWorkers}/${MAX_WORKERS} max)...`);
8640
+ const queue2 = await getQueue();
8641
+ await queue2.work(
8642
+ QUEUE_NAMES.TASK_PROCESS,
8643
+ taskProcessor,
8644
+ { batchSize: 5 }
8645
+ );
8646
+ await queue2.work(
8647
+ QUEUE_NAMES.CHAT_RUN_PROCESS,
8648
+ chatProcessor,
8649
+ { batchSize: 2 }
5858
8650
  );
5859
8651
  console.log(`[worker] Listening on queue: ${QUEUE_NAMES.TASK_PROCESS}`);
8652
+ console.log(`[worker] Listening on queue: ${QUEUE_NAMES.CHAT_RUN_PROCESS}`);
5860
8653
  const shutdown = async (signal) => {
5861
8654
  console.log(`[worker] Received ${signal}, shutting down...`);
5862
8655
  await stopQueue();