copilot-operator 0.1.90 → 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 (42) hide show
  1. package/dist/src/api/operator.service.js +24 -9
  2. package/dist/src/cli.js +3 -0
  3. package/dist/src/config/live.js +6 -3
  4. package/dist/src/config/schema.js +23 -0
  5. package/dist/src/orchestrator/taskRunner.js +25 -3
  6. package/dist/src/plan/systemGuide.js +215 -0
  7. package/dist/src/session/chatNotice.js +4 -1
  8. package/dist/src/session/events.js +5 -1
  9. package/dist/src/session/locatorFailures.js +2 -1
  10. package/dist/src/transport/chatSteps.js +74 -0
  11. package/dist/src/transport/copilotTransport.js +223 -30
  12. package/dist/src/transport/keptWindow.js +4 -0
  13. package/dist/src/transport/locators.js +53 -5
  14. package/dist/web/404.html +2 -2
  15. package/dist/web/_next/static/chunks/{1077.1cc6d439e3dd0fa9.js → 1077.922b5f1492f6e0dd.js} +1 -1
  16. package/dist/web/_next/static/chunks/{1548.3de9dc874e47558e.js → 1548.4a09f12e23d369ec.js} +1 -1
  17. package/dist/web/_next/static/chunks/{2163.66458fb9c54fb52d.js → 2163.14e7879a45ae9748.js} +1 -1
  18. package/dist/web/_next/static/chunks/{714.cffed2b87154be0f.js → 714.2daeede6dd07ee60.js} +1 -1
  19. package/dist/web/_next/static/chunks/{7220.30b6a3e1bd41e51a.js → 7220.260579c8dbfa2c30.js} +1 -1
  20. package/dist/web/_next/static/chunks/{7921-d3a4a261e08950e0.js → 7921-1de1f08d23145c0d.js} +1 -1
  21. package/dist/web/_next/static/chunks/{8584.36422ed19d6c43e9.js → 8584.01e3a7f9f14f0b4f.js} +1 -1
  22. package/dist/web/_next/static/chunks/{9067.e579f97591576de2.js → 9067.75d4fdcf47f62fd1.js} +1 -1
  23. package/dist/web/_next/static/chunks/{9747.11247f0e21542f6d.js → 9747.f1bdfbefaba61f8b.js} +1 -1
  24. package/dist/web/_next/static/chunks/app/layout-f5681fae8247797b.js +1 -0
  25. package/dist/web/_next/static/chunks/app/settings/page-7d343eecdd9c7500.js +1 -0
  26. package/dist/web/_next/static/chunks/{webpack-78ec62098b09e4a0.js → webpack-abd1f09115b96456.js} +1 -1
  27. package/dist/web/_next/static/css/{d74aa18c98dacdb4.css → 6b92f118889ca88b.css} +1 -1
  28. package/dist/web/defaults.html +2 -2
  29. package/dist/web/defaults.txt +8 -8
  30. package/dist/web/index.html +3 -3
  31. package/dist/web/index.txt +9 -9
  32. package/dist/web/queue.html +2 -2
  33. package/dist/web/queue.txt +9 -9
  34. package/dist/web/settings.html +2 -2
  35. package/dist/web/settings.txt +9 -9
  36. package/dist/web/system.html +2 -2
  37. package/dist/web/system.txt +9 -9
  38. package/package.json +1 -1
  39. package/dist/web/_next/static/chunks/app/layout-7b5fa7c74ecd6939.js +0 -1
  40. package/dist/web/_next/static/chunks/app/settings/page-7651920337bbb580.js +0 -1
  41. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → n7rfXOWgaCFmATod4Q6hp}/_buildManifest.js +0 -0
  42. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → n7rfXOWgaCFmATod4Q6hp}/_ssgManifest.js +0 -0
@@ -20,6 +20,7 @@ import { readFile as readFileText } from 'node:fs/promises';
20
20
  import { LocatorFailures } from '../session/locatorFailures.js';
21
21
  import { CHAT_LOCATOR_KEYS, locatorPrompt, resolveChatLocators } from '../transport/locators.js';
