@0perator/operator 0.1.331 → 0.1.333
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/acp/config-options.js +10 -1
- package/dist/auth/byo.js +90 -9
- package/dist/auth/commands.js +1 -1
- package/dist/autonomy/delegate.js +3 -2
- package/dist/autonomy/session-factory.js +1 -0
- package/dist/cli.js +210 -62
- package/dist/config/persona.js +3 -1
- package/dist/config/settings.js +38 -4
- package/dist/engine/agent.js +8 -4
- package/dist/engine/anthropic-chat.js +28 -6
- package/dist/engine/anthropic.js +1 -1
- package/dist/engine/aurora.js +5 -1
- package/dist/engine/continuation.js +1 -1
- package/dist/engine/router-adapter.js +6 -5
- package/dist/engine/verify-gate.js +30 -3
- package/dist/remote/safe-commands.js +1 -1
- package/dist/router/discovery.js +23 -4
- package/dist/router/free-models.js +191 -0
- package/dist/router/models.js +142 -60
- package/dist/services/preflight.js +17 -2
- package/dist/session.js +94 -23
- package/dist/tools/sandbox.js +1 -1
- package/dist/ui/App.js +4 -3
- package/dist/ui/Composer.js +16 -1
- package/dist/ui/QuestionPrompt.js +22 -4
- package/dist/ui/SecretPrompt.js +77 -0
- package/dist/ui/StatusRule.js +6 -6
- package/dist/ui/modelPicker.js +110 -0
- package/dist/ui/slashCommands.js +3 -1
- package/dist/util/slash.js +3 -2
- package/package.json +1 -1
- package/dist/engine/cli.js +0 -1171
- package/dist/router/models.js.bak +0 -78
- package/dist/router/models.js.bak-1791259923 +0 -78
- package/dist/router/models.js.bak-pre-gateway +0 -78
- package/dist/router/models.js.bak-pre-patch2 +0 -78
- package/dist/router/models.js.bak2 +0 -78
- package/dist/services/model-autodetect.js +0 -240
- package/dist/tools/native-redirect.js +0 -140
- package/dist/tools/power-tools.js +0 -627
- package/dist/tools/registry.js.bak-1791259948 +0 -1914
- package/dist/tools/registry.js.bak-pre-plugins +0 -1914
- package/dist/ui/BusTray.js +0 -70
- package/dist/ui/resize.js +0 -160
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// GW-40 · Session Config Options — the editor's model dropdown.
|
|
2
|
+
// The stabilized ACP spec (agentclientprotocol.com/protocol/v1/session-config-options, fetched
|
|
3
|
+
// 2026-10-01) supersedes the older model APIs with a generic `configOptions[]` on session/new
|
|
4
|
+
// (category:"model" select) switched via `session/set_config_option`. The TS SDK we pin (0.4.5)
|
|
5
|
+
// ships the legacy session/set_model dispatch but NOT the new method — its dispatcher is a closed
|
|
6
|
+
// switch, so run.ts carries a thin shim (configOptionShim) translating the new call into the old
|
|
7
|
+
// one, and answering with the full configOptions state as the spec requires. Both client
|
|
8
|
+
// generations get the same picker; when the SDK catches up, delete the shim, keep everything else.
|
|
9
|
+
import { profileEndpoint } from "../router/models.js";
|
|
1
10
|
/** The honest model selector: only profiles Session.setModel would ACCEPT today are listed —
|
|
2
11
|
* MOA is omitted unless a moa block exists in settings (setModel refuses it otherwise, and a
|
|
3
12
|
* dropdown that can fail is the dishonesty SPEC/providers.md §1 bans). Descriptions carry ctx
|
|
@@ -9,7 +18,7 @@ export function buildModelConfigOption(registry, currentId, moaAvailable, hasByo
|
|
|
9
18
|
continue; // picker truth: down slots aren't offered…
|
|
10
19
|
if (p.ownerOnly && !isOwner)
|
|
11
20
|
continue; // …nor owner-only lanes to a non-owner seat (setModel refuses them too)
|
|
12
|
-
if (p.byo && !(hasByo ? hasByo(p.byo) : false))
|
|
21
|
+
if (p.byo && !(hasByo ? hasByo(p.byo, profileEndpoint(p)) : false))
|
|
13
22
|
continue; // …nor unconnectable connectors
|
|
14
23
|
if (p.kind === "orchestrated" && !moaAvailable)
|
|
15
24
|
continue;
|
package/dist/auth/byo.js
CHANGED
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
// "client itself calls a vendor directly" fast path the spec allows, and the vendor key NEVER touches
|
|
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
|
-
// Env override per account: KODE_BYO_<ACCOUNT> (uppercase, non-alnum → "_") for CI/headless.
|
|
7
|
-
//
|
|
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
|
|
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
|
+
// nor ride to a proxy row that shares the account name. KODE_NO_KEYCHAIN=1 forces the 0600 JSON file (same
|
|
10
|
+
// convention as auth/store.ts).
|
|
8
11
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
9
12
|
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
13
|
import { platform } from "node:os";
|
|
11
14
|
import { dirname } from "node:path";
|
|
12
15
|
import { operatorPath } from "../config/home.js";
|
|
16
|
+
import { BYO_PRESETS } from "../router/models.js"; // leaf registry (no imports of its own) — no cycle
|
|
17
|
+
import { getOperatorToken } from "../engine/aurora.js";
|
|
13
18
|
const SERVICE = "axe-operator-byo";
|
|
14
19
|
// Resolved per call, not at import: the file follows $KODE_HOME / $KODE_PROFILE, so a profile's vendor keys
|
|
15
20
|
// never land in (or get read from) another identity's file.
|
|
@@ -18,6 +23,26 @@ const NO_KEYCHAIN = process.env.KODE_NO_KEYCHAIN === "1";
|
|
|
18
23
|
function envName(account) {
|
|
19
24
|
return "KODE_BYO_" + account.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
20
25
|
}
|
|
26
|
+
const hostOf = (url) => {
|
|
27
|
+
try {
|
|
28
|
+
return url ? new URL(url).host : undefined;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** The vendor's own variable for an account, but only when `endpoint` is on that preset's host. Looked up at call
|
|
35
|
+
* time so a preset added later counts. */
|
|
36
|
+
function envAliasValue(account, endpoint) {
|
|
37
|
+
const host = hostOf(endpoint);
|
|
38
|
+
if (!host)
|
|
39
|
+
return undefined;
|
|
40
|
+
for (const p of Object.values(BYO_PRESETS)) {
|
|
41
|
+
if (p.account === account && p.envAlias && hostOf(p.endpoint) === host)
|
|
42
|
+
return process.env[p.envAlias]?.trim() || undefined;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
21
46
|
function readFile_() {
|
|
22
47
|
try {
|
|
23
48
|
const j = JSON.parse(readFileSync(byoFile(), "utf8"));
|
|
@@ -35,11 +60,24 @@ function writeFile_(map) {
|
|
|
35
60
|
}
|
|
36
61
|
catch { /* best-effort: a pre-existing looser file is tightened */ }
|
|
37
62
|
}
|
|
38
|
-
/** Sync read:
|
|
39
|
-
* Keychain/file lookups are memoized per account:
|
|
40
|
-
* every miss would spawn `security`. Env stays live
|
|
63
|
+
/** Sync read: KODE_BYO_<ACCOUNT> → OS keychain → 0600 file → the preset's envAlias (only for `endpoint` on the
|
|
64
|
+
* preset's own host). Used by setModel (sync path). Keychain/file lookups are memoized per account:
|
|
65
|
+
* buildCapabilities calls the registry liberally and every miss would spawn `security`. Env stays live
|
|
66
|
+
* (process.env is cheap, CI can flip it mid-run). */
|
|
41
67
|
const _cache = new Map();
|
|
42
|
-
export function getByoToken(account) {
|
|
68
|
+
export function getByoToken(account, endpoint) {
|
|
69
|
+
return storedByoToken(account) ?? envAliasValue(account, endpoint);
|
|
70
|
+
}
|
|
71
|
+
/** The owner's explicit key only — KODE_BYO_<ACCOUNT> or the store, never an ambient vendor variable. Model-driven
|
|
72
|
+
* selection (delegate_task) gates on this, so a variable exported for other tools never becomes spendable by the model. */
|
|
73
|
+
export function hasStoredByoToken(account) {
|
|
74
|
+
return !!storedByoToken(account);
|
|
75
|
+
}
|
|
76
|
+
/** A sign-in preset's account (0perator Free) is the Operator sign-in itself: no key is ever stored for it. */
|
|
77
|
+
const signInAccount = (account) => Object.values(BYO_PRESETS).some((p) => p.signIn && p.account === account);
|
|
78
|
+
function storedByoToken(account) {
|
|
79
|
+
if (signInAccount(account))
|
|
80
|
+
return process.env.KODE_OPERATOR_TOKEN?.trim() || getOperatorToken();
|
|
43
81
|
const env = process.env[envName(account)];
|
|
44
82
|
if (env)
|
|
45
83
|
return env.trim() || undefined;
|
|
@@ -66,9 +104,9 @@ export function getByoToken(account) {
|
|
|
66
104
|
_cache.set(account, found);
|
|
67
105
|
return found;
|
|
68
106
|
}
|
|
69
|
-
/** True when an account's key resolves — the connector "Connected" state for pickers
|
|
70
|
-
export function hasByoToken(account) {
|
|
71
|
-
return !!getByoToken(account);
|
|
107
|
+
/** True when an account's key resolves for `endpoint` — the connector "Connected" state for owner pickers. */
|
|
108
|
+
export function hasByoToken(account, endpoint) {
|
|
109
|
+
return !!getByoToken(account, endpoint);
|
|
72
110
|
}
|
|
73
111
|
export function clearByoCache(account) {
|
|
74
112
|
if (account)
|
|
@@ -123,3 +161,46 @@ export function setByoTokenInteractive(account) {
|
|
|
123
161
|
writeFile_(m);
|
|
124
162
|
return true;
|
|
125
163
|
}
|
|
164
|
+
/** The one `security -i` line that stores a key. Pure (tests check the text with no keychain). A key or account
|
|
165
|
+
* that is not a single printable-ASCII token free of quotes and backslashes is refused rather than quoted —
|
|
166
|
+
* `security`'s line parser is not a shell, and no vendor key contains a space or a quote. */
|
|
167
|
+
export function buildKeychainAddCommand(account, key) {
|
|
168
|
+
for (const v of [account, key]) {
|
|
169
|
+
if (!/^[\x21-\x7e]+$/.test(v) || /["'\\]/.test(v))
|
|
170
|
+
throw new Error("byo: account and key must be one printable token (no spaces, quotes, backslashes or control characters)");
|
|
171
|
+
}
|
|
172
|
+
return `add-generic-password -U -s ${SERVICE} -a ${account} -w ${key}`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Store a key handed over in-process (the /model "Connect a provider key" prompt, where Ink owns the terminal so
|
|
176
|
+
* the TTY double-prompt above is unavailable). macOS: `security -i` reads the add-generic-password line from STDIN —
|
|
177
|
+
* the secret is never in argv (ps / launchd logs would show it) — and its exit code is the verdict: a keychain that
|
|
178
|
+
* exists but refuses (locked, denied) is a failure, never a silent downgrade to the file. Non-mac, KODE_NO_KEYCHAIN=1,
|
|
179
|
+
* or no `security` binary at all: the 0600 byo file. The memo is cleared so the new connector shows at once; the
|
|
180
|
+
* value is never logged. Returns ok.
|
|
181
|
+
*/
|
|
182
|
+
export function setByoToken(account, key, opts = {}) {
|
|
183
|
+
const value = key.trim();
|
|
184
|
+
let line;
|
|
185
|
+
try {
|
|
186
|
+
line = buildKeychainAddCommand(account, value);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (!NO_KEYCHAIN && (opts.platform ?? platform()) === "darwin") {
|
|
192
|
+
const r = (opts.spawn ?? spawnSync)("security", ["-i"], { input: `${line}\n`, stdio: ["pipe", "ignore", "ignore"] });
|
|
193
|
+
if (!r.error) {
|
|
194
|
+
if (r.status !== 0)
|
|
195
|
+
return false;
|
|
196
|
+
clearByoCache(account);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
// spawn itself failed (no `security` on PATH) → the file tier below
|
|
200
|
+
}
|
|
201
|
+
const m = readFile_();
|
|
202
|
+
m[account] = value;
|
|
203
|
+
writeFile_(m);
|
|
204
|
+
clearByoCache(account);
|
|
205
|
+
return true;
|
|
206
|
+
}
|
package/dist/auth/commands.js
CHANGED
|
@@ -269,7 +269,7 @@ async function byoModel(rest) {
|
|
|
269
269
|
console.error(` presets: ${Object.keys(BYO_PRESETS).join(", ")}`);
|
|
270
270
|
return 1;
|
|
271
271
|
}
|
|
272
|
-
const profile = { id, label: label ?? id, kind: "single", desc: `BYO ${label ?? id} — your key`, endpoint: base, model, ctx, byo: account, transport: dialect };
|
|
272
|
+
const profile = { id, label: label ?? id, kind: "single", desc: `BYO ${label ?? id} — your key`, endpoint: base, model, ctx, byo: account, transport: dialect, ...(preset?.chatPath && base === preset.endpoint ? { chatPath: preset.chatPath } : {}) };
|
|
273
273
|
const existing = loadSettings().models ?? [];
|
|
274
274
|
const models = [...existing.filter((m) => m.id !== id), profile];
|
|
275
275
|
saveSettings({ models });
|
|
@@ -91,7 +91,7 @@ function briefFor(task) {
|
|
|
91
91
|
* flywheel-prefix contract, _ai-docs/conventions) and the two parenthesized empty-reply notes in engine/agent.ts.
|
|
92
92
|
* Returned verbatim they would reach the planner AS the sub-agent's answer — seen live: Scout on a tool task
|
|
93
93
|
* emitted whitespace twice and the planner would have been told "(the model returned an empty response…)". */
|
|
94
|
-
const NO_ANSWER = /^\s*(\[(stopped|paused|no reply came back from the model)\b|\((the model returned an empty response|hit the output limit before an answer landed))/;
|
|
94
|
+
const NO_ANSWER = /^\s*(\[(stopped|paused|no reply came back from the model|declined by the provider)\b|\((the model returned an empty response|hit the output limit before an answer landed))/;
|
|
95
95
|
let _seq = 0;
|
|
96
96
|
const TIMED_OUT = Symbol("delegate-timeout");
|
|
97
97
|
/** Race a send against the wall-clock bound. On timeout the session is interrupted (so a cooperative turn
|
|
@@ -125,7 +125,8 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
125
125
|
// Gate BYO providers (Claude/OpenAI/Gemini/Qwen/…) on the user actually having stored that provider's key,
|
|
126
126
|
// the same check /model applies — so an unconnected provider fails fast with the actionable "store the key"
|
|
127
127
|
// error BEFORE a sub-agent session is spun up (and before setModel would refuse it anyway, more expensively).
|
|
128
|
-
|
|
128
|
+
// A key the owner stored explicitly, never an ambient vendor variable: the model picks this target, not the owner.
|
|
129
|
+
const hasByo = deps.hasByo ?? (await nodeImport("../auth/byo.js")).hasStoredByoToken;
|
|
129
130
|
const { profile, error } = selectModel(modelRegistry(settings.models), modelId, hasByo);
|
|
130
131
|
if (error || !profile)
|
|
131
132
|
return `error: delegate_task: ${error ?? `unknown model "${modelId}"`}`;
|
|
@@ -48,6 +48,7 @@ export function createAutonomySession(settings, opts = {}) {
|
|
|
48
48
|
fastStart: settings.fastStart,
|
|
49
49
|
features: settings.features, // feature flags — registers flag-gated tools (e.g. cloudAgents) only when on
|
|
50
50
|
activeModel: settings.activeModel,
|
|
51
|
+
contextPin: settings.contextPin, // the owner's /context choice (KODE_CONTEXT wins in loadSettings) holds for headless, ACP and delegated runs too
|
|
51
52
|
permissions: opts.permissions ?? settings.permissions,
|
|
52
53
|
// Audit attribution: without these every headless/cron/dream tool event carried session:"" and no seat.
|
|
53
54
|
sessionId: `hl-${randomUUID().slice(0, 12)}`,
|