@operad-io/cli 0.2.0 → 0.3.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/package.json +13 -13
- package/src/defaults.ts +6 -2
- package/src/doctor.ts +7 -0
- package/src/main.ts +7 -1
- package/src/serve-stop.ts +68 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "operad: an open orchestration layer for coding agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -12,18 +12,18 @@
|
|
|
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.
|
|
25
|
-
"@operad-io/telegram": "0.
|
|
26
|
-
"@operad-io/memory": "0.
|
|
15
|
+
"@operad-io/engine": "0.3.1",
|
|
16
|
+
"@operad-io/mcp": "0.3.1",
|
|
17
|
+
"@operad-io/shell": "0.3.1",
|
|
18
|
+
"@operad-io/chat": "0.3.1",
|
|
19
|
+
"@operad-io/dev": "0.3.1",
|
|
20
|
+
"@operad-io/harness-codex": "0.3.1",
|
|
21
|
+
"@operad-io/harness-pi": "0.3.1",
|
|
22
|
+
"@operad-io/harness-radian": "0.3.1",
|
|
23
|
+
"@operad-io/pool": "0.3.1",
|
|
24
|
+
"@operad-io/bot": "0.3.1",
|
|
25
|
+
"@operad-io/telegram": "0.3.1",
|
|
26
|
+
"@operad-io/memory": "0.3.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@operad-io/test-support": "0.0.0"
|
package/src/defaults.ts
CHANGED
|
@@ -28,8 +28,12 @@ export const PI_CODING_AGENT_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
|
28
28
|
/** The exact pi version operad installs; it moves with an operad release. */
|
|
29
29
|
export const PI_CODING_AGENT_VERSION = "1.6.0";
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The agent commands `operad init` looks for, in this order. The first one is
|
|
33
|
+
* a new chat's default agent, so agents that carry every access level come
|
|
34
|
+
* before radian, which cannot carry `plan` or `ask` (ADR 0028 D2).
|
|
35
|
+
*/
|
|
36
|
+
export const INIT_HARNESS_PLUGINS: readonly string[] = ["claude", "pi", "radian"];
|
|
33
37
|
|
|
34
38
|
/** Harness plugins are named after their agent; their npm packages are `harness-<agent>`. */
|
|
35
39
|
const HARNESS_PLUGINS: readonly string[] = ["claude", "codex", "pi", "radian"];
|
package/src/doctor.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface DoctorEnv {
|
|
|
42
42
|
/** The test host when one is set; `undefined` when none is. */
|
|
43
43
|
testHost(): Promise<{ readonly host: string; readonly reachable: boolean } | undefined>;
|
|
44
44
|
setup(): Promise<readonly DoctorSetupItem[]>;
|
|
45
|
+
/** Whether the git program is installed; absent means the check is not made. */
|
|
46
|
+
gitInstalled?(): boolean;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export interface DoctorCheck {
|
|
@@ -166,6 +168,11 @@ export async function runDoctor(env: DoctorEnv): Promise<DoctorReport> {
|
|
|
166
168
|
checks.push(bad("serve", `serve could not be checked: ${reasonOf(error)}`, "operad serve"));
|
|
167
169
|
}
|
|
168
170
|
|
|
171
|
+
// Not a problem: chat and file changes work without git, which only a task needs.
|
|
172
|
+
if (env.gitInstalled !== undefined && !env.gitInstalled()) {
|
|
173
|
+
checks.push(good("git", "git is not installed: chat works without it, and a task needs it"));
|
|
174
|
+
}
|
|
175
|
+
|
|
169
176
|
if (loadable) {
|
|
170
177
|
try {
|
|
171
178
|
const host = await env.testHost();
|
package/src/main.ts
CHANGED
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
type ViewRow,
|
|
100
100
|
} from "@operad-io/engine";
|
|
101
101
|
import { loginBotFor } from "@operad-io/bot";
|
|
102
|
-
import { stopAllKeptWorkers } from "@operad-io/engine/platform";
|
|
102
|
+
import { findGit, stopAllKeptWorkers } from "@operad-io/engine/platform";
|
|
103
103
|
import { ChannelTypeError, runMcpServer } from "@operad-io/mcp";
|
|
104
104
|
import {
|
|
105
105
|
guardBackgroundBusy,
|
|
@@ -132,6 +132,7 @@ import { QrTooLongError, encodeQr, renderQr } from "./qr.ts";
|
|
|
132
132
|
import {
|
|
133
133
|
DEFAULT_STOP_TIMEOUT_SECS,
|
|
134
134
|
parseStopTimeout,
|
|
135
|
+
recordSupervisor,
|
|
135
136
|
serveStop,
|
|
136
137
|
} from "./serve-stop.ts";
|
|
137
138
|
|
|
@@ -897,6 +898,7 @@ function systemDoctorEnv(home: string, io: CliIo): DoctorEnv & { close(): Promis
|
|
|
897
898
|
return { answering: false };
|
|
898
899
|
}
|
|
899
900
|
},
|
|
901
|
+
gitInstalled: () => findGit() !== undefined,
|
|
900
902
|
testHost: async () => {
|
|
901
903
|
const { registry } = await context();
|
|
902
904
|
const fromEnv = process.env.OPERAD_CHECK_HOST;
|
|
@@ -2793,10 +2795,12 @@ export function pluginAdminFor(
|
|
|
2793
2795
|
if (!row.enabled) return row;
|
|
2794
2796
|
const signedIn = await context.registry.signedInFor(row.name);
|
|
2795
2797
|
const models = context.registry.loadedModels()[row.name];
|
|
2798
|
+
const capabilities = context.registry.loadedCapabilities()[row.name];
|
|
2796
2799
|
return {
|
|
2797
2800
|
...row,
|
|
2798
2801
|
...(signedIn === undefined ? {} : { signedIn }),
|
|
2799
2802
|
...(models === undefined ? {} : { models }),
|
|
2803
|
+
...(capabilities === undefined ? {} : { accessLevels: capabilities.accessLevels ?? [] }),
|
|
2800
2804
|
};
|
|
2801
2805
|
};
|
|
2802
2806
|
/** The rows, plus a plugin still being installed before the file names it. */
|
|
@@ -3518,6 +3522,8 @@ export async function main(
|
|
|
3518
3522
|
restored: boolean,
|
|
3519
3523
|
): Promise<"stopped" | "reload"> => {
|
|
3520
3524
|
const lock = acquireLock(serveLockPath(home));
|
|
3525
|
+
// `serve stop` reaches the supervisor too, so it can stop a reload that is in flight.
|
|
3526
|
+
if (isSupervised) recordSupervisor(home);
|
|
3521
3527
|
// Held across a reload's wait for the stores, so a busy write that
|
|
3522
3528
|
// work of the old context left running is never unguarded.
|
|
3523
3529
|
const unguard = guardBackgroundBusy({
|
package/src/serve-stop.ts
CHANGED
|
@@ -9,13 +9,50 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { StateError, pidAlive, readLockPid, serveLockPath } from "@operad-io/engine";
|
|
12
|
-
import { stopAllKeptWorkers } from "@operad-io/engine/platform";
|
|
13
|
-
import { existsSync } from "node:fs";
|
|
12
|
+
import { stopAllKeptWorkers, writeJsonAtomicSync } from "@operad-io/engine/platform";
|
|
13
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
14
15
|
|
|
15
16
|
export const DEFAULT_STOP_TIMEOUT_SECS = 30;
|
|
16
17
|
const COMMAND_ASKS = 20;
|
|
17
18
|
const COMMAND_ASK_WAIT_MS = 50;
|
|
18
19
|
|
|
20
|
+
function supervisorPath(home: string): string {
|
|
21
|
+
return join(home, "serve-supervisor.json");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A serve that runs under a supervisor names it in the home: the supervisor
|
|
26
|
+
* outlives each serve it starts and starts the next one after a reload, so
|
|
27
|
+
* `serve stop` must reach it, not only the serve that holds the lock.
|
|
28
|
+
*/
|
|
29
|
+
export function recordSupervisor(home: string, pid: number = process.ppid): void {
|
|
30
|
+
writeJsonAtomicSync(supervisorPath(home), { pid });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readSupervisor(home: string): number | undefined {
|
|
34
|
+
try {
|
|
35
|
+
const raw: unknown = JSON.parse(readFileSync(supervisorPath(home), "utf8"));
|
|
36
|
+
const pid =
|
|
37
|
+
typeof raw === "object" && raw !== null ? (raw as { pid?: unknown }).pid : undefined;
|
|
38
|
+
return typeof pid === "number" ? pid : undefined;
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The parent of a process, or undefined when `ps` cannot say. */
|
|
45
|
+
export function parentOf(pid: number): number | undefined {
|
|
46
|
+
const result = Bun.spawnSync({
|
|
47
|
+
cmd: ["ps", "-p", String(pid), "-o", "ppid="],
|
|
48
|
+
stdout: "pipe",
|
|
49
|
+
stderr: "ignore",
|
|
50
|
+
});
|
|
51
|
+
if (result.exitCode !== 0) return undefined;
|
|
52
|
+
const value = Number(result.stdout.toString().trim());
|
|
53
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
19
56
|
export interface ServeStopOptions {
|
|
20
57
|
readonly home: string;
|
|
21
58
|
readonly timeoutSecs: number;
|
|
@@ -24,6 +61,7 @@ export interface ServeStopOptions {
|
|
|
24
61
|
readonly isAlive?: ((pid: number) => boolean) | undefined;
|
|
25
62
|
readonly commandOf?: ((pid: number) => string | undefined) | undefined;
|
|
26
63
|
readonly signal?: ((pid: number) => void) | undefined;
|
|
64
|
+
readonly parentOf?: ((pid: number) => number | undefined) | undefined;
|
|
27
65
|
readonly sleep?: ((ms: number) => Promise<void>) | undefined;
|
|
28
66
|
readonly clock?: (() => number) | undefined;
|
|
29
67
|
}
|
|
@@ -61,8 +99,27 @@ export async function serveStop(options: ServeStopOptions): Promise<void> {
|
|
|
61
99
|
await stopAllKeptWorkers({ home: options.home });
|
|
62
100
|
const path = serveLockPath(options.home);
|
|
63
101
|
const isAlive = options.isAlive ?? pidAlive;
|
|
64
|
-
const
|
|
65
|
-
|
|
102
|
+
const lockPid = readLockPid(path);
|
|
103
|
+
const holder = lockPid !== undefined && isAlive(lockPid) ? lockPid : undefined;
|
|
104
|
+
// The supervisor of the serve, when there is one that is really its parent.
|
|
105
|
+
// Between two serves of a reload nothing holds the lock, and the supervisor
|
|
106
|
+
// is the only process that will start the next one.
|
|
107
|
+
let supervisor = readSupervisor(options.home);
|
|
108
|
+
if (supervisor !== undefined && !isAlive(supervisor)) supervisor = undefined;
|
|
109
|
+
// A record whose pid was reused by another process names no supervisor.
|
|
110
|
+
if (supervisor !== undefined) {
|
|
111
|
+
const supervisorCommand = (options.commandOf ?? processCommand)(supervisor);
|
|
112
|
+
if (supervisorCommand !== undefined && !isServeCommand(supervisorCommand)) {
|
|
113
|
+
rmSync(supervisorPath(options.home), { force: true });
|
|
114
|
+
supervisor = undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (supervisor !== undefined && holder !== undefined && holder !== supervisor) {
|
|
118
|
+
const parent = (options.parentOf ?? parentOf)(holder);
|
|
119
|
+
if (parent !== undefined && parent !== supervisor) supervisor = undefined;
|
|
120
|
+
}
|
|
121
|
+
const pid = supervisor ?? holder;
|
|
122
|
+
if (pid === undefined) {
|
|
66
123
|
options.write(`no operad serve runs for ${options.home}\n`);
|
|
67
124
|
return;
|
|
68
125
|
}
|
|
@@ -99,7 +156,13 @@ export async function serveStop(options: ServeStopOptions): Promise<void> {
|
|
|
99
156
|
const clock = options.clock ?? (() => Date.now());
|
|
100
157
|
const deadline = clock() + options.timeoutSecs * 1_000;
|
|
101
158
|
for (;;) {
|
|
102
|
-
|
|
159
|
+
// The supervisor is gone, and so is every serve it started: the lock
|
|
160
|
+
// names no live process, or the file is gone.
|
|
161
|
+
const current = readLockPid(path);
|
|
162
|
+
const served = current !== undefined && isAlive(current) && existsSync(path);
|
|
163
|
+
const supervised = supervisor !== undefined && isAlive(supervisor);
|
|
164
|
+
if (supervisor === undefined ? !isAlive(pid) || !existsSync(path) : !supervised && !served) {
|
|
165
|
+
if (supervisor !== undefined) rmSync(supervisorPath(options.home), { force: true });
|
|
103
166
|
options.write("stopped\n");
|
|
104
167
|
return;
|
|
105
168
|
}
|