@maiaos/cli 0.1.0-canary.63 → 0.1.0-canary.65

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 +260 -55
  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,23 @@
1
- import { MAX_TURN_INPUT_BYTES, MAX_TURN_WAIT_IDS, } from "@maiaos/sdk";
1
+ import { MAX_TURN_INPUT_BYTES, MAX_TURN_WAIT_IDS, turnSteerConfirmParametersSchema, } from "@maiaos/sdk";
2
2
  import * as Effect from "effect/Effect";
3
- import { CliArgumentError, parseOptions, readExpectedRevision, readRevisionOption, readWaitTimeoutSeconds, reportError, requirePositionals, writeNodeResult, writeSuccess, } from "../../command-line/index.js";
4
- import { formatTurnMutation, formatTurnQueue, formatTurnSend, formatTurnShow, formatTurnWait, turnWaitExitCode, } from "./output.js";
3
+ import { CliArgumentError, confirmParameters, parseOptions, parseOptionsWith, readOptionalRevision, readRevisionOption, readWaitTimeoutSeconds, reportError, requestedTwoPhaseMode, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeNodeResult, writeSuccess, } from "../../command-line/index.js";
4
+ import { changeAtRevision, commandIdentifier, } from "../../local-node/index.js";
5
+ import { readTurnAttachments } from "./attachments.js";
6
+ import { formatTurnAttachments, formatTurnMutation, formatTurnQueue, formatTurnSend, formatTurnShow, formatTurnSteer, formatTurnSteerPreview, formatTurnWait, summarizeTurnMutation, turnWaitExitCode, } from "./output.js";
5
7
  const utf8 = new TextEncoder();
6
- const summarizeTurnMutation = (result) => ({
7
- delivery: result.delivery,
8
- receipt: result.receipt,
9
- revision: result.turn.revision,
10
- sessionId: result.turn.sessionId,
11
- state: result.turn.state,
12
- turnId: result.turn.id,
13
- });
14
8
  const SEND_WAIT_MILLISECONDS = 24 * 60 * 60 * 1000;
