copilot-operator 0.1.84 → 0.1.85

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 (60) hide show
  1. package/dist/src/api/operator.controller.js +90 -0
  2. package/dist/src/api/operator.service.js +270 -30
  3. package/dist/src/config/schema.js +17 -0
  4. package/dist/src/orchestrator/cardText.js +91 -0
  5. package/dist/src/orchestrator/kerriganRunner.js +912 -0
  6. package/dist/src/orchestrator/leadRunner.js +22 -14
  7. package/dist/src/orchestrator/planMode.js +6 -4
  8. package/dist/src/orchestrator/taskRunner.js +42 -14
  9. package/dist/src/plan/kerrigan.js +109 -4
  10. package/dist/src/plan/systemGuide.js +194 -2
  11. package/dist/src/protocol/kerriganSchema.js +175 -0
  12. package/dist/src/session/store.js +9 -0
  13. package/dist/src/vcs/git.js +72 -2
  14. package/dist/src/vcs/operatorGit.js +409 -0
  15. package/dist/web/404.html +2 -2
  16. package/dist/web/_next/static/chunks/1077.06fe73b2c16f8f49.js +1 -0
  17. package/dist/web/_next/static/chunks/1548.b38c5d8d00ab2a72.js +1 -0
  18. package/dist/web/_next/static/chunks/{2163.2af0979126ae613a.js → 2163.ba933c9a506302ca.js} +1 -1
  19. package/dist/web/_next/static/chunks/714.575273a189d030fe.js +1 -0
  20. package/dist/web/_next/static/chunks/7220.988dfd28e00f407c.js +1 -0
  21. package/dist/web/_next/static/chunks/7921-65dd56d87144bd44.js +1 -0
  22. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +1 -0
  23. package/dist/web/_next/static/chunks/8584.2221587201bc2fa2.js +1 -0
  24. package/dist/web/_next/static/chunks/9067.8d94a08830c3d1da.js +1 -0
  25. package/dist/web/_next/static/chunks/9747.8671194406acd839.js +1 -0
  26. package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +1 -0
  27. package/dist/web/_next/static/chunks/app/page-76139370c7ca3715.js +1 -0
  28. package/dist/web/_next/static/chunks/app/settings/page-116da78c83f0c5c9.js +1 -0
  29. package/dist/web/_next/static/chunks/webpack-13ccb80d7b7094ca.js +1 -0
  30. package/dist/web/_next/static/css/6e2b8656501f0dd7.css +1 -0
  31. package/dist/web/defaults.html +2 -2
  32. package/dist/web/defaults.txt +8 -8
  33. package/dist/web/index.html +3 -3
  34. package/dist/web/index.txt +9 -9
  35. package/dist/web/queue.html +2 -2
  36. package/dist/web/queue.txt +9 -9
  37. package/dist/web/settings.html +2 -2
  38. package/dist/web/settings.txt +9 -9
  39. package/dist/web/system.html +2 -2
  40. package/dist/web/system.txt +9 -9
  41. package/package.json +175 -173
  42. package/prompts/kerrigan1.md +169 -0
  43. package/prompts/lead1.md +4 -1
  44. package/prompts/level1.md +8 -1
  45. package/dist/web/_next/static/chunks/1077.e0136d293069ccb8.js +0 -1
  46. package/dist/web/_next/static/chunks/1548.5cc0c57b00c2e44f.js +0 -1
  47. package/dist/web/_next/static/chunks/714.410e2b61aa8c72b7.js +0 -1
  48. package/dist/web/_next/static/chunks/7220.2c4e5173a060769f.js +0 -1
  49. package/dist/web/_next/static/chunks/7921-3d21f385338afdf9.js +0 -1
  50. package/dist/web/_next/static/chunks/8124-1dc34be1646970a8.js +0 -1
  51. package/dist/web/_next/static/chunks/8584.61650a59d2bfa54d.js +0 -1
  52. package/dist/web/_next/static/chunks/9067.553056fc9b6cf80e.js +0 -1
  53. package/dist/web/_next/static/chunks/9747.d5826524bf4b714d.js +0 -1
  54. package/dist/web/_next/static/chunks/app/layout-b8a1e0075a48b025.js +0 -1
  55. package/dist/web/_next/static/chunks/app/page-13147b69cf336831.js +0 -1
  56. package/dist/web/_next/static/chunks/app/settings/page-e3909ef6c2d8e321.js +0 -1
  57. package/dist/web/_next/static/chunks/webpack-19a2d7161f23b21d.js +0 -1
  58. package/dist/web/_next/static/css/f152f27d6afce55c.css +0 -1
  59. /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → aCQe1FDhYTj4zGeI5ueVq}/_buildManifest.js +0 -0
  60. /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → aCQe1FDhYTj4zGeI5ueVq}/_ssgManifest.js +0 -0
@@ -36,6 +36,15 @@ function fail(e) {
36
36
  throw e;
37
37
  throw new BadRequestException(e.message);
38
38
  }
