copilot-operator 0.1.83 → 0.1.85

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 (62) hide show
  1. package/dist/src/api/operator.controller.js +90 -0
  2. package/dist/src/api/operator.service.js +270 -30
  3. package/dist/src/config/schema.js +17 -0
  4. package/dist/src/orchestrator/cardText.js +91 -0
  5. package/dist/src/orchestrator/kerriganRunner.js +912 -0
  6. package/dist/src/orchestrator/leadRunner.js +25 -16
  7. package/dist/src/orchestrator/planMode.js +6 -4
  8. package/dist/src/orchestrator/taskRunner.js +88 -16
  9. package/dist/src/plan/kerrigan.js +109 -4
  10. package/dist/src/plan/systemGuide.js +194 -2
  11. package/dist/src/protocol/kerriganSchema.js +175 -0
  12. package/dist/src/session/store.js +9 -0
  13. package/dist/src/transport/chatTransport.js +1 -1
  14. package/dist/src/transport/copilotTransport.js +150 -3
  15. package/dist/src/vcs/git.js +72 -2
  16. package/dist/src/vcs/operatorGit.js +409 -0
  17. package/dist/web/404.html +2 -2
  18. package/dist/web/_next/static/chunks/1077.06fe73b2c16f8f49.js +1 -0
  19. package/dist/web/_next/static/chunks/1548.b38c5d8d00ab2a72.js +1 -0
  20. package/dist/web/_next/static/chunks/{2163.2af0979126ae613a.js → 2163.ba933c9a506302ca.js} +1 -1
  21. package/dist/web/_next/static/chunks/714.575273a189d030fe.js +1 -0
  22. package/dist/web/_next/static/chunks/7220.988dfd28e00f407c.js +1 -0
  23. package/dist/web/_next/static/chunks/7921-65dd56d87144bd44.js +1 -0
  24. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +1 -0
  25. package/dist/web/_next/static/chunks/8584.2221587201bc2fa2.js +1 -0
  26. package/dist/web/_next/static/chunks/9067.8d94a08830c3d1da.js +1 -0
  27. package/dist/web/_next/static/chunks/9747.8671194406acd839.js +1 -0
  28. package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +1 -0
  29. package/dist/web/_next/static/chunks/app/page-76139370c7ca3715.js +1 -0
  30. package/dist/web/_next/static/chunks/app/settings/page-116da78c83f0c5c9.js +1 -0
  31. package/dist/web/_next/static/chunks/webpack-13ccb80d7b7094ca.js +1 -0
  32. package/dist/web/_next/static/css/6e2b8656501f0dd7.css +1 -0
  33. package/dist/web/defaults.html +2 -2
  34. package/dist/web/defaults.txt +8 -8
  35. package/dist/web/index.html +3 -3
  36. package/dist/web/index.txt +9 -9
  37. package/dist/web/queue.html +2 -2
  38. package/dist/web/queue.txt +9 -9
  39. package/dist/web/settings.html +2 -2
  40. package/dist/web/settings.txt +9 -9
  41. package/dist/web/system.html +2 -2
  42. package/dist/web/system.txt +9 -9
  43. package/package.json +175 -173
  44. package/prompts/kerrigan1.md +169 -0
  45. package/prompts/lead1.md +4 -1
  46. package/prompts/level1.md +8 -1
  47. package/dist/web/_next/static/chunks/1077.e0136d293069ccb8.js +0 -1
  48. package/dist/web/_next/static/chunks/1548.5cc0c57b00c2e44f.js +0 -1
  49. package/dist/web/_next/static/chunks/714.410e2b61aa8c72b7.js +0 -1
  50. package/dist/web/_next/static/chunks/7220.2c4e5173a060769f.js +0 -1
  51. package/dist/web/_next/static/chunks/7921-3d21f385338afdf9.js +0 -1
  52. package/dist/web/_next/static/chunks/8124-1dc34be1646970a8.js +0 -1
  53. package/dist/web/_next/static/chunks/8584.61650a59d2bfa54d.js +0 -1
  54. package/dist/web/_next/static/chunks/9067.553056fc9b6cf80e.js +0 -1
  55. package/dist/web/_next/static/chunks/9747.d5826524bf4b714d.js +0 -1
  56. package/dist/web/_next/static/chunks/app/layout-b8a1e0075a48b025.js +0 -1
  57. package/dist/web/_next/static/chunks/app/page-13147b69cf336831.js +0 -1
  58. package/dist/web/_next/static/chunks/app/settings/page-e3909ef6c2d8e321.js +0 -1
  59. package/dist/web/_next/static/chunks/webpack-19a2d7161f23b21d.js +0 -1
  60. package/dist/web/_next/static/css/f152f27d6afce55c.css +0 -1
  61. /package/dist/web/_next/static/{aHzr4dVoCwf71514A9bWP → aCQe1FDhYTj4zGeI5ueVq}/_buildManifest.js +0 -0
  62. /package/dist/web/_next/static/{aHzr4dVoCwf71514A9bWP → aCQe1FDhYTj4zGeI5ueVq}/_ssgManifest.js +0 -0
