@maiaos/cli 0.1.0-canary.54 → 0.1.0-canary.56

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 (179) hide show
  1. package/README.md +4 -3
  2. package/dist/bin/maia.cdx.json +19 -19
  3. package/dist/bin/maia.mjs +1 -1
  4. package/dist/command-line/emit/index.d.ts +1 -1
  5. package/dist/command-line/emit/index.js +1 -1
  6. package/dist/command-line/emit/rows.d.ts +1 -0
  7. package/dist/command-line/emit/rows.js +5 -0
  8. package/dist/command-line/index.d.ts +2 -2
  9. package/dist/command-line/index.js +2 -2
  10. package/dist/command-line/input/index.d.ts +1 -0
  11. package/dist/command-line/input/index.js +1 -0
  12. package/dist/command-line/input/manager-options.d.ts +10 -0
  13. package/dist/command-line/input/manager-options.js +38 -0
  14. package/dist/events/commands.js +4 -3
  15. package/dist/import/batch.js +196 -0
  16. package/dist/import/client.d.ts +3 -3
  17. package/dist/import/client.js +1 -1
  18. package/dist/import/commands.d.ts +1 -0
  19. package/dist/import/commands.js +82 -8
  20. package/dist/import/index.d.ts +1 -1
  21. package/dist/import/index.js +1 -1
  22. package/dist/import/input.js +16 -2
  23. package/dist/import/manifest.js +107 -0
  24. package/dist/import/output.js +44 -2
  25. package/dist/session/approval/commands.d.ts +1 -0
  26. package/dist/session/approval/commands.js +75 -9
  27. package/dist/session/approval/index.d.ts +1 -1
  28. package/dist/session/approval/index.js +1 -1
  29. package/dist/session/coding-client.d.ts +2 -0
  30. package/dist/session/coding-client.js +1 -2
  31. package/dist/session/coding-commands.js +24 -7
  32. package/dist/session/commands.js +36 -39
  33. package/dist/session/output/human.js +14 -3
  34. package/dist/session/output/tasks.js +25 -11
  35. package/dist/session/tree/tree.js +31 -9
  36. package/package.json +5 -5
  37. package/dist/address-space/address-space.d.ts +0 -38
  38. package/dist/address-space/index.d.ts +0 -2
  39. package/dist/agents/input.d.ts +0 -132
  40. package/dist/agents/output/format.d.ts +0 -8
  41. package/dist/agents/output/index.d.ts +0 -2
  42. package/dist/agents/tree/index.d.ts +0 -2
  43. package/dist/agents/tree/tree.d.ts +0 -3
  44. package/dist/bootstrap/exit.d.ts +0 -14
  45. package/dist/bootstrap/exit.js +0 -42
  46. package/dist/bootstrap/index.d.ts +0 -3
  47. package/dist/bootstrap/index.js +0 -3
  48. package/dist/bootstrap/process.d.ts +0 -5
  49. package/dist/bootstrap/process.js +0 -23
  50. package/dist/bootstrap/run.d.ts +0 -25
  51. package/dist/bootstrap/run.js +0 -98
  52. package/dist/bootstrap/stdio.d.ts +0 -4
  53. package/dist/bootstrap/stdio.js +0 -9
  54. package/dist/cli/environment.d.ts +0 -8
  55. package/dist/cli/services.d.ts +0 -4
  56. package/dist/command-line/emit/json-decoder.d.ts +0 -3
  57. package/dist/command-line/input/stdin-stream.d.ts +0 -4
  58. package/dist/command-receipt/command.d.ts +0 -4
  59. package/dist/command-receipt/compact-list.d.ts +0 -20
  60. package/dist/command-receipt/index.d.ts +0 -3
  61. package/dist/command-tree/completion.d.ts +0 -6
  62. package/dist/command-tree/local.d.ts +0 -3
  63. package/dist/command-tree/row.js +0 -2
  64. package/dist/connection/access/format.d.ts +0 -8
  65. package/dist/connection/access/input.d.ts +0 -53
  66. package/dist/connection/input.d.ts +0 -50
  67. package/dist/connection/signin.d.ts +0 -4
  68. package/dist/connection/tree/index.d.ts +0 -2
  69. package/dist/connection/tree/tree.d.ts +0 -3
  70. package/dist/container/output/format.d.ts +0 -11
  71. package/dist/container/output/index.d.ts +0 -2
  72. package/dist/context/client.d.ts +0 -7
  73. package/dist/context/commands.d.ts +0 -3
  74. package/dist/context/index.d.ts +0 -3
  75. package/dist/dashboard/cockpit-client.d.ts +0 -6
  76. package/dist/dashboard/cockpit-client.js +0 -27
  77. package/dist/dashboard/cockpits.d.ts +0 -29
  78. package/dist/dashboard/cockpits.js +0 -65
  79. package/dist/dashboard/dashboard.d.ts +0 -7
  80. package/dist/dashboard/draw.d.ts +0 -15
  81. package/dist/dashboard/frame.d.ts +0 -4
  82. package/dist/dashboard/index.d.ts +0 -2
  83. package/dist/dashboard/modes.d.ts +0 -5
  84. package/dist/dashboard/node-connection.d.ts +0 -15
  85. package/dist/dashboard/node-connection.js +0 -51
  86. package/dist/dashboard/pi-tui.d.ts +0 -6
  87. package/dist/dashboard/status-bar.d.ts +0 -4
  88. package/dist/dashboard/terminal.d.ts +0 -53
  89. package/dist/dashboard/tree-model.d.ts +0 -28
  90. package/dist/dashboard/tree.d.ts +0 -10
  91. package/dist/development/cli.d.ts +0 -3
  92. package/dist/development/cli.js +0 -44
  93. package/dist/events/commands.d.ts +0 -11
  94. package/dist/events/index.d.ts +0 -2
  95. package/dist/events/tree/index.d.ts +0 -2
  96. package/dist/events/tree/tree.d.ts +0 -10
  97. package/dist/execution/tree/index.d.ts +0 -2
  98. package/dist/execution/tree/tree.d.ts +0 -3
  99. package/dist/hold/output/format.d.ts +0 -11
  100. package/dist/hold/output/index.d.ts +0 -2
  101. package/dist/hold/tree/index.d.ts +0 -2
  102. package/dist/hold/tree/tree.d.ts +0 -3
  103. package/dist/import/input.d.ts +0 -19
  104. package/dist/import/output.d.ts +0 -6
  105. package/dist/integration/output.d.ts +0 -22
  106. package/dist/login/failure.d.ts +0 -3
  107. package/dist/login/gateway.d.ts +0 -12
  108. package/dist/login/menu.d.ts +0 -4
  109. package/dist/login/output/format.d.ts +0 -16
  110. package/dist/login/output/index.d.ts +0 -2
  111. package/dist/login/vendor-account.d.ts +0 -95
  112. package/dist/login/vendor-input.d.ts +0 -14
  113. package/dist/mcp/calls.d.ts +0 -8
  114. package/dist/orchestration/output/compact-aggregate.d.ts +0 -121
  115. package/dist/orchestration/output/compact-run-list.d.ts +0 -20
  116. package/dist/orchestration/output/human.d.ts +0 -80
  117. package/dist/orchestration/output/index.d.ts +0 -4
  118. package/dist/orchestration/tree/index.d.ts +0 -2
  119. package/dist/orchestration/tree/tree.d.ts +0 -3
  120. package/dist/port-lease/input.d.ts +0 -65
  121. package/dist/port-lease/output/format.d.ts +0 -11
  122. package/dist/port-lease/output/index.d.ts +0 -2
  123. package/dist/presentation/output/format.d.ts +0 -11
  124. package/dist/presentation/output/index.d.ts +0 -3
  125. package/dist/project-guard/input.d.ts +0 -21
  126. package/dist/project-guard/output/format.d.ts +0 -11
  127. package/dist/project-guard/output/index.d.ts +0 -2
  128. package/dist/project-workspace/output/human.d.ts +0 -139
  129. package/dist/project-workspace/output/index.d.ts +0 -3
  130. package/dist/project-workspace/output/metadata.d.ts +0 -11
  131. package/dist/project-workspace/tree/index.d.ts +0 -2
  132. package/dist/project-workspace/tree/tree.d.ts +0 -3
  133. package/dist/provider/client.d.ts +0 -6
  134. package/dist/provider/commands.d.ts +0 -3
  135. package/dist/provider/index.d.ts +0 -3
  136. package/dist/reference/commands.d.ts +0 -3
  137. package/dist/reference/index.d.ts +0 -3
  138. package/dist/reference/resolve.d.ts +0 -31
  139. package/dist/reference/tree/index.d.ts +0 -2
  140. package/dist/reference/tree/tree.d.ts +0 -3
  141. package/dist/remote-node/reachability.d.ts +0 -64
  142. package/dist/remote-node/text.d.ts +0 -10
  143. package/dist/remote-node/tree/index.d.ts +0 -2
  144. package/dist/remote-node/tree/tree.d.ts +0 -3
  145. package/dist/routine/input.d.ts +0 -28
  146. package/dist/routine/output/format.d.ts +0 -23
  147. package/dist/routine/output/index.d.ts +0 -2
  148. package/dist/routine/tree/index.d.ts +0 -2
  149. package/dist/routine/tree/tree.d.ts +0 -3
  150. package/dist/run-ledger/input.d.ts +0 -42
  151. package/dist/run-ledger/output/format.d.ts +0 -11
  152. package/dist/run-ledger/output/index.d.ts +0 -2
  153. package/dist/session/approval/output/format.d.ts +0 -23
  154. package/dist/session/approval/output/index.d.ts +0 -2
  155. package/dist/session/attach-render.d.ts +0 -16
  156. package/dist/session/create-tasks.d.ts +0 -20
  157. package/dist/session/interaction/input.d.ts +0 -15
  158. package/dist/session/interaction/output/format.d.ts +0 -11
  159. package/dist/session/interaction/output/index.d.ts +0 -2
  160. package/dist/session/output/diff.d.ts +0 -3
  161. package/dist/session/output/failure.d.ts +0 -11
  162. package/dist/session/output/human.d.ts +0 -115
  163. package/dist/session/output/index.d.ts +0 -6
  164. package/dist/session/output/observe.d.ts +0 -4
  165. package/dist/session/output/tasks.d.ts +0 -36
  166. package/dist/session/task-file.d.ts +0 -5
  167. package/dist/session/tree/index.d.ts +0 -2
  168. package/dist/session/tree/tree.d.ts +0 -3
  169. package/dist/team-workspace/ceremony.d.ts +0 -19
  170. package/dist/team-workspace/confirmation.d.ts +0 -4
  171. package/dist/team-workspace/dependencies.js +0 -2
  172. package/dist/team-workspace/output.d.ts +0 -15
  173. package/dist/terminal/arguments.d.ts +0 -13
  174. package/dist/terminal/keys.d.ts +0 -12
  175. package/dist/terminal/output/compact-list.d.ts +0 -149
  176. package/dist/terminal/output/human.d.ts +0 -42
  177. package/dist/terminal/output/index.d.ts +0 -3
  178. package/dist/terminal/tree/index.d.ts +0 -2
  179. package/dist/terminal/tree/tree.d.ts +0 -3
