copilot-operator 0.1.54 → 0.1.56

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 (197) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +618 -609
  3. package/dist/src/api/folderPicker.js +22 -22
  4. package/dist/src/api/operator.controller.js +32 -3
  5. package/dist/src/api/operator.service.js +80 -12
  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/hold.js +25 -0
  15. package/dist/src/orchestrator/leadLedger.js +88 -0
  16. package/dist/src/orchestrator/leadRunner.js +29 -2
  17. package/dist/src/orchestrator/review.js +2 -2
  18. package/dist/src/orchestrator/taskRunner.js +46 -4
  19. package/dist/src/plan/kerrigan.js +126 -126
  20. package/dist/src/plan/systemGuide.js +129 -17
  21. package/dist/src/protocol/leadSchema.js +36 -2
  22. package/dist/src/session/store.js +3 -0
  23. package/dist/src/session/workspaceGit.js +95 -1
  24. package/dist/src/transport/profileLock.js +34 -4
  25. package/dist/web/404.html +3 -3
  26. package/dist/web/_next/static/L-h3cKqABsuAzPqNkvLAP/_buildManifest.js +1 -0
  27. package/dist/web/_next/static/chunks/1077.a8fcbe8fc90ecb2d.js +1 -0
  28. package/dist/web/_next/static/chunks/1083.0122bea31f7199d9.js +1 -0
  29. package/dist/web/_next/static/chunks/1490.f5154054ddfd3dee.js +1 -0
  30. package/dist/web/_next/static/chunks/1536.98fab69162f370f0.js +1 -0
  31. package/dist/web/_next/static/chunks/1548.3aba99d28ca12a76.js +1 -0
  32. package/dist/web/_next/static/chunks/1584.7500138d08971f81.js +1 -0
  33. package/dist/web/_next/static/chunks/1732.90182d376c75c315.js +1 -0
  34. package/dist/web/_next/static/chunks/17449abc.fa53da036b7dcfb4.js +1 -0
  35. package/dist/web/_next/static/chunks/1872.d12259d09bb1173f.js +1 -0
  36. package/dist/web/_next/static/chunks/192.955be0d5fcd27ec6.js +1 -0
  37. package/dist/web/_next/static/chunks/1920.59b93a4215a75653.js +1 -0
  38. package/dist/web/_next/static/chunks/2063.4745e20abad5b208.js +1 -0
  39. package/dist/web/_next/static/chunks/2163.f028462d8dbc30fe.js +1 -0
  40. package/dist/web/_next/static/chunks/2175.8c8957600f6b88a8.js +1 -0
  41. package/dist/web/_next/static/chunks/2280.5a3754f49656d989.js +1 -0
  42. package/dist/web/_next/static/chunks/2355.d6bb92f10d516f81.js +1 -0
  43. package/dist/web/_next/static/chunks/2378.4f15342be64a9d23.js +1 -0
  44. package/dist/web/_next/static/chunks/2395.c2c4d3696d3b5542.js +1 -0
  45. package/dist/web/_next/static/chunks/2486.d130023b2b399eaa.js +1 -0
  46. package/dist/web/_next/static/chunks/2606.8e9434e7fee257b9.js +1 -0
  47. package/dist/web/_next/static/chunks/26dd8e60.1890515693b4ca88.js +1 -0
  48. package/dist/web/_next/static/chunks/2738.2559ed1058f6fb19.js +1 -0
  49. package/dist/web/_next/static/chunks/2821.409d92f5ac5b8142.js +1 -0
  50. package/dist/web/_next/static/chunks/3088.12b1d19ca55225b7.js +1 -0
  51. package/dist/web/_next/static/chunks/3152.d623d85a9afed5d3.js +1 -0
  52. package/dist/web/_next/static/chunks/3184.0788c67536fc4140.js +1 -0
  53. package/dist/web/_next/static/chunks/3194.8ee589997ce1e093.js +1 -0
  54. package/dist/web/_next/static/chunks/3322.4f7b378a41711478.js +1 -0
  55. package/dist/web/_next/static/chunks/3564.bfa030e92401f57d.js +1 -0
  56. package/dist/web/_next/static/chunks/358.4791f77f174006f3.js +1 -0
  57. package/dist/web/_next/static/chunks/3696.a367f4c8f42909d1.js +1 -0
  58. package/dist/web/_next/static/chunks/3748.8726b202d79d0dba.js +3 -0
  59. package/dist/web/_next/static/chunks/3794.19aedfb95f89dc48.js +1 -0
  60. package/dist/web/_next/static/chunks/384.063f394c789898a7.js +1 -0
  61. package/dist/web/_next/static/chunks/3854.39b7a1bf2b4189fe.js +1 -0
  62. package/dist/web/_next/static/chunks/386.2718f961400a3322.js +1 -0
  63. package/dist/web/_next/static/chunks/4008.3691a32e1711848f.js +1 -0
  64. package/dist/web/_next/static/chunks/4054.1c8d37b1513d20d8.js +1 -0
  65. package/dist/web/_next/static/chunks/4328.e326d66dd5c820c6.js +1 -0
  66. package/dist/web/_next/static/chunks/4444.36f5d8532bd6300d.js +1 -0
  67. package/dist/web/_next/static/chunks/4560.b8235d283fb3608c.js +1 -0
  68. package/dist/web/_next/static/chunks/464.f60ecfb6c72ec733.js +1 -0
  69. package/dist/web/_next/static/chunks/4912.1ab85b0ebf52a3e0.js +1 -0
  70. package/dist/web/_next/static/chunks/4982.bbbd303d665de4f0.js +1 -0
  71. package/dist/web/_next/static/chunks/4fecf3c3.e14d65bd1dce80cf.js +1 -0
  72. package/dist/web/_next/static/chunks/5052.dc8c36742419eed5.js +1 -0
  73. package/dist/web/_next/static/chunks/{7496.17282033df0e8794.js → 5115.fbe164892bfd6fa4.js} +1 -1
  74. package/dist/web/_next/static/chunks/5120.b4aadb89d4fb4f65.js +1 -0
  75. package/dist/web/_next/static/chunks/5448.1c4e0b719af53b3f.js +1 -0
  76. package/dist/web/_next/static/chunks/5623.cc6818f4096ce4c2.js +1 -0
  77. package/dist/web/_next/static/chunks/5664.507fea1f6305067e.js +1 -0
  78. package/dist/web/_next/static/chunks/5706.be484c6a7bed3fde.js +1 -0
  79. package/dist/web/_next/static/chunks/6336.b09d0d920c7631eb.js +1 -0
  80. package/dist/web/_next/static/chunks/6364.5b0466f24f4ecf58.js +1 -0
  81. package/dist/web/_next/static/chunks/640.2c2baacde5197a77.js +1 -0
  82. package/dist/web/_next/static/chunks/6419.61399b0413b8bef0.js +1 -0
  83. package/dist/web/_next/static/chunks/642.b70763e1cfe9e45e.js +1 -0
  84. package/dist/web/_next/static/chunks/6554.0110334a71e72bbe.js +1 -0
  85. package/dist/web/_next/static/chunks/6688.4a6ac23ba061262b.js +1 -0
  86. package/dist/web/_next/static/chunks/6815.6537cc012ba16cca.js +1 -0
  87. package/dist/web/_next/static/chunks/6896.33fdeb4e682c2cab.js +1 -0
  88. package/dist/web/_next/static/chunks/6912.3416822e13b4bc03.js +1 -0
  89. package/dist/web/_next/static/chunks/6944.635230aa8cb23871.js +1 -0
  90. package/dist/web/_next/static/chunks/6964.35718884ad3375bc.js +1 -0
  91. package/dist/web/_next/static/chunks/6992.4b059bae2659231d.js +1 -0
  92. package/dist/web/_next/static/chunks/6996.7c41217972cabc3f.js +1 -0
  93. package/dist/web/_next/static/chunks/7024.8bc670b892a558bb.js +1 -0
  94. package/dist/web/_next/static/chunks/7040.e058d8f95c3c11e7.js +1 -0
  95. package/dist/web/_next/static/chunks/714.70bdf8b4550aa78f.js +1 -0
  96. package/dist/web/_next/static/chunks/7220.807613863ef39947.js +1 -0
  97. package/dist/web/_next/static/chunks/7250.7f1d45021e49d2fd.js +1 -0
  98. package/dist/web/_next/static/chunks/7290.7bceed706f7b6df5.js +1 -0
  99. package/dist/web/_next/static/chunks/7301.c60eb2ba8ae6b859.js +1 -0
  100. package/dist/web/_next/static/chunks/7328.021e5e45124e40de.js +1 -0
  101. package/dist/web/_next/static/chunks/7340.a5a75ee889c30b74.js +1 -0
  102. package/dist/web/_next/static/chunks/7443.c189418756727101.js +1 -0
  103. package/dist/web/_next/static/chunks/7484.c0e6bfca7b2fb65e.js +1 -0
  104. package/dist/web/_next/static/chunks/7496.e638a7286c17e438.js +1 -0
  105. package/dist/web/_next/static/chunks/7500-077d236acd9b9c50.js +1 -0
  106. package/dist/web/_next/static/chunks/7695.11ba99db589cb586.js +1 -0
  107. package/dist/web/_next/static/chunks/7764.e62333ee1d63a458.js +1 -0
  108. package/dist/web/_next/static/chunks/7921-ddb0291f25a2e486.js +1 -0
  109. package/dist/web/_next/static/chunks/80.df762af692aca107.js +1 -0
  110. package/dist/web/_next/static/chunks/8024.4bd0b5a7f26a0f7d.js +1 -0
  111. package/dist/web/_next/static/chunks/82b69429.c6dd4e5c5ac704f3.js +368 -0
  112. package/dist/web/_next/static/chunks/8360.371456f14873ee9f.js +1 -0
  113. package/dist/web/_next/static/chunks/8544.7c1fb012f9073eaa.js +1 -0
  114. package/dist/web/_next/static/chunks/8547.424f9970cc72775f.js +1 -0
  115. package/dist/web/_next/static/chunks/8584.9bf7e755a7c8c432.js +1 -0
  116. package/dist/web/_next/static/chunks/8616.8e05c4a20dcdf39d.js +1 -0
  117. package/dist/web/_next/static/chunks/8752.bf29293df3366e17.js +298 -0
  118. package/dist/web/_next/static/chunks/8800.3c7b01176e98160a.js +1 -0
  119. package/dist/web/_next/static/chunks/88b2132a.04b02968da05b8a6.js +1005 -0
  120. package/dist/web/_next/static/chunks/8924.49dd385ac101fb7e.js +1 -0
  121. package/dist/web/_next/static/chunks/896.eb46d6e001d25d0f.js +1 -0
  122. package/dist/web/_next/static/chunks/9003.3d5c7a418d0b858b.js +1 -0
  123. package/dist/web/_next/static/chunks/9067.394ff92d9ae542b3.js +1 -0
  124. package/dist/web/_next/static/chunks/9068.9662bb8fa5fdc637.js +1 -0
  125. package/dist/web/_next/static/chunks/9178.a7631bd283f2a69c.js +1 -0
  126. package/dist/web/_next/static/chunks/9190.e3a90b1a9ed21668.js +1 -0
  127. package/dist/web/_next/static/chunks/9296.59fcfc8261a4c6bd.js +1 -0
  128. package/dist/web/_next/static/chunks/9312.e1fb4089a122d3d3.js +1 -0
  129. package/dist/web/_next/static/chunks/9348.022486b05b882739.js +1 -0
  130. package/dist/web/_next/static/chunks/948.132a0571d85c8b01.js +1 -0
  131. package/dist/web/_next/static/chunks/951.43a4ba54b1d1ff4e.js +3 -0
  132. package/dist/web/_next/static/chunks/9544.acc06fe34aa32c5c.js +7 -0
  133. package/dist/web/_next/static/chunks/9591.d205941f0062de24.js +1 -0
  134. package/dist/web/_next/static/chunks/9628.d8954a2bd28b85a6.js +1 -0
  135. package/dist/web/_next/static/chunks/9636.35df6241125f8513.js +1 -0
  136. package/dist/web/_next/static/chunks/9658.cdecb568f615e4c9.js +782 -0
  137. package/dist/web/_next/static/chunks/9672.b379566a8bfcd947.js +1 -0
  138. package/dist/web/_next/static/chunks/9680.d10b204d08ca3a62.js +1 -0
  139. package/dist/web/_next/static/chunks/9728.1d4cb6c68bd55f44.js +1 -0
  140. package/dist/web/_next/static/chunks/9747.80f474bcd4654c6c.js +1 -0
  141. package/dist/web/_next/static/chunks/9784.c9938b7e977e14eb.js +1 -0
  142. package/dist/web/_next/static/chunks/9812.024424a52730b057.js +1 -0
  143. package/dist/web/_next/static/chunks/9888.ce925cd415b672ef.js +1 -0
  144. package/dist/web/_next/static/chunks/{9891.91a2c59fd073fd48.js → 9891.a97db7c8f05693d1.js} +1 -1
  145. package/dist/web/_next/static/chunks/9904.a3d2f8569d7355ab.js +1 -0
  146. package/dist/web/_next/static/chunks/992.8470b96c23472686.js +1 -0
  147. package/dist/web/_next/static/chunks/9924.03252dda78c705c3.js +1 -0
  148. package/dist/web/_next/static/chunks/9968.3d45ff9183e8b07b.js +1 -0
  149. package/dist/web/_next/static/chunks/app/_not-found/page-23c6c0396966da29.js +1 -0
  150. package/dist/web/_next/static/chunks/app/defaults/page-4e5be923763ba3d9.js +1 -0
  151. package/dist/web/_next/static/chunks/app/layout-678acf830096ce90.js +1 -0
  152. package/dist/web/_next/static/chunks/app/page-be5c3849591d8c11.js +1 -0
  153. package/dist/web/_next/static/chunks/app/settings/page-b39878dce98ded94.js +1 -0
  154. package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +1 -0
  155. package/dist/web/_next/static/chunks/{main-app-f747f0f5ddb4213b.js → main-app-d23441ca81b3a063.js} +1 -1
  156. package/dist/web/_next/static/chunks/webpack-b26d4d956feb6e65.js +1 -0
  157. package/dist/web/_next/static/css/2de713eca93a7750.css +3 -0
  158. package/dist/web/_next/static/css/4bfdd3ebb3d1a180.css +1 -0
  159. package/dist/web/_next/static/css/51bfff1122e9f34d.css +1 -0
  160. package/dist/web/_next/static/css/73368887921d70d9.css +1 -0
  161. package/dist/web/_next/static/media/codicon.5ce2572b.ttf +0 -0
  162. package/dist/web/_next/static/media/editorWebWorkerMain.828b206c.js +1 -0
  163. package/dist/web/defaults.html +3 -3
  164. package/dist/web/defaults.txt +9 -9
  165. package/dist/web/index.html +4 -4
  166. package/dist/web/index.txt +9 -9
  167. package/dist/web/settings.html +14 -0
  168. package/dist/web/settings.txt +25 -0
  169. package/dist/web/system.html +3 -3
  170. package/dist/web/system.txt +9 -9
  171. package/dist/web/third-party-notices.txt +5966 -0
  172. package/package.json +157 -151
  173. package/prompts/lead1.md +140 -116
  174. package/prompts/level1.md +574 -574
  175. package/prompts/review1.md +287 -287
  176. package/dist/src/context/desktopDir.js +0 -44
  177. package/dist/web/_next/static/WuIGWiKKh_ESR3KwzsLZF/_buildManifest.js +0 -1
  178. package/dist/web/_next/static/chunks/1077.ae2fd686ef05572e.js +0 -1
  179. package/dist/web/_next/static/chunks/1548.bd558d3f2c8df4af.js +0 -1
  180. package/dist/web/_next/static/chunks/2163.b41334711ddcceff.js +0 -1
  181. package/dist/web/_next/static/chunks/714.cb77983f9be215c9.js +0 -1
  182. package/dist/web/_next/static/chunks/7220.072a60cd9d60220a.js +0 -1
  183. package/dist/web/_next/static/chunks/7500-f90e2ae7061e351d.js +0 -1
  184. package/dist/web/_next/static/chunks/7921-54dae769aa8bae96.js +0 -1
  185. package/dist/web/_next/static/chunks/8547.0a9997b67008c706.js +0 -1
  186. package/dist/web/_next/static/chunks/8584.9d5d6c09b0375015.js +0 -1
  187. package/dist/web/_next/static/chunks/9067.832c4761a991f2c2.js +0 -1
  188. package/dist/web/_next/static/chunks/9591.fabd60bd0d10341c.js +0 -1
  189. package/dist/web/_next/static/chunks/9747.c8d4ba56c9eef95f.js +0 -1
  190. package/dist/web/_next/static/chunks/app/_not-found/page-1264c0db9665169c.js +0 -1
  191. package/dist/web/_next/static/chunks/app/defaults/page-a1f90fe37e302928.js +0 -1
  192. package/dist/web/_next/static/chunks/app/layout-46efb208d7c88648.js +0 -1
  193. package/dist/web/_next/static/chunks/app/page-57787f15774d76b8.js +0 -1
  194. package/dist/web/_next/static/chunks/app/system/page-825f53f14d16033d.js +0 -1
  195. package/dist/web/_next/static/chunks/webpack-cb74fa884b8af278.js +0 -1
  196. package/dist/web/_next/static/css/d3398f485b2a9075.css +0 -1
  197. /package/dist/web/_next/static/{WuIGWiKKh_ESR3KwzsLZF → L-h3cKqABsuAzPqNkvLAP}/_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);
