@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
package/dist/mcp/calls.js CHANGED
@@ -1,240 +1,61 @@
1
- import { agentsListParametersSchema, agentsShowParametersSchema, approvalListParametersSchema, approvalRespondParametersSchema, approvalShowParametersSchema, connectionDetectParametersSchema, connectionListParametersSchema, connectionModelsListParametersSchema, connectionShowParametersSchema, connectionUsageShowParametersSchema, containerIndexListParametersSchema, COORDINATOR_TOOL_OPERATIONS, discoverySessionsListParametersSchema, invocationContextShowParametersSchema, LOCAL_NODE_CALL_METHODS, localNodeRequestPayloadSchema, portLeaseAcquireParametersSchema, portLeaseListParametersSchema, portLeaseReleaseParametersSchema, portLeaseRenewParametersSchema, projectGuardShowParametersSchema, projectListParametersSchema, projectShowParametersSchema, receiptGetParametersSchema, routineListParametersSchema, routineShowParametersSchema, runLedgerCreateParametersSchema, runLedgerListParametersSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskListParametersSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskShowParametersSchema, sessionArchiveParametersSchema, sessionCreateParametersSchema, sessionDiffParametersSchema, sessionEventsListParametersSchema, sessionHistoryReadParametersSchema, sessionInboxAckParametersSchema, sessionInboxCheckParametersSchema, sessionListParametersSchema, sessionMessageSendParametersSchema, sessionObserveParametersSchema, sessionResumeParametersSchema, sessionShowParametersSchema, sessionStartParametersSchema, sessionStopParametersSchema, turnCancelParametersSchema, turnInterruptParametersSchema, turnQueueListParametersSchema, turnSendParametersSchema, turnShowParametersSchema, turnWaitParametersSchema, workerToolDefinitions, workspaceListParametersSchema, workspaceShowParametersSchema, } from "@maiaos/sdk";
1
+ import { coordinatorToolDefinitions, localNodeRequestPayloadSchema, workerToolDefinitions, } from "@maiaos/sdk";
2
2
  import { Effect, Predicate } from "effect";
3
3
  import { invalidNodeInput, } from "../local-node/index.js";
4
4
  const recoveryOf = (input) => Predicate.hasProperty(input, "commandId") &&
5
5
  Predicate.isString(input.commandId)
6
6
  ? { commandId: input.commandId }
7
7
  : undefined;
