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

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 (240) 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/bootstrap/run.js +5 -2
  28. package/dist/cli/cli.d.ts +2 -1
  29. package/dist/cli/cli.js +81 -16
  30. package/dist/command-line/context.d.ts +14 -4
  31. package/dist/command-line/context.js +1 -1
  32. package/dist/command-line/index.d.ts +6 -6
  33. package/dist/command-line/index.js +6 -5
  34. package/dist/command-line/input/arguments.d.ts +7 -0
  35. package/dist/command-line/input/arguments.js +22 -10
  36. package/dist/command-line/input/index.d.ts +2 -2
  37. package/dist/command-line/input/index.js +2 -2
  38. package/dist/command-line/input/stdin.d.ts +1 -0
  39. package/dist/command-line/input/stdin.js +1 -0
  40. package/dist/command-line/json.d.ts +1 -0
  41. package/dist/command-line/json.js +23 -0
  42. package/dist/command-line/output.d.ts +8 -1
  43. package/dist/command-line/output.js +33 -14
  44. package/dist/command-line/rows.d.ts +2 -0
  45. package/dist/command-line/rows.js +10 -1
  46. package/dist/command-line/two-phase.d.ts +5 -0
  47. package/dist/command-line/two-phase.js +33 -8
  48. package/dist/command-tree/help.d.ts +1 -1
  49. package/dist/command-tree/help.js +1 -0
  50. package/dist/command-tree/index.d.ts +2 -2
  51. package/dist/command-tree/index.js +1 -1
  52. package/dist/command-tree/local.js +12 -0
  53. package/dist/command-tree/placeholder.d.ts +1 -0
  54. package/dist/command-tree/placeholder.js +1 -0
  55. package/dist/command-tree/row.d.ts +2 -0
  56. package/dist/command-tree/tree.d.ts +3 -2
  57. package/dist/command-tree/tree.js +18 -2
  58. package/dist/connection/access/client.d.ts +13 -0
  59. package/dist/connection/access/client.js +19 -0
  60. package/dist/connection/access/commands.d.ts +6 -0
  61. package/dist/connection/access/commands.js +60 -0
  62. package/dist/connection/access/format.d.ts +8 -0
  63. package/dist/connection/access/format.js +61 -0
  64. package/dist/connection/access/index.d.ts +3 -0
  65. package/dist/connection/access/index.js +3 -0
  66. package/dist/connection/access/input.d.ts +53 -0
  67. package/dist/connection/access/input.js +83 -0
  68. package/dist/connection/client.d.ts +99 -1
  69. package/dist/connection/client.js +9 -1
  70. package/dist/connection/index.d.ts +2 -1
  71. package/dist/connection/index.js +2 -1
  72. package/dist/connection/system.d.ts +1 -0
  73. package/dist/connection/system.js +109 -5
  74. package/dist/connection/tree/tree.js +59 -8
  75. package/dist/container/output/format.js +1 -2
  76. package/dist/dashboard/cockpit-client.d.ts +6 -0
  77. package/dist/dashboard/cockpit-client.js +27 -0
  78. package/dist/dashboard/cockpits.d.ts +29 -0
  79. package/dist/dashboard/cockpits.js +65 -0
  80. package/dist/dashboard/dashboard.d.ts +7 -0
  81. package/dist/dashboard/dashboard.js +47 -0
  82. package/dist/dashboard/draw.d.ts +15 -0
  83. package/dist/dashboard/draw.js +30 -0
  84. package/dist/dashboard/frame.d.ts +4 -0
  85. package/dist/dashboard/frame.js +15 -0
  86. package/dist/dashboard/index.d.ts +2 -0
  87. package/dist/dashboard/index.js +2 -0
  88. package/dist/dashboard/modes.d.ts +5 -0
  89. package/dist/dashboard/modes.js +16 -0
  90. package/dist/dashboard/node-connection.d.ts +15 -0
  91. package/dist/dashboard/node-connection.js +51 -0
  92. package/dist/dashboard/pi-tui.d.ts +6 -0
  93. package/dist/dashboard/pi-tui.js +35 -0
  94. package/dist/dashboard/status-bar.d.ts +4 -0
  95. package/dist/dashboard/status-bar.js +60 -0
  96. package/dist/dashboard/terminal.d.ts +53 -0
  97. package/dist/dashboard/terminal.js +165 -0
  98. package/dist/dashboard/tree-model.d.ts +28 -0
  99. package/dist/dashboard/tree-model.js +97 -0
  100. package/dist/dashboard/tree.d.ts +10 -0
  101. package/dist/dashboard/tree.js +76 -0
  102. package/dist/fleet/fleet.d.ts +70 -0
  103. package/dist/fleet/fleet.js +91 -0
  104. package/dist/fleet/index.d.ts +2 -0
  105. package/dist/fleet/index.js +2 -0
  106. package/dist/hold/output/format.js +1 -5
  107. package/dist/hold/tree/tree.js +1 -0
  108. package/dist/import/commands.js +3 -4
  109. package/dist/import/output.js +1 -4
  110. package/dist/local-node/client.d.ts +9 -4
  111. package/dist/local-node/client.js +21 -9
  112. package/dist/local-node/index.d.ts +2 -1
  113. package/dist/local-node/index.js +2 -1
  114. package/dist/local-node/wait.d.ts +10 -0
  115. package/dist/local-node/wait.js +17 -0
  116. package/dist/login/commands.js +2 -1
  117. package/dist/mcp/calls.d.ts +1 -0
  118. package/dist/mcp/calls.js +37 -3
  119. package/dist/mcp/commands.d.ts +5 -2
  120. package/dist/mcp/commands.js +30 -4
  121. package/dist/mcp/routing.d.ts +24 -0
  122. package/dist/mcp/routing.js +188 -0
  123. package/dist/mcp/server.d.ts +13 -4
  124. package/dist/mcp/server.js +35 -12
  125. package/dist/presentation/output/format.js +4 -3
  126. package/dist/project-guard/commands.js +11 -2
  127. package/dist/project-workspace/commands.js +16 -6
  128. package/dist/project-workspace/output/human.d.ts +13 -0
  129. package/dist/project-workspace/output/human.js +17 -5
  130. package/dist/project-workspace/output/index.d.ts +1 -1
  131. package/dist/project-workspace/output/index.js +1 -1
  132. package/dist/project-workspace/output/metadata.js +1 -1
  133. package/dist/project-workspace/tree/tree.js +27 -12
  134. package/dist/reference/commands.js +4 -2
  135. package/dist/reference/index.d.ts +1 -1
  136. package/dist/reference/index.js +1 -1
  137. package/dist/reference/resolve.d.ts +2 -0
  138. package/dist/reference/resolve.js +28 -18
  139. package/dist/remote-node/client.d.ts +89 -9
  140. package/dist/remote-node/client.js +6 -1
  141. package/dist/remote-node/commands.d.ts +9 -0
  142. package/dist/remote-node/commands.js +96 -18
  143. package/dist/remote-node/connector.d.ts +12 -4
  144. package/dist/remote-node/connector.js +54 -26
  145. package/dist/remote-node/index.d.ts +2 -2
  146. package/dist/remote-node/index.js +2 -2
  147. package/dist/remote-node/reachability.d.ts +43 -1
  148. package/dist/remote-node/reachability.js +13 -3
  149. package/dist/remote-node/text.d.ts +2 -1
  150. package/dist/remote-node/text.js +74 -27
  151. package/dist/remote-node/tree/tree.js +21 -1
  152. package/dist/routine/client.d.ts +398 -0
  153. package/dist/routine/client.js +28 -0
  154. package/dist/routine/commands.d.ts +9 -0
  155. package/dist/routine/commands.js +109 -0
  156. package/dist/routine/index.d.ts +3 -0
  157. package/dist/routine/index.js +3 -0
  158. package/dist/routine/input.d.ts +28 -0
  159. package/dist/routine/input.js +44 -0
  160. package/dist/routine/output/format.d.ts +23 -0
  161. package/dist/routine/output/format.js +83 -0
  162. package/dist/routine/output/index.d.ts +2 -0
  163. package/dist/routine/output/index.js +2 -0
  164. package/dist/routine/tree/index.d.ts +2 -0
  165. package/dist/routine/tree/index.js +2 -0
  166. package/dist/routine/tree/tree.d.ts +3 -0
  167. package/dist/routine/tree/tree.js +70 -0
  168. package/dist/session/agent-permission.d.ts +2 -2
  169. package/dist/session/approval/commands.js +31 -9
  170. package/dist/session/approval/output/format.d.ts +11 -0
  171. package/dist/session/approval/output/format.js +8 -0
  172. package/dist/session/approval/output/index.d.ts +1 -1
  173. package/dist/session/approval/output/index.js +1 -1
  174. package/dist/session/attach-client.d.ts +1 -1
  175. package/dist/session/attach-client.js +12 -3
  176. package/dist/session/attach-render.js +15 -7
  177. package/dist/session/attach.js +17 -3
  178. package/dist/session/client.d.ts +12 -3
  179. package/dist/session/client.js +18 -17
  180. package/dist/session/commands.d.ts +1 -0
  181. package/dist/session/commands.js +120 -13
  182. package/dist/session/create-tasks.js +29 -11
  183. package/dist/session/index.d.ts +2 -2
  184. package/dist/session/index.js +2 -1
  185. package/dist/session/interaction/output/format.js +2 -1
  186. package/dist/session/output/diff.js +3 -10
  187. package/dist/session/output/failure.js +3 -10
  188. package/dist/session/output/human.d.ts +1 -0
  189. package/dist/session/output/human.js +21 -10
  190. package/dist/session/output/index.d.ts +2 -2
  191. package/dist/session/output/index.js +2 -2
  192. package/dist/session/output/tasks.d.ts +16 -1
  193. package/dist/session/output/tasks.js +41 -27
  194. package/dist/session/tree/tree.js +67 -8
  195. package/dist/session/turn/client.d.ts +4 -1
  196. package/dist/session/turn/client.js +22 -11
  197. package/dist/session/turn/commands.d.ts +2 -0
  198. package/dist/session/turn/commands.js +39 -11
  199. package/dist/session/turn/index.d.ts +3 -3
  200. package/dist/session/turn/index.js +1 -1
  201. package/dist/session/turn/output.d.ts +7 -2
  202. package/dist/session/turn/output.js +36 -13
  203. package/dist/status/client.d.ts +7 -2
  204. package/dist/status/command.js +3 -1
  205. package/dist/status/doctor.d.ts +5 -1
  206. package/dist/status/doctor.js +10 -4
  207. package/dist/status/output/compact.d.ts +1 -0
  208. package/dist/status/output/compact.js +3 -0
  209. package/dist/status/output/human.d.ts +1 -1
  210. package/dist/status/output/human.js +71 -14
  211. package/dist/team-workspace/ceremony.d.ts +19 -0
  212. package/dist/team-workspace/ceremony.js +141 -0
  213. package/dist/team-workspace/client.d.ts +58 -0
  214. package/dist/team-workspace/client.js +6 -0
  215. package/dist/team-workspace/commands.d.ts +3 -0
  216. package/dist/team-workspace/commands.js +85 -0
  217. package/dist/team-workspace/confirmation.d.ts +4 -0
  218. package/dist/team-workspace/confirmation.js +8 -0
  219. package/dist/team-workspace/dependencies.d.ts +8 -0
  220. package/dist/team-workspace/dependencies.js +2 -0
  221. package/dist/team-workspace/index.d.ts +6 -0
  222. package/dist/team-workspace/index.js +5 -0
  223. package/dist/team-workspace/launcher.d.ts +17 -0
  224. package/dist/team-workspace/launcher.js +30 -0
  225. package/dist/team-workspace/output.d.ts +15 -0
  226. package/dist/team-workspace/output.js +28 -0
  227. package/dist/team-workspace/terminal.d.ts +9 -0
  228. package/dist/team-workspace/terminal.js +46 -0
  229. package/dist/terminal/client.d.ts +4 -0
  230. package/dist/terminal/client.js +3 -0
  231. package/dist/terminal/commands.js +37 -25
  232. package/dist/terminal/control-commands.js +26 -9
  233. package/dist/terminal/keys.d.ts +12 -0
  234. package/dist/terminal/keys.js +62 -0
  235. package/dist/terminal/output/compact-list.d.ts +1 -0
  236. package/dist/terminal/output/compact-list.js +1 -0
  237. package/dist/terminal/output/human.d.ts +2 -19
  238. package/dist/terminal/output/human.js +6 -6
  239. package/dist/terminal/tree/tree.js +16 -16
  240. package/package.json +10 -8
