@operad-io/cli 0.0.1 → 0.1.1
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/README.md +19 -0
- package/package.json +13 -12
- package/src/defaults.ts +5 -4
- package/src/main.ts +57 -27
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @operad-io/cli
|
|
2
|
+
|
|
3
|
+
**The `operad` command.** The command line for operad: set up a home, run `operad serve`, open the terminal client, see what is pending, and run plugin commands. It needs [Bun](https://bun.com).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add -g @operad-io/cli
|
|
9
|
+
operad --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`npm install -g @operad-io/cli` also works while `bun` is on your `PATH`. Then run `operad init` and `operad serve` or `operad tui`.
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
- User guide: [docs/user/cli.md](https://github.com/operad-io/operad/blob/main/docs/user/cli.md)
|
|
17
|
+
- Website: <https://operad.io>
|
|
18
|
+
|
|
19
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "operad: an open orchestration layer for coding agents
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "operad: an open orchestration layer for coding agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
"operad": "bin/operad.ts"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@operad-io/engine": "0.
|
|
16
|
-
"@operad-io/mcp": "0.
|
|
17
|
-
"@operad-io/shell": "0.
|
|
18
|
-
"@operad-io/chat": "0.
|
|
19
|
-
"@operad-io/dev": "0.
|
|
20
|
-
"@operad-io/harness-codex": "0.
|
|
21
|
-
"@operad-io/harness-pi": "0.
|
|
22
|
-
"@operad-io/harness-radian": "0.
|
|
23
|
-
"@operad-io/pool": "0.
|
|
24
|
-
"@operad-io/bot": "0.
|
|
15
|
+
"@operad-io/engine": "0.1.1",
|
|
16
|
+
"@operad-io/mcp": "0.1.1",
|
|
17
|
+
"@operad-io/shell": "0.1.1",
|
|
18
|
+
"@operad-io/chat": "0.1.1",
|
|
19
|
+
"@operad-io/dev": "0.1.1",
|
|
20
|
+
"@operad-io/harness-codex": "0.1.1",
|
|
21
|
+
"@operad-io/harness-pi": "0.1.1",
|
|
22
|
+
"@operad-io/harness-radian": "0.1.1",
|
|
23
|
+
"@operad-io/pool": "0.1.1",
|
|
24
|
+
"@operad-io/bot": "0.1.1",
|
|
25
|
+
"@operad-io/telegram": "0.1.1"
|
|
25
26
|
},
|
|
26
27
|
"license": "MIT",
|
|
27
28
|
"files": [
|
package/src/defaults.ts
CHANGED
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
} from "@operad-io/engine";
|
|
9
9
|
|
|
10
10
|
/** The plugins `operad init` installs, in load order. */
|
|
11
|
-
export const DEFAULT_PLUGINS: readonly string[] = ["shell", "radian", "chat", "dev"];
|
|
11
|
+
export const DEFAULT_PLUGINS: readonly string[] = ["shell", "radian", "chat", "pool", "dev"];
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Plugins shipped with operad that `
|
|
15
|
-
*
|
|
14
|
+
* Plugins shipped with operad that `plugin enable <name>` can add. Most are not
|
|
15
|
+
* in the default config; `pool` is, and stays here so a home made before init
|
|
16
|
+
* installed it can still enable it.
|
|
16
17
|
*/
|
|
17
|
-
export const OPTIONAL_PLUGINS: readonly string[] = ["pi", "claude", "codex", "pool", "bot"];
|
|
18
|
+
export const OPTIONAL_PLUGINS: readonly string[] = ["pi", "claude", "codex", "pool", "bot", "telegram"];
|
|
18
19
|
|
|
19
20
|
/** The plugins whose package is installed into the home rather than shipped with the CLI. */
|
|
20
21
|
export const INSTALL_ON_ENABLE: readonly string[] = ["claude"];
|
package/src/main.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { INSTALL_ON_ENABLE, OPTIONAL_PLUGINS, defaultPluginModule, distributionC
|
|
|
2
2
|
import { closeSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
|
|
3
3
|
import { userInfo } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { isatty } from "node:tty";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import {
|
|
7
8
|
ConfigError,
|
|
@@ -131,16 +132,47 @@ function isClosedPipe(error: unknown): boolean {
|
|
|
131
132
|
);
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/** stdout's width when it is a terminal; a stream that cannot be read leaves it unknown. */
|
|
136
|
+
function stdoutColumns(): number | undefined {
|
|
137
|
+
if (!isatty(1)) return undefined;
|
|
138
|
+
try {
|
|
139
|
+
return process.stdout.columns;
|
|
140
|
+
} catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const hookedStreams = new WeakSet<NodeJS.WriteStream>();
|
|
146
|
+
|
|
147
|
+
function hookStream(stream: NodeJS.WriteStream): void {
|
|
148
|
+
if (hookedStreams.has(stream)) return;
|
|
149
|
+
hookedStreams.add(stream);
|
|
150
|
+
// A write that fails later arrives as an error event; EPIPE ends output the
|
|
151
|
+
// same way, anything else stays an unhandled error as it was.
|
|
152
|
+
stream.on("error", (error) => {
|
|
153
|
+
if (isClosedPipe(error)) {
|
|
154
|
+
outputClosed = true;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
134
161
|
/**
|
|
135
162
|
* Writes to a process stream. A closed pipe (EPIPE) stops all output without a
|
|
136
163
|
* message; any other write error is thrown as before. The write is synchronous
|
|
137
164
|
* on the descriptor: Bun reports a write queued behind a full pipe as done and
|
|
138
165
|
* drops it at exit, so a reader that closes meanwhile went unseen and the
|
|
139
166
|
* status was 0.
|
|
167
|
+
*
|
|
168
|
+
* The stream is read only here, not when the module loads: under
|
|
169
|
+
* `bun test --isolate`, Bun can leave a stale epoll registration for a stdio
|
|
170
|
+
* stream of an earlier file, so merely reading process.stdout fails with
|
|
171
|
+
* EEXIST before this command writes anything (oven-sh/bun#37968).
|
|
140
172
|
*/
|
|
141
|
-
function writeStream(
|
|
173
|
+
function writeStream(fd: 1 | 2, text: string): void {
|
|
142
174
|
if (outputClosed) return;
|
|
143
|
-
|
|
175
|
+
hookStream(fd === 2 ? process.stderr : process.stdout);
|
|
144
176
|
try {
|
|
145
177
|
const bytes = Buffer.from(text);
|
|
146
178
|
let offset = 0;
|
|
@@ -159,21 +191,9 @@ function writeStream(stream: NodeJS.WriteStream, text: string): void {
|
|
|
159
191
|
}
|
|
160
192
|
}
|
|
161
193
|
|
|
162
|
-
// A write that fails later arrives as an error event; EPIPE ends output the
|
|
163
|
-
// same way, anything else stays an unhandled error as it was.
|
|
164
|
-
for (const stream of [process.stdout, process.stderr]) {
|
|
165
|
-
stream.on("error", (error) => {
|
|
166
|
-
if (isClosedPipe(error)) {
|
|
167
|
-
outputClosed = true;
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
throw error;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
194
|
const STDIO: CliIo = {
|
|
175
|
-
write: (text) => writeStream(
|
|
176
|
-
error: (text) => writeStream(
|
|
195
|
+
write: (text) => writeStream(1, text),
|
|
196
|
+
error: (text) => writeStream(2, text),
|
|
177
197
|
};
|
|
178
198
|
|
|
179
199
|
/** A command line mistake; exit code 2. */
|
|
@@ -434,14 +454,18 @@ function kernelFor(
|
|
|
434
454
|
io: CliIo,
|
|
435
455
|
rules: readonly TriggerRule[],
|
|
436
456
|
): Kernel {
|
|
437
|
-
|
|
457
|
+
const kernel = new Kernel({
|
|
438
458
|
log: context.log,
|
|
439
459
|
registry: context.registry,
|
|
440
460
|
home: context.home,
|
|
441
461
|
storeRoot: context.storeRoot,
|
|
442
462
|
rules,
|
|
463
|
+
client: context.views,
|
|
443
464
|
onLog: (message) => io.error(`${message}\n`),
|
|
444
465
|
});
|
|
466
|
+
// A source plugin's `pending` shows the candidates HTTP shows.
|
|
467
|
+
context.views.useCandidates(kernel);
|
|
468
|
+
return kernel;
|
|
445
469
|
}
|
|
446
470
|
|
|
447
471
|
function splitFlag(
|
|
@@ -1053,8 +1077,9 @@ function noteField(args: ActionArgsSchema | undefined): string | undefined {
|
|
|
1053
1077
|
return undefined;
|
|
1054
1078
|
}
|
|
1055
1079
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1080
|
+
/** Who the CLI acts as; an empty user name would be refused as an actor, so it falls back to `cli`. */
|
|
1081
|
+
export function actorOfCli(username: string = userInfo().username): Actor {
|
|
1082
|
+
return { via: "cli", id: username.length === 0 ? "cli" : username };
|
|
1058
1083
|
}
|
|
1059
1084
|
|
|
1060
1085
|
function actionCandidates(
|
|
@@ -1131,6 +1156,10 @@ async function promptNote(io: CliIo): Promise<string> {
|
|
|
1131
1156
|
|
|
1132
1157
|
async function readLine(io: CliIo, prompt: string): Promise<string | undefined> {
|
|
1133
1158
|
if (io.readLine !== undefined) return io.readLine(prompt);
|
|
1159
|
+
// Only the real command reads the process streams. A caller that injected
|
|
1160
|
+
// its io supplies readLine when it wants prompts; reading the streams there
|
|
1161
|
+
// could hit Bun's stale epoll registration (oven-sh/bun#37968).
|
|
1162
|
+
if (io !== STDIO) return undefined;
|
|
1134
1163
|
const { createInterface } = await import("node:readline/promises");
|
|
1135
1164
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1136
1165
|
try {
|
|
@@ -2082,12 +2111,15 @@ async function readSecretValue(io: CliIo): Promise<string> {
|
|
|
2082
2111
|
if (line === undefined) throw new UsageError("secret set: no value was read");
|
|
2083
2112
|
return line.replace(/\r?\n$/, "");
|
|
2084
2113
|
}
|
|
2085
|
-
if (
|
|
2114
|
+
if (!isatty(0)) {
|
|
2086
2115
|
const text = await Bun.stdin.text();
|
|
2087
2116
|
const line = text.split(/\r?\n/, 1)[0];
|
|
2088
2117
|
if (line === undefined) throw new UsageError("secret set: no value was read");
|
|
2089
2118
|
return line;
|
|
2090
2119
|
}
|
|
2120
|
+
// As in readLine, a caller that injected its io and wants a secret prompt
|
|
2121
|
+
// supplies readLine; only the real command reads the process streams.
|
|
2122
|
+
if (io !== STDIO) throw new UsageError("secret set: no value was read");
|
|
2091
2123
|
const { createInterface } = await import("node:readline/promises");
|
|
2092
2124
|
const rl = createInterface({
|
|
2093
2125
|
input: process.stdin,
|
|
@@ -2096,12 +2128,12 @@ async function readSecretValue(io: CliIo): Promise<string> {
|
|
|
2096
2128
|
});
|
|
2097
2129
|
const muted = rl as unknown as { _writeToOutput?: (text: string) => void };
|
|
2098
2130
|
muted._writeToOutput = () => undefined;
|
|
2099
|
-
writeStream(
|
|
2131
|
+
writeStream(2, "secret value: ");
|
|
2100
2132
|
try {
|
|
2101
2133
|
return (await rl.question("")).replace(/\r?\n$/, "");
|
|
2102
2134
|
} finally {
|
|
2103
2135
|
rl.close();
|
|
2104
|
-
writeStream(
|
|
2136
|
+
writeStream(2, "\n");
|
|
2105
2137
|
}
|
|
2106
2138
|
}
|
|
2107
2139
|
|
|
@@ -2441,9 +2473,7 @@ export async function main(
|
|
|
2441
2473
|
): Promise<number> {
|
|
2442
2474
|
const io = options.io ?? STDIO;
|
|
2443
2475
|
const home = options.home ?? defaultOperadHome();
|
|
2444
|
-
const tty =
|
|
2445
|
-
options.isTTY ??
|
|
2446
|
-
(process.stdout.isTTY === true && process.stdin.isTTY === true);
|
|
2476
|
+
const tty = options.isTTY ?? (isatty(1) && isatty(0));
|
|
2447
2477
|
const command = args[0];
|
|
2448
2478
|
|
|
2449
2479
|
try {
|
|
@@ -2525,7 +2555,7 @@ export async function main(
|
|
|
2525
2555
|
home,
|
|
2526
2556
|
io,
|
|
2527
2557
|
args.slice(1),
|
|
2528
|
-
options.isTTY ??
|
|
2558
|
+
options.isTTY ?? isatty(1),
|
|
2529
2559
|
);
|
|
2530
2560
|
}
|
|
2531
2561
|
|
|
@@ -2787,7 +2817,7 @@ export async function main(
|
|
|
2787
2817
|
return 0;
|
|
2788
2818
|
}
|
|
2789
2819
|
if (command === "show") {
|
|
2790
|
-
await commandShow(context, io, showRepo?.args ?? args.slice(1), tty, options.columns ??
|
|
2820
|
+
await commandShow(context, io, showRepo?.args ?? args.slice(1), tty, options.columns ?? stdoutColumns());
|
|
2791
2821
|
return 0;
|
|
2792
2822
|
}
|
|
2793
2823
|
const { args: rest, present } = splitFlag(args.slice(1), "--json");
|