copilot-operator 0.1.90 → 0.1.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/src/api/operator.controller.js +26 -0
  2. package/dist/src/api/operator.service.js +55 -14
  3. package/dist/src/cli.js +3 -0
  4. package/dist/src/config/live.js +6 -3
  5. package/dist/src/config/schema.js +23 -0
  6. package/dist/src/orchestrator/taskRunner.js +25 -3
  7. package/dist/src/plan/systemGuide.js +220 -13
  8. package/dist/src/session/chatNotice.js +4 -1
  9. package/dist/src/session/chatbotFile.js +117 -0
  10. package/dist/src/session/events.js +5 -1
  11. package/dist/src/session/locatorFailures.js +2 -1
  12. package/dist/src/transport/chatSteps.js +74 -0
  13. package/dist/src/transport/copilotTransport.js +288 -31
  14. package/dist/src/transport/keptWindow.js +4 -0
  15. package/dist/src/transport/locators.js +106 -5
  16. package/dist/src/transport/pageHtml.js +36 -2
  17. package/dist/web/404.html +2 -2
  18. package/dist/web/_next/static/chunks/{1077.1cc6d439e3dd0fa9.js → 1077.626a11362f53d35c.js} +1 -1
  19. package/dist/web/_next/static/chunks/{1548.3de9dc874e47558e.js → 1548.79f05ff765581b0a.js} +1 -1
  20. package/dist/web/_next/static/chunks/{2163.66458fb9c54fb52d.js → 2163.09f1212655504f3a.js} +1 -1
  21. package/dist/web/_next/static/chunks/{714.cffed2b87154be0f.js → 714.acea3698b6af7a61.js} +1 -1
  22. package/dist/web/_next/static/chunks/{7220.30b6a3e1bd41e51a.js → 7220.1eba10bd9d449cea.js} +1 -1
  23. package/dist/web/_next/static/chunks/7921-29256ac683ea4bc5.js +1 -0
  24. package/dist/web/_next/static/chunks/{8584.36422ed19d6c43e9.js → 8584.b5aac5354f124d4b.js} +1 -1
  25. package/dist/web/_next/static/chunks/{9067.e579f97591576de2.js → 9067.177163495f3bd8fa.js} +1 -1
  26. package/dist/web/_next/static/chunks/{9747.11247f0e21542f6d.js → 9747.5b9d763e89abc7e4.js} +1 -1
  27. package/dist/web/_next/static/chunks/app/layout-1b7d13f7b2efd008.js +1 -0
  28. package/dist/web/_next/static/chunks/app/settings/page-c92548f9c6318962.js +1 -0
  29. package/dist/web/_next/static/chunks/{webpack-78ec62098b09e4a0.js → webpack-33252b1a0a7d93ba.js} +1 -1
  30. package/dist/web/_next/static/css/{d74aa18c98dacdb4.css → 6b92f118889ca88b.css} +1 -1
  31. package/dist/web/defaults.html +2 -2
  32. package/dist/web/defaults.txt +8 -8
  33. package/dist/web/index.html +3 -3
  34. package/dist/web/index.txt +9 -9
  35. package/dist/web/queue.html +2 -2
  36. package/dist/web/queue.txt +9 -9
  37. package/dist/web/settings.html +2 -2
  38. package/dist/web/settings.txt +9 -9
  39. package/dist/web/system.html +2 -2
  40. package/dist/web/system.txt +9 -9
  41. package/package.json +1 -1
  42. package/dist/web/_next/static/chunks/7921-d3a4a261e08950e0.js +0 -1
  43. package/dist/web/_next/static/chunks/app/layout-7b5fa7c74ecd6939.js +0 -1
  44. package/dist/web/_next/static/chunks/app/settings/page-7651920337bbb580.js +0 -1
  45. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → ZrEcjGdZEXe66UUxUqine}/_buildManifest.js +0 -0
  46. /package/dist/web/_next/static/{3VkK1sxEugkae88HSFR-i → ZrEcjGdZEXe66UUxUqine}/_ssgManifest.js +0 -0
