copilot-operator 0.1.94 → 0.1.97

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 (71) hide show
  1. package/dist/src/api/apiLock.js +82 -0
  2. package/dist/src/api/main.js +5 -0
  3. package/dist/src/api/operator.controller.js +23 -5
  4. package/dist/src/api/operator.service.js +518 -83
  5. package/dist/src/api/server.js +10 -0
  6. package/dist/src/config/exportHome.js +1 -1
  7. package/dist/src/config/live.js +12 -12
  8. package/dist/src/config/schema.js +13 -0
  9. package/dist/src/exec/policy.js +9 -18
  10. package/dist/src/orchestrator/kerriganRunner.js +11 -4
  11. package/dist/src/orchestrator/leadRunner.js +76 -23
  12. package/dist/src/orchestrator/review.js +6 -2
  13. package/dist/src/orchestrator/subtaskRetry.js +2 -1
  14. package/dist/src/orchestrator/taskRunner.js +75 -16
  15. package/dist/src/plan/kerrigan.js +4 -4
  16. package/dist/src/plan/systemGuide.js +36 -36
  17. package/dist/src/queue/queue.js +19 -0
  18. package/dist/src/queue/queueBranch.js +34 -9
  19. package/dist/src/session/locatorFailures.js +10 -11
  20. package/dist/src/session/model.js +4 -0
  21. package/dist/src/session/store.js +56 -0
  22. package/dist/src/session/workspace.js +3 -2
  23. package/dist/src/transport/copilotTransport.js +83 -68
  24. package/dist/src/transport/keptWindow.js +17 -14
  25. package/dist/src/vcs/newBranch.js +28 -0
  26. package/dist/src/vcs/operatorGit.js +9 -10
  27. package/dist/src/vcs/referenceGuard.js +16 -2
  28. package/dist/web/404.html +2 -2
  29. package/dist/web/_next/static/chunks/1024-c0eee3ec374816d1.js +1 -0
  30. package/dist/web/_next/static/chunks/1077.4da389906036b1bb.js +1 -0
  31. package/dist/web/_next/static/chunks/1548.4aa3e42afe4542ab.js +1 -0
  32. package/dist/web/_next/static/chunks/2163.4c6ce20cf967756c.js +1 -0
  33. package/dist/web/_next/static/chunks/714.ffb1325246519f64.js +1 -0
  34. package/dist/web/_next/static/chunks/7220.f483b83c11525063.js +1 -0
  35. package/dist/web/_next/static/chunks/7921-946e538fe3f9630f.js +1 -0
  36. package/dist/web/_next/static/chunks/8124-967df691ec1bfeeb.js +1 -0
  37. package/dist/web/_next/static/chunks/8584.3301b056c97be517.js +1 -0
  38. package/dist/web/_next/static/chunks/9067.03cdfb01ebf6a35d.js +1 -0
  39. package/dist/web/_next/static/chunks/9747.fe06238bc42bd23d.js +1 -0
  40. package/dist/web/_next/static/chunks/app/{layout-1b7d13f7b2efd008.js → layout-7943a4391ad2f88f.js} +1 -1
  41. package/dist/web/_next/static/chunks/app/page-6ec948e0cf4b24f0.js +1 -0
  42. package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +1 -0
  43. package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +1 -0
  44. package/dist/web/_next/static/chunks/{webpack-91b2de9c3da6f8b9.js → webpack-710628d673fa4afb.js} +1 -1
  45. package/dist/web/defaults.html +2 -2
  46. package/dist/web/defaults.txt +7 -7
  47. package/dist/web/index.html +3 -3
  48. package/dist/web/index.txt +8 -8
  49. package/dist/web/queue.html +2 -2
  50. package/dist/web/queue.txt +8 -8
  51. package/dist/web/settings.html +2 -2
  52. package/dist/web/settings.txt +8 -8
  53. package/dist/web/system.html +2 -2
  54. package/dist/web/system.txt +8 -8
  55. package/package.json +1 -1
  56. package/dist/web/_next/static/chunks/1024-dee283a1ddf295bf.js +0 -1
  57. package/dist/web/_next/static/chunks/1077.b7df9cb8ca810075.js +0 -1
  58. package/dist/web/_next/static/chunks/1548.417c17b63c371f00.js +0 -1
  59. package/dist/web/_next/static/chunks/2163.469367b8fbcc862d.js +0 -1
  60. package/dist/web/_next/static/chunks/714.72112704f3cb8127.js +0 -1
  61. package/dist/web/_next/static/chunks/7220.8bd897c7ddfee701.js +0 -1
  62. package/dist/web/_next/static/chunks/7921-25d1755799107ea7.js +0 -1
  63. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
  64. package/dist/web/_next/static/chunks/8584.f87df7324303ab75.js +0 -1
  65. package/dist/web/_next/static/chunks/9067.67a7c7cf3b019b5c.js +0 -1
  66. package/dist/web/_next/static/chunks/9747.a87dbd4acd45e39d.js +0 -1
  67. package/dist/web/_next/static/chunks/app/page-7eae1e8848525e1d.js +0 -1
  68. package/dist/web/_next/static/chunks/app/queue/page-7909ba7c9e3d4c2d.js +0 -1
  69. package/dist/web/_next/static/chunks/app/settings/page-c92548f9c6318962.js +0 -1
  70. /package/dist/web/_next/static/{UNygvDtRnBVZrGJt53IE4 → D3ew46wEw5JXPsTVwZwFC}/_buildManifest.js +0 -0
  71. /package/dist/web/_next/static/{UNygvDtRnBVZrGJt53IE4 → D3ew46wEw5JXPsTVwZwFC}/_ssgManifest.js +0 -0
