@maiaos/cli 0.1.0-canary.64 → 0.1.0-canary.66

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 (334) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -9
  3. package/dist/address-space/address-space.js +21 -2
  4. package/dist/address-space/index.js +1 -1
  5. package/dist/agents/client.d.ts +1 -0
  6. package/dist/agents/tree/tree.js +3 -3
  7. package/dist/bin/maia.NOTICES.txt +1 -1
  8. package/dist/bin/maia.cdx.json +70 -19
  9. package/dist/bin/maia.mjs +1 -1
  10. package/dist/board/client.d.ts +27 -0
  11. package/dist/board/client.js +40 -0
  12. package/dist/board/commands.d.ts +28 -0
  13. package/dist/board/commands.js +52 -0
  14. package/dist/board/index.d.ts +3 -0
  15. package/dist/board/index.js +3 -0
  16. package/dist/board/input.js +339 -0
  17. package/dist/board/output/format.js +175 -0
  18. package/dist/board/output/index.js +2 -0
  19. package/dist/board/plan.js +47 -0
  20. package/dist/board/tree/index.js +2 -0
  21. package/dist/board/tree/tree.js +161 -0
  22. package/dist/cli/cli.d.ts +3 -1
  23. package/dist/cli/cli.js +175 -6
  24. package/dist/cli/log-level.d.ts +11 -0
  25. package/dist/cli/log-level.js +14 -0
  26. package/dist/command-line/context.d.ts +18 -5
  27. package/dist/command-line/emit/output.d.ts +5 -1
  28. package/dist/command-line/emit/output.js +13 -5
  29. package/dist/command-line/index.d.ts +2 -2
  30. package/dist/command-line/index.js +1 -2
  31. package/dist/command-line/input/arguments.d.ts +3 -0
  32. package/dist/command-line/input/arguments.js +12 -0
  33. package/dist/command-line/input/index.d.ts +2 -2
  34. package/dist/command-line/input/index.js +2 -2
  35. package/dist/command-line/input/prompt.d.ts +1 -0
  36. package/dist/command-line/input/prompt.js +1 -0
  37. package/dist/command-line/two-phase/two-phase.d.ts +4 -4
  38. package/dist/command-line/two-phase/two-phase.js +9 -9
  39. package/dist/command-tree/commands.js +0 -4
  40. package/dist/command-tree/deprecated.d.ts +2 -0
  41. package/dist/command-tree/deprecated.js +29 -0
  42. package/dist/command-tree/grammar.js +2 -0
  43. package/dist/command-tree/help.d.ts +2 -2
  44. package/dist/command-tree/help.js +13 -15
  45. package/dist/command-tree/index.d.ts +1 -0
  46. package/dist/command-tree/index.js +1 -0
  47. package/dist/command-tree/local.js +10 -5
  48. package/dist/command-tree/placeholder.js +1 -1
  49. package/dist/command-tree/row.d.ts +1 -0
  50. package/dist/command-tree/tree.d.ts +2 -1
  51. package/dist/command-tree/tree.js +30 -4
  52. package/dist/connection/client.d.ts +36 -18
  53. package/dist/connection/client.js +1 -0
  54. package/dist/connection/executors/executors.d.ts +18 -0
  55. package/dist/connection/executors/executors.js +95 -0
  56. package/dist/connection/executors/index.d.ts +2 -0
  57. package/dist/connection/executors/index.js +2 -0
  58. package/dist/connection/executors/reading.js +22 -0
  59. package/dist/connection/index.d.ts +1 -0
  60. package/dist/connection/index.js +1 -0
  61. package/dist/connection/input.js +2 -2
  62. package/dist/connection/login.d.ts +1 -1
  63. package/dist/connection/login.js +4 -3
  64. package/dist/connection/output/format.js +2 -2
  65. package/dist/connection/output/index.d.ts +1 -1
  66. package/dist/connection/output/index.js +1 -1
  67. package/dist/connection/resolve.d.ts +1 -0
  68. package/dist/connection/setup-file.js +161 -0
  69. package/dist/connection/system.js +90 -45
  70. package/dist/connection/tree/tree.js +120 -7
  71. package/dist/container/client.d.ts +2 -0
  72. package/dist/fleet/fleet.d.ts +7 -8
  73. package/dist/fleet/fleet.js +18 -6
  74. package/dist/fleet/index.d.ts +1 -1
  75. package/dist/fleet/index.js +1 -1
  76. package/dist/github/client.d.ts +189 -0
  77. package/dist/github/client.js +16 -0
  78. package/dist/github/commands.d.ts +17 -0
  79. package/dist/github/commands.js +81 -0
  80. package/dist/github/index.d.ts +3 -0
  81. package/dist/github/index.js +3 -0
  82. package/dist/github/input.js +114 -0
  83. package/dist/github/output/format.js +78 -0
  84. package/dist/github/output/index.js +2 -0
  85. package/dist/github/tree/index.js +2 -0
  86. package/dist/github/tree/tree.js +28 -0
  87. package/dist/goal/client.d.ts +246 -0
  88. package/dist/goal/client.js +13 -0
  89. package/dist/goal/commands.d.ts +22 -0
  90. package/dist/goal/commands.js +110 -0
  91. package/dist/goal/index.d.ts +4 -0
  92. package/dist/goal/index.js +4 -0
  93. package/dist/goal/input.js +118 -0
  94. package/dist/goal/output/format.js +29 -0
  95. package/dist/goal/output/index.js +2 -0
  96. package/dist/goal/pause.d.ts +16 -0
  97. package/dist/goal/pause.js +91 -0
  98. package/dist/goal/tree/index.js +2 -0
  99. package/dist/goal/tree/tree.js +49 -0
  100. package/dist/hold/client.d.ts +2 -0
  101. package/dist/hold/tree/tree.js +2 -2
  102. package/dist/import/{batch.js → batch/batch.js} +5 -5
  103. package/dist/import/batch/index.js +3 -0
  104. package/dist/import/{manifest.js → batch/manifest.js} +7 -6
  105. package/dist/import/commands.d.ts +1 -0
  106. package/dist/import/commands.js +27 -15
  107. package/dist/import/detach.d.ts +12 -0
  108. package/dist/import/detach.js +70 -0
  109. package/dist/import/index.d.ts +2 -1
  110. package/dist/import/index.js +2 -1
  111. package/dist/import/input.js +32 -10
  112. package/dist/import/output.js +13 -8
  113. package/dist/inbox/client.d.ts +310 -0
  114. package/dist/inbox/client.js +15 -0
  115. package/dist/inbox/index.d.ts +2 -0
  116. package/dist/inbox/index.js +2 -0
  117. package/dist/integration/client.d.ts +307 -1
  118. package/dist/integration/client.js +21 -1
  119. package/dist/integration/commands.d.ts +8 -0
  120. package/dist/integration/commands.js +53 -10
  121. package/dist/integration/index.d.ts +1 -1
  122. package/dist/integration/index.js +1 -1
  123. package/dist/local-node/client.d.ts +11 -1
  124. package/dist/local-node/client.js +185 -235
  125. package/dist/local-node/index.d.ts +1 -1
  126. package/dist/local-node/index.js +1 -1
  127. package/dist/login/commands.js +7 -1
  128. package/dist/login/gateway.js +34 -11
  129. package/dist/login/menu.js +2 -1
  130. package/dist/login/vendor-account.js +3 -2
  131. package/dist/login/vendor-input.js +3 -2
  132. package/dist/mcp/calls.js +47 -226
  133. package/dist/mcp/routing.d.ts +3 -2
  134. package/dist/mcp/routing.js +37 -8
  135. package/dist/mcp/server.d.ts +10 -1
  136. package/dist/mcp/server.js +16 -6
  137. package/dist/migrate/classes.js +158 -0
  138. package/dist/migrate/commands.js +46 -0
  139. package/dist/migrate/format.js +199 -0
  140. package/dist/migrate/index.js +2 -0
  141. package/dist/migrate/item.js +59 -0
  142. package/dist/migrate/plan.js +79 -0
  143. package/dist/migrate/tree/index.js +2 -0
  144. package/dist/migrate/tree/tree.js +23 -0
  145. package/dist/node-update/client.d.ts +17 -0
  146. package/dist/node-update/client.js +27 -0
  147. package/dist/node-update/commands.d.ts +20 -0
  148. package/dist/node-update/commands.js +150 -0
  149. package/dist/node-update/index.d.ts +4 -0
  150. package/dist/node-update/index.js +4 -0
  151. package/dist/node-update/output.d.ts +12 -0
  152. package/dist/node-update/output.js +165 -0
  153. package/dist/node-update/tree/index.js +2 -0
  154. package/dist/node-update/tree/tree.js +73 -0
  155. package/dist/pairing/client.d.ts +13 -0
  156. package/dist/pairing/client.js +36 -0
  157. package/dist/pairing/commands.d.ts +15 -0
  158. package/dist/pairing/commands.js +131 -0
  159. package/dist/pairing/index.d.ts +4 -0
  160. package/dist/pairing/index.js +4 -0
  161. package/dist/pairing/output.d.ts +12 -0
  162. package/dist/pairing/output.js +53 -0
  163. package/dist/pairing/tree/index.js +2 -0
  164. package/dist/pairing/tree/tree.js +35 -0
  165. package/dist/panel/client.d.ts +9 -0
  166. package/dist/panel/client.js +24 -0
  167. package/dist/panel/commands.d.ts +19 -0
  168. package/dist/panel/commands.js +112 -0
  169. package/dist/panel/index.d.ts +3 -0
  170. package/dist/panel/index.js +3 -0
  171. package/dist/panel/tree/index.js +2 -0
  172. package/dist/panel/tree/tree.js +14 -0
  173. package/dist/port-lease/client.d.ts +3 -0
  174. package/dist/principal/client.d.ts +9 -0
  175. package/dist/principal/client.js +7 -0
  176. package/dist/principal/commands.d.ts +14 -0
  177. package/dist/principal/commands.js +84 -0
  178. package/dist/principal/index.d.ts +4 -0
  179. package/dist/principal/index.js +4 -0
  180. package/dist/principal/output.d.ts +8 -0
  181. package/dist/principal/output.js +43 -0
  182. package/dist/principal/tree/index.js +2 -0
  183. package/dist/principal/tree/tree.js +31 -0
  184. package/dist/project-guard/client.d.ts +1 -0
  185. package/dist/project-instructions/client.d.ts +56 -0
  186. package/dist/project-instructions/client.js +7 -0
  187. package/dist/project-instructions/commands.d.ts +13 -0
  188. package/dist/project-instructions/commands.js +89 -0
  189. package/dist/project-instructions/index.d.ts +3 -0
  190. package/dist/project-instructions/index.js +3 -0
  191. package/dist/project-instructions/input.js +33 -0
  192. package/dist/project-instructions/output/format.js +22 -0
  193. package/dist/project-instructions/output/index.js +2 -0
  194. package/dist/project-knowledge/change.js +22 -0
  195. package/dist/project-knowledge/client.d.ts +127 -0
  196. package/dist/project-knowledge/client.js +17 -0
  197. package/dist/project-knowledge/commands.d.ts +14 -0
  198. package/dist/project-knowledge/commands.js +100 -0
  199. package/dist/project-knowledge/index.d.ts +3 -0
  200. package/dist/project-knowledge/index.js +3 -0
  201. package/dist/project-knowledge/input.js +32 -0
  202. package/dist/project-knowledge/output/format.js +64 -0
  203. package/dist/project-knowledge/output/index.js +2 -0
  204. package/dist/project-knowledge/sources.js +108 -0
  205. package/dist/project-knowledge/upload.js +27 -0
  206. package/dist/project-workspace/git-reads.d.ts +12 -0
  207. package/dist/project-workspace/git-reads.js +71 -0
  208. package/dist/project-workspace/index.d.ts +1 -0
  209. package/dist/project-workspace/index.js +1 -0
  210. package/dist/project-workspace/metadata-client.d.ts +2 -0
  211. package/dist/project-workspace/output/human.js +1 -1
  212. package/dist/project-workspace/tree/tree.js +95 -5
  213. package/dist/reach/client.d.ts +9 -0
  214. package/dist/reach/client.js +7 -0
  215. package/dist/reach/commands.d.ts +14 -0
  216. package/dist/reach/commands.js +72 -0
  217. package/dist/reach/index.d.ts +3 -0
  218. package/dist/reach/index.js +3 -0
  219. package/dist/reach/output.js +41 -0
  220. package/dist/reach/tree/index.js +2 -0
  221. package/dist/reach/tree/tree.js +28 -0
  222. package/dist/remote-node/client.d.ts +85 -0
  223. package/dist/remote-node/commands.js +32 -17
  224. package/dist/remote-node/connector.d.ts +16 -0
  225. package/dist/remote-node/connector.js +2 -2
  226. package/dist/remote-node/reachability.js +31 -18
  227. package/dist/remote-node/reading.js +31 -0
  228. package/dist/remote-node/text.js +68 -5
  229. package/dist/remote-node/tree/tree.js +14 -3
  230. package/dist/routine/client.d.ts +547 -13
  231. package/dist/routine/client.js +19 -1
  232. package/dist/routine/commands.d.ts +5 -0
  233. package/dist/routine/commands.js +73 -15
  234. package/dist/routine/index.d.ts +2 -1
  235. package/dist/routine/index.js +2 -1
  236. package/dist/routine/input.js +66 -3
  237. package/dist/routine/output/format.js +80 -19
  238. package/dist/routine/output/index.js +1 -1
  239. package/dist/routine/portable/import-files.js +74 -0
  240. package/dist/routine/portable/import-output.js +21 -0
  241. package/dist/routine/portable/import.js +274 -0
  242. package/dist/routine/portable/index.js +3 -0
  243. package/dist/routine/portable/portable.js +185 -0
  244. package/dist/routine/tree/tree.js +80 -8
  245. package/dist/routine/trigger/commands.d.ts +20 -0
  246. package/dist/routine/trigger/commands.js +74 -0
  247. package/dist/routine/trigger/format.js +42 -0
  248. package/dist/routine/trigger/index.d.ts +2 -0
  249. package/dist/routine/trigger/index.js +2 -0
  250. package/dist/routine/trigger/input.js +81 -0
  251. package/dist/run-ledger/client.d.ts +45 -0
  252. package/dist/secret/client.d.ts +39 -0
  253. package/dist/secret/client.js +6 -0
  254. package/dist/secret/commands.d.ts +12 -0
  255. package/dist/secret/commands.js +91 -0
  256. package/dist/secret/index.d.ts +3 -0
  257. package/dist/secret/index.js +3 -0
  258. package/dist/secret/input.js +22 -0
  259. package/dist/secret/output/format.js +10 -0
  260. package/dist/secret/output/index.js +2 -0
  261. package/dist/secret/tree/index.js +2 -0
  262. package/dist/secret/tree/tree.js +16 -0
  263. package/dist/session/agent-permission.d.ts +3 -2
  264. package/dist/session/approval/client.d.ts +4 -3
  265. package/dist/session/approval/commands.d.ts +7 -0
  266. package/dist/session/approval/commands.js +176 -6
  267. package/dist/session/approval/index.d.ts +1 -1
  268. package/dist/session/approval/index.js +1 -1
  269. package/dist/session/approval/output/format.js +53 -1
  270. package/dist/session/approval/output/index.js +1 -1
  271. package/dist/session/attach.d.ts +1 -1
  272. package/dist/session/attach.js +7 -2
  273. package/dist/session/client.d.ts +12 -12
  274. package/dist/session/client.js +8 -17
  275. package/dist/session/command/commands.js +109 -0
  276. package/dist/session/command/index.js +2 -0
  277. package/dist/session/commands.d.ts +5 -1
  278. package/dist/session/commands.js +273 -57
  279. package/dist/session/create-tasks.js +3 -48
  280. package/dist/session/creation/creation.js +51 -0
  281. package/dist/session/creation/index.js +2 -0
  282. package/dist/session/fork/fork.js +135 -0
  283. package/dist/session/fork/index.js +2 -0
  284. package/dist/session/git-status.d.ts +11 -0
  285. package/dist/session/git-status.js +30 -0
  286. package/dist/session/index.d.ts +4 -3
  287. package/dist/session/index.js +3 -2
  288. package/dist/session/interaction/client.d.ts +3 -0
  289. package/dist/session/move/index.js +2 -0
  290. package/dist/session/move/move.js +439 -0
  291. package/dist/session/output/held.js +28 -0
  292. package/dist/session/output/human.js +34 -7
  293. package/dist/session/output/tasks.js +23 -6
  294. package/dist/session/setup/index.js +2 -0
  295. package/dist/session/setup/setup.js +69 -0
  296. package/dist/session/spawn/caps.js +128 -0
  297. package/dist/session/spawn/index.js +5 -0
  298. package/dist/session/spawn/spawn.js +203 -0
  299. package/dist/session/spawn/standing.js +62 -0
  300. package/dist/session/spawn/supervision.js +62 -0
  301. package/dist/session/switch/index.js +2 -0
  302. package/dist/session/switch/switch.js +103 -0
  303. package/dist/session/tree/tree.js +280 -18
  304. package/dist/session/turn/attachments.js +54 -0
  305. package/dist/session/turn/client.d.ts +3 -1
  306. package/dist/session/turn/client.js +6 -1
  307. package/dist/session/turn/commands.d.ts +5 -1
  308. package/dist/session/turn/commands.js +148 -27
  309. package/dist/session/turn/index.d.ts +2 -2
  310. package/dist/session/turn/index.js +1 -1
  311. package/dist/session/turn/output.d.ts +25 -1
  312. package/dist/session/turn/output.js +33 -0
  313. package/dist/skills-sync/client.d.ts +9 -0
  314. package/dist/skills-sync/client.js +7 -0
  315. package/dist/skills-sync/commands.d.ts +15 -0
  316. package/dist/skills-sync/commands.js +241 -0
  317. package/dist/skills-sync/index.d.ts +3 -0
  318. package/dist/skills-sync/index.js +3 -0
  319. package/dist/skills-sync/output.js +168 -0
  320. package/dist/skills-sync/set-file.js +23 -0
  321. package/dist/skills-sync/tree/index.js +2 -0
  322. package/dist/skills-sync/tree/tree.js +38 -0
  323. package/dist/status/client.d.ts +7 -0
  324. package/dist/status/command.js +3 -2
  325. package/dist/status/doctor.js +4 -3
  326. package/dist/team-workspace/client.d.ts +1 -0
  327. package/dist/text-input/index.js +2 -0
  328. package/dist/text-input/text-input.js +35 -0
  329. package/dist/webhooks/client.d.ts +10 -9
  330. package/dist/webhooks/input.js +2 -2
  331. package/dist/webhooks/tree/tree.js +4 -4
  332. package/guidance/maia-sessions/SKILL.md +37 -3
  333. package/package.json +6 -5
  334. package/dist/command-line/context.js +0 -2
