copilot-operator 0.1.51 → 0.1.52

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 (64) hide show
  1. package/README.md +8 -3
  2. package/dist/src/api/operator.controller.js +32 -81
  3. package/dist/src/api/operator.service.js +166 -109
  4. package/dist/src/config/schema.js +13 -0
  5. package/dist/src/orchestrator/leadRunner.js +559 -0
  6. package/dist/src/orchestrator/taskRunner.js +55 -17
  7. package/dist/src/plan/kerrigan.js +172 -47
  8. package/dist/src/plan/systemGuide.js +443 -506
  9. package/dist/src/protocol/leadSchema.js +156 -0
  10. package/dist/src/protocol/parser.js +1 -1
  11. package/dist/src/session/chatNotice.js +115 -0
  12. package/dist/src/session/checkpoint.js +19 -0
  13. package/dist/src/session/compose.js +1 -1
  14. package/dist/src/session/store.js +18 -72
  15. package/dist/src/transport/copilotTransport.js +2 -0
  16. package/dist/web/404.html +13 -18
  17. package/dist/web/_next/static/_1zhoDsMOPAH2xW702E5A/_buildManifest.js +1 -0
  18. package/dist/web/_next/static/chunks/163.dbd7d36584d0bb37.js +1 -0
  19. package/dist/web/_next/static/chunks/220.35531b39410e1a9f.js +1 -0
  20. package/dist/web/_next/static/chunks/548.71ac96c94136659b.js +1 -0
  21. package/dist/web/_next/static/chunks/584.6df695c5b86a75aa.js +1 -0
  22. package/dist/web/_next/static/chunks/67.9ed79e2fbfb56f26.js +1 -0
  23. package/dist/web/_next/static/chunks/714.1e2338736a70b9c7.js +1 -0
  24. package/dist/web/_next/static/chunks/747.d2c1249d736dc03b.js +1 -0
  25. package/dist/web/_next/static/chunks/77.a200abef0f5b4a7f.js +1 -0
  26. package/dist/web/_next/static/chunks/808-bc7d7eac6d823291.js +1 -0
  27. package/dist/web/_next/static/chunks/921-dc5538cd779c6432.js +1 -0
  28. package/dist/web/_next/static/chunks/app/defaults/page-edd7534ca9ecf366.js +1 -0
  29. package/dist/web/_next/static/chunks/app/layout-8f99a164d76897a0.js +1 -0
  30. package/dist/web/_next/static/chunks/app/page-4bed816eda370d0c.js +1 -0
  31. package/dist/web/_next/static/chunks/app/system/page-1cf9e75e76da59ed.js +1 -0
  32. package/dist/web/_next/static/chunks/webpack-77147e31d2125631.js +1 -0
  33. package/dist/web/_next/static/css/3bea264adc472bc8.css +1 -0
  34. package/dist/web/defaults.html +13 -18
  35. package/dist/web/defaults.txt +9 -9
  36. package/dist/web/index.html +13 -18
  37. package/dist/web/index.txt +9 -9
  38. package/dist/web/system.html +13 -18
  39. package/dist/web/system.txt +9 -9
  40. package/package.json +4 -5
  41. package/prompts/lead1.md +116 -0
  42. package/dist/src/vcs/prepareFromRemote.js +0 -288
  43. package/dist/src/vcs/remoteAuth.js +0 -117
  44. package/dist/src/vcs/syncCommand.js +0 -97
  45. package/dist/web/_next/static/chunks/190-70555f20dd0da19b.js +0 -1
  46. package/dist/web/_next/static/chunks/643-e85d221d57900ed7.js +0 -1
  47. package/dist/web/_next/static/chunks/867-869900ec999e6345.js +0 -1
  48. package/dist/web/_next/static/chunks/app/appearance/page-cdef33c421397cbe.js +0 -1
  49. package/dist/web/_next/static/chunks/app/defaults/page-e0a2b8f9a41a94c4.js +0 -1
  50. package/dist/web/_next/static/chunks/app/layout-b4fc21e26e1bad95.js +0 -1
  51. package/dist/web/_next/static/chunks/app/level1/page-31b74cae86d960d8.js +0 -1
  52. package/dist/web/_next/static/chunks/app/page-1075921d44db3e4d.js +0 -1
  53. package/dist/web/_next/static/chunks/app/presets/page-f8abdd83cdf468f7.js +0 -1
  54. package/dist/web/_next/static/chunks/app/system/page-2a270bb885885821.js +0 -1
  55. package/dist/web/_next/static/chunks/webpack-0f31b926d9a9c5a4.js +0 -1
  56. package/dist/web/_next/static/css/8b14cb3cf0051138.css +0 -1
  57. package/dist/web/_next/static/eqTUTH_SJtBgNgq8Zzy3n/_buildManifest.js +0 -1
  58. package/dist/web/appearance.html +0 -18
  59. package/dist/web/appearance.txt +0 -25
  60. package/dist/web/level1.html +0 -18
  61. package/dist/web/level1.txt +0 -25
  62. package/dist/web/presets.html +0 -21
  63. package/dist/web/presets.txt +0 -25
  64. /package/dist/web/_next/static/{eqTUTH_SJtBgNgq8Zzy3n → _1zhoDsMOPAH2xW702E5A}/_ssgManifest.js +0 -0
