copilot-operator 0.1.55 → 0.1.57

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 (195) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +625 -609
  3. package/dist/src/api/folderPicker.js +22 -22
  4. package/dist/src/api/operator.controller.js +30 -3
  5. package/dist/src/api/operator.service.js +96 -10
  6. package/dist/src/api/security.js +1 -1
  7. package/dist/src/api/server.js +9 -1
  8. package/dist/src/api/settings.js +18 -4
  9. package/dist/src/cli.js +16 -15
  10. package/dist/src/config/home.js +109 -0
  11. package/dist/src/config/layout.js +40 -5
  12. package/dist/src/config/schema.js +5 -1
  13. package/dist/src/exec/network.js +50 -3
  14. package/dist/src/orchestrator/leadRunner.js +20 -3
  15. package/dist/src/orchestrator/review.js +3 -2
  16. package/dist/src/orchestrator/taskRunner.js +88 -6
  17. package/dist/src/plan/kerrigan.js +126 -126
  18. package/dist/src/plan/systemGuide.js +99 -11
  19. package/dist/src/session/store.js +4 -0
  20. package/dist/src/session/workspaceGit.js +95 -1
  21. package/dist/src/transport/profileLock.js +34 -4
  22. package/dist/web/404.html +3 -3
  23. package/dist/web/_next/static/chunks/1077.7e88c156c16718c0.js +1 -0
  24. package/dist/web/_next/static/chunks/1083.0122bea31f7199d9.js +1 -0
  25. package/dist/web/_next/static/chunks/1490.f5154054ddfd3dee.js +1 -0
  26. package/dist/web/_next/static/chunks/1536.98fab69162f370f0.js +1 -0
  27. package/dist/web/_next/static/chunks/1548.a7127a9edf3f266b.js +1 -0
  28. package/dist/web/_next/static/chunks/1584.7500138d08971f81.js +1 -0
  29. package/dist/web/_next/static/chunks/1732.90182d376c75c315.js +1 -0
  30. package/dist/web/_next/static/chunks/17449abc.fa53da036b7dcfb4.js +1 -0
  31. package/dist/web/_next/static/chunks/1872.d12259d09bb1173f.js +1 -0
  32. package/dist/web/_next/static/chunks/192.955be0d5fcd27ec6.js +1 -0
  33. package/dist/web/_next/static/chunks/1920.59b93a4215a75653.js +1 -0
  34. package/dist/web/_next/static/chunks/2063.4745e20abad5b208.js +1 -0
  35. package/dist/web/_next/static/chunks/2163.60f52655ceb57752.js +1 -0
  36. package/dist/web/_next/static/chunks/2175.8c8957600f6b88a8.js +1 -0
  37. package/dist/web/_next/static/chunks/2280.5a3754f49656d989.js +1 -0
  38. package/dist/web/_next/static/chunks/2355.d6bb92f10d516f81.js +1 -0
  39. package/dist/web/_next/static/chunks/2378.4f15342be64a9d23.js +1 -0
  40. package/dist/web/_next/static/chunks/2395.c2c4d3696d3b5542.js +1 -0
  41. package/dist/web/_next/static/chunks/2486.d130023b2b399eaa.js +1 -0
  42. package/dist/web/_next/static/chunks/2606.8e9434e7fee257b9.js +1 -0
  43. package/dist/web/_next/static/chunks/26dd8e60.1890515693b4ca88.js +1 -0
  44. package/dist/web/_next/static/chunks/2738.2559ed1058f6fb19.js +1 -0
  45. package/dist/web/_next/static/chunks/2821.409d92f5ac5b8142.js +1 -0
  46. package/dist/web/_next/static/chunks/3088.12b1d19ca55225b7.js +1 -0
  47. package/dist/web/_next/static/chunks/3152.d623d85a9afed5d3.js +1 -0
  48. package/dist/web/_next/static/chunks/3184.0788c67536fc4140.js +1 -0
  49. package/dist/web/_next/static/chunks/3194.8ee589997ce1e093.js +1 -0
  50. package/dist/web/_next/static/chunks/3322.4f7b378a41711478.js +1 -0
  51. package/dist/web/_next/static/chunks/3564.bfa030e92401f57d.js +1 -0
  52. package/dist/web/_next/static/chunks/358.4791f77f174006f3.js +1 -0
  53. package/dist/web/_next/static/chunks/3696.a367f4c8f42909d1.js +1 -0
  54. package/dist/web/_next/static/chunks/3748.8726b202d79d0dba.js +3 -0
  55. package/dist/web/_next/static/chunks/3794.19aedfb95f89dc48.js +1 -0
  56. package/dist/web/_next/static/chunks/384.063f394c789898a7.js +1 -0
  57. package/dist/web/_next/static/chunks/3854.39b7a1bf2b4189fe.js +1 -0
  58. package/dist/web/_next/static/chunks/386.2718f961400a3322.js +1 -0
  59. package/dist/web/_next/static/chunks/4008.3691a32e1711848f.js +1 -0
  60. package/dist/web/_next/static/chunks/4054.1c8d37b1513d20d8.js +1 -0
  61. package/dist/web/_next/static/chunks/4328.e326d66dd5c820c6.js +1 -0
  62. package/dist/web/_next/static/chunks/4444.36f5d8532bd6300d.js +1 -0
  63. package/dist/web/_next/static/chunks/4512-8bcb4b34f41115b4.js +1 -0
  64. package/dist/web/_next/static/chunks/4560.b8235d283fb3608c.js +1 -0
  65. package/dist/web/_next/static/chunks/464.f60ecfb6c72ec733.js +1 -0
  66. package/dist/web/_next/static/chunks/4912.1ab85b0ebf52a3e0.js +1 -0
  67. package/dist/web/_next/static/chunks/4982.bbbd303d665de4f0.js +1 -0
  68. package/dist/web/_next/static/chunks/4fecf3c3.e14d65bd1dce80cf.js +1 -0
  69. package/dist/web/_next/static/chunks/5052.dc8c36742419eed5.js +1 -0
  70. package/dist/web/_next/static/chunks/{7496.17282033df0e8794.js → 5115.fbe164892bfd6fa4.js} +1 -1
  71. package/dist/web/_next/static/chunks/5120.b4aadb89d4fb4f65.js +1 -0
  72. package/dist/web/_next/static/chunks/5448.1c4e0b719af53b3f.js +1 -0
  73. package/dist/web/_next/static/chunks/5623.cc6818f4096ce4c2.js +1 -0
  74. package/dist/web/_next/static/chunks/5664.507fea1f6305067e.js +1 -0
  75. package/dist/web/_next/static/chunks/5706.be484c6a7bed3fde.js +1 -0
  76. package/dist/web/_next/static/chunks/6336.b09d0d920c7631eb.js +1 -0
  77. package/dist/web/_next/static/chunks/6364.5b0466f24f4ecf58.js +1 -0
  78. package/dist/web/_next/static/chunks/640.2c2baacde5197a77.js +1 -0
  79. package/dist/web/_next/static/chunks/6419.61399b0413b8bef0.js +1 -0
  80. package/dist/web/_next/static/chunks/642.b70763e1cfe9e45e.js +1 -0
  81. package/dist/web/_next/static/chunks/6554.0110334a71e72bbe.js +1 -0
  82. package/dist/web/_next/static/chunks/6688.4a6ac23ba061262b.js +1 -0
  83. package/dist/web/_next/static/chunks/6815.6537cc012ba16cca.js +1 -0
  84. package/dist/web/_next/static/chunks/6896.33fdeb4e682c2cab.js +1 -0
  85. package/dist/web/_next/static/chunks/6912.3416822e13b4bc03.js +1 -0
  86. package/dist/web/_next/static/chunks/6944.635230aa8cb23871.js +1 -0
  87. package/dist/web/_next/static/chunks/6964.35718884ad3375bc.js +1 -0
  88. package/dist/web/_next/static/chunks/6992.4b059bae2659231d.js +1 -0
  89. package/dist/web/_next/static/chunks/6996.7c41217972cabc3f.js +1 -0
  90. package/dist/web/_next/static/chunks/7024.8bc670b892a558bb.js +1 -0
  91. package/dist/web/_next/static/chunks/7040.e058d8f95c3c11e7.js +1 -0
  92. package/dist/web/_next/static/chunks/714.bee36b765509e92c.js +1 -0
  93. package/dist/web/_next/static/chunks/7220.c9c5c5f25baafec7.js +1 -0
  94. package/dist/web/_next/static/chunks/7250.7f1d45021e49d2fd.js +1 -0
  95. package/dist/web/_next/static/chunks/7290.7bceed706f7b6df5.js +1 -0
  96. package/dist/web/_next/static/chunks/7301.c60eb2ba8ae6b859.js +1 -0
  97. package/dist/web/_next/static/chunks/7328.021e5e45124e40de.js +1 -0
  98. package/dist/web/_next/static/chunks/7340.a5a75ee889c30b74.js +1 -0
  99. package/dist/web/_next/static/chunks/7443.c189418756727101.js +1 -0
  100. package/dist/web/_next/static/chunks/7484.c0e6bfca7b2fb65e.js +1 -0
  101. package/dist/web/_next/static/chunks/7496.e638a7286c17e438.js +1 -0
  102. package/dist/web/_next/static/chunks/7695.11ba99db589cb586.js +1 -0
  103. package/dist/web/_next/static/chunks/7764.e62333ee1d63a458.js +1 -0
  104. package/dist/web/_next/static/chunks/7921-fb0045927b0e86a8.js +1 -0
  105. package/dist/web/_next/static/chunks/80.df762af692aca107.js +1 -0
  106. package/dist/web/_next/static/chunks/8024.4bd0b5a7f26a0f7d.js +1 -0
  107. package/dist/web/_next/static/chunks/82b69429.c6dd4e5c5ac704f3.js +368 -0
  108. package/dist/web/_next/static/chunks/8360.371456f14873ee9f.js +1 -0
  109. package/dist/web/_next/static/chunks/8544.7c1fb012f9073eaa.js +1 -0
  110. package/dist/web/_next/static/chunks/8547.424f9970cc72775f.js +1 -0
  111. package/dist/web/_next/static/chunks/8584.97613589db58864f.js +1 -0
  112. package/dist/web/_next/static/chunks/8616.8e05c4a20dcdf39d.js +1 -0
  113. package/dist/web/_next/static/chunks/8752.bf29293df3366e17.js +298 -0
  114. package/dist/web/_next/static/chunks/8800.3c7b01176e98160a.js +1 -0
  115. package/dist/web/_next/static/chunks/88b2132a.04b02968da05b8a6.js +1005 -0
  116. package/dist/web/_next/static/chunks/8924.49dd385ac101fb7e.js +1 -0
  117. package/dist/web/_next/static/chunks/896.eb46d6e001d25d0f.js +1 -0
  118. package/dist/web/_next/static/chunks/9003.3d5c7a418d0b858b.js +1 -0
  119. package/dist/web/_next/static/chunks/9067.f7e111c6aa999784.js +1 -0
  120. package/dist/web/_next/static/chunks/9068.9662bb8fa5fdc637.js +1 -0
  121. package/dist/web/_next/static/chunks/9178.a7631bd283f2a69c.js +1 -0
  122. package/dist/web/_next/static/chunks/9190.e3a90b1a9ed21668.js +1 -0
  123. package/dist/web/_next/static/chunks/9296.59fcfc8261a4c6bd.js +1 -0
  124. package/dist/web/_next/static/chunks/9312.e1fb4089a122d3d3.js +1 -0
  125. package/dist/web/_next/static/chunks/9348.022486b05b882739.js +1 -0
  126. package/dist/web/_next/static/chunks/948.132a0571d85c8b01.js +1 -0
  127. package/dist/web/_next/static/chunks/951.43a4ba54b1d1ff4e.js +3 -0
  128. package/dist/web/_next/static/chunks/9544.acc06fe34aa32c5c.js +7 -0
  129. package/dist/web/_next/static/chunks/9591.d205941f0062de24.js +1 -0
  130. package/dist/web/_next/static/chunks/9628.d8954a2bd28b85a6.js +1 -0
  131. package/dist/web/_next/static/chunks/9636.35df6241125f8513.js +1 -0
  132. package/dist/web/_next/static/chunks/9658.cdecb568f615e4c9.js +782 -0
  133. package/dist/web/_next/static/chunks/9672.b379566a8bfcd947.js +1 -0
  134. package/dist/web/_next/static/chunks/9680.d10b204d08ca3a62.js +1 -0
  135. package/dist/web/_next/static/chunks/9728.1d4cb6c68bd55f44.js +1 -0
  136. package/dist/web/_next/static/chunks/9747.a5828643aaff11c0.js +1 -0
  137. package/dist/web/_next/static/chunks/9784.c9938b7e977e14eb.js +1 -0
  138. package/dist/web/_next/static/chunks/9812.024424a52730b057.js +1 -0
  139. package/dist/web/_next/static/chunks/9888.ce925cd415b672ef.js +1 -0
  140. package/dist/web/_next/static/chunks/{9891.91a2c59fd073fd48.js → 9891.a97db7c8f05693d1.js} +1 -1
  141. package/dist/web/_next/static/chunks/9904.a3d2f8569d7355ab.js +1 -0
  142. package/dist/web/_next/static/chunks/992.8470b96c23472686.js +1 -0
  143. package/dist/web/_next/static/chunks/9924.03252dda78c705c3.js +1 -0
  144. package/dist/web/_next/static/chunks/9968.3d45ff9183e8b07b.js +1 -0
  145. package/dist/web/_next/static/chunks/app/_not-found/page-23c6c0396966da29.js +1 -0
  146. package/dist/web/_next/static/chunks/app/defaults/page-4e5be923763ba3d9.js +1 -0
  147. package/dist/web/_next/static/chunks/app/layout-9cd9b0b0587f4882.js +1 -0
  148. package/dist/web/_next/static/chunks/app/page-8e85b507af649f85.js +1 -0
  149. package/dist/web/_next/static/chunks/app/settings/page-b39878dce98ded94.js +1 -0
  150. package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +1 -0
  151. package/dist/web/_next/static/chunks/{main-app-f747f0f5ddb4213b.js → main-app-d23441ca81b3a063.js} +1 -1
  152. package/dist/web/_next/static/chunks/webpack-d103630008e57024.js +1 -0
  153. package/dist/web/_next/static/css/2de713eca93a7750.css +3 -0
  154. package/dist/web/_next/static/css/4bf77b2aec4626c2.css +1 -0
  155. package/dist/web/_next/static/css/4bfdd3ebb3d1a180.css +1 -0
  156. package/dist/web/_next/static/css/73368887921d70d9.css +1 -0
  157. package/dist/web/_next/static/g2MUlOzNxfAGFR7EI9zQv/_buildManifest.js +1 -0
  158. package/dist/web/_next/static/media/codicon.5ce2572b.ttf +0 -0
  159. package/dist/web/_next/static/media/editorWebWorkerMain.828b206c.js +1 -0
  160. package/dist/web/defaults.html +3 -3
  161. package/dist/web/defaults.txt +11 -10
  162. package/dist/web/icon.svg +4 -0
  163. package/dist/web/index.html +4 -4
  164. package/dist/web/index.txt +11 -10
  165. package/dist/web/settings.html +14 -0
  166. package/dist/web/settings.txt +26 -0
  167. package/dist/web/system.html +3 -3
  168. package/dist/web/system.txt +11 -10
  169. package/dist/web/third-party-notices.txt +5966 -0
  170. package/package.json +160 -153
  171. package/prompts/lead1.md +140 -140
  172. package/prompts/level1.md +574 -574
  173. package/prompts/review1.md +287 -287
  174. package/dist/src/context/desktopDir.js +0 -44
  175. package/dist/web/_next/static/chunks/1077.3c07f38a61cef38a.js +0 -1
  176. package/dist/web/_next/static/chunks/1548.55dadf800d6c2a79.js +0 -1
  177. package/dist/web/_next/static/chunks/2163.83d1085b99ac1773.js +0 -1
  178. package/dist/web/_next/static/chunks/714.88c495053f62f187.js +0 -1
  179. package/dist/web/_next/static/chunks/7220.f1e8a10d52a7ee87.js +0 -1
  180. package/dist/web/_next/static/chunks/7500-1353339f7e2eda10.js +0 -1
  181. package/dist/web/_next/static/chunks/7921-56de379f7bdfbacf.js +0 -1
  182. package/dist/web/_next/static/chunks/8547.0a9997b67008c706.js +0 -1
  183. package/dist/web/_next/static/chunks/8584.b34930a6837344a6.js +0 -1
  184. package/dist/web/_next/static/chunks/9067.5651e8647cef053f.js +0 -1
  185. package/dist/web/_next/static/chunks/9591.fabd60bd0d10341c.js +0 -1
  186. package/dist/web/_next/static/chunks/9747.ad6b319cf12169ee.js +0 -1
  187. package/dist/web/_next/static/chunks/app/_not-found/page-1264c0db9665169c.js +0 -1
  188. package/dist/web/_next/static/chunks/app/defaults/page-ba24062a86d50e12.js +0 -1
  189. package/dist/web/_next/static/chunks/app/layout-46efb208d7c88648.js +0 -1
  190. package/dist/web/_next/static/chunks/app/page-07f80fd07281a230.js +0 -1
  191. package/dist/web/_next/static/chunks/app/system/page-825f53f14d16033d.js +0 -1
  192. package/dist/web/_next/static/chunks/webpack-ab0451ef95a8f52a.js +0 -1
  193. package/dist/web/_next/static/css/131c746a9d388eda.css +0 -1
  194. package/dist/web/_next/static/w1xPyNasTvFr11R3F7HkS/_buildManifest.js +0 -1
  195. /package/dist/web/_next/static/{w1xPyNasTvFr11R3F7HkS → g2MUlOzNxfAGFR7EI9zQv}/_ssgManifest.js +0 -0
