@0perator/operator 0.1.359 → 0.1.360-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/dashboard/index.html +2 -2
- package/dist/autonomy/cloud-agent.js +2 -2
- package/dist/autonomy/headless.js +15 -6
- package/dist/autonomy/session-factory.js +2 -1
- package/dist/background/notices.js +1 -1
- package/dist/browser/session.js +7 -0
- package/dist/cli.js +94 -52
- package/dist/config/features.js +6 -5
- package/dist/config/persona.js +57 -40
- package/dist/config/settings.js +39 -55
- package/dist/engine/agent.js +72 -33
- package/dist/engine/aurora.js +24 -2
- package/dist/engine/compaction.js +27 -7
- package/dist/engine/decision-points.js +16 -4
- package/dist/engine/kv-slot.js +87 -0
- package/dist/engine/loop-guard.js +49 -18
- package/dist/engine/messages.js +8 -1
- package/dist/engine/progress-deadline.js +37 -0
- package/dist/engine/verify-gate.js +134 -9
- package/dist/enterprise/cli.js +13 -1
- package/dist/mcp/craft-server.js +5 -3
- package/dist/memory/live-progress.js +35 -6
- package/dist/permissions/policy.js +8 -0
- package/dist/permissions/signature.js +9 -0
- package/dist/products/artifact-library.js +47 -0
- package/dist/products/craft.js +58 -94
- package/dist/products/temple.js +230 -0
- package/dist/remote/host.js +28 -1
- package/dist/router/discovery.js +23 -6
- package/dist/router/models.js +29 -70
- package/dist/services/preflight.js +3 -41
- package/dist/session.js +121 -38
- package/dist/skills/catalogue.js +2 -0
- package/dist/skills/finder.js +1 -1
- package/dist/tools/background-result.js +26 -0
- package/dist/tools/chauffeur-native.js +6 -0
- package/dist/tools/craft.js +17 -6
- package/dist/tools/deferred.js +64 -30
- package/dist/tools/executor.js +4 -2
- package/dist/tools/paths.js +3 -3
- package/dist/tools/read-ledger.js +44 -0
- package/dist/tools/registry.js +218 -264
- package/dist/tools/sandbox.js +52 -39
- package/dist/tools/shell-context.js +5 -0
- package/dist/tools/shell-session.js +61 -29
- package/dist/tools/vision-gateway.js +79 -34
- package/dist/tools/wave-tools.js +2 -2
- package/dist/tools/wave2-tools.js +6 -6
- package/dist/ui/ArtifactPicker.js +2 -2
- package/dist/ui/Composer.js +9 -2
- package/dist/ui/StatusRule.js +1 -1
- package/dist/ui/modelPicker.js +1 -1
- package/dist/ui/nextStep.js +1 -0
- package/dist/ui/pending.js +10 -0
- package/dist/update.js +78 -4
- package/dist/util/retry.js +34 -0
- package/dist/util/slash.js +2 -1
- package/dist/vault/tool.js +3 -1
- package/mcp/powertools-toolbox.mjs +166 -1
- package/package.json +9 -13
- package/dashboard/README.md +0 -62
- package/dist/compose/client.js +0 -56
- package/mcp/README.md +0 -88
- package/mcp/powertools.md +0 -210
package/dist/router/models.js
CHANGED
|
@@ -24,7 +24,7 @@ export const MODEL_ALIASES = {
|
|
|
24
24
|
"aurora-128k": "operator-128k",
|
|
25
25
|
"spectre": "cortana", // flagship renamed Spectre -> Cortana 35B (2026-10-07); old id keeps resolving
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
27
|
+
/** The one shared model gateway, public face.
|
|
28
28
|
* The portal client (router/portal.ts) derives its host from this too, so the address lives in exactly one place. */
|
|
29
29
|
export const GATEWAY_BASE = `https://${PRODUCT_API_HOST}/v1`;
|
|
30
30
|
/** The same gateway on this box's loopback. Fleet entries list it FIRST and the public face second, so a local
|
|
@@ -40,78 +40,32 @@ const GEMINI_BASE = "https://generativelanguage.googleapis.com/v1beta/openai"; /
|
|
|
40
40
|
const GEMINI_CHAT_PATH = "/chat/completions"; // the base already carries its version: …/v1beta/openai/chat/completions
|
|
41
41
|
const QWEN_BASE = "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1";
|
|
42
42
|
/** Output ceilings (ModelProfile.maxOutput) — only where the vendor's limit is cited. Anthropic: the current Claude
|
|
43
|
-
* family's max_tokens ceiling (a larger value is a 400). QwenCloud qwen3.8-flash: the vendor's own 400
|
|
43
|
+
* family's max_tokens ceiling (a larger value is a 400). QwenCloud qwen3.8-flash: the vendor's own 400,
|
|
44
44
|
* 2026-10-28 — "Range of max_tokens should be [1, 131072]". */
|
|
45
45
|
export const ANTHROPIC_MAX_OUTPUT = 128_000;
|
|
46
46
|
const QWEN_FLASH_MAX_OUTPUT = 131_072;
|
|
47
47
|
const NOUS_BASE = "https://inference-api.nousresearch.com/v1";
|
|
48
|
-
// Registry order IS picker order (visibleModels keeps it):
|
|
48
|
+
// Registry order IS picker order (visibleModels keeps it): the local row, then the gateway rows, then the
|
|
49
49
|
// connected-provider rows (hidden until their key is connected), then the by-id-only lanes, then MOA. Free
|
|
50
50
|
// vendor rows (tier "free") arrive at runtime through Session.dynamicModels and land after all of these.
|
|
51
|
+
// A deployment's own servers (direct endpoints, owner-only trials, its labels and descriptions) are NOT listed
|
|
52
|
+
// here: they come from settings.models, which adds rows and overrides these by id (modelRegistry).
|
|
51
53
|
export const BUILTIN_MODELS = [
|
|
52
|
-
// ──
|
|
54
|
+
// ── local ───────────────────────────────────────────────────────────────────────────────────────────────
|
|
53
55
|
// THE one Aurora row (0.1.332). The 300K/600K/1M choice is a context PIN (settings.contextPin, /context,
|
|
54
56
|
// Ctrl+X) applied over the served window — not three profiles of one model. The static :8097 is the
|
|
55
57
|
// gateway-less fallback; on a gateway box Session.setModel restores the shell's chain for this id (the
|
|
56
|
-
// dynamic port + the
|
|
57
|
-
{ id: "operator-1m", tier: "power", label: "Aurora Code 1", params: "35B-A3B", box: "
|
|
58
|
-
// ──
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{ id: "cortana", tier: "power", label: "Cortana", params: "35B-A3B", box: "JL1", kind: "single", desc: "Qwen3.6-35B-A3B abliterated, Q4_K_M", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["cortana", "cortana"], model: "/Volumes/Ai Storage/jl1-local/models/aurorax/Huihui-Qwen3.6-35B-A3B-abliterated.Q4_K_M.gguf", ctx: 262144 },
|
|
68
|
-
{ id: "gpt-oss-20b", tier: "economy", label: "gpt-oss", params: "20B-A3.6B", box: "JL1", kind: "single", desc: "OpenAI gpt-oss-20b, Q4_K_M — the MoA specialist (arena's best sub-agent)", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["gpt-oss-20b", "gpt-oss-20b"], model: "gpt-oss-20b", ctx: 65536 },
|
|
69
|
-
// Thor — huihui-ai QwQ-32B abliterated: a dense reasoning model that thinks before it answers. Served on JL1:8124
|
|
70
|
-
// (the portal lists it "available" = registered, loaded on demand); gateway-first like cortana. ctx 32768 = the
|
|
71
|
-
// server's --ctx-size. Mirrors the hand override JL2's settings.json carried under this id (now a no-op by id).
|
|
72
|
-
{ id: "thor", tier: "power", label: "Thor", params: "32B", box: "JL1", kind: "single", desc: "QwQ-32B abliterated reasoning model — thinks before answering", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["thor", "thor"], model: "/Volumes/Ai Storage/axe-models/thor-32b/huihui-ai_QwQ-32B-abliterated-Q4_K_M.gguf", ctx: 32768 },
|
|
73
|
-
// Qwen3-4B — fast LOCAL tier (stock qwen3-4b-mlx-q4, 2.26GB MLX 4-bit, ctx 40960) served via mlx_lm.server
|
|
74
|
-
// on JL1:8110. Qwen3 vocab (151936) — the same family as ghost-32b, so it's the review-recommended quick tier
|
|
75
|
-
// AND the vocab lineage for ghost spec-decode (the actual draft is Qwen3-0.6B, too small to list here). Runs
|
|
76
|
-
// /no_think for speed. Picked (2026-10-07) from a fleet-wide 3B-class review; no 3B had been execution-graded,
|
|
77
|
-
// so this is the evidence-led default pending a dyno/coding-eval bench. 40960 ≥ LEAN_HARNESS_CTX → full harness.
|
|
78
|
-
{ id: "scout", tier: "lite", label: "Scout", params: "4B", box: "JL1", kind: "single", desc: "fast local tier — Qwen3-4B /no_think, Qwen3 vocab (JL1:8110, MLX 4-bit; local gateway first, public gateway as failover)", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["scout", "scout"], model: "/Volumes/Ai Storage/axe-models/qwen3-4b-mlx-q4", ctx: 32000 },
|
|
79
|
-
// Falcon-H1-34B — a NOVEL architecture nobody else on the fleet runs: hybrid SSM+attention, trained with a
|
|
80
|
-
// genuinely long native context (no YaRN stretch needed — 262144 is baked into the GGUF's own metadata,
|
|
81
|
-
// confirmed via gguf-py header read, rope.freq_base ≈1e11). Served JL1:8101, q8_0 KV, parallel=1. Not one
|
|
82
|
-
// of our own fine-tunes — picked specifically to try something outside the Qwen/Aurora lineage.
|
|
83
|
-
{ id: "falcon-h1-34b", tier: "power", label: "Falcon-H1", params: "34B", box: "JL1", kind: "single", desc: "novel hybrid SSM+attention architecture, native 256K context (no rope extension) — not ours, picked to try something different from the Qwen/Aurora lineage", endpoint: "http://192.168.1.103:8101/v1", model: "/Volumes/Ai Storage/axe-models/falcon-h1-34b/Falcon-H1-34B-Instruct-Q4_K_M.gguf", ctx: 262144 },
|
|
84
|
-
// Casanova (axe/newton-base-32b) — OUR OWN fine-tune, Qwen2-architecture, 32B. Source was MLX 4-bit
|
|
85
|
-
// quantized (group_size 64, affine) — dequantized via mlx_lm --dequantize, reconverted+requantized to
|
|
86
|
-
// Q4_K_M via convert_hf_to_gguf.py + llama-quantize (2026-10-22). Native ctx is only 32768, so 128K here is
|
|
87
|
-
// a 4x YaRN stretch (--rope-scaling yarn --yarn-orig-ctx 32768 --rope-scale 4) — untested at the edge,
|
|
88
|
-
// verify with a real long-context probe before trusting it near the ceiling.
|
|
89
|
-
{ id: "casanova", tier: "power", label: "Casanova", params: "32B", box: "JL1", kind: "single", desc: "our own fine-tune (axe/newton-base-32b) — 128K via 4x YaRN stretch from a 32K native window", endpoint: "http://192.168.1.103:8102/v1", model: "/Users/home/.axe/gguf-converted/casanova-current/casanova-current-Q4_K_M.gguf", ctx: 131072 },
|
|
90
|
-
// Code tier for the coding/Replit-clone surface — Qwen2.5-Coder-3B has a real chat template + tool-calling
|
|
91
|
-
// + FIM (ollama reports "completion, tools, insert"), unlike StarCoder2/replit-code (completion-only, can't
|
|
92
|
-
// drive an agent loop). Ollama on JL1, on-demand (loads ~3GB, so SELECT only when JL1 swap has headroom).
|
|
93
|
-
// ctx 32000 stays just under the 32768 train wall (the 0.1.259/260 overrun bug) and below LEAN_HARNESS_CTX
|
|
94
|
-
// so a 3B gets the lean harness. LICENCE: Qwen Research Licence (non-commercial) — fine for owner/eval use;
|
|
95
|
-
// the paid product should use an Apache-2.0 size (qwen2.5-coder 1.5b/7b).
|
|
96
|
-
// transport:"openai" = Ollama /v1. ENDPOINT FIX 2026-10-12: was 127.0.0.1:11434, which only resolves
|
|
97
|
-
// ON JL1 — every laptop picker entry pointed at its own dead loopback. LAN address like the other
|
|
98
|
-
// JL1 slots.
|
|
99
|
-
{ id: "qwen-coder", tier: "lite", label: "Qwen2.5-Coder", params: "3B", box: "JL1", kind: "single", desc: "code tier — Qwen2.5-Coder-3B Q4_K_M (chat + tool-calling + FIM), Ollama on JL1:11434 (on-demand ~3GB); Qwen Research Licence, non-commercial", endpoint: "http://192.168.1.103:11434/v1", model: "qwen2.5-coder:3b", ctx: 32000, transport: "openai" },
|
|
100
|
-
// Belmont 30b — an OWNER-ONLY trial of muse (muse0P abliterated, Q4_K_M ~16.9GB), served under the alias
|
|
101
|
-
// `muse-op` on llama.cpp :8113. FAILOVER pair: JL2 primary (192.168.1.146:8113), JL1 standby
|
|
102
|
-
// (192.168.1.103:8113) — same model/alias on both, so the router can hop JL2->JL1 on a busy/5xx. JL1 runs
|
|
103
|
-
// overnight training, so muse is served on JL2 and only falls back to JL1 when that box is free (it must be
|
|
104
|
-
// running on at least one box to answer — nothing here starts a server). ctx 131072 matches the served
|
|
105
|
-
// n_ctx on :8113 (JL1 /props: muse0P, n_ctx 131072); the earlier 16384 understated it 8x and instantly
|
|
106
|
-
// stalled the full headless harness at ctxPct=99 (it sits ABOVE LEAN_HARNESS_CTX, so Belmont gets the
|
|
107
|
-
// full harness). Keep this equal to the serve scripts' --ctx-size on both boxes.
|
|
108
|
-
// ownerOnly: enterprise-grade private trial — hidden from every picker and refused for any non-owner seat.
|
|
109
|
-
{ id: "belmont-30b", tier: "economy", label: "Belmont", params: "30B", box: "JL1", kind: "single", desc: "OWNER-ONLY trial — muse (muse-op, abliterated 30B Q4_K_M) on llama.cpp :8113, JL2 primary + JL1 failover; must be served on a box to answer", endpoints: ["http://192.168.1.146:8113/v1", "http://192.168.1.103:8113/v1"], model: "muse-op", ctx: 131072, ownerOnly: true, leanPersona: true },
|
|
110
|
-
// Venice 24B — a LIGHTER uncensored alternative to the 35B Cortana: Dolphin-Mistral-24B-Venice-Edition
|
|
111
|
-
// (Q4_K_M, ~14GB) with a bolted-on Mistral-Small-3.1 mmproj for vision. Dense 24B (not MoE), served on
|
|
112
|
-
// JL1:8114 via llama.cpp (--jinja, q8 KV). ctx 32768 ≥ LEAN_HARNESS_CTX → full harness. A quick drop-in to
|
|
113
|
-
// test a smaller/different flavour alongside Cortana without the 35B footprint.
|
|
114
|
-
{ id: "venice-24b", tier: "economy", label: "Venice", params: "24B", box: "JL1", kind: "single", desc: "lighter uncensored tier — Dolphin-Mistral-24B-Venice + vision (JL1:8114) — slot stopped today; hidden from the picker, resolves by id once launched", endpoint: "http://192.168.1.103:8114/v1", model: "/Volumes/Ai Storage/exotic-models/dolphin-mistral-24b-venice-gguf/cognitivecomputations_Dolphin-Mistral-24B-Venice-Edition-Q4_K_M.gguf", ctx: 32768, hidden: true },
|
|
58
|
+
// dynamic port + the fleet and cloud legs buildEndpointChain assembles).
|
|
59
|
+
{ id: "operator-1m", tier: "power", label: "Aurora Code 1", params: "35B-A3B", box: "local", kind: "single", desc: "the default model, served on this machine; the gateway takes over when it is down", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 1000000 },
|
|
60
|
+
// ── gateway ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
61
|
+
// GATEWAY-FIRST: the local gateway when this machine runs one, then the public face. `ctx` is the window the
|
|
62
|
+
// gateway serves. The 0.1.260 lesson stands: a profile that claims MORE than the server's --ctx-size makes the
|
|
63
|
+
// engine overrun the wall and the server cuts a round mid-tool-call (0.1.259) — change a number ONLY when the
|
|
64
|
+
// served window changes.
|
|
65
|
+
{ id: "cortana", tier: "power", label: "Cortana", params: "35B-A3B", box: "gateway", kind: "single", desc: "general model with vision", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["cortana", "cortana"], model: "cortana", ctx: 262144 },
|
|
66
|
+
{ id: "gpt-oss-20b", tier: "economy", label: "gpt-oss", params: "20B-A3.6B", box: "gateway", kind: "single", desc: "OpenAI gpt-oss-20b — the MoA specialist", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["gpt-oss-20b", "gpt-oss-20b"], model: "gpt-oss-20b", ctx: 65536 },
|
|
67
|
+
{ id: "thor", tier: "power", label: "Thor", params: "32B", box: "gateway", kind: "single", desc: "reasoning model — thinks before answering", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["thor", "thor"], model: "thor", ctx: 32768 },
|
|
68
|
+
{ id: "scout", tier: "lite", label: "Scout", params: "4B", box: "gateway", kind: "single", desc: "fast small model", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["scout", "scout"], model: "scout", ctx: 32000 },
|
|
115
69
|
// ── connected providers (BYO: hidden until the vendor key is connected — /model "+ Connect a provider key") ──
|
|
116
70
|
// Claude — BYO Anthropic connectors, so "delegate to Claude" and `/model claude-sonnet` work. Unlike the
|
|
117
71
|
// qwen/OpenAI connectors (OpenAI dialect), Claude speaks the NATIVE Anthropic Messages wire — transport
|
|
@@ -137,8 +91,8 @@ export const BUILTIN_MODELS = [
|
|
|
137
91
|
// and the Operator token is its native auth (authHeaders scoping) — never a BYO gate on this id: gating it
|
|
138
92
|
// behind an unissued `sk-axe-…` account hid our own remote lane from our own picker (2026-10-12 audit). When
|
|
139
93
|
// the V1 vendor keys ship, reintroduce a byo:"axe" SKU as a SEPARATE connector id, never by re-gating this one.
|
|
140
|
-
{ id: "axe-aurora-300k", tier: "power", label: "Aurora Code 1", params: "35B-A3B", box: "cloud", kind: "single", desc: "
|
|
141
|
-
{ id: "operator-128k", tier: "economy", label: "Aurora Code 1", params: "35B-A3B", box: "
|
|
94
|
+
{ id: "axe-aurora-300k", tier: "power", label: "Aurora Code 1", params: "35B-A3B", box: "cloud", kind: "single", desc: "the default model on the shared gateway", endpoint: GATEWAY_BASE, endpoints: [GATEWAY_BASE, LEGACY_GATEWAY_BASE], model: "aurora-code-1", ctx: 307200, transport: "openai", hidden: true },
|
|
95
|
+
{ id: "operator-128k", tier: "economy", label: "Aurora Code 1", params: "35B-A3B", box: "local", kind: "single", desc: "128K context, lighter RAM (:8096); hidden from the picker, resolves by id when the slot is served", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072, hidden: true },
|
|
142
96
|
// ── capabilities (0.1.355) ──────────────────────────────────────────────────────────────────────────────
|
|
143
97
|
// A capability is a name the gateway resolves (the portal's aliases and routes), so the owner asks for a KIND of worker and
|
|
144
98
|
// the fleet answers with its best healthy model: the strongest resident one first, parallel delegations spilling down the
|
|
@@ -147,7 +101,7 @@ export const BUILTIN_MODELS = [
|
|
|
147
101
|
// is the smallest window any model in the chain serves, so compaction is safe wherever the request lands.
|
|
148
102
|
{ id: "subagent", tier: "power", label: "Sub-agent", box: "fleet", kind: "single", desc: "capability: the default sub-agent — the gateway picks the best healthy model", endpoint: LOCAL_GATEWAY_BASE, endpoints: [LOCAL_GATEWAY_BASE, GATEWAY_BASE], endpointModels: ["subagent", "subagent"], model: "subagent", ctx: 262144, hidden: true },
|
|
149
103
|
// ── orchestrated ────────────────────────────────────────────────────────────────────────────────────────
|
|
150
|
-
{ id: "moa", tier: "power_turbo", label: "MOA", box: "mixture of agents", kind: "orchestrated", desc: "the team slot —
|
|
104
|
+
{ id: "moa", tier: "power_turbo", label: "MOA", box: "mixture of agents", kind: "orchestrated", desc: "the team slot — a planner hands steps to specialists, checks their work and writes the answer (settings.moa overrides)" },
|
|
151
105
|
];
|
|
152
106
|
export const OPERATOR_FREE_ACCOUNT = "0perator";
|
|
153
107
|
export const BYO_PRESETS = {
|
|
@@ -228,18 +182,23 @@ export function laneTier(lane) {
|
|
|
228
182
|
return lane === "reasoning" ? "power" : "lite";
|
|
229
183
|
}
|
|
230
184
|
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
231
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K
|
|
232
|
-
* can't take Operator's full memory + handoff injection (sized for
|
|
185
|
+
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K one)
|
|
186
|
+
* can't take Operator's full memory + handoff injection (sized for a 300K window); it fills the window and
|
|
233
187
|
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
234
|
-
* threshold while keeping the base persona
|
|
188
|
+
* threshold while keeping the base persona. */
|
|
235
189
|
export function modelCtxFor(id, overrides) {
|
|
236
190
|
if (!id)
|
|
237
191
|
return Number.POSITIVE_INFINITY;
|
|
238
192
|
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
239
193
|
}
|
|
240
194
|
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
241
|
-
* full; a self-hosted small model (
|
|
195
|
+
* full; a self-hosted small model (8K, or a 16K bump) goes lean. */
|
|
242
196
|
export const LEAN_HARNESS_CTX = 32768;
|
|
197
|
+
/** The default served-window floor for the model a session runs its full harness on (settings.contextFloor): below it
|
|
198
|
+
* the system prompt and the tool schemas (~32K tokens) leave too little room, and the session compacts every round. */
|
|
199
|
+
export const AGENT_CTX_FLOOR = 131_072;
|
|
200
|
+
/** The window production agent models are served at; between the floor and this a session runs, with a warning. */
|
|
201
|
+
export const AGENT_CTX_TARGET = 262_144;
|
|
243
202
|
/** The smallest context pin accepted anywhere (the /context parser, settings.contextPin, Session): below it the system
|
|
244
203
|
* prompt and the tool schemas (~16K tokens) leave no room for a multi-round turn. */
|
|
245
204
|
export const MIN_CONTEXT_PIN = 32_000;
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
// it UP; it NEVER stops Aurora on exit, because that would break every other client.
|
|
13
13
|
// • autopilot (:9333) is optional and handled the same start-only way (non-fatal if it won't come up).
|
|
14
14
|
// • vision (:7788, axe.vision-bot) is OFF BY DEFAULT — the media-pipeline ADR (2026-10-19) keeps the
|
|
15
|
-
// GPU with Aurora, so boot only PROBES + reports it (settings DEFAULTS ship autostart:false).
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
// until `enable` runs first — ensureLaunchd's kick-failure path (bootout→enable→bootstrap→kickstart)
|
|
19
|
-
// is exactly that repair.
|
|
15
|
+
// GPU with Aurora, so boot only PROBES + reports it (settings DEFAULTS ship autostart:false). Nothing
|
|
16
|
+
// here starts it at point of need: image_analyze asks the gateway's `vision` route, and which servers
|
|
17
|
+
// back that route is the router's business (tools/vision-gateway.ts).
|
|
20
18
|
// • SearXNG is session-scoped and owned by tools/searxng.ts (lazy start + idle/exit stop) — the only
|
|
21
19
|
// service Operator tears down, via stopSessionServices() below.
|
|
22
20
|
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
@@ -267,42 +265,6 @@ async function ensureOptional(name, cfg, onProgress, healthPath = "/") {
|
|
|
267
265
|
const optCfg = { ...cfg, waitSec: Math.min(cfg.waitSec ?? 8, 8) };
|
|
268
266
|
return ensureLaunchd(name, `${url}${healthPath}`, healthPath !== "/", optCfg, onProgress);
|
|
269
267
|
}
|
|
270
|
-
/** Point-of-need vision start — the ADR's deferred auto-on, done client-side. image_analyze calls this
|
|
271
|
-
* when a LOCAL vision target fails /health, so the media pipeline comes up for the turn that needs it
|
|
272
|
-
* while boot never touches it (GPU stays with Aurora by default). Reuses the full ensureLaunchd repair
|
|
273
|
-
* (kickstart → bootout/enable/bootstrap/kickstart), so a job left launchd-disabled — by `media-pipeline
|
|
274
|
-
* off` or a stale eval pause — self-heals here instead of dying with bootstrap I/O-error(5). Single-flight:
|
|
275
|
-
* concurrent callers share one start attempt; a short negative TTL so a genuinely broken worker doesn't
|
|
276
|
-
* re-kick launchd on every retry. Returns true iff vision answered /health. */
|
|
277
|
-
let visionStart = null;
|
|
278
|
-
let visionStartFailedAt = 0;
|
|
279
|
-
const VISION_START_TTL_MS = 60_000;
|
|
280
|
-
export function ensureVisionUp(url = "http://127.0.0.1:7788") {
|
|
281
|
-
if (visionStart)
|
|
282
|
-
return visionStart;
|
|
283
|
-
if (Date.now() - visionStartFailedAt < VISION_START_TTL_MS)
|
|
284
|
-
return Promise.resolve(false);
|
|
285
|
-
visionStart = (async () => {
|
|
286
|
-
const uid = typeof process.getuid === "function" ? process.getuid() : NaN;
|
|
287
|
-
if (Number.isNaN(uid)) {
|
|
288
|
-
visionStartFailedAt = Date.now();
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
const r = await ensureLaunchd("vision", `${url.replace(/\/$/, "")}/health`, true, {
|
|
292
|
-
autostart: true,
|
|
293
|
-
launchdLabel: "co.0perator.vision",
|
|
294
|
-
plistPath: "~/Library/LaunchAgents/co.0perator.vision.plist",
|
|
295
|
-
legacyLabels: ["axe.vision-bot"],
|
|
296
|
-
waitSec: 12, // qwen2.5vl:7b is an ollama-backed worker — a cold load is seconds, not minutes
|
|
297
|
-
});
|
|
298
|
-
const ok = r.state === "up" || r.state === "started";
|
|
299
|
-
if (!ok)
|
|
300
|
-
visionStartFailedAt = Date.now();
|
|
301
|
-
visionStart = null;
|
|
302
|
-
return ok;
|
|
303
|
-
})();
|
|
304
|
-
return visionStart;
|
|
305
|
-
}
|
|
306
268
|
/** Best-effort install of an optional companion (autopilot / chauffeur) via the packaged setup script,
|
|
307
269
|
* DETACHED so it never blocks boot. Sourcing (fleet rsync / clone) lives in scripts/setup-services.sh —
|
|
308
270
|
* kept out of the JS so the mobile bundle carries no installer. No-ops if the script or spawn is absent. */
|
package/dist/session.js
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
// that maps these callbacks onto React state; a test can drive the same `send()` directly.
|
|
4
4
|
import { runTurn, TurnAbortedError } from "./engine/agent.js";
|
|
5
5
|
import { recordTruncation } from "./observability/blackbox.js";
|
|
6
|
-
import { Conversation, placeSessionContext, SESSION_CONTEXT_OPEN, SESSION_CONTEXT_CLOSE } from "./engine/messages.js";
|
|
6
|
+
import { Conversation, placeSessionContext, SESSION_CONTEXT_OPEN, SESSION_CONTEXT_CLOSE, SESSION_CONTEXT_REQUEST_LINE } from "./engine/messages.js";
|
|
7
7
|
import { scratchDirFor } from "./config/scratch.js";
|
|
8
|
-
import {
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { chat, health, reachable, gateKey, isRemoteBase, shipsLlamaCacheKnobs, requiresOperatorToken, operatorTrustedUrl } from "./engine/aurora.js";
|
|
10
|
+
import { claimSlot, releaseSlot } from "./engine/kv-slot.js";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
9
12
|
import { compact, compactionSplit, fitToWindow, turnStarts, SUMMARY_INSTRUCTION, stripTrailingOrphanToolCall, pickSummaryContent, renderAnchorIndex, verbatimUserTail, applyAnchorVerification } from "./engine/compaction.js";
|
|
10
13
|
import { globalTokenMeter, endpointKey } from "./engine/token-meter.js";
|
|
11
14
|
import { spillToolOutput } from "./tools/tool-output-spill.js"; // GW-10-COMPLETE: node-side spill sink
|
|
@@ -20,8 +23,9 @@ import { withDelegateDefault } from "./autonomy/delegate.js";
|
|
|
20
23
|
import { routeShadowTurn, shadowPrompt } from "./moa/shadow.js"; // MOA phase-0 observability (KODE_MOA_SHADOW)
|
|
21
24
|
import { AuroraRouter } from "./router/router.js";
|
|
22
25
|
import { operatorAgentPersona } from "./config/operator-harness.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
26
|
+
import { progressDeadline, summaryCeilingMs, DeadlineError } from "./engine/progress-deadline.js";
|
|
27
|
+
import { modelRegistry, findModel, selectModel, visibleModels, endpointBase, profileEndpoint, fmtCtx, MIN_CONTEXT_PIN, AGENT_CTX_FLOOR, AGENT_CTX_TARGET, DEFAULT_MODEL_ID, LEAN_HARNESS_CTX } from "./router/models.js";
|
|
28
|
+
import { probeServed, usableCtx } from "./router/discovery.js";
|
|
25
29
|
import { FAST_START_INSTRUCTION, parseFastStartReply } from "./engine/fast-start.js";
|
|
26
30
|
import { askFrontDoor, recentTurns } from "./engine/front-door.js";
|
|
27
31
|
import { getByoToken, hasByoToken } from "./auth/byo.js";
|
|
@@ -98,7 +102,7 @@ function makeSpawnTool(handler) {
|
|
|
98
102
|
"the same round you decide to delegate, and in that message tell the owner who you are sending and why (one line " +
|
|
99
103
|
"per agent). You stay the lead: do what does NOT depend on them; never redo, re-spawn or poll for a step one is " +
|
|
100
104
|
"working on — each report, and a STUCK notice if one stalls, arrives as a message at the start of a later turn. " +
|
|
101
|
-
"agent_status shows rounds, files and stuck flags; message_agent steers; stop_agent stops one so you can take its " +
|
|
105
|
+
"On demand: agent_status shows rounds, files and stuck flags; message_agent steers; stop_agent stops one so you can take its " +
|
|
102
106
|
"step over (a sub-agent id is not a shell job id).\n" +
|
|
103
107
|
"USE FOR: reasoning-heavy or context-flooding subtasks, independent parallel workstreams (research per area, " +
|
|
104
108
|
"review per module, search per tree, drafting a file).\n" +
|
|
@@ -112,17 +116,19 @@ function makeSpawnTool(handler) {
|
|
|
112
116
|
type: "object",
|
|
113
117
|
properties: {
|
|
114
118
|
tasks: { type: "array", items: { type: "string" }, description: "the brief(s); one entry per sub-agent" },
|
|
115
|
-
task: { type: "string", description: "a single brief
|
|
119
|
+
task: { type: "string", description: "a single brief" },
|
|
116
120
|
role: { type: "string", enum: ["research", "search", "review", "plan", "code-edit", "generic"], description: "research = web research on an outside subject (web tools only, cites URLs); search = find things in this repo; review = code review; plan = a plan — those four cannot write files; code-edit = change files (own worktree); generic = every tool. Set it when the deliverable is a file." },
|
|
117
121
|
agent: { type: "string", description: "optional repo-local persona from .operator/agents/ (listed under 'Repo-local harness')" },
|
|
118
122
|
names: { type: "array", items: { type: "string" }, description: "a short first name for each sub-agent, same order as `tasks` (you choose them, e.g. Nova, Atlas) — the owner sees and steers them by name" },
|
|
119
123
|
name: { type: "string", description: "the name for a single `task`" },
|
|
120
124
|
},
|
|
125
|
+
required: ["tasks"],
|
|
121
126
|
},
|
|
122
127
|
run: async (args) => {
|
|
123
|
-
const
|
|
128
|
+
const listed = Array.isArray(args.tasks) ? args.tasks.map((t) => String(t ?? "").trim()).filter(Boolean) : [];
|
|
129
|
+
const briefs = listed.length ? listed : [String(args.task ?? "").trim()].filter(Boolean);
|
|
124
130
|
if (!briefs.length)
|
|
125
|
-
return "error: spawn_agent needs `tasks
|
|
131
|
+
return "error: spawn_agent needs `tasks`, one full brief per sub-agent — e.g. tasks: [\"**Objective** … **Done** …\"]";
|
|
126
132
|
const names = Array.isArray(args.names) ? args.names.map((n) => String(n ?? "").trim()) : [String(args.name ?? "").trim()];
|
|
127
133
|
const thin = briefs.findIndex((b) => b.split(/\s+/).filter(Boolean).length < MIN_BRIEF_WORDS);
|
|
128
134
|
if (thin >= 0) {
|
|
@@ -327,6 +333,18 @@ function makeSkillDeactivateTool(deactivate) {
|
|
|
327
333
|
const SUMMARY_MAX_TOKENS = 1800; // room for Aurora's reasoning AND the 9-section contract before content lands
|
|
328
334
|
const SUMMARY_MAX_TOKENS_THINKING = 8000; // a Claude summarize: adaptive thinking draws on the same budget
|
|
329
335
|
const SKILL_CAP = 4000; // max chars injected from an active skill — a huge skill must not crowd working memory
|
|
336
|
+
/** A session started in the home folder works in no project: say so, so a project's checks are run from its root (11/23:
|
|
337
|
+
* a session in ~ ran `npm test` there, got "no package.json" and reported the task complete). Empty anywhere else. */
|
|
338
|
+
export function homeDirNote(cwd, home = homedir()) {
|
|
339
|
+
const norm = (p) => p.replace(/\/+$/, "");
|
|
340
|
+
if (!home || norm(cwd) !== norm(home))
|
|
341
|
+
return "";
|
|
342
|
+
// Stated as a fact about where checks count, never as a step to take: this text rides in front of the owner's first
|
|
343
|
+
// message, and "cd to its root first (the folder holding its package.json…)" made a small model answer "hello" by
|
|
344
|
+
// hunting the home folder for manifests (11/25).
|
|
345
|
+
return "\nThis is the home folder, not a project. A project's build and checks only count when run from that " +
|
|
346
|
+
"project's root; a check run here checks nothing.";
|
|
347
|
+
}
|
|
330
348
|
export class Session {
|
|
331
349
|
convo = new Conversation();
|
|
332
350
|
inner; // was readonly — /model rebuilds it for a "single" profile switch
|
|
@@ -337,6 +355,30 @@ export class Session {
|
|
|
337
355
|
dynamicModels;
|
|
338
356
|
pin; // the owner's context pin (tokens); undefined = auto — read live by the engine router
|
|
339
357
|
servedByBase = new Map(); // raw n_ctx learned per base (probeServedContext)
|
|
358
|
+
directSlots = new Map(); // slot count of a base that is itself a loopback llama-server (probeServed)
|
|
359
|
+
kvSlots = new Map(); // this conversation's slot per direct endpoint, claimed once
|
|
360
|
+
kvSession = `s_${randomUUID()}`; // this conversation's id for a router (SESSION_HEADER); a sub-agent is its own Session
|
|
361
|
+
/** How a request names this conversation so the server reuses its KV cache for the live turn, the summarizer and
|
|
362
|
+
* the rolling summary. A loopback llama-server that answered `/props` itself gets `id_slot`: a slot leased once
|
|
363
|
+
* among the Operator processes on this machine (engine/kv-slot.ts), which are all of its clients. Anything else
|
|
364
|
+
* that speaks the llama dialect is a shared door — a router or gateway with clients this machine cannot see —
|
|
365
|
+
* so it gets the session id and leases slots itself. Nothing for a vendor, or with KODE_SLOT_AFFINITY=0. */
|
|
366
|
+
affinity = (e) => {
|
|
367
|
+
if (process.env.KODE_SLOT_AFFINITY === "0" || !shipsLlamaCacheKnobs(e.base, e.transport))
|
|
368
|
+
return {};
|
|
369
|
+
const slots = this.directSlots.get(e.base);
|
|
370
|
+
const interactive = !this.background && !this.unattended; // the owner's own session: not a sub-agent, not a headless or loop run
|
|
371
|
+
if (!slots)
|
|
372
|
+
return { session: this.kvSession, sessionRole: interactive ? "interactive" : "background" };
|
|
373
|
+
const key = gateKey(e.base, e.model);
|
|
374
|
+
let slot = this.kvSlots.get(key);
|
|
375
|
+
if (slot === undefined)
|
|
376
|
+
this.kvSlots.set(key, slot = claimSlot(key, slots, interactive, this.kvSlotDir));
|
|
377
|
+
return { slot };
|
|
378
|
+
};
|
|
379
|
+
kvSlotDir;
|
|
380
|
+
probing; // the latest served-window probe; a turn waits for it before checking the floor
|
|
381
|
+
contextFloor;
|
|
340
382
|
moaConfig;
|
|
341
383
|
onDemand;
|
|
342
384
|
frontDoor;
|
|
@@ -527,10 +569,12 @@ export class Session {
|
|
|
527
569
|
this.hooks = cfg.hooks;
|
|
528
570
|
this.cwd = cfg.cwd;
|
|
529
571
|
this.unattended = cfg.unattended === true;
|
|
572
|
+
this.kvSlotDir = cfg.kvSlotDir;
|
|
530
573
|
this.maxRounds = cfg.maxRounds;
|
|
531
574
|
this.maxRoundsHard = cfg.maxRoundsHard;
|
|
532
575
|
this.compactionThreshold = cfg.compactionThreshold;
|
|
533
576
|
this.compactionCeilingTokens = cfg.compactionCeilingTokens;
|
|
577
|
+
this.contextFloor = cfg.contextFloor ?? AGENT_CTX_FLOOR;
|
|
534
578
|
this.background = cfg.background ?? false;
|
|
535
579
|
this.owner = cfg.owner;
|
|
536
580
|
this.temperature = cfg.temperature ?? 0.7;
|
|
@@ -576,8 +620,8 @@ export class Session {
|
|
|
576
620
|
sessionContextBlock() {
|
|
577
621
|
const cwd = this.cwd ?? process.cwd();
|
|
578
622
|
return `${SESSION_CONTEXT_OPEN}Working directory: ${cwd}\nScratch dir: ${scratchDirFor(cwd)}\nRelative paths and shell ` +
|
|
579
|
-
`commands resolve in the working directory. This is authoritative over any working dir named elsewhere;
|
|
580
|
-
`
|
|
623
|
+
`commands resolve in the working directory. This is authoritative over any working dir named elsewhere; files a ` +
|
|
624
|
+
`task creates go there unless the owner names another path.${homeDirNote(cwd)}${SESSION_CONTEXT_REQUEST_LINE}${SESSION_CONTEXT_CLOSE}`;
|
|
581
625
|
}
|
|
582
626
|
/** The effective system prompt: the base persona plus any memory recalled this session. Injected as ONE system
|
|
583
627
|
* prompt — never a second system message, which 400s llama.cpp's chat template. An active skill is NOT here
|
|
@@ -861,11 +905,19 @@ export class Session {
|
|
|
861
905
|
* would ride along). Best-effort — a probe that does not answer in time changes nothing. Returns the raw served
|
|
862
906
|
* window and, when the pin sits above it, the one clamp note the shell prints as a sys line (a Session has no
|
|
863
907
|
* notice channel of its own). */
|
|
864
|
-
|
|
865
|
-
const
|
|
908
|
+
probeServedContext(opts = {}) {
|
|
909
|
+
const probe = this.probeServed(opts);
|
|
910
|
+
this.probing = probe.catch(() => undefined);
|
|
911
|
+
return probe;
|
|
912
|
+
}
|
|
913
|
+
async probeServed(opts) {
|
|
914
|
+
const primary = this.inner.list()[0];
|
|
915
|
+
const base = primary?.base ?? this.inner.base;
|
|
866
916
|
if (!base || requiresOperatorToken(base) || !operatorTrustedUrl(base))
|
|
867
917
|
return { base };
|
|
868
|
-
const served = await
|
|
918
|
+
const { ctx: served, slots, direct } = await probeServed(base, { timeoutMs: opts.timeoutMs ?? 1500, fetchImpl: opts.fetchImpl, model: primary?.model });
|
|
919
|
+
if (slots && direct && !isRemoteBase(base))
|
|
920
|
+
this.directSlots.set(base, slots);
|
|
869
921
|
if (!served)
|
|
870
922
|
return { base };
|
|
871
923
|
this.servedByBase.set(base, served);
|
|
@@ -873,8 +925,21 @@ export class Session {
|
|
|
873
925
|
const out = { base, served };
|
|
874
926
|
if (this.pin && this.pin > served)
|
|
875
927
|
out.note = `context pin ${fmtCtx(this.pin)} is above the served ${served.toLocaleString("en-US")} — using ${fmtCtx(served)}`;
|
|
928
|
+
else if (this.contextFloor > 0 && served >= this.contextFloor && served < AGENT_CTX_TARGET)
|
|
929
|
+
out.note = `${this.modelId} serves ${fmtCtx(served)}; production models run at ${fmtCtx(AGENT_CTX_TARGET)} or more`;
|
|
876
930
|
return out;
|
|
877
931
|
}
|
|
932
|
+
/** The refusal for a turn on a model whose served window is known to be under settings.contextFloor, else undefined.
|
|
933
|
+
* An unknown window (no /props, no router row, a cloud leg) is not refused: there is nothing true to compare. */
|
|
934
|
+
async contextFloorRefusal() {
|
|
935
|
+
if (this.contextFloor <= 0)
|
|
936
|
+
return undefined;
|
|
937
|
+
await this.probing;
|
|
938
|
+
const served = this.servedByBase.get(this.inner.list()[0]?.base ?? this.inner.base);
|
|
939
|
+
if (served === undefined || served >= this.contextFloor)
|
|
940
|
+
return undefined;
|
|
941
|
+
return `${this.modelId} serves a ${fmtCtx(served)} context window, below the ${fmtCtx(this.contextFloor)} floor: Operator's prompt and tools alone fill ~32K, so it would compact every round. Re-serve it at ${fmtCtx(AGENT_CTX_TARGET)} or more, or pick another model with /model.`;
|
|
942
|
+
}
|
|
878
943
|
/** Cumulative tokens (prefill + output) across every turn this session — the Claude-Code-style running
|
|
879
944
|
* session total for the status rule, so the real spend is visible (not just the current completion). */
|
|
880
945
|
sessionTokens() { return this.sessionTokensTotal; }
|
|
@@ -1097,6 +1162,10 @@ export class Session {
|
|
|
1097
1162
|
this.router = this.wrap(this.inner);
|
|
1098
1163
|
}
|
|
1099
1164
|
this.modelId = profile.id;
|
|
1165
|
+
// A profile's window is often inherited (a gateway row with no ctx gets the default model's): learn the real one
|
|
1166
|
+
// before the first turn on it, so compaction sizes to it and the floor can be checked.
|
|
1167
|
+
if (profile.kind === "single" && !profile.byo)
|
|
1168
|
+
void this.probeServedContext().catch(() => undefined);
|
|
1100
1169
|
return { ok: true };
|
|
1101
1170
|
}
|
|
1102
1171
|
/** Re-point this session at a freshly built endpoint chain. The interactive shell constructs the Session at
|
|
@@ -1170,18 +1239,23 @@ export class Session {
|
|
|
1170
1239
|
}
|
|
1171
1240
|
// FAILSAFE (2026-10-22 live incident — Σ810k session wedged on "compacting context…" with no way out):
|
|
1172
1241
|
// the summarize request had only the USER's esc to stop it, so a slow/wedged endpoint on a huge evicted
|
|
1173
|
-
// span hung the whole session indefinitely — no throw, nothing for compact()'s catch to catch.
|
|
1174
|
-
//
|
|
1175
|
-
//
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const signal = this.ctrl?.signal ? AbortSignal.any([this.ctrl.signal, timeoutSignal]) : timeoutSignal;
|
|
1242
|
+
// span hung the whole session indefinitely — no throw, nothing for compact()'s catch to catch. The first
|
|
1243
|
+
// fix was a fixed 120 s wall clock, which also killed a summarizer that was still reading (2026-11-24: a
|
|
1244
|
+
// long span is minutes of prompt read before the first written token). So the limit follows progress:
|
|
1245
|
+
// abort when nothing was read or written for the stream's idle window (KODE_STREAM_IDLE_MS, 0 = off), or
|
|
1246
|
+
// at a ceiling scaled to the request (KODE_COMPACTION_SUMMARY_TIMEOUT_MS overrides it).
|
|
1179
1247
|
// The summarize request rides the SAME leg's key, wire and chat path as the live turn: a vendor row (Claude, Gemini,
|
|
1180
1248
|
// a free row) went to /v1/chat/completions with no key before, so a session on it could never compact.
|
|
1181
1249
|
const leg = [...this.inner.list(), ...(this.chain?.list() ?? [])].find((e) => e.base === sumBase && e.model === sumModel);
|
|
1182
|
-
|
|
1250
|
+
// Claude's adaptive thinking counts toward max_tokens: 1800 can be spent before the summary text starts.
|
|
1251
|
+
const maxTokens = leg?.transport === "anthropic" ? SUMMARY_MAX_TOKENS_THINKING : SUMMARY_MAX_TOKENS;
|
|
1252
|
+
const tools = this.allSchemas();
|
|
1253
|
+
const idleMs = Number(process.env.KODE_STREAM_IDLE_MS ?? 300_000);
|
|
1254
|
+
const deadline = progressDeadline(idleMs, Number(process.env.KODE_COMPACTION_SUMMARY_TIMEOUT_MS) || summaryCeilingMs(globalTokenMeter.estimateRequestFor(this.meterKey(), messages, tools), maxTokens));
|
|
1255
|
+
const signal = this.ctrl?.signal ? AbortSignal.any([this.ctrl.signal, deadline.signal]) : deadline.signal;
|
|
1256
|
+
const handlers = this.turnHandlers;
|
|
1183
1257
|
let wrote = 0;
|
|
1184
|
-
const written =
|
|
1258
|
+
const written = () => { deadline.progress(); handlers?.onCompactionWrite?.(++wrote); }; // its writing, so the line moves on from "reading" (review F2)
|
|
1185
1259
|
let r;
|
|
1186
1260
|
try {
|
|
1187
1261
|
r = await chat(messages, {
|
|
@@ -1191,34 +1265,36 @@ export class Session {
|
|
|
1191
1265
|
loopbackAuth: leg?.loopbackAuth,
|
|
1192
1266
|
transport: leg?.transport,
|
|
1193
1267
|
chatPath: leg?.chatPath,
|
|
1194
|
-
tools
|
|
1195
|
-
|
|
1196
|
-
maxTokens: leg?.transport === "anthropic" ? SUMMARY_MAX_TOKENS_THINKING : SUMMARY_MAX_TOKENS,
|
|
1268
|
+
tools, // identical tools → the span prefix-matches the live turn's cached KV
|
|
1269
|
+
maxTokens,
|
|
1197
1270
|
temperature: 0,
|
|
1198
1271
|
background: this.background, // a sub-agent's compaction summarize also yields to the interactive main turn
|
|
1272
|
+
...this.affinity({ base: sumBase, model: sumModel, transport: leg?.transport }), // the live turn's slot or session: the span is cached there
|
|
1199
1273
|
owner: "compaction",
|
|
1200
|
-
|
|
1274
|
+
onSent: deadline.progress, // the endpoint granted its slot: the idle window restarts for the request itself
|
|
1275
|
+
onPromptProgress: (p) => { deadline.progress(); handlers?.onPromptProgress?.(p); }, // the compaction line shows the summarizer's own measured read
|
|
1201
1276
|
onDelta: written,
|
|
1202
1277
|
onReasoning: written,
|
|
1203
1278
|
signal, // ESC during "compacting" must tear down THIS request too, not just the main generation stream —
|
|
1204
1279
|
// without it a compaction summarize (which can be a large request on a slow/deep endpoint) runs to
|
|
1205
|
-
// completion after the user already hit esc. Null ctrl (background pass outside a turn) →
|
|
1280
|
+
// completion after the user already hit esc. Null ctrl (background pass outside a turn) → deadline-only.
|
|
1206
1281
|
});
|
|
1207
1282
|
}
|
|
1208
1283
|
catch (e) {
|
|
1209
|
-
//
|
|
1210
|
-
//
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
`evicted without a model summary. Key facts below are from the deterministic backstop, not prose.]`;
|
|
1219
|
-
}
|
|
1284
|
+
// A limit (not the user's esc, not a transport error) throws the limit that was hit, so compact() keeps the
|
|
1285
|
+
// history and the owner reads "no progress for 300 s", not "errored". The stream's own watchdog reads the same
|
|
1286
|
+
// idle window and can notice a silent endpoint first: that is the same limit, so it is the same error.
|
|
1287
|
+
if (this.ctrl?.signal?.aborted)
|
|
1288
|
+
throw e;
|
|
1289
|
+
if (deadline.signal.aborted)
|
|
1290
|
+
throw deadline.signal.reason;
|
|
1291
|
+
if (e instanceof Error && /stream stalled/.test(e.message))
|
|
1292
|
+
throw new DeadlineError("idle", idleMs);
|
|
1220
1293
|
throw e;
|
|
1221
1294
|
}
|
|
1295
|
+
finally {
|
|
1296
|
+
deadline.clear();
|
|
1297
|
+
}
|
|
1222
1298
|
// Return "" on a genuinely empty response so compact()'s empty-summary guard fires and PRESERVES history
|
|
1223
1299
|
// rather than replacing it with a useless placeholder — the old "(summary unavailable)" sentinel was
|
|
1224
1300
|
// non-empty, so it DEFEATED that guard and could silently destroy the evicted span. A summary is never
|
|
@@ -1363,6 +1439,9 @@ export class Session {
|
|
|
1363
1439
|
shutdown() {
|
|
1364
1440
|
this.hub?.shutdown();
|
|
1365
1441
|
this.disposeShell();
|
|
1442
|
+
for (const [key, slot] of this.kvSlots)
|
|
1443
|
+
releaseSlot(key, slot, this.kvSlotDir);
|
|
1444
|
+
this.kvSlots.clear();
|
|
1366
1445
|
this.sleepScheduler?.dispose(); // tear down the sleep consolidation scheduler
|
|
1367
1446
|
}
|
|
1368
1447
|
/** Kill just this session's persistent shell — call when a background sub-agent finishes so its
|
|
@@ -1425,6 +1504,9 @@ export class Session {
|
|
|
1425
1504
|
const active = findModel(this.liveRegistry(), this.modelId);
|
|
1426
1505
|
if (active?.kind === "orchestrated")
|
|
1427
1506
|
return await this.sendMoa(text, h, active);
|
|
1507
|
+
const refusal = await this.contextFloorRefusal();
|
|
1508
|
+
if (refusal)
|
|
1509
|
+
return { content: refusal, display: refusal, rounds: 0, toolCalls: 0, interrupted: false, stopKind: "context_floor" };
|
|
1428
1510
|
const sys = this.sysWithThink();
|
|
1429
1511
|
const sysForTurn = turnDirective ? `${sys ?? ""}${turnDirective}` : sys;
|
|
1430
1512
|
return await this.sendWithFastStart(text, h, sysForTurn);
|
|
@@ -1592,6 +1674,7 @@ export class Session {
|
|
|
1592
1674
|
pinnedContext: () => this.pinned(), // a summary is a rewrite anyway: the skill and Autonomous mode's rules ride it
|
|
1593
1675
|
preservedState: this.background ? undefined : () => renderActiveTasks() ?? undefined, // a mid-turn compaction keeps the active task list — the FOREGROUND's; the list is one module store, so a sub-agent must not see (or close on) the owner's items
|
|
1594
1676
|
background: this.background, // endpoint gate: a sub-agent's rounds yield the shared slot to the main turn
|
|
1677
|
+
affinity: this.affinity,
|
|
1595
1678
|
liveSubAgents: this.wakeTurn ? this.liveAgents : undefined, // a wake turn with sub-agents live yields from its first idle round
|
|
1596
1679
|
slotSharers: this.slotSharers, // …but only to sub-agents on THIS model's slot; children on another server never make it yield
|
|
1597
1680
|
maxTokens: this.maxTokens,
|
|
@@ -1602,7 +1685,7 @@ export class Session {
|
|
|
1602
1685
|
unattended: this.unattended, // headless runs hard-stop a tool loop by default; interactive sessions only warn
|
|
1603
1686
|
maxRounds: this.maxRounds, // soft round budget from settings.maxRounds (undefined → runTurn default)
|
|
1604
1687
|
maxRoundsHard: this.maxRoundsHard, // absolute ceiling; undefined → runTurn default 400, tighter for bg sub-agents
|
|
1605
|
-
compactionThreshold: this.compactionThreshold, // settings.compaction.threshold; undefined →
|
|
1688
|
+
compactionThreshold: this.compactionThreshold, // settings.compaction.threshold; undefined → derived from the served window
|
|
1606
1689
|
compactionCeilingTokens: this.compactionCeilingTokens, // settings.compaction.ceilingTokens; undefined → no absolute ceiling
|
|
1607
1690
|
temperature: this.temperature,
|
|
1608
1691
|
thinking: () => !this.turnThinkOff && this.thinkMode !== "off", // /think, /ultrathink re-enable native reasoning — read per request, so a mid-turn /think applies from the next call; "continue, think off" turns it off for one turn without touching the prompt
|
package/dist/skills/catalogue.js
CHANGED
|
@@ -155,6 +155,8 @@ export async function runSkillCatalog(args) {
|
|
|
155
155
|
shown.map((e) => `${e.name} [${e.category}] — ${e.description}`).join("\n") +
|
|
156
156
|
(matched.length > shown.length ? `\n… +${matched.length - shown.length} more — refine with query` : "");
|
|
157
157
|
}
|
|
158
|
+
if ((action === "install" || action === "remove") && !args.name)
|
|
159
|
+
return `skill_catalog: ${action} needs \`name\` — an exact name from browse`;
|
|
158
160
|
if (action === "install")
|
|
159
161
|
return await installSkill(String(args.name ?? ""));
|
|
160
162
|
if (action === "remove")
|
package/dist/skills/finder.js
CHANGED
|
@@ -219,5 +219,5 @@ export function draftSkillPrompt(name, description) {
|
|
|
219
219
|
return `Write a new skill named "${slug}" for this: ${oneLine(description) || slug}. Make it a reusable playbook: a one-line ` +
|
|
220
220
|
`description, "When to use", concrete "Steps" (exact commands, files, checks) and how to verify it worked. Check the existing ` +
|
|
221
221
|
`catalogue first (skill_list "${oneLine(description).slice(0, 60) || slug}") and build on the closest match instead of starting over. ` +
|
|
222
|
-
`Save it with skill_save name="${slug}", then tell me in one line what it covers.`;
|
|
222
|
+
`Save it with skill_save name="${slug}" (both tools on demand), then tell me in one line what it covers.`;
|
|
223
223
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// How a shell result says its command went to a background job, and how bash_output says that job ended. One definition
|
|
2
|
+
// for the tool layer that writes the text (registry.ts) and the engine that reads it (verify-gate.ts): on 11/24 the gate
|
|
3
|
+
// knew only the first prefix, so an auto-backgrounded `npm test` counted as a passed check. Dependency-free leaf, like mutating.ts.
|
|
4
|
+
export const MOVED_TO_BACKGROUND = "moved to background as ";
|
|
5
|
+
export const AUTO_BACKGROUNDED = "[auto-backgrounded: ";
|
|
6
|
+
export const STARTED_BACKGROUND_JOB = "started background job ";
|
|
7
|
+
/** True when the command is still running as a background job: it has produced no result yet. */
|
|
8
|
+
export const stillInBackground = (result) => {
|
|
9
|
+
const r = result.trimStart();
|
|
10
|
+
return r.startsWith(MOVED_TO_BACKGROUND) || r.startsWith(AUTO_BACKGROUNDED);
|
|
11
|
+
};
|
|
12
|
+
/** The id of the job a backgrounded command's result names. */
|
|
13
|
+
export const backgroundJobId = (result) => {
|
|
14
|
+
const r = result.trimStart();
|
|
15
|
+
const rest = r.startsWith(MOVED_TO_BACKGROUND) ? r.slice(MOVED_TO_BACKGROUND.length)
|
|
16
|
+
: r.startsWith(STARTED_BACKGROUND_JOB) ? r.slice(STARTED_BACKGROUND_JOB.length)
|
|
17
|
+
: r.startsWith(AUTO_BACKGROUNDED) ? r.slice(r.indexOf("\n" + STARTED_BACKGROUND_JOB) + 1 + STARTED_BACKGROUND_JOB.length) : "";
|
|
18
|
+
return rest.match(/^sh\d+/)?.[0];
|
|
19
|
+
};
|
|
20
|
+
/** bash_output's first line for a job that has ended. `code` is null when it was killed or its shell died. */
|
|
21
|
+
export const jobFinishedLine = (id, code) => `[job ${id} finished — exit ${code}]`;
|
|
22
|
+
/** The job and exit code a bash_output result reports, once the job has ended (-1: it ended without an exit code). */
|
|
23
|
+
export const finishedJob = (result) => {
|
|
24
|
+
const m = result.match(/^\[job (sh\d+) finished — exit (-?\d+|null)\]/);
|
|
25
|
+
return m ? { id: m[1], exit: m[2] === "null" ? -1 : Number(m[2]) } : undefined;
|
|
26
|
+
};
|