copilot-operator 0.1.70 → 0.1.80

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.
Files changed (78) hide show
  1. package/dist/src/api/operator.controller.js +9 -5
  2. package/dist/src/api/operator.service.js +107 -23
  3. package/dist/src/cli.js +1 -0
  4. package/dist/src/config/live.js +122 -0
  5. package/dist/src/config/schema.js +7 -0
  6. package/dist/src/exec/authorizer.js +2 -2
  7. package/dist/src/exec/commandHeads.js +11 -2
  8. package/dist/src/exec/locations.js +194 -0
  9. package/dist/src/exec/network.js +3 -1
  10. package/dist/src/exec/policy.js +14 -2
  11. package/dist/src/exec/policyManifest.js +2 -0
  12. package/dist/src/exec/processes.js +8 -3
  13. package/dist/src/exec/scriptFiles.js +66 -23
  14. package/dist/src/exec/scriptKinds.js +7 -7
  15. package/dist/src/exec/stops.js +147 -0
  16. package/dist/src/orchestrator/chosenAnswers.js +22 -0
  17. package/dist/src/orchestrator/handoff.js +37 -2
  18. package/dist/src/orchestrator/hold.js +83 -4
  19. package/dist/src/orchestrator/leadRunner.js +39 -22
  20. package/dist/src/orchestrator/taskRunner.js +130 -50
  21. package/dist/src/plan/kerrigan.js +36 -15
  22. package/dist/src/plan/systemGuide.js +72 -32
  23. package/dist/src/protocol/leadSchema.js +6 -1
  24. package/dist/src/protocol/replySchema.js +6 -0
  25. package/dist/src/queue/queue.js +6 -0
  26. package/dist/src/session/model.js +12 -0
  27. package/dist/src/util/pacing.js +6 -0
  28. package/dist/src/vcs/newBranch.js +69 -10
  29. package/dist/web/404.html +2 -2
  30. package/dist/web/_next/static/chunks/1024-17c74da39fb738c9.js +1 -0
  31. package/dist/web/_next/static/chunks/1077.ad76ce55c8120db5.js +1 -0
  32. package/dist/web/_next/static/chunks/1548.4dc2e419eee42487.js +1 -0
  33. package/dist/web/_next/static/chunks/2163.9f5c1d052712579f.js +1 -0
  34. package/dist/web/_next/static/chunks/714.3f04498b624bc1a4.js +1 -0
  35. package/dist/web/_next/static/chunks/7220.43612a34a3cb5146.js +1 -0
  36. package/dist/web/_next/static/chunks/7921-df716a0338420836.js +1 -0
  37. package/dist/web/_next/static/chunks/8124-2f07cc63c1494443.js +1 -0
  38. package/dist/web/_next/static/chunks/8584.36fd8289becb2d75.js +1 -0
  39. package/dist/web/_next/static/chunks/895-9c1f0751920e6624.js +1 -0
  40. package/dist/web/_next/static/chunks/9067.eff8198294aec025.js +1 -0
  41. package/dist/web/_next/static/chunks/9747.43e5b7201aa505ba.js +1 -0
  42. package/dist/web/_next/static/chunks/app/layout-b8a1e0075a48b025.js +1 -0
  43. package/dist/web/_next/static/chunks/app/page-4a7cf5d83c000d73.js +1 -0
  44. package/dist/web/_next/static/chunks/app/queue/{page-82f724d0842f4870.js → page-317151444eda8115.js} +1 -1
  45. package/dist/web/_next/static/chunks/app/settings/page-ec85a538fda29964.js +1 -0
  46. package/dist/web/_next/static/chunks/{webpack-950df0f512eef7ec.js → webpack-a7f5c4d1eda36000.js} +1 -1
  47. package/dist/web/_next/static/css/0e586e29189e8783.css +1 -0
  48. package/dist/web/defaults.html +2 -2
  49. package/dist/web/defaults.txt +8 -8
  50. package/dist/web/index.html +3 -3
  51. package/dist/web/index.txt +9 -9
  52. package/dist/web/queue.html +2 -2
  53. package/dist/web/queue.txt +9 -9
  54. package/dist/web/settings.html +2 -2
  55. package/dist/web/settings.txt +9 -9
  56. package/dist/web/system.html +2 -2
  57. package/dist/web/system.txt +9 -9
  58. package/package.json +4 -3
  59. package/prompts/lead1.md +5 -2
  60. package/prompts/level1.md +50 -38
  61. package/dist/web/_next/static/chunks/1024-67625a65f58057ae.js +0 -1
  62. package/dist/web/_next/static/chunks/1077.9fe1c0425bf51375.js +0 -1
  63. package/dist/web/_next/static/chunks/1548.cae3ba2196c8d52f.js +0 -1
  64. package/dist/web/_next/static/chunks/2163.5c9f8477d98b75a4.js +0 -1
  65. package/dist/web/_next/static/chunks/714.a0b32193f71e0e91.js +0 -1
  66. package/dist/web/_next/static/chunks/7220.5d6da026e0b34169.js +0 -1
  67. package/dist/web/_next/static/chunks/7921-0f7954cb5a9f697b.js +0 -1
  68. package/dist/web/_next/static/chunks/8124-a39d85dff0db6600.js +0 -1
  69. package/dist/web/_next/static/chunks/8584.6aa7ce56f7552f17.js +0 -1
  70. package/dist/web/_next/static/chunks/9067.2e4ba2e0e572f21e.js +0 -1
  71. package/dist/web/_next/static/chunks/9747.763da2026719a863.js +0 -1
  72. package/dist/web/_next/static/chunks/9929-2e0b1d006ebd5345.js +0 -1
  73. package/dist/web/_next/static/chunks/app/layout-52a2079ffa83c21f.js +0 -1
  74. package/dist/web/_next/static/chunks/app/page-44eac9d137f26dc5.js +0 -1
  75. package/dist/web/_next/static/chunks/app/settings/page-2df196e25cb7bfe1.js +0 -1
  76. package/dist/web/_next/static/css/cfe8ccb4adf3a311.css +0 -1
  77. /package/dist/web/_next/static/{DzoLjnxX5FvdxuPasWlnb → NP3hd8WmgkJYg_cn8gcXy}/_buildManifest.js +0 -0
  78. /package/dist/web/_next/static/{DzoLjnxX5FvdxuPasWlnb → NP3hd8WmgkJYg_cn8gcXy}/_ssgManifest.js +0 -0