@@ -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
  }
@@ -4,8 +4,7 @@
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 } from 'node:fs/promises';
8
- import { writeFileAtomically } from './store.js';
7
+ import { readStoreJson, writeFileAtomically } from './store.js';
9
8
  import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
10
9
  import { isStepKey } from '../transport/chatSteps.js';
11
10
  const isKey = (k) => typeof k === 'string' && (CHAT_LOCATOR_KEYS.includes(k) || isStepKey(k));
@@ -16,16 +15,16 @@ export class LocatorFailures {
16
15
  constructor(file) {
17
16
  this.file = file;
18
17
  }
18
+ /** As kept, for the banner and Settings: one that cannot be read shows none (the change below refuses it). */
19
19
  async list() {
20
- try {
21
- const raw = JSON.parse(await readFile(this.file, 'utf8'));
22
- if (!Array.isArray(raw))
23
- return [];
24
- return raw.filter((f) => !!f && typeof f === 'object' && isKey(f.key) && typeof f.locator === 'string' && typeof f.at === 'string');
25
- }
26
- catch {
20
+ return await this.read().catch(() => []);
21
+ }
22
+ /** As kept; one there but not readable is refused (2026-11-19), so a change never writes it over. */
23
+ async read() {
24
+ const raw = await readStoreJson(this.file);
25
+ if (!Array.isArray(raw))
27
26
  return [];
28
- }
27
+ return raw.filter((f) => !!f && typeof f === 'object' && isKey(f.key) && typeof f.locator === 'string' && typeof f.at === 'string');
29
28
  }
30
29
  async get(key) {
31
30
  return (await this.list()).find((f) => f.key === key) ?? null;
@@ -50,7 +49,7 @@ export class LocatorFailures {
50
49
  */
51
50
  async change(edit) {
52
51
  const run = async () => {
53
- await writeFileAtomically(this.file, async () => JSON.stringify(edit(await this.list()), null, 2));
52
+ await writeFileAtomically(this.file, async () => JSON.stringify(edit(await this.read()), null, 2));
54
53
  };
55
54
  const done = this.queue.then(run, run);
56
55
  this.queue = done.catch(() => undefined);
@@ -12,6 +12,10 @@ export function tidyVcsPlan(plan) {
12
12
  return undefined;
13
13
  return { ...(branch ? { branch } : {}), ...(commitMessage ? { commitMessage } : {}) };
14
14
  }
15
+ /** Whether a set-aside task's card is over — stopped, or let go of by the queue — so that "Continue" carries it on. */
16
+ export function parkedOver(parked) {
17
+ return !parked || parked.answer?.kind === 'stopped' || parked.answer?.kind === 'released';
18
+ }
15
19
  export const clipText = (s, n) => {
16
20
  const t = (s ?? '').trim();
17
21
  if (!t)
@@ -786,6 +786,53 @@ function inTurn(path, work) {
786
786
  * setting put back whatever another had changed in between. If it throws, nothing is written. Like
787
787
  * any work in a turn, it must not wait for another turn on the same file (see `inTurn`).
788
788
  */
789
+ /**
790
+ * A file of the bot's own records that is there but cannot be used (2026-11-19). Read as empty, it was written over by
791
+ * the next change: a queue.json the machine lost power over, or another program held, came back as an empty queue,
792
+ * and the next task added wrote it over — every task and every card kept for the operator gone, without a word. As
793
+ * `SettingsUnusableError` refuses for settings.json.
794
+ */
795
+ export class StoreFileUnusable extends Error {
796
+ path;
797
+ constructor(path, problem) {
798
+ super(`${path} ${problem}. Nothing has been saved over it: mend it, or move it away to start that list again empty.`);
799
+ this.path = path;
800
+ this.name = 'StoreFileUnusable';
801
+ }
802
+ }
803
+ /**
804
+ * A JSON file of the bot's own records, read to be changed and written back: undefined when it is not there or holds
805
+ * nothing (a list not begun); a moment's lock by another program — a virus scanner, a sync client — waited out, as a
806
+ * write's is (`moveOver`); anything else refused (`StoreFileUnusable`), so it is never written over.
807
+ */
808
+ export async function readStoreJson(path) {
809
+ const backoffMs = [10, 25, 60, 120, 250, 500];
810
+ for (let attempt = 0;; attempt += 1) {
811
+ let text;
812
+ try {
813
+ text = await readFile(path, 'utf8');
814
+ }
815
+ catch (e) {
816
+ const code = e.code ?? '';
817
+ if (code === 'ENOENT')
818
+ return undefined;
819
+ if ((code === 'EBUSY' || code === 'EPERM' || code === 'EACCES') && attempt < backoffMs.length) {
820
+ await new Promise((r) => setTimeout(r, backoffMs[attempt]));
821
+ continue;
822
+ }
823
+ throw new StoreFileUnusable(path, `could not be read (${code || e.message})`);
824
+ }
825
+ const body = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
826
+ if (body.trim() === '')
827
+ return undefined;
828
+ try {
829
+ return JSON.parse(body);
830
+ }
831
+ catch (e) {
832
+ throw new StoreFileUnusable(path, `is not valid JSON (${e.message})`);
833
+ }
834
+ }
835
+ }
789
836
  export async function writeFileAtomically(path, content) {
790
837
  await inTurn(path, async () => replaceFile(path, typeof content === 'string' ? content : await content()));
791
838
  }
@@ -815,6 +862,15 @@ async function removeFile(path) {
815
862
  async function replaceFile(path, content) {
816
863
  const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
817
864
  await writeFile(tmp, content, 'utf8');
865
+ await moveOver(tmp, path);
866
+ }
867
+ /**
868
+ * Moves a file written beside another over it, trying again while Windows refuses for a moment (see `replaceFile`), and
869
+ * takes the file written away when it cannot. Also the workbench editor's save (bug hunt 2026-11-18): it renamed once, so
870
+ * a save while VS Code or a virus scanner had the file open failed, and left its `.cop-save-…` file in the project,
871
+ * where "Commit all" could take it.
872
+ */
873
+ export async function moveOver(tmp, path) {
818
874
  const backoffMs = [10, 25, 60, 120, 250, 500];
819
875
  for (let attempt = 0;; attempt += 1) {
820
876
  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
  /**
@@ -1292,7 +1307,7 @@ Current URL: ${url}`);
1292
1307
  throw await this.notTheChat();
1293
1308
  }
1294
1309
  await this.assertWorkSurface();
1295
- await this.runSteps('open', opts.signal);
1310
+ await this.runSteps('open', opts.signal, opts.stepsLookOnly);
1296
1311
  }
1297
1312
  async newChat() {
1298
1313
  this.onChat = null;
@@ -1313,7 +1328,7 @@ Current URL: ${url}`);
1313
1328
  this.onChat = 'new';
1314
1329
  }
1315
1330
  /** Reopens a conversation by its id. Returns false when it no longer opens. */
1316
- async openConversation(chatId) {
1331
+ async openConversation(chatId, opts = {}) {
1317
1332
  this.onChat = null;
1318
1333
  const path = Url.conversationPath(chatId);
1319
1334
  await this.p.goto(this.chatAddress(path), { waitUntil: 'domcontentloaded' });
@@ -1323,7 +1338,7 @@ Current URL: ${url}`);
1323
1338
  const there = parseChatId(this.p.url()) === chatId;
1324
1339
  if (there) {
1325
1340
  this.onChat = { id: chatId };
1326
- await this.runSteps('open');
1341
+ await this.runSteps('open', undefined, opts.stepsLookOnly);
1327
1342
  }
1328
1343
  return there;
1329
1344
  }
@@ -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) {
@@ -223,6 +223,34 @@ export async function setAsideUncommitted(folder, why, prefix = 'cop/') {
223
223
  }
224
224
  return { saved, commit: kept.commit, files: changed.length + untracked.length };
225
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
+ /*
243
+ * Taken back as a merge is (2026-11-19): a pick with --no-commit leaves no cherry-pick for "--abort" to end, and the
244
+ * folder was left half merged, conflict markers in it. `reset --merge` takes back what the pick laid — the clash, the
245
+ * new files — and keeps an edit of the folder's own elsewhere, which a pick never touches (it refuses first).
246
+ */
247
+ await git(repoDir, ['reset', '--merge']);
248
+ 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}` };
249
+ }
250
+ // Not staged, as they were: the new files new again, the changed ones changed.
251
+ await git(repoDir, ['reset', '--quiet']);
252
+ return { files };
253
+ }
226
254
  /** The bot's own name on a commit. */
227
255
  const BOT_AUTHOR = ['-c', 'user.name=copilot-operator', '-c', `user.email=${RUNNER_EMAIL}`];
228
256
  /** The commit message when the operator wrote none. */
@@ -22,11 +22,12 @@
22
22
  */
23
23
  import { createHash } from 'node:crypto';
24
24
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
25
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
25
+ import { mkdir } from 'node:fs/promises';
26
26
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
27
27
  import { git, gitLive, RUNNER_EMAIL } from './git.js';
28
28
  import { askpassProgram, closePasswordWindows, operatorFetchEnv, passwordWindowOpen } from './remoteAuth.js';
29
29
  import { workspaceGit } from '../session/workspaceGit.js';
30
+ import { readStoreJson, writeFileAtomically } from '../session/store.js';
30
31
  const MINUTES = 60_000;
31
32
  /** Long enough for a project's pre-commit checks or a big push; the view shows every line meanwhile. */
32
33
  const OP_TIMEOUT_MS = 15 * MINUTES;
@@ -67,17 +68,14 @@ export class TrustedHooks {
67
68
  constructor(file) {
68
69
  this.file = file;
69
70
  }
71
+ /** As kept; one there but not readable is refused (2026-11-19), so an addition never writes the others over. */
70
72
  async read() {
71
- try {
72
- const data = JSON.parse(await readFile(this.file, 'utf8'));
73
- return data && typeof data === 'object' ? data : {};
74
- }
75
- catch {
76
- return {};
77
- }
73
+ const data = await readStoreJson(this.file);
74
+ return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
78
75
  }
76
+ /** Not readable: not trusted, so the hook is asked about again. */
79
77
  async has(top, path, sha) {
80
- return !!sha && (await this.read())[repoKey(top)]?.[path] === sha;
78
+ return !!sha && (await this.read().catch(() => ({})))[repoKey(top)]?.[path] === sha;
81
79
  }
82
80
  async add(top, hooks) {
83
81
  if (hooks.length === 0)
@@ -88,7 +86,8 @@ export class TrustedHooks {
88
86
  mine[h.path] = h.sha;
89
87
  all[repoKey(top)] = mine;
90
88
  await mkdir(dirname(this.file), { recursive: true });
91
- await writeFile(this.file, `${JSON.stringify(all, null, 2)}\n`, 'utf8');
89
+ // Through a temporary file and a rename, retried as Windows needs (2026-11-19): written in place, a crash left it cut.
90
+ await writeFileAtomically(this.file, `${JSON.stringify(all, null, 2)}\n`);
92
91
  }
93
92
  }
94
93
  /** The repository's top folder, or null when the folder is not in one. */
@@ -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');