@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
@@ -0,0 +1,8 @@
1
+ import type { BootstrapClientDependencies } from "./client.js";
2
+ import type { StartBootstrapNode } from "./launcher.js";
3
+ import type { ConfirmOnTerminal } from "./terminal.js";
4
+ export type BootstrapCliDependencies = BootstrapClientDependencies & {
5
+ readonly confirmOnTerminal: ConfirmOnTerminal;
6
+ readonly startBootstrapNode: StartBootstrapNode;
7
+ };
8
+ //# sourceMappingURL=dependencies.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1,6 @@
1
+ export { makeBootstrapClient } from "./client.js";
2
+ export { runNodeBootstrap } from "./commands.js";
3
+ export type { BootstrapCliDependencies } from "./dependencies.js";
4
+ export { startBootstrapNode } from "./launcher.js";
5
+ export { confirmOnControllingTerminal } from "./terminal.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { makeBootstrapClient } from "./client.js";
2
+ export { runNodeBootstrap } from "./commands.js";
3
+ export { startBootstrapNode } from "./launcher.js";
4
+ export { confirmOnControllingTerminal } from "./terminal.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,17 @@
1
+ import * as Effect from "effect/Effect";
2
+ import type * as Scope from "effect/Scope";
3
+ declare const BootstrapNodeError_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 & {
4
+ readonly _tag: "BootstrapNodeError";
5
+ } & Readonly<A>;
6
+ export declare class BootstrapNodeError extends BootstrapNodeError_base<{
7
+ readonly message: string;
8
+ }> {
9
+ }
10
+ export type BootstrapNode = {
11
+ readonly exited: Effect.Effect<never, BootstrapNodeError>;
12
+ readonly sendConfirmation: (frame: string) => Effect.Effect<void, BootstrapNodeError>;
13
+ };
14
+ export type StartBootstrapNode = (profile: string) => Effect.Effect<BootstrapNode, BootstrapNodeError, Scope.Scope>;
15
+ export declare const startBootstrapNode: StartBootstrapNode;
16
+ export {};
17
+ //# sourceMappingURL=launcher.d.ts.map
@@ -0,0 +1,30 @@
1
+ import * as NodeChildProcessSpawner from "@effect/platform-node-shared/NodeChildProcessSpawner";
2
+ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
3
+ import * as NodePath from "@effect/platform-node-shared/NodePath";
4
+ import * as Data from "effect/Data";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
+ import * as ChildProcess from "effect/process/ChildProcess";
8
+ import * as Stream from "effect/Stream";
9
+ export class BootstrapNodeError extends Data.TaggedError("BootstrapNodeError") {
10
+ }
11
+ const CHANNEL_DESCRIPTOR = 3;
12
+ const FORCE_KILL_AFTER = "10 seconds";
13
+ const NODE_EXECUTABLE = "maia-node";
14
+ const spawner = NodeChildProcessSpawner.layer.pipe(Layer.provide(Layer.merge(NodeFileSystem.layer, NodePath.layer)));
15
+ const failure = (message) => new BootstrapNodeError({ message });
16
+ const spawnNode = (profile) => ChildProcess.make(NODE_EXECUTABLE, ["--desktop", "--profile", profile, "--bootstrap-channel"], {
17
+ additionalFds: { fd3: { type: "input" } },
18
+ detached: false,
19
+ env: { ["MAIA_DESKTOP_PARENT_PIPE"]: "1" },
20
+ extendEnv: true,
21
+ forceKillAfter: FORCE_KILL_AFTER,
22
+ stderr: "ignore",
23
+ stdin: "pipe",
24
+ stdout: "ignore",
25
+ });
26
+ export const startBootstrapNode = (profile) => spawnNode(profile).pipe(Effect.map((handle) => ({
27
+ exited: handle.exitCode.pipe(Effect.mapError(() => failure("The Node could not be supervised.")), Effect.flatMap((code) => Effect.fail(failure(`The Node exited with code ${String(code)}.`)))),
28
+ sendConfirmation: (frame) => Stream.make(new TextEncoder().encode(frame)).pipe(Stream.run(handle.getInputFd(CHANNEL_DESCRIPTOR)), Effect.mapError(() => failure("The Node closed its confirmation channel."))),
29
+ })), Effect.mapError(() => failure("The Node could not be started.")), Effect.provide(spawner));
30
+ //# sourceMappingURL=launcher.js.map
@@ -0,0 +1,15 @@
1
+ import type { TeamWorkspaceBootstrapApplyResult, TeamWorkspaceBootstrapPreviewResult } from "@maiaos/sdk";
2
+ export type BootstrapPreviewView = {
3
+ readonly ownerDisplayName: string;
4
+ readonly preview: TeamWorkspaceBootstrapPreviewResult;
5
+ readonly profile: string;
6
+ readonly workspaceName: string;
7
+ };
8
+ export declare const describePreview: ({ ownerDisplayName, preview, profile, workspaceName, }: BootstrapPreviewView) => string;
9
+ export type BootstrapOutput = {
10
+ readonly command: TeamWorkspaceBootstrapApplyResult["method"];
11
+ readonly result: TeamWorkspaceBootstrapApplyResult;
12
+ };
13
+ export declare const toBootstrapOutput: (result: TeamWorkspaceBootstrapApplyResult) => BootstrapOutput;
14
+ export declare const formatBootstrapOutput: ({ result }: BootstrapOutput) => string;
15
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1,28 @@
1
+ const LABEL_WIDTH = 16;
2
+ const row = (label, value) => ` ${label.padEnd(LABEL_WIDTH)}${value}`;
3
+ export const describePreview = ({ ownerDisplayName, preview, profile, workspaceName, }) => [
4
+ "Bootstrap the first owner of this Node. This cannot be repeated or undone.",
5
+ row("profile", profile),
6
+ row("node", `${preview.nodeId} (epoch ${preview.nodeEpoch})`),
7
+ row("owner", `${JSON.stringify(ownerDisplayName)} as ${preview.userId}`),
8
+ row("device", preview.deviceId),
9
+ row("client", preview.clientId),
10
+ row("team workspace", `${JSON.stringify(workspaceName)} as ${preview.teamWorkspaceId}`),
11
+ row("role", preview.role),
12
+ row("command", preview.commandId),
13
+ row("digest", preview.inputDigest),
14
+ row("preview", preview.previewId),
15
+ row("expires", preview.expiresAt),
16
+ ].join("\n");
17
+ export const toBootstrapOutput = (result) => ({ command: result.method, result });
18
+ export const formatBootstrapOutput = ({ result }) => `${[
19
+ `bootstrapped\t${result.delivery}`,
20
+ `node\t${result.nodeId}`,
21
+ `owner\t${result.userId}`,
22
+ `device\t${result.deviceId}`,
23
+ `client\t${result.clientId}`,
24
+ `team workspace\t${result.teamWorkspaceId}`,
25
+ `role\t${result.role}`,
26
+ `receipt\t${result.receipt.receiptId}`,
27
+ ].join("\n")}\n`;
28
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1,9 @@
1
+ import * as Effect from "effect/Effect";
2
+ export type TerminalAnswer = "confirmed" | "declined" | "unavailable";
3
+ export type TerminalRequest = {
4
+ readonly description: string;
5
+ readonly expected: string;
6
+ };
7
+ export type ConfirmOnTerminal = (request: TerminalRequest) => Effect.Effect<TerminalAnswer>;
8
+ export declare const confirmOnControllingTerminal: ConfirmOnTerminal;
9
+ //# sourceMappingURL=terminal.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { closeSync, openSync } from "node:fs";
2
+ import { createInterface } from "node:readline";
3
+ import { isatty, ReadStream, WriteStream } from "node:tty";
4
+ import * as Effect from "effect/Effect";
5
+ const CONTROLLING_TERMINAL = "/dev/tty";
6
+ const openDescriptor = (flags) => {
7
+ const descriptor = openSync(CONTROLLING_TERMINAL, flags);
8
+ if (isatty(descriptor))
9
+ return descriptor;
10
+ closeSync(descriptor);
11
+ throw new TypeError("The controlling terminal is not a terminal.");
12
+ };
13
+ const destroyOnRelease = (stream) => Effect.sync(() => {
14
+ stream.destroy();
15
+ });
16
+ const openInput = Effect.acquireRelease(Effect.try(() => new ReadStream(openDescriptor("r"))), destroyOnRelease);
17
+ const openOutput = Effect.acquireRelease(Effect.try(() => new WriteStream(openDescriptor("w"))), destroyOnRelease);
18
+ const openLines = Effect.gen(function* () {
19
+ const input = yield* openInput;
20
+ const output = yield* openOutput;
21
+ return yield* Effect.acquireRelease(Effect.sync(() => createInterface({ input, output, terminal: true })), (lines) => Effect.sync(() => {
22
+ lines.close();
23
+ }));
24
+ });
25
+ const readAnswer = (lines, question) => Effect.callback((resume) => {
26
+ const ended = () => {
27
+ resume(Effect.undefined);
28
+ };
29
+ lines.once("close", ended);
30
+ lines.once("SIGINT", ended);
31
+ lines.question(question, (answer) => {
32
+ resume(Effect.succeed(answer));
33
+ });
34
+ return Effect.sync(() => {
35
+ lines.off("close", ended);
36
+ lines.off("SIGINT", ended);
37
+ });
38
+ });
39
+ export const confirmOnControllingTerminal = ({ description, expected, }) => Effect.gen(function* () {
40
+ const lines = yield* openLines;
41
+ const answer = yield* readAnswer(lines, `${description}\nType ${expected} to confirm, or anything else to cancel: `);
42
+ return answer?.trim() === expected
43
+ ? "confirmed"
44
+ : "declined";
45
+ }).pipe(Effect.scoped, Effect.orElseSucceed(() => "unavailable"));
46
+ //# sourceMappingURL=terminal.js.map
@@ -4,6 +4,10 @@ export type CreateTerminalInput = {
4
4
  readonly columns: number;
5
5
  readonly commandId?: string;
6
6
  readonly interactive: true;
7
+ readonly program?: {
8
+ readonly argv: readonly string[];
9
+ readonly name: string;
10
+ };
7
11
  readonly rows: number;
8
12
  readonly workspaceId: string;
9
13
  } | {
@@ -10,6 +10,9 @@ export const makeTerminalClient = (node) => {
10
10
  commandId,
11
11
  expectedRevision: "0",
12
12
  mode: "interactive",
13
+ ...(input.program === undefined
14
+ ? {}
15
+ : { program: input.program }),
13
16
  rows: input.rows,
14
17
  workspaceId: input.workspaceId,
15
18
  }
@@ -1,22 +1,12 @@
1
1
  import * as Effect from "effect/Effect";
2
- import { CliArgumentError, parseOptions, readCursor, readPageSize, requirePositionals, } from "../command-line/index.js";
2
+ import { CliArgumentError, parseOptions, readCursor, readPageSize, reportError, requirePositionals, } from "../command-line/index.js";
3
3
  import { readTerminalColumns, readTerminalRows } from "./arguments.js";
4
4
  import { projectTerminalEventsResult, projectTerminalListResult, projectTerminalReadResult, projectTerminalShowResult, terminalOutputAudience, writeTerminalResult, } from "./output/index.js";
5
- const summarizeTerminalCreation = (result) => {
6
- if (!("accepted" in result) || result.accepted)
7
- return result;
8
- const unavailableResult = result;
9
- return {
10
- accepted: unavailableResult.accepted,
11
- delivery: unavailableResult.delivery,
12
- receipt: unavailableResult.receipt,
13
- state: unavailableResult.terminal.state,
14
- terminalId: unavailableResult.terminal.id,
15
- unavailability: unavailableResult.terminal.unavailability,
16
- workspaceId: unavailableResult.terminal.workspaceId,
17
- workspaceRevision: unavailableResult.terminal.workspaceRevision,
18
- };
19
- };
5
+ const unavailableCreateError = ({ receipt, terminal, }) => ({
6
+ code: terminal.unavailability.code,
7
+ message: `${terminal.id} is unavailable on this ${terminal.unavailability.platform} Node (${terminal.unavailability.code}); receipt ${receipt.receiptId} records it.`,
8
+ retryable: false,
9
+ });
20
10
  const readTerminalEventPageSize = (value) => {
21
11
  if (value === undefined)
22
12
  return 20;
@@ -33,27 +23,47 @@ const readTerminalChunkPageSize = (value) => {
33
23
  }
34
24
  return Number(value);
35
25
  };
26
+ const readProgramTokens = (tokens) => {
27
+ const separator = tokens.indexOf("--");
28
+ if (separator === -1)
29
+ return undefined;
30
+ const [name, ...argv] = tokens.slice(separator + 1);
31
+ if (name === undefined) {
32
+ throw new CliArgumentError("Name a program after '--'.");
33
+ }
34
+ return { argv, name };
35
+ };
36
36
  const parseTerminalCreate = (tokens) => {
37
- const parsed = parseOptions(tokens, new Set(["--columns", "--command-id", "--rows", "--workspace"]), new Set(["--interactive"]));
37
+ const separator = tokens.indexOf("--");
38
+ const parsed = parseOptions(separator === -1 ? tokens : tokens.slice(0, separator), new Set(["--columns", "--command-id", "--rows", "--workspace"]), new Set(["--interactive"]));
38
39
  requirePositionals(parsed.positionals, 0);
39
40
  const workspaceId = parsed.options.get("--workspace");
40
41
  if (workspaceId === undefined) {
41
42
  throw new CliArgumentError("Option '--workspace' is required.");
42
43
  }
43
- return { parsed, workspaceId };
44
+ const program = readProgramTokens(tokens);
45
+ return { parsed, ...(program === undefined ? {} : { program }), workspaceId };
44
46
  };
45
- const makeTerminalCreateInput = (parsed, workspaceId) => {
46
- const interactive = parsed.flags.has("--interactive");
47
+ const requireInteractiveForViewportAndProgram = (input) => {
48
+ const interactive = input.parsed.flags.has("--interactive");
47
49
  if (!interactive &&
48
- (parsed.options.has("--columns") || parsed.options.has("--rows"))) {
49
- throw new CliArgumentError("Options '--columns' and '--rows' require '--interactive'.");
50
+ (input.parsed.options.has("--columns") ||
51
+ input.parsed.options.has("--rows") ||
52
+ input.program !== undefined)) {
53
+ throw new CliArgumentError("Options '--columns' and '--rows' and a program after '--' require '--interactive'.");
50
54
  }
55
+ return interactive;
56
+ };
57
+ const makeTerminalCreateInput = (input) => {
58
+ const { parsed, program, workspaceId } = input;
59
+ const interactive = requireInteractiveForViewportAndProgram(input);
51
60
  const commandId = parsed.options.get("--command-id");
52
61
  return interactive
53
62
  ? {
54
63
  columns: readTerminalColumns(parsed.options.get("--columns"), 80),
55
64
  ...(commandId === undefined ? {} : { commandId }),
56
65
  interactive: true,
66
+ ...(program === undefined ? {} : { program }),
57
67
  rows: readTerminalRows(parsed.options.get("--rows"), 24),
58
68
  workspaceId,
59
69
  }
@@ -63,12 +73,14 @@ const makeTerminalCreateInput = (parsed, workspaceId) => {
63
73
  };
64
74
  };
65
75
  export const runTerminalCreate = (tokens, context) => Effect.gen(function* () {
66
- const { parsed, workspaceId } = parseTerminalCreate(tokens);
67
- const input = makeTerminalCreateInput(parsed, workspaceId);
76
+ const input = makeTerminalCreateInput(parseTerminalCreate(tokens));
68
77
  const result = yield* context.dependencies.createTerminal(input);
78
+ if (result.ok && "accepted" in result.value && !result.value.accepted) {
79
+ return reportError(unavailableCreateError(result.value), context);
80
+ }
69
81
  return writeTerminalResult(result, context, (value) => ({
70
82
  command: "terminal.create",
71
- result: summarizeTerminalCreation(value),
83
+ result: value,
72
84
  }));
73
85
  });
74
86
  const parseTerminalList = (tokens) => {
@@ -3,8 +3,19 @@ import { liveTerminalWriteParametersSchema, MAX_TERMINAL_INPUT_CHUNK_BYTES, } fr
3
3
  import * as Effect from "effect/Effect";
4
4
  import { CliArgumentError, parseOptions, requirePositionals, } from "../command-line/index.js";
5
5
  import { readTerminalColumns, readTerminalControllerFence, readTerminalExpectedRevision, readTerminalGeneration, readTerminalInputSequence, readTerminalLeaseDuration, readTerminalRows, terminalControllerFenceOptionNames, } from "./arguments.js";
6
+ import { terminalInputBytes, UnknownKeyError } from "./keys.js";
6
7
  import { writeTerminalResult } from "./output/index.js";
7
8
  const optionNames = (...additional) => new Set([...terminalControllerFenceOptionNames, ...additional]);
9
+ const typedInputBytes = (options) => {
10
+ try {
11
+ return terminalInputBytes([...options].filter(([name]) => name === "--text" || name === "--keys"));
12
+ }
13
+ catch (error) {
14
+ throw error instanceof UnknownKeyError
15
+ ? new CliArgumentError(error.message)
16
+ : error;
17
+ }
18
+ };
8
19
  const commandId = (options) => {
9
20
  const value = options.get("--command-id");
10
21
  return value === undefined ? {} : { commandId: value };
@@ -99,15 +110,15 @@ export const runControllerAcquire = (tokens, context) => Effect.gen(function* ()
99
110
  }));
100
111
  });
