rookery-agent 0.3.1 → 0.4.1

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 (743) hide show
  1. package/README.md +9 -3
  2. package/docs/updates.md +12 -0
  3. package/package.json +1 -2
  4. package/packages/cli/dist/commands/chat.d.ts.map +1 -1
  5. package/packages/cli/dist/commands/chat.js +37 -74
  6. package/packages/cli/dist/commands/chat.js.map +1 -1
  7. package/packages/cli/dist/commands/config.js +4 -4
  8. package/packages/cli/dist/commands/config.js.map +1 -1
  9. package/packages/cli/dist/commands/doctor.d.ts.map +1 -1
  10. package/packages/cli/dist/commands/doctor.js +113 -91
  11. package/packages/cli/dist/commands/doctor.js.map +1 -1
  12. package/packages/cli/dist/commands/memory.d.ts.map +1 -1
  13. package/packages/cli/dist/commands/memory.js +28 -31
  14. package/packages/cli/dist/commands/memory.js.map +1 -1
  15. package/packages/cli/dist/commands/org.d.ts.map +1 -1
  16. package/packages/cli/dist/commands/org.js +36 -103
  17. package/packages/cli/dist/commands/org.js.map +1 -1
  18. package/packages/cli/dist/commands/serve.d.ts.map +1 -1
  19. package/packages/cli/dist/commands/serve.js +8 -6
  20. package/packages/cli/dist/commands/serve.js.map +1 -1
  21. package/packages/cli/dist/commands/sessions.d.ts.map +1 -1
  22. package/packages/cli/dist/commands/sessions.js +18 -17
  23. package/packages/cli/dist/commands/sessions.js.map +1 -1
  24. package/packages/cli/dist/commands/shared.d.ts +26 -5
  25. package/packages/cli/dist/commands/shared.d.ts.map +1 -1
  26. package/packages/cli/dist/commands/shared.js +85 -63
  27. package/packages/cli/dist/commands/shared.js.map +1 -1
  28. package/packages/cli/dist/commands/slash.d.ts +51 -0
  29. package/packages/cli/dist/commands/slash.d.ts.map +1 -0
  30. package/packages/cli/dist/commands/slash.js +110 -0
  31. package/packages/cli/dist/commands/slash.js.map +1 -0
  32. package/packages/cli/dist/commands/tasks.d.ts.map +1 -1
  33. package/packages/cli/dist/commands/tasks.js +74 -115
  34. package/packages/cli/dist/commands/tasks.js.map +1 -1
  35. package/packages/cli/dist/commands/tools.d.ts.map +1 -1
  36. package/packages/cli/dist/commands/tools.js +51 -34
  37. package/packages/cli/dist/commands/tools.js.map +1 -1
  38. package/packages/cli/dist/index.js +42 -52
  39. package/packages/cli/dist/index.js.map +1 -1
  40. package/packages/cli/dist/repl.d.ts +1 -25
  41. package/packages/cli/dist/repl.d.ts.map +1 -1
  42. package/packages/cli/dist/repl.js +165 -726
  43. package/packages/cli/dist/repl.js.map +1 -1
  44. package/packages/cli/dist/replInput.d.ts +33 -0
  45. package/packages/cli/dist/replInput.d.ts.map +1 -0
  46. package/packages/cli/dist/replInput.js +97 -0
  47. package/packages/cli/dist/replInput.js.map +1 -0
  48. package/packages/cli/dist/replOutput.d.ts +11 -0
  49. package/packages/cli/dist/replOutput.d.ts.map +1 -0
  50. package/packages/cli/dist/replOutput.js +22 -0
  51. package/packages/cli/dist/replOutput.js.map +1 -0
  52. package/packages/cli/dist/replQuestions.d.ts +32 -0
  53. package/packages/cli/dist/replQuestions.d.ts.map +1 -0
  54. package/packages/cli/dist/replQuestions.js +122 -0
  55. package/packages/cli/dist/replQuestions.js.map +1 -0
  56. package/packages/cli/dist/replSlash.d.ts +24 -0
  57. package/packages/cli/dist/replSlash.d.ts.map +1 -0
  58. package/packages/cli/dist/replSlash.js +311 -0
  59. package/packages/cli/dist/replSlash.js.map +1 -0
  60. package/packages/cli/dist/replState.d.ts +56 -0
  61. package/packages/cli/dist/replState.d.ts.map +1 -0
  62. package/packages/cli/dist/replState.js +89 -0
  63. package/packages/cli/dist/replState.js.map +1 -0
  64. package/packages/cli/dist/tui/App.d.ts +7 -24
  65. package/packages/cli/dist/tui/App.d.ts.map +1 -1
  66. package/packages/cli/dist/tui/App.js +139 -513
  67. package/packages/cli/dist/tui/App.js.map +1 -1
  68. package/packages/cli/dist/tui/LiveRegion.d.ts +16 -0
  69. package/packages/cli/dist/tui/LiveRegion.d.ts.map +1 -0
  70. package/packages/cli/dist/tui/LiveRegion.js +37 -0
  71. package/packages/cli/dist/tui/LiveRegion.js.map +1 -0
  72. package/packages/cli/dist/tui/boot.d.ts +34 -0
  73. package/packages/cli/dist/tui/boot.d.ts.map +1 -0
  74. package/packages/cli/dist/tui/boot.js +133 -0
  75. package/packages/cli/dist/tui/boot.js.map +1 -0
  76. package/packages/cli/dist/tui/commands.d.ts +3 -4
  77. package/packages/cli/dist/tui/commands.d.ts.map +1 -1
  78. package/packages/cli/dist/tui/commands.js +339 -405
  79. package/packages/cli/dist/tui/commands.js.map +1 -1
  80. package/packages/cli/dist/tui/components/ActivityLine.d.ts +1 -1
  81. package/packages/cli/dist/tui/components/ActivityLine.d.ts.map +1 -1
  82. package/packages/cli/dist/tui/components/ActivityLine.js +2 -2
  83. package/packages/cli/dist/tui/components/ActivityLine.js.map +1 -1
  84. package/packages/cli/dist/tui/components/AssignmentsView.d.ts.map +1 -1
  85. package/packages/cli/dist/tui/components/AssignmentsView.js +34 -20
  86. package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -1
  87. package/packages/cli/dist/tui/components/Logo.d.ts +3 -19
  88. package/packages/cli/dist/tui/components/Logo.d.ts.map +1 -1
  89. package/packages/cli/dist/tui/components/Logo.js +13 -13
  90. package/packages/cli/dist/tui/components/Logo.js.map +1 -1
  91. package/packages/cli/dist/tui/components/Markdown.d.ts.map +1 -1
  92. package/packages/cli/dist/tui/components/Markdown.js +201 -146
  93. package/packages/cli/dist/tui/components/Markdown.js.map +1 -1
  94. package/packages/cli/dist/tui/components/QuestionView.d.ts +0 -2
  95. package/packages/cli/dist/tui/components/QuestionView.d.ts.map +1 -1
  96. package/packages/cli/dist/tui/components/QuestionView.js +21 -12
  97. package/packages/cli/dist/tui/components/QuestionView.js.map +1 -1
  98. package/packages/cli/dist/tui/components/Scrollback.d.ts.map +1 -1
  99. package/packages/cli/dist/tui/components/Scrollback.js +6 -3
  100. package/packages/cli/dist/tui/components/Scrollback.js.map +1 -1
  101. package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -1
  102. package/packages/cli/dist/tui/components/SlashPalette.js +14 -9
  103. package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -1
  104. package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -1
  105. package/packages/cli/dist/tui/components/StatusLine.js +45 -22
  106. package/packages/cli/dist/tui/components/StatusLine.js.map +1 -1
  107. package/packages/cli/dist/tui/components/ToolGroup.d.ts.map +1 -1
  108. package/packages/cli/dist/tui/components/ToolGroup.js +12 -7
  109. package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -1
  110. package/packages/cli/dist/tui/components/WatchView.d.ts.map +1 -1
  111. package/packages/cli/dist/tui/components/WatchView.js +28 -17
  112. package/packages/cli/dist/tui/components/WatchView.js.map +1 -1
  113. package/packages/cli/dist/tui/highlight.d.ts +0 -2
  114. package/packages/cli/dist/tui/highlight.d.ts.map +1 -1
  115. package/packages/cli/dist/tui/highlight.js +8 -6
  116. package/packages/cli/dist/tui/highlight.js.map +1 -1
  117. package/packages/cli/dist/tui/history.d.ts +30 -4
  118. package/packages/cli/dist/tui/history.d.ts.map +1 -1
  119. package/packages/cli/dist/tui/history.js +100 -75
  120. package/packages/cli/dist/tui/history.js.map +1 -1
  121. package/packages/cli/dist/tui/hooks/coalescer.d.ts +18 -0
  122. package/packages/cli/dist/tui/hooks/coalescer.d.ts.map +1 -0
  123. package/packages/cli/dist/tui/hooks/coalescer.js +36 -0
  124. package/packages/cli/dist/tui/hooks/coalescer.js.map +1 -0
  125. package/packages/cli/dist/tui/hooks/useColumns.d.ts +2 -7
  126. package/packages/cli/dist/tui/hooks/useColumns.d.ts.map +1 -1
  127. package/packages/cli/dist/tui/hooks/useColumns.js +6 -11
  128. package/packages/cli/dist/tui/hooks/useColumns.js.map +1 -1
  129. package/packages/cli/dist/tui/hooks/useHistory.d.ts +7 -4
  130. package/packages/cli/dist/tui/hooks/useHistory.d.ts.map +1 -1
  131. package/packages/cli/dist/tui/hooks/useHistory.js +21 -18
  132. package/packages/cli/dist/tui/hooks/useHistory.js.map +1 -1
  133. package/packages/cli/dist/tui/hooks/usePrompt.d.ts +27 -0
  134. package/packages/cli/dist/tui/hooks/usePrompt.d.ts.map +1 -0
  135. package/packages/cli/dist/tui/hooks/usePrompt.js +169 -0
  136. package/packages/cli/dist/tui/hooks/usePrompt.js.map +1 -0
  137. package/packages/cli/dist/tui/hooks/useQuestion.d.ts +23 -0
  138. package/packages/cli/dist/tui/hooks/useQuestion.d.ts.map +1 -0
  139. package/packages/cli/dist/tui/hooks/useQuestion.js +43 -0
  140. package/packages/cli/dist/tui/hooks/useQuestion.js.map +1 -0
  141. package/packages/cli/dist/tui/hooks/useScrollback.d.ts +18 -0
  142. package/packages/cli/dist/tui/hooks/useScrollback.d.ts.map +1 -0
  143. package/packages/cli/dist/tui/hooks/useScrollback.js +29 -0
  144. package/packages/cli/dist/tui/hooks/useScrollback.js.map +1 -0
  145. package/packages/cli/dist/tui/hooks/useSession.d.ts +25 -0
  146. package/packages/cli/dist/tui/hooks/useSession.d.ts.map +1 -0
  147. package/packages/cli/dist/tui/hooks/useSession.js +36 -0
  148. package/packages/cli/dist/tui/hooks/useSession.js.map +1 -0
  149. package/packages/cli/dist/tui/hooks/useSlash.d.ts +0 -2
  150. package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -1
  151. package/packages/cli/dist/tui/hooks/useSlash.js +0 -1
  152. package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -1
  153. package/packages/cli/dist/tui/hooks/useSpeech.d.ts +19 -0
  154. package/packages/cli/dist/tui/hooks/useSpeech.d.ts.map +1 -0
  155. package/packages/cli/dist/tui/hooks/useSpeech.js +33 -0
  156. package/packages/cli/dist/tui/hooks/useSpeech.js.map +1 -0
  157. package/packages/cli/dist/tui/hooks/useTicker.d.ts +13 -0
  158. package/packages/cli/dist/tui/hooks/useTicker.d.ts.map +1 -0
  159. package/packages/cli/dist/tui/hooks/useTicker.js +24 -0
  160. package/packages/cli/dist/tui/hooks/useTicker.js.map +1 -0
  161. package/packages/cli/dist/tui/hooks/useTurn.d.ts +4 -4
  162. package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -1
  163. package/packages/cli/dist/tui/hooks/useTurn.js +167 -289
  164. package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -1
  165. package/packages/cli/dist/tui/hooks/useWatch.d.ts.map +1 -1
  166. package/packages/cli/dist/tui/hooks/useWatch.js +15 -48
  167. package/packages/cli/dist/tui/hooks/useWatch.js.map +1 -1
  168. package/packages/cli/dist/tui/inkTheme.d.ts.map +1 -1
  169. package/packages/cli/dist/tui/inkTheme.js +9 -11
  170. package/packages/cli/dist/tui/inkTheme.js.map +1 -1
  171. package/packages/cli/dist/tui/theme.d.ts +7 -13
  172. package/packages/cli/dist/tui/theme.d.ts.map +1 -1
  173. package/packages/cli/dist/tui/theme.js +18 -15
  174. package/packages/cli/dist/tui/theme.js.map +1 -1
  175. package/packages/cli/dist/tui/types.d.ts +10 -23
  176. package/packages/cli/dist/tui/types.d.ts.map +1 -1
  177. package/packages/cli/dist/tui/types.js +13 -31
  178. package/packages/cli/dist/tui/types.js.map +1 -1
  179. package/packages/cli/dist/ui/modelNames.d.ts.map +1 -1
  180. package/packages/cli/dist/ui/modelNames.js +45 -37
  181. package/packages/cli/dist/ui/modelNames.js.map +1 -1
  182. package/packages/cli/dist/ui/render.d.ts +32 -14
  183. package/packages/cli/dist/ui/render.d.ts.map +1 -1
  184. package/packages/cli/dist/ui/render.js +155 -98
  185. package/packages/cli/dist/ui/render.js.map +1 -1
  186. package/packages/cli/dist/ui/speech.d.ts +4 -7
  187. package/packages/cli/dist/ui/speech.d.ts.map +1 -1
  188. package/packages/cli/dist/ui/speech.js +37 -51
  189. package/packages/cli/dist/ui/speech.js.map +1 -1
  190. package/packages/cli/dist/ui/spinner.d.ts +1 -4
  191. package/packages/cli/dist/ui/spinner.d.ts.map +1 -1
  192. package/packages/cli/dist/ui/spinner.js +1 -12
  193. package/packages/cli/dist/ui/spinner.js.map +1 -1
  194. package/packages/cli/package.json +1 -1
  195. package/packages/core/dist/agents/persona.d.ts.map +1 -1
  196. package/packages/core/dist/agents/persona.js +27 -11
  197. package/packages/core/dist/agents/persona.js.map +1 -1
  198. package/packages/core/dist/assistant/board-watch.d.ts +72 -0
  199. package/packages/core/dist/assistant/board-watch.d.ts.map +1 -0
  200. package/packages/core/dist/assistant/board-watch.js +224 -0
  201. package/packages/core/dist/assistant/board-watch.js.map +1 -0
  202. package/packages/core/dist/assistant/chat-turn.d.ts +14 -0
  203. package/packages/core/dist/assistant/chat-turn.d.ts.map +1 -0
  204. package/packages/core/dist/assistant/chat-turn.js +159 -0
  205. package/packages/core/dist/assistant/chat-turn.js.map +1 -0
  206. package/packages/core/dist/assistant/dream-recorder.d.ts +74 -0
  207. package/packages/core/dist/assistant/dream-recorder.d.ts.map +1 -0
  208. package/packages/core/dist/assistant/dream-recorder.js +282 -0
  209. package/packages/core/dist/assistant/dream-recorder.js.map +1 -0
  210. package/packages/core/dist/assistant/headless-turn.d.ts +17 -0
  211. package/packages/core/dist/assistant/headless-turn.d.ts.map +1 -0
  212. package/packages/core/dist/assistant/headless-turn.js +330 -0
  213. package/packages/core/dist/assistant/headless-turn.js.map +1 -0
  214. package/packages/core/dist/assistant/journalled-turn.d.ts +39 -0
  215. package/packages/core/dist/assistant/journalled-turn.d.ts.map +1 -0
  216. package/packages/core/dist/assistant/journalled-turn.js +75 -0
  217. package/packages/core/dist/assistant/journalled-turn.js.map +1 -0
  218. package/packages/core/dist/assistant/memory-learning.d.ts +27 -0
  219. package/packages/core/dist/assistant/memory-learning.d.ts.map +1 -0
  220. package/packages/core/dist/assistant/memory-learning.js +82 -0
  221. package/packages/core/dist/assistant/memory-learning.js.map +1 -0
  222. package/packages/core/dist/assistant/promotion-notice.d.ts +14 -0
  223. package/packages/core/dist/assistant/promotion-notice.d.ts.map +1 -0
  224. package/packages/core/dist/assistant/promotion-notice.js +33 -0
  225. package/packages/core/dist/assistant/promotion-notice.js.map +1 -0
  226. package/packages/core/dist/assistant/scheduled-runs.d.ts +30 -0
  227. package/packages/core/dist/assistant/scheduled-runs.d.ts.map +1 -0
  228. package/packages/core/dist/assistant/scheduled-runs.js +184 -0
  229. package/packages/core/dist/assistant/scheduled-runs.js.map +1 -0
  230. package/packages/core/dist/assistant/sessions.d.ts +44 -0
  231. package/packages/core/dist/assistant/sessions.d.ts.map +1 -0
  232. package/packages/core/dist/assistant/sessions.js +75 -0
  233. package/packages/core/dist/assistant/sessions.js.map +1 -0
  234. package/packages/core/dist/assistant/terminal-turn.d.ts +18 -0
  235. package/packages/core/dist/assistant/terminal-turn.d.ts.map +1 -0
  236. package/packages/core/dist/assistant/terminal-turn.js +228 -0
  237. package/packages/core/dist/assistant/terminal-turn.js.map +1 -0
  238. package/packages/core/dist/assistant/terminals.d.ts +91 -0
  239. package/packages/core/dist/assistant/terminals.d.ts.map +1 -0
  240. package/packages/core/dist/assistant/terminals.js +266 -0
  241. package/packages/core/dist/assistant/terminals.js.map +1 -0
  242. package/packages/core/dist/assistant/turn-support.d.ts +109 -0
  243. package/packages/core/dist/assistant/turn-support.d.ts.map +1 -0
  244. package/packages/core/dist/assistant/turn-support.js +80 -0
  245. package/packages/core/dist/assistant/turn-support.js.map +1 -0
  246. package/packages/core/dist/assistant/turn-transcript.d.ts +44 -0
  247. package/packages/core/dist/assistant/turn-transcript.d.ts.map +1 -0
  248. package/packages/core/dist/assistant/turn-transcript.js +82 -0
  249. package/packages/core/dist/assistant/turn-transcript.js.map +1 -0
  250. package/packages/core/dist/assistant/types.d.ts +120 -0
  251. package/packages/core/dist/assistant/types.d.ts.map +1 -0
  252. package/packages/core/dist/assistant/types.js +2 -0
  253. package/packages/core/dist/assistant/types.js.map +1 -0
  254. package/packages/core/dist/computer/accessibility.d.ts.map +1 -1
  255. package/packages/core/dist/computer/accessibility.js +40 -35
  256. package/packages/core/dist/computer/accessibility.js.map +1 -1
  257. package/packages/core/dist/computer/mcp-server.js +426 -364
  258. package/packages/core/dist/computer/mcp-server.js.map +1 -1
  259. package/packages/core/dist/computer/powershell.d.ts.map +1 -1
  260. package/packages/core/dist/computer/powershell.js +25 -16
  261. package/packages/core/dist/computer/powershell.js.map +1 -1
  262. package/packages/core/dist/computer/screen-text.d.ts.map +1 -1
  263. package/packages/core/dist/computer/screen-text.js +54 -34
  264. package/packages/core/dist/computer/screen-text.js.map +1 -1
  265. package/packages/core/dist/computer/sketch.d.ts.map +1 -1
  266. package/packages/core/dist/computer/sketch.js +185 -128
  267. package/packages/core/dist/computer/sketch.js.map +1 -1
  268. package/packages/core/dist/computer/tools.d.ts +2 -0
  269. package/packages/core/dist/computer/tools.d.ts.map +1 -1
  270. package/packages/core/dist/computer/tools.js +31 -27
  271. package/packages/core/dist/computer/tools.js.map +1 -1
  272. package/packages/core/dist/computer/validation.d.ts +16 -16
  273. package/packages/core/dist/computer/validation.d.ts.map +1 -1
  274. package/packages/core/dist/computer/validation.js +28 -20
  275. package/packages/core/dist/computer/validation.js.map +1 -1
  276. package/packages/core/dist/config.d.ts +10 -1
  277. package/packages/core/dist/config.d.ts.map +1 -1
  278. package/packages/core/dist/config.js +81 -26
  279. package/packages/core/dist/config.js.map +1 -1
  280. package/packages/core/dist/cron/parse.d.ts.map +1 -1
  281. package/packages/core/dist/cron/parse.js +90 -77
  282. package/packages/core/dist/cron/parse.js.map +1 -1
  283. package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
  284. package/packages/core/dist/cron/scheduler.js +99 -65
  285. package/packages/core/dist/cron/scheduler.js.map +1 -1
  286. package/packages/core/dist/cron/script.d.ts.map +1 -1
  287. package/packages/core/dist/cron/script.js +72 -42
  288. package/packages/core/dist/cron/script.js.map +1 -1
  289. package/packages/core/dist/external/claude-code.d.ts.map +1 -1
  290. package/packages/core/dist/external/claude-code.js +41 -28
  291. package/packages/core/dist/external/claude-code.js.map +1 -1
  292. package/packages/core/dist/external/discovery.d.ts.map +1 -1
  293. package/packages/core/dist/external/discovery.js +14 -11
  294. package/packages/core/dist/external/discovery.js.map +1 -1
  295. package/packages/core/dist/external/shared.d.ts +20 -0
  296. package/packages/core/dist/external/shared.d.ts.map +1 -1
  297. package/packages/core/dist/external/shared.js +97 -81
  298. package/packages/core/dist/external/shared.js.map +1 -1
  299. package/packages/core/dist/gateway/policy.d.ts.map +1 -1
  300. package/packages/core/dist/gateway/policy.js +5 -2
  301. package/packages/core/dist/gateway/policy.js.map +1 -1
  302. package/packages/core/dist/logger.d.ts.map +1 -1
  303. package/packages/core/dist/logger.js +11 -11
  304. package/packages/core/dist/logger.js.map +1 -1
  305. package/packages/core/dist/memory/db.d.ts.map +1 -1
  306. package/packages/core/dist/memory/db.js +175 -226
  307. package/packages/core/dist/memory/db.js.map +1 -1
  308. package/packages/core/dist/memory/dream/admission.d.ts +5 -0
  309. package/packages/core/dist/memory/dream/admission.d.ts.map +1 -1
  310. package/packages/core/dist/memory/dream/admission.js +8 -14
  311. package/packages/core/dist/memory/dream/admission.js.map +1 -1
  312. package/packages/core/dist/memory/dream/candidate.d.ts.map +1 -1
  313. package/packages/core/dist/memory/dream/candidate.js +119 -92
  314. package/packages/core/dist/memory/dream/candidate.js.map +1 -1
  315. package/packages/core/dist/memory/dream/evaluate.d.ts +13 -4
  316. package/packages/core/dist/memory/dream/evaluate.d.ts.map +1 -1
  317. package/packages/core/dist/memory/dream/evaluate.js +264 -288
  318. package/packages/core/dist/memory/dream/evaluate.js.map +1 -1
  319. package/packages/core/dist/memory/dream/frame.d.ts +6 -0
  320. package/packages/core/dist/memory/dream/frame.d.ts.map +1 -1
  321. package/packages/core/dist/memory/dream/frame.js +137 -91
  322. package/packages/core/dist/memory/dream/frame.js.map +1 -1
  323. package/packages/core/dist/memory/dream/label.d.ts.map +1 -1
  324. package/packages/core/dist/memory/dream/label.js +6 -9
  325. package/packages/core/dist/memory/dream/label.js.map +1 -1
  326. package/packages/core/dist/memory/dream/measure.d.ts +4 -0
  327. package/packages/core/dist/memory/dream/measure.d.ts.map +1 -1
  328. package/packages/core/dist/memory/dream/measure.js +13 -58
  329. package/packages/core/dist/memory/dream/measure.js.map +1 -1
  330. package/packages/core/dist/memory/dream/policy.d.ts.map +1 -1
  331. package/packages/core/dist/memory/dream/policy.js +4 -2
  332. package/packages/core/dist/memory/dream/policy.js.map +1 -1
  333. package/packages/core/dist/memory/dream/probe.d.ts +31 -4
  334. package/packages/core/dist/memory/dream/probe.d.ts.map +1 -1
  335. package/packages/core/dist/memory/dream/probe.js +290 -289
  336. package/packages/core/dist/memory/dream/probe.js.map +1 -1
  337. package/packages/core/dist/memory/dream/promote.d.ts.map +1 -1
  338. package/packages/core/dist/memory/dream/promote.js +10 -11
  339. package/packages/core/dist/memory/dream/promote.js.map +1 -1
  340. package/packages/core/dist/memory/dream/score.d.ts +9 -0
  341. package/packages/core/dist/memory/dream/score.d.ts.map +1 -1
  342. package/packages/core/dist/memory/dream/score.js +6 -7
  343. package/packages/core/dist/memory/dream/score.js.map +1 -1
  344. package/packages/core/dist/memory/dream/slots.d.ts.map +1 -1
  345. package/packages/core/dist/memory/dream/slots.js +0 -0
  346. package/packages/core/dist/memory/dream/slots.js.map +1 -1
  347. package/packages/core/dist/memory/dream/trajectory.d.ts.map +1 -1
  348. package/packages/core/dist/memory/dream/trajectory.js +76 -53
  349. package/packages/core/dist/memory/dream/trajectory.js.map +1 -1
  350. package/packages/core/dist/memory/dream/util.d.ts +44 -0
  351. package/packages/core/dist/memory/dream/util.d.ts.map +1 -0
  352. package/packages/core/dist/memory/dream/util.js +83 -0
  353. package/packages/core/dist/memory/dream/util.js.map +1 -0
  354. package/packages/core/dist/memory/extractor.d.ts.map +1 -1
  355. package/packages/core/dist/memory/extractor.js +67 -46
  356. package/packages/core/dist/memory/extractor.js.map +1 -1
  357. package/packages/core/dist/memory/gate.d.ts.map +1 -1
  358. package/packages/core/dist/memory/gate.js +55 -44
  359. package/packages/core/dist/memory/gate.js.map +1 -1
  360. package/packages/core/dist/memory/recall.d.ts +1 -1
  361. package/packages/core/dist/memory/recall.d.ts.map +1 -1
  362. package/packages/core/dist/memory/recall.js +55 -43
  363. package/packages/core/dist/memory/recall.js.map +1 -1
  364. package/packages/core/dist/memory/sleep-dream.d.ts +210 -0
  365. package/packages/core/dist/memory/sleep-dream.d.ts.map +1 -0
  366. package/packages/core/dist/memory/sleep-dream.js +1109 -0
  367. package/packages/core/dist/memory/sleep-dream.js.map +1 -0
  368. package/packages/core/dist/memory/sleep-frames.d.ts +40 -0
  369. package/packages/core/dist/memory/sleep-frames.d.ts.map +1 -0
  370. package/packages/core/dist/memory/sleep-frames.js +127 -0
  371. package/packages/core/dist/memory/sleep-frames.js.map +1 -0
  372. package/packages/core/dist/memory/sleep-limits.d.ts +18 -0
  373. package/packages/core/dist/memory/sleep-limits.d.ts.map +1 -0
  374. package/packages/core/dist/memory/sleep-limits.js +34 -0
  375. package/packages/core/dist/memory/sleep-limits.js.map +1 -0
  376. package/packages/core/dist/memory/sleep-model.d.ts +36 -0
  377. package/packages/core/dist/memory/sleep-model.d.ts.map +1 -0
  378. package/packages/core/dist/memory/sleep-model.js +80 -0
  379. package/packages/core/dist/memory/sleep-model.js.map +1 -0
  380. package/packages/core/dist/memory/sleep-policy.d.ts +19 -0
  381. package/packages/core/dist/memory/sleep-policy.d.ts.map +1 -0
  382. package/packages/core/dist/memory/sleep-policy.js +79 -0
  383. package/packages/core/dist/memory/sleep-policy.js.map +1 -0
  384. package/packages/core/dist/memory/sleep-prompts.d.ts +15 -0
  385. package/packages/core/dist/memory/sleep-prompts.d.ts.map +1 -0
  386. package/packages/core/dist/memory/sleep-prompts.js +212 -0
  387. package/packages/core/dist/memory/sleep-prompts.js.map +1 -0
  388. package/packages/core/dist/memory/sleep-report.d.ts +63 -0
  389. package/packages/core/dist/memory/sleep-report.d.ts.map +1 -0
  390. package/packages/core/dist/memory/sleep-report.js +97 -0
  391. package/packages/core/dist/memory/sleep-report.js.map +1 -0
  392. package/packages/core/dist/memory/sleep-verdicts.d.ts +77 -0
  393. package/packages/core/dist/memory/sleep-verdicts.d.ts.map +1 -0
  394. package/packages/core/dist/memory/sleep-verdicts.js +198 -0
  395. package/packages/core/dist/memory/sleep-verdicts.js.map +1 -0
  396. package/packages/core/dist/memory/sleep.d.ts +6 -61
  397. package/packages/core/dist/memory/sleep.d.ts.map +1 -1
  398. package/packages/core/dist/memory/sleep.js +1099 -2458
  399. package/packages/core/dist/memory/sleep.js.map +1 -1
  400. package/packages/core/dist/memory/store-rows.d.ts +43 -0
  401. package/packages/core/dist/memory/store-rows.d.ts.map +1 -0
  402. package/packages/core/dist/memory/store-rows.js +330 -0
  403. package/packages/core/dist/memory/store-rows.js.map +1 -0
  404. package/packages/core/dist/memory/store.d.ts +34 -20
  405. package/packages/core/dist/memory/store.d.ts.map +1 -1
  406. package/packages/core/dist/memory/store.js +634 -861
  407. package/packages/core/dist/memory/store.js.map +1 -1
  408. package/packages/core/dist/migration-cron.d.ts +2 -1
  409. package/packages/core/dist/migration-cron.d.ts.map +1 -1
  410. package/packages/core/dist/migration-cron.js +197 -154
  411. package/packages/core/dist/migration-cron.js.map +1 -1
  412. package/packages/core/dist/migration-scripts.d.ts +11 -3
  413. package/packages/core/dist/migration-scripts.d.ts.map +1 -1
  414. package/packages/core/dist/migration-scripts.js +81 -61
  415. package/packages/core/dist/migration-scripts.js.map +1 -1
  416. package/packages/core/dist/migration-shared.d.ts +9 -0
  417. package/packages/core/dist/migration-shared.d.ts.map +1 -0
  418. package/packages/core/dist/migration-shared.js +16 -0
  419. package/packages/core/dist/migration-shared.js.map +1 -0
  420. package/packages/core/dist/migration.d.ts.map +1 -1
  421. package/packages/core/dist/migration.js +150 -111
  422. package/packages/core/dist/migration.js.map +1 -1
  423. package/packages/core/dist/org/assignment-log.d.ts +28 -0
  424. package/packages/core/dist/org/assignment-log.d.ts.map +1 -0
  425. package/packages/core/dist/org/assignment-log.js +86 -0
  426. package/packages/core/dist/org/assignment-log.js.map +1 -0
  427. package/packages/core/dist/org/bridge.d.ts.map +1 -1
  428. package/packages/core/dist/org/bridge.js +32 -30
  429. package/packages/core/dist/org/bridge.js.map +1 -1
  430. package/packages/core/dist/org/controller.d.ts +18 -21
  431. package/packages/core/dist/org/controller.d.ts.map +1 -1
  432. package/packages/core/dist/org/controller.js +2042 -1848
  433. package/packages/core/dist/org/controller.js.map +1 -1
  434. package/packages/core/dist/org/json-reply.d.ts +6 -0
  435. package/packages/core/dist/org/json-reply.d.ts.map +1 -0
  436. package/packages/core/dist/org/json-reply.js +23 -0
  437. package/packages/core/dist/org/json-reply.js.map +1 -0
  438. package/packages/core/dist/org/mcp-bridge.js +34 -26
  439. package/packages/core/dist/org/mcp-bridge.js.map +1 -1
  440. package/packages/core/dist/org/planner.d.ts.map +1 -1
  441. package/packages/core/dist/org/planner.js +38 -42
  442. package/packages/core/dist/org/planner.js.map +1 -1
  443. package/packages/core/dist/org/project-mcp.d.ts.map +1 -1
  444. package/packages/core/dist/org/project-mcp.js +2 -5
  445. package/packages/core/dist/org/project-mcp.js.map +1 -1
  446. package/packages/core/dist/org/prompts.d.ts.map +1 -1
  447. package/packages/core/dist/org/prompts.js +176 -156
  448. package/packages/core/dist/org/prompts.js.map +1 -1
  449. package/packages/core/dist/org/questions.d.ts.map +1 -1
  450. package/packages/core/dist/org/questions.js +19 -14
  451. package/packages/core/dist/org/questions.js.map +1 -1
  452. package/packages/core/dist/org/review.d.ts.map +1 -1
  453. package/packages/core/dist/org/review.js +27 -43
  454. package/packages/core/dist/org/review.js.map +1 -1
  455. package/packages/core/dist/org/store.d.ts +19 -32
  456. package/packages/core/dist/org/store.d.ts.map +1 -1
  457. package/packages/core/dist/org/store.js +250 -206
  458. package/packages/core/dist/org/store.js.map +1 -1
  459. package/packages/core/dist/org/tool-args.d.ts +54 -0
  460. package/packages/core/dist/org/tool-args.d.ts.map +1 -0
  461. package/packages/core/dist/org/tool-args.js +104 -0
  462. package/packages/core/dist/org/tool-args.js.map +1 -0
  463. package/packages/core/dist/org/tools.d.ts.map +1 -1
  464. package/packages/core/dist/org/tools.js +238 -443
  465. package/packages/core/dist/org/tools.js.map +1 -1
  466. package/packages/core/dist/profile.d.ts.map +1 -1
  467. package/packages/core/dist/profile.js +114 -57
  468. package/packages/core/dist/profile.js.map +1 -1
  469. package/packages/core/dist/providers/catalogue.d.ts.map +1 -1
  470. package/packages/core/dist/providers/catalogue.js +89 -60
  471. package/packages/core/dist/providers/catalogue.js.map +1 -1
  472. package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
  473. package/packages/core/dist/providers/claude-code.js +418 -357
  474. package/packages/core/dist/providers/claude-code.js.map +1 -1
  475. package/packages/core/dist/providers/claude-tui.d.ts +13 -9
  476. package/packages/core/dist/providers/claude-tui.d.ts.map +1 -1
  477. package/packages/core/dist/providers/claude-tui.js +568 -396
  478. package/packages/core/dist/providers/claude-tui.js.map +1 -1
  479. package/packages/core/dist/providers/codex-auth.d.ts +3 -0
  480. package/packages/core/dist/providers/codex-auth.d.ts.map +1 -1
  481. package/packages/core/dist/providers/codex-auth.js +9 -7
  482. package/packages/core/dist/providers/codex-auth.js.map +1 -1
  483. package/packages/core/dist/providers/codex-bridge.d.ts +24 -7
  484. package/packages/core/dist/providers/codex-bridge.d.ts.map +1 -1
  485. package/packages/core/dist/providers/codex-bridge.js +128 -168
  486. package/packages/core/dist/providers/codex-bridge.js.map +1 -1
  487. package/packages/core/dist/providers/codex-translate.d.ts.map +1 -1
  488. package/packages/core/dist/providers/codex-translate.js +195 -197
  489. package/packages/core/dist/providers/codex-translate.js.map +1 -1
  490. package/packages/core/dist/providers/loopback-server.d.ts +33 -0
  491. package/packages/core/dist/providers/loopback-server.d.ts.map +1 -0
  492. package/packages/core/dist/providers/loopback-server.js +104 -0
  493. package/packages/core/dist/providers/loopback-server.js.map +1 -0
  494. package/packages/core/dist/providers/model-gateway.d.ts +2 -4
  495. package/packages/core/dist/providers/model-gateway.d.ts.map +1 -1
  496. package/packages/core/dist/providers/model-gateway.js +39 -75
  497. package/packages/core/dist/providers/model-gateway.js.map +1 -1
  498. package/packages/core/dist/providers/process.d.ts.map +1 -1
  499. package/packages/core/dist/providers/process.js +32 -23
  500. package/packages/core/dist/providers/process.js.map +1 -1
  501. package/packages/core/dist/providers/provider-catalog.d.ts.map +1 -1
  502. package/packages/core/dist/providers/provider-catalog.js +21 -23
  503. package/packages/core/dist/providers/provider-catalog.js.map +1 -1
  504. package/packages/core/dist/providers/quota.d.ts.map +1 -1
  505. package/packages/core/dist/providers/quota.js +37 -37
  506. package/packages/core/dist/providers/quota.js.map +1 -1
  507. package/packages/core/dist/providers/registry.d.ts.map +1 -1
  508. package/packages/core/dist/providers/registry.js +3 -1
  509. package/packages/core/dist/providers/registry.js.map +1 -1
  510. package/packages/core/dist/providers/user-settings-guard.d.ts.map +1 -1
  511. package/packages/core/dist/providers/user-settings-guard.js +7 -2
  512. package/packages/core/dist/providers/user-settings-guard.js.map +1 -1
  513. package/packages/core/dist/runtime.d.ts +45 -158
  514. package/packages/core/dist/runtime.d.ts.map +1 -1
  515. package/packages/core/dist/runtime.js +184 -1701
  516. package/packages/core/dist/runtime.js.map +1 -1
  517. package/packages/core/dist/skills/import.d.ts.map +1 -1
  518. package/packages/core/dist/skills/import.js +52 -36
  519. package/packages/core/dist/skills/import.js.map +1 -1
  520. package/packages/core/dist/skills/shelf.d.ts +14 -0
  521. package/packages/core/dist/skills/shelf.d.ts.map +1 -1
  522. package/packages/core/dist/skills/shelf.js +2 -3
  523. package/packages/core/dist/skills/shelf.js.map +1 -1
  524. package/packages/core/dist/skills/store.d.ts +2 -0
  525. package/packages/core/dist/skills/store.d.ts.map +1 -1
  526. package/packages/core/dist/skills/store.js +17 -12
  527. package/packages/core/dist/skills/store.js.map +1 -1
  528. package/packages/core/dist/tools/catalog.d.ts +13 -0
  529. package/packages/core/dist/tools/catalog.d.ts.map +1 -1
  530. package/packages/core/dist/tools/catalog.js +20 -5
  531. package/packages/core/dist/tools/catalog.js.map +1 -1
  532. package/packages/core/dist/tools/hub.d.ts +4 -1
  533. package/packages/core/dist/tools/hub.d.ts.map +1 -1
  534. package/packages/core/dist/tools/hub.js +114 -83
  535. package/packages/core/dist/tools/hub.js.map +1 -1
  536. package/packages/core/dist/turns/journal.d.ts.map +1 -1
  537. package/packages/core/dist/turns/journal.js +12 -18
  538. package/packages/core/dist/turns/journal.js.map +1 -1
  539. package/packages/core/dist/types.d.ts +25 -3
  540. package/packages/core/dist/types.d.ts.map +1 -1
  541. package/packages/core/dist/types.js.map +1 -1
  542. package/packages/core/dist/util/blocks.d.ts.map +1 -1
  543. package/packages/core/dist/util/blocks.js +14 -22
  544. package/packages/core/dist/util/blocks.js.map +1 -1
  545. package/packages/core/dist/util/queue.d.ts +0 -2
  546. package/packages/core/dist/util/queue.d.ts.map +1 -1
  547. package/packages/core/dist/util/queue.js +0 -6
  548. package/packages/core/dist/util/queue.js.map +1 -1
  549. package/packages/core/package.json +1 -1
  550. package/packages/server/dist/auth.d.ts +27 -9
  551. package/packages/server/dist/auth.d.ts.map +1 -1
  552. package/packages/server/dist/auth.js +73 -15
  553. package/packages/server/dist/auth.js.map +1 -1
  554. package/packages/server/dist/env.d.ts.map +1 -1
  555. package/packages/server/dist/env.js +18 -15
  556. package/packages/server/dist/env.js.map +1 -1
  557. package/packages/server/dist/errors.d.ts +3 -0
  558. package/packages/server/dist/errors.d.ts.map +1 -0
  559. package/packages/server/dist/errors.js +5 -0
  560. package/packages/server/dist/errors.js.map +1 -0
  561. package/packages/server/dist/gateways/attachments.d.ts.map +1 -1
  562. package/packages/server/dist/gateways/attachments.js +38 -21
  563. package/packages/server/dist/gateways/attachments.js.map +1 -1
  564. package/packages/server/dist/gateways/markdown.d.ts.map +1 -1
  565. package/packages/server/dist/gateways/markdown.js +30 -12
  566. package/packages/server/dist/gateways/markdown.js.map +1 -1
  567. package/packages/server/dist/gateways/push.d.ts +6 -6
  568. package/packages/server/dist/gateways/push.d.ts.map +1 -1
  569. package/packages/server/dist/gateways/push.js +101 -74
  570. package/packages/server/dist/gateways/push.js.map +1 -1
  571. package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -1
  572. package/packages/server/dist/gateways/telegram-api.js +61 -44
  573. package/packages/server/dist/gateways/telegram-api.js.map +1 -1
  574. package/packages/server/dist/gateways/telegram.d.ts +5 -0
  575. package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
  576. package/packages/server/dist/gateways/telegram.js +985 -753
  577. package/packages/server/dist/gateways/telegram.js.map +1 -1
  578. package/packages/server/dist/gateways/threads.d.ts.map +1 -1
  579. package/packages/server/dist/gateways/threads.js +144 -130
  580. package/packages/server/dist/gateways/threads.js.map +1 -1
  581. package/packages/server/dist/listeners/imap.d.ts.map +1 -1
  582. package/packages/server/dist/listeners/imap.js +0 -0
  583. package/packages/server/dist/listeners/imap.js.map +1 -1
  584. package/packages/server/dist/listeners/registry.d.ts.map +1 -1
  585. package/packages/server/dist/listeners/registry.js +15 -15
  586. package/packages/server/dist/listeners/registry.js.map +1 -1
  587. package/packages/server/dist/main.js +3 -2
  588. package/packages/server/dist/main.js.map +1 -1
  589. package/packages/server/dist/routes/chat.d.ts.map +1 -1
  590. package/packages/server/dist/routes/chat.js +5 -8
  591. package/packages/server/dist/routes/chat.js.map +1 -1
  592. package/packages/server/dist/routes/config.d.ts +6 -0
  593. package/packages/server/dist/routes/config.d.ts.map +1 -1
  594. package/packages/server/dist/routes/config.js +34 -31
  595. package/packages/server/dist/routes/config.js.map +1 -1
  596. package/packages/server/dist/routes/cron.d.ts.map +1 -1
  597. package/packages/server/dist/routes/cron.js +33 -23
  598. package/packages/server/dist/routes/cron.js.map +1 -1
  599. package/packages/server/dist/routes/dream.d.ts +1 -1
  600. package/packages/server/dist/routes/dream.d.ts.map +1 -1
  601. package/packages/server/dist/routes/dream.js +16 -34
  602. package/packages/server/dist/routes/dream.js.map +1 -1
  603. package/packages/server/dist/routes/gateways.d.ts.map +1 -1
  604. package/packages/server/dist/routes/gateways.js +8 -13
  605. package/packages/server/dist/routes/gateways.js.map +1 -1
  606. package/packages/server/dist/routes/memories.d.ts.map +1 -1
  607. package/packages/server/dist/routes/memories.js +16 -29
  608. package/packages/server/dist/routes/memories.js.map +1 -1
  609. package/packages/server/dist/routes/night.d.ts +31 -0
  610. package/packages/server/dist/routes/night.d.ts.map +1 -0
  611. package/packages/server/dist/routes/night.js +28 -0
  612. package/packages/server/dist/routes/night.js.map +1 -0
  613. package/packages/server/dist/routes/org.d.ts.map +1 -1
  614. package/packages/server/dist/routes/org.js +125 -119
  615. package/packages/server/dist/routes/org.js.map +1 -1
  616. package/packages/server/dist/routes/profile.d.ts.map +1 -1
  617. package/packages/server/dist/routes/profile.js +5 -6
  618. package/packages/server/dist/routes/profile.js.map +1 -1
  619. package/packages/server/dist/routes/providers.d.ts.map +1 -1
  620. package/packages/server/dist/routes/providers.js +1 -3
  621. package/packages/server/dist/routes/providers.js.map +1 -1
  622. package/packages/server/dist/routes/query.d.ts +10 -0
  623. package/packages/server/dist/routes/query.d.ts.map +1 -0
  624. package/packages/server/dist/routes/query.js +17 -0
  625. package/packages/server/dist/routes/query.js.map +1 -0
  626. package/packages/server/dist/routes/questions.d.ts.map +1 -1
  627. package/packages/server/dist/routes/questions.js +5 -11
  628. package/packages/server/dist/routes/questions.js.map +1 -1
  629. package/packages/server/dist/routes/sessions.d.ts.map +1 -1
  630. package/packages/server/dist/routes/sessions.js +20 -28
  631. package/packages/server/dist/routes/sessions.js.map +1 -1
  632. package/packages/server/dist/routes/sleep.d.ts.map +1 -1
  633. package/packages/server/dist/routes/sleep.js +21 -36
  634. package/packages/server/dist/routes/sleep.js.map +1 -1
  635. package/packages/server/dist/routes/stats.d.ts.map +1 -1
  636. package/packages/server/dist/routes/stats.js +2 -7
  637. package/packages/server/dist/routes/stats.js.map +1 -1
  638. package/packages/server/dist/routes/terminals.d.ts.map +1 -1
  639. package/packages/server/dist/routes/terminals.js +19 -14
  640. package/packages/server/dist/routes/terminals.js.map +1 -1
  641. package/packages/server/dist/routes/tools.d.ts.map +1 -1
  642. package/packages/server/dist/routes/tools.js +9 -5
  643. package/packages/server/dist/routes/tools.js.map +1 -1
  644. package/packages/server/dist/routes/ws.d.ts.map +1 -1
  645. package/packages/server/dist/routes/ws.js +235 -207
  646. package/packages/server/dist/routes/ws.js.map +1 -1
  647. package/packages/server/dist/schemas.d.ts +30 -21
  648. package/packages/server/dist/schemas.d.ts.map +1 -1
  649. package/packages/server/dist/schemas.js +3 -2
  650. package/packages/server/dist/schemas.js.map +1 -1
  651. package/packages/server/dist/server.d.ts.map +1 -1
  652. package/packages/server/dist/server.js +257 -238
  653. package/packages/server/dist/server.js.map +1 -1
  654. package/packages/server/dist/services/stream.d.ts.map +1 -1
  655. package/packages/server/dist/services/stream.js +6 -4
  656. package/packages/server/dist/services/stream.js.map +1 -1
  657. package/packages/server/dist/services/stt.d.ts +1 -1
  658. package/packages/server/dist/services/stt.d.ts.map +1 -1
  659. package/packages/server/dist/services/stt.js +175 -124
  660. package/packages/server/dist/services/stt.js.map +1 -1
  661. package/packages/server/dist/services/tts.d.ts.map +1 -1
  662. package/packages/server/dist/services/tts.js +82 -54
  663. package/packages/server/dist/services/tts.js.map +1 -1
  664. package/packages/server/dist/services/turns.d.ts +8 -6
  665. package/packages/server/dist/services/turns.d.ts.map +1 -1
  666. package/packages/server/dist/services/turns.js +36 -32
  667. package/packages/server/dist/services/turns.js.map +1 -1
  668. package/packages/server/dist/services/updates.d.ts +1 -0
  669. package/packages/server/dist/services/updates.d.ts.map +1 -1
  670. package/packages/server/dist/services/updates.js +150 -91
  671. package/packages/server/dist/services/updates.js.map +1 -1
  672. package/packages/server/dist/services/voice-keys.d.ts.map +1 -1
  673. package/packages/server/dist/services/voice-keys.js +4 -2
  674. package/packages/server/dist/services/voice-keys.js.map +1 -1
  675. package/packages/server/dist/static.d.ts +1 -1
  676. package/packages/server/dist/static.d.ts.map +1 -1
  677. package/packages/server/dist/static.js +7 -7
  678. package/packages/server/dist/static.js.map +1 -1
  679. package/packages/server/package.json +1 -1
  680. package/packages/web/dist/assets/{abnfDiagram-O67JEVCF-D7YyFndQ.js → abnfDiagram-O67JEVCF-BmjzYusK.js} +1 -1
  681. package/packages/web/dist/assets/{arc-C_Zgk2dJ.js → arc-n9TPu3wY.js} +1 -1
  682. package/packages/web/dist/assets/{architectureDiagram-NJMV4G6O-eI0adu1B.js → architectureDiagram-NJMV4G6O-Cx9TKHMG.js} +1 -1
  683. package/packages/web/dist/assets/{blockDiagram-BEXU5L5S-WAoOFUA9.js → blockDiagram-BEXU5L5S-Cu2lqO0u.js} +1 -1
  684. package/packages/web/dist/assets/{c4Diagram-YGBWAQC7-DE8Zyhng.js → c4Diagram-YGBWAQC7-C0lage7M.js} +1 -1
  685. package/packages/web/dist/assets/channel-Cx64mAod.js +1 -0
  686. package/packages/web/dist/assets/{chunk-2Q5K7J3B-bnqLP2XD.js → chunk-2Q5K7J3B-D3aVQoie.js} +1 -1
  687. package/packages/web/dist/assets/{chunk-3FUC2YCW-Ck1_SVe0.js → chunk-3FUC2YCW-Cmrvpp5I.js} +2 -2
  688. package/packages/web/dist/assets/{chunk-5VM5RSS4-hDmC41gD.js → chunk-5VM5RSS4-Bk7nd1Or.js} +1 -1
  689. package/packages/web/dist/assets/{chunk-GTNCS2PH-PoWvfCrT.js → chunk-GTNCS2PH--_-V13S9.js} +1 -1
  690. package/packages/web/dist/assets/{chunk-GWA4HPMP-D3V0IG43.js → chunk-GWA4HPMP-B2iN_iAC.js} +1 -1
  691. package/packages/web/dist/assets/{chunk-JWPE2WC7-BryfpHM5.js → chunk-JWPE2WC7-BCQEdHBw.js} +1 -1
  692. package/packages/web/dist/assets/{chunk-NETBCI7D-8ic1iEdT.js → chunk-NETBCI7D-lKrFsR6g.js} +1 -1
  693. package/packages/web/dist/assets/{chunk-WEXAMYUT-nM8tmQT2.js → chunk-WEXAMYUT-Bl4c2a1n.js} +1 -1
  694. package/packages/web/dist/assets/{chunk-XXDRQBXY-Do28F482.js → chunk-XXDRQBXY-xvPIGObD.js} +1 -1
  695. package/packages/web/dist/assets/{classDiagram-v2-NBCMYWYE-Bop9oNNO.js → classDiagram-v2-NBCMYWYE-DjX85RUY.js} +1 -1
  696. package/packages/web/dist/assets/{cose-bilkent-JH36ORCC-a7f_bpnt.js → cose-bilkent-JH36ORCC-Dn5oYBNs.js} +1 -1
  697. package/packages/web/dist/assets/{cynefin-OW5HDTMX-DnArcis_.js → cynefin-OW5HDTMX-D1zN_crx.js} +1 -1
  698. package/packages/web/dist/assets/{cynefinDiagram-VND7K2PF-vEuTb1GD.js → cynefinDiagram-VND7K2PF-B-GwPS_J.js} +1 -1
  699. package/packages/web/dist/assets/{dagre-6A5THRUB-BgG4MynJ.js → dagre-6A5THRUB-C2wUvKaS.js} +1 -1
  700. package/packages/web/dist/assets/{diagram-22UHCM2B-DRCQpafv.js → diagram-22UHCM2B-DnZ3T6JG.js} +1 -1
  701. package/packages/web/dist/assets/{diagram-3UASUU5V-BKgmAXde.js → diagram-3UASUU5V-DR8pK0Yb.js} +1 -1
  702. package/packages/web/dist/assets/{diagram-ATOU4E4O-B6Hsy36X.js → diagram-ATOU4E4O-olswvjNy.js} +1 -1
  703. package/packages/web/dist/assets/{diagram-CDSNMT55-JflyfyoB.js → diagram-CDSNMT55-CkbrgFGH.js} +1 -1
  704. package/packages/web/dist/assets/{diagram-MLGK6HIB-Dd2QPJjT.js → diagram-MLGK6HIB-DiNLsh9k.js} +1 -1
  705. package/packages/web/dist/assets/{diagram-MPIPVDR6-DE5QU60x.js → diagram-MPIPVDR6-DY0eRCo8.js} +1 -1
  706. package/packages/web/dist/assets/{ebnfDiagram-ZINNZB2B-D7AQ741b.js → ebnfDiagram-ZINNZB2B-BwyYBste.js} +1 -1
  707. package/packages/web/dist/assets/{elk-276RUBZZ-CeewBVLF.js → elk-276RUBZZ-BOkb2Unt.js} +1 -1
  708. package/packages/web/dist/assets/{erDiagram-OPXOYQCR-mLLYkZ5c.js → erDiagram-OPXOYQCR-Bopm0hOe.js} +1 -1
  709. package/packages/web/dist/assets/{flowDiagram-KWPJA3E3-DtpSpsQN.js → flowDiagram-KWPJA3E3-CB8O7Rey.js} +1 -1
  710. package/packages/web/dist/assets/{ganttDiagram-FUAMR5RP-1_lh-3ky.js → ganttDiagram-FUAMR5RP-BMoBwxn3.js} +1 -1
  711. package/packages/web/dist/assets/{gitGraphDiagram-X574FWY7-DoPXZuT5.js → gitGraphDiagram-X574FWY7-r9EVynuW.js} +1 -1
  712. package/packages/web/dist/assets/index-BJFGaq8t.js +646 -0
  713. package/packages/web/dist/assets/index-BMYKZrup.css +32 -0
  714. package/packages/web/dist/assets/{infoDiagram-VRGFBTTK-DQpRGGiD.js → infoDiagram-VRGFBTTK-4NICTzD4.js} +1 -1
  715. package/packages/web/dist/assets/{ishikawaDiagram-OU5B5YK6-gH5C9Q2e.js → ishikawaDiagram-OU5B5YK6-qmYHkSam.js} +1 -1
  716. package/packages/web/dist/assets/{journeyDiagram-ZHPQQLJL-Bg-oeFjb.js → journeyDiagram-ZHPQQLJL-BSb6Qa2c.js} +1 -1
  717. package/packages/web/dist/assets/{kanban-definition-PNTS6WVX-BnpI4VH8.js → kanban-definition-PNTS6WVX-B0cwMsip.js} +1 -1
  718. package/packages/web/dist/assets/{mermaid.core-BwBKxlRA.js → mermaid.core-CTl4Qse1.js} +4 -4
  719. package/packages/web/dist/assets/{mindmap-definition-NLK3R4M7-NBnnxEoO.js → mindmap-definition-NLK3R4M7-tbJ4AKr2.js} +1 -1
  720. package/packages/web/dist/assets/{pegDiagram-GJSIUBJH-RrXXbIvO.js → pegDiagram-GJSIUBJH-BD50Xatx.js} +1 -1
  721. package/packages/web/dist/assets/{pieDiagram-5QR66LMP-B27q6Gso.js → pieDiagram-5QR66LMP-C52DU0dU.js} +1 -1
  722. package/packages/web/dist/assets/{quadrantDiagram-O4NWA36T-DGDsdur2.js → quadrantDiagram-O4NWA36T-Dmf0Relz.js} +1 -1
  723. package/packages/web/dist/assets/{railroadDiagram-XR7U4H2S-GdjkE3mI.js → railroadDiagram-XR7U4H2S-q1rW0LBx.js} +1 -1
  724. package/packages/web/dist/assets/{requirementDiagram-PLB6GJNP-DjK0GfgO.js → requirementDiagram-PLB6GJNP-ChTty00B.js} +1 -1
  725. package/packages/web/dist/assets/{sankeyDiagram-IPEJSGJF-BG_AIkwF.js → sankeyDiagram-IPEJSGJF-vRhUUtR0.js} +1 -1
  726. package/packages/web/dist/assets/scene-DUzELcJR.js +4620 -0
  727. package/packages/web/dist/assets/{sequenceDiagram-PO4LG4MO-CIQwUb4y.js → sequenceDiagram-PO4LG4MO-CJ37i6X7.js} +1 -1
  728. package/packages/web/dist/assets/{sizeCapture-INFHLROL-bpIoPxdJ.js → sizeCapture-INFHLROL-CUwB5IU5.js} +1 -1
  729. package/packages/web/dist/assets/{stateDiagram-v2-GCMORJYK-8hYXvPPv.js → stateDiagram-v2-GCMORJYK-CbmUCHZz.js} +1 -1
  730. package/packages/web/dist/assets/{swimlanes-2SLR337P-gfflUMF9.js → swimlanes-2SLR337P-BH1ix14-.js} +1 -1
  731. package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-D1P54_6D.js +8 -0
  732. package/packages/web/dist/assets/{timeline-definition-EJHVYXUP-PHMNoGTZ.js → timeline-definition-EJHVYXUP-h73o8wo_.js} +1 -1
  733. package/packages/web/dist/assets/{usecaseDiagram-POWQR4AR-B2j5iteO.js → usecaseDiagram-POWQR4AR-BmrG9VWs.js} +1 -1
  734. package/packages/web/dist/assets/{vennDiagram-UO4OBE2U-BzxtZ-_2.js → vennDiagram-UO4OBE2U-Bax-03xB.js} +1 -1
  735. package/packages/web/dist/assets/{wardleyDiagram-VNRHLVJA-DL7YbMpY.js → wardleyDiagram-VNRHLVJA-A2y6258q.js} +1 -1
  736. package/packages/web/dist/assets/{xychartDiagram-PMCCYNJV-CisgP1cT.js → xychartDiagram-PMCCYNJV-BSiMaGgj.js} +1 -1
  737. package/packages/web/dist/index.html +2 -2
  738. package/packages/web/package.json +1 -1
  739. package/packages/web/dist/assets/channel-egZxcyUK.js +0 -1
  740. package/packages/web/dist/assets/index-Cw2Opmx7.js +0 -648
  741. package/packages/web/dist/assets/index-j0zBRCgT.css +0 -32
  742. package/packages/web/dist/assets/scene-D4LPicHk.js +0 -4620
  743. package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-9wdzGXU-.js +0 -8
