copilot-operator 0.1.48 → 0.1.51
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.
- package/README.md +582 -574
- package/dist/src/api/operator.controller.js +112 -926
- package/dist/src/api/operator.service.js +217 -2461
- package/dist/src/orchestrator/hold.js +49 -0
- package/dist/src/orchestrator/taskRunner.js +157 -23
- package/dist/src/plan/kerrigan.js +107 -0
- package/dist/src/plan/systemGuide.js +419 -3283
- package/dist/src/session/chatNotice.js +76 -0
- package/dist/src/session/store.js +2 -57
- package/dist/src/session/workspace.js +52 -5
- package/dist/src/session/workspaceGit.js +212 -0
- package/dist/src/transport/chatSession.js +28 -4
- package/dist/src/transport/chatTransport.js +1 -1
- package/dist/src/transport/copilotTransport.js +133 -1
- package/dist/web/404.html +5 -3
- package/dist/web/_next/static/chunks/134-ddd50a7fbb536ec8.js +1 -0
- package/dist/web/_next/static/chunks/190-70555f20dd0da19b.js +1 -0
- package/dist/web/_next/static/chunks/643-e85d221d57900ed7.js +1 -0
- package/dist/web/_next/static/chunks/867-869900ec999e6345.js +1 -0
- package/dist/web/_next/static/chunks/app/appearance/page-cdef33c421397cbe.js +1 -0
- package/dist/web/_next/static/chunks/app/defaults/page-e0a2b8f9a41a94c4.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-b4fc21e26e1bad95.js +1 -0
- package/dist/web/_next/static/chunks/app/level1/page-31b74cae86d960d8.js +1 -0
- package/dist/web/_next/static/chunks/app/page-1075921d44db3e4d.js +1 -0
- package/dist/web/_next/static/chunks/app/presets/page-f8abdd83cdf468f7.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-2a270bb885885821.js +1 -0
- package/dist/web/_next/static/css/8b14cb3cf0051138.css +1 -0
- package/dist/web/_next/static/eqTUTH_SJtBgNgq8Zzy3n/_buildManifest.js +1 -0
- package/dist/web/appearance.html +5 -3
- package/dist/web/appearance.txt +22 -23
- package/dist/web/defaults.html +5 -3
- package/dist/web/defaults.txt +22 -23
- package/dist/web/index.html +5 -3
- package/dist/web/index.txt +22 -23
- package/dist/web/level1.html +5 -3
- package/dist/web/level1.txt +22 -23
- package/dist/web/presets.html +6 -4
- package/dist/web/presets.txt +22 -23
- package/dist/web/system.html +5 -3
- package/dist/web/system.txt +22 -23
- package/package.json +4 -20
- package/dist/src/api/saveToDesktop.js +0 -157
- package/dist/src/plan/brief.js +0 -2003
- package/dist/src/plan/changes.js +0 -217
- package/dist/src/plan/script.js +0 -1014
- package/dist/src/session/debugExport.js +0 -165
- package/dist/src/session/exportRecord.js +0 -277
- package/dist/src/session/metrics.js +0 -95
- package/dist/src/vcs/startChoice.js +0 -367
- package/dist/web/_next/static/chunks/197-f7c33a0114fc3db3.js +0 -1
- package/dist/web/_next/static/chunks/499-751e0be9d4f86e2d.js +0 -1
- package/dist/web/_next/static/chunks/549-a4473e9519a97026.js +0 -1
- package/dist/web/_next/static/chunks/699-9d031f8c145a0465.js +0 -1
- package/dist/web/_next/static/chunks/867-b159f25612da5cbc.js +0 -1
- package/dist/web/_next/static/chunks/897-5a34109533c3da50.js +0 -1
- package/dist/web/_next/static/chunks/app/appearance/page-a18019cdc395de3d.js +0 -1
- package/dist/web/_next/static/chunks/app/defaults/page-614be29d185a2947.js +0 -1
- package/dist/web/_next/static/chunks/app/history/page-0bb537407fed5944.js +0 -1
- package/dist/web/_next/static/chunks/app/import/page-8ef75fc08638e75f.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-485ce9395cb17998.js +0 -1
- package/dist/web/_next/static/chunks/app/level1/page-dd3ebf37d29dce4f.js +0 -1
- package/dist/web/_next/static/chunks/app/page-3caf0b02046754a1.js +0 -1
- package/dist/web/_next/static/chunks/app/presets/page-93ab518db67e52a2.js +0 -1
- package/dist/web/_next/static/chunks/app/sessions/page-28376d2e4a9b4738.js +0 -1
- package/dist/web/_next/static/chunks/app/sessions/view/page-835d3533fdc63082.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-227a259e383ca2a0.js +0 -1
- package/dist/web/_next/static/css/ddb518572ea43e30.css +0 -1
- package/dist/web/_next/static/nLLy7-v8M5YRGIMtuTvMJ/_buildManifest.js +0 -1
- package/dist/web/history.html +0 -16
- package/dist/web/history.txt +0 -26
- package/dist/web/import.html +0 -16
- package/dist/web/import.txt +0 -26
- package/dist/web/sessions/view.html +0 -16
- package/dist/web/sessions/view.txt +0 -26
- package/dist/web/sessions.html +0 -16
- package/dist/web/sessions.txt +0 -26
- package/prompts/organisation.bg.md +0 -43
- package/prompts/organisation.en.md +0 -43
- package/prompts/persona.bg.md +0 -17
- package/prompts/persona.en.md +0 -17
- package/prompts/work.bg.md +0 -19
- package/prompts/work.en.md +0 -19
- /package/dist/web/_next/static/{nLLy7-v8M5YRGIMtuTvMJ → eqTUTH_SJtBgNgq8Zzy3n}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Pause" on the chat (operator, 2026-10-20: a "Pause" button that pauses the work on a task, and turns into
|
|
3
|
+
* "Continue" to go on when the operator sees fit).
|
|
4
|
+
*
|
|
5
|
+
* The task holds where it is. The reply being waited for is waited for and the command running runs to its end —
|
|
6
|
+
* neither can be held halfway — and then nothing more is sent to Copilot and no other command runs until the
|
|
7
|
+
* operator continues. Nothing ends: it is the same task, in the same conversation and the same browser window,
|
|
8
|
+
* after it, and the time it spent held does not count against `maxRunMinutes`.
|
|
9
|
+
*
|
|
10
|
+
* Not `RunDeps.shouldPause`, which holds a queue between tasks, after the task running has ended properly.
|
|
11
|
+
*/
|
|
12
|
+
export class Hold {
|
|
13
|
+
paused = false;
|
|
14
|
+
waiting = [];
|
|
15
|
+
/** Whether the operator has asked the task to hold. */
|
|
16
|
+
get held() {
|
|
17
|
+
return this.paused;
|
|
18
|
+
}
|
|
19
|
+
/** Asks the task to hold at its next message or command. False when it was held already. */
|
|
20
|
+
pause() {
|
|
21
|
+
if (this.paused)
|
|
22
|
+
return false;
|
|
23
|
+
this.paused = true;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/** Lets the task go on. False when it was not held. */
|
|
27
|
+
resume() {
|
|
28
|
+
if (!this.paused)
|
|
29
|
+
return false;
|
|
30
|
+
this.paused = false;
|
|
31
|
+
for (const go of this.waiting.splice(0))
|
|
32
|
+
go();
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/** Resolves at once when not held; otherwise when the operator continues, or the run is stopped. */
|
|
36
|
+
until(signal) {
|
|
37
|
+
if (!this.paused || signal?.aborted)
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const go = () => {
|
|
41
|
+
signal?.removeEventListener('abort', go);
|
|
42
|
+
this.waiting = this.waiting.filter((w) => w !== go);
|
|
43
|
+
resolve();
|
|
44
|
+
};
|
|
45
|
+
this.waiting.push(go);
|
|
46
|
+
signal?.addEventListener('abort', go, { once: true });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -14,7 +14,7 @@ import { createHash } from 'node:crypto';
|
|
|
14
14
|
import { readFile, mkdir, writeFile, appendFile } from 'node:fs/promises';
|
|
15
15
|
import { join, resolve } from 'node:path';
|
|
16
16
|
import { buttonShows, normModel } from '../transport/modelMatch.js';
|
|
17
|
-
import { createTransport, isReplyTimeout } from '../transport/chatTransport.js';
|
|
17
|
+
import { createTransport, isReplyTimeout, WindowClosed } from '../transport/chatTransport.js';
|
|
18
18
|
import { buildChatName, chatCode, loadPointer, savePointer } from '../transport/chatSession.js';
|
|
19
19
|
import { parseReply, formatErrorMessage, findLikelyDamage, damageGuidance } from '../protocol/parser.js';
|
|
20
20
|
import { resolveDeviations, describeDeviations, mergeDisputes, describeDisputes } from '../protocol/replySchema.js';
|
|
@@ -257,7 +257,35 @@ function sendsUntilStopped(transport, signal) {
|
|
|
257
257
|
return new Proxy(transport, {
|
|
258
258
|
get(target, key) {
|
|
259
259
|
if (key === 'sendAndConfirm') {
|
|
260
|
-
return (...args) => signal.aborted ? Promise.reject(new
|
|
260
|
+
return (...args) => signal.aborted ? Promise.reject(new StoppedSend()) : target.sendAndConfirm(...args);
|
|
261
|
+
}
|
|
262
|
+
const value = Reflect.get(target, key, target);
|
|
263
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/** A message not sent because the run was stopped first; the task it belongs to ends `aborted`. */
|
|
268
|
+
export class StoppedSend extends Error {
|
|
269
|
+
constructor() {
|
|
270
|
+
super('the run was stopped; nothing more is sent');
|
|
271
|
+
this.name = 'StoppedSend';
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The same chat, whose every message waits while the operator has paused the task ("Pause", 2026-10-20). The
|
|
276
|
+
* runner sends from a dozen places — the task, each round's report, format repairs, the plan, the review, the
|
|
277
|
+
* checks — and holding here holds all of them, the ones added later included. `hold` resolves true when the run
|
|
278
|
+
* was stopped while held: then nothing is sent.
|
|
279
|
+
*/
|
|
280
|
+
function holdsWhilePaused(transport, hold) {
|
|
281
|
+
return new Proxy(transport, {
|
|
282
|
+
get(target, key) {
|
|
283
|
+
if (key === 'sendAndConfirm') {
|
|
284
|
+
return async (...args) => {
|
|
285
|
+
if (await hold())
|
|
286
|
+
throw new StoppedSend();
|
|
287
|
+
return await target.sendAndConfirm(...args);
|
|
288
|
+
};
|
|
261
289
|
}
|
|
262
290
|
const value = Reflect.get(target, key, target);
|
|
263
291
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
@@ -308,10 +336,18 @@ class Sink {
|
|
|
308
336
|
* (live run 2026-10-04). `speakFor` moves it; the id it was opened under still hears every event.
|
|
309
337
|
*/
|
|
310
338
|
const speakers = new WeakMap();
|
|
311
|
-
|
|
339
|
+
/**
|
|
340
|
+
* `alone`: only that session hears it from now on, not the one it was opened under as well. For the chat's window
|
|
341
|
+
* (2026-10-19), which goes from one conversation to the next and belongs to none of them: a batch's window is opened
|
|
342
|
+
* under the batch, whose log is the run's, but the chat's is opened by whichever message came first.
|
|
343
|
+
*/
|
|
344
|
+
export function speakFor(transport, sessionId, opts = {}) {
|
|
312
345
|
const speaker = speakers.get(transport);
|
|
313
|
-
if (speaker)
|
|
314
|
-
|
|
346
|
+
if (!speaker)
|
|
347
|
+
return;
|
|
348
|
+
speaker.id = sessionId;
|
|
349
|
+
if (opts.alone)
|
|
350
|
+
speaker.alone = true;
|
|
315
351
|
}
|
|
316
352
|
export async function openBrowser(cfg, bus, transportDir, sessionId,
|
|
317
353
|
/** The run's Stop: a sign-in still awaited ends with it. */
|
|
@@ -336,8 +372,9 @@ signal) {
|
|
|
336
372
|
'error-banner': 'The chat reported a transient error; reloading the page.',
|
|
337
373
|
'reply-files-ignored': 'The reply came with a file attached. It was not downloaded and will not be run: the runner takes only the text of a reply.',
|
|
338
374
|
'model-menu-stuck': 'The model menu would not close — Escape, the menu button and a click outside all left it open. Close it in the Edge window; the run goes on.',
|
|
375
|
+
'window-closed': 'The Edge window was closed. A run in it stops; the next message opens a new one.',
|
|
339
376
|
};
|
|
340
|
-
for (const id of new Set([speaker.id, sessionId])) {
|
|
377
|
+
for (const id of new Set(speaker.alone ? [speaker.id] : [speaker.id, sessionId])) {
|
|
341
378
|
bus.publish({
|
|
342
379
|
sessionId: id,
|
|
343
380
|
type: `browser:${event}`,
|
|
@@ -363,8 +400,10 @@ signal) {
|
|
|
363
400
|
await transport.ensureSignedIn(undefined, { signal });
|
|
364
401
|
}
|
|
365
402
|
catch (e) {
|
|
403
|
+
const byHand = transport.closedOutside();
|
|
366
404
|
await transport.close().catch(() => undefined);
|
|
367
|
-
|
|
405
|
+
// Closed with its X while it opened or the sign-in was awaited: a stop, not a failure to start (2026-10-19).
|
|
406
|
+
throw byHand ? new WindowClosed() : e;
|
|
368
407
|
}
|
|
369
408
|
return transport;
|
|
370
409
|
}
|
|
@@ -501,10 +540,33 @@ async function joinGroupConversation(store, session, bus) {
|
|
|
501
540
|
});
|
|
502
541
|
return updated;
|
|
503
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Marks a run's failure as one of opening the browser, its profile, the sign-in or the conversation, so the notice of
|
|
545
|
+
* a start that could not begin says "opening the browser" rather than "the run" (2026-10-20: with the batch's own
|
|
546
|
+
* window gone, every chat start failed as "the run", the profile in use by another Edge included).
|
|
547
|
+
*/
|
|
548
|
+
export function failedOpening(e) {
|
|
549
|
+
if (e instanceof Error)
|
|
550
|
+
Object.assign(e, { openingBrowser: true });
|
|
551
|
+
return e;
|
|
552
|
+
}
|
|
553
|
+
/** Whether a run failed while opening the browser or entering the conversation (see `failedOpening`). */
|
|
554
|
+
export const failedWhileOpening = (e) => !!e?.openingBrowser;
|
|
504
555
|
/** The old shape, kept for the terminal path: open a browser and enter the conversation. */
|
|
505
556
|
export async function openSessionTransport(cfg, session, bus, runsDir, signal) {
|
|
506
557
|
const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id, signal);
|
|
507
|
-
|
|
558
|
+
/*
|
|
559
|
+
* Closed on any failure to enter the conversation, not only a conversation that will not reopen: the caller has no
|
|
560
|
+
* transport yet, so a page that would not load left the window open on the profile with nobody holding it.
|
|
561
|
+
*/
|
|
562
|
+
try {
|
|
563
|
+
await enterSessionConversation(transport, session, { closeOnFailure: true });
|
|
564
|
+
}
|
|
565
|
+
catch (e) {
|
|
566
|
+
const byHand = transport.closedOutside();
|
|
567
|
+
await transport.close().catch(() => undefined);
|
|
568
|
+
throw byHand ? new WindowClosed() : e;
|
|
569
|
+
}
|
|
508
570
|
return transport;
|
|
509
571
|
}
|
|
510
572
|
/**
|
|
@@ -835,7 +897,27 @@ export async function runTask(transport, session, task, deps) {
|
|
|
835
897
|
await store.updateTask(session.id, task.id, mutate);
|
|
836
898
|
};
|
|
837
899
|
const startedAt = Date.now();
|
|
838
|
-
|
|
900
|
+
/** Moved on by the time the operator held the task paused: the limit is on the work, not on the pause. */
|
|
901
|
+
let deadline = startedAt + cfg.limits.maxRunMinutes * 60_000;
|
|
902
|
+
/*
|
|
903
|
+
* "Pause" (operator, 2026-10-20; see `Hold`): every message to the chat waits here while the task is paused, and
|
|
904
|
+
* so does every command (the step loop below). True when the run was stopped while held.
|
|
905
|
+
*/
|
|
906
|
+
const holdHere = async (before) => {
|
|
907
|
+
const hold = deps.hold;
|
|
908
|
+
if (!hold?.held || signal?.aborted)
|
|
909
|
+
return false;
|
|
910
|
+
const from = Date.now();
|
|
911
|
+
sink.event('task-paused', { before }, before === 'message' ? 'paused by the operator: nothing more is sent to the chat until Continue' : 'paused by the operator: no other command runs until Continue');
|
|
912
|
+
await hold.until(signal);
|
|
913
|
+
const heldMs = Date.now() - from;
|
|
914
|
+
deadline += heldMs;
|
|
915
|
+
const stopped = !!signal?.aborted;
|
|
916
|
+
const secs = Math.round(heldMs / 1000);
|
|
917
|
+
sink.event('task-resumed', { before, heldMs, stopped }, stopped ? `stopped while paused, after ${secs} s` : `continued by the operator after ${secs} s paused; that time does not count against maxRunMinutes`);
|
|
918
|
+
return stopped;
|
|
919
|
+
};
|
|
920
|
+
transport = holdsWhilePaused(transport, () => holdHere('message'));
|
|
839
921
|
let iterations = 0;
|
|
840
922
|
/** What the model has declared it could not do as written, merged across every reply. */
|
|
841
923
|
let deviations = [];
|
|
@@ -1130,8 +1212,13 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1130
1212
|
* What the task said about the repository was written before the commit. When it did not end
|
|
1131
1213
|
* done and the runner then committed its changes, the reason says so, so "not committed, the
|
|
1132
1214
|
* tree is dirty" is not left standing beside a commit on the record.
|
|
1215
|
+
*
|
|
1216
|
+
* Against the record `commitTaskResult` was given, not the task as it was when it started: a chat message's
|
|
1217
|
+
* photograph after it is on the task by then (`vcs.commit`, on no branch), and every message of the chat that
|
|
1218
|
+
* did not end done said "the runner committed the task's changes as … on undefined", having committed nothing
|
|
1219
|
+
* (2026-10-19).
|
|
1133
1220
|
*/
|
|
1134
|
-
if (status !== 'done' && vcsAfter?.commit && vcsAfter.commit !== task.vcs?.commit) {
|
|
1221
|
+
if (status !== 'done' && vcsAfter?.commit && vcsAfter.commit !== (fresh ? fresh.vcs?.commit : task.vcs?.commit)) {
|
|
1135
1222
|
reason = sentences(reason, `After that, the runner committed the task's changes as ${vcsAfter.commit.slice(0, 8)} on ${vcsAfter.branch}` +
|
|
1136
1223
|
`${vcsAfter.afterCommit ? (vcsAfter.afterCommit.clean ? '; the working tree is clean' : `; still uncommitted: ${vcsAfter.afterCommit.changed.slice(0, 8).join(', ')}`) : ''}.`);
|
|
1137
1224
|
}
|
|
@@ -1540,7 +1627,7 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1540
1627
|
: undefined,
|
|
1541
1628
|
shellNote: shellNote(shells, defaultShell),
|
|
1542
1629
|
...(planning && planMode !== 'off'
|
|
1543
|
-
? { planNote: planModeNote(planMode, planEnforced, planMode === 'approve' && !!deps.approvePlan && (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm') }
|
|
1630
|
+
? { planNote: planModeNote(planMode, planEnforced, planMode === 'approve' && !!deps.approvePlan && (session.kind === 'chat' || (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm')) }
|
|
1544
1631
|
: {}),
|
|
1545
1632
|
// The operator's notes about this task not sent yet: they go out with this opening (2026-10-14).
|
|
1546
1633
|
...(openingNotes.length > 0 ? { operatorNotes: operatorNotesSection(openingNotes, false) } : {}),
|
|
@@ -2437,8 +2524,12 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2437
2524
|
});
|
|
2438
2525
|
await record(`PLAN ${planVersion}`, describePlan(plan));
|
|
2439
2526
|
sink.event('plan-received', { version: planVersion, steps: plan.steps.length, files: plan.files }, `plan ${planVersion} received: ${plan.steps.length} stage(s)${plan.files.length > 0 ? `, ${plan.files.length} file(s)` : ''}`);
|
|
2440
|
-
|
|
2441
|
-
|
|
2527
|
+
/*
|
|
2528
|
+
* Asked of the operator in a run that asks before each command: one that does not approves it itself. In the
|
|
2529
|
+
* workbench's chat always, as plan mode is there (2026-10-20: "a plan mode, as in Claude Code"): the operator
|
|
2530
|
+
* turned it on to see the plan before anything changes, whether the commands are then asked about or not.
|
|
2531
|
+
*/
|
|
2532
|
+
const asks = planMode === 'approve' && !!deps.approvePlan && (session.kind === 'chat' || (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm');
|
|
2442
2533
|
let answer = { decision: 'approve' };
|
|
2443
2534
|
if (asks) {
|
|
2444
2535
|
sink.event('plan-waiting', { version: planVersion }, `plan ${planVersion} is waiting for the operator`, 'warn');
|
|
@@ -2572,6 +2663,8 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2572
2663
|
*/
|
|
2573
2664
|
let refusedAt = null;
|
|
2574
2665
|
for (const step of reply.steps) {
|
|
2666
|
+
// Paused: no other command runs until Continue. Stopped while held, the Stop just below takes it.
|
|
2667
|
+
await holdHere('command');
|
|
2575
2668
|
if (signal?.aborted) {
|
|
2576
2669
|
results.push(refusedResult(step, 'stopped by the operator', 'operator'));
|
|
2577
2670
|
aborted = true;
|
|
@@ -2889,7 +2982,8 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2889
2982
|
* second copy under a reply in progress; this is the reply wait from the settings running
|
|
2890
2983
|
* out, which ends the task at that limit (see the catch at the end), not an upload to retry.
|
|
2891
2984
|
*/
|
|
2892
|
-
|
|
2985
|
+
// Nor is a window the operator closed, which no retry reaches.
|
|
2986
|
+
if (isReplyTimeout(e) || transport.closedOutside())
|
|
2893
2987
|
throw e;
|
|
2894
2988
|
sink.event('report-send-failed', { attempt, error: String(e) }, `sending the report failed (attempt ${attempt + 1}): ${e.message}`, 'warn');
|
|
2895
2989
|
if (attempt === cfg.report.uploadRetries) {
|
|
@@ -2918,6 +3012,11 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2918
3012
|
}
|
|
2919
3013
|
catch (e) {
|
|
2920
3014
|
const message = e.message;
|
|
3015
|
+
// Stopped before a message went out — while paused, or as the reviewer was about to send: nothing more was sent.
|
|
3016
|
+
if (e instanceof StoppedSend) {
|
|
3017
|
+
sink.event('task-stopped', {}, 'stopped by the operator; nothing more was sent');
|
|
3018
|
+
return await finish('aborted', 'stopped by the operator; nothing more was sent');
|
|
3019
|
+
}
|
|
2921
3020
|
/*
|
|
2922
3021
|
* The chat took longer than Settings allow for a reply. A limit, not a fault: the conversation
|
|
2923
3022
|
* and the work are where they were, and "Continue" carries the task on in that chat.
|
|
@@ -2927,6 +3026,15 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2927
3026
|
limitHit = { setting: 'replyTimeoutSec', value: e.seconds };
|
|
2928
3027
|
return await finish('limit-reached', `replyTimeoutSec (${e.seconds}) reached: ${message}`);
|
|
2929
3028
|
}
|
|
3029
|
+
/*
|
|
3030
|
+
* The operator closed the window with its X (2026-10-19: "the operator can close the browser with its X at any
|
|
3031
|
+
* moment"): what they did, said as a stop rather than as the error every call on a closed page gives. Unless
|
|
3032
|
+
* Edge left a crash report, which says it was not them.
|
|
3033
|
+
*/
|
|
3034
|
+
if (transport.closedOutside() && !(await transport.recentCrash().catch(() => null))) {
|
|
3035
|
+
sink.event('window-closed', { error: message }, 'the browser window was closed; nothing more is sent', 'warn');
|
|
3036
|
+
return await finish('aborted', 'the browser window was closed; nothing more was sent');
|
|
3037
|
+
}
|
|
2930
3038
|
sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
|
|
2931
3039
|
await transport.dumpFailure(log.path('failures'), 'crash').catch(() => undefined);
|
|
2932
3040
|
/*
|
|
@@ -2982,14 +3090,26 @@ export async function runSession(sessionId, deps) {
|
|
|
2982
3090
|
let paused = false;
|
|
2983
3091
|
try {
|
|
2984
3092
|
session = await joinGroupConversation(store, session, bus);
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
3093
|
+
try {
|
|
3094
|
+
if (borrowed) {
|
|
3095
|
+
speakFor(borrowed, session.id, { alone: !!deps.chatWindow });
|
|
3096
|
+
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' });
|
|
3097
|
+
if (deps.chatWindow) {
|
|
3098
|
+
await borrowed.clearNotice().catch(() => undefined);
|
|
3099
|
+
await borrowed.ensureSignedIn(undefined, { signal: deps.signal });
|
|
3100
|
+
}
|
|
3101
|
+
await enterSessionConversation(borrowed, session, { closeOnFailure: false });
|
|
3102
|
+
}
|
|
3103
|
+
else {
|
|
3104
|
+
await deps.beforeBrowser?.();
|
|
3105
|
+
// The chat's window outlives this message, so what it keeps goes where the batch's window keeps its own.
|
|
3106
|
+
transport = await openSessionTransport(cfg, session, bus, deps.chatWindow ? cfg.resolved.runsDir : sessionRunsDir, deps.signal);
|
|
3107
|
+
if (deps.chatWindow)
|
|
3108
|
+
speakFor(transport, session.id, { alone: true });
|
|
3109
|
+
}
|
|
2989
3110
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
transport = await openSessionTransport(cfg, session, bus, sessionRunsDir, deps.signal);
|
|
3111
|
+
catch (e) {
|
|
3112
|
+
throw failedOpening(e);
|
|
2993
3113
|
}
|
|
2994
3114
|
const chat = transport;
|
|
2995
3115
|
// The picker belongs to the conversation, so the session's choice is applied once, here,
|
|
@@ -3034,6 +3154,11 @@ export async function runSession(sessionId, deps) {
|
|
|
3034
3154
|
}
|
|
3035
3155
|
let outcome = await runTask(chat, session, task, deps);
|
|
3036
3156
|
ran += 1;
|
|
3157
|
+
// The operator closed the window with its X: a stop, for the tasks after it too (2026-10-19).
|
|
3158
|
+
if (chat.closedOutside()) {
|
|
3159
|
+
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed; the tasks after this one stay queued' });
|
|
3160
|
+
break;
|
|
3161
|
+
}
|
|
3037
3162
|
/*
|
|
3038
3163
|
* A blocked task is run again in a fresh conversation, up to the configured number of
|
|
3039
3164
|
* times, before the verdict stands.
|
|
@@ -3190,6 +3315,10 @@ export async function runSession(sessionId, deps) {
|
|
|
3190
3315
|
if (deps.signal?.aborted && ran === 0) {
|
|
3191
3316
|
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: `stopped by the operator before the first task was sent; the tasks stay queued (${e.message})` });
|
|
3192
3317
|
}
|
|
3318
|
+
else if ((e instanceof WindowClosed || transport?.closedOutside()) && ran === 0) {
|
|
3319
|
+
// Closed with its X while the chat was being opened, the sign-in awaited or the model chosen: a stop as well.
|
|
3320
|
+
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed before the first task was sent; the tasks stay queued' });
|
|
3321
|
+
}
|
|
3193
3322
|
else {
|
|
3194
3323
|
bus.publish({ sessionId, type: 'session-error', level: 'error', message: e.message });
|
|
3195
3324
|
throw e;
|
|
@@ -3197,8 +3326,13 @@ export async function runSession(sessionId, deps) {
|
|
|
3197
3326
|
}
|
|
3198
3327
|
finally {
|
|
3199
3328
|
// A borrowed window belongs to whoever opened it and stays open for the next session.
|
|
3200
|
-
if (!borrowed)
|
|
3201
|
-
|
|
3329
|
+
if (!borrowed) {
|
|
3330
|
+
// The chat's, still open, is kept for its next message; one the operator closed is let go of.
|
|
3331
|
+
if (deps.chatWindow && transport?.isOpen())
|
|
3332
|
+
deps.chatWindow.keep(transport);
|
|
3333
|
+
else
|
|
3334
|
+
await transport?.close();
|
|
3335
|
+
}
|
|
3202
3336
|
await store.updateSession(sessionId, (s) => {
|
|
3203
3337
|
s.status = 'idle';
|
|
3204
3338
|
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kerrigan (2026-10-20): the persona the operator may give to a chat of their own choosing — Microsoft Copilot,
|
|
3
|
+
* ChatGPT, another — so that chat knows what copilot-operator is and helps them write a task for it.
|
|
4
|
+
*
|
|
5
|
+
* Wished for, not required: the bot's own chat works the same without her, and nothing here is sent anywhere by the
|
|
6
|
+
* bot; the operator saves the text or copies it from the home screen. She replaced the plan persona that wrote JSON
|
|
7
|
+
* plans for the Sessions page, which went with it. What she says about the screen is the guide's own inventory of
|
|
8
|
+
* the workbench (`systemGuide.ts`), so the names she quotes are the names on the buttons, held to the dictionary by
|
|
9
|
+
* `test/guide.check.ts`; the numbers are this machine's settings at the moment the text is asked for.
|
|
10
|
+
*/
|
|
11
|
+
import { MAX_INSTRUCTION_CHARS } from '../session/model.js';
|
|
12
|
+
import { SYSTEM_GUIDE } from './systemGuide.js';
|
|
13
|
+
/** The screen the chat is on, as the guide describes it, in the persona's words. */
|
|
14
|
+
function screenGuide(lang) {
|
|
15
|
+
const bg = lang === 'bg';
|
|
16
|
+
const screen = SYSTEM_GUIDE.find((s) => s.route === '/');
|
|
17
|
+
if (!screen)
|
|
18
|
+
return '';
|
|
19
|
+
const lines = [];
|
|
20
|
+
for (const section of screen.sections) {
|
|
21
|
+
lines.push('');
|
|
22
|
+
lines.push(`**${bg ? section.bg : section.en}**`);
|
|
23
|
+
for (const c of section.controls)
|
|
24
|
+
lines.push(`- "${bg ? c.bg : c.en}" — ${bg ? c.doesBg : c.doesEn}`);
|
|
25
|
+
}
|
|
26
|
+
return lines.join('\n');
|
|
27
|
+
}
|
|
28
|
+
export function kerriganPersona(lang, facts) {
|
|
29
|
+
return lang === 'bg' ? bg(facts) : en(facts);
|
|
30
|
+
}
|
|
31
|
+
export function kerriganFileName(lang) {
|
|
32
|
+
return `kerrigan-copilot-operator.${lang}.md`;
|
|
33
|
+
}
|
|
34
|
+
function en(f) {
|
|
35
|
+
return `# Kerrigan — a helper for writing tasks for copilot-operator
|
|
36
|
+
|
|
37
|
+
You are **Kerrigan**. You help the person talking to you write tasks for **copilot-operator** (version ${f.version}), a program on their Windows machine. You do not run anything and you cannot see their screen or their files: you know what they tell you, and what is written here. Keep to the language they write in.
|
|
38
|
+
|
|
39
|
+
## What copilot-operator is
|
|
40
|
+
|
|
41
|
+
- It is a local program with a chat of its own (the "workbench", opened in the browser at the address it prints). The person writes a task in that chat, about the **project folder** that is open there.
|
|
42
|
+
- The program sends the task to **Microsoft 365 Copilot** (a work account) in an Edge window it opens and keeps open. Copilot cannot touch the machine itself: it answers with **PowerShell commands**, in a fixed JSON form.
|
|
43
|
+
- copilot-operator **runs those commands on the machine, in the project folder**, and sends what they printed back to Copilot. Round after round, until Copilot says the task is **done** (with a summary of what it did), or **blocked** (with what it tried and what it needs), or a limit is reached.
|
|
44
|
+
- Copilot learns the project only through those commands: it lists files, reads them, runs the build and the tests. It is not sent the files themselves, and it does not know anything about the project that the task does not say and the commands cannot find.
|
|
45
|
+
- The person chooses how commands run: **"Ask before each command"** (they press **"Run"**, **"Run this and the rest"** or **"Skip"**) or **"Run commands without asking"**. A list of forbidden commands applies either way; pushing to a remote is refused; nothing needs administrator rights.
|
|
46
|
+
- Limits from the settings: at most ${f.maxIterations} messages to Copilot and ${f.maxRunMinutes} minutes per task, carried on by itself up to ${f.autoContinue} time(s) when a limit is reached. One message in the chat can be at most ${MAX_INSTRUCTION_CHARS.toLocaleString('en')} characters.
|
|
47
|
+
- Each message is one task. The next message goes into the **same Copilot conversation**, so it can build on what was done ("now add tests for that"). **"New chat"** starts a conversation with nothing of the earlier one. Before each message the folder is photographed, and with **"Go back to before this message"** the folder is put back exactly as it was then.
|
|
48
|
+
- **"Plan mode"** (a choice under the chat's box): Copilot first looks at the project with read-only commands and proposes a plan — what is there, how it means to do it, the stages, the files, how it will show it works — and nothing is changed until the person approves the plan, asks for another, or stops.
|
|
49
|
+
- While it works, a message written in the chat is added to what it is doing, and Copilot gets it with its next report. **"Stop"** stops it.
|
|
50
|
+
|
|
51
|
+
## How you help
|
|
52
|
+
|
|
53
|
+
1. Ask what they want to achieve, in their words. If something essential is missing — which folder or files, what "done" means, how to check it — ask for it before you write the task. Do not invent paths, names or commands you were not told.
|
|
54
|
+
2. Write the task as **one message, ready to paste** into copilot-operator's chat, in a fenced block, under ${MAX_INSTRUCTION_CHARS.toLocaleString('en')} characters. One goal per message; if the work is large, give a short series of messages to send one after another, each waiting for the one before to finish.
|
|
55
|
+
3. A good task says:
|
|
56
|
+
- **Goal** — what should be true when it is done, in one or two sentences.
|
|
57
|
+
- **Where** — the files and folders, as paths from the project's root; what already exists that it should use or follow.
|
|
58
|
+
- **What to do** — the steps, when the order matters; the decisions already made (library, style, approach).
|
|
59
|
+
- **Done when** — how to show it works: the command to run (build, tests, a script) and what it should print; the files that should exist and what they should hold.
|
|
60
|
+
- **Leave alone** — what must not change: files, public interfaces, dependencies (no new ones unless asked), formatting of untouched code.
|
|
61
|
+
- **Context Copilot cannot discover** — business rules, error messages copied word for word, the version of the tools, why something is the way it is.
|
|
62
|
+
4. Never put passwords, tokens, keys or personal data in a task. If a command needs a secret, say where the program should read it from (an environment variable, a file that is already there) — not the secret.
|
|
63
|
+
5. The commands run in **PowerShell on Windows**. Say so when a task names commands, and prefer what is already installed on the machine; a step that downloads something from the network is asked about before it runs.
|
|
64
|
+
6. Suggest **"Plan mode"** for a change that touches several files or that the person wants to see planned first, and **"Ask before each command"** when they want to watch every step.
|
|
65
|
+
7. When a task ended **blocked** or **at a limit**, help write the next message: what Copilot said it tried and needs, what the person can now tell it, or a smaller step. When it went wrong, the person can go back to before that message and send a better one.
|
|
66
|
+
|
|
67
|
+
## The chat's screen, and what everything on it is called
|
|
68
|
+
${screenGuide('en')}
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
function bg(f) {
|
|
72
|
+
return `# Кериган — помощник за писане на задания за copilot-operator
|
|
73
|
+
|
|
74
|
+
Ти си **Кериган**. Помагаш на човека, който ти пише, да напише задания за **copilot-operator** (версия ${f.version}) — програма на неговата машина с Windows. Ти не изпълняваш нищо и не виждаш екрана или файловете му: знаеш това, което ти каже, и написаното тук. Пиши на езика, на който ти пише.
|
|
75
|
+
|
|
76
|
+
## Какво е copilot-operator
|
|
77
|
+
|
|
78
|
+
- Локална програма със собствен чат (работната среда, отворена в браузъра на адреса, който програмата изписва). Човекът пише задание в този чат, за **папката на проекта**, отворена там.
|
|
79
|
+
- Програмата изпраща заданието на **Microsoft 365 Copilot** (служебен акаунт) в прозорец на Edge, който отваря и държи отворен. Copilot не може сам да пипа машината: отговаря с **команди на PowerShell**, в определен вид JSON.
|
|
80
|
+
- copilot-operator **изпълнява тези команди на машината, в папката на проекта**, и връща на Copilot какво са изписали. Кръг след кръг, докато Copilot каже, че заданието е **готово** (с обобщение на направеното), или **блокирано** (с какво е опитал и какво му трябва), или се стигне ограничение.
|
|
81
|
+
- Copilot опознава проекта само чрез тези команди: изброява файлове, чете ги, пуска компилацията и тестовете. Самите файлове не му се изпращат и той не знае за проекта нищо, което заданието не казва и командите не могат да намерят.
|
|
82
|
+
- Човекът избира как се изпълняват командите: **„Питай преди всяка команда“** (натиска **„Изпълни“**, **„Изпълни тази и останалите“** или **„Пропусни“**) или **„Изпълнявай командите без питане“**. И в двата случая важи списък със забранени команди; изпращането към отдалечено хранилище (push) се отказва; нищо не изисква администраторски права.
|
|
83
|
+
- Ограничения от настройките: най-много ${f.maxIterations} съобщения към Copilot и ${f.maxRunMinutes} минути на задание, продължено само до ${f.autoContinue} път(и), когато се стигне ограничение. Едно съобщение в чата може да е най-много ${MAX_INSTRUCTION_CHARS.toLocaleString('bg')} знака.
|
|
84
|
+
- Всяко съобщение е едно задание. Следващото съобщение отива в **същия разговор в Copilot**, така че може да надгражда („сега добави тестове за това“). **„Нов чат“** започва разговор без нищо от предишния. Преди всяко съобщение папката се „снима“ и с **„Върни отпреди това съобщение“** папката се връща точно каквато е била тогава.
|
|
85
|
+
- **„Режим на план“** (избор под полето на чата): Copilot първо разглежда проекта само с команди, които четат, и предлага план — какво има, как смята да го направи, етапите, файловете, как ще покаже, че работи, — и нищо не се променя, докато човекът не одобри плана, не поиска друг или не спре.
|
|
86
|
+
- Докато работи, съобщение, написано в чата, се добавя към това, което прави, и Copilot го получава със следващия си отчет. **„Спри“** го спира.
|
|
87
|
+
|
|
88
|
+
## Как помагаш
|
|
89
|
+
|
|
90
|
+
1. Питай какво иска да постигне, с неговите думи. Ако липсва нещо съществено — коя папка или кои файлове, какво значи „готово“, как да се провери, — попитай, преди да напишеш заданието. Не измисляй пътища, имена или команди, които не са ти казани.
|
|
91
|
+
2. Напиши заданието като **едно съобщение, готово за поставяне** в чата на copilot-operator, в отделен блок, под ${MAX_INSTRUCTION_CHARS.toLocaleString('bg')} знака. Една цел на съобщение; ако работата е голяма, дай кратка поредица от съобщения, които да се изпращат едно след друго, всяко след като предишното е свършило.
|
|
92
|
+
3. Доброто задание казва:
|
|
93
|
+
- **Цел** — какво трябва да е вярно, когато е готово, в едно-две изречения.
|
|
94
|
+
- **Къде** — файловете и папките, като пътища от корена на проекта; какво вече има, което трябва да се използва или следва.
|
|
95
|
+
- **Какво да се направи** — стъпките, когато редът има значение; вече взетите решения (библиотека, стил, подход).
|
|
96
|
+
- **Готово е, когато** — как да се покаже, че работи: командата за пускане (компилация, тестове, скрипт) и какво трябва да изпише; файловете, които трябва да съществуват, и какво да съдържат.
|
|
97
|
+
- **Да не се пипа** — какво не трябва да се променя: файлове, публични интерфейси, зависимости (без нови, освен ако не е поискано), форматирането на непипан код.
|
|
98
|
+
- **Контекст, който Copilot не може да открие** — бизнес правила, съобщения за грешки, копирани дума по дума, версиите на инструментите, защо нещо е такова, каквото е.
|
|
99
|
+
4. Никога не слагай в заданието пароли, токени, ключове или лични данни. Ако команда има нужда от тайна, кажи откъде програмата да я прочете (променлива на средата, файл, който вече е там) — не самата тайна.
|
|
100
|
+
5. Командите се изпълняват в **PowerShell под Windows**. Кажи го, когато заданието посочва команди, и предпочитай това, което вече е инсталирано на машината; стъпка, която тегли нещо от мрежата, се пита, преди да се изпълни.
|
|
101
|
+
6. Предлагай **„Режим на план“** за промяна, която пипа няколко файла или която човекът иска първо да види планирана, и **„Питай преди всяка команда“**, когато иска да следи всяка стъпка.
|
|
102
|
+
7. Когато задание е завършило **блокирано** или **при ограничение**, помогни да се напише следващото съобщение: какво Copilot е казал, че е опитал и му трябва, какво човекът може да му каже сега, или по-малка стъпка. Когато нещо е тръгнало зле, човекът може да се върне отпреди това съобщение и да изпрати по-добро.
|
|
103
|
+
|
|
104
|
+
## Екранът на чата и как се казва всичко по него
|
|
105
|
+
${screenGuide('bg')}
|
|
106
|
+
`;
|
|
107
|
+
}
|