copilot-operator 0.1.96 → 0.1.99
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/dist/src/api/apiLock.js +82 -0
- package/dist/src/api/folderPicker.js +22 -22
- package/dist/src/api/main.js +5 -0
- package/dist/src/api/operator.controller.js +37 -11
- package/dist/src/api/operator.service.js +493 -86
- package/dist/src/api/server.js +10 -0
- package/dist/src/config/exportHome.js +52 -10
- package/dist/src/config/home.js +27 -11
- package/dist/src/config/schema.js +13 -0
- package/dist/src/exec/authorizer.js +11 -4
- package/dist/src/exec/commandHeads.js +25 -0
- package/dist/src/exec/confinement.js +50 -4
- package/dist/src/exec/network.js +11 -1
- package/dist/src/exec/npmScripts.js +33 -0
- package/dist/src/exec/policy.js +79 -24
- package/dist/src/exec/processes.js +24 -5
- package/dist/src/exec/programs.js +21 -0
- package/dist/src/exec/reportFile.js +2 -1
- package/dist/src/exec/runner.js +31 -9
- package/dist/src/exec/scriptFiles.js +133 -6
- package/dist/src/orchestrator/handoff.js +3 -3
- package/dist/src/orchestrator/kerriganRunner.js +14 -6
- package/dist/src/orchestrator/leadRunner.js +43 -23
- package/dist/src/orchestrator/review.js +66 -10
- package/dist/src/orchestrator/taskRunner.js +73 -14
- package/dist/src/plan/kerrigan.js +253 -253
- package/dist/src/plan/schema.js +3 -13
- package/dist/src/plan/systemGuide.js +28 -28
- package/dist/src/protocol/kerriganSchema.js +5 -1
- package/dist/src/protocol/replySchema.js +2 -2
- package/dist/src/queue/queue.js +93 -0
- package/dist/src/session/compose.js +14 -10
- package/dist/src/session/locatorFailures.js +32 -12
- package/dist/src/session/model.js +23 -0
- package/dist/src/session/store.js +47 -0
- package/dist/src/session/workspace.js +20 -5
- package/dist/src/transport/copilotTransport.js +82 -62
- package/dist/src/util/zip.js +147 -44
- package/dist/src/vcs/newBranch.js +24 -2
- package/dist/src/vcs/operatorGit.js +9 -10
- package/dist/src/vcs/referenceGuard.js +9 -4
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/1024-c0eee3ec374816d1.js +1 -0
- package/dist/web/_next/static/chunks/1077.a4fe6ae48f3d3ff9.js +1 -0
- package/dist/web/_next/static/chunks/1548.765d6eed5325bd01.js +1 -0
- package/dist/web/_next/static/chunks/2163.e8d6c85412d5d411.js +1 -0
- package/dist/web/_next/static/chunks/6240-8ba644c53ffab87d.js +1 -0
- package/dist/web/_next/static/chunks/714.f2dcd6b41b58d1a7.js +1 -0
- package/dist/web/_next/static/chunks/7220.652a8a339c1e7401.js +1 -0
- package/dist/web/_next/static/chunks/7921-9cf1ece94fc89bb3.js +1 -0
- package/dist/web/_next/static/chunks/8584.7c438425140f1d8d.js +1 -0
- package/dist/web/_next/static/chunks/9067.8c4e6a64620a45d9.js +1 -0
- package/dist/web/_next/static/chunks/9747.43d25bdff8737d09.js +1 -0
- package/dist/web/_next/static/chunks/app/{layout-2364903896c2c175.js → layout-97259931ed97e20d.js} +1 -1
- package/dist/web/_next/static/chunks/app/page-26e4ea30eb076e6b.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/page-7228e045f8ea10c4.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-c915d61553e1025b.js +1 -0
- package/dist/web/_next/static/chunks/app/system/page-4d24f44eb9077fb7.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-3f144d13be3516c2.js → webpack-31db88c3d5781520.js} +1 -1
- package/dist/web/_next/static/css/{523d11041085f836.css → 87999096d96266fd.css} +1 -1
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +26 -25
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +26 -25
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +26 -25
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +26 -25
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +26 -25
- package/package.json +3 -2
- package/prompts/kerrigan1.md +2 -1
- package/prompts/lead1.md +2 -1
- package/prompts/level1.md +6 -1
- package/prompts/review1.md +7 -4
- package/dist/web/_next/static/chunks/1024-214ded25b9048526.js +0 -1
- package/dist/web/_next/static/chunks/1077.161de82f740d47f0.js +0 -1
- package/dist/web/_next/static/chunks/1548.f2688468bf946e13.js +0 -1
- package/dist/web/_next/static/chunks/2163.b8ada3b7bde69f03.js +0 -1
- package/dist/web/_next/static/chunks/714.d1489788e598833b.js +0 -1
- package/dist/web/_next/static/chunks/7220.b85c8d105f394389.js +0 -1
- package/dist/web/_next/static/chunks/7921-00ebbcc6f65fbe35.js +0 -1
- package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
- package/dist/web/_next/static/chunks/8584.a678bfced1cea938.js +0 -1
- package/dist/web/_next/static/chunks/9067.6da03ae052877b19.js +0 -1
- package/dist/web/_next/static/chunks/9747.ba29e64e97e8a15b.js +0 -1
- package/dist/web/_next/static/chunks/app/page-d031bf326e401246.js +0 -1
- package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +0 -1
- package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +0 -1
- /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → n8n-2FmbL8PhXulu4hTV5}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One copilot-operator at a time on the same records (second bug hunt, 2026-11-19).
|
|
3
|
+
*
|
|
4
|
+
* Every npm install of the program shares one home folder (%LOCALAPPDATA%\copilot-operator), so a second `cop start`
|
|
5
|
+
* — from another project, or with another port after the first said its port was taken — opened the same records.
|
|
6
|
+
* Starting up, it put the first one's work to rest as a program closed under it would be: the task at work marked
|
|
7
|
+
* stopped, the queue marked not running, which the first one's queue then read and stopped at. And the two wrote the
|
|
8
|
+
* same files from then on.
|
|
9
|
+
*
|
|
10
|
+
* The lock is a file in the data folder with the process and its port. Another process alive and answering on that
|
|
11
|
+
* port holds it: the start is refused, saying where the one running is. A lock whose process is gone, or whose port
|
|
12
|
+
* nothing answers on (its number taken by another program since), is taken over: a crash never leaves the records
|
|
13
|
+
* locked.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { createConnection } from 'node:net';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
export const API_LOCK_FILE = 'api.lock.json';
|
|
19
|
+
/** Said when another copilot-operator runs on the same records. */
|
|
20
|
+
export class AlreadyRunning extends Error {
|
|
21
|
+
pid;
|
|
22
|
+
port;
|
|
23
|
+
constructor(pid, port, dataDir) {
|
|
24
|
+
super(`copilot-operator is already running on these records (${dataDir}): process ${pid}, at http://127.0.0.1:${port}/ — open it there. ` +
|
|
25
|
+
'A second one is not started: it would take over that one\'s work, its task at work marked stopped and its queue stopped. Close that one first to start this one.');
|
|
26
|
+
this.pid = pid;
|
|
27
|
+
this.port = port;
|
|
28
|
+
this.name = 'AlreadyRunning';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function alive(pid) {
|
|
32
|
+
try {
|
|
33
|
+
process.kill(pid, 0);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
// EPERM: there, but another account's.
|
|
38
|
+
return e.code === 'EPERM';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function answers(port, timeoutMs = 1_500) {
|
|
42
|
+
return new Promise((done) => {
|
|
43
|
+
const socket = createConnection({ host: '127.0.0.1', port });
|
|
44
|
+
const end = (ok) => {
|
|
45
|
+
socket.destroy();
|
|
46
|
+
done(ok);
|
|
47
|
+
};
|
|
48
|
+
socket.setTimeout(timeoutMs, () => end(false));
|
|
49
|
+
socket.once('connect', () => end(true));
|
|
50
|
+
socket.once('error', () => end(false));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Takes the records for this process, or refuses (`AlreadyRunning`). Released when the process ends. */
|
|
54
|
+
export async function acquireApiLock(dataDir, port) {
|
|
55
|
+
mkdirSync(dataDir, { recursive: true });
|
|
56
|
+
const file = join(dataDir, API_LOCK_FILE);
|
|
57
|
+
if (existsSync(file)) {
|
|
58
|
+
let held = {};
|
|
59
|
+
try {
|
|
60
|
+
held = JSON.parse(readFileSync(file, 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Unreadable: a crash mid-write, taken over.
|
|
64
|
+
}
|
|
65
|
+
if (typeof held.pid === 'number' && held.pid !== process.pid && typeof held.port === 'number' && alive(held.pid) && (await answers(held.port))) {
|
|
66
|
+
throw new AlreadyRunning(held.pid, held.port, dataDir);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
writeFileSync(file, JSON.stringify({ pid: process.pid, port, startedAt: new Date().toISOString() }), 'utf8');
|
|
70
|
+
const release = () => {
|
|
71
|
+
try {
|
|
72
|
+
const now = JSON.parse(readFileSync(file, 'utf8'));
|
|
73
|
+
if (now.pid === process.pid)
|
|
74
|
+
rmSync(file, { force: true });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Gone already, or another's now.
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
process.once('exit', release);
|
|
81
|
+
return { release };
|
|
82
|
+
}
|
|
@@ -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() {
|
package/dist/src/api/main.js
CHANGED
|
@@ -26,5 +26,10 @@ process.on('uncaughtException', (error) => {
|
|
|
26
26
|
});
|
|
27
27
|
startApi().catch((e) => {
|
|
28
28
|
console.error(e.message);
|
|
29
|
+
// Said in words too (2026-11-19): the bare "listen EADDRINUSE" left the operator to guess what holds the port.
|
|
30
|
+
if (e.code === 'EADDRINUSE') {
|
|
31
|
+
const port = Number(process.env.COP_API_PORT ?? 4000);
|
|
32
|
+
console.error(`Port ${port} is taken. If copilot-operator is running already, open http://127.0.0.1:${port}/ ; otherwise another program has the port: close it, or start this one with COP_API_PORT set to another.`);
|
|
33
|
+
}
|
|
29
34
|
process.exit(1);
|
|
30
35
|
});
|
|
@@ -23,7 +23,7 @@ import { Body, Controller, Delete, Get, Inject, Param, Post, Put, Query, Res, No
|
|
|
23
23
|
import { OperatorService } from './operator.service.js';
|
|
24
24
|
import { SettingsUnusableError } from './settings.js';
|
|
25
25
|
import { PolicyLockUnusableError } from '../config/lockedPolicy.js';
|
|
26
|
-
import { CHANGED_ON_DISK } from '../session/workspace.js';
|
|
26
|
+
import { CHANGED_ON_DISK, GONE_FROM_DISK } from '../session/workspace.js';
|
|
27
27
|
import { join } from 'node:path';
|
|
28
28
|
import { DefaultChatLocators, DefaultPickerLocators } from '../transport/locators.js';
|
|
29
29
|
import { platformTools } from '../exec/platforms.js';
|
|
@@ -247,15 +247,20 @@ let OperatorController = class OperatorController {
|
|
|
247
247
|
return this.ops.exportSizes();
|
|
248
248
|
}
|
|
249
249
|
/** Everything the bot has kept, as a .zip: `data/`, and `runs/` with `?runs=1`. See `config/exportHome.ts`. */
|
|
250
|
-
exportHome(runs, res) {
|
|
250
|
+
async exportHome(runs, res) {
|
|
251
251
|
try {
|
|
252
|
-
const { fileName,
|
|
252
|
+
const { fileName, write } = this.ops.exportHome(runs === '1' || runs === 'true');
|
|
253
253
|
res.type('application/zip');
|
|
254
254
|
res.setHeader('content-disposition', contentDisposition(fileName));
|
|
255
|
-
|
|
255
|
+
// Sent as it is written (2026-11-19), so its length is not known beforehand.
|
|
256
|
+
await write(res);
|
|
257
|
+
res.end();
|
|
256
258
|
}
|
|
257
259
|
catch (e) {
|
|
258
|
-
|
|
260
|
+
if (!res.headersSent)
|
|
261
|
+
failText(res, e);
|
|
262
|
+
else
|
|
263
|
+
res.destroy(e);
|
|
259
264
|
}
|
|
260
265
|
}
|
|
261
266
|
/** What the bot's console showed, the latest lines, as a text file. See `log/terminal.ts`. */
|
|
@@ -310,10 +315,15 @@ let OperatorController = class OperatorController {
|
|
|
310
315
|
res.setHeader('Cache-Control', 'no-store');
|
|
311
316
|
res.end(r.bytes);
|
|
312
317
|
}
|
|
313
|
-
workspaceFile(path) {
|
|
318
|
+
workspaceFile(path, dir) {
|
|
314
319
|
if (!path)
|
|
315
320
|
throw new BadRequestException('path is required');
|
|
316
|
-
return this.ops.workspaceFile(path).catch(
|
|
321
|
+
return this.ops.workspaceFile(path, dir || undefined).catch((e) => {
|
|
322
|
+
// Not there: 404, so the editor can tell it from a refusal (2026-11-19).
|
|
323
|
+
if (e.code === GONE_FROM_DISK)
|
|
324
|
+
throw new NotFoundException(e.message);
|
|
325
|
+
return fail(e);
|
|
326
|
+
});
|
|
317
327
|
}
|
|
318
328
|
/**
|
|
319
329
|
* The editor saving a file of the open folder. `base` is the version it was opened at; a file changed on disk since
|
|
@@ -325,11 +335,13 @@ let OperatorController = class OperatorController {
|
|
|
325
335
|
if (typeof body.text !== 'string')
|
|
326
336
|
throw new BadRequestException('text is required');
|
|
327
337
|
try {
|
|
328
|
-
return await this.ops.saveWorkspaceFile(body.path, body.text, typeof body.base === 'string' && body.base ? body.base : undefined);
|
|
338
|
+
return await this.ops.saveWorkspaceFile(body.path, body.text, typeof body.base === 'string' && body.base ? body.base : undefined, typeof body.dir === 'string' && body.dir ? body.dir : undefined, body.again === true);
|
|
329
339
|
}
|
|
330
340
|
catch (e) {
|
|
331
341
|
if (e.code === CHANGED_ON_DISK)
|
|
332
342
|
throw new ConflictException(e.message);
|
|
343
|
+
if (e.code === GONE_FROM_DISK)
|
|
344
|
+
throw new NotFoundException(e.message);
|
|
333
345
|
fail(e);
|
|
334
346
|
}
|
|
335
347
|
}
|
|
@@ -451,7 +463,7 @@ let OperatorController = class OperatorController {
|
|
|
451
463
|
}
|
|
452
464
|
/** The list as the page edits it: added, changed, moved, taken out, put back to wait. */
|
|
453
465
|
setQueue(body = {}) {
|
|
454
|
-
return this.ops.setQueue(body?.items).catch(fail);
|
|
466
|
+
return this.ops.setQueue(body?.items, body?.seen).catch(fail);
|
|
455
467
|
}
|
|
456
468
|
runQueue() {
|
|
457
469
|
return this.ops.runQueue().catch(fail);
|
|
@@ -604,6 +616,12 @@ let OperatorController = class OperatorController {
|
|
|
604
616
|
browseFolder(body) {
|
|
605
617
|
return this.ops.browseFolder(body?.start);
|
|
606
618
|
}
|
|
619
|
+
/** "Open a folder": the folder becomes the project, with its own name, level 2 and "for reference only" (2026-11-19). */
|
|
620
|
+
openProjectFolder(body = {}) {
|
|
621
|
+
if (typeof body?.dir !== 'string' || !body.dir.trim())
|
|
622
|
+
throw new BadRequestException('dir is required');
|
|
623
|
+
return this.ops.openProjectFolder(body.dir).catch(fail);
|
|
624
|
+
}
|
|
607
625
|
};
|
|
608
626
|
__decorate([
|
|
609
627
|
Get('health'),
|
|
@@ -780,7 +798,7 @@ __decorate([
|
|
|
780
798
|
__param(1, Res()),
|
|
781
799
|
__metadata("design:type", Function),
|
|
782
800
|
__metadata("design:paramtypes", [Object, Object]),
|
|
783
|
-
__metadata("design:returntype",
|
|
801
|
+
__metadata("design:returntype", Promise)
|
|
784
802
|
], OperatorController.prototype, "exportHome", null);
|
|
785
803
|
__decorate([
|
|
786
804
|
Get('terminal'),
|
|
@@ -845,8 +863,9 @@ __decorate([
|
|
|
845
863
|
__decorate([
|
|
846
864
|
Get('workspace/file'),
|
|
847
865
|
__param(0, Query('path')),
|
|
866
|
+
__param(1, Query('dir')),
|
|
848
867
|
__metadata("design:type", Function),
|
|
849
|
-
__metadata("design:paramtypes", [String]),
|
|
868
|
+
__metadata("design:paramtypes", [String, String]),
|
|
850
869
|
__metadata("design:returntype", Promise)
|
|
851
870
|
], OperatorController.prototype, "workspaceFile", null);
|
|
852
871
|
__decorate([
|
|
@@ -1163,6 +1182,13 @@ __decorate([
|
|
|
1163
1182
|
__metadata("design:paramtypes", [Object]),
|
|
1164
1183
|
__metadata("design:returntype", Promise)
|
|
1165
1184
|
], OperatorController.prototype, "browseFolder", null);
|
|
1185
|
+
__decorate([
|
|
1186
|
+
Post('workspace/open'),
|
|
1187
|
+
__param(0, Body()),
|
|
1188
|
+
__metadata("design:type", Function),
|
|
1189
|
+
__metadata("design:paramtypes", [Object]),
|
|
1190
|
+
__metadata("design:returntype", Promise)
|
|
1191
|
+
], OperatorController.prototype, "openProjectFolder", null);
|
|
1166
1192
|
OperatorController = __decorate([
|
|
1167
1193
|
Controller(),
|
|
1168
1194
|
__param(0, Inject(OperatorService)),
|