@@ -22,6 +22,42 @@ const PROTOCOL_FALLBACK = '2025-06-18';
22
22
  const MAX_WIDTH = Math.min(3840, Math.max(320, Number(process.env.ROOKERY_COMPUTER_MAX_WIDTH) || 1280));
23
23
  const RUN_DIR = process.env.ROOKERY_COMPUTER_DIR ? join(process.env.ROOKERY_COMPUTER_DIR, 'run') : '';
24
24
  const BACKGROUND = process.env.ROOKERY_COMPUTER_MODE === 'background';
25
+ /** What a fresh worker gets to let go of held buttons and keys. */
26
+ const RELEASE_TIMEOUT_MS = 10_000;
27
+ /** Version reported in the MCP initialize handshake. */
28
+ const SERVER_VERSION = '0.2.0';
29
+ const JSONRPC_METHOD_NOT_FOUND = -32601;
30
+ const JSONRPC_SERVER_ERROR = -32000;
31
+ /** What the worker gets for a capture, snapshot, automation action or launch. */
32
+ const WORKER_TIMEOUT_MS = 15_000;
33
+ /** What the worker gets to recognise or search the screen's text. */
34
+ const OCR_TIMEOUT_MS = 20_000;
35
+ /** What the worker gets to settle after an action. */
36
+ const SETTLE_TIMEOUT_MS = 5_000;
37
+ /** Default for physical input, before drawing adds its own length. */
38
+ const PHYSICAL_TIMEOUT_MS = 30_000;
39
+ /** The worker's timeout beyond the time the user is given in a hand-over. */
40
+ const HAND_OVER_GRACE_MS = 15_000;
41
+ /** How often wait_for looks at the screen again. */
42
+ const WAIT_FOR_POLL_MS = 400;
43
+ /** Longest stretch a pause sleeps before checking for a stop. */
44
+ const PAUSE_STEP_MS = 50;
45
+ /** Clipboard text returned to the model is cut at this many characters. */
46
+ const CLIPBOARD_READ_LIMIT = 20_000;
47
+ /** Audit entries keep only this much of a failure's first line. */
48
+ const AUDIT_ERROR_LENGTH = 200;
49
+ /** Shutdown: how long the cursor may fade out, and how long the worker gets to be asked. */
50
+ const CURSOR_FADE_BUDGET_MS = 700;
51
+ const CURSOR_DISMISS_TIMEOUT_MS = 2000;
52
+ const RELEASE_ON_EXIT_TIMEOUT_MS = 3000;
53
+ /** Settle for an action with nothing to observe: a short look at what it left in front. */
54
+ const QUIET_SETTLE = 'Rk-Settle 40 600 80';
55
+ function textContent(text) {
56
+ return [{ type: 'text', text }];
57
+ }
58
+ function elapsedMs(started) {
59
+ return Math.round(performance.now() - started);
60
+ }
25
61
  const shell = new PowerShellSession();
