copilot-operator 0.1.64 → 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.
Files changed (57) hide show
  1. package/dist/src/api/operator.controller.js +48 -0
  2. package/dist/src/api/operator.service.js +415 -53
  3. package/dist/src/exec/dangerous.js +12 -0
  4. package/dist/src/exec/runner.js +75 -2
  5. package/dist/src/exec/stepEnv.js +13 -2
  6. package/dist/src/orchestrator/taskRunner.js +12 -1
  7. package/dist/src/plan/kerrigan.js +32 -6
  8. package/dist/src/plan/systemGuide.js +136 -0
  9. package/dist/src/queue/queue.js +65 -4
  10. package/dist/src/queue/queueBranch.js +66 -0
  11. package/dist/src/session/compose.js +15 -0
  12. package/dist/src/session/store.js +4 -0
  13. package/dist/src/vcs/newBranch.js +241 -0
  14. package/dist/src/vcs/remoteAuth.js +119 -0
  15. package/dist/web/404.html +2 -2
  16. package/dist/web/_next/static/chunks/1024-444e9060299d04ba.js +1 -0
  17. package/dist/web/_next/static/chunks/1077.b88b069535f7008e.js +1 -0
  18. package/dist/web/_next/static/chunks/1548.9e01803e48173ea9.js +1 -0
  19. package/dist/web/_next/static/chunks/2163.018cd5f719ae4b3d.js +1 -0
  20. package/dist/web/_next/static/chunks/6262-d074473db83ee798.js +1 -0
  21. package/dist/web/_next/static/chunks/714.281f68f85df26013.js +1 -0
  22. package/dist/web/_next/static/chunks/7220.3bd10a3e4e053e0c.js +1 -0
  23. package/dist/web/_next/static/chunks/7921-1c173d00d23b3589.js +1 -0
  24. package/dist/web/_next/static/chunks/8124-bb544c96a7c0e7e3.js +1 -0
  25. package/dist/web/_next/static/chunks/8584.c7cd52c2e7075bcb.js +1 -0
  26. package/dist/web/_next/static/chunks/{9067.538dec4d8ec0b04e.js → 9067.feaf894390db1a88.js} +1 -1
  27. package/dist/web/_next/static/chunks/9747.7cee8a2d8301f25c.js +1 -0
  28. package/dist/web/_next/static/chunks/app/{layout-9201c637ca24b2c9.js → layout-5e0e7601702723bb.js} +1 -1
  29. package/dist/web/_next/static/chunks/app/page-95379244849623fc.js +1 -0
  30. package/dist/web/_next/static/chunks/app/queue/page-fb49cb2d3dc6d14c.js +1 -0
  31. package/dist/web/_next/static/chunks/{webpack-d85f02ecd2903252.js → webpack-5ea108bc2e386c55.js} +1 -1
  32. package/dist/web/_next/static/css/a112074f3d1a8a07.css +1 -0
  33. package/dist/web/defaults.html +2 -2
  34. package/dist/web/defaults.txt +8 -8
  35. package/dist/web/index.html +3 -3
  36. package/dist/web/index.txt +9 -9
  37. package/dist/web/queue.html +2 -2
  38. package/dist/web/queue.txt +9 -9
  39. package/dist/web/settings.html +2 -2
  40. package/dist/web/settings.txt +9 -9
  41. package/dist/web/system.html +2 -2
  42. package/dist/web/system.txt +9 -9
  43. package/package.json +4 -2
  44. package/dist/web/_next/static/chunks/1077.32bfff8490ea3d67.js +0 -1
  45. package/dist/web/_next/static/chunks/1548.2bbbbb4759fd5073.js +0 -1
  46. package/dist/web/_next/static/chunks/2163.147b0ca65a65d5dd.js +0 -1
  47. package/dist/web/_next/static/chunks/714.16070ca6426f260c.js +0 -1
  48. package/dist/web/_next/static/chunks/7220.f71047baa16e6be0.js +0 -1
  49. package/dist/web/_next/static/chunks/7921-90ed63bfdf7162f3.js +0 -1
  50. package/dist/web/_next/static/chunks/8124-5458b17433987fab.js +0 -1
  51. package/dist/web/_next/static/chunks/8584.abc09920f03375b1.js +0 -1
  52. package/dist/web/_next/static/chunks/9747.9d15583d6ebafba3.js +0 -1
  53. package/dist/web/_next/static/chunks/app/page-185efe80d6e8dd05.js +0 -1
  54. package/dist/web/_next/static/chunks/app/queue/page-d4155eb6ab172c03.js +0 -1
  55. package/dist/web/_next/static/css/d107848da2f006af.css +0 -1
  56. /package/dist/web/_next/static/{vU04zVwJyicqgtWQsApuV → BbWvNQTsh3pH7ZN_RKR60}/_buildManifest.js +0 -0
  57. /package/dist/web/_next/static/{vU04zVwJyicqgtWQsApuV → 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, mainBranchOf, mergeItems, nextStep, skippedBecause, statusOfTask, waitsByHand } from '../queue/queue.js';
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';
@@ -68,7 +69,7 @@ import { searchWorkspace } from '../session/workspaceSearch.js';
68
69
  import { restoreCheckpoint } from '../session/checkpoint.js';
