@skillcdn/console 0.4.7 → 0.5.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 (599) hide show
  1. package/README.md +74 -14
  2. package/SKILLCDN.md +5 -3
  3. package/dist/agent-page.d.ts +44 -0
  4. package/dist/agent-page.d.ts.map +1 -0
  5. package/dist/agent-page.js +415 -0
  6. package/dist/agent-page.js.map +1 -0
  7. package/dist/agent-stream.d.ts +52 -0
  8. package/dist/agent-stream.d.ts.map +1 -0
  9. package/dist/agent-stream.js +155 -0
  10. package/dist/agent-stream.js.map +1 -0
  11. package/dist/api.d.ts +12 -6
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +11 -5
  14. package/dist/api.js.map +1 -1
  15. package/dist/avatar.d.ts +137 -0
  16. package/dist/avatar.d.ts.map +1 -0
  17. package/dist/avatar.js +1216 -0
  18. package/dist/avatar.js.map +1 -0
  19. package/dist/charts.d.ts +103 -0
  20. package/dist/charts.d.ts.map +1 -0
  21. package/dist/charts.js +182 -0
  22. package/dist/charts.js.map +1 -0
  23. package/dist/cli/cli.d.ts +39 -1
  24. package/dist/cli/cli.d.ts.map +1 -1
  25. package/dist/cli/cli.js +2424 -296
  26. package/dist/cli/cli.js.map +1 -1
  27. package/dist/cli/command-words.d.ts +20 -0
  28. package/dist/cli/command-words.d.ts.map +1 -0
  29. package/dist/cli/command-words.js +51 -0
  30. package/dist/cli/command-words.js.map +1 -0
  31. package/dist/cli/credentials.d.ts +59 -5
  32. package/dist/cli/credentials.d.ts.map +1 -1
  33. package/dist/cli/credentials.js +128 -16
  34. package/dist/cli/credentials.js.map +1 -1
  35. package/dist/cli/directory.d.ts +19 -4
  36. package/dist/cli/directory.d.ts.map +1 -1
  37. package/dist/cli/directory.js +16 -8
  38. package/dist/cli/directory.js.map +1 -1
  39. package/dist/cli/format.d.ts +91 -8
  40. package/dist/cli/format.d.ts.map +1 -1
  41. package/dist/cli/format.js +386 -57
  42. package/dist/cli/format.js.map +1 -1
  43. package/dist/cli/help.d.ts +13 -4
  44. package/dist/cli/help.d.ts.map +1 -1
  45. package/dist/cli/help.js +202 -62
  46. package/dist/cli/help.js.map +1 -1
  47. package/dist/cli/main.js +94 -0
  48. package/dist/cli/main.js.map +1 -1
  49. package/dist/cli/pack.d.ts +69 -36
  50. package/dist/cli/pack.d.ts.map +1 -1
  51. package/dist/cli/pack.js +241 -188
  52. package/dist/cli/pack.js.map +1 -1
  53. package/dist/cli/plugin-check.d.ts +42 -0
  54. package/dist/cli/plugin-check.d.ts.map +1 -1
  55. package/dist/cli/plugin-check.js +221 -36
  56. package/dist/cli/plugin-check.js.map +1 -1
  57. package/dist/cli/plugin-cli.d.ts +6 -1
  58. package/dist/cli/plugin-cli.d.ts.map +1 -1
  59. package/dist/cli/plugin-cli.js +21 -4
  60. package/dist/cli/plugin-cli.js.map +1 -1
  61. package/dist/cli/plugin-main.js +1 -0
  62. package/dist/cli/plugin-main.js.map +1 -1
  63. package/dist/cli/runner-host.d.ts +36 -0
  64. package/dist/cli/runner-host.d.ts.map +1 -0
  65. package/dist/cli/runner-host.js +154 -0
  66. package/dist/cli/runner-host.js.map +1 -0
  67. package/dist/cli/serve.d.ts +33 -1
  68. package/dist/cli/serve.d.ts.map +1 -1
  69. package/dist/cli/serve.js +275 -6
  70. package/dist/cli/serve.js.map +1 -1
  71. package/dist/cli/setup-machine.d.ts +36 -0
  72. package/dist/cli/setup-machine.d.ts.map +1 -0
  73. package/dist/cli/setup-machine.js +109 -0
  74. package/dist/cli/setup-machine.js.map +1 -0
  75. package/dist/client.d.ts +189 -10
  76. package/dist/client.d.ts.map +1 -1
  77. package/dist/client.js +192 -57
  78. package/dist/client.js.map +1 -1
  79. package/dist/compat.d.ts +1 -1
  80. package/dist/compat.js +2 -2
  81. package/dist/components/agent-page.d.ts +384 -0
  82. package/dist/components/agent-page.d.ts.map +1 -0
  83. package/dist/components/agent-page.js +985 -0
  84. package/dist/components/agent-page.js.map +1 -0
  85. package/dist/components/agents.d.ts +102 -0
  86. package/dist/components/agents.d.ts.map +1 -0
  87. package/dist/components/agents.js +246 -0
  88. package/dist/components/agents.js.map +1 -0
  89. package/dist/components/calendar.d.ts +17 -17
  90. package/dist/components/calendar.d.ts.map +1 -1
  91. package/dist/components/calendar.js +7 -2
  92. package/dist/components/calendar.js.map +1 -1
  93. package/dist/components/charts.d.ts +157 -0
  94. package/dist/components/charts.d.ts.map +1 -0
  95. package/dist/components/charts.js +182 -0
  96. package/dist/components/charts.js.map +1 -0
  97. package/dist/components/comments.d.ts +2 -0
  98. package/dist/components/comments.d.ts.map +1 -1
  99. package/dist/components/comments.js +1 -1
  100. package/dist/components/comments.js.map +1 -1
  101. package/dist/components/connect.d.ts.map +1 -1
  102. package/dist/components/connect.js +7 -2
  103. package/dist/components/connect.js.map +1 -1
  104. package/dist/components/decision-form.d.ts +21 -0
  105. package/dist/components/decision-form.d.ts.map +1 -1
  106. package/dist/components/decision-form.js +20 -6
  107. package/dist/components/decision-form.js.map +1 -1
  108. package/dist/components/decision-list.d.ts +24 -0
  109. package/dist/components/decision-list.d.ts.map +1 -1
  110. package/dist/components/decision-list.js +54 -5
  111. package/dist/components/decision-list.js.map +1 -1
  112. package/dist/components/desk-records.d.ts +102 -0
  113. package/dist/components/desk-records.d.ts.map +1 -0
  114. package/dist/components/desk-records.js +221 -0
  115. package/dist/components/desk-records.js.map +1 -0
  116. package/dist/components/desk.d.ts +85 -0
  117. package/dist/components/desk.d.ts.map +1 -0
  118. package/dist/components/desk.js +135 -0
  119. package/dist/components/desk.js.map +1 -0
  120. package/dist/components/event-feed.d.ts.map +1 -1
  121. package/dist/components/event-feed.js +26 -1
  122. package/dist/components/event-feed.js.map +1 -1
  123. package/dist/components/home.d.ts +12 -1
  124. package/dist/components/home.d.ts.map +1 -1
  125. package/dist/components/home.js +175 -16
  126. package/dist/components/home.js.map +1 -1
  127. package/dist/components/my-decisions.d.ts +5 -0
  128. package/dist/components/my-decisions.d.ts.map +1 -1
  129. package/dist/components/my-decisions.js +3 -3
  130. package/dist/components/my-decisions.js.map +1 -1
  131. package/dist/components/people.d.ts +17 -0
  132. package/dist/components/people.d.ts.map +1 -1
  133. package/dist/components/people.js +55 -19
  134. package/dist/components/people.js.map +1 -1
  135. package/dist/components/picker.d.ts +2 -0
  136. package/dist/components/picker.d.ts.map +1 -1
  137. package/dist/components/picker.js +1 -1
  138. package/dist/components/picker.js.map +1 -1
  139. package/dist/components/pictures.d.ts +38 -10
  140. package/dist/components/pictures.d.ts.map +1 -1
  141. package/dist/components/pictures.js +195 -40
  142. package/dist/components/pictures.js.map +1 -1
  143. package/dist/components/plugin-events.d.ts +29 -0
  144. package/dist/components/plugin-events.d.ts.map +1 -0
  145. package/dist/components/plugin-events.js +139 -0
  146. package/dist/components/plugin-events.js.map +1 -0
  147. package/dist/components/plugin-frame.d.ts.map +1 -1
  148. package/dist/components/plugin-frame.js +14 -37
  149. package/dist/components/plugin-frame.js.map +1 -1
  150. package/dist/components/plugin-settings.d.ts.map +1 -1
  151. package/dist/components/plugin-settings.js +58 -7
  152. package/dist/components/plugin-settings.js.map +1 -1
  153. package/dist/components/projects.d.ts.map +1 -1
  154. package/dist/components/projects.js +30 -10
  155. package/dist/components/projects.js.map +1 -1
  156. package/dist/components/rules.d.ts +8 -10
  157. package/dist/components/rules.d.ts.map +1 -1
  158. package/dist/components/rules.js +36 -14
  159. package/dist/components/rules.js.map +1 -1
  160. package/dist/components/sessions.d.ts.map +1 -1
  161. package/dist/components/sessions.js +8 -4
  162. package/dist/components/sessions.js.map +1 -1
  163. package/dist/components/setup.d.ts +59 -0
  164. package/dist/components/setup.d.ts.map +1 -0
  165. package/dist/components/setup.js +93 -0
  166. package/dist/components/setup.js.map +1 -0
  167. package/dist/components/sign-in.js +1 -1
  168. package/dist/components/sign-in.js.map +1 -1
  169. package/dist/components/task-form.d.ts.map +1 -1
  170. package/dist/components/task-form.js +2 -2
  171. package/dist/components/task-form.js.map +1 -1
  172. package/dist/components/task-list.d.ts +7 -6
  173. package/dist/components/task-list.d.ts.map +1 -1
  174. package/dist/components/task-list.js.map +1 -1
  175. package/dist/components/task-view.d.ts +3 -0
  176. package/dist/components/task-view.d.ts.map +1 -1
  177. package/dist/components/task-view.js +1 -1
  178. package/dist/components/task-view.js.map +1 -1
  179. package/dist/components/ui.d.ts +78 -8
  180. package/dist/components/ui.d.ts.map +1 -1
  181. package/dist/components/ui.js +88 -9
  182. package/dist/components/ui.js.map +1 -1
  183. package/dist/components/work.d.ts +5 -5
  184. package/dist/components/work.d.ts.map +1 -1
  185. package/dist/components/work.js.map +1 -1
  186. package/dist/components/workspace.d.ts +17 -0
  187. package/dist/components/workspace.d.ts.map +1 -1
  188. package/dist/components/workspace.js +129 -2
  189. package/dist/components/workspace.js.map +1 -1
  190. package/dist/connect-page.d.ts.map +1 -1
  191. package/dist/connect-page.js +5 -2
  192. package/dist/connect-page.js.map +1 -1
  193. package/dist/console.css +7551 -4580
  194. package/dist/console.d.ts +20 -0
  195. package/dist/console.d.ts.map +1 -1
  196. package/dist/console.js +331 -57
  197. package/dist/console.js.map +1 -1
  198. package/dist/data.d.ts +22 -1
  199. package/dist/data.d.ts.map +1 -1
  200. package/dist/data.js +62 -34
  201. package/dist/data.js.map +1 -1
  202. package/dist/desk-page.d.ts +38 -0
  203. package/dist/desk-page.d.ts.map +1 -0
  204. package/dist/desk-page.js +184 -0
  205. package/dist/desk-page.js.map +1 -0
  206. package/dist/desk-records-page.d.ts +18 -0
  207. package/dist/desk-records-page.d.ts.map +1 -0
  208. package/dist/desk-records-page.js +130 -0
  209. package/dist/desk-records-page.js.map +1 -0
  210. package/dist/desk-records.d.ts +247 -0
  211. package/dist/desk-records.d.ts.map +1 -0
  212. package/dist/desk-records.js +543 -0
  213. package/dist/desk-records.js.map +1 -0
  214. package/dist/desk.d.ts +122 -0
  215. package/dist/desk.d.ts.map +1 -0
  216. package/dist/desk.js +211 -0
  217. package/dist/desk.js.map +1 -0
  218. package/dist/feed-stream.d.ts +39 -0
  219. package/dist/feed-stream.d.ts.map +1 -0
  220. package/dist/feed-stream.js +117 -0
  221. package/dist/feed-stream.js.map +1 -0
  222. package/dist/glances.d.ts +39 -0
  223. package/dist/glances.d.ts.map +1 -0
  224. package/dist/glances.js +94 -0
  225. package/dist/glances.js.map +1 -0
  226. package/dist/home-tiles.d.ts +69 -5
  227. package/dist/home-tiles.d.ts.map +1 -1
  228. package/dist/home-tiles.js +347 -9
  229. package/dist/home-tiles.js.map +1 -1
  230. package/dist/i18n/en.d.ts +773 -3
  231. package/dist/i18n/en.d.ts.map +1 -1
  232. package/dist/i18n/en.js +770 -9
  233. package/dist/i18n/en.js.map +1 -1
  234. package/dist/i18n/ko.d.ts.map +1 -1
  235. package/dist/i18n/ko.js +736 -9
  236. package/dist/i18n/ko.js.map +1 -1
  237. package/dist/index.d.ts +19 -7
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +17 -5
  240. package/dist/index.js.map +1 -1
  241. package/dist/limits.d.ts +67 -0
  242. package/dist/limits.d.ts.map +1 -1
  243. package/dist/limits.js +67 -0
  244. package/dist/limits.js.map +1 -1
  245. package/dist/onboarding.d.ts +21 -0
  246. package/dist/onboarding.d.ts.map +1 -0
  247. package/dist/onboarding.js +43 -0
  248. package/dist/onboarding.js.map +1 -0
  249. package/dist/persona.d.ts +34 -0
  250. package/dist/persona.d.ts.map +1 -0
  251. package/dist/persona.js +71 -0
  252. package/dist/persona.js.map +1 -0
  253. package/dist/plugin/context.d.ts +42 -11
  254. package/dist/plugin/context.d.ts.map +1 -1
  255. package/dist/plugin/limits.d.ts +2 -0
  256. package/dist/plugin/limits.d.ts.map +1 -1
  257. package/dist/plugin/limits.js +2 -0
  258. package/dist/plugin/limits.js.map +1 -1
  259. package/dist/plugin/manifest.d.ts +13 -0
  260. package/dist/plugin/manifest.d.ts.map +1 -1
  261. package/dist/plugin/manifest.js +34 -4
  262. package/dist/plugin/manifest.js.map +1 -1
  263. package/dist/plugin/rest-schemas.d.ts +56 -0
  264. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  265. package/dist/plugin/rest-schemas.js +42 -0
  266. package/dist/plugin/rest-schemas.js.map +1 -1
  267. package/dist/plugin/sandbox.d.ts.map +1 -1
  268. package/dist/plugin/sandbox.js +4 -1
  269. package/dist/plugin/sandbox.js.map +1 -1
  270. package/dist/plugin/testing.d.ts +6 -2
  271. package/dist/plugin/testing.d.ts.map +1 -1
  272. package/dist/plugin/testing.js +52 -10
  273. package/dist/plugin/testing.js.map +1 -1
  274. package/dist/plugin.d.ts +1 -1
  275. package/dist/plugin.d.ts.map +1 -1
  276. package/dist/plugin.js +1 -1
  277. package/dist/plugin.js.map +1 -1
  278. package/dist/records.d.ts +283 -0
  279. package/dist/records.d.ts.map +1 -0
  280. package/dist/records.js +543 -0
  281. package/dist/records.js.map +1 -0
  282. package/dist/router.d.ts +50 -3
  283. package/dist/router.d.ts.map +1 -1
  284. package/dist/router.js +78 -7
  285. package/dist/router.js.map +1 -1
  286. package/dist/routes.d.ts +12 -2
  287. package/dist/routes.d.ts.map +1 -1
  288. package/dist/routes.js +14 -1
  289. package/dist/routes.js.map +1 -1
  290. package/dist/rules.d.ts +30 -11
  291. package/dist/rules.d.ts.map +1 -1
  292. package/dist/rules.js +99 -42
  293. package/dist/rules.js.map +1 -1
  294. package/dist/runner/acp.d.ts +20 -0
  295. package/dist/runner/acp.d.ts.map +1 -0
  296. package/dist/runner/acp.js +1132 -0
  297. package/dist/runner/acp.js.map +1 -0
  298. package/dist/runner/claude.d.ts +13 -0
  299. package/dist/runner/claude.d.ts.map +1 -0
  300. package/dist/runner/claude.js +615 -0
  301. package/dist/runner/claude.js.map +1 -0
  302. package/dist/runner/codex.d.ts +19 -0
  303. package/dist/runner/codex.d.ts.map +1 -0
  304. package/dist/runner/codex.js +597 -0
  305. package/dist/runner/codex.js.map +1 -0
  306. package/dist/runner/config.d.ts +35 -0
  307. package/dist/runner/config.d.ts.map +1 -0
  308. package/dist/runner/config.js +74 -0
  309. package/dist/runner/config.js.map +1 -0
  310. package/dist/runner/desk.d.ts +81 -0
  311. package/dist/runner/desk.d.ts.map +1 -0
  312. package/dist/runner/desk.js +303 -0
  313. package/dist/runner/desk.js.map +1 -0
  314. package/dist/runner/launchd.d.ts +7 -0
  315. package/dist/runner/launchd.d.ts.map +1 -0
  316. package/dist/runner/launchd.js +78 -0
  317. package/dist/runner/launchd.js.map +1 -0
  318. package/dist/runner/message.d.ts +66 -0
  319. package/dist/runner/message.d.ts.map +1 -0
  320. package/dist/runner/message.js +181 -0
  321. package/dist/runner/message.js.map +1 -0
  322. package/dist/runner/modules.d.ts +13 -0
  323. package/dist/runner/modules.d.ts.map +1 -0
  324. package/dist/runner/modules.js +30 -0
  325. package/dist/runner/modules.js.map +1 -0
  326. package/dist/runner/process.d.ts +7 -0
  327. package/dist/runner/process.d.ts.map +1 -0
  328. package/dist/runner/process.js +65 -0
  329. package/dist/runner/process.js.map +1 -0
  330. package/dist/runner/redact.d.ts +48 -0
  331. package/dist/runner/redact.d.ts.map +1 -0
  332. package/dist/runner/redact.js +214 -0
  333. package/dist/runner/redact.js.map +1 -0
  334. package/dist/runner/registry.d.ts +37 -0
  335. package/dist/runner/registry.d.ts.map +1 -0
  336. package/dist/runner/registry.js +26 -0
  337. package/dist/runner/registry.js.map +1 -0
  338. package/dist/runner/runner.d.ts +130 -0
  339. package/dist/runner/runner.d.ts.map +1 -0
  340. package/dist/runner/runner.js +1551 -0
  341. package/dist/runner/runner.js.map +1 -0
  342. package/dist/runner/slack.d.ts +16 -0
  343. package/dist/runner/slack.d.ts.map +1 -0
  344. package/dist/runner/slack.js +157 -0
  345. package/dist/runner/slack.js.map +1 -0
  346. package/dist/runner/systemd-user.d.ts +7 -0
  347. package/dist/runner/systemd-user.d.ts.map +1 -0
  348. package/dist/runner/systemd-user.js +93 -0
  349. package/dist/runner/systemd-user.js.map +1 -0
  350. package/dist/runner/task-scheduler.d.ts +38 -0
  351. package/dist/runner/task-scheduler.d.ts.map +1 -0
  352. package/dist/runner/task-scheduler.js +216 -0
  353. package/dist/runner/task-scheduler.js.map +1 -0
  354. package/dist/runner/types.d.ts +315 -0
  355. package/dist/runner/types.d.ts.map +1 -0
  356. package/dist/runner/types.js +24 -0
  357. package/dist/runner/types.js.map +1 -0
  358. package/dist/runner.d.ts +18 -0
  359. package/dist/runner.d.ts.map +1 -0
  360. package/dist/runner.js +20 -0
  361. package/dist/runner.js.map +1 -0
  362. package/dist/schemas.d.ts +6082 -1295
  363. package/dist/schemas.d.ts.map +1 -1
  364. package/dist/schemas.js +930 -31
  365. package/dist/schemas.js.map +1 -1
  366. package/dist/services.d.ts +110 -0
  367. package/dist/services.d.ts.map +1 -0
  368. package/dist/services.js +305 -0
  369. package/dist/services.js.map +1 -0
  370. package/dist/setup-guide.d.ts +64 -0
  371. package/dist/setup-guide.d.ts.map +1 -0
  372. package/dist/setup-guide.js +256 -0
  373. package/dist/setup-guide.js.map +1 -0
  374. package/dist/setup-page.d.ts +6 -0
  375. package/dist/setup-page.d.ts.map +1 -0
  376. package/dist/setup-page.js +29 -0
  377. package/dist/setup-page.js.map +1 -0
  378. package/dist/sse.d.ts +15 -0
  379. package/dist/sse.d.ts.map +1 -0
  380. package/dist/sse.js +73 -0
  381. package/dist/sse.js.map +1 -0
  382. package/dist/tab-title.d.ts +6 -0
  383. package/dist/tab-title.d.ts.map +1 -0
  384. package/dist/tab-title.js +22 -0
  385. package/dist/tab-title.js.map +1 -0
  386. package/dist/tokens.d.ts.map +1 -1
  387. package/dist/tokens.js +3 -0
  388. package/dist/tokens.js.map +1 -1
  389. package/dist/use-action.d.ts +5 -2
  390. package/dist/use-action.d.ts.map +1 -1
  391. package/dist/use-action.js +6 -1
  392. package/dist/use-action.js.map +1 -1
  393. package/dist/vocabulary.d.ts +84 -4
  394. package/dist/vocabulary.d.ts.map +1 -1
  395. package/dist/vocabulary.js +115 -3
  396. package/dist/vocabulary.js.map +1 -1
  397. package/docs/specs/cli.md +147 -41
  398. package/docs/specs/plugins.md +37 -27
  399. package/docs/specs/records.md +113 -0
  400. package/docs/specs/rest.md +155 -20
  401. package/docs/specs/runner.md +347 -0
  402. package/package.json +12 -3
  403. package/skills/building-a-console/SKILL.md +4 -4
  404. package/skills/building-a-console/references/configuring.md +1 -0
  405. package/skills/building-a-plugin/SKILL.md +7 -7
  406. package/skills/deploying-a-console/SKILL.md +4 -4
  407. package/skills/deploying-a-console/references/resources.md +48 -8
  408. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  409. package/skills/keeping-a-desk/SKILL.md +133 -0
  410. package/skills/keeping-a-desk/collections.md +96 -0
  411. package/skills/planning-the-board/SKILL.md +14 -18
  412. package/skills/planning-the-board/references/a-task.md +2 -2
  413. package/skills/planning-the-board/references/project-rules.md +13 -14
  414. package/skills/planning-the-board/references/setting-up.md +22 -9
  415. package/skills/running-an-agent/SKILL.md +107 -0
  416. package/skills/running-an-agent/references/slack-app.md +61 -0
  417. package/skills/working-the-board/SKILL.md +66 -39
  418. package/skills/working-the-board/references/terms.md +9 -5
  419. package/skills/working-the-board/references/the-pack.md +14 -9
  420. package/skills/working-the-board/references/the-sentence.md +2 -2
  421. package/src/agent-page.tsx +1039 -0
  422. package/src/agent-stream.ts +199 -0
  423. package/src/api.ts +317 -2
  424. package/src/avatar.ts +1506 -0
  425. package/src/charts.ts +250 -0
  426. package/src/cli/cli.ts +3210 -503
  427. package/src/cli/command-words.ts +56 -0
  428. package/src/cli/credentials.ts +188 -16
  429. package/src/cli/directory.ts +28 -10
  430. package/src/cli/format.ts +470 -67
  431. package/src/cli/help.ts +233 -61
  432. package/src/cli/main.ts +89 -0
  433. package/src/cli/pack.ts +332 -263
  434. package/src/cli/plugin-check.ts +275 -34
  435. package/src/cli/plugin-cli.ts +28 -4
  436. package/src/cli/plugin-main.ts +1 -0
  437. package/src/cli/runner-host.ts +188 -0
  438. package/src/cli/serve.ts +320 -5
  439. package/src/cli/setup-machine.ts +153 -0
  440. package/src/client.ts +711 -126
  441. package/src/compat.ts +2 -2
  442. package/src/components/agent-page.tsx +1946 -0
  443. package/src/components/agents.tsx +638 -0
  444. package/src/components/calendar.tsx +74 -53
  445. package/src/components/charts.tsx +680 -0
  446. package/src/components/comments.tsx +3 -0
  447. package/src/components/connect.tsx +37 -2
  448. package/src/components/decision-form.tsx +89 -51
  449. package/src/components/decision-list.tsx +140 -4
  450. package/src/components/desk-records.tsx +724 -0
  451. package/src/components/desk.tsx +471 -0
  452. package/src/components/event-feed.tsx +30 -1
  453. package/src/components/home.tsx +353 -12
  454. package/src/components/my-decisions.tsx +8 -2
  455. package/src/components/people.tsx +300 -203
  456. package/src/components/picker.tsx +3 -1
  457. package/src/components/pictures.tsx +256 -44
  458. package/src/components/plugin-events.ts +159 -0
  459. package/src/components/plugin-frame.tsx +14 -38
  460. package/src/components/plugin-settings.tsx +178 -22
  461. package/src/components/projects.tsx +33 -15
  462. package/src/components/rules.tsx +96 -36
  463. package/src/components/sessions.tsx +7 -4
  464. package/src/components/setup.tsx +252 -0
  465. package/src/components/sign-in.tsx +1 -1
  466. package/src/components/task-form.tsx +11 -2
  467. package/src/components/task-list.tsx +7 -6
  468. package/src/components/task-view.tsx +4 -0
  469. package/src/components/ui.tsx +169 -25
  470. package/src/components/work.tsx +9 -9
  471. package/src/components/workspace.tsx +345 -4
  472. package/src/connect-page.tsx +15 -2
  473. package/src/console.tsx +657 -83
  474. package/src/data.ts +109 -43
  475. package/src/desk-page.tsx +332 -0
  476. package/src/desk-records-page.tsx +256 -0
  477. package/src/desk-records.ts +808 -0
  478. package/src/desk.ts +329 -0
  479. package/src/feed-stream.ts +144 -0
  480. package/src/glances.ts +132 -0
  481. package/src/home-tiles.ts +411 -9
  482. package/src/i18n/en.ts +828 -10
  483. package/src/i18n/ko.ts +792 -10
  484. package/src/index.ts +172 -3
  485. package/src/limits.ts +67 -0
  486. package/src/onboarding.ts +84 -0
  487. package/src/persona.ts +100 -0
  488. package/src/plugin/context.ts +55 -12
  489. package/src/plugin/limits.ts +2 -0
  490. package/src/plugin/manifest.ts +42 -3
  491. package/src/plugin/rest-schemas.ts +46 -0
  492. package/src/plugin/sandbox.ts +4 -1
  493. package/src/plugin/testing.ts +63 -12
  494. package/src/plugin.ts +2 -0
  495. package/src/records.ts +702 -0
  496. package/src/router.ts +120 -10
  497. package/src/routes.ts +17 -1
  498. package/src/rules.ts +109 -44
  499. package/src/runner/acp.ts +1267 -0
  500. package/src/runner/claude.ts +695 -0
  501. package/src/runner/codex.ts +691 -0
  502. package/src/runner/config.ts +97 -0
  503. package/src/runner/desk.ts +377 -0
  504. package/src/runner/launchd.ts +86 -0
  505. package/src/runner/message.ts +232 -0
  506. package/src/runner/modules.ts +30 -0
  507. package/src/runner/process.ts +72 -0
  508. package/src/runner/redact.ts +242 -0
  509. package/src/runner/registry.ts +67 -0
  510. package/src/runner/runner.ts +1879 -0
  511. package/src/runner/slack.ts +180 -0
  512. package/src/runner/systemd-user.ts +103 -0
  513. package/src/runner/task-scheduler.ts +236 -0
  514. package/src/runner/types.ts +334 -0
  515. package/src/runner.ts +110 -0
  516. package/src/schemas.ts +1183 -30
  517. package/src/services.ts +424 -0
  518. package/src/setup-guide.ts +336 -0
  519. package/src/setup-page.tsx +46 -0
  520. package/src/sse.ts +84 -0
  521. package/src/styles/README.md +111 -0
  522. package/src/styles/base.css +130 -0
  523. package/src/styles/console.css +85 -7095
  524. package/src/styles/drawn-by-pages.json +256 -0
  525. package/src/styles/pages/agents.css +1195 -0
  526. package/src/styles/pages/board.css +380 -0
  527. package/src/styles/pages/calendar.css +214 -0
  528. package/src/styles/pages/connect.css +182 -0
  529. package/src/styles/pages/decisions.css +370 -0
  530. package/src/styles/pages/desk.css +126 -0
  531. package/src/styles/pages/documents.css +273 -0
  532. package/src/styles/pages/feed.css +118 -0
  533. package/src/styles/pages/home.css +718 -0
  534. package/src/styles/pages/people.css +90 -0
  535. package/src/styles/pages/plugins.css +212 -0
  536. package/src/styles/pages/roadmap.css +377 -0
  537. package/src/styles/pages/settings.css +171 -0
  538. package/src/styles/pages/shell.css +208 -0
  539. package/src/styles/pages/sign-in.css +178 -0
  540. package/src/styles/pages/task.css +108 -0
  541. package/src/styles/pages/thread.css +331 -0
  542. package/src/styles/pages/work.css +68 -0
  543. package/src/styles/parts/avatar.css +82 -0
  544. package/src/styles/parts/badge.css +227 -0
  545. package/src/styles/parts/bars.css +80 -0
  546. package/src/styles/parts/button.css +99 -0
  547. package/src/styles/parts/calendar.css +547 -0
  548. package/src/styles/parts/callout.css +41 -0
  549. package/src/styles/parts/category.css +8 -0
  550. package/src/styles/parts/chart.css +173 -0
  551. package/src/styles/parts/chip.css +90 -0
  552. package/src/styles/parts/code.css +48 -0
  553. package/src/styles/parts/count.css +27 -0
  554. package/src/styles/parts/crumbs.css +61 -0
  555. package/src/styles/parts/detail.css +110 -0
  556. package/src/styles/parts/empty.css +21 -0
  557. package/src/styles/parts/eyebrow.css +9 -0
  558. package/src/styles/parts/facts.css +147 -0
  559. package/src/styles/parts/figures.css +65 -0
  560. package/src/styles/parts/files.css +38 -0
  561. package/src/styles/parts/filters.css +42 -0
  562. package/src/styles/parts/form.css +109 -0
  563. package/src/styles/parts/frame.css +45 -0
  564. package/src/styles/parts/input.css +243 -0
  565. package/src/styles/parts/legend.css +48 -0
  566. package/src/styles/parts/links.css +37 -0
  567. package/src/styles/parts/mark.css +79 -0
  568. package/src/styles/parts/menu.css +147 -0
  569. package/src/styles/parts/page.css +174 -0
  570. package/src/styles/parts/pager.css +19 -0
  571. package/src/styles/parts/panel.css +33 -0
  572. package/src/styles/parts/person.css +257 -0
  573. package/src/styles/parts/picker.css +185 -0
  574. package/src/styles/parts/progress.css +25 -0
  575. package/src/styles/parts/prose.css +128 -0
  576. package/src/styles/parts/rows.css +63 -0
  577. package/src/styles/parts/series.css +32 -0
  578. package/src/styles/parts/settings.css +101 -0
  579. package/src/styles/parts/share.css +25 -0
  580. package/src/styles/parts/spark.css +23 -0
  581. package/src/styles/parts/spinner.css +29 -0
  582. package/src/styles/parts/stat.css +69 -0
  583. package/src/styles/parts/steps.css +68 -0
  584. package/src/styles/parts/tabs.css +175 -0
  585. package/src/styles/parts/text.css +61 -0
  586. package/src/styles/parts/toggle.css +71 -0
  587. package/src/styles/parts/workers.css +37 -0
  588. package/src/styles/tokens.css +295 -0
  589. package/src/tab-title.ts +25 -0
  590. package/src/tokens.ts +3 -0
  591. package/src/use-action.ts +7 -2
  592. package/src/vocabulary.ts +151 -3
  593. package/template/desk-web/README.md +8 -0
  594. package/template/desk-web/index.html +13 -0
  595. package/template/desk-web/package.json +25 -0
  596. package/template/desk-web/src/main.tsx +24 -0
  597. package/template/desk-web/src/page.tsx +51 -0
  598. package/template/desk-web/tsconfig.json +16 -0
  599. package/template/desk-web/vite.config.ts +15 -0