26
62
  // Warm the worker and its cursor while the model is still writing its first call;
27
63
  // the first action then finds everything loaded. A failure here surfaces on that call.
@@ -72,11 +108,11 @@ let inputInFlight = 0;
72
108
  * cleanup, so a drag's button or a shortcut's modifier would stay down for the
73
109
  * user. A fresh worker lets go of whatever is still held.
74
110
  */
75
- async function releaseHeld(timeoutMs = 10_000) {
111
+ async function releaseHeld(timeoutMs = RELEASE_TIMEOUT_MS) {
76
112
  await shell.run('Rk-Release', timeoutMs).catch(() => undefined);
77
113
  }
78
114
  /** Serialize physical input across Rookery processes; the worker's guard refuses a changed desktop. */
79
- async function physical(expression, timeoutMs = 30_000) {
115
+ async function physical(expression, timeoutMs = PHYSICAL_TIMEOUT_MS) {
80
116
  inputInFlight++;
81
117
  try {
82
118
  await shell.run('$mutex = New-Object System.Threading.Mutex($false, "Local\\RookeryComputerInput"); ' +
@@ -162,7 +198,7 @@ function planDrawing(args) {
162
198
  strokes: packed[0],
163
199
  points,
164
200
  // Ink runs at about 3.5 px/ms; each stroke adds a hop and two short holds.
165
- timeoutMs: 30_000 + ink / 2.5 + packed[0] * 250,
201
+ timeoutMs: PHYSICAL_TIMEOUT_MS + ink / 2.5 + packed[0] * 250,
166
202
  };
167
203
  }
168
204
  /* ---------------------------------- tools --------------------------------- */
@@ -173,7 +209,7 @@ function planDrawing(args) {
173
209
  * with no baseline yet (a turn's first call), the reading establishes one.
174
210
  */
175
211
  async function ocr(guarded = false) {
176
- return shell.run((guarded ? 'if ($null -ne $script:rkForeground) { Rk-Guard }; ' : '') + 'Rk-ReadScreen ' + (stopped ? '$false' : '$true'), 20_000);
212
+ return shell.run((guarded ? 'if ($null -ne $script:rkForeground) { Rk-Guard }; ' : '') + 'Rk-ReadScreen ' + (stopped ? '$false' : '$true'), OCR_TIMEOUT_MS);
177
213
  }
178
214
  /**
179
215
  * Recognise the screen's text. Like a screenshot, it becomes the view that
@@ -196,7 +232,7 @@ function listMatches(matches) {
196
232
  }
197
233
  /** Controls named exactly like the phrase in one window, with refs act accepts. */
198
234
  async function findControls(window, name) {
199
- return shell.run('Rk-FindControls ' + window + ' ' + psQuote(name), 20_000);
235
+ return shell.run('Rk-FindControls ' + window + ' ' + psQuote(name), OCR_TIMEOUT_MS);
200
236
  }
201
237
  function listControls(found, from = 0) {
202
238
  const map = mapping(found.screen);
@@ -208,7 +244,7 @@ async function pause(ms) {
208
244
  while (Date.now() < until) {
209
245
  if (stopped)
210
246
  throw new Error('Computer use stopped.');
211
- await delay(Math.min(50, until - Date.now()));
247
+ await delay(Math.min(PAUSE_STEP_MS, until - Date.now()));
212
248
  }
213
249
  }
214
250
  /**
@@ -220,7 +256,7 @@ async function pause(ms) {
220
256
  * tells the model when nothing visibly happened.
221
257
  */
222
258
  async function settled(observe) {
223
- const result = await shell.run(observe === 'none' ? 'Rk-Settle 40 600 80' : 'Rk-Settle', 5_000);
259
+ const result = await shell.run(observe === 'none' ? QUIET_SETTLE : 'Rk-Settle', SETTLE_TIMEOUT_MS);
224
260
  const note = { type: 'text', text: describeSettle(result) };
225
261
  if (observe === 'none')
226
262
  return [note];
@@ -248,298 +284,316 @@ async function perform(command) {
248
284
  const { name, args } = command;
249
285
  if (stopped && !observations.has(name))
250
286
  throw new Error('Computer use stopped. Start a new turn to resume.');
251
- switch (name) {
252
- case 'stop':
253
- stopped = true;
254
- view = null;
255
- shell.close();
256
- return [{ type: 'text', text: 'Computer use stopped. Current and queued actions cancelled.' }];
257
- case 'snapshot': {
258
- const result = await shell.run('Rk-Snapshot ' + args.window + ' ' + args.maxNodes + ' ' + args.depth + ' ' + (stopped ? '$false' : '$true'), 15_000);
259
- return [{ type: 'text', text: describeSnapshot(result, mapping(result.screen)) }];
260
- }
261
- case 'act': {
262
- // The desktop view stays: physical input re-checks foreground and bounds before it moves.
263
- const result = await shell.run('Rk-Act ' + psQuote(args.ref) + ' ' + psQuote(args.action) + ' ' + psQuote(args.value ?? ''), 15_000);
264
- if (BACKGROUND && result.focusChanged) {
265
- stopped = true;
266
- shell.close();
267
- throw new Error(describeAct(result) + ' Background-only mode stopped all further actions; inspect the result before retrying in a new turn.');
268
- }
269
- return [{ type: 'text', text: describeAct(result) }];
270
- }
271
- case 'batch': {
272
- // Steps run blind; each still settles briefly, and the batch observes once at its end.
273
- const actions = args.actions.map((step) => {
274
- const action = validateComputerCall(step.tool, step.arguments, BACKGROUND);
275
- if ('observe' in action.args)
276
- action.args.observe = 'none';
277
- return action;
278
- });
279
- const done = [];
280
- for (const action of actions) {
281
- const started = performance.now();
282
- try {
283
- const content = await call(action);
284
- const said = content.map((part) => (part.type === 'text' ? part.text : '')).join(' ').trim();
285
- done.push((done.length + 1) + '. ' + action.name + ': ' + said + ' (' + Math.round(performance.now() - started) + ' ms)');
286
- }
287
- catch (error) {
288
- const step = done.length + 1;
289
- const skipped = actions.length - step;
290
- throw new Error('Step ' + step + ' of ' + actions.length + ' (' + action.name + ') failed: ' + error.message +
291
- (done.length ? '\nCompleted before it:\n' + done.join('\n') : '') +
292
- (skipped ? '\nSkipped: step' + (skipped > 1 ? 's ' + (step + 1) + '-' + actions.length : ' ' + actions.length) + '.' : '') +
293
- '\nNothing was rolled back.');
294
- }
295
- }
296
- const report = { type: 'text', text: done.join('\n') };
297
- const observe = args.observe ?? batchObservation(args.window, BACKGROUND);
298
- if (observe === 'none')
299
- return [report];
300
- const tool = observe === 'text' ? 'read_screen' : observe;
301
- try {
302
- return [report, ...(await call(validateComputerCall(tool, args.window && tool !== 'read_screen' ? { window: args.window } : {}, BACKGROUND)))];
303
- }
304
- catch (error) {
305
- throw new Error(done.join('\n') + '\nAll steps completed; the final ' + observe + ' failed: ' + error.message);
306
- }
307
- }
308
- case 'screenshot': {
309
- if (RUN_DIR)
310
- mkdirSync(RUN_DIR, { recursive: true });
311
- const path = RUN_DIR ? join(RUN_DIR, 'computer-' + process.pid + '.jpg') : '';
312
- let region = '$null';
313
- const previous = view;
314
- if (args.region) {
315
- if (!previous)
316
- throw new Error('A region is measured in pixels of the last desktop screenshot; take one first.');
317
- const r = args.region;
318
- if (r.x + r.width > previous.width || r.y + r.height > previous.height)
319
- throw new Error('The region reaches outside the last desktop screenshot (' + previous.width + 'x' + previous.height + ').');
320
- region = '@(' + [
321
- Math.round(previous.left + r.x / previous.scale), Math.round(previous.top + r.y / previous.scale),
322
- Math.max(1, Math.round(r.width / previous.scale)), Math.max(1, Math.round(r.height / previous.scale)),
323
- ].join(',') + ')';
324
- }
325
- const shot = await shell.run('Rk-Screenshot ' + MAX_WIDTH + ' ' + psQuote(path) + ' ' + (args.window ?? 0) + ' ' + (stopped ? '$false' : '$true') + ' ' + region + ' ' + (args.screen ?? 0), 15_000);
326
- if (!args.window) {
327
- view = { scale: shot.scale, left: shot.left, top: shot.top, width: shot.width, height: shot.height };
328
- restartsSeen = shell.restarts;
329
- }
330
- const pointer = shot.cursorX >= 0 && shot.cursorY >= 0 && shot.cursorX < shot.width && shot.cursorY < shot.height
331
- ? 'Pointer at ' + shot.cursorX + ',' + shot.cursorY + '.'
332
- : 'Pointer outside this view.';
333
- let what;
334
- if (args.window)
335
- what = 'Window capture (app-dependent); virtual cursor marks the last UIA target. Observe with snapshot if blank.';
336
- else if (args.region) {
337
- const zoom = shot.scale / previous.scale;
338
- what = 'Zoomed ' + zoom.toFixed(1) + 'x into the region ' + args.region.x + ',' + args.region.y + ' ' + args.region.width + 'x' + args.region.height +
339
- ' of the previous screenshot. Coordinates now refer to this image until the next desktop screenshot or read_screen. ' + pointer;
340
- }
341
- else if (args.screen)
342
- what = 'Display ' + args.screen + ' only; coordinates now refer to this image. ' + pointer;
343
- else
344
- what = pointer;
345
- return [
346
- { type: 'image', data: shot.jpeg, mimeType: 'image/jpeg' },
347
- {
348
- type: 'text',
349
- text: 'Screenshot ' + shot.width + 'x' + shot.height + ' px' +
350
- (shot.scale < 1 ? ' (screen scaled by ' + shot.scale.toFixed(3) + ')' : '') + '. ' + what +
351
- (args.window ? '' : ' Active window: ' + describeWindow(shot.active) + '.') +
352
- (path ? ' Saved as ' + path + '.' : ''),
353
- },
354
- ];
355
- }
356
- case 'screen_info': {
357
- const info = await shell.run('Rk-ScreenInfo');
358
- const m = { scale: Math.min(1, MAX_WIDTH / info.width) };
359
- return [
360
- {
361
- type: 'text',
362
- text: 'Screenshot size ' + Math.round(info.width * m.scale) + 'x' + Math.round(info.height * m.scale) +
363
- ' px, scale ' + m.scale.toFixed(3) + ' of ' + info.width + 'x' + info.height + ' real pixels.\n' +
364
- info.screens
365
- .map((s, i) => '- screen ' + (i + 1) + ': ' + s.name + (s.primary ? ' (primary)' : '') + ': ' + s.width + 'x' + s.height + ' at ' + s.x + ',' + s.y)
366
- .join('\n') + '\nObserver: ' + JSON.stringify(info.observer),
367
- },
368
- ];
369
- }
370
- case 'read_screen': {
371
- const { screen, scale } = await readScreen();
372
- return [{ type: 'text', text: 'Screen text (OCR), centre x,y in screenshot pixels. Active window: ' + describeWindow(screen.active) + '.\n' + describeScreen(screen, scale) }];
373
- }
374
- case 'find_text': {
375
- const lines = [];
376
- let screen = null;
377
- if (!BACKGROUND) {
378
- ({ screen } = await readScreen());
379
- const matches = findText(screen, args.text);
380
- if (matches.length)
381
- lines.push(listMatches(matches));
382
- }
383
- // Controls by accessible name: the given window, else the active one when OCR saw nothing.
384
- const window = args.window ?? (lines.length ? 0 : screen?.foreground ?? 0);
385
- if (window) {
386
- const found = await findControls(window, args.text);
387
- if (found.controls.length)
388
- lines.push((lines.length ? 'Controls named ' : 'No visible text, but controls named ') + JSON.stringify(args.text) + ':\n' + listControls(found));
389
- }
390
- if (!lines.length) {
391
- return [{ type: 'text', text: 'No text or control named "' + args.text + '"' + (window ? ' in window ' + window : '') + '.' + (screen ? ' Visible text:\n' + visible(screen) : '') }];
392
- }
393
- return [{ type: 'text', text: lines.join('\n') }];
394
- }
395
- case 'wait_for': {
396
- const started = Date.now();
397
- const what = JSON.stringify(args.text);
398
- let screen = null;
399
- for (;;) {
400
- let where = '';
401
- if (args.window) {
402
- const found = await findControls(args.window, args.text);
403
- if (found.controls.length)
404
- where = listControls(found);
405
- }
406
- else {
407
- ({ screen } = await readScreen());
408
- const matches = findText(screen, args.text);
409
- if (matches.length)
410
- where = listMatches(matches);
411
- }
412
- const seconds = Math.round((Date.now() - started) / 100) / 10;
413
- if (Boolean(where) !== args.gone) {
414
- return [{ type: 'text', text: what + (args.gone ? ' is gone' : ' is on screen') + ' after ' + seconds + ' s.' + (where ? '\n' + where : '') }];
415
- }
416
- if (Date.now() - started >= args.timeoutSec * 1000) {
417
- throw new Error('Timed out after ' + args.timeoutSec + ' s: ' + what + (args.gone ? ' is still on screen.' : ' did not appear.') +
418
- (screen ? '\nVisible text:\n' + visible(screen) : ''));
419
- }
420
- await pause(400);
421
- }
422
- }
423
- case 'hand_over': {
424
- const timeout = args.timeoutSec * 1000;
425
- const result = await shell.run('Rk-HandOver ' + psQuote(args.reason) + ' ' + timeout, timeout + 15_000);
426
- const outcome = { type: 'text', text: result.outcome + ' Waited ' + Math.round(result.waitedMs / 1000) + ' s.' };
427
- // Background-only mode may not capture the desktop; the model snapshots its window instead.
428
- return BACKGROUND ? [outcome] : [outcome, ...(await settled('screenshot'))];
429
- }
430
- case 'click': {
431
- const { button, count } = args;
432
- const clicked = (what) => [{ type: 'text', text: (count === 2 ? 'Double-clicked ' : 'Clicked ') + (button === 'left' ? '' : 'with the ' + button + ' button ') + what + '.' }];
433
- let sx, sy, what;
434
- if (args.text !== undefined) {
435
- // The view stays as it is: the point comes from what is on screen now, not from the model's coordinates.
436
- const screen = await ocr(true);
437
- const matches = findText(screen, args.text);
438
- let picked = pickMatch(matches, args.text, args.index);
439
- if (typeof picked === 'string' && !matches.length && args.index === undefined && screen.foreground) {
440
- // Icon buttons and menu items have names without visible text.
441
- const found = await findControls(screen.foreground, args.text);
442
- const control = found.controls[0];
443
- if (found.controls.length === 1 && control) {
444
- const [x, y, width, height] = control.bounds;
445
- [sx, sy] = [Math.round(x + width / 2), Math.round(y + height / 2)];
446
- await physical('Rk-Click ' + sx + ' ' + sy + ' ' + psQuote(button) + ' ' + count);
447
- return clicked(control.role + ' "' + control.name + '" at ' + toView(sx, sy));
448
- }
449
- if (found.controls.length > 1)
450
- picked = found.controls.length + ' controls are named "' + args.text + '" and none shows the text; click one of their centres:\n' + listControls(found);
451
- }
452
- if (typeof picked === 'string') {
453
- throw new Error(picked + '\n' + (matches.length ? listMatches(matches) : 'Visible text:\n' + visible(screen)));
454
- }
455
- [sx, sy] = centre(picked);
456
- what = '"' + picked.text + '" at ' + toView(sx, sy) + (picked.foreground ? '' : ' (outside the active window)');
457
- }
458
- else {
459
- [sx, sy] = toScreen(args.x, args.y);
460
- what = args.x + ',' + args.y;
461
- }
462
- await physical('Rk-Click ' + sx + ' ' + sy + ' ' + psQuote(button) + ' ' + count);
463
- return clicked(what);
464
- }
465
- case 'move_mouse': {
466
- const [x, y] = toScreen(args.x, args.y);
467
- await physical('Rk-Move ' + x + ' ' + y);
468
- return [{ type: 'text', text: 'Pointer at ' + args.x + ',' + args.y + '.' }];
469
- }
470
- case 'drag': {
471
- const [x1, y1] = toScreen(args.fromX, args.fromY);
472
- const [x2, y2] = toScreen(args.toX, args.toY);
473
- await physical('Rk-Drag ' + x1 + ' ' + y1 + ' ' + x2 + ' ' + y2);
474
- return [{ type: 'text', text: 'Dragged from ' + args.fromX + ',' + args.fromY + ' to ' + args.toX + ',' + args.toY + '.' }];
475
- }
476
- case 'draw': {
477
- const plan = planDrawing(args);
478
- await physical('Rk-Draw ' + psQuote(plan.packed) + ' ' + psQuote(args.button), plan.timeoutMs);
479
- return [{ type: 'text', text: 'Drew ' + plan.strokes + (plan.strokes === 1 ? ' stroke' : ' strokes') + ' through ' + plan.points + ' points.' }];
480
- }
481
- case 'scroll': {
482
- const [x, y] = toScreen(args.x, args.y);
483
- const { direction, amount } = args;
484
- await physical('Rk-Scroll ' + x + ' ' + y + ' ' + psQuote(direction) + ' ' + amount);
485
- return [{ type: 'text', text: 'Scrolled ' + direction + ' by ' + amount + '.' }];
486
- }
487
- case 'type_text': {
488
- await physical('Rk-Type ' + psQuote(args.text));
489
- return [{ type: 'text', text: 'Typed ' + args.text.length + ' characters.' }];
490
- }
491
- case 'press_keys': {
492
- const combos = parseKeySequence(args.keys);
493
- const literal = '@(' + combos.map((combo) => ',@(' + combo.join(',') + ')').join(';') + ')';
494
- await physical('Rk-Keys ' + literal);
495
- return [{ type: 'text', text: 'Pressed ' + args.keys + '.' }];
496
- }
497
- case 'list_windows': {
498
- const rows = await shell.run('Rk-Windows');
499
- const list = Array.isArray(rows) ? rows : [rows];
500
- if (!list.length)
501
- return [{ type: 'text', text: 'No windows.' }];
502
- return [
503
- {
504
- type: 'text',
505
- text: list
506
- .map((w) => '- window=' + w.handle + ' ' + (w.active ? '[active] ' : '') + JSON.stringify(w.title) + ' (' + w.process + ') ' +
507
- (w.minimized ? 'minimized' : w.width + 'x' + w.height + ' at ' + w.x + ',' + w.y))
508
- .join('\n'),
509
- },
510
- ];
511
- }
512
- case 'focus_window': {
513
- view = null;
514
- const result = await shell.run('Rk-Focus ' + psQuote(args.title ?? '') + ' ' + (args.window ?? 0));
515
- return [{ type: 'text', text: 'Focused ' + describeWindow(result) + '.' }];
287
+ // The table pairs each name with its own argument type; the union of names cannot express that.
288
+ return TOOL_HANDLERS[name](args);
289
+ }
290
+ const TOOL_HANDLERS = {
291
+ stop: stopTool,
292
+ snapshot: snapshotTool,
293
+ act: actTool,
294
+ batch: batchTool,
295
+ screenshot: screenshotTool,
296
+ screen_info: screenInfoTool,
297
+ read_screen: readScreenTool,
298
+ find_text: findTextTool,
299
+ wait_for: waitForTool,
300
+ hand_over: handOverTool,
301
+ click: clickTool,
302
+ move_mouse: moveMouseTool,
303
+ drag: dragTool,
304
+ draw: drawTool,
305
+ scroll: scrollTool,
306
+ type_text: typeTextTool,
307
+ press_keys: pressKeysTool,
308
+ list_windows: listWindowsTool,
309
+ focus_window: focusWindowTool,
310
+ open: openTool,
311
+ clipboard: clipboardTool,
312
+ wait: waitTool,
313
+ };
314
+ async function stopTool() {
315
+ stopped = true;
316
+ view = null;
317
+ shell.close();
318
+ return textContent('Computer use stopped. Current and queued actions cancelled.');
319
+ }
320
+ async function snapshotTool(args) {
321
+ const result = await shell.run('Rk-Snapshot ' + args.window + ' ' + args.maxNodes + ' ' + args.depth + ' ' + (stopped ? '$false' : '$true'), WORKER_TIMEOUT_MS);
322
+ return textContent(describeSnapshot(result, mapping(result.screen)));
323
+ }
324
+ async function actTool(args) {
325
+ // The desktop view stays: physical input re-checks foreground and bounds before it moves.
326
+ const result = await shell.run('Rk-Act ' + psQuote(args.ref) + ' ' + psQuote(args.action) + ' ' + psQuote(args.value ?? ''), WORKER_TIMEOUT_MS);
327
+ if (BACKGROUND && result.focusChanged) {
328
+ stopped = true;
329
+ shell.close();
330
+ throw new Error(describeAct(result) + ' Background-only mode stopped all further actions; inspect the result before retrying in a new turn.');
331
+ }
332
+ return textContent(describeAct(result));
333
+ }
334
+ async function batchTool(args) {
335
+ // Steps run blind; each still settles briefly, and the batch observes once at its end.
336
+ const actions = args.actions.map((step) => {
337
+ const action = validateComputerCall(step.tool, step.arguments, BACKGROUND);
338
+ if ('observe' in action.args)
339
+ action.args.observe = 'none';
340
+ return action;
341
+ });
342
+ const done = await runBatchSteps(actions);
343
+ const report = textContent(done.join('\n'));
344
+ const observe = args.observe ?? batchObservation(args.window, BACKGROUND);
345
+ if (observe === 'none')
346
+ return report;
347
+ const tool = observe === 'text' ? 'read_screen' : observe;
348
+ try {
349
+ return [...report, ...(await call(validateComputerCall(tool, args.window && tool !== 'read_screen' ? { window: args.window } : {}, BACKGROUND)))];
350
+ }
351
+ catch (error) {
352
+ throw new Error(done.join('\n') + '\nAll steps completed; the final ' + observe + ' failed: ' + error.message);
353
+ }
354
+ }
355
+ /** Run the steps in order; the first failure stops the batch and reports what was done and what was skipped. */
356
+ async function runBatchSteps(actions) {
357
+ const done = [];
358
+ for (const action of actions) {
359
+ const started = performance.now();
360
+ try {
361
+ const content = await call(action);
362
+ done.push((done.length + 1) + '. ' + action.name + ': ' + spokenText(content) + ' (' + elapsedMs(started) + ' ms)');
516
363
  }
517
- case 'open': {
518
- view = null;
519
- const result = await shell.run('Rk-Open ' + psQuote(args.target), 15_000);
520
- if (!result.changed) {
521
- // Nothing to type into yet: say so as an error, so the model does not send input to whatever is in front.
522
- throw new Error('Opened ' + args.target + ', but no window came to the front within 3 s' +
523
- (result.behind ? ': ' + describeWindow(result.behind) + ' stayed behind ' : '; the active window is still ') + describeWindow(result.active) +
524
- '. Nothing was typed. Use focus_window with the handle, or wait_for, then take a screenshot.');
525
- }
526
- return [{ type: 'text', text: 'Opened ' + args.target + '. Active window is now ' + describeWindow(result.active) + '.' }];
364
+ catch (error) {
365
+ throw new Error(describeStepFailure(action, done, actions.length, error));
527
366
  }
528
- case 'clipboard': {
529
- if (args.action === 'set') {
530
- await shell.run('Rk-ClipSet ' + psQuote(args.text ?? ''));
531
- return [{ type: 'text', text: 'Clipboard set (' + args.text.length + ' characters).' }];
532
- }
533
- const result = await shell.run('Rk-ClipGet');
534
- return [{ type: 'text', text: result.text ? result.text.slice(0, 20_000) : '(clipboard is empty)' }];
367
+ }
368
+ return done;
369
+ }
370
+ function describeStepFailure(action, done, total, error) {
371
+ const step = done.length + 1;
372
+ const skipped = total - step;
373
+ return 'Step ' + step + ' of ' + total + ' (' + action.name + ') failed: ' + error.message +
374
+ (done.length ? '\nCompleted before it:\n' + done.join('\n') : '') +
375
+ (skipped ? '\nSkipped: step' + (skipped > 1 ? 's ' + (step + 1) + '-' + total : ' ' + total) + '.' : '') +
376
+ '\nNothing was rolled back.';
377
+ }
378
+ /** The text parts of a result on one line. */
379
+ function spokenText(content) {
380
+ return content.map((part) => (part.type === 'text' ? part.text : '')).join(' ').trim();
381
+ }
382
+ async function screenshotTool(args) {
383
+ if (RUN_DIR)
384
+ mkdirSync(RUN_DIR, { recursive: true });
385
+ const path = RUN_DIR ? join(RUN_DIR, 'computer-' + process.pid + '.jpg') : '';
386
+ const previous = view;
387
+ const region = args.region ? regionExpression(args.region, previous) : '$null';
388
+ const shot = await shell.run('Rk-Screenshot ' + MAX_WIDTH + ' ' + psQuote(path) + ' ' + (args.window ?? 0) + ' ' + (stopped ? '$false' : '$true') + ' ' + region + ' ' + (args.screen ?? 0), WORKER_TIMEOUT_MS);
389
+ if (!args.window) {
390
+ view = { scale: shot.scale, left: shot.left, top: shot.top, width: shot.width, height: shot.height };
391
+ restartsSeen = shell.restarts;
392
+ }
393
+ const caption = 'Screenshot ' + shot.width + 'x' + shot.height + ' px' +
394
+ (shot.scale < 1 ? ' (screen scaled by ' + shot.scale.toFixed(3) + ')' : '') + '. ' + describeCapture(args, shot, previous) +
395
+ (args.window ? '' : ' Active window: ' + describeWindow(shot.active) + '.') +
396
+ (path ? ' Saved as ' + path + '.' : '');
397
+ return [{ type: 'image', data: shot.jpeg, mimeType: 'image/jpeg' }, { type: 'text', text: caption }];
398
+ }
399
+ /** A region of the previous desktop screenshot as the worker's physical x, y, width, height. */
400
+ function regionExpression(region, previous) {
401
+ if (!previous)
402
+ throw new Error('A region is measured in pixels of the last desktop screenshot; take one first.');
403
+ if (region.x + region.width > previous.width || region.y + region.height > previous.height)
404
+ throw new Error('The region reaches outside the last desktop screenshot (' + previous.width + 'x' + previous.height + ').');
405
+ return '@(' + [
406
+ Math.round(previous.left + region.x / previous.scale), Math.round(previous.top + region.y / previous.scale),
407
+ Math.max(1, Math.round(region.width / previous.scale)), Math.max(1, Math.round(region.height / previous.scale)),
408
+ ].join(',') + ')';
409
+ }
410
+ /** What the model needs to know about how the capture relates to what it asked for. */
411
+ function describeCapture(args, shot, previous) {
412
+ if (args.window)
413
+ return 'Window capture (app-dependent); virtual cursor marks the last UIA target. Observe with snapshot if blank.';
414
+ const pointer = shot.cursorX >= 0 && shot.cursorY >= 0 && shot.cursorX < shot.width && shot.cursorY < shot.height
415
+ ? 'Pointer at ' + shot.cursorX + ',' + shot.cursorY + '.'
416
+ : 'Pointer outside this view.';
417
+ if (args.region) {
418
+ const zoom = shot.scale / previous.scale;
419
+ return 'Zoomed ' + zoom.toFixed(1) + 'x into the region ' + args.region.x + ',' + args.region.y + ' ' + args.region.width + 'x' + args.region.height +
420
+ ' of the previous screenshot. Coordinates now refer to this image until the next desktop screenshot or read_screen. ' + pointer;
421
+ }
422
+ if (args.screen)
423
+ return 'Display ' + args.screen + ' only; coordinates now refer to this image. ' + pointer;
424
+ return pointer;
425
+ }
426
+ async function screenInfoTool() {
427
+ const info = await shell.run('Rk-ScreenInfo');
428
+ const scale = Math.min(1, MAX_WIDTH / info.width);
429
+ return textContent('Screenshot size ' + Math.round(info.width * scale) + 'x' + Math.round(info.height * scale) +
430
+ ' px, scale ' + scale.toFixed(3) + ' of ' + info.width + 'x' + info.height + ' real pixels.\n' +
431
+ info.screens
432
+ .map((s, i) => '- screen ' + (i + 1) + ': ' + s.name + (s.primary ? ' (primary)' : '') + ': ' + s.width + 'x' + s.height + ' at ' + s.x + ',' + s.y)
433
+ .join('\n') + '\nObserver: ' + JSON.stringify(info.observer));
434
+ }
435
+ async function readScreenTool() {
436
+ const { screen, scale } = await readScreen();
437
+ return textContent('Screen text (OCR), centre x,y in screenshot pixels. Active window: ' + describeWindow(screen.active) + '.\n' + describeScreen(screen, scale));
438
+ }
439
+ async function findTextTool(args) {
440
+ const lines = [];
441
+ let screen = null;
442
+ if (!BACKGROUND) {
443
+ ({ screen } = await readScreen());
444
+ const matches = findText(screen, args.text);
445
+ if (matches.length)
446
+ lines.push(listMatches(matches));
447
+ }
448
+ // Controls by accessible name: the given window, else the active one when OCR saw nothing.
449
+ const window = args.window ?? (lines.length ? 0 : screen?.foreground ?? 0);
450
+ if (window) {
451
+ const found = await findControls(window, args.text);
452
+ if (found.controls.length)
453
+ lines.push((lines.length ? 'Controls named ' : 'No visible text, but controls named ') + JSON.stringify(args.text) + ':\n' + listControls(found));
454
+ }
455
+ if (!lines.length) {
456
+ return textContent('No text or control named "' + args.text + '"' + (window ? ' in window ' + window : '') + '.' + (screen ? ' Visible text:\n' + visible(screen) : ''));
457
+ }
458
+ return textContent(lines.join('\n'));
459
+ }
460
+ async function waitForTool(args) {
461
+ const started = Date.now();
462
+ const what = JSON.stringify(args.text);
463
+ for (;;) {
464
+ const { where, screen } = await locate(args.text, args.window);
465
+ const seconds = Math.round((Date.now() - started) / 100) / 10;
466
+ if (Boolean(where) !== args.gone) {
467
+ return textContent(what + (args.gone ? ' is gone' : ' is on screen') + ' after ' + seconds + ' s.' + (where ? '\n' + where : ''));
535
468
  }
536
- case 'wait': {
537
- await pause(args.ms);
538
- return [{ type: 'text', text: 'Waited ' + args.ms + ' ms.' }];
469
+ if (Date.now() - started >= args.timeoutSec * 1000) {
470
+ throw new Error('Timed out after ' + args.timeoutSec + ' s: ' + what + (args.gone ? ' is still on screen.' : ' did not appear.') +
471
+ (screen ? '\nVisible text:\n' + visible(screen) : ''));
539
472
  }
540
- default:
541
- throw new Error('Unknown tool ' + name + '.');
473
+ await pause(WAIT_FOR_POLL_MS);
474
+ }
475
+ }
476
+ /** One look for the text: among a window's controls, or on the screen (which becomes the view). Empty `where` means not found. */
477
+ async function locate(text, window) {
478
+ if (window) {
479
+ const found = await findControls(window, text);
480
+ return { where: found.controls.length ? listControls(found) : '', screen: null };
542
481
  }
482
+ const { screen } = await readScreen();
483
+ const matches = findText(screen, text);
484
+ return { where: matches.length ? listMatches(matches) : '', screen };
485
+ }
486
+ async function handOverTool(args) {
487
+ const timeout = args.timeoutSec * 1000;
488
+ const result = await shell.run('Rk-HandOver ' + psQuote(args.reason) + ' ' + timeout, timeout + HAND_OVER_GRACE_MS);
489
+ const outcome = textContent(result.outcome + ' Waited ' + Math.round(result.waitedMs / 1000) + ' s.');
490
+ // Background-only mode may not capture the desktop; the model snapshots its window instead.
491
+ return BACKGROUND ? outcome : [...outcome, ...(await settled('screenshot'))];
492
+ }
493
+ async function clickTool(args) {
494
+ const { button, count } = args;
495
+ const target = args.text === undefined ? coordinateTarget(args.x, args.y) : await textTarget(args.text, args.index);
496
+ await physical('Rk-Click ' + target.x + ' ' + target.y + ' ' + psQuote(button) + ' ' + count);
497
+ return textContent((count === 2 ? 'Double-clicked ' : 'Clicked ') + (button === 'left' ? '' : 'with the ' + button + ' button ') + target.what + '.');
498
+ }
499
+ function coordinateTarget(viewX, viewY) {
500
+ const [x, y] = toScreen(viewX, viewY);
501
+ return { x, y, what: viewX + ',' + viewY };
502
+ }
503
+ /** The point comes from what is on screen now, not from the model's coordinates; the view stays as it is. */
504
+ async function textTarget(text, index) {
505
+ const screen = await ocr(true);
506
+ const matches = findText(screen, text);
507
+ let picked = pickMatch(matches, text, index);
508
+ if (typeof picked === 'string' && !matches.length && index === undefined && screen.foreground) {
509
+ // Icon buttons and menu items have names without visible text.
510
+ const found = await findControls(screen.foreground, text);
511
+ const control = found.controls[0];
512
+ if (found.controls.length === 1 && control)
513
+ return controlTarget(control);
514
+ if (found.controls.length > 1)
515
+ picked = found.controls.length + ' controls are named "' + text + '" and none shows the text; click one of their centres:\n' + listControls(found);
516
+ }
517
+ if (typeof picked === 'string') {
518
+ throw new Error(picked + '\n' + (matches.length ? listMatches(matches) : 'Visible text:\n' + visible(screen)));
519
+ }
520
+ const [x, y] = centre(picked);
521
+ return { x, y, what: '"' + picked.text + '" at ' + toView(x, y) + (picked.foreground ? '' : ' (outside the active window)') };
522
+ }
523
+ function controlTarget(control) {
524
+ const [left, top, width, height] = control.bounds;
525
+ const x = Math.round(left + width / 2), y = Math.round(top + height / 2);
526
+ return { x, y, what: control.role + ' "' + control.name + '" at ' + toView(x, y) };
527
+ }
528
+ async function moveMouseTool(args) {
529
+ const [x, y] = toScreen(args.x, args.y);
530
+ await physical('Rk-Move ' + x + ' ' + y);
531
+ return textContent('Pointer at ' + args.x + ',' + args.y + '.');
532
+ }
533
+ async function dragTool(args) {
534
+ const [x1, y1] = toScreen(args.fromX, args.fromY);
535
+ const [x2, y2] = toScreen(args.toX, args.toY);
536
+ await physical('Rk-Drag ' + x1 + ' ' + y1 + ' ' + x2 + ' ' + y2);
537
+ return textContent('Dragged from ' + args.fromX + ',' + args.fromY + ' to ' + args.toX + ',' + args.toY + '.');
538
+ }
539
+ async function drawTool(args) {
540
+ const plan = planDrawing(args);
541
+ await physical('Rk-Draw ' + psQuote(plan.packed) + ' ' + psQuote(args.button), plan.timeoutMs);
542
+ return textContent('Drew ' + plan.strokes + (plan.strokes === 1 ? ' stroke' : ' strokes') + ' through ' + plan.points + ' points.');
543
+ }
544
+ async function scrollTool(args) {
545
+ const [x, y] = toScreen(args.x, args.y);
546
+ const { direction, amount } = args;
547
+ await physical('Rk-Scroll ' + x + ' ' + y + ' ' + psQuote(direction) + ' ' + amount);
548
+ return textContent('Scrolled ' + direction + ' by ' + amount + '.');
549
+ }
550
+ async function typeTextTool(args) {
551
+ await physical('Rk-Type ' + psQuote(args.text));
552
+ return textContent('Typed ' + args.text.length + ' characters.');
553
+ }
554
+ async function pressKeysTool(args) {
555
+ const combos = parseKeySequence(args.keys);
556
+ const literal = '@(' + combos.map((combo) => ',@(' + combo.join(',') + ')').join(';') + ')';
557
+ await physical('Rk-Keys ' + literal);
558
+ return textContent('Pressed ' + args.keys + '.');
559
+ }
560
+ async function listWindowsTool() {
561
+ const rows = await shell.run('Rk-Windows');
562
+ const list = Array.isArray(rows) ? rows : [rows];
563
+ if (!list.length)
564
+ return textContent('No windows.');
565
+ return textContent(list
566
+ .map((w) => '- window=' + w.handle + ' ' + (w.active ? '[active] ' : '') + JSON.stringify(w.title) + ' (' + w.process + ') ' +
567
+ (w.minimized ? 'minimized' : w.width + 'x' + w.height + ' at ' + w.x + ',' + w.y))
568
+ .join('\n'));
569
+ }
570
+ async function focusWindowTool(args) {
571
+ view = null;
572
+ const result = await shell.run('Rk-Focus ' + psQuote(args.title ?? '') + ' ' + (args.window ?? 0));
573
+ return textContent('Focused ' + describeWindow(result) + '.');
574
+ }
575
+ async function openTool(args) {
576
+ view = null;
577
+ const result = await shell.run('Rk-Open ' + psQuote(args.target), WORKER_TIMEOUT_MS);
578
+ if (!result.changed) {
579
+ // Nothing to type into yet: say so as an error, so the model does not send input to whatever is in front.
580
+ throw new Error('Opened ' + args.target + ', but no window came to the front within 3 s' +
581
+ (result.behind ? ': ' + describeWindow(result.behind) + ' stayed behind ' : '; the active window is still ') + describeWindow(result.active) +
582
+ '. Nothing was typed. Use focus_window with the handle, or wait_for, then take a screenshot.');
583
+ }
584
+ return textContent('Opened ' + args.target + '. Active window is now ' + describeWindow(result.active) + '.');
585
+ }
586
+ async function clipboardTool(args) {
587
+ if (args.action === 'set') {
588
+ await shell.run('Rk-ClipSet ' + psQuote(args.text ?? ''));
589
+ return textContent('Clipboard set (' + args.text.length + ' characters).');
590
+ }
591
+ const result = await shell.run('Rk-ClipGet');
592
+ return textContent(result.text ? result.text.slice(0, CLIPBOARD_READ_LIMIT) : '(clipboard is empty)');
593
+ }
594
+ async function waitTool(args) {
595
+ await pause(args.ms);
596
+ return textContent('Waited ' + args.ms + ' ms.');
543
597
  }
544
598
  /* ------------------------------- MCP server ------------------------------- */
545
599
  function send(message) {
@@ -554,76 +608,84 @@ async function handle(message) {
554
608
  if (id === undefined)
555
609
  return;
556
610
  try {
557
- switch (method) {
558
- case 'initialize':
559
- send({
560
- id,
561
- result: {
562
- protocolVersion: params?.protocolVersion ?? PROTOCOL_FALLBACK,
563
- capabilities: { tools: {} },
564
- serverInfo: { name: COMPUTER_SERVER_NAME, version: '0.2.0' },
565
- },
566
- });
567
- return;
568
- case 'ping':
569
- send({ id, result: {} });
570
- return;
571
- case 'tools/list':
572
- send({ id, result: { tools: COMPUTER_TOOLS } });
573
- return;
574
- case 'tools/call': {
575
- const name = String(params?.name ?? '');
576
- const args = (params?.arguments ?? {});
577
- if (process.platform !== 'win32') {
578
- send({ id, result: { content: [{ type: 'text', text: 'Computer control is available on Windows only.' }], isError: true } });
579
- return;
580
- }
581
- pending.add(id);
582
- const execute = async () => {
583
- const started = performance.now();
584
- let failure;
585
- try {
586
- const content = await call(validateComputerCall(name, args, BACKGROUND));
587
- content.push({ type: 'text', text: JSON.stringify({ durationMs: Math.round(performance.now() - started), mode: BACKGROUND ? 'background' : 'desktop' }) });
588
- send({ id, result: { content, isError: false } });
589
- }
590
- catch (error) {
591
- failure = error.message;
592
- send({ id, result: { content: [{ type: 'text', text: failure }], isError: true } });
593
- }
594
- finally {
595
- pending.delete(id);
596
- if (RUN_DIR) {
597
- // The audit says which tool, how long, and why it failed; never what was typed or seen.
598
- const steps = name === 'batch' && Array.isArray(args.actions) ? args.actions.length : undefined;
599
- try {
600
- mkdirSync(RUN_DIR, { recursive: true });
601
- appendFileSync(join(RUN_DIR, 'computer-audit.jsonl'), JSON.stringify({
602
- at: new Date().toISOString(), session: process.pid, tool: name, ...(steps === undefined ? {} : { steps }),
603
- durationMs: Math.round(performance.now() - started), isError: failure !== undefined,
604
- ...(failure === undefined ? {} : { error: failure.split('\n')[0].replace(/"[^"]*"/g, '"…"').slice(0, 200) }),
605
- }) + '\n');
606
- }
607
- catch { /* Audit storage failure must not retry an already-dispatched action. */ }
608
- }
609
- }
610
- };
611
- if (name === 'stop')
612
- await execute();
613
- else {
614
- const task = queue.then(execute);
615
- queue = task.catch(() => undefined);
616
- await task;
617
- }
618
- return;
619
- }
620
- default:
621
- send({ id, error: { code: -32601, message: 'Method not found: ' + method } });
622
- }
611
+ await respond(id, method, params);
612
+ }
613
+ catch (error) {
614
+ send({ id, error: { code: JSONRPC_SERVER_ERROR, message: error.message } });
615
+ }
616
+ }
617
+ async function respond(id, method, params) {
618
+ switch (method) {
619
+ case 'initialize':
620
+ send({
621
+ id,
622
+ result: {
623
+ protocolVersion: params?.protocolVersion ?? PROTOCOL_FALLBACK,
624
+ capabilities: { tools: {} },
625
+ serverInfo: { name: COMPUTER_SERVER_NAME, version: SERVER_VERSION },
626
+ },
627
+ });
628
+ return;
629
+ case 'ping':
630
+ send({ id, result: {} });
631
+ return;
632
+ case 'tools/list':
633
+ send({ id, result: { tools: COMPUTER_TOOLS } });
634
+ return;
635
+ case 'tools/call':
636
+ await callTool(id, String(params?.name ?? ''), (params?.arguments ?? {}));
637
+ return;
638
+ default:
639
+ send({ id, error: { code: JSONRPC_METHOD_NOT_FOUND, message: 'Method not found: ' + method } });
640
+ }
641
+ }
642
+ async function callTool(id, name, args) {
643
+ if (process.platform !== 'win32') {
644
+ send({ id, result: { content: [{ type: 'text', text: 'Computer control is available on Windows only.' }], isError: true } });
645
+ return;
646
+ }
647
+ pending.add(id);
648
+ const execute = () => runTool(id, name, args);
649
+ // A stop must not wait behind the action it cancels.
650
+ if (name === 'stop') {
651
+ await execute();
652
+ return;
653
+ }
654
+ const task = queue.then(execute);
655
+ queue = task.catch(() => undefined);
656
+ await task;
657
+ }
658
+ /** Run one tool call and answer it, success or failure; the audit follows either way. */
659
+ async function runTool(id, name, args) {
660
+ const started = performance.now();
661
+ let failure;
662
+ try {
663
+ const content = await call(validateComputerCall(name, args, BACKGROUND));
664
+ content.push({ type: 'text', text: JSON.stringify({ durationMs: elapsedMs(started), mode: BACKGROUND ? 'background' : 'desktop' }) });
665
+ send({ id, result: { content, isError: false } });
623
666
  }
624
667
  catch (error) {
625
- send({ id, error: { code: -32000, message: error.message } });
668
+ failure = error.message;
669
+ send({ id, result: { content: [{ type: 'text', text: failure }], isError: true } });
670
+ }
671
+ finally {
672
+ pending.delete(id);
673
+ if (RUN_DIR)
674
+ audit(name, args, started, failure);
675
+ }
676
+ }
677
+ /** The audit says which tool, how long, and why it failed; never what was typed or seen. */
678
+ function audit(name, args, started, failure) {
679
+ const steps = name === 'batch' && Array.isArray(args.actions) ? args.actions.length : undefined;
680
+ try {
681
+ mkdirSync(RUN_DIR, { recursive: true });
682
+ appendFileSync(join(RUN_DIR, 'computer-audit.jsonl'), JSON.stringify({
683
+ at: new Date().toISOString(), session: process.pid, tool: name, ...(steps === undefined ? {} : { steps }),
684
+ durationMs: elapsedMs(started), isError: failure !== undefined,
685
+ ...(failure === undefined ? {} : { error: failure.split('\n')[0].replace(/"[^"]*"/g, '"…"').slice(0, AUDIT_ERROR_LENGTH) }),
686
+ }) + '\n');
626
687
  }
688
+ catch { /* Audit storage failure must not retry an already-dispatched action. */ }
627
689
  }
628
690
  const input = createInterface({ input: process.stdin });
629
691
  input.on('line', (line) => {
@@ -653,14 +715,14 @@ async function shutdown() {
653
715
  closing = true;
654
716
  if (shell.running) {
655
717
  await Promise.race([
656
- shell.run('Rk-CursorDismiss; @{}', 2000).catch(() => undefined),
657
- delay(700),
718
+ shell.run('Rk-CursorDismiss; @{}', CURSOR_DISMISS_TIMEOUT_MS).catch(() => undefined),
719
+ delay(CURSOR_FADE_BUDGET_MS),
658
720
  ]);
659
721
  }
660
722
  const held = inputInFlight > 0;
661
723
  shell.close();
662
724
  if (held)
663
- await releaseHeld(3000);
725
+ await releaseHeld(RELEASE_ON_EXIT_TIMEOUT_MS);
664
726
  shell.close();
665
727
  process.exit(0);
666
728
  }