copilot-operator 0.1.96 → 0.1.99

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 (92) hide show
  1. package/dist/src/api/apiLock.js +82 -0
  2. package/dist/src/api/folderPicker.js +22 -22
  3. package/dist/src/api/main.js +5 -0
  4. package/dist/src/api/operator.controller.js +37 -11
  5. package/dist/src/api/operator.service.js +493 -86
  6. package/dist/src/api/server.js +10 -0
  7. package/dist/src/config/exportHome.js +52 -10
  8. package/dist/src/config/home.js +27 -11
  9. package/dist/src/config/schema.js +13 -0
  10. package/dist/src/exec/authorizer.js +11 -4
  11. package/dist/src/exec/commandHeads.js +25 -0
  12. package/dist/src/exec/confinement.js +50 -4
  13. package/dist/src/exec/network.js +11 -1
  14. package/dist/src/exec/npmScripts.js +33 -0
  15. package/dist/src/exec/policy.js +79 -24
  16. package/dist/src/exec/processes.js +24 -5
  17. package/dist/src/exec/programs.js +21 -0
  18. package/dist/src/exec/reportFile.js +2 -1
  19. package/dist/src/exec/runner.js +31 -9
  20. package/dist/src/exec/scriptFiles.js +133 -6
  21. package/dist/src/orchestrator/handoff.js +3 -3
  22. package/dist/src/orchestrator/kerriganRunner.js +14 -6
  23. package/dist/src/orchestrator/leadRunner.js +43 -23
  24. package/dist/src/orchestrator/review.js +66 -10
  25. package/dist/src/orchestrator/taskRunner.js +73 -14
  26. package/dist/src/plan/kerrigan.js +253 -253
  27. package/dist/src/plan/schema.js +3 -13
  28. package/dist/src/plan/systemGuide.js +28 -28
  29. package/dist/src/protocol/kerriganSchema.js +5 -1
  30. package/dist/src/protocol/replySchema.js +2 -2
  31. package/dist/src/queue/queue.js +93 -0
  32. package/dist/src/session/compose.js +14 -10
  33. package/dist/src/session/locatorFailures.js +32 -12
  34. package/dist/src/session/model.js +23 -0
  35. package/dist/src/session/store.js +47 -0
  36. package/dist/src/session/workspace.js +20 -5
  37. package/dist/src/transport/copilotTransport.js +82 -62
  38. package/dist/src/util/zip.js +147 -44
  39. package/dist/src/vcs/newBranch.js +24 -2
  40. package/dist/src/vcs/operatorGit.js +9 -10
  41. package/dist/src/vcs/referenceGuard.js +9 -4
  42. package/dist/web/404.html +2 -2
  43. package/dist/web/_next/static/chunks/1024-c0eee3ec374816d1.js +1 -0
  44. package/dist/web/_next/static/chunks/1077.a4fe6ae48f3d3ff9.js +1 -0
  45. package/dist/web/_next/static/chunks/1548.765d6eed5325bd01.js +1 -0
  46. package/dist/web/_next/static/chunks/2163.e8d6c85412d5d411.js +1 -0
  47. package/dist/web/_next/static/chunks/6240-8ba644c53ffab87d.js +1 -0
  48. package/dist/web/_next/static/chunks/714.f2dcd6b41b58d1a7.js +1 -0
  49. package/dist/web/_next/static/chunks/7220.652a8a339c1e7401.js +1 -0
  50. package/dist/web/_next/static/chunks/7921-9cf1ece94fc89bb3.js +1 -0
  51. package/dist/web/_next/static/chunks/8584.7c438425140f1d8d.js +1 -0
  52. package/dist/web/_next/static/chunks/9067.8c4e6a64620a45d9.js +1 -0
  53. package/dist/web/_next/static/chunks/9747.43d25bdff8737d09.js +1 -0
  54. package/dist/web/_next/static/chunks/app/{layout-2364903896c2c175.js → layout-97259931ed97e20d.js} +1 -1
  55. package/dist/web/_next/static/chunks/app/page-26e4ea30eb076e6b.js +1 -0
  56. package/dist/web/_next/static/chunks/app/queue/page-7228e045f8ea10c4.js +1 -0
  57. package/dist/web/_next/static/chunks/app/settings/page-c915d61553e1025b.js +1 -0
  58. package/dist/web/_next/static/chunks/app/system/page-4d24f44eb9077fb7.js +1 -0
  59. package/dist/web/_next/static/chunks/{webpack-3f144d13be3516c2.js → webpack-31db88c3d5781520.js} +1 -1
  60. package/dist/web/_next/static/css/{523d11041085f836.css → 87999096d96266fd.css} +1 -1
  61. package/dist/web/defaults.html +2 -2
  62. package/dist/web/defaults.txt +26 -25
  63. package/dist/web/index.html +3 -3
  64. package/dist/web/index.txt +26 -25
  65. package/dist/web/queue.html +2 -2
  66. package/dist/web/queue.txt +26 -25
  67. package/dist/web/settings.html +2 -2
  68. package/dist/web/settings.txt +26 -25
  69. package/dist/web/system.html +2 -2
  70. package/dist/web/system.txt +26 -25
  71. package/package.json +3 -2
  72. package/prompts/kerrigan1.md +2 -1
  73. package/prompts/lead1.md +2 -1
  74. package/prompts/level1.md +6 -1
  75. package/prompts/review1.md +7 -4
  76. package/dist/web/_next/static/chunks/1024-214ded25b9048526.js +0 -1
  77. package/dist/web/_next/static/chunks/1077.161de82f740d47f0.js +0 -1
  78. package/dist/web/_next/static/chunks/1548.f2688468bf946e13.js +0 -1
  79. package/dist/web/_next/static/chunks/2163.b8ada3b7bde69f03.js +0 -1
  80. package/dist/web/_next/static/chunks/714.d1489788e598833b.js +0 -1
  81. package/dist/web/_next/static/chunks/7220.b85c8d105f394389.js +0 -1
  82. package/dist/web/_next/static/chunks/7921-00ebbcc6f65fbe35.js +0 -1
  83. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
  84. package/dist/web/_next/static/chunks/8584.a678bfced1cea938.js +0 -1
  85. package/dist/web/_next/static/chunks/9067.6da03ae052877b19.js +0 -1
  86. package/dist/web/_next/static/chunks/9747.ba29e64e97e8a15b.js +0 -1
  87. package/dist/web/_next/static/chunks/app/page-d031bf326e401246.js +0 -1
  88. package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +0 -1
  89. package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +0 -1
  90. package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +0 -1
  91. /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_buildManifest.js +0 -0
  92. /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_ssgManifest.js +0 -0
@@ -22,15 +22,14 @@ import { chatbotFile } from '../session/chatbotFile.js';
22
22
  import { CHAT_LOCATOR_KEYS, locatorPrompt, resolveChatLocators } from '../transport/locators.js';
23
23
  import { LocatorMissing } from '../transport/copilotTransport.js';
24
24
  import { isStepKey, stepKey, stepPrompt } from '../transport/chatSteps.js';
25
- import { readFile } from 'node:fs/promises';
26
- import { join, resolve } from 'node:path';
25
+ import { basename, join, resolve } from 'node:path';
27
26
  import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
28
27
  import { chooseHome, homeRefusal, movedFrom } from '../config/home.js';
29
- import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW, writeFileAtomically } from '../session/store.js';
30
- import { checkItems, emptyQueue, itemTitle, mergeItems, nextStep, parkAfterMs, parkedAnswerFrom, skippedBecause, statusOfTask, waitsByHand, MAX_PARK_AFTER_SEC, PARKED_WORDS } from '../queue/queue.js';
28
+ import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW, readStoreJson, StoreFileUnusable, writeFileAtomically } from '../session/store.js';
29
+ import { carriesOn, checkItems, emptyQueue, holdsChat, itemTitle, mergeItems, nextStep, rebaseEdit, parkAfterMs, parkedAnswerFrom, skippedBecause, statusOfTask, waitsByHand, MAX_PARK_AFTER_SEC, PARKED_WORDS } from '../queue/queue.js';
31
30
  import { branchStart, madeFromRemote, makeQueueBranch, refreshQueueBranch } from '../queue/queueBranch.js';
32
31
  import { EventBus } from '../session/events.js';
33
- import { isContinuable, MAX_INSTRUCTION_CHARS, newId, withProblemAt } from '../session/model.js';
32
+ import { isContinuable, parkedOver, MAX_INSTRUCTION_CHARS, newId, withProblemAt } from '../session/model.js';
34
33
  import { handoffOutcomeOf, handoffResultMessage } from '../orchestrator/handoff.js';
35
34
  import { runSession, queuedToRun, failedWhileOpening, pickerOptions } from '../orchestrator/taskRunner.js';
36
35
  import { Hold, WaitsFor } from '../orchestrator/hold.js';