@@ -30,6 +30,9 @@ import { chatNotice } from '../session/chatNotice.js';
30
30
  import { kerriganFileName, kerriganPersona } from '../plan/kerrigan.js';
31
31
  import { workspaceCommit, workspaceGit, workspaceGitVersions } from '../session/workspaceGit.js';
32
32
  import { chatCode } from '../transport/chatSession.js';
33
+ /** The folders the operator works in: the default new sessions start on, and the rest by name. */
34
+ /** The longest level 2 a project may have: Kerrigan carries each one whole. */
35
+ export const MAX_PROJECT_LEVEL2 = 8000;
33
36
  /**
34
37
  * A settings file or a policy lock that cannot be used: answered 409 with its own message on every route
35
38
  * (see `server.ts`), so a start passes it on rather than answering it as a start that did not happen.
@@ -58,8 +61,6 @@ import { assessIsolation, readIsolationSignals } from '../exec/isolation.js';
58
61
  import { unattendedPrecondition } from '../exec/policy.js';
59
62
  import { createTransport } from '../transport/chatTransport.js';
60
63
  import { composeHandoff } from '../session/handoff.js';
61
- import { planPrepare, prepareFromRemote } from '../vcs/prepareFromRemote.js';
62
- import { askpassProgram } from '../vcs/remoteAuth.js';
63
64
  import { appendRunLog, appendSessionLog, readRunLog } from '../session/runLog.js';
64
65
  import { StartFailures, failureReport, refOf } from '../session/startFailure.js';
65
66
  import { formatTerminal, localTime, terminalLines, terminalLogFile } from '../log/terminal.js';
@@ -129,6 +130,15 @@ let OperatorService = class OperatorService {
129
130
  startFailures = new StartFailures();
130
131
  running = new Map();
131
132
  waiting = new Map();
133
+ /**
134
+ * The workers of the two-chat mode, by the session of the lead they work for (2026-10-20). A worker's steps and cards
135
+ * carry its own session's id, while the run, its mode and its Stop are the lead's: they are looked up through this.
136
+ */
137
+ workerLeads = new Map();
138
+ /** The session whose run a session's steps belong to: its own, or its lead's for a worker. */
139
+ runKey(sessionId) {
140
+ return this.running.has(sessionId) ? sessionId : (this.workerLeads.get(sessionId) ?? sessionId);
141
+ }
132
142
  ready = null;
