copilot-operator 0.1.62 → 0.1.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/src/api/operator.controller.js +36 -3
  2. package/dist/src/api/operator.service.js +142 -14
  3. package/dist/src/config/schema.js +10 -0
  4. package/dist/src/orchestrator/leadRunner.js +268 -30
  5. package/dist/src/orchestrator/subtaskRetry.js +152 -0
  6. package/dist/src/orchestrator/taskRunner.js +8 -0
  7. package/dist/src/plan/kerrigan.js +31 -4
  8. package/dist/src/plan/systemGuide.js +185 -2
  9. package/dist/src/queue/queue.js +8 -2
  10. package/dist/src/session/store.js +4 -0
  11. package/dist/web/404.html +2 -2
  12. package/dist/web/_next/static/chunks/1077.32bfff8490ea3d67.js +1 -0
  13. package/dist/web/_next/static/chunks/1548.2bbbbb4759fd5073.js +1 -0
  14. package/dist/web/_next/static/chunks/2163.147b0ca65a65d5dd.js +1 -0
  15. package/dist/web/_next/static/chunks/714.16070ca6426f260c.js +1 -0
  16. package/dist/web/_next/static/chunks/7220.f71047baa16e6be0.js +1 -0
  17. package/dist/web/_next/static/chunks/7921-90ed63bfdf7162f3.js +1 -0
  18. package/dist/web/_next/static/chunks/8584.abc09920f03375b1.js +1 -0
  19. package/dist/web/_next/static/chunks/9067.538dec4d8ec0b04e.js +1 -0
  20. package/dist/web/_next/static/chunks/9747.9d15583d6ebafba3.js +1 -0
  21. package/dist/web/_next/static/chunks/app/page-185efe80d6e8dd05.js +1 -0
  22. package/dist/web/_next/static/chunks/app/queue/page-d4155eb6ab172c03.js +1 -0
  23. package/dist/web/_next/static/chunks/app/settings/page-9a83381087178f80.js +1 -0
  24. package/dist/web/_next/static/chunks/{webpack-4665fed2f4b06052.js → webpack-d85f02ecd2903252.js} +1 -1
  25. package/dist/web/_next/static/css/{5ec15fce93be8cbe.css → d107848da2f006af.css} +1 -1
  26. package/dist/web/defaults.html +2 -2
  27. package/dist/web/defaults.txt +8 -8
  28. package/dist/web/index.html +3 -3
  29. package/dist/web/index.txt +9 -9
  30. package/dist/web/queue.html +2 -2
  31. package/dist/web/queue.txt +9 -9
  32. package/dist/web/settings.html +2 -2
  33. package/dist/web/settings.txt +9 -9
  34. package/dist/web/system.html +2 -2
  35. package/dist/web/system.txt +9 -9
  36. package/package.json +3 -2
  37. package/dist/web/_next/static/chunks/1077.42a0502bfe3f2014.js +0 -1
  38. package/dist/web/_next/static/chunks/1548.dbf0648a1239382e.js +0 -1
  39. package/dist/web/_next/static/chunks/2163.dbdeebeb0c069d62.js +0 -1
  40. package/dist/web/_next/static/chunks/714.6472121643f99452.js +0 -1
  41. package/dist/web/_next/static/chunks/7220.391debd1191fc29a.js +0 -1
  42. package/dist/web/_next/static/chunks/7921-0549a0038e591e42.js +0 -1
  43. package/dist/web/_next/static/chunks/8584.4432f14f0cd88188.js +0 -1
  44. package/dist/web/_next/static/chunks/9067.841d6d2f4726f9c2.js +0 -1
  45. package/dist/web/_next/static/chunks/9747.1a7337320eccdc8a.js +0 -1
  46. package/dist/web/_next/static/chunks/app/page-ea0a60db75dac546.js +0 -1
  47. package/dist/web/_next/static/chunks/app/queue/page-f86936d39121ade8.js +0 -1
  48. package/dist/web/_next/static/chunks/app/settings/page-1833ace66fc9eb0e.js +0 -1
  49. /package/dist/web/_next/static/{PJs9xZLAnUDPOFvGV0T_M → vU04zVwJyicqgtWQsApuV}/_buildManifest.js +0 -0
  50. /package/dist/web/_next/static/{PJs9xZLAnUDPOFvGV0T_M → vU04zVwJyicqgtWQsApuV}/_ssgManifest.js +0 -0