9
+ const TURN_SEND_OPTIONS = {
10
+ allowed: new Set([
11
+ "--attach",
12
+ "--command-id",
13
+ "--expected-revision",
14
+ "--session",
15
+ ]),
16
+ allowedFlags: new Set(["--prompt-stdin", "--wait"]),
17
+ repeatable: new Set(["--attach"]),
18
+ };
15
19
  const parseTurnSendArguments = (tokens) => {
16
- const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision", "--session"]), new Set(["--prompt-stdin", "--wait"]));
20
+ const parsed = parseOptionsWith(tokens, TURN_SEND_OPTIONS);
17
21
  requirePositionals(parsed.positionals, 0);
18
22
  const sessionId = parsed.options.get("--session");
19
23
  if (sessionId === undefined) {
@@ -23,17 +27,28 @@ const parseTurnSendArguments = (tokens) => {
23
27
  throw new CliArgumentError("Option '--prompt-stdin' is required.");
24
28
  }
25
29
  const commandId = parsed.options.get("--command-id");
30
+ const expectedRevision = readOptionalRevision(parsed.options);
26
31
  return {
27
- expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
32
+ attach: parsed.options.get("--attach")?.split(",") ?? [],
28
33
  sessionId,
29
34
  wait: parsed.flags.has("--wait"),
30
35
  ...(commandId === undefined ? {} : { commandId }),
36
+ ...(expectedRevision === undefined ? {} : { expectedRevision }),
31
37
  };
32
38
  };
33
39
  const waitFailure = (turnId, error) => ({
34
40
  ...error,
35
41
  message: `Turn ${turnId} was accepted, but waiting for it failed: ${error.message} Follow it with 'maia session turn wait ${turnId}'.`,
36
42
  });
43
+ export const readTurnPrompt = (context) => {
44
+ if (context.io.stdin === undefined)
45
+ throw new CliArgumentError("Standard input is unavailable.");
46
+ return context.io.stdin({
47
+ label: "turn prompt",
48
+ maxBytes: MAX_TURN_INPUT_BYTES,
49
+ maxChunks: 1024,
50
+ });
51
+ };
37
52
  const waitForSentTurn = (context, sent) => Effect.gen(function* () {
38
53
  const { waitTurns } = context.dependencies;
39
54
  if (waitTurns === undefined)
@@ -51,21 +66,43 @@ const waitForSentTurn = (context, sent) => Effect.gen(function* () {
51
66
  }, context, formatTurnSend);
52
67
  return turnWaitExitCode(waited.value);
53
68
  });
69
+ const attachedFiles = (context, input) => Effect.gen(function* () {
70
+ if (input.attach.length === 0)
71
+ return { ok: true, value: [] };
72
+ const { showTurnAttachmentPolicy } = context.dependencies;
73
+ if (showTurnAttachmentPolicy === undefined)
74
+ throw new CliArgumentError("Turn attachments are unavailable.");
75
+ const policy = yield* showTurnAttachmentPolicy(input.sessionId);
76
+ return policy.ok
77
+ ? yield* readTurnAttachments(input.attach, policy.value)
78
+ : policy;
79
+ });
80
+ const sendAtRevision = (context, input, { attachments, prompt, }) => {
81
+ const { sendTurn, showSession } = context.dependencies;
82
+ return changeAtRevision(input.expectedRevision, {
83
+ change: (expectedRevision) => sendTurn({
84
+ ...(attachments.length === 0 ? {} : { attachments }),
85
+ ...(input.commandId === undefined
86
+ ? {}
87
+ : { commandId: input.commandId }),
88
+ expectedRevision,
89
+ prompt,
90
+ sessionId: input.sessionId,
91
+ }),
92
+ read: () => showSession(input.sessionId),
93
+ retry: `session turn send --session ${input.sessionId} --prompt-stdin`,
94
+ revisionOf: ({ session }) => ({ ok: true, value: session.revision }),
95
+ });
96
+ };
54
97
  export const runTurnSend = (tokens, context) => Effect.gen(function* () {
55
98
  const input = parseTurnSendArguments(tokens);
56
- if (context.io.stdin === undefined) {
57
- throw new CliArgumentError("Standard input is unavailable.");
58
- }
59
- const prompt = yield* context.io.stdin({
60
- label: "turn prompt",
61
- maxBytes: MAX_TURN_INPUT_BYTES,
62
- maxChunks: 1024,
63
- });
64
- const sent = yield* context.dependencies.sendTurn({
65
- ...(input.commandId === undefined ? {} : { commandId: input.commandId }),
66
- expectedRevision: input.expectedRevision,
99
+ const prompt = yield* readTurnPrompt(context);
100
+ const attached = yield* attachedFiles(context, input);
101
+ if (!attached.ok)
102
+ return reportError(attached.error, context);
103
+ const sent = yield* sendAtRevision(context, input, {
104
+ attachments: attached.value,
67
105
  prompt,
68
- sessionId: input.sessionId,
69
106
  });
70
107
  if (!sent.ok || !input.wait)
71
108
  return writeNodeResult(sent, context, {
@@ -80,7 +117,7 @@ export const runTurnSend = (tokens, context) => Effect.gen(function* () {
80
117
  const parseTurnMutationArguments = (tokens, revisionOption) => {
81
118
  const parsed = parseOptions(tokens, new Set(["--command-id", revisionOption]));
82
119
  requirePositionals(parsed.positionals, 1);
83
- const turnId = parsed.positionals[0];
120
+ const [turnId] = parsed.positionals;
84
121
  if (turnId === undefined) {
85
122
  throw new CliArgumentError("The turn identifier is missing.");
86
123
  }
@@ -111,7 +148,7 @@ export const runTurnCancel = (tokens, context) => Effect.gen(function* () {
111
148
  return writeNodeResult(result, context, {
112
149
  toResult: (value) => ({
113
150
  command: "turn.cancel",
114
- result: summarizeTurnMutation(value),
151
+ result: { ...summarizeTurnMutation(value), outcome: value.outcome },
115
152
  }),
116
153
  toText: formatTurnMutation,
117
154
  });
@@ -135,6 +172,25 @@ export const runTurnQueue = (tokens, context) => Effect.gen(function* () {
135
172
  toText: formatTurnQueue,
136
173
  });
137
174
  });
175
+ export const runTurnAttachments = (tokens, context) => Effect.gen(function* () {
176
+ const parsed = parseOptions(tokens, new Set());
177
+ requirePositionals(parsed.positionals, 1);
178
+ const sessionId = parsed.positionals[0];
179
+ if (sessionId === undefined) {
180
+ throw new CliArgumentError("The Session identifier is missing.");
181
+ }
182
+ const { showTurnAttachmentPolicy } = context.dependencies;
183
+ if (showTurnAttachmentPolicy === undefined)
184
+ throw new CliArgumentError("Turn attachments are unavailable.");
185
+ const result = yield* showTurnAttachmentPolicy(sessionId);
186
+ return writeNodeResult(result, context, {
187
+ toResult: (value) => ({
188
+ command: "turn.attachment.policy",
189
+ result: value,
190
+ }),
191
+ toText: formatTurnAttachments,
192
+ });
193
+ });
138
194
  const parseTurnShowArguments = (tokens) => {
139
195
  const parsed = parseOptions(tokens, new Set(["--session"]), new Set(["--include-content", "--latest"]));
140
196
  const includeContent = parsed.flags.has("--include-content");
@@ -234,4 +290,69 @@ export const runTurnWait = (tokens, context) => Effect.gen(function* () {
234
290
  });
235
291
  return result.ok ? turnWaitExitCode(result.value) : code;
236
292
  });
293
+ const readSteerMode = (flags) => {
294
+ const mode = requestedTwoPhaseMode(flags);
295
+ const prompt = flags.has("--prompt-stdin");
296
+ if (mode === "confirm-stdin" && prompt)
297
+ throw new CliArgumentError("Use one of '--prompt-stdin' or '--confirm-stdin'.");
298
+ if (mode === undefined)
299
+ throw new CliArgumentError("Preview with '--prompt-stdin --dry-run', pipe that preview to '--confirm-stdin', or confirm at once with '--prompt-stdin --yes'.");
300
+ if (mode !== "confirm-stdin" && !prompt)
301
+ throw new CliArgumentError("Option '--prompt-stdin' is required.");
302
+ return mode;
303
+ };
304
+ const requirePipedAlone = ({ options, positionals }) => {
305
+ if (positionals.length > 0 || options.size > 0)
306
+ throw new CliArgumentError("A piped preview carries its turn, prompt, revision and command ID: give '--confirm-stdin' alone.");
307
+ };
308
+ const summarizeSteer = (value) => ({
309
+ command: "turn.steer.confirm",
310
+ result: {
311
+ ...summarizeTurnMutation(value),
312
+ path: value.path,
313
+ sourceState: value.source.state,
314
+ sourceTurnId: value.source.id,
315
+ },
316
+ });
317
+ const previewSteer = (parsed, context, call) => Effect.gen(function* () {
318
+ const commandId = yield* commandIdentifier(parsed.options.get("--command-id"));
319
+ const expectedRevision = readRevisionOption(parsed.options.get("--expected-session-revision"), "--expected-session-revision");
320
+ const prompt = yield* readTurnPrompt(context);
321
+ return yield* call("turn.steer.preview", {
322
+ commandId,
323
+ expectedRevision,
324
+ input: { text: prompt, type: "text" },
325
+ turnId: parsed.positionals[0] ?? "",
326
+ });
327
+ });
328
+ const writeSteerConfirm = (result, context) => writeNodeResult(result, context, {
329
+ toResult: summarizeSteer,
330
+ toText: formatTurnSteer,
331
+ });
332
+ const writeSteerPreview = (result, context) => writeNodeResult(result, context, {
333
+ toResult: (value) => ({
334
+ command: "turn.steer.preview",
335
+ result: value,
336
+ }),
337
+ toText: formatTurnSteerPreview,
338
+ });
339
+ export const runTurnSteer = (tokens, context) => {
340
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-session-revision"]), new Set([...TWO_PHASE_FLAGS, "--prompt-stdin"]));
341
+ const mode = readSteerMode(parsed.flags);
342
+ const { call } = context.dependencies;
343
+ if (call === undefined)
344
+ throw new CliArgumentError("Turn steer is unavailable.");
345
+ if (mode === "confirm-stdin")
346
+ requirePipedAlone(parsed);
347
+ else
348
+ requirePositionals(parsed.positionals, 1);
349
+ return runTwoPhase({
350
+ confirm: (preview) => Effect.flatMap(confirmParameters(turnSteerConfirmParametersSchema, preview, ["path"]), (confirmation) => call("turn.steer.confirm", confirmation)),
351
+ context,
352
+ mode,
353
+ preview: () => previewSteer(parsed, context, call),
354
+ writeConfirm: (result) => writeSteerConfirm(result, context),
355
+ writePreview: (result) => writeSteerPreview(result, context),
356
+ });
357
+ };
237
358
  //# sourceMappingURL=commands.js.map
@@ -1,4 +1,4 @@
1
1
  export { type CancelTurnInput, type InterruptTurnInput, makeTurnClient, type SendTurnInput, type WaitTurnsInput, } from "./client.js";
2
- export { runTurnCancel, runTurnInterrupt, runTurnQueue, runTurnSend, runTurnShow, runTurnWait, } from "./commands.js";
3
- export { type CliTurnMutation, type CliTurnQueue, type CliTurnShow, type CliTurnWait, } from "./output.js";
2
+ export { runTurnAttachments, runTurnCancel, runTurnInterrupt, runTurnQueue, runTurnSend, runTurnShow, runTurnSteer, runTurnWait, } from "./commands.js";
3
+ export { type CliTurnAttachments, type CliTurnMutation, type CliTurnQueue, type CliTurnShow, type CliTurnSteer, type CliTurnSteerPreview, type CliTurnWait, } from "./output.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export { makeTurnClient, } from "./client.js";
2
- export { runTurnCancel, runTurnInterrupt, runTurnQueue, runTurnSend, runTurnShow, runTurnWait, } from "./commands.js";
2
+ export { runTurnAttachments, runTurnCancel, runTurnInterrupt, runTurnQueue, runTurnSend, runTurnShow, runTurnSteer, runTurnWait, } from "./commands.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,11 @@
1
- import type { FailureDetail, TurnInterruptResult, TurnQueueListResult, TurnShowResult, TurnTokenUsage, TurnWaitResult } from "@maiaos/sdk";
1
+ import type { FailureDetail, LocalNodeCallResult, TurnAttachmentPolicyResult, TurnCancelResult, TurnInterruptResult, TurnQueueListResult, TurnSendResult, TurnShowResult, TurnTokenUsage, TurnWaitResult } from "@maiaos/sdk";
2
+ type SteerPreview = LocalNodeCallResult<"turn.steer.preview">;
3
+ type SteerConfirmed = LocalNodeCallResult<"turn.steer.confirm">;
2
4
  export type CliTurnMutation = {
3
5
  readonly command: "turn.cancel" | "turn.interrupt" | "turn.send";
4
6
  readonly result: {
5
7
  readonly delivery: TurnInterruptResult["delivery"];
8
+ readonly outcome?: TurnCancelResult["outcome"];
6
9
  readonly receipt: TurnInterruptResult["receipt"];
7
10
  readonly revision: string;
8
11
  readonly sessionId: string;
@@ -11,6 +14,19 @@ export type CliTurnMutation = {
11
14
  readonly wait?: TurnWaitResult;
12
15
  };
13
16
  };
17
+ export declare const summarizeTurnMutation: (result: SteerConfirmed | TurnCancelResult | TurnInterruptResult | TurnSendResult) => CliTurnMutation["result"];
18
+ export type CliTurnSteerPreview = {
19
+ readonly command: "turn.steer.preview";
20
+ readonly result: SteerPreview;
21
+ };
22
+ export type CliTurnSteer = {
23
+ readonly command: "turn.steer.confirm";
24
+ readonly result: CliTurnMutation["result"] & {
25
+ readonly path: SteerConfirmed["path"];
26
+ readonly sourceState: SteerConfirmed["source"]["state"];
27
+ readonly sourceTurnId: string;
28
+ };
29
+ };
14
30
  export type CliTurnShow = {
15
31
  readonly command: "turn.show";
16
32
  readonly result: (TurnShowResult & {
@@ -40,14 +56,22 @@ export type CliTurnWait = {
40
56
  readonly command: "turn.wait";
41
57
  readonly result: TurnWaitResult;
42
58
  };
59
+ export type CliTurnAttachments = {
60
+ readonly command: "turn.attachment.policy";
61
+ readonly result: TurnAttachmentPolicyResult;
62
+ };
43
63
  export type CliTurnQueue = {
44
64
  readonly command: "turn.queue.list";
45
65
  readonly result: TurnQueueListResult;
46
66
  };
67
+ export declare const formatTurnAttachments: ({ result }: CliTurnAttachments) => string;
47
68
  export declare const formatTurnMutation: ({ result }: CliTurnMutation) => string;
69
+ export declare const formatTurnSteer: ({ result }: CliTurnSteer) => string;
70
+ export declare const formatTurnSteerPreview: ({ result, }: CliTurnSteerPreview) => string;
48
71
  export declare const formatTurnSend: (output: CliTurnMutation) => string;
49
72
  export declare const formatTurnQueue: ({ result }: CliTurnQueue) => string;
50
73
  export declare const formatTurnShow: ({ result }: CliTurnShow) => string;
51
74
  export declare const formatTurnWait: ({ result }: CliTurnWait) => string;
52
75
  export declare const turnWaitExitCode: (result: TurnWaitResult) => number;
76
+ export {};
53
77
  //# sourceMappingURL=output.d.ts.map
@@ -1,10 +1,43 @@
1
1
  import { block, cell, fields, formatRows, tab, } from "../../command-line/index.js";
2
2
  import { formatFailure } from "../output/index.js";
3
+ export const summarizeTurnMutation = (result) => ({
4
+ delivery: result.delivery,
5
+ receipt: result.receipt,
6
+ revision: result.turn.revision,
7
+ sessionId: result.turn.sessionId,
8
+ state: result.turn.state,
9
+ turnId: result.turn.id,
10
+ });
11
+ export const formatTurnAttachments = ({ result }) => fields([
12
+ ["session", result.sessionId],
13
+ ["accepted", String(result.accepted)],
14
+ ["max-bytes", String(result.maxBytes)],
15
+ ["types", result.mediaTypes.join(",")],
16
+ ]);
3
17
  export const formatTurnMutation = ({ result }) => fields([
4
18
  ["turn", result.turnId],
19
+ ["outcome", result.outcome],
5
20
  ["state", result.state],
6
21
  ["revision", result.revision],
7
22
  ]);
23
+ export const formatTurnSteer = ({ result }) => fields([
24
+ ["turn", result.turnId],
25
+ ["state", result.state],
26
+ ["revision", result.revision],
27
+ ["path", result.path],
28
+ ["source", `${result.sourceTurnId} ${result.sourceState}`],
29
+ ]);
30
+ const steerEffect = (path) => path === "interrupt-restart"
31
+ ? "interrupts the running turn and discards its in-flight work, then runs the new input as the next turn"
32
+ : "adds the new input to the running turn";
33
+ export const formatTurnSteerPreview = ({ result, }) => fields([
34
+ ["turn", result.turnId],
35
+ ["path", result.path],
36
+ ["effect", steerEffect(result.path)],
37
+ ["command", result.commandId],
38
+ ["revision", result.expectedRevision],
39
+ ["valid until", result.validUntil],
40
+ ]);
8
41
  export const formatTurnSend = (output) => output.result.wait === undefined
9
42
  ? formatTurnMutation(output)
10
43
  : formatTurnWait({ command: "turn.wait", result: output.result.wait });
@@ -0,0 +1,9 @@
1
+ import { type SkillsSyncConfirmParameters, type SkillsSyncConfirmResult, type SkillsSyncPreviewParameters, type SkillsSyncPreviewResult, type SkillsSyncShowParameters, type SkillsSyncShowResult } from "@maiaos/sdk";
2
+ import type { CliNodeEffect, CliNodeOperations } from "../local-node/index.js";
3
+ export declare const makeSkillsSyncClient: (node: CliNodeOperations) => {
4
+ confirmSkillsSync: (input: SkillsSyncConfirmParameters) => CliNodeEffect<SkillsSyncConfirmResult>;
5
+ previewSkillsSync: (input: SkillsSyncPreviewParameters) => CliNodeEffect<SkillsSyncPreviewResult>;
6
+ showSkillsSync: (input: SkillsSyncShowParameters) => CliNodeEffect<SkillsSyncShowResult>;
7
+ };
8
+ export type SkillsSyncCliDependencies = ReturnType<typeof makeSkillsSyncClient>;
9
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { skillsSyncConfirmParametersSchema, skillsSyncPreviewParametersSchema, skillsSyncShowParametersSchema, } from "@maiaos/sdk";
2
+ export const makeSkillsSyncClient = (node) => ({
3
+ confirmSkillsSync: (input) => node.runValidatedNodeOperation(input, skillsSyncConfirmParametersSchema, (client, parameters, options) => client.confirmSkillsSync(parameters, options)),
4
+ previewSkillsSync: (input) => node.runValidatedNodeOperation(input, skillsSyncPreviewParametersSchema, (client, parameters, options) => client.previewSkillsSync(parameters, options)),
5
+ showSkillsSync: (input) => node.runValidatedNodeOperation(input, skillsSyncShowParametersSchema, (client, parameters, options) => client.showSkillsSync(parameters, options)),
6
+ });
7
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,15 @@
1
+ import type * as Crypto from "effect/Crypto";
2
+ import * as Effect from "effect/Effect";
3
+ import type { OutputContext } from "../command-line/emit/index.js";
4
+ import { CliArgumentError } from "../command-line/input/index.js";
5
+ import type { SkillsSyncCliDependencies } from "./client.js";
6
+ type Dependencies = Partial<SkillsSyncCliDependencies>;
7
+ type CommandContext = OutputContext & {
8
+ readonly bindNode?: (name: string) => Dependencies;
9
+ };
10
+ type CommandEffect = Effect.Effect<number, CliArgumentError, Crypto.Crypto>;
11
+ export declare const runSkillsSyncShow: (tokens: readonly string[], context: CommandContext) => CommandEffect;
12
+ export declare const runSkillsSyncApply: (tokens: readonly string[], context: CommandContext) => CommandEffect;
13
+ export declare const runSkillsSyncRollback: (tokens: readonly string[], context: CommandContext) => CommandEffect;
14
+ export {};
15
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1,241 @@
1
+ import { MAX_SKILLS_SYNC_NODES, protocolErrorSchema, skillsSyncPreviewParametersSchema, skillsSyncPreviewResultSchema, skillsSyncShowParametersSchema, } from "@maiaos/sdk";
2
+ import { confirmSkillsSyncFanOut, previewSkillsSyncFanOut, showSkillsSyncFanOut, } from "@maiaos/sdk/node/effect";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
5
+ import { reportError, writeSuccess } from "../command-line/emit/index.js";
6
+ import { CliArgumentError, parseOptionsWith, readNodeName, } from "../command-line/input/index.js";
7
+ import { readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../command-line/two-phase/index.js";
8
+ import { commandIdentifier, } from "../local-node/index.js";
9
+ import { blockerOf, formatSkillsSyncResult, } from "./output.js";
10
+ import { readSetFile } from "./set-file.js";
11
+ const INCOMPLETE = 1;
12
+ const lift = (effect) => Effect.flatMap(effect, (result) => result.ok ? Effect.succeed(result.value) : Effect.fail(result.error));
13
+ const syncNodeOf = (name, dependencies) => {
14
+ const { confirmSkillsSync, previewSkillsSync, showSkillsSync } = dependencies;
15
+ if (confirmSkillsSync === undefined ||
16
+ previewSkillsSync === undefined ||
17
+ showSkillsSync === undefined)
18
+ return Effect.fail(new CliArgumentError("Skills sync is unavailable."));
19
+ return Effect.succeed({
20
+ confirm: (parameters) => lift(confirmSkillsSync(parameters)),
21
+ node: name,
22
+ preview: (parameters) => lift(previewSkillsSync(parameters)),
23
+ show: (parameters) => lift(showSkillsSync(parameters)),
24
+ });
25
+ };
26
+ const syncNodesOf = (context, names) => {
27
+ const { bindNode } = context;
28
+ if (bindNode === undefined)
29
+ return Effect.fail(new CliArgumentError("This CLI cannot reach Nodes."));
30
+ return Effect.forEach(names, (name) => syncNodeOf(name, bindNode(name)));
31
+ };
32
+ const usageError = (error) => new CliArgumentError(error.message);
33
+ const readNodeNames = (positionals) => {
34
+ if (positionals.length === 0 || positionals.length > MAX_SKILLS_SYNC_NODES)
35
+ throw new CliArgumentError(`Name one to ${String(MAX_SKILLS_SYNC_NODES)} Nodes.`);
36
+ return positionals.map(readNodeName);
37
+ };
38
+ const readWorkspace = (parsed) => {
39
+ const workspace = parsed.options.get("--workspace");
40
+ if (workspace === undefined)
41
+ throw new CliArgumentError("Option '--workspace' is required.");
42
+ return workspace;
43
+ };
44
+ const write = (context, setFile) => (output) => {
45
+ const error = blockerOf(output);
46
+ writeSuccess({ command: output.method, result: output }, error === undefined ? context : { ...context, error, ok: false }, (result) => formatSkillsSyncResult(result, setFile));
47
+ return error === undefined ? 0 : INCOMPLETE;
48
+ };
49
+ const writeResult = (context, setFile) => (result) => result.ok
50
+ ? write(context, setFile)(result.value)
51
+ : reportError(result.error, context);
52
+ const ok = (value) => ({
53
+ ok: true,
54
+ value,
55
+ });
56
+ const SHOW_OPTIONS = new Set(["--workspace"]);
57
+ export const runSkillsSyncShow = (tokens, context) => Effect.gen(function* () {
58
+ const parsed = parseOptionsWith(tokens, {
59
+ allowed: SHOW_OPTIONS,
60
+ allowedFlags: new Set(),
61
+ repeatable: new Set(),
62
+ });
63
+ const names = readNodeNames(parsed.positionals);
64
+ const parameters = skillsSyncShowParametersSchema.safeParse({
65
+ workspace: readWorkspace(parsed),
66
+ });
67
+ if (!parameters.success)
68
+ return yield* new CliArgumentError("The Workspace key is invalid.");
69
+ const nodes = yield* syncNodesOf(context, names);
70
+ const shown = yield* Effect.mapError(showSkillsSyncFanOut(nodes, parameters.data), usageError);
71
+ const output = {
72
+ method: "skills.sync.show",
73
+ nodes: shown,
74
+ workspace: parameters.data.workspace,
75
+ };
76
+ return write(context)(output);
77
+ });
78
+ const PREVIEW_BAD_INPUT = "The set, the Workspace key or the command ID is invalid; a set file holds { digest, skills, source }.";
79
+ const readParameters = (input) => {
80
+ const parsed = skillsSyncPreviewParametersSchema.safeParse(input);
81
+ if (!parsed.success)
82
+ throw new CliArgumentError(PREVIEW_BAD_INPUT);
83
+ return parsed.data;
84
+ };
85
+ const changeOf = (kind, set) => kind === "apply" ? { kind, set } : { kind };
86
+ const syncOptions = (kind) => ({
87
+ allowed: new Set([
88
+ "--command-id",
89
+ "--workspace",
90
+ ...(kind === "apply" ? ["--set"] : []),
91
+ ]),
92
+ allowedFlags: new Set(TWO_PHASE_FLAGS),
93
+ repeatable: new Set(),
94
+ });
95
+ const readTarget = (parsed, mode) => {
96
+ if (mode !== "confirm-stdin")
97
+ return {
98
+ names: readNodeNames(parsed.positionals),
99
+ workspace: readWorkspace(parsed),
100
+ };
101
+ if (parsed.positionals.length > 0 ||
102
+ parsed.options.has("--workspace") ||
103
+ parsed.options.has("--command-id"))
104
+ throw new CliArgumentError("The Nodes, '--workspace' and '--command-id' belong to the preview; '--confirm-stdin' takes the piped preview.");
105
+ return { names: [], workspace: "" };
106
+ };
107
+ const errorShape = Schema.Struct({
108
+ code: Schema.String,
109
+ message: Schema.String,
110
+ retryable: Schema.Boolean,
111
+ });
112
+ const pipedEntry = Schema.Struct({
113
+ error: Schema.optional(errorShape),
114
+ node: Schema.String,
115
+ outcome: Schema.Literals(["conflict", "failed", "ready"]),
116
+ preview: Schema.optional(Schema.Unknown),
117
+ standing: Schema.optional(Schema.Literals(["drift", "in_sync", "unpinned"])),
118
+ tampered: Schema.optional(Schema.Boolean),
119
+ });
120
+ const pipedPreview = Schema.Struct({
121
+ commandId: Schema.String,
122
+ kind: Schema.Literals(["apply", "rollback"]),
123
+ method: Schema.Literal("skills.sync.preview"),
124
+ nodes: Schema.Array(pipedEntry).check(Schema.isBetweenLength(1, MAX_SKILLS_SYNC_NODES)),
125
+ ready: Schema.Boolean,
126
+ workspace: Schema.String,
127
+ });
128
+ const invalidPreview = () => new CliArgumentError("The piped preview is invalid; pipe the output of 'maia --json skills sync … --dry-run'.");
129
+ const entryOf = (entry) => {
130
+ readNodeName(entry.node);
131
+ if (entry.outcome === "failed") {
132
+ return {
133
+ error: protocolErrorSchema.parse(entry.error),
134
+ node: entry.node,
135
+ outcome: "failed",
136
+ };
137
+ }
138
+ if (entry.standing === undefined || entry.tampered === undefined)
139
+ throw invalidPreview();
140
+ return {
141
+ node: entry.node,
142
+ outcome: entry.outcome,
143
+ preview: skillsSyncPreviewResultSchema.parse(entry.preview),
144
+ standing: entry.standing,
145
+ tampered: entry.tampered,
146
+ };
147
+ };
148
+ const readPipedPreview = (value) => {
149
+ try {
150
+ const piped = Schema.decodeUnknownSync(pipedPreview, {
151
+ onExcessProperty: "error",
152
+ })(value);
153
+ const nodes = piped.nodes.map(entryOf);
154
+ if (new Set(nodes.map(({ node }) => node)).size !== nodes.length)
155
+ throw invalidPreview();
156
+ return {
157
+ ...piped,
158
+ nodes,
159
+ ready: nodes.every(({ outcome }) => outcome === "ready"),
160
+ };
161
+ }
162
+ catch {
163
+ throw invalidPreview();
164
+ }
165
+ };
166
+ const requireSameChange = (piped, parameters) => {
167
+ const { change } = parameters;
168
+ const mismatched = piped.nodes.some((entry) => entry.outcome !== "failed" &&
169
+ (entry.preview.kind !== change.kind ||
170
+ (change.kind === "apply" &&
171
+ entry.preview.digest !== change.set.digest)));
172
+ if (mismatched || piped.kind !== change.kind)
173
+ throw new CliArgumentError("The piped preview is for another change; pipe the preview of this command.");
174
+ };
175
+ const PROMPTS = {
176
+ apply: "Apply this set on every Node listed?",
177
+ rollback: "Roll every Node listed back to its previous set?",
178
+ };
179
+ const previewStep = ({ context, kind, parsed, set }, names) => () => Effect.gen(function* () {
180
+ const commandId = yield* commandIdentifier(parsed.options.get("--command-id"));
181
+ const workspace = readWorkspace(parsed);
182
+ const parameters = readParameters({
183
+ change: changeOf(kind, set),
184
+ commandId,
185
+ workspace,
186
+ });
187
+ const nodes = yield* syncNodesOf(context, names);
188
+ const fanOut = yield* Effect.mapError(previewSkillsSyncFanOut(nodes, parameters), usageError);
189
+ return ok({
190
+ ...fanOut,
191
+ commandId,
192
+ kind,
193
+ method: "skills.sync.preview",
194
+ workspace,
195
+ });
196
+ });
197
+ const confirmFanOut = ({ context, kind, set }, piped) => Effect.gen(function* () {
198
+ const preview = readPipedPreview(piped);
199
+ const { commandId, workspace } = preview;
200
+ const { change } = readParameters({
201
+ change: changeOf(kind, set),
202
+ commandId,
203
+ workspace,
204
+ });
205
+ requireSameChange(preview, { change, commandId, workspace });
206
+ const nodes = yield* syncNodesOf(context, preview.nodes.map(({ node }) => node));
207
+ const fanOut = yield* Effect.mapError(confirmSkillsSyncFanOut(nodes, { change, preview }), usageError);
208
+ return ok({
209
+ ...fanOut,
210
+ commandId,
211
+ kind,
212
+ method: "skills.sync.confirm",
213
+ workspace,
214
+ });
215
+ });
216
+ const confirmStep = (run) => (piped) => confirmFanOut(run, piped);
217
+ const runSync = (kind) => (tokens, context) => Effect.gen(function* () {
218
+ const parsed = parseOptionsWith(tokens, syncOptions(kind));
219
+ const mode = readTwoPhaseMode(parsed.flags, context);
220
+ const { names } = readTarget(parsed, mode);
221
+ const setFile = parsed.options.get("--set");
222
+ if (kind === "apply" && setFile === undefined)
223
+ throw new CliArgumentError("Option '--set' is required.");
224
+ const set = setFile === undefined ? undefined : yield* readSetFile(setFile);
225
+ const run = { context, kind, parsed, set };
226
+ return yield* runTwoPhase({
227
+ confirm: confirmStep(run),
228
+ context,
229
+ mode,
230
+ preview: previewStep(run, names),
231
+ prompt: {
232
+ describe: (preview) => formatSkillsSyncResult({ command: preview.method, result: preview }, setFile),
233
+ question: PROMPTS[kind],
234
+ },
235
+ writeConfirm: writeResult(context, setFile),
236
+ writePreview: writeResult(context, setFile),
237
+ });
238
+ });
239
+ export const runSkillsSyncApply = runSync("apply");
240
+ export const runSkillsSyncRollback = runSync("rollback");
241
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1,3 @@
1
+ export { makeSkillsSyncClient, type SkillsSyncCliDependencies, } from "./client.js";
2
+ export { runSkillsSyncApply, runSkillsSyncRollback, runSkillsSyncShow, } from "./commands.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { makeSkillsSyncClient, } from "./client.js";
2
+ export { runSkillsSyncApply, runSkillsSyncRollback, runSkillsSyncShow, } from "./commands.js";
3
+ //# sourceMappingURL=index.js.map