@0perator/operator 0.1.172 → 0.1.235
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/CHANGELOG.md +858 -0
- package/README.md +4 -4
- package/dist/acp/agent.js +42 -3
- package/dist/acp/config-options.js +34 -0
- package/dist/acp/run.js +83 -2
- package/dist/auth/byo.js +118 -0
- package/dist/auth/commands.js +34 -1
- package/dist/autonomy/dream.js +1 -1
- package/dist/autonomy/index.js +16 -2
- package/dist/autonomy/media-robot.js +138 -0
- package/dist/autonomy/profile.js +77 -0
- package/dist/autonomy/session-factory.js +13 -9
- package/dist/background/index.js +8 -1
- package/dist/cli.js +132 -95
- package/dist/compose/client.js +56 -0
- package/dist/config/persona.js +186 -14
- package/dist/config/settings.js +49 -16
- package/dist/consolidation/scheduler.js +7 -4
- package/dist/consolidation/sleep.js +15 -1
- package/dist/engine/agent.js +152 -9
- package/dist/engine/aurora.js +73 -14
- package/dist/engine/compaction.js +129 -2
- package/dist/engine/computer-event.js +139 -0
- package/dist/engine/continuation.js +55 -0
- package/dist/engine/contract.js +3 -1
- package/dist/engine/grandmaster.js +13 -3
- package/dist/engine/messages.js +2 -2
- package/dist/engine/redact.js +25 -0
- package/dist/engine/rolling-summary.js +22 -7
- package/dist/engine/router-adapter.js +2 -0
- package/dist/engine/unrestricted.js +51 -0
- package/dist/engine/verify-gate.js +6 -0
- package/dist/index.browser.js +4 -0
- package/dist/index.js +4 -0
- package/dist/memory/index.js +0 -0
- package/dist/permissions/audit.js +4 -1
- package/dist/permissions/policy.js +4 -3
- package/dist/permissions/tier.js +31 -14
- package/dist/remote/host.js +9 -2
- package/dist/router/models.js +43 -2
- package/dist/session.js +113 -36
- package/dist/telemetry/events.js +8 -3
- package/dist/tools/computer.js +1 -1
- package/dist/tools/executor.js +22 -17
- package/dist/tools/mutating.js +6 -0
- package/dist/tools/registry.js +872 -27
- package/dist/tools/shell-session.js +36 -1
- package/dist/tools/tool-output-spill.js +2 -2
- package/dist/ui/ActivitySpinner.js +17 -6
- package/dist/ui/App.js +36 -14
- package/dist/ui/ArtifactPicker.js +109 -0
- package/dist/ui/BusTray.js +70 -0
- package/dist/ui/Composer.js +39 -8
- package/dist/ui/Markdown.js +5 -3
- package/dist/ui/MouseProvider.js +99 -19
- package/dist/ui/QuestionPrompt.js +24 -3
- package/dist/ui/ThinkingSpinner.js +9 -5
- package/dist/ui/ToolStep.js +17 -12
- package/dist/ui/Transcript.js +14 -7
- package/dist/ui/capabilities.js +0 -9
- package/dist/ui/listhit.js +23 -0
- package/dist/ui/mouse.js +22 -0
- package/dist/ui/osc.js +7 -4
- package/dist/ui/progressbar.js +46 -0
- package/dist/ui/shimmer.js +43 -0
- package/dist/ui/theme.js +2 -0
- package/dist/ui/tick.js +48 -0
- package/dist/ui/toolicons.js +69 -0
- package/dist/util/slash.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Operator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
AXE's agentic terminal coding agent: a TypeScript + [Ink](https://github.com/vadimdemedes/ink) app backed by
|
|
4
|
+
the Aurora model, built to the frozen `SPEC/` contract shared with the Python core.
|
|
5
5
|
Launched as **`operator`** (1M-only) / **`operator+`** (Air⇄1M) — AXE's agentic terminal, built on the Aurora model.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Its reason to exist: a **full-frame React reconciler + Ink `<Static>`** render, which makes the
|
|
8
8
|
scroll / echo / prompt-overwrite bug class of the ANSI-cursor Python REPL *structurally impossible*.
|
|
9
9
|
|
|
10
10
|
## Architecture
|
package/dist/acp/agent.js
CHANGED
|
@@ -6,13 +6,21 @@
|
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { PROTOCOL_VERSION } from "@zed-industries/agent-client-protocol";
|
|
8
8
|
import { createAutonomySession } from "../autonomy/session-factory.js";
|
|
9
|
+
import { modelRegistry, visibleModels } from "../router/models.js";
|
|
10
|
+
import { hasByoToken } from "../auth/byo.js";
|
|
11
|
+
import { buildModelConfigOption, configOptionUpdate } from "./config-options.js";
|
|
9
12
|
export class OperatorAcpAgent {
|
|
10
13
|
conn;
|
|
11
14
|
settings;
|
|
15
|
+
sessionFactory;
|
|
12
16
|
sessions = new Map();
|
|
13
|
-
constructor(conn, settings
|
|
17
|
+
constructor(conn, settings,
|
|
18
|
+
// Structural seam (same discipline as CompactionOpts.meter): tests build the agent without the
|
|
19
|
+
// whole router/MCP/permissions stack; production passes nothing and gets createAutonomySession.
|
|
20
|
+
sessionFactory = createAutonomySession) {
|
|
14
21
|
this.conn = conn;
|
|
15
22
|
this.settings = settings;
|
|
23
|
+
this.sessionFactory = sessionFactory;
|
|
16
24
|
}
|
|
17
25
|
async initialize(_params) {
|
|
18
26
|
// We negotiate the version we build against and advertise a text-prompt agent. loadSession is not yet
|
|
@@ -28,10 +36,41 @@ export class OperatorAcpAgent {
|
|
|
28
36
|
}
|
|
29
37
|
async newSession(params) {
|
|
30
38
|
// Same building blocks as headless (router, MCP tools, permissions, telemetry) — no TUI, no ask_user.
|
|
31
|
-
const session =
|
|
39
|
+
const session = this.sessionFactory(this.settings);
|
|
32
40
|
const sessionId = randomUUID();
|
|
33
41
|
this.sessions.set(sessionId, { session, cwd: params.cwd || process.cwd() });
|
|
34
|
-
|
|
42
|
+
// GW-40: the stabilized configOptions surface (Zed dropdown for new clients; the SDK-0.4.5
|
|
43
|
+
// legacy set_model below for current ones). Extra field on the response — the SDK validates
|
|
44
|
+
// REQUESTS only, so this passes through to the wire untouched.
|
|
45
|
+
return { sessionId, configOptions: [this.modelOption(sessionId)] };
|
|
46
|
+
}
|
|
47
|
+
/** The live model selector for a session — honest (MOA listed only if configured), current value
|
|
48
|
+
* read from the Session itself so a /model-style switch elsewhere is reflected here too. */
|
|
49
|
+
modelOption(sessionId) {
|
|
50
|
+
const live = this.sessions.get(sessionId);
|
|
51
|
+
const moa = this.settings.moa;
|
|
52
|
+
return buildModelConfigOption(visibleModels(modelRegistry(this.settings.models), hasByoToken), live?.session.currentModel() ?? "", !!moa?.proposers?.length);
|
|
53
|
+
}
|
|
54
|
+
/** SDK-0.4.5 legacy path (wire: session/set_model) — what Zed ships today. The spec-stable
|
|
55
|
+
* session/set_config_option is translated onto this method by the run.ts shim; both client
|
|
56
|
+
* generations end up here, one switch, one source of truth (Session.setModel + its MOA guard). */
|
|
57
|
+
async setSessionModel(params) {
|
|
58
|
+
const live = this.sessions.get(params.sessionId);
|
|
59
|
+
if (!live)
|
|
60
|
+
throw new Error(`ACP: unknown session ${params.sessionId}`);
|
|
61
|
+
const r = live.session.setModel(params.modelId);
|
|
62
|
+
if (!r.ok)
|
|
63
|
+
throw new Error(r.error ?? `unknown model ${params.modelId}`);
|
|
64
|
+
// Spec: the agent notifies with the COMPLETE config state after its own changes.
|
|
65
|
+
void this.conn.sessionUpdate({
|
|
66
|
+
sessionId: params.sessionId,
|
|
67
|
+
update: configOptionUpdate([this.modelOption(params.sessionId)]),
|
|
68
|
+
}).catch(() => { });
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
/** Shim answer for session/set_config_option: the spec response is the full updated options. */
|
|
72
|
+
currentConfigOptions(sessionId) {
|
|
73
|
+
return { configOptions: [this.modelOption(sessionId)] };
|
|
35
74
|
}
|
|
36
75
|
// Required by the interface; the local editor link is unauthenticated (authMethods is empty above).
|
|
37
76
|
async authenticate(_params) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The honest model selector: only profiles Session.setModel would ACCEPT today are listed —
|
|
2
|
+
* MOA is omitted unless a moa block exists in settings (setModel refuses it otherwise, and a
|
|
3
|
+
* dropdown that can fail is the dishonesty SPEC/providers.md §1 bans). Descriptions carry ctx
|
|
4
|
+
* size and kind so the user can price a switch with their eyes. */
|
|
5
|
+
export function buildModelConfigOption(registry, currentId, moaAvailable) {
|
|
6
|
+
const options = [];
|
|
7
|
+
for (const p of registry) {
|
|
8
|
+
if (p.kind === "orchestrated" && !moaAvailable)
|
|
9
|
+
continue;
|
|
10
|
+
const bits = [p.desc, p.kind === "single" && p.ctx ? `${Math.round(p.ctx / 1000)}k ctx` : null, p.kind === "orchestrated" ? "mixture-of-agents" : null].filter(Boolean);
|
|
11
|
+
options.push({ value: p.id, name: p.label, description: bits.join(" · ") || undefined });
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
id: "model",
|
|
15
|
+
name: "Model",
|
|
16
|
+
category: "model",
|
|
17
|
+
type: "select",
|
|
18
|
+
currentValue: options.some((o) => o.value === currentId) ? currentId : options[0]?.value ?? currentId,
|
|
19
|
+
options,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Request-frame translation: session/set_config_option{sessionId,configId,value} ->
|
|
23
|
+
* session/set_model{sessionId,modelId}. Returns the rewritten params when configId is the model
|
|
24
|
+
* selector; null otherwise (mode-style options are not claimed — honesty over fake support). */
|
|
25
|
+
export function translateSetConfigOption(params) {
|
|
26
|
+
const p = params;
|
|
27
|
+
if (!p || typeof p.sessionId !== "string" || p.configId !== "model" || typeof p.value !== "string")
|
|
28
|
+
return null;
|
|
29
|
+
return { sessionId: p.sessionId, modelId: p.value };
|
|
30
|
+
}
|
|
31
|
+
/** Agent-side update notification shape (spec: complete config state). */
|
|
32
|
+
export function configOptionUpdate(options) {
|
|
33
|
+
return { sessionUpdate: "config_option_update", configOptions: options };
|
|
34
|
+
}
|
package/dist/acp/run.js
CHANGED
|
@@ -4,6 +4,84 @@
|
|
|
4
4
|
import { AgentSideConnection, ndJsonStream } from "@zed-industries/agent-client-protocol";
|
|
5
5
|
import { Readable, Writable } from "node:stream";
|
|
6
6
|
import { OperatorAcpAgent } from "./agent.js";
|
|
7
|
+
import { translateSetConfigOption } from "./config-options.js";
|
|
8
|
+
// GW-40 protocol shim. The stabilized spec's `session/set_config_option` is NOT in our pinned SDK
|
|
9
|
+
// (0.4.5) — its dispatcher is a closed switch that would answer method-not-found. Rather than
|
|
10
|
+
// upgrade a protocol dependency mid-flight, we translate on the wire: inbound
|
|
11
|
+
// set_config_option{configId:"model"} -> legacy set_model (both land in Agent.setSessionModel),
|
|
12
|
+
// outbound response -> the spec's complete-configOptions result. JSON-RPC ids are remembered only
|
|
13
|
+
// for in-flight requests (deleted on answer), so a client reusing ids stays correct.
|
|
14
|
+
export class SetConfigOptionShim {
|
|
15
|
+
pending = new Map(); // rpc id -> sessionId
|
|
16
|
+
agent = null;
|
|
17
|
+
input() {
|
|
18
|
+
let buf = "";
|
|
19
|
+
const pending = this.pending;
|
|
20
|
+
return new TransformStream({
|
|
21
|
+
transform(chunk, controller) {
|
|
22
|
+
buf += new TextDecoder().decode(chunk, { stream: true });
|
|
23
|
+
const parts = buf.split("\n");
|
|
24
|
+
buf = parts.pop() ?? "";
|
|
25
|
+
for (const line of parts)
|
|
26
|
+
controller.enqueue(new TextEncoder().encode(rewriteIn(line, pending) + "\n"));
|
|
27
|
+
},
|
|
28
|
+
flush(controller) { if (buf)
|
|
29
|
+
controller.enqueue(new TextEncoder().encode(rewriteIn(buf, pending) + "\n")); },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
output() {
|
|
33
|
+
let buf = "";
|
|
34
|
+
const self = this;
|
|
35
|
+
return new TransformStream({
|
|
36
|
+
transform(chunk, controller) {
|
|
37
|
+
buf += new TextDecoder().decode(chunk, { stream: true });
|
|
38
|
+
const parts = buf.split("\n");
|
|
39
|
+
buf = parts.pop() ?? "";
|
|
40
|
+
for (const line of parts)
|
|
41
|
+
controller.enqueue(new TextEncoder().encode(self.rewriteOut(line) + "\n"));
|
|
42
|
+
},
|
|
43
|
+
flush(controller) { if (buf)
|
|
44
|
+
controller.enqueue(new TextEncoder().encode(self.rewriteOut(buf) + "\n")); },
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
rewriteOut(line) {
|
|
48
|
+
if (!line.trim())
|
|
49
|
+
return line;
|
|
50
|
+
try {
|
|
51
|
+
const msg = JSON.parse(line);
|
|
52
|
+
const sid = msg && typeof msg.id !== "undefined" && this.pending.get(msg.id);
|
|
53
|
+
if (sid !== undefined) {
|
|
54
|
+
this.pending.delete(msg.id);
|
|
55
|
+
if (!msg.error && this.agent)
|
|
56
|
+
msg.result = this.agent.currentConfigOptions(sid);
|
|
57
|
+
}
|
|
58
|
+
return JSON.stringify(msg);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return line;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function rewriteIn(line, pending) {
|
|
66
|
+
if (!line.trim())
|
|
67
|
+
return line;
|
|
68
|
+
try {
|
|
69
|
+
const msg = JSON.parse(line);
|
|
70
|
+
if (msg?.method === "session/set_config_option" && typeof msg.id !== "undefined") {
|
|
71
|
+
const t = translateSetConfigOption(msg.params);
|
|
72
|
+
if (t) {
|
|
73
|
+
pending.set(msg.id, t.sessionId);
|
|
74
|
+
msg.method = "session/set_model";
|
|
75
|
+
msg.params = { sessionId: t.sessionId, modelId: t.modelId };
|
|
76
|
+
return JSON.stringify(msg);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return line;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return line;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
7
85
|
export async function runAcp(settings) {
|
|
8
86
|
// Safety net: anything that reaches for stdout (an MCP server, a dependency) would break the JSON-RPC
|
|
9
87
|
// stream. Send every console channel to stderr; the ACP connection owns stdout exclusively.
|
|
@@ -12,9 +90,12 @@ export async function runAcp(settings) {
|
|
|
12
90
|
}
|
|
13
91
|
const output = Writable.toWeb(process.stdout);
|
|
14
92
|
const input = Readable.toWeb(process.stdin);
|
|
15
|
-
const
|
|
93
|
+
const shim = new SetConfigOptionShim();
|
|
94
|
+
const outT = shim.output();
|
|
95
|
+
void outT.readable.pipeTo(output).catch(() => { });
|
|
96
|
+
const stream = ndJsonStream(outT.writable, input.pipeThrough(shim.input()));
|
|
16
97
|
// The connection lives until the client closes stdin (the editor detached / quit).
|
|
17
|
-
new AgentSideConnection((conn) => new OperatorAcpAgent(conn, settings), stream);
|
|
98
|
+
new AgentSideConnection((conn) => (shim.agent = new OperatorAcpAgent(conn, settings)), stream);
|
|
18
99
|
await new Promise((resolve) => {
|
|
19
100
|
process.stdin.once("end", resolve);
|
|
20
101
|
process.stdin.once("close", resolve);
|
package/dist/auth/byo.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// BYO vendor-key store (SPEC/providers.md §3: API-key connector, "paste once; stored in the Keychain";
|
|
2
|
+
// §5's gateway-first rule stays for api.axe.onl-routed models — a BYO connector is exactly the rare
|
|
3
|
+
// "client itself calls a vendor directly" fast path the spec allows, and the vendor key NEVER touches
|
|
4
|
+
// the gateway). Distinct keychain SERVICE from the operator token ("axe-operator") so a vendor key can
|
|
5
|
+
// never be read/mistaken for the operator bearer by any client — the separation IS the leak guard.
|
|
6
|
+
// Env override per account: KODE_BYO_<ACCOUNT> (uppercase, non-alnum → "_") for CI/headless.
|
|
7
|
+
// KODE_NO_KEYCHAIN=1 forces the 0600 JSON file (same convention as auth/store.ts).
|
|
8
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
9
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { homedir, platform } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
const SERVICE = "axe-operator-byo";
|
|
13
|
+
const FILE = process.env.KODE_BYO_FILE ?? join(homedir(), ".axe", "operator", "byo.json");
|
|
14
|
+
const NO_KEYCHAIN = process.env.KODE_NO_KEYCHAIN === "1";
|
|
15
|
+
function envName(account) {
|
|
16
|
+
return "KODE_BYO_" + account.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
17
|
+
}
|
|
18
|
+
function readFile_() {
|
|
19
|
+
try {
|
|
20
|
+
const j = JSON.parse(readFileSync(FILE, "utf8"));
|
|
21
|
+
return j && typeof j === "object" ? j : {};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function writeFile_(map) {
|
|
28
|
+
mkdirSync(dirname(FILE), { recursive: true, mode: 0o700 });
|
|
29
|
+
writeFileSync(FILE, JSON.stringify(map, null, 1), { mode: 0o600 });
|
|
30
|
+
}
|
|
31
|
+
/** Sync read: env override → OS keychain → 0600 file fallback. Used by setModel (sync path).
|
|
32
|
+
* Keychain/file lookups are memoized per account: buildCapabilities calls the registry liberally and
|
|
33
|
+
* every miss would spawn `security`. Env stays live (process.env is cheap, CI can flip it mid-run). */
|
|
34
|
+
const _cache = new Map();
|
|
35
|
+
export function getByoToken(account) {
|
|
36
|
+
const env = process.env[envName(account)];
|
|
37
|
+
if (env)
|
|
38
|
+
return env.trim() || undefined;
|
|
39
|
+
if (_cache.has(account))
|
|
40
|
+
return _cache.get(account);
|
|
41
|
+
let found;
|
|
42
|
+
if (!NO_KEYCHAIN) {
|
|
43
|
+
try {
|
|
44
|
+
if (platform() === "darwin") {
|
|
45
|
+
const out = execFileSync("security", ["find-generic-password", "-s", SERVICE, "-a", account, "-w"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
46
|
+
if (out.trim())
|
|
47
|
+
found = out.trim();
|
|
48
|
+
}
|
|
49
|
+
else if (platform() === "linux") {
|
|
50
|
+
const out = execFileSync("secret-tool", ["lookup", "service", SERVICE, "account", account], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
51
|
+
if (out.trim())
|
|
52
|
+
found = out.trim();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch { /* not stored here → fall through */ }
|
|
56
|
+
}
|
|
57
|
+
if (!found)
|
|
58
|
+
found = readFile_()[account] || undefined;
|
|
59
|
+
_cache.set(account, found);
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
/** True when an account's key resolves — the connector "Connected" state for pickers/gates. */
|
|
63
|
+
export function hasByoToken(account) {
|
|
64
|
+
return !!getByoToken(account);
|
|
65
|
+
}
|
|
66
|
+
export function clearByoCache(account) {
|
|
67
|
+
if (account)
|
|
68
|
+
_cache.delete(account);
|
|
69
|
+
else
|
|
70
|
+
_cache.clear();
|
|
71
|
+
}
|
|
72
|
+
/** Delete from all three tiers (env is the caller's process, only noted). */
|
|
73
|
+
export function deleteByoToken(account) {
|
|
74
|
+
try {
|
|
75
|
+
if (!NO_KEYCHAIN && platform() === "darwin") {
|
|
76
|
+
spawnSync("security", ["delete-generic-password", "-s", SERVICE, "-a", account], { stdio: "ignore" });
|
|
77
|
+
}
|
|
78
|
+
else if (!NO_KEYCHAIN && platform() === "linux") {
|
|
79
|
+
spawnSync("secret-tool", ["clear", "service", SERVICE, "account", account], { stdio: "ignore" });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch { /* file tier below still cleans */ }
|
|
83
|
+
const m = readFile_();
|
|
84
|
+
if (account in m) {
|
|
85
|
+
delete m[account];
|
|
86
|
+
writeFile_(m);
|
|
87
|
+
}
|
|
88
|
+
clearByoCache(account);
|
|
89
|
+
}
|
|
90
|
+
/** Accounts with a stored key (file + keychain best-effort; for `operator auth byo` listing). */
|
|
91
|
+
export function listByoAccounts() {
|
|
92
|
+
return Object.keys(readFile_()).filter((a) => !!readFile_()[a]);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Interactive paste-and-store on the real TTY. macOS: `security add-generic-password -w` with NO value
|
|
96
|
+
* arg prompts twice with HIDDEN input — the key never echoes, never lands in shell history, and never
|
|
97
|
+
* passes through this process's memory at all. Non-mac / KODE_NO_KEYCHAIN: pass the key via
|
|
98
|
+
* KODE_BYO_<ACCOUNT> (or a direct 0600 write to the byo file) — we deliberately do NOT prompt in clear
|
|
99
|
+
* text where we cannot guarantee echo-off. Returns ok; the value is never logged.
|
|
100
|
+
*/
|
|
101
|
+
export function setByoTokenInteractive(account) {
|
|
102
|
+
if (!NO_KEYCHAIN && platform() === "darwin") {
|
|
103
|
+
const r = spawnSync("security", ["add-generic-password", "-U", "-s", SERVICE, "-a", account, "-w"], { stdio: "inherit" });
|
|
104
|
+
if (r.status !== 0)
|
|
105
|
+
return false;
|
|
106
|
+
clearByoCache(account); // a fresh paste must beat the memoized miss
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
const env = getByoToken(account); // honors KODE_BYO_<ACCOUNT> when present
|
|
110
|
+
if (!env) {
|
|
111
|
+
process.stderr.write(`no keychain here — set ${envName(account)} or write ${FILE} (0600)\n`);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const m = readFile_();
|
|
115
|
+
m[account] = env;
|
|
116
|
+
writeFile_(m);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
package/dist/auth/commands.js
CHANGED
|
@@ -16,6 +16,7 @@ import { platform } from "node:os";
|
|
|
16
16
|
import { createInterface } from "node:readline/promises";
|
|
17
17
|
import { requestDeviceCode, awaitApproval, verifyToken, authBase, signupStart, signupVerify, } from "./client.js";
|
|
18
18
|
import { saveCredentials, loadCredentials, clearCredentials } from "./store.js";
|
|
19
|
+
import { listByoAccounts, hasByoToken, deleteByoToken, setByoTokenInteractive } from "./byo.js";
|
|
19
20
|
/** One-line prompt on the real TTY. Runs before Ink mounts, so plain readline is safe. */
|
|
20
21
|
async function ask(question) {
|
|
21
22
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -171,6 +172,37 @@ function flagValue(rest, flag) {
|
|
|
171
172
|
const i = rest.indexOf(flag);
|
|
172
173
|
return i >= 0 ? rest[i + 1] : undefined;
|
|
173
174
|
}
|
|
175
|
+
/** `operator auth byo [account] [--list|--rm]` — BYO vendor-key connectors (SPEC/providers.md §2/§3):
|
|
176
|
+
* hidden paste into the OS keychain under the SEPARATE `axe-operator-byo` service (an operator token
|
|
177
|
+
* and a vendor key can never be confused), then /model's connectors light up. QwenCloud Token Plan
|
|
178
|
+
* example: `operator auth byo qwen` → paste the `sk-sp-…` key from home.qwencloud.com. */
|
|
179
|
+
function byo(rest) {
|
|
180
|
+
const account = rest.find((a) => !a.startsWith("--"));
|
|
181
|
+
if (rest.includes("--list")) {
|
|
182
|
+
const accts = listByoAccounts();
|
|
183
|
+
for (const a of new Set([...accts, "qwen"]))
|
|
184
|
+
if (hasByoToken(a))
|
|
185
|
+
console.log(`connected: ${a}`);
|
|
186
|
+
if (!accts.length)
|
|
187
|
+
console.log('(no BYO keys stored yet — e.g. "operator auth byo qwen")');
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
if (!account) {
|
|
191
|
+
console.error("usage: operator auth byo <account> | byo --list | byo <account> --rm");
|
|
192
|
+
return 1;
|
|
193
|
+
}
|
|
194
|
+
if (rest.includes("--rm")) {
|
|
195
|
+
deleteByoToken(account);
|
|
196
|
+
console.log(`✓ removed the ${account} key`);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
if (setByoTokenInteractive(account)) {
|
|
200
|
+
console.log(`✓ ${account} key stored — /model now offers its connectors`);
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
console.error(`✗ could not store the ${account} key`);
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
174
206
|
/** Dispatch `operator auth <sub> [args]`. Returns a process exit code. */
|
|
175
207
|
export async function runAuth(argv) {
|
|
176
208
|
const [sub, ...rest] = argv;
|
|
@@ -189,8 +221,9 @@ export async function runAuth(argv) {
|
|
|
189
221
|
case "logout": return logout();
|
|
190
222
|
case "status":
|
|
191
223
|
case "whoami": return status();
|
|
224
|
+
case "byo": return byo(rest);
|
|
192
225
|
default:
|
|
193
|
-
console.log("usage: operator auth <login [--email <addr> | --browser | --token <pat>] | logout | status>");
|
|
226
|
+
console.log("usage: operator auth <login [--email <addr> | --browser | --token <pat>] | logout | status | byo [account] [--list | --rm]>");
|
|
194
227
|
return sub ? 1 : 0;
|
|
195
228
|
}
|
|
196
229
|
}
|
package/dist/autonomy/dream.js
CHANGED
|
@@ -29,7 +29,7 @@ export async function runDream(settings, opts = {}) {
|
|
|
29
29
|
const reporter = opts.reporter ?? makeReporter({ json: opts.json, logFile: opts.logFile });
|
|
30
30
|
const dream = settings.autonomy?.dream;
|
|
31
31
|
if (!dream?.enabled) {
|
|
32
|
-
reporter.event("dream_disabled", { hint: "set autonomy.dream.enabled=true
|
|
32
|
+
reporter.event("dream_disabled", { hint: "set autonomy.dream.enabled=true in settings to allow dream mode" });
|
|
33
33
|
return 2;
|
|
34
34
|
}
|
|
35
35
|
const allow = dream.allow ?? ["board"];
|
package/dist/autonomy/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// operator board <list|add "<task>"|run|status> [--json] [--max N] [--keep-awake]
|
|
7
7
|
// operator routine <list|run <id>|install <id> [--crontab]|watch> [--keep-awake]
|
|
8
8
|
// operator dream [--keep-awake]
|
|
9
|
+
// operator media-robot [--kind image|video] [--n N] [--max N] [--dry] [--json] [--keep-awake]
|
|
9
10
|
//
|
|
10
11
|
// Returns an exit code when it handled the argv, or null when the first arg isn't an autonomy command
|
|
11
12
|
// (so cli.tsx falls through to the interactive REPL). Keep-awake is applied centrally here and torn down
|
|
@@ -18,7 +19,7 @@ import { runAcp } from "../acp/run.js";
|
|
|
18
19
|
import { boardPath, addTask, readBoard } from "./board.js";
|
|
19
20
|
import { routinesPath, readRoutines } from "./routines.js";
|
|
20
21
|
import { readableRoutine, nextFire, runRoutine, launchdPlist, launchdLabel, crontabLine } from "./routine-run.js";
|
|
21
|
-
const AUTONOMY_COMMANDS = new Set(["run", "loop", "board", "routine", "dream", "acp"]);
|
|
22
|
+
const AUTONOMY_COMMANDS = new Set(["run", "loop", "board", "routine", "dream", "acp", "media-robot"]);
|
|
22
23
|
/** Split argv (after the subcommand) into --bool flags, --key value pairs, and positionals. `--` ends
|
|
23
24
|
* flag parsing so a task string starting with a dash is preserved. */
|
|
24
25
|
function parseFlags(args, valued) {
|
|
@@ -51,7 +52,7 @@ function parseFlags(args, valued) {
|
|
|
51
52
|
}
|
|
52
53
|
return { bool, val, positional };
|
|
53
54
|
}
|
|
54
|
-
const VALUED = new Set(["log", "max-turns", "max-seconds", "max"]);
|
|
55
|
+
const VALUED = new Set(["log", "max-turns", "max-seconds", "max", "n", "source", "sink", "kind"]);
|
|
55
56
|
function intFlag(f, key) {
|
|
56
57
|
const v = f.val.get(key);
|
|
57
58
|
if (v === undefined)
|
|
@@ -256,5 +257,18 @@ export async function dispatchAutonomy(argv, settings) {
|
|
|
256
257
|
if (cmd === "dream") {
|
|
257
258
|
return withKeepAwake(wantKeepAwake(settings, f), "Operator dream", () => runDream(settings, { json: f.bool.has("json"), logFile: f.val.get("log") }));
|
|
258
259
|
}
|
|
260
|
+
if (cmd === "media-robot") {
|
|
261
|
+
// Autonomous flywheel pass: mine media-gen.jsonl → best-of-N regenerate → vision self-review → log winners.
|
|
262
|
+
const { runMediaRobot } = await import("./media-robot.js");
|
|
263
|
+
return withKeepAwake(wantKeepAwake(settings, f), "Operator media-robot", () => runMediaRobot(settings, {
|
|
264
|
+
kind: f.val.get("kind") === "video" ? "video" : "image",
|
|
265
|
+
n: intFlag(f, "n"),
|
|
266
|
+
max: intFlag(f, "max"),
|
|
267
|
+
source: f.val.get("source"),
|
|
268
|
+
sink: f.val.get("sink"),
|
|
269
|
+
dry: f.bool.has("dry"),
|
|
270
|
+
json: f.bool.has("json"),
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
259
273
|
return null;
|
|
260
274
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Autonomous media robot — a triggerable, broker-agnostic pass that mines the media-gen flywheel corpus,
|
|
2
|
+
// regenerates prompts best-of-N, SELF-REVIEWS each candidate with the fleet vision model (a reward signal),
|
|
3
|
+
// keeps the winner, and logs the SCORED outcome to a results sink. This is the flywheel's compounding loop
|
|
4
|
+
// made autonomous: media-gen.jsonl (every generation) → best-of-N + vision-judge (which output is good) →
|
|
5
|
+
// media-robot.jsonl (scored winners) → the retrieval/reward layer learns "good". It composes the shipped
|
|
6
|
+
// media tools (image_generate / video_generate / image_analyze) through the tool registry — NO new model, NO
|
|
7
|
+
// broker change — so it inherits every broker upgrade (e.g. the reference/identity broker) with zero change
|
|
8
|
+
// here: a reference-bearing request just routes to a better backend and scores higher.
|
|
9
|
+
//
|
|
10
|
+
// Safe by default: a SINGLE pass (`--once` is implicit), small best-of-N, image-only — never an unattended
|
|
11
|
+
// GPU loop unless the operator explicitly schedules it (`operator routine`). The brokers are scale-to-zero,
|
|
12
|
+
// so an idle robot costs nothing.
|
|
13
|
+
import { registry } from "../tools/registry.js";
|
|
14
|
+
async function homeFile(name) {
|
|
15
|
+
const os = await import("node:os");
|
|
16
|
+
const { join } = await import("node:path");
|
|
17
|
+
return join(os.homedir(), ".axe", "operator", name);
|
|
18
|
+
}
|
|
19
|
+
/** Parse the provenance corpus (one JSON object per line, malformed lines skipped). */
|
|
20
|
+
async function readCorpus(file) {
|
|
21
|
+
const { readFile } = await import("node:fs/promises");
|
|
22
|
+
const txt = await readFile(file, "utf8").catch(() => "");
|
|
23
|
+
const recs = [];
|
|
24
|
+
for (const line of txt.split("\n")) {
|
|
25
|
+
const s = line.trim();
|
|
26
|
+
if (!s)
|
|
27
|
+
continue;
|
|
28
|
+
try {
|
|
29
|
+
recs.push(JSON.parse(s));
|
|
30
|
+
}
|
|
31
|
+
catch { /* skip malformed */ }
|
|
32
|
+
}
|
|
33
|
+
return recs;
|
|
34
|
+
}
|
|
35
|
+
/** Pick the prompts to (re)generate: most-recent unique SUCCESSFUL prompts for the requested kind, preferring
|
|
36
|
+
* the richer EXPANDED prompt when one was logged (the flywheel's own prior improvement). */
|
|
37
|
+
function selectPrompts(corpus, kind, max) {
|
|
38
|
+
const want = kind === "video" ? "video_generate" : "image_generate";
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
const out = [];
|
|
41
|
+
for (let i = corpus.length - 1; i >= 0 && out.length < max; i--) {
|
|
42
|
+
const r = corpus[i];
|
|
43
|
+
if (r.tool !== want || r.ok === false)
|
|
44
|
+
continue;
|
|
45
|
+
const p = (r.expanded || r.prompt || "").trim();
|
|
46
|
+
if (!p || seen.has(p))
|
|
47
|
+
continue;
|
|
48
|
+
seen.add(p);
|
|
49
|
+
out.push(p);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
const URL_RE = /https?:\/\/\S+?\.(?:png|mp4|jpg|jpeg|webp)/i;
|
|
54
|
+
/** Pull the renderable reference out of a generate tool's string result (public URL first, else a local path). */
|
|
55
|
+
function extractRef(toolResult) {
|
|
56
|
+
const url = toolResult.match(URL_RE);
|
|
57
|
+
if (url)
|
|
58
|
+
return url[0];
|
|
59
|
+
const path = toolResult.match(/→\s+(\/\S+\.(?:png|mp4|jpg|jpeg|webp))/i);
|
|
60
|
+
return path ? path[1] : undefined;
|
|
61
|
+
}
|
|
62
|
+
/** Vision-judge a generated image against its prompt → a 0..10 score, using the SAME fleet vision model the
|
|
63
|
+
* tools use (image_analyze). This is the reward signal for best-of-N selection. Returns score -1 when the
|
|
64
|
+
* judge is unreachable or its answer can't be parsed (that candidate is simply not preferred). */
|
|
65
|
+
async function judgeImage(ref, prompt) {
|
|
66
|
+
const analyze = registry.get("image_analyze");
|
|
67
|
+
if (!analyze)
|
|
68
|
+
return { score: -1, note: "no image_analyze tool available" };
|
|
69
|
+
const q = `On a scale of 0 to 10, how well does this image match the description: "${prompt}"? ` +
|
|
70
|
+
`Weigh subject, composition, style, lighting, and detail. ` +
|
|
71
|
+
`Answer with ONLY a number 0-10, then a dash and a brief reason.`;
|
|
72
|
+
const out = (await analyze.run({ image: ref, question: q, max_tokens: 120 })).trim();
|
|
73
|
+
if (out.startsWith("error:"))
|
|
74
|
+
return { score: -1, note: out.slice(0, 160) };
|
|
75
|
+
const m = out.match(/\d+(?:\.\d+)?/);
|
|
76
|
+
const score = m ? Math.max(0, Math.min(10, parseFloat(m[0]))) : -1;
|
|
77
|
+
return { score, note: out.replace(/\s+/g, " ").slice(0, 160) };
|
|
78
|
+
}
|
|
79
|
+
/** One autonomous pass: read the corpus → select prompts → best-of-N generate → self-review → log winners. */
|
|
80
|
+
export async function runMediaRobot(_settings, opts = {}) {
|
|
81
|
+
const kind = opts.kind === "video" ? "video" : "image";
|
|
82
|
+
const n = Math.max(1, Math.min(opts.n ?? 2, 4));
|
|
83
|
+
const max = Math.max(1, Math.min(opts.max ?? 3, 20));
|
|
84
|
+
const source = opts.source || (await homeFile("media-gen.jsonl"));
|
|
85
|
+
const sink = opts.sink || (await homeFile("media-robot.jsonl"));
|
|
86
|
+
const log = (s) => process.stderr.write(s + "\n");
|
|
87
|
+
const corpus = await readCorpus(source);
|
|
88
|
+
const prompts = selectPrompts(corpus, kind, max);
|
|
89
|
+
log(`media-robot: ${corpus.length} corpus record(s) → ${prompts.length} ${kind} prompt(s), best-of-${n}${opts.dry ? " [DRY]" : ""}`);
|
|
90
|
+
if (!prompts.length) {
|
|
91
|
+
log(`media-robot: nothing to do — no successful ${kind} generations in ${source} yet. Run some ${kind} gens first; each one seeds the robot.`);
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
if (opts.dry) {
|
|
95
|
+
prompts.forEach((p, i) => log(` ${i + 1}. ${p.length > 100 ? p.slice(0, 100) + "…" : p}`));
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
const gen = registry.get(kind === "video" ? "video_generate" : "image_generate");
|
|
99
|
+
if (!gen) {
|
|
100
|
+
log("media-robot: no generate tool in registry");
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
const { appendFile, mkdir } = await import("node:fs/promises");
|
|
104
|
+
const { dirname } = await import("node:path");
|
|
105
|
+
await mkdir(dirname(sink), { recursive: true }).catch(() => { });
|
|
106
|
+
const outcomes = [];
|
|
107
|
+
for (const prompt of prompts) {
|
|
108
|
+
const cands = [];
|
|
109
|
+
for (let i = 0; i < n; i++) {
|
|
110
|
+
const res = await gen.run(kind === "video" ? { prompt } : { prompt, size: "1024x1024" });
|
|
111
|
+
const ref = extractRef(res);
|
|
112
|
+
if (!ref) {
|
|
113
|
+
log(` ✗ gen failed: ${res.slice(0, 120)}`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// Image candidates get a real vision-judged score (best-of-N reward). Video self-review is qualitative
|
|
117
|
+
// only for now (a numeric video-judge via video_analyze is a follow-up), so video keeps every candidate.
|
|
118
|
+
const j = kind === "image" ? await judgeImage(ref, prompt) : { score: 0, note: "video: self-review TODO (video_analyze judge)" };
|
|
119
|
+
cands.push({ ref, score: j.score, note: j.note });
|
|
120
|
+
log(` • cand ${i + 1}/${n} score ${j.score >= 0 ? j.score : "?"} → ${ref}`);
|
|
121
|
+
}
|
|
122
|
+
if (!cands.length)
|
|
123
|
+
continue;
|
|
124
|
+
cands.sort((a, b) => b.score - a.score); // highest score wins; -1 (unjudged) sinks to the bottom
|
|
125
|
+
const best = cands[0];
|
|
126
|
+
const rec = {
|
|
127
|
+
ts: new Date().toISOString(), kind, prompt, n,
|
|
128
|
+
best_ref: best.ref, best_score: best.score, best_note: best.note, candidates: cands,
|
|
129
|
+
};
|
|
130
|
+
outcomes.push(rec);
|
|
131
|
+
await appendFile(sink, JSON.stringify(rec) + "\n", { encoding: "utf8", mode: 0o600 }).catch(() => { });
|
|
132
|
+
log(` ✓ best (score ${best.score >= 0 ? best.score : "unjudged"}) → ${best.ref}`);
|
|
133
|
+
}
|
|
134
|
+
log(`media-robot: pass complete — ${outcomes.length} winner(s) logged to ${sink}`);
|
|
135
|
+
if (opts.json)
|
|
136
|
+
process.stdout.write(JSON.stringify({ kind, processed: outcomes.length, outcomes }, null, 2) + "\n");
|
|
137
|
+
return 0;
|
|
138
|
+
}
|