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
@@ -6,7 +6,9 @@
6
6
  * Next.js dev server of its own.
7
7
  * package `npm i -D copilot-operator` in a project, started with `npx cop start`. The code
8
8
  * is in `node_modules`, which `npm install` rewrites whenever it likes, so nothing of
9
- * the operator's may live there: the records go to `<project>/.copilot-operator/`,
9
+ * the operator's may live there: the records go to the bot's own folder —
10
+ * `%LOCALAPPDATA%\copilot-operator` unless the operator chose another on the System
11
+ * page, or COP_HOME names one (2026-10-22; until then `<project>/.copilot-operator/`) —
10
12
  * and the UI is the prebuilt one shipped in the package, served by the API itself.
11
13
  *
12
14
  * Which one is decided by where the code is: inside a `node_modules` folder is a package. The
@@ -20,11 +22,37 @@
20
22
  * data folder or the runs folder asks here instead, so the two installs cannot disagree about
21
23
  * where a thing is.
22
24
  */
23
- import { existsSync } from 'node:fs';
24
- import { basename, dirname, join, resolve, sep } from 'node:path';
25
+ import { existsSync, readFileSync } from 'node:fs';
26
+ import { homedir } from 'node:os';
27
+ import { basename, dirname, isAbsolute, join, resolve, sep } from 'node:path';
25
28
  import { botRootDir } from '../exec/workDir.js';
26
- /** The name of the records folder a package keeps inside the project. */
29
+ /**
30
+ * The name of the records folder a package kept inside the project until 2026-10-22 — and still keeps there when the
31
+ * operator chooses that folder. See `defaultHome`.
32
+ */
27
33
  export const HOME_FOLDER = '.copilot-operator';
