copilot-operator 0.1.59 → 0.1.61

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 (59) hide show
  1. package/dist/src/api/operator.controller.js +78 -1
  2. package/dist/src/api/operator.service.js +248 -3
  3. package/dist/src/cli.js +3 -0
  4. package/dist/src/config/exportHome.js +78 -0
  5. package/dist/src/config/schema.js +22 -0
  6. package/dist/src/orchestrator/taskRunner.js +15 -4
  7. package/dist/src/plan/systemGuide.js +278 -0
  8. package/dist/src/queue/queue.js +113 -0
  9. package/dist/src/transport/copilotTransport.js +263 -131
  10. package/dist/src/transport/locators.js +119 -33
  11. package/dist/src/util/zip.js +80 -0
  12. package/dist/src/vcs/taskVcs.js +25 -1
  13. package/dist/web/404.html +2 -2
  14. package/dist/web/_next/static/VmnUW8Gr79dsc-Ifk8oGP/_buildManifest.js +1 -0
  15. package/dist/web/_next/static/chunks/1077.d84d3a09cffc08c0.js +1 -0
  16. package/dist/web/_next/static/chunks/1548.03db34ce36acd5d5.js +1 -0
  17. package/dist/web/_next/static/chunks/2163.56378b27583dfc24.js +1 -0
  18. package/dist/web/_next/static/chunks/4512-db21be6b8e4eabf4.js +1 -0
  19. package/dist/web/_next/static/chunks/714.5cc516832a5f44c9.js +1 -0
  20. package/dist/web/_next/static/chunks/7220.26bb7ae30c8a587a.js +1 -0
  21. package/dist/web/_next/static/chunks/7921-51a72190643f4b1a.js +1 -0
  22. package/dist/web/_next/static/chunks/8197-e2fcb43f38a2b4a7.js +1 -0
  23. package/dist/web/_next/static/chunks/8584.49c69cd6e77d2fd7.js +1 -0
  24. package/dist/web/_next/static/chunks/9067.7ae4ac6836a74d94.js +1 -0
  25. package/dist/web/_next/static/chunks/9747.5a244ec2d1b84d29.js +1 -0
  26. package/dist/web/_next/static/chunks/app/layout-f18945b2fe2c8719.js +1 -0
  27. package/dist/web/_next/static/chunks/app/{page-c3c50d426109e8c5.js → page-9c0f8e27ab7c8677.js} +1 -1
  28. package/dist/web/_next/static/chunks/app/queue/page-7d853e6bcbbacf0d.js +1 -0
  29. package/dist/web/_next/static/chunks/app/settings/page-1833ace66fc9eb0e.js +1 -0
  30. package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +1 -0
  31. package/dist/web/_next/static/chunks/{webpack-d210ad961e7a9237.js → webpack-047b9e390d242a45.js} +1 -1
  32. package/dist/web/_next/static/css/{e544b477e4b4b108.css → 975a0235944db79c.css} +1 -1
  33. package/dist/web/defaults.html +2 -2
  34. package/dist/web/defaults.txt +8 -8
  35. package/dist/web/index.html +3 -3
  36. package/dist/web/index.txt +9 -9
  37. package/dist/web/queue.html +14 -0
  38. package/dist/web/queue.txt +26 -0
  39. package/dist/web/settings.html +2 -2
  40. package/dist/web/settings.txt +9 -9
  41. package/dist/web/system.html +2 -2
  42. package/dist/web/system.txt +9 -9
  43. package/package.json +5 -2
  44. package/dist/web/_next/static/Gan_sPghz9GR_aVaCL2ah/_buildManifest.js +0 -1
  45. package/dist/web/_next/static/chunks/1077.34c33df752c793fd.js +0 -1
  46. package/dist/web/_next/static/chunks/1548.9bd3216f2e2ed40a.js +0 -1
  47. package/dist/web/_next/static/chunks/2163.c764c5ddf04e8f3c.js +0 -1
  48. package/dist/web/_next/static/chunks/3134-b6a7bc1f267c39aa.js +0 -1
  49. package/dist/web/_next/static/chunks/4512-bf72c643d4a4db71.js +0 -1
  50. package/dist/web/_next/static/chunks/714.ce1d54a2c2b5474f.js +0 -1
  51. package/dist/web/_next/static/chunks/7220.07100b580a566f9c.js +0 -1
  52. package/dist/web/_next/static/chunks/7921-97fcfd1f6aff2774.js +0 -1
  53. package/dist/web/_next/static/chunks/8584.d863bb44ea78998d.js +0 -1
  54. package/dist/web/_next/static/chunks/9067.3d3d65b5fb1c6a61.js +0 -1
  55. package/dist/web/_next/static/chunks/9747.af530d25cd7cc8fb.js +0 -1
  56. package/dist/web/_next/static/chunks/app/layout-9cd9b0b0587f4882.js +0 -1
  57. package/dist/web/_next/static/chunks/app/settings/page-e485720f199e3194.js +0 -1
  58. package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +0 -1
  59. /package/dist/web/_next/static/{Gan_sPghz9GR_aVaCL2ah → VmnUW8Gr79dsc-Ifk8oGP}/_ssgManifest.js +0 -0