133
143
  /**
134
144
  * What has the browser now: one session's run, a batch, or a read of the model list.
@@ -227,30 +237,6 @@ let OperatorService = class OperatorService {
227
237
  await this.init();
228
238
  return await this.store.getLevel1();
229
239
  }
230
- async setLevel1(content) {
231
- await this.init();
232
- await this.store.setLevel1(content);
233
- }
234
- async resetLevel1() {
235
- await this.init();
236
- await this.store.resetLevel1();
237
- return await this.store.getLevel1();
238
- }
239
- // --- the organisation's part of the plan persona -------------------------------------
240
- // --- level 2 presets ------------------------------------------------------------------
241
- async listPresets() {
242
- await this.init();
243
- return await this.store.listPresets();
244
- }
245
- async savePreset(name, content) {
246
- await this.init();
247
- return await this.store.savePreset(name, content);
248
- }
249
- async deletePreset(name) {
250
- await this.init();
251
- await this.store.deletePreset(name);
252
- }
253
- // --- named personas for the import page -----------------------------------------------
254
240
  // --- sessions and tasks ---------------------------------------------------------------
255
241
  async listSessions() {
256
242
  await this.init();
@@ -270,7 +256,7 @@ let OperatorService = class OperatorService {
270
256
  if (patch.active !== undefined && this.running.has(id)) {
271
257
  throw new Error('This session is running; its status can be changed once it has stopped.');
272
258
  }
273
- return await this.store.updateSession(id, (s) => {
259
+ const updated = await this.store.updateSession(id, (s) => {
274
260
  const before = { model: s.model, manualModel: s.manualModel };
275
261
  if (patch.name !== undefined)
276
262
  s.name = patch.name.trim() || s.name;
@@ -296,6 +282,12 @@ let OperatorService = class OperatorService {
296
282
  if ((patch.model !== undefined || typeof patch.manualModel === 'boolean') && (s.model !== before.model || !!s.manualModel !== !!before.manualModel)) {
297
283
  delete s.modelByHand;
298
284
  }
285
+ // The worker's model (two chats), kept on the lead's session and given to its worker below.
286
+ if (s.lead && (patch.workerModel !== undefined || typeof patch.workerManualModel === 'boolean')) {
287
+ const manual = typeof patch.workerManualModel === 'boolean' ? patch.workerManualModel : !!s.lead.workerManualModel;
288
+ const model = patch.workerModel !== undefined ? patch.workerModel.trim() : (s.lead.workerModel ?? '');
289
+ s.lead = { ...s.lead, workerManualModel: manual || undefined, workerModel: manual ? undefined : model || undefined };
290
+ }
299
291
  // The same for the group: clearing it gives this session its conversation back. It does
300
292
  // not move the conversation it is already in; that history is where it is.
301
293
  if (patch.conversationGroup !== undefined)
@@ -397,6 +389,19 @@ let OperatorService = class OperatorService {
397
389
  s.vcs = merged;
398
390
  }
399
391
  });
392
+ // The worker's model (two chats): given to the worker's session too, which asks again for one chosen by hand.
393
+ const workerId = updated.lead?.workerSessionId;
394
+ if (workerId && (patch.workerModel !== undefined || typeof patch.workerManualModel === 'boolean')) {
395
+ await this.store
396
+ .updateSession(workerId, (w) => {
397
+ w.manualModel = updated.lead?.workerManualModel ? true : undefined;
398
+ w.model = updated.lead?.workerManualModel ? undefined : updated.lead?.workerModel;
399
+ w.modelSource = w.model ? 'operator' : undefined;
400
+ delete w.modelByHand;
401
+ })
402
+ .catch(() => undefined);
403
+ }
404
+ return updated;
400
405
  }
401
406
  /**
402
407
  * A note to the chat about a task (2026-10-14): queued, running or waiting, it goes out with the task's
@@ -581,7 +586,7 @@ let OperatorService = class OperatorService {
581
586
  if (tasks.length === 0)
582
587
  return;
583
588
  // Refused at its turn, nothing of it began: said as a start that could not happen, not as a stop.
584
- await window.showNotice(chatNotice(s.lang === 'bg' ? 'bg' : 'en', tasks, tally.error ?? tally.refused)).catch(() => undefined);
589
+ await window.showNotice(chatNotice(s.lang || 'en', tasks, tally.error ?? tally.refused)).catch(() => undefined);
585
590
  }
586
591
  /** The program is closing: so is the window the chat left open. */
587
592
  async onModuleDestroy() {
@@ -785,6 +790,11 @@ let OperatorService = class OperatorService {
785
790
  const startedAt = new Date().toISOString();
786
791
  const hold = new Hold();
787
792
  this.running.set(sessionId, { controller, startedAt, mode, policy, hold });
793
+ {
794
+ const asLead = await this.store.getSession(sessionId);
795
+ if (asLead?.lead?.workerSessionId)
796
+ this.workerLeads.set(asLead.lead.workerSessionId, sessionId);
797
+ }
788
798
  this.bus.publish({ sessionId, type: 'run-requested', level: 'info', message: `starting in ${mode} mode` });
789
799
  // Said at the start of every run, in both modes, because it is the one fact about this tool a
790
800
  // data-protection team needs and the one an operator forgets: the reports leave the machine.
@@ -851,6 +861,9 @@ let OperatorService = class OperatorService {
851
861
  },
852
862
  // Plan mode `approve`: the plan is put to the operator on the approvals card.
853
863
  approvePlan: (ask) => this.askPlanApproval(ask, controller.signal),
864
+ // The two-chat mode (2026-10-20): the lead's questions, and the worker the run speaks for too.
865
+ askQuestion: (ask) => this.askLeadQuestion(ask, controller.signal),
866
+ onWorker: (workerId) => this.workerLeads.set(workerId, sessionId),
854
867
  hold,
855
868
  })
