@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.
- package/README.md +38 -265
- package/dist/address-space/address-space.d.ts +38 -0
- package/dist/address-space/address-space.js +130 -0
- package/dist/address-space/index.d.ts +2 -0
- package/dist/address-space/index.js +2 -0
- package/dist/agents/client.d.ts +171 -0
- package/dist/agents/client.js +8 -0
- package/dist/agents/commands.d.ts +7 -0
- package/dist/agents/commands.js +65 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.js +3 -0
- package/dist/agents/input.d.ts +130 -0
- package/dist/agents/input.js +99 -0
- package/dist/agents/output/format.d.ts +8 -0
- package/dist/agents/output/format.js +47 -0
- package/dist/agents/output/index.d.ts +2 -0
- package/dist/agents/output/index.js +2 -0
- package/dist/agents/tree/index.d.ts +2 -0
- package/dist/agents/tree/index.js +2 -0
- package/dist/agents/tree/tree.d.ts +3 -0
- package/dist/agents/tree/tree.js +43 -0
- package/dist/bin/maia.cdx.json +37 -14
- package/dist/bin/maia.mjs +1 -1
- package/dist/bootstrap/exit.d.ts +14 -0
- package/dist/bootstrap/exit.js +42 -0
- package/dist/bootstrap/process.js +4 -26
- package/dist/bootstrap/run.js +5 -2
- package/dist/cli/cli.d.ts +2 -1
- package/dist/cli/cli.js +81 -16
- package/dist/command-line/context.d.ts +14 -4
- package/dist/command-line/context.js +1 -1
- package/dist/command-line/index.d.ts +6 -6
- package/dist/command-line/index.js +6 -5
- package/dist/command-line/input/arguments.d.ts +7 -0
- package/dist/command-line/input/arguments.js +22 -10
- package/dist/command-line/input/index.d.ts +2 -2
- package/dist/command-line/input/index.js +2 -2
- package/dist/command-line/input/stdin.d.ts +1 -0
- package/dist/command-line/input/stdin.js +1 -0
- package/dist/command-line/json.d.ts +1 -0
- package/dist/command-line/json.js +23 -0
- package/dist/command-line/output.d.ts +8 -1
- package/dist/command-line/output.js +33 -14
- package/dist/command-line/rows.d.ts +2 -0
- package/dist/command-line/rows.js +10 -1
- package/dist/command-line/two-phase.d.ts +5 -0
- package/dist/command-line/two-phase.js +33 -8
- package/dist/command-tree/help.d.ts +1 -1
- package/dist/command-tree/help.js +1 -0
- package/dist/command-tree/index.d.ts +2 -2
- package/dist/command-tree/index.js +1 -1
- package/dist/command-tree/local.js +12 -0
- package/dist/command-tree/placeholder.d.ts +1 -0
- package/dist/command-tree/placeholder.js +1 -0
- package/dist/command-tree/row.d.ts +2 -0
- package/dist/command-tree/tree.d.ts +3 -2
- package/dist/command-tree/tree.js +18 -2
- package/dist/connection/access/client.d.ts +13 -0
- package/dist/connection/access/client.js +19 -0
- package/dist/connection/access/commands.d.ts +6 -0
- package/dist/connection/access/commands.js +60 -0
- package/dist/connection/access/format.d.ts +8 -0
- package/dist/connection/access/format.js +61 -0
- package/dist/connection/access/index.d.ts +3 -0
- package/dist/connection/access/index.js +3 -0
- package/dist/connection/access/input.d.ts +53 -0
- package/dist/connection/access/input.js +83 -0
- package/dist/connection/client.d.ts +99 -1
- package/dist/connection/client.js +9 -1
- package/dist/connection/index.d.ts +2 -1
- package/dist/connection/index.js +2 -1
- package/dist/connection/system.d.ts +1 -0
- package/dist/connection/system.js +109 -5
- package/dist/connection/tree/tree.js +59 -8
- package/dist/container/output/format.js +1 -2
- package/dist/dashboard/cockpit-client.d.ts +6 -0
- package/dist/dashboard/cockpit-client.js +27 -0
- package/dist/dashboard/cockpits.d.ts +29 -0
- package/dist/dashboard/cockpits.js +65 -0
- package/dist/dashboard/dashboard.d.ts +7 -0
- package/dist/dashboard/dashboard.js +47 -0
- package/dist/dashboard/draw.d.ts +15 -0
- package/dist/dashboard/draw.js +30 -0
- package/dist/dashboard/frame.d.ts +4 -0
- package/dist/dashboard/frame.js +15 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/modes.d.ts +5 -0
- package/dist/dashboard/modes.js +16 -0
- package/dist/dashboard/node-connection.d.ts +15 -0
- package/dist/dashboard/node-connection.js +51 -0
- package/dist/dashboard/pi-tui.d.ts +6 -0
- package/dist/dashboard/pi-tui.js +35 -0
- package/dist/dashboard/status-bar.d.ts +4 -0
- package/dist/dashboard/status-bar.js +60 -0
- package/dist/dashboard/terminal.d.ts +53 -0
- package/dist/dashboard/terminal.js +165 -0
- package/dist/dashboard/tree-model.d.ts +28 -0
- package/dist/dashboard/tree-model.js +97 -0
- package/dist/dashboard/tree.d.ts +10 -0
- package/dist/dashboard/tree.js +76 -0
- package/dist/fleet/fleet.d.ts +70 -0
- package/dist/fleet/fleet.js +91 -0
- package/dist/fleet/index.d.ts +2 -0
- package/dist/fleet/index.js +2 -0
- package/dist/hold/output/format.js +1 -5
- package/dist/hold/tree/tree.js +1 -0
- package/dist/import/commands.js +3 -4
- package/dist/import/output.js +1 -4
- package/dist/local-node/client.d.ts +9 -4
- package/dist/local-node/client.js +21 -9
- package/dist/local-node/index.d.ts +2 -1
- package/dist/local-node/index.js +2 -1
- package/dist/local-node/wait.d.ts +10 -0
- package/dist/local-node/wait.js +17 -0
- package/dist/login/commands.js +2 -1
- package/dist/mcp/calls.d.ts +1 -0
- package/dist/mcp/calls.js +37 -3
- package/dist/mcp/commands.d.ts +5 -2
- package/dist/mcp/commands.js +30 -4
- package/dist/mcp/routing.d.ts +24 -0
- package/dist/mcp/routing.js +188 -0
- package/dist/mcp/server.d.ts +13 -4
- package/dist/mcp/server.js +35 -12
- package/dist/presentation/output/format.js +4 -3
- package/dist/project-guard/commands.js +11 -2
- package/dist/project-workspace/commands.js +16 -6
- package/dist/project-workspace/output/human.d.ts +13 -0
- package/dist/project-workspace/output/human.js +17 -5
- package/dist/project-workspace/output/index.d.ts +1 -1
- package/dist/project-workspace/output/index.js +1 -1
- package/dist/project-workspace/output/metadata.js +1 -1
- package/dist/project-workspace/tree/tree.js +27 -12
- package/dist/reference/commands.js +4 -2
- package/dist/reference/index.d.ts +1 -1
- package/dist/reference/index.js +1 -1
- package/dist/reference/resolve.d.ts +2 -0
- package/dist/reference/resolve.js +28 -18
- package/dist/remote-node/client.d.ts +89 -9
- package/dist/remote-node/client.js +6 -1
- package/dist/remote-node/commands.d.ts +9 -0
- package/dist/remote-node/commands.js +96 -18
- package/dist/remote-node/connector.d.ts +12 -4
- package/dist/remote-node/connector.js +54 -26
- package/dist/remote-node/index.d.ts +2 -2
- package/dist/remote-node/index.js +2 -2
- package/dist/remote-node/reachability.d.ts +43 -1
- package/dist/remote-node/reachability.js +13 -3
- package/dist/remote-node/text.d.ts +2 -1
- package/dist/remote-node/text.js +74 -27
- package/dist/remote-node/tree/tree.js +21 -1
- package/dist/routine/client.d.ts +398 -0
- package/dist/routine/client.js +28 -0
- package/dist/routine/commands.d.ts +9 -0
- package/dist/routine/commands.js +109 -0
- package/dist/routine/index.d.ts +3 -0
- package/dist/routine/index.js +3 -0
- package/dist/routine/input.d.ts +28 -0
- package/dist/routine/input.js +44 -0
- package/dist/routine/output/format.d.ts +23 -0
- package/dist/routine/output/format.js +83 -0
- package/dist/routine/output/index.d.ts +2 -0
- package/dist/routine/output/index.js +2 -0
- package/dist/routine/tree/index.d.ts +2 -0
- package/dist/routine/tree/index.js +2 -0
- package/dist/routine/tree/tree.d.ts +3 -0
- package/dist/routine/tree/tree.js +70 -0
- package/dist/session/agent-permission.d.ts +2 -2
- package/dist/session/approval/commands.js +31 -9
- package/dist/session/approval/output/format.d.ts +11 -0
- package/dist/session/approval/output/format.js +8 -0
- package/dist/session/approval/output/index.d.ts +1 -1
- package/dist/session/approval/output/index.js +1 -1
- package/dist/session/attach-client.d.ts +1 -1
- package/dist/session/attach-client.js +12 -3
- package/dist/session/attach-render.js +15 -7
- package/dist/session/attach.js +17 -3
- package/dist/session/client.d.ts +12 -3
- package/dist/session/client.js +18 -17
- package/dist/session/commands.d.ts +1 -0
- package/dist/session/commands.js +120 -13
- package/dist/session/create-tasks.js +29 -11
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.js +2 -1
- package/dist/session/interaction/output/format.js +2 -1
- package/dist/session/output/diff.js +3 -10
- package/dist/session/output/failure.js +3 -10
- package/dist/session/output/human.d.ts +1 -0
- package/dist/session/output/human.js +21 -10
- package/dist/session/output/index.d.ts +2 -2
- package/dist/session/output/index.js +2 -2
- package/dist/session/output/tasks.d.ts +16 -1
- package/dist/session/output/tasks.js +41 -27
- package/dist/session/tree/tree.js +67 -8
- package/dist/session/turn/client.d.ts +4 -1
- package/dist/session/turn/client.js +22 -11
- package/dist/session/turn/commands.d.ts +2 -0
- package/dist/session/turn/commands.js +39 -11
- package/dist/session/turn/index.d.ts +3 -3
- package/dist/session/turn/index.js +1 -1
- package/dist/session/turn/output.d.ts +7 -2
- package/dist/session/turn/output.js +36 -13
- package/dist/status/client.d.ts +7 -2
- package/dist/status/command.js +3 -1
- package/dist/status/doctor.d.ts +5 -1
- package/dist/status/doctor.js +10 -4
- package/dist/status/output/compact.d.ts +1 -0
- package/dist/status/output/compact.js +3 -0
- package/dist/status/output/human.d.ts +1 -1
- package/dist/status/output/human.js +71 -14
- package/dist/team-workspace/ceremony.d.ts +19 -0
- package/dist/team-workspace/ceremony.js +141 -0
- package/dist/team-workspace/client.d.ts +58 -0
- package/dist/team-workspace/client.js +6 -0
- package/dist/team-workspace/commands.d.ts +3 -0
- package/dist/team-workspace/commands.js +85 -0
- package/dist/team-workspace/confirmation.d.ts +4 -0
- package/dist/team-workspace/confirmation.js +8 -0
- package/dist/team-workspace/dependencies.d.ts +8 -0
- package/dist/team-workspace/dependencies.js +2 -0
- package/dist/team-workspace/index.d.ts +6 -0
- package/dist/team-workspace/index.js +5 -0
- package/dist/team-workspace/launcher.d.ts +17 -0
- package/dist/team-workspace/launcher.js +30 -0
- package/dist/team-workspace/output.d.ts +15 -0
- package/dist/team-workspace/output.js +28 -0
- package/dist/team-workspace/terminal.d.ts +9 -0
- package/dist/team-workspace/terminal.js +46 -0
- package/dist/terminal/client.d.ts +4 -0
- package/dist/terminal/client.js +3 -0
- package/dist/terminal/commands.js +37 -25
- package/dist/terminal/control-commands.js +26 -9
- package/dist/terminal/keys.d.ts +12 -0
- package/dist/terminal/keys.js +62 -0
- package/dist/terminal/output/compact-list.d.ts +1 -0
- package/dist/terminal/output/compact-list.js +1 -0
- package/dist/terminal/output/human.d.ts +2 -19
- package/dist/terminal/output/human.js +6 -6
- package/dist/terminal/tree/tree.js +16 -16
- package/package.json +10 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FailureDetail, TurnInterruptResult, TurnShowResult, TurnTokenUsage, TurnWaitResult } from "@maiaos/sdk";
|
|
1
|
+
import type { FailureDetail, TurnInterruptResult, TurnQueueListResult, TurnShowResult, TurnTokenUsage, TurnWaitResult } from "@maiaos/sdk";
|
|
2
2
|
export type CliTurnMutation = {
|
|
3
|
-
readonly command: "turn.interrupt" | "turn.send";
|
|
3
|
+
readonly command: "turn.cancel" | "turn.interrupt" | "turn.send";
|
|
4
4
|
readonly result: {
|
|
5
5
|
readonly delivery: TurnInterruptResult["delivery"];
|
|
6
6
|
readonly receipt: TurnInterruptResult["receipt"];
|
|
@@ -35,7 +35,12 @@ export type CliTurnWait = {
|
|
|
35
35
|
readonly command: "turn.wait";
|
|
36
36
|
readonly result: TurnWaitResult;
|
|
37
37
|
};
|
|
38
|
+
export type CliTurnQueue = {
|
|
39
|
+
readonly command: "turn.queue.list";
|
|
40
|
+
readonly result: TurnQueueListResult;
|
|
41
|
+
};
|
|
38
42
|
export declare const formatTurnMutation: ({ result }: CliTurnMutation) => string;
|
|
43
|
+
export declare const formatTurnQueue: ({ result }: CliTurnQueue) => string;
|
|
39
44
|
export declare const formatTurnShow: ({ result }: CliTurnShow) => string;
|
|
40
45
|
export declare const formatTurnWait: ({ result }: CliTurnWait) => string;
|
|
41
46
|
export declare const turnWaitExitCode: (result: TurnWaitResult) => number;
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
import { block, cell, fields, formatRows, tab, } from "../../command-line/index.js";
|
|
1
2
|
import { formatFailure } from "../output/index.js";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export const formatTurnMutation = ({ result }) => fields([
|
|
4
|
+
["turn", result.turnId],
|
|
5
|
+
["state", result.state],
|
|
6
|
+
["revision", result.revision],
|
|
7
|
+
]);
|
|
8
|
+
const turnFields = (turn, reason) => fields([
|
|
9
|
+
["turn", turn.id],
|
|
10
|
+
["state", turn.state],
|
|
11
|
+
["revision", turn.revision],
|
|
12
|
+
["session", turn.sessionId],
|
|
13
|
+
["reason", reason],
|
|
14
|
+
]);
|
|
15
|
+
export const formatTurnQueue = ({ result }) => {
|
|
16
|
+
const { activeTurn, queue } = result;
|
|
17
|
+
const rows = [
|
|
18
|
+
...(activeTurn === undefined
|
|
19
|
+
? []
|
|
20
|
+
: [["-", activeTurn.state, activeTurn.id, activeTurn.revision, ""]]),
|
|
21
|
+
...queue.map((entry) => [
|
|
22
|
+
String(entry.position),
|
|
23
|
+
"queued",
|
|
24
|
+
entry.id,
|
|
25
|
+
entry.revision,
|
|
26
|
+
cell(entry.inputPreview.replaceAll(/\s+/gu, " ")),
|
|
27
|
+
]),
|
|
28
|
+
];
|
|
29
|
+
return formatRows(rows, tab, {
|
|
30
|
+
empty: "no running or queued turn",
|
|
31
|
+
headers: ["POSITION", "STATE", "TURN", "REVISION", "INPUT"],
|
|
32
|
+
});
|
|
33
|
+
};
|
|
11
34
|
const formatUsage = (usage) => usage === undefined
|
|
12
35
|
? ""
|
|
13
36
|
: `tokens: input ${String(usage.inputTokens)} (cached ${String(usage.cachedInputTokens)}), output ${String(usage.outputTokens)} (reasoning ${String(usage.reasoningOutputTokens)}), total ${String(usage.totalTokens)}${usage.modelCallCount === undefined ? "" : `, model calls ${String(usage.modelCallCount)}`}\n`;
|
|
14
|
-
const formatContent = (turn) => `input:\n${
|
|
37
|
+
const formatContent = (turn) => `input:\n${block(turn.input.text)}\n${turn.state === "completed" ? `response:\n${block(turn.responseText)}\n` : ""}`;
|
|
15
38
|
const shownContent = (result) => result.contentIncluded ? formatContent(result.turn) : "";
|
|
16
39
|
export const formatTurnShow = ({ result }) => {
|
|
17
40
|
const { turn } = result;
|
|
@@ -20,11 +43,11 @@ export const formatTurnShow = ({ result }) => {
|
|
|
20
43
|
? formatFailure(turn.failure, turn.state)
|
|
21
44
|
: "";
|
|
22
45
|
const usage = "tokenUsage" in turn ? formatUsage(turn.tokenUsage) : "";
|
|
23
|
-
return `${
|
|
46
|
+
return `${turnFields(turn)}${failure}${usage}${shownContent(result)}`;
|
|
24
47
|
};
|
|
25
48
|
export const formatTurnWait = ({ result }) => result.turns
|
|
26
|
-
.map((turn) => `${
|
|
27
|
-
.join("");
|
|
49
|
+
.map((turn) => `${turnFields(turn, turn.failureReason)}${turn.state === "failed" || turn.state === "outcome-unknown" ? formatFailure(turn.failure, turn.state) : ""}`)
|
|
50
|
+
.join("\n");
|
|
28
51
|
const EXIT_FAILED = 70;
|
|
29
52
|
const EXIT_DEADLINE = 74;
|
|
30
53
|
const EXIT_OUTCOME_UNKNOWN = 76;
|
package/dist/status/client.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
|
|
|
8
8
|
readonly pid: number;
|
|
9
9
|
readonly profile: string;
|
|
10
10
|
readonly startedAt: string;
|
|
11
|
+
readonly executorHost?: {
|
|
12
|
+
readonly bubblewrap: "found" | "missing";
|
|
13
|
+
readonly socat: "found" | "missing";
|
|
14
|
+
readonly userNamespaces: "allowed" | "no_nesting" | "restricted";
|
|
15
|
+
} | undefined;
|
|
11
16
|
readonly method: "node.status";
|
|
12
17
|
readonly processResources: {
|
|
13
18
|
readonly activeTrees: number;
|
|
@@ -42,7 +47,7 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
|
|
|
42
47
|
};
|
|
43
48
|
readonly cleanupUnknownTrees: number;
|
|
44
49
|
readonly fencedTrees: number;
|
|
45
|
-
readonly nextStep: "close_idle_terminal" | "inspect_cleanup_unknown" | "inspect_observed_pressure" | "none" | "verify_native_host";
|
|
50
|
+
readonly nextStep: "close_idle_terminal" | "inspect_cleanup_unknown" | "inspect_observed_pressure" | "none" | "run_node_in_delegated_cgroup" | "verify_native_host";
|
|
46
51
|
readonly observations: {
|
|
47
52
|
readonly cpuTimeMilliseconds: {
|
|
48
53
|
readonly availableTrees: number;
|
|
@@ -102,7 +107,7 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
|
|
|
102
107
|
};
|
|
103
108
|
readonly treeCount: number;
|
|
104
109
|
};
|
|
105
|
-
readonly pressure: "admission_degraded" | "cleanup_unknown" | "healthy" | "observed_pressure" | "warning";
|
|
110
|
+
readonly pressure: "admission_degraded" | "cgroup_delegation_unavailable" | "cleanup_unknown" | "healthy" | "observed_pressure" | "warning";
|
|
106
111
|
readonly supervision: {
|
|
107
112
|
readonly trackedTrees: number;
|
|
108
113
|
readonly watcherFibers: number;
|
package/dist/status/command.js
CHANGED
|
@@ -14,7 +14,9 @@ const unavailableError = (cause) => {
|
|
|
14
14
|
const remote = Predicate.hasProperty(error, "remoteError")
|
|
15
15
|
? protocolErrorSchema.safeParse(error.remoteError)
|
|
16
16
|
: undefined;
|
|
17
|
-
return remote?.success === true &&
|
|
17
|
+
return remote?.success === true &&
|
|
18
|
+
(remote.data.code === "node_unavailable" ||
|
|
19
|
+
remote.data.code === "invalid_argument")
|
|
18
20
|
? remote.data
|
|
19
21
|
: createUnavailableError();
|
|
20
22
|
};
|
package/dist/status/doctor.d.ts
CHANGED
|
@@ -5,9 +5,13 @@ export type DoctorCheck = {
|
|
|
5
5
|
readonly next?: string;
|
|
6
6
|
readonly ok: boolean;
|
|
7
7
|
};
|
|
8
|
+
export type DoctorScope = "machine" | "node";
|
|
8
9
|
export type CliDoctorResult = {
|
|
9
|
-
readonly checks: readonly DoctorCheck
|
|
10
|
+
readonly checks: readonly (DoctorCheck & {
|
|
11
|
+
readonly scope: DoctorScope;
|
|
12
|
+
})[];
|
|
10
13
|
readonly command: "doctor";
|
|
14
|
+
readonly node?: string;
|
|
11
15
|
readonly ok: boolean;
|
|
12
16
|
readonly version: string;
|
|
13
17
|
};
|
package/dist/status/doctor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Option from "effect/Option";
|
|
3
|
-
import { requireNoArguments, writeSuccess, } from "../command-line/index.js";
|
|
3
|
+
import { LOCAL_NODE, requireNoArguments, writeSuccess, } from "../command-line/index.js";
|
|
4
4
|
const EXIT_FAILED = 70;
|
|
5
5
|
const vendorWords = (executor) => executor === "codex-cli"
|
|
6
6
|
? { integration: "codex", login: "codex" }
|
|
@@ -71,8 +71,8 @@ const nodeChecks = (detected, connections) => {
|
|
|
71
71
|
]),
|
|
72
72
|
];
|
|
73
73
|
};
|
|
74
|
-
const formatDoctor = (result) => `Maia doctor ${result.ok ? "ok" : "failed"}\n${result.checks
|
|
75
|
-
.map((check) => ` ${check.code}: ${check.ok ? "ok" : "failed"}${check.detail === undefined ? "" : ` (${check.detail})`}${check.ok || check.next === undefined ? "" : `; next: ${check.next}`}\n`)
|
|
74
|
+
const formatDoctor = (result) => `Maia doctor ${result.ok ? "ok" : "failed"}${result.node === undefined ? "" : ` (Node ${result.node})`}\n${result.checks
|
|
75
|
+
.map((check) => ` ${check.code}${check.scope === "machine" ? " (this machine)" : ""}: ${check.ok ? "ok" : "failed"}${check.detail === undefined ? "" : ` (${check.detail})`}${check.ok || check.next === undefined ? "" : `; next: ${check.next}`}\n`)
|
|
76
76
|
.join("")}`;
|
|
77
77
|
const readLifecycle = (dependencies) => Effect.map(Effect.option(Effect.map(Effect.suspend(() => dependencies.readStatus()), (node) => node.lifecycle)), Option.getOrUndefined);
|
|
78
78
|
const nodeCheck = (lifecycle) => lifecycle === undefined
|
|
@@ -100,8 +100,14 @@ export const runDoctor = (tokens, context) => Effect.gen(function* () {
|
|
|
100
100
|
const checks = yield* readChecks(context);
|
|
101
101
|
const ok = checks.every((check) => check.ok);
|
|
102
102
|
const result = {
|
|
103
|
-
checks
|
|
103
|
+
checks: checks.map((check) => ({
|
|
104
|
+
...check,
|
|
105
|
+
scope: check.code === "cli" ? "machine" : "node",
|
|
106
|
+
})),
|
|
104
107
|
command: "doctor",
|
|
108
|
+
...(context.node === undefined || context.node === LOCAL_NODE
|
|
109
|
+
? {}
|
|
110
|
+
: { node: context.node }),
|
|
105
111
|
ok,
|
|
106
112
|
version: context.version,
|
|
107
113
|
};
|
|
@@ -2,6 +2,7 @@ import type { LocalNodeStatusResult } from "@maiaos/sdk";
|
|
|
2
2
|
export declare const sumObservationWarningTrees: (observations: LocalNodeStatusResult["processResources"]["observations"]) => number;
|
|
3
3
|
export type CliCompactStatusResult = {
|
|
4
4
|
readonly command: "status";
|
|
5
|
+
readonly executorHost?: LocalNodeStatusResult["executorHost"];
|
|
5
6
|
readonly instanceId: LocalNodeStatusResult["instanceId"];
|
|
6
7
|
readonly lifecycle: LocalNodeStatusResult["lifecycle"];
|
|
7
8
|
readonly pid: LocalNodeStatusResult["pid"];
|
|
@@ -26,6 +26,9 @@ const projectStatusCapability = (capability) => ({
|
|
|
26
26
|
});
|
|
27
27
|
export const projectStatusResult = (node) => ({
|
|
28
28
|
command: "status",
|
|
29
|
+
...(node.executorHost === undefined
|
|
30
|
+
? {}
|
|
31
|
+
: { executorHost: node.executorHost }),
|
|
29
32
|
instanceId: node.instanceId,
|
|
30
33
|
lifecycle: node.lifecycle,
|
|
31
34
|
pid: node.pid,
|
|
@@ -3,5 +3,5 @@ export type CliStatusResult = {
|
|
|
3
3
|
readonly command: "status";
|
|
4
4
|
readonly node: LocalNodeStatusResult;
|
|
5
5
|
};
|
|
6
|
-
export declare const formatHumanStatus: (
|
|
6
|
+
export declare const formatHumanStatus: ({ node }: CliStatusResult) => string;
|
|
7
7
|
//# sourceMappingURL=human.d.ts.map
|
|
@@ -8,23 +8,80 @@ const processResourceNextStep = (nextStep) => {
|
|
|
8
8
|
return "inspect per-tree pressure warnings; termination stays disabled";
|
|
9
9
|
case "none":
|
|
10
10
|
return "none";
|
|
11
|
+
case "run_node_in_delegated_cgroup":
|
|
12
|
+
return "restart the Node in a cgroup delegated to its user: a systemd user unit with Delegate=yes and DelegateSubgroup=node, or systemd-run --user -p Delegate=yes -p DelegateSubgroup=node";
|
|
11
13
|
case "verify_native_host":
|
|
12
14
|
return "verify the native process host";
|
|
13
15
|
}
|
|
14
16
|
};
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const OBSERVED_METRICS = [
|
|
18
|
+
["cpu-ms", "cpuTimeMilliseconds"],
|
|
19
|
+
["rss-bytes", "rssBytes"],
|
|
20
|
+
["peak-rss-bytes", "observedPeakRssBytes"],
|
|
21
|
+
["processes", "processCount"],
|
|
22
|
+
["fds", "fileDescriptorCount"],
|
|
23
|
+
["io-read-bytes", "ioReadBytes"],
|
|
24
|
+
["io-write-bytes", "ioWriteBytes"],
|
|
25
|
+
];
|
|
26
|
+
const formatMetric = (label, metric, trees) => {
|
|
27
|
+
const parts = [
|
|
28
|
+
metric.maximumValue === undefined
|
|
29
|
+
? ""
|
|
30
|
+
: `max ${String(metric.maximumValue)}`,
|
|
31
|
+
metric.unavailableTrees === 0
|
|
32
|
+
? ""
|
|
33
|
+
: `${String(metric.unavailableTrees)} of ${String(trees)} unmeasured`,
|
|
34
|
+
metric.warningTrees === 0 ? "" : `${String(metric.warningTrees)} warning`,
|
|
35
|
+
].filter(Boolean);
|
|
36
|
+
return metric.budget === "declared_per_tree_limit" && parts.length > 0
|
|
37
|
+
? [`${label} ${parts.join(", ")}`]
|
|
38
|
+
: [];
|
|
39
|
+
};
|
|
40
|
+
const processResourceLines = ({ admission, capability, cleanupUnknownTrees, fencedTrees, nextStep, observations, pressure, }) => {
|
|
41
|
+
const measured = OBSERVED_METRICS.flatMap(([label, key]) => formatMetric(label, observations[key], observations.treeCount));
|
|
42
|
+
return [
|
|
43
|
+
`process resources: ${pressure} (${capability.mode}; hard limits ${capability.hardLimitEnforcement})`,
|
|
44
|
+
`capacity: ${String(admission.usedTrees)}/${String(admission.capacity)} process trees in use${admission.state === "available" ? "" : `; ${admission.state}`}`,
|
|
45
|
+
...(cleanupUnknownTrees === 0
|
|
46
|
+
? []
|
|
47
|
+
: [
|
|
48
|
+
`ownership: ${String(fencedTrees)} fenced; ${String(cleanupUnknownTrees)} cleanup unknown`,
|
|
49
|
+
]),
|
|
50
|
+
`observations: ${measured.length === 0 ? "none yet" : measured.join("; ")}`,
|
|
51
|
+
...(nextStep === "none"
|
|
52
|
+
? []
|
|
53
|
+
: [`next step: ${processResourceNextStep(nextStep)}`]),
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
const BOTH = "refuses Codex and coding Claude Code Sessions";
|
|
57
|
+
const CODING_CLAUDE = "refuses coding Claude Code Sessions";
|
|
58
|
+
const executorHostLines = (host) => {
|
|
59
|
+
if (host === undefined)
|
|
60
|
+
return [];
|
|
61
|
+
const userNamespaces = {
|
|
62
|
+
allowed: "user namespaces: allowed",
|
|
63
|
+
["no_nesting"]: `user namespaces: no_nesting (${CODING_CLAUDE}); next step: the owner sets kernel.apparmor_restrict_unprivileged_userns=0 and stops enforcing the unpriv_bwrap AppArmor profile`,
|
|
64
|
+
restricted: `user namespaces: restricted (${BOTH}); next step: the owner sets kernel.apparmor_restrict_unprivileged_userns=0`,
|
|
65
|
+
};
|
|
66
|
+
return [
|
|
67
|
+
host.bubblewrap === "found"
|
|
68
|
+
? "bubblewrap: found"
|
|
69
|
+
: `bubblewrap: missing (${BOTH}); next step: the owner installs the bubblewrap package`,
|
|
70
|
+
host.socat === "found"
|
|
71
|
+
? "socat: found"
|
|
72
|
+
: `socat: missing (${CODING_CLAUDE}); next step: the owner installs the socat package`,
|
|
73
|
+
userNamespaces[host.userNamespaces],
|
|
74
|
+
];
|
|
75
|
+
};
|
|
76
|
+
export const formatHumanStatus = ({ node }) => {
|
|
77
|
+
const lines = [
|
|
78
|
+
`profile: ${node.profile}`,
|
|
79
|
+
`pid: ${String(node.pid)}`,
|
|
80
|
+
`instance: ${node.instanceId}`,
|
|
81
|
+
`storage: ${node.storage.integrity} (${node.storage.journalMode})`,
|
|
82
|
+
...processResourceLines(node.processResources),
|
|
83
|
+
...executorHostLines(node.executorHost),
|
|
84
|
+
];
|
|
85
|
+
return `Maia node ${node.lifecycle}\n${lines.map((line) => ` ${line}\n`).join("")}`;
|
|
29
86
|
};
|
|
30
87
|
//# sourceMappingURL=human.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ProtocolError, type TeamWorkspaceBootstrapPreviewParameters } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Ref from "effect/Ref";
|
|
4
|
+
import { CliArgumentError, type CliDependencies, type CommandContext } from "../command-line/index.js";
|
|
5
|
+
import type { CliMutationRecovery } from "../local-node/index.js";
|
|
6
|
+
import type { BootstrapNode } from "./launcher.js";
|
|
7
|
+
export type BootstrapDependencies = Required<Pick<CliDependencies, "applyBootstrap" | "confirmOnTerminal" | "getReceipt" | "previewBootstrap" | "startBootstrapNode">>;
|
|
8
|
+
export type Ceremony = {
|
|
9
|
+
readonly context: CommandContext;
|
|
10
|
+
readonly dependencies: BootstrapDependencies;
|
|
11
|
+
readonly node: BootstrapNode;
|
|
12
|
+
readonly parameters: TeamWorkspaceBootstrapPreviewParameters;
|
|
13
|
+
readonly profile: string;
|
|
14
|
+
readonly sent: Ref.Ref<boolean>;
|
|
15
|
+
};
|
|
16
|
+
export declare const nodeUnavailable: (message: string) => ProtocolError;
|
|
17
|
+
export declare const recoveryFor: ({ parameters, profile, }: Pick<Ceremony, "parameters" | "profile">) => CliMutationRecovery;
|
|
18
|
+
export declare const runCeremony: (ceremony: Ceremony) => Effect.Effect<number, CliArgumentError, import("effect/Crypto").Crypto>;
|
|
19
|
+
//# sourceMappingURL=ceremony.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { TEAM_WORKSPACE_BOOTSTRAP_PREVIEW_TTL_MILLISECONDS, teamWorkspaceBootstrapApplyResultSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Predicate from "effect/Predicate";
|
|
4
|
+
import * as Ref from "effect/Ref";
|
|
5
|
+
import * as Schedule from "effect/Schedule";
|
|
6
|
+
import { CliArgumentError, EXIT_CANCELLED, reportError, writeNodeResult, } from "../command-line/index.js";
|
|
7
|
+
import { confirmationFrame, confirmationPhrase } from "./confirmation.js";
|
|
8
|
+
import { describePreview, formatBootstrapOutput, toBootstrapOutput, } from "./output.js";
|
|
9
|
+
const READY_DEADLINE = "30 seconds";
|
|
10
|
+
const READY_INTERVAL = "100 millis";
|
|
11
|
+
const DEFINITE_REFUSALS = new Set([
|
|
12
|
+
"bootstrap_authority_unavailable",
|
|
13
|
+
"bootstrap_binding_mismatch",
|
|
14
|
+
"bootstrap_confirmation_required",
|
|
15
|
+
"bootstrap_preview_expired",
|
|
16
|
+
]);
|
|
17
|
+
const RESERVED_IDENTIFIERS = [
|
|
18
|
+
"clientId",
|
|
19
|
+
"deviceId",
|
|
20
|
+
"nodeId",
|
|
21
|
+
"teamWorkspaceId",
|
|
22
|
+
"userId",
|
|
23
|
+
];
|
|
24
|
+
export const nodeUnavailable = (message) => ({
|
|
25
|
+
code: "node_unavailable",
|
|
26
|
+
message,
|
|
27
|
+
retryable: true,
|
|
28
|
+
});
|
|
29
|
+
const failed = (error) => ({
|
|
30
|
+
error,
|
|
31
|
+
ok: false,
|
|
32
|
+
});
|
|
33
|
+
const integrityFailed = (message) => failed({ code: "bootstrap_integrity_failed", message, retryable: false });
|
|
34
|
+
const previewWhenReady = (ceremony) => Effect.suspend(() => ceremony.dependencies.previewBootstrap(ceremony.parameters)).pipe(Effect.repeat({
|
|
35
|
+
schedule: Schedule.spaced(READY_INTERVAL),
|
|
36
|
+
until: (result) => result.ok || result.error.code !== "node_unavailable",
|
|
37
|
+
}), Effect.timeoutOrElse({
|
|
38
|
+
duration: READY_DEADLINE,
|
|
39
|
+
orElse: () => Effect.succeed(failed(nodeUnavailable("The Node did not become ready in 30 seconds."))),
|
|
40
|
+
}));
|
|
41
|
+
const askPerson = (ceremony, preview) => ceremony.dependencies
|
|
42
|
+
.confirmOnTerminal({
|
|
43
|
+
description: describePreview({
|
|
44
|
+
ownerDisplayName: ceremony.parameters.ownerDisplayName,
|
|
45
|
+
preview,
|
|
46
|
+
profile: ceremony.profile,
|
|
47
|
+
workspaceName: ceremony.parameters.workspaceName,
|
|
48
|
+
}),
|
|
49
|
+
expected: confirmationPhrase(preview),
|
|
50
|
+
})
|
|
51
|
+
.pipe(Effect.timeoutOrElse({
|
|
52
|
+
duration: TEAM_WORKSPACE_BOOTSTRAP_PREVIEW_TTL_MILLISECONDS,
|
|
53
|
+
orElse: () => Effect.succeed("expired"),
|
|
54
|
+
}));
|
|
55
|
+
const withoutApproval = (ceremony, answer) => {
|
|
56
|
+
const { context } = ceremony;
|
|
57
|
+
if (answer === "unavailable")
|
|
58
|
+
return Effect.fail(new CliArgumentError("No controlling terminal: run this command in a terminal. A pipe or redirect cannot confirm."));
|
|
59
|
+
if (answer === "expired")
|
|
60
|
+
return Effect.succeed(reportError({
|
|
61
|
+
code: "bootstrap_preview_expired",
|
|
62
|
+
message: "The preview expired before it was confirmed; run the command again.",
|
|
63
|
+
retryable: false,
|
|
64
|
+
}, context));
|
|
65
|
+
return Effect.sync(() => {
|
|
66
|
+
context.io.stderr("Cancelled; nothing changed.\n");
|
|
67
|
+
return EXIT_CANCELLED;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const matchesPreview = (result, preview) => result.commandId === preview.commandId &&
|
|
71
|
+
result.inputDigest === preview.inputDigest &&
|
|
72
|
+
result.previewId === preview.previewId &&
|
|
73
|
+
RESERVED_IDENTIFIERS.every((key) => result[key] === preview[key]);
|
|
74
|
+
const settle = (result, preview) => result.ok && !matchesPreview(result.value, preview)
|
|
75
|
+
? integrityFailed("The Node's result does not match the confirmed preview.")
|
|
76
|
+
: result;
|
|
77
|
+
const recovered = (receipt, preview) => {
|
|
78
|
+
const parsed = Predicate.isObject(receipt.result)
|
|
79
|
+
? teamWorkspaceBootstrapApplyResultSchema.safeParse({
|
|
80
|
+
...receipt.result,
|
|
81
|
+
receipt: receipt.receipt,
|
|
82
|
+
})
|
|
83
|
+
: { success: false };
|
|
84
|
+
return parsed.success
|
|
85
|
+
? settle({ ok: true, value: parsed.data }, preview)
|
|
86
|
+
: integrityFailed("The stored receipt is not this bootstrap's result.");
|
|
87
|
+
};
|
|
88
|
+
const afterRetry = (result, unknown) => {
|
|
89
|
+
if (result.ok)
|
|
90
|
+
return result;
|
|
91
|
+
const { code } = result.error;
|
|
92
|
+
if (code === "bootstrap_already_completed")
|
|
93
|
+
return integrityFailed("The Node is owned but holds no receipt for this command; bootstrap is not repeated.");
|
|
94
|
+
return DEFINITE_REFUSALS.has(code) ? result : unknown;
|
|
95
|
+
};
|
|
96
|
+
const applyParametersFor = (parameters, preview) => ({
|
|
97
|
+
...parameters,
|
|
98
|
+
inputDigest: preview.inputDigest,
|
|
99
|
+
previewId: preview.previewId,
|
|
100
|
+
});
|
|
101
|
+
const reconcile = (ceremony, preview, unknown) => Effect.gen(function* () {
|
|
102
|
+
const { dependencies, parameters } = ceremony;
|
|
103
|
+
const receipt = yield* Effect.suspend(() => dependencies.getReceipt(parameters.commandId));
|
|
104
|
+
if (receipt.ok)
|
|
105
|
+
return recovered(receipt.value, preview);
|
|
106
|
+
if (receipt.error.code !== "resource_not_found")
|
|
107
|
+
return unknown;
|
|
108
|
+
const retried = yield* Effect.suspend(() => dependencies.applyBootstrap(applyParametersFor(parameters, preview)));
|
|
109
|
+
return settle(afterRetry(retried, unknown), preview);
|
|
110
|
+
});
|
|
111
|
+
const applyOnce = (ceremony, preview) => Effect.suspend(() => ceremony.dependencies.applyBootstrap(applyParametersFor(ceremony.parameters, preview))).pipe(Effect.flatMap((result) => !result.ok && result.error.code === "outcome_unknown"
|
|
112
|
+
? reconcile(ceremony, preview, result)
|
|
113
|
+
: Effect.succeed(settle(result, preview))));
|
|
114
|
+
export const recoveryFor = ({ parameters, profile, }) => ({
|
|
115
|
+
commandId: parameters.commandId,
|
|
116
|
+
profile,
|
|
117
|
+
});
|
|
118
|
+
const withRecovery = (result, ceremony) => !result.ok && result.recovery !== undefined
|
|
119
|
+
? { ...result, recovery: recoveryFor(ceremony) }
|
|
120
|
+
: result;
|
|
121
|
+
const confirmAndApply = (ceremony, preview) => ceremony.node.sendConfirmation(confirmationFrame(preview)).pipe(Effect.matchEffect({
|
|
122
|
+
onFailure: (error) => Effect.succeed(reportError({
|
|
123
|
+
code: "bootstrap_channel_invalid",
|
|
124
|
+
message: error.message,
|
|
125
|
+
retryable: false,
|
|
126
|
+
}, ceremony.context)),
|
|
127
|
+
onSuccess: () => Ref.set(ceremony.sent, true).pipe(Effect.andThen(applyOnce(ceremony, preview)), Effect.map((result) => writeNodeResult(withRecovery(result, ceremony), ceremony.context, {
|
|
128
|
+
toResult: toBootstrapOutput,
|
|
129
|
+
toText: formatBootstrapOutput,
|
|
130
|
+
}))),
|
|
131
|
+
}));
|
|
132
|
+
export const runCeremony = (ceremony) => Effect.gen(function* () {
|
|
133
|
+
const previewed = yield* previewWhenReady(ceremony);
|
|
134
|
+
if (!previewed.ok)
|
|
135
|
+
return reportError(previewed.error, ceremony.context);
|
|
136
|
+
const answer = yield* askPerson(ceremony, previewed.value);
|
|
137
|
+
return answer === "confirmed"
|
|
138
|
+
? yield* confirmAndApply(ceremony, previewed.value)
|
|
139
|
+
: yield* withoutApproval(ceremony, answer);
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=ceremony.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type TeamWorkspaceBootstrapApplyParameters, type TeamWorkspaceBootstrapPreviewParameters } from "@maiaos/sdk";
|
|
2
|
+
import type { CliNodeOperations } from "../local-node/index.js";
|
|
3
|
+
export declare const makeBootstrapClient: (node: CliNodeOperations) => {
|
|
4
|
+
applyBootstrap: (input: TeamWorkspaceBootstrapApplyParameters) => import("../local-node/client.js").CliNodeEffect<{
|
|
5
|
+
readonly clientId: string;
|
|
6
|
+
readonly deviceId: string;
|
|
7
|
+
readonly nodeId: string;
|
|
8
|
+
readonly teamWorkspaceId: string;
|
|
9
|
+
readonly userId: string;
|
|
10
|
+
readonly authoritySource: "local-os-profile-owner";
|
|
11
|
+
readonly bootstrapRevision: "1";
|
|
12
|
+
readonly commandId: string;
|
|
13
|
+
readonly delivery: "duplicate" | "new";
|
|
14
|
+
readonly inputDigest: string;
|
|
15
|
+
readonly method: "team-workspace.bootstrap.apply";
|
|
16
|
+
readonly previewId: string;
|
|
17
|
+
readonly receipt: {
|
|
18
|
+
readonly actorId: string;
|
|
19
|
+
readonly aggregateRevision: string;
|
|
20
|
+
readonly commandId: string;
|
|
21
|
+
readonly createdAt: string;
|
|
22
|
+
readonly eventCursor: string;
|
|
23
|
+
readonly method: string;
|
|
24
|
+
readonly receiptId: string;
|
|
25
|
+
readonly schemaVersion: 1;
|
|
26
|
+
readonly state: "succeeded";
|
|
27
|
+
readonly target: {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly type: string;
|
|
30
|
+
};
|
|
31
|
+
readonly updatedAt: string;
|
|
32
|
+
};
|
|
33
|
+
readonly releaseQualified: false;
|
|
34
|
+
readonly role: "owner";
|
|
35
|
+
readonly schemaVersion: 1;
|
|
36
|
+
}>;
|
|
37
|
+
previewBootstrap: (input: TeamWorkspaceBootstrapPreviewParameters) => import("../local-node/client.js").CliNodeEffect<{
|
|
38
|
+
readonly clientId: string;
|
|
39
|
+
readonly deviceId: string;
|
|
40
|
+
readonly nodeId: string;
|
|
41
|
+
readonly teamWorkspaceId: string;
|
|
42
|
+
readonly userId: string;
|
|
43
|
+
readonly authoritySource: "local-os-profile-owner";
|
|
44
|
+
readonly commandId: string;
|
|
45
|
+
readonly expectedBootstrapRevision: "0";
|
|
46
|
+
readonly expiresAt: string;
|
|
47
|
+
readonly inputDigest: string;
|
|
48
|
+
readonly issuedAt: string;
|
|
49
|
+
readonly method: "team-workspace.bootstrap.preview";
|
|
50
|
+
readonly nodeEpoch: string;
|
|
51
|
+
readonly previewId: string;
|
|
52
|
+
readonly releaseQualified: false;
|
|
53
|
+
readonly role: "owner";
|
|
54
|
+
readonly schemaVersion: 1;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
export type BootstrapClientDependencies = ReturnType<typeof makeBootstrapClient>;
|
|
58
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { teamWorkspaceBootstrapApplyParametersSchema, teamWorkspaceBootstrapPreviewParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
export const makeBootstrapClient = (node) => ({
|
|
3
|
+
applyBootstrap: (input) => node.runValidatedNodeOperation(input, teamWorkspaceBootstrapApplyParametersSchema, (client, parameters, options) => client.applyTeamWorkspaceBootstrap(parameters, options), { commandId: input.commandId }),
|
|
4
|
+
previewBootstrap: (input) => node.runValidatedNodeOperation(input, teamWorkspaceBootstrapPreviewParametersSchema, (client, parameters, options) => client.previewTeamWorkspaceBootstrap(parameters, options)),
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { TEAM_WORKSPACE_BOOTSTRAP_SCHEMA_VERSION, teamWorkspaceBootstrapPreviewParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Ref from "effect/Ref";
|
|
4
|
+
import { CliArgumentError, parseOptions, reportError, requirePositionals, } from "../command-line/index.js";
|
|
5
|
+
import { commandIdentifier } from "../local-node/index.js";
|
|
6
|
+
import { nodeUnavailable, recoveryFor, runCeremony, } from "./ceremony.js";
|
|
7
|
+
const OPTIONS = new Set(["--command-id", "--owner-name", "--workspace-name"]);
|
|
8
|
+
const requiredOption = (options, name) => {
|
|
9
|
+
const value = options.get(name);
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new CliArgumentError(`Option '${name}' is required.`);
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
const requiredProfile = (context) => {
|
|
15
|
+
if (context.profile === undefined)
|
|
16
|
+
throw new CliArgumentError("Option '--profile' is required: it names the profile whose Node this command starts.");
|
|
17
|
+
return context.profile;
|
|
18
|
+
};
|
|
19
|
+
const requireTerminalSession = (context) => {
|
|
20
|
+
if (context.io.interactive !== true)
|
|
21
|
+
throw new CliArgumentError("A person must confirm at a terminal: run this with standard input and error attached to a terminal and without '--no-input'.");
|
|
22
|
+
};
|
|
23
|
+
const readRequest = (tokens, context) => {
|
|
24
|
+
const parsed = parseOptions(tokens, OPTIONS);
|
|
25
|
+
requirePositionals(parsed.positionals, 0);
|
|
26
|
+
const profile = requiredProfile(context);
|
|
27
|
+
requireTerminalSession(context);
|
|
28
|
+
const commandId = parsed.options.get("--command-id");
|
|
29
|
+
return {
|
|
30
|
+
...(commandId === undefined ? {} : { commandId }),
|
|
31
|
+
ownerDisplayName: requiredOption(parsed.options, "--owner-name"),
|
|
32
|
+
profile,
|
|
33
|
+
workspaceName: requiredOption(parsed.options, "--workspace-name"),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const requireDependencies = (context) => {
|
|
37
|
+
const { applyBootstrap, confirmOnTerminal, getReceipt, previewBootstrap, startBootstrapNode, } = context.dependencies;
|
|
38
|
+
if (applyBootstrap === undefined ||
|
|
39
|
+
confirmOnTerminal === undefined ||
|
|
40
|
+
previewBootstrap === undefined ||
|
|
41
|
+
startBootstrapNode === undefined)
|
|
42
|
+
throw new CliArgumentError("This CLI cannot bootstrap a Node.");
|
|
43
|
+
return {
|
|
44
|
+
applyBootstrap,
|
|
45
|
+
confirmOnTerminal,
|
|
46
|
+
getReceipt,
|
|
47
|
+
previewBootstrap,
|
|
48
|
+
startBootstrapNode,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const previewParametersFor = (request) => Effect.gen(function* () {
|
|
52
|
+
const parsed = teamWorkspaceBootstrapPreviewParametersSchema.safeParse({
|
|
53
|
+
commandId: yield* commandIdentifier(request.commandId),
|
|
54
|
+
expectedBootstrapRevision: "0",
|
|
55
|
+
ownerDisplayName: request.ownerDisplayName,
|
|
56
|
+
schemaVersion: TEAM_WORKSPACE_BOOTSTRAP_SCHEMA_VERSION,
|
|
57
|
+
workspaceName: request.workspaceName,
|
|
58
|
+
});
|
|
59
|
+
return parsed.success
|
|
60
|
+
? parsed.data
|
|
61
|
+
: yield* new CliArgumentError("The bootstrap input is invalid: a name is 1 to 160 UTF-8 bytes of NFC text without control characters or edge whitespace, and '--command-id' is a protocol identifier.");
|
|
62
|
+
});
|
|
63
|
+
const reportExit = (node, ceremony) => node.exited.pipe(Effect.catch((error) => Effect.map(Ref.get(ceremony.sent), (confirmed) => reportError(nodeUnavailable(error.message), {
|
|
64
|
+
...ceremony.context,
|
|
65
|
+
...(confirmed ? { recovery: recoveryFor(ceremony) } : {}),
|
|
66
|
+
}))));
|
|
67
|
+
const supervise = (plan) => plan.dependencies.startBootstrapNode(plan.profile).pipe(Effect.matchEffect({
|
|
68
|
+
onFailure: (error) => Effect.succeed(reportError(nodeUnavailable(error.message), plan.context)),
|
|
69
|
+
onSuccess: (node) => Effect.flatMap(Ref.make(false), (sent) => {
|
|
70
|
+
const ceremony = { ...plan, node, sent };
|
|
71
|
+
return Effect.raceFirst(runCeremony(ceremony), reportExit(node, ceremony));
|
|
72
|
+
}),
|
|
73
|
+
}));
|
|
74
|
+
const plan = (request, context, parameters) => ({
|
|
75
|
+
context,
|
|
76
|
+
dependencies: requireDependencies(context),
|
|
77
|
+
parameters,
|
|
78
|
+
profile: request.profile,
|
|
79
|
+
});
|
|
80
|
+
export const runNodeBootstrap = (tokens, context) => Effect.gen(function* () {
|
|
81
|
+
const request = readRequest(tokens, context);
|
|
82
|
+
const parameters = yield* previewParametersFor(request);
|
|
83
|
+
return yield* Effect.scoped(supervise(plan(request, context, parameters)));
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TeamWorkspaceBootstrapPreviewResult } from "@maiaos/sdk";
|
|
2
|
+
export declare const confirmationFrame: (preview: Pick<TeamWorkspaceBootstrapPreviewResult, "commandId" | "inputDigest" | "nodeEpoch" | "previewId">) => string;
|
|
3
|
+
export declare const confirmationPhrase: (preview: Pick<TeamWorkspaceBootstrapPreviewResult, "previewId">) => string;
|
|
4
|
+
//# sourceMappingURL=confirmation.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const confirmationFrame = (preview) => JSON.stringify({
|
|
2
|
+
commandId: preview.commandId,
|
|
3
|
+
inputDigest: preview.inputDigest,
|
|
4
|
+
nodeEpoch: preview.nodeEpoch,
|
|
5
|
+
previewId: preview.previewId,
|
|
6
|
+
});
|
|
7
|
+
export const confirmationPhrase = (preview) => `YES ${preview.previewId}`;
|
|
8
|
+
//# sourceMappingURL=confirmation.js.map
|