@maiaos/cli 0.1.0-canary.2 → 0.1.0-canary.3

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 (216) hide show
  1. package/README.md +38 -265
  2. package/dist/address-space/address-space.d.ts +38 -0
  3. package/dist/address-space/address-space.js +130 -0
  4. package/dist/address-space/index.d.ts +2 -0
  5. package/dist/address-space/index.js +2 -0
  6. package/dist/agents/client.d.ts +171 -0
  7. package/dist/agents/client.js +8 -0
  8. package/dist/agents/commands.d.ts +7 -0
  9. package/dist/agents/commands.js +65 -0
  10. package/dist/agents/index.d.ts +3 -0
  11. package/dist/agents/index.js +3 -0
  12. package/dist/agents/input.d.ts +130 -0
  13. package/dist/agents/input.js +99 -0
  14. package/dist/agents/output/format.d.ts +8 -0
  15. package/dist/agents/output/format.js +47 -0
  16. package/dist/agents/output/index.d.ts +2 -0
  17. package/dist/agents/output/index.js +2 -0
  18. package/dist/agents/tree/index.d.ts +2 -0
  19. package/dist/agents/tree/index.js +2 -0
  20. package/dist/agents/tree/tree.d.ts +3 -0
  21. package/dist/agents/tree/tree.js +43 -0
  22. package/dist/bin/maia.cdx.json +37 -14
  23. package/dist/bin/maia.mjs +1 -1
  24. package/dist/bootstrap/exit.d.ts +14 -0
  25. package/dist/bootstrap/exit.js +42 -0
  26. package/dist/bootstrap/process.js +4 -26
  27. package/dist/cli/cli.js +70 -13
  28. package/dist/command-line/context.d.ts +13 -4
  29. package/dist/command-line/context.js +1 -1
  30. package/dist/command-line/index.d.ts +5 -5
  31. package/dist/command-line/index.js +5 -4
  32. package/dist/command-line/input/index.d.ts +1 -1
  33. package/dist/command-line/input/index.js +1 -1
  34. package/dist/command-line/input/stdin.d.ts +1 -0
  35. package/dist/command-line/input/stdin.js +1 -0
  36. package/dist/command-line/json.d.ts +1 -0
  37. package/dist/command-line/json.js +23 -0
  38. package/dist/command-line/output.d.ts +8 -1
  39. package/dist/command-line/output.js +33 -14
  40. package/dist/command-line/rows.d.ts +2 -0
  41. package/dist/command-line/rows.js +10 -1
  42. package/dist/command-line/two-phase.d.ts +5 -0
  43. package/dist/command-line/two-phase.js +33 -8
  44. package/dist/command-tree/help.d.ts +1 -1
  45. package/dist/command-tree/help.js +1 -0
  46. package/dist/command-tree/index.d.ts +2 -2
  47. package/dist/command-tree/index.js +1 -1
  48. package/dist/command-tree/local.js +12 -0
  49. package/dist/command-tree/placeholder.d.ts +1 -0
  50. package/dist/command-tree/placeholder.js +1 -0
  51. package/dist/command-tree/row.d.ts +2 -0
  52. package/dist/command-tree/tree.d.ts +3 -2
  53. package/dist/command-tree/tree.js +18 -2
  54. package/dist/connection/client.d.ts +93 -1
  55. package/dist/connection/client.js +7 -1
  56. package/dist/connection/index.d.ts +1 -1
  57. package/dist/connection/index.js +1 -1
  58. package/dist/connection/system.d.ts +1 -0
  59. package/dist/connection/system.js +109 -5
  60. package/dist/connection/tree/tree.js +17 -4
  61. package/dist/container/output/format.js +1 -2
  62. package/dist/dashboard/cockpit-client.d.ts +6 -0
  63. package/dist/dashboard/cockpit-client.js +27 -0
  64. package/dist/dashboard/cockpits.d.ts +29 -0
  65. package/dist/dashboard/cockpits.js +65 -0
  66. package/dist/dashboard/dashboard.d.ts +7 -0
  67. package/dist/dashboard/dashboard.js +47 -0
  68. package/dist/dashboard/draw.d.ts +15 -0
  69. package/dist/dashboard/draw.js +30 -0
  70. package/dist/dashboard/frame.d.ts +4 -0
  71. package/dist/dashboard/frame.js +15 -0
  72. package/dist/dashboard/index.d.ts +2 -0
  73. package/dist/dashboard/index.js +2 -0
  74. package/dist/dashboard/modes.d.ts +5 -0
  75. package/dist/dashboard/modes.js +16 -0
  76. package/dist/dashboard/node-connection.d.ts +15 -0
  77. package/dist/dashboard/node-connection.js +51 -0
  78. package/dist/dashboard/pi-tui.d.ts +6 -0
  79. package/dist/dashboard/pi-tui.js +35 -0
  80. package/dist/dashboard/status-bar.d.ts +4 -0
  81. package/dist/dashboard/status-bar.js +60 -0
  82. package/dist/dashboard/terminal.d.ts +53 -0
  83. package/dist/dashboard/terminal.js +165 -0
  84. package/dist/dashboard/tree-model.d.ts +28 -0
  85. package/dist/dashboard/tree-model.js +97 -0
  86. package/dist/dashboard/tree.d.ts +10 -0
  87. package/dist/dashboard/tree.js +76 -0
  88. package/dist/fleet/fleet.d.ts +70 -0
  89. package/dist/fleet/fleet.js +91 -0
  90. package/dist/fleet/index.d.ts +2 -0
  91. package/dist/fleet/index.js +2 -0
  92. package/dist/hold/output/format.js +1 -5
  93. package/dist/hold/tree/tree.js +1 -0
  94. package/dist/import/commands.js +3 -4
  95. package/dist/import/output.js +1 -4
  96. package/dist/local-node/client.d.ts +8 -4
  97. package/dist/local-node/client.js +20 -9
  98. package/dist/local-node/index.d.ts +1 -1
  99. package/dist/local-node/index.js +1 -1
  100. package/dist/login/commands.js +2 -1
  101. package/dist/mcp/calls.d.ts +1 -0
  102. package/dist/mcp/calls.js +36 -3
  103. package/dist/mcp/commands.d.ts +5 -2
  104. package/dist/mcp/commands.js +30 -4
  105. package/dist/mcp/routing.d.ts +24 -0
  106. package/dist/mcp/routing.js +188 -0
  107. package/dist/mcp/server.d.ts +13 -4
  108. package/dist/mcp/server.js +35 -12
  109. package/dist/presentation/output/format.js +4 -3
  110. package/dist/project-guard/commands.js +11 -2
  111. package/dist/project-workspace/commands.js +16 -6
  112. package/dist/project-workspace/output/human.d.ts +13 -0
  113. package/dist/project-workspace/output/human.js +17 -5
  114. package/dist/project-workspace/output/index.d.ts +1 -1
  115. package/dist/project-workspace/output/index.js +1 -1
  116. package/dist/project-workspace/output/metadata.js +1 -1
  117. package/dist/project-workspace/tree/tree.js +27 -12
  118. package/dist/reference/commands.js +4 -2
  119. package/dist/reference/index.d.ts +1 -1
  120. package/dist/reference/index.js +1 -1
  121. package/dist/reference/resolve.d.ts +2 -0
  122. package/dist/reference/resolve.js +20 -17
  123. package/dist/remote-node/client.d.ts +89 -9
  124. package/dist/remote-node/client.js +6 -1
  125. package/dist/remote-node/commands.d.ts +9 -0
  126. package/dist/remote-node/commands.js +96 -18
  127. package/dist/remote-node/connector.d.ts +12 -4
  128. package/dist/remote-node/connector.js +46 -25
  129. package/dist/remote-node/index.d.ts +2 -2
  130. package/dist/remote-node/index.js +2 -2
  131. package/dist/remote-node/reachability.d.ts +43 -1
  132. package/dist/remote-node/reachability.js +13 -3
  133. package/dist/remote-node/text.d.ts +2 -1
  134. package/dist/remote-node/text.js +74 -27
  135. package/dist/remote-node/tree/tree.js +21 -1
  136. package/dist/routine/client.d.ts +398 -0
  137. package/dist/routine/client.js +28 -0
  138. package/dist/routine/commands.d.ts +9 -0
  139. package/dist/routine/commands.js +109 -0
  140. package/dist/routine/index.d.ts +3 -0
  141. package/dist/routine/index.js +3 -0
  142. package/dist/routine/input.d.ts +28 -0
  143. package/dist/routine/input.js +44 -0
  144. package/dist/routine/output/format.d.ts +23 -0
  145. package/dist/routine/output/format.js +83 -0
  146. package/dist/routine/output/index.d.ts +2 -0
  147. package/dist/routine/output/index.js +2 -0
  148. package/dist/routine/tree/index.d.ts +2 -0
  149. package/dist/routine/tree/index.js +2 -0
  150. package/dist/routine/tree/tree.d.ts +3 -0
  151. package/dist/routine/tree/tree.js +70 -0
  152. package/dist/session/agent-permission.d.ts +2 -2
  153. package/dist/session/approval/commands.js +24 -6
  154. package/dist/session/approval/output/format.d.ts +11 -0
  155. package/dist/session/approval/output/format.js +8 -0
  156. package/dist/session/approval/output/index.d.ts +1 -1
  157. package/dist/session/approval/output/index.js +1 -1
  158. package/dist/session/attach-client.d.ts +1 -1
  159. package/dist/session/attach-client.js +12 -3
  160. package/dist/session/attach-render.js +15 -7
  161. package/dist/session/attach.js +17 -3
  162. package/dist/session/client.d.ts +4 -2
  163. package/dist/session/client.js +4 -15
  164. package/dist/session/commands.js +76 -9
  165. package/dist/session/create-tasks.js +29 -11
  166. package/dist/session/index.d.ts +1 -1
  167. package/dist/session/index.js +1 -0
  168. package/dist/session/interaction/output/format.js +2 -1
  169. package/dist/session/output/diff.js +3 -10
  170. package/dist/session/output/failure.js +3 -10
  171. package/dist/session/output/human.js +21 -10
  172. package/dist/session/output/index.d.ts +1 -1
  173. package/dist/session/output/index.js +1 -1
  174. package/dist/session/output/tasks.d.ts +16 -1
  175. package/dist/session/output/tasks.js +41 -27
  176. package/dist/session/tree/tree.js +56 -8
  177. package/dist/session/turn/client.d.ts +4 -1
  178. package/dist/session/turn/client.js +15 -2
  179. package/dist/session/turn/commands.d.ts +2 -0
  180. package/dist/session/turn/commands.js +38 -5
  181. package/dist/session/turn/index.d.ts +3 -3
  182. package/dist/session/turn/index.js +1 -1
  183. package/dist/session/turn/output.d.ts +7 -2
  184. package/dist/session/turn/output.js +36 -13
  185. package/dist/status/client.d.ts +7 -2
  186. package/dist/status/output/compact.d.ts +1 -0
  187. package/dist/status/output/compact.js +3 -0
  188. package/dist/status/output/human.d.ts +1 -1
  189. package/dist/status/output/human.js +71 -14
  190. package/dist/team-workspace/ceremony.d.ts +19 -0
  191. package/dist/team-workspace/ceremony.js +141 -0
  192. package/dist/team-workspace/client.d.ts +58 -0
  193. package/dist/team-workspace/client.js +6 -0
  194. package/dist/team-workspace/commands.d.ts +3 -0
  195. package/dist/team-workspace/commands.js +85 -0
  196. package/dist/team-workspace/confirmation.d.ts +4 -0
  197. package/dist/team-workspace/confirmation.js +8 -0
  198. package/dist/team-workspace/dependencies.d.ts +8 -0
  199. package/dist/team-workspace/dependencies.js +2 -0
  200. package/dist/team-workspace/index.d.ts +6 -0
  201. package/dist/team-workspace/index.js +5 -0
  202. package/dist/team-workspace/launcher.d.ts +17 -0
  203. package/dist/team-workspace/launcher.js +30 -0
  204. package/dist/team-workspace/output.d.ts +15 -0
  205. package/dist/team-workspace/output.js +28 -0
  206. package/dist/team-workspace/terminal.d.ts +9 -0
  207. package/dist/team-workspace/terminal.js +46 -0
  208. package/dist/terminal/client.d.ts +4 -0
  209. package/dist/terminal/client.js +3 -0
  210. package/dist/terminal/commands.js +37 -25
  211. package/dist/terminal/output/compact-list.d.ts +1 -0
  212. package/dist/terminal/output/compact-list.js +1 -0
  213. package/dist/terminal/output/human.d.ts +2 -19
  214. package/dist/terminal/output/human.js +6 -6
  215. package/dist/terminal/tree/tree.js +15 -15
  216. package/package.json +8 -6
