copilot-operator 0.1.59 → 0.1.62
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/dist/src/api/operator.controller.js +78 -1
- package/dist/src/api/operator.service.js +254 -3
- package/dist/src/cli.js +3 -0
- package/dist/src/config/exportHome.js +78 -0
- package/dist/src/config/schema.js +22 -0
- package/dist/src/orchestrator/taskRunner.js +15 -4
- package/dist/src/plan/systemGuide.js +326 -0
- package/dist/src/queue/queue.js +160 -0
- package/dist/src/transport/copilotTransport.js +263 -131
- package/dist/src/transport/locators.js +119 -33
- package/dist/src/util/zip.js +80 -0
- package/dist/src/vcs/taskVcs.js +25 -1
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/PJs9xZLAnUDPOFvGV0T_M/_buildManifest.js +1 -0
- package/dist/web/_next/static/chunks/1077.42a0502bfe3f2014.js +1 -0
- package/dist/web/_next/static/chunks/1548.dbf0648a1239382e.js +1 -0
- package/dist/web/_next/static/chunks/2163.dbdeebeb0c069d62.js +1 -0
- package/dist/web/_next/static/chunks/714.6472121643f99452.js +1 -0
- package/dist/web/_next/static/chunks/7220.391debd1191fc29a.js +1 -0
- package/dist/web/_next/static/chunks/7921-0549a0038e591e42.js +1 -0
- package/dist/web/_next/static/chunks/8124-5458b17433987fab.js +1 -0
- package/dist/web/_next/static/chunks/8197-e2fcb43f38a2b4a7.js +1 -0
- package/dist/web/_next/static/chunks/8584.4432f14f0cd88188.js +1 -0
- package/dist/web/_next/static/chunks/9067.841d6d2f4726f9c2.js +1 -0
- package/dist/web/_next/static/chunks/9747.1a7337320eccdc8a.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-9201c637ca24b2c9.js +1 -0
- package/dist/web/_next/static/chunks/app/{page-c3c50d426109e8c5.js → page-ea0a60db75dac546.js} +1 -1
- package/dist/web/_next/static/chunks/app/queue/page-f86936d39121ade8.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-1833ace66fc9eb0e.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-d210ad961e7a9237.js → webpack-4665fed2f4b06052.js} +1 -1
- package/dist/web/_next/static/css/5ec15fce93be8cbe.css +1 -0
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +8 -8
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +9 -9
- package/dist/web/queue.html +14 -0
- package/dist/web/queue.txt +26 -0
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +9 -9
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +9 -9
- package/package.json +5 -2
- package/dist/web/_next/static/Gan_sPghz9GR_aVaCL2ah/_buildManifest.js +0 -1
- package/dist/web/_next/static/chunks/1077.34c33df752c793fd.js +0 -1
- package/dist/web/_next/static/chunks/1548.9bd3216f2e2ed40a.js +0 -1
- package/dist/web/_next/static/chunks/2163.c764c5ddf04e8f3c.js +0 -1
- package/dist/web/_next/static/chunks/3134-b6a7bc1f267c39aa.js +0 -1
- package/dist/web/_next/static/chunks/4512-bf72c643d4a4db71.js +0 -1
- package/dist/web/_next/static/chunks/714.ce1d54a2c2b5474f.js +0 -1
- package/dist/web/_next/static/chunks/7220.07100b580a566f9c.js +0 -1
- package/dist/web/_next/static/chunks/7921-97fcfd1f6aff2774.js +0 -1
- package/dist/web/_next/static/chunks/8584.d863bb44ea78998d.js +0 -1
- package/dist/web/_next/static/chunks/9067.3d3d65b5fb1c6a61.js +0 -1
- package/dist/web/_next/static/chunks/9747.af530d25cd7cc8fb.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-9cd9b0b0587f4882.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-e485720f199e3194.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +0 -1
- package/dist/web/_next/static/css/e544b477e4b4b108.css +0 -1
- /package/dist/web/_next/static/{Gan_sPghz9GR_aVaCL2ah → PJs9xZLAnUDPOFvGV0T_M}/_ssgManifest.js +0 -0
|
@@ -24,6 +24,8 @@ import { OperatorService } from './operator.service.js';
|
|
|
24
24
|
import { SettingsUnusableError } from './settings.js';
|
|
25
25
|
import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
|
|
26
26
|
import { CHANGED_ON_DISK } from '../session/workspace.js';
|
|
27
|
+
import { join } from 'node:path';
|
|
28
|
+
import { DefaultPickerLocators } from '../transport/locators.js';
|
|
27
29
|
function fail(e) {
|
|
28
30
|
// A settings file or a policy lock that cannot be used is not the request's fault, and every route
|
|
29
31
|
// that reads the settings meets it, wrapped here or not: it is passed on as it is, for the server
|
|
@@ -76,7 +78,12 @@ let OperatorController = class OperatorController {
|
|
|
76
78
|
// --- settings ---------------------------------------------------------------------------
|
|
77
79
|
async settings() {
|
|
78
80
|
const [raw, defaults, resolved] = await Promise.all([this.ops.settings.raw(), this.ops.settings.defaults(), this.ops.settings.load()]);
|
|
79
|
-
|
|
81
|
+
/*
|
|
82
|
+
* The model menu's locators (2026-10-24): their defaults, which Settings shows and puts back, and where the
|
|
83
|
+
* pictures of a choice are kept — a run's beside its browser's other files, a reading of the list in its own.
|
|
84
|
+
*/
|
|
85
|
+
const picker = { defaults: DefaultPickerLocators, dirs: { run: join(resolved.resolved.runsDir, '_browser'), read: join(resolved.resolved.runsDir, '_models') } };
|
|
86
|
+
return { raw, defaults, resolved: resolved.resolved, picker };
|
|
80
87
|
}
|
|
81
88
|
async saveSettings(body) {
|
|
82
89
|
await this.ops.settings.save(body).catch(fail);
|
|
@@ -163,6 +170,22 @@ let OperatorController = class OperatorController {
|
|
|
163
170
|
failText(res, e);
|
|
164
171
|
}
|
|
165
172
|
}
|
|
173
|
+
/** How much an export of the bot's folder would hold (2026-10-23). */
|
|
174
|
+
exportSize() {
|
|
175
|
+
return this.ops.exportSizes();
|
|
176
|
+
}
|
|
177
|
+
/** Everything the bot has kept, as a .zip: `data/`, and `runs/` with `?runs=1`. See `config/exportHome.ts`. */
|
|
178
|
+
exportHome(runs, res) {
|
|
179
|
+
try {
|
|
180
|
+
const { fileName, content } = this.ops.exportHome(runs === '1' || runs === 'true');
|
|
181
|
+
res.type('application/zip');
|
|
182
|
+
res.setHeader('content-disposition', contentDisposition(fileName));
|
|
183
|
+
res.send(content);
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
failText(res, e);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
166
189
|
/** What the bot's console showed, the latest lines, as a text file. See `log/terminal.ts`. */
|
|
167
190
|
async terminal(res) {
|
|
168
191
|
try {
|
|
@@ -299,6 +322,21 @@ let OperatorController = class OperatorController {
|
|
|
299
322
|
})
|
|
300
323
|
.catch(fail);
|
|
301
324
|
}
|
|
325
|
+
// --- the queue of tasks (2026-10-24) -------------------------------------------------------------------
|
|
326
|
+
/** The tasks prepared to run one after another, each in a new chat, and whether the queue is running. */
|
|
327
|
+
queue() {
|
|
328
|
+
return this.ops.queue().catch(fail);
|
|
329
|
+
}
|
|
330
|
+
/** The list as the page edits it: added, changed, moved, taken out, put back to wait. */
|
|
331
|
+
setQueue(body = {}) {
|
|
332
|
+
return this.ops.setQueue(body?.items).catch(fail);
|
|
333
|
+
}
|
|
334
|
+
runQueue() {
|
|
335
|
+
return this.ops.runQueue().catch(fail);
|
|
336
|
+
}
|
|
337
|
+
stopQueue() {
|
|
338
|
+
return this.ops.stopQueue().catch(fail);
|
|
339
|
+
}
|
|
302
340
|
/** Back to before a message: the folder as it was then, that message and the ones after it taken out. */
|
|
303
341
|
async chatRewind(id, body = {}) {
|
|
304
342
|
if (typeof body?.taskId !== 'string' || !body.taskId)
|
|
@@ -534,6 +572,20 @@ __decorate([
|
|
|
534
572
|
__metadata("design:paramtypes", [String, Object]),
|
|
535
573
|
__metadata("design:returntype", Promise)
|
|
536
574
|
], OperatorController.prototype, "startFailureReport", null);
|
|
575
|
+
__decorate([
|
|
576
|
+
Get('home/export/size'),
|
|
577
|
+
__metadata("design:type", Function),
|
|
578
|
+
__metadata("design:paramtypes", []),
|
|
579
|
+
__metadata("design:returntype", Object)
|
|
580
|
+
], OperatorController.prototype, "exportSize", null);
|
|
581
|
+
__decorate([
|
|
582
|
+
Get('home/export'),
|
|
583
|
+
__param(0, Query('runs')),
|
|
584
|
+
__param(1, Res()),
|
|
585
|
+
__metadata("design:type", Function),
|
|
586
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
587
|
+
__metadata("design:returntype", void 0)
|
|
588
|
+
], OperatorController.prototype, "exportHome", null);
|
|
537
589
|
__decorate([
|
|
538
590
|
Get('terminal'),
|
|
539
591
|
__param(0, Res()),
|
|
@@ -657,6 +709,31 @@ __decorate([
|
|
|
657
709
|
__metadata("design:paramtypes", [Object]),
|
|
658
710
|
__metadata("design:returntype", Promise)
|
|
659
711
|
], OperatorController.prototype, "chatSend", null);
|
|
712
|
+
__decorate([
|
|
713
|
+
Get('queue'),
|
|
714
|
+
__metadata("design:type", Function),
|
|
715
|
+
__metadata("design:paramtypes", []),
|
|
716
|
+
__metadata("design:returntype", Promise)
|
|
717
|
+
], OperatorController.prototype, "queue", null);
|
|
718
|
+
__decorate([
|
|
719
|
+
Put('queue'),
|
|
720
|
+
__param(0, Body()),
|
|
721
|
+
__metadata("design:type", Function),
|
|
722
|
+
__metadata("design:paramtypes", [Object]),
|
|
723
|
+
__metadata("design:returntype", Promise)
|
|
724
|
+
], OperatorController.prototype, "setQueue", null);
|
|
725
|
+
__decorate([
|
|
726
|
+
Post('queue/run'),
|
|
727
|
+
__metadata("design:type", Function),
|
|
728
|
+
__metadata("design:paramtypes", []),
|
|
729
|
+
__metadata("design:returntype", Promise)
|
|
730
|
+
], OperatorController.prototype, "runQueue", null);
|
|
731
|
+
__decorate([
|
|
732
|
+
Post('queue/stop'),
|
|
733
|
+
__metadata("design:type", Function),
|
|
734
|
+
__metadata("design:paramtypes", []),
|
|
735
|
+
__metadata("design:returntype", Promise)
|
|
736
|
+
], OperatorController.prototype, "stopQueue", null);
|
|
660
737
|
__decorate([
|
|
661
738
|
Post('chat/:id/rewind'),
|
|
662
739
|
__param(0, Param('id')),
|
|
@@ -15,13 +15,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
15
15
|
import { pageModelFor, sameModel } from '../transport/modelMatch.js';
|
|
16
16
|
import { Injectable } from '@nestjs/common';
|
|
17
17
|
import { existsSync } from 'node:fs';
|
|
18
|
+
import { readFile } from 'node:fs/promises';
|
|
18
19
|
import { join, resolve } from 'node:path';
|
|
19
20
|
import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
|
|
20
21
|
import { chooseHome, homeRefusal, movedFrom } from '../config/home.js';
|
|
21
|
-
import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW } from '../session/store.js';
|
|
22
|
+
import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW, writeFileAtomically } from '../session/store.js';
|
|
23
|
+
import { checkItems, emptyQueue, itemTitle, mainBranchOf, mergeItems, nextStep, skippedBecause, statusOfTask, waitsByHand } from '../queue/queue.js';
|
|
22
24
|
import { EventBus } from '../session/events.js';
|
|
23
25
|
import { MAX_INSTRUCTION_CHARS, newId } from '../session/model.js';
|
|
24
|
-
import { runSession, queuedToRun, failedWhileOpening } from '../orchestrator/taskRunner.js';
|
|
26
|
+
import { runSession, queuedToRun, failedWhileOpening, pickerOptions } from '../orchestrator/taskRunner.js';
|
|
25
27
|
import { Hold } from '../orchestrator/hold.js';
|
|
26
28
|
import { exportFileName, exportMachine, writeAttemptRecord } from '../session/exports.js';
|
|
27
29
|
import { suggestRunName } from '../session/runName.js';
|
|
@@ -83,6 +85,8 @@ import { runVcsPreflight } from '../vcs/runPreflight.js';
|
|
|
83
85
|
import { inputSettings, normalisePatterns } from '../vcs/inputs.js';
|
|
84
86
|
import { coveredByArtifacts } from '../vcs/artifacts.js';
|
|
85
87
|
import { botVersion } from '../config/version.js';
|
|
88
|
+
import { exportEntries, exportFileName as homeExportName, exportSizes } from '../config/exportHome.js';
|
|
89
|
+
import { createZip } from '../util/zip.js';
|
|
86
90
|
import { settingsOf, SettingsUnusableError } from './settings.js';
|
|
87
91
|
import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
|
|
88
92
|
import { chatDenyPatterns } from '../config/schema.js';
|
|
@@ -141,11 +145,20 @@ let OperatorService = class OperatorService {
|
|
|
141
145
|
* for `activity`, which every page asks on a timer and answers from memory. Gone when the message ends.
|
|
142
146
|
*/
|
|
143
147
|
acting = new Map();
|
|
148
|
+
/**
|
|
149
|
+
* How the last message ended (2026-10-23: the tab reads "Done", "Error" and the like when the work stops, for an
|
|
150
|
+
* operator in another window): a worker's subtask is not the message.
|
|
151
|
+
*/
|
|
152
|
+
lastOutcome = null;
|
|
144
153
|
followsActing = this.bus.subscribe('*', (e) => {
|
|
145
154
|
if (e.type === 'acting' && e.data)
|
|
146
155
|
this.acting.set(e.sessionId, e.data);
|
|
147
|
-
else if (e.type === 'task-finished')
|
|
156
|
+
else if (e.type === 'task-finished') {
|
|
148
157
|
this.acting.delete(e.sessionId);
|
|
158
|
+
const status = e.data?.status;
|
|
159
|
+
if (typeof status === 'string' && !this.workerLeads.has(e.sessionId))
|
|
160
|
+
this.lastOutcome = { status, at: e.at, sessionId: e.sessionId };
|
|
161
|
+
}
|
|
149
162
|
});
|
|
150
163
|
waiting = new Map();
|
|
151
164
|
/**
|
|
@@ -614,6 +627,8 @@ let OperatorService = class OperatorService {
|
|
|
614
627
|
}
|
|
615
628
|
/** The program is closing: so is the window the chat left open. */
|
|
616
629
|
async onModuleDestroy() {
|
|
630
|
+
// The queue's loop lets go; its file still says running, and the next start says what was in flight (`recoverQueue`).
|
|
631
|
+
this.queueClosing = true;
|
|
617
632
|
await this.closeChatWindow('the program is closing');
|
|
618
633
|
}
|
|
619
634
|
/**
|
|
@@ -736,6 +751,18 @@ let OperatorService = class OperatorService {
|
|
|
736
751
|
return { fileName: `copilot-operator-not-started-${fileStamp(f.at)}.txt`, content: redactSecrets(text, cfg.report.redactPatterns) };
|
|
737
752
|
}
|
|
738
753
|
/** What the bot's console showed: the latest lines kept in memory, as a file. See `log/terminal.ts`. */
|
|
754
|
+
/** How much an export of the bot's folder would hold (2026-10-23): its data, and its runs' records. */
|
|
755
|
+
exportSizes() {
|
|
756
|
+
return exportSizes(this.layout);
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Everything the bot has kept, as one .zip (operator, 2026-10-23): `data/` — the key and the Edge profile left out,
|
|
760
|
+
* the manifest says why — and `runs/` when asked for.
|
|
761
|
+
*/
|
|
762
|
+
exportHome(runs) {
|
|
763
|
+
const now = new Date();
|
|
764
|
+
return { fileName: homeExportName(now), content: createZip(exportEntries(this.layout, { runs, version: botVersion(), now })) };
|
|
765
|
+
}
|
|
739
766
|
async terminalReport() {
|
|
740
767
|
const cfg = await this.settings.load();
|
|
741
768
|
const lines = terminalLines({ max: 5_000 });
|
|
@@ -1022,6 +1049,8 @@ let OperatorService = class OperatorService {
|
|
|
1022
1049
|
starting,
|
|
1023
1050
|
...(acting ? { acting } : {}),
|
|
1024
1051
|
...(run?.hold?.held ? { paused: true } : {}),
|
|
1052
|
+
// How the last message ended, while nothing runs: what the tab says until the operator has looked.
|
|
1053
|
+
...(this.running.size === 0 && this.lastOutcome ? { last: { status: this.lastOutcome.status, at: this.lastOutcome.at } } : {}),
|
|
1025
1054
|
};
|
|
1026
1055
|
}
|
|
1027
1056
|
/**
|
|
@@ -1257,6 +1286,226 @@ let OperatorService = class OperatorService {
|
|
|
1257
1286
|
}
|
|
1258
1287
|
return { threadId: session.id, taskId: task.id, needsStart: false };
|
|
1259
1288
|
}
|
|
1289
|
+
// --- the queue of tasks (2026-10-24) ----------------------------------------------------------------
|
|
1290
|
+
//
|
|
1291
|
+
// Tasks written beforehand, each run in a new chat on its own model while nobody watches; one that failed takes
|
|
1292
|
+
// the tasks that depend on it with it, and the queue goes on with the next. See `queue/queue.ts`.
|
|
1293
|
+
queueFile = join(this.dataDir, 'queue.json');
|
|
1294
|
+
queueTurn = Promise.resolve();
|
|
1295
|
+
queueLoop = null;
|
|
1296
|
+
queueRecovered = false;
|
|
1297
|
+
/** The program is closing: the queue's loop stops where it is. */
|
|
1298
|
+
queueClosing = false;
|
|
1299
|
+
/** The queue as it is on disk; one that cannot be read is an empty one, said in the console. */
|
|
1300
|
+
async readQueue() {
|
|
1301
|
+
try {
|
|
1302
|
+
const q = JSON.parse(await readFile(this.queueFile, 'utf8'));
|
|
1303
|
+
return { items: Array.isArray(q.items) ? q.items : [], running: q.running === true, updatedAt: q.updatedAt ?? '' };
|
|
1304
|
+
}
|
|
1305
|
+
catch (e) {
|
|
1306
|
+
if (e.code !== 'ENOENT')
|
|
1307
|
+
console.error('[queue] data/queue.json could not be read:', e.message);
|
|
1308
|
+
return emptyQueue();
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
/** Changes the queue in a turn of its own, so two changes never write over each other. */
|
|
1312
|
+
changeQueue(change) {
|
|
1313
|
+
const run = async () => {
|
|
1314
|
+
const q = await this.readQueue();
|
|
1315
|
+
change(q);
|
|
1316
|
+
q.updatedAt = new Date().toISOString();
|
|
1317
|
+
await writeFileAtomically(this.queueFile, JSON.stringify(q, null, 2));
|
|
1318
|
+
return q;
|
|
1319
|
+
};
|
|
1320
|
+
const done = this.queueTurn.then(run, run);
|
|
1321
|
+
this.queueTurn = done.catch(() => undefined);
|
|
1322
|
+
return done;
|
|
1323
|
+
}
|
|
1324
|
+
setQueueItem(q, id, patch) {
|
|
1325
|
+
const item = q.items.find((x) => x.id === id);
|
|
1326
|
+
if (!item)
|
|
1327
|
+
return;
|
|
1328
|
+
Object.assign(item, patch);
|
|
1329
|
+
for (const key of Object.keys(patch))
|
|
1330
|
+
if (patch[key] === undefined)
|
|
1331
|
+
delete item[key];
|
|
1332
|
+
}
|
|
1333
|
+
/** A queue that was running when the bot last closed: not running now, and its task in flight stopped. */
|
|
1334
|
+
async recoverQueue() {
|
|
1335
|
+
if (this.queueRecovered)
|
|
1336
|
+
return;
|
|
1337
|
+
this.queueRecovered = true;
|
|
1338
|
+
const q = await this.readQueue();
|
|
1339
|
+
if (!q.running && !q.items.some((x) => x.status === 'running'))
|
|
1340
|
+
return;
|
|
1341
|
+
await this.changeQueue((x) => {
|
|
1342
|
+
x.running = false;
|
|
1343
|
+
for (const item of x.items) {
|
|
1344
|
+
if (item.status === 'running')
|
|
1345
|
+
Object.assign(item, { status: 'stopped', why: 'the bot was closed while it ran', endedAt: new Date().toISOString() });
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
async queue() {
|
|
1350
|
+
await this.recoverQueue();
|
|
1351
|
+
return await this.readQueue();
|
|
1352
|
+
}
|
|
1353
|
+
/** The list as the page edits it: added, changed, moved, taken out, put back to wait ("Run again"). */
|
|
1354
|
+
async setQueue(items) {
|
|
1355
|
+
await this.recoverQueue();
|
|
1356
|
+
const checked = checkItems(items, MAX_INSTRUCTION_CHARS);
|
|
1357
|
+
if ('problem' in checked)
|
|
1358
|
+
throw new Error(checked.problem);
|
|
1359
|
+
let problem;
|
|
1360
|
+
const q = await this.changeQueue((x) => {
|
|
1361
|
+
const merged = mergeItems(x.items, checked.items);
|
|
1362
|
+
if ('problem' in merged)
|
|
1363
|
+
problem = merged.problem;
|
|
1364
|
+
else
|
|
1365
|
+
x.items = merged.items;
|
|
1366
|
+
});
|
|
1367
|
+
if (problem)
|
|
1368
|
+
throw new Error(problem);
|
|
1369
|
+
return q;
|
|
1370
|
+
}
|
|
1371
|
+
/** Runs the waiting tasks one after another, in the background; the page follows `queue()`. */
|
|
1372
|
+
async runQueue() {
|
|
1373
|
+
await this.init();
|
|
1374
|
+
await this.recoverQueue();
|
|
1375
|
+
if (this.queueLoop)
|
|
1376
|
+
throw new Error('The queue is running already.');
|
|
1377
|
+
const q = await this.readQueue();
|
|
1378
|
+
if (!nextStep(q.items))
|
|
1379
|
+
throw new Error('No task in the queue is waiting. Add one, or put one back with "Run again".');
|
|
1380
|
+
const ws = await this.workspace();
|
|
1381
|
+
if (!ws.ok)
|
|
1382
|
+
throw new Error(ws.problem ?? 'No project folder is open: open one in the chat first.');
|
|
1383
|
+
const unnamed = this.queueWithoutModel(q.items.filter((x) => x.status === 'waiting'), await this.settings.load());
|
|
1384
|
+
if (unnamed)
|
|
1385
|
+
throw new Error(unnamed);
|
|
1386
|
+
const started = await this.changeQueue((x) => {
|
|
1387
|
+
x.running = true;
|
|
1388
|
+
});
|
|
1389
|
+
this.queueLoop = this.runQueueLoop()
|
|
1390
|
+
.catch((e) => console.error('[queue] the queue stopped:', e.stack ?? e.message))
|
|
1391
|
+
.finally(() => {
|
|
1392
|
+
this.queueLoop = null;
|
|
1393
|
+
void this.changeQueue((x) => {
|
|
1394
|
+
x.running = false;
|
|
1395
|
+
});
|
|
1396
|
+
});
|
|
1397
|
+
return started;
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Tasks that would wait for the operator to choose their model by hand: none of their own, and no "Model for the
|
|
1401
|
+
* worker" in Settings — a chat that names no model is asked for it by hand (`modelByHand`), and nobody is there.
|
|
1402
|
+
*/
|
|
1403
|
+
queueWithoutModel(items, cfg) {
|
|
1404
|
+
const said = items.flatMap((x) => waitsByHand(x, cfg.copilot).map((part) => part === 'model'
|
|
1405
|
+
? `"${itemTitle(x)}" has no model of its own, and Settings have no "${x.lead ? 'Model for the lead' : 'Model for the worker'}"`
|
|
1406
|
+
: `"${itemTitle(x)}" is reviewed, with no model for the review of its own, and Settings have no "Model for the review"`));
|
|
1407
|
+
if (said.length === 0)
|
|
1408
|
+
return null;
|
|
1409
|
+
return `${said.join('; ')}: ${said.length === 1 ? 'it' : 'they'} would wait for you to choose a model by hand. Choose the model in the task, or in Settings.`;
|
|
1410
|
+
}
|
|
1411
|
+
/** Stops the queue: the task at work is stopped as the chat's Stop does, and the rest wait. */
|
|
1412
|
+
async stopQueue() {
|
|
1413
|
+
const q = await this.changeQueue((x) => {
|
|
1414
|
+
x.running = false;
|
|
1415
|
+
});
|
|
1416
|
+
const at = q.items.find((x) => x.status === 'running');
|
|
1417
|
+
if (at?.sessionId)
|
|
1418
|
+
await this.stop(at.sessionId).catch(() => undefined);
|
|
1419
|
+
return q;
|
|
1420
|
+
}
|
|
1421
|
+
async runQueueLoop() {
|
|
1422
|
+
const now = () => new Date().toISOString();
|
|
1423
|
+
for (;;) {
|
|
1424
|
+
if (this.queueClosing)
|
|
1425
|
+
return;
|
|
1426
|
+
const q = await this.readQueue();
|
|
1427
|
+
if (!q.running)
|
|
1428
|
+
return;
|
|
1429
|
+
const step = nextStep(q.items);
|
|
1430
|
+
if (!step)
|
|
1431
|
+
return;
|
|
1432
|
+
if ('skip' in step) {
|
|
1433
|
+
await this.changeQueue((x) => this.setQueueItem(x, step.skip.id, { status: 'skipped', why: skippedBecause(step.because), endedAt: now() }));
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
const item = step.run;
|
|
1437
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, sessionId: undefined }));
|
|
1438
|
+
const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
|
|
1439
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { ...ended, endedAt: now() }));
|
|
1440
|
+
// Stopped — from the queue, or the chat's Stop: the rest wait for the operator.
|
|
1441
|
+
if (ended.status === 'stopped')
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
/** One task of the queue, in a new chat, to its end. */
|
|
1446
|
+
async runQueueItem(item) {
|
|
1447
|
+
const pause = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1448
|
+
const stillRunning = async () => (await this.readQueue()).running;
|
|
1449
|
+
// Read afresh each time: the browser is let go of by other work while this waits.
|
|
1450
|
+
const holder = () => this.browser;
|
|
1451
|
+
// The browser may be the chat's, or a reading of the models': the task waits its turn.
|
|
1452
|
+
while (holder()) {
|
|
1453
|
+
if (this.queueClosing || !(await stillRunning()))
|
|
1454
|
+
return { status: 'stopped', why: 'the queue was stopped before it began' };
|
|
1455
|
+
await pause(1_000);
|
|
1456
|
+
}
|
|
1457
|
+
const ws = await this.workspace();
|
|
1458
|
+
if (!ws.ok)
|
|
1459
|
+
return { status: 'failed', why: ws.problem ?? 'no project folder is open' };
|
|
1460
|
+
// Settings may have changed since the queue was started.
|
|
1461
|
+
const unnamed = this.queueWithoutModel([item], await this.settings.load());
|
|
1462
|
+
if (unnamed)
|
|
1463
|
+
return { status: 'failed', why: unnamed };
|
|
1464
|
+
const base = item.branch === 'main' ? await mainBranchOf(ws.dir) : null;
|
|
1465
|
+
if (item.branch === 'main' && !base)
|
|
1466
|
+
return { status: 'failed', why: `${ws.dir} has no main (or master) branch to make a new branch from` };
|
|
1467
|
+
// As the chat's box sends a first message: the model, the review and its model, or two chats and the worker's model.
|
|
1468
|
+
const sent = await this.chatSend({
|
|
1469
|
+
text: item.prompt,
|
|
1470
|
+
...(item.model ? { model: item.model } : {}),
|
|
1471
|
+
review: item.review,
|
|
1472
|
+
...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
|
|
1473
|
+
...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
|
|
1474
|
+
});
|
|
1475
|
+
const sessionId = sent.threadId;
|
|
1476
|
+
await this.store.updateSession(sessionId, (s) => {
|
|
1477
|
+
s.name = `queue: ${itemTitle(item)}`;
|
|
1478
|
+
s.queueItem = item.id;
|
|
1479
|
+
/*
|
|
1480
|
+
* A new branch from main (2026-10-24): the runner's own version control, as a session of the bot's has it — the
|
|
1481
|
+
* branch cut from main, brought up to date from the server first when that needs no password (`updateFromRemote`
|
|
1482
|
+
* asks nobody anything; it fails, and the local main is used), and the work committed on it. The chat is told
|
|
1483
|
+
* which main it was (`noteFor`).
|
|
1484
|
+
*/
|
|
1485
|
+
if (base) {
|
|
1486
|
+
s.vcs = { ...DEFAULT_VCS, enabled: true, repoDir: ws.dir, branchMode: 'per-session', commitOnFinish: true, startFrom: 'branch', baseBranch: base, updateFromRemote: true };
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
|
|
1490
|
+
const cfg = await this.settings.load();
|
|
1491
|
+
const reply = await this.start(sessionId, cfg.execution.mode);
|
|
1492
|
+
if (!reply.started)
|
|
1493
|
+
return { status: 'failed', why: reply.reason ?? 'it did not start', sessionId };
|
|
1494
|
+
// Until its run has ended and its window let the browser go, so the next one can have it.
|
|
1495
|
+
let asked = false;
|
|
1496
|
+
while (this.running.has(sessionId) || (holder()?.kind === 'run' && holder().sessionId === sessionId)) {
|
|
1497
|
+
if (this.queueClosing)
|
|
1498
|
+
return { status: 'stopped', why: 'the bot was closed while it ran', sessionId };
|
|
1499
|
+
if (!asked && !(await stillRunning())) {
|
|
1500
|
+
asked = true;
|
|
1501
|
+
await this.stop(sessionId).catch(() => undefined);
|
|
1502
|
+
}
|
|
1503
|
+
await pause(1_000);
|
|
1504
|
+
}
|
|
1505
|
+
const task = (await this.store.getSession(sessionId))?.tasks.find((t) => t.id === sent.taskId);
|
|
1506
|
+
const status = statusOfTask(task?.status);
|
|
1507
|
+
return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
|
|
1508
|
+
}
|
|
1260
1509
|
// --- skills (2026-10-21) ----------------------------------------------------------------------------
|
|
1261
1510
|
/** The skills in Settings, and how long their instructions may be. */
|
|
1262
1511
|
async skills() {
|
|
@@ -2132,6 +2381,8 @@ let OperatorService = class OperatorService {
|
|
|
2132
2381
|
signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
|
|
2133
2382
|
humanWaitMs: cfg.copilot.humanWaitSec * 1000,
|
|
2134
2383
|
keepFailurePage: cfg.copilot.keepFailurePage,
|
|
2384
|
+
// The rows' locator reads the names (Settings' own, 2026-10-24).
|
|
2385
|
+
...pickerOptions(cfg),
|
|
2135
2386
|
});
|
|
2136
2387
|
await this.closeChatWindow('reading the models needs the browser');
|
|
2137
2388
|
await transport.open();
|
package/dist/src/cli.js
CHANGED
|
@@ -388,7 +388,10 @@ program
|
|
|
388
388
|
.option('--steps', 'with --set: print each step of the choice with its time, and keep a picture of each in runs/_models')
|
|
389
389
|
.option('--chat <id-or-address>', 'first open this existing conversation (its id, or its address from the browser), as a task carried on does')
|
|
390
390
|
.action(async (opts) => {
|
|
391
|
+
// The model menu's locators saved in Settings (2026-10-24), as a run and "Read the list from Copilot" use them.
|
|
392
|
+
const saved = await settingsOf(installLayout()).load().catch(() => null);
|
|
391
393
|
const transport = new CopilotTransport({
|
|
394
|
+
...(saved?.copilot.pickerLocators ? { pickerLocators: saved.copilot.pickerLocators } : {}),
|
|
392
395
|
profileDir: opts.profile,
|
|
393
396
|
transportDir: join(installLayout().runsDir, '_models'),
|
|
394
397
|
chatUrl: opts.url,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything the bot has kept, as one file (operator, 2026-10-23: "an option to export everything saved so far under
|
|
3
|
+
* this profile — we keep it in the bot's folder anyway"): its settings, conversations, skills, level 2 templates and
|
|
4
|
+
* logs — `data/` — and, when asked for, every run's records — `runs/`. A `manifest.json` says what is in it and what
|
|
5
|
+
* was left out, and why: the API's key, which belongs to this machine alone, and the Edge profile, which holds the
|
|
6
|
+
* Microsoft 365 sign-in — a file carrying that would sign anybody who has it in as the operator.
|
|
7
|
+
*/
|
|
8
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
9
|
+
import { join, relative } from 'node:path';
|
|
10
|
+
/** Files of the data folder never exported, by name: this machine's key and the API's own bookkeeping. */
|
|
11
|
+
const NEVER = new Set(['api-token', 'dev-pids.json', '.cop-lock.json']);
|
|
12
|
+
function filesUnder(dir) {
|
|
13
|
+
const out = [];
|
|
14
|
+
const walk = (d) => {
|
|
15
|
+
let names;
|
|
16
|
+
try {
|
|
17
|
+
names = readdirSync(d);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const name of names) {
|
|
23
|
+
const p = join(d, name);
|
|
24
|
+
let st;
|
|
25
|
+
try {
|
|
26
|
+
st = statSync(p);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (st.isDirectory())
|
|
32
|
+
walk(p);
|
|
33
|
+
else if (st.isFile())
|
|
34
|
+
out.push({ path: p, size: st.size, mtime: st.mtime });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
walk(dir);
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const dataFiles = (layout) => filesUnder(layout.dataDir).filter((f) => !NEVER.has(relative(layout.dataDir, f.path).replace(/\\/g, '/')));
|
|
41
|
+
/** How much an export would hold: the data folder, and the runs' records if asked for. */
|
|
42
|
+
export function exportSizes(layout) {
|
|
43
|
+
const data = dataFiles(layout);
|
|
44
|
+
const runs = filesUnder(layout.runsDir);
|
|
45
|
+
return { data: data.reduce((n, f) => n + f.size, 0), dataFiles: data.length, runs: runs.reduce((n, f) => n + f.size, 0), runsFiles: runs.length };
|
|
46
|
+
}
|
|
47
|
+
/** The files of an export, named as they go in the archive (`data/…`, `runs/…`), and its manifest first. */
|
|
48
|
+
export function exportEntries(layout, opts) {
|
|
49
|
+
const now = opts.now ?? new Date();
|
|
50
|
+
const entries = [];
|
|
51
|
+
const add = (root, under) => (f) => {
|
|
52
|
+
entries.push({ name: `${under}/${relative(root, f.path).replace(/\\/g, '/')}`, data: readFileSync(f.path), mtime: f.mtime });
|
|
53
|
+
};
|
|
54
|
+
const data = dataFiles(layout);
|
|
55
|
+
data.forEach(add(layout.dataDir, 'data'));
|
|
56
|
+
const runs = opts.runs ? filesUnder(layout.runsDir) : [];
|
|
57
|
+
runs.forEach(add(layout.runsDir, 'runs'));
|
|
58
|
+
const manifest = {
|
|
59
|
+
exportedBy: `copilot-operator ${opts.version}`,
|
|
60
|
+
exportedAt: now.toISOString(),
|
|
61
|
+
from: layout.homeDir,
|
|
62
|
+
holds: [
|
|
63
|
+
{ what: 'data/', files: data.length, is: 'settings, conversations, skills, level 2 templates, logs' },
|
|
64
|
+
...(opts.runs ? [{ what: 'runs/', files: runs.length, is: "every run's records: transcripts, replies, reports" }] : []),
|
|
65
|
+
],
|
|
66
|
+
leftOut: [
|
|
67
|
+
{ what: 'data/api-token', why: "the key of this machine's API: it belongs to this machine alone" },
|
|
68
|
+
{ what: 'edge-profile/', why: 'the Edge profile holds the Microsoft 365 sign-in; anybody with it would be signed in as you' },
|
|
69
|
+
...(opts.runs ? [] : [{ what: 'runs/', why: 'not asked for' }]),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
return [{ name: 'manifest.json', data: Buffer.from(JSON.stringify(manifest, null, 2), 'utf8'), mtime: now }, ...entries];
|
|
73
|
+
}
|
|
74
|
+
/** The export's file name: copilot-operator-export-20261023-1142.zip. */
|
|
75
|
+
export function exportFileName(now = new Date()) {
|
|
76
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
77
|
+
return `copilot-operator-export-${now.getFullYear()}${two(now.getMonth() + 1)}${two(now.getDate())}-${two(now.getHours())}${two(now.getMinutes())}.zip`;
|
|
78
|
+
}
|
|
@@ -142,6 +142,28 @@ export const RunConfigSchema = z.object({
|
|
|
142
142
|
* runs/ is a folder on disk. The screenshot and the URL are always kept.
|
|
143
143
|
*/
|
|
144
144
|
keepFailurePage: z.boolean().default(false),
|
|
145
|
+
/**
|
|
146
|
+
* The model menu's locators (operator, 2026-10-24: "an option in Settings to edit the general locators, so the
|
|
147
|
+
* user can put the right ones when the page changes"): the picker button, the rows the names are read from, and
|
|
148
|
+
* the templates for a model of the main menu, a provider's row and a model in a provider's menu, with
|
|
149
|
+
* `{$model_name}` / `{$provider_name}` where the name goes. Each one left out, or empty, is the default in
|
|
150
|
+
* `transport/locators.ts`; one that cannot be used is not, and the run says why.
|
|
151
|
+
*/
|
|
152
|
+
pickerLocators: z
|
|
153
|
+
.object({
|
|
154
|
+
button: z.string().optional(),
|
|
155
|
+
rows: z.string().optional(),
|
|
156
|
+
model: z.string().optional(),
|
|
157
|
+
provider: z.string().optional(),
|
|
158
|
+
providerModel: z.string().optional(),
|
|
159
|
+
})
|
|
160
|
+
.optional(),
|
|
161
|
+
/**
|
|
162
|
+
* A picture and the menu's HTML at every step of choosing a model, with what each locator found (operator,
|
|
163
|
+
* 2026-10-24: "an option in Settings to keep this information"), beside the run's other browser files. Off: only
|
|
164
|
+
* a failed choice keeps the menu (models-select-failed.*).
|
|
165
|
+
*/
|
|
166
|
+
pickerSteps: z.boolean().default(false),
|
|
145
167
|
})
|
|
146
168
|
.prefault({}),
|
|
147
169
|
/** Level 1: the base prompt about how the runner works. Shipped with the project; editable in the UI. */
|
|
@@ -381,6 +381,10 @@ export function speakFor(transport, sessionId, opts = {}) {
|
|
|
381
381
|
if (opts.alone)
|
|
382
382
|
speaker.alone = true;
|
|
383
383
|
}
|
|
384
|
+
/** The model menu's locators and its step pictures, as Settings have them (2026-10-24), for every window that picks a model. */
|
|
385
|
+
export function pickerOptions(cfg) {
|
|
386
|
+
return { ...(cfg.copilot.pickerLocators ? { pickerLocators: cfg.copilot.pickerLocators } : {}), ...(cfg.copilot.pickerSteps ? { modelStepShots: true } : {}) };
|
|
387
|
+
}
|
|
384
388
|
export async function openBrowser(cfg, bus, transportDir, sessionId,
|
|
385
389
|
/** The run's Stop: a sign-in still awaited ends with it. */
|
|
386
390
|
signal) {
|
|
@@ -395,6 +399,7 @@ signal) {
|
|
|
395
399
|
signInTimeoutMs: cfg.copilot.signInTimeoutSec * 1000,
|
|
396
400
|
humanWaitMs: cfg.copilot.humanWaitSec * 1000,
|
|
397
401
|
keepFailurePage: cfg.copilot.keepFailurePage,
|
|
402
|
+
...pickerOptions(cfg),
|
|
398
403
|
onEvent: (event, detail) => {
|
|
399
404
|
const spoken = {
|
|
400
405
|
'sign-in-required': 'The chat is asking you to sign in. Do it in the open Edge window; the run is waiting.',
|
|
@@ -1143,9 +1148,14 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1143
1148
|
}
|
|
1144
1149
|
return check;
|
|
1145
1150
|
};
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1151
|
+
/*
|
|
1152
|
+
* A chat message's checkpoint and folder (2026-10-17), set where the task starts; read by `finish`. Not for a chat on
|
|
1153
|
+
* a branch of the runner's own (a task of the queue on a new branch from main, 2026-10-24): its work is committed on
|
|
1154
|
+
* that branch, and the photograph after it wrote over the task's record of the branch, so nothing was committed.
|
|
1155
|
+
*/
|
|
1156
|
+
const photographed = session.kind === 'chat' && !session.vcs?.enabled;
|
|
1157
|
+
let chatCheckpoint = photographed ? task.checkpoint : undefined;
|
|
1158
|
+
const chatDir = photographed ? session.projectDir?.trim() ?? '' : '';
|
|
1149
1159
|
const finish = async (status, reason, summary, finalReply) => {
|
|
1150
1160
|
// How it ended as reported; the runner's own checks below can still change it, and the final word is written at the end.
|
|
1151
1161
|
await record(`ENDING: ${status.toUpperCase()}`, [summary ?? '', reason ? `Reason: ${reason}` : ''].filter(Boolean).join('\n\n') || '(no details)');
|
|
@@ -1735,7 +1745,8 @@ export async function runTask(transport, session, task, deps) {
|
|
|
1735
1745
|
// The operator's new prompt goes out whether or not the attempt it follows reached a conversation.
|
|
1736
1746
|
...(task.continuing?.instruction ? { instruction: { text: task.continuing.instruction, fromAttempt: task.continuing.fromAttempt, ended: task.continuing.ended } } : {}),
|
|
1737
1747
|
workDirNote: workingDirNote(work),
|
|
1738
|
-
|
|
1748
|
+
// A chat on a branch of the runner's own (a task of the queue, 2026-10-24) is told about that branch, not the folder's.
|
|
1749
|
+
vcsNote: session.kind === 'chat' && !session.vcs?.enabled ? CHAT_NOTE : prepared.note,
|
|
1739
1750
|
// What is said about a commit is true only where one happens (live run 2026-10-03: promised with commits off).
|
|
1740
1751
|
referenceNote: forReference.length > 0 ? referenceNote(forReference, work.cwd) : undefined,
|
|
1741
1752
|
readOnlyNote: task.readOnly ? readOnlyNote(!!(session.vcs?.enabled && session.vcs.commitOnFinish !== false && trackedRepoOf(session)), artifactPatterns(session.vcs)) : undefined,
|