39
+ /** The files a stage or unstage names: `all`, or a list of paths as the Git view lists them. */
40
+ function stagedWhich(body) {
41
+ if (body?.all === true)
42
+ return 'all';
43
+ if (!Array.isArray(body?.paths) || body.paths.length === 0 || !body.paths.every((p) => typeof p === 'string' && p.length > 0 && p.length < 4096)) {
44
+ throw new BadRequestException('paths must be a list of the files to stage or unstage, or all: true');
45
+ }
46
+ return body.paths.slice(0, 5000);
47
+ }
39
48
  /**
40
49
  * `fail` for a route that writes its own response, as the downloads do: the request's own problem
41
50
  * as plain text with a 400, and a settings file or a policy lock that cannot be used passed on to
@@ -304,6 +313,36 @@ let OperatorController = class OperatorController {
304
313
  workspaceGitCounts(base) {
305
314
  return this.ops.workspaceGitCounts(base || undefined).catch(fail);
306
315
  }
316
+ /**
317
+ * The operator's own git from the Git view (2026-11-11, see `vcs/operatorGit.ts`): files of its lists staged or
318
+ * unstaged (`paths`, or `all`); a commit (`message`, `all` to commit everything) and a push, each started and then
319
+ * followed through `workspace/git/op`; `hooks: 'skip'` runs neither without the project's hooks, `trust` runs the ones
320
+ * named (path and hash, as the view showed them) although they are not the project's own. Refused while a task, the
321
+ * queue or another commit or push is at work in the folder.
322
+ */
323
+ gitStage(body = {}) {
324
+ return this.ops.gitStage('stage', stagedWhich(body)).catch(fail);
325
+ }
326
+ gitUnstage(body = {}) {
327
+ return this.ops.gitStage('unstage', stagedWhich(body)).catch(fail);
328
+ }
329
+ gitCommit(body = {}) {
330
+ return this.ops.gitCommit(body ?? {}).catch(fail);
331
+ }
332
+ gitPush(body = {}) {
333
+ return this.ops.gitPush(body ?? {}).catch(fail);
334
+ }
335
+ /** The commit or push running now, or the last one: `{ op: null }` before the first. */
336
+ gitOp() {
337
+ return { op: this.ops.gitOpState() };
338
+ }
339
+ /** The operator's name and e-mail as git has them; and set, here (`global` false) or for every repository. */
340
+ gitIdentity() {
341
+ return this.ops.gitIdentity().catch(fail);
342
+ }
343
+ setGitIdentity(body = {}) {
344
+ return this.ops.setGitIdentity(body ?? {}).catch(fail);
345
+ }
307
346
  workspaceCommit(sha) {
308
347
  if (!sha)
309
348
  throw new BadRequestException('sha is required');
@@ -345,6 +384,10 @@ let OperatorController = class OperatorController {
345
384
  ...(body.workerManualModel === true ? { workerManualModel: true } : {}),
346
385
  // The skill chosen for this message (2026-10-21), by its name.
347
386
  ...(typeof body.skill === 'string' && body.skill.trim() ? { skill: body.skill } : {}),
387
+ // Kerrigan directs, for a new conversation (2026-11-12): the model of the chats she sends to, as chosen beside hers.
388
+ ...(body.kerrigan === true ? { kerrigan: true } : {}),
389
+ ...(typeof body.chatModel === 'string' && body.chatModel.trim() ? { chatModel: body.chatModel } : {}),
390
+ ...(body.chatManualModel === true ? { chatManualModel: true } : {}),
348
391
  })
349
392
  .catch(fail);
350
393
  }
@@ -753,6 +796,53 @@ __decorate([
753
796
  __metadata("design:paramtypes", [String]),
754
797
  __metadata("design:returntype", Promise)
755
798
  ], OperatorController.prototype, "workspaceGitCounts", null);
799
+ __decorate([
800
+ Post('workspace/git/stage'),
801
+ __param(0, Body()),
802
+ __metadata("design:type", Function),
803
+ __metadata("design:paramtypes", [Object]),
804
+ __metadata("design:returntype", Promise)
805
+ ], OperatorController.prototype, "gitStage", null);
806
+ __decorate([
807
+ Post('workspace/git/unstage'),
808
+ __param(0, Body()),
809
+ __metadata("design:type", Function),
810
+ __metadata("design:paramtypes", [Object]),
811
+ __metadata("design:returntype", Promise)
812
+ ], OperatorController.prototype, "gitUnstage", null);
813
+ __decorate([
814
+ Post('workspace/git/commit'),
815
+ __param(0, Body()),
816
+ __metadata("design:type", Function),
817
+ __metadata("design:paramtypes", [Object]),
818
+ __metadata("design:returntype", Promise)
819
+ ], OperatorController.prototype, "gitCommit", null);
820
+ __decorate([
821
+ Post('workspace/git/push'),
822
+ __param(0, Body()),
823
+ __metadata("design:type", Function),
824
+ __metadata("design:paramtypes", [Object]),
825
+ __metadata("design:returntype", Promise)
826
+ ], OperatorController.prototype, "gitPush", null);
827
+ __decorate([
828
+ Get('workspace/git/op'),
829
+ __metadata("design:type", Function),
830
+ __metadata("design:paramtypes", []),
831
+ __metadata("design:returntype", Object)
832
+ ], OperatorController.prototype, "gitOp", null);
833
+ __decorate([
834
+ Get('workspace/git/identity'),
835
+ __metadata("design:type", Function),
836
+ __metadata("design:paramtypes", []),
837
+ __metadata("design:returntype", Promise)
838
+ ], OperatorController.prototype, "gitIdentity", null);
839
+ __decorate([
840
+ Put('workspace/git/identity'),
841
+ __param(0, Body()),
842
+ __metadata("design:type", Function),
843
+ __metadata("design:paramtypes", [Object]),
844
+ __metadata("design:returntype", Promise)
845
+ ], OperatorController.prototype, "setGitIdentity", null);
756
846
  __decorate([
757
847
  Get('workspace/git/commit'),
758
848
  __param(0, Query('sha')),
@@ -33,7 +33,7 @@ import { suggestRunName } from '../session/runName.js';
33
33
  import { buildStory } from '../session/story.js';
34
34
  import { buildTaskExchange } from '../session/taskExchange.js';
35
35
  import { chatNotice } from '../session/chatNotice.js';
36
- import { kerriganFileName, kerriganPersona } from '../plan/kerrigan.js';
36
+ import { kerriganBrief, kerriganFileName, kerriganPersona } from '../plan/kerrigan.js';
37
37
  import { branchChanges, gitCounts, workspaceCommit, workspaceGit, workspaceGitVersions } from '../session/workspaceGit.js';
38
38
  import { chatCode } from '../transport/chatSession.js';
39
39
  /** The folders the operator works in: the default new sessions start on, and the rest by name. */
@@ -45,6 +45,8 @@ export const MAX_SESSION_NAME = 120;
45
45
  * beginning goes as text and the whole of it attached.
46
46
  */
47
47
  export const MAX_SKILL_DESCRIPTION = 300;
48
+ /** What a skill says for Kerrigan is short (2026-11-12): its phases, its result, what it needs. */
49
+ export const MAX_SKILL_FOR_KERRIGAN = 3000;
48
50
  export const MAX_SKILLS = 50;
49
51
  /** What follows `/` at the start of a message: lowercase letters, digits and hyphens, 2 to 40 of them. */
50
52
  export const SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,38}[a-z0-9]$/;
@@ -90,6 +92,7 @@ import { dirtyPolicy } from '../vcs/snapshot.js';
90
92
  import { runVcsPreflight } from '../vcs/runPreflight.js';
91
93
  import { inputSettings, normalisePatterns } from '../vcs/inputs.js';
92
94
  import { createNewBranch, planNewBranch } from '../vcs/newBranch.js';
95
+ import { commitAsOperator, identityOf, pushAsOperator, setIdentity, stageFiles, TrustedHooks } from '../vcs/operatorGit.js';
93
96
  import { askpassProgram, closePasswordWindows } from '../vcs/remoteAuth.js';
94
97
  import { planApprovedMessage, planReviseMessage } from '../orchestrator/planMode.js';
95
98
  import { coveredByArtifacts } from '../vcs/artifacts.js';
@@ -118,6 +121,18 @@ function stepRules(cfg) {
118
121
  writtenScripts: cfg.execution.writtenScripts,
119
122
  };
120
123
  }
