copilot-operator 0.1.64 → 0.1.67

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 (68) hide show
  1. package/dist/src/api/operator.controller.js +56 -1
  2. package/dist/src/api/operator.service.js +418 -54
  3. package/dist/src/cli.js +1 -0
  4. package/dist/src/config/schema.js +7 -0
  5. package/dist/src/exec/authorizer.js +26 -6
  6. package/dist/src/exec/commandHeads.js +30 -6
  7. package/dist/src/exec/dangerous.js +12 -0
  8. package/dist/src/exec/platforms.js +13 -2
  9. package/dist/src/exec/policy.js +31 -4
  10. package/dist/src/exec/policyManifest.js +9 -0
  11. package/dist/src/exec/readOnly.js +158 -0
  12. package/dist/src/exec/runner.js +75 -2
  13. package/dist/src/exec/stepEnv.js +13 -2
  14. package/dist/src/orchestrator/taskRunner.js +16 -3
  15. package/dist/src/plan/kerrigan.js +34 -6
  16. package/dist/src/plan/systemGuide.js +199 -0
  17. package/dist/src/queue/queue.js +65 -4
  18. package/dist/src/queue/queueBranch.js +66 -0
  19. package/dist/src/session/compose.js +15 -0
  20. package/dist/src/session/store.js +4 -0
  21. package/dist/src/vcs/newBranch.js +241 -0
  22. package/dist/src/vcs/remoteAuth.js +119 -0
  23. package/dist/web/404.html +2 -2
  24. package/dist/web/_next/static/chunks/1024-5f630cbb54e7346f.js +1 -0
  25. package/dist/web/_next/static/chunks/1077.3b82a837cf810f8b.js +1 -0
  26. package/dist/web/_next/static/chunks/1548.52bfcd01c16aaafe.js +1 -0
  27. package/dist/web/_next/static/chunks/2163.e60d3be9bb3f8b3f.js +1 -0
  28. package/dist/web/_next/static/chunks/6262-d074473db83ee798.js +1 -0
  29. package/dist/web/_next/static/chunks/714.b452ef814760b5a5.js +1 -0
  30. package/dist/web/_next/static/chunks/7220.96b18052ed9c06c7.js +1 -0
  31. package/dist/web/_next/static/chunks/7921-dd201ce7aa02c12d.js +1 -0
  32. package/dist/web/_next/static/chunks/8124-c27ce7bd781f4c56.js +1 -0
  33. package/dist/web/_next/static/chunks/8584.ab8d406781cdd45c.js +1 -0
  34. package/dist/web/_next/static/chunks/9067.5b8abc40104d51d9.js +1 -0
  35. package/dist/web/_next/static/chunks/9747.cf0353e7ffec2ee4.js +1 -0
  36. package/dist/web/_next/static/chunks/app/{layout-9201c637ca24b2c9.js → layout-5e0e7601702723bb.js} +1 -1
  37. package/dist/web/_next/static/chunks/app/page-ab73d1b3ba9181c2.js +1 -0
  38. package/dist/web/_next/static/chunks/app/queue/page-fb49cb2d3dc6d14c.js +1 -0
  39. package/dist/web/_next/static/chunks/app/settings/page-7d120feb5af0ace9.js +1 -0
  40. package/dist/web/_next/static/chunks/{webpack-d85f02ecd2903252.js → webpack-23ace264f775d98a.js} +1 -1
  41. package/dist/web/_next/static/css/532df8667473c4fc.css +1 -0
  42. package/dist/web/defaults.html +2 -2
  43. package/dist/web/defaults.txt +8 -8
  44. package/dist/web/index.html +3 -3
  45. package/dist/web/index.txt +9 -9
  46. package/dist/web/queue.html +2 -2
  47. package/dist/web/queue.txt +9 -9
  48. package/dist/web/settings.html +2 -2
  49. package/dist/web/settings.txt +9 -9
  50. package/dist/web/system.html +2 -2
  51. package/dist/web/system.txt +9 -9
  52. package/package.json +5 -2
  53. package/dist/web/_next/static/chunks/1077.32bfff8490ea3d67.js +0 -1
  54. package/dist/web/_next/static/chunks/1548.2bbbbb4759fd5073.js +0 -1
  55. package/dist/web/_next/static/chunks/2163.147b0ca65a65d5dd.js +0 -1
  56. package/dist/web/_next/static/chunks/714.16070ca6426f260c.js +0 -1
  57. package/dist/web/_next/static/chunks/7220.f71047baa16e6be0.js +0 -1
  58. package/dist/web/_next/static/chunks/7921-90ed63bfdf7162f3.js +0 -1
  59. package/dist/web/_next/static/chunks/8124-5458b17433987fab.js +0 -1
  60. package/dist/web/_next/static/chunks/8584.abc09920f03375b1.js +0 -1
  61. package/dist/web/_next/static/chunks/9067.538dec4d8ec0b04e.js +0 -1
  62. package/dist/web/_next/static/chunks/9747.9d15583d6ebafba3.js +0 -1
  63. package/dist/web/_next/static/chunks/app/page-185efe80d6e8dd05.js +0 -1
  64. package/dist/web/_next/static/chunks/app/queue/page-d4155eb6ab172c03.js +0 -1
  65. package/dist/web/_next/static/chunks/app/settings/page-9a83381087178f80.js +0 -1
  66. package/dist/web/_next/static/css/d107848da2f006af.css +0 -1
  67. /package/dist/web/_next/static/{vU04zVwJyicqgtWQsApuV → JpBxrjYpw2xowWbFoiPjO}/_buildManifest.js +0 -0
  68. /package/dist/web/_next/static/{vU04zVwJyicqgtWQsApuV → JpBxrjYpw2xowWbFoiPjO}/_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 };