@@ -1,4 +1,4 @@
1
1
  export { decodeJsonText, jsonLine } from "./json.js";
2
2
  export { type CliCommandOutput, type CliErrorOutput, type CliIo, type CliResolution, type CliSuccessOutput, type CliSuccessResult, exitCodeOf, type NodeResultPresenter, type OutputContext, reportError, writeNodeResult, writeSuccess, } from "./output.js";
3
- export { block, cell, type CliTable, fields, formatRows, tab, withNextPage, withPrunedHistory, } from "./rows.js";
3
+ export { block, cell, type CliTable, fields, formatRows, labelCells, tab, withNextPage, withPrunedHistory, } from "./rows.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
1
  export { decodeJsonText, jsonLine } from "./json.js";
2
2
  export { exitCodeOf, reportError, writeNodeResult, writeSuccess, } from "./output.js";
3
- export { block, cell, fields, formatRows, tab, withNextPage, withPrunedHistory, } from "./rows.js";
3
+ export { block, cell, fields, formatRows, labelCells, tab, withNextPage, withPrunedHistory, } from "./rows.js";
4
4
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  export declare const isTerminalControl: (character: string) => boolean;
2
2
  export declare const cell: (value: string) => string;
3
3
  export declare const block: (value: string) => string;
4
+ export declare const labelCells: (labels: Readonly<Record<string, string>> | undefined) => string;
4
5
  export declare const tab: (values: readonly unknown[]) => string;