69
70
  import { readInterruption } from '../session/interruption.js';
70
71
  import { baseRefOf, commitInterrupted, nextAttemptBranch, repoDirOf, trackedRepoOf, sessionBranchName } from '../vcs/taskVcs.js';
71
- import { changedFilesBetween, fileAt, git, repoUnusableReason } from '../vcs/git.js';
72
+ import { branchExists, changedFilesBetween, fileAt, git, repoUnusableReason } from '../vcs/git.js';
72
73
  import { makeAuthorizer } from '../exec/authorizer.js';
73
74
  import { pickFolder } from './folderPicker.js';
74
75
  import { findEdgeUsingProfile, profileHolder } from '../transport/profileLock.js';
@@ -88,6 +89,9 @@ import { sessionRoots } from '../exec/confinement.js';
88
89
  import { dirtyPolicy } from '../vcs/snapshot.js';
89
90
  import { runVcsPreflight } from '../vcs/runPreflight.js';
90
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';
91
95
  import { coveredByArtifacts } from '../vcs/artifacts.js';
92
96
  import { botVersion } from '../config/version.js';
93
97
  import { exportEntries, exportFileName as homeExportName, exportSizes } from '../config/exportHome.js';
@@ -155,11 +159,28 @@ let OperatorService = class OperatorService {
155
159
  * operator in another window): a worker's subtask is not the message.
156
160
  */
157
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();
158
164
  followsActing = this.bus.subscribe('*', (e) => {
159
165
  if (e.type === 'acting' && e.data)
160
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
+ }
161
181
  else if (e.type === 'task-finished') {
162
182
  this.acting.delete(e.sessionId);
183
+ this.passwordAsked.delete(e.sessionId);
163
184
  const status = e.data?.status;
164
185
  if (typeof status === 'string' && !this.workerLeads.has(e.sessionId))
165
186
  this.lastOutcome = { status, at: e.at, sessionId: e.sessionId };
@@ -1062,6 +1083,8 @@ let OperatorService = class OperatorService {
1062
1083
  starting,
1063
1084
  ...(acting ? { acting } : {}),
1064
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 } : {}),
1065
1088
  // How the last message ended, while nothing runs: what the tab says until the operator has looked.
1066
1089
  ...(this.running.size === 0 && this.lastOutcome ? { last: { status: this.lastOutcome.status, at: this.lastOutcome.at } } : {}),
1067
1090
  };
@@ -1103,6 +1126,45 @@ let OperatorService = class OperatorService {
1103
1126
  const cfg = await this.settings.load();
1104
1127
  return await workspaceInfo(cfg.project?.rootDir ?? '', cfg.project?.name ?? '');
1105
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
+ }
1106
1168
  /** The open folder's code, searched as VS Code's Search view does (2026-10-21, see `workspaceSearch.ts`). */
