copilot-operator 0.1.50 → 0.1.52
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 +587 -574
- package/dist/src/api/operator.controller.js +119 -1023
- package/dist/src/api/operator.service.js +346 -2553
- package/dist/src/config/schema.js +13 -0
- package/dist/src/orchestrator/hold.js +49 -0
- package/dist/src/orchestrator/leadRunner.js +559 -0
- package/dist/src/orchestrator/taskRunner.js +211 -39
- package/dist/src/plan/kerrigan.js +232 -0
- package/dist/src/plan/systemGuide.js +758 -3757
- package/dist/src/protocol/leadSchema.js +156 -0
- package/dist/src/protocol/parser.js +1 -1
- package/dist/src/session/chatNotice.js +191 -0
- package/dist/src/session/checkpoint.js +19 -0
- package/dist/src/session/compose.js +1 -1
- package/dist/src/session/store.js +17 -126
- package/dist/src/session/workspace.js +52 -5
- package/dist/src/transport/chatTransport.js +1 -1
- package/dist/src/transport/copilotTransport.js +135 -1
- package/dist/web/404.html +13 -16
- package/dist/web/_next/static/_1zhoDsMOPAH2xW702E5A/_buildManifest.js +1 -0
- package/dist/web/_next/static/chunks/134-ddd50a7fbb536ec8.js +1 -0
- package/dist/web/_next/static/chunks/163.dbd7d36584d0bb37.js +1 -0
- package/dist/web/_next/static/chunks/220.35531b39410e1a9f.js +1 -0
- package/dist/web/_next/static/chunks/548.71ac96c94136659b.js +1 -0
- package/dist/web/_next/static/chunks/584.6df695c5b86a75aa.js +1 -0
- package/dist/web/_next/static/chunks/67.9ed79e2fbfb56f26.js +1 -0
- package/dist/web/_next/static/chunks/714.1e2338736a70b9c7.js +1 -0
- package/dist/web/_next/static/chunks/747.d2c1249d736dc03b.js +1 -0
- package/dist/web/_next/static/chunks/77.a200abef0f5b4a7f.js +1 -0
- package/dist/web/_next/static/chunks/808-bc7d7eac6d823291.js +1 -0
- package/dist/web/_next/static/chunks/921-dc5538cd779c6432.js +1 -0
- package/dist/web/_next/static/chunks/app/defaults/page-edd7534ca9ecf366.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-8f99a164d76897a0.js +1 -0
- package/dist/web/_next/static/chunks/app/page-4bed816eda370d0c.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-1cf9e75e76da59ed.js +1 -0
- package/dist/web/_next/static/chunks/webpack-77147e31d2125631.js +1 -0
- package/dist/web/_next/static/css/3bea264adc472bc8.css +1 -0
- package/dist/web/defaults.html +13 -16
- package/dist/web/defaults.txt +22 -23
- package/dist/web/index.html +13 -16
- package/dist/web/index.txt +22 -23
- package/dist/web/system.html +13 -16
- package/dist/web/system.txt +22 -23
- package/package.json +5 -23
- package/prompts/lead1.md +116 -0
- 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/prepareFromRemote.js +0 -288
- package/dist/src/vcs/remoteAuth.js +0 -117
- package/dist/src/vcs/startChoice.js +0 -367
- package/dist/src/vcs/syncCommand.js +0 -97
- 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/534-56c68930a1a3c10f.js +0 -1
- package/dist/web/_next/static/chunks/549-c32dd718a1809d4d.js +0 -1
- package/dist/web/_next/static/chunks/699-9d031f8c145a0465.js +0 -1
- package/dist/web/_next/static/chunks/867-0e5d0d5472bf185f.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-95bab4c1b1ff9339.js +0 -1
- package/dist/web/_next/static/chunks/app/import/page-8ef75fc08638e75f.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-a1314921eeba8ad5.js +0 -1
- package/dist/web/_next/static/chunks/app/level1/page-dd3ebf37d29dce4f.js +0 -1
- package/dist/web/_next/static/chunks/app/page-4d8f0851fe672925.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-adb64f8ba3d8c06e.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-227a259e383ca2a0.js +0 -1
- package/dist/web/_next/static/chunks/webpack-0f31b926d9a9c5a4.js +0 -1
- package/dist/web/_next/static/css/4335e4ce269ba1ea.css +0 -1
- package/dist/web/_next/static/z74_FBfnnXW5IJCHTgTH2/_buildManifest.js +0 -1
- package/dist/web/appearance.html +0 -16
- package/dist/web/appearance.txt +0 -26
- 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/level1.html +0 -16
- package/dist/web/level1.txt +0 -26
- package/dist/web/presets.html +0 -19
- package/dist/web/presets.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/{z74_FBfnnXW5IJCHTgTH2 → _1zhoDsMOPAH2xW702E5A}/_ssgManifest.js +0 -0
|
@@ -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';
|
|
@@ -40,7 +40,7 @@ import { writeReport } from '../exec/reportFile.js';
|
|
|
40
40
|
import { Pacer } from '../util/pacing.js';
|
|
41
41
|
import { RunLog } from '../log/runLog.js';
|
|
42
42
|
import { composeOpening, operatorNotesSection, readOnlyNote } from '../session/compose.js';
|
|
43
|
-
import { takeAfter, takeCheckpoint } from '../session/checkpoint.js';
|
|
43
|
+
import { changedSince, takeAfter, takeCheckpoint } from '../session/checkpoint.js';
|
|
44
44
|
import { MIN_TRIED_APPROACHES } from '../protocol/replySchema.js';
|
|
45
45
|
import { enforceScope, scopeMessage, scopeNote } from '../vcs/scope.js';
|
|
46
46
|
import { PLAN_FIRST, PLAN_NOT_NOW, PLAN_NUDGE_AFTER, describePlan, planApprovedMessage, planFrom, planModeNote, planNudge, planReviseMessage } from './planMode.js';
|
|
@@ -53,6 +53,7 @@ import { prepareForTask, commitTaskResult, commitShortfall, repoDirOf, trackedRe
|
|
|
53
53
|
import { protectInputs, inputsMessage, inputsAtCommit, untrackedInputs, blobOfFile } from '../vcs/inputs.js';
|
|
54
54
|
import { artifactPatterns, artifactState, keepArtifacts } from '../vcs/artifacts.js';
|
|
55
55
|
import { exportMachine, writeAttemptRecord } from '../session/exports.js';
|
|
56
|
+
import { runLeadTask } from './leadRunner.js';
|
|
56
57
|
/**
|
|
57
58
|
* Causes no conversation can change: the task contradicts itself, the machine lacks what a step needs,
|
|
58
59
|
* a check can never run. A fresh chat is no cure for these, and retrying them in one only repeats the
|
|
@@ -257,7 +258,35 @@ function sendsUntilStopped(transport, signal) {
|
|
|
257
258
|
return new Proxy(transport, {
|
|
258
259
|
get(target, key) {
|
|
259
260
|
if (key === 'sendAndConfirm') {
|
|
260
|
-
return (...args) => signal.aborted ? Promise.reject(new
|
|
261
|
+
return (...args) => signal.aborted ? Promise.reject(new StoppedSend()) : target.sendAndConfirm(...args);
|
|
262
|
+
}
|
|
263
|
+
const value = Reflect.get(target, key, target);
|
|
264
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/** A message not sent because the run was stopped first; the task it belongs to ends `aborted`. */
|
|
269
|
+
export class StoppedSend extends Error {
|
|
270
|
+
constructor() {
|
|
271
|
+
super('the run was stopped; nothing more is sent');
|
|
272
|
+
this.name = 'StoppedSend';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The same chat, whose every message waits while the operator has paused the task ("Pause", 2026-10-20). The
|
|
277
|
+
* runner sends from a dozen places — the task, each round's report, format repairs, the plan, the review, the
|
|
278
|
+
* checks — and holding here holds all of them, the ones added later included. `hold` resolves true when the run
|
|
279
|
+
* was stopped while held: then nothing is sent.
|
|
280
|
+
*/
|
|
281
|
+
export function holdsWhilePaused(transport, hold) {
|
|
282
|
+
return new Proxy(transport, {
|
|
283
|
+
get(target, key) {
|
|
284
|
+
if (key === 'sendAndConfirm') {
|
|
285
|
+
return async (...args) => {
|
|
286
|
+
if (await hold())
|
|
287
|
+
throw new StoppedSend();
|
|
288
|
+
return await target.sendAndConfirm(...args);
|
|
289
|
+
};
|
|
261
290
|
}
|
|
262
291
|
const value = Reflect.get(target, key, target);
|
|
263
292
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
@@ -265,7 +294,7 @@ function sendsUntilStopped(transport, signal) {
|
|
|
265
294
|
});
|
|
266
295
|
}
|
|
267
296
|
/** One place that writes to the transcript, the console and the live stream at once. */
|
|
268
|
-
class Sink {
|
|
297
|
+
export class Sink {
|
|
269
298
|
log;
|
|
270
299
|
bus;
|
|
271
300
|
sessionId;
|
|
@@ -308,10 +337,18 @@ class Sink {
|
|
|
308
337
|
* (live run 2026-10-04). `speakFor` moves it; the id it was opened under still hears every event.
|
|
309
338
|
*/
|
|
310
339
|
const speakers = new WeakMap();
|
|
311
|
-
|
|
340
|
+
/**
|
|
341
|
+
* `alone`: only that session hears it from now on, not the one it was opened under as well. For the chat's window
|
|
342
|
+
* (2026-10-19), which goes from one conversation to the next and belongs to none of them: a batch's window is opened
|
|
343
|
+
* under the batch, whose log is the run's, but the chat's is opened by whichever message came first.
|
|
344
|
+
*/
|
|
345
|
+
export function speakFor(transport, sessionId, opts = {}) {
|
|
312
346
|
const speaker = speakers.get(transport);
|
|
313
|
-
if (speaker)
|
|
314
|
-
|
|
347
|
+
if (!speaker)
|
|
348
|
+
return;
|
|
349
|
+
speaker.id = sessionId;
|
|
350
|
+
if (opts.alone)
|
|
351
|
+
speaker.alone = true;
|
|
315
352
|
}
|
|
316
353
|
export async function openBrowser(cfg, bus, transportDir, sessionId,
|
|
317
354
|
/** The run's Stop: a sign-in still awaited ends with it. */
|
|
@@ -336,8 +373,9 @@ signal) {
|
|
|
336
373
|
'error-banner': 'The chat reported a transient error; reloading the page.',
|
|
337
374
|
'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
375
|
'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.',
|
|
376
|
+
'window-closed': 'The Edge window was closed. A run in it stops; the next message opens a new one.',
|
|
339
377
|
};
|
|
340
|
-
for (const id of new Set([speaker.id, sessionId])) {
|
|
378
|
+
for (const id of new Set(speaker.alone ? [speaker.id] : [speaker.id, sessionId])) {
|
|
341
379
|
bus.publish({
|
|
342
380
|
sessionId: id,
|
|
343
381
|
type: `browser:${event}`,
|
|
@@ -363,8 +401,10 @@ signal) {
|
|
|
363
401
|
await transport.ensureSignedIn(undefined, { signal });
|
|
364
402
|
}
|
|
365
403
|
catch (e) {
|
|
404
|
+
const byHand = transport.closedOutside();
|
|
366
405
|
await transport.close().catch(() => undefined);
|
|
367
|
-
|
|
406
|
+
// Closed with its X while it opened or the sign-in was awaited: a stop, not a failure to start (2026-10-19).
|
|
407
|
+
throw byHand ? new WindowClosed() : e;
|
|
368
408
|
}
|
|
369
409
|
return transport;
|
|
370
410
|
}
|
|
@@ -501,10 +541,37 @@ async function joinGroupConversation(store, session, bus) {
|
|
|
501
541
|
});
|
|
502
542
|
return updated;
|
|
503
543
|
}
|
|
544
|
+
/** Which conversation of the two-chat mode a session's is, for the cards that ask about its model (2026-10-20). */
|
|
545
|
+
export function roleOf(session) {
|
|
546
|
+
return session.workerOf ? { role: 'worker' } : session.lead ? { role: 'lead' } : {};
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Marks a run's failure as one of opening the browser, its profile, the sign-in or the conversation, so the notice of
|
|
550
|
+
* a start that could not begin says "opening the browser" rather than "the run" (2026-10-20: with the batch's own
|
|
551
|
+
* window gone, every chat start failed as "the run", the profile in use by another Edge included).
|
|
552
|
+
*/
|
|
553
|
+
export function failedOpening(e) {
|
|
554
|
+
if (e instanceof Error)
|
|
555
|
+
Object.assign(e, { openingBrowser: true });
|
|
556
|
+
return e;
|
|
557
|
+
}
|
|
558
|
+
/** Whether a run failed while opening the browser or entering the conversation (see `failedOpening`). */
|
|
559
|
+
export const failedWhileOpening = (e) => !!e?.openingBrowser;
|
|
504
560
|
/** The old shape, kept for the terminal path: open a browser and enter the conversation. */
|
|
505
561
|
export async function openSessionTransport(cfg, session, bus, runsDir, signal) {
|
|
506
562
|
const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id, signal);
|
|
507
|
-
|
|
563
|
+
/*
|
|
564
|
+
* Closed on any failure to enter the conversation, not only a conversation that will not reopen: the caller has no
|
|
565
|
+
* transport yet, so a page that would not load left the window open on the profile with nobody holding it.
|
|
566
|
+
*/
|
|
567
|
+
try {
|
|
568
|
+
await enterSessionConversation(transport, session, { closeOnFailure: true });
|
|
569
|
+
}
|
|
570
|
+
catch (e) {
|
|
571
|
+
const byHand = transport.closedOutside();
|
|
572
|
+
await transport.close().catch(() => undefined);
|
|
573
|
+
throw byHand ? new WindowClosed() : e;
|
|
574
|
+
}
|
|
508
575
|
return transport;
|
|
509
576
|
}
|
|
510
577
|
/**
|
|
@@ -546,7 +613,7 @@ export function modelByHand(session, cfg) {
|
|
|
546
613
|
return true;
|
|
547
614
|
return session.kind === 'chat' && !effectiveModels(session, cfg).model;
|
|
548
615
|
}
|
|
549
|
-
async function applySessionModel(transport, session, bus, cfg, store, hooks,
|
|
616
|
+
export async function applySessionModel(transport, session, bus, cfg, store, hooks,
|
|
550
617
|
/** Whether the conversation was opened new for this run, rather than one the session already had. */
|
|
551
618
|
fresh = true,
|
|
552
619
|
/** The run's Stop: the picker's waits end with it, and nothing is sent. */
|
|
@@ -582,7 +649,7 @@ signal) {
|
|
|
582
649
|
const why = cfg.copilot.manualModel ? 'Settings ask for the model to be chosen by hand' : 'the session asks for the model to be set by hand';
|
|
583
650
|
const hand = wanted && buttonShows(shown, wanted)
|
|
584
651
|
? { result: { ok: true, current: wanted, by: 'already' }, goOnAsItIs: false }
|
|
585
|
-
: await withOperatorHand(transport, wanted, { ok: false, current: shown, reason: why }, hooks, session.id, bus, true);
|
|
652
|
+
: await withOperatorHand(transport, wanted, { ok: false, current: shown, reason: why }, hooks, session.id, bus, true, roleOf(session));
|
|
586
653
|
if (!wanted) {
|
|
587
654
|
const now = await transport.currentModel().catch(() => null);
|
|
588
655
|
if (hand.result.ok || hand.goOnAsItIs) {
|
|
@@ -670,16 +737,20 @@ signal) {
|
|
|
670
737
|
* choose it in the Copilot window; "check and go on" reads the picker button again, and asks again while it
|
|
671
738
|
* still shows another model. With no model asked for, whatever the operator chose is taken.
|
|
672
739
|
*/
|
|
673
|
-
async function withOperatorHand(transport, wanted, first, hooks, sessionId, bus, manual
|
|
740
|
+
async function withOperatorHand(transport, wanted, first, hooks, sessionId, bus, manual,
|
|
741
|
+
/** For the review's own conversation: the card says so, and why its model is best another, stronger one. For the
|
|
742
|
+
* lead's or the worker's conversation of the two-chat mode: the card says which it is (2026-10-20). */
|
|
743
|
+
opts = {}) {
|
|
674
744
|
let result = first;
|
|
675
745
|
for (let tries = 1; !result.ok && hooks?.askHelp; tries += 1) {
|
|
676
746
|
const shown = await transport.currentModel().catch(() => null);
|
|
747
|
+
const what = `${wanted ? `"${wanted}"` : 'the model'}${opts.review ? ' for the review' : opts.role ? ` for the ${opts.role}` : ''}`;
|
|
677
748
|
bus.publish({ sessionId, type: 'model-help-asked', level: 'warn',
|
|
678
749
|
message: manual
|
|
679
|
-
? `asking the operator to choose ${
|
|
680
|
-
: `the chat could not be put on
|
|
681
|
-
data: { asked: wanted, shown, why: result.reason ?? '', tries, manual } });
|
|
682
|
-
const answer = await hooks.askHelp({ sessionId, asked: wanted, shown, why: result.reason ?? 'unknown reason', tries, ...(manual ? { manual: true } : {}) });
|
|
750
|
+
? `asking the operator to choose ${what} in the Copilot window (by hand; picker shows "${shown ?? 'nothing'}")`
|
|
751
|
+
: `the chat could not be put on ${what} by the runner; asking the operator to choose it in the Copilot window (picker shows "${shown ?? 'nothing'}")`,
|
|
752
|
+
data: { asked: wanted, shown, why: result.reason ?? '', tries, manual, ...(opts.review ? { review: true } : {}), ...(opts.role ? { role: opts.role } : {}) } });
|
|
753
|
+
const answer = await hooks.askHelp({ sessionId, asked: wanted, shown, why: result.reason ?? 'unknown reason', tries, ...(manual ? { manual: true } : {}), ...(opts.review ? { review: true } : {}), ...(opts.role ? { role: opts.role } : {}) });
|
|
683
754
|
if (answer === 'stop')
|
|
684
755
|
return { result, goOnAsItIs: false };
|
|
685
756
|
if (answer === 'continue') {
|
|
@@ -835,7 +906,27 @@ export async function runTask(transport, session, task, deps) {
|
|
|
835
906
|
await store.updateTask(session.id, task.id, mutate);
|
|
836
907
|
};
|
|
837
908
|
const startedAt = Date.now();
|
|
838
|
-
|
|
909
|
+
/** Moved on by the time the operator held the task paused: the limit is on the work, not on the pause. */
|
|
910
|
+
let deadline = startedAt + cfg.limits.maxRunMinutes * 60_000;
|
|
911
|
+
/*
|
|
912
|
+
* "Pause" (operator, 2026-10-20; see `Hold`): every message to the chat waits here while the task is paused, and
|
|
913
|
+
* so does every command (the step loop below). True when the run was stopped while held.
|
|
914
|
+
*/
|
|
915
|
+
const holdHere = async (before) => {
|
|
916
|
+
const hold = deps.hold;
|
|
917
|
+
if (!hold?.held || signal?.aborted)
|
|
918
|
+
return false;
|
|
919
|
+
const from = Date.now();
|
|
920
|
+
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');
|
|
921
|
+
await hold.until(signal);
|
|
922
|
+
const heldMs = Date.now() - from;
|
|
923
|
+
deadline += heldMs;
|
|
924
|
+
const stopped = !!signal?.aborted;
|
|
925
|
+
const secs = Math.round(heldMs / 1000);
|
|
926
|
+
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`);
|
|
927
|
+
return stopped;
|
|
928
|
+
};
|
|
929
|
+
transport = holdsWhilePaused(transport, () => holdHere('message'));
|
|
839
930
|
let iterations = 0;
|
|
840
931
|
/** What the model has declared it could not do as written, merged across every reply. */
|
|
841
932
|
let deviations = [];
|
|
@@ -1130,8 +1221,13 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1130
1221
|
* What the task said about the repository was written before the commit. When it did not end
|
|
1131
1222
|
* done and the runner then committed its changes, the reason says so, so "not committed, the
|
|
1132
1223
|
* tree is dirty" is not left standing beside a commit on the record.
|
|
1224
|
+
*
|
|
1225
|
+
* Against the record `commitTaskResult` was given, not the task as it was when it started: a chat message's
|
|
1226
|
+
* photograph after it is on the task by then (`vcs.commit`, on no branch), and every message of the chat that
|
|
1227
|
+
* did not end done said "the runner committed the task's changes as … on undefined", having committed nothing
|
|
1228
|
+
* (2026-10-19).
|
|
1133
1229
|
*/
|
|
1134
|
-
if (status !== 'done' && vcsAfter?.commit && vcsAfter.commit !== task.vcs?.commit) {
|
|
1230
|
+
if (status !== 'done' && vcsAfter?.commit && vcsAfter.commit !== (fresh ? fresh.vcs?.commit : task.vcs?.commit)) {
|
|
1135
1231
|
reason = sentences(reason, `After that, the runner committed the task's changes as ${vcsAfter.commit.slice(0, 8)} on ${vcsAfter.branch}` +
|
|
1136
1232
|
`${vcsAfter.afterCommit ? (vcsAfter.afterCommit.clean ? '; the working tree is clean' : `; still uncommitted: ${vcsAfter.afterCommit.changed.slice(0, 8).join(', ')}`) : ''}.`);
|
|
1137
1233
|
}
|
|
@@ -1540,7 +1636,7 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1540
1636
|
: undefined,
|
|
1541
1637
|
shellNote: shellNote(shells, defaultShell),
|
|
1542
1638
|
...(planning && planMode !== 'off'
|
|
1543
|
-
? { planNote: planModeNote(planMode, planEnforced, planMode === 'approve' && !!deps.approvePlan && (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm') }
|
|
1639
|
+
? { planNote: planModeNote(planMode, planEnforced, planMode === 'approve' && !!deps.approvePlan && (session.kind === 'chat' || (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm')) }
|
|
1544
1640
|
: {}),
|
|
1545
1641
|
// The operator's notes about this task not sent yet: they go out with this opening (2026-10-14).
|
|
1546
1642
|
...(openingNotes.length > 0 ? { operatorNotes: operatorNotesSection(openingNotes, false) } : {}),
|
|
@@ -1946,18 +2042,29 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1946
2042
|
}
|
|
1947
2043
|
reviewRounds += 1;
|
|
1948
2044
|
const model = effectiveModels(session, cfg).reviewModel;
|
|
2045
|
+
/*
|
|
2046
|
+
* Chosen by hand: in the Copilot window, as the work's model is (see `modelByHand`). The chat's model is by
|
|
2047
|
+
* hand unless one is named (2026-10-17), and its review is too: asked on a card that says it is the review's
|
|
2048
|
+
* and why a different, stronger model is worth choosing for it (operator, 2026-10-20).
|
|
2049
|
+
*/
|
|
2050
|
+
const reviewByHand = cfg.copilot.manualModel || !!session.manualModel || (session.kind === 'chat' && !model);
|
|
1949
2051
|
const repoDir = trackedRepoOf(session);
|
|
1950
2052
|
/*
|
|
1951
2053
|
* What changed, read from git rather than from anybody's account of it.
|
|
1952
2054
|
*
|
|
1953
2055
|
* The commit happens when the task closes, which is after this, so the task's changes are
|
|
1954
2056
|
* still sitting in the working tree. That is exactly the list wanted: the branch was cut
|
|
1955
|
-
* before this task started, so everything dirty now is this task's doing.
|
|
2057
|
+
* before this task started, so everything dirty now is this task's doing. A chat message
|
|
2058
|
+
* works on the operator's own branch, where much may be uncommitted that is not its doing:
|
|
2059
|
+
* what it changed is the folder against its photograph from before it (2026-10-20).
|
|
1956
2060
|
*/
|
|
1957
|
-
const
|
|
2061
|
+
const chatChanged = !repoDir && session.kind === 'chat' && chatCheckpoint && chatDir
|
|
2062
|
+
? await changedSince(chatDir, chatCheckpoint, `${task.id}-r${reviewRounds}`).catch(() => null)
|
|
2063
|
+
: null;
|
|
2064
|
+
const changedFiles = repoDir ? (await repoState(repoDir).catch(() => null))?.changed ?? [] : chatChanged ?? [];
|
|
1958
2065
|
// When nothing changed, or nothing was allowed to, the closing account is the product and
|
|
1959
2066
|
// the reviewer is given it — as claims to test. See `Deliverable` in review.ts.
|
|
1960
|
-
const deliverable = deliverableFor(task, closing, repoDir !== '', changedFiles);
|
|
2067
|
+
const deliverable = deliverableFor(task, closing, repoDir !== '' || chatChanged !== null, changedFiles);
|
|
1961
2068
|
sink.event('review-started', { round: reviewRounds, model: model || '(the session model)', files: changedFiles.length, deliverable: deliverable?.why }, `an independent review is opening a fresh conversation (round ${reviewRounds} of ${maxReviewRounds})` +
|
|
1962
2069
|
(deliverable ? `; the closing summary goes with it as the product (${deliverable.why})` : ''));
|
|
1963
2070
|
// What is running before the review, so that what the review leaves is its own.
|
|
@@ -1966,14 +2073,17 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1966
2073
|
let outcome;
|
|
1967
2074
|
try {
|
|
1968
2075
|
await transport.newChat();
|
|
1969
|
-
if (model) {
|
|
2076
|
+
if (model || (reviewByHand && deps.models?.askHelp)) {
|
|
1970
2077
|
let picked;
|
|
1971
|
-
if (
|
|
2078
|
+
if (reviewByHand && deps.models?.askHelp) {
|
|
1972
2079
|
// By hand, as the work's model (see `applySessionModel`): the review's fresh conversation is asked about too.
|
|
1973
2080
|
const shown = await transport.currentModel().catch(() => null);
|
|
1974
|
-
picked = buttonShows(shown, model)
|
|
2081
|
+
picked = model && buttonShows(shown, model)
|
|
1975
2082
|
? { ok: true, current: model, by: 'already' }
|
|
1976
|
-
: (await withOperatorHand(transport, model, { ok: false, current: shown, reason: '
|
|
2083
|
+
: (await withOperatorHand(transport, model, { ok: false, current: shown, reason: 'the model is chosen by hand (the review)' }, deps.models, session.id, bus, true, { review: true })).result;
|
|
2084
|
+
// Stopped on the card: the run stops, as it does on the work's card, and nothing is sent to the review.
|
|
2085
|
+
if (!picked.ok && signal?.aborted)
|
|
2086
|
+
throw new StoppedSend();
|
|
1977
2087
|
}
|
|
1978
2088
|
else {
|
|
1979
2089
|
const reviewLocator = await deps.models?.locate?.(model).catch(() => undefined);
|
|
@@ -2437,8 +2547,12 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2437
2547
|
});
|
|
2438
2548
|
await record(`PLAN ${planVersion}`, describePlan(plan));
|
|
2439
2549
|
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
|
-
|
|
2550
|
+
/*
|
|
2551
|
+
* Asked of the operator in a run that asks before each command: one that does not approves it itself. In the
|
|
2552
|
+
* workbench's chat always, as plan mode is there (2026-10-20: "a plan mode, as in Claude Code"): the operator
|
|
2553
|
+
* turned it on to see the plan before anything changes, whether the commands are then asked about or not.
|
|
2554
|
+
*/
|
|
2555
|
+
const asks = planMode === 'approve' && !!deps.approvePlan && (session.kind === 'chat' || (deps.currentMode?.() ?? cfg.execution.mode) === 'confirm');
|
|
2442
2556
|
let answer = { decision: 'approve' };
|
|
2443
2557
|
if (asks) {
|
|
2444
2558
|
sink.event('plan-waiting', { version: planVersion }, `plan ${planVersion} is waiting for the operator`, 'warn');
|
|
@@ -2572,6 +2686,8 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2572
2686
|
*/
|
|
2573
2687
|
let refusedAt = null;
|
|
2574
2688
|
for (const step of reply.steps) {
|
|
2689
|
+
// Paused: no other command runs until Continue. Stopped while held, the Stop just below takes it.
|
|
2690
|
+
await holdHere('command');
|
|
2575
2691
|
if (signal?.aborted) {
|
|
2576
2692
|
results.push(refusedResult(step, 'stopped by the operator', 'operator'));
|
|
2577
2693
|
aborted = true;
|
|
@@ -2889,7 +3005,8 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2889
3005
|
* second copy under a reply in progress; this is the reply wait from the settings running
|
|
2890
3006
|
* out, which ends the task at that limit (see the catch at the end), not an upload to retry.
|
|
2891
3007
|
*/
|
|
2892
|
-
|
|
3008
|
+
// Nor is a window the operator closed, which no retry reaches.
|
|
3009
|
+
if (isReplyTimeout(e) || transport.closedOutside())
|
|
2893
3010
|
throw e;
|
|
2894
3011
|
sink.event('report-send-failed', { attempt, error: String(e) }, `sending the report failed (attempt ${attempt + 1}): ${e.message}`, 'warn');
|
|
2895
3012
|
if (attempt === cfg.report.uploadRetries) {
|
|
@@ -2918,6 +3035,11 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2918
3035
|
}
|
|
2919
3036
|
catch (e) {
|
|
2920
3037
|
const message = e.message;
|
|
3038
|
+
// Stopped before a message went out — while paused, or as the reviewer was about to send: nothing more was sent.
|
|
3039
|
+
if (e instanceof StoppedSend) {
|
|
3040
|
+
sink.event('task-stopped', {}, 'stopped by the operator; nothing more was sent');
|
|
3041
|
+
return await finish('aborted', 'stopped by the operator; nothing more was sent');
|
|
3042
|
+
}
|
|
2921
3043
|
/*
|
|
2922
3044
|
* The chat took longer than Settings allow for a reply. A limit, not a fault: the conversation
|
|
2923
3045
|
* and the work are where they were, and "Continue" carries the task on in that chat.
|
|
@@ -2927,6 +3049,15 @@ export async function runTask(transport, session, task, deps) {
|
|
|
2927
3049
|
limitHit = { setting: 'replyTimeoutSec', value: e.seconds };
|
|
2928
3050
|
return await finish('limit-reached', `replyTimeoutSec (${e.seconds}) reached: ${message}`);
|
|
2929
3051
|
}
|
|
3052
|
+
/*
|
|
3053
|
+
* The operator closed the window with its X (2026-10-19: "the operator can close the browser with its X at any
|
|
3054
|
+
* moment"): what they did, said as a stop rather than as the error every call on a closed page gives. Unless
|
|
3055
|
+
* Edge left a crash report, which says it was not them.
|
|
3056
|
+
*/
|
|
3057
|
+
if (transport.closedOutside() && !(await transport.recentCrash().catch(() => null))) {
|
|
3058
|
+
sink.event('window-closed', { error: message }, 'the browser window was closed; nothing more is sent', 'warn');
|
|
3059
|
+
return await finish('aborted', 'the browser window was closed; nothing more was sent');
|
|
3060
|
+
}
|
|
2930
3061
|
sink.event('task-error', { error: message, stack: e.stack }, message, 'error');
|
|
2931
3062
|
await transport.dumpFailure(log.path('failures'), 'crash').catch(() => undefined);
|
|
2932
3063
|
/*
|
|
@@ -2982,14 +3113,26 @@ export async function runSession(sessionId, deps) {
|
|
|
2982
3113
|
let paused = false;
|
|
2983
3114
|
try {
|
|
2984
3115
|
session = await joinGroupConversation(store, session, bus);
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
3116
|
+
try {
|
|
3117
|
+
if (borrowed) {
|
|
3118
|
+
speakFor(borrowed, session.id, { alone: !!deps.chatWindow });
|
|
3119
|
+
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' });
|
|
3120
|
+
if (deps.chatWindow) {
|
|
3121
|
+
await borrowed.clearNotice().catch(() => undefined);
|
|
3122
|
+
await borrowed.ensureSignedIn(undefined, { signal: deps.signal });
|
|
3123
|
+
}
|
|
3124
|
+
await enterSessionConversation(borrowed, session, { closeOnFailure: false });
|
|
3125
|
+
}
|
|
3126
|
+
else {
|
|
3127
|
+
await deps.beforeBrowser?.();
|
|
3128
|
+
// The chat's window outlives this message, so what it keeps goes where the batch's window keeps its own.
|
|
3129
|
+
transport = await openSessionTransport(cfg, session, bus, deps.chatWindow ? cfg.resolved.runsDir : sessionRunsDir, deps.signal);
|
|
3130
|
+
if (deps.chatWindow)
|
|
3131
|
+
speakFor(transport, session.id, { alone: true });
|
|
3132
|
+
}
|
|
2989
3133
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
transport = await openSessionTransport(cfg, session, bus, sessionRunsDir, deps.signal);
|
|
3134
|
+
catch (e) {
|
|
3135
|
+
throw failedOpening(e);
|
|
2993
3136
|
}
|
|
2994
3137
|
const chat = transport;
|
|
2995
3138
|
// The picker belongs to the conversation, so the session's choice is applied once, here,
|
|
@@ -3032,8 +3175,28 @@ export async function runSession(sessionId, deps) {
|
|
|
3032
3175
|
});
|
|
3033
3176
|
task = session.tasks.find((t) => t.id === queuedTask.id);
|
|
3034
3177
|
}
|
|
3178
|
+
/*
|
|
3179
|
+
* A message of a conversation in the two-chat mode (2026-10-20): its lead directs it and its worker carries out the
|
|
3180
|
+
* subtasks (see `leadRunner.ts`). Not carried on or retried in a fresh chat here: the lead decides what to do when
|
|
3181
|
+
* a subtask falls short, and its own limits bound it.
|
|
3182
|
+
*/
|
|
3183
|
+
if (session.lead && session.kind === 'chat') {
|
|
3184
|
+
const led = await runLeadTask(chat, session, task, deps);
|
|
3185
|
+
ran += 1;
|
|
3186
|
+
lastStatus = led.status;
|
|
3187
|
+
if (chat.closedOutside()) {
|
|
3188
|
+
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed; the tasks after this one stay queued' });
|
|
3189
|
+
break;
|
|
3190
|
+
}
|
|
3191
|
+
continue;
|
|
3192
|
+
}
|
|
3035
3193
|
let outcome = await runTask(chat, session, task, deps);
|
|
3036
3194
|
ran += 1;
|
|
3195
|
+
// The operator closed the window with its X: a stop, for the tasks after it too (2026-10-19).
|
|
3196
|
+
if (chat.closedOutside()) {
|
|
3197
|
+
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed; the tasks after this one stay queued' });
|
|
3198
|
+
break;
|
|
3199
|
+
}
|
|
3037
3200
|
/*
|
|
3038
3201
|
* A blocked task is run again in a fresh conversation, up to the configured number of
|
|
3039
3202
|
* times, before the verdict stands.
|
|
@@ -3190,6 +3353,10 @@ export async function runSession(sessionId, deps) {
|
|
|
3190
3353
|
if (deps.signal?.aborted && ran === 0) {
|
|
3191
3354
|
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
3355
|
}
|
|
3356
|
+
else if ((e instanceof WindowClosed || transport?.closedOutside()) && ran === 0) {
|
|
3357
|
+
// Closed with its X while the chat was being opened, the sign-in awaited or the model chosen: a stop as well.
|
|
3358
|
+
bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: 'the browser window was closed before the first task was sent; the tasks stay queued' });
|
|
3359
|
+
}
|
|
3193
3360
|
else {
|
|
3194
3361
|
bus.publish({ sessionId, type: 'session-error', level: 'error', message: e.message });
|
|
3195
3362
|
throw e;
|
|
@@ -3197,8 +3364,13 @@ export async function runSession(sessionId, deps) {
|
|
|
3197
3364
|
}
|
|
3198
3365
|
finally {
|
|
3199
3366
|
// A borrowed window belongs to whoever opened it and stays open for the next session.
|
|
3200
|
-
if (!borrowed)
|
|
3201
|
-
|
|
3367
|
+
if (!borrowed) {
|
|
3368
|
+
// The chat's, still open, is kept for its next message; one the operator closed is let go of.
|
|
3369
|
+
if (deps.chatWindow && transport?.isOpen())
|
|
3370
|
+
deps.chatWindow.keep(transport);
|
|
3371
|
+
else
|
|
3372
|
+
await transport?.close();
|
|
3373
|
+
}
|
|
3202
3374
|
await store.updateSession(sessionId, (s) => {
|
|
3203
3375
|
s.status = 'idle';
|
|
3204
3376
|
});
|