copilot-operator 0.1.84 → 0.1.88

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 (66) hide show
  1. package/dist/src/api/operator.controller.js +113 -0
  2. package/dist/src/api/operator.service.js +329 -32
  3. package/dist/src/config/schema.js +32 -0
  4. package/dist/src/orchestrator/cardText.js +91 -0
  5. package/dist/src/orchestrator/kerriganRunner.js +914 -0
  6. package/dist/src/orchestrator/leadRunner.js +25 -15
  7. package/dist/src/orchestrator/planMode.js +6 -4
  8. package/dist/src/orchestrator/taskRunner.js +93 -40
  9. package/dist/src/plan/kerrigan.js +109 -4
  10. package/dist/src/plan/systemGuide.js +227 -4
  11. package/dist/src/protocol/kerriganSchema.js +175 -0
  12. package/dist/src/session/compose.js +5 -1
  13. package/dist/src/session/store.js +9 -0
  14. package/dist/src/transport/chatTransport.js +6 -2
  15. package/dist/src/transport/copilotTransport.js +226 -11
  16. package/dist/src/transport/keptWindow.js +247 -0
  17. package/dist/src/transport/locators.js +14 -4
  18. package/dist/src/vcs/git.js +72 -2
  19. package/dist/src/vcs/operatorGit.js +409 -0
  20. package/dist/web/404.html +2 -2
  21. package/dist/web/_next/static/chunks/1077.26ca37faa3726fff.js +1 -0
  22. package/dist/web/_next/static/chunks/1548.f5790cd11a91309f.js +1 -0
  23. package/dist/web/_next/static/chunks/2163.aa9d9b82fcde6caa.js +1 -0
  24. package/dist/web/_next/static/chunks/714.b7dbce98ba0b59a8.js +1 -0
  25. package/dist/web/_next/static/chunks/7220.0ca53eefec5d01ea.js +1 -0
  26. package/dist/web/_next/static/chunks/7921-8f6503aba840928a.js +1 -0
  27. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +1 -0
  28. package/dist/web/_next/static/chunks/8584.9f3b058a8f67d3d7.js +1 -0
  29. package/dist/web/_next/static/chunks/9067.107f6164157e0aa1.js +1 -0
  30. package/dist/web/_next/static/chunks/9747.984a86f70f9cd973.js +1 -0
  31. package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +1 -0
  32. package/dist/web/_next/static/chunks/app/page-b71841852e6b9ff5.js +1 -0
  33. package/dist/web/_next/static/chunks/app/settings/page-95069cb94d79e909.js +1 -0
  34. package/dist/web/_next/static/chunks/webpack-c015bbeb103c0856.js +1 -0
  35. package/dist/web/_next/static/css/0c5d6d5914aa3824.css +1 -0
  36. package/dist/web/defaults.html +2 -2
  37. package/dist/web/defaults.txt +8 -8
  38. package/dist/web/index.html +3 -3
  39. package/dist/web/index.txt +9 -9
  40. package/dist/web/queue.html +2 -2
  41. package/dist/web/queue.txt +9 -9
  42. package/dist/web/settings.html +2 -2
  43. package/dist/web/settings.txt +9 -9
  44. package/dist/web/system.html +2 -2
  45. package/dist/web/system.txt +9 -9
  46. package/package.json +176 -173
  47. package/prompts/kerrigan1.md +169 -0
  48. package/prompts/lead1.md +4 -1
  49. package/prompts/level1.md +8 -1
  50. package/dist/web/_next/static/chunks/1077.e0136d293069ccb8.js +0 -1
  51. package/dist/web/_next/static/chunks/1548.5cc0c57b00c2e44f.js +0 -1
  52. package/dist/web/_next/static/chunks/2163.2af0979126ae613a.js +0 -1
  53. package/dist/web/_next/static/chunks/714.410e2b61aa8c72b7.js +0 -1
  54. package/dist/web/_next/static/chunks/7220.2c4e5173a060769f.js +0 -1
  55. package/dist/web/_next/static/chunks/7921-3d21f385338afdf9.js +0 -1
  56. package/dist/web/_next/static/chunks/8124-1dc34be1646970a8.js +0 -1
  57. package/dist/web/_next/static/chunks/8584.61650a59d2bfa54d.js +0 -1
  58. package/dist/web/_next/static/chunks/9067.553056fc9b6cf80e.js +0 -1
  59. package/dist/web/_next/static/chunks/9747.d5826524bf4b714d.js +0 -1
  60. package/dist/web/_next/static/chunks/app/layout-b8a1e0075a48b025.js +0 -1
  61. package/dist/web/_next/static/chunks/app/page-13147b69cf336831.js +0 -1
  62. package/dist/web/_next/static/chunks/app/settings/page-e3909ef6c2d8e321.js +0 -1
  63. package/dist/web/_next/static/chunks/webpack-19a2d7161f23b21d.js +0 -1
  64. package/dist/web/_next/static/css/f152f27d6afce55c.css +0 -1
  65. /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → hLBBsG7Kn4vd0p_J-47BJ}/_buildManifest.js +0 -0
  66. /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → hLBBsG7Kn4vd0p_J-47BJ}/_ssgManifest.js +0 -0
