@operad-io/cli 0.1.1 → 0.3.0
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 +4 -2
- package/package.json +16 -12
- package/src/code-reload.ts +81 -13
- package/src/defaults.ts +35 -19
- package/src/doctor.ts +211 -0
- package/src/http-bind.ts +2 -1
- package/src/main.ts +1176 -248
- package/src/serve-guard.ts +127 -0
- package/src/serve-stop.ts +71 -4
- package/src/markdown.ts +0 -11
package/README.md
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
bun add -g @operad-io/cli
|
|
9
|
-
operad
|
|
9
|
+
operad
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
`npm install -g @operad-io/cli` also works while `bun` is on your `PATH`.
|
|
12
|
+
`npm install -g @operad-io/cli` also works while `bun` is on your `PATH`. With
|
|
13
|
+
no command, `operad` creates the home, starts `serve`, and opens the default
|
|
14
|
+
bot's new chat; `operad --help` lists every command.
|
|
13
15
|
|
|
14
16
|
## Documentation
|
|
15
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "operad: an open orchestration layer for coding agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -12,17 +12,21 @@
|
|
|
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.
|
|
15
|
+
"@operad-io/engine": "0.3.0",
|
|
16
|
+
"@operad-io/mcp": "0.3.0",
|
|
17
|
+
"@operad-io/shell": "0.3.0",
|
|
18
|
+
"@operad-io/chat": "0.3.0",
|
|
19
|
+
"@operad-io/dev": "0.3.0",
|
|
20
|
+
"@operad-io/harness-codex": "0.3.0",
|
|
21
|
+
"@operad-io/harness-pi": "0.3.0",
|
|
22
|
+
"@operad-io/harness-radian": "0.3.0",
|
|
23
|
+
"@operad-io/pool": "0.3.0",
|
|
24
|
+
"@operad-io/bot": "0.3.0",
|
|
25
|
+
"@operad-io/telegram": "0.3.0",
|
|
26
|
+
"@operad-io/memory": "0.3.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@operad-io/test-support": "0.0.0"
|
|
26
30
|
},
|
|
27
31
|
"license": "MIT",
|
|
28
32
|
"files": [
|
package/src/code-reload.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* problems on the error stream, and the next change tries again.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { messageOf } from "@operad-io/engine";
|
|
10
11
|
import {
|
|
11
12
|
describeChange,
|
|
12
13
|
diffFingerprints,
|
|
@@ -14,9 +15,12 @@ import {
|
|
|
14
15
|
newHashCache,
|
|
15
16
|
codeRoots,
|
|
16
17
|
pluginFile,
|
|
18
|
+
secondsOf,
|
|
17
19
|
waitForCodeChange,
|
|
18
20
|
} from "@operad-io/engine";
|
|
19
21
|
import type { CodeFingerprint, CodeRoot } from "@operad-io/engine";
|
|
22
|
+
import { systemClock } from "@operad-io/engine/platform";
|
|
23
|
+
import type { Clock } from "@operad-io/engine/platform";
|
|
20
24
|
import { basename, extname, join } from "node:path";
|
|
21
25
|
import { fileURLToPath } from "node:url";
|
|
22
26
|
|
|
@@ -161,24 +165,77 @@ export function loadsAsWellAs(
|
|
|
161
165
|
return problems.every((line) => keys.has(problemKey(line)));
|
|
162
166
|
}
|
|
163
167
|
|
|
168
|
+
/**
|
|
169
|
+
* What a load check found: the problems that did not load, or that the check
|
|
170
|
+
* itself did not finish, in which case the code was not judged at all.
|
|
171
|
+
*/
|
|
172
|
+
export interface LoadProbe {
|
|
173
|
+
readonly problems: readonly string[];
|
|
174
|
+
/** False when the check did not finish: its problems say why. */
|
|
175
|
+
readonly finished: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** How long a load check may run before the old code is kept. */
|
|
179
|
+
export const PROBE_TIMEOUT_MS = 60_000;
|
|
180
|
+
|
|
181
|
+
export interface ProbeLoadOptions {
|
|
182
|
+
/** The command that loads the code; a test gives one that does not end. */
|
|
183
|
+
readonly command?: readonly string[] | undefined;
|
|
184
|
+
readonly timeoutMs?: number | undefined;
|
|
185
|
+
/** The timers of the limit; tests inject theirs. */
|
|
186
|
+
readonly clock?: Clock | undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
164
189
|
/**
|
|
165
190
|
* Starts a fresh process that loads the code on disk and reports what did not
|
|
166
191
|
* load, one line each. A process that cannot start reports that as the problem.
|
|
192
|
+
* A process that does not end is ended: a check that hangs has no verdict, and
|
|
193
|
+
* the watch that waits for it must not wait for good.
|
|
167
194
|
*/
|
|
168
|
-
export async function probeLoad(
|
|
195
|
+
export async function probeLoad(
|
|
196
|
+
home: string,
|
|
197
|
+
options: ProbeLoadOptions = {},
|
|
198
|
+
): Promise<LoadProbe> {
|
|
199
|
+
const clock = options.clock ?? systemClock;
|
|
200
|
+
const timeoutMs = options.timeoutMs ?? PROBE_TIMEOUT_MS;
|
|
169
201
|
const child = Bun.spawn({
|
|
170
|
-
cmd: [process.execPath, CLI_ENTRY, "check-load"],
|
|
202
|
+
cmd: options.command === undefined ? [process.execPath, CLI_ENTRY, "check-load"] : [...options.command],
|
|
171
203
|
cwd: home,
|
|
172
204
|
env: { ...process.env, OPERAD_HOME: home },
|
|
173
205
|
stdin: "ignore",
|
|
174
206
|
stdout: "pipe",
|
|
175
207
|
stderr: "pipe",
|
|
176
208
|
});
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
209
|
+
const read = (async (): Promise<{ code: number; out: string; err: string }> => {
|
|
210
|
+
const [code, out, err] = await Promise.all([
|
|
211
|
+
child.exited,
|
|
212
|
+
new Response(child.stdout).text(),
|
|
213
|
+
new Response(child.stderr).text(),
|
|
214
|
+
]);
|
|
215
|
+
return { code, out, err };
|
|
216
|
+
})();
|
|
217
|
+
let timer: unknown;
|
|
218
|
+
const limit = new Promise<"timeout">((resolve) => {
|
|
219
|
+
timer = clock.setTimeout(() => resolve("timeout"), timeoutMs);
|
|
220
|
+
});
|
|
221
|
+
let outcome: { code: number; out: string; err: string } | "timeout";
|
|
222
|
+
try {
|
|
223
|
+
outcome = await Promise.race([read, limit]);
|
|
224
|
+
} finally {
|
|
225
|
+
clock.clearTimeout(timer);
|
|
226
|
+
}
|
|
227
|
+
if (outcome === "timeout") {
|
|
228
|
+
// This process started the child, so it may end it. A descendant that keeps
|
|
229
|
+
// the pipes open is not waited for either: the check has no verdict.
|
|
230
|
+
child.kill("SIGKILL");
|
|
231
|
+
void read.catch(() => undefined);
|
|
232
|
+
await child.exited.catch(() => undefined);
|
|
233
|
+
return {
|
|
234
|
+
problems: [`the load check did not finish within ${secondsOf(timeoutMs)}`],
|
|
235
|
+
finished: false,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const { code, out, err } = outcome;
|
|
182
239
|
if (code !== 0) {
|
|
183
240
|
const last = err
|
|
184
241
|
.split("\n")
|
|
@@ -186,9 +243,12 @@ export async function probeLoad(home: string): Promise<string[]> {
|
|
|
186
243
|
.filter((line) => line.length > 0)
|
|
187
244
|
.slice(-3)
|
|
188
245
|
.join(" ");
|
|
189
|
-
return
|
|
246
|
+
return {
|
|
247
|
+
problems: [`operad does not start: ${last.length > 0 ? last : `exit ${code}`}`],
|
|
248
|
+
finished: true,
|
|
249
|
+
};
|
|
190
250
|
}
|
|
191
|
-
return out.split("\n").filter((line) => line.length > 0);
|
|
251
|
+
return { problems: out.split("\n").filter((line) => line.length > 0), finished: true };
|
|
192
252
|
}
|
|
193
253
|
|
|
194
254
|
export interface CodeCheckOptions {
|
|
@@ -197,6 +257,8 @@ export interface CodeCheckOptions {
|
|
|
197
257
|
/** The problems this process had when it loaded. */
|
|
198
258
|
readonly known: readonly string[];
|
|
199
259
|
readonly onProblem: (message: string) => void;
|
|
260
|
+
/** How long the fresh process may take; defaults to `PROBE_TIMEOUT_MS`. */
|
|
261
|
+
readonly probeTimeoutMs?: number | undefined;
|
|
200
262
|
/**
|
|
201
263
|
* When set, a change that does not load is waited out instead of skipped:
|
|
202
264
|
* the check does not return until the files load or match what the process
|
|
@@ -223,10 +285,16 @@ export function codeChecker(
|
|
|
223
285
|
const seen = fingerprintCode(watched, options.snapshot.cache);
|
|
224
286
|
const change = diffFingerprints(options.snapshot.baseline, current);
|
|
225
287
|
if (change === undefined) return undefined;
|
|
226
|
-
const
|
|
227
|
-
|
|
288
|
+
const probe = await probeLoad(options.home, {
|
|
289
|
+
timeoutMs: options.probeTimeoutMs,
|
|
290
|
+
});
|
|
291
|
+
if (probe.finished && loadsAsWellAs(probe.problems, options.known)) {
|
|
292
|
+
return describeChange(change);
|
|
293
|
+
}
|
|
228
294
|
options.onProblem(
|
|
229
|
-
|
|
295
|
+
probe.finished
|
|
296
|
+
? `code changed (${describeChange(change)}) but does not load; the old code keeps running: ${probe.problems.join("; ")}`
|
|
297
|
+
: `code changed (${describeChange(change)}) but the load check did not finish; the old code keeps running: ${probe.problems.join("; ")}`,
|
|
230
298
|
);
|
|
231
299
|
if (options.waitPollMs === undefined) return undefined;
|
|
232
300
|
// A settings file that did not read may be fixed, so it wakes the wait
|
|
@@ -318,7 +386,7 @@ export async function superviseServe(
|
|
|
318
386
|
// The old code is gone too: say so rather than leave the one line
|
|
319
387
|
// that promised its addresses standing as the last word.
|
|
320
388
|
log(
|
|
321
|
-
`reload: the old code could not listen either (${
|
|
389
|
+
`reload: the old code could not listen either (${messageOf(error)}); this serve ends\n`,
|
|
322
390
|
);
|
|
323
391
|
throw error;
|
|
324
392
|
} finally {
|
package/src/defaults.ts
CHANGED
|
@@ -7,19 +7,34 @@ import {
|
|
|
7
7
|
type PluginOffer,
|
|
8
8
|
} from "@operad-io/engine";
|
|
9
9
|
|
|
10
|
-
/** The plugins `operad init` installs, in load order. */
|
|
11
|
-
export const DEFAULT_PLUGINS: readonly string[] = ["shell", "radian", "chat", "pool", "dev"];
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
|
-
* Plugins shipped with operad that `plugin enable <name>` can add
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Plugins shipped with operad that `plugin enable <name>` can add, including
|
|
12
|
+
* those a new home leaves off (`shell`, `dev`, `pool`) and those a home made
|
|
13
|
+
* before the current defaults may still need (`bot`, `memory`, the harnesses).
|
|
17
14
|
*/
|
|
18
|
-
export const OPTIONAL_PLUGINS: readonly string[] = ["pi", "claude", "codex", "pool", "bot", "telegram"];
|
|
15
|
+
export const OPTIONAL_PLUGINS: readonly string[] = ["shell", "pi", "claude", "codex", "pool", "bot", "telegram", "memory", "dev"];
|
|
16
|
+
|
|
17
|
+
/** The shipped plugins a plugin needs; enabling it enables these first (ADR 0012 D2). */
|
|
18
|
+
export const PLUGIN_NEEDS: Readonly<Record<string, readonly string[]>> = {
|
|
19
|
+
dev: ["pool", "shell"],
|
|
20
|
+
};
|
|
19
21
|
|
|
20
22
|
/** The plugins whose package is installed into the home rather than shipped with the CLI. */
|
|
21
23
|
export const INSTALL_ON_ENABLE: readonly string[] = ["claude"];
|
|
22
24
|
|
|
25
|
+
/** The pi library operad installs into the home when no agent is on `PATH` (ADR 0023 D9). */
|
|
26
|
+
export const PI_CODING_AGENT_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
27
|
+
|
|
28
|
+
/** The exact pi version operad installs; it moves with an operad release. */
|
|
29
|
+
export const PI_CODING_AGENT_VERSION = "1.6.0";
|
|
30
|
+
|
|
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"];
|
|
37
|
+
|
|
23
38
|
/** Harness plugins are named after their agent; their npm packages are `harness-<agent>`. */
|
|
24
39
|
const HARNESS_PLUGINS: readonly string[] = ["claude", "codex", "pi", "radian"];
|
|
25
40
|
|
|
@@ -28,24 +43,25 @@ export function defaultPluginModule(name: string): string {
|
|
|
28
43
|
return HARNESS_PLUGINS.includes(name) ? `@operad-io/harness-${name}` : `@operad-io/${name}`;
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
/** The actions `operad init` lets a lead run:
|
|
32
|
-
export const DEFAULT_LEAD_ACTIONS: readonly string[] = [
|
|
33
|
-
"dev:rework",
|
|
34
|
-
"dev:reverify",
|
|
35
|
-
"dev:reject",
|
|
36
|
-
"dev:priority",
|
|
37
|
-
"dev:concurrency",
|
|
38
|
-
"chat:close",
|
|
39
|
-
];
|
|
46
|
+
/** The actions `operad init` lets a lead run: only actions of the plugins a new home enables. */
|
|
47
|
+
export const DEFAULT_LEAD_ACTIONS: readonly string[] = ["chat:close"];
|
|
40
48
|
|
|
41
49
|
/** The allowed actions that also need the confirmation. */
|
|
42
50
|
export const DEFAULT_CONFIRM_ACTIONS: readonly string[] = ["chat:close"];
|
|
43
51
|
|
|
44
|
-
/** The
|
|
45
|
-
export function
|
|
52
|
+
/** The plugins of a new home: the assistant's fixed ones plus its harnesses. */
|
|
53
|
+
export function defaultPluginsFor(harnesses: readonly string[]): readonly string[] {
|
|
54
|
+
return ["chat", "bot", "memory", ...harnesses];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The config a new home starts with, with the harness plugins passed in place of the fallback. */
|
|
58
|
+
export function distributionConfig(
|
|
59
|
+
home: string,
|
|
60
|
+
harnesses: readonly string[] = ["radian"],
|
|
61
|
+
): OperadConfig {
|
|
46
62
|
return {
|
|
47
63
|
...defaultConfig(home),
|
|
48
|
-
plugins:
|
|
64
|
+
plugins: defaultPluginsFor(harnesses).map((name) => ({
|
|
49
65
|
name,
|
|
50
66
|
module: defaultPluginModule(name),
|
|
51
67
|
enabled: true,
|
package/src/doctor.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `operad doctor`: one read-only pass over a home. It asks an environment for
|
|
3
|
+
* each fact and turns the answers into one line per fact; every problem line
|
|
4
|
+
* ends with the next command to type. The environment is a parameter so a test
|
|
5
|
+
* supplies the facts and nothing touches the machine or the network.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** One plugin the home enables. */
|
|
9
|
+
export interface DoctorPlugin {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly loaded: boolean;
|
|
12
|
+
/** Why it did not load. */
|
|
13
|
+
readonly problem?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** One enabled agent (harness plugin). */
|
|
17
|
+
export interface DoctorAgent {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly version?: string | undefined;
|
|
20
|
+
/** `undefined` when the agent cannot say. */
|
|
21
|
+
readonly signedIn?: boolean | undefined;
|
|
22
|
+
/** The bot whose agent this is, when operad's own login covers the agent. */
|
|
23
|
+
readonly loginBot?: string | undefined;
|
|
24
|
+
/** Why the agent cannot be used, when it cannot. */
|
|
25
|
+
readonly problem?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What `operad pending` reports as a setup problem. */
|
|
29
|
+
export interface DoctorSetupItem {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly prompt: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DoctorEnv {
|
|
35
|
+
/** Whether the home directory exists. */
|
|
36
|
+
homeExists(): boolean;
|
|
37
|
+
/** Whether `config.json` exists; throws with the reason when it is invalid. */
|
|
38
|
+
config(): Promise<{ readonly present: boolean }>;
|
|
39
|
+
plugins(): Promise<readonly DoctorPlugin[]>;
|
|
40
|
+
agents(): Promise<readonly DoctorAgent[]>;
|
|
41
|
+
serve(): Promise<{ readonly answering: boolean }>;
|
|
42
|
+
/** The test host when one is set; `undefined` when none is. */
|
|
43
|
+
testHost(): Promise<{ readonly host: string; readonly reachable: boolean } | undefined>;
|
|
44
|
+
setup(): Promise<readonly DoctorSetupItem[]>;
|
|
45
|
+
/** Whether the git program is installed; absent means the check is not made. */
|
|
46
|
+
gitInstalled?(): boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DoctorCheck {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly ok: boolean;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
/** The command to type next; present on every problem. */
|
|
54
|
+
readonly next?: string | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface DoctorReport {
|
|
58
|
+
readonly ok: boolean;
|
|
59
|
+
readonly checks: readonly DoctorCheck[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The agent's own command that signs in, for an agent operad's login does not
|
|
64
|
+
* cover. Each was checked against that agent's `--help`.
|
|
65
|
+
*/
|
|
66
|
+
const SIGN_IN: Readonly<Record<string, string>> = {
|
|
67
|
+
claude: "claude auth login",
|
|
68
|
+
codex: "codex login",
|
|
69
|
+
pi: "pi auth login <provider>",
|
|
70
|
+
radian: "radian login",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function good(id: string, message: string): DoctorCheck {
|
|
74
|
+
return { id, ok: true, message };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function bad(id: string, message: string, next: string): DoctorCheck {
|
|
78
|
+
return { id, ok: false, message, next };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function reasonOf(error: unknown): string {
|
|
82
|
+
return error instanceof Error ? error.message : String(error);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Runs every check once. It never throws: a failed ask is a problem line. */
|
|
86
|
+
export async function runDoctor(env: DoctorEnv): Promise<DoctorReport> {
|
|
87
|
+
const checks: DoctorCheck[] = [];
|
|
88
|
+
|
|
89
|
+
let loadable = false;
|
|
90
|
+
if (!env.homeExists()) {
|
|
91
|
+
checks.push(bad("home", "the operad home does not exist", "operad init"));
|
|
92
|
+
} else {
|
|
93
|
+
try {
|
|
94
|
+
const config = await env.config();
|
|
95
|
+
if (config.present) {
|
|
96
|
+
checks.push(good("home", "home and config.json are valid"));
|
|
97
|
+
loadable = true;
|
|
98
|
+
} else {
|
|
99
|
+
checks.push(bad("home", "the home has no config.json", "operad init"));
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
checks.push(
|
|
103
|
+
bad(
|
|
104
|
+
"home",
|
|
105
|
+
`config.json is not valid: ${reasonOf(error)}`,
|
|
106
|
+
"operad doctor",
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (loadable) {
|
|
113
|
+
try {
|
|
114
|
+
for (const plugin of await env.plugins()) {
|
|
115
|
+
checks.push(
|
|
116
|
+
plugin.loaded
|
|
117
|
+
? good(`plugin:${plugin.name}`, `plugin ${plugin.name} is loaded`)
|
|
118
|
+
: bad(
|
|
119
|
+
`plugin:${plugin.name}`,
|
|
120
|
+
`plugin ${plugin.name} did not load: ${plugin.problem ?? "no reason given"}`,
|
|
121
|
+
`operad plugin disable ${plugin.name}`,
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const agents = await env.agents();
|
|
126
|
+
for (const agent of agents) {
|
|
127
|
+
const id = `agent:${agent.name}`;
|
|
128
|
+
const version = agent.version === undefined ? "" : ` ${agent.version}`;
|
|
129
|
+
if (agent.problem !== undefined) {
|
|
130
|
+
checks.push(
|
|
131
|
+
bad(id, `agent ${agent.name} cannot be used: ${agent.problem}`, "operad init"),
|
|
132
|
+
);
|
|
133
|
+
} else if (agent.signedIn === false) {
|
|
134
|
+
checks.push(
|
|
135
|
+
bad(
|
|
136
|
+
id,
|
|
137
|
+
`agent ${agent.name}${version} is not signed in`,
|
|
138
|
+
agent.loginBot === undefined
|
|
139
|
+
? (SIGN_IN[agent.name] ?? `sign in to ${agent.name}, then operad doctor`)
|
|
140
|
+
: `operad bot:login ${agent.loginBot}`,
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
checks.push(
|
|
145
|
+
good(
|
|
146
|
+
id,
|
|
147
|
+
`agent ${agent.name}${version}${agent.signedIn === true ? ", signed in" : ""}`,
|
|
148
|
+
),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (agents.length === 0) {
|
|
153
|
+
checks.push(bad("agents", "no agent is enabled", "operad plugin enable pi"));
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
checks.push(bad("plugins", `plugins could not be read: ${reasonOf(error)}`, "operad doctor"));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const serve = await env.serve();
|
|
162
|
+
checks.push(
|
|
163
|
+
serve.answering
|
|
164
|
+
? good("serve", "serve is answering")
|
|
165
|
+
: bad("serve", "serve is not answering", "operad serve"),
|
|
166
|
+
);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
checks.push(bad("serve", `serve could not be checked: ${reasonOf(error)}`, "operad serve"));
|
|
169
|
+
}
|
|
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
|
+
|
|
176
|
+
if (loadable) {
|
|
177
|
+
try {
|
|
178
|
+
const host = await env.testHost();
|
|
179
|
+
if (host !== undefined) {
|
|
180
|
+
checks.push(
|
|
181
|
+
host.reachable
|
|
182
|
+
? good("test-host", `test host ${host.host} is reachable`)
|
|
183
|
+
: bad("test-host", `test host ${host.host} is not reachable`, `ssh ${host.host}`),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
for (const item of await env.setup()) {
|
|
187
|
+
// A standing item that already names a command: that is the next step.
|
|
188
|
+
const named = /`([^`]+)`/.exec(item.prompt)?.[1];
|
|
189
|
+
checks.push(
|
|
190
|
+
named === undefined
|
|
191
|
+
? bad(`setup:${item.id}`, item.prompt, "operad pending")
|
|
192
|
+
: { id: `setup:${item.id}`, ok: false, message: item.prompt, next: named },
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
} catch (error) {
|
|
196
|
+
checks.push(bad("setup", `setup could not be read: ${reasonOf(error)}`, "operad pending"));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return { ok: checks.every((check) => check.ok), checks };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The lines `operad doctor` prints: `ok` or `problem`, then the fact and, for a problem, what to type. */
|
|
204
|
+
export function formatDoctor(report: DoctorReport): string {
|
|
205
|
+
const lines = report.checks.map((check) => {
|
|
206
|
+
if (check.ok) return `ok ${check.message}`;
|
|
207
|
+
const next = check.next === undefined ? "" : ` -> ${check.next}`;
|
|
208
|
+
return `problem ${check.message}${next}`;
|
|
209
|
+
});
|
|
210
|
+
return `${lines.join("\n")}\n`;
|
|
211
|
+
}
|
package/src/http-bind.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* bounded time before the new code gives up.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { messageOf } from "@operad-io/engine";
|
|
8
9
|
import { ConfigError, HttpStopError } from "@operad-io/engine";
|
|
9
10
|
import { RELOAD_EXIT, takeSupervisedFlag } from "./code-reload.ts";
|
|
10
11
|
|
|
@@ -22,7 +23,7 @@ export interface BindRetryOptions {
|
|
|
22
23
|
/** The new code could not listen in time; the old code has to serve. */
|
|
23
24
|
export class BindFailed extends Error {
|
|
24
25
|
constructor(cause: unknown) {
|
|
25
|
-
super(
|
|
26
|
+
super(messageOf(cause));
|
|
26
27
|
this.name = "BindFailed";
|
|
27
28
|
}
|
|
28
29
|
}
|