@maiaos/cli 0.1.0-canary.13 → 0.1.0-canary.15

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.
@@ -10,6 +10,7 @@ export type CreateSessionInput = {
10
10
  readonly baseRef?: string;
11
11
  readonly commandId?: string;
12
12
  readonly connectionId?: string;
13
+ readonly cwd?: string;
13
14
  readonly definitionRef?: SessionCreateParameters["definitionRef"];
14
15
  readonly effort?: SessionCreateParameters["effort"];
15
16
  readonly executor?: SessionCreateParameters["executor"];
@@ -11,9 +11,11 @@ const SESSION_CREATE_OPTIONS = new Set([
11
11
  "--base",
12
12
  "--command-id",
13
13
  "--connection",
14
+ "--cwd",
14
15
  "--effort",
15
16
  "--executor",
16
17
  "--model",
18
+ "--name",
17
19
  "--agent-definition",
18
20
  "--agent-definition-version",
19
21
  "--agent-definition-digest",
@@ -118,18 +120,25 @@ const readAgentId = (options) => {
118
120
  throw new CliArgumentError(`Option '--agent' fixes the harness, Connection, model and effort; drop '${clash}'.`);
119
121
  return { agentId };
120
122
  };
123
+ const readSessionTitle = (options) => {
124
+ if (options.has("--name") && options.has("--title"))
125
+ throw new CliArgumentError("Use one of '--name' or '--title'.");
126
+ return options.get("--title") ?? options.get("--name");
127
+ };
121
128
  const readSessionSelection = (options, workspaceId) => {
122
129
  const agent = readAgentId(options);
123
130
  const commandId = options.get("--command-id");
124
131
  const connectionId = options.get("--connection");
125
132
  const executor = readExecutorKind(options.get("--executor"));
126
133
  const effort = readEffort(options.get("--effort"));
134
+ const cwd = options.get("--cwd");
127
135
  const model = options.get("--model");
128
- const title = options.get("--title");
136
+ const title = readSessionTitle(options);
129
137
  const selection = {
130
138
  ...agent,
131
139
  ...(commandId === undefined ? {} : { commandId }),
132
140
  ...(connectionId === undefined ? {} : { connectionId }),
141
+ ...(cwd === undefined ? {} : { cwd }),
133
142
  ...(effort === undefined ? {} : { effort }),
134
143
  ...(executor === undefined ? {} : { executor }),
135
144
  ...(model === undefined ? {} : { model }),
@@ -189,8 +198,9 @@ const taskSource = (parsed) => {
189
198
  const stdin = parsed.flags.has("--prompt-stdin");
190
199
  if ([file, message, stdin ? "" : undefined].filter((value) => value !== undefined).length > 1)
191
200
  throw new CliArgumentError("Use one of '--message', '--prompt-stdin' or '--from-file'.");
192
- if (file !== undefined && parsed.options.has("--title"))
193
- throw new CliArgumentError("Option '--title' names one Session; with '--from-file' each Session takes its task's first line.");
201
+ if (file !== undefined &&
202
+ (parsed.options.has("--title") || parsed.options.has("--name")))
203
+ throw new CliArgumentError("Option '--title' or '--name' names one Session; with '--from-file' each Session takes its task's first line.");
194
204
  if (file !== undefined)
195
205
  return { kind: "file", path: file };
196
206
  if (message !== undefined)
@@ -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>] [--cwd <path>] [--title <text> | --name <text>] [--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.",
@@ -3,8 +3,19 @@ import { liveTerminalWriteParametersSchema, MAX_TERMINAL_INPUT_CHUNK_BYTES, } fr
3
3
  import * as Effect from "effect/Effect";
4
4
  import { CliArgumentError, parseOptions, requirePositionals, } from "../command-line/index.js";
5
5
  import { readTerminalColumns, readTerminalControllerFence, readTerminalExpectedRevision, readTerminalGeneration, readTerminalInputSequence, readTerminalLeaseDuration, readTerminalRows, terminalControllerFenceOptionNames, } from "./arguments.js";
6
+ import { terminalInputBytes, UnknownKeyError } from "./keys.js";
6
7
  import { writeTerminalResult } from "./output/index.js";
7
8
  const optionNames = (...additional) => new Set([...terminalControllerFenceOptionNames, ...additional]);
9
+ const typedInputBytes = (options) => {
10
+ try {
11
+ return terminalInputBytes([...options].filter(([name]) => name === "--text" || name === "--keys"));
12
+ }
13
+ catch (error) {
14
+ throw error instanceof UnknownKeyError
15
+ ? new CliArgumentError(error.message)
16
+ : error;
17
+ }
18
+ };
8
19
  const commandId = (options) => {
9
20
  const value = options.get("--command-id");
10
21
  return value === undefined ? {} : { commandId: value };
@@ -99,15 +110,15 @@ export const runControllerAcquire = (tokens, context) => Effect.gen(function* ()
99
110
  }));
100
111
  });
101
112
  const parseTerminalWriteOptions = (tokens) => {
102
- const parsed = parseOptions(tokens, optionNames("--input-id", "--input-sequence"), new Set(["--input-stdin"]));
113
+ const parsed = parseOptions(tokens, optionNames("--input-id", "--input-sequence", "--keys", "--text"), new Set(["--input-stdin"]));
103
114
  requirePositionals(parsed.positionals, 1);
104
- if (!parsed.flags.has("--input-stdin")) {
105
- throw new CliArgumentError("Option '--input-stdin' is required.");
115
+ const typed = parsed.options.has("--text") || parsed.options.has("--keys");
116
+ if (parsed.flags.has("--input-stdin") === typed) {
117
+ throw new CliArgumentError("Give the input as '--input-stdin' or as '--text' and '--keys', not both.");
106
118
  }
107
119
  return parsed;
108
120
  };
109
- const readTerminalWriteScope = (tokens) => {
110
- const parsed = parseTerminalWriteOptions(tokens);
121
+ const readTerminalWriteScope = (parsed) => {
111
122
  const terminalId = requiredTerminalId(parsed.positionals);
112
123
  const inputId = parsed.options.get("--input-id");
113
124
  if (inputId === undefined) {
@@ -146,14 +157,20 @@ const readTerminalInput = (context) => {
146
157
  });
147
158
  };
148
159
  export const runTerminalInputWrite = (tokens, context) => Effect.gen(function* () {
149
- const scope = readTerminalWriteScope(tokens);
150
- const input = yield* readTerminalInput(context);
151
- if (input.length === 0) {
160
+ const parsed = parseTerminalWriteOptions(tokens);
161
+ const scope = readTerminalWriteScope(parsed);
162
+ const bytes = parsed.flags.has("--input-stdin")
163
+ ? Buffer.from(yield* readTerminalInput(context), "utf8")
164
+ : typedInputBytes(parsed.options);
165
+ if (bytes.length === 0) {
152
166
  throw new CliArgumentError("Terminal input must not be empty.");
153
167
  }
168
+ if (bytes.length > MAX_TERMINAL_INPUT_CHUNK_BYTES) {
169
+ throw new CliArgumentError(`Terminal input must be at most ${String(MAX_TERMINAL_INPUT_CHUNK_BYTES)} bytes.`);
170
+ }
154
171
  const result = yield* context.dependencies.writeTerminalInput({
155
172
  ...scope,
156
- bytesBase64: Buffer.from(input, "utf8").toString("base64"),
173
+ bytesBase64: bytes.toString("base64"),
157
174
  });
158
175
  return writeTerminalResult(result, context, (value) => ({
159
176
  command: "terminal.input.write",
@@ -0,0 +1,12 @@
1
+ import { Buffer } from "node:buffer";
2
+ declare const UnknownKeyError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
3
+ readonly _tag: "UnknownKeyError";
4
+ } & Readonly<A>;
5
+ export declare class UnknownKeyError extends UnknownKeyError_base<{
6
+ readonly message: string;
7
+ }> {
8
+ }
9
+ export declare const TERMINAL_KEY_NAMES: readonly string[];
10
+ export declare const terminalInputBytes: (parts: Iterable<readonly [option: string, value: string]>) => Buffer;
11
+ export {};
12
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { Data } from "effect";
3
+ const NAMED_KEYS = new Map([
4
+ ["Backspace", "\u007F"],
5
+ ["Delete", "\u001B[3~"],
6
+ ["Down", "\u001B[B"],
7
+ ["End", "\u001B[F"],
8
+ ["Enter", "\r"],
9
+ ["Escape", "\u001B"],
10
+ ["F1", "\u001BOP"],
11
+ ["F2", "\u001BOQ"],
12
+ ["F3", "\u001BOR"],
13
+ ["F4", "\u001BOS"],
14
+ ["F5", "\u001B[15~"],
15
+ ["F6", "\u001B[17~"],
16
+ ["F7", "\u001B[18~"],
17
+ ["F8", "\u001B[19~"],
18
+ ["F9", "\u001B[20~"],
19
+ ["F10", "\u001B[21~"],
20
+ ["F11", "\u001B[23~"],
21
+ ["F12", "\u001B[24~"],
22
+ ["Home", "\u001B[H"],
23
+ ["Insert", "\u001B[2~"],
24
+ ["Left", "\u001B[D"],
25
+ ["PageDown", "\u001B[6~"],
26
+ ["PageUp", "\u001B[5~"],
27
+ ["Right", "\u001B[C"],
28
+ ["Space", " "],
29
+ ["Tab", "\t"],
30
+ ["Up", "\u001B[A"],
31
+ ]);
32
+ export class UnknownKeyError extends Data.TaggedError("UnknownKeyError") {
33
+ }
34
+ export const TERMINAL_KEY_NAMES = [
35
+ ...NAMED_KEYS.keys(),
36
+ "C-<a..z>",
37
+ "M-<char>",
38
+ ];
39
+ const bytesOfKey = (name) => {
40
+ const named = NAMED_KEYS.get(name);
41
+ if (named !== undefined)
42
+ return named;
43
+ if (/^C-[a-z]$/u.test(name)) {
44
+ return String.fromCodePoint((name.codePointAt(2) ?? 0) - 0x60);
45
+ }
46
+ const alt = /^M-(\P{Cc})$/u.exec(name);
47
+ if (alt?.[1] !== undefined)
48
+ return `\u001B${alt[1]}`;
49
+ throw new UnknownKeyError({
50
+ message: `Unknown key '${name}'. Keys: ${TERMINAL_KEY_NAMES.join(", ")}.`,
51
+ });
52
+ };
53
+ export const terminalInputBytes = (parts) => Buffer.from([...parts]
54
+ .map(([option, value]) => option === "--text"
55
+ ? value
56
+ : value
57
+ .split(/\s+/u)
58
+ .filter((name) => name !== "")
59
+ .map(bytesOfKey)
60
+ .join(""))
61
+ .join(""), "utf8");
62
+ //# sourceMappingURL=keys.js.map
@@ -72,7 +72,7 @@ export const TERMINAL_TREE = {
72
72
  { route: "<terminal-id>", run: [terminal, "runControllerRelease"] },
73
73
  ],
74
74
  [
75
- "terminal input write <terminal-id> --input-stdin --input-id <id> --input-sequence <1..2147483647> --controller-id <id> --controller-epoch <epoch> --controller-revision <revision> --controller-expires-at <timestamp> --terminal-generation <1..65535> --expected-revision <revision> [--command-id <id>]",
75
+ "terminal input write <terminal-id> (--input-stdin | [--text <text>] [--keys <names>]) --input-id <id> --input-sequence <1..2147483647> --controller-id <id> --controller-epoch <epoch> --controller-revision <revision> --controller-expires-at <timestamp> --terminal-generation <1..65535> --expected-revision <revision> [--command-id <id>]",
76
76
  1,
77
77
  "terminal.input.write",
78
78
  "Write input to a terminal you control.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiaos/cli",
3
- "version": "0.1.0-canary.13",
3
+ "version": "0.1.0-canary.15",
4
4
  "description": "The maia CLI and MCP server: start, drive, observe and stop swarms of Claude Code and Codex agents from a terminal, a script or another agent.",
5
5
  "keywords": [
6
6
  "maia",
@@ -64,9 +64,9 @@
64
64
  "dependencies": {
65
65
  "@earendil-works/pi-tui": "1.0.0",
66
66
  "@effect/platform-node-shared": "4.0.0",
67
- "@maiaos/agent": "0.1.0-canary.13",
68
- "@maiaos/client-core": "0.1.0-canary.13",
69
- "@maiaos/sdk": "0.1.0-canary.13",
67
+ "@maiaos/agent": "0.1.0-canary.15",
68
+ "@maiaos/client-core": "0.1.0-canary.15",
69
+ "@maiaos/sdk": "0.1.0-canary.15",
70
70
  "effect": "4.0.0"
71
71
  },
72
72
  "scripts": {