copilot-operator 0.1.55 → 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.
- package/LICENSE +21 -21
- package/README.md +618 -609
- package/dist/src/api/folderPicker.js +22 -22
- package/dist/src/api/operator.controller.js +30 -3
- package/dist/src/api/operator.service.js +68 -9
- package/dist/src/api/security.js +1 -1
- package/dist/src/api/server.js +9 -1
- package/dist/src/api/settings.js +18 -4
- package/dist/src/cli.js +16 -15
- package/dist/src/config/home.js +109 -0
- package/dist/src/config/layout.js +40 -5
- package/dist/src/config/schema.js +5 -1
- package/dist/src/exec/network.js +50 -3
- package/dist/src/orchestrator/leadRunner.js +7 -2
- package/dist/src/orchestrator/review.js +2 -2
- package/dist/src/orchestrator/taskRunner.js +36 -0
- package/dist/src/plan/kerrigan.js +126 -126
- package/dist/src/plan/systemGuide.js +83 -11
- package/dist/src/session/workspaceGit.js +95 -1
- package/dist/src/transport/profileLock.js +34 -4
- package/dist/web/404.html +3 -3
- package/dist/web/_next/static/L-h3cKqABsuAzPqNkvLAP/_buildManifest.js +1 -0
- package/dist/web/_next/static/chunks/1077.a8fcbe8fc90ecb2d.js +1 -0
- package/dist/web/_next/static/chunks/1083.0122bea31f7199d9.js +1 -0
- package/dist/web/_next/static/chunks/1490.f5154054ddfd3dee.js +1 -0
- package/dist/web/_next/static/chunks/1536.98fab69162f370f0.js +1 -0
- package/dist/web/_next/static/chunks/1548.3aba99d28ca12a76.js +1 -0
- package/dist/web/_next/static/chunks/1584.7500138d08971f81.js +1 -0
- package/dist/web/_next/static/chunks/1732.90182d376c75c315.js +1 -0
- package/dist/web/_next/static/chunks/17449abc.fa53da036b7dcfb4.js +1 -0
- package/dist/web/_next/static/chunks/1872.d12259d09bb1173f.js +1 -0
- package/dist/web/_next/static/chunks/192.955be0d5fcd27ec6.js +1 -0
- package/dist/web/_next/static/chunks/1920.59b93a4215a75653.js +1 -0
- package/dist/web/_next/static/chunks/2063.4745e20abad5b208.js +1 -0
- package/dist/web/_next/static/chunks/2163.f028462d8dbc30fe.js +1 -0
- package/dist/web/_next/static/chunks/2175.8c8957600f6b88a8.js +1 -0
- package/dist/web/_next/static/chunks/2280.5a3754f49656d989.js +1 -0
- package/dist/web/_next/static/chunks/2355.d6bb92f10d516f81.js +1 -0
- package/dist/web/_next/static/chunks/2378.4f15342be64a9d23.js +1 -0
- package/dist/web/_next/static/chunks/2395.c2c4d3696d3b5542.js +1 -0
- package/dist/web/_next/static/chunks/2486.d130023b2b399eaa.js +1 -0
- package/dist/web/_next/static/chunks/2606.8e9434e7fee257b9.js +1 -0
- package/dist/web/_next/static/chunks/26dd8e60.1890515693b4ca88.js +1 -0
- package/dist/web/_next/static/chunks/2738.2559ed1058f6fb19.js +1 -0
- package/dist/web/_next/static/chunks/2821.409d92f5ac5b8142.js +1 -0
- package/dist/web/_next/static/chunks/3088.12b1d19ca55225b7.js +1 -0
- package/dist/web/_next/static/chunks/3152.d623d85a9afed5d3.js +1 -0
- package/dist/web/_next/static/chunks/3184.0788c67536fc4140.js +1 -0
- package/dist/web/_next/static/chunks/3194.8ee589997ce1e093.js +1 -0
- package/dist/web/_next/static/chunks/3322.4f7b378a41711478.js +1 -0
- package/dist/web/_next/static/chunks/3564.bfa030e92401f57d.js +1 -0
- package/dist/web/_next/static/chunks/358.4791f77f174006f3.js +1 -0
- package/dist/web/_next/static/chunks/3696.a367f4c8f42909d1.js +1 -0
- package/dist/web/_next/static/chunks/3748.8726b202d79d0dba.js +3 -0
- package/dist/web/_next/static/chunks/3794.19aedfb95f89dc48.js +1 -0
- package/dist/web/_next/static/chunks/384.063f394c789898a7.js +1 -0
- package/dist/web/_next/static/chunks/3854.39b7a1bf2b4189fe.js +1 -0
- package/dist/web/_next/static/chunks/386.2718f961400a3322.js +1 -0
- package/dist/web/_next/static/chunks/4008.3691a32e1711848f.js +1 -0
- package/dist/web/_next/static/chunks/4054.1c8d37b1513d20d8.js +1 -0
- package/dist/web/_next/static/chunks/4328.e326d66dd5c820c6.js +1 -0
- package/dist/web/_next/static/chunks/4444.36f5d8532bd6300d.js +1 -0
- package/dist/web/_next/static/chunks/4560.b8235d283fb3608c.js +1 -0
- package/dist/web/_next/static/chunks/464.f60ecfb6c72ec733.js +1 -0
- package/dist/web/_next/static/chunks/4912.1ab85b0ebf52a3e0.js +1 -0
- package/dist/web/_next/static/chunks/4982.bbbd303d665de4f0.js +1 -0
- package/dist/web/_next/static/chunks/4fecf3c3.e14d65bd1dce80cf.js +1 -0
- package/dist/web/_next/static/chunks/5052.dc8c36742419eed5.js +1 -0
- package/dist/web/_next/static/chunks/{7496.17282033df0e8794.js → 5115.fbe164892bfd6fa4.js} +1 -1
- package/dist/web/_next/static/chunks/5120.b4aadb89d4fb4f65.js +1 -0
- package/dist/web/_next/static/chunks/5448.1c4e0b719af53b3f.js +1 -0
- package/dist/web/_next/static/chunks/5623.cc6818f4096ce4c2.js +1 -0
- package/dist/web/_next/static/chunks/5664.507fea1f6305067e.js +1 -0
- package/dist/web/_next/static/chunks/5706.be484c6a7bed3fde.js +1 -0
- package/dist/web/_next/static/chunks/6336.b09d0d920c7631eb.js +1 -0
- package/dist/web/_next/static/chunks/6364.5b0466f24f4ecf58.js +1 -0
- package/dist/web/_next/static/chunks/640.2c2baacde5197a77.js +1 -0
- package/dist/web/_next/static/chunks/6419.61399b0413b8bef0.js +1 -0
- package/dist/web/_next/static/chunks/642.b70763e1cfe9e45e.js +1 -0
- package/dist/web/_next/static/chunks/6554.0110334a71e72bbe.js +1 -0
- package/dist/web/_next/static/chunks/6688.4a6ac23ba061262b.js +1 -0
- package/dist/web/_next/static/chunks/6815.6537cc012ba16cca.js +1 -0
- package/dist/web/_next/static/chunks/6896.33fdeb4e682c2cab.js +1 -0
- package/dist/web/_next/static/chunks/6912.3416822e13b4bc03.js +1 -0
- package/dist/web/_next/static/chunks/6944.635230aa8cb23871.js +1 -0
- package/dist/web/_next/static/chunks/6964.35718884ad3375bc.js +1 -0
- package/dist/web/_next/static/chunks/6992.4b059bae2659231d.js +1 -0
- package/dist/web/_next/static/chunks/6996.7c41217972cabc3f.js +1 -0
- package/dist/web/_next/static/chunks/7024.8bc670b892a558bb.js +1 -0
- package/dist/web/_next/static/chunks/7040.e058d8f95c3c11e7.js +1 -0
- package/dist/web/_next/static/chunks/714.70bdf8b4550aa78f.js +1 -0
- package/dist/web/_next/static/chunks/7220.807613863ef39947.js +1 -0
- package/dist/web/_next/static/chunks/7250.7f1d45021e49d2fd.js +1 -0
- package/dist/web/_next/static/chunks/7290.7bceed706f7b6df5.js +1 -0
- package/dist/web/_next/static/chunks/7301.c60eb2ba8ae6b859.js +1 -0
- package/dist/web/_next/static/chunks/7328.021e5e45124e40de.js +1 -0
- package/dist/web/_next/static/chunks/7340.a5a75ee889c30b74.js +1 -0
- package/dist/web/_next/static/chunks/7443.c189418756727101.js +1 -0
- package/dist/web/_next/static/chunks/7484.c0e6bfca7b2fb65e.js +1 -0
- package/dist/web/_next/static/chunks/7496.e638a7286c17e438.js +1 -0
- package/dist/web/_next/static/chunks/7500-077d236acd9b9c50.js +1 -0
- package/dist/web/_next/static/chunks/7695.11ba99db589cb586.js +1 -0
- package/dist/web/_next/static/chunks/7764.e62333ee1d63a458.js +1 -0
- package/dist/web/_next/static/chunks/7921-ddb0291f25a2e486.js +1 -0
- package/dist/web/_next/static/chunks/80.df762af692aca107.js +1 -0
- package/dist/web/_next/static/chunks/8024.4bd0b5a7f26a0f7d.js +1 -0
- package/dist/web/_next/static/chunks/82b69429.c6dd4e5c5ac704f3.js +368 -0
- package/dist/web/_next/static/chunks/8360.371456f14873ee9f.js +1 -0
- package/dist/web/_next/static/chunks/8544.7c1fb012f9073eaa.js +1 -0
- package/dist/web/_next/static/chunks/8547.424f9970cc72775f.js +1 -0
- package/dist/web/_next/static/chunks/8584.9bf7e755a7c8c432.js +1 -0
- package/dist/web/_next/static/chunks/8616.8e05c4a20dcdf39d.js +1 -0
- package/dist/web/_next/static/chunks/8752.bf29293df3366e17.js +298 -0
- package/dist/web/_next/static/chunks/8800.3c7b01176e98160a.js +1 -0
- package/dist/web/_next/static/chunks/88b2132a.04b02968da05b8a6.js +1005 -0
- package/dist/web/_next/static/chunks/8924.49dd385ac101fb7e.js +1 -0
- package/dist/web/_next/static/chunks/896.eb46d6e001d25d0f.js +1 -0
- package/dist/web/_next/static/chunks/9003.3d5c7a418d0b858b.js +1 -0
- package/dist/web/_next/static/chunks/9067.394ff92d9ae542b3.js +1 -0
- package/dist/web/_next/static/chunks/9068.9662bb8fa5fdc637.js +1 -0
- package/dist/web/_next/static/chunks/9178.a7631bd283f2a69c.js +1 -0
- package/dist/web/_next/static/chunks/9190.e3a90b1a9ed21668.js +1 -0
- package/dist/web/_next/static/chunks/9296.59fcfc8261a4c6bd.js +1 -0
- package/dist/web/_next/static/chunks/9312.e1fb4089a122d3d3.js +1 -0
- package/dist/web/_next/static/chunks/9348.022486b05b882739.js +1 -0
- package/dist/web/_next/static/chunks/948.132a0571d85c8b01.js +1 -0
- package/dist/web/_next/static/chunks/951.43a4ba54b1d1ff4e.js +3 -0
- package/dist/web/_next/static/chunks/9544.acc06fe34aa32c5c.js +7 -0
- package/dist/web/_next/static/chunks/9591.d205941f0062de24.js +1 -0
- package/dist/web/_next/static/chunks/9628.d8954a2bd28b85a6.js +1 -0
- package/dist/web/_next/static/chunks/9636.35df6241125f8513.js +1 -0
- package/dist/web/_next/static/chunks/9658.cdecb568f615e4c9.js +782 -0
- package/dist/web/_next/static/chunks/9672.b379566a8bfcd947.js +1 -0
- package/dist/web/_next/static/chunks/9680.d10b204d08ca3a62.js +1 -0
- package/dist/web/_next/static/chunks/9728.1d4cb6c68bd55f44.js +1 -0
- package/dist/web/_next/static/chunks/9747.80f474bcd4654c6c.js +1 -0
- package/dist/web/_next/static/chunks/9784.c9938b7e977e14eb.js +1 -0
- package/dist/web/_next/static/chunks/9812.024424a52730b057.js +1 -0
- package/dist/web/_next/static/chunks/9888.ce925cd415b672ef.js +1 -0
- package/dist/web/_next/static/chunks/{9891.91a2c59fd073fd48.js → 9891.a97db7c8f05693d1.js} +1 -1
- package/dist/web/_next/static/chunks/9904.a3d2f8569d7355ab.js +1 -0
- package/dist/web/_next/static/chunks/992.8470b96c23472686.js +1 -0
- package/dist/web/_next/static/chunks/9924.03252dda78c705c3.js +1 -0
- package/dist/web/_next/static/chunks/9968.3d45ff9183e8b07b.js +1 -0
- package/dist/web/_next/static/chunks/app/_not-found/page-23c6c0396966da29.js +1 -0
- package/dist/web/_next/static/chunks/app/defaults/page-4e5be923763ba3d9.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-678acf830096ce90.js +1 -0
- package/dist/web/_next/static/chunks/app/page-be5c3849591d8c11.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-b39878dce98ded94.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +1 -0
- package/dist/web/_next/static/chunks/{main-app-f747f0f5ddb4213b.js → main-app-d23441ca81b3a063.js} +1 -1
- package/dist/web/_next/static/chunks/webpack-b26d4d956feb6e65.js +1 -0
- package/dist/web/_next/static/css/2de713eca93a7750.css +3 -0
- package/dist/web/_next/static/css/4bfdd3ebb3d1a180.css +1 -0
- package/dist/web/_next/static/css/51bfff1122e9f34d.css +1 -0
- package/dist/web/_next/static/css/73368887921d70d9.css +1 -0
- package/dist/web/_next/static/media/codicon.5ce2572b.ttf +0 -0
- package/dist/web/_next/static/media/editorWebWorkerMain.828b206c.js +1 -0
- package/dist/web/defaults.html +3 -3
- package/dist/web/defaults.txt +9 -9
- package/dist/web/index.html +4 -4
- package/dist/web/index.txt +9 -9
- package/dist/web/settings.html +14 -0
- package/dist/web/settings.txt +25 -0
- package/dist/web/system.html +3 -3
- package/dist/web/system.txt +9 -9
- package/dist/web/third-party-notices.txt +5966 -0
- package/package.json +157 -153
- package/prompts/lead1.md +140 -140
- package/prompts/level1.md +574 -574
- package/prompts/review1.md +287 -287
- package/dist/src/context/desktopDir.js +0 -44
- package/dist/web/_next/static/chunks/1077.3c07f38a61cef38a.js +0 -1
- package/dist/web/_next/static/chunks/1548.55dadf800d6c2a79.js +0 -1
- package/dist/web/_next/static/chunks/2163.83d1085b99ac1773.js +0 -1
- package/dist/web/_next/static/chunks/714.88c495053f62f187.js +0 -1
- package/dist/web/_next/static/chunks/7220.f1e8a10d52a7ee87.js +0 -1
- package/dist/web/_next/static/chunks/7500-1353339f7e2eda10.js +0 -1
- package/dist/web/_next/static/chunks/7921-56de379f7bdfbacf.js +0 -1
- package/dist/web/_next/static/chunks/8547.0a9997b67008c706.js +0 -1
- package/dist/web/_next/static/chunks/8584.b34930a6837344a6.js +0 -1
- package/dist/web/_next/static/chunks/9067.5651e8647cef053f.js +0 -1
- package/dist/web/_next/static/chunks/9591.fabd60bd0d10341c.js +0 -1
- package/dist/web/_next/static/chunks/9747.ad6b319cf12169ee.js +0 -1
- package/dist/web/_next/static/chunks/app/_not-found/page-1264c0db9665169c.js +0 -1
- package/dist/web/_next/static/chunks/app/defaults/page-ba24062a86d50e12.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-46efb208d7c88648.js +0 -1
- package/dist/web/_next/static/chunks/app/page-07f80fd07281a230.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-825f53f14d16033d.js +0 -1
- package/dist/web/_next/static/chunks/webpack-ab0451ef95a8f52a.js +0 -1
- package/dist/web/_next/static/css/131c746a9d388eda.css +0 -1
- package/dist/web/_next/static/w1xPyNasTvFr11R3F7HkS/_buildManifest.js +0 -1
- /package/dist/web/_next/static/{w1xPyNasTvFr11R3F7HkS → 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
|
|
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
|
|
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';
|
|
@@ -1078,6 +1078,13 @@ let OperatorService = class OperatorService {
|
|
|
1078
1078
|
throw new Error(ws.problem ?? 'No project folder is open.');
|
|
1079
1079
|
return await workspaceGit(ws.dir);
|
|
1080
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
|
+
}
|
|
1081
1088
|
async workspaceCommit(sha) {
|
|
1082
1089
|
const ws = await this.workspace();
|
|
1083
1090
|
if (!ws.ok)
|
|
@@ -2110,10 +2117,55 @@ let OperatorService = class OperatorService {
|
|
|
2110
2117
|
async browseFolder(start) {
|
|
2111
2118
|
return await pickFolder(start);
|
|
2112
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
|
+
}
|
|
2113
2162
|
async doctor() {
|
|
2114
2163
|
const cfg = await this.settings.load();
|
|
2115
2164
|
const edge = ['C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', 'C:/Program Files/Microsoft/Edge/Application/msedge.exe'].find((p) => existsSync(p));
|
|
2116
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;
|
|
2117
2169
|
return {
|
|
2118
2170
|
// Which copilot-operator this is: `cop --version` without a terminal.
|
|
2119
2171
|
version: botVersion(),
|
|
@@ -2123,13 +2175,20 @@ let OperatorService = class OperatorService {
|
|
|
2123
2175
|
profileExists: existsSync(cfg.resolved.profileDir),
|
|
2124
2176
|
profileHeldBy: Array.isArray(holders) ? holders.map((h) => h.pid) : 'unknown',
|
|
2125
2177
|
/*
|
|
2126
|
-
*
|
|
2127
|
-
*
|
|
2128
|
-
* fail" was shown
|
|
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.
|
|
2129
2181
|
*/
|
|
2182
|
+
profileHolder: holder === 'own' ? (this.running.size > 0 ? 'own-run' : 'own-window') : holder,
|
|
2130
2183
|
botRunning: this.running.size > 0,
|
|
2131
|
-
|
|
2132
|
-
|
|
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'),
|
|
2133
2192
|
cwd: cfg.resolved.cwd,
|
|
2134
2193
|
runsDir: cfg.resolved.runsDir,
|
|
2135
2194
|
dataDir: this.dataDir,
|
package/dist/src/api/security.js
CHANGED
|
@@ -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 (
|
|
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.',
|
package/dist/src/api/server.js
CHANGED
|
@@ -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
|
|
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.
|
package/dist/src/api/settings.js
CHANGED
|
@@ -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,
|
|
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 =
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
@@ -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
|
|
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 {
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
*
|