@@ -13,28 +13,28 @@
13
13
  import { spawn } from 'node:child_process';
14
14
  import { existsSync } from 'node:fs';
15
15
  /** Nothing is interpolated into the script; the start folder goes in as an environment variable. */
16
- const SCRIPT = `
17
- Add-Type -AssemblyName System.Windows.Forms | Out-Null
18
- $dialog = New-Object System.Windows.Forms.FolderBrowserDialog
19
- $dialog.Description = 'Select the project folder'
20
- $dialog.ShowNewFolderButton = $false
21
- if ($env:COP_PICKER_START -and (Test-Path -LiteralPath $env:COP_PICKER_START)) {
22
- $dialog.SelectedPath = $env:COP_PICKER_START
23
- }
24
- # An owner window that is always on top, so the dialog lands in front of the browser
25
- # instead of behind it.
26
- $owner = New-Object System.Windows.Forms.Form
27
- $owner.TopMost = $true
28
- $owner.ShowInTaskbar = $false
29
- $owner.Opacity = 0
30
- $owner.Show()
31
- $result = $dialog.ShowDialog($owner)
32
- $owner.Close()
33
- if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
34
- [Console]::Out.Write('PICKED:' + $dialog.SelectedPath)
35
- } else {
36
- [Console]::Out.Write('CANCELLED')
37
- }
16
+ const SCRIPT = `
17
+ Add-Type -AssemblyName System.Windows.Forms | Out-Null
18
+ $dialog = New-Object System.Windows.Forms.FolderBrowserDialog
19
+ $dialog.Description = 'Select the project folder'
20
+ $dialog.ShowNewFolderButton = $false
21
+ if ($env:COP_PICKER_START -and (Test-Path -LiteralPath $env:COP_PICKER_START)) {
22
+ $dialog.SelectedPath = $env:COP_PICKER_START
23
+ }
24
+ # An owner window that is always on top, so the dialog lands in front of the browser
25
+ # instead of behind it.
26
+ $owner = New-Object System.Windows.Forms.Form
27
+ $owner.TopMost = $true
28
+ $owner.ShowInTaskbar = $false
29
+ $owner.Opacity = 0
30
+ $owner.Show()
31
+ $result = $dialog.ShowDialog($owner)
32
+ $owner.Close()
33
+ if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
34
+ [Console]::Out.Write('PICKED:' + $dialog.SelectedPath)
35
+ } else {
36
+ [Console]::Out.Write('CANCELLED')
37
+ }
38
38
  `;
39
39
  /** Windows PowerShell first: it is always present and its dialog is the familiar one. */
40
40
  function shellCandidates() {
@@ -239,20 +239,33 @@ let OperatorController = class OperatorController {
239
239
  }
240
240
  }
241
241
  /** The open folder's git: the changes, staged and not, and the branch's commits. Read-only. */
242
+ /**
243
+ * The bot's folder, chosen on the System page (2026-10-22): `dir` a folder, or null for the default; `copy` to copy
244
+ * what is in the folder now. Read at the bot's next start.
245
+ */
246
+ setHome(body = {}) {
247
+ if (body.dir !== null && typeof body.dir !== 'string')
248
+ throw new BadRequestException('dir must be the path of a folder, or null for the default');
249
+ return this.ops.setHome(body.dir === null ? null : body.dir, body.copy === true).catch(fail);
250
+ }
242
251
  workspaceGit() {
243
252
  return this.ops.workspaceGit().catch(fail);
244
253
  }
254
+ /** Everything the branch changed against `base` (a branch of the list it gives), as a pull request shows it. Read-only. */
255
+ workspaceBranch(base) {
256
+ return this.ops.workspaceBranch(base || undefined).catch(fail);
257
+ }
245
258
  workspaceCommit(sha) {
246
259
  if (!sha)
247
260
  throw new BadRequestException('sha is required');
248
261
  return this.ops.workspaceCommit(sha).catch(fail);
249
262
  }
250
- /** A file of those lists, its two versions: `area` staged, changes or commit (with `commit`). */
263
+ /** A file of those lists, its two versions: `area` staged, changes, commit (with `commit`) or branch (`commit`: the base). */
251
264
  workspaceGitFile(area, path, commit) {
252
265
  if (!path)
253
266
  throw new BadRequestException('path is required');
254
- if (area !== 'staged' && area !== 'changes' && area !== 'commit')
255
- throw new BadRequestException('area must be staged, changes or commit');
267
+ if (area !== 'staged' && area !== 'changes' && area !== 'commit' && area !== 'branch')
268
+ throw new BadRequestException('area must be staged, changes, commit or branch');
256
269
  if (area === 'commit' && !commit)
257
270
  throw new BadRequestException('commit is required');
258
271
  return this.ops.workspaceGitFile(area, path, commit).catch(fail);
@@ -591,12 +604,26 @@ __decorate([
591
604
  __metadata("design:paramtypes", [Object]),
592
605
  __metadata("design:returntype", Promise)
593
606
  ], OperatorController.prototype, "saveWorkspaceFile", null);
607
+ __decorate([
608
+ Put('home'),
609
+ __param(0, Body()),
610
+ __metadata("design:type", Function),
611
+ __metadata("design:paramtypes", [Object]),
612
+ __metadata("design:returntype", Promise)
613
+ ], OperatorController.prototype, "setHome", null);
594
614
  __decorate([
595
615
  Get('workspace/git'),
596
616
  __metadata("design:type", Function),
597
617
  __metadata("design:paramtypes", []),
598
618
  __metadata("design:returntype", Promise)
599
619
  ], OperatorController.prototype, "workspaceGit", null);
620
+ __decorate([
621
+ Get('workspace/git/branch'),
622
+ __param(0, Query('base')),
623
+ __metadata("design:type", Function),
624
+ __metadata("design:paramtypes", [String]),
625
+ __metadata("design:returntype", Promise)
626
+ ], OperatorController.prototype, "workspaceBranch", null);
600
627
  __decorate([
601
628
  Get('workspace/git/commit'),
602
629
  __param(0, Query('sha')),
@@ -16,7 +16,8 @@ import { pageModelFor, sameModel } from '../transport/modelMatch.js';
16
16
  import { Injectable } from '@nestjs/common';
17
17
  import { existsSync } from 'node:fs';
18
18
  import { join, resolve } from 'node:path';
19
- import { installLayout } from '../config/layout.js';
19
+ import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
20
+ import { chooseHome, homeRefusal, movedFrom } from '../config/home.js';
20
21
  import { SessionStore, DEFAULT_VCS, DEFAULT_REVIEW } from '../session/store.js';
21
22
  import { EventBus } from '../session/events.js';
22
23
  import { MAX_INSTRUCTION_CHARS, newId } from '../session/model.js';
@@ -28,7 +29,7 @@ import { buildStory } from '../session/story.js';
28
29
  import { buildTaskExchange } from '../session/taskExchange.js';
29
30
  import { chatNotice } from '../session/chatNotice.js';
30
31
  import { kerriganFileName, kerriganPersona } from '../plan/kerrigan.js';
31
- import { workspaceCommit, workspaceGit, workspaceGitVersions } from '../session/workspaceGit.js';
32
+ import { branchChanges, workspaceCommit, workspaceGit, workspaceGitVersions } from '../session/workspaceGit.js';
32
33
  import { chatCode } from '../transport/chatSession.js';
33
34
  /** The folders the operator works in: the default new sessions start on, and the rest by name. */
34
35
  /** The longest level 2 a project may have: Kerrigan carries each one whole. */
@@ -63,7 +64,7 @@ import { baseRefOf, commitInterrupted, nextAttemptBranch, repoDirOf, trackedRepo
63
64
  import { changedFilesBetween, fileAt, git, repoUnusableReason } from '../vcs/git.js';
64
65
  import { makeAuthorizer } from '../exec/authorizer.js';
65
66
  import { pickFolder } from './folderPicker.js';
66
- import { findEdgeUsingProfile } from '../transport/profileLock.js';
67
+ import { findEdgeUsingProfile, profileHolder } from '../transport/profileLock.js';
67
68
  import { assessIsolation, readIsolationSignals } from '../exec/isolation.js';
68
69
  import { unattendedPrecondition } from '../exec/policy.js';
69
70
  import { createTransport } from '../transport/chatTransport.js';
@@ -82,7 +83,6 @@ import { runVcsPreflight } from '../vcs/runPreflight.js';
82
83
  import { inputSettings, normalisePatterns } from '../vcs/inputs.js';
83
84
  import { coveredByArtifacts } from '../vcs/artifacts.js';
84
85
  import { botVersion } from '../config/version.js';
85
- import { resolveDesktopDir, desktopIsSynced } from '../context/desktopDir.js';
86
86
  import { settingsOf, SettingsUnusableError } from './settings.js';
87
87
  import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
88
88
  import { chatDenyPatterns } from '../config/schema.js';
@@ -136,6 +136,17 @@ let OperatorService = class OperatorService {
136
136
  /** Starts that did not get as far as a first task, for the page to show and offer as a file. */
137
137
  startFailures = new StartFailures();
138
138
  running = new Map();
139
+ /**
140
+ * Who is at work in each session's message now, as its runner says it (2026-10-22: "show clearly who works"):
141
+ * for `activity`, which every page asks on a timer and answers from memory. Gone when the message ends.
142
+ */
143
+ acting = new Map();
144
+ followsActing = this.bus.subscribe('*', (e) => {
145
+ if (e.type === 'acting' && e.data)
146
+ this.acting.set(e.sessionId, e.data);
147
+ else if (e.type === 'task-finished')
148
+ this.acting.delete(e.sessionId);
149
+ });
139
150
  waiting = new Map();
140
151
  /**
141
152
  * 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
@@ -803,6 +814,8 @@ let OperatorService = class OperatorService {
803
814
  const startedAt = new Date().toISOString();
804
815
  const hold = new Hold();
805
816
  this.running.set(sessionId, { controller, startedAt, mode, policy, hold });
817
+ // Who was at work in a run of it that ended without saying so is not who is at work in this one.
818
+ this.acting.delete(sessionId);
806
819
  {
807
820
  const asLead = await this.store.getSession(sessionId);
808
821
  if (asLead?.lead?.workerSessionId)
@@ -997,7 +1010,16 @@ let OperatorService = class OperatorService {
997
1010
  * and not idle either: `starting` says so, so "nothing is happening" is not read in that moment.
998
1011
  */
999
1012
  const starting = this.running.size === 0 && this.browser?.kind === 'run';
1000
- return { running: this.running.size > 0, sessions: this.running.size, starting };
1013
+ // Who is at work in the run going now — the lead's session says when its worker is (2026-10-22) — and whether it is held.
1014
+ const [id, run] = [...this.running.entries()][0] ?? [];
1015
+ const acting = id ? this.acting.get(id) : undefined;
1016
+ return {
1017
+ running: this.running.size > 0,
1018
+ sessions: this.running.size,
1019
+ starting,
1020
+ ...(acting ? { acting } : {}),
1021
+ ...(run?.hold?.held ? { paused: true } : {}),
1022
+ };
1001
1023
  }
1002
1024
  /**
1003
1025
  * Runs the queued tasks of several sessions, one session after another.
@@ -1078,6 +1100,13 @@ let OperatorService = class OperatorService {
1078
1100
  throw new Error(ws.problem ?? 'No project folder is open.');
1079
1101
  return await workspaceGit(ws.dir);
1080
1102
  }
1103
+ /** Everything the branch changed against a base, as a pull request shows it (see `branchChanges`). Read-only. */
1104
+ async workspaceBranch(base) {
1105
+ const ws = await this.workspace();
1106
+ if (!ws.ok)
1107
+ throw new Error(ws.problem ?? 'No project folder is open.');
1108
+ return await branchChanges(ws.dir, base);
1109
+ }
1081
1110
  async workspaceCommit(sha) {
1082
1111
  const ws = await this.workspace();
1083
1112
  if (!ws.ok)
@@ -1352,6 +1381,7 @@ let OperatorService = class OperatorService {
1352
1381
  stepId: 0,
1353
1382
  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}` : ''}`,
1354
1383
  createdAt: new Date().toISOString(),
1384
+ ...(ask.actor ? { actor: ask.actor } : {}),
1355
1385
  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 } : {}) },
1356
1386
  };
1357
1387
  this.waiting.set(approval.id, {
@@ -1380,6 +1410,7 @@ let OperatorService = class OperatorService {
1380
1410
  stepId: 0,
1381
1411
  description: `The lead asks: ${ask.question}`,
1382
1412
  createdAt: new Date().toISOString(),
1413
+ actor: 'lead',
1383
1414
  question: { text: ask.question, ...(ask.why ? { why: ask.why } : {}), options: ask.options },
1384
1415
  };
1385
1416
  this.waiting.set(approval.id, {
@@ -1423,6 +1454,8 @@ let OperatorService = class OperatorService {
1423
1454
  stepId: 0,
1424
1455
  description: `The plan of "${ask.title}" (version ${ask.plan.version})`,
1425
1456
  createdAt: new Date().toISOString(),
1457
+ // The chat that wrote it in plan mode, or the lead's plan of two chats.
1458
+ actor: ask.actor ?? 'plan',
1426
1459
  plan: { title: ask.title, plan: ask.plan },
1427
1460
  };
1428
1461
  this.waiting.set(approval.id, {
@@ -1562,6 +1595,7 @@ let OperatorService = class OperatorService {
1562
1595
  stepId: step.id,
1563
1596
  description: `[${step.shell ?? 'pwsh'}] ${step.cmd}`,
1564
1597
  createdAt: new Date().toISOString(),
1598
+ ...(ctx.actor ? { actor: ctx.actor } : {}),
1565
1599
  ...(held ? { network: held.network } : {}),
1566
1600
  };
1567
1601
  this.waiting.set(approval.id, { approval, resolve: resolvePromise });
@@ -2110,10 +2144,55 @@ let OperatorService = class OperatorService {
2110
2144
  async browseFolder(start) {
2111
2145
  return await pickFolder(start);
2112
2146
  }
2147
+ /**
2148
+ * The bot's folder chosen on the System page (operator, 2026-10-22): `dir`, or `null` for the default; with `copy`,
2149
+ * what is in the folder now goes there too. Read at the next start; refused while work goes on, for a clone, or for
2150
+ * a folder that cannot be the bot's.
2151
+ */
2152
+ async setHome(dir, copy) {
2153
+ const layout = this.layout;
2154
+ if (layout.mode !== 'package')
2155
+ throw new Error('A clone keeps its records in the clone (data/ and runs/); start it with COP_DATA_DIR set to keep them elsewhere.');
2156
+ if (layout.homeFrom === 'env')
2157
+ throw new Error(`COP_HOME places the bot's folder (${layout.homeDir}); change or remove it where it is set.`);
2158
+ if (this.running.size > 0)
2159
+ throw new Error('Work is going on: stop it, or let it end, before moving the bot\'s folder.');
2160
+ if (dir !== null) {
2161
+ const refused = homeRefusal(dir, layout);
2162
+ if (refused)
2163
+ throw new Error(refused);
2164
+ }
2165
+ if (copy) {
2166
+ // Its files are in use while its window is open: closed first, as another run would close it.
2167
+ await this.closeChatWindow('the bot\'s folder is being copied');
2168
+ const cfg = await this.settings.load();
2169
+ const holders = findEdgeUsingProfile(cfg.resolved.profileDir);
2170
+ if (Array.isArray(holders) && holders.length > 0)
2171
+ throw new Error(`Edge has the bot's profile open (pid ${holders.slice(0, 4).map((h) => h.pid).join(', ')}): close that window, then copy.`);
2172
+ }
2173
+ /*
2174
+ * A profile the settings name in the folder left behind would stay there: it follows the folder instead. Before the
2175
+ * copy, so the settings copied over say so too; for this process it is the same folder, the default one.
2176
+ */
2177
+ await this.settings.update((raw) => {
2178
+ const copilot = raw.copilot ?? {};
2179
+ if (typeof copilot.profileDir === 'string' && resolve(copilot.profileDir).toLowerCase() === resolve(join(layout.homeDir, 'edge-profile')).toLowerCase()) {
2180
+ const { profileDir: _gone, ...rest } = copilot;
2181
+ return { ...raw, copilot: rest };
2182
+ }
2183
+ return raw;
2184
+ });
2185
+ const chosen = chooseHome(layout, dir, copy);
2186
+ console.log(`[home] the bot's folder will be ${chosen.home} from its next start${chosen.copied.length ? ` (copied: ${chosen.copied.join(', ')})` : ''}`);
2187
+ return { ...chosen, restart: true };
2188
+ }
2113
2189
  async doctor() {
2114
2190
  const cfg = await this.settings.load();
2115
2191
  const edge = ['C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', 'C:/Program Files/Microsoft/Edge/Application/msedge.exe'].find((p) => existsSync(p));
2116
2192
  const holders = findEdgeUsingProfile(cfg.resolved.profileDir);
2193
+ // Whose Edge it is: the bot's own — a run's, or its chat window kept open between messages — or another's.
2194
+ const holder = profileHolder(holders, process.pid);
2195
+ const layout = this.layout;
2117
2196
  return {
2118
2197
  // Which copilot-operator this is: `cop --version` without a terminal.
2119
2198
  version: botVersion(),
@@ -2123,13 +2202,20 @@ let OperatorService = class OperatorService {
2123
2202
  profileExists: existsSync(cfg.resolved.profileDir),
2124
2203
  profileHeldBy: Array.isArray(holders) ? holders.map((h) => h.pid) : 'unknown',
2125
2204
  /*
2126
- * Whether the bot itself is what holds the profile. While a run is going, Edge is open
2127
- * on that profile *by the runner*, and the warning "close this Edge window, a run would
2128
- * fail" was shown in exactly the moment it was false. The page says which it is.
2205
+ * Whose Edge holds the profile (2026-10-22). While a run is going, Edge is open on it by the runner; between
2206
+ * messages the chat's window stays open by the bot too, and the warning "close this Edge window, a run would
2207
+ * fail" was shown then, when it was false: it counted only runs. An Edge the bot's API started is its own.
2129
2208
  */
2209
+ profileHolder: holder === 'own' ? (this.running.size > 0 ? 'own-run' : 'own-window') : holder,
2130
2210
  botRunning: this.running.size > 0,
2131
- desktop: resolveDesktopDir(),
2132
- desktopSynced: desktopIsSynced(),
2211
+ // The bot's folder (2026-10-22): where it is, where it would be by default, and what was chosen for the next start.
2212
+ install: layout.mode,
2213
+ home: layout.homeDir,
2214
+ homeFrom: layout.homeFrom,
2215
+ homeDefault: layout.mode === 'package' ? defaultHome() : null,
2216
+ homeNext: layout.mode === 'package' && layout.homeFrom !== 'env' ? (chosenHome() ?? defaultHome()) : null,
2217
+ homeMovedFrom: movedFrom(layout.homeDir),
2218
+ settingsFile: join(this.dataDir, 'settings.json'),
2133
2219
  cwd: cfg.resolved.cwd,
2134
2220
  runsDir: cfg.resolved.runsDir,
2135
2221
  dataDir: this.dataDir,
@@ -223,7 +223,7 @@ export function judgeRequest(req, opts) {
223
223
  ok: false,
224
224
  status: 401,
225
225
  reason: 'token',
226
- detail: 'this API needs the token kept in data/api-token (.copilot-operator/data/api-token when installed from npm), ' +
226
+ detail: 'this API needs the token kept in data/api-token (in the bot\'s folder when installed from npm: System shows where), ' +
227
227
  'as an Authorization: Bearer header, ' +
228
228
  'an x-cop-token header, or a token query parameter. Open the interface from `npx cop start` (or ' +
229
229
  '`npm start` in a clone) and it is given the token.',
@@ -22,6 +22,7 @@ import { pruneRuns } from '../session/retention.js';
22
22
  import { mkdir, writeFile } from 'node:fs/promises';
23
23
  import { existsSync } from 'node:fs';
24
24
  import { installLayout } from '../config/layout.js';
25
+ import { moveLegacyHome } from '../config/home.js';
25
26
  import { captureTerminal } from '../log/terminal.js';
26
27
  /**
27
28
  * A settings file, or a policy lock, that cannot be used, answered the same way on every route: 409,
@@ -84,12 +85,19 @@ export async function startApi(opts = {}) {
84
85
  * on the machine were both callers all along.
85
86
  */
86
87
  const layout = installLayout();
88
+ /*
89
+ * The records a package kept in the project's .copilot-operator until 2026-10-22, copied once into the bot's own
90
+ * folder (see config/home.ts). The old folder stays, for the operator to delete; System says where it is.
91
+ */
92
+ const moved = moveLegacyHome(layout);
93
+ if (moved)
94
+ console.log(`[start] the bot's records were in ${moved.from}; copied to its own folder ${moved.to}. The old folder can be deleted.`);
87
95
  const dataDir = layout.dataDir;
88
96
  const webDir = opts.webDir ?? layout.webDir;
89
97
  await mkdir(dataDir, { recursive: true });
90
98
  if (layout.mode === 'package') {
91
99
  /*
92
- * The records folder sits inside the project, so it must be invisible to the project's git:
100
+ * The records folder may sit inside a project, when the operator chose that, so it must be invisible to its git:
93
101
  * version control refuses to branch on a tree with untracked files, and the records are not
94
102
  * the project's work. A `.gitignore` of `*` inside the folder says so without touching the
95
103
  * project's own .gitignore.
@@ -79,7 +79,9 @@ export function checkSettings(value, path) {
79
79
  * for the API and for `cop doctor`, so the doctor reads them as the API that it vouches for will.
80
80
  */
81
81
  export function settingsOf(layout) {
82
- return new Settings(layout.projectRoot, layout.dataDir, layout.mode === 'package' ? { runsDir: layout.runsDir, level1File: join(layout.promptsDir, 'level1.md') } : {});
82
+ return new Settings(layout.projectRoot, layout.dataDir,
83
+ // A package's Edge profile is in its folder, wherever that is (2026-10-22): where it was, unless another was chosen.
84
+ layout.mode === 'package' ? { runsDir: layout.runsDir, level1File: join(layout.promptsDir, 'level1.md'), profileDir: join(layout.homeDir, 'edge-profile') } : {});
83
85
  }
84
86
  export class Settings {
85
87
  projectRoot;
@@ -124,7 +126,7 @@ export class Settings {
124
126
  * does not parse is a `PolicyLockUnusableError`, answered by name on every route as this one is.
125
127
  */
126
128
  async load() {
127
- const value = { ...this.installDefaults, ...(await this.raw()), dataDir: this.dataDir };
129
+ const value = this.withDefaults(await this.raw());
128
130
  try {
129
131
  return await loadConfigObject(value, this.projectRoot, this.path);
130
132
  }
@@ -171,7 +173,7 @@ export class Settings {
171
173
  const raw = await this.raw();
172
174
  const value = next(raw);
173
175
  try {
174
- resolved = await loadConfigObject({ ...this.installDefaults, ...value, dataDir: this.dataDir }, this.projectRoot, this.path);
176
+ resolved = await loadConfigObject(this.withDefaults(value), this.projectRoot, this.path);
175
177
  }
176
178
  catch (e) {
177
179
  /*
@@ -182,13 +184,25 @@ export class Settings {
182
184
  * set replaces what the file holds, and what the schema refuses in it is the request's own.
183
185
  */
184
186
  if (rest === 'keeps')
185
- checkSettings({ ...this.installDefaults, ...raw, dataDir: this.dataDir }, this.path);
187
+ checkSettings(this.withDefaults(raw), this.path);
186
188
  throw e;
187
189
  }
188
190
  return JSON.stringify(value, null, 2);
189
191
  });
190
192
  return resolved;
191
193
  }
194
+ /**
195
+ * What the file holds over this install's defaults. The Edge profile's is one of `copilot`'s keys, so it goes in
196
+ * there when the file names none, keeping whatever else the file says of `copilot`.
197
+ */
198
+ withDefaults(raw) {
199
+ const { profileDir, ...defaults } = this.installDefaults;
200
+ const value = { ...defaults, ...raw, dataDir: this.dataDir };
201
+ const copilot = raw.copilot ?? {};
202
+ if (typeof profileDir === 'string' && typeof copilot.profileDir !== 'string')
203
+ value.copilot = { ...copilot, profileDir };
204
+ return value;
205
+ }
192
206
  /** The schema defaults, for the UI to show what "not set" means. */
193
207
  async defaults() {
194
208
  const resolved = await loadConfigObject({}, this.projectRoot, 'defaults');
package/dist/src/cli.js CHANGED
@@ -26,10 +26,9 @@ import { EventBus } from './session/events.js';
26
26
  import { terminalAuthorizer, unattendedAuthorizer } from './exec/authorizer.js';
27
27
  import { unattendedPrecondition } from './exec/policy.js';
28
28
  import { isOwnCheckout } from './exec/workDir.js';
29
- import { desktopIsSynced, resolveDesktopDir } from './context/desktopDir.js';
30
29
  import { Url } from './transport/locators.js';
31
30
  import { botVersion } from './config/version.js';
32
- import { findEdgeUsingProfile } from './transport/profileLock.js';
31
+ import { findEdgeUsingProfile, profileHolder, profileLockOwner } from './transport/profileLock.js';
33
32
  import { assessIsolation, readIsolationSignals } from './exec/isolation.js';
34
33
  /** The running version; see `config/version.ts`. */
35
34
  const ownVersion = botVersion;
@@ -38,7 +37,8 @@ program
38
37
  .name('cop')
39
38
  .description('Runs a task loop with Microsoft 365 Copilot on a Windows machine.')
40
39
  .version(ownVersion());
41
- const DEFAULT_PROFILE = expandPath('~/AppData/Local/copilot-operator/edge-profile', process.cwd());
40
+ // In the bot's folder when installed from npm, as the API has it (config/layout.ts, 2026-10-22).
41
+ const DEFAULT_PROFILE = installLayout().mode === 'package' ? join(installLayout().homeDir, 'edge-profile') : expandPath('~/AppData/Local/copilot-operator/edge-profile', process.cwd());
42
42
  program
43
43
  .command('start')
44
44
  .description("start copilot-operator for this project on 127.0.0.1: the API, and the web interface the package ships (a clone's interface comes from npm start)")
@@ -196,7 +196,7 @@ program
196
196
  replyTimeoutMs: 60_000,
197
197
  signInTimeoutMs: 15 * 60_000,
198
198
  humanWaitMs: 15 * 60_000,
199
- onEvent: (e, d) => process.stdout.write(` ${e}${d && Object.keys(d).length ? ' ' + JSON.stringify(d) : ''}
199
+ onEvent: (e, d) => process.stdout.write(` ${e}${d && Object.keys(d).length ? ' ' + JSON.stringify(d) : ''}
200
200
  `),
201
201
  });
202
202
  await transport.open();
@@ -340,7 +340,12 @@ program
340
340
  }
341
341
  }
342
342
  const edgeUsers = findEdgeUsingProfile(DEFAULT_PROFILE);
343
- if (Array.isArray(edgeUsers) && edgeUsers.length > 0) {
343
+ // The bot's own API may hold it — its chat window stays open between messages — and then a run uses it.
344
+ const lockOwner = profileLockOwner(DEFAULT_PROFILE);
345
+ if (Array.isArray(edgeUsers) && edgeUsers.length > 0 && lockOwner !== null && profileHolder(edgeUsers, lockOwner) === 'own') {
346
+ console.log(` ok the bot's own Edge has the profile (its API, process ${lockOwner}): its chat window, kept open between messages`);
347
+ }
348
+ else if (Array.isArray(edgeUsers) && edgeUsers.length > 0) {
344
349
  const pids = edgeUsers.map((u) => u.pid);
345
350
  say(false, `Edge is already running with the bot profile (${pids.length} process(es)). A run would ` +
346
351
  `fail with "Target page, context or browser has been closed". Close that Edge window, or:`);
@@ -352,10 +357,6 @@ program
352
357
  else {
353
358
  console.log(' ok no Edge process is holding the bot profile');
354
359
  }
355
- const desktop = resolveDesktopDir();
356
- say(existsSync(desktop), `Desktop at ${desktop}`);
357
- console.log(` ${desktopIsSynced() ? 'ok ' : 'note'} Desktop ${desktopIsSynced() ? 'is' : 'is NOT'} backed up by OneDrive` +
358
- `${desktopIsSynced() ? '' : ' — logs saved there stay on this machine only'}`);
359
360
  if (configPath) {
360
361
  try {
361
362
  const cfg = await loadConfig(configPath);
@@ -506,14 +507,14 @@ program
506
507
  console.log('');
507
508
  console.log(`task "${done?.title}": ${done?.status} after ${done?.iterations ?? 0} iteration(s)`);
508
509
  if (done?.summary)
509
- console.log(`
510
- Summary:
510
+ console.log(`
511
+ Summary:
511
512
  ${done.summary}`);
512
513
  if (done?.reason)
513
- console.log(`
514
+ console.log(`
514
515
  Reason: ${done.reason}`);
515
516
  if (final?.chat)
516
- console.log(`
517
+ console.log(`
517
518
  chat: ${final.chat.name} — ${final.chat.url}`);
518
519
  if (done?.runId)
519
520
  console.log(`log: ${join(cfg.resolved.runsDir, done.runId, 'task-log.txt')}`);
@@ -533,8 +534,8 @@ program
533
534
  return;
534
535
  }
535
536
  const c = withChat.chat;
536
- console.log(`${c.name}
537
- ${c.url}
537
+ console.log(`${c.name}
538
+ ${c.url}
538
539
  session ${withChat.id}, ${withChat.tasks.length} task(s), created ${c.createdAt}`);
539
540
  });
540
541
  program.parseAsync(process.argv).catch((e) => {
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The bot's folder: its settings, its conversations, its logs and its Edge profile (operator, 2026-10-22: "let the
3
+ * user choose where the bot's profile is kept; with nothing chosen, show the default; no .copilot-operator folder in
4
+ * the project unless it was set there").
5
+ *
6
+ * A package keeps it in `defaultHome()` unless the operator chose another folder, which is written in the default
7
+ * folder's `location.json` and read at start (see `installLayout`). A start that finds the bot's records where they
8
+ * were kept until then — `.copilot-operator` in the folder it was started from — and none yet in its folder copies
9
+ * them over once, and says so; the old folder is left for the operator to delete.
10
+ */
11
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
12
+ import { isAbsolute, join, resolve, sep } from 'node:path';
13
+ import { defaultHome, HOME_CHOICE_FILE } from './layout.js';
14
+ /** The file in the bot's folder that says where its records were copied from, and when. */
15
+ const MOVED_FILE = 'moved-from.json';
16
+ const same = (a, b) => resolve(a).toLowerCase() === resolve(b).toLowerCase();
17
+ const inside = (dir, root) => {
18
+ const a = resolve(dir).toLowerCase();
19
+ const b = resolve(root).toLowerCase();
20
+ return a === b || a.startsWith(b.endsWith(sep) ? b : b + sep);
21
+ };
22
+ /** Whether a folder holds the bot's records: its settings or its conversations. */
23
+ function holdsRecords(home) {
24
+ return existsSync(join(home, 'data', 'settings.json')) || existsSync(join(home, 'data', 'sessions'));
25
+ }
26
+ /**
27
+ * At start: the records a package kept in the project's `.copilot-operator` until 2026-10-22, copied into the bot's
28
+ * folder when that has none of its own yet. Not when the operator chose the project's folder itself, nor when
29
+ * COP_HOME or COP_DATA_DIR place the records. The old folder is left as it was.
30
+ */
31
+ export function moveLegacyHome(layout, env = process.env) {
32
+ if (layout.mode !== 'package' || layout.homeFrom === 'env' || env.COP_DATA_DIR?.trim() || !layout.legacyHomeDir)
33
+ return null;
34
+ const legacy = layout.legacyHomeDir;
35
+ if (same(legacy, layout.homeDir) || !holdsRecords(legacy) || holdsRecords(layout.homeDir))
36
+ return null;
37
+ mkdirSync(layout.homeDir, { recursive: true });
38
+ for (const part of ['data', 'runs']) {
39
+ if (existsSync(join(legacy, part)))
40
+ cpSync(join(legacy, part), join(layout.homeDir, part), { recursive: true, force: false, errorOnExist: false });
41
+ }
42
+ writeFileSync(join(layout.homeDir, MOVED_FILE), JSON.stringify({ from: legacy, at: new Date().toISOString() }, null, 2), 'utf8');
43
+ return { from: legacy, to: layout.homeDir };
44
+ }
45
+ /** Where the bot's records were copied from into this folder, and when; null when they were not. */
46
+ export function movedFrom(home) {
47
+ try {
48
+ const v = JSON.parse(readFileSync(join(home, MOVED_FILE), 'utf8'));
49
+ if (typeof v.from !== 'string' || typeof v.at !== 'string')
50
+ return null;
51
+ return { from: v.from, at: v.at, stillThere: existsSync(v.from) };
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /** Why a folder cannot be the bot's, or null when it can: absolute, not the program's own, writable. */
58
+ export function homeRefusal(dir, layout) {
59
+ if (!dir.trim() || !isAbsolute(dir.trim()))
60
+ return 'Give the whole path of a folder, as C:\\Users\\you\\bot or D:\\bot.';
61
+ const d = resolve(dir.trim());
62
+ if (inside(d, layout.botRoot) || /[\\/]node_modules([\\/]|$)/i.test(d))
63
+ return 'That is inside the program itself, which npm replaces on every update: choose a folder of your own.';
64
+ // Copied into itself, or over the folder it is copied from, a copy would never end.
65
+ if (!same(d, layout.homeDir) && (inside(d, layout.homeDir) || inside(layout.homeDir, d)))
66
+ return `That folder is inside the bot's folder now (${layout.homeDir}), or holds it: choose one beside it.`;
67
+ try {
68
+ mkdirSync(d, { recursive: true });
69
+ const probe = join(d, `.cop-write-test-${process.pid}`);
70
+ writeFileSync(probe, 'x', 'utf8');
71
+ rmSync(probe, { force: true });
72
+ }
73
+ catch (e) {
74
+ return `That folder cannot be written to: ${e.message}`;
75
+ }
76
+ return null;
77
+ }
78
+ /**
79
+ * The operator's choice of folder, written where the next start reads it; `null` back to the default. With `copy`,
80
+ * what is in the folder now — settings, conversations, logs, the Edge profile — is copied into the new one first,
81
+ * leaving out what the new one has already (`kept`): nothing in it is overwritten. Takes effect when the bot starts
82
+ * again.
83
+ */
84
+ export function chooseHome(layout, dir, copy, env = process.env) {
85
+ const target = dir ? resolve(dir.trim()) : defaultHome(env);
86
+ const copied = [];
87
+ const kept = [];
88
+ if (copy && !same(target, layout.homeDir) && existsSync(layout.homeDir)) {
89
+ mkdirSync(target, { recursive: true });
90
+ for (const part of readdirSync(layout.homeDir)) {
91
+ if (part === HOME_CHOICE_FILE || part === MOVED_FILE)
92
+ continue;
93
+ if (existsSync(join(target, part))) {
94
+ kept.push(part);
95
+ continue;
96
+ }
97
+ cpSync(join(layout.homeDir, part), join(target, part), { recursive: true, force: false, errorOnExist: false });
98
+ copied.push(part);
99
+ }
100
+ }
101
+ const pointerDir = defaultHome(env);
102
+ mkdirSync(pointerDir, { recursive: true });
103
+ const pointer = join(pointerDir, HOME_CHOICE_FILE);
104
+ if (same(target, pointerDir))
105
+ rmSync(pointer, { force: true });
106
+ else
107
+ writeFileSync(pointer, JSON.stringify({ home: target }, null, 2), 'utf8');
108
+ return { home: target, copied, kept };
109
+ }