rookery-agent 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (670) hide show
  1. package/README.md +467 -367
  2. package/docs/migration.md +88 -88
  3. package/docs/updates.md +112 -0
  4. package/package.json +13 -3
  5. package/packages/cli/dist/commands/config.js +2 -2
  6. package/packages/cli/dist/commands/doctor.d.ts.map +1 -1
  7. package/packages/cli/dist/commands/doctor.js +13 -9
  8. package/packages/cli/dist/commands/doctor.js.map +1 -1
  9. package/packages/cli/dist/commands/memory.js +1 -1
  10. package/packages/cli/dist/commands/org.d.ts +2 -2
  11. package/packages/cli/dist/commands/org.d.ts.map +1 -1
  12. package/packages/cli/dist/commands/org.js +19 -17
  13. package/packages/cli/dist/commands/org.js.map +1 -1
  14. package/packages/cli/dist/commands/serve.js +1 -1
  15. package/packages/cli/dist/commands/serve.js.map +1 -1
  16. package/packages/cli/dist/commands/shared.d.ts.map +1 -1
  17. package/packages/cli/dist/commands/shared.js +2 -1
  18. package/packages/cli/dist/commands/shared.js.map +1 -1
  19. package/packages/cli/dist/commands/tasks.d.ts.map +1 -1
  20. package/packages/cli/dist/commands/tasks.js +25 -11
  21. package/packages/cli/dist/commands/tasks.js.map +1 -1
  22. package/packages/cli/dist/commands/tools.js +1 -1
  23. package/packages/cli/dist/commands/tools.js.map +1 -1
  24. package/packages/cli/dist/index.js +13 -13
  25. package/packages/cli/dist/index.js.map +1 -1
  26. package/packages/cli/dist/repl.d.ts +12 -0
  27. package/packages/cli/dist/repl.d.ts.map +1 -1
  28. package/packages/cli/dist/repl.js +170 -16
  29. package/packages/cli/dist/repl.js.map +1 -1
  30. package/packages/cli/dist/tui/App.d.ts +7 -3
  31. package/packages/cli/dist/tui/App.d.ts.map +1 -1
  32. package/packages/cli/dist/tui/App.js +182 -16
  33. package/packages/cli/dist/tui/App.js.map +1 -1
  34. package/packages/cli/dist/tui/commands.d.ts +7 -0
  35. package/packages/cli/dist/tui/commands.d.ts.map +1 -1
  36. package/packages/cli/dist/tui/commands.js +70 -8
  37. package/packages/cli/dist/tui/commands.js.map +1 -1
  38. package/packages/cli/dist/tui/components/AssignmentsView.js +4 -4
  39. package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -1
  40. package/packages/cli/dist/tui/components/Banner.d.ts +11 -2
  41. package/packages/cli/dist/tui/components/Banner.d.ts.map +1 -1
  42. package/packages/cli/dist/tui/components/Banner.js +7 -10
  43. package/packages/cli/dist/tui/components/Banner.js.map +1 -1
  44. package/packages/cli/dist/tui/components/CodeBlock.js +2 -2
  45. package/packages/cli/dist/tui/components/CodeBlock.js.map +1 -1
  46. package/packages/cli/dist/tui/components/InputBox.d.ts.map +1 -1
  47. package/packages/cli/dist/tui/components/InputBox.js +4 -4
  48. package/packages/cli/dist/tui/components/InputBox.js.map +1 -1
  49. package/packages/cli/dist/tui/components/Logo.d.ts +56 -0
  50. package/packages/cli/dist/tui/components/Logo.d.ts.map +1 -0
  51. package/packages/cli/dist/tui/components/Logo.js +50 -0
  52. package/packages/cli/dist/tui/components/Logo.js.map +1 -0
  53. package/packages/cli/dist/tui/components/Markdown.js +8 -8
  54. package/packages/cli/dist/tui/components/Markdown.js.map +1 -1
  55. package/packages/cli/dist/tui/components/Message.d.ts +1 -1
  56. package/packages/cli/dist/tui/components/Message.d.ts.map +1 -1
  57. package/packages/cli/dist/tui/components/Message.js +5 -4
  58. package/packages/cli/dist/tui/components/Message.js.map +1 -1
  59. package/packages/cli/dist/tui/components/QuestionView.d.ts +29 -0
  60. package/packages/cli/dist/tui/components/QuestionView.d.ts.map +1 -0
  61. package/packages/cli/dist/tui/components/QuestionView.js +53 -0
  62. package/packages/cli/dist/tui/components/QuestionView.js.map +1 -0
  63. package/packages/cli/dist/tui/components/SlashPalette.d.ts +5 -2
  64. package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -1
  65. package/packages/cli/dist/tui/components/SlashPalette.js +2 -2
  66. package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -1
  67. package/packages/cli/dist/tui/components/StatusLine.d.ts +0 -2
  68. package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -1
  69. package/packages/cli/dist/tui/components/StatusLine.js +8 -5
  70. package/packages/cli/dist/tui/components/StatusLine.js.map +1 -1
  71. package/packages/cli/dist/tui/components/ToolGroup.js +2 -2
  72. package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -1
  73. package/packages/cli/dist/tui/components/WatchView.d.ts +21 -0
  74. package/packages/cli/dist/tui/components/WatchView.d.ts.map +1 -0
  75. package/packages/cli/dist/tui/components/WatchView.js +36 -0
  76. package/packages/cli/dist/tui/components/WatchView.js.map +1 -0
  77. package/packages/cli/dist/tui/history.d.ts +20 -0
  78. package/packages/cli/dist/tui/history.d.ts.map +1 -0
  79. package/packages/cli/dist/tui/history.js +105 -0
  80. package/packages/cli/dist/tui/history.js.map +1 -0
  81. package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -1
  82. package/packages/cli/dist/tui/hooks/useSlash.js +3 -2
  83. package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -1
  84. package/packages/cli/dist/tui/hooks/useTurn.d.ts +58 -1
  85. package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -1
  86. package/packages/cli/dist/tui/hooks/useTurn.js +214 -36
  87. package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -1
  88. package/packages/cli/dist/tui/hooks/useWatch.d.ts +52 -0
  89. package/packages/cli/dist/tui/hooks/useWatch.d.ts.map +1 -0
  90. package/packages/cli/dist/tui/hooks/useWatch.js +145 -0
  91. package/packages/cli/dist/tui/hooks/useWatch.js.map +1 -0
  92. package/packages/cli/dist/tui/inkTheme.d.ts +19 -0
  93. package/packages/cli/dist/tui/inkTheme.d.ts.map +1 -0
  94. package/packages/cli/dist/tui/inkTheme.js +81 -0
  95. package/packages/cli/dist/tui/inkTheme.js.map +1 -0
  96. package/packages/cli/dist/tui/theme.d.ts +39 -29
  97. package/packages/cli/dist/tui/theme.d.ts.map +1 -1
  98. package/packages/cli/dist/tui/theme.js +35 -25
  99. package/packages/cli/dist/tui/theme.js.map +1 -1
  100. package/packages/cli/dist/tui/types.d.ts +56 -3
  101. package/packages/cli/dist/tui/types.d.ts.map +1 -1
  102. package/packages/cli/dist/tui/types.js +85 -0
  103. package/packages/cli/dist/tui/types.js.map +1 -1
  104. package/packages/cli/dist/ui/modelNames.d.ts +51 -0
  105. package/packages/cli/dist/ui/modelNames.d.ts.map +1 -0
  106. package/packages/cli/dist/ui/modelNames.js +134 -0
  107. package/packages/cli/dist/ui/modelNames.js.map +1 -0
  108. package/packages/cli/dist/ui/render.d.ts.map +1 -1
  109. package/packages/cli/dist/ui/render.js +17 -8
  110. package/packages/cli/dist/ui/render.js.map +1 -1
  111. package/packages/cli/dist/ui/speech.js +5 -0
  112. package/packages/cli/dist/ui/speech.js.map +1 -1
  113. package/packages/cli/dist/ui/theme.d.ts +33 -9
  114. package/packages/cli/dist/ui/theme.d.ts.map +1 -1
  115. package/packages/cli/dist/ui/theme.js +33 -9
  116. package/packages/cli/dist/ui/theme.js.map +1 -1
  117. package/packages/cli/package.json +1 -1
  118. package/packages/core/dist/agents/persona.d.ts.map +1 -1
  119. package/packages/core/dist/agents/persona.js +5 -2
  120. package/packages/core/dist/agents/persona.js.map +1 -1
  121. package/packages/core/dist/computer/accessibility.d.ts +78 -0
  122. package/packages/core/dist/computer/accessibility.d.ts.map +1 -0
  123. package/packages/core/dist/computer/accessibility.js +270 -0
  124. package/packages/core/dist/computer/accessibility.js.map +1 -0
  125. package/packages/core/dist/computer/assemblies.d.ts +17 -0
  126. package/packages/core/dist/computer/assemblies.d.ts.map +1 -0
  127. package/packages/core/dist/computer/assemblies.js +55 -0
  128. package/packages/core/dist/computer/assemblies.js.map +1 -0
  129. package/packages/core/dist/computer/browser-init.d.ts +9 -0
  130. package/packages/core/dist/computer/browser-init.d.ts.map +1 -0
  131. package/packages/core/dist/computer/browser-init.js +133 -0
  132. package/packages/core/dist/computer/browser-init.js.map +1 -0
  133. package/packages/core/dist/computer/cursor.d.ts +30 -0
  134. package/packages/core/dist/computer/cursor.d.ts.map +1 -0
  135. package/packages/core/dist/computer/cursor.js +30 -0
  136. package/packages/core/dist/computer/cursor.js.map +1 -0
  137. package/packages/core/dist/computer/mcp-server.js +524 -82
  138. package/packages/core/dist/computer/mcp-server.js.map +1 -1
  139. package/packages/core/dist/computer/powershell.d.ts +4 -0
  140. package/packages/core/dist/computer/powershell.d.ts.map +1 -1
  141. package/packages/core/dist/computer/powershell.js +471 -81
  142. package/packages/core/dist/computer/powershell.js.map +1 -1
  143. package/packages/core/dist/computer/screen-text.d.ts +82 -0
  144. package/packages/core/dist/computer/screen-text.d.ts.map +1 -0
  145. package/packages/core/dist/computer/screen-text.js +243 -0
  146. package/packages/core/dist/computer/screen-text.js.map +1 -0
  147. package/packages/core/dist/computer/sketch.d.ts +66 -0
  148. package/packages/core/dist/computer/sketch.d.ts.map +1 -0
  149. package/packages/core/dist/computer/sketch.js +540 -0
  150. package/packages/core/dist/computer/sketch.js.map +1 -0
  151. package/packages/core/dist/computer/tools.d.ts +8 -8
  152. package/packages/core/dist/computer/tools.d.ts.map +1 -1
  153. package/packages/core/dist/computer/tools.js +186 -31
  154. package/packages/core/dist/computer/tools.js.map +1 -1
  155. package/packages/core/dist/computer/validation.d.ts +555 -0
  156. package/packages/core/dist/computer/validation.d.ts.map +1 -0
  157. package/packages/core/dist/computer/validation.js +111 -0
  158. package/packages/core/dist/computer/validation.js.map +1 -0
  159. package/packages/core/dist/computer/windows-cursor.d.ts +14 -0
  160. package/packages/core/dist/computer/windows-cursor.d.ts.map +1 -0
  161. package/packages/core/dist/computer/windows-cursor.js +713 -0
  162. package/packages/core/dist/computer/windows-cursor.js.map +1 -0
  163. package/packages/core/dist/config.d.ts +34 -1
  164. package/packages/core/dist/config.d.ts.map +1 -1
  165. package/packages/core/dist/config.js +362 -11
  166. package/packages/core/dist/config.js.map +1 -1
  167. package/packages/core/dist/cron/scheduler.d.ts +59 -6
  168. package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
  169. package/packages/core/dist/cron/scheduler.js +295 -27
  170. package/packages/core/dist/cron/scheduler.js.map +1 -1
  171. package/packages/core/dist/cron/store.d.ts +19 -1
  172. package/packages/core/dist/cron/store.d.ts.map +1 -1
  173. package/packages/core/dist/cron/store.js +36 -8
  174. package/packages/core/dist/cron/store.js.map +1 -1
  175. package/packages/core/dist/external/claude-code.d.ts +4 -0
  176. package/packages/core/dist/external/claude-code.d.ts.map +1 -0
  177. package/packages/core/dist/external/claude-code.js +111 -0
  178. package/packages/core/dist/external/claude-code.js.map +1 -0
  179. package/packages/core/dist/external/discovery.d.ts +33 -0
  180. package/packages/core/dist/external/discovery.d.ts.map +1 -0
  181. package/packages/core/dist/external/discovery.js +144 -0
  182. package/packages/core/dist/external/discovery.js.map +1 -0
  183. package/packages/core/dist/external/homes.d.ts +26 -0
  184. package/packages/core/dist/external/homes.d.ts.map +1 -0
  185. package/packages/core/dist/external/homes.js +49 -0
  186. package/packages/core/dist/external/homes.js.map +1 -0
  187. package/packages/core/dist/external/shared.d.ts +201 -0
  188. package/packages/core/dist/external/shared.d.ts.map +1 -0
  189. package/packages/core/dist/external/shared.js +308 -0
  190. package/packages/core/dist/external/shared.js.map +1 -0
  191. package/packages/core/dist/gateway/policy.d.ts +117 -2
  192. package/packages/core/dist/gateway/policy.d.ts.map +1 -1
  193. package/packages/core/dist/gateway/policy.js +286 -6
  194. package/packages/core/dist/gateway/policy.js.map +1 -1
  195. package/packages/core/dist/index.d.ts +38 -12
  196. package/packages/core/dist/index.d.ts.map +1 -1
  197. package/packages/core/dist/index.js +66 -12
  198. package/packages/core/dist/index.js.map +1 -1
  199. package/packages/core/dist/memory/db.d.ts +1 -1
  200. package/packages/core/dist/memory/db.d.ts.map +1 -1
  201. package/packages/core/dist/memory/db.js +878 -1
  202. package/packages/core/dist/memory/db.js.map +1 -1
  203. package/packages/core/dist/memory/dream/admission.d.ts +124 -0
  204. package/packages/core/dist/memory/dream/admission.d.ts.map +1 -0
  205. package/packages/core/dist/memory/dream/admission.js +116 -0
  206. package/packages/core/dist/memory/dream/admission.js.map +1 -0
  207. package/packages/core/dist/memory/dream/candidate.d.ts +152 -0
  208. package/packages/core/dist/memory/dream/candidate.d.ts.map +1 -0
  209. package/packages/core/dist/memory/dream/candidate.js +547 -0
  210. package/packages/core/dist/memory/dream/candidate.js.map +1 -0
  211. package/packages/core/dist/memory/dream/evaluate.d.ts +394 -0
  212. package/packages/core/dist/memory/dream/evaluate.d.ts.map +1 -0
  213. package/packages/core/dist/memory/dream/evaluate.js +1032 -0
  214. package/packages/core/dist/memory/dream/evaluate.js.map +1 -0
  215. package/packages/core/dist/memory/dream/frame.d.ts +61 -0
  216. package/packages/core/dist/memory/dream/frame.d.ts.map +1 -0
  217. package/packages/core/dist/memory/dream/frame.js +292 -0
  218. package/packages/core/dist/memory/dream/frame.js.map +1 -0
  219. package/packages/core/dist/memory/dream/label.d.ts +370 -0
  220. package/packages/core/dist/memory/dream/label.d.ts.map +1 -0
  221. package/packages/core/dist/memory/dream/label.js +439 -0
  222. package/packages/core/dist/memory/dream/label.js.map +1 -0
  223. package/packages/core/dist/memory/dream/measure.d.ts +114 -0
  224. package/packages/core/dist/memory/dream/measure.d.ts.map +1 -0
  225. package/packages/core/dist/memory/dream/measure.js +205 -0
  226. package/packages/core/dist/memory/dream/measure.js.map +1 -0
  227. package/packages/core/dist/memory/dream/policy.d.ts +21 -0
  228. package/packages/core/dist/memory/dream/policy.d.ts.map +1 -0
  229. package/packages/core/dist/memory/dream/policy.js +157 -0
  230. package/packages/core/dist/memory/dream/policy.js.map +1 -0
  231. package/packages/core/dist/memory/dream/probe.d.ts +202 -0
  232. package/packages/core/dist/memory/dream/probe.d.ts.map +1 -0
  233. package/packages/core/dist/memory/dream/probe.js +671 -0
  234. package/packages/core/dist/memory/dream/probe.js.map +1 -0
  235. package/packages/core/dist/memory/dream/promote.d.ts +312 -0
  236. package/packages/core/dist/memory/dream/promote.d.ts.map +1 -0
  237. package/packages/core/dist/memory/dream/promote.js +528 -0
  238. package/packages/core/dist/memory/dream/promote.js.map +1 -0
  239. package/packages/core/dist/memory/dream/score.d.ts +103 -0
  240. package/packages/core/dist/memory/dream/score.d.ts.map +1 -0
  241. package/packages/core/dist/memory/dream/score.js +334 -0
  242. package/packages/core/dist/memory/dream/score.js.map +1 -0
  243. package/packages/core/dist/memory/dream/slots.d.ts +193 -0
  244. package/packages/core/dist/memory/dream/slots.d.ts.map +1 -0
  245. package/packages/core/dist/memory/dream/slots.js +0 -0
  246. package/packages/core/dist/memory/dream/slots.js.map +1 -0
  247. package/packages/core/dist/memory/dream/trajectory.d.ts +262 -0
  248. package/packages/core/dist/memory/dream/trajectory.d.ts.map +1 -0
  249. package/packages/core/dist/memory/dream/trajectory.js +366 -0
  250. package/packages/core/dist/memory/dream/trajectory.js.map +1 -0
  251. package/packages/core/dist/memory/extractor.d.ts +7 -0
  252. package/packages/core/dist/memory/extractor.d.ts.map +1 -1
  253. package/packages/core/dist/memory/extractor.js +35 -12
  254. package/packages/core/dist/memory/extractor.js.map +1 -1
  255. package/packages/core/dist/memory/gate.d.ts +43 -7
  256. package/packages/core/dist/memory/gate.d.ts.map +1 -1
  257. package/packages/core/dist/memory/gate.js +91 -4
  258. package/packages/core/dist/memory/gate.js.map +1 -1
  259. package/packages/core/dist/memory/recall.d.ts +57 -0
  260. package/packages/core/dist/memory/recall.d.ts.map +1 -1
  261. package/packages/core/dist/memory/recall.js +60 -123
  262. package/packages/core/dist/memory/recall.js.map +1 -1
  263. package/packages/core/dist/memory/sleep.d.ts +131 -4
  264. package/packages/core/dist/memory/sleep.d.ts.map +1 -1
  265. package/packages/core/dist/memory/sleep.js +2384 -65
  266. package/packages/core/dist/memory/sleep.js.map +1 -1
  267. package/packages/core/dist/memory/store.d.ts +564 -10
  268. package/packages/core/dist/memory/store.d.ts.map +1 -1
  269. package/packages/core/dist/memory/store.js +1673 -102
  270. package/packages/core/dist/memory/store.js.map +1 -1
  271. package/packages/core/dist/org/controller.d.ts +268 -4
  272. package/packages/core/dist/org/controller.d.ts.map +1 -1
  273. package/packages/core/dist/org/controller.js +2298 -248
  274. package/packages/core/dist/org/controller.js.map +1 -1
  275. package/packages/core/dist/org/ponytail.d.ts +1 -1
  276. package/packages/core/dist/org/ponytail.js +1 -1
  277. package/packages/core/dist/org/project-mcp.d.ts +3 -3
  278. package/packages/core/dist/org/prompts.d.ts +44 -30
  279. package/packages/core/dist/org/prompts.d.ts.map +1 -1
  280. package/packages/core/dist/org/prompts.js +209 -92
  281. package/packages/core/dist/org/prompts.js.map +1 -1
  282. package/packages/core/dist/org/questions.d.ts +104 -0
  283. package/packages/core/dist/org/questions.d.ts.map +1 -0
  284. package/packages/core/dist/org/questions.js +136 -0
  285. package/packages/core/dist/org/questions.js.map +1 -0
  286. package/packages/core/dist/org/review.d.ts +100 -0
  287. package/packages/core/dist/org/review.d.ts.map +1 -0
  288. package/packages/core/dist/org/review.js +256 -0
  289. package/packages/core/dist/org/review.js.map +1 -0
  290. package/packages/core/dist/org/store.d.ts +311 -2
  291. package/packages/core/dist/org/store.d.ts.map +1 -1
  292. package/packages/core/dist/org/store.js +981 -13
  293. package/packages/core/dist/org/store.js.map +1 -1
  294. package/packages/core/dist/org/tools.d.ts +33 -3
  295. package/packages/core/dist/org/tools.d.ts.map +1 -1
  296. package/packages/core/dist/org/tools.js +380 -67
  297. package/packages/core/dist/org/tools.js.map +1 -1
  298. package/packages/core/dist/providers/catalogue.d.ts +1 -1
  299. package/packages/core/dist/providers/catalogue.d.ts.map +1 -1
  300. package/packages/core/dist/providers/catalogue.js +2 -2
  301. package/packages/core/dist/providers/catalogue.js.map +1 -1
  302. package/packages/core/dist/providers/claude-code.d.ts +19 -3
  303. package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
  304. package/packages/core/dist/providers/claude-code.js +501 -40
  305. package/packages/core/dist/providers/claude-code.js.map +1 -1
  306. package/packages/core/dist/providers/claude-tui.d.ts +288 -0
  307. package/packages/core/dist/providers/claude-tui.d.ts.map +1 -0
  308. package/packages/core/dist/providers/claude-tui.js +1118 -0
  309. package/packages/core/dist/providers/claude-tui.js.map +1 -0
  310. package/packages/core/dist/providers/codex-auth.d.ts +15 -0
  311. package/packages/core/dist/providers/codex-auth.d.ts.map +1 -0
  312. package/packages/core/dist/providers/codex-auth.js +127 -0
  313. package/packages/core/dist/providers/codex-auth.js.map +1 -0
  314. package/packages/core/dist/providers/codex-bridge.d.ts +58 -0
  315. package/packages/core/dist/providers/codex-bridge.d.ts.map +1 -0
  316. package/packages/core/dist/providers/codex-bridge.js +375 -0
  317. package/packages/core/dist/providers/codex-bridge.js.map +1 -0
  318. package/packages/core/dist/providers/codex-translate.d.ts +75 -0
  319. package/packages/core/dist/providers/codex-translate.d.ts.map +1 -0
  320. package/packages/core/dist/providers/codex-translate.js +383 -0
  321. package/packages/core/dist/providers/codex-translate.js.map +1 -0
  322. package/packages/core/dist/providers/model-gateway.d.ts +56 -0
  323. package/packages/core/dist/providers/model-gateway.d.ts.map +1 -0
  324. package/packages/core/dist/providers/model-gateway.js +119 -0
  325. package/packages/core/dist/providers/model-gateway.js.map +1 -0
  326. package/packages/core/dist/providers/process.d.ts +3 -1
  327. package/packages/core/dist/providers/process.d.ts.map +1 -1
  328. package/packages/core/dist/providers/process.js +3 -3
  329. package/packages/core/dist/providers/process.js.map +1 -1
  330. package/packages/core/dist/providers/profiles.d.ts +11 -0
  331. package/packages/core/dist/providers/profiles.d.ts.map +1 -0
  332. package/packages/core/dist/providers/profiles.js +28 -0
  333. package/packages/core/dist/providers/profiles.js.map +1 -0
  334. package/packages/core/dist/providers/provider-catalog.d.ts +72 -0
  335. package/packages/core/dist/providers/provider-catalog.d.ts.map +1 -0
  336. package/packages/core/dist/providers/provider-catalog.js +144 -0
  337. package/packages/core/dist/providers/provider-catalog.js.map +1 -0
  338. package/packages/core/dist/providers/quota.d.ts +40 -1
  339. package/packages/core/dist/providers/quota.d.ts.map +1 -1
  340. package/packages/core/dist/providers/quota.js +288 -25
  341. package/packages/core/dist/providers/quota.js.map +1 -1
  342. package/packages/core/dist/providers/registry.d.ts +46 -3
  343. package/packages/core/dist/providers/registry.d.ts.map +1 -1
  344. package/packages/core/dist/providers/registry.js +148 -13
  345. package/packages/core/dist/providers/registry.js.map +1 -1
  346. package/packages/core/dist/providers/router.d.ts +28 -0
  347. package/packages/core/dist/providers/router.d.ts.map +1 -0
  348. package/packages/core/dist/providers/router.js +88 -0
  349. package/packages/core/dist/providers/router.js.map +1 -0
  350. package/packages/core/dist/providers/user-settings-guard.d.ts +12 -0
  351. package/packages/core/dist/providers/user-settings-guard.d.ts.map +1 -0
  352. package/packages/core/dist/providers/user-settings-guard.js +130 -0
  353. package/packages/core/dist/providers/user-settings-guard.js.map +1 -0
  354. package/packages/core/dist/runtime.d.ts +193 -7
  355. package/packages/core/dist/runtime.d.ts.map +1 -1
  356. package/packages/core/dist/runtime.js +1676 -219
  357. package/packages/core/dist/runtime.js.map +1 -1
  358. package/packages/core/dist/skills/builtin.d.ts +34 -0
  359. package/packages/core/dist/skills/builtin.d.ts.map +1 -0
  360. package/packages/core/dist/skills/builtin.js +305 -0
  361. package/packages/core/dist/skills/builtin.js.map +1 -0
  362. package/packages/core/dist/skills/shelf.d.ts +30 -0
  363. package/packages/core/dist/skills/shelf.d.ts.map +1 -0
  364. package/packages/core/dist/skills/shelf.js +159 -0
  365. package/packages/core/dist/skills/shelf.js.map +1 -0
  366. package/packages/core/dist/skills/store.d.ts +66 -4
  367. package/packages/core/dist/skills/store.d.ts.map +1 -1
  368. package/packages/core/dist/skills/store.js +105 -18
  369. package/packages/core/dist/skills/store.js.map +1 -1
  370. package/packages/core/dist/skills/suggest.d.ts +21 -0
  371. package/packages/core/dist/skills/suggest.d.ts.map +1 -0
  372. package/packages/core/dist/skills/suggest.js +150 -0
  373. package/packages/core/dist/skills/suggest.js.map +1 -0
  374. package/packages/core/dist/tools/catalog.d.ts +1 -3
  375. package/packages/core/dist/tools/catalog.d.ts.map +1 -1
  376. package/packages/core/dist/tools/catalog.js +38 -26
  377. package/packages/core/dist/tools/catalog.js.map +1 -1
  378. package/packages/core/dist/tools/hub.d.ts +136 -10
  379. package/packages/core/dist/tools/hub.d.ts.map +1 -1
  380. package/packages/core/dist/tools/hub.js +418 -24
  381. package/packages/core/dist/tools/hub.js.map +1 -1
  382. package/packages/core/dist/turns/journal.d.ts +78 -0
  383. package/packages/core/dist/turns/journal.d.ts.map +1 -0
  384. package/packages/core/dist/turns/journal.js +104 -0
  385. package/packages/core/dist/turns/journal.js.map +1 -0
  386. package/packages/core/dist/types.d.ts +1776 -12
  387. package/packages/core/dist/types.d.ts.map +1 -1
  388. package/packages/core/dist/types.js.map +1 -1
  389. package/packages/core/dist/util/blocks.d.ts +41 -0
  390. package/packages/core/dist/util/blocks.d.ts.map +1 -0
  391. package/packages/core/dist/util/blocks.js +175 -0
  392. package/packages/core/dist/util/blocks.js.map +1 -0
  393. package/packages/core/dist/util/queue.d.ts +12 -0
  394. package/packages/core/dist/util/queue.d.ts.map +1 -1
  395. package/packages/core/dist/util/queue.js +16 -0
  396. package/packages/core/dist/util/queue.js.map +1 -1
  397. package/packages/core/dist/util/time.d.ts +39 -0
  398. package/packages/core/dist/util/time.d.ts.map +1 -0
  399. package/packages/core/dist/util/time.js +71 -0
  400. package/packages/core/dist/util/time.js.map +1 -0
  401. package/packages/core/package.json +1 -1
  402. package/packages/server/dist/auth.d.ts +14 -1
  403. package/packages/server/dist/auth.d.ts.map +1 -1
  404. package/packages/server/dist/auth.js +19 -0
  405. package/packages/server/dist/auth.js.map +1 -1
  406. package/packages/server/dist/context.d.ts +35 -1
  407. package/packages/server/dist/context.d.ts.map +1 -1
  408. package/packages/server/dist/context.js +39 -10
  409. package/packages/server/dist/context.js.map +1 -1
  410. package/packages/server/dist/gateways/attachments.d.ts +32 -0
  411. package/packages/server/dist/gateways/attachments.d.ts.map +1 -0
  412. package/packages/server/dist/gateways/attachments.js +167 -0
  413. package/packages/server/dist/gateways/attachments.js.map +1 -0
  414. package/packages/server/dist/gateways/markdown.d.ts +9 -0
  415. package/packages/server/dist/gateways/markdown.d.ts.map +1 -0
  416. package/packages/server/dist/gateways/markdown.js +170 -0
  417. package/packages/server/dist/gateways/markdown.js.map +1 -0
  418. package/packages/server/dist/gateways/push.d.ts +1 -1
  419. package/packages/server/dist/gateways/push.d.ts.map +1 -1
  420. package/packages/server/dist/gateways/push.js +420 -13
  421. package/packages/server/dist/gateways/push.js.map +1 -1
  422. package/packages/server/dist/gateways/telegram-api.d.ts +70 -1
  423. package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -1
  424. package/packages/server/dist/gateways/telegram-api.js +140 -1
  425. package/packages/server/dist/gateways/telegram-api.js.map +1 -1
  426. package/packages/server/dist/gateways/telegram.d.ts +181 -1
  427. package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
  428. package/packages/server/dist/gateways/telegram.js +1572 -78
  429. package/packages/server/dist/gateways/telegram.js.map +1 -1
  430. package/packages/server/dist/gateways/threads.d.ts +84 -0
  431. package/packages/server/dist/gateways/threads.d.ts.map +1 -0
  432. package/packages/server/dist/gateways/threads.js +289 -0
  433. package/packages/server/dist/gateways/threads.js.map +1 -0
  434. package/packages/server/dist/index.d.ts +2 -1
  435. package/packages/server/dist/index.d.ts.map +1 -1
  436. package/packages/server/dist/index.js +2 -1
  437. package/packages/server/dist/index.js.map +1 -1
  438. package/packages/server/dist/listeners/imap.d.ts +13 -0
  439. package/packages/server/dist/listeners/imap.d.ts.map +1 -0
  440. package/packages/server/dist/listeners/imap.js +0 -0
  441. package/packages/server/dist/listeners/imap.js.map +1 -0
  442. package/packages/server/dist/listeners/registry.d.ts +18 -0
  443. package/packages/server/dist/listeners/registry.d.ts.map +1 -0
  444. package/packages/server/dist/listeners/registry.js +88 -0
  445. package/packages/server/dist/listeners/registry.js.map +1 -0
  446. package/packages/server/dist/listeners/types.d.ts +55 -0
  447. package/packages/server/dist/listeners/types.d.ts.map +1 -0
  448. package/packages/server/dist/listeners/types.js +2 -0
  449. package/packages/server/dist/listeners/types.js.map +1 -0
  450. package/packages/server/dist/main.js +15 -1
  451. package/packages/server/dist/main.js.map +1 -1
  452. package/packages/server/dist/routes/chat.d.ts +7 -3
  453. package/packages/server/dist/routes/chat.d.ts.map +1 -1
  454. package/packages/server/dist/routes/chat.js +8 -17
  455. package/packages/server/dist/routes/chat.js.map +1 -1
  456. package/packages/server/dist/routes/config.d.ts.map +1 -1
  457. package/packages/server/dist/routes/config.js +66 -7
  458. package/packages/server/dist/routes/config.js.map +1 -1
  459. package/packages/server/dist/routes/cron.d.ts.map +1 -1
  460. package/packages/server/dist/routes/cron.js +65 -8
  461. package/packages/server/dist/routes/cron.js.map +1 -1
  462. package/packages/server/dist/routes/dream.d.ts +22 -0
  463. package/packages/server/dist/routes/dream.d.ts.map +1 -0
  464. package/packages/server/dist/routes/dream.js +152 -0
  465. package/packages/server/dist/routes/dream.js.map +1 -0
  466. package/packages/server/dist/routes/hooks.d.ts +18 -0
  467. package/packages/server/dist/routes/hooks.d.ts.map +1 -0
  468. package/packages/server/dist/routes/hooks.js +62 -0
  469. package/packages/server/dist/routes/hooks.js.map +1 -0
  470. package/packages/server/dist/routes/listeners.d.ts +10 -0
  471. package/packages/server/dist/routes/listeners.d.ts.map +1 -0
  472. package/packages/server/dist/routes/listeners.js +12 -0
  473. package/packages/server/dist/routes/listeners.js.map +1 -0
  474. package/packages/server/dist/routes/memories.d.ts.map +1 -1
  475. package/packages/server/dist/routes/memories.js +55 -3
  476. package/packages/server/dist/routes/memories.js.map +1 -1
  477. package/packages/server/dist/routes/org.d.ts.map +1 -1
  478. package/packages/server/dist/routes/org.js +289 -49
  479. package/packages/server/dist/routes/org.js.map +1 -1
  480. package/packages/server/dist/routes/profile.d.ts.map +1 -1
  481. package/packages/server/dist/routes/profile.js +6 -3
  482. package/packages/server/dist/routes/profile.js.map +1 -1
  483. package/packages/server/dist/routes/providers.d.ts.map +1 -1
  484. package/packages/server/dist/routes/providers.js +66 -7
  485. package/packages/server/dist/routes/providers.js.map +1 -1
  486. package/packages/server/dist/routes/questions.d.ts +45 -0
  487. package/packages/server/dist/routes/questions.d.ts.map +1 -0
  488. package/packages/server/dist/routes/questions.js +73 -0
  489. package/packages/server/dist/routes/questions.js.map +1 -0
  490. package/packages/server/dist/routes/sessions.d.ts.map +1 -1
  491. package/packages/server/dist/routes/sessions.js +26 -6
  492. package/packages/server/dist/routes/sessions.js.map +1 -1
  493. package/packages/server/dist/routes/sleep.d.ts.map +1 -1
  494. package/packages/server/dist/routes/sleep.js +71 -2
  495. package/packages/server/dist/routes/sleep.js.map +1 -1
  496. package/packages/server/dist/routes/terminals.d.ts +25 -0
  497. package/packages/server/dist/routes/terminals.d.ts.map +1 -0
  498. package/packages/server/dist/routes/terminals.js +35 -0
  499. package/packages/server/dist/routes/terminals.js.map +1 -0
  500. package/packages/server/dist/routes/tools.d.ts.map +1 -1
  501. package/packages/server/dist/routes/tools.js +140 -6
  502. package/packages/server/dist/routes/tools.js.map +1 -1
  503. package/packages/server/dist/routes/updates.d.ts +10 -0
  504. package/packages/server/dist/routes/updates.d.ts.map +1 -0
  505. package/packages/server/dist/routes/updates.js +22 -0
  506. package/packages/server/dist/routes/updates.js.map +1 -0
  507. package/packages/server/dist/routes/ws.d.ts +11 -5
  508. package/packages/server/dist/routes/ws.d.ts.map +1 -1
  509. package/packages/server/dist/routes/ws.js +168 -28
  510. package/packages/server/dist/routes/ws.js.map +1 -1
  511. package/packages/server/dist/schemas.d.ts +1177 -215
  512. package/packages/server/dist/schemas.d.ts.map +1 -1
  513. package/packages/server/dist/schemas.js +317 -12
  514. package/packages/server/dist/schemas.js.map +1 -1
  515. package/packages/server/dist/server.d.ts +7 -1
  516. package/packages/server/dist/server.d.ts.map +1 -1
  517. package/packages/server/dist/server.js +210 -3
  518. package/packages/server/dist/server.js.map +1 -1
  519. package/packages/server/dist/services/stream.d.ts +94 -5
  520. package/packages/server/dist/services/stream.d.ts.map +1 -1
  521. package/packages/server/dist/services/stream.js +9 -20
  522. package/packages/server/dist/services/stream.js.map +1 -1
  523. package/packages/server/dist/services/stt.d.ts +65 -0
  524. package/packages/server/dist/services/stt.d.ts.map +1 -0
  525. package/packages/server/dist/services/stt.js +306 -0
  526. package/packages/server/dist/services/stt.js.map +1 -0
  527. package/packages/server/dist/services/turns.d.ts +54 -0
  528. package/packages/server/dist/services/turns.d.ts.map +1 -0
  529. package/packages/server/dist/services/turns.js +186 -0
  530. package/packages/server/dist/services/turns.js.map +1 -0
  531. package/packages/server/dist/services/updates.d.ts +99 -0
  532. package/packages/server/dist/services/updates.d.ts.map +1 -0
  533. package/packages/server/dist/services/updates.js +316 -0
  534. package/packages/server/dist/services/updates.js.map +1 -0
  535. package/packages/server/package.json +1 -1
  536. package/packages/web/dist/app-icon.svg +2 -0
  537. package/packages/web/dist/apple-touch-icon.png +0 -0
  538. package/packages/web/dist/assets/abnfDiagram-O67JEVCF-D7YyFndQ.js +1 -0
  539. package/packages/web/dist/assets/arc-C_Zgk2dJ.js +1 -0
  540. package/packages/web/dist/assets/architectureDiagram-NJMV4G6O-eI0adu1B.js +36 -0
  541. package/packages/web/dist/assets/blockDiagram-BEXU5L5S-WAoOFUA9.js +140 -0
  542. package/packages/web/dist/assets/c4Diagram-YGBWAQC7-DE8Zyhng.js +38 -0
  543. package/packages/web/dist/assets/channel-egZxcyUK.js +1 -0
  544. package/packages/web/dist/assets/chunk-2Q5K7J3B-bnqLP2XD.js +1 -0
  545. package/packages/web/dist/assets/chunk-3FUC2YCW-Ck1_SVe0.js +2 -0
  546. package/packages/web/dist/assets/chunk-5VM5RSS4-hDmC41gD.js +15 -0
  547. package/packages/web/dist/assets/chunk-GTNCS2PH-PoWvfCrT.js +88 -0
  548. package/packages/web/dist/assets/chunk-GWA4HPMP-D3V0IG43.js +1 -0
  549. package/packages/web/dist/assets/chunk-JWPE2WC7-BryfpHM5.js +1 -0
  550. package/packages/web/dist/assets/chunk-NETBCI7D-8ic1iEdT.js +1 -0
  551. package/packages/web/dist/assets/chunk-WEXAMYUT-nM8tmQT2.js +1 -0
  552. package/packages/web/dist/assets/chunk-XXDRQBXY-Do28F482.js +1 -0
  553. package/packages/web/dist/assets/classDiagram-v2-NBCMYWYE-Bop9oNNO.js +217 -0
  554. package/packages/web/dist/assets/cose-bilkent-JH36ORCC-a7f_bpnt.js +1 -0
  555. package/packages/web/dist/assets/cynefin-OW5HDTMX-DnArcis_.js +178 -0
  556. package/packages/web/dist/assets/cynefinDiagram-VND7K2PF-vEuTb1GD.js +62 -0
  557. package/packages/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
  558. package/packages/web/dist/assets/dagre-6A5THRUB-BgG4MynJ.js +4 -0
  559. package/packages/web/dist/assets/diagram-22UHCM2B-DRCQpafv.js +200 -0
  560. package/packages/web/dist/assets/diagram-3UASUU5V-BKgmAXde.js +24 -0
  561. package/packages/web/dist/assets/diagram-ATOU4E4O-B6Hsy36X.js +3 -0
  562. package/packages/web/dist/assets/diagram-CDSNMT55-JflyfyoB.js +30 -0
  563. package/packages/web/dist/assets/diagram-MLGK6HIB-Dd2QPJjT.js +24 -0
  564. package/packages/web/dist/assets/diagram-MPIPVDR6-DE5QU60x.js +41 -0
  565. package/packages/web/dist/assets/draco_decoder-C32yEggz.wasm +0 -0
  566. package/packages/web/dist/assets/draco_decoder-Z1_iN-Ht.wasm +0 -0
  567. package/packages/web/dist/assets/draco_decoder-fzg4nYZr.js +34 -0
  568. package/packages/web/dist/assets/draco_wasm_wrapper-DxJM36Ib.js +117 -0
  569. package/packages/web/dist/assets/draco_wasm_wrapper-fZCQGLGb.js +116 -0
  570. package/packages/web/dist/assets/ebnfDiagram-ZINNZB2B-D7AQ741b.js +1 -0
  571. package/packages/web/dist/assets/elk-276RUBZZ-CeewBVLF.js +27 -0
  572. package/packages/web/dist/assets/erDiagram-OPXOYQCR-mLLYkZ5c.js +99 -0
  573. package/packages/web/dist/assets/flowDiagram-KWPJA3E3-DtpSpsQN.js +213 -0
  574. package/packages/web/dist/assets/ganttDiagram-FUAMR5RP-1_lh-3ky.js +292 -0
  575. package/packages/web/dist/assets/gitGraphDiagram-X574FWY7-DoPXZuT5.js +106 -0
  576. package/packages/web/dist/assets/graph-Bn3Yngep.js +1 -0
  577. package/packages/web/dist/assets/index-Cw2Opmx7.js +648 -0
  578. package/packages/web/dist/assets/index-j0zBRCgT.css +32 -0
  579. package/packages/web/dist/assets/infoDiagram-VRGFBTTK-DQpRGGiD.js +2 -0
  580. package/packages/web/dist/assets/ishikawaDiagram-OU5B5YK6-gH5C9Q2e.js +70 -0
  581. package/packages/web/dist/assets/journeyDiagram-ZHPQQLJL-Bg-oeFjb.js +139 -0
  582. package/packages/web/dist/assets/kanban-definition-PNTS6WVX-BnpI4VH8.js +89 -0
  583. package/packages/web/dist/assets/katex-C5jXJg4s.js +257 -0
  584. package/packages/web/dist/assets/mermaid.core-BwBKxlRA.js +313 -0
  585. package/packages/web/dist/assets/mindmap-definition-NLK3R4M7-NBnnxEoO.js +96 -0
  586. package/packages/web/dist/assets/pegDiagram-GJSIUBJH-RrXXbIvO.js +1 -0
  587. package/packages/web/dist/assets/pieDiagram-5QR66LMP-B27q6Gso.js +39 -0
  588. package/packages/web/dist/assets/quadrantDiagram-O4NWA36T-DGDsdur2.js +7 -0
  589. package/packages/web/dist/assets/railroadDiagram-XR7U4H2S-GdjkE3mI.js +1 -0
  590. package/packages/web/dist/assets/requirementDiagram-PLB6GJNP-DjK0GfgO.js +84 -0
  591. package/packages/web/dist/assets/sankeyDiagram-IPEJSGJF-BG_AIkwF.js +40 -0
  592. package/packages/web/dist/assets/scene-D4LPicHk.js +4620 -0
  593. package/packages/web/dist/assets/sequenceDiagram-PO4LG4MO-CIQwUb4y.js +169 -0
  594. package/packages/web/dist/assets/sizeCapture-INFHLROL-bpIoPxdJ.js +1 -0
  595. package/packages/web/dist/assets/stateDiagram-v2-GCMORJYK-8hYXvPPv.js +291 -0
  596. package/packages/web/dist/assets/swimlanes-2SLR337P-gfflUMF9.js +1 -0
  597. package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-9wdzGXU-.js +8 -0
  598. package/packages/web/dist/assets/timeline-definition-EJHVYXUP-PHMNoGTZ.js +120 -0
  599. package/packages/web/dist/assets/usecaseDiagram-POWQR4AR-B2j5iteO.js +370 -0
  600. package/packages/web/dist/assets/vennDiagram-UO4OBE2U-BzxtZ-_2.js +34 -0
  601. package/packages/web/dist/assets/wardleyDiagram-VNRHLVJA-DL7YbMpY.js +78 -0
  602. package/packages/web/dist/assets/xychartDiagram-PMCCYNJV-CisgP1cT.js +7 -0
  603. package/packages/web/dist/draco/draco_decoder.js +33 -0
  604. package/packages/web/dist/draco/draco_decoder.wasm +0 -0
  605. package/packages/web/dist/draco/draco_wasm_wrapper.js +116 -0
  606. package/packages/web/dist/favicon-16.png +0 -0
  607. package/packages/web/dist/favicon-32.png +0 -0
  608. package/packages/web/dist/favicon-48.png +0 -0
  609. package/packages/web/dist/favicon.ico +0 -0
  610. package/packages/web/dist/favicon.svg +1 -1
  611. package/packages/web/dist/icon-192.png +0 -0
  612. package/packages/web/dist/icon-512.png +0 -0
  613. package/packages/web/dist/index.html +12 -4
  614. package/packages/web/dist/logo-light.svg +1 -1
  615. package/packages/web/dist/logo-mono.svg +2 -0
  616. package/packages/web/dist/logo-stacked-light.svg +2 -0
  617. package/packages/web/dist/logo-stacked.svg +2 -0
  618. package/packages/web/dist/logo-white.svg +2 -0
  619. package/packages/web/dist/logo.svg +1 -1
  620. package/packages/web/dist/mark-light.svg +1 -1
  621. package/packages/web/dist/mark-mono.svg +2 -0
  622. package/packages/web/dist/mark-small-light.svg +2 -0
  623. package/packages/web/dist/mark-small.svg +2 -0
  624. package/packages/web/dist/mark-white.svg +2 -0
  625. package/packages/web/dist/mark.svg +1 -1
  626. package/packages/web/dist/models/LICENSE.txt +5 -0
  627. package/packages/web/dist/models/brain.glb +0 -0
  628. package/packages/web/dist/site.webmanifest +23 -0
  629. package/packages/web/dist/wordmark-light.svg +2 -0
  630. package/packages/web/dist/wordmark.svg +2 -0
  631. package/packages/web/package.json +1 -1
  632. package/scripts/rookery.mjs +204 -122
  633. package/scripts/updater.mjs +227 -0
  634. package/packages/cli/dist/tui/components/Wordmark.d.ts +0 -35
  635. package/packages/cli/dist/tui/components/Wordmark.d.ts.map +0 -1
  636. package/packages/cli/dist/tui/components/Wordmark.js +0 -81
  637. package/packages/cli/dist/tui/components/Wordmark.js.map +0 -1
  638. package/packages/core/dist/agents/orchestrator.d.ts +0 -24
  639. package/packages/core/dist/agents/orchestrator.d.ts.map +0 -1
  640. package/packages/core/dist/agents/orchestrator.js +0 -88
  641. package/packages/core/dist/agents/orchestrator.js.map +0 -1
  642. package/packages/core/dist/agents/roles.d.ts +0 -21
  643. package/packages/core/dist/agents/roles.d.ts.map +0 -1
  644. package/packages/core/dist/agents/roles.js +0 -81
  645. package/packages/core/dist/agents/roles.js.map +0 -1
  646. package/packages/core/dist/agents/team.d.ts +0 -105
  647. package/packages/core/dist/agents/team.d.ts.map +0 -1
  648. package/packages/core/dist/agents/team.js +0 -623
  649. package/packages/core/dist/agents/team.js.map +0 -1
  650. package/packages/core/dist/providers/codex.d.ts +0 -10
  651. package/packages/core/dist/providers/codex.d.ts.map +0 -1
  652. package/packages/core/dist/providers/codex.js +0 -375
  653. package/packages/core/dist/providers/codex.js.map +0 -1
  654. package/packages/core/dist/tools/browser.d.ts +0 -20
  655. package/packages/core/dist/tools/browser.d.ts.map +0 -1
  656. package/packages/core/dist/tools/browser.js +0 -72
  657. package/packages/core/dist/tools/browser.js.map +0 -1
  658. package/packages/server/dist/routes/agents.d.ts +0 -5
  659. package/packages/server/dist/routes/agents.d.ts.map +0 -1
  660. package/packages/server/dist/routes/agents.js +0 -6
  661. package/packages/server/dist/routes/agents.js.map +0 -1
  662. package/packages/server/dist/routes/team.d.ts +0 -11
  663. package/packages/server/dist/routes/team.d.ts.map +0 -1
  664. package/packages/server/dist/routes/team.js +0 -36
  665. package/packages/server/dist/routes/team.js.map +0 -1
  666. package/packages/web/dist/assets/3d-force-graph-BPZmoydi.js +0 -1163
  667. package/packages/web/dist/assets/index-IBSTzK7-.js +0 -1255
  668. package/packages/web/dist/assets/index-qUXUui7W.css +0 -1
  669. package/packages/web/dist/assets/three-spritetext-B9ZIW7c-.js +0 -4
  670. package/packages/web/dist/assets/three.module-cmFfBtHS.js +0 -4228