@@ -16,7 +16,7 @@ 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, Css, Label, Model, ModelPicking, OperatorModelLocators, Rename, Sidebar, Signal, Surface, TestId, Upload, Url } from './locators.js';
19
+ import { Blocker, Css, fillLocator, Label, Model, ModelPicking, pageQuery, playwrightSelector, Rename, resolvePickerLocators, Sidebar, Signal, Surface, TestId, Upload, Url, } from './locators.js';
20
20
  import { acquireProfileLock } from './profileLock.js';
21
21
  import { chatNameForms, parseChatId } from './chatSession.js';
22
22
  /**
@@ -63,22 +63,23 @@ export function surfaceOfUrl(url) {
63
63
  return 'unknown';
64
64
  }
65
65
  /**
66
- * Which of the operator's locators a chosen model is. Groups first, by the word the locator is written
67
- * with ("Sonnet", "Opus", "GPT-5.6 Sol Think deeper") contained in the name, longest first; then the
68
- * models at the top, by their name ("Think deeper" is in "GPT-5.6 Sol Think deeper" too, so they come
69
- * last). Null for a model the operator gave no locator for.
66
+ * The operator's locators for a model, from the templates in force and where the list read from the page found it
67
+ * (operator, 2026-10-24): a model of the main menu by the template for those; one in a provider's menu by the
68
+ * provider's template, with the provider's name as the list read it, and then the template for a model there. Null
69
+ * when the model's place is not known: the list is read first (see `chooseModel`).
70
70
  */