856
869
  .then(async (outcome) => {
@@ -876,13 +889,13 @@ let OperatorService = class OperatorService {
876
889
  return tally;
877
890
  })
878
891
  .finally(() => {
879
- this.running.delete(sessionId);
880
892
  for (const [id, w] of this.waiting) {
881
- if (w.approval.sessionId === sessionId) {
893
+ if (this.runKey(w.approval.sessionId) === sessionId) {
882
894
  w.resolve({ action: 'abort', reason: 'the run ended' });
883
895
  this.waiting.delete(id);
884
896
  }
885
897
  }
898
+ this.running.delete(sessionId);
886
899
  });
887
900
  return { started: true, done };
888
901
  }
@@ -943,7 +956,7 @@ let OperatorService = class OperatorService {
943
956
  return { stopping: false };
944
957
  r.controller.abort();
945
958
  for (const [id, w] of this.waiting) {
946
- if (w.approval.sessionId === sessionId) {
959
+ if (this.runKey(w.approval.sessionId) === sessionId) {
947
960
  w.resolve({ action: 'abort', reason: 'stopped by the operator', by: 'operator' });
948
961
  this.waiting.delete(id);
949
962
  }
@@ -1052,30 +1065,41 @@ let OperatorService = class OperatorService {
1052
1065
  }
1053
1066
  /**
1054
1067
  * Kerrigan (2026-10-20): the persona the operator may give to a chat of their own, in the language asked for, with
1055
- * this machine's limits in it. Nothing is sent anywhere: the page saves it or copies it. See `plan/kerrigan.ts`.
1068
+ * this machine's limits in it and the projects of Settings — each one's folder, its branch now, and the level 2 the
1069
+ * operator wrote for it. Nothing is sent anywhere: the page saves it or copies it. See `plan/kerrigan.ts`; in a
1070
+ * language she is not written out in, the page fills in the names of the controls (`filled: false`).
1056
1071
  */
1057
1072
  async kerrigan(lang) {
1058
1073
  const cfg = await this.settings.load();
1074
+ const p = await this.project();
1075
+ const projects = [
1076
+ ...(p.rootDir ? [{ name: p.name, rootDir: p.rootDir, ...(p.branch ? { branch: p.branch } : {}), level2: p.level2, chat: true }] : []),
1077
+ ...p.others.map((o) => ({ name: o.name, rootDir: o.rootDir, ...(o.branch ? { branch: o.branch } : {}), level2: o.level2 })),
1078
+ ];
1059
1079
  const text = kerriganPersona(lang, {
1060
1080
  version: botVersion(),
1061
1081
  maxIterations: cfg.limits.maxIterations,
1062
1082
  maxRunMinutes: cfg.limits.maxRunMinutes,
1063
1083
  autoContinue: cfg.limits.autoContinue ?? 0,
1084
+ maxReviewRounds: cfg.limits.maxReviewRounds ?? 2,
1085
+ maxSubtasks: cfg.limits.maxSubtasks ?? 20,
1086
+ projects,
1064
1087
  });
1065
- return { lang, fileName: kerriganFileName(lang), text };
1088
+ return { lang, fileName: kerriganFileName(lang), text, filled: lang === 'en' || lang === 'bg' };
1066
1089
  }
1067
1090
  /** The chat's conversations, newest first. */
1068
1091
  async chatThreads() {
1069
1092
  await this.init();
1070
1093
  return (await this.store.listSessions())
1071
- .filter((s) => s.kind === 'chat')
1094
+ // A worker's session (two chats) is not a conversation of the list: it is shown under its lead's messages.
1095
+ .filter((s) => s.kind === 'chat' && !s.workerOf)
1072
1096
  .sort((a, b) => b.createdAt.localeCompare(a.createdAt))
1073
1097
  .map((s) => ({ id: s.id, name: s.name, createdAt: s.createdAt, status: s.status, turns: s.tasks.length, running: this.running.has(s.id), repoDir: s.vcs?.repoDir || s.projectDir }));
1074
1098
  }
1075
1099
  /**
1076
1100
  * A message written in the chat. With no conversation yet, one is made in the open project folder: a session of
1077
- * kind `chat`, one branch for all of it, no independent review, plan mode off, so each message is answered as
1078
- * it would be in an IDE's chat. The message becomes a task of it, queued; the caller starts it (the start window
1101
+ * kind `chat`, one branch for all of it, reviewed by a conversation of its own unless "Review" under the box is
1102
+ * unticked (2026-10-20), plan mode as chosen there, so each message is answered as it would be in an IDE's chat. The message becomes a task of it, queued; the caller starts it (the start window
1079
1103
  * the first time, where the work starts being asked once). While the conversation is working, the message is a
1080
1104
  * note to the task in flight, which the chat gets with its next report.
1081
1105
  */
@@ -1105,7 +1129,12 @@ let OperatorService = class OperatorService {
1105
1129
  session = await this.store.updateSession(created.id, (s) => {
1106
1130
  s.kind = 'chat';
1107
1131
  s.onFailure = 'continue';
1108
- s.review = { enabled: false, model: '' };
1132
+ /*
1133
+ * The review as chosen under the box (operator, 2026-10-20): the box is on unless unticked, and the page always
1134
+ * says which. A second conversation checks the work when it says it is done, and sends back what it finds; it
1135
+ * was off for the chat from 2026-10-17. Asked for without the box — the API on its own, a script — it stays off.
1136
+ */
1137
+ s.review = { enabled: input.review === true, model: '' };
1109
1138
  // Plan mode as chosen under the box (2026-10-20, "as in Claude Code"): the plan first, approved by the operator.
1110
1139
  s.planMode = input.planMode ? 'approve' : 'off';
1111
1140
  /*
@@ -1115,6 +1144,17 @@ let OperatorService = class OperatorService {
1115
1144
  */
1116
1145
  s.vcs = { ...(s.vcs ?? DEFAULT_VCS), enabled: false, repoDir: '' };
1117
1146
  s.projectDir = ws.dir;
1147
+ /*
1148
+ * Two chats (operator, 2026-10-20): this conversation is the lead's, and a worker carries out its subtasks. The
1149
+ * lead judges the worker's reports, so there is no review of its own.
1150
+ */
1151
+ if (input.lead) {
1152
+ s.lead = {
1153
+ ...(input.workerManualModel ? { workerManualModel: true } : {}),
1154
+ ...(!input.workerManualModel && input.workerModel?.trim() ? { workerModel: input.workerModel.trim() } : {}),
1155
+ };
1156
+ s.review = { enabled: false, model: '' };
1157
+ }
1118
1158
  // The model chosen in the chat for this conversation: the operator's word, which outranks Settings.
1119
1159
  if (input.manualModel)
1120
1160
  s.manualModel = true;
@@ -1213,9 +1253,9 @@ let OperatorService = class OperatorService {
1213
1253
  sessionId: ask.sessionId,
1214
1254
  taskId: '',
1215
1255
  stepId: 0,
1216
- description: ask.asked ? `Choose "${ask.asked}" in the Copilot window` : 'Choose the model in the Copilot window',
1256
+ description: `${ask.asked ? `Choose "${ask.asked}" in the Copilot window` : 'Choose the model in the Copilot window'}${ask.review ? ' for the review' : ask.role ? ` for the ${ask.role}` : ''}`,
1217
1257
  createdAt: new Date().toISOString(),
1218
- model: { asked: ask.asked, shown: ask.shown, why: ask.why, tries: ask.tries, ...(ask.manual ? { manual: true } : {}) },
1258
+ model: { asked: ask.asked, shown: ask.shown, why: ask.why, tries: ask.tries, ...(ask.manual ? { manual: true } : {}), ...(ask.review ? { review: true } : {}), ...(ask.role ? { role: ask.role } : {}) },
1219
1259
  };
1220
1260
  this.waiting.set(approval.id, {
1221
1261
  approval,
@@ -1225,6 +1265,49 @@ let OperatorService = class OperatorService {
1225
1265
  message: `choose "${ask.asked}" in the Copilot window, then answer on the card`, data: { approvalId: approval.id, model: approval.model } });
1226
1266
  });
1227
1267
  }
1268
+ /**
1269
+ * The lead's question for the operator (two chats, 2026-10-20): what only a person can decide, on a card in the
1270
+ * conversation, waiting in every mode — an unattended run included, since nobody else can answer it — until it is
1271
+ * answered or the task is stopped.
1272
+ */
1273
+ askLeadQuestion(ask, signal) {
1274
+ return new Promise((resolveAnswer) => {
1275
+ if (signal.aborted) {
1276
+ resolveAnswer('stop');
1277
+ return;
1278
+ }
1279
+ const approval = {
1280
+ id: newId('a-'),
1281
+ sessionId: ask.sessionId,
1282
+ taskId: ask.taskId,
1283
+ stepId: 0,
1284
+ description: `The lead asks: ${ask.question}`,
1285
+ createdAt: new Date().toISOString(),
1286
+ question: { text: ask.question, ...(ask.why ? { why: ask.why } : {}), options: ask.options },
1287
+ };
1288
+ this.waiting.set(approval.id, {
1289
+ approval,
1290
+ // A stop, the end of the run, "abort" on the card: the task stops at the question.
1291
+ resolve: () => resolveAnswer('stop'),
1292
+ resolveAnswer,
1293
+ });
1294
+ this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
1295
+ message: `the lead asks the operator: ${ask.question}`, data: { approvalId: approval.id, question: approval.question } });
1296
+ });
1297
+ }
1298
+ /** The operator's answer to the lead's question. */
1299
+ answerQuestion(approvalId, text) {
1300
+ const w = this.waiting.get(approvalId);
1301
+ if (!w?.resolveAnswer)
1302
+ return { ok: false, problem: 'No question of the lead is waiting under that id.' };
1303
+ if (!text.trim())
1304
+ return { ok: false, problem: 'Write the answer first.' };
1305
+ this.waiting.delete(approvalId);
1306
+ w.resolveAnswer({ answer: text.trim() });
1307
+ this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
1308
+ message: 'the operator answered the lead', data: { approvalId, question: true } });
1309
+ return { ok: true };
1310
+ }
1228
1311
  /**
1229
1312
  * A task's plan, put to the operator (plan mode `approve`, in a run that asks before each command): it
1230
1313
  * waits on the approvals card, on every page, until it is approved, sent back for another, or the task
@@ -1273,8 +1356,9 @@ let OperatorService = class OperatorService {
1273
1356
  message: `plan: ${action}${text ? ' (with a note)' : ''}`, data: { approvalId, action, plan: true } });
1274
1357
  return { ok: true };
1275
1358
  }
1359
+ /** What waits for the operator; of one session, its worker's included (two chats: they are asked in its conversation). */
1276
1360
  pendingApprovals(sessionId) {
1277
- return [...this.waiting.values()].map((w) => w.approval).filter((a) => !sessionId || a.sessionId === sessionId);
1361
+ return [...this.waiting.values()].map((w) => w.approval).filter((a) => !sessionId || a.sessionId === sessionId || this.workerLeads.get(a.sessionId) === sessionId);
1278
1362
  }
1279
1363
  /**
1280
1364
  * Answers one pending approval.
@@ -1290,7 +1374,7 @@ let OperatorService = class OperatorService {
1290
1374
  return { ok: false };
1291
1375
  this.waiting.delete(approvalId);
1292
1376
  if (action === 'run-all')
1293
- this.setRunMode(w.approval.sessionId, 'unattended');
1377
+ this.setRunMode(this.runKey(w.approval.sessionId), 'unattended');
1294
1378
  const decision = action === 'run' || action === 'run-all'
1295
1379
  ? { action: 'run' }
1296
1380
  : action === 'skip'
@@ -1344,10 +1428,10 @@ let OperatorService = class OperatorService {
1344
1428
  });
1345
1429
  if (mode === 'unattended') {
1346
1430
  for (const [id, w] of this.waiting) {
1347
- if (w.approval.sessionId !== sessionId)
1431
+ if (this.runKey(w.approval.sessionId) !== sessionId)
1348
1432
  continue;
1349
- // A fetch waits for its own answer: "run the rest without asking" is not an answer to it.
1350
- if (w.approval.network || w.approval.model)
1433
+ // A fetch waits for its own answer: "run the rest without asking" is not an answer to it; nor is a question.
1434
+ if (w.approval.network || w.approval.model || w.approval.question || w.approval.plan)
1351
1435
  continue;
1352
1436
  this.waiting.delete(id);
1353
1437
  w.resolve({ action: 'run' });
@@ -1370,7 +1454,7 @@ let OperatorService = class OperatorService {
1370
1454
  // This is checked per step rather than captured once, which is what makes the switch
1371
1455
  // take effect from the very next step instead of the next run. A held step is the
1372
1456
  // exception: it is asked about in an unattended run too, which is the point of holding it.
1373
- if (!held && this.running.get(ctx.sessionId ?? '')?.mode === 'unattended') {
1457
+ if (!held && this.running.get(this.runKey(ctx.sessionId ?? ''))?.mode === 'unattended') {
1374
1458
  resolvePromise({ action: 'run' });
1375
1459
  return;
1376
1460
  }
@@ -1653,54 +1737,6 @@ let OperatorService = class OperatorService {
1653
1737
  }
1654
1738
  return undefined;
1655
1739
  }
1656
- /** Throws unless the folder is a project in Settings or the repository of a session. */
1657
- async knownProjectFolder(dir, otherwise) {
1658
- const wanted = normaliseDir(dir);
1659
- const cfg = await this.settings.load();
1660
- const known = new Set([cfg.project?.rootDir ?? '', ...(cfg.project?.others ?? []).map((o) => o.rootDir), ...(await this.store.listSessions()).flatMap((s) => [s.vcs?.repoDir ?? '', s.projectDir ?? ''])]
1661
- .filter((d) => d.trim())
1662
- .map(normaliseDir));
1663
- if (!wanted || !known.has(wanted)) {
1664
- throw new Error(`That folder is not one of the projects in Settings or the repository of a session, so ${otherwise}.`);
1665
- }
1666
- }
1667
- /**
1668
- * "Prepare the folder from the remote main branch", first half: fetches and says what would be
1669
- * kept where and what the folder would be. See `vcs/prepareFromRemote.ts`.
1670
- */
1671
- async preparePreview(dir, fetch = true) {
1672
- await this.init();
1673
- await this.knownProjectFolder(dir, 'it is not prepared from here');
1674
- // The operator pressed the button and is looking: the remote may ask for a password through Git's own window.
1675
- return await planPrepare(resolve(dir.trim()), { fetch, askpass: fetch ? await askpassProgram() : null });
1676
- }
1677
- /**
1678
- * The second half: does it, if the folder is still what the preview showed. Refused while anything
1679
- * runs, or is being started, in that folder or one around it: it moves the checkout.
1680
- */
1681
- async prepareProject(dir, fingerprint, names = {}) {
1682
- await this.init();
1683
- await this.knownProjectFolder(dir, 'it is not prepared from here');
1684
- if (this.running.size > 0)
1685
- return { ok: false, problem: 'A run is going. Stop it before preparing the folder; nothing was changed.' };
1686
- if (this.browser?.kind === 'run')
1687
- return { ok: false, problem: 'A run is being started. Wait for it, or stop it, before preparing the folder; nothing was changed.' };
1688
- const other = await this.runningIn(dir);
1689
- if (other)
1690
- return { ok: false, problem: `Session "${other.name}" is running in this folder. Stop it before preparing the folder; nothing was changed.` };
1691
- const done = await prepareFromRemote(resolve(dir.trim()), String(fingerprint ?? ''), { names });
1692
- // Kept on every session working in that folder: it moved the checkout and made saved branches.
1693
- if (done.ok) {
1694
- const cfg = await this.settings.load();
1695
- const here = normaliseDir(dir);
1696
- for (const s of (await this.store.listSessions()).filter((x) => normaliseDir(repoDirOf(x)) === here)) {
1697
- const message = `the folder was prepared from ${done.target}: ${done.result}`;
1698
- await appendSessionLog(cfg.resolved.runsDir, s.id, { type: 'folder-prepared', message, data: { target: done.target, commit: done.commit, branch: done.branch, saved: done.saved, removedFromFolder: done.removedFromFolder } }).catch(() => undefined);
1699
- this.bus.publish({ sessionId: s.id, type: 'folder-prepared', level: 'info', message, data: { target: done.target, commit: done.commit, saved: done.saved } });
1700
- }
1701
- }
1702
- return done;
1703
- }
1704
1740
  // --- the project being worked on ---------------------------------------------------------
1705
1741
  /**
1706
1742
  * The folder new sessions start pointed at, and whether it can carry version control.
@@ -1711,18 +1747,25 @@ let OperatorService = class OperatorService {
1711
1747
  async project() {
1712
1748
  const cfg = await this.settings.load();
1713
1749
  const rootDir = (cfg.project?.rootDir ?? '').trim();
1714
- const problem = repoUnusableReason(rootDir);
1715
- const others = (cfg.project?.others ?? []).map((o) => {
1716
- const p = repoUnusableReason(o.rootDir);
1717
- return { name: o.name, rootDir: o.rootDir, repoOk: p === null, ...(p ? { repoProblem: p } : {}) };
1718
- });
1719
- return {
1720
- rootDir,
1721
- name: (cfg.project?.name ?? '').trim(),
1722
- repoOk: rootDir !== '' && problem === null,
1723
- ...(problem ? { repoProblem: problem } : {}),
1724
- others,
1750
+ /*
1751
+ * The branch each folder is on now (operator, 2026-10-20: "show which branch is chosen"), read from git each
1752
+ * time, since the operator switches it by hand and the chat works on whatever is checked out.
1753
+ */
1754
+ const entry = async (name, dir, level2) => {
1755
+ const problem = dir ? repoUnusableReason(dir) : 'no folder';
1756
+ const branch = dir && problem === null ? await git(dir, ['rev-parse', '--abbrev-ref', 'HEAD']).catch(() => null) : null;
1757
+ return {
1758
+ name,
1759
+ rootDir: dir,
1760
+ repoOk: dir !== '' && problem === null,
1761
+ ...(dir && problem ? { repoProblem: problem } : {}),
1762
+ ...(branch?.ok && branch.stdout ? { branch: branch.stdout } : {}),
1763
+ level2,
1764
+ };
1725
1765
  };
1766
+ const main = await entry((cfg.project?.name ?? '').trim(), rootDir, cfg.project?.level2 ?? '');
1767
+ const others = await Promise.all((cfg.project?.others ?? []).map((o) => entry(o.name, o.rootDir, o.level2 ?? '')));
1768
+ return { ...main, others };
1726
1769
  }