@@ -1,19 +1,22 @@
1
- import { MAX_SESSION_INBOX_CHECK_LIMIT, MAX_SESSION_MESSAGE_BODY_BYTES, MAX_SESSION_OBSERVE_IDS, MAX_SESSION_SETTLED_IDLE_SECONDS, MAX_SESSION_STALL_AFTER_SECONDS, MIN_SESSION_STALL_AFTER_SECONDS, SESSION_EFFORT_LEVELS, sessionBaseRefSchema, sessionCreateParametersSchema, } from "@maiaos/sdk";
2
- import { Effect } from "effect";
3
- import { listEach, writeMerged } from "../address-space/index.js";
4
- import { CliArgumentError, LABEL_OPTION, parseOptions, parseOptionsWith, readCursor, readDuration, readExpectedRevision, readLabels, readPageSize, readPermission, readSessionRole, readSessionTitle, readWaitTimeoutSeconds, requireOneLabelPerOption, requirePositionals, writeNodeResult, } from "../command-line/index.js";
5
- import { mergeLists } from "../fleet/index.js";
1
+ import { connectionModelIdSchema, EXECUTOR_IDS, MAX_SESSION_INBOX_CHECK_LIMIT, MAX_SESSION_MESSAGE_BODY_BYTES, MAX_SESSION_OBSERVE_IDS, MAX_SESSION_SETTLED_IDLE_SECONDS, MAX_SESSION_STALL_AFTER_SECONDS, MIN_SESSION_STALL_AFTER_SECONDS, SESSION_EFFORT_LEVELS, sessionAcceptsModel, sessionBaseRefSchema, sessionBranchNameSchema, sessionCreateParametersSchema, sessionEffortLevels, sessionExecutorKindSchema, } from "@maiaos/sdk";
2
+ import { Clock, Effect } from "effect";
3
+ import { everyNode, everyNodeName, formatMerged, listEach, writeMerged, } from "../address-space/index.js";
4
+ import { cell, CliArgumentError, exitCodeOf, formatRows, LABEL_OPTION, LOCAL_NODE, parseOptions, parseOptionsWith, readCursor, readDuration, readExpectedRevision, readLabels, readOptionalRevision, readPageSize, readPermission, readSessionRole, readSessionTitle, readWaitTimeoutSeconds, requireOneLabelPerOption, requirePositionals, writeNodeResult, writeSuccess, } from "../command-line/index.js";
5
+ import { freshnessOf, mergeLists } from "../fleet/index.js";
6
+ import { changeAtRevision, } from "../local-node/index.js";
6
7
  import { runSessionTasks, } from "./create-tasks.js";