@@ -826,6 +847,7 @@ let OperatorService = class OperatorService {
826
847
  // Read once per run like the rest of the policy: a change in Settings applies from the next start.
827
848
  networkFetch: cfg.execution.networkFetch,
828
849
  platformAccess: cfg.execution.questions === 'agree' ? 'allow' : 'ask',
850
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
829
851
  };
830
852
  /*
831
853
  * An unattended run that cannot legally execute anything is stopped here, where the operator
@@ -1062,6 +1084,8 @@ let OperatorService = class OperatorService {
1062
1084
  starting,
1063
1085
  ...(acting ? { acting } : {}),
1064
1086
  ...(run?.hold?.held ? { paused: true } : {}),
1087
+ // Git asks for a password in its own window, and the work waits for it (2026-10-26).
1088
+ ...(this.passwordAsked.size > 0 ? { password: true } : {}),
1065
1089
  // How the last message ended, while nothing runs: what the tab says until the operator has looked.
1066
1090
  ...(this.running.size === 0 && this.lastOutcome ? { last: { status: this.lastOutcome.status, at: this.lastOutcome.at } } : {}),
1067
1091
  };
@@ -1103,6 +1127,45 @@ let OperatorService = class OperatorService {
1103
1127
  const cfg = await this.settings.load();
1104
1128
  return await workspaceInfo(cfg.project?.rootDir ?? '', cfg.project?.name ?? '');
1105
1129
  }
1130
+ // --- a new branch from main, from the chat (2026-10-26) --------------------------------------------------------
1131
+ /** Why the folder's branch may not be changed now: a task at work, or the queue between its tasks. */
1132
+ branchBusy() {
1133
+ if (this.running.size > 0 || this.browser?.kind === 'run')
1134
+ return 'A task is working: stop it or let it finish first; the branch is not changed under it.';
1135
+ if (this.queueLoop)
1136
+ return 'The queue is running: stop it first; the branch is not changed under its tasks.';
1137
+ return null;
1138
+ }
1139
+ /**
1140
+ * What a new branch from main would start from (see `vcs/newBranch.ts`). With `fetch`, the remote's main is fetched
1141
+ * first — through Git's own password window when the remote asks for one, which the bot never reads; without, what
1142
+ * was last fetched here.
1143
+ */
1144
+ async newBranchPreview(fetch) {
1145
+ const ws = await this.workspace();
1146
+ if (!ws.ok)
1147
+ throw new Error(ws.problem ?? 'No project folder is open: open one first.');
1148
+ const busy = this.branchBusy();
1149
+ if (busy)
1150
+ throw new Error(busy);
1151
+ return await planNewBranch(ws.dir, { fetch, askpass: fetch ? await askpassProgram() : null });
1152
+ }
1153
+ /** The branch made and checked out, the uncommitted changes taken to it or put aside, as the operator chose. */
1154
+ async newBranchCreate(input) {
1155
+ const ws = await this.workspace();
1156
+ if (!ws.ok)
1157
+ throw new Error(ws.problem ?? 'No project folder is open: open one first.');
1158
+ const busy = this.branchBusy();
1159
+ if (busy)
1160
+ throw new Error(busy);
1161
+ return await createNewBranch(ws.dir, {
1162
+ name: typeof input.name === 'string' ? input.name : '',
1163
+ carry: input.carry === 'aside' ? 'aside' : 'take',
1164
+ fingerprint: typeof input.fingerprint === 'string' ? input.fingerprint : '',
1165
+ // The saved branch under the bot's own prefix, as its other branches are.
1166
+ prefix: DEFAULT_VCS.branchPrefix,
1167
+ });
1168
+ }
1106
1169
  /** The open folder's code, searched as VS Code's Search view does (2026-10-21, see `workspaceSearch.ts`). */