71
- export function operatorTargetFor(name) {
72
- const n = ` ${normModel(name)} `;
73
- const has = (word) => n.includes(` ${normModel(word)} `);
74
- const inGroups = OperatorModelLocators.groups
75
- .flatMap((g) => g.models.map((m) => ({ model: m.model, xpath: m.xpath, group: { name: g.group, xpath: g.xpath } })))
76
- .sort((a, b) => b.model.length - a.model.length);
77
- const grouped = inGroups.find((m) => has(m.model));
78
- if (grouped)
79
- return grouped;
80
- const top = OperatorModelLocators.top.find((m) => sameModel(m.model, name));
81
- return top ? { model: top.model, xpath: top.xpath } : null;
71
+ export function templateTarget(name, place, locators) {
72
+ if (!place)
73
+ return null;
74
+ if (!place.group)
75
+ return { model: name, locator: fillLocator(locators.model, { model: name }), kind: 'model' };
76
+ const provider = place.group.name;
77
+ return {
78
+ model: name,
79
+ locator: fillLocator(locators.providerModel, { model: name, provider }),
80
+ kind: 'providerModel',
81
+ group: { name: provider, locator: fillLocator(locators.provider, { provider }), at: place.group },
82
+ };
82
83
  }
83
84
  /** The second line of a group's row: its vendor ("OpenAI", "Anthropic"). */
84
85
  function vendorOf(row) {
@@ -163,65 +164,65 @@ const NOTICE_ID = 'copilot-operator-notice';
163
164
  * impossible — the runner notes it before the click and waits for it to move, so a copy that
164
165
  * did not happen reads as a failure rather than as the previous answer.
165
166
  */
166
- export const CLIPBOARD_GUARD = `(() => {
167
- const state = { text: '', seq: 0 };
168
- try {
169
- Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
170
- } catch (e) {
171
- window.__copClipboard = state;
172
- }
173
-
174
- const remember = (text) => {
175
- if (typeof text !== 'string' || text.length === 0) return;
176
- state.text = text;
177
- state.seq += 1;
178
- };
179
-
180
- const clip = navigator.clipboard;
181
- if (clip) {
182
- try {
183
- Object.defineProperty(clip, 'writeText', {
184
- configurable: true,
185
- writable: true,
186
- value: (text) => {
187
- remember(String(text));
188
- return Promise.resolve();
189
- },
190
- });
191
- } catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
192
-
193
- try {
194
- Object.defineProperty(clip, 'write', {
195
- configurable: true,
196
- writable: true,
197
- value: async (items) => {
198
- for (const item of items || []) {
199
- try {
200
- if (item && item.types && item.types.indexOf('text/plain') >= 0) {
201
- remember(await (await item.getType('text/plain')).text());
202
- }
203
- } catch (e) { /* one unreadable item is not a reason to drop the rest */ }
204
- }
205
- },
206
- });
207
- } catch (e) { /* as above */ }
208
- }
209
-
210
- // The old way: select text in a hidden field, then execCommand('copy'). The selection is
211
- // exactly the text being copied, so it is taken and the command is never run.
212
- try {
213
- const realExec = document.execCommand.bind(document);
214
- document.execCommand = (command, ...rest) => {
215
- if (String(command).toLowerCase() === 'copy') {
216
- const selected = String(window.getSelection() || '');
217
- if (selected.length > 0) {
218
- remember(selected);
219
- return true;
220
- }
221
- }
222
- return realExec(command, ...rest);
223
- };
224
- } catch (e) { /* as above */ }
167
+ export const CLIPBOARD_GUARD = `(() => {
168
+ const state = { text: '', seq: 0 };
169
+ try {
170
+ Object.defineProperty(window, '__copClipboard', { value: state, enumerable: false });
171
+ } catch (e) {
172
+ window.__copClipboard = state;
173
+ }
174
+
175
+ const remember = (text) => {
176
+ if (typeof text !== 'string' || text.length === 0) return;
177
+ state.text = text;
178
+ state.seq += 1;
179
+ };
180
+
181
+ const clip = navigator.clipboard;
182
+ if (clip) {
183
+ try {
184
+ Object.defineProperty(clip, 'writeText', {
185
+ configurable: true,
186
+ writable: true,
187
+ value: (text) => {
188
+ remember(String(text));
189
+ return Promise.resolve();
190
+ },
191
+ });
192
+ } catch (e) { /* a frame that will not let its clipboard be replaced reads as a failure later */ }
193
+
194
+ try {
195
+ Object.defineProperty(clip, 'write', {
196
+ configurable: true,
197
+ writable: true,
198
+ value: async (items) => {
199
+ for (const item of items || []) {
200
+ try {
201
+ if (item && item.types && item.types.indexOf('text/plain') >= 0) {
202
+ remember(await (await item.getType('text/plain')).text());
203
+ }
204
+ } catch (e) { /* one unreadable item is not a reason to drop the rest */ }
205
+ }
206
+ },
207
+ });
208
+ } catch (e) { /* as above */ }
209
+ }
210
+
211
+ // The old way: select text in a hidden field, then execCommand('copy'). The selection is
212
+ // exactly the text being copied, so it is taken and the command is never run.
213
+ try {
214
+ const realExec = document.execCommand.bind(document);
215
+ document.execCommand = (command, ...rest) => {
216
+ if (String(command).toLowerCase() === 'copy') {
217
+ const selected = String(window.getSelection() || '');
218
+ if (selected.length > 0) {
219
+ remember(selected);
220
+ return true;
221
+ }
222
+ }
223
+ return realExec(command, ...rest);
224
+ };
225
+ } catch (e) { /* as above */ }
225
226
  })();`;
226
227
  export class CopilotTransport {
227
228
  opts;
@@ -238,8 +239,23 @@ export class CopilotTransport {
238
239
  closing = false;
239
240
  /** The window went away without `close`: its X pressed, or Edge ended (2026-10-19). */
240
241
  gone = false;
242
+ /** The model menu's locators in force: Settings' own, else the defaults (see `resolvePickerLocators`). */
243
+ locators;
244
+ /** Why a locator saved in Settings is not used; said once, at the first choice or reading of the models. */
245
+ locatorProblems;
246
+ /** Whether the rows' locator has been said not to work in the page (see `readMenuRows`). */
247
+ rowsLocatorFailed = false;
241
248
  constructor(opts) {
242
249
  this.opts = opts;
250
+ const { locators, problems } = resolvePickerLocators(opts.pickerLocators);
251
+ this.locators = locators;
252
+ this.locatorProblems = problems;
253
+ }
254
+ /** Says, once, which locators saved in Settings could not be used and why. */
255
+ sayLocatorProblems() {
256
+ for (const problem of this.locatorProblems)
257
+ this.emit('model-locator-not-used', { problem });
258
+ this.locatorProblems = [];
243
259
  }
244
260
  /** A pause of the model picker that ends early, with `StoppedByOperator`, once the run is stopped. */
245
261
  async hold(ms) {
@@ -530,7 +546,7 @@ export class CopilotTransport {
530
546
  'sign-in': 'The profile is signed out. Run "cop login".',
531
547
  unknown: 'The page is not the Microsoft 365 Copilot chat.',
532
548
  };
533
- throw new Error(`${explain[where] ?? explain.unknown}
549
+ throw new Error(`${explain[where] ?? explain.unknown}
534
550
  Current URL: ${url}`);
535
551
  }
536
552
  /**
@@ -870,9 +886,9 @@ Current URL: ${url}`);
870
886
  // The aria-label is the control's name ("Model Selector"); the text is the value ("Auto").
871
887
  return text.length > 0 ? text.split('\n')[0].trim() : label.replace(Model.buttonLabel, '').trim() || null;
872
888
  }
889
+ /** The picker button by the locator in force (Settings' own since 2026-10-24, else `button#gptModeSwitcher`). */
873
890
  modelButton() {
874
- const byId = this.p.locator(Model.button);
875
- return byId;
891
+ return this.p.locator(playwrightSelector(this.locators.button));
876
892
  }
877
893
  /**
878
894
  * The picker button, by id if it is there, otherwise by its accessible name.
@@ -910,9 +926,10 @@ Current URL: ${url}`);
910
926
  * model, so the run could not choose it and went on Auto (2026-10-05).
911
927
  */
912
928
  async listModels() {
929
+ this.sayLocatorProblems();
913
930
  const button = await this.resolveModelButton();
914
931
  if (!button) {
915
- return { options: [], current: null, note: 'This chat does not show a model picker, so there is nothing to choose.' };
932
+ return { options: [], current: null, note: `This chat does not show a model picker, so there is nothing to choose (the picker button's locator: ${this.locators.button}).` };
916
933
  }
917
934
  const current = await this.currentModel();
918
935
  await button.click();
@@ -925,6 +942,9 @@ Current URL: ${url}`);
925
942
  const top = this.topRows(shown);
926
943
  await this.captureMenu('top', shown);
927
944
  await this.closeMenu();
945
+ if (shown.length === 0) {
946
+ return { options: [], current, note: `The model menu opened, and its rows' locator found nothing in it (${this.locators.rows}). Settings → "The model menu's locators" has it; the menu is kept as models-top.html/.png.` };
947
+ }
928
948
  const strip = (r) => ({ name: r.name, raw: r.raw, selected: r.selected, disabled: r.disabled, role: r.role });
929
949
  const options = top.filter((r) => !r.opensSubmenu).map((r) => ({ ...strip(r), locator: { role: r.role, index: r.index } }));
930
950
  const groups = top.filter((r) => r.opensSubmenu);
@@ -985,17 +1005,36 @@ Current URL: ${url}`);
985
1005
  * the row that opens it) and its place there (`index`), so the same row can be found again without
986
1006
  * going by its text. Rows are not merged by name: the group row and the model chosen in it carry the
987
1007
  * same name once that model is in force.
1008
+ *
1009
+ * The rows are what the rows' locator in force finds (Settings' own since 2026-10-24), an XPath or a CSS selector.
988
1010
  */
989
1011
  async readMenuRows() {
990
- return await this.p.evaluate(({ roles, selectedAttrs, submenuAttrs }) => {
1012
+ const read = await this.p.evaluate(({ query, selectedAttrs, submenuAttrs }) => {
991
1013
  const out = [];
992
- const selector = roles.map((r) => `[role="${r}"]`).join(',');
1014
+ let found;
1015
+ try {
1016
+ if (query.xpath) {
1017
+ const snap = document.evaluate(query.text, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
1018
+ found = [];
1019
+ for (let i = 0; i < snap.snapshotLength; i += 1) {
1020
+ const node = snap.snapshotItem(i);
1021
+ if (node instanceof Element)
1022
+ found.push(node);
1023
+ }
1024
+ }
1025
+ else {
1026
+ found = Array.from(document.querySelectorAll(query.text));
1027
+ }
1028
+ }
1029
+ catch (e) {
1030
+ return { rows: out, error: String(e?.message ?? e) };
1031
+ }
993
1032
  const counted = new Map();
994
1033
  // A menu's key: what labels it (a submenu is labelled by the row that opens it), else a mark put
995
1034
  // on it here, so a menu with no label is told apart from the others all the same.
996
1035
  // (Written inline: a named function in here is wrapped by the bundler in a helper the page does not have.)
997
1036
  const w = window;
998
- for (const el of Array.from(document.querySelectorAll(selector))) {
1037
+ for (const el of found) {
999
1038
  // A menu that is closed is still in the DOM, so visibility is what separates
1000
1039
  // what is on screen from what was on screen a moment ago.
1001
1040
  if (el.getClientRects().length === 0)
@@ -1032,18 +1071,44 @@ Current URL: ${url}`);
1032
1071
  elId: el.id ?? '',
