@0perator/operator 0.1.313 → 0.1.322
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 +128 -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/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/services/preflight.js +54 -2
- package/dist/services/store-sync.js +111 -0
- package/dist/session-teardown.js +10 -1
- package/dist/session.js +43 -1
- 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/paths.js +154 -0
- package/dist/tools/registry.js +309 -18
- 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/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/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
package/dist/remote/host.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { frameKey as deriveFrameKey, pairingId as derivePairingId, encryptFrame, decryptFrame } from "./pairing.js";
|
|
2
|
+
import { redactSecrets } from "../engine/redact.js";
|
|
3
|
+
/** Redact known secret shapes in tool-approval args before they hit the relay / followers. */
|
|
4
|
+
export function redactApprovalArgs(args) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(redactSecrets(JSON.stringify(args ?? {})));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
2
12
|
const V = 1;
|
|
3
13
|
// RC v2 (engine contract 1.7.0, wire v:1). The host advertises these on hello so the relay/followers can
|
|
4
14
|
// version-gate; everything is additive, so an old relay simply ignores the extra fields.
|
|
@@ -400,7 +410,13 @@ export class RemoteHost {
|
|
|
400
410
|
this.state("transcript", { entry: e });
|
|
401
411
|
}
|
|
402
412
|
toolStep(step) { this.state("tool_step", { step: this.pickTool(step) }); }
|
|
403
|
-
pickTool(step) {
|
|
413
|
+
pickTool(step) {
|
|
414
|
+
const scrubbed = step.args
|
|
415
|
+
? { ...step, args: redactApprovalArgs(step.args) }
|
|
416
|
+
: step;
|
|
417
|
+
this.upsertTool(scrubbed);
|
|
418
|
+
return scrubbed;
|
|
419
|
+
}
|
|
404
420
|
setActivity(state, label) { this.activity = state; this.state("activity", { state, ...(label ? { label } : {}) }); }
|
|
405
421
|
setStatus(ctxPct, route, tokens) {
|
|
406
422
|
this.ctxPct = ctxPct;
|
|
@@ -409,7 +425,9 @@ export class RemoteHost {
|
|
|
409
425
|
this.tokens = tokens;
|
|
410
426
|
this.state("status", { ctxPct, route, ...(this.tokens != null ? { tokens: this.tokens } : {}) });
|
|
411
427
|
}
|
|
412
|
-
approvalRequest(id, tool, args) {
|
|
428
|
+
approvalRequest(id, tool, args) {
|
|
429
|
+
this.state("approval_request", { id, tool, args: redactApprovalArgs(args) });
|
|
430
|
+
}
|
|
413
431
|
/** Mirrors an ask_user clarification to followers — a DISTINCT frame type from approval_request
|
|
414
432
|
* (not folded into it), matching the web/mobile follower's contract. A local answer and a
|
|
415
433
|
* follower's ask_user_response race first-wins in the host (settleQuestion in cli.tsx); local
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Remote-control follower slash allowlist. Kept OUT of cli.tsx so tests can assert the security
|
|
2
|
+
// boundary without importing the Ink entry. Local `/help` / Composer menu use ui/slashCommands.ts
|
|
3
|
+
// (broader). A follower may ONLY drive names in this list — everything else is refused in onCommand.
|
|
4
|
+
//
|
|
5
|
+
// Deliberately EXCLUDES (in addition to exit/login/remote):
|
|
6
|
+
// mode — `/mode auto` flips host policy to bypass (ungated tool/MCP execution)
|
|
7
|
+
// mcp — `/mcp on` enables the full fleet MCP surface for the host session
|
|
8
|
+
// bg — spawns background agents with host privileges
|
|
9
|
+
// Those remain local-owner-only. A follower already has `prompt` (runs under current host mode);
|
|
10
|
+
// they must not escalate the host's permission/MCP posture.
|
|
11
|
+
//
|
|
12
|
+
// Preference: prefer `/pair` (QR e2e) over long-lived token RC when sharing a session — paired
|
|
13
|
+
// frames encrypt DATA payloads; token mode trusts the relay path. Escalation cmds stay host-local
|
|
14
|
+
// either way (this allowlist is the hard gate).
|
|
15
|
+
export const REMOTE_SAFE_COMMANDS = [
|
|
16
|
+
{ name: "help", description: "list available commands" },
|
|
17
|
+
{ name: "model", description: "pick a model: operator-1m · operator-128k · moa (mixture-of-agents)", args: "[id]" },
|
|
18
|
+
{ name: "route", description: "pin routing to an endpoint, or auto (by size)", args: "[endpoint|auto]" },
|
|
19
|
+
{ name: "endpoints", description: "show the Operator endpoint + live health" },
|
|
20
|
+
{ name: "services", description: "ensure/inspect the service lever (Operator+autopilot+searxng); stop searxng", args: "[stop]" },
|
|
21
|
+
{ name: "audit", description: "recent tool + control-plane events from the audit trail", args: "[n]" },
|
|
22
|
+
{ name: "dashboard", description: "launch the live swarm console" },
|
|
23
|
+
{ name: "plan", description: "toggle plan mode (read-only research + propose a plan)" },
|
|
24
|
+
{ name: "think", description: "toggle extended reasoning" },
|
|
25
|
+
{ name: "ultrathink", description: "toggle deep, exhaustive reasoning" },
|
|
26
|
+
{ name: "compact", description: "force-compact the conversation now" },
|
|
27
|
+
{ name: "remember", description: "store a note to recall in future sessions", args: "<note>" },
|
|
28
|
+
{ name: "memory", description: "show remembered notes", args: "[query]" },
|
|
29
|
+
{ name: "skill", description: "activate a skill as a system-prompt directive, or /skill off", args: "<name|off>" },
|
|
30
|
+
{ name: "whoami", description: "show signed-in identity" },
|
|
31
|
+
{ name: "agents", description: "detailed sub-agent status, or a per-agent deep view + controls", args: "[id] [msg <text>|stop]" },
|
|
32
|
+
{ name: "monitor", description: "toggle live event stream (tool decisions, turns, control)" },
|
|
33
|
+
{ name: "new", description: "start a fresh conversation" },
|
|
34
|
+
{ name: "clear", description: "clear the screen (keeps the conversation)" },
|
|
35
|
+
];
|
|
36
|
+
export const REMOTE_SAFE_COMMAND_NAMES = new Set(REMOTE_SAFE_COMMANDS.map((c) => c.name));
|
|
37
|
+
/** Escalation commands that stay owner-local (must never appear in REMOTE_SAFE_COMMAND_NAMES). */
|
|
38
|
+
export const REMOTE_ESCALATION_COMMANDS = ["mode", "mcp", "bg"];
|
|
@@ -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
|
@@ -303,6 +303,7 @@ export class Session {
|
|
|
303
303
|
convo = new Conversation();
|
|
304
304
|
inner; // was readonly — /model rebuilds it for a "single" profile switch
|
|
305
305
|
router; // rebuilt alongside inner (setModel)
|
|
306
|
+
chain; // the endpoint chain the shell built (cfg.router / useRouter) — what the default local model routes through
|
|
306
307
|
registry; // /model's choices — built-ins + any settings.models
|
|
307
308
|
moaConfig;
|
|
308
309
|
fastStartConfig;
|
|
@@ -422,6 +423,7 @@ export class Session {
|
|
|
422
423
|
this.localSchemas = toSchemas(reg);
|
|
423
424
|
this.inner = cfg.router ?? new AuroraRouter();
|
|
424
425
|
this.router = engineRouter(this.inner);
|
|
426
|
+
this.chain = cfg.router;
|
|
425
427
|
this.registry = modelRegistry(cfg.models);
|
|
426
428
|
this.isOwner = (cfg.eventActor?.tier ?? "admin") === "admin"; // set before the startup setModel so a persisted owner-only activeModel resolves for the owner
|
|
427
429
|
this.moaConfig = cfg.moa;
|
|
@@ -738,7 +740,14 @@ export class Session {
|
|
|
738
740
|
if (profile.kind === "orchestrated" && !this.moaConfig?.proposers?.length) {
|
|
739
741
|
return { ok: false, error: `MOA needs a "moa" block (proposers + aggregator) in settings.json — see MOA-DESIGN.md` };
|
|
740
742
|
}
|
|
741
|
-
if (profile.kind === "single" &&
|
|
743
|
+
if (profile.kind === "single" && profile.id === DEFAULT_MODEL_ID && this.chain) {
|
|
744
|
+
// The default local model IS the shell's endpoint chain (the gateway's published port + its failover
|
|
745
|
+
// legs). Restore it rather than rebuilding from the profile's static :8097 endpoint, which no longer
|
|
746
|
+
// answers on a gateway box — otherwise /model away-and-back lands on a dead port.
|
|
747
|
+
this.inner = this.chain;
|
|
748
|
+
this.router = engineRouter(this.inner);
|
|
749
|
+
}
|
|
750
|
+
else if (profile.kind === "single" && (profile.endpoint || profile.endpoints?.length)) {
|
|
742
751
|
// BYO connectors carry their vendor bearer (never the Operator token — see authHeaders scoping);
|
|
743
752
|
// selectModel already refused the id if the key is not connected, so resolution can't miss here.
|
|
744
753
|
const token = profile.byo ? getByoToken(profile.byo) : undefined;
|
|
@@ -764,6 +773,17 @@ export class Session {
|
|
|
764
773
|
this.modelId = profile.id;
|
|
765
774
|
return { ok: true };
|
|
766
775
|
}
|
|
776
|
+
/** Re-point this session at a freshly built endpoint chain. The interactive shell constructs the Session at
|
|
777
|
+
* first render, BEFORE the boot lever has resolved the gateway's dynamic port (server.json) — the chain must
|
|
778
|
+
* follow that resolution or health() and every turn probe the "" sentinel. Same swap setModel does. A
|
|
779
|
+
* non-default /model pick keeps owning routing; the chain then waits for `/model operator-1m`. */
|
|
780
|
+
useRouter(router) {
|
|
781
|
+
this.chain = router;
|
|
782
|
+
if (this.modelId !== DEFAULT_MODEL_ID)
|
|
783
|
+
return;
|
|
784
|
+
this.inner = router;
|
|
785
|
+
this.router = engineRouter(this.inner);
|
|
786
|
+
}
|
|
767
787
|
/** The full conversation, for persistence (auto-save / --resume). */
|
|
768
788
|
snapshot() {
|
|
769
789
|
return this.convo.all.map((m) => ({ ...m }));
|
|
@@ -949,6 +969,28 @@ export class Session {
|
|
|
949
969
|
await this.discoverMcp();
|
|
950
970
|
return this.mcpToolCount();
|
|
951
971
|
}
|
|
972
|
+
/** `/mcp reload`: rebuild the hub from disk (base + `$KODE_MCP_EXTRA` merge) and rediscover tools
|
|
973
|
+
* without restarting Operator — live-drive after `/mcp add powertools …`. */
|
|
974
|
+
async reloadMcp() {
|
|
975
|
+
this.wantMcp = true;
|
|
976
|
+
try {
|
|
977
|
+
if (this.hub) {
|
|
978
|
+
this.hub.shutdown();
|
|
979
|
+
this.hub = undefined;
|
|
980
|
+
}
|
|
981
|
+
this.hub = await McpHub.fromConfig();
|
|
982
|
+
if (!this.hub)
|
|
983
|
+
return 0;
|
|
984
|
+
this.hub.spillSink = spillToolOutput;
|
|
985
|
+
await this.hub.discover({ force: true });
|
|
986
|
+
this.tools = this.buildTools();
|
|
987
|
+
this.mcpSchemas = this.hub.schemas();
|
|
988
|
+
this.deferred = deferredEnabled(this.mcpSchemas.length, globalThis.process?.env) ? deferredState(this.mcpSchemas) : null;
|
|
989
|
+
this.tools = this.buildTools();
|
|
990
|
+
}
|
|
991
|
+
catch { /* stay local-only */ }
|
|
992
|
+
return this.mcpToolCount();
|
|
993
|
+
}
|
|
952
994
|
/** Local registry schemas plus any fleet MCP tool schemas discovered this session.
|
|
953
995
|
* Under HV3-04 deferral: locals + only the MCP tools described this session + the meta trio. */
|
|
954
996
|
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
|
+
}
|
package/dist/tools/chauffeur.js
CHANGED
|
@@ -62,14 +62,21 @@ async function resolveBinaryFresh() {
|
|
|
62
62
|
const override = process.env.KODE_CHAUFFEUR_BIN;
|
|
63
63
|
if (override)
|
|
64
64
|
return override;
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
// Variable-specifier dynamic imports — matches the mcp/config.ts + mcp/stdio.ts convention
|
|
66
|
+
// so esbuild cannot statically resolve "node:*" into a browser/JSCore graph. Required for
|
|
67
|
+
// test/neutral-graph.test.mts to pass when any chain (registry.ts → chauffeur-native.ts →
|
|
68
|
+
// chauffeur.ts) reaches this module from the shared engine bundle.
|
|
69
|
+
const nodeFs = "node:fs";
|
|
70
|
+
const nodeOs = "node:os";
|
|
71
|
+
const nodeChild = "node:child_process";
|
|
72
|
+
const { existsSync } = await import(nodeFs);
|
|
73
|
+
const { homedir } = await import(nodeOs);
|
|
67
74
|
const local = `${homedir()}/.local/bin/chauffeur-local`;
|
|
68
75
|
if (existsSync(local))
|
|
69
76
|
return local;
|
|
70
77
|
// Fall back to PATH resolution; if `chauffeur` isn't there either, give up (no dead hub, no failed spawn).
|
|
71
78
|
try {
|
|
72
|
-
const { execFile } = await import(
|
|
79
|
+
const { execFile } = await import(nodeChild);
|
|
73
80
|
const p = await new Promise((resolve, reject) => {
|
|
74
81
|
execFile("/bin/sh", ["-c", "command -v chauffeur"], { timeout: 3000, encoding: "utf8" }, (err, stdout) => (err ? reject(err) : resolve(stdout)));
|
|
75
82
|
});
|
|
@@ -95,7 +102,11 @@ export async function buildChauffeurServer() {
|
|
|
95
102
|
tools: [...CHAUFFEUR_TOOLS], // curated allowlist (the McpHub filters discovery to these)
|
|
96
103
|
};
|
|
97
104
|
}
|
|
105
|
+
let _hubPromise = null;
|
|
98
106
|
export async function buildChauffeurHub() {
|
|
107
|
+
return (_hubPromise ??= buildChauffeurHubFresh());
|
|
108
|
+
}
|
|
109
|
+
async function buildChauffeurHubFresh() {
|
|
99
110
|
const server = await buildChauffeurServer();
|
|
100
111
|
return server ? new McpHub([server]) : null;
|
|
101
112
|
}
|