@maiaos/cli 0.1.0-canary.2

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 (413) hide show
  1. package/README.md +287 -0
  2. package/dist/bin/maia.NOTICES.txt +59 -0
  3. package/dist/bin/maia.cdx.json +145 -0
  4. package/dist/bin/maia.mjs +2 -0
  5. package/dist/bootstrap/index.d.ts +3 -0
  6. package/dist/bootstrap/index.js +3 -0
  7. package/dist/bootstrap/process.d.ts +5 -0
  8. package/dist/bootstrap/process.js +45 -0
  9. package/dist/bootstrap/run.d.ts +25 -0
  10. package/dist/bootstrap/run.js +95 -0
  11. package/dist/bootstrap/stdio.d.ts +4 -0
  12. package/dist/bootstrap/stdio.js +9 -0
  13. package/dist/cli/cli.d.ts +17 -0
  14. package/dist/cli/cli.js +481 -0
  15. package/dist/cli/environment.d.ts +8 -0
  16. package/dist/cli/environment.js +12 -0
  17. package/dist/cli/index.d.ts +2 -0
  18. package/dist/cli/index.js +2 -0
  19. package/dist/cli/services.d.ts +4 -0
  20. package/dist/cli/services.js +4 -0
  21. package/dist/command-line/context.d.ts +178 -0
  22. package/dist/command-line/context.js +2 -0
  23. package/dist/command-line/index.d.ts +7 -0
  24. package/dist/command-line/index.js +6 -0
  25. package/dist/command-line/input/arguments.d.ts +55 -0
  26. package/dist/command-line/input/arguments.js +220 -0
  27. package/dist/command-line/input/index.d.ts +4 -0
  28. package/dist/command-line/input/index.js +4 -0
  29. package/dist/command-line/input/prompt.d.ts +8 -0
  30. package/dist/command-line/input/prompt.js +44 -0
  31. package/dist/command-line/input/stdin-stream.d.ts +4 -0
  32. package/dist/command-line/input/stdin-stream.js +3 -0
  33. package/dist/command-line/input/stdin.d.ts +11 -0
  34. package/dist/command-line/input/stdin.js +23 -0
  35. package/dist/command-line/json-decoder.d.ts +3 -0
  36. package/dist/command-line/json-decoder.js +3 -0
  37. package/dist/command-line/json.d.ts +3 -0
  38. package/dist/command-line/json.js +4 -0
  39. package/dist/command-line/output.d.ts +57 -0
  40. package/dist/command-line/output.js +94 -0
  41. package/dist/command-line/rows.d.ts +10 -0
  42. package/dist/command-line/rows.js +32 -0
  43. package/dist/command-line/two-phase.d.ts +57 -0
  44. package/dist/command-line/two-phase.js +148 -0
  45. package/dist/command-receipt/command.d.ts +4 -0
  46. package/dist/command-receipt/command.js +59 -0
  47. package/dist/command-receipt/compact-list.d.ts +20 -0
  48. package/dist/command-receipt/compact-list.js +29 -0
  49. package/dist/command-receipt/index.d.ts +3 -0
  50. package/dist/command-receipt/index.js +3 -0
  51. package/dist/command-tree/commands.d.ts +17 -0
  52. package/dist/command-tree/commands.js +41 -0
  53. package/dist/command-tree/completion.d.ts +6 -0
  54. package/dist/command-tree/completion.js +36 -0
  55. package/dist/command-tree/grammar.d.ts +18 -0
  56. package/dist/command-tree/grammar.js +160 -0
  57. package/dist/command-tree/help.d.ts +62 -0
  58. package/dist/command-tree/help.js +219 -0
  59. package/dist/command-tree/index.d.ts +8 -0
  60. package/dist/command-tree/index.js +6 -0
  61. package/dist/command-tree/local.d.ts +3 -0
  62. package/dist/command-tree/local.js +126 -0
  63. package/dist/command-tree/placeholder.d.ts +3 -0
  64. package/dist/command-tree/placeholder.js +4 -0
  65. package/dist/command-tree/row.d.ts +29 -0
  66. package/dist/command-tree/row.js +2 -0
  67. package/dist/command-tree/suggest.d.ts +3 -0
  68. package/dist/command-tree/suggest.js +81 -0
  69. package/dist/command-tree/tree.d.ts +34 -0
  70. package/dist/command-tree/tree.js +124 -0
  71. package/dist/connection/client.d.ts +692 -0
  72. package/dist/connection/client.js +28 -0
  73. package/dist/connection/commands.d.ts +15 -0
  74. package/dist/connection/commands.js +118 -0
  75. package/dist/connection/index.d.ts +7 -0
  76. package/dist/connection/index.js +7 -0
  77. package/dist/connection/input.d.ts +50 -0
  78. package/dist/connection/input.js +90 -0
  79. package/dist/connection/login.d.ts +13 -0
  80. package/dist/connection/login.js +69 -0
  81. package/dist/connection/output/format.d.ts +32 -0
  82. package/dist/connection/output/format.js +94 -0
  83. package/dist/connection/output/index.d.ts +2 -0
  84. package/dist/connection/output/index.js +2 -0
  85. package/dist/connection/resolve.d.ts +60 -0
  86. package/dist/connection/resolve.js +30 -0
  87. package/dist/connection/signin.d.ts +4 -0
  88. package/dist/connection/signin.js +32 -0
  89. package/dist/connection/system.d.ts +4 -0
  90. package/dist/connection/system.js +190 -0
  91. package/dist/connection/tree/index.d.ts +2 -0
  92. package/dist/connection/tree/index.js +2 -0
  93. package/dist/connection/tree/tree.d.ts +3 -0
  94. package/dist/connection/tree/tree.js +209 -0
  95. package/dist/container/client.d.ts +142 -0
  96. package/dist/container/client.js +11 -0
  97. package/dist/container/commands.d.ts +7 -0
  98. package/dist/container/commands.js +100 -0
  99. package/dist/container/index.d.ts +3 -0
  100. package/dist/container/index.js +3 -0
  101. package/dist/container/output/format.d.ts +11 -0
  102. package/dist/container/output/format.js +28 -0
  103. package/dist/container/output/index.d.ts +2 -0
  104. package/dist/container/output/index.js +2 -0
  105. package/dist/context/client.d.ts +7 -0
  106. package/dist/context/client.js +21 -0
  107. package/dist/context/commands.d.ts +3 -0
  108. package/dist/context/commands.js +27 -0
  109. package/dist/context/index.d.ts +3 -0
  110. package/dist/context/index.js +3 -0
  111. package/dist/development/cli.d.ts +3 -0
  112. package/dist/development/cli.js +44 -0
  113. package/dist/execution/client.d.ts +25 -0
  114. package/dist/execution/client.js +24 -0
  115. package/dist/execution/index.d.ts +3 -0
  116. package/dist/execution/index.js +3 -0
  117. package/dist/execution/relocation.d.ts +6 -0
  118. package/dist/execution/relocation.js +123 -0
  119. package/dist/execution/tree/index.d.ts +2 -0
  120. package/dist/execution/tree/index.js +2 -0
  121. package/dist/execution/tree/tree.d.ts +3 -0
  122. package/dist/execution/tree/tree.js +137 -0
  123. package/dist/hold/client.d.ts +137 -0
  124. package/dist/hold/client.js +12 -0
  125. package/dist/hold/commands.d.ts +5 -0
  126. package/dist/hold/commands.js +91 -0
  127. package/dist/hold/index.d.ts +3 -0
  128. package/dist/hold/index.js +3 -0
  129. package/dist/hold/output/format.d.ts +11 -0
  130. package/dist/hold/output/format.js +29 -0
  131. package/dist/hold/output/index.d.ts +2 -0
  132. package/dist/hold/output/index.js +2 -0
  133. package/dist/hold/tree/index.d.ts +2 -0
  134. package/dist/hold/tree/index.js +2 -0
  135. package/dist/hold/tree/tree.d.ts +3 -0
  136. package/dist/hold/tree/tree.js +96 -0
  137. package/dist/import/client.d.ts +14 -0
  138. package/dist/import/client.js +16 -0
  139. package/dist/import/commands.d.ts +5 -0
  140. package/dist/import/commands.js +76 -0
  141. package/dist/import/index.d.ts +3 -0
  142. package/dist/import/index.js +3 -0
  143. package/dist/import/input.d.ts +16 -0
  144. package/dist/import/input.js +92 -0
  145. package/dist/import/output.d.ts +6 -0
  146. package/dist/import/output.js +40 -0
  147. package/dist/index.d.ts +2 -0
  148. package/dist/index.js +2 -0
  149. package/dist/integration/client.d.ts +1284 -0
  150. package/dist/integration/client.js +24 -0
  151. package/dist/integration/commands.d.ts +10 -0
  152. package/dist/integration/commands.js +104 -0
  153. package/dist/integration/index.d.ts +3 -0
  154. package/dist/integration/index.js +3 -0
  155. package/dist/integration/output.d.ts +22 -0
  156. package/dist/integration/output.js +20 -0
  157. package/dist/local-node/call.d.ts +7 -0
  158. package/dist/local-node/call.js +13 -0
  159. package/dist/local-node/client.d.ts +67 -0
  160. package/dist/local-node/client.js +241 -0
  161. package/dist/local-node/index.d.ts +3 -0
  162. package/dist/local-node/index.js +3 -0
  163. package/dist/login/agent-provider.d.ts +20 -0
  164. package/dist/login/agent-provider.js +109 -0
  165. package/dist/login/commands.d.ts +4 -0
  166. package/dist/login/commands.js +93 -0
  167. package/dist/login/failure.d.ts +3 -0
  168. package/dist/login/failure.js +14 -0
  169. package/dist/login/gateway.d.ts +12 -0
  170. package/dist/login/gateway.js +71 -0
  171. package/dist/login/index.d.ts +3 -0
  172. package/dist/login/index.js +2 -0
  173. package/dist/login/menu.d.ts +4 -0
  174. package/dist/login/menu.js +105 -0
  175. package/dist/login/output/format.d.ts +16 -0
  176. package/dist/login/output/format.js +31 -0
  177. package/dist/login/output/index.d.ts +2 -0
  178. package/dist/login/output/index.js +2 -0
  179. package/dist/login/vendor-account.d.ts +95 -0
  180. package/dist/login/vendor-account.js +75 -0
  181. package/dist/login/vendor-input.d.ts +14 -0
  182. package/dist/login/vendor-input.js +36 -0
  183. package/dist/mcp/calls.d.ts +7 -0
  184. package/dist/mcp/calls.js +202 -0
  185. package/dist/mcp/commands.d.ts +9 -0
  186. package/dist/mcp/commands.js +21 -0
  187. package/dist/mcp/index.d.ts +2 -0
  188. package/dist/mcp/index.js +2 -0
  189. package/dist/mcp/server.d.ts +11 -0
  190. package/dist/mcp/server.js +57 -0
  191. package/dist/orchestration/client.d.ts +78 -0
  192. package/dist/orchestration/client.js +89 -0
  193. package/dist/orchestration/commands.d.ts +14 -0
  194. package/dist/orchestration/commands.js +312 -0
  195. package/dist/orchestration/index.d.ts +3 -0
  196. package/dist/orchestration/index.js +3 -0
  197. package/dist/orchestration/output/compact-aggregate.d.ts +121 -0
  198. package/dist/orchestration/output/compact-aggregate.js +110 -0
  199. package/dist/orchestration/output/compact-run-list.d.ts +20 -0
  200. package/dist/orchestration/output/compact-run-list.js +16 -0
  201. package/dist/orchestration/output/human.d.ts +80 -0
  202. package/dist/orchestration/output/human.js +252 -0
  203. package/dist/orchestration/output/index.d.ts +4 -0
  204. package/dist/orchestration/output/index.js +4 -0
  205. package/dist/orchestration/tree/index.d.ts +2 -0
  206. package/dist/orchestration/tree/index.js +2 -0
  207. package/dist/orchestration/tree/tree.d.ts +3 -0
  208. package/dist/orchestration/tree/tree.js +142 -0
  209. package/dist/port-lease/client.d.ts +160 -0
  210. package/dist/port-lease/client.js +11 -0
  211. package/dist/port-lease/commands.d.ts +6 -0
  212. package/dist/port-lease/commands.js +17 -0
  213. package/dist/port-lease/index.d.ts +3 -0
  214. package/dist/port-lease/index.js +3 -0
  215. package/dist/port-lease/input.d.ts +65 -0
  216. package/dist/port-lease/input.js +67 -0
  217. package/dist/port-lease/output/format.d.ts +11 -0
  218. package/dist/port-lease/output/format.js +24 -0
  219. package/dist/port-lease/output/index.d.ts +2 -0
  220. package/dist/port-lease/output/index.js +2 -0
  221. package/dist/presentation/client.d.ts +10 -0
  222. package/dist/presentation/client.js +9 -0
  223. package/dist/presentation/commands.d.ts +6 -0
  224. package/dist/presentation/commands.js +78 -0
  225. package/dist/presentation/index.d.ts +4 -0
  226. package/dist/presentation/index.js +3 -0
  227. package/dist/presentation/output/format.d.ts +11 -0
  228. package/dist/presentation/output/format.js +32 -0
  229. package/dist/presentation/output/index.d.ts +3 -0
  230. package/dist/presentation/output/index.js +2 -0
  231. package/dist/project-guard/client.d.ts +88 -0
  232. package/dist/project-guard/client.js +7 -0
  233. package/dist/project-guard/commands.d.ts +4 -0
  234. package/dist/project-guard/commands.js +39 -0
  235. package/dist/project-guard/index.d.ts +3 -0
  236. package/dist/project-guard/index.js +3 -0
  237. package/dist/project-guard/input.d.ts +18 -0
  238. package/dist/project-guard/input.js +47 -0
  239. package/dist/project-guard/output/format.d.ts +11 -0
  240. package/dist/project-guard/output/format.js +35 -0
  241. package/dist/project-guard/output/index.d.ts +2 -0
  242. package/dist/project-guard/output/index.js +2 -0
  243. package/dist/project-workspace/client.d.ts +86 -0
  244. package/dist/project-workspace/client.js +159 -0
  245. package/dist/project-workspace/commands.d.ts +30 -0
  246. package/dist/project-workspace/commands.js +700 -0
  247. package/dist/project-workspace/index.d.ts +5 -0
  248. package/dist/project-workspace/index.js +5 -0
  249. package/dist/project-workspace/metadata-client.d.ts +99 -0
  250. package/dist/project-workspace/metadata-client.js +8 -0
  251. package/dist/project-workspace/metadata-commands.d.ts +4 -0
  252. package/dist/project-workspace/metadata-commands.js +56 -0
  253. package/dist/project-workspace/output/human.d.ts +126 -0
  254. package/dist/project-workspace/output/human.js +103 -0
  255. package/dist/project-workspace/output/index.d.ts +3 -0
  256. package/dist/project-workspace/output/index.js +3 -0
  257. package/dist/project-workspace/output/metadata.d.ts +11 -0
  258. package/dist/project-workspace/output/metadata.js +17 -0
  259. package/dist/project-workspace/tree/index.d.ts +2 -0
  260. package/dist/project-workspace/tree/index.js +2 -0
  261. package/dist/project-workspace/tree/tree.d.ts +3 -0
  262. package/dist/project-workspace/tree/tree.js +197 -0
  263. package/dist/provider/client.d.ts +6 -0
  264. package/dist/provider/client.js +5 -0
  265. package/dist/provider/commands.d.ts +3 -0
  266. package/dist/provider/commands.js +38 -0
  267. package/dist/provider/index.d.ts +3 -0
  268. package/dist/provider/index.js +3 -0
  269. package/dist/reference/commands.d.ts +3 -0
  270. package/dist/reference/commands.js +39 -0
  271. package/dist/reference/index.d.ts +3 -0
  272. package/dist/reference/index.js +3 -0
  273. package/dist/reference/resolve.d.ts +29 -0
  274. package/dist/reference/resolve.js +294 -0
  275. package/dist/reference/tree/index.d.ts +2 -0
  276. package/dist/reference/tree/index.js +2 -0
  277. package/dist/reference/tree/tree.d.ts +3 -0
  278. package/dist/reference/tree/tree.js +17 -0
  279. package/dist/remote-node/client.d.ts +258 -0
  280. package/dist/remote-node/client.js +12 -0
  281. package/dist/remote-node/commands.d.ts +6 -0
  282. package/dist/remote-node/commands.js +264 -0
  283. package/dist/remote-node/connector.d.ts +59 -0
  284. package/dist/remote-node/connector.js +122 -0
  285. package/dist/remote-node/index.d.ts +4 -0
  286. package/dist/remote-node/index.js +4 -0
  287. package/dist/remote-node/reachability.d.ts +22 -0
  288. package/dist/remote-node/reachability.js +34 -0
  289. package/dist/remote-node/text.d.ts +9 -0
  290. package/dist/remote-node/text.js +64 -0
  291. package/dist/remote-node/tree/index.d.ts +2 -0
  292. package/dist/remote-node/tree/index.js +2 -0
  293. package/dist/remote-node/tree/tree.d.ts +3 -0
  294. package/dist/remote-node/tree/tree.js +51 -0
  295. package/dist/run-ledger/client.d.ts +358 -0
  296. package/dist/run-ledger/client.js +13 -0
  297. package/dist/run-ledger/commands.d.ts +8 -0
  298. package/dist/run-ledger/commands.js +19 -0
  299. package/dist/run-ledger/index.d.ts +3 -0
  300. package/dist/run-ledger/index.js +3 -0
  301. package/dist/run-ledger/input.d.ts +42 -0
  302. package/dist/run-ledger/input.js +107 -0
  303. package/dist/run-ledger/output/format.d.ts +11 -0
  304. package/dist/run-ledger/output/format.js +49 -0
  305. package/dist/run-ledger/output/index.d.ts +2 -0
  306. package/dist/run-ledger/output/index.js +2 -0
  307. package/dist/session/agent-permission.d.ts +63 -0
  308. package/dist/session/agent-permission.js +20 -0
  309. package/dist/session/approval/client.d.ts +117 -0
  310. package/dist/session/approval/client.js +7 -0
  311. package/dist/session/approval/commands.d.ts +7 -0
  312. package/dist/session/approval/commands.js +123 -0
  313. package/dist/session/approval/index.d.ts +3 -0
  314. package/dist/session/approval/index.js +3 -0
  315. package/dist/session/approval/output/format.d.ts +12 -0
  316. package/dist/session/approval/output/format.js +25 -0
  317. package/dist/session/approval/output/index.d.ts +2 -0
  318. package/dist/session/approval/output/index.js +2 -0
  319. package/dist/session/attach-client.d.ts +16 -0
  320. package/dist/session/attach-client.js +8 -0
  321. package/dist/session/attach-render.d.ts +16 -0
  322. package/dist/session/attach-render.js +154 -0
  323. package/dist/session/attach.d.ts +5 -0
  324. package/dist/session/attach.js +106 -0
  325. package/dist/session/client.d.ts +132 -0
  326. package/dist/session/client.js +128 -0
  327. package/dist/session/coding-client.d.ts +16 -0
  328. package/dist/session/coding-client.js +15 -0
  329. package/dist/session/coding-commands.d.ts +4 -0
  330. package/dist/session/coding-commands.js +50 -0
  331. package/dist/session/commands.d.ts +13 -0
  332. package/dist/session/commands.js +488 -0
  333. package/dist/session/create-tasks.d.ts +20 -0
  334. package/dist/session/create-tasks.js +110 -0
  335. package/dist/session/index.d.ts +9 -0
  336. package/dist/session/index.js +7 -0
  337. package/dist/session/interaction/client.d.ts +347 -0
  338. package/dist/session/interaction/client.js +15 -0
  339. package/dist/session/interaction/commands.d.ts +7 -0
  340. package/dist/session/interaction/commands.js +101 -0
  341. package/dist/session/interaction/index.d.ts +3 -0
  342. package/dist/session/interaction/index.js +3 -0
  343. package/dist/session/interaction/input.d.ts +15 -0
  344. package/dist/session/interaction/input.js +46 -0
  345. package/dist/session/interaction/output/format.d.ts +11 -0
  346. package/dist/session/interaction/output/format.js +3 -0
  347. package/dist/session/interaction/output/index.d.ts +2 -0
  348. package/dist/session/interaction/output/index.js +2 -0
  349. package/dist/session/output/diff.d.ts +3 -0
  350. package/dist/session/output/diff.js +30 -0
  351. package/dist/session/output/failure.d.ts +11 -0
  352. package/dist/session/output/failure.js +24 -0
  353. package/dist/session/output/human.d.ts +112 -0
  354. package/dist/session/output/human.js +71 -0
  355. package/dist/session/output/index.d.ts +6 -0
  356. package/dist/session/output/index.js +6 -0
  357. package/dist/session/output/observe.d.ts +4 -0
  358. package/dist/session/output/observe.js +46 -0
  359. package/dist/session/output/tasks.d.ts +19 -0
  360. package/dist/session/output/tasks.js +34 -0
  361. package/dist/session/rename.d.ts +3 -0
  362. package/dist/session/rename.js +37 -0
  363. package/dist/session/task-file.d.ts +5 -0
  364. package/dist/session/task-file.js +23 -0
  365. package/dist/session/tree/index.d.ts +2 -0
  366. package/dist/session/tree/index.js +2 -0
  367. package/dist/session/tree/tree.d.ts +3 -0
  368. package/dist/session/tree/tree.js +309 -0
  369. package/dist/session/turn/client.d.ts +25 -0
  370. package/dist/session/turn/client.js +40 -0
  371. package/dist/session/turn/commands.d.ts +6 -0
  372. package/dist/session/turn/commands.js +157 -0
  373. package/dist/session/turn/index.d.ts +4 -0
  374. package/dist/session/turn/index.js +3 -0
  375. package/dist/session/turn/output.d.ts +42 -0
  376. package/dist/session/turn/output.js +38 -0
  377. package/dist/status/client.d.ts +119 -0
  378. package/dist/status/client.js +5 -0
  379. package/dist/status/command.d.ts +4 -0
  380. package/dist/status/command.js +40 -0
  381. package/dist/status/doctor.d.ts +15 -0
  382. package/dist/status/doctor.js +111 -0
  383. package/dist/status/index.d.ts +5 -0
  384. package/dist/status/index.js +4 -0
  385. package/dist/status/output/compact.d.ts +31 -0
  386. package/dist/status/output/compact.js +46 -0
  387. package/dist/status/output/human.d.ts +7 -0
  388. package/dist/status/output/human.js +30 -0
  389. package/dist/status/output/index.d.ts +3 -0
  390. package/dist/status/output/index.js +3 -0
  391. package/dist/terminal/arguments.d.ts +13 -0
  392. package/dist/terminal/arguments.js +79 -0
  393. package/dist/terminal/client.d.ts +79 -0
  394. package/dist/terminal/client.js +68 -0
  395. package/dist/terminal/commands.d.ts +7 -0
  396. package/dist/terminal/commands.js +131 -0
  397. package/dist/terminal/control-commands.d.ts +10 -0
  398. package/dist/terminal/control-commands.js +212 -0
  399. package/dist/terminal/index.d.ts +4 -0
  400. package/dist/terminal/index.js +4 -0
  401. package/dist/terminal/output/compact-list.d.ts +147 -0
  402. package/dist/terminal/output/compact-list.js +152 -0
  403. package/dist/terminal/output/human.d.ts +59 -0
  404. package/dist/terminal/output/human.js +55 -0
  405. package/dist/terminal/output/index.d.ts +3 -0
  406. package/dist/terminal/output/index.js +3 -0
  407. package/dist/terminal/tree/index.d.ts +2 -0
  408. package/dist/terminal/tree/index.js +2 -0
  409. package/dist/terminal/tree/tree.d.ts +3 -0
  410. package/dist/terminal/tree/tree.js +104 -0
  411. package/guidance/maia-cli/SKILL.md +58 -0
  412. package/guidance/maia-orchestration/SKILL.md +54 -0
  413. package/package.json +76 -0