1033
1072
  });
1034
1073
  }
1035
- return out;
1074
+ return { rows: out, error: '' };
1036
1075
  }, {
1037
- roles: [...Model.optionRoles],
1076
+ query: pageQuery(this.locators.rows),
1038
1077
  selectedAttrs: [...Model.selectedAttributes],
1039
1078
  submenuAttrs: [...Model.submenuAttributes],
1040
1079
  });
1080
+ // Said once: the menu is read many times a choice (whether it is still open, among them).
1081
+ if (read.error && !this.rowsLocatorFailed) {
1082
+ this.rowsLocatorFailed = true;
1083
+ this.emit('model-rows-locator-failed', { locator: this.locators.rows, error: read.error });
1084
+ }
1085
+ return read.rows;
1041
1086
  }
1042
1087
  /** The rows of the top menu, read while only it is open: the menu its first row is in. */
1043
1088
  topRows(rows) {
1044
1089
  const key = rows[0]?.menuOf;
1045
1090
  return key === undefined ? [] : rows.filter((r) => r.menuOf === key);
1046
1091
  }
1092
+ /**
1093
+ * A group's row among the rows read: by its test id; else by the vendor its row names ("OpenAI"), which a choice
1094
+ * does not change; else by its text, as it reads or contains; else by its place.
1095
+ */
1096
+ groupRowIn(shown, group) {
1097
+ const groups = this.topRows(shown).filter((r) => r.opensSubmenu);
1098
+ return ((group.testId ? groups.find((r) => r.testId === group.testId) : undefined) ??
1099
+ (group.vendor ? groups.find((r) => vendorOf(r) && sameModel(vendorOf(r), group.vendor)) : undefined) ??
1100
+ groups.find((r) => sameModel(r.name, group.name)) ??
1101
+ groups.find((r) => containsModel(r.raw, group.name)) ??
1102
+ groups.find((r) => r.index === group.index));
1103
+ }
1104
+ /** A group's row in the open menu, found where the list read it (see `groupRowIn`), as an element to press. */
1105
+ async groupRowAt(group) {
1106
+ const row = this.groupRowIn(await this.readMenuRows().catch(() => []), group);
1107
+ if (!row)
1108
+ return null;
1109
+ const el = this.p.locator(`[data-cop-row="${row.menuOf}#${row.index}"]`).first();
1110
+ return (await el.isVisible().catch(() => false)) ? el : null;
1111
+ }
1047
1112
  /**
1048
1113
  * Opens one group of the open picker and returns the key of its submenu (see `readMenuRows`), or null.
1049
1114
  * The group's row is found by its test id, else by its place among the top rows, else by its text. Its
@@ -1052,19 +1117,13 @@ Current URL: ${url}`);
1052
1117
  */