@@ -140,6 +140,37 @@ export class WindowClosed extends Error {
140
140
  this.name = 'WindowClosed';
141
141
  }
142
142
  }
143
+ /**
144
+ * The window had left the conversation the bot put it on, and could not be put back (operator, 2026-11-09; see
145
+ * `ensureOnChat`): the conversation does not open again, or the sign-in the page asked for first was not done in time.
146
+ * Nothing was sent: not to it, and not to the page the window was on instead, another conversation or a new one on
147
+ * Copilot's home page. Nothing that sends again gets past it either, so a caller's retries do not try (see `runTask`).
148
+ */
149
+ export class ChatLost extends Error {
150
+ chatId;
151
+ found;
152
+ constructor(chatId,
153
+ /** Where the window was: its address without the query. */
154
+ found, message) {
155
+ super(message ??
156
+ `Copilot's window was no longer on this conversation (${chatId}): it showed ${found}. The conversation could not be ` +
157
+ 'opened again, by its address or by its name in the sidebar, so nothing was sent, and nothing went into another chat. ' +
158
+ "Look in Copilot's sidebar in the Edge window to see whether the conversation is still there.");
159
+ this.chatId = chatId;
160
+ this.found = found;
161
+ this.name = 'ChatLost';
162
+ }
163
+ }
164
+ /** An address without its query and fragment, which may carry an account's name: what a record says of where a page was. */
165
+ export function whereIs(url) {
166
+ try {
167
+ const u = new URL(url);
168
+ return u.protocol === 'about:' ? url : `${u.origin}${u.pathname}`;
169
+ }
170
+ catch {
171
+ return url.replace(/[?#].*$/, '').slice(0, 200);
172
+ }
173
+ }
143
174
  /** The id of the notice's element in the chat's page, so the next one, and `clearNotice`, find it. */
144
175
  const NOTICE_ID = 'copilot-operator-notice';
145
176
  /**
@@ -245,6 +276,19 @@ export class CopilotTransport {
245
276
  locatorProblems;
246
277
  /** Whether the rows' locator has been said not to work in the page (see `readMenuRows`). */
247
278
  rowsLocatorFailed = false;
279
+ /**
280
+ * The conversation the bot itself put this window on (operator, 2026-11-09: a task paused, or waiting on a card, for
281
+ * some days went on in a new chat on Auto — the page had left its conversation meanwhile, and the next message went
282
+ * wherever the page was). `{ id }` once the conversation has an address; `'new'` for a new one not yet answered, which
283
+ * gets its address with its first answer (`waitForReply`); null where none is expected, as on Copilot's home page after
284
+ * a sign-in, before a run enters its conversation. Set only by what moves the page on purpose — `newChat`,
285
+ * `openConversation`, `openConversationByName`, `ensureSignedIn`, `gotoChatAs`, `signOut` — and read by `ensureOnChat`.
286
+ */
287
+ onChat = null;
288
+ /** The name each conversation was given, or found by, in the sidebar: the way back to it when its address does not open it. */
289
+ chatNames = new Map();
290
+ /** How long a page is given to show the composer before it is taken to be asking for a sign-in. */
291
+ firstLookMs = 15_000;
248
292
  constructor(opts) {
249
293
  this.opts = opts;
250
294
  const { locators, problems } = resolvePickerLocators(opts.pickerLocators);
@@ -508,6 +552,7 @@ export class CopilotTransport {
508
552
  * without anyone choosing it.
509
553
  */
510
554
  async signOut() {
555
+ this.onChat = null;
511
556
  this.emit('signing-out');
512
557
  await this.p
513
558
  .goto('https://login.microsoftonline.com/common/oauth2/v2.0/logout', {
@@ -531,6 +576,7 @@ export class CopilotTransport {
531
576
  target.searchParams.set('login_hint', upn);
532
577
  target.searchParams.set('prompt', 'select_account');
533
578
  }
579
+ this.onChat = null;
534
580
  await this.p.goto(target.toString(), { waitUntil: 'domcontentloaded' });
535
581
  }
536
582
  /** Throws with an explanation when the profile is not on the work Copilot. */
@@ -640,13 +686,15 @@ Current URL: ${url}`);
640
686
  * types credentials; it only waits for the composer to appear.
641
687
  */
642
688
  async ensureSignedIn(url = this.opts.chatUrl, opts = {}) {
689
+ // Copilot's home page, where no conversation is expected until the run enters one.
690
+ this.onChat = null;
643
691
  await this.p.goto(url, { waitUntil: 'domcontentloaded' });
644
692
  /*
645
693
  * Looked for a second at a time, so a Stop pressed while the page loads or the operator has not signed in yet
646
694
  * ends the wait at once, rather than after the whole sign-in timeout, fifteen minutes by default (2026-10-17).
647
695
  */
648
696
  const stoppedHere = 'stopped by the operator while waiting for the sign-in';
649
- if (!(await this.composerWithin(15_000, opts.signal, stoppedHere))) {
697
+ if (!(await this.composerWithin(this.firstLookMs, opts.signal, stoppedHere))) {
650
698
  this.emit('sign-in-required', { url: this.p.url() });
651
699
  if (!(await this.composerWithin(this.opts.signInTimeoutMs, opts.signal, stoppedHere))) {
652
700
  throw new Error(`The sign-in was not completed within ${Math.round(this.opts.signInTimeoutMs / 1000)} s (Settings → copilot.signInTimeoutSec). ` +
@@ -658,28 +706,120 @@ Current URL: ${url}`);
658
706
  await this.assertWorkSurface();
659
707
  }
660
708
  async newChat() {
709
+ this.onChat = null;
661
710
  await this.p.goto(Url.newChat, { waitUntil: 'domcontentloaded' });
662
711
  await this.composer().waitFor({ state: 'visible' });
663
712
  await this.dismissPopups();
713
+ this.onChat = 'new';
664
714
  }
665
715
  /** Reopens a conversation by its id. Returns false when it no longer opens. */
666
716
  async openConversation(chatId) {
717
+ this.onChat = null;
667
718
  await this.p.goto(Url.conversation(chatId), { waitUntil: 'domcontentloaded' });
668
719
  if (!(await this.isChatReady(20_000)))
669
720
  return false;
670
- return parseChatId(this.p.url()) === chatId;
721
+ const there = parseChatId(this.p.url()) === chatId;
722
+ if (there)
723
+ this.onChat = { id: chatId };
724
+ return there;
671
725
  }
672
726
  /** Finds a conversation by its exact name in the sidebar. */
673
727
  async openConversationByName(name) {
674
728
  const row = this.p.locator(`${Sidebar.conversationLink}[aria-label="${name.replace(/"/g, '\\"')}"]`);
675
729
  if ((await row.count()) === 0)
676
730
  return false;
731
+ // The conversation it is, from the link's own address: the page's follows a moment after the click.
732
+ const href = await row.first().getAttribute('href').catch(() => null);
733
+ this.onChat = null;
677
734
  await row.first().click();
678
- return await this.isChatReady(20_000);
735
+ if (!(await this.isChatReady(20_000)))
736
+ return false;
737
+ const id = parseChatId(href ?? '') ?? parseChatId(this.p.url());
738
+ if (id) {
739
+ this.onChat = { id };
740
+ this.chatNames.set(id, name);
741
+ }
742
+ return true;
679
743
  }
680
744
  async currentChatId() {
681
745
  return parseChatId(this.p.url());
682
746
  }
747
+ /** The conversation id in the page's address, waited for up to `ms`: null when it shows none by then. */
748
+ async addressId(ms) {
749
+ const until = Date.now() + ms;
750
+ for (;;) {
751
+ const id = parseChatId(this.p.url());
752
+ if (id || Date.now() >= until)
753
+ return id;
754
+ await this.p.waitForTimeout(200);
755
+ }
756
+ }
757
+ /**
758
+ * Puts the window back on the conversation the bot put it on, when it has left it (operator, 2026-11-09: "after every
759
+ * return to the bot — an action taken, a pause ended — check that we are on the right chat, by the address taken at
760
+ * its start; if not, go back to it and carry on from there"). The runner asks this before every message it sends
761
+ * (`staysOnItsChat` in taskRunner.ts), which is every moment the work goes on after a wait: a pause, a card answered,
762
+ * commands handed over, a sign-in.
763
+ *
764
+ * What is compared is the conversation's id in the page's address, a uuid, the one the run keeps on record: unique,
765
+ * and the same whatever the conversation is called. When the page shows another, or none — Copilot's home page, a new
766
+ * chat on Auto, the sign-in page of a session that ran out, a conversation the operator opened from the sidebar — the
767
+ * conversation is opened again by its address, and when the page asks for a sign-in first, the operator signing in is
768
+ * waited for as at the start (`sign-in-required`; the run's Stop ends the wait); then by the name it was given in the
769
+ * sidebar. The page is never written in where it was found: a conversation that will not open again ends with
770
+ * `ChatLost`, and the next message is not sent anywhere either.
771
+ *
772
+ * A new conversation has no address until its first answer, so before that nothing can be compared; it takes the one
773
+ * the page shows from then on.
774
+ */
775
+ async ensureOnChat(opts = {}) {
776
+ const want = this.onChat;
777
+ if (!want)
778
+ return { at: 'unknown' };
779
+ const now = parseChatId(this.p.url());
780
+ if (want === 'new') {
781
+ if (now)
782
+ this.onChat = { id: now };
783
+ return { at: 'here' };
784
+ }
785
+ if (now === want.id)
786
+ return { at: 'here' };
787
+ const from = whereIs(this.p.url());
788
+ this.emit('chat-left', { chatId: want.id, found: from });
789
+ const stopped = 'stopped by the operator while waiting for the sign-in';
790
+ let signedIn = false;
791
+ for (let tries = 0; tries < 3; tries += 1) {
792
+ await this.p.goto(Url.conversation(want.id), { waitUntil: 'domcontentloaded' });
793
+ if (await this.composerWithin(this.firstLookMs, opts.signal, stopped)) {
794
+ if (parseChatId(this.p.url()) !== want.id)
795
+ break;
796
+ this.onChat = want;
797
+ await this.dismissPopups().catch(() => undefined);
798
+ this.emit('chat-returned', { chatId: want.id, by: 'address', signedIn, from });
799
+ return { at: 'returned', chatId: want.id, from, by: 'address', signedIn };
800
+ }
801
+ // No composer: the session ran out while the window waited, and the page asks for a sign-in — the operator's.
802
+ this.emit('sign-in-required', { url: whereIs(this.p.url()) });
803
+ await this.p.bringToFront().catch(() => undefined);
804
+ if (!(await this.composerWithin(this.opts.signInTimeoutMs, opts.signal, stopped))) {
805
+ this.onChat = want;
806
+ throw new ChatLost(want.id, from, `The chat asked for a sign-in before going back to this conversation, and it was not completed within ${Math.round(this.opts.signInTimeoutMs / 1000)} s ` +
807
+ '(Settings → copilot.signInTimeoutSec). Nothing was sent. Sign in in the open Edge window, then continue the task.');
808
+ }
809
+ this.emit('signed-in');
810
+ signedIn = true;
811
+ // A sign-in comes back to Copilot's home page, not to the conversation: its address is opened again.
812
+ }
813
+ const name = this.chatNames.get(want.id);
814
+ if (name && (await this.openConversationByName(name).catch(() => false)) && (await this.addressId(5_000)) === want.id) {
815
+ this.emit('chat-returned', { chatId: want.id, by: 'name', name, signedIn, from });
816
+ return { at: 'returned', chatId: want.id, from, by: 'name', signedIn };
817
+ }
818
+ // Still the one expected: the next message is not sent to the page found either.
819
+ this.onChat = want;
820
+ this.emit('chat-lost', { chatId: want.id, found: from });
821
+ throw new ChatLost(want.id, from);
822
+ }
683
823
  /**
684
824
  * Best-effort dismissal of first-run dialogs. Unknown ones are left alone and reported.
685
825
  *
@@ -795,6 +935,7 @@ Current URL: ${url}`);
795
935
  return false;
796
936
  }
797
937
  this.emit('chat-named', { chatId, name: wanted, ...(wanted !== name ? { asked: name } : {}) });
938
+ this.chatNames.set(chatId, wanted);
798
939
  return wanted;
799
940
  }
800
941
  catch (e) {
@@ -2013,6 +2154,12 @@ Current URL: ${url}`);
2013
2154
  this.emit('reply-files-ignored', { files: attachments });
2014
2155
  const codeBlocksDom = await this.lastAnswerCodeBlocks();
2015
2156
  const { markdown, degraded } = await this.copyLastReply();
2157
+ // A new conversation has its address once it has answered: from now on, the one `ensureOnChat` holds the page to.
2158
+ if (this.onChat === 'new') {
2159
+ const id = parseChatId(this.p.url());
2160
+ if (id)
2161
+ this.onChat = { id };
2162
+ }
2016
2163
  this.emit('reply-received', {
2017
2164
  chars: markdown.length,
2018
2165
  degraded,
@@ -15,7 +15,8 @@
15
15
  * - Nothing runs through a shell. `execFile` takes an argument list, so a branch name or a
16
16
  * commit message cannot turn into another command.
17
17
  */
18
- import { execFile, spawnSync } from 'node:child_process';
18
+ import { execFile, spawn, spawnSync } from 'node:child_process';
19
+ import { StringDecoder } from 'node:string_decoder';
19
20
  import { existsSync, statSync } from 'node:fs';
20
21
  import { readFile, stat } from 'node:fs/promises';
21
22
  import { createHash } from 'node:crypto';
@@ -43,6 +44,12 @@ export const SAFE_GIT = [
43
44
  function noHooksDir() {
44
45
  return process.env.SystemRoot ? join(process.env.SystemRoot, 'System32', 'copilot-operator-no-hooks') : '/nonexistent';
45
46
  }
47
+ /**
48
+ * The settings of the operator's own commit and push from the Git view (2026-11-11), the only git of the bot that runs
49
+ * the repository's hooks — and only once `vcs/operatorGit.ts` has found them to be the project's own, or the operator
50
+ * has said to run them. Still no fsmonitor program and no untracked cache.
51
+ */
52
+ export const OWN_HOOKS_GIT = ['-c', 'core.fsmonitor=false', '-c', 'core.untrackedCache=false'];
46
53
  /** Runs one git command in a directory. Never throws: the caller decides what a failure means. */
47
54
  export function git(cwd, args, timeoutMs = 60_000, env,
48
55
  /**
@@ -55,7 +62,7 @@ opts = {}) {
55
62
  return new Promise((resolve) => {
56
63
  let timedOut = false;
57
64
  let timer;
58
- const child = execFile('git', [...SAFE_GIT, ...args], { cwd, timeout: opts.killTree ? 0 : timeoutMs, windowsHide: opts.windowsHide ?? true, maxBuffer: 8 * 1024 * 1024, ...(env ? { env } : {}) }, (error, stdout, stderr) => {
65
+ const child = execFile('git', [...(opts.ownHooks ? OWN_HOOKS_GIT : SAFE_GIT), ...args], { cwd, timeout: opts.killTree ? 0 : timeoutMs, windowsHide: opts.windowsHide ?? true, maxBuffer: 8 * 1024 * 1024, ...(env ? { env } : {}) }, (error, stdout, stderr) => {
59
66
  if (timer)
60
67
  clearTimeout(timer);
61
68
  const code = error?.code;
@@ -78,6 +85,69 @@ opts = {}) {
78
85
  }
79
86
  });
80
87
  }
88
+ /**
89
+ * One git command whose output is read as it comes, stdout and stderr together in the order they arrive (2026-11-11):
90
+ * the operator's commit and push, whose hooks and remote talk for as long as they need, and whose every line the Git
91
+ * view shows while it runs. `ownHooks` runs the repository's hooks (see `OWN_HOOKS_GIT`); otherwise `SAFE_GIT`. Nothing
92
+ * is read from stdin, so a hook that waits for an answer gets none and ends. On the timeout git and everything it
93
+ * started are stopped. Never throws.
94
+ */
95
+ export function gitLive(cwd, args, opts) {
96
+ const max = opts.maxChars ?? 200_000;
97
+ return new Promise((resolveLive) => {
98
+ let output = '';
99
+ let cut = false;
100
+ let timedOut = false;
101
+ let settled = false;
102
+ const add = (text) => {
103
+ if (!text)
104
+ return;
105
+ output += text;
106
+ if (output.length > max) {
107
+ output = output.slice(output.length - max);
108
+ cut = true;
109
+ }
110
+ opts.onOutput?.(output, cut);
111
+ };
112
+ const done = (r) => {
113
+ if (settled)
114
+ return;
115
+ settled = true;
116
+ clearTimeout(timer);
117
+ resolveLive({ ...r, output, cut, timedOut });
118
+ };
119
+ let child;
120
+ try {
121
+ child = spawn('git', [...(opts.ownHooks ? OWN_HOOKS_GIT : SAFE_GIT), ...args], { cwd, windowsHide: opts.windowsHide ?? true, stdio: ['ignore', 'pipe', 'pipe'], ...(opts.env ? { env: opts.env } : {}) });
122
+ }
123
+ catch (e) {
124
+ add(`git could not be started: ${e.message}\n`);
125
+ resolveLive({ ok: false, code: 1, output, cut, timedOut });
126
+ return;
127
+ }
128
+ const out = new StringDecoder('utf8');
129
+ const err = new StringDecoder('utf8');
130
+ child.stdout?.on('data', (b) => add(out.write(b)));
131
+ child.stderr?.on('data', (b) => add(err.write(b)));
132
+ const timer = setTimeout(() => {
133
+ timedOut = true;
134
+ add(`\ngit gave up after ${Math.round(opts.timeoutMs / 1000)} s\n`);
135
+ if (process.platform === 'win32' && child.pid)
136
+ execFile('taskkill', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true }, () => undefined);
137
+ else
138
+ child.kill('SIGKILL');
139
+ }, opts.timeoutMs);
140
+ child.on('error', (e) => {
141
+ add(`git could not be started: ${e.message}\n`);
142
+ done({ ok: false, code: 1 });
143
+ });
144
+ child.on('close', (code) => {
145
+ add(out.end());
146
+ add(err.end());
147
+ done({ ok: code === 0 && !timedOut, code: typeof code === 'number' ? code : 1 });
148
+ });
149
+ });
150
+ }
81
151
  /**
82
152
  * One git command, synchronously, for the gate: it decides before a step starts, in a function with no await to give
83
153
  * (see `exec/scriptFiles.ts`). Only reading commands go through it. Never throws: a git that is missing, fails or