@maiaos/cli 0.1.0-canary.64 → 0.1.0-canary.66
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/LICENSE +21 -0
- package/README.md +15 -9
- package/dist/address-space/address-space.js +21 -2
- package/dist/address-space/index.js +1 -1
- package/dist/agents/client.d.ts +1 -0
- package/dist/agents/tree/tree.js +3 -3
- package/dist/bin/maia.NOTICES.txt +1 -1
- package/dist/bin/maia.cdx.json +70 -19
- package/dist/bin/maia.mjs +1 -1
- package/dist/board/client.d.ts +27 -0
- package/dist/board/client.js +40 -0
- package/dist/board/commands.d.ts +28 -0
- package/dist/board/commands.js +52 -0
- package/dist/board/index.d.ts +3 -0
- package/dist/board/index.js +3 -0
- package/dist/board/input.js +339 -0
- package/dist/board/output/format.js +175 -0
- package/dist/board/output/index.js +2 -0
- package/dist/board/plan.js +47 -0
- package/dist/board/tree/index.js +2 -0
- package/dist/board/tree/tree.js +161 -0
- package/dist/cli/cli.d.ts +3 -1
- package/dist/cli/cli.js +175 -6
- package/dist/cli/log-level.d.ts +11 -0
- package/dist/cli/log-level.js +14 -0
- package/dist/command-line/context.d.ts +18 -5
- package/dist/command-line/emit/output.d.ts +5 -1
- package/dist/command-line/emit/output.js +13 -5
- package/dist/command-line/index.d.ts +2 -2
- package/dist/command-line/index.js +1 -2
- package/dist/command-line/input/arguments.d.ts +3 -0
- package/dist/command-line/input/arguments.js +12 -0
- package/dist/command-line/input/index.d.ts +2 -2
- package/dist/command-line/input/index.js +2 -2
- package/dist/command-line/input/prompt.d.ts +1 -0
- package/dist/command-line/input/prompt.js +1 -0
- package/dist/command-line/two-phase/two-phase.d.ts +4 -4
- package/dist/command-line/two-phase/two-phase.js +9 -9
- package/dist/command-tree/commands.js +0 -4
- package/dist/command-tree/deprecated.d.ts +2 -0
- package/dist/command-tree/deprecated.js +29 -0
- package/dist/command-tree/grammar.js +2 -0
- package/dist/command-tree/help.d.ts +2 -2
- package/dist/command-tree/help.js +13 -15
- package/dist/command-tree/index.d.ts +1 -0
- package/dist/command-tree/index.js +1 -0
- package/dist/command-tree/local.js +10 -5
- package/dist/command-tree/placeholder.js +1 -1
- package/dist/command-tree/row.d.ts +1 -0
- package/dist/command-tree/tree.d.ts +2 -1
- package/dist/command-tree/tree.js +30 -4
- package/dist/connection/client.d.ts +36 -18
- package/dist/connection/client.js +1 -0
- package/dist/connection/executors/executors.d.ts +18 -0
- package/dist/connection/executors/executors.js +95 -0
- package/dist/connection/executors/index.d.ts +2 -0
- package/dist/connection/executors/index.js +2 -0
- package/dist/connection/executors/reading.js +22 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/connection/index.js +1 -0
- package/dist/connection/input.js +2 -2
- package/dist/connection/login.d.ts +1 -1
- package/dist/connection/login.js +4 -3
- package/dist/connection/output/format.js +2 -2
- package/dist/connection/output/index.d.ts +1 -1
- package/dist/connection/output/index.js +1 -1
- package/dist/connection/resolve.d.ts +1 -0
- package/dist/connection/setup-file.js +161 -0
- package/dist/connection/system.js +90 -45
- package/dist/connection/tree/tree.js +120 -7
- package/dist/container/client.d.ts +2 -0
- package/dist/fleet/fleet.d.ts +7 -8
- package/dist/fleet/fleet.js +18 -6
- package/dist/fleet/index.d.ts +1 -1
- package/dist/fleet/index.js +1 -1
- package/dist/github/client.d.ts +189 -0
- package/dist/github/client.js +16 -0
- package/dist/github/commands.d.ts +17 -0
- package/dist/github/commands.js +81 -0
- package/dist/github/index.d.ts +3 -0
- package/dist/github/index.js +3 -0
- package/dist/github/input.js +114 -0
- package/dist/github/output/format.js +78 -0
- package/dist/github/output/index.js +2 -0
- package/dist/github/tree/index.js +2 -0
- package/dist/github/tree/tree.js +28 -0
- package/dist/goal/client.d.ts +246 -0
- package/dist/goal/client.js +13 -0
- package/dist/goal/commands.d.ts +22 -0
- package/dist/goal/commands.js +110 -0
- package/dist/goal/index.d.ts +4 -0
- package/dist/goal/index.js +4 -0
- package/dist/goal/input.js +118 -0
- package/dist/goal/output/format.js +29 -0
- package/dist/goal/output/index.js +2 -0
- package/dist/goal/pause.d.ts +16 -0
- package/dist/goal/pause.js +91 -0
- package/dist/goal/tree/index.js +2 -0
- package/dist/goal/tree/tree.js +49 -0
- package/dist/hold/client.d.ts +2 -0
- package/dist/hold/tree/tree.js +2 -2
- package/dist/import/{batch.js → batch/batch.js} +5 -5
- package/dist/import/batch/index.js +3 -0
- package/dist/import/{manifest.js → batch/manifest.js} +7 -6
- package/dist/import/commands.d.ts +1 -0
- package/dist/import/commands.js +27 -15
- package/dist/import/detach.d.ts +12 -0
- package/dist/import/detach.js +70 -0
- package/dist/import/index.d.ts +2 -1
- package/dist/import/index.js +2 -1
- package/dist/import/input.js +32 -10
- package/dist/import/output.js +13 -8
- package/dist/inbox/client.d.ts +310 -0
- package/dist/inbox/client.js +15 -0
- package/dist/inbox/index.d.ts +2 -0
- package/dist/inbox/index.js +2 -0
- package/dist/integration/client.d.ts +307 -1
- package/dist/integration/client.js +21 -1
- package/dist/integration/commands.d.ts +8 -0
- package/dist/integration/commands.js +53 -10
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/index.js +1 -1
- package/dist/local-node/client.d.ts +11 -1
- package/dist/local-node/client.js +185 -235
- package/dist/local-node/index.d.ts +1 -1
- package/dist/local-node/index.js +1 -1
- package/dist/login/commands.js +7 -1
- package/dist/login/gateway.js +34 -11
- package/dist/login/menu.js +2 -1
- package/dist/login/vendor-account.js +3 -2
- package/dist/login/vendor-input.js +3 -2
- package/dist/mcp/calls.js +47 -226
- package/dist/mcp/routing.d.ts +3 -2
- package/dist/mcp/routing.js +37 -8
- package/dist/mcp/server.d.ts +10 -1
- package/dist/mcp/server.js +16 -6
- package/dist/migrate/classes.js +158 -0
- package/dist/migrate/commands.js +46 -0
- package/dist/migrate/format.js +199 -0
- package/dist/migrate/index.js +2 -0
- package/dist/migrate/item.js +59 -0
- package/dist/migrate/plan.js +79 -0
- package/dist/migrate/tree/index.js +2 -0
- package/dist/migrate/tree/tree.js +23 -0
- package/dist/node-update/client.d.ts +17 -0
- package/dist/node-update/client.js +27 -0
- package/dist/node-update/commands.d.ts +20 -0
- package/dist/node-update/commands.js +150 -0
- package/dist/node-update/index.d.ts +4 -0
- package/dist/node-update/index.js +4 -0
- package/dist/node-update/output.d.ts +12 -0
- package/dist/node-update/output.js +165 -0
- package/dist/node-update/tree/index.js +2 -0
- package/dist/node-update/tree/tree.js +73 -0
- package/dist/pairing/client.d.ts +13 -0
- package/dist/pairing/client.js +36 -0
- package/dist/pairing/commands.d.ts +15 -0
- package/dist/pairing/commands.js +131 -0
- package/dist/pairing/index.d.ts +4 -0
- package/dist/pairing/index.js +4 -0
- package/dist/pairing/output.d.ts +12 -0
- package/dist/pairing/output.js +53 -0
- package/dist/pairing/tree/index.js +2 -0
- package/dist/pairing/tree/tree.js +35 -0
- package/dist/panel/client.d.ts +9 -0
- package/dist/panel/client.js +24 -0
- package/dist/panel/commands.d.ts +19 -0
- package/dist/panel/commands.js +112 -0
- package/dist/panel/index.d.ts +3 -0
- package/dist/panel/index.js +3 -0
- package/dist/panel/tree/index.js +2 -0
- package/dist/panel/tree/tree.js +14 -0
- package/dist/port-lease/client.d.ts +3 -0
- package/dist/principal/client.d.ts +9 -0
- package/dist/principal/client.js +7 -0
- package/dist/principal/commands.d.ts +14 -0
- package/dist/principal/commands.js +84 -0
- package/dist/principal/index.d.ts +4 -0
- package/dist/principal/index.js +4 -0
- package/dist/principal/output.d.ts +8 -0
- package/dist/principal/output.js +43 -0
- package/dist/principal/tree/index.js +2 -0
- package/dist/principal/tree/tree.js +31 -0
- package/dist/project-guard/client.d.ts +1 -0
- package/dist/project-instructions/client.d.ts +56 -0
- package/dist/project-instructions/client.js +7 -0
- package/dist/project-instructions/commands.d.ts +13 -0
- package/dist/project-instructions/commands.js +89 -0
- package/dist/project-instructions/index.d.ts +3 -0
- package/dist/project-instructions/index.js +3 -0
- package/dist/project-instructions/input.js +33 -0
- package/dist/project-instructions/output/format.js +22 -0
- package/dist/project-instructions/output/index.js +2 -0
- package/dist/project-knowledge/change.js +22 -0
- package/dist/project-knowledge/client.d.ts +127 -0
- package/dist/project-knowledge/client.js +17 -0
- package/dist/project-knowledge/commands.d.ts +14 -0
- package/dist/project-knowledge/commands.js +100 -0
- package/dist/project-knowledge/index.d.ts +3 -0
- package/dist/project-knowledge/index.js +3 -0
- package/dist/project-knowledge/input.js +32 -0
- package/dist/project-knowledge/output/format.js +64 -0
- package/dist/project-knowledge/output/index.js +2 -0
- package/dist/project-knowledge/sources.js +108 -0
- package/dist/project-knowledge/upload.js +27 -0
- package/dist/project-workspace/git-reads.d.ts +12 -0
- package/dist/project-workspace/git-reads.js +71 -0
- package/dist/project-workspace/index.d.ts +1 -0
- package/dist/project-workspace/index.js +1 -0
- package/dist/project-workspace/metadata-client.d.ts +2 -0
- package/dist/project-workspace/output/human.js +1 -1
- package/dist/project-workspace/tree/tree.js +95 -5
- package/dist/reach/client.d.ts +9 -0
- package/dist/reach/client.js +7 -0
- package/dist/reach/commands.d.ts +14 -0
- package/dist/reach/commands.js +72 -0
- package/dist/reach/index.d.ts +3 -0
- package/dist/reach/index.js +3 -0
- package/dist/reach/output.js +41 -0
- package/dist/reach/tree/index.js +2 -0
- package/dist/reach/tree/tree.js +28 -0
- package/dist/remote-node/client.d.ts +85 -0
- package/dist/remote-node/commands.js +32 -17
- package/dist/remote-node/connector.d.ts +16 -0
- package/dist/remote-node/connector.js +2 -2
- package/dist/remote-node/reachability.js +31 -18
- package/dist/remote-node/reading.js +31 -0
- package/dist/remote-node/text.js +68 -5
- package/dist/remote-node/tree/tree.js +14 -3
- package/dist/routine/client.d.ts +547 -13
- package/dist/routine/client.js +19 -1
- package/dist/routine/commands.d.ts +5 -0
- package/dist/routine/commands.js +73 -15
- package/dist/routine/index.d.ts +2 -1
- package/dist/routine/index.js +2 -1
- package/dist/routine/input.js +66 -3
- package/dist/routine/output/format.js +80 -19
- package/dist/routine/output/index.js +1 -1
- package/dist/routine/portable/import-files.js +74 -0
- package/dist/routine/portable/import-output.js +21 -0
- package/dist/routine/portable/import.js +274 -0
- package/dist/routine/portable/index.js +3 -0
- package/dist/routine/portable/portable.js +185 -0
- package/dist/routine/tree/tree.js +80 -8
- package/dist/routine/trigger/commands.d.ts +20 -0
- package/dist/routine/trigger/commands.js +74 -0
- package/dist/routine/trigger/format.js +42 -0
- package/dist/routine/trigger/index.d.ts +2 -0
- package/dist/routine/trigger/index.js +2 -0
- package/dist/routine/trigger/input.js +81 -0
- package/dist/run-ledger/client.d.ts +45 -0
- package/dist/secret/client.d.ts +39 -0
- package/dist/secret/client.js +6 -0
- package/dist/secret/commands.d.ts +12 -0
- package/dist/secret/commands.js +91 -0
- package/dist/secret/index.d.ts +3 -0
- package/dist/secret/index.js +3 -0
- package/dist/secret/input.js +22 -0
- package/dist/secret/output/format.js +10 -0
- package/dist/secret/output/index.js +2 -0
- package/dist/secret/tree/index.js +2 -0
- package/dist/secret/tree/tree.js +16 -0
- package/dist/session/agent-permission.d.ts +3 -2
- package/dist/session/approval/client.d.ts +4 -3
- package/dist/session/approval/commands.d.ts +7 -0
- package/dist/session/approval/commands.js +176 -6
- package/dist/session/approval/index.d.ts +1 -1
- package/dist/session/approval/index.js +1 -1
- package/dist/session/approval/output/format.js +53 -1
- package/dist/session/approval/output/index.js +1 -1
- package/dist/session/attach.d.ts +1 -1
- package/dist/session/attach.js +7 -2
- package/dist/session/client.d.ts +12 -12
- package/dist/session/client.js +8 -17
- package/dist/session/command/commands.js +109 -0
- package/dist/session/command/index.js +2 -0
- package/dist/session/commands.d.ts +5 -1
- package/dist/session/commands.js +273 -57
- package/dist/session/create-tasks.js +3 -48
- package/dist/session/creation/creation.js +51 -0
- package/dist/session/creation/index.js +2 -0
- package/dist/session/fork/fork.js +135 -0
- package/dist/session/fork/index.js +2 -0
- package/dist/session/git-status.d.ts +11 -0
- package/dist/session/git-status.js +30 -0
- package/dist/session/index.d.ts +4 -3
- package/dist/session/index.js +3 -2
- package/dist/session/interaction/client.d.ts +3 -0
- package/dist/session/move/index.js +2 -0
- package/dist/session/move/move.js +439 -0
- package/dist/session/output/held.js +28 -0
- package/dist/session/output/human.js +34 -7
- package/dist/session/output/tasks.js +23 -6
- package/dist/session/setup/index.js +2 -0
- package/dist/session/setup/setup.js +69 -0
- package/dist/session/spawn/caps.js +128 -0
- package/dist/session/spawn/index.js +5 -0
- package/dist/session/spawn/spawn.js +203 -0
- package/dist/session/spawn/standing.js +62 -0
- package/dist/session/spawn/supervision.js +62 -0
- package/dist/session/switch/index.js +2 -0
- package/dist/session/switch/switch.js +103 -0
- package/dist/session/tree/tree.js +280 -18
- package/dist/session/turn/attachments.js +54 -0
- package/dist/session/turn/client.d.ts +3 -1
- package/dist/session/turn/client.js +6 -1
- package/dist/session/turn/commands.d.ts +5 -1
- package/dist/session/turn/commands.js +148 -27
- package/dist/session/turn/index.d.ts +2 -2
- package/dist/session/turn/index.js +1 -1
- package/dist/session/turn/output.d.ts +25 -1
- package/dist/session/turn/output.js +33 -0
- package/dist/skills-sync/client.d.ts +9 -0
- package/dist/skills-sync/client.js +7 -0
- package/dist/skills-sync/commands.d.ts +15 -0
- package/dist/skills-sync/commands.js +241 -0
- package/dist/skills-sync/index.d.ts +3 -0
- package/dist/skills-sync/index.js +3 -0
- package/dist/skills-sync/output.js +168 -0
- package/dist/skills-sync/set-file.js +23 -0
- package/dist/skills-sync/tree/index.js +2 -0
- package/dist/skills-sync/tree/tree.js +38 -0
- package/dist/status/client.d.ts +7 -0
- package/dist/status/command.js +3 -2
- package/dist/status/doctor.js +4 -3
- package/dist/team-workspace/client.d.ts +1 -0
- package/dist/text-input/index.js +2 -0
- package/dist/text-input/text-input.js +35 -0
- package/dist/webhooks/client.d.ts +10 -9
- package/dist/webhooks/input.js +2 -2
- package/dist/webhooks/tree/tree.js +4 -4
- package/guidance/maia-sessions/SKILL.md +37 -3
- package/package.json +6 -5
- package/dist/command-line/context.js +0 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { sessionSetupConfirmParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { fields, writeNodeResult, } from "../../command-line/emit/index.js";
|
|
4
|
+
import { CliArgumentError, parseOptionsWith, requirePositionals, } from "../../command-line/input/index.js";
|
|
5
|
+
import { confirmParameters, readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../../command-line/two-phase/index.js";
|
|
6
|
+
import { commandIdentifier, } from "../../local-node/index.js";
|
|
7
|
+
import { requirePipedAlone } from "../fork/index.js";
|
|
8
|
+
const SETUP_OPTIONS = {
|
|
9
|
+
allowed: new Set(["--command-id"]),
|
|
10
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
11
|
+
repeatable: new Set(),
|
|
12
|
+
};
|
|
13
|
+
const previewSetup = (call, { options, positionals }) => {
|
|
14
|
+
requirePositionals(positionals, 1);
|
|
15
|
+
return Effect.flatMap(commandIdentifier(options.get("--command-id")), (commandId) => call("session.setup.preview", {
|
|
16
|
+
commandId,
|
|
17
|
+
sessionId: positionals[0] ?? "",
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
const previewText = ({ setup, ...preview }) => fields([
|
|
21
|
+
["Session", preview.sessionId],
|
|
22
|
+
["Command", setup.command.join(" ")],
|
|
23
|
+
...setup.files.map((file) => [`File ${file.path}`, file.sha256]),
|
|
24
|
+
["Confirmed", preview.approved ? "yes" : "no"],
|
|
25
|
+
["Digest", preview.setupDigest],
|
|
26
|
+
["Command ID", preview.commandId],
|
|
27
|
+
["Revision", preview.expectedRevision],
|
|
28
|
+
["Valid until", preview.validUntil],
|
|
29
|
+
]);
|
|
30
|
+
const confirmedText = (confirmed) => fields([
|
|
31
|
+
["Session", confirmed.sessionId],
|
|
32
|
+
["Digest", confirmed.setupDigest],
|
|
33
|
+
["Delivery", confirmed.delivery],
|
|
34
|
+
["Receipt", confirmed.receipt.receiptId],
|
|
35
|
+
]);
|
|
36
|
+
const previewed = {
|
|
37
|
+
toResult: (value) => ({ command: "session.setup.preview", result: value }),
|
|
38
|
+
toText: ({ result }) => previewText(result),
|
|
39
|
+
};
|
|
40
|
+
const confirmed = {
|
|
41
|
+
toResult: (value) => ({ command: "session.setup.confirm", result: value }),
|
|
42
|
+
toText: ({ result }) => confirmedText(result),
|
|
43
|
+
};
|
|
44
|
+
const confirmSetup = (call, preview) => Effect.flatMap(confirmParameters(sessionSetupConfirmParametersSchema, preview, [
|
|
45
|
+
"approved",
|
|
46
|
+
"setup",
|
|
47
|
+
]), (confirmation) => call("session.setup.confirm", confirmation));
|
|
48
|
+
export const runSessionSetupApply = (tokens, context) => {
|
|
49
|
+
const parsed = parseOptionsWith(tokens, SETUP_OPTIONS);
|
|
50
|
+
const mode = readTwoPhaseMode(parsed.flags, context);
|
|
51
|
+
if (mode === "confirm-stdin")
|
|
52
|
+
requirePipedAlone(parsed, "Session, script digest and command ID");
|
|
53
|
+
const { call } = context.dependencies;
|
|
54
|
+
if (call === undefined)
|
|
55
|
+
throw new CliArgumentError("Session setup is unavailable.");
|
|
56
|
+
return runTwoPhase({
|
|
57
|
+
confirm: (preview) => confirmSetup(call, preview),
|
|
58
|
+
context,
|
|
59
|
+
mode,
|
|
60
|
+
preview: () => previewSetup(call, parsed),
|
|
61
|
+
prompt: {
|
|
62
|
+
describe: previewText,
|
|
63
|
+
question: "Let this setup script run in the Project's Session worktrees? A changed script asks again.",
|
|
64
|
+
},
|
|
65
|
+
writeConfirm: (result) => writeNodeResult(result, context, confirmed),
|
|
66
|
+
writePreview: (result) => writeNodeResult(result, context, previewed),
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SESSION_SPAWN_CAP_BOUNDS, sessionSpawnCapsConfirmParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { fields, writeNodeResult, } from "../../command-line/emit/index.js";
|
|
4
|
+
import { CliArgumentError, parseOptionsWith, readExpectedRevision, requirePositionals, } from "../../command-line/input/index.js";
|
|
5
|
+
import { confirmParameters, readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../../command-line/two-phase/index.js";
|
|
6
|
+
import { commandIdentifier } from "../../local-node/index.js";
|
|
7
|
+
const CAP_OPTIONS = {
|
|
8
|
+
concurrency: "--max-concurrency",
|
|
9
|
+
depth: "--max-depth",
|
|
10
|
+
fanOut: "--max-fan-out",
|
|
11
|
+
};
|
|
12
|
+
const SET_OPTIONS = {
|
|
13
|
+
allowed: new Set([
|
|
14
|
+
"--command-id",
|
|
15
|
+
"--expected-revision",
|
|
16
|
+
...Object.values(CAP_OPTIONS),
|
|
17
|
+
]),
|
|
18
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
19
|
+
repeatable: new Set(),
|
|
20
|
+
};
|
|
21
|
+
const SHOW_OPTIONS = {
|
|
22
|
+
allowed: new Set(),
|
|
23
|
+
allowedFlags: new Set(),
|
|
24
|
+
repeatable: new Set(),
|
|
25
|
+
};
|
|
26
|
+
const callOf = (context) => {
|
|
27
|
+
const { call } = context.dependencies;
|
|
28
|
+
if (call === undefined)
|
|
29
|
+
throw new CliArgumentError("Spawn caps are unavailable.");
|
|
30
|
+
return call;
|
|
31
|
+
};
|
|
32
|
+
const readCap = (options, cap) => {
|
|
33
|
+
const option = CAP_OPTIONS[cap];
|
|
34
|
+
const value = options.get(option) ?? "";
|
|
35
|
+
const { maximum, minimum } = SESSION_SPAWN_CAP_BOUNDS[cap];
|
|
36
|
+
const parsed = /^\d{1,3}$/u.test(value) ? Number(value) : 0;
|
|
37
|
+
if (parsed < minimum || parsed > maximum)
|
|
38
|
+
throw new CliArgumentError(`Option '${option}' must be an integer from ${String(minimum)} to ${String(maximum)}.`);
|
|
39
|
+
return parsed;
|
|
40
|
+
};
|
|
41
|
+
const capsEntries = (record) => [
|
|
42
|
+
["Depth", String(record.caps.depth)],
|
|
43
|
+
["Fan-out", String(record.caps.fanOut)],
|
|
44
|
+
["Concurrency", String(record.caps.concurrency)],
|
|
45
|
+
["Revision", record.revision],
|
|
46
|
+
["Source", record.source],
|
|
47
|
+
];
|
|
48
|
+
const shown = {
|
|
49
|
+
toResult: (value) => ({ command: "session.spawn-caps.show", result: value }),
|
|
50
|
+
toText: ({ result }) => fields(capsEntries(result.caps)),
|
|
51
|
+
};
|
|
52
|
+
const previewText = (preview) => fields([
|
|
53
|
+
[
|
|
54
|
+
"Depth",
|
|
55
|
+
`${String(preview.current.caps.depth)} -> ${String(preview.caps.depth)}`,
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"Fan-out",
|
|
59
|
+
`${String(preview.current.caps.fanOut)} -> ${String(preview.caps.fanOut)}`,
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
"Concurrency",
|
|
63
|
+
`${String(preview.current.caps.concurrency)} -> ${String(preview.caps.concurrency)}`,
|
|
64
|
+
],
|
|
65
|
+
["Revision", preview.expectedRevision],
|
|
66
|
+
["Command", preview.commandId],
|
|
67
|
+
["Valid until", preview.validUntil],
|
|
68
|
+
]);
|
|
69
|
+
const previewed = {
|
|
70
|
+
toResult: (value) => ({
|
|
71
|
+
command: "session.spawn-caps.preview",
|
|
72
|
+
result: value,
|
|
73
|
+
}),
|
|
74
|
+
toText: ({ result }) => previewText(result),
|
|
75
|
+
};
|
|
76
|
+
const confirmed = {
|
|
77
|
+
toResult: (value) => ({
|
|
78
|
+
command: "session.spawn-caps.confirm",
|
|
79
|
+
result: value,
|
|
80
|
+
}),
|
|
81
|
+
toText: ({ result }) => fields([
|
|
82
|
+
...capsEntries(result.caps),
|
|
83
|
+
["Receipt", result.receipt.receiptId],
|
|
84
|
+
["Delivery", result.delivery],
|
|
85
|
+
]),
|
|
86
|
+
};
|
|
87
|
+
export const runSessionSpawnCapsShow = (tokens, context) => Effect.gen(function* () {
|
|
88
|
+
requirePositionals(parseOptionsWith(tokens, SHOW_OPTIONS).positionals, 0);
|
|
89
|
+
const result = yield* callOf(context)("session.spawn-caps.show", {});
|
|
90
|
+
return writeNodeResult(result, context, shown);
|
|
91
|
+
});
|
|
92
|
+
const readChange = (parsed) => {
|
|
93
|
+
requirePositionals(parsed.positionals, 0);
|
|
94
|
+
const expectedRevision = readExpectedRevision(parsed.options.get("--expected-revision"));
|
|
95
|
+
const caps = {
|
|
96
|
+
concurrency: readCap(parsed.options, "concurrency"),
|
|
97
|
+
depth: readCap(parsed.options, "depth"),
|
|
98
|
+
fanOut: readCap(parsed.options, "fanOut"),
|
|
99
|
+
};
|
|
100
|
+
return Effect.map(commandIdentifier(parsed.options.get("--command-id")), (commandId) => ({ caps, commandId, expectedRevision }));
|
|
101
|
+
};
|
|
102
|
+
const readSetMode = (parsed, context) => {
|
|
103
|
+
const mode = readTwoPhaseMode(parsed.flags, context);
|
|
104
|
+
if (mode === "confirm-stdin" &&
|
|
105
|
+
(parsed.positionals.length > 0 || parsed.options.size > 0))
|
|
106
|
+
throw new CliArgumentError("A piped preview carries its caps, revision and command ID: give '--confirm-stdin' alone.");
|
|
107
|
+
return mode;
|
|
108
|
+
};
|
|
109
|
+
export const runSessionSpawnCapsSet = (tokens, context) => {
|
|
110
|
+
const parsed = parseOptionsWith(tokens, SET_OPTIONS);
|
|
111
|
+
const mode = readSetMode(parsed, context);
|
|
112
|
+
const call = callOf(context);
|
|
113
|
+
return runTwoPhase({
|
|
114
|
+
confirm: (preview) => Effect.flatMap(confirmParameters(sessionSpawnCapsConfirmParametersSchema, preview, [
|
|
115
|
+
"current",
|
|
116
|
+
]), (confirmation) => call("session.spawn-caps.confirm", confirmation)),
|
|
117
|
+
context,
|
|
118
|
+
mode,
|
|
119
|
+
preview: () => Effect.flatMap(readChange(parsed), (change) => call("session.spawn-caps.preview", change)),
|
|
120
|
+
prompt: {
|
|
121
|
+
describe: previewText,
|
|
122
|
+
question: "Set these spawn caps?",
|
|
123
|
+
},
|
|
124
|
+
writeConfirm: (result) => writeNodeResult(result, context, confirmed),
|
|
125
|
+
writePreview: (result) => writeNodeResult(result, context, previewed),
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=caps.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { runSessionSpawnCapsSet, runSessionSpawnCapsShow, } from "./caps.js";
|
|
2
|
+
export { runSessionSpawn, } from "./spawn.js";
|
|
3
|
+
export { readResumeParent } from "./standing.js";
|
|
4
|
+
export { cancelChildren, linkChild, reconcileChildren, resumeSupervised, } from "./supervision.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { sessionSpawnConfirmParametersSchema, sessionSpawnPreviewParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { fields, writeNodeResult, } from "../../command-line/emit/index.js";
|
|
4
|
+
import { CliArgumentError, LOCAL_NODE, parseOptionsWith, requirePositionals, } from "../../command-line/input/index.js";
|
|
5
|
+
import { confirmParameters, readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../../command-line/two-phase/index.js";
|
|
6
|
+
import { commandIdentifier, } from "../../local-node/index.js";
|
|
7
|
+
import { readParentStanding, requireFreshChildren, } from "./standing.js";
|
|
8
|
+
import { linkChild } from "./supervision.js";
|
|
9
|
+
const SPAWN_OPTIONS = {
|
|
10
|
+
allowed: new Set([
|
|
11
|
+
"--command-id",
|
|
12
|
+
"--harness",
|
|
13
|
+
"--permission",
|
|
14
|
+
"--to-node",
|
|
15
|
+
"--workspace",
|
|
16
|
+
]),
|
|
17
|
+
allowedFlags: new Set([...TWO_PHASE_FLAGS, "--host-authority"]),
|
|
18
|
+
repeatable: new Set(),
|
|
19
|
+
};
|
|
20
|
+
const ENDED_STATES = new Set([
|
|
21
|
+
"failed",
|
|
22
|
+
"stopped",
|
|
23
|
+
]);
|
|
24
|
+
const requireOption = (options, name) => {
|
|
25
|
+
const value = options.get(name);
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
throw new CliArgumentError(`Option '${name}' is required.`);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const readChild = ({ flags, options }) => {
|
|
31
|
+
const permission = options.get("--permission");
|
|
32
|
+
const hostAuthority = flags.has("--host-authority");
|
|
33
|
+
if (permission !== undefined && !hostAuthority)
|
|
34
|
+
throw new CliArgumentError("Option '--permission' needs '--host-authority'.");
|
|
35
|
+
const checked = sessionSpawnPreviewParametersSchema.safeParse({
|
|
36
|
+
commandId: options.get("--command-id") ?? "command_validate",
|
|
37
|
+
executor: requireOption(options, "--harness"),
|
|
38
|
+
...(hostAuthority ? { hostAuthority: true } : {}),
|
|
39
|
+
parent: {
|
|
40
|
+
children: { live: 0, total: 0 },
|
|
41
|
+
depth: 0,
|
|
42
|
+
role: "worker",
|
|
43
|
+
sessionId: "session_validate",
|
|
44
|
+
},
|
|
45
|
+
...(permission === undefined ? {} : { permission }),
|
|
46
|
+
workspaceId: requireOption(options, "--workspace"),
|
|
47
|
+
});
|
|
48
|
+
if (!checked.success)
|
|
49
|
+
throw new CliArgumentError("Option '--harness' must be an executor id, '--workspace' an ID, and '--permission' a permission mode that harness defines.");
|
|
50
|
+
return checked.data;
|
|
51
|
+
};
|
|
52
|
+
const destinationOf = (context, toNode) => {
|
|
53
|
+
const own = context.node ?? LOCAL_NODE;
|
|
54
|
+
const node = toNode ?? own;
|
|
55
|
+
const bound = node === own ? context.dependencies : context.bindNode?.(node);
|
|
56
|
+
if (bound === undefined)
|
|
57
|
+
throw new CliArgumentError("Spawning on another Node is unavailable here.");
|
|
58
|
+
if (bound.call === undefined)
|
|
59
|
+
throw new CliArgumentError("Session spawn is unavailable.");
|
|
60
|
+
return { call: bound.call, node };
|
|
61
|
+
};
|
|
62
|
+
const grantOf = (session) => ({
|
|
63
|
+
sessionId: session.id,
|
|
64
|
+
...(session.containment === "none"
|
|
65
|
+
? {
|
|
66
|
+
hostAuthority: true,
|
|
67
|
+
...(session.permission === undefined
|
|
68
|
+
? {}
|
|
69
|
+
: { permission: session.permission }),
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
});
|
|
73
|
+
const parentGrant = (dependencies, sessionId) => Effect.map(dependencies.showSession(sessionId), (shown) => {
|
|
74
|
+
if (!shown.ok)
|
|
75
|
+
return shown;
|
|
76
|
+
const { session } = shown.value;
|
|
77
|
+
return ENDED_STATES.has(session.state)
|
|
78
|
+
? {
|
|
79
|
+
error: {
|
|
80
|
+
code: "storage_conflict",
|
|
81
|
+
message: `Session ${session.id} is ${session.state}; a Session that has ended cannot spawn children.`,
|
|
82
|
+
retryable: false,
|
|
83
|
+
},
|
|
84
|
+
ok: false,
|
|
85
|
+
}
|
|
86
|
+
: { ok: true, value: grantOf(session) };
|
|
87
|
+
});
|
|
88
|
+
const previewSpawn = (context, { destination, everyNode }, parsed) => {
|
|
89
|
+
requirePositionals(parsed.positionals, 1);
|
|
90
|
+
const child = readChild(parsed);
|
|
91
|
+
const sessionId = parsed.positionals[0] ?? "";
|
|
92
|
+
return Effect.gen(function* () {
|
|
93
|
+
const commandId = yield* commandIdentifier(parsed.options.get("--command-id"));
|
|
94
|
+
const parent = yield* parentGrant(context.dependencies, sessionId);
|
|
95
|
+
if (!parent.ok)
|
|
96
|
+
return parent;
|
|
97
|
+
const standing = yield* readParentStanding(context.dependencies, everyNode, { destination: destination.node, sessionId });
|
|
98
|
+
if (!standing.ok)
|
|
99
|
+
return standing;
|
|
100
|
+
return yield* destination.call("session.spawn.preview", {
|
|
101
|
+
...child,
|
|
102
|
+
commandId,
|
|
103
|
+
parent: { ...parent.value, ...standing.value },
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
const linkedOnHolder = (holder, created) => created.node === holder.node
|
|
108
|
+
? Effect.succeed({ ok: true, value: created })
|
|
109
|
+
: Effect.map(linkChild(holder.dependencies, {
|
|
110
|
+
childSessionId: created.sessionId,
|
|
111
|
+
node: created.node,
|
|
112
|
+
parentSessionId: created.parentSessionId,
|
|
113
|
+
}), (linked) => linked.ok
|
|
114
|
+
? { ok: true, value: created }
|
|
115
|
+
: {
|
|
116
|
+
error: {
|
|
117
|
+
...linked.error,
|
|
118
|
+
message: `Child ${created.sessionId} was created on Node ${created.node}, but Node ${holder.node} did not link it to its parent, so a cancel cannot mark it orphaned: ${linked.error.message}`,
|
|
119
|
+
},
|
|
120
|
+
ok: false,
|
|
121
|
+
});
|
|
122
|
+
const confirmSpawn = ({ destination, everyNode, holder }, preview) => Effect.gen(function* () {
|
|
123
|
+
const confirmation = yield* confirmParameters(sessionSpawnConfirmParametersSchema, preview);
|
|
124
|
+
const { children, sessionId } = confirmation.parent;
|
|
125
|
+
const fresh = yield* requireFreshChildren(everyNode, { destination: destination.node, sessionId }, children);
|
|
126
|
+
if (!fresh.ok)
|
|
127
|
+
return fresh;
|
|
128
|
+
const created = yield* destination.call("session.spawn.confirm", confirmation);
|
|
129
|
+
return created.ok
|
|
130
|
+
? yield* linkedOnHolder(holder, spawned(destination.node, created.value))
|
|
131
|
+
: created;
|
|
132
|
+
});
|
|
133
|
+
const spawned = (node, { delivery, parentSessionId, receipt, session }) => ({
|
|
134
|
+
delivery,
|
|
135
|
+
node,
|
|
136
|
+
parentSessionId,
|
|
137
|
+
receiptId: receipt.receiptId,
|
|
138
|
+
sessionId: session.id,
|
|
139
|
+
state: session.state,
|
|
140
|
+
...(session.executor === undefined
|
|
141
|
+
? {}
|
|
142
|
+
: { executor: session.executor.kind }),
|
|
143
|
+
});
|
|
144
|
+
const grantText = ({ hostAuthority, permission, }) => hostAuthority === true
|
|
145
|
+
? `host authority${permission === undefined ? "" : `, ${permission}`}`
|
|
146
|
+
: "sandbox";
|
|
147
|
+
const previewText = (preview, node) => fields([
|
|
148
|
+
["Parent", preview.parent.sessionId],
|
|
149
|
+
["Parent grant", grantText(preview.parent)],
|
|
150
|
+
["Harness", preview.executor],
|
|
151
|
+
["Node", node],
|
|
152
|
+
["Workspace", preview.workspaceId],
|
|
153
|
+
["Child grant", grantText(preview)],
|
|
154
|
+
["Command", preview.commandId],
|
|
155
|
+
["Valid until", preview.validUntil],
|
|
156
|
+
]);
|
|
157
|
+
const spawnedText = (result) => fields([
|
|
158
|
+
["Session", result.sessionId],
|
|
159
|
+
["Parent", result.parentSessionId],
|
|
160
|
+
["Harness", result.executor],
|
|
161
|
+
["Node", result.node],
|
|
162
|
+
["State", result.state],
|
|
163
|
+
["Receipt", result.receiptId],
|
|
164
|
+
["Delivery", result.delivery],
|
|
165
|
+
]);
|
|
166
|
+
const previewed = (node) => ({
|
|
167
|
+
toResult: (value) => ({ command: "session.spawn.preview", result: value }),
|
|
168
|
+
toText: ({ result }) => previewText(result, node),
|
|
169
|
+
});
|
|
170
|
+
const confirmed = {
|
|
171
|
+
toResult: (value) => ({ command: "session.spawn.confirm", result: value }),
|
|
172
|
+
toText: ({ result }) => spawnedText(result),
|
|
173
|
+
};
|
|
174
|
+
const requirePipedNodeOnly = ({ flags, options, positionals, }) => {
|
|
175
|
+
if (positionals.length > 0 ||
|
|
176
|
+
[...options.keys()].some((name) => name !== "--to-node") ||
|
|
177
|
+
[...flags].some((flag) => flag !== "--confirm-stdin"))
|
|
178
|
+
throw new CliArgumentError("A piped preview carries its parent, harness, Workspace, grant and command ID: give '--confirm-stdin' with '--to-node' alone.");
|
|
179
|
+
};
|
|
180
|
+
export const runSessionSpawn = (tokens, context) => {
|
|
181
|
+
const parsed = parseOptionsWith(tokens, SPAWN_OPTIONS);
|
|
182
|
+
const mode = readTwoPhaseMode(parsed.flags, context);
|
|
183
|
+
if (mode === "confirm-stdin")
|
|
184
|
+
requirePipedNodeOnly(parsed);
|
|
185
|
+
const destination = destinationOf(context, parsed.options.get("--to-node"));
|
|
186
|
+
const { dependencies, everyNode, node } = context;
|
|
187
|
+
if (everyNode === undefined)
|
|
188
|
+
throw new CliArgumentError("Session spawn is unavailable.");
|
|
189
|
+
const holder = { dependencies, node: node ?? LOCAL_NODE };
|
|
190
|
+
return runTwoPhase({
|
|
191
|
+
confirm: (preview) => confirmSpawn({ destination, everyNode, holder }, preview),
|
|
192
|
+
context,
|
|
193
|
+
mode,
|
|
194
|
+
preview: () => previewSpawn(context, { destination, everyNode }, parsed),
|
|
195
|
+
prompt: {
|
|
196
|
+
describe: (preview) => previewText(preview, destination.node),
|
|
197
|
+
question: `Spawn this child Session on Node ${destination.node}?`,
|
|
198
|
+
},
|
|
199
|
+
writeConfirm: (result) => writeNodeResult(result, context, confirmed),
|
|
200
|
+
writePreview: (result) => writeNodeResult(result, context, previewed(destination.node)),
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
const refused = (code, message, retryable = false) => ({ error: { code, message, retryable }, ok: false });
|
|
3
|
+
const showOn = (dependencies, sessionId) => dependencies.call === undefined
|
|
4
|
+
? Effect.succeed(refused("command_not_implemented", "Spawn caps are unavailable."))
|
|
5
|
+
: dependencies.call("session.spawn-caps.show", { sessionId });
|
|
6
|
+
const heldStanding = (dependencies, sessionId) => Effect.map(showOn(dependencies, sessionId), (held) => {
|
|
7
|
+
if (!held.ok)
|
|
8
|
+
return held;
|
|
9
|
+
const depth = held.value.standing?.depth;
|
|
10
|
+
const role = held.value.standing?.role;
|
|
11
|
+
return depth === undefined || role === undefined
|
|
12
|
+
? refused("resource_not_found", `The Node addressed does not hold Session ${sessionId}.`)
|
|
13
|
+
: { ok: true, value: { depth, role } };
|
|
14
|
+
});
|
|
15
|
+
const sumChildren = (answers, sessionId, destination) => {
|
|
16
|
+
const failed = answers.find(({ result }) => !result.ok);
|
|
17
|
+
if (failed !== undefined && !failed.result.ok)
|
|
18
|
+
return refused(failed.result.error.code, `Node ${failed.node} did not count the children of Session ${sessionId}: ${failed.result.error.message}`, failed.result.error.retryable);
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
value: answers.reduce((sum, { node, result }) => {
|
|
22
|
+
const children = result.ok && node !== destination
|
|
23
|
+
? result.value.standing?.children
|
|
24
|
+
: undefined;
|
|
25
|
+
return {
|
|
26
|
+
live: sum.live + (children?.live ?? 0),
|
|
27
|
+
total: sum.total + (children?.total ?? 0),
|
|
28
|
+
};
|
|
29
|
+
}, { live: 0, total: 0 }),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const readOtherChildren = (everyNode, { destination, sessionId }) => Effect.map(everyNode((node) => showOn(node, sessionId)), (answers) => answers.ok ? sumChildren(answers.value, sessionId, destination) : answers);
|
|
33
|
+
export const readParentStanding = (holder, everyNode, route) => Effect.gen(function* () {
|
|
34
|
+
const held = yield* heldStanding(holder, route.sessionId);
|
|
35
|
+
if (!held.ok)
|
|
36
|
+
return held;
|
|
37
|
+
const children = yield* readOtherChildren(everyNode, route);
|
|
38
|
+
if (!children.ok)
|
|
39
|
+
return children;
|
|
40
|
+
return { ok: true, value: { children: children.value, ...held.value } };
|
|
41
|
+
});
|
|
42
|
+
export const requireFreshChildren = (everyNode, route, claimed) => Effect.map(readOtherChildren(everyNode, route), (fresh) => {
|
|
43
|
+
if (!fresh.ok)
|
|
44
|
+
return fresh;
|
|
45
|
+
const { live, total } = fresh.value;
|
|
46
|
+
return live === claimed.live && total === claimed.total
|
|
47
|
+
? { ok: true, value: undefined }
|
|
48
|
+
: refused("storage_conflict", `Session ${route.sessionId} has ${String(total)} children on the other Nodes, ${String(live)} live, since the preview counted ${String(claimed.total)}, ${String(claimed.live)} live; preview again.`);
|
|
49
|
+
});
|
|
50
|
+
const ENDED_STATES = new Set(["failed", "stopped"]);
|
|
51
|
+
export const readResumeParent = (everyNode, destination, { parentSessionId, state }) => parentSessionId === undefined || !ENDED_STATES.has(state)
|
|
52
|
+
? Effect.succeed({ ok: true, value: undefined })
|
|
53
|
+
: Effect.map(readOtherChildren(everyNode, {
|
|
54
|
+
destination,
|
|
55
|
+
sessionId: parentSessionId,
|
|
56
|
+
}), (children) => children.ok
|
|
57
|
+
? {
|
|
58
|
+
ok: true,
|
|
59
|
+
value: { children: children.value, sessionId: parentSessionId },
|
|
60
|
+
}
|
|
61
|
+
: children);
|
|
62
|
+
//# sourceMappingURL=standing.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { cancelSubtree, linkRemoteChild, reconcileSubtree, resumeSupervised as resumeSupervisedSession, } from "@maiaos/sdk/node/effect";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { newCliIdentifier, } from "../../local-node/index.js";
|
|
4
|
+
const unavailable = (message) => ({
|
|
5
|
+
error: { code: "command_not_implemented", message, retryable: false },
|
|
6
|
+
ok: false,
|
|
7
|
+
});
|
|
8
|
+
const parentCalls = ({ call, showSession, }) => ({
|
|
9
|
+
record: (parameters) => call === undefined
|
|
10
|
+
? Effect.succeed(unavailable("Child supervision is unavailable."))
|
|
11
|
+
: Effect.flatMap(newCliIdentifier("command"), (commandId) => call("session.spawn.record", { ...parameters, commandId })),
|
|
12
|
+
showSession,
|
|
13
|
+
});
|
|
14
|
+
const fleetOf = ({ bindNode, names, node, }) => ({
|
|
15
|
+
names: [...new Set([node, ...names])],
|
|
16
|
+
node: (name) => {
|
|
17
|
+
const bound = bindNode(name);
|
|
18
|
+
return (bound && {
|
|
19
|
+
...parentCalls(bound),
|
|
20
|
+
listChildren: bound.listSessions,
|
|
21
|
+
stopSession: bound.stopSession ??
|
|
22
|
+
(() => Effect.succeed(unavailable("Session stop is unavailable."))),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const asChildStop = (line) => {
|
|
27
|
+
if (!("outcome" in line))
|
|
28
|
+
return line;
|
|
29
|
+
const { outcome: _outcome, ...child } = line;
|
|
30
|
+
return child;
|
|
31
|
+
};
|
|
32
|
+
export const cancelChildren = (route, parentSessionId) => Effect.map(cancelSubtree(fleetOf(route), {
|
|
33
|
+
node: route.node,
|
|
34
|
+
sessionId: parentSessionId,
|
|
35
|
+
}), (supervised) => supervised.ok
|
|
36
|
+
? supervised.value.map(asChildStop)
|
|
37
|
+
: [
|
|
38
|
+
{
|
|
39
|
+
error: {
|
|
40
|
+
...supervised.error,
|
|
41
|
+
message: `Nothing below ${parentSessionId} was asked: ${supervised.error.message}`,
|
|
42
|
+
},
|
|
43
|
+
node: route.node,
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
export const reconcileChildren = (route, parentSessionId) => Effect.map(reconcileSubtree(fleetOf(route), {
|
|
47
|
+
node: route.node,
|
|
48
|
+
sessionId: parentSessionId,
|
|
49
|
+
}), (supervised) => supervised.ok
|
|
50
|
+
? { ok: true, value: supervised.value.map(asChildStop) }
|
|
51
|
+
: supervised);
|
|
52
|
+
export const linkChild = (parent, link) => Effect.map(linkRemoteChild(parentCalls(parent), link), (linked) => linked.ok ? { ok: true, value: undefined } : linked);
|
|
53
|
+
export const resumeSupervised = (everyNode, calls, input) => resumeSupervisedSession({
|
|
54
|
+
...calls,
|
|
55
|
+
parentShows: (parentSessionId) => Effect.map(everyNode((node) => node.showSession(parentSessionId)), (answers) => answers.ok
|
|
56
|
+
? {
|
|
57
|
+
ok: true,
|
|
58
|
+
value: answers.value.map(({ result }) => result),
|
|
59
|
+
}
|
|
60
|
+
: answers),
|
|
61
|
+
}, input);
|
|
62
|
+
//# sourceMappingURL=supervision.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { sessionSwitchConfirmParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { fields, writeNodeResult, } from "../../command-line/emit/index.js";
|
|
4
|
+
import { CliArgumentError, parseOptionsWith, requirePositionals, } from "../../command-line/input/index.js";
|
|
5
|
+
import { confirmParameters, readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../../command-line/two-phase/index.js";
|
|
6
|
+
import { commandIdentifier, } from "../../local-node/index.js";
|
|
7
|
+
import { requirePipedAlone, startAndHandOff, wireSuccessor, } from "../fork/index.js";
|
|
8
|
+
const SWITCH_OPTIONS = {
|
|
9
|
+
allowed: new Set(["--command-id", "--connection", "--harness", "--model"]),
|
|
10
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
11
|
+
repeatable: new Set(),
|
|
12
|
+
};
|
|
13
|
+
const readTarget = (options) => {
|
|
14
|
+
const executor = options.get("--harness");
|
|
15
|
+
const connectionId = options.get("--connection");
|
|
16
|
+
const model = options.get("--model");
|
|
17
|
+
if (executor === undefined &&
|
|
18
|
+
connectionId === undefined &&
|
|
19
|
+
model === undefined)
|
|
20
|
+
throw new CliArgumentError("Name what to switch to: '--harness', '--connection' or '--model'.");
|
|
21
|
+
return {
|
|
22
|
+
...(connectionId === undefined ? {} : { connectionId }),
|
|
23
|
+
...(executor === undefined ? {} : { executor }),
|
|
24
|
+
...(model === undefined ? {} : { model }),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const previewSwitch = (dependencies, { options, positionals }) => {
|
|
28
|
+
requirePositionals(positionals, 1);
|
|
29
|
+
const target = readTarget(options);
|
|
30
|
+
return Effect.flatMap(commandIdentifier(options.get("--command-id")), (commandId) => dependencies.call("session.switch.preview", {
|
|
31
|
+
commandId,
|
|
32
|
+
sessionId: positionals[0] ?? "",
|
|
33
|
+
target,
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
const withBinding = (forked, { session: { executor } }) => ({
|
|
37
|
+
...forked,
|
|
38
|
+
...(executor?.connectionId === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: { connectionId: executor.connectionId }),
|
|
41
|
+
...(executor === undefined ? {} : { executor: executor.kind }),
|
|
42
|
+
...(executor?.model === undefined ? {} : { model: executor.model }),
|
|
43
|
+
});
|
|
44
|
+
const confirmSwitch = (dependencies, confirmation) => Effect.gen(function* () {
|
|
45
|
+
const switched = yield* dependencies.call("session.switch.confirm", confirmation);
|
|
46
|
+
if (!switched.ok)
|
|
47
|
+
return switched;
|
|
48
|
+
const handedOff = yield* startAndHandOff(dependencies, confirmation.commandId, switched.value);
|
|
49
|
+
return handedOff.ok
|
|
50
|
+
? { ok: true, value: withBinding(handedOff.value, switched.value) }
|
|
51
|
+
: handedOff;
|
|
52
|
+
});
|
|
53
|
+
const previewText = (preview) => fields([
|
|
54
|
+
["Session", preview.sessionId],
|
|
55
|
+
["Executor", preview.target.executor],
|
|
56
|
+
["Connection", preview.target.connectionId],
|
|
57
|
+
["Model", preview.target.model],
|
|
58
|
+
["Path", preview.path],
|
|
59
|
+
["Command", preview.commandId],
|
|
60
|
+
["Revision", preview.expectedRevision],
|
|
61
|
+
["Valid until", preview.validUntil],
|
|
62
|
+
]);
|
|
63
|
+
const switchedText = (switched) => fields([
|
|
64
|
+
["Session", switched.sessionId],
|
|
65
|
+
["Source", switched.sourceSessionId],
|
|
66
|
+
["Executor", switched.executor],
|
|
67
|
+
["Connection", switched.connectionId],
|
|
68
|
+
["Model", switched.model],
|
|
69
|
+
["Path", switched.path],
|
|
70
|
+
["Turn", switched.turnId],
|
|
71
|
+
["Delivery", switched.delivery],
|
|
72
|
+
["Receipt", switched.receiptId],
|
|
73
|
+
]);
|
|
74
|
+
const previewed = {
|
|
75
|
+
toResult: (value) => ({ command: "session.switch.preview", result: value }),
|
|
76
|
+
toText: ({ result }) => previewText(result),
|
|
77
|
+
};
|
|
78
|
+
const confirmed = {
|
|
79
|
+
toResult: (value) => ({ command: "session.switch.confirm", result: value }),
|
|
80
|
+
toText: ({ result }) => switchedText(result),
|
|
81
|
+
};
|
|
82
|
+
export const runSessionSwitch = (tokens, context) => {
|
|
83
|
+
const parsed = parseOptionsWith(tokens, SWITCH_OPTIONS);
|
|
84
|
+
const mode = readTwoPhaseMode(parsed.flags, context);
|
|
85
|
+
if (mode === "confirm-stdin")
|
|
86
|
+
requirePipedAlone(parsed, "Session, target and command ID");
|
|
87
|
+
const dependencies = wireSuccessor(context.dependencies, "Session switch");
|
|
88
|
+
return runTwoPhase({
|
|
89
|
+
confirm: (preview) => Effect.flatMap(confirmParameters(sessionSwitchConfirmParametersSchema, preview, [
|
|
90
|
+
"path",
|
|
91
|
+
]), (confirmation) => confirmSwitch(dependencies, confirmation)),
|
|
92
|
+
context,
|
|
93
|
+
mode,
|
|
94
|
+
preview: () => previewSwitch(dependencies, parsed),
|
|
95
|
+
prompt: {
|
|
96
|
+
describe: previewText,
|
|
97
|
+
question: "Switch to a new Session on this binding? The source Session stays as it is.",
|
|
98
|
+
},
|
|
99
|
+
writeConfirm: (result) => writeNodeResult(result, context, confirmed),
|
|
100
|
+
writePreview: (result) => writeNodeResult(result, context, previewed),
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=switch.js.map
|