rookery-agent 0.1.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 (508) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +367 -0
  3. package/docs/migration.md +88 -0
  4. package/package.json +39 -0
  5. package/packages/cli/dist/commands/chat.d.ts +52 -0
  6. package/packages/cli/dist/commands/chat.d.ts.map +1 -0
  7. package/packages/cli/dist/commands/chat.js +107 -0
  8. package/packages/cli/dist/commands/chat.js.map +1 -0
  9. package/packages/cli/dist/commands/config.d.ts +12 -0
  10. package/packages/cli/dist/commands/config.d.ts.map +1 -0
  11. package/packages/cli/dist/commands/config.js +156 -0
  12. package/packages/cli/dist/commands/config.js.map +1 -0
  13. package/packages/cli/dist/commands/doctor.d.ts +12 -0
  14. package/packages/cli/dist/commands/doctor.d.ts.map +1 -0
  15. package/packages/cli/dist/commands/doctor.js +137 -0
  16. package/packages/cli/dist/commands/doctor.js.map +1 -0
  17. package/packages/cli/dist/commands/memory.d.ts +34 -0
  18. package/packages/cli/dist/commands/memory.d.ts.map +1 -0
  19. package/packages/cli/dist/commands/memory.js +133 -0
  20. package/packages/cli/dist/commands/memory.js.map +1 -0
  21. package/packages/cli/dist/commands/org.d.ts +93 -0
  22. package/packages/cli/dist/commands/org.d.ts.map +1 -0
  23. package/packages/cli/dist/commands/org.js +389 -0
  24. package/packages/cli/dist/commands/org.js.map +1 -0
  25. package/packages/cli/dist/commands/serve.d.ts +13 -0
  26. package/packages/cli/dist/commands/serve.d.ts.map +1 -0
  27. package/packages/cli/dist/commands/serve.js +100 -0
  28. package/packages/cli/dist/commands/serve.js.map +1 -0
  29. package/packages/cli/dist/commands/sessions.d.ts +18 -0
  30. package/packages/cli/dist/commands/sessions.d.ts.map +1 -0
  31. package/packages/cli/dist/commands/sessions.js +88 -0
  32. package/packages/cli/dist/commands/sessions.js.map +1 -0
  33. package/packages/cli/dist/commands/shared.d.ts +59 -0
  34. package/packages/cli/dist/commands/shared.d.ts.map +1 -0
  35. package/packages/cli/dist/commands/shared.js +230 -0
  36. package/packages/cli/dist/commands/shared.js.map +1 -0
  37. package/packages/cli/dist/commands/tasks.d.ts +62 -0
  38. package/packages/cli/dist/commands/tasks.d.ts.map +1 -0
  39. package/packages/cli/dist/commands/tasks.js +262 -0
  40. package/packages/cli/dist/commands/tasks.js.map +1 -0
  41. package/packages/cli/dist/commands/tools.d.ts +8 -0
  42. package/packages/cli/dist/commands/tools.d.ts.map +1 -0
  43. package/packages/cli/dist/commands/tools.js +65 -0
  44. package/packages/cli/dist/commands/tools.js.map +1 -0
  45. package/packages/cli/dist/index.d.ts +15 -0
  46. package/packages/cli/dist/index.d.ts.map +1 -0
  47. package/packages/cli/dist/index.js +513 -0
  48. package/packages/cli/dist/index.js.map +1 -0
  49. package/packages/cli/dist/repl.d.ts +29 -0
  50. package/packages/cli/dist/repl.d.ts.map +1 -0
  51. package/packages/cli/dist/repl.js +634 -0
  52. package/packages/cli/dist/repl.js.map +1 -0
  53. package/packages/cli/dist/tui/App.d.ts +51 -0
  54. package/packages/cli/dist/tui/App.d.ts.map +1 -0
  55. package/packages/cli/dist/tui/App.js +461 -0
  56. package/packages/cli/dist/tui/App.js.map +1 -0
  57. package/packages/cli/dist/tui/commands.d.ts +34 -0
  58. package/packages/cli/dist/tui/commands.d.ts.map +1 -0
  59. package/packages/cli/dist/tui/commands.js +367 -0
  60. package/packages/cli/dist/tui/commands.js.map +1 -0
  61. package/packages/cli/dist/tui/components/ActivityLine.d.ts +16 -0
  62. package/packages/cli/dist/tui/components/ActivityLine.d.ts.map +1 -0
  63. package/packages/cli/dist/tui/components/ActivityLine.js +7 -0
  64. package/packages/cli/dist/tui/components/ActivityLine.js.map +1 -0
  65. package/packages/cli/dist/tui/components/AssignmentsView.d.ts +31 -0
  66. package/packages/cli/dist/tui/components/AssignmentsView.d.ts.map +1 -0
  67. package/packages/cli/dist/tui/components/AssignmentsView.js +79 -0
  68. package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -0
  69. package/packages/cli/dist/tui/components/Banner.d.ts +18 -0
  70. package/packages/cli/dist/tui/components/Banner.d.ts.map +1 -0
  71. package/packages/cli/dist/tui/components/Banner.js +16 -0
  72. package/packages/cli/dist/tui/components/Banner.js.map +1 -0
  73. package/packages/cli/dist/tui/components/CodeBlock.d.ts +19 -0
  74. package/packages/cli/dist/tui/components/CodeBlock.d.ts.map +1 -0
  75. package/packages/cli/dist/tui/components/CodeBlock.js +21 -0
  76. package/packages/cli/dist/tui/components/CodeBlock.js.map +1 -0
  77. package/packages/cli/dist/tui/components/InputBox.d.ts +25 -0
  78. package/packages/cli/dist/tui/components/InputBox.d.ts.map +1 -0
  79. package/packages/cli/dist/tui/components/InputBox.js +35 -0
  80. package/packages/cli/dist/tui/components/InputBox.js.map +1 -0
  81. package/packages/cli/dist/tui/components/Markdown.d.ts +74 -0
  82. package/packages/cli/dist/tui/components/Markdown.d.ts.map +1 -0
  83. package/packages/cli/dist/tui/components/Markdown.js +293 -0
  84. package/packages/cli/dist/tui/components/Markdown.js.map +1 -0
  85. package/packages/cli/dist/tui/components/Message.d.ts +29 -0
  86. package/packages/cli/dist/tui/components/Message.d.ts.map +1 -0
  87. package/packages/cli/dist/tui/components/Message.js +28 -0
  88. package/packages/cli/dist/tui/components/Message.js.map +1 -0
  89. package/packages/cli/dist/tui/components/Scrollback.d.ts +23 -0
  90. package/packages/cli/dist/tui/components/Scrollback.d.ts.map +1 -0
  91. package/packages/cli/dist/tui/components/Scrollback.js +36 -0
  92. package/packages/cli/dist/tui/components/Scrollback.js.map +1 -0
  93. package/packages/cli/dist/tui/components/SlashPalette.d.ts +17 -0
  94. package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -0
  95. package/packages/cli/dist/tui/components/SlashPalette.js +19 -0
  96. package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -0
  97. package/packages/cli/dist/tui/components/StatusLine.d.ts +61 -0
  98. package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -0
  99. package/packages/cli/dist/tui/components/StatusLine.js +55 -0
  100. package/packages/cli/dist/tui/components/StatusLine.js.map +1 -0
  101. package/packages/cli/dist/tui/components/ToolGroup.d.ts +33 -0
  102. package/packages/cli/dist/tui/components/ToolGroup.d.ts.map +1 -0
  103. package/packages/cli/dist/tui/components/ToolGroup.js +52 -0
  104. package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -0
  105. package/packages/cli/dist/tui/components/Wordmark.d.ts +35 -0
  106. package/packages/cli/dist/tui/components/Wordmark.d.ts.map +1 -0
  107. package/packages/cli/dist/tui/components/Wordmark.js +81 -0
  108. package/packages/cli/dist/tui/components/Wordmark.js.map +1 -0
  109. package/packages/cli/dist/tui/highlight.d.ts +29 -0
  110. package/packages/cli/dist/tui/highlight.d.ts.map +1 -0
  111. package/packages/cli/dist/tui/highlight.js +137 -0
  112. package/packages/cli/dist/tui/highlight.js.map +1 -0
  113. package/packages/cli/dist/tui/hooks/useColumns.d.ts +20 -0
  114. package/packages/cli/dist/tui/hooks/useColumns.d.ts.map +1 -0
  115. package/packages/cli/dist/tui/hooks/useColumns.js +38 -0
  116. package/packages/cli/dist/tui/hooks/useColumns.js.map +1 -0
  117. package/packages/cli/dist/tui/hooks/useHistory.d.ts +21 -0
  118. package/packages/cli/dist/tui/hooks/useHistory.d.ts.map +1 -0
  119. package/packages/cli/dist/tui/hooks/useHistory.js +57 -0
  120. package/packages/cli/dist/tui/hooks/useHistory.js.map +1 -0
  121. package/packages/cli/dist/tui/hooks/useSlash.d.ts +38 -0
  122. package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -0
  123. package/packages/cli/dist/tui/hooks/useSlash.js +89 -0
  124. package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -0
  125. package/packages/cli/dist/tui/hooks/useTurn.d.ts +75 -0
  126. package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -0
  127. package/packages/cli/dist/tui/hooks/useTurn.js +396 -0
  128. package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -0
  129. package/packages/cli/dist/tui/theme.d.ts +126 -0
  130. package/packages/cli/dist/tui/theme.d.ts.map +1 -0
  131. package/packages/cli/dist/tui/theme.js +127 -0
  132. package/packages/cli/dist/tui/theme.js.map +1 -0
  133. package/packages/cli/dist/tui/types.d.ts +205 -0
  134. package/packages/cli/dist/tui/types.d.ts.map +1 -0
  135. package/packages/cli/dist/tui/types.js +55 -0
  136. package/packages/cli/dist/tui/types.js.map +1 -0
  137. package/packages/cli/dist/ui/render.d.ts +74 -0
  138. package/packages/cli/dist/ui/render.d.ts.map +1 -0
  139. package/packages/cli/dist/ui/render.js +349 -0
  140. package/packages/cli/dist/ui/render.js.map +1 -0
  141. package/packages/cli/dist/ui/speech.d.ts +42 -0
  142. package/packages/cli/dist/ui/speech.d.ts.map +1 -0
  143. package/packages/cli/dist/ui/speech.js +257 -0
  144. package/packages/cli/dist/ui/speech.js.map +1 -0
  145. package/packages/cli/dist/ui/spinner.d.ts +17 -0
  146. package/packages/cli/dist/ui/spinner.d.ts.map +1 -0
  147. package/packages/cli/dist/ui/spinner.js +61 -0
  148. package/packages/cli/dist/ui/spinner.js.map +1 -0
  149. package/packages/cli/dist/ui/theme.d.ts +54 -0
  150. package/packages/cli/dist/ui/theme.d.ts.map +1 -0
  151. package/packages/cli/dist/ui/theme.js +74 -0
  152. package/packages/cli/dist/ui/theme.js.map +1 -0
  153. package/packages/cli/package.json +1 -0
  154. package/packages/core/dist/agents/legacy-persona.d.ts +4 -0
  155. package/packages/core/dist/agents/legacy-persona.d.ts.map +1 -0
  156. package/packages/core/dist/agents/legacy-persona.js +39 -0
  157. package/packages/core/dist/agents/legacy-persona.js.map +1 -0
  158. package/packages/core/dist/agents/orchestrator.d.ts +24 -0
  159. package/packages/core/dist/agents/orchestrator.d.ts.map +1 -0
  160. package/packages/core/dist/agents/orchestrator.js +88 -0
  161. package/packages/core/dist/agents/orchestrator.js.map +1 -0
  162. package/packages/core/dist/agents/persona.d.ts +56 -0
  163. package/packages/core/dist/agents/persona.d.ts.map +1 -0
  164. package/packages/core/dist/agents/persona.js +153 -0
  165. package/packages/core/dist/agents/persona.js.map +1 -0
  166. package/packages/core/dist/agents/roles.d.ts +21 -0
  167. package/packages/core/dist/agents/roles.d.ts.map +1 -0
  168. package/packages/core/dist/agents/roles.js +81 -0
  169. package/packages/core/dist/agents/roles.js.map +1 -0
  170. package/packages/core/dist/agents/team.d.ts +105 -0
  171. package/packages/core/dist/agents/team.d.ts.map +1 -0
  172. package/packages/core/dist/agents/team.js +623 -0
  173. package/packages/core/dist/agents/team.js.map +1 -0
  174. package/packages/core/dist/computer/keys.d.ts +12 -0
  175. package/packages/core/dist/computer/keys.d.ts.map +1 -0
  176. package/packages/core/dist/computer/keys.js +56 -0
  177. package/packages/core/dist/computer/keys.js.map +1 -0
  178. package/packages/core/dist/computer/mcp-server.d.ts +11 -0
  179. package/packages/core/dist/computer/mcp-server.d.ts.map +1 -0
  180. package/packages/core/dist/computer/mcp-server.js +228 -0
  181. package/packages/core/dist/computer/mcp-server.js.map +1 -0
  182. package/packages/core/dist/computer/powershell.d.ts +13 -0
  183. package/packages/core/dist/computer/powershell.d.ts.map +1 -0
  184. package/packages/core/dist/computer/powershell.js +359 -0
  185. package/packages/core/dist/computer/powershell.js.map +1 -0
  186. package/packages/core/dist/computer/tools.d.ts +43 -0
  187. package/packages/core/dist/computer/tools.d.ts.map +1 -0
  188. package/packages/core/dist/computer/tools.js +260 -0
  189. package/packages/core/dist/computer/tools.js.map +1 -0
  190. package/packages/core/dist/config.d.ts +32 -0
  191. package/packages/core/dist/config.d.ts.map +1 -0
  192. package/packages/core/dist/config.js +329 -0
  193. package/packages/core/dist/config.js.map +1 -0
  194. package/packages/core/dist/cron/parse.d.ts +52 -0
  195. package/packages/core/dist/cron/parse.d.ts.map +1 -0
  196. package/packages/core/dist/cron/parse.js +277 -0
  197. package/packages/core/dist/cron/parse.js.map +1 -0
  198. package/packages/core/dist/cron/scheduler.d.ts +102 -0
  199. package/packages/core/dist/cron/scheduler.d.ts.map +1 -0
  200. package/packages/core/dist/cron/scheduler.js +334 -0
  201. package/packages/core/dist/cron/scheduler.js.map +1 -0
  202. package/packages/core/dist/cron/script.d.ts +9 -0
  203. package/packages/core/dist/cron/script.d.ts.map +1 -0
  204. package/packages/core/dist/cron/script.js +113 -0
  205. package/packages/core/dist/cron/script.js.map +1 -0
  206. package/packages/core/dist/cron/store.d.ts +77 -0
  207. package/packages/core/dist/cron/store.d.ts.map +1 -0
  208. package/packages/core/dist/cron/store.js +229 -0
  209. package/packages/core/dist/cron/store.js.map +1 -0
  210. package/packages/core/dist/gateway/policy.d.ts +113 -0
  211. package/packages/core/dist/gateway/policy.d.ts.map +1 -0
  212. package/packages/core/dist/gateway/policy.js +373 -0
  213. package/packages/core/dist/gateway/policy.js.map +1 -0
  214. package/packages/core/dist/index.d.ts +45 -0
  215. package/packages/core/dist/index.d.ts.map +1 -0
  216. package/packages/core/dist/index.js +52 -0
  217. package/packages/core/dist/index.js.map +1 -0
  218. package/packages/core/dist/logger.d.ts +21 -0
  219. package/packages/core/dist/logger.d.ts.map +1 -0
  220. package/packages/core/dist/logger.js +61 -0
  221. package/packages/core/dist/logger.js.map +1 -0
  222. package/packages/core/dist/memory/db.d.ts +12 -0
  223. package/packages/core/dist/memory/db.d.ts.map +1 -0
  224. package/packages/core/dist/memory/db.js +414 -0
  225. package/packages/core/dist/memory/db.js.map +1 -0
  226. package/packages/core/dist/memory/extractor.d.ts +35 -0
  227. package/packages/core/dist/memory/extractor.d.ts.map +1 -0
  228. package/packages/core/dist/memory/extractor.js +159 -0
  229. package/packages/core/dist/memory/extractor.js.map +1 -0
  230. package/packages/core/dist/memory/gate.d.ts +68 -0
  231. package/packages/core/dist/memory/gate.d.ts.map +1 -0
  232. package/packages/core/dist/memory/gate.js +163 -0
  233. package/packages/core/dist/memory/gate.js.map +1 -0
  234. package/packages/core/dist/memory/recall.d.ts +61 -0
  235. package/packages/core/dist/memory/recall.d.ts.map +1 -0
  236. package/packages/core/dist/memory/recall.js +342 -0
  237. package/packages/core/dist/memory/recall.js.map +1 -0
  238. package/packages/core/dist/memory/sleep.d.ts +105 -0
  239. package/packages/core/dist/memory/sleep.d.ts.map +1 -0
  240. package/packages/core/dist/memory/sleep.js +888 -0
  241. package/packages/core/dist/memory/sleep.js.map +1 -0
  242. package/packages/core/dist/memory/store.d.ts +263 -0
  243. package/packages/core/dist/memory/store.d.ts.map +1 -0
  244. package/packages/core/dist/memory/store.js +999 -0
  245. package/packages/core/dist/memory/store.js.map +1 -0
  246. package/packages/core/dist/migration-cron.d.ts +37 -0
  247. package/packages/core/dist/migration-cron.d.ts.map +1 -0
  248. package/packages/core/dist/migration-cron.js +257 -0
  249. package/packages/core/dist/migration-cron.js.map +1 -0
  250. package/packages/core/dist/migration-scripts.d.ts +15 -0
  251. package/packages/core/dist/migration-scripts.d.ts.map +1 -0
  252. package/packages/core/dist/migration-scripts.js +97 -0
  253. package/packages/core/dist/migration-scripts.js.map +1 -0
  254. package/packages/core/dist/migration.d.ts +33 -0
  255. package/packages/core/dist/migration.d.ts.map +1 -0
  256. package/packages/core/dist/migration.js +296 -0
  257. package/packages/core/dist/migration.js.map +1 -0
  258. package/packages/core/dist/org/bridge.d.ts +42 -0
  259. package/packages/core/dist/org/bridge.d.ts.map +1 -0
  260. package/packages/core/dist/org/bridge.js +139 -0
  261. package/packages/core/dist/org/bridge.js.map +1 -0
  262. package/packages/core/dist/org/controller.d.ts +118 -0
  263. package/packages/core/dist/org/controller.d.ts.map +1 -0
  264. package/packages/core/dist/org/controller.js +1431 -0
  265. package/packages/core/dist/org/controller.js.map +1 -0
  266. package/packages/core/dist/org/mcp-bridge.d.ts +11 -0
  267. package/packages/core/dist/org/mcp-bridge.d.ts.map +1 -0
  268. package/packages/core/dist/org/mcp-bridge.js +148 -0
  269. package/packages/core/dist/org/mcp-bridge.js.map +1 -0
  270. package/packages/core/dist/org/planner.d.ts +60 -0
  271. package/packages/core/dist/org/planner.d.ts.map +1 -0
  272. package/packages/core/dist/org/planner.js +175 -0
  273. package/packages/core/dist/org/planner.js.map +1 -0
  274. package/packages/core/dist/org/ponytail.d.ts +24 -0
  275. package/packages/core/dist/org/ponytail.d.ts.map +1 -0
  276. package/packages/core/dist/org/ponytail.js +53 -0
  277. package/packages/core/dist/org/ponytail.js.map +1 -0
  278. package/packages/core/dist/org/project-mcp.d.ts +32 -0
  279. package/packages/core/dist/org/project-mcp.d.ts.map +1 -0
  280. package/packages/core/dist/org/project-mcp.js +53 -0
  281. package/packages/core/dist/org/project-mcp.js.map +1 -0
  282. package/packages/core/dist/org/prompts.d.ts +71 -0
  283. package/packages/core/dist/org/prompts.d.ts.map +1 -0
  284. package/packages/core/dist/org/prompts.js +268 -0
  285. package/packages/core/dist/org/prompts.js.map +1 -0
  286. package/packages/core/dist/org/store.d.ts +176 -0
  287. package/packages/core/dist/org/store.d.ts.map +1 -0
  288. package/packages/core/dist/org/store.js +594 -0
  289. package/packages/core/dist/org/store.js.map +1 -0
  290. package/packages/core/dist/org/tools.d.ts +22 -0
  291. package/packages/core/dist/org/tools.d.ts.map +1 -0
  292. package/packages/core/dist/org/tools.js +578 -0
  293. package/packages/core/dist/org/tools.js.map +1 -0
  294. package/packages/core/dist/profile.d.ts +16 -0
  295. package/packages/core/dist/profile.d.ts.map +1 -0
  296. package/packages/core/dist/profile.js +176 -0
  297. package/packages/core/dist/profile.js.map +1 -0
  298. package/packages/core/dist/providers/catalogue.d.ts +6 -0
  299. package/packages/core/dist/providers/catalogue.d.ts.map +1 -0
  300. package/packages/core/dist/providers/catalogue.js +104 -0
  301. package/packages/core/dist/providers/catalogue.js.map +1 -0
  302. package/packages/core/dist/providers/claude-code.d.ts +10 -0
  303. package/packages/core/dist/providers/claude-code.d.ts.map +1 -0
  304. package/packages/core/dist/providers/claude-code.js +321 -0
  305. package/packages/core/dist/providers/claude-code.js.map +1 -0
  306. package/packages/core/dist/providers/codex.d.ts +10 -0
  307. package/packages/core/dist/providers/codex.d.ts.map +1 -0
  308. package/packages/core/dist/providers/codex.js +375 -0
  309. package/packages/core/dist/providers/codex.js.map +1 -0
  310. package/packages/core/dist/providers/process.d.ts +48 -0
  311. package/packages/core/dist/providers/process.d.ts.map +1 -0
  312. package/packages/core/dist/providers/process.js +165 -0
  313. package/packages/core/dist/providers/process.js.map +1 -0
  314. package/packages/core/dist/providers/quota.d.ts +13 -0
  315. package/packages/core/dist/providers/quota.d.ts.map +1 -0
  316. package/packages/core/dist/providers/quota.js +231 -0
  317. package/packages/core/dist/providers/quota.js.map +1 -0
  318. package/packages/core/dist/providers/registry.d.ts +27 -0
  319. package/packages/core/dist/providers/registry.d.ts.map +1 -0
  320. package/packages/core/dist/providers/registry.js +64 -0
  321. package/packages/core/dist/providers/registry.js.map +1 -0
  322. package/packages/core/dist/runtime.d.ts +149 -0
  323. package/packages/core/dist/runtime.d.ts.map +1 -0
  324. package/packages/core/dist/runtime.js +778 -0
  325. package/packages/core/dist/runtime.js.map +1 -0
  326. package/packages/core/dist/skills/import.d.ts +41 -0
  327. package/packages/core/dist/skills/import.d.ts.map +1 -0
  328. package/packages/core/dist/skills/import.js +129 -0
  329. package/packages/core/dist/skills/import.js.map +1 -0
  330. package/packages/core/dist/skills/store.d.ts +57 -0
  331. package/packages/core/dist/skills/store.d.ts.map +1 -0
  332. package/packages/core/dist/skills/store.js +126 -0
  333. package/packages/core/dist/skills/store.js.map +1 -0
  334. package/packages/core/dist/tools/browser.d.ts +20 -0
  335. package/packages/core/dist/tools/browser.d.ts.map +1 -0
  336. package/packages/core/dist/tools/browser.js +72 -0
  337. package/packages/core/dist/tools/browser.js.map +1 -0
  338. package/packages/core/dist/tools/catalog.d.ts +67 -0
  339. package/packages/core/dist/tools/catalog.d.ts.map +1 -0
  340. package/packages/core/dist/tools/catalog.js +233 -0
  341. package/packages/core/dist/tools/catalog.js.map +1 -0
  342. package/packages/core/dist/tools/hub.d.ts +68 -0
  343. package/packages/core/dist/tools/hub.d.ts.map +1 -0
  344. package/packages/core/dist/tools/hub.js +213 -0
  345. package/packages/core/dist/tools/hub.js.map +1 -0
  346. package/packages/core/dist/types.d.ts +1031 -0
  347. package/packages/core/dist/types.d.ts.map +1 -0
  348. package/packages/core/dist/types.js +22 -0
  349. package/packages/core/dist/types.js.map +1 -0
  350. package/packages/core/dist/util/queue.d.ts +25 -0
  351. package/packages/core/dist/util/queue.d.ts.map +1 -0
  352. package/packages/core/dist/util/queue.js +64 -0
  353. package/packages/core/dist/util/queue.js.map +1 -0
  354. package/packages/core/package.json +1 -0
  355. package/packages/server/dist/auth.d.ts +12 -0
  356. package/packages/server/dist/auth.d.ts.map +1 -0
  357. package/packages/server/dist/auth.js +61 -0
  358. package/packages/server/dist/auth.js.map +1 -0
  359. package/packages/server/dist/context.d.ts +29 -0
  360. package/packages/server/dist/context.d.ts.map +1 -0
  361. package/packages/server/dist/context.js +46 -0
  362. package/packages/server/dist/context.js.map +1 -0
  363. package/packages/server/dist/env.d.ts +8 -0
  364. package/packages/server/dist/env.d.ts.map +1 -0
  365. package/packages/server/dist/env.js +36 -0
  366. package/packages/server/dist/env.js.map +1 -0
  367. package/packages/server/dist/gateways/push.d.ts +22 -0
  368. package/packages/server/dist/gateways/push.d.ts.map +1 -0
  369. package/packages/server/dist/gateways/push.js +267 -0
  370. package/packages/server/dist/gateways/push.js.map +1 -0
  371. package/packages/server/dist/gateways/telegram-api.d.ts +82 -0
  372. package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -0
  373. package/packages/server/dist/gateways/telegram-api.js +168 -0
  374. package/packages/server/dist/gateways/telegram-api.js.map +1 -0
  375. package/packages/server/dist/gateways/telegram.d.ts +32 -0
  376. package/packages/server/dist/gateways/telegram.d.ts.map +1 -0
  377. package/packages/server/dist/gateways/telegram.js +583 -0
  378. package/packages/server/dist/gateways/telegram.js.map +1 -0
  379. package/packages/server/dist/index.d.ts +12 -0
  380. package/packages/server/dist/index.d.ts.map +1 -0
  381. package/packages/server/dist/index.js +12 -0
  382. package/packages/server/dist/index.js.map +1 -0
  383. package/packages/server/dist/main.d.ts +2 -0
  384. package/packages/server/dist/main.d.ts.map +1 -0
  385. package/packages/server/dist/main.js +74 -0
  386. package/packages/server/dist/main.js.map +1 -0
  387. package/packages/server/dist/routes/agents.d.ts +5 -0
  388. package/packages/server/dist/routes/agents.d.ts.map +1 -0
  389. package/packages/server/dist/routes/agents.js +6 -0
  390. package/packages/server/dist/routes/agents.js.map +1 -0
  391. package/packages/server/dist/routes/chat.d.ts +10 -0
  392. package/packages/server/dist/routes/chat.d.ts.map +1 -0
  393. package/packages/server/dist/routes/chat.js +36 -0
  394. package/packages/server/dist/routes/chat.js.map +1 -0
  395. package/packages/server/dist/routes/config.d.ts +4 -0
  396. package/packages/server/dist/routes/config.d.ts.map +1 -0
  397. package/packages/server/dist/routes/config.js +58 -0
  398. package/packages/server/dist/routes/config.js.map +1 -0
  399. package/packages/server/dist/routes/cron.d.ts +10 -0
  400. package/packages/server/dist/routes/cron.d.ts.map +1 -0
  401. package/packages/server/dist/routes/cron.js +128 -0
  402. package/packages/server/dist/routes/cron.js.map +1 -0
  403. package/packages/server/dist/routes/gateways.d.ts +10 -0
  404. package/packages/server/dist/routes/gateways.d.ts.map +1 -0
  405. package/packages/server/dist/routes/gateways.js +32 -0
  406. package/packages/server/dist/routes/gateways.js.map +1 -0
  407. package/packages/server/dist/routes/health.d.ts +8 -0
  408. package/packages/server/dist/routes/health.d.ts.map +1 -0
  409. package/packages/server/dist/routes/health.js +12 -0
  410. package/packages/server/dist/routes/health.js.map +1 -0
  411. package/packages/server/dist/routes/memories.d.ts +11 -0
  412. package/packages/server/dist/routes/memories.d.ts.map +1 -0
  413. package/packages/server/dist/routes/memories.js +134 -0
  414. package/packages/server/dist/routes/memories.js.map +1 -0
  415. package/packages/server/dist/routes/org.d.ts +13 -0
  416. package/packages/server/dist/routes/org.d.ts.map +1 -0
  417. package/packages/server/dist/routes/org.js +316 -0
  418. package/packages/server/dist/routes/org.js.map +1 -0
  419. package/packages/server/dist/routes/profile.d.ts +4 -0
  420. package/packages/server/dist/routes/profile.d.ts.map +1 -0
  421. package/packages/server/dist/routes/profile.js +51 -0
  422. package/packages/server/dist/routes/profile.js.map +1 -0
  423. package/packages/server/dist/routes/providers.d.ts +9 -0
  424. package/packages/server/dist/routes/providers.d.ts.map +1 -0
  425. package/packages/server/dist/routes/providers.js +41 -0
  426. package/packages/server/dist/routes/providers.js.map +1 -0
  427. package/packages/server/dist/routes/sessions.d.ts +9 -0
  428. package/packages/server/dist/routes/sessions.d.ts.map +1 -0
  429. package/packages/server/dist/routes/sessions.js +72 -0
  430. package/packages/server/dist/routes/sessions.js.map +1 -0
  431. package/packages/server/dist/routes/sleep.d.ts +12 -0
  432. package/packages/server/dist/routes/sleep.d.ts.map +1 -0
  433. package/packages/server/dist/routes/sleep.js +70 -0
  434. package/packages/server/dist/routes/sleep.js.map +1 -0
  435. package/packages/server/dist/routes/stats.d.ts +17 -0
  436. package/packages/server/dist/routes/stats.d.ts.map +1 -0
  437. package/packages/server/dist/routes/stats.js +57 -0
  438. package/packages/server/dist/routes/stats.js.map +1 -0
  439. package/packages/server/dist/routes/team.d.ts +11 -0
  440. package/packages/server/dist/routes/team.d.ts.map +1 -0
  441. package/packages/server/dist/routes/team.js +36 -0
  442. package/packages/server/dist/routes/team.js.map +1 -0
  443. package/packages/server/dist/routes/tools.d.ts +10 -0
  444. package/packages/server/dist/routes/tools.d.ts.map +1 -0
  445. package/packages/server/dist/routes/tools.js +128 -0
  446. package/packages/server/dist/routes/tools.js.map +1 -0
  447. package/packages/server/dist/routes/tts.d.ts +12 -0
  448. package/packages/server/dist/routes/tts.d.ts.map +1 -0
  449. package/packages/server/dist/routes/tts.js +38 -0
  450. package/packages/server/dist/routes/tts.js.map +1 -0
  451. package/packages/server/dist/routes/ws.d.ts +13 -0
  452. package/packages/server/dist/routes/ws.d.ts.map +1 -0
  453. package/packages/server/dist/routes/ws.js +96 -0
  454. package/packages/server/dist/routes/ws.js.map +1 -0
  455. package/packages/server/dist/schemas.d.ts +981 -0
  456. package/packages/server/dist/schemas.d.ts.map +1 -0
  457. package/packages/server/dist/schemas.js +339 -0
  458. package/packages/server/dist/schemas.js.map +1 -0
  459. package/packages/server/dist/server.d.ts +20 -0
  460. package/packages/server/dist/server.d.ts.map +1 -0
  461. package/packages/server/dist/server.js +234 -0
  462. package/packages/server/dist/server.js.map +1 -0
  463. package/packages/server/dist/services/stream.d.ts +77 -0
  464. package/packages/server/dist/services/stream.d.ts.map +1 -0
  465. package/packages/server/dist/services/stream.js +84 -0
  466. package/packages/server/dist/services/stream.js.map +1 -0
  467. package/packages/server/dist/services/tts.d.ts +53 -0
  468. package/packages/server/dist/services/tts.d.ts.map +1 -0
  469. package/packages/server/dist/services/tts.js +281 -0
  470. package/packages/server/dist/services/tts.js.map +1 -0
  471. package/packages/server/dist/services/voice-keys.d.ts +26 -0
  472. package/packages/server/dist/services/voice-keys.d.ts.map +1 -0
  473. package/packages/server/dist/services/voice-keys.js +51 -0
  474. package/packages/server/dist/services/voice-keys.js.map +1 -0
  475. package/packages/server/dist/static.d.ts +12 -0
  476. package/packages/server/dist/static.d.ts.map +1 -0
  477. package/packages/server/dist/static.js +63 -0
  478. package/packages/server/dist/static.js.map +1 -0
  479. package/packages/server/package.json +1 -0
  480. package/packages/web/dist/apple-touch-icon.png +0 -0
  481. package/packages/web/dist/assets/3d-force-graph-BPZmoydi.js +1163 -0
  482. package/packages/web/dist/assets/bricolage-grotesque-latin-ext-wght-normal-CcLUaPy7.woff2 +0 -0
  483. package/packages/web/dist/assets/bricolage-grotesque-latin-wght-normal-DLoelf7F.woff2 +0 -0
  484. package/packages/web/dist/assets/bricolage-grotesque-vietnamese-wght-normal-BUzh504Q.woff2 +0 -0
  485. package/packages/web/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  486. package/packages/web/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  487. package/packages/web/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  488. package/packages/web/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  489. package/packages/web/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  490. package/packages/web/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  491. package/packages/web/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  492. package/packages/web/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  493. package/packages/web/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  494. package/packages/web/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  495. package/packages/web/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  496. package/packages/web/dist/assets/index-IBSTzK7-.js +1255 -0
  497. package/packages/web/dist/assets/index-qUXUui7W.css +1 -0
  498. package/packages/web/dist/assets/three-spritetext-B9ZIW7c-.js +4 -0
  499. package/packages/web/dist/assets/three.module-cmFfBtHS.js +4228 -0
  500. package/packages/web/dist/favicon.ico +0 -0
  501. package/packages/web/dist/favicon.svg +2 -0
  502. package/packages/web/dist/index.html +28 -0
  503. package/packages/web/dist/logo-light.svg +2 -0
  504. package/packages/web/dist/logo.svg +2 -0
  505. package/packages/web/dist/mark-light.svg +2 -0
  506. package/packages/web/dist/mark.svg +2 -0
  507. package/packages/web/package.json +1 -0
  508. package/scripts/rookery.mjs +183 -0