101
112
  const parseTerminalWriteOptions = (tokens) => {
102
- const parsed = parseOptions(tokens, optionNames("--input-id", "--input-sequence"), new Set(["--input-stdin"]));
113
+ const parsed = parseOptions(tokens, optionNames("--input-id", "--input-sequence", "--keys", "--text"), new Set(["--input-stdin"]));
103
114
  requirePositionals(parsed.positionals, 1);
104
- if (!parsed.flags.has("--input-stdin")) {
105
- throw new CliArgumentError("Option '--input-stdin' is required.");
115
+ const typed = parsed.options.has("--text") || parsed.options.has("--keys");
116
+ if (parsed.flags.has("--input-stdin") === typed) {
117
+ throw new CliArgumentError("Give the input as '--input-stdin' or as '--text' and '--keys', not both.");
106
118
  }
107
119
  return parsed;
108
120
  };
109
- const readTerminalWriteScope = (tokens) => {
110
- const parsed = parseTerminalWriteOptions(tokens);
121
+ const readTerminalWriteScope = (parsed) => {
111
122
  const terminalId = requiredTerminalId(parsed.positionals);
112
123
  const inputId = parsed.options.get("--input-id");
113
124
  if (inputId === undefined) {
@@ -146,14 +157,20 @@ const readTerminalInput = (context) => {
146
157
  });
147
158
  };
148
159
  export const runTerminalInputWrite = (tokens, context) => Effect.gen(function* () {
149
- const scope = readTerminalWriteScope(tokens);
150
- const input = yield* readTerminalInput(context);
151
- if (input.length === 0) {
160
+ const parsed = parseTerminalWriteOptions(tokens);
161
+ const scope = readTerminalWriteScope(parsed);
162
+ const bytes = parsed.flags.has("--input-stdin")
163
+ ? Buffer.from(yield* readTerminalInput(context), "utf8")
164
+ : typedInputBytes(parsed.options);
165
+ if (bytes.length === 0) {
152
166
  throw new CliArgumentError("Terminal input must not be empty.");
153
167
  }
168
+ if (bytes.length > MAX_TERMINAL_INPUT_CHUNK_BYTES) {
169
+ throw new CliArgumentError(`Terminal input must be at most ${String(MAX_TERMINAL_INPUT_CHUNK_BYTES)} bytes.`);
170
+ }
154
171
  const result = yield* context.dependencies.writeTerminalInput({
155
172
  ...scope,
156
- bytesBase64: Buffer.from(input, "utf8").toString("base64"),
173
+ bytesBase64: bytes.toString("base64"),
157
174
  });
158
175
  return writeTerminalResult(result, context, (value) => ({
159
176
  command: "terminal.input.write",
@@ -0,0 +1,12 @@
1
+ import { Buffer } from "node:buffer";
2
+ declare const UnknownKeyError_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 & {
3
+ readonly _tag: "UnknownKeyError";
4
+ } & Readonly<A>;
5
+ export declare class UnknownKeyError extends UnknownKeyError_base<{
6
+ readonly message: string;
7
+ }> {
8
+ }
9
+ export declare const TERMINAL_KEY_NAMES: readonly string[];
10
+ export declare const terminalInputBytes: (parts: Iterable<readonly [option: string, value: string]>) => Buffer;
11
+ export {};
12
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { Data } from "effect";
3
+ const NAMED_KEYS = new Map([
4
+ ["Backspace", "\u007F"],
5
+ ["Delete", "\u001B[3~"],
6
+ ["Down", "\u001B[B"],
7
+ ["End", "\u001B[F"],
8
+ ["Enter", "\r"],
9
+ ["Escape", "\u001B"],
10
+ ["F1", "\u001BOP"],
11
+ ["F2", "\u001BOQ"],
12
+ ["F3", "\u001BOR"],
13
+ ["F4", "\u001BOS"],
14
+ ["F5", "\u001B[15~"],
15
+ ["F6", "\u001B[17~"],
16
+ ["F7", "\u001B[18~"],
17
+ ["F8", "\u001B[19~"],
18
+ ["F9", "\u001B[20~"],
19
+ ["F10", "\u001B[21~"],
20
+ ["F11", "\u001B[23~"],
21
+ ["F12", "\u001B[24~"],
22
+ ["Home", "\u001B[H"],
23
+ ["Insert", "\u001B[2~"],
24
+ ["Left", "\u001B[D"],
25
+ ["PageDown", "\u001B[6~"],
26
+ ["PageUp", "\u001B[5~"],
27
+ ["Right", "\u001B[C"],
28
+ ["Space", " "],
29
+ ["Tab", "\t"],
30
+ ["Up", "\u001B[A"],
31
+ ]);
32
+ export class UnknownKeyError extends Data.TaggedError("UnknownKeyError") {
33
+ }
34
+ export const TERMINAL_KEY_NAMES = [
35
+ ...NAMED_KEYS.keys(),
36
+ "C-<a..z>",
37
+ "M-<char>",
38
+ ];
39
+ const bytesOfKey = (name) => {
40
+ const named = NAMED_KEYS.get(name);
41
+ if (named !== undefined)
42
+ return named;
43
+ if (/^C-[a-z]$/u.test(name)) {
44
+ return String.fromCodePoint((name.codePointAt(2) ?? 0) - 0x60);
45
+ }
46
+ const alt = /^M-(\P{Cc})$/u.exec(name);
47
+ if (alt?.[1] !== undefined)
48
+ return `\u001B${alt[1]}`;
49
+ throw new UnknownKeyError({
50
+ message: `Unknown key '${name}'. Keys: ${TERMINAL_KEY_NAMES.join(", ")}.`,
51
+ });
52
+ };
53
+ export const terminalInputBytes = (parts) => Buffer.from([...parts]
54
+ .map(([option, value]) => option === "--text"
55
+ ? value
56
+ : value
57
+ .split(/\s+/u)
58
+ .filter((name) => name !== "")
59
+ .map(bytesOfKey)
60
+ .join(""))
61
+ .join(""), "utf8");
62
+ //# sourceMappingURL=keys.js.map
@@ -130,6 +130,7 @@ type CliTerminalChunk = {
130
130
  export type CliTerminalReadResult = {
131
131
  readonly command: "terminal.read";
132
132
  readonly count: number;
133
+ readonly gap?: TerminalReadResult["gap"];
133
134
  readonly headChunkCursor: TerminalReadResult["headChunkCursor"];
134
135
  readonly items: readonly CliTerminalChunk[];
135
136
  readonly nextChunkCursor?: TerminalReadResult["nextChunkCursor"];
@@ -142,6 +142,7 @@ export const projectTerminalChunk = (chunk) => ({
142
142
  export const projectTerminalReadResult = (value) => ({
143
143
  command: "terminal.read",
144
144
  count: value.items.length,
145
+ ...(value.gap === undefined ? {} : { gap: value.gap }),
145
146
  headChunkCursor: value.headChunkCursor,
146
147
  items: value.items.map(projectTerminalChunk),
147
148
  ...(value.nextChunkCursor === undefined
@@ -1,14 +1,7 @@
1
- import type { LiveTerminalCloseResult, LiveTerminalControllerAcquireResult, LiveTerminalControllerReleaseResult, LiveTerminalControllerRequestResult, LiveTerminalControllerRequestShowResult, LiveTerminalResizeResult, LiveTerminalSignalResult, LiveTerminalWriteResult, TerminalCreateResult, TerminalListResult } from "@maiaos/sdk";
1
+ import type { LiveTerminalCloseResult, LiveTerminalControllerAcquireResult, LiveTerminalControllerReleaseResult, LiveTerminalControllerRequestResult, LiveTerminalControllerRequestShowResult, LiveTerminalResizeResult, LiveTerminalSignalResult, LiveTerminalWriteResult, TerminalCreateResult } from "@maiaos/sdk";
2
2
  import { type CliIo } from "../../command-line/index.js";
3
3
  import type { CliNodeResult } from "../../local-node/index.js";
4
4
  import type { CliOutputAudience, CliTerminalEventsResult, CliTerminalListResult, CliTerminalReadResult, CliTerminalShowResult } from "./compact-list.js";
5
- type UnavailableTerminal = Extract<TerminalListResult["items"][number], {
6
- readonly state: "unavailable";
7
- }>;
8
- type UnavailableTerminalCreateResult = Extract<TerminalCreateResult, {
9
- readonly accepted: false;
10
- }>;
11
- type InteractiveTerminalCreateResult = Exclude<TerminalCreateResult, UnavailableTerminalCreateResult>;
12
5
  export type CliTerminalResult = CliTerminalEventsResult<CliOutputAudience> | CliTerminalListResult<CliOutputAudience> | CliTerminalReadResult | CliTerminalShowResult<CliOutputAudience> | {
13
6
  readonly command: "terminal.close";
14
7
  readonly result: LiveTerminalCloseResult;
@@ -26,16 +19,7 @@ export type CliTerminalResult = CliTerminalEventsResult<CliOutputAudience> | Cli
26
19
  readonly result: LiveTerminalControllerRequestShowResult;
27
20
  } | {
28
21
  readonly command: "terminal.create";
29
- readonly result: InteractiveTerminalCreateResult | {
30
- readonly accepted: false;
31
- readonly delivery: UnavailableTerminalCreateResult["delivery"];
32
- readonly receipt: UnavailableTerminalCreateResult["receipt"];
33
- readonly state: UnavailableTerminal["state"];
34
- readonly terminalId: string;
35
- readonly unavailability: UnavailableTerminal["unavailability"];
36
- readonly workspaceId: string;
37
- readonly workspaceRevision: string;
38
- };
22
+ readonly result: TerminalCreateResult;
39
23
  } | {
40
24
  readonly command: "terminal.input.write";
41
25
  readonly result: LiveTerminalWriteResult;
@@ -55,5 +39,4 @@ export declare const writeTerminalResult: <TValue>(result: CliNodeResult<TValue>
55
39
  readonly io: CliIo;
56
40
  readonly json: boolean;
57
41
  }, map: (value: TValue) => CliTerminalResult) => number;
58
- export {};
59
42
  //# sourceMappingURL=human.d.ts.map
@@ -1,4 +1,4 @@
1
- import { cell, formatRows, writeNodeResult, } from "../../command-line/index.js";
1
+ import { cell, formatRows, jsonLine, writeNodeResult, } from "../../command-line/index.js";
2
2
  const isHumanLiveTerminal = (terminal) => terminal.state !== "unavailable" && "capability" in terminal;
3
3
  const formatTerminalProjection = (terminal) => {
4
4
  if (terminal.state === "unavailable") {
@@ -22,13 +22,13 @@ const formatTerminalEvent = (event) => {
22
22
  return `${cell(event.cursor)}\t${cell(event.type)}`;
23
23
  };
24
24
  export const formatTerminalEvents = (result) => formatRows(result.items, formatTerminalEvent);
25
- export const formatTerminalRead = (result) => formatRows(result.items, (chunk) => `${cell(chunk.cursor)}\t${chunk.bytesBase64}`);
25
+ export const formatTerminalRead = (result) => (result.gap === undefined
26
+ ? ""
27
+ : `gap\t${result.gap.reason}\t${cell(result.gap.oldestAvailableCursor)}\n`) +
28
+ formatRows(result.items, (chunk) => `${cell(chunk.cursor)}\t${chunk.bytesBase64}`);
26
29
  export const formatTerminalResult = (result) => {
27
30
  switch (result.command) {
28
31
  case "terminal.create":
29
- return "accepted" in result.result && !result.result.accepted
30
- ? `${result.result.terminalId}\t${result.result.state}\t${result.result.unavailability.code}\n`
31
- : `${JSON.stringify(result.result)}\n`;
32
32
  case "terminal.close":
33
33
  case "terminal.controller.acquire":
34
34
  case "terminal.controller.release":
@@ -37,7 +37,7 @@ export const formatTerminalResult = (result) => {
37
37
  case "terminal.input.write":
38
38
  case "terminal.resize":
39
39
  case "terminal.signal":
40
- return `${JSON.stringify(result.result)}\n`;
40
+ return jsonLine(result.result);
41
41
  case "terminal.events":
42
42
  return formatTerminalEvents(result);
43
43
  case "terminal.list":