copilot-operator 0.1.90 → 0.1.93

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 (46) hide show
  1. package/dist/src/api/operator.controller.js +26 -0
  2. package/dist/src/api/operator.service.js +55 -14
  3. package/dist/src/cli.js +3 -0
  4. package/dist/src/config/live.js +6 -3
  5. package/dist/src/config/schema.js +23 -0
  6. package/dist/src/orchestrator/taskRunner.js +25 -3
  7. package/dist/src/plan/systemGuide.js +220 -13
  8. package/dist/src/session/chatNotice.js +4 -1
  9. package/dist/src/session/chatbotFile.js +117 -0
  10. package/dist/src/session/events.js +5 -1
  11. package/dist/src/session/locatorFailures.js +2 -1
  12. package/dist/src/transport/chatSteps.js +74 -0
  13. package/dist/src/transport/copilotTransport.js +288 -31
  14. package/dist/src/transport/keptWindow.js +4 -0
  15. package/dist/src/transport/locators.js +106 -5
  16. package/dist/src/transport/pageHtml.js +36 -2
  17. package/dist/web/404.html +2 -2
  18. package/dist/web/_next/static/chunks/{1077.1cc6d439e3dd0fa9.js → 1077.626a11362f53d35c.js} +1 -1
  19. package/dist/web/_next/static/chunks/{1548.3de9dc874e47558e.js → 1548.79f05ff765581b0a.js} +1 -1
  20. package/dist/web/_next/static/chunks/{2163.66458fb9c54fb52d.js → 2163.09f1212655504f3a.js} +1 -1
  21. package/dist/web/_next/static/chunks/{714.cffed2b87154be0f.js → 714.acea3698b6af7a61.js} +1 -1
  22. package/dist/web/_next/static/chunks/{7220.30b6a3e1bd41e51a.js → 7220.1eba10bd9d449cea.js} +1 -1
  23. package/dist/web/_next/static/chunks/7921-29256ac683ea4bc5.js +1 -0
  24. package/dist/web/_next/static/chunks/{8584.36422ed19d6c43e9.js → 8584.b5aac5354f124d4b.js} +1 -1
  25. package/dist/web/_next/static/chunks/{9067.e579f97591576de2.js → 9067.177163495f3bd8fa.js} +1 -1
  26. package/dist/web/_next/static/chunks/{9747.11247f0e21542f6d.js → 9747.5b9d763e89abc7e4.js} +1 -1
  27. package/dist/web/_next/static/chunks/app/layout-1b7d13f7b2efd008.js +1 -0
  28. package/dist/web/_next/static/chunks/app/settings/page-c92548f9c6318962.js +1 -0
  29. package/dist/web/_next/static/chunks/{webpack-78ec62098b09e4a0.js → webpack-33252b1a0a7d93ba.js} +1 -1
  30. package/dist/web/_next/static/css/{d74aa18c98dacdb4.css → 6b92f118889ca88b.css} +1 -1
  31. package/dist/web/defaults.html +2 -2
  32. package/dist/web/defaults.txt +8 -8
  33. package/dist/web/index.html +3 -3
  34. package/dist/web/index.txt +9 -9
  35. package/dist/web/queue.html +2 -2
  36. package/dist/web/queue.txt +9 -9
  37. package/dist/web/settings.html +2 -2
  38. package/dist/web/settings.txt +9 -9
  39. package/dist/web/system.html +2 -2
  40. package/dist/web/system.txt +9 -9
  41. package/package.json +1 -1
  42. package/dist/web/_next/static/chunks/7921-d3a4a261e08950e0.js +0 -1
  43. package/dist/web/_next/static/chunks/app/layout-7b5fa7c74ecd6939.js +0 -1
  44. package/dist/web/_next/static/chunks/app/settings/page-7651920337bbb580.js +0 -1
  45. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → ZrEcjGdZEXe66UUxUqine}/_buildManifest.js +0 -0
  46. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → ZrEcjGdZEXe66UUxUqine}/_ssgManifest.js +0 -0
@@ -16,10 +16,11 @@ import { mkdir, writeFile } from 'node:fs/promises';
16
16
  import { join } from 'node:path';
17
17
  import { findRecentCrash, describeCrash } from './edgeCrash.js';
18
18
  import { landed } from './acceptance.js';
19
- import { Blocker, CHAT_ID, CHAT_LOCATOR_KEYS, ChatLocatorGroupOf, ChatLocatorWhat, Css, DefaultChatLocators, fillLocator, Label, Model, ModelPicking, pageQuery, playwrightSelector, Rename, resolveChatLocators, resolvePickerLocators, Signal, Surface, Upload, Url, } from './locators.js';
19
+ import { Blocker, CHAT_ID, CHAT_LOCATOR_KEYS, ChatLocatorGroupOf, ChatLocatorNear, ChatLocatorWhat, Css, DefaultChatLocators, fillFileLocator, fillLocator, Label, Model, NearPlaces, ModelPicking, pageQuery, playwrightSelector, Rename, resolveChatLocators, resolvePickerLocators, Signal, StepNear, Surface, Url, } from './locators.js';
20
20
  import { acquireProfileLock } from './profileLock.js';
21
21
  import { chatNameForms, parseChatId } from './chatSession.js';
22
22
  import { strippedPageHtml } from './pageHtml.js';