@@ -77,7 +76,23 @@ function sameFolder(a, b) {
77
76
  const CARRIES_ON_AFTER = (what) => `${what}; it carries on from where it stopped, in its own chat, when the queue is run again`;
78
77
  /** A card answered after it went: by Kerrigan, another tab, or its work having ended (2026-11-18). */
79
78
  export const CARD_GONE = 'That card is not waiting any more: it was answered, or its work ended.';
79
+ /** A card pressed as the queue sets its task aside (second bug hunt, 2026-11-19). */
80
+ /**
81
+ * A set-aside task whose chat went on past it (second bug hunt, 2026-11-19): a message written there since. Answered, the
82
+ * older message ran again after the newer one, in the same conversation, where "Continue" carries on only the last.
83
+ */
84
+ export const PARKED_PASSED = 'The conversation has gone on past this task in its chat (a message was written there since), so its answer cannot carry it on: Stop it here, and say what it still needs in a new message in its chat.';
85
+ export const SET_ASIDE_NOW = "The queue has just set this task aside, as it waited for you: answer it on the queue's page, where it waits now.";
80
86
  /** "Run this and the rest" where the run may not go on unasked: said, and the card kept (2026-11-18). */
87
+ /** How long a task of the queue waits for a sign-in Copilot asks for: as long as it takes, a week (2026-11-19). */
88
+ export const QUEUE_SIGN_IN_WAIT_SEC = 7 * 24 * 3600;
89
+ /** Said when "Sign in to Copilot" is pressed while a run's own window waits for the sign-in (2026-11-19). */
90
+ export const SIGN_IN_IN_THE_RUNS_WINDOW = 'The Copilot window the work opened is waiting for you to sign in: sign in there — it may be behind this one — and the work goes on by itself.';
91
+ /** Said when a set-aside task's card is pressed after the queue let go of it (2026-11-19). */
92
+ export const PARKED_RELEASED = 'Its card is closed now: "Continue" under its message carries it on in its own chat.';
93
+ /** Said when "Continue" is pressed on a message answered on its card in the queue (2026-11-19). */
94
+ export const PARKED_ALREADY_ANSWERED = 'This card was answered already, on another page: the queue carries the task on with that answer. To stop it, use Stop on the queue\'s page.';
95
+ export const PARKED_ANSWERED = "This message was answered on its card, and the queue carries it on with that answer: at the queue's next turn, or when the queue is run.";
81
96
  export const RUN_ALL_REFUSED = (why) => `"Run this and the rest" cannot be given here — ${why} Nothing was run: "Run" runs this step.`;
82
97
  /** Whether a folder is another, or inside it: Windows paths, as `sameFolder` reads them. */
83
98
  function folderInside(inner, outer) {
@@ -94,7 +109,7 @@ import { makeAuthorizer } from '../exec/authorizer.js';
94
109
  import { pickFolder } from './folderPicker.js';
95
110
  import { findEdgeUsingProfile, profileHolder } from '../transport/profileLock.js';
96
111
  import { assessIsolation, readIsolationSignals } from '../exec/isolation.js';
97
- import { unattendedPrecondition } from '../exec/policy.js';
112
+ import { unattendedBlock, unattendedPrecondition } from '../exec/policy.js';
98
113
  import { createTransport } from '../transport/chatTransport.js';
99
114
  import { composeHandoff } from '../session/handoff.js';
100
115
  import { appendRunLog, appendSessionLog, readRunLog } from '../session/runLog.js';
@@ -116,8 +131,7 @@ import { planApprovedMessage, planReviseMessage } from '../orchestrator/planMode
116
131
  import { leadPlanApproved, leadPlanRevise } from '../orchestrator/leadRunner.js';
117
132
  import { coveredByArtifacts } from '../vcs/artifacts.js';
118
133
  import { botVersion } from '../config/version.js';
119
- import { exportEntries, exportFileName as homeExportName, exportSizes } from '../config/exportHome.js';
120
- import { createZip } from '../util/zip.js';
134
+ import { exportFileName as homeExportName, exportPlan, exportSizes, writeExport } from '../config/exportHome.js';
121
135
  import { settingsOf, SettingsUnusableError } from './settings.js';
122
136
  import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
123
137
  import { chatDenyPatterns } from '../config/schema.js';
@@ -238,20 +252,39 @@ let OperatorService = class OperatorService {
238
252
  * opened again, a conversation lost, the program closed, are said.
239
253
  */
240
254
  stoppedByOperator = new Set();
255
+ /**
256
+ * Whether a conversation's latest message ended by the operator's own Stop, by its session: read by the queue, which
257
+ * only that stops (2026-11-19: a conversation lost, which ends a message stopped so that "Continue" is offered,
258
+ * stopped the whole queue left running).
259
+ */
260
+ endedByOperator = new Map();
241
261
  /** Where Git asks the operator for a password now, in its own window (2026-10-26): the step waits for it. */
242
262
  passwordAsked = new Map();
263
+ /**
264
+ * Where the Copilot window of a run waits for the operator to sign in (2026-11-19): said on the tab and in the chat,
265
+ * and "Sign in to Copilot" points to that window rather than refusing because of it.
266
+ */
267
+ signInAsked = new Map();
268
+ /** A reading of Copilot's page — the models, "Check the locators" — waits for the operator to sign in (2026-11-19). */
269
+ readingSignIn = false;
243
270
  followsActing = this.bus.subscribe('*', (e) => {
244
271
  if (e.type === 'acting' && e.data)
245
272
  this.acting.set(e.sessionId, e.data);
246
273
  // A chat locator that found nothing (2026-11-17): kept for the banner and Settings.
247
274
  else if (e.type === 'browser:locator-missing' && e.data)
248
275
  this.recordLocatorFailure(e.data);
276
+ else if (e.type === 'browser:locator-found' && e.data)
277
+ this.locatorFound(e.data);
249
278
  else if (e.type === 'browser:sign-in-required' || e.type === 'browser:verification-required') {
250
279
  // The Copilot window waits for the operator to sign in, or to show a person is there: not counted (2026-10-29).
251
280
  this.holdOf(e.sessionId)?.waitFor(`${e.type}:${e.sessionId}`);
281
+ if (e.type === 'browser:sign-in-required')
282
+ this.signInAsked.set(e.sessionId, e.at);
252
283
  }
253
284
  else if (e.type === 'browser:signed-in' || e.type === 'browser:verification-cleared') {
254
285
  this.holdOf(e.sessionId)?.waited(`${e.type === 'browser:signed-in' ? 'browser:sign-in-required' : 'browser:verification-required'}:${e.sessionId}`);
286
+ if (e.type === 'browser:signed-in')
287
+ this.signInAsked.delete(e.sessionId);
255
288
  }
256
289
  else if (e.type === 'password-window') {
257
290
  const open = e.data?.open === true;
@@ -275,12 +308,14 @@ let OperatorService = class OperatorService {
275
308
  else if (e.type === 'task-finished') {
276
309
  this.acting.delete(e.sessionId);
277
310
  this.passwordAsked.delete(e.sessionId);
311
+ this.signInAsked.delete(e.sessionId);
278
312
  for (const key of [`pw:${e.sessionId}`, `browser:sign-in-required:${e.sessionId}`, `browser:verification-required:${e.sessionId}`])
279
313
  this.holdOf(e.sessionId)?.waited(key);
280
314
  const status = e.data?.status;
281
315
  if (typeof status === 'string' && !this.workerLeads.has(e.sessionId)) {
282
316
  const byOperator = status === 'aborted' && this.stoppedByOperator.has(this.runKey(e.sessionId));
283
317
  this.lastOutcome = { status, at: e.at, sessionId: e.sessionId, ...(byOperator ? { byOperator: true } : {}) };
318
+ this.endedByOperator.set(e.sessionId, byOperator);
284
319
  }
285
320
  }
286
321
  });
@@ -421,8 +456,10 @@ let OperatorService = class OperatorService {
421
456
  await writeAttemptRecord(settled, ended, cfg.resolved.runsDir, exportMachine(cfg));
422
457
  }
423
458
  /** Runs the startup work now, so it does not wait for the first request. */
424
- bootstrap() {
425
- return this.init();
459
+ async bootstrap() {
460
+ await this.init();
461
+ // At once, not at the queue's first use (2026-11-19): a chat shows a set-aside task's card before the queue is read.
462
+ await this.recoverQueue().catch((e) => console.error('[queue] could not be recovered at the start:', e.message));
426
463
  }
427
464
  // --- level 1 --------------------------------------------------------------------------
428
465
  async getLevel1() {
@@ -919,6 +956,15 @@ let OperatorService = class OperatorService {
919
956
  * "a mechanism that detects which locator exactly the bot failed on"): kept as the last one for that locator, for the
920
957
  * banner on every page and the field in red in Settings.
921
958
  */
959
+ /**
960
+ * A locator said to find nothing, found after all (second bug hunt, 2026-11-19: the box, once a slow sign-in was done):
961
+ * its failure goes — the banner, the red field — unless its locator was changed in Settings since.
962
+ */
963
+ locatorFound(detail) {
964
+ if (typeof detail.key !== 'string' || typeof detail.locator !== 'string')
965
+ return;
966
+ void this.locatorFailures.dismiss(detail.key, detail.locator).catch(() => undefined);
967
+ }
922
968
  recordLocatorFailure(detail) {
923
969
  const key = detail.key;
924
970
  if (typeof key !== 'string' || !(CHAT_LOCATOR_KEYS.includes(key) || isStepKey(key)) || typeof detail.locator !== 'string')
@@ -942,7 +988,7 @@ let OperatorService = class OperatorService {
942
988
  ...(url ? { url } : {}),
943
989
  ...(piece ? { piece, ...(around ? { around } : {}) } : {}),
944
990
  })
945
- .catch(() => undefined);
991
+ .catch((e) => console.error(`[locators] the locator of "${key}" found nothing, and that could not be kept for the banner: ${e.message}`));
946
992
  }
947
993
  /**
948
994
  * The failures kept, each with whether its locator has been changed in Settings since (then it is no longer the one
@@ -1033,9 +1079,11 @@ let OperatorService = class OperatorService {
1033
1079
  * Everything the bot has kept, as one .zip (operator, 2026-10-23): `data/` — the key and the Edge profile left out,
1034
1080
  * the manifest says why — and `runs/` when asked for.
1035
1081
  */
1082
+ /** Written to the download as it goes (2026-11-19): see `writeExport`. Its name first, for the download's header. */
1036
1083
  exportHome(runs) {
1037
1084
  const now = new Date();
1038
- return { fileName: homeExportName(now), content: createZip(exportEntries(this.layout, { runs, version: botVersion(), now })) };
1085
+ const plan = exportPlan(this.layout, { runs, version: botVersion(), now });
1086
+ return { fileName: homeExportName(now), write: (out) => writeExport(plan, out) };
1039
1087
  }
1040
1088
  async terminalReport() {
1041
1089
  const cfg = await this.settings.load();
@@ -1093,6 +1141,13 @@ let OperatorService = class OperatorService {
1093
1141
  */
1094
1142
  if (session.queueItem)
1095
1143
  runCfg.copilot = { ...runCfg.copilot, manualModel: false, leadManualModel: false, reviewManualModel: false, kerriganManualModel: false };
1144
+ /*
1145
+ * And a sign-in Copilot asks for is waited for as long as it takes (second bug hunt, 2026-11-19): a queue left
1146
+ * overnight whose account was signed out failed each task after fifteen minutes, skipping what depended on it, where
1147
+ * signed in in the morning it carries on by itself. The wait is not counted, and the run's Stop ends it.
1148
+ */
1149
+ if (session.queueItem)
1150
+ runCfg.copilot = { ...runCfg.copilot, signInTimeoutSec: Math.max(runCfg.copilot.signInTimeoutSec, QUEUE_SIGN_IN_WAIT_SEC) };
1096
1151
  const live = new LiveSettings(runCfg, session.kind === 'chat', loaded);
1097
1152
  const policy = { mode, ...stepRules(runCfg) };
1098
1153
  /*
@@ -1264,6 +1319,17 @@ let OperatorService = class OperatorService {
1264
1319
  if (s.status === 'stopping')
1265
1320
  s.status = 'idle';
1266
1321
  }).catch(() => undefined);
1322
+ /*
1323
+ * A sign-in or a password asked for by this run, never answered (third hunt, 2026-11-20): a run Stopped, or out of
1324
+ * time, while its window waited for the sign-in ended with no task finished, and the entry stayed — every later run
1325
+ * said "waiting for you to sign in", and "Sign in to Copilot" was refused, until the program was restarted.
1326
+ */
1327
+ for (const id of [...this.signInAsked.keys()])
1328
+ if (id === sessionId || this.runKey(id) === sessionId)
1329
+ this.signInAsked.delete(id);
1330
+ for (const id of [...this.passwordAsked.keys()])
1331
+ if (id === sessionId || this.runKey(id) === sessionId)
1332
+ this.passwordAsked.delete(id);
1267
1333
  this.running.delete(sessionId);
1268
1334
  this.stoppedByOperator.delete(sessionId);
1269
1335
  });
@@ -1372,8 +1438,12 @@ let OperatorService = class OperatorService {
1372
1438
  ...(run?.hold?.held ? { paused: true } : {}),
1373
1439
  // Git asks for a password in its own window, and the work waits for it (2026-10-26).
1374
1440
  ...(this.passwordAsked.size > 0 ? { password: true } : {}),
1441
+ // Copilot's window waits for the operator to sign in (2026-11-19): the work goes on by itself once signed in.
1442
+ ...((this.signInAsked.size > 0 && this.running.size > 0) || this.readingSignIn ? { signIn: true } : {}),
1375
1443
  // The queue still has its turn going, between one of its tasks and the next (2026-11-03): the work is not over.
1376
1444
  ...(this.queueLoop ? { queue: true } : {}),
1445
+ // Tasks of the queue set aside, waiting for the operator's answer on their cards (2026-11-19): the work is not over.
1446
+ ...(this.queueParked > 0 ? { parked: this.queueParked } : {}),
1377
1447
  // How the last message ended, while nothing runs: what the tab says until the operator has looked.
1378
1448
  ...(this.running.size === 0 && this.lastOutcome ? { last: { status: this.lastOutcome.status, at: this.lastOutcome.at, ...(this.lastOutcome.byOperator ? { byOperator: true } : {}) } } : {}),
1379
1449
  };
@@ -1523,14 +1593,28 @@ let OperatorService = class OperatorService {
1523
1593
  const busy = this.branchBusy();
1524
1594
  if (busy)
1525
1595
  throw new Error(busy);
1526
- return await createNewBranch(ws.dir, {
1596
+ const carry = input.carry === 'aside' || input.carry === 'commit' ? input.carry : 'take';
1597
+ /*
1598
+ * The work of a queue's task set aside on "the folder as it is" (2026-11-19): taken to the new branch, it carried on
1599
+ * without it, Copilot not told; put aside, nobody knew whose it was. Put aside, it is kept for that task and put back
1600
+ * when it carries on; taken along, refused, saying so; committed, it stays on the task's branch.
1601
+ */
1602
+ const onNow = ws.isRepo ? (await git(ws.dir, ['symbolic-ref', '--quiet', '--short', 'HEAD']).catch(() => null))?.stdout || null : null;
1603
+ const owners = await this.folderOwners(onNow);
1604
+ if (owners.length > 0 && carry === 'take' && (await git(ws.dir, ['status', '--porcelain']).catch(() => null))?.stdout.trim()) {
1605
+ throw new Error(`What is not committed here is the work of the queue's task "${itemTitle(owners[0].item)}", set aside while it waits for you: taken to the new branch, it would carry on without it. Put it aside instead — it is put back when that task carries on — or commit it, or answer the task's card first.`);
1606
+ }
1607
+ const made = await createNewBranch(ws.dir, {
1527
1608
  name: typeof input.name === 'string' ? input.name : '',
1528
- carry: input.carry === 'aside' || input.carry === 'commit' ? input.carry : 'take',
1609
+ carry,
1529
1610
  fingerprint: typeof input.fingerprint === 'string' ? input.fingerprint : '',
1530
1611
  ...(typeof input.message === 'string' && input.message.trim() ? { message: input.message.trim().slice(0, 2000) } : {}),
1531
1612
  // The saved branch under the bot's own prefix, as its other branches are.
1532
1613
  prefix: DEFAULT_VCS.branchPrefix,
1533
1614
  });
1615
+ if (made.ok && made.saved && owners.length > 0)
1616
+ await this.leftoversOf(onNow, '', made.saved.branch);
1617
+ return made;
1534
1618
  }
1535
1619
  /** The open folder's code, searched as VS Code's Search view does (2026-10-21, see `workspaceSearch.ts`). */
1536
1620
  async workspaceSearch(query, opts) {
@@ -1552,18 +1636,28 @@ let OperatorService = class OperatorService {
1552
1636
  throw new Error(ws.problem ?? 'No project folder is open.');
1553
1637
  return { dir: ws.dir, ...(await workspaceFiles(ws.dir)) };
1554
1638
  }
1555
- async workspaceFile(path) {
1639
+ async workspaceFile(path, dir) {
1556
1640
  const ws = await this.workspace();
1557
1641
  if (!ws.ok)
1558
1642
  throw new Error(ws.problem ?? 'No project folder is open.');
1643
+ this.sameOpenFolder(ws.dir, dir);
1559
1644
  return await workspaceFile(ws.dir, path);
1560
1645
  }
1646
+ /**
1647
+ * A file opened in one folder, read or saved after another was opened (second bug hunt, 2026-11-19): its path was
1648
+ * taken in the folder open now, and Ctrl+S wrote one folder's edit into the other's file of the same name. Refused.
1649
+ */
1650
+ sameOpenFolder(open, dir) {
1651
+ if (dir && !sameFolder(dir, open))
1652
+ throw new Error(`That file was opened in ${dir}, and the folder open now is ${open}: nothing was read or saved there. Open ${dir} again to save it.`);
1653
+ }
1561
1654
  /** The editor's text saved over a file of the open folder, over the version it was made on (see `saveWorkspaceFile`). */
1562
- async saveWorkspaceFile(path, text, base) {
1655
+ async saveWorkspaceFile(path, text, base, dir, again = false) {
1563
1656
  const ws = await this.workspace();
1564
1657
  if (!ws.ok)
1565
1658
  throw new Error(ws.problem ?? 'No project folder is open.');
1566
- const saved = await saveWorkspaceFile(ws.dir, path, text, base);
1659
+ this.sameOpenFolder(ws.dir, dir);
1660
+ const saved = await saveWorkspaceFile(ws.dir, path, text, base, again);
1567
1661
  console.log(`[editor] saved ${saved.path} (${saved.size} bytes)`);
1568
1662
  return saved;
1569
1663
  }
@@ -1809,32 +1903,50 @@ let OperatorService = class OperatorService {
1809
1903
  queueTurn = Promise.resolve();
1810
1904
  queueLoop = null;
1811
1905
  queueRecovered = false;
1906
+ /** The recovery under way, so two calls at once do it once; let go when it could not be written, to be tried again. */
1907
+ queueRecovering = null;
1908
+ /** The ending of the queue's task at work, until it is written: written again when the queue's loop ends (2026-11-19). */
1909
+ queueEnding = null;
1812
1910
  /** The program is closing: the queue's loop stops where it is. */
1813
1911
  queueClosing = false;
1814
1912
  /** The session of the queue's task at work now (2026-10-26): where a wait for the operator is timed, to park it. */
1815
1913
  queueAtWork = new Set();
1914
+ /**
1915
+ * Cards whose task the queue is setting aside now (second bug hunt, 2026-11-19): a press on one is refused, and said
1916
+ * where to answer. Taken as the setting aside went on, the answer was lost: the task stopped and was set aside all the
1917
+ * same, and asked for it again.
1918
+ */
1919
+ parking = new Set();
1816
1920
  /** The timers of the waits of the queue's task at work: a card, by its id; a password window, by `pw:` and the session. */
1817
1921
  parkTimers = new Map();
1818
1922
  /** Commands the operator approved on a parked task's card, run without asking when its chat sends them again. */
1819
1923
  approvedAhead = new Map();
1820
1924
  /** Branches made for tasks of the queue, one edit of the list at a time. */
1821
1925
  branchTurn = Promise.resolve();
1822
- /** The queue as it is on disk; one that cannot be read is an empty one, said in the console. */
1926
+ /**
1927
+ * How many of the queue's tasks are set aside, waiting for the operator, as last read (2026-11-19): the work is not
1928
+ * over while one waits, and "Finished: aborted" — the queue's own stop to set it aside — was said instead.
1929
+ */
1930
+ queueParked = 0;
1931
+ /**
1932
+ * The queue as it is on disk: empty when it was never written. One that is there but cannot be read is refused, never
1933
+ * read as empty (2026-11-19: the next change wrote the empty queue over it, every task and card kept in it lost).
1934
+ */
1823
1935
  async readQueue() {
1824
- try {
1825
- const q = JSON.parse(await readFile(this.queueFile, 'utf8'));
1826
- return {
1827
- items: Array.isArray(q.items) ? q.items : [],
1828
- running: q.running === true,
1829
- updatedAt: q.updatedAt ?? '',
1830
- ...(typeof q.parkAfterSec === 'number' ? { parkAfterSec: q.parkAfterSec } : {}),
1831
- };
1832
- }
1833
- catch (e) {
1834
- if (e.code !== 'ENOENT')
1835
- console.error('[queue] data/queue.json could not be read:', e.message);
1936
+ const q = await readStoreJson(this.queueFile);
1937
+ if (q === undefined) {
1938
+ this.queueParked = 0;
1836
1939
  return emptyQueue();
1837
1940
  }
1941
+ if (!q || typeof q !== 'object' || Array.isArray(q))
1942
+ throw new StoreFileUnusable(this.queueFile, 'does not hold a queue');
1943
+ this.queueParked = Array.isArray(q.items) ? q.items.filter((x) => x?.status === 'parked').length : 0;
1944
+ return {
1945
+ items: Array.isArray(q.items) ? q.items : [],
1946
+ running: q.running === true,
1947
+ updatedAt: q.updatedAt ?? '',
1948
+ ...(typeof q.parkAfterSec === 'number' ? { parkAfterSec: q.parkAfterSec } : {}),
1949
+ };
1838
1950
  }
1839
1951
  /** Changes the queue in a turn of its own, so two changes never write over each other. */
1840
1952
  changeQueue(change) {
@@ -1844,6 +1956,7 @@ let OperatorService = class OperatorService {
1844
1956
  q.updatedAt = new Date().toISOString();
1845
1957
  delete q.busy;
1846
1958
  await writeFileAtomically(this.queueFile, JSON.stringify(q, null, 2));
1959
+ this.queueParked = q.items.filter((x) => x.status === 'parked').length;
1847
1960
  return q;
1848
1961
  };
1849
1962
  const done = this.queueTurn.then(run, run);
@@ -1857,22 +1970,38 @@ let OperatorService = class OperatorService {
1857
1970
  * were put, as said.
1858
1971
  */
1859
1972
  async leftoversOf(onBranch, except, saved) {
1860
- if (!onBranch)
1973
+ const owners = await this.folderOwners(onBranch, except);
1974
+ if (owners.length === 1) {
1975
+ const owner = owners[0].item.id;
1976
+ await this.changeQueue((x) => this.setQueueItem(x, owner, { setAside: [...(x.items.find((i) => i.id === owner)?.setAside ?? []), saved] }));
1861
1977
  return;
1978
+ }
1979
+ /*
1980
+ * Two or more such tasks (2026-11-19): whose each change is cannot be told, and nobody was told where the work went.
1981
+ * Each is told, in its chat, where it is kept; none has it put back, which would lay another's work on it.
1982
+ */
1983
+ for (const o of owners) {
1984
+ await this.store.addTaskNote(o.sessionId, o.taskId, `What was not committed in the folder on ${onBranch} — yours, or another set-aside task's of the queue that works there too — was put aside on the branch ${saved} while you waited. It is not put back by itself, since it cannot be told whose each change is: take back what is yours from there (git restore --source ${saved} -- <path>).`).catch(() => undefined);
1985
+ }
1986
+ }
1987
+ /**
1988
+ * The queue's tasks on "the folder as it is", set aside or carrying on at their next turn, whose work began on
1989
+ * `onBranch`: whose uncommitted changes the folder there holds.
1990
+ */
1991
+ async folderOwners(onBranch, except = '') {
1992
+ if (!onBranch)
1993
+ return [];
1862
1994
  const q = await this.readQueue();
1863
1995
  const owners = [];
1864
1996
  for (const x of q.items) {
1865
- if (x.id === except || x.branch !== 'folder' || !x.sessionId || !(x.status === 'parked' || (x.status === 'waiting' && x.resume)))
1997
+ if (x.id === except || x.branch !== 'folder' || !x.sessionId || !holdsChat(x))
1866
1998
  continue;
1867
1999
  const s = await this.store.getSession(x.sessionId);
1868
2000
  const t = s?.tasks.find((k) => k.parked && !k.parked.answer) ?? s?.tasks.at(-1);
1869
- if (s && !s.vcs?.enabled && t?.checkpoint?.branch === onBranch)
1870
- owners.push(x.id);
2001
+ if (s && t && !s.vcs?.enabled && t.checkpoint?.branch === onBranch)
2002
+ owners.push({ item: x, sessionId: s.id, taskId: t.id });
1871
2003
  }
1872
- if (owners.length !== 1)
1873
- return;
1874
- const owner = owners[0];
1875
- await this.changeQueue((x) => this.setQueueItem(x, owner, { setAside: [...(x.items.find((i) => i.id === owner)?.setAside ?? []), saved] }));
2004
+ return owners;
1876
2005
  }
1877
2006
  setQueueItem(q, id, patch) {
1878
2007
  const item = q.items.find((x) => x.id === id);
@@ -1890,8 +2019,31 @@ let OperatorService = class OperatorService {
1890
2019
  async recoverQueue() {
1891
2020
  if (this.queueRecovered)
1892
2021
  return;
1893
- this.queueRecovered = true;
2022
+ /*
2023
+ * Marked done once it has been written (second bug hunt, 2026-11-19): marked before, a write that failed once — the
2024
+ * file held a moment by a virus scanner — left a task "running" until the program was started again.
2025
+ */
2026
+ this.queueRecovering ??= this.recoverQueueOnce().then(() => {
2027
+ this.queueRecovered = true;
2028
+ }, (e) => {
2029
+ this.queueRecovering = null;
2030
+ throw e;
2031
+ });
2032
+ await this.queueRecovering;
2033
+ }
2034
+ async recoverQueueOnce() {
1894
2035
  const q = await this.readQueue();
2036
+ /*
2037
+ * The cards of set-aside tasks the queue does not hold any more (2026-11-19) — taken out, run again, the queue's file
2038
+ * lost, before this was looked after — closed, so their messages are carried on in their chats.
2039
+ */
2040
+ for (const s of await this.store.listSessions().catch(() => [])) {
2041
+ if (!s.queueItem || !s.tasks.some((t) => t.parked && !parkedOver(t.parked)))
2042
+ continue;
2043
+ const item = q.items.find((x) => x.id === s.queueItem);
2044
+ if (!item || item.sessionId !== s.id || !holdsChat(item))
2045
+ await this.releaseFromQueue(s.id, s.queueItem, undefined);
2046
+ }
1895
2047
  if (!q.running && !q.items.some((x) => x.status === 'running'))
1896
2048
  return;
1897
2049
  await this.changeQueue((x) => {
@@ -1909,6 +2061,31 @@ let OperatorService = class OperatorService {
1909
2061
  }
1910
2062
  });
1911
2063
  }
2064
+ /**
2065
+ * A chat the queue lets go of (2026-11-19): its set-aside task's card closed — "Continue" carries the message on there —
2066
+ * and, when the task had work put aside by a task after it, where that work is said in the chat, since nothing will
2067
+ * put it back now.
2068
+ */
2069
+ async releaseFromQueue(sessionId, itemId, setAside) {
2070
+ const s = await this.store.getSession(sessionId);
2071
+ if (!s || s.queueItem !== itemId)
2072
+ return;
2073
+ const open = s.tasks.find((t) => t.parked && !parkedOver(t.parked));
2074
+ if (open) {
2075
+ await this.store.updateSession(sessionId, (x) => {
2076
+ const t = x.tasks.find((y) => y.id === open.id);
2077
+ if (t?.parked && !parkedOver(t.parked))
2078
+ t.parked.answer = { kind: 'released', at: new Date().toISOString() };
2079
+ }).catch(() => undefined);
2080
+ this.bus.publish({ sessionId, taskId: open.id, type: 'queue-released', level: 'info', message: 'the queue does not hold this task any more: its card is closed, and "Continue" carries it on here' });
2081
+ }
2082
+ const last = open ?? s.tasks.at(-1);
2083
+ for (const saved of setAside ?? []) {
2084
+ if (last)
2085
+ await this.store.addTaskNote(sessionId, last.id, `What you had changed and not committed was put aside on the branch ${saved} while you waited, and the queue no longer puts it back. Take back what you need from there (git restore --source ${saved} -- <path>).`).catch(() => undefined);
2086
+ this.bus.publish({ sessionId, type: 'queue-put-back', level: 'warn', message: `what it had not committed is kept on ${saved}; the queue no longer puts it back`, data: { saved } });
2087
+ }
2088
+ }
1912
2089
  async queue() {
1913
2090
  await this.recoverQueue();
1914
2091
  return await this.withBusy(await this.readQueue());
@@ -1930,12 +2107,19 @@ let OperatorService = class OperatorService {
1930
2107
  const busy = { kind: 'chat', sessionId: holder.sessionId, title: at?.title ?? s?.name.replace(/^chat: /, '') ?? '' };
1931
2108
  return { ...q, busy };
1932
2109
  }
1933
- /** The list as the page edits it: added, changed, moved, taken out, put back to wait ("Run again"). */
1934
- async setQueue(items) {
2110
+ /**
2111
+ * The list as the page edits it: added, changed, moved, taken out, put back to wait ("Run again"). `seen` is the list
2112
+ * the page had read: the edit is put onto the queue as it is now (`rebaseEdit`), so a page that read it before a change
2113
+ * — a second tab — drops no task added since and puts back none taken out (second bug hunt, 2026-11-19).
2114
+ */
2115
+ async setQueue(items, seen) {
1935
2116
  await this.recoverQueue();
1936
2117
  const checked = checkItems(items, MAX_INSTRUCTION_CHARS);
1937
2118
  if ('problem' in checked)
1938
2119
  throw new Error(checked.problem);
2120
+ const read = seen === undefined ? undefined : checkItems(seen, Number.MAX_SAFE_INTEGER);
2121
+ if (read && 'problem' in read)
2122
+ throw new Error(`The list the page had read could not be used: ${read.problem}`);
1939
2123
  // A skill is one of Settings' (2026-10-25); whether it is for the folder is said when the task runs, in its chat.
1940
2124
  const { skills } = await this.skills();
1941
2125
  /*
@@ -1946,6 +2130,8 @@ let OperatorService = class OperatorService {
1946
2130
  const before = new Map((await this.readQueue()).items.map((x) => [x.id, x]));
1947
2131
  const runs = (x) => {
1948
2132
  const was = before.get(x.id);
2133
+ if (was && carriesOn(was, x))
2134
+ return false;
1949
2135
  return !was || was.skill !== x.skill || (x.status ?? was.status) === 'waiting';
1950
2136
  };
1951
2137
  const unknown = checked.items.findIndex((x) => x.skill && runs(x) && !skills.some((k) => k.name === x.skill));
@@ -1954,15 +2140,21 @@ let OperatorService = class OperatorService {
1954
2140
  throw new Error(`Task ${unknown + 1} is sent with the skill "${name}", which is not in Settings → Skills${skills.length > 0 ? `; there are ${skills.map((k) => k.name).join(', ')}` : ''}.`);
1955
2141
  }
1956
2142
  let problem;
2143
+ let letGo = [];
1957
2144
  const q = await this.changeQueue((x) => {
1958
- const merged = mergeItems(x.items, checked.items);
2145
+ const merged = mergeItems(x.items, read ? rebaseEdit(x.items, read.items, checked.items) : checked.items);
1959
2146
  if ('problem' in merged)
1960
2147
  problem = merged.problem;
1961
- else
2148
+ else {
2149
+ letGo = x.items.filter((was) => holdsChat(was) && !merged.items.some((now) => now.id === was.id && now.sessionId === was.sessionId && holdsChat(now)));
1962
2150
  x.items = merged.items;
2151
+ }
1963
2152
  });
1964
2153
  if (problem)
1965
2154
  throw new Error(problem);
2155
+ // Taken out, run again or started over (2026-11-19): its chat's card closed, so its message is carried on there.
2156
+ for (const was of letGo)
2157
+ await this.releaseFromQueue(was.sessionId, was.id, was.setAside);
1966
2158
  return await this.withBusy(await this.makeQueueBranches(q));
1967
2159
  }
1968
2160
  /**
@@ -2032,12 +2224,46 @@ let OperatorService = class OperatorService {
2032
2224
  .catch((e) => console.error('[queue] the queue stopped:', e.stack ?? e.message))
2033
2225
  .finally(() => {
2034
2226
  this.queueLoop = null;
2035
- void this.changeQueue((x) => {
2036
- x.running = false;
2037
- });
2227
+ void this.settleQueue();
2038
2228
  });
2039
2229
  return await this.withBusy(started);
2040
2230
  }
2231
+ /**
2232
+ * The queue's loop is over: the queue not running, and no task left "running" (second bug hunt, 2026-11-19). A task
2233
+ * whose end could not be written — the file held a moment as it ended — stayed running for good: it could not be
2234
+ * taken out or edited, Stop did nothing to it, and what depended on it waited until the program was started again.
2235
+ * Its end is written now, as it ended; one whose end is not known carries on in its chat at the next run, as after a
2236
+ * restart. Tried again a few times, the file being the one that would not be written.
2237
+ */
2238
+ async settleQueue() {
2239
+ const left = this.queueEnding;
2240
+ this.queueEnding = null;
2241
+ for (let attempt = 0;; attempt += 1) {
2242
+ try {
2243
+ await this.changeQueue((x) => {
2244
+ x.running = false;
2245
+ for (const item of x.items) {
2246
+ if (item.status !== 'running')
2247
+ continue;
2248
+ if (left?.id === item.id)
2249
+ this.setQueueItem(x, item.id, left.ended);
2250
+ else
2251
+ Object.assign(item, item.sessionId
2252
+ ? { status: 'waiting', resume: true, why: CARRIES_ON_AFTER('the queue stopped while it ran'), endedAt: new Date().toISOString() }
2253
+ : { status: 'waiting', why: undefined });
2254
+ }
2255
+ });
2256
+ return;
2257
+ }
2258
+ catch (e) {
2259
+ if (attempt >= 4) {
2260
+ console.error('[queue] the queue could not be written as stopped:', e.message);
2261
+ return;
2262
+ }
2263
+ await new Promise((r) => setTimeout(r, 1_500 * (attempt + 1)));
2264
+ }
2265
+ }
2266
+ }
2041
2267
  /**
2042
2268
  * Tasks that would wait for the operator to choose their model by hand: none of their own, and no "Model for the
2043
2269
  * worker" in Settings — a chat that names no model is asked for it by hand (`modelByHand`), and nobody is there.
@@ -2077,18 +2303,39 @@ let OperatorService = class OperatorService {
2077
2303
  if (!this.queueAtWork.has(key))
2078
2304
  return;
2079
2305
  const timerKey = kind === 'password' ? `pw:${approval.sessionId}` : approval.id;
2080
- void this.readQueue().then((q) => {
2306
+ // Read again a few times when queue.json is busy (third hunt, 2026-11-20): one failed read set no timer, said nothing.
2307
+ const readSoon = async () => {
2308
+ for (let i = 0;; i++) {
2309
+ try {
2310
+ return await this.readQueue();
2311
+ }
2312
+ catch (e) {
2313
+ if (i >= 3)
2314
+ throw e;
2315
+ await new Promise((r) => setTimeout(r, 1_000 * (i + 1)));
2316
+ }
2317
+ }
2318
+ };
2319
+ void readSoon().then((q) => {
2081
2320
  const ms = parkAfterMs(q);
2082
2321
  if (ms === null || this.parkTimers.has(timerKey))
2083
2322
  return;
2084
2323
  const timer = setTimeout(() => {
2085
2324
  this.parkTimers.delete(timerKey);
2086
2325
  const still = kind === 'password' ? this.passwordAsked.has(approval.sessionId) : this.waiting.has(approval.id);
2087
- if (still)
2088
- void this.park(key, approval, kind, ms).catch((e) => console.error('[queue] the task could not be set aside:', e.message));
2326
+ if (!still)
2327
+ return;
2328
+ if (kind !== 'password')
2329
+ this.parking.add(approval.id);
2330
+ void this.park(key, approval, kind, ms)
2331
+ .catch((e) => console.error('[queue] the task could not be set aside:', e.message))
2332
+ .finally(() => this.parking.delete(approval.id));
2089
2333
  }, ms);
2090
2334
  timer.unref?.();
2091
2335
  this.parkTimers.set(timerKey, timer);
2336
+ }).catch((e) => {
2337
+ this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'queue-park-unread', level: 'warn',
2338
+ message: `the queue could not be read, so this card is not set aside when its time is up; it waits here: ${e.message}` });
2092
2339
  });
2093
2340
  }
2094
2341
  unparkLater(timerKey) {
@@ -2136,16 +2383,31 @@ let OperatorService = class OperatorService {
2136
2383
  await this.recoverQueue();
2137
2384
  const q = await this.readQueue();
2138
2385
  const item = q.items.find((x) => x.id === itemId);
2139
- if (!item)
2140
- throw new Error('That task is not in the queue any more.');
2141
- if (item.status !== 'parked' || !item.sessionId)
2142
- throw new Error('That task is not waiting for an answer.');
2143
2386
  /*
2144
- * The card of another run of it (bug hunt 2026-11-18): a card left in the chat of an earlier run — stopped, run
2145
- * again, or a task removed whose id a new one took — answered the card the queue's task waits on now, unseen.
2387
+ * A card the queue does not hold any more (2026-11-19): its task taken out, run again or started over, or set aside
2388
+ * again in another chat. Every button failed, Stop included, and "Continue" was refused: the card is closed now, at
2389
+ * any press, and "Continue" carries its message on in its own chat. A Stop of it is simply taken.
2146
2390
  */
2147
- if (typeof input?.sessionId === 'string' && input.sessionId !== item.sessionId) {
2148
- throw new Error('That card is of another run of this task: what the task waits for now is on the queue\'s page.');
2391
+ const from = typeof input?.sessionId === 'string' ? input.sessionId : undefined;
2392
+ /*
2393
+ * Answered already, on another page, and waiting to carry on with that answer (third hunt, 2026-11-20): a copy of the
2394
+ * card not yet refreshed was read as one the queue let go of, and its press overwrote the answer with "let go" — a
2395
+ * plan approved was asked for again, a pasted output lost — and a Stop was said taken while the task went on.
2396
+ */
2397
+ if (item && item.status !== 'parked' && holdsChat(item) && (!from || from === item.sessionId))
2398
+ throw new Error(PARKED_ALREADY_ANSWERED);
2399
+ if (!item || item.status !== 'parked' || !item.sessionId || (from && from !== item.sessionId)) {
2400
+ const of = from ?? (item?.status === 'parked' ? undefined : item?.sessionId);
2401
+ if (of)
2402
+ await this.releaseFromQueue(of, itemId);
2403
+ if (input?.stop === true && of)
2404
+ return await this.queue();
2405
+ if (!item)
2406
+ throw new Error(`That task is not in the queue any more. ${PARKED_RELEASED}`);
2407
+ // The card of another run of it (bug hunt 2026-11-18): it answered the card the queue's task waits on now, unseen.
2408
+ if (from && item.sessionId && from !== item.sessionId)
2409
+ throw new Error(`That card is of another run of this task: what the task waits for now is on the queue's page. ${PARKED_RELEASED}`);
2410
+ throw new Error(`That task is not waiting for an answer. ${PARKED_RELEASED}`);
2149
2411
  }
2150
2412
  const s = await this.store.getSession(item.sessionId);
2151
2413
  const task = s?.tasks.find((t) => t.parked && !t.parked.answer);
@@ -2160,10 +2422,15 @@ let OperatorService = class OperatorService {
2160
2422
  t.parked.answer = { kind: 'stopped', at: new Date().toISOString() };
2161
2423
  }).catch(() => undefined);
2162
2424
  }
2163
- return await this.withBusy(await this.changeQueue((x) => this.setQueueItem(x, itemId, { status: 'stopped', why: 'stopped by the operator at its card', waitsFor: undefined })));
2425
+ // Its work put aside by a task after it is not put back now (2026-11-19): where it is, said in its chat.
2426
+ if (item.setAside?.length)
2427
+ await this.releaseFromQueue(item.sessionId, itemId, item.setAside);
2428
+ return await this.withBusy(await this.changeQueue((x) => this.setQueueItem(x, itemId, { status: 'stopped', why: 'stopped by the operator at its card', waitsFor: undefined, setAside: undefined })));
2164
2429
  }
2165
2430
  if (!s || !task?.parked)
2166
2431
  throw new Error('What that task waited for is not on its record any more; run it again.');
2432
+ if (s.tasks.at(-1)?.id !== task.id)
2433
+ throw new Error(PARKED_PASSED);
2167
2434
  const answer = parkedAnswerFrom(task.parked, input);
2168
2435
  if ('problem' in answer)
2169
2436
  throw new Error(answer.problem);
@@ -2205,7 +2472,10 @@ let OperatorService = class OperatorService {
2205
2472
  // An answered parked task keeps its chat: it carries on there.
2206
2473
  await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, waitsFor: undefined, resume: undefined, ...(item.resume ? {} : { sessionId: undefined }) }));
2207
2474
  const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
2208
- await this.changeQueue((x) => this.setQueueItem(x, item.id, { ...ended, endedAt: now() }));
2475
+ // Kept until written: a write that fails ends the loop, and the end is written when it is over (`settleQueue`).
2476
+ this.queueEnding = { id: item.id, ended: { ...ended, endedAt: now() } };
2477
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, this.queueEnding.ended));
2478
+ this.queueEnding = null;
2209
2479
  // Stopped — from the queue, or the chat's Stop: the rest wait for the operator. Parked: the queue goes on.
2210
2480
  if (ended.status === 'stopped')
2211
2481
  return;
@@ -2217,7 +2487,21 @@ let OperatorService = class OperatorService {
2217
2487
  /** One task of the queue, in a new chat — or, answered after it was parked, in its own — to its end. */
2218
2488
  async runQueueItem(item) {
2219
2489
  const pause = (ms) => new Promise((r) => setTimeout(r, ms));
2220
- const stillRunning = async () => (await this.readQueue()).running;
2490
+ /*
2491
+ * Whether the queue still runs, as last read when queue.json is busy or unreadable for a moment (third hunt,
2492
+ * 2026-11-20): a lock held a second longer than the reads wait made this poll — once a second for the whole task —
2493
+ * throw, the task was ended "failed" while its chat's run went on, and its cards were never set aside.
2494
+ */
2495
+ let lastRunning = true;
2496
+ const stillRunning = async () => {
2497
+ try {
2498
+ lastRunning = (await this.readQueue()).running;
2499
+ }
2500
+ catch {
2501
+ /* as last read */
2502
+ }
2503
+ return lastRunning;
2504
+ };
2221
2505
  // Read afresh each time: the browser is let go of by other work while this waits.
2222
2506
  const holder = () => this.browser;
2223
2507
  // The browser may be the chat's, or a reading of the models': the task waits its turn.
@@ -2237,10 +2521,21 @@ let OperatorService = class OperatorService {
2237
2521
  let carryOn = false;
2238
2522
  if (item.resume && item.sessionId) {
2239
2523
  const s0 = await this.store.getSession(item.sessionId);
2240
- const answered = s0?.tasks.find((t) => t.parked?.answer && t.parked.answer.kind !== 'stopped');
2524
+ const answered = s0?.tasks.find((t) => t.parked?.answer && !parkedOver(t.parked));
2241
2525
  const last = s0?.tasks.at(-1);
2242
2526
  if (!s0 || !last)
2243
2527
  return { status: 'failed', why: 'its chat is not there any more; run it again' };
2528
+ /*
2529
+ * A carry-on that fails before it carries on (third hunt, 2026-11-20): the chat was kept with an answered card — its
2530
+ * "Continue" refused as "the queue carries it on", which it would not now, and no card on the queue's page — and its
2531
+ * work put aside by a task after it was never named. The queue lets go of it, saying where that work is.
2532
+ */
2533
+ const failed = async (why) => {
2534
+ const left = (await this.readQueue()).items.find((x) => x.id === item.id)?.setAside ?? item.setAside;
2535
+ await this.releaseFromQueue(s0.id, item.id, left);
2536
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, { setAside: undefined })).catch(() => undefined);
2537
+ return { status: 'failed', why, sessionId: s0.id };
2538
+ };
2244
2539
  /*
2245
2540
  * Back on the branch it began on, a task on "the folder as it is" (bug hunt 2026-11-18): it carried on on whatever
2246
2541
  * branch the task after it left the folder on — one made for another task. What that left uncommitted is put
@@ -2252,15 +2547,16 @@ let OperatorService = class OperatorService {
2252
2547
  if (onNow !== began) {
2253
2548
  const aside = await setAsideUncommitted(ws.dir, `the queue's task "${itemTitle(item)}" carries on on ${began}, where it began, and the folder held changes left on ${onNow ?? 'a detached HEAD'}`);
2254
2549
  if (aside && 'problem' in aside)
2255
- return { status: 'failed', why: `what was not committed in the folder could not be put aside before it: ${aside.problem}`, sessionId: s0.id };
2550
+ return await failed(`what was not committed in the folder could not be put aside before it: ${aside.problem}`);
2551
+ // Kept for whose it is first (2026-11-19): a switch that failed after it said nothing of where it went.
2552
+ if (aside && 'saved' in aside)
2553
+ await this.leftoversOf(onNow, item.id, aside.saved);
2256
2554
  const back = await git(ws.dir, ['switch', began]);
2257
2555
  if (!back.ok)
2258
- return { status: 'failed', why: `it could not be put back on ${began}, where it began: ${(back.stderr || back.stdout).trim().slice(0, 300)}`, sessionId: s0.id };
2556
+ return await failed(`it could not be put back on ${began}, where it began: ${(back.stderr || back.stdout).trim().slice(0, 300)}${aside ? `; what was not committed in the folder is kept on ${aside.saved}, not pushed` : ''}`);
2259
2557
  this.bus.publish({ sessionId: s0.id, type: 'queue-back-on-branch', level: 'info',
2260
2558
  message: `back on ${began}, where it began, before it carries on (the folder was on ${onNow ?? 'a detached HEAD'})${aside ? `; what was not committed there is kept on ${aside.saved}, not pushed` : ''}`,
2261
2559
  data: { branch: began, was: onNow, ...(aside ? { saved: aside.saved } : {}) } });
2262
- if (aside && 'saved' in aside)
2263
- await this.leftoversOf(onNow, item.id, aside.saved);
2264
2560
  }
2265
2561
  }
2266
2562
  // Its own work, put aside by a task after it on a branch of its own (2026-11-18): put back before it carries on.
@@ -2278,7 +2574,7 @@ let OperatorService = class OperatorService {
2278
2574
  if (answered) {
2279
2575
  const carried = await this.resumeParked(item.sessionId, ws.dir);
2280
2576
  if ('problem' in carried)
2281
- return { status: 'failed', why: carried.problem, sessionId: item.sessionId };
2577
+ return await failed(carried.problem);
2282
2578
  taskId = carried.taskId;
2283
2579
  }
2284
2580
  else {
@@ -2419,7 +2715,14 @@ let OperatorService = class OperatorService {
2419
2715
  if ((asked || !(await stillRunning())) && task && (task.status === 'queued' || isContinuable(task))) {
2420
2716
  return { status: 'waiting', resume: true, why: CARRIES_ON_AFTER('the queue was stopped while it ran'), sessionId };
2421
2717
  }
2422
- const status = statusOfTask(task?.status);
2718
+ const byOperator = this.endedByOperator.get(sessionId) === true;
2719
+ this.endedByOperator.delete(sessionId);
2720
+ /*
2721
+ * Stopped by nobody — its conversation lost, its window closed past the times it is opened again (2026-11-19): it
2722
+ * ended stopped so that its chat offers "Continue", but only the operator's Stop stops the queue. It failed: what
2723
+ * depends on it is skipped, the others run, and its chat carries it on when the operator chooses.
2724
+ */
2725
+ const status = task?.status === 'aborted' && !byOperator ? 'failed' : statusOfTask(task?.status);
2423
2726
  return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
2424
2727
  }
2425
2728
  /**
@@ -2431,11 +2734,14 @@ let OperatorService = class OperatorService {
2431
2734
  async resumeParked(sessionId, dir) {
2432
2735
  const s = await this.store.getSession(sessionId);
2433
2736
  // Not one stopped at its card (2026-11-18): that is an answer that does not carry it on.
2434
- const task = s?.tasks.find((t) => t.parked?.answer && t.parked.answer.kind !== 'stopped');
2737
+ const task = s?.tasks.find((t) => t.parked?.answer && !parkedOver(t.parked));
2435
2738
  const p = task?.parked;
2436
2739
  const a = p?.answer;
2437
- if (!s || !task || !p || !a || a.kind === 'stopped')
2740
+ if (!s || !task || !p || !a || a.kind === 'stopped' || a.kind === 'released')
2438
2741
  return { problem: 'its answer is not on its record any more; run it again' };
2742
+ // Only the last message of a conversation is carried on, as "Continue" holds it (2026-11-19).
2743
+ if (s.tasks.at(-1)?.id !== task.id)
2744
+ return { problem: 'its chat went on past it (a message was written there since), so it is not carried on: say what it still needs in a new message there' };
2439
2745
  const continuing = { fromAttempt: task.attempt ?? 1, stoppedBecause: task.reason, how: 'parked', parkedFor: p.kind };
2440
2746
  let note = '';
2441
2747
  let approvedPlan;
@@ -2480,6 +2786,7 @@ let OperatorService = class OperatorService {
2480
2786
  const last = worker?.tasks.find((t) => t.id === p.approval.taskId);
2481
2787
  const ended = last ? [`Its last attempt ended ${last.status}${last.reason ? `: ${last.reason}` : ''}.`, ...(last.summary?.trim() ? ['', 'The worker\'s summary:', '', last.summary.trim()] : [])] : [];
2482
2788
  note = [`Subtask ${r.n} (${r.title}) is taken as failed, at the operator's word: decide what to do next without it.`, ...(ended.length > 0 ? ['', ...ended] : [])].join('\n');
2789
+ continuing.takenAsFailed = { n: r.n };
2483
2790
  }
2484
2791
  else {
2485
2792
  if (a.choice === 'restore') {
@@ -2491,7 +2798,7 @@ let OperatorService = class OperatorService {
2491
2798
  const cp = worker?.tasks.find((t) => t.id === first)?.checkpoint;
2492
2799
  const back = cp ? await restoreCheckpoint(dir, cp) : { ok: false, problem: 'the subtask\'s start was not photographed' };
2493
2800
  if (!back.ok)
2494
- return { problem: `the folder could not be put back to the subtask's start (${back.problem}); answer it again with another choice` };
2801
+ return { problem: `the folder could not be put back to the subtask's start (${back.problem}); carry the message on in its chat with "Continue", or run the task again` };
2495
2802
  }
2496
2803
  // Put back: the next attempt is told it starts over, not to carry on from what the last one left.
2497
2804
  continuing.retrySubtask = { n: r.n, ...(a.choice === 'fresh' ? { fresh: true } : {}), ...(a.choice === 'restore' ? { restored: true } : {}) };
@@ -2738,6 +3045,8 @@ let OperatorService = class OperatorService {
2738
3045
  }
2739
3046
  /** The operator's choice for a subtask that failed for a technical reason: one of the card's own. */
2740
3047
  answerRetry(approvalId, choice, as) {
3048
+ if (this.parking.has(approvalId))
3049
+ return { ok: false, problem: SET_ASIDE_NOW };
2741
3050
  const w = this.waiting.get(approvalId);
2742
3051
  if (!w?.resolveRetry || !w.approval.retry)
2743
3052
  return { ok: false, problem: 'No subtask is waiting for a choice under that id.' };
@@ -2795,6 +3104,14 @@ let OperatorService = class OperatorService {
2795
3104
  const last = sub.attempts?.at(-1);
2796
3105
  if (last?.status === 'done')
2797
3106
  throw new Error(`Subtask ${n} was done; it is not done again.`);
3107
+ /*
3108
+ * A queue task set aside, or answered on its card (third hunt, 2026-11-20): tried again here, its record moved into
3109
+ * the attempts and the queue's card failed at every press but Stop, the task and those after it waiting for good.
3110
+ */
3111
+ if (task.parked && !task.parked.answer)
3112
+ throw new Error('This message waits for an answer on its card in the queue: answer it there, and the queue carries it on.');
3113
+ if (!parkedOver(task.parked))
3114
+ throw new Error(PARKED_ANSWERED);
2798
3115
  // The browser first, as for Continue (2026-11-18): nothing changes when it is not free.
2799
3116
  const busy = this.browserBusyFor(threadId);
2800
3117
  if (busy)
@@ -2838,6 +3155,12 @@ let OperatorService = class OperatorService {
2838
3155
  // A queue task set aside is answered on its card (2026-11-18): carried on here, its queue entry lost what it waited for.
2839
3156
  if (task.parked && !task.parked.answer)
2840
3157
  throw new Error('This message waits for an answer on its card in the queue: answer it there, and the queue carries it on.');
3158
+ /*
3159
+ * Answered on its card, the queue carries it on with the answer (2026-11-19): carried on here instead, the answer was
3160
+ * filed under the attempt before and lost — a plan approved was asked for again, a question's answer never sent.
3161
+ */
3162
+ if (!parkedOver(task.parked))
3163
+ throw new Error(PARKED_ANSWERED);
2841
3164
  const busy = this.browserBusyFor(threadId);
2842
3165
  if (busy)
2843
3166
  throw new Error(busy);
@@ -2864,6 +3187,8 @@ let OperatorService = class OperatorService {
2864
3187
  return await this.start(threadId, cfg.execution.mode);
2865
3188
  }
2866
3189
  answerQuestion(approvalId, text, ran, outcome, chosen, as) {
3190
+ if (this.parking.has(approvalId))
3191
+ return { ok: false, problem: SET_ASIDE_NOW };
2867
3192
  const w = this.waiting.get(approvalId);
2868
3193
  if (!w?.resolveAnswer)
2869
3194
  return { ok: false, problem: 'No question of the lead is waiting under that id.' };
@@ -2938,6 +3263,8 @@ let OperatorService = class OperatorService {
2938
3263
  * another (saying what to change), or stop the task.
2939
3264
  */
2940
3265
  decidePlan(approvalId, action, note, as) {
3266
+ if (this.parking.has(approvalId))
3267
+ return { ok: false, problem: SET_ASIDE_NOW };
2941
3268
  const w = this.waiting.get(approvalId);
2942
3269
  if (!w || !w.resolvePlan)
2943
3270
  return { ok: false, problem: 'That plan is not waiting any more.' };
@@ -2960,7 +3287,26 @@ let OperatorService = class OperatorService {
2960
3287
  /** What waits for the operator; of one session, its worker's included (two chats: they are asked in its conversation). */
2961
3288
  pendingApprovals(sessionId) {
2962
3289
  // Kerrigan's (2026-11-12): the cards of the chats she directs, and of their workers, are shown in hers too.
2963
- return [...this.waiting.values()].map((w) => w.approval).filter((a) => !sessionId || this.under(a.sessionId, sessionId));
3290
+ return [...this.waiting.values()]
3291
+ .map((w) => w.approval)
3292
+ .filter((a) => !sessionId || this.under(a.sessionId, sessionId))
3293
+ .map((a) => {
3294
+ const off = this.runAllOff(a);
3295
+ return off ? { ...a, runAllOff: off } : a;
3296
+ });
3297
+ }
3298
+ /**
3299
+ * What keeps "Run this and the rest" from this command's card, read as the card is shown (2026-11-19): under the
3300
+ * default Settings — no isolation — it was offered on every card and refused at every press. Only a command's card
3301
+ * has it, and not one that downloads or reaches a platform, which is asked about in every run anyway.
3302
+ */
3303
+ runAllOff(a) {
3304
+ if (a.plan || a.question || a.retry || a.model || a.network || a.platform)
3305
+ return undefined;
3306
+ const run = this.running.get(this.runKey(a.sessionId));
3307
+ if (!run || run.mode === 'unattended')
3308
+ return undefined;
3309
+ return unattendedBlock(run.policy) ?? undefined;
2964
3310
  }
2965
3311
  /**
2966
3312
  * Answers one pending approval.
@@ -2971,6 +3317,8 @@ let OperatorService = class OperatorService {
2971
3317
  * in the rest. The deny list is untouched by it.
2972
3318
  */
2973
3319
  decide(approvalId, action) {
3320
+ if (this.parking.has(approvalId))
3321
+ return { ok: false, problem: SET_ASIDE_NOW };
2974
3322
  const w = this.waiting.get(approvalId);
2975
3323
  // Said (bug hunt 2026-11-18): answered "ok: false" with 200, the press looked taken, and the card went on waiting.
2976
3324
  if (!w)
@@ -2992,7 +3340,7 @@ let OperatorService = class OperatorService {
2992
3340
  if (action === 'run-all')
2993
3341
  this.setRunMode(this.runKey(w.approval.sessionId), 'unattended');
2994
3342
  const decision = action === 'run' || action === 'run-all'
2995
- ? { action: 'run' }
3343
+ ? { action: 'run', by: 'operator' }
2996
3344
  : action === 'skip'
2997
3345
  ? { action: 'skip', reason: 'skipped by the operator', by: 'operator' }
2998
3346
  : { action: 'abort', reason: 'aborted by the operator', by: 'operator' };
@@ -3068,6 +3416,9 @@ let OperatorService = class OperatorService {
3068
3416
  continue;
3069
3417
  if (w.approval.scripts && run.policy.writtenScripts !== 'run')
3070
3418
  continue;
3419
+ // Being set aside by the queue (2026-11-19): its answer is given on the queue's page.
3420
+ if (this.parking.has(id))
3421
+ continue;
3071
3422
  this.waiting.delete(id);
3072
3423
  w.resolve({ action: 'run' });
3073
3424
  }
@@ -3394,6 +3745,44 @@ let OperatorService = class OperatorService {
3394
3745
  * The repository check travels with it because the two questions are always asked together:
3395
3746
  * somewhere to work, and whether that somewhere can be branched and committed.
3396
3747
  */
3748
+ /**
3749
+ * "Open a folder" in the workbench (second bug hunt, 2026-11-19): the folder becomes the project. It kept the name,
3750
+ * the level 2 and "for reference only" of the one before — a folder opened to work in was then for reference only,
3751
+ * every change put back, and Kerrigan given another project's notes. One of the other projects comes with its own,
3752
+ * and the one before takes its place among them; any other folder comes with what it had when it was the project
3753
+ * before, or with nothing, and the one before is remembered with its own.
3754
+ */
3755
+ async openProjectFolder(dir) {
3756
+ const target = dir.trim();
3757
+ if (!target || !existsSync(target))
3758
+ throw new Error(`The folder ${target || '(none)'} does not exist on this machine.`);
3759
+ await this.settings.update((raw) => {
3760
+ const current = (raw.project ?? {});
3761
+ const was = { rootDir: (current.rootDir ?? '').trim(), name: (current.name ?? '').trim(), level2: current.level2 ?? '', readOnly: current.readOnly === true };
3762
+ if (was.rootDir && sameFolder(was.rootDir, target))
3763
+ return raw;
3764
+ const others = (current.others ?? []);
3765
+ let earlier = (current.earlier ?? []).filter((e) => e.rootDir && !sameFolder(e.rootDir, target) && !(was.rootDir && sameFolder(e.rootDir, was.rootDir)));
3766
+ const i = others.findIndex((o) => o.rootDir && sameFolder(o.rootDir, target));
3767
+ let next;
3768
+ let nextOthers = others;
3769
+ if (i >= 0) {
3770
+ const o = others[i];
3771
+ next = { rootDir: o.rootDir, name: o.name ?? '', level2: o.level2 ?? '', readOnly: o.readOnly === true };
3772
+ nextOthers = was.rootDir
3773
+ ? others.map((x, j) => (j === i ? { name: was.name || basename(was.rootDir) || was.rootDir, rootDir: was.rootDir, level2: was.level2, readOnly: was.readOnly } : x))
3774
+ : others.filter((_, j) => j !== i);
3775
+ }
3776
+ else {
3777
+ const before = (current.earlier ?? []).find((e) => e.rootDir && sameFolder(e.rootDir, target));
3778
+ next = { rootDir: target, name: before?.name ?? '', level2: before?.level2 ?? '', readOnly: before?.readOnly === true };
3779
+ if (was.rootDir && (was.name || was.level2.trim() || was.readOnly))
3780
+ earlier = [was, ...earlier].slice(0, 20);
3781
+ }
3782
+ return { ...raw, project: { ...current, ...next, others: nextOthers, earlier } };
3783
+ });
3784
+ return await this.project();
3785
+ }
3397
3786
  async project() {
3398
3787
  const cfg = await this.settings.load();
3399
3788
  const rootDir = (cfg.project?.rootDir ?? '').trim();
@@ -3494,10 +3883,14 @@ let OperatorService = class OperatorService {
3494
3883
  }
3495
3884
  /*
3496
3885
  * A project that may be changed inside one for reference only (bug hunt 2026-11-18): every change made in it would
3497
- * be put back after each step, so no task there could finish. Refused, with what to do.
3886
+ * be put back after each step, so no task there could finish. Refused, with what to do. Not the chat's own folder
3887
+ * (second bug hunt, 2026-11-19): inside one for reference only, every message there only reads and reports, as
3888
+ * Kerrigan's text says and the chat is told — and "Open a folder" can make it so, after which every save of the
3889
+ * projects, a name or a level 2, was refused for it.
3498
3890
  */
3499
- const all = [{ name: name || rootDir, rootDir, readOnly }, ...others].filter((p) => p.rootDir);
3500
- for (const w of all.filter((p) => !p.readOnly)) {
3891
+ const chats = { name: name || rootDir, rootDir, readOnly };
3892
+ const all = [chats, ...others].filter((p) => p.rootDir);
3893
+ for (const w of all.filter((p) => !p.readOnly && p !== chats)) {
3501
3894
  const r = all.find((p) => p.readOnly && p !== w && folderInside(w.rootDir, p.rootDir));
3502
3895
  if (r) {
3503
3896
  throw new Error(`${w.name} (${w.rootDir}) is inside ${r.name} (${r.rootDir}), which is for reference only: every change made in it would be put back after each step. Untick "for reference only" on ${r.name}, or list for reference only the folders of it beside ${w.name}.`);
@@ -3615,6 +4008,9 @@ let OperatorService = class OperatorService {
3615
4008
  if (upn && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(upn)) {
3616
4009
  throw new Error(`"${upn}" is not an account address. Give the work or school address, for example name@company.com, or leave it empty.`);
3617
4010
  }
4011
+ // The run's own window waits for exactly that (2026-11-19): it was refused "once the run has finished", which never came.
4012
+ if (this.signInAsked.size > 0 && this.running.size > 0)
4013
+ throw new Error(SIGN_IN_IN_THE_RUNS_WINDOW);
3618
4014
  const claim = this.claimBrowser({ kind: 'login' });
3619
4015
  if ('refused' in claim)
3620
4016
  throw new Error(claim.refused);
@@ -3697,14 +4093,11 @@ let OperatorService = class OperatorService {
3697
4093
  keepFailurePage: cfg.copilot.keepFailurePage,
3698
4094
  // The rows' locator reads the names (Settings' own, 2026-10-24).
3699
4095
  ...pickerOptions(cfg),
3700
- onEvent: (event, detail) => {
3701
- if (event === 'locator-missing' && detail)
3702
- this.recordLocatorFailure(detail);
3703
- },
4096
+ onEvent: (event, detail) => this.onReadingEvent(event, detail),
3704
4097
  });
3705
4098
  await this.closeChatWindow('reading the models needs the browser');
3706
4099
  await transport.open();
3707
- await transport.ensureSignedIn();
4100
+ await transport.ensureSignedIn(undefined, { boxNotWaited: true });
3708
4101
  const { options, current, note } = await transport.listModels();
3709
4102
  const catalogue = { options, current: current ?? undefined, readAt: new Date().toISOString(), note };
3710
4103
  await this.store.saveModels(catalogue);
@@ -3729,10 +4122,26 @@ let OperatorService = class OperatorService {
3729
4122
  return catalogue;
3730
4123
  }
3731
4124
  finally {
4125
+ this.readingSignIn = false;
3732
4126
  await transport?.close().catch(() => undefined);
3733
4127
  this.releaseBrowser(claim.holder);
3734
4128
  }
3735
4129
  }
4130
+ /**
4131
+ * What the window of a reading says (the models, "Check the locators"): a locator that found nothing is kept; a sign-in
4132
+ * it waits for is said on the tab and on the page that asked (2026-11-19), where there was only a button that went on
4133
+ * turning.
4134
+ */
4135
+ onReadingEvent(event, detail) {
4136
+ if (event === 'locator-missing' && detail)
4137
+ this.recordLocatorFailure(detail);
4138
+ if (event === 'locator-found' && detail)
4139
+ this.locatorFound(detail);
4140
+ if (event === 'sign-in-required')
4141
+ this.readingSignIn = true;
4142
+ if (event === 'signed-in')
4143
+ this.readingSignIn = false;
4144
+ }
3736
4145
  /**
3737
4146
  * "Check the locators" (operator, 2026-11-17): the Copilot window opened as for reading the models, each of the chat's
3738
4147
  * locators looked for (`checkLocators`, which only reads and looks), and the window closed. One that found nothing is
@@ -3755,17 +4164,14 @@ let OperatorService = class OperatorService {
3755
4164
  headless: cfg.copilot.headless,
3756
4165
  keepFailurePage: cfg.copilot.keepFailurePage,
3757
4166
  ...pickerOptions(cfg),
3758
- onEvent: (event, detail) => {
3759
- if (event === 'locator-missing' && detail)
3760
- this.recordLocatorFailure(detail);
3761
- },
4167
+ onEvent: (event, detail) => this.onReadingEvent(event, detail),
3762
4168
  });
3763
4169
  await this.closeChatWindow('checking the locators needs the browser');
3764
4170
  await transport.open();
3765
4171
  let results;
3766
4172
  try {
3767
4173
  // A step of the operator's own that is not there does not stop a check, which only reads: each is looked for below.
3768
- await transport.ensureSignedIn(undefined, { stepsLookOnly: true });
4174
+ await transport.ensureSignedIn(undefined, { stepsLookOnly: true, boxNotWaited: true });
3769
4175
  results = await transport.checkLocators();
3770
4176
  }
3771
4177
  catch (e) {
@@ -3781,6 +4187,7 @@ let OperatorService = class OperatorService {
3781
4187
  return { checkedAt: new Date().toISOString(), results };
3782
4188
  }
3783
4189
  finally {
4190
+ this.readingSignIn = false;
3784
4191
  await transport?.close().catch(() => undefined);
3785
4192
  this.releaseBrowser(claim.holder);
3786
4193
  }
@@ -3830,7 +4237,7 @@ let OperatorService = class OperatorService {
3830
4237
  return raw;
3831
4238
  });
3832
4239
  const chosen = chooseHome(layout, dir, copy);
3833
- console.log(`[home] the bot's folder will be ${chosen.home} from its next start${chosen.copied.length ? ` (copied: ${chosen.copied.join(', ')})` : ''}`);
4240
+ console.log(`[home] the bot's folder will be ${chosen.home} from its next start${chosen.copied.length ? ` (copied: ${chosen.copied.join(', ')})` : ''}${chosen.asideDir ? `; what it had put aside in ${chosen.asideDir}` : ''}`);
3834
4241
  return { ...chosen, restart: true };
3835
4242
  }
3836
4243
  async doctor() {