1107
1169
  async workspaceSearch(query, opts) {
1108
1170
  const ws = await this.workspace();
@@ -1316,11 +1378,24 @@ let OperatorService = class OperatorService {
1316
1378
  queueRecovered = false;
1317
1379
  /** The program is closing: the queue's loop stops where it is. */
1318
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();
1319
1389
  /** The queue as it is on disk; one that cannot be read is an empty one, said in the console. */
1320
1390
  async readQueue() {
1321
1391
  try {
1322
1392
  const q = JSON.parse(await readFile(this.queueFile, 'utf8'));
1323
- return { items: Array.isArray(q.items) ? q.items : [], running: q.running === true, updatedAt: q.updatedAt ?? '' };
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
+ };
1324
1399
  }
1325
1400
  catch (e) {
1326
1401
  if (e.code !== 'ENOENT')
@@ -1334,6 +1409,7 @@ let OperatorService = class OperatorService {
1334
1409
  const q = await this.readQueue();
1335
1410
  change(q);
1336
1411
  q.updatedAt = new Date().toISOString();
1412
+ delete q.busy;
1337
1413
  await writeFileAtomically(this.queueFile, JSON.stringify(q, null, 2));
1338
1414
  return q;
1339
1415
  };
@@ -1350,7 +1426,10 @@ let OperatorService = class OperatorService {
1350
1426
  if (patch[key] === undefined)
1351
1427
  delete item[key];
1352
1428
  }
1353
- /** A queue that was running when the bot last closed: not running now, and its task in flight stopped. */
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
+ */
1354
1433
  async recoverQueue() {
1355
1434
  if (this.queueRecovered)
1356
1435
  return;
@@ -1410,7 +1489,52 @@ let OperatorService = class OperatorService {
1410
1489
  });
1411
1490
  if (problem)
1412
1491
  throw new Error(problem);
1413
- return await this.withBusy(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
+ }));
1414
1538
  }
1415
1539
  /** Runs the waiting tasks one after another, in the background; the page follows `queue()`. */
1416
1540
  async runQueue() {
@@ -1424,7 +1548,7 @@ let OperatorService = class OperatorService {
1424
1548
  const ws = await this.workspace();
1425
1549
  if (!ws.ok)
1426
1550
  throw new Error(ws.problem ?? 'No project folder is open: open one in the chat first.');
1427
- 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());
1428
1552
  if (unnamed)
1429
1553
  throw new Error(unnamed);
1430
1554
  const started = await this.changeQueue((x) => {
@@ -1462,6 +1586,104 @@ let OperatorService = class OperatorService {
1462
1586
  await this.stop(at.sessionId).catch(() => undefined);
1463
1587
  return await this.withBusy(q);
1464
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);
1686
+ }
1465
1687
  async runQueueLoop() {
1466
1688
  const now = () => new Date().toISOString();
1467
1689
  for (;;) {
@@ -1488,15 +1710,16 @@ let OperatorService = class OperatorService {
1488
1710
  continue;
1489
1711
  }
1490
1712
  const item = step.run;
1491
- await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, sessionId: undefined }));
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 }) }));
1492
1715
  const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
1493
1716
  await this.changeQueue((x) => this.setQueueItem(x, item.id, { ...ended, endedAt: now() }));
1494
- // 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.
1495
1718
  if (ended.status === 'stopped')
1496
1719
  return;
1497
1720
  }
1498
1721
  }