23
+ import { DefaultBuiltInSteps, stepKey, usableSteps } from './chatSteps.js';
23
24
  /**
24
25
  * The chat did not finish a reply within `copilot.replyTimeoutSec`.
25
26
  *
@@ -288,7 +289,9 @@ export class LocatorMissing extends Error {
288
289
  locator;
289
290
  html;
290
291
  picture;
291
- constructor(key, locator, message, html, picture) {
292
+ constructor(
293
+ /** A chat locator's key, or `step:<id>` for one of the operator's own steps (see `chatSteps.ts`). */
294
+ key, locator, message, html, picture) {
292
295
  super(message);
293
296
  this.key = key;
294
297
  this.locator = locator;
@@ -316,6 +319,14 @@ export class CopilotTransport {
316
319
  locators;
317
320
  /** The chat page's locators in force — the box to write in: Settings' own, else the default (see `resolveChatLocators`). */
318
321
  chatLocators;
322
+ /** The bot's own steps as Settings switch them, the operator's own steps taken, and why one saved is not (2026-11-17). */
323
+ builtIn;
324
+ steps;
325
+ stepProblems;
326
+ /** A picture at each step of choosing a model (Settings' `pickerSteps`). */
327
+ stepShots;
328
+ /** Said once a window: the conversation is not named (its step switched off); a step passed over that is not required. */
329
+ nameOffSaid = false;
319
330
  /** Why a chat locator saved in Settings is not used; said once, when the chat is first opened. */
320
331
  chatLocatorProblems;
321
332
  /** Why a locator saved in Settings is not used; said once, at the first choice or reading of the models. */
@@ -363,8 +374,35 @@ export class CopilotTransport {
363
374
  this.chatLocators = chat.locators;
364
375
  this.chatLocatorProblems = chat.problems;
365
376
  this.locatorProblems = problems;
377
+ this.builtIn = { ...DefaultBuiltInSteps, ...(opts.builtInSteps ?? {}) };
378
+ const own = usableSteps(opts.extraSteps);
379
+ this.steps = own.steps;
380
+ this.stepProblems = own.problems;
381
+ this.stepShots = !!opts.modelStepShots;
366
382
  this.chatOrigin = surfaceOfUrl(opts.chatUrl) === 'work' ? new URL(opts.chatUrl).origin : Url.origin;
367
383
  }
384
+ /**
385
+ * Settings saved since this window opened (2026-11-17): the locators, the model menu's and the chat's, and the steps
386
+ * on the way to the chat. The chat's window is kept open between messages, and a locator fixed in Settings went on
387
+ * being looked for as it was until the window closed; each message's run hands the window what Settings say now, and
388
+ * a save while a message is at work does the same. What cannot be used is said as when a window opens.
389
+ */
390
+ takeSettings(o) {
391
+ const picker = resolvePickerLocators(o.pickerLocators);
392
+ this.locators = picker.locators;
393
+ this.locatorProblems = picker.problems;
394
+ const chat = resolveChatLocators(o.chatLocators);
395
+ if (JSON.stringify(chat.locators) !== JSON.stringify(this.chatLocators))
396
+ this.warned.clear();
397
+ this.chatLocators = chat.locators;
398
+ this.chatLocatorProblems = chat.problems;
399
+ this.builtIn = { ...DefaultBuiltInSteps, ...(o.builtInSteps ?? {}) };
400
+ const own = usableSteps(o.extraSteps);
401
+ this.steps = own.steps;
402
+ this.stepProblems = own.problems;
403
+ this.stepShots = !!o.modelStepShots;
404
+ this.emit('settings-taken', { steps: this.steps.length, builtIn: this.builtIn });
405
+ }
368
406
  /** Says, once, which locators saved in Settings could not be used and why. */
369
407
  sayLocatorProblems() {
370
408
  for (const problem of this.locatorProblems)
@@ -630,29 +668,140 @@ export class CopilotTransport {
630
668
  async locatorMissing(key, why, opts = {}) {
631
669
  const stopped = opts.stopped ?? true;
632
670
  const locator = this.chatLocators[key];
633
- const open = !!this.page && !this.page.isClosed();
634
- const dir = join(this.opts.transportDir, '..', 'failures');
635
- const tag = `locator-${key}-${Date.now()}`;
636
- let picture;
637
- let html;
638
- if (open) {
639
- await mkdir(dir, { recursive: true }).catch(() => undefined);
640
- const png = join(dir, `${tag}.png`);
641
- if (await this.p.screenshot({ path: png, fullPage: true }).then(() => true, () => false))
642
- picture = png;
643
- const text = await this.p.evaluate(strippedPageHtml, ChatLocatorGroupOf[key] === 'conversations').catch(() => '');
644
- const file = join(dir, `${tag}.html`);
645
- if (text && (await writeFile(file, text, 'utf8').then(() => true, () => false)))
646
- html = file;
647
- }
648
- const url = open ? whereIs(this.p.url()) : undefined;
649
- this.emit('locator-missing', { key, locator, why, stopped, ...(html ? { html } : {}), ...(picture ? { picture } : {}), ...(url ? { url } : {}) });
671
+ const { picture, html, url, piece, around } = await this.keepPage(`locator-${key}-${Date.now()}`, ChatLocatorGroupOf[key] === 'conversations', {
672
+ near: ChatLocatorNear[key],
673
+ ...(opts.chatId ? { chatId: opts.chatId } : {}),
674
+ ...(opts.file ? { file: opts.file } : {}),
675
+ });
676
+ this.emit('locator-missing', { key, locator, why, stopped, ...(html ? { html } : {}), ...(picture ? { picture } : {}), ...(url ? { url } : {}), ...(piece ? { piece, around } : {}) });
650
677
  const files = [picture ? `A picture of the page: ${picture}.` : '', html ? `The page's HTML, for a chatbot to find the right locator in: ${html}.` : ''].filter(Boolean).join(' ');
651
678
  const message = opts.message?.(files) ??
652
679
  `Not found on Copilot's page: ${ChatLocatorWhat[key]}. The "${key}" locator found nothing ${why}. In force: ${locator} ` +
653
680
  `(Settings → "The chat's locators"). ${files}`.trim();
654
681
  return new LocatorMissing(key, locator, message, html, picture);
655
682
  }
683
+ /**
684
+ * A picture of the page and its HTML for a chatbot (see `pageHtml.ts`), in the failures folder; where the page was.
685
+ * With `near` (2026-11-18), also the piece of the page where the element not found most likely is: around the first
686
+ * of those that finds something (`ChatLocatorNear`), and what that was (`around`).
687
+ */
688
+ async keepPage(tag, keepSidebar, near) {
689
+ if (!this.page || this.page.isClosed())
690
+ return {};
691
+ const dir = join(this.opts.transportDir, '..', 'failures');
692
+ await mkdir(dir, { recursive: true }).catch(() => undefined);
693
+ const out = { url: whereIs(this.p.url()) };
694
+ const png = join(dir, `${tag}.png`);
695
+ if (await this.p.screenshot({ path: png, fullPage: true }).then(() => true, () => false))
696
+ out.picture = png;
697
+ const anchor = near ? await this.nearAnchor(near).catch(() => null) : null;
698
+ const kept = await this.p.evaluate(strippedPageHtml, { keepSidebar, anchor: anchor?.handle ?? null, cap: 40_000 }).catch(() => ({ page: '', piece: '' }));
699
+ await anchor?.handle.dispose().catch(() => undefined);
700
+ const file = join(dir, `${tag}.html`);
701
+ if (kept.page && (await writeFile(file, kept.page, 'utf8').then(() => true, () => false)))
702
+ out.html = file;
703
+ const pieceFile = join(dir, `${tag}.piece.html`);
704
+ if (anchor && kept.piece && (await writeFile(pieceFile, kept.piece, 'utf8').then(() => true, () => false))) {
705
+ out.piece = pieceFile;
706
+ out.around = anchor.what;
707
+ }
708
+ return out;
709
+ }
710
+ /** The first of `near` that finds something on the page: the element (the newest of a conversation's), and what it is. */
711
+ async nearAnchor(near) {
712
+ for (const n of near.near) {
713
+ const place = NearPlaces[n];
714
+ const key = place ? null : n;
715
+ let found;
716
+ if (place)
717
+ found = this.p.locator(place.selector);
718
+ else if (key === 'attachment' || key === 'attachmentUploaded') {
719
+ if (!near.file)
720
+ continue;
721
+ found = this.fileEl(key, near.file);
722
+ }
723
+ else if (key === 'chatMore') {
724
+ if (!near.chatId)
725
+ continue;
726
+ found = this.el(key, near.chatId);
727
+ }
728
+ else
729
+ found = this.el(key);
730
+ const newest = key === 'answer' || key === 'turn' || key === 'userMessage' || key === 'copy';
731
+ // One that shows first; a hidden one (the file input) only when none shows.
732
+ for (const which of [found.filter({ visible: true }), found]) {
733
+ if ((await which.count().catch(() => 0)) === 0)
734
+ continue;
735
+ const handle = await (newest ? which.last() : which.first()).elementHandle({ timeout: 1_000 }).catch(() => null);
736
+ if (handle)
737
+ return { handle, what: place ? place.what : `the element the "${key}" locator finds: ${ChatLocatorWhat[key]}` };
738
+ }
739
+ }
740
+ return null;
741
+ }
742
+ /**
743
+ * The operator's own steps for `when` (2026-11-17, see `chatSteps.ts`), in their order: "if this is on the page, do
744
+ * this". One that must be there and is not, within its seconds, stops the work like a locator that found nothing,
745
+ * said by its name; one that need not be is passed over.
746
+ */
747
+ async runSteps(when, signal) {
748
+ for (const problem of this.stepProblems.splice(0))
749
+ this.emit('chat-step-not-used', { problem });
750
+ for (const step of this.steps) {
751
+ if (step.when !== when)
752
+ continue;
753
+ if (signal?.aborted)
754
+ throw new StoppedByOperator('stopped by the operator during a step on the way to the chat');
755
+ await this.runStep(step);
756
+ }
757
+ }
758
+ async runStep(step) {
759
+ const ms = Math.max(0, step.waitSec ?? 2) * 1000;
760
+ const shown = this.p.locator(playwrightSelector(step.locator)).filter({ visible: true }).first();
761
+ const said = { id: step.id, name: step.name, when: step.when, action: step.action };
762
+ if (step.action === 'gone') {
763
+ // Waited for to go, when it is there: a spinner, a banner that leaves by itself.
764
+ if ((await shown.count().catch(() => 0)) === 0)
765
+ return this.emit('chat-step', { ...said, did: 'not-there' });
766
+ const went = ms > 0 && (await shown.waitFor({ state: 'hidden', timeout: ms }).then(() => true, () => false));
767
+ if (went)
768
+ return this.emit('chat-step', { ...said, did: 'gone' });
769
+ if (step.must)
770
+ throw await this.stepMissing(step, `was still on the page after ${Math.round(ms / 1000)} s`);
771
+ return this.emit('chat-step', { ...said, did: 'still-there' });
772
+ }
773
+ // 0 seconds: only a look at the page as it is (a wait of no time would see nothing, even what is there).
774
+ const there = ms === 0
775
+ ? (await shown.count().catch(() => 0)) > 0
776
+ : await shown.waitFor({ state: 'visible', timeout: ms }).then(() => true, () => false);
777
+ if (!there) {
778
+ if (step.must)
779
+ throw await this.stepMissing(step, `found nothing within ${Math.round(ms / 1000)} s`);
780
+ return this.emit('chat-step', { ...said, did: 'not-there' });
781
+ }
782
+ try {
783
+ if (step.action === 'click')
784
+ await shown.click({ timeout: 10_000 });
785
+ else if (step.action === 'press')
786
+ await this.p.keyboard.press((step.key ?? '').trim());
787
+ this.emit('chat-step', { ...said, did: step.action === 'appear' ? 'appeared' : step.action === 'press' ? 'pressed' : 'clicked' });
788
+ }
789
+ catch (e) {
790
+ if (step.must)
791
+ throw await this.stepMissing(step, `was found, and ${step.action === 'press' ? 'the key could not be pressed' : 'could not be clicked'}: ${e.message.split('\n')[0]}`);
792
+ this.emit('chat-step', { ...said, did: 'failed', error: e.message.split('\n')[0] });
793
+ }
794
+ }
795
+ /** One of the operator's own steps that must be there and is not: said like a locator that found nothing. */
796
+ async stepMissing(step, why, stopped = true) {
797
+ const key = stepKey(step.id);
798
+ const { picture, html, url, piece, around } = await this.keepPage(`step-${step.id}-${Date.now()}`, false, { near: StepNear });
799
+ const when = step.when === 'open' ? 'when the chat opened' : 'before a message';
800
+ this.emit('locator-missing', { key, name: step.name, locator: step.locator, why: `${when}: ${why}`, stopped, ...(html ? { html } : {}), ...(picture ? { picture } : {}), ...(url ? { url } : {}), ...(piece ? { piece, around } : {}) });
801
+ const files = [picture ? `A picture of the page: ${picture}.` : '', html ? `The page's HTML, for a chatbot to find the right locator in: ${html}.` : ''].filter(Boolean).join(' ');
802
+ return new LocatorMissing(key, step.locator, `Your step "${step.name || step.locator}" must be there, and ${when} its locator ${why}. In force: ${step.locator} ` +
803
+ `(Settings → "Steps to the chat"; switch the step off there, or make it not required, to go on without it). ${files}`.trim(), html, picture);
804
+ }
656
805
  /** A locator that found nothing where the work goes on without it (a conversation's name): said once a window. */
657
806
  async warnLocator(key, why, chatId) {
658
807
  if (this.warned.has(key) || !this.page || this.page.isClosed())
@@ -699,6 +848,10 @@ export class CopilotTransport {
699
848
  await this.composer().fill('').catch(() => undefined);
700
849
  }
701
850
  await record('send', send);
851
+ // The box's file input (hidden: counted, not looked at). An attached file shows only once one is, and none is here.
852
+ await look('uploadInput');
853
+ notHere('attachment', 'attach');
854
+ notHere('attachmentUploaded', 'attach');
702
855
  // Stop shows only while Copilot writes.
703
856
  const stop = await count('stop');
704
857
  if (stop > 0)
@@ -744,8 +897,26 @@ export class CopilotTransport {
744
897
  // The rename dialog is not opened: renaming is not this check's to do.
745
898
  notHere('renameInput', 'dialog');
746
899
  notHere('renameSave', 'dialog');
900
+ // The operator's own steps (2026-11-17): what each finds now; one required not found is in red, the rest as they are.
901
+ const ownSteps = [];
902
+ for (const step of this.steps) {
903
+ const key = stepKey(step.id);
904
+ const n = await this.p.locator(playwrightSelector(step.locator)).filter({ visible: true }).count().catch(() => 0);
905
+ if (n > 0)
906
+ ownSteps.push({ key, status: 'found', count: n });
907
+ else if (step.action === 'gone')
908
+ ownSteps.push({ key, status: 'not-here', count: 0, note: 'gone' });
909
+ else if (step.must) {
910
+ ownSteps.push({ key, status: 'none', count: 0 });
911
+ await this.stepMissing(step, 'found nothing when the locators were checked', false).catch(() => undefined);
912
+ }
913
+ else
914
+ ownSteps.push({ key, status: 'not-here', count: 0, note: 'optional' });
915
+ }
916
+ for (const c of ownSteps)
917
+ out.set(c.key, c);
747
918
  this.emit('locators-checked', { found: [...out.values()].filter((c) => c.status === 'found').length, none: [...out.values()].filter((c) => c.status === 'none').map((c) => c.key) });
748
- return CHAT_LOCATOR_KEYS.map((k) => out.get(k) ?? { key: k, status: 'not-here', count: 0 });
919
+ return [...CHAT_LOCATOR_KEYS.map((k) => out.get(k) ?? { key: k, status: 'not-here', count: 0 }), ...ownSteps];
749
920
  }
750
921
  /** Whether the box to write in is empty: a message clicked away with Send leaves it so. */
751
922
  async boxIsEmpty() {
@@ -1105,6 +1276,7 @@ Current URL: ${url}`);
1105
1276
  throw await this.notTheChat();
1106
1277
  }
1107
1278
  await this.assertWorkSurface();
1279
+ await this.runSteps('open', opts.signal);
1108
1280
  }
1109
1281
  async newChat() {
1110
1282
  this.onChat = null;
@@ -1121,6 +1293,7 @@ Current URL: ${url}`);
1121
1293
  throw await this.locatorMissing('composer', 'on a new chat, within a minute');
1122
1294
  });
1123
1295
  await this.dismissPopups();
1296
+ await this.runSteps('open');
1124
1297
  this.onChat = 'new';
1125
1298
  }
1126
1299
  /** Reopens a conversation by its id. Returns false when it no longer opens. */
@@ -1132,8 +1305,10 @@ Current URL: ${url}`);
1132
1305
  if (at === 'elsewhere' || (at === 'no-box' && !(await this.isChatReady(5_000))))
1133
1306
  return false;
1134
1307
  const there = parseChatId(this.p.url()) === chatId;
1135
- if (there)
1308
+ if (there) {
1136
1309
  this.onChat = { id: chatId };
1310
+ await this.runSteps('open');
1311
+ }
1137
1312
  return there;
1138
1313
  }
1139
1314
  /** Finds a conversation by its exact name in the sidebar. */
@@ -1152,6 +1327,7 @@ Current URL: ${url}`);
1152
1327
  this.onChat = { id };
1153
1328
  this.chatNames.set(id, name);
1154
1329
  }