124
+ /** The languages of the page, by their names in English: the language Kerrigan writes to the person in (2026-11-12). */
125
+ const LANGUAGE_NAMES = {
126
+ en: 'English',
127
+ bg: 'Bulgarian',
128
+ de: 'German',
129
+ es: 'Spanish',
130
+ fr: 'French',
131
+ ja: 'Japanese',
132
+ ko: 'Korean',
133
+ pt: 'Portuguese',
134
+ ar: 'Arabic',
135
+ };
121
136
  const INACTIVE_REASON = 'the session is inactive; make it active on the Sessions page to run it';
122
137
  /**
123
138
  * Why the browser cannot be had now, said in terms of what was pressed. The sentences a start, a
@@ -147,6 +162,16 @@ function browserRefusal(held, ask) {
147
162
  ? 'already running'
148
163
  : 'another conversation is running, and the browser takes one run at a time; start this one once it has finished';
149
164
  }
165
+ /** What the Git view said about the project's hooks: none of them (`skip`), or these run although flagged, each as shown then. */
166
+ function hookChoiceOf(input) {
167
+ const trust = Array.isArray(input.trust)
168
+ ? input.trust
169
+ .filter((t) => !!t && typeof t.path === 'string' && typeof t.sha === 'string')
170
+ .slice(0, 100)
171
+ .map((t) => ({ path: t.path, sha: t.sha }))
172
+ : [];
173
+ return { hooks: input.hooks === 'skip' ? 'skip' : 'auto', ...(trust.length > 0 ? { trust } : {}) };
174
+ }
150
175
  /** A folder as compared: absolute, forward slashes, no trailing slash, and case folded as Windows does. */