@@ -0,0 +1,488 @@
1
+ import { MAX_SESSION_INBOX_CHECK_LIMIT, MAX_SESSION_MESSAGE_BODY_BYTES, MAX_SESSION_OBSERVE_IDS, MAX_SESSION_STALL_AFTER_SECONDS, MIN_SESSION_STALL_AFTER_SECONDS, sessionBaseRefSchema, sessionCreateParametersSchema, } from "@maiaos/sdk";
2
+ import { Effect } from "effect";
3
+ import { CliArgumentError, parseOptions, readCursor, readDuration, readExpectedRevision, readPageSize, requirePositionals, } from "../command-line/index.js";
4
+ import { runSessionTasks, } from "./create-tasks.js";
5
+ import { writeSessionResult } from "./output/index.js";
6
+ const SESSION_CREATE_OPTIONS = new Set([
7
+ "--base",
8
+ "--command-id",
9
+ "--connection",
10
+ "--executor",
11
+ "--model",
12
+ "--agent-definition",
13
+ "--agent-definition-version",
14
+ "--agent-definition-digest",
15
+ "--role",
16
+ "--title",
17
+ ]);
18
+ const summarizeSessionCreation = (result) => ({
19
+ ...(result.session.agentDefinitionRef === undefined
20
+ ? {}
21
+ : { agentDefinitionRef: result.session.agentDefinitionRef }),
22
+ ...(result.session.executor === undefined
23
+ ? {}
24
+ : { executor: result.session.executor }),
25
+ delivery: result.delivery,
26
+ receipt: result.receipt,
27
+ revision: result.session.revision,
28
+ sessionId: result.session.id,
29
+ state: result.session.state,
30
+ ...(result.session.title === undefined
31
+ ? {}
32
+ : { title: result.session.title }),
33
+ workspaceId: result.session.workspaceId,
34
+ workspaceRevision: result.session.workspaceRevision,
35
+ ...(result.session.worktree === undefined
36
+ ? {}
37
+ : { worktree: result.session.worktree }),
38
+ });
39
+ const summarizeSessionLifecycle = (result) => ({
40
+ delivery: result.delivery,
41
+ receipt: result.receipt,
42
+ revision: result.session.revision,
43
+ sessionId: result.session.id,
44
+ state: result.session.state,
45
+ });
46
+ const readSessionEventPageSize = (value) => {
47
+ if (value === undefined)
48
+ return 20;
49
+ if (!/^(?:[1-9]|[12]\d|3[0-2])$/u.test(value)) {
50
+ throw new CliArgumentError("Option '--limit' must be an integer from 1 to 32 for session events.");
51
+ }
52
+ return Number(value);
53
+ };
54
+ const readSessionCreateOptions = (parsed) => {
55
+ requirePositionals(parsed.positionals, 0);
56
+ const workspaceId = parsed.options.get("--workspace");
57
+ if (workspaceId === undefined)
58
+ throw new CliArgumentError(parsed.options.has("--project")
59
+ ? "Option '--project' needs '--message', '--prompt-stdin' or '--from-file'; name a Workspace with '--workspace' otherwise."
60
+ : "Option '--workspace' is required.");
61
+ const input = readSessionSelection(parsed.options, workspaceId);
62
+ const definition = readDefinitionSelection(parsed.options, input);
63
+ requireOneSelection({ ...input, ...definition });
64
+ return { ...input, ...definition };
65
+ };
66
+ const requireOneSelection = (input) => {
67
+ if (input.definitionRef !== undefined &&
68
+ (input.connectionId !== undefined || input.executor !== undefined))
69
+ throw new CliArgumentError("Use one of '--connection', '--executor' or '--agent-definition'.");
70
+ if (input.model !== undefined && input.connectionId === undefined)
71
+ throw new CliArgumentError("Option '--model' needs '--connection' with a gateway connection.");
72
+ };
73
+ const readSessionRole = (value) => {
74
+ if (value === undefined)
75
+ return {};
76
+ if (value === "worker" || value === "orchestrator")
77
+ return { role: value };
78
+ throw new CliArgumentError("Option '--role' must be worker or orchestrator.");
79
+ };
80
+ const readSessionSelection = (options, workspaceId) => {
81
+ const commandId = options.get("--command-id");
82
+ const connectionId = options.get("--connection");
83
+ const executor = readExecutorKind(options.get("--executor"));
84
+ const model = options.get("--model");
85
+ const title = options.get("--title");
86
+ const selection = {
87
+ ...(commandId === undefined ? {} : { commandId }),
88
+ ...(connectionId === undefined ? {} : { connectionId }),
89
+ ...(executor === undefined ? {} : { executor }),
90
+ ...(model === undefined ? {} : { model }),
91
+ ...readSessionRole(options.get("--role")),
92
+ ...(title === undefined ? {} : { title }),
93
+ workspaceId,
94
+ };
95
+ const baseRef = readBaseRef(options.get("--base"), selection);
96
+ return { ...selection, ...(baseRef === undefined ? {} : { baseRef }) };
97
+ };
98
+ const readBaseRef = (value, selection) => {
99
+ if (value === undefined)
100
+ return;
101
+ if (selection.connectionId === undefined && selection.executor === undefined)
102
+ throw new CliArgumentError("Option '--base' needs '--connection' or '--executor'.");
103
+ if (sessionBaseRefSchema.safeParse(value).success)
104
+ return value;
105
+ throw new CliArgumentError("Option '--base' must name a branch, tag or commit without ranges, revision suffixes or a leading dash.");
106
+ };
107
+ const readExecutorKind = (value) => {
108
+ if (value === undefined || value === "codex-cli" || value === "claude-code")
109
+ return value;
110
+ throw new CliArgumentError("Option '--executor' must be codex-cli or claude-code.");
111
+ };
112
+ const readDefinitionSelection = (options, input) => {
113
+ const key = options.get("--agent-definition");
114
+ const version = options.get("--agent-definition-version");
115
+ const contentDigest = options.get("--agent-definition-digest");
116
+ if (key === undefined &&
117
+ version === undefined &&
118
+ contentDigest === undefined) {
119
+ return {};
120
+ }
121
+ const validated = sessionCreateParametersSchema.safeParse({
122
+ ...input,
123
+ commandId: input.commandId ?? "command_validate",
124
+ definitionRef: { contentDigest, key, version },
125
+ expectedRevision: "0",
126
+ });
127
+ if (!validated.success) {
128
+ throw new CliArgumentError("Agent definition selection requires valid '--agent-definition', '--agent-definition-version', and '--agent-definition-digest' together.");
129
+ }
130
+ return { definitionRef: validated.data.definitionRef };
131
+ };
132
+ const TASK_OPTIONS = new Set([
133
+ ...SESSION_CREATE_OPTIONS,
134
+ "--from-file",
135
+ "--message",
136
+ "--project",
137
+ "--workspace",
138
+ ]);
139
+ const taskSource = (parsed) => {
140
+ const file = parsed.options.get("--from-file");
141
+ const message = parsed.options.get("--message");
142
+ const stdin = parsed.flags.has("--prompt-stdin");
143
+ if ([file, message, stdin ? "" : undefined].filter((value) => value !== undefined).length > 1)
144
+ throw new CliArgumentError("Use one of '--message', '--prompt-stdin' or '--from-file'.");
145
+ if (file !== undefined && parsed.options.has("--title"))
146
+ throw new CliArgumentError("Option '--title' names one Session; with '--from-file' each Session takes its task's first line.");
147
+ if (file !== undefined)
148
+ return { kind: "file", path: file };
149
+ if (message !== undefined)
150
+ return { kind: "message", text: message };
151
+ return stdin ? { kind: "stdin" } : undefined;
152
+ };
153
+ const readTaskWorkspace = (parsed, source) => {
154
+ requirePositionals(parsed.positionals, 0);
155
+ const named = parsed.options.get("--workspace");
156
+ if ((named === undefined) === !parsed.options.has("--project"))
157
+ throw new CliArgumentError("Name one Workspace with '--workspace', or a Project with '--project'.");
158
+ if (parsed.options.has("--agent-definition"))
159
+ throw new CliArgumentError("Option '--agent-definition' does not apply to Session tasks.");
160
+ if (parsed.options.has("--command-id") && source.kind === "file")
161
+ throw new CliArgumentError("Option '--command-id' names one Session; use it with '--message' or '--prompt-stdin'.");
162
+ return named;
163
+ };
164
+ const readSessionTasks = (parsed, source) => {
165
+ const workspaceId = readTaskWorkspace(parsed, source);
166
+ const projectId = parsed.options.get("--project");
167
+ const commandId = parsed.options.get("--command-id");
168
+ const { workspaceId: _placeholder, ...selection } = readSessionSelection(parsed.options, workspaceId ?? "workspace_default");
169
+ requireOneSelection({ ...selection, workspaceId: _placeholder });
170
+ return {
171
+ ...(commandId === undefined ? {} : { commandId }),
172
+ ...(projectId === undefined ? {} : { projectId }),
173
+ selection,
174
+ source,
175
+ ...(workspaceId === undefined ? {} : { workspaceId }),
176
+ };
177
+ };
178
+ export const runSessionCreate = (tokens, context) => {
179
+ const parsed = parseOptions(tokens, TASK_OPTIONS, new Set(["--prompt-stdin"]));
180
+ const source = taskSource(parsed);
181
+ if (source !== undefined)
182
+ return runSessionTasks(readSessionTasks(parsed, source), context);
183
+ return Effect.map(context.dependencies.createSession(readSessionCreateOptions(parsed)), (result) => writeSessionResult(result, context, (value) => ({
184
+ command: "session.create",
185
+ result: summarizeSessionCreation(value),
186
+ })));
187
+ };
188
+ const readSessionList = (tokens) => {
189
+ const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--project", "--state"]), new Set(["--all", "--attention"]));
190
+ requirePositionals(parsed.positionals, 0);
191
+ const projectId = parsed.options.get("--project");
192
+ if ((projectId === undefined) === !parsed.flags.has("--all"))
193
+ throw new CliArgumentError("Use one of '--project' or '--all'.");
194
+ const states = parsed.options.get("--state")?.split(",");
195
+ return {
196
+ afterCursor: readCursor(parsed.options.get("--after")),
197
+ limit: readPageSize(parsed.options.get("--limit")),
198
+ ...(projectId === undefined ? {} : { projectId }),
199
+ ...(parsed.flags.has("--attention") ? { attention: true } : {}),
200
+ ...(states === undefined ? {} : { states }),
201
+ };
202
+ };
203
+ export const runSessionList = (tokens, context) => Effect.gen(function* () {
204
+ const result = yield* context.dependencies.listSessions(readSessionList(tokens));
205
+ return writeSessionResult(result, context, (value) => ({
206
+ command: "session.list",
207
+ result: value,
208
+ }));
209
+ });
210
+ export const runSessionShow = (tokens, context) => Effect.gen(function* () {
211
+ const parsed = parseOptions(tokens, new Set());
212
+ requirePositionals(parsed.positionals, 1);
213
+ const sessionId = parsed.positionals[0];
214
+ if (sessionId === undefined) {
215
+ throw new CliArgumentError("The session identifier is missing.");
216
+ }
217
+ const result = yield* context.dependencies.showSession(sessionId);
218
+ return writeSessionResult(result, context, (value) => ({
219
+ command: "session.show",
220
+ result: value,
221
+ }));
222
+ });
223
+ const readLifecycleInput = (parsed) => {
224
+ const sessionId = parsed.positionals[0];
225
+ if (sessionId === undefined) {
226
+ throw new CliArgumentError("The session identifier is missing.");
227
+ }
228
+ const commandId = parsed.options.get("--command-id");
229
+ return {
230
+ expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
231
+ sessionId,
232
+ ...(commandId === undefined ? {} : { commandId }),
233
+ };
234
+ };
235
+ const parseSessionLifecycle = (verb, tokens, flags = new Set()) => {
236
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision"]), flags);
237
+ requirePositionals(parsed.positionals, 1);
238
+ return { flags: parsed.flags, input: readLifecycleInput(parsed) };
239
+ };
240
+ export const runSessionStart = (tokens, context) => Effect.gen(function* () {
241
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision", "--timeout"]), new Set(["--wait"]));
242
+ requirePositionals(parsed.positionals, 1);
243
+ const input = readLifecycleInput(parsed);
244
+ const wait = parsed.flags.has("--wait");
245
+ const timeout = parsed.options.get("--timeout");
246
+ if (timeout !== undefined && !wait)
247
+ throw new CliArgumentError("Option '--timeout' needs '--wait'.");
248
+ const deadlineMilliseconds = timeout === undefined
249
+ ? RUNNING_DEADLINE_MILLISECONDS
250
+ : readDuration(timeout, "--timeout", { max: 3600, min: 1 }) * 1000;
251
+ const result = yield* context.dependencies.startSession(input);
252
+ if (!wait || !result.ok)
253
+ return writeSessionResult(result, context, (value) => ({
254
+ command: "session.start",
255
+ result: summarizeSessionLifecycle(value),
256
+ }));
257
+ return yield* waitUntilRunning(result.value, context, deadlineMilliseconds);
258
+ });
259
+ const RUNNING_DEADLINE_MILLISECONDS = 120_000;
260
+ const EXIT_NOT_RUNNING = 70;
261
+ const EXIT_STILL_STARTING = 74;
262
+ const waitUntilRunning = (started, context, deadlineMilliseconds) => Effect.gen(function* () {
263
+ const { awaitSessionRunning } = context.dependencies;
264
+ if (awaitSessionRunning === undefined)
265
+ return yield* new CliArgumentError("Waiting for a Session is unavailable.");
266
+ const awaited = yield* awaitSessionRunning({
267
+ deadlineMilliseconds,
268
+ sessionId: started.session.id,
269
+ });
270
+ const code = writeSessionResult(awaited, context, (session) => ({
271
+ command: "session.start",
272
+ result: {
273
+ ...summarizeSessionLifecycle(started),
274
+ revision: session.revision,
275
+ state: session.state,
276
+ },
277
+ }));
278
+ if (code !== 0 || !awaited.ok || awaited.value.state === "running")
279
+ return code;
280
+ return awaited.value.state === "failed" ||
281
+ awaited.value.state.startsWith("stop")
282
+ ? EXIT_NOT_RUNNING
283
+ : EXIT_STILL_STARTING;
284
+ });
285
+ export const runSessionStop = (tokens, context) => Effect.gen(function* () {
286
+ const { input } = parseSessionLifecycle("stop", tokens);
287
+ const { stopSession } = context.dependencies;
288
+ if (stopSession === undefined)
289
+ throw new CliArgumentError("Session stop is unavailable.");
290
+ const result = yield* stopSession(input);
291
+ return writeSessionResult(result, context, (value) => ({
292
+ command: "session.stop",
293
+ result: summarizeSessionLifecycle(value),
294
+ }));
295
+ });
296
+ export const runSessionResume = (tokens, context) => Effect.gen(function* () {
297
+ const { input } = parseSessionLifecycle("resume", tokens);
298
+ const { resumeSession } = context.dependencies;
299
+ if (resumeSession === undefined)
300
+ throw new CliArgumentError("Session resume is unavailable.");
301
+ const result = yield* resumeSession(input);
302
+ return writeSessionResult(result, context, (value) => ({
303
+ command: "session.resume",
304
+ result: summarizeSessionLifecycle(value),
305
+ }));
306
+ });
307
+ export const runSessionEventsList = (tokens, context) => Effect.gen(function* () {
308
+ const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--session"]));
309
+ requirePositionals(parsed.positionals, 0);
310
+ const sessionId = requireSessionOption(parsed.options, "--session");
311
+ const result = yield* context.dependencies.listSessionEvents({
312
+ afterSessionCursor: readCursor(parsed.options.get("--after")),
313
+ limit: readSessionEventPageSize(parsed.options.get("--limit")),
314
+ sessionId,
315
+ });
316
+ return writeSessionResult(result, context, (value) => ({
317
+ command: "session.events.list",
318
+ result: value,
319
+ }));
320
+ });
321
+ const readStallAfter = (value) => value === undefined
322
+ ? undefined
323
+ : readDuration(value, "--stall-after", {
324
+ max: MAX_SESSION_STALL_AFTER_SECONDS,
325
+ min: MIN_SESSION_STALL_AFTER_SECONDS,
326
+ });
327
+ export const runSessionObserve = (tokens, context) => Effect.gen(function* () {
328
+ const parsed = parseOptions(tokens, new Set(["--stall-after"]));
329
+ if (parsed.positionals.length > MAX_SESSION_OBSERVE_IDS)
330
+ throw new CliArgumentError(`Observe at most ${String(MAX_SESSION_OBSERVE_IDS)} Sessions.`);
331
+ const stallAfterSeconds = readStallAfter(parsed.options.get("--stall-after"));
332
+ const { observeSessions } = context.dependencies;
333
+ if (observeSessions === undefined)
334
+ throw new CliArgumentError("Session observation is unavailable.");
335
+ const result = yield* observeSessions({
336
+ ...(parsed.positionals.length === 0
337
+ ? {}
338
+ : { sessionIds: parsed.positionals }),
339
+ ...(stallAfterSeconds === undefined ? {} : { stallAfterSeconds }),
340
+ });
341
+ return writeSessionResult(result, context, (value) => ({
342
+ command: "session.observe",
343
+ result: value,
344
+ }));
345
+ });
346
+ const requireSessionOption = (options, name) => {
347
+ const value = options.get(name);
348
+ if (value !== undefined)
349
+ return value;
350
+ throw new CliArgumentError(`Option '${name}' is required.`);
351
+ };
352
+ const requireAttachedFlag = (flags) => {
353
+ if (flags.has("--attached"))
354
+ return;
355
+ throw new CliArgumentError("Option '--attached' is required.");
356
+ };
357
+ const summarizeMessageSend = (result) => ({
358
+ delivery: result.delivery,
359
+ deliveryId: result.deliveryId,
360
+ mailboxId: result.mailboxId,
361
+ message: {
362
+ createdAt: result.message.createdAt,
363
+ digest: result.message.digest,
364
+ id: result.message.id,
365
+ recipientSessionId: result.message.recipientSessionId,
366
+ senderSessionId: result.message.senderSessionId,
367
+ workspaceId: result.message.workspaceId,
368
+ },
369
+ receipt: result.receipt,
370
+ sequence: result.sequence,
371
+ });
372
+ const readSessionMessageBody = (context) => {
373
+ if (context.io.stdin === undefined)
374
+ throw new CliArgumentError("Session message body requires standard input.");
375
+ return context.io.stdin({
376
+ label: "Session message body",
377
+ maxBytes: MAX_SESSION_MESSAGE_BODY_BYTES,
378
+ maxChunks: 256,
379
+ });
380
+ };
381
+ const parseSessionMessageSend = (tokens) => {
382
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--session", "--subject"]), new Set(["--attached", "--body-stdin"]));
383
+ requirePositionals(parsed.positionals, 0);
384
+ requireAttachedFlag(parsed.flags);
385
+ if (!parsed.flags.has("--body-stdin"))
386
+ throw new CliArgumentError("Option '--body-stdin' is required.");
387
+ const recipientSessionId = requireSessionOption(parsed.options, "--session");
388
+ const commandId = parsed.options.get("--command-id");
389
+ return {
390
+ ...(commandId === undefined ? {} : { commandId }),
391
+ recipientSessionId,
392
+ subject: requireSessionOption(parsed.options, "--subject"),
393
+ };
394
+ };
395
+ export const runSessionMessageSend = (tokens, context) => Effect.gen(function* () {
396
+ const input = parseSessionMessageSend(tokens);
397
+ const operation = context.dependencies.sendAttachedSessionMessage;
398
+ if (operation === undefined)
399
+ throw new CliArgumentError("Attached Session messaging is unavailable.");
400
+ const result = yield* operation({
401
+ ...input,
402
+ body: yield* readSessionMessageBody(context),
403
+ });
404
+ return writeSessionResult(result, context, (value) => ({
405
+ command: "session.message.send",
406
+ result: summarizeMessageSend(value),
407
+ }));
408
+ });
409
+ const projectInboxDelivery = (delivery) => ({
410
+ attemptCount: delivery.attemptCount,
411
+ deliveryId: delivery.id,
412
+ firstCheckedAt: delivery.firstCheckedAt,
413
+ lastCheckedAt: delivery.lastCheckedAt,
414
+ mailboxId: delivery.mailboxId,
415
+ message: delivery.message,
416
+ sequence: delivery.sequence,
417
+ });
418
+ const readSessionInboxLimit = (value) => {
419
+ if (!/^\d+$/u.test(value))
420
+ throw new CliArgumentError("Session inbox limit must be an integer.");
421
+ const limit = Number(value);
422
+ if (limit >= 1 && limit <= MAX_SESSION_INBOX_CHECK_LIMIT)
423
+ return limit;
424
+ throw new CliArgumentError(`Session inbox limit must be from 1 to ${String(MAX_SESSION_INBOX_CHECK_LIMIT)}.`);
425
+ };
426
+ const parseSessionInboxCheck = (tokens) => {
427
+ const parsed = parseOptions(tokens, new Set(["--limit"]), new Set(["--attached"]));
428
+ requirePositionals(parsed.positionals, 0);
429
+ requireAttachedFlag(parsed.flags);
430
+ const limit = parsed.options.get("--limit");
431
+ return {
432
+ ...(limit === undefined ? {} : { limit: readSessionInboxLimit(limit) }),
433
+ };
434
+ };
435
+ export const runSessionInboxCheck = (tokens, context) => Effect.gen(function* () {
436
+ const operation = context.dependencies.checkAttachedSessionInbox;
437
+ if (operation === undefined)
438
+ throw new CliArgumentError("Attached Session inbox is unavailable.");
439
+ const result = yield* operation(parseSessionInboxCheck(tokens));
440
+ return writeSessionResult(result, context, (value) => ({
441
+ command: "session.inbox.check",
442
+ result: {
443
+ count: value.deliveries.length,
444
+ deliveries: value.deliveries.map(projectInboxDelivery),
445
+ mailboxId: value.mailbox.id,
446
+ mailboxRevision: value.mailbox.revision,
447
+ },
448
+ }));
449
+ });
450
+ const summarizeInboxAck = (result) => ({
451
+ delivery: result.delivery,
452
+ deliveryRecord: {
453
+ acknowledgedAt: result.deliveryRecord.acknowledgedAt,
454
+ acknowledgingSessionId: result.deliveryRecord.acknowledgingSessionId,
455
+ deliveryId: result.deliveryRecord.id,
456
+ mailboxId: result.deliveryRecord.mailboxId,
457
+ messageId: result.deliveryRecord.message.id,
458
+ sequence: result.deliveryRecord.sequence,
459
+ },
460
+ mailboxId: result.mailboxId,
461
+ mailboxRevision: result.mailboxRevision,
462
+ receipt: result.receipt,
463
+ });
464
+ const parseSessionInboxAck = (tokens) => {
465
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-mailbox-revision"]), new Set(["--attached"]));
466
+ requirePositionals(parsed.positionals, 1);
467
+ requireAttachedFlag(parsed.flags);
468
+ const deliveryId = parsed.positionals[0];
469
+ if (deliveryId === undefined)
470
+ throw new CliArgumentError("The delivery identifier is missing.");
471
+ const commandId = parsed.options.get("--command-id");
472
+ return {
473
+ ...(commandId === undefined ? {} : { commandId }),
474
+ deliveryId,
475
+ expectedMailboxRevision: readExpectedRevision(parsed.options.get("--expected-mailbox-revision")),
476
+ };
477
+ };
478
+ export const runSessionInboxAck = (tokens, context) => Effect.gen(function* () {
479
+ const operation = context.dependencies.acknowledgeAttachedSessionDelivery;
480
+ if (operation === undefined)
481
+ throw new CliArgumentError("Attached Session acknowledgement is unavailable.");
482
+ const result = yield* operation(parseSessionInboxAck(tokens));
483
+ return writeSessionResult(result, context, (value) => ({
484
+ command: "session.inbox.ack",
485
+ result: summarizeInboxAck(value),
486
+ }));
487
+ });
488
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1,20 @@
1
+ import { type CommandContext, type CommandEffect } from "../command-line/index.js";
2
+ import type { CreateSessionInput } from "./client.js";
3
+ export type SessionTaskSource = {
4
+ readonly kind: "file";
5
+ readonly path: string;
6
+ } | {
7
+ readonly kind: "message";
8
+ readonly text: string;
9
+ } | {
10
+ readonly kind: "stdin";
11
+ };
12
+ export type SessionTasksRequest = {
13
+ readonly commandId?: string;
14
+ readonly projectId?: string;
15
+ readonly selection: Omit<CreateSessionInput, "workspaceId">;
16
+ readonly source: SessionTaskSource;
17
+ readonly workspaceId?: string;
18
+ };
19
+ export declare const runSessionTasks: (request: SessionTasksRequest, context: CommandContext) => CommandEffect;
20
+ //# sourceMappingURL=create-tasks.d.ts.map
@@ -0,0 +1,110 @@
1
+ import { MAX_SESSION_CREATION_TASKS, MAX_TURN_INPUT_BYTES, } from "@maiaos/sdk";
2
+ import { Effect } from "effect";
3
+ import { CliArgumentError, reportError, writeSuccess, } from "../command-line/index.js";
4
+ import { formatSessionTasks } from "./output/index.js";
5
+ import { readTaskFile } from "./task-file.js";
6
+ const EXIT_OUTCOME_UNKNOWN = 76;
7
+ const EXIT_REFUSED = 70;
8
+ const readText = (source, context) => {
9
+ if (source.kind === "message")
10
+ return Effect.succeed(source.text);
11
+ if (source.kind === "file")
12
+ return readTaskFile(source.path);
13
+ if (context.io.stdin === undefined)
14
+ return Effect.fail(new CliArgumentError("Standard input is unavailable."));
15
+ return context.io.stdin({
16
+ label: "Session task",
17
+ maxBytes: MAX_TURN_INPUT_BYTES,
18
+ maxChunks: 1024,
19
+ });
20
+ };
21
+ const refusalMessage = (refusal) => refusal.reason === "too_long"
22
+ ? `Task line ${String(refusal.line)} exceeds ${String(MAX_TURN_INPUT_BYTES)} bytes.`
23
+ : `A batch holds at most ${String(MAX_SESSION_CREATION_TASKS)} tasks; line ${String(refusal.line)} is beyond it.`;
24
+ const toInput = (request, text) => {
25
+ const { baseRef, connectionId, executor, model, role, title } = request.selection;
26
+ const { projectId, source, workspaceId } = request;
27
+ return {
28
+ ...(projectId === undefined ? {} : { projectId }),
29
+ session: {
30
+ ...(connectionId === undefined ? {} : { connectionId }),
31
+ ...(executor === undefined ? {} : { executor }),
32
+ ...(model === undefined ? {} : { model }),
33
+ ...(role === undefined ? {} : { role }),
34
+ ...(title === undefined ? {} : { title }),
35
+ ...(baseRef === undefined ? {} : { worktree: { baseRef } }),
36
+ },
37
+ split: source.kind === "file" ? "lines" : "whole",
38
+ text,
39
+ ...(workspaceId === undefined ? {} : { workspaceId }),
40
+ };
41
+ };
42
+ const reportItem = (plan, outcome) => {
43
+ const commandId = outcome.stage === "unknown" ? outcome.error?.commandId : undefined;
44
+ const { error, index, receipts, sessionId, stage, turnId } = outcome;
45
+ return {
46
+ ...(error === undefined ? {} : { error }),
47
+ line: plan.items[index]?.line ?? 0,
48
+ receipts,
49
+ ...(commandId === undefined ? {} : { recovery: { commandId } }),
50
+ ...(sessionId === undefined ? {} : { sessionId }),
51
+ stage,
52
+ ...(turnId === undefined ? {} : { turnId }),
53
+ };
54
+ };
55
+ const MAX_TASK_COMMAND_ID_LENGTH = 122;
56
+ const withCommandId = (plan, commandId) => {
57
+ if (commandId === undefined)
58
+ return plan;
59
+ if (plan.items.length !== 1)
60
+ throw new CliArgumentError("Option '--command-id' names one Session; the input holds several tasks.");
61
+ if (commandId.length > MAX_TASK_COMMAND_ID_LENGTH)
62
+ throw new CliArgumentError(`Option '--command-id' takes at most ${String(MAX_TASK_COMMAND_ID_LENGTH)} characters with a first message.`);
63
+ return {
64
+ ...plan,
65
+ items: plan.items.map((item) => ({
66
+ ...item,
67
+ commands: {
68
+ create: commandId,
69
+ send: `${commandId}.send`,
70
+ start: `${commandId}.start`,
71
+ },
72
+ })),
73
+ };
74
+ };
75
+ const exitCode = (items) => {
76
+ if (items.some((item) => item.stage === "unknown"))
77
+ return EXIT_OUTCOME_UNKNOWN;
78
+ return items.every((item) => item.stage === "sent" || item.stage === "started")
79
+ ? 0
80
+ : EXIT_REFUSED;
81
+ };
82
+ const writeBatch = (plan, outcomes, context) => {
83
+ const items = outcomes.map((outcome) => reportItem(plan, outcome));
84
+ const code = exitCode(items);
85
+ writeSuccess({
86
+ command: "session.create.tasks",
87
+ result: { items, workspaceId: plan.workspaceId },
88
+ }, { ...context, ok: code === 0 }, ({ result }) => formatSessionTasks(result));
89
+ return code;
90
+ };
91
+ export const runSessionTasks = (request, context) => Effect.gen(function* () {
92
+ const { planSessions, runSessions } = context.dependencies;
93
+ if (planSessions === undefined || runSessions === undefined)
94
+ return yield* new CliArgumentError("Session tasks are unavailable.");
95
+ const text = yield* readText(request.source, context);
96
+ if (text.trim() === "")
97
+ return yield* new CliArgumentError("The task text is empty.");
98
+ const planned = yield* planSessions(toInput(request, text));
99
+ if (!planned.ok)
100
+ return reportError(planned.error, context);
101
+ const plan = withCommandId(planned.value, request.commandId);
102
+ const [refusal] = plan.refusals;
103
+ if (refusal !== undefined)
104
+ return yield* new CliArgumentError(refusalMessage(refusal));
105
+ const ran = yield* runSessions(plan);
106
+ if (!ran.ok)
107
+ return reportError(ran.error, context);
108
+ return writeBatch(plan, ran.value, context);
109
+ });
110
+ //# sourceMappingURL=create-tasks.js.map
@@ -0,0 +1,9 @@
1
+ export { runAgentPermissionSet } from "./agent-permission.js";
2
+ export { runSessionAttach } from "./attach.js";
3
+ export type { AttachSessionInput, SessionAttachStream, } from "./attach-client.js";
4
+ export { type CreateSessionInput, type ListSessionsInput, makeSessionClient, type StartSessionInput, } from "./client.js";
5
+ export { type ArchiveSessionInput, type DiffSessionInput, } from "./coding-client.js";
6
+ export { runSessionArchive, runSessionDiff } from "./coding-commands.js";
7
+ export { runSessionCreate, runSessionEventsList, runSessionInboxAck, runSessionInboxCheck, runSessionList, runSessionMessageSend, runSessionObserve, runSessionResume, runSessionShow, runSessionStart, runSessionStop, } from "./commands.js";
8
+ export { runSessionRename } from "./rename.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export { runAgentPermissionSet } from "./agent-permission.js";
2
+ export { runSessionAttach } from "./attach.js";
3
+ export { makeSessionClient, } from "./client.js";
4
+ export { runSessionArchive, runSessionDiff } from "./coding-commands.js";
5
+ export { runSessionCreate, runSessionEventsList, runSessionInboxAck, runSessionInboxCheck, runSessionList, runSessionMessageSend, runSessionObserve, runSessionResume, runSessionShow, runSessionStart, runSessionStop, } from "./commands.js";
6
+ export { runSessionRename } from "./rename.js";
7
+ //# sourceMappingURL=index.js.map