copilot-operator 0.1.63 → 0.1.66
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 +53 -3
- package/dist/src/api/operator.service.js +479 -57
- package/dist/src/exec/dangerous.js +12 -0
- package/dist/src/exec/runner.js +75 -2
- package/dist/src/exec/stepEnv.js +13 -2
- package/dist/src/orchestrator/taskRunner.js +12 -1
- package/dist/src/plan/kerrigan.js +63 -10
- package/dist/src/plan/systemGuide.js +202 -2
- package/dist/src/queue/queue.js +71 -4
- package/dist/src/queue/queueBranch.js +66 -0
- package/dist/src/session/compose.js +15 -0
- package/dist/src/session/store.js +4 -0
- package/dist/src/vcs/newBranch.js +241 -0
- package/dist/src/vcs/remoteAuth.js +119 -0
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/1024-444e9060299d04ba.js +1 -0
- package/dist/web/_next/static/chunks/1077.b88b069535f7008e.js +1 -0
- package/dist/web/_next/static/chunks/1548.9e01803e48173ea9.js +1 -0
- package/dist/web/_next/static/chunks/2163.018cd5f719ae4b3d.js +1 -0
- package/dist/web/_next/static/chunks/6262-d074473db83ee798.js +1 -0
- package/dist/web/_next/static/chunks/714.281f68f85df26013.js +1 -0
- package/dist/web/_next/static/chunks/7220.3bd10a3e4e053e0c.js +1 -0
- package/dist/web/_next/static/chunks/7921-1c173d00d23b3589.js +1 -0
- package/dist/web/_next/static/chunks/8124-bb544c96a7c0e7e3.js +1 -0
- package/dist/web/_next/static/chunks/8584.c7cd52c2e7075bcb.js +1 -0
- package/dist/web/_next/static/chunks/9067.feaf894390db1a88.js +1 -0
- package/dist/web/_next/static/chunks/9747.7cee8a2d8301f25c.js +1 -0
- package/dist/web/_next/static/chunks/app/{layout-9201c637ca24b2c9.js → layout-5e0e7601702723bb.js} +1 -1
- package/dist/web/_next/static/chunks/app/page-95379244849623fc.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/page-fb49cb2d3dc6d14c.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-38c956574db7c7a6.js → webpack-5ea108bc2e386c55.js} +1 -1
- package/dist/web/_next/static/css/a112074f3d1a8a07.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 +2 -2
- package/dist/web/queue.txt +9 -9
- 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 +4 -2
- package/dist/web/_next/static/chunks/1077.155f883ebfb223ae.js +0 -1
- package/dist/web/_next/static/chunks/1548.52fe19b2bb6dbe66.js +0 -1
- package/dist/web/_next/static/chunks/2163.51278cbd88674f1a.js +0 -1
- package/dist/web/_next/static/chunks/714.a3555e6b7e5f4339.js +0 -1
- package/dist/web/_next/static/chunks/7220.a7dcaec140695190.js +0 -1
- package/dist/web/_next/static/chunks/7921-b7eba39a21993047.js +0 -1
- package/dist/web/_next/static/chunks/8124-5458b17433987fab.js +0 -1
- package/dist/web/_next/static/chunks/8584.baf85c4394dc04eb.js +0 -1
- package/dist/web/_next/static/chunks/9067.2d7665cd257d7b47.js +0 -1
- package/dist/web/_next/static/chunks/9747.66a374501673612f.js +0 -1
- package/dist/web/_next/static/chunks/app/page-03f129240e06a07c.js +0 -1
- package/dist/web/_next/static/chunks/app/queue/page-f86936d39121ade8.js +0 -1
- package/dist/web/_next/static/css/2f2419505403ce07.css +0 -1
- /package/dist/web/_next/static/{kxZRE1oIu_arurqhfP4mS → BbWvNQTsh3pH7ZN_RKR60}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{kxZRE1oIu_arurqhfP4mS → BbWvNQTsh3pH7ZN_RKR60}/_ssgManifest.js +0 -0
|
@@ -20,7 +20,8 @@ import { join, resolve } from 'node:path';
|
|
|
20
20
|
import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
|
|
21
21
|
import { chooseHome, homeRefusal, movedFrom } from '../config/home.js';
|
|
22
22
|
import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW, writeFileAtomically } from '../session/store.js';
|
|
23
|
-
import { checkItems, emptyQueue, itemTitle,
|
|
23
|
+
import { checkItems, emptyQueue, itemTitle, mergeItems, nextStep, parkAfterMs, parkedAnswerFrom, skippedBecause, statusOfTask, waitsByHand, MAX_PARK_AFTER_SEC, PARKED_WORDS } from '../queue/queue.js';
|
|
24
|
+
import { branchStart, makeQueueBranch, refreshQueueBranch } from '../queue/queueBranch.js';
|
|
24
25
|
import { EventBus } from '../session/events.js';
|
|
25
26
|
import { MAX_INSTRUCTION_CHARS, newId } from '../session/model.js';
|
|
26
27
|
import { runSession, queuedToRun, failedWhileOpening, pickerOptions } from '../orchestrator/taskRunner.js';
|
|
@@ -36,6 +37,8 @@ import { chatCode } from '../transport/chatSession.js';
|
|
|
36
37
|
/** The folders the operator works in: the default new sessions start on, and the rest by name. */
|
|
37
38
|
/** The longest level 2 a project may have: Kerrigan carries each one whole. */
|
|
38
39
|
export const MAX_PROJECT_LEVEL2 = 8000;
|
|
40
|
+
/** The longest name a conversation or a session may be given (2026-10-26). */
|
|
41
|
+
export const MAX_SESSION_NAME = 120;
|
|
39
42
|
/*
|
|
40
43
|
* Its instructions have no limit of their own (operator, 2026-10-25: "remove the limit; say how many characters there
|
|
41
44
|
* are instead"): the message they go with is held to Settings' `limits.maxMessageChars` like every other — longer, its
|
|
@@ -66,7 +69,7 @@ import { searchWorkspace } from '../session/workspaceSearch.js';
|
|
|
66
69
|
import { restoreCheckpoint } from '../session/checkpoint.js';
|
|
67
70
|
import { readInterruption } from '../session/interruption.js';
|
|
68
71
|
import { baseRefOf, commitInterrupted, nextAttemptBranch, repoDirOf, trackedRepoOf, sessionBranchName } from '../vcs/taskVcs.js';
|
|
69
|
-
import { changedFilesBetween, fileAt, git, repoUnusableReason } from '../vcs/git.js';
|
|
72
|
+
import { branchExists, changedFilesBetween, fileAt, git, repoUnusableReason } from '../vcs/git.js';
|
|
70
73
|
import { makeAuthorizer } from '../exec/authorizer.js';
|
|
71
74
|
import { pickFolder } from './folderPicker.js';
|
|
72
75
|
import { findEdgeUsingProfile, profileHolder } from '../transport/profileLock.js';
|
|
@@ -86,6 +89,9 @@ import { sessionRoots } from '../exec/confinement.js';
|
|
|
86
89
|
import { dirtyPolicy } from '../vcs/snapshot.js';
|
|
87
90
|
import { runVcsPreflight } from '../vcs/runPreflight.js';
|
|
88
91
|
import { inputSettings, normalisePatterns } from '../vcs/inputs.js';
|
|
92
|
+
import { createNewBranch, planNewBranch } from '../vcs/newBranch.js';
|
|
93
|
+
import { askpassProgram, closePasswordWindows } from '../vcs/remoteAuth.js';
|
|
94
|
+
import { planApprovedMessage, planReviseMessage } from '../orchestrator/planMode.js';
|
|
89
95
|
import { coveredByArtifacts } from '../vcs/artifacts.js';
|
|
90
96
|
import { botVersion } from '../config/version.js';
|
|
91
97
|
import { exportEntries, exportFileName as homeExportName, exportSizes } from '../config/exportHome.js';
|
|
@@ -153,11 +159,28 @@ let OperatorService = class OperatorService {
|
|
|
153
159
|
* operator in another window): a worker's subtask is not the message.
|
|
154
160
|
*/
|
|
155
161
|
lastOutcome = null;
|
|
162
|
+
/** Where Git asks the operator for a password now, in its own window (2026-10-26): the step waits for it. */
|
|
163
|
+
passwordAsked = new Map();
|
|
156
164
|
followsActing = this.bus.subscribe('*', (e) => {
|
|
157
165
|
if (e.type === 'acting' && e.data)
|
|
158
166
|
this.acting.set(e.sessionId, e.data);
|
|
167
|
+
else if (e.type === 'password-window') {
|
|
168
|
+
const open = e.data?.open === true;
|
|
169
|
+
if (open)
|
|
170
|
+
this.passwordAsked.set(e.sessionId, e.at);
|
|
171
|
+
else
|
|
172
|
+
this.passwordAsked.delete(e.sessionId);
|
|
173
|
+
// In the queue, a password nobody types sets the task aside, as an unanswered card does (2026-10-26).
|
|
174
|
+
if (open) {
|
|
175
|
+
const step = Number(e.data?.id) || 0;
|
|
176
|
+
this.parkLater({ id: `pw-${e.sessionId}`, sessionId: e.sessionId, taskId: e.taskId ?? '', stepId: step, description: 'Git asked for a password in its own window', createdAt: e.at }, 'password');
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
this.unparkLater(`pw:${e.sessionId}`);
|
|
180
|
+
}
|
|
159
181
|
else if (e.type === 'task-finished') {
|
|
160
182
|
this.acting.delete(e.sessionId);
|
|
183
|
+
this.passwordAsked.delete(e.sessionId);
|
|
161
184
|
const status = e.data?.status;
|
|
162
185
|
if (typeof status === 'string' && !this.workerLeads.has(e.sessionId))
|
|
163
186
|
this.lastOutcome = { status, at: e.at, sessionId: e.sessionId };
|
|
@@ -296,6 +319,13 @@ let OperatorService = class OperatorService {
|
|
|
296
319
|
if (patch.active !== undefined && this.running.has(id)) {
|
|
297
320
|
throw new Error('This session is running; its status can be changed once it has stopped.');
|
|
298
321
|
}
|
|
322
|
+
/*
|
|
323
|
+
* A conversation renamed (operator, 2026-10-26: "an option to rename the chats"): any time, working or not — it is
|
|
324
|
+
* what the list calls it. The conversation in Copilot keeps its own name (`Session.chat.name`), which is how the bot
|
|
325
|
+
* finds it again.
|
|
326
|
+
*/
|
|
327
|
+
if (patch.name !== undefined && patch.name.trim().length > MAX_SESSION_NAME)
|
|
328
|
+
throw new Error(`A name can be at most ${MAX_SESSION_NAME} characters.`);
|
|
299
329
|
const updated = await this.store.updateSession(id, (s) => {
|
|
300
330
|
const before = { model: s.model, manualModel: s.manualModel };
|
|
301
331
|
if (patch.name !== undefined)
|
|
@@ -1053,6 +1083,8 @@ let OperatorService = class OperatorService {
|
|
|
1053
1083
|
starting,
|
|
1054
1084
|
...(acting ? { acting } : {}),
|
|
1055
1085
|
...(run?.hold?.held ? { paused: true } : {}),
|
|
1086
|
+
// Git asks for a password in its own window, and the work waits for it (2026-10-26).
|
|
1087
|
+
...(this.passwordAsked.size > 0 ? { password: true } : {}),
|
|
1056
1088
|
// How the last message ended, while nothing runs: what the tab says until the operator has looked.
|
|
1057
1089
|
...(this.running.size === 0 && this.lastOutcome ? { last: { status: this.lastOutcome.status, at: this.lastOutcome.at } } : {}),
|
|
1058
1090
|
};
|
|
@@ -1094,6 +1126,45 @@ let OperatorService = class OperatorService {
|
|
|
1094
1126
|
const cfg = await this.settings.load();
|
|
1095
1127
|
return await workspaceInfo(cfg.project?.rootDir ?? '', cfg.project?.name ?? '');
|
|
1096
1128
|
}
|
|
1129
|
+
// --- a new branch from main, from the chat (2026-10-26) --------------------------------------------------------
|
|
1130
|
+
/** Why the folder's branch may not be changed now: a task at work, or the queue between its tasks. */
|
|
1131
|
+
branchBusy() {
|
|
1132
|
+
if (this.running.size > 0 || this.browser?.kind === 'run')
|
|
1133
|
+
return 'A task is working: stop it or let it finish first; the branch is not changed under it.';
|
|
1134
|
+
if (this.queueLoop)
|
|
1135
|
+
return 'The queue is running: stop it first; the branch is not changed under its tasks.';
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* What a new branch from main would start from (see `vcs/newBranch.ts`). With `fetch`, the remote's main is fetched
|
|
1140
|
+
* first — through Git's own password window when the remote asks for one, which the bot never reads; without, what
|
|
1141
|
+
* was last fetched here.
|
|
1142
|
+
*/
|
|
1143
|
+
async newBranchPreview(fetch) {
|
|
1144
|
+
const ws = await this.workspace();
|
|
1145
|
+
if (!ws.ok)
|
|
1146
|
+
throw new Error(ws.problem ?? 'No project folder is open: open one first.');
|
|
1147
|
+
const busy = this.branchBusy();
|
|
1148
|
+
if (busy)
|
|
1149
|
+
throw new Error(busy);
|
|
1150
|
+
return await planNewBranch(ws.dir, { fetch, askpass: fetch ? await askpassProgram() : null });
|
|
1151
|
+
}
|
|
1152
|
+
/** The branch made and checked out, the uncommitted changes taken to it or put aside, as the operator chose. */
|
|
1153
|
+
async newBranchCreate(input) {
|
|
1154
|
+
const ws = await this.workspace();
|
|
1155
|
+
if (!ws.ok)
|
|
1156
|
+
throw new Error(ws.problem ?? 'No project folder is open: open one first.');
|
|
1157
|
+
const busy = this.branchBusy();
|
|
1158
|
+
if (busy)
|
|
1159
|
+
throw new Error(busy);
|
|
1160
|
+
return await createNewBranch(ws.dir, {
|
|
1161
|
+
name: typeof input.name === 'string' ? input.name : '',
|
|
1162
|
+
carry: input.carry === 'aside' ? 'aside' : 'take',
|
|
1163
|
+
fingerprint: typeof input.fingerprint === 'string' ? input.fingerprint : '',
|
|
1164
|
+
// The saved branch under the bot's own prefix, as its other branches are.
|
|
1165
|
+
prefix: DEFAULT_VCS.branchPrefix,
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1097
1168
|
/** The open folder's code, searched as VS Code's Search view does (2026-10-21, see `workspaceSearch.ts`). */
|
|
1098
1169
|
async workspaceSearch(query, opts) {
|
|
1099
1170
|
const ws = await this.workspace();
|
|
@@ -1161,7 +1232,7 @@ let OperatorService = class OperatorService {
|
|
|
1161
1232
|
* operator wrote for it. Nothing is sent anywhere: the page saves it or copies it. See `plan/kerrigan.ts`; in a
|
|
1162
1233
|
* language she is not written out in, the page fills in the names of the controls (`filled: false`).
|
|
1163
1234
|
*/
|
|
1164
|
-
async kerrigan(lang) {
|
|
1235
|
+
async kerrigan(lang, skill) {
|
|
1165
1236
|
const cfg = await this.settings.load();
|
|
1166
1237
|
const p = await this.project();
|
|
1167
1238
|
const projects = [
|
|
@@ -1170,7 +1241,13 @@ let OperatorService = class OperatorService {
|
|
|
1170
1241
|
];
|
|
1171
1242
|
// The skills, each with the name of the project it is for.
|
|
1172
1243
|
const nameOf = (dir) => [{ name: p.name || p.rootDir, rootDir: p.rootDir }, ...p.others].find((x) => x.rootDir && sameFolder(x.rootDir, dir))?.name ?? dir;
|
|
1173
|
-
const
|
|
1244
|
+
const all = (await this.skills()).skills;
|
|
1245
|
+
const skills = all.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}) }));
|
|
1246
|
+
// The skill chosen beside her button (2026-10-26): its instructions go with her text.
|
|
1247
|
+
const asked = skill?.trim().replace(/^\//, '').toLowerCase();
|
|
1248
|
+
const chosen = asked ? all.find((k) => k.name === asked) : undefined;
|
|
1249
|
+
if (asked && !chosen)
|
|
1250
|
+
throw new Error(`There is no skill called "${asked}" in Settings → Skills.`);
|
|
1174
1251
|
const text = kerriganPersona(lang, {
|
|
1175
1252
|
version: botVersion(),
|
|
1176
1253
|
skills,
|
|
@@ -1180,8 +1257,9 @@ let OperatorService = class OperatorService {
|
|
|
1180
1257
|
maxReviewRounds: cfg.limits.maxReviewRounds ?? 2,
|
|
1181
1258
|
maxSubtasks: cfg.limits.maxSubtasks ?? 20,
|
|
1182
1259
|
projects,
|
|
1260
|
+
...(chosen ? { chosenSkill: { name: chosen.name, description: chosen.description, text: chosen.text, ...(chosen.projectDir ? { project: nameOf(chosen.projectDir) } : {}) } } : {}),
|
|
1183
1261
|
});
|
|
1184
|
-
return { lang, fileName: kerriganFileName(lang), text, filled: lang === 'en' || lang === 'bg' };
|
|
1262
|
+
return { lang, fileName: kerriganFileName(lang, chosen?.name), text, filled: lang === 'en' || lang === 'bg' };
|
|
1185
1263
|
}
|
|
1186
1264
|
/** The chat's conversations, newest first. */
|
|
1187
1265
|
async chatThreads() {
|
|
@@ -1300,11 +1378,24 @@ let OperatorService = class OperatorService {
|
|
|
1300
1378
|
queueRecovered = false;
|
|
1301
1379
|
/** The program is closing: the queue's loop stops where it is. */
|
|
1302
1380
|
queueClosing = false;
|
|
1381
|
+
/** The session of the queue's task at work now (2026-10-26): where a wait for the operator is timed, to park it. */
|
|
1382
|
+
queueAtWork = new Set();
|
|
1383
|
+
/** The timers of the waits of the queue's task at work: a card, by its id; a password window, by `pw:` and the session. */
|
|
1384
|
+
parkTimers = new Map();
|
|
1385
|
+
/** Commands the operator approved on a parked task's card, run without asking when its chat sends them again. */
|
|
1386
|
+
approvedAhead = new Map();
|
|
1387
|
+
/** Branches made for tasks of the queue, one edit of the list at a time. */
|
|
1388
|
+
branchTurn = Promise.resolve();
|
|
1303
1389
|
/** The queue as it is on disk; one that cannot be read is an empty one, said in the console. */
|
|
1304
1390
|
async readQueue() {
|
|
1305
1391
|
try {
|
|
1306
1392
|
const q = JSON.parse(await readFile(this.queueFile, 'utf8'));
|
|
1307
|
-
return {
|
|
1393
|
+
return {
|
|
1394
|
+
items: Array.isArray(q.items) ? q.items : [],
|
|
1395
|
+
running: q.running === true,
|
|
1396
|
+
updatedAt: q.updatedAt ?? '',
|
|
1397
|
+
...(typeof q.parkAfterSec === 'number' ? { parkAfterSec: q.parkAfterSec } : {}),
|
|
1398
|
+
};
|
|
1308
1399
|
}
|
|
1309
1400
|
catch (e) {
|
|
1310
1401
|
if (e.code !== 'ENOENT')
|
|
@@ -1318,6 +1409,7 @@ let OperatorService = class OperatorService {
|
|
|
1318
1409
|
const q = await this.readQueue();
|
|
1319
1410
|
change(q);
|
|
1320
1411
|
q.updatedAt = new Date().toISOString();
|
|
1412
|
+
delete q.busy;
|
|
1321
1413
|
await writeFileAtomically(this.queueFile, JSON.stringify(q, null, 2));
|
|
1322
1414
|
return q;
|
|
1323
1415
|
};
|
|
@@ -1334,7 +1426,10 @@ let OperatorService = class OperatorService {
|
|
|
1334
1426
|
if (patch[key] === undefined)
|
|
1335
1427
|
delete item[key];
|
|
1336
1428
|
}
|
|
1337
|
-
/**
|
|
1429
|
+
/**
|
|
1430
|
+
* A queue that was running when the bot last closed: not running now, and its task in flight stopped. A parked task
|
|
1431
|
+
* stays parked, with what it waits for, and an answered one still carries on at the queue's next turn (2026-10-26).
|
|
1432
|
+
*/
|
|
1338
1433
|
async recoverQueue() {
|
|
1339
1434
|
if (this.queueRecovered)
|
|
1340
1435
|
return;
|
|
@@ -1352,7 +1447,24 @@ let OperatorService = class OperatorService {
|
|
|
1352
1447
|
}
|
|
1353
1448
|
async queue() {
|
|
1354
1449
|
await this.recoverQueue();
|
|
1355
|
-
return await this.readQueue();
|
|
1450
|
+
return await this.withBusy(await this.readQueue());
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* The queue as the page is shown it: with what has the browser now, when it is not the queue's own task (2026-10-25)
|
|
1454
|
+
* — a message working in the chat, a reading of the models, the sign-in. The queue's next task starts after it.
|
|
1455
|
+
*/
|
|
1456
|
+
async withBusy(q) {
|
|
1457
|
+
const holder = this.browser;
|
|
1458
|
+
if (!holder)
|
|
1459
|
+
return q;
|
|
1460
|
+
if (holder.kind !== 'run')
|
|
1461
|
+
return { ...q, busy: { kind: holder.kind } };
|
|
1462
|
+
if (q.items.some((x) => x.status === 'running' && x.sessionId === holder.sessionId))
|
|
1463
|
+
return q;
|
|
1464
|
+
const s = await this.store.getSession(holder.sessionId);
|
|
1465
|
+
const at = s?.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval') ?? s?.tasks.find((t) => t.status === 'queued');
|
|
1466
|
+
const busy = { kind: 'chat', sessionId: holder.sessionId, title: at?.title ?? s?.name.replace(/^chat: /, '') ?? '' };
|
|
1467
|
+
return { ...q, busy };
|
|
1356
1468
|
}
|
|
1357
1469
|
/** The list as the page edits it: added, changed, moved, taken out, put back to wait ("Run again"). */
|
|
1358
1470
|
async setQueue(items) {
|
|
@@ -1360,6 +1472,13 @@ let OperatorService = class OperatorService {
|
|
|
1360
1472
|
const checked = checkItems(items, MAX_INSTRUCTION_CHARS);
|
|
1361
1473
|
if ('problem' in checked)
|
|
1362
1474
|
throw new Error(checked.problem);
|
|
1475
|
+
// A skill is one of Settings' (2026-10-25); whether it is for the folder is said when the task runs, in its chat.
|
|
1476
|
+
const { skills } = await this.skills();
|
|
1477
|
+
const unknown = checked.items.findIndex((x) => x.skill && !skills.some((k) => k.name === x.skill));
|
|
1478
|
+
if (unknown >= 0) {
|
|
1479
|
+
const name = checked.items[unknown].skill;
|
|
1480
|
+
throw new Error(`Task ${unknown + 1} is sent with the skill "${name}", which is not in Settings → Skills${skills.length > 0 ? `; there are ${skills.map((k) => k.name).join(', ')}` : ''}.`);
|
|
1481
|
+
}
|
|
1363
1482
|
let problem;
|
|
1364
1483
|
const q = await this.changeQueue((x) => {
|
|
1365
1484
|
const merged = mergeItems(x.items, checked.items);
|
|
@@ -1370,7 +1489,52 @@ let OperatorService = class OperatorService {
|
|
|
1370
1489
|
});
|
|
1371
1490
|
if (problem)
|
|
1372
1491
|
throw new Error(problem);
|
|
1373
|
-
return q;
|
|
1492
|
+
return await this.withBusy(await this.makeQueueBranches(q));
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* The branches of the tasks "on a new branch from main" that have none yet (2026-10-26), made now, while the operator
|
|
1496
|
+
* is at the page: the remote's main fetched once — through Git's own window if it asks for a password — and a branch
|
|
1497
|
+
* made at it for each, not checked out. A branch that cannot be made now is made when the task starts.
|
|
1498
|
+
*/
|
|
1499
|
+
makeQueueBranches(q) {
|
|
1500
|
+
const run = async () => {
|
|
1501
|
+
const need = q.items.filter((x) => x.branch === 'main' && x.status === 'waiting' && !x.branchName);
|
|
1502
|
+
if (need.length === 0)
|
|
1503
|
+
return q;
|
|
1504
|
+
const ws = await this.workspace();
|
|
1505
|
+
if (!ws.ok || !ws.isRepo)
|
|
1506
|
+
return q;
|
|
1507
|
+
const start = await branchStart(ws.dir, await askpassProgram());
|
|
1508
|
+
const made = [];
|
|
1509
|
+
for (const item of need) {
|
|
1510
|
+
if ('problem' in start) {
|
|
1511
|
+
made.push({ id: item.id, patch: { why: `no branch could be made for it yet (${start.problem}); one is made when it starts` } });
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
const branch = await makeQueueBranch(ws.dir, item.id, itemTitle(item), start);
|
|
1515
|
+
made.push({ id: item.id, patch: 'problem' in branch ? { why: `no branch could be made for it yet (${branch.problem}); one is made when it starts` } : { branchName: branch.branch, branchBase: branch.base, branchFrom: start.from, why: undefined } });
|
|
1516
|
+
}
|
|
1517
|
+
return await this.changeQueue((x) => {
|
|
1518
|
+
for (const m of made) {
|
|
1519
|
+
const item = x.items.find((i) => i.id === m.id);
|
|
1520
|
+
// Still a task that needs it: an edit meanwhile may have taken it out or changed where it works.
|
|
1521
|
+
if (item && item.branch === 'main' && !item.branchName)
|
|
1522
|
+
this.setQueueItem(x, m.id, m.patch);
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
};
|
|
1526
|
+
const done = this.branchTurn.then(run, run);
|
|
1527
|
+
this.branchTurn = done.catch(() => undefined);
|
|
1528
|
+
return done;
|
|
1529
|
+
}
|
|
1530
|
+
/** The queue's own settings, from its page (2026-10-26): how long a task may wait for the operator before it is parked. */
|
|
1531
|
+
async setQueueSettings(input) {
|
|
1532
|
+
const sec = Number(input?.parkAfterSec);
|
|
1533
|
+
if (!Number.isFinite(sec) || sec < 0 || sec > MAX_PARK_AFTER_SEC)
|
|
1534
|
+
throw new Error(`The wait is a number of seconds, from 0 (as long as it takes) to ${MAX_PARK_AFTER_SEC}.`);
|
|
1535
|
+
return await this.withBusy(await this.changeQueue((x) => {
|
|
1536
|
+
x.parkAfterSec = Math.round(sec);
|
|
1537
|
+
}));
|
|
1374
1538
|
}
|
|
1375
1539
|
/** Runs the waiting tasks one after another, in the background; the page follows `queue()`. */
|
|
1376
1540
|
async runQueue() {
|
|
@@ -1384,7 +1548,7 @@ let OperatorService = class OperatorService {
|
|
|
1384
1548
|
const ws = await this.workspace();
|
|
1385
1549
|
if (!ws.ok)
|
|
1386
1550
|
throw new Error(ws.problem ?? 'No project folder is open: open one in the chat first.');
|
|
1387
|
-
const unnamed = this.queueWithoutModel(q.items.filter((x) => x.status === 'waiting'), await this.settings.load());
|
|
1551
|
+
const unnamed = this.queueWithoutModel(q.items.filter((x) => x.status === 'waiting' && !x.resume), await this.settings.load());
|
|
1388
1552
|
if (unnamed)
|
|
1389
1553
|
throw new Error(unnamed);
|
|
1390
1554
|
const started = await this.changeQueue((x) => {
|
|
@@ -1398,7 +1562,7 @@ let OperatorService = class OperatorService {
|
|
|
1398
1562
|
x.running = false;
|
|
1399
1563
|
});
|
|
1400
1564
|
});
|
|
1401
|
-
return started;
|
|
1565
|
+
return await this.withBusy(started);
|
|
1402
1566
|
}
|
|
1403
1567
|
/**
|
|
1404
1568
|
* Tasks that would wait for the operator to choose their model by hand: none of their own, and no "Model for the
|
|
@@ -1420,7 +1584,105 @@ let OperatorService = class OperatorService {
|
|
|
1420
1584
|
const at = q.items.find((x) => x.status === 'running');
|
|
1421
1585
|
if (at?.sessionId)
|
|
1422
1586
|
await this.stop(at.sessionId).catch(() => undefined);
|
|
1423
|
-
return q;
|
|
1587
|
+
return await this.withBusy(q);
|
|
1588
|
+
}
|
|
1589
|
+
// --- a task of the queue set aside while it waits for the operator (2026-10-26) ---------------------------------
|
|
1590
|
+
//
|
|
1591
|
+
// Operator: "if I run a queue, every question has a timeout, since I may not be at the computer to answer; the work
|
|
1592
|
+
// on that task stops and the next one starts; the question is kept, for me to answer later, and everything is kept
|
|
1593
|
+
// even when the program is closed." A card of the task at work — a plan, a question, a subtask cut off, a command, a
|
|
1594
|
+
// model to choose — or Git's password window, unanswered for as long as the queue allows: the task is stopped as
|
|
1595
|
+
// Stop stops it (its work committed on its branch), the card kept on its record, and the queue goes on.
|
|
1596
|
+
/** What a card asks for, as a parked task keeps it. */
|
|
1597
|
+
parkedKindOf(a) {
|
|
1598
|
+
return a.plan ? 'plan' : a.question ? 'question' : a.retry ? 'retry' : a.model ? 'model' : 'command';
|
|
1599
|
+
}
|
|
1600
|
+
/** A card of the queue's task at work, timed: unanswered for as long as the queue allows, the task is parked. */
|
|
1601
|
+
parkLater(approval, kind = this.parkedKindOf(approval)) {
|
|
1602
|
+
const key = this.runKey(approval.sessionId);
|
|
1603
|
+
if (!this.queueAtWork.has(key))
|
|
1604
|
+
return;
|
|
1605
|
+
const timerKey = kind === 'password' ? `pw:${approval.sessionId}` : approval.id;
|
|
1606
|
+
void this.readQueue().then((q) => {
|
|
1607
|
+
const ms = parkAfterMs(q);
|
|
1608
|
+
if (ms === null || this.parkTimers.has(timerKey))
|
|
1609
|
+
return;
|
|
1610
|
+
const timer = setTimeout(() => {
|
|
1611
|
+
this.parkTimers.delete(timerKey);
|
|
1612
|
+
const still = kind === 'password' ? this.passwordAsked.has(approval.sessionId) : this.waiting.has(approval.id);
|
|
1613
|
+
if (still)
|
|
1614
|
+
void this.park(key, approval, kind, ms).catch((e) => console.error('[queue] the task could not be set aside:', e.message));
|
|
1615
|
+
}, ms);
|
|
1616
|
+
timer.unref?.();
|
|
1617
|
+
this.parkTimers.set(timerKey, timer);
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
unparkLater(timerKey) {
|
|
1621
|
+
const timer = this.parkTimers.get(timerKey);
|
|
1622
|
+
if (timer)
|
|
1623
|
+
clearTimeout(timer);
|
|
1624
|
+
this.parkTimers.delete(timerKey);
|
|
1625
|
+
}
|
|
1626
|
+
/** The queue's task at work set aside: what it waits for kept on its record and on the queue's, then stopped. */
|
|
1627
|
+
async park(key, approval, kind, waitedMs) {
|
|
1628
|
+
if (!this.queueAtWork.has(key))
|
|
1629
|
+
return;
|
|
1630
|
+
const s = await this.store.getSession(key);
|
|
1631
|
+
const task = s?.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval');
|
|
1632
|
+
if (!s || !task)
|
|
1633
|
+
return;
|
|
1634
|
+
const at = new Date().toISOString();
|
|
1635
|
+
await this.store.updateSession(key, (x) => {
|
|
1636
|
+
const t = x.tasks.find((y) => y.id === task.id);
|
|
1637
|
+
if (t)
|
|
1638
|
+
t.parked = { kind, at, approval };
|
|
1639
|
+
});
|
|
1640
|
+
await this.changeQueue((x) => {
|
|
1641
|
+
const item = x.items.find((i) => i.sessionId === key && i.status === 'running');
|
|
1642
|
+
if (item)
|
|
1643
|
+
this.setQueueItem(x, item.id, { waitsFor: { kind, at, approval } });
|
|
1644
|
+
});
|
|
1645
|
+
this.bus.publish({ sessionId: key, taskId: task.id, type: 'task-parked', level: 'warn', data: { kind },
|
|
1646
|
+
message: `set aside after waiting ${Math.round(waitedMs / 1000)} s for the operator (${kind}); the queue goes on with the next task, and what it waits for is kept to be answered later` });
|
|
1647
|
+
// Git's own window, left on screen by the step it asked for: closed, so it does not ask for nothing.
|
|
1648
|
+
if (kind === 'password') {
|
|
1649
|
+
const ask = await askpassProgram();
|
|
1650
|
+
if (ask)
|
|
1651
|
+
await closePasswordWindows(ask, new Date(Date.parse(approval.createdAt) - 5_000)).catch(() => 0);
|
|
1652
|
+
}
|
|
1653
|
+
await this.stop(key).catch(() => undefined);
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* The operator's answer to a parked task, given when they are back (2026-10-26): kept on the task's record, and the
|
|
1657
|
+
* task waits to carry on from where it stopped — at the queue's next turn, before the others; when the queue is not
|
|
1658
|
+
* running, when it is run. `stop` leaves it stopped.
|
|
1659
|
+
*/
|
|
1660
|
+
async answerParked(itemId, input) {
|
|
1661
|
+
await this.recoverQueue();
|
|
1662
|
+
const q = await this.readQueue();
|
|
1663
|
+
const item = q.items.find((x) => x.id === itemId);
|
|
1664
|
+
if (!item)
|
|
1665
|
+
throw new Error('That task is not in the queue any more.');
|
|
1666
|
+
if (item.status !== 'parked' || !item.sessionId)
|
|
1667
|
+
throw new Error('That task is not waiting for an answer.');
|
|
1668
|
+
const s = await this.store.getSession(item.sessionId);
|
|
1669
|
+
const task = s?.tasks.find((t) => t.parked && !t.parked.answer);
|
|
1670
|
+
if (!s || !task?.parked)
|
|
1671
|
+
throw new Error('What that task waited for is not on its record any more; run it again.');
|
|
1672
|
+
if (input?.stop === true) {
|
|
1673
|
+
return await this.withBusy(await this.changeQueue((x) => this.setQueueItem(x, itemId, { status: 'stopped', why: 'stopped by the operator at its card', waitsFor: undefined })));
|
|
1674
|
+
}
|
|
1675
|
+
const answer = parkedAnswerFrom(task.parked, input);
|
|
1676
|
+
if ('problem' in answer)
|
|
1677
|
+
throw new Error(answer.problem);
|
|
1678
|
+
await this.store.updateSession(s.id, (x) => {
|
|
1679
|
+
const t = x.tasks.find((y) => y.id === task.id);
|
|
1680
|
+
if (t?.parked)
|
|
1681
|
+
t.parked.answer = { ...answer, at: new Date().toISOString() };
|
|
1682
|
+
});
|
|
1683
|
+
const next = await this.changeQueue((x) => this.setQueueItem(x, itemId, { status: 'waiting', resume: true, why: x.running ? 'answered: it carries on after the task at work' : 'answered: it carries on when the queue is run' }));
|
|
1684
|
+
this.bus.publish({ sessionId: s.id, taskId: task.id, type: 'task-answered', level: 'info', message: `the operator answered what the task waited for (${task.parked.kind}); it carries on at the queue's next turn` });
|
|
1685
|
+
return await this.withBusy(next);
|
|
1424
1686
|
}
|
|
1425
1687
|
async runQueueLoop() {
|
|
1426
1688
|
const now = () => new Date().toISOString();
|
|
@@ -1437,16 +1699,27 @@ let OperatorService = class OperatorService {
|
|
|
1437
1699
|
await this.changeQueue((x) => this.setQueueItem(x, step.skip.id, { status: 'skipped', why: skippedBecause(step.because), endedAt: now() }));
|
|
1438
1700
|
continue;
|
|
1439
1701
|
}
|
|
1702
|
+
/*
|
|
1703
|
+
* Its turn comes when the browser is free (operator, 2026-10-25: "I add a task while one sent from the chat runs;
|
|
1704
|
+
* the new one starts after it"): whatever has it — a message of the chat, a reading of the models, the sign-in —
|
|
1705
|
+
* ends first. It waits as a task that waits, so it can still be edited, moved or taken out, and the queue is read
|
|
1706
|
+
* again before it is taken.
|
|
1707
|
+
*/
|
|
1708
|
+
if (this.browser) {
|
|
1709
|
+
await new Promise((r) => setTimeout(r, 1_000));
|
|
1710
|
+
continue;
|
|
1711
|
+
}
|
|
1440
1712
|
const item = step.run;
|
|
1441
|
-
|
|
1713
|
+
// An answered parked task keeps its chat: it carries on there.
|
|
1714
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, waitsFor: undefined, resume: undefined, ...(item.resume ? {} : { sessionId: undefined }) }));
|
|
1442
1715
|
const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
|
|
1443
1716
|
await this.changeQueue((x) => this.setQueueItem(x, item.id, { ...ended, endedAt: now() }));
|
|
1444
|
-
// Stopped — from the queue, or the chat's Stop: the rest wait for the operator.
|
|
1717
|
+
// Stopped — from the queue, or the chat's Stop: the rest wait for the operator. Parked: the queue goes on.
|
|
1445
1718
|
if (ended.status === 'stopped')
|
|
1446
1719
|
return;
|
|
1447
1720
|
}
|
|
1448
1721
|
}
|
|
1449
|
-
/** One task of the queue, in a new chat, to its end. */
|
|
1722
|
+
/** One task of the queue, in a new chat — or, answered after it was parked, in its own — to its end. */
|
|
1450
1723
|
async runQueueItem(item) {
|
|
1451
1724
|
const pause = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1452
1725
|
const stillRunning = async () => (await this.readQueue()).running;
|
|
@@ -1461,55 +1734,190 @@ let OperatorService = class OperatorService {
|
|
|
1461
1734
|
const ws = await this.workspace();
|
|
1462
1735
|
if (!ws.ok)
|
|
1463
1736
|
return { status: 'failed', why: ws.problem ?? 'no project folder is open' };
|
|
1464
|
-
// Settings may have changed since the queue was started.
|
|
1465
|
-
const unnamed = this.queueWithoutModel([item], await this.settings.load());
|
|
1466
|
-
if (unnamed)
|
|
1467
|
-
return { status: 'failed', why: unnamed };
|
|
1468
|
-
const base = item.branch === 'main' ? await mainBranchOf(ws.dir) : null;
|
|
1469
|
-
if (item.branch === 'main' && !base)
|
|
1470
|
-
return { status: 'failed', why: `${ws.dir} has no main (or master) branch to make a new branch from` };
|
|
1471
|
-
// As the chat's box sends a first message: the model, the review and its model, or two chats and the worker's model.
|
|
1472
|
-
const sent = await this.chatSend({
|
|
1473
|
-
text: item.prompt,
|
|
1474
|
-
...(item.model ? { model: item.model } : {}),
|
|
1475
|
-
review: item.review,
|
|
1476
|
-
...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
|
|
1477
|
-
...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
|
|
1478
|
-
});
|
|
1479
|
-
const sessionId = sent.threadId;
|
|
1480
|
-
await this.store.updateSession(sessionId, (s) => {
|
|
1481
|
-
s.name = `queue: ${itemTitle(item)}`;
|
|
1482
|
-
s.queueItem = item.id;
|
|
1483
|
-
/*
|
|
1484
|
-
* A new branch from main (2026-10-24): the runner's own version control, as a session of the bot's has it — the
|
|
1485
|
-
* branch cut from main, brought up to date from the server first when that needs no password (`updateFromRemote`
|
|
1486
|
-
* asks nobody anything; it fails, and the local main is used), and the work committed on it. The chat is told
|
|
1487
|
-
* which main it was (`noteFor`).
|
|
1488
|
-
*/
|
|
1489
|
-
if (base) {
|
|
1490
|
-
s.vcs = { ...DEFAULT_VCS, enabled: true, repoDir: ws.dir, branchMode: 'per-session', commitOnFinish: true, startFrom: 'branch', baseBranch: base, updateFromRemote: true };
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
|
|
1494
1737
|
const cfg = await this.settings.load();
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1738
|
+
let sessionId;
|
|
1739
|
+
let taskId;
|
|
1740
|
+
if (item.resume && item.sessionId) {
|
|
1741
|
+
const carried = await this.resumeParked(item.sessionId, ws.dir);
|
|
1742
|
+
if ('problem' in carried)
|
|
1743
|
+
return { status: 'failed', why: carried.problem, sessionId: item.sessionId };
|
|
1744
|
+
sessionId = item.sessionId;
|
|
1745
|
+
taskId = carried.taskId;
|
|
1746
|
+
}
|
|
1747
|
+
else {
|
|
1748
|
+
// Settings may have changed since the queue was started.
|
|
1749
|
+
const unnamed = this.queueWithoutModel([item], cfg);
|
|
1750
|
+
if (unnamed)
|
|
1751
|
+
return { status: 'failed', why: unnamed };
|
|
1752
|
+
// Its own branch, made when it was added (2026-10-26): brought up to the remote's main if nothing is on it yet.
|
|
1753
|
+
let branchName = item.branch === 'main' && ws.isRepo ? item.branchName : undefined;
|
|
1754
|
+
if (branchName && item.branchBase) {
|
|
1755
|
+
if (!(await branchExists(ws.dir, branchName)))
|
|
1756
|
+
branchName = undefined;
|
|
1757
|
+
else {
|
|
1758
|
+
const fresh = await refreshQueueBranch(ws.dir, branchName, item.branchBase);
|
|
1759
|
+
if (fresh.moved)
|
|
1760
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { branchBase: fresh.base, branchFrom: 'origin/main' }));
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
// Not made when it was added — no repository then, or no main to make it from: made now, asking nobody anything.
|
|
1764
|
+
let branchFrom = item.branchFrom;
|
|
1765
|
+
if (item.branch === 'main' && ws.isRepo && !branchName) {
|
|
1766
|
+
const start = await branchStart(ws.dir, null);
|
|
1767
|
+
if ('problem' in start)
|
|
1768
|
+
return { status: 'failed', why: `no branch could be made for it: ${start.problem}` };
|
|
1769
|
+
const made = await makeQueueBranch(ws.dir, item.id, itemTitle(item), start);
|
|
1770
|
+
if ('problem' in made)
|
|
1771
|
+
return { status: 'failed', why: `no branch could be made for it: ${made.problem}` };
|
|
1772
|
+
branchName = made.branch;
|
|
1773
|
+
branchFrom = start.from;
|
|
1774
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { branchName: made.branch, branchBase: made.base, branchFrom: start.from }));
|
|
1775
|
+
}
|
|
1776
|
+
if (item.branch === 'main' && !ws.isRepo)
|
|
1777
|
+
return { status: 'failed', why: `${ws.dir} is not a git repository, so there is no main to make a branch from` };
|
|
1778
|
+
// As the chat's box sends a first message: the model, plan first, the review and its model, two chats, the skill.
|
|
1779
|
+
const sent = await this.chatSend({
|
|
1780
|
+
text: item.prompt,
|
|
1781
|
+
...(item.model ? { model: item.model } : {}),
|
|
1782
|
+
...(item.plan ? { planMode: true } : {}),
|
|
1783
|
+
review: item.review,
|
|
1784
|
+
...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
|
|
1785
|
+
...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
|
|
1786
|
+
...(item.skill ? { skill: item.skill } : {}),
|
|
1787
|
+
});
|
|
1788
|
+
sessionId = sent.threadId;
|
|
1789
|
+
taskId = sent.taskId;
|
|
1790
|
+
await this.store.updateSession(sessionId, (s) => {
|
|
1791
|
+
s.name = `queue: ${itemTitle(item)}`;
|
|
1792
|
+
s.queueItem = item.id;
|
|
1793
|
+
// The runner's own version control on the branch made for it, its work committed there (`existing-branch`).
|
|
1794
|
+
if (branchName)
|
|
1795
|
+
s.vcs = { ...DEFAULT_VCS, enabled: true, repoDir: ws.dir, commitOnFinish: true, startFrom: 'existing-branch', existingBranch: branchName };
|
|
1796
|
+
});
|
|
1797
|
+
// Where its branch came from, told with its opening message: the local main when the server's could not be read.
|
|
1798
|
+
if (branchName) {
|
|
1799
|
+
await this.store.addTaskNote(sessionId, taskId, branchFrom && branchFrom !== 'origin/main'
|
|
1800
|
+
? `This task works on its own branch ${branchName}, made from the local \`${branchFrom}\`: the server's main could not be fetched without asking for a password, and a run never types one. Do not try to fetch or pull it.`
|
|
1801
|
+
: `This task works on its own branch ${branchName}, made from the server's main (${branchFrom ?? 'origin/main'}). Do not switch to another branch.`).catch(() => undefined);
|
|
1506
1802
|
}
|
|
1803
|
+
await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
|
|
1804
|
+
}
|
|
1805
|
+
/*
|
|
1806
|
+
* A message of the chat sent meanwhile has the browser: this one starts after it, never refused for it. The browser
|
|
1807
|
+
* is looked at and taken in the same moment — `start` takes it before it awaits anything.
|
|
1808
|
+
*/
|
|
1809
|
+
while (holder()) {
|
|
1810
|
+
if (this.queueClosing || !(await stillRunning()))
|
|
1811
|
+
return { status: 'stopped', why: 'the queue was stopped before it began', sessionId };
|
|
1507
1812
|
await pause(1_000);
|
|
1508
1813
|
}
|
|
1509
|
-
|
|
1814
|
+
this.queueAtWork.add(sessionId);
|
|
1815
|
+
try {
|
|
1816
|
+
const reply = await this.start(sessionId, cfg.execution.mode);
|
|
1817
|
+
if (!reply.started)
|
|
1818
|
+
return { status: 'failed', why: reply.reason ?? 'it did not start', sessionId };
|
|
1819
|
+
// Until its run has ended and its window let the browser go, so the next one can have it.
|
|
1820
|
+
let asked = false;
|
|
1821
|
+
while (this.running.has(sessionId) || (holder()?.kind === 'run' && holder().sessionId === sessionId)) {
|
|
1822
|
+
if (this.queueClosing)
|
|
1823
|
+
return { status: 'stopped', why: 'the bot was closed while it ran', sessionId };
|
|
1824
|
+
if (!asked && !(await stillRunning())) {
|
|
1825
|
+
asked = true;
|
|
1826
|
+
await this.stop(sessionId).catch(() => undefined);
|
|
1827
|
+
}
|
|
1828
|
+
await pause(1_000);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
finally {
|
|
1832
|
+
this.queueAtWork.delete(sessionId);
|
|
1833
|
+
}
|
|
1834
|
+
const task = (await this.store.getSession(sessionId))?.tasks.find((t) => t.id === taskId);
|
|
1835
|
+
// Set aside while it waited for the operator: what for, said; the card is on its record and on the queue's.
|
|
1836
|
+
if (task?.parked && !task.parked.answer) {
|
|
1837
|
+
// Its ending says so, rather than "stopped by the operator": nobody stopped it.
|
|
1838
|
+
const why = `waits for you: ${PARKED_WORDS[task.parked.kind]}`;
|
|
1839
|
+
await this.store.updateSession(sessionId, (x) => {
|
|
1840
|
+
const t = x.tasks.find((y) => y.id === taskId);
|
|
1841
|
+
if (t)
|
|
1842
|
+
t.reason = `set aside by the queue while it waited for you; it ${why}`;
|
|
1843
|
+
});
|
|
1844
|
+
return { status: 'parked', why, sessionId };
|
|
1845
|
+
}
|
|
1510
1846
|
const status = statusOfTask(task?.status);
|
|
1511
1847
|
return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
|
|
1512
1848
|
}
|
|
1849
|
+
/**
|
|
1850
|
+
* A parked task, answered, carried on in its own chat from where it stopped (2026-10-26): the answer does what it
|
|
1851
|
+
* says — a plan approved stays approved, a plan sent back is made again first, a command approved runs without asking
|
|
1852
|
+
* when its chat sends it again, a subtask cut off is tried again as chosen — and it goes to the chat as the operator's
|
|
1853
|
+
* note with the attempt that carries the task on.
|
|
1854
|
+
*/
|
|
1855
|
+
async resumeParked(sessionId, dir) {
|
|
1856
|
+
const s = await this.store.getSession(sessionId);
|
|
1857
|
+
const task = s?.tasks.find((t) => t.parked?.answer);
|
|
1858
|
+
const p = task?.parked;
|
|
1859
|
+
const a = p?.answer;
|
|
1860
|
+
if (!s || !task || !p || !a)
|
|
1861
|
+
return { problem: 'its answer is not on its record any more; run it again' };
|
|
1862
|
+
const continuing = { fromAttempt: task.attempt ?? 1, stoppedBecause: task.reason, how: 'parked', parkedFor: p.kind };
|
|
1863
|
+
let note = '';
|
|
1864
|
+
let approvedPlan;
|
|
1865
|
+
const command = p.approval.description.replace(/^\[[\w-]+\]\s*/, '');
|
|
1866
|
+
if (a.kind === 'plan') {
|
|
1867
|
+
if (a.decision === 'approve' && p.approval.plan) {
|
|
1868
|
+
approvedPlan = { ...p.approval.plan.plan, approved: { by: 'operator', at: a.at, ...(a.note?.trim() ? { note: a.note.trim() } : {}) } };
|
|
1869
|
+
note = planApprovedMessage(approvedPlan.approved);
|
|
1870
|
+
}
|
|
1871
|
+
else {
|
|
1872
|
+
continuing.replan = true;
|
|
1873
|
+
note = planReviseMessage(a.note?.trim() || 'Make the plan more concrete: name the files and the stages.', p.approval.plan?.plan.version ?? 1);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
else if (a.kind === 'question') {
|
|
1877
|
+
note = `You asked: ${p.approval.question?.text ?? ''}\n\nThe operator answers: ${a.answer}`;
|
|
1878
|
+
}
|
|
1879
|
+
else if (a.kind === 'retry' && p.approval.retry) {
|
|
1880
|
+
const r = p.approval.retry;
|
|
1881
|
+
if (a.choice === 'accept')
|
|
1882
|
+
note = `Subtask ${r.n} (${r.title}) is taken as failed, at the operator's word: decide what to do next without it.`;
|
|
1883
|
+
else {
|
|
1884
|
+
if (a.choice === 'restore') {
|
|
1885
|
+
const worker = await this.store.getSession(p.approval.sessionId);
|
|
1886
|
+
const cp = worker?.tasks.find((t) => t.id === p.approval.taskId)?.checkpoint;
|
|
1887
|
+
const back = cp ? await restoreCheckpoint(dir, cp) : { ok: false, problem: 'the subtask\'s start was not photographed' };
|
|
1888
|
+
if (!back.ok)
|
|
1889
|
+
return { problem: `the folder could not be put back to the subtask's start (${back.problem}); answer it again with another choice` };
|
|
1890
|
+
}
|
|
1891
|
+
continuing.retrySubtask = { n: r.n, ...(a.choice === 'fresh' ? { fresh: true } : {}) };
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
else if (a.kind === 'command') {
|
|
1895
|
+
if (a.decision === 'run') {
|
|
1896
|
+
this.approvedAhead.set(sessionId, [...(this.approvedAhead.get(sessionId) ?? []), command.trim()]);
|
|
1897
|
+
note = `The command you were waiting to run is approved now: ${command}\n\nSend it again and it runs.`;
|
|
1898
|
+
}
|
|
1899
|
+
else
|
|
1900
|
+
note = `The command ${command} is not approved: do without it.`;
|
|
1901
|
+
}
|
|
1902
|
+
else {
|
|
1903
|
+
note =
|
|
1904
|
+
p.kind === 'password'
|
|
1905
|
+
? 'The operator is here now: run again the git command that waited for a password; Git asks for it in its own window, which the operator answers.'
|
|
1906
|
+
: 'The operator is here now: the model is chosen by hand in the Copilot window when it is asked for.';
|
|
1907
|
+
}
|
|
1908
|
+
await this.store.rerunTask(sessionId, task.id, {}, continuing);
|
|
1909
|
+
if (approvedPlan) {
|
|
1910
|
+
await this.store.updateSession(sessionId, (x) => {
|
|
1911
|
+
const t = x.tasks.find((y) => y.id === task.id);
|
|
1912
|
+
if (t)
|
|
1913
|
+
t.plan = approvedPlan;
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
if (note)
|
|
1917
|
+
await this.store.addTaskNote(sessionId, task.id, note);
|
|
1918
|
+
this.bus.publish({ sessionId, taskId: task.id, type: 'task-resumed', level: 'info', message: `carried on with the operator's answer to what it waited for (${p.kind})` });
|
|
1919
|
+
return { taskId: task.id };
|
|
1920
|
+
}
|
|
1513
1921
|
// --- skills (2026-10-21) ----------------------------------------------------------------------------
|
|
1514
1922
|
/** The skills in Settings, and how long what each is for may be. */
|
|
1515
1923
|
async skills() {
|
|
@@ -1641,6 +2049,7 @@ let OperatorService = class OperatorService {
|
|
|
1641
2049
|
approval,
|
|
1642
2050
|
resolve: (d) => resolveAnswer(d.action === 'run' ? 'recheck' : d.action === 'skip' ? 'continue' : 'stop'),
|
|
1643
2051
|
});
|
|
2052
|
+
this.parkLater(approval);
|
|
1644
2053
|
this.bus.publish({ sessionId: ask.sessionId, type: 'approval-requested', level: 'warn',
|
|
1645
2054
|
message: `choose "${ask.asked}" in the Copilot window, then answer on the card`, data: { approvalId: approval.id, model: approval.model } });
|
|
1646
2055
|
});
|
|
@@ -1673,6 +2082,7 @@ let OperatorService = class OperatorService {
|
|
|
1673
2082
|
resolve: () => resolveAnswer('stop'),
|
|
1674
2083
|
resolveAnswer,
|
|
1675
2084
|
});
|
|
2085
|
+
this.parkLater(approval);
|
|
1676
2086
|
this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
|
|
1677
2087
|
message: `the lead asks the operator: ${ask.question}`, data: { approvalId: approval.id, question: approval.question } });
|
|
1678
2088
|
});
|
|
@@ -1700,6 +2110,7 @@ let OperatorService = class OperatorService {
|
|
|
1700
2110
|
retry: ask.retry,
|
|
1701
2111
|
};
|
|
1702
2112
|
this.waiting.set(approval.id, { approval, resolve: () => resolveRetry('stop'), resolveRetry });
|
|
2113
|
+
this.parkLater(approval);
|
|
1703
2114
|
this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
|
|
1704
2115
|
message: `subtask ${ask.retry.n} did not finish (attempt ${ask.retry.attempt} of ${ask.retry.maxAttempts}): the operator is asked what to do`, data: { approvalId: approval.id, retry: ask.retry } });
|
|
1705
2116
|
});
|
|
@@ -1784,6 +2195,7 @@ let OperatorService = class OperatorService {
|
|
|
1784
2195
|
resolve: (d) => resolveAnswer(d.action === 'run' ? { decision: 'approve' } : { decision: 'stop' }),
|
|
1785
2196
|
resolvePlan: resolveAnswer,
|
|
1786
2197
|
});
|
|
2198
|
+
this.parkLater(approval);
|
|
1787
2199
|
this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
|
|
1788
2200
|
message: `the plan of "${ask.title}" (version ${ask.plan.version}) is waiting for you to approve it`, data: { approvalId: approval.id, plan: true } });
|
|
1789
2201
|
});
|
|
@@ -1909,6 +2321,15 @@ let OperatorService = class OperatorService {
|
|
|
1909
2321
|
resolvePromise({ action: 'run' });
|
|
1910
2322
|
return;
|
|
1911
2323
|
}
|
|
2324
|
+
// Approved on the card of the task while the queue had it set aside (2026-10-26): once, as it was approved.
|
|
2325
|
+
const ahead = this.approvedAhead.get(this.runKey(ctx.sessionId ?? '')) ?? this.approvedAhead.get(ctx.sessionId ?? '');
|
|
2326
|
+
const at = ahead ? ahead.indexOf(step.cmd.trim()) : -1;
|
|
2327
|
+
if (ahead && at >= 0) {
|
|
2328
|
+
ahead.splice(at, 1);
|
|
2329
|
+
this.bus.publish({ sessionId: ctx.sessionId ?? '', taskId: ctx.taskId, type: 'approval-decided', level: 'info', message: `run without asking: the operator approved it on the task's card while the queue had it set aside: ${step.cmd}` });
|
|
2330
|
+
resolvePromise({ action: 'run' });
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
1912
2333
|
const approval = {
|
|
1913
2334
|
id: newId('a-'),
|
|
1914
2335
|
sessionId: ctx.sessionId ?? '',
|
|
@@ -1921,6 +2342,7 @@ let OperatorService = class OperatorService {
|
|
|
1921
2342
|
...(held?.platform ? { platform: held.platform } : {}),
|
|
1922
2343
|
};
|
|
1923
2344
|
this.waiting.set(approval.id, { approval, resolve: resolvePromise });
|
|
2345
|
+
this.parkLater(approval);
|
|
1924
2346
|
this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'approval-requested', level: 'warn',
|
|
1925
2347
|
message: held
|
|
1926
2348
|
? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
|