@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
@@ -0,0 +1,165 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Data from "effect/Data";
3
+ import * as Deferred from "effect/Deferred";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import { NO_MODES, observe, resetBytes } from "./modes.js";
7
+ const EXIT_SIGNALLED = 130;
8
+ const SHUTDOWN_SIGNALS = ["SIGHUP", "SIGINT", "SIGTERM"];
9
+ const SUSPEND_KEY = "ctrl+z";
10
+ const PROCESS_GROUP = 0;
11
+ const WITHOUT_JOB_CONTROL = "win32";
12
+ const TERMINAL_PANE = "MAIA_TERMINAL_PANE";
13
+ const TERMINAL_GONE = "EIO";
14
+ export class TerminalFailure extends Data.TaggedError("TerminalFailure") {
15
+ }
16
+ export class DashboardTerminal extends Context.Service()("maia/cli/DashboardTerminal") {
17
+ }
18
+ const ignoringGoneTerminal = (action) => {
19
+ try {
20
+ action();
21
+ }
22
+ catch (error) {
23
+ const code = error instanceof Error ? Reflect.get(error, "code") : undefined;
24
+ if (code !== TERMINAL_GONE)
25
+ throw error;
26
+ }
27
+ };
28
+ const restore = (session) => {
29
+ const bytes = resetBytes(session.ledger);
30
+ session.ledger = NO_MODES;
31
+ if (bytes !== "")
32
+ session.host.stdout.write(bytes);
33
+ ignoringGoneTerminal(() => {
34
+ session.host.stdin.setRawMode?.(false);
35
+ });
36
+ };
37
+ const leave = (session) => {
38
+ try {
39
+ ignoringGoneTerminal(session.surface.stop);
40
+ }
41
+ finally {
42
+ restore(session);
43
+ }
44
+ };
45
+ const listen = (session) => {
46
+ const { stdout } = session.host;
47
+ const original = stdout.write;
48
+ stdout.write = (chunk, callback) => {
49
+ session.ledger = observe(session.ledger, chunk);
50
+ return original.call(stdout, chunk, callback);
51
+ };
52
+ return () => {
53
+ stdout.write = original;
54
+ };
55
+ };
56
+ const end = (session, code) => {
57
+ Deferred.doneUnsafe(session.outcome, Effect.succeed(code));
58
+ };
59
+ const attempt = (session, fallback, action) => {
60
+ try {
61
+ return action();
62
+ }
63
+ catch (error) {
64
+ Deferred.doneUnsafe(session.outcome, Effect.fail(new TerminalFailure({ cause: error, reason: "callback" })));
65
+ return fallback;
66
+ }
67
+ };
68
+ const suspend = (session) => {
69
+ const { host, onStop, surface } = session;
70
+ if (host.platform === WITHOUT_JOB_CONTROL || host.env[TERMINAL_PANE] === "1")
71
+ return;
72
+ attempt(session, undefined, () => {
73
+ leave(session);
74
+ host.off("SIGTSTP", onStop);
75
+ host.kill(PROCESS_GROUP, "SIGTSTP");
76
+ host.on("SIGTSTP", onStop);
77
+ surface.start();
78
+ });
79
+ };
80
+ const present = (session) => {
81
+ const { screen, surface } = session;
82
+ surface.show(() => attempt(session, [], () => [...screen.render(surface.size())]), (input) => {
83
+ attempt(session, undefined, () => {
84
+ if (surface.matches(input, SUSPEND_KEY))
85
+ suspend(session);
86
+ else if (screen.quitKeys.some((key) => surface.matches(input, key)))
87
+ end(session, 0);
88
+ });
89
+ });
90
+ attempt(session, undefined, surface.start);
91
+ };
92
+ const onExit = (session) => () => {
93
+ restore(session);
94
+ };
95
+ const take = (session) => {
96
+ const unlisten = listen(session);
97
+ const shutdown = () => {
98
+ end(session, EXIT_SIGNALLED);
99
+ };
100
+ const handlers = [
101
+ ...SHUTDOWN_SIGNALS.map((signal) => [signal, shutdown]),
102
+ ["SIGTSTP", session.onStop],
103
+ ["exit", onExit(session)],
104
+ ];
105
+ handlers.forEach(([event, handler]) => session.host.on(event, handler));
106
+ return () => {
107
+ unlisten();
108
+ handlers.forEach(([event, handler]) => session.host.off(event, handler));
109
+ };
110
+ };
111
+ const keep = (session, cause) => {
112
+ session.failure ??= { cause };
113
+ };
114
+ const release = (session, detach) => {
115
+ const drain = Effect.tryPromise({
116
+ catch: (error) => error,
117
+ try: () => session.surface.drain(),
118
+ }).pipe(Effect.catch((error) => Effect.sync(() => {
119
+ keep(session, error);
120
+ })));
121
+ const finish = Effect.sync(() => {
122
+ try {
123
+ leave(session);
124
+ }
125
+ catch (error) {
126
+ keep(session, error);
127
+ }
128
+ finally {
129
+ detach();
130
+ }
131
+ });
132
+ return Effect.ensuring(drain, finish);
133
+ };
134
+ const hold = (session) => Effect.gen(function* () {
135
+ yield* Effect.acquireRelease(Effect.sync(() => take(session)), (detach) => release(session, detach));
136
+ yield* Effect.sync(() => {
137
+ present(session);
138
+ });
139
+ return yield* Deferred.await(session.outcome);
140
+ }).pipe(Effect.scoped);
141
+ const run = (host, load, screen) => Effect.gen(function* () {
142
+ if (host.stdin.isTTY !== true || host.stdout.isTTY !== true)
143
+ return yield* new TerminalFailure({ reason: "no-terminal" });
144
+ const session = {
145
+ host,
146
+ ledger: NO_MODES,
147
+ onStop: () => {
148
+ suspend(session);
149
+ },
150
+ outcome: yield* Deferred.make(),
151
+ screen,
152
+ surface: yield* load,
153
+ };
154
+ const code = yield* hold(session);
155
+ return session.failure === undefined
156
+ ? code
157
+ : yield* new TerminalFailure({
158
+ cause: session.failure.cause,
159
+ reason: "callback",
160
+ });
161
+ });
162
+ export const terminalLayer = (host, load) => Layer.succeed(DashboardTerminal, {
163
+ run: (screen) => run(host, load, screen),
164
+ });
165
+ //# sourceMappingURL=terminal.js.map
@@ -0,0 +1,28 @@
1
+ import { type AttentionReason, type CockpitState } from "@maiaos/client-core/cockpit";
2
+ import type { NodeView } from "@maiaos/client-core/node-registry";
3
+ import type { Routine } from "@maiaos/sdk";
4
+ export type TreeNode = NodeView & Pick<CockpitState, "partial" | "stale">;
5
+ export type TreeInput = {
6
+ readonly accounts?: ReadonlyMap<string, string>;
7
+ readonly nodes: readonly TreeNode[];
8
+ readonly now: number;
9
+ readonly profile: string;
10
+ readonly routines?: readonly Routine[];
11
+ readonly state: CockpitState;
12
+ };
13
+ export type Row = {
14
+ readonly at: string;
15
+ readonly cells: readonly string[];
16
+ readonly children: readonly Row[];
17
+ readonly code: string;
18
+ readonly depth: number;
19
+ readonly id: string;
20
+ readonly marker: boolean;
21
+ readonly name: string;
22
+ };
23
+ export declare const ALARM = "1;31";
24
+ export declare const WARNING = "33";
25
+ export declare const codeStyle: (code: string) => string | undefined;
26
+ export declare const attentionStyle: (reason: AttentionReason) => string | undefined;
27
+ export declare const treeRows: (input: TreeInput) => readonly Row[];
28
+ //# sourceMappingURL=tree-model.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { isWorking, runtimeStatus, } from "@maiaos/client-core/cockpit";
2
+ export const ALARM = "1;31";
3
+ export const WARNING = "33";
4
+ const CODES = [..."APPR ASK FAIL STAL DONE RUN IDLE HOLD OFF".split(" "), ""];
5
+ const ATTENTION_CODES = new Map([
6
+ ["approval_pending", "APPR"],
7
+ ["failed", "FAIL"],
8
+ ["question", "ASK"],
9
+ ["settled_unreviewed", "DONE"],
10
+ ["stalled", "STAL"],
11
+ ["turn_failed", "FAIL"],
12
+ ]);
13
+ const ROUTINE_CODES = {
14
+ active: "IDLE",
15
+ disabled: "OFF",
16
+ paused: "HOLD",
17
+ };
18
+ export const codeStyle = (code) => [ALARM, ALARM, WARNING, WARNING][CODES.indexOf(code)];
19
+ export const attentionStyle = (reason) => codeStyle(ATTENTION_CODES.get(reason) ?? "");
20
+ const order = (left, right) => Number(left > right) - Number(left < right);
21
+ const byUrgency = (left, right) => CODES.indexOf(left.code) - CODES.indexOf(right.code) ||
22
+ order(right.at, left.at) ||
23
+ order(left.id, right.id);
24
+ const group = (head, ...blocks) => {
25
+ const children = blocks.flatMap((block) => block.toSorted(byUrgency));
26
+ const { at, code, marker } = children.toSorted(byUrgency)[0] ?? {
27
+ at: "",
28
+ code: "",
29
+ marker: false,
30
+ };
31
+ return { ...head, at, cells: [], children, code, marker };
32
+ };
33
+ const marked = (lookup, holder) => holder === undefined || !lookup.fresh.has(holder.nodeId);
34
+ const sessionCode = ({ state }, session) => {
35
+ const reason = state.index.attention.get(session.id);
36
+ if (reason !== undefined)
37
+ return ATTENTION_CODES.get(reason) ?? "";
38
+ if (session.state === "waiting-approval")
39
+ return "APPR";
40
+ if (session.state === "failed")
41
+ return "FAIL";
42
+ const runtime = runtimeStatus(state.runtimes.get(session.id));
43
+ return isWorking({ ...runtime, state: session.state }) ? "RUN" : "IDLE";
44
+ };
45
+ const sessionRow = (lookup, session) => {
46
+ const { executor, id, title, updatedAt } = session;
47
+ const holder = lookup.state.index.sessionNodes?.get(id);
48
+ const [harness = "", model = "", effort = "", account = ""] = executor === undefined
49
+ ? []
50
+ : [
51
+ executor.kind.split("-")[0],
52
+ executor.model ?? "default",
53
+ executor.effort ?? "default",
54
+ lookup.accounts?.get(executor.connectionId) ?? executor.connectionId,
55
+ ];
56
+ return {
57
+ at: updatedAt,
58
+ cells: [harness, model, effort, holder?.hostLabel ?? "", account],
59
+ children: [],
60
+ code: sessionCode(lookup, session),
61
+ depth: 2,
62
+ id,
63
+ marker: marked(lookup, holder),
64
+ name: title ?? id,
65
+ };
66
+ };
67
+ const routineRow = (lookup, routine) => {
68
+ const { id, name, state, template, updatedAt } = routine;
69
+ const holder = lookup.state.index.projectNodes?.get(template.projectId);
70
+ return {
71
+ at: updatedAt,
72
+ cells: ["", "", "", holder?.hostLabel ?? ""],
73
+ children: [],
74
+ code: ROUTINE_CODES[state],
75
+ depth: 2,
76
+ id,
77
+ marker: marked(lookup, holder),
78
+ name,
79
+ };
80
+ };
81
+ const flatten = (row) => [
82
+ row,
83
+ ...row.children.flatMap(flatten),
84
+ ];
85
+ export const treeRows = (input) => {
86
+ const { nodes, routines = [], state } = input;
87
+ const fresh = nodes.filter(({ health, stale }) => health === "ready" && !stale);
88
+ const lookup = { ...input, fresh: new Set(fresh.map((node) => node.nodeId)) };
89
+ const sessionsOf = Map.groupBy(state.index.sessions.values(), (s) => s.projectId);
90
+ const routinesOf = Map.groupBy(routines, (r) => r.template.projectId);
91
+ const projectRow = (id) => group({ depth: 1, id, name: state.index.projects.get(id)?.name ?? id }, (routinesOf.get(id) ?? []).map((r) => routineRow(lookup, r)), (sessionsOf.get(id) ?? []).map((s) => sessionRow(lookup, s)));
92
+ return [...state.index.workspaces.values()]
93
+ .map(({ id, name, projectIds }) => group({ depth: 0, id, name }, projectIds.map(projectRow)))
94
+ .toSorted(byUrgency)
95
+ .flatMap(flatten);
96
+ };
97
+ //# sourceMappingURL=tree-model.js.map
@@ -0,0 +1,10 @@
1
+ import { type Width } from "./draw.js";
2
+ import type { ScreenSize } from "./terminal.js";
3
+ import { type TreeInput } from "./tree-model.js";
4
+ export type TreeOptions = {
5
+ readonly color: boolean;
6
+ readonly width: Width;
7
+ };
8
+ export declare const tooSmall: ({ columns, rows }: ScreenSize) => string | undefined;
9
+ export declare const renderTree: (input: TreeInput, size: ScreenSize, { color, width }: TreeOptions) => readonly string[];
10
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1,76 @@
1
+ import { makeDraw } from "./draw.js";
2
+ import { statusBar } from "./status-bar.js";
3
+ import { codeStyle, treeRows } from "./tree-model.js";
4
+ const MINIMUM = { columns: 80, rows: 24 };
5
+ const COLUMNS = [
6
+ ["HARN", 7],
7
+ ["MODEL", 16],
8
+ ["EFF", 8],
9
+ ["NODE", 6],
10
+ ["ACCT", 9],
11
+ ];
12
+ const GRID_WIDTH = 55;
13
+ const AGE_COLUMNS = 3;
14
+ const BAND_ROWS = 2;
15
+ export const tooSmall = ({ columns, rows }) => columns < MINIMUM.columns || rows < MINIMUM.rows
16
+ ? `Maia dashboard needs ${String(MINIMUM.columns)}x${String(MINIMUM.rows)} or more; this one is ${String(columns)}x${String(rows)}.`
17
+ : undefined;
18
+ const ageOf = (at, now) => {
19
+ const minutes = Math.max(0, Math.floor((now - Date.parse(at)) / 60_000));
20
+ if (Number.isNaN(minutes))
21
+ return "-";
22
+ const hours = Math.floor(minutes / 60);
23
+ const days = Math.floor(hours / 24);
24
+ if (minutes < 1)
25
+ return "<1m";
26
+ if (hours < 1)
27
+ return `${String(minutes)}m`;
28
+ if (days < 1)
29
+ return `${String(hours)}h`;
30
+ if (days < 100)
31
+ return `${String(days)}d`;
32
+ if (days < 365)
33
+ return `${String(Math.floor(days / 7))}w`;
34
+ return `${String(Math.min(99, Math.floor(days / 365)))}y`;
35
+ };
36
+ const grid = (draw, texts) => COLUMNS.map(([, size], index) => draw.column(texts[index] ?? "", size)).join("");
37
+ const rowLine = (draw, now, row) => draw.line([
38
+ [
39
+ draw.column(`${" ".repeat(row.depth)}${row.name}`, draw.columns - GRID_WIDTH),
40
+ ],
41
+ [row.code.padEnd(4), codeStyle(row.code)],
42
+ [`${row.marker ? "?" : " "} `],
43
+ [grid(draw, row.cells)],
44
+ [ageOf(row.at, now).padStart(AGE_COLUMNS)],
45
+ ]);
46
+ const headerLine = (draw) => draw.line([
47
+ [draw.column("NAME", draw.columns - GRID_WIDTH)],
48
+ ["STATE "],
49
+ [
50
+ grid(draw, COLUMNS.map(([label]) => label)),
51
+ ],
52
+ ["AGE".padStart(AGE_COLUMNS)],
53
+ ]);
54
+ export const renderTree = (input, size, { color, width }) => {
55
+ const draw = makeDraw({ color, columns: size.columns, width });
56
+ const small = tooSmall(size);
57
+ if (small !== undefined)
58
+ return [draw.line([[small]])];
59
+ const rows = treeRows(input);
60
+ const room = size.rows - BAND_ROWS;
61
+ const shown = rows.slice(0, rows.length > room ? room - 1 : room);
62
+ const empty = input.state.partial
63
+ ? "No Workspace read yet."
64
+ : "No Workspace yet. Add one: maia container create --input-stdin --dry-run";
65
+ return [
66
+ draw.line(statusBar(input, rows, draw)),
67
+ headerLine(draw),
68
+ ...(rows.length === 0
69
+ ? [draw.line([[empty]])]
70
+ : shown.map((row) => rowLine(draw, input.now, row))),
71
+ ...(shown.length < rows.length
72
+ ? [draw.line([[`... ${String(rows.length - shown.length)} more rows`]])]
73
+ : []),
74
+ ];
75
+ };
76
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1,70 @@
1
+ import { type NodeHolding, type PagedNode, type RouteKind } from "@maiaos/client-core/cockpit";
2
+ import { type ProtocolError } from "@maiaos/sdk";
3
+ import type * as Crypto from "effect/Crypto";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Result from "effect/Result";
6
+ import type { CliNodeEffect, CliNodeResult } from "../local-node/index.js";
7
+ export type FleetNode<TReach> = {
8
+ readonly node: string;
9
+ readonly reach: TReach;
10
+ };
11
+ export type NodeAnswer<TValue> = {
12
+ readonly node: string;
13
+ readonly result: CliNodeResult<TValue>;
14
+ };
15
+ export type ListedNode = PagedNode<ProtocolError>;
16
+ export type HeldId = {
17
+ readonly id: string;
18
+ readonly kind: RouteKind;
19
+ };
20
+ export type NoHolder = {
21
+ readonly error: ProtocolError;
22
+ readonly holdings: readonly NodeHolding[];
23
+ };
24
+ export declare const refused: (code: string, message: string, retryable?: boolean) => {
25
+ error: {
26
+ code: string;
27
+ message: string;
28
+ retryable: boolean;
29
+ };
30
+ ok: false;
31
+ };
32
+ export type Fleet<TReach> = {
33
+ readonly bind?: (name: string) => TReach;
34
+ readonly chosen: boolean;
35
+ readonly listRemoteNodes?: (input: Record<string, never>) => CliNodeEffect<{
36
+ readonly nodes: readonly {
37
+ readonly name: string;
38
+ }[];
39
+ }>;
40
+ readonly local: FleetNode<TReach>;
41
+ };
42
+ export declare const fleetNodes: <TReach>({ bind, chosen, listRemoteNodes, local, }: Fleet<TReach>) => CliNodeEffect<readonly FleetNode<TReach>[]>;
43
+ export declare const askEach: <TReach, TValue>(nodes: readonly FleetNode<TReach>[], ask: (reach: TReach) => CliNodeEffect<TValue>) => Effect.Effect<NodeAnswer<TValue>[], never, Crypto.Crypto>;
44
+ export declare const routes: ({ id, kind }: HeldId) => boolean;
45
+ export type HolderSearch<TReach> = {
46
+ readonly choose: string;
47
+ readonly probe: (reach: TReach) => CliNodeEffect<unknown>;
48
+ };
49
+ export declare const holderIn: <TReach>(nodes: readonly FleetNode<TReach>[], { id, kind }: HeldId, { choose, probe }: HolderSearch<TReach>) => Effect.Effect<Result.Result<FleetNode<TReach>, NoHolder>, never, Crypto.Crypto>;
50
+ export declare const mergeLists: <TItem extends object>(answers: readonly NodeAnswer<{
51
+ readonly items: readonly TItem[];
52
+ readonly nextCursor?: string;
53
+ }>[]) => {
54
+ items: (TItem & {
55
+ node: string;
56
+ })[];
57
+ nodes: PagedNode<{
58
+ readonly code: string;
59
+ readonly message: string;
60
+ readonly retryable: boolean;
61
+ readonly saturation?: "account" | "admission" | undefined;
62
+ }>[];
63
+ };
64
+ export declare const failureOf: (nodes: readonly ListedNode[]) => {
65
+ readonly code: string;
66
+ readonly message: string;
67
+ readonly retryable: boolean;
68
+ readonly saturation?: "account" | "admission" | undefined;
69
+ } | undefined;
70
+ //# sourceMappingURL=fleet.d.ts.map
@@ -0,0 +1,91 @@
1
+ import { combinePages, holderAmong, } from "@maiaos/client-core/cockpit";
2
+ import { receiptGetParametersSchema } from "@maiaos/sdk";
3
+ import * as Config from "effect/Config";
4
+ import * as Duration from "effect/Duration";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Option from "effect/Option";
7
+ import * as Result from "effect/Result";
8
+ import { cell, LOCAL_NODE } from "../command-line/index.js";
9
+ import { isExactId } from "../reference/index.js";
10
+ const ASK_DEADLINE = Duration.seconds(12);
11
+ const ASK_CONCURRENCY = 4;
12
+ export const refused = (code, message, retryable = false) => ({
13
+ error: { code, message, retryable },
14
+ ok: false,
15
+ });
16
+ const actsAsSession = Effect.map(Effect.orElseSucceed(Config.option(Config.String("MAIA_SESSION_CREDENTIAL")), Option.none), Option.isSome);
17
+ const NO_REGISTRY = new Set([
18
+ "command_not_implemented",
19
+ "unsupported_method",
20
+ ]);
21
+ const withRemotes = (local, names, bind) => names.includes(LOCAL_NODE)
22
+ ? refused("invalid_argument", "A remote Node is registered as 'local', the name of this machine's Node: remove it with 'maia node remove local' and install it under another name.")
23
+ : {
24
+ ok: true,
25
+ value: [local, ...names.map((node) => ({ node, reach: bind(node) }))],
26
+ };
27
+ export const fleetNodes = ({ bind, chosen, listRemoteNodes, local, }) => Effect.gen(function* () {
28
+ if (chosen ||
29
+ bind === undefined ||
30
+ listRemoteNodes === undefined ||
31
+ (yield* actsAsSession))
32
+ return { ok: true, value: [local] };
33
+ const listed = yield* listRemoteNodes({});
34
+ if (listed.ok)
35
+ return withRemotes(local, listed.value.nodes.map(({ name }) => name), bind);
36
+ return NO_REGISTRY.has(listed.error.code)
37
+ ? { ok: true, value: [local] }
38
+ : listed;
39
+ });
40
+ export const askEach = (nodes, ask) => Effect.forEach(nodes, ({ node, reach }) => ask(reach).pipe(nodes.length === 1
41
+ ? (asked) => asked
42
+ : Effect.timeoutOrElse({
43
+ duration: ASK_DEADLINE,
44
+ orElse: () => Effect.succeed(refused("node_unavailable", `Node ${node} did not answer within ${Duration.format(ASK_DEADLINE)}.`, true)),
45
+ }), Effect.map((result) => ({ node, result }))), { concurrency: ASK_CONCURRENCY });
46
+ export const routes = ({ id, kind }) => kind === "command"
47
+ ? receiptGetParametersSchema.safeParse({ commandId: id }).success
48
+ : isExactId(kind, id);
49
+ const holdingOf = ({ node, result }) => {
50
+ if (result.ok)
51
+ return { node, state: "holds" };
52
+ return {
53
+ node,
54
+ state: result.error.code === "resource_not_found" ? "absent" : "unavailable",
55
+ };
56
+ };
57
+ const refusalOf = ({ id, nodes = [], reason }, answers, choose) => {
58
+ switch (reason) {
59
+ case "ambiguous":
60
+ return refused("node_ambiguous", `${id} is on ${String(nodes.length)} Nodes: ${nodes.join(", ")}. ${choose.charAt(0).toUpperCase()}${choose.slice(1)} to choose one.`).error;
61
+ case "unavailable": {
62
+ const why = answers.flatMap(({ node, result }) => nodes.includes(node) && !result.ok
63
+ ? [`${node} (${cell(result.error.message)})`]
64
+ : []);
65
+ return refused("node_unavailable", `${id} could be on a Node that did not answer: ${why.join(", ")}. Retry, or ${choose}.`, true).error;
66
+ }
67
+ case "unknown":
68
+ return refused("resource_not_found", `No Node holds ${id}.`).error;
69
+ }
70
+ };
71
+ export const holderIn = (nodes, { id, kind }, { choose, probe }) => Effect.map(askEach(nodes, probe), (answers) => {
72
+ const holdings = answers.map(holdingOf);
73
+ const holder = holderAmong(kind, id, holdings);
74
+ const found = Result.isSuccess(holder)
75
+ ? nodes.find(({ node }) => node === holder.success)
76
+ : undefined;
77
+ if (found !== undefined)
78
+ return Result.succeed(found);
79
+ const error = Result.isFailure(holder)
80
+ ? refusalOf(holder.failure, answers, choose)
81
+ : refused("resource_not_found", `No Node holds ${id}.`).error;
82
+ return Result.fail({ error, holdings });
83
+ });
84
+ export const mergeLists = (answers) => combinePages(answers.map(({ node, result }) => ({
85
+ node,
86
+ page: result.ok
87
+ ? Result.succeed(result.value)
88
+ : Result.fail(result.error),
89
+ })));
90
+ export const failureOf = (nodes) => nodes.find(({ error }) => error !== undefined)?.error;
91
+ //# sourceMappingURL=fleet.js.map
@@ -0,0 +1,2 @@
1
+ export { askEach, failureOf, type Fleet, type FleetNode, fleetNodes, type HeldId, holderIn, type ListedNode, mergeLists, type NodeAnswer, type NoHolder, refused, routes, } from "./fleet.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { askEach, failureOf, fleetNodes, holderIn, mergeLists, refused, routes, } from "./fleet.js";
2
+ //# sourceMappingURL=index.js.map
@@ -1,9 +1,5 @@
1
- import { formatRows } from "../../command-line/index.js";
1
+ import { cell, formatRows } from "../../command-line/index.js";
2
2
  export const isHoldResult = (result) => result.command.startsWith("hold.");
