@0perator/operator 0.2.1 → 0.2.2-next.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/auth/byo.js +1 -1
- package/dist/auth/commands.js +8 -2
- package/dist/autonomy/agent-cli.js +1 -1
- package/dist/autonomy/headless.js +30 -6
- package/dist/autonomy/pr-isolation.js +92 -0
- package/dist/autonomy/pr-preflight.js +474 -0
- package/dist/autonomy/session-factory.js +2 -0
- package/dist/browser/capture.js +505 -0
- package/dist/browser/engine.js +4 -3
- package/dist/browser/page-capture.js +167 -0
- package/dist/browser/png.js +116 -0
- package/dist/browser/visual-compare.js +229 -0
- package/dist/bus/beam-drop.js +55 -0
- package/dist/bus/inbox.js +7 -1
- package/dist/cli.js +126 -25
- package/dist/config/managed.js +40 -1
- package/dist/config/persona.js +51 -26
- package/dist/config/product-hosts.js +2 -0
- package/dist/config/settings.js +30 -13
- package/dist/config/skills-index.js +37 -14
- package/dist/engine/agent.js +1 -1
- package/dist/engine/aurora.js +18 -9
- package/dist/engine/continuation.js +36 -0
- package/dist/engine/identity.js +42 -0
- package/dist/engine/moa.js +7 -0
- package/dist/engine/net-error.js +15 -0
- package/dist/engine/rolling-summary.js +142 -93
- package/dist/engine/waterfall.js +33 -0
- package/dist/gateway-cli.js +10 -1
- package/dist/memory/session-index.js +3 -3
- package/dist/permissions/index.js +2 -1
- package/dist/permissions/policy.js +9 -2
- package/dist/permissions/tier.js +9 -1
- package/dist/products/craft.js +90 -1
- package/dist/products/temple.js +20 -1
- package/dist/products/voice.js +112 -0
- package/dist/router/free-models.js +5 -9
- package/dist/router/models.js +58 -14
- package/dist/router/provider-models.js +78 -0
- package/dist/router/router.js +15 -3
- package/dist/selfimprove/lessons.js +23 -0
- package/dist/session.js +192 -87
- package/dist/skills/catalogue.js +5 -2
- package/dist/skills/finder.js +4 -4
- package/dist/skills/install-guard.js +1 -1
- package/dist/tools/beam.js +246 -0
- package/dist/tools/craft.js +23 -0
- package/dist/tools/deferred.js +7 -3
- package/dist/tools/doc-text.js +1 -1
- package/dist/tools/registry.js +55 -9
- package/dist/tools/sandbox.js +6 -6
- package/dist/ui/App.js +3 -3
- package/dist/ui/ApprovalPrompt.js +1 -1
- package/dist/ui/Composer.js +44 -2
- package/dist/ui/StatusRule.js +2 -1
- package/dist/ui/Transcript.js +5 -0
- package/dist/ui/modelPicker.js +10 -6
- package/dist/ui/phase.js +4 -2
- package/dist/ui/slashCommands.js +1 -0
- package/dist/ui/voice.js +185 -0
- package/dist/update.js +1 -2
- package/dist/util/audio-io.js +82 -0
- package/dist/util/slash.js +2 -2
- package/dist/vision/pairs.js +239 -0
- package/package.json +1 -1
package/dist/config/settings.js
CHANGED
|
@@ -8,7 +8,7 @@ import { randomBytes } from "node:crypto";
|
|
|
8
8
|
import { dirname } from "node:path";
|
|
9
9
|
import { operatorPath } from "./home.js";
|
|
10
10
|
import { applyManagedPolicy, loadManagedPolicy } from "./managed.js";
|
|
11
|
-
import { MIN_CONTEXT_PIN, DEFAULT_ACTIVE_MODEL, GATEWAY_BASE, LOCAL_GATEWAY_BASE } from "../router/models.js";
|
|
11
|
+
import { MIN_CONTEXT_PIN, DEFAULT_ACTIVE_MODEL, GATEWAY_BASE, LOCAL_GATEWAY_BASE, gatewayModelFor, isRetiredAuroraBase } from "../router/models.js";
|
|
12
12
|
import { LEGACY_API_HOST, PRODUCT_API_HOST } from "./product-hosts.js";
|
|
13
13
|
/** Resolve an endpoint's bearer from config/env/secret-file (first hit wins); undefined when none set
|
|
14
14
|
* (a local/un-gated endpoint). Keeps the raw key out of settings when `apiKeyEnv`/`apiKeyFile` are used. */
|
|
@@ -42,7 +42,7 @@ const DEFAULTS = {
|
|
|
42
42
|
// Fallback literal for hosts without a running operator-runtime gateway (mobile, browser, dev).
|
|
43
43
|
// Fleet nodes with ~/.operator/runtime/server.json dynamically override this at startup via the
|
|
44
44
|
// gateway-discovery path in cli.tsx — single source of truth, enterprise-safe for both postures.
|
|
45
|
-
aurora: { base:
|
|
45
|
+
aurora: { base: LOCAL_GATEWAY_BASE.replace(/\/v1\/?$/, ""), ctxWindow: 262144, model: "main" }, // == DEFAULT_AURORA_ENDPOINT: the local router's `main`
|
|
46
46
|
// No built-in standby: a deployment names its own in settings.json (endpoints.failover — same model and the
|
|
47
47
|
// same real window as the primary, so a failover holds a live session instead of truncating it).
|
|
48
48
|
},
|
|
@@ -75,12 +75,13 @@ const DEFAULTS = {
|
|
|
75
75
|
vision: { autostart: false, launchdLabel: "co.0perator.vision", plistPath: "~/Library/LaunchAgents/co.0perator.vision.plist", legacyLabels: ["axe.vision-bot"], url: "http://127.0.0.1:7788" },
|
|
76
76
|
stopOnExit: { searxng: true }, // aurora/autopilot are shared + never stopped; only the SearXNG container is
|
|
77
77
|
},
|
|
78
|
-
// MOA (2026-
|
|
79
|
-
//
|
|
80
|
-
//
|
|
78
|
+
// MOA (2026-11-30, James): the cloud planner holds the planner + composer seat (plans, checks, writes the answer)
|
|
79
|
+
// through the gateway's planner-cloud route; the specialist is the gateway's operator-flash route = the JL1 worker,
|
|
80
|
+
// then the JL2 worker (no cloud leg). Sub-agents use the gateway's subagent pool (JL2 first, then JL1). The previous
|
|
81
|
+
// team's two routes were retired from the gateway 2026-11-30. settings.moa replaces it wholesale.
|
|
81
82
|
moa: {
|
|
82
|
-
planner: { id: "
|
|
83
|
-
specialist: { id: "
|
|
83
|
+
planner: { id: "planner-cloud", endpoint: GATEWAY_BASE, model: "planner-cloud" },
|
|
84
|
+
specialist: { id: "operator-flash" },
|
|
84
85
|
},
|
|
85
86
|
activeModel: DEFAULT_ACTIVE_MODEL, // /model default for a fresh install: the router's operator-flash route (0.1.361; was the Aurora row)
|
|
86
87
|
// Autonomy: everything conservative. keepAwake off; dream OFF and read-mostly with a board-only
|
|
@@ -502,9 +503,23 @@ const CLOUD_FAILOVERS = [
|
|
|
502
503
|
{ name: "axe-cloud", base: `https://${LEGACY_API_HOST}`, model: "main", ctxLimit: 307200, transport: "openai" },
|
|
503
504
|
];
|
|
504
505
|
/** The shipped endpoints.aurora literal (DEFAULTS) — a box that never named its own primary. */
|
|
505
|
-
const DEFAULT_AURORA_ENDPOINT =
|
|
506
|
+
const DEFAULT_AURORA_ENDPOINT = DEFAULTS.endpoints.aurora;
|
|
506
507
|
function isDefaultAuroraLiteral(e) {
|
|
507
|
-
return e.base.replace(/\/+$/, "") === DEFAULT_AURORA_ENDPOINT.base && e.
|
|
508
|
+
return e.base.replace(/\/+$/, "") === DEFAULT_AURORA_ENDPOINT.base && e.ctxWindow === DEFAULT_AURORA_ENDPOINT.ctxWindow && !e.apiKey && !e.apiKeyEnv && !e.apiKeyFile;
|
|
509
|
+
}
|
|
510
|
+
/** A saved endpoints.aurora (or failover) on the retired :8097 moves to the router's `main`, never an error. Its model
|
|
511
|
+
* id stays when the gateway serves it (operator-flash); Aurora's own ids (aurora-code-1, aurora, operator-1m) become
|
|
512
|
+
* `main`. A failover there is dropped: the cloud tier already backs the router. Pure. */
|
|
513
|
+
export function migrateRetiredAurora(s) {
|
|
514
|
+
const { aurora, failover } = s.endpoints;
|
|
515
|
+
if (!isRetiredAuroraBase(aurora.base) && !isRetiredAuroraBase(failover?.base))
|
|
516
|
+
return s;
|
|
517
|
+
const endpoints = { ...s.endpoints };
|
|
518
|
+
if (isRetiredAuroraBase(aurora.base))
|
|
519
|
+
endpoints.aurora = { ...DEFAULT_AURORA_ENDPOINT, model: gatewayModelFor(aurora.model) };
|
|
520
|
+
if (isRetiredAuroraBase(failover?.base))
|
|
521
|
+
delete endpoints.failover;
|
|
522
|
+
return { ...s, endpoints };
|
|
508
523
|
}
|
|
509
524
|
/** The local router's `main` capability (the one door, loopback): the default primary when the owner named none. */
|
|
510
525
|
const ROUTER_MAIN = { name: "main", base: LOCAL_GATEWAY_BASE.replace(/\/v1\/?$/, ""), model: "main", ctxLimit: 262144 };
|
|
@@ -538,10 +553,12 @@ export function buildEndpointChain(s) {
|
|
|
538
553
|
seen.add(key);
|
|
539
554
|
chain.push(ep);
|
|
540
555
|
};
|
|
541
|
-
// 11/25: the built-in primary is the local router's `main` capability
|
|
542
|
-
//
|
|
556
|
+
// 11/25: the built-in primary is the local router's `main` capability (or the model a migrated :8097 setting named);
|
|
557
|
+
// an owner's own endpoints.aurora (or the gateway's discovered port) stays first.
|
|
543
558
|
if (isDefaultAuroraLiteral(aurora))
|
|
544
|
-
add({ ...ROUTER_MAIN });
|
|
559
|
+
add({ ...ROUTER_MAIN, model: aurora.model });
|
|
560
|
+
else if (isRetiredAuroraBase(aurora.base))
|
|
561
|
+
add({ ...ROUTER_MAIN, model: gatewayModelFor(aurora.model) });
|
|
545
562
|
else
|
|
546
563
|
add({ name: "operator-1m", base: aurora.base, model: aurora.model, ctxLimit: aurora.ctxWindow, token: resolveEndpointApiKey(aurora), loopbackAuth: true });
|
|
547
564
|
for (const base of (s.fleet?.auroraNodes ?? []).filter(Boolean)) {
|
|
@@ -596,7 +613,7 @@ export function loadSettings() {
|
|
|
596
613
|
// structuredClone the base so a returned settings object never aliases the module-level DEFAULTS —
|
|
597
614
|
// deepMerge only recurses into keys the override touches, so an untouched nested endpoint would
|
|
598
615
|
// otherwise flow through by reference and a later mutation would corrupt defaults process-wide.
|
|
599
|
-
const merged = applyEnv(deepMerge(structuredClone(DEFAULTS), file));
|
|
616
|
+
const merged = migrateRetiredAurora(applyEnv(deepMerge(structuredClone(DEFAULTS), file)));
|
|
600
617
|
// Managed policy goes LAST: over defaults, the user's file and env. Absent file = identity function.
|
|
601
618
|
const managed = loadManagedPolicy();
|
|
602
619
|
const flywheelPinned = (isPlainObject(file) && isPlainObject(file.selfImprove) && typeof file.selfImprove.flywheel === "boolean") ||
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// renderSkillsIndex is sync so composeSystemPrompt can drop it in without going async.
|
|
4
4
|
import { get_operator_home } from "./home.js";
|
|
5
5
|
const INDEX_CAP = 4000;
|
|
6
|
-
const INDEX_DESC = 57;
|
|
7
6
|
function nodeBuiltins() {
|
|
8
7
|
try {
|
|
9
8
|
const proc = globalThis.process;
|
|
@@ -43,6 +42,33 @@ function field(fm, key) {
|
|
|
43
42
|
const m = fm.match(new RegExp(`^${key}:\\s*(.*)$`, "m"));
|
|
44
43
|
return m ? yamlScalar(m[1]) : "";
|
|
45
44
|
}
|
|
45
|
+
/** `metadata.operator.tags` from a skill's frontmatter, inline (`[a, b]`) or as a `- a` list. Skills written
|
|
46
|
+
* before the key was renamed carry `metadata.hermes`, which is read when `operator` is absent. */
|
|
47
|
+
export function skillTags(raw) {
|
|
48
|
+
const fm = frontmatter(raw);
|
|
49
|
+
const meta = fm && /^metadata:[ \t]*\r?\n((?:[ \t]+.*(?:\r?\n|$))*)/m.exec(fm)?.[1];
|
|
50
|
+
if (!meta)
|
|
51
|
+
return [];
|
|
52
|
+
for (const key of ["operator", "hermes"]) {
|
|
53
|
+
const block = new RegExp(`^([ \\t]+)${key}:[ \\t]*\\r?\\n((?:\\1[ \\t]+.*(?:\\r?\\n|$))*)`, "m").exec(meta)?.[2];
|
|
54
|
+
if (block === undefined)
|
|
55
|
+
continue;
|
|
56
|
+
const m = /^[ \t]+tags:[ \t]*(.*)$/m.exec(block);
|
|
57
|
+
if (!m)
|
|
58
|
+
return [];
|
|
59
|
+
if (m[1].trim().startsWith("["))
|
|
60
|
+
return m[1].trim().replace(/^\[|\]$/g, "").split(",").map(yamlScalar).filter(Boolean);
|
|
61
|
+
const items = [];
|
|
62
|
+
for (const line of block.slice(m.index + m[0].length).split(/\r?\n/).slice(1)) {
|
|
63
|
+
const li = /^[ \t]+-[ \t]+(.*)$/.exec(line);
|
|
64
|
+
if (!li)
|
|
65
|
+
break;
|
|
66
|
+
items.push(yamlScalar(li[1]));
|
|
67
|
+
}
|
|
68
|
+
return items.filter(Boolean);
|
|
69
|
+
}
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
46
72
|
function parseDescription(raw) {
|
|
47
73
|
const fm = frontmatter(raw);
|
|
48
74
|
if (fm) {
|
|
@@ -84,7 +110,7 @@ function readSkill(fs, file) {
|
|
|
84
110
|
catch { /* empty */ }
|
|
85
111
|
const fallback = file.replace(/\\/g, "/").split("/").pop()?.replace(/\.md$/i, "") || "skill";
|
|
86
112
|
const leaf = fallback === "SKILL" ? (file.replace(/\\/g, "/").split("/").slice(-2, -1)[0] || "skill") : fallback;
|
|
87
|
-
return { name: parseName(raw, leaf), description: parseDescription(raw) };
|
|
113
|
+
return { name: parseName(raw, leaf), description: parseDescription(raw), tags: skillTags(raw) };
|
|
88
114
|
}
|
|
89
115
|
export function listLocalSkills() {
|
|
90
116
|
const b = nodeBuiltins();
|
|
@@ -107,7 +133,7 @@ export function listLocalSkills() {
|
|
|
107
133
|
const full = b.path.join(root, ent.name);
|
|
108
134
|
if (ent.isFile() && ent.name.endsWith(".md")) {
|
|
109
135
|
const meta = readSkill(b.fs, full);
|
|
110
|
-
found.push({ name: meta.name, file: full, dir: false, description: meta.description });
|
|
136
|
+
found.push({ name: meta.name, file: full, dir: false, description: meta.description, tags: meta.tags });
|
|
111
137
|
}
|
|
112
138
|
}
|
|
113
139
|
const walk = (dir, depth) => {
|
|
@@ -127,7 +153,7 @@ export function listLocalSkills() {
|
|
|
127
153
|
const skillMd = b.path.join(full, "SKILL.md");
|
|
128
154
|
if (isFile(b.fs, skillMd)) {
|
|
129
155
|
const meta = readSkill(b.fs, skillMd);
|
|
130
|
-
found.push({ name: meta.name, file: skillMd, dir: true, root: full, description: meta.description });
|
|
156
|
+
found.push({ name: meta.name, file: skillMd, dir: true, root: full, description: meta.description, tags: meta.tags });
|
|
131
157
|
}
|
|
132
158
|
else {
|
|
133
159
|
walk(full, depth + 1);
|
|
@@ -160,20 +186,17 @@ export function resolveSkillFile(skillRoot, filePath) {
|
|
|
160
186
|
return null;
|
|
161
187
|
return target;
|
|
162
188
|
}
|
|
189
|
+
/** The installed skills' names, comma-separated, under INDEX_CAP: what each does is skill_list's answer, its body
|
|
190
|
+
* skill_fetch's (the deferred tools' split: names in the prompt, the rest on demand). */
|
|
163
191
|
export function renderSkillsIndex() {
|
|
164
|
-
const
|
|
165
|
-
if (!skills.length)
|
|
166
|
-
return "";
|
|
167
|
-
const lines = [];
|
|
192
|
+
const names = [];
|
|
168
193
|
let used = 0;
|
|
169
|
-
for (const s of
|
|
170
|
-
const
|
|
171
|
-
const line = `${s.name}: ${desc}`;
|
|
172
|
-
const next = used + line.length + (lines.length ? 1 : 0);
|
|
194
|
+
for (const s of listLocalSkills()) {
|
|
195
|
+
const next = used + s.name.length + (names.length ? 2 : 0);
|
|
173
196
|
if (next > INDEX_CAP)
|
|
174
197
|
break;
|
|
175
|
-
|
|
198
|
+
names.push(s.name);
|
|
176
199
|
used = next;
|
|
177
200
|
}
|
|
178
|
-
return
|
|
201
|
+
return names.join(", ");
|
|
179
202
|
}
|
package/dist/engine/agent.js
CHANGED
|
@@ -845,7 +845,7 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
845
845
|
const seen = legFailures.find((l) => l.model === model && l.host === host);
|
|
846
846
|
if (seen)
|
|
847
847
|
return Object.assign(seen, { cause, detail, tries: seen.tries + 1 });
|
|
848
|
-
const leg = { model, host, cause, detail, tries: 1 };
|
|
848
|
+
const leg = { model, host, cause, detail, tries: 1, role: fallback ? "backup" : "primary" };
|
|
849
849
|
legFailures.push(leg);
|
|
850
850
|
return leg;
|
|
851
851
|
};
|
package/dist/engine/aurora.js
CHANGED
|
@@ -204,6 +204,8 @@ const LOOP_MIN_LINE_LEN = 12; // ignore short/structural lines (braces, bullets,
|
|
|
204
204
|
const LOOP_LINE_REPEATS = 6; // same substantial line seen this many times => degenerate
|
|
205
205
|
const LOOP_TAIL = 260; // chars of tail scanned for a back-to-back repeating cycle
|
|
206
206
|
const LOOP_CHECK_EVERY = 200; // only run the scan every ~N new chars (cheap amortization)
|
|
207
|
+
const LOOP_SCAN_TAIL = 4000; // repeats are counted in this much of the tail: a loop piles up there, while a long
|
|
208
|
+
// round that redrafts the same code between fresh work spreads its repeats out
|
|
207
209
|
const RUNAWAY_CHARS = 120_000; // a round is capped at max_tokens (~8k => ~33k chars); far past that is a
|
|
208
210
|
// decode loop or a stream/render duplication, never a real answer — hard stop.
|
|
209
211
|
function hasAlpha(s) {
|
|
@@ -215,8 +217,9 @@ function hasAlpha(s) {
|
|
|
215
217
|
function normLoop(s) {
|
|
216
218
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
217
219
|
}
|
|
218
|
-
/** True once the accumulated text is provably looping — a
|
|
219
|
-
* a short cycle repeated
|
|
220
|
+
/** True once the accumulated text is provably looping — a substantial line or 8-word phrase repeated within the
|
|
221
|
+
* recent tail (exact OR normalized), a short cycle repeated at the very end (raw OR normalized), or a runaway past
|
|
222
|
+
* any sane single-round length. */
|
|
220
223
|
export function isDegenerate(text) {
|
|
221
224
|
if (text.length < LOOP_MIN_LINE_LEN * 3)
|
|
222
225
|
return false;
|
|
@@ -224,10 +227,11 @@ export function isDegenerate(text) {
|
|
|
224
227
|
// or a render/stream duplication. Catches the class even when the repeat isn't a clean line/cycle.
|
|
225
228
|
if (text.length > RUNAWAY_CHARS)
|
|
226
229
|
return true;
|
|
227
|
-
|
|
230
|
+
const recent = text.slice(-LOOP_SCAN_TAIL);
|
|
231
|
+
// (a) a substantial line repeated many times in the recent tail — counted both exact and fuzzy-normalized.
|
|
228
232
|
const exact = new Map();
|
|
229
233
|
const norm = new Map();
|
|
230
|
-
for (const raw of
|
|
234
|
+
for (const raw of recent.split("\n")) {
|
|
231
235
|
const line = raw.trim();
|
|
232
236
|
if (line.length < LOOP_MIN_LINE_LEN || !hasAlpha(line))
|
|
233
237
|
continue;
|
|
@@ -243,9 +247,9 @@ export function isDegenerate(text) {
|
|
|
243
247
|
norm.set(nl, nn);
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
|
-
// (c) a normalized word n-gram repeated many times
|
|
247
|
-
// that is one long line with trailing junk, so it's neither line- nor
|
|
248
|
-
const words = normLoop(
|
|
250
|
+
// (c) a normalized word n-gram repeated many times in the recent tail — catches a run-together / garbled loop
|
|
251
|
+
// that is one long line with trailing junk, so it's neither line- nor cycle-aligned.
|
|
252
|
+
const words = normLoop(recent).split(" ").filter(Boolean);
|
|
249
253
|
const N = 8;
|
|
250
254
|
if (words.length >= N * LOOP_LINE_REPEATS) {
|
|
251
255
|
const grams = new Map();
|
|
@@ -394,6 +398,11 @@ async function fetchChat(o, body) {
|
|
|
394
398
|
throw e;
|
|
395
399
|
// Only a transient transport error is retryable; a thrown fetch never carries an HTTP status, so
|
|
396
400
|
// classifyFailure returns "transient" here — but gate on it so any non-transient throw fails fast.
|
|
401
|
+
// No headers in time means the server is still queued or reading: sending the same long prompt again starts it over.
|
|
402
|
+
if (e.cause?.code === "UND_ERR_HEADERS_TIMEOUT") {
|
|
403
|
+
lastErr = e;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
397
406
|
if (classifyFailure(e) !== "transient" || attempt >= FETCH_TRIES - 1) {
|
|
398
407
|
lastErr = e;
|
|
399
408
|
break;
|
|
@@ -533,7 +542,7 @@ async function* streamDeltas(messages, o) {
|
|
|
533
542
|
const wallLeft = wallMs > 0 ? wallMs - (Date.now() - startedAt) : Infinity;
|
|
534
543
|
const budget = Math.min(idleLeft, wallLeft);
|
|
535
544
|
if (budget <= 0)
|
|
536
|
-
throw new Error("
|
|
545
|
+
throw new Error("model stream stalled — deadline exceeded before read (decode wedged; transient)");
|
|
537
546
|
let timer;
|
|
538
547
|
let raced;
|
|
539
548
|
try {
|
|
@@ -548,7 +557,7 @@ async function* streamDeltas(messages, o) {
|
|
|
548
557
|
}
|
|
549
558
|
if (raced === "timeout") {
|
|
550
559
|
void reader.cancel().catch(() => { });
|
|
551
|
-
throw new Error(`
|
|
560
|
+
throw new Error(`model stream stalled — no bytes within ${Math.round(budget / 1000)}s (decode wedged; transient)`);
|
|
552
561
|
}
|
|
553
562
|
const { value, done } = raced;
|
|
554
563
|
lastByteAt = Date.now();
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// FINAL sentence is a first-person announcement of a tool-shaped action, and never on a question, a hand-back
|
|
10
10
|
// ("let me know…"), a deferral ("…in a follow-up"), a contingency ("if that fails, I'll…"), or a summary report.
|
|
11
11
|
// Dependency-free leaf (agent.ts is also bundled for the browser).
|
|
12
|
+
import { discloseModel, shownCause, shownCauses, shownModel, sentence } from "./identity.js";
|
|
12
13
|
/** At most this many continuation nudges per turn — the model can never be forced into an unbounded turn. */
|
|
13
14
|
export const ANNOUNCE_NUDGE_MAX = 2;
|
|
14
15
|
export const ANNOUNCE_NUDGE = "You described the next action but didn't perform it — proceed now: call the tool(s) to do it.";
|
|
@@ -233,6 +234,10 @@ export function stopQuestion(kind, activeTasks) {
|
|
|
233
234
|
}
|
|
234
235
|
/** The owner's one line when the model's fallback answered this turn: what failed, why, and what answered. */
|
|
235
236
|
export function fallbackLine(o) {
|
|
237
|
+
if (!discloseModel()) {
|
|
238
|
+
const why = o.silent ? `the primary model sent ${o.silent} empty replies` : `the primary model's server is failing (${shownCauses((o.cause ?? "").split("; "))})`;
|
|
239
|
+
return `${sentence(why)} — a backup model answered this turn`;
|
|
240
|
+
}
|
|
236
241
|
const what = o.silent ? `${o.from} sent ${o.silent} empty replies` : `${o.from}'s server is failing (${o.cause})`;
|
|
237
242
|
return `${what} — ${o.to} answered this turn`;
|
|
238
243
|
}
|
|
@@ -240,6 +245,10 @@ export function fallbackLine(o) {
|
|
|
240
245
|
* answer never reads as a broken model. */
|
|
241
246
|
export function recoveryLine(s) {
|
|
242
247
|
const n = s.next;
|
|
248
|
+
if (!discloseModel()) {
|
|
249
|
+
const next = n.kind === "leg" ? "reconnecting" : n.kind === "fallback" ? "a backup model takes this turn" : `retrying in ${Math.max(1, Math.round(n.waitMs / 1000))} s`;
|
|
250
|
+
return `${sentence(shownModel(s.failed.model, s.failed.role ?? "primary"))}: ${shownCause(s.failed.cause)} — ${next}`;
|
|
251
|
+
}
|
|
243
252
|
const next = n.kind === "leg" ? `reconnecting via ${n.host}` : n.kind === "fallback" ? `${n.to} takes this turn` : `retrying in ${Math.max(1, Math.round(n.waitMs / 1000))} s`;
|
|
244
253
|
return `${s.failed.model} at ${s.failed.host}: ${s.failed.cause} — ${next}`;
|
|
245
254
|
}
|
|
@@ -250,12 +259,16 @@ export function fallbackNotice(e) {
|
|
|
250
259
|
/** Shown when the primary recovers after the session had been served from a fallback — so a degraded stretch
|
|
251
260
|
* reads as temporary, never a silent permanent downgrade. `primary` is the box that answered (x-0perator-backend). */
|
|
252
261
|
export function primaryRecoveredLine(primary) {
|
|
262
|
+
if (!discloseModel())
|
|
263
|
+
return "✓ The primary model is back — answers are served from it again";
|
|
253
264
|
return `✓ ${primary} is back — answers are served from it again`;
|
|
254
265
|
}
|
|
255
266
|
/** A turn nothing answered — every leg of the owner's model and of its fallback failed, or finished with nothing in the
|
|
256
267
|
* reply: each leg's cause in the order tried, and what the next turn does. `note` stays in history (the next turn's model
|
|
257
268
|
* reads it; the result's stopKind is "unanswered"); `display` is what the owner reads. Never "want me to try again?". */
|
|
258
269
|
export function noAnswer(o) {
|
|
270
|
+
if (!discloseModel())
|
|
271
|
+
return neutralNoAnswer(o);
|
|
259
272
|
const legs = o.tried.map((l) => {
|
|
260
273
|
const more = [l.detail, l.tries > 1 ? `${l.tries} tries` : undefined].filter(Boolean);
|
|
261
274
|
return `- ${l.model} at ${l.host}: ${l.cause}${more.length ? ` (${more.join(", ")})` : ""}`;
|
|
@@ -267,6 +280,29 @@ export function noAnswer(o) {
|
|
|
267
280
|
display: `Nothing answered this turn. I tried, in order:\n${legs}\n${next}${tasks}`,
|
|
268
281
|
};
|
|
269
282
|
}
|
|
283
|
+
/** noAnswer with the serving model confidential: each role's causes, without hosts, upstream ids or a server's words.
|
|
284
|
+
* The note stays neutral too: the next turn's model reads it. */
|
|
285
|
+
function neutralNoAnswer(o) {
|
|
286
|
+
const byLine = new Map();
|
|
287
|
+
for (const l of o.tried) {
|
|
288
|
+
const line = `- ${shownModel(l.model, l.role ?? "primary")}: ${shownCause(l.cause)}`;
|
|
289
|
+
byLine.set(line, (byLine.get(line) ?? 0) + l.tries);
|
|
290
|
+
}
|
|
291
|
+
const legs = [...byLine].map(([line, tries]) => (tries > 1 ? `${line} (${tries} tries)` : line)).join("\n");
|
|
292
|
+
const next = `Next: the next turn tries the primary model first again${o.fallback ? ", then a backup model" : ""}.`;
|
|
293
|
+
const tasks = tasksBlock(o.tasks);
|
|
294
|
+
return {
|
|
295
|
+
note: `[no answer — nothing answered this turn. Tried, in order:\n${legs}\n${next}]${tasks}`,
|
|
296
|
+
display: `Nothing answered this turn. I tried, in order:\n${legs}\n${next}${tasks}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** The TUI's line when a gateway answered from another box (AgentOpts.onServed, x-0perator-fallback): the selected
|
|
300
|
+
* model is down and another is replying under its name. */
|
|
301
|
+
export function gatewayFallbackLine(o) {
|
|
302
|
+
if (!discloseModel())
|
|
303
|
+
return "⚠ The selected model is unavailable — this answer came from a backup model (gateway fallback)";
|
|
304
|
+
return `⚠ ${o.from} is unavailable — this answer came from ${o.backend ?? "another backend"} (gateway fallback)`;
|
|
305
|
+
}
|
|
270
306
|
/** Append the active task list and a steer to an engine stop note. A yield (sub-agents will resume the turn) gets its
|
|
271
307
|
* own steer: the owner can always take the delegated work back. */
|
|
272
308
|
export function closeStopNote(note, activeTasks, kind) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// How model, leg and host identity reads in text a user sees (2026-11-30-neutral-harness-names). The serving model is
|
|
2
|
+
// confidential unless the owner opted in (settings.identity.discloseModel → KODE_DISCLOSE_MODEL=1): then every formatter
|
|
3
|
+
// here returns its input unchanged. Otherwise a model reads as a role, a host or a box is left out, and a server's own
|
|
4
|
+
// words become a short cause. Telemetry, events.jsonl and the audit keep the real names; only user-facing text comes
|
|
5
|
+
// through here. Dependency-free leaf (agent.ts is also bundled for the browser).
|
|
6
|
+
export const BRAND = "Operator";
|
|
7
|
+
export function discloseModel() {
|
|
8
|
+
return globalThis.process?.env?.KODE_DISCLOSE_MODEL === "1";
|
|
9
|
+
}
|
|
10
|
+
const ROLE = { primary: "the primary model", backup: "a backup model", selected: "the selected model" };
|
|
11
|
+
/** A model named in a sentence: its name when disclosed, else its role ("the primary model"). */
|
|
12
|
+
export function shownModel(name, role) {
|
|
13
|
+
return discloseModel() ? name : ROLE[role];
|
|
14
|
+
}
|
|
15
|
+
/** The model on the status line, the phase line and receipts: its label when disclosed, else the brand. */
|
|
16
|
+
export function shownModelLabel(label) {
|
|
17
|
+
return discloseModel() ? label : BRAND;
|
|
18
|
+
}
|
|
19
|
+
/** A failure's cause as a user reads it: the full cause when disclosed (it may carry a box, an upstream id or a
|
|
20
|
+
* router's error body), else one of busy, timed out, unavailable, empty reply or server error. */
|
|
21
|
+
export function shownCause(cause) {
|
|
22
|
+
return discloseModel() ? cause : neutralCause(cause);
|
|
23
|
+
}
|
|
24
|
+
export function neutralCause(cause) {
|
|
25
|
+
if (/nothing in them|empty repl|no content/i.test(cause))
|
|
26
|
+
return "empty reply";
|
|
27
|
+
if (/busy|maxInflight|\b429\b|rate.?limit|overloaded|capacity|too many/i.test(cause))
|
|
28
|
+
return "busy";
|
|
29
|
+
if (/timed? ?out|timeout|stall|too slow|no response/i.test(cause))
|
|
30
|
+
return "timed out";
|
|
31
|
+
if (/refused|not found|unreachable|DNS|reset|dropped|\b50[234]\b|\b404\b|unavailable|\bdown\b|loading|offline|closed/i.test(cause))
|
|
32
|
+
return "unavailable";
|
|
33
|
+
return "server error";
|
|
34
|
+
}
|
|
35
|
+
/** Several legs' causes as one: each shown, without repeats ("busy; timed out"). */
|
|
36
|
+
export function shownCauses(causes) {
|
|
37
|
+
return [...new Set(causes.filter(Boolean).map(shownCause))].join("; ");
|
|
38
|
+
}
|
|
39
|
+
/** Capitalize the first letter: a role opens a sentence ("The primary model's server…"). */
|
|
40
|
+
export function sentence(s) {
|
|
41
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
42
|
+
}
|
package/dist/engine/moa.js
CHANGED
|
@@ -19,6 +19,12 @@ const CODEACT_LINES = [
|
|
|
19
19
|
" call per item. Never for edits, commits, pushes, network or messages: those stay normal steps. A step the check",
|
|
20
20
|
" refuses runs on tools and the report says why.",
|
|
21
21
|
];
|
|
22
|
+
/** The external lane's lines in the brief (Waterfall teams): steps that need the open web go to a remote agent. */
|
|
23
|
+
const EXTERNAL_LINES = [
|
|
24
|
+
"- A step that needs the live web, a browser, an outside site or long outside research: delegate_task it with model",
|
|
25
|
+
" \"external-executor\" (a remote agent with its own browser and sandbox). It takes minutes and is metered: only when",
|
|
26
|
+
" the open web is required, never for repo, file or fleet work, and give it the full context it needs.",
|
|
27
|
+
];
|
|
22
28
|
/** The planner's standing brief. Identical every turn for a given team, so it stays in the prompt cache. */
|
|
23
29
|
export function plannerBrief(team) {
|
|
24
30
|
if (team.prompt)
|
|
@@ -37,6 +43,7 @@ export function plannerBrief(team) {
|
|
|
37
43
|
" as many as it has free lanes; a brief it hands back, do yourself. Keep decisions, edits and the synthesis here.",
|
|
38
44
|
"- No fan-out for one step, a step quicker than ~20 s inline, or a chain where each step needs the last.",
|
|
39
45
|
...(team.codeact ? CODEACT_LINES : []),
|
|
46
|
+
...(team.external ? EXTERNAL_LINES : []),
|
|
40
47
|
"- Do yourself: a single quick tool call, anything that needs reading an image (only you read images), and the final",
|
|
41
48
|
" answer.",
|
|
42
49
|
"- Check every report before marking the step done (task_update); fix or redo a wrong one instead of passing it on.",
|
package/dist/engine/net-error.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// unreachable. For network-level failures (the request never got an HTTP answer) this appends the active
|
|
3
3
|
// model's label and the endpoint hosts that were tried, plus the one action that helps. The original message is
|
|
4
4
|
// never swallowed, and any other error renders exactly as before.
|
|
5
|
+
import { discloseModel, neutralCause } from "./identity.js";
|
|
5
6
|
const NET_RE = /fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|socket hang up|network (?:error|request failed)/i;
|
|
7
|
+
const SERVER_RE = /\bHTTP \d{3}\b|backend|upstream|maxInflight/i;
|
|
6
8
|
export function isNetworkFailure(message) {
|
|
7
9
|
return NET_RE.test(message);
|
|
8
10
|
}
|
|
@@ -15,7 +17,20 @@ export function hostOf(base) {
|
|
|
15
17
|
return base.replace(/^https?:\/\//, "").replace(/\/.*$/, "");
|
|
16
18
|
}
|
|
17
19
|
}
|
|
20
|
+
/** An error message as a user reads it. With the serving model confidential, a network failure or a server's error
|
|
21
|
+
* (a router's body names legs, upstreams and boxes) becomes one neutral phrase; anything else is unchanged. */
|
|
22
|
+
export function shownFailure(message) {
|
|
23
|
+
if (discloseModel())
|
|
24
|
+
return message;
|
|
25
|
+
if (isNetworkFailure(message))
|
|
26
|
+
return "the model's server is unreachable";
|
|
27
|
+
if (SERVER_RE.test(message))
|
|
28
|
+
return `the model's server failed (${neutralCause(message)})`;
|
|
29
|
+
return message;
|
|
30
|
+
}
|
|
18
31
|
export function describeTurnError(message, ctx = {}) {
|
|
32
|
+
if (shownFailure(message) !== message)
|
|
33
|
+
return `[turn error: ${shownFailure(message)}; /model to switch]`;
|
|
19
34
|
if (!isNetworkFailure(message))
|
|
20
35
|
return `[turn error: ${message}]`;
|
|
21
36
|
const hosts = [...new Set((ctx.bases ?? []).map(hostOf))];
|