@@ -0,0 +1,1267 @@
1
+ import { MAX_FILE_BYTES } from "../limits.js";
2
+ import { TRANSCRIPT_PICTURE_TYPES } from "../vocabulary.js";
3
+ import type { DriverHost } from "./registry.js";
4
+ import {
5
+ type Child,
6
+ type Cut,
7
+ type Driver,
8
+ type DriverEvent,
9
+ type DriverMessage,
10
+ type DriverSession,
11
+ errorsShown,
12
+ type Fact,
13
+ type Picture,
14
+ type Probe,
15
+ plainCut,
16
+ plainCutEnd,
17
+ type StartOptions,
18
+ } from "./types.js";
19
+
20
+ // The driver for any product that speaks the Agent Client Protocol (ADR-0085): the product's
21
+ // command, which `runner.json` names, started once for a session and spoken to over its standard
22
+ // input and output, a JSON-RPC message a line. The runner is the protocol's client. It offers
23
+ // the agent no file and no terminal of its own, so the agent works with its own tools in the
24
+ // desk; it answers what the agent asks leave for, since nobody is at a terminal to ask; and it
25
+ // reads what the agent does as whole blocks, where the protocol sends a message in pieces.
26
+ // Written from the protocol's documentation, version 1, and read against the types the protocol
27
+ // publishes and the source of one agent that speaks it, and run against that agent since.
28
+
29
+ /** The protocol's version this driver speaks. */
30
+ const PROTOCOL_VERSION = 1;
31
+ /** How long a session that is stopped is given to end by itself, then after it was asked to. */
32
+ const STOP_GRACE_MS = 5000;
33
+ const KILL_GRACE_MS = 2000;
34
+ /** How long the product is given to say what it is and to open a session. */
35
+ const START_TIMEOUT_MS = 120_000;
36
+ /** How long it is given to say what it is and offers, asked without a session to run. */
37
+ const PROBE_TIMEOUT_MS = 30_000;
38
+ /**
39
+ * How long an agent is given to take a model or a level of effort in a running session. The
40
+ * runner handles one thing at a time: an agent that answers nothing while it works would hold
41
+ * every signal behind the choice, a stop among them.
42
+ */
43
+ const SET_TIMEOUT_MS = 5000;
44
+ /** The most of a tool's input that is shown. */
45
+ const MAX_INPUT_LENGTH = 4000;
46
+ /** The most that is shown of what a command printed while it ran, where an agent sends it in pieces. */
47
+ const MAX_PRINTED_LENGTH = 200_000;
48
+ /**
49
+ * How much more of it is kept than is shown: what is printed is cut once the account's secrets
50
+ * are out of it, and a secret that stands at the cut is whole only where what follows the cut
51
+ * was kept. More than the longest form a secret is looked for in.
52
+ */
53
+ const PRINTED_BEYOND = 64 * 1024;
54
+ /** The most that is shown of what an error carries beside its message. */
55
+ const MAX_DETAIL_LENGTH = 1000;
56
+ /** The protocol's code for a request the agent takes only once the product is signed in. */
57
+ const AUTH_REQUIRED = -32000;
58
+ /** The answer to a request for a method this client does not offer. */
59
+ const METHOD_NOT_FOUND = -32601;
60
+
61
+ /**
62
+ * What an error says when the product is not signed in. The products' words for it are their
63
+ * own: read by pattern, beside the protocol's own code for it.
64
+ */
65
+ const SIGN_IN =
66
+ /not (?:logged|signed) in|logged out|(?:log|sign) ?in (?:is )?required|authentication (?:is )?required|auth_required|invalid (?:x-)?api[- ]key|token (?:has )?expired|unauthorized/i;
67
+
68
+ /**
69
+ * What the runner answers where the agent asks leave for a tool call, in the driver's own two
70
+ * words. `allow` lets it, once each: a run nobody attends has nobody to ask, and an agent that
71
+ * is refused everything does no work. `deny` refuses each, for an agent that is to do only what
72
+ * its own mode lets it without asking. Beside the two, the desk may name one of the agent's own
73
+ * modes, which the protocol has a session say and set: the agent then runs in it, and what it
74
+ * still asks is refused, since the mode is what it may do with nobody there.
75
+ */
76
+ const MODES = ["allow", "deny"] as const;
77
+
78
+ /**
79
+ * The mode an agent has for a run nobody attends, by what the agent calls itself: the one in
80
+ * which it works without asking and asks leave only for what its own review holds back. The
81
+ * driver names it where the desk names none, as the other drivers name their product's, and
82
+ * refuses what the agent still asks. Seen with the adapters that put Codex and Claude Code
83
+ * behind the protocol, whose words for it are `agent` and `auto`. An agent the driver does not
84
+ * know runs in its own mode and is allowed what it asks: the desk names its mode for such a run.
85
+ */
86
+ const UNATTENDED_MODES: Readonly<Record<string, string>> = {
87
+ Codex: "agent",
88
+ "Claude Agent": "auto",
89
+ };
90
+
91
+ /**
92
+ * The agents the driver was run against, each by what it calls itself, with the versions it said
93
+ * of itself: the adapters that put Codex and Claude Code behind the protocol, each run on
94
+ * Windows with a real account.
95
+ */
96
+ const TRIED: Readonly<Record<string, readonly string[]>> = {
97
+ Codex: ["2.6.0"],
98
+ "Claude Agent": ["0.106.0"],
99
+ };
100
+ const UNATTENDED_MODE = "allow";
101
+ const LEAST_MODE = "deny";
102
+
103
+ /** The mode a session answers in: the one named where it is one of the two, the least where it is not, `allow` where none is named. */
104
+ export function acpMode(named: string | undefined): (typeof MODES)[number] {
105
+ if (named === undefined) {
106
+ return UNATTENDED_MODE;
107
+ }
108
+ return named === "allow" || named === "deny" ? named : LEAST_MODE;
109
+ }
110
+
111
+ const PICTURE_TYPES: ReadonlySet<string> = new Set(TRANSCRIPT_PICTURE_TYPES);
112
+ const EXTENSIONS: Readonly<Record<string, string>> = {
113
+ "image/png": "png",
114
+ "image/jpeg": "jpg",
115
+ "image/gif": "gif",
116
+ "image/webp": "webp",
117
+ };
118
+
119
+ type Json = Record<string, unknown>;
120
+ const isObject = (value: unknown): value is Json =>
121
+ typeof value === "object" && value !== null && !Array.isArray(value);
122
+ const textOf = (value: unknown): string | undefined =>
123
+ typeof value === "string" ? value : undefined;
124
+ const listOf = (value: unknown): readonly unknown[] => (Array.isArray(value) ? value : []);
125
+
126
+ const wait = (ms: number): Promise<"timeout"> =>
127
+ new Promise((resolve) => {
128
+ setTimeout(() => resolve("timeout"), ms).unref?.();
129
+ });
130
+
131
+ /**
132
+ * What an error carries beside its message, as words: an agent may say "Internal error" and put
133
+ * why under `data`, as text or as an object with a message of its own.
134
+ */
135
+ function detailOf(data: unknown, cut: Cut): string | undefined {
136
+ const words = isObject(data)
137
+ ? (textOf(data.message) ?? textOf(data.details) ?? textOf(data.error))
138
+ : textOf(data);
139
+ const detail = words?.trim();
140
+ return detail === undefined || detail.length === 0 ? undefined : cut(detail, MAX_DETAIL_LENGTH);
141
+ }
142
+
143
+ /** What a request was refused with, as the protocol says it: the message, with what it carries beside it. */
144
+ class RpcError extends Error {
145
+ readonly code: number;
146
+ constructor(code: number, message: string, data?: unknown, cut: Cut = plainCut) {
147
+ const detail = detailOf(data, cut);
148
+ super(detail === undefined || message.includes(detail) ? message : `${message}: ${detail}`);
149
+ this.code = code;
150
+ }
151
+ }
152
+
153
+ /** The two ends of the protocol on one process: requests with their answers, and what arrives unasked. */
154
+ interface Connection {
155
+ request(method: string, params: Json): Promise<unknown>;
156
+ notify(method: string, params: Json): Promise<void>;
157
+ /** Answers a request of the agent's. */
158
+ answer(id: unknown, result: Json): Promise<void>;
159
+ refuse(id: unknown, code: number, message: string): Promise<void>;
160
+ /** Reads the process to its end, handing over what the agent says and asks. */
161
+ read(on: {
162
+ notification(method: string, params: Json): void;
163
+ request(id: unknown, method: string, params: Json): void;
164
+ }): Promise<void>;
165
+ }
166
+
167
+ function connectionOf(child: Child, cut: Cut = plainCut): Connection {
168
+ let next = 0;
169
+ const pending = new Map<number, { resolve(value: unknown): void; reject(error: Error): void }>();
170
+ const write = (message: Json): Promise<void> =>
171
+ child.write(JSON.stringify({ jsonrpc: "2.0", ...message }));
172
+ return {
173
+ request(method, params) {
174
+ const id = next;
175
+ next += 1;
176
+ return new Promise((resolve, reject) => {
177
+ pending.set(id, { resolve, reject });
178
+ write({ id, method, params }).catch((error: unknown) => {
179
+ pending.delete(id);
180
+ reject(error instanceof Error ? error : new Error(String(error)));
181
+ });
182
+ });
183
+ },
184
+ notify: (method, params) => write({ method, params }),
185
+ answer: (id, result) => write({ id, result }),
186
+ refuse: (id, code, message) => write({ id, error: { code, message } }),
187
+ async read(on) {
188
+ try {
189
+ for await (const text of child.lines) {
190
+ if (text.trim().length === 0) {
191
+ continue;
192
+ }
193
+ let line: unknown;
194
+ try {
195
+ line = JSON.parse(text);
196
+ } catch {
197
+ // What is no message of the protocol is none of the runner's: a line a product
198
+ // printed beside it, say.
199
+ continue;
200
+ }
201
+ if (!isObject(line)) {
202
+ continue;
203
+ }
204
+ const method = textOf(line.method);
205
+ if (method !== undefined) {
206
+ const params = isObject(line.params) ? line.params : {};
207
+ if (line.id === undefined || line.id === null) {
208
+ on.notification(method, params);
209
+ } else {
210
+ on.request(line.id, method, params);
211
+ }
212
+ continue;
213
+ }
214
+ const waiting = typeof line.id === "number" ? pending.get(line.id) : undefined;
215
+ if (waiting === undefined || typeof line.id !== "number") {
216
+ continue;
217
+ }
218
+ pending.delete(line.id);
219
+ if (isObject(line.error)) {
220
+ waiting.reject(
221
+ new RpcError(
222
+ typeof line.error.code === "number" ? line.error.code : 0,
223
+ textOf(line.error.message) ?? "the request was refused",
224
+ line.error.data,
225
+ cut,
226
+ ),
227
+ );
228
+ } else {
229
+ waiting.resolve(line.result);
230
+ }
231
+ }
232
+ } catch {
233
+ // The output closed in the middle of a line: how the process ended says the rest.
234
+ }
235
+ // Nothing answers what was asked of a process that is gone.
236
+ for (const waiting of pending.values()) {
237
+ waiting.reject(new Error("the product's process ended"));
238
+ }
239
+ pending.clear();
240
+ },
241
+ };
242
+ }
243
+
244
+ /** What one of the product's choices is, as the protocol lists it: its id, what it stands at, and what it may be set to. */
245
+ interface Choice {
246
+ readonly id: string;
247
+ readonly current: string | null;
248
+ readonly values: readonly string[];
249
+ }
250
+
251
+ /** The choice of a category among a session's configuration: the model, or the level of thought. */
252
+ function choiceOf(options: unknown, category: string): Choice | undefined {
253
+ for (const option of listOf(options)) {
254
+ if (!isObject(option) || option.category !== category || option.type !== "select") {
255
+ continue;
256
+ }
257
+ const id = textOf(option.id);
258
+ if (id === undefined) {
259
+ continue;
260
+ }
261
+ const values: string[] = [];
262
+ for (const entry of listOf(option.options)) {
263
+ if (!isObject(entry)) {
264
+ continue;
265
+ }
266
+ // A flat list of values, or groups of them.
267
+ for (const one of Array.isArray(entry.options) ? entry.options : [entry]) {
268
+ const value = isObject(one) ? textOf(one.value) : undefined;
269
+ if (value !== undefined && value.length > 0 && value.length <= 200) {
270
+ values.push(value);
271
+ }
272
+ }
273
+ }
274
+ return { id, current: textOf(option.currentValue) ?? null, values: values.slice(0, 100) };
275
+ }
276
+ return undefined;
277
+ }
278
+
279
+ /** The agent's own modes, as a session says them: a choice of the category `mode`, or its modes. */
280
+ interface Standing {
281
+ readonly choice: Choice;
282
+ /** How one is set: as a choice of the session's configuration, or as the session's mode. */
283
+ readonly by: "option" | "mode";
284
+ }
285
+
286
+ function standingOf(opened: unknown): Standing | undefined {
287
+ if (!isObject(opened)) {
288
+ return undefined;
289
+ }
290
+ const configured = choiceOf(opened.configOptions, "mode");
291
+ if (configured !== undefined) {
292
+ return { choice: configured, by: "option" };
293
+ }
294
+ if (!isObject(opened.modes)) {
295
+ return undefined;
296
+ }
297
+ const values = listOf(opened.modes.availableModes)
298
+ .map((one) => (isObject(one) ? textOf(one.id) : undefined))
299
+ .filter((id): id is string => id !== undefined && id.length > 0 && id.length <= 200)
300
+ .slice(0, 100);
301
+ return values.length === 0
302
+ ? undefined
303
+ : {
304
+ choice: { id: "", current: textOf(opened.modes.currentModeId) ?? null, values },
305
+ by: "mode",
306
+ };
307
+ }
308
+
309
+ /** A tool's input as a person reads it: the command of a shell, the path of a file, or the input whole and bounded. */
310
+ function inputOf(input: unknown, cut: Cut): string {
311
+ if (input === undefined || input === null) {
312
+ return "";
313
+ }
314
+ if (isObject(input)) {
315
+ // An input with nothing in it yet is none: an agent may open a call before it is whole.
316
+ if (Object.keys(input).length === 0) {
317
+ return "";
318
+ }
319
+ const line =
320
+ textOf(input.command) ??
321
+ textOf(input.file_path) ??
322
+ textOf(input.path) ??
323
+ textOf(input.abs_path);
324
+ if (line !== undefined && Object.keys(input).length <= 3) {
325
+ return line;
326
+ }
327
+ }
328
+ let whole: string;
329
+ try {
330
+ whole = typeof input === "string" ? input : (JSON.stringify(input) ?? "");
331
+ } catch {
332
+ whole = "";
333
+ }
334
+ return cut(whole, MAX_INPUT_LENGTH);
335
+ }
336
+
337
+ /** The text and the pictures of what a tool call holds: blocks of content, a change to a file, a terminal. */
338
+ function contentOf(
339
+ content: unknown,
340
+ name: string,
341
+ ): { readonly text: string; readonly pictures: Picture[] } {
342
+ const texts: string[] = [];
343
+ const pictures: Picture[] = [];
344
+ for (const item of listOf(content)) {
345
+ if (!isObject(item)) {
346
+ continue;
347
+ }
348
+ if (item.type === "diff") {
349
+ const path = textOf(item.path) ?? "a file";
350
+ // What became of the file: as the agent says it beside the protocol where it does, read
351
+ // from the text before where it does not. A file changed in several places is said once.
352
+ const said = isObject(item._meta) ? textOf(item._meta.kind) : undefined;
353
+ const fresh = item.oldText === null || item.oldText === undefined;
354
+ const what =
355
+ said === "delete"
356
+ ? "Removed"
357
+ : said === "add" || (said === undefined && fresh)
358
+ ? "Wrote"
359
+ : "Changed";
360
+ if (!texts.includes(`${what} ${path}`)) {
361
+ texts.push(`${what} ${path}`);
362
+ }
363
+ continue;
364
+ }
365
+ if (item.type !== "content" || !isObject(item.content)) {
366
+ continue;
367
+ }
368
+ const block = item.content;
369
+ if (block.type === "text" && typeof block.text === "string") {
370
+ texts.push(block.text);
371
+ } else if (block.type === "image") {
372
+ const type = textOf(block.mimeType) ?? "";
373
+ const data = textOf(block.data);
374
+ // A picture of a kind a transcript keeps, within the bound on a file; anything else is said and left.
375
+ if (
376
+ data !== undefined &&
377
+ PICTURE_TYPES.has(type) &&
378
+ data.length <= Math.ceil((MAX_FILE_BYTES * 4) / 3) + 4
379
+ ) {
380
+ const bytes = Buffer.from(data, "base64");
381
+ if (bytes.byteLength > 0 && bytes.byteLength <= MAX_FILE_BYTES) {
382
+ pictures.push({
383
+ name: `${name}-${pictures.length + 1}.${EXTENSIONS[type] ?? "png"}`,
384
+ contentType: type,
385
+ bytes,
386
+ });
387
+ continue;
388
+ }
389
+ }
390
+ texts.push("[a picture the transcript does not keep]");
391
+ } else if (block.type === "resource_link") {
392
+ texts.push(textOf(block.uri) ?? "");
393
+ }
394
+ }
395
+ return { text: texts.filter((text) => text.length > 0).join("\n"), pictures };
396
+ }
397
+
398
+ /** What the agent says it is: its name as people read it, and its version. */
399
+ function agentOf(initialized: unknown): { name: string | undefined; version: string | undefined } {
400
+ const info =
401
+ isObject(initialized) && isObject(initialized.agentInfo) ? initialized.agentInfo : {};
402
+ const short = (value: unknown): string | undefined => {
403
+ const text = textOf(value)?.trim();
404
+ return text === undefined || text.length === 0 ? undefined : text.slice(0, 80);
405
+ };
406
+ return { name: short(info.title) ?? short(info.name), version: short(info.version) };
407
+ }
408
+
409
+ /** What the runner says of itself when it begins: no file and no terminal of its own, so that the agent works with its own tools. */
410
+ const hello = (version: string | undefined): Json => ({
411
+ protocolVersion: PROTOCOL_VERSION,
412
+ // What the agent has to tell beside its work, a warning say, is taken as a notice: an agent
413
+ // that is offered none says it as its own words, in the middle of its answer.
414
+ clientCapabilities: {
415
+ fs: { readTextFile: false, writeTextFile: false },
416
+ terminal: false,
417
+ session: { notices: {} },
418
+ },
419
+ // The protocol has a client say its version: the command's, or none that it knows.
420
+ clientInfo: {
421
+ name: "skillcdn-console-runner",
422
+ title: "SkillCDN Console runner",
423
+ version: version ?? "0.0.0",
424
+ },
425
+ });
426
+
427
+ /** Ends a process: its input closed first, then asked, then made to. */
428
+ async function endOf(child: Child): Promise<void> {
429
+ child.end();
430
+ if ((await Promise.race([child.exited, wait(STOP_GRACE_MS)])) === "timeout") {
431
+ child.kill("SIGTERM");
432
+ if ((await Promise.race([child.exited, wait(KILL_GRACE_MS)])) === "timeout") {
433
+ child.kill("SIGKILL");
434
+ }
435
+ }
436
+ }
437
+
438
+ function sessionOf(
439
+ child: Child,
440
+ options: StartOptions,
441
+ /** The version of the command the runner is, said to the product. */
442
+ own: string | undefined,
443
+ /** How long a choice set in the running session is waited for. */
444
+ setMs: number = SET_TIMEOUT_MS,
445
+ ): DriverSession {
446
+ /** What cuts a text to what is shown of it: the runner's, which takes the account's secrets out first. */
447
+ const cut = options.cut ?? plainCut;
448
+ const connection = connectionOf(child, cut);
449
+ /** How what the agent asks leave for is answered: settled once the session says its modes. */
450
+ let mode = acpMode(options.permissions);
451
+
452
+ // What the session says, in order, for whoever reads it: until it ends.
453
+ const said: DriverEvent[] = [];
454
+ let reader: (() => void) | undefined;
455
+ /**
456
+ * The tool calls under way, by id: what each is called and was called with, what it holds so
457
+ * far, what its command printed, and whether it and its end were said.
458
+ */
459
+ const calls = new Map<
460
+ string,
461
+ {
462
+ tool: string;
463
+ title: string;
464
+ input: string;
465
+ said: boolean;
466
+ done: boolean;
467
+ content: unknown;
468
+ raw: unknown;
469
+ printed: string;
470
+ }
471
+ >();
472
+ /**
473
+ * The calls that began and are not said yet, in order: an agent may open a call before what
474
+ * it is called with is whole, and say that in an update. A call is said once its input is
475
+ * known, and before anything else is, so that the transcript keeps the order of what happened.
476
+ */
477
+ const held: string[] = [];
478
+ const emit = (...events: DriverEvent[]): void => {
479
+ for (const id of held.splice(0)) {
480
+ const call = calls.get(id);
481
+ if (call === undefined || call.said) {
482
+ continue;
483
+ }
484
+ call.said = true;
485
+ said.push({
486
+ type: "event",
487
+ kind: "tool_call",
488
+ text:
489
+ call.input.length === 0 || call.title.includes(call.input)
490
+ ? call.title
491
+ : `${call.title}\n${call.input}`.trim(),
492
+ data: { tool: call.tool, id },
493
+ });
494
+ }
495
+ said.push(...events);
496
+ reader?.();
497
+ reader = undefined;
498
+ };
499
+ async function* events(): AsyncGenerator<DriverEvent> {
500
+ for (;;) {
501
+ const next = said.shift();
502
+ if (next === undefined) {
503
+ await new Promise<void>((resolve) => {
504
+ reader = resolve;
505
+ });
506
+ continue;
507
+ }
508
+ yield next;
509
+ if (next.type === "ended") {
510
+ return;
511
+ }
512
+ }
513
+ }
514
+
515
+ let stopping = false;
516
+ /** Whether the product answered at all: a process that ends before is one that did not start. */
517
+ let began = false;
518
+ /** Whether the session cannot go on, as was said: nothing more is said of how the process ends. */
519
+ let gaveUp = false;
520
+ let session: string | undefined;
521
+ let takesImages = false;
522
+ /** Whether the agent has said what it takes: before that, nothing is known of pictures. */
523
+ let saidWhatItTakes = false;
524
+ let model: Choice | undefined;
525
+ let effort: Choice | undefined;
526
+ /** The agent's version, and what the session was last said to run with. */
527
+ let product: string | null = null;
528
+ let ran: { model: string | null; effort: string | null } | undefined;
529
+ /**
530
+ * Says what the session runs with, where that is not what was said last: when it opens, when
531
+ * a choice is taken in it, and when the agent changes one itself. The runner tells the
532
+ * console from it, so a choice that is taken and not said stays the old one on every page.
533
+ */
534
+ const runs = (): void => {
535
+ const now = { model: model?.current ?? null, effort: effort?.current ?? null };
536
+ if (ran !== undefined && ran.model === now.model && ran.effort === now.effort) {
537
+ return;
538
+ }
539
+ ran = now;
540
+ emit({ type: "running", ...now, version: product });
541
+ };
542
+ /** While a conversation is loaded, what the agent replays of it is none of this session's. */
543
+ let replaying = false;
544
+ /** The turn under way: why it was stopped where it was, and whether the agent was refused leave in it. */
545
+ let turn: { cut: "message" | "stopped" | undefined; refused: boolean } | undefined;
546
+ /** The messages that wait for the session to open, or for the turn under way to end. */
547
+ let waiting: DriverMessage[] = [];
548
+ let ready = false;
549
+ let results = 0;
550
+
551
+ /** What the agent says in pieces, kept until it is whole: a block of the transcript. */
552
+ let piece: { kind: "assistant" | "thinking"; text: string } | undefined;
553
+ const flush = (): void => {
554
+ // A block is its words: an agent may begin one with empty lines, which are none of it.
555
+ const words = piece?.text.trim() ?? "";
556
+ if (piece !== undefined && words.length > 0) {
557
+ emit({ type: "event", kind: piece.kind, text: words });
558
+ }
559
+ piece = undefined;
560
+ };
561
+ const chunk = (kind: "assistant" | "thinking", content: unknown): void => {
562
+ const text = isObject(content) && content.type === "text" ? textOf(content.text) : undefined;
563
+ if (text === undefined) {
564
+ return;
565
+ }
566
+ if (piece !== undefined && piece.kind !== kind) {
567
+ flush();
568
+ }
569
+ piece = { kind, text: `${piece?.text ?? ""}${text}` };
570
+ };
571
+
572
+ const toolUpdate = (update: Json, first: boolean): void => {
573
+ const id = textOf(update.toolCallId);
574
+ if (id === undefined) {
575
+ return;
576
+ }
577
+ let call = calls.get(id);
578
+ // A call opened under an id whose call is done is another call: an agent that numbers its
579
+ // calls anew at every turn has each of them on the record.
580
+ if (first && call?.done === true) {
581
+ call = undefined;
582
+ }
583
+ const known = call !== undefined;
584
+ if (call === undefined) {
585
+ call = {
586
+ tool: textOf(update.name) ?? textOf(update.kind) ?? "tool",
587
+ title: "",
588
+ input: "",
589
+ said: false,
590
+ done: false,
591
+ content: undefined,
592
+ raw: undefined,
593
+ printed: "",
594
+ };
595
+ calls.set(id, call);
596
+ flush();
597
+ held.push(id);
598
+ }
599
+ if (!call.said && !(known && first)) {
600
+ // What a call is called, and was called with, as it was said last before the call is.
601
+ call.title = textOf(update.title) ?? call.title;
602
+ const input = inputOf(update.rawInput, cut);
603
+ if (input.length > 0) {
604
+ call.input = input;
605
+ }
606
+ // Said once its input is known, or at the next thing said of it: a call may have none.
607
+ if (call.input.length > 0 || known) {
608
+ emit();
609
+ }
610
+ }
611
+ if ((known && first) || call.done) {
612
+ return;
613
+ }
614
+ // An update says what changed and leaves the rest as it was: what a call holds is what was
615
+ // said of it last, when it began or since.
616
+ if (update.content !== undefined && update.content !== null) {
617
+ call.content = update.content;
618
+ }
619
+ if (update.rawOutput !== undefined && update.rawOutput !== null) {
620
+ call.raw = update.rawOutput;
621
+ }
622
+ // Beside the protocol, an agent may send what a command prints while it runs: whole, or a
623
+ // piece at a time. It is the call's result where the call holds no text of its own.
624
+ const beside = isObject(update._meta) ? update._meta : {};
625
+ const whole = isObject(beside.terminal_output)
626
+ ? textOf(beside.terminal_output.data)
627
+ : undefined;
628
+ const more = isObject(beside.terminal_output_delta)
629
+ ? textOf(beside.terminal_output_delta.data)
630
+ : undefined;
631
+ if (whole !== undefined) {
632
+ call.printed = whole.slice(0, MAX_PRINTED_LENGTH + PRINTED_BEYOND);
633
+ } else if (more !== undefined && call.printed.length < MAX_PRINTED_LENGTH + PRINTED_BEYOND) {
634
+ call.printed = `${call.printed}${more}`.slice(0, MAX_PRINTED_LENGTH + PRINTED_BEYOND);
635
+ }
636
+ const status = textOf(update.status);
637
+ if (status === "completed" || status === "failed") {
638
+ call.done = true;
639
+ flush();
640
+ results += 1;
641
+ const result = contentOf(call.content, `tool-${results}`);
642
+ const output =
643
+ result.text.length > 0
644
+ ? result.text
645
+ : call.printed.trim().length > 0
646
+ ? cut(
647
+ call.printed,
648
+ MAX_PRINTED_LENGTH,
649
+ // Kept to its bound: what was printed went on, and its end here may begin a secret.
650
+ call.printed.length >= MAX_PRINTED_LENGTH + PRINTED_BEYOND,
651
+ )
652
+ : inputOf(call.raw, cut);
653
+ // Nothing more is read of a call that ended.
654
+ call.content = undefined;
655
+ call.raw = undefined;
656
+ call.printed = "";
657
+ emit({
658
+ type: "event",
659
+ kind: "tool_result",
660
+ text: output,
661
+ data: { id, error: status === "failed" },
662
+ pictures: result.pictures,
663
+ });
664
+ }
665
+ };
666
+
667
+ const onUpdate = (params: Json): void => {
668
+ if (replaying || !isObject(params.update)) {
669
+ return;
670
+ }
671
+ const update = params.update;
672
+ switch (update.sessionUpdate) {
673
+ case "agent_message_chunk":
674
+ chunk("assistant", update.content);
675
+ return;
676
+ case "agent_thought_chunk":
677
+ chunk("thinking", update.content);
678
+ return;
679
+ case "tool_call":
680
+ toolUpdate(update, true);
681
+ return;
682
+ case "tool_call_update":
683
+ toolUpdate(update, false);
684
+ return;
685
+ case "plan": {
686
+ flush();
687
+ const lines = listOf(update.entries)
688
+ .filter(isObject)
689
+ .map(
690
+ (entry) => `- [${textOf(entry.status) ?? "pending"}] ${textOf(entry.content) ?? ""}`,
691
+ );
692
+ if (lines.length > 0) {
693
+ emit({ type: "event", kind: "status", text: `Plan:\n${lines.join("\n")}` });
694
+ }
695
+ return;
696
+ }
697
+ case "notice": {
698
+ // What the agent tells beside its work: an error as one, anything else as a status.
699
+ const title = textOf(update.title)?.trim() ?? "";
700
+ const more = textOf(update.description)?.trim() ?? "";
701
+ const words = [title, more].filter((one) => one.length > 0).join("\n");
702
+ if (words.length > 0) {
703
+ flush();
704
+ emit({
705
+ type: "event",
706
+ kind: update.severity === "error" ? "error" : "status",
707
+ text: cut(words, MAX_INPUT_LENGTH),
708
+ });
709
+ }
710
+ return;
711
+ }
712
+ case "config_option_update":
713
+ model = choiceOf(update.configOptions, "model") ?? model;
714
+ effort = choiceOf(update.configOptions, "thought_level") ?? effort;
715
+ runs();
716
+ return;
717
+ default:
718
+ // What the client was not asked to keep: the commands the agent offers, its mode, how
719
+ // much it used, what a person typed, said back.
720
+ return;
721
+ }
722
+ };
723
+
724
+ const onRequest = (id: unknown, method: string, params: Json): void => {
725
+ if (method !== "session/request_permission") {
726
+ // No file and no terminal were offered: an agent that asks for one all the same is told.
727
+ void connection
728
+ .refuse(id, METHOD_NOT_FOUND, `${method} is not offered`)
729
+ .catch(() => undefined);
730
+ return;
731
+ }
732
+ const call = isObject(params.toolCall) ? params.toolCall : {};
733
+ const callId = textOf(call.toolCallId);
734
+ const known = callId === undefined ? undefined : calls.get(callId);
735
+ const title = textOf(call.title) ?? known?.tool ?? "a tool call";
736
+ const kinds =
737
+ mode === "allow" ? ["allow_once", "allow_always"] : ["reject_once", "reject_always"];
738
+ const options = listOf(params.options).filter(isObject);
739
+ const option = kinds
740
+ .map((kind) => options.find((one) => one.kind === kind))
741
+ .find((one) => one !== undefined && typeof one.optionId === "string");
742
+ const data: Record<string, Fact> = {
743
+ tool: known?.tool ?? textOf(call.kind) ?? "tool",
744
+ answer: option === undefined ? "cancelled" : mode === "allow" ? "allowed" : "denied",
745
+ };
746
+ if (callId !== undefined) {
747
+ data.id = callId;
748
+ }
749
+ if (turn !== undefined && data.answer !== "allowed") {
750
+ turn.refused = true;
751
+ }
752
+ flush();
753
+ emit({
754
+ type: "event",
755
+ kind: "permission",
756
+ text:
757
+ option === undefined
758
+ ? `Not answered, the agent offered no way to ${mode === "allow" ? "allow" : "refuse"} it: ${title}`
759
+ : mode === "allow"
760
+ ? `Allowed, with nobody at the terminal to ask: ${title}`
761
+ : `Denied, with nobody at the terminal to ask: ${title}`,
762
+ data,
763
+ });
764
+ void connection
765
+ .answer(id, {
766
+ outcome:
767
+ option === undefined
768
+ ? { outcome: "cancelled" }
769
+ : { outcome: "selected", optionId: option.optionId },
770
+ })
771
+ .catch(() => undefined);
772
+ };
773
+
774
+ /**
775
+ * Sets one of the product's choices; whether it took it. Nothing asked is taken. Within
776
+ * `within` where one is given: an answer that comes later is not waited for, and the choice
777
+ * counts as not taken, which the runner then gives the next session.
778
+ */
779
+ const choose = async (
780
+ choice: Choice | undefined,
781
+ value: string | null | undefined,
782
+ within?: number,
783
+ ): Promise<boolean> => {
784
+ if (value === undefined || value === null) {
785
+ return true;
786
+ }
787
+ if (session === undefined || choice === undefined || !choice.values.includes(value)) {
788
+ return false;
789
+ }
790
+ if (choice.current === value) {
791
+ return true;
792
+ }
793
+ try {
794
+ const asked = connection.request("session/set_config_option", {
795
+ sessionId: session,
796
+ configId: choice.id,
797
+ value,
798
+ });
799
+ const result = within === undefined ? await asked : await Promise.race([asked, wait(within)]);
800
+ if (result === "timeout") {
801
+ return false;
802
+ }
803
+ const options = isObject(result) ? result.configOptions : undefined;
804
+ model = choiceOf(options, "model") ?? model;
805
+ effort = choiceOf(options, "thought_level") ?? effort;
806
+ return true;
807
+ } catch {
808
+ return false;
809
+ }
810
+ };
811
+
812
+ /**
813
+ * How the session stands to what the agent may do. The driver's own two words leave the
814
+ * agent's mode as it is. A mode of the agent's own, the one the desk names or, where it names
815
+ * none, the one the agent has for a run nobody attends, is set, and what the agent still asks
816
+ * is refused. A mode named that the agent does not offer is a mistake in the desk's file, and
817
+ * is never read as leave to do more.
818
+ */
819
+ const stand = async (
820
+ standing: Standing | undefined,
821
+ agent: string | undefined,
822
+ ): Promise<void> => {
823
+ const named = options.permissions;
824
+ if (named === "allow" || named === "deny") {
825
+ return;
826
+ }
827
+ const wanted = named ?? (agent === undefined ? undefined : UNATTENDED_MODES[agent]);
828
+ if (wanted === undefined) {
829
+ return;
830
+ }
831
+ const offered = standing?.choice.values ?? [];
832
+ if (standing === undefined || !offered.includes(wanted)) {
833
+ if (named !== undefined) {
834
+ emit({
835
+ type: "event",
836
+ kind: "status",
837
+ text: `runner.json names the mode ${named}, which this agent does not offer${offered.length === 0 ? "" : ` (it offers ${offered.join(", ")})`}: it runs in its own, and what it asks leave for is refused.`,
838
+ });
839
+ }
840
+ return;
841
+ }
842
+ mode = "deny";
843
+ if (standing.choice.current === wanted) {
844
+ return;
845
+ }
846
+ try {
847
+ if (standing.by === "option") {
848
+ await connection.request("session/set_config_option", {
849
+ sessionId: session ?? "",
850
+ configId: standing.choice.id,
851
+ value: wanted,
852
+ });
853
+ } else {
854
+ await connection.request("session/set_mode", { sessionId: session ?? "", modeId: wanted });
855
+ }
856
+ } catch (error) {
857
+ emit({
858
+ type: "event",
859
+ kind: "status",
860
+ text: `The agent did not take the mode ${wanted}${error instanceof Error ? ` (${error.message})` : ""}: it runs in its own, and what it asks leave for is refused.`,
861
+ });
862
+ }
863
+ };
864
+
865
+ /** One turn: what arrived together is read together, each under its own header. */
866
+ const prompt = (messages: readonly DriverMessage[]): void => {
867
+ const mine: NonNullable<typeof turn> = { cut: undefined, refused: false };
868
+ turn = mine;
869
+ // A turn's messages are the agent's once it is prompted with them: said once for each.
870
+ emit(...messages.map((): DriverEvent => ({ type: "taken" })));
871
+ const blocks: Json[] = [];
872
+ for (const message of messages) {
873
+ const left = takesImages ? [] : message.images;
874
+ // Where the runner did not know yet that this agent takes no picture, the message says a
875
+ // picture was shown: said here that it was not, with where it is in the desk.
876
+ const where = left.flatMap((image) => (image.path === undefined ? [] : [image.path]));
877
+ blocks.push({
878
+ type: "text",
879
+ text:
880
+ left.length === 0
881
+ ? message.text
882
+ : `${message.text}\n\n(${left.length} picture${left.length === 1 ? "" : "s"} came with this and ${left.length === 1 ? "was" : "were"} not shown to you: this agent takes none as a picture.${where.length === 0 ? "" : ` Open ${where.join(", ")}.`})`,
883
+ });
884
+ for (const image of takesImages ? message.images : []) {
885
+ blocks.push({
886
+ type: "image",
887
+ mimeType: image.contentType,
888
+ data: Buffer.from(image.bytes).toString("base64"),
889
+ });
890
+ }
891
+ }
892
+ void (async () => {
893
+ let reason: string | undefined;
894
+ let failure: unknown;
895
+ try {
896
+ const result = await connection.request("session/prompt", {
897
+ sessionId: session ?? "",
898
+ prompt: blocks,
899
+ });
900
+ reason = isObject(result) ? textOf(result.stopReason) : undefined;
901
+ } catch (error) {
902
+ failure = error;
903
+ }
904
+ flush();
905
+ turn = undefined;
906
+ if (gaveUp) {
907
+ return;
908
+ }
909
+ if (failure !== undefined) {
910
+ const words = failure instanceof Error ? failure.message : String(failure);
911
+ if (failure instanceof RpcError) {
912
+ emit({ type: "event", kind: "error", text: `The agent refused the turn: ${words}` });
913
+ if (failure.code === AUTH_REQUIRED || SIGN_IN.test(words)) {
914
+ gaveUp = true;
915
+ waiting = [];
916
+ emit({ type: "cannot_go_on", state: "failed", reason: "sign_in" });
917
+ return;
918
+ }
919
+ // A turn the agent itself said failed is a turn that ended: it takes the next message.
920
+ } else {
921
+ // The process is gone: how it ended is said where its output ends.
922
+ return;
923
+ }
924
+ } else if (reason === "refusal") {
925
+ gaveUp = true;
926
+ waiting = [];
927
+ emit(
928
+ { type: "event", kind: "error", text: "The model refused to answer." },
929
+ { type: "cannot_go_on", state: "refused", reason: "model_refused" },
930
+ );
931
+ return;
932
+ } else if (reason === "cancelled" || mine.cut !== undefined) {
933
+ emit({
934
+ type: "event",
935
+ kind: "status",
936
+ // An agent may end its turn where it is refused leave: nobody stopped that one.
937
+ text:
938
+ mine.cut === "message"
939
+ ? "The turn was stopped for a message."
940
+ : mine.cut === undefined && mine.refused
941
+ ? "The agent ended the turn where it was refused leave."
942
+ : "The turn was stopped.",
943
+ });
944
+ } else if (reason === "max_tokens" || reason === "max_turn_requests") {
945
+ emit({
946
+ type: "event",
947
+ kind: "status",
948
+ text:
949
+ reason === "max_tokens"
950
+ ? "The turn ended at the most the model writes in one."
951
+ : "The turn ended at the most requests the agent makes in one.",
952
+ });
953
+ }
954
+ // The agent is done when nothing it was sent still waits: what arrived meanwhile is its next turn.
955
+ if (waiting.length > 0) {
956
+ const next = waiting;
957
+ waiting = [];
958
+ prompt(next);
959
+ } else {
960
+ emit({ type: "turn_completed" });
961
+ }
962
+ })();
963
+ };
964
+
965
+ const stopTurn = (cut: "message" | "stopped"): void => {
966
+ if (turn === undefined || turn.cut !== undefined || session === undefined) {
967
+ return;
968
+ }
969
+ turn.cut = cut;
970
+ void connection.notify("session/cancel", { sessionId: session }).catch(() => undefined);
971
+ };
972
+
973
+ /** Why the session could not open, said once; the process is ended, and nothing more is said of it. */
974
+ const cannotStart = (text: string, reason: "start" | "sign_in"): void => {
975
+ gaveUp = true;
976
+ waiting = [];
977
+ emit({ type: "event", kind: "error", text }, { type: "cannot_go_on", state: "failed", reason });
978
+ void endOf(child);
979
+ };
980
+
981
+ const open = async (): Promise<void> => {
982
+ const initialized = await connection.request("initialize", hello(own));
983
+ began = true;
984
+ const version = isObject(initialized) ? initialized.protocolVersion : undefined;
985
+ if (version !== PROTOCOL_VERSION) {
986
+ cannotStart(
987
+ `The product speaks version ${String(version)} of the Agent Client Protocol, and this runner version ${PROTOCOL_VERSION}.`,
988
+ "start",
989
+ );
990
+ return;
991
+ }
992
+ const capabilities =
993
+ isObject(initialized) && isObject(initialized.agentCapabilities)
994
+ ? initialized.agentCapabilities
995
+ : {};
996
+ takesImages =
997
+ isObject(capabilities.promptCapabilities) && capabilities.promptCapabilities.image === true;
998
+ saidWhatItTakes = true;
999
+ const resumes =
1000
+ isObject(capabilities.sessionCapabilities) &&
1001
+ capabilities.sessionCapabilities.resume !== undefined &&
1002
+ capabilities.sessionCapabilities.resume !== null &&
1003
+ capabilities.sessionCapabilities.resume !== false;
1004
+ const loads = capabilities.loadSession === true;
1005
+ const place = { cwd: options.cwd, mcpServers: [] };
1006
+ let opened: unknown;
1007
+ if (options.resume !== undefined && (resumes || loads)) {
1008
+ // Gone on with where the agent can: without its history said again where it resumes, and
1009
+ // with it replayed, and left unread, where it only loads.
1010
+ replaying = !resumes;
1011
+ try {
1012
+ opened = await connection.request(resumes ? "session/resume" : "session/load", {
1013
+ sessionId: options.resume,
1014
+ ...place,
1015
+ });
1016
+ session = options.resume;
1017
+ } catch (error) {
1018
+ // Not signed in is said as that, and a process that is gone where its output ends.
1019
+ if (
1020
+ !(error instanceof RpcError) ||
1021
+ error.code === AUTH_REQUIRED ||
1022
+ SIGN_IN.test(error.message)
1023
+ ) {
1024
+ throw error;
1025
+ }
1026
+ // A conversation the agent has no more, or never kept: said, and a new one begun, as
1027
+ // the runner begins one where the conversation kept was another product's.
1028
+ emit({
1029
+ type: "event",
1030
+ kind: "status",
1031
+ text: `The agent could not go on with the conversation it had (${error.message}): a new one begins.`,
1032
+ });
1033
+ } finally {
1034
+ replaying = false;
1035
+ }
1036
+ } else if (options.resume !== undefined) {
1037
+ emit({
1038
+ type: "event",
1039
+ kind: "status",
1040
+ text: "This agent goes on with no conversation from one session to the next: a new one begins.",
1041
+ });
1042
+ }
1043
+ if (session === undefined) {
1044
+ opened = await connection.request("session/new", place);
1045
+ session = isObject(opened) ? textOf(opened.sessionId) : undefined;
1046
+ if (session === undefined) {
1047
+ cannotStart("The product opened a session and did not say which.", "start");
1048
+ return;
1049
+ }
1050
+ }
1051
+ const configuration = isObject(opened) ? opened.configOptions : undefined;
1052
+ model = choiceOf(configuration, "model");
1053
+ effort = choiceOf(configuration, "thought_level");
1054
+ await choose(model, options.model);
1055
+ await choose(effort, options.effort);
1056
+ const agent = agentOf(initialized);
1057
+ await stand(standingOf(opened), agent.name);
1058
+ product = agent.version ?? null;
1059
+ emit({ type: "conversation", id: session });
1060
+ runs();
1061
+ ready = true;
1062
+ if (waiting.length > 0) {
1063
+ const next = waiting;
1064
+ waiting = [];
1065
+ prompt(next);
1066
+ }
1067
+ };
1068
+
1069
+ void (async () => {
1070
+ const reading = connection.read({
1071
+ notification: (method, params) => {
1072
+ if (method === "session/update") {
1073
+ onUpdate(params);
1074
+ }
1075
+ },
1076
+ request: onRequest,
1077
+ });
1078
+ const opening = open().catch((error: unknown) => {
1079
+ if (gaveUp || stopping) {
1080
+ return;
1081
+ }
1082
+ if (error instanceof RpcError) {
1083
+ const signIn = error.code === AUTH_REQUIRED || SIGN_IN.test(error.message);
1084
+ cannotStart(
1085
+ signIn
1086
+ ? `The product is not signed in: ${error.message}`
1087
+ : `The product did not open a session: ${error.message}`,
1088
+ signIn ? "sign_in" : "start",
1089
+ );
1090
+ }
1091
+ // Anything else is a process that is gone: how it ended is said where its output ends.
1092
+ });
1093
+ const late = wait(START_TIMEOUT_MS).then(() => {
1094
+ if (!ready && !gaveUp && !stopping) {
1095
+ cannotStart("The product did not open a session in time.", "start");
1096
+ }
1097
+ });
1098
+ void late;
1099
+ await reading;
1100
+ await opening;
1101
+ flush();
1102
+ const exit = await child.exited;
1103
+ const clean = stopping || (exit.code === 0 && exit.signal === null && exit.error === undefined);
1104
+ if (!clean && !gaveUp) {
1105
+ const errors = child.errors().trim();
1106
+ // Its end, cut after the secrets are out, so that none stands at the cut.
1107
+ const shown = errorsShown(errors, options.cutEnd ?? plainCutEnd);
1108
+ emit(
1109
+ {
1110
+ type: "event",
1111
+ kind: "error",
1112
+ text:
1113
+ exit.error !== undefined
1114
+ ? `The product could not be started: ${exit.error}`
1115
+ : `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`}.${shown.length === 0 ? "" : `\n${shown}`}`,
1116
+ },
1117
+ {
1118
+ type: "cannot_go_on",
1119
+ state: "failed",
1120
+ reason: SIGN_IN.test(errors) ? "sign_in" : began ? "crashed" : "start",
1121
+ },
1122
+ );
1123
+ }
1124
+ emit({ type: "ended", how: clean ? "exited" : "crashed" });
1125
+ })();
1126
+
1127
+ return {
1128
+ events: events(),
1129
+ images: () => (saidWhatItTakes ? takesImages : undefined),
1130
+ async send(message) {
1131
+ if (stopping || gaveUp) {
1132
+ throw new Error("the session takes no more input");
1133
+ }
1134
+ if (!ready || turn !== undefined) {
1135
+ waiting.push(message);
1136
+ // The protocol takes no message in a turn: one to be read now stops the turn, and is
1137
+ // the turn after.
1138
+ if (message.priority === "now") {
1139
+ stopTurn("message");
1140
+ }
1141
+ return;
1142
+ }
1143
+ prompt([message]);
1144
+ },
1145
+ async interrupt() {
1146
+ stopTurn("stopped");
1147
+ },
1148
+ async set(next) {
1149
+ const tookModel = await choose(model, next.model, setMs);
1150
+ const tookEffort = await choose(effort, next.effort, setMs);
1151
+ runs();
1152
+ return tookModel && tookEffort;
1153
+ },
1154
+ async stop() {
1155
+ stopping = true;
1156
+ await endOf(child);
1157
+ },
1158
+ };
1159
+ }
1160
+
1161
+ /** A session that never began, with why: said once, as an agent that cannot go on. */
1162
+ function unstarted(text: string): DriverSession {
1163
+ async function* events(): AsyncGenerator<DriverEvent> {
1164
+ yield { type: "event", kind: "error", text };
1165
+ yield { type: "cannot_go_on", state: "failed", reason: "start" };
1166
+ yield { type: "ended", how: "crashed" };
1167
+ }
1168
+ return {
1169
+ events: events(),
1170
+ send: async () => {
1171
+ throw new Error("the session takes no more input");
1172
+ },
1173
+ interrupt: async () => undefined,
1174
+ set: async () => false,
1175
+ stop: async () => undefined,
1176
+ };
1177
+ }
1178
+
1179
+ /**
1180
+ * What the driver is started with: the command that speaks the protocol and its words, which
1181
+ * `runner.json` names, since there is no one product behind this driver.
1182
+ */
1183
+ export function createAcpDriver(host: DriverHost): Driver {
1184
+ const command = host.command;
1185
+ const args = host.args ?? [];
1186
+ /** What the product said it is called, once it was asked. */
1187
+ let name: string | undefined;
1188
+ const start = (cwd: string, env: Readonly<Record<string, string>>): Child =>
1189
+ host.spawn(command ?? "", args, { cwd, env });
1190
+ return {
1191
+ name: "acp",
1192
+ get product() {
1193
+ return {
1194
+ name: name ?? "An agent over the Agent Client Protocol",
1195
+ tried: (name === undefined ? undefined : TRIED[name]) ?? [],
1196
+ };
1197
+ },
1198
+ // A message waits for the turn under way, or stops it: none is taken in one. Pictures, a
1199
+ // conversation gone on with and the model are the agent's to offer, and are asked of it.
1200
+ can: { steer: false, images: true, resume: true, set: true },
1201
+ permissions: { modes: MODES, unattended: UNATTENDED_MODE, least: LEAST_MODE },
1202
+ async probe(): Promise<Probe> {
1203
+ const nothing: Probe = { version: undefined, models: [], efforts: [] };
1204
+ if (command === undefined) {
1205
+ return nothing;
1206
+ }
1207
+ let child: Child;
1208
+ try {
1209
+ child = start(host.cwd, {});
1210
+ } catch {
1211
+ return nothing;
1212
+ }
1213
+ const connection = connectionOf(child);
1214
+ const reading = connection.read({
1215
+ notification: () => undefined,
1216
+ request: (id, method) => {
1217
+ void connection
1218
+ .refuse(id, METHOD_NOT_FOUND, `${method} is not offered`)
1219
+ .catch(() => undefined);
1220
+ },
1221
+ });
1222
+ const asked = (async (): Promise<Probe> => {
1223
+ const initialized = await connection.request("initialize", hello(host.version));
1224
+ const agent = agentOf(initialized);
1225
+ name = agent.name ?? name;
1226
+ try {
1227
+ // What it offers to choose from is a session's to say: one is opened, and closed
1228
+ // again where the agent closes one, so that it keeps nothing of a session nobody had.
1229
+ const opened = await connection.request("session/new", { cwd: host.cwd, mcpServers: [] });
1230
+ const configuration = isObject(opened) ? opened.configOptions : undefined;
1231
+ const capabilities =
1232
+ isObject(initialized) && isObject(initialized.agentCapabilities)
1233
+ ? initialized.agentCapabilities
1234
+ : {};
1235
+ const closes =
1236
+ isObject(capabilities.sessionCapabilities) &&
1237
+ isObject(capabilities.sessionCapabilities.close);
1238
+ const opening = isObject(opened) ? textOf(opened.sessionId) : undefined;
1239
+ if (closes && opening !== undefined) {
1240
+ await connection
1241
+ .request("session/close", { sessionId: opening })
1242
+ .catch(() => undefined);
1243
+ }
1244
+ return {
1245
+ version: agent.version,
1246
+ models: choiceOf(configuration, "model")?.values ?? [],
1247
+ efforts: choiceOf(configuration, "thought_level")?.values ?? [],
1248
+ };
1249
+ } catch {
1250
+ return { version: agent.version, models: [], efforts: [] };
1251
+ }
1252
+ })().catch(() => nothing);
1253
+ const probe = await Promise.race([asked, wait(PROBE_TIMEOUT_MS).then(() => nothing)]);
1254
+ await endOf(child);
1255
+ await reading;
1256
+ return probe;
1257
+ },
1258
+ start(options) {
1259
+ if (command === undefined) {
1260
+ return unstarted(
1261
+ "runner.json names the driver acp and no command for it: say which program speaks the protocol, as product.command.",
1262
+ );
1263
+ }
1264
+ return sessionOf(start(options.cwd, options.env), options, host.version, host.timing?.setMs);
1265
+ },
1266
+ };
1267
+ }