3
- const cell = (value) => Array.from(value, (character) => {
4
- const point = character.codePointAt(0) ?? 0;
5
- return point < 32 || (point >= 127 && point <= 159) ? " " : character;
6
- }).join("");
7
3
  const targetList = (targets) => targets.map((target) => `${target.kind}:${target.id}`).join(",");
8
4
  export const formatHoldResult = ({ result }) => {
9
5
  switch (result.method) {
@@ -50,6 +50,7 @@ export const SAFETY_TREE = {
50
50
  "Show the receipt of one command ID.",
51
51
  {
52
52
  example: "maia --json receipt show create-1",
53
+ route: "<command-id>",
53
54
  run: [receipt, "runReceiptShow"],
54
55
  },
55
56
  ],
@@ -1,14 +1,13 @@
1
1
  import { Effect } from "effect";
2
- import { CliArgumentError, parseOptions, readTwoPhaseMode, reportError, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, } from "../command-line/index.js";
2
+ import { CliArgumentError, parseOptions, readTwoPhaseMode, reportError, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeSuccess, } from "../command-line/index.js";
3
3
  import { readAdopt, readHistory, readScan } from "./input.js";
4
4
  import { formatAdoptConfirm, formatAdoptPreview, formatHistory, formatScan, } from "./output.js";
5
5
  const missingClient = () => Effect.fail(new CliArgumentError("Session discovery is unavailable."));
6
6
  const write = (response, context, output) => {
7
7
  if (!response.ok)
8
8
  return reportError(response.error, context);
9
- context.io.stdout(context.json
10
- ? `${JSON.stringify({ ok: true, result: { command: output.command, result: response.value } })}\n`
11
- : output.format(response.value));
9
+ const { value } = response;
10
+ writeSuccess({ command: output.command, result: value }, context, () => output.format(value));
12
11
  return 0;
13
12
  };
14
13
  const required = (context, name) => {
@@ -1,7 +1,4 @@
1
- const cell = (value) => Array.from(value, (character) => {
2
- const point = character.codePointAt(0) ?? 0;
3
- return point < 32 || (point >= 127 && point <= 159) ? " " : character;
4
- }).join("");
1
+ import { cell } from "../command-line/index.js";
5
2
  const line = (...cells) => `${cells.map(cell).join("\t")}\n`;
6
3
  const nativeName = (session) => `${session.executor === "claude-code" ? "claude" : "codex"}:${session.nativeId}`;
7
4
  const groupLine = (group) => line(group.kind, group.repository?.rootPath ?? group.cwd ?? "", `${String(group.sessionCount)} sessions`, group.registeredProjectId ?? "unregistered");
@@ -1,10 +1,10 @@
1
1
  import type { LocalNodeRequestOptions, LocalNodeStatusResult, ProtocolError } from "@maiaos/sdk";
2
- import type { DiscoveredNodeApiEffectConnection, LocalNodeEffectClient, NodeApiEffectDiscoveryOptions } from "@maiaos/sdk/node/effect";
2
+ import type { DiscoveredNodeApiEffectConnection, LocalNodeEffectClient, NodeApiEffectDiscoveryOptions, NodeBridge } from "@maiaos/sdk/node/effect";
3
3
  import * as Crypto from "effect/Crypto";
4
4
  import * as Effect from "effect/Effect";
5
- import * as Schedule from "effect/Schedule";
6
5
  export type CliMutationRecovery = {
7
6
  readonly commandId: string;
7
+ readonly profile?: string;
8
8
  };
9
9
  export type CliNodeResult<TValue> = {
10
10
  readonly error: ProtocolError;
@@ -14,7 +14,9 @@ export type CliNodeResult<TValue> = {
14
14
  readonly ok: true;
15
15
  readonly value: TValue;
16
16
  };
17
- export type CliNodeConnection = Pick<DiscoveredNodeApiEffectConnection, "client" | "status">;
17
+ export type CliNodeConnection = Pick<DiscoveredNodeApiEffectConnection, "client" | "status"> & {
18
+ readonly attachSession?: NodeBridge["attachSession"];
19
+ };
18
20
  export type CliNodeConnector = (options: NodeApiEffectDiscoveryOptions) => Effect.Effect<CliNodeConnection, unknown, Crypto.Crypto>;
19
21
  export declare const newCliIdentifier: (prefix: "command" | "request") => Effect.Effect<string, never, Crypto.Crypto>;
20
22
  export declare const commandIdentifier: (commandId: string | undefined) => Effect.Effect<string, never, Crypto.Crypto>;
@@ -36,6 +38,8 @@ export type CliNodeOperations = {
36
38
  readonly asCoordinator: () => CliNodeOperations;
37
39
  readonly asSession: () => CliNodeOperations;
38
40
  readonly readStatus: Effect.Effect<LocalNodeStatusResult, unknown, Crypto.Crypto>;
41
+ readonly remote: boolean;
42
+ readonly runConnectionOperation: <TValue>(operation: (connection: CliNodeConnection) => Effect.Effect<TValue, unknown, Crypto.Crypto>) => CliNodeEffect<TValue>;
39
43
  readonly runDiscoveryOperation: <TValue>(operation: (options: NodeApiEffectDiscoveryOptions) => Effect.Effect<TValue, unknown, Crypto.Crypto>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
40
44
  readonly runNodeClientOperation: <TValue>(operation: (client: LocalNodeEffectClient, options: LocalNodeRequestOptions) => Effect.Effect<TValue, unknown>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
41
45
  readonly runValidatedNodeOperation: <TParameters, TValue>(input: unknown, schema: ParameterSchema<TParameters>, operation: (client: LocalNodeEffectClient, parameters: TParameters, options: LocalNodeRequestOptions) => Effect.Effect<TValue, unknown>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
@@ -59,7 +63,7 @@ type LazyNodeDependencyInput<TModule, TClient> = {
59
63
  readonly name: keyof TClient;
60
64
  };
61
65
  export declare const isBriefSaturation: (error: unknown) => boolean;
62
- export declare const SATURATION_RETRY: Schedule.Schedule<import("effect/Duration").Duration, unknown, never, never>;
66
+ export declare const retryBriefSaturation: <TValue, TError, TServices>(attempt: Effect.Effect<TValue, TError, TServices>, deadlineAt?: bigint) => Effect.Effect<TValue, TError, TServices>;
63
67
  export declare const makeCliNodeOperations: (options?: CliNodeOperationsOptions) => CliNodeOperations;
64
68
  export declare const discoveryOptionsFor: (profile: string | undefined) => Effect.Effect<NodeApiEffectDiscoveryOptions, unknown>;
65
69
  export declare const runLazyNodeDependency: <TModule, TClient>(input: LazyNodeDependencyInput<TModule, TClient>) => Effect.Effect<unknown, unknown, Crypto.Crypto>;