@0perator/operator 0.1.164 → 0.1.165
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 +17 -0
- package/dist/cli.js +1 -1
- package/dist/config/settings.js +27 -7
- package/dist/session.js +24 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ Operator is AXE's terminal coding agent (npm `@0perator/operator`), running on A
|
|
|
4
4
|
Newest first. Every release bumps `src/cli.tsx` VERSION + `package.json`, adds an entry here, and ships to
|
|
5
5
|
npm + both git remotes (memjar/kode, axetechnologies/kode). Test counts are the full suite at that release.
|
|
6
6
|
|
|
7
|
+
## 0.1.165 — 2026-10-01 — Robustness: deep-context swap-thrash guard + ESC-abort hardening
|
|
8
|
+
- **Swap-thrash guard (track · fix · prevent).** A long session could grow the live context past the box's RAM,
|
|
9
|
+
so model weights + KV cache spilled into swap and decode collapsed to ~0 tok/s (measured 2026-10-01: context
|
|
10
|
+
reached ~191K tokens on a 64GB box → 7.6GB swap → "88 tokens in 6 minutes"). The context *window* is a TOKEN
|
|
11
|
+
limit; the real cliff is a MEMORY limit the %-of-window compaction threshold can't see (it's the same % at any
|
|
12
|
+
RAM). Fix: `compactionCeilingTokens` now, when unset, applies a RAM-aware safe default —
|
|
13
|
+
`defaultCompactionCeiling(totalmem, window)` reserves ~28GB (≈model + OS/overhead) then ~3500 tok/GB of what's
|
|
14
|
+
left, clamped to [8000, 0.85·window] and deliberately BELOW the measured cliff — so proactive compaction fires
|
|
15
|
+
before swap on any box (64GB/300K → ~126K). An explicit `compaction.ceilingTokens` / `KODE_COMPACTION_CEILING_TOKENS`
|
|
16
|
+
still wins. The 0.1.164 token meter makes the trigger exact. `test/settings.test.mts` +8 regression tests lock
|
|
17
|
+
the ceiling below the cliff so this can't silently return.
|
|
18
|
+
- **ESC-abort hardening.** The main streaming abort path was already correct (verified by trace + a 6ms live
|
|
19
|
+
repro — no main-path bug); closed two narrower gaps: the compaction summarizer's `chat()` now carries the
|
|
20
|
+
abort signal (ESC during "compacting" tears it down), and `send()` arms the AbortController *before* first-turn
|
|
21
|
+
`maybeRecall`/MCP-discovery so ESC no longer no-ops in that window (`execute()` reuses the same controller).
|
|
22
|
+
- Full suite: 769 passed, 0 failed (104 files). `tsc --noEmit` clean.
|
|
23
|
+
|
|
7
24
|
## 0.1.164 — 2026-10-01 — Token meter (engine) + Switchboard messages inline in the transcript
|
|
8
25
|
- `src/engine/token-meter.ts` learns each endpoint's REAL chars-per-token online from the exact counts
|
|
9
26
|
the server already reports (`timings.prompt_n`, `usage.completion_tokens`): EMA (converges in ~10
|
package/dist/cli.js
CHANGED
|
@@ -461,7 +461,7 @@ function Root() {
|
|
|
461
461
|
maxTurnTokens: settings.maxTurnTokens, // opt-in per-turn cost ceiling (total tokens); undefined → no cap
|
|
462
462
|
maxRounds: settings.autonomy?.maxRounds, // soft per-turn round budget (default 40) — a real build isn't cut off at 10
|
|
463
463
|
compactionThreshold: compactionThreshold(settings), // settings.compaction.threshold / KODE_COMPACTION_THRESHOLD; undefined → 0.85
|
|
464
|
-
compactionCeilingTokens: compactionCeilingTokens(settings
|
|
464
|
+
compactionCeilingTokens: compactionCeilingTokens(settings, settings.endpoints.aurora.ctxWindow), // explicit setting/env wins; else a RAM-aware safe default caps context below the box's swap cliff (the "88 tok/6min" stall)
|
|
465
465
|
temperature: settings.temperature,
|
|
466
466
|
recall: settings.memory.recall,
|
|
467
467
|
models: settings.models, // /model registry overrides (router/models.ts has the built-in defaults)
|
package/dist/config/settings.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// default. Never throws — a missing or malformed file just falls back to defaults, same as an env
|
|
4
4
|
// var that was never set.
|
|
5
5
|
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
6
|
-
import { homedir } from "node:os";
|
|
6
|
+
import { homedir, totalmem } from "node:os";
|
|
7
7
|
import { join, dirname } from "node:path";
|
|
8
8
|
import { DEFAULT_MODEL_ID } from "../router/models.js";
|
|
9
9
|
// The sole endpoint: Aurora on :8097 at its REAL served context — 307,200 tokens (300K; the llama-server
|
|
@@ -161,14 +161,34 @@ export function compactionThreshold(s) {
|
|
|
161
161
|
const t = s.compaction?.threshold;
|
|
162
162
|
return typeof t === "number" && t >= 0.3 && t <= 0.95 ? t : undefined;
|
|
163
163
|
}
|
|
164
|
+
/** A RAM-aware SAFE default compaction ceiling (pure; exported for tests). The context window is a TOKEN
|
|
165
|
+
* limit, but the real failure is a MEMORY limit: model weights + KV cache must fit in RAM or macOS swaps and
|
|
166
|
+
* decode collapses to ~0 tok/s (measured 2026-10-01 on a 64GB box: context reached ~191K tok → 7.6GB swap →
|
|
167
|
+
* decode 26→2.7→0 tok/s). The %-of-window threshold can't see that cliff (it's the same % regardless of RAM),
|
|
168
|
+
* so we cap effective context by a budget derived from the box's RAM. Reserve ~28GB (≈20GB model + OS/app/KV
|
|
169
|
+
* overhead), then ~3500 tok/GB of what's left — deliberately BELOW the measured cliff (errs toward compacting
|
|
170
|
+
* a little early, which only costs some fidelity that retrieval reclaims; the alternative is the swap stall).
|
|
171
|
+
* Clamped to [8000, 0.85·window], so on a small window it never fires before the threshold path would. */
|
|
172
|
+
export function defaultCompactionCeiling(totalBytes, windowTokens) {
|
|
173
|
+
const totalGB = totalBytes / 2 ** 30;
|
|
174
|
+
const budgetGB = Math.max(0, totalGB - 28);
|
|
175
|
+
const raw = Math.floor(budgetGB * 3500);
|
|
176
|
+
const cap = Math.floor((windowTokens > 0 ? windowTokens : 0) * 0.85);
|
|
177
|
+
return Math.max(8000, Math.min(raw, cap));
|
|
178
|
+
}
|
|
164
179
|
/** The absolute-token proactive-compaction ceiling to hand runTurn: settings.compaction.ceilingTokens
|
|
165
|
-
* (env-overridden in loadSettings)
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
|
|
180
|
+
* (env-overridden in loadSettings), validated to a sane floor of 8000 tokens. When UNSET, we no longer leave
|
|
181
|
+
* it uncapped — we apply a RAM-aware safe default (defaultCompactionCeiling) so a large window can't grow the
|
|
182
|
+
* KV cache past the box's memory into swap (the "88 tokens in 6 minutes" stall). An explicit valid setting
|
|
183
|
+
* always wins. `windowTokens` is the active endpoint's context window; pass 0 if unknown (then only the floor
|
|
184
|
+
* applies). Resolved here so CLI, headless, and ACP surfaces read it identically. */
|
|
185
|
+
export function compactionCeilingTokens(s, windowTokens = 0) {
|
|
170
186
|
const t = s.compaction?.ceilingTokens;
|
|
171
|
-
|
|
187
|
+
if (typeof t === "number" && Number.isFinite(t) && t >= 8000)
|
|
188
|
+
return Math.floor(t);
|
|
189
|
+
if (windowTokens >= 8000)
|
|
190
|
+
return defaultCompactionCeiling(totalmem(), windowTokens);
|
|
191
|
+
return undefined;
|
|
172
192
|
}
|
|
173
193
|
/** Whether to auto-start a Remote Control host on session boot. An explicit setting/env wins
|
|
174
194
|
* (settings.remote.autostart / KODE_RC_AUTOSTART=1/0). Otherwise it is FEATURE-FLAGGED to the admin/VIP
|
package/dist/session.js
CHANGED
|
@@ -497,6 +497,10 @@ export class Session {
|
|
|
497
497
|
maxTokens: SUMMARY_MAX_TOKENS,
|
|
498
498
|
temperature: 0,
|
|
499
499
|
background: this.background, // a sub-agent's compaction summarize also yields to the interactive main turn
|
|
500
|
+
signal: this.ctrl?.signal, // ESC during "compacting" must tear down THIS request too, not just the main
|
|
501
|
+
// generation stream — without it a compaction summarize (which can be a large request on a slow/deep
|
|
502
|
+
// endpoint) runs to completion after the user already hit esc. Null ctrl (background pass outside a turn)
|
|
503
|
+
// → undefined → no abort, which is correct.
|
|
500
504
|
});
|
|
501
505
|
// Return "" on a genuinely empty response so compact()'s empty-summary guard fires and PRESERVES history
|
|
502
506
|
// rather than replacing it with a useless placeholder — the old "(summary unavailable)" sentinel was
|
|
@@ -600,12 +604,23 @@ export class Session {
|
|
|
600
604
|
async send(text, h = {}) {
|
|
601
605
|
if (this.ctrl)
|
|
602
606
|
throw new Error("Session.send called while a turn is in flight — serialize turns (the shell queues input)");
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
// Arm the interrupt controller BEFORE maybeRecall. The host flips status to "thinking" the instant send() is
|
|
608
|
+
// called, so an esc during first-turn memory recall / MCP discovery (which hit the network and can be slow)
|
|
609
|
+
// would otherwise no-op — this.ctrl was null until execute(). execute() reuses this same controller.
|
|
610
|
+
this.ctrl = new AbortController();
|
|
611
|
+
try {
|
|
612
|
+
await this.maybeRecall(text); // fold past-session memory into the system prompt on the first turn
|
|
613
|
+
if (this.ctrl.signal.aborted)
|
|
614
|
+
return { content: "", rounds: 0, toolCalls: 0, interrupted: true };
|
|
615
|
+
this.inner.resetTurn(); // re-evaluate routing from the smallest endpoint + clear last turn's unhealthy set
|
|
616
|
+
const active = findModel(this.registry, this.modelId);
|
|
617
|
+
if (active?.kind === "orchestrated")
|
|
618
|
+
return await this.sendMoa(text, h, active);
|
|
619
|
+
return await this.execute(text, h, this.router, this.sysWithThink());
|
|
620
|
+
}
|
|
621
|
+
finally {
|
|
622
|
+
this.ctrl = null; // execute() nulls on its own path too; this also covers the maybeRecall-abort early return
|
|
623
|
+
}
|
|
609
624
|
}
|
|
610
625
|
/** MOA turn (MOA-DESIGN.md): fan out to settings.moa's proposers in parallel, then run the
|
|
611
626
|
* aggregator through the SAME runTurn loop as a normal turn (execute) — pointed at the
|
|
@@ -645,7 +660,9 @@ export class Session {
|
|
|
645
660
|
async execute(text, h, router, sys, routeLabel) {
|
|
646
661
|
this.executor.resetTurn(); // clear the host executor's per-turn loop guard before this turn
|
|
647
662
|
this.lastSys = sys; // remember the EXACT system prompt this turn sends, so cache-safe compaction reuses it verbatim
|
|
648
|
-
|
|
663
|
+
// Reuse the controller send() already armed (so esc during maybeRecall / MOA fan-out is live); create one
|
|
664
|
+
// only if execute() is somehow entered without send() arming it (defensive — every caller goes via send).
|
|
665
|
+
const controller = this.ctrl ?? new AbortController();
|
|
649
666
|
this.ctrl = controller;
|
|
650
667
|
const _t0 = performance.now();
|
|
651
668
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.165",
|
|
4
4
|
"description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|