1499
- /** 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. */
1500
1723
  async runQueueItem(item) {
1501
1724
  const pause = (ms) => new Promise((r) => setTimeout(r, ms));
1502
1725
  const stillRunning = async () => (await this.readQueue()).running;
@@ -1511,38 +1734,74 @@ let OperatorService = class OperatorService {
1511
1734
  const ws = await this.workspace();
1512
1735
  if (!ws.ok)
1513
1736
  return { status: 'failed', why: ws.problem ?? 'no project folder is open' };
1514
- // Settings may have changed since the queue was started.
1515
- const unnamed = this.queueWithoutModel([item], await this.settings.load());
1516
- if (unnamed)
1517
- return { status: 'failed', why: unnamed };
1518
- const base = item.branch === 'main' ? await mainBranchOf(ws.dir) : null;
1519
- if (item.branch === 'main' && !base)
1520
- return { status: 'failed', why: `${ws.dir} has no main (or master) branch to make a new branch from` };
1521
- // As the chat's box sends a first message: the model, the review and its model, or two chats and the worker's model.
1522
- const sent = await this.chatSend({
1523
- text: item.prompt,
1524
- ...(item.model ? { model: item.model } : {}),
1525
- review: item.review,
1526
- ...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
1527
- ...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
1528
- ...(item.skill ? { skill: item.skill } : {}),
1529
- });
1530
- const sessionId = sent.threadId;
1531
- await this.store.updateSession(sessionId, (s) => {
1532
- s.name = `queue: ${itemTitle(item)}`;
1533
- s.queueItem = item.id;
1534
- /*
1535
- * A new branch from main (2026-10-24): the runner's own version control, as a session of the bot's has it — the
1536
- * branch cut from main, brought up to date from the server first when that needs no password (`updateFromRemote`
1537
- * asks nobody anything; it fails, and the local main is used), and the work committed on it. The chat is told
1538
- * which main it was (`noteFor`).
1539
- */
1540
- if (base) {
1541
- s.vcs = { ...DEFAULT_VCS, enabled: true, repoDir: ws.dir, branchMode: 'per-session', commitOnFinish: true, startFrom: 'branch', baseBranch: base, updateFromRemote: true };
1542
- }
1543
- });
1544
- await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
1545
1737
  const cfg = await this.settings.load();
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);
1802
+ }
1803
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
1804
+ }
1546
1805
  /*
1547
1806
  * A message of the chat sent meanwhile has the browser: this one starts after it, never refused for it. The browser
1548
1807
  * is looked at and taken in the same moment — `start` takes it before it awaits anything.
@@ -1552,24 +1811,113 @@ let OperatorService = class OperatorService {
1552
1811
  return { status: 'stopped', why: 'the queue was stopped before it began', sessionId };
1553
1812
  await pause(1_000);
1554
1813
  }
1555
- const reply = await this.start(sessionId, cfg.execution.mode);
1556
- if (!reply.started)
1557
- return { status: 'failed', why: reply.reason ?? 'it did not start', sessionId };
1558
- // Until its run has ended and its window let the browser go, so the next one can have it.
1559
- let asked = false;
1560
- while (this.running.has(sessionId) || (holder()?.kind === 'run' && holder().sessionId === sessionId)) {
1561
- if (this.queueClosing)
1562
- return { status: 'stopped', why: 'the bot was closed while it ran', sessionId };
1563
- if (!asked && !(await stillRunning())) {
1564
- asked = true;
1565
- await this.stop(sessionId).catch(() => undefined);
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);
1566
1829
  }
1567
- await pause(1_000);
1568
1830
  }
1569
- const task = (await this.store.getSession(sessionId))?.tasks.find((t) => t.id === sent.taskId);
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
+ }
1570
1846
  const status = statusOfTask(task?.status);
1571
1847
  return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
1572
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
+ }
1573
1921
  // --- skills (2026-10-21) ----------------------------------------------------------------------------
1574
1922
  /** The skills in Settings, and how long what each is for may be. */
1575
1923
  async skills() {
@@ -1701,6 +2049,7 @@ let OperatorService = class OperatorService {
1701
2049
  approval,
1702
2050
  resolve: (d) => resolveAnswer(d.action === 'run' ? 'recheck' : d.action === 'skip' ? 'continue' : 'stop'),
1703
2051
  });
2052
+ this.parkLater(approval);
1704
2053
  this.bus.publish({ sessionId: ask.sessionId, type: 'approval-requested', level: 'warn',
1705
2054
  message: `choose "${ask.asked}" in the Copilot window, then answer on the card`, data: { approvalId: approval.id, model: approval.model } });
1706
2055
  });
@@ -1733,6 +2082,7 @@ let OperatorService = class OperatorService {
1733
2082
  resolve: () => resolveAnswer('stop'),
1734
2083
  resolveAnswer,
1735
2084
  });
2085
+ this.parkLater(approval);
1736
2086
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1737
2087
  message: `the lead asks the operator: ${ask.question}`, data: { approvalId: approval.id, question: approval.question } });
1738
2088
  });
@@ -1760,6 +2110,7 @@ let OperatorService = class OperatorService {
1760
2110
  retry: ask.retry,
1761
2111
  };
1762
2112
  this.waiting.set(approval.id, { approval, resolve: () => resolveRetry('stop'), resolveRetry });
2113
+ this.parkLater(approval);
1763
2114
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1764
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 } });
1765
2116
  });
