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
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A question whose answers may be chosen more than one at a time (operator, 2026-11-02: "can the chat offer options not
3
+ * only as radio buttons but as check boxes — more than one choice; I do not want them to look like radio buttons or
4
+ * check boxes"): the answers chosen, by their place, checked against the question, and the answer they make — the
5
+ * chosen ones as a list, with what the operator wrote under it. The card in the chat and the card of a queue task set
6
+ * aside at the question answer through it alike.
7
+ */
8
+ export function chosenAnswer(question, picks, written) {
9
+ if (!question.multiple)
10
+ return { problem: 'This question takes one answer: press it, or write one.' };
11
+ const valid = Array.isArray(picks) && picks.length > 0 && picks.every((n) => Number.isInteger(n) && n >= 0 && n < question.options.length);
12
+ if (!valid)
13
+ return { problem: 'Choose at least one of the answers offered.' };
14
+ const chosen = [...new Set(picks)].sort((a, b) => a - b).map((n) => question.options[n]);
15
+ const text = written.trim();
16
+ return { answer: [chosen.map((c) => `- ${c}`).join('\n'), text].filter(Boolean).join('\n\n'), chosen, ...(text ? { written: text } : {}) };
17
+ }
18
+ /** What the chat or the lead is told after "The operator answered your question, ": the ones chosen, and what was written besides. */
19
+ export function chosenSaid(a) {
20
+ const n = a.chosen.length;
21
+ return [`choosing ${n === 1 ? 'one' : n} of your answers:`, '', ...a.chosen.map((c) => `- ${c}`), ...(a.written ? ['', 'And wrote:', '', a.written] : [])].join('\n');
22
+ }
@@ -21,6 +21,8 @@ import { dangerousRefusal } from '../exec/dangerous.js';
21
21
  import { botSelfRefusal, networkFetchReason } from '../exec/network.js';
22
22
  import { matchDenyPattern } from '../exec/policy.js';
23
23
  import { platformReason } from '../exec/platforms.js';
24
+ import { codeFilesRun, shellScriptsRun } from '../exec/scriptFiles.js';
25
+ import { endsTheShell } from '../exec/stops.js';
24
26
  /** The most of one script shown on the card. */
25
27
  const MAX_SHOWN_BYTES = 64 * 1024;
26
28
  /** A script larger than this is not read for the card at all. */
@@ -44,7 +46,20 @@ export function handoffCard(h, cwd, roots, denyPatterns, revision = 1) {
44
46
  const folder = resolve(cwd, h.cwd ?? '.');
45
47
  const texts = [...h.commands];
46
48
  const warnings = [];
47
- const files = h.files.map((f) => {
49
+ /*
50
+ * The scripts the chat names, and every one its lines run besides (2026-11-03): `Push-Location 'rules-engine';
51
+ * .\switch-env.ps1 qa` went on a card with no script on it, and what the script did was found out when it stopped
52
+ * the bot. The lines are typed one after another in one terminal, so a folder one of them moves to holds for the next.
53
+ */
54
+ const typed = h.commands.join('\n');
55
+ const named = new Map();
56
+ for (const f of h.files)
57
+ named.set(resolve(folder, f).toLowerCase(), f);
58
+ for (const full of [...shellScriptsRun(typed, folder, 'pwsh'), ...codeFilesRun(typed, folder, 'pwsh')]) {
59
+ if (!named.has(full.toLowerCase()))
60
+ named.set(full.toLowerCase(), full);
61
+ }
62
+ const files = [...named.values()].map((f) => {
48
63
  const full = resolve(folder, f);
49
64
  const path = relative(cwd, full).replace(/\\/g, '/') || f;
50
65
  if (!inside(roots, full))
@@ -69,7 +84,7 @@ export function handoffCard(h, cwd, roots, denyPatterns, revision = 1) {
69
84
  }
70
85
  });
71
86
  h.commands.forEach((line, i) => {
72
- const why = refusedText(line, denyPatterns);
87
+ const why = refusedText(line, denyPatterns) ?? endsTheShell(line);
73
88
  if (why)
74
89
  warnings.push(`${i + 1}: ${why}`);
75
90
  });
@@ -125,6 +140,26 @@ export function handoffResultMessage(h, outcome, text) {
125
140
  `You expected: ${h.expect}\n\nCompare the two and go on with the work from here, in the same format. ` +
126
141
  'A script that is not part of the work can be deleted once you have what you needed from it.');
127
142
  }
143
+ /** How many times a handoff whose lines end the terminal goes back to the chat before the card shows it, marked. */
144
+ export const MAX_SHELL_ENDING_RETURNS = 2;
145
+ /** Which lines of a handoff end the terminal they are typed in (`endsTheShell`), by their number. */
146
+ export function shellEndingLines(h) {
147
+ return h.commands.flatMap((line, i) => {
148
+ const why = endsTheShell(line);
149
+ return why ? [{ n: i + 1, why }] : [];
150
+ });
151
+ }
152
+ /**
153
+ * What the chat is told of lines that would end the operator's terminal (operator, 2026-11-03: "this command stops the
154
+ * cop package — it kills its terminal outright"): sent back before the operator sees them, which costs the operator
155
+ * nothing — they would have lost what the lines printed, and the chat what it asked for.
156
+ */
157
+ export function shellEndingMessage(lines) {
158
+ return (`Not shown to the operator yet: ${lines.map((l) => `line ${l.n} — ${l.why}`).join('; ')}. The operator types these commands ` +
159
+ 'into their own open terminal, where that closes the terminal itself, and with it what the commands printed — which is ' +
160
+ 'what you ask them to send back. Hand them over again with status "handoff": the same commands, without it. To show how ' +
161
+ "they ended, print it instead, for example Write-Output ('EXIT=' + $LASTEXITCODE).");
162
+ }
128
163
  /** What the chat is told when nobody is here to run them: the terminal's run, or one with nobody to ask. */
129
164
  export const HANDOFF_NOBODY = 'Nobody is here to run the commands you handed over: this run has nobody to ask. Go on with the work without them, ' +
130
165
  'or end blocked and say in "needed" what the operator has to run and what it should show.';
@@ -7,6 +7,13 @@
7
7
  * operator continues. Nothing ends: it is the same task, in the same conversation and the same browser window,
8
8
  * after it, and the time it spent held does not count against `maxRunMinutes`.
9
9
  *
10
+ * Nor does the time the work waits for the operator (operator, 2026-10-29: "the time the browser session may be used
11
+ * went on while the user had not answered the chat's questions; while the bot waits for the user to type something or
12
+ * answer, it must not count"): a card — a command, a question, a plan, the model to choose, a subtask to try again,
13
+ * commands handed over —, Git's password window, a sign-in or a check that a person is there, each from the moment it
14
+ * waits to the moment it is answered (`waitFor`, `waited`). A pause and a wait, or two waits, at the same time are
15
+ * counted once.
16
+ *
10
17
  * Not `RunDeps.shouldPause`, which holds a queue between tasks, after the task running has ended properly.
11
18
  */
12
19
  export class Hold {
@@ -18,6 +25,10 @@ export class Hold {
18
25
  * paused is taken off a task's minutes — its limit, and the minutes the page shows.
19
26
  */
20
27
  spans = [];
28
+ /** What waits for the operator now, by a key of its own (`card:<id>`, `pw:<session>`…), since when. */
29
+ waits = new Map();
30
+ /** The waits that were answered, or went any other way. */
31
+ waitedSpans = [];
21
32
  /** Whether the operator has asked the task to hold. */
22
33
  get held() {
23
34
  return this.paused;
@@ -42,13 +53,30 @@ export class Hold {
42
53
  go();
43
54
  return true;
44
55
  }
45
- /** How long the work was paused since `since` (ms), the pause going on counted to now. */
56
+ /** Something waits for the operator from now; a second start of the same one changes nothing. */
57
+ waitFor(key, at = Date.now()) {
58
+ if (!this.waits.has(key))
59
+ this.waits.set(key, at);
60
+ }
61
+ /** It was answered, or went any other way; nothing when it was not waiting. */
62
+ waited(key, at = Date.now()) {
63
+ const from = this.waits.get(key);
64
+ if (from === undefined)
65
+ return;
66
+ this.waits.delete(key);
67
+ this.waitedSpans.push({ from, to: Math.max(from, at) });
68
+ }
69
+ /** The time not counted — paused, or waiting for the operator — joined where it overlaps, in order. */
70
+ notCounted() {
71
+ return joined([...this.spans, ...this.waitedSpans, ...[...this.waits.values()].map((from) => ({ from }))]);
72
+ }
73
+ /** How long the work was paused or waited for the operator since `since` (ms), what goes on counted to now. */
46
74
  pausedSince(since, now = Date.now()) {
47
- return pausedWithin(this.spans, since, now);
75
+ return pausedWithin(this.notCounted(), since, now);
48
76
  }
49
- /** The pauses, for the page to take them off the minutes it shows. */
77
+ /** The time not counted, for the page to take it off the minutes it shows: the pauses and the waits, joined. */
50
78
  get pauses() {
51
- return this.spans.map((s) => ({ from: new Date(s.from).toISOString(), ...(s.to !== undefined ? { to: new Date(s.to).toISOString() } : {}) }));
79
+ return this.notCounted().map((s) => ({ from: new Date(s.from).toISOString(), ...(s.to !== undefined ? { to: new Date(s.to).toISOString() } : {}) }));
52
80
  }
53
81
  /** Resolves at once when not held; otherwise when the operator continues, or the run is stopped. */
54
82
  until(signal) {
@@ -65,6 +93,57 @@ export class Hold {
65
93
  });
66
94
  }
67
95
  }
96
+ /** Spans joined where they overlap or touch, in order; one with no end takes in every span that starts after it. */
97
+ export function joined(spans) {
98
+ const out = [];
99
+ for (const s of [...spans].sort((a, b) => a.from - b.from)) {
100
+ const last = out.at(-1);
101
+ if (last && (last.to === undefined || s.from <= last.to)) {
102
+ if (last.to !== undefined) {
103
+ if (s.to === undefined)
104
+ delete last.to;
105
+ else
106
+ last.to = Math.max(last.to, s.to);
107
+ }
108
+ }
109
+ else
110
+ out.push(s.to === undefined ? { from: s.from } : { from: s.from, to: s.to });
111
+ }
112
+ return out;
113
+ }
114
+ /**
115
+ * The cards that wait for the operator, kept as a map, each starting a wait when it is put in and ending it when it
116
+ * goes — answered, set aside, stopped —, so no card can wait without its time being left out (2026-10-29).
117
+ */
118
+ export class WaitsFor extends Map {
119
+ onWait;
120
+ constructor(onWait) {
121
+ super();
122
+ this.onWait = onWait;
123
+ }
124
+ set(key, value) {
125
+ const fresh = !this.has(key);
126
+ super.set(key, value);
127
+ // `onWait` is not there yet while `super()` runs: Map's constructor puts nothing in, but be sure.
128
+ if (fresh)
129
+ this.onWait?.(key, value, true);
130
+ return this;
131
+ }
132
+ delete(key) {
133
+ const had = this.has(key);
134
+ const value = this.get(key);
135
+ const gone = super.delete(key);
136
+ if (had && gone)
137
+ this.onWait(key, value, false);
138
+ return gone;
139
+ }
140
+ clear() {
141
+ const all = [...this.entries()];
142
+ super.clear();
143
+ for (const [key, value] of all)
144
+ this.onWait(key, value, false);
145
+ }
146
+ }
68
147
  /** The time of `spans` that falls between `since` and `now`, a span with no end lasting to `now`. */
69
148
  export function pausedWithin(spans, since, now) {
70
149
  let ms = 0;
@@ -31,6 +31,7 @@ import { operatorNotesSection, whyItStopped } from '../session/compose.js';
31
31
  import { describeDeviations } from '../protocol/replySchema.js';
32
32
  import { leadFormatErrorMessage, parseLeadReply, UNDERSTANDING_FIRST } from '../protocol/leadSchema.js';
33
33
  import { describePlan, planFrom } from './planMode.js';
34
+ import { chosenSaid } from './chosenAnswers.js';
34
35
  import { closeLedger, describeLedger, nextLedger } from './leadLedger.js';
35
36
  import { classifySubtaskEnd, describeAttempts, FAILURE_WORDS, retryMessage, retryPlan, sanitizedReason, sideEffectsOf, stepFacts, stepsOf } from './subtaskRetry.js';
36
37
  import { ACTOR_WORDS, applySessionModel, enterSessionConversation, holdsWhilePaused, limitsMessageLength, redactsMessages, runTask, Sink, speakFor, StoppedSend } from './taskRunner.js';
@@ -159,8 +160,10 @@ export function leadPlanRevise(comment, version) {
159
160
  ].join('\n');
160
161
  }
161
162
  /** The operator's answer to the lead's question. */
162
- export function operatorAnswerMessage(answer, left) {
163
- return ['The operator answers your question:', '', answer.trim(), '', `Go on in the lead's format. Subtasks left: ${left}.`].join('\n');
163
+ export function operatorAnswerMessage(answer, left, many) {
164
+ // A question of several answers (2026-11-02): the ones chosen, one a line, and what was written besides.
165
+ const said = many ? ['The operator answered your question, ' + chosenSaid(many)] : ['The operator answers your question:', '', answer.trim()];
166
+ return [...said, '', `Go on in the lead's format. Subtasks left: ${left}.`].join('\n');
164
167
  }
165
168
  /** Nobody can answer the lead's question (a run with no page to ask on). */
166
169
  export const NOBODY_TO_ASK = 'Nobody can answer a question in this run: decide it yourself, the way that keeps the most options open, say the assumption in "notes", and go on.';
@@ -236,6 +239,8 @@ export async function runLeadTask(transport, session, task, deps) {
236
239
  signal,
237
240
  onGap: (ms) => sink.event('pacing-gap', { ms, lead: true }, `the next message to the lead waits ${Math.ceil(ms / 1000)} s: Settings ask for a pause between messages`),
238
241
  });
242
+ // The pauses as Settings have them when one is saved while the lead works (2026-11-03); the worker's task says the rest.
243
+ const unlive = deps.live?.onChange(() => pacer.retune({ enabled: cfg.pacing.enabled, settleMs: cfg.pacing.settleMs, maxMessagesPerHour: cfg.pacing.maxMessagesPerHour, gapMs: gapFrom(cfg.pacing) })) ?? (() => undefined);
239
244
  let limitHit;
240
245
  /*
241
246
  * Paused (see `Hold`): the lead's next message waits, as the worker's do in `runTask`. True when the run was stopped
@@ -254,7 +259,9 @@ export async function runLeadTask(transport, session, task, deps) {
254
259
  };
255
260
  // No message to the lead longer than Settings allow as text: the rest goes attached (2026-10-22).
256
261
  const leadChat = redactsMessages(limitsMessageLength(holdsWhilePaused(transport, holdHere), {
257
- max: cfg.limits.maxMessageChars,
262
+ get max() {
263
+ return cfg.limits.maxMessageChars;
264
+ },
258
265
  dir: log.path('messages'),
259
266
  onLong: ({ chars, max, file }) => sink.event('message-long', { chars, max, file, lead: true }, `a message to the lead of ${chars} characters is over the ${max} sent as text: its beginning is sent, the whole of it attached as ${file}`, 'warn'),
260
267
  }), {
@@ -337,6 +344,7 @@ export async function runLeadTask(transport, session, task, deps) {
337
344
  });
338
345
  await record(`TASK ${status.toUpperCase()}`, [summary ?? '', reason ? `Reason: ${reason}` : ''].filter(Boolean).join('\n\n') || '(no details)');
339
346
  sink.event('task-finished', { status, reason, iterations: lead.rounds.length, subtasks: lead.subtasks, lead: true }, `task "${task.title}" ${status}${reason ? `: ${reason}` : ''}`);
347
+ unlive();
340
348
  await log.close();
341
349
  return { status, iterations: lead.rounds.length, summary, reason };
342
350
  };
@@ -433,9 +441,16 @@ export async function runLeadTask(transport, session, task, deps) {
433
441
  * many times more, so far apart. Only for two chats.
434
442
  */
435
443
  const retrying = {
436
- mode: (cfg.limits.subtaskRetryMode ?? 'ask'),
437
- maxAttempts: 1 + Math.max(0, Math.min(3, cfg.limits.subtaskRetries ?? 2)),
438
- waitMs: Math.max(0, cfg.limits.subtaskRetryWaitSec ?? 15) * 1000,
444
+ // As Settings have them when a subtask is tried again (2026-11-03: a save takes effect at once).
445
+ get mode() {
446
+ return (cfg.limits.subtaskRetryMode ?? 'ask');
447
+ },
448
+ get maxAttempts() {
449
+ return 1 + Math.max(0, Math.min(3, cfg.limits.subtaskRetries ?? 2));
450
+ },
451
+ get waitMs() {
452
+ return Math.max(0, cfg.limits.subtaskRetryWaitSec ?? 15) * 1000;
453
+ },
439
454
  };
440
455
  /** A pause the run's Stop ends. */
441
456
  const pauseFor = (ms) => new Promise((resolve) => {
@@ -741,37 +756,37 @@ export async function runLeadTask(transport, session, task, deps) {
741
756
  else {
742
757
  markdown = await tell(assignment);
743
758
  }
744
- const maxFormat = Math.max(0, cfg.limits.maxFormatRetries ?? 2);
759
+ const maxFormat = () => Math.max(0, cfg.limits.maxFormatRetries ?? 2);
745
760
  let formatRetries = 0;
746
761
  // A message carried on was restated when it began: its first reply now need not do it again.
747
762
  let understood = carryingOn;
748
763
  let planVersion = 0;
749
764
  let revisions = [];
750
- const maxRounds = Math.max(1, cfg.limits.maxIterations);
765
+ const maxRounds = () => Math.max(1, cfg.limits.maxIterations);
751
766
  for (;;) {
752
767
  if (signal?.aborted)
753
768
  return await finish('aborted', 'stopped by the operator');
754
- if (lead.rounds.length >= maxRounds) {
755
- limitHit = { setting: 'maxIterations', value: maxRounds };
756
- return await finish('limit-reached', `maxIterations (${maxRounds}) reached: the lead's replies`);
769
+ if (lead.rounds.length >= maxRounds()) {
770
+ limitHit = { setting: 'maxIterations', value: maxRounds() };
771
+ return await finish('limit-reached', `maxIterations (${maxRounds()}) reached: the lead's replies`);
757
772
  }
758
773
  const parsed = parseLeadReply(markdown);
759
774
  if (!parsed.ok) {
760
775
  formatRetries += 1;
761
- if (formatRetries > maxFormat) {
762
- limitHit = { setting: 'maxFormatRetries', value: maxFormat };
763
- return await finish('limit-reached', `maxFormatRetries (${maxFormat}) reached: the lead's replies did not match its format (${parsed.detail})`);
776
+ if (formatRetries > maxFormat()) {
777
+ limitHit = { setting: 'maxFormatRetries', value: maxFormat() };
778
+ return await finish('limit-reached', `maxFormatRetries (${maxFormat()}) reached: the lead's replies did not match its format (${parsed.detail})`);
764
779
  }
765
- sink.event('lead-format-retry', { reason: parsed.reason, detail: parsed.detail, retry: formatRetries }, `the lead's reply did not match its format, asked again (${formatRetries} of ${maxFormat})`, 'warn');
766
- markdown = await tell(leadFormatErrorMessage(parsed, formatRetries, maxFormat));
780
+ sink.event('lead-format-retry', { reason: parsed.reason, detail: parsed.detail, retry: formatRetries }, `the lead's reply did not match its format, asked again (${formatRetries} of ${maxFormat()})`, 'warn');
781
+ markdown = await tell(leadFormatErrorMessage(parsed, formatRetries, maxFormat()));
767
782
  continue;
768
783
  }
769
784
  const r = parsed.reply;
770
785
  if (!understood && !r.understanding) {
771
786
  formatRetries += 1;
772
- if (formatRetries > maxFormat) {
773
- limitHit = { setting: 'maxFormatRetries', value: maxFormat };
774
- return await finish('limit-reached', `maxFormatRetries (${maxFormat}) reached: the lead did not restate the assignment`);
787
+ if (formatRetries > maxFormat()) {
788
+ limitHit = { setting: 'maxFormatRetries', value: maxFormat() };
789
+ return await finish('limit-reached', `maxFormatRetries (${maxFormat()}) reached: the lead did not restate the assignment`);
775
790
  }
776
791
  markdown = await tell(UNDERSTANDING_FIRST);
777
792
  continue;
@@ -845,7 +860,7 @@ export async function runLeadTask(transport, session, task, deps) {
845
860
  break;
846
861
  }
847
862
  case 'ask': {
848
- round.question = { text: r.question, ...(r.why ? { why: r.why } : {}), ...(r.options.length > 0 ? { options: r.options } : {}) };
863
+ round.question = { text: r.question, ...(r.why ? { why: r.why } : {}), ...(r.options.length > 0 ? { options: r.options } : {}), ...(r.multiple ? { multiple: true } : {}) };
849
864
  await saveLead();
850
865
  /*
851
866
  * Settings agree with what the bot proposes (2026-10-23): the lead's recommended answer, its first, is taken
@@ -865,14 +880,16 @@ export async function runLeadTask(transport, session, task, deps) {
865
880
  break;
866
881
  }
867
882
  sink.event('lead-question', { round: round.n, question: r.question }, `the lead asks the operator: ${r.question}`, 'warn');
868
- const got = await deps.askQuestion({ sessionId: session.id, taskId: task.id, question: r.question, ...(r.why ? { why: r.why } : {}), options: r.options, actor: 'lead' });
883
+ const got = await deps.askQuestion({ sessionId: session.id, taskId: task.id, question: r.question, ...(r.why ? { why: r.why } : {}), options: r.options, ...(r.multiple ? { multiple: true } : {}), actor: 'lead' });
869
884
  if (got === 'stop' || signal?.aborted)
870
885
  return await finish('aborted', 'the operator stopped the task at the lead\'s question');
871
886
  round.question.answer = got.answer;
887
+ if (got.chosen)
888
+ round.question.chosen = got.chosen;
872
889
  round.question.at = new Date().toISOString();
873
890
  await saveLead();
874
891
  sink.event('lead-question-answered', { round: round.n }, 'the operator answered the lead');
875
- markdown = await tell(operatorAnswerMessage(got.answer, limit - lead.subtasks));
892
+ markdown = await tell(operatorAnswerMessage(got.answer, limit - lead.subtasks, got.chosen ? { chosen: got.chosen, ...(got.written ? { written: got.written } : {}) } : undefined));
876
893
  break;
877
894
  }
878
895
  case 'done': {