copilot-operator 0.1.93 → 0.1.96

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 (64) hide show
  1. package/README.md +640 -625
  2. package/dist/src/api/operator.controller.js +5 -1
  3. package/dist/src/api/operator.service.js +354 -66
  4. package/dist/src/config/live.js +12 -12
  5. package/dist/src/exec/readOnly.js +27 -2
  6. package/dist/src/orchestrator/kerriganRunner.js +20 -6
  7. package/dist/src/orchestrator/leadRunner.js +76 -23
  8. package/dist/src/orchestrator/review.js +6 -2
  9. package/dist/src/orchestrator/subtaskRetry.js +2 -1
  10. package/dist/src/orchestrator/taskRunner.js +89 -19
  11. package/dist/src/plan/kerrigan.js +263 -243
  12. package/dist/src/plan/systemGuide.js +130 -82
  13. package/dist/src/queue/queue.js +12 -0
  14. package/dist/src/queue/queueBranch.js +34 -9
  15. package/dist/src/session/compose.js +13 -0
  16. package/dist/src/session/locatorFailures.js +8 -5
  17. package/dist/src/session/store.js +9 -0
  18. package/dist/src/session/workspace.js +3 -2
  19. package/dist/src/transport/copilotTransport.js +103 -70
  20. package/dist/src/transport/keptWindow.js +17 -14
  21. package/dist/src/vcs/newBranch.js +69 -0
  22. package/dist/src/vcs/referenceGuard.js +16 -2
  23. package/dist/web/404.html +2 -2
  24. package/dist/web/_next/static/chunks/1024-214ded25b9048526.js +1 -0
  25. package/dist/web/_next/static/chunks/1077.161de82f740d47f0.js +1 -0
  26. package/dist/web/_next/static/chunks/1548.f2688468bf946e13.js +1 -0
  27. package/dist/web/_next/static/chunks/2163.b8ada3b7bde69f03.js +1 -0
  28. package/dist/web/_next/static/chunks/714.d1489788e598833b.js +1 -0
  29. package/dist/web/_next/static/chunks/7220.b85c8d105f394389.js +1 -0
  30. package/dist/web/_next/static/chunks/7921-00ebbcc6f65fbe35.js +1 -0
  31. package/dist/web/_next/static/chunks/8584.a678bfced1cea938.js +1 -0
  32. package/dist/web/_next/static/chunks/9067.6da03ae052877b19.js +1 -0
  33. package/dist/web/_next/static/chunks/9747.ba29e64e97e8a15b.js +1 -0
  34. package/dist/web/_next/static/chunks/app/{layout-1b7d13f7b2efd008.js → layout-2364903896c2c175.js} +1 -1
  35. package/dist/web/_next/static/chunks/app/{page-b71841852e6b9ff5.js → page-d031bf326e401246.js} +1 -1
  36. package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +1 -0
  37. package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +1 -0
  38. package/dist/web/_next/static/chunks/{webpack-33252b1a0a7d93ba.js → webpack-3f144d13be3516c2.js} +1 -1
  39. package/dist/web/_next/static/css/{6b92f118889ca88b.css → 523d11041085f836.css} +1 -1
  40. package/dist/web/defaults.html +2 -2
  41. package/dist/web/defaults.txt +8 -8
  42. package/dist/web/index.html +3 -3
  43. package/dist/web/index.txt +9 -9
  44. package/dist/web/queue.html +2 -2
  45. package/dist/web/queue.txt +9 -9
  46. package/dist/web/settings.html +2 -2
  47. package/dist/web/settings.txt +9 -9
  48. package/dist/web/system.html +2 -2
  49. package/dist/web/system.txt +9 -9
  50. package/package.json +2 -1
  51. package/dist/web/_next/static/chunks/1024-dee283a1ddf295bf.js +0 -1
  52. package/dist/web/_next/static/chunks/1077.626a11362f53d35c.js +0 -1
  53. package/dist/web/_next/static/chunks/1548.79f05ff765581b0a.js +0 -1
  54. package/dist/web/_next/static/chunks/2163.09f1212655504f3a.js +0 -1
  55. package/dist/web/_next/static/chunks/714.acea3698b6af7a61.js +0 -1
  56. package/dist/web/_next/static/chunks/7220.1eba10bd9d449cea.js +0 -1
  57. package/dist/web/_next/static/chunks/7921-29256ac683ea4bc5.js +0 -1
  58. package/dist/web/_next/static/chunks/8584.b5aac5354f124d4b.js +0 -1
  59. package/dist/web/_next/static/chunks/9067.177163495f3bd8fa.js +0 -1
  60. package/dist/web/_next/static/chunks/9747.5b9d763e89abc7e4.js +0 -1
  61. package/dist/web/_next/static/chunks/app/queue/page-7909ba7c9e3d4c2d.js +0 -1
  62. package/dist/web/_next/static/chunks/app/settings/page-c92548f9c6318962.js +0 -1
  63. /package/dist/web/_next/static/{ZrEcjGdZEXe66UUxUqine → kNfJ9jSwlboc-1sFBBfuI}/_buildManifest.js +0 -0
  64. /package/dist/web/_next/static/{ZrEcjGdZEXe66UUxUqine → kNfJ9jSwlboc-1sFBBfuI}/_ssgManifest.js +0 -0
