coxpit 3.2.2 → 3.3.0
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/README.md +3 -1
- package/package.json +1 -1
- package/src/config.ts +21 -1
- package/src/index.ts +13 -1
- package/src/lock.ts +74 -0
- package/src/server.ts +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ Your keys and login never touch coxpit's config or database.
|
|
|
64
64
|
| env | default | what |
|
|
65
65
|
|---|---|---|
|
|
66
66
|
| `COXPIT_HOST` / `COXPIT_PORT` | `127.0.0.1` / `8210` | daemon bind |
|
|
67
|
-
| `COXPIT_DB` |
|
|
67
|
+
| `COXPIT_DB` | `~/.coxpit/coxpit.db` | SQLite (libSQL) file (a legacy `./coxpit.db` in the cwd is still honored) |
|
|
68
68
|
| `COXPIT_AUTH_PASS` / `COXPIT_AUTH_USER` | — / `admin` | basic auth (empty pass = open; set it) |
|
|
69
69
|
| `COXPIT_AUTH_DISABLED` | — | `1` disables auth (local dev only) |
|
|
70
70
|
| `COXPIT_SSH_KEY` | — | private key for remote machines (else ssh defaults/agent) |
|
|
@@ -87,6 +87,8 @@ machines — git worktrees · tmux sessions · agent CLIs
|
|
|
87
87
|
|
|
88
88
|
One daemon, one SQLite file, zero external services. Machines are reached over SSH; the local machine is just `sh`.
|
|
89
89
|
|
|
90
|
+
**One daemon per machine.** Every install method shares `~/.coxpit/` — the daemon takes a lock there (`daemon.lock.json`) and refuses to start if another daemon already owns the database (running two would corrupt each other's live runs). The desktop app checks for a running daemon first and attaches to it (prompting for its basic auth if set); it only spawns its own embedded daemon when none is running. So npm CLI, launchd/systemd service, and the desktop app all see the same machines, tasks, and run history.
|
|
91
|
+
|
|
90
92
|
## Status
|
|
91
93
|
|
|
92
94
|
`v3.0` — fleet, compare/merge, terminal, Design Mode, run destinations (merge · export · PR), swarm (plan fan-out + integrate with conflict-resolving agents), AI review, and sessions (work/ask + notifications) — all shipped and e2e-tested. Roadmap: ROADMAP.md.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coxpit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Self-hosted cockpit for running a fleet of AI coding agents across your own machines — parallel worktree runs, live board, compare & merge, web terminal, design capture.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
2
5
|
|
|
3
6
|
// GUI 앱(Finder/데스크톱)에서 뜨면 PATH 가 최소(/usr/bin:/bin...)라 brew 로 설치한
|
|
4
7
|
// 도구(claude·tmux·git)를 못 찾는다 — 표준 설치 경로를 부팅 시 1회 보강한다.
|
|
@@ -24,13 +27,30 @@ import 'dotenv/config';
|
|
|
24
27
|
if (process.env.LC_ALL && !/utf-?8/i.test(process.env.LC_ALL)) delete process.env.LC_ALL;
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
// 기본 DB 경로 — npm/dmg 어느 설치든 같은 상태를 보도록 ~/.coxpit 로 통일한다.
|
|
31
|
+
// 구버전(cwd 상대 ./coxpit.db)로 쌓아온 사용자는 그 파일이 존재하는 한 그대로 존중.
|
|
32
|
+
function defaultDbPath(): string {
|
|
33
|
+
const legacy = path.resolve('./coxpit.db');
|
|
34
|
+
if (fs.existsSync(legacy)) {
|
|
35
|
+
console.log(`[coxpit] using legacy database at ${legacy} (move it to ~/.coxpit/coxpit.db to adopt the shared default)`);
|
|
36
|
+
return legacy;
|
|
37
|
+
}
|
|
38
|
+
const dir = path.join(os.homedir(), '.coxpit');
|
|
39
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
40
|
+
return path.join(dir, 'coxpit.db');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dbPath = process.env.COXPIT_DB || defaultDbPath();
|
|
44
|
+
|
|
27
45
|
/** 런타임 설정. 시크릿은 전부 env 주입(번들 0). */
|
|
28
46
|
export const config = {
|
|
29
47
|
// UTF-8 보장된 로케일 — PTY/원격 셸에 명시 전달용
|
|
30
48
|
lang: process.env.LANG!,
|
|
31
49
|
host: process.env.COXPIT_HOST ?? '127.0.0.1',
|
|
32
50
|
port: Number(process.env.COXPIT_PORT ?? 8210),
|
|
33
|
-
dbPath
|
|
51
|
+
dbPath,
|
|
52
|
+
// 단일 데몬 락 파일 — DB 와 같은 폴더(그 DB 를 지키는 락이므로)
|
|
53
|
+
lockPath: path.join(path.dirname(path.resolve(dbPath)), 'daemon.lock.json'),
|
|
34
54
|
// 원격 머신 SSH 개인키 경로(선택). 없으면 ssh 기본 키/에이전트 사용.
|
|
35
55
|
sshKey: process.env.COXPIT_SSH_KEY ?? '',
|
|
36
56
|
// run 정착 시 POST 할 웹훅(선택) — 텔레그램 브릿지 등 사용자 연결용.
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { config } from './config';
|
|
2
2
|
import { db, ensureSchema } from './db';
|
|
3
3
|
import { machines } from './db/schema';
|
|
4
|
+
import { acquireDaemonLock } from './lock';
|
|
4
5
|
import { reconcileOrphanRuns } from './orchestrator';
|
|
5
6
|
import { buildServer } from './server';
|
|
6
7
|
|
|
8
|
+
// DB 를 열기 전에 단일 데몬 보장 — 이미 떠 있으면 그 URL 을 안내하고 종료.
|
|
9
|
+
await acquireDaemonLock();
|
|
10
|
+
|
|
7
11
|
await ensureSchema();
|
|
8
12
|
|
|
9
13
|
// 첫 실행 시 로컬 머신 시드(데몬이 도는 이 기계).
|
|
@@ -16,4 +20,12 @@ const orphans = await reconcileOrphanRuns();
|
|
|
16
20
|
if (orphans > 0) console.log(`[coxpit] settled ${orphans} orphaned run(s) from a previous daemon instance`);
|
|
17
21
|
|
|
18
22
|
const app = await buildServer();
|
|
19
|
-
|
|
23
|
+
try {
|
|
24
|
+
await app.listen({ host: config.host, port: config.port });
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if ((e as NodeJS.ErrnoException)?.code === 'EADDRINUSE') {
|
|
27
|
+
console.error(`[coxpit] port ${config.port} is already in use — is another daemon (or app) running? Set COXPIT_PORT to change.`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
package/src/lock.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { config } from './config';
|
|
3
|
+
|
|
4
|
+
// 단일 데몬 락 — DB 폴더의 daemon.lock.json.
|
|
5
|
+
// 두 데몬이 같은 DB 를 잡으면 부팅 시 reconcileOrphanRuns() 가 상대 데몬의
|
|
6
|
+
// 살아있는 run 을 고아로 정산해버린다. 락 + 헬스 프로브로 원천 차단한다.
|
|
7
|
+
|
|
8
|
+
interface LockInfo {
|
|
9
|
+
pid: number;
|
|
10
|
+
host: string;
|
|
11
|
+
port: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 해당 주소에 살아있는 coxpit 데몬이 있는지 확인 (/api/health 는 인증 면제). */
|
|
15
|
+
export async function probeCoxpit(host: string, port: number, timeoutMs = 1500): Promise<boolean> {
|
|
16
|
+
try {
|
|
17
|
+
const ac = new AbortController();
|
|
18
|
+
const t = setTimeout(() => ac.abort(), timeoutMs);
|
|
19
|
+
const res = await fetch(`http://${host === '0.0.0.0' ? '127.0.0.1' : host}:${port}/api/health`, { signal: ac.signal });
|
|
20
|
+
clearTimeout(t);
|
|
21
|
+
if (!res.ok) return false;
|
|
22
|
+
const body = (await res.json()) as { name?: string };
|
|
23
|
+
return body?.name === 'coxpit';
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readLock(lockPath: string): LockInfo | null {
|
|
30
|
+
try {
|
|
31
|
+
const raw = JSON.parse(fs.readFileSync(lockPath, 'utf8')) as LockInfo;
|
|
32
|
+
return Number.isInteger(raw?.pid) && Number.isInteger(raw?.port) ? raw : null;
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function pidAlive(pid: number): boolean {
|
|
39
|
+
try { process.kill(pid, 0); return true; } catch { return false; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 락 획득. 이미 살아있는 데몬이 같은 DB 를 잡고 있으면 안내 후 종료.
|
|
44
|
+
* 죽은 프로세스가 남긴 stale 락은 치우고 진행한다.
|
|
45
|
+
*/
|
|
46
|
+
export async function acquireDaemonLock(): Promise<void> {
|
|
47
|
+
const existing = readLock(config.lockPath);
|
|
48
|
+
if (existing && existing.pid !== process.pid) {
|
|
49
|
+
// pid 재사용 오탐을 피하려고 헬스 프로브를 진실로 삼는다.
|
|
50
|
+
const alive = pidAlive(existing.pid) && (await probeCoxpit(existing.host ?? '127.0.0.1', existing.port));
|
|
51
|
+
if (alive) {
|
|
52
|
+
const url = `http://${(existing.host ?? '127.0.0.1') === '0.0.0.0' ? '127.0.0.1' : existing.host}:${existing.port}/`;
|
|
53
|
+
console.error(
|
|
54
|
+
`[coxpit] another daemon already owns this database (pid ${existing.pid}, ${url}).\n` +
|
|
55
|
+
`[coxpit] open that URL instead, or stop it first — running two daemons on one DB corrupts live runs.`,
|
|
56
|
+
);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
try { fs.unlinkSync(config.lockPath); } catch { /* gone */ }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.writeFileSync(config.lockPath, JSON.stringify({ pid: process.pid, host: config.host, port: config.port } satisfies LockInfo));
|
|
63
|
+
|
|
64
|
+
const release = () => {
|
|
65
|
+
try {
|
|
66
|
+
const cur = readLock(config.lockPath);
|
|
67
|
+
if (cur?.pid === process.pid) fs.unlinkSync(config.lockPath);
|
|
68
|
+
} catch { /* best effort */ }
|
|
69
|
+
};
|
|
70
|
+
process.on('exit', release);
|
|
71
|
+
for (const sig of ['SIGINT', 'SIGTERM'] as const) {
|
|
72
|
+
process.on(sig, () => { release(); process.exit(0); });
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -33,7 +33,7 @@ export async function buildServer(): Promise<FastifyInstance> {
|
|
|
33
33
|
app.addHook('onRequest', authGate);
|
|
34
34
|
|
|
35
35
|
// 무인증 헬스(외부 감시용)
|
|
36
|
-
app.get('/api/health', async () => ({ ok: true, name: 'coxpit', version: '3.
|
|
36
|
+
app.get('/api/health', async () => ({ ok: true, name: 'coxpit', version: '3.3.0' }));
|
|
37
37
|
|
|
38
38
|
// 플릿 보드(단일 페이지). 인증 게이트 적용됨.
|
|
39
39
|
app.get('/', async (_req, reply) => reply.type('text/html').send(BOARD_HTML));
|