@0perator/operator 0.1.360-next.2 → 0.2.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 +1 -1
- package/dist/autonomy/delegate-mode.js +159 -0
- package/dist/autonomy/delegate.js +1 -1
- package/dist/autonomy/session-factory.js +2 -0
- package/dist/background/index.js +26 -2
- package/dist/background/resume.js +125 -0
- package/dist/browser/engine.js +163 -0
- package/dist/browser/session.js +130 -140
- package/dist/cli.js +174 -12
- package/dist/config/settings.js +1 -1
- package/dist/engine/agent.js +1 -1
- package/dist/engine/aurora.js +4 -4
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/moa.js +2 -1
- package/dist/engine/selfheal.js +1 -1
- package/dist/engine/toolcalls.js +6 -6
- package/dist/index.js +3 -0
- package/dist/mcp/phone-server.js +30 -0
- package/dist/permissions/index.js +33 -17
- package/dist/permissions/signature.js +5 -0
- package/dist/phone-cli.js +65 -0
- package/dist/remote/host.js +31 -2
- package/dist/router/models.js +5 -15
- package/dist/selfimprove/index.js +1 -1
- package/dist/session.js +48 -7
- package/dist/tools/deferred.js +1 -0
- package/dist/tools/device/android.js +227 -0
- package/dist/tools/device/classify.js +127 -0
- package/dist/tools/device/deps.js +69 -0
- package/dist/tools/device/desktop.js +82 -0
- package/dist/tools/device/harness.js +262 -0
- package/dist/tools/device/iphone.js +206 -0
- package/dist/tools/device/mirroring-jxa.js +146 -0
- package/dist/tools/device/setup.js +90 -0
- package/dist/tools/device/tools.js +70 -0
- package/dist/tools/device/types.js +19 -0
- package/dist/tools/registry.js +12 -3
- package/dist/ui/App.js +4 -3
- package/dist/ui/ApprovalPrompt.js +10 -4
- package/dist/ui/BgPanel.js +2 -2
- package/dist/ui/UpdatePrompt.js +40 -0
- package/dist/ui/modelPicker.js +1 -1
- package/dist/ui/slashCommands.js +1 -0
- package/dist/update-check.js +134 -0
- package/dist/update.js +59 -15
- package/dist/util/slash.js +2 -2
- package/package.json +4 -2
- package/src/tools/device/NOTICE +37 -0
- package/dist/browser/cdp.js +0 -271
|
@@ -15,6 +15,10 @@ function summarize(name, args) {
|
|
|
15
15
|
case "computer_key": return `key: ${s(args.key)}${Array.isArray(args.modifiers) && args.modifiers.length ? ` +${args.modifiers.join("+")}` : ""}`;
|
|
16
16
|
case "computer_click": return `click at ${s(args.x)},${s(args.y)}`;
|
|
17
17
|
case "computer_screenshot": return "capture the screen to a file";
|
|
18
|
+
case "phone_tap": return `${args.device ? `${s(args.device)}: ` : ""}tap ${typeof args.text === "string" ? `"${s(args.text)}"` : `${s(args.x)},${s(args.y)}`}`;
|
|
19
|
+
case "phone_type": return `${args.device ? `${s(args.device)}: ` : ""}type ${String(args.text ?? "").length} characters${args.submit === true ? " and press enter" : ""}`;
|
|
20
|
+
case "phone_key": return `${args.device ? `${s(args.device)}: ` : ""}press ${s(args.key)}`;
|
|
21
|
+
case "phone_open_app": return `${args.device ? `${s(args.device)}: ` : ""}open ${s(args.name)}`;
|
|
18
22
|
case "shell_exec": return `$ ${s(args.command, 120)}`;
|
|
19
23
|
case "file_write": return `write ${s(args.path)}`;
|
|
20
24
|
case "file_edit": return `edit ${s(args.path)}`;
|
|
@@ -33,15 +37,17 @@ export function ApprovalPrompt({ approval, onDecide, suspended = false, waiting
|
|
|
33
37
|
onDecide(false, false); // Ctrl-C at the prompt = deny (bail out safely)
|
|
34
38
|
else if (c === "a" || key.return)
|
|
35
39
|
onDecide(true, false); // allow once
|
|
36
|
-
else if (c === "s")
|
|
37
|
-
onDecide(true, true); // allow always (this session)
|
|
40
|
+
else if (c === "s" && !approval.ctx?.once)
|
|
41
|
+
onDecide(true, true); // allow always (this session); never for a phone signature line
|
|
38
42
|
else if (c === "d" || key.escape)
|
|
39
43
|
onDecide(false, false); // deny
|
|
40
44
|
}, { isActive: !!approval && !suspended });
|
|
41
45
|
if (!approval)
|
|
42
46
|
return null;
|
|
43
47
|
const detail = summarize(approval.name, approval.args);
|
|
44
|
-
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [_jsxs(Text, { color: "yellow", bold: true, children: ["⚠ Operator wants to run ", _jsx(Text, { color: "magenta", children: approval.name })] }), detail ? _jsx(Text, { dimColor: true, children: " " + detail }) : null, suspended
|
|
48
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [_jsxs(Text, { color: "yellow", bold: true, children: ["⚠ Operator wants to run ", _jsx(Text, { color: "magenta", children: approval.name })] }), detail ? _jsx(Text, { dimColor: true, children: " " + detail }) : null, approval.ctx ? _jsx(Text, { color: "red", bold: true, children: ` ${approval.ctx.line} — a human signs this one, every time` }) : null, approval.ctx?.preview ? _jsx(Text, { children: " the screen it will act on: " + approval.ctx.preview }) : null, suspended
|
|
45
49
|
? _jsx(Text, { dimColor: true, children: " waiting · " + (waiting ?? "another prompt has the keyboard") })
|
|
46
|
-
:
|
|
50
|
+
: approval.ctx?.once
|
|
51
|
+
? _jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "[a]" }), " allow once ", _jsx(Text, { color: "red", children: "[d]" }), " deny ", _jsx(Text, { dimColor: true, children: "(Enter=allow \u00B7 Esc=deny)" })] })
|
|
52
|
+
: _jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "[a]" }), " allow once ", _jsx(Text, { color: "cyan", children: "[s]" }), " allow always ", _jsx(Text, { color: "red", children: "[d]" }), " deny ", _jsx(Text, { dimColor: true, children: "(Enter=allow \u00B7 Esc=deny)" })] })] }));
|
|
47
53
|
}
|
package/dist/ui/BgPanel.js
CHANGED
|
@@ -69,7 +69,7 @@ export function ledgerLine(a) {
|
|
|
69
69
|
a.commands ? `ran ${a.commands}` : "",
|
|
70
70
|
].filter(Boolean).join(" · ");
|
|
71
71
|
const verify = a.verified == null ? "" : a.verified ? "✓ verified" : `✗ unverified${a.verifyDetail ? `: ${cap(a.verifyDetail, 30)}` : ""}`;
|
|
72
|
-
return [a.title ?? "assistant", a.model, done || (a.status === "working" ? "nothing written yet" : ""), verify, a.malformed ? "⚠ malformed" : ""]
|
|
72
|
+
return [a.title ?? "assistant", a.resumed ? "resumed" : "", a.model, done || (a.status === "working" ? "nothing written yet" : ""), verify, a.malformed ? "⚠ malformed" : ""]
|
|
73
73
|
.filter(Boolean).join(" · ");
|
|
74
74
|
}
|
|
75
75
|
/** The third row (pure, testable): a stuck agent shows WHY and the exact commands to re-steer or stop it; a working one
|
|
@@ -167,7 +167,7 @@ export function mainLaneOf(m) {
|
|
|
167
167
|
/** One sub-agent as a lane: its round and mission, who holds the slot it waits for, why it stopped. Pure. */
|
|
168
168
|
export function agentLaneOf(a, now, ctx = {}) {
|
|
169
169
|
const elapsedMs = a.status === "working" ? (a.startedAt !== undefined ? now - a.startedAt : undefined) : a.durationMs;
|
|
170
|
-
const base = { key: a.id, name: a.name ?? a.id, role: a.title ?? "sub-agent"
|
|
170
|
+
const base = { key: a.id, name: a.name ?? a.id, role: `${a.title ?? "sub-agent"}${a.resumed ? " · resumed" : ""}`, elapsedMs, tokens: a.tokens };
|
|
171
171
|
const ledger = [a.written?.length ? `wrote ${a.written.length}` : "", a.reads ? `read ${a.reads}` : "", a.commands ? `ran ${a.commands}` : ""].filter(Boolean).join(" · ");
|
|
172
172
|
const join = (...xs) => xs.filter(Boolean).join(" · ");
|
|
173
173
|
if (a.status === "queued")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The update-available prompt (update-check.ts): shown before the first turn when the startup check found a newer build.
|
|
3
|
+
// It owns the keyboard while up (App.tsx promptUp suspends the composer). Enter takes the highlighted choice, a digit takes
|
|
4
|
+
// its row, Esc or ctrl+c skips this launch.
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { Box, Text, useInput } from "ink";
|
|
7
|
+
const CHOICES = ["update", "skip", "skip-version"];
|
|
8
|
+
export function choiceLabels(p) {
|
|
9
|
+
return [`Update now (runs \`${p.command}\`)`, "Skip", "Skip until next version"];
|
|
10
|
+
}
|
|
11
|
+
/** Pure keystroke reducer: the next highlight, or the choice made. */
|
|
12
|
+
export function updateKey(sel, input, key) {
|
|
13
|
+
if (key.escape || (key.ctrl && input.toLowerCase() === "c"))
|
|
14
|
+
return { choice: "skip" };
|
|
15
|
+
if (key.return)
|
|
16
|
+
return { choice: CHOICES[sel] };
|
|
17
|
+
if (key.upArrow)
|
|
18
|
+
return { sel: (sel + CHOICES.length - 1) % CHOICES.length };
|
|
19
|
+
if (key.downArrow)
|
|
20
|
+
return { sel: (sel + 1) % CHOICES.length };
|
|
21
|
+
const n = Number(input);
|
|
22
|
+
if (Number.isInteger(n) && n >= 1 && n <= CHOICES.length)
|
|
23
|
+
return { choice: CHOICES[n - 1] };
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
export function UpdatePrompt({ pending, suspended = false }) {
|
|
27
|
+
const [sel, setSel] = useState(0);
|
|
28
|
+
useInput((input, key) => {
|
|
29
|
+
if (!pending)
|
|
30
|
+
return;
|
|
31
|
+
const r = updateKey(sel, input, key);
|
|
32
|
+
if (r.choice)
|
|
33
|
+
pending.resolve(r.choice);
|
|
34
|
+
else if (r.sel !== undefined)
|
|
35
|
+
setSel(r.sel);
|
|
36
|
+
}, { isActive: !!pending && !suspended });
|
|
37
|
+
if (!pending)
|
|
38
|
+
return null;
|
|
39
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { bold: true, children: ["Update available · ", _jsx(Text, { dimColor: true, children: pending.current }), " → ", _jsx(Text, { color: "green", children: pending.version })] }), _jsx(Text, { dimColor: true, children: "Release notes: " + pending.notes }), _jsx(Text, { children: " " }), choiceLabels(pending).map((label, i) => (_jsxs(Text, { children: [i === sel ? _jsx(Text, { color: "cyan", bold: true, children: "› " }) : " ", _jsx(Text, { bold: i === sel, children: `${i + 1}. ${label}` })] }, label))), _jsx(Text, { children: " " }), _jsx(Text, { dimColor: true, children: suspended ? "waiting · another prompt has the keyboard" : "enter continue · esc skip" })] }));
|
|
40
|
+
}
|
package/dist/ui/modelPicker.js
CHANGED
|
@@ -15,7 +15,7 @@ export const CONNECT_ROW = "+ Connect a provider key (Anthropic, Google, Nous, O
|
|
|
15
15
|
* `:free` listing joins here. */
|
|
16
16
|
export const FREE_ROW_PRESETS = ["operator", "nous"];
|
|
17
17
|
/** The /model main rows, in this order (0.1.361); everything else sits behind MORE_ROW. */
|
|
18
|
-
export const MAIN_MODEL_IDS = ["operator-flash", "kimi-linear-48b", "
|
|
18
|
+
export const MAIN_MODEL_IDS = ["operator-flash", "kimi-linear-48b", "operator-dense"];
|
|
19
19
|
/** The last main row: an action that opens the rest (other fleet rows, connected providers, free rows, MOA, connect). */
|
|
20
20
|
export const MORE_ROW = "More models…";
|
|
21
21
|
// fleet → connected providers → free rows → MOA. The built-ins already list the local row before the gateway rows.
|
package/dist/ui/slashCommands.js
CHANGED
|
@@ -19,6 +19,7 @@ export const SLASH_COMMANDS = [
|
|
|
19
19
|
{ name: "mode", description: "set operating mode: autonomous · manual · plan · gated", args: "[auto|manual|plan|gated]" },
|
|
20
20
|
{ name: "think", description: "toggle extended reasoning (think before answering)" },
|
|
21
21
|
{ name: "ultrathink", description: "toggle deep, exhaustive reasoning for hard problems" },
|
|
22
|
+
{ name: "delegate", description: "any /model id as the MoA planner or the sub-agents; guard: no push, deploys or writes outside this repo", args: "[planner <model> [executor]|subagents <model>|guard on|off|push on|off|off]" },
|
|
22
23
|
{ name: "agents", description: "detailed sub-agent status: running/queued/done/errored + metrics" },
|
|
23
24
|
{ name: "bg", description: "spawn a background sub-agent, list, or stop one", args: "<task|stop id>" },
|
|
24
25
|
{ name: "jobs", description: "background shell jobs: list, or stop one (ctrl+b moves a running command here)", args: "[stop id]" },
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// The update-available prompt (ui/UpdatePrompt.tsx): an interactive start of a packaged install asks the public download
|
|
2
|
+
// URL (update.ts) which version each channel holds, in the background, and offers a newer one before the first turn.
|
|
3
|
+
// Never for a subcommand (`operator run`, acp, mcp, update…), a non-TTY, CI, a source checkout (it updates by git), or
|
|
4
|
+
// with settings.updates.check false / OPERATOR_NO_UPDATE_CHECK=1. The answer is cached ~20 h in the Operator home's
|
|
5
|
+
// state folder, with the version "skip until next version" chose. Every failure is silent: no offer.
|
|
6
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { operatorPath } from "./config/home.js";
|
|
9
|
+
import { channelOf, distBase, distTagsAsync, installedVersion, installPackaged, isOlder, isReleaseInstall, platformLabel, VERSION } from "./update.js";
|
|
10
|
+
export const CHECK_TTL_MS = 20 * 3600_000;
|
|
11
|
+
const FETCH_MS = 1500;
|
|
12
|
+
const REGISTRY_MS = 5000;
|
|
13
|
+
const NOTES = {
|
|
14
|
+
latest: "https://github.com/axetechnologies/kode/blob/main/CHANGELOG.md",
|
|
15
|
+
next: "https://github.com/axetechnologies/kode/blob/develop/CHANGELOG.md",
|
|
16
|
+
};
|
|
17
|
+
export const statePath = () => operatorPath("state", "update-check.json");
|
|
18
|
+
const on = (v) => !!v && v !== "0" && v.toLowerCase() !== "false";
|
|
19
|
+
/** Whether this launch checks at all. `argv` is process.argv: any subcommand (a bare word after the binary) is not an
|
|
20
|
+
* interactive start. */
|
|
21
|
+
export function checkEnabled(o) {
|
|
22
|
+
const sub = o.argv[2];
|
|
23
|
+
if (sub && !sub.startsWith("-"))
|
|
24
|
+
return false;
|
|
25
|
+
if (o.argv.includes("--version") || o.argv.includes("-V") || o.argv.includes("--help"))
|
|
26
|
+
return false;
|
|
27
|
+
if (!o.tty || on(o.env.CI) || on(o.env.OPERATOR_NO_UPDATE_CHECK) || on(o.env.KODE_NO_UPDATE_CHECK))
|
|
28
|
+
return false;
|
|
29
|
+
return o.settings.updates?.check !== false && !o.sourceCheckout;
|
|
30
|
+
}
|
|
31
|
+
/** What to offer: a newer build on the install's own channel; a next build also sees latest and gets the newer of the
|
|
32
|
+
* two (a release that has passed the prerelease it runs). Never an older or equal one (update.ts isOlder). */
|
|
33
|
+
export function pickOffer(current, found) {
|
|
34
|
+
const own = channelOf(current);
|
|
35
|
+
let best = null;
|
|
36
|
+
for (const channel of own === "next" ? ["next", "latest"] : ["latest"]) {
|
|
37
|
+
const v = found[channel];
|
|
38
|
+
if (!v || !isOlder(current, v) || (best && !isOlder(best.version, v)))
|
|
39
|
+
continue;
|
|
40
|
+
best = { version: v, channel };
|
|
41
|
+
}
|
|
42
|
+
return best;
|
|
43
|
+
}
|
|
44
|
+
/** The channel files at the public URL; when none answers (and not for an install.sh install, whose update never uses
|
|
45
|
+
* the registry) the registry's dist-tags of the same names. Unreachable everywhere = {}. */
|
|
46
|
+
export async function fetchVersions(own, o = {}) {
|
|
47
|
+
const want = own === "next" ? ["next", "latest"] : ["latest"];
|
|
48
|
+
const base = o.base ?? distBase();
|
|
49
|
+
const read = async (ch) => {
|
|
50
|
+
try {
|
|
51
|
+
const res = await fetch(`${base}/${ch}.txt`, { signal: AbortSignal.timeout(FETCH_MS) });
|
|
52
|
+
const v = res.ok ? (await res.text()).trim() : "";
|
|
53
|
+
return VERSION.test(v) ? v : undefined;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const got = {};
|
|
60
|
+
await Promise.all(want.map(async (ch) => { const v = await read(ch); if (v)
|
|
61
|
+
got[ch] = v; }));
|
|
62
|
+
if (Object.keys(got).length || o.registry === false)
|
|
63
|
+
return got;
|
|
64
|
+
const t = await (o.tags ?? distTagsAsync)(REGISTRY_MS);
|
|
65
|
+
if ("error" in t)
|
|
66
|
+
return got;
|
|
67
|
+
for (const ch of want)
|
|
68
|
+
if (VERSION.test(t.tags[ch] ?? ""))
|
|
69
|
+
got[ch] = t.tags[ch];
|
|
70
|
+
return got;
|
|
71
|
+
}
|
|
72
|
+
export function readState(path = statePath()) {
|
|
73
|
+
try {
|
|
74
|
+
const s = JSON.parse(readFileSync(path, "utf8"));
|
|
75
|
+
return s && typeof s === "object" && !Array.isArray(s) ? s : {};
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function writeState(state, path) {
|
|
82
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
83
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
84
|
+
writeFileSync(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 0o600 });
|
|
85
|
+
renameSync(tmp, path);
|
|
86
|
+
}
|
|
87
|
+
/** The offer for this launch, or null. A check younger than CHECK_TTL_MS is reused; a fresh one is written only when
|
|
88
|
+
* something answered, so a launch without network asks again next time. */
|
|
89
|
+
export async function checkForUpdate(current, o = {}) {
|
|
90
|
+
try {
|
|
91
|
+
const now = o.now ?? Date.now(), path = o.path ?? statePath();
|
|
92
|
+
const state = readState(path);
|
|
93
|
+
const fresh = typeof state.checkedAt === "number" && now >= state.checkedAt && now - state.checkedAt < CHECK_TTL_MS;
|
|
94
|
+
let found = { latest: state.latest, next: state.next };
|
|
95
|
+
if (!fresh) {
|
|
96
|
+
found = await (o.fetch ?? ((own) => fetchVersions(own, { registry: !isReleaseInstall() })))(channelOf(current));
|
|
97
|
+
if (found.latest || found.next)
|
|
98
|
+
writeState({ ...readState(path), checkedAt: now, latest: found.latest, next: found.next }, path);
|
|
99
|
+
}
|
|
100
|
+
const pick = pickOffer(current, found);
|
|
101
|
+
if (!pick || pick.version === state.skipVersion)
|
|
102
|
+
return null;
|
|
103
|
+
const command = pick.channel === channelOf(current) ? "operator update" : `operator update --${pick.channel}`;
|
|
104
|
+
return { current, ...pick, notes: NOTES[pick.channel], command };
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** "Skip until next version": this exact version is not offered again; a newer one is. */
|
|
111
|
+
export function skipVersion(version, path = statePath()) {
|
|
112
|
+
try {
|
|
113
|
+
writeState({ ...readState(path), skipVersion: version }, path);
|
|
114
|
+
}
|
|
115
|
+
catch { /* best-effort: it is asked again next launch */ }
|
|
116
|
+
}
|
|
117
|
+
/** "Update now", after the TUI has closed: the same packaged update `operator update` runs, then the version the next
|
|
118
|
+
* `operator` starts, read back. Success is said only when that read matches. */
|
|
119
|
+
export async function runOfferedUpdate(offer, o = {}) {
|
|
120
|
+
const say = o.write ?? ((s) => { process.stdout.write(s); });
|
|
121
|
+
say(`Updating Operator via \`${offer.command}\`...\n`);
|
|
122
|
+
say(`==> Updating Operator from ${offer.current} to ${offer.version}\n`);
|
|
123
|
+
say(`==> Detected platform: ${platformLabel()}\n`);
|
|
124
|
+
say(`==> Resolved version: ${offer.version}\n`);
|
|
125
|
+
const code = await installPackaged(offer.channel, true, o.pkgJson);
|
|
126
|
+
const now = installedVersion(o.pkgJson);
|
|
127
|
+
if (code === 0 && now === offer.version) {
|
|
128
|
+
say(`Operator ${now} installed successfully.\n`);
|
|
129
|
+
say("Update ran successfully. Please restart Operator.\n");
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
say(`Operator ${offer.version} was not installed: \`operator\` still starts v${now ?? "?"}. Run \`${offer.command}\` to try again.\n`);
|
|
133
|
+
return code || 1;
|
|
134
|
+
}
|
package/dist/update.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// `operator update` — self-update (bareword, like a CLI self-updater). Two install shapes:
|
|
2
2
|
// • packaged → the published package. update = the channel's build from the public download URL (the one
|
|
3
3
|
// install.sh uses), sha256-verified: `latest` (main's releases, the default and `--latest`) or `next`
|
|
4
|
-
// (`--next`:
|
|
4
|
+
// (`--next`: M.N.P-next.K prereleases from develop). When that URL can't be reached, the npm
|
|
5
5
|
// registry's dist-tag of the same name, as before.
|
|
6
6
|
// • source/dev → a git checkout linked via `npm link`; update = pull + rebuild.
|
|
7
7
|
// We detect the shape from where THIS module resolves: a checkout still has a .git above it;
|
|
8
8
|
// a global install lives under a node_modules tree with no repo around it.
|
|
9
|
-
import { spawnSync, execSync } from "node:child_process";
|
|
9
|
+
import { execFile, spawnSync, execSync } from "node:child_process";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { existsSync, mkdtempSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { homedir, tmpdir } from "node:os";
|
|
13
13
|
import { dirname, join, resolve } from "node:path";
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
15
|
const PKG = "@0perator/operator"; // published (private) scope/name — keep in sync with package.json
|
|
16
16
|
const DIST_BASE = "https://0perator.co/dl"; // latest.txt, next.txt, SHA256SUMS, operator-<version>.tgz (docs/INSTALL-CURL.md)
|
|
17
|
+
export const distBase = () => process.env.OPERATOR_DIST_BASE || DIST_BASE;
|
|
17
18
|
// An install made by install.sh: <root>/releases/<version>/node_modules/@0perator/operator, linked into a bin folder.
|
|
18
19
|
const RELEASE_PKG = /^(.*)\/releases\/[^/]+\/node_modules\/@0perator\/operator\/package\.json$/;
|
|
19
20
|
/** `--next` or `--latest`; `explicit` says a flag picked it. Both flags is a usage error. With no flag an install stays
|
|
@@ -27,12 +28,14 @@ export function updateChannel(args, current) {
|
|
|
27
28
|
return { channel: next ? "next" : "latest", explicit: true };
|
|
28
29
|
return { channel: current ? channelOf(current) : "latest", explicit: false };
|
|
29
30
|
}
|
|
30
|
-
// A next build is a
|
|
31
|
-
const channelOf = (version) => (/-next\.\d+$/.test(version) ? "next" : "latest");
|
|
32
|
-
/**
|
|
31
|
+
// A next build is a M.N.P-next.K prerelease; a release is a plain M.N.P.
|
|
32
|
+
export const channelOf = (version) => (/-next\.\d+$/.test(version) ? "next" : "latest");
|
|
33
|
+
/** A published version, release or next: what a channel file or dist-tag must hold. */
|
|
34
|
+
export const VERSION = /^(\d+)\.(\d+)\.(\d+)(?:-next\.(\d+))?$/;
|
|
35
|
+
/** Whether `target` is older than `current`. M.N.P-next.K precedes M.N.P. An unparsable version is never older. */
|
|
33
36
|
export function isOlder(target, current) {
|
|
34
37
|
const parse = (v) => {
|
|
35
|
-
const m =
|
|
38
|
+
const m = VERSION.exec(v);
|
|
36
39
|
return m ? [Number(m[1]), Number(m[2]), Number(m[3]), m[4] === undefined ? Infinity : Number(m[4])] : undefined;
|
|
37
40
|
};
|
|
38
41
|
const t = parse(target), c = parse(current);
|
|
@@ -61,6 +64,18 @@ function findRepoRoot() {
|
|
|
61
64
|
}
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
67
|
+
/** A source checkout updates by git, so it never offers or runs a packaged update. */
|
|
68
|
+
export const isSourceCheckout = () => findRepoRoot() !== null;
|
|
69
|
+
/** An install made by install.sh (a release folder). Its update never falls back to the registry. */
|
|
70
|
+
export const isReleaseInstall = (pkgJson = fileURLToPath(new URL("../package.json", import.meta.url))) => RELEASE_PKG.test(pkgJson);
|
|
71
|
+
/** The platform as install.sh names it ("macOS (Apple Silicon)"). */
|
|
72
|
+
export function platformLabel(platform = process.platform, arch = process.arch) {
|
|
73
|
+
if (platform === "darwin")
|
|
74
|
+
return `macOS (${arch === "arm64" ? "Apple Silicon" : arch === "x64" ? "Intel" : arch})`;
|
|
75
|
+
if (platform === "linux")
|
|
76
|
+
return `Linux (${arch === "x64" ? "x86_64" : arch})`;
|
|
77
|
+
return `${platform} (${arch})`;
|
|
78
|
+
}
|
|
64
79
|
function run(cmd, args, cwd) {
|
|
65
80
|
const r = spawnSync(cmd, args, { stdio: "inherit", cwd });
|
|
66
81
|
return r.status ?? 1;
|
|
@@ -68,21 +83,32 @@ function run(cmd, args, cwd) {
|
|
|
68
83
|
/** The registry's dist-tags for PKG (`{ latest: "0.1.352", next: "0.1.353-next.0" }`), or why they can't be read. */
|
|
69
84
|
function distTags() {
|
|
70
85
|
const r = spawnSync("npm", ["view", PKG, "dist-tags", "--json"], { encoding: "utf8" });
|
|
86
|
+
return readTags(r.status, r.stdout, r.stderr, r.signal);
|
|
87
|
+
}
|
|
88
|
+
/** distTags without blocking, for the startup check (update-check.ts), which must never hold the TUI. */
|
|
89
|
+
export function distTagsAsync(timeoutMs) {
|
|
90
|
+
return new Promise((done) => {
|
|
91
|
+
execFile("npm", ["view", PKG, "dist-tags", "--json"], { encoding: "utf8", timeout: timeoutMs }, (err, stdout, stderr) => {
|
|
92
|
+
done(readTags(err ? (typeof err.code === "number" ? err.code : 1) : 0, stdout, stderr, err?.signal ?? null));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function readTags(status, stdout, stderr, signal) {
|
|
71
97
|
let out;
|
|
72
98
|
try {
|
|
73
|
-
const parsed = JSON.parse(
|
|
99
|
+
const parsed = JSON.parse(stdout);
|
|
74
100
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
75
101
|
out = parsed;
|
|
76
102
|
}
|
|
77
103
|
catch { /* not JSON */ }
|
|
78
|
-
if (
|
|
104
|
+
if (status === 0 && out && !("error" in out))
|
|
79
105
|
return { tags: out };
|
|
80
106
|
// With --json npm puts its own error on stdout ({ error: { code, summary } }); stderr ends with the log file's path.
|
|
81
107
|
const e = out?.error;
|
|
82
108
|
if (e?.code || e?.summary)
|
|
83
109
|
return { error: [e.code, e.summary].filter(Boolean).join(" ") };
|
|
84
|
-
const lines = `${
|
|
85
|
-
return { error: lines.slice(0, 2).join(" · ") || `npm exited ${
|
|
110
|
+
const lines = `${stderr ?? ""}`.split("\n").map((l) => l.trim()).filter((l) => l && !/complete log of this run/i.test(l));
|
|
111
|
+
return { error: lines.slice(0, 2).join(" · ") || `npm exited ${status ?? signal}` };
|
|
86
112
|
}
|
|
87
113
|
function versionAt(pkgJson) {
|
|
88
114
|
try {
|
|
@@ -140,13 +166,13 @@ async function download(url, ms) {
|
|
|
140
166
|
* old ones (kept for rollback) and its bin link moved; any other install is replaced in place by `npm install -g`.
|
|
141
167
|
* Returns null, having installed nothing, when the URL can't be reached and the registry can stand in (not for an
|
|
142
168
|
* install.sh install, which exits 1 instead). */
|
|
143
|
-
export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), base =
|
|
169
|
+
export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), base = distBase(), refuseOlder = false) {
|
|
144
170
|
const current = versionAt(pkgJson) ?? "?";
|
|
145
171
|
const release = RELEASE_PKG.exec(pkgJson);
|
|
146
172
|
let target, tarball, sums;
|
|
147
173
|
try {
|
|
148
174
|
target = (await download(`${base}/${channel}.txt`, 15_000)).toString("utf8").trim();
|
|
149
|
-
if (
|
|
175
|
+
if (!VERSION.test(target))
|
|
150
176
|
throw new Error(`${base}/${channel}.txt is not a version`);
|
|
151
177
|
if (target === current) {
|
|
152
178
|
process.stderr.write(`operator update: already on v${current} (${channel}).\n`);
|
|
@@ -200,6 +226,25 @@ export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("
|
|
|
200
226
|
process.stderr.write(`operator update: done — now v${now} (${channel}).\n`);
|
|
201
227
|
return 0;
|
|
202
228
|
}
|
|
229
|
+
/** The packaged update `operator update` runs: the public download URL, else (not for an install.sh install) the
|
|
230
|
+
* registry. */
|
|
231
|
+
export async function installPackaged(channel, refuseOlder, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url))) {
|
|
232
|
+
return (await installFromDist(channel, pkgJson, undefined, refuseOlder)) ?? installChannel(channel, pkgJson, refuseOlder);
|
|
233
|
+
}
|
|
234
|
+
/** The version the next `operator` starts, read back after an update: an install.sh install follows its bin link into
|
|
235
|
+
* the release folder it now points at; any other install is this package, which npm replaced in place. */
|
|
236
|
+
export function installedVersion(pkgJson = fileURLToPath(new URL("../package.json", import.meta.url))) {
|
|
237
|
+
if (!RELEASE_PKG.test(pkgJson))
|
|
238
|
+
return versionAt(pkgJson);
|
|
239
|
+
try {
|
|
240
|
+
const link = join(process.env.OPERATOR_BIN_DIR || join(homedir(), ".local", "bin"), "operator");
|
|
241
|
+
const bin = resolve(dirname(link), readlinkSync(link)); // <release>/node_modules/.bin/operator, as installFromDist links it
|
|
242
|
+
return versionAt(join(dirname(dirname(bin)), "@0perator", "operator", "package.json"));
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
203
248
|
export async function runUpdate(args = [], pkgJson = fileURLToPath(new URL("../package.json", import.meta.url))) {
|
|
204
249
|
const pick = updateChannel(args, versionAt(pkgJson));
|
|
205
250
|
if ("error" in pick) {
|
|
@@ -259,6 +304,5 @@ export async function runUpdate(args = [], pkgJson = fileURLToPath(new URL("../p
|
|
|
259
304
|
}
|
|
260
305
|
return code;
|
|
261
306
|
}
|
|
262
|
-
|
|
263
|
-
return (await installFromDist(pick.channel, undefined, undefined, refuseOlder)) ?? installChannel(pick.channel, undefined, refuseOlder);
|
|
307
|
+
return installPackaged(pick.channel, !pick.explicit);
|
|
264
308
|
}
|
package/dist/util/slash.js
CHANGED
|
@@ -6,7 +6,7 @@ const KNOWN = new Set([
|
|
|
6
6
|
"think", "ultrathink", "compact", "remember", "memory", "mcp", "whoami", "agents", "jobs", "monitor",
|
|
7
7
|
"bg", "new", "clear", "exit", "quit", "stats", "login", "logout", "remote", "remotecontrol", "rc",
|
|
8
8
|
"artifacts", "sessions", "skills", "skill", "allow", "caffeinate", "caffeine", "deep-research", "deepresearch",
|
|
9
|
-
"research", "pair",
|
|
9
|
+
"research", "pair", "delegate",
|
|
10
10
|
]);
|
|
11
11
|
export const KNOWN_COMMANDS = KNOWN;
|
|
12
12
|
export function isSlashCommand(text) {
|
|
@@ -24,7 +24,7 @@ export const MIDTURN = {
|
|
|
24
24
|
help: "now", agents: "now", jobs: "now", stats: "now", endpoints: "now", audit: "now", memory: "now", skills: "now",
|
|
25
25
|
skill: "now", whoami: "now", monitor: "now", remember: "now", caffeinate: "now", caffeine: "now", bg: "now", dashboard: "now",
|
|
26
26
|
remote: "now", remotecontrol: "now", rc: "now", pair: "now",
|
|
27
|
-
think: "next", ultrathink: "next", context: "next", ctx: "next", mode: "next", plan: "next", allow: "next",
|
|
27
|
+
think: "next", ultrathink: "next", context: "next", ctx: "next", mode: "next", plan: "next", allow: "next", delegate: "next",
|
|
28
28
|
model: "after", new: "after", compact: "after", clear: "after", route: "after", mcp: "after", login: "after", logout: "after",
|
|
29
29
|
sessions: "after", artifacts: "after", services: "after",
|
|
30
30
|
"deep-research": "after", deepresearch: "after", research: "after", exit: "after", quit: "after",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"operator": "dist/cli.js",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"dashboard/index.html",
|
|
15
15
|
"dashboard/server.mjs",
|
|
16
16
|
"mcp/*.mjs",
|
|
17
|
-
"mcp/ocr-macos.swift"
|
|
17
|
+
"mcp/ocr-macos.swift",
|
|
18
|
+
"src/tools/device/NOTICE"
|
|
18
19
|
],
|
|
19
20
|
"engines": {
|
|
20
21
|
"node": ">=20"
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"ink": "^5.0.1",
|
|
38
39
|
"marked": "^12.0.2",
|
|
39
40
|
"pdfkit": "^0.15.2",
|
|
41
|
+
"playwright-core": "1.65.0",
|
|
40
42
|
"qrcode": "^1.5.4",
|
|
41
43
|
"react": "^18.3.1",
|
|
42
44
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Operator device harness (src/tools/device/)
|
|
2
|
+
|
|
3
|
+
The iPhone (iPhone Mirroring) and Android (adb) backends in this directory are a
|
|
4
|
+
TypeScript port of phone-harness, https://github.com/phone-harness/phone-harness
|
|
5
|
+
(commit f5096606b10e, read on 2026-11-25). Ported: the adb command set and its device
|
|
6
|
+
states (android.py), the uiautomator tree parse, the lock gate, the iPhone
|
|
7
|
+
Mirroring window discovery by bundle id, window capture with region fallback,
|
|
8
|
+
CGEvent taps / drags / scroll-wheel swipes, keys held as real modifier keys,
|
|
9
|
+
paste-based typing, Spotlight app launch and the Cmd+1/2/3 shortcuts
|
|
10
|
+
(mirror.py, ios.py), and Vision OCR with the bottom-left box flip (ocr.py).
|
|
11
|
+
Rewritten for Operator: argv-only process calls with bounded timeouts, one
|
|
12
|
+
backend interface shared with the macOS desktop (Chauffeur), Operator's
|
|
13
|
+
permission gate, signature lines and audit trail.
|
|
14
|
+
|
|
15
|
+
phone-harness is used under the MIT License:
|
|
16
|
+
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2026 shawn pana
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|