@0perator/operator 0.2.0 → 0.2.2-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/auth/byo.js +1 -1
- package/dist/auth/commands.js +15 -5
- package/dist/auth/identity.js +1 -0
- package/dist/auth/staff.js +55 -0
- package/dist/autonomy/agent-cli.js +1 -1
- package/dist/autonomy/delegate-mode.js +2 -2
- package/dist/autonomy/delegate.js +41 -14
- package/dist/autonomy/headless.js +37 -10
- package/dist/autonomy/index.js +2 -4
- package/dist/autonomy/pr-isolation.js +92 -0
- package/dist/autonomy/pr-preflight.js +474 -0
- package/dist/autonomy/session-factory.js +13 -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/browser/capture.js +505 -0
- package/dist/browser/engine.js +4 -3
- package/dist/browser/page-capture.js +167 -0
- package/dist/browser/png.js +116 -0
- package/dist/browser/visual-compare.js +229 -0
- package/dist/bus/beam-drop.js +55 -0
- package/dist/bus/inbox.js +157 -7
- package/dist/cli.js +316 -120
- package/dist/config/features.js +3 -3
- package/dist/config/managed.js +40 -1
- package/dist/config/persona.js +80 -29
- package/dist/config/product-hosts.js +2 -0
- package/dist/config/settings.js +289 -31
- package/dist/config/skills-index.js +37 -14
- package/dist/config/staff-prompt.js +12 -0
- package/dist/engine/agent.js +52 -41
- package/dist/engine/aurora.js +54 -13
- package/dist/engine/batch-scheduler.js +4 -13
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/continuation.js +66 -32
- package/dist/engine/decision-points.js +2 -3
- package/dist/engine/fanout.js +16 -0
- package/dist/engine/identity.js +42 -0
- package/dist/engine/loop-guard.js +26 -83
- package/dist/engine/messages.js +2 -2
- package/dist/engine/moa.js +23 -1
- package/dist/engine/native-vision-node.js +72 -0
- package/dist/engine/native-vision.js +103 -0
- package/dist/engine/net-error.js +15 -0
- package/dist/engine/rolling-summary.js +142 -93
- package/dist/engine/verify-gate.js +37 -7
- package/dist/engine/waterfall.js +33 -0
- package/dist/gateway-cli.js +24 -4
- package/dist/memory/live-progress.js +4 -5
- package/dist/memory/session-index.js +3 -3
- 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/index.js +2 -1
- package/dist/permissions/policy.js +9 -2
- package/dist/permissions/tier.js +13 -3
- package/dist/products/craft.js +92 -3
- package/dist/products/temple.js +20 -1
- package/dist/products/voice.js +112 -0
- package/dist/remote/grants.js +119 -0
- package/dist/remote/host.js +33 -5
- package/dist/router/free-models.js +5 -9
- package/dist/router/models.js +80 -26
- package/dist/router/provider-models.js +78 -0
- package/dist/router/router.js +15 -3
- package/dist/selfimprove/index.js +8 -6
- package/dist/selfimprove/lessons.js +23 -0
- package/dist/services/preflight.js +35 -91
- package/dist/session.js +316 -125
- package/dist/skills/catalogue.js +5 -2
- package/dist/skills/finder.js +4 -4
- 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/beam.js +246 -0
- package/dist/tools/classes.js +103 -0
- package/dist/tools/contract.js +1 -1
- package/dist/tools/craft.js +36 -2
- package/dist/tools/deferred.js +7 -3
- package/dist/tools/doc-text.js +1 -1
- package/dist/tools/executor.js +25 -15
- package/dist/tools/generation-gateway.js +94 -0
- package/dist/tools/registry.js +135 -158
- package/dist/tools/sandbox.js +6 -6
- package/dist/ui/App.js +17 -6
- package/dist/ui/ApprovalPrompt.js +1 -1
- package/dist/ui/BgPanel.js +15 -10
- package/dist/ui/Composer.js +44 -2
- package/dist/ui/Header.js +1 -6
- package/dist/ui/StatusRule.js +20 -8
- package/dist/ui/ToolStep.js +3 -3
- package/dist/ui/Transcript.js +41 -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/modelPicker.js +10 -6
- package/dist/ui/opsMode.js +20 -0
- package/dist/ui/phase.js +4 -2
- package/dist/ui/slashCommands.js +1 -0
- package/dist/ui/types.js +0 -2
- package/dist/ui/voice.js +185 -0
- package/dist/update-check.js +17 -6
- package/dist/update.js +1 -2
- package/dist/util/audio-io.js +82 -0
- package/dist/util/slash.js +2 -2
- package/dist/vision/pairs.js +239 -0
- package/package.json +1 -1
- package/dist/tools/mutating.js +0 -15
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// FINAL sentence is a first-person announcement of a tool-shaped action, and never on a question, a hand-back
|
|
10
10
|
// ("let me know…"), a deferral ("…in a follow-up"), a contingency ("if that fails, I'll…"), or a summary report.
|
|
11
11
|
// Dependency-free leaf (agent.ts is also bundled for the browser).
|
|
12
|
+
import { discloseModel, shownCause, shownCauses, shownModel, sentence } from "./identity.js";
|
|
12
13
|
/** At most this many continuation nudges per turn — the model can never be forced into an unbounded turn. */
|
|
13
14
|
export const ANNOUNCE_NUDGE_MAX = 2;
|
|
14
15
|
export const ANNOUNCE_NUDGE = "You described the next action but didn't perform it — proceed now: call the tool(s) to do it.";
|
|
@@ -58,13 +59,13 @@ export function detectUnfinishedAction(content) {
|
|
|
58
59
|
// while none of its calls delegated — the live failure (2026-10-28): a model that kept running bash itself,
|
|
59
60
|
// restating "then spawn sub-agents for each subsystem" round after round, and never calling spawn_agent.
|
|
60
61
|
const DELEGATION_RE = /\b(?:(?:spawning|spawn)\s+(?:a |the |some |more )?(?:parallel )?(?:sub-?)?agents?|(?:spinning|spin)\s+up\s+(?:sub-?)?agents?|sub-?agents?\s+(?:to|for|will|in parallel|per|should)|delegat(?:e|es|ed|ing)\s+(?:to|the|this|these|that|those|each|research|work|it|tasks?)|(?:fanning|fan)\s+out)\b/i;
|
|
61
|
-
|
|
62
|
+
import { DELEGATION } from "../tools/classes.js";
|
|
62
63
|
export const DELEGATION_NUDGE = "You said you would delegate, but this round made no spawn_agent call. If parts of the work are independent, call " +
|
|
63
64
|
"spawn_agent NOW with each part as an entry in `tasks` (they run in parallel) — otherwise do the work yourself. " +
|
|
64
65
|
"Do not announce delegation again without making the call.";
|
|
65
66
|
/** True when a tool round's narration announces delegation and none of the round's calls delegated. */
|
|
66
67
|
export function detectAnnouncedDelegation(content, calledTools) {
|
|
67
|
-
if (calledTools.some((n) =>
|
|
68
|
+
if (calledTools.some((n) => DELEGATION.has(n)))
|
|
68
69
|
return false;
|
|
69
70
|
const text = (content ?? "").trim();
|
|
70
71
|
return !!text && DELEGATION_RE.test(text);
|
|
@@ -196,11 +197,11 @@ export function needsDeliverFindings(final, o) {
|
|
|
196
197
|
return false; // it must close ON a question/ask — a report that merely mentions options is fine
|
|
197
198
|
return DIRECTION_ASK_RE.test(text);
|
|
198
199
|
}
|
|
199
|
-
/** True
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
export function
|
|
203
|
-
return
|
|
200
|
+
/** True when the engine, not the model, ended the turn: a typed stop (`stopKind`, set where the turn ends) or a reply the
|
|
201
|
+
* provider declined (its note is the content). The flywheel never grades it, a planner never takes it for a sub-agent's
|
|
202
|
+
* answer, headless exits non-zero. Never read from `content`: a model's answer may quote "[stopped — …]" itself. */
|
|
203
|
+
export function engineEnded(r) {
|
|
204
|
+
return r.stopKind !== undefined || r.stopReason === "content_filter";
|
|
204
205
|
}
|
|
205
206
|
export const EMPTY_REPLY_NUDGE = "Your reply was empty. Answer the owner now in plain text: what is done, what you are doing or about to do, and " +
|
|
206
207
|
"one question if you are blocked. If a tool call is needed, make the call — but never return nothing.";
|
|
@@ -209,31 +210,34 @@ function tasksBlock(activeTasks) {
|
|
|
209
210
|
const t = (activeTasks ?? "").replace(/^\[Your active task list[^\n]*\]\n?/, "").trim();
|
|
210
211
|
return t ? `\n\nOpen items:\n${t}` : "";
|
|
211
212
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
{
|
|
218
|
-
{
|
|
219
|
-
{
|
|
220
|
-
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
213
|
+
/** What the owner (or their client) reads when the engine ends a turn itself. The `[stopped — …]` / `[paused — …]` note
|
|
214
|
+
* stays in history and in `content` for the model to read, but on screen a bracketed engine note reads as an error.
|
|
215
|
+
* This is the same situation said plainly, ending in a question. context_floor writes its own (session.ts). */
|
|
216
|
+
const STOP_QUESTIONS = {
|
|
217
|
+
yield: { 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?" },
|
|
218
|
+
repetition: { 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?" },
|
|
219
|
+
reasoning_budget: { 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?" },
|
|
220
|
+
paused: { lead: "This is taking longer than I expected.", ask: "Want me to keep going from here?" },
|
|
221
|
+
window: { lead: "This conversation has grown too long for me to keep working in it.", ask: "Want me to compact it (/compact) and carry on?" },
|
|
222
|
+
rounds: { lead: "I've worked through a lot of steps and may not be finished.", ask: "Want me to continue from here?" },
|
|
223
|
+
unanswered: { lead: "Nothing answered this turn.", ask: "" },
|
|
224
|
+
length: { lead: "I ran out of room before finishing that answer.", ask: "Want me to continue?" },
|
|
225
|
+
owner: { lead: "You asked me to answer with what I had, and I kept reaching for tools instead.", ask: "Want me to answer from what I have now, or keep working on it?" },
|
|
226
|
+
stopped: { lead: "I'm not making progress with the approach I was taking.", ask: "Should I try a different way, or can you tell me which part matters most?" },
|
|
227
|
+
};
|
|
228
|
+
/** The owner-facing words for an engine stop of this kind, with the open task list. */
|
|
229
|
+
export function stopQuestion(kind, activeTasks) {
|
|
230
|
+
const q = kind === "context_floor" ? undefined : STOP_QUESTIONS[kind];
|
|
227
231
|
if (!q)
|
|
228
232
|
return undefined;
|
|
229
233
|
return [q.lead + tasksBlock(activeTasks), q.ask].filter(Boolean).join("\n\n");
|
|
230
234
|
}
|
|
231
|
-
/** The STOP_QUESTIONS key an engine stop note matches, or undefined for a normal answer. */
|
|
232
|
-
export function stopKind(note) {
|
|
233
|
-
return STOP_QUESTIONS.find((x) => x.match.test(note.trim()))?.key;
|
|
234
|
-
}
|
|
235
235
|
/** The owner's one line when the model's fallback answered this turn: what failed, why, and what answered. */
|
|
236
236
|
export function fallbackLine(o) {
|
|
237
|
+
if (!discloseModel()) {
|
|
238
|
+
const why = o.silent ? `the primary model sent ${o.silent} empty replies` : `the primary model's server is failing (${shownCauses((o.cause ?? "").split("; "))})`;
|
|
239
|
+
return `${sentence(why)} — a backup model answered this turn`;
|
|
240
|
+
}
|
|
237
241
|
const what = o.silent ? `${o.from} sent ${o.silent} empty replies` : `${o.from}'s server is failing (${o.cause})`;
|
|
238
242
|
return `${what} — ${o.to} answered this turn`;
|
|
239
243
|
}
|
|
@@ -241,6 +245,10 @@ export function fallbackLine(o) {
|
|
|
241
245
|
* answer never reads as a broken model. */
|
|
242
246
|
export function recoveryLine(s) {
|
|
243
247
|
const n = s.next;
|
|
248
|
+
if (!discloseModel()) {
|
|
249
|
+
const next = n.kind === "leg" ? "reconnecting" : n.kind === "fallback" ? "a backup model takes this turn" : `retrying in ${Math.max(1, Math.round(n.waitMs / 1000))} s`;
|
|
250
|
+
return `${sentence(shownModel(s.failed.model, s.failed.role ?? "primary"))}: ${shownCause(s.failed.cause)} — ${next}`;
|
|
251
|
+
}
|
|
244
252
|
const next = n.kind === "leg" ? `reconnecting via ${n.host}` : n.kind === "fallback" ? `${n.to} takes this turn` : `retrying in ${Math.max(1, Math.round(n.waitMs / 1000))} s`;
|
|
245
253
|
return `${s.failed.model} at ${s.failed.host}: ${s.failed.cause} — ${next}`;
|
|
246
254
|
}
|
|
@@ -251,12 +259,16 @@ export function fallbackNotice(e) {
|
|
|
251
259
|
/** Shown when the primary recovers after the session had been served from a fallback — so a degraded stretch
|
|
252
260
|
* reads as temporary, never a silent permanent downgrade. `primary` is the box that answered (x-0perator-backend). */
|
|
253
261
|
export function primaryRecoveredLine(primary) {
|
|
262
|
+
if (!discloseModel())
|
|
263
|
+
return "✓ The primary model is back — answers are served from it again";
|
|
254
264
|
return `✓ ${primary} is back — answers are served from it again`;
|
|
255
265
|
}
|
|
256
266
|
/** A turn nothing answered — every leg of the owner's model and of its fallback failed, or finished with nothing in the
|
|
257
267
|
* reply: each leg's cause in the order tried, and what the next turn does. `note` stays in history (the next turn's model
|
|
258
|
-
* reads it
|
|
268
|
+
* reads it; the result's stopKind is "unanswered"); `display` is what the owner reads. Never "want me to try again?". */
|
|
259
269
|
export function noAnswer(o) {
|
|
270
|
+
if (!discloseModel())
|
|
271
|
+
return neutralNoAnswer(o);
|
|
260
272
|
const legs = o.tried.map((l) => {
|
|
261
273
|
const more = [l.detail, l.tries > 1 ? `${l.tries} tries` : undefined].filter(Boolean);
|
|
262
274
|
return `- ${l.model} at ${l.host}: ${l.cause}${more.length ? ` (${more.join(", ")})` : ""}`;
|
|
@@ -268,11 +280,33 @@ export function noAnswer(o) {
|
|
|
268
280
|
display: `Nothing answered this turn. I tried, in order:\n${legs}\n${next}${tasks}`,
|
|
269
281
|
};
|
|
270
282
|
}
|
|
271
|
-
/**
|
|
272
|
-
*
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
const
|
|
283
|
+
/** noAnswer with the serving model confidential: each role's causes, without hosts, upstream ids or a server's words.
|
|
284
|
+
* The note stays neutral too: the next turn's model reads it. */
|
|
285
|
+
function neutralNoAnswer(o) {
|
|
286
|
+
const byLine = new Map();
|
|
287
|
+
for (const l of o.tried) {
|
|
288
|
+
const line = `- ${shownModel(l.model, l.role ?? "primary")}: ${shownCause(l.cause)}`;
|
|
289
|
+
byLine.set(line, (byLine.get(line) ?? 0) + l.tries);
|
|
290
|
+
}
|
|
291
|
+
const legs = [...byLine].map(([line, tries]) => (tries > 1 ? `${line} (${tries} tries)` : line)).join("\n");
|
|
292
|
+
const next = `Next: the next turn tries the primary model first again${o.fallback ? ", then a backup model" : ""}.`;
|
|
293
|
+
const tasks = tasksBlock(o.tasks);
|
|
294
|
+
return {
|
|
295
|
+
note: `[no answer — nothing answered this turn. Tried, in order:\n${legs}\n${next}]${tasks}`,
|
|
296
|
+
display: `Nothing answered this turn. I tried, in order:\n${legs}\n${next}${tasks}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** The TUI's line when a gateway answered from another box (AgentOpts.onServed, x-0perator-fallback): the selected
|
|
300
|
+
* model is down and another is replying under its name. */
|
|
301
|
+
export function gatewayFallbackLine(o) {
|
|
302
|
+
if (!discloseModel())
|
|
303
|
+
return "⚠ The selected model is unavailable — this answer came from a backup model (gateway fallback)";
|
|
304
|
+
return `⚠ ${o.from} is unavailable — this answer came from ${o.backend ?? "another backend"} (gateway fallback)`;
|
|
305
|
+
}
|
|
306
|
+
/** Append the active task list and a steer to an engine stop note. A yield (sub-agents will resume the turn) gets its
|
|
307
|
+
* own steer: the owner can always take the delegated work back. */
|
|
308
|
+
export function closeStopNote(note, activeTasks, kind) {
|
|
309
|
+
const steer = kind === "yield"
|
|
276
310
|
? `\n\nTo steer: say "take over" and I'll do the delegated steps myself, name an agent to change its brief, or say "wait".`
|
|
277
311
|
: `\n\nTo steer: tell me which step to take next, or say "continue" to resume from here.`;
|
|
278
312
|
return note + tasksBlock(activeTasks) + steer;
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
// owner turn, the FIRST mutating call before any ask_user is held back once and the model is told to offer a
|
|
6
6
|
// plan + options first — or, in Autonomous mode, to put the plan up for review. Pure and dependency-free so the
|
|
7
7
|
// gate's trigger logic is unit-testable.
|
|
8
|
-
import { isMutatingTool } from "../tools/
|
|
9
|
-
const SHELL_TOOLS = new Set(["bash", "shell_exec", "shell_background", "shell_task_start"]);
|
|
8
|
+
import { SHELL_ANY, isMutatingTool } from "../tools/classes.js";
|
|
10
9
|
// Shell commands that change the workspace or the machine. Read-only probes (ls, cat, grep, git status, a test
|
|
11
10
|
// run) are NOT here — the gate must never hold back investigation, only the first change.
|
|
12
11
|
const MUTATING_SHELL_RE = new RegExp([
|
|
@@ -44,7 +43,7 @@ export function isMutatingCall(name, rawArgs) {
|
|
|
44
43
|
const cmd = String(args.command ?? args.args ?? rawArgs ?? "");
|
|
45
44
|
return !/^\s*(?:git\s+)?(?:status|log|diff|show|branch|remote|rev-parse|blame|ls-files)\b/.test(cmd);
|
|
46
45
|
}
|
|
47
|
-
if (!
|
|
46
|
+
if (!SHELL_ANY.has(name ?? ""))
|
|
48
47
|
return false;
|
|
49
48
|
const cmd = String(args.command ?? args.cmd ?? rawArgs ?? "");
|
|
50
49
|
return MUTATING_SHELL_RE.test(cmd);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Planner fan-out (owner, 11/27: "tune the planner to fan out more"): which steps of a plan go to parallel sub-agents
|
|
2
|
+
// and which stay with the planner. Independent read-shaped steps fan out, sized to the delegate route's free lanes;
|
|
3
|
+
// decisions, edits, chains and quick steps stay inline, where a spawn would cost more than it saves. Pure.
|
|
4
|
+
/** Under this a step is quicker inline than a sub-agent's start, brief and report. */
|
|
5
|
+
export const MIN_FANOUT_SECONDS = 20;
|
|
6
|
+
const FANS_OUT = new Set(["read", "search", "summarize", "verify"]);
|
|
7
|
+
/** A step fans out when it is read-shaped, needs no other step, feeds no other read-shaped step (a chain), and is not
|
|
8
|
+
* trivial. Two or more such steps are spawned, up to `free` lanes, in plan order; everything else (the decisions, edits
|
|
9
|
+
* and synthesis that use their results, and the overflow) stays inline. */
|
|
10
|
+
export function planFanOut(steps, free) {
|
|
11
|
+
const needed = new Set(steps.flatMap((s) => (FANS_OUT.has(s.kind) ? s.after ?? [] : [])));
|
|
12
|
+
const open = steps.flatMap((s, i) => FANS_OUT.has(s.kind) && !s.after?.length && !needed.has(i) && (s.estSeconds ?? Infinity) >= MIN_FANOUT_SECONDS ? [i] : []);
|
|
13
|
+
const spawn = open.length >= 2 ? open.slice(0, Math.max(0, Math.floor(free))) : [];
|
|
14
|
+
const taken = new Set(spawn);
|
|
15
|
+
return { spawn, inline: steps.map((_, i) => i).filter((i) => !taken.has(i)) };
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// How model, leg and host identity reads in text a user sees (2026-11-30-neutral-harness-names). The serving model is
|
|
2
|
+
// confidential unless the owner opted in (settings.identity.discloseModel → KODE_DISCLOSE_MODEL=1): then every formatter
|
|
3
|
+
// here returns its input unchanged. Otherwise a model reads as a role, a host or a box is left out, and a server's own
|
|
4
|
+
// words become a short cause. Telemetry, events.jsonl and the audit keep the real names; only user-facing text comes
|
|
5
|
+
// through here. Dependency-free leaf (agent.ts is also bundled for the browser).
|
|
6
|
+
export const BRAND = "Operator";
|
|
7
|
+
export function discloseModel() {
|
|
8
|
+
return globalThis.process?.env?.KODE_DISCLOSE_MODEL === "1";
|
|
9
|
+
}
|
|
10
|
+
const ROLE = { primary: "the primary model", backup: "a backup model", selected: "the selected model" };
|
|
11
|
+
/** A model named in a sentence: its name when disclosed, else its role ("the primary model"). */
|
|
12
|
+
export function shownModel(name, role) {
|
|
13
|
+
return discloseModel() ? name : ROLE[role];
|
|
14
|
+
}
|
|
15
|
+
/** The model on the status line, the phase line and receipts: its label when disclosed, else the brand. */
|
|
16
|
+
export function shownModelLabel(label) {
|
|
17
|
+
return discloseModel() ? label : BRAND;
|
|
18
|
+
}
|
|
19
|
+
/** A failure's cause as a user reads it: the full cause when disclosed (it may carry a box, an upstream id or a
|
|
20
|
+
* router's error body), else one of busy, timed out, unavailable, empty reply or server error. */
|
|
21
|
+
export function shownCause(cause) {
|
|
22
|
+
return discloseModel() ? cause : neutralCause(cause);
|
|
23
|
+
}
|
|
24
|
+
export function neutralCause(cause) {
|
|
25
|
+
if (/nothing in them|empty repl|no content/i.test(cause))
|
|
26
|
+
return "empty reply";
|
|
27
|
+
if (/busy|maxInflight|\b429\b|rate.?limit|overloaded|capacity|too many/i.test(cause))
|
|
28
|
+
return "busy";
|
|
29
|
+
if (/timed? ?out|timeout|stall|too slow|no response/i.test(cause))
|
|
30
|
+
return "timed out";
|
|
31
|
+
if (/refused|not found|unreachable|DNS|reset|dropped|\b50[234]\b|\b404\b|unavailable|\bdown\b|loading|offline|closed/i.test(cause))
|
|
32
|
+
return "unavailable";
|
|
33
|
+
return "server error";
|
|
34
|
+
}
|
|
35
|
+
/** Several legs' causes as one: each shown, without repeats ("busy; timed out"). */
|
|
36
|
+
export function shownCauses(causes) {
|
|
37
|
+
return [...new Set(causes.filter(Boolean).map(shownCause))].join("; ");
|
|
38
|
+
}
|
|
39
|
+
/** Capitalize the first letter: a role opens a sentence ("The primary model's server…"). */
|
|
40
|
+
export function sentence(s) {
|
|
41
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
42
|
+
}
|
|
@@ -11,6 +11,9 @@
|
|
|
11
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
12
|
// engine offers bounded recovery (LoopRecovery).
|
|
13
13
|
import { unwrapToolCall } from "./decision-points.js";
|
|
14
|
+
import { AUTOPOST_POLLERS, DISPATCH, DISPATCH_BOOKKEEPING, FAILURE_TOLERANT, FILE_WRITE, IDEMPOTENT, PATH_READ, POLLERS, PROGRESS, SHELL_FOREGROUND, SUBAGENT_SPAWN, SUPERVISION, WRITE_PROGRESS, mutationLanded, refusedResult, resultFailed as failedResult, } from "../tools/classes.js";
|
|
15
|
+
// The classes under the names this module's importers know (tools/classes.ts defines them).
|
|
16
|
+
export { IDEMPOTENT as IDEMPOTENT_TOOLS, PROGRESS as PROGRESS_TOOLS, FAILURE_TOLERANT as FAILURE_TOLERANT_TOOLS, POLLERS as POLLER_TOOLS, WRITE_PROGRESS as WRITE_PROGRESS_TOOLS, AUTOPOST_POLLERS, DISPATCH as DISPATCH_TOOLS, DISPATCH_BOOKKEEPING, SUPERVISION as SUPERVISION_TOOLS, refusedResult, } from "../tools/classes.js";
|
|
14
17
|
export const LOOP_GUARD_DEFAULTS = {
|
|
15
18
|
warnIdentical: 3, warnExactFailure: 2, warnSameToolFailure: 3, warnNoProgress: 2, warnInvestigateLoop: 8,
|
|
16
19
|
stopIdentical: 5, stopExactFailure: 5, stopSameToolFailure: 8, stopNoProgress: 5, stopInvestigateLoop: 15,
|
|
@@ -55,76 +58,28 @@ export function resolveLoopGuardConfig(raw, ctx, env = safeEnv()) {
|
|
|
55
58
|
maxLoopCompactions: Math.min(5, intAtLeast(s.maxLoopCompactions, 2, 0)),
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
|
-
/** Read-only tools: the same call returning the same result again is no new information. */
|
|
59
|
-
export const IDEMPOTENT_TOOLS = new Set([
|
|
60
|
-
"file_read", "read_files", "search", "grep_search", "list_directory", "find_files", "locate", "web_search",
|
|
61
|
-
"web_fetch", "git_status", "memory_search", "session_search", "session_read", "skill_catalog", "skill_fetch",
|
|
62
|
-
"skill_list",
|
|
63
|
-
]);
|
|
64
|
-
/** A successful call to one of these is progress: every failing call still counted this turn is retried as a
|
|
65
|
-
* new experiment (edit -> re-run), not a replay. */
|
|
66
|
-
export const PROGRESS_TOOLS = new Set([
|
|
67
|
-
"file_write", "file_edit", "bash", "shell_exec", "shell_background", "git_command", "delegate_task",
|
|
68
|
-
"spawn_agent", "email_send", "cronjob", "task_add", "task_update", "task_clear", "memory_store", "checkpoint",
|
|
69
|
-
"http_request", "browser", "chauffeur",
|
|
70
|
-
]);
|
|
71
|
-
/** Tools whose "failure" is normal work output (a red test run, an empty page): a run of DIFFERENT failing
|
|
72
|
-
* calls is diagnosis, so the same-tool failure run only warns for them and never stops the turn. */
|
|
73
|
-
export const FAILURE_TOLERANT_TOOLS = new Set([
|
|
74
|
-
"bash", "shell_exec", "shell_background", "bash_output", "browser", "web_fetch", "http_request", "chauffeur",
|
|
75
|
-
]);
|
|
76
|
-
/** Pollers: re-invoked with identical args while waiting on async work. Never flagged as a loop. */
|
|
77
|
-
export const POLLER_TOOLS = new Set(["agent_status", "bash_output"]);
|
|
78
61
|
// A shell command that waits on or inspects a running job: sleeps/waits, process checks, following or tailing a
|
|
79
62
|
// log, reading a job's log/pid/status file. An unchanged answer there means "not done yet", which is progress.
|
|
80
63
|
const POLL_COMMAND_RE = /(?:^|[;&|(]\s*)(?:sleep|wait|until|watch|pgrep|pidof|jobs|tail)\b|\bkill\s+-0\b|\bps\s+(?:-|aux)|\.(?:log|out|pid|status)\b/i;
|
|
81
|
-
const SHELL_TOOLS = new Set(["bash", "shell_exec"]);
|
|
82
|
-
const SPAWN_TOOLS = new Set(["delegate_task", "spawn_agent"]);
|
|
83
64
|
const MAX_CYCLE_PERIOD = 4;
|
|
84
65
|
const CYCLE_HISTORY = 64;
|
|
85
66
|
/** From the 2nd byte-identical repeat a duplicate result of at least this size becomes a reference stub. */
|
|
86
67
|
export const STUB_MIN_CHARS = 512;
|
|
87
68
|
const STUB_ARGS_PREVIEW = 120;
|
|
88
|
-
const FAILURE_PREFIX_RE = /^(?:error|permission denied|cancelled)\b/i;
|
|
89
69
|
const EXIT_TRAILER_RE = /(?:\[exit (\d+)\]|^\(no output; exit (\d+|\?)\))\s*$/;
|
|
90
70
|
/** True when a poll-style call is legitimately repeated while waiting (never a loop). */
|
|
91
71
|
export function isRepeatable(name, args) {
|
|
92
72
|
({ name, args } = unwrapToolCall(name, args));
|
|
93
|
-
if (
|
|
73
|
+
if (POLLERS.has(name))
|
|
94
74
|
return true;
|
|
95
75
|
// A known allowance: generated/MCP poller naming conventions are legitimately re-invoked with identical args.
|
|
96
76
|
if (name.endsWith("_poll") || name.endsWith("_get_result"))
|
|
97
77
|
return true;
|
|
98
|
-
return
|
|
78
|
+
return SHELL_FOREGROUND.has(name) && POLL_COMMAND_RE.test(String(args.command ?? ""));
|
|
99
79
|
}
|
|
100
|
-
/** Whether a tool result reports failure. A refusal by the engine's own guards is not
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (/^(?:loop guard|repeated action)/i.test(t))
|
|
104
|
-
return false;
|
|
105
|
-
if (FAILURE_PREFIX_RE.test(t))
|
|
106
|
-
return true;
|
|
107
|
-
if (SHELL_TOOLS.has(name) || name === "shell_background") {
|
|
108
|
-
const m = EXIT_TRAILER_RE.exec(result);
|
|
109
|
-
if (m)
|
|
110
|
-
return (m[1] ?? m[2]) !== "0";
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
/** A landed workspace edit: file_write / file_edit that did not come back as an error. */
|
|
115
|
-
function mutationOk(name, result) {
|
|
116
|
-
return (name === "file_write" || name === "file_edit") && !FAILURE_PREFIX_RE.test(result.trimStart()) && !/^(?:loop guard|repeated action)/i.test(result.trimStart());
|
|
117
|
-
}
|
|
118
|
-
/** Tools that constitute genuine write-progress for the investigate-loop detector.
|
|
119
|
-
* Deliberately narrower than PROGRESS_TOOLS: bash/git_command are excluded because
|
|
120
|
-
* grep/search/ls inside bash are the exact pattern that motivated this detector.
|
|
121
|
-
* Trade: one cheap nudge vs a 3-hour marathon of bash-based investigation. */
|
|
122
|
-
export const WRITE_PROGRESS_TOOLS = new Set([
|
|
123
|
-
"file_write", "file_edit", "file_create", "checkpoint",
|
|
124
|
-
"task_add", "task_update", "task_clear", "memory_store",
|
|
125
|
-
"delegate_task", "delegate_to_agent", "spawn_agent",
|
|
126
|
-
"cronjob",
|
|
127
|
-
]);
|
|
80
|
+
/** Whether a tool result reports failure (tools/classes.ts toolOutcome). A refusal by the engine's own guards is not
|
|
81
|
+
* the tool failing. `name` is kept for callers; the reading does not depend on the tool. */
|
|
82
|
+
export const resultFailed = (_name, result) => failedResult(result);
|
|
128
83
|
function canonical(v) {
|
|
129
84
|
if (Array.isArray(v))
|
|
130
85
|
return "[" + v.map(canonical).join(",") + "]";
|
|
@@ -205,7 +160,7 @@ export class LoopGuard {
|
|
|
205
160
|
}
|
|
206
161
|
this.webSearches++;
|
|
207
162
|
}
|
|
208
|
-
if (
|
|
163
|
+
if (SUBAGENT_SPAWN.has(name) && c.maxSubagents > 0) {
|
|
209
164
|
if (this.spawns >= c.maxSubagents) {
|
|
210
165
|
return this.stop("subagent_cap", name, this.spawns, `this turn already started ${this.spawns} sub-agents (limit ${c.maxSubagents}) — that looks like a runaway delegation loop`);
|
|
211
166
|
}
|
|
@@ -215,7 +170,7 @@ export class LoopGuard {
|
|
|
215
170
|
// Read-only no-progress: the SAME idempotent read returning the SAME result. hardStop on → stop at the low
|
|
216
171
|
// count; hardStop off → at the high terminal (so an attended read-only loop still halts). Varied reads never
|
|
217
172
|
// reach this (different sig each time), so legitimate research is untouched.
|
|
218
|
-
const rec =
|
|
173
|
+
const rec = IDEMPOTENT.has(name) ? this.noProgress.get(sig) : undefined;
|
|
219
174
|
const noProgStop = this.noProgressStopAt(c.stopNoProgress);
|
|
220
175
|
if (rec && noProgStop > 0 && rec.count >= noProgStop) {
|
|
221
176
|
return this.stop("no_progress", name, rec.count, `${name} returned the same result ${rec.count} times`);
|
|
@@ -260,7 +215,7 @@ export class LoopGuard {
|
|
|
260
215
|
const same = (this.sameToolFailures.get(name) ?? 0) + 1;
|
|
261
216
|
this.sameToolFailures.set(name, same);
|
|
262
217
|
this.noProgress.delete(sig);
|
|
263
|
-
if (c.hardStop && !
|
|
218
|
+
if (c.hardStop && !FAILURE_TOLERANT.has(name) && same >= c.stopSameToolFailure) {
|
|
264
219
|
decision = this.stop("same_tool_failure", name, same, `${name} failed ${same} times this turn`);
|
|
265
220
|
}
|
|
266
221
|
else if (exact >= c.warnExactFailure) {
|
|
@@ -273,7 +228,7 @@ export class LoopGuard {
|
|
|
273
228
|
else {
|
|
274
229
|
this.exactFailures.delete(sig);
|
|
275
230
|
this.sameToolFailures.delete(name);
|
|
276
|
-
const landed =
|
|
231
|
+
const landed = mutationLanded(name, result);
|
|
277
232
|
if (landed) {
|
|
278
233
|
// The workspace changed: every earlier observation is stale, so a re-run is a new experiment.
|
|
279
234
|
for (const k of this.exactFailures.keys())
|
|
@@ -283,12 +238,12 @@ export class LoopGuard {
|
|
|
283
238
|
this.history = [];
|
|
284
239
|
this.streak = { sig: "", hash: "", count: 0, firstId: "" };
|
|
285
240
|
}
|
|
286
|
-
else if (
|
|
241
|
+
else if (PROGRESS.has(name)) {
|
|
287
242
|
for (const k of this.exactFailures.keys())
|
|
288
243
|
this.progressSinceFailure.add(k);
|
|
289
244
|
this.sameToolFailures.clear();
|
|
290
245
|
}
|
|
291
|
-
if (
|
|
246
|
+
if (IDEMPOTENT.has(name)) {
|
|
292
247
|
const h = hash(result);
|
|
293
248
|
const prev = this.noProgress.get(sig);
|
|
294
249
|
const count = prev && prev.hash === h ? prev.count + 1 : 1;
|
|
@@ -396,7 +351,6 @@ export class LoopGuard {
|
|
|
396
351
|
// legitimate (an unchanged result there means "not done yet"), and a round containing any non-poller tool
|
|
397
352
|
// resets the streak. The distinction is intrinsic: auto-posting pollers never need a wait loop; everything
|
|
398
353
|
// else might.
|
|
399
|
-
export const AUTOPOST_POLLERS = new Set(["agent_status"]);
|
|
400
354
|
export const POLL_SPIN_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
|
|
401
355
|
export const POLL_SPIN_NUDGE = "agent_status will not change faster by asking again — each report, and a STUCK notice if one stalls, arrives " +
|
|
402
356
|
"as a message on its own. Act on what it shows: steer an agent that is stuck or off its brief (message_agent), " +
|
|
@@ -458,10 +412,6 @@ export class PollSpinGuard {
|
|
|
458
412
|
// not progress: nudge at `nudgeAfter`, end the turn at `stopAfter` so the auto-posted reports resume it and the
|
|
459
413
|
// sub-agents get the slot. Only spawn_agent counts as a dispatch — delegate_task / delegate_to_agent block until
|
|
460
414
|
// the child is done, so nothing is running after they return.
|
|
461
|
-
export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
|
|
462
|
-
/** Calls that only book-keep around a dispatch (the plan pane, the agent panel): a dispatch round made of these
|
|
463
|
-
* alone has no independent work in it. */
|
|
464
|
-
export const DISPATCH_BOOKKEEPING = new Set(["task_add", "task_update", "task_list", "task_clear", "agent_status", "message_agent"]);
|
|
465
415
|
export const YIELD_DEFAULTS = { nudgeAfter: 1, stopAfter: 2 };
|
|
466
416
|
export const YIELD_NUDGE = "Your sub-agents are working their steps and this round changed nothing. Do not redo their work: finish what does " +
|
|
467
417
|
"not depend on them, or close the turn — one status line per agent and 2-3 options for the owner.";
|
|
@@ -469,8 +419,6 @@ export const YIELD_STOP = "[turn ended — sub-agents are running on this model'
|
|
|
469
419
|
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
470
420
|
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 " +
|
|
471
421
|
"arrives as a new message and resumes this conversation. Nothing was lost.]";
|
|
472
|
-
/** Supervising IS progress: stopping a sub-agent (to take its step over) or asking the owner never counts as idling. */
|
|
473
|
-
export const SUPERVISION_TOOLS = new Set(["stop_agent", "ask_user"]);
|
|
474
422
|
/** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); a MUTATING
|
|
475
423
|
* round resets the streak. The endpoint's slot count sets the policy: on ONE slot (the fleet default) the parent
|
|
476
424
|
* working beside its sub-agents is pure contention — every parent round waits behind a sub-agent round and then
|
|
@@ -497,15 +445,15 @@ export class YieldAfterDispatchGuard {
|
|
|
497
445
|
* supervising, with one nudge against redoing their work. */
|
|
498
446
|
observe(names, mutating, slots = 1, shared = true) {
|
|
499
447
|
const single = slots <= 1;
|
|
500
|
-
if (names.some((n) =>
|
|
448
|
+
if (names.some((n) => DISPATCH.has(n))) {
|
|
501
449
|
this.dispatched = true;
|
|
502
450
|
this.streak = 0;
|
|
503
|
-
const pure = names.every((n) =>
|
|
451
|
+
const pure = names.every((n) => DISPATCH.has(n) || DISPATCH_BOOKKEEPING.has(n));
|
|
504
452
|
return shared && single && pure ? { action: "halt", streak: 0, message: YIELD_DISPATCHED } : { action: "allow", streak: 0 };
|
|
505
453
|
}
|
|
506
454
|
if (!this.dispatched)
|
|
507
455
|
return { action: "allow", streak: 0 };
|
|
508
|
-
if (mutating || names.some((n) =>
|
|
456
|
+
if (mutating || names.some((n) => SUPERVISION.has(n))) {
|
|
509
457
|
this.streak = 0;
|
|
510
458
|
return { action: "allow", streak: 0 };
|
|
511
459
|
}
|
|
@@ -550,7 +498,7 @@ export class NoWriteProgressGuard {
|
|
|
550
498
|
/** One settled round: the tools it ran (names) and their results, index-aligned. */
|
|
551
499
|
observe(names, results) {
|
|
552
500
|
// Any write-progress call ⇒ progress, reset.
|
|
553
|
-
if (names.some((n, i) =>
|
|
501
|
+
if (names.some((n, i) => WRITE_PROGRESS.has(n) && (!results || (results[i] !== undefined && !resultFailed(n, results[i]) && !refusedResult(results[i]))))) {
|
|
554
502
|
this.reset();
|
|
555
503
|
return { action: "allow", streak: 0 };
|
|
556
504
|
}
|
|
@@ -859,25 +807,23 @@ function shellReads(command, cwd) {
|
|
|
859
807
|
const display = command.replace(/^\s*cd\s+\S+\s*&&\s*/, "").replace(/\s+/g, " ").trim();
|
|
860
808
|
return { files, display: display.length > 100 ? display.slice(0, 100) + "…" : display, mutates };
|
|
861
809
|
}
|
|
862
|
-
const FILE_READ_TOOLS = new Set(["file_read", "read_file", "image_inspect"]);
|
|
863
|
-
const WRITE_TOOLS = new Set(["file_write", "file_edit", "file_create", "file_delete"]);
|
|
864
810
|
/** What one tool call READ: files, or — for a read-only call with no file in it — the call itself; `mutates` when a shell
|
|
865
811
|
* command changes the tree. Pollers, writes and everything that is not a read return nothing. Pure and node-free;
|
|
866
812
|
* shared by the engine and the backfill. */
|
|
867
813
|
export function readTargets(name, args, cwd) {
|
|
868
|
-
if (
|
|
814
|
+
if (PATH_READ.has(name) && typeof args.path === "string")
|
|
869
815
|
return { files: [joinPath(cwd, args.path)] };
|
|
870
816
|
if (name === "read_files" && Array.isArray(args.paths)) { // paths, or {path, offset, limit} objects
|
|
871
817
|
const paths = args.paths.map((p) => (typeof p === "string" ? p : p?.path)).filter((p) => typeof p === "string");
|
|
872
818
|
return { files: paths.map((p) => joinPath(cwd, p)) };
|
|
873
819
|
}
|
|
874
|
-
if (
|
|
820
|
+
if (SHELL_FOREGROUND.has(name) && typeof args.command === "string") {
|
|
875
821
|
const r = shellReads(args.command, typeof args.cwd === "string" ? args.cwd : cwd);
|
|
876
822
|
if (r.files.length)
|
|
877
823
|
return { files: r.files, mutates: r.mutates };
|
|
878
824
|
return r.mutates || isRepeatable(name, args) || !r.display ? { files: [], mutates: r.mutates } : { files: [], call: `$ ${r.display}` };
|
|
879
825
|
}
|
|
880
|
-
if (
|
|
826
|
+
if (IDEMPOTENT.has(name)) {
|
|
881
827
|
const c = canonical(args);
|
|
882
828
|
return { files: [], call: `${name} ${c.length > 100 ? c.slice(0, 100) + "…" : c}` };
|
|
883
829
|
}
|
|
@@ -905,16 +851,13 @@ export function isLooped(e) {
|
|
|
905
851
|
// are also the engine's reaction to a reply it just received (agent.ts), so one of them means the model has answered.
|
|
906
852
|
const REPETITION_KINDS = new Set(["reasoning_loop", "repeated_step", "self_loop"]);
|
|
907
853
|
// A call the engine or the executor refused without running it (a guard, a re-worded repeat, a cap, a denial): no read.
|
|
908
|
-
const REFUSED_RE = /^(?:loop guard|repeated action|blocked |permission denied|cancelled|\[interrupted)/i;
|
|
909
|
-
/** A result that says the call never ran (REFUSED_RE). */
|
|
910
|
-
export const refusedResult = (result) => REFUSED_RE.test(result.trimStart());
|
|
911
854
|
// The result guard's own marks (LoopGuard.afterCall): a byte-identical duplicate swapped for a stub, short notes appended.
|
|
912
855
|
const STUB_RE = /^\[note: this result is byte-identical to the /;
|
|
913
856
|
const GUARD_NOTES_RE = /\n\n\[note: [^\n]*\](?:\n\[note: [^\n]*\])*\s*$/;
|
|
914
857
|
/** How a call is named in the loop reset's digest and the dead-round note: `$ sed -n '1,80p' src/a.ts`,
|
|
915
858
|
* `file_read {"path":"src/a.ts"}`. */
|
|
916
859
|
export function callLabel(name, args) {
|
|
917
|
-
if (
|
|
860
|
+
if (SHELL_FOREGROUND.has(name) && typeof args.command === "string")
|
|
918
861
|
return `$ ${shellReads(args.command).display}`;
|
|
919
862
|
const c = canonical(args);
|
|
920
863
|
return `${name} ${c.length > 100 ? c.slice(0, 100) + "…" : c}`;
|
|
@@ -949,7 +892,7 @@ export function toolSkeleton(name, args) {
|
|
|
949
892
|
return callSkeleton(name, args).skeleton;
|
|
950
893
|
}
|
|
951
894
|
function callSkeleton(name, args) {
|
|
952
|
-
if (
|
|
895
|
+
if (SHELL_FOREGROUND.has(name) && typeof args.command === "string") {
|
|
953
896
|
const literals = [];
|
|
954
897
|
const segs = segments(shellWords(args.command)).map((seg) => seg.map((w, i, arr) => {
|
|
955
898
|
const afterFlag = i > 0 && typeof arr[i - 1] === "string" && arr[i - 1].startsWith("-") && arr[i - 1].length > 1;
|
|
@@ -1122,10 +1065,10 @@ export class LoopEvidenceTracker {
|
|
|
1122
1065
|
observe(name, args, result = "") {
|
|
1123
1066
|
this.struggle.observe(name, args, result); // advisory: populates evidence().struggles, changes nothing this phase
|
|
1124
1067
|
const head = result.trimStart();
|
|
1125
|
-
if (
|
|
1068
|
+
if (refusedResult(head))
|
|
1126
1069
|
return; // the call never ran
|
|
1127
|
-
if (
|
|
1128
|
-
if (
|
|
1070
|
+
if (FILE_WRITE.has(name)) {
|
|
1071
|
+
if (!mutationLanded(name, result))
|
|
1129
1072
|
return;
|
|
1130
1073
|
this.unheeded = 0;
|
|
1131
1074
|
this.staleSinceWrite = 0;
|
package/dist/engine/messages.js
CHANGED
|
@@ -134,8 +134,8 @@ export class Conversation {
|
|
|
134
134
|
get all() {
|
|
135
135
|
return this.messages;
|
|
136
136
|
}
|
|
137
|
-
user(content) {
|
|
138
|
-
this.messages.push({ role: "user", content });
|
|
137
|
+
user(content, images) {
|
|
138
|
+
this.messages.push({ role: "user", content, ...(images?.length ? { images } : {}) });
|
|
139
139
|
}
|
|
140
140
|
assistant(content, toolCalls) {
|
|
141
141
|
// Neutralize unparseable arguments at the point they enter history, so the SAVED session file never carries
|
package/dist/engine/moa.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { codeActEnabled } from "../moa/codeact.js";
|
|
1
2
|
/** The team from settings.moa, new shape or the pre-10/31 one (aggregator → planner, first other proposer →
|
|
2
3
|
* specialist). Undefined when no planner is configured. A missing specialist falls back to the planner itself. */
|
|
3
4
|
export function moaTeam(cfg) {
|
|
@@ -8,8 +9,22 @@ export function moaTeam(cfg) {
|
|
|
8
9
|
const specialist = cfg?.specialist?.id?.trim()
|
|
9
10
|
|| cfg?.proposers?.find((p) => p.id !== planner.id)?.id
|
|
10
11
|
|| planner.id;
|
|
11
|
-
return { planner, specialist, prompt: cfg?.planner_prompt };
|
|
12
|
+
return { planner, specialist, prompt: cfg?.planner_prompt, ...(codeActEnabled(cfg?.codeact) ? { codeact: true } : {}) };
|
|
12
13
|
}
|
|
14
|
+
/** The CodeAct lane's lines in the brief, only while moa.codeact.enabled (moa/codeact.ts decides eligibility in code). */
|
|
15
|
+
const CODEACT_LINES = [
|
|
16
|
+
"- A bulk step that only reads and always gives the same answer (scan a repo, count or list matches across many files,",
|
|
17
|
+
" batch-check files, analyse a log): delegate_task it with lane \"codeact\", targets (the paths), items or",
|
|
18
|
+
" est_round_trips, read_only true, deterministic true. The specialist does it in one sandboxed program instead of a",
|
|
19
|
+
" call per item. Never for edits, commits, pushes, network or messages: those stay normal steps. A step the check",
|
|
20
|
+
" refuses runs on tools and the report says why.",
|
|
21
|
+
];
|
|
22
|
+
/** The external lane's lines in the brief (Waterfall teams): steps that need the open web go to a remote agent. */
|
|
23
|
+
const EXTERNAL_LINES = [
|
|
24
|
+
"- A step that needs the live web, a browser, an outside site or long outside research: delegate_task it with model",
|
|
25
|
+
" \"external-executor\" (a remote agent with its own browser and sandbox). It takes minutes and is metered: only when",
|
|
26
|
+
" the open web is required, never for repo, file or fleet work, and give it the full context it needs.",
|
|
27
|
+
];
|
|
13
28
|
/** The planner's standing brief. Identical every turn for a given team, so it stays in the prompt cache. */
|
|
14
29
|
export function plannerBrief(team) {
|
|
15
30
|
if (team.prompt)
|
|
@@ -22,6 +37,13 @@ export function plannerBrief(team) {
|
|
|
22
37
|
`- Hand each self-contained step to the specialist with delegate_task (it runs on ${s} by default). The specialist sees`,
|
|
23
38
|
" only the task you write: include the goal, the inputs (paths, URLs, facts) and what to report back. Independent",
|
|
24
39
|
" steps can be delegated together.",
|
|
40
|
+
"- Two or more independent read, search, summarize or verify steps (none needs another's result): spawn_agent them in",
|
|
41
|
+
" one call, role generic, each with its own small slice (paths and line windows, not a whole digest), a concrete",
|
|
42
|
+
" deliverable and deadline_minutes; list nice-to-have ones in `optional`. They run beside you on the sub-agent route,",
|
|
43
|
+
" as many as it has free lanes; a brief it hands back, do yourself. Keep decisions, edits and the synthesis here.",
|
|
44
|
+
"- No fan-out for one step, a step quicker than ~20 s inline, or a chain where each step needs the last.",
|
|
45
|
+
...(team.codeact ? CODEACT_LINES : []),
|
|
46
|
+
...(team.external ? EXTERNAL_LINES : []),
|
|
25
47
|
"- Do yourself: a single quick tool call, anything that needs reading an image (only you read images), and the final",
|
|
26
48
|
" answer.",
|
|
27
49
|
"- Check every report before marking the step done (task_update); fix or redo a wrong one instead of passing it on.",
|