@@ -457,7 +457,11 @@ export function speakFor(transport, sessionId, opts = {}) {
457
457
  speaker.alone = true;
458
458
  }
459
459
  /** The settings a window open takes at once (`takeSettings`): its locators and the steps on the way to the chat. */
460
- const WINDOW_NOW = new Set(['copilot.pickerLocators', 'copilot.chatLocators', 'copilot.pickerSteps', 'copilot.builtInSteps', 'copilot.extraSteps']);
460
+ const WINDOW_NOW = new Set([
461
+ 'copilot.pickerLocators', 'copilot.chatLocators', 'copilot.pickerSteps', 'copilot.builtInSteps', 'copilot.extraSteps',
462
+ // The window's waits (2026-11-18), which the window kept open between messages went on with for days.
463
+ 'copilot.replyTimeoutSec', 'copilot.signInTimeoutSec', 'copilot.humanWaitSec',
464
+ ]);
461
465
  /** The model menu's locators and its step pictures, as Settings have them (2026-10-24), for every window that picks a model. */
462
466
  /** The locators Settings hold for the Copilot window: the model menu's, and the chat page's own (the box to write in, 2026-11-17). */
463
467
  export function pickerOptions(cfg) {
@@ -472,11 +476,17 @@ export function pickerOptions(cfg) {
472
476
  ...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}),
473
477
  ...(switchedOff ? { builtInSteps: builtIn } : {}),
474
478
  ...(own.length > 0 ? { extraSteps: own } : {}),
479
+ // Its waits, as Settings have them now (2026-11-18): a window kept open is handed them with each message.
480
+ replyTimeoutMs: cfg.copilot.replyTimeoutSec * 1000,
481
+ signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
482
+ humanWaitMs: cfg.copilot.humanWaitSec * 1000,
475
483
  };
476
484
  }