@@ -37,7 +37,8 @@ import { allAboutTheTask, isRepeat, findingId } from '../protocol/reviewSchema.j
37
37
  import { repoState, workingTreePaths } from '../vcs/git.js';
38
38
  import { describeStep, checkAccessRefusal, checkCommandRefusal, commandRefusal } from '../exec/policy.js';
39
39
  import { networkFetchReason } from '../exec/network.js';
40
- import { handoffCard, handoffOutcomeOf, handoffResultMessage, HANDOFF_NOBODY } from './handoff.js';
40
+ import { handoffCard, handoffOutcomeOf, handoffResultMessage, HANDOFF_NOBODY, MAX_SHELL_ENDING_RETURNS, shellEndingLines, shellEndingMessage } from './handoff.js';
41
+ import { chosenSaid } from './chosenAnswers.js';
41
42
  import { gitConfigMessage, watchGitConfig } from '../vcs/gitConfigGuard.js';
42
43
  import { scriptsNote } from '../exec/scriptKinds.js';
43
44
  import { collectPolicyManifest, describePolicyManifest } from '../exec/policyManifest.js';
@@ -56,7 +57,7 @@ import { composeHandoff } from '../session/handoff.js';
56
57
  import { ProgressWatch } from './progress.js';
57
58
  import { contractConflicts, readsTreeClean } from './contract.js';
58
59
  import { commitFiles, treeFingerprint } from '../vcs/git.js';
59
- import { isContinuable } from '../session/model.js';
60
+ import { isContinuable, withProblemAt } from '../session/model.js';
60
61
  import { prepareForTask, commitTaskResult, commitShortfall, repoDirOf, trackedRepoOf, whereLeft } from '../vcs/taskVcs.js';
61
62
  import { protectInputs, inputsMessage, inputsAtCommit, untrackedInputs, blobOfFile } from '../vcs/inputs.js';
62
63
  import { artifactPatterns, artifactState, keepArtifacts } from '../vcs/artifacts.js';
@@ -69,6 +70,11 @@ import { runLeadTask } from './leadRunner.js';
69
70
  * conflict decided before any message was retried twice in fresh chats).
70
71
  */
71
72
  export const NOT_THE_CHATS = ['contract-conflict', 'environment', 'invalid-check'];
73
+ /** The Settings each step is judged by: the chat is told when a save changes one under it (2026-11-03). */
74
+ const LIVE_RULES = new Set([
75
+ 'execution.allowedPrograms', 'execution.readOnlyPrograms', 'execution.runWithoutAsking', 'execution.scripts',
76
+ 'execution.writtenScripts', 'execution.networkFetch', 'execution.denyPatterns', 'execution.isolation',
77
+ ]);
72
78
  /**
73
79
  * Records a model the page offers under a new name where it was chosen — the session, or Settings — and
74
80
  * the line-up read on the way. Returns the sentence that says so, or ''.
@@ -967,6 +973,8 @@ export async function runTask(transport, session, task, deps) {
967
973
  return;
968
974
  log.event(e.type, { ...(e.data ?? {}), ...(e.message ? { message: e.message } : {}), mirrored: true }, undefined, e.level);
969
975
  });
976
+ // No longer hearing of Settings saved, once the task ends (see `tookSettings`).
977
+ let unlive = () => undefined;
970
978
  const pacer = new Pacer({
971
979
  enabled: cfg.pacing.enabled,
972
980
  settleMs: cfg.pacing.settleMs,
@@ -1049,14 +1057,19 @@ export async function runTask(transport, session, task, deps) {
1049
1057
  };
1050
1058
  transport = holdsWhilePaused(transport, () => holdHere('message'));
1051
1059
  // No message longer than Settings allow as text: the rest goes attached (2026-10-22, see `limitsMessageLength`).
1060
+ // The limit and the patterns as Settings have them when each message goes (2026-11-03: a save takes effect at once).
1052
1061
  transport = limitsMessageLength(transport, {
1053
- max: cfg.limits.maxMessageChars,
1062
+ get max() {
1063
+ return cfg.limits.maxMessageChars;
1064
+ },
1054
1065
  dir: log.path('messages'),
1055
1066
  onLong: ({ chars, max, file }) => sink.event('message-long', { chars, max, file }, `a message of ${chars} characters is over the ${max} sent as text: its beginning is sent, the whole of it attached as ${file}`, 'warn'),
1056
1067
  });
1057
1068
  // Nothing goes to the chat with a secret in it, whatever made the message (audit, 2026-10-27).
1058
1069
  transport = redactsMessages(transport, {
1059
- patterns: cfg.report.redactPatterns,
1070
+ get patterns() {
1071
+ return cfg.report.redactPatterns;
1072
+ },
1060
1073
  onRedacted: (hits) => sink.event('message-redacted', { redactions: hits }, `secrets taken out of a message before it was sent: ${hits.map((h) => `${h.name} ×${h.count}`).join(', ')}`, 'warn'),
1061
1074
  });
1062
1075
  let iterations = 0;
@@ -1076,6 +1089,8 @@ export async function runTask(transport, session, task, deps) {
1076
1089
  /** The handoff's revision, and whether the last one was sent back for a correction (2026-10-27). */
1077
1090
  let handoffRevision = 0;