@@ -96,10 +96,11 @@ let OperatorController = class OperatorController {
96
96
  }
97
97
  // --- Kerrigan -------------------------------------------------------------------------------
98
98
  /** Kerrigan, the persona to give another chat: what copilot-operator is and how a task is best written for it. */
99
- kerrigan(lang) {
99
+ kerrigan(lang, skill) {
100
100
  // Any language code of the interface: in one she is not written out in, the page fills in the controls' names.
101
101
  const code = typeof lang === 'string' && /^[a-z]{2,3}$/.test(lang) ? lang : 'en';
102
- return this.ops.kerrigan(code).catch(fail);
102
+ // `skill`: the one chosen beside her button, whose instructions go with her text (2026-10-26).
103
+ return this.ops.kerrigan(code, typeof skill === 'string' && skill.trim() ? skill : undefined).catch(fail);
103
104
  }
104
105
  // --- the chat's conversations (sessions of kind `chat`) -------------------------------------
105
106
  sessions() {
@@ -356,6 +357,20 @@ let OperatorController = class OperatorController {
356
357
  }
357
358
  return this.ops.decide(id, body.action);
358
359
  }
360
+ /** A subtask that failed for a technical reason (two chats, 2026-10-25): one of its card's choices. */
361
+ answerRetry(id, body) {
362
+ const result = this.ops.answerRetry(id, typeof body?.choice === 'string' ? body.choice : '');
363
+ if (!result.ok)
364
+ throw new BadRequestException(result.problem);
365
+ return result;
366
+ }
367
+ /** After a Stop (two chats, 2026-10-25): the stopped message carried on with one of its subtasks tried again first. */
368
+ chatRetrySubtask(id, taskId, body = {}) {
369
+ const n = Number(body?.n);
370
+ if (!Number.isInteger(n) || n < 1)
371
+ throw new BadRequestException('n, the subtask\'s number, is required');
372
+ return this.ops.chatRetrySubtask(id, taskId, n, body?.fresh === true).catch(fail);
373
+ }
359
374
  /** The lead's question (two chats): the operator's answer, as text. Stopping the task is `approvals/:id` with abort. */
360
375
  answerQuestion(id, body) {
361
376
  const result = this.ops.answerQuestion(id, typeof body?.text === 'string' ? body.text : '');
@@ -480,8 +495,9 @@ __decorate([
480
495
  __decorate([
481
496
  Get('kerrigan'),
482
497
  __param(0, Query('lang')),
498
+ __param(1, Query('skill')),
483
499
  __metadata("design:type", Function),
484
- __metadata("design:paramtypes", [String]),
500
+ __metadata("design:paramtypes", [String, String]),
485
501
  __metadata("design:returntype", Promise)
486
502
  ], OperatorController.prototype, "kerrigan", null);
487
503
  __decorate([
@@ -757,6 +773,23 @@ __decorate([
757
773
  __metadata("design:paramtypes", [String, Object]),
758
774
  __metadata("design:returntype", Object)
759
775
  ], OperatorController.prototype, "decide", null);
776
+ __decorate([
777
+ Post('approvals/:id/retry'),
778
+ __param(0, Param('id')),
779
+ __param(1, Body()),
780
+ __metadata("design:type", Function),
781
+ __metadata("design:paramtypes", [String, Object]),
782
+ __metadata("design:returntype", Object)
783
+ ], OperatorController.prototype, "answerRetry", null);
784
+ __decorate([
785
+ Post('chat/:id/tasks/:taskId/retry-subtask'),
786
+ __param(0, Param('id')),
787
+ __param(1, Param('taskId')),
788
+ __param(2, Body()),
789
+ __metadata("design:type", Function),
790
+ __metadata("design:paramtypes", [String, String, Object]),
791
+ __metadata("design:returntype", Promise)
792
+ ], OperatorController.prototype, "chatRetrySubtask", null);
760
793
  __decorate([
761
794
  Post('approvals/:id/answer'),
762
795
  __param(0, Param('id')),
@@ -36,8 +36,13 @@ import { chatCode } from '../transport/chatSession.js';
36
36
  /** The folders the operator works in: the default new sessions start on, and the rest by name. */
37
37
  /** The longest level 2 a project may have: Kerrigan carries each one whole. */
38
38
  export const MAX_PROJECT_LEVEL2 = 8000;
39
- /** Its instructions: as long as a project's level 2, the longest text the opening carries besides the task. */
40
- export const MAX_SKILL_TEXT = 8000;
39
+ /** The longest name a conversation or a session may be given (2026-10-26). */
40
+ export const MAX_SESSION_NAME = 120;
41
+ /*
42
+ * Its instructions have no limit of their own (operator, 2026-10-25: "remove the limit; say how many characters there
43
+ * are instead"): the message they go with is held to Settings' `limits.maxMessageChars` like every other — longer, its
44
+ * beginning goes as text and the whole of it attached.
45
+ */
41
46
  export const MAX_SKILL_DESCRIPTION = 300;
42
47
  export const MAX_SKILLS = 50;
43
48
  /** What follows `/` at the start of a message: lowercase letters, digits and hyphens, 2 to 40 of them. */
@@ -293,6 +298,13 @@ let OperatorService = class OperatorService {
293
298
  if (patch.active !== undefined && this.running.has(id)) {
294
299
  throw new Error('This session is running; its status can be changed once it has stopped.');
295
300
  }
301
+ /*
302
+ * A conversation renamed (operator, 2026-10-26: "an option to rename the chats"): any time, working or not — it is
303
+ * what the list calls it. The conversation in Copilot keeps its own name (`Session.chat.name`), which is how the bot
304
+ * finds it again.
305
+ */
306
+ if (patch.name !== undefined && patch.name.trim().length > MAX_SESSION_NAME)
307
+ throw new Error(`A name can be at most ${MAX_SESSION_NAME} characters.`);
296
308
  const updated = await this.store.updateSession(id, (s) => {
297
309
  const before = { model: s.model, manualModel: s.manualModel };
298
310
  if (patch.name !== undefined)
@@ -919,6 +931,7 @@ let OperatorService = class OperatorService {
919
931
  approvePlan: (ask) => this.askPlanApproval(ask, controller.signal),
920
932
  // The two-chat mode (2026-10-20): the lead's questions, and the worker the run speaks for too.
921
933
  askQuestion: (ask) => this.askLeadQuestion(ask, controller.signal),
934
+ askSubtaskRetry: (ask) => this.askSubtaskRetry(ask, controller.signal),
922
935
  onWorker: (workerId) => this.workerLeads.set(workerId, sessionId),
923
936
  hold,
924
937
  })
@@ -1157,7 +1170,7 @@ let OperatorService = class OperatorService {
1157
1170
  * operator wrote for it. Nothing is sent anywhere: the page saves it or copies it. See `plan/kerrigan.ts`; in a
1158
1171
  * language she is not written out in, the page fills in the names of the controls (`filled: false`).
1159
1172
  */
1160
- async kerrigan(lang) {
1173
+ async kerrigan(lang, skill) {
1161
1174
  const cfg = await this.settings.load();
1162
1175
  const p = await this.project();
1163
1176
  const projects = [
@@ -1166,7 +1179,13 @@ let OperatorService = class OperatorService {
1166
1179
  ];
1167
1180
  // The skills, each with the name of the project it is for.
1168
1181
  const nameOf = (dir) => [{ name: p.name || p.rootDir, rootDir: p.rootDir }, ...p.others].find((x) => x.rootDir && sameFolder(x.rootDir, dir))?.name ?? dir;
1169
- const skills = (await this.skills()).skills.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}) }));
1182
+ const all = (await this.skills()).skills;
1183
+ const skills = all.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}) }));
1184
+ // The skill chosen beside her button (2026-10-26): its instructions go with her text.
1185
+ const asked = skill?.trim().replace(/^\//, '').toLowerCase();
1186
+ const chosen = asked ? all.find((k) => k.name === asked) : undefined;
1187
+ if (asked && !chosen)
1188
+ throw new Error(`There is no skill called "${asked}" in Settings → Skills.`);
1170
1189
  const text = kerriganPersona(lang, {
1171
1190
  version: botVersion(),
1172
1191
  skills,
@@ -1176,8 +1195,9 @@ let OperatorService = class OperatorService {
1176
1195
  maxReviewRounds: cfg.limits.maxReviewRounds ?? 2,
1177
1196
  maxSubtasks: cfg.limits.maxSubtasks ?? 20,
1178
1197
  projects,
1198
+ ...(chosen ? { chosenSkill: { name: chosen.name, description: chosen.description, text: chosen.text, ...(chosen.projectDir ? { project: nameOf(chosen.projectDir) } : {}) } } : {}),
1179
1199
  });
1180
- return { lang, fileName: kerriganFileName(lang), text, filled: lang === 'en' || lang === 'bg' };
1200
+ return { lang, fileName: kerriganFileName(lang, chosen?.name), text, filled: lang === 'en' || lang === 'bg' };
1181
1201
  }
1182
1202
  /** The chat's conversations, newest first. */
1183
1203
  async chatThreads() {
@@ -1348,7 +1368,24 @@ let OperatorService = class OperatorService {
1348
1368
  }
1349
1369
  async queue() {
1350
1370
  await this.recoverQueue();
1351
- return await this.readQueue();
1371
+ return await this.withBusy(await this.readQueue());
1372
+ }
1373
+ /**
1374
+ * 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)
1375
+ * — a message working in the chat, a reading of the models, the sign-in. The queue's next task starts after it.
1376
+ */
1377
+ async withBusy(q) {
1378
+ const holder = this.browser;
1379
+ if (!holder)
1380
+ return q;
1381
+ if (holder.kind !== 'run')
1382
+ return { ...q, busy: { kind: holder.kind } };
1383
+ if (q.items.some((x) => x.status === 'running' && x.sessionId === holder.sessionId))
1384
+ return q;
1385
+ const s = await this.store.getSession(holder.sessionId);
1386
+ const at = s?.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval') ?? s?.tasks.find((t) => t.status === 'queued');
1387
+ const busy = { kind: 'chat', sessionId: holder.sessionId, title: at?.title ?? s?.name.replace(/^chat: /, '') ?? '' };
1388
+ return { ...q, busy };
1352
1389
  }
1353
1390
  /** The list as the page edits it: added, changed, moved, taken out, put back to wait ("Run again"). */
1354
1391
  async setQueue(items) {
@@ -1356,6 +1393,13 @@ let OperatorService = class OperatorService {
1356
1393
  const checked = checkItems(items, MAX_INSTRUCTION_CHARS);
1357
1394
  if ('problem' in checked)
1358
1395
  throw new Error(checked.problem);
1396
+ // A skill is one of Settings' (2026-10-25); whether it is for the folder is said when the task runs, in its chat.
1397
+ const { skills } = await this.skills();
1398
+ const unknown = checked.items.findIndex((x) => x.skill && !skills.some((k) => k.name === x.skill));
1399
+ if (unknown >= 0) {
1400
+ const name = checked.items[unknown].skill;
1401
+ 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(', ')}` : ''}.`);
1402
+ }
1359
1403
  let problem;
1360
1404
  const q = await this.changeQueue((x) => {
1361
1405
  const merged = mergeItems(x.items, checked.items);
@@ -1366,7 +1410,7 @@ let OperatorService = class OperatorService {
1366
1410
  });
1367
1411
  if (problem)
1368
1412
  throw new Error(problem);
1369
- return q;
1413
+ return await this.withBusy(q);
1370
1414
  }
1371
1415
  /** Runs the waiting tasks one after another, in the background; the page follows `queue()`. */
1372
1416
  async runQueue() {
@@ -1394,7 +1438,7 @@ let OperatorService = class OperatorService {
1394
1438
  x.running = false;
1395
1439
  });
1396
1440
  });
1397
- return started;
1441
+ return await this.withBusy(started);
1398
1442
  }
1399
1443
  /**
1400
1444
  * Tasks that would wait for the operator to choose their model by hand: none of their own, and no "Model for the
@@ -1416,7 +1460,7 @@ let OperatorService = class OperatorService {
1416
1460
  const at = q.items.find((x) => x.status === 'running');
1417
1461
  if (at?.sessionId)
1418
1462
  await this.stop(at.sessionId).catch(() => undefined);
1419
- return q;
1463
+ return await this.withBusy(q);
1420
1464
  }
1421
1465
  async runQueueLoop() {
1422
1466
  const now = () => new Date().toISOString();
@@ -1433,6 +1477,16 @@ let OperatorService = class OperatorService {
1433
1477
  await this.changeQueue((x) => this.setQueueItem(x, step.skip.id, { status: 'skipped', why: skippedBecause(step.because), endedAt: now() }));
1434
1478
  continue;
1435
1479
  }
1480
+ /*
1481
+ * Its turn comes when the browser is free (operator, 2026-10-25: "I add a task while one sent from the chat runs;
1482
+ * the new one starts after it"): whatever has it — a message of the chat, a reading of the models, the sign-in —
1483
+ * ends first. It waits as a task that waits, so it can still be edited, moved or taken out, and the queue is read
1484
+ * again before it is taken.
1485
+ */
1486
+ if (this.browser) {
1487
+ await new Promise((r) => setTimeout(r, 1_000));
1488
+ continue;
1489
+ }
1436
1490
  const item = step.run;
1437
1491
  await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, sessionId: undefined }));