8
- const validated = (schema, run) => (node, input) => node.runValidatedNodeOperation(input, schema, run, recoveryOf(input));
9
- const status = (node, input) => input === undefined ||
10
- (Predicate.isObject(input) && Object.keys(input).length === 0)
11
- ? node.runNodeClientOperation((client, options) => client.status(options))
12
- : invalidNodeInput();
13
- const callBound = new Set(LOCAL_NODE_CALL_METHODS);
14
- const isCallPayload = (payload) => callBound.has(payload.method);
15
- const isCallBound = (operation) => callBound.has(operation);
16
- const typedCall = (method) => (node, input) => {
17
- const payload = localNodeRequestPayloadSchema.safeParse({
18
- method,
19
- parameters: input,
20
- });
21
- if (!payload.success)
22
- return invalidNodeInput(payload.error);
23
- const { data } = payload;
24
- return isCallPayload(data)
25
- ? node.runNodeClientOperation((client, options) => client.call(data.method, data.parameters, options), recoveryOf(input))
26
- : invalidNodeInput();
27
- };
28
- export const COORDINATOR_CALLS = new Map([
29
- ...COORDINATOR_TOOL_OPERATIONS.filter(isCallBound).map((operation) => [operation, typedCall(operation)]),
30
- [
31
- "agents.list",
32
- validated(agentsListParametersSchema, (client, parameters, options) => client.listAgents(parameters, options)),
33
- ],
34
- [
35
- "agents.show",
36
- validated(agentsShowParametersSchema, (client, parameters, options) => client.showAgent(parameters, options)),
37
- ],
38
- [
39
- "approval.list",
40
- validated(approvalListParametersSchema, (client, parameters, options) => client.listApprovals(parameters, options)),
41
- ],
42
- [
43
- "approval.respond",
44
- validated(approvalRespondParametersSchema, (client, parameters, options) => client.respondToApproval(parameters, options)),
45
- ],
46
- [
47
- "approval.show",
48
- validated(approvalShowParametersSchema, (client, parameters, options) => client.showApproval(parameters, options)),
49
- ],
50
- [
51
- "connection.detect",
52
- validated(connectionDetectParametersSchema, (client, parameters, options) => client.detectConnections(parameters, options)),
53
- ],
54
- [
55
- "connection.list",
56
- validated(connectionListParametersSchema, (client, parameters, options) => client.listConnections(parameters, options)),
57
- ],
58
- [
59
- "connection.models.list",
60
- validated(connectionModelsListParametersSchema, (client, parameters, options) => client.listConnectionModels(parameters, options)),
61
- ],
62
- [
63
- "connection.show",
64
- validated(connectionShowParametersSchema, (client, parameters, options) => client.showConnection(parameters, options)),
65
- ],
66
- [
67
- "connection.usage.show",
68
- validated(connectionUsageShowParametersSchema, (client, parameters, options) => client.showConnectionUsage(parameters, options)),
69
- ],
70
- [
71
- "container.index.list",
72
- validated(containerIndexListParametersSchema, (client, parameters, options) => client.listContainerIndex(parameters, options)),
73
- ],
74
- [
75
- "discovery.sessions.list",
76
- validated(discoverySessionsListParametersSchema, (client, parameters, options) => client.listDiscoveredSessions(parameters, options)),
77
- ],
78
- ["node.status", status],
79
- [
80
- "port.lease.acquire",
81
- validated(portLeaseAcquireParametersSchema, (client, parameters, options) => client.acquirePortLease(parameters, options)),
82
- ],
83
- [
84
- "port.lease.list",
85
- validated(portLeaseListParametersSchema, (client, parameters, options) => client.listPortLeases(parameters, options)),
86
- ],
87
- [
88
- "port.lease.release",
89
- validated(portLeaseReleaseParametersSchema, (client, parameters, options) => client.releasePortLease(parameters, options)),
90
- ],
91
- [
92
- "port.lease.renew",
93
- validated(portLeaseRenewParametersSchema, (client, parameters, options) => client.renewPortLease(parameters, options)),
94
- ],
95
- [
96
- "project.guard.show",
97
- validated(projectGuardShowParametersSchema, (client, parameters, options) => client.showProjectGuard(parameters, options)),
98
- ],
99
- [
100
- "project.list",
101
- validated(projectListParametersSchema, (client, parameters, options) => client.listProjects(parameters, options)),
102
- ],
103
- [
104
- "project.show",
105
- validated(projectShowParametersSchema, (client, parameters, options) => client.showProject(parameters, options)),
106
- ],
107
- [
108
- "receipt.get",
109
- validated(receiptGetParametersSchema, (client, parameters, options) => client.getReceipt(parameters, options)),
110
- ],
111
- [
112
- "routine.list",
113
- validated(routineListParametersSchema, (client, parameters, options) => client.listRoutines(parameters, options)),
114
- ],
115
- [
116
- "routine.show",
117
- validated(routineShowParametersSchema, (client, parameters, options) => client.showRoutine(parameters, options)),
118
- ],
119
- [
120
- "run.ledger.create",
121
- validated(runLedgerCreateParametersSchema, (client, parameters, options) => client.createRunLedger(parameters, options)),
122
- ],
123
- [
124
- "run.ledger.list",
125
- validated(runLedgerListParametersSchema, (client, parameters, options) => client.listRunLedgers(parameters, options)),
126
- ],
127
- [
128
- "run.ledger.task.dispatch",
129
- validated(runLedgerTaskDispatchParametersSchema, (client, parameters, options) => client.dispatchRunLedgerTask(parameters, options)),
130
- ],
131
- [
132
- "run.ledger.task.list",
133
- validated(runLedgerTaskListParametersSchema, (client, parameters, options) => client.listRunLedgerTasks(parameters, options)),
134
- ],
135
- [
136
- "run.ledger.task.settle",
137
- validated(runLedgerTaskSettleParametersSchema, (client, parameters, options) => client.settleRunLedgerTask(parameters, options)),
138
- ],
139
- [
140
- "run.ledger.task.show",
141
- validated(runLedgerTaskShowParametersSchema, (client, parameters, options) => client.showRunLedgerTask(parameters, options)),
142
- ],
143
- [
144
- "session.archive",
145
- validated(sessionArchiveParametersSchema, (client, parameters, options) => client.archiveSession(parameters, options)),
146
- ],
147
- [
148
- "session.create",
149
- validated(sessionCreateParametersSchema, (client, parameters, options) => client.createSession(parameters, options)),
150
- ],
151
- [
152
- "session.diff",
153
- validated(sessionDiffParametersSchema, (client, parameters, options) => client.diffSession(parameters, options)),
154
- ],
155
- [
156
- "session.events.list",
157
- validated(sessionEventsListParametersSchema, (client, parameters, options) => client.listSessionEvents(parameters, options)),
158
- ],
159
- [
160
- "session.history.read",
161
- validated(sessionHistoryReadParametersSchema, (client, parameters, options) => client.readSessionHistory(parameters, options)),
162
- ],
163
- [
164
- "session.list",
165
- validated(sessionListParametersSchema, (client, parameters, options) => client.listSessions(parameters, options)),
166
- ],
167
- [
168
- "session.observe",
169
- validated(sessionObserveParametersSchema, (client, parameters, options) => client.observeSessions(parameters, options)),
170
- ],
171
- [
172
- "session.resume",
173
- validated(sessionResumeParametersSchema, (client, parameters, options) => client.resumeSession(parameters, options)),
174
- ],
175
- [
176
- "session.show",
177
- validated(sessionShowParametersSchema, (client, parameters, options) => client.showSession(parameters, options)),
178
- ],
179
- [
180
- "session.start",
181
- validated(sessionStartParametersSchema, (client, parameters, options) => client.startSession(parameters, options)),
182
- ],
183
- [
184
- "session.stop",
185
- validated(sessionStopParametersSchema, (client, parameters, options) => client.stopSession(parameters, options)),
186
- ],
187
- [
188
- "turn.cancel",
189
- validated(turnCancelParametersSchema, (client, parameters, options) => client.cancelTurn(parameters, options)),
190
- ],
191
- [
192
- "turn.interrupt",
193
- validated(turnInterruptParametersSchema, (client, parameters, options) => client.interruptTurn(parameters, options)),
194
- ],
195
- [
196
- "turn.queue.list",
197
- validated(turnQueueListParametersSchema, (client, parameters, options) => client.listTurnQueue(parameters, options)),
198
- ],
199
- [
200
- "turn.send",
201
- validated(turnSendParametersSchema, (client, parameters, options) => client.sendTurn(parameters, options)),
202
- ],
203
- [
204
- "turn.show",
205
- validated(turnShowParametersSchema, (client, parameters, options) => client.showTurn(parameters, options)),
206
- ],
207
- [
208
- "turn.wait",
209
- validated(turnWaitParametersSchema, (client, parameters, options) => client.waitTurns(parameters, options)),
210
- ],
211
- [
212
- "workspace.list",
213
- validated(workspaceListParametersSchema, (client, parameters, options) => client.listWorkspaces(parameters, options)),
214
- ],
215
- [
216
- "workspace.show",
217
- validated(workspaceShowParametersSchema, (client, parameters, options) => client.showWorkspace(parameters, options)),
218
- ],
8
+ const WITHOUT_PARAMETERS = new Set([
9
+ "showNodeUpdate",
10
+ "status",
219
11
  ]);
12
+ const sdkArguments = ({ operation, sdkOperation }, parameters, options) => {
13
+ if (sdkOperation === "call")
14
+ return [operation, parameters, options];
15
+ return WITHOUT_PARAMETERS.has(sdkOperation)
16
+ ? [options]
17
+ : [parameters, options];
18
+ };
19
+ const isSdkEffect = (value) => Effect.isEffect(value);
20
+ export const bindSdkOperation = (tool) => (client, parameters, options) => {
21
+ const operation = Reflect.get(client, tool.sdkOperation);
22
+ if (typeof operation !== "function")
23
+ return Effect.die(new Error(`The SDK client has no ${tool.sdkOperation} for ${tool.operation}.`));
24
+ const result = Reflect.apply(operation, client, sdkArguments(tool, parameters, options));
25
+ return isSdkEffect(result)
26
+ ? result
27
+ : Effect.die(new Error(`The SDK operation ${tool.sdkOperation} for ${tool.operation} returned no Effect.`));
28
+ };
29
+ const handedOver = ({ operation }, checked, input) => operation === "session.resume" &&
30
+ Predicate.isObject(checked) &&
31
+ Predicate.hasProperty(input, "parent") &&
32
+ input.parent !== undefined
33
+ ? { ...checked, parent: input.parent }
34
+ : checked;
35
+ const callFor = (tool) => {
36
+ const run = bindSdkOperation(tool);
37
+ return (node, input) => {
38
+ const payload = localNodeRequestPayloadSchema.safeParse({
39
+ method: tool.operation,
40
+ parameters: input === undefined && WITHOUT_PARAMETERS.has(tool.sdkOperation)
41
+ ? {}
42
+ : input,
43
+ });
44
+ return payload.success
45
+ ? node.runNodeClientOperation((client, options) => run(client, handedOver(tool, payload.data.parameters, input), options), recoveryOf(input))
46
+ : invalidNodeInput(payload.error);
47
+ };
48
+ };
49
+ const callsOf = (tools) => new Map(tools.map((tool) => [
50
+ tool.operation,
51
+ callFor(tool),
52
+ ]));
53
+ export const COORDINATOR_CALLS = callsOf(coordinatorToolDefinitions());
220
54
  export const callCoordinator = (node) => (operation, input) => {
221
55
  const call = COORDINATOR_CALLS.get(operation);
222
56
  return call === undefined
223
57
  ? Effect.die(new Error(`No SDK call for ${operation}.`))
224
58
  : call(node, input);
225
59
  };
226
- export const WORKER_CALLS = (() => {
227
- const available = new Map(COORDINATOR_CALLS);
228
- available.set("context.show", validated(invocationContextShowParametersSchema, (client, parameters, options) => client.showCurrentContext(parameters, options)));
229
- available.set("approval.respond", validated(approvalRespondParametersSchema, (client, parameters, options) => client.respondToApproval(parameters, options)));
230
- available.set("session.inbox.ack", validated(sessionInboxAckParametersSchema, (client, parameters, options) => client.acknowledgeSessionDelivery(parameters, options)));
231
- available.set("session.inbox.check", validated(sessionInboxCheckParametersSchema, (client, parameters, options) => client.checkSessionInbox(parameters, options)));
232
- available.set("session.message.send", validated(sessionMessageSendParametersSchema, (client, parameters, options) => client.sendSessionMessage(parameters, options)));
233
- return new Map(workerToolDefinitions("orchestrator").map(({ operation }) => {
234
- const call = available.get(operation);
235
- if (call === undefined)
236
- throw new Error(`No worker SDK call for ${operation}.`);
237
- return [operation, call];
238
- }));
239
- })();
60
+ export const WORKER_CALLS = callsOf(workerToolDefinitions("orchestrator"));
240
61
  //# sourceMappingURL=calls.js.map
@@ -1,15 +1,16 @@
1
1
  import type { RouteKind } from "@maiaos/client-core/cockpit";
2
2
  import { type CoordinatorToolOperation, type ProtocolError } from "@maiaos/sdk";
3
+ import { type SupervisedResume } from "@maiaos/sdk/node/effect";
3
4
  import { type Crypto, Effect } from "effect";
4
5
  import { type Fleet } from "../fleet/index.js";
5
6
  import { type CliNodeEffect, type CliNodeResult } from "../local-node/index.js";
6
- export type ToolReach = (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
7
+ export type ToolReach = <TOperation extends CoordinatorToolOperation>(operation: TOperation, input: TOperation extends "session.resume" ? SupervisedResume : unknown) => CliNodeEffect<unknown>;
7
8
  export type ToolAnswer = CliNodeResult<unknown> | {
8
9
  readonly error: ProtocolError;
9
10
  readonly ok: false;
10
11
  readonly result: unknown;
11
12
  };
12
- type ToolKind = Exclude<RouteKind, "terminal">;
13
+ type ToolKind = Exclude<RouteKind, "inbox" | "terminal">;
13
14
  type ToolRoute = {
14
15
  readonly held?: {
15
16
  readonly ids: (input: object) => unknown;
@@ -1,4 +1,5 @@
1
- import { localNodeRequestPayloadSchema, } from "@maiaos/sdk";
1
+ import { localNodeRequestPayloadSchema, sessionShowResultSchema, } from "@maiaos/sdk";
2
+ import { resumeSupervised, } from "@maiaos/sdk/node/effect";
2
3
  import { Effect, Predicate, Result } from "effect";
3
4
  import { askEach, failureOf, fleetNodes, holderIn, mergeLists, refused, routes, } from "../fleet/index.js";
4
5
  import { invalidNodeInput, } from "../local-node/index.js";
@@ -35,6 +36,9 @@ export const TOOL_ROUTES = new Map([
35
36
  ["container.index.list", LOCAL],
36
37
  ["discovery.sessions.list", LOCAL],
37
38
  ["node.status", LOCAL],
39
+ ["node.update.pause", LOCAL],
40
+ ["node.update.resume", LOCAL],
41
+ ["node.update.show", LOCAL],
38
42
  ["port.lease.acquire", LOCAL],
39
43
  ["port.lease.list", LOCAL],
40
44
  ["port.lease.release", LOCAL],
@@ -45,6 +49,7 @@ export const TOOL_ROUTES = new Map([
45
49
  ["receipt.get", held("command", "commandId")],
46
50
  ["reference.resolve", held("project", "projectId")],
47
51
  ["routine.list", held("project", "projectId", true)],
52
+ ["routine.runs", held("routine", "routineId")],
48
53
  ["routine.show", held("routine", "routineId")],
49
54
  ["run.ledger.create", LOCAL],
50
55
  ["run.ledger.list", LOCAL],
@@ -53,9 +58,12 @@ export const TOOL_ROUTES = new Map([
53
58
  ["run.ledger.task.settle", LOCAL],
54
59
  ["run.ledger.task.show", LOCAL],
55
60
  ["session.archive", held("session", "sessionId")],
61
+ ["session.command.list", held("session", "sessionId")],
62
+ ["session.command.send", held("session", "sessionId")],
56
63
  ["session.create", held("workspace", "workspaceId")],
57
64
  ["session.diff", held("session", "sessionId")],
58
65
  ["session.events.list", held("session", "sessionId")],
66
+ ["session.git.status", held("session", "sessionId")],
59
67
  ["session.history.read", HISTORY],
60
68
  ["session.list", held("project", "projectId", true)],
61
69
  ["session.observe", held("session", "sessionIds", true)],
@@ -70,6 +78,8 @@ export const TOOL_ROUTES = new Map([
70
78
  ["turn.send", held("session", "sessionId")],
71
79
  ["turn.show", held("turn", "turnId")],
72
80
  ["turn.wait", held("turn", "turnIds")],
81
+ ["workspace.branches.list", held("workspace", "workspaceId")],
82
+ ["workspace.code-host.show", held("workspace", "workspaceId")],
73
83
  ["workspace.list", held("project", "projectId")],
74
84
  ["workspace.show", held("workspace", "workspaceId")],
75
85
  ]);
@@ -155,14 +165,29 @@ const mergedAnswer = (operation) => (answers) => {
155
165
  const mergedList = (nodes, operation, input) => continues(input)
156
166
  ? Effect.succeed(refused("invalid_argument", `A cursor pages one Node: ${CHOOSE_NODE} to page it.`))
157
167
  : Effect.map(askEach(nodes, (reach) => reach(operation, input)), mergedAnswer(operation));
158
- const routeAmong = (local, nodes, { held, merged }) => (operation, input) => {
168
+ const shownOn = (reach, sessionId) => Effect.map(reach("session.show", { sessionId }), (answer) => {
169
+ if (!answer.ok)
170
+ return answer;
171
+ const shown = sessionShowResultSchema.safeParse(answer.value);
172
+ return shown.success
173
+ ? { ok: true, value: shown.data }
174
+ : refused("internal_error", "A Node answered an unknown Session show.");
175
+ });
176
+ const resumeOn = (nodes, parameters) => ({ reach }) => resumeSupervised({
177
+ claim: () => Effect.succeed({ ok: true, value: parameters.parent }),
178
+ parentShows: (sessionId) => Effect.map(askEach(nodes, (asked) => shownOn(asked, sessionId)), (answers) => ({
179
+ ok: true,
180
+ value: answers.map(({ result }) => result),
181
+ })),
182
+ resumeSession: (resumed) => reach("session.resume", resumed),
183
+ showSession: (sessionId) => shownOn(reach, sessionId),
184
+ }, parameters);
185
+ const routeAmong = (local, nodes, { held, merged }) => (operation, input, send) => {
159
186
  const ids = held === undefined ? [] : heldIds(held, input);
160
187
  if (held !== undefined && ids.length > 0)
161
- return Effect.flatMap(holderOfAll(nodes, held.kind, ids), (holder) => holder.ok
162
- ? holder.value.reach(operation, input)
163
- : Effect.succeed(holder));
188
+ return Effect.flatMap(holderOfAll(nodes, held.kind, ids), (holder) => holder.ok ? send(holder.value) : Effect.succeed(holder));
164
189
  return merged === undefined
165
- ? local.reach(operation, input)
190
+ ? send(local)
166
191
  : mergedList(nodes, operation, input);
167
192
  };
168
193
  const ROUTED = new Set(TOOL_ROUTES.keys());
@@ -178,12 +203,16 @@ export const routeToolCall = (fleet, operation, input) => {
178
203
  });
179
204
  if (!checked.success)
180
205
  return invalidNodeInput(checked.error);
206
+ const { data } = checked;
181
207
  return Effect.flatMap(fleetNodes(fleet), (space) => {
182
208
  if (!space.ok)
183
209
  return Effect.succeed(space);
210
+ const send = data.method === "session.resume"
211
+ ? resumeOn(space.value, data.parameters)
212
+ : ({ reach }) => reach(operation, input);
184
213
  return space.value.length === 1
185
- ? local.reach(operation, input)
186
- : routeAmong(local, space.value, route)(operation, input);
214
+ ? send(local)
215
+ : routeAmong(local, space.value, route)(operation, input, send);
187
216
  });
188
217
  };
189
218
  //# sourceMappingURL=routing.js.map
@@ -8,13 +8,22 @@ export type ToolFleet = Omit<Fleet<ToolReach>, "local"> & {
8
8
  readonly node: string;
9
9
  };
10
10
  export declare const toolResult: (result: ToolAnswer) => McpSchema.CallToolResult;
11
+ declare const SessionRoleUnreadable_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
12
+ readonly _tag: "SessionRoleUnreadable";
13
+ } & Readonly<A>;
14
+ export declare class SessionRoleUnreadable extends SessionRoleUnreadable_base<{
15
+ readonly message: string;
16
+ }> {
17
+ }
18
+ type McpStartError = Cause.IllegalArgumentError | SessionRoleUnreadable;
11
19
  export declare const coordinatorMcpLayer: (node: CliNodeOperations, version: string, { fleet, worker, }?: {
12
20
  readonly fleet?: ToolFleet;
13
21
  readonly worker?: boolean;
14
- }) => Layer.Layer<never, Cause.IllegalArgumentError, Crypto.Crypto | Stdio>;
22
+ }) => Layer.Layer<never, McpStartError, Crypto.Crypto | Stdio>;
15
23
  export declare const serveCoordinatorMcp: (node: CliNodeOperations, version: string, options?: {
16
24
  readonly fleet?: ToolFleet;
17
25
  readonly stdio?: Layer.Layer<Stdio>;
18
26
  readonly worker?: boolean;
19
27
  }) => Effect.Effect<number, never, Crypto.Crypto>;
28
+ export {};
20
29
  //# sourceMappingURL=server.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import * as NodeStdio from "@effect/platform-node-shared/NodeStdio";
2
2
  import { coordinatorToolDefinitions, workerToolDefinitions, } from "@maiaos/sdk";
3
- import { Cause, Context, Crypto, Effect, Exit, Fiber, Layer, Logger, Predicate, } from "effect";
3
+ import { Cause, Context, Crypto, Data, Effect, Exit, Fiber, Layer, Logger, Predicate, } from "effect";
4
4
  import * as McpProtocol from "effect/ai/McpProtocol";
5
5
  import * as McpSchema from "effect/ai/McpSchema";
6
6
  import * as McpServer from "effect/ai/McpServer";
@@ -43,15 +43,25 @@ const callFor = (definition) => {
43
43
  ? Effect.die(new Error(`No SDK call for ${definition.operation}.`))
44
44
  : Effect.succeed(call);
45
45
  };
46
+ export class SessionRoleUnreadable extends Data.TaggedError("SessionRoleUnreadable") {
47
+ }
48
+ const CREDENTIAL_FAILURES = new Set([
49
+ "authentication_failed",
50
+ "configuration_invalid",
51
+ ]);
46
52
  const sessionRole = (node) => {
47
53
  const show = WORKER_CALLS.get("context.show");
48
54
  return show === undefined
49
55
  ? Effect.succeed("worker")
50
- : show(node, {}).pipe(Effect.map((result) => result.ok &&
51
- Predicate.hasProperty(result.value, "role") &&
52
- result.value.role === "orchestrator"
53
- ? "orchestrator"
54
- : "worker"));
56
+ : show(node, {}).pipe(Effect.flatMap((result) => result.ok || CREDENTIAL_FAILURES.has(result.error.code)
57
+ ? Effect.succeed(result.ok &&
58
+ Predicate.hasProperty(result.value, "role") &&
59
+ result.value.role === "orchestrator"
60
+ ? "orchestrator"
61
+ : "worker")
62
+ : Effect.fail(new SessionRoleUnreadable({
63
+ message: `This Session's context.show failed (${result.error.code}: ${result.error.message}), so its tools are unknown.`,
64
+ }))), Effect.tapError((error) => Effect.logError(error.message)));
55
65
  };
56
66
  const answerFor = (node, call, fleet) => (definition) => (payload) => {
57
67
  const { operation } = definition;
@@ -0,0 +1,158 @@
1
+ import { MAX_AGENT_PAGE_SIZE, MAX_DISCOVERY_PAGE_SIZE, MAX_DISCOVERY_WINDOW_DAYS, remoteNodeRegisterPreviewParametersSchema, routineCreatePreviewParametersSchema, } from "@maiaos/sdk";
2
+ import * as Effect from "effect/Effect";
3
+ import { SOURCES } from "../import/batch/index.js";
4
+ import { classify, listLive, readyOf } from "../routine/portable/index.js";
5
+ import { ask, CREATE, held, idOf, listedIn, named, pages, planned, skip, } from "./item.js";
6
+ const skips = (items, reference) => named(items, reference)?.action === "skip";
7
+ const projectDecision = (live) => ({ name, path }) => {
8
+ if (path === undefined)
9
+ return skip("A Project registers from a folder on the Node's machine: give 'path'.");
10
+ return live.some((item) => item.name === name)
11
+ ? skip("A Project of this name exists; the plan cannot tell whether it is the same repository.")
12
+ : CREATE;
13
+ };
14
+ export const planProjects = (context, projects) => Effect.flatMap(projects.length === 0
15
+ ? Effect.succeed([])
16
+ : pages((afterCursor = "0") => ask(context.dependencies.listProjects?.({ afterCursor, limit: 100 }))), (live) => Effect.map(planned(context, ["projects", projects], projectDecision(live)), (items) => items.map(listedIn(live.map(({ id }) => id)))));
17
+ const perProject = (references, projects, read) => Effect.map(Effect.forEach([
18
+ ...new Set(references.flatMap((reference) => idOf(named(projects, reference)) ?? [])),
19
+ ], (projectId) => Effect.map(read(projectId), (live) => [projectId, live])), (entries) => new Map(entries));
20
+ const idsOf = (lives) => [...lives.values()].flatMap((live) => live.map(({ id }) => id));
21
+ const active = ({ state }) => state === "active";
22
+ const agentsOf = (context) => (projectId) => pages((afterCursor) => ask(context.dependencies.listAgents?.({
23
+ ...(afterCursor === undefined ? {} : { afterCursor }),
24
+ limit: MAX_AGENT_PAGE_SIZE,
25
+ projectId,
26
+ })));
27
+ const activeIn = (lives) => idsOf(new Map([...lives].map(([project, live]) => [project, live.filter(active)])));
28
+ const agentDecision = (projects, lives) => ({ executor, instructions, name, project }) => {
29
+ if (project === undefined)
30
+ return skip("An Agent lives in a Project: give 'project'.");
31
+ if (executor === undefined)
32
+ return skip("An Agent names its executor: give 'executor'.");
33
+ const home = idOf(named(projects, project));
34
+ const same = (lives.get(home ?? "") ?? []).filter(({ spec }) => spec.name === name);
35
+ const match = same.find((live) => active(live) &&
36
+ live.spec.instruction === instructions &&
37
+ live.spec.harness === executor);
38
+ if (match !== undefined)
39
+ return held(match.id, "name");
40
+ return same.length === 0
41
+ ? CREATE
42
+ : skip("An Agent of this name is disabled, or holds another instruction or executor.");
43
+ };
44
+ export const planAgents = (context, agents, projects) => {
45
+ const personas = agents.map(({ memory: _memory, ...persona }) => persona);
46
+ return Effect.flatMap(perProject(personas.map(({ project }) => project), projects, agentsOf(context)), (lives) => Effect.map(planned(context, ["agents", personas, ({ project }) => skips(projects, project)], agentDecision(projects, lives)), (items) => items.map(listedIn(activeIn(lives)))));
47
+ };
48
+ const homeOf = ({ agent, executor, name, project }, { agents, projects }, lives) => {
49
+ if (agent === undefined && executor === undefined)
50
+ return skip("A routine names who runs it: give 'agent' or 'executor'.");
51
+ const projectId = idOf(named(projects, project));
52
+ if (projectId === undefined)
53
+ return CREATE;
54
+ const live = lives.get(projectId) ?? [];
55
+ const agentId = idOf(named(agents, agent));
56
+ if (agent === undefined)
57
+ return { live, projectId };
58
+ if (agentId !== undefined)
59
+ return { agentId, live, projectId };
60
+ return live.some((item) => item.name === name)
61
+ ? skip("A live routine has this name, and its Agent is still to create.")
62
+ : CREATE;
63
+ };
64
+ const inputOf = ({ enabled, executor, name, prompt, schedule }, commandId, { agentId, projectId }) => routineCreatePreviewParametersSchema.safeParse({
65
+ commandId,
66
+ name,
67
+ ...(enabled === false ? { paused: true } : {}),
68
+ schedule,
69
+ template: {
70
+ ...(agentId === undefined ? { executor } : { agentId }),
71
+ projectId,
72
+ prompt,
73
+ },
74
+ });
75
+ const liveDecision = (draft, live) => {
76
+ const { entry } = classify(draft, live);
77
+ if (entry.action === "create")
78
+ return CREATE;
79
+ return entry.action === "unchanged" && entry.routineId !== undefined
80
+ ? held(entry.routineId, "name")
81
+ : skip(entry.error?.message ?? "A live routine has this name.");
82
+ };
83
+ const routineDecision = (context, plans, lives) => (routine, commandId) => {
84
+ const home = homeOf(routine, plans, lives);
85
+ if ("action" in home)
86
+ return home;
87
+ const input = inputOf(routine, commandId, home);
88
+ return input.success
89
+ ? liveDecision(readyOf(context, { input: input.data, name: routine.name }), home.live)
90
+ : skip("The routine does not fit a Node routine: check its name, executor and prompt.");
91
+ };
92
+ export const planRoutines = (context, routines, plans) => Effect.flatMap(perProject(routines.map(({ project }) => project), plans.projects, (projectId) => ask(listLive(context, projectId))), (lives) => Effect.map(planned(context, [
93
+ "routines",
94
+ routines,
95
+ ({ agent, project }) => skips(plans.projects, project) || skips(plans.agents, agent),
96
+ ], routineDecision(context, plans, lives)), (items) => items.map(listedIn(idsOf(lives)))));
97
+ const INCOMPLETE = skip("The Node did not list every native session, so the plan cannot place this one: plan again.");
98
+ const nativeDecision = (pointer, { complete, listed }) => {
99
+ const match = listed.find(({ executor, nativeId }) => executor === pointer.executor && nativeId === pointer.nativeId);
100
+ if (match?.adoptedSessionId !== undefined)
101
+ return held(match.adoptedSessionId, "native-id");
102
+ if (match !== undefined)
103
+ return CREATE;
104
+ return complete
105
+ ? skip(`The Node does not list this native session among those of the last ${String(MAX_DISCOVERY_WINDOW_DAYS)} days.`)
106
+ : INCOMPLETE;
107
+ };
108
+ const sessionDecision = (listing) => ({ project, transcript }) => {
109
+ if ("location" in transcript)
110
+ return skip("No importer reads a transcript file yet.");
111
+ return project === undefined
112
+ ? skip("An adoption runs in the Workspace of a Project: give 'project'.")
113
+ : nativeDecision(transcript, listing);
114
+ };
115
+ const natives = (context) => Effect.map(pages((cursor) => Effect.map(ask(context.dependencies.listDiscoveredSessions?.({
116
+ ...(cursor === undefined ? {} : { cursor }),
117
+ limit: MAX_DISCOVERY_PAGE_SIZE,
118
+ sinceDays: MAX_DISCOVERY_WINDOW_DAYS,
119
+ sources: SOURCES,
120
+ })), ({ nextCursor, ...page }) => ({
121
+ items: [page],
122
+ ...(nextCursor === undefined ? {} : { nextCursor }),
123
+ }))), (listed) => ({
124
+ complete: listed.every(({ sourceErrors, truncatedSources = [] }) => sourceErrors.length === 0 && truncatedSources.length === 0),
125
+ listed: listed.flatMap(({ items }) => items),
126
+ }));
127
+ const adoptedIn = ({ listed }) => listed.flatMap(({ adoptedSessionId }) => adoptedSessionId ?? []);
128
+ export const planSessions = (context, sessions, projects) => Effect.flatMap(sessions.some(({ transcript }) => "executor" in transcript)
129
+ ? natives(context)
130
+ : Effect.succeed({ complete: true, listed: [] }), (listing) => Effect.map(planned(context, ["sessions", sessions, ({ project }) => skips(projects, project)], sessionDecision(listing)), (items) => items.map(listedIn(adoptedIn(listing), listing.complete ? undefined : INCOMPLETE))));
131
+ const ready = ({ state }) => state === "ready";
132
+ const NOT_READY = skip("The registry holds a remote Node of this name that is not ready.");
133
+ const hostDecision = (local, nodes) => ({ name, reach }, commandId) => {
134
+ if (!local)
135
+ return skip("A host registers on this machine's Node: plan it without '--node'.");
136
+ if (reach.transport !== "ssh")
137
+ return skip("A Node reaches another machine over ssh.");
138
+ const host = reach.address;
139
+ const input = { commandId, host, name };
140
+ if (!remoteNodeRegisterPreviewParametersSchema.safeParse(input).success)
141
+ return skip("The host does not fit a remote Node: check its name and address.");
142
+ const match = nodes.find((node) => node.name === name);
143
+ if (match === undefined)
144
+ return CREATE;
145
+ if (!ready(match))
146
+ return NOT_READY;
147
+ return match.host === host
148
+ ? held(name, "name")
149
+ : skip("A remote Node of this name is registered at another address.");
150
+ };
151
+ export const planHosts = (context, hosts) => {
152
+ const local = context.node === undefined;
153
+ const registered = local && hosts.length > 0
154
+ ? Effect.map(ask(context.dependencies.listRemoteNodes?.({})), ({ nodes }) => nodes)
155
+ : Effect.succeed([]);
156
+ return Effect.flatMap(registered, (nodes) => Effect.map(planned(context, ["hosts", hosts], hostDecision(local, nodes)), (items) => items.map(listedIn(nodes.filter(ready).map(({ name }) => name)))));
157
+ };
158
+ //# sourceMappingURL=classes.js.map