@@ -0,0 +1,778 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { join } from 'node:path';
3
+ import { ASSISTANT_MEMORY_OWNER } from './types.js';
4
+ import { agentWorkspace, databasePath, loadConfig } from './config.js';
5
+ import { createLogger, silentLogger } from './logger.js';
6
+ import { ProviderRegistry } from './providers/registry.js';
7
+ import { Store } from './memory/store.js';
8
+ import { coreProfile, dropContradicted, recall } from './memory/recall.js';
9
+ import { extractMemories, smallModelFor } from './memory/extractor.js';
10
+ import { admitCandidates, linkEntities } from './memory/gate.js';
11
+ import { SleepRunner } from './memory/sleep.js';
12
+ import { buildSystemPrompt, deriveTitle } from './agents/persona.js';
13
+ import { BridgeServer } from './org/bridge.js';
14
+ import { OrgController } from './org/controller.js';
15
+ import { assistantOrgBlock, buildAgentChatPrompt } from './org/prompts.js';
16
+ import { dormantToolsHint, ensureToolServers, toolServersFor } from './tools/hub.js';
17
+ import { SkillStore, renderSkillsIndex } from './skills/store.js';
18
+ import { CronScheduler } from './cron/scheduler.js';
19
+ import { describeCron } from './cron/parse.js';
20
+ import { runCronScript } from './cron/script.js';
21
+ import { EventQueue } from './util/queue.js';
22
+ /**
23
+ * The assistant runtime.
24
+ *
25
+ * One turn is: resolve session -> recall memories -> assemble context ->
26
+ * stream the provider -> persist -> learn.
27
+ *
28
+ * There is no routing step and no agent selection. Rookery is one personal
29
+ * assistant: the identity is fixed, and the provider only ever changes when
30
+ * the caller asks for it or the current one is logged out. That matters
31
+ * beyond persona - switching provider throws away `providerSessionId`, so a
32
+ * router that changed its mind mid-conversation would silently drop the
33
+ * thread the assistant was holding.
34
+ *
35
+ * What the assistant can do beyond talking is run its company: every turn
36
+ * gets Rookery's tools through the MCP bridge, and an `assign` call from
37
+ * inside the provider process starts an agent in the background. Those
38
+ * assignments report into the same event stream as the turn itself.
39
+ *
40
+ * The assistant's own process always runs in the workspace. It never sees
41
+ * the directory Rookery was started from; only agents work in project
42
+ * directories, and only when the project names one.
43
+ */
44
+ /**
45
+ * How many provider processes one turn may use. Two, because a turn that
46
+ * attaches a tool server needs a second process to actually get it, and
47
+ * because a third would let the assistant loop over its own switches.
48
+ */
49
+ const MAX_PROVIDER_PASSES = 2;
50
+ /** Add up what two passes of one turn cost; the last pass owns the context gauge. */
51
+ function mergeUsage(base, next) {
52
+ if (!base)
53
+ return next;
54
+ if (!next)
55
+ return base;
56
+ const sum = (a, b) => (a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0));
57
+ return {
58
+ inputTokens: sum(base.inputTokens, next.inputTokens),
59
+ outputTokens: sum(base.outputTokens, next.outputTokens),
60
+ cachedInputTokens: sum(base.cachedInputTokens, next.cachedInputTokens),
61
+ reasoningTokens: sum(base.reasoningTokens, next.reasoningTokens),
62
+ costUsd: sum(base.costUsd, next.costUsd),
63
+ contextTokens: next.contextTokens ?? base.contextTokens,
64
+ contextWindow: next.contextWindow ?? base.contextWindow,
65
+ };
66
+ }
67
+ /**
68
+ * What the second pass is asked. It is not the user talking, and it says so:
69
+ * the assistant should pick the work back up, not answer this sentence.
70
+ */
71
+ function continuePrompt(servers) {
72
+ return [
73
+ '[Rookery] The tool servers you just switched on are attached now: ' + servers.join(', ') + '.',
74
+ 'This message is from the system, not from your user, so do not address it and do not greet.',
75
+ 'Carry on with what you stopped for, using the new tools, and finish the answer without',
76
+ 'repeating what you already said.',
77
+ ].join(' ');
78
+ }
79
+ export class Assistant extends EventEmitter {
80
+ config;
81
+ store;
82
+ providers;
83
+ log;
84
+ /** The company: structure, rules and assignment execution. */
85
+ org;
86
+ /** The skills folder: written procedures the assistant and agents open on demand. */
87
+ skills;
88
+ /**
89
+ * The clock: schedules that fire while the process is up. Created here so
90
+ * the assistant's tools can manage them, started by whoever hosts the
91
+ * runtime for real (the server), never by a one-off CLI command.
92
+ */
93
+ cron;
94
+ /**
95
+ * The night shift: condensing, linking and concluding over the memory
96
+ * bank while nobody is talking. Fires from a schedule like anything else,
97
+ * and can be started by hand from the memory page.
98
+ */
99
+ sleep;
100
+ /**
101
+ * Whether a notification would actually reach the user right now. Set by
102
+ * whoever owns the outgoing channels (the server, for its gateways); left
103
+ * unset, the `notify` tool falls back to "is anything listening at all".
104
+ * A function rather than a flag because the answer changes with a setting,
105
+ * a blocked recipient or a channel that was switched off mid-session.
106
+ */
107
+ notifyProbe;
108
+ constructor(options = {}) {
109
+ super();
110
+ this.config = loadConfig(options.config ?? {});
111
+ this.store = options.store ?? new Store(databasePath(this.config));
112
+ this.providers = options.registry ?? new ProviderRegistry();
113
+ this.log =
114
+ options.logger ??
115
+ (this.config.logLevel === 'silent'
116
+ ? silentLogger
117
+ : createLogger({ level: this.config.logLevel, home: this.config.home, scope: 'runtime' }));
118
+ this.skills = new SkillStore(this.config.skillsDir);
119
+ this.cron = new CronScheduler({
120
+ store: this.store,
121
+ runner: (job, run, signal) => this.#runScheduled(job, run, signal),
122
+ logger: this.log,
123
+ timeoutMs: this.config.org.assignmentTimeoutMs,
124
+ });
125
+ // Before the controller: the `sleep_now` tool needs it at construction.
126
+ this.sleep = new SleepRunner({
127
+ store: this.store,
128
+ registry: this.providers,
129
+ config: this.config,
130
+ logger: this.log,
131
+ });
132
+ this.org = new OrgController({
133
+ store: this.store,
134
+ registry: this.providers,
135
+ config: this.config,
136
+ bridge: new BridgeServer({ runDir: join(this.config.home, 'run') }),
137
+ logger: this.log,
138
+ cron: this.cron,
139
+ sleep: this.sleep,
140
+ // The `notify` tool asks this instead of a transport it cannot see. A
141
+ // listener on `notify` is the floor, not the answer: a push service
142
+ // attaches once at startup and stays attached while it is switched
143
+ // off, so a bare listener count would let the tool report "Sent" into
144
+ // a channel that drops the message. Whoever hosts the runtime sets
145
+ // `notifyProbe` to the honest test.
146
+ canNotify: () => (this.notifyProbe ? this.notifyProbe() : this.listenerCount('notify') > 0),
147
+ });
148
+ this.cron.on('cron', (event) => this.emit('cron', event));
149
+ this.cron.on('message', (event) => this.emit('message', event));
150
+ // Every client watches the brain fall asleep and wake up again.
151
+ this.sleep.on('sleep', (event) => this.emit('sleep', event));
152
+ // Anything an agent does is interesting to every client, not only the
153
+ // turn that caused it: the org page shows activity live.
154
+ this.org.on('assignment', (event) => this.emit('assignment', event));
155
+ this.org.on('message', (event) => this.emit('message', event));
156
+ this.org.on('task', (event) => this.emit('task', event));
157
+ this.org.on('changed', (change) => this.emit('changed', change));
158
+ // The assistant reaching out on its own initiative - no HTTP, no
159
+ // Telegram here, just an event a channel in another package can listen
160
+ // for and act on however it likes.
161
+ this.org.on('notify', (event) => this.emit('notify', event));
162
+ }
163
+ close() {
164
+ this.cron.stop();
165
+ void this.org.bridge.close();
166
+ this.store.close();
167
+ }
168
+ /* ---------------------------- sessions ---------------------------- */
169
+ createSession(input = {}) {
170
+ const agent = input.agentId ? this.store.org.getAgent(input.agentId) : null;
171
+ if (input.agentId && !agent)
172
+ throw new Error('No agent ' + input.agentId + '.');
173
+ return this.store.createSession({
174
+ title: input.title,
175
+ kind: input.kind,
176
+ provider: input.provider ?? agent?.provider ?? this.config.defaultProvider,
177
+ model: input.model ?? agent?.model ?? this.config.defaultModel,
178
+ cwd: this.config.workspace,
179
+ projectId: input.projectId,
180
+ agentId: agent?.id,
181
+ });
182
+ }
183
+ getSession(id) {
184
+ return this.store.getSession(id);
185
+ }
186
+ /**
187
+ * Recent sessions; `agentId` narrows to one counterpart (`null` = the
188
+ * assistant), `kind` to chats or voice. Archived conversations stay out
189
+ * unless asked for, because archiving is how a list is kept short.
190
+ */
191
+ listSessions(limit = 50, agentId, kind, includeArchived = false) {
192
+ return this.store.listSessions({ limit, agentId, kind, includeArchived });
193
+ }
194
+ deleteSession(id) {
195
+ this.store.deleteSession(id);
196
+ }
197
+ /** Forget the provider-side thread so the next turn starts cold. */
198
+ resetSessionContext(id) {
199
+ this.store.updateSession(id, { providerSessionId: undefined });
200
+ this.store.db
201
+ .prepare('UPDATE sessions SET provider_session_id = NULL WHERE id = ?')
202
+ .run(id);
203
+ }
204
+ /* ------------------------------ memory ---------------------------- */
205
+ recallMemories(text, limit) {
206
+ return recall(this.store, {
207
+ text,
208
+ limit: limit ?? this.config.memory.recallLimit,
209
+ threshold: this.config.memory.recallThreshold,
210
+ hopEntity: this.config.memory.graph.hopEntity,
211
+ hopEdge: this.config.memory.graph.hopEdge,
212
+ touch: false,
213
+ });
214
+ }
215
+ /**
216
+ * Something the user told us to keep. Marked `user`, which makes it
217
+ * untouchable for the nightly run: it is never merged away and never put
218
+ * to sleep, however little it gets recalled.
219
+ */
220
+ rememberFact(input) {
221
+ const record = this.store.upsertMemory({
222
+ kind: input.kind ?? 'fact',
223
+ content: input.content,
224
+ tags: input.tags,
225
+ importance: input.importance,
226
+ owner: ASSISTANT_MEMORY_OWNER,
227
+ origin: 'user',
228
+ pinned: input.pinned,
229
+ });
230
+ linkEntities(this.store, ASSISTANT_MEMORY_OWNER, record.id, input.tags ?? []);
231
+ return record;
232
+ }
233
+ /* ------------------------------- sleep ---------------------------- */
234
+ /** Run a night by hand, for one bank. The memory page's "sleep now". */
235
+ async sleepNow(owner = ASSISTANT_MEMORY_OWNER, signal) {
236
+ return this.sleep.run({ owner, trigger: 'manual', signal });
237
+ }
238
+ sleepRuns(owner, limit = 30) {
239
+ return this.store.listSleepRuns({ owner, limit });
240
+ }
241
+ /** Take one night back, in a single transaction. */
242
+ undoSleep(runId) {
243
+ return this.sleep.undo(runId);
244
+ }
245
+ /**
246
+ * Make sure the nightly run has a schedule. Called once when the clock
247
+ * starts. The job is an ordinary `cron_jobs` row, so it shows up on the
248
+ * schedules page, can be edited, switched off or run by hand like any
249
+ * other - there is no second, hidden timer anywhere.
250
+ */
251
+ ensureSleepSchedule() {
252
+ const sleep = this.config.memory.sleep;
253
+ if (!sleep.enabled)
254
+ return null;
255
+ try {
256
+ const organization = this.org.activeOrganization();
257
+ const existing = this.cron.list(organization.id).find((job) => job.kind === 'sleep');
258
+ if (existing) {
259
+ // Follow the config when the user changes it there, but never
260
+ // re-enable a job they switched off by hand.
261
+ if (existing.schedule !== sleep.schedule && existing.enabled) {
262
+ return this.cron.update(existing.id, { schedule: sleep.schedule });
263
+ }
264
+ return existing;
265
+ }
266
+ return this.cron.create({
267
+ orgId: organization.id,
268
+ name: 'Memory sleep',
269
+ schedule: sleep.schedule,
270
+ kind: 'sleep',
271
+ prompt: sleep.scope,
272
+ createdBy: 'user',
273
+ });
274
+ }
275
+ catch (error) {
276
+ this.log.warn('Could not set up the nightly memory schedule', { error: error.message });
277
+ return null;
278
+ }
279
+ }
280
+ /* ------------------------------- chat ----------------------------- */
281
+ /** One conversational turn, streamed. Assignments the turn starts ride the same stream. */
282
+ async *chat(input) {
283
+ const prompt = input.text.trim();
284
+ if (!prompt) {
285
+ yield { type: 'error', message: 'Nothing to send.', fatal: true };
286
+ return;
287
+ }
288
+ const session = this.#resolveSession(input);
289
+ // The counterpart: an agent for a direct chat, otherwise the assistant.
290
+ const agent = session.agentId ? this.store.org.getAgent(session.agentId) : null;
291
+ if (session.agentId && !agent) {
292
+ yield { type: 'error', message: 'The agent this conversation belonged to no longer exists.', fatal: true };
293
+ return;
294
+ }
295
+ const owner = agent ? agent.id : ASSISTANT_MEMORY_OWNER;
296
+ if (input.projectId && input.projectId !== session.projectId) {
297
+ this.store.updateSession(session.id, { projectId: input.projectId });
298
+ session.projectId = input.projectId;
299
+ }
300
+ const wanted = input.provider ?? session.provider;
301
+ const providerId = await this.providers.resolveUsable(wanted);
302
+ if (!providerId) {
303
+ const statuses = await this.providers.statuses();
304
+ const detail = statuses.map((s) => s.id + ': ' + (s.detail ?? 'unavailable')).join(' | ');
305
+ yield { type: 'error', message: 'No AI provider is ready. ' + detail, fatal: true };
306
+ return;
307
+ }
308
+ if (providerId !== wanted) {
309
+ yield { type: 'status', label: 'provider', detail: wanted + ' is not logged in, using ' + providerId };
310
+ }
311
+ // Resuming the provider's own thread only works on the same provider.
312
+ const resumed = Boolean(session.providerSessionId) && session.provider === providerId;
313
+ const model = input.model ?? session.model ?? this.config.defaultModel;
314
+ const effort = input.effort ?? this.config.defaultEffort;
315
+ let memories = [];
316
+ if (this.config.memory.enabled) {
317
+ yield { type: 'status', label: 'recalling', detail: 'searching memory' };
318
+ const matched = recall(this.store, {
319
+ text: prompt,
320
+ owner,
321
+ limit: this.config.memory.recallLimit,
322
+ threshold: this.config.memory.recallThreshold,
323
+ hopEntity: this.config.memory.graph.hopEntity,
324
+ hopEdge: this.config.memory.graph.hopEdge,
325
+ });
326
+ const profile = coreProfile(this.store, {
327
+ owner,
328
+ limit: Math.max(3, Math.floor(this.config.memory.recallLimit / 2)),
329
+ });
330
+ const byId = new Map();
331
+ for (const memory of profile)
332
+ byId.set(memory.id, memory);
333
+ for (const memory of matched)
334
+ byId.set(memory.id, memory);
335
+ // Of a contradicting pair only the newer sentence goes into the prompt;
336
+ // the older one stays in the bank and stays visible in the inspector.
337
+ memories = dropContradicted(this.store, [...byId.values()]).sort((a, b) => b.score - a.score);
338
+ if (memories.length) {
339
+ yield { type: 'memory', action: 'recalled', count: memories.length, items: memories };
340
+ }
341
+ }
342
+ const history = resumed ? [] : this.store.getMessages(session.id, this.config.memory.workingWindow);
343
+ // The company block: who works here, what is running, what arrived in
344
+ // the inbox. Read once per turn; the inbox is then marked as read.
345
+ const organization = this.org.activeOrganization();
346
+ const snapshot = this.org.snapshot(organization.id);
347
+ const inbox = this.store.org.inbox(organization.id, agent?.id ?? null, { unreadOnly: true });
348
+ const project = session.projectId ? (this.store.org.getProject(session.projectId) ?? undefined) : undefined;
349
+ if (inbox.length)
350
+ this.store.org.markRead(inbox.map((message) => message.id));
351
+ // The hub decides which extra MCP servers this turn gets, and the prompt
352
+ // carries one paragraph per server plus the index of skills to open.
353
+ const who = agent ? 'agent' : 'assistant';
354
+ await ensureToolServers(this.config, who, providerId, project?.id, (id, error) => this.log.warn('Tool server could not prepare', { id, error: error.message }));
355
+ const extra = toolServersFor(this.config, who, providerId, project?.id);
356
+ // The assistant also hears about the servers it could attach but has not:
357
+ // a switch it does not know about is a wall it cannot climb.
358
+ const toolHints = [...extra.hints, dormantToolsHint(this.config, who, project?.id)].filter(Boolean);
359
+ const skillsIndex = renderSkillsIndex(this.skills.for(who));
360
+ const systemPrompt = agent
361
+ ? buildAgentChatPrompt({
362
+ config: this.config, agent, snapshot, memories, inbox, history, resumed, project,
363
+ toolHints, skillsIndex,
364
+ })
365
+ : buildSystemPrompt({
366
+ config: this.config,
367
+ query: prompt,
368
+ memories,
369
+ history,
370
+ resumed,
371
+ // A voice session speaks whichever surface the turn came from.
372
+ voice: input.voice ?? session.kind === 'voice',
373
+ orgBlock: assistantOrgBlock(this.config, snapshot, inbox, project, this.cron.list(organization.id)),
374
+ toolHints,
375
+ skillsIndex,
376
+ // Lets the memory block group itself by entity.
377
+ store: this.store,
378
+ });
379
+ this.store.addMessage({ sessionId: session.id, role: 'user', content: prompt });
380
+ if (session.messageCount === 0 && session.title === 'New conversation') {
381
+ this.store.updateSession(session.id, { title: deriveTitle(prompt) });
382
+ }
383
+ const provider = this.providers.get(providerId);
384
+ const started = Date.now();
385
+ let answer = '';
386
+ const toolCalls = [];
387
+ let providerSessionId = resumed ? session.providerSessionId : undefined;
388
+ let failed = false;
389
+ let usage;
390
+ yield { type: 'session', sessionId: session.id, providerSessionId, provider: providerId, model };
391
+ // An agent in a chat may look at its project; the assistant stays in the
392
+ // workspace and is a person, not Claude Code's coding agent.
393
+ const cwd = agent ? (project?.path || agentWorkspace(this.config, agent.id)) : this.config.workspace;
394
+ // What this pass of the provider is run with. A turn usually has exactly
395
+ // one pass; see the continuation below for why it sometimes has two.
396
+ let passPrompt = prompt;
397
+ let passSystemPrompt = systemPrompt;
398
+ let passExtra = extra;
399
+ let attached = new Set(extra.specs.map((spec) => spec.name));
400
+ for (let pass = 1; pass <= MAX_PROVIDER_PASSES; pass += 1) {
401
+ // Everything the turn produces goes through one queue: the provider's
402
+ // own events, and whatever the tool calls it makes cause in the company.
403
+ const queue = new EventQueue();
404
+ const token = this.org.register({
405
+ orgId: organization.id,
406
+ audience: agent ? 'agent' : 'assistant',
407
+ agentId: agent?.id,
408
+ sessionId: session.id,
409
+ projectId: session.projectId,
410
+ depth: agent ? 0 : -1,
411
+ emit: (event) => queue.push(event),
412
+ signal: input.signal,
413
+ });
414
+ const currentPrompt = passPrompt;
415
+ const currentSystemPrompt = passSystemPrompt;
416
+ const currentSpecs = passExtra.specs;
417
+ const currentResume = providerSessionId;
418
+ const pump = (async () => {
419
+ try {
420
+ const mcp = await this.org.bridge.spec(token);
421
+ for await (const event of provider.run({
422
+ prompt: currentPrompt,
423
+ systemPrompt: currentSystemPrompt,
424
+ systemPromptMode: agent ? 'append' : 'replace',
425
+ providerSessionId: currentResume,
426
+ model,
427
+ effort,
428
+ cwd,
429
+ permission: input.permission ?? agent?.permission ?? this.config.defaultPermission,
430
+ mcp,
431
+ mcpExtra: currentSpecs.length ? currentSpecs : undefined,
432
+ signal: input.signal,
433
+ })) {
434
+ queue.push(event);
435
+ }
436
+ }
437
+ catch (error) {
438
+ queue.push({ type: 'error', message: error.message, fatal: true });
439
+ }
440
+ finally {
441
+ queue.close();
442
+ }
443
+ })();
444
+ let passText = '';
445
+ try {
446
+ for await (const event of queue.drain()) {
447
+ switch (event.type) {
448
+ case 'tool':
449
+ toolCalls.push(event);
450
+ yield event;
451
+ break;
452
+ case 'text':
453
+ passText += event.delta;
454
+ yield event;
455
+ break;
456
+ case 'session':
457
+ providerSessionId = event.providerSessionId ?? providerSessionId;
458
+ break;
459
+ case 'done':
460
+ providerSessionId = event.providerSessionId ?? providerSessionId;
461
+ passText = event.text || passText;
462
+ usage = mergeUsage(usage, event.usage);
463
+ break;
464
+ case 'error':
465
+ if (event.fatal)
466
+ failed = true;
467
+ yield event;
468
+ break;
469
+ default:
470
+ yield event;
471
+ }
472
+ }
473
+ }
474
+ finally {
475
+ await pump;
476
+ this.org.unregister(token);
477
+ }
478
+ answer = answer && passText ? answer + '\n\n' + passText : answer || passText;
479
+ // The continuation. A tool server the assistant switched on mid-turn
480
+ // can only be attached to a provider process that has not started yet,
481
+ // so without this the work stalls until the user asks again - exactly
482
+ // the dead end the assistant is told not to accept. Instead the turn
483
+ // runs once more with the new servers attached and the provider's own
484
+ // session resumed, and the two answers are joined.
485
+ if (failed || agent || pass === MAX_PROVIDER_PASSES)
486
+ break;
487
+ if (input.signal?.aborted)
488
+ break;
489
+ const next = toolServersFor(this.config, who, providerId, project?.id);
490
+ const fresh = next.specs.map((spec) => spec.name).filter((name) => !attached.has(name));
491
+ if (!fresh.length)
492
+ break;
493
+ await ensureToolServers(this.config, who, providerId, project?.id, (id, error) => this.log.warn('Tool server could not prepare', { id, error: error.message }));
494
+ passExtra = next;
495
+ attached = new Set(next.specs.map((spec) => spec.name));
496
+ passSystemPrompt = buildSystemPrompt({
497
+ config: this.config,
498
+ query: prompt,
499
+ memories,
500
+ resumed: true,
501
+ voice: input.voice ?? session.kind === 'voice',
502
+ orgBlock: assistantOrgBlock(this.config, snapshot, [], project, this.cron.list(organization.id)),
503
+ toolHints: [...next.hints, dormantToolsHint(this.config, who, project?.id)].filter(Boolean),
504
+ skillsIndex,
505
+ store: this.store,
506
+ });
507
+ passPrompt = continuePrompt(fresh);
508
+ yield { type: 'status', label: 'tools', detail: fresh.join(', ') + ' attached, carrying on' };
509
+ }
510
+ if (failed && !answer && !toolCalls.length) {
511
+ // Nothing usable came back; leave the session context untouched so the
512
+ // next attempt can still resume cleanly.
513
+ return;
514
+ }
515
+ // The provider's numbers plus the wall-clock of the whole turn, so a
516
+ // reloaded transcript can still show what the context looked like.
517
+ const turnUsage = { ...usage, durationMs: Date.now() - started };
518
+ this.store.addMessage({
519
+ sessionId: session.id,
520
+ role: 'assistant',
521
+ content: answer,
522
+ provider: providerId,
523
+ model,
524
+ usage: turnUsage,
525
+ toolCalls,
526
+ });
527
+ if (failed && !answer)
528
+ return;
529
+ this.store.updateSession(session.id, { provider: providerId, model, providerSessionId });
530
+ yield { type: 'done', text: answer, providerSessionId, usage: turnUsage };
531
+ if (this.config.memory.enabled && this.config.memory.autoExtract) {
532
+ void this.#learn(session.id, prompt, answer, providerId, owner);
533
+ }
534
+ }
535
+ /* ------------------------------ assign ---------------------------- */
536
+ /**
537
+ * Give one agent a task directly, outside a conversation. Streams the
538
+ * assignment's events and ends with `done` carrying the report.
539
+ */
540
+ async *assign(input) {
541
+ const task = input.task.trim();
542
+ if (!task) {
543
+ yield { type: 'error', message: 'The task is empty.', fatal: true };
544
+ return;
545
+ }
546
+ const organization = this.org.activeOrganization();
547
+ const agent = this.store.org.findAgent(organization.id, input.agent);
548
+ if (!agent) {
549
+ yield { type: 'error', message: 'No agent "' + input.agent + '".', fatal: true };
550
+ return;
551
+ }
552
+ if (input.projectId && !this.store.org.getProject(input.projectId)) {
553
+ yield { type: 'error', message: 'No project ' + input.projectId + '.', fatal: true };
554
+ return;
555
+ }
556
+ const queue = new EventQueue();
557
+ const run = this.org
558
+ .run({
559
+ orgId: organization.id,
560
+ agent,
561
+ task,
562
+ projectId: input.projectId,
563
+ sessionId: input.sessionId,
564
+ requesterKind: 'user',
565
+ depth: 0,
566
+ emit: (event) => queue.push(event),
567
+ signal: input.signal,
568
+ })
569
+ .finally(() => queue.close());
570
+ for await (const event of queue.drain())
571
+ yield event;
572
+ const assignment = await run;
573
+ if (assignment.status === 'done') {
574
+ yield { type: 'done', text: assignment.result ?? '', usage: { durationMs: assignment.durationMs } };
575
+ }
576
+ else {
577
+ yield {
578
+ type: 'error',
579
+ message: 'Assignment ' + assignment.status + (assignment.error ? ': ' + assignment.error : '.'),
580
+ fatal: true,
581
+ };
582
+ }
583
+ }
584
+ /* ------------------------------- tasks ---------------------------- */
585
+ /** Plan one task from the board on the user's behalf. Throws when the task is unknown. */
586
+ async planTask(taskId, hint) {
587
+ const organization = this.org.activeOrganization();
588
+ const task = this.org.findTask(organization.id, taskId);
589
+ if (!task)
590
+ throw new Error('No task ' + taskId + '.');
591
+ return this.org.planTask({ orgId: organization.id, audience: 'assistant', depth: -1, emit: () => { } }, task, hint);
592
+ }
593
+ /**
594
+ * Run one task from the board on the user's behalf. Streams task and
595
+ * assignment events and ends with `done` carrying the combined result.
596
+ */
597
+ async *runTask(input) {
598
+ const organization = this.org.activeOrganization();
599
+ const task = this.org.findTask(organization.id, input.taskId);
600
+ if (!task) {
601
+ yield { type: 'error', message: 'No task ' + input.taskId + '.', fatal: true };
602
+ return;
603
+ }
604
+ const queue = new EventQueue();
605
+ const run = this.org
606
+ .runTask({
607
+ orgId: organization.id,
608
+ audience: 'assistant',
609
+ depth: -1,
610
+ projectId: task.projectId,
611
+ emit: (event) => queue.push(event),
612
+ signal: input.signal,
613
+ }, task)
614
+ .finally(() => queue.close());
615
+ for await (const event of queue.drain())
616
+ yield event;
617
+ const finished = await run;
618
+ if (finished.status === 'done') {
619
+ yield { type: 'done', text: finished.result ?? '' };
620
+ }
621
+ else {
622
+ yield {
623
+ type: 'error',
624
+ message: 'Task ' + finished.status + (finished.error ? ': ' + finished.error : '.'),
625
+ fatal: true,
626
+ };
627
+ }
628
+ }
629
+ /* ----------------------------- schedules -------------------------- */
630
+ /**
631
+ * Execute one schedule. The assistant's own jobs run as a turn in a
632
+ * conversation kept per job, so the user can open it and read along or
633
+ * carry on; an agent's jobs run as an ordinary assignment.
634
+ */
635
+ async #runScheduled(job, run, signal) {
636
+ void run;
637
+ if (job.kind === 'script') {
638
+ const result = await runCronScript(this.config.home, job, signal);
639
+ if (result.silent)
640
+ return { status: 'done', result: '', silent: true };
641
+ if (job.script?.noAgent)
642
+ return { status: 'done', result: result.output };
643
+ job = { ...job, prompt: job.prompt + '\n\nThe imported pre-check script produced this data:\n' + result.output };
644
+ }
645
+ if (job.kind === 'sleep') {
646
+ // The night shift. `prompt` carries the scope, not an instruction:
647
+ // "assistant", "all", or one agent id.
648
+ const scope = job.prompt.trim() || 'assistant';
649
+ const owners = scope === 'all' ? this.sleep.dueOwners() : scope === 'assistant' ? [ASSISTANT_MEMORY_OWNER] : [scope];
650
+ const lines = [];
651
+ let failed;
652
+ for (const owner of owners) {
653
+ const result = await this.sleep.run({ owner, trigger: 'schedule', signal });
654
+ lines.push(labelForOwner(this, owner) + ': ' + (result.report ?? '-'));
655
+ if (result.status === 'failed')
656
+ failed = result.error ?? 'The sleep run failed.';
657
+ }
658
+ if (failed && lines.length <= 1)
659
+ return { status: 'failed', error: failed };
660
+ return { status: 'done', result: lines.join('\n') };
661
+ }
662
+ if (job.kind === 'agent') {
663
+ const agent = job.agentId ? this.store.org.getAgent(job.agentId) : null;
664
+ if (!agent || agent.archived)
665
+ return { status: 'failed', error: 'The agent for this schedule no longer exists.' };
666
+ let assignmentId;
667
+ let text = '';
668
+ let error;
669
+ for await (const event of this.assign({ agent: agent.id, task: job.prompt, projectId: job.projectId, signal })) {
670
+ if (event.type === 'assignment' && !assignmentId)
671
+ assignmentId = event.assignment.id;
672
+ else if (event.type === 'done')
673
+ text = event.text;
674
+ else if (event.type === 'error' && event.fatal)
675
+ error = event.message;
676
+ }
677
+ return error ? { status: 'failed', error, assignmentId } : { status: 'done', result: text, assignmentId };
678
+ }
679
+ let sessionId = job.sessionId && this.store.getSession(job.sessionId) ? job.sessionId : undefined;
680
+ if (!sessionId) {
681
+ sessionId = this.createSession({ title: 'Schedule: ' + job.name, projectId: job.projectId }).id;
682
+ this.store.cron.updateJob(job.id, { sessionId }, false);
683
+ }
684
+ const when = new Date().toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' });
685
+ const prompt = 'Automatic run of schedule “' + job.name + '” (' + describeCron(job.schedule) + '), ' + when + '. ' +
686
+ 'Nobody is following live: carry out the assignment now and finish with a short report ' +
687
+ 'for the user to read later.\n\n' + job.prompt;
688
+ let text = '';
689
+ let error;
690
+ for await (const event of this.chat({ text: prompt, sessionId, projectId: job.projectId, permission: job.permission, signal })) {
691
+ if (event.type === 'done')
692
+ text = event.text;
693
+ else if (event.type === 'error' && event.fatal)
694
+ error = event.message;
695
+ }
696
+ if (error && !text)
697
+ return { status: 'failed', error, sessionId };
698
+ if (job.kind === 'script' && text.trim() === '[SILENT]')
699
+ return { status: 'done', result: '', silent: true, sessionId };
700
+ return { status: 'done', result: text, sessionId };
701
+ }
702
+ /* ---------------------------- internals --------------------------- */
703
+ #resolveSession(input) {
704
+ if (input.sessionId) {
705
+ const existing = this.store.getSession(input.sessionId);
706
+ if (existing)
707
+ return existing;
708
+ this.log.warn('Unknown session, starting a new one', { sessionId: input.sessionId });
709
+ }
710
+ return this.createSession({
711
+ // A spoken first turn opens a voice session, so the hands-free screen
712
+ // never has to create one by hand.
713
+ kind: input.voice ? 'voice' : 'chat',
714
+ provider: input.provider,
715
+ model: input.model,
716
+ projectId: input.projectId,
717
+ agentId: input.agentId,
718
+ });
719
+ }
720
+ /** Extract and store durable memories from a finished exchange. */
721
+ async #learn(sessionId, userText, assistantText, providerId, owner) {
722
+ try {
723
+ // What the model must not repeat is what is RELEVANT here, not what
724
+ // happens to rank highest overall. Listing the forty most important
725
+ // memories was the single biggest reason the bank kept growing: the
726
+ // sentence about to be written again was almost never in that list.
727
+ const known = relevantKnown(this.store, owner, userText + '\n' + assistantText);
728
+ const candidates = await extractMemories(this.providers.get(providerId), {
729
+ userText,
730
+ assistantText,
731
+ known,
732
+ sessionId,
733
+ model: smallModelFor(providerId),
734
+ });
735
+ const admitted = admitCandidates(this.store, {
736
+ candidates,
737
+ owner,
738
+ config: this.config.memory,
739
+ sourceSessionId: sessionId,
740
+ });
741
+ if (admitted.rejected.length) {
742
+ this.log.debug('Memory gate rejected candidates', {
743
+ count: admitted.rejected.length,
744
+ reasons: admitted.rejected.map((entry) => entry.reason).join(','),
745
+ });
746
+ }
747
+ const event = { sessionId, stored: admitted.stored };
748
+ this.emit('memory', event);
749
+ }
750
+ catch (error) {
751
+ this.log.warn('Memory extraction failed', { error: error.message });
752
+ }
753
+ }
754
+ }
755
+ /** "The assistant" or the agent's name, for the schedule's report line. */
756
+ function labelForOwner(assistant, owner) {
757
+ if (owner === ASSISTANT_MEMORY_OWNER)
758
+ return 'Assistant';
759
+ return assistant.store.org.getAgent(owner)?.name ?? owner.slice(0, 8);
760
+ }
761
+ /**
762
+ * The memories the extractor needs to see so it does not write them again:
763
+ * whatever this exchange actually touches, plus the small core profile.
764
+ */
765
+ function relevantKnown(store, owner, text) {
766
+ const matched = recall(store, { text, owner, limit: 20, threshold: 0.05, touch: false, expand: false });
767
+ const profile = coreProfile(store, { owner, limit: 5 });
768
+ const seen = new Set();
769
+ const out = [];
770
+ for (const memory of [...matched, ...profile]) {
771
+ if (seen.has(memory.id))
772
+ continue;
773
+ seen.add(memory.id);
774
+ out.push(memory.content);
775
+ }
776
+ return out;
777
+ }
778
+ //# sourceMappingURL=runtime.js.map