copilot-operator 0.1.88 → 0.1.92

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 (47) hide show
  1. package/dist/src/api/operator.controller.js +66 -3
  2. package/dist/src/api/operator.service.js +156 -0
  3. package/dist/src/api/server.js +5 -1
  4. package/dist/src/cli.js +9 -0
  5. package/dist/src/config/live.js +6 -3
  6. package/dist/src/config/schema.js +35 -0
  7. package/dist/src/orchestrator/taskRunner.js +33 -4
  8. package/dist/src/plan/systemGuide.js +373 -0
  9. package/dist/src/session/chatNotice.js +4 -1
  10. package/dist/src/session/events.js +5 -1
  11. package/dist/src/session/locatorFailures.js +56 -0
  12. package/dist/src/transport/chatSteps.js +74 -0
  13. package/dist/src/transport/copilotTransport.js +514 -76
  14. package/dist/src/transport/keptWindow.js +7 -0
  15. package/dist/src/transport/locators.js +174 -5
  16. package/dist/src/transport/pageHtml.js +62 -0
  17. package/dist/web/404.html +2 -2
  18. package/dist/web/_next/static/chunks/{1077.26ca37faa3726fff.js → 1077.922b5f1492f6e0dd.js} +1 -1
  19. package/dist/web/_next/static/chunks/{1548.f5790cd11a91309f.js → 1548.4a09f12e23d369ec.js} +1 -1
  20. package/dist/web/_next/static/chunks/{2163.aa9d9b82fcde6caa.js → 2163.14e7879a45ae9748.js} +1 -1
  21. package/dist/web/_next/static/chunks/{714.b7dbce98ba0b59a8.js → 714.2daeede6dd07ee60.js} +1 -1
  22. package/dist/web/_next/static/chunks/{7220.0ca53eefec5d01ea.js → 7220.260579c8dbfa2c30.js} +1 -1
  23. package/dist/web/_next/static/chunks/7921-1de1f08d23145c0d.js +1 -0
  24. package/dist/web/_next/static/chunks/{8584.9f3b058a8f67d3d7.js → 8584.01e3a7f9f14f0b4f.js} +1 -1
  25. package/dist/web/_next/static/chunks/{9067.107f6164157e0aa1.js → 9067.75d4fdcf47f62fd1.js} +1 -1
  26. package/dist/web/_next/static/chunks/{9747.984a86f70f9cd973.js → 9747.f1bdfbefaba61f8b.js} +1 -1
  27. package/dist/web/_next/static/chunks/app/layout-f5681fae8247797b.js +1 -0
  28. package/dist/web/_next/static/chunks/app/queue/{page-317151444eda8115.js → page-7909ba7c9e3d4c2d.js} +1 -1
  29. package/dist/web/_next/static/chunks/app/settings/page-7d343eecdd9c7500.js +1 -0
  30. package/dist/web/_next/static/chunks/{webpack-c015bbeb103c0856.js → webpack-abd1f09115b96456.js} +1 -1
  31. package/dist/web/_next/static/css/{0c5d6d5914aa3824.css → 6b92f118889ca88b.css} +1 -1
  32. package/dist/web/defaults.html +2 -2
  33. package/dist/web/defaults.txt +8 -8
  34. package/dist/web/index.html +3 -3
  35. package/dist/web/index.txt +9 -9
  36. package/dist/web/queue.html +2 -2
  37. package/dist/web/queue.txt +9 -9
  38. package/dist/web/settings.html +2 -2
  39. package/dist/web/settings.txt +9 -9
  40. package/dist/web/system.html +2 -2
  41. package/dist/web/system.txt +9 -9
  42. package/package.json +3 -2
  43. package/dist/web/_next/static/chunks/7921-8f6503aba840928a.js +0 -1
  44. package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +0 -1
  45. package/dist/web/_next/static/chunks/app/settings/page-95069cb94d79e909.js +0 -1
  46. /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → n7rfXOWgaCFmATod4Q6hp}/_buildManifest.js +0 -0
  47. /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → n7rfXOWgaCFmATod4Q6hp}/_ssgManifest.js +0 -0
@@ -19,13 +19,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
19
19
  * What is here is what the chat and its workbench use, with Settings and Kerrigan (2026-10-20: the sessions, the task
20
20
  * register and the plan from JSON were removed, and their routes with them).
21
21
  */
22
- import { Body, Controller, Get, Inject, Param, Post, Put, Query, Res, NotFoundException, BadRequestException, ConflictException } from '@nestjs/common';
22
+ import { Body, Controller, Delete, Get, Inject, Param, Post, Put, Query, Res, NotFoundException, BadRequestException, ConflictException } from '@nestjs/common';
23
23
  import { OperatorService } from './operator.service.js';
24
24
  import { SettingsUnusableError } from './settings.js';
25
25
  import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