1330
+ await this.runSteps('open');
1155
1331
  return true;
1156
1332
  }
1157
1333
  async currentChatId() {
@@ -1213,6 +1389,7 @@ Current URL: ${url}`);
1213
1389
  break;
1214
1390
  this.onChat = want;
1215
1391
  await this.dismissPopups().catch(() => undefined);
1392
+ await this.runSteps('open', opts.signal);
1216
1393
  this.emit('chat-returned', { chatId: want.id, by: 'address', signedIn, from });
1217
1394
  return { at: 'returned', chatId: want.id, from, by: 'address', signedIn };
1218
1395
  }
@@ -1254,6 +1431,9 @@ Current URL: ${url}`);
1254
1431
  * something else entirely.
1255
1432
  */
1256
1433
  async dismissPopups() {
1434
+ // Switched off in Settings → "Steps to the chat" (2026-11-17).
1435
+ if (!this.builtIn.popups)
1436
+ return;
1257
1437
  for (const name of ['Got it', 'Close', 'Dismiss', 'No thanks', 'Skip', 'Set later', 'Not now', 'Maybe later', 'Reject All', 'Reject all']) {
1258
1438
  const b = this.p.getByRole('button', { name, exact: true });
1259
1439
  if ((await b.count()) > 0 && (await b.first().isVisible().catch(() => false))) {
@@ -1271,6 +1451,13 @@ Current URL: ${url}`);
1271
1451
  * of it when Copilot's dialog refused that one (see `chatNameForms`) — or false when it could not be renamed.
1272
1452
  */
1273
1453
  async nameChat(chatId, name, opts = {}) {
1454
+ // Switched off in Settings → "Steps to the chat" (2026-11-17): the conversation keeps Copilot's own title.
1455
+ if (!this.builtIn.nameChat) {
1456
+ if (!this.nameOffSaid)
1457
+ this.emit('chat-name-off', { chatId, name });
1458
+ this.nameOffSaid = true;
1459
+ return false;
1460
+ }
1274
1461
  const row = this.el('conversationLink').and(this.p.locator(`[href*="${chatId}"]`)).first();
1275
1462
  // Waited for, like everything below: a new chat's row appears in the sidebar some seconds after the
1276
1463
  // reply, and `count()` read it as missing and returned without a word (live run 2026-10-03). The run
@@ -1335,6 +1522,20 @@ Current URL: ${url}`);
1335
1522
  const refused = [];
1336
1523
  for (const form of chatNameForms(name)) {
1337
1524
  await input.fill(form);
1525
+ /*
1526
+ * Its Save not found (work, 2026-11-18: role=button[name="Save"] found nothing, and the dialog was left open
1527
+ * over the chat): said, with the dialog's HTML while it is still open, and the name given with Enter, which
1528
+ * such a field takes. Once only: a dialog that takes no Enter is closed with Cancel below.
1529
+ */
1530
+ if (!(await save.waitFor({ state: 'visible', timeout: 3_000 }).then(() => true, () => false))) {
1531
+ await this.warnLocator('renameSave', `while the conversation was being named "${name}"`, chatId).catch(() => undefined);
1532
+ await input.press('Enter').catch(() => undefined);
1533
+ if (await this.renameTaken(input, save))
1534
+ wanted = form;
1535
+ else
1536
+ refused.push(form);
1537
+ break;
1538
+ }
1338
1539
  await this.press(save);
1339
1540
  if (await this.renameTaken(input, save)) {
1340
1541
  wanted = form;
@@ -1368,6 +1569,9 @@ Current URL: ${url}`);
1368
1569
  this.emit('chat-name-failed', { chatId, name, error: e.message });
1369
1570
  // The step's locator, when it finds nothing: said (the name is the work's convenience; the work goes on).
1370
1571
  await this.warnLocator(step, `while the conversation was being named "${name}"`, chatId).catch(() => undefined);
1572
+ // A rename dialog it stopped in is not left open over the chat (work, 2026-11-18): closed, after its HTML is kept.
1573
+ if (step === 'renameInput' || step === 'renameSave')
1574
+ await this.p.keyboard.press('Escape').catch(() => undefined);
1371
1575
  return false;
1372
1576
  }
1373
1577
  finally {
@@ -1864,7 +2068,7 @@ Current URL: ${url}`);
1864
2068
  let shot = 0;
1865
2069
  /** With `modelStepShots`, a picture and the menu's HTML at each step, numbered, beside the transport's files. */
1866
2070
  const picture = async (label) => {
1867
- if (!this.opts.modelStepShots)
2071
+ if (!this.stepShots)
1868
2072
  return;
1869
2073
  shot += 1;
1870
2074
  await this.captureMenu(`step-${String(shot).padStart(2, '0')}-${label.replace(/[^A-Za-z0-9._-]+/g, '-').slice(0, 40)}`, await this.readMenuRows().catch(() => [])).catch(() => undefined);
@@ -2334,6 +2538,7 @@ Current URL: ${url}`);
2334
2538
  throw new Error('Refusing to send an empty message: the composer requires text.');
2335
2539
  }
2336
2540
  await this.clearBlockers();
2541
+ await this.runSteps('message');
2337
2542
  if (attachments.length > 0)
2338
2543
  await this.attach(attachments);
2339
2544
  const composer = this.composer();
@@ -2384,6 +2589,8 @@ Current URL: ${url}`);
2384
2589
  * scoped now, so the panel being open is untidy rather than fatal.
2385
2590
  */
2386
2591
  async dismissFeedbackPanel() {
2592
+ if (!this.builtIn.feedbackPanel)
2593
+ return;
2387
2594
  const panel = this.p.locator(Css.feedbackPanel);
2388
2595
  if ((await panel.count()) === 0)
2389
2596
  return;
@@ -2482,20 +2689,70 @@ Current URL: ${url}`);
2482
2689
  * prefix, which is the signal that the upload actually finished.
2483
2690
  */
2484
2691
  async attach(paths) {
2485
- await this.p.setInputFiles(Upload.input, paths);
2692
+ /*
2693
+ * By the chat's locators in force (2026-11-17: the work page showed the attached file as a card of its own, and the
2694
+ * old `div.fx-Attachment[aria-label=<name>]`, written in the code, waited two minutes and ended the message with
2695
+ * Playwright's own words). Each can be set in Settings → "The chat's locators" → "Attaching a file"; one that finds
2696
+ * nothing is said by its name, with the page's HTML, like the others.
2697
+ */
2698
+ const input = this.el('uploadInput').first();
2699
+ const there = await input.waitFor({ state: 'attached', timeout: this.inputWaitMs }).then(() => true, () => false);
2700
+ if (!there)
2701
+ throw await this.locatorMissing('uploadInput', 'when a file was to be attached to the message');
2702
+ await input.setInputFiles(paths);
2486
2703
  for (const path of paths) {
2487
2704
  const name = path.split(/[\\/]/).pop();
2488
- const chip = this.p.locator(`${Upload.chip}[aria-label="${name.replace(/"/g, '\\"')}"]`);
2489
- await chip.first().waitFor({ state: 'visible', timeout: 120_000 });
2490
- await this.p
2491
- .waitForFunction(({ sel, prefix }) => {
2492
- const el = document.querySelector(sel);
2493
- return !!el && (el.id || '').startsWith(prefix);
2494
- }, { sel: `${Upload.chip}[aria-label="${name.replace(/"/g, '\\"')}"]`, prefix: Upload.uploadedIdPrefix }, { timeout: 120_000 })
2495
- .catch(() => this.emit('attachment-upload-unconfirmed', { name }));
2705
+ const shown = await this.fileEl('attachment', path)
2706
+ .filter({ visible: true })
2707
+ .first()
2708
+ .waitFor({ state: 'visible', timeout: this.attachWaitMs })
2709
+ .then(() => true, (e) => {
2710
+ if (e.name !== 'TimeoutError')
2711
+ throw e;
2712
+ return false;
2713
+ });
2714
+ if (!shown) {
2715
+ throw await this.locatorMissing('attachment', `after the file ${name} was put in the box's file input, within ${Math.round(this.attachWaitMs / 1000)} s`);
2716
+ }
2717
+ // Uploaded: the locator finds it, and goes on finding it for a moment (a spinner can come a little after the card).
2718
+ const uploaded = await this.holds(async () => (await this.fileEl('attachmentUploaded', path).count().catch(() => 0)) > 0, this.uploadWaitMs, 2_000);
2719
+ if (!uploaded) {
2720
+ // As before: the message goes on (Send waits while it cannot be pressed); what found nothing is said once a window.
2721
+ this.emit('attachment-upload-unconfirmed', { name });
2722
+ if (!this.warned.has('attachmentUploaded')) {
2723
+ this.warned.add('attachmentUploaded');
2724
+ await this.locatorMissing('attachmentUploaded', `for ${Math.round(this.uploadWaitMs / 1000)} s after the file ${name} was attached`, { stopped: false, file: path }).catch(() => undefined);
2725
+ }
2726
+ }
2496
2727
  this.emit('attached', { name });
2497
2728
  }
2498
2729
  }
2730
+ /** How long an attached file may take to show in the box, and to finish uploading (fields, for the checks). */
2731
+ inputWaitMs = 10_000;
2732
+ attachWaitMs = 30_000;
2733
+ uploadWaitMs = 120_000;
2734
+ /** An attached file's locator in force, with the file's name put in its place (see `fillFileLocator`). */
2735
+ fileEl(key, file) {
2736
+ return this.p.locator(playwrightSelector(fillFileLocator(this.chatLocators[key], file)));
2737
+ }
2738
+ /** Whether `test` comes true within `ms` and stays true for `steadyMs`, looked at every half second. */
2739
+ async holds(test, ms, steadyMs) {
2740
+ const until = Date.now() + ms;
2741
+ let since = null;
2742
+ while (Date.now() < until) {
2743
+ if (this.p.isClosed())
2744
+ return false;
2745
+ if (await test()) {
2746
+ since ??= Date.now();
2747
+ if (Date.now() - since >= steadyMs)
2748
+ return true;
2749
+ }
2750
+ else
2751
+ since = null;
2752
+ await this.p.waitForTimeout(500);
2753
+ }
2754
+ return false;
2755
+ }
2499
2756
  /**
2500
2757
  * Waits for the answer to finish streaming, then returns its raw markdown.
2501
2758
  *
@@ -233,6 +233,10 @@ export class KeptWindow {
233
233
  checkLocators(...a) {
234
234
  return this.withWindow(() => this.inner.checkLocators(...a));
235
235
  }
236
+ /** Settings saved since the window opened: taken by it, open or not (a window opened again is the same one). */
237
+ takeSettings(...a) {
238
+ this.inner.takeSettings(...a);
239
+ }
236
240
  }
