copilot-operator 0.1.94 → 0.1.97
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/main.js +5 -0
- package/dist/src/api/operator.controller.js +23 -5
- package/dist/src/api/operator.service.js +518 -83
- package/dist/src/api/server.js +10 -0
- package/dist/src/config/exportHome.js +1 -1
- package/dist/src/config/live.js +12 -12
- package/dist/src/config/schema.js +13 -0
- package/dist/src/exec/policy.js +9 -18
- package/dist/src/orchestrator/kerriganRunner.js +11 -4
- package/dist/src/orchestrator/leadRunner.js +76 -23
- package/dist/src/orchestrator/review.js +6 -2
- package/dist/src/orchestrator/subtaskRetry.js +2 -1
- package/dist/src/orchestrator/taskRunner.js +75 -16
- package/dist/src/plan/kerrigan.js +4 -4
- package/dist/src/plan/systemGuide.js +36 -36
- package/dist/src/queue/queue.js +19 -0
- package/dist/src/queue/queueBranch.js +34 -9
- package/dist/src/session/locatorFailures.js +10 -11
- package/dist/src/session/model.js +4 -0
- package/dist/src/session/store.js +56 -0
- package/dist/src/session/workspace.js +3 -2
- package/dist/src/transport/copilotTransport.js +83 -68
- package/dist/src/transport/keptWindow.js +17 -14
- package/dist/src/vcs/newBranch.js +28 -0
- package/dist/src/vcs/operatorGit.js +9 -10
- package/dist/src/vcs/referenceGuard.js +16 -2
- 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.4da389906036b1bb.js +1 -0
- package/dist/web/_next/static/chunks/1548.4aa3e42afe4542ab.js +1 -0
- package/dist/web/_next/static/chunks/2163.4c6ce20cf967756c.js +1 -0
- package/dist/web/_next/static/chunks/714.ffb1325246519f64.js +1 -0
- package/dist/web/_next/static/chunks/7220.f483b83c11525063.js +1 -0
- package/dist/web/_next/static/chunks/7921-946e538fe3f9630f.js +1 -0
- package/dist/web/_next/static/chunks/8124-967df691ec1bfeeb.js +1 -0
- package/dist/web/_next/static/chunks/8584.3301b056c97be517.js +1 -0
- package/dist/web/_next/static/chunks/9067.03cdfb01ebf6a35d.js +1 -0
- package/dist/web/_next/static/chunks/9747.fe06238bc42bd23d.js +1 -0
- package/dist/web/_next/static/chunks/app/{layout-1b7d13f7b2efd008.js → layout-7943a4391ad2f88f.js} +1 -1
- package/dist/web/_next/static/chunks/app/page-6ec948e0cf4b24f0.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/page-9cfc8f78d536cfb6.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-9c2b961beb8b3dce.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-91b2de9c3da6f8b9.js → webpack-710628d673fa4afb.js} +1 -1
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +7 -7
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +8 -8
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +8 -8
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +8 -8
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +8 -8
- package/package.json +1 -1
- package/dist/web/_next/static/chunks/1024-dee283a1ddf295bf.js +0 -1
- package/dist/web/_next/static/chunks/1077.b7df9cb8ca810075.js +0 -1
- package/dist/web/_next/static/chunks/1548.417c17b63c371f00.js +0 -1
- package/dist/web/_next/static/chunks/2163.469367b8fbcc862d.js +0 -1
- package/dist/web/_next/static/chunks/714.72112704f3cb8127.js +0 -1
- package/dist/web/_next/static/chunks/7220.8bd897c7ddfee701.js +0 -1
- package/dist/web/_next/static/chunks/7921-25d1755799107ea7.js +0 -1
- package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
- package/dist/web/_next/static/chunks/8584.f87df7324303ab75.js +0 -1
- package/dist/web/_next/static/chunks/9067.67a7c7cf3b019b5c.js +0 -1
- package/dist/web/_next/static/chunks/9747.a87dbd4acd45e39d.js +0 -1
- package/dist/web/_next/static/chunks/app/page-7eae1e8848525e1d.js +0 -1
- package/dist/web/_next/static/chunks/app/queue/page-7909ba7c9e3d4c2d.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-c92548f9c6318962.js +0 -1
- /package/dist/web/_next/static/{UNygvDtRnBVZrGJt53IE4 → D3ew46wEw5JXPsTVwZwFC}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{UNygvDtRnBVZrGJt53IE4 → D3ew46wEw5JXPsTVwZwFC}/_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
|
+
}
|
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
|
});
|
|
@@ -310,10 +310,10 @@ let OperatorController = class OperatorController {
|
|
|
310
310
|
res.setHeader('Cache-Control', 'no-store');
|
|
311
311
|
res.end(r.bytes);
|
|
312
312
|
}
|
|
313
|
-
workspaceFile(path) {
|
|
313
|
+
workspaceFile(path, dir) {
|
|
314
314
|
if (!path)
|
|
315
315
|
throw new BadRequestException('path is required');
|
|
316
|
-
return this.ops.workspaceFile(path).catch(fail);
|
|
316
|
+
return this.ops.workspaceFile(path, dir || undefined).catch(fail);
|
|
317
317
|
}
|
|
318
318
|
/**
|
|
319
319
|
* The editor saving a file of the open folder. `base` is the version it was opened at; a file changed on disk since
|
|
@@ -325,7 +325,7 @@ let OperatorController = class OperatorController {
|
|
|
325
325
|
if (typeof body.text !== 'string')
|
|
326
326
|
throw new BadRequestException('text is required');
|
|
327
327
|
try {
|
|
328
|
-
return await this.ops.saveWorkspaceFile(body.path, body.text, typeof body.base === 'string' && body.base ? body.base : undefined);
|
|
328
|
+
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);
|
|
329
329
|
}
|
|
330
330
|
catch (e) {
|
|
331
331
|
if (e.code === CHANGED_ON_DISK)
|
|
@@ -484,7 +484,11 @@ let OperatorController = class OperatorController {
|
|
|
484
484
|
if (!['run', 'skip', 'abort', 'run-all'].includes(body?.action)) {
|
|
485
485
|
throw new BadRequestException('action must be run, run-all, skip or abort');
|
|
486
486
|
}
|
|
487
|
-
|
|
487
|
+
// Refused as the other answers are (2026-11-18): an "ok: false" with 200 looked taken in the page.
|
|
488
|
+
const result = this.ops.decide(id, body.action);
|
|
489
|
+
if (!result.ok)
|
|
490
|
+
throw new BadRequestException(result.problem);
|
|
491
|
+
return result;
|
|
488
492
|
}
|
|
489
493
|
/** A subtask that failed for a technical reason (two chats, 2026-10-25): one of its card's choices. */
|
|
490
494
|
answerRetry(id, body) {
|
|
@@ -600,6 +604,12 @@ let OperatorController = class OperatorController {
|
|
|
600
604
|
browseFolder(body) {
|
|
601
605
|
return this.ops.browseFolder(body?.start);
|
|
602
606
|
}
|
|
607
|
+
/** "Open a folder": the folder becomes the project, with its own name, level 2 and "for reference only" (2026-11-19). */
|
|
608
|
+
openProjectFolder(body = {}) {
|
|
609
|
+
if (typeof body?.dir !== 'string' || !body.dir.trim())
|
|
610
|
+
throw new BadRequestException('dir is required');
|
|
611
|
+
return this.ops.openProjectFolder(body.dir).catch(fail);
|
|
612
|
+
}
|
|
603
613
|
};
|
|
604
614
|
__decorate([
|
|
605
615
|
Get('health'),
|
|
@@ -841,8 +851,9 @@ __decorate([
|
|
|
841
851
|
__decorate([
|
|
842
852
|
Get('workspace/file'),
|
|
843
853
|
__param(0, Query('path')),
|
|
854
|
+
__param(1, Query('dir')),
|
|
844
855
|
__metadata("design:type", Function),
|
|
845
|
-
__metadata("design:paramtypes", [String]),
|
|
856
|
+
__metadata("design:paramtypes", [String, String]),
|
|
846
857
|
__metadata("design:returntype", Promise)
|
|
847
858
|
], OperatorController.prototype, "workspaceFile", null);
|
|
848
859
|
__decorate([
|
|
@@ -1159,6 +1170,13 @@ __decorate([
|
|
|
1159
1170
|
__metadata("design:paramtypes", [Object]),
|
|
1160
1171
|
__metadata("design:returntype", Promise)
|
|
1161
1172
|
], OperatorController.prototype, "browseFolder", null);
|
|
1173
|
+
__decorate([
|
|
1174
|
+
Post('workspace/open'),
|
|
1175
|
+
__param(0, Body()),
|
|
1176
|
+
__metadata("design:type", Function),
|
|
1177
|
+
__metadata("design:paramtypes", [Object]),
|
|
1178
|
+
__metadata("design:returntype", Promise)
|
|
1179
|
+
], OperatorController.prototype, "openProjectFolder", null);
|
|
1162
1180
|
OperatorController = __decorate([
|
|
1163
1181
|
Controller(),
|
|
1164
1182
|
__param(0, Inject(OperatorService)),
|