26
26
  import { CHANGED_ON_DISK } from '../session/workspace.js';
27
27
  import { join } from 'node:path';
28
- import { DefaultPickerLocators } from '../transport/locators.js';
28
+ import { DefaultChatLocators, DefaultPickerLocators } from '../transport/locators.js';
29
29
  import { platformTools } from '../exec/platforms.js';
30
30
  import { readOnlyCapable } from '../exec/readOnly.js';
31
31
  function fail(e) {
@@ -101,7 +101,9 @@ let OperatorController = class OperatorController {
101
101
  const programs = { platforms: platformTools(), readOnly: readOnlyCapable(), inForce: resolved.execution.allowedPrograms };
102
102
  // The scripts the bot may run, as in force (2026-10-27): a lock may have emptied the boxes for its own.
103
103
  const scripts = { inForce: resolved.execution.scripts, writtenScripts: resolved.execution.writtenScripts };
104
- return { raw, defaults, resolved: resolved.resolved, picker, programs, scripts };
104
+ // The chat page's own locators (2026-11-17): their defaults, which Settings shows and puts back.
105
+ const chat = { defaults: DefaultChatLocators };
106
+ return { raw, defaults, resolved: resolved.resolved, picker, chat, programs, scripts };
105
107
  }
106
108
  /** Saved, and taken at once by the work going on where it can be (2026-11-03): the answer says what was, and what waits. */
107
109
  async saveSettings(body) {
@@ -177,6 +179,40 @@ let OperatorController = class OperatorController {
177
179
  startFailures(unanswered) {
178
180
  return this.ops.recentStartFailures(unanswered === '1' || unanswered === 'true');
179
181
  }
182
+ /**
183
+ * The chat's locators that found nothing where the bot needed them (2026-11-17): the last time for each, whether it
184
+ * has been changed in Settings since, and the text for a chatbot. Read by the banner on every page and by Settings.
185
+ */
186
+ locatorFailures() {
187
+ return this.ops.listLocatorFailures();
188
+ }
189
+ /**
190
+ * The page's HTML kept with one, to hand to a chatbot. Always a download, never a page of this origin: what the page
191
+ * held is not this program's, however much of it was taken out.
192
+ */
193
+ async locatorFailureHtml(key, res) {
194
+ try {
195
+ const { fileName, content } = await this.ops.locatorFailureHtml(key);
196
+ res.type('application/octet-stream');
197
+ res.setHeader('content-disposition', contentDisposition(fileName));
198
+ res.setHeader('x-content-type-options', 'nosniff');
199
+ res.send(Buffer.from(content, 'utf8'));
200
+ }
201
+ catch (e) {
202
+ failText(res, e);
203
+ }
204
+ }
205
+ /**
206
+ * "Check the locators" (2026-11-17): the Copilot window opened, each of the chat's locators looked for, and what each
207
+ * found. Takes as long as the window takes to open, a sign-in included.
208
+ */
209
+ checkLocators() {
210
+ return this.ops.checkLocators().catch(fail);
211
+ }
212
+ /** Closed by the operator: its banner and its red go. */
213
+ async dismissLocatorFailure(key) {
214
+ return { dismissed: await this.ops.locatorFailures.dismiss(key) };
215
+ }
180
216
  /** One of them as a text file: the error, where it stopped, the run's record, the events and the console. */
181
217
  async startFailureReport(id, res) {
182
218
  try {
@@ -667,6 +703,33 @@ __decorate([
667
703
  __metadata("design:paramtypes", [String]),
668
704
  __metadata("design:returntype", Object)
669
705
  ], OperatorController.prototype, "startFailures", null);
706
+ __decorate([
707
+ Get('locators/failures'),
708
+ __metadata("design:type", Function),
709
+ __metadata("design:paramtypes", []),
710
+ __metadata("design:returntype", Promise)
711
+ ], OperatorController.prototype, "locatorFailures", null);
712
+ __decorate([
713
+ Get('locators/failures/:key/html'),
714
+ __param(0, Param('key')),
715
+ __param(1, Res()),
716
+ __metadata("design:type", Function),
717
+ __metadata("design:paramtypes", [String, Object]),
718
+ __metadata("design:returntype", Promise)
719
+ ], OperatorController.prototype, "locatorFailureHtml", null);
720
+ __decorate([
721
+ Post('locators/check'),
722
+ __metadata("design:type", Function),
723
+ __metadata("design:paramtypes", []),
724
+ __metadata("design:returntype", Promise)
725
+ ], OperatorController.prototype, "checkLocators", null);
726
+ __decorate([
727
+ Delete('locators/failures/:key'),
728
+ __param(0, Param('key')),
729
+ __metadata("design:type", Function),
730
+ __metadata("design:paramtypes", [String]),
731
+ __metadata("design:returntype", Promise)
732
+ ], OperatorController.prototype, "dismissLocatorFailure", null);
670
733
  __decorate([
671
734
  Get('start/failures/:id/report'),
672
735
  __param(0, Param('id')),
@@ -15,6 +15,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
15
15
  import { pageModelFor, sameModel } from '../transport/modelMatch.js';
16
16
  import { Injectable } from '@nestjs/common';
17
17
  import { existsSync } from 'node:fs';
18
+ import { isAbsolute, relative } from 'node:path';
19
+ import { readFile as readFileText } from 'node:fs/promises';
20
+ import { LocatorFailures } from '../session/locatorFailures.js';
21
+ import { CHAT_LOCATOR_KEYS, locatorPrompt, resolveChatLocators } from '../transport/locators.js';
22
+ import { LocatorMissing } from '../transport/copilotTransport.js';
23
+ import { isStepKey, stepKey, stepPrompt } from '../transport/chatSteps.js';
18
24
  import { readFile } from 'node:fs/promises';
19
25
  import { join, resolve } from 'node:path';
20
26
  import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
@@ -150,6 +156,14 @@ function browserRefusal(held, ask) {
150
156
  }
151
157
  if (ask.kind === 'login')
152
158
  return loginWhileBusy;
159
+ // "Check the locators" (2026-11-17) holds the browser for the moment it looks.
160
+ if (held.kind === 'locators') {
161
+ return ask.kind === 'locators'
162
+ ? 'The locators are already being checked.'
163
+ : "the chat's locators are being checked in the browser; start this once that has finished";
164
+ }
165
+ if (ask.kind === 'locators')
166
+ return 'The browser profile is in use right now (a run, or a reading of the models). Check the locators once it has finished.';
153
167
  if (held.kind === 'models') {
154
168
  return ask.kind === 'models'
155
169
  ? 'The model list is already being read.'
@@ -187,6 +201,8 @@ let OperatorService = class OperatorService {
187
201
  layout = installLayout();
188
202
  projectRoot = this.layout.projectRoot;
189
203
  dataDir = this.layout.dataDir;
204
+ /** The chat's locators that found nothing, the last time for each (2026-11-17): the banner's and Settings' red fields. */
205
+ locatorFailures = new LocatorFailures(join(this.layout.dataDir, 'locator-failures.json'));
190
206
  settings = settingsOf(this.layout);
191
207
  store = new SessionStore(this.dataDir, join(this.layout.promptsDir, 'level1.md'));
192
208
  bus = new EventBus();
@@ -208,6 +224,9 @@ let OperatorService = class OperatorService {
208
224
  followsActing = this.bus.subscribe('*', (e) => {
209
225
  if (e.type === 'acting' && e.data)
210
226
  this.acting.set(e.sessionId, e.data);
227
+ // A chat locator that found nothing (2026-11-17): kept for the banner and Settings.
228
+ else if (e.type === 'browser:locator-missing' && e.data)
229
+ this.recordLocatorFailure(e.data);
211
230
  else if (e.type === 'browser:sign-in-required' || e.type === 'browser:verification-required') {
212
231
  // The Copilot window waits for the operator to sign in, or to show a person is there: not counted (2026-10-29).
213
232
  this.holdOf(e.sessionId)?.waitFor(`${e.type}:${e.sessionId}`);
@@ -866,6 +885,73 @@ let OperatorService = class OperatorService {
866
885
  * One of them as a file: what failed and where, the run's record, the sessions' events from the press,
867
886
  * and the console lines from the press to a few seconds after — secret-shaped text taken out.
868
887
  */
888
+ /**
889
+ * A chat locator that found nothing where the bot needed it (the transport's `locator-missing`, operator 2026-11-17:
890
+ * "a mechanism that detects which locator exactly the bot failed on"): kept as the last one for that locator, for the
891
+ * banner on every page and the field in red in Settings.
892
+ */
893
+ recordLocatorFailure(detail) {
894
+ const key = detail.key;
895
+ if (typeof key !== 'string' || !(CHAT_LOCATOR_KEYS.includes(key) || isStepKey(key)) || typeof detail.locator !== 'string')
896
+ return;
897
+ const str = (v) => (typeof v === 'string' && v ? v : undefined);
898
+ const html = str(detail.html);
899
+ const picture = str(detail.picture);
900
+ const url = str(detail.url);
901
+ void this.locatorFailures
902
+ .record({
903
+ key: key,
904
+ ...(str(detail.name) ? { name: str(detail.name) } : {}),
905
+ locator: detail.locator,
906
+ at: new Date().toISOString(),
907
+ why: str(detail.why) ?? '',
908
+ stopped: detail.stopped !== false,
909
+ ...(html ? { html } : {}),
910
+ ...(picture ? { picture } : {}),
911
+ ...(url ? { url } : {}),
912
+ })
913
+ .catch(() => undefined);
914
+ }
915
+ /**
916
+ * The failures kept, each with whether its locator has been changed in Settings since (then it is no longer the one
917
+ * that found nothing, and the banner and the red go), whether its HTML is there to download, and the text for a
918
+ * chatbot. The files' places are not given out: the HTML is downloaded through the API.
919
+ */
920
+ async listLocatorFailures() {
921
+ const cfg = await this.settings.load();
922
+ const inForce = resolveChatLocators(cfg.copilot.chatLocators).locators;
923
+ // A step's (2026-11-17): changed when its locator is, or it is switched off, made not required, or gone.
924
+ const steps = new Map(cfg.copilot.extraSteps.map((s) => [stepKey(s.id), s]));
925
+ return (await this.locatorFailures.list()).map(({ html, picture: _picture, ...f }) => {
926
+ const step = isStepKey(f.key) ? steps.get(f.key) : undefined;
927
+ return {
928
+ ...f,
929
+ ...(step?.name ? { name: step.name } : {}),
930
+ html: !!html && existsSync(html),
931
+ changed: isStepKey(f.key) ? !step || step.off || step.locator !== f.locator || (f.stopped && !step.must) : inForce[f.key] !== f.locator,
932
+ prompt: isStepKey(f.key) ? stepPrompt(step ?? { name: f.name ?? '', action: 'click' }, f.locator) : locatorPrompt(f.key, f.locator),
933
+ };
934
+ });
935
+ }
936
+ /** The page's HTML kept with a failure, to download: only a file in the bot's runs folder. */
937
+ async locatorFailureHtml(key) {
938
+ const f = await this.locatorFailures.get(key);
939
+ if (!f?.html)
940
+ throw new Error(`No HTML is kept for the "${key}" locator.`);
941
+ const cfg = await this.settings.load();
942
+ const runs = resolve(cfg.resolved.runsDir);
943
+ const file = resolve(f.html);
944
+ const inside = relative(runs, file);
945
+ if (!inside || inside.startsWith('..') || isAbsolute(inside)) {
946
+ throw new Error(`The HTML kept for the "${key}" locator is not in the bot's runs folder.`);
947
+ }
948
+ const content = await readFileText(file, 'utf8').catch(() => {
949
+ throw new Error(`The HTML kept for the "${key}" locator is gone (${file}).`);
950
+ });
951
+ const stamp = f.at.replace(/[-:]/g, '').replace('T', '-').slice(0, 15);
952
+ // A step's key holds a colon, which a Windows file name cannot.
953
+ return { fileName: `copilot-page-${key.replace(/[^\w-]/g, '-')}-${stamp}.html`, content };
954
+ }
869
955
  async startFailureReport(id) {
870
956
  await this.init();
871
957
  const f = this.startFailures.get(id);
@@ -3214,6 +3300,14 @@ let OperatorService = class OperatorService {
3214
3300
  await this.init();
3215
3301
  const cfg = await this.settings.load();
3216
3302
  transport = createTransport({
3303
+ // The box to write in by Settings' locator (2026-11-17): the sign-in ends when it shows; one that finds nothing is kept.
3304
+ ...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
3305
+ builtInSteps: cfg.copilot.builtInSteps,
3306
+ extraSteps: cfg.copilot.extraSteps,
3307
+ onEvent: (event, detail) => {
3308
+ if (event === 'locator-missing' && detail)
3309
+ this.recordLocatorFailure(detail);
3310
+ },
3217
3311
  profileDir: cfg.resolved.profileDir,
3218
3312
  transportDir: join(cfg.resolved.runsDir, '_login'),
3219
3313
  chatUrl: cfg.copilot.url,
@@ -3283,6 +3377,10 @@ let OperatorService = class OperatorService {
3283
3377
  keepFailurePage: cfg.copilot.keepFailurePage,
3284
3378
  // The rows' locator reads the names (Settings' own, 2026-10-24).
3285
3379
  ...pickerOptions(cfg),
3380
+ onEvent: (event, detail) => {
3381
+ if (event === 'locator-missing' && detail)
3382
+ this.recordLocatorFailure(detail);
3383
+ },
3286
3384
  });
3287
3385
  await this.closeChatWindow('reading the models needs the browser');
3288
3386
  await transport.open();
@@ -3315,6 +3413,64 @@ let OperatorService = class OperatorService {
3315
3413
  this.releaseBrowser(claim.holder);
3316
3414
  }
3317
3415
  }
3416
+ /**
3417
+ * "Check the locators" (operator, 2026-11-17): the Copilot window opened as for reading the models, each of the chat's
3418
+ * locators looked for (`checkLocators`, which only reads and looks), and the window closed. One that found nothing is
3419
+ * kept as a failure (its field red, its HTML kept); one found whose failure is still kept has it taken away: it works
3420
+ * again. The box itself not found: the chat did not open, said for the box, the others not looked for.
3421
+ */
3422
+ async checkLocators() {
3423
+ const claim = this.claimBrowser({ kind: 'locators' });
3424
+ if ('refused' in claim)
3425
+ throw new Error(claim.refused);
3426
+ let transport = null;
3427
+ try {
3428
+ await this.init();
3429
+ const cfg = await this.settings.load();
3430
+ transport = createTransport({
3431
+ profileDir: cfg.resolved.profileDir,
3432
+ transportDir: join(cfg.resolved.runsDir, '_locators'),
3433
+ chatUrl: cfg.copilot.url,
3434
+ channel: cfg.copilot.channel,
3435
+ headless: cfg.copilot.headless,
3436
+ replyTimeoutMs: cfg.copilot.replyTimeoutSec * 1000,
3437
+ signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
3438
+ humanWaitMs: cfg.copilot.humanWaitSec * 1000,
3439
+ keepFailurePage: cfg.copilot.keepFailurePage,
3440
+ ...pickerOptions(cfg),
3441
+ onEvent: (event, detail) => {
3442
+ if (event === 'locator-missing' && detail)
3443
+ this.recordLocatorFailure(detail);
3444
+ },
3445
+ });
3446
+ await this.closeChatWindow('checking the locators needs the browser');
3447
+ await transport.open();
3448
+ let results;
3449
+ try {
3450
+ // A step of the operator's own that is not there stops the opening, as at work; it is said, and the check goes on.
3451
+ await transport.ensureSignedIn().catch((e) => {
3452
+ if (!(e instanceof LocatorMissing) || !isStepKey(e.key))
3453
+ throw e;
3454
+ });
3455
+ results = await transport.checkLocators();
3456
+ }
3457
+ catch (e) {
3458
+ if (!(e instanceof LocatorMissing) || e.key !== 'composer')
3459
+ throw e;
3460
+ results = CHAT_LOCATOR_KEYS.map((key) => (key === 'composer' ? { key, status: 'none', count: 0 } : { key, status: 'not-here', count: 0, note: 'noChat' }));
3461
+ }
3462
+ // Found now: no longer a failure, whatever was kept.
3463
+ const kept = await this.locatorFailures.list();
3464
+ for (const r of results)
3465
+ if (r.status === 'found' && kept.some((f) => f.key === r.key))
3466
+ await this.locatorFailures.dismiss(r.key);
3467
+ return { checkedAt: new Date().toISOString(), results };
3468
+ }
3469
+ finally {
3470
+ await transport?.close().catch(() => undefined);
3471
+ this.releaseBrowser(claim.holder);
3472
+ }
3473
+ }
3318
3474
  // --- the registry ---------------------------------------------------------------------
3319
3475
  // --- environment ----------------------------------------------------------------------
3320
3476
  /** Opens the machine's own folder dialog and reports what was picked. */
@@ -149,7 +149,11 @@ export async function startApi(opts = {}) {
149
149
  await app.close();
150
150
  throw e;
151
151
  });
152
- await app.listen(PORT, '127.0.0.1');
152
+ // A port that cannot be taken (in use, or reserved by Windows: EACCES) closes what was opened, so a caller can try another.
153
+ await app.listen(PORT, '127.0.0.1').catch(async (e) => {
154
+ await app.close().catch(() => undefined);
155
+ throw e;
156
+ });
153
157
  // Close whatever the previous process left open before anyone can look at it, rather than
154
158
  // waiting for the first request to trigger it.
155
159
  await ops.bootstrap();
package/dist/src/cli.js CHANGED
@@ -126,7 +126,11 @@ program
126
126
  console.log('No existing profile to delete.');
127
127
  }
128
128
  }
129
+ // The box to write in by Settings' locator (2026-11-17): the sign-in ends when it shows.
130
+ const saved = await settingsOf(installLayout()).load().catch(() => null);
129
131
  const transport = new CopilotTransport({
132
+ ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
133
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
130
134
  profileDir: opts.profile,
131
135
  transportDir: join(opts.profile, '_transport'),
132
136
  chatUrl: opts.url,
@@ -187,7 +191,10 @@ program
187
191
  .option('-p, --profile <dir>', 'profile directory', DEFAULT_PROFILE)
188
192
  .option('--url <url>', 'chat url', Url.chat)
189
193
  .action(async (opts) => {
194
+ const saved = await settingsOf(installLayout()).load().catch(() => null);
190
195
  const transport = new CopilotTransport({
196
+ ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
197
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
191
198
  profileDir: opts.profile,
192
199
  transportDir: join(opts.profile, '_transport'),
193
200
  chatUrl: opts.url,
@@ -392,6 +399,8 @@ program
392
399
  const saved = await settingsOf(installLayout()).load().catch(() => null);
393
400
  const transport = new CopilotTransport({
394
401
  ...(saved?.copilot.pickerLocators ? { pickerLocators: saved.copilot.pickerLocators } : {}),
402
+ ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
403
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
395
404
  profileDir: opts.profile,
396
405
  transportDir: join(installLayout().runsDir, '_models'),
397
406
  chatUrl: opts.url,
@@ -12,8 +12,9 @@
12
12
  * - from the next message (`next`): what a message is built on when it starts — the models, plan mode, the shell and
13
13
  * folder a step runs in by default, the project and its folders, the skills, the contract's stop word, the mode a
14
14
  * start takes, and the lead's number of subtasks, which its assignment states;
15
- * - when the chat window opens again (`window`): the chat's address, its browser and the waits and locators the
16
- * window was opened with; it is kept open between messages.
15
+ * - when the chat window opens again (`window`): the chat's address, its browser and the waits the window was opened
16
+ * with; it is kept open between messages. Its locators and the steps on the way to the chat are taken at once
17
+ * (2026-11-17): the window open is handed them (`takeSettings`).
17
18
  *
18
19
  * A step that is running, and a card already put to the operator, go on as they began. The locked policy, when there is
19
20
  * one, is in what was saved (`loadConfigObject`), so it is taken with the rest and still wins.
@@ -29,6 +30,8 @@ const NOW = {
29
30
  limits: '*',
30
31
  pacing: '*',
31
32
  report: '*',
33
+ // The locators and the steps on the way to the chat (2026-11-17): handed to the window open, at once (`takeSettings`).
34
+ copilot: ['pickerLocators', 'chatLocators', 'pickerSteps', 'builtInSteps', 'extraSteps'],
32
35
  };
33
36
  /** Of a section taken whole, what a message is told when it starts: the lead's number of subtasks is its assignment's. */
34
37
  const NOT_NOW = {
@@ -36,7 +39,7 @@ const NOT_NOW = {
36
39
  };
37
40
  /** What the chat window was opened with. */
38
41
  const WINDOW = {
39
- copilot: ['url', 'profileDir', 'channel', 'headless', 'replyTimeoutSec', 'signInTimeoutSec', 'humanWaitSec', 'keepFailurePage', 'pickerLocators', 'pickerSteps'],
42
+ copilot: ['url', 'profileDir', 'channel', 'headless', 'replyTimeoutSec', 'signInTimeoutSec', 'humanWaitSec', 'keepFailurePage'],
40
43
  };
41
44
  /** The sections a run compares; the rest (where the bot keeps its records) is read when the bot starts. */
42
45
  const SECTIONS = ['copilot', 'task', 'execution', 'report', 'project', 'skills', 'pacing', 'limits'];
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { z } from 'zod';
9
9
  import { SCRIPT_KINDS } from '../exec/scriptKinds.js';
10
+ import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
10
11
  import { parse as parseYaml } from 'yaml';
11
12
  import { readHandWritten } from './handWritten.js';
12
13
  import { applyPolicyLock, readPolicyLocks } from './lockedPolicy.js';
@@ -169,12 +170,46 @@ export const RunConfigSchema = z.object({
169
170
  providerModel: z.string().optional(),
170
171
  })
171
172
  .optional(),
173
+ /**
174
+ * The chat page's locators (operator, 2026-11-17: "a field in Settings to set it by hand", after the work page's
175
+ * box to write in changed and the start was refused as "not the Microsoft 365 Copilot chat"; then "each of the
176
+ * locators"): every one the bot finds the chat by. Left out, or empty, the default in `transport/locators.ts`
177
+ * (`DefaultChatLocators`); one that cannot be used is not, and the run says why. Taken by the next Copilot window.
178
+ * Made from the keys themselves: written out by hand, it kept only the box's, and a locator saved for Send was
179
+ * dropped when the settings were read.
180
+ */
181
+ chatLocators: z
182
+ .object(Object.fromEntries(CHAT_LOCATOR_KEYS.map((k) => [k, z.string().optional()])))
183
+ .optional(),
172
184
  /**
173
185
  * A picture and the menu's HTML at every step of choosing a model, with what each locator found (operator,
174
186
  * 2026-10-24: "an option in Settings to keep this information"), beside the run's other browser files. Off: only
175
187
  * a failed choice keeps the menu (models-select-failed.*).
176
188
  */
177
189
  pickerSteps: z.boolean().default(false),
190
+ /**
191
+ * The steps on the way to the chat (operator, 2026-11-17: "what happens if we want to add or remove a step?"),
192
+ * see `transport/chatSteps.ts`: the bot's own that can be done without, each on unless switched off; and the
193
+ * operator's own, in their order, each "if this is on the page, do this" when the chat opens or before each message.
194
+ * Taken at once by the window open (`config/live.ts`).
195
+ */
196
+ builtInSteps: z
197
+ .object({ popups: z.boolean().default(true), feedbackPanel: z.boolean().default(true), nameChat: z.boolean().default(true) })
198
+ .prefault({}),
199
+ extraSteps: z
200
+ .array(z.object({
201
+ id: z.string().regex(/^[\w-]{1,40}$/),
202
+ name: z.string().max(200).default(''),
203
+ when: z.enum(['open', 'message']).default('message'),
204
+ locator: z.string().max(4000).default(''),
205
+ action: z.enum(['click', 'press', 'appear', 'gone']).default('click'),
206
+ key: z.string().max(60).optional(),
207
+ must: z.boolean().default(false),
208
+ waitSec: z.number().min(0).max(600).default(2),
209
+ off: z.boolean().default(false),
210
+ }))
211
+ .max(100)
212
+ .default([]),
178
213
  })
179
214
  .prefault({}),
180
215
  /** Level 1: the base prompt about how the runner works. Shipped with the project; editable in the UI. */
@@ -45,7 +45,7 @@ import { scriptsNote } from '../exec/scriptKinds.js';
45
45
  import { collectPolicyManifest, describePolicyManifest } from '../exec/policyManifest.js';
46
46
  import { assessIsolation, readIsolationSignals } from '../exec/isolation.js';
47
47
  import { confinementRefusal, isWithin, sessionRoots } from '../exec/confinement.js';
48
- import { writeReport } from '../exec/reportFile.js';
48
+ import { stripAnsi, writeReport } from '../exec/reportFile.js';
49
49
  import { gapFrom, Pacer } from '../util/pacing.js';
50
50
  import { RunLog } from '../log/runLog.js';
51
51
  import { composeOpening, operatorNotesSection, readOnlyNote } from '../session/compose.js';
@@ -456,9 +456,23 @@ export function speakFor(transport, sessionId, opts = {}) {
456
456
  if (opts.alone)
457
457
  speaker.alone = true;
458
458
  }
459
+ /** The settings a window open takes at once (`takeSettings`): its locators and the steps on the way to the chat. */
460
+ const WINDOW_NOW = new Set(['copilot.pickerLocators', 'copilot.chatLocators', 'copilot.pickerSteps', 'copilot.builtInSteps', 'copilot.extraSteps']);
459
461
  /** The model menu's locators and its step pictures, as Settings have them (2026-10-24), for every window that picks a model. */
462
+ /** The locators Settings hold for the Copilot window: the model menu's, and the chat page's own (the box to write in, 2026-11-17). */
460
463
  export function pickerOptions(cfg) {
461
- return { ...(cfg.copilot.pickerLocators ? { pickerLocators: cfg.copilot.pickerLocators } : {}), ...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}) };
464
+ // The steps on the way to the chat (2026-11-17): only what differs from the defaults, as the locators. Left out, a
465
+ // window takes the defaults (`takeSettings` too: a step deleted or switched back on goes with the next one).
466
+ const builtIn = cfg.copilot.builtInSteps;
467
+ const switchedOff = !!builtIn && Object.values(builtIn).some((on) => on === false);
468
+ const own = cfg.copilot.extraSteps ?? [];
469
+ return {
470
+ ...(cfg.copilot.pickerLocators ? { pickerLocators: cfg.copilot.pickerLocators } : {}),
471
+ ...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
472
+ ...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}),
473
+ ...(switchedOff ? { builtInSteps: builtIn } : {}),
474
+ ...(own.length > 0 ? { extraSteps: own } : {}),
475
+ };
462
476
  }
463
477
  export async function openBrowser(cfg, bus, transportDir, sessionId,
464
478
  /** The run's Stop: a sign-in still awaited ends with it. */
@@ -496,6 +510,14 @@ signal) {
496
510
  'chat-left': `The Copilot window is no longer on this conversation (it shows ${String(detail?.found ?? 'another page')}). Going back to it before anything is sent.`,
497
511
  'chat-returned': `Back on this conversation${detail?.signedIn ? ', after the sign-in' : ''}${detail?.by === 'name' ? ', found by its name in the sidebar' : ''}. The work goes on there.`,
498
512
  'chat-lost': 'The conversation could not be opened again, by its address or by its name. Nothing was sent, and nothing went into another chat.',
513
+ // A locator of the chat that found nothing (2026-11-17): which, and where Settings has it; the API keeps it for the red field.
514
+ 'locator-missing': String(detail?.key ?? '').startsWith('step:')
515
+ ? `Your step "${String(detail?.name || detail?.locator || '')}" (${String(detail?.locator ?? '')}) ${String(detail?.why ?? '')}. ${detail?.stopped === false ? 'The work goes on without it. ' : ''}Settings → "Steps to the chat" shows it in red, with the page's HTML for a chatbot to find the right one in.`
516
+ : `Not found on Copilot's page: the "${String(detail?.key ?? '')}" locator (${String(detail?.locator ?? '')}) found nothing ${String(detail?.why ?? '')}. ${detail?.stopped === false ? 'The work goes on without it. ' : ''}Settings → "The chat's locators" shows it in red, with the page's HTML for a chatbot to find the right one in.`,
517
+ // The steps on the way to the chat (2026-11-17).
518
+ 'chat-step-not-used': `A step of yours in Settings is not taken: ${String(detail?.problem ?? '')}`,
519
+ 'chat-name-off': "The conversation is not named in Copilot's sidebar: that step is switched off in Settings → \"Steps to the chat\".",
520
+ 'chat-step': `Your step "${String(detail?.name ?? '')}": ${String(detail?.did ?? '')}`,
499
521
  // Copilot showed another of its pages, its home page, instead of the chat (2026-11-17): the chat opened from it.
500
522
  'chat-page-elsewhere': `Copilot showed its page ${String(detail?.found ?? '')} instead of the chat; opening the chat ${detail?.by === 'link' ? "by the page's own link to it" : `at ${String(detail?.to ?? '')}`}.`,
501
523
  };
@@ -503,7 +525,7 @@ signal) {
503
525
  bus.publish({
504
526
  sessionId: id,
505
527
  type: `browser:${event}`,
506
- level: event === 'chat-lost' ? 'error' : ['verification-required', 'reply-files-ignored', 'model-menu-stuck', 'chat-left', 'window-closed', 'window-not-reopened', 'reply-asked-again', 'message-sent-again'].includes(event) ? 'warn' : 'info',
528
+ level: event === 'chat-lost' || (event === 'locator-missing' && detail?.stopped !== false) ? 'error' : event === 'locator-missing' ? 'warn' : ['verification-required', 'reply-files-ignored', 'model-menu-stuck', 'chat-left', 'window-closed', 'window-not-reopened', 'reply-asked-again', 'message-sent-again'].includes(event) ? 'warn' : 'info',
507
529
  // An event with no sentence of its own is named, not said as "undefined".
508
530
  message: spoken[event] ?? event.replace(/-/g, ' '),
509
531
  data: detail,
@@ -1290,7 +1312,9 @@ export async function runTask(transport, session, task, deps) {
1290
1312
  const photographed = session.kind === 'chat' && !session.vcs?.enabled;
1291
1313
  let chatCheckpoint = photographed ? task.checkpoint : undefined;
1292
1314
  const chatDir = photographed ? session.projectDir?.trim() ?? '' : '';
1293
- const finish = async (status, reason, summary, finalReply) => {
1315
+ const finish = async (status, reasonAsIs, summary, finalReply) => {
1316
+ // An error's text as a terminal would colour it (Playwright's: [2m … [22m) is said without the colours.
1317
+ let reason = reasonAsIs === undefined ? undefined : stripAnsi(reasonAsIs);
1294
1318
  // How it ended as reported; the runner's own checks below can still change it, and the final word is written at the end.
1295
1319
  await record(`ENDING: ${status.toUpperCase()}`, [summary ?? '', reason ? `Reason: ${reason}` : ''].filter(Boolean).join('\n\n') || '(no details)');
1296
1320
  // The net under the plan's own checks: whatever the task left running is stopped and named.
@@ -1706,6 +1730,9 @@ export async function runTask(transport, session, task, deps) {
1706
1730
  */
1707
1731
  let policyRevision = 1;
1708
1732
  const tookSettings = async (change) => {
1733
+ // The locators and the steps on the way to the chat, fixed in Settings: the window open looks by them from now on.
1734
+ if (change.now.some((name) => WINDOW_NOW.has(name)))
1735
+ transport.takeSettings(pickerOptions(cfg));
1709
1736
  pacer.retune({ enabled: cfg.pacing.enabled, settleMs: cfg.pacing.settleMs, maxMessagesPerHour: cfg.pacing.maxMessagesPerHour, gapMs: gapFrom(cfg.pacing) });
1710
1737
  const later = [...change.next, ...change.window];
1711
1738
  sink.event('settings-changed', change, `Settings saved while this message runs: ${change.now.join(', ')} in force from now${later.length ? `; ${later.join(', ')} from the next message, or the next time the chat window opens` : ''}`);
@@ -3646,6 +3673,8 @@ export async function runSession(sessionId, deps) {
3646
3673
  if (borrowed) {
3647
3674
  speakFor(borrowed, session.id, { alone: !!deps.chatWindow });
3648
3675
  bus.publish({ sessionId, type: 'browser-reused', level: 'info', message: deps.chatWindow ? 'using the browser window the last message left open' : 'using the browser window that is already open' });
3676
+ // The window the last message left open, told what Settings say now: a locator fixed there since is looked by.
3677
+ borrowed.takeSettings(pickerOptions(cfg));
3649
3678
  if (deps.chatWindow) {
3650
3679
  await borrowed.clearNotice().catch(() => undefined);
3651
3680
  await borrowed.ensureSignedIn(undefined, { signal: deps.signal });