copilot-operator 0.1.96 → 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.
Files changed (56) hide show
  1. package/dist/src/api/apiLock.js +82 -0
  2. package/dist/src/api/main.js +5 -0
  3. package/dist/src/api/operator.controller.js +18 -4
  4. package/dist/src/api/operator.service.js +264 -51
  5. package/dist/src/api/server.js +10 -0
  6. package/dist/src/config/exportHome.js +1 -1
  7. package/dist/src/config/schema.js +13 -0
  8. package/dist/src/exec/policy.js +9 -18
  9. package/dist/src/plan/kerrigan.js +2 -2
  10. package/dist/src/plan/systemGuide.js +26 -26
  11. package/dist/src/queue/queue.js +7 -0
  12. package/dist/src/session/locatorFailures.js +10 -11
  13. package/dist/src/session/model.js +4 -0
  14. package/dist/src/session/store.js +47 -0
  15. package/dist/src/vcs/newBranch.js +6 -1
  16. package/dist/src/vcs/operatorGit.js +9 -10
  17. package/dist/web/404.html +2 -2
  18. package/dist/web/_next/static/chunks/1024-c0eee3ec374816d1.js +1 -0
  19. package/dist/web/_next/static/chunks/1077.4da389906036b1bb.js +1 -0
  20. package/dist/web/_next/static/chunks/1548.4aa3e42afe4542ab.js +1 -0
  21. package/dist/web/_next/static/chunks/2163.4c6ce20cf967756c.js +1 -0
  22. package/dist/web/_next/static/chunks/714.ffb1325246519f64.js +1 -0
  23. package/dist/web/_next/static/chunks/7220.f483b83c11525063.js +1 -0
  24. package/dist/web/_next/static/chunks/7921-946e538fe3f9630f.js +1 -0
  25. package/dist/web/_next/static/chunks/8124-967df691ec1bfeeb.js +1 -0
  26. package/dist/web/_next/static/chunks/8584.3301b056c97be517.js +1 -0
  27. package/dist/web/_next/static/chunks/9067.03cdfb01ebf6a35d.js +1 -0
  28. package/dist/web/_next/static/chunks/9747.fe06238bc42bd23d.js +1 -0
  29. package/dist/web/_next/static/chunks/app/{layout-2364903896c2c175.js → layout-7943a4391ad2f88f.js} +1 -1
  30. package/dist/web/_next/static/chunks/app/page-6ec948e0cf4b24f0.js +1 -0
  31. package/dist/web/_next/static/chunks/{webpack-3f144d13be3516c2.js → webpack-710628d673fa4afb.js} +1 -1
  32. package/dist/web/defaults.html +2 -2
  33. package/dist/web/defaults.txt +7 -7
  34. package/dist/web/index.html +3 -3
  35. package/dist/web/index.txt +8 -8
  36. package/dist/web/queue.html +2 -2
  37. package/dist/web/queue.txt +8 -8
  38. package/dist/web/settings.html +2 -2
  39. package/dist/web/settings.txt +8 -8
  40. package/dist/web/system.html +2 -2
  41. package/dist/web/system.txt +8 -8
  42. package/package.json +1 -1
  43. package/dist/web/_next/static/chunks/1024-214ded25b9048526.js +0 -1
  44. package/dist/web/_next/static/chunks/1077.161de82f740d47f0.js +0 -1
  45. package/dist/web/_next/static/chunks/1548.f2688468bf946e13.js +0 -1
  46. package/dist/web/_next/static/chunks/2163.b8ada3b7bde69f03.js +0 -1
  47. package/dist/web/_next/static/chunks/714.d1489788e598833b.js +0 -1
  48. package/dist/web/_next/static/chunks/7220.b85c8d105f394389.js +0 -1
  49. package/dist/web/_next/static/chunks/7921-00ebbcc6f65fbe35.js +0 -1
  50. package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +0 -1
  51. package/dist/web/_next/static/chunks/8584.a678bfced1cea938.js +0 -1
  52. package/dist/web/_next/static/chunks/9067.6da03ae052877b19.js +0 -1
  53. package/dist/web/_next/static/chunks/9747.ba29e64e97e8a15b.js +0 -1
  54. package/dist/web/_next/static/chunks/app/page-d031bf326e401246.js +0 -1
  55. /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → D3ew46wEw5JXPsTVwZwFC}/_buildManifest.js +0 -0
  56. /package/dist/web/_next/static/{kNfJ9jSwlboc-1sFBBfuI → 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
+ }
@@ -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)
@@ -604,6 +604,12 @@ let OperatorController = class OperatorController {
604
604
  browseFolder(body) {
605
605
  return this.ops.browseFolder(body?.start);
606
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
+ }
607
613
  };
608
614
  __decorate([
609
615
  Get('health'),
@@ -845,8 +851,9 @@ __decorate([
845
851
  __decorate([
846
852
  Get('workspace/file'),
847
853
  __param(0, Query('path')),
854
+ __param(1, Query('dir')),
848
855
  __metadata("design:type", Function),
849
- __metadata("design:paramtypes", [String]),
856
+ __metadata("design:paramtypes", [String, String]),
850
857
  __metadata("design:returntype", Promise)
851
858
  ], OperatorController.prototype, "workspaceFile", null);
852
859
  __decorate([
@@ -1163,6 +1170,13 @@ __decorate([
1163
1170
  __metadata("design:paramtypes", [Object]),
1164
1171
  __metadata("design:returntype", Promise)
1165
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);
1166
1180
  OperatorController = __decorate([
1167
1181
  Controller(),
1168
1182
  __param(0, Inject(OperatorService)),