1727
1770
  /**
1728
1771
  * Stores the project folder and the other folders the operator works in. A field left out
@@ -1742,12 +1785,26 @@ let OperatorService = class OperatorService {
1742
1785
  const current = (raw.project ?? {});
1743
1786
  const rootDir = patch.rootDir !== undefined ? patch.rootDir.trim() : (current.rootDir ?? '').trim();
1744
1787
  const name = patch.name !== undefined ? patch.name.trim() : (current.name ?? '').trim();
1788
+ const level2 = patch.level2 !== undefined ? patch.level2 : (current.level2 ?? '');
1789
+ // Each goes into Kerrigan whole, and she is pasted into a chat: bounded, so one project cannot crowd out the rest.
1790
+ const tooLong = [{ name: name || rootDir, level2 }, ...(patch.others ?? [])].find((o) => (o.level2 ?? '').length > MAX_PROJECT_LEVEL2);
1791
+ if (tooLong)
1792
+ throw new Error(`The level 2 of "${tooLong.name}" is longer than ${MAX_PROJECT_LEVEL2.toLocaleString('en')} characters; keep it to what a chat needs to know about the project.`);
1745
1793
  if (rootDir && !existsSync(rootDir))
1746
1794
  throw new Error(`The folder ${rootDir} does not exist on this machine.`);
1747
- const others = (patch.others ?? current.others ?? []).map((o) => ({
1748
- name: (o.name ?? '').trim(),
1749
- rootDir: (o.rootDir ?? '').trim(),
1750
- }));
1795
+ /*
1796
+ * A project's level 2 is kept with it when the list comes without one — renamed or moved, or saved by a page that
1797
+ * does not know the field — matched by its folder, then by its name.
1798
+ */
1799
+ const before = current.others ?? [];
1800
+ const others = (patch.others ?? before).map((o) => {
1801
+ const was = before.find((b) => sameFolder(b.rootDir ?? '', o.rootDir ?? '')) ?? before.find((b) => (b.name ?? '').trim() === (o.name ?? '').trim());
1802
+ return {
1803
+ name: (o.name ?? '').trim(),
1804
+ rootDir: (o.rootDir ?? '').trim(),
1805
+ level2: o.level2 !== undefined ? o.level2 : (was?.level2 ?? ''),
1806
+ };
1807
+ });
1751
1808
  const seen = new Set();