@@ -1,8 +1,10 @@
1
1
  import { protocolErrorSchema } from "@maiaos/sdk";
2
2
  import * as Cause from "effect/Cause";
3
+ import * as Clock from "effect/Clock";
3
4
  import * as Config from "effect/Config";
4
5
  import * as Crypto from "effect/Crypto";
5
6
  import * as Data from "effect/Data";
7
+ import * as Duration from "effect/Duration";
6
8
  import * as Effect from "effect/Effect";
7
9
  import * as Option from "effect/Option";
8
10
  import * as Predicate from "effect/Predicate";
@@ -181,15 +183,21 @@ export const isBriefSaturation = (error) => {
181
183
  return (parsed.data.code === "saturated" && parsed.data.saturation === "admission");
182
184
  return maiaClientErrorCode(error) === "saturated";
183
185
  };
184
- export const SATURATION_RETRY = Schedule.exponential("100 millis").pipe(Schedule.jittered);
186
+ const SATURATION_RETRY = Schedule.exponential("100 millis").pipe(Schedule.jittered);
185
187
  const SATURATION_RETRIES = 4;
188
+ const DEADLINE_MARGIN_NANOS = 500000000n;
189
+ const endingBefore = (deadlineAt) => Schedule.fromStep(Effect.map(Schedule.toStep(SATURATION_RETRY), (step) => (now, input) => Effect.flatMap(step(now, input), ([output, backoff]) => Effect.flatMap(Clock.monotonicTimeNanos, (current) => current + Duration.toNanosUnsafe(backoff) + DEADLINE_MARGIN_NANOS >=
190
+ deadlineAt
191
+ ? Cause.done(output)
192
+ : Effect.succeed([output, backoff])))));
193
+ export const retryBriefSaturation = (attempt, deadlineAt) => Effect.retry(attempt, {
194
+ schedule: deadlineAt === undefined ? SATURATION_RETRY : endingBefore(deadlineAt),
195
+ times: SATURATION_RETRIES,
196
+ while: isBriefSaturation,
197
+ });
186
198
  const nodeClientOperation = (connect) => (operation, recovery) => completeOperation(Effect.gen(function* () {
187
199
  const connection = yield* connect;
188
- return yield* newCliIdentifier("request").pipe(Effect.flatMap((messageId) => operation(connection.client, { messageId })), Effect.retry({
189
- schedule: SATURATION_RETRY,
190
- times: SATURATION_RETRIES,
191
- while: isBriefSaturation,
192
- }));
200
+ return yield* retryBriefSaturation(newCliIdentifier("request").pipe(Effect.flatMap((messageId) => operation(connection.client, { messageId }))));
193
201
  }), recovery);