@@ -1844,6 +2195,7 @@ let OperatorService = class OperatorService {
1844
2195
  resolve: (d) => resolveAnswer(d.action === 'run' ? { decision: 'approve' } : { decision: 'stop' }),
1845
2196
  resolvePlan: resolveAnswer,
1846
2197
  });
2198
+ this.parkLater(approval);
1847
2199
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1848
2200
  message: `the plan of "${ask.title}" (version ${ask.plan.version}) is waiting for you to approve it`, data: { approvalId: approval.id, plan: true } });
1849
2201
  });
@@ -1969,6 +2321,15 @@ let OperatorService = class OperatorService {
1969
2321
  resolvePromise({ action: 'run' });
1970
2322
  return;
1971
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
+ }
1972
2333
  const approval = {
1973
2334
  id: newId('a-'),
1974
2335
  sessionId: ctx.sessionId ?? '',
@@ -1981,6 +2342,7 @@ let OperatorService = class OperatorService {
1981
2342
  ...(held?.platform ? { platform: held.platform } : {}),
1982
2343
  };
1983
2344
  this.waiting.set(approval.id, { approval, resolve: resolvePromise });
2345
+ this.parkLater(approval);
1984
2346
  this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'approval-requested', level: 'warn',
1985
2347
  message: held
1986
2348
  ? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
@@ -150,6 +150,18 @@ export const DANGEROUS_TECHNIQUES = [
150
150
  pattern: /\bInvoke-Item\b|\|\s*ii(?![\w.\-:\\\/])|(?:^|[;&({\n]|\$[\w:.{}\[\]]+\s*=)\s*[.&]?\s*ii(?:\s+[^\s;|&)}]|\()|\b(?:pwsh|powershell)(?:\.exe)?\b(?:(?:(?![\s'"]-f)[^|;\n])*?[\s'"]-(?:c|co|com|comm|comma|comman|command)\b['"]?(?:\s*,\s*|\s+)|(?:\s+-(?!f)\w+(?::\S+)?(?:\s+(?![-'"])[\w.]+)?)*\s+)["']?ii(?![\w.\-:\\\/])|\b(Start-Process|saps|start)\s+(?:-\w+\s+)*(?:-FilePath\s+)?["']?(?:[^\s"']+\.(hta|vbs|vbe|js|jse|wsf|wsh|lnk|url|scr|cpl|msc|reg|inf|msi|msp|chm|pif)\b|https?:\/\/|ms-\w+:|file:\/\/)/i,
151
151
  why: 'a file opened through its registered handler, or a URL opened in the browser, runs whatever Windows has registered for it under this runner. Start the program itself, by name, with the file as its argument.',
152
152
  },
153
+ {
154
+ name: 'credential-capture',
155
+ /*
156
+ * Git asks the operator for a password through its own window (2026-10-26, `stepEnv.ts`), and the answer goes from
157
+ * the window straight to git. A step that ran the window itself, or a credential helper, or set git's or ssh's own
158
+ * password and ssh programs, could put up the same window with its own question and catch the answer in its output
159
+ * — which goes to the chat. Git asks for what it needs by itself: `git push`, `git fetch`, `git pull` and
160
+ * `git clone` are not touched by this.
161
+ */
162
+ pattern: /\b(?:git|ssh)-askpass\b|\b(?:GIT_ASKPASS|SSH_ASKPASS(?:_REQUIRE)?|GIT_SSH_COMMAND|GIT_SSH|GCM_[A-Z_]+)\b|\bcore\.(?:askpass|sshCommand)\b|\bcredential\.(?:helper|[\w.-]*\.helper)\b|\bgit-credential(?:-[\w-]+)?\b|\bgit(?:\.exe)?(?:\s+-[-\w.=]+(?:\s+[^\s-][^\s]*)?)*\s+credential(?:-[\w-]+)?\b/i,
163
+ why: 'the password Git asks for goes from its own window straight to git; a step that runs that window, a credential helper or git\'s password settings itself could catch what the operator types. Run git itself — push, fetch, pull, clone — and Git asks for what it needs in its own window.',
164
+ },
153
165
  {
154
166
  name: 'obfuscated-name',
155
167
  /*