@maiaos/cli 0.1.0-canary.2 → 0.1.0-canary.4
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/cli/cli.js +76 -13
- package/dist/command-line/context.d.ts +13 -4
- package/dist/command-line/context.js +1 -1
- package/dist/command-line/index.d.ts +5 -5
- package/dist/command-line/index.js +5 -4
- package/dist/command-line/input/index.d.ts +1 -1
- package/dist/command-line/input/index.js +1 -1
- 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 +8 -4
- package/dist/local-node/client.js +20 -9
- package/dist/local-node/index.d.ts +1 -1
- package/dist/local-node/index.js +1 -1
- package/dist/login/commands.js +2 -1
- package/dist/mcp/calls.d.ts +1 -0
- package/dist/mcp/calls.js +36 -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 +20 -17
- 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 +46 -25
- 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 +24 -6
- 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 +4 -2
- package/dist/session/client.js +4 -15
- package/dist/session/commands.js +76 -9
- package/dist/session/create-tasks.js +29 -11
- package/dist/session/index.d.ts +1 -1
- package/dist/session/index.js +1 -0
- 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.js +21 -10
- package/dist/session/output/index.d.ts +1 -1
- package/dist/session/output/index.js +1 -1
- package/dist/session/output/tasks.d.ts +16 -1
- package/dist/session/output/tasks.js +41 -27
- package/dist/session/tree/tree.js +56 -8
- package/dist/session/turn/client.d.ts +4 -1
- package/dist/session/turn/client.js +15 -2
- package/dist/session/turn/commands.d.ts +2 -0
- package/dist/session/turn/commands.js +38 -5
- 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/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/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 +15 -15
- package/package.json +10 -8
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import { CliArgumentError, reportError, requireNoArguments, writeSuccess, } from "../command-line/index.js";
|
|
6
|
+
import { frameLines, plainLines } from "./frame.js";
|
|
7
|
+
import { loadPiTui } from "./pi-tui.js";
|
|
8
|
+
import { DashboardTerminal, terminalLayer, } from "./terminal.js";
|
|
9
|
+
const DEFAULT_PROFILE = "default";
|
|
10
|
+
const profileOf = ({ profile }) => profile ?? DEFAULT_PROFILE;
|
|
11
|
+
const screenOf = (context) => ({
|
|
12
|
+
quitKeys: ["q", "ctrl+c"],
|
|
13
|
+
render: (size) => frameLines(profileOf(context), size),
|
|
14
|
+
});
|
|
15
|
+
const refuseSession = (context) => reportError({
|
|
16
|
+
code: "role_denied",
|
|
17
|
+
message: "The dashboard is for a person at a terminal, not a Session.",
|
|
18
|
+
retryable: false,
|
|
19
|
+
}, context);
|
|
20
|
+
const printPlain = (context) => {
|
|
21
|
+
const profile = profileOf(context);
|
|
22
|
+
writeSuccess({ command: "dashboard", profile }, context, () => `${plainLines(profile).join("\n")}\n`);
|
|
23
|
+
return 0;
|
|
24
|
+
};
|
|
25
|
+
const reportFailure = (error, context) => error.reason === "no-terminal"
|
|
26
|
+
? Effect.fail(new CliArgumentError("The dashboard needs a terminal on standard input and output; pass --plain for plain text."))
|
|
27
|
+
: Effect.succeed(reportError({
|
|
28
|
+
code: "internal_error",
|
|
29
|
+
message: error.reason === "missing"
|
|
30
|
+
? "The dashboard cannot load its terminal library; next: reinstall Maia."
|
|
31
|
+
: "The dashboard failed while drawing; the terminal was restored.",
|
|
32
|
+
retryable: false,
|
|
33
|
+
}, context));
|
|
34
|
+
export const showScreen = (screen, context) => DashboardTerminal.use((terminal) => terminal.run(screen)).pipe(Effect.catchTag("TerminalFailure", (error) => reportFailure(error, context)));
|
|
35
|
+
export const showDashboard = (tokens, context) => Effect.gen(function* () {
|
|
36
|
+
const credential = yield* Effect.orDie(Config.option(Config.String("MAIA_SESSION_CREDENTIAL")));
|
|
37
|
+
if (Option.isSome(credential))
|
|
38
|
+
return refuseSession(context);
|
|
39
|
+
const plain = tokens[0] === "--plain";
|
|
40
|
+
requireNoArguments(plain ? tokens.slice(1) : tokens, "dashboard");
|
|
41
|
+
return plain
|
|
42
|
+
? printPlain(context)
|
|
43
|
+
: yield* showScreen(screenOf(context), context);
|
|
44
|
+
});
|
|
45
|
+
const processTerminal = terminalLayer(process, loadPiTui());
|
|
46
|
+
export const runDashboard = (tokens, context) => showDashboard(tokens, context).pipe(Effect.provide(processTerminal));
|
|
47
|
+
//# sourceMappingURL=dashboard.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Width = (text: string) => number;
|
|
2
|
+
export type Span = readonly [text: string, style?: string];
|
|
3
|
+
export type Draw = {
|
|
4
|
+
readonly clip: (text: string, size: number) => string;
|
|
5
|
+
readonly column: (text: string, size: number) => string;
|
|
6
|
+
readonly columns: number;
|
|
7
|
+
readonly line: (spans: readonly Span[]) => string;
|
|
8
|
+
readonly width: Width;
|
|
9
|
+
};
|
|
10
|
+
export declare const makeDraw: (options: {
|
|
11
|
+
readonly color: boolean;
|
|
12
|
+
readonly columns: number;
|
|
13
|
+
readonly width: Width;
|
|
14
|
+
}) => Draw;
|
|
15
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cell } from "../command-line/index.js";
|
|
2
|
+
const paint = ([text, style]) => style === undefined ? text : `\u001B[${style}m${text}\u001B[0m`;
|
|
3
|
+
const clipWith = (width) => (value, size) => {
|
|
4
|
+
const text = cell(value);
|
|
5
|
+
if (width(text) <= size)
|
|
6
|
+
return text;
|
|
7
|
+
const parts = Array.from(new Intl.Segmenter().segment(text), (part) => part.segment);
|
|
8
|
+
const kept = parts.findIndex((_, index) => width(`${parts.slice(0, index + 1).join("")}~`) > size);
|
|
9
|
+
return size < 1 ? "" : `${parts.slice(0, Math.max(kept, 0)).join("")}~`;
|
|
10
|
+
};
|
|
11
|
+
export const makeDraw = (options) => {
|
|
12
|
+
const { color, columns, width } = options;
|
|
13
|
+
const clip = clipWith(width);
|
|
14
|
+
return {
|
|
15
|
+
clip,
|
|
16
|
+
column: (text, size) => {
|
|
17
|
+
const shown = clip(text, size - 1);
|
|
18
|
+
return `${shown}${" ".repeat(Math.max(0, size - width(shown)))}`;
|
|
19
|
+
},
|
|
20
|
+
columns,
|
|
21
|
+
line: (spans) => {
|
|
22
|
+
const plain = spans.map(([text]) => text).join("");
|
|
23
|
+
if (width(plain) > columns)
|
|
24
|
+
return clip(plain, columns);
|
|
25
|
+
return color ? spans.map(paint).join("") : plain;
|
|
26
|
+
},
|
|
27
|
+
width,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=draw.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { cell } from "../command-line/index.js";
|
|
2
|
+
import { tooSmall } from "./tree.js";
|
|
3
|
+
const statusLine = (profile) => `Maia dashboard | profile: ${cell(profile)}`;
|
|
4
|
+
const TREE_NOTICE = "The Tree arrives in a later version.";
|
|
5
|
+
export const plainLines = (profile) => [
|
|
6
|
+
statusLine(profile),
|
|
7
|
+
TREE_NOTICE,
|
|
8
|
+
];
|
|
9
|
+
export const frameLines = (profile, size) => {
|
|
10
|
+
const small = tooSmall(size);
|
|
11
|
+
return small === undefined
|
|
12
|
+
? [`${statusLine(profile)} | q quits`, TREE_NOTICE]
|
|
13
|
+
: [small];
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=frame.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type ModeLedger = readonly string[];
|
|
2
|
+
export declare const NO_MODES: ModeLedger;
|
|
3
|
+
export declare const observe: (ledger: ModeLedger, chunk: string) => ModeLedger;
|
|
4
|
+
export declare const resetBytes: (ledger: ModeLedger) => string;
|
|
5
|
+
//# sourceMappingURL=modes.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const MODES = [
|
|
2
|
+
["\u001B[?1049h", "\u001B[?1049l"],
|
|
3
|
+
["\u001B[?7l", "\u001B[?7h"],
|
|
4
|
+
["\u001B[?25l", "\u001B[?25h"],
|
|
5
|
+
["\u001B[?2004h", "\u001B[?2004l"],
|
|
6
|
+
["\u001B[>7u", "\u001B[<u"],
|
|
7
|
+
["\u001B[>4;2m", "\u001B[>4;0m"],
|
|
8
|
+
];
|
|
9
|
+
export const NO_MODES = [];
|
|
10
|
+
export const observe = (ledger, chunk) => MODES.filter(([on, off]) => {
|
|
11
|
+
const turnedOn = chunk.lastIndexOf(on);
|
|
12
|
+
const turnedOff = chunk.lastIndexOf(off);
|
|
13
|
+
return turnedOn === turnedOff ? ledger.includes(off) : turnedOn > turnedOff;
|
|
14
|
+
}).map(([, off]) => off);
|
|
15
|
+
export const resetBytes = (ledger) => ledger.toReversed().join("");
|
|
16
|
+
//# sourceMappingURL=modes.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MaiaClientError } from "@maiaos/sdk";
|
|
2
|
+
import type * as Crypto from "effect/Crypto";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import type * as Scope from "effect/Scope";
|
|
5
|
+
import type { CliNodeConnection } from "../local-node/index.js";
|
|
6
|
+
export declare const UNANSWERED_BEFORE_LOST = 3;
|
|
7
|
+
export type OpenConnection = (scope: Scope.Scope) => Effect.Effect<CliNodeConnection, unknown, Crypto.Crypto>;
|
|
8
|
+
export declare const noConnection: (reason: "node_connecting" | "node_unreachable", detail?: string) => MaiaClientError;
|
|
9
|
+
export type HeldConnection = {
|
|
10
|
+
readonly current: Effect.Effect<CliNodeConnection, MaiaClientError>;
|
|
11
|
+
readonly heard: (connection: CliNodeConnection, answered: boolean) => Effect.Effect<void>;
|
|
12
|
+
readonly lose: (connection: CliNodeConnection) => Effect.Effect<void>;
|
|
13
|
+
};
|
|
14
|
+
export declare const holdConnection: (open: OpenConnection) => Effect.Effect<HeldConnection, never, Crypto.Crypto | Scope.Scope>;
|
|
15
|
+
//# sourceMappingURL=node-connection.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MaiaClientError } from "@maiaos/sdk";
|
|
2
|
+
import * as Duration from "effect/Duration";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Latch from "effect/Latch";
|
|
5
|
+
import * as Ref from "effect/Ref";
|
|
6
|
+
import * as Schedule from "effect/Schedule";
|
|
7
|
+
const RECONNECT_BACKOFF = Schedule.min([
|
|
8
|
+
Schedule.exponential(Duration.seconds(2)),
|
|
9
|
+
Schedule.spaced(Duration.seconds(30)),
|
|
10
|
+
]);
|
|
11
|
+
export const UNANSWERED_BEFORE_LOST = 3;
|
|
12
|
+
export const noConnection = (reason, detail) => new MaiaClientError("transport_failure", "The Node has no live connection; nothing was sent.", { cause: { reason, ...(detail === undefined ? {} : { detail }) } });
|
|
13
|
+
const ifHeld = (state) => (connection, change) => Effect.asVoid(Effect.flatten(Ref.modify(state, (held) => "connection" in held && held.connection === connection
|
|
14
|
+
? change(held)
|
|
15
|
+
: [Effect.void, held])));
|
|
16
|
+
const view = (state) => {
|
|
17
|
+
const onHeld = ifHeld(state);
|
|
18
|
+
return {
|
|
19
|
+
current: Effect.flatMap(Ref.get(state), (held) => "connection" in held
|
|
20
|
+
? Effect.succeed(held.connection)
|
|
21
|
+
: Effect.fail(held.failure)),
|
|
22
|
+
heard: (connection, answered) => onHeld(connection, (live) => {
|
|
23
|
+
const unanswered = answered ? 0 : live.unanswered + 1;
|
|
24
|
+
return [
|
|
25
|
+
unanswered >= UNANSWERED_BEFORE_LOST ? live.lost.open : Effect.void,
|
|
26
|
+
{ ...live, unanswered },
|
|
27
|
+
];
|
|
28
|
+
}),
|
|
29
|
+
lose: (connection) => onHeld(connection, (live) => [live.lost.open, live]),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const generation = (open, state, attempted) => Effect.scoped(Effect.gen(function* () {
|
|
33
|
+
const connection = yield* Effect.flatMap(Effect.scope, open).pipe(Effect.tapError((error) => Ref.set(state, {
|
|
34
|
+
failure: noConnection("node_unreachable", error instanceof MaiaClientError ? error.message : undefined),
|
|
35
|
+
}).pipe(Effect.andThen(attempted.open))));
|
|
36
|
+
const lost = yield* Latch.make();
|
|
37
|
+
yield* Ref.set(state, { connection, lost, unanswered: 0 });
|
|
38
|
+
yield* attempted.open;
|
|
39
|
+
yield* lost.await;
|
|
40
|
+
yield* Ref.set(state, { failure: noConnection("node_connecting") });
|
|
41
|
+
}));
|
|
42
|
+
export const holdConnection = (open) => Effect.gen(function* () {
|
|
43
|
+
const state = yield* Ref.make({
|
|
44
|
+
failure: noConnection("node_connecting"),
|
|
45
|
+
});
|
|
46
|
+
const attempted = yield* Latch.make();
|
|
47
|
+
yield* Effect.forkScoped(Effect.forever(generation(open, state, attempted).pipe(Effect.retry(RECONNECT_BACKOFF))));
|
|
48
|
+
yield* attempted.await;
|
|
49
|
+
return view(state);
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=node-connection.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as PiTui from "@earendil-works/pi-tui";
|
|
2
|
+
import { type LoadSurface } from "./terminal.js";
|
|
3
|
+
type Library = Pick<typeof PiTui, "isKeyRelease" | "isKeyRepeat" | "matchesKey" | "ProcessTerminal" | "TuiAltScreen">;
|
|
4
|
+
export declare const loadPiTui: (importLibrary?: () => Promise<Library>) => LoadSurface;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=pi-tui.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { constVoid } from "effect/Function";
|
|
3
|
+
import { TerminalFailure } from "./terminal.js";
|
|
4
|
+
const NO_LOG_DIRECTORY = undefined;
|
|
5
|
+
const surfaceOf = (library) => {
|
|
6
|
+
const terminal = new library.ProcessTerminal();
|
|
7
|
+
const tui = new library.TuiAltScreen(terminal, false, NO_LOG_DIRECTORY, {
|
|
8
|
+
mouse: false,
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
drain: () => terminal.drainInput(),
|
|
12
|
+
matches: (input, key) => library.matchesKey(input, key) &&
|
|
13
|
+
!library.isKeyRelease(input) &&
|
|
14
|
+
!library.isKeyRepeat(input),
|
|
15
|
+
show: (paint, onInput) => {
|
|
16
|
+
tui.addChild({ invalidate: constVoid, render: paint });
|
|
17
|
+
tui.addInputListener((input) => {
|
|
18
|
+
onInput(input);
|
|
19
|
+
return { consume: true };
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
size: () => ({ columns: terminal.columns, rows: terminal.rows }),
|
|
23
|
+
start: () => {
|
|
24
|
+
tui.start();
|
|
25
|
+
},
|
|
26
|
+
stop: () => {
|
|
27
|
+
tui.stop({ preserveScreen: true });
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const loadPiTui = (importLibrary = () => import("@earendil-works/pi-tui")) => Effect.tryPromise({
|
|
32
|
+
catch: (cause) => new TerminalFailure({ cause, reason: "missing" }),
|
|
33
|
+
try: importLibrary,
|
|
34
|
+
}).pipe(Effect.map(surfaceOf));
|
|
35
|
+
//# sourceMappingURL=pi-tui.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MAX_ATTENTION_ITEMS } from "@maiaos/client-core/cockpit";
|
|
2
|
+
import { ALARM, attentionStyle, WARNING, } from "./tree-model.js";
|
|
3
|
+
const LIMIT = { label: 12, profile: 16, reason: 16 };
|
|
4
|
+
const isDown = ({ health }) => health === "connecting" || health === "unreachable";
|
|
5
|
+
const reasonOf = (node) => {
|
|
6
|
+
if (node.health === "connecting")
|
|
7
|
+
return node.health;
|
|
8
|
+
if (node.health === "unreachable")
|
|
9
|
+
return node.lastFailure ?? node.health;
|
|
10
|
+
return [
|
|
11
|
+
node.health === "stale" || node.stale ? "stale" : "",
|
|
12
|
+
node.partial ? "partial" : "",
|
|
13
|
+
]
|
|
14
|
+
.filter((reason) => reason !== "")
|
|
15
|
+
.join(",");
|
|
16
|
+
};
|
|
17
|
+
const namesOf = (nodes, draw) => nodes
|
|
18
|
+
.filter((node) => reasonOf(node) !== "")
|
|
19
|
+
.toSorted((left, right) => Number(isDown(right)) - Number(isDown(left)))
|
|
20
|
+
.map((node) => `${draw.clip(node.hostLabel, LIMIT.label)}:${draw.clip(reasonOf(node), LIMIT.reason)}`);
|
|
21
|
+
const listed = (names, room, draw) => {
|
|
22
|
+
const [first, ...rest] = names;
|
|
23
|
+
if (first === undefined)
|
|
24
|
+
return "";
|
|
25
|
+
const used = 1 + draw.width(first);
|
|
26
|
+
const reserve = rest.length > 0 ? ` +${String(rest.length)}`.length : 0;
|
|
27
|
+
return used + reserve > room
|
|
28
|
+
? ` +${String(names.length)}`
|
|
29
|
+
: ` ${first}${listed(rest, room - used, draw)}`;
|
|
30
|
+
};
|
|
31
|
+
const countSpans = ({ nodes, state }, running) => {
|
|
32
|
+
const low = state.partial ||
|
|
33
|
+
state.stale ||
|
|
34
|
+
state.index.coverage === "truncated" ||
|
|
35
|
+
nodes.some(({ health }) => health !== "ready");
|
|
36
|
+
const lost = low || state.attention.length >= MAX_ATTENTION_ITEMS;
|
|
37
|
+
const styled = (style) => state.attention.filter(({ reason }) => attentionStyle(reason) === style)
|
|
38
|
+
.length;
|
|
39
|
+
return [
|
|
40
|
+
["ALM", styled(ALARM), ALARM, lost],
|
|
41
|
+
["WRN", styled(WARNING), WARNING, lost],
|
|
42
|
+
["RUN", running, undefined, low],
|
|
43
|
+
].map(([label, total, style, plus]) => [
|
|
44
|
+
` ${label} ${String(total)}${plus ? "+" : ""}`,
|
|
45
|
+
total > 0 ? style : undefined,
|
|
46
|
+
]);
|
|
47
|
+
};
|
|
48
|
+
export const statusBar = (input, rows, draw) => {
|
|
49
|
+
const { nodes, profile } = input;
|
|
50
|
+
const running = rows.filter(({ children, code }) => children.length === 0 && code === "RUN").length;
|
|
51
|
+
const up = nodes.filter(({ health }) => health === "ready").length;
|
|
52
|
+
const head = [
|
|
53
|
+
[draw.clip(profile, LIMIT.profile)],
|
|
54
|
+
...countSpans(input, running),
|
|
55
|
+
[` NODE ${String(up)}/${String(nodes.length)}`],
|
|
56
|
+
];
|
|
57
|
+
const room = draw.columns - draw.width(head.map(([text]) => text).join(""));
|
|
58
|
+
return [...head, [listed(namesOf(nodes, draw), room, draw)]];
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=status-bar.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { KeyId } from "@earendil-works/pi-tui";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
export type ScreenSize = {
|
|
6
|
+
readonly columns: number;
|
|
7
|
+
readonly rows: number;
|
|
8
|
+
};
|
|
9
|
+
export type Screen = {
|
|
10
|
+
readonly quitKeys: readonly KeyId[];
|
|
11
|
+
readonly render: (size: ScreenSize) => readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export type Surface = {
|
|
14
|
+
readonly drain: () => Promise<void>;
|
|
15
|
+
readonly matches: (input: string, key: KeyId) => boolean;
|
|
16
|
+
readonly show: (paint: () => string[], onInput: (input: string) => void) => void;
|
|
17
|
+
readonly size: () => ScreenSize;
|
|
18
|
+
readonly start: () => void;
|
|
19
|
+
readonly stop: () => void;
|
|
20
|
+
};
|
|
21
|
+
type Write = (chunk: string, callback?: () => void) => unknown;
|
|
22
|
+
export type TerminalHost = {
|
|
23
|
+
readonly env: Readonly<NodeJS.ProcessEnv>;
|
|
24
|
+
readonly kill: (pid: number, signal: "SIGTSTP") => unknown;
|
|
25
|
+
readonly off: (event: string, listener: () => void) => unknown;
|
|
26
|
+
readonly on: (event: string, listener: () => void) => unknown;
|
|
27
|
+
readonly platform: NodeJS.Platform;
|
|
28
|
+
readonly stdin: {
|
|
29
|
+
readonly isTTY?: boolean;
|
|
30
|
+
readonly setRawMode?: (mode: boolean) => unknown;
|
|
31
|
+
};
|
|
32
|
+
readonly stdout: {
|
|
33
|
+
readonly isTTY?: boolean;
|
|
34
|
+
write: Write;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
declare const TerminalFailure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
38
|
+
readonly _tag: "TerminalFailure";
|
|
39
|
+
} & Readonly<A>;
|
|
40
|
+
export declare class TerminalFailure extends TerminalFailure_base<{
|
|
41
|
+
readonly cause?: unknown;
|
|
42
|
+
readonly reason: "callback" | "missing" | "no-terminal";
|
|
43
|
+
}> {
|
|
44
|
+
}
|
|
45
|
+
declare const DashboardTerminal_base: Context.ServiceClass<DashboardTerminal, "maia/cli/DashboardTerminal", {
|
|
46
|
+
readonly run: (screen: Screen) => Effect.Effect<number, TerminalFailure>;
|
|
47
|
+
}>;
|
|
48
|
+
export declare class DashboardTerminal extends DashboardTerminal_base {
|
|
49
|
+
}
|
|
50
|
+
export type LoadSurface = Effect.Effect<Surface, TerminalFailure>;
|
|
51
|
+
export declare const terminalLayer: (host: TerminalHost, load: LoadSurface) => Layer.Layer<DashboardTerminal, never, never>;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -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
|