@0perator/operator 0.2.1 → 0.2.2-next.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.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/byo.js +1 -1
  3. package/dist/auth/commands.js +8 -2
  4. package/dist/autonomy/agent-cli.js +1 -1
  5. package/dist/autonomy/headless.js +30 -6
  6. package/dist/autonomy/pr-isolation.js +92 -0
  7. package/dist/autonomy/pr-preflight.js +474 -0
  8. package/dist/autonomy/session-factory.js +2 -0
  9. package/dist/browser/capture.js +505 -0
  10. package/dist/browser/engine.js +4 -3
  11. package/dist/browser/page-capture.js +167 -0
  12. package/dist/browser/png.js +116 -0
  13. package/dist/browser/visual-compare.js +229 -0
  14. package/dist/bus/beam-drop.js +55 -0
  15. package/dist/bus/inbox.js +7 -1
  16. package/dist/cli.js +130 -26
  17. package/dist/config/managed.js +40 -1
  18. package/dist/config/persona.js +86 -41
  19. package/dist/config/product-hosts.js +2 -0
  20. package/dist/config/settings.js +30 -13
  21. package/dist/config/skills-index.js +37 -14
  22. package/dist/engine/agent.js +1 -1
  23. package/dist/engine/aurora.js +18 -9
  24. package/dist/engine/continuation.js +36 -0
  25. package/dist/engine/identity.js +42 -0
  26. package/dist/engine/moa.js +7 -0
  27. package/dist/engine/net-error.js +15 -0
  28. package/dist/engine/rolling-summary.js +142 -93
  29. package/dist/engine/waterfall.js +33 -0
  30. package/dist/gateway-cli.js +10 -1
  31. package/dist/memory/session-index.js +3 -3
  32. package/dist/permissions/index.js +2 -1
  33. package/dist/permissions/policy.js +9 -2
  34. package/dist/permissions/tier.js +9 -1
  35. package/dist/products/craft.js +90 -1
  36. package/dist/products/temple.js +20 -1
  37. package/dist/products/voice.js +112 -0
  38. package/dist/router/free-models.js +5 -9
  39. package/dist/router/models.js +58 -14
  40. package/dist/router/provider-models.js +78 -0
  41. package/dist/router/router.js +15 -3
  42. package/dist/selfimprove/lessons.js +23 -0
  43. package/dist/session.js +192 -87
  44. package/dist/skills/catalogue.js +5 -2
  45. package/dist/skills/finder.js +4 -4
  46. package/dist/skills/install-guard.js +1 -1
  47. package/dist/tools/beam.js +246 -0
  48. package/dist/tools/craft.js +23 -0
  49. package/dist/tools/deferred.js +7 -3
  50. package/dist/tools/doc-text.js +1 -1
  51. package/dist/tools/registry.js +55 -9
  52. package/dist/tools/sandbox.js +6 -6
  53. package/dist/ui/App.js +3 -3
  54. package/dist/ui/ApprovalPrompt.js +1 -1
  55. package/dist/ui/Composer.js +44 -2
  56. package/dist/ui/StatusRule.js +2 -1
  57. package/dist/ui/Transcript.js +5 -0
  58. package/dist/ui/modelPicker.js +10 -6
  59. package/dist/ui/phase.js +4 -2
  60. package/dist/ui/slashCommands.js +1 -0
  61. package/dist/ui/voice.js +185 -0
  62. package/dist/update.js +1 -2
  63. package/dist/util/audio-io.js +82 -0
  64. package/dist/util/slash.js +2 -2
  65. package/dist/vision/pairs.js +239 -0
  66. package/package.json +1 -1
package/README.md CHANGED
@@ -74,7 +74,7 @@ operator --resume # reload the last conversation in this dir
74
74
  Dev: `npm install && npm run dev`, or `scripts/operator-dev.sh` installed as `operator-dev` for unreleased `develop`.
75
75
 
76
76
  ### Headless — `operator run`
