@0perator/operator 0.1.325 → 0.1.327

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/cli.js CHANGED
@@ -667,7 +667,9 @@ function Root() {
667
667
  return `spawned background sub-agent ${id}. Its result auto-posts to THIS conversation when done — ` +
668
668
  `keep working, do not poll it. Do NOT call bash_output/bash_kill on ${id} (that's for shell_background ` +
669
669
  `jobs only and will just error). Use agent_status to check on it, or message_agent to nudge it. ` +
670
- `Never re-spawn ${id}'s task assuming it was lost — it wasn't.`;
670
+ `Never re-spawn ${id}'s task assuming it was lost — it wasn't. When nothing else is independent of ${id}, ` +
671
+ `give a one-line status and END YOUR TURN — its report resumes this conversation; a turn that keeps ` +
672
+ `polling holds the model slot and starves it.`;
671
673
  },
672
674
  // The reverse channel: message a RUNNING sub-agent mid-flight (steer it / answer its question).
673
675
  messageAgent: (id, text) => {
@@ -402,7 +402,10 @@ export function basePersona(cwd = process.cwd(), opts = {}) {
402
402
  `"let me delegate" without making that call in the same round. For independent, parallelizable subtasks ` +
403
403
  `(research per area, search a large tree, draft a file, a long build) give each a fully self-contained ` +
404
404
  `instruction — it runs on another ` +
405
- `session in parallel and posts its result back here; keep working meanwhile. The user watches each ` +
405
+ `session in parallel and posts its result back here. Do only the work that does NOT depend on it, then give ` +
406
+ `a one-line status and END YOUR TURN — the result resumes the conversation; a turn that keeps polling holds ` +
407
+ `the model slot and starves the sub-agents. Never redo a delegated subtask yourself — reading up on the topic ` +
408
+ `you just handed off is the busywork that starves them. The user watches each ` +
406
409
  `sub-agent's live tokens + time in the background panel. Don't delegate trivial work you can do inline, ` +
407
410
  `and don't spawn many at once — they all share this one model.\n` +
408
411
  `WRITE THE BRIEF LIKE A SPEC, not a run-on paragraph — the child has NO memory of this chat, so a wall ` +
@@ -12,7 +12,7 @@ import { classifyFailure, servedContextLimit, backoffMs, sleep } from "./selfhea
12
12
  import { TaskVerification, VERIFY_REMINDER, NOT_VERIFIED_BANNER } from "./verify-gate.js";
13
13
  import { detectRefusal, buildAffirmativeRetry, UNRESTRICTED_MAX_RETRIES } from "./unrestricted.js";
14
14
  import { ComputerEventStream, ComputerEventTracker } from "./computer-event.js";
15
- import { LoopGuard, PollSpinGuard, NoWriteProgressGuard, loopStopNote, resolveLoopGuardConfig } from "./loop-guard.js";
15
+ import { LoopGuard, PollSpinGuard, NoWriteProgressGuard, YieldAfterDispatchGuard, loopStopNote, resolveLoopGuardConfig } from "./loop-guard.js";
16
16
  import { RunawayStreamWatch, ReasoningBudgetWatch, isDegenerateReply, REPETITION_INTERRUPTED, REASONING_BUDGET_INTERRUPTED } from "./repetition-guard.js";
17
17
  const MAX_SELF_HEAL_PER_TURN = 3;
18
18
  // A "loading" 503 (endpoint restarting/warming) is a KNOWN-recoverable WAIT, not a failure — a model reload
@@ -539,6 +539,7 @@ export async function runTurn(userInput, conversation, opts) {
539
539
  const guardCfg = resolveLoopGuardConfig(opts.loopGuard, { unattended: opts.unattended === true });
540
540
  const guard = guardCfg.enabled ? new LoopGuard(guardCfg) : undefined; // result-aware tool loop guard (engine/loop-guard.ts)
541
541
  const pollSpin = guardCfg.enabled ? new PollSpinGuard() : undefined; // auto-post-poller (agent_status) spin guard — a separate detector, since pollers are EXEMPT from `guard`
542
+ const yieldGuard = guardCfg.enabled ? new YieldAfterDispatchGuard() : undefined; // after spawn_agent: non-mutating rounds are waiting-with-busywork — yield so the reports resume the turn
542
543
  const noWriteProgress = guardCfg.enabled ? new NoWriteProgressGuard(guardCfg.warnInvestigateLoop, guardCfg.stopInvestigateLoop, guardCfg.hardStop) : undefined; // investigate-loop detector — catches rounds with zero mutating calls
543
544
  const rca = { succeeded: new Map(), refused: new Map() }; // normalized-fingerprint → completed exact spellings; + refusal tally (see RCA_STOP)
544
545
  const contentSigs = new Map(); // per-round prose fingerprints → the narration loop guard
@@ -1160,7 +1161,7 @@ export async function runTurn(userInput, conversation, opts) {
1160
1161
  // turn — pollers are exempt from the loop guard above, so this catches them. Nudge once, then end the
1161
1162
  // turn so the auto-posted sub-agent results resume it (rather than burning the budget re-checking).
1162
1163
  if (pollSpin) {
1163
- const ps = pollSpin.observe(response.toolCalls.map((c) => c.function.name), toolMsgs.map((m) => m.content ?? ""));
1164
+ const ps = pollSpin.observe(response.toolCalls.map((c) => c.function.name), toolMsgs.map((m) => m.content ?? ""), response.toolCalls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
1164
1165
  if (ps.action === "halt")
1165
1166
  return stopTurn(ps.message, rounds + 1);
1166
1167
  if (ps.action === "nudge") {
@@ -1168,6 +1169,15 @@ export async function runTurn(userInput, conversation, opts) {
1168
1169
  continue;
1169
1170
  }
1170
1171
  }
1172
+ if (yieldGuard) {
1173
+ const yg = yieldGuard.observe(response.toolCalls.map((c) => c.function.name), response.toolCalls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
1174
+ if (yg.action === "halt")
1175
+ return stopTurn(yg.message, rounds + 1);
1176
+ if (yg.action === "nudge") {
1177
+ conversation.user(yg.message);
1178
+ continue;
1179
+ }
1180
+ }
1171
1181
  if (noWriteProgress) {
1172
1182
  const nwp = noWriteProgress.observe(response.toolCalls.map((c) => c.function.name));
1173
1183
  if (nwp.action === "halt")
@@ -1208,7 +1218,7 @@ export async function runTurn(userInput, conversation, opts) {
1208
1218
  noEditStreak = recovered.calls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")) ? 0 : noEditStreak + 1;
1209
1219
  trackTouchedFiles(recovered.calls, touchedFiles);
1210
1220
  if (pollSpin) {
1211
- const ps = pollSpin.observe(recovered.calls.map((c) => c.function.name), toolMsgs.map((m) => m.content ?? ""));
1221
+ const ps = pollSpin.observe(recovered.calls.map((c) => c.function.name), toolMsgs.map((m) => m.content ?? ""), recovered.calls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
1212
1222
  if (ps.action === "halt")
1213
1223
  return stopTurn(ps.message, rounds + 1);
1214
1224
  if (ps.action === "nudge") {
@@ -1216,6 +1226,15 @@ export async function runTurn(userInput, conversation, opts) {
1216
1226
  continue;
1217
1227
  }
1218
1228
  }
1229
+ if (yieldGuard) {
1230
+ const yg = yieldGuard.observe(recovered.calls.map((c) => c.function.name), recovered.calls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
1231
+ if (yg.action === "halt")
1232
+ return stopTurn(yg.message, rounds + 1);
1233
+ if (yg.action === "nudge") {
1234
+ conversation.user(yg.message);
1235
+ continue;
1236
+ }
1237
+ }
1219
1238
  if (noWriteProgress) {
1220
1239
  const nwp = noWriteProgress.observe(recovered.calls.map((c) => c.function.name));
1221
1240
  if (nwp.action === "halt")
@@ -351,9 +351,10 @@ export class LoopGuard {
351
351
  export const AUTOPOST_POLLERS = new Set(["agent_status"]);
352
352
  export const POLL_SPIN_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
353
353
  export const POLL_SPIN_NUDGE = "Sub-agent results auto-post to this conversation the moment they finish — you do not need to poll " +
354
- "agent_status to learn that. Stop checking status: either do independent work now, or end your turn and the " +
355
- "auto-posted results will resume it when they land. Do NOT call agent_status again without doing real work first.";
356
- export const POLL_SPIN_STOP = "[stopped — agent_status was polled repeatedly with no other work and no change in status. Sub-agent results " +
354
+ "agent_status to learn that. Reads and status checks while they run are not progress: finish only what does " +
355
+ "NOT depend on them, give a one-line status, and END YOUR TURN — the results resume this conversation on their " +
356
+ "own, and a turn that keeps polling holds the model slot and starves the sub-agents.";
357
+ export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no mutating work and no change in status. Sub-agent results " +
357
358
  "auto-post when they finish and will resume this turn, so polling only burns time and tokens. Nothing was " +
358
359
  "lost — the results arrive on their own.]";
359
360
  /** Watches settled tool rounds for an auto-post-poller spin. Fed one round at a time via observe(); a
@@ -370,18 +371,22 @@ export class PollSpinGuard {
370
371
  this.stopAfter = stopAfter;
371
372
  }
372
373
  reset() { this.streak = 0; this.nudged = false; this.lastHash = ""; }
373
- /** One settled round: the tools it ran (names) and their results, index-aligned. */
374
- observe(names, results) {
374
+ /** One settled round: the tools it ran (names), their results (index-aligned), and whether any call in the round
375
+ * CHANGED the workspace. Read-only work beside a poll is not progress — a parent that alternates agent_status
376
+ * with greps, reads and status bash while its sub-agents run is still waiting on them (the 2026-10-28 32-minute
377
+ * turn), and should end the turn so the auto-posted results resume it and the sub-agents get the model slot. */
378
+ observe(names, results, mutating = false) {
375
379
  const pollers = names.filter((n) => AUTOPOST_POLLERS.has(n));
376
- const hasOther = names.some((n) => !AUTOPOST_POLLERS.has(n));
377
- // No auto-post poller, or any real work alongside it ⇒ progress, never a spin.
378
- if (pollers.length === 0 || hasOther) {
380
+ // No auto-post poller, or a MUTATING call alongside it ⇒ progress, never a spin.
381
+ if (pollers.length === 0 || mutating) {
379
382
  this.reset();
380
383
  return { action: "allow", streak: 0 };
381
384
  }
382
385
  // A pure poll round. A changed poll result means a sub-agent's state moved (one finished / was added) —
383
386
  // that IS new information, so the streak resets.
384
- const h = hash(names.filter((n) => AUTOPOST_POLLERS.has(n)).join("\0") + "\u0001" + results.join("\0"));
387
+ // Only the POLLERS' results count as "the status": a read-only tool's output changes every round (a
388
+ // different grep, a longer log) and must not look like a sub-agent moving.
389
+ const h = hash(pollers.join("\0") + "\u0001" + results.filter((_, i) => AUTOPOST_POLLERS.has(names[i])).join("\0"));
385
390
  if (this.streak > 0 && h !== this.lastHash) {
386
391
  this.reset();
387
392
  this.lastHash = h;
@@ -398,6 +403,56 @@ export class PollSpinGuard {
398
403
  return { action: "allow", streak: this.streak };
399
404
  }
400
405
  }
406
+ // ── Yield-after-dispatch guard ───────────────────────────────────────────────
407
+ // The poll-spin guard keys on agent_status. The 2026-10-28 0.1.326 run showed the other shape: after spawning
408
+ // three sub-agents the parent never polled — it re-researched the SAME topics itself for 30 minutes (web_search /
409
+ // web_fetch every round, nothing written), holding the shared model slot while the sub-agents crawled. Once
410
+ // background sub-agents have been dispatched this turn, a round with no MUTATING call is waiting-with-busywork,
411
+ // not progress: nudge at `nudgeAfter`, end the turn at `stopAfter` so the auto-posted reports resume it and the
412
+ // sub-agents get the slot. Only spawn_agent counts as a dispatch — delegate_task / delegate_to_agent block until
413
+ // the child is done, so nothing is running after they return.
414
+ export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
415
+ export const YIELD_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
416
+ export const YIELD_NUDGE = "Your sub-agents are running and this round changed nothing. Do not redo their work: write down anything you " +
417
+ "found (task_update / scratchpad), give a one-line status, and END YOUR TURN — their reports resume this " +
418
+ "conversation on their own; a turn that keeps reading holds the model slot and starves them.";
419
+ export const YIELD_STOP = "[turn ended — sub-agents are running and the last rounds changed nothing. Their reports auto-post and resume " +
420
+ "this conversation; the turn yielded so they get the model slot. Nothing was lost.]";
421
+ /** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); the dispatch
422
+ * round itself and any MUTATING round reset the streak. Side-effect-free, like PollSpinGuard. */
423
+ export class YieldAfterDispatchGuard {
424
+ nudgeAfter;
425
+ stopAfter;
426
+ dispatched = false;
427
+ streak = 0;
428
+ nudged = false;
429
+ constructor(nudgeAfter = YIELD_DEFAULTS.nudgeAfter, stopAfter = YIELD_DEFAULTS.stopAfter) {
430
+ this.nudgeAfter = nudgeAfter;
431
+ this.stopAfter = stopAfter;
432
+ }
433
+ /** One settled round: the tools it ran (names) and whether any call changed the workspace. */
434
+ observe(names, mutating) {
435
+ if (names.some((n) => DISPATCH_TOOLS.has(n))) {
436
+ this.dispatched = true;
437
+ this.streak = 0;
438
+ return { action: "allow", streak: 0 };
439
+ }
440
+ if (!this.dispatched)
441
+ return { action: "allow", streak: 0 };
442
+ if (mutating) {
443
+ this.streak = 0;
444
+ return { action: "allow", streak: 0 };
445
+ }
446
+ this.streak += 1;
447
+ if (this.streak >= this.stopAfter)
448
+ return { action: "halt", streak: this.streak, message: YIELD_STOP };
449
+ if (this.streak >= this.nudgeAfter && !this.nudged) {
450
+ this.nudged = true;
451
+ return { action: "nudge", streak: this.streak, message: YIELD_NUDGE };
452
+ }
453
+ return { action: "allow", streak: this.streak };
454
+ }
455
+ }
401
456
  // ── No-write-progress detector ───────────────────────────────────────────────
402
457
  // Catches investigate-loops: consecutive rounds of tool calls where ZERO are mutating calls.
403
458
  // The existing loop guard (identical-call, cycle, failure) evades this by varying args each round.
package/dist/session.js CHANGED
@@ -84,7 +84,8 @@ function makeSpawnTool(handler) {
84
84
  "\"I'll spawn sub-agents\" without calling spawn_agent. Keep working meanwhile: NEVER sleep, poll or wait for a " +
85
85
  "result (agent_status checks state, message_agent steers, stop_agent halts; a sub-agent id is NOT a shell job id — " +
86
86
  "bash_output/bash_kill will just error). NEVER re-spawn a task because its result hasn't arrived — it is still " +
87
- "working.\n" +
87
+ "working. Then finish only what does NOT depend on them, give a one-line status and END YOUR TURN — reports " +
88
+ "re-enter as new messages; a turn that keeps polling holds the model slot and starves the sub-agents.\n" +
88
89
  "USE FOR: reasoning-heavy subtasks, work that would flood your context, or independent parallel workstreams " +
89
90
  "(research per area, review per module, search per tree, drafting a file).\n" +
90
91
  "DO NOT USE FOR: a single tool call; mechanical steps with no reasoning; anything that needs the user (sub-agents " +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.325",
3
+ "version": "0.1.327",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",