@@ -10,6 +10,9 @@ export const CONNECTION_TREE = {
10
10
  ["connection usage", "A Connection's usage."],
11
11
  ["connection models", "Models a Connection offers."],
12
12
  ["connection capacity", "A Connection's Session limit."],
13
+ ["connection grant", "Grants."],
14
+ ["connection pool", "Pools."],
15
+ ["connection update-policy", "Vendor CLI update proposals."],
13
16
  ["integration", "Approve vendor executables."],
14
17
  ["integration plan", "Plan approving a vendor executable."],
15
18
  ["integration status", "A vendor integration's status."],
@@ -23,7 +26,7 @@ export const CONNECTION_TREE = {
23
26
  "setup [--max-sessions <1..16>] [--command-id <id>] [--dry-run | --confirm-stdin | --yes]",
24
27
  1,
25
28
  ["connection.system.preview", "connection.system.confirm"],
26
- "Use the installed vendor CLIs as system-default accounts.",
29
+ "Use installed vendor CLIs as system-default accounts.",
27
30
  {
28
31
  example: "maia setup --max-sessions 4",
29
32
  kind: "two-phase",
@@ -59,7 +62,7 @@ export const CONNECTION_TREE = {
59
62
  "login gateway --name <name> --base-url <url> --api-key-stdin [--max-sessions <1..16>] [--command-id <id>]",
60
63
  1,
61
64
  "connection.gateway.create",
62
- "Add an AI gateway Connection with its API key.",
65
+ "Add a gateway Connection with its API key.",
63
66
  { run: [login, "runLoginGateway"] },
64
67
  ],
65
68
  [
@@ -87,20 +90,32 @@ export const CONNECTION_TREE = {
87
90
  { run: [connection, "runConnectionShow"] },
88
91
  ],
89
92
  [
90
- "connection detect",
93
+ "connection detect [--refresh]",
91
94
  1,
92
- "connection.detect",
93
- "Detect the installed vendor CLIs.",
95
+ ["connection.detect", "connection.upkeep.refresh"],
96
+ "Detect installed vendor CLIs and newer versions.",
94
97
  {
95
- example: "maia --json connection detect",
98
+ example: "maia --json connection detect --refresh",
99
+ kind: "composite",
96
100
  run: [connection, "runConnectionDetect"],
97
101
  },
98
102
  ],
103
+ [
104
+ "connection update-policy set <claude-code|codex-cli> <off|notify> [--command-id <id>] [--dry-run | --confirm-stdin | --yes]",
105
+ 1,
106
+ ["connection.upkeep.preview", "connection.upkeep.confirm"],
107
+ "Set a vendor CLI's update policy.",
108
+ {
109
+ example: "maia connection update-policy set codex-cli off",
110
+ kind: "two-phase",
111
+ run: [connection, "runConnectionUpdatePolicySet"],
112
+ },
113
+ ],
99
114
  [
100
115
  "connection login start <connection> [--device-code] [--command-id <id>]",
101
116
  1,
102
117
  "connection.login.start",
103
- "Start a Node-side sign-in for a Connection.",
118
+ "Start a Node-side sign-in.",
104
119
  { run: [connection, "runConnectionLoginStart"] },
105
120
  ],
106
121
  [
@@ -114,7 +129,7 @@ export const CONNECTION_TREE = {
114
129
  "connection models list --connection <connection>",
115
130
  1,
116
131
  "connection.models.list",
117
- "List the models a Connection offers.",
132
+ "List a Connection's models.",
118
133
  { run: [connection, "runConnectionModelsList"] },
119
134
  ],
120
135
  [
@@ -124,6 +139,42 @@ export const CONNECTION_TREE = {
124
139
  "Set a Connection's Session limit.",
125
140
  { run: [connection, "runConnectionCapacitySet"] },
126
141
  ],
142
+ [
143
+ "connection grant list [--connection <connection>] [--project <project-id> | --container <container-id>] [--state <active|revoked>] [--limit <1..100>] [--after <cursor>]",
144
+ 1,
145
+ "connection.grant.list",
146
+ "List grants.",
147
+ { run: [connection, "runConnectionGrantList"] },
148
+ ],
149
+ [
150
+ "connection grant set <connection> (--project <project-id> | --container <container-id> | --confirm-stdin) [--revoke] [--command-id <id>] [--dry-run]",
151
+ 1,
152
+ ["connection.grant.set.preview", "connection.grant.set.confirm"],
153
+ "Grant or revoke a Connection.",
154
+ {
155
+ example: "maia connection grant set claude-a --project maiaos",
156
+ kind: "two-phase",
157
+ run: [connection, "runConnectionGrantSet"],
158
+ },
159
+ ],
160
+ [
161
+ "connection pool list [--project <project-id> | --container <container-id>] [--limit <1..100>] [--after <cursor>]",
162
+ 1,
163
+ "connection.pool.list",
164
+ "List pools.",
165
+ { run: [connection, "runConnectionPoolList"] },
166
+ ],
167
+ [
168
+ "connection pool set (--project <project-id> | --container <container-id> | --confirm-stdin) --mode <off|rotate|single> [<connection>...] [--command-id <id>] [--dry-run]",
169
+ 1,
170
+ ["connection.pool.set.preview", "connection.pool.set.confirm"],
171
+ "Pin, rotate or clear a pool.",
172
+ {
173
+ example: "maia connection pool set --project maiaos --mode rotate claude-a claude-b",
174
+ kind: "two-phase",
175
+ run: [connection, "runConnectionPoolSet"],
176
+ },
177
+ ],
127
178
  [
128
179
  "connection enable <connection> --expected-revision <revision> [--command-id <id>]",
129
180
  1,
@@ -1,6 +1,5 @@
1
- import { formatRows } from "../../command-line/index.js";
1
+ import { cell, formatRows } from "../../command-line/index.js";
2
2
  export const isContainerResult = (result) => result.command.startsWith("container.");
3
- const cell = (value) => value.replaceAll(/[\u0000-\u001F\u007F-\u009F]/gu, " ");
4
3
  const projectCount = (count) => `${String(count)} ${count === 1 ? "Project" : "Projects"}`;
5
4
  const formatIndex = (result) => result.items.length === 0
6
5
  ? "No containers.\n"
@@ -0,0 +1,6 @@
1
+ import { type CockpitClient } from "@maiaos/client-core/cockpit";
2
+ import type * as Context from "effect/Context";
3
+ import type * as Crypto from "effect/Crypto";
4
+ import { type HeldConnection } from "./node-connection.js";
5
+ export declare const makeCockpitClient: (held: HeldConnection, context: Context.Context<Crypto.Crypto>) => CockpitClient;
6
+ //# sourceMappingURL=cockpit-client.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { COCKPIT_CLIENT_METHODS, } from "@maiaos/client-core/cockpit";
2
+ import { classifyClientError } from "@maiaos/sdk";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Exit from "effect/Exit";
5
+ import { newCliIdentifier, retryBriefSaturation, } from "../local-node/index.js";
6
+ import { noConnection } from "./node-connection.js";
7
+ const rejectsCredential = (error) => {
8
+ const { code } = classifyClientError(error, { mutation: false });
9
+ return code === "authentication_failed" || code === "credential_invalid";
10
+ };
11
+ const connectionLost = (error) => {
12
+ const { code, kind } = classifyClientError(error, { mutation: false });
13
+ return ((kind === "offline" && code !== "saturated") ||
14
+ kind === "outcome_unknown" ||
15
+ code === "node_unavailable" ||
16
+ rejectsCredential(error));
17
+ };
18
+ const failedOn = (held, connection) => (error) => Effect.andThen(connectionLost(error) ? held.lose(connection) : Effect.void, Effect.fail(rejectsCredential(error) ? noConnection("node_connecting") : error));
19
+ const operationOf = (client, name) => Reflect.get(client, name);
20
+ export const makeCockpitClient = (held, context) => Object.fromEntries(COCKPIT_CLIENT_METHODS.map((name) => [
21
+ name,
22
+ (parameters, options) => Effect.runPromiseWith(context)(Effect.flatMap(held.current, (connection) => retryBriefSaturation(Effect.flatMap(newCliIdentifier("request"), (messageId) => operationOf(connection.client, name)(parameters, {
23
+ ...options,
24
+ messageId,
25
+ })), options?.deadlineAt).pipe(Effect.onExit((exit) => held.heard(connection, !Exit.hasInterrupts(exit))), Effect.catch(failedOn(held, connection)))), options?.signal === undefined ? {} : { signal: options.signal }),
26
+ ]));
27
+ //# sourceMappingURL=cockpit-client.js.map
@@ -0,0 +1,29 @@
1
+ import { type Cockpit, type CockpitClient, type CockpitState, type NodeCockpitState, type ReadAdmissionService } from "@maiaos/client-core/cockpit";
2
+ import { type NodeEntry, type NodeRegistry, type NodeView } from "@maiaos/client-core/node-registry";
3
+ import type { NodeApiEffectDiscoveryOptions } from "@maiaos/sdk/node/effect";
4
+ import type * as Crypto from "effect/Crypto";
5
+ import * as Effect from "effect/Effect";
6
+ import type * as Scope from "effect/Scope";
7
+ import * as Stream from "effect/Stream";
8
+ import type { CliNodeConnector } from "../local-node/index.js";
9
+ import { type OpenConnection } from "./node-connection.js";
10
+ export declare const READS_IN_FLIGHT = 3;
11
+ export type NodeCockpit = {
12
+ readonly admit: ReadAdmissionService;
13
+ readonly client: CockpitClient;
14
+ readonly cockpit: Cockpit;
15
+ readonly node: NodeEntry;
16
+ };
17
+ export declare const openNodeCockpit: (registry: NodeRegistry, node: NodeEntry, open: OpenConnection) => Effect.Effect<NodeCockpit, never, Crypto.Crypto | Scope.Scope>;
18
+ export type DashboardNodes = {
19
+ readonly local: CliNodeConnector;
20
+ readonly options: NodeApiEffectDiscoveryOptions;
21
+ readonly remote: (name: string, scope: Scope.Scope) => CliNodeConnector;
22
+ };
23
+ export type DashboardCockpits = {
24
+ readonly combined: Stream.Stream<CockpitState>;
25
+ readonly nodes: Stream.Stream<readonly NodeView[]>;
26
+ readonly states: Stream.Stream<readonly NodeCockpitState[]>;
27
+ };
28
+ export declare const dashboardCockpits: (nodes: DashboardNodes) => Effect.Effect<DashboardCockpits, never, Crypto.Crypto | Scope.Scope>;
29
+ //# sourceMappingURL=cockpits.d.ts.map
@@ -0,0 +1,65 @@
1
+ import { CockpitError, combineCockpits, makeCockpit, ReadAdmission, readRemoteNodes, } from "@maiaos/client-core/cockpit";
2
+ import { LOCAL_NODE, makeNodeRegistry, remoteNodeEntry, } from "@maiaos/client-core/node-registry";
3
+ import { pollingNodeChangesLayer } from "@maiaos/client-core/presentation";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Option from "effect/Option";
6
+ import * as Schedule from "effect/Schedule";
7
+ import * as Semaphore from "effect/Semaphore";
8
+ import * as Stream from "effect/Stream";
9
+ import * as SubscriptionRef from "effect/SubscriptionRef";
10
+ import { makeCockpitClient } from "./cockpit-client.js";
11
+ import { holdConnection, } from "./node-connection.js";
12
+ export const READS_IN_FLIGHT = 3;
13
+ const RELOAD_EVERY = "15 seconds";
14
+ const REMOTE_LIST_EVERY = "60 seconds";
15
+ const instanceOf = (held) => held.current.pipe(Effect.map(({ status }) => status.instanceId), Effect.mapError(() => new CockpitError({
16
+ message: "The Node has no live connection.",
17
+ operation: "node.status",
18
+ reason: "offline",
19
+ })));
20
+ export const openNodeCockpit = (registry, node, open) => Effect.gen(function* () {
21
+ const held = yield* holdConnection(open);
22
+ const client = makeCockpitClient(held, yield* Effect.context());
23
+ const admit = (yield* Semaphore.make(READS_IN_FLIGHT)).withPermits(1);
24
+ const cockpit = yield* makeCockpit({
25
+ client,
26
+ instance: instanceOf(held),
27
+ nodeId: node.nodeId,
28
+ registry,
29
+ }).pipe(Effect.provide(pollingNodeChangesLayer(RELOAD_EVERY)), Effect.provideService(ReadAdmission, admit));
30
+ const reload = Effect.provideService(cockpit.reload, ReadAdmission, admit);
31
+ return { admit, client, cockpit: { ...cockpit, reload }, node };
32
+ });
33
+ const mirror = (states, { cockpit, node }) => Effect.forkScoped(Stream.runForEach(cockpit.changes, (state) => SubscriptionRef.update(states, (previous) => new Map(previous).set(node.nodeId, { node, state }))));
34
+ const startRemote = ({ nodes, registry, states }, remote) => {
35
+ const node = remoteNodeEntry(remote);
36
+ const open = (scope) => nodes.remote(remote.name, scope)(nodes.options);
37
+ return remote.state === "ready"
38
+ ? Effect.flatMap(openNodeCockpit(registry, node, open), (opened) => mirror(states, opened))
39
+ : Effect.ignore(registry.recordFailure(node.nodeId, `It is ${remote.state}, not ready.`));
40
+ };
41
+ const runRemotes = (dashboard, remotes) => Effect.scoped(Effect.gen(function* () {
42
+ yield* SubscriptionRef.update(dashboard.states, (previous) => new Map([...previous].filter(([id]) => id === LOCAL_NODE.nodeId)));
43
+ yield* dashboard.registry.setEntries([
44
+ LOCAL_NODE,
45
+ ...remotes.map(remoteNodeEntry),
46
+ ]);
47
+ yield* Effect.forEach(remotes, (remote) => startRemote(dashboard, remote), { concurrency: "unbounded", discard: true });
48
+ return yield* Effect.never;
49
+ }));
50
+ const sameRemotes = (left, right) => JSON.stringify(left) === JSON.stringify(right);
51
+ const followRemotes = (dashboard, local) => Stream.fromEffect(Effect.option(Effect.provideService(readRemoteNodes(local.client), ReadAdmission, local.admit))).pipe(Stream.repeat(Schedule.spaced(REMOTE_LIST_EVERY)), Stream.filter(Option.isSome), Stream.map(({ value }) => value), Stream.changesWith(sameRemotes), Stream.switchMap((remotes) => Stream.fromEffect(runRemotes(dashboard, remotes))), Stream.runDrain);
52
+ export const dashboardCockpits = (nodes) => Effect.gen(function* () {
53
+ const registry = yield* makeNodeRegistry([LOCAL_NODE]);
54
+ const states = yield* SubscriptionRef.make(new Map());
55
+ const local = yield* openNodeCockpit(registry, LOCAL_NODE, () => nodes.local(nodes.options));
56
+ yield* mirror(states, local);
57
+ yield* Effect.forkScoped(followRemotes({ nodes, registry, states }, local));
58
+ const parts = SubscriptionRef.changes(states).pipe(Stream.map((held) => [...held.values()]));
59
+ return {
60
+ combined: parts.pipe(Stream.map(combineCockpits)),
61
+ nodes: registry.watch,
62
+ states: parts,
63
+ };
64
+ });
65
+ //# sourceMappingURL=cockpits.js.map
@@ -0,0 +1,7 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { CliArgumentError, type CommandContext, type CommandEffect } from "../command-line/index.js";
3
+ import { DashboardTerminal, type Screen } from "./terminal.js";
4
+ export declare const showScreen: (screen: Screen, context: CommandContext) => Effect.Effect<number, CliArgumentError, DashboardTerminal>;
5
+ export declare const showDashboard: (tokens: readonly string[], context: CommandContext) => Effect.Effect<number, CliArgumentError, DashboardTerminal>;
6
+ export declare const runDashboard: (tokens: readonly string[], context: CommandContext) => CommandEffect;
7
+ //# sourceMappingURL=dashboard.d.ts.map
@@ -0,0 +1,47 @@
1
+ import process from "node:process";
2
+ import * as Config from "effect/Config";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Option from "effect/Option";
5
+ import { CliArgumentError, reportError, requireNoArguments, writeSuccess, } from "../command-line/index.js";
6
+ import { frameLines, plainLines } from "./frame.js";
7
+ import { loadPiTui } from "./pi-tui.js";
8
+ import { DashboardTerminal, terminalLayer, } from "./terminal.js";
9
+ const DEFAULT_PROFILE = "default";
10
+ const profileOf = ({ profile }) => profile ?? DEFAULT_PROFILE;
11
+ const screenOf = (context) => ({
12
+ quitKeys: ["q", "ctrl+c"],
13
+ render: (size) => frameLines(profileOf(context), size),
14
+ });
15
+ const refuseSession = (context) => reportError({
16
+ code: "role_denied",
17
+ message: "The dashboard is for a person at a terminal, not a Session.",
18
+ retryable: false,
19
+ }, context);
20
+ const printPlain = (context) => {
21
+ const profile = profileOf(context);
22
+ writeSuccess({ command: "dashboard", profile }, context, () => `${plainLines(profile).join("\n")}\n`);
23
+ return 0;
24
+ };
25
+ const reportFailure = (error, context) => error.reason === "no-terminal"
26
+ ? Effect.fail(new CliArgumentError("The dashboard needs a terminal on standard input and output; pass --plain for plain text."))
27
+ : Effect.succeed(reportError({
28
+ code: "internal_error",
29
+ message: error.reason === "missing"
30
+ ? "The dashboard cannot load its terminal library; next: reinstall Maia."
31
+ : "The dashboard failed while drawing; the terminal was restored.",
32
+ retryable: false,
33
+ }, context));
34
+ export const showScreen = (screen, context) => DashboardTerminal.use((terminal) => terminal.run(screen)).pipe(Effect.catchTag("TerminalFailure", (error) => reportFailure(error, context)));
35
+ export const showDashboard = (tokens, context) => Effect.gen(function* () {
36
+ const credential = yield* Effect.orDie(Config.option(Config.String("MAIA_SESSION_CREDENTIAL")));
37
+ if (Option.isSome(credential))
38
+ return refuseSession(context);
39
+ const plain = tokens[0] === "--plain";
40
+ requireNoArguments(plain ? tokens.slice(1) : tokens, "dashboard");
41
+ return plain
42
+ ? printPlain(context)
43
+ : yield* showScreen(screenOf(context), context);
44
+ });
45
+ const processTerminal = terminalLayer(process, loadPiTui());
46
+ export const runDashboard = (tokens, context) => showDashboard(tokens, context).pipe(Effect.provide(processTerminal));
47
+ //# sourceMappingURL=dashboard.js.map
@@ -0,0 +1,15 @@
1
+ export type Width = (text: string) => number;
2
+ export type Span = readonly [text: string, style?: string];
3
+ export type Draw = {
4
+ readonly clip: (text: string, size: number) => string;
5
+ readonly column: (text: string, size: number) => string;
6
+ readonly columns: number;
7
+ readonly line: (spans: readonly Span[]) => string;
8
+ readonly width: Width;
9
+ };
10
+ export declare const makeDraw: (options: {
11
+ readonly color: boolean;
12
+ readonly columns: number;
13
+ readonly width: Width;
14
+ }) => Draw;
15
+ //# sourceMappingURL=draw.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { cell } from "../command-line/index.js";
2
+ const paint = ([text, style]) => style === undefined ? text : `\u001B[${style}m${text}\u001B[0m`;
3
+ const clipWith = (width) => (value, size) => {
4
+ const text = cell(value);
5
+ if (width(text) <= size)
6
+ return text;
7
+ const parts = Array.from(new Intl.Segmenter().segment(text), (part) => part.segment);
8
+ const kept = parts.findIndex((_, index) => width(`${parts.slice(0, index + 1).join("")}~`) > size);
9
+ return size < 1 ? "" : `${parts.slice(0, Math.max(kept, 0)).join("")}~`;
10
+ };
11
+ export const makeDraw = (options) => {
12
+ const { color, columns, width } = options;
13
+ const clip = clipWith(width);
14
+ return {
15
+ clip,
16
+ column: (text, size) => {
17
+ const shown = clip(text, size - 1);
18
+ return `${shown}${" ".repeat(Math.max(0, size - width(shown)))}`;
19
+ },
20
+ columns,
21
+ line: (spans) => {
22
+ const plain = spans.map(([text]) => text).join("");
23
+ if (width(plain) > columns)
24
+ return clip(plain, columns);
25
+ return color ? spans.map(paint).join("") : plain;
26
+ },
27
+ width,
28
+ };
29
+ };
30
+ //# sourceMappingURL=draw.js.map
@@ -0,0 +1,4 @@
1
+ import type { ScreenSize } from "./terminal.js";
2
+ export declare const plainLines: (profile: string) => readonly string[];
3
+ export declare const frameLines: (profile: string, size: ScreenSize) => readonly string[];
4
+ //# sourceMappingURL=frame.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { cell } from "../command-line/index.js";
2
+ import { tooSmall } from "./tree.js";
3
+ const statusLine = (profile) => `Maia dashboard | profile: ${cell(profile)}`;
4
+ const TREE_NOTICE = "The Tree arrives in a later version.";
5
+ export const plainLines = (profile) => [
6
+ statusLine(profile),
7
+ TREE_NOTICE,
8
+ ];
9
+ export const frameLines = (profile, size) => {
10
+ const small = tooSmall(size);
11
+ return small === undefined
12
+ ? [`${statusLine(profile)} | q quits`, TREE_NOTICE]
13
+ : [small];
14
+ };
15
+ //# sourceMappingURL=frame.js.map
@@ -0,0 +1,2 @@
1
+ export { runDashboard } from "./dashboard.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { runDashboard } from "./dashboard.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ export type ModeLedger = readonly string[];
2
+ export declare const NO_MODES: ModeLedger;
3
+ export declare const observe: (ledger: ModeLedger, chunk: string) => ModeLedger;
4
+ export declare const resetBytes: (ledger: ModeLedger) => string;
5
+ //# sourceMappingURL=modes.d.ts.map
@@ -0,0 +1,16 @@
1
+ const MODES = [
2
+ ["\u001B[?1049h", "\u001B[?1049l"],
3
+ ["\u001B[?7l", "\u001B[?7h"],
4
+ ["\u001B[?25l", "\u001B[?25h"],
5
+ ["\u001B[?2004h", "\u001B[?2004l"],
6
+ ["\u001B[>7u", "\u001B[<u"],
7
+ ["\u001B[>4;2m", "\u001B[>4;0m"],
8
+ ];
9
+ export const NO_MODES = [];
10
+ export const observe = (ledger, chunk) => MODES.filter(([on, off]) => {
11
+ const turnedOn = chunk.lastIndexOf(on);
12
+ const turnedOff = chunk.lastIndexOf(off);
13
+ return turnedOn === turnedOff ? ledger.includes(off) : turnedOn > turnedOff;
14
+ }).map(([, off]) => off);
15
+ export const resetBytes = (ledger) => ledger.toReversed().join("");
16
+ //# sourceMappingURL=modes.js.map
@@ -0,0 +1,15 @@
1
+ import { MaiaClientError } from "@maiaos/sdk";
2
+ import type * as Crypto from "effect/Crypto";
3
+ import * as Effect from "effect/Effect";
4
+ import type * as Scope from "effect/Scope";
5
+ import type { CliNodeConnection } from "../local-node/index.js";
6
+ export declare const UNANSWERED_BEFORE_LOST = 3;
7
+ export type OpenConnection = (scope: Scope.Scope) => Effect.Effect<CliNodeConnection, unknown, Crypto.Crypto>;
8
+ export declare const noConnection: (reason: "node_connecting" | "node_unreachable", detail?: string) => MaiaClientError;
9
+ export type HeldConnection = {
10
+ readonly current: Effect.Effect<CliNodeConnection, MaiaClientError>;
11
+ readonly heard: (connection: CliNodeConnection, answered: boolean) => Effect.Effect<void>;
12
+ readonly lose: (connection: CliNodeConnection) => Effect.Effect<void>;
13
+ };
14
+ export declare const holdConnection: (open: OpenConnection) => Effect.Effect<HeldConnection, never, Crypto.Crypto | Scope.Scope>;
15
+ //# sourceMappingURL=node-connection.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { MaiaClientError } from "@maiaos/sdk";
2
+ import * as Duration from "effect/Duration";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Latch from "effect/Latch";
5
+ import * as Ref from "effect/Ref";
6
+ import * as Schedule from "effect/Schedule";
7
+ const RECONNECT_BACKOFF = Schedule.min([
8
+ Schedule.exponential(Duration.seconds(2)),
9
+ Schedule.spaced(Duration.seconds(30)),
10
+ ]);
11
+ export const UNANSWERED_BEFORE_LOST = 3;
12
+ export const noConnection = (reason, detail) => new MaiaClientError("transport_failure", "The Node has no live connection; nothing was sent.", { cause: { reason, ...(detail === undefined ? {} : { detail }) } });
13
+ const ifHeld = (state) => (connection, change) => Effect.asVoid(Effect.flatten(Ref.modify(state, (held) => "connection" in held && held.connection === connection
14
+ ? change(held)
15
+ : [Effect.void, held])));
16
+ const view = (state) => {
17
+ const onHeld = ifHeld(state);
18
+ return {
19
+ current: Effect.flatMap(Ref.get(state), (held) => "connection" in held
20
+ ? Effect.succeed(held.connection)
21
+ : Effect.fail(held.failure)),
22
+ heard: (connection, answered) => onHeld(connection, (live) => {
23
+ const unanswered = answered ? 0 : live.unanswered + 1;
24
+ return [
25
+ unanswered >= UNANSWERED_BEFORE_LOST ? live.lost.open : Effect.void,
26
+ { ...live, unanswered },
27
+ ];
28
+ }),
29
+ lose: (connection) => onHeld(connection, (live) => [live.lost.open, live]),
30
+ };
31
+ };
32
+ const generation = (open, state, attempted) => Effect.scoped(Effect.gen(function* () {
33
+ const connection = yield* Effect.flatMap(Effect.scope, open).pipe(Effect.tapError((error) => Ref.set(state, {
34
+ failure: noConnection("node_unreachable", error instanceof MaiaClientError ? error.message : undefined),
35
+ }).pipe(Effect.andThen(attempted.open))));
36
+ const lost = yield* Latch.make();
37
+ yield* Ref.set(state, { connection, lost, unanswered: 0 });
38
+ yield* attempted.open;
39
+ yield* lost.await;
40
+ yield* Ref.set(state, { failure: noConnection("node_connecting") });
41
+ }));
42
+ export const holdConnection = (open) => Effect.gen(function* () {
43
+ const state = yield* Ref.make({
44
+ failure: noConnection("node_connecting"),
45
+ });
46
+ const attempted = yield* Latch.make();
47
+ yield* Effect.forkScoped(Effect.forever(generation(open, state, attempted).pipe(Effect.retry(RECONNECT_BACKOFF))));
48
+ yield* attempted.await;
49
+ return view(state);
50
+ });
51
+ //# sourceMappingURL=node-connection.js.map
@@ -0,0 +1,6 @@
1
+ import type * as PiTui from "@earendil-works/pi-tui";
2
+ import { type LoadSurface } from "./terminal.js";
3
+ type Library = Pick<typeof PiTui, "isKeyRelease" | "isKeyRepeat" | "matchesKey" | "ProcessTerminal" | "TuiAltScreen">;
4
+ export declare const loadPiTui: (importLibrary?: () => Promise<Library>) => LoadSurface;
5
+ export {};
6
+ //# sourceMappingURL=pi-tui.d.ts.map
@@ -0,0 +1,35 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { constVoid } from "effect/Function";
3
+ import { TerminalFailure } from "./terminal.js";
4
+ const NO_LOG_DIRECTORY = undefined;
5
+ const surfaceOf = (library) => {
6
+ const terminal = new library.ProcessTerminal();
7
+ const tui = new library.TuiAltScreen(terminal, false, NO_LOG_DIRECTORY, {
8
+ mouse: false,
9
+ });
10
+ return {
11
+ drain: () => terminal.drainInput(),
12
+ matches: (input, key) => library.matchesKey(input, key) &&
13
+ !library.isKeyRelease(input) &&
14
+ !library.isKeyRepeat(input),
15
+ show: (paint, onInput) => {
16
+ tui.addChild({ invalidate: constVoid, render: paint });
17
+ tui.addInputListener((input) => {
18
+ onInput(input);
19
+ return { consume: true };
20
+ });
21
+ },
22
+ size: () => ({ columns: terminal.columns, rows: terminal.rows }),
23
+ start: () => {
24
+ tui.start();
25
+ },
26
+ stop: () => {
27
+ tui.stop({ preserveScreen: true });
28
+ },
29
+ };
30
+ };
31
+ export const loadPiTui = (importLibrary = () => import("@earendil-works/pi-tui")) => Effect.tryPromise({
32
+ catch: (cause) => new TerminalFailure({ cause, reason: "missing" }),
33
+ try: importLibrary,
34
+ }).pipe(Effect.map(surfaceOf));
35
+ //# sourceMappingURL=pi-tui.js.map
@@ -0,0 +1,4 @@
1
+ import type { Draw, Span } from "./draw.js";
2
+ import { type Row, type TreeInput } from "./tree-model.js";
3
+ export declare const statusBar: (input: TreeInput, rows: readonly Row[], draw: Draw) => readonly Span[];
4
+ //# sourceMappingURL=status-bar.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { MAX_ATTENTION_ITEMS } from "@maiaos/client-core/cockpit";
2
+ import { ALARM, attentionStyle, WARNING, } from "./tree-model.js";
3
+ const LIMIT = { label: 12, profile: 16, reason: 16 };
4
+ const isDown = ({ health }) => health === "connecting" || health === "unreachable";
5
+ const reasonOf = (node) => {
6
+ if (node.health === "connecting")
7
+ return node.health;
8
+ if (node.health === "unreachable")
9
+ return node.lastFailure ?? node.health;
10
+ return [
11
+ node.health === "stale" || node.stale ? "stale" : "",
12
+ node.partial ? "partial" : "",
13
+ ]
14
+ .filter((reason) => reason !== "")
15
+ .join(",");
16
+ };
17
+ const namesOf = (nodes, draw) => nodes
18
+ .filter((node) => reasonOf(node) !== "")
19
+ .toSorted((left, right) => Number(isDown(right)) - Number(isDown(left)))
20
+ .map((node) => `${draw.clip(node.hostLabel, LIMIT.label)}:${draw.clip(reasonOf(node), LIMIT.reason)}`);
21
+ const listed = (names, room, draw) => {
22
+ const [first, ...rest] = names;
23
+ if (first === undefined)
24
+ return "";
25
+ const used = 1 + draw.width(first);
26
+ const reserve = rest.length > 0 ? ` +${String(rest.length)}`.length : 0;
27
+ return used + reserve > room
28
+ ? ` +${String(names.length)}`
29
+ : ` ${first}${listed(rest, room - used, draw)}`;
30
+ };
31
+ const countSpans = ({ nodes, state }, running) => {
32
+ const low = state.partial ||
33
+ state.stale ||
34
+ state.index.coverage === "truncated" ||
35
+ nodes.some(({ health }) => health !== "ready");
36
+ const lost = low || state.attention.length >= MAX_ATTENTION_ITEMS;
37
+ const styled = (style) => state.attention.filter(({ reason }) => attentionStyle(reason) === style)
38
+ .length;
39
+ return [
40
+ ["ALM", styled(ALARM), ALARM, lost],
41
+ ["WRN", styled(WARNING), WARNING, lost],
42
+ ["RUN", running, undefined, low],
43
+ ].map(([label, total, style, plus]) => [
44
+ ` ${label} ${String(total)}${plus ? "+" : ""}`,
45
+ total > 0 ? style : undefined,
46
+ ]);
47
+ };
48
+ export const statusBar = (input, rows, draw) => {
49
+ const { nodes, profile } = input;
50
+ const running = rows.filter(({ children, code }) => children.length === 0 && code === "RUN").length;
51
+ const up = nodes.filter(({ health }) => health === "ready").length;
52
+ const head = [
53
+ [draw.clip(profile, LIMIT.profile)],
54
+ ...countSpans(input, running),
55
+ [` NODE ${String(up)}/${String(nodes.length)}`],
56
+ ];
57
+ const room = draw.columns - draw.width(head.map(([text]) => text).join(""));
58
+ return [...head, [listed(namesOf(nodes, draw), room, draw)]];
59
+ };
60
+ //# sourceMappingURL=status-bar.js.map