@@ -1,4 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { reviewLabel } from '../memory/dream/label.js';
3
+ import { titleFromBrief } from '../util/queue.js';
2
4
  /**
3
5
  * Persistence for the organisation: companies, projects, teams, agents,
4
6
  * assignments and inter-agent messages. Pure CRUD; the rules about who may
@@ -139,6 +141,7 @@ export class OrgStore {
139
141
  name: input.name.trim() || 'Unnamed',
140
142
  title: input.title.trim() || 'Staff member',
141
143
  instructions: input.instructions.trim(),
144
+ voice: blank(input.voice),
142
145
  teamId: blank(input.teamId),
143
146
  managerId: blank(input.managerId),
144
147
  provider: input.provider,
@@ -150,10 +153,10 @@ export class OrgStore {
150
153
  };
151
154
  this.#db
152
155
  .prepare(`INSERT INTO agents
153
- (id, org_id, slug, name, title, instructions, team_id, manager_id, provider, model, permission,
156
+ (id, org_id, slug, name, title, instructions, voice, team_id, manager_id, provider, model, permission,
154
157
  created_at, updated_at, archived)
155
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)`)
156
- .run(agent.id, agent.orgId, agent.slug, agent.name, agent.title, agent.instructions, agent.teamId ?? null, agent.managerId ?? null, agent.provider ?? null, agent.model ?? null, agent.permission ?? null, now, now);
158
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)`)
159
+ .run(agent.id, agent.orgId, agent.slug, agent.name, agent.title, agent.instructions, agent.voice ?? null, agent.teamId ?? null, agent.managerId ?? null, agent.provider ?? null, agent.model ?? null, agent.permission ?? null, now, now);
157
160
  return agent;
158
161
  }
159
162
  getAgent(id) {
@@ -202,6 +205,7 @@ export class OrgStore {
202
205
  name: patch.name?.trim(),
203
206
  title: patch.title?.trim(),
204
207
  instructions: patch.instructions?.trim(),
208
+ voice: patch.voice === undefined ? undefined : patch.voice === null ? null : patch.voice.trim() || null,
205
209
  team_id: patch.teamId,
206
210
  manager_id: patch.managerId,
207
211
  provider: patch.provider,
@@ -239,6 +243,7 @@ export class OrgStore {
239
243
  parentId: blank(input.parentId),
240
244
  requesterKind: input.requesterKind,
241
245
  requesterAgentId: blank(input.requesterAgentId),
246
+ title: input.title?.trim() || titleFromBrief(input.task),
242
247
  task: input.task.trim(),
243
248
  status: 'pending',
244
249
  chars: 0,
@@ -248,9 +253,9 @@ export class OrgStore {
248
253
  this.#db
249
254
  .prepare(`INSERT INTO assignments
250
255
  (id, org_id, agent_id, project_id, session_id, parent_id, requester_kind, requester_agent_id,
251
- task, status, chars, depth, created_at)
252
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', 0, ?, ?)`)
253
- .run(assignment.id, assignment.orgId, assignment.agentId, assignment.projectId ?? null, assignment.sessionId ?? null, assignment.parentId ?? null, assignment.requesterKind, assignment.requesterAgentId ?? null, assignment.task, assignment.depth, now);
256
+ title, task, status, chars, depth, created_at)
257
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', 0, ?, ?)`)
258
+ .run(assignment.id, assignment.orgId, assignment.agentId, assignment.projectId ?? null, assignment.sessionId ?? null, assignment.parentId ?? null, assignment.requesterKind, assignment.requesterAgentId ?? null, assignment.title, assignment.task, assignment.depth, now);
254
259
  return assignment;
255
260
  }
256
261
  getAssignment(id) {
@@ -291,6 +296,23 @@ export class OrgStore {
291
296
  duration_ms: patch.durationMs,
292
297
  }, false);
293
298
  }
299
+ /**
300
+ * Assignments still marked pending/running from a previous process are
301
+ * failed on startup, mirroring `CronStore.failStaleRuns` (cron/store.ts).
302
+ * Returns the rows it changed so the caller can announce them.
303
+ */
304
+ failStaleAssignments(reason) {
305
+ const now = Date.now();
306
+ const rows = this.#db
307
+ .prepare("SELECT * FROM assignments WHERE status IN ('pending', 'running')")
308
+ .all();
309
+ if (!rows.length)
310
+ return [];
311
+ this.#db
312
+ .prepare("UPDATE assignments SET status = 'failed', error = ?, finished_at = ? WHERE status IN ('pending', 'running')")
313
+ .run(reason, now);
314
+ return rows.map((row) => mapAssignment({ ...row, status: 'failed', error: reason, finished_at: now }));
315
+ }
294
316
  /* --------------------------------- messages -------------------------------- */