5
6
  export declare const fields: (entries: readonly (readonly [label: string, value: string | undefined])[]) => string;
6
7
  export type CliTable = {
@@ -11,6 +11,11 @@ export const isTerminalControl = (character) => {
11
11
  const replaceControls = (value, kept) => Array.from(value, (character) => !kept.includes(character) && isTerminalControl(character) ? "�" : character).join("");
12
12
  export const cell = (value) => replaceControls(value, "");
13
13
  export const block = (value) => replaceControls(value, "\t\n");
14
+ export const labelCells = (labels) => labels === undefined
15
+ ? "-"
16
+ : Object.entries(labels)
17
+ .map(([key, value]) => `${key}=${value}`)
18
+ .join(",");
14
19
  export const tab = (values) => values.join("\t");
15
20
  const align = (rows) => {
16
21
  const widths = rows.reduce((sizes, row) => row.map((value, index) => Math.max(sizes[index] ?? 0, value.length)), []);
@@ -1,7 +1,7 @@
1
1
  export { type CliDependencies, type CliServices, type CommandContext, type CommandEffect, LOCAL_NODE, } from "./context.js";
2
2
  export { decodeJsonText, jsonLine } from "./emit/index.js";
3
3
  export { type CliCommandOutput, type CliErrorOutput, type CliIo, type CliResolution, type CliSuccessOutput, type CliSuccessResult, exitCodeOf, type NodeResultPresenter, reportError, writeNodeResult, writeSuccess, } from "./emit/index.js";
4
- export { block, cell, type CliTable, fields, formatRows, tab, withNextPage, withPrunedHistory, } from "./emit/index.js";
5
- export { argumentsAreBounded, type ArgumentToken, CliArgumentError, missingArgument, parseArguments, type ParsedArguments, type ParsedOptions, parseOptions, parseOptionsWith, readBoundedStdin, readCursor, readDuration, readExpectedRevision, readGlobalValue, readPageSize, readPermission, readRevisionOption, readWaitTimeoutSeconds, recoverStdin, requireNoArguments, requirePositionals, tokenizeArguments, unknownCommand, } from "./input/index.js";
4
+ export { block, cell, type CliTable, fields, formatRows, labelCells, tab, withNextPage, withPrunedHistory, } from "./emit/index.js";
5
+ export { argumentsAreBounded, type ArgumentToken, CliArgumentError, LABEL_OPTION, missingArgument, parseArguments, type ParsedArguments, type ParsedOptions, parseOptions, parseOptionsWith, readBoundedStdin, readCursor, readDuration, readExpectedRevision, readGlobalValue, readLabels, readPageSize, readPermission, readRevisionOption, readSessionRole, readSessionTitle, readWaitTimeoutSeconds, recoverStdin, requireNoArguments, requireOneLabelPerOption, requirePositionals, tokenizeArguments, unknownCommand, } from "./input/index.js";
6
6
  export { askToConfirm, canPrompt, confirmationOf, confirmParameters, EXIT_CANCELLED, peekStdin, promptOrRefuse, readInputMode, readPipedPreview, readTwoPhaseMode, requestedTwoPhaseMode, runInputTwoPhase, runTwoPhase, TWO_PHASE_FLAGS, type TwoPhaseMode, } from "./two-phase.js";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
1
  export { LOCAL_NODE, } from "./context.js";
2
2
  export { decodeJsonText, jsonLine } from "./emit/index.js";
3
3
  export { exitCodeOf, reportError, writeNodeResult, writeSuccess, } from "./emit/index.js";
4
- export { block, cell, fields, formatRows, tab, withNextPage, withPrunedHistory, } from "./emit/index.js";
5
- export { argumentsAreBounded, CliArgumentError, missingArgument, parseArguments, parseOptions, parseOptionsWith, readBoundedStdin, readCursor, readDuration, readExpectedRevision, readGlobalValue, readPageSize, readPermission, readRevisionOption, readWaitTimeoutSeconds, recoverStdin, requireNoArguments, requirePositionals, tokenizeArguments, unknownCommand, } from "./input/index.js";
4
+ export { block, cell, fields, formatRows, labelCells, tab, withNextPage, withPrunedHistory, } from "./emit/index.js";
5
+ export { argumentsAreBounded, CliArgumentError, LABEL_OPTION, missingArgument, parseArguments, parseOptions, parseOptionsWith, readBoundedStdin, readCursor, readDuration, readExpectedRevision, readGlobalValue, readLabels, readPageSize, readPermission, readRevisionOption, readSessionRole, readSessionTitle, readWaitTimeoutSeconds, recoverStdin, requireNoArguments, requireOneLabelPerOption, requirePositionals, tokenizeArguments, unknownCommand, } from "./input/index.js";
6
6
  export { askToConfirm, canPrompt, confirmationOf, confirmParameters, EXIT_CANCELLED, peekStdin, promptOrRefuse, readInputMode, readPipedPreview, readTwoPhaseMode, requestedTwoPhaseMode, runInputTwoPhase, runTwoPhase, TWO_PHASE_FLAGS, } from "./two-phase.js";
7
7
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,5 @@
1
1
  export { argumentsAreBounded, type ArgumentToken, CliArgumentError, missingArgument, parseArguments, type ParsedArguments, type ParsedOptions, parseOptions, parseOptionsWith, readCursor, readDuration, readExpectedRevision, readGlobalValue, readPageSize, readPermission, readRevisionOption, readWaitTimeoutSeconds, requireNoArguments, requirePositionals, tokenizeArguments, unknownCommand, } from "./arguments.js";
2
+ export { LABEL_OPTION, readLabels, readSessionRole, readSessionTitle, requireOneLabelPerOption, } from "./manager-options.js";
2
3
  export { promptLine, type PromptOptions, terminalIsInteractive, } from "./prompt.js";
3
4
  export { type BoundedStdinRequest, readBoundedStdin, recoverStdin, replayStdin, } from "./stdin.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,5 @@
1
1
  export { argumentsAreBounded, CliArgumentError, missingArgument, parseArguments, parseOptions, parseOptionsWith, readCursor, readDuration, readExpectedRevision, readGlobalValue, readPageSize, readPermission, readRevisionOption, readWaitTimeoutSeconds, requireNoArguments, requirePositionals, tokenizeArguments, unknownCommand, } from "./arguments.js";
2
+ export { LABEL_OPTION, readLabels, readSessionRole, readSessionTitle, requireOneLabelPerOption, } from "./manager-options.js";
2
3
  export { promptLine, terminalIsInteractive, } from "./prompt.js";
3
4
  export { readBoundedStdin, recoverStdin, replayStdin, } from "./stdin.js";
4
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ export declare const LABEL_OPTION: ReadonlySet<string>;
2
+ export declare const requireOneLabelPerOption: (tokens: readonly string[]) => void;
3
+ export declare const readLabels: (value: string | undefined) => {
4
+ readonly labels?: Readonly<Record<string, string>>;
5
+ };
6
+ export declare const readSessionRole: (value: string | undefined) => {
7
+ readonly role?: "orchestrator" | "worker";
8
+ };
9
+ export declare const readSessionTitle: (options: ReadonlyMap<string, string>) => string | undefined;
10
+ //# sourceMappingURL=manager-options.d.ts.map
@@ -0,0 +1,38 @@
1
+ import { CliArgumentError } from "./arguments.js";
2
+ export const LABEL_OPTION = new Set(["--label"]);
3
+ export const requireOneLabelPerOption = (tokens) => {
4
+ const given = tokens.flatMap((token, index) => {
5
+ if (tokens[index - 1] === "--label")
6
+ return [token];
7
+ return token.startsWith("--label=") ? [token.slice("--label=".length)] : [];
8
+ });
9
+ if (given.some((value) => value.includes(",")))
10
+ throw new CliArgumentError("Option '--label' takes one key=value; repeat the option for more.");
11
+ };
12
+ export const readLabels = (value) => {
13
+ if (value === undefined)
14
+ return {};
15
+ const pairs = value.split(",").map((pair) => {
16
+ const separator = pair.indexOf("=");
17
+ if (separator < 1)
18
+ throw new CliArgumentError("Option '--label' takes key=value.");
19
+ return [pair.slice(0, separator), pair.slice(separator + 1)];
20
+ });
21
+ const duplicate = pairs.find(([key], index) => pairs.findIndex(([other]) => other === key) !== index);
22
+ if (duplicate !== undefined)
23
+ throw new CliArgumentError(`Label '${duplicate[0]}' is given twice.`);
24
+ return { labels: Object.fromEntries(pairs) };
25
+ };
26
+ export const readSessionRole = (value) => {
27
+ if (value === undefined)
28
+ return {};
29
+ if (value === "worker" || value === "orchestrator")
30
+ return { role: value };
31
+ throw new CliArgumentError("Option '--role' must be worker or orchestrator.");
32
+ };
33
+ export const readSessionTitle = (options) => {
34
+ if (options.has("--name") && options.has("--title"))
35
+ throw new CliArgumentError("Use one of '--name' or '--title'.");
36
+ return options.get("--title") ?? options.get("--name");
37
+ };
38
+ //# sourceMappingURL=manager-options.js.map
@@ -1,4 +1,4 @@
1
- import { findEventKind, localNodeRequestPayloadSchema, SESSION_ACTIVITY_SUBJECT_TYPE, } from "@maiaos/sdk";
1
+ import { findEventKind, localNodeRequestPayloadSchema, SESSION_ACTIVITY_SUBJECT_TYPE, SESSION_STATUS_SUBJECT_TYPE, } from "@maiaos/sdk";
2
2
  import * as Effect from "effect/Effect";
3
3
  import { cell, writeNodeResult, } from "../command-line/emit/index.js";
4
4
  import { CliArgumentError, parseOptionsWith, readPageSize, requirePositionals, } from "../command-line/input/index.js";
@@ -8,8 +8,9 @@ const readSubject = (value) => {
8
8
  if (split < 1 || split === value.length - 1)
9
9
  throw new CliArgumentError("Option '--subject' must be <type>:<id>.");
10
10
  const type = value.slice(0, split);
11
- if (type !== SESSION_ACTIVITY_SUBJECT_TYPE)
12
- throw new CliArgumentError(`Option '--subject' type must be ${SESSION_ACTIVITY_SUBJECT_TYPE}.`);
11
+ if (type !== SESSION_ACTIVITY_SUBJECT_TYPE &&
12
+ type !== SESSION_STATUS_SUBJECT_TYPE)
13
+ throw new CliArgumentError(`Option '--subject' type must be ${SESSION_ACTIVITY_SUBJECT_TYPE} or ${SESSION_STATUS_SUBJECT_TYPE}.`);
13
14
  return { id: value.slice(split + 1), type };
14
15
  };
15
16
  const readKinds = (value) => {
@@ -0,0 +1,196 @@
1
+ import { ADOPTION_REFUSED_ERROR_CODE, } from "@maiaos/sdk";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Schema from "effect/Schema";
4
+ import { jsonLine } from "../command-line/emit/index.js";
5
+ import { CliArgumentError } from "../command-line/input/index.js";
6
+ import { newCliIdentifier, } from "../local-node/index.js";
7
+ import { MAX_IMPORT_BYTES, MAX_IMPORT_ENTRIES, } from "./manifest.js";
8
+ const MAX_REASON_CHARACTERS = 300;
9
+ const harness = Schema.Literals(["claude-code", "codex-cli"]);
10
+ const nativeId = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_.:-]{1,200}$/u));
11
+ const base = { harness, index: Schema.Int, nativeId };
12
+ const reason = Schema.String.check(Schema.isMaxLength(MAX_REASON_CHARACTERS));
13
+ const sessionId = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_.:-]{1,200}$/u));
14
+ const plannedEntry = Schema.Union([
15
+ Schema.Struct({
16
+ ...base,
17
+ commandId: sessionId,
18
+ connectionId: sessionId,
19
+ expiresAt: Schema.String,
20
+ hostAuthority: Schema.optional(Schema.Literal(true)),
21
+ inputDigest: Schema.String,
22
+ labels: Schema.optional(Schema.Record(Schema.String, Schema.String)),
23
+ outcome: Schema.Literal("adopt"),
24
+ permission: Schema.optional(Schema.String.check(Schema.isMaxLength(64))),
25
+ previewId: Schema.String.check(Schema.isPattern(/^adopt_[A-Za-z0-9_-]{43}$/u)),
26
+ role: Schema.optional(Schema.Literals(["orchestrator", "worker"])),
27
+ title: Schema.optional(Schema.String.check(Schema.isMaxLength(80))),
28
+ workingDirectory: Schema.String.check(Schema.isMaxLength(4096)),
29
+ workspaceId: sessionId,
30
+ }),
31
+ Schema.Struct({ ...base, outcome: Schema.Literal("skipped"), sessionId }),
32
+ Schema.Struct({ ...base, outcome: Schema.Literal("refused"), reason }),
33
+ ]);
34
+ const importPlan = Schema.Struct({
35
+ entries: Schema.Array(plannedEntry).check(Schema.isMinLength(1), Schema.isMaxLength(MAX_IMPORT_ENTRIES)),
36
+ method: Schema.Literal("session.import.preview"),
37
+ });
38
+ const cut = (text) => text.length > MAX_REASON_CHARACTERS
39
+ ? `${text.slice(0, MAX_REASON_CHARACTERS - 1)}…`
40
+ : text;
41
+ const identityOf = ({ harness, index, nativeId }) => ({
42
+ harness,
43
+ index,
44
+ nativeId,
45
+ });
46
+ const refusedBy = (identity, error) => ({
47
+ ...identity,
48
+ outcome: "refused",
49
+ reason: cut(`${error.code}: ${error.message}`),
50
+ });
51
+ const managerFields = ({ labels, role, title }) => ({
52
+ ...(labels === undefined ? {} : { labels }),
53
+ ...(role === undefined ? {} : { role }),
54
+ ...(title === undefined ? {} : { title }),
55
+ });
56
+ const plannedFrom = (identity, commandId, value) => "alreadyAdopted" in value
57
+ ? {
58
+ ...identity,
59
+ outcome: "skipped",
60
+ sessionId: value.alreadyAdopted.sessionId,
61
+ }
62
+ : {
63
+ ...identity,
64
+ commandId,
65
+ connectionId: value.connectionId,
66
+ expiresAt: value.expiresAt,
67
+ ...(value.hostAuthority === true
68
+ ? { hostAuthority: true }
69
+ : {}),
70
+ inputDigest: value.inputDigest,
71
+ outcome: "adopt",
72
+ ...(value.permission === undefined
73
+ ? {}
74
+ : { permission: value.permission }),
75
+ ...managerFields(value),
76
+ previewId: value.previewId,
77
+ workingDirectory: value.workingDirectory,
78
+ workspaceId: value.workspaceId,
79
+ };
80
+ const previewEntry = (entry, previewAdopt) => {
81
+ const identity = identityOf(entry);
82
+ return Effect.gen(function* () {
83
+ const commandId = yield* newCliIdentifier("command");
84
+ const answer = yield* previewAdopt({ ...entry.request, commandId });
85
+ return answer.ok
86
+ ? plannedFrom(identity, commandId, answer.value)
87
+ : refusedBy(identity, answer.error);
88
+ });
89
+ };
90
+ export const previewOutputBytes = (plan) => new TextEncoder().encode(jsonLine({ ok: true, result: { command: "session.import", result: plan } })).length;
91
+ export const previewImport = (entries, previewAdopt) => Effect.forEach(entries, (entry) => previewEntry(entry, previewAdopt)).pipe(Effect.map((planned) => ({
92
+ entries: planned,
93
+ method: "session.import.preview",
94
+ })), Effect.filterOrFail((plan) => previewOutputBytes(plan) <= MAX_IMPORT_BYTES, () => new CliArgumentError(`The preview artifact exceeds ${String(MAX_IMPORT_BYTES)} bytes, the most '--confirm-stdin' reads; split the import file.`)));
95
+ export const readImportPlan = (value) => {
96
+ try {
97
+ return Schema.decodeUnknownSync(importPlan, { onExcessProperty: "error" })(value);
98
+ }
99
+ catch {
100
+ throw new CliArgumentError("The piped preview is invalid; pipe the output of 'maia --json session import --from <file> --dry-run'.");
101
+ }
102
+ };
103
+ const AMBIGUOUS_CODES = new Set([
104
+ "deadline_exceeded",
105
+ "outcome_unknown",
106
+ "transport_failed",
107
+ ]);
108
+ const failedConfirm = (entry, error) => {
109
+ const identity = identityOf(entry);
110
+ if (error.code === "already_adopted")
111
+ return { ...identity, outcome: "skipped" };
112
+ return AMBIGUOUS_CODES.has(error.code)
113
+ ? {
114
+ ...identity,
115
+ commandId: entry.commandId,
116
+ outcome: "unknown",
117
+ reason: cut(`${error.message} Check 'maia receipt show ${entry.commandId}' before importing again.`),
118
+ }
119
+ : refusedBy(identity, error);
120
+ };
121
+ const mismatch = (entry, value) => {
122
+ const differs = [
123
+ ["command ID", value.commandId, entry.commandId],
124
+ ["input digest", value.inputDigest, entry.inputDigest],
125
+ ["executor", value.adoption.executor, entry.harness],
126
+ ["native ID", value.adoption.nativeId, entry.nativeId],
127
+ ["connection", value.adoption.connectionId, entry.connectionId],
128
+ ].filter(([, got, wanted]) => got !== wanted);
129
+ return differs.length === 0
130
+ ? undefined
131
+ : differs.map(([name]) => name).join(", ");
132
+ };
133
+ const confirmed = (entry, value) => {
134
+ const differs = mismatch(entry, value);
135
+ return differs === undefined
136
+ ? {
137
+ ...identityOf(entry),
138
+ commandId: entry.commandId,
139
+ delivery: value.delivery,
140
+ outcome: "adopted",
141
+ receiptId: value.receipt.receiptId,
142
+ sessionId: value.session.id,
143
+ }
144
+ : {
145
+ ...identityOf(entry),
146
+ commandId: entry.commandId,
147
+ outcome: "unknown",
148
+ reason: cut(`The Node confirmed a different adoption than the preview (${differs}). Check 'maia receipt show ${entry.commandId}' before importing again.`),
149
+ };
150
+ };
151
+ const settled = (entry, answer) => answer.ok
152
+ ? confirmed(entry, answer.value)
153
+ : failedConfirm(entry, answer.error);
154
+ const carried = (entry) => entry.outcome === "skipped"
155
+ ? { ...identityOf(entry), outcome: "skipped", sessionId: entry.sessionId }
156
+ : { ...identityOf(entry), outcome: "refused", reason: entry.reason };
157
+ const confirmEntry = (entry, stopped, confirmAdopt) => {
158
+ if (entry.outcome !== "adopt")
159
+ return Effect.succeed(carried(entry));
160
+ if (stopped)
161
+ return Effect.succeed({
162
+ ...identityOf(entry),
163
+ commandId: entry.commandId,
164
+ outcome: "not-attempted",
165
+ });
166
+ return confirmAdopt({
167
+ inputDigest: entry.inputDigest,
168
+ previewId: entry.previewId,
169
+ }).pipe(Effect.map((answer) => settled(entry, answer)));
170
+ };
171
+ export const confirmImport = (plan, confirmAdopt) => Effect.reduce(plan.entries, () => ({ entries: [], stopped: false }), (state, entry) => confirmEntry(entry, state.stopped, confirmAdopt).pipe(Effect.map((result) => ({
172
+ entries: [...state.entries, result],
173
+ stopped: state.stopped || result.outcome === "unknown",
174
+ })))).pipe(Effect.map(({ entries }) => ({
175
+ entries,
176
+ method: "session.import.confirm",
177
+ })));
178
+ export const firstFailure = (result) => {
179
+ const failed = result.entries.find((entry) => entry.outcome !== "adopted" && entry.outcome !== "skipped");
180
+ if (failed === undefined)
181
+ return undefined;
182
+ if (failed.outcome === "refused")
183
+ return {
184
+ code: ADOPTION_REFUSED_ERROR_CODE,
185
+ message: failed.reason,
186
+ retryable: false,
187
+ };
188
+ return {
189
+ code: "outcome_unknown",
190
+ message: failed.outcome === "unknown"
191
+ ? failed.reason
192
+ : `Entry ${String(failed.index)} was not attempted.`,
193
+ retryable: false,
194
+ };
195
+ };
196
+ //# sourceMappingURL=batch.js.map
@@ -1,11 +1,11 @@
1
- import { type DiscoverySessionsListParameters, type DiscoverySessionsListResult, type SessionAdoptConfirmResult, type SessionAdoptPreviewParameters, type SessionAdoptPreviewResult, type SessionHistoryReadParameters, type SessionHistoryReadResult } from "@maiaos/sdk";
1
+ import { type DiscoverySessionsListParameters, type DiscoverySessionsListResult, type SessionAdoptConfirmParameters, type SessionAdoptConfirmResult, type SessionAdoptPreviewOutcome, type SessionAdoptPreviewParameters, type SessionHistoryReadParameters, type SessionHistoryReadResult } from "@maiaos/sdk";
2
2
  import { type CliNodeEffect, type CliNodeOperations } from "../local-node/index.js";