77
- One task, no terminal UI, for SSH, CI, cron and other agents (the shape of `codex exec` and `hermes -z`):
77
+ One task, no terminal UI, for SSH, CI, cron and other agents (the shape of `codex exec`):
78
78
  ```
79
79
  operator run "fix the failing test" # progress on stderr, the answer on stdout
80
80
  echo "summarise CHANGELOG.md" | operator run - # task from stdin (also when stdin is a pipe and no task is given)
package/dist/auth/byo.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // the gateway). Distinct keychain SERVICE from the operator token ("axe-operator") so a vendor key can
5
5
  // never be read/mistaken for the operator bearer by any client — the separation IS the leak guard.
6
6
  // Env override per account: KODE_BYO_<ACCOUNT> (uppercase, non-alnum → "_") for CI/headless. The vendor's own
7
- // variable (ByoPreset.envAlias: ANTHROPIC_API_KEY, NOUS_API_KEY, …) is the LAST resort, after the stored key, and
7
+ // variable (ByoPreset.envAlias: ANTHROPIC_API_KEY, OPENAI_API_KEY, …) is the LAST resort, after the stored key, and
8
8
  // only for a request going to that preset's own host — an ambient org key must never shadow a key the owner pasted,
9
9
  // nor ride to a proxy row that shares the account name. KODE_NO_KEYCHAIN=1 forces the 0600 JSON file (same
10
10
  // convention as auth/store.ts).
@@ -22,7 +22,7 @@ import { listByoAccounts, hasByoToken, deleteByoToken, setByoTokenInteractive }
22
22
  import { ghInstalled, ghAuthStatus, ghLogin, ghSwitch } from "./gh-account.js";
23
23
  import { auditControl } from "../telemetry/lifecycle.js";
24
24
  import { loadSettings, saveSettings } from "../config/settings.js";
25
- import { BYO_PRESETS } from "../router/models.js";
25
+ import { BYO_PRESETS, replacedProvider } from "../router/models.js";
26
26
  // Credential-lifecycle audit (inert unless the seat is audited — see telemetry/lifecycle.ts). Module-level
27
27
  // because every login path ends in the same few exits; runAuth sets it once from the CLI's settings.
28
28
  let auditCfg;
@@ -207,7 +207,13 @@ async function byoModel(rest) {
207
207
  return 0;
208
208
  }
209
209
  const presetName = flagValue(rest, "--preset");
210
- const preset = presetName ? BYO_PRESETS[presetName] : undefined;
210
+ const old = replacedProvider(presetName);
211
+ const preset = presetName ? BYO_PRESETS[old?.by ?? presetName] : undefined;
212
+ if (preset?.signIn) {
213
+ // A sign-in provider has no key to paste and no row to register: the Operator sign-in is its key, /model lists its rows.
214
+ console.log(`${old ? `${old.label} is no longer offered — ` : ""}${preset.label} uses your Operator sign-in (operator auth login); /model lists its models`);
215
+ return 0;
216
+ }
211
217
  if (presetName && !preset) {
212
218
  console.error(`unknown preset "${presetName}" — choices: ${Object.keys(BYO_PRESETS).join(", ")}`);
213
219
  return 1;
@@ -146,7 +146,7 @@ async function defaultResolveBin(bin) {
146
146
  }
147
147
  /** The SYNCHRONOUS bin resolver powering the tool description at module load (no I/O awaited there, same
148
148
  * idiom as registry.ownedMcpNote): uses process.getBuiltinModule so it's a no-op in the neutral bundle. */
149
- function resolveBinSync(bin) {
149
+ export function resolveBinSync(bin) {
150
150
  try {
151
151
  const proc = globalThis.process;
152
152
  const fs = proc?.getBuiltinModule?.("node:fs");
@@ -9,6 +9,10 @@ import { makeReporter } from "./reporter.js";
9
9
  import { recordLiveProgress, roundProgressed, settleLiveProgress, touchedPaths } from "../memory/live-progress.js";
10
10
  import { getAgentTasks } from "../tools/registry.js";
11
11
  import { engineEnded } from "../engine/continuation.js";
12
+ import { pollBus, selfAgent } from "../bus/inbox.js";
13
+ import { beamDrop, beamDropHint, beamDropLine } from "../bus/beam-drop.js";
14
+ import { shownModel, shownModelLabel } from "../engine/identity.js";
15
+ import { shownFailure } from "../engine/net-error.js";
12
16
  const newJournal = (prompt) => ({ session: `headless-${process.pid}`, prompt, touched: [], written: false });
13
17
  function settleJournal(j, how) {
14
18
  if (j.written)
@@ -19,11 +23,11 @@ function settleJournal(j, how) {
19
23
  function handlersFor(reporter, json, prompt = "", onDelta, journal = newJournal(prompt)) {
20
24
  const { touched, session } = journal;
21
25
  return {
22
- onRoute: (label, ctxPct) => reporter.event("route", { route: label, ctxPct }),
23
- onServed: (s) => reporter.event("fallback", { from: s.fallbackFrom, servedBy: s.backend ?? null }), // the selected model was down; another box answered
26
+ onRoute: (label, ctxPct) => reporter.event("route", { route: shownModelLabel(label), ctxPct }),
27
+ onServed: (s) => reporter.event("fallback", { from: shownModel(s.fallbackFrom, "selected"), servedBy: s.backend ? shownModel(s.backend, "backup") : null }), // the selected model was down; another box answered
24
28
  onAutoContinue: (round) => reporter.event("auto_continue", { round }),
25
29
  onSelfHeal: (kind, attempt) => reporter.event("self_heal", { kind, attempt }),
26
- onFallback: (e) => reporter.event("model_fallback", { from: e.from, servedBy: e.to, reason: e.reason, note: e.line }), // every leg of the model failed; its fallback answered
30
+ onFallback: (e) => reporter.event("model_fallback", { from: shownModel(e.from, "primary"), servedBy: shownModel(e.to, "backup"), reason: e.reason, note: e.line }), // every leg of the model failed; its fallback answered
27
31
  onLoopCompaction: (e) => reporter.event("loop_compaction", { ...e }),
28
32
  onLoopRecovery: (e) => reporter.event("loop_recovery", { attempt: e.attempt, max: e.max, rounds: e.rounds, replaced: e.replaced, calls: e.repeated.length }),
29
33
  onToolBatch: (events, durationMs) => {
@@ -42,6 +46,24 @@ function handlersFor(reporter, json, prompt = "", onDelta, journal = newJournal(
42
46
  onDelta: json ? undefined : onDelta ?? ((chunk) => process.stdout.write(chunk)),
43
47
  };
44
48
  }
49
+ /** One `beam_drop` event per beam drop addressed to this run's agent that arrives while it runs. It peeks, so each
50
+ * message stays in the inbox for the TUI, `switch` and `beam inbox`. Returns the stop function. */
51
+ export function watchBeamDrops(reporter, agent = selfAgent(), everyMs = 3000) {
52
+ const since = Date.now();
53
+ const seen = new Set();
54
+ const tick = () => {
55
+ for (const m of pollBus(agent, { peek: true })) {
56
+ const d = beamDrop(m);
57
+ if (!d || seen.has(d.id) || Date.parse(m.ts) < since)
58
+ continue;
59
+ seen.add(d.id);
60
+ reporter.event("beam_drop", { id: d.id, from: d.from, name: d.name, size: d.size, line: beamDropLine(d), hint: beamDropHint(d) });
61
+ }
62
+ };
63
+ const timer = setInterval(tick, everyMs);
64
+ timer.unref?.();
65
+ return () => clearInterval(timer);
66
+ }
45
67
  /**
46
68
  * Run `prompt` headless. Returns a process exit code: 0 an answer, 1 an error or an engine stop (the json result names
47
69
  * it in `stopKind`), 130 interrupted. Wires SIGINT
@@ -89,7 +111,8 @@ export async function runHeadless(settings, prompt, opts = {}) {
89
111
  catch { /* idle */ } };
90
112
  process.on("SIGINT", onSig);
91
113
  process.on("SIGTERM", onSig);
92
- reporter.event("start", { mode: opts.loop ? "loop" : "headless", model: settings.endpoints.aurora.model });
114
+ reporter.event("start", { mode: opts.loop ? "loop" : "headless", model: shownModelLabel(settings.endpoints.aurora.model) });
115
+ const stopBeamWatch = watchBeamDrops(reporter);
93
116
  try {
94
117
  if (opts.loop) {
95
118
  const res = await runLoop(session, prompt, {
@@ -123,11 +146,12 @@ export async function runHeadless(settings, prompt, opts = {}) {
123
146
  }
124
147
  catch (e) {
125
148
  const message = e instanceof Error ? e.message : String(e);
126
- reporter.event("error", { message });
127
- result = { ...result, error: message };
149
+ reporter.event("error", { message: shownFailure(message) });
150
+ result = { ...result, error: shownFailure(message) };
128
151
  return finish(1);
129
152
  }
130
153
  finally {
154
+ stopBeamWatch();
131
155
  process.off("SIGINT", onSig);
132
156
  process.off("SIGTERM", onSig);
133
157
  session.shutdown();
@@ -0,0 +1,92 @@
1
+ // What isolation this box can confirm for the PR preflight (pr-preflight.ts). A backend counts only when a real run
2
+ // proves it: the same profile the held command would get runs a trivial command, and a write outside its roots is
3
+ // refused. Anything short of that is "not confirmed" and the preflight fails closed. VM and container CLIs (Apple's
4
+ // `container`, `tart`, /dev/kvm, a docker daemon) are reported to the owner but never driven or installed.
5
+ // node-only, loaded lazily (variable specifier) like tools/sandbox.ts.
6
+ import { seatbeltProfile, bwrapArgs } from "../tools/sandbox.js";
7
+ const nodeImport = (m) => import(/* @vite-ignore */ m);
8
+ /** True when `bin` is an executable file on PATH (no spawn: the VM CLIs are only reported, never run). */
9
+ async function onPath(bin) {
10
+ const { access, constants } = await nodeImport("node:fs/promises");
11
+ const { join, delimiter } = await nodeImport("node:path");
12
+ for (const dir of (process.env.PATH ?? "").split(delimiter)) {
13
+ if (!dir)
14
+ continue;
15
+ try {
16
+ await access(join(dir, bin), constants.X_OK);
17
+ return true;
18
+ }
19
+ catch { /* not here */ }
20
+ }
21
+ return false;
22
+ }
23
+ async function defaultRun(file, args) {
24
+ const { execFile } = await nodeImport("node:child_process");
25
+ // bins: sandbox-exec bwrap docker
26
+ return new Promise((res) => execFile(file, args, { timeout: 5000 }, (e, stdout, stderr) => res({ ok: !e, out: `${stdout ?? ""}${stderr ?? ""}`.trim() })));
27
+ }
28
+ const CHECK = 'echo ok > "$1/probe" && ! (echo x > "$2") 2>/dev/null && test ! -e "$2"';
29
+ export async function probeIsolation(platform = process.platform, run = defaultRun) {
30
+ const fs = await nodeImport("node:fs");
31
+ const os = await nodeImport("node:os");
32
+ const path = await nodeImport("node:path");
33
+ const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "op-pr-probe-"))); // seatbelt matches real paths (/private/var, not /var)
34
+ const outside = path.join(os.homedir(), `.op-pr-probe-${process.pid}`);
35
+ const out = { reportOnly: [], detail: [] };
36
+ const scope = { writeRoots: [root], network: false };
37
+ try {
38
+ if (platform === "darwin") {
39
+ const r = await run("/usr/bin/sandbox-exec", ["-p", seatbeltProfile("strict", scope), "/bin/bash", "-c", CHECK, "_", root, outside]);
40
+ if (r.ok && fs.existsSync(path.join(root, "probe"))) {
41
+ out.backend = "seatbelt";
42
+ out.label = "macOS seatbelt (sandbox-exec)";
43
+ out.detail.push("seatbelt: confirmed");
44
+ }
45
+ else
46
+ out.detail.push(`seatbelt: not confirmed${r.out ? ` (${r.out.slice(0, 120)})` : ""}`);
47
+ for (const bin of ["container", "tart"])
48
+ if (await onPath(bin))
49
+ out.reportOnly.push(bin === "container" ? "Apple container (VM)" : "tart (VM)");
50
+ }
51
+ else if (platform === "linux") {
52
+ const r = await run("bwrap", [...bwrapArgs("strict", scope), "/bin/sh", "-c", CHECK, "_", root, outside]);
53
+ if (r.ok && fs.existsSync(path.join(root, "probe"))) {
54
+ out.backend = "bwrap";
55
+ out.label = "bubblewrap (bwrap)";
56
+ out.detail.push("bwrap: confirmed");
57
+ }
58
+ else
59
+ out.detail.push(`bwrap: not confirmed${r.out ? ` (${r.out.slice(0, 120)})` : ""}`);
60
+ try {
61
+ fs.accessSync("/dev/kvm", fs.constants.R_OK | fs.constants.W_OK);
62
+ out.reportOnly.push("/dev/kvm (VM capable)");
63
+ }
64
+ catch { /* no KVM for this user */ }
65
+ if ((await run("docker", ["info", "--format", "{{.ServerVersion}}"])).ok)
66
+ out.reportOnly.push("docker");
67
+ }
68
+ else {
69
+ out.detail.push(`no isolation backend on ${platform}`);
70
+ }
71
+ }
72
+ finally {
73
+ try {
74
+ fs.rmSync(root, { recursive: true, force: true });
75
+ }
76
+ catch { /* temp dir */ }
77
+ try {
78
+ if (fs.existsSync(outside)) {
79
+ fs.rmSync(outside, { force: true });
80
+ out.backend = undefined;
81
+ out.detail.push("a write outside the roots landed: not confined");
82
+ }
83
+ }
84
+ catch { /* nothing there */ }
85
+ }
86
+ return out;
87
+ }
88
+ /** `git <args>` in `cwd` for the preflight's bookkeeping: trimmed stdout, or null on any failure. */
89
+ export async function prGit(cwd, args) {
90
+ const { execFile } = await nodeImport("node:child_process");
91
+ return new Promise((res) => execFile("git", ["-C", cwd, ...args], { timeout: 5000 }, (e, stdout) => res(e ? null : String(stdout).trim() || null)));
92
+ }