295
317
  postMessage(input) {
296
318
  const message = {
@@ -337,6 +359,358 @@ export class OrgStore {
337
359
  for (const id of ids)
338
360
  statement.run(now, id);
339
361
  }
362
+ /* ----------------------------------- mail ------------------------------------ */
363
+ // Retired in schema 27. Nothing in the runtime writes mail any more - what
364
+ // reached the user is a notification now, a task's thread is its activity
365
+ // (both further up) - but the tables and these readers stay, so the old
366
+ // mail can still be read and whoever still calls them compiles until it
367
+ // has moved over (docs/concepts/mail-removal-notifications-and-task-activity.md).
368
+ /**
369
+ * Send mail: one `mail` row plus one `mail_recipients` row per to/cc
370
+ * target. Delivery only - the auto-trigger rule (a To agent gets a real
371
+ * run) lives in org/controller.ts, which is the one place that knows
372
+ * about running assignments.
373
+ */
374
+ sendMail(input) {
375
+ const now = Date.now();
376
+ const id = randomUUID();
377
+ const subject = input.subject.trim() || '(no subject)';
378
+ const threadId = input.threadId ?? id;
379
+ this.#db
380
+ .prepare(`INSERT INTO mail (id, org_id, from_kind, from_agent_id, subject, body, thread_id, in_reply_to, depth, assignment_id, created_at)
381
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
382
+ .run(id, input.orgId, input.from.kind, input.from.kind === 'agent' ? (input.from.id ?? null) : null, subject, input.body, threadId, input.inReplyTo ?? null, input.depth ?? 0, input.assignmentId ?? null, now);
383
+ // One protocol row per thread, and `OR IGNORE` is the whole inheritance
384
+ // rule: only the thread's first mail writes the row, every reply falls
385
+ // through to it. A mail an agent sends opens a report - it exists because
386
+ // a run or a scheduling produced it - unless a caller knows better.
387
+ const kind = input.kind ?? (input.from.kind === 'agent' ? 'report' : 'chat');
388
+ this.#db
389
+ .prepare(`INSERT OR IGNORE INTO mail_threads (thread_id, org_id, kind, task_id, archived_at, created_at)
390
+ VALUES (?, ?, ?, NULL, NULL, ?)`)
391
+ .run(threadId, input.orgId, kind, now);
392
+ const insertRecipient = this.#db.prepare(`INSERT INTO mail_recipients (id, mail_id, recipient_kind, recipient_id, box, read_at)
393
+ VALUES (?, ?, ?, ?, ?, NULL)`);
394
+ const targets = [
395
+ ...input.to.map((who) => ({ who, box: 'to' })),
396
+ ...(input.cc ?? []).map((who) => ({ who, box: 'cc' })),
397
+ ];
398
+ const recipients = targets.map(({ who, box }) => {
399
+ const recipientId = who.kind === 'agent' ? who.id : undefined;
400
+ const recipient = { id: randomUUID(), mailId: id, recipientKind: who.kind, recipientId, box };
401
+ insertRecipient.run(recipient.id, id, recipient.recipientKind, recipient.recipientId ?? null, recipient.box);
402
+ return recipient;
403
+ });
404
+ // The thread's own row, not the computed default: a reply landed in a
405
+ // thread whose kind was decided by its first mail, and that is the truth
406
+ // the caller should see.
407
+ const threadRow = this.#db
408
+ .prepare('SELECT kind, task_id, archived_at, created_at FROM mail_threads WHERE thread_id = ?')
409
+ .get(threadId);
410
+ return {
411
+ id,
412
+ orgId: input.orgId,
413
+ fromKind: input.from.kind,
414
+ fromAgentId: input.from.kind === 'agent' ? input.from.id : undefined,
415
+ subject,
416
+ body: input.body,
417
+ threadId,
418
+ inReplyTo: input.inReplyTo,
419
+ depth: input.depth ?? 0,
420
+ assignmentId: input.assignmentId,
421
+ createdAt: now,
422
+ recipients,
423
+ threadKind: threadRow?.kind ?? 'chat',
424
+ threadArchivedAt: optionalScore(threadRow?.archived_at),
425
+ };
426
+ }
427
+ /** One mail with its recipients and its thread's protocol row, or null. */
428
+ getMail(id) {
429
+ const row = this.#db
430
+ .prepare(`SELECT m.*, mt.kind AS thread_kind, mt.archived_at AS thread_archived_at, mt.task_id AS thread_task_id, t.title AS thread_task_title
431
+ FROM mail m
432
+ LEFT JOIN mail_threads mt ON mt.thread_id = m.thread_id
433
+ LEFT JOIN tasks t ON t.id = mt.task_id
434
+ WHERE m.id = ?`)
435
+ .get(id);
436
+ if (!row)
437
+ return null;
438
+ const recipients = this.#db.prepare('SELECT * FROM mail_recipients WHERE mail_id = ?').all(id);
439
+ return mapMail(row, recipients.map(mapMailRecipient));
440
+ }
441
+ /** The protocol row behind a thread, or null. */
442
+ getMailThread(orgId, threadId) {
443
+ const row = this.#db
444
+ .prepare('SELECT * FROM mail_threads WHERE org_id = ? AND thread_id = ?')
445
+ .get(orgId, threadId);
446
+ return row ? mapMailThread(row) : null;
447
+ }
448
+ /** The mail thread an assignment thread opened for `taskId`, or null. */
449
+ getMailThreadForTask(orgId, taskId) {
450
+ const row = this.#db
451
+ .prepare('SELECT * FROM mail_threads WHERE org_id = ? AND task_id = ? ORDER BY created_at DESC')
452
+ .get(orgId, taskId);
453
+ return row ? mapMailThread(row) : null;
454
+ }
455
+ /** Names the task an assignment thread created - the traceable side of the coupling. */
456
+ linkMailThreadTask(orgId, threadId, taskId) {
457
+ this.#db
458
+ .prepare('UPDATE mail_threads SET task_id = ? WHERE org_id = ? AND thread_id = ?')
459
+ .run(taskId, orgId, threadId);
460
+ }
461
+ /** Archives (or restores) a whole thread; archived mail leaves the live folders. */
462
+ archiveMailThread(orgId, threadId, archived) {
463
+ this.#db
464
+ .prepare('UPDATE mail_threads SET archived_at = ? WHERE org_id = ? AND thread_id = ?')
465
+ .run(archived ? Date.now() : null, orgId, threadId);
466
+ }
467
+ /**
468
+ * A mailbox as one of the company sees it: `inbox` is everything addressed
469
+ * to `who` via To or Cc, sliced by `folder` - the fixed structure, where
470
+ * `archiv` is the only folder a person puts things into by hand; `outbox`
471
+ * is everything `who` sent, unsliced. Newest first.
472
+ */
473
+ mailbox(orgId, who, box, opts = {}) {
474
+ const limit = opts.limit ?? 50;
475
+ const agentId = who.id ?? null;
476
+ let ids;
477
+ if (box === 'outbox') {
478
+ ids = (who.kind === 'agent'
479
+ ? this.#db
480
+ .prepare('SELECT id FROM mail WHERE org_id = ? AND from_kind = ? AND from_agent_id = ? ORDER BY created_at DESC LIMIT ?')
481
+ .all(orgId, who.kind, agentId, limit)
482
+ : this.#db
483
+ .prepare('SELECT id FROM mail WHERE org_id = ? AND from_kind = ? ORDER BY created_at DESC LIMIT ?')
484
+ .all(orgId, who.kind, limit)).map((row) => row.id);
485
+ }
486
+ else {
487
+ // Which slice of the inbox: kind is what the thread *is*, decided once
488
+ // when it opened and inherited by every reply.
489
+ const folder = opts.folder ?? 'inbox';
490
+ const clause = folder === 'tasks'
491
+ ? "mt.kind = 'assignment' AND mt.archived_at IS NULL"
492
+ : folder === 'reports'
493
+ ? "mt.kind = 'report' AND mt.archived_at IS NULL"
494
+ : folder === 'archiv'
495
+ ? 'mt.archived_at IS NOT NULL'
496
+ : 'mt.archived_at IS NULL';
497
+ ids = (who.kind === 'agent'
498
+ ? this.#db
499
+ .prepare(`SELECT m.id FROM mail m JOIN mail_recipients r ON r.mail_id = m.id
500
+ JOIN mail_threads mt ON mt.thread_id = m.thread_id
501
+ WHERE m.org_id = ? AND r.recipient_kind = ? AND r.recipient_id = ? AND (? = 0 OR r.read_at IS NULL)
502
+ AND ${clause}
503
+ ORDER BY m.created_at DESC LIMIT ?`)
504
+ .all(orgId, who.kind, agentId, opts.unreadOnly ? 1 : 0, limit)
505
+ : this.#db
506
+ .prepare(`SELECT m.id FROM mail m JOIN mail_recipients r ON r.mail_id = m.id
507
+ JOIN mail_threads mt ON mt.thread_id = m.thread_id
508
+ WHERE m.org_id = ? AND r.recipient_kind = ? AND (? = 0 OR r.read_at IS NULL)
509
+ AND ${clause}
510
+ ORDER BY m.created_at DESC LIMIT ?`)
511
+ .all(orgId, who.kind, opts.unreadOnly ? 1 : 0, limit)).map((row) => row.id);
512
+ }
513
+ return ids.map((id) => this.getMail(id)).filter((mail) => mail !== null);
514
+ }
515
+ /**
516
+ * One conversation, oldest first. A mail-triggered run only ever gets the
517
+ * mail that woke it; without the thread behind it an agent answers a reply
518
+ * having never seen what it replies to.
519
+ */
520
+ thread(orgId, threadId, opts = {}) {
521
+ const rows = this.#db
522
+ .prepare('SELECT id FROM mail WHERE org_id = ? AND thread_id = ? ORDER BY created_at DESC LIMIT ?')
523
+ .all(orgId, threadId, opts.limit ?? 20);
524
+ const mail = rows
525
+ .map((row) => this.getMail(row.id))
526
+ .filter((entry) => entry !== null)
527
+ .reverse();
528
+ const who = opts.who;
529
+ if (!who)
530
+ return mail;
531
+ // Their own view of the conversation: what they wrote, and what they were
532
+ // on. A thread can carry mail they were never a party to.
533
+ const isWho = (kind, id) => kind === who.kind && (who.kind !== 'agent' || id === who.id);
534
+ return mail.filter((entry) => isWho(entry.fromKind, entry.fromAgentId) ||
535
+ entry.recipients.some((recipient) => isWho(recipient.recipientKind, recipient.recipientId)));
536
+ }
537
+ /** Unread mail addressed to `who` via To or Cc - the "waiting for you" prompt block. */
538
+ unreadMailFor(orgId, who) {
539
+ return this.mailbox(orgId, who, 'inbox', { unreadOnly: true });
540
+ }
541
+ markMailRead(recipientRowIds) {
542
+ if (!recipientRowIds.length)
543
+ return;
544
+ const statement = this.#db.prepare('UPDATE mail_recipients SET read_at = ? WHERE id = ? AND read_at IS NULL');
545
+ const now = Date.now();
546
+ for (const id of recipientRowIds)
547
+ statement.run(now, id);
548
+ }
549
+ /**
550
+ * The other direction, for the reading pane's "Mark as unread".
551
+ *
552
+ * Opening a mail marks it read on its own, so putting one back is the only
553
+ * way to keep it on the unread list after having looked at it.
554
+ */
555
+ markMailUnread(recipientRowIds) {
556
+ if (!recipientRowIds.length)
557
+ return;
558
+ const statement = this.#db.prepare('UPDATE mail_recipients SET read_at = NULL WHERE id = ?');
559
+ for (const id of recipientRowIds)
560
+ statement.run(id);
561
+ }
562
+ /** Convenience over markMailRead: marks every recipient row in `mail` that belongs to `who`. */
563
+ markMailReadFor(mail, who) {
564
+ const ids = mail.flatMap((entry) => entry.recipients
565
+ .filter((recipient) => recipient.recipientKind === who.kind && (who.kind !== 'agent' || recipient.recipientId === who.id))
566
+ .map((recipient) => recipient.id));
567
+ this.markMailRead(ids);
568
+ }
569
+ /* ------------------------------- notifications ------------------------------ */
570
+ /**
571
+ * Store one notification for the user. Pure write - the controller's
572
+ * `notifyUser` is what announces it; anything that bypasses that (the
573
+ * scheduler without a controller, a migration) stays silent on purpose.
574
+ */
575
+ createNotification(input) {
576
+ const notification = {
577
+ id: randomUUID(),
578
+ orgId: input.orgId,
579
+ kind: input.kind,
580
+ title: input.title.trim() || '(untitled)',
581
+ body: input.body ?? '',
582
+ fromKind: input.fromKind ?? 'system',
583
+ fromAgentId: input.fromKind === 'agent' ? blank(input.fromAgentId) : undefined,
584
+ taskId: blank(input.taskId),
585
+ cronJobId: blank(input.cronJobId),
586
+ cronRunId: blank(input.cronRunId),
587
+ sessionId: blank(input.sessionId),
588
+ createdAt: Date.now(),
589
+ };
590
+ this.#db
591
+ .prepare(`INSERT INTO notifications
592
+ (id, org_id, kind, title, body, from_kind, from_agent_id, task_id, cron_job_id, cron_run_id, session_id,
593
+ read_at, archived_at, created_at)
594
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?)`)
595
+ .run(notification.id, notification.orgId, notification.kind, notification.title, notification.body, notification.fromKind, notification.fromAgentId ?? null, notification.taskId ?? null, notification.cronJobId ?? null, notification.cronRunId ?? null, notification.sessionId ?? null, notification.createdAt);
596
+ return notification;
597
+ }
598
+ getNotification(id) {
599
+ const row = this.#db.prepare('SELECT * FROM notifications WHERE id = ?').get(id);
600
+ return row ? mapNotification(row) : null;
601
+ }
602
+ /**
603
+ * Notifications, newest first. `archived` picks the shelf: the live list by
604
+ * default, the archive when true. `unread` narrows either to what has not
605
+ * been read; `kind` to one or several kinds.
606
+ */
607
+ listNotifications(opts = {}) {
608
+ const where = [opts.archived ? 'archived_at IS NOT NULL' : 'archived_at IS NULL'];
609
+ const params = [];
610
+ if (opts.orgId) {
611
+ where.push('org_id = ?');
612
+ params.push(opts.orgId);
613
+ }
614
+ if (opts.unread)
615
+ where.push('read_at IS NULL');
616
+ const kinds = opts.kind === undefined ? [] : Array.isArray(opts.kind) ? opts.kind : [opts.kind];
617
+ if (kinds.length) {
618
+ where.push('kind IN (' + kinds.map(() => '?').join(', ') + ')');
619
+ params.push(...kinds);
620
+ }
621
+ params.push(Math.max(1, Math.min(opts.limit ?? 100, 1000)));
622
+ const rows = this.#db
623
+ .prepare('SELECT * FROM notifications WHERE ' + where.join(' AND ') + ' ORDER BY created_at DESC, rowid DESC LIMIT ?')
624
+ .all(...params);
625
+ return rows.map(mapNotification);
626
+ }
627
+ /**
628
+ * Mark notifications read - by id, or `'all'` for everything unread (in one
629
+ * company when `orgId` is given). `read: false` puts them back on the
630
+ * unread list. Returns how many rows changed.
631
+ */
632
+ markNotificationsRead(ids, options = {}) {
633
+ const read = options.read ?? true;
634
+ const now = Date.now();
635
+ if (ids === 'all') {
636
+ const result = read
637
+ ? options.orgId
638
+ ? this.#db.prepare('UPDATE notifications SET read_at = ? WHERE read_at IS NULL AND org_id = ?').run(now, options.orgId)
639
+ : this.#db.prepare('UPDATE notifications SET read_at = ? WHERE read_at IS NULL').run(now)
640
+ : options.orgId
641
+ ? this.#db.prepare('UPDATE notifications SET read_at = NULL WHERE org_id = ?').run(options.orgId)
642
+ : this.#db.prepare('UPDATE notifications SET read_at = NULL').run();
643
+ return Number(result.changes);
644
+ }
645
+ let changed = 0;
646
+ const statement = read
647
+ ? this.#db.prepare('UPDATE notifications SET read_at = ? WHERE id = ? AND read_at IS NULL')
648
+ : this.#db.prepare('UPDATE notifications SET read_at = NULL WHERE id = ? AND read_at IS NOT NULL');
649
+ for (const id of ids) {
650
+ changed += Number((read ? statement.run(now, id) : statement.run(id)).changes);
651
+ }
652
+ return changed;
653
+ }
654
+ /**
655
+ * Archive (or restore) one notification. Archiving also marks it read:
656
+ * something put away on purpose is not waiting for anybody.
657
+ */
658
+ archiveNotification(id, archived = true) {
659
+ const now = Date.now();
660
+ if (archived) {
661
+ this.#db
662
+ .prepare('UPDATE notifications SET archived_at = ?, read_at = COALESCE(read_at, ?) WHERE id = ?')
663
+ .run(now, now, id);
664
+ }
665
+ else {
666
+ this.#db.prepare('UPDATE notifications SET archived_at = NULL WHERE id = ?').run(id);
667
+ }
668
+ return this.getNotification(id);
669
+ }
670
+ /** Unread, unarchived notifications - the badge. */
671
+ unreadNotificationCount(orgId) {
672
+ const row = (orgId
673
+ ? this.#db
674
+ .prepare('SELECT COUNT(*) AS n FROM notifications WHERE read_at IS NULL AND archived_at IS NULL AND org_id = ?')
675
+ .get(orgId)
676
+ : this.#db.prepare('SELECT COUNT(*) AS n FROM notifications WHERE read_at IS NULL AND archived_at IS NULL').get());
677
+ return Number(row?.n ?? 0);
678
+ }
679
+ /* -------------------------------- task activity ------------------------------ */
680
+ /** Append one line to a card's activity. */
681
+ addTaskEvent(input) {
682
+ const event = {
683
+ id: randomUUID(),
684
+ taskId: input.taskId,
685
+ at: input.at ?? Date.now(),
686
+ kind: input.kind,
687
+ actorKind: input.actorKind,
688
+ actorAgentId: input.actorKind === 'agent' ? blank(input.actorAgentId) : undefined,
689
+ text: input.text,
690
+ assignmentId: blank(input.assignmentId),
691
+ };
692
+ this.#db
693
+ .prepare(`INSERT INTO task_events (id, task_id, at, kind, actor_kind, actor_agent_id, text, assignment_id)
694
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
695
+ .run(event.id, event.taskId, event.at, event.kind, event.actorKind, event.actorAgentId ?? null, event.text, event.assignmentId ?? null);
696
+ return event;
697
+ }
698
+ /** A card's whole activity, oldest first. */
699
+ listTaskEvents(taskId) {
700
+ const rows = this.#db
701
+ .prepare('SELECT * FROM task_events WHERE task_id = ? ORDER BY at, rowid')
702
+ .all(taskId);
703
+ return rows.map(mapTaskEvent);
704
+ }
705
+ /** The newest line of a card's activity, of one kind when `kind` is given. */
706
+ lastTaskEvent(taskId, kind) {
707
+ const row = (kind
708
+ ? this.#db
709
+ .prepare('SELECT * FROM task_events WHERE task_id = ? AND kind = ? ORDER BY at DESC, rowid DESC LIMIT 1')
710
+ .get(taskId, kind)
711
+ : this.#db.prepare('SELECT * FROM task_events WHERE task_id = ? ORDER BY at DESC, rowid DESC LIMIT 1').get(taskId));
712
+ return row ? mapTaskEvent(row) : null;
713
+ }
340
714
  /* ----------------------------------- tasks ---------------------------------- */
341
715
  createTask(input) {
342
716
  const now = Date.now();
@@ -352,33 +726,78 @@ export class OrgStore {
352
726
  assigneeId: blank(input.assigneeId),
353
727
  createdBy: input.createdBy,
354
728
  createdByAgentId: blank(input.createdByAgentId),
729
+ scheduleId: blank(input.scheduleId),
730
+ requesterSessionId: blank(input.requesterSessionId),
355
731
  dependsOn: [...new Set(input.dependsOn ?? [])],
356
732
  planNote: blank(input.planNote),
357
733
  createdAt: now,
358
734
  updatedAt: now,
735
+ // New cards start at the back of their column; drag&drop assigns a real
736
+ // position once someone reorders it.
737
+ sortOrder: now,
359
738
  };
360
739
  this.#db
361
740
  .prepare(`INSERT INTO tasks
362
741
  (id, org_id, project_id, parent_id, title, description, status, priority, assignee_id,
363
- created_by, created_by_agent_id, depends_on, plan_note, created_at, updated_at)
364
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
365
- .run(task.id, task.orgId, task.projectId ?? null, task.parentId ?? null, task.title, task.description, task.status, task.priority, task.assigneeId ?? null, task.createdBy, task.createdByAgentId ?? null, JSON.stringify(task.dependsOn), task.planNote ?? null, now, now);
742
+ created_by, created_by_agent_id, schedule_id, requester_session_id, depends_on, plan_note,
743
+ created_at, updated_at, sort_order)
744
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
745
+ .run(task.id, task.orgId, task.projectId ?? null, task.parentId ?? null, task.title, task.description, task.status, task.priority, task.assigneeId ?? null, task.createdBy, task.createdByAgentId ?? null, task.scheduleId ?? null, task.requesterSessionId ?? null, JSON.stringify(task.dependsOn), task.planNote ?? null, now, now, task.sortOrder);
746
+ // Every card opens its activity with its own brief, whoever made it and
747
+ // through whichever door - the tool, the board, a route, a schedule. It
748
+ // replaces the work-order mail a task used to be opened with, and it is
749
+ // written here rather than by each caller so no door can forget it.
750
+ this.addTaskEvent({
751
+ taskId: task.id,
752
+ kind: 'created',
753
+ actorKind: task.createdBy,
754
+ actorAgentId: task.createdBy === 'agent' ? task.createdByAgentId : undefined,
755
+ text: task.description || task.title,
756
+ at: now,
757
+ });
366
758
  return task;
367
759
  }
760
+ /**
761
+ * Take a task for a run, atomically. True when this caller got it.
762
+ *
763
+ * The in-memory `#activeTasks` claim stops two invocations inside one
764
+ * process; it cannot see a second process, and it cannot see a status
765
+ * write that lands between the read and the write - so two processes
766
+ * sharing this database could both decide a task was free and both start
767
+ * a run of it. The condition is the guard, and it is exactly one rule:
768
+ * a task that is already running cannot be taken again.
769
+ *
770
+ * Deliberately not stricter. A finished task is claimable, because an
771
+ * answer to it is allowed to set it going again with that answer as its
772
+ * brief (`answer_task`) - excluding `done` here quietly broke that, and
773
+ * the card simply never moved.
774
+ */
775
+ claimTaskForRun(id, startedAt) {
776
+ const result = this.#db
777
+ .prepare(`UPDATE tasks SET status = 'running', started_at = ?, error = NULL, updated_at = ?
778
+ WHERE id = ? AND status != 'running'`)
779
+ .run(startedAt, Date.now(), id);
780
+ return Number(result.changes) > 0;
781
+ }
368
782
  getTask(id) {
369
783
  const row = this.#db.prepare('SELECT * FROM tasks WHERE id = ?').get(id);
370
784
  return row ? mapTask(row) : null;
371
785
  }
372
- /** Board view: top-level tasks by default, or the subtasks of one parent. */
786
+ /**
787
+ * Board view: top-level tasks by default, or the subtasks of one parent.
788
+ * `anyLevel` drops the nesting question altogether - a search for every
789
+ * blocked task has to find the ones that hang under a parent too.
790
+ */
373
791
  listTasks(orgId, options = {}) {
374
792
  const clauses = ['org_id = ?'];
375
793
  const values = [orgId];
376
- if (options.parentId === null || options.parentId === undefined)
377
- clauses.push('parent_id IS NULL');
378
- else {
794
+ if (options.parentId !== null && options.parentId !== undefined) {
379
795
  clauses.push('parent_id = ?');
380
796
  values.push(options.parentId);
381
797
  }
798
+ else if (!options.anyLevel) {
799
+ clauses.push('parent_id IS NULL');
800
+ }
382
801
  if (options.status?.length) {
383
802
  clauses.push('status IN (' + options.status.map(() => '?').join(', ') + ')');
384
803
  values.push(...options.status);
@@ -416,8 +835,355 @@ export class OrgStore {
416
835
  error: patch.error,
417
836
  started_at: patch.startedAt,
418
837
  finished_at: patch.finishedAt,
838
+ sort_order: patch.sortOrder,
419
839
  });
420
840
  }
841
+ /**
842
+ * Tasks still marked running from a previous process are failed on
843
+ * startup, mirroring `failStaleAssignments` above. Returns the rows it
844
+ * changed so the caller can announce them.
845
+ *
846
+ * `planned` is deliberately left alone. A planned task has a plan and no
847
+ * run: nothing about it died with the process, and failing it asserted
848
+ * something untrue - "the server restarted while this was running" - about
849
+ * work the user had knowingly not started yet. Worse, `failed` is what
850
+ * wakes the board watcher, so every boot used to hand it a pile of
851
+ * fabricated failures to act on.
852
+ */
853
+ failStaleTasks(reason) {
854
+ const now = Date.now();
855
+ const rows = this.#db
856
+ .prepare("SELECT * FROM tasks WHERE status = 'running'")
857
+ .all();
858
+ if (!rows.length)
859
+ return [];
860
+ this.#db
861
+ .prepare("UPDATE tasks SET status = 'failed', error = ?, finished_at = ? WHERE status = 'running'")
862
+ .run(reason, now);
863
+ return rows.map((row) => mapTask({ ...row, status: 'failed', error: reason, finished_at: now, updated_at: now }));
864
+ }
865
+ /**
866
+ * Record that this assignment ran this task, keeping every run instead of
867
+ * just the latest: a rerun used to overwrite `tasks.assignment_id` with no
868
+ * trace of the previous (often failed) run, which broke the reverse lookup
869
+ * from an old assignment back to its task. `tasks.assignment_id` still
870
+ * tracks "the current run" for cheap reads; this table is the durable side.
871
+ */
872
+ linkTaskAssignment(taskId, assignmentId) {
873
+ this.#db
874
+ .prepare(`INSERT OR IGNORE INTO task_assignments (task_id, assignment_id, created_at)
875
+ VALUES (?, ?, ?)`)
876
+ .run(taskId, assignmentId, Date.now());
877
+ this.updateTask(taskId, { assignmentId });
878
+ }
879
+ /**
880
+ * Which run of its task this one is, counting from one, or null when it
881
+ * belongs to no task. A run inherits its task's name (decision E17), so
882
+ * the chain is the only thing that tells two of them apart in a list -
883
+ * "Run 2" rather than a second, invented title for the same piece of work.
884
+ */
885
+ taskRunNumber(assignmentId) {
886
+ const row = this.#db
887
+ .prepare(`SELECT (SELECT COUNT(*) FROM task_assignments earlier
888
+ WHERE earlier.task_id = link.task_id
889
+ AND (earlier.created_at < link.created_at
890
+ OR (earlier.created_at = link.created_at AND earlier.assignment_id <= link.assignment_id))
891
+ ) AS position
892
+ FROM task_assignments link
893
+ WHERE link.assignment_id = ?`)
894
+ .get(assignmentId);
895
+ return row ? Number(row.position) : null;
896
+ }
897
+ /**
898
+ * How many runs a task has had. Derived from `task_assignments`, which
899
+ * already keeps every run rather than only the latest, so this needs no
900
+ * column of its own and survives a restart the way the rows do.
901
+ *
902
+ * It exists so nothing re-runs a task forever without anyone noticing: a
903
+ * deterministic failure - a project directory that is gone, an assignee
904
+ * that was archived - fails identically every time, and the cost of
905
+ * finding that out again is a whole model run. Callers that restart work
906
+ * on their own initiative check this first; a person asking for another
907
+ * run is not subject to it.
908
+ */
909
+ taskRunCount(taskId) {
910
+ const row = this.#db
911
+ .prepare('SELECT COUNT(*) AS runs FROM task_assignments WHERE task_id = ?')
912
+ .get(taskId);
913
+ return row ? Number(row.runs) : 0;
914
+ }
915
+ /** The task an assignment belongs to, even one a later rerun's assignment_id overwrote. */
916
+ getTaskIdForAssignment(assignmentId) {
917
+ const row = this.#db
918
+ .prepare('SELECT task_id FROM task_assignments WHERE assignment_id = ?')
919
+ .get(assignmentId);
920
+ return row?.task_id ?? null;
921
+ }
922
+ /* ------------------------------ agent reviews ------------------------------- */
923
+ /**
924
+ * A judgment of one assignment, or a periodic one when `assignmentId` is
925
+ * unset. Always inserts a new row - callers that mean "replace the review
926
+ * for this assignment and source" want {@link upsertReview} instead, which
927
+ * is every caller today (there is no periodic review yet).
928
+ */
929
+ createReview(input) {
930
+ const review = {
931
+ id: randomUUID(),
932
+ orgId: input.orgId,
933
+ agentId: input.agentId,
934
+ assignmentId: blank(input.assignmentId),
935
+ taskId: blank(input.taskId),
936
+ source: input.source,
937
+ overall: clampReviewScore(input.overall),
938
+ quality: clampReviewScoreOptional(input.quality),
939
+ completeness: clampReviewScoreOptional(input.completeness),
940
+ reliability: clampReviewScoreOptional(input.reliability),
941
+ communication: clampReviewScoreOptional(input.communication),
942
+ efficiency: clampReviewScoreOptional(input.efficiency),
943
+ comment: blank(input.comment),
944
+ tags: [...new Set(input.tags ?? [])],
945
+ failedRun: input.failedRun ?? false,
946
+ createdAt: Date.now(),
947
+ };
948
+ this.#db
949
+ .prepare(`INSERT INTO agent_reviews
950
+ (id, org_id, agent_id, assignment_id, task_id, source, overall, quality, completeness,
951
+ reliability, communication, efficiency, comment, tags, failed_run, created_at)
952
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
953
+ .run(review.id, review.orgId, review.agentId, review.assignmentId ?? null, review.taskId ?? null, review.source, review.overall, review.quality ?? null, review.completeness ?? null, review.reliability ?? null, review.communication ?? null, review.efficiency ?? null, review.comment ?? null, JSON.stringify(review.tags), review.failedRun ? 1 : 0, review.createdAt);
954
+ return review;
955
+ }
956
+ /**
957
+ * One effective review per (assignment, source) - a second call for the
958
+ * same pair replaces it instead of stacking beside it, matching
959
+ * `idx_agent_reviews_once`. A periodic review (`assignmentId` unset) never
960
+ * collides with another: each is its own row.
961
+ */
962
+ upsertReview(input) {
963
+ if (input.assignmentId) {
964
+ const existing = this.#db
965
+ .prepare('SELECT id FROM agent_reviews WHERE assignment_id = ? AND source = ?')
966
+ .get(input.assignmentId, input.source);
967
+ if (existing) {
968
+ const overall = clampReviewScore(input.overall);
969
+ const quality = clampReviewScoreOptional(input.quality);
970
+ const completeness = clampReviewScoreOptional(input.completeness);
971
+ const reliability = clampReviewScoreOptional(input.reliability);
972
+ const communication = clampReviewScoreOptional(input.communication);
973
+ const efficiency = clampReviewScoreOptional(input.efficiency);
974
+ const comment = blank(input.comment);
975
+ const tags = [...new Set(input.tags ?? [])];
976
+ const failedRun = input.failedRun ?? false;
977
+ this.#db
978
+ .prepare(`UPDATE agent_reviews
979
+ SET task_id = ?, overall = ?, quality = ?, completeness = ?, reliability = ?,
980
+ communication = ?, efficiency = ?, comment = ?, tags = ?, failed_run = ?, created_at = ?
981
+ WHERE id = ?`)
982
+ .run(blank(input.taskId) ?? null, overall, quality ?? null, completeness ?? null, reliability ?? null, communication ?? null, efficiency ?? null, comment ?? null, JSON.stringify(tags), failedRun ? 1 : 0, Date.now(), existing.id);
983
+ const updated = this.getReview(existing.id);
984
+ this.#writeReviewLabel(updated);
985
+ return updated;
986
+ }
987
+ }
988
+ const created = this.createReview(input);
989
+ this.#writeReviewLabel(created);
990
+ return created;
991
+ }
992
+ /**
993
+ * The `review` label (concept 4.2d, S8), written where every review source
994
+ * already meets: `upsertReview` is the one funnel of all four of them -
995
+ * Jarvis's judgement, the system's technical failure, the manager's note
996
+ * and the HTTP route - so one writer here catches them all without four
997
+ * call sites having to remember.
998
+ *
999
+ * Two warnings this source carries, and they are the reason the sentence
1000
+ * above is not the whole story. `upsertReview` REPLACES the row for the
1001
+ * same `(assignment_id, source)` and resets `created_at`, so a reward once
1002
+ * appended can later be revoked silently - and the label follows it,
1003
+ * because `(turn_id, target, source)` is the label's key too. Two
1004
+ * different review SOURCES scoring one assignment collapse onto that same
1005
+ * key for the same reason: the label says `source: 'review'`, not which
1006
+ * review. And an agent never receives a correction through `#replay`, so
1007
+ * this one blurry source is nearly its whole label supply.
1008
+ *
1009
+ * It is `gainFrom` that keeps the row out of DCG, never the caller (S8):
1010
+ * scoring an assignment from 1 to 5 says nothing about which memory
1011
+ * belonged in which prompt, which is why the target is the sentinel `'*'`.
1012
+ */
1013
+ #writeReviewLabel(review) {
1014
+ const assignment = review.assignmentId ? this.getAssignment(review.assignmentId) : null;
1015
+ const label = reviewLabel({
1016
+ // The agent's own bank - the population this review is evidence about.
1017
+ owner: review.agentId,
1018
+ // A periodic review names no assignment; it is keyed on itself, and
1019
+ // its scope is session-wide either way.
1020
+ assignmentId: review.assignmentId ?? review.id,
1021
+ ...(assignment?.sessionId ? { sessionId: assignment.sessionId } : {}),
1022
+ overall: review.overall,
1023
+ evidence: 'review:' + review.id + ':' + review.source,
1024
+ now: review.createdAt,
1025
+ });
1026
+ // The same statement `Store.putLabels` writes, spelled out here because
1027
+ // `OrgStore` holds the raw `Db` and nothing else: reaching the memory
1028
+ // store from inside the organisation store would be the wrong direction
1029
+ // of dependency for one INSERT.
1030
+ this.#db
1031
+ .prepare(`INSERT OR REPLACE INTO dream_labels
1032
+ (turn_id, target, source, relevance, scope, evidence, dead_at, created_at, owner, session_id)
1033
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1034
+ .run(label.turnId, label.target, label.source, label.relevance, label.scope, label.evidence ?? null, label.deadAt ?? null, label.createdAt, label.owner, label.sessionId ?? null);
1035
+ }
1036
+ getReview(id) {
1037
+ const row = this.#db.prepare('SELECT * FROM agent_reviews WHERE id = ?').get(id);
1038
+ return row ? mapReview(row) : null;
1039
+ }
1040
+ /** An agent's review history, newest first. */
1041
+ listReviews(agentId, options = {}) {
1042
+ const rows = this.#db
1043
+ .prepare('SELECT * FROM agent_reviews WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?')
1044
+ .all(agentId, options.limit ?? 20);
1045
+ return rows.map(mapReview);
1046
+ }
1047
+ /** Every review of one assignment - at most one per source. */
1048
+ reviewsForAssignment(assignmentId) {
1049
+ const rows = this.#db
1050
+ .prepare('SELECT * FROM agent_reviews WHERE assignment_id = ? ORDER BY created_at DESC')
1051
+ .all(assignmentId);
1052
+ return rows.map(mapReview);
1053
+ }
1054
+ /* ------------------------------ agent actions ------------------------------- */
1055
+ /** Append one entry to an agent's personnel record. */
1056
+ createAction(input) {
1057
+ const action = {
1058
+ id: randomUUID(),
1059
+ orgId: input.orgId,
1060
+ agentId: input.agentId,
1061
+ kind: input.kind,
1062
+ stage: input.stage,
1063
+ reason: input.reason.trim(),
1064
+ beforeText: blank(input.beforeText),
1065
+ afterText: blank(input.afterText),
1066
+ agentNote: blank(input.agentNote),
1067
+ handoverText: blank(input.handoverText),
1068
+ reviewIds: [...new Set(input.reviewIds ?? [])],
1069
+ decidedBy: input.decidedBy,
1070
+ successorAgentId: blank(input.successorAgentId),
1071
+ createdAt: Date.now(),
1072
+ };
1073
+ this.#db
1074
+ .prepare(`INSERT INTO agent_actions
1075
+ (id, org_id, agent_id, kind, stage, reason, before_text, after_text, agent_note,
1076
+ handover_text, review_ids, decided_by, successor_agent_id, created_at)
1077
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1078
+ .run(action.id, action.orgId, action.agentId, action.kind, action.stage, action.reason, action.beforeText ?? null, action.afterText ?? null, action.agentNote ?? null, action.handoverText ?? null, JSON.stringify(action.reviewIds), action.decidedBy, action.successorAgentId ?? null, action.createdAt);
1079
+ return action;
1080
+ }
1081
+ /** One personnel-record entry by id, for the paths that act on a specific one. */
1082
+ getAction(id) {
1083
+ const row = this.#db.prepare('SELECT * FROM agent_actions WHERE id = ?').get(id);
1084
+ return row ? mapAction(row) : null;
1085
+ }
1086
+ /** An agent's personnel record, newest first. */
1087
+ listActions(agentId, options = {}) {
1088
+ const rows = this.#db
1089
+ .prepare('SELECT * FROM agent_actions WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?')
1090
+ .all(agentId, options.limit ?? 50);
1091
+ return rows.map(mapAction);
1092
+ }
1093
+ /**
1094
+ * The judgment that actually counts for one assignment: at most one review
1095
+ * per assignment survives, and where several sources judged the same run,
1096
+ * `user` beats `assistant` beats `system` (section 2, "Wer bewertet
1097
+ * wann"). A periodic review (no `assignmentId`) never competes with
1098
+ * anything and always survives on its own. Newest first.
1099
+ */
1100
+ effectiveReviews(agentId, limit = 30) {
1101
+ const rank = { user: 0, assistant: 1, system: 2 };
1102
+ const rows = this.#db
1103
+ .prepare('SELECT * FROM agent_reviews WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?')
1104
+ .all(agentId, Math.max(limit * 6, 200));
1105
+ const byAssignment = new Map();
1106
+ const periodic = [];
1107
+ for (const row of rows) {
1108
+ const assignmentId = row.assignment_id;
1109
+ if (!assignmentId) {
1110
+ periodic.push(row);
1111
+ continue;
1112
+ }
1113
+ const existing = byAssignment.get(assignmentId);
1114
+ const rowRank = rank[row.source] ?? 9;
1115
+ const existingRank = existing ? rank[existing.source] ?? 9 : 9;
1116
+ if (!existing || rowRank < existingRank) {
1117
+ byAssignment.set(assignmentId, row);
1118
+ }
1119
+ }
1120
+ return [...byAssignment.values(), ...periodic]
1121
+ .map(mapReview)
1122
+ .sort((a, b) => b.createdAt - a.createdAt)
1123
+ .slice(0, limit);
1124
+ }
1125
+ /**
1126
+ * The computed, never-materialised view of one agent's standing
1127
+ * (docs/concepts/agent-performance-management.md, section 3: "on the fly,
1128
+ * not materialised" - O1). A technically failed run counts only toward
1129
+ * `failureRate`, never toward the quality average or the escalation
1130
+ * triggers below it - punishing an agent for a missing provider or a
1131
+ * timeout would blame it for infrastructure.
1132
+ */
1133
+ performance(agentId) {
1134
+ const effective = this.effectiveReviews(agentId, 30);
1135
+ const quality = effective.filter((review) => !review.failedRun);
1136
+ const last20 = effective.slice(0, 20);
1137
+ const failedInLast20 = last20.filter((review) => review.failedRun).length;
1138
+ const average10 = quality.slice(0, 10);
1139
+ const average = average10.length >= 3 ? mean(average10.map((review) => review.overall)) : null;
1140
+ let trend = null;
1141
+ if (quality.length >= 10) {
1142
+ const recent5 = mean(quality.slice(0, 5).map((review) => review.overall));
1143
+ const prior5 = mean(quality.slice(5, 10).map((review) => review.overall));
1144
+ if (recent5 !== null && prior5 !== null)
1145
+ trend = recent5 - prior5;
1146
+ }
1147
+ return {
1148
+ average,
1149
+ count: average10.length,
1150
+ trend,
1151
+ stage: stageFromReviews(quality, this.listActions(agentId, { limit: 50 })),
1152
+ failureRate: last20.length ? failedInLast20 / last20.length : 0,
1153
+ lastReviewAt: effective[0]?.createdAt,
1154
+ };
1155
+ }
1156
+ /**
1157
+ * `agent_note` texts written for this agent since its last `reconfig` -
1158
+ * the only part of the personnel record an agent's own prompt is allowed
1159
+ * to carry (decision E2). Newest first, capped by the caller.
1160
+ */
1161
+ agentNotesSince(agentId, since) {
1162
+ const actions = this.listActions(agentId, { limit: 50 });
1163
+ const cutoff = since ?? actions.find((action) => action.kind === 'reconfig')?.createdAt ?? 0;
1164
+ return actions
1165
+ .filter((action) => action.agentNote && action.createdAt >= cutoff)
1166
+ .map((action) => ({ note: action.agentNote, createdAt: action.createdAt }));
1167
+ }
1168
+ /**
1169
+ * The identity chain (agent-performance-management, phase 4, decision E4):
1170
+ * the `replace` action that retired this agent, if any - carries the
1171
+ * successor's id and the handover text. Newest first, though there is at
1172
+ * most one per agent.
1173
+ */
1174
+ replacementFor(agentId) {
1175
+ const row = this.#db
1176
+ .prepare("SELECT * FROM agent_actions WHERE agent_id = ? AND kind = 'replace' ORDER BY created_at DESC LIMIT 1")
1177
+ .get(agentId);
1178
+ return row ? mapAction(row) : null;
1179
+ }
1180
+ /** The predecessor this agent replaced, if it was hired as one's successor. */
1181
+ predecessorFor(agentId) {
1182
+ const row = this.#db
1183
+ .prepare("SELECT agent_id FROM agent_actions WHERE kind = 'replace' AND successor_agent_id = ? LIMIT 1")
1184
+ .get(agentId);
1185
+ return row ? this.getAgent(row.agent_id) : null;
1186
+ }
421
1187
  /* --------------------------------- internals -------------------------------- */
422
1188
  /** Generic partial update. `undefined` skips a column, `null` clears it. */
423
1189
  #update(table, id, patch, touch = true) {
@@ -453,6 +1219,92 @@ function blank(value) {
453
1219
  const text = value?.trim();
454
1220
  return text ? text : undefined;
455
1221
  }
1222
+ /** 1..5, rounded to the nearest whole star. */
1223
+ function clampReviewScore(value) {
1224
+ return Math.min(5, Math.max(1, Math.round(value)));
1225
+ }
1226
+ function clampReviewScoreOptional(value) {
1227
+ return value === undefined ? undefined : clampReviewScore(value);
1228
+ }
1229
+ function parseStringArray(raw) {
1230
+ try {
1231
+ const parsed = JSON.parse(String(raw ?? '[]'));
1232
+ return Array.isArray(parsed) ? parsed.map(String) : [];
1233
+ }
1234
+ catch {
1235
+ return [];
1236
+ }
1237
+ }
1238
+ function optionalScore(value) {
1239
+ return value === null || value === undefined ? undefined : Number(value);
1240
+ }
1241
+ function mean(values) {
1242
+ return values.length ? values.reduce((sum, value) => sum + value, 0) / values.length : null;
1243
+ }
1244
+ /**
1245
+ * A pure function of the review history and the last action taken - nothing
1246
+ * beyond that is stored, by design (section 4 of the concept doc). `quality`
1247
+ * is newest-first, failed runs already excluded.
1248
+ *
1249
+ * Deliberately simplified against the concept doc's exact wording in two
1250
+ * places:
1251
+ *
1252
+ * - The "one user rating of 1" trigger is read over the last five reviews
1253
+ * rather than unboundedly, and re-triggering a note after one already
1254
+ * exists uses "three fresh reviews since it" rather than a hand-tracked
1255
+ * per-decline counter - the doc stores no extra state, and this is the
1256
+ * simplest function of the data that will not renote the same decline on
1257
+ * every single review while still reacting to a fresh one.
1258
+ * - The doc allows up to two reconfigs before a replacement is proposed;
1259
+ * this collapses that to one. `#develop`'s idempotency (only act when the
1260
+ * computed stage exceeds the last action's) cannot represent "stay at
1261
+ * stage 2, but take a second reconfig action" without a second piece of
1262
+ * stored state, which is exactly what O1 rules out - so a single
1263
+ * probation window after the one reconfig decides it: recovered (stage 0)
1264
+ * or a replacement is proposed (stage 3), never a second autonomous
1265
+ * reconfig.
1266
+ */
1267
+ function stageFromReviews(quality, actions) {
1268
+ const minData = quality.length;
1269
+ if (minData < 3)
1270
+ return 0;
1271
+ // A good user rating right after a weak stretch resets everything - the
1272
+ // user always wins.
1273
+ const newest = quality[0];
1274
+ if (newest && newest.source === 'user' && newest.overall >= 4)
1275
+ return 0;
1276
+ const recent3 = quality.slice(0, 3);
1277
+ const recent5 = quality.slice(0, 5);
1278
+ const weakLast3 = recent3.filter((review) => review.overall <= 2).length >= 2;
1279
+ const oneStarUser = recent5.some((review) => review.source === 'user' && review.overall === 1);
1280
+ const avgLast5 = mean(recent5.map((review) => review.overall));
1281
+ const weak = weakLast3 || oneStarUser || (avgLast5 !== null && avgLast5 < 3.0);
1282
+ // Only an applied `reconfig` opens the probation window; a pending
1283
+ // `reconfig-proposal` deliberately does not. Nothing about the agent has
1284
+ // changed yet, so there is nothing to give it probation for - it stays at
1285
+ // stage 2 until somebody accepts or rejects the draft, and an unapproved
1286
+ // proposal can never escalate on its own to a replacement.
1287
+ const lastReconfig = actions.find((action) => action.kind === 'reconfig');
1288
+ const lastNote = actions.find((action) => action.kind === 'note');
1289
+ if (lastReconfig) {
1290
+ if (minData < 10)
1291
+ return weak ? 2 : 0; // not enough fresh data yet to judge the probation window
1292
+ const probationWindow = quality.filter((review) => review.createdAt > lastReconfig.createdAt).slice(0, 5);
1293
+ if (probationWindow.length < 5)
1294
+ return weak ? 2 : 0; // window still filling
1295
+ const probationAverage = mean(probationWindow.map((review) => review.overall));
1296
+ return probationAverage !== null && probationAverage < 3.0 ? 3 : 0;
1297
+ }
1298
+ if (!weak)
1299
+ return 0;
1300
+ // Re-trigger a note only once three reviews have landed since the last
1301
+ // one, so the same decline is not renoted on every single new review.
1302
+ if (lastNote) {
1303
+ const since = quality.filter((review) => review.createdAt > lastNote.createdAt);
1304
+ return since.length >= 3 ? 2 : 1;
1305
+ }
1306
+ return 1;
1307
+ }
456
1308
  function optional(value) {
457
1309
  return typeof value === 'string' && value ? value : undefined;
458
1310
  }
@@ -512,6 +1364,7 @@ function mapAgent(row) {
512
1364
  name: row.name,
513
1365
  title: row.title,
514
1366
  instructions: row.instructions,
1367
+ voice: optional(row.voice),
515
1368
  teamId: optional(row.team_id),
516
1369
  managerId: optional(row.manager_id),
517
1370
  provider: optional(row.provider),
@@ -532,6 +1385,10 @@ function mapAssignment(row) {
532
1385
  parentId: optional(row.parent_id),
533
1386
  requesterKind: row.requester_kind,
534
1387
  requesterAgentId: optional(row.requester_agent_id),
1388
+ // Rows from before the column existed are named when they are read and
1389
+ // never written back: the derivation is cheap, and a backfill would put
1390
+ // a guess in the place a real name belongs (decision E15).
1391
+ title: optional(row.title) ?? titleFromBrief(row.task),
535
1392
  task: row.task,
536
1393
  status: row.status,
537
1394
  result: optional(row.result),
@@ -569,6 +1426,8 @@ function mapTask(row) {
569
1426
  assignmentId: optional(row.assignment_id),
570
1427
  createdBy: row.created_by,
571
1428
  createdByAgentId: optional(row.created_by_agent_id),
1429
+ scheduleId: optional(row.schedule_id),
1430
+ requesterSessionId: optional(row.requester_session_id),
572
1431
  dependsOn,
573
1432
  planNote: optional(row.plan_note),
574
1433
  result: optional(row.result),
@@ -577,6 +1436,7 @@ function mapTask(row) {
577
1436
  updatedAt: Number(row.updated_at),
578
1437
  startedAt: row.started_at ? Number(row.started_at) : undefined,
579
1438
  finishedAt: row.finished_at ? Number(row.finished_at) : undefined,
1439
+ sortOrder: Number(row.sort_order ?? 0),
580
1440
  };
581
1441
  }
582
1442
  function mapMessage(row) {
@@ -591,4 +1451,112 @@ function mapMessage(row) {
591
1451
  readAt: row.read_at ? Number(row.read_at) : undefined,
592
1452
  };
593
1453
  }
1454
+ function mapMail(row, recipients) {
1455
+ return {
1456
+ id: row.id,
1457
+ orgId: row.org_id,
1458
+ fromKind: row.from_kind,
1459
+ fromAgentId: optional(row.from_agent_id),
1460
+ subject: row.subject,
1461
+ body: row.body,
1462
+ threadId: row.thread_id,
1463
+ inReplyTo: optional(row.in_reply_to),
1464
+ depth: Number(row.depth ?? 0),
1465
+ assignmentId: optional(row.assignment_id),
1466
+ createdAt: Number(row.created_at),
1467
+ recipients,
1468
+ threadKind: optional(row.thread_kind) ?? 'chat',
1469
+ threadArchivedAt: optionalScore(row.thread_archived_at),
1470
+ taskId: optional(row.thread_task_id),
1471
+ taskTitle: optional(row.thread_task_title),
1472
+ };
1473
+ }
1474
+ function mapMailThread(row) {
1475
+ return {
1476
+ threadId: row.thread_id,
1477
+ orgId: row.org_id,
1478
+ kind: row.kind ?? 'chat',
1479
+ taskId: optional(row.task_id),
1480
+ archivedAt: optionalScore(row.archived_at),
1481
+ createdAt: Number(row.created_at),
1482
+ };
1483
+ }
1484
+ function mapReview(row) {
1485
+ return {
1486
+ id: row.id,
1487
+ orgId: row.org_id,
1488
+ agentId: row.agent_id,
1489
+ assignmentId: optional(row.assignment_id),
1490
+ taskId: optional(row.task_id),
1491
+ source: row.source,
1492
+ overall: Number(row.overall),
1493
+ quality: optionalScore(row.quality),
1494
+ completeness: optionalScore(row.completeness),
1495
+ reliability: optionalScore(row.reliability),
1496
+ communication: optionalScore(row.communication),
1497
+ efficiency: optionalScore(row.efficiency),
1498
+ comment: optional(row.comment),
1499
+ tags: parseStringArray(row.tags),
1500
+ failedRun: Number(row.failed_run) === 1,
1501
+ createdAt: Number(row.created_at),
1502
+ };
1503
+ }
1504
+ function mapAction(row) {
1505
+ return {
1506
+ id: row.id,
1507
+ orgId: row.org_id,
1508
+ agentId: row.agent_id,
1509
+ kind: row.kind,
1510
+ stage: Number(row.stage),
1511
+ reason: row.reason,
1512
+ beforeText: optional(row.before_text),
1513
+ afterText: optional(row.after_text),
1514
+ agentNote: optional(row.agent_note),
1515
+ handoverText: optional(row.handover_text),
1516
+ reviewIds: parseStringArray(row.review_ids),
1517
+ decidedBy: row.decided_by,
1518
+ successorAgentId: optional(row.successor_agent_id),
1519
+ createdAt: Number(row.created_at),
1520
+ };
1521
+ }
1522
+ function mapMailRecipient(row) {
1523
+ return {
1524
+ id: row.id,
1525
+ mailId: row.mail_id,
1526
+ recipientKind: row.recipient_kind,
1527
+ recipientId: optional(row.recipient_id),
1528
+ box: row.box,
1529
+ readAt: row.read_at ? Number(row.read_at) : undefined,
1530
+ };
1531
+ }
1532
+ function mapNotification(row) {
1533
+ return {
1534
+ id: row.id,
1535
+ orgId: row.org_id,
1536
+ kind: row.kind,
1537
+ title: row.title,
1538
+ body: row.body ?? '',
1539
+ fromKind: row.from_kind,
1540
+ fromAgentId: optional(row.from_agent_id),
1541
+ taskId: optional(row.task_id),
1542
+ cronJobId: optional(row.cron_job_id),
1543
+ cronRunId: optional(row.cron_run_id),
1544
+ sessionId: optional(row.session_id),
1545
+ readAt: optionalScore(row.read_at),
1546
+ archivedAt: optionalScore(row.archived_at),
1547
+ createdAt: Number(row.created_at),
1548
+ };
1549
+ }
1550
+ function mapTaskEvent(row) {
1551
+ return {
1552
+ id: row.id,
1553
+ taskId: row.task_id,
1554
+ at: Number(row.at),
1555
+ kind: row.kind,
1556
+ actorKind: row.actor_kind,
1557
+ actorAgentId: optional(row.actor_agent_id),
1558
+ text: row.text ?? '',
1559
+ assignmentId: optional(row.assignment_id),
1560
+ };
1561
+ }
594
1562
  //# sourceMappingURL=store.js.map