151
176
  function normaliseDir(dir) {
152
177
  if (!dir.trim())
@@ -236,13 +261,35 @@ let OperatorService = class OperatorService {
236
261
  return this.running.get(this.runKey(sessionId))?.hold;
237
262
  }
238
263
  /**
239
- * 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
240
- * carry its own session's id, while the run, its mode and its Stop are the lead's: they are looked up through this.
264
+ * The workers of the two-chat mode, by the session of the lead they work for (2026-10-20); and since 2026-11-12 the
265
+ * chats Kerrigan directs, by her conversation's session, and their workers by their chat. A worker's steps and cards
266
+ * carry its own session's id, while the run, its mode and its Stop are the lead's — or Kerrigan's: they are looked up
267
+ * through this, up the chain.
241
268
  */
242
269
  workerLeads = new Map();
243
- /** The session whose run a session's steps belong to: its own, or its lead's for a worker. */
270
+ /** The session whose run a session's steps belong to: its own, or the one up its chain whose run it is. */
244
271
  runKey(sessionId) {
245
- return this.running.has(sessionId) ? sessionId : (this.workerLeads.get(sessionId) ?? sessionId);
272
+ let key = sessionId;
273
+ for (let i = 0; i < 4 && !this.running.has(key); i++) {
274
+ const up = this.workerLeads.get(key);
275
+ if (!up)
276
+ break;
277
+ key = up;
278
+ }
279
+ return this.running.has(key) ? key : sessionId;
280
+ }
281
+ /** Whether a session is this one or below it: its worker, a chat Kerrigan directs, that chat's worker. */
282
+ under(sessionId, top) {
283
+ let key = sessionId;
284
+ for (let i = 0; i < 4; i++) {
285
+ if (key === top)
286
+ return true;
287
+ const up = this.workerLeads.get(key);
288
+ if (!up)
289
+ return false;
290
+ key = up;
291
+ }
292
+ return false;
246
293
  }
247
294
  ready = null;
248
295
  /**
@@ -406,6 +453,12 @@ let OperatorService = class OperatorService {
406
453
  const model = patch.workerModel !== undefined ? patch.workerModel.trim() : (s.lead.workerModel ?? '');
407
454
  s.lead = { ...s.lead, workerManualModel: manual || undefined, workerModel: manual ? undefined : model || undefined };
408
455
  }
456
+ // Kerrigan's (2026-11-12): the same fields are the model of the chats she sends to — the ones she makes from now on.
457
+ if (s.kerrigan && (patch.workerModel !== undefined || typeof patch.workerManualModel === 'boolean')) {
458
+ const manual = typeof patch.workerManualModel === 'boolean' ? patch.workerManualModel : !!s.kerrigan.chatManualModel;
459
+ const model = patch.workerModel !== undefined ? patch.workerModel.trim() : (s.kerrigan.chatModel ?? '');
460
+ s.kerrigan = { ...(manual ? { chatManualModel: true } : {}), ...(!manual && model ? { chatModel: model } : {}) };
461
+ }
409
462
  // The same for the group: clearing it gives this session its conversation back. It does
410
463
  // not move the conversation it is already in; that history is where it is.
411
464
  if (patch.conversationGroup !== undefined)
@@ -873,6 +926,10 @@ let OperatorService = class OperatorService {
873
926
  const idle = { ran: 0, failed: 0, leftQueued: 0, failedTitles: [] };
874
927
  if (this.running.has(sessionId))
875
928
  return { started: false, reason: 'already running', done: Promise.resolve(idle) };
929
+ // The operator's own commit or push still running in the folder: a run's git would go under it (2026-11-11).
930
+ const gitBusy = this.gitOpBusy();
931
+ if (gitBusy)
932
+ return { started: false, reason: gitBusy, done: Promise.resolve(idle) };
876
933
  const session = await this.store.getSession(sessionId);
877
934
  if (!session)
878
935
  return { started: false, reason: 'no such session', done: Promise.resolve(idle) };
@@ -923,6 +980,16 @@ let OperatorService = class OperatorService {
923
980
  const asLead = await this.store.getSession(sessionId);
924
981
  if (asLead?.lead?.workerSessionId)
925
982
  this.workerLeads.set(asLead.lead.workerSessionId, sessionId);
983
+ // Kerrigan's (2026-11-12): the chats she directs, and their workers, are hers to speak for from the start.
984
+ if (asLead?.kerrigan) {
985
+ for (const s of await this.store.listSessions()) {
986
+ if (s.directedBy !== sessionId)
987
+ continue;
988
+ this.workerLeads.set(s.id, sessionId);
989
+ if (s.lead?.workerSessionId)
990
+ this.workerLeads.set(s.lead.workerSessionId, s.id);
991
+ }
992
+ }
926
993
  }
927
994
  this.bus.publish({ sessionId, type: 'run-requested', level: 'info', message: `starting in ${mode} mode` });
928
995
  // Said at the start of every run, in both modes, because it is the one fact about this tool a
@@ -996,7 +1063,15 @@ let OperatorService = class OperatorService {
996
1063
  // The two-chat mode (2026-10-20): the lead's questions, and the worker the run speaks for too.
997
1064
  askQuestion: (ask) => this.askLeadQuestion(ask, controller.signal),
998
1065
  askSubtaskRetry: (ask) => this.askSubtaskRetry(ask, controller.signal),
999
- onWorker: (workerId) => this.workerLeads.set(workerId, sessionId),
1066
+ onWorker: (workerId, parent) => this.workerLeads.set(workerId, parent ?? sessionId),
1067
+ // A conversation Kerrigan directs (2026-11-12): the facts she is told, and the skills she sends with.
1068
+ kerrigan: {
1069
+ brief: async () => await this.kerriganBriefText((await this.store.getSession(sessionId))?.lang ?? session.lang, sessionId),
1070
+ skill: async (name, dir) => {
1071
+ const found = await this.skillFor(name, dir).catch(() => null);
1072
+ return found ? { name: found.name, description: found.description, text: found.text } : null;
1073
+ },
1074
+ },
1000
1075
  hold,
1001
1076
  })
1002
1077
  .then(async (outcome) => {
@@ -1067,7 +1142,9 @@ let OperatorService = class OperatorService {
1067
1142
  * "Pause" on the chat (operator, 2026-10-20): the running work holds at its next message to Copilot or its next
1068
1143
  * command, and the button becomes "Continue". A reply being written and a command running are let finish.
1069
1144
  */
1070
- pause(sessionId) {
1145
+ pause(asked) {
1146
+ // A chat Kerrigan directs is paused with her run (2026-11-12).
1147
+ const sessionId = this.runKey(asked);
1071
1148
  const r = this.running.get(sessionId);
1072
1149
  if (!r)
1073
1150
  throw new Error('Nothing of this conversation is running, so there is nothing to pause.');
@@ -1077,13 +1154,16 @@ let OperatorService = class OperatorService {
1077
1154
  return { paused: true };
1078
1155
  }
1079
1156
  /** "Continue": the paused work goes on from where it held. A run that has ended meanwhile has nothing to go on with. */
1080
- resume(sessionId) {
1157
+ resume(asked) {
1158
+ const sessionId = this.runKey(asked);
1081
1159
  const r = this.running.get(sessionId);
1082
1160
  if (r?.hold.resume())
1083
1161
  this.bus.publish({ sessionId, type: 'resume-asked', level: 'info', message: 'continued by the operator' });
1084
1162
  return { paused: false };
1085
1163
  }
1086
- async stop(sessionId) {
1164
+ async stop(asked) {
1165
+ // A chat Kerrigan directs is stopped with her run (2026-11-12): it is one run.
1166
+ const sessionId = this.runKey(asked);
1087
1167
  const r = this.running.get(sessionId);
1088
1168
  if (!r)
1089
1169
  return { stopping: false };
@@ -1172,13 +1252,90 @@ let OperatorService = class OperatorService {
1172
1252
  return await workspaceInfo(cfg.project?.rootDir ?? '', cfg.project?.name ?? '');
1173
1253
  }
1174
1254
  // --- a new branch from main, from the chat (2026-10-26) --------------------------------------------------------
1175
- /** Why the folder's branch may not be changed now: a task at work, or the queue between its tasks. */
1255
+ /** Why the folder's branch may not be changed now: a task at work, the queue between its tasks, or the operator's own commit or push. */
1176
1256
  branchBusy() {
1177
1257
  if (this.running.size > 0 || this.browser?.kind === 'run')
1178
1258
  return 'A task is working: stop it or let it finish first; the branch is not changed under it.';
1179
1259
  if (this.queueLoop)
1180
1260
  return 'The queue is running: stop it first; the branch is not changed under its tasks.';
1181
- return null;
1261
+ return this.gitOpBusy();
1262
+ }
1263
+ // --- the operator's own commit and push, from the Git view (2026-11-11, see `vcs/operatorGit.ts`) ------------------
1264
+ /** The commit or push of the operator's that runs now, or ran last: what the Git view follows. One at a time. */
1265
+ gitOp = null;
1266
+ /** Hook files the operator said to run although they were not the project's own, each as it was then. */
1267
+ trustedHooks = new TrustedHooks(join(this.dataDir, 'trusted-hooks.json'));
1268
+ /** Why nothing else may change the folder's git now: the operator's commit or push still running. */
1269
+ gitOpBusy() {
1270
+ if (this.gitOp?.state !== 'running')
1271
+ return null;
1272
+ return this.gitOp.kind === 'commit'
1273
+ ? 'Git is committing in the project folder (the Git view follows it): let it finish first.'
1274
+ : 'Git is pushing from the project folder (the Git view follows it): let it finish first.';
1275
+ }
1276
+ /** The folder the Git view acts in, when nothing else is changing its git; else why not. */
1277
+ async gitFolder() {
1278
+ const ws = await this.workspace();
1279
+ if (!ws.ok)
1280
+ throw new Error(ws.problem ?? 'No project folder is open: open one first.');
1281
+ const busy = this.branchBusy();
1282
+ if (busy)
1283
+ throw new Error(busy);
1284
+ return ws.dir;
1285
+ }
1286
+ /** The commit or push running now, or the last one. */
1287
+ gitOpState() {
1288
+ return this.gitOp;
1289
+ }
1290
+ /** Files of the Git view's lists staged or unstaged; the folder's git as it is then. */
1291
+ async gitStage(how, which) {
1292
+ const dir = await this.gitFolder();
1293
+ await stageFiles(dir, how, which);
1294
+ return await workspaceGit(dir);
1295
+ }
1296
+ /** Starts a commit or a push and answers at once with it; the Git view reads it again while it runs (`gitOpState`). */
1297
+ startGitOp(kind, dir, run, extra = {}) {
1298
+ const op = { id: newId('g-'), kind, state: 'running', startedAt: new Date().toISOString(), command: kind === 'commit' ? 'git commit' : 'git push', output: '', hooks: 'none', ...extra };
1299
+ this.gitOp = op;
1300
+ const update = (patch) => {
1301
+ // A later one replaces this one only once this one has ended, so nothing is written into another's record.
1302
+ if (this.gitOp?.id === op.id)
1303
+ Object.assign(op, patch);
1304
+ };
1305
+ void run(update)
1306
+ .catch((e) => update({ state: 'failed', cause: 'unknown', output: `${op.output}${op.output ? '\n' : ''}${e.message}\n`, endedAt: new Date().toISOString() }))
1307
+ .finally(() => {
1308
+ if (op.state === 'running')
1309
+ update({ state: 'failed', cause: 'unknown', endedAt: new Date().toISOString() });
1310
+ console.log(`[git] ${op.kind} in ${dir}: ${op.state}${op.cause ? ` (${op.cause})` : ''}${op.commit ? ` ${op.commit.slice(0, 8)}` : ''}${op.target ? ` → ${op.target}` : ''}`);
1311
+ });
1312
+ return op;
1313
+ }
1314
+ /** The operator's commit of what is staged, or of everything (`all`), with the project's hooks as `hooks`/`trust` say. */
1315
+ async gitCommit(input) {
1316
+ const dir = await this.gitFolder();
1317
+ const message = typeof input.message === 'string' ? input.message.slice(0, 20_000) : '';
1318
+ const all = input.all === true;
1319
+ const choice = hookChoiceOf(input);
1320
+ return this.startGitOp('commit', dir, (update) => commitAsOperator(dir, { message, all, ...choice }, this.trustedHooks, update), { message, all });
1321
+ }
1322
+ /** The operator's push of the branch the folder is on, to its upstream or published (see `pushAsOperator`). */
1323
+ async gitPush(input) {
1324
+ const dir = await this.gitFolder();
1325
+ return this.startGitOp('push', dir, (update) => pushAsOperator(dir, hookChoiceOf(input), this.trustedHooks, update));
1326
+ }
1327
+ /** The operator's name and e-mail as git has them for the open folder's repository. */
1328
+ async gitIdentity() {
1329
+ const ws = await this.workspace();
1330
+ if (!ws.ok)
1331
+ throw new Error(ws.problem ?? 'No project folder is open.');
1332
+ return await identityOf(ws.dir);
1333
+ }
1334
+ /** The operator's name and e-mail set for git, in this repository or for all of theirs: what a first commit asks for. */
1335
+ async setGitIdentity(input) {
1336
+ const dir = await this.gitFolder();
1337
+ await setIdentity(dir, { name: typeof input.name === 'string' ? input.name : '', email: typeof input.email === 'string' ? input.email : '', global: input.global === true });
1338
+ return await identityOf(dir);
1182
1339
  }
1183
1340
  /**
1184
1341
  * What a new branch from main would start from (see `vcs/newBranch.ts`). With `fetch`, the remote's main is fetched
@@ -1286,6 +1443,22 @@ let OperatorService = class OperatorService {
1286
1443
  * language she is not written out in, the page fills in the names of the controls (`filled: false`).
1287
1444
  */
1288
1445
  async kerrigan(lang, skill) {
1446
+ const { facts, chosen } = await this.kerriganFacts(skill);
1447
+ const text = kerriganPersona(lang, facts);
1448
+ return { lang, fileName: kerriganFileName(lang, chosen?.name), text, filled: lang === 'en' || lang === 'bg' };
1449
+ }
1450
+ /**
1451
+ * The facts of this machine for Kerrigan when she directs a conversation herself (2026-11-12): the same as her text's,
1452
+ * with the person's language, how many messages she may send to chats, and how the chats' commands run in this run.
1453
+ */
1454
+ async kerriganBriefText(lang, sessionId) {
1455
+ const cfg = await this.settings.load();
1456
+ const { facts } = await this.kerriganFacts();
1457
+ const mode = this.running.get(this.runKey(sessionId))?.mode ?? cfg.execution.mode;
1458
+ return kerriganBrief({ ...facts, language: LANGUAGE_NAMES[lang ?? 'en'] ?? 'English', maxSends: cfg.limits.maxKerriganSends ?? 6, commands: mode === 'unattended' ? 'auto' : 'ask' });
1459
+ }
1460
+ /** What Kerrigan is told of this machine: its limits, the projects with their notes, the skills; a skill chosen, too. */
1461
+ async kerriganFacts(skill) {
1289
1462
  const cfg = await this.settings.load();
1290
1463
  const p = await this.project();
1291
1464
  const projects = [
@@ -1295,13 +1468,13 @@ let OperatorService = class OperatorService {
1295
1468
  // The skills, each with the name of the project it is for.
1296
1469
  const nameOf = (dir) => [{ name: p.name || p.rootDir, rootDir: p.rootDir }, ...p.others].find((x) => x.rootDir && sameFolder(x.rootDir, dir))?.name ?? dir;
1297
1470
  const all = (await this.skills()).skills;
1298
- const skills = all.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}) }));
1471
+ const skills = all.map((k) => ({ name: k.name, description: k.description, ...(k.projectDir ? { project: nameOf(k.projectDir) } : {}), forKerrigan: k.forKerrigan, text: k.text }));
1299
1472
  // The skill chosen beside her button (2026-10-26): its instructions go with her text.
1300
1473
  const asked = skill?.trim().replace(/^\//, '').toLowerCase();
1301
1474
  const chosen = asked ? all.find((k) => k.name === asked) : undefined;
1302
1475
  if (asked && !chosen)
1303
1476
  throw new Error(`There is no skill called "${asked}" in Settings → Skills.`);
1304
- const text = kerriganPersona(lang, {
1477
+ const facts = {
1305
1478
  version: botVersion(),
1306
1479
  skills,
1307
1480
  maxIterations: cfg.limits.maxIterations,
@@ -1311,8 +1484,8 @@ let OperatorService = class OperatorService {
1311
1484
  maxSubtasks: cfg.limits.maxSubtasks ?? 20,
1312
1485
  projects,
1313
1486
  ...(chosen ? { chosenSkill: { name: chosen.name, description: chosen.description, text: chosen.text, ...(chosen.projectDir ? { project: nameOf(chosen.projectDir) } : {}) } } : {}),
1314
- });
1315
- return { lang, fileName: kerriganFileName(lang, chosen?.name), text, filled: lang === 'en' || lang === 'bg' };
1487
+ };
1488
+ return { facts, ...(chosen ? { chosen } : {}) };
1316
1489
  }
1317
1490
  /** The chat's conversations, newest first. */
1318
1491
  async chatThreads() {
@@ -1321,7 +1494,18 @@ let OperatorService = class OperatorService {
1321
1494
  // A worker's session (two chats) is not a conversation of the list: it is shown under its lead's messages.
1322
1495
  .filter((s) => s.kind === 'chat' && !s.workerOf)
1323
1496
  .sort((a, b) => b.createdAt.localeCompare(a.createdAt))
1324
- .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 }));
1497
+ .map((s) => ({
1498
+ id: s.id,
1499
+ name: s.name,
1500
+ createdAt: s.createdAt,
1501
+ status: s.status,
1502
+ turns: s.tasks.length,
1503
+ // A chat Kerrigan directs runs in her run (2026-11-12): running while a message of its is at work in it.
1504
+ running: this.running.has(s.id) || (!!s.directedBy && this.running.has(this.runKey(s.id)) && s.tasks.some((t) => t.status === 'running' || t.status === 'waiting-approval')),
1505
+ repoDir: s.vcs?.repoDir || s.projectDir,
1506
+ ...(s.kerrigan ? { kerrigan: true } : {}),
1507
+ ...(s.directedBy ? { directedBy: s.directedBy } : {}),
1508
+ }));
1325
1509
  }
1326
1510
  /**
1327
1511
  * A message written in the chat. With no conversation yet, one is made in the open project folder: a session of
@@ -1344,6 +1528,16 @@ let OperatorService = class OperatorService {
1344
1528
  const skill = input.skill?.trim() ? await this.skillFor(input.skill, session?.projectDir ?? (await this.workspace()).dir) : undefined;
1345
1529
  if (session) {
1346
1530
  const inFlight = session.tasks.find((t) => t.status === 'running' || t.status === 'waiting-approval');
1531
+ // A chat Kerrigan directs, while she works (2026-11-12): a note to its message at work, or to her.
1532
+ if (session.directedBy && !this.running.has(session.id) && this.running.has(this.runKey(session.id))) {
1533
+ if (skill)
1534
+ throw new Error('Kerrigan is at work with this chat: write to her conversation, or Stop her first.');
1535
+ if (inFlight) {
1536
+ await this.addTaskNote(session.id, inFlight.id, text);
1537
+ return { threadId: session.id, taskId: inFlight.id, noted: true, needsStart: false };
1538
+ }
1539
+ throw new Error('Kerrigan is at work with this chat: write to her conversation, or Stop her first.');
1540
+ }
1347
1541
  if (inFlight && this.running.has(session.id)) {
1348
1542
  if (skill)
1349
1543
  throw new Error(`A skill goes with a new message, and this one would be a note to the message at work. Send /${skill.name} when it has finished.`);
@@ -1382,7 +1576,19 @@ let OperatorService = class OperatorService {
1382
1576
  * Two chats (operator, 2026-10-20): this conversation is the lead's, and a worker carries out its subtasks. The
1383
1577
  * lead judges the worker's reports, so there is no review of its own.
1384
1578
  */
1385
- if (input.lead) {
1579
+ /*
1580
+ * Kerrigan directs (operator, 2026-11-12): the conversation is hers, and she chooses plan mode, two chats, the review
1581
+ * and the skill for each message she sends to a chat of its own. The model of those chats, as chosen beside hers.
1582
+ */
1583
+ if (input.kerrigan) {
1584
+ s.kerrigan = {
1585
+ ...(input.chatManualModel ? { chatManualModel: true } : {}),
1586
+ ...(!input.chatManualModel && input.chatModel?.trim() ? { chatModel: input.chatModel.trim() } : {}),
1587
+ };
1588
+ s.review = { enabled: false, model: '' };
1589
+ s.planMode = 'off';
1590
+ }
1591
+ else if (input.lead) {
1386
1592
  s.lead = {
1387
1593
  ...(input.workerManualModel ? { workerManualModel: true } : {}),
1388
1594
  ...(!input.workerManualModel && input.workerModel?.trim() ? { workerModel: input.workerModel.trim() } : {}),
@@ -1985,8 +2191,9 @@ let OperatorService = class OperatorService {
1985
2191
  async skills() {
1986
2192
  const cfg = await this.settings.load();
1987
2193
  return {
1988
- skills: (cfg.skills ?? []).map((k) => ({ name: k.name, description: k.description ?? '', text: k.text ?? '', projectDir: k.projectDir ?? '' })),
2194
+ skills: (cfg.skills ?? []).map((k) => ({ name: k.name, description: k.description ?? '', text: k.text ?? '', projectDir: k.projectDir ?? '', forKerrigan: k.forKerrigan ?? '' })),
1989
2195
  maxDescription: MAX_SKILL_DESCRIPTION,
2196
+ maxForKerrigan: MAX_SKILL_FOR_KERRIGAN,
1990
2197
  };
1991
2198
  }
1992
2199
  /**
@@ -2017,7 +2224,10 @@ let OperatorService = class OperatorService {
2017
2224
  const projectDir = String(k?.projectDir ?? '').trim();
2018
2225
  if (projectDir && !folders.some((f) => sameFolder(f, projectDir)))
2019
2226
  throw new Error(`The skill "${name}" is for ${projectDir}, which is not one of the projects in Settings.`);
2020
- return { name, description, text, projectDir };
2227
+ const forKerrigan = String(k?.forKerrigan ?? '').trim();
2228
+ if (forKerrigan.length > MAX_SKILL_FOR_KERRIGAN)
2229
+ throw new Error(`What "${name}" says for Kerrigan is longer than ${MAX_SKILL_FOR_KERRIGAN} characters: its phases, its result and what it needs, in a few lines.`);
2230
+ return { name, description, text, projectDir, forKerrigan };
2021
2231
  });
2022
2232
  await this.settings.update((raw) => ({ ...raw, skills }));
2023
2233
  return await this.skills();
@@ -2156,6 +2366,7 @@ let OperatorService = class OperatorService {
2156
2366
  this.parkLater(approval);
2157
2367
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
2158
2368
  message: `the lead asks the operator: ${ask.question}`, data: { approvalId: approval.id, question: approval.question } });
2369
+ ask.onCard?.(this.cardHandle(approval.id, (a, why) => this.answerQuestion(approval.id, a.text, undefined, undefined, a.chosen, { by: 'kerrigan', why })));
2159
2370
  });
2160
2371
  }
2161
2372
  /** The operator's answer to the lead's question. */
@@ -2184,10 +2395,11 @@ let OperatorService = class OperatorService {
2184
2395
  this.parkLater(approval);
2185
2396
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
2186
2397
  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 } });
2398
+ ask.onCard?.(this.cardHandle(approval.id, (choice, why) => this.answerRetry(approval.id, choice, { by: 'kerrigan', why })));
2187
2399
  });
2188
2400
  }
2189
2401
  /** The operator's choice for a subtask that failed for a technical reason: one of the card's own. */
2190
- answerRetry(approvalId, choice) {
2402
+ answerRetry(approvalId, choice, as) {
2191
2403
  const w = this.waiting.get(approvalId);
2192
2404
  if (!w?.resolveRetry || !w.approval.retry)
2193
2405
  return { ok: false, problem: 'No subtask is waiting for a choice under that id.' };
@@ -2196,9 +2408,31 @@ let OperatorService = class OperatorService {
2196
2408
  this.waiting.delete(approvalId);
2197
2409
  w.resolveRetry(choice);
2198
2410
  this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
2199
- message: `the operator chose for subtask ${w.approval.retry.n}: ${choice}`, data: { approvalId, retry: choice } });
2411
+ message: `${as ? 'Kerrigan' : 'the operator'} chose for subtask ${w.approval.retry.n}: ${choice}${as?.why ? ` — ${as.why}` : ''}`, data: { approvalId, retry: choice, ...(as ? { by: as.by } : {}) } });
2200
2412
  return { ok: true };
2201
2413
  }