22
22
  import { LocatorMissing } from '../transport/copilotTransport.js';
23
+ import { isStepKey, stepKey, stepPrompt } from '../transport/chatSteps.js';
23
24
  import { readFile } from 'node:fs/promises';
24
25
  import { join, resolve } from 'node:path';
25
26
  import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
@@ -891,7 +892,7 @@ let OperatorService = class OperatorService {
891
892
  */
892
893
  recordLocatorFailure(detail) {
893
894
  const key = detail.key;
894
- if (typeof key !== 'string' || !CHAT_LOCATOR_KEYS.includes(key) || typeof detail.locator !== 'string')
895
+ if (typeof key !== 'string' || !(CHAT_LOCATOR_KEYS.includes(key) || isStepKey(key)) || typeof detail.locator !== 'string')
895
896
  return;
896
897
  const str = (v) => (typeof v === 'string' && v ? v : undefined);
897
898
  const html = str(detail.html);
@@ -900,6 +901,7 @@ let OperatorService = class OperatorService {
900
901
  void this.locatorFailures
901
902
  .record({
902
903
  key: key,
904
+ ...(str(detail.name) ? { name: str(detail.name) } : {}),
903
905
  locator: detail.locator,
904
906
  at: new Date().toISOString(),
905
907
  why: str(detail.why) ?? '',
@@ -918,12 +920,18 @@ let OperatorService = class OperatorService {
918
920
  async listLocatorFailures() {
919
921
  const cfg = await this.settings.load();
920
922
  const inForce = resolveChatLocators(cfg.copilot.chatLocators).locators;
921
- return (await this.locatorFailures.list()).map(({ html, picture: _picture, ...f }) => ({
922
- ...f,
923
- html: !!html && existsSync(html),
924
- changed: inForce[f.key] !== f.locator,
925
- prompt: locatorPrompt(f.key, f.locator),
926
- }));
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
+ });
927
935
  }
928
936
  /** The page's HTML kept with a failure, to download: only a file in the bot's runs folder. */
929
937
  async locatorFailureHtml(key) {
@@ -941,7 +949,8 @@ let OperatorService = class OperatorService {
941
949
  throw new Error(`The HTML kept for the "${key}" locator is gone (${file}).`);
942
950
  });
943
951
  const stamp = f.at.replace(/[-:]/g, '').replace('T', '-').slice(0, 15);
944
- return { fileName: `copilot-page-${key}-${stamp}.html`, content };
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 };
945
954
  }
946
955
  async startFailureReport(id) {
947
956
  await this.init();
@@ -3293,6 +3302,8 @@ let OperatorService = class OperatorService {
3293
3302
  transport = createTransport({
3294
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.
3295
3304
  ...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
3305
+ builtInSteps: cfg.copilot.builtInSteps,
3306
+ extraSteps: cfg.copilot.extraSteps,
3296
3307
  onEvent: (event, detail) => {
3297
3308
  if (event === 'locator-missing' && detail)
3298
3309
  this.recordLocatorFailure(detail);
@@ -3436,7 +3447,11 @@ let OperatorService = class OperatorService {
3436
3447
  await transport.open();
3437
3448
  let results;
3438
3449
  try {
3439
- await transport.ensureSignedIn();
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
+ });
3440
3455
  results = await transport.checkLocators();
3441
3456
  }
3442
3457
  catch (e) {
package/dist/src/cli.js CHANGED
@@ -130,6 +130,7 @@ program
130
130
  const saved = await settingsOf(installLayout()).load().catch(() => null);
131
131
  const transport = new CopilotTransport({
132
132
  ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
133
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
133
134
  profileDir: opts.profile,
134
135
  transportDir: join(opts.profile, '_transport'),
135
136
  chatUrl: opts.url,
@@ -193,6 +194,7 @@ program
193
194
  const saved = await settingsOf(installLayout()).load().catch(() => null);
194
195
  const transport = new CopilotTransport({
195
196
  ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
197
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
196
198
  profileDir: opts.profile,
197
199
  transportDir: join(opts.profile, '_transport'),
198
200
  chatUrl: opts.url,
@@ -398,6 +400,7 @@ program
398
400
  const transport = new CopilotTransport({
399
401
  ...(saved?.copilot.pickerLocators ? { pickerLocators: saved.copilot.pickerLocators } : {}),
400
402
  ...(saved?.copilot.chatLocators ? { chatLocators: saved.copilot.chatLocators } : {}),
403
+ ...(saved ? { builtInSteps: saved.copilot.builtInSteps, extraSteps: saved.copilot.extraSteps } : {}),
401
404
  profileDir: opts.profile,
402
405
  transportDir: join(installLayout().runsDir, '_models'),
403
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', 'chatLocators', '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'];
@@ -187,6 +187,29 @@ export const RunConfigSchema = z.object({
187
187
  * a failed choice keeps the menu (models-select-failed.*).
188
188
  */
189
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([]),
190
213
  })
191
214
  .prefault({}),
192
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,13 +456,22 @@ 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. */
460
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). */
461
463
  export function pickerOptions(cfg) {
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 ?? [];
462
469
  return {
463
470
  ...(cfg.copilot.pickerLocators ? { pickerLocators: cfg.copilot.pickerLocators } : {}),
464
471
  ...(cfg.copilot.chatLocators ? { chatLocators: cfg.copilot.chatLocators } : {}),
465
472
  ...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}),
473
+ ...(switchedOff ? { builtInSteps: builtIn } : {}),
474
+ ...(own.length > 0 ? { extraSteps: own } : {}),
466
475
  };
467
476
  }
468
477
  export async function openBrowser(cfg, bus, transportDir, sessionId,
@@ -502,7 +511,13 @@ signal) {
502
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.`,
503
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.',
504
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.
505
- 'locator-missing': `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.`,
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 ?? '')}`,
506
521
  // Copilot showed another of its pages, its home page, instead of the chat (2026-11-17): the chat opened from it.
507
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 ?? '')}`}.`,
508
523
  };
@@ -1297,7 +1312,9 @@ export async function runTask(transport, session, task, deps) {
1297
1312
  const photographed = session.kind === 'chat' && !session.vcs?.enabled;
1298
1313
  let chatCheckpoint = photographed ? task.checkpoint : undefined;
1299
1314
  const chatDir = photographed ? session.projectDir?.trim() ?? '' : '';
1300
- 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);
1301
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.
1302
1319
  await record(`ENDING: ${status.toUpperCase()}`, [summary ?? '', reason ? `Reason: ${reason}` : ''].filter(Boolean).join('\n\n') || '(no details)');
1303
1320
  // The net under the plan's own checks: whatever the task left running is stopped and named.
@@ -1713,6 +1730,9 @@ export async function runTask(transport, session, task, deps) {
1713
1730
  */
1714
1731
  let policyRevision = 1;
1715
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));
1716
1736
  pacer.retune({ enabled: cfg.pacing.enabled, settleMs: cfg.pacing.settleMs, maxMessagesPerHour: cfg.pacing.maxMessagesPerHour, gapMs: gapFrom(cfg.pacing) });
1717
1737
  const later = [...change.next, ...change.window];
1718
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` : ''}`);
@@ -3653,6 +3673,8 @@ export async function runSession(sessionId, deps) {
3653
3673
  if (borrowed) {
3654
3674
  speakFor(borrowed, session.id, { alone: !!deps.chatWindow });
3655
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));
3656
3678
  if (deps.chatWindow) {
3657
3679
  await borrowed.clearNotice().catch(() => undefined);
3658
3680
  await borrowed.ensureSignedIn(undefined, { signal: deps.signal });
@@ -2586,6 +2586,30 @@ export const SYSTEM_GUIDE = [
2586
2586
  doesEn: 'How the bot finds the messages it sent in the conversation, to know one arrived; empty is the default, [id^="user-message-"].',
2587
2587
  doesBg: 'Как ботът намира изпратените от него съобщения в разговора, за да разбере, че са пристигнали; празно е стойността по подразбиране, [id^="user-message-"].',
2588
2588
  },
2589
+ {
2590
+ key: 'chatloc.uploadInput',
2591
+ kind: 'field',
2592
+ en: 'The box\'s file input',
2593
+ bg: 'Полето за файл на кутията',
2594
+ doesEn: 'How the bot finds the hidden file input of the box, through which it attaches a file (a message too long for text goes as one); empty is the default.',
2595
+ doesBg: 'Как ботът намира скритото поле за файл на кутията, през което прикачва файл (твърде дълго съобщение отива като файл); празно е стойността по подразбиране.',
2596
+ },
2597
+ {
2598
+ key: 'chatloc.attachment',
2599
+ kind: 'field',
2600
+ en: 'The attached file in the box',
2601
+ bg: 'Прикаченият файл в кутията',
2602
+ doesEn: 'How the bot sees that the file is attached; {$file_name} is where the file\'s name goes, {$file_stem} the name without its extension; empty is the default, which finds the old and the new look.',
2603
+ doesBg: 'Как ботът вижда, че файлът е прикачен; {$file_name} е мястото на името на файла, {$file_stem} е името без разширението; празно е стойността по подразбиране, която намира стария и новия вид.',
2604
+ },
2605
+ {
2606
+ key: 'chatloc.attachmentUploaded',
2607
+ kind: 'field',
2608
+ en: 'The attached file, uploaded',
2609
+ bg: 'Прикаченият файл, качен',
2610
+ doesEn: 'How the bot sees that the attached file has finished uploading, before it sends; empty is the default.',
2611
+ doesBg: 'Как ботът вижда, че прикаченият файл е качен докрай, преди да изпрати; празно е стойността по подразбиране.',
2612
+ },
2589
2613
  {
2590
2614
  key: 'chatloc.turn',
2591
2615
  kind: 'field',
@@ -2660,6 +2684,197 @@ export const SYSTEM_GUIDE = [
2660
2684
  },
2661
2685
  ],
2662
2686
  },
2687
+ {
2688
+ headingKey: 'steps.title',
2689
+ en: 'Steps to the chat',
2690
+ bg: 'Стъпки до чата',
2691
+ controls: [
2692
+ {
2693
+ key: 'steps.builtInTitle',
2694
+ kind: 'note',
2695
+ en: 'The bot\'s own steps',
2696
+ bg: 'Стъпките на бота',
2697
+ doesEn: 'The bot\'s own steps on Copilot\'s page that can be done without, each with a tick box.',
2698
+ doesBg: 'Собствените стъпки на бота в страницата на Copilot, без които може, всяка с отметка.',
2699
+ },
2700
+ {
2701
+ key: 'steps.popups',
2702
+ kind: 'checkbox',
2703
+ en: 'Close first-run dialogs and banners',
2704
+ bg: 'Затваряй прозорците и банерите при първо пускане',
2705
+ doesEn: 'On (the default): Edge\'s and the page\'s first-run dialogs and banners are closed with the button that declines, before each message and when the chat opens. Off: left as they are.',
2706
+ doesBg: 'Включено (по подразбиране): прозорците и банерите при първо пускане на Edge и на страницата се затварят с бутона, който отказва, преди всяко съобщение и при отваряне на чата. Изключено: остават.',
2707
+ },
2708
+ {
2709
+ key: 'steps.feedbackPanel',
2710
+ kind: 'checkbox',
2711
+ en: 'Close Office\'s feedback panel',
2712
+ bg: 'Затваряй панела за обратна връзка на Office',
2713
+ doesEn: 'On (the default): Office\'s feedback panel is closed before each message when it is open. Off: left open.',
2714
+ doesBg: 'Включено (по подразбиране): панелът за обратна връзка на Office се затваря преди всяко съобщение, когато е отворен. Изключено: остава отворен.',
2715
+ },
2716
+ {
2717
+ key: 'steps.nameChat',
2718
+ kind: 'checkbox',
2719
+ en: 'Name the conversation in the sidebar',
2720
+ bg: 'Кръщавай разговора в страничната лента',
2721
+ doesEn: 'On (the default): a new conversation is renamed in Copilot\'s sidebar after its first answer. Off: it keeps Copilot\'s title and is found by its address only.',
2722
+ doesBg: 'Включено (по подразбиране): новият разговор се преименува в страничната лента на Copilot след първия отговор. Изключено: остава със заглавието от Copilot и се намира само по адреса си.',
2723
+ },
2724
+ {
2725
+ key: 'steps.ownTitle',
2726
+ kind: 'note',
2727
+ en: 'Your steps',
2728
+ bg: 'Твоите стъпки',
2729
+ doesEn: 'The steps of your own, in their order: each "if this is on the page, do this".',
2730
+ doesBg: 'Твоите стъпки, в реда им: всяка „ако това е на страницата, направи това“.',
2731
+ },
2732
+ {
2733
+ key: 'steps.add',
2734
+ kind: 'button',
2735
+ en: '+ Add a step',
2736
+ bg: '+ Добави стъпка',
2737
+ doesEn: 'Adds a step of your own at the end of the list, switched on, before each message, "Click it"; its name field gets the cursor.',
2738
+ doesBg: 'Добавя твоя стъпка в края на списъка, включена, преди всяко съобщение, „Кликни го“; курсорът отива в полето за име.',
2739
+ },
2740
+ {
2741
+ key: 'steps.on',
2742
+ kind: 'checkbox',
2743
+ en: 'On',
2744
+ bg: 'Включена',
2745
+ doesEn: 'Whether the bot takes the step; off, it is kept and passed over.',
2746
+ doesBg: 'Дали ботът прави стъпката; изключена, остава и се пропуска.',
2747
+ },
2748
+ {
2749
+ key: 'steps.name',
2750
+ kind: 'field',
2751
+ en: 'Name',
2752
+ bg: 'Име',
2753
+ doesEn: 'The step\'s name in your words, shown in the bot\'s messages and given to a chatbot with the page\'s HTML.',
2754
+ doesBg: 'Името на стъпката с твои думи, показва се в съобщенията на бота и се дава на чатбот с HTML-а на страницата.',
2755
+ },
2756
+ {
2757
+ key: 'steps.when',
2758
+ kind: 'select',
2759
+ en: 'When',
2760
+ bg: 'Кога',
2761
+ doesEn: 'When the step is taken: "When the chat opens" or "Before each message".',
2762
+ doesBg: 'Кога се прави стъпката: „При отваряне на чата“ или „Преди всяко съобщение“.',
2763
+ },
2764
+ {
2765
+ key: 'steps.whenOpen',
2766
+ kind: 'select',
2767
+ en: 'When the chat opens',
2768
+ bg: 'При отваряне на чата',
2769
+ doesEn: 'In "When": a new chat, a conversation opened again, after a sign-in.',
2770
+ doesBg: 'В „Кога“: нов чат, разговор, отворен отново, след вход.',
2771
+ },
2772
+ {
2773
+ key: 'steps.whenMessage',
2774
+ kind: 'select',
2775
+ en: 'Before each message',
2776
+ bg: 'Преди всяко съобщение',
2777
+ doesEn: 'In "When": just before the bot writes each message in the box.',
2778
+ doesBg: 'В „Кога“: точно преди ботът да напише всяко съобщение в кутията.',
2779
+ },
2780
+ {
2781
+ key: 'steps.locator',
2782
+ kind: 'field',
2783
+ en: 'Locator',
2784
+ bg: 'Локатор',
2785
+ doesEn: 'What the step looks for on the page (CSS, XPath or Playwright\'s own); only what is visible counts. In red when a required step found nothing, with the page\'s HTML.',
2786
+ doesBg: 'Какво търси стъпката на страницата (CSS, XPath или формата на Playwright); брои се само видимото. В червено, когато задължителна стъпка не е намерила нищо, с HTML-а на страницата.',
2787
+ },
2788
+ {
2789
+ key: 'steps.action',
2790
+ kind: 'select',
2791
+ en: 'Action',
2792
+ bg: 'Действие',
2793
+ doesEn: 'What is done when the locator finds something: "Click it", "Press a key", "Wait for it to show", "Wait for it to go".',
2794
+ doesBg: 'Какво се прави, когато локаторът намери нещо: „Кликни го“, „Натисни клавиш“, „Изчакай да се появи“, „Изчакай да изчезне“.',
2795
+ },
2796
+ {
2797
+ key: 'steps.action.click',
2798
+ kind: 'select',
2799
+ en: 'Click it',
2800
+ bg: 'Кликни го',
2801
+ doesEn: 'In "Action": the element found is clicked.',
2802
+ doesBg: 'В „Действие“: намереният елемент се кликва.',
2803
+ },
2804
+ {
2805
+ key: 'steps.action.press',
2806
+ kind: 'select',
2807
+ en: 'Press a key',
2808
+ bg: 'Натисни клавиш',
2809
+ doesEn: 'In "Action": the key in "Key" is pressed when the element is there.',
2810
+ doesBg: 'В „Действие“: натиска се клавишът от „Клавиш“, когато елементът е там.',
2811
+ },
2812
+ {
2813
+ key: 'steps.action.appear',
2814
+ kind: 'select',
2815
+ en: 'Wait for it to show',
2816
+ bg: 'Изчакай да се появи',
2817
+ doesEn: 'In "Action": the bot only waits for the element to show.',
2818
+ doesBg: 'В „Действие“: ботът само изчаква елементът да се появи.',
2819
+ },
2820
+ {
2821
+ key: 'steps.action.gone',
2822
+ kind: 'select',
2823
+ en: 'Wait for it to go',
2824
+ bg: 'Изчакай да изчезне',
2825
+ doesEn: 'In "Action": when the element is there, the bot waits for it to go (a spinner, a banner).',
2826
+ doesBg: 'В „Действие“: когато елементът е там, ботът чака да изчезне (индикатор, банер).',
2827
+ },
2828
+ {
2829
+ key: 'steps.key',
2830
+ kind: 'field',
2831
+ en: 'Key',
2832
+ bg: 'Клавиш',
2833
+ doesEn: 'With "Press a key": the key, as Playwright names it (Escape, Enter, Tab…).',
2834
+ doesBg: 'При „Натисни клавиш“: клавишът, както го нарича Playwright (Escape, Enter, Tab…).',
2835
+ },
2836
+ {
2837
+ key: 'steps.must',
2838
+ kind: 'checkbox',
2839
+ en: 'Must be there',
2840
+ bg: 'Задължителна',
2841
+ doesEn: 'On: a step that finds nothing in its seconds stops the work and is shown in red. Off: it is passed over.',
2842
+ doesBg: 'Включено: стъпка, която не намери нищо в секундите си, спира работата и се показва в червено. Изключено: пропуска се.',
2843
+ },
2844
+ {
2845
+ key: 'steps.waitSec',
2846
+ kind: 'field',
2847
+ en: 'Wait up to',
2848
+ bg: 'Чакай до',
2849
+ doesEn: 'How many seconds the step waits for its element to show (or to go); 0 only looks.',
2850
+ doesBg: 'Колко секунди стъпката чака елементът да се появи (или да изчезне); 0 само поглежда.',
2851
+ },
2852
+ {
2853
+ key: 'steps.up',
2854
+ kind: 'button',
2855
+ en: 'Move up',
2856
+ bg: 'Нагоре',
2857
+ doesEn: 'Moves the step one place up: the steps are taken in their order.',
2858
+ doesBg: 'Мести стъпката едно място нагоре: стъпките се правят в реда си.',
2859
+ },
2860
+ {
2861
+ key: 'steps.down',
2862
+ kind: 'button',
2863
+ en: 'Move down',
2864
+ bg: 'Надолу',
2865
+ doesEn: 'Moves the step one place down.',
2866
+ doesBg: 'Мести стъпката едно място надолу.',
2867
+ },
2868
+ {
2869
+ key: 'steps.remove',
2870
+ kind: 'button',
2871
+ en: 'Delete',
2872
+ bg: 'Изтрий',
2873
+ doesEn: 'Deletes the step, after asking. To keep it for later, untick "On" instead.',
2874
+ doesBg: 'Изтрива стъпката, след като попита. За да я запазиш за по-късно, махни отметката „Включена“.',
2875
+ },
2876
+ ],
2877
+ },
2663
2878
  {
2664
2879
  headingKey: 'loc.title',
2665
2880
  en: "The model menu's locators",
@@ -1,3 +1,6 @@
1
+ /** A text without a terminal's colour codes (Playwright's errors carry them: [2m … [22m). */
2
+ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;?]*[ -/]*[@-~]`, 'g');
3
+ const stripAnsi = (text) => text.replace(ANSI, '');
1
4
  const WORDS = {
2
5
  en: {
3
6
  done: 'The task is done',
@@ -148,7 +151,7 @@ const WORDS = {
148
151
  const RIGHT_TO_LEFT = new Set(['ar']);
149
152
  /** A reason as a line: its first sentence or so, since the whole of it is in the chat. */
150
153
  function brief(text, max = 220) {
151
- const one = (text ?? '').replace(/\s+/g, ' ').trim();
154
+ const one = stripAnsi(text ?? '').replace(/\s+/g, ' ').trim();
152
155
  return one.length > max ? `${one.slice(0, max - 1).trimEnd()}…` : one;
153
156
  }
154
157
  /** The card for a run of the chat that has ended: how its message(s) ended, and that the window stays open. */
@@ -6,6 +6,9 @@
6
6
  * history so a page that opens mid-run can catch up.
7
7
  */
8
8
  import { EventEmitter } from 'node:events';
9
+ /** A text without a terminal's colour codes (Playwright's errors carry them: [2m … [22m). */
10
+ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;?]*[ -/]*[@-~]`, 'g');
11
+ const stripAnsi = (text) => text.replace(ANSI, '');
9
12
  const HISTORY_PER_SESSION = 500;
10
13
  export class EventBus {
11
14
  emitter = new EventEmitter();
@@ -14,7 +17,8 @@ export class EventBus {
14
17
  this.emitter.setMaxListeners(100);
15
18
  }
16
19
  publish(event) {
17
- const full = { at: new Date().toISOString(), ...event };
20
+ // Playwright colours its errors for a terminal ([2m … [22m): what is said is said without (2026-11-17).
21
+ const full = { at: new Date().toISOString(), ...event, ...(typeof event.message === 'string' ? { message: stripAnsi(event.message) } : {}) };
18
22
  const list = this.history.get(event.sessionId) ?? [];
19
23
  list.push(full);
20
24
  if (list.length > HISTORY_PER_SESSION)
@@ -6,7 +6,8 @@
6
6
  */
7
7
  import { readFile, rename, writeFile } from 'node:fs/promises';
8
8
  import { CHAT_LOCATOR_KEYS } from '../transport/locators.js';
9
- const isKey = (k) => typeof k === 'string' && CHAT_LOCATOR_KEYS.includes(k);
9
+ import { isStepKey } from '../transport/chatSteps.js';
10
+ const isKey = (k) => typeof k === 'string' && (CHAT_LOCATOR_KEYS.includes(k) || isStepKey(k));
10
11
  export class LocatorFailures {
11
12
  file;
12
13
  /** One write at a time: two failures in the same second are both kept. */
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The steps on the way to the chat, as the operator sets them (2026-11-17: "what happens if we want to add or remove a
3
+ * step? Some steps will drop out in future and new ones will appear to reach the chat"). The locators say where each of
4
+ * the bot's own steps clicks; these say which of those steps are taken at all, and what more is done:
5
+ *
6
+ * - the bot's own steps that can be done without — declining Edge's and the page's first-run dialogs, closing
7
+ * Office's feedback panel, naming the conversation in the sidebar — each switched off in Settings;
8
+ * - steps of the operator's own, in their order, each "if this is on the page, do this": when the chat opens (a new
9
+ * chat, a conversation opened again, after a sign-in) or before each message. Click it, press a key, wait for it to
10
+ * show, wait for it to go. One that "must be there" and is not, within its seconds, stops the work and is said like
11
+ * a locator that found nothing — in red in Settings, with the page's HTML for a chatbot; the others are passed over
12
+ * when they are not there.
13
+ *
14
+ * Only on Copilot's page, only what the locator finds: nothing is typed, nothing is downloaded, no program is started.
15
+ */
16
+ import { locatorSyntaxProblem } from './locators.js';
17
+ export const STEP_WHEN = ['open', 'message'];
18
+ export const STEP_ACTIONS = ['click', 'press', 'appear', 'gone'];
19
+ /** The bot's own steps that can be switched off; all on by default, as before 2026-11-17. */
20
+ export const BUILT_IN_STEPS = ['popups', 'feedbackPanel', 'nameChat'];
21
+ export const DefaultBuiltInSteps = { popups: true, feedbackPanel: true, nameChat: true };
22
+ /** Where a step's failure is kept, and Settings finds its row by. */
23
+ export const stepKey = (id) => `step:${id}`;
24
+ export const isStepKey = (key) => /^step:[\w-]{1,40}$/.test(key);
25
+ /** A key Playwright can press: a name or one character, with Control/Shift/Alt/Meta in front. */
26
+ export function keyProblem(key) {
27
+ const k = (key ?? '').trim();
28
+ if (!k)
29
+ return 'no key is given to press';
30
+ const ok = /^(?:(?:Control|Shift|Alt|Meta)\+)*(?:[A-Za-z0-9]|F(?:[1-9]|1[0-2])|Escape|Enter|Tab|Space|Backspace|Delete|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|Home|End|PageUp|PageDown)$/.test(k);
31
+ return ok ? null : `"${k}" is not a key it can press (Escape, Enter, Tab, Space, an arrow, F1–F12, one letter or digit, Control+… )`;
32
+ }
33
+ /** What keeps a step from being taken, said for the operator; null when it can be. */
34
+ export function stepProblem(step) {
35
+ if (!step.locator.trim())
36
+ return 'it has no locator';
37
+ const syntax = locatorSyntaxProblem(step.locator);
38
+ if (syntax)
39
+ return syntax;
40
+ if (step.action === 'press')
41
+ return keyProblem(step.key);
42
+ return null;
43
+ }
44
+ /** The steps taken, in their order: those switched on that can be taken; the rest said in `problems`. */
45
+ export function usableSteps(saved) {
46
+ const steps = [];
47
+ const problems = [];
48
+ for (const [i, step] of (saved ?? []).entries()) {
49
+ if (step.off)
50
+ continue;
51
+ const problem = stepProblem(step);
52
+ if (problem)
53
+ problems.push(`step ${i + 1} "${step.name || step.locator}" in Settings is not taken: ${problem}`);
54
+ else
55
+ steps.push(step);
56
+ }
57
+ return { steps, problems };
58
+ }
59
+ /** The text a chatbot is handed with the page's HTML for a step's element (as `locatorPrompt` for the chat's own). */
60
+ export function stepPrompt(step, failed) {
61
+ const what = step.action === 'click' ? 'the element the user clicks at this point'
62
+ : step.action === 'press' ? `the element whose presence means the key ${step.key ?? ''} is to be pressed`
63
+ : step.action === 'appear' ? 'the element that shows when the page is ready for this step'
64
+ : 'the element that shows while the page is not ready yet (a spinner, a banner, a dialog)';
65
+ return [
66
+ 'The attached file is the HTML of the Microsoft 365 Copilot chat page in a browser (scripts, styles and the list of conversations taken out).',
67
+ `Find this element in it: ${what}. The user describes it as: "${step.name || '(no description)'}".`,
68
+ `This locator used to find it and now finds nothing: ${failed}`,
69
+ 'Give me one locator that finds exactly this element, and only it: a CSS selector, or an XPath if CSS cannot say it.',
70
+ '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, the visible text.',
71
+ 'Do not use class names made of random letters (like azFuQXgw or ___1x5usfw): they change with every new version of the page.',
72
+ 'Answer with the locator on the first line, then one line on why it is that element.',
73
+ ].join('\n');
74
+ }