@0perator/operator 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/auth/commands.js +7 -3
- package/dist/auth/identity.js +1 -0
- package/dist/auth/staff.js +55 -0
- package/dist/autonomy/delegate-mode.js +2 -2
- package/dist/autonomy/delegate.js +41 -14
- package/dist/autonomy/headless.js +7 -4
- package/dist/autonomy/index.js +2 -4
- package/dist/autonomy/session-factory.js +11 -12
- package/dist/autonomy/subagent-model.js +17 -7
- package/dist/background/capacity.js +136 -0
- package/dist/background/evidence.js +42 -0
- package/dist/background/index.js +311 -44
- package/dist/background/lane-phase.js +60 -0
- package/dist/background/lane-summary.js +151 -0
- package/dist/background/notices.js +12 -3
- package/dist/background/synthesis.js +25 -0
- package/dist/bus/inbox.js +150 -6
- package/dist/cli.js +191 -96
- package/dist/config/features.js +3 -3
- package/dist/config/persona.js +29 -3
- package/dist/config/settings.js +261 -20
- package/dist/config/staff-prompt.js +12 -0
- package/dist/engine/agent.js +51 -40
- package/dist/engine/aurora.js +36 -4
- package/dist/engine/batch-scheduler.js +4 -13
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/continuation.js +30 -32
- package/dist/engine/decision-points.js +2 -3
- package/dist/engine/fanout.js +16 -0
- package/dist/engine/loop-guard.js +26 -83
- package/dist/engine/messages.js +2 -2
- package/dist/engine/moa.js +16 -1
- package/dist/engine/native-vision-node.js +72 -0
- package/dist/engine/native-vision.js +103 -0
- package/dist/engine/verify-gate.js +37 -7
- package/dist/gateway-cli.js +14 -3
- package/dist/memory/live-progress.js +4 -5
- package/dist/moa/codeact-lane.js +98 -0
- package/dist/moa/codeact-sandbox.js +409 -0
- package/dist/moa/codeact.js +140 -0
- package/dist/permissions/artifact-visibility.js +10 -0
- package/dist/permissions/tier.js +4 -2
- package/dist/products/craft.js +2 -2
- package/dist/remote/grants.js +119 -0
- package/dist/remote/host.js +33 -5
- package/dist/router/models.js +24 -14
- package/dist/selfimprove/index.js +8 -6
- package/dist/services/preflight.js +35 -91
- package/dist/session.js +127 -41
- package/dist/skills/install-guard.js +68 -0
- package/dist/skills/install.js +67 -0
- package/dist/toolchain/manifest.json +13 -13
- package/dist/tools/background-result.js +1 -1
- package/dist/tools/classes.js +103 -0
- package/dist/tools/contract.js +1 -1
- package/dist/tools/craft.js +13 -2
- package/dist/tools/executor.js +25 -15
- package/dist/tools/generation-gateway.js +94 -0
- package/dist/tools/registry.js +83 -152
- package/dist/ui/App.js +15 -4
- package/dist/ui/BgPanel.js +15 -10
- package/dist/ui/Header.js +1 -6
- package/dist/ui/StatusRule.js +18 -7
- package/dist/ui/ToolStep.js +3 -3
- package/dist/ui/Transcript.js +36 -14
- package/dist/ui/batchLine.js +4 -4
- package/dist/ui/editdiff.js +2 -4
- package/dist/ui/format.js +4 -20
- package/dist/ui/liveTools.js +3 -3
- package/dist/ui/opsMode.js +20 -0
- package/dist/ui/types.js +0 -2
- package/dist/update-check.js +17 -6
- package/package.json +1 -1
- package/dist/tools/mutating.js +0 -15
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
// (there is no launchd; ensureServices returns everything "down" and the caller reports it).
|
|
6
6
|
//
|
|
7
7
|
// TWO tiers, and the split is the whole point:
|
|
8
|
-
// • Aurora
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// the published endpoint and reports `idle` for a local job that is not serving. Operator only ever brings
|
|
12
|
-
// it UP; it NEVER stops Aurora on exit, because that would break every other client.
|
|
8
|
+
// • Aurora (co.0perator.gateway) is RETIRED (11/25): Operator never starts it — not at boot, not for a turn, not
|
|
9
|
+
// from /services. auroraAtBoot only resolves the published endpoint (server.json) and reports; `operator gateway
|
|
10
|
+
// start` refuses without --force. Operator also never stops it on exit.
|
|
13
11
|
// • autopilot (:9333) is optional and handled the same start-only way (non-fatal if it won't come up).
|
|
14
12
|
// • vision (:7788, axe.vision-bot) is OFF BY DEFAULT — the media-pipeline ADR (2026-10-19) keeps the
|
|
15
13
|
// GPU with Aurora, so boot only PROBES + reports it (settings DEFAULTS ship autostart:false). Nothing
|
|
@@ -118,8 +116,9 @@ async function ensureLaunchd(name, healthUrl, okOnly, cfg, onProgress) {
|
|
|
118
116
|
: { name, state: "down", detail: `started the launchd job but ${name} did not report ready at ${healthUrl} within ${waitSec}s` };
|
|
119
117
|
}
|
|
120
118
|
/** Start `name`'s launchd job: kickstart -k when it is loaded, else bootout any half-state and bootstrap the plist
|
|
121
|
-
* fresh. Returns the report when it will not start it (autostart off, no label/uid, plist missing), else null.
|
|
122
|
-
|
|
119
|
+
* fresh. Returns the report when it will not start it (autostart off, no label/uid, plist missing), else null.
|
|
120
|
+
* Optional companions only (autopilot, vision): nothing calls it for Aurora. */
|
|
121
|
+
export async function kickLaunchd(name, cfg, onProgress) {
|
|
123
122
|
if (cfg.autostart === false)
|
|
124
123
|
return { name, state: "down", detail: "down (autostart off)" };
|
|
125
124
|
cfg = await withLegacyLabel(cfg);
|
|
@@ -141,7 +140,10 @@ async function kickLaunchd(name, cfg, onProgress) {
|
|
|
141
140
|
}
|
|
142
141
|
const run = cfg.launchctl ?? launchctl;
|
|
143
142
|
const disabled = await run(["print-disabled", `gui/${uid}`]);
|
|
144
|
-
|
|
143
|
+
// Fail closed: when launchd's disabled list cannot be read, the owner's `launchctl disable` cannot be honored, so nothing starts.
|
|
144
|
+
if (disabled.code !== 0)
|
|
145
|
+
return { name, state: "down", detail: `down (cannot read launchd's disabled list for ${label} — not starting it)` };
|
|
146
|
+
if (isLaunchdDisabled(disabled.out, label))
|
|
145
147
|
return { name, state: "disabled", detail: disabledLine(name, label) };
|
|
146
148
|
onProgress?.(`starting ${name} via launchd…`);
|
|
147
149
|
const target = `gui/${uid}/${label}`;
|
|
@@ -188,90 +190,45 @@ const auroraHealth = (base) => (base ? `${base.replace(/\/$/, "")}/health` : "")
|
|
|
188
190
|
function applyDiscovered(cfg, d) {
|
|
189
191
|
if (!d)
|
|
190
192
|
return;
|
|
191
|
-
|
|
193
|
+
const found = normBase(d.base);
|
|
194
|
+
if (cfg.base && !gatewayBases.has(normBase(cfg.base)) && normBase(cfg.base) !== found)
|
|
195
|
+
return; // an explicit endpoint (the router, a remote) is not the gateway's to overwrite
|
|
196
|
+
gatewayBases.add(found);
|
|
197
|
+
cfg.base = found;
|
|
192
198
|
if (d.apiKey)
|
|
193
199
|
cfg.apiKey = d.apiKey;
|
|
194
200
|
}
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
const normBase = (b) => b.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
202
|
+
/** Every base this process has resolved from the gateway's server.json: the endpoints that ARE the local gateway. */
|
|
203
|
+
const gatewayBases = new Set();
|
|
204
|
+
/** True iff the endpoint is the local gateway: unset (auto-discover) or a base resolved from its server.json. Any other
|
|
205
|
+
* base (the router's `main`, a remote or tester endpoint) is served by something else, so a miss there is `down`, not
|
|
206
|
+
* `idle`. Call after applyDiscovered. */
|
|
207
|
+
function servedByLocalGateway(base) {
|
|
208
|
+
return !base || gatewayBases.has(normBase(base));
|
|
209
|
+
}
|
|
210
|
+
/** True iff Aurora is a launchd job on this box (its plist, or a legacy one, is on disk). A remote or tester endpoint has
|
|
211
|
+
* no job here and keeps the old health-gated report. */
|
|
197
212
|
async function localAuroraJob(cfg) {
|
|
198
213
|
const job = await withLegacyLabel(cfg);
|
|
199
214
|
return !!job.launchdLabel && !!job.plistPath && (await fileExists(expandHome(job.plistPath)));
|
|
200
215
|
}
|
|
201
216
|
/** Boot's view of Aurora: resolve the published endpoint and report, never start the gateway. A local job that is not
|
|
202
|
-
* serving is `idle` (
|
|
217
|
+
* serving is `idle` (retired: nothing loads it); with no local job it is `down`, as before. */
|
|
203
218
|
export async function auroraAtBoot(cfg) {
|
|
204
219
|
applyDiscovered(cfg, await discoverAuroraServer());
|
|
205
220
|
const state = cfg.base ? await probe(auroraHealth(cfg.base), true) : "refused";
|
|
206
221
|
if (state === "ready")
|
|
207
222
|
return { name: "aurora", state: "up" };
|
|
208
|
-
if (await localAuroraJob(cfg))
|
|
209
|
-
return { name: "aurora", state: "idle", detail: state === "loading" ? "loading" : "
|
|
223
|
+
if (servedByLocalGateway(cfg.base) && (await localAuroraJob(cfg)))
|
|
224
|
+
return { name: "aurora", state: "idle", detail: state === "loading" ? "loading" : "not serving (retired — Operator does not start it)" };
|
|
210
225
|
return { name: "aurora", state: "down", detail: cfg.base ? `no response from ${cfg.base}` : "no gateway endpoint published" };
|
|
211
226
|
}
|
|
212
|
-
/**
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const first = cfg.base ? await probe(auroraHealth(cfg.base), true) : "refused";
|
|
216
|
-
if (first === "ready")
|
|
217
|
-
return { name: "aurora", state: "up" };
|
|
218
|
-
if (first === "loading")
|
|
219
|
-
onProgress?.("aurora is loading…");
|
|
220
|
-
else {
|
|
221
|
-
const refused = await kickLaunchd("aurora", cfg, onProgress);
|
|
222
|
-
if (refused)
|
|
223
|
-
return refused;
|
|
224
|
-
}
|
|
225
|
-
const waitSec = cfg.waitSec ?? 90;
|
|
226
|
-
return (await waitForAurora(cfg, waitSec, signal))
|
|
227
|
-
? { name: "aurora", state: first === "loading" ? "up" : "started" }
|
|
228
|
-
: { name: "aurora", state: "down", detail: `aurora did not report ready within ${waitSec}s` };
|
|
229
|
-
}
|
|
230
|
-
/** Poll until the published endpoint answers /health, re-reading server.json each time: the gateway publishes its
|
|
231
|
-
* base only once llama-server is spawned and deletes server.json when it stops, so a base read before the kick is
|
|
232
|
-
* stale or absent. Polling that one is the 11/03 boot that sat 90 s on "starting aurora via launchd…" with Aurora
|
|
233
|
-
* ready after 16 s. */
|
|
234
|
-
export async function waitForAurora(cfg, waitSec, signal) {
|
|
235
|
-
for (let waited = 0;; waited += 2) {
|
|
236
|
-
applyDiscovered(cfg, await discoverAuroraServer());
|
|
237
|
-
if (cfg.base && (await probe(auroraHealth(cfg.base), true)) === "ready")
|
|
238
|
-
return true;
|
|
239
|
-
if (waited >= waitSec || signal?.aborted)
|
|
240
|
-
return false;
|
|
241
|
-
await new Promise((res) => setTimeout(res, 2000));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/** The Session's onDemand hook for a local Aurora: before a turn on the default model, make sure the gateway is
|
|
245
|
-
* serving (start it if not), and when its published base or key changed write them onto `endpoint` and return
|
|
246
|
-
* `rebuild()`. Inert where Aurora is not a local launchd job, so a remote endpoint is never probed per turn. */
|
|
247
|
-
export function auroraOnDemand(endpoint, svc, rebuild, onProgress, onDisabled) {
|
|
248
|
-
let local;
|
|
249
|
-
let told = false;
|
|
250
|
-
return async (signal) => {
|
|
251
|
-
local ??= localAuroraJob(svc ?? {});
|
|
252
|
-
if (!(await local))
|
|
253
|
-
return null;
|
|
254
|
-
const cfg = { ...svc, base: endpoint.base, apiKey: endpoint.apiKey };
|
|
255
|
-
const report = await ensureAurora(cfg, onProgress, signal);
|
|
256
|
-
if (report.state === "disabled") {
|
|
257
|
-
if (!told && report.detail)
|
|
258
|
-
onDisabled?.(report.detail); // once per session: the router's next leg answers every turn
|
|
259
|
-
told = true;
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
if (cfg.base === endpoint.base && cfg.apiKey === endpoint.apiKey)
|
|
263
|
-
return null;
|
|
264
|
-
endpoint.base = cfg.base;
|
|
265
|
-
if (cfg.apiKey)
|
|
266
|
-
endpoint.apiKey = cfg.apiKey;
|
|
267
|
-
return rebuild();
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
/** Ensure the services Operator depends on are up. Aurora first (required, health-gated; with auroraOnDemand only
|
|
271
|
-
* resolved and reported); autopilot and vision are optional and never block. Returns one report per service for the
|
|
272
|
-
* boot UI. Mutates cfg.aurora.base in-place when the dynamic port is discovered from server.json. */
|
|
227
|
+
/** Ensure the services Operator depends on are up. Aurora is only resolved and reported (auroraAtBoot); autopilot and
|
|
228
|
+
* vision are optional and never block. Returns one report per service for the boot UI. Mutates cfg.aurora.base
|
|
229
|
+
* in-place when the dynamic port is discovered from server.json. */
|
|
273
230
|
export async function ensureServices(cfg) {
|
|
274
|
-
const reports = [
|
|
231
|
+
const reports = [await auroraAtBoot(cfg.aurora)];
|
|
275
232
|
if (cfg.autopilot) {
|
|
276
233
|
reports.push(await ensureOptional("autopilot", cfg.autopilot, cfg.onProgress));
|
|
277
234
|
}
|
|
@@ -303,21 +260,8 @@ async function installCompanion(name) {
|
|
|
303
260
|
}
|
|
304
261
|
catch { /* installer unavailable — the boot already skipped cleanly, nothing else to do */ }
|
|
305
262
|
}
|
|
306
|
-
/**
|
|
307
|
-
*
|
|
308
|
-
* Fire-and-forget: never awaited from boot, never throws — a failed warmup just means the old behavior. */
|
|
309
|
-
export async function warmAurora(base, model) {
|
|
310
|
-
try {
|
|
311
|
-
await fetch(`${base.replace(/\/$/, "")}/v1/chat/completions`, {
|
|
312
|
-
method: "POST",
|
|
313
|
-
headers: { "content-type": "application/json" },
|
|
314
|
-
body: JSON.stringify({ model, messages: [{ role: "user", content: "warmup" }], max_tokens: 1, temperature: 0 }),
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
catch { /* best-effort — warmup failing just restores the cold-first-turn behavior */ }
|
|
318
|
-
}
|
|
319
|
-
/** Tear down ONLY the session-scoped services on exit. Aurora and autopilot are shared, always-on, and
|
|
320
|
-
* owned by launchd — Operator never stops them (other clients depend on :8097). SearXNG is the one
|
|
263
|
+
/** Tear down ONLY the session-scoped services on exit. Aurora and autopilot are shared and owned by launchd —
|
|
264
|
+
* Operator never stops them. SearXNG is the one
|
|
321
265
|
* service Operator owns end to end. Best-effort; safe to call more than once. */
|
|
322
266
|
export async function stopSessionServices(opts) {
|
|
323
267
|
if (opts?.searxng === false)
|
package/dist/session.js
CHANGED
|
@@ -6,6 +6,11 @@ import { recordTruncation } from "./observability/blackbox.js";
|
|
|
6
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
8
|
import { homedir } from "node:os";
|
|
9
|
+
import { detectVision, markVisionRejected } from "./engine/native-vision.js";
|
|
10
|
+
import { extractImagePaths } from "./engine/native-vision-node.js";
|
|
11
|
+
import { planFanOut } from "./engine/fanout.js";
|
|
12
|
+
import { withCodeActDelegateSchema } from "./moa/codeact-lane.js";
|
|
13
|
+
import { codeActEnabled } from "./moa/codeact.js";
|
|
9
14
|
import { chat, health, reachable, gateKey, isRemoteBase, shipsLlamaCacheKnobs, requiresOperatorToken, operatorTrustedUrl } from "./engine/aurora.js";
|
|
10
15
|
import { claimSlot, releaseSlot } from "./engine/kv-slot.js";
|
|
11
16
|
import { randomUUID } from "node:crypto";
|
|
@@ -26,12 +31,13 @@ import { routeShadowTurn, shadowPrompt } from "./moa/shadow.js"; // MOA phase-0
|
|
|
26
31
|
import { AuroraRouter } from "./router/router.js";
|
|
27
32
|
import { operatorAgentPersona } from "./config/operator-harness.js";
|
|
28
33
|
import { progressDeadline, summaryCeilingMs, DeadlineError } from "./engine/progress-deadline.js";
|
|
29
|
-
import { modelRegistry, findModel, fallbackProfile, selectModel, visibleModels, endpointBase, profileEndpoint, fmtCtx, MIN_CONTEXT_PIN, AGENT_CTX_FLOOR, AGENT_CTX_TARGET,
|
|
34
|
+
import { modelRegistry, findModel, fallbackProfile, selectModel, visibleModels, endpointBase, profileEndpoint, fmtCtx, MIN_CONTEXT_PIN, AGENT_CTX_FLOOR, AGENT_CTX_TARGET, CHAIN_MODEL_ID, LEAN_HARNESS_CTX, resolveModel } from "./router/models.js";
|
|
30
35
|
import { probeServed, usableCtx } from "./router/discovery.js";
|
|
31
36
|
import { FAST_START_INSTRUCTION, parseFastStartReply } from "./engine/fast-start.js";
|
|
32
37
|
import { askFrontDoor, recentTurns } from "./engine/front-door.js";
|
|
33
38
|
import { getByoToken, hasByoToken } from "./auth/byo.js";
|
|
34
39
|
import { Executor } from "./tools/executor.js";
|
|
40
|
+
import { autoDeliverReport, autoDeliverFailure, wakeRoot } from "./bus/inbox.js";
|
|
35
41
|
import { toSchemas, registry, disposeShellSessionKey, requestShellDetach, cloudAgentToolsFor, mdocToolsFor, craftToolsFor, renderActiveTasks, getAgentTasks, taskPlanRevision, openTaskCount } from "./tools/registry.js";
|
|
36
42
|
import { isFeatureEnabled } from "./config/features.js";
|
|
37
43
|
import { MemoryStore } from "./memory/index.js";
|
|
@@ -95,12 +101,12 @@ export function renderBudgetBlock(b) {
|
|
|
95
101
|
/** A brief shorter than this is not a brief (10/31: a sub-agent was spawned with the objective "agent"). 12 refused a
|
|
96
102
|
* complete 11-word brief in the e2e ("Create the file …/nova.md containing exactly three lines: red, green, blue"). */
|
|
97
103
|
const MIN_BRIEF_WORDS = 5;
|
|
98
|
-
function makeSpawnTool(handler) {
|
|
104
|
+
export function makeSpawnTool(handler, slots) {
|
|
99
105
|
return {
|
|
100
106
|
name: "spawn_agent",
|
|
101
107
|
safe: false,
|
|
102
108
|
description: "Spawn sub-agents: isolated sessions, each with its own shell, on the sub-agent model (the result says which). " +
|
|
103
|
-
"One `tasks` entry = one sub-agent; several run in parallel
|
|
109
|
+
"One `tasks` entry = one sub-agent; several run in parallel as capacity allows. Make THIS call in " +
|
|
104
110
|
"the same round you decide to delegate, and in that message tell the owner who you are sending and why (one line " +
|
|
105
111
|
"per agent). You stay the lead: do what does NOT depend on them; never redo, re-spawn or poll for a step one is " +
|
|
106
112
|
"working on — each report, and a STUCK notice if one stalls, arrives as a message at the start of a later turn. " +
|
|
@@ -113,7 +119,8 @@ function makeSpawnTool(handler) {
|
|
|
113
119
|
"RULES: the sub-agent knows NOTHING of this conversation — brief it as a spec: **Objective** · **Context** " +
|
|
114
120
|
"(every path, id, fact) · **Deliverable** · **Constraints** · **Done**. A file deliverable needs role code-edit or " +
|
|
115
121
|
"generic. A report is a SELF-REPORT — open what it produced and check it against Done before you tell the owner. " +
|
|
116
|
-
"SINGLE WRITER: keep file edits on one agent. Ask for a CONCISE report (~1-2k tokens) listing the files it wrote."
|
|
122
|
+
"SINGLE WRITER: keep file edits on one agent. Ask for a CONCISE report (~1-2k tokens) listing the files it wrote. " +
|
|
123
|
+
"You wake when every agent not in `optional` has reported. Give each agent its own slice of a large input.",
|
|
117
124
|
parameters: {
|
|
118
125
|
type: "object",
|
|
119
126
|
properties: {
|
|
@@ -123,6 +130,8 @@ function makeSpawnTool(handler) {
|
|
|
123
130
|
agent: { type: "string", description: "optional repo-local persona from .operator/agents/ (listed under 'Repo-local harness')" },
|
|
124
131
|
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" },
|
|
125
132
|
name: { type: "string", description: "the name for a single `task`" },
|
|
133
|
+
optional: { type: "array", items: { type: "string" }, description: "names not waited on (reported missing if late)" },
|
|
134
|
+
deadline_minutes: { type: "number", description: "due time, shown on each lane" },
|
|
126
135
|
},
|
|
127
136
|
required: ["tasks"],
|
|
128
137
|
},
|
|
@@ -146,11 +155,25 @@ function makeSpawnTool(handler) {
|
|
|
146
155
|
const frame = (task) => !agent ? task : persona
|
|
147
156
|
? `You are acting as the "${agent}" sub-agent for this repo. Follow this persona:\n\n${persona}\n\n---\nYour task:\n${task}`
|
|
148
157
|
: `${task}\n\n(note: no .operator/agents/${agent}.md persona found — ran without it)`;
|
|
158
|
+
const optional = new Set(Array.isArray(args.optional) ? args.optional.map((n) => String(n ?? "").trim().toLowerCase()) : []);
|
|
159
|
+
const mins = Number(args.deadline_minutes);
|
|
160
|
+
const opts = (i) => ({
|
|
161
|
+
...(names[i] && optional.has(names[i].toLowerCase()) ? { optional: true } : {}),
|
|
162
|
+
...(Number.isFinite(mins) && mins > 0 ? { deadlineMs: Math.round(mins * 60_000) } : {}),
|
|
163
|
+
});
|
|
149
164
|
if (briefs.length === 1)
|
|
150
|
-
return handler(frame(briefs[0]), role, names[0] || undefined);
|
|
165
|
+
return handler(frame(briefs[0]), role, names[0] || undefined, opts(0));
|
|
166
|
+
const free = role === "code-edit" ? undefined : slots?.();
|
|
167
|
+
if (free !== undefined) {
|
|
168
|
+
const { spawn } = planFanOut(briefs.map(() => ({ kind: "read" })), free);
|
|
169
|
+
const go = new Set(spawn);
|
|
170
|
+
return briefs.map((t, i) => `[${i + 1}/${briefs.length}] ${go.has(i)
|
|
171
|
+
? handler(frame(t), role, names[i] || undefined, opts(i))
|
|
172
|
+
: `not spawned: no free lane on the sub-agent route — do this step yourself (${(names[i] || t).slice(0, 60)})`}`).join("\n");
|
|
173
|
+
}
|
|
151
174
|
// Fan-out: one spawn per brief, in order; the manager queues past its running cap and refuses past the
|
|
152
175
|
// in-flight cap — each line reports what happened to that brief, so a partial fan-out is never silent.
|
|
153
|
-
return briefs.map((t, i) => `[${i + 1}/${briefs.length}] ${handler(frame(t), role, names[i] || undefined)}`).join("\n");
|
|
176
|
+
return briefs.map((t, i) => `[${i + 1}/${briefs.length}] ${handler(frame(t), role, names[i] || undefined, opts(i))}`).join("\n");
|
|
154
177
|
},
|
|
155
178
|
};
|
|
156
179
|
}
|
|
@@ -382,13 +405,13 @@ export class Session {
|
|
|
382
405
|
probing; // the latest served-window probe; a turn waits for it before checking the floor
|
|
383
406
|
contextFloor;
|
|
384
407
|
moaConfig;
|
|
385
|
-
onDemand;
|
|
386
408
|
frontDoor;
|
|
387
409
|
frontDoorRoute; // the gateway's call on THIS turn (null = no answer; undefined = not asked), read by sendMoa
|
|
388
410
|
classifier;
|
|
389
411
|
fastStartConfig;
|
|
390
412
|
fastStartEnabled;
|
|
391
|
-
modelId =
|
|
413
|
+
modelId = CHAIN_MODEL_ID; // active /model selection
|
|
414
|
+
modelNote; // the startup pick was a retired row: one line for the shell (takeModelNote)
|
|
392
415
|
turnFellBack = false; // this turn's model fallback took over (turnModel): its rounds run on the default row
|
|
393
416
|
executor;
|
|
394
417
|
shellKey; // this session's persistent-shell key (see disposeShell)
|
|
@@ -438,6 +461,8 @@ export class Session {
|
|
|
438
461
|
owner;
|
|
439
462
|
temperature;
|
|
440
463
|
ctrl = null;
|
|
464
|
+
/** The image files this turn's message carries natively (nativeImagesFor); empty when the model cannot see them. */
|
|
465
|
+
turnImages = [];
|
|
441
466
|
memory;
|
|
442
467
|
wantRecall;
|
|
443
468
|
recallBlock = ""; // memory recalled on the first turn, folded into the system prompt thereafter
|
|
@@ -497,9 +522,9 @@ export class Session {
|
|
|
497
522
|
// here only when the flag resolves on — so both dispatch (executor) and the advertised schemas include them iff enabled.
|
|
498
523
|
const cloudTools = cloudAgentToolsFor({ features: cfg.features });
|
|
499
524
|
const mdocTools = mdocToolsFor({ features: cfg.features }); // flag-gated product tools (feature `mdoc`, default OFF)
|
|
500
|
-
const craftTools = craftToolsFor({ features: cfg.features }); //
|
|
525
|
+
const craftTools = craftToolsFor({ features: cfg.features }); // artifact library (always) + craft_create (feature `craft`)
|
|
501
526
|
if (cfg.spawnAgent)
|
|
502
|
-
reg.set("spawn_agent", makeSpawnTool(cfg.spawnAgent));
|
|
527
|
+
reg.set("spawn_agent", makeSpawnTool(cfg.spawnAgent, cfg.spawnSlots));
|
|
503
528
|
if (cfg.messageAgent)
|
|
504
529
|
reg.set("message_agent", makeMessageTool(cfg.messageAgent));
|
|
505
530
|
if (cfg.agentStatus)
|
|
@@ -535,6 +560,12 @@ export class Session {
|
|
|
535
560
|
}
|
|
536
561
|
for (const name of cfg.toolDeny ?? [])
|
|
537
562
|
reg.delete(name);
|
|
563
|
+
for (const t of cfg.extraTools ?? [])
|
|
564
|
+
reg.set(t.name, t);
|
|
565
|
+
// The MoA CodeAct lane (moa/codeact.ts): only while it is on does delegate_task offer it, so the schema is unchanged off.
|
|
566
|
+
const dt = reg.get("delegate_task");
|
|
567
|
+
if (dt && cfg.moa && codeActEnabled(cfg.moa.codeact))
|
|
568
|
+
reg.set("delegate_task", withCodeActDelegateSchema(dt));
|
|
538
569
|
this.executor = new Executor(reg, cfg.cwd, cfg.sessionId);
|
|
539
570
|
this.shellKey = this.executor.shellKey; // for disposeShell() on teardown
|
|
540
571
|
this.localSchemas = toSchemas(reg);
|
|
@@ -551,7 +582,6 @@ export class Session {
|
|
|
551
582
|
this.registry = modelRegistry(cfg.models);
|
|
552
583
|
this.isOwner = (cfg.eventActor?.tier ?? "admin") === "admin"; // set before the startup setModel so a persisted owner-only activeModel resolves for the owner
|
|
553
584
|
this.moaConfig = cfg.moa;
|
|
554
|
-
this.onDemand = cfg.onDemand;
|
|
555
585
|
this.frontDoor = cfg.frontDoor;
|
|
556
586
|
this.classifier = cfg.classifier;
|
|
557
587
|
this.fastStartConfig = cfg.fastStart;
|
|
@@ -559,9 +589,11 @@ export class Session {
|
|
|
559
589
|
// Apply the persisted /model choice, unless a router was explicitly injected (tests / bg agents
|
|
560
590
|
// pinned to a fixed endpoint) — an injected router owns routing, /model doesn't override it. The shell's own
|
|
561
591
|
// chain is injected too, so it opts in: without that every interactive session started on the default model.
|
|
562
|
-
if ((!cfg.router || cfg.applyActiveModel) && cfg.activeModel && cfg.activeModel !==
|
|
563
|
-
|
|
564
|
-
|
|
592
|
+
if ((!cfg.router || cfg.applyActiveModel) && cfg.activeModel && cfg.activeModel !== CHAIN_MODEL_ID) {
|
|
593
|
+
const r = this.setModel(cfg.activeModel);
|
|
594
|
+
if (!r.ok)
|
|
595
|
+
this.modelId = CHAIN_MODEL_ID; // unavailable at startup → quiet fallback
|
|
596
|
+
this.modelNote = r.note;
|
|
565
597
|
}
|
|
566
598
|
this.systemPrompt = cfg.systemPrompt;
|
|
567
599
|
this.maxTokens = cfg.maxTokens ?? 32768; // == settings DEFAULTS.maxTokens (session-defaults.test.mts locks the pair); ACP/headless callers that omit cfg used to silently get a tight 2048 cap. clampMaxTokens still trims to the live window.
|
|
@@ -627,7 +659,7 @@ export class Session {
|
|
|
627
659
|
sessionContextBlock() {
|
|
628
660
|
const cwd = this.cwd ?? process.cwd();
|
|
629
661
|
return `${SESSION_CONTEXT_OPEN}Working directory: ${cwd}\nScratch dir: ${scratchDirFor(cwd)}\nRelative paths and shell ` +
|
|
630
|
-
`commands resolve in the working directory. This is authoritative over any working dir named elsewhere; files a ` +
|
|
662
|
+
`commands resolve in the working directory. This is authoritative over any working dir named elsewhere (except a turn the harness itself roots in a brief's worktree); files a ` +
|
|
631
663
|
`task creates go there unless the owner names another path.${homeDirNote(cwd)}${SESSION_CONTEXT_REQUEST_LINE}${SESSION_CONTEXT_CLOSE}`;
|
|
632
664
|
}
|
|
633
665
|
/** The effective system prompt: the base persona plus any memory recalled this session. Injected as ONE system
|
|
@@ -808,7 +840,7 @@ export class Session {
|
|
|
808
840
|
return this.inner.base;
|
|
809
841
|
if (planner.endpoint)
|
|
810
842
|
return endpointBase(planner.endpoint);
|
|
811
|
-
const row =
|
|
843
|
+
const row = resolveModel(this.liveRegistry(), planner.id);
|
|
812
844
|
const ep = row ? profileEndpoint(row) : undefined;
|
|
813
845
|
return ep ? endpointBase(ep) : this.inner.base;
|
|
814
846
|
}
|
|
@@ -859,7 +891,7 @@ export class Session {
|
|
|
859
891
|
if (p?.kind !== "single")
|
|
860
892
|
return undefined;
|
|
861
893
|
let base, model;
|
|
862
|
-
if (p.id ===
|
|
894
|
+
if (p.id === CHAIN_MODEL_ID) {
|
|
863
895
|
const r = this.chain ?? this.inner;
|
|
864
896
|
base = r.base;
|
|
865
897
|
model = r.model;
|
|
@@ -1183,8 +1215,14 @@ export class Session {
|
|
|
1183
1215
|
moaTeam() {
|
|
1184
1216
|
return moaTeam(this.moaConfig);
|
|
1185
1217
|
}
|
|
1218
|
+
/** The line a retired startup pick earned (a persisted activeModel of a retired row), once. */
|
|
1219
|
+
takeModelNote() {
|
|
1220
|
+
const n = this.modelNote;
|
|
1221
|
+
this.modelNote = undefined;
|
|
1222
|
+
return n;
|
|
1223
|
+
}
|
|
1186
1224
|
setModel(id) {
|
|
1187
|
-
const { profile, error } = selectModel(this.liveRegistry(), id, hasByoToken, this.isOwner);
|
|
1225
|
+
const { profile, error, retired } = selectModel(this.liveRegistry(), id, hasByoToken, this.isOwner);
|
|
1188
1226
|
if (error || !profile)
|
|
1189
1227
|
return { ok: false, error };
|
|
1190
1228
|
this.decodeSamples = []; // another model's rate says nothing about this one
|
|
@@ -1198,10 +1236,9 @@ export class Session {
|
|
|
1198
1236
|
return { ok: false, error: `MoA planner: ${p.error ?? `"${team.planner.id}" has no endpoint of its own`}` };
|
|
1199
1237
|
}
|
|
1200
1238
|
}
|
|
1201
|
-
if (profile.kind === "single" && profile.id ===
|
|
1202
|
-
// The
|
|
1203
|
-
//
|
|
1204
|
-
// answers on a gateway box — otherwise /model away-and-back lands on a dead port.
|
|
1239
|
+
if (profile.kind === "single" && profile.id === CHAIN_MODEL_ID && this.chain) {
|
|
1240
|
+
// The chain row IS the shell's endpoint chain (the router's `main`, then the fleet and cloud legs). Restore it
|
|
1241
|
+
// rather than rebuilding from the row's own two legs, so /model away-and-back keeps every failover leg.
|
|
1205
1242
|
this.inner = this.chain;
|
|
1206
1243
|
this.router = this.wrap(this.inner);
|
|
1207
1244
|
}
|
|
@@ -1214,15 +1251,15 @@ export class Session {
|
|
|
1214
1251
|
// before the first turn on it, so compaction sizes to it and the floor can be checked.
|
|
1215
1252
|
if (profile.kind === "single" && !profile.byo)
|
|
1216
1253
|
void this.probeServedContext().catch(() => undefined);
|
|
1217
|
-
return { ok: true };
|
|
1254
|
+
return { ok: true, ...(retired ? { note: `${retired.label} (${retired.id}) is retired — ${profile.label} answers instead; /model picks another` } : {}) };
|
|
1218
1255
|
}
|
|
1219
1256
|
/** Re-point this session at a freshly built endpoint chain. The interactive shell constructs the Session at
|
|
1220
1257
|
* first render, BEFORE the boot lever has resolved the gateway's dynamic port (server.json) — the chain must
|
|
1221
1258
|
* follow that resolution or health() and every turn probe "" (unset — auto-discover). Same swap setModel does. A
|
|
1222
|
-
* non-default /model pick keeps owning routing; the chain then waits for `/model
|
|
1259
|
+
* non-default /model pick keeps owning routing; the chain then waits for `/model main`. */
|
|
1223
1260
|
useRouter(router) {
|
|
1224
1261
|
this.chain = router;
|
|
1225
|
-
if (this.modelId !==
|
|
1262
|
+
if (this.modelId !== CHAIN_MODEL_ID)
|
|
1226
1263
|
return;
|
|
1227
1264
|
this.inner = router;
|
|
1228
1265
|
this.router = this.wrap(this.inner);
|
|
@@ -1273,13 +1310,13 @@ export class Session {
|
|
|
1273
1310
|
// A small-context active model (e.g. a self-hosted 8K Venice) can't summarize its OWN overflow — the
|
|
1274
1311
|
// [system + tools + span] summarize request itself exceeds the window, so compaction frees nothing and
|
|
1275
1312
|
// the session walls ("compaction can't free enough space"). Route the summarizer to the large-context
|
|
1276
|
-
//
|
|
1313
|
+
// chain row (the router's `main`, 262K) instead: it loses the live-turn's prefix-cache reuse (its
|
|
1277
1314
|
// prefix differs from the small model's), but that trade is what lets a small model compact continuously
|
|
1278
1315
|
// and run autonomously for hours. A large active model keeps the cache-safe same-endpoint path.
|
|
1279
1316
|
let sumBase = this.lastBase ?? this.inner.base;
|
|
1280
1317
|
let sumModel = this.lastModel ?? this.inner.model;
|
|
1281
1318
|
if (this.inner.ctxLimit() < LEAN_HARNESS_CTX) {
|
|
1282
|
-
const big = findModel(this.registry,
|
|
1319
|
+
const big = findModel(this.registry, CHAIN_MODEL_ID);
|
|
1283
1320
|
if (big?.endpoint) {
|
|
1284
1321
|
sumBase = endpointBase(big.endpoint);
|
|
1285
1322
|
sumModel = big.model ?? big.id;
|
|
@@ -1535,16 +1572,10 @@ export class Session {
|
|
|
1535
1572
|
// would otherwise no-op — this.ctrl was null until execute(). execute() reuses this same controller.
|
|
1536
1573
|
this.ctrl = new AbortController();
|
|
1537
1574
|
try {
|
|
1538
|
-
|
|
1575
|
+
this.turnImages = await this.nativeImagesFor(text);
|
|
1576
|
+
const front = await this.viaFrontDoor(text, h);
|
|
1539
1577
|
if (front)
|
|
1540
1578
|
return front;
|
|
1541
|
-
if (this.onDemand && this.modelId === DEFAULT_MODEL_ID) {
|
|
1542
|
-
const fresh = await this.onDemand(this.ctrl.signal);
|
|
1543
|
-
if (fresh)
|
|
1544
|
-
this.useRouter(fresh);
|
|
1545
|
-
if (this.ctrl.signal.aborted)
|
|
1546
|
-
return { content: "", rounds: 0, toolCalls: 0, interrupted: true };
|
|
1547
|
-
}
|
|
1548
1579
|
await this.maybeRecall(text); // fold past-session memory into the system prompt on the first turn
|
|
1549
1580
|
if (this.ctrl.signal.aborted)
|
|
1550
1581
|
return { content: "", rounds: 0, toolCalls: 0, interrupted: true };
|
|
@@ -1564,10 +1595,40 @@ export class Session {
|
|
|
1564
1595
|
}
|
|
1565
1596
|
finally {
|
|
1566
1597
|
this.ctrl = null; // execute() nulls on its own path too; this also covers the maybeRecall-abort early return
|
|
1598
|
+
this.turnImages = [];
|
|
1567
1599
|
this.wakeTurn = false;
|
|
1568
1600
|
this.turnThinkOff = false;
|
|
1569
1601
|
}
|
|
1570
1602
|
}
|
|
1603
|
+
/** The image files in the owner's message that go to the model as pictures, not through image_analyze: only when the
|
|
1604
|
+
* model answering can see (the profile says so, else its server does; an unknown is tried, and a server that turns
|
|
1605
|
+
* the image down puts it back on the tool). Never for a sub-agent, a wake turn or a remote url. */
|
|
1606
|
+
async nativeImagesFor(text) {
|
|
1607
|
+
if (this.background || this.wakeTurn)
|
|
1608
|
+
return [];
|
|
1609
|
+
const paths = extractImagePaths(text);
|
|
1610
|
+
if (!paths.length)
|
|
1611
|
+
return [];
|
|
1612
|
+
const p = findModel(this.liveRegistry(), this.modelId);
|
|
1613
|
+
if (p?.kind !== "single" || p.transport === "anthropic" || p.vision === false)
|
|
1614
|
+
return [];
|
|
1615
|
+
if (p.vision === true || p.byo)
|
|
1616
|
+
return paths;
|
|
1617
|
+
let base, model;
|
|
1618
|
+
if (p.id === CHAIN_MODEL_ID) {
|
|
1619
|
+
const r = this.chain ?? this.inner;
|
|
1620
|
+
base = r.base;
|
|
1621
|
+
model = r.model;
|
|
1622
|
+
}
|
|
1623
|
+
else {
|
|
1624
|
+
const ep = p.endpoints?.[0] ?? p.endpoint;
|
|
1625
|
+
if (!ep)
|
|
1626
|
+
return [];
|
|
1627
|
+
base = endpointBase(ep);
|
|
1628
|
+
model = p.endpointModels?.[0] ?? p.model ?? p.id;
|
|
1629
|
+
}
|
|
1630
|
+
return (await detectVision(base, model)) === "no" ? [] : paths;
|
|
1631
|
+
}
|
|
1571
1632
|
/** Speed-aware compaction: the last measured turns decoded under compaction.minDecodeTps at a request big enough
|
|
1572
1633
|
* for compaction to help, so compact now, before this turn's first request. The samples are cleared either way, so
|
|
1573
1634
|
* the next trigger needs two fresh slow turns. A failed summarizer leaves the conversation as it was. */
|
|
@@ -1602,13 +1663,13 @@ export class Session {
|
|
|
1602
1663
|
this.frontDoorRoute = undefined;
|
|
1603
1664
|
const fd = this.frontDoor;
|
|
1604
1665
|
const active = findModel(this.liveRegistry(), this.modelId);
|
|
1605
|
-
if (!fd || (this.modelId !==
|
|
1606
|
-
return null;
|
|
1666
|
+
if (!fd || (this.modelId !== CHAIN_MODEL_ID && active?.kind !== "orchestrated") || this.turnImages.length)
|
|
1667
|
+
return null; // the fast model sees no pictures
|
|
1607
1668
|
const t0 = Date.now();
|
|
1608
1669
|
// The gateway's front door is configured on the default model's route; `name` is the model as the owner knows it
|
|
1609
1670
|
// (activeModelBlock), so a MOA session is MOA to the fast model too.
|
|
1610
1671
|
const name = active ? `${active.label}${active.params ? ` ${active.params}` : ""}` : this.modelId;
|
|
1611
|
-
const d = await askFrontDoor(fd, { model:
|
|
1672
|
+
const d = await askFrontDoor(fd, { model: CHAIN_MODEL_ID, name, messages: [...recentTurns(this.convo.all), { role: "user", content: text }] }, this.ctrl?.signal);
|
|
1612
1673
|
if (this.ctrl?.signal.aborted)
|
|
1613
1674
|
return { content: "", rounds: 0, toolCalls: 0, interrupted: true };
|
|
1614
1675
|
this.frontDoorRoute = d?.route ?? null;
|
|
@@ -1634,11 +1695,12 @@ export class Session {
|
|
|
1634
1695
|
// specialist with the full prompt.
|
|
1635
1696
|
const fd = this.frontDoorRoute;
|
|
1636
1697
|
const route = fd === undefined && this.classifier && this.classifier.mode !== "off" ? await routeTurn(text, this.classifier.endpoint) : null;
|
|
1637
|
-
const
|
|
1698
|
+
const specialistRow = route?.route === "direct" ? resolveModel(this.liveRegistry(), team.specialist) : undefined;
|
|
1699
|
+
const specialist = specialistRow?.kind === "single" ? specialistRow : undefined;
|
|
1638
1700
|
this.telemetry.record({ type: "moa", planner: team.planner.id, specialist: team.specialist, route: specialist ? "direct" : route || fd === "work" ? "planned" : "unrouted", pDirect: route?.pDirect });
|
|
1639
1701
|
if (specialist)
|
|
1640
1702
|
return this.execute(text, h, this.wrap(this.routerForProfile(specialist)), this.sysWithThink(), specialist.id);
|
|
1641
|
-
const plannerRow = team.planner.endpoint ? undefined :
|
|
1703
|
+
const plannerRow = team.planner.endpoint ? undefined : resolveModel(this.liveRegistry(), team.planner.id);
|
|
1642
1704
|
if (!team.planner.endpoint && plannerRow?.kind !== "single")
|
|
1643
1705
|
throw new Error(`MoA planner "${team.planner.id}" is not a /model id with an endpoint`);
|
|
1644
1706
|
const plannerRouter = this.wrap(plannerRow?.kind === "single" ? this.routerForProfile(plannerRow) : new AuroraRouter([
|
|
@@ -1717,6 +1779,8 @@ export class Session {
|
|
|
1717
1779
|
* and system prompt they pass in. */
|
|
1718
1780
|
async execute(text, h, router, sys, routeLabel) {
|
|
1719
1781
|
this.executor.resetTurn(); // clear the host executor's per-turn loop guard before this turn
|
|
1782
|
+
// A wake turn whose brief named a contained worktree runs there for this turn only (Codex --cd / Claude Code worktree isolation).
|
|
1783
|
+
this.executor.setTurnRoot(wakeRoot(text) ?? undefined);
|
|
1720
1784
|
this.lastSys = sys; // remember the EXACT system prompt this turn sends, so cache-safe compaction reuses it verbatim
|
|
1721
1785
|
// Reuse the controller send() already armed (so esc during maybeRecall / MOA fan-out is live); create one
|
|
1722
1786
|
// only if execute() is somehow entered without send() arming it (defensive — every caller goes via send).
|
|
@@ -1724,6 +1788,7 @@ export class Session {
|
|
|
1724
1788
|
this.ctrl = controller;
|
|
1725
1789
|
this.turnHandlers = h; // a mid-turn compaction's summarizer reports its read through this turn's handlers
|
|
1726
1790
|
const _t0 = performance.now();
|
|
1791
|
+
const wallT0 = Date.now(); // wall clock, for the bus: did this turn reply to its sender (autoDeliverReport)
|
|
1727
1792
|
// Snapshot the conversation length so we can slice out THIS turn's steps (user + assistant/tool messages)
|
|
1728
1793
|
// for the flywheel row — the per-step structure SRFT credit assignment needs. runTurn pushes the user
|
|
1729
1794
|
// message itself, so everything from here on is this turn's.
|
|
@@ -1743,6 +1808,8 @@ export class Session {
|
|
|
1743
1808
|
try {
|
|
1744
1809
|
const res = await runTurn(text, this.convo, {
|
|
1745
1810
|
ownerText,
|
|
1811
|
+
images: this.turnImages,
|
|
1812
|
+
onImagesRejected: (ep) => markVisionRejected(ep.base, ep.model),
|
|
1746
1813
|
router,
|
|
1747
1814
|
tools: this.liveTools, // read through at each call: a mid-turn /mode or Shift+Tab applies from the next tool call
|
|
1748
1815
|
toolSchemas: this.allSchemas(),
|
|
@@ -1896,12 +1963,22 @@ export class Session {
|
|
|
1896
1963
|
turn.recorded = true;
|
|
1897
1964
|
const record = {
|
|
1898
1965
|
input: text, content: res.content, rounds: res.rounds, toolCalls: res.toolCalls,
|
|
1899
|
-
tokens: res.tokens, stopReason: res.stopReason, model: this.currentModel(),
|
|
1966
|
+
tokens: res.tokens, stopReason: res.stopReason, stopKind: res.stopKind, model: this.currentModel(),
|
|
1900
1967
|
cwd: process.cwd(), durationMs: Math.round(performance.now() - _t0), unverified: res.unverified,
|
|
1901
1968
|
steps: this.turnSteps(convoStart, text), task, loop: res.loop, lessonTs: turn.lessonTs,
|
|
1902
1969
|
};
|
|
1903
1970
|
const cfg = this.selfImproveCfg();
|
|
1904
1971
|
this.learn(() => runSelfImprove(cfg, record)); // after any lesson a loop recovery is still writing
|
|
1972
|
+
// A woken turn owes its sender a report; when it ended without one, the harness delivers the final answer
|
|
1973
|
+
// (Claude Code returns a sub-agent's final message to its parent; `codex exec -o` writes it for the caller).
|
|
1974
|
+
try {
|
|
1975
|
+
const to = autoDeliverReport(ownerText, res.content ?? "", wallT0);
|
|
1976
|
+
if (to.length) {
|
|
1977
|
+
this.telemetry.record({ type: "auto_report", recipients: to.length });
|
|
1978
|
+
h.onAutoReport?.(to);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
catch { /* best-effort: a bus write failure never fails the turn */ }
|
|
1905
1982
|
return { ...res, interrupted: false, durationMs: Math.round(performance.now() - _t0) };
|
|
1906
1983
|
}
|
|
1907
1984
|
catch (e) {
|
|
@@ -1911,8 +1988,16 @@ export class Session {
|
|
|
1911
1988
|
const cfg = this.selfImproveCfg();
|
|
1912
1989
|
if (r)
|
|
1913
1990
|
this.learn(() => runSelfImprove(cfg, r));
|
|
1991
|
+
try {
|
|
1992
|
+
autoDeliverFailure(ownerText, "interrupted");
|
|
1993
|
+
}
|
|
1994
|
+
catch { /* best-effort */ }
|
|
1914
1995
|
return { content: "", rounds: 0, toolCalls: 0, interrupted: true };
|
|
1915
1996
|
}
|
|
1997
|
+
try {
|
|
1998
|
+
autoDeliverFailure(ownerText, "failed");
|
|
1999
|
+
}
|
|
2000
|
+
catch { /* best-effort */ }
|
|
1916
2001
|
this.telemetry.record({ type: "error", where: "send", errorClass: Telemetry.errorClass(e) });
|
|
1917
2002
|
throw e;
|
|
1918
2003
|
}
|
|
@@ -1921,6 +2006,7 @@ export class Session {
|
|
|
1921
2006
|
if (this.inflight === turn)
|
|
1922
2007
|
this.inflight = undefined;
|
|
1923
2008
|
this.turnHandlers = undefined;
|
|
2009
|
+
this.executor.setTurnRoot(undefined);
|
|
1924
2010
|
}
|
|
1925
2011
|
}
|
|
1926
2012
|
/** The self-improvement sinks: the flywheel (settings.selfImprove → KODE_SELFIMPROVE) and the memory sink
|