@0perator/operator 0.1.313 → 0.1.321
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/dist/autonomy/agent-cli.js +6 -2
- package/dist/autonomy/cron.js +1 -1
- package/dist/autonomy/delegate.js +29 -4
- package/dist/autonomy/index.js +22 -0
- package/dist/autonomy/profile.js +1 -1
- package/dist/browser/cdp.js +1 -1
- package/dist/cli.js +119 -43
- package/dist/config/persona.js +29 -12
- package/dist/config/settings.js +12 -7
- package/dist/engine/agent.js +4 -2
- package/dist/engine/aurora.js +8 -3
- package/dist/engine/batch-scheduler.js +3 -3
- package/dist/engine/cli.js +1171 -0
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/loop-guard.js +1 -1
- package/dist/engine/router-adapter.js +1 -0
- package/dist/idle/activity.js +20 -0
- package/dist/idle/index.js +5 -0
- package/dist/idle/monitor.js +71 -0
- package/dist/idle/policy.js +66 -0
- package/dist/idle/proc.js +22 -0
- package/dist/idle/reaper.js +69 -0
- package/dist/idle/session-record.js +59 -0
- package/dist/index.js +1 -1
- package/dist/mcp/config.js +72 -14
- package/dist/mcp/index.js +9 -2
- package/dist/memory/index.js +1 -1
- package/dist/permissions/index.js +22 -7
- package/dist/permissions/tier.js +1 -1
- package/dist/remote/host.js +20 -2
- package/dist/remote/safe-commands.js +38 -0
- package/dist/router/models.js.bak +78 -0
- package/dist/router/models.js.bak-1791259923 +78 -0
- package/dist/router/models.js.bak-pre-gateway +78 -0
- package/dist/router/models.js.bak-pre-patch2 +78 -0
- package/dist/router/models.js.bak2 +78 -0
- package/dist/services/model-autodetect.js +240 -0
- package/dist/services/preflight.js +54 -2
- package/dist/services/store-sync.js +111 -0
- package/dist/session-teardown.js +10 -1
- package/dist/session.js +22 -0
- package/dist/skills/catalogue.js +1 -1
- package/dist/tools/chauffeur-native.js +155 -0
- package/dist/tools/chauffeur.js +14 -3
- package/dist/tools/download.js +229 -0
- package/dist/tools/executor.js +1 -1
- package/dist/tools/monitoring-tools.js +312 -0
- package/dist/tools/native-redirect.js +140 -0
- package/dist/tools/paths.js +154 -0
- package/dist/tools/power-tools.js +627 -0
- package/dist/tools/registry.js +309 -18
- package/dist/tools/registry.js.bak-1791259948 +1914 -0
- package/dist/tools/registry.js.bak-pre-plugins +1914 -0
- package/dist/tools/shell-jobs.js +5 -2
- package/dist/tools/shell-session.js +4 -2
- package/dist/tools/tool-output-spill.js +1 -1
- package/dist/ui/BusTray.js +70 -0
- package/dist/ui/Composer.js +5 -2
- package/dist/ui/QuestionPrompt.js +1 -1
- package/dist/ui/ToolStep.js +16 -1
- package/dist/ui/liveTools.js +1 -1
- package/dist/ui/resize.js +160 -0
- package/dist/util/mentions.js +1 -1
- package/dist/vault/store.js +1 -1
- package/mcp/README.md +88 -0
- package/mcp/ocr-macos.swift +45 -0
- package/mcp/powertools-media.mjs +464 -0
- package/mcp/powertools-toolbox.mjs +1114 -0
- package/mcp/powertools.md +210 -0
- package/mcp/powertools.mjs +861 -0
- package/package.json +2 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Model auto-detect boot — connect to whatever model is HEALTHY, local or remote, instead of hard-launching
|
|
2
|
+
// one port and freezing the boot when it is down. (Incident 2026-10-10: the JL2 Aurora gguf vanished, the
|
|
3
|
+
// boot kickstarted com.imi.aurora-serve and HARD-WAITED 90s on a dead :8097, then quit — bricking Operator
|
|
4
|
+
// while cortana, a healthy 35B, answered on JL1:8112 the whole time.)
|
|
5
|
+
//
|
|
6
|
+
// The shape, and the split that makes it testable:
|
|
7
|
+
// • buildCandidates() PURE — the ordered list to try: (a) the active model's endpoint, (b) same-model
|
|
8
|
+
// standbys (failover, fleet nodes), (c) every other registry profile; cloud/BYO last.
|
|
9
|
+
// • detectBoot() the decision flow over an INJECTED probe/launch/sleep (no network in tests):
|
|
10
|
+
// probe → first healthy by priority wins → (only if none) wait out a model that is
|
|
11
|
+
// already loading → cloud tier → Service-lever launch as the LAST resort → degraded.
|
|
12
|
+
// • probeCandidate() the real network probe (short timeout, /health and /v1/models raced in parallel).
|
|
13
|
+
// Nothing here knows what "aurora" is: every entry is just {base, model, ctx}. Aurora is one candidate.
|
|
14
|
+
import { authHeaders } from "../engine/aurora.js";
|
|
15
|
+
import { endpointBase } from "../router/models.js";
|
|
16
|
+
const norm = (base) => base.replace(/\/+$/, "").toLowerCase();
|
|
17
|
+
const keyOf = (c) => `${norm(c.base)}|${c.model}`;
|
|
18
|
+
/** host:port of a base, for the one-line "→ model: …" notice. Falls back to the raw string. */
|
|
19
|
+
export function hostPort(base) {
|
|
20
|
+
try {
|
|
21
|
+
return new URL(base).host;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return base;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The ordered candidate list. PURE. Priority: active → standbys → registry (local/LAN first, cloud last);
|
|
28
|
+
* de-duplicated on base+model so the registry's own copy of the active profile never probes twice. */
|
|
29
|
+
export function buildCandidates(i) {
|
|
30
|
+
const out = [];
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const add = (c) => {
|
|
33
|
+
const k = keyOf(c);
|
|
34
|
+
if (seen.has(k))
|
|
35
|
+
return;
|
|
36
|
+
seen.add(k);
|
|
37
|
+
out.push(c);
|
|
38
|
+
};
|
|
39
|
+
const a = i.active;
|
|
40
|
+
// An active BYO profile (the owner's /model qwen3.8-max) carries its vendor key + dialect on the registry entry.
|
|
41
|
+
const ap = i.registry.find((p) => p.id === a.id);
|
|
42
|
+
add({ id: a.id, label: a.label ?? a.id, base: a.base, model: a.model, ctx: a.ctx, profileId: a.id, token: a.token ?? (ap?.byo ? i.byoToken?.(ap.byo) : undefined), transport: a.transport ?? ap?.transport, cloud: false, source: "active" });
|
|
43
|
+
if (i.enabled === false)
|
|
44
|
+
return out;
|
|
45
|
+
for (const s of i.standby) {
|
|
46
|
+
if (!s.base)
|
|
47
|
+
continue;
|
|
48
|
+
add({ id: s.id, label: s.id, base: s.base, model: s.model, ctx: s.ctx, cloud: false, source: "standby" });
|
|
49
|
+
}
|
|
50
|
+
const profiles = i.registry.filter((p) => p.kind === "single" && !!p.endpoint && p.autodetect !== false);
|
|
51
|
+
const cloud = (p) => !!p.byo;
|
|
52
|
+
for (const p of [...profiles.filter((p) => !cloud(p)), ...(i.allowCloud === false ? [] : profiles.filter(cloud))]) {
|
|
53
|
+
const token = p.byo ? i.byoToken?.(p.byo) : undefined;
|
|
54
|
+
if (p.byo && !token)
|
|
55
|
+
continue; // a connector with no resolvable key can never answer — don't list a guaranteed ✗
|
|
56
|
+
add({ id: p.id, label: p.label, base: endpointBase(p.endpoint), model: p.model ?? p.id, ctx: p.ctx ?? a.ctx, profileId: p.id, token, transport: p.transport, cloud: cloud(p), source: "registry" });
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** The router chain to adopt for a chosen candidate: it first, then the other LOCAL candidates that serve the
|
|
61
|
+
* SAME model (the aurora nodes), so a mid-session death still hops to a sibling instead of stranding. A
|
|
62
|
+
* different model is never mixed in — a failover must not silently change which model answers. PURE. */
|
|
63
|
+
export function routerChain(chosen, all) {
|
|
64
|
+
const toEp = (c) => ({ name: c.id, base: c.base, model: c.model, ctxLimit: c.ctx, token: c.token, transport: c.transport });
|
|
65
|
+
const sib = all.filter((c) => c !== chosen && !c.cloud && !chosen.cloud && c.model === chosen.model && keyOf(c) !== keyOf(chosen));
|
|
66
|
+
return [toEp(chosen), ...sib.map(toEp)];
|
|
67
|
+
}
|
|
68
|
+
/** Probe one candidate. `/health` (llama.cpp, mlx_lm, gateways) and `/v1/models` (Ollama, any OpenAI-compatible
|
|
69
|
+
* server with no /health) are raced IN PARALLEL under ONE short timeout, so the worst case is the timeout, not
|
|
70
|
+
* a serial pair. ready = a 2xx that doesn't say it is still starting; loading = the port answered 503 (llama.cpp
|
|
71
|
+
* serves 503 while it mmaps the model — alive, must not be restarted); down = refused / timed out / 4xx. Never throws. */
|
|
72
|
+
export async function probeCandidate(c, o = {}) {
|
|
73
|
+
const f = o.fetchImpl ?? fetch;
|
|
74
|
+
const ctrl = new AbortController();
|
|
75
|
+
const timer = setTimeout(() => ctrl.abort(), o.timeoutMs ?? 2500);
|
|
76
|
+
const onAbort = () => ctrl.abort();
|
|
77
|
+
o.signal?.addEventListener("abort", onAbort, { once: true });
|
|
78
|
+
const headers = authHeaders({ base: c.base, model: c.model, token: c.token });
|
|
79
|
+
const base = c.base.replace(/\/+$/, "");
|
|
80
|
+
const get = async (path) => {
|
|
81
|
+
try {
|
|
82
|
+
const r = await f(`${base}${path}`, { signal: ctrl.signal, headers });
|
|
83
|
+
if (r.status === 503)
|
|
84
|
+
return "loading";
|
|
85
|
+
if (!r.ok)
|
|
86
|
+
return "down";
|
|
87
|
+
if (path !== "/health")
|
|
88
|
+
return "ready";
|
|
89
|
+
const j = await r.json().catch(() => undefined);
|
|
90
|
+
return j && typeof j.status === "string" && j.status !== "ok" ? "loading" : "ready"; // 200 {"status":"loading model"} is alive-but-not-serving
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return "down";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
// First `ready` wins at once (a healthy endpoint must not wait on its slower sibling request); otherwise the
|
|
98
|
+
// verdict is "loading" if either request saw a 503, else "down".
|
|
99
|
+
return await new Promise((resolve) => {
|
|
100
|
+
const seen = [];
|
|
101
|
+
for (const p of [get("/health"), get("/v1/models")]) {
|
|
102
|
+
void p.then((s) => {
|
|
103
|
+
if (s === "ready")
|
|
104
|
+
return resolve("ready");
|
|
105
|
+
seen.push(s);
|
|
106
|
+
if (seen.length === 2)
|
|
107
|
+
resolve(seen.includes("loading") ? "loading" : "down");
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
o.signal?.removeEventListener("abort", onAbort);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Fire every probe in parallel, then walk them in PRIORITY order: the first `ready` wins the moment every
|
|
118
|
+
* higher-priority candidate has settled — so a healthy active endpoint returns at once and never waits on a
|
|
119
|
+
* dead LAN host's timeout further down the list. Stragglers are aborted. */
|
|
120
|
+
async function pickFirstReady(cands, deps) {
|
|
121
|
+
const ctrl = new AbortController();
|
|
122
|
+
const memo = new Map(); // one probe per base+token — qwen3.8-max and -flash share a host
|
|
123
|
+
const run = (c) => {
|
|
124
|
+
const k = `${norm(c.base)}|${c.token ? "t" : ""}`;
|
|
125
|
+
let p = memo.get(k);
|
|
126
|
+
if (!p) {
|
|
127
|
+
p = deps.probe(c, ctrl.signal).catch(() => "down");
|
|
128
|
+
memo.set(k, p);
|
|
129
|
+
}
|
|
130
|
+
return p;
|
|
131
|
+
};
|
|
132
|
+
const pending = cands.map(run);
|
|
133
|
+
const attempts = [];
|
|
134
|
+
try {
|
|
135
|
+
for (let i = 0; i < cands.length; i++) {
|
|
136
|
+
const status = await pending[i];
|
|
137
|
+
attempts.push({ candidate: cands[i], status });
|
|
138
|
+
if (status === "ready")
|
|
139
|
+
return { chosen: cands[i], attempts };
|
|
140
|
+
}
|
|
141
|
+
return { attempts };
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
ctrl.abort();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** The boot decision flow. Never throws, never blocks longer than: one probe timeout (+ `waitSec` if a model is
|
|
148
|
+
* already loading, + the caller-bounded launch when nothing is healthy and one is configured). */
|
|
149
|
+
export async function detectBoot(cands, deps) {
|
|
150
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
151
|
+
const now = deps.now ?? Date.now;
|
|
152
|
+
const waitSec = deps.waitSec ?? 25;
|
|
153
|
+
const local = cands.filter((c) => !c.cloud);
|
|
154
|
+
const cloud = cands.filter((c) => c.cloud);
|
|
155
|
+
const tried = [];
|
|
156
|
+
const note = (a) => { for (const x of a)
|
|
157
|
+
if (!tried.some((t) => t.candidate === x.candidate))
|
|
158
|
+
tried.push(x); };
|
|
159
|
+
const done = (chosen, launch) => {
|
|
160
|
+
const failed = tried.filter((t) => t.candidate !== chosen && t.status !== "ready");
|
|
161
|
+
if (launch?.state === "started")
|
|
162
|
+
return { kind: "launched", chosen, tried: failed, launch };
|
|
163
|
+
return { kind: chosen === cands[0] ? "primary" : "alternate", chosen, tried: failed };
|
|
164
|
+
};
|
|
165
|
+
const first = await pickFirstReady(local, deps);
|
|
166
|
+
note(first.attempts);
|
|
167
|
+
if (first.chosen)
|
|
168
|
+
return done(first.chosen);
|
|
169
|
+
// Something is already coming up on its own (llama.cpp 503 while it mmaps): wait it out, bounded — never
|
|
170
|
+
// restart a mid-load model, and never freeze on it past `waitSec`.
|
|
171
|
+
const loading = local.filter((c) => tried.some((t) => t.candidate === c && t.status === "loading"));
|
|
172
|
+
if (loading.length) {
|
|
173
|
+
deps.onProgress?.(`${loading[0].label} is loading…`);
|
|
174
|
+
const deadline = now() + waitSec * 1000;
|
|
175
|
+
while (now() < deadline) {
|
|
176
|
+
await sleep(1000);
|
|
177
|
+
const r = await pickFirstReady(loading, deps);
|
|
178
|
+
for (const a of r.attempts) {
|
|
179
|
+
const t = tried.find((x) => x.candidate === a.candidate);
|
|
180
|
+
if (t)
|
|
181
|
+
t.status = a.status;
|
|
182
|
+
}
|
|
183
|
+
if (r.chosen)
|
|
184
|
+
return done(r.chosen);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (cloud.length) {
|
|
188
|
+
deps.onProgress?.("no local model answered — trying connected cloud models…");
|
|
189
|
+
const r = await pickFirstReady(cloud, deps);
|
|
190
|
+
note(r.attempts);
|
|
191
|
+
if (r.chosen)
|
|
192
|
+
return done(r.chosen);
|
|
193
|
+
}
|
|
194
|
+
// LAST resort — and never while something is mid-load (that service is already starting itself).
|
|
195
|
+
let launch;
|
|
196
|
+
if (deps.launch && !loading.length) {
|
|
197
|
+
deps.onProgress?.("no model reachable — trying the local launchd model…");
|
|
198
|
+
launch = await deps.launch().catch((e) => ({ state: "down", detail: String(e?.message ?? e) }));
|
|
199
|
+
if (launch.state === "up" || launch.state === "started") {
|
|
200
|
+
const r = await pickFirstReady(local, deps);
|
|
201
|
+
for (const a of r.attempts) {
|
|
202
|
+
const t = tried.find((x) => x.candidate === a.candidate);
|
|
203
|
+
if (t)
|
|
204
|
+
t.status = a.status;
|
|
205
|
+
else
|
|
206
|
+
tried.push(a);
|
|
207
|
+
}
|
|
208
|
+
if (r.chosen)
|
|
209
|
+
return done(r.chosen, launch);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { kind: "degraded", tried, launch };
|
|
213
|
+
}
|
|
214
|
+
/** What a boot outcome says about ONE base, for the dashboard's service tiles. undefined = it was never probed
|
|
215
|
+
* (e.g. a healthy higher-priority endpoint won before the walk reached it) — never claim a state we didn't observe. PURE. */
|
|
216
|
+
export function stateOfBase(o, base) {
|
|
217
|
+
const b = norm(base);
|
|
218
|
+
if (o.kind !== "degraded" && norm(o.chosen.base) === b)
|
|
219
|
+
return o.kind === "launched" ? "started" : "up";
|
|
220
|
+
return o.tried.some((t) => norm(t.candidate.base) === b) ? "down" : undefined;
|
|
221
|
+
}
|
|
222
|
+
const mark = (s) => (s === "ready" ? "✓" : s === "loading" ? "…" : "✗");
|
|
223
|
+
/** The scrollback notice for an outcome — "" for the happy path (the services line already confirms it). PURE. */
|
|
224
|
+
export function describeOutcome(o) {
|
|
225
|
+
if (o.kind === "primary")
|
|
226
|
+
return "";
|
|
227
|
+
if (o.kind === "degraded") {
|
|
228
|
+
const rows = o.tried.map((t) => ` ${mark(t.status)} ${t.candidate.id} ${hostPort(t.candidate.base)} ${t.status}`);
|
|
229
|
+
const lane = o.launch ? `\n launch: ${o.launch.detail ?? o.launch.state}` : "";
|
|
230
|
+
return `no model reachable — tried:\n${rows.join("\n")}${lane}\nOperator is open but has no model yet. Pick one with /model <id>, pin an endpoint with /route <name>, or point Operator at a running model in your settings and relaunch. The next message re-checks.`;
|
|
231
|
+
}
|
|
232
|
+
const c = o.chosen;
|
|
233
|
+
const where = `${c.id} @ ${hostPort(c.base)}`;
|
|
234
|
+
const cloudNote = c.cloud ? " (cloud — your own API key; nothing local was reachable)" : "";
|
|
235
|
+
// Two endpoints can share an id (KODE_AURORA re-points the active operator-1m while the registry still lists its
|
|
236
|
+
// own) — name the host only where the id alone would be ambiguous.
|
|
237
|
+
const nameOf = (c) => (o.tried.filter((t) => t.candidate.id === c.id).length > 1 ? `${c.id}@${hostPort(c.base)}` : c.id);
|
|
238
|
+
const skipped = o.tried.length ? `\n skipped: ${o.tried.map((t) => `${nameOf(t.candidate)} (${t.status})`).join(", ")}` : "";
|
|
239
|
+
return `→ model: ${where}${cloudNote}${o.kind === "launched" ? " (launched)" : ""}${skipped}`;
|
|
240
|
+
}
|
|
@@ -126,11 +126,63 @@ async function ensureLaunchd(name, healthUrl, okOnly, cfg, onProgress) {
|
|
|
126
126
|
? { name, state: "started" }
|
|
127
127
|
: { name, state: "down", detail: `started the launchd job but ${name} did not report ready at ${healthUrl} within ${waitSec}s` };
|
|
128
128
|
}
|
|
129
|
+
/** The live gateway the supervisor publishes to ~/.operator/runtime/server.json. The contract is
|
|
130
|
+
* that the supervisor writes {base_url, api_key, pid} and consumers read BOTH: `base` to reach the dynamic
|
|
131
|
+
* port, `apiKey` to authenticate to it. Returns null when server.json is absent (gateway not running yet). */
|
|
132
|
+
export async function discoverAuroraServer() {
|
|
133
|
+
try {
|
|
134
|
+
const { readFile } = await nodeImport("node:fs/promises");
|
|
135
|
+
const serverJson = `${process.env.HOME ?? ""}/.operator/runtime/server.json`;
|
|
136
|
+
const raw = await readFile(serverJson, "utf8");
|
|
137
|
+
const state = JSON.parse(raw);
|
|
138
|
+
if (state.base_url && typeof state.base_url === "string") {
|
|
139
|
+
return { base: state.base_url, apiKey: typeof state.api_key === "string" ? state.api_key : undefined };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch { /* server.json absent or unreadable — gateway not running yet */ }
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
/** Back-compat shim: just the base_url (e.g. "http://127.0.0.1:52100/v1") or null. */
|
|
146
|
+
export async function discoverAuroraEndpoint() {
|
|
147
|
+
return (await discoverAuroraServer())?.base ?? null;
|
|
148
|
+
}
|
|
129
149
|
/** Ensure the services Operator depends on are up. Aurora first (required, health-gated); autopilot and
|
|
130
|
-
* vision are optional and never block. Returns one report per service for the boot UI.
|
|
150
|
+
* vision are optional and never block. Returns one report per service for the boot UI.
|
|
151
|
+
* Mutates cfg.aurora.base in-place when the dynamic port is discovered from server.json. */
|
|
131
152
|
export async function ensureServices(cfg) {
|
|
132
153
|
const reports = [];
|
|
133
|
-
|
|
154
|
+
// Apply a server.json discovery onto cfg.aurora (dynamic port + api_key). Falls back to the
|
|
155
|
+
// existing cfg.aurora.base when server.json is absent (e.g. a settings.json static override).
|
|
156
|
+
const applyDiscovered = (d) => {
|
|
157
|
+
if (!d)
|
|
158
|
+
return false;
|
|
159
|
+
cfg.aurora.base = d.base.replace(/\/v1\/?$/, "");
|
|
160
|
+
if (d.apiKey)
|
|
161
|
+
cfg.aurora.apiKey = d.apiKey; // carry the gateway's published key onto the cfg
|
|
162
|
+
return true;
|
|
163
|
+
};
|
|
164
|
+
applyDiscovered(await discoverAuroraServer());
|
|
165
|
+
if (cfg.aurora.base) {
|
|
166
|
+
const healthUrl = `${cfg.aurora.base.replace(/\/$/, "")}/health`;
|
|
167
|
+
reports.push(await ensureLaunchd("aurora", healthUrl, true, cfg.aurora, cfg.onProgress));
|
|
168
|
+
// After launchd start, re-discover in case the port changed (fresh spawn)
|
|
169
|
+
if (reports[0]?.state === "started" || reports[0]?.state === "down") {
|
|
170
|
+
applyDiscovered(await discoverAuroraServer());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// No endpoint discovered and no static override — kickstart the gateway, then discover
|
|
175
|
+
reports.push(await ensureLaunchd("aurora", "", true, cfg.aurora, cfg.onProgress));
|
|
176
|
+
// Wait a beat for server.json to appear after gateway start
|
|
177
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
178
|
+
const retry = await discoverAuroraServer();
|
|
179
|
+
if (applyDiscovered(retry)) {
|
|
180
|
+
const retryHealth = `${cfg.aurora.base.replace(/\/$/, "")}/health`;
|
|
181
|
+
if (await waitReady(retryHealth, true, cfg.aurora.waitSec ?? 45)) {
|
|
182
|
+
reports[reports.length - 1] = { name: "aurora", state: "started", detail: `discovered at ${retry.base}` };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
134
186
|
if (cfg.autopilot) {
|
|
135
187
|
reports.push(await ensureOptional("autopilot", cfg.autopilot, cfg.onProgress));
|
|
136
188
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { hostname } from "node:os";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
const POST_TIMEOUT = 5_000;
|
|
4
|
+
const GET_TIMEOUT = 5_000;
|
|
5
|
+
const HEALTH_TIMEOUT = 3_000;
|
|
6
|
+
export function resolveStoreKey(store) {
|
|
7
|
+
if (store.key)
|
|
8
|
+
return store.key;
|
|
9
|
+
const envName = store.keyEnv || "OPERATOR_STORE_KEY";
|
|
10
|
+
if (process.env[envName])
|
|
11
|
+
return process.env[envName];
|
|
12
|
+
if (store.keyFile) {
|
|
13
|
+
try {
|
|
14
|
+
return readFileSync(store.keyFile.replace(/^~/, process.env.HOME || "~"), "utf8").trim();
|
|
15
|
+
}
|
|
16
|
+
catch { /* unreadable */ }
|
|
17
|
+
}
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
export function createStoreClient(endpoint, key) {
|
|
21
|
+
const base = endpoint.replace(/\/+$/, "");
|
|
22
|
+
const headers = { "Content-Type": "application/json" };
|
|
23
|
+
if (key)
|
|
24
|
+
headers["Authorization"] = `Bearer ${key}`;
|
|
25
|
+
const node = hostname();
|
|
26
|
+
return {
|
|
27
|
+
async push(archive) {
|
|
28
|
+
try {
|
|
29
|
+
const body = JSON.stringify({
|
|
30
|
+
id: archive.id,
|
|
31
|
+
node,
|
|
32
|
+
cwd: archive.cwd,
|
|
33
|
+
title: archive.title,
|
|
34
|
+
model: archive.model || "",
|
|
35
|
+
started_at: archive.startedAt,
|
|
36
|
+
updated_at: archive.updatedAt,
|
|
37
|
+
messages: archive.messages,
|
|
38
|
+
version: archive.version,
|
|
39
|
+
});
|
|
40
|
+
const res = await fetch(`${base}/v1/sessions`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers,
|
|
43
|
+
body,
|
|
44
|
+
signal: AbortSignal.timeout(POST_TIMEOUT),
|
|
45
|
+
});
|
|
46
|
+
return res.ok;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async list(opts) {
|
|
53
|
+
try {
|
|
54
|
+
const params = new URLSearchParams();
|
|
55
|
+
if (opts?.node)
|
|
56
|
+
params.set("node", opts.node);
|
|
57
|
+
if (opts?.cwd)
|
|
58
|
+
params.set("cwd", opts.cwd);
|
|
59
|
+
if (opts?.limit)
|
|
60
|
+
params.set("limit", String(opts.limit));
|
|
61
|
+
const qs = params.toString();
|
|
62
|
+
const res = await fetch(`${base}/v1/sessions${qs ? `?${qs}` : ""}`, {
|
|
63
|
+
headers,
|
|
64
|
+
signal: AbortSignal.timeout(GET_TIMEOUT),
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
return [];
|
|
68
|
+
const data = await res.json();
|
|
69
|
+
return data.sessions || [];
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async fetch(id) {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(`${base}/v1/sessions/${encodeURIComponent(id)}`, {
|
|
78
|
+
headers,
|
|
79
|
+
signal: AbortSignal.timeout(GET_TIMEOUT),
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok)
|
|
82
|
+
return null;
|
|
83
|
+
const data = await res.json();
|
|
84
|
+
return {
|
|
85
|
+
version: 1,
|
|
86
|
+
id: data.id,
|
|
87
|
+
cwd: data.cwd,
|
|
88
|
+
title: data.title,
|
|
89
|
+
model: data.model,
|
|
90
|
+
startedAt: data.started_at,
|
|
91
|
+
updatedAt: data.updated_at,
|
|
92
|
+
messages: data.messages,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
async healthy() {
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch(`${base}/health`, {
|
|
102
|
+
signal: AbortSignal.timeout(HEALTH_TIMEOUT),
|
|
103
|
+
});
|
|
104
|
+
return res.ok;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
package/dist/session-teardown.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { killOwnedChildren, killOwnedChildrenSync, removePidfile } from "./util/owned-children.js";
|
|
2
|
-
|
|
2
|
+
import { removeSessionRecord } from "./idle/session-record.js";
|
|
3
|
+
export const asEndReason = (r) => (r === "quit" || r === "idle" || r === "error" ? r : "interrupted");
|
|
3
4
|
export function installProcessTeardown(t, d) {
|
|
4
5
|
t.add("session-end", (r) => d.recordEnd(asEndReason(r)), { order: 10 }); // first: record before anything is killed
|
|
6
|
+
t.add("store-sync", async () => {
|
|
7
|
+
if (!d.storeClient || !d.buildArchive)
|
|
8
|
+
return;
|
|
9
|
+
const archive = d.buildArchive();
|
|
10
|
+
if (archive)
|
|
11
|
+
await d.storeClient.push(archive).catch(() => { });
|
|
12
|
+
}, { order: 12 });
|
|
5
13
|
t.add("shells", () => d.disposeShells(), { order: 80 });
|
|
6
14
|
t.add("browser", () => d.disposeBrowser(), { order: 81 });
|
|
7
15
|
// The sweep: whatever this process spawned and still owns (background jobs, MCP servers, Chrome, shells) — waited for, then SIGKILLed.
|
|
8
16
|
t.add("owned-children", () => killOwnedChildren().then(() => undefined), { sync: () => { killOwnedChildrenSync(); }, order: 90 });
|
|
9
17
|
t.add("telemetry-flush", () => d.flushTelemetry(), { sync: () => d.flushTelemetrySync(), order: 95 });
|
|
10
18
|
t.add("pidfile", () => removePidfile(), { order: 99 });
|
|
19
|
+
t.add("session-record", () => removeSessionRecord(), { order: 99 }); // the idle reaper judges only pids that still have one
|
|
11
20
|
}
|
package/dist/session.js
CHANGED
|
@@ -949,6 +949,28 @@ export class Session {
|
|
|
949
949
|
await this.discoverMcp();
|
|
950
950
|
return this.mcpToolCount();
|
|
951
951
|
}
|
|
952
|
+
/** `/mcp reload`: rebuild the hub from disk (base + `$KODE_MCP_EXTRA` merge) and rediscover tools
|
|
953
|
+
* without restarting Operator — live-drive after `/mcp add powertools …`. */
|
|
954
|
+
async reloadMcp() {
|
|
955
|
+
this.wantMcp = true;
|
|
956
|
+
try {
|
|
957
|
+
if (this.hub) {
|
|
958
|
+
this.hub.shutdown();
|
|
959
|
+
this.hub = undefined;
|
|
960
|
+
}
|
|
961
|
+
this.hub = await McpHub.fromConfig();
|
|
962
|
+
if (!this.hub)
|
|
963
|
+
return 0;
|
|
964
|
+
this.hub.spillSink = spillToolOutput;
|
|
965
|
+
await this.hub.discover({ force: true });
|
|
966
|
+
this.tools = this.buildTools();
|
|
967
|
+
this.mcpSchemas = this.hub.schemas();
|
|
968
|
+
this.deferred = deferredEnabled(this.mcpSchemas.length, globalThis.process?.env) ? deferredState(this.mcpSchemas) : null;
|
|
969
|
+
this.tools = this.buildTools();
|
|
970
|
+
}
|
|
971
|
+
catch { /* stay local-only */ }
|
|
972
|
+
return this.mcpToolCount();
|
|
973
|
+
}
|
|
952
974
|
/** Local registry schemas plus any fleet MCP tool schemas discovered this session.
|
|
953
975
|
* Under HV3-04 deferral: locals + only the MCP tools described this session + the meta trio. */
|
|
954
976
|
allSchemas() {
|
package/dist/skills/catalogue.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// ships in the repo (operator-home/skills-catalogue/), activating a skill = copying its tree into
|
|
3
3
|
// $KODE_HOME/skills/<category>/<name>/ where the operator-home-v2 phase-3 local-skills index picks it
|
|
4
4
|
// up immediately (skill_list/skill_fetch unchanged). Nothing in the catalogue is ever injected on its
|
|
5
|
-
// own — that gating is the whole point (
|
|
5
|
+
// own — that gating is the whole point (shipped as "not activated by default").
|
|
6
6
|
// Node builtins stay behind lazy variable-specifier imports (purity contract, session-rewind idiom).
|
|
7
7
|
import { operatorPath } from "../config/home.js";
|
|
8
8
|
async function nodeImport(id) {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Native Chauffeur tool wrappers for the Operator engine. These wrap key Chauffeur MCP tools as
|
|
2
|
+
// first-class engine tools so any model dropped into Operator gets desktop automation and live-drive
|
|
3
|
+
// verification without needing to know about MCP at all. The hub is memoized per process.
|
|
4
|
+
import { buildChauffeurHub } from "./chauffeur.js";
|
|
5
|
+
let hubPromise = null;
|
|
6
|
+
function getHub() {
|
|
7
|
+
return (hubPromise ??= buildChauffeurHub());
|
|
8
|
+
}
|
|
9
|
+
export async function chauffeurReady() {
|
|
10
|
+
const hub = await getHub();
|
|
11
|
+
return hub !== null;
|
|
12
|
+
}
|
|
13
|
+
async function callChauffeur(tool, args) {
|
|
14
|
+
const hub = await getHub();
|
|
15
|
+
// Graceful degradation when the desktop driver is not available on this host.
|
|
16
|
+
// No install path in user prose: the install path is operator-runtime's responsibility
|
|
17
|
+
// (setup-services.sh), not something to ask the end-user to resolve by name or env var.
|
|
18
|
+
if (!hub)
|
|
19
|
+
return "error: desktop automation unavailable on this host";
|
|
20
|
+
try {
|
|
21
|
+
const result = await hub.call(`chauffeur:${tool}`, args);
|
|
22
|
+
if (typeof result === "string")
|
|
23
|
+
return result;
|
|
24
|
+
return JSON.stringify(result, null, 2);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return `error calling chauffeur:${tool}: ${e?.message ?? e}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function desktopScreenshot(args) {
|
|
31
|
+
return callChauffeur("get_desktop_state", {
|
|
32
|
+
include_screenshot: true,
|
|
33
|
+
...args,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export async function desktopClick(args) {
|
|
37
|
+
const description = args.description;
|
|
38
|
+
const x = args.x ?? args.coordinate_x;
|
|
39
|
+
const y = args.y ?? args.coordinate_y;
|
|
40
|
+
const element = args.element;
|
|
41
|
+
const clickArgs = {};
|
|
42
|
+
if (x != null && y != null) {
|
|
43
|
+
clickArgs.x = x;
|
|
44
|
+
clickArgs.y = y;
|
|
45
|
+
}
|
|
46
|
+
if (element)
|
|
47
|
+
clickArgs.element = element;
|
|
48
|
+
if (args.button)
|
|
49
|
+
clickArgs.button = args.button;
|
|
50
|
+
const result = await callChauffeur("click", clickArgs);
|
|
51
|
+
if (args.verify !== false) {
|
|
52
|
+
const verify = await callChauffeur("verify_state", { expect: typeof description === "string" ? description : "click landed" });
|
|
53
|
+
return result + "\n--- verify ---\n" + verify;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
export async function desktopRead(args) {
|
|
58
|
+
const pid = args.pid;
|
|
59
|
+
const windowId = args.window_id;
|
|
60
|
+
const readArgs = {};
|
|
61
|
+
if (pid != null)
|
|
62
|
+
readArgs.pid = pid;
|
|
63
|
+
if (windowId != null)
|
|
64
|
+
readArgs.window_id = windowId;
|
|
65
|
+
return callChauffeur("get_window_state", readArgs);
|
|
66
|
+
}
|
|
67
|
+
export async function appInteract(args) {
|
|
68
|
+
const app = args.app;
|
|
69
|
+
const action = args.action;
|
|
70
|
+
if (typeof app !== "string")
|
|
71
|
+
return "error: app name required";
|
|
72
|
+
if (typeof action !== "string")
|
|
73
|
+
return "error: action required (launch, find, click, type, read)";
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (action === "launch" || action === "find" || action === "click" || action === "type") {
|
|
76
|
+
const launch = await callChauffeur("launch_app", { name: app });
|
|
77
|
+
parts.push("=== LAUNCH ===\n" + launch);
|
|
78
|
+
}
|
|
79
|
+
if (action === "read" || action === "find") {
|
|
80
|
+
const state = await callChauffeur("get_window_state", { app_name: app });
|
|
81
|
+
parts.push("=== READ ===\n" + state);
|
|
82
|
+
}
|
|
83
|
+
if (action === "click" && args.element) {
|
|
84
|
+
const click = await callChauffeur("click", { element: args.element });
|
|
85
|
+
parts.push("=== CLICK ===\n" + click);
|
|
86
|
+
}
|
|
87
|
+
if (action === "type" && args.text) {
|
|
88
|
+
const type = await callChauffeur("type_text", { text: args.text });
|
|
89
|
+
parts.push("=== TYPE ===\n" + type);
|
|
90
|
+
}
|
|
91
|
+
return parts.join("\n\n") || `completed ${action} on ${app}`;
|
|
92
|
+
}
|
|
93
|
+
export async function capturePermalink(args) {
|
|
94
|
+
const parts = [];
|
|
95
|
+
if (args.app) {
|
|
96
|
+
const launch = await callChauffeur("launch_app", { name: args.app });
|
|
97
|
+
parts.push(launch);
|
|
98
|
+
}
|
|
99
|
+
if (args.element) {
|
|
100
|
+
const click = await callChauffeur("right_click", { element: args.element });
|
|
101
|
+
parts.push(click);
|
|
102
|
+
}
|
|
103
|
+
const clipboard = await callChauffeur("clipboard_read", {});
|
|
104
|
+
parts.push("clipboard: " + clipboard);
|
|
105
|
+
return parts.join("\n");
|
|
106
|
+
}
|
|
107
|
+
export async function liveDrive(args) {
|
|
108
|
+
const url = args.url;
|
|
109
|
+
if (typeof url !== "string")
|
|
110
|
+
return "error: url required";
|
|
111
|
+
const checks = args.checks;
|
|
112
|
+
if (!Array.isArray(checks) || !checks.length)
|
|
113
|
+
return "error: checks must be a non-empty array";
|
|
114
|
+
const parts = [];
|
|
115
|
+
// Prepare browser
|
|
116
|
+
parts.push("=== BROWSER PREPARE ===");
|
|
117
|
+
const prep = await callChauffeur("browser_prepare", {});
|
|
118
|
+
parts.push(prep);
|
|
119
|
+
parts.push("\n=== NAVIGATE ===");
|
|
120
|
+
const nav = await callChauffeur("browser_navigate", { url });
|
|
121
|
+
parts.push(nav);
|
|
122
|
+
let passed = 0;
|
|
123
|
+
for (const check of checks) {
|
|
124
|
+
const label = check.label || "check";
|
|
125
|
+
const action = check.action || "screenshot";
|
|
126
|
+
parts.push(`\n=== ${String(label).toUpperCase()} ===`);
|
|
127
|
+
let result;
|
|
128
|
+
switch (action) {
|
|
129
|
+
case "screenshot":
|
|
130
|
+
result = await callChauffeur("get_browser_state", { include_screenshot: true });
|
|
131
|
+
break;
|
|
132
|
+
case "find":
|
|
133
|
+
result = await callChauffeur("find", { text: check.selector || check.expect });
|
|
134
|
+
break;
|
|
135
|
+
case "click":
|
|
136
|
+
result = await callChauffeur("browser_click", { selector: check.selector });
|
|
137
|
+
break;
|
|
138
|
+
case "text":
|
|
139
|
+
result = await callChauffeur("get_page_text", {});
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
result = `unknown action: ${action}`;
|
|
143
|
+
}
|
|
144
|
+
parts.push(result);
|
|
145
|
+
if (check.expect && typeof result === "string" && !result.toLowerCase().includes(String(check.expect).toLowerCase())) {
|
|
146
|
+
parts.push(`=== ${String(label).toUpperCase()} FAILED (expected "${check.expect}" not found) ===`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
passed++;
|
|
150
|
+
parts.push(`=== ${String(label).toUpperCase()} PASSED ===`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
parts.push(`\n=== LIVE DRIVE COMPLETE: ${passed}/${checks.length} checks passed ===`);
|
|
154
|
+
return parts.join("\n");
|
|
155
|
+
}
|