477
485
  export async function openBrowser(cfg, bus, transportDir, sessionId,
478
486
  /** The run's Stop: a sign-in still awaited ends with it. */
479
- signal) {
487
+ signal,
488
+ /** The run's settings: a locator or a step fixed while the sign-in is awaited is handed to the window at once. */
489
+ live) {
480
490
  const speaker = { id: sessionId };
481
491
  const transport = createTransport({
482
492
  profileDir: cfg.resolved.profileDir,
@@ -484,9 +494,6 @@ signal) {
484
494
  chatUrl: cfg.copilot.url,
485
495
  channel: cfg.copilot.channel,
486
496
  headless: cfg.copilot.headless,
487
- replyTimeoutMs: cfg.copilot.replyTimeoutSec * 1000,
488
- signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
489
- humanWaitMs: cfg.copilot.humanWaitSec * 1000,
490
497
  keepFailurePage: cfg.copilot.keepFailurePage,
491
498
  ...pickerOptions(cfg),
492
499
  onEvent: (event, detail) => {
@@ -542,6 +549,11 @@ signal) {
542
549
  * or read of the models, the one the error asks for, was refused as "Edge is already running with
543
550
  * this profile" until the window was closed by hand.
544
551
  */
552
+ // Until the run has the window (`runSession` hands it what is saved from then on): bug hunt 2026-11-18.
553
+ const unlive = live?.onChange((change) => {
554
+ if (change.now.some((name) => WINDOW_NOW.has(name)))
555
+ transport.takeSettings(pickerOptions(cfg));
556
+ });
545
557
  try {
546
558
  await transport.open();
547
559
  await transport.ensureSignedIn(undefined, { signal });
@@ -552,6 +564,9 @@ signal) {
552
564
  // Closed with its X while it opened or the sign-in was awaited: a stop, not a failure to start (2026-10-19).
553
565
  throw byHand ? new WindowClosed() : e;
554
566
  }
567
+ finally {
568
+ unlive?.();
569
+ }
555
570
  return transport;
556
571
  }
557
572
  /**
@@ -719,8 +734,8 @@ export function failedOpening(e) {
719
734
  /** Whether a run failed while opening the browser or entering the conversation (see `failedOpening`). */
720
735
  export const failedWhileOpening = (e) => !!e?.openingBrowser;
721
736
  /** The old shape, kept for the terminal path: open a browser and enter the conversation. */
722
- export async function openSessionTransport(cfg, session, bus, runsDir, signal) {
723
- const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id, signal);
737
+ export async function openSessionTransport(cfg, session, bus, runsDir, signal, live) {
738
+ const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id, signal, live);
724
739
  /*
725
740
  * Closed on any failure to enter the conversation, not only a conversation that will not reopen: the caller has no
726
741
  * transport yet, so a page that would not load left the window open on the profile with nobody holding it.
@@ -825,6 +840,12 @@ signal) {
825
840
  const hand = wanted && buttonShows(shown, wanted)
826
841
  ? { result: { ok: true, current: wanted, by: 'already' }, goOnAsItIs: false }
827
842
  : await withOperatorHand(transport, wanted, { ok: false, current: shown, reason: why }, hooks, session.id, bus, true, asks);
843
+ /*
844
+ * Stopped on the card (2026-11-18): the run stops, as the card's "Stop" says — with a model named too, which asked
845
+ * the operator a second time ("could not choose the model") before.
846
+ */
847
+ if ('stopped' in hand && hand.stopped)
848
+ return { refused: 'The model was to be chosen by hand, and the operator stopped the run. Nothing was sent.' };
828
849
  if (!wanted) {
829
850
  const now = await transport.currentModel().catch(() => null);
830
851
  if (hand.result.ok || hand.goOnAsItIs) {
@@ -938,7 +959,7 @@ opts = {}) {
938
959
  actor: opts.actor ?? (opts.review ? 'review' : opts.role ?? 'worker'),
939
960
  });
940
961
  if (answer === 'stop')
941
- return { result, goOnAsItIs: false };
962
+ return { result, goOnAsItIs: false, stopped: true };
942
963
  if (answer === 'continue') {
943
964
  bus.publish({ sessionId, type: 'model-help-continue', level: 'warn', message: `the operator chose to go on with the model the chat is on ("${shown ?? 'unknown'}")${wanted ? `, not "${wanted}"` : ''}`, data: { asked: wanted, shown } });
944
965
  return { result: { ok: false, current: shown, reason: `the operator chose to go on with "${shown ?? 'unknown'}"` }, goOnAsItIs: true };
@@ -1792,8 +1813,13 @@ export async function runTask(transport, session, task, deps) {
1792
1813
  * the way a read-only task is wherever the task has a branch of its own.
1793
1814
  */
1794
1815
  const planMode = session.planMode ?? cfg.execution.planMode ?? 'off';
1795
- // A continued task does not plan again, unless its plan was sent back while the queue had it set aside (2026-10-26).
1796
- let planning = planMode !== 'off' && (!task.continuing || task.continuing.replan === true);
1816
+ /*
1817
+ * A continued task does not plan again when a plan was approved for it — it carries on from that plan — nor when it
1818
+ * was sent back while the queue had it set aside it does (2026-10-26). One carried on with no plan approved at all
1819
+ * plans first (2026-11-18: a Stop at the plan's card, a restart, or a limit while planning, then "Continue" or the
1820
+ * carrying on after a limit, went straight to the work, and files changed with no plan approved).
1821
+ */
1822
+ let planning = planMode !== 'off' && (!task.continuing || task.continuing.replan === true || !approvedPlanOf(task));
1797
1823
  await actingNow(planning ? 'plan' : 'worker');
1798
1824
  const planEnforced = planning && onOwnBranch;
1799
1825
  let planVersion = 0;
@@ -2404,6 +2430,8 @@ export async function runTask(transport, session, task, deps) {
2404
2430
  const beforeReview = processesBefore ? await snapshotProcesses(work.cwd, processesBefore.since).catch(() => null) : null;
2405
2431
  let roundLeftovers = [];
2406
2432
  let outcome;
2433
+ /** What cut the review off, when it was not the review's own failing: the window closed, the conversation lost. */
2434
+ let reviewCut;
2407
2435
  try {
2408
2436
  await transport.newChat();
2409
2437
  if (model || (reviewByHand && deps.models?.askHelp)) {
@@ -2485,6 +2513,7 @@ export async function runTask(transport, session, task, deps) {
2485
2513
  });
2486
2514
  }
2487
2515
  catch (e) {
2516
+ reviewCut = e;
2488
2517
  outcome = { verdict: 'error', findings: [], stepsRun: 0, iterations: 0, problem: e.message };
2489
2518
  }
2490
2519
  finally {
@@ -2517,6 +2546,21 @@ export async function runTask(transport, session, task, deps) {
2517
2546
  sink.event('review-stopped', { round: reviewRounds, stepsRun: outcome.stepsRun }, `the operator stopped the run during review round ${reviewRounds}; the work is neither accepted nor sent back`, 'warn');
2518
2547
  return 'stopped';
2519
2548
  }
2549
+ /*
2550
+ * The window closed during the review and not opened again, or a conversation lost (bug hunt 2026-11-18): said as
2551
+ * the review's error, which accepts the work unreviewed, so the task ended "done" where everywhere else it ends
2552
+ * stopped, with Continue. Thrown on, for the end of the task to say it as it says it anywhere (see `runTask`).
2553
+ */
2554
+ if (transport.closedOutside() || reviewCut instanceof ChatLost || reviewCut instanceof WindowClosed) {
2555
+ await saveReview({
2556
+ verdict: 'error',
2557
+ rounds: reviewRounds,
2558
+ stepsRun: outcome.stepsRun,
2559
+ problem: `review round ${reviewRounds} was cut off: ${outcome.problem ?? 'the browser window was closed'}`,
2560
+ model: model || undefined,
2561
+ });
2562
+ throw reviewCut instanceof Error ? reviewCut : new WindowClosed(CLOSED_NOT_REOPENED);
2563
+ }
2520
2564
  /*
2521
2565
  * Which findings an earlier round already raised.
2522
2566
  *
@@ -3606,6 +3650,19 @@ export async function runTask(transport, session, task, deps) {
3606
3650
  sink.event('window-closed', { error: message, reopened: transport.reopenedTimes?.() ?? 0 }, why, 'warn');
3607
3651
  return await finish('aborted', why);
3608
3652
  }
3653
+ /*
3654
+ * The window could not be put back on its conversation (2026-11-09), nothing sent: a stop, not a failure of the work
3655
+ * (bug hunt 2026-11-18: it ended "failed", where no Continue is offered, though its own words say to continue once
3656
+ * signed in). Continue goes back to the conversation again. A fault of the means all the same, so a worker's subtask
3657
+ * that ends so may be tried again (`classifySubtaskEnd`), as any fault of the chat may.
3658
+ */
3659
+ if (e instanceof ChatLost) {
3660
+ sink.event('chat-lost', { chatId: e.chatId, found: e.found }, message, 'warn');
3661
+ await setTask((t) => {
3662
+ t.failure = { kind: 'transport', detail: message.slice(0, 400) };
3663
+ }).catch(() => undefined);
3664
+ return await finish('aborted', message);
3665
+ }
3609
3666
  sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
3610
3667
  await transport.dumpFailure(log.path('failures'), 'crash').catch(() => undefined);
3611
3668
  /*
@@ -3667,6 +3724,16 @@ export async function runSession(sessionId, deps) {
3667
3724
  let lastStatus;
3668
3725
  /** Whether the queue stopped because the operator asked it to hold, rather than because it ended. */
3669
3726
  let paused = false;
3727
+ /*
3728
+ * The locators and the steps on the way to the chat, fixed in Settings while this run goes (bug hunt 2026-11-18): the
3729
+ * window takes them at once, as the notice says, whatever the run is doing — waiting for a sign-in or on the model's
3730
+ * card, or the lead or Kerrigan at their turn. Only a task at work handed them on before (`tookSettings` in
3731
+ * `runTask`); the window opened for the run is handed them while it waits for the sign-in too (`openBrowser`).
3732
+ */
3733
+ const unwindow = deps.live?.onChange((change) => {
3734
+ if (transport && change.now.some((name) => WINDOW_NOW.has(name)))
3735
+ transport.takeSettings(pickerOptions(cfg));
3736
+ }) ?? (() => undefined);
3670
3737
  try {
3671
3738
  session = await joinGroupConversation(store, session, bus);
3672
3739
  try {
@@ -3684,7 +3751,7 @@ export async function runSession(sessionId, deps) {
3684
3751
  else {
3685
3752
  await deps.beforeBrowser?.();
3686
3753
  // The chat's window outlives this message, so what it keeps goes where the batch's window keeps its own.
3687
- transport = await openSessionTransport(cfg, session, bus, deps.chatWindow ? cfg.resolved.runsDir : sessionRunsDir, deps.signal);
3754
+ transport = await openSessionTransport(cfg, session, bus, deps.chatWindow ? cfg.resolved.runsDir : sessionRunsDir, deps.signal, deps.live);
3688
3755
  if (deps.chatWindow)
3689
3756
  speakFor(transport, session.id, { alone: true });
3690
3757
  }
@@ -3724,7 +3791,8 @@ export async function runSession(sessionId, deps) {
3724
3791
  * 2026-11-13: "if I close the browser by accident, carry the task on from where it got to"), up to the times
3725
3792
  * Settings allow for one message — its runs again in a fresh chat and on its own after a limit included.
3726
3793
  */
3727
- chat.holdWindow?.(cfg.limits.reopenWindow ?? 3, deps.signal);
3794
+ // As Settings have it each time the window goes (bug hunt 2026-11-18: copied at the message's start).
3795
+ chat.holdWindow?.(() => cfg.limits.reopenWindow ?? 3, deps.signal);
3728
3796
  /*
3729
3797
  * A task taken from the queue was started by the operator, never by the retry loop below, which
3730
3798
  * runs its own. A fresh-retry mark on it is left from a retry that was queued and never ran —
@@ -3798,10 +3866,11 @@ export async function runSession(sessionId, deps) {
3798
3866
  * stopped, not one that blocked with nothing to do (that goes to a fresh chat below, then to a person),
3799
3867
  * and not when a pause or Stop was asked for.
3800
3868
  */
3801
- const autoAllowed = Math.max(0, cfg.limits.autoContinue ?? 0);
3869
+ // As Settings have it each time (bug hunt 2026-11-18: copied once, though Settings say limits count at once).
3870
+ const autoAllowed = () => Math.max(0, cfg.limits.autoContinue ?? 0);
3802
3871
  let autoContinued = 0;
3803
3872
  const carriedOnAtOnce = async () => {
3804
- if (autoContinued >= autoAllowed || deps.signal?.aborted || deps.shouldPause?.())
3873
+ if (autoContinued >= autoAllowed() || deps.signal?.aborted || deps.shouldPause?.())
3805
3874
  return false;
3806
3875
  const now = (await store.getSession(sessionId))?.tasks.find((x) => x.id === task.id);
3807
3876
  if (!now || !now.limit || now.status === 'aborted' || !isContinuable(now))
@@ -3812,8 +3881,8 @@ export async function runSession(sessionId, deps) {
3812
3881
  taskId: task.id,
3813
3882
  type: 'task-auto-continue',
3814
3883
  level: 'warn',
3815
- message: `"${task.title}" stopped at ${now.limit.setting} (${now.limit.value}); carrying it on in its own chat, from where it got to (${autoContinued} of ${autoAllowed})`,
3816
- data: { setting: now.limit.setting, value: now.limit.value, time: autoContinued, of: autoAllowed, status: now.status },
3884
+ message: `"${task.title}" stopped at ${now.limit.setting} (${now.limit.value}); carrying it on in its own chat, from where it got to (${autoContinued} of ${autoAllowed()})`,
3885
+ data: { setting: now.limit.setting, value: now.limit.value, time: autoContinued, of: autoAllowed(), status: now.status },
3817
3886
  });
3818
3887
  await store.continueTask(sessionId, task.id);
3819
3888
  session = (await store.getSession(sessionId));
@@ -3827,7 +3896,7 @@ export async function runSession(sessionId, deps) {
3827
3896
  for (;;) {
3828
3897
  while (outcome.status === 'blocked' && retried < retriesAllowed && !deps.signal?.aborted && !(outcome.stopCode && NOT_THE_CHATS.includes(outcome.stopCode))
3829
3898
  // A task a limit stopped is carried on where it is, with its work, not started over in a fresh chat.
3830
- && !(autoContinued < autoAllowed && !!(await store.getSession(sessionId))?.tasks.find((x) => x.id === task.id)?.limit)) {
3899
+ && !(autoContinued < autoAllowed() && !!(await store.getSession(sessionId))?.tasks.find((x) => x.id === task.id)?.limit)) {
3831
3900
  retried += 1;
3832
3901
  bus.publish({
3833
3902
  sessionId,
@@ -3885,8 +3954,8 @@ export async function runSession(sessionId, deps) {
3885
3954
  level: outcome.status === 'done' ? 'info' : 'warn',
3886
3955
  message: outcome.status === 'done'
3887
3956
  ? `"${task.title}" done after being carried on ${autoContinued} time(s) on its own`
3888
- : `"${task.title}" ended ${outcome.status} after being carried on ${autoContinued} time(s) on its own${autoContinued >= autoAllowed ? ` — limits.autoContinue (${autoAllowed}) reached` : ''}`,
3889
- data: { times: autoContinued, of: autoAllowed, status: outcome.status },
3957
+ : `"${task.title}" ended ${outcome.status} after being carried on ${autoContinued} time(s) on its own${autoContinued >= autoAllowed() ? ` — limits.autoContinue (${autoAllowed()}) reached` : ''}`,
3958
+ data: { times: autoContinued, of: autoAllowed(), status: outcome.status },
3890
3959
  });
3891
3960
  }
3892
3961
  if (retried > 0) {
@@ -3941,6 +4010,7 @@ export async function runSession(sessionId, deps) {
3941
4010
  }
3942
4011
  }
3943
4012
  finally {
4013
+ unwindow();
3944
4014
  // No message at work: a window closed from now on is the next message's to open. One being opened again is let finish.
3945
4015
  await transport?.releaseWindow?.().catch(() => undefined);
3946
4016
  // A borrowed window belongs to whoever opened it and stays open for the next session.