1107
1170
  async workspaceSearch(query, opts) {
1108
1171
  const ws = await this.workspace();
@@ -1316,11 +1379,24 @@ let OperatorService = class OperatorService {
1316
1379
  queueRecovered = false;
1317
1380
  /** The program is closing: the queue's loop stops where it is. */
1318
1381
  queueClosing = false;
1382
+ /** The session of the queue's task at work now (2026-10-26): where a wait for the operator is timed, to park it. */
1383
+ queueAtWork = new Set();
1384
+ /** 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. */
1385
+ parkTimers = new Map();
1386
+ /** Commands the operator approved on a parked task's card, run without asking when its chat sends them again. */
1387
+ approvedAhead = new Map();
1388
+ /** Branches made for tasks of the queue, one edit of the list at a time. */
1389
+ branchTurn = Promise.resolve();
1319
1390
  /** The queue as it is on disk; one that cannot be read is an empty one, said in the console. */
1320
1391
  async readQueue() {
1321
1392
  try {
1322
1393
  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 ?? '' };
1394
+ return {
1395
+ items: Array.isArray(q.items) ? q.items : [],
1396
+ running: q.running === true,
1397
+ updatedAt: q.updatedAt ?? '',
1398
+ ...(typeof q.parkAfterSec === 'number' ? { parkAfterSec: q.parkAfterSec } : {}),
1399
+ };
1324
1400
  }
1325
1401
  catch (e) {
1326
1402
  if (e.code !== 'ENOENT')
@@ -1334,6 +1410,7 @@ let OperatorService = class OperatorService {
1334
1410
  const q = await this.readQueue();
1335
1411
  change(q);
1336
1412
  q.updatedAt = new Date().toISOString();
1413
+ delete q.busy;
1337
1414
  await writeFileAtomically(this.queueFile, JSON.stringify(q, null, 2));
1338
1415
  return q;
1339
1416
  };
@@ -1350,7 +1427,10 @@ let OperatorService = class OperatorService {
1350
1427
  if (patch[key] === undefined)
1351
1428
  delete item[key];
1352
1429
  }
1353
- /** A queue that was running when the bot last closed: not running now, and its task in flight stopped. */
1430
+ /**
1431
+ * A queue that was running when the bot last closed: not running now, and its task in flight stopped. A parked task
1432
+ * stays parked, with what it waits for, and an answered one still carries on at the queue's next turn (2026-10-26).
1433
+ */
1354
1434
  async recoverQueue() {
1355
1435
  if (this.queueRecovered)
1356
1436
  return;
@@ -1410,7 +1490,52 @@ let OperatorService = class OperatorService {
1410
1490
  });
1411
1491
  if (problem)
1412
1492
  throw new Error(problem);
1413
- return await this.withBusy(q);
1493
+ return await this.withBusy(await this.makeQueueBranches(q));
1494
+ }
1495
+ /**
1496
+ * The branches of the tasks "on a new branch from main" that have none yet (2026-10-26), made now, while the operator
1497
+ * is at the page: the remote's main fetched once — through Git's own window if it asks for a password — and a branch
1498
+ * made at it for each, not checked out. A branch that cannot be made now is made when the task starts.
1499
+ */
1500
+ makeQueueBranches(q) {
1501
+ const run = async () => {
1502
+ const need = q.items.filter((x) => x.branch === 'main' && x.status === 'waiting' && !x.branchName);
1503
+ if (need.length === 0)
1504
+ return q;
1505
+ const ws = await this.workspace();
1506
+ if (!ws.ok || !ws.isRepo)
1507
+ return q;
1508
+ const start = await branchStart(ws.dir, await askpassProgram());
1509
+ const made = [];
1510
+ for (const item of need) {
1511
+ if ('problem' in start) {
1512
+ made.push({ id: item.id, patch: { why: `no branch could be made for it yet (${start.problem}); one is made when it starts` } });
1513
+ continue;
1514
+ }
1515
+ const branch = await makeQueueBranch(ws.dir, item.id, itemTitle(item), start);
1516
+ 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 } });
1517
+ }
1518
+ return await this.changeQueue((x) => {
1519
+ for (const m of made) {
1520
+ const item = x.items.find((i) => i.id === m.id);
1521
+ // Still a task that needs it: an edit meanwhile may have taken it out or changed where it works.
1522
+ if (item && item.branch === 'main' && !item.branchName)
1523
+ this.setQueueItem(x, m.id, m.patch);
1524
+ }
1525
+ });
1526
+ };
1527
+ const done = this.branchTurn.then(run, run);
1528
+ this.branchTurn = done.catch(() => undefined);
1529
+ return done;
1530
+ }
1531
+ /** The queue's own settings, from its page (2026-10-26): how long a task may wait for the operator before it is parked. */
1532
+ async setQueueSettings(input) {
1533
+ const sec = Number(input?.parkAfterSec);
1534
+ if (!Number.isFinite(sec) || sec < 0 || sec > MAX_PARK_AFTER_SEC)
1535
+ throw new Error(`The wait is a number of seconds, from 0 (as long as it takes) to ${MAX_PARK_AFTER_SEC}.`);
1536
+ return await this.withBusy(await this.changeQueue((x) => {
1537
+ x.parkAfterSec = Math.round(sec);
1538
+ }));
1414
1539
  }