2414
+ /**
2415
+ * A card, handed to Kerrigan to answer in the operator's place (2026-11-12): answered through the same way as their
2416
+ * press, said to be hers; marked with what she is doing about it, which the card shows.
2417
+ */
2418
+ cardHandle(id, answer) {
2419
+ return {
2420
+ id,
2421
+ open: () => this.waiting.has(id),
2422
+ answer: (a, why) => (this.waiting.has(id) ? answer(a, why) : { ok: false, problem: 'The card was answered already.' }),
2423
+ mark: (state) => {
2424
+ const w = this.waiting.get(id);
2425
+ if (!w)
2426
+ return;
2427
+ if (state)
2428
+ w.approval.kerrigan = state;
2429
+ else
2430
+ delete w.approval.kerrigan;
2431
+ this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-kerrigan', level: state?.state === 'yours' ? 'warn' : 'info',
2432
+ message: state?.state === 'yours' ? `Kerrigan leaves the card to the operator: ${state.why ?? ''}` : state ? 'the card went to Kerrigan' : 'the card is the operator\'s again', data: { approvalId: id, kerrigan: state } });
2433
+ },
2434
+ };
2435
+ }
2202
2436
  /**
2203
2437
  * Two chats, after a Stop (2026-10-25): "do not start a task again by itself after Stop; when the operator carries on in
2204
2438
  * the same conversation, let a chosen failed subtask be tried again, with the plan and the reports kept". The message
@@ -2227,19 +2461,23 @@ let OperatorService = class OperatorService {
2227
2461
  const cfg = await this.settings.load();
2228
2462
  return await this.start(threadId, cfg.execution.mode);
2229
2463
  }
2230
- answerQuestion(approvalId, text, ran, outcome, chosen) {
2464
+ answerQuestion(approvalId, text, ran, outcome, chosen, as) {
2231
2465
  const w = this.waiting.get(approvalId);
2232
2466
  if (!w?.resolveAnswer)
2233
2467
  return { ok: false, problem: 'No question of the lead is waiting under that id.' };
2468
+ // Kerrigan never answers commands handed over to run (2026-11-12): those are the operator's.
2469
+ if (as && w.approval.question?.handoff)
2470
+ return { ok: false, problem: 'Commands handed over to run are the operator\'s to answer.' };
2471
+ const who = as ? 'Kerrigan' : 'the operator';
2234
2472
  // A question of several answers (2026-11-02): the ones chosen, by their place, and what was written besides.
2235
2473
  if (chosen !== undefined && w.approval.question && !w.approval.question.handoff) {
2236
2474
  const many = chosenAnswer(w.approval.question, chosen, text);
2237
2475
  if ('problem' in many)
2238
2476
  return { ok: false, problem: many.problem };
2239
2477
  this.waiting.delete(approvalId);
2240
- w.resolveAnswer(many);
2478
+ w.resolveAnswer({ ...many, ...(as ? { by: as.by } : {}) });
2241
2479
  this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
2242
- message: `the operator chose ${many.chosen.length} of the answers`, data: { approvalId, question: true } });
2480
+ message: `${who} chose ${many.chosen.length} of the answers${as?.why ? ` — ${as.why}` : ''}`, data: { approvalId, question: true, ...(as ? { by: as.by } : {}) } });
2243
2481
  return { ok: true };
2244
2482
  }
2245
2483
  /*
@@ -2255,9 +2493,9 @@ let OperatorService = class OperatorService {
2255
2493
  if (!handed && !text.trim())
2256
2494
  return { ok: false, problem: 'Write the answer first.' };
2257
2495
  this.waiting.delete(approvalId);
2258
- w.resolveAnswer(handed ? { answer: text.trim(), ran: how === 'ran', outcome: how } : { answer: text.trim() });
2496
+ w.resolveAnswer(handed ? { answer: text.trim(), ran: how === 'ran', outcome: how } : { answer: text.trim(), ...(as ? { by: as.by } : {}) });
2259
2497
  this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
2260
- message: 'the operator answered the lead', data: { approvalId, question: true } });
2498
+ message: `${who} answered: ${text.trim().slice(0, 200)}${as?.why ? ` — ${as.why}` : ''}`, data: { approvalId, question: true, ...(as ? { by: as.by } : {}) } });
2261
2499
  return { ok: true };
2262
2500
  }
2263
2501
  /**
@@ -2290,13 +2528,14 @@ let OperatorService = class OperatorService {
2290
2528
  this.parkLater(approval);
2291
2529
  this.bus.publish({ sessionId: ask.sessionId, taskId: ask.taskId, type: 'approval-requested', level: 'warn',
2292
2530
  message: `the plan of "${ask.title}" (version ${ask.plan.version}) is waiting for you to approve it`, data: { approvalId: approval.id, plan: true } });
2531
+ ask.onCard?.(this.cardHandle(approval.id, (a, why) => this.decidePlan(approval.id, a.decision, a.note, { by: 'kerrigan', why })));
2293
2532
  });
2294
2533
  }
2295
2534
  /**
2296
2535
  * Answers a plan waiting for approval: approve it (with a note the chat is given beside it), ask for
2297
2536
  * another (saying what to change), or stop the task.
2298
2537
  */