@@ -21,6 +21,7 @@
21
21
  */
22
22
  import { appendFile, mkdir, writeFile } from 'node:fs/promises';
23
23
  import { isReplyTimeout, WindowClosed } from '../transport/chatTransport.js';
24
+ import { CLOSED_NOT_REOPENED } from '../transport/keptWindow.js';
24
25
  import { buildChatName, chatCode, savePointer } from '../transport/chatSession.js';
25
26
  import { RunLog } from '../log/runLog.js';
26
27
  import { gapFrom, Pacer } from '../util/pacing.js';
@@ -143,16 +144,20 @@ export function noSubtasksLeft(max) {
143
144
  /** The plan, as the lead is told it was approved. */
144
145
  export function leadPlanApproved(approval, left) {
145
146
  return [
146
- approval.by === 'operator' ? 'The operator approved your plan.' : 'Your plan is on record; the operator is not asked about plans in this conversation.',
147
- ...(approval.note?.trim() ? ['', 'With this from the operator, which wins where it and the plan disagree:', '', approval.note.trim()] : []),
147
+ approval.by === 'operator'
148
+ ? 'The operator approved your plan.'
149
+ : approval.by === 'kerrigan'
150
+ ? 'Kerrigan, who directs this work for the operator, approved your plan.'
151
+ : 'Your plan is on record; the operator is not asked about plans in this conversation.',
152
+ ...(approval.note?.trim() ? ['', `With this from ${approval.by === 'kerrigan' ? 'her' : 'the operator'}, which wins where it and the plan disagree:`, '', approval.note.trim()] : []),
148
153
  '',
149
154
  `Carry it out now: give the worker the first subtask of it (status "delegate"). Subtasks left: ${left}.`,
150
155
  ].join('\n');
151
156
  }
152
- /** The operator asked the lead for another plan. */
153
- export function leadPlanRevise(comment, version) {
157
+ /** The operator — or Kerrigan in their place (2026-11-12) — asked the lead for another plan. */
158
+ export function leadPlanRevise(comment, version, byKerrigan = false) {
154
159
  return [
155
- `The operator read version ${version} of your plan and asks for another. What to change:`,
160
+ `${byKerrigan ? 'Kerrigan, who directs this work for the operator,' : 'The operator'} read version ${version} of your plan and asks for another. What to change:`,
156
161
  '',
157
162
  comment.trim(),
158
163
  '',
@@ -160,9 +165,10 @@ export function leadPlanRevise(comment, version) {
160
165
  ].join('\n');
161
166
  }
162
167
  /** The operator's answer to the lead's question. */
163
- export function operatorAnswerMessage(answer, left, many) {
168
+ export function operatorAnswerMessage(answer, left, many, byKerrigan = false) {
164
169
  // 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()];
170
+ const who = byKerrigan ? 'Kerrigan, who directs this work for the operator,' : 'The operator';
171
+ const said = many ? [`${who} answered your question, ` + chosenSaid(many)] : [`${who} answers your question:`, '', answer.trim()];
166
172
  return [...said, '', `Go on in the lead's format. Subtasks left: ${left}.`].join('\n');
167
173
  }
168
174
  /** Nobody can answer the lead's question (a run with no page to ask on). */
@@ -355,7 +361,7 @@ export async function runLeadTask(transport, session, task, deps) {
355
361
  const id = now?.lead?.workerSessionId;
356
362
  const existing = id ? await store.getSession(id) : null;
357
363
  if (existing) {
358
- deps.onWorker?.(existing.id);
364
+ deps.onWorker?.(existing.id, session.id);
359
365
  lead.workerSessionId = existing.id;
360
366
  return existing;
361
367
  }
@@ -399,7 +405,7 @@ export async function runLeadTask(transport, session, task, deps) {
399
405
  s.lead = { ...(s.lead ?? {}), workerSessionId: worker.id };
400
406
  });
401
407
  lead.workerSessionId = worker.id;
402
- deps.onWorker?.(worker.id);
408
+ deps.onWorker?.(worker.id, session.id);
403
409
  sink.event('worker-made', { workerSessionId: worker.id }, 'a worker for the lead\'s subtasks');
404
410
  return worker;
405
411
  };
@@ -845,10 +851,10 @@ export async function runLeadTask(transport, session, task, deps) {
845
851
  if (t.plan)
846
852
  t.plan.revisions = revisions;
847
853
  });
848
- markdown = await tell(leadPlanRevise(answer.note ?? '', planVersion));
854
+ markdown = await tell(leadPlanRevise(answer.note ?? '', planVersion, answer.by === 'kerrigan'));
849
855
  break;
850
856
  }
851
- approved = { by: 'operator', at: new Date().toISOString(), ...(answer.note?.trim() ? { note: answer.note.trim() } : {}) };
857
+ approved = { by: answer.by === 'kerrigan' ? 'kerrigan' : 'operator', at: new Date().toISOString(), ...(answer.note?.trim() ? { note: answer.note.trim() } : {}) };
852
858
  }
