@maiaos/cli 0.1.0-canary.5 → 0.1.0-canary.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +2 -2
  2. package/dist/agents/client.d.ts +47 -27
  3. package/dist/agents/client.js +10 -3
  4. package/dist/agents/commands.d.ts +1 -0
  5. package/dist/agents/commands.js +24 -2
  6. package/dist/agents/index.d.ts +1 -1
  7. package/dist/agents/index.js +1 -1
  8. package/dist/agents/input.d.ts +3 -1
  9. package/dist/agents/input.js +6 -0
  10. package/dist/agents/output/format.d.ts +2 -2
  11. package/dist/agents/output/format.js +11 -0
  12. package/dist/agents/tree/tree.js +13 -1
  13. package/dist/bin/maia.cdx.json +19 -19
  14. package/dist/bin/maia.mjs +1 -1
  15. package/dist/bootstrap/run.js +5 -2
  16. package/dist/cli/cli.d.ts +8 -2
  17. package/dist/cli/cli.js +19 -6
  18. package/dist/cli/index.d.ts +1 -1
  19. package/dist/cli/index.js +1 -1
  20. package/dist/command-line/context.d.ts +2 -1
  21. package/dist/command-line/emit/index.d.ts +4 -0
  22. package/dist/command-line/emit/index.js +4 -0
  23. package/dist/command-line/{output.d.ts → emit/output.d.ts} +2 -2
  24. package/dist/command-line/{rows.d.ts → emit/rows.d.ts} +1 -0
  25. package/dist/command-line/{rows.js → emit/rows.js} +3 -0
  26. package/dist/command-line/index.d.ts +4 -4
  27. package/dist/command-line/index.js +4 -4
  28. package/dist/command-line/input/arguments.d.ts +10 -0
  29. package/dist/command-line/input/arguments.js +30 -10
  30. package/dist/command-line/input/index.d.ts +1 -1
  31. package/dist/command-line/input/index.js +1 -1
  32. package/dist/command-line/two-phase.js +1 -1
  33. package/dist/command-receipt/command.js +1 -1
  34. package/dist/command-tree/tree.d.ts +1 -1
  35. package/dist/command-tree/tree.js +3 -1
  36. package/dist/connection/input.js +2 -2
  37. package/dist/connection/system.js +3 -2
  38. package/dist/connection/tree/tree.js +5 -5
  39. package/dist/events/commands.d.ts +11 -0
  40. package/dist/events/commands.js +64 -0
  41. package/dist/events/index.d.ts +2 -0
  42. package/dist/events/index.js +2 -0
  43. package/dist/events/tree/index.d.ts +2 -0
  44. package/dist/events/tree/index.js +2 -0
  45. package/dist/events/tree/tree.d.ts +10 -0
  46. package/dist/events/tree/tree.js +17 -0
  47. package/dist/import/commands.js +1 -1
  48. package/dist/import/input.d.ts +4 -1
  49. package/dist/import/input.js +23 -2
  50. package/dist/import/output.js +3 -1
  51. package/dist/local-node/client.d.ts +1 -0
  52. package/dist/local-node/client.js +1 -0
  53. package/dist/local-node/index.d.ts +2 -1
  54. package/dist/local-node/index.js +2 -1
  55. package/dist/local-node/wait.d.ts +10 -0
  56. package/dist/local-node/wait.js +17 -0
  57. package/dist/login/gateway.js +2 -2
  58. package/dist/login/vendor-input.js +2 -2
  59. package/dist/mcp/calls.js +6 -1
  60. package/dist/mcp/routing.js +1 -0
  61. package/dist/project-guard/client.d.ts +12 -0
  62. package/dist/project-guard/input.d.ts +3 -0
  63. package/dist/project-guard/input.js +15 -1
  64. package/dist/project-guard/output/format.js +5 -0
  65. package/dist/project-workspace/tree/tree.js +1 -1
  66. package/dist/reference/resolve.js +9 -2
  67. package/dist/remote-node/connector.js +8 -1
  68. package/dist/run-ledger/client.d.ts +2 -0
  69. package/dist/session/agent-permission.d.ts +2 -2
  70. package/dist/session/approval/client.d.ts +5 -2
  71. package/dist/session/approval/client.js +2 -2
  72. package/dist/session/approval/commands.js +29 -15
  73. package/dist/session/client.d.ts +14 -3
  74. package/dist/session/client.js +17 -2
  75. package/dist/session/commands.d.ts +1 -0
  76. package/dist/session/commands.js +125 -9
  77. package/dist/session/create-tasks.js +10 -2
  78. package/dist/session/index.d.ts +1 -1
  79. package/dist/session/index.js +1 -1
  80. package/dist/session/output/human.d.ts +3 -0
  81. package/dist/session/output/human.js +20 -4
  82. package/dist/session/output/index.d.ts +1 -1
  83. package/dist/session/output/index.js +1 -1
  84. package/dist/session/output/tasks.d.ts +2 -0
  85. package/dist/session/output/tasks.js +34 -4
  86. package/dist/session/tree/tree.js +23 -12
  87. package/dist/session/turn/client.js +7 -9
  88. package/dist/session/turn/commands.js +67 -20
  89. package/dist/session/turn/output.d.ts +6 -0
  90. package/dist/session/turn/output.js +12 -2
  91. package/dist/status/client.d.ts +14 -3
  92. package/dist/status/command.js +3 -1
  93. package/dist/status/doctor.d.ts +5 -1
  94. package/dist/status/doctor.js +10 -4
  95. package/dist/status/output/compact.d.ts +3 -0
  96. package/dist/status/output/compact.js +17 -7
  97. package/dist/status/output/human.js +15 -0
  98. package/dist/terminal/control-commands.js +26 -9
  99. package/dist/terminal/keys.d.ts +12 -0
  100. package/dist/terminal/keys.js +62 -0
  101. package/dist/terminal/output/compact-list.d.ts +1 -0
  102. package/dist/terminal/output/compact-list.js +3 -0
  103. package/dist/terminal/output/human.js +2 -2
  104. package/dist/terminal/tree/tree.js +1 -1
  105. package/guidance/maia-cli/SKILL.md +1 -1
  106. package/guidance/maia-node/SKILL.md +54 -0
  107. package/guidance/maia-orchestration/SKILL.md +1 -2
  108. package/guidance/maia-sessions/SKILL.md +69 -0
  109. package/package.json +4 -4
  110. /package/dist/command-line/{json-decoder.d.ts → emit/json-decoder.d.ts} +0 -0
  111. /package/dist/command-line/{json-decoder.js → emit/json-decoder.js} +0 -0
  112. /package/dist/command-line/{json.d.ts → emit/json.d.ts} +0 -0
  113. /package/dist/command-line/{json.js → emit/json.js} +0 -0
  114. /package/dist/command-line/{output.js → emit/output.js} +0 -0