1752
1809
  for (const o of others) {
1753
1810
  if (!o.name)
@@ -1765,7 +1822,7 @@ let OperatorService = class OperatorService {
1765
1822
  }
1766
1823
  // What the removed Desktop copies left in the stored project is dropped with the next save.
1767
1824
  const { mirror: _m, desktop: _d, mirrorToDesktop: _t, ...rest } = current;
1768
- return { ...raw, project: { ...rest, rootDir, name, others } };
1825
+ return { ...raw, project: { ...rest, rootDir, name, level2, others } };
1769
1826
  });
1770
1827
  return await this.project();
1771
1828
  }
@@ -308,6 +308,12 @@ export const RunConfigSchema = z.object({
308
308
  * default one had nowhere to put it.
309
309
  */
310
310
  name: z.string().trim().default(''),
311
+ /**
312
+ * Level 2 of this project (operator, 2026-10-20: "a level 2 template for each project"): what the operator
313
+ * writes about it — its stack, its conventions, how its tests run, what not to touch. It goes into Kerrigan,
314
+ * saved or copied, so the chat she helps in knows the project; the bot sends it nowhere by itself.
315
+ */
316
+ level2: z.string().default(''),
311
317
  /**
312
318
  * The other folders this operator works in, each with a short name: a front end, a back
313
319
  * end, the test suite. They are not defaults — a new session still starts on `rootDir` —
@@ -320,6 +326,8 @@ export const RunConfigSchema = z.object({
320
326
  .array(z.object({
321
327
  name: z.string().trim().min(1),
322
328
  rootDir: z.string().trim().min(1),
329
+ /** Its level 2, as the default project's `level2`. */
330
+ level2: z.string().default(''),
323
331
  }))
324
332
  .default([]),
325
333
  })
@@ -411,6 +419,11 @@ export const RunConfigSchema = z.object({
411
419
  * Zero turns it off.
412
420
  */
413
421
  autoContinue: z.number().int().min(0).max(20).default(3),
422
+ /*
423
+ * The most subtasks the lead of a two-chat conversation may give its worker for one message (2026-10-20). Each
424
+ * subtask is a task of the worker's, with the limits above; this bounds the whole. Settings → Execution.
425
+ */
426
+ maxSubtasks: z.number().int().min(1).max(100).default(20),
414
427
  /*
415
428
  * How many genuinely different approaches the chat must have tried before it may end a task
416
429
  * "blocked". The reply format's own floor is 2 (replySchema.ts); this raises it. A "blocked"