7
- import { formatMergedSessions, formatSessionShow, writeSessionResult, } from "./output/index.js";
8
+ import { formatMergedSessions, formatSessionResult, formatSessionShow, writeSessionResult, } from "./output/index.js";
9
+ import { cancelChildren, readResumeParent, reconcileChildren, resumeSupervised, runSessionSpawn as runSpawn, } from "./spawn/index.js";
8
10
  const EXIT_DEADLINE = 74;
9
11
  const SESSION_CREATE_OPTIONS = new Set([
10
12
  "--agent",
11
13
  "--base",
14
+ "--branch",
12
15
  "--command-id",
13
16
  "--connection",
14
17
  "--cwd",
15
18
  "--effort",
16
- "--executor",
19
+ "--harness",
17
20
  "--label",
18
21
  "--model",
19
22
  "--name",
@@ -74,7 +77,7 @@ const readSessionCreateOptions = (parsed) => {
74
77
  const workspaceId = parsed.options.get("--workspace");
75
78
  if (workspaceId === undefined)
76
79
  throw new CliArgumentError(parsed.options.has("--project")
77
- ? "Option '--project' needs '--message', '--prompt-stdin' or '--from-file'; name a Workspace with '--workspace' otherwise."
80
+ ? "Option '--project' needs '--text', '--prompt-stdin' or '--from-file'; name a Workspace with '--workspace' otherwise."
78
81
  : "Option '--workspace' is required.");
79
82
  const input = readSessionSelection(parsed, workspaceId);
80
83
  const definition = readDefinitionSelection(parsed.options, input);
@@ -84,27 +87,40 @@ const readSessionCreateOptions = (parsed) => {
84
87
  const requireOneSelection = (input) => {
85
88
  if (input.definitionRef !== undefined &&
86
89
  (input.connectionId !== undefined || input.executor !== undefined))
87
- throw new CliArgumentError("Use one of '--connection', '--executor' or '--agent-definition'.");
88
- if (input.model !== undefined && input.connectionId === undefined)
89
- throw new CliArgumentError("Option '--model' needs '--connection' with a gateway connection.");
90
+ throw new CliArgumentError("Use one of '--connection', '--harness' or '--agent-definition'.");
91
+ requireModelSelection(input);
90
92
  requireSupportedEffort(input);
91
93
  };
94
+ const requireModelSelection = ({ connectionId, executor, model, }) => {
95
+ if (model === undefined)
96
+ return;
97
+ if (!connectionModelIdSchema.safeParse(model).success)
98
+ throw new CliArgumentError("Option '--model' must be a model id of up to 256 letters, digits and '._:/@-', starting with a letter or digit.");
99
+ if (connectionId !== undefined)
100
+ return;
101
+ if (executor === undefined)
102
+ throw new CliArgumentError("Option '--model' needs '--connection' or '--harness'.");
103
+ if (!sessionAcceptsModel(executor))
104
+ throw new CliArgumentError(`The ${executor} executor takes no model.`);
105
+ };
92
106
  const requireSupportedEffort = ({ connectionId, effort, executor, }) => {
93
107
  if (effort === undefined)
94
108
  return;
95
109
  if (connectionId === undefined && executor === undefined)
96
- throw new CliArgumentError("Option '--effort' needs '--connection' or '--executor'.");
97
- const levels = executor === undefined ? [] : SESSION_EFFORT_LEVELS[executor];
110
+ throw new CliArgumentError("Option '--effort' needs '--connection' or '--harness'.");
111
+ const levels = executor === undefined ? [] : sessionEffortLevels(executor);
98
112
  if (executor !== undefined && !levels.includes(effort))
99
- throw new CliArgumentError(`Executor ${executor} supports effort ${levels.join(", ")}.`);
113
+ throw new CliArgumentError(levels.length === 0
114
+ ? `The ${executor} executor declares no effort levels.`
115
+ : `Executor ${executor} supports effort ${levels.join(", ")}.`);
100
116
  };
101
117
  const readEffort = (value) => {
102
118
  if (value === undefined)
103
119
  return;
104
- const level = SESSION_EFFORT_LEVELS["codex-cli"].find((candidate) => candidate === value);
120
+ const level = SESSION_EFFORT_LEVELS[EXECUTOR_IDS.codex].find((candidate) => candidate === value);
105
121
  if (level !== undefined)
106
122
  return level;
107
- throw new CliArgumentError(`Option '--effort' must be ${SESSION_EFFORT_LEVELS["codex-cli"].slice(0, -1).join(", ")} or ${SESSION_EFFORT_LEVELS["codex-cli"].at(-1) ?? "ultra"}.`);
123
+ throw new CliArgumentError(`Option '--effort' must be ${SESSION_EFFORT_LEVELS[EXECUTOR_IDS.codex].slice(0, -1).join(", ")} or ${SESSION_EFFORT_LEVELS[EXECUTOR_IDS.codex].at(-1) ?? "ultra"}.`);
108
124
  };
109
125
  const AGENT_FIXED_OPTIONS = [
110
126
  "--agent-definition",
@@ -112,7 +128,7 @@ const AGENT_FIXED_OPTIONS = [
112
128
  "--agent-definition-version",
113
129
  "--connection",
114
130
  "--effort",
115
- "--executor",
131
+ "--harness",
116
132
  "--model",
117
133
  ];
118
134
  const readAgentId = (options) => {
@@ -128,7 +144,7 @@ const readSessionSelection = ({ flags, options }, workspaceId) => {
128
144
  const agent = readAgentId(options);
129
145
  const commandId = options.get("--command-id");
130
146
  const connectionId = options.get("--connection");
131
- const executor = readExecutorKind(options.get("--executor"));
147
+ const executor = readExecutorKind(options.get("--harness"));
132
148
  const effort = readEffort(options.get("--effort"));
133
149
  const cwd = options.get("--cwd");
134
150
  const model = options.get("--model");
@@ -147,8 +163,7 @@ const readSessionSelection = ({ flags, options }, workspaceId) => {
147
163
  ...readHostAuthority({ flags, options }),
148
164
  workspaceId,
149
165
  };
150
- const baseRef = readBaseRef(options.get("--base"), selection);
151
- return { ...selection, ...(baseRef === undefined ? {} : { baseRef }) };
166
+ return { ...selection, ...readWorktreeOptions(options, selection) };
152
167
  };
153
168
  const validPermission = (permission, executor) => {
154
169
  const valid = sessionCreateParametersSchema.safeParse({
@@ -172,11 +187,19 @@ const readHostAuthority = ({ flags, options, }) => {
172
187
  }
173
188
  if (options.has("--base"))
174
189
  throw new CliArgumentError("Option '--host-authority' runs in an existing '--cwd', not a Maia worktree; drop '--base'.");
175
- if (!options.has("--connection") && !options.has("--executor"))
176
- throw new CliArgumentError("Option '--host-authority' needs '--connection' or '--executor'.");
190
+ if (!options.has("--connection") && !options.has("--harness"))
191
+ throw new CliArgumentError("Option '--host-authority' needs '--connection' or '--harness'.");
177
192
  return {
178
193
  hostAuthority: true,
179
- ...readPermission(permission, (value) => validPermission(value, readExecutorKind(options.get("--executor")))),
194
+ ...readPermission(permission, (value) => validPermission(value, readExecutorKind(options.get("--harness")))),
195
+ };
196
+ };
197
+ const readWorktreeOptions = (options, selection) => {
198
+ const baseRef = readBaseRef(options.get("--base"), selection);
199
+ const branch = readBranch(options.get("--branch"), baseRef);
200
+ return {
201
+ ...(baseRef === undefined ? {} : { baseRef }),
202
+ ...(branch === undefined ? {} : { branch }),
180
203
  };
181
204
  };
182
205
  const readBaseRef = (value, selection) => {
@@ -185,15 +208,27 @@ const readBaseRef = (value, selection) => {
185
208
  if (selection.agentId === undefined &&
186
209
  selection.connectionId === undefined &&
187
210
  selection.executor === undefined)
188
- throw new CliArgumentError("Option '--base' needs '--agent', '--connection' or '--executor'.");
211
+ throw new CliArgumentError("Option '--base' needs '--agent', '--connection' or '--harness'.");
189
212
  if (sessionBaseRefSchema.safeParse(value).success)
190
213
  return value;
191
214
  throw new CliArgumentError("Option '--base' must name a branch, tag or commit without ranges, revision suffixes or a leading dash.");
192
215
  };
216
+ const readBranch = (value, baseRef) => {
217
+ if (value === undefined)
218
+ return;
219
+ if (baseRef === undefined)
220
+ throw new CliArgumentError("Option '--branch' needs '--base'.");
221
+ if (sessionBranchNameSchema.safeParse(value).success)
222
+ return value;
223
+ throw new CliArgumentError("Option '--branch' must be 'maia/<name>' of up to 160 characters: letters, digits, '_', '-' and single inner dots, not ending in '.lock'.");
224
+ };
193
225
  const readExecutorKind = (value) => {
194
- if (value === undefined || value === "codex-cli" || value === "claude-code")
226
+ if (value === undefined)
195
227
  return value;
196
- throw new CliArgumentError("Option '--executor' must be codex-cli or claude-code.");
228
+ const valid = sessionExecutorKindSchema.safeParse(value);
229
+ if (valid.success)
230
+ return valid.data;
231
+ throw new CliArgumentError("Option '--harness' must be an executor id: lowercase letters, digits and dashes, starting with a letter, such as codex-cli or claude-code.");
197
232
  };
198
233
  const readDefinitionSelection = (options, input) => {
199
234
  const key = options.get("--agent-definition");
@@ -218,23 +253,28 @@ const readDefinitionSelection = (options, input) => {
218
253
  const TASK_OPTIONS = new Set([
219
254
  ...SESSION_CREATE_OPTIONS,
220
255
  "--from-file",
221
- "--message",
256
+ "--text",
222
257
  "--project",
223
258
  "--workspace",
224
259
  ]);
260
+ const requireOneSessionOptions = (options) => {
261
+ if (options.has("--title") || options.has("--name"))
262
+ throw new CliArgumentError("Option '--title' or '--name' names one Session; with '--from-file' each Session takes its task's first line.");
263
+ if (options.has("--label"))
264
+ throw new CliArgumentError("Option '--label' labels one Session; it cannot be used with '--from-file'.");
265
+ if (options.has("--branch"))
266
+ throw new CliArgumentError("Option '--branch' names one Session's branch; it cannot be used with '--from-file'.");
267
+ };
225
268
  const taskSource = (parsed) => {
226
269
  const file = parsed.options.get("--from-file");
227
- const message = parsed.options.get("--message");
270
+ const message = parsed.options.get("--text");
228
271
  const stdin = parsed.flags.has("--prompt-stdin");
229
272
  if ([file, message, stdin ? "" : undefined].filter((value) => value !== undefined).length > 1)
230
- throw new CliArgumentError("Use one of '--message', '--prompt-stdin' or '--from-file'.");
231
- if (file !== undefined &&
232
- (parsed.options.has("--title") || parsed.options.has("--name")))
233
- throw new CliArgumentError("Option '--title' or '--name' names one Session; with '--from-file' each Session takes its task's first line.");
234
- if (file !== undefined && parsed.options.has("--label"))
235
- throw new CliArgumentError("Option '--label' labels one Session; it cannot be used with '--from-file'.");
236
- if (file !== undefined)
273
+ throw new CliArgumentError("Use one of '--text', '--prompt-stdin' or '--from-file'.");
274
+ if (file !== undefined) {
275
+ requireOneSessionOptions(parsed.options);
237
276
  return { kind: "file", path: file };
277
+ }
238
278
  if (message !== undefined)
239
279
  return { kind: "message", text: message };
240
280
  return stdin ? { kind: "stdin" } : undefined;
@@ -247,7 +287,7 @@ const readTaskWorkspace = (parsed, source) => {
247
287
  if (parsed.options.has("--agent-definition"))
248
288
  throw new CliArgumentError("Option '--agent-definition' does not apply to Session tasks.");
249
289
  if (parsed.options.has("--command-id") && source.kind === "file")
250
- throw new CliArgumentError("Option '--command-id' names one Session; use it with '--message' or '--prompt-stdin'.");
290
+ throw new CliArgumentError("Option '--command-id' names one Session; use it with '--text' or '--prompt-stdin'.");
251
291
  return named;
252
292
  };
253
293
  const readSessionTasks = (parsed, source) => {
@@ -298,6 +338,15 @@ const readSettled = ({ flags, options, }) => {
298
338
  settled: true,
299
339
  };
300
340
  };
341
+ const requireOneScope = (projectId, flags) => {
342
+ const everyProject = flags.has("--all") || flags.has("--all-nodes");
343
+ if ((projectId === undefined) === !everyProject)
344
+ throw new CliArgumentError("Use one of '--project', '--all' or '--all-nodes'.");
345
+ };
346
+ const readParent = (options) => {
347
+ const parentSessionId = options.get("--parent");
348
+ return parentSessionId === undefined ? {} : { parentSessionId };
349
+ };
301
350
  const readSessionList = (tokens) => {
302
351
  requireOneLabelPerOption(tokens);
303
352
  const parsed = parseOptionsWith(tokens, {
@@ -306,22 +355,23 @@ const readSessionList = (tokens) => {
306
355
  "--idle-for",
307
356
  "--label",
308
357
  "--limit",
358
+ "--parent",
309
359
  "--project",
310
360
  "--state",
311
361
  ]),
312
- allowedFlags: new Set(["--all", "--attention", "--settled"]),
362
+ allowedFlags: new Set(["--all", "--all-nodes", "--attention", "--settled"]),
313
363
  repeatable: LABEL_OPTION,
314
364
  });
315
365
  requirePositionals(parsed.positionals, 0);
316
366
  const projectId = parsed.options.get("--project");
317
- if ((projectId === undefined) === !parsed.flags.has("--all"))
318
- throw new CliArgumentError("Use one of '--project' or '--all'.");
367
+ requireOneScope(projectId, parsed.flags);
319
368
  const states = parsed.options.get("--state")?.split(",");
320
369
  return {
321
370
  afterCursor: readCursor(parsed.options.get("--after")),
322
371
  ...readSettled(parsed),
323
372
  limit: readPageSize(parsed.options.get("--limit")),
324
373
  ...readLabels(parsed.options.get("--label")),
374
+ ...readParent(parsed.options),
325
375
  ...(projectId === undefined ? {} : { projectId }),
326
376
  ...(parsed.flags.has("--attention") ? { attention: true } : {}),
327
377
  ...(states === undefined ? {} : { states }),
@@ -355,6 +405,98 @@ const writeMergedSessions = (context, answers) => {
355
405
  };
356
406
  return writeMerged(context, { command: "session.list", result }, formatMergedSessions);
357
407
  };
408
+ const PLACEMENT_TABLE = {
409
+ empty: "No Nodes answered.",
410
+ headers: [
411
+ "EXECUTOR",
412
+ "READY",
413
+ "LOGIN",
414
+ "ACCOUNTS",
415
+ "ACTIVE",
416
+ "LOAD/CPU",
417
+ "MEM FREE",
418
+ "DISK FREE",
419
+ "READING",
420
+ "LIMIT",
421
+ "REASON",
422
+ ],
423
+ };
424
+ const percentCell = (value) => value === undefined ? "-" : `${value.toFixed(0)}%`;
425
+ const figure = (value) => String(Math.round(value * 100) / 100);
426
+ const limitCell = (refusal) => {
427
+ if (refusal === undefined)
428
+ return "-";
429
+ const { code, measured, required, resource, saturation } = refusal;
430
+ if (measured === undefined || required === undefined)
431
+ return resource === undefined
432
+ ? (saturation ?? code)
433
+ : `${resource} unreadable`;
434
+ if (resource === undefined)
435
+ return `sessions ${figure(measured)}/${figure(required)}`;
436
+ return resource === "cpu"
437
+ ? `cpu ${figure(measured)} load/CPU, max ${figure(required)}`
438
+ : `${resource} ${figure(measured)}% free, min ${figure(required)}%`;
439
+ };
440
+ const placementRow = ({ capacity, executor, login, reading, ready, reason, refusal, }) => [
441
+ executor.id,
442
+ ready ? "yes" : "no",
443
+ login,
444
+ String(executor.accounts),
445
+ `${String(capacity.activeSessions)}/${String(capacity.maximumActiveSessions)}`,
446
+ capacity.host?.loadPerCpu.toFixed(2) ?? "-",
447
+ percentCell(capacity.host?.memoryAvailablePercent),
448
+ percentCell(capacity.host?.diskFreePercent),
449
+ reading,
450
+ limitCell(refusal),
451
+ cell(reason ?? "-"),
452
+ ].join("\t");
453
+ const readPlacement = ({ call }, executor) => call === undefined
454
+ ? Effect.die(new Error("Missing the typed Node call."))
455
+ : Effect.gen(function* () {
456
+ const result = yield* call("session.placement.show", { executor });
457
+ if (!result.ok)
458
+ return result;
459
+ const now = yield* Clock.currentTimeMillis;
460
+ const { host } = result.value.capacity;
461
+ return {
462
+ ok: true,
463
+ value: {
464
+ ...result.value,
465
+ reading: host === undefined ? "live" : freshnessOf(host.observedAt, now),
466
+ },
467
+ };
468
+ });
469
+ const writeMergedPlacements = (context, answers) => {
470
+ const { items, nodes } = mergeLists(answers.map(({ node, result }) => ({
471
+ node,
472
+ result: result.ok
473
+ ? { ok: true, value: { items: [result.value] } }
474
+ : result,
475
+ })));
476
+ return writeMerged(context, {
477
+ command: "session.placement.show",
478
+ result: { items, method: "session.placement.show", nodes },
479
+ }, ({ result }) => formatMerged(result, placementRow, PLACEMENT_TABLE));
480
+ };
481
+ export const runSessionPlacementShow = (tokens, context) => {
482
+ const parsed = parseOptions(tokens, new Set(["--harness"]));
483
+ requirePositionals(parsed.positionals, 0);
484
+ const executor = readExecutorKind(parsed.options.get("--harness"));
485
+ if (executor === undefined)
486
+ throw new CliArgumentError("Option '--harness' is required.");
487
+ return listEach(context, {
488
+ merged: (answers) => writeMergedPlacements(context, answers),
489
+ paged: false,
490
+ read: (dependencies) => readPlacement(dependencies, executor),
491
+ sole: (result) => writeNodeResult(result, context, {
492
+ toResult: (value) => ({
493
+ command: "session.placement.show",
494
+ result: value,
495
+ }),
496
+ toText: ({ result }) => formatRows([result], placementRow, PLACEMENT_TABLE),
497
+ }),
498
+ });
499
+ };
358
500
  export const runSessionShow = (tokens, context) => Effect.gen(function* () {
359
501
  const parsed = parseOptions(tokens, new Set());
360
502
  requirePositionals(parsed.positionals, 1);
@@ -400,27 +542,29 @@ export const runSessionWait = (tokens, context) => Effect.gen(function* () {
400
542
  });
401
543
  return result.ok && !result.value.satisfied ? EXIT_DEADLINE : code;
402
544
  });
403
- const readLifecycleInput = (parsed) => {
545
+ const readLifecycleTarget = (parsed) => {
404
546
  const sessionId = parsed.positionals[0];
405
547
  if (sessionId === undefined) {
406
548
  throw new CliArgumentError("The session identifier is missing.");
407
549
  }
408
550
  const commandId = parsed.options.get("--command-id");
409
- return {
410
- expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
411
- sessionId,
412
- ...(commandId === undefined ? {} : { commandId }),
413
- };
551
+ return { sessionId, ...(commandId === undefined ? {} : { commandId }) };
414
552
  };
553
+ const readLifecycleInput = (parsed) => ({
554
+ ...readLifecycleTarget(parsed),
555
+ expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
556
+ });
415
557
  const parseSessionLifecycle = (verb, tokens, flags = new Set()) => {
416
558
  const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision"]), flags);
417
559
  requirePositionals(parsed.positionals, 1);
418
560
  return { flags: parsed.flags, input: readLifecycleInput(parsed) };
419
561
  };
420
- export const runSessionStart = (tokens, context) => Effect.gen(function* () {
562
+ const RUNNING_DEADLINE_MILLISECONDS = 120_000;
563
+ const readStartInput = (tokens) => {
421
564
  const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision", "--timeout"]), new Set(["--wait"]));
422
565
  requirePositionals(parsed.positionals, 1);
423
- const input = readLifecycleInput(parsed);
566
+ const target = readLifecycleTarget(parsed);
567
+ const named = readOptionalRevision(parsed.options);
424
568
  const wait = parsed.flags.has("--wait");
425
569
  const timeout = parsed.options.get("--timeout");
426
570
  if (timeout !== undefined && !wait)
@@ -428,7 +572,17 @@ export const runSessionStart = (tokens, context) => Effect.gen(function* () {
428
572
  const deadlineMilliseconds = timeout === undefined
429
573
  ? RUNNING_DEADLINE_MILLISECONDS
430
574
  : readDuration(timeout, "--timeout", { max: 3600, min: 1 }) * 1000;
431
- const result = yield* context.dependencies.startSession(input);
575
+ return { deadlineMilliseconds, named, target, wait };
576
+ };
577
+ export const runSessionStart = (tokens, context) => Effect.gen(function* () {
578
+ const { deadlineMilliseconds, named, target, wait } = readStartInput(tokens);
579
+ const { showSession, startSession } = context.dependencies;
580
+ const result = yield* changeAtRevision(named, {
581
+ change: (expectedRevision) => startSession({ ...target, expectedRevision }),
582
+ read: () => showSession(target.sessionId),
583
+ retry: `session start ${target.sessionId}`,
584
+ revisionOf: ({ session }) => ({ ok: true, value: session.revision }),
585
+ });
432
586
  if (!wait || !result.ok)
433
587
  return writeSessionResult(result, context, (value) => ({
434
588
  command: "session.start",
@@ -436,7 +590,6 @@ export const runSessionStart = (tokens, context) => Effect.gen(function* () {
436
590
  }));
437
591
  return yield* waitUntilRunning(result.value, context, deadlineMilliseconds);
438
592
  });
439
- const RUNNING_DEADLINE_MILLISECONDS = 120_000;
440
593
  const EXIT_NOT_RUNNING = 70;
441
594
  const EXIT_STILL_STARTING = 74;
442
595
  const waitUntilRunning = (started, context, deadlineMilliseconds) => Effect.gen(function* () {
@@ -462,28 +615,90 @@ const waitUntilRunning = (started, context, deadlineMilliseconds) => Effect.gen(
462
615
  ? EXIT_NOT_RUNNING
463
616
  : EXIT_STILL_STARTING;
464
617
  });
618
+ const summarizeSessionStop = (result, children) => ({
619
+ command: "session.stop",
620
+ result: {
621
+ ...summarizeSessionLifecycle(result),
622
+ ...(children === undefined ? {} : { children }),
623
+ },
624
+ });
625
+ const writeChildOutcomes = (output, children, context) => {
626
+ const failed = children.find(({ error }) => error !== undefined)?.error;
627
+ writeSuccess(output, {
628
+ ...context,
629
+ ...(failed === undefined ? {} : { error: failed, ok: false }),
630
+ }, formatSessionResult);
631
+ return failed === undefined ? 0 : exitCodeOf(failed);
632
+ };
633
+ const supervisionRoute = (context, names = []) => ({
634
+ bindNode: (name) => name === (context.node ?? LOCAL_NODE)
635
+ ? context.dependencies
636
+ : (context.bindNode?.(name) ??
637
+ (name === LOCAL_NODE ? context.dependencies : undefined)),
638
+ names,
639
+ node: context.node ?? LOCAL_NODE,
640
+ });
641
+ const subtreeRoute = (context) => Effect.map(everyNodeName(context), (names) => ({
642
+ route: supervisionRoute(context, names.ok ? names.value : []),
643
+ unread: names.ok ? [] : [{ error: names.error, node: LOCAL_NODE }],
644
+ }));
645
+ const withReconcileHint = (result, { flags, input }) => flags.has("--children") &&
646
+ !result.ok &&
647
+ result.error.code === "storage_conflict"
648
+ ? {
649
+ ...result,
650
+ error: {
651
+ ...result.error,
652
+ message: `${result.error.message} Nothing below it was asked. If it has stopped, run 'maia session reconcile ${input.sessionId}' to stop what runs below it.`,
653
+ },
654
+ }
655
+ : result;
465
656
  export const runSessionStop = (tokens, context) => Effect.gen(function* () {
466
- const { input } = parseSessionLifecycle("stop", tokens);
657
+ const stop = parseSessionLifecycle("stop", tokens, new Set(["--children"]));
658
+ const { flags, input } = stop;
467
659
  const { stopSession } = context.dependencies;
468
660
  if (stopSession === undefined)
469
661
  throw new CliArgumentError("Session stop is unavailable.");
470
- const result = yield* stopSession(input);
471
- return writeSessionResult(result, context, (value) => ({
472
- command: "session.stop",
473
- result: summarizeSessionLifecycle(value),
474
- }));
662
+ const result = withReconcileHint(yield* stopSession(input), stop);
663
+ if (!flags.has("--children") || !result.ok)
664
+ return writeSessionResult(result, context, (value) => summarizeSessionStop(value));
665
+ const { route, unread } = yield* subtreeRoute(context);
666
+ const children = [
667
+ ...unread,
668
+ ...(yield* cancelChildren(route, input.sessionId)),
669
+ ];
670
+ return writeChildOutcomes(summarizeSessionStop(result.value, children), children, context);
475
671
  });
476
672
  export const runSessionResume = (tokens, context) => Effect.gen(function* () {
477
673
  const { input } = parseSessionLifecycle("resume", tokens);
478
- const { resumeSession } = context.dependencies;
674
+ const { resumeSession, showSession } = context.dependencies;
479
675
  if (resumeSession === undefined)
480
676
  throw new CliArgumentError("Session resume is unavailable.");
481
- const result = yield* resumeSession(input);
677
+ const result = yield* resumeSupervised(everyNode(context), {
678
+ claim: (child) => readResumeParent(everyNode(context), context.node ?? LOCAL_NODE, child),
679
+ resumeSession,
680
+ showSession,
681
+ }, input);
482
682
  return writeSessionResult(result, context, (value) => ({
483
683
  command: "session.resume",
484
684
  result: summarizeSessionLifecycle(value),
485
685
  }));
486
686
  });
687
+ export const runSessionReconcile = (tokens, context) => Effect.gen(function* () {
688
+ const { positionals } = parseOptions(tokens, new Set());
689
+ requirePositionals(positionals, 1);
690
+ const sessionId = positionals[0] ?? "";
691
+ const { route, unread } = yield* subtreeRoute(context);
692
+ const result = yield* reconcileChildren(route, sessionId);
693
+ const output = (children) => ({
694
+ command: "session.reconcile",
695
+ result: { children, sessionId },
696
+ });
697
+ if (!result.ok)
698
+ return writeSessionResult(result, context, output);
699
+ const children = [...unread, ...result.value];
700
+ return writeChildOutcomes(output(children), children, context);
701
+ });
487
702
  export const runSessionEventsList = (tokens, context) => Effect.gen(function* () {
488
703
  const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--session"]));
489
704
  requirePositionals(parsed.positionals, 0);
@@ -665,4 +880,5 @@ export const runSessionInboxAck = (tokens, context) => Effect.gen(function* () {
665
880
  result: summarizeInboxAck(value),
666
881
  }));
667
882
  });
883
+ export const runSessionSpawn = (tokens, context) => runSpawn(tokens, { ...context, everyNode: everyNode(context) });
668
884
  //# sourceMappingURL=commands.js.map
@@ -1,6 +1,7 @@
1
1
  import { MAX_SESSION_CREATION_TASKS, MAX_TURN_INPUT_BYTES, } from "@maiaos/sdk";
2
2
  import { Effect } from "effect";
3
3
  import { CliArgumentError, reportError, writeSuccess, } from "../command-line/index.js";
4
+ import { batchError, reportItem, toWorktreeRequest, withCommandId, } from "./creation/index.js";
4
5
  import { formatSessionTasks } from "./output/index.js";
5
6
  import { readTaskFile } from "./task-file.js";
6
7
  const EXIT_OUTCOME_UNKNOWN = 76;
@@ -27,7 +28,7 @@ const toStartFields = ({ cwd, hostAuthority, permission, }) => ({
27
28
  ...(permission === undefined ? {} : { permission }),
28
29
  });
29
30
  const toTemplate = (selection) => {
30
- const { agentId, baseRef, connectionId, effort, executor, labels, model, role, title, } = selection;
31
+ const { agentId, connectionId, effort, executor, labels, model, role, title, } = selection;
31
32
  return {
32
33
  ...(agentId === undefined ? {} : { agentId }),
33
34
  ...(connectionId === undefined ? {} : { connectionId }),
@@ -38,7 +39,7 @@ const toTemplate = (selection) => {
38
39
  ...(model === undefined ? {} : { model }),
39
40
  ...(role === undefined ? {} : { role }),
40
41
  ...(title === undefined ? {} : { title }),
41
- ...(baseRef === undefined ? {} : { worktree: { baseRef } }),
42
+ ...toWorktreeRequest(selection),
42
43
  };
43
44
  };
44
45
  const toInput = (request, text) => {
@@ -51,39 +52,6 @@ const toInput = (request, text) => {
51
52
  ...(workspaceId === undefined ? {} : { workspaceId }),
52
53
  };
53
54
  };
54
- const reportItem = (plan, outcome) => {
55
- const commandId = outcome.stage === "unknown" ? outcome.error?.commandId : undefined;
56
- const { error, index, receipts, sessionId, stage, turnId } = outcome;
57
- return {
58
- ...(error === undefined ? {} : { error }),
59
- line: plan.items[index]?.line ?? 0,
60
- receipts,
61
- ...(commandId === undefined ? {} : { recovery: { commandId } }),
62
- ...(sessionId === undefined ? {} : { sessionId }),
63
- stage,
64
- ...(turnId === undefined ? {} : { turnId }),
65
- };
66
- };
67
- const MAX_TASK_COMMAND_ID_LENGTH = 122;
68
- const withCommandId = (plan, commandId) => {
69
- if (commandId === undefined)
70
- return plan;
71
- if (plan.items.length !== 1)
72
- throw new CliArgumentError("Option '--command-id' names one Session; the input holds several tasks.");
73
- if (commandId.length > MAX_TASK_COMMAND_ID_LENGTH)
74
- throw new CliArgumentError(`Option '--command-id' takes at most ${String(MAX_TASK_COMMAND_ID_LENGTH)} characters with a first message.`);
75
- return {
76
- ...plan,
77
- items: plan.items.map((item) => ({
78
- ...item,
79
- commands: {
80
- create: commandId,
81
- send: `${commandId}.send`,
82
- start: `${commandId}.start`,
83
- },
84
- })),
85
- };
86
- };
87
55
  const exitCode = (items) => {
88
56
  if (items.some((item) => item.stage === "unknown"))
89
57
  return EXIT_OUTCOME_UNKNOWN;
@@ -91,19 +59,6 @@ const exitCode = (items) => {
91
59
  ? 0
92
60
  : EXIT_REFUSED;
93
61
  };
94
- const batchError = (items) => {
95
- const failed = items.find((item) => item.error !== undefined);
96
- if (failed?.error === undefined)
97
- return undefined;
98
- const { code, failure, kind, message, operationId, retryable } = failed.error;
99
- return {
100
- code: failure?.code ?? code ?? kind,
101
- message: failure?.message ??
102
- message ??
103
- `Line ${String(failed.line)} stopped at ${operationId}: ${code ?? kind}.`,
104
- retryable,
105
- };
106
- };
107
62
  const writeBatch = (plan, outcomes, context) => {
108
63
  const items = outcomes.map((outcome) => reportItem(plan, outcome));
109
64
  const code = exitCode(items);
@@ -0,0 +1,51 @@
1
+ import { CliArgumentError } from "../../command-line/input/index.js";
2
+ export const toWorktreeRequest = ({ baseRef, branch, }) => baseRef === undefined
3
+ ? {}
4
+ : { worktree: { baseRef, ...(branch === undefined ? {} : { branch }) } };
5
+ export const reportItem = (plan, outcome) => {
6
+ const commandId = outcome.stage === "unknown" ? outcome.error?.commandId : undefined;
7
+ const { error, index, receipts, sessionId, stage, turnId } = outcome;
8
+ return {
9
+ ...(error === undefined ? {} : { error }),
10
+ line: plan.items[index]?.line ?? 0,
11
+ receipts,
12
+ ...(commandId === undefined ? {} : { recovery: { commandId } }),
13
+ ...(sessionId === undefined ? {} : { sessionId }),
14
+ stage,
15
+ ...(turnId === undefined ? {} : { turnId }),
16
+ };
17
+ };
18
+ const MAX_TASK_COMMAND_ID_LENGTH = 122;
19
+ export const withCommandId = (plan, commandId) => {
20
+ if (commandId === undefined)
21
+ return plan;
22
+ if (plan.items.length !== 1)
23
+ throw new CliArgumentError("Option '--command-id' names one Session; the input holds several tasks.");
24
+ if (commandId.length > MAX_TASK_COMMAND_ID_LENGTH)
25
+ throw new CliArgumentError(`Option '--command-id' takes at most ${String(MAX_TASK_COMMAND_ID_LENGTH)} characters with a first message.`);
26
+ return {
27
+ ...plan,
28
+ items: plan.items.map((item) => ({
29
+ ...item,
30
+ commands: {
31
+ create: commandId,
32
+ send: `${commandId}.send`,
33
+ start: `${commandId}.start`,
34
+ },
35
+ })),
36
+ };
37
+ };
38
+ export const batchError = (items) => {
39
+ const failed = items.find((item) => item.error !== undefined);
40
+ if (failed?.error === undefined)
41
+ return undefined;
42
+ const { code, failure, kind, message, operationId, retryable } = failed.error;
43
+ return {
44
+ code: failure?.code ?? code ?? kind,
45
+ message: failure?.message ??
46
+ message ??
47
+ `Line ${String(failed.line)} stopped at ${operationId}: ${code ?? kind}.`,
48
+ retryable,
49
+ };
50
+ };
51
+ //# sourceMappingURL=creation.js.map
@@ -0,0 +1,2 @@
1
+ export { batchError, reportItem, toWorktreeRequest, withCommandId, } from "./creation.js";
2
+ //# sourceMappingURL=index.js.map