@@ -1,9 +1,17 @@
1
1
  import { formatMerged } from "../../address-space/index.js";
2
2
  import { cell, fields, formatRows, tab, withNextPage, } from "../../command-line/index.js";
3
3
  import { formatFailureCell } from "./failure.js";
4
- const failure = ({ error }) => error === undefined
5
- ? undefined
6
- : `${error.operationId}:${error.code ?? error.kind}${error.failure === undefined ? "" : ` (${formatFailureCell(error.failure)})`}`;
4
+ const failureDetail = ({ failure, message, }) => {
5
+ if (failure !== undefined)
6
+ return formatFailureCell(failure);
7
+ return message === undefined ? undefined : cell(message);
8
+ };
9
+ const failure = ({ error }) => {
10
+ if (error === undefined)
11
+ return undefined;
12
+ const detail = failureDetail(error);
13
+ return `${error.operationId}:${error.code ?? error.kind}${detail === undefined ? "" : ` (${detail})`}`;
14
+ };
7
15
  export const formatSessionTasks = ({ items }) => items.length === 1
8
16
  ? items
9
17
  .map((item) => fields([
@@ -25,13 +33,35 @@ export const formatSessionTasks = ({ items }) => items.length === 1
25
33
  empty: "",
26
34
  headers: ["LINE", "STAGE", "SESSION", "TURN", "COMMAND", "ERROR"],
27
35
  });
28
- const SESSION_HEADERS = ["SESSION", "STATE", "WORKSPACE", "ATTENTION", "TITLE"];
36
+ const SESSION_HEADERS = [
37
+ "SESSION",
38
+ "STATE",
39
+ "ACTIVITY",
40
+ "WORKSPACE",
41
+ "ATTENTION",
42
+ "CONTAINMENT",
43
+ "TITLE",
44
+ "LABELS",
45
+ "LAST ACTIVE",
46
+ ];
47
+ export const activityLabel = (session) => session.activity === "idle" && session.latestTurnState === "completed"
48
+ ? "done"
49
+ : (session.activity ?? "-");
50
+ export const labelCells = (labels) => labels === undefined
51
+ ? "-"
52
+ : Object.entries(labels)
53
+ .map(([key, value]) => `${key}=${value}`)
54
+ .join(",");
29
55
  const sessionCells = (session, attention) => [
30
56
  session.id,
31
57
  session.state,
58
+ activityLabel(session),
32
59
  session.workspaceId,
33
60
  attention ?? "-",
61
+ session.containment ?? "-",
34
62
  cell(session.title ?? "-"),
63
+ labelCells(session.labels),
64
+ session.updatedAt,
35
65
  ];
36
66
  export const formatSessionList = (result) => {
37
67
  const attention = new Map((result.attention ?? []).map((item) => [item.sessionId, item.attention]));
@@ -18,7 +18,7 @@ export const SESSION_TREE = {
18
18
  ],
19
19
  leaves: [
20
20
  [
21
- "session create (--workspace <workspace-id> | --project <project-id>) [--command-id <id>] [--role <worker|orchestrator>] [--connection <connection-id> [--executor <codex-cli|claude-code>] [--model <id>] | --executor <codex-cli|claude-code> | --agent <agent-id> | --agent-definition <key> --agent-definition-version <version> --agent-definition-digest <sha256>] [--effort <low|medium|high|xhigh|max|ultra>] [--base <branch-tag-or-commit>] [--title <text>] [--message <text> | --prompt-stdin | --from-file <path>]",
21
+ "session create (--workspace <workspace-id> | --project <project-id>) [--command-id <id>] [--role <worker|orchestrator>] [--connection <connection-id> [--executor <codex-cli|claude-code>] [--model <id>] | --executor <codex-cli|claude-code> | --agent <agent-id> | --agent-definition <key> --agent-definition-version <version> --agent-definition-digest <sha256>] [--effort <low|medium|high|xhigh|max|ultra>] [--base <branch-tag-or-commit> | --host-authority [--permission <mode>]] [--cwd <path>] [--title <text> | --name <text>] [--label <key=value>...] [--message <text> | --prompt-stdin | --from-file <path>]",
22
22
  0,
23
23
  "session.create",
24
24
  "Create a Session, optionally starting it with a first message.",
@@ -50,6 +50,17 @@ export const SESSION_TREE = {
50
50
  run: [session, "runSessionShow"],
51
51
  },
52
52
  ],
53
+ [
54
+ "session wait <session-id> [--until <state>[,<state>...]] [--activity <activity>[,<activity>...]] [--timeout <duration>]",
55
+ 1,
56
+ "session.wait",
57
+ "Wait until a Session reaches a state or activity; exits 74 on timeout.",
58
+ {
59
+ example: "maia --json session wait session_1 --activity idle,waiting_approval,stopped --timeout 10m",
60
+ route: "<session-id>",
61
+ run: [session, "runSessionWait"],
62
+ },
63
+ ],
53
64
  [
54
65
  "session rename <session-id> --title <text> --expected-revision <revision> [--command-id <id>]",
55
66
  1,
@@ -151,7 +162,7 @@ export const SESSION_TREE = {
151
162
  },
152
163
  ],
153
164
  [
154
- "session adopt (<claude|codex>:<native-id> --workspace <workspace-id> [--attest-ended] [--command-id <id>] [--dry-run] | --confirm-stdin)",
165
+ "session adopt (<claude|codex>:<native-id> --workspace <workspace-id> [--attest-ended] [--host-authority [--permission <mode>]] [--command-id <id>] [--dry-run] | --confirm-stdin)",
155
166
  1,
156
167
  ["session.adopt.preview", "session.adopt.confirm"],
157
168
  "Adopt a Claude Code or Codex session after a preview.",
@@ -190,12 +201,12 @@ export const SESSION_TREE = {
190
201
  { run: [session, "runSessionInboxAck"] },
191
202
  ],
192
203
  [
193
- "session turn send --session <session-id> --prompt-stdin --expected-revision <revision> [--command-id <id>]",
204
+ "session turn send --session <session-id> --prompt-stdin --expected-revision <revision> [--wait] [--command-id <id>]",
194
205
  1,
195
206
  "turn.send",
196
- "Send a turn from stdin; it queues behind the running turn.",
207
+ "Send a turn from stdin; it queues. --wait returns once it is done.",
197
208
  {
198
- example: "printf %s 'Explain the build' | maia --json session turn send --session session_1 --prompt-stdin --expected-revision 2 --command-id send-1",
209
+ example: "printf %s 'Explain the build' | maia --json session turn send --session session_1 --prompt-stdin --expected-revision 2 --wait --command-id send-1",
199
210
  route: "--session",
200
211
  run: [turn, "runTurnSend"],
201
212
  },
@@ -223,13 +234,13 @@ export const SESSION_TREE = {
223
234
  },
224
235
  ],
225
236
  [
226
- "session turn show <turn-id> [--include-content]",
237
+ "session turn show (<turn-id> | --session <session-id> --latest) [--include-content]",
227
238
  1,
228
239
  "turn.show",
229
- "Show one turn, its usage and, with --include-content, its text.",
240
+ "Show a turn or a Session's latest turn; --include-content adds its text.",
230
241
  {
231
- example: "maia --json session turn show turn_1 --include-content",
232
- route: "<turn-id>",
242
+ example: "maia --json session turn show --session session_1 --latest --include-content",
243
+ route: ["<turn-id>", "--session"],
233
244
  run: [turn, "runTurnShow"],
234
245
  },
235
246
  ],
@@ -274,7 +285,7 @@ export const SESSION_TREE = {
274
285
  { route: "<approval-id>", run: [approval, "runApprovalShow"] },
275
286
  ],
276
287
  [
277
- "session approval approve <approval-id> [--for-session] [--command-id <id>]",
288
+ "session approval approve <approval-id> [--for-session] [--as-coordinator] [--command-id <id>]",
278
289
  1,
279
290
  "approval.respond",
280
291
  "Approve a worker's request.",
@@ -286,7 +297,7 @@ export const SESSION_TREE = {
286
297
  },
287
298
  ],
288
299
  [
289
- "session approval deny <approval-id> [--reason <text>] [--command-id <id>]",
300
+ "session approval deny <approval-id> [--reason <text>] [--as-coordinator] [--command-id <id>]",
290
301
  1,
291
302
  "approval.respond",
292
303
  "Deny a worker's request.",
@@ -297,7 +308,7 @@ export const SESSION_TREE = {
297
308
  },
298
309
  ],
299
310
  [
300
- "session approval answer <approval-id> (--text <answer> | --option <option-id>) [--command-id <id>]",
311
+ "session approval answer <approval-id> (--text <answer> | --option <option-id>) [--as-coordinator] [--command-id <id>]",
301
312
  1,
302
313
  "approval.respond",
303
314
  "Answer a worker's question.",
@@ -1,6 +1,6 @@
1
1
  import { MAX_TURN_WAIT_MILLISECONDS, turnCancelParametersSchema, turnInterruptParametersSchema, turnQueueListParametersSchema, turnSendParametersSchema, turnShowParametersSchema, turnWaitParametersSchema, } from "@maiaos/sdk";
2
2
  import { Effect } from "effect";
3
- import { commandIdentifier, } from "../../local-node/index.js";
3
+ import { commandIdentifier, repeatBoundedWait, } from "../../local-node/index.js";
4
4
  export const makeTurnClient = (node) => {
5
5
  const interruptTurn = (input) => {
6
6
  return Effect.flatMap(commandIdentifier(input.commandId), (commandId) => {
@@ -29,17 +29,15 @@ export const makeTurnClient = (node) => {
29
29
  };
30
30
  const showTurn = (turnId) => node.runValidatedNodeOperation({ turnId }, turnShowParametersSchema, (client, parameters, options) => client.showTurn(parameters, options));
31
31
  const waitTurnsOnce = (parameters) => node.runValidatedNodeOperation(parameters, turnWaitParametersSchema, (client, validated, options) => client.waitTurns(validated, options));
32
- const waitWithin = (input) => Effect.gen(function* () {
33
- const waitMilliseconds = Math.min(MAX_TURN_WAIT_MILLISECONDS, input.timeoutMilliseconds);
34
- const result = yield* waitTurnsOnce({
32
+ const waitWithin = (input) => repeatBoundedWait({
33
+ maxRequestMilliseconds: MAX_TURN_WAIT_MILLISECONDS,
34
+ once: (waitMilliseconds) => waitTurnsOnce({
35
35
  mode: input.mode,
36
36
  turnIds: input.turnIds,
37
37
  waitMilliseconds,
38
- });
39
- const remaining = input.timeoutMilliseconds - waitMilliseconds;
40
- if (!result.ok || result.value.satisfied || remaining <= 0)
41
- return result;
42
- return yield* waitWithin({ ...input, timeoutMilliseconds: remaining });
38
+ }),
39
+ satisfied: (value) => value.satisfied,
40
+ timeoutMilliseconds: input.timeoutMilliseconds,
43
41
  });
44
42
  return {
45
43
  cancelTurn,
@@ -1,7 +1,7 @@
1
1
  import { MAX_TURN_INPUT_BYTES, MAX_TURN_WAIT_IDS, } from "@maiaos/sdk";
2
2
  import * as Effect from "effect/Effect";
3
- import { CliArgumentError, parseOptions, readDuration, readExpectedRevision, readRevisionOption, requirePositionals, writeNodeResult, } from "../../command-line/index.js";
4
- import { formatTurnMutation, formatTurnQueue, formatTurnShow, formatTurnWait, turnWaitExitCode, } from "./output.js";
3
+ import { CliArgumentError, parseOptions, readExpectedRevision, readRevisionOption, readWaitTimeoutSeconds, reportError, requirePositionals, writeNodeResult, writeSuccess, } from "../../command-line/index.js";
4
+ import { formatTurnMutation, formatTurnQueue, formatTurnSend, formatTurnShow, formatTurnWait, turnWaitExitCode, } from "./output.js";
5
5
  const utf8 = new TextEncoder();
6
6
  const summarizeTurnMutation = (result) => ({
7
7
  delivery: result.delivery,
@@ -11,8 +11,9 @@ const summarizeTurnMutation = (result) => ({
11
11
  state: result.turn.state,
12
12
  turnId: result.turn.id,
13
13
  });
14
+ const SEND_WAIT_MILLISECONDS = 24 * 60 * 60 * 1000;
14
15
  const parseTurnSendArguments = (tokens) => {
15
- const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision", "--session"]), new Set(["--prompt-stdin"]));
16
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--expected-revision", "--session"]), new Set(["--prompt-stdin", "--wait"]));
16
17
  requirePositionals(parsed.positionals, 0);
17
18
  const sessionId = parsed.options.get("--session");
18
19
  if (sessionId === undefined) {
@@ -25,9 +26,31 @@ const parseTurnSendArguments = (tokens) => {
25
26
  return {
26
27
  expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
27
28
  sessionId,
29
+ wait: parsed.flags.has("--wait"),
28
30
  ...(commandId === undefined ? {} : { commandId }),
29
31
  };
30
32
  };
33
+ const waitFailure = (turnId, error) => ({
34
+ ...error,
35
+ message: `Turn ${turnId} was accepted, but waiting for it failed: ${error.message} Follow it with 'maia session turn wait ${turnId}'.`,
36
+ });
37
+ const waitForSentTurn = (context, sent) => Effect.gen(function* () {
38
+ const { waitTurns } = context.dependencies;
39
+ if (waitTurns === undefined)
40
+ throw new CliArgumentError("Turn wait is unavailable.");
41
+ const waited = yield* waitTurns({
42
+ mode: "all",
43
+ timeoutMilliseconds: SEND_WAIT_MILLISECONDS,
44
+ turnIds: [sent.turn.id],
45
+ });
46
+ if (!waited.ok)
47
+ return reportError(waitFailure(sent.turn.id, waited.error), context);
48
+ writeSuccess({
49
+ command: "turn.send",
50
+ result: { ...summarizeTurnMutation(sent), wait: waited.value },
51
+ }, context, formatTurnSend);
52
+ return turnWaitExitCode(waited.value);
53
+ });
31
54
  export const runTurnSend = (tokens, context) => Effect.gen(function* () {
32
55
  const input = parseTurnSendArguments(tokens);
33
56
  if (context.io.stdin === undefined) {
@@ -38,14 +61,21 @@ export const runTurnSend = (tokens, context) => Effect.gen(function* () {
38
61
  maxBytes: MAX_TURN_INPUT_BYTES,
39
62
  maxChunks: 1024,
40
63
  });
41
- const result = yield* context.dependencies.sendTurn({ ...input, prompt });
42
- return writeNodeResult(result, context, {
43
- toResult: (value) => ({
44
- command: "turn.send",
45
- result: summarizeTurnMutation(value),
46
- }),
47
- toText: formatTurnMutation,
64
+ const sent = yield* context.dependencies.sendTurn({
65
+ ...(input.commandId === undefined ? {} : { commandId: input.commandId }),
66
+ expectedRevision: input.expectedRevision,
67
+ prompt,
68
+ sessionId: input.sessionId,
48
69
  });
70
+ if (!sent.ok || !input.wait)
71
+ return writeNodeResult(sent, context, {
72
+ toResult: (value) => ({
73
+ command: "turn.send",
74
+ result: summarizeTurnMutation(value),
75
+ }),
76
+ toText: formatTurnSend,
77
+ });
78
+ return yield* waitForSentTurn(context, sent.value);
49
79
  });
50
80
  const parseTurnMutationArguments = (tokens, revisionOption) => {
51
81
  const parsed = parseOptions(tokens, new Set(["--command-id", revisionOption]));
@@ -106,14 +136,21 @@ export const runTurnQueue = (tokens, context) => Effect.gen(function* () {
106
136
  });
107
137
  });
108
138
  const parseTurnShowArguments = (tokens) => {
109
- const parsed = parseOptions(tokens, new Set(), new Set(["--include-content"]));
110
- requirePositionals(parsed.positionals, 1);
139
+ const parsed = parseOptions(tokens, new Set(["--session"]), new Set(["--include-content", "--latest"]));
111
140
  const includeContent = parsed.flags.has("--include-content");
141
+ const sessionId = parsed.options.get("--session");
142
+ if (sessionId !== undefined || parsed.flags.has("--latest")) {
143
+ if (sessionId === undefined || !parsed.flags.has("--latest"))
144
+ throw new CliArgumentError("Use '--session' and '--latest' together.");
145
+ requirePositionals(parsed.positionals, 0);
146
+ return { includeContent, target: { sessionId, type: "latest" } };
147
+ }
148
+ requirePositionals(parsed.positionals, 1);
112
149
  const turnId = parsed.positionals[0];
113
150
  if (turnId === undefined) {
114
151
  throw new CliArgumentError("The turn identifier is missing.");
115
152
  }
116
- return { includeContent, turnId };
153
+ return { includeContent, target: { turnId, type: "turn" } };
117
154
  };
118
155
  const turnTerminalProjection = (turn) => {
119
156
  if (turn.state === "completed") {
@@ -145,22 +182,32 @@ const projectTurnWithoutContent = (value) => ({
145
182
  const summarizeTurnShow = (value, includeContent) => includeContent
146
183
  ? { ...value, contentIncluded: true }
147
184
  : projectTurnWithoutContent(value);
185
+ const turnToShow = (context, target) => {
186
+ const { showSession, showTurn } = context.dependencies;
187
+ if (target.type === "turn")
188
+ return showTurn(target.turnId);
189
+ return Effect.flatMap(showSession(target.sessionId), (shown) => {
190
+ if (!shown.ok)
191
+ return Effect.succeed({ error: shown.error, ok: false });
192
+ const { latestTurnId } = shown.value.session;
193
+ return latestTurnId === undefined
194
+ ? Effect.succeed({ ok: true, value: undefined })
195
+ : showTurn(latestTurnId);
196
+ });
197
+ };
148
198
  export const runTurnShow = (tokens, context) => Effect.gen(function* () {
149
199
  const input = parseTurnShowArguments(tokens);
150
- const result = yield* context.dependencies.showTurn(input.turnId);
200
+ const result = yield* turnToShow(context, input.target);
151
201
  return writeNodeResult(result, context, {
152
202
  toResult: (value) => ({
153
203
  command: "turn.show",
154
- result: summarizeTurnShow(value, input.includeContent),
204
+ result: value === undefined
205
+ ? { contentIncluded: false, method: "turn.show" }
206
+ : summarizeTurnShow(value, input.includeContent),
155
207
  }),
156
208
  toText: formatTurnShow,
157
209
  });
158
210
  });
159
- const DEFAULT_TURN_WAIT_SECONDS = 600;
160
- const MAX_TURN_WAIT_SECONDS = 86_400;
161
- const readWaitTimeoutSeconds = (value) => value === undefined
162
- ? DEFAULT_TURN_WAIT_SECONDS
163
- : readDuration(value, "--timeout", { max: MAX_TURN_WAIT_SECONDS, min: 1 });
164
211
  const parseTurnWaitArguments = (tokens) => {
165
212
  const parsed = parseOptions(tokens, new Set(["--timeout"]), new Set(["--any"]));
166
213
  if (parsed.positionals.length === 0 ||
@@ -8,6 +8,7 @@ export type CliTurnMutation = {
8
8
  readonly sessionId: string;
9
9
  readonly state: TurnInterruptResult["turn"]["state"];
10
10
  readonly turnId: string;
11
+ readonly wait?: TurnWaitResult;
11
12
  };
12
13
  };
13
14
  export type CliTurnShow = {
@@ -29,6 +30,10 @@ export type CliTurnShow = {
29
30
  readonly state: TurnShowResult["turn"]["state"];
30
31
  readonly tokenUsage?: TurnTokenUsage;
31
32
  };
33
+ } | {
34
+ readonly contentIncluded: false;
35
+ readonly method: "turn.show";
36
+ readonly turn?: undefined;
32
37
  };
33
38
  };
34
39
  export type CliTurnWait = {
@@ -40,6 +45,7 @@ export type CliTurnQueue = {
40
45
  readonly result: TurnQueueListResult;
41
46
  };
42
47
  export declare const formatTurnMutation: ({ result }: CliTurnMutation) => string;
48
+ export declare const formatTurnSend: (output: CliTurnMutation) => string;
43
49
  export declare const formatTurnQueue: ({ result }: CliTurnQueue) => string;
44
50
  export declare const formatTurnShow: ({ result }: CliTurnShow) => string;
45
51
  export declare const formatTurnWait: ({ result }: CliTurnWait) => string;
@@ -5,6 +5,9 @@ export const formatTurnMutation = ({ result }) => fields([
5
5
  ["state", result.state],
6
6
  ["revision", result.revision],
7
7
  ]);
8
+ export const formatTurnSend = (output) => output.result.wait === undefined
9
+ ? formatTurnMutation(output)
10
+ : formatTurnWait({ command: "turn.wait", result: output.result.wait });
8
11
  const turnFields = (turn, reason) => fields([
9
12
  ["turn", turn.id],
10
13
  ["state", turn.state],
@@ -31,13 +34,20 @@ export const formatTurnQueue = ({ result }) => {
31
34
  headers: ["POSITION", "STATE", "TURN", "REVISION", "INPUT"],
32
35
  });
33
36
  };
37
+ const formatContext = (usage) => usage.contextTokens === undefined || usage.contextWindow === undefined
38
+ ? ""
39
+ : `context: ${String(usage.contextTokens)} of ${String(usage.contextWindow)} tokens (${String(Math.round((100 * usage.contextTokens) / usage.contextWindow))}%)\n`;
34
40
  const formatUsage = (usage) => usage === undefined
35
41
  ? ""
36
- : `tokens: input ${String(usage.inputTokens)} (cached ${String(usage.cachedInputTokens)}), output ${String(usage.outputTokens)} (reasoning ${String(usage.reasoningOutputTokens)}), total ${String(usage.totalTokens)}${usage.modelCallCount === undefined ? "" : `, model calls ${String(usage.modelCallCount)}`}\n`;
42
+ : `tokens: input ${String(usage.inputTokens)} (cached ${String(usage.cachedInputTokens)}), output ${String(usage.outputTokens)} (reasoning ${String(usage.reasoningOutputTokens)}), total ${String(usage.totalTokens)}${usage.modelCallCount === undefined ? "" : `, model calls ${String(usage.modelCallCount)}`}\n${formatContext(usage)}`;
37
43
  const formatContent = (turn) => `input:\n${block(turn.input.text)}\n${turn.state === "completed" ? `response:\n${block(turn.responseText)}\n` : ""}`;
38
- const shownContent = (result) => result.contentIncluded ? formatContent(result.turn) : "";
44
+ const shownContent = (result) => result.contentIncluded && result.turn !== undefined
45
+ ? formatContent(result.turn)
46
+ : "";
39
47
  export const formatTurnShow = ({ result }) => {
40
48
  const { turn } = result;
49
+ if (turn === undefined)
50
+ return "no turn with output yet\n";
41
51
  const failure = "failure" in turn &&
42
52
  (turn.state === "failed" || turn.state === "outcome-unknown")
43
53
  ? formatFailure(turn.failure, turn.state)
@@ -8,11 +8,17 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
8
8
  readonly pid: number;
9
9
  readonly profile: string;
10
10
  readonly startedAt: string;
11
+ readonly admissionCaps?: {
12
+ readonly defaultAccountSessions: number;
13
+ readonly maximumActiveSessions: number;
14
+ } | undefined;
11
15
  readonly executorHost?: {
12
16
  readonly bubblewrap: "found" | "missing";
13
17
  readonly socat: "found" | "missing";
14
18
  readonly userNamespaces: "allowed" | "no_nesting" | "restricted";
15
19
  } | undefined;
20
+ readonly headlessApprovals?: "off" | "on" | undefined;
21
+ readonly hostAuthority?: "disabled" | "enabled" | undefined;
16
22
  readonly method: "node.status";
17
23
  readonly processResources: {
18
24
  readonly activeTrees: number;
@@ -47,7 +53,7 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
47
53
  };
48
54
  readonly cleanupUnknownTrees: number;
49
55
  readonly fencedTrees: number;
50
- readonly nextStep: "close_idle_terminal" | "inspect_cleanup_unknown" | "inspect_observed_pressure" | "none" | "run_node_in_delegated_cgroup" | "verify_native_host";
56
+ readonly nextStep: "close_idle_terminal" | "inspect_cleanup_unknown" | "inspect_observed_pressure" | "none" | "run_node_in_delegated_cgroup" | "upgrade_kernel" | "verify_native_host";
51
57
  readonly observations: {
52
58
  readonly cpuTimeMilliseconds: {
53
59
  readonly availableTrees: number;
@@ -107,14 +113,19 @@ export declare const makeStatusClient: (node: CliNodeOperations) => {
107
113
  };
108
114
  readonly treeCount: number;
109
115
  };
110
- readonly pressure: "admission_degraded" | "cgroup_delegation_unavailable" | "cleanup_unknown" | "healthy" | "observed_pressure" | "warning";
116
+ readonly pressure: "admission_degraded" | "cgroup_delegation_unavailable" | "cleanup_unknown" | "healthy" | "landlock_scoped_unavailable" | "observed_pressure" | "warning";
111
117
  readonly supervision: {
112
118
  readonly trackedTrees: number;
113
119
  readonly watcherFibers: number;
114
120
  };
115
121
  };
116
122
  readonly storage: {
117
- readonly integrity: "ok";
123
+ readonly events?: {
124
+ readonly checkpointBlocked?: boolean | undefined;
125
+ readonly excessBytes: number;
126
+ readonly oldestAgeMs?: number | undefined;
127
+ } | undefined;
128
+ readonly integrity: "ok" | "unavailable";
118
129
  readonly journalMode: "wal";
119
130
  readonly schemaTag: string;
120
131
  readonly schemaVersion: number;
@@ -14,7 +14,9 @@ const unavailableError = (cause) => {
14
14
  const remote = Predicate.hasProperty(error, "remoteError")
15
15
  ? protocolErrorSchema.safeParse(error.remoteError)
16
16
  : undefined;
17
- return remote?.success === true && remote.data.code === "node_unavailable"
17
+ return remote?.success === true &&
18
+ (remote.data.code === "node_unavailable" ||
19
+ remote.data.code === "invalid_argument")
18
20
  ? remote.data
19
21
  : createUnavailableError();
20
22
  };
@@ -5,9 +5,13 @@ export type DoctorCheck = {
5
5
  readonly next?: string;
6
6
  readonly ok: boolean;
7
7
  };
8
+ export type DoctorScope = "machine" | "node";
8
9
  export type CliDoctorResult = {
9
- readonly checks: readonly DoctorCheck[];
10
+ readonly checks: readonly (DoctorCheck & {
11
+ readonly scope: DoctorScope;
12
+ })[];
10
13
  readonly command: "doctor";
14
+ readonly node?: string;
11
15
  readonly ok: boolean;
12
16
  readonly version: string;
13
17
  };
@@ -1,6 +1,6 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import * as Option from "effect/Option";
3
- import { requireNoArguments, writeSuccess, } from "../command-line/index.js";
3
+ import { LOCAL_NODE, requireNoArguments, writeSuccess, } from "../command-line/index.js";
4
4
  const EXIT_FAILED = 70;
5
5
  const vendorWords = (executor) => executor === "codex-cli"
6
6
  ? { integration: "codex", login: "codex" }
@@ -71,8 +71,8 @@ const nodeChecks = (detected, connections) => {
71
71
  ]),
72
72
  ];
73
73
  };
74
- const formatDoctor = (result) => `Maia doctor ${result.ok ? "ok" : "failed"}\n${result.checks
75
- .map((check) => ` ${check.code}: ${check.ok ? "ok" : "failed"}${check.detail === undefined ? "" : ` (${check.detail})`}${check.ok || check.next === undefined ? "" : `; next: ${check.next}`}\n`)
74
+ const formatDoctor = (result) => `Maia doctor ${result.ok ? "ok" : "failed"}${result.node === undefined ? "" : ` (Node ${result.node})`}\n${result.checks
75
+ .map((check) => ` ${check.code}${check.scope === "machine" ? " (this machine)" : ""}: ${check.ok ? "ok" : "failed"}${check.detail === undefined ? "" : ` (${check.detail})`}${check.ok || check.next === undefined ? "" : `; next: ${check.next}`}\n`)
76
76
  .join("")}`;
77
77
  const readLifecycle = (dependencies) => Effect.map(Effect.option(Effect.map(Effect.suspend(() => dependencies.readStatus()), (node) => node.lifecycle)), Option.getOrUndefined);
78
78
  const nodeCheck = (lifecycle) => lifecycle === undefined
@@ -100,8 +100,14 @@ export const runDoctor = (tokens, context) => Effect.gen(function* () {
100
100
  const checks = yield* readChecks(context);
101
101
  const ok = checks.every((check) => check.ok);
102
102
  const result = {
103
- checks,
103
+ checks: checks.map((check) => ({
104
+ ...check,
105
+ scope: check.code === "cli" ? "machine" : "node",
106
+ })),
104
107
  command: "doctor",
108
+ ...(context.node === undefined || context.node === LOCAL_NODE
109
+ ? {}
110
+ : { node: context.node }),
105
111
  ok,
106
112
  version: context.version,
107
113
  };
@@ -1,8 +1,10 @@
1
1
  import type { LocalNodeStatusResult } from "@maiaos/sdk";
2
2
  export declare const sumObservationWarningTrees: (observations: LocalNodeStatusResult["processResources"]["observations"]) => number;
3
3
  export type CliCompactStatusResult = {
4
+ readonly admissionCaps?: LocalNodeStatusResult["admissionCaps"];
4
5
  readonly command: "status";
5
6
  readonly executorHost?: LocalNodeStatusResult["executorHost"];
7
+ readonly hostAuthority?: LocalNodeStatusResult["hostAuthority"];
6
8
  readonly instanceId: LocalNodeStatusResult["instanceId"];
7
9
  readonly lifecycle: LocalNodeStatusResult["lifecycle"];
8
10
  readonly pid: LocalNodeStatusResult["pid"];
@@ -23,6 +25,7 @@ export type CliCompactStatusResult = {
23
25
  };
24
26
  readonly profile: LocalNodeStatusResult["profile"];
25
27
  readonly storage: {
28
+ readonly events?: LocalNodeStatusResult["storage"]["events"];
26
29
  readonly integrity: LocalNodeStatusResult["storage"]["integrity"];
27
30
  readonly journalMode: LocalNodeStatusResult["storage"]["journalMode"];
28
31
  readonly schemaVersion: LocalNodeStatusResult["storage"]["schemaVersion"];
@@ -24,23 +24,33 @@ const projectStatusCapability = (capability) => ({
24
24
  mode: capability.mode,
25
25
  releaseQualified: capability.releaseQualified,
26
26
  });
27
+ const projectProcessResources = (node) => ({
28
+ admission: projectStatusAdmission(node.processResources.admission),
29
+ capability: projectStatusCapability(node.processResources.capability),
30
+ nextStep: node.processResources.nextStep,
31
+ pressure: node.processResources.pressure,
32
+ warningTrees: sumObservationWarningTrees(node.processResources.observations),
33
+ });
27
34
  export const projectStatusResult = (node) => ({
28
35
  command: "status",
36
+ ...(node.admissionCaps === undefined
37
+ ? {}
38
+ : { admissionCaps: node.admissionCaps }),
29
39
  ...(node.executorHost === undefined
30
40
  ? {}
31
41
  : { executorHost: node.executorHost }),
42
+ ...(node.hostAuthority === undefined
43
+ ? {}
44
+ : { hostAuthority: node.hostAuthority }),
32
45
  instanceId: node.instanceId,
33
46
  lifecycle: node.lifecycle,
34
47
  pid: node.pid,
35
- processResources: {
36
- admission: projectStatusAdmission(node.processResources.admission),
37
- capability: projectStatusCapability(node.processResources.capability),
38
- nextStep: node.processResources.nextStep,
39
- pressure: node.processResources.pressure,
40
- warningTrees: sumObservationWarningTrees(node.processResources.observations),
41
- },
48
+ processResources: projectProcessResources(node),
42
49
  profile: node.profile,
43
50
  storage: {
51
+ ...(node.storage.events === undefined
52
+ ? {}
53
+ : { events: node.storage.events }),
44
54
  integrity: node.storage.integrity,
45
55
  journalMode: node.storage.journalMode,
46
56
  schemaVersion: node.storage.schemaVersion,
@@ -10,6 +10,8 @@ const processResourceNextStep = (nextStep) => {
10
10
  return "none";
11
11
  case "run_node_in_delegated_cgroup":
12
12
  return "restart the Node in a cgroup delegated to its user: a systemd user unit with Delegate=yes and DelegateSubgroup=node, or systemd-run --user -p Delegate=yes -p DelegateSubgroup=node";
13
+ case "upgrade_kernel":
14
+ return "upgrade the Linux kernel to 6.12 or newer";
13
15
  case "verify_native_host":
14
16
  return "verify the native process host";
15
17
  }
@@ -73,12 +75,25 @@ const executorHostLines = (host) => {
73
75
  userNamespaces[host.userNamespaces],
74
76
  ];
75
77
  };
78
+ const eventLines = (events) => events === undefined
79
+ ? []
80
+ : [
81
+ `events: ${String(events.excessBytes)} bytes over limit` +
82
+ (events.oldestAgeMs === undefined
83
+ ? ""
84
+ : `, oldest ${String(Math.floor(events.oldestAgeMs / 3_600_000))} h`) +
85
+ (events.checkpointBlocked === true ? ", checkpoint blocked" : ""),
86
+ ];
76
87
  export const formatHumanStatus = ({ node }) => {
77
88
  const lines = [
78
89
  `profile: ${node.profile}`,
79
90
  `pid: ${String(node.pid)}`,
80
91
  `instance: ${node.instanceId}`,
81
92
  `storage: ${node.storage.integrity} (${node.storage.journalMode})`,
93
+ ...(node.hostAuthority === undefined
94
+ ? []
95
+ : [`host authority: ${node.hostAuthority}`]),
96
+ ...eventLines(node.storage.events),
82
97
  ...processResourceLines(node.processResources),
83
98
  ...executorHostLines(node.executorHost),
84
99
  ];