1078
1091
  let handoffSentBack = false;
1092
+ // Handoffs sent back in a row because a line would end the operator's terminal (2026-11-03).
1093
+ let shellEndingReturns = 0;
1079
1094
  /**
1080
1095
  * Each handoff as it was shown and answered, kept in the run folder, so the conversation shows every revision, the
1081
1096
  * note it was sent back with and what the operator's own run printed (`session/story.ts`).
@@ -1094,15 +1109,22 @@ export async function runTask(transport, session, task, deps) {
1094
1109
  * How many different approaches "blocked" needs, from Settings, never below the format's own two.
1095
1110
  * A "blocked" with fewer is sent back; after `MAX_EARLY_BLOCKS` of them in a row with nothing tried
1096
1111
  * in between the verdict is accepted, so a chat that cannot think of anything else does not spend
1097
- * the rest of the iterations saying so.
1112
+ * the rest of the iterations saying so. Read when it is asked, as the limits below are, so a change
1113
+ * saved in Settings while the task runs is the one it goes by (2026-11-03).
1098
1114
  */
1099
- const minApproaches = Math.max(MIN_TRIED_APPROACHES, cfg.limits.minApproachesBeforeBlocked ?? MIN_TRIED_APPROACHES);
1115
+ const minApproaches = () => Math.max(MIN_TRIED_APPROACHES, cfg.limits.minApproachesBeforeBlocked ?? MIN_TRIED_APPROACHES);
1100
1116
  const MAX_EARLY_BLOCKS = 3;
1101
1117
  let earlyBlocks = 0;
1102
1118
  /** What went wrong on the way, counted for the register's figures. See `TaskStats`. */
1103
1119
  const stats = { formatErrors: 0, doneRejected: 0, repeatsRefused: 0, stepsRefused: 0, operatorStops: 0, reviewRejections: 0, scopeReverts: 0 };
1104
1120
  /** Loops the older guards do not see; see `progress.ts`. */
1105
- const progress = new ProgressWatch({ noProgress: Math.max(2, cfg.limits.maxNoProgressRounds ?? 3), oscillations: 2 });
1121
+ const progress = new ProgressWatch({
1122
+ // As Settings have it when it is asked (2026-11-03).
1123
+ get noProgress() {
1124
+ return Math.max(2, cfg.limits.maxNoProgressRounds ?? 3);
1125
+ },
1126
+ oscillations: 2,
1127
+ });
1106
1128
  /** Set when a check round shows no progress; the give-up then ends the task blocked with it. */
1107
1129
  let noProgressReason = null;
1108
1130
  /** The scope as enforced on the task's own branch, once known; `finish` holds the commit to it too. */
@@ -1365,7 +1387,8 @@ export async function runTask(transport, session, task, deps) {
1365
1387
  }
1366
1388
  }
