@maiaos/cli 0.1.0-canary.63 → 0.1.0-canary.65
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 +260 -55
- 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,439 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { MAX_PROJECT_CONTEXT_NOTE_BODY_BYTES, MAX_TURN_INPUT_BYTES, } from "@maiaos/sdk";
|
|
3
|
+
import { Crypto, Data, Effect } from "effect";
|
|
4
|
+
import { decodeJsonText, exitCodeOf, fields, labelCells, reportError, writeSuccess, } from "../../command-line/emit/index.js";
|
|
5
|
+
import { CliArgumentError, LOCAL_NODE, parseOptions, requirePositionals, } from "../../command-line/input/index.js";
|
|
6
|
+
import { readTwoPhaseMode, runTwoPhase, TWO_PHASE_FLAGS, } from "../../command-line/two-phase/index.js";
|
|
7
|
+
import { batchError, reportItem, withCommandId } from "../creation/index.js";
|
|
8
|
+
class Stopped extends Data.TaggedError("MoveStopped") {
|
|
9
|
+
}
|
|
10
|
+
const utf8 = new TextEncoder();
|
|
11
|
+
const MAX_COMMAND_ID_LENGTH = 120;
|
|
12
|
+
const MOVABLE_STATES = new Set([
|
|
13
|
+
"failed",
|
|
14
|
+
"idle",
|
|
15
|
+
"interrupted",
|
|
16
|
+
"running",
|
|
17
|
+
"stopped",
|
|
18
|
+
]);
|
|
19
|
+
const IN_FLIGHT_TURNS = new Set([
|
|
20
|
+
"dispatching",
|
|
21
|
+
"queued",
|
|
22
|
+
"running",
|
|
23
|
+
]);
|
|
24
|
+
const NO_SUMMARY = "The Session has no final text to carry over; pass '--summary' or '--summary-stdin'.";
|
|
25
|
+
const ok = (value) => ({ ok: true, value });
|
|
26
|
+
const refuse = (message) => new Stopped({
|
|
27
|
+
error: { code: "session_move_refused", message, retryable: false },
|
|
28
|
+
});
|
|
29
|
+
const need = (effect) => Effect.flatMap(effect, (result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new Stopped(result)));
|
|
30
|
+
const stopped = (done) => ({ error, recovery }) => Effect.succeed({ ...done, error, recovery });
|
|
31
|
+
const readTarget = (options) => {
|
|
32
|
+
const projectId = options.get("--project");
|
|
33
|
+
const workspaceId = options.get("--workspace");
|
|
34
|
+
const toNode = options.get("--to-node");
|
|
35
|
+
if (toNode === undefined)
|
|
36
|
+
throw new CliArgumentError("Option '--to-node' names the target Node.");
|
|
37
|
+
if (projectId !== undefined && workspaceId === undefined)
|
|
38
|
+
return { scope: { projectId }, toNode };
|
|
39
|
+
if (workspaceId !== undefined && projectId === undefined)
|
|
40
|
+
return { scope: { workspaceId }, toNode };
|
|
41
|
+
throw new CliArgumentError("Name the target with one of '--project' or '--workspace', an ID on the target Node.");
|
|
42
|
+
};
|
|
43
|
+
const readSummary = (options, flags) => {
|
|
44
|
+
const summary = options.get("--summary");
|
|
45
|
+
const stdin = flags.has("--summary-stdin");
|
|
46
|
+
if (summary !== undefined && stdin)
|
|
47
|
+
throw new CliArgumentError("Use one of '--summary' or '--summary-stdin'.");
|
|
48
|
+
if (summary !== undefined)
|
|
49
|
+
return { from: "option", summary };
|
|
50
|
+
return { from: stdin ? "stdin" : "turn" };
|
|
51
|
+
};
|
|
52
|
+
const OPTIONS = new Set([
|
|
53
|
+
"--command-id",
|
|
54
|
+
"--expected-revision",
|
|
55
|
+
"--project",
|
|
56
|
+
"--summary",
|
|
57
|
+
"--to-node",
|
|
58
|
+
"--workspace",
|
|
59
|
+
]);
|
|
60
|
+
const FLAGS = new Set([...TWO_PHASE_FLAGS, "--no-start", "--summary-stdin"]);
|
|
61
|
+
const readRequest = (tokens, context) => {
|
|
62
|
+
const { flags, options, positionals } = parseOptions(tokens, OPTIONS, FLAGS);
|
|
63
|
+
requirePositionals(positionals, 1);
|
|
64
|
+
const commandId = options.get("--command-id");
|
|
65
|
+
if ((commandId?.length ?? 0) > MAX_COMMAND_ID_LENGTH)
|
|
66
|
+
throw new CliArgumentError(`Option '--command-id' takes at most ${String(MAX_COMMAND_ID_LENGTH)} characters; each step adds a suffix.`);
|
|
67
|
+
const mode = readTwoPhaseMode(flags, context);
|
|
68
|
+
if (mode === "confirm-stdin" && flags.has("--summary-stdin"))
|
|
69
|
+
throw new CliArgumentError("Use one of '--summary-stdin' or '--confirm-stdin'; each reads standard input.");
|
|
70
|
+
return {
|
|
71
|
+
...readSummary(options, flags),
|
|
72
|
+
...readTarget(options),
|
|
73
|
+
commandId,
|
|
74
|
+
expectedRevision: options.get("--expected-revision"),
|
|
75
|
+
mode,
|
|
76
|
+
noStart: flags.has("--no-start"),
|
|
77
|
+
sessionId: positionals[0] ?? "",
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const labelsOf = (sourceNode, sessionId, noteId) => Object.fromEntries([
|
|
81
|
+
["moved-from-node", sourceNode],
|
|
82
|
+
["moved-from-session", sessionId],
|
|
83
|
+
...(noteId === undefined ? [] : [["moved-seed-note", noteId]]),
|
|
84
|
+
]);
|
|
85
|
+
const seedOf = (sourceNode, { session, summary }) => `Moved from Maia Node ${sourceNode}, Session ${session.id}.\n\n${summary}`;
|
|
86
|
+
const readSummaryStdin = ({ io }) => {
|
|
87
|
+
if (io.stdin === undefined)
|
|
88
|
+
return Effect.fail(new CliArgumentError("Standard input is unavailable."));
|
|
89
|
+
return io.stdin({
|
|
90
|
+
label: "Session summary",
|
|
91
|
+
maxBytes: MAX_TURN_INPUT_BYTES,
|
|
92
|
+
maxChunks: 1024,
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const summaryOf = (request, session, route) => {
|
|
96
|
+
const { context } = route;
|
|
97
|
+
const { latestTurnId } = session;
|
|
98
|
+
if (request.summary !== undefined)
|
|
99
|
+
return Effect.succeed(request.summary);
|
|
100
|
+
if (request.from === "stdin")
|
|
101
|
+
return readSummaryStdin(context);
|
|
102
|
+
if (latestTurnId === undefined)
|
|
103
|
+
return Effect.fail(refuse(NO_SUMMARY));
|
|
104
|
+
return Effect.flatMap(need(context.dependencies.showTurn(latestTurnId)), ({ turn }) => turn.state === "completed"
|
|
105
|
+
? Effect.succeed(turn.responseText)
|
|
106
|
+
: Effect.fail(refuse(NO_SUMMARY)));
|
|
107
|
+
};
|
|
108
|
+
const unsettled = ({ id, latestTurnState, state, worktree }) => {
|
|
109
|
+
if (!MOVABLE_STATES.has(state))
|
|
110
|
+
return `Session ${id} is ${state}; move it once it settles.`;
|
|
111
|
+
if (worktree !== undefined && worktree.state !== "active")
|
|
112
|
+
return `Session ${id} is archived; it has already moved or ended.`;
|
|
113
|
+
return IN_FLIGHT_TURNS.has(latestTurnState)
|
|
114
|
+
? `Session ${id} has a turn in flight or queued; wait for it or interrupt it first.`
|
|
115
|
+
: undefined;
|
|
116
|
+
};
|
|
117
|
+
const staleRevision = ({ id, revision }, expected) => expected === undefined || expected === revision
|
|
118
|
+
? undefined
|
|
119
|
+
: new Stopped({
|
|
120
|
+
error: {
|
|
121
|
+
code: "storage_conflict",
|
|
122
|
+
message: `Session ${id} is at revision ${revision}, not ${expected}; preview the move again.`,
|
|
123
|
+
retryable: true,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const archivedBefore = (commandId, route, sessionId) => Effect.flatMap(route.context.dependencies.getReceipt(commandId), (found) => {
|
|
127
|
+
if (found.ok) {
|
|
128
|
+
const { method, target } = found.value.receipt;
|
|
129
|
+
return Effect.succeed(method === "session.archive" && target.id === sessionId);
|
|
130
|
+
}
|
|
131
|
+
return found.error.code === "resource_not_found"
|
|
132
|
+
? Effect.succeed(false)
|
|
133
|
+
: Effect.fail(new Stopped(found));
|
|
134
|
+
});
|
|
135
|
+
const archiveCommandId = (commandId) => `${commandId}.archive`;
|
|
136
|
+
const finishing = (route, sessionId) => archivedBefore(archiveCommandId(route.commandId), route, sessionId);
|
|
137
|
+
const hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
138
|
+
const moveCommandId = ({ request, sourceNode }) => {
|
|
139
|
+
if (request.commandId !== undefined)
|
|
140
|
+
return Effect.succeed(request.commandId);
|
|
141
|
+
const { noStart, scope, sessionId, toNode } = request;
|
|
142
|
+
const identity = JSON.stringify([
|
|
143
|
+
sourceNode,
|
|
144
|
+
sessionId,
|
|
145
|
+
toNode,
|
|
146
|
+
scope,
|
|
147
|
+
noStart,
|
|
148
|
+
]);
|
|
149
|
+
return Effect.flatMap(Crypto.Crypto, (crypto) => Effect.map(Effect.orDie(crypto.digest("SHA-256", utf8.encode(identity))), (digest) => `move-${hex(digest).slice(0, 32)}`));
|
|
150
|
+
};
|
|
151
|
+
const readSource = (route) => Effect.gen(function* () {
|
|
152
|
+
const { context, request, sourceNode } = route;
|
|
153
|
+
const { session } = yield* need(context.dependencies.showSession(request.sessionId));
|
|
154
|
+
const blocked = unsettled(session);
|
|
155
|
+
const refusal = blocked === undefined
|
|
156
|
+
? staleRevision(session, request.expectedRevision)
|
|
157
|
+
: refuse(blocked);
|
|
158
|
+
if (refusal !== undefined && !(yield* finishing(route, session.id)))
|
|
159
|
+
return yield* refusal;
|
|
160
|
+
const summary = (yield* summaryOf(request, session, route)).trim();
|
|
161
|
+
if (summary === "")
|
|
162
|
+
return yield* refuse(NO_SUMMARY);
|
|
163
|
+
const { byteLength } = utf8.encode(seedOf(sourceNode, { session, summary }));
|
|
164
|
+
if (request.noStart && byteLength > MAX_PROJECT_CONTEXT_NOTE_BODY_BYTES)
|
|
165
|
+
return yield* refuse(`The seed is ${String(byteLength)} bytes; a Project context note holds ${String(MAX_PROJECT_CONTEXT_NOTE_BODY_BYTES)}. Pass a shorter '--summary'.`);
|
|
166
|
+
return { session, summary };
|
|
167
|
+
});
|
|
168
|
+
const projectOf = ({ request: { scope }, target }) => "projectId" in scope
|
|
169
|
+
? Effect.succeed(scope.projectId)
|
|
170
|
+
: Effect.map(need(target.showWorkspace(scope.workspaceId)), ({ workspace }) => workspace.projectId);
|
|
171
|
+
const planOf = (route, source) => Effect.gen(function* () {
|
|
172
|
+
const { request, sourceNode, target } = route;
|
|
173
|
+
const { executor, id } = source.session;
|
|
174
|
+
if (target.planSessions === undefined)
|
|
175
|
+
return yield* new CliArgumentError("Session creation is unavailable.");
|
|
176
|
+
const plan = yield* need(target.planSessions({
|
|
177
|
+
...request.scope,
|
|
178
|
+
session: {
|
|
179
|
+
...(executor === undefined ? {} : { executor: executor.kind }),
|
|
180
|
+
labels: labelsOf(sourceNode, id),
|
|
181
|
+
},
|
|
182
|
+
split: "whole",
|
|
183
|
+
text: seedOf(sourceNode, source),
|
|
184
|
+
}));
|
|
185
|
+
if (plan.refusals.length > 0 || plan.items.length !== 1)
|
|
186
|
+
return yield* refuse("The summary does not fit one first message; pass a shorter '--summary'.");
|
|
187
|
+
return plan;
|
|
188
|
+
});
|
|
189
|
+
const readMove = (route) => Effect.gen(function* () {
|
|
190
|
+
const source = yield* readSource(route);
|
|
191
|
+
const projectId = yield* projectOf(route);
|
|
192
|
+
const plan = yield* planOf(route, source);
|
|
193
|
+
return { ...route, ...source, plan, projectId };
|
|
194
|
+
});
|
|
195
|
+
const outcomeFailure = (plan, outcome) => {
|
|
196
|
+
const item = outcome === undefined ? undefined : reportItem(plan, outcome);
|
|
197
|
+
return {
|
|
198
|
+
error: (item === undefined ? undefined : batchError([item])) ?? {
|
|
199
|
+
code: "incomplete",
|
|
200
|
+
message: `The new Session stopped at ${outcome?.stage ?? "an unknown step"}.`,
|
|
201
|
+
retryable: true,
|
|
202
|
+
},
|
|
203
|
+
recovery: item?.recovery,
|
|
204
|
+
sessionId: item?.sessionId,
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const createUnstarted = ({ commandId, plan, target }) => Effect.gen(function* () {
|
|
208
|
+
if (target.runSessions === undefined)
|
|
209
|
+
return yield* new CliArgumentError("Session creation is unavailable.");
|
|
210
|
+
const [outcome] = yield* need(target.runSessions(withCommandId(plan, commandId), { until: "created" }));
|
|
211
|
+
const first = { archived: false };
|
|
212
|
+
if (outcome?.stage === "created" && outcome.sessionId !== undefined)
|
|
213
|
+
return { ...first, sessionId: outcome.sessionId };
|
|
214
|
+
return { ...first, ...outcomeFailure(plan, outcome) };
|
|
215
|
+
});
|
|
216
|
+
const startSeeded = ({ commandId, plan, target }, done) => Effect.gen(function* () {
|
|
217
|
+
if (target.runSessions === undefined)
|
|
218
|
+
return yield* new CliArgumentError("Session creation is unavailable.");
|
|
219
|
+
const [outcome] = yield* need(target.runSessions(withCommandId(plan, commandId)));
|
|
220
|
+
if (outcome?.stage === "sent")
|
|
221
|
+
return done;
|
|
222
|
+
const { sessionId = done.sessionId, ...failure } = outcomeFailure(plan, outcome);
|
|
223
|
+
return { ...done, ...failure, sessionId };
|
|
224
|
+
});
|
|
225
|
+
const createSeeded = (move) => {
|
|
226
|
+
const { commandId, plan, projectId, session, sourceNode, target } = move;
|
|
227
|
+
return Effect.gen(function* () {
|
|
228
|
+
const { note } = yield* need(target.recordProjectContext({
|
|
229
|
+
body: seedOf(sourceNode, move),
|
|
230
|
+
commandId: `${commandId}.seed`,
|
|
231
|
+
projectId,
|
|
232
|
+
}));
|
|
233
|
+
const seeded = { archived: false, seedNoteId: note.id };
|
|
234
|
+
return yield* need(target.createSession({
|
|
235
|
+
commandId,
|
|
236
|
+
executor: session.executor?.kind,
|
|
237
|
+
labels: labelsOf(sourceNode, session.id, note.id),
|
|
238
|
+
workspaceId: plan.workspaceId,
|
|
239
|
+
})).pipe(Effect.map(({ session: created }) => ({
|
|
240
|
+
...seeded,
|
|
241
|
+
revision: created.revision,
|
|
242
|
+
sessionId: created.id,
|
|
243
|
+
})), Effect.catchTag("MoveStopped", stopped(seeded)));
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
const archiveSource = (move, done, movedId) => {
|
|
247
|
+
const { context, request, session } = move;
|
|
248
|
+
const { archiveSession } = context.dependencies;
|
|
249
|
+
const commandId = archiveCommandId(move.commandId);
|
|
250
|
+
return Effect.gen(function* () {
|
|
251
|
+
if (yield* archivedBefore(commandId, move, session.id))
|
|
252
|
+
return { ...done, archived: true };
|
|
253
|
+
if (archiveSession === undefined)
|
|
254
|
+
return yield* refuse("Archiving a Session is unavailable.");
|
|
255
|
+
const { archive } = yield* need(archiveSession({
|
|
256
|
+
commandId,
|
|
257
|
+
expectedRevision: session.revision,
|
|
258
|
+
sessionId: session.id,
|
|
259
|
+
summary: `Moved to ${request.toNode}:${movedId}`,
|
|
260
|
+
}));
|
|
261
|
+
return { ...done, archived: true, kept: archive };
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
const applyMove = (move) => Effect.gen(function* () {
|
|
265
|
+
const create = move.request.noStart
|
|
266
|
+
? createSeeded
|
|
267
|
+
: createUnstarted;
|
|
268
|
+
const created = yield* create(move).pipe(Effect.catchTag("MoveStopped", stopped({ archived: false })));
|
|
269
|
+
const { error, sessionId } = created;
|
|
270
|
+
if (error !== undefined || sessionId === undefined)
|
|
271
|
+
return created;
|
|
272
|
+
const archived = yield* archiveSource(move, created, sessionId).pipe(Effect.catchTag("MoveStopped", stopped(created)));
|
|
273
|
+
if (archived.error !== undefined || move.request.noStart)
|
|
274
|
+
return archived;
|
|
275
|
+
return yield* startSeeded(move, archived).pipe(Effect.catchTag("MoveStopped", stopped(archived)));
|
|
276
|
+
});
|
|
277
|
+
const CARRIES = "summary";
|
|
278
|
+
const CARRIES_TEXT = "the summary only; no native history and no code moves with it";
|
|
279
|
+
const worktreeOf = ({ worktree }, node) => worktree === undefined ? undefined : { branch: worktree.branch, node };
|
|
280
|
+
const stepsOf = (move, worktree) => {
|
|
281
|
+
const { projectId, request, session, sourceNode } = move;
|
|
282
|
+
const { noStart, toNode } = request;
|
|
283
|
+
return [
|
|
284
|
+
noStart
|
|
285
|
+
? `Record the seed as a context note on Project ${projectId} and create a Session on ${toNode} that starts nothing.`
|
|
286
|
+
: `Create a Session on ${toNode}; it does not start yet.`,
|
|
287
|
+
`Stop and archive ${session.id} on ${sourceNode} with the summary "Moved to ${toNode}:<new Session>".`,
|
|
288
|
+
...(worktree === undefined
|
|
289
|
+
? []
|
|
290
|
+
: [
|
|
291
|
+
`The archive commits any uncommitted work to branch ${worktree.branch} on ${sourceNode}. The branch stays there, is not copied to ${toNode} and is never deleted; the checkout folder is removed later, only once clean.`,
|
|
292
|
+
]),
|
|
293
|
+
...(noStart
|
|
294
|
+
? []
|
|
295
|
+
: [`Start the new Session on ${toNode} and send it the summary.`]),
|
|
296
|
+
];
|
|
297
|
+
};
|
|
298
|
+
const previewOf = (move) => {
|
|
299
|
+
const { plan, projectId, request, session, sourceNode, summary } = move;
|
|
300
|
+
const worktree = worktreeOf(session, sourceNode);
|
|
301
|
+
return {
|
|
302
|
+
carries: CARRIES,
|
|
303
|
+
labels: labelsOf(sourceNode, session.id),
|
|
304
|
+
source: {
|
|
305
|
+
node: sourceNode,
|
|
306
|
+
revision: session.revision,
|
|
307
|
+
sessionId: session.id,
|
|
308
|
+
},
|
|
309
|
+
started: !request.noStart,
|
|
310
|
+
steps: stepsOf(move, worktree),
|
|
311
|
+
summary: { bytes: utf8.encode(summary).byteLength, from: request.from },
|
|
312
|
+
target: { node: request.toNode, projectId, workspaceId: plan.workspaceId },
|
|
313
|
+
...(worktree === undefined ? {} : { worktree }),
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
const laterCommands = (node, done) => {
|
|
317
|
+
const { archived, revision, seedNoteId, sessionId } = done;
|
|
318
|
+
if (!archived || revision === undefined || seedNoteId === undefined)
|
|
319
|
+
return undefined;
|
|
320
|
+
const maia = node === LOCAL_NODE ? "maia" : `maia --node ${node}`;
|
|
321
|
+
return [
|
|
322
|
+
`${maia} session start ${String(sessionId)} --expected-revision ${revision} --wait`,
|
|
323
|
+
`${maia} --json project context show ${seedNoteId} | jq -r .result.result.note.body | ${maia} session turn send --session ${String(sessionId)} --prompt-stdin --wait`,
|
|
324
|
+
];
|
|
325
|
+
};
|
|
326
|
+
const resultOf = (move, done) => {
|
|
327
|
+
const { request, session, sourceNode } = move;
|
|
328
|
+
const { archived, kept, recovery, revision, seedNoteId, sessionId } = done;
|
|
329
|
+
const worktree = worktreeOf(session, sourceNode);
|
|
330
|
+
return {
|
|
331
|
+
archived,
|
|
332
|
+
carries: CARRIES,
|
|
333
|
+
next: laterCommands(request.toNode, done),
|
|
334
|
+
recovery,
|
|
335
|
+
seedNoteId,
|
|
336
|
+
source: { node: sourceNode, sessionId: session.id },
|
|
337
|
+
started: !request.noStart,
|
|
338
|
+
target: { node: request.toNode, revision, sessionId },
|
|
339
|
+
worktree: worktree && {
|
|
340
|
+
...worktree,
|
|
341
|
+
branchRevision: kept?.branchRevision,
|
|
342
|
+
snapshot: kept?.snapshot,
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
const formatPreview = ({ labels, source, steps, summary, target, worktree, }) => `${fields([
|
|
347
|
+
["move", `${source.sessionId} on ${source.node} to ${target.node}`],
|
|
348
|
+
["carries", CARRIES_TEXT],
|
|
349
|
+
["revision", source.revision],
|
|
350
|
+
["project", target.projectId],
|
|
351
|
+
["workspace", target.workspaceId],
|
|
352
|
+
["summary", `${String(summary.bytes)} bytes (${summary.from})`],
|
|
353
|
+
["labels", labelCells(labels)],
|
|
354
|
+
[
|
|
355
|
+
"branch",
|
|
356
|
+
worktree && `${worktree.branch} stays on ${worktree.node}, not copied`,
|
|
357
|
+
],
|
|
358
|
+
])}${steps.map((step, index) => `${String(index + 1)}. ${step}`).join("\n")}\n`;
|
|
359
|
+
const stoppedAt = ({ archived, source, target, }) => {
|
|
360
|
+
const { node, sessionId } = target;
|
|
361
|
+
if (sessionId === undefined)
|
|
362
|
+
return `No Session was created on ${node}; the source is unchanged`;
|
|
363
|
+
return archived
|
|
364
|
+
? `Created ${sessionId} on ${node} and archived the source ${source.sessionId}, but the new Session did not start`
|
|
365
|
+
: `Created ${sessionId} on ${node}, but the source ${source.sessionId} is not archived`;
|
|
366
|
+
};
|
|
367
|
+
const formatResult = (output, error) => {
|
|
368
|
+
const { next, seedNoteId, source, started, target, worktree } = output;
|
|
369
|
+
if (error !== undefined)
|
|
370
|
+
return `${stoppedAt(output)}: ${error.message}\n`;
|
|
371
|
+
const { node, sessionId } = target;
|
|
372
|
+
const moved = `Moved ${source.sessionId} on ${source.node} to ${String(sessionId)} on ${node}${started ? "" : " without a first turn"}; the source is archived.\n${fields([
|
|
373
|
+
["carries", CARRIES_TEXT],
|
|
374
|
+
[
|
|
375
|
+
"branch",
|
|
376
|
+
worktree &&
|
|
377
|
+
`${worktree.branch} stays on ${worktree.node}${worktree.snapshot === "committed" ? ", uncommitted work committed to it" : ""}`,
|
|
378
|
+
],
|
|
379
|
+
])}`;
|
|
380
|
+
if (next === undefined)
|
|
381
|
+
return moved;
|
|
382
|
+
return `${moved}${fields([["seed note", seedNoteId]])}To send it as the first turn, run:\n${next.map((command) => ` ${command}\n`).join("")}The second takes the revision the first prints.\n`;
|
|
383
|
+
};
|
|
384
|
+
const writeOutcome = (move) => (response) => {
|
|
385
|
+
const { context } = move;
|
|
386
|
+
if (!response.ok)
|
|
387
|
+
return reportError(response.error, context);
|
|
388
|
+
const { error } = response.value;
|
|
389
|
+
const failure = error && {
|
|
390
|
+
...error,
|
|
391
|
+
message: `${error.message} Run the same command again to finish.`,
|
|
392
|
+
};
|
|
393
|
+
writeSuccess({ command: "session.move", result: resultOf(move, response.value) }, failure === undefined
|
|
394
|
+
? context
|
|
395
|
+
: { ...context, error: failure, ok: false }, (output) => formatResult(output.result, failure));
|
|
396
|
+
return failure === undefined ? 0 : exitCodeOf(failure);
|
|
397
|
+
};
|
|
398
|
+
const writePreview = (context) => (response) => {
|
|
399
|
+
if (!response.ok)
|
|
400
|
+
return reportError(response.error, context);
|
|
401
|
+
writeSuccess({ command: "session.move.preview", result: response.value }, context, (output) => formatPreview(output.result));
|
|
402
|
+
return 0;
|
|
403
|
+
};
|
|
404
|
+
const STALE_PREVIEW = "The piped preview is not this move's preview now; pipe the output of the same command with '--json --dry-run'.";
|
|
405
|
+
const asPiped = (preview) => decodeJsonText(JSON.stringify(preview), () => new CliArgumentError(STALE_PREVIEW));
|
|
406
|
+
const moveSession = (intent) => {
|
|
407
|
+
const { context, request } = intent;
|
|
408
|
+
return Effect.gen(function* () {
|
|
409
|
+
const route = { ...intent, commandId: yield* moveCommandId(intent) };
|
|
410
|
+
const move = yield* readMove(route);
|
|
411
|
+
const preview = previewOf(move);
|
|
412
|
+
return yield* runTwoPhase({
|
|
413
|
+
confirm: (confirming) => Effect.flatMap(asPiped(preview), (current) => isDeepStrictEqual(confirming, current)
|
|
414
|
+
? Effect.map(applyMove(move), ok)
|
|
415
|
+
: Effect.fail(new CliArgumentError(STALE_PREVIEW))),
|
|
416
|
+
context,
|
|
417
|
+
mode: request.mode,
|
|
418
|
+
preview: () => Effect.succeed(ok(preview)),
|
|
419
|
+
prompt: { describe: formatPreview, question: "Move this Session?" },
|
|
420
|
+
writeConfirm: writeOutcome(move),
|
|
421
|
+
writePreview: writePreview(context),
|
|
422
|
+
});
|
|
423
|
+
}).pipe(Effect.catchTag("MoveStopped", ({ error }) => Effect.sync(() => reportError(error, context))));
|
|
424
|
+
};
|
|
425
|
+
export const runSessionMove = (tokens, context) => {
|
|
426
|
+
const request = readRequest(tokens, context);
|
|
427
|
+
const sourceNode = context.node ?? LOCAL_NODE;
|
|
428
|
+
if (request.toNode === sourceNode)
|
|
429
|
+
throw new CliArgumentError("The target is the Session's own Node; name another Node with '--to-node'.");
|
|
430
|
+
if (context.bindNode === undefined)
|
|
431
|
+
throw new CliArgumentError("Moving a Session to another Node is unavailable here.");
|
|
432
|
+
return moveSession({
|
|
433
|
+
context,
|
|
434
|
+
request,
|
|
435
|
+
sourceNode,
|
|
436
|
+
target: context.bindNode(request.toNode),
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
//# sourceMappingURL=move.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cell, formatRows, tab } from "../../command-line/emit/index.js";
|
|
2
|
+
const HELD_HEADERS = [
|
|
3
|
+
"SESSION",
|
|
4
|
+
"HELD TASK",
|
|
5
|
+
"STATE",
|
|
6
|
+
"CLAIMED",
|
|
7
|
+
"LEASE UNTIL",
|
|
8
|
+
"TITLE",
|
|
9
|
+
];
|
|
10
|
+
const moreLines = (sessions) => sessions
|
|
11
|
+
.filter((session) => (session.heldTaskCount ?? 0) > (session.heldTasks?.length ?? 0))
|
|
12
|
+
.map((session) => `more held by ${session.id}: maia board tasks list --session ${session.id}\n`)
|
|
13
|
+
.join("");
|
|
14
|
+
export const formatHeldTasks = (sessions) => {
|
|
15
|
+
const rows = sessions.flatMap((session) => (session.heldTasks ?? []).map((task) => ({ session: session.id, task })));
|
|
16
|
+
const table = rows.length === 0
|
|
17
|
+
? ""
|
|
18
|
+
: formatRows(rows, ({ session, task }) => tab([
|
|
19
|
+
session,
|
|
20
|
+
task.id,
|
|
21
|
+
task.state,
|
|
22
|
+
task.claimedAt,
|
|
23
|
+
task.leaseExpiresAt,
|
|
24
|
+
cell(task.title),
|
|
25
|
+
]), { empty: "", headers: HELD_HEADERS });
|
|
26
|
+
return `${table}${moreLines(sessions)}`;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=held.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cell, fields, formatRows, labelCells, tab, withPrunedHistory, writeNodeResult, } from "../../command-line/index.js";
|
|
2
2
|
import { formatSessionDiff } from "./diff.js";
|
|
3
3
|
import { formatFailure, formatSessionEvents } from "./failure.js";
|
|
4
|
+
import { formatHeldTasks } from "./held.js";
|
|
4
5
|
import { formatSessionObservation } from "./observe.js";
|
|
5
6
|
import { activityLabel, formatSessionList, formatSessionTasks, } from "./tasks.js";
|
|
6
7
|
const formatSessionInbox = (deliveries) => formatRows(deliveries, (delivery) => `${delivery.deliveryId}\t${delivery.sequence}\t${cell(delivery.message.senderSessionId)}\t${cell(delivery.message.subject)}\t${cell(delivery.message.body)}`);
|
|
@@ -41,7 +42,15 @@ const formatPrompt = (prompt) => prompt === undefined
|
|
|
41
42
|
.join("\n")}\n${(prompt.options ?? [])
|
|
42
43
|
.map((option) => ` ${option.optionId}\t${option.label}\n`)
|
|
43
44
|
.join("")}`;
|
|
44
|
-
|
|
45
|
+
const formatRemoteChild = ({ node, observedState, orphanedAt, sessionId, state, }) => `${tab([
|
|
46
|
+
"child",
|
|
47
|
+
node,
|
|
48
|
+
sessionId,
|
|
49
|
+
state === "orphaned"
|
|
50
|
+
? `orphaned since ${orphanedAt ?? "-"}`
|
|
51
|
+
: (observedState ?? state),
|
|
52
|
+
])}\n`;
|
|
53
|
+
export const formatSessionShow = ({ remoteChildren = [], session, }) => `${fields([
|
|
45
54
|
["session", session.id],
|
|
46
55
|
["state", session.state],
|
|
47
56
|
...(session.status === undefined
|
|
@@ -62,16 +71,34 @@ export const formatSessionShow = ({ session, }) => `${fields([
|
|
|
62
71
|
session.labels === undefined ? undefined : labelCells(session.labels),
|
|
63
72
|
],
|
|
64
73
|
["updated", session.updatedAt],
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
["held-tasks", session.heldTaskCount?.toString()],
|
|
75
|
+
])}${formatHeldTasks([session])}${formatPrompt(session.prompt)}${formatFailure(session.failure)}${formatFailure(session.recovery, "recovering")}${remoteChildren.map(formatRemoteChild).join("")}`;
|
|
76
|
+
const formatChildStop = ({ error, node, orphanedAt, sessionId, state, }) => `${tab([
|
|
77
|
+
"child",
|
|
78
|
+
node,
|
|
79
|
+
sessionId ?? "-",
|
|
80
|
+
error === undefined
|
|
81
|
+
? (state ?? "-")
|
|
82
|
+
: `${orphanedAt === undefined ? "not stopped" : `orphaned since ${orphanedAt}`}: ${cell(error.message)}`,
|
|
83
|
+
])}\n`;
|
|
84
|
+
const formatLifecycle = ({ children = [], revision, sessionId, state, }) => `${fields([
|
|
67
85
|
["session", sessionId],
|
|
68
86
|
["state", state],
|
|
69
87
|
["revision", revision],
|
|
70
|
-
])}${state === "starting" ? `next: maia session start ${sessionId} --expected-revision ${revision} --wait returns once it runs; maia session show ${sessionId} shows it now\n` : ""}`;
|
|
88
|
+
])}${children.map(formatChildStop).join("")}${state === "starting" ? `next: maia session start ${sessionId} --expected-revision ${revision} --wait returns once it runs; maia session show ${sessionId} shows it now\n` : ""}`;
|
|
71
89
|
const formatSessions = (result) => result.items.length === 0 ? "No Sessions.\n" : formatSessionList(result);
|
|
72
90
|
const formatInboxAck = ({ delivery, deliveryRecord, mailboxRevision, }) => `${tab([deliveryRecord.deliveryId, delivery, mailboxRevision])}\n`;
|
|
73
91
|
const formatMessageSend = ({ delivery, deliveryId, sequence, }) => `${tab([deliveryId, delivery, sequence])}\n`;
|
|
74
92
|
const formatEventsPage = ({ items, oldestRetainedCursor, }) => withPrunedHistory(formatSessionEvents(items), oldestRetainedCursor !== undefined);
|
|
93
|
+
const formatParent = (result) => result.command === "session.show"
|
|
94
|
+
? formatSessionShow(result.result)
|
|
95
|
+
: formatReconcile(result.result);
|
|
96
|
+
const formatInbox = (result) => result.command === "session.inbox.ack"
|
|
97
|
+
? formatInboxAck(result.result)
|
|
98
|
+
: formatSessionInbox(result.result.deliveries);
|
|
99
|
+
const formatReconcile = ({ children, sessionId, }) => children.length === 0
|
|
100
|
+
? `Nothing to reconcile below ${sessionId}.\n`
|
|
101
|
+
: children.map(formatChildStop).join("");
|
|
75
102
|
export const formatSessionResult = (result) => {
|
|
76
103
|
switch (result.command) {
|
|
77
104
|
case "session.agent-permission.confirm":
|
|
@@ -85,17 +112,17 @@ export const formatSessionResult = (result) => {
|
|
|
85
112
|
case "session.events.list":
|
|
86
113
|
return formatEventsPage(result.result);
|
|
87
114
|
case "session.inbox.ack":
|
|
88
|
-
return formatInboxAck(result.result);
|
|
89
115
|
case "session.inbox.check":
|
|
90
|
-
return
|
|
116
|
+
return formatInbox(result);
|
|
91
117
|
case "session.list":
|
|
92
118
|
return formatSessions(result.result);
|
|
93
119
|
case "session.message.send":
|
|
94
120
|
return formatMessageSend(result.result);
|
|
95
121
|
case "session.observe":
|
|
96
122
|
return formatSessionObservation(result.result);
|
|
123
|
+
case "session.reconcile":
|
|
97
124
|
case "session.show":
|
|
98
|
-
return
|
|
125
|
+
return formatParent(result);
|
|
99
126
|
case "session.resume":
|
|
100
127
|
case "session.start":
|
|
101
128
|
case "session.stop":
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatMerged } from "../../address-space/index.js";
|
|
2
2
|
import { cell, fields, formatRows, labelCells, tab, withNextPage, } from "../../command-line/index.js";
|
|
3
3
|
import { formatFailureCell } from "./failure.js";
|
|
4
|
+
import { formatHeldTasks } from "./held.js";
|
|
4
5
|
const failureDetail = ({ failure, message, }) => {
|
|
5
6
|
if (failure !== undefined)
|
|
6
7
|
return formatFailureCell(failure);
|
|
@@ -53,10 +54,25 @@ export const activityLabel = (session) => {
|
|
|
53
54
|
? "done"
|
|
54
55
|
: (session.activity ?? "-");
|
|
55
56
|
};
|
|
56
|
-
const sessionHeaders = (items) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const sessionHeaders = (items) => [
|
|
58
|
+
...SESSION_HEADERS,
|
|
59
|
+
...(items.some((session) => session.settledReason !== undefined)
|
|
60
|
+
? ["SETTLED"]
|
|
61
|
+
: []),
|
|
62
|
+
...(items.some((session) => session.heldTaskCount !== undefined)
|
|
63
|
+
? ["HELD"]
|
|
64
|
+
: []),
|
|
65
|
+
];
|
|
66
|
+
const settledCells = (session, headers) => [
|
|
67
|
+
...(headers.includes("SETTLED") ? [session.settledReason ?? "-"] : []),
|
|
68
|
+
...(headers.includes("HELD")
|
|
69
|
+
? [
|
|
70
|
+
session.heldTaskCount === undefined
|
|
71
|
+
? "-"
|
|
72
|
+
: String(session.heldTaskCount),
|
|
73
|
+
]
|
|
74
|
+
: []),
|
|
75
|
+
];
|
|
60
76
|
const sessionCells = (session, attention) => [
|
|
61
77
|
session.id,
|
|
62
78
|
session.state,
|
|
@@ -72,10 +88,11 @@ const sessionCells = (session, attention) => [
|
|
|
72
88
|
export const formatSessionList = (result) => {
|
|
73
89
|
const attention = new Map((result.attention ?? []).map((item) => [item.sessionId, item.attention]));
|
|
74
90
|
const headers = sessionHeaders(result.items);
|
|
75
|
-
|
|
91
|
+
const held = formatHeldTasks(result.items);
|
|
92
|
+
return withNextPage(`${formatRows(result.items, (session) => tab([
|
|
76
93
|
...sessionCells(session, attention.get(session.id)),
|
|
77
94
|
...settledCells(session, headers),
|
|
78
|
-
]), { empty: "No Sessions.", headers })
|
|
95
|
+
]), { empty: "No Sessions.", headers })}${held === "" ? "" : `\n${held}`}`, result.nextCursor);
|
|
79
96
|
};
|
|
80
97
|
const sessionKey = (node, id) => `${node} ${id}`;
|
|
81
98
|
export const formatMergedSessions = ({ result, }) => {
|