@@ -275,6 +288,8 @@ let OperatorController = class OperatorController {
275
288
  ...(typeof body.lang === 'string' && /^[a-z]{2,3}$/.test(body.lang) ? { lang: body.lang } : {}),
276
289
  ...(body.planMode === true ? { planMode: true } : {}),
277
290
  ...(typeof body.review === 'boolean' ? { review: body.review } : {}),
291
+ // The review's model, chosen beside the box (2026-10-21); left out, Settings' review model.
292
+ ...(typeof body.reviewModel === 'string' && body.reviewModel.trim() ? { reviewModel: body.reviewModel } : {}),
278
293
  // Two chats, for a new conversation: a lead that directs and a worker that carries out (2026-10-20).
279
294
  ...(body.lead === true ? { lead: true } : {}),
280
295
  ...(typeof body.workerModel === 'string' && body.workerModel.trim() ? { workerModel: body.workerModel } : {}),
@@ -589,12 +604,26 @@ __decorate([
589
604
  __metadata("design:paramtypes", [Object]),
590
605
  __metadata("design:returntype", Promise)
591
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);
592
614
  __decorate([
593
615
  Get('workspace/git'),
594
616
  __metadata("design:type", Function),
595
617
  __metadata("design:paramtypes", []),
596
618
  __metadata("design:returntype", Promise)
597
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);
598
627
  __decorate([
599
628
  Get('workspace/git/commit'),
600
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';
@@ -248,7 +248,8 @@ let OperatorService = class OperatorService {
248
248
  async listSessions() {
249
249
  await this.init();
250
250
  const all = await this.store.listSessions();
251
- return all.map((s) => ({ ...s, running: this.running.has(s.id), paused: this.running.get(s.id)?.hold.held ?? false }));
251
+ // The pauses of the run going on, for the page to take them off the minutes it shows (2026-10-21).
252
+ return all.map((s) => ({ ...s, running: this.running.has(s.id), paused: this.running.get(s.id)?.hold.held ?? false, ...this.pausesOf(s.id) }));
252
253
  }
253
254
  async getSession(id) {
254
255
  await this.init();
@@ -256,7 +257,12 @@ let OperatorService = class OperatorService {
256
257
  if (!s)
257
258
  return null;
258
259
  const pending = [...this.waiting.values()].filter((w) => w.approval.sessionId === id).map((w) => w.approval);
259
- return { ...s, running: this.running.has(id), paused: this.running.get(id)?.hold.held ?? false, pending, runMode: this.running.get(id)?.mode };
260
+ return { ...s, running: this.running.has(id), paused: this.running.get(id)?.hold.held ?? false, ...this.pausesOf(id), pending, runMode: this.running.get(id)?.mode };
261
+ }
262
+ /** The pauses of the run going on in a session, from "Pause" to "Continue"; none when nothing runs or it was never paused. */
263
+ pausesOf(id) {
264
+ const pauses = this.running.get(id)?.hold.pauses ?? [];
265
+ return pauses.length > 0 ? { pauses } : {};
260
266
  }
261
267
  async updateSession(id, patch) {
262
268
  await this.init();
@@ -1072,6 +1078,13 @@ let OperatorService = class OperatorService {
1072
1078
  throw new Error(ws.problem ?? 'No project folder is open.');
1073
1079
  return await workspaceGit(ws.dir);
1074
1080
  }
1081
+ /** Everything the branch changed against a base, as a pull request shows it (see `branchChanges`). Read-only. */
1082
+ async workspaceBranch(base) {
1083
+ const ws = await this.workspace();
1084
+ if (!ws.ok)
1085
+ throw new Error(ws.problem ?? 'No project folder is open.');
1086
+ return await branchChanges(ws.dir, base);
1087
+ }
1075
1088
  async workspaceCommit(sha) {
1076
1089
  const ws = await this.workspace();
1077
1090
  if (!ws.ok)
@@ -1163,7 +1176,10 @@ let OperatorService = class OperatorService {
1163
1176
  * says which. A second conversation checks the work when it says it is done, and sends back what it finds; it
1164
1177
  * was off for the chat from 2026-10-17. Asked for without the box — the API on its own, a script — it stays off.
1165
1178
  */
1166
- s.review = { enabled: input.review === true, model: '' };
1179
+ s.review = { enabled: input.review === true, model: input.reviewModel?.trim() ?? '' };
1180
+ // The review's model chosen beside the box (2026-10-21) is the operator's word, as the work's is.
1181
+ if (s.review.model)
1182
+ s.reviewModelSource = 'operator';
1167
1183
  // Plan mode as chosen under the box (2026-10-20, "as in Claude Code"): the plan first, approved by the operator.
1168
1184
  s.planMode = input.planMode ? 'approve' : 'off';
1169
1185
  /*
@@ -2101,10 +2117,55 @@ let OperatorService = class OperatorService {
2101
2117
  async browseFolder(start) {
2102
2118
  return await pickFolder(start);
2103
2119
  }
2120
+ /**
2121
+ * The bot's folder chosen on the System page (operator, 2026-10-22): `dir`, or `null` for the default; with `copy`,
2122
+ * what is in the folder now goes there too. Read at the next start; refused while work goes on, for a clone, or for
2123
+ * a folder that cannot be the bot's.
2124
+ */
2125
+ async setHome(dir, copy) {
2126
+ const layout = this.layout;
2127
+ if (layout.mode !== 'package')
2128
+ 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.');
2129
+ if (layout.homeFrom === 'env')
2130
+ throw new Error(`COP_HOME places the bot's folder (${layout.homeDir}); change or remove it where it is set.`);
2131
+ if (this.running.size > 0)
2132
+ throw new Error('Work is going on: stop it, or let it end, before moving the bot\'s folder.');
2133
+ if (dir !== null) {
2134
+ const refused = homeRefusal(dir, layout);
2135
+ if (refused)
2136
+ throw new Error(refused);
2137
+ }
2138
+ if (copy) {
2139
+ // Its files are in use while its window is open: closed first, as another run would close it.
2140
+ await this.closeChatWindow('the bot\'s folder is being copied');
2141
+ const cfg = await this.settings.load();
2142
+ const holders = findEdgeUsingProfile(cfg.resolved.profileDir);
2143
+ if (Array.isArray(holders) && holders.length > 0)
2144
+ 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.`);
2145
+ }
2146
+ /*
2147
+ * A profile the settings name in the folder left behind would stay there: it follows the folder instead. Before the
2148
+ * copy, so the settings copied over say so too; for this process it is the same folder, the default one.
2149
+ */
2150
+ await this.settings.update((raw) => {
2151
+ const copilot = raw.copilot ?? {};
2152
+ if (typeof copilot.profileDir === 'string' && resolve(copilot.profileDir).toLowerCase() === resolve(join(layout.homeDir, 'edge-profile')).toLowerCase()) {
2153
+ const { profileDir: _gone, ...rest } = copilot;
2154
+ return { ...raw, copilot: rest };
2155
+ }
2156
+ return raw;
2157
+ });
2158
+ const chosen = chooseHome(layout, dir, copy);
2159
+ console.log(`[home] the bot's folder will be ${chosen.home} from its next start${chosen.copied.length ? ` (copied: ${chosen.copied.join(', ')})` : ''}`);
2160
+ return { ...chosen, restart: true };
2161
+ }
2104
2162
  async doctor() {
2105
2163
  const cfg = await this.settings.load();
2106
2164
  const edge = ['C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', 'C:/Program Files/Microsoft/Edge/Application/msedge.exe'].find((p) => existsSync(p));
2107
2165
  const holders = findEdgeUsingProfile(cfg.resolved.profileDir);
2166
+ // Whose Edge it is: the bot's own — a run's, or its chat window kept open between messages — or another's.
2167
+ const holder = profileHolder(holders, process.pid);
2168
+ const layout = this.layout;
2108
2169
  return {
2109
2170
  // Which copilot-operator this is: `cop --version` without a terminal.
2110
2171
  version: botVersion(),
@@ -2114,13 +2175,20 @@ let OperatorService = class OperatorService {
2114
2175
  profileExists: existsSync(cfg.resolved.profileDir),
2115
2176
  profileHeldBy: Array.isArray(holders) ? holders.map((h) => h.pid) : 'unknown',
2116
2177
  /*
2117
- * Whether the bot itself is what holds the profile. While a run is going, Edge is open
2118
- * on that profile *by the runner*, and the warning "close this Edge window, a run would
2119
- * fail" was shown in exactly the moment it was false. The page says which it is.
2178
+ * Whose Edge holds the profile (2026-10-22). While a run is going, Edge is open on it by the runner; between
2179
+ * messages the chat's window stays open by the bot too, and the warning "close this Edge window, a run would
2180
+ * fail" was shown then, when it was false: it counted only runs. An Edge the bot's API started is its own.
2120
2181
  */
2182
+ profileHolder: holder === 'own' ? (this.running.size > 0 ? 'own-run' : 'own-window') : holder,
2121
2183
  botRunning: this.running.size > 0,
2122
- desktop: resolveDesktopDir(),
2123
- desktopSynced: desktopIsSynced(),
2184
+ // The bot's folder (2026-10-22): where it is, where it would be by default, and what was chosen for the next start.
2185
+ install: layout.mode,
2186
+ home: layout.homeDir,
2187
+ homeFrom: layout.homeFrom,
2188
+ homeDefault: layout.mode === 'package' ? defaultHome() : null,
2189
+ homeNext: layout.mode === 'package' && layout.homeFrom !== 'env' ? (chosenHome() ?? defaultHome()) : null,
2190
+ homeMovedFrom: movedFrom(layout.homeDir),
2191
+ settingsFile: join(this.dataDir, 'settings.json'),
2124
2192
  cwd: cfg.resolved.cwd,
2125
2193
  runsDir: cfg.resolved.runsDir,
2126
2194
  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
+ }