34
+ /**
35
+ * Where a package keeps its records unless the operator chose another folder (operator, 2026-10-22: "I do not want a
36
+ * .copilot-operator folder in the project's folder unless I set it there"): the user's own local application data,
37
+ * `%LOCALAPPDATA%\copilot-operator`, where the bot's Edge profile already was. Not the folder it was started from —
38
+ * a global install started from C:\ kept everything in C:\.copilot-operator.
39
+ */
40
+ export function defaultHome(env = process.env) {
41
+ const local = env.LOCALAPPDATA?.trim() || join(env.USERPROFILE?.trim() || homedir(), 'AppData', 'Local');
42
+ return join(local, 'copilot-operator');
43
+ }
44
+ /** The file in the default home that names the folder the operator chose instead: `{ "home": "D:\\bot" }`. */
45
+ export const HOME_CHOICE_FILE = 'location.json';
46
+ /** The folder the operator chose for the records, when they chose one (System → the bot's folder). */
47
+ export function chosenHome(env = process.env) {
48
+ try {
49
+ const value = JSON.parse(readFileSync(join(defaultHome(env), HOME_CHOICE_FILE), 'utf8'));
50
+ return typeof value.home === 'string' && isAbsolute(value.home.trim()) ? resolve(value.home.trim()) : null;
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
28
56
  /** The project a package install belongs to: the folder holding the `node_modules` the code sits in. */
29
57
  function projectOfPackage(botRoot) {
30
58
  const parent = dirname(resolve(botRoot));
@@ -49,7 +77,11 @@ export function installLayout(env = process.env, cwd = process.cwd(), botRoot =
49
77
  // was started. Checked by folder, so a start from a subfolder of the project still finds it.
50
78
  const owner = isInside(cwd, packaged) ? packaged : cwd;
51
79
  const projectRoot = resolve(env.COP_PROJECT_ROOT ?? owner);
52
- const homeDir = join(projectRoot, HOME_FOLDER);
80
+ // The operator's own folder by default; another they chose; COP_HOME over both (2026-10-22).
81
+ const fromEnv = env.COP_HOME?.trim() ?? '';
82
+ const chosen = fromEnv ? null : chosenHome(env);
83
+ const homeFrom = fromEnv ? 'env' : chosen ? 'chosen' : 'default';
84
+ const homeDir = resolve(fromEnv || chosen || defaultHome(env));
53
85
  const shippedWeb = join(botRoot, 'dist', 'web');
54
86
  return {
55
87
  mode: 'package',
@@ -57,6 +89,8 @@ export function installLayout(env = process.env, cwd = process.cwd(), botRoot =
57
89
  promptsDir,
58
90
  projectRoot,
59
91
  homeDir,
92
+ homeFrom,
93
+ legacyHomeDir: join(projectRoot, HOME_FOLDER),
60
94
  dataDir: resolve(env.COP_DATA_DIR ?? join(homeDir, 'data')),
61
95
  runsDir: join(homeDir, 'runs'),
62
96
  webDir: existsSync(join(shippedWeb, 'index.html')) ? shippedWeb : null,
@@ -69,6 +103,7 @@ export function installLayout(env = process.env, cwd = process.cwd(), botRoot =
69
103
  promptsDir,
70
104
  projectRoot,
71
105
  homeDir: projectRoot,
106
+ homeFrom: 'checkout',
72
107
  dataDir: resolve(env.COP_DATA_DIR ?? join(projectRoot, 'data')),
73
108
  runsDir: join(projectRoot, 'runs'),
74
109
  /*
@@ -382,7 +382,11 @@ export const RunConfigSchema = z.object({
382
382
  maxIterations: z.number().int().positive().default(60),
383
383
  maxRunMinutes: z.number().int().positive().default(240),
384
384
  maxFormatRetries: z.number().int().nonnegative().default(2),
385
- maxMessageChars: z.number().int().positive().default(100_000),
385
+ /*
386
+ * The most characters of one message sent to the chat as text (operator, 2026-10-22: 120 000 by default, set in
387
+ * Settings → Execution): a longer one goes as its beginning with the whole of it attached (`limitsMessageLength`).
388
+ */
389
+ maxMessageChars: z.number().int().min(1000).max(1_000_000).default(120_000),
386
390
  /**
387
391
  * How many times a task may be sent back because its checks did not pass.
388
392
  *
@@ -52,6 +52,7 @@
52
52
  import { existsSync } from 'node:fs';
53
53
  import { dirname, join, resolve } from 'node:path';
54
54
  import { botRootDir } from './workDir.js';
55
+ import { chosenHome, defaultHome, installLayout } from '../config/layout.js';
55
56
  const FETCHERS = [
56
57
  { name: 'Invoke-WebRequest', pattern: /\b(Invoke-WebRequest|iwr)\b/i },
57
58
  { name: 'Invoke-RestMethod', pattern: /\b(Invoke-RestMethod|irm)\b/i },
@@ -279,13 +280,24 @@ export function networkFetchReason(command, cwd) {
279
280
  * `127.0.0.1:4000` and answer its own held download. The token is no longer passed (`stepEnv.ts`);
280
281
  * this refuses the attempt as well, so a step that goes looking gets a reason instead of a 401.
281
282
  */
282
- export function botSelfRefusal(command, ports = botPorts(), root = botRootDir()) {
283
+ export function botSelfRefusal(command, ports = botPorts(), root = botRootDir(), homes = botHomeFolders()) {
283
284
  const port = `(?:${ports.map((p) => String(Math.trunc(p))).join('|')})`;
284
285
  const host = String.raw `(?:localhost|127(?:\.\d{1,3}){3}|\[::1\]|0\.0\.0\.0|::1)`;
285
286
  // The folders the bot keeps its records in, by path: its data, its runs, its update backups.
286
- const folded = command.replace(/\//g, '\\').toLowerCase();
287
- const own = root.replace(/\//g, '\\').toLowerCase().replace(/\\+$/, '');
287
+ const folded = foldPath(command);
288
+ const own = foldPath(root).replace(/\\+$/, '');
288
289
  const reachesRecords = ['data', 'runs', 'data-backups'].some((d) => folded.includes(`${own}\\${d}`));
290
+ /*
291
+ * The bot's own folder (2026-10-22): its settings, conversations, logs, its key and its Edge profile, kept in the
292
+ * user's local application data by default and wherever the operator chose otherwise — by its path, and the default
293
+ * one by the variables that spell it as well.
294
+ */
295
+ const reachesHome = homes.some((h) => namesFolder(folded, foldPath(h).replace(/\\+$/, ''))) ||
296
+ (/appdata|localapplicationdata/i.test(command) && /(?:^|[\s'"`=(\\/,;])copilot-operator(?![\w-])/i.test(command));
297
+ if (reachesHome) {
298
+ return ("refused: this reaches the bot's own folder — its settings, conversations, logs, its key and its Edge profile. " +
299
+ 'The bot that runs the task is not part of the work; leave that folder alone.');
300
+ }
289
301
  /*
290
302
  * Installed from npm, the bot is a dependency of the very project it works on: its code sits in
291
303
  * the project's `node_modules`, its records in the project's `.copilot-operator`, and both are
@@ -306,6 +318,41 @@ export function botSelfRefusal(command, ports = botPorts(), root = botRootDir())
306
318
  }
307
319
  return null;
308
320
  }
321
+ /** A path or a command as compared here: one backslash for any run of slashes, lower case. */
322
+ function foldPath(text) {
323
+ return text.replace(/[\\/]+/g, '\\').toLowerCase();
324
+ }
325
+ /** Whether `folded` names `folder` itself or something in it — not a folder whose name merely starts the same. */
326
+ function namesFolder(folded, folder) {
327
+ if (!folder)
328
+ return false;
329
+ for (let i = folded.indexOf(folder); i >= 0; i = folded.indexOf(folder, i + 1)) {
330
+ const next = folded[i + folder.length];
331
+ if (next === undefined || /[\\\s'"`;|),]/.test(next))
332
+ return true;
333
+ }
334
+ return false;
335
+ }
336
+ /** The bot's folders as this process found them when it started: a folder chosen since takes effect at the next start. */
337
+ const homesAtStart = (() => {
338
+ try {
339
+ const layout = installLayout();
340
+ // A clone's folder is the clone, whose records are found by `root` above; its data may be elsewhere (COP_DATA_DIR).
341
+ return layout.mode === 'package' ? [layout.homeDir, layout.dataDir] : [layout.dataDir];
342
+ }
343
+ catch {
344
+ return [];
345
+ }
346
+ })();
347
+ /**
348
+ * The folders that hold the bot's records apart from its code: its folder now, the one its next start will use, and
349
+ * the default one — which holds a clone's Edge profile and the pointer to a chosen folder, so a step that rewrote it
350
+ * would move the bot's records where it likes.
351
+ */
352
+ export function botHomeFolders(env = process.env) {
353
+ const next = chosenHome(env);
354
+ return [...new Set([...homesAtStart, defaultHome(env), ...(next ? [next] : [])])];
355
+ }
309
356
  /** The ports the bot's API and web page listen on. */
310
357
  export function botPorts(env = process.env) {
311
358
  const api = Number(env.COP_API_PORT ?? 4000);
@@ -12,6 +12,12 @@
12
12
  export class Hold {
13
13
  paused = false;
14
14
  waiting = [];
15
+ /**
16
+ * Each pause, from "Pause" pressed to "Continue" (operator, 2026-10-21: "when paused, the time must stop being
17
+ * measured"): the clock stops at the press, not at the point the work reaches a little later, and the time it was
18
+ * paused is taken off a task's minutes — its limit, and the minutes the page shows.
19
+ */
20
+ spans = [];
15
21
  /** Whether the operator has asked the task to hold. */
16
22
  get held() {
17
23
  return this.paused;
@@ -21,6 +27,7 @@ export class Hold {
21
27
  if (this.paused)
22
28
  return false;
23
29
  this.paused = true;
30
+ this.spans.push({ from: Date.now() });
24
31
  return true;
25
32
  }
26
33
  /** Lets the task go on. False when it was not held. */
@@ -28,10 +35,21 @@ export class Hold {
28
35
  if (!this.paused)
29
36
  return false;
30
37
  this.paused = false;
38
+ const open = this.spans.at(-1);
39
+ if (open && open.to === undefined)
40
+ open.to = Date.now();
31
41
  for (const go of this.waiting.splice(0))
32
42
  go();
33
43
  return true;
34
44
  }
45
+ /** How long the work was paused since `since` (ms), the pause going on counted to now. */
46
+ pausedSince(since, now = Date.now()) {
47
+ return pausedWithin(this.spans, since, now);
48
+ }
49
+ /** The pauses, for the page to take them off the minutes it shows. */
50
+ get pauses() {
51
+ return this.spans.map((s) => ({ from: new Date(s.from).toISOString(), ...(s.to !== undefined ? { to: new Date(s.to).toISOString() } : {}) }));
52
+ }
35
53
  /** Resolves at once when not held; otherwise when the operator continues, or the run is stopped. */
36
54
  until(signal) {
37
55
  if (!this.paused || signal?.aborted)
@@ -47,3 +65,10 @@ export class Hold {
47
65
  });
48
66
  }
49
67
  }
68
+ /** The time of `spans` that falls between `since` and `now`, a span with no end lasting to `now`. */
69
+ export function pausedWithin(spans, since, now) {
70
+ let ms = 0;
71
+ for (const s of spans)
72
+ ms += Math.max(0, Math.min(s.to ?? now, now) - Math.max(s.from, since));
73
+ return ms;
74
+ }
@@ -0,0 +1,88 @@
1
+ /** A title as two of them are compared: case, punctuation, a leading number and spacing set aside. */
2
+ export function titleKey(title) {
3
+ return title
4
+ .toLowerCase()
5
+ .replace(/^\s*(?:subtask\s*)?\d+\s*[.):-]\s*/, '')
6
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
7
+ .trim();
8
+ }
9
+ /** The same subtask, said the same or nearly: one title contains the other, once they are both long enough to tell. */
10
+ export function sameTitle(a, b) {
11
+ const x = titleKey(a);
12
+ const y = titleKey(b);
13
+ if (!x || !y)
14
+ return false;
15
+ if (x === y)
16
+ return true;
17
+ const [short, long] = x.length <= y.length ? [x, y] : [y, x];
18
+ return short.length >= 6 && long.includes(short);
19
+ }
20
+ /**
21
+ * The list after a reply of the lead's. `todo` is the list the reply sent, if it sent one; `giving` the subtask it gives
22
+ * now, with the number it will have. With no list in the reply, the one before stands (a question, the result). The
23
+ * change is returned when the list is new or its version went up.
24
+ */
25
+ export function nextLedger(before, todo, at, giving) {
26
+ if (!todo || todo.length === 0)
27
+ return { ledger: before };
28
+ // One entry a title, the first one as sent.
29
+ const items = [];
30
+ for (const t of todo) {
31
+ if (items.some((i) => titleKey(i.title) === titleKey(t.title)))
32
+ continue;
33
+ const known = before?.items.find((i) => titleKey(i.title) === titleKey(t.title));
34
+ items.push({ title: t.title.trim(), status: t.status, ...(t.phase ? { phase: t.phase } : {}), ...(known?.n ? { n: known.n } : {}) });
35
+ }
36
+ if (giving) {
37
+ const running = items.filter((i) => i.status === 'running');
38
+ let mine = items.find((i) => i.status !== 'done' && sameTitle(i.title, giving.title)) ?? (running.length === 1 ? running[0] : undefined);
39
+ if (!mine) {
40
+ mine = { title: giving.title.trim(), status: 'running' };
41
+ const firstPlanned = items.findIndex((i) => i.status === 'planned');
42
+ items.splice(firstPlanned >= 0 ? firstPlanned : items.length, 0, mine);
43
+ }
44
+ for (const i of items)
45
+ if (i.status === 'running' && i !== mine)
46
+ i.status = 'planned';
47
+ mine.status = 'running';
48
+ mine.n = giving.n;
49
+ }
50
+ const keys = items.map((i) => titleKey(i.title));
51
+ const was = before?.items.map((i) => titleKey(i.title)) ?? [];
52
+ const added = items.filter((i) => !was.includes(titleKey(i.title))).map((i) => i.title);
53
+ const removed = (before?.items ?? []).filter((i) => !keys.includes(titleKey(i.title))).map((i) => i.title);
54
+ // The ones in both, in the order of each: another order is another plan.
55
+ const common = keys.filter((k) => was.includes(k));
56
+ const reordered = common.join('\n') !== was.filter((k) => keys.includes(k)).join('\n');
57
+ const changed = !before || added.length > 0 || removed.length > 0 || reordered;
58
+ const revision = before ? before.revision + (changed ? 1 : 0) : 1;
59
+ const ledger = {
60
+ revision,
61
+ items,
62
+ at,
63
+ ...(changed ? (added.length > 0 ? { added } : {}) : before?.added ? { added: before.added } : {}),
64
+ ...(changed ? (removed.length > 0 ? { removed } : {}) : before?.removed ? { removed: before.removed } : {}),
65
+ };
66
+ return { ledger, ...(changed ? { change: { revision, added: added.length, removed: removed.length, total: items.length } } : {}) };
67
+ }
68
+ /** The list at the end of the work: the one running is done when the lead delivered, blocked when it could not. */
69
+ export function closeLedger(ledger, how) {
70
+ if (!ledger)
71
+ return ledger;
72
+ return { ...ledger, items: ledger.items.map((i) => (i.status === 'running' ? { ...i, status: how } : i)) };
73
+ }
74
+ /** The counts the chat and the lead are given: where the work is against the plan, and the limit apart. */
75
+ export function ledgerCounts(ledger) {
76
+ const of = (s) => ledger.items.filter((i) => i.status === s).length;
77
+ const at = ledger.items.findIndex((i) => i.status === 'running');
78
+ return { total: ledger.items.length, done: of('done'), running: of('running'), planned: of('planned'), stuck: of('blocked') + of('failed'), current: at >= 0 ? at + 1 : 0 };
79
+ }
80
+ /** The list as the lead is shown it with a report: one line a subtask, its status, its phase. */
81
+ export function describeLedger(ledger, given, max) {
82
+ const c = ledgerCounts(ledger);
83
+ return [
84
+ `Your list of subtasks (version ${ledger.revision}): ${c.done} done, ${c.running} running, ${c.planned} planned${c.stuck > 0 ? `, ${c.stuck} blocked or failed` : ''}. Subtasks given so far: ${given}; at most ${max} may be given.`,
85
+ ...ledger.items.map((i, k) => `${k + 1}. [${i.status}] ${i.title}${i.phase ? ` — ${i.phase}` : ''}`),
86
+ 'Send the whole list again with your next subtask or plan: mark the one just reported "done" if you accept its report, "blocked" or "failed" if not; add what it showed is needed, drop what is not.',
87
+ ].join('\n');
88
+ }
@@ -31,7 +31,8 @@ import { operatorNotesSection, whyItStopped } from '../session/compose.js';
31
31
  import { describeDeviations } from '../protocol/replySchema.js';
32
32
  import { leadFormatErrorMessage, parseLeadReply, UNDERSTANDING_FIRST } from '../protocol/leadSchema.js';
33
33
  import { describePlan, planFrom } from './planMode.js';
34
- import { applySessionModel, enterSessionConversation, holdsWhilePaused, runTask, Sink, speakFor, StoppedSend } from './taskRunner.js';
34
+ import { closeLedger, describeLedger, nextLedger } from './leadLedger.js';
35
+ import { applySessionModel, enterSessionConversation, holdsWhilePaused, limitsMessageLength, runTask, Sink, speakFor, StoppedSend } from './taskRunner.js';
35
36
  import { DEFAULT_VCS } from '../session/store.js';
36
37
  /** The assignment as the lead is given it: the operator's message, and what the runner tells it about the work. */
37
38
  export function assignmentMessage(task, n, facts, again) {
@@ -176,6 +177,8 @@ export async function runLeadTask(transport, session, task, deps) {
176
177
  t.iterations = copy.rounds.length;
177
178
  });
178
179
  };
180
+ // From here the message's minutes are counted, its pauses taken off (2026-10-21).
181
+ const leadStartedAt = Date.now();
179
182
  await setTask((t) => {
180
183
  t.status = 'running';
181
184
  t.runId = runId;
@@ -224,7 +227,12 @@ export async function runLeadTask(transport, session, task, deps) {
224
227
  sink.event('task-resumed', { heldMs: Date.now() - from, stopped }, stopped ? 'stopped while paused' : 'continued by the operator');
225
228
  return stopped;
226
229
  };
227
- const leadChat = holdsWhilePaused(transport, holdHere);
230
+ // No message to the lead longer than Settings allow as text: the rest goes attached (2026-10-22).
231
+ const leadChat = limitsMessageLength(holdsWhilePaused(transport, holdHere), {
232
+ max: cfg.limits.maxMessageChars,
233
+ dir: log.path('messages'),
234
+ onLong: ({ chars, max, file }) => sink.event('message-long', { chars, max, file, lead: true }, `a message to the lead of ${chars} characters is over the ${max} sent as text: its beginning is sent, the whole of it attached as ${file}`, 'warn'),
235
+ });
228
236
  let sent = 0;
229
237
  let replies = 0;
230
238
  /** One message to the lead, and its reply. */
@@ -289,6 +297,9 @@ export async function runLeadTask(transport, session, task, deps) {
289
297
  t.vcs = vcs;
290
298
  t.status = status;
291
299
  t.finishedAt = new Date().toISOString();
300
+ const held = deps.hold?.pausedSince(leadStartedAt) ?? 0;
301
+ if (held > 0)
302
+ t.pausedMs = held;
292
303
  t.summary = summary;
293
304
  t.reason = reason;
294
305
  t.logFile = 'task-log.txt';
@@ -368,6 +379,8 @@ export async function runLeadTask(transport, session, task, deps) {
368
379
  ...((t?.deviations?.length ?? 0) > 0 ? ['', describeDeviations(t.deviations)] : []),
369
380
  '',
370
381
  `Subtasks left: ${max - lead.subtasks} of ${max}.`,
382
+ // Its own list, as it sent it last, to send again with the next subtask (2026-10-21).
383
+ ...(lead.ledger ? ['', describeLedger(lead.ledger, lead.subtasks, max)] : []),
371
384
  'Reply in the lead\'s format: the next subtask, the plan, a question for the operator, or the result.',
372
385
  ].join('\n');
373
386
  };
@@ -514,6 +527,17 @@ export async function runLeadTask(transport, session, task, deps) {
514
527
  ...(r.notes ? { notes: r.notes } : {}),
515
528
  };
516
529
  lead.rounds.push(round);
530
+ // Its list of subtasks, as this reply sends it (2026-10-21); the subtask given now is the running one.
531
+ const giving = r.status === 'delegate' && r.subtask && lead.subtasks < max ? { title: r.subtask.title, n: lead.subtasks + 1 } : undefined;
532
+ const listed = nextLedger(lead.ledger, r.todo, round.at, giving);
533
+ lead.ledger = listed.ledger;
534
+ if (listed.change) {
535
+ round.ledger = listed.change;
536
+ const { revision, added, removed, total } = listed.change;
537
+ sink.event('lead-ledger', { round: round.n, ...listed.change }, revision === 1
538
+ ? `the lead's list: ${total} subtask(s)`
539
+ : `the lead's list changed (version ${revision}): ${total} subtask(s)${added > 0 ? `, ${added} new` : ''}${removed > 0 ? `, ${removed} dropped` : ''}${added === 0 && removed === 0 ? ', in another order' : ''}`);
540
+ }
517
541
  await saveLead();
518
542
  sink.event('lead-reply', { round: round.n, status: r.status }, `the lead: ${r.status}${r.subtask ? ` — ${r.subtask.title}` : ''}`);
519
543
  switch (r.status) {
@@ -581,9 +605,12 @@ export async function runLeadTask(transport, session, task, deps) {
581
605
  }
582
606
  case 'done': {
583
607
  lead.evidence = r.evidence;
608
+ // Delivered: the subtask it was on was accepted with it.
609
+ lead.ledger = closeLedger(lead.ledger, 'done');
584
610
  return await finish('done', undefined, r.answer);
585
611
  }
586
612
  case 'blocked': {
613
+ lead.ledger = closeLedger(lead.ledger, 'blocked');
587
614
  return await finish('blocked', `the lead could not take it further: ${r.needed ?? ''}`.trim(), r.summary);
588
615
  }
589
616
  }
@@ -261,8 +261,8 @@ export async function runReview(transport, session, task, deps) {
261
261
  // The machine's shells, when they are not what the contract's example assumes — the same note
262
262
  // the implementer's conversation opens with, for a conversation working to the same example.
263
263
  const machineNote = shellNote(undefined, defaultShell);
264
- let before = await transport.sendAndConfirm(machineNote ? `${contract}
265
-
264
+ let before = await transport.sendAndConfirm(machineNote ? `${contract}
265
+
266
266
  ${machineNote}` : contract);
267
267
  await transport.waitForReply(before);
268
268
  await pacer.throttleSend();
@@ -294,6 +294,36 @@ export function holdsWhilePaused(transport, hold) {
294
294
  },
295
295
  });
296
296
  }
297
+ /**
298
+ * The same chat, whose every message is at most `max` characters of text (operator, 2026-10-22: "the most characters
299
+ * the chat takes as text, not as an attached document, set in Settings; and a check that the messages made are not
300
+ * longer"). A longer one — the contract, a task's opening with its brief, a report, a review's — goes as its
301
+ * beginning, said to be only that, with the whole of it attached as a text file beside the files it already had;
302
+ * `onLong` is told of each. Like `holdsWhilePaused`, it holds every message the runner sends, from wherever.
303
+ */
304
+ export function limitsMessageLength(transport, opts) {
305
+ let n = 0;
306
+ return new Proxy(transport, {
307
+ get(target, key) {
308
+ if (key === 'sendAndConfirm') {
309
+ return async (text, attachments = []) => {
310
+ if (text.length <= opts.max)
311
+ return await target.sendAndConfirm(text, attachments);
312
+ n += 1;
313
+ await mkdir(opts.dir, { recursive: true });
314
+ const file = join(opts.dir, `message-${String(n).padStart(2, '0')}-in-full.txt`);
315
+ await writeFile(file, text, 'utf8');
316
+ const note = `\n\n[This message is ${text.length} characters long, more than the ${opts.max} sent as text: the whole of it is in the attached file ` +
317
+ `${basename(file)}. Read it there and answer it as a whole; what is above is only its beginning.]`;
318
+ opts.onLong?.({ chars: text.length, max: opts.max, file });
319
+ return await target.sendAndConfirm(`${text.slice(0, Math.max(0, opts.max - note.length))}${note}`, [...attachments, file]);
320
+ };
321
+ }
322
+ const value = Reflect.get(target, key, target);
323
+ return typeof value === 'function' ? value.bind(target) : value;
324
+ },
325
+ });
326
+ }
297
327
  /** One place that writes to the transcript, the console and the live stream at once. */
298
328
  export class Sink {
299
329
  log;
@@ -911,8 +941,12 @@ export async function runTask(transport, session, task, deps) {
911
941
  await store.updateTask(session.id, task.id, mutate);
912
942
  };
913
943
  const startedAt = Date.now();
914
- /** Moved on by the time the operator held the task paused: the limit is on the work, not on the pause. */
915
- let deadline = startedAt + cfg.limits.maxRunMinutes * 60_000;
944
+ /*
945
+ * The limit is on the work, not on the pause: the time from "Pause" pressed to "Continue" is taken off (2026-10-21:
946
+ * from the press, not from the point the work held at — a reply being written, a command running — a little later).
947
+ */
948
+ const pausedMs = () => deps.hold?.pausedSince(startedAt) ?? 0;
949
+ const pastDeadline = () => Date.now() - startedAt - pausedMs() > cfg.limits.maxRunMinutes * 60_000;
916
950
  /*
917
951
  * "Pause" (operator, 2026-10-20; see `Hold`): every message to the chat waits here while the task is paused, and
918
952
  * so does every command (the step loop below). True when the run was stopped while held.
@@ -925,13 +959,18 @@ export async function runTask(transport, session, task, deps) {
925
959
  sink.event('task-paused', { before }, before === 'message' ? 'paused by the operator: nothing more is sent to the chat until Continue' : 'paused by the operator: no other command runs until Continue');
926
960
  await hold.until(signal);
927
961
  const heldMs = Date.now() - from;
928
- deadline += heldMs;
929
962
  const stopped = !!signal?.aborted;
930
963
  const secs = Math.round(heldMs / 1000);
931
964
  sink.event('task-resumed', { before, heldMs, stopped }, stopped ? `stopped while paused, after ${secs} s` : `continued by the operator after ${secs} s paused; that time does not count against maxRunMinutes`);
932
965
  return stopped;
933
966
  };
934
967
  transport = holdsWhilePaused(transport, () => holdHere('message'));
968
+ // No message longer than Settings allow as text: the rest goes attached (2026-10-22, see `limitsMessageLength`).
969
+ transport = limitsMessageLength(transport, {
970
+ max: cfg.limits.maxMessageChars,
971
+ dir: log.path('messages'),
972
+ onLong: ({ chars, max, file }) => sink.event('message-long', { chars, max, file }, `a message of ${chars} characters is over the ${max} sent as text: its beginning is sent, the whole of it attached as ${file}`, 'warn'),
973
+ });
935
974
  let iterations = 0;
936
975
  /** What the model has declared it could not do as written, merged across every reply. */
937
976
  let deviations = [];
@@ -1258,6 +1297,9 @@ export async function runTask(transport, session, task, deps) {
1258
1297
  t.status = status;
1259
1298
  t.iterations = iterations;
1260
1299
  t.finishedAt = new Date().toISOString();
1300
+ const held = pausedMs();
1301
+ if (held > 0)
1302
+ t.pausedMs = held;
1261
1303
  t.summary = summary;
1262
1304
  t.reason = reason;
1263
1305
  t.finalReply = finalReply;
@@ -2448,7 +2490,7 @@ export async function runTask(transport, session, task, deps) {
2448
2490
  for (;;) {
2449
2491
  if (signal?.aborted)
2450
2492
  return await finish('aborted', 'stopped by the operator');
2451
- if (Date.now() > deadline) {
2493
+ if (pastDeadline()) {
2452
2494
  limitHit = { setting: 'maxRunMinutes', value: cfg.limits.maxRunMinutes };
2453
2495
  return await finish('limit-reached', `maxRunMinutes (${cfg.limits.maxRunMinutes}) reached`);
2454
2496
  }