237
241
  /** A window kept for the work, its `window-closed` heard as it happens. */
238
242
  export function keptWindow(make, opts) {
@@ -222,9 +222,15 @@ export const CHAT_LOCATOR_KEYS = [
222
222
  'renameItem',
223
223
  'renameInput',
224
224
  'renameSave',
225
+ 'uploadInput',
226
+ 'attachment',
227
+ 'attachmentUploaded',
225
228
  ];
226
229
  /** Where a conversation's id goes in a template (the sidebar's "More" button of one conversation). */
227
230
  export const CHAT_ID = '{$chat_id}';
231
+ /** Where an attached file's name goes (`message-01-in-full.txt`), and its name without the extension (`message-01-in-full`). */
232
+ export const FILE_NAME = '{$file_name}';
233
+ export const FILE_STEM = '{$file_stem}';
228
234
  export const DefaultChatLocators = {
229
235
  composer: '#m365-chat-editor-target-element, [data-test-id="chat-input-wrapper"] [role="textbox"][contenteditable="true"]',
230
236
  send: '[data-test-id="chat-input-wrapper"] >> role=button[name="Send"]',
@@ -238,6 +244,21 @@ export const DefaultChatLocators = {
238
244
  renameItem: 'role=menuitem[name="Rename"]',
239
245
  renameInput: '#new-session-name',
240
246
  renameSave: 'role=button[name="Save"]',
247
+ uploadInput: '#upload-file-button',
248
+ /*
249
+ * The attached file in the box, before Send (2026-11-17: the work page shows it as a card with the name without
250
+ * its extension and "Text file", no longer `div.fx-Attachment[aria-label=<name>]`). Either: the old one by its
251
+ * label, or, in the box's wrapper, the element whose text is exactly the file's name, with or without the extension.
252
+ */
253
+ attachment: `div.fx-Attachment[aria-label="${FILE_NAME}"], [data-test-id="chat-input-wrapper"] :text-is("${FILE_STEM}"), ` +
254
+ `[data-test-id="chat-input-wrapper"] :text-is("${FILE_NAME}")`,
255
+ /*
256
+ * The same, once it is uploaded: the old one's id starts with SPO_ then; on the new page, nothing in the box's wrapper
257
+ * shows progress any more (a spinner, a progress bar: role=progressbar).
258
+ */
259
+ attachmentUploaded: `div.fx-Attachment[aria-label="${FILE_NAME}"][id^="SPO_"], ` +
260
+ `[data-test-id="chat-input-wrapper"]:not(:has(div.fx-Attachment)):not(:has([role="progressbar"])) :text-is("${FILE_STEM}"), ` +
261
+ `[data-test-id="chat-input-wrapper"]:not(:has(div.fx-Attachment)):not(:has([role="progressbar"])) :text-is("${FILE_NAME}")`,
241
262
  };
242
263
  export const ChatLocatorGroupOf = {
243
264
  composer: 'write',
@@ -252,6 +273,9 @@ export const ChatLocatorGroupOf = {
252
273
  renameItem: 'conversations',
253
274
  renameInput: 'conversations',
254
275
  renameSave: 'conversations',
276
+ uploadInput: 'attach',
277
+ attachment: 'attach',
278
+ attachmentUploaded: 'attach',
255
279
  };
256
280
  /**
257
281
  * What each one is, in words a chatbot that reads the page's HTML can find it by (the text it is handed with the HTML,
@@ -270,9 +294,79 @@ export const ChatLocatorWhat = {
270
294
  renameItem: 'the "Rename" item of the menu a conversation\'s "More" button opens in the sidebar',
271
295
  renameInput: 'the text field of the dialog that renames a conversation',
272
296
  renameSave: 'the "Save" button of the dialog that renames a conversation',
297
+ uploadInput: 'the hidden file input (input type="file") of the box where a message is typed, through which files are attached to the message',
298
+ attachment: `the file attached to the message, as the box shows it before Send (a card with the file's name); ${FILE_NAME} is where the file's name goes (message-01-in-full.txt), ${FILE_STEM} the name without its extension (message-01-in-full)`,
299
+ attachmentUploaded: `the same attached file once it has finished uploading (no spinner or progress on it any more); ${FILE_NAME} is where the file's name goes, ${FILE_STEM} the name without its extension`,
300
+ };
301
+ /**
302
+ * Places on the page an element that is not found is most likely near, when none of the chat's own locators finds
303
+ * something beside it (operator, 2026-11-18: "the piece of code where the new locator probably is").
304
+ */
305
+ export const NearPlaces = {
306
+ wrapper: { selector: '[data-test-id="chat-input-wrapper"], [data-testid="chat-input-wrapper"]', what: 'the area around the box where a message is typed' },
307
+ dialog: { selector: '[role="dialog"], [role="alertdialog"], [aria-modal="true"], dialog[open]', what: 'the dialog open on the page' },
308
+ menu: { selector: '[role="menu"], [role="listbox"]', what: 'the menu open on the page' },
309
+ main: { selector: 'main, [role="main"]', what: 'the main part of the page, where the conversation is' },
310
+ sidebar: { selector: 'nav, [role="navigation"], aside', what: 'the sidebar with the list of conversations' },
273
311
  };
274
- /** The placeholder a template must hold; the others hold none. */
275
- export const ChatPlaceholder = { chatMore: CHAT_ID };
312
+ /**
313
+ * Where to look for each element that was not found, nearest first: another of the chat's locators that finds
314
+ * something beside it (the box for its Send, the rename dialog's field for its Save), or a place (`NearPlaces`). The
315
+ * first that finds something gives the piece of the page handed to a chatbot.
316
+ */
317
+ export const ChatLocatorNear = {
318
+ composer: ['wrapper', 'send', 'uploadInput', 'main'],
319
+ send: ['composer', 'wrapper', 'uploadInput'],
320
+ userMessage: ['turn', 'answer', 'main'],
321
+ turn: ['userMessage', 'answer', 'main'],
322
+ answer: ['turn', 'copy', 'userMessage', 'main'],
323
+ copy: ['answer', 'turn', 'main'],
324
+ stop: ['composer', 'send', 'wrapper', 'answer'],
325
+ conversationLink: ['sidebar'],
326
+ chatMore: ['conversationLink', 'sidebar'],
327
+ renameItem: ['menu', 'chatMore', 'sidebar'],
328
+ renameInput: ['dialog', 'renameSave', 'sidebar'],
329
+ renameSave: ['renameInput', 'dialog'],
330
+ uploadInput: ['composer', 'wrapper', 'send'],
331
+ attachment: ['composer', 'wrapper', 'uploadInput'],
332
+ attachmentUploaded: ['attachment', 'composer', 'wrapper'],
333
+ };
334
+ /** For one of the operator's own steps, whose element can be anywhere: a dialog first (most are), then the box's area. */
335
+ export const StepNear = ['dialog', 'wrapper', 'composer', 'main'];
336
+ /** When each one is on the screen, for a person to bring it there and find it by hand in the browser's developer tools. */
337
+ export const ChatLocatorShows = {
338
+ composer: 'open Copilot\'s chat: the box is at the bottom of the page',
339
+ send: 'type a word in the box at the bottom of the chat: the Send button is beside it (do not send it)',
340
+ userMessage: 'open a conversation that has messages: each message the user sent is shown in it',
341
+ turn: 'open a conversation that has messages',
342
+ answer: 'open a conversation in which Copilot has answered',
343
+ copy: 'open a conversation in which Copilot has answered, and point the mouse at an answer: the Copy button is in the row of small buttons under it',
344
+ stop: 'send Copilot a question that takes a long answer, and while it is still writing, the Stop button shows (near the box at the bottom)',
345
+ conversationLink: 'open the sidebar with the list of conversations (the button at the top left, if it is closed)',
346
+ chatMore: 'in the sidebar, point the mouse at a conversation: its "More" button (three dots) shows on its row',
347
+ renameItem: 'in the sidebar, click a conversation\'s "More" button (three dots): the menu with "Rename" opens',
348
+ renameInput: 'in the sidebar, click a conversation\'s "More" button (three dots), then "Rename": the dialog with the field opens',
349
+ renameSave: 'in the sidebar, click a conversation\'s "More" button (three dots), then "Rename": the dialog opens; its button that saves the name is the one wanted (do not click it)',
350
+ uploadInput: 'it is never on the screen: it is the hidden <input type="file"> near the box at the bottom, found in Elements with Ctrl+F and input[type="file"]',
351
+ attachment: 'attach a file to the message with the box\'s attach button (a paper clip or a "+"): its card shows in the box',
352
+ attachmentUploaded: 'attach a file to the message with the box\'s attach button (a paper clip or a "+") and wait until it has finished uploading (no spinner or progress on its card): the card as it is then is wanted',
353
+ };
354
+ /** The placeholder a template must hold; the others hold none. An attached file's: its name, or its name without the extension. */
355
+ export const ChatPlaceholder = { chatMore: CHAT_ID, attachment: FILE_NAME, attachmentUploaded: FILE_NAME };
356
+ /** Whether a template holds its placeholder (for a file's, either of the two). */
357
+ export function holdsChatPlaceholder(key, locator) {
358
+ const needs = ChatPlaceholder[key];
359
+ if (!needs)
360
+ return true;
361
+ return locator.includes(needs) || (needs === FILE_NAME && locator.includes(FILE_STEM));
362
+ }
363
+ /** A file template with the file's name put in, safe inside the quotes it stands in. */
364
+ export function fillFileLocator(template, file) {
365
+ const name = file.split(/[\\/]/).pop() ?? file;
366
+ const stem = name.replace(/\.[^.]*$/, '');
367
+ const quoted = (v) => v.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
368
+ return template.split(FILE_NAME).join(quoted(name)).split(FILE_STEM).join(quoted(stem));
369
+ }
276
370
  /** The chat's locators in force: each one saved in Settings, else the default; one that cannot be used is said in `problems`. */
277
371
  export function resolveChatLocators(saved) {
278
372
  const locators = { ...DefaultChatLocators };
@@ -282,7 +376,11 @@ export function resolveChatLocators(saved) {
282
376
  if (!own)
283
377
  continue;
284
378
  const needs = ChatPlaceholder[key];
285
- const problem = needs && !own.includes(needs) ? `it has no ${needs}: put it where the conversation's id goes` : locatorSyntaxProblem(own);
379
+ const problem = needs && !holdsChatPlaceholder(key, own)
380
+ ? needs === FILE_NAME
381
+ ? `it has no ${FILE_NAME} (or ${FILE_STEM}): put it where the file's name goes`
382
+ : `it has no ${needs}: put it where the conversation's id goes`
383
+ : locatorSyntaxProblem(own);
286
384
  if (problem)
287
385
  problems.push(`the chat's ${key} locator in Settings is not used, ${problem}`);
288
386
  else
@@ -303,12 +401,15 @@ export function locatorPrompt(key, failed) {
303
401
  'Give me one locator that finds exactly this element, and only it: a CSS selector, or an XPath if CSS cannot say it.',
304
402
  'Use what stays the same between versions of the page: id, role, aria-label, data-testid, data-test-id and other data-* attributes, the tag.',
305
403
  'Do not use class names made of random letters (like azFuQXgw or ___1x5usfw): they change with every new version of the page.',
306
- ...(ChatPlaceholder[key] ? [`Keep ${ChatPlaceholder[key]} in it where the conversation's id goes.`] : []),
404
+ ...(ChatPlaceholder[key] === CHAT_ID ? [`Keep ${CHAT_ID} in it where the conversation's id goes.`] : []),
405
+ ...(ChatPlaceholder[key] === FILE_NAME
406
+ ? [`Keep ${FILE_NAME} in it where the file's name goes (message-01-in-full.txt), or ${FILE_STEM} for the name without its extension (message-01-in-full): the attached file in the HTML is message-01-in-full.txt.`]
407
+ : []),
307
408
  'Answer with the locator on the first line, then one line on why it is that element.',
308
409
  ].join('\n');
309
410
  }
310
411
  /** An XPath axis written with one colon (`parent:span`), which is not XPath; null when there is none. */
311
- function locatorSyntaxProblem(locator) {
412
+ export function locatorSyntaxProblem(locator) {
312
413
  const axis = /(^|[/[(|\s])(ancestor-or-self|ancestor|attribute|child|descendant-or-self|descendant|following-sibling|following|parent|preceding-sibling|preceding|self):(?!:)/.exec(locator);
313
414
  return axis && isXPath(locator) ? `"${axis[2]}:" needs two colons: ${axis[2]}::` : null;
314
415
  }