2299
- decidePlan(approvalId, action, note) {
2538
+ decidePlan(approvalId, action, note, as) {
2300
2539
  const w = this.waiting.get(approvalId);
2301
2540
  if (!w || !w.resolvePlan)
2302
2541
  return { ok: false, problem: 'That plan is not waiting any more.' };
@@ -2306,14 +2545,15 @@ let OperatorService = class OperatorService {
2306
2545
  if (text.length > MAX_INSTRUCTION_CHARS)
2307
2546
  return { ok: false, problem: `The note is ${text.length} characters; it can be at most ${MAX_INSTRUCTION_CHARS}.` };
2308
2547
  this.waiting.delete(approvalId);
2309
- w.resolvePlan({ decision: action, ...(text ? { note: text } : {}) });
2548
+ w.resolvePlan({ decision: action, ...(text ? { note: text } : {}), ...(as ? { by: as.by } : {}) });
2310
2549
  this.bus.publish({ sessionId: w.approval.sessionId, taskId: w.approval.taskId, type: 'approval-decided', level: 'info',
2311
- message: `plan: ${action}${text ? ' (with a note)' : ''}`, data: { approvalId, action, plan: true } });
2550
+ message: `plan: ${action}${text ? ' (with a note)' : ''}${as ? `, by Kerrigan${as.why ? ` — ${as.why}` : ''}` : ''}`, data: { approvalId, action, plan: true, ...(as ? { by: as.by } : {}) } });
2312
2551
  return { ok: true };
2313
2552
  }
2314
2553
  /** What waits for the operator; of one session, its worker's included (two chats: they are asked in its conversation). */
2315
2554
  pendingApprovals(sessionId) {
2316
- return [...this.waiting.values()].map((w) => w.approval).filter((a) => !sessionId || a.sessionId === sessionId || this.workerLeads.get(a.sessionId) === sessionId);
2555
+ // Kerrigan's (2026-11-12): the cards of the chats she directs, and of their workers, are shown in hers too.
2556
+ return [...this.waiting.values()].map((w) => w.approval).filter((a) => !sessionId || this.under(a.sessionId, sessionId));
2317
2557
  }
2318
2558
  /**
2319
2559
  * Answers one pending approval.