@0perator/operator 0.1.345 → 0.1.347
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/autonomy/delegate.js +4 -3
- package/dist/autonomy/session-factory.js +2 -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/cli.js +64 -32
- package/dist/config/persona.js +29 -16
- package/dist/engine/agent.js +40 -18
- package/dist/engine/anthropic-chat.js +2 -2
- package/dist/engine/aurora.js +8 -4
- package/dist/engine/continuation.js +30 -5
- package/dist/engine/grandmaster.js +18 -1
- package/dist/engine/loop-guard.js +58 -24
- package/dist/session.js +48 -26
- package/dist/tools/executor.js +2 -1
- 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
|
@@ -85,6 +85,20 @@ export const ENGINE_NOTE_PREFIX = "[engine note — automatic, not from the owne
|
|
|
85
85
|
export function engineNote(text) {
|
|
86
86
|
return text.startsWith(ENGINE_NOTE_PREFIX) ? text : ENGINE_NOTE_PREFIX + text;
|
|
87
87
|
}
|
|
88
|
+
// The owner asking where things stand, or saying something went wrong. 10/31: after "why did you stop and what did we
|
|
89
|
+
// get done — I received no update at any time", the model went silent for 7 minutes writing a document before saying a
|
|
90
|
+
// word. The owner's question comes first. Short messages only: a long brief that happens to contain "update" is a task.
|
|
91
|
+
const STATUS_ASK = new RegExp(String.raw `^\s*(?:any\s+)?(?:update|status|progress)\s*[?.!]*\s*$|` +
|
|
92
|
+
String.raw `\b(?:where are we|where (?:do|are) things|what(?:'s| is) (?:the )?(?:status|progress)|what did (?:we|you) (?:get )?(?:do|done|finish)|` +
|
|
93
|
+
String.raw `why did (?:you|it|this) stop|why (?:are you|is it) (?:stuck|stopped|idle)|are you (?:stuck|done)|what happened|` +
|
|
94
|
+
String.raw `(?:received|got|had) no update|no update)\b`, "i");
|
|
95
|
+
export function isStatusAsk(text) {
|
|
96
|
+
const t = text.trim();
|
|
97
|
+
return t.length > 0 && t.length <= 280 && STATUS_ASK.test(t);
|
|
98
|
+
}
|
|
99
|
+
export const STATUS_FIRST_NOTE = "The owner is asking where things stand. Your FIRST output, before any tool call, is the update: what is done (and " +
|
|
100
|
+
"checked), what is not and why, and what you will do next. Then carry on — and hand independent parts to named " +
|
|
101
|
+
"sub-agents in the same round so the work moves in parallel.";
|
|
88
102
|
export const SELF_DIALOGUE_NUDGE_MAX = 2;
|
|
89
103
|
export const SELF_DIALOGUE_NUDGE = "Nobody spoke: the owner has sent nothing new since they last wrote, and engine notes are not the owner. Do not " +
|
|
90
104
|
"answer an imagined message, do not write a line for the owner and reply to it, and do not quote or paraphrase an " +
|
|
@@ -113,8 +127,15 @@ export function detectSelfDialogue(content, repliesSinceOwner) {
|
|
|
113
127
|
return REACTION_RE.test(text) || FABRICATED_LINE_RE.test(text) || SPEAKER_LABEL_RE.test(text) || GREETING_ONLY_RE.test(text);
|
|
114
128
|
}
|
|
115
129
|
/** A model that was just told what the marker means may echo it back; the owner must never see it. */
|
|
130
|
+
// A whole line in the MODEL's reply that copies one of the engine's own markers (10/31: the model ended "Waiting for its
|
|
131
|
+
// report." with a line "[turn ended]" it wrote itself — on screen it read as the engine stopping with nothing to say).
|
|
132
|
+
const ECHOED_MARKER_LINE = /^[ \t]*\[(?:turn ended|stopped|paused|engine note)[^\]\n]*\][ \t]*$/gim;
|
|
116
133
|
export function stripEngineEcho(content) {
|
|
117
|
-
|
|
134
|
+
const head = (content ?? "").replace(/^\s*\[engine note[^\]]*\]\s*/i, "").replace(/^\s*engine note:\s*/i, "");
|
|
135
|
+
// Outside fenced code only: a literal "[stopped]" in a code sample is the owner's content, not an echo.
|
|
136
|
+
const parts = head.split(/(```[\s\S]*?```)/);
|
|
137
|
+
const cleaned = parts.map((p, i) => (i % 2 === 1 ? p : p.replace(ECHOED_MARKER_LINE, ""))).join("");
|
|
138
|
+
return cleaned === head ? head : cleaned.replace(/\n{3,}/g, "\n\n").trim();
|
|
118
139
|
}
|
|
119
140
|
export const CLOSING_NUDGE = "You are about to end this turn with work still open and no question for the owner. Either continue the open " +
|
|
120
141
|
"items now, or close properly: one line of status per open item (done / in progress / blocked and why) and " +
|
|
@@ -128,6 +149,7 @@ const QUESTION_RE = /[??]\s*(?:\*\*|_)?\s*$/m;
|
|
|
128
149
|
const STATUS_RE = /^(?:#{1,4}\s*|\*\*)?(?:status|where (?:things|we) (?:stand|are)|progress|open items?|next steps?|blocked(?: on)?)\b\s*(?:\*\*)?\s*[:—–-]/im;
|
|
129
150
|
// A final that names remaining work without a task list ("cameras and lights are still to do").
|
|
130
151
|
const REMAINING_RE = /\b(?:still to do|still (?:need|needs|remain)|remaining|left to do|to do next|not (?:yet )?done|haven['’]t (?:done|finished|started)|next up)\b/i;
|
|
152
|
+
const WAITING_ON_AGENT_RE = /\bwaiting (?:for|on) (?:its|their|the|a|an|my|agent|sub-?agents?|[a-z]+-\d+)\b[^.?!\n]*/gi;
|
|
131
153
|
/** True when a text-only final should not end the turn as is: work remains (open task-list items, or — with no task
|
|
132
154
|
* list — the text itself names remaining work) and the text neither asks the owner anything, hands back, nor
|
|
133
155
|
* reports status. A hand-back ("let me know…") or a report already leaves the owner with something to act on. */
|
|
@@ -139,7 +161,8 @@ export function needsClosingSteer(content, hasOpenTasks) {
|
|
|
139
161
|
return true;
|
|
140
162
|
if (QUESTION_RE.test(text))
|
|
141
163
|
return false;
|
|
142
|
-
|
|
164
|
+
// "Waiting for its report." hands nothing to the owner (10/31: the whole reply to "update", then a dead turn).
|
|
165
|
+
if (HANDBACK_RE.test(text.replace(WAITING_ON_AGENT_RE, "")) || SUMMARY_RE.test(text) || STATUS_RE.test(text))
|
|
143
166
|
return false;
|
|
144
167
|
return true;
|
|
145
168
|
}
|
|
@@ -159,7 +182,7 @@ function tasksBlock(activeTasks) {
|
|
|
159
182
|
* stays in history and in `content` — the model and the flywheel, delegate and self-improve detectors key on it — but on
|
|
160
183
|
* screen a bracketed engine note reads as an error. This is the same situation said plainly, ending in a question. */
|
|
161
184
|
const STOP_QUESTIONS = [
|
|
162
|
-
{ match: /sub-agents? (?:are running|dispatched)|waiting on sub-agents/i, lead: "I've handed parts of this to helpers and will pick it up as soon as they report back.", ask: "" },
|
|
185
|
+
{ match: /sub-agents? (?:are running|dispatched)|waiting on sub-agents/i, lead: "I've handed parts of this to helpers and will pick it up as soon as they report back.", ask: "Want me to keep going on the next step meanwhile, change what one of them is doing, or take a step over myself?" },
|
|
163
186
|
{ match: /repetition loop/i, lead: "That answer wasn't coming out right, so I held it back.", ask: "Want me to take another pass with a different approach, or is there one part you'd like me to focus on first?" },
|
|
164
187
|
{ match: /reasoned a long time/i, lead: "I've thought this through but haven't acted on it yet.", ask: "Should I go ahead with the next concrete step, or would you like to point me somewhere first?" },
|
|
165
188
|
{ match: /^\[paused/i, lead: "This is taking longer than I expected.", ask: "Want me to keep going from here?" },
|
|
@@ -182,9 +205,11 @@ export function emptyReplyStatus(activeTasks, tries) {
|
|
|
182
205
|
return `[no reply came back from the model after ${tries} tries. Where things stand:${tasks}\n\nTell me which step to take next, or say "continue" to resume from here.]`;
|
|
183
206
|
}
|
|
184
207
|
/** Append the active task list and a steer to an engine stop note. A yield note (sub-agents will resume the turn)
|
|
185
|
-
* gets
|
|
208
|
+
* gets its own steer: the owner can always take the delegated work back. */
|
|
186
209
|
export function closeStopNote(note, activeTasks) {
|
|
187
210
|
const yielded = /sub-agents? (?:are running|dispatched)|waiting on sub-agents/i.test(note);
|
|
188
|
-
const steer = yielded
|
|
211
|
+
const steer = yielded
|
|
212
|
+
? `\n\nTo steer: say "take over" and I'll do the delegated steps myself, name an agent to change its brief, or say "wait".`
|
|
213
|
+
: `\n\nTo steer: tell me which step to take next, or say "continue" to resume from here.`;
|
|
189
214
|
return note + tasksBlock(activeTasks) + steer;
|
|
190
215
|
}
|
|
@@ -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"];
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// Detectors: consecutive identical (tool, args, result) calls; repeating cycles A,B,A,B… of up to four calls
|
|
9
9
|
// with identical args and results; exact-args failure replays; failure runs on one tool; read-only calls that
|
|
10
10
|
// keep returning the same result; per-turn caps on web searches and sub-agent spawns. Warnings never block.
|
|
11
|
-
// A hard stop is on by default for unattended runs and opt-in for an interactive owner
|
|
11
|
+
// A hard stop is on by default for unattended runs and opt-in for an interactive owner; before it ends a turn the
|
|
12
|
+
// engine offers bounded recovery (LoopRecovery).
|
|
12
13
|
export const LOOP_GUARD_DEFAULTS = {
|
|
13
14
|
warnIdentical: 3, warnExactFailure: 2, warnSameToolFailure: 3, warnNoProgress: 2, warnInvestigateLoop: 8,
|
|
14
15
|
stopIdentical: 5, stopExactFailure: 5, stopSameToolFailure: 8, stopNoProgress: 5, stopInvestigateLoop: 15,
|
|
@@ -24,6 +25,8 @@ export function resolveLoopGuardConfig(raw, ctx) {
|
|
|
24
25
|
enabled: s.enabled !== false,
|
|
25
26
|
hardStop: typeof s.hardStop === "boolean" ? s.hardStop : ctx.unattended,
|
|
26
27
|
repetition: s.repetition !== false,
|
|
28
|
+
recoveryAttempts: Math.min(5, intAtLeast(s.recovery?.maxAttempts, 2, 0)),
|
|
29
|
+
stopOnNoWrite: s.stopOnNoWrite === true,
|
|
27
30
|
warnIdentical: intAtLeast(s.warnAfter?.identicalCall, d.warnIdentical, 2),
|
|
28
31
|
warnExactFailure: intAtLeast(s.warnAfter?.exactFailure, d.warnExactFailure, 1),
|
|
29
32
|
warnSameToolFailure: intAtLeast(s.warnAfter?.sameToolFailure, d.warnSameToolFailure, 1),
|
|
@@ -148,6 +151,10 @@ export class LoopGuard {
|
|
|
148
151
|
}
|
|
149
152
|
/** The decision that ended the turn, if any. The engine stops cleanly at the next batch boundary. */
|
|
150
153
|
get halt() { return this.haltDecision; }
|
|
154
|
+
/** Legacy repeat detectors enter the same batch-boundary recovery path, never the user-cancel path. */
|
|
155
|
+
trip(message, code = "repeated_action") { this.stop(code, "tool batch", 0, message); }
|
|
156
|
+
/** Clear the pending stop only. Evidence, refusal counters and resource caps remain intact. */
|
|
157
|
+
resume() { this.haltDecision = null; }
|
|
151
158
|
stop(code, tool, count, message) {
|
|
152
159
|
const d = { action: "halt", code, message, tool, count };
|
|
153
160
|
this.haltDecision ??= d;
|
|
@@ -350,13 +357,12 @@ export class LoopGuard {
|
|
|
350
357
|
// else might.
|
|
351
358
|
export const AUTOPOST_POLLERS = new Set(["agent_status"]);
|
|
352
359
|
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.]";
|
|
360
|
+
export const POLL_SPIN_NUDGE = "agent_status will not change faster by asking again — each report, and a STUCK notice if one stalls, arrives " +
|
|
361
|
+
"as a message on its own. Act on what it shows: steer an agent that is stuck or off its brief (message_agent), " +
|
|
362
|
+
"or stop it (stop_agent) and do its step yourself. Otherwise do the work that does not depend on them, or close " +
|
|
363
|
+
"the turn for the owner: one status line per agent (round, files written) and 2-3 options.";
|
|
364
|
+
export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no change. Their reports, and a notice if " +
|
|
365
|
+
"one gets stuck, arrive on their own. Nothing was lost.]";
|
|
360
366
|
/** Watches settled tool rounds for an auto-post-poller spin. Fed one round at a time via observe(); a
|
|
361
367
|
* productive (non-poller) tool OR a changed poll result resets the streak. Side-effect-free: the engine acts
|
|
362
368
|
* on the returned action (inject the nudge once, then end the turn). */
|
|
@@ -416,13 +422,14 @@ export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
|
|
|
416
422
|
* alone has no independent work in it. */
|
|
417
423
|
export const DISPATCH_BOOKKEEPING = new Set(["task_add", "task_update", "task_list", "task_clear", "agent_status", "message_agent"]);
|
|
418
424
|
export const YIELD_DEFAULTS = { nudgeAfter: 1, stopAfter: 2 };
|
|
419
|
-
export const YIELD_NUDGE = "Your sub-agents are
|
|
420
|
-
"
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
425
|
+
export const YIELD_NUDGE = "Your sub-agents are working their steps and this round changed nothing. Do not redo their work: finish what does " +
|
|
426
|
+
"not depend on them, or close the turn — one status line per agent and 2-3 options for the owner.";
|
|
427
|
+
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 " +
|
|
428
|
+
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
429
|
+
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 " +
|
|
430
|
+
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
431
|
+
/** Supervising IS progress: stopping a sub-agent (to take its step over) or asking the owner never counts as idling. */
|
|
432
|
+
export const SUPERVISION_TOOLS = new Set(["stop_agent", "ask_user"]);
|
|
426
433
|
/** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); a MUTATING
|
|
427
434
|
* round resets the streak. The endpoint's slot count sets the policy: on ONE slot (the fleet default) the parent
|
|
428
435
|
* working beside its sub-agents is pure contention — every parent round waits behind a sub-agent round and then
|
|
@@ -442,24 +449,27 @@ export class YieldAfterDispatchGuard {
|
|
|
442
449
|
this.stopAfter = stopAfter;
|
|
443
450
|
this.dispatched = armed;
|
|
444
451
|
}
|
|
445
|
-
/** One settled round: the tools it ran (names), whether any call changed the workspace,
|
|
446
|
-
*
|
|
447
|
-
|
|
452
|
+
/** One settled round: the tools it ran (names), whether any call changed the workspace, how many requests the
|
|
453
|
+
* model endpoint serves at once (engine/aurora.ts endpointSlots — 1 unless KODE_ENDPOINT_SLOTS says more), and
|
|
454
|
+
* whether a live sub-agent is served from THIS turn's slot. Sub-agents on another server (10/31: Cortana main,
|
|
455
|
+
* gpt-oss-20b children) cannot be starved by the parent, so it never yields to them — it keeps working and
|
|
456
|
+
* supervising, with one nudge against redoing their work. */
|
|
457
|
+
observe(names, mutating, slots = 1, shared = true) {
|
|
448
458
|
const single = slots <= 1;
|
|
449
459
|
if (names.some((n) => DISPATCH_TOOLS.has(n))) {
|
|
450
460
|
this.dispatched = true;
|
|
451
461
|
this.streak = 0;
|
|
452
462
|
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 };
|
|
463
|
+
return shared && single && pure ? { action: "halt", streak: 0, message: YIELD_DISPATCHED } : { action: "allow", streak: 0 };
|
|
454
464
|
}
|
|
455
465
|
if (!this.dispatched)
|
|
456
466
|
return { action: "allow", streak: 0 };
|
|
457
|
-
if (mutating) {
|
|
467
|
+
if (mutating || names.some((n) => SUPERVISION_TOOLS.has(n))) {
|
|
458
468
|
this.streak = 0;
|
|
459
469
|
return { action: "allow", streak: 0 };
|
|
460
470
|
}
|
|
461
471
|
this.streak += 1;
|
|
462
|
-
if (single || this.streak >= this.stopAfter)
|
|
472
|
+
if (shared && (single || this.streak >= this.stopAfter))
|
|
463
473
|
return { action: "halt", streak: this.streak, message: YIELD_STOP };
|
|
464
474
|
if (this.streak >= this.nudgeAfter && !this.nudged) {
|
|
465
475
|
this.nudged = true;
|
|
@@ -474,7 +484,8 @@ export class YieldAfterDispatchGuard {
|
|
|
474
484
|
// This detector keys on the ABSENCE of progress, not on repetition. It is a round-level guard
|
|
475
485
|
// (fed one settled round at a time), not a per-call guard.
|
|
476
486
|
export const INVESTIGATE_LOOP_NUDGE = "You have made no write-progress in the last {n} rounds — only reads, searches, and status checks. " +
|
|
477
|
-
"
|
|
487
|
+
"Summarize the evidence and the remaining question. If the task is research or review, produce the requested answer; " +
|
|
488
|
+
"if a change is required, take the smallest justified step and verify it. Do not create files merely to satisfy this notice.";
|
|
478
489
|
export const INVESTIGATE_LOOP_STOP = "[stopped — no write-progress in {n} consecutive rounds. You have been gathering context without producing output. " +
|
|
479
490
|
"Pick a direction and act on it, or end the turn.]";
|
|
480
491
|
/** Watches settled tool rounds for zero write-progress. Fed one round at a time via observe(); a
|
|
@@ -493,9 +504,9 @@ export class NoWriteProgressGuard {
|
|
|
493
504
|
}
|
|
494
505
|
reset() { this.streak = 0; this.warned = false; }
|
|
495
506
|
/** One settled round: the tools it ran (names) and their results, index-aligned. */
|
|
496
|
-
observe(names) {
|
|
507
|
+
observe(names, results) {
|
|
497
508
|
// Any write-progress call ⇒ progress, reset.
|
|
498
|
-
if (names.some((n) => WRITE_PROGRESS_TOOLS.has(n))) {
|
|
509
|
+
if (names.some((n, i) => WRITE_PROGRESS_TOOLS.has(n) && (!results || (results[i] !== undefined && !resultFailed(n, results[i]) && !/^(?:loop guard|repeated action|blocked)\b/i.test(results[i].trimStart()))))) {
|
|
499
510
|
this.reset();
|
|
500
511
|
return { action: "allow", streak: 0 };
|
|
501
512
|
}
|
|
@@ -516,3 +527,26 @@ export function loopStopNote(d) {
|
|
|
516
527
|
return `[stopped — the loop guard ended this turn: ${d.message}. Repeating it unchanged was not making progress. ` +
|
|
517
528
|
`Nothing was lost; tell me how you'd like to proceed, or ask me to continue and I'll take a different approach.]`;
|
|
518
529
|
}
|
|
530
|
+
/** Turn-local recovery budget. No network, endpoint selection, permission changes, or counter resets. */
|
|
531
|
+
export class LoopRecovery {
|
|
532
|
+
maxAttempts;
|
|
533
|
+
used = 0;
|
|
534
|
+
constructor(maxAttempts) {
|
|
535
|
+
this.maxAttempts = maxAttempts;
|
|
536
|
+
}
|
|
537
|
+
get attempts() { return this.used; }
|
|
538
|
+
next(d) {
|
|
539
|
+
// Caps are budgets, and a re-worded repeat of a COMPLETED action has nothing left to recover: both stay terminal.
|
|
540
|
+
if (d.code === "web_search_cap" || d.code === "subagent_cap" || d.code === "completed_action" || this.used >= this.maxAttempts)
|
|
541
|
+
return undefined;
|
|
542
|
+
this.used++;
|
|
543
|
+
return `Loop recovery ${this.used}/${this.maxAttempts}: ${d.message}. ` +
|
|
544
|
+
`Keep completed work and the original objective. Do not repeat the blocked action unchanged. ` +
|
|
545
|
+
(this.used === 1
|
|
546
|
+
? `State the failed assumption and use the available evidence to choose a different query, tool, or smaller step. `
|
|
547
|
+
: `The previous recovery did not resolve the stall. Work on an independent remaining step or report a useful partial result with the exact blocker and what is needed next. `) +
|
|
548
|
+
`Use only authorized tools and configured endpoints; offline evidence may suffice. Never bypass a permission denial, ` +
|
|
549
|
+
`repeat a side effect whose outcome is uncertain, invent missing information, or claim unverified success. ` +
|
|
550
|
+
`Continue within the existing time, token, round and resource limits.`;
|
|
551
|
+
}
|
|
552
|
+
}
|
package/dist/session.js
CHANGED
|
@@ -15,6 +15,7 @@ import { dirname } from "node:path";
|
|
|
15
15
|
import { operatorPath } from "./config/home.js";
|
|
16
16
|
import { moaTeam, plannerBrief } from "./engine/moa.js";
|
|
17
17
|
import { routeTurn } from "./classifier/route.js";
|
|
18
|
+
import { engineNote, isStatusAsk, STATUS_FIRST_NOTE } from "./engine/continuation.js";
|
|
18
19
|
import { withDelegateDefault } from "./autonomy/delegate.js";
|
|
19
20
|
import { routeShadowTurn, shadowPrompt } from "./moa/shadow.js"; // MOA phase-0 observability (KODE_MOA_SHADOW)
|
|
20
21
|
import { AuroraRouter } from "./router/router.js";
|
|
@@ -78,37 +79,49 @@ export function renderBudgetBlock(b) {
|
|
|
78
79
|
// The `spawn_agent` tool — a thin pass-through to the shell's delegate handler. The handler owns the
|
|
79
80
|
// policy (cap) and the reply text; the tool just guards against an empty task. safe:false so it's an
|
|
80
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;
|
|
81
85
|
function makeSpawnTool(handler) {
|
|
82
86
|
return {
|
|
83
87
|
name: "spawn_agent",
|
|
84
88
|
safe: false,
|
|
85
|
-
description: "Spawn sub-agents: isolated sessions
|
|
86
|
-
"sub-agent; several run in parallel (2 running + 2 queued by default).
|
|
87
|
-
"
|
|
88
|
-
" what does NOT depend on them
|
|
89
|
-
"
|
|
90
|
-
"
|
|
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" +
|
|
91
96
|
"USE FOR: reasoning-heavy or context-flooding subtasks, independent parallel workstreams (research per area, " +
|
|
92
97
|
"review per module, search per tree, drafting a file).\n" +
|
|
93
98
|
"DO NOT USE FOR: a single tool call; mechanical steps; anything that needs the user; edits to the same files " +
|
|
94
99
|
"from several agents.\n" +
|
|
95
100
|
"RULES: the sub-agent knows NOTHING of this conversation — brief it as a spec: **Objective** · **Context** " +
|
|
96
|
-
"(every path, id, fact) · **Deliverable** · **Constraints** · **Done**. A
|
|
97
|
-
"
|
|
98
|
-
"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.",
|
|
99
104
|
parameters: {
|
|
100
105
|
type: "object",
|
|
101
106
|
properties: {
|
|
102
107
|
tasks: { type: "array", items: { type: "string" }, description: "the brief(s); one entry per sub-agent" },
|
|
103
108
|
task: { type: "string", description: "a single brief (same as a one-entry `tasks`)" },
|
|
104
|
-
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." },
|
|
105
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`" },
|
|
106
113
|
},
|
|
107
114
|
},
|
|
108
115
|
run: async (args) => {
|
|
109
116
|
const briefs = (Array.isArray(args.tasks) ? args.tasks.map((t) => String(t ?? "").trim()) : [String(args.task ?? "").trim()]).filter(Boolean);
|
|
110
117
|
if (!briefs.length)
|
|
111
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
|
+
}
|
|
112
125
|
const agent = String(args.agent ?? "").trim();
|
|
113
126
|
const roleArg = String(args.role ?? "").trim();
|
|
114
127
|
const role = ["research", "search", "review", "plan", "code-edit", "generic"].includes(roleArg) ? roleArg : undefined;
|
|
@@ -119,10 +132,10 @@ function makeSpawnTool(handler) {
|
|
|
119
132
|
? `You are acting as the "${agent}" sub-agent for this repo. Follow this persona:\n\n${persona}\n\n---\nYour task:\n${task}`
|
|
120
133
|
: `${task}\n\n(note: no .operator/agents/${agent}.md persona found — ran without it)`;
|
|
121
134
|
if (briefs.length === 1)
|
|
122
|
-
return handler(frame(briefs[0]), role);
|
|
135
|
+
return handler(frame(briefs[0]), role, names[0] || undefined);
|
|
123
136
|
// Fan-out: one spawn per brief, in order; the manager queues past its running cap and refuses past the
|
|
124
137
|
// in-flight cap — each line reports what happened to that brief, so a partial fan-out is never silent.
|
|
125
|
-
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");
|
|
126
139
|
},
|
|
127
140
|
};
|
|
128
141
|
}
|
|
@@ -133,12 +146,13 @@ function makeMessageTool(handler) {
|
|
|
133
146
|
return {
|
|
134
147
|
name: "message_agent",
|
|
135
148
|
safe: false,
|
|
136
|
-
description: "Send a message to a background sub-agent that is STILL RUNNING (
|
|
137
|
-
"
|
|
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.",
|
|
138
152
|
parameters: {
|
|
139
153
|
type: "object",
|
|
140
154
|
properties: {
|
|
141
|
-
id: { type: "string", description: "sub-agent id
|
|
155
|
+
id: { type: "string", description: "sub-agent id (agent-1) or name" },
|
|
142
156
|
text: { type: "string", description: "the message" },
|
|
143
157
|
},
|
|
144
158
|
required: ["id", "text"],
|
|
@@ -160,13 +174,13 @@ function makeStatusTool(handler) {
|
|
|
160
174
|
return {
|
|
161
175
|
name: "agent_status",
|
|
162
176
|
safe: true,
|
|
163
|
-
description: "Check background sub-agents WITHOUT re-spawning them: no `id` lists every one
|
|
164
|
-
"(queued/working/idle/stopped); `id` checks one. Use it
|
|
165
|
-
"
|
|
166
|
-
"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.",
|
|
167
181
|
parameters: {
|
|
168
182
|
type: "object",
|
|
169
|
-
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" } },
|
|
170
184
|
},
|
|
171
185
|
run: async (args) => {
|
|
172
186
|
const id = String(args.id ?? "").trim();
|
|
@@ -182,13 +196,14 @@ function makeStopTool(handler) {
|
|
|
182
196
|
return {
|
|
183
197
|
name: "stop_agent",
|
|
184
198
|
safe: false,
|
|
185
|
-
description: "Stop a background sub-agent
|
|
186
|
-
"acknowledge it. `id` stops one; omit it (or \"all\") to stop every
|
|
187
|
-
"come back as its report
|
|
188
|
-
"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.",
|
|
189
204
|
parameters: {
|
|
190
205
|
type: "object",
|
|
191
|
-
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" } },
|
|
192
207
|
},
|
|
193
208
|
run: async (args) => {
|
|
194
209
|
const id = String(args.id ?? "").trim();
|
|
@@ -327,6 +342,7 @@ export class Session {
|
|
|
327
342
|
maxTurnWallClockMs;
|
|
328
343
|
loopGuard;
|
|
329
344
|
liveAgents;
|
|
345
|
+
slotSharers;
|
|
330
346
|
wakeTurn = false; // the turn in flight was started by the shell to deliver a report / job notice, not typed by the owner
|
|
331
347
|
hooks;
|
|
332
348
|
cwd;
|
|
@@ -423,6 +439,8 @@ export class Session {
|
|
|
423
439
|
if (!allow.has(name))
|
|
424
440
|
reg.delete(name);
|
|
425
441
|
}
|
|
442
|
+
for (const name of cfg.toolDeny ?? [])
|
|
443
|
+
reg.delete(name);
|
|
426
444
|
this.executor = new Executor(reg, cfg.cwd, cfg.sessionId);
|
|
427
445
|
this.shellKey = this.executor.shellKey; // for disposeShell() on teardown
|
|
428
446
|
this.localSchemas = toSchemas(reg);
|
|
@@ -454,6 +472,7 @@ export class Session {
|
|
|
454
472
|
this.maxTurnWallClockMs = cfg.maxTurnWallClockMs;
|
|
455
473
|
this.loopGuard = cfg.loopGuard;
|
|
456
474
|
this.liveAgents = cfg.liveAgents;
|
|
475
|
+
this.slotSharers = cfg.slotSharers;
|
|
457
476
|
this.hooks = cfg.hooks;
|
|
458
477
|
this.cwd = cfg.cwd;
|
|
459
478
|
this.unattended = cfg.unattended === true;
|
|
@@ -1288,7 +1307,8 @@ export class Session {
|
|
|
1288
1307
|
// for the flywheel row — the per-step structure SRFT credit assignment needs. runTurn pushes the user
|
|
1289
1308
|
// message itself, so everything from here on is this turn's.
|
|
1290
1309
|
const convoStart = this.convo.all.length;
|
|
1291
|
-
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");
|
|
1292
1312
|
this.skillNote = "";
|
|
1293
1313
|
if (carry)
|
|
1294
1314
|
text = `${carry}\n\n${text}`;
|
|
@@ -1304,6 +1324,7 @@ export class Session {
|
|
|
1304
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
|
|
1305
1325
|
background: this.background, // endpoint gate: a sub-agent's rounds yield the shared slot to the main turn
|
|
1306
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
|
|
1307
1328
|
maxTokens: this.maxTokens,
|
|
1308
1329
|
maxTurnTokens: this.maxTurnTokens, // opt-in per-turn cost ceiling (total tokens); undefined → no cap
|
|
1309
1330
|
maxTurnWallClockMs: this.maxTurnWallClockMs, // opt-in per-turn TIME ceiling; the brake on hour-long crawling turns
|
|
@@ -1329,6 +1350,7 @@ export class Session {
|
|
|
1329
1350
|
onServed: h.onServed,
|
|
1330
1351
|
onSelfHeal: (kind, attempt) => { this.telemetry.record({ type: "self_heal", kind, attempt }); h.onSelfHeal?.(kind, attempt); },
|
|
1331
1352
|
onCompaction: (e) => { this.telemetry.record({ type: "compaction", ...e }); h.onCompaction?.(e); },
|
|
1353
|
+
steer: h.steer,
|
|
1332
1354
|
// Truncation black-box: raw unparseable-args evidence → observability/blackbox.ts (content-bearing,
|
|
1333
1355
|
// local-only). NOT telemetry.jsonl — that stream is metrics-only by policy. A metrics-only marker
|
|
1334
1356
|
// still goes to telemetry so dashboards can count incidents without reading content.
|
package/dist/tools/executor.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// new user turn (not required by SPEC §3's
|
|
9
9
|
// round loop itself, but needed so the guard
|
|
10
10
|
// doesn't bleed across turns)
|
|
11
|
+
import { IDEMPOTENT_TOOLS } from "../engine/loop-guard.js";
|
|
11
12
|
import { isAbsolute, join, resolve } from "node:path";
|
|
12
13
|
import { registry } from "./registry.js";
|
|
13
14
|
import { expandPath } from "./paths.js";
|
|
@@ -80,7 +81,7 @@ export class Executor {
|
|
|
80
81
|
}
|
|
81
82
|
async execute(name, rawArgs) {
|
|
82
83
|
const args = this.root ? rootArgs(name, rawArgs, this.root) : rawArgs;
|
|
83
|
-
if (!LOOP_GUARD_EXEMPT.has(name)) { // poll/status tools are never loop-guarded (repeated calls are legit)
|
|
84
|
+
if (!LOOP_GUARD_EXEMPT.has(name) && !IDEMPOTENT_TOOLS.has(name)) { // poll/status tools are never loop-guarded (repeated calls are legit)
|
|
84
85
|
const key = `${name} ${JSON.stringify(args)}`;
|
|
85
86
|
const count = (this.seen.get(key) ?? 0) + 1;
|
|
86
87
|
this.seen.set(key, count);
|
|
@@ -5,41 +5,36 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
// tofu (same font-safety rule as the star).
|
|
6
6
|
// • StepSpinner — a tool batch is executing (braille run-spinner, cyan)
|
|
7
7
|
// • OrbitSpinner — a background sub-agent is working (rotating arc, violet)
|
|
8
|
-
import { useEffect, useRef
|
|
8
|
+
import { useEffect, useRef } from "react";
|
|
9
9
|
import { Text } from "ink";
|
|
10
10
|
import { theme } from "./theme.js";
|
|
11
11
|
import { useTick } from "./tick.js";
|
|
12
12
|
import { renderBar } from "./progressbar.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return;
|
|
18
|
-
const id = setInterval(() => setI((n) => (n + 1) % frames.length), tickMs);
|
|
19
|
-
return () => clearInterval(id);
|
|
20
|
-
}, [active, frames, tickMs]);
|
|
21
|
-
return frames[i];
|
|
13
|
+
// Every glyph advances off the ONE shared clock (tick.ts): a timer per spinner meant one full-frame redraw per
|
|
14
|
+
// working sub-agent per tick — the panel flashed harder with each agent added (10/31).
|
|
15
|
+
function useFrame(frames, active) {
|
|
16
|
+
return frames[useTick(active) % frames.length];
|
|
22
17
|
}
|
|
23
18
|
const BRAILLE = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; // classic run-spinner
|
|
24
19
|
const ORBIT = ["◜", "◠", "◝", "◞", "◡", "◟"]; // a dot orbiting a ring — "something running elsewhere"
|
|
25
20
|
const SETTLE = ["◐", "◓", "◑", "◒"]; // a filling/turning disc — "adjusting, working it out" (NOT an error)
|
|
26
21
|
/** Tools are executing this turn. Distinct from the star: a cyan braille run-spinner + the tool name(s). */
|
|
27
|
-
export function StepSpinner({ active, label
|
|
28
|
-
const glyph = useFrame(BRAILLE, active
|
|
22
|
+
export function StepSpinner({ active, label }) {
|
|
23
|
+
const glyph = useFrame(BRAILLE, active);
|
|
29
24
|
if (!active)
|
|
30
25
|
return null;
|
|
31
26
|
return (_jsxs(Text, { color: theme.info, children: [glyph, " ", label ? `${label}…` : "running…"] }));
|
|
32
27
|
}
|
|
33
28
|
/** A background sub-agent is working. Distinct again: a violet rotating arc + the agent label. */
|
|
34
|
-
export function OrbitSpinner({ active, label
|
|
35
|
-
const glyph = useFrame(ORBIT, active
|
|
29
|
+
export function OrbitSpinner({ active, label }) {
|
|
30
|
+
const glyph = useFrame(ORBIT, active);
|
|
36
31
|
if (!active)
|
|
37
32
|
return null;
|
|
38
33
|
return (_jsxs(Text, { color: theme.accent, children: [glyph, " ", label ?? "sub-agent working", "\u2026"] }));
|
|
39
34
|
}
|
|
40
35
|
/** Just the animated orbit glyph (violet), for embedding in the bg-agents list beside a working agent. */
|
|
41
|
-
export function OrbitGlyph(
|
|
42
|
-
return _jsx(Text, { color: theme.accent, children: useFrame(ORBIT, true
|
|
36
|
+
export function OrbitGlyph() {
|
|
37
|
+
return _jsx(Text, { color: theme.accent, children: useFrame(ORBIT, true) });
|
|
43
38
|
}
|
|
44
39
|
/** Self-heal in progress (context compaction / reconnect). Shown INSTEAD of a raw "http 400" so a recovery
|
|
45
40
|
* reads as the agent working it out, not an error — a PINK turning disc + a calm label + a PINK bar that
|