1367
1389
  else {
1368
- afterCommitResults = outcomes.map((o) => ({ name: `${o.check.name} (after the commit)`, passed: o.passed, detail: o.detail }));
1390
+ const at = new Date().toISOString();
1391
+ afterCommitResults = outcomes.map((o) => ({ name: `${o.check.name} (after the commit)`, passed: o.passed, detail: o.detail, at }));
1369
1392
  for (const o of outcomes) {
1370
1393
  sink.event(o.passed ? 'check-passed' : 'check-failed', { name: o.check.name, detail: o.detail, afterCommit: true }, `${o.passed ? 'passed' : 'FAILED'} after the commit: ${o.check.name} — ${o.detail}`, o.passed ? 'info' : 'warn');
1371
1394
  }
@@ -1406,7 +1429,7 @@ export async function runTask(transport, session, task, deps) {
1406
1429
  }
1407
1430
  await setTask((t) => {
1408
1431
  if (vcsAfter)
1409
- t.vcs = vcsAfter;
1432
+ t.vcs = withProblemAt(t.vcs, vcsAfter);
1410
1433
  t.status = status;
1411
1434
  delete t.acting;
1412
1435
  t.iterations = iterations;
@@ -1449,6 +1472,7 @@ export async function runTask(transport, session, task, deps) {
1449
1472
  await record(`TASK ${status.toUpperCase()}`, reason ? `Reason: ${reason}` : '(no reason: it ended as reported)');
1450
1473
  sink.event('task-finished', { status, reason, iterations }, `task "${task.title}" ${status}${reason ? `: ${reason}` : ''}`);
1451
1474
  unmirror();
1475
+ unlive();
1452
1476
  await log.close();
1453
1477
  /*
1454
1478
  * An attempt that did not end done leaves its plan, work and runner views in its own folder,
@@ -1592,23 +1616,49 @@ export async function runTask(transport, session, task, deps) {
1592
1616
  for (const concern of isolation.warnings) {
1593
1617
  sink.event('isolation', { claim: isolation.claim, elevated: isolation.signals.elevated }, concern, 'warn');
1594
1618
  }
1595
- const manifest = collectPolicyManifest({
1596
- isolation,
1619
+ // The rules in force as Settings have them now: at the start, and again whenever a save changes them.
1620
+ const policyManifestNow = (assessed = isolation) => collectPolicyManifest({
1621
+ isolation: assessed,
1597
1622
  confinedTo: confinement.roots,
1598
1623
  mode: deps.currentMode?.() ?? cfg.execution.mode,
1599
1624
  networkFetch: cfg.execution.networkFetch,
1600
1625
  allowedPrograms: cfg.execution.allowedPrograms,
1601
1626
  readOnlyPrograms: cfg.execution.readOnlyPrograms,
1627
+ runWithoutAsking: cfg.execution.runWithoutAsking,
1602
1628
  scripts: cfg.execution.scripts,
1603
1629
  writtenScripts: cfg.execution.writtenScripts,
1604
1630
  denyPatterns: cfg.execution.denyPatterns,
1605
1631
  cwd: work.cwd,
1606
1632
  lock: cfg.policyLock,
1607
1633
  });
1634
+ const manifest = policyManifestNow();
1608
1635
  await writeFile(log.path('policy.json'), JSON.stringify(manifest, null, 2), 'utf8').catch(() => undefined);
1609
1636
  await record('POLICY', describePolicyManifest(manifest));
1610
1637
  sink.event('policy', { mode: manifest.mode, allowlist: manifest.allowlist.enforced, allowlistDigest: manifest.allowlist.digest }, `policy: ${manifest.mode}, allowlist ${manifest.allowlist.enforced ? `${manifest.allowlist.count} programs (${manifest.allowlist.digest})` : 'NOT ENFORCED'}, ` +
1611
1638
  'the chat cannot supply files', manifest.mode === 'unattended' || !manifest.allowlist.enforced ? 'warn' : 'info');
1639
+ /*
1640
+ * Settings saved while this message is at work (operator, 2026-11-03: "when I change a setting, if it can be, let it
1641
+ * take effect at once, even while a task is running"). `cfg` has taken what can change under a message already
1642
+ * (`config/live.ts`), and every part of the task reads it where it uses it. Here the record says so, the pauses are
1643
+ * set again, the rules in force are written beside the first ones, and the chat is told with the next message — a
1644
+ * step refused before may run now, and one that ran may be refused.
1645
+ */
1646
+ let policyRevision = 1;
1647
+ const tookSettings = async (change) => {
1648
+ pacer.retune({ enabled: cfg.pacing.enabled, settleMs: cfg.pacing.settleMs, maxMessagesPerHour: cfg.pacing.maxMessagesPerHour, gapMs: gapFrom(cfg.pacing) });
1649
+ const later = [...change.next, ...change.window];
1650
+ sink.event('settings-changed', change, `Settings saved while this message runs: ${change.now.join(', ')} in force from now${later.length ? `; ${later.join(', ')} from the next message, or the next time the chat window opens` : ''}`);
1651
+ const rules = change.now.filter((name) => LIVE_RULES.has(name));
1652
+ if (rules.length === 0)
1653
+ return;
1654
+ policyRevision += 1;
1655
+ const again = policyManifestNow(assessIsolation(cfg.execution.isolation, readIsolationSignals()));
1656
+ await writeFile(log.path(`policy-${policyRevision}.json`), JSON.stringify(again, null, 2), 'utf8').catch(() => undefined);
1657
+ await record(`POLICY CHANGED (${policyRevision})`, describePolicyManifest(again));
1658
+ runnerNotes.push(`The operator changed Settings while this task runs: ${rules.map((name) => name.replace(/^execution\./, '')).join(', ')}. Every step is judged by ` +
1659
+ 'them as they are now: a step refused before for them may run now — send it again if the work needs it — and one that ran before may be refused.');
1660
+ };
1661
+ unlive = deps.live?.onChange((change) => void tookSettings(change).catch(() => undefined)) ?? unlive;
1612
1662
  // Not when the project is this runner's own checkout: every process of the runner would
1613
1663
  // then look like a leftover.
1614
1664
  processesBefore = work.ownCheckout ? null : await snapshotProcesses(work.cwd).catch(() => null);
@@ -1619,13 +1669,13 @@ export async function runTask(transport, session, task, deps) {
1619
1669
  }, () => store.listSessions());
1620
1670
  if (prepared.refuse) {
1621
1671
  await setTask((t) => {
1622
- t.vcs = prepared.vcs;
1672
+ t.vcs = withProblemAt(t.vcs, prepared.vcs);
1623
1673
  });
1624
1674
  return await finish('failed', prepared.refuse);
1625
1675
  }
1626
1676
  if (prepared.vcs.branch || prepared.vcs.problem) {
1627
1677
  await setTask((t) => {
1628
- t.vcs = prepared.vcs;
1678
+ t.vcs = withProblemAt(t.vcs, prepared.vcs);
1629
1679
  });
1630
1680
  await record('VERSION CONTROL', prepared.vcs.problem
1631
1681
  ? `not active: ${prepared.vcs.problem}`
@@ -1821,8 +1871,8 @@ export async function runTask(transport, session, task, deps) {
1821
1871
  ? `## Outputs\n\nThis task is to produce: ${(task.outputs ?? []).map((o) => `\`${o}\``).join(', ')}. What it creates or changes there is kept with the run's record as its evidence.`
1822
1872
  : '',
1823
1873
  ].filter(Boolean).join('\n\n'),
1824
- approachesNote: minApproaches > MIN_TRIED_APPROACHES
1825
- ? `## Giving up\n\nThis task may end with status "blocked" only after at least ${minApproaches} genuinely different approaches, ` +
1874
+ approachesNote: minApproaches() > MIN_TRIED_APPROACHES
1875
+ ? `## Giving up\n\nThis task may end with status "blocked" only after at least ${minApproaches()} genuinely different approaches, ` +
1826
1876
  `each listed in "tried". With fewer, the runner asks you for another approach instead of accepting it.`
1827
1877
  : undefined,
1828
1878
  shellNote: shellNote(shells, defaultShell),
@@ -1924,7 +1974,7 @@ export async function runTask(transport, session, task, deps) {
1924
1974
  // refresh the object this function is holding, so reading it back would give the state
1925
1975
  // before the checks ran and the reason would come out empty.
1926
1976
  let lastOutcomes = [];
1927
- const maxCheckRounds = Math.max(1, cfg.limits.maxCheckRounds ?? 3);
1977
+ const maxCheckRounds = () => Math.max(1, cfg.limits.maxCheckRounds ?? 3);
1928
1978
  /*
1929
1979
  * The runner's own check, when there is going to be a commit.
1930
1980
  *
@@ -2063,8 +2113,9 @@ export async function runTask(transport, session, task, deps) {
2063
2113
  pointedOut.set(o.check.expect, shown);
2064
2114
  }
2065
2115
  }
2116
+ const checkedAt = new Date().toISOString();
2066
2117
  await setTask((t) => {
2067
- t.checkResults = outcomes.map((o) => ({ name: o.check.name, passed: o.passed, detail: o.detail }));
2118
+ t.checkResults = outcomes.map((o) => ({ name: o.check.name, passed: o.passed, detail: o.detail, at: checkedAt }));
2068
2119
  });
2069
2120
  /*
2070
2121
  * The machine, not the work.
@@ -2139,7 +2190,7 @@ export async function runTask(transport, session, task, deps) {
2139
2190
  sink.event('no-progress', { kind: 'checks' }, stuck, 'warn');
2140
2191
  return 'give-up';
2141
2192
  }
2142
- if (checkRounds > maxCheckRounds) {
2193
+ if (checkRounds > maxCheckRounds()) {
2143
2194
  /*
2144
2195
  * Only checks from earlier reviews are failing. A reviewer's check is outranked by the
2145
2196
  * next reviewer's judgement, not by a counter: they are suspended, the work goes to
@@ -2152,11 +2203,11 @@ export async function runTask(transport, session, task, deps) {
2152
2203
  t.reviewChecks = reviewChecks;
2153
2204
  });
2154
2205
  derivedStillFailing = failed.map((o) => ({ name: o.check.name, detail: o.detail }));
2155
- sink.event('checks-derived-deferred', { rounds: checkRounds - 1, checks: failed.map((o) => o.check.name) }, `${failed.length} check(s) from earlier reviews still fail after ${maxCheckRounds} attempt(s); the work goes to the reviewer with them named`, 'warn');
2206
+ sink.event('checks-derived-deferred', { rounds: checkRounds - 1, checks: failed.map((o) => o.check.name) }, `${failed.length} check(s) from earlier reviews still fail after ${maxCheckRounds()} attempt(s); the work goes to the reviewer with them named`, 'warn');
2156
2207
  return 'accept';
2157
2208
  }
2158
- limitHit = { setting: 'maxCheckRounds', value: maxCheckRounds };
2159
- sink.event('checks-exhausted', { rounds: checkRounds - 1 }, `${failed.length} check(s) still failing after ${maxCheckRounds} attempt(s); the task is closed as failed`, 'warn');
2209
+ limitHit = { setting: 'maxCheckRounds', value: maxCheckRounds() };
2210
+ sink.event('checks-exhausted', { rounds: checkRounds - 1 }, `${failed.length} check(s) still failing after ${maxCheckRounds()} attempt(s); the task is closed as failed`, 'warn');
2160
2211
  return 'give-up';
2161
2212
  }
2162
2213
  // A Stop that came after every check had run: the round stands, and nothing more is sent.
@@ -2174,7 +2225,7 @@ export async function runTask(transport, session, task, deps) {
2174
2225
  const checkReport = failureReport(outcomes, cfg.report.redactPatterns);
2175
2226
  await writeFile(path, checkReport, 'utf8');
2176
2227
  await record(`CHECKS ${checkRounds}`, checkReport);
2177
- const message = failureMessage(outcomes, checkRounds, maxCheckRounds, cfg.report.redactPatterns);
2228
+ const message = failureMessage(outcomes, checkRounds, maxCheckRounds(), cfg.report.redactPatterns);
2178
2229
  await record(`CHECKS ${checkRounds} MESSAGE SENT`, message);
2179
2230
  // Said as a step report's redaction is, so a checks round that hid something is not silent.
2180
2231
  const redactions = failureRedactions(outcomes, cfg.report.redactPatterns);
@@ -2213,10 +2264,10 @@ export async function runTask(transport, session, task, deps) {
2213
2264
  /** What the previous review's own steps left running, told to both sides. */
2214
2265
  let previousLeftovers = [];
2215
2266
  const reviewWanted = task.reviewEnabled ?? session.review?.enabled ?? true;
2216
- const maxReviewRounds = Math.max(1, cfg.limits.maxReviewRounds ?? 2);
2267
+ const maxReviewRounds = () => Math.max(1, cfg.limits.maxReviewRounds ?? 2);
2217
2268
  const saveReview = async (review) => {
2218
2269
  await setTask((t) => {
2219
- t.review = review;
2270
+ t.review = { ...review, at: new Date().toISOString() };
2220
2271
  });
2221
2272
  };
2222
2273
  /**
@@ -2259,7 +2310,7 @@ export async function runTask(transport, session, task, deps) {
2259
2310
  // the reviewer is given it — as claims to test. See `Deliverable` in review.ts.
2260
2311
  const deliverable = deliverableFor(task, closing, repoDir !== '' || chatChanged !== null, changedFiles);
2261
2312
  await actingNow('review', { round: reviewRounds });
2262
- sink.event('review-started', { round: reviewRounds, model: model || '(the session model)', files: changedFiles.length, deliverable: deliverable?.why }, `an independent review is opening a fresh conversation (round ${reviewRounds} of ${maxReviewRounds})` +
2313
+ sink.event('review-started', { round: reviewRounds, model: model || '(the session model)', files: changedFiles.length, deliverable: deliverable?.why }, `an independent review is opening a fresh conversation (round ${reviewRounds} of ${maxReviewRounds()})` +
2263
2314
  (deliverable ? `; the closing summary goes with it as the product (${deliverable.why})` : ''));
2264
2315
  // What is running before the review, so that what the review leaves is its own.
2265
2316
  const beforeReview = processesBefore ? await snapshotProcesses(work.cwd, processesBefore.since).catch(() => null) : null;
@@ -2494,9 +2545,9 @@ export async function runTask(transport, session, task, deps) {
2494
2545
  * was then blocked quoting that finding as "still there" without anybody having looked
2495
2546
  * at the fix. It had been fixed.
2496
2547
  */
2497
- if (reviewRounds > maxReviewRounds) {
2498
- limitHit = { setting: 'maxReviewRounds', value: maxReviewRounds };
2499
- sink.event('review-exhausted', { rounds: maxReviewRounds, findings: outcome.findings.length }, `the review still has findings after ${maxReviewRounds} round(s) of fixing; the task is closed as blocked`, 'warn');
2548
+ if (reviewRounds > maxReviewRounds()) {
2549
+ limitHit = { setting: 'maxReviewRounds', value: maxReviewRounds() };
2550
+ sink.event('review-exhausted', { rounds: maxReviewRounds(), findings: outcome.findings.length }, `the review still has findings after ${maxReviewRounds()} round(s) of fixing; the task is closed as blocked`, 'warn');
2500
2551
  return 'give-up';
2501
2552
  }
2502
2553
  sink.event('review-failed', { round: reviewRounds, findings: outcome.findings.length }, `the review found ${outcome.findings.length} problem(s); sending them back to be fixed`, 'warn');
@@ -2506,7 +2557,7 @@ export async function runTask(transport, session, task, deps) {
2506
2557
  await pacer.throttleSend();
2507
2558
  // The reviewer quotes output in its evidence, so the message gets the same treatment.
2508
2559
  // Recorded as sent, because what reached the chat is what the next question is about.
2509
- const findingsSent = redactSecrets(findingsMessage(outcome, reviewRounds, maxReviewRounds, repeatedNamed, roundLeftovers), cfg.report.redactPatterns);
2560
+ const findingsSent = redactSecrets(findingsMessage(outcome, reviewRounds, maxReviewRounds(), repeatedNamed, roundLeftovers), cfg.report.redactPatterns);
2510
2561
  await writeFile(log.path('review', String(reviewRounds), 'findings-sent.md'), findingsSent, 'utf8').catch(() => undefined);
2511
2562
  await record(`REVIEW ${reviewRounds} FINDINGS SENT`, findingsSent);
2512
2563
  const before = await transport.sendAndConfirm(findingsSent);
@@ -2528,7 +2579,7 @@ export async function runTask(transport, session, task, deps) {
2528
2579
  ? `an independent review found ${findings.length} problem(s) with the task itself rather than with the work, ` +
2529
2580
  `so there was nothing to send back for fixing: ${listed}`
2530
2581
  : `an independent review found ${findings.length} problem(s) that were still there after ` +
2531
- `${maxReviewRounds} round(s) of fixing: ${listed}`;
2582
+ `${maxReviewRounds()} round(s) of fixing: ${listed}`;
2532
2583
  };
2533
2584
  /**
2534
2585
  * What a reported "done" comes to: the checks, then the review, either of which may end the
@@ -2588,8 +2639,8 @@ export async function runTask(transport, session, task, deps) {
2588
2639
  * in a circle, and the thing that turns into a task that ends rather than a task that times
2589
2640
  * out.
2590
2641
  */
2591
- const maxCommandRepeats = Math.max(1, cfg.limits.maxCommandRepeats ?? 3);
2592
- const maxStalledIterations = Math.max(1, cfg.limits.maxStalledIterations ?? 2);
2642
+ const maxCommandRepeats = () => Math.max(1, cfg.limits.maxCommandRepeats ?? 3);
2643
+ const maxStalledIterations = () => Math.max(1, cfg.limits.maxStalledIterations ?? 2);
2593
2644
  /**
2594
2645
  * Per command: how many times in a row it has returned exactly the same thing.
2595
2646
  *
@@ -2732,7 +2783,29 @@ export async function runTask(transport, session, task, deps) {
2732
2783
  * agreement or not: only their own run of it has anything to say. With nobody to ask, the chat is told so. What
2733
2784
  * they printed, or that they did not run it, goes back, and the work goes on.
2734
2785
  */
2786
+ if (reply.status !== 'handoff')
2787
+ shellEndingReturns = 0;
2735
2788
  if (reply.status === 'handoff' && reply.handoff) {
2789
+ /*
2790
+ * A line that would end the terminal it is typed in — `exit`, the chat's habit for passing on an exit code — goes
2791
+ * back to the chat before the operator sees it (2026-11-03): typed into their open terminal, it closed it, and what
2792
+ * it printed with it. Twice at most; then the card shows it, marked, and the operator decides.
2793
+ */
2794
+ const ending = shellEndingLines(reply.handoff);
2795
+ if (ending.length > 0 && shellEndingReturns < MAX_SHELL_ENDING_RETURNS) {
2796
+ shellEndingReturns += 1;
2797
+ sink.event('handoff-ends-shell', { lines: ending.map((l) => l.n), time: shellEndingReturns }, `the commands handed over would close the operator's terminal (line ${ending.map((l) => l.n).join(', ')}): sent back to the chat, ${shellEndingReturns}/${MAX_SHELL_ENDING_RETURNS}`, 'warn');
2798
+ const message = shellEndingMessage(ending);
2799
+ await record('HANDOFF SENT BACK — IT WOULD CLOSE THE TERMINAL', message);
2800
+ await pacer.throttleSend();
2801
+ const before = await transport.sendAndConfirm(message);
2802
+ const next = await transport.waitForReply(before);
2803
+ await saveReply(`handoff-ends-shell-${shellEndingReturns}`, next);
2804
+ lastMarkdown = next.markdown;
2805
+ await pacer.settle();
2806
+ continue;
2807
+ }
2808
+ shellEndingReturns = 0;
2736
2809
  // The next revision of the one sent back for a correction; otherwise the first of a new one (2026-10-27).
2737
2810
  handoffRevision = handoffSentBack ? handoffRevision + 1 : 1;
2738
2811
  handoffSentBack = false;
@@ -2789,6 +2862,8 @@ export async function runTask(transport, session, task, deps) {
2789
2862
  const options = reply.options;
2790
2863
  const agree = cfg.execution.questions === 'agree' || !deps.askQuestion;
2791
2864
  let answer = options[0].answer;
2865
+ // A question of several answers (2026-11-02): the ones the operator chose, and what they wrote besides.
2866
+ let many;
2792
2867
  if (agree) {
2793
2868
  sink.event('question-agreed', { question, answer, why: cfg.execution.questions === 'agree' ? 'settings' : 'nobody to ask' }, `the chat asked: ${question} — answered as it recommends (${cfg.execution.questions === 'agree' ? 'Settings agree with what the bot proposes' : 'nobody is there to ask'}): ${answer}`);
2794
2869
  }
@@ -2804,6 +2879,7 @@ export async function runTask(transport, session, task, deps) {
2804
2879
  ...(reply.why?.trim() ? { why: reply.why.trim() } : {}),
2805
2880
  options: options.map((o) => o.answer),
2806
2881
  commands: options.map((o) => o.run ?? null),
2882
+ ...(reply.multiple ? { multiple: true } : {}),
2807
2883
  actor: planning ? 'plan' : 'worker',
2808
2884
  });
2809
2885
  await setTask((t) => {
@@ -2812,10 +2888,12 @@ export async function runTask(transport, session, task, deps) {
2812
2888
  if (got === 'stop' || signal?.aborted)
2813
2889
  return await finish('aborted', 'stopped by the operator at its question', undefined, lastMarkdown);
2814
2890
  answer = got.answer;
2815
- sink.event('question-answered', { question, answer }, `the operator answered: ${answer}`);
2891
+ if (got.chosen)
2892
+ many = { chosen: got.chosen, ...(got.written ? { written: got.written } : {}) };
2893
+ sink.event('question-answered', { question, answer, ...(many ? { chosen: many.chosen } : {}) }, `the operator answered: ${answer}`);
2816
2894
  }
2817
2895
  await record('QUESTION', `${question}\n\nAnswer${agree ? ' (as the chat recommends)' : ''}: ${answer}`);
2818
- const chosen = options.find((o) => o.answer === answer);
2896
+ const chosen = many ? undefined : options.find((o) => o.answer === answer);
2819
2897
  if (chosen?.run) {
2820
2898
  // Run as this reply's one step: through the step loop below, its output reported as any step's.
2821
2899
  chosenRun = agree && deps.askQuestion === undefined ? null : chosen.run.trim();
@@ -2826,8 +2904,10 @@ export async function runTask(transport, session, task, deps) {
2826
2904
  'The runner ran the command that answer carries — step 1 below, its output with it. Go on from there.');
2827
2905
  }
2828
2906
  else {
2829
- const message = `${agree ? 'The runner took your recommended answer' : 'The operator answered your question'} ("${question}"): "${answer}".\n\n` +
2830
- 'Go on with the work from here, in the same format.';
2907
+ const message = many
2908
+ ? `The operator answered your question ("${question}"), ${chosenSaid(many)}\n\nGo on with the work from here, in the same format.`
2909
+ : `${agree ? 'The runner took your recommended answer' : 'The operator answered your question'} ("${question}"): "${answer}".\n\n` +
2910
+ 'Go on with the work from here, in the same format.';
2831
2911
  await record('ANSWER', message);
2832
2912
  await pacer.throttleSend();
2833
2913
  const before = await transport.sendAndConfirm(message);
@@ -2956,7 +3036,7 @@ export async function runTask(transport, session, task, deps) {
2956
3036
  await pacer.settle();
2957
3037
  continue;
2958
3038
  }
2959
- if (blocked && reply.tried.length < minApproaches && earlyBlocks < MAX_EARLY_BLOCKS) {
3039
+ if (blocked && reply.tried.length < minApproaches() && earlyBlocks < MAX_EARLY_BLOCKS) {
2960
3040
  /*
2961
3041
  * Too early to give up, by the operator's own measure (Settings → Execution). Sent back as a
2962
3042
  * request for another approach rather than accepted: the format only knows that two is the
@@ -2964,8 +3044,8 @@ export async function runTask(transport, session, task, deps) {
2964
3044
  */
2965
3045
  earlyBlocks += 1;
2966
3046
  stats.blockedTooEarly = (stats.blockedTooEarly ?? 0) + 1;
2967
- sink.event('blocked-too-early', { tried: reply.tried.length, needed: minApproaches, time: earlyBlocks }, `"blocked" after ${reply.tried.length} approach(es); Settings ask for ${minApproaches}, so the chat is asked for another`, 'warn');
2968
- const message = `Not yet. This task is given up only after at least ${minApproaches} genuinely different approaches, and your reply lists ` +
3047
+ sink.event('blocked-too-early', { tried: reply.tried.length, needed: minApproaches(), time: earlyBlocks }, `"blocked" after ${reply.tried.length} approach(es); Settings ask for ${minApproaches()}, so the chat is asked for another`, 'warn');
3048
+ const message = `Not yet. This task is given up only after at least ${minApproaches()} genuinely different approaches, and your reply lists ` +
2969
3049
  `${reply.tried.length}: ${reply.tried.map((x, i) => `(${i + 1}) ${x}`).join(' ')}. Try a different approach now — not one of ` +
2970
3050
  'these again, and not the same command reworded — and send its steps with status "continue". If it fails too, add it to ' +
2971
3051
  '"tried" and try another. Nothing you listed is lost: the runner keeps what has been tried.';
@@ -2980,8 +3060,8 @@ export async function runTask(transport, session, task, deps) {
2980
3060
  }
2981
3061
  if (blocked) {
2982
3062
  sink.event('task-blocked', { tried: reply.tried, needed: reply.needed }, `the task was given up as blocked after ${reply.tried.length} approach(es)`, 'warn');
2983
- const early = reply.tried.length < minApproaches
2984
- ? `It gave up after ${reply.tried.length} of the ${minApproaches} approaches Settings ask for, having been asked ${earlyBlocks} time(s) for another.`
3063
+ const early = reply.tried.length < minApproaches()
3064
+ ? `It gave up after ${reply.tried.length} of the ${minApproaches()} approaches Settings ask for, having been asked ${earlyBlocks} time(s) for another.`
2985
3065
  : '';
2986
3066
  return await finish('blocked', sentences(blockedReason(reply.tried, reply.needed), early), reply.summary, lastMarkdown);
2987
3067
  }
@@ -3059,7 +3139,7 @@ export async function runTask(transport, session, task, deps) {
3059
3139
  const key = fingerprint(step);
3060
3140
  const last = seen.get(key);
3061
3141
  let ran = last?.sameInARow ?? 0;
3062
- if (ran >= maxCommandRepeats && last) {
3142
+ if (ran >= maxCommandRepeats() && last) {
3063
3143
  // Something changed since it last ran — the tree, or (without a tree to compare) another step ran: not a repeat.
3064
3144
  const nowTree = await treeNow();
3065
3145
  const changed = last.tree !== null && nowTree !== null ? last.tree !== nowTree : stepsRunThisAttempt > last.stepNo;
@@ -3068,11 +3148,11 @@ export async function runTask(transport, session, task, deps) {
3068
3148
  ran = 0;
3069
3149
  }
3070
3150
  }
3071
- if (ran >= maxCommandRepeats) {
3151
+ if (ran >= maxCommandRepeats()) {
3072
3152
  repeatsRefused += 1;
3073
3153
  stats.repeatsRefused += 1;
3074
- sink.event('step-repeated', { id: step.id, count: ran, limit: maxCommandRepeats, command: describeStep(step) }, `step ${step.id} refused: already run ${ran} time(s) in this task with the same result`, 'warn');
3075
- results.push(refusedResult(step, repeatRefusal(ran, maxCommandRepeats)));
3154
+ sink.event('step-repeated', { id: step.id, count: ran, limit: maxCommandRepeats(), command: describeStep(step) }, `step ${step.id} refused: already run ${ran} time(s) in this task with the same result`, 'warn');
3155
+ results.push(refusedResult(step, repeatRefusal(ran, maxCommandRepeats())));
3076
3156
  continue;
3077
3157
  }
3078
3158
  await setTask((t) => {
@@ -3152,7 +3232,7 @@ export async function runTask(transport, session, task, deps) {
3152
3232
  const previous = seen.get(key);
3153
3233
  const sameInARow = previous && previous.signature === signature ? previous.sameInARow + 1 : 1;
3154
3234
  // The tree is read only for a command at the limit, the one case it is asked about.
3155
- seen.set(key, { signature, sameInARow, tree: sameInARow >= maxCommandRepeats ? await treeNow() : null, stepNo: stepsRunThisAttempt });
3235
+ seen.set(key, { signature, sameInARow, tree: sameInARow >= maxCommandRepeats() ? await treeNow() : null, stepNo: stepsRunThisAttempt });
3156
3236
  sink.event('step-finished', { id: step.id, outcome: result.outcome, exitCode: result.exitCode, durationMs: result.durationMs, shell: result.shell, requestedShell: result.requestedShell ?? null, shellPath: result.shellPath ?? '' }, `step ${step.id}: ${result.outcome}, exit ${result.exitCode}, ${(result.durationMs / 1000).toFixed(1)}s`);
3157
3237
  /*
3158
3238
  * Stopped while it ran. The signal is looked at before each step, and after the last one
@@ -3312,10 +3392,10 @@ export async function runTask(transport, session, task, deps) {
3312
3392
  const allNamedAMissingShell = repeatsRefused === 0;
3313
3393
  if (reply.steps.length > 0 && refusedEverything === reply.steps.length) {
3314
3394
  stalled += 1;
3315
- sink.event('iteration-stalled', { stalled, limit: maxStalledIterations }, `every step this iteration ${allRepeats ? 'was a repeat' : allNamedAMissingShell ? 'named a shell this machine has not got' : 'was a repeat or named a shell this machine has not got'} (${stalled}/${maxStalledIterations})`, 'warn');
3316
- if (stalled >= maxStalledIterations) {
3395
+ sink.event('iteration-stalled', { stalled, limit: maxStalledIterations() }, `every step this iteration ${allRepeats ? 'was a repeat' : allNamedAMissingShell ? 'named a shell this machine has not got' : 'was a repeat or named a shell this machine has not got'} (${stalled}/${maxStalledIterations()})`, 'warn');
3396
+ if (stalled >= maxStalledIterations()) {
3317
3397
  const repeated = [...seen.entries()]
3318
- .filter(([, v]) => v.sameInARow >= maxCommandRepeats)
3398
+ .filter(([, v]) => v.sameInARow >= maxCommandRepeats())
3319
3399
  .map(([cmd]) => cmd.slice(0, 120));
3320
3400
  return await finish('blocked', allRepeats
3321
3401
  ? `the same command(s) were sent again after being refused for repetition, ${stalled} iteration(s) running, ` +
@@ -3350,7 +3430,7 @@ export async function runTask(transport, session, task, deps) {
3350
3430
  if (repeatsRefused > 0) {
3351
3431
  covering +=
3352
3432
  `\n\n${repeatsRefused} of the ${reply.steps.length} step(s) were not run: they repeat a command ` +
3353
- `that has already run ${maxCommandRepeats} time(s) in this task with the same result. ` +
3433
+ `that has already run ${maxCommandRepeats()} time(s) in this task with the same result. ` +
3354
3434
  'Change the approach rather than the wording. If nothing else is left to try, end with ' +
3355
3435
  'status "blocked" and say in "tried" what you attempted.';
3356
3436
  }