3
3
  type AdoptInput = Omit<SessionAdoptPreviewParameters, "commandId"> & {
4
4
  readonly commandId?: string;
5
5
  };
6
6
  export declare const makeDiscoveryClient: (node: CliNodeOperations) => {
7
- previewSessionAdopt: (input: AdoptInput) => CliNodeEffect<SessionAdoptPreviewResult>;
8
- confirmSessionAdopt: (previewId: string) => CliNodeEffect<SessionAdoptConfirmResult>;
7
+ previewSessionAdopt: (input: AdoptInput) => CliNodeEffect<SessionAdoptPreviewOutcome>;
8
+ confirmSessionAdopt: (input: SessionAdoptConfirmParameters) => CliNodeEffect<SessionAdoptConfirmResult>;
9
9
  listDiscoveredSessions: (input: DiscoverySessionsListParameters) => CliNodeEffect<DiscoverySessionsListResult>;
10
10
  readSessionHistory: (input: SessionHistoryReadParameters) => CliNodeEffect<SessionHistoryReadResult>;
11
11
  };
@@ -5,7 +5,7 @@ const makePreviewClient = (node) => ({
5
5
  previewSessionAdopt: (input) => Effect.flatMap(commandIdentifier(input.commandId), (commandId) => node.runValidatedNodeOperation({ ...input, commandId }, sessionAdoptPreviewParametersSchema, (client, parameters, options) => client.previewSessionAdopt(parameters, options))),
6
6
  });