@@ -0,0 +1,117 @@
1
+ import { CHAT_ID, ChatLocatorShows, ChatLocatorWhat, ChatPlaceholder, FILE_NAME, FILE_STEM } from '../transport/locators.js';
2
+ const LANGUAGE_NAMES = {
3
+ en: 'English',
4
+ bg: 'Bulgarian',
5
+ de: 'German',
6
+ es: 'Spanish',
7
+ fr: 'French',
8
+ pt: 'Portuguese',
9
+ ja: 'Japanese',
10
+ ko: 'Korean',
11
+ ar: 'Arabic',
12
+ };
13
+ /** The language the chatbot speaks to the operator in: the interface's, English when it is not one of its. */
14
+ export function languageName(code) {
15
+ return LANGUAGE_NAMES[(code ?? '').toLowerCase()] ?? 'English';
16
+ }
17
+ /** The whole page is cut at this length: what is past it is rarely read by a chatbot, and the file stays small to attach. */
18
+ export const PAGE_CAP = 600_000;
19
+ /** A fence longer than any run of backticks in the text, so the HTML never closes its own code block. */
20
+ function fenced(text, lang) {
21
+ const longest = Math.max(0, ...Array.from(text.matchAll(/`+/g), (m) => m[0].length));
22
+ const fence = '`'.repeat(Math.max(3, longest + 1));
23
+ return `${fence}${lang}\n${text}\n${fence}`;
24
+ }
25
+ /** What the element is, said for the chatbot. */
26
+ function elementOf(failure, step) {
27
+ if (!failure.key.startsWith('step:'))
28
+ return ChatLocatorWhat[failure.key];
29
+ const action = step?.action ?? 'click';
30
+ const what = action === 'click' ? 'the element the program clicks at this point'
31
+ : action === 'press' ? `the element whose presence means the key ${step?.key ?? ''} is to be pressed`
32
+ : action === 'appear' ? 'the element that shows when the page is ready for this step'
33
+ : 'the element that shows while the page is not ready yet (a spinner, a banner, a dialog)';
34
+ return `${what}. The user describes it as: "${step?.name || failure.name || '(no description)'}"`;
35
+ }
36
+ /** When the element is on the screen, for the person to bring it there by hand. */
37
+ function showsWhen(failure, step) {
38
+ if (!failure.key.startsWith('step:'))
39
+ return ChatLocatorShows[failure.key];
40
+ const when = (step?.when ?? 'message') === 'open' ? 'right after the chat opens' : 'just before a message is sent';
41
+ return `bring the page to where the program meets it, ${when} (the user knows the step: "${step?.name || failure.name || ''}")`;
42
+ }
43
+ /** The file's text (Markdown, kept as .txt so every chatbot takes it as an attachment). */
44
+ export function chatbotFile({ failure, step, piece, page, lang }) {
45
+ const isStep = failure.key.startsWith('step:');
46
+ const where = isStep ? 'Settings → "Steps to the chat", the step\'s row in red' : 'Settings → "The chat\'s locators", the field in red';
47
+ const placeholder = isStep ? undefined : ChatPlaceholder[failure.key];
48
+ const language = languageName(lang);
49
+ const cutPage = page.length > PAGE_CAP ? `${page.slice(0, PAGE_CAP)}\n<!-- … the rest of the page is cut here (it is ${page.length} characters long) -->` : page;
50
+ const lines = [
51
+ '# For the chatbot: find a locator on the Microsoft 365 Copilot page',
52
+ '',
53
+ 'Read this whole file before you answer. The user attached it and may have written nothing else: start at once.',
54
+ `Speak to the user in ${language}. Keep every locator exactly as it must be typed, in a code block.`,
55
+ '',
56
+ '## What this is about',
57
+ '',
58
+ 'The user runs copilot-operator, a program that drives the Microsoft 365 Copilot chat page in Microsoft Edge (with Playwright).',
59
+ 'It finds each element it needs on that page by a locator: a CSS selector, an XPath, or a Playwright selector.',
60
+ 'Copilot\'s page changed, and one of those locators now finds nothing.',
61
+ '',
62
+ `**Your goal:** give the user ONE new locator that finds exactly this element, and only it. The user pastes it into the program (${where}), and the program finds the element again.`,
63
+ '',
64
+ '## What failed',
65
+ '',
66
+ `- **The element:** ${elementOf(failure, step)}.`,
67
+ `- **Its name in the program:** ${isStep ? `the step "${step?.name || failure.name || failure.key.slice(5)}"` : `"${failure.key}"`}`,
68
+ `- **The old locator, which now finds nothing:** \`${failure.locator}\``,
69
+ `- **When and what the program was doing:** ${failure.at}: ${isStep ? failure.why : `it found nothing ${failure.why}`}`,
70
+ `- **The work:** ${failure.stopped ? 'stopped there' : 'went on without it, more slowly or with something left undone'}`,
71
+ ...(failure.url ? [`- **The page's address:** ${failure.url}`] : []),
72
+ '',
73
+ '## Rules for the new locator',
74
+ '',
75
+ '- A CSS selector; an XPath (starting with /) only when CSS cannot say it. The program also takes Playwright\'s :text-is("…"), :has-text("…"), :has(…) and role=button[name="…"].',
76
+ '- 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.',
77
+ '- Do not use class names made of random letters (like azFuQXgw or ___1x5usfw): they change with every new version of the page.',
78
+ '- Before you give it, check it against the HTML below: it must match exactly one element (for elements the page shows many of, like the conversation\'s messages, it must match each of them and nothing else).',
79
+ ...(placeholder === CHAT_ID ? [`- Keep ${CHAT_ID} in it where the conversation's id goes: the program puts the id there.`] : []),
80
+ ...(placeholder === FILE_NAME
81
+ ? [`- Keep ${FILE_NAME} in it where the file's name goes (the HTML shows message-01-in-full.txt or the like), or ${FILE_STEM} for the name without its extension (message-01-in-full): the program puts the name there.`]
82
+ : []),
83
+ '',
84
+ '## How to answer',
85
+ '',
86
+ '1. The locator alone, in a code block.',
87
+ '2. One line on why it is that element.',
88
+ `3. Tell the user to paste it into the program: ${where}.`,
89
+ '4. Tell the user how to check it on the real page: in Edge on the Copilot page, press F12, open "Elements", press Ctrl+F, paste the locator: it must show "1 of 1". (Ctrl+F there takes CSS and XPath, not Playwright\'s :text-is() or role=…: for those, the program\'s own "Check the locators" in Settings does the check.) If it shows "0 of 0" or more than one, the user tells you, and you look again.',
90
+ '',
91
+ '## Where to look',
92
+ '',
93
+ piece
94
+ ? `Look first in **Part 1**: the piece of the page the program took from around ${failure.around ?? 'where the element was looked for'}. The element is most likely in it: beside it, above it or inside it. If it is not there, look in **Part 2**, the whole page.`
95
+ : 'Look in **Part 2**, the whole page. (The program could not tell which part of the page the element is most likely in, so there is no Part 1.)',
96
+ 'The page was saved without its scripts, styles and picture data, and without the names of the user\'s conversations.',
97
+ '',
98
+ '## If the element is in neither part',
99
+ '',
100
+ 'This is rare: the page may not have been showing it when it was saved. Do not guess a locator. Walk the user through finding it, one step at a time, and wait for their answer after each:',
101
+ `1. In Edge, open the Copilot page and bring the element onto the screen: ${showsWhen(failure, step)}.`,
102
+ '2. Press F12 (the developer tools), then Ctrl+Shift+C, and click the element on the page. Its line in "Elements" is now highlighted.',
103
+ '3. Right-click that highlighted line → Copy → Copy outerHTML, and paste it to you. Then the same for the line of its parent (the line above it, one step to the left), and paste that too.',
104
+ '4. From what they paste, give the locator as above.',
105
+ 'If the user cannot bring the element onto the screen at all, it may no longer exist on the page: say so, and ask them to describe or send a picture of what the page shows at that moment instead, and find with them what replaced it.',
106
+ '',
107
+ '## Part 1: the piece of the page where the element most likely is',
108
+ '',
109
+ piece ? fenced(piece, 'html') : '(none: see Part 2)',
110
+ '',
111
+ '## Part 2: the whole page',
112
+ '',
113
+ cutPage ? fenced(cutPage, 'html') : '(The page itself was not saved: help the user find the element in the browser, as said above.)',
114
+ '',
115
+ ];
116
+ return lines.join('\n');
117
+ }
@@ -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
+ }