194
202
  const validatedNodeOperation = (runNodeClientOperation) => (input, schema, operation, recovery) => {
195
203
  const parameters = schema.safeParse(input);
@@ -208,6 +216,9 @@ const coordinatorOptions = (options) => ({
208
216
  const boundSession = (options) => options.remote === true
209
217
  ? () => Effect.fail(sessionRemoteDenied())
210
218
  : connectSession;
219
+ const discoveryOperation = (options, discoveryOptions, operation) => options.remote === true
220
+ ? Effect.fail(remoteDiscoveryDenied())
221
+ : asSessionOr(Effect.flatMap(discoveryOptions, operation), () => Effect.fail(sessionAttachmentDenied()));
211
222
  export const makeCliNodeOperations = (options = {}) => {
212
223
  const discoveryOptions = discoveryOptionsOf(options.discoveryOptions);
213
224
  const connector = options.connector ?? connectLocalNode;
@@ -217,9 +228,9 @@ export const makeCliNodeOperations = (options = {}) => {
217
228
  asCoordinator: () => makeCliNodeOperations(coordinatorOptions(options)),
218
229
  asSession: () => makeCliNodeOperations({ ...options, requireSession: true }),
219
230
  readStatus: Effect.map(connect, (connection) => connection.status),
220
- runDiscoveryOperation: (operation, recovery) => completeOperation(options.remote === true
221
- ? Effect.fail(remoteDiscoveryDenied())
222
- : asSessionOr(Effect.flatMap(discoveryOptions, operation), () => Effect.fail(sessionAttachmentDenied())), recovery),
231
+ remote: options.remote === true,
232
+ runConnectionOperation: (operation) => completeOperation(Effect.flatMap(connect, operation)),
233
+ runDiscoveryOperation: (operation, recovery) => completeOperation(discoveryOperation(options, discoveryOptions, operation), recovery),
223
234
  runNodeClientOperation,
224
235
  runValidatedNodeOperation: validatedNodeOperation(runNodeClientOperation),
225
236
  };
@@ -1,3 +1,3 @@
1
1
  export { type CliNodeCall, makeCallClient } from "./call.js";
2
- export { type CliMutationRecovery, type CliNodeBinding, type CliNodeConnection, type CliNodeConnector, type CliNodeEffect, type CliNodeOperations, type CliNodeOperationsOptions, type CliNodeResult, commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, type ParameterSchema, runLazyNodeDependency, } from "./client.js";
2
+ export { type CliMutationRecovery, type CliNodeBinding, type CliNodeConnection, type CliNodeConnector, type CliNodeEffect, type CliNodeOperations, type CliNodeOperationsOptions, type CliNodeResult, commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, type ParameterSchema, retryBriefSaturation, runLazyNodeDependency, } from "./client.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export { makeCallClient } from "./call.js";
2
- export { commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, runLazyNodeDependency, } from "./client.js";
2
+ export { commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, retryBriefSaturation, runLazyNodeDependency, } from "./client.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { CliArgumentError, parseOptions, reportError, requirePositionals, unknownCommand, writeSuccess, } from "../command-line/index.js";
2
+ import { CliArgumentError, LOCAL_NODE, parseOptions, reportError, requirePositionals, unknownCommand, writeSuccess, } from "../command-line/index.js";
3
3
  import { callNode, ConnectionNodeError, redactConnection, } from "../connection/index.js";
4
4
  import { listAgentProviders, signInAgentProvider } from "./agent-provider.js";
5
5
  import { loginFailureMessage } from "./failure.js";
@@ -57,6 +57,7 @@ const providerLogin = (tokens, context) => parsed(() => readProviderLogin(tokens
57
57
  }));
58
58
  const loginTarget = (tokens) => parseOptions(tokens, new Set(["--base-url", "--command-id", "--max-sessions", "--name"]), new Set(["--api-key-stdin", "--device-code"])).positionals[0];
59
59
  const remoteLoginRefusal = (target, context) => context.node === undefined ||
60
+ context.node === LOCAL_NODE ||
60
61
  target === "claude" ||
61
62
  target === "codex" ||
62
63
  target === "gateway"
@@ -3,5 +3,6 @@ import { type LocalNodeRequestMethod } from "@maiaos/sdk";
3
3
  import { type CliNodeEffect, type CliNodeOperations } from "../local-node/index.js";
4
4
  export type CoordinatorCall = (node: CliNodeOperations, input: unknown) => CliNodeEffect<unknown>;
5
5
  export declare const COORDINATOR_CALLS: ReadonlyMap<CoordinatorToolOperation, CoordinatorCall>;
6
+ export declare const callCoordinator: (node: CliNodeOperations) => (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
6
7
  export declare const WORKER_CALLS: ReadonlyMap<LocalNodeRequestMethod, CoordinatorCall>;
7
8
  //# sourceMappingURL=calls.d.ts.map
package/dist/mcp/calls.js CHANGED
@@ -1,5 +1,5 @@
1
- import { approvalListParametersSchema, 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, runLedgerCreateParametersSchema, runLedgerListParametersSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskListParametersSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskShowParametersSchema, sessionArchiveParametersSchema, sessionCreateParametersSchema, sessionDiffParametersSchema, sessionEventsListParametersSchema, sessionHistoryReadParametersSchema, sessionListParametersSchema, sessionObserveParametersSchema, sessionResumeParametersSchema, sessionShowParametersSchema, sessionStartParametersSchema, sessionStopParametersSchema, turnInterruptParametersSchema, turnSendParametersSchema, turnShowParametersSchema, turnWaitParametersSchema, workerToolDefinitions, workspaceListParametersSchema, workspaceShowParametersSchema, } from "@maiaos/sdk";
2
- import { Predicate } from "effect";
1
+ import { agentsListParametersSchema, agentsShowParametersSchema, approvalListParametersSchema, 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";
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)
@@ -27,6 +27,14 @@ const typedCall = (method) => (node, input) => {
27
27
  };
28
28
  export const COORDINATOR_CALLS = new Map([
29
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
+ ],
30
38
  [
31
39
  "approval.list",
32
40
  validated(approvalListParametersSchema, (client, parameters, options) => client.listApprovals(parameters, options)),
@@ -96,6 +104,14 @@ export const COORDINATOR_CALLS = new Map([
96
104
  "receipt.get",
97
105
  validated(receiptGetParametersSchema, (client, parameters, options) => client.getReceipt(parameters, options)),
98
106
  ],
107
+ [
108
+ "routine.list",
109
+ validated(routineListParametersSchema, (client, parameters, options) => client.listRoutines(parameters, options)),
110
+ ],
111
+ [
112
+ "routine.show",
113
+ validated(routineShowParametersSchema, (client, parameters, options) => client.showRoutine(parameters, options)),
114
+ ],
99
115
  [
100
116
  "run.ledger.create",
101
117
  validated(runLedgerCreateParametersSchema, (client, parameters, options) => client.createRunLedger(parameters, options)),
@@ -164,10 +180,18 @@ export const COORDINATOR_CALLS = new Map([
164
180
  "session.stop",
165
181
  validated(sessionStopParametersSchema, (client, parameters, options) => client.stopSession(parameters, options)),
166
182
  ],
183
+ [
184
+ "turn.cancel",
185
+ validated(turnCancelParametersSchema, (client, parameters, options) => client.cancelTurn(parameters, options)),
186
+ ],
167
187
  [
168
188
  "turn.interrupt",
169
189
  validated(turnInterruptParametersSchema, (client, parameters, options) => client.interruptTurn(parameters, options)),
170
190
  ],
191
+ [
192
+ "turn.queue.list",
193
+ validated(turnQueueListParametersSchema, (client, parameters, options) => client.listTurnQueue(parameters, options)),
194
+ ],
171
195
  [
172
196
  "turn.send",
173
197
  validated(turnSendParametersSchema, (client, parameters, options) => client.sendTurn(parameters, options)),
@@ -189,10 +213,19 @@ export const COORDINATOR_CALLS = new Map([
189
213
  validated(workspaceShowParametersSchema, (client, parameters, options) => client.showWorkspace(parameters, options)),
190
214
  ],
191
215
  ]);
216
+ export const callCoordinator = (node) => (operation, input) => {
217
+ const call = COORDINATOR_CALLS.get(operation);
218
+ return call === undefined
219
+ ? Effect.die(new Error(`No SDK call for ${operation}.`))
220
+ : call(node, input);
221
+ };
192
222
  export const WORKER_CALLS = (() => {
193
223
  const available = new Map(COORDINATOR_CALLS);
194
224
  available.set("context.show", validated(invocationContextShowParametersSchema, (client, parameters, options) => client.showCurrentContext(parameters, options)));
195
- return new Map(workerToolDefinitions().map(({ operation }) => {
225
+ available.set("session.inbox.ack", validated(sessionInboxAckParametersSchema, (client, parameters, options) => client.acknowledgeSessionDelivery(parameters, options)));
226
+ available.set("session.inbox.check", validated(sessionInboxCheckParametersSchema, (client, parameters, options) => client.checkSessionInbox(parameters, options)));
227
+ available.set("session.message.send", validated(sessionMessageSendParametersSchema, (client, parameters, options) => client.sendSessionMessage(parameters, options)));
228
+ return new Map(workerToolDefinitions("orchestrator").map(({ operation }) => {
196
229
  const call = available.get(operation);
197
230
  if (call === undefined)
198
231
  throw new Error(`No worker SDK call for ${operation}.`);
@@ -1,8 +1,11 @@
1
+ import type { CoordinatorToolOperation } from "@maiaos/sdk";
1
2
  import * as Effect from "effect/Effect";
2
3
  import { type CliServices, type CommandContext, type CommandEffect } from "../command-line/index.js";
3
- import type { CliNodeOperations } from "../local-node/index.js";
4
+ import type { CliNodeEffect, CliNodeOperations } from "../local-node/index.js";
5
+ import type { ToolFleet } from "./server.js";
4
6
  export type McpCliDependencies = {
5
- readonly serveMcp: (version: string, worker?: boolean) => Effect.Effect<number, unknown, CliServices>;
7
+ readonly callCoordinatorTool: (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
8
+ readonly serveMcp: (version: string, worker?: boolean, fleet?: ToolFleet) => Effect.Effect<number, unknown, CliServices>;
6
9
  };
7
10
  export declare const makeMcpClient: (node: CliNodeOperations) => McpCliDependencies;
8
11
  export declare const runMcpCommand: (tokens: readonly string[], context: CommandContext) => CommandEffect;
@@ -1,21 +1,47 @@
1
1
  import * as Config from "effect/Config";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Option from "effect/Option";
4
- import { requireNoArguments, } from "../command-line/index.js";
4
+ import { LOCAL_NODE, requireNoArguments, } from "../command-line/index.js";
5
+ import { refused } from "../fleet/index.js";
6
+ const coordinatorTool = (node) => (operation, input) => Effect.promise(() => import("./calls.js")).pipe(Effect.flatMap((module) => module.callCoordinator(node.asCoordinator())(operation, input)));
5
7
  export const makeMcpClient = (node) => ({
6
- serveMcp: (version, worker = false) => Effect.promise(() => import("./server.js")).pipe(Effect.flatMap((module) => Effect.gen(function* () {
8
+ callCoordinatorTool: coordinatorTool(node),
9
+ serveMcp: (version, worker = false, fleet) => Effect.promise(() => import("./server.js")).pipe(Effect.flatMap((module) => Effect.gen(function* () {
7
10
  const credential = yield* Config.option(Config.String("MAIA_SESSION_CREDENTIAL"));
8
11
  const origin = yield* Config.option(Config.String("MAIA_NODE_ORIGIN"));
9
12
  const session = worker || Option.isSome(credential) || Option.isSome(origin);
10
- return yield* module.serveCoordinatorMcp(session ? node.asSession() : node.asCoordinator(), version, { worker: session });
13
+ return yield* module.serveCoordinatorMcp(session ? node.asSession() : node.asCoordinator(), version, {
14
+ worker: session,
15
+ ...(session || fleet === undefined ? {} : { fleet }),
16
+ });
11
17
  }))),
12
18
  });
19
+ const fleetOf = ({ bindNode, dependencies, node, }) => {
20
+ const bound = new Map();
21
+ const bind = (name) => {
22
+ const known = bound.get(name);
23
+ if (known !== undefined)
24
+ return known;
25
+ const call = bindNode?.(name).callCoordinatorTool;
26
+ const reach = (operation, input) => call === undefined
27
+ ? Effect.succeed(refused("internal_error", `Node ${name} has no coordinator tools.`))
28
+ : call(operation, input);
29
+ bound.set(name, reach);
30
+ return reach;
31
+ };
32
+ return {
33
+ bind: bindNode && bind,
34
+ chosen: node !== undefined,
35
+ listRemoteNodes: dependencies.listRemoteNodes,
36
+ node: node ?? LOCAL_NODE,
37
+ };
38
+ };
13
39
  export const runMcpCommand = (tokens, context) => {
14
40
  const worker = tokens[0] === "--worker";
15
41
  requireNoArguments(worker ? tokens.slice(1) : tokens, "MCP");
16
42
  const { serveMcp } = context.dependencies;
17
43
  if (serveMcp === undefined)
18
44
  return Effect.die(new Error("The MCP server is unavailable."));
19
- return Effect.orDie(serveMcp(context.version, worker));
45
+ return Effect.orDie(serveMcp(context.version, worker, worker ? undefined : fleetOf(context)));
20
46
  };
21
47
  //# sourceMappingURL=commands.js.map
@@ -0,0 +1,24 @@
1
+ import type { RouteKind } from "@maiaos/client-core/cockpit";
2
+ import { type CoordinatorToolOperation, type ProtocolError } from "@maiaos/sdk";
3
+ import { type Crypto, Effect } from "effect";
4
+ import { type Fleet } from "../fleet/index.js";
5
+ import { type CliNodeEffect, type CliNodeResult } from "../local-node/index.js";
6
+ export type ToolReach = (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
7
+ export type ToolAnswer = CliNodeResult<unknown> | {
8
+ readonly error: ProtocolError;
9
+ readonly ok: false;
10
+ readonly result: unknown;
11
+ };
12
+ type ToolKind = Exclude<RouteKind, "terminal">;
13
+ type ToolRoute = {
14
+ readonly held?: {
15
+ readonly ids: (input: object) => unknown;
16
+ readonly kind: ToolKind;
17
+ };
18
+ readonly merged?: true;
19
+ };
20
+ export declare const TOOL_ROUTES: ReadonlyMap<CoordinatorToolOperation, ToolRoute>;
21
+ export declare const isRoutedTool: (operation: string) => operation is CoordinatorToolOperation;
22
+ export declare const routeToolCall: (fleet: Fleet<ToolReach>, operation: CoordinatorToolOperation, input: unknown) => Effect.Effect<ToolAnswer, never, Crypto.Crypto>;
23
+ export {};
24
+ //# sourceMappingURL=routing.d.ts.map
@@ -0,0 +1,188 @@
1
+ import { localNodeRequestPayloadSchema, } from "@maiaos/sdk";
2
+ import { Effect, Predicate, Result } from "effect";
3
+ import { askEach, failureOf, fleetNodes, holderIn, mergeLists, refused, routes, } from "../fleet/index.js";
4
+ import { invalidNodeInput, } from "../local-node/index.js";
5
+ const LOCAL = {};
6
+ const held = (kind, field, merged) => ({
7
+ held: {
8
+ ids: (input) => Predicate.hasProperty(input, field) ? input[field] : undefined,
9
+ kind,
10
+ },
11
+ ...(merged === undefined ? {} : { merged }),
12
+ });
13
+ const HISTORY = {
14
+ held: {
15
+ ids: (input) => Predicate.hasProperty(input, "target") &&
16
+ Predicate.hasProperty(input.target, "sessionId") &&
17
+ Predicate.hasProperty(input.target, "kind") &&
18
+ input.target.kind === "session"
19
+ ? input.target.sessionId
20
+ : undefined,
21
+ kind: "session",
22
+ },
23
+ };
24
+ export const TOOL_ROUTES = new Map([
25
+ ["agents.list", LOCAL],
26
+ ["agents.show", LOCAL],
27
+ ["approval.list", held("session", "sessionId", true)],
28
+ ["approval.show", held("approval", "approvalId")],
29
+ ["connection.detect", LOCAL],
30
+ ["connection.list", LOCAL],
31
+ ["connection.models.list", LOCAL],
32
+ ["connection.show", LOCAL],
33
+ ["connection.usage.show", LOCAL],
34
+ ["container.index.list", LOCAL],
35
+ ["discovery.sessions.list", LOCAL],
36
+ ["node.status", LOCAL],
37
+ ["port.lease.acquire", LOCAL],
38
+ ["port.lease.list", LOCAL],
39
+ ["port.lease.release", LOCAL],
40
+ ["port.lease.renew", LOCAL],
41
+ ["project.guard.show", held("project", "projectId")],
42
+ ["project.list", { merged: true }],
43
+ ["project.show", held("project", "projectId")],
44
+ ["receipt.get", held("command", "commandId")],
45
+ ["reference.resolve", held("project", "projectId")],
46
+ ["routine.list", held("project", "projectId", true)],
47
+ ["routine.show", held("routine", "routineId")],
48
+ ["run.ledger.create", LOCAL],
49
+ ["run.ledger.list", LOCAL],
50
+ ["run.ledger.task.dispatch", LOCAL],
51
+ ["run.ledger.task.list", LOCAL],
52
+ ["run.ledger.task.settle", LOCAL],
53
+ ["run.ledger.task.show", LOCAL],
54
+ ["session.archive", held("session", "sessionId")],
55
+ ["session.create", held("workspace", "workspaceId")],
56
+ ["session.diff", held("session", "sessionId")],
57
+ ["session.events.list", held("session", "sessionId")],
58
+ ["session.history.read", HISTORY],
59
+ ["session.list", held("project", "projectId", true)],
60
+ ["session.observe", held("session", "sessionIds", true)],
61
+ ["session.rename", held("session", "sessionId")],
62
+ ["session.resume", held("session", "sessionId")],
63
+ ["session.show", held("session", "sessionId")],
64
+ ["session.start", held("session", "sessionId")],
65
+ ["session.stop", held("session", "sessionId")],
66
+ ["turn.cancel", held("turn", "turnId")],
67
+ ["turn.interrupt", held("turn", "turnId")],
68
+ ["turn.queue.list", held("session", "sessionId")],
69
+ ["turn.send", held("session", "sessionId")],
70
+ ["turn.show", held("turn", "turnId")],
71
+ ["turn.wait", held("turn", "turnIds")],
72
+ ["workspace.list", held("project", "projectId")],
73
+ ["workspace.show", held("workspace", "workspaceId")],
74
+ ]);
75
+ const PROBES = {
76
+ approval: (approvalId) => ["approval.show", { approvalId }],
77
+ command: (commandId) => ["receipt.get", { commandId }],
78
+ project: (projectId) => ["project.show", { projectId }],
79
+ routine: (routineId) => ["routine.show", { routineId }],
80
+ session: (sessionId) => ["session.show", { sessionId }],
81
+ turn: (turnId) => ["turn.show", { turnId }],
82
+ workspace: (workspaceId) => ["workspace.show", { workspaceId }],
83
+ };
84
+ const CHOOSE_NODE = "serve that Node alone with 'maia --node <name> mcp'";
85
+ const heldIds = ({ ids, kind }, input) => {
86
+ const value = Predicate.isObject(input) ? ids(input) : undefined;
87
+ const named = [value].flat();
88
+ return named.length > 0 &&
89
+ named.every((id) => Predicate.isString(id) && routes({ id, kind }))
90
+ ? [...new Set(named)]
91
+ : [];
92
+ };
93
+ const oneHolder = (ids) => (holders) => {
94
+ const names = [...new Set(holders.map(({ node }) => node))];
95
+ const [holder] = holders;
96
+ return holder !== undefined && names.length === 1
97
+ ? { ok: true, value: holder }
98
+ : refused("invalid_argument", `${ids.join(", ")} are on different Nodes (${names.join(", ")}): call once per Node.`);
99
+ };
100
+ const holderOf = (nodes, kind, id) => Effect.flatMap(holderIn(nodes, { id, kind }, {
101
+ choose: CHOOSE_NODE,
102
+ probe: (reach) => reach(...PROBES[kind](id)),
103
+ }), (found) => Result.isSuccess(found)
104
+ ? Effect.succeed(found.success)
105
+ : Effect.fail(found.failure.error));
106
+ const holderOfAll = (nodes, kind, ids) => Effect.forEach(ids, (id) => holderOf(nodes, kind, id)).pipe(Effect.match({
107
+ onFailure: (error) => ({ error, ok: false }),
108
+ onSuccess: oneHolder(ids),
109
+ }));
110
+ const pageOf = (node, result) => {
111
+ if (!result.ok)
112
+ return result;
113
+ const { value } = result;
114
+ return Predicate.hasProperty(value, "items") && Array.isArray(value.items)
115
+ ? { ok: true, value: value }
116
+ : refused("internal_error", `Node ${node} answered a list without items.`);
117
+ };
118
+ const continues = (input) => Predicate.hasProperty(input, "afterCursor") &&
119
+ input.afterCursor !== undefined &&
120
+ input.afterCursor !== "0";
121
+ const observationOf = (result) => {
122
+ if (!result.ok)
123
+ return {};
124
+ const { value } = result;
125
+ return {
126
+ ...(Predicate.hasProperty(value, "observedAt")
127
+ ? { observedAt: value.observedAt }
128
+ : {}),
129
+ ...(Predicate.hasProperty(value, "stallAfterSeconds")
130
+ ? { stallAfterSeconds: value.stallAfterSeconds }
131
+ : {}),
132
+ };
133
+ };
134
+ const mergedAnswer = (operation) => (answers) => {
135
+ const lists = mergeLists(answers.map(({ node, result }) => ({
136
+ node,
137
+ result: pageOf(node, result),
138
+ })));
139
+ const merged = {
140
+ ...lists,
141
+ method: operation,
142
+ nodes: lists.nodes.map((entry, index) => {
143
+ const answer = answers[index];
144
+ return answer === undefined
145
+ ? entry
146
+ : { ...entry, ...observationOf(answer.result) };
147
+ }),
148
+ };
149
+ const failed = failureOf(merged.nodes);
150
+ return failed === undefined
151
+ ? { ok: true, value: merged }
152
+ : { error: failed, ok: false, result: merged };
153
+ };
154
+ const mergedList = (nodes, operation, input) => continues(input)
155
+ ? Effect.succeed(refused("invalid_argument", `A cursor pages one Node: ${CHOOSE_NODE} to page it.`))
156
+ : Effect.map(askEach(nodes, (reach) => reach(operation, input)), mergedAnswer(operation));
157
+ const routeAmong = (local, nodes, { held, merged }) => (operation, input) => {
158
+ const ids = held === undefined ? [] : heldIds(held, input);
159
+ if (held !== undefined && ids.length > 0)
160
+ return Effect.flatMap(holderOfAll(nodes, held.kind, ids), (holder) => holder.ok
161
+ ? holder.value.reach(operation, input)
162
+ : Effect.succeed(holder));
163
+ return merged === undefined
164
+ ? local.reach(operation, input)
165
+ : mergedList(nodes, operation, input);
166
+ };
167
+ const ROUTED = new Set(TOOL_ROUTES.keys());
168
+ export const isRoutedTool = (operation) => ROUTED.has(operation);
169
+ export const routeToolCall = (fleet, operation, input) => {
170
+ const route = TOOL_ROUTES.get(operation) ?? LOCAL;
171
+ const { local } = fleet;
172
+ if (route.held === undefined && route.merged === undefined)
173
+ return local.reach(operation, input);
174
+ const checked = localNodeRequestPayloadSchema.safeParse({
175
+ method: operation,
176
+ parameters: input,
177
+ });
178
+ if (!checked.success)
179
+ return invalidNodeInput(checked.error);
180
+ return Effect.flatMap(fleetNodes(fleet), (space) => {
181
+ if (!space.ok)
182
+ return Effect.succeed(space);
183
+ return space.value.length === 1
184
+ ? local.reach(operation, input)
185
+ : routeAmong(local, space.value, route)(operation, input);
186
+ });
187
+ };
188
+ //# sourceMappingURL=routing.js.map
@@ -1,10 +1,19 @@
1
1
  import { Cause, Crypto, Effect, Layer } from "effect";
2
- import { McpSchema } from "effect/ai";
2
+ import * as McpSchema from "effect/ai/McpSchema";
3
3
  import type { Stdio } from "effect/Stdio";
4
- import type { CliNodeOperations, CliNodeResult } from "../local-node/index.js";
5
- export declare const toolResult: (result: CliNodeResult<unknown>) => McpSchema.CallToolResult;
6
- export declare const coordinatorMcpLayer: (node: CliNodeOperations, version: string, worker?: boolean) => Layer.Layer<never, Cause.IllegalArgumentError, Crypto.Crypto | Stdio>;
4
+ import type { Fleet } from "../fleet/index.js";
5
+ import type { CliNodeOperations } from "../local-node/index.js";
6
+ import { type ToolAnswer, type ToolReach } from "./routing.js";
7
+ export type ToolFleet = Omit<Fleet<ToolReach>, "local"> & {
8
+ readonly node: string;
9
+ };
10
+ export declare const toolResult: (result: ToolAnswer) => McpSchema.CallToolResult;
11
+ export declare const coordinatorMcpLayer: (node: CliNodeOperations, version: string, { fleet, worker, }?: {
12
+ readonly fleet?: ToolFleet;
13
+ readonly worker?: boolean;
14
+ }) => Layer.Layer<never, Cause.IllegalArgumentError, Crypto.Crypto | Stdio>;
7
15
  export declare const serveCoordinatorMcp: (node: CliNodeOperations, version: string, options?: {
16
+ readonly fleet?: ToolFleet;
8
17
  readonly stdio?: Layer.Layer<Stdio>;
9
18
  readonly worker?: boolean;
10
19
  }) => Effect.Effect<number, never, Crypto.Crypto>;
@@ -1,8 +1,11 @@
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, } from "effect";
4
- import { McpProtocol, McpSchema, McpServer } from "effect/ai";
5
- import { COORDINATOR_CALLS, WORKER_CALLS, } from "./calls.js";
3
+ import { Cause, Context, Crypto, Effect, Exit, Fiber, Layer, Logger, Predicate, } from "effect";
4
+ import * as McpProtocol from "effect/ai/McpProtocol";
5
+ import * as McpSchema from "effect/ai/McpSchema";
6
+ import * as McpServer from "effect/ai/McpServer";
7
+ import { callCoordinator, COORDINATOR_CALLS, WORKER_CALLS, } from "./calls.js";
8
+ import { isRoutedTool, routeToolCall, } from "./routing.js";
6
9
  export const toolResult = (result) => result.ok
7
10
  ? new McpSchema.CallToolResult({
8
11
  content: [{ text: JSON.stringify(result.value), type: "text" }],
@@ -12,9 +15,10 @@ export const toolResult = (result) => result.ok
12
15
  {
13
16
  text: JSON.stringify({
14
17
  error: result.error,
15
- ...(result.recovery === undefined
16
- ? {}
17
- : { recovery: result.recovery }),
18
+ ...("recovery" in result && result.recovery !== undefined
19
+ ? { recovery: result.recovery }
20
+ : {}),
21
+ ...("result" in result ? { result: result.result } : {}),
18
22
  }),
19
23
  type: "text",
20
24
  },
@@ -39,19 +43,38 @@ const callFor = (definition) => {
39
43
  ? Effect.die(new Error(`No SDK call for ${definition.operation}.`))
40
44
  : Effect.succeed(call);
41
45
  };
42
- const registerTools = (node, worker) => Effect.gen(function* () {
46
+ const sessionRole = (node) => {
47
+ const show = WORKER_CALLS.get("context.show");
48
+ return show === undefined
49
+ ? 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"));
55
+ };
56
+ const answerFor = (node, call, fleet) => (definition) => (payload) => {
57
+ const { operation } = definition;
58
+ if (fleet === undefined || !isRoutedTool(operation))
59
+ return call(node, payload);
60
+ const { node: name, ...others } = fleet;
61
+ return routeToolCall({ ...others, local: { node: name, reach: callCoordinator(node) } }, operation, payload);
62
+ };
63
+ const registerTools = (node, definitions, fleet) => Effect.gen(function* () {
43
64
  const server = yield* McpServer.McpServer;
44
65
  const crypto = yield* Crypto.Crypto;
45
- yield* Effect.forEach(worker ? workerToolDefinitions() : coordinatorToolDefinitions(), (definition) => Effect.flatMap(callFor(definition), (call) => server.addTool({
66
+ yield* Effect.forEach(definitions, (definition) => Effect.flatMap(callFor(definition), (call) => server.addTool({
46
67
  annotations: Context.empty(),
47
- handle: (payload) => call(node, payload).pipe(Effect.provideService(Crypto.Crypto, crypto), Effect.map(toolResult)),
68
+ handle: (payload) => answerFor(node, call, fleet)(definition)(payload).pipe(Effect.provideService(Crypto.Crypto, crypto), Effect.map(toolResult)),
48
69
  tool: toolFor(definition),
49
70
  })), { discard: true });
50
71
  });
51
- export const coordinatorMcpLayer = (node, version, worker = false) => Layer.effectDiscard(registerTools(node, worker)).pipe(Layer.provide(McpServer.layerStdio({
72
+ export const coordinatorMcpLayer = (node, version, { fleet, worker = false, } = {}) => Layer.unwrap((worker
73
+ ? Effect.map(sessionRole(node), workerToolDefinitions)
74
+ : Effect.succeed(coordinatorToolDefinitions())).pipe(Effect.map((definitions) => Layer.effectDiscard(registerTools(node, definitions, worker ? undefined : fleet)).pipe(Layer.provide(McpServer.layerStdio({
52
75
  name: "maia",
53
76
  protocols: [McpProtocol.v2025_06_18],
54
77
  version,
55
- })));
56
- export const serveCoordinatorMcp = (node, version, options = {}) => Layer.launch(coordinatorMcpLayer(node, version, options.worker)).pipe(Effect.provide(options.stdio ?? NodeStdio.layer), Effect.provideService(Logger.LogToStderr, true), Effect.forkChild, Effect.flatMap(Fiber.await), Effect.map((exit) => Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause) ? 0 : 1));
78
+ }))))));
79
+ export const serveCoordinatorMcp = (node, version, options = {}) => Layer.launch(coordinatorMcpLayer(node, version, options)).pipe(Effect.provide(options.stdio ?? NodeStdio.layer), Effect.provideService(Logger.LogToStderr, true), Effect.forkChild, Effect.flatMap(Fiber.await), Effect.map((exit) => Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause) ? 0 : 1));
57
80
  //# sourceMappingURL=server.js.map
@@ -1,8 +1,9 @@
1
+ import { cell } from "../../command-line/index.js";
1
2
  export const isPresentationResult = (result) => result.command === "presentation.catalog.show" ||
2
3
  result.command === "presentation.workspace-directory.show" ||
3
4
  result.command === "presentation.project-list.show" ||
4
5
  result.command === "presentation.session-list.show";
5
- const cell = (value) => JSON.stringify(value).replaceAll(/\p{Control}/gu, " ");
6
+ const quoted = (value) => cell(JSON.stringify(value));
6
7
  const page = (result) => {
7
8
  if (result.method === "presentation.session-list.show")
8
9
  return {
@@ -19,7 +20,7 @@ const page = (result) => {
19
20
  ? "Projects"
20
21
  : "Workspace directory",
21
22
  rows: items
22
- .map((item) => `${item.id}\t${cell(item.name)}\t${item.revision}\n`)
23
+ .map((item) => `${item.id}\t${quoted(item.name)}\t${item.revision}\n`)
23
24
  .join(""),
24
25
  };
25
26
  };
@@ -27,6 +28,6 @@ export const formatPresentationResult = ({ result, }) => {
27
28
  if (result.method === "presentation.catalog.show")
28
29
  return `${result.catalogVersion}\t${result.catalogDigest}\toperator-local\n`;
29
30
  const { heading, rows } = page(result);
30
- return `${heading} (operator-local)\n${rows}${result.resources.nextCursor === undefined ? "" : `Next: ${cell(result.resources.nextCursor)}\n`}`;
31
+ return `${heading} (operator-local)\n${rows}${result.resources.nextCursor === undefined ? "" : `Next: ${quoted(result.resources.nextCursor)}\n`}`;
31
32
  };
32
33
  //# sourceMappingURL=format.js.map
@@ -1,6 +1,7 @@
1
1
  import { projectGuardConfirmParametersSchema, } from "@maiaos/sdk";
2
2
  import * as Effect from "effect/Effect";
3
- import { CliArgumentError, confirmParameters, parseOptions, readTwoPhaseMode, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeNodeResult, } from "../command-line/index.js";
3
+ import { onHolder } from "../address-space/index.js";
4
+ import { CliArgumentError, confirmParameters, parseOptions, readPipedPreview, readTwoPhaseMode, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeNodeResult, } from "../command-line/index.js";
4
5
  import { GUARD_OPTIONS, readGuardPreview, readGuardShow } from "./input.js";
5
6
  import { formatProjectGuardResult, } from "./output/index.js";
6
7
  const write = (context) => (result) => writeNodeResult(result, context, {
@@ -18,11 +19,19 @@ const GUARD_PROMPT = {
18
19
  describe: (preview) => formatProjectGuardResult({ command: preview.method, result: preview }),
19
20
  question: "Set these guards?",
20
21
  };
22
+ const confirmPipedGuards = (context) => Effect.flatMap(Effect.flatMap(readPipedPreview(context), confirmGuardParameters), (confirmation) => onHolder(context, { id: confirmation.projectId, kind: "project" }, (bound) => {
23
+ const confirm = bound.dependencies.confirmProjectGuard;
24
+ if (confirm === undefined)
25
+ return Effect.fail(new CliArgumentError("Project guards are unavailable."));
26
+ return Effect.map(confirm(confirmation), write(bound));
27
+ }));
21
28
  export const runProjectGuardSet = (tokens, context) => Effect.gen(function* () {
22
29
  const parsed = parseOptions(tokens, GUARD_OPTIONS, new Set(TWO_PHASE_FLAGS));
23
30
  const mode = readTwoPhaseMode(parsed.flags, context);
24
- if (mode === "confirm-stdin")
31
+ if (mode === "confirm-stdin") {
25
32
  requirePositionals(parsed.positionals, 0);
33
+ return yield* confirmPipedGuards(context);
34
+ }
26
35
  const { confirmProjectGuard, previewProjectGuard } = context.dependencies;
27
36
  if (confirmProjectGuard === undefined || previewProjectGuard === undefined)
28
37
  return yield* new CliArgumentError("Project guards are unavailable.");