1438
1492
  const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
@@ -1471,6 +1525,7 @@ let OperatorService = class OperatorService {
1471
1525
  review: item.review,
1472
1526
  ...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
1473
1527
  ...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
1528
+ ...(item.skill ? { skill: item.skill } : {}),
1474
1529
  });
1475
1530
  const sessionId = sent.threadId;
1476
1531
  await this.store.updateSession(sessionId, (s) => {
@@ -1488,6 +1543,15 @@ let OperatorService = class OperatorService {
1488
1543
  });
1489
1544
  await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
1490
1545
  const cfg = await this.settings.load();
1546
+ /*
1547
+ * A message of the chat sent meanwhile has the browser: this one starts after it, never refused for it. The browser
1548
+ * is looked at and taken in the same moment — `start` takes it before it awaits anything.
1549
+ */
1550
+ while (holder()) {
1551
+ if (this.queueClosing || !(await stillRunning()))
1552
+ return { status: 'stopped', why: 'the queue was stopped before it began', sessionId };
1553
+ await pause(1_000);
1554
+ }
1491
1555
  const reply = await this.start(sessionId, cfg.execution.mode);
1492
1556
  if (!reply.started)
1493
1557
  return { status: 'failed', why: reply.reason ?? 'it did not start', sessionId };
@@ -1507,18 +1571,17 @@ let OperatorService = class OperatorService {
1507
1571
  return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
1508
1572
  }
1509
1573
  // --- skills (2026-10-21) ----------------------------------------------------------------------------
1510
- /** The skills in Settings, and how long their instructions may be. */
1574
+ /** The skills in Settings, and how long what each is for may be. */
1511
1575
  async skills() {
1512
1576
  const cfg = await this.settings.load();
1513
1577
  return {
1514
1578
  skills: (cfg.skills ?? []).map((k) => ({ name: k.name, description: k.description ?? '', text: k.text ?? '', projectDir: k.projectDir ?? '' })),
1515
- maxText: MAX_SKILL_TEXT,
1516
1579
  maxDescription: MAX_SKILL_DESCRIPTION,
1517
1580
  };
1518
1581
  }
1519
1582
  /**
1520
1583
  * Stores the list as given, held to the rules: a name to type after `/` — lowercase, digits and hyphens, each used
1521
- * once — instructions that are there and not too long, a project that is one of Settings' or every project.
1584
+ * once — instructions that are there, of any length, a project that is one of Settings' or every project.
1522
1585
  */
1523
1586
  async setSkills(list) {
1524
1587
  if (!Array.isArray(list))
@@ -1541,8 +1604,6 @@ let OperatorService = class OperatorService {
1541
1604
  const text = String(k?.text ?? '');
1542
1605
  if (!text.trim())
1543
1606
  throw new Error(`The skill "${name}" has no instructions: write what the chat should know and do for this kind of task.`);
1544
- if (text.length > MAX_SKILL_TEXT)
1545
- throw new Error(`The instructions of "${name}" are longer than ${MAX_SKILL_TEXT.toLocaleString('en')} characters.`);
1546
1607
  const projectDir = String(k?.projectDir ?? '').trim();
1547
1608
  if (projectDir && !folders.some((f) => sameFolder(f, projectDir)))
1548
1609
  throw new Error(`The skill "${name}" is for ${projectDir}, which is not one of the projects in Settings.`);
@@ -1677,6 +1738,73 @@ let OperatorService = class OperatorService {
1677
1738
  });
1678
1739
  }
1679
1740
  /** The operator's answer to the lead's question. */
1741
+ /**
1742
+ * A subtask of two chats that failed for a technical reason, put to the operator (2026-10-25): a card under the subtask
1743
+ * with why, which attempt it was, what it left, and the choices; it waits until one is chosen, or the task is stopped.
1744
+ * Answered with `answerRetry`; "abort" on the card, a Stop or the end of the run stop the task.
1745
+ */
1746
+ askSubtaskRetry(ask, signal) {
1747
+ return new Promise((resolveRetry) => {
1748
+ if (signal.aborted) {
1749
+ resolveRetry('stop');
1750
+ return;
1751
+ }
1752
+ const approval = {
1753
+ id: newId('a-'),
1754
+ sessionId: ask.sessionId,
1755
+ taskId: ask.taskId,
1756
+ stepId: 0,
1757
+ description: `Subtask ${ask.retry.n} (${ask.retry.title}) did not finish, attempt ${ask.retry.attempt} of ${ask.retry.maxAttempts}: ${ask.retry.reason || ask.retry.category}`,
1758
+ createdAt: new Date().toISOString(),
1759
+ actor: 'lead',
1760
+ retry: ask.retry,
1761
+ };
1762
+ this.waiting.set(approval.id, { approval, resolve: () => resolveRetry('stop'), resolveRetry });
1763
+ this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1764
+ 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 } });
1765
+ });
1766
+ }
1767
+ /** The operator's choice for a subtask that failed for a technical reason: one of the card's own. */
1768
+ answerRetry(approvalId, choice) {
1769
+ const w = this.waiting.get(approvalId);
1770
+ if (!w?.resolveRetry || !w.approval.retry)
1771
+ return { ok: false, problem: 'No subtask is waiting for a choice under that id.' };
1772
+ if (!w.approval.retry.choices.includes(choice))
1773
+ return { ok: false, problem: `"${choice}" is not one of this card's choices: ${w.approval.retry.choices.join(', ')}.` };
1774
+ this.waiting.delete(approvalId);
1775
+ w.resolveRetry(choice);
1776
+ this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
1777
+ message: `the operator chose for subtask ${w.approval.retry.n}: ${choice}`, data: { approvalId, retry: choice } });
1778
+ return { ok: true };
1779
+ }
1780
+ /**
1781
+ * Two chats, after a Stop (2026-10-25): "do not start a task again by itself after Stop; when the operator carries on in
1782
+ * the same conversation, let a chosen failed subtask be tried again, with the plan and the reports kept". The message
1783
+ * is carried on with that subtask first (`TaskContinuation.retrySubtask`), then the lead goes on; the run is started
1784
+ * as a message of the chat is.
1785
+ */
1786
+ async chatRetrySubtask(threadId, taskId, n, fresh) {
1787
+ await this.init();
1788
+ const session = await this.store.getSession(threadId);
1789
+ if (!session || session.kind !== 'chat')
1790
+ throw new Error('That conversation is not there any more.');
1791
+ if (this.running.has(threadId))
1792
+ throw new Error('The conversation is working: stop it first, or let it finish.');
1793
+ const task = session.tasks.find((t) => t.id === taskId);
1794
+ if (!task?.lead)
1795
+ throw new Error('That message is not one of two chats.');
1796
+ if (task.status !== 'aborted')
1797
+ throw new Error('Only a message that was stopped has a subtask to try again: the others carry on by themselves, or end.');
1798
+ const sub = [...task.lead.rounds].reverse().find((r) => r.subtask?.n === n)?.subtask;
1799
+ if (!sub)
1800
+ throw new Error(`The message has no subtask ${n}.`);
1801
+ const last = sub.attempts?.at(-1);
1802
+ if (last?.status === 'done')
1803
+ throw new Error(`Subtask ${n} was done; it is not done again.`);
1804
+ await this.store.rerunTask(threadId, taskId, {}, { fromAttempt: task.attempt ?? 1, stoppedBecause: task.reason, how: 'stopped', retrySubtask: { n, ...(fresh ? { fresh: true } : {}) } });
1805
+ const cfg = await this.settings.load();
1806
+ return await this.start(threadId, cfg.execution.mode);
1807
+ }
1680
1808
  answerQuestion(approvalId, text) {
1681
1809
  const w = this.waiting.get(approvalId);
1682
1810
  if (!w?.resolveAnswer)
@@ -498,6 +498,16 @@ export const RunConfigSchema = z.object({
498
498
  * subtask is a task of the worker's, with the limits above; this bounds the whole. Settings → Execution.
499
499
  */
500
500
  maxSubtasks: z.number().int().min(1).max(100).default(20),
501
+ /*
502
+ * A subtask of two chats that failed for a technical reason (operator's specification, 2026-10-25; see
503
+ * `orchestrator/subtaskRetry.ts`): `ask` puts it to the operator on a card; `same` tries it again in the same
504
+ * worker's conversation, `fresh` in a new one — by themselves only for a proven, temporary fault of the chat; `lead`
505
+ * gives the lead the report, as before. At most `subtaskRetries` times more (0 to 3), `subtaskRetryWaitSec` apart.
506
+ * Settings → "Retrying an interrupted subtask". Only for two chats.
507
+ */
508
+ subtaskRetryMode: z.enum(['ask', 'same', 'fresh', 'lead']).default('ask'),
509
+ subtaskRetries: z.number().int().min(0).max(3).default(2),
510
+ subtaskRetryWaitSec: z.number().int().min(0).max(600).default(15),
501
511
  /*
502
512
  * How many genuinely different approaches the chat must have tried before it may end a task
503
513
  * "blocked". The reply format's own floor is 2 (replySchema.ts); this raises it. A "blocked"