853
859
  else {
854
860
  approved = { by: 'auto', at: new Date().toISOString(), why: 'plans are not put to the operator in this conversation' };
@@ -867,7 +873,8 @@ export async function runLeadTask(transport, session, task, deps) {
867
873
  * Settings agree with what the bot proposes (2026-10-23): the lead's recommended answer, its first, is taken
868
874
  * and said; with no answers given, it is told to go on as it proposes.
869
875
  */
870
- if (cfg.execution.questions === 'agree') {
876
+ // Kerrigan directs (2026-11-12): the question goes to its card, which she answers, whatever Settings say.
877
+ if (cfg.execution.questions === 'agree' && !deps.directed) {
871
878
  const agreed = r.options[0] ?? 'Go on as you propose.';
872
879
  round.question.answer = agreed;
873
880
  round.question.at = new Date().toISOString();
@@ -887,10 +894,12 @@ export async function runLeadTask(transport, session, task, deps) {
887
894
  round.question.answer = got.answer;
888
895
  if (got.chosen)
889
896
  round.question.chosen = got.chosen;
897
+ if (got.by === 'kerrigan')
898
+ round.question.by = 'kerrigan';
890
899
  round.question.at = new Date().toISOString();
891
900
  await saveLead();
892
- sink.event('lead-question-answered', { round: round.n }, 'the operator answered the lead');
893
- markdown = await tell(operatorAnswerMessage(got.answer, limit - lead.subtasks, got.chosen ? { chosen: got.chosen, ...(got.written ? { written: got.written } : {}) } : undefined));
901
+ sink.event('lead-question-answered', { round: round.n, ...(got.by ? { by: got.by } : {}) }, got.by === 'kerrigan' ? 'Kerrigan answered the lead' : 'the operator answered the lead');
902
+ markdown = await tell(operatorAnswerMessage(got.answer, limit - lead.subtasks, got.chosen ? { chosen: got.chosen, ...(got.written ? { written: got.written } : {}) } : undefined, got.by === 'kerrigan'));
894
903
  break;
895
904
  }
896
905
  case 'done': {
@@ -914,8 +923,9 @@ export async function runLeadTask(transport, session, task, deps) {
914
923
  limitHit = { setting: 'replyTimeoutSec', value: e.seconds };
915
924
  return await finish('limit-reached', `replyTimeoutSec (${e.seconds}) reached: ${message}`);
916
925
  }
926
+ // Why, as the kept window says it (2026-11-13): not opened again by Settings, past the times allowed, or not found.
917
927
  if (e instanceof WindowClosed || transport.closedOutside())
918
- return await finish('aborted', 'the browser window was closed; nothing more was sent');
928
+ return await finish('aborted', e instanceof WindowClosed ? e.message : CLOSED_NOT_REOPENED);
919
929
  sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
920
930
  return await finish('failed', message);
921
931
  }
@@ -54,10 +54,12 @@ export function describePlan(plan) {
54
54
  export function planApprovedMessage(approval) {
55
55
  const by = approval.by === 'operator'
56
56
  ? 'The operator approved your plan.'
57
- : `Your plan is approved by the runner${approval.why ? ` (${approval.why})` : ''}.`;
57
+ : approval.by === 'kerrigan'
58
+ ? 'Kerrigan, who directs this work for the operator, approved your plan.'
59
+ : `Your plan is approved by the runner${approval.why ? ` (${approval.why})` : ''}.`;
58
60
  return [
59
61
  by,
60
- ...(approval.note?.trim() ? ['', 'With this from the operator, which wins where it and the plan disagree:', '', approval.note.trim()] : []),
62
+ ...(approval.note?.trim() ? ['', `With this from ${approval.by === 'kerrigan' ? 'her' : 'the operator'}, which wins where it and the plan disagree:`, '', approval.note.trim()] : []),
61
63
  '',
62
64
  'Carry it out now: reply with status "continue" and the steps of its first stage. Keep to the plan; when it',
63
65
  'has to change, say so in `notes` and why — a change the plan did not foresee is declared, not hidden.',
@@ -65,9 +67,9 @@ export function planApprovedMessage(approval) {
65
67
  ].join('\n');
66
68
  }
67
69
  /** The operator asked for another plan. */
68
- export function planReviseMessage(comment, version) {
70
+ export function planReviseMessage(comment, version, byKerrigan = false) {
69
71
  return [
70
- `The operator read version ${version} of your plan and asks for another. What to change:`,
72
+ `${byKerrigan ? 'Kerrigan, who directs this work for the operator,' : 'The operator'} read version ${version} of your plan and asks for another. What to change:`,
71
73
  '',
72
74
  comment.trim(),
73
75
  '',
@@ -15,6 +15,7 @@ import { readFile, mkdir, writeFile, appendFile } from 'node:fs/promises';
15
15
  import { basename, join, resolve } from 'node:path';
16
16
  import { buttonShows, normModel } from '../transport/modelMatch.js';
17
17
  import { ChatLost, createTransport, isReplyTimeout, WindowClosed } from '../transport/chatTransport.js';
18
+ import { CLOSED_NOT_REOPENED } from '../transport/keptWindow.js';
18
19
  import { buildChatName, chatCode, loadPointer, savePointer } from '../transport/chatSession.js';
19
20
  import { parseReply, formatErrorMessage, findLikelyDamage, damageGuidance } from '../protocol/parser.js';
20
21
  import { resolveDeviations, describeDeviations, mergeDisputes, describeDisputes } from '../protocol/replySchema.js';
@@ -63,6 +64,7 @@ import { protectInputs, inputsMessage, inputsAtCommit, untrackedInputs, blobOfFi
63
64
  import { artifactPatterns, artifactState, keepArtifacts } from '../vcs/artifacts.js';
64
65
  import { exportMachine, writeAttemptRecord } from '../session/exports.js';
65
66
  import { runLeadTask } from './leadRunner.js';
67
+ import { runKerriganTask } from './kerriganRunner.js';
66
68
  /**
67
69
  * Causes no conversation can change: the task contradicts itself, the machine lacks what a step needs,
68
70
  * a check can never run. A fresh chat is no cure for these, and retrying them in one only repeats the
@@ -99,7 +101,8 @@ async function followPageModels(which, wanted, result, session, store, hooks, fr
99
101
  else {
100
102
  await hooks?.renamedDefault?.(which, wanted, result.matched).catch(() => undefined);
101
103
  }
102
- return `"${wanted}" is no longer offered under that name; the page offers it as "${result.matched}", which was chosen, and ${own ? "the session's" : 'Settings\''} ${which === 'model' ? 'model' : 'review model'} now says so`;
104
+ const what = which === 'review' ? 'review model' : own ? 'model' : which === 'lead' ? 'model for the lead' : which === 'kerrigan' ? 'model for Kerrigan' : 'model';
105
+ return `"${wanted}" is no longer offered under that name; the page offers it as "${result.matched}", which was chosen, and ${own ? "the session's" : 'Settings\''} ${what} now says so`;
103
106
  }
104
107
  /** Why a task that was reported as done is being closed as failed. */
105
108
  function checksFailedReason(outcomes) {
@@ -441,6 +444,10 @@ const speakers = new WeakMap();
441
444
  * (2026-10-19), which goes from one conversation to the next and belongs to none of them: a batch's window is opened
442
445
  * under the batch, whose log is the run's, but the chat's is opened by whichever message came first.
443
446
  */
447
+ /** Whose session the window speaks for now (see `speakFor`), to give it back after a turn of another's (2026-11-12). */
448
+ export function spokenFor(transport) {
449
+ return speakers.get(transport)?.id;
450
+ }
444
451
  export function speakFor(transport, sessionId, opts = {}) {
445
452
  const speaker = speakers.get(transport);
446
453
  if (!speaker)
@@ -477,17 +484,26 @@ signal) {
477
484
  'error-banner': 'The chat reported a transient error; reloading the page.',
478
485
  'reply-files-ignored': 'The reply came with a file attached. It was not downloaded and will not be run: the runner takes only the text of a reply.',
479
486
  'model-menu-stuck': 'The model menu would not close — Escape, the menu button and a click outside all left it open. Close it in the Edge window; the run goes on.',
480
- 'window-closed': 'The Edge window was closed. A run in it stops; the next message opens a new one.',
487
+ 'window-closed': 'The Edge window was closed. While a message is at work it is opened again on its conversation, as many times as ' +
488
+ 'Settings allow (limits.reopenWindow); between messages, the next message opens a new one.',
489
+ // Opened again under the work (2026-11-13): see transport/keptWindow.ts.
490
+ 'window-reopening': `Opening Edge again on this conversation (${String(detail?.time ?? '?')} of ${String(detail?.of ?? '?')} for this message), so the work goes on there.`,
491
+ 'window-reopened': 'Back on this conversation in a new Edge window; the work goes on from where it was.',
492
+ 'window-not-reopened': `The window was not opened again: ${String(detail?.reason ?? '')}`,
493
+ 'reply-asked-again': 'The chat was writing its answer when the window was closed; it was asked to send that answer again.',
494
+ 'message-sent-again': 'The window was closed while a message was being sent; it was sent again, saying it is a copy.',
481
495
  // The window left its conversation while the work waited (2026-11-09): put back before anything is sent.
482
496
  'chat-left': `The Copilot window is no longer on this conversation (it shows ${String(detail?.found ?? 'another page')}). Going back to it before anything is sent.`,
483
497
  'chat-returned': `Back on this conversation${detail?.signedIn ? ', after the sign-in' : ''}${detail?.by === 'name' ? ', found by its name in the sidebar' : ''}. The work goes on there.`,
484
498
  'chat-lost': 'The conversation could not be opened again, by its address or by its name. Nothing was sent, and nothing went into another chat.',
499
+ // Copilot showed another of its pages, its home page, instead of the chat (2026-11-17): the chat opened from it.
500
+ 'chat-page-elsewhere': `Copilot showed its page ${String(detail?.found ?? '')} instead of the chat; opening the chat ${detail?.by === 'link' ? "by the page's own link to it" : `at ${String(detail?.to ?? '')}`}.`,
485
501
  };
486
502
  for (const id of new Set(speaker.alone ? [speaker.id] : [speaker.id, sessionId])) {
487
503
  bus.publish({
488
504
  sessionId: id,
489
505
  type: `browser:${event}`,
490
- level: event === 'chat-lost' ? 'error' : event === 'verification-required' || event === 'reply-files-ignored' || event === 'model-menu-stuck' || event === 'chat-left' ? 'warn' : 'info',
506
+ level: event === 'chat-lost' ? 'error' : ['verification-required', 'reply-files-ignored', 'model-menu-stuck', 'chat-left', 'window-closed', 'window-not-reopened', 'reply-asked-again', 'message-sent-again'].includes(event) ? 'warn' : 'info',
491
507
  // An event with no sentence of its own is named, not said as "undefined".
492
508
  message: spoken[event] ?? event.replace(/-/g, ' '),
493
509
  data: detail,
@@ -654,7 +670,7 @@ export function roleOf(session) {
654
670
  return session.workerOf ? { role: 'worker' } : session.lead ? { role: 'lead' } : {};
655
671
  }
656
672
  /** Who is at work, as the run's transcript and the Output panel say it. */
657
- export const ACTOR_WORDS = { plan: 'the chat writing its plan', lead: 'the lead', worker: 'the worker', review: 'the reviewer' };
673
+ export const ACTOR_WORDS = { plan: 'the chat writing its plan', lead: 'the lead', worker: 'the worker', review: 'the reviewer', kerrigan: 'Kerrigan' };
658
674
  /**
659
675
  * Who a session's conversation is, for a card it raises before its first message (2026-10-22): the lead or the worker
660
676
  * of two chats, the chat that writes its plan first in plan mode, or else the chat that does the work.
@@ -662,6 +678,8 @@ export const ACTOR_WORDS = { plan: 'the chat writing its plan', lead: 'the lead'
662
678
  export function actorOfSession(session, cfg) {
663
679
  if (session.workerOf)
664
680
  return 'worker';
681
+ if (session.kerrigan)
682
+ return 'kerrigan';
665
683
  if (session.lead)
666
684
  return 'lead';
667
685
  return (session.planMode ?? cfg.execution?.planMode ?? 'off') !== 'off' ? 'plan' : 'worker';
@@ -695,28 +713,25 @@ export async function openSessionTransport(cfg, session, bus, runsDir, signal) {
695
713
  }
696
714
  return transport;
697
715
  }
716
+ /** Which part of Settings a session's conversation takes its model from. */
717
+ export function modelPartOf(session) {
718
+ return session.kerrigan ? 'kerrigan' : session.lead ? 'lead' : 'model';
719
+ }
698
720
  /**
699
- * Puts the conversation on the model the session asks for, once per run.
700
- *
701
- * Applied here rather than per task because the picker belongs to the conversation, and a
702
- * failure is reported rather than raised: a model that is out of quota or has been withdrawn
703
- * should not throw away a queue of tasks. The run continues on whatever the chat is actually
704
- * set to, and the session records that, so the register shows which model did the work rather
705
- * than which one was asked for.
706
- */
707
- /**
708
- * The models a session runs on: its own, or else the ones chosen in Settings at this moment.
709
- * A session gets a model of its own from the plan or from its own picker; one that has none
710
- * follows Settings, so a model chosen there after the session was made still reaches it.
711
- */
712
- /**
713
- * The models a session runs on, and where each came from.
714
- *
715
- * The operator's choice on the session's page or the run panel first; then Settings; the plan's last.
716
- * Settings used to come after any model the session held, and a plan imported with a "model" — written
717
- * by another chat, often a model the picker no longer had — overrode what the operator chose in Settings
718
- * on every run (operator's rule, 2026-10-06: what is set in Settings outranks the same thing in the JSON).
721
+ * Settings' model for a part, with what stands in for it when none is chosen there: Kerrigan's, else the lead's; the
722
+ * lead's, else the worker's. `setting` names the one the name comes from, so a model the page renamed is followed there.
719
723
  */
724
+ export function settingsModelOf(part, copilot) {
725
+ const own = (x) => (x ?? '').trim();
726
+ if (part === 'kerrigan' && own(copilot.defaultKerriganModel))
727
+ return { model: own(copilot.defaultKerriganModel), setting: 'kerrigan' };
728
+ if (part !== 'model' && own(copilot.defaultLeadModel))
729
+ return { model: own(copilot.defaultLeadModel), setting: 'lead' };
730
+ return { model: own(copilot.defaultModel), setting: 'model' };
731
+ }
732
+ function settingsModelFor(session, cfg) {
733
+ return settingsModelOf(modelPartOf(session), cfg.copilot).model;
734
+ }
720
735
  export function effectiveModels(session, cfg) {
721
736
  const pick = (own, source, settings) => own && source === 'operator' ? [own, 'session'] : settings ? [settings, 'settings'] : own ? [own, 'plan'] : ['', 'none'];
722
737
  // Set by hand in the Copilot window: no name is asked for, neither the session's nor the one in Settings.
@@ -724,7 +739,11 @@ export function effectiveModels(session, cfg) {
724
739
  * Settings' model for the conversation's part (2026-10-23): the lead's for the lead of two chats — the worker's when
725
740
  * none is chosen for the lead, as before there were two — else the worker's.
726
741
  */
727
- const fromSettings = ((session.lead ? cfg.copilot.defaultLeadModel?.trim() || cfg.copilot.defaultModel : cfg.copilot.defaultModel) ?? '').trim();
742
+ /*
743
+ * Kerrigan's conversation (2026-11-13): Settings' model for Kerrigan; none chosen there, the lead's, as it was from
744
+ * 2026-11-12 when she directed as the lead does; none for the lead either, the worker's.
745
+ */
746
+ const fromSettings = settingsModelFor(session, cfg);
728
747
  const [model, modelFrom] = session.manualModel ? ['', 'none'] : pick((session.model ?? '').trim(), session.modelSource, fromSettings);
729
748
  const [reviewModel, reviewModelFrom] = pick((session.review?.model ?? '').trim(), session.reviewModelSource, (cfg.copilot.defaultReviewModel ?? '').trim());
730
749
  return { model, reviewModel, modelFrom, reviewModelFrom };
@@ -735,8 +754,12 @@ export function effectiveModels(session, cfg) {
735
754
  * model and has none from Settings either — its picker shows "by hand" for that, and what it shows is what happens.
736
755
  */
737
756
  export function modelByHand(session, cfg) {
738
- // Settings' "by hand" for the conversation's part (2026-10-23): the lead's has its own, absent as the worker's.
739
- const settingsSay = session.lead ? (cfg.copilot.leadManualModel ?? cfg.copilot.manualModel) : cfg.copilot.manualModel;
757
+ /*
758
+ * Settings' "by hand" for the conversation's part (2026-10-23): the lead's has its own, absent as the worker's.
759
+ * Kerrigan's has her own since 2026-11-13, absent as the lead's.
760
+ */
761
+ const lead = cfg.copilot.leadManualModel ?? cfg.copilot.manualModel;
762
+ const settingsSay = session.kerrigan ? (cfg.copilot.kerriganManualModel ?? lead) : session.lead ? lead : cfg.copilot.manualModel;
740
763
  if (settingsSay || session.manualModel)
741
764
  return true;
742
765
  return session.kind === 'chat' && !effectiveModels(session, cfg).model;
@@ -820,7 +843,8 @@ signal) {
820
843
  const hand = await withOperatorHand(transport, wanted, result, hooks, session.id, bus, false, asks);
821
844
  result = hand.result;
822
845
  const goOnAsItIs = hand.goOnAsItIs;
823
- const renamed = await followPageModels(session.lead ? 'lead' : 'model', wanted, result, session, store, hooks, modelFrom);
846
+ // Followed in the setting the name came from: a part with none of its own takes another's (see `settingsModelOf`).
847
+ const renamed = await followPageModels(settingsModelOf(modelPartOf(session), cfg.copilot).setting, wanted, result, session, store, hooks, modelFrom);
824
848
  if (renamed)
825
849
  bus.publish({ sessionId: session.id, type: 'model-renamed', level: 'warn', message: renamed, data: { asked: wanted, chosen: result.matched } });
826
850
  bus.publish({
@@ -2897,10 +2921,13 @@ export async function runTask(transport, session, task, deps) {
2897
2921
  if (reply.status === 'ask') {
2898
2922
  const question = (reply.question ?? '').trim();
2899
2923
  const options = reply.options;
2900
- const agree = cfg.execution.questions === 'agree' || !deps.askQuestion;
2924
+ // Kerrigan directs (2026-11-12): the question goes to its card, which she answers, whatever Settings say.
2925
+ const agree = (cfg.execution.questions === 'agree' && !deps.directed) || !deps.askQuestion;
2901
2926
  let answer = options[0].answer;
2902
2927
  // A question of several answers (2026-11-02): the ones the operator chose, and what they wrote besides.
2903
2928
  let many;
2929
+ // Answered by Kerrigan in the operator's place: no click of theirs, so no command runs by it unasked.
2930
+ let byKerrigan = false;
2904
2931
  if (agree) {
2905
2932
  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}`);
2906
2933
  }
@@ -2925,25 +2952,27 @@ export async function runTask(transport, session, task, deps) {
2925
2952
  if (got === 'stop' || signal?.aborted)
2926
2953
  return await finish('aborted', 'stopped by the operator at its question', undefined, lastMarkdown);
2927
2954
  answer = got.answer;
2955
+ byKerrigan = got.by === 'kerrigan';
2928
2956
  if (got.chosen)
2929
2957
  many = { chosen: got.chosen, ...(got.written ? { written: got.written } : {}) };
2930
- sink.event('question-answered', { question, answer, ...(many ? { chosen: many.chosen } : {}) }, `the operator answered: ${answer}`);
2958
+ sink.event('question-answered', { question, answer, ...(many ? { chosen: many.chosen } : {}), ...(byKerrigan ? { by: 'kerrigan' } : {}) }, `${byKerrigan ? 'Kerrigan answered' : 'the operator answered'}: ${answer}`);
2931
2959
  }
2932
2960
  await record('QUESTION', `${question}\n\nAnswer${agree ? ' (as the chat recommends)' : ''}: ${answer}`);
2933
2961
  const chosen = many ? undefined : options.find((o) => o.answer === answer);
2934
2962
  if (chosen?.run) {
2935
2963
  // Run as this reply's one step: through the step loop below, its output reported as any step's.
2936
- chosenRun = agree && deps.askQuestion === undefined ? null : chosen.run.trim();
2964
+ // Kerrigan's answer is no click of the operator's (2026-11-12): its command is asked about as any step is.
2965
+ chosenRun = (agree && deps.askQuestion === undefined) || byKerrigan ? null : chosen.run.trim();
2937
2966
  const mutable = reply;
2938
2967
  mutable.status = 'continue';
2939
2968
  mutable.steps = [{ id: 1, type: 'command', cmd: chosen.run, ...(chosen.shell ? { shell: chosen.shell } : {}) }];
2940
- runnerNotes.push(`${agree ? 'The runner took your recommended answer' : 'The operator answered your question'} ("${question}"): "${answer}". ` +
2969
+ runnerNotes.push(`${agree ? 'The runner took your recommended answer' : byKerrigan ? 'Kerrigan, who directs this work for the operator, answered your question' : 'The operator answered your question'} ("${question}"): "${answer}". ` +
2941
2970
  'The runner ran the command that answer carries — step 1 below, its output with it. Go on from there.');
2942
2971
  }
2943
2972
  else {
2944
2973
  const message = many
2945
- ? `The operator answered your question ("${question}"), ${chosenSaid(many)}\n\nGo on with the work from here, in the same format.`
2946
- : `${agree ? 'The runner took your recommended answer' : 'The operator answered your question'} ("${question}"): "${answer}".\n\n` +
2974
+ ? `${byKerrigan ? 'Kerrigan, who directs this work for the operator, answered your question' : 'The operator answered your question'} ("${question}"), ${chosenSaid(many)}\n\nGo on with the work from here, in the same format.`
2975
+ : `${agree ? 'The runner took your recommended answer' : byKerrigan ? 'Kerrigan, who directs this work for the operator, answered your question' : 'The operator answered your question'} ("${question}"): "${answer}".\n\n` +
2947
2976
  'Go on with the work from here, in the same format.';
2948
2977
  await record('ANSWER', message);
2949
2978
  await pacer.throttleSend();
@@ -3003,14 +3032,14 @@ export async function runTask(transport, session, task, deps) {
3003
3032
  if (t.plan)
3004
3033
  t.plan.revisions = [...planRevisions];
3005
3034
  });
3006
- sink.event('plan-revise', { version: planVersion, comment }, `the operator asked for another plan: ${comment}`);
3007
- message = planReviseMessage(comment, planVersion);
3035
+ sink.event('plan-revise', { version: planVersion, comment, ...(answer.by ? { by: answer.by } : {}) }, `${answer.by === 'kerrigan' ? 'Kerrigan' : 'the operator'} asked for another plan: ${comment}`);
3036
+ message = planReviseMessage(comment, planVersion, answer.by === 'kerrigan');
3008
3037
  }
3009
3038
  else {
3010
3039
  // Who approved it, and why the operator was not asked when they were not.
3011
3040
  const why = asks ? undefined : planMode === 'auto' ? 'plan mode approves plans automatically' : 'the run does not ask before each command';
3012
3041
  const approved = {
3013
- by: asks ? 'operator' : 'auto',
3042
+ by: asks ? (answer.by === 'kerrigan' ? 'kerrigan' : 'operator') : 'auto',
3014
3043
  at: new Date().toISOString(),
3015
3044
  ...(answer.note?.trim() ? { note: answer.note.trim() } : {}),
3016
3045
  ...(why ? { why } : {}),
@@ -3020,7 +3049,7 @@ export async function runTask(transport, session, task, deps) {
3020
3049
  t.plan.approved = approved;
3021
3050
  });
3022
3051
  planInForce = { ...plan, approved };
3023
- sink.event('plan-approved', { version: planVersion, by: approved.by, ...(approved.note ? { note: approved.note } : {}) }, `plan ${planVersion} approved ${asks ? 'by the operator' : `by the runner — ${why}`}${approved.note ? `, with a note` : ''}`);
3052
+ sink.event('plan-approved', { version: planVersion, by: approved.by, ...(approved.note ? { note: approved.note } : {}) }, `plan ${planVersion} approved ${asks ? (approved.by === 'kerrigan' ? 'by Kerrigan' : 'by the operator') : `by the runner — ${why}`}${approved.note ? `, with a note` : ''}`);
3024
3053
  planning = false;
3025
3054
  await actingNow('worker');
3026
3055
  message = planApprovedMessage(approved);
@@ -3545,8 +3574,10 @@ export async function runTask(transport, session, task, deps) {
3545
3574
  * Edge left a crash report, which says it was not them.
3546
3575
  */
3547
3576
  if (transport.closedOutside() && !(await transport.recentCrash().catch(() => null))) {
3548
- sink.event('window-closed', { error: message }, 'the browser window was closed; nothing more is sent', 'warn');
3549
- return await finish('aborted', 'the browser window was closed; nothing more was sent');
3577
+ // Why, as the kept window says it (2026-11-13): not opened again by Settings, past the times allowed, or not found.
3578
+ const why = e instanceof WindowClosed ? e.message : CLOSED_NOT_REOPENED;
3579
+ sink.event('window-closed', { error: message, reopened: transport.reopenedTimes?.() ?? 0 }, why, 'warn');
3580
+ return await finish('aborted', why);
3550
3581
  }
3551
3582
  sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
3552
3583
  await transport.dumpFailure(log.path('failures'), 'crash').catch(() => undefined);
@@ -3659,6 +3690,12 @@ export async function runSession(sessionId, deps) {
3659
3690
  let task = session.tasks.find((t) => t.id === queuedTask.id);
3660
3691
  if (!task || task.status !== 'queued')
3661
3692
  continue;
3693
+ /*
3694
+ * The window, closed under this message, is opened again on its conversation and the work goes on there (operator,
3695
+ * 2026-11-13: "if I close the browser by accident, carry the task on from where it got to"), up to the times
3696
+ * Settings allow for one message — its runs again in a fresh chat and on its own after a limit included.
3697
+ */
3698
+ chat.holdWindow?.(cfg.limits.reopenWindow ?? 3, deps.signal);
3662
3699
  /*
3663
3700
  * A task taken from the queue was started by the operator, never by the retry loop below, which
3664
3701
  * runs its own. A fresh-retry mark on it is left from a retry that was queued and never ran —
@@ -3678,6 +3715,20 @@ export async function runSession(sessionId, deps) {
3678
3715
  * subtasks (see `leadRunner.ts`). Not carried on or retried in a fresh chat here: the lead decides what to do when
3679
3716
  * a subtask falls short, and its own limits bound it.
3680
3717
  */
3718
+ /*
3719
+ * A message of a conversation Kerrigan directs (2026-11-12): she writes the messages for chats of their own and
3720
+ * answers their cards (see `kerriganRunner.ts`). Not carried on here: she decides what to do with a result.
3721
+ */
3722
+ if (session.kerrigan && session.kind === 'chat') {
3723
+ const led = await runKerriganTask(chat, session, task, deps);
3724
+ ran += 1;
3725
+ lastStatus = led.status;
3726
+ if (chat.closedOutside()) {
3727
+ bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed; the tasks after this one stay queued' });
3728
+ break;
3729
+ }
3730
+ continue;
3731
+ }
3681
3732
  if (session.lead && session.kind === 'chat') {
3682
3733
  const led = await runLeadTask(chat, session, task, deps);
3683
3734
  ran += 1;
@@ -3861,6 +3912,8 @@ export async function runSession(sessionId, deps) {
3861
3912
  }
3862
3913
  }
3863
3914
  finally {
3915
+ // No message at work: a window closed from now on is the next message's to open. One being opened again is let finish.
3916
+ await transport?.releaseWindow?.().catch(() => undefined);
3864
3917
  // A borrowed window belongs to whoever opened it and stays open for the next session.
3865
3918
  if (!borrowed) {
3866
3919
  // The chat's, still open, is kept for its next message; one the operator closed is let go of.