7
7
  const makeConfirmClient = (node) => ({
8
- confirmSessionAdopt: (previewId) => node.runValidatedNodeOperation({ previewId }, sessionAdoptConfirmParametersSchema, (client, parameters, options) => client.confirmSessionAdopt(parameters, options)),
8
+ confirmSessionAdopt: (input) => node.runValidatedNodeOperation(input, sessionAdoptConfirmParametersSchema, (client, parameters, options) => client.confirmSessionAdopt(parameters, options)),
9
9
  });
10
10
  export const makeDiscoveryClient = (node) => ({
11
11
  ...makePreviewClient(node),
@@ -2,4 +2,5 @@ import { type CommandContext, type CommandEffect } from "../command-line/index.j
2
2
  export declare const runScan: (tokens: readonly string[], context: CommandContext) => CommandEffect;
3
3
  export declare const runHistoryRead: (tokens: readonly string[], context: CommandContext) => CommandEffect;
4
4
  export declare const runAdopt: (tokens: readonly string[], context: CommandContext) => CommandEffect;
5
+ export declare const runImport: (tokens: readonly string[], context: CommandContext) => CommandEffect;
5
6
  //# sourceMappingURL=commands.d.ts.map
@@ -1,7 +1,10 @@
1
+ import { ADOPTION_REFUSED_ERROR_CODE, } from "@maiaos/sdk";
1
2
  import { Effect } from "effect";
2
- import { CliArgumentError, parseOptions, readTwoPhaseMode, reportError, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeSuccess, } from "../command-line/index.js";
3
+ import { CliArgumentError, LABEL_OPTION, parseOptions, parseOptionsWith, readTwoPhaseMode, reportError, requireOneLabelPerOption, requirePositionals, runTwoPhase, TWO_PHASE_FLAGS, writeSuccess, } from "../command-line/index.js";
4
+ import { confirmImport, firstFailure, previewImport, readImportPlan, } from "./batch.js";
3
5
  import { readAdopt, readHistory, readScan } from "./input.js";
4
- import { formatAdoptConfirm, formatAdoptPreview, formatHistory, formatScan, } from "./output.js";
6
+ import { parseManifest, readManifestFile } from "./manifest.js";
7
+ import { formatAdoptConfirm, formatAdoptPreview, formatHistory, formatImportPreview, formatImportResult, formatScan, } from "./output.js";
5
8
  const missingClient = () => Effect.fail(new CliArgumentError("Session discovery is unavailable."));
6
9
  const write = (response, context, output) => {
7
10
  if (!response.ok)
@@ -39,14 +42,34 @@ export const runHistoryRead = (tokens, context) => Effect.gen(function* () {
39
42
  format: formatHistory,
40
43
  });
41
44
  }).pipe(Effect.catch(failed(context)));
42
- const previewIdOf = (preview) => {
45
+ const confirmationOf = (preview) => {
43
46
  const previewId = Reflect.get(preview, "previewId");
44
- if (typeof previewId !== "string" || !previewId.startsWith("adopt_"))
47
+ const inputDigest = Reflect.get(preview, "inputDigest");
48
+ if (typeof previewId !== "string" ||
49
+ !previewId.startsWith("adopt_") ||
50
+ typeof inputDigest !== "string")
45
51
  throw new CliArgumentError("The piped preview is invalid; pipe the output of 'maia --json session adopt … --dry-run'.");
46
- return previewId;
52
+ return { inputDigest, previewId };
47
53
  };
48
54
  const readAdoptMode = (tokens, context) => {
49
- const parsed = parseOptions(tokens, new Set(["--command-id", "--permission", "--workspace"]), new Set(["--attest-ended", "--host-authority", ...TWO_PHASE_FLAGS]));
55
+ requireOneLabelPerOption(tokens);
56
+ const parsed = parseOptionsWith(tokens, {
57
+ allowed: new Set([
58
+ "--command-id",
59
+ "--label",
60
+ "--name",
61
+ "--permission",
62
+ "--role",
63
+ "--title",
64
+ "--workspace",
65
+ ]),
66
+ allowedFlags: new Set([
67
+ "--attest-ended",
68
+ "--host-authority",
69
+ ...TWO_PHASE_FLAGS,
70
+ ]),
71
+ repeatable: LABEL_OPTION,
72
+ });
50
73
  const mode = readTwoPhaseMode(parsed.flags, context);
51
74
  if (mode === "confirm-stdin")
52
75
  requirePositionals(parsed.positionals, 0);
@@ -57,10 +80,10 @@ export const runAdopt = (tokens, context) => Effect.gen(function* () {
57
80
  const previewSessionAdopt = yield* required(context, "previewSessionAdopt");
58
81
  const confirmSessionAdopt = yield* required(context, "confirmSessionAdopt");
59
82
  return yield* runTwoPhase({
60
- confirm: (preview) => Effect.suspend(() => confirmSessionAdopt(previewIdOf(preview))),
83
+ confirm: (preview) => Effect.suspend(() => confirmSessionAdopt(confirmationOf(preview))),
61
84
  context,
62
85
  mode,
63
- preview: () => Effect.suspend(() => previewSessionAdopt(readAdopt(parsed))),
86
+ preview: () => Effect.suspend(() => previewSessionAdopt(readAdopt(parsed))).pipe(Effect.map(refuseAlreadyAdopted)),
64
87
  prompt: { describe: formatAdoptPreview, question: "Adopt this session?" },
65
88
  writeConfirm: (result) => write(result, context, {
66
89
  command: "session.adopt.confirm",
@@ -72,4 +95,55 @@ export const runAdopt = (tokens, context) => Effect.gen(function* () {
72
95
  }),
73
96
  });
74
97
  }).pipe(Effect.catch(failed(context)));
98
+ const refuseAlreadyAdopted = (response) => response.ok && "alreadyAdopted" in response.value
99
+ ? {
100
+ error: {
101
+ code: ADOPTION_REFUSED_ERROR_CODE,
102
+ message: `Maia Session ${response.value.alreadyAdopted.sessionId} already adopted this session.`,
103
+ retryable: false,
104
+ },
105
+ ok: false,
106
+ }
107
+ : response;
108
+ const IMPORT_INCOMPLETE = 1;
109
+ const readImportSource = (parsed, mode) => {
110
+ const from = parsed.options.get("--from");
111
+ if (mode === "confirm-stdin" && from !== undefined)
112
+ throw new CliArgumentError("Option '--from' belongs to the preview; '--confirm-stdin' takes the piped preview.");
113
+ if (mode !== "confirm-stdin" && from === undefined)
114
+ throw new CliArgumentError("Option '--from' is required.");
115
+ return from ?? "";
116
+ };
117
+ const importWriter = (context, format, failure) => (result) => {
118
+ if (!result.ok)
119
+ return reportError(result.error, context);
120
+ const error = failure?.(result.value);
121
+ writeSuccess({ command: "session.import", result: result.value }, error === undefined ? context : { ...context, error, ok: false }, () => format(result.value));
122
+ return error === undefined ? 0 : IMPORT_INCOMPLETE;
123
+ };
124
+ const ok = (value) => ({ ok: true, value });
125
+ const IMPORT_PROMPT = {
126
+ describe: formatImportPreview,
127
+ question: "Adopt these sessions?",
128
+ };
129
+ const readImportArguments = (tokens, context) => {
130
+ const parsed = parseOptions(tokens, new Set(["--from"]), new Set(TWO_PHASE_FLAGS));
131
+ requirePositionals(parsed.positionals, 0);
132
+ const mode = readTwoPhaseMode(parsed.flags, context);
133
+ return { from: readImportSource(parsed, mode), mode };
134
+ };
135
+ export const runImport = (tokens, context) => Effect.gen(function* () {
136
+ const { from, mode } = readImportArguments(tokens, context);
137
+ const previewAdopt = yield* required(context, "previewSessionAdopt");
138
+ const confirmAdopt = yield* required(context, "confirmSessionAdopt");
139
+ return yield* runTwoPhase({
140
+ confirm: (piped) => Effect.suspend(() => confirmImport(readImportPlan(piped), confirmAdopt)).pipe(Effect.map(ok)),
141
+ context,
142
+ mode,
143
+ preview: () => readManifestFile(from).pipe(Effect.flatMap(parseManifest), Effect.flatMap((entries) => previewImport(entries, previewAdopt)), Effect.map(ok)),
144
+ prompt: IMPORT_PROMPT,
145
+ writeConfirm: importWriter(context, formatImportResult, firstFailure),
146
+ writePreview: importWriter(context, formatImportPreview),
147
+ });
148
+ }).pipe(Effect.catch(failed(context)));
75
149
  //# sourceMappingURL=commands.js.map
@@ -1,3 +1,3 @@
1
1
  export { type DiscoveryCliDependencies, makeDiscoveryClient, } from "./client.js";
2
- export { runAdopt, runHistoryRead, runScan } from "./commands.js";
2
+ export { runAdopt, runHistoryRead, runImport, runScan } from "./commands.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export { makeDiscoveryClient, } from "./client.js";
2
- export { runAdopt, runHistoryRead, runScan } from "./commands.js";
2
+ export { runAdopt, runHistoryRead, runImport, runScan } from "./commands.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { sessionCreateParametersSchema, } from "@maiaos/sdk";
2
- import { CliArgumentError, parseOptions, readPageSize, readPermission, requirePositionals, } from "../command-line/index.js";
2
+ import { CliArgumentError, parseOptions, readLabels, readPageSize, readPermission, readSessionRole, readSessionTitle, requirePositionals, } from "../command-line/index.js";
3
3
  export const validPermission = (permission, executor) => {
4
4
  const valid = sessionCreateParametersSchema.safeParse({
5
5
  commandId: "command_validate",
@@ -33,18 +33,28 @@ const readDays = (value) => {
33
33
  return days;
34
34
  };
35
35
  const readScanLimit = (value) => value === undefined ? 50 : readPageSize(value);
36
+ const readAdoptedFilter = (flags) => {
37
+ if (flags.has("--adopted") && flags.has("--not-adopted"))
38
+ throw new CliArgumentError("Options '--adopted' and '--not-adopted' cannot be used together.");
39
+ if (flags.has("--adopted"))
40
+ return "only";
41
+ return flags.has("--not-adopted") ? "none" : undefined;
42
+ };
36
43
  export const readScan = (tokens) => {
37
- const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--root", "--since", "--source"]), new Set(["--include-content"]));
44
+ const parsed = parseOptions(tokens, new Set(["--after", "--limit", "--root", "--since", "--source"]), new Set(["--adopted", "--include-content", "--not-adopted", "--running"]));
38
45
  requirePositionals(parsed.positionals, 0);
46
+ const adopted = readAdoptedFilter(parsed.flags);
39
47
  const cursor = parsed.options.get("--after");
40
48
  const root = parsed.options.get("--root");
41
49
  const sinceDays = readDays(parsed.options.get("--since"));
42
50
  return {
51
+ ...(adopted === undefined ? {} : { adopted }),
43
52
  ...(cursor === undefined ? {} : { cursor }),
44
53
  ...(parsed.flags.has("--include-content")
45
54
  ? { includeContentFields: true }
46
55
  : {}),
47
56
  limit: readScanLimit(parsed.options.get("--limit")),
57
+ ...(parsed.flags.has("--running") ? { observed: "running" } : {}),
48
58
  ...(root === undefined ? {} : { roots: [root] }),
49
59
  ...(sinceDays === undefined ? {} : { sinceDays }),
50
60
  sources: readSources(parsed.options.get("--source")),
@@ -99,6 +109,7 @@ export const readAdopt = (parsed) => {
99
109
  if (permission !== undefined && !hostAuthority)
100
110
  throw new CliArgumentError("Option '--permission' needs '--host-authority'.");
101
111
  const target = readNativeTarget(parsed.positionals[0] ?? "");
112
+ const title = readSessionTitle(parsed.options);
102
113
  return {
103
114
  ...(parsed.flags.has("--attest-ended")
104
115
  ? { attestEnded: true }
@@ -106,6 +117,9 @@ export const readAdopt = (parsed) => {
106
117
  ...(commandId === undefined ? {} : { commandId }),
107
118
  ...(hostAuthority ? { hostAuthority: true } : {}),
108
119
  ...readPermission(permission, (value) => validPermission(value, target.executor)),
120
+ ...readLabels(parsed.options.get("--label")),
121
+ ...readSessionRole(parsed.options.get("--role")),
122
+ ...(title === undefined ? {} : { title }),
109
123
  ...target,
110
124
  workspaceId,
111
125
  };