1415
1540
  /** Runs the waiting tasks one after another, in the background; the page follows `queue()`. */
1416
1541
  async runQueue() {
@@ -1424,7 +1549,7 @@ let OperatorService = class OperatorService {
1424
1549
  const ws = await this.workspace();
1425
1550
  if (!ws.ok)
1426
1551
  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());
1552
+ const unnamed = this.queueWithoutModel(q.items.filter((x) => x.status === 'waiting' && !x.resume), await this.settings.load());
1428
1553
  if (unnamed)
1429
1554
  throw new Error(unnamed);
1430
1555
  const started = await this.changeQueue((x) => {
@@ -1462,6 +1587,104 @@ let OperatorService = class OperatorService {
1462
1587
  await this.stop(at.sessionId).catch(() => undefined);
1463
1588
  return await this.withBusy(q);
1464
1589
  }
1590
+ // --- a task of the queue set aside while it waits for the operator (2026-10-26) ---------------------------------
1591
+ //
1592
+ // Operator: "if I run a queue, every question has a timeout, since I may not be at the computer to answer; the work
1593
+ // on that task stops and the next one starts; the question is kept, for me to answer later, and everything is kept
1594
+ // even when the program is closed." A card of the task at work — a plan, a question, a subtask cut off, a command, a
1595
+ // model to choose — or Git's password window, unanswered for as long as the queue allows: the task is stopped as
1596
+ // Stop stops it (its work committed on its branch), the card kept on its record, and the queue goes on.
1597
+ /** What a card asks for, as a parked task keeps it. */
1598
+ parkedKindOf(a) {
1599
+ return a.plan ? 'plan' : a.question ? 'question' : a.retry ? 'retry' : a.model ? 'model' : 'command';
1600
+ }
1601
+ /** A card of the queue's task at work, timed: unanswered for as long as the queue allows, the task is parked. */
1602
+ parkLater(approval, kind = this.parkedKindOf(approval)) {
1603
+ const key = this.runKey(approval.sessionId);
1604
+ if (!this.queueAtWork.has(key))
1605
+ return;
1606
+ const timerKey = kind === 'password' ? `pw:${approval.sessionId}` : approval.id;
1607
+ void this.readQueue().then((q) => {
1608
+ const ms = parkAfterMs(q);
1609
+ if (ms === null || this.parkTimers.has(timerKey))
1610
+ return;
1611
+ const timer = setTimeout(() => {
1612
+ this.parkTimers.delete(timerKey);
1613
+ const still = kind === 'password' ? this.passwordAsked.has(approval.sessionId) : this.waiting.has(approval.id);
1614
+ if (still)
1615
+ void this.park(key, approval, kind, ms).catch((e) => console.error('[queue] the task could not be set aside:', e.message));
1616
+ }, ms);
1617
+ timer.unref?.();
1618
+ this.parkTimers.set(timerKey, timer);
1619
+ });
1620
+ }
1621
+ unparkLater(timerKey) {
1622
+ const timer = this.parkTimers.get(timerKey);
1623
+ if (timer)
1624
+ clearTimeout(timer);
1625
+ this.parkTimers.delete(timerKey);
1626
+ }
1627
+ /** The queue's task at work set aside: what it waits for kept on its record and on the queue's, then stopped. */
1628
+ async park(key, approval, kind, waitedMs) {
1629
+ if (!this.queueAtWork.has(key))
1630
+ return;
1631
+ const s = await this.store.getSession(key);
1632
+ const task = s?.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval');
1633
+ if (!s || !task)
1634
+ return;
1635
+ const at = new Date().toISOString();
1636
+ await this.store.updateSession(key, (x) => {
1637
+ const t = x.tasks.find((y) => y.id === task.id);
1638
+ if (t)
1639
+ t.parked = { kind, at, approval };
1640
+ });
1641
+ await this.changeQueue((x) => {
1642
+ const item = x.items.find((i) => i.sessionId === key && i.status === 'running');
1643
+ if (item)
1644
+ this.setQueueItem(x, item.id, { waitsFor: { kind, at, approval } });
1645
+ });
1646
+ this.bus.publish({ sessionId: key, taskId: task.id, type: 'task-parked', level: 'warn', data: { kind },
1647
+ 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` });
1648
+ // Git's own window, left on screen by the step it asked for: closed, so it does not ask for nothing.
1649
+ if (kind === 'password') {
1650
+ const ask = await askpassProgram();
1651
+ if (ask)
1652
+ await closePasswordWindows(ask, new Date(Date.parse(approval.createdAt) - 5_000)).catch(() => 0);
1653
+ }
1654
+ await this.stop(key).catch(() => undefined);
1655
+ }
1656
+ /**
1657
+ * The operator's answer to a parked task, given when they are back (2026-10-26): kept on the task's record, and the
1658
+ * task waits to carry on from where it stopped — at the queue's next turn, before the others; when the queue is not
1659
+ * running, when it is run. `stop` leaves it stopped.
1660
+ */
1661
+ async answerParked(itemId, input) {
1662
+ await this.recoverQueue();
1663
+ const q = await this.readQueue();
1664
+ const item = q.items.find((x) => x.id === itemId);
1665
+ if (!item)
1666
+ throw new Error('That task is not in the queue any more.');
1667
+ if (item.status !== 'parked' || !item.sessionId)
1668
+ throw new Error('That task is not waiting for an answer.');
1669
+ const s = await this.store.getSession(item.sessionId);
1670
+ const task = s?.tasks.find((t) => t.parked && !t.parked.answer);
1671
+ if (!s || !task?.parked)
1672
+ throw new Error('What that task waited for is not on its record any more; run it again.');
1673
+ if (input?.stop === true) {
1674
+ return await this.withBusy(await this.changeQueue((x) => this.setQueueItem(x, itemId, { status: 'stopped', why: 'stopped by the operator at its card', waitsFor: undefined })));
1675
+ }
1676
+ const answer = parkedAnswerFrom(task.parked, input);
1677
+ if ('problem' in answer)
1678
+ throw new Error(answer.problem);
1679
+ await this.store.updateSession(s.id, (x) => {
1680
+ const t = x.tasks.find((y) => y.id === task.id);
1681
+ if (t?.parked)
1682
+ t.parked.answer = { ...answer, at: new Date().toISOString() };
1683
+ });
1684
+ 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' }));
1685
+ 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` });
1686
+ return await this.withBusy(next);
1687
+ }
1465
1688
  async runQueueLoop() {
1466
1689
  const now = () => new Date().toISOString();
1467
1690
  for (;;) {
@@ -1488,15 +1711,16 @@ let OperatorService = class OperatorService {
1488
1711
  continue;
1489
1712
  }
1490
1713
  const item = step.run;
1491
- await this.changeQueue((x) => this.setQueueItem(x, item.id, { status: 'running', startedAt: now(), why: undefined, endedAt: undefined, sessionId: undefined }));
1714
+ // An answered parked task keeps its chat: it carries on there.
1715
+ 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
1716
  const ended = await this.runQueueItem(item).catch((e) => ({ status: 'failed', why: e.message }));
1493
1717
  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.
1718
+ // Stopped — from the queue, or the chat's Stop: the rest wait for the operator. Parked: the queue goes on.
1495
1719
  if (ended.status === 'stopped')
1496
1720
  return;
1497
1721
  }
1498
1722
  }
1499
- /** One task of the queue, in a new chat, to its end. */
1723
+ /** One task of the queue, in a new chat — or, answered after it was parked, in its own — to its end. */
1500
1724
  async runQueueItem(item) {
1501
1725
  const pause = (ms) => new Promise((r) => setTimeout(r, ms));
1502
1726
  const stillRunning = async () => (await this.readQueue()).running;
@@ -1511,38 +1735,74 @@ let OperatorService = class OperatorService {
1511
1735
  const ws = await this.workspace();
1512
1736
  if (!ws.ok)
1513
1737
  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
1738
  const cfg = await this.settings.load();
1739
+ let sessionId;
1740
+ let taskId;
1741
+ if (item.resume && item.sessionId) {
1742
+ const carried = await this.resumeParked(item.sessionId, ws.dir);
1743
+ if ('problem' in carried)
1744
+ return { status: 'failed', why: carried.problem, sessionId: item.sessionId };
1745
+ sessionId = item.sessionId;
1746
+ taskId = carried.taskId;
1747
+ }
1748
+ else {
1749
+ // Settings may have changed since the queue was started.
1750
+ const unnamed = this.queueWithoutModel([item], cfg);
1751
+ if (unnamed)
1752
+ return { status: 'failed', why: unnamed };
1753
+ // Its own branch, made when it was added (2026-10-26): brought up to the remote's main if nothing is on it yet.
1754
+ let branchName = item.branch === 'main' && ws.isRepo ? item.branchName : undefined;
1755
+ if (branchName && item.branchBase) {
1756
+ if (!(await branchExists(ws.dir, branchName)))
1757
+ branchName = undefined;
1758
+ else {
1759
+ const fresh = await refreshQueueBranch(ws.dir, branchName, item.branchBase);
1760
+ if (fresh.moved)
1761
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, { branchBase: fresh.base, branchFrom: 'origin/main' }));
1762
+ }
1763
+ }
1764
+ // Not made when it was added — no repository then, or no main to make it from: made now, asking nobody anything.
1765
+ let branchFrom = item.branchFrom;
1766
+ if (item.branch === 'main' && ws.isRepo && !branchName) {
1767
+ const start = await branchStart(ws.dir, null);
1768
+ if ('problem' in start)
1769
+ return { status: 'failed', why: `no branch could be made for it: ${start.problem}` };
1770
+ const made = await makeQueueBranch(ws.dir, item.id, itemTitle(item), start);
1771
+ if ('problem' in made)
1772
+ return { status: 'failed', why: `no branch could be made for it: ${made.problem}` };
1773
+ branchName = made.branch;
1774
+ branchFrom = start.from;
1775
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, { branchName: made.branch, branchBase: made.base, branchFrom: start.from }));
1776
+ }
1777
+ if (item.branch === 'main' && !ws.isRepo)
1778
+ return { status: 'failed', why: `${ws.dir} is not a git repository, so there is no main to make a branch from` };
1779
+ // As the chat's box sends a first message: the model, plan first, the review and its model, two chats, the skill.
1780
+ const sent = await this.chatSend({
1781
+ text: item.prompt,
1782
+ ...(item.model ? { model: item.model } : {}),
1783
+ ...(item.plan ? { planMode: true } : {}),
1784
+ review: item.review,
1785
+ ...(item.reviewModel ? { reviewModel: item.reviewModel } : {}),
1786
+ ...(item.lead ? { lead: true, ...(item.workerModel ? { workerModel: item.workerModel } : {}) } : {}),
1787
+ ...(item.skill ? { skill: item.skill } : {}),
1788
+ });
1789
+ sessionId = sent.threadId;
1790
+ taskId = sent.taskId;
1791
+ await this.store.updateSession(sessionId, (s) => {
1792
+ s.name = `queue: ${itemTitle(item)}`;
1793
+ s.queueItem = item.id;
1794
+ // The runner's own version control on the branch made for it, its work committed there (`existing-branch`).
1795
+ if (branchName)
1796
+ s.vcs = { ...DEFAULT_VCS, enabled: true, repoDir: ws.dir, commitOnFinish: true, startFrom: 'existing-branch', existingBranch: branchName };
1797
+ });
1798
+ // Where its branch came from, told with its opening message: the local main when the server's could not be read.
1799
+ if (branchName) {
1800
+ await this.store.addTaskNote(sessionId, taskId, branchFrom && branchFrom !== 'origin/main'
1801
+ ? `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.`
1802
+ : `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);
1803
+ }
1804
+ await this.changeQueue((x) => this.setQueueItem(x, item.id, { sessionId }));
1805
+ }
1546
1806
  /*
1547
1807
  * A message of the chat sent meanwhile has the browser: this one starts after it, never refused for it. The browser
1548
1808
  * is looked at and taken in the same moment — `start` takes it before it awaits anything.
@@ -1552,24 +1812,113 @@ let OperatorService = class OperatorService {
1552
1812
  return { status: 'stopped', why: 'the queue was stopped before it began', sessionId };
1553
1813
  await pause(1_000);
1554
1814
  }
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);
1815
+ this.queueAtWork.add(sessionId);
1816
+ try {
1817
+ const reply = await this.start(sessionId, cfg.execution.mode);
1818
+ if (!reply.started)
1819
+ return { status: 'failed', why: reply.reason ?? 'it did not start', sessionId };
1820
+ // Until its run has ended and its window let the browser go, so the next one can have it.
1821
+ let asked = false;
1822
+ while (this.running.has(sessionId) || (holder()?.kind === 'run' && holder().sessionId === sessionId)) {
1823
+ if (this.queueClosing)
1824
+ return { status: 'stopped', why: 'the bot was closed while it ran', sessionId };
1825
+ if (!asked && !(await stillRunning())) {
1826
+ asked = true;
1827
+ await this.stop(sessionId).catch(() => undefined);
1828
+ }
1829
+ await pause(1_000);
1566
1830
  }
1567
- await pause(1_000);
1568
1831
  }
1569
- const task = (await this.store.getSession(sessionId))?.tasks.find((t) => t.id === sent.taskId);
1832
+ finally {
1833
+ this.queueAtWork.delete(sessionId);
1834
+ }
1835
+ const task = (await this.store.getSession(sessionId))?.tasks.find((t) => t.id === taskId);
1836
+ // Set aside while it waited for the operator: what for, said; the card is on its record and on the queue's.
1837
+ if (task?.parked && !task.parked.answer) {
1838
+ // Its ending says so, rather than "stopped by the operator": nobody stopped it.
1839
+ const why = `waits for you: ${PARKED_WORDS[task.parked.kind]}`;
1840
+ await this.store.updateSession(sessionId, (x) => {
1841
+ const t = x.tasks.find((y) => y.id === taskId);
1842
+ if (t)
1843
+ t.reason = `set aside by the queue while it waited for you; it ${why}`;
1844
+ });
1845
+ return { status: 'parked', why, sessionId };
1846
+ }
1570
1847
  const status = statusOfTask(task?.status);
1571
1848
  return { status, ...(status !== 'done' ? { why: task?.reason ?? `it ended ${task?.status ?? 'without a record'}` } : {}), sessionId };
1572
1849
  }
1850
+ /**
1851
+ * A parked task, answered, carried on in its own chat from where it stopped (2026-10-26): the answer does what it
1852
+ * says — a plan approved stays approved, a plan sent back is made again first, a command approved runs without asking
1853
+ * 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
1854
+ * note with the attempt that carries the task on.
1855
+ */
1856
+ async resumeParked(sessionId, dir) {
1857
+ const s = await this.store.getSession(sessionId);
1858
+ const task = s?.tasks.find((t) => t.parked?.answer);
1859
+ const p = task?.parked;
1860
+ const a = p?.answer;
1861
+ if (!s || !task || !p || !a)
1862
+ return { problem: 'its answer is not on its record any more; run it again' };
1863
+ const continuing = { fromAttempt: task.attempt ?? 1, stoppedBecause: task.reason, how: 'parked', parkedFor: p.kind };
1864
+ let note = '';
1865
+ let approvedPlan;
1866
+ const command = p.approval.description.replace(/^\[[\w-]+\]\s*/, '');
1867
+ if (a.kind === 'plan') {
1868
+ if (a.decision === 'approve' && p.approval.plan) {
1869
+ approvedPlan = { ...p.approval.plan.plan, approved: { by: 'operator', at: a.at, ...(a.note?.trim() ? { note: a.note.trim() } : {}) } };
1870
+ note = planApprovedMessage(approvedPlan.approved);
1871
+ }
1872
+ else {
1873
+ continuing.replan = true;
1874
+ note = planReviseMessage(a.note?.trim() || 'Make the plan more concrete: name the files and the stages.', p.approval.plan?.plan.version ?? 1);
1875
+ }
1876
+ }
1877
+ else if (a.kind === 'question') {
1878
+ note = `You asked: ${p.approval.question?.text ?? ''}\n\nThe operator answers: ${a.answer}`;
1879
+ }
1880
+ else if (a.kind === 'retry' && p.approval.retry) {
1881
+ const r = p.approval.retry;
1882
+ if (a.choice === 'accept')
1883
+ note = `Subtask ${r.n} (${r.title}) is taken as failed, at the operator's word: decide what to do next without it.`;
1884
+ else {
1885
+ if (a.choice === 'restore') {
1886
+ const worker = await this.store.getSession(p.approval.sessionId);
1887
+ const cp = worker?.tasks.find((t) => t.id === p.approval.taskId)?.checkpoint;
1888
+ const back = cp ? await restoreCheckpoint(dir, cp) : { ok: false, problem: 'the subtask\'s start was not photographed' };
1889
+ if (!back.ok)
1890
+ return { problem: `the folder could not be put back to the subtask's start (${back.problem}); answer it again with another choice` };
1891
+ }
1892
+ continuing.retrySubtask = { n: r.n, ...(a.choice === 'fresh' ? { fresh: true } : {}) };
1893
+ }
1894
+ }
1895
+ else if (a.kind === 'command') {
1896
+ if (a.decision === 'run') {
1897
+ this.approvedAhead.set(sessionId, [...(this.approvedAhead.get(sessionId) ?? []), command.trim()]);
1898
+ note = `The command you were waiting to run is approved now: ${command}\n\nSend it again and it runs.`;
1899
+ }
1900
+ else
1901
+ note = `The command ${command} is not approved: do without it.`;
1902
+ }
1903
+ else {
1904
+ note =
1905
+ p.kind === 'password'
1906
+ ? '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.'
1907
+ : 'The operator is here now: the model is chosen by hand in the Copilot window when it is asked for.';
1908
+ }
1909
+ await this.store.rerunTask(sessionId, task.id, {}, continuing);
1910
+ if (approvedPlan) {
1911
+ await this.store.updateSession(sessionId, (x) => {
1912
+ const t = x.tasks.find((y) => y.id === task.id);
1913
+ if (t)
1914
+ t.plan = approvedPlan;
1915
+ });
1916
+ }
1917
+ if (note)
1918
+ await this.store.addTaskNote(sessionId, task.id, note);
1919
+ 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})` });
1920
+ return { taskId: task.id };
1921
+ }
1573
1922
  // --- skills (2026-10-21) ----------------------------------------------------------------------------
1574
1923
  /** The skills in Settings, and how long what each is for may be. */
1575
1924
  async skills() {
@@ -1701,6 +2050,7 @@ let OperatorService = class OperatorService {
1701
2050
  approval,
1702
2051
  resolve: (d) => resolveAnswer(d.action === 'run' ? 'recheck' : d.action === 'skip' ? 'continue' : 'stop'),
1703
2052
  });
2053
+ this.parkLater(approval);
1704
2054
  this.bus.publish({ sessionId: ask.sessionId, type: 'approval-requested', level: 'warn',
1705
2055
  message: `choose "${ask.asked}" in the Copilot window, then answer on the card`, data: { approvalId: approval.id, model: approval.model } });
1706
2056
  });
@@ -1733,6 +2083,7 @@ let OperatorService = class OperatorService {
1733
2083
  resolve: () => resolveAnswer('stop'),
1734
2084
  resolveAnswer,
1735
2085
  });
2086
+ this.parkLater(approval);
1736
2087
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1737
2088
  message: `the lead asks the operator: ${ask.question}`, data: { approvalId: approval.id, question: approval.question } });
1738
2089
  });
@@ -1760,6 +2111,7 @@ let OperatorService = class OperatorService {
1760
2111
  retry: ask.retry,
1761
2112
  };
1762
2113
  this.waiting.set(approval.id, { approval, resolve: () => resolveRetry('stop'), resolveRetry });
2114
+ this.parkLater(approval);
1763
2115
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1764
2116
  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
2117
  });
@@ -1844,6 +2196,7 @@ let OperatorService = class OperatorService {
1844
2196
  resolve: (d) => resolveAnswer(d.action === 'run' ? { decision: 'approve' } : { decision: 'stop' }),
1845
2197
  resolvePlan: resolveAnswer,
1846
2198
  });
2199
+ this.parkLater(approval);
1847
2200
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1848
2201
  message: `the plan of "${ask.title}" (version ${ask.plan.version}) is waiting for you to approve it`, data: { approvalId: approval.id, plan: true } });
1849
2202
  });
@@ -1969,6 +2322,15 @@ let OperatorService = class OperatorService {
1969
2322
  resolvePromise({ action: 'run' });
1970
2323
  return;
1971
2324
  }
2325
+ // Approved on the card of the task while the queue had it set aside (2026-10-26): once, as it was approved.
2326
+ const ahead = this.approvedAhead.get(this.runKey(ctx.sessionId ?? '')) ?? this.approvedAhead.get(ctx.sessionId ?? '');
2327
+ const at = ahead ? ahead.indexOf(step.cmd.trim()) : -1;
2328
+ if (ahead && at >= 0) {
2329
+ ahead.splice(at, 1);
2330
+ 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}` });
2331
+ resolvePromise({ action: 'run' });
2332
+ return;
2333
+ }
1972
2334
  const approval = {
1973
2335
  id: newId('a-'),
1974
2336
  sessionId: ctx.sessionId ?? '',
@@ -1979,11 +2341,13 @@ let OperatorService = class OperatorService {
1979
2341
  ...(ctx.actor ? { actor: ctx.actor } : {}),
1980
2342
  ...(held?.network ? { network: held.network } : {}),
1981
2343
  ...(held?.platform ? { platform: held.platform } : {}),
2344
+ ...(held?.readOnly ? { readOnly: held.readOnly } : {}),
1982
2345
  };
1983
2346
  this.waiting.set(approval.id, { approval, resolve: resolvePromise });
2347
+ this.parkLater(approval);
1984
2348
  this.bus.publish({ sessionId: approval.sessionId, taskId: approval.taskId, type: 'approval-requested', level: 'warn',
1985
2349
  message: held
1986
- ? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
2350
+ ? `held for the operator — ${[held.platform ? `it reaches ${held.platform} with the operator's access` : '', held.readOnly ? `set to read only, and ${held.readOnly}` : '', held.network ?? ''].filter(Boolean).join('; ')}: ${approval.description}`
1987
2351
  : `waiting for approval: ${approval.description}`,
1988
2352
  data: { ...approval } });
1989
2353
  }), signal);
package/dist/src/cli.js CHANGED
@@ -501,6 +501,7 @@ program
501
501
  lockedToConfirm: cfg.policyLock?.maxMode === 'confirm',
502
502
  networkFetch: cfg.execution.networkFetch,
503
503
  platformAccess: cfg.execution.questions === 'agree' ? 'allow' : 'ask',
504
+ readOnlyPrograms: cfg.execution.readOnlyPrograms,
504
505
  };
505
506
  const authorizer = cfg.execution.mode === 'unattended'
506
507
  ? unattendedAuthorizer(policy)