@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
@@ -10,6 +10,7 @@ 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 update-policy", "Whether Maia proposes vendor CLI updates."],
13
14
  ["integration", "Approve vendor executables."],
14
15
  ["integration plan", "Plan approving a vendor executable."],
15
16
  ["integration status", "A vendor integration's status."],
@@ -87,15 +88,27 @@ export const CONNECTION_TREE = {
87
88
  { run: [connection, "runConnectionShow"] },
88
89
  ],
89
90
  [
90
- "connection detect",
91
+ "connection detect [--refresh]",
91
92
  1,
92
- "connection.detect",
93
- "Detect the installed vendor CLIs.",
93
+ ["connection.detect", "connection.upkeep.refresh"],
94
+ "Detect the installed vendor CLIs and whether newer versions exist.",
94
95
  {
95
- example: "maia --json connection detect",
96
+ example: "maia --json connection detect --refresh",
97
+ kind: "composite",
96
98
  run: [connection, "runConnectionDetect"],
97
99
  },
98
100
  ],
101
+ [
102
+ "connection update-policy set <claude-code|codex-cli> <off|notify> [--command-id <id>] [--dry-run | --confirm-stdin | --yes]",
103
+ 1,
104
+ ["connection.upkeep.preview", "connection.upkeep.confirm"],
105
+ "Choose whether Maia proposes updates for a vendor CLI.",
106
+ {
107
+ example: "maia connection update-policy set codex-cli off",
108
+ kind: "two-phase",
109
+ run: [connection, "runConnectionUpdatePolicySet"],
110
+ },
111
+ ],
99
112
  [
100
113
  "connection login start <connection> [--device-code] [--command-id <id>]",
101
114
  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
@@ -0,0 +1,53 @@
1
+ import type { KeyId } from "@earendil-works/pi-tui";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ export type ScreenSize = {
6
+ readonly columns: number;
7
+ readonly rows: number;
8
+ };
9
+ export type Screen = {
10
+ readonly quitKeys: readonly KeyId[];
11
+ readonly render: (size: ScreenSize) => readonly string[];
12
+ };
13
+ export type Surface = {
14
+ readonly drain: () => Promise<void>;
15
+ readonly matches: (input: string, key: KeyId) => boolean;
16
+ readonly show: (paint: () => string[], onInput: (input: string) => void) => void;
17
+ readonly size: () => ScreenSize;
18
+ readonly start: () => void;
19
+ readonly stop: () => void;
20
+ };
21
+ type Write = (chunk: string, callback?: () => void) => unknown;
22
+ export type TerminalHost = {
23
+ readonly env: Readonly<NodeJS.ProcessEnv>;
24
+ readonly kill: (pid: number, signal: "SIGTSTP") => unknown;
25
+ readonly off: (event: string, listener: () => void) => unknown;
26
+ readonly on: (event: string, listener: () => void) => unknown;
27
+ readonly platform: NodeJS.Platform;
28
+ readonly stdin: {
29
+ readonly isTTY?: boolean;
30
+ readonly setRawMode?: (mode: boolean) => unknown;
31
+ };
32
+ readonly stdout: {
33
+ readonly isTTY?: boolean;
34
+ write: Write;
35
+ };
36
+ };
37
+ declare const TerminalFailure_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]; }>) => import("effect/Cause").YieldableError & {
38
+ readonly _tag: "TerminalFailure";
39
+ } & Readonly<A>;
40
+ export declare class TerminalFailure extends TerminalFailure_base<{
41
+ readonly cause?: unknown;
42
+ readonly reason: "callback" | "missing" | "no-terminal";
43
+ }> {
44
+ }
45
+ declare const DashboardTerminal_base: Context.ServiceClass<DashboardTerminal, "maia/cli/DashboardTerminal", {
46
+ readonly run: (screen: Screen) => Effect.Effect<number, TerminalFailure>;
47
+ }>;
48
+ export declare class DashboardTerminal extends DashboardTerminal_base {
49
+ }
50
+ export type LoadSurface = Effect.Effect<Surface, TerminalFailure>;
51
+ export declare const terminalLayer: (host: TerminalHost, load: LoadSurface) => Layer.Layer<DashboardTerminal, never, never>;
52
+ export {};
53
+ //# sourceMappingURL=terminal.d.ts.map