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
@@ -120,6 +120,14 @@ export function mergeItems(current, edited) {
120
120
  // A parked task keeps what it waits for; its answer is given on its card, not by an edit of the list.
121
121
  if (was.status === 'parked')
122
122
  return { ...was, ...given, status: 'parked' };
123
+ /*
124
+ * A task that carries on in its own chat (`resume`: the queue stopped or the bot closed under it, or answered after it
125
+ * was set aside) carries on as it was given there, so an edit of what it does was kept and never used (bug hunt
126
+ * 2026-11-18). Such an edit starts it over, as "Run again" does, with the edit; its name and what it depends on are
127
+ * the queue's own, and leave it carrying on.
128
+ */
129
+ if (was.resume && WHAT_IT_DOES.some((key) => asSaid(was[key]) !== asSaid(given[key])))
130
+ return { ...given, status: 'waiting' };
123
131
  // Where it works changed: the branch made for it no longer is its.
124
132
  if (was.branch !== given.branch) {
125
133
  const { branchName: _name, branchBase: _base, ...rest } = was;
@@ -135,6 +143,10 @@ export function mergeItems(current, edited) {
135
143
  }
136
144
  /** What the operator gives a task, apart from what its runs give it. */
137
145
  const GIVEN = ['id', 'name', 'prompt', 'model', 'dependsOn', 'branch', 'review', 'reviewModel', 'lead', 'workerModel', 'skill', 'plan'];
146
+ /** Of what is given, what the task's chat is told: an edit of it starts over a task that carries on. */
147
+ const WHAT_IT_DOES = ['prompt', 'model', 'branch', 'review', 'reviewModel', 'lead', 'workerModel', 'skill', 'plan'];
148
+ /** A field as an edit says it: off, empty or left out are the same. */
149
+ const asSaid = (v) => JSON.stringify(v === false || v === '' || v === null ? undefined : v) ?? '';
138
150
  function asGiven(x) {
139
151
  const out = {};
140
152
  for (const key of GIVEN)
@@ -38,29 +38,54 @@ export async function makeQueueBranch(dir, id, title, start) {
38
38
  return { problem: (made.stderr || made.stdout || `the branch ${branch} could not be made`).split(/\r?\n/)[0] };
39
39
  return { branch, base: start.commit };
40
40
  }
41
+ /** The remotes of a repository, by name. */
42
+ async function remotesOf(dir) {
43
+ return (await git(dir, ['remote'])).stdout.split(/\r?\n/).map((r) => r.trim()).filter(Boolean);
44
+ }
45
+ /**
46
+ * The remote's branch a queue branch is brought up to: the one it was made from (`origin/master`, `upstream/main`), or,
47
+ * made from a local main when the remote could not be read then, that main on the remote (`origin` first). Not `main`
48
+ * of `origin` whatever the repository has (bug hunt 2026-11-18): one whose remote's default is `master`, or whose remote
49
+ * is not `origin`, was never brought up to date, and its chat was told it was made from a local main.
50
+ */
51
+ export async function remoteMainOf(dir, from) {
52
+ const remotes = await remotesOf(dir);
53
+ const said = (from ?? '').trim();
54
+ const at = said.indexOf('/');
55
+ if (at > 0 && remotes.includes(said.slice(0, at)))
56
+ return { remote: said.slice(0, at), ref: said.slice(at + 1) };
57
+ const remote = remotes.includes('origin') ? 'origin' : remotes[0];
58
+ return remote ? { remote, ref: said || 'main' } : null;
59
+ }
60
+ /** Whether a branch was made from a remote's branch (`origin/main`), not from a local one (`main`). */
61
+ export async function madeFromRemote(dir, from) {
62
+ const at = from.indexOf('/');
63
+ return at > 0 && (await remotesOf(dir)).includes(from.slice(0, at));
64
+ }
41
65
  /**
42
66
  * At the task's start: the branch brought up to the remote's main when nothing has been done on it yet — still at the
43
67
  * commit it was made at — and the remote can be read without asking anybody (nobody may be there). Forward only.
68
+ * `from`: what it was made from (`BranchStart.from`), which names the remote and its main.
44
69
  */
45
- export async function refreshQueueBranch(dir, branch, base) {
70
+ export async function refreshQueueBranch(dir, branch, base, from) {
46
71
  const tip = (await git(dir, ['rev-parse', '--verify', '--quiet', `refs/heads/${branch}^{commit}`])).stdout;
47
72
  if (!tip)
48
73
  return { base, moved: false, detail: `there is no branch ${branch} any more` };
49
74
  if (tip !== base)
50
75
  return { base, moved: false, detail: 'work is on it already' };
51
- const remotes = (await git(dir, ['remote'])).stdout.split(/\r?\n/).map((r) => r.trim()).filter(Boolean);
52
- const remote = remotes.includes('origin') ? 'origin' : remotes[0];
53
- if (!remote)
76
+ const main = await remoteMainOf(dir, from);
77
+ if (!main)
54
78
  return { base, moved: false, detail: 'no remote' };
55
- const fetched = await fetchAsOperator(dir, remote, { askpass: null, refspecs: [`+refs/heads/main:refs/remotes/${remote}/main`] });
79
+ const { remote, ref } = main;
80
+ const fetched = await fetchAsOperator(dir, remote, { askpass: null, refspecs: [`+refs/heads/${ref}:refs/remotes/${remote}/${ref}`] });
56
81
  if (!fetched.ok)
57
82
  return { base, moved: false, detail: fetched.detail };
58
- const latest = (await git(dir, ['rev-parse', '--verify', '--quiet', `refs/remotes/${remote}/main^{commit}`])).stdout;
83
+ const latest = (await git(dir, ['rev-parse', '--verify', '--quiet', `refs/remotes/${remote}/${ref}^{commit}`])).stdout;
59
84
  if (!latest || latest === base)
60
85
  return { base, moved: false };
61
86
  if (!(await isAncestor(dir, base, latest)))
62
- return { base, moved: false, detail: `${remote}/main went another way` };
87
+ return { base, moved: false, detail: `${remote}/${ref} went another way` };
63
88
  const current = (await git(dir, ['symbolic-ref', '--quiet', '--short', 'HEAD'])).stdout;
64
- const moved = current === branch ? await git(dir, ['merge', '--ff-only', '--quiet', latest]) : await git(dir, ['update-ref', '-m', `copilot-operator: ${branch} brought up to ${remote}/main`, `refs/heads/${branch}`, latest, base]);
65
- return moved.ok ? { base: latest, moved: true } : { base, moved: false, detail: (moved.stderr || moved.stdout).split(/\r?\n/)[0] };
89
+ const moved = current === branch ? await git(dir, ['merge', '--ff-only', '--quiet', latest]) : await git(dir, ['update-ref', '-m', `copilot-operator: ${branch} brought up to ${remote}/${ref}`, `refs/heads/${branch}`, latest, base]);
90
+ return moved.ok ? { base: latest, moved: true, from: `${remote}/${ref}` } : { base, moved: false, detail: (moved.stderr || moved.stdout).split(/\r?\n/)[0] };
66
91
  }
@@ -164,6 +164,19 @@ export function composeOpening(input) {
164
164
  const instruction = input.instruction?.text.trim() ? input.instruction : undefined;
165
165
  if (input.continuing && input.contractAlreadySent) {
166
166
  const title = input.taskTitle.trim() || 'untitled';
167
+ /*
168
+ * Carried on with no plan approved yet, in plan mode (2026-11-18): not "carry on from your plan" — there is none the
169
+ * operator approved — but plan first, as the plan-mode note says, and nothing changes until the plan is approved.
170
+ */
171
+ if (input.planNote) {
172
+ const message = `Continue task ${input.taskNumber}: ${title}, in this same conversation. ${whyItStopped(input.continuing)} ` +
173
+ `Its plan was not approved yet, so the work does not go on from where it stopped: plan first, as below — look at ` +
174
+ `what is there now, changing nothing — and send the plan for approval. Step numbering restarts at 1.\n\n` +
175
+ `${input.planNote}\n\n` +
176
+ (instruction ? `${instructionSection(instruction.text)}\n\n` : '') +
177
+ `${runnerBlock(input)}`.trimEnd();
178
+ return { messages: [message], firstMessage: message };
179
+ }
167
180
  /*
168
181
  * After a failure, with the operator's new prompt: told how it ended and why, that its files are
169
182
  * there, and what to do now — not "carry on from your plan", which is the plan that failed.
@@ -4,7 +4,8 @@
4
4
  * each. Kept in the data folder, so a failure seen before a restart is still shown; read by the banner on every page
5
5
  * and by Settings, where the locator's field is in red, until the locator is changed there or the operator closes it.
6
6
  */
7
- import { readFile, rename, writeFile } from 'node:fs/promises';
7
+ import { readFile } from 'node:fs/promises';
8
+ import { writeFileAtomically } from './store.js';
8
9
  import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
9
10
  import { isStepKey } from '../transport/chatSteps.js';
10
11
  const isKey = (k) => typeof k === 'string' && (CHAT_LOCATOR_KEYS.includes(k) || isStepKey(k));
@@ -42,12 +43,14 @@ export class LocatorFailures {
42
43
  });
43
44
  return had;
44
45
  }
46
+ /*
47
+ * Through the store's own atomic write, which tries again when Windows refuses the rename for a moment (2026-11-18:
48
+ * a failure recorded while the banner, polling every few seconds, was reading the file was lost without a word: the
49
+ * rename onto a file open for reading was refused, and the error swallowed).
50
+ */
45
51
  async change(edit) {
46
52
  const run = async () => {
47
- const next = edit(await this.list());
48
- const tmp = `${this.file}.tmp`;
49
- await writeFile(tmp, JSON.stringify(next, null, 2), 'utf8');
50
- await rename(tmp, this.file);
53
+ await writeFileAtomically(this.file, async () => JSON.stringify(edit(await this.list()), null, 2));
51
54
  };
52
55
  const done = this.queue.then(run, run);
53
56
  this.queue = done.catch(() => undefined);
@@ -815,6 +815,15 @@ async function removeFile(path) {
815
815
  async function replaceFile(path, content) {
816
816
  const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
817
817
  await writeFile(tmp, content, 'utf8');
818
+ await moveOver(tmp, path);
819
+ }
820
+ /**
821
+ * Moves a file written beside another over it, trying again while Windows refuses for a moment (see `replaceFile`), and
822
+ * takes the file written away when it cannot. Also the workbench editor's save (bug hunt 2026-11-18): it renamed once, so
823
+ * a save while VS Code or a virus scanner had the file open failed, and left its `.cop-save-…` file in the project,
824
+ * where "Commit all" could take it.
825
+ */
826
+ export async function moveOver(tmp, path) {
818
827
  const backoffMs = [10, 25, 60, 120, 250, 500];
819
828
  for (let attempt = 0;; attempt += 1) {
820
829
  try {
@@ -6,9 +6,10 @@
6
6
  */
7
7
  import { createHash } from 'node:crypto';
8
8
  import { existsSync, statSync } from 'node:fs';
9
- import { readdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
9
+ import { readdir, readFile, stat, writeFile } from 'node:fs/promises';
10
10
  import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
11
11
  import { git, looksLikeRepo, repoState } from '../vcs/git.js';
12
+ import { moveOver } from './store.js';
12
13
  export async function workspaceInfo(dir, name = '') {
13
14
  const d = dir.trim();
14
15
  if (!d)
@@ -135,6 +136,6 @@ export async function saveWorkspaceFile(dir, path, text, base) {
135
136
  // Written beside it and moved over it, so a file is never left half written.
136
137
  const temp = `${full}.cop-save-${process.pid}`;
137
138
  await writeFile(temp, bytes);
138
- await rename(temp, full);
139
+ await moveOver(temp, full);
139
140
  return { path: clean, version: versionOf(bytes), size: bytes.length };
140
141
  }
@@ -218,65 +218,65 @@ const NOTICE_ID = 'copilot-operator-notice';
218
218
  * impossible — the runner notes it before the click and waits for it to move, so a copy that
219
219
  * did not happen reads as a failure rather than as the previous answer.
220
220
  */
221
- export const CLIPBOARD_GUARD = `(() => {
222
- const state = { text: '', seq: 0 };
223
- try {
224
- Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
225
- } catch (e) {
226
- window.__copClipboard = state;
227
- }
228
-
229
- const remember = (text) => {
230
- if (typeof text !== 'string' || text.length === 0) return;
231
- state.text = text;
232
- state.seq += 1;
233
- };
234
-
235
- const clip = navigator.clipboard;
236
- if (clip) {
237
- try {
238
- Object.defineProperty(clip, 'writeText', {
239
- configurable: true,
240
- writable: true,
241
- value: (text) => {
242
- remember(String(text));
243
- return Promise.resolve();
244
- },
245
- });
246
- } catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
247
-
248
- try {
249
- Object.defineProperty(clip, 'write', {
250
- configurable: true,
251
- writable: true,
252
- value: async (items) => {
253
- for (const item of items || []) {
254
- try {
255
- if (item && item.types && item.types.indexOf('text/plain') >= 0) {
256
- remember(await (await item.getType('text/plain')).text());
257
- }
258
- } catch (e) { /* one unreadable item is not a reason to drop the rest */ }
259
- }
260
- },
261
- });
262
- } catch (e) { /* as above */ }
263
- }
264
-
265
- // The old way: select text in a hidden field, then execCommand('copy'). The selection is
266
- // exactly the text being copied, so it is taken and the command is never run.
267
- try {
268
- const realExec = document.execCommand.bind(document);
269
- document.execCommand = (command, ...rest) => {
270
- if (String(command).toLowerCase() === 'copy') {
271
- const selected = String(window.getSelection() || '');
272
- if (selected.length > 0) {
273
- remember(selected);
274
- return true;
275
- }
276
- }
277
- return realExec(command, ...rest);
278
- };
279
- } catch (e) { /* as above */ }
221
+ export const CLIPBOARD_GUARD = `(() => {
222
+ const state = { text: '', seq: 0 };
223
+ try {
224
+ Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
225
+ } catch (e) {
226
+ window.__copClipboard = state;
227
+ }
228
+
229
+ const remember = (text) => {
230
+ if (typeof text !== 'string' || text.length === 0) return;
231
+ state.text = text;
232
+ state.seq += 1;
233
+ };
234
+
235
+ const clip = navigator.clipboard;
236
+ if (clip) {
237
+ try {
238
+ Object.defineProperty(clip, 'writeText', {
239
+ configurable: true,
240
+ writable: true,
241
+ value: (text) => {
242
+ remember(String(text));
243
+ return Promise.resolve();
244
+ },
245
+ });
246
+ } catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
247
+
248
+ try {
249
+ Object.defineProperty(clip, 'write', {
250
+ configurable: true,
251
+ writable: true,
252
+ value: async (items) => {
253
+ for (const item of items || []) {
254
+ try {
255
+ if (item && item.types && item.types.indexOf('text/plain') >= 0) {
256
+ remember(await (await item.getType('text/plain')).text());
257
+ }
258
+ } catch (e) { /* one unreadable item is not a reason to drop the rest */ }
259
+ }
260
+ },
261
+ });
262
+ } catch (e) { /* as above */ }
263
+ }
264
+
265
+ // The old way: select text in a hidden field, then execCommand('copy'). The selection is
266
+ // exactly the text being copied, so it is taken and the command is never run.
267
+ try {
268
+ const realExec = document.execCommand.bind(document);
269
+ document.execCommand = (command, ...rest) => {
270
+ if (String(command).toLowerCase() === 'copy') {
271
+ const selected = String(window.getSelection() || '');
272
+ if (selected.length > 0) {
273
+ remember(selected);
274
+ return true;
275
+ }
276
+ }
277
+ return realExec(command, ...rest);
278
+ };
279
+ } catch (e) { /* as above */ }
280
280
  })();`;
281
281
  /**
282
282
  * A locator of the chat that found nothing where the bot needed it (operator, 2026-11-17: "a mechanism that detects
@@ -388,6 +388,16 @@ export class CopilotTransport {
388
388
  * a save while a message is at work does the same. What cannot be used is said as when a window opens.
389
389
  */
390
390
  takeSettings(o) {
391
+ /*
392
+ * The waits too (bug hunt 2026-11-18): the window kept open between messages went on, for days, with the reply,
393
+ * sign-in and verification waits it was opened with, though Settings had changed them.
394
+ */
395
+ if (o.replyTimeoutMs !== undefined)
396
+ this.opts.replyTimeoutMs = o.replyTimeoutMs;
397
+ if (o.signInTimeoutMs !== undefined)
398
+ this.opts.signInTimeoutMs = o.signInTimeoutMs;
399
+ if (o.humanWaitMs !== undefined)
400
+ this.opts.humanWaitMs = o.humanWaitMs;
391
401
  const picker = resolvePickerLocators(o.pickerLocators);
392
402
  this.locators = picker.locators;
393
403
  this.locatorProblems = picker.problems;
@@ -744,7 +754,7 @@ export class CopilotTransport {
744
754
  * this". One that must be there and is not, within its seconds, stops the work like a locator that found nothing,
745
755
  * said by its name; one that need not be is passed over.
746
756
  */
747
- async runSteps(when, signal) {
757
+ async runSteps(when, signal, lookOnly = false) {
748
758
  for (const problem of this.stepProblems.splice(0))
749
759
  this.emit('chat-step-not-used', { problem });
750
760
  for (const step of this.steps) {
@@ -752,7 +762,12 @@ export class CopilotTransport {
752
762
  continue;
753
763
  if (signal?.aborted)
754
764
  throw new StoppedByOperator('stopped by the operator during a step on the way to the chat');
755
- await this.runStep(step);
765
+ /*
766
+ * `lookOnly`: "Check the locators", which only reads (bug hunt 2026-11-18). A step that must be there and is not
767
+ * stopped the opening of the newest conversation, so what only a conversation holds was not looked for, and it was
768
+ * said as having stopped the work. Taken as one that need not be; the check looks for each step itself.
769
+ */
770
+ await this.runStep(lookOnly ? { ...step, must: false } : step);
756
771
  }
757
772
  }
758
773
  async runStep(step) {
@@ -862,7 +877,7 @@ export class CopilotTransport {
862
877
  const links = await look('conversationLink');
863
878
  const href = links > 0 ? await this.el('conversationLink').first().getAttribute('href').catch(() => null) : null;
864
879
  const chatId = href ? parseChatId(href) : null;
865
- const opened = chatId ? await this.openConversation(chatId).catch(() => false) : false;
880
+ const opened = chatId ? await this.openConversation(chatId, { stepsLookOnly: true }).catch(() => false) : false;
866
881
  if (opened && chatId) {
867
882
  for (const key of ['turn', 'userMessage', 'answer', 'copy'])
868
883
  await look(key);
@@ -1049,7 +1064,7 @@ export class CopilotTransport {
1049
1064
  // Most likely the box itself (2026-11-17: Copilot's chat was at /home, its box changed): said as the box's locator.
1050
1065
  return await this.locatorMissing('composer', `on ${whereIs(url)}, which did not turn into the chat`, {
1051
1066
  message: (files) => `Copilot showed its page ${whereIs(url)} instead of the chat, and the chat did not open from there ` +
1052
- `(by its address on that host, nor by a link to it on the page). Nothing was sent. ${files} ${this.composerHint()}
1067
+ `(by its address on that host, nor by a link to it on the page). Nothing was sent. ${files} ${this.composerHint()}
1053
1068
  Current URL: ${url}`,
1054
1069
  });
1055
1070
  }
@@ -1145,10 +1160,10 @@ Current URL: ${url}`,
1145
1160
  unknown: 'The page is not the Microsoft 365 Copilot chat.',
1146
1161
  };
1147
1162
  if (where === 'unknown') {
1148
- throw await this.locatorMissing('composer', `on ${whereIs(url)}`, { message: (files) => `${explain.unknown} ${files} ${this.composerHint()}
1163
+ throw await this.locatorMissing('composer', `on ${whereIs(url)}`, { message: (files) => `${explain.unknown} ${files} ${this.composerHint()}
1149
1164
  Current URL: ${url}` });
1150
1165
  }
1151
- throw new Error(`${explain[where] ?? explain.unknown}
1166
+ throw new Error(`${explain[where] ?? explain.unknown}
1152
1167
  Current URL: ${url}`);
1153
1168
  }
1154
1169
  /**
@@ -1260,9 +1275,25 @@ Current URL: ${url}`);
1260
1275
  let at = await this.arrive(Url.newChatPath, opts.signal, stoppedHere);
1261
1276
  if (at === 'no-box') {
1262
1277
  this.emit('sign-in-required', { url: this.p.url() });
1263
- if (!(await this.composerWithin(this.opts.signInTimeoutMs, opts.signal, stoppedHere))) {
1278
+ /*
1279
+ * On Copilot's own chat page, no sign-in page in sight, and still no box after a while (2026-11-18): most likely the
1280
+ * box's locator, which finds nothing on a page Copilot changed — and the bot waited the whole sign-in time (15
1281
+ * minutes by default) and then said "the sign-in was not completed", with no locator named. Said once, then, as the
1282
+ * box's locator, the page's file for a chatbot kept; the wait for a sign-in goes on, since Copilot may also ask for
1283
+ * one on its own page.
1284
+ */
1285
+ const firstLook = Math.min(this.boxSuspectMs, this.opts.signInTimeoutMs);
1286
+ const soon = await this.composerWithin(firstLook, opts.signal, stoppedHere);
1287
+ if (!soon && isWorkChatAddress(this.p.url()) && !this.warned.has('composer')) {
1288
+ this.warned.add('composer');
1289
+ await this.locatorMissing('composer', `on ${whereIs(this.p.url())}, Copilot's own chat page and not a sign-in page, for ${Math.round(firstLook / 1000)} s: if you are signed in, the box's locator is the one to fix (the bot goes on waiting for a sign-in meanwhile)`, { stopped: false }).catch(() => undefined);
1290
+ }
1291
+ if (!soon && !(await this.composerWithin(Math.max(1, this.opts.signInTimeoutMs - firstLook), opts.signal, stoppedHere))) {
1264
1292
  throw new Error(`The sign-in was not completed within ${Math.round(this.opts.signInTimeoutMs / 1000)} s (Settings → copilot.signInTimeoutSec). ` +
1265
- 'Sign in in the open Edge window, then start again.');
1293
+ 'Sign in in the open Edge window, then start again.' +
1294
+ (this.warned.has('composer') && isWorkChatAddress(this.p.url())
1295
+ ? ` If you were signed in, the box to write in was not found on Copilot's chat page: fix "Box to write in" in Settings → "The chat's locators" (its notice has the file for a chatbot). In force: ${this.chatLocators.composer}`
1296
+ : ''));
1266
1297
  }
1267
1298
  this.emit('signed-in');
1268
1299
  // A sign-in may come back to Copilot's home page rather than to its chat.
@@ -1276,7 +1307,7 @@ Current URL: ${url}`);
1276
1307
  throw await this.notTheChat();
1277
1308
  }
1278
1309
  await this.assertWorkSurface();
1279
- await this.runSteps('open', opts.signal);
1310
+ await this.runSteps('open', opts.signal, opts.stepsLookOnly);
1280
1311
  }
1281
1312
  async newChat() {
1282
1313
  this.onChat = null;
@@ -1297,7 +1328,7 @@ Current URL: ${url}`);
1297
1328
  this.onChat = 'new';
1298
1329
  }
1299
1330
  /** Reopens a conversation by its id. Returns false when it no longer opens. */
1300
- async openConversation(chatId) {
1331
+ async openConversation(chatId, opts = {}) {
1301
1332
  this.onChat = null;
1302
1333
  const path = Url.conversationPath(chatId);
1303
1334
  await this.p.goto(this.chatAddress(path), { waitUntil: 'domcontentloaded' });
@@ -1307,7 +1338,7 @@ Current URL: ${url}`);
1307
1338
  const there = parseChatId(this.p.url()) === chatId;
1308
1339
  if (there) {
1309
1340
  this.onChat = { id: chatId };
1310
- await this.runSteps('open');
1341
+ await this.runSteps('open', undefined, opts.stepsLookOnly);
1311
1342
  }
1312
1343
  return there;
1313
1344
  }
@@ -2731,6 +2762,8 @@ Current URL: ${url}`);
2731
2762
  inputWaitMs = 10_000;
2732
2763
  attachWaitMs = 30_000;
2733
2764
  uploadWaitMs = 120_000;
2765
+ /** How long Copilot's own chat page may show no box before its locator is said as the likely cause (a field, for the checks). */
2766
+ boxSuspectMs = 30_000;
2734
2767
  /** An attached file's locator in force, with the file's name put in its place (see `fillFileLocator`). */
2735
2768
  fileEl(key, file) {
2736
2769
  return this.p.locator(playwrightSelector(fillFileLocator(this.chatLocators[key], file)));
@@ -13,8 +13,10 @@ export class KeptWindow {
13
13
  /** Whether a message is at work: only then is a window closed under it opened again. */
14
14
  atWork = false;
15
15
  /** How many times it may still be opened again for the message at work, of how many. */
16
- left = 0;
17
- allowed = 0;
16
+ /** Times opened again for the message at work. */
17
+ used = 0;
18
+ /** How many Settings allow, read each time: saved during the message, it counts at once (bug hunt 2026-11-18). */
19
+ allowed = () => 0;
18
20
  signal;
19
21
  /** It is being opened again now. */
20
22
  back = null;
@@ -34,8 +36,8 @@ export class KeptWindow {
34
36
  */
35
37
  holdWindow(times, signal) {
36
38
  this.atWork = true;
37
- this.allowed = Math.max(0, Math.floor(times));
38
- this.left = this.allowed;
39
+ this.allowed = () => Math.max(0, Math.floor(typeof times === 'function' ? times() : times));
40
+ this.used = 0;
39
41
  this.signal = signal;
40
42
  this.gaveUp = null;
41
43
  }
@@ -50,7 +52,7 @@ export class KeptWindow {
50
52
  }
51
53
  /** How many times the window was opened again for the message at work. */
52
54
  reopenedTimes() {
53
- return this.allowed - this.left;
55
+ return this.used;
54
56
  }
55
57
  /** Told by the window when it went (its `window-closed`): opened again at once while a message is at work. */
56
58
  windowWent() {
@@ -67,23 +69,24 @@ export class KeptWindow {
67
69
  this.gaveUp = new WindowClosed('the browser window was closed, and the work was stopped before it was opened again; nothing more was sent');
68
70
  return;
69
71
  }
70
- if (this.left <= 0) {
71
- this.gaveUp = new WindowClosed(this.allowed === 0
72
+ const allowed = this.allowed();
73
+ if (this.used >= allowed) {
74
+ this.gaveUp = new WindowClosed(this.used === 0
72
75
  ? CLOSED_NOT_REOPENED
73
- : `the browser window was closed ${this.allowed + 1} times while this message was at work; it was opened again ${this.allowed} time(s), ` +
74
- 'as many as Settings allow for one message (limits.reopenWindow), so nothing more was sent');
75
- this.speak('window-not-reopened', { reason: this.gaveUp.message, times: this.allowed });
76
+ : `the browser window was closed ${this.used + 1} times while this message was at work; it was opened again ${this.used} time(s), ` +
77
+ `${this.used === allowed ? 'as many as Settings allow' : `and Settings now allow ${allowed}`} for one message (limits.reopenWindow), so nothing more was sent`);
78
+ this.speak('window-not-reopened', { reason: this.gaveUp.message, times: this.used });
76
79
  return;
77
80
  }
78
- this.left -= 1;
79
- const time = this.allowed - this.left;
81
+ this.used += 1;
82
+ const time = this.used;
80
83
  const gen = this.generation;
81
- this.speak('window-reopening', { time, of: this.allowed });
84
+ this.speak('window-reopening', { time, of: allowed });
82
85
  try {
83
86
  const at = await this.inner.reopen({ signal: this.signal });
84
87
  if (this.generation !== gen)
85
88
  continue;
86
- this.speak('window-reopened', { time, of: this.allowed, ...('chatId' in at ? { chatId: at.chatId } : {}) });
89
+ this.speak('window-reopened', { time, of: allowed, ...('chatId' in at ? { chatId: at.chatId } : {}) });
87
90
  return;
88
91
  }
89
92
  catch (e) {
@@ -177,6 +177,75 @@ async function keepUncommitted(dir, head, branch, message, author) {
177
177
  await rm(index, { force: true });
178
178
  }
179
179
  }
180
+ /**
181
+ * What is not committed in the folder, put aside as "New branch from main" puts it aside: one commit on a branch of its
182
+ * own (`<prefix>saved/<when>`, never pushed), checked whole, and only then taken out of the folder, which is left clean
183
+ * on the branch it is on. Nothing is deleted. Null when there was nothing to put aside.
184
+ *
185
+ * For the queue (2026-11-18): a task that works on "the folder as it is" leaves its changes uncommitted, and the next
186
+ * task with a branch of its own was refused for them ("There are uncommitted changes … Commit or stash them first"), the
187
+ * tasks depending on it skipped, in a queue nobody was watching.
188
+ */
189
+ export async function setAsideUncommitted(folder, why, prefix = 'cop/') {
190
+ const top = await git(folder, ['rev-parse', '--show-toplevel']);
191
+ const repoDir = top.ok && top.stdout ? resolve(top.stdout) : folder;
192
+ const changed = porcelainPaths((await git(repoDir, ['status', '--porcelain', '--untracked-files=no'])).stdout);
193
+ const untracked = lines((await git(repoDir, ['ls-files', '--others', '--exclude-standard'])).stdout);
194
+ if (changed.length === 0 && untracked.length === 0)
195
+ return null;
196
+ const head = (await git(repoDir, ['rev-parse', '--verify', '--quiet', 'HEAD'])).stdout;
197
+ if (!head)
198
+ return { problem: 'the repository has no commit yet to keep the changes on top of' };
199
+ const here = (await git(repoDir, ['symbolic-ref', '--quiet', '--short', 'HEAD'])).stdout || null;
200
+ const saved = await freeBranchName(repoDir, `${branchNameFrom(['saved'], prefix)}/${stamp()}`);
201
+ const message = [
202
+ 'Keep uncommitted work',
203
+ '',
204
+ `Everything that was not committed in the folder on ${here ?? 'a detached HEAD'} (${short(head)}), kept here: ${why}`,
205
+ 'To take a file back: git restore --source <this branch> -- <path>',
206
+ '',
207
+ ...[...changed.map((p) => `- changed: ${p}`), ...untracked.map((p) => `- new: ${p}`)].slice(0, 300),
208
+ '',
209
+ 'Committed by copilot-operator. Not pushed.',
210
+ '',
211
+ ].join('\n');
212
+ const kept = await keepUncommitted(repoDir, head, saved, message);
213
+ if ('problem' in kept)
214
+ return { problem: kept.problem };
215
+ // Kept whole: now out of the folder — the tracked changes put back, the new files kept on the branch taken out.
216
+ const restored = await git(repoDir, ['restore', '--staged', '--worktree', '--source', 'HEAD', '--', '.'], 300_000);
217
+ if (!restored.ok)
218
+ return { problem: `the changes are kept on ${saved}, but could not be taken out of the folder: ${restored.stderr}` };
219
+ for (let i = 0; i < untracked.length; i += 100) {
220
+ const cleaned = await git(repoDir, ['--literal-pathspecs', 'clean', '-fd', '--quiet', '--', ...untracked.slice(i, i + 100)], 300_000);
221
+ if (!cleaned.ok)
222
+ return { problem: `the new files are kept on ${saved}, but could not be taken out of the folder: ${cleaned.stderr}` };
223
+ }
224
+ return { saved, commit: kept.commit, files: changed.length + untracked.length };
225
+ }
226
+ /**
227
+ * What `setAsideUncommitted` kept on `saved`, put back into the folder, uncommitted again: its changes laid on what the
228
+ * folder holds now, the new files new again (bug hunt 2026-11-18: a queue's task on "the folder as it is", set aside
229
+ * with its work not committed, carried on without it — the next task on a branch of its own had put it aside). The
230
+ * branch stays: nothing is deleted. One that cannot be laid on what is there is not forced: the folder is left as it
231
+ * was, and said.
232
+ */
233
+ export async function putBackAside(folder, saved) {
234
+ const top = await git(folder, ['rev-parse', '--show-toplevel']);
235
+ const repoDir = top.ok && top.stdout ? resolve(top.stdout) : folder;
236
+ const commit = (await git(repoDir, ['rev-parse', '--verify', '--quiet', `refs/heads/${saved}^{commit}`])).stdout;
237
+ if (!commit)
238
+ return { problem: `there is no branch ${saved} any more` };
239
+ const files = lines((await git(repoDir, ['diff', '--name-only', `${commit}^`, commit])).stdout).length;
240
+ const laid = await git(repoDir, [...BOT_AUTHOR, 'cherry-pick', '--no-commit', commit], 300_000);
241
+ if (!laid.ok) {
242
+ await git(repoDir, ['cherry-pick', '--abort']);
243
+ return { problem: `its changes could not be laid on what the folder holds now (${(laid.stderr || laid.stdout).split(/\r?\n/)[0]}); they are kept on ${saved}` };
244
+ }
245
+ // Not staged, as they were: the new files new again, the changed ones changed.
246
+ await git(repoDir, ['reset', '--quiet']);
247
+ return { files };
248
+ }
180
249
  /** The bot's own name on a commit. */
181
250
  const BOT_AUTHOR = ['-c', 'user.name=copilot-operator', '-c', `user.email=${RUNNER_EMAIL}`];
182
251
  /** The commit message when the operator wrote none. */
@@ -276,7 +276,17 @@ export class ReferenceGuard {
276
276
  export function referenceNote(projects, workDir) {
277
277
  if (projects.length === 0)
278
278
  return '';
279
- const here = projects.some((p) => resolve(p.dir).toLowerCase() === resolve(workDir).toLowerCase());
279
+ /*
280
+ * The folder worked in is one of them, or inside one (bug hunt 2026-11-18: `C:\P` for reference, the chat in
281
+ * `C:\P\app`): every change is put back there too, so the chat is told it can only read — it was told only when the
282
+ * folders were the same, and spent its rounds on changes put back after every step.
283
+ */
284
+ const work = resolve(workDir).toLowerCase();
285
+ const holding = projects.find((p) => {
286
+ const dir = resolve(p.dir).toLowerCase().replace(/[\\/]+$/, '');
287
+ return work === dir || work.startsWith(`${dir}\\`) || work.startsWith(`${dir}/`);
288
+ });
289
+ const here = !!holding && resolve(holding.dir).toLowerCase() === work;
280
290
  return [
281
291
  '## Projects for reference only',
282
292
  '',
@@ -284,7 +294,11 @@ export function referenceNote(projects, workDir) {
284
294
  'file written, moved or removed, nothing installed or built into them, no git command that changes something.',
285
295
  'After every step the runner compares them with how they were when this task began, puts back whatever changed,',
286
296
  'and does not run the rest of that round.',
287
- ...(here ? ['', 'The folder you work in is one of them: this task can only read, run what reads, and report.'] : []),
297
+ ...(holding
298
+ ? ['', here
299
+ ? 'The folder you work in is one of them: this task can only read, run what reads, and report.'
300
+ : `The folder you work in is inside one of them (${holding.name}): this task can only read, run what reads, and report.`]
301
+ : []),
288
302
  '',
289
303
  ...projects.map((p) => `- ${p.name}: ${p.dir}`),
290
304
  ].join('\n');