1053
1118
  async openGroup(group) {
1054
1119
  const shown = await this.readMenuRows();
1055
- const groups = this.topRows(shown).filter((r) => r.opensSubmenu);
1056
- // By its test id; else by the vendor its row names ("OpenAI"), which a choice does not change; else by
1057
- // its text, as it reads or contains; else by its place.
1058
- const row = (group.testId ? groups.find((r) => r.testId === group.testId) : undefined) ??
1059
- (group.vendor ? groups.find((r) => vendorOf(r) && sameModel(vendorOf(r), group.vendor)) : undefined) ??
1060
- groups.find((r) => sameModel(r.name, group.name)) ??
1061
- groups.find((r) => containsModel(r.raw, group.name)) ??
1062
- groups.find((r) => r.index === group.index);
1120
+ const row = this.groupRowIn(shown, group);
1063
1121
  if (!row)
1064
1122
  return null;
1065
1123
  const trigger = this.p.locator(`[data-cop-row="${row.menuOf}#${row.index}"]`).first();
1066
- // Submenus already on screen are not this group's, whatever opened them.
1124
+ // Submenus already on screen are not this group's, whatever opened them; nor is one labelled by another group's row.
1067
1125
  const before = new Set(shown.filter((r) => r.menuOf !== row.menuOf).map((r) => r.menuOf));
1126
+ const others = new Set(this.topRows(shown).filter((r) => r.opensSubmenu && r.elId && r.elId !== row.elId).map((r) => r.elId));
1068
1127
  const opened = async (ms) => {
1069
1128
  const started = Date.now();
1070
1129
  do {
@@ -1073,14 +1132,22 @@ Current URL: ${url}`);
1073
1132
  // appeared, never one that was already there (2026-10-05: Claude's was taken for GPT's).
1074
1133
  if (row.elId && rows.some((r) => r.menuOf === row.elId))
1075
1134
  return row.elId;
1076
- const fresh = rows.find((r) => !before.has(r.menuOf) && r.menuOf !== row.elId);
1135
+ const fresh = rows.find((r) => !before.has(r.menuOf) && r.menuOf !== row.elId && !others.has(r.menuOf));
1077
1136
  if (fresh && (!row.elId || Date.now() - started > 1_500))
1078
1137
  return fresh.menuOf;
1079
1138
  await this.hold(200);
1080
1139
  } while (Date.now() - started < ms);
1081
1140
  return null;
1082
1141
  };
1083
- // Hover is how these open; a click is the fallback for a build that wants one.
1142
+ /*
1143
+ * A click sent to the element itself first, as a choice opens a group (2026-10-06): the mouse goes to coordinates,
1144
+ * and on a menu that moves while it opens, a hover or a click meant for "GPT" opened "Claude" — read so, the list
1145
+ * had no GPT models, and a run had nowhere to look for them (2026-10-24). Then hover, then the mouse.
1146
+ */
1147
+ await trigger.evaluate((el) => el.click(), undefined, { timeout: 3_000 }).catch(() => undefined);
1148
+ const clicked = await opened(4_000);
1149
+ if (clicked)
1150
+ return clicked;
1084
1151
  await trigger.hover({ timeout: 3_000 }).catch(() => undefined);
1085
1152
  const hovered = await opened(4_000);
1086
1153
  if (hovered)
@@ -1100,11 +1167,12 @@ Current URL: ${url}`);
1100
1167
  return children;
1101
1168
  }
1102
1169
  /**
1103
- * The visible row an XPath of `Model` finds for a text, waited for: the one whose own first line is
1104
- * the text when several contain it ("Think deeper" is in "GPT-5.6 Sol Think deeper" too), else the first.
1170
+ * The visible row a locator finds for a text, waited for — an XPath of `Model`, or the operator's (an XPath or a CSS
1171
+ * selector): the one whose own first line is the text when several contain it ("Think deeper" is in "GPT-5.6 Sol
1172
+ * Think deeper" too), else the first.
1105
1173
  */
1106
- async rowByXPath(xpath, text, waitMs) {
1107
- const all = this.p.locator(`xpath=${xpath}`);
1174
+ async rowBy(locator, text, waitMs) {
1175
+ const all = this.p.locator(playwrightSelector(locator));
1108
1176
  const deadline = Date.now() + waitMs;
1109
1177
  do {
1110
1178
  let first = null;
@@ -1137,19 +1205,19 @@ Current URL: ${url}`);
1137
1205
  if (!(await this.waitForPopup()))
1138
1206
  return { problem: 'The model picker did not open.' };
1139
1207
  if (group) {
1140
- const trigger = await this.rowByXPath(`${Model.groupRowXPath(group)} | ${Model.groupRowByAllText(group)}`, group, 4_000);
1208
+ const trigger = await this.rowBy(`${Model.groupRowXPath(group)} | ${Model.groupRowByAllText(group)}`, group, 4_000);
1141
1209
  if (!trigger)
1142
1210
  return { problem: `the picker has no "${group}" group.` };
1143
1211
  // Hover is how these open; a click on it is the fallback.
1144
1212
  await trigger.hover({ timeout: 3_000 }).catch(() => undefined);
1145
- let row = await this.rowByXPath(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1213
+ let row = await this.rowBy(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1146
1214
  if (!row) {
1147
1215
  await this.press(trigger).catch(() => undefined);
1148
- row = await this.rowByXPath(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1216
+ row = await this.rowBy(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1149
1217
  }
1150
1218
  return row ? { row } : { problem: `"${name}" is not in the "${group}" group.` };
1151
1219
  }
1152
- const row = await this.rowByXPath(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1220
+ const row = await this.rowBy(`${Model.modelRowXPath(name)} | ${Model.modelRowByAllText(name)}`, name, 4_000);
1153
1221
  return row ? { row } : { problem: `"${name}" is not in the picker.` };
1154
1222
  }
1155
1223
  /**
@@ -1198,12 +1266,26 @@ Current URL: ${url}`);
1198
1266
  };
1199
1267
  }
1200
1268
  /**
1201
- * Chooses a model by the operator's own locators (`OperatorModelLocators`): the picker button, then the
1202
- * model; for a model in a group, the group first, then — once its models are on screen — the model. The
1203
- * choice counts only when the model's row is marked chosen, read again the same way.
1269
+ * Chooses a model by the operator's own locators (`templateTarget`): the picker button, then the model; for a model
1270
+ * in a provider's menu, the provider first, then — once its models are on screen — the model. The choice counts
1271
+ * only when the model's row is marked chosen, read again the same way.
1272
+ *
1273
+ * A locator that finds nothing at all, after the whole wait of the first attempt, is not tried five times more
1274
+ * (2026-10-24): it is the locator, not the page being slow, and the ways that do not need it are tried at once. A
1275
+ * provider's row its locator does not find is looked for where the list read it (its test id, its vendor, its
1276
+ * place): its row reads the model chosen in it, once one is (2026-10-05), and its name is then not on it.
1204
1277
  */
1205
1278
  async chooseByOperatorLocators(name, target) {
1206
1279
  const before = await this.currentModel();
1280
+ // What was looked for, for the record kept when nothing worked (models-select-failed.json).
1281
+ const tried = [
1282
+ ...(target.group ? [{ what: 'provider', locator: target.group.locator }] : []),
1283
+ { what: target.kind, locator: target.locator },
1284
+ ];
1285
+ const keepFailure = async () => {
1286
+ const found = await Promise.all(tried.map(async (x) => ({ ...x, found: await this.p.locator(playwrightSelector(x.locator)).count().catch((e) => `not usable: ${e.message.split('\n')[0]}`) })));
1287
+ await this.captureMenu('select-failed', await this.readMenuRows().catch(() => []), { asked: name, locators: found }).catch(() => undefined);
1288
+ };
1207
1289
  const textOf = async (el) => (((await el.innerText().catch(() => '')) ?? '').split('\n')[0] ?? '').trim();
1208
1290
  // A fixed pause after every opening and every press (see `ModelPicking`); the checks give it less.
1209
1291
  const settle = () => this.hold(this.opts.modelSettleMs ?? ModelPicking.settleMs);
@@ -1243,6 +1325,18 @@ Current URL: ${url}`);
1243
1325
  return el;
1244
1326
  };
1245
1327
  const visible = async (el) => (el && (await el.isVisible().catch(() => false)) ? el : null);
1328
+ /** The provider's row: by its locator, else where the list read it (see above). */
1329
+ const providerRow = async () => {
1330
+ const g = target.group;
1331
+ const byLocator = await this.rowBy(g.locator, g.name, 0);
1332
+ if (byLocator)
1333
+ return byLocator;
1334
+ const atPlace = await this.groupRowAt(g.at);
1335
+ if (atPlace)
1336
+ this.emit('model-step', { step: 'provider found where the list read it, not by its locator', provider: g.name, locator: g.locator });
1337
+ return atPlace;
1338
+ };
1339
+ /** `missing`: what was looked for first was never there, whatever the wait — the locator finds nothing. */
1246
1340
  const reach = async () => {
1247
1341
  const button = await waitThenFind('the picker button', async () => visible(await this.resolveModelButton(1_000)));
1248
1342
  if (!button)
@@ -1253,9 +1347,11 @@ Current URL: ${url}`);
1253
1347
  return { problem: 'The model picker did not open.' };
1254
1348
  this.emit('model-step', { step: 'picker opened' });
1255
1349
  if (target.group) {
1256
- const group = await waitThenFind(`the "${target.group.name}" group`, () => this.rowByXPath(target.group.xpath, target.group.name, 0));
1257
- if (!group)
1258
- return { problem: `the "${target.group.name}" row was not found by ${target.group.xpath}` };
1350
+ const group = await waitThenFind(`the "${target.group.name}" provider`, providerRow);
1351
+ if (!group) {
1352
+ await keepFailure();
1353
+ return { problem: `the "${target.group.name}" row was not found by the provider's locator (${target.group.locator}), nor where the list read it; the menu is kept as models-select-failed.html/.png`, missing: true };
1354
+ }
1259
1355
  /*
1260
1356
  * Opened without the mouse first: a mouse click goes to coordinates, and the picker moves while it
1261
1357
  * opens, so on the work machine a press meant for "GPT" (now second) opened "Claude" (now first)
@@ -1271,21 +1367,28 @@ Current URL: ${url}`);
1271
1367
  for (const [how, act] of ways) {
1272
1368
  await act().catch(() => undefined);
1273
1369
  await settle();
1274
- const row = await waitThenFind(`"${target.model}"`, () => this.rowByXPath(target.xpath, name, 0));
1370
+ const row = await waitThenFind(`"${target.model}"`, () => this.rowBy(target.locator, name, 0));
1275
1371
  if (row) {
1276
1372
  this.emit('model-step', { step: 'group opened', how, model: await textOf(row) });
1277
1373
  return { row };
1278
1374
  }
1375
+ // Its menu is open and the model's locator finds nothing in it, after the whole wait: the locator's doing.
1376
+ const shownNow = await this.readMenuRows().catch(() => []);
1377
+ if (shownNow.some((r) => r.menuOf !== shownNow[0]?.menuOf)) {
1378
+ this.emit('model-step', { step: "provider's menu open, the model's locator finds nothing in it", how, locator: target.locator });
1379
+ await keepFailure();
1380
+ return { problem: `"${target.model}" was not found in the "${target.group.name}" menu by the locator for a model in a provider's menu (${target.locator}); the menu is kept as models-select-failed.html/.png`, missing: true };
1381
+ }
1279
1382
  this.emit('model-step', { step: 'group not opened', how });
1280
1383
  await this.hold(pause);
1281
1384
  }
1282
- await this.captureMenu('select-failed', await this.readMenuRows().catch(() => [])).catch(() => undefined);
1283
- return { problem: `"${target.model}" did not appear after opening "${target.group.name}" every way (${target.xpath}); the menu is kept as models-select-failed.html/.png` };
1385
+ await keepFailure();
1386
+ return { problem: `"${target.model}" did not appear after opening "${target.group.name}" every way (the locator for a model in a provider's menu: ${target.locator}); the menu is kept as models-select-failed.html/.png` };
1284
1387
  }
1285
- const row = await waitThenFind(`"${target.model}"`, () => this.rowByXPath(target.xpath, name, 0));
1388
+ const row = await waitThenFind(`"${target.model}"`, () => this.rowBy(target.locator, name, 0));
1286
1389
  if (!row) {
1287
- await this.captureMenu('select-failed', await this.readMenuRows().catch(() => [])).catch(() => undefined);
1288
- return { problem: `"${target.model}" was not found by ${target.xpath}; the menu is kept as models-select-failed.html/.png` };
1390
+ await keepFailure();
1391
+ return { problem: `"${target.model}" was not found by the locator for a model of the main menu (${target.locator}); the menu is kept as models-select-failed.html/.png`, missing: true };
1289
1392
  }
1290
1393
  return { row };
1291
1394
  };
@@ -1305,7 +1408,7 @@ Current URL: ${url}`);
1305
1408
  await settle();
1306
1409
  if (!(await this.waitForPopup()))
1307
1410
  return false;
1308
- const group = await waitThenFind(`the "${target.group.name}" group`, () => this.rowByXPath(target.group.xpath, target.group.name, 0));
1411
+ const group = await waitThenFind(`the "${target.group.name}" provider`, providerRow);
1309
1412
  if (!group) {
1310
1413
  await this.closeMenu();
1311
1414
  return false;
@@ -1314,11 +1417,12 @@ Current URL: ${url}`);
1314
1417
  await this.p.keyboard.press('ArrowRight');
1315
1418
  this.emit('model-step', { step: 'group opened by the keyboard (ArrowRight)', attempt });
1316
1419
  await settle();
1317
- const focused = () => this.p.evaluate(() => {
1420
+ // A model's row, which is a menuitemradio or, since 2026-10-23, a menuitem that opens nothing (`Model.modelRowCss`).
1421
+ const focused = () => this.p.evaluate((modelRow) => {
1318
1422
  const el = document.activeElement;
1319
1423
  const row = el?.closest('[role="menuitemradio"],[role="menuitem"]');
1320
- return { text: (row?.innerText ?? '').trim(), radio: !!el?.closest('[role="menuitemradio"]') };
1321
- });
1424
+ return { text: (row?.innerText ?? '').trim(), radio: !!el?.closest(modelRow) };
1425
+ }, Model.modelRowCss);
1322
1426
  for (let presses = 0; presses < 12; presses += 1) {
1323
1427
  const now = await focused();
1324
1428
  const line = now.text.split('\n')[0]?.trim() ?? '';
@@ -1354,6 +1458,11 @@ Current URL: ${url}`);
1354
1458
  this.emit('model-step', { step: 'not reached', attempt, why });
1355
1459
  await this.closeMenu();
1356
1460
  await settle();
1461
+ // The locator finds nothing: the other ways are tried now, not after five more attempts with it.
1462
+ if (found.missing) {
1463
+ this.emit('model-step', { step: 'the locator finds nothing; the other ways now', attempt });
1464
+ return { ok: false, current: await this.currentModel(), reason: why };
1465
+ }
1357
1466
  /*
1358
1467
  * The keyboard only when the clicks did not get there. Tried first on 2026-10-06, the live page did
1359
1468
  * not move the focus into the submenu (2026-10-07: "model not reached by the keyboard", 6.5 s lost),
@@ -1377,7 +1486,7 @@ Current URL: ${url}`);
1377
1486
  }
1378
1487
  // The names in the model's own menu, read before the press closes it: what a shortened button may mean.
1379
1488
  const siblings = await found.row
1380
- .evaluate((el) => Array.from(el.closest('[role="menu"],[role="listbox"]')?.querySelectorAll('[role="menuitemradio"]') ?? []).map((r) => (r.innerText || '').split('\n')[0].trim()))
1489
+ .evaluate((el, modelRow) => Array.from(el.closest('[role="menu"],[role="listbox"]')?.querySelectorAll(modelRow) ?? []).map((r) => (r.innerText || '').split('\n')[0].trim()), Model.modelRowCss)
1381
1490
  .catch(() => []);
1382
1491
  // On the element itself, for the same reason as the group; the mouse only when that does nothing.
1383
1492
  this.emit('model-step', { step: 'model pressed', attempt, text: await textOf(found.row) });
@@ -1557,39 +1666,62 @@ Current URL: ${url}`);
1557
1666
  this.emit('model-already-selected', { model: name, buttonShows: shown, by: 'button' });
1558
1667
  return { ok: true, current: name, by: 'already' };
1559
1668
  }
1560
- // The operator's own locators first, for the models they cover (see `OperatorModelLocators`).
1561
- const target = operatorTargetFor(name);
1669
+ this.sayLocatorProblems();
1670
+ /*
1671
+ * The operator's own locators first (2026-10-24): the templates in force, filled for this model from where the
1672
+ * list read it — the saved list's place, else the place a fresh reading finds — each place tried once.
1673
+ */
1674
+ const tried = new Set();
1675
+ const byTemplates = async (model, place) => {
1676
+ const target = templateTarget(model, place, this.locators);
1677
+ if (!target)
1678
+ return null;
1679
+ const key = `${target.group?.locator ?? ''}|${target.locator}`;
1680
+ if (tried.has(key))
1681
+ return null;
1682
+ tried.add(key);
1683
+ return await this.chooseByOperatorLocators(model, target);
1684
+ };
1562
1685
  let first = null;
1563
- if (target) {
1564
- first = await this.chooseByOperatorLocators(name, target);
1565
- if (first.ok)
1566
- return first;
1567
- }
1568
1686
  if (opts.locator) {
1687
+ first = await byTemplates(name, opts.locator);
1688
+ if (first?.ok)
1689
+ return first;
1569
1690
  const second = await this.chooseAt(name, opts.locator);
1570
1691
  if (second.ok)
1571
1692
  return { ...second, ...(first?.reason ? { locatorMiss: first.reason } : {}) };
1572
1693
  first = first ?? second;
1573
1694
  }
1574
- // The line-up as the page shows it now, each model with its place in it.
1575
- const read = await this.listModels().catch(() => null);
1695
+ // The line-up as the page shows it now, each model with its place in it. A Stop pressed while it is read stops.
1696
+ const read = await this.listModels().catch((e) => {
1697
+ if (e instanceof StoppedByOperator)
1698
+ throw e;
1699
+ return null;
1700
+ });
1576
1701
  const options = read?.options ?? [];
1577
1702
  const match = options.find((o) => sameModel(o.name, name)) ?? pageModelFor(name, options);
1703
+ const which = () => (tried.size > 0 ? "by the operator's locators" : 'at the saved place');
1578
1704
  if (!match?.locator) {
1579
1705
  const offered = options.filter((o) => !o.disabled).map((o) => o.name);
1580
1706
  return {
1581
1707
  ok: false,
1582
1708
  current: await this.currentModel(),
1583
1709
  reason: `The picker does not offer "${name}" any more${offered.length > 0 ? `; it offers ${offered.map((o) => `"${o}"`).join(', ')}` : ''}.` +
1584
- (first?.reason ? ` (${target ? "By the operator's locators" : 'At the place the list was read'}: ${first.reason})` : ''),
1710
+ (first?.reason ? ` (${which().replace(/^./, (c) => c.toUpperCase())}: ${first.reason})` : ''),
1585
1711
  ...(options.length > 0 ? { options } : {}),
1586
1712
  };
1587
1713
  }
1714
+ // Where the list has just read it: its provider and its name as the page shows them now.
1715
+ const fresh = await byTemplates(match.name, match.locator);
1716
+ if (fresh?.ok)
1717
+ return { ...fresh, ...(!sameModel(match.name, name) ? { matched: match.name } : {}), ...(first?.reason ? { locatorMiss: first.reason } : {}), options };
1718
+ if (fresh && !first)
1719
+ first = fresh;
1588
1720
  const chosen = await this.chooseAt(match.name, match.locator);
1589
1721
  return {
1590
1722
  ...chosen,
1591
1723
  // When both ways failed, why the operator's locators did is said too: that is the one to fix.
1592
- ...(!chosen.ok && first?.reason ? { reason: `${chosen.reason ?? 'not chosen'} (${target ? "by the operator's locators" : 'at the saved place'}: ${first.reason})` } : {}),
1724
+ ...(!chosen.ok && first?.reason ? { reason: `${chosen.reason ?? 'not chosen'} (${which()}: ${first.reason})` } : {}),
1593
1725
  ...(chosen.ok && !sameModel(match.name, name) ? { matched: match.name } : {}),
1594
1726
  ...(chosen.ok ? { by: opts.locator ? 'reread' : 'name' } : {}),
1595
1727
  // Why the saved locator missed, kept: what to look at when the page has changed.