@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/dist/router/models.js
CHANGED
|
@@ -10,6 +10,25 @@ export const MODEL_ALIASES = {
|
|
|
10
10
|
export const BUILTIN_MODELS = [
|
|
11
11
|
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
12
|
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
+
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
+
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
+
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
+
// to the served truth (observeContext).
|
|
17
|
+
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
+
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
+
// Ghost 32B — self-hosted ABLITERATED Qwen3-VL-32B (Huihui, Q4_K_M) served via llama.cpp on JL1:8101 at
|
|
20
|
+
// 128K ctx, bound 0.0.0.0 for LAN. Uncensored at the weights + vision-capable; a 300K-class alternative to
|
|
21
|
+
// Aurora for side-by-side testing. Replaced the held venice-24b — JL1's 64G can't host a 24B + a 32B + Aurora
|
|
22
|
+
// warm at once (the 32B's 128K KV OOM-killed Venice), so one small/mid model shares the box with Aurora.
|
|
23
|
+
// 128K ctx ≥ LEAN_HARNESS_CTX → full harness + cache-safe same-endpoint compaction. (venice-24b: re-add when
|
|
24
|
+
// JL1 RAM frees or Venice lands on another node.)
|
|
25
|
+
{ id: "ghost-32b", label: "Ghost 32B (abliterated)", kind: "single", desc: "self-hosted abliterated Qwen3-VL-32B, 128K ctx (fleet llama.cpp, JL1:8101)", endpoint: "http://192.168.1.103:8101/v1", model: "/Users/home/models/qwen3-vl-32b-operatorx/Huihui-Qwen3-VL-32B-Instruct-abliterated.Q4_K_M.gguf", ctx: 131072 },
|
|
26
|
+
// Qwen3-4B — fast LOCAL tier (stock qwen3-4b-mlx-q4, 2.26GB MLX 4-bit, ctx 40960) served via mlx_lm.server
|
|
27
|
+
// on JL1:8110. Qwen3 vocab (151936) — the same family as ghost-32b, so it's the review-recommended quick tier
|
|
28
|
+
// AND the vocab lineage for ghost spec-decode (the actual draft is Qwen3-0.6B, too small to list here). Runs
|
|
29
|
+
// /no_think for speed. Picked (2026-10-07) from a fleet-wide 3B-class review; no 3B had been execution-graded,
|
|
30
|
+
// so this is the evidence-led default pending a dyno/coding-eval bench. 40960 ≥ LEAN_HARNESS_CTX → full harness.
|
|
31
|
+
{ id: "scout", label: "Scout", kind: "single", desc: "fast local tier — Qwen3-4B /no_think, Qwen3 vocab (JL1:8110, MLX 4-bit)", endpoint: "http://192.168.1.103:8110/v1", model: "/Volumes/Ai Storage/axe-models/qwen3-4b-mlx-q4", ctx: 32000 },
|
|
13
32
|
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
14
33
|
];
|
|
15
34
|
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
@@ -26,17 +45,39 @@ export function findModel(registry, id) {
|
|
|
26
45
|
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
27
46
|
return registry.find((m) => m.id === canon);
|
|
28
47
|
}
|
|
48
|
+
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
49
|
+
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
50
|
+
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
51
|
+
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
52
|
+
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
53
|
+
export function modelCtxFor(id, overrides) {
|
|
54
|
+
if (!id)
|
|
55
|
+
return Number.POSITIVE_INFINITY;
|
|
56
|
+
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
57
|
+
}
|
|
58
|
+
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
59
|
+
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
60
|
+
export const LEAN_HARNESS_CTX = 32768;
|
|
29
61
|
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
30
62
|
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
31
|
-
* which this module intentionally doesn't import).
|
|
32
|
-
|
|
63
|
+
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
64
|
+
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
65
|
+
export function selectModel(registry, id, hasByo) {
|
|
33
66
|
const profile = findModel(registry, id);
|
|
34
67
|
if (!profile)
|
|
35
68
|
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
36
69
|
if (profile.kind === "single" && !profile.endpoint)
|
|
37
70
|
return { error: `model "${id}" has no endpoint configured` };
|
|
71
|
+
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
72
|
+
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
73
|
+
}
|
|
38
74
|
return { profile };
|
|
39
75
|
}
|
|
76
|
+
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
77
|
+
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
78
|
+
export function visibleModels(registry, hasByo) {
|
|
79
|
+
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
80
|
+
}
|
|
40
81
|
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
41
82
|
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
42
83
|
export function endpointBase(endpoint) {
|
package/dist/session.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { runTurn, TurnAbortedError } from "./engine/agent.js";
|
|
5
5
|
import { Conversation } from "./engine/messages.js";
|
|
6
6
|
import { chat, health } from "./engine/aurora.js";
|
|
7
|
-
import { compact, fitToWindow, turnStarts, SUMMARY_INSTRUCTION, stripTrailingOrphanToolCall, pickSummaryContent } from "./engine/compaction.js";
|
|
7
|
+
import { compact, fitToWindow, turnStarts, SUMMARY_INSTRUCTION, stripTrailingOrphanToolCall, pickSummaryContent, renderAnchorIndex, verbatimUserTail, applyAnchorVerification } from "./engine/compaction.js";
|
|
8
8
|
import { globalTokenMeter, endpointKey } from "./engine/token-meter.js";
|
|
9
9
|
import { spillToolOutput } from "./tools/tool-output-spill.js"; // GW-10-COMPLETE: node-side spill sink
|
|
10
10
|
import { engineRouter } from "./engine/router-adapter.js";
|
|
@@ -14,7 +14,8 @@ import { homedir } from "node:os";
|
|
|
14
14
|
import { fanOutProposers, labelDrafts, DEFAULT_AGGREGATOR_PROMPT } from "./engine/moa.js";
|
|
15
15
|
import { AuroraRouter } from "./router/router.js";
|
|
16
16
|
import { operatorAgentPersona } from "./config/operator-harness.js";
|
|
17
|
-
import { modelRegistry, findModel, selectModel, endpointBase, DEFAULT_MODEL_ID } from "./router/models.js";
|
|
17
|
+
import { modelRegistry, findModel, selectModel, visibleModels, endpointBase, DEFAULT_MODEL_ID, LEAN_HARNESS_CTX } from "./router/models.js";
|
|
18
|
+
import { getByoToken, hasByoToken } from "./auth/byo.js";
|
|
18
19
|
import { Executor } from "./tools/executor.js";
|
|
19
20
|
import { toSchemas, registry, disposeShellSessionKey } from "./tools/registry.js";
|
|
20
21
|
import { MemoryStore } from "./memory/index.js";
|
|
@@ -24,6 +25,26 @@ import { Telemetry } from "./observability/index.js";
|
|
|
24
25
|
import { runSelfImprove } from "./selfimprove/index.js";
|
|
25
26
|
import { RollingSummarizer } from "./engine/rolling-summary.js";
|
|
26
27
|
import { createSleepScheduler } from "./consolidation/scheduler.js";
|
|
28
|
+
/** The system-prompt directive for an extended-reasoning mode ("" when off). The owner watches the model's
|
|
29
|
+
* reasoning stream live (dim, above the answer) and re-reads it in scrollback, so /think asks the model to
|
|
30
|
+
* EXPOSE its thinking as readable copy — options weighed, why one won, tradeoffs, the plan — at roughly 2-3× the
|
|
31
|
+
* detail of a terse chain of thought. Plain /think is enough; ultrathink only adds depth on top. */
|
|
32
|
+
export function thinkDirective(mode) {
|
|
33
|
+
if (mode === "off")
|
|
34
|
+
return "";
|
|
35
|
+
const think = `\n\n## THINK (active)\nYour reasoning is shown to the owner as you work, so write it as ` +
|
|
36
|
+
`readable thinking, not shorthand. Before you act, lay out: what you understand the task to be; the real ` +
|
|
37
|
+
`options you weighed (at least two whenever a choice exists) and what each would cost; WHY you chose the one ` +
|
|
38
|
+
`you did, and what would change your mind; the risks and edge cases you are guarding against; and your plan as ` +
|
|
39
|
+
`the concrete next steps. Between tool calls, say what the last result told you and what you will do next. ` +
|
|
40
|
+
`Give roughly two to three times the detail of a terse chain of thought — complete sentences, concrete names ` +
|
|
41
|
+
`(files, functions, commands), no filler.`;
|
|
42
|
+
if (mode === "think")
|
|
43
|
+
return think;
|
|
44
|
+
return think + `\n\n## ULTRATHINK (active)\nThink exhaustively before answering: reason step by step ` +
|
|
45
|
+
`through the whole problem, surface assumptions, weigh alternatives and edge cases, and check your ` +
|
|
46
|
+
`own work — then give the answer. Depth over speed for this turn.`;
|
|
47
|
+
}
|
|
27
48
|
// The `spawn_agent` tool — a thin pass-through to the shell's delegate handler. The handler owns the
|
|
28
49
|
// policy (cap) and the reply text; the tool just guards against an empty task. safe:false so it's an
|
|
29
50
|
// action (gated when permissions are on), never run speculatively in the safe-parallel batch.
|
|
@@ -213,10 +234,11 @@ export class Session {
|
|
|
213
234
|
eventActor;
|
|
214
235
|
sessionId;
|
|
215
236
|
mcpSchemas = []; // merged in after first-turn discovery (empty until then)
|
|
216
|
-
wantMcp;
|
|
237
|
+
wantMcp; // mutable: `/mcp on` flips it for the live session (enableMcp)
|
|
217
238
|
systemPrompt;
|
|
218
239
|
maxTokens;
|
|
219
240
|
maxTurnTokens;
|
|
241
|
+
maxTurnWallClockMs;
|
|
220
242
|
maxRounds;
|
|
221
243
|
maxRoundsHard;
|
|
222
244
|
compactionThreshold;
|
|
@@ -234,10 +256,13 @@ export class Session {
|
|
|
234
256
|
// Rolling summarizer — instant compaction (Engine doc #2). A background process continuously
|
|
235
257
|
// maintains a structured session-memory/summary.md during the session. When compact() fires,
|
|
236
258
|
// it loads the pre-written summary — /compact went from up to 2 minutes to instant.
|
|
237
|
-
rollingSummarizer
|
|
259
|
+
rollingSummarizer;
|
|
238
260
|
// Sleep-time consolidation scheduler — triggers memory reorganization during idle (Engine doc #1).
|
|
239
261
|
sleepScheduler = null;
|
|
240
262
|
constructor(cfg = {}) {
|
|
263
|
+
if (cfg.thinkMode)
|
|
264
|
+
this.thinkMode = cfg.thinkMode;
|
|
265
|
+
this.rollingSummarizer = new RollingSummarizer(cfg.rollingSummaryPath ? { summaryPath: cfg.rollingSummaryPath } : {});
|
|
241
266
|
// Calibration durability (SPEC §5, token-meter): learned chars/token persist beside the operator
|
|
242
267
|
// state dir, so the FIRST deep session after a restart already sizes correctly instead of running
|
|
243
268
|
// on the cold prior. Best-effort by construction: a no-op off node, a cold start on corrupt/missing.
|
|
@@ -275,6 +300,7 @@ export class Session {
|
|
|
275
300
|
this.systemPrompt = cfg.systemPrompt;
|
|
276
301
|
this.maxTokens = cfg.maxTokens ?? 2048;
|
|
277
302
|
this.maxTurnTokens = cfg.maxTurnTokens;
|
|
303
|
+
this.maxTurnWallClockMs = cfg.maxTurnWallClockMs;
|
|
278
304
|
this.maxRounds = cfg.maxRounds;
|
|
279
305
|
this.maxRoundsHard = cfg.maxRoundsHard;
|
|
280
306
|
this.compactionThreshold = cfg.compactionThreshold;
|
|
@@ -324,16 +350,13 @@ export class Session {
|
|
|
324
350
|
`(/plan) to let you execute.`;
|
|
325
351
|
return (base ?? "") + plan;
|
|
326
352
|
}
|
|
327
|
-
/** The system prompt with the
|
|
328
|
-
*
|
|
353
|
+
/** The system prompt with the think directive appended when extended reasoning is on. /think enables the
|
|
354
|
+
* model's native reasoning AND asks it to write that reasoning as readable copy (see thinkDirective);
|
|
355
|
+
* ultrathink adds the exhaustive push on top. */
|
|
329
356
|
sysWithThink() {
|
|
330
357
|
const base = this.sys();
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const push = `\n\n## ULTRATHINK (active)\nThink exhaustively before answering: reason step by step ` +
|
|
334
|
-
`through the whole problem, surface assumptions, weigh alternatives and edge cases, and check your ` +
|
|
335
|
-
`own work — then give the answer. Depth over speed for this turn.`;
|
|
336
|
-
return (base ?? "") + push;
|
|
358
|
+
const push = thinkDirective(this.thinkMode);
|
|
359
|
+
return push ? (base ?? "") + push : base;
|
|
337
360
|
}
|
|
338
361
|
/** Compose the tool executor: local tools + MCP (composite) with the permission/audit layer on top.
|
|
339
362
|
* withPermissions returns the composite UNCHANGED when the policy is inert (bypass) — zero overhead.
|
|
@@ -443,16 +466,32 @@ export class Session {
|
|
|
443
466
|
// then compact() uses it as the evicted span's replacement.
|
|
444
467
|
const prewritten = this.rollingSummarizer.getSummary();
|
|
445
468
|
if (prewritten) {
|
|
446
|
-
const summaryMsg = {
|
|
447
|
-
role: "user",
|
|
448
|
-
content: `[Compacted summary (pre-written — instant)]:\n${prewritten}`,
|
|
449
|
-
};
|
|
450
469
|
const starts = turnStarts(this.convo.all);
|
|
451
470
|
const minKeep = opts.minKeepTurns ?? 4;
|
|
452
|
-
|
|
471
|
+
// GW-27-U2 STALENESS GATE (the silent-loss fix). The pre-written summary is trustworthy ONLY
|
|
472
|
+
// if (a) it isn't dirty (no threshold crossing since the fire) AND (b) its watermark covers
|
|
473
|
+
// every turn the cut would evict — i.e. coverage >= starts.length - minKeep. Turns added
|
|
474
|
+
// AFTER the fire but below the rolling threshold were previously dropped with zero trace:
|
|
475
|
+
// quiet turns (< the 5000-token cadence) accumulate uncovered, and /compact swapped in a
|
|
476
|
+
// summary that predates them. Uncovered => fall through to the live path (compact() skips on
|
|
477
|
+
// summarize failure rather than destroying the span, and fitToWindow OFFLOADS via GW-10 spill
|
|
478
|
+
// — lossless in both branches).
|
|
479
|
+
const covered = this.rollingSummarizer.getCoveredThrough();
|
|
480
|
+
const trustworthy = !this.rollingSummarizer.isStale() && starts.length > minKeep && covered >= starts.length - minKeep;
|
|
481
|
+
if (trustworthy) {
|
|
453
482
|
const cutIndex = starts[starts.length - minKeep];
|
|
483
|
+
const evicted = this.convo.all.slice(0, cutIndex);
|
|
484
|
+
// H2 (audit-engine §2): the instant path used to insert the raw pre-written blob — skipping
|
|
485
|
+
// the GW-31/N1 backstop the auto-favored path EXISTS to guarantee. Coverage proved it knows
|
|
486
|
+
// about these turns; now it also carries their anchors and the user's own words. All
|
|
487
|
+
// render-side and mechanical — the "instant" property is untouched (microseconds, zero calls).
|
|
488
|
+
const summaryMsg = {
|
|
489
|
+
role: "user",
|
|
490
|
+
content: `[Compacted summary (pre-written — instant)]:\n${prewritten}${renderAnchorIndex(evicted)}${verbatimUserTail(evicted)}`,
|
|
491
|
+
};
|
|
454
492
|
const kept = this.convo.all.slice(cutIndex);
|
|
455
493
|
this.convo.replaceAll([summaryMsg, ...kept]);
|
|
494
|
+
applyAnchorVerification(summaryMsg, evicted, this.convo.all);
|
|
456
495
|
const before = this.requestEstimate();
|
|
457
496
|
this.convo.replaceAll(fitToWindow(this.convo.all, opts));
|
|
458
497
|
return Math.max(0, before - this.requestEstimate());
|
|
@@ -474,7 +513,7 @@ export class Session {
|
|
|
474
513
|
// Start the scheduler if not already enabled
|
|
475
514
|
const sleepEnabled = process.env.KODE_SLEEP_CONSOLIDATION === "1";
|
|
476
515
|
if (!sleepEnabled)
|
|
477
|
-
return { lessonsExtracted: 0, lessonsPersisted: 0, memoryDeduped: 0, error: "consolidation disabled —
|
|
516
|
+
return { lessonsExtracted: 0, lessonsPersisted: 0, memoryDeduped: 0, error: "consolidation disabled — enable autonomy.sleepConsolidation in settings" };
|
|
478
517
|
this.sleepScheduler = createSleepScheduler({
|
|
479
518
|
consolidation: { enabled: true, idleThresholdSec: 30, stepsBetweenPasses: 10, modelTier: "fast" },
|
|
480
519
|
});
|
|
@@ -495,9 +534,10 @@ export class Session {
|
|
|
495
534
|
return this.inner.currentName();
|
|
496
535
|
}
|
|
497
536
|
/** All model profiles the owner can pick between (/model) — built-ins plus any settings.models
|
|
498
|
-
* overrides passed in at construction.
|
|
537
|
+
* overrides passed in at construction. BYO connectors appear ONLY when their vendor key is
|
|
538
|
+
* connected (SPEC/providers.md §1 "Honest availability": the picker shows what can actually run). */
|
|
499
539
|
modelRegistry() {
|
|
500
|
-
return this.registry;
|
|
540
|
+
return visibleModels(this.registry, hasByoToken);
|
|
501
541
|
}
|
|
502
542
|
/** The active /model selection (id), for the status line + persistence. */
|
|
503
543
|
currentModel() {
|
|
@@ -509,14 +549,17 @@ export class Session {
|
|
|
509
549
|
* error instead of throwing, so the shell can show it inline: an unknown id, or "moa" selected
|
|
510
550
|
* with no settings.moa configured. */
|
|
511
551
|
setModel(id) {
|
|
512
|
-
const { profile, error } = selectModel(this.registry, id);
|
|
552
|
+
const { profile, error } = selectModel(this.registry, id, hasByoToken);
|
|
513
553
|
if (error || !profile)
|
|
514
554
|
return { ok: false, error };
|
|
515
555
|
if (profile.kind === "orchestrated" && !this.moaConfig?.proposers?.length) {
|
|
516
556
|
return { ok: false, error: `MOA needs a "moa" block (proposers + aggregator) in settings.json — see MOA-DESIGN.md` };
|
|
517
557
|
}
|
|
518
558
|
if (profile.kind === "single" && profile.endpoint) {
|
|
519
|
-
|
|
559
|
+
// BYO connectors carry their vendor bearer (never the Operator token — see authHeaders scoping);
|
|
560
|
+
// selectModel already refused the id if the key is not connected, so resolution can't miss here.
|
|
561
|
+
const token = profile.byo ? getByoToken(profile.byo) : undefined;
|
|
562
|
+
this.inner = new AuroraRouter([{ name: profile.id, base: endpointBase(profile.endpoint), model: profile.model ?? profile.id, ctxLimit: profile.ctx ?? this.inner.ctxLimit(), token, transport: profile.transport }]);
|
|
520
563
|
this.router = engineRouter(this.inner);
|
|
521
564
|
}
|
|
522
565
|
this.modelId = profile.id;
|
|
@@ -561,9 +604,24 @@ export class Session {
|
|
|
561
604
|
...stripTrailingOrphanToolCall(span),
|
|
562
605
|
{ role: "user", content: SUMMARY_INSTRUCTION },
|
|
563
606
|
];
|
|
607
|
+
// A small-context active model (e.g. a self-hosted 8K Venice) can't summarize its OWN overflow — the
|
|
608
|
+
// [system + tools + span] summarize request itself exceeds the window, so compaction frees nothing and
|
|
609
|
+
// the session walls ("compaction can't free enough space"). Route the summarizer to the large-context
|
|
610
|
+
// DEFAULT (Aurora/operator-1m, 300K) instead: it loses the live-turn's prefix-cache reuse (Aurora's
|
|
611
|
+
// prefix differs from the small model's), but that trade is what lets a small model compact continuously
|
|
612
|
+
// and run autonomously for hours. A large active model keeps the cache-safe same-endpoint path.
|
|
613
|
+
let sumBase = this.lastBase ?? this.inner.base;
|
|
614
|
+
let sumModel = this.lastModel ?? this.inner.model;
|
|
615
|
+
if (this.inner.ctxLimit() < LEAN_HARNESS_CTX) {
|
|
616
|
+
const big = findModel(this.registry, DEFAULT_MODEL_ID);
|
|
617
|
+
if (big?.endpoint) {
|
|
618
|
+
sumBase = endpointBase(big.endpoint);
|
|
619
|
+
sumModel = big.model ?? big.id;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
564
622
|
const r = await chat(messages, {
|
|
565
|
-
base:
|
|
566
|
-
model:
|
|
623
|
+
base: sumBase, // small-ctx active model → large default (Aurora) summarizes; else the live endpoint (cache-safe)
|
|
624
|
+
model: sumModel,
|
|
567
625
|
tools: this.allSchemas(), // identical tools → the span prefix-matches the live turn's cached KV
|
|
568
626
|
maxTokens: SUMMARY_MAX_TOKENS,
|
|
569
627
|
temperature: 0,
|
|
@@ -617,7 +675,9 @@ export class Session {
|
|
|
617
675
|
const summaryText = await this.summarize(this.convo.all);
|
|
618
676
|
if (summaryText) {
|
|
619
677
|
this.rollingSummarizer.setSummary(summaryText);
|
|
620
|
-
|
|
678
|
+
// GW-27-U2: record coverage — the summary spans the conversation AS OF NOW, so /compact
|
|
679
|
+
// may trust it only while the eviction cut stays inside this watermark.
|
|
680
|
+
this.rollingSummarizer.markSummaryFired(turnStarts(this.convo.all).length);
|
|
621
681
|
}
|
|
622
682
|
}
|
|
623
683
|
catch { /* best-effort — rolling summary never blocks a turn */ }
|
|
@@ -637,18 +697,30 @@ export class Session {
|
|
|
637
697
|
this.recallBlock = "";
|
|
638
698
|
}
|
|
639
699
|
}
|
|
640
|
-
if (this.wantMcp)
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
this.
|
|
649
|
-
|
|
650
|
-
|
|
700
|
+
if (this.wantMcp)
|
|
701
|
+
await this.discoverMcp();
|
|
702
|
+
}
|
|
703
|
+
/** Build the MCP hub (from the owned-MCP registry unless one was injected) and discover its tools, then rebind
|
|
704
|
+
* dispatch + schemas. Best-effort — an unreachable gateway leaves the session local-only. */
|
|
705
|
+
async discoverMcp() {
|
|
706
|
+
try {
|
|
707
|
+
if (!this.hub)
|
|
708
|
+
this.hub = await McpHub.fromConfig();
|
|
709
|
+
if (!this.hub)
|
|
710
|
+
return;
|
|
711
|
+
this.hub.spillSink = spillToolOutput; // GW-10-COMPLETE: MCP offload
|
|
712
|
+
await this.hub.discover();
|
|
713
|
+
this.tools = this.buildTools(); // rebind so dispatch sees the discovered tools
|
|
714
|
+
this.mcpSchemas = this.hub.schemas();
|
|
651
715
|
}
|
|
716
|
+
catch { /* gateway unreachable — stay local-only */ }
|
|
717
|
+
}
|
|
718
|
+
/** `/mcp on`: switch the fleet MCP layer on for THIS session without a restart (the first-turn path in
|
|
719
|
+
* maybeRecall does the same discovery). Returns how many tools are now available (0 if the gateway is down). */
|
|
720
|
+
async enableMcp() {
|
|
721
|
+
this.wantMcp = true;
|
|
722
|
+
await this.discoverMcp();
|
|
723
|
+
return this.mcpToolCount();
|
|
652
724
|
}
|
|
653
725
|
/** Local registry schemas plus any fleet MCP tool schemas discovered this session. */
|
|
654
726
|
allSchemas() {
|
|
@@ -767,6 +839,7 @@ export class Session {
|
|
|
767
839
|
background: this.background, // endpoint gate: a sub-agent's rounds yield the shared slot to the main turn
|
|
768
840
|
maxTokens: this.maxTokens,
|
|
769
841
|
maxTurnTokens: this.maxTurnTokens, // opt-in per-turn cost ceiling (total tokens); undefined → no cap
|
|
842
|
+
maxTurnWallClockMs: this.maxTurnWallClockMs, // opt-in per-turn TIME ceiling; the brake on hour-long crawling turns
|
|
770
843
|
maxRounds: this.maxRounds, // soft round budget from settings.maxRounds (undefined → runTurn default)
|
|
771
844
|
maxRoundsHard: this.maxRoundsHard, // absolute ceiling; undefined → runTurn default 400, tighter for bg sub-agents
|
|
772
845
|
compactionThreshold: this.compactionThreshold, // settings.compaction.threshold; undefined → runTurn default 0.85
|
|
@@ -788,6 +861,10 @@ export class Session {
|
|
|
788
861
|
// reminder round when a turn changed files but ran no passing check. Every surface routes through
|
|
789
862
|
// here, so the gate is uniform across CLI, web/RC, headless, and loop turns.
|
|
790
863
|
verifyGate: { enabled: process.env.KODE_VERIFY_GATE !== "0", maxNudges: Number(process.env.KODE_VERIFY_GATE_MAX) || 1 },
|
|
864
|
+
// Turn-continuation: a text-only reply that ends on an unperformed action announcement ("Let me implement
|
|
865
|
+
// these now.") gets one nudge to actually do it (≤2/turn) instead of finalizing. Off in plan mode — there
|
|
866
|
+
// the text IS the deliverable ("I'll implement this once you approve") — and via KODE_TURN_CONTINUATION=0.
|
|
867
|
+
turnContinuation: { enabled: process.env.KODE_TURN_CONTINUATION !== "0" && !this.planMode },
|
|
791
868
|
});
|
|
792
869
|
this.telemetry.record({ type: "turn", rounds: res.rounds, toolCalls: res.toolCalls, interrupted: false, durationMs: Math.round(performance.now() - _t0), ctxPct: this.ctxPct(), stopReason: res.stopReason });
|
|
793
870
|
this.sessionTokensTotal += (res.tokens ?? 0) + (res.promptTokens ?? 0); // cumulative session spend
|
package/dist/telemetry/events.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// simply never reached (a mobile host injects its own sink). Best-effort by construction: a sink failure
|
|
10
10
|
// never blocks or fails a turn — observability is not a gate.
|
|
11
11
|
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
12
|
+
// redact is pure regex + node-free — the static import keeps this module bundle-safe (GW-10 graph).
|
|
13
|
+
import { redactSecrets } from "../engine/redact.js";
|
|
12
14
|
export const EVENT_V = 1;
|
|
13
15
|
/** Emits OperatorEvents to a local JSONL file and, if configured, an HTTP sink. Both best-effort. The
|
|
14
16
|
* HTTP POST is fire-and-forget with a short timeout so a slow/down sink never stalls a turn. */
|
|
@@ -57,8 +59,11 @@ export class EventSink {
|
|
|
57
59
|
nodeImport("node:fs/promises"), nodeImport("node:os"), nodeImport("node:path"),
|
|
58
60
|
]);
|
|
59
61
|
const file = this.file.startsWith("~/") ? join(os.homedir(), this.file.slice(2)) : this.file;
|
|
60
|
-
await mkdir(dirname(file), { recursive: true });
|
|
61
|
-
|
|
62
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
63
|
+
// H4 (audit-tools §1): events sit next to bearer-token args in tool payloads; the file was
|
|
64
|
+
// world-readable by default and unmasked. 0700/0600 + redactSecrets — the POST sink below gets
|
|
65
|
+
// the identical treatment; claims of "secret-free" in this file's header are now ENFORCED.
|
|
66
|
+
await appendFile(file, redactSecrets(JSON.stringify(e)) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
62
67
|
}
|
|
63
68
|
catch { /* best-effort: no fs (mobile) or a write failure must never break a turn */ }
|
|
64
69
|
}
|
|
@@ -71,7 +76,7 @@ export class EventSink {
|
|
|
71
76
|
await fetch(this.url, {
|
|
72
77
|
method: "POST",
|
|
73
78
|
headers: { "content-type": "application/json" },
|
|
74
|
-
body: JSON.stringify(e),
|
|
79
|
+
body: redactSecrets(JSON.stringify(e)), // H4: never egress an unmasked token
|
|
75
80
|
signal: ctrl.signal,
|
|
76
81
|
});
|
|
77
82
|
}
|
package/dist/tools/computer.js
CHANGED
|
@@ -8,7 +8,7 @@ export function computerEnabled() { return ENABLED; }
|
|
|
8
8
|
function str(v, fallback = "") {
|
|
9
9
|
return v === undefined || v === null ? fallback : String(v);
|
|
10
10
|
}
|
|
11
|
-
const DISABLED_MSG = "computer control is disabled. Enable it with
|
|
11
|
+
const DISABLED_MSG = "computer control is disabled. Enable it with computer.enabled in settings.json, " +
|
|
12
12
|
"and grant the terminal app macOS permissions (run computer_doctor for the exact steps).";
|
|
13
13
|
// macOS is the only supported host for now (osascript/screencapture). Fail clearly elsewhere rather
|
|
14
14
|
// than silently no-op.
|
package/dist/tools/executor.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Interface consumed by the engine (Karpathy's lane):
|
|
3
3
|
// execute(name, args) -> Promise<string> one call; never throws, always resolves
|
|
4
4
|
// executeParallel(calls) -> Promise<string[]> one round's tool_calls, in input order;
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// executed in input order: a contiguous run of safe
|
|
6
|
+
// (read-only) tools runs concurrently, every other
|
|
7
|
+
// call runs alone, awaited in place
|
|
7
8
|
// resetTurn() -> void clear loop-guard history; call once per
|
|
8
9
|
// new user turn (not required by SPEC §3's
|
|
9
10
|
// round loop itself, but needed so the guard
|
|
@@ -38,7 +39,7 @@ export function rootArgs(name, args, root) {
|
|
|
38
39
|
return a;
|
|
39
40
|
}
|
|
40
41
|
const LOOP_GUARD_THRESHOLD = 5; // must match agent.ts LOOP_GUARD_LIMIT so this secondary guard never fires first
|
|
41
|
-
import {
|
|
42
|
+
import { mutationLanded } from "./mutating.js"; // single source of truth (see tools/mutating.ts) — a LANDED workspace edit ⇒ prior identical-call counts are stale
|
|
42
43
|
const LOOP_GUARD_EXEMPT = new Set(["agent_status", "bash_output"]); // poll/status tools — repeated calls are legit, never guarded
|
|
43
44
|
// Unique fallback id per Executor instance, so two sessions with no sessionId and no root (the
|
|
44
45
|
// foreground and a read-only sub-agent lane) still get DISTINCT shell keys. One Executor lives for
|
|
@@ -81,9 +82,10 @@ export class Executor {
|
|
|
81
82
|
// Run the tool inside THIS session's shell-key context so a persistent-shell tool (bash) picks
|
|
82
83
|
// this session's own ShellSession, not a process-wide singleton shared with other sub-agents.
|
|
83
84
|
const out = capToolResult(await shellKeyStore.run(this.shellKey, () => tool.run(args)), spillToolOutput);
|
|
84
|
-
// A file edit changed the workspace, so prior identical-call counts are stale — re-running the
|
|
85
|
-
// test/build after an edit is verify-after-fix iteration, not a loop. Clear so repeats start fresh.
|
|
86
|
-
|
|
85
|
+
// A file edit that LANDED changed the workspace, so prior identical-call counts are stale — re-running the
|
|
86
|
+
// same test/build after an edit is verify-after-fix iteration, not a loop. Clear so repeats start fresh.
|
|
87
|
+
// A FAILING edit ("error: old_string not found") changed nothing, so it must not reset the count.
|
|
88
|
+
if (mutationLanded(name, out))
|
|
87
89
|
this.seen.clear();
|
|
88
90
|
return out;
|
|
89
91
|
}
|
|
@@ -93,20 +95,23 @@ export class Executor {
|
|
|
93
95
|
}
|
|
94
96
|
async executeParallel(calls, onSettle) {
|
|
95
97
|
const results = new Array(calls.length);
|
|
96
|
-
const
|
|
97
|
-
for (let i = 0; i < calls.length; i++) {
|
|
98
|
-
if (this.reg.get(calls[i].name)?.safe)
|
|
99
|
-
safeIdx.add(i);
|
|
100
|
-
}
|
|
101
|
-
await Promise.all([...safeIdx].map(async (i) => {
|
|
98
|
+
const runAt = async (i) => {
|
|
102
99
|
results[i] = await this.execute(calls[i].name, calls[i].args);
|
|
103
100
|
onSettle?.(i, results[i]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
};
|
|
102
|
+
// Walk in INPUT ORDER: a contiguous run of safe (read-only) calls runs together, and every unsafe call
|
|
103
|
+
// runs ALONE, awaited in place — so a read batched after a write sees the write (and an edit followed
|
|
104
|
+
// by a grep reads post-edit state), instead of all reads racing ahead of every mutation.
|
|
105
|
+
let i = 0;
|
|
106
|
+
while (i < calls.length) {
|
|
107
|
+
if (!this.reg.get(calls[i].name)?.safe) {
|
|
108
|
+
await runAt(i++);
|
|
107
109
|
continue;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
}
|
|
111
|
+
const batch = [];
|
|
112
|
+
while (i < calls.length && this.reg.get(calls[i].name)?.safe)
|
|
113
|
+
batch.push(runAt(i++));
|
|
114
|
+
await Promise.all(batch);
|
|
110
115
|
}
|
|
111
116
|
return results;
|
|
112
117
|
}
|
package/dist/tools/mutating.js
CHANGED
|
@@ -7,3 +7,9 @@
|
|
|
7
7
|
export const MUTATING_TOOLS = new Set(["file_write", "file_edit"]);
|
|
8
8
|
/** True when a tool call's name is a workspace mutation. Tolerates undefined (a malformed/partial call). */
|
|
9
9
|
export const isMutatingTool = (name) => MUTATING_TOOLS.has(name ?? "");
|
|
10
|
+
/** True when a mutating call actually LANDED. file_write/file_edit report failure as a returned `error: …`
|
|
11
|
+
* string (not a throw), and a gated/denied or loop-guarded call never ran, so the tool NAME alone proves
|
|
12
|
+
* nothing. The loop-guard clears its identical-call counts only on a landed mutation — a failing edit must not
|
|
13
|
+
* grant a spinning model a fresh runway (the model can otherwise alternate a failing edit with the same
|
|
14
|
+
* poisoned call forever). */
|
|
15
|
+
export const mutationLanded = (name, result) => isMutatingTool(name) && !/^(?:error|loop guard|permission denied)/i.test(result.trimStart());
|