@0perator/operator 0.1.344 → 0.1.346
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/dist/acp/agent.js +7 -2
- package/dist/autonomy/delegate.js +25 -4
- package/dist/autonomy/headless.js +6 -1
- package/dist/autonomy/index.js +10 -1
- package/dist/autonomy/session-factory.js +5 -1
- package/dist/autonomy/subagent-model.js +20 -0
- package/dist/background/commands.js +7 -0
- package/dist/background/index.js +135 -14
- package/dist/background/notices.js +25 -3
- package/dist/classifier/route.js +46 -0
- package/dist/cli.js +74 -39
- package/dist/config/persona.js +29 -16
- package/dist/config/settings.js +5 -8
- package/dist/engine/agent.js +13 -5
- package/dist/engine/anthropic-chat.js +2 -2
- package/dist/engine/aurora.js +8 -4
- package/dist/engine/continuation.js +50 -4
- package/dist/engine/grandmaster.js +18 -1
- package/dist/engine/loop-guard.js +23 -20
- package/dist/engine/moa.js +28 -57
- package/dist/router/models.js +2 -1
- package/dist/session.js +98 -81
- package/dist/ui/ActivitySpinner.js +11 -16
- package/dist/ui/BgPanel.js +35 -24
- package/dist/ui/PlanPane.js +26 -2
- package/dist/ui/ToolStep.js +16 -2
- package/package.json +1 -1
|
@@ -34,6 +34,20 @@ export function inferType(objective) {
|
|
|
34
34
|
return "code-edit";
|
|
35
35
|
return "generic";
|
|
36
36
|
}
|
|
37
|
+
/** Whether a role can write files (its tool list has file_write; no list = every tool). */
|
|
38
|
+
export function roleCanWrite(type) {
|
|
39
|
+
const tools = SUBAGENT_ROLES[type]?.tools;
|
|
40
|
+
return !tools || tools.includes("file_write");
|
|
41
|
+
}
|
|
42
|
+
// A brief whose deliverable is a file. 10/31: "Modern website design components … the file exists at …" was guessed
|
|
43
|
+
// "plan" from the word "design" — a read-only role with no file_write — and looped 54 rounds unable to deliver.
|
|
44
|
+
const FILE_DELIVERABLE = /\bfile exists at\b|\b(?:write|create|save|draft|produce|generate)\b[^.\n]{0,80}\.(?:md|txt|json|ya?ml|tsx?|jsx?|py|html|css|sh|csv)\b/i;
|
|
45
|
+
/** The role for a brief spawned without one: the keyword guess, unless it is read-only and the brief must produce a
|
|
46
|
+
* file — then "generic" (every tool, the live working directory). */
|
|
47
|
+
export function roleForBrief(brief) {
|
|
48
|
+
const guess = inferType(brief);
|
|
49
|
+
return !roleCanWrite(guess) && FILE_DELIVERABLE.test(brief) ? "generic" : guess;
|
|
50
|
+
}
|
|
37
51
|
// The per-task-type final_answer schema, rendered as a compact JSON example the child fills in.
|
|
38
52
|
export function schemaHintFor(type) {
|
|
39
53
|
switch (type) {
|
|
@@ -64,7 +78,10 @@ function defaultContext(type, cwd) {
|
|
|
64
78
|
// inherited the owner's project list and every tool, and researched the owner's files instead of the web.
|
|
65
79
|
// Tool lists are allowlists of registry names; undefined = every tool (the previous behaviour, kept for code-edit
|
|
66
80
|
// and generic). skill_list / skill_fetch ride in every list: the catalog is how a scoped role reaches more.
|
|
67
|
-
const CATALOG_TOOLS = ["skill_list", "skill_fetch", "
|
|
81
|
+
const CATALOG_TOOLS = ["skill_list", "skill_fetch", "scratchpad"];
|
|
82
|
+
/** Never a sub-agent's: the task list is the OWNER's plan (registry.ts keeps one store per process). A sub-agent
|
|
83
|
+
* tracks its own steps in its scratchpad. Applied to every sub-agent session, whatever its role. */
|
|
84
|
+
export const SUBAGENT_TOOL_DENY = ["task_add", "task_update", "task_clear"];
|
|
68
85
|
const READ_TOOLS = ["file_read", "read_files", "grep_search", "search", "find_files", "list_directory", "glob",
|
|
69
86
|
"git_status", "code_search", "codebase_search", "lsp_diag"];
|
|
70
87
|
const WEB_TOOLS = ["web_search", "web_fetch", "deep_research", "browser_read", "knowledge_search"];
|
|
@@ -350,13 +350,12 @@ export class LoopGuard {
|
|
|
350
350
|
// else might.
|
|
351
351
|
export const AUTOPOST_POLLERS = new Set(["agent_status"]);
|
|
352
352
|
export const POLL_SPIN_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
|
|
353
|
-
export const POLL_SPIN_NUDGE = "
|
|
354
|
-
"
|
|
355
|
-
"
|
|
356
|
-
"
|
|
357
|
-
export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no
|
|
358
|
-
"
|
|
359
|
-
"lost — the reports arrive on their own.]";
|
|
353
|
+
export const POLL_SPIN_NUDGE = "agent_status will not change faster by asking again — each report, and a STUCK notice if one stalls, arrives " +
|
|
354
|
+
"as a message on its own. Act on what it shows: steer an agent that is stuck or off its brief (message_agent), " +
|
|
355
|
+
"or stop it (stop_agent) and do its step yourself. Otherwise do the work that does not depend on them, or close " +
|
|
356
|
+
"the turn for the owner: one status line per agent (round, files written) and 2-3 options.";
|
|
357
|
+
export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no change. Their reports, and a notice if " +
|
|
358
|
+
"one gets stuck, arrive on their own. Nothing was lost.]";
|
|
360
359
|
/** Watches settled tool rounds for an auto-post-poller spin. Fed one round at a time via observe(); a
|
|
361
360
|
* productive (non-poller) tool OR a changed poll result resets the streak. Side-effect-free: the engine acts
|
|
362
361
|
* on the returned action (inject the nudge once, then end the turn). */
|
|
@@ -416,13 +415,14 @@ export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
|
|
|
416
415
|
* alone has no independent work in it. */
|
|
417
416
|
export const DISPATCH_BOOKKEEPING = new Set(["task_add", "task_update", "task_list", "task_clear", "agent_status", "message_agent"]);
|
|
418
417
|
export const YIELD_DEFAULTS = { nudgeAfter: 1, stopAfter: 2 };
|
|
419
|
-
export const YIELD_NUDGE = "Your sub-agents are
|
|
420
|
-
"
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
418
|
+
export const YIELD_NUDGE = "Your sub-agents are working their steps and this round changed nothing. Do not redo their work: finish what does " +
|
|
419
|
+
"not depend on them, or close the turn — one status line per agent and 2-3 options for the owner.";
|
|
420
|
+
export const YIELD_STOP = "[turn ended — sub-agents are running on this model's only slot, so the turn hands it to them; each report " +
|
|
421
|
+
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
422
|
+
export const YIELD_DISPATCHED = "[turn ended — sub-agents dispatched onto this model's only slot, so the turn hands it to them now; each report " +
|
|
423
|
+
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
424
|
+
/** Supervising IS progress: stopping a sub-agent (to take its step over) or asking the owner never counts as idling. */
|
|
425
|
+
export const SUPERVISION_TOOLS = new Set(["stop_agent", "ask_user"]);
|
|
426
426
|
/** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); a MUTATING
|
|
427
427
|
* round resets the streak. The endpoint's slot count sets the policy: on ONE slot (the fleet default) the parent
|
|
428
428
|
* working beside its sub-agents is pure contention — every parent round waits behind a sub-agent round and then
|
|
@@ -442,24 +442,27 @@ export class YieldAfterDispatchGuard {
|
|
|
442
442
|
this.stopAfter = stopAfter;
|
|
443
443
|
this.dispatched = armed;
|
|
444
444
|
}
|
|
445
|
-
/** One settled round: the tools it ran (names), whether any call changed the workspace,
|
|
446
|
-
*
|
|
447
|
-
|
|
445
|
+
/** One settled round: the tools it ran (names), whether any call changed the workspace, how many requests the
|
|
446
|
+
* model endpoint serves at once (engine/aurora.ts endpointSlots — 1 unless KODE_ENDPOINT_SLOTS says more), and
|
|
447
|
+
* whether a live sub-agent is served from THIS turn's slot. Sub-agents on another server (10/31: Cortana main,
|
|
448
|
+
* gpt-oss-20b children) cannot be starved by the parent, so it never yields to them — it keeps working and
|
|
449
|
+
* supervising, with one nudge against redoing their work. */
|
|
450
|
+
observe(names, mutating, slots = 1, shared = true) {
|
|
448
451
|
const single = slots <= 1;
|
|
449
452
|
if (names.some((n) => DISPATCH_TOOLS.has(n))) {
|
|
450
453
|
this.dispatched = true;
|
|
451
454
|
this.streak = 0;
|
|
452
455
|
const pure = names.every((n) => DISPATCH_TOOLS.has(n) || DISPATCH_BOOKKEEPING.has(n));
|
|
453
|
-
return single && pure ? { action: "halt", streak: 0, message: YIELD_DISPATCHED } : { action: "allow", streak: 0 };
|
|
456
|
+
return shared && single && pure ? { action: "halt", streak: 0, message: YIELD_DISPATCHED } : { action: "allow", streak: 0 };
|
|
454
457
|
}
|
|
455
458
|
if (!this.dispatched)
|
|
456
459
|
return { action: "allow", streak: 0 };
|
|
457
|
-
if (mutating) {
|
|
460
|
+
if (mutating || names.some((n) => SUPERVISION_TOOLS.has(n))) {
|
|
458
461
|
this.streak = 0;
|
|
459
462
|
return { action: "allow", streak: 0 };
|
|
460
463
|
}
|
|
461
464
|
this.streak += 1;
|
|
462
|
-
if (single || this.streak >= this.stopAfter)
|
|
465
|
+
if (shared && (single || this.streak >= this.stopAfter))
|
|
463
466
|
return { action: "halt", streak: this.streak, message: YIELD_STOP };
|
|
464
467
|
if (this.streak >= this.nudgeAfter && !this.nudged) {
|
|
465
468
|
this.nudged = true;
|
package/dist/engine/moa.js
CHANGED
|
@@ -1,59 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async function callProposer(p, messages) {
|
|
12
|
-
const t0 = performance.now();
|
|
13
|
-
const ctrl = new AbortController();
|
|
14
|
-
const timer = setTimeout(() => ctrl.abort(), PROPOSER_TIMEOUT_MS);
|
|
15
|
-
try {
|
|
16
|
-
const res = await fetch(`${p.endpoint.replace(/\/$/, "")}/chat/completions`, {
|
|
17
|
-
method: "POST",
|
|
18
|
-
// The same bearer scoping as every model call: the signed-in Operator token on the 0perator gateway (proposers
|
|
19
|
-
// default to it), nothing for a local server or a foreign host.
|
|
20
|
-
headers: { "content-type": "application/json", ...authHeaders({ base: p.endpoint, model: p.model }) },
|
|
21
|
-
body: JSON.stringify({ model: p.model, messages, stream: false }),
|
|
22
|
-
signal: ctrl.signal,
|
|
23
|
-
});
|
|
24
|
-
if (!res.ok)
|
|
25
|
-
return { id: p.id, content: "", ms: Math.round(performance.now() - t0), error: `http ${res.status}` };
|
|
26
|
-
const json = await res.json();
|
|
27
|
-
const content = String(json?.choices?.[0]?.message?.content ?? "").trim();
|
|
28
|
-
return { id: p.id, content, ms: Math.round(performance.now() - t0), error: content ? undefined : "empty completion" };
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
return { id: p.id, content: "", ms: Math.round(performance.now() - t0), error: e.name || "error" };
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
}
|
|
1
|
+
/** The team from settings.moa, new shape or the pre-10/31 one (aggregator → planner, first other proposer →
|
|
2
|
+
* specialist). Undefined when no planner is configured. A missing specialist falls back to the planner itself. */
|
|
3
|
+
export function moaTeam(cfg) {
|
|
4
|
+
const planner = cfg?.planner ?? cfg?.aggregator;
|
|
5
|
+
if (!planner)
|
|
6
|
+
return undefined;
|
|
7
|
+
const specialist = cfg?.specialist?.id?.trim()
|
|
8
|
+
|| cfg?.proposers?.find((p) => p.id !== planner.id)?.id
|
|
9
|
+
|| planner.id;
|
|
10
|
+
return { planner, specialist, prompt: cfg?.planner_prompt };
|
|
36
11
|
}
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
12
|
+
/** The planner's standing brief. Identical every turn for a given team, so it stays in the prompt cache. */
|
|
13
|
+
export function plannerBrief(team) {
|
|
14
|
+
if (team.prompt)
|
|
15
|
+
return team.prompt;
|
|
16
|
+
const s = team.specialist;
|
|
17
|
+
return [
|
|
18
|
+
`You are the planner of a two-model team: you (${team.planner.id}) plan, check and answer; ${s} is your specialist.`,
|
|
19
|
+
"- A question you can answer directly, answer directly — no plan, no delegation.",
|
|
20
|
+
"- Otherwise plan first: add each step to the task list (task_add), small and concrete, in order.",
|
|
21
|
+
`- Hand each self-contained step to the specialist with delegate_task (it runs on ${s} by default). The specialist sees`,
|
|
22
|
+
" only the task you write: include the goal, the inputs (paths, URLs, facts) and what to report back. Independent",
|
|
23
|
+
" steps can be delegated together.",
|
|
24
|
+
"- Do yourself: a single quick tool call, anything that needs reading an image (only you read images), and the final",
|
|
25
|
+
" answer.",
|
|
26
|
+
"- Check every report before marking the step done (task_update); fix or redo a wrong one instead of passing it on.",
|
|
27
|
+
"- Finish with the result for the owner — what was done and what it found — not a description of the process.",
|
|
28
|
+
`This mixture's team: planner ${team.planner.id}; specialist ${s}. Asked which models make up the mixture, name exactly these.`,
|
|
29
|
+
].join("\n");
|
|
42
30
|
}
|
|
43
|
-
/** Label + join the surviving (non-empty) drafts as "Candidate A: ..." (MOA-DESIGN.md), for the
|
|
44
|
-
* aggregator's input. Pure + testable without a network call. */
|
|
45
|
-
export function labelDrafts(drafts) {
|
|
46
|
-
return drafts
|
|
47
|
-
.filter((d) => d.content)
|
|
48
|
-
.map((d, i) => `Candidate ${String.fromCharCode(65 + i)} (${d.id}):\n${d.content}`)
|
|
49
|
-
.join("\n\n");
|
|
50
|
-
}
|
|
51
|
-
/** The team, as fact, for the aggregator. Without it the model guessed its own members from the fleet notes in the
|
|
52
|
-
* prompt (10/30: it named Aurora and the vision model while only Cortana had answered, Dolphin being down). */
|
|
53
|
-
export function teamLine(proposers, answered, aggregator) {
|
|
54
|
-
const missing = proposers.map((p) => p.id).filter((id) => !answered.includes(id));
|
|
55
|
-
return `This mixture's team: proposers ${proposers.map((p) => p.id).join(", ")}; aggregator ${aggregator}.` +
|
|
56
|
-
(missing.length ? ` Did not answer this turn: ${missing.join(", ")}.` : "") +
|
|
57
|
-
" Asked which models make up the mixture, name exactly these.";
|
|
58
|
-
}
|
|
59
|
-
export const DEFAULT_AGGREGATOR_PROMPT = "You are given candidate answers from several models. Synthesize the single best, correct, complete answer. Do not mention the candidates.";
|
package/dist/router/models.js
CHANGED
|
@@ -65,6 +65,7 @@ export const BUILTIN_MODELS = [
|
|
|
65
65
|
// claims MORE than the server's --ctx-size makes the engine overrun the wall and the server cuts a round
|
|
66
66
|
// mid-tool-call (0.1.259) — change this number ONLY when the server's --ctx-size changes.
|
|
67
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 },
|
|
68
69
|
// Thor — huihui-ai QwQ-32B abliterated: a dense reasoning model that thinks before it answers. Served on JL1:8124
|
|
69
70
|
// (the portal lists it "available" = registered, loaded on demand); gateway-first like cortana. ctx 32768 = the
|
|
70
71
|
// server's --ctx-size. Mirrors the hand override JL2's settings.json carried under this id (now a no-op by id).
|
|
@@ -139,7 +140,7 @@ export const BUILTIN_MODELS = [
|
|
|
139
140
|
{ id: "axe-aurora-300k", tier: "power", label: "Aurora Code 1", params: "35B-A3B", box: "cloud", kind: "single", desc: "remote shared slot via api.0perator.co (api.axe.onl as fallback) — contended decode measured 1-4.6 tok/s vs local 24-47; cold >~100K prefills can hit the Cloudflare ~125s edge cutoff", endpoint: GATEWAY_BASE, endpoints: [GATEWAY_BASE, LEGACY_GATEWAY_BASE], model: "aurora-code-1", ctx: 307200, transport: "openai", hidden: true },
|
|
140
141
|
{ id: "operator-128k", tier: "economy", label: "Aurora Code 1", params: "35B-A3B", box: "JL2", kind: "single", desc: "128K context, lighter RAM (:8096) — slot not served on this fleet today; hidden from the picker, resolves by id when the slot comes up", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072, hidden: true },
|
|
141
142
|
// ── orchestrated ────────────────────────────────────────────────────────────────────────────────────────
|
|
142
|
-
{ id: "moa", tier: "power_turbo", label: "MOA", box: "mixture of agents", kind: "orchestrated", desc: "the team slot — each
|
|
143
|
+
{ id: "moa", tier: "power_turbo", label: "MOA", box: "mixture of agents", kind: "orchestrated", desc: "the team slot — Cortana plans each request into steps and hands them to gpt-oss-20b specialists, checks their work, writes the answer and reads any images (settings.moa overrides)" },
|
|
143
144
|
];
|
|
144
145
|
export const OPERATOR_FREE_ACCOUNT = "0perator";
|
|
145
146
|
export const BYO_PRESETS = {
|
package/dist/session.js
CHANGED
|
@@ -13,7 +13,10 @@ import { engineRouter } from "./engine/router-adapter.js";
|
|
|
13
13
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
14
14
|
import { dirname } from "node:path";
|
|
15
15
|
import { operatorPath } from "./config/home.js";
|
|
16
|
-
import {
|
|
16
|
+
import { moaTeam, plannerBrief } from "./engine/moa.js";
|
|
17
|
+
import { routeTurn } from "./classifier/route.js";
|
|
18
|
+
import { engineNote, isStatusAsk, STATUS_FIRST_NOTE } from "./engine/continuation.js";
|
|
19
|
+
import { withDelegateDefault } from "./autonomy/delegate.js";
|
|
17
20
|
import { routeShadowTurn, shadowPrompt } from "./moa/shadow.js"; // MOA phase-0 observability (KODE_MOA_SHADOW)
|
|
18
21
|
import { AuroraRouter } from "./router/router.js";
|
|
19
22
|
import { operatorAgentPersona } from "./config/operator-harness.js";
|
|
@@ -76,37 +79,49 @@ export function renderBudgetBlock(b) {
|
|
|
76
79
|
// The `spawn_agent` tool — a thin pass-through to the shell's delegate handler. The handler owns the
|
|
77
80
|
// policy (cap) and the reply text; the tool just guards against an empty task. safe:false so it's an
|
|
78
81
|
// action (gated when permissions are on), never run speculatively in the safe-parallel batch.
|
|
82
|
+
/** A brief shorter than this is not a brief (10/31: a sub-agent was spawned with the objective "agent"). 12 refused a
|
|
83
|
+
* complete 11-word brief in the e2e ("Create the file …/nova.md containing exactly three lines: red, green, blue"). */
|
|
84
|
+
const MIN_BRIEF_WORDS = 5;
|
|
79
85
|
function makeSpawnTool(handler) {
|
|
80
86
|
return {
|
|
81
87
|
name: "spawn_agent",
|
|
82
88
|
safe: false,
|
|
83
|
-
description: "Spawn sub-agents: isolated sessions
|
|
84
|
-
"sub-agent; several run in parallel (2 running + 2 queued by default).
|
|
85
|
-
"
|
|
86
|
-
" what does NOT depend on them
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
+
description: "Spawn sub-agents: isolated sessions, each with its own shell, on the sub-agent model (the result says which). " +
|
|
90
|
+
"One `tasks` entry = one sub-agent; several run in parallel (2 running + 2 queued by default). Make THIS call in " +
|
|
91
|
+
"the same round you decide to delegate, and in that message tell the owner who you are sending and why (one line " +
|
|
92
|
+
"per agent). You stay the lead: do what does NOT depend on them; never redo, re-spawn or poll for a step one is " +
|
|
93
|
+
"working on — each report, and a STUCK notice if one stalls, arrives as a message at the start of a later turn. " +
|
|
94
|
+
"agent_status shows rounds, files and stuck flags; message_agent steers; stop_agent stops one so you can take its " +
|
|
95
|
+
"step over (a sub-agent id is not a shell job id).\n" +
|
|
89
96
|
"USE FOR: reasoning-heavy or context-flooding subtasks, independent parallel workstreams (research per area, " +
|
|
90
97
|
"review per module, search per tree, drafting a file).\n" +
|
|
91
98
|
"DO NOT USE FOR: a single tool call; mechanical steps; anything that needs the user; edits to the same files " +
|
|
92
99
|
"from several agents.\n" +
|
|
93
100
|
"RULES: the sub-agent knows NOTHING of this conversation — brief it as a spec: **Objective** · **Context** " +
|
|
94
|
-
"(every path, id, fact) · **Deliverable** · **Constraints** · **Done**. A
|
|
95
|
-
"
|
|
96
|
-
"CONCISE report (~1-2k tokens).",
|
|
101
|
+
"(every path, id, fact) · **Deliverable** · **Constraints** · **Done**. A file deliverable needs role code-edit or " +
|
|
102
|
+
"generic. A report is a SELF-REPORT — open what it produced and check it against Done before you tell the owner. " +
|
|
103
|
+
"SINGLE WRITER: keep file edits on one agent. Ask for a CONCISE report (~1-2k tokens) listing the files it wrote.",
|
|
97
104
|
parameters: {
|
|
98
105
|
type: "object",
|
|
99
106
|
properties: {
|
|
100
107
|
tasks: { type: "array", items: { type: "string" }, description: "the brief(s); one entry per sub-agent" },
|
|
101
108
|
task: { type: "string", description: "a single brief (same as a one-entry `tasks`)" },
|
|
102
|
-
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
|
|
109
|
+
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." },
|
|
103
110
|
agent: { type: "string", description: "optional repo-local persona from .operator/agents/ (listed under 'Repo-local harness')" },
|
|
111
|
+
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" },
|
|
112
|
+
name: { type: "string", description: "the name for a single `task`" },
|
|
104
113
|
},
|
|
105
114
|
},
|
|
106
115
|
run: async (args) => {
|
|
107
116
|
const briefs = (Array.isArray(args.tasks) ? args.tasks.map((t) => String(t ?? "").trim()) : [String(args.task ?? "").trim()]).filter(Boolean);
|
|
108
117
|
if (!briefs.length)
|
|
109
118
|
return "error: spawn_agent needs `tasks` (an array of briefs — one per sub-agent) or `task`";
|
|
119
|
+
const names = Array.isArray(args.names) ? args.names.map((n) => String(n ?? "").trim()) : [String(args.name ?? "").trim()];
|
|
120
|
+
const thin = briefs.findIndex((b) => b.split(/\s+/).filter(Boolean).length < MIN_BRIEF_WORDS);
|
|
121
|
+
if (thin >= 0) {
|
|
122
|
+
return `error: spawn_agent brief ${thin + 1} is too short to act on ("${briefs[thin].slice(0, 60)}"). The sub-agent knows NOTHING ` +
|
|
123
|
+
`of this conversation: write **Objective** · **Context** (every path, id, fact) · **Deliverable** · **Done** — or do the step yourself.`;
|
|
124
|
+
}
|
|
110
125
|
const agent = String(args.agent ?? "").trim();
|
|
111
126
|
const roleArg = String(args.role ?? "").trim();
|
|
112
127
|
const role = ["research", "search", "review", "plan", "code-edit", "generic"].includes(roleArg) ? roleArg : undefined;
|
|
@@ -117,10 +132,10 @@ function makeSpawnTool(handler) {
|
|
|
117
132
|
? `You are acting as the "${agent}" sub-agent for this repo. Follow this persona:\n\n${persona}\n\n---\nYour task:\n${task}`
|
|
118
133
|
: `${task}\n\n(note: no .operator/agents/${agent}.md persona found — ran without it)`;
|
|
119
134
|
if (briefs.length === 1)
|
|
120
|
-
return handler(frame(briefs[0]), role);
|
|
135
|
+
return handler(frame(briefs[0]), role, names[0] || undefined);
|
|
121
136
|
// Fan-out: one spawn per brief, in order; the manager queues past its running cap and refuses past the
|
|
122
137
|
// in-flight cap — each line reports what happened to that brief, so a partial fan-out is never silent.
|
|
123
|
-
return briefs.map((t, i) => `[${i + 1}/${briefs.length}] ${handler(frame(t), role)}`).join("\n");
|
|
138
|
+
return briefs.map((t, i) => `[${i + 1}/${briefs.length}] ${handler(frame(t), role, names[i] || undefined)}`).join("\n");
|
|
124
139
|
},
|
|
125
140
|
};
|
|
126
141
|
}
|
|
@@ -131,12 +146,13 @@ function makeMessageTool(handler) {
|
|
|
131
146
|
return {
|
|
132
147
|
name: "message_agent",
|
|
133
148
|
safe: false,
|
|
134
|
-
description: "Send a message to a background sub-agent that is STILL RUNNING (
|
|
135
|
-
"
|
|
149
|
+
description: "Send a message to a background sub-agent that is STILL RUNNING (its id, like agent-1, or its name): it acts on " +
|
|
150
|
+
"it at its next round — steer it, add context, answer its question, or re-steer one that is stuck or off its " +
|
|
151
|
+
"brief (name the exact file or next step). No-op once it has finished.",
|
|
136
152
|
parameters: {
|
|
137
153
|
type: "object",
|
|
138
154
|
properties: {
|
|
139
|
-
id: { type: "string", description: "sub-agent id
|
|
155
|
+
id: { type: "string", description: "sub-agent id (agent-1) or name" },
|
|
140
156
|
text: { type: "string", description: "the message" },
|
|
141
157
|
},
|
|
142
158
|
required: ["id", "text"],
|
|
@@ -158,13 +174,13 @@ function makeStatusTool(handler) {
|
|
|
158
174
|
return {
|
|
159
175
|
name: "agent_status",
|
|
160
176
|
safe: true,
|
|
161
|
-
description: "Check background sub-agents WITHOUT re-spawning them: no `id` lists every one
|
|
162
|
-
"(queued/working/idle/stopped); `id` checks one. Use it
|
|
163
|
-
"
|
|
164
|
-
"on
|
|
177
|
+
description: "Check background sub-agents WITHOUT re-spawning them: no `id` lists every one — name, role, model, status " +
|
|
178
|
+
"(queued/working/idle/stopped), round, files written, and STUCK with the reason; `id` (or name) checks one. Use it " +
|
|
179
|
+
"when the owner asks for an update or BEFORE you steer, stop or take one over — not in a loop: reports and stuck " +
|
|
180
|
+
"notices arrive on their own. bash_output/bash_kill are for shell jobs and will error on a sub-agent id.",
|
|
165
181
|
parameters: {
|
|
166
182
|
type: "object",
|
|
167
|
-
properties: { id: { type: "string", description: "optional sub-agent id; omit to list all" } },
|
|
183
|
+
properties: { id: { type: "string", description: "optional sub-agent id or name; omit to list all" } },
|
|
168
184
|
},
|
|
169
185
|
run: async (args) => {
|
|
170
186
|
const id = String(args.id ?? "").trim();
|
|
@@ -180,13 +196,14 @@ function makeStopTool(handler) {
|
|
|
180
196
|
return {
|
|
181
197
|
name: "stop_agent",
|
|
182
198
|
safe: false,
|
|
183
|
-
description: "Stop a background sub-agent
|
|
184
|
-
"acknowledge it. `id` stops one; omit it (or \"all\") to stop every
|
|
185
|
-
"come back as its report
|
|
186
|
-
"write
|
|
199
|
+
description: "Stop a background sub-agent when the owner asks to stop, cancel or kill one (or all) — never just " +
|
|
200
|
+
"acknowledge it — or when it is STUCK. `id` (or name) stops one; omit it (or \"all\") to stop every " +
|
|
201
|
+
"running/queued one. Its PARTIAL findings come back as its report; then do its step yourself or re-brief a fresh " +
|
|
202
|
+
"agent, and tell the owner which. Research/search/review/plan agents write no files by design — judge them by " +
|
|
203
|
+
"rounds and notes, not files.",
|
|
187
204
|
parameters: {
|
|
188
205
|
type: "object",
|
|
189
|
-
properties: { id: { type: "string", description: "sub-agent id; omit or \"all\" for every one" } },
|
|
206
|
+
properties: { id: { type: "string", description: "sub-agent id or name; omit or \"all\" for every one" } },
|
|
190
207
|
},
|
|
191
208
|
run: async (args) => {
|
|
192
209
|
const id = String(args.id ?? "").trim();
|
|
@@ -296,6 +313,7 @@ export class Session {
|
|
|
296
313
|
pin; // the owner's context pin (tokens); undefined = auto — read live by the engine router
|
|
297
314
|
servedByBase = new Map(); // raw n_ctx learned per base (probeServedContext)
|
|
298
315
|
moaConfig;
|
|
316
|
+
classifier;
|
|
299
317
|
fastStartConfig;
|
|
300
318
|
fastStartEnabled;
|
|
301
319
|
modelId = DEFAULT_MODEL_ID; // active /model selection
|
|
@@ -324,6 +342,7 @@ export class Session {
|
|
|
324
342
|
maxTurnWallClockMs;
|
|
325
343
|
loopGuard;
|
|
326
344
|
liveAgents;
|
|
345
|
+
slotSharers;
|
|
327
346
|
wakeTurn = false; // the turn in flight was started by the shell to deliver a report / job notice, not typed by the owner
|
|
328
347
|
hooks;
|
|
329
348
|
cwd;
|
|
@@ -420,6 +439,8 @@ export class Session {
|
|
|
420
439
|
if (!allow.has(name))
|
|
421
440
|
reg.delete(name);
|
|
422
441
|
}
|
|
442
|
+
for (const name of cfg.toolDeny ?? [])
|
|
443
|
+
reg.delete(name);
|
|
423
444
|
this.executor = new Executor(reg, cfg.cwd, cfg.sessionId);
|
|
424
445
|
this.shellKey = this.executor.shellKey; // for disposeShell() on teardown
|
|
425
446
|
this.localSchemas = toSchemas(reg);
|
|
@@ -436,6 +457,7 @@ export class Session {
|
|
|
436
457
|
this.registry = modelRegistry(cfg.models);
|
|
437
458
|
this.isOwner = (cfg.eventActor?.tier ?? "admin") === "admin"; // set before the startup setModel so a persisted owner-only activeModel resolves for the owner
|
|
438
459
|
this.moaConfig = cfg.moa;
|
|
460
|
+
this.classifier = cfg.classifier;
|
|
439
461
|
this.fastStartConfig = cfg.fastStart;
|
|
440
462
|
this.fastStartEnabled = isFeatureEnabled("fastStart", { features: cfg.features }) && !!cfg.fastStart;
|
|
441
463
|
// Apply the persisted /model choice, unless a router was explicitly injected (tests / bg agents
|
|
@@ -450,6 +472,7 @@ export class Session {
|
|
|
450
472
|
this.maxTurnWallClockMs = cfg.maxTurnWallClockMs;
|
|
451
473
|
this.loopGuard = cfg.loopGuard;
|
|
452
474
|
this.liveAgents = cfg.liveAgents;
|
|
475
|
+
this.slotSharers = cfg.slotSharers;
|
|
453
476
|
this.hooks = cfg.hooks;
|
|
454
477
|
this.cwd = cfg.cwd;
|
|
455
478
|
this.unattended = cfg.unattended === true;
|
|
@@ -825,6 +848,32 @@ export class Session {
|
|
|
825
848
|
currentModel() {
|
|
826
849
|
return this.modelId;
|
|
827
850
|
}
|
|
851
|
+
/** The endpoint chain for a single-endpoint profile (/model, and the MoA specialist's fast path). */
|
|
852
|
+
routerForProfile(profile) {
|
|
853
|
+
// BYO connectors carry their vendor bearer (never the Operator token — see authHeaders scoping);
|
|
854
|
+
// selectModel already refused the id if the key is not connected, so resolution can't miss here.
|
|
855
|
+
const token = profile.byo ? getByoToken(profile.byo, profileEndpoint(profile)) : undefined;
|
|
856
|
+
// A failover `endpoints` list builds one AuroraRouter endpoint per box (same model/alias on each), so
|
|
857
|
+
// the router hops primary->standby on a busy/5xx; a lone `endpoint` is the single-box case. Names carry
|
|
858
|
+
// the host so /route reads which box answered.
|
|
859
|
+
const bases = profile.endpoints?.length ? profile.endpoints : [profile.endpoint];
|
|
860
|
+
// A fleet entry that lists the AXE gateway beside direct LAN legs: authHeaders trusts LAN hosts, so
|
|
861
|
+
// without this the Operator bearer would ride along to the LAN leg. "" is falsy (no Authorization
|
|
862
|
+
// header) yet not nullish, so it also stops authHeaders falling back to the signed-in token.
|
|
863
|
+
const hasGatewayLeg = !profile.byo && bases.some((b) => requiresOperatorToken(b));
|
|
864
|
+
const eps = bases.map((ep, i) => ({
|
|
865
|
+
name: bases.length > 1 ? `${profile.id}@${endpointBase(ep).replace(/^https?:\/\//, "")}` : profile.id,
|
|
866
|
+
base: endpointBase(ep),
|
|
867
|
+
model: profile.endpointModels?.[i] ?? profile.model ?? profile.id,
|
|
868
|
+
ctxLimit: profile.ctx ?? this.inner.ctxLimit(),
|
|
869
|
+
token: token ?? (hasGatewayLeg && !requiresOperatorToken(ep) ? "" : undefined),
|
|
870
|
+
transport: profile.transport,
|
|
871
|
+
chatPath: profile.chatPath,
|
|
872
|
+
maxOutput: profile.maxOutput,
|
|
873
|
+
provider: profile.box,
|
|
874
|
+
}));
|
|
875
|
+
return new AuroraRouter(eps);
|
|
876
|
+
}
|
|
828
877
|
/** Switch the active model (/model). A "single" profile rebuilds the router to point at that
|
|
829
878
|
* endpoint — no server is started/stopped, this only changes which endpoint THIS session talks
|
|
830
879
|
* to. "moa" has no endpoint of its own; send() special-cases it (sendMoa) instead. Returns an
|
|
@@ -834,8 +883,8 @@ export class Session {
|
|
|
834
883
|
const { profile, error } = selectModel(this.liveRegistry(), id, hasByoToken, this.isOwner);
|
|
835
884
|
if (error || !profile)
|
|
836
885
|
return { ok: false, error };
|
|
837
|
-
if (profile.kind === "orchestrated" && !this.moaConfig
|
|
838
|
-
return { ok: false, error: `MOA needs a "moa" block (
|
|
886
|
+
if (profile.kind === "orchestrated" && !moaTeam(this.moaConfig)) {
|
|
887
|
+
return { ok: false, error: `MOA needs a "moa" block (planner + specialist) in settings.json` };
|
|
839
888
|
}
|
|
840
889
|
if (profile.kind === "single" && profile.id === DEFAULT_MODEL_ID && this.chain) {
|
|
841
890
|
// The default local model IS the shell's endpoint chain (the gateway's published port + its failover
|
|
@@ -845,29 +894,7 @@ export class Session {
|
|
|
845
894
|
this.router = this.wrap(this.inner);
|
|
846
895
|
}
|
|
847
896
|
else if (profile.kind === "single" && (profile.endpoint || profile.endpoints?.length)) {
|
|
848
|
-
|
|
849
|
-
// selectModel already refused the id if the key is not connected, so resolution can't miss here.
|
|
850
|
-
const token = profile.byo ? getByoToken(profile.byo, profileEndpoint(profile)) : undefined;
|
|
851
|
-
// A failover `endpoints` list builds one AuroraRouter endpoint per box (same model/alias on each), so
|
|
852
|
-
// the router hops primary->standby on a busy/5xx; a lone `endpoint` is the single-box case. Names carry
|
|
853
|
-
// the host so /route reads which box answered.
|
|
854
|
-
const bases = profile.endpoints?.length ? profile.endpoints : [profile.endpoint];
|
|
855
|
-
// A fleet entry that lists the AXE gateway beside direct LAN legs: authHeaders trusts LAN hosts, so
|
|
856
|
-
// without this the Operator bearer would ride along to the LAN leg. "" is falsy (no Authorization
|
|
857
|
-
// header) yet not nullish, so it also stops authHeaders falling back to the signed-in token.
|
|
858
|
-
const hasGatewayLeg = !profile.byo && bases.some((b) => requiresOperatorToken(b));
|
|
859
|
-
const eps = bases.map((ep, i) => ({
|
|
860
|
-
name: bases.length > 1 ? `${profile.id}@${endpointBase(ep).replace(/^https?:\/\//, "")}` : profile.id,
|
|
861
|
-
base: endpointBase(ep),
|
|
862
|
-
model: profile.endpointModels?.[i] ?? profile.model ?? profile.id,
|
|
863
|
-
ctxLimit: profile.ctx ?? this.inner.ctxLimit(),
|
|
864
|
-
token: token ?? (hasGatewayLeg && !requiresOperatorToken(ep) ? "" : undefined),
|
|
865
|
-
transport: profile.transport,
|
|
866
|
-
chatPath: profile.chatPath,
|
|
867
|
-
maxOutput: profile.maxOutput,
|
|
868
|
-
provider: profile.box,
|
|
869
|
-
}));
|
|
870
|
-
this.inner = new AuroraRouter(eps);
|
|
897
|
+
this.inner = this.routerForProfile(profile);
|
|
871
898
|
this.router = this.wrap(this.inner);
|
|
872
899
|
}
|
|
873
900
|
this.modelId = profile.id;
|
|
@@ -1182,36 +1209,23 @@ export class Session {
|
|
|
1182
1209
|
this.wakeTurn = false;
|
|
1183
1210
|
}
|
|
1184
1211
|
}
|
|
1185
|
-
/** MOA turn (
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
const
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
survived: survivors.map((d) => d.id),
|
|
1200
|
-
latenciesMs: Object.fromEntries(drafts.map((d) => [d.id, d.ms])),
|
|
1201
|
-
});
|
|
1202
|
-
if (!survivors.length) {
|
|
1203
|
-
h.onRoute?.(active.id, this.ctxPct());
|
|
1204
|
-
this.modelId = DEFAULT_MODEL_ID; // fall back for this and future turns until /model moa retries
|
|
1205
|
-
const note = "MOA: every proposer failed or timed out — falling back to operator-1m for this reply.\n\n";
|
|
1206
|
-
h.onDelta?.(note);
|
|
1207
|
-
const res = await this.execute(text, h, this.router, this.sysWithThink());
|
|
1208
|
-
return { ...res, content: note + res.content };
|
|
1209
|
-
}
|
|
1210
|
-
const aggRouter = this.wrap(new AuroraRouter([
|
|
1211
|
-
{ name: moa.aggregator.id, base: endpointBase(moa.aggregator.endpoint), model: moa.aggregator.model, ctxLimit: this.inner.ctxLimit() },
|
|
1212
|
+
/** MOA turn (engine/moa.ts): the planner takes the turn through the SAME runTurn loop as any turn (execute), on its
|
|
1213
|
+
* own endpoint, with the planner brief in the system prompt — and every delegate_task in it defaults to the
|
|
1214
|
+
* specialist. The brief is fixed per team, so the system prompt stays byte-stable across turns. */
|
|
1215
|
+
async sendMoa(text, h, _active) {
|
|
1216
|
+
const team = moaTeam(this.moaConfig); // setModel refuses to select "moa" without one
|
|
1217
|
+
// The router (classifier/route.ts): a request it is confident needs no tools goes straight to the fast
|
|
1218
|
+
// specialist — no planner round, no planner prefill. Anything else, or no answer from the router, is planned.
|
|
1219
|
+
const route = this.classifier && this.classifier.mode !== "off" ? await routeTurn(text, this.classifier.endpoint) : null;
|
|
1220
|
+
const specialist = route?.route === "direct" ? this.liveRegistry().find((m) => m.id === team.specialist && m.kind === "single") : undefined;
|
|
1221
|
+
this.telemetry.record({ type: "moa", planner: team.planner.id, specialist: team.specialist, route: specialist ? "direct" : route ? "planned" : "unrouted", pDirect: route?.pDirect });
|
|
1222
|
+
if (specialist)
|
|
1223
|
+
return this.execute(text, h, this.wrap(this.routerForProfile(specialist)), this.sysWithThink(), specialist.id);
|
|
1224
|
+
const plannerRouter = this.wrap(new AuroraRouter([
|
|
1225
|
+
{ name: team.planner.id, base: endpointBase(team.planner.endpoint), model: team.planner.model, ctxLimit: this.inner.ctxLimit() },
|
|
1212
1226
|
]));
|
|
1213
|
-
const
|
|
1214
|
-
return this.execute(text, h,
|
|
1227
|
+
const sys = `${this.sysWithThink() ?? ""}\n\n## MOA: planner\n${plannerBrief(team)}`;
|
|
1228
|
+
return withDelegateDefault(team.specialist, () => this.execute(text, h, plannerRouter, sys, team.planner.id));
|
|
1215
1229
|
}
|
|
1216
1230
|
/** Fire scout (settings.fastStart) with a bounded, independent timeout — never the real turn's own
|
|
1217
1231
|
* abort signal, so a user esc during the real turn doesn't need to also race scout's cleanup. Any
|
|
@@ -1293,7 +1307,8 @@ export class Session {
|
|
|
1293
1307
|
// for the flywheel row — the per-step structure SRFT credit assignment needs. runTurn pushes the user
|
|
1294
1308
|
// message itself, so everything from here on is this turn's.
|
|
1295
1309
|
const convoStart = this.convo.all.length;
|
|
1296
|
-
const
|
|
1310
|
+
const statusFirst = isStatusAsk(text) ? engineNote(STATUS_FIRST_NOTE) : ""; // the owner's "update?" is answered before any work
|
|
1311
|
+
const carry = [this.skillNote, this.pinnedSkill(), statusFirst].filter(Boolean).join("\n\n");
|
|
1297
1312
|
this.skillNote = "";
|
|
1298
1313
|
if (carry)
|
|
1299
1314
|
text = `${carry}\n\n${text}`;
|
|
@@ -1309,6 +1324,7 @@ export class Session {
|
|
|
1309
1324
|
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
|
|
1310
1325
|
background: this.background, // endpoint gate: a sub-agent's rounds yield the shared slot to the main turn
|
|
1311
1326
|
liveSubAgents: this.wakeTurn ? this.liveAgents : undefined, // a wake turn with sub-agents live yields from its first idle round
|
|
1327
|
+
slotSharers: this.slotSharers, // …but only to sub-agents on THIS model's slot; children on another server never make it yield
|
|
1312
1328
|
maxTokens: this.maxTokens,
|
|
1313
1329
|
maxTurnTokens: this.maxTurnTokens, // opt-in per-turn cost ceiling (total tokens); undefined → no cap
|
|
1314
1330
|
maxTurnWallClockMs: this.maxTurnWallClockMs, // opt-in per-turn TIME ceiling; the brake on hour-long crawling turns
|
|
@@ -1334,6 +1350,7 @@ export class Session {
|
|
|
1334
1350
|
onServed: h.onServed,
|
|
1335
1351
|
onSelfHeal: (kind, attempt) => { this.telemetry.record({ type: "self_heal", kind, attempt }); h.onSelfHeal?.(kind, attempt); },
|
|
1336
1352
|
onCompaction: (e) => { this.telemetry.record({ type: "compaction", ...e }); h.onCompaction?.(e); },
|
|
1353
|
+
steer: h.steer,
|
|
1337
1354
|
// Truncation black-box: raw unparseable-args evidence → observability/blackbox.ts (content-bearing,
|
|
1338
1355
|
// local-only). NOT telemetry.jsonl — that stream is metrics-only by policy. A metrics-only marker
|
|
1339
1356
|
// still goes to telemetry so dashboards can count incidents without reading content.
|