cohorte 3.2.0 → 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.
@@ -0,0 +1 @@
1
+ :root{color-scheme:dark;--font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;--font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;--bg-canvas: #0c0d0f;--bg-rail: #111215;--bg-input: #131417;--bg-card: #16181b;--bg-raised: #1c1f23;--bg-selected: #24272c;--bg-strong: #2a2d33;--line-subtle: #ffffff0f;--line-default: #ffffff1a;--line-strong: #ffffff38;--text-primary: #eceae5;--text-secondary: #d8d5cf;--text-muted: #a3a09a;--text-faint: #8a8781;--text-disabled: #6f6d68;--text-inverse: #111215;--action-primary: #eceae5;--state-running: #5ec8e5;--state-attention: #a897ff;--state-attention-text: #c3b8ff;--state-success: #5cc195;--state-success-text: #8fddb8;--state-danger: #ef7a6e;--state-danger-text: #f2a79e;--state-idle: #6f6d68;--state-info: #7aa2f7;--tint-running: #5ec8e51a;--tint-attention: #a897ff12;--tint-attention-line: #a897ff42;--tint-success: #5cc19517;--tint-success-line: #5cc19559;--tint-danger: #ef7a6e14;--tint-danger-line: #ef7a6e47;--bg-terminal: #09090b;--state-warn: #e0b45a;--state-warn-text: #ecc986;--tint-warn: #e0b45a14;--tint-warn-line: #e0b45a52;--tint-info: #7aa2f712;--diff-add-bg: var(--tint-success);--diff-add-text: var(--state-success-text);--diff-remove-bg: var(--tint-danger);--diff-remove-text: var(--state-danger-text);--diff-context-text: var(--text-faint);--overlay-scrim: #060708b8;--bg-popover: #1a1c20;--space-4: 4px;--space-6: 6px;--space-8: 8px;--space-10: 10px;--space-12: 12px;--space-16: 16px;--space-20: 20px;--space-24: 24px;--space-32: 32px;--radius-4: 4px;--radius-6: 6px;--radius-8: 8px;--radius-10: 10px;--shadow-float: 0 18px 48px 0 rgba(0, 0, 0, .5)}:root[data-theme=light]{color-scheme:light;--bg-canvas: #fafaf8;--bg-rail: #f3f2ef;--bg-input: #ffffff;--bg-card: #ffffff;--bg-raised: #e9e7e2;--bg-selected: #e2e0da;--bg-strong: #dad7d0;--line-subtle: #11121514;--line-default: #11121521;--line-strong: #11121540;--text-primary: #1a1b1e;--text-secondary: #3a3b3f;--text-muted: #5f5d58;--text-faint: #716e68;--text-disabled: #9a978f;--text-inverse: #f3f2ef;--action-primary: #1a1b1e;--state-running: #0b7fa0;--state-attention: #6b55e0;--state-attention-text: #5440c8;--state-success: #1e875a;--state-success-text: #1b7550;--state-danger: #c6443a;--state-danger-text: #ae3a30;--state-idle: #9a978f;--state-info: #3a62c8;--tint-running: #0b7fa01a;--tint-attention: #6b55e00f;--tint-attention-line: #6b55e04d;--tint-success: #1e875a14;--tint-success-line: #1e875a59;--tint-danger: #c6443a14;--tint-danger-line: #c6443a4d;--bg-terminal: #f5f4f1;--state-warn: #8f6a12;--state-warn-text: #7d5c0d;--tint-warn: #8f6a1214;--tint-warn-line: #8f6a1259;--tint-info: #3a62c812;--overlay-scrim: #11121566;--bg-popover: #ffffff;--shadow-float: 0 18px 48px 0 rgba(17, 18, 21, .16)}*{box-sizing:border-box}html,body,#root{margin:0;height:100%}body{background:var(--bg-canvas);color:var(--text-primary);font:400 13px/1.5 var(--font-ui);-webkit-font-smoothing:antialiased}h1{font-size:16px;font-weight:600;margin:0 0 14px;letter-spacing:-.01em}h2{font-size:16px;font-weight:600;margin:0 0 2px;letter-spacing:-.01em}.section{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--text-faint);margin:22px 0 8px}.section.plain{text-transform:none;letter-spacing:0;font-size:13px;color:var(--text-secondary)}.muted{color:var(--text-muted)}.mono{font-family:var(--font-mono);font-size:12px}.error{color:var(--state-danger-text)}.fix{color:var(--text-faint);font-size:12px}:focus-visible{outline:2px solid var(--state-info);outline-offset:1px}.layout{display:grid;grid-template-columns:280px 1fr;min-height:100%}.sidebar{background:var(--bg-rail);border-right:1px solid var(--line-subtle);padding:16px;overflow:auto}.main{padding:20px 32px 40px;overflow:auto;max-width:1180px;width:100%}.topbar{display:flex;justify-content:flex-end;align-items:center;gap:8px;margin-bottom:6px}.head-actions{margin-top:8px}.btn{display:inline-flex;align-items:center;gap:6px;padding:5px 10px;border:1px solid var(--line-default);border-radius:var(--radius-6);background:var(--bg-input);color:var(--text-primary);font:inherit;cursor:pointer}.btn:hover:not(:disabled){background:var(--bg-raised)}.btn:disabled{opacity:.45;cursor:not-allowed}.btn-primary{background:var(--action-primary);color:var(--text-inverse);border-color:transparent}.btn-primary:hover:not(:disabled){background:var(--action-primary);filter:brightness(.92)}.btn.icon{padding:5px 7px}input,select,textarea{padding:6px 8px;border:1px solid var(--line-default);border-radius:var(--radius-6);background:var(--bg-input);color:var(--text-primary);font:inherit}input[type=checkbox],input[type=radio]{padding:0;margin-right:6px}input{flex:1;min-width:0}textarea{width:100%;margin-bottom:6px;resize:vertical}.row-form{display:flex;gap:6px;margin:12px 0}.row-form.wrap{flex-wrap:wrap}.actions{display:flex;gap:6px;flex-wrap:wrap}.toolbar{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0}.proj{display:block;width:100%;text-align:left;background:none;border:1px solid transparent;border-radius:var(--radius-8);padding:8px 10px;margin-bottom:4px;color:inherit;cursor:pointer;font:inherit}.proj:hover{background:var(--bg-raised)}.proj.sel{background:var(--bg-selected);border-color:var(--line-default)}.proj-name{display:flex;gap:8px;align-items:center;font-weight:600}.proj .muted{display:block}.dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--state-idle);flex:none}.dot-ok{background:var(--state-success)}.dot-warn{background:var(--state-warn)}.dot-bad{background:var(--state-danger)}.sug{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:4px 0}.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line-subtle);margin:16px 0}.tab{padding:8px 12px;background:none;border:0;border-bottom:2px solid transparent;color:var(--text-muted);cursor:pointer;font:inherit}.tab:hover{color:var(--text-primary)}.tab.sel{color:var(--text-primary);border-color:var(--action-primary)}.table{width:100%;border-collapse:collapse}.table th,.table td{text-align:left;padding:7px 10px;border-bottom:1px solid var(--line-subtle);vertical-align:top}.table th{font-size:12px;color:var(--text-faint);font-weight:500}.table tr.click{cursor:pointer}.table tr.click:hover{background:var(--bg-raised)}.pill{display:inline-block;padding:0 8px;border-radius:10px;border:1px solid var(--line-default);font-size:12px;color:var(--text-secondary)}.pill-ok{color:var(--state-success-text);border-color:var(--tint-success-line);background:var(--tint-success)}.pill-warn{color:var(--state-warn-text);border-color:var(--tint-warn-line);background:var(--tint-warn)}.pill-bad{color:var(--state-danger-text);border-color:var(--tint-danger-line);background:var(--tint-danger)}.pill-info{color:var(--state-info)}.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:10px}.card{border:1px solid var(--line-default);border-radius:var(--radius-8);padding:10px 12px;background:var(--bg-card)}.card-ok{border-color:var(--tint-success-line)}.card-warn{border-color:var(--tint-warn-line)}.card-bad{border-color:var(--tint-danger-line)}.stat{text-align:left;font:inherit;color:inherit}.stat-v{font-size:20px;font-weight:600;letter-spacing:-.01em}.card-ok .stat-v{color:var(--state-success-text)}.card-warn .stat-v{color:var(--state-warn-text)}.card-bad .stat-v{color:var(--state-danger-text)}.link{cursor:pointer}.link:hover{border-color:var(--line-strong)}.gate{margin:10px 0}.gate p{margin:6px 0}.pre{background:var(--bg-terminal);border:1px solid var(--line-subtle);border-radius:var(--radius-8);padding:12px;overflow:auto;white-space:pre-wrap;font:12px/1.5 var(--font-mono);margin:8px 0}.pre-max{max-height:480px}.empty{padding:48px 0;text-align:center;color:var(--text-muted)}.spec-title{margin-top:12px}.feed{margin-top:10px}.ev{padding:3px 0;white-space:pre-wrap;word-break:break-word}.reply{border-left:3px solid var(--state-attention);padding-left:8px}.reply-box{margin-top:14px}.q{border:0;padding:0;margin:8px 0}.q legend{font-weight:600;padding:0}.opt{display:block;cursor:pointer}.other{margin-top:4px;width:100%}.layout .empty{grid-column:1/-1}@media (max-width:860px){.layout{grid-template-columns:1fr}.sidebar{border-right:0;border-bottom:1px solid var(--line-subtle)}.main{padding:16px}}.stat-v.small{font-size:13px;letter-spacing:0;word-break:break-all}.sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.nowrap{white-space:nowrap}.gap-top{margin-top:4px}.toolbar.between{justify-content:space-between;align-items:center}.table tr.current{background:var(--bg-selected)}.disclose{margin:14px 0}.disclose summary{cursor:pointer;color:var(--text-muted)}.disclose summary:hover{color:var(--text-primary)}.brand{background:none;border:0;padding:0;color:inherit;font:inherit;font-weight:600;cursor:pointer;letter-spacing:-.01em}.brand:hover{text-decoration:underline}.stepper{display:flex;gap:4px;list-style:none;margin:0;padding:0;flex-wrap:wrap}.step{display:inline-flex;align-items:center;gap:5px;padding:1px 8px 1px 6px;border-radius:10px;border:1px solid var(--line-default);font-size:12px;color:var(--text-faint)}.step-mark{display:inline-block;min-width:10px;text-align:center;font-size:10px;line-height:1}.step-done{color:var(--state-success-text);border-color:var(--tint-success-line);background:var(--tint-success)}.step-current{color:var(--state-running);border-color:var(--state-running);background:var(--tint-running)}.step-blocked{color:var(--state-danger-text);border-color:var(--tint-danger-line);background:var(--tint-danger)}.step-skipped{color:var(--text-faint);border-style:dashed}.spec-head{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin:12px 0}.next{display:inline-flex;gap:6px;align-items:center;flex-wrap:wrap}.seg-group{display:inline-flex;border:1px solid var(--line-default);border-radius:var(--radius-6);overflow:hidden}.seg{display:inline-flex;align-items:center;gap:5px;padding:4px 10px;background:var(--bg-input);color:var(--text-muted);border:0;font:inherit;cursor:pointer}.seg+.seg{border-left:1px solid var(--line-default)}.seg.sel{background:var(--bg-selected);color:var(--text-primary)}.seg:hover:not(.sel){background:var(--bg-raised)}.board{display:grid;grid-template-columns:repeat(6,minmax(170px,1fr));gap:10px;overflow-x:auto;align-items:start;padding-bottom:6px}.col{background:var(--bg-rail);border:1px solid var(--line-subtle);border-radius:var(--radius-8);padding:8px;min-height:90px}.col-head{display:flex;justify-content:space-between;margin:0 0 8px;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--text-faint)}.count{font-weight:500;color:var(--text-muted)}.spec-card{background:var(--bg-card);border:1px solid var(--line-default);border-radius:var(--radius-8);padding:8px 10px;margin-bottom:8px;display:flex;flex-direction:column;gap:6px;cursor:pointer}.spec-card:hover{border-color:var(--line-strong)}.spec-card-meta{display:flex;gap:6px;flex-wrap:wrap}.sev-strip{display:flex;gap:14px;margin:6px 0 10px;flex-wrap:wrap}.sev{color:var(--text-secondary)}.sev.zero{color:var(--text-faint)}.sev-critical:not(.zero),.sev-high:not(.zero){color:var(--state-danger-text)}.sev-medium:not(.zero){color:var(--state-warn-text)}.rc{grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}.rc-head{display:flex;justify-content:space-between;gap:8px;margin-bottom:6px}.rc-row{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}.rc-list{margin:8px 0 0;padding-left:18px}.rc-list li{margin:3px 0}.git-state{display:flex;gap:8px;align-items:center;flex-wrap:wrap;font-size:12px}.last-commit{font-size:12px;margin-top:2px;max-width:420px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.add{color:var(--diff-add-text)}.del{color:var(--diff-remove-text)}.pr-chip{text-decoration:none}a.pr-chip:hover{border-color:var(--line-strong)}.pill-idle{color:var(--text-muted)}.open-links{display:flex;flex-direction:column;gap:2px;margin-top:4px}.open-link{color:var(--state-info);text-decoration:none}.open-link:hover{text-decoration:underline}.diff-panel{margin-top:6px}.diff-grid{display:grid;grid-template-columns:minmax(200px,300px) 1fr;gap:12px;align-items:start}.file-list{list-style:none;margin:0;padding:0;border:1px solid var(--line-subtle);border-radius:var(--radius-8);max-height:520px;overflow:auto;background:var(--bg-rail)}.file{display:flex;gap:8px;align-items:center;width:100%;text-align:left;background:none;border:0;border-bottom:1px solid var(--line-subtle);padding:5px 8px;color:inherit;cursor:pointer;font:inherit;word-break:break-all}.file:hover{background:var(--bg-raised)}.file.sel{background:var(--bg-selected)}.badge{display:inline-flex;align-items:center;justify-content:center;min-width:16px;height:16px;border-radius:4px;font:600 10px var(--font-mono);flex:none;background:var(--bg-strong);color:var(--text-secondary)}.badge-added,.badge-untracked{background:var(--tint-success);color:var(--diff-add-text)}.badge-deleted{background:var(--tint-danger);color:var(--diff-remove-text)}.badge-modified,.badge-renamed,.badge-changed{background:var(--tint-info);color:var(--state-info)}.diff{background:var(--bg-terminal);border:1px solid var(--line-subtle);border-radius:var(--radius-8);padding:8px 0;overflow:auto;max-height:560px;margin:0;font:12px/1.5 var(--font-mono)}.dl{padding:0 12px;white-space:pre;min-width:max-content}.dl-add{background:var(--diff-add-bg);color:var(--diff-add-text)}.dl-remove{background:var(--diff-remove-bg);color:var(--diff-remove-text)}.dl-hunk{background:var(--tint-info);color:var(--state-info)}.dl-meta,.dl-context{color:var(--diff-context-text)}.dl-context{color:var(--text-secondary)}@media (max-width:1000px){.diff-grid{grid-template-columns:1fr}}.live{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--text-muted);margin-right:auto}.live-dot{width:7px;height:7px;border-radius:50%;background:var(--state-idle)}.live-live .live-dot{background:var(--state-success)}.live-reconnecting .live-dot,.live-connecting .live-dot{background:var(--state-warn)}.live-polling .live-dot{background:var(--state-idle)}.kbd{font:11px var(--font-mono);color:var(--text-muted);border:1px solid var(--line-default);border-radius:4px;padding:0 5px;background:var(--bg-input)}.btn.icon .kbd{border:0;background:none;padding:0}.badge-attn,.badge-run{margin-left:auto;font:600 11px var(--font-mono);border-radius:9px;padding:0 6px}.badge-attn{background:var(--state-attention);color:var(--text-inverse)}.badge-run{background:var(--tint-running);color:var(--state-running);border:1px solid var(--state-running)}.home-cards{grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}.home-card{display:flex;flex-direction:column;gap:6px;text-align:left}.home-line{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.home-chips{display:flex;gap:5px;flex-wrap:wrap;margin-top:2px}.activity{list-style:none;margin:0;padding:0}.act-row{display:flex;gap:10px;align-items:center;width:100%;text-align:left;background:none;border:0;border-bottom:1px solid var(--line-subtle);padding:7px 6px;color:inherit;cursor:pointer;font:inherit}.act-row:hover{background:var(--bg-raised)}.act-proj{min-width:110px}.act-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.overlay{position:fixed;inset:0;background:var(--overlay-scrim);display:flex;align-items:flex-start;justify-content:center;padding-top:12vh;z-index:50}.dialog{background:var(--bg-popover,var(--bg-card));border:1px solid var(--line-default);border-radius:var(--radius-10);box-shadow:var(--shadow-float);padding:16px;width:min(560px,92vw)}.palette{padding:0;overflow:hidden}.palette input{width:100%;border:0;border-bottom:1px solid var(--line-subtle);border-radius:0;padding:12px 14px;font-size:14px;background:transparent}.palette-list{list-style:none;margin:0;padding:6px;max-height:50vh;overflow:auto}.palette-group{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--text-faint);padding:8px 8px 4px}.palette-item{display:flex;justify-content:space-between;gap:12px;padding:6px 8px;border-radius:var(--radius-6);cursor:pointer}.palette-item.sel{background:var(--bg-selected)}.palette-hint{max-width:55%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.palette-empty{padding:14px;text-align:center;color:var(--text-muted)}.shortcuts{display:grid;grid-template-columns:1fr 1fr;gap:6px 18px;margin:12px 0}.shortcuts div{display:flex;gap:10px;align-items:center}.shortcuts dt{min-width:84px;text-align:center}.shortcuts dd{margin:0}.spec-card .btn{font-size:12px;text-align:left;white-space:normal;align-self:flex-start}.rc{grid-template-columns:repeat(auto-fill,minmax(320px,1fr))}.rc-head{flex-wrap:wrap;align-items:baseline}.rc-head .mono{font-size:11px}
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="color-scheme" content="dark light">
7
+ <title>Cohorte</title>
8
+ <link rel="icon" href="data:,">
9
+ <script type="module" crossorigin src="./assets/index-Clp1YW4S.js"></script>
10
+ <link rel="stylesheet" crossorigin href="./assets/style-0oNNMjwU.css">
11
+ </head>
12
+ <body>
13
+ <div id="root"></div>
14
+ </body>
15
+ </html>
package/ui/docker.js DELETED
@@ -1,147 +0,0 @@
1
- 'use strict';
2
- // cohorte ui — the project's Docker Compose stack: what is up, and the few things the dashboard may do to it.
3
- //
4
- // Same rules as ops.js:
5
- // - the compose file is the one the profile declares (isolation.compose_file) or a conventional name at the
6
- // repo root, resolved INSIDE the repo — never a path from the client;
7
- // - the verbs are fixed (up -d, stop, restart, down, logs); `down` never takes -v, so volumes (the data) stay;
8
- // - a service name from the client is only accepted when `docker compose config --services` lists it;
9
- // - the project's gate is asked first, like every other command this dashboard launches.
10
- // Reads (daemon, ps) never go through a shell and are bounded by a timeout so a hung daemon cannot hang the page.
11
-
12
- const fs = require('fs');
13
- const path = require('path');
14
- const { spawn } = require('child_process');
15
- const { OpError, gateVerdict, confirm, readProfile } = require('./ops.js');
16
-
17
- const CANDIDATES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
18
- const ACTIONS = ['up', 'stop', 'restart', 'down', 'logs'];
19
- const bin = () => process.env.COHORTE_DOCKER_BIN || 'docker';
20
- const realOr = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
21
-
22
- // { file, rel } or null. The declared file wins; it must stay inside the repo.
23
- function composeFile(root) {
24
- const declared = ((readProfile(root).isolation || {}).compose_file);
25
- const names = typeof declared === 'string' && declared.trim() ? [declared.trim(), ...CANDIDATES] : CANDIDATES;
26
- const base = realOr(root);
27
- for (const n of names) {
28
- if (path.isAbsolute(n)) continue;
29
- const file = realOr(path.join(root, n));
30
- if (!file.startsWith(base + path.sep)) continue;
31
- try { if (fs.statSync(file).isFile()) return { file, rel: path.relative(base, file) }; } catch { /* next */ }
32
- }
33
- return null;
34
- }
35
-
36
- // Async, bounded, no shell. Resolves { code, out, err, missing } — never rejects.
37
- function exec(args, { cwd, timeout = 8000 } = {}) {
38
- return new Promise((resolve) => {
39
- let out = ''; let err = ''; let done = false;
40
- const finish = (r) => { if (!done) { done = true; clearTimeout(timer); resolve({ out, err, ...r }); } };
41
- let child;
42
- try { child = spawn(bin(), args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] }); } catch (e) { return resolve({ code: -1, out, err: e.message, missing: e.code === 'ENOENT' }); }
43
- const timer = setTimeout(() => { try { child.kill('SIGKILL'); } catch { /* gone */ } finish({ code: -1, timedOut: true }); }, timeout);
44
- child.stdout.on('data', (d) => { out += d; if (out.length > 2e6) out = out.slice(-2e6); });
45
- child.stderr.on('data', (d) => { err += d; if (err.length > 2e5) err = err.slice(-2e5); });
46
- child.on('error', (e) => finish({ code: -1, missing: e.code === 'ENOENT', err: e.message }));
47
- child.on('close', (code) => finish({ code }));
48
- });
49
- }
50
-
51
- const firstLine = (s) => String(s || '').trim().split(/\r?\n/).find((l) => l.trim()) || '';
52
-
53
- // `docker compose ps --format json` prints one object per line on recent versions, a JSON array on older ones.
54
- function parsePs(out) {
55
- const text = String(out || '').trim();
56
- if (!text) return [];
57
- let rows = [];
58
- try { const v = JSON.parse(text); rows = Array.isArray(v) ? v : [v]; } catch {
59
- for (const l of text.split(/\r?\n/)) { try { rows.push(JSON.parse(l)); } catch { /* not a row */ } }
60
- }
61
- return rows.filter((r) => r && typeof r === 'object');
62
- }
63
-
64
- function portsOf(row) {
65
- const pubs = Array.isArray(row.Publishers) ? row.Publishers : [];
66
- const seen = new Set();
67
- for (const p of pubs) if (p && p.PublishedPort) seen.add(`${p.PublishedPort}→${p.TargetPort}`);
68
- return [...seen];
69
- }
70
-
71
- async function daemon() {
72
- const r = await exec(['info', '--format', '{{.ServerVersion}}'], { timeout: 6000 });
73
- if (r.missing) return { installed: false, up: false, error: 'the docker CLI is not installed (or not on PATH)' };
74
- if (r.timedOut) return { installed: true, up: false, error: 'the Docker daemon did not answer in time' };
75
- if (r.code !== 0) return { installed: true, up: false, error: firstLine(r.err) || 'the Docker daemon is not running' };
76
- return { installed: true, up: true, version: firstLine(r.out) };
77
- }
78
-
79
- // Everything the Docker tab shows. Each part degrades alone: no daemon still lists the declared services.
80
- async function status(root) {
81
- const cf = composeFile(root);
82
- if (!cf) return { configured: false };
83
- const [d, cfg] = await Promise.all([daemon(), exec(['compose', '-f', cf.file, 'config', '--services'], { cwd: root })]);
84
- const defined = cfg.code === 0 ? cfg.out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean) : [];
85
- const out = { configured: true, file: cf.rel, daemon: d, services: [], configError: cfg.code === 0 ? null : firstLine(cfg.err) || 'docker compose could not read the file' };
86
- let rows = [];
87
- if (d.up && defined.length) {
88
- const ps = await exec(['compose', '-f', cf.file, 'ps', '-a', '--format', 'json'], { cwd: root });
89
- if (ps.code === 0) rows = parsePs(ps.out); else out.psError = firstLine(ps.err);
90
- }
91
- const by = new Map();
92
- for (const r of rows) by.set(r.Service || r.Name, r);
93
- const names = defined.length ? defined : [...by.keys()];
94
- out.services = names.map((name) => {
95
- const r = by.get(name);
96
- if (!r) return { name, state: d.up ? 'not created' : 'unknown', health: '', status: '', ports: [], image: '' };
97
- return { name, state: String(r.State || '').toLowerCase() || 'unknown', health: String(r.Health || '').toLowerCase(), status: String(r.Status || ''), ports: portsOf(r), image: String(r.Image || '') };
98
- });
99
- out.running = out.services.filter((s) => s.state === 'running').length;
100
- return out;
101
- }
102
-
103
- // Starts up/stop/restart/down/logs as a job. Returns the job.
104
- async function act(jobs, project, { action, service, confirmed = false }) {
105
- if (!ACTIONS.includes(action)) throw new OpError(`action must be one of ${ACTIONS.join(', ')}`);
106
- const cf = composeFile(project.root);
107
- if (!cf) throw new OpError('this project declares no compose file (isolation.compose_file)', 400);
108
- const d = await daemon();
109
- if (!d.up) throw new OpError(d.error || 'the Docker daemon is not running', 409, { dockerDown: true });
110
- let svc = null;
111
- if (service !== undefined && service !== null && service !== '') {
112
- if (action === 'down') throw new OpError('down applies to the whole stack');
113
- const cfg = await exec(['compose', '-f', cf.file, 'config', '--services'], { cwd: project.root });
114
- const defined = cfg.out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
115
- if (typeof service !== 'string' || !defined.includes(service)) throw new OpError('not a service of this compose file', 404);
116
- svc = service;
117
- }
118
- const verb = { up: ['up', '-d'], stop: ['stop'], restart: ['restart'], down: ['down'], logs: ['logs', '--no-color', '--tail', '200', '-f'] }[action];
119
- const args = ['compose', '-f', cf.file, ...verb, ...(svc ? [svc] : [])];
120
- const shown = `docker compose -f ${cf.rel} ${verb.join(' ')}${svc ? ` ${svc}` : ''}`;
121
- const kind = action === 'logs' ? 'docker-logs' : 'docker';
122
- const tag = action === 'logs' ? (svc || '*') : 'stack';
123
- if (jobs.find(project.id, kind, tag)) throw new OpError(action === 'logs' ? 'these logs are already being followed' : 'a docker command is already running for this project', 409);
124
- confirm(gateVerdict(project.root, shown, project.root), confirmed, shown);
125
- return jobs.start({ projectId: project.id, kind, tag, label: `docker · ${verb[0]}${svc ? ` ${svc}` : ''}`, cwd: project.root, file: bin(), args, command: undefined, display: shown });
126
- }
127
-
128
- // Before `scripts/new-feature.sh`: the script creates the worktree's database INSIDE a compose service
129
- // (`docker compose exec -T postgres …`), so it fails — late and obscurely — when Docker or that service is down.
130
- // Returns null when the script needs nothing, else { ok, reason, services, missing }.
131
- async function preflight(root) {
132
- const cf = composeFile(root);
133
- let script = '';
134
- try { script = fs.readFileSync(path.join(root, 'scripts', 'new-feature.sh'), 'utf8'); } catch { return null; }
135
- if (!cf || !/\bdocker\b/.test(script)) return null;
136
- const needs = new Set();
137
- const re = /docker\s+compose[^\n]*?\bexec\b\s+(?:-[A-Za-z-]+\s+)*([A-Za-z][\w.-]*)/g;
138
- for (let m = re.exec(script); m; m = re.exec(script)) needs.add(m[1]);
139
- const s = await status(root);
140
- if (!s.daemon.installed) return { ok: false, reason: s.daemon.error, services: [...needs], missing: [...needs], daemonUp: false };
141
- if (!s.daemon.up) return { ok: false, reason: `${s.daemon.error || 'the Docker daemon is not running'} — scripts/new-feature.sh needs it to create the worktree's database`, services: [...needs], missing: [...needs], daemonUp: false };
142
- const down = [...needs].filter((n) => { const x = s.services.find((v) => v.name === n); return !x || x.state !== 'running'; });
143
- if (down.length) return { ok: false, reason: `scripts/new-feature.sh runs commands inside ${down.join(', ')}, which ${down.length > 1 ? 'are' : 'is'} not running`, services: [...needs], missing: down, daemonUp: true };
144
- return { ok: true, services: [...needs], missing: [], daemonUp: true };
145
- }
146
-
147
- module.exports = { composeFile, status, act, preflight, ACTIONS, parsePs };
package/ui/jobs.js DELETED
@@ -1,127 +0,0 @@
1
- 'use strict';
2
- // cohorte ui — child processes the dashboard starts (dev servers, worktree scripts).
3
- //
4
- // A job is one command in one folder, in its own process group so that stopping it stops the whole
5
- // tree (a dev server spawns children). Output is kept in a bounded ring buffer that clients poll with a
6
- // cursor. Nothing here accepts a command from a client: callers pass commands that came from the
7
- // project's own profile or from fixed git invocations, after the project's gate had its say.
8
-
9
- const http = require('http');
10
- const https = require('https');
11
- const crypto = require('crypto');
12
- const { spawn } = require('child_process');
13
-
14
- const MAX_LINES = 2000;
15
- const MAX_LINE = 4000;
16
- const KILL_GRACE_MS = 4000;
17
-
18
- function killTree(child, signal) {
19
- if (!child || child.exitCode !== null || child.signalCode) return;
20
- try {
21
- if (process.platform === 'win32') spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore' });
22
- else process.kill(-child.pid, signal);
23
- } catch { /* already gone */ }
24
- }
25
-
26
- function probeOnce(target, cwd) {
27
- return new Promise((resolve) => {
28
- if (/^https?:\/\//i.test(target)) {
29
- const lib = target.startsWith('https') ? https : http;
30
- const req = lib.get(target, { timeout: 1500 }, (res) => { res.resume(); resolve(res.statusCode >= 200 && res.statusCode < 400); });
31
- req.on('timeout', () => { req.destroy(); resolve(false); });
32
- req.on('error', () => resolve(false));
33
- } else {
34
- const c = spawn(target, { shell: true, cwd, stdio: 'ignore' });
35
- const t = setTimeout(() => c.kill(), 5000);
36
- c.on('close', (code) => { clearTimeout(t); resolve(code === 0); });
37
- c.on('error', () => { clearTimeout(t); resolve(false); });
38
- }
39
- });
40
- }
41
-
42
- class Jobs {
43
- constructor() { this.jobs = new Map(); }
44
-
45
- // opts: { projectId, kind, label, cwd, command (shell string) | file+args (+ display: what to show), ready, readyTimeoutMs, tag, env }
46
- start(opts) {
47
- const id = crypto.randomBytes(4).toString('hex');
48
- const job = {
49
- id, projectId: opts.projectId, kind: opts.kind, label: opts.label, cwd: opts.cwd, tag: opts.tag || null,
50
- command: opts.display || opts.command || [opts.file, ...(opts.args || [])].join(' '),
51
- status: 'starting', pid: null, startedAt: new Date().toISOString(), endedAt: null, exitCode: null,
52
- lines: [], dropped: 0, stopping: false, child: null,
53
- };
54
- const push = (chunk) => {
55
- for (const raw of String(chunk).split(/\r?\n/)) {
56
- if (raw === '') continue;
57
- job.lines.push(raw.length > MAX_LINE ? `${raw.slice(0, MAX_LINE)}…` : raw);
58
- }
59
- if (job.lines.length > MAX_LINES) { const cut = job.lines.length - MAX_LINES; job.lines.splice(0, cut); job.dropped += cut; }
60
- };
61
- const child = opts.command
62
- ? spawn(opts.command, { shell: true, cwd: opts.cwd, detached: process.platform !== 'win32', stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, ...(opts.env || {}) } })
63
- : spawn(opts.file, opts.args || [], { cwd: opts.cwd, detached: process.platform !== 'win32', stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, ...(opts.env || {}) } });
64
- job.child = child;
65
- job.pid = child.pid || null;
66
- job.status = 'running';
67
- child.stdout.on('data', push);
68
- child.stderr.on('data', push);
69
- child.on('error', (e) => { push(`[cohorte ui] could not start: ${e.message}`); job.status = 'failed'; job.endedAt = new Date().toISOString(); });
70
- child.on('close', (code, signal) => {
71
- job.exitCode = code;
72
- job.endedAt = new Date().toISOString();
73
- job.status = job.stopping ? 'stopped' : code === 0 ? 'done' : 'failed';
74
- if (signal && !job.stopping) push(`[cohorte ui] killed by ${signal}`);
75
- clearTimeout(job.readyTimer);
76
- });
77
- if (opts.ready) this.#waitReady(job, opts.ready, opts.readyTimeoutMs || 90000);
78
- this.jobs.set(id, job);
79
- return job;
80
- }
81
-
82
- async #waitReady(job, target, timeoutMs) {
83
- const until = Date.now() + timeoutMs;
84
- while (job.status === 'running' && Date.now() < until) {
85
- if (await probeOnce(target, job.cwd)) { if (job.status === 'running') job.status = 'ready'; return; }
86
- await new Promise((r) => { job.readyTimer = setTimeout(r, 1000); });
87
- }
88
- if (job.status === 'running') job.lines.push(`[cohorte ui] not ready after ${Math.round(timeoutMs / 1000)}s (still running) — probe: ${target}`);
89
- }
90
-
91
- isLive(job) { return job.status === 'running' || job.status === 'ready' || job.status === 'starting'; }
92
-
93
- find(projectId, kind, tag) {
94
- return [...this.jobs.values()].reverse().find((j) => j.projectId === projectId && j.kind === kind && j.tag === tag && this.isLive(j)) || null;
95
- }
96
-
97
- get(id) { return this.jobs.get(id) || null; }
98
-
99
- forProject(projectId) { return [...this.jobs.values()].filter((j) => j.projectId === projectId); }
100
-
101
- stop(job) {
102
- if (!this.isLive(job)) return false;
103
- job.stopping = true;
104
- killTree(job.child, 'SIGTERM');
105
- const t = setTimeout(() => killTree(job.child, 'SIGKILL'), KILL_GRACE_MS);
106
- t.unref();
107
- return true;
108
- }
109
-
110
- stopAll() {
111
- for (const j of this.jobs.values()) if (this.isLive(j)) { j.stopping = true; killTree(j.child, 'SIGTERM'); }
112
- }
113
-
114
- view(job, since) {
115
- const out = { id: job.id, kind: job.kind, label: job.label, cwd: job.cwd, tag: job.tag, command: job.command, status: job.status,
116
- pid: job.pid, startedAt: job.startedAt, endedAt: job.endedAt, exitCode: job.exitCode };
117
- if (since !== undefined) {
118
- const total = job.dropped + job.lines.length;
119
- const from = Math.max(0, since - job.dropped);
120
- out.lines = job.lines.slice(from);
121
- out.cursor = total;
122
- }
123
- return out;
124
- }
125
- }
126
-
127
- module.exports = { Jobs };
package/ui/ops.js DELETED
@@ -1,164 +0,0 @@
1
- 'use strict';
2
- // cohorte ui — what the dashboard can DO to a project: provision / remove a worktree, start a dev server.
3
- //
4
- // Rules, each one a thing the HTTP layer must not be trusted with:
5
- // - the command that runs is never client-supplied: it is the project's own `commands.dev` or its own
6
- // isolation scripts, or a fixed git invocation;
7
- // - the project's gate (.claude/hooks/cohorte-gate.py --check) is asked first, like verify-run.sh does:
8
- // `deny` refuses, `ask` needs an explicit confirmation from the human;
9
- // - a worktree is addressed by a path that `git worktree list` reports for that repo;
10
- // - the main checkout is never removed, and removal never forces (a dirty tree is refused by git).
11
-
12
- const fs = require('fs');
13
- const path = require('path');
14
- const { spawnSync } = require('child_process');
15
- const registry = require('../lib/registry.js');
16
- const { checkTrust } = require('../lib/doctor.js');
17
- const { parseProfileBlock } = require('../lib/yaml.js');
18
-
19
- const FEATURE_ID = /^[a-z0-9][a-z0-9-]{0,62}$/;
20
- class OpError extends Error { constructor(message, code = 400, extra = {}) { super(message); this.code = code; Object.assign(this, extra); } }
21
-
22
- // git reports `C:/x/y` where Node says `C:\x\y` (and 8.3 short names, and drive-letter case) on Windows:
23
- // compare paths through the native realpath, normalized, case-insensitively there.
24
- const realOr = (p) => {
25
- let r;
26
- try { r = fs.realpathSync.native(p); } catch { r = path.resolve(p); }
27
- r = path.normalize(r);
28
- return process.platform === 'win32' ? r.toLowerCase() : r;
29
- };
30
- const git = (cwd, ...a) => spawnSync('git', ['-C', cwd, ...a], { encoding: 'utf8' });
31
-
32
- function readProfile(root) {
33
- try { return JSON.parse(fs.readFileSync(path.join(root, '.claude', 'profile.json'), 'utf8')); } catch { /* fall through */ }
34
- try { return parseProfileBlock(fs.readFileSync(path.join(root, 'PIPELINE.md'), 'utf8')) || {}; } catch { return {}; }
35
- }
36
-
37
- // 'allow' | 'ask' | 'deny' + the gate's own words. No gate file ⇒ allow (nothing to ask).
38
- function gateVerdict(root, command, cwd) {
39
- const gate = path.join(root, '.claude', 'hooks', 'cohorte-gate.py');
40
- if (!fs.existsSync(gate)) return { verdict: 'allow', reason: '' };
41
- const r = spawnSync('python3', [gate, '--check', '--cwd', cwd || root, '--', command], { encoding: 'utf8', timeout: 15000 });
42
- if (r.error) return { verdict: 'ask', reason: `the gate could not run (${r.error.message})` };
43
- const reason = (r.stdout || '').trim();
44
- return { verdict: r.status === 0 ? 'allow' : r.status === 2 ? 'deny' : 'ask', reason };
45
- }
46
-
47
- function isolationScripts(root) {
48
- const has = (n) => fs.existsSync(path.join(root, 'scripts', n));
49
- return { create: has('new-feature.sh'), remove: has('remove-feature.sh') };
50
- }
51
-
52
- function devInfo(root) {
53
- const c = (readProfile(root).commands || {});
54
- return { command: typeof c.dev === 'string' && c.dev.trim() ? c.dev.trim() : null,
55
- ready: typeof c.dev_ready === 'string' && c.dev_ready.trim() ? c.dev_ready.trim() : null };
56
- }
57
-
58
- function resolveWorktree(root, wtPath) {
59
- if (typeof wtPath !== 'string') throw new OpError('a worktree path is required');
60
- const want = realOr(wtPath);
61
- const wt = registry.worktrees(root).find((w) => realOr(w.path) === want);
62
- if (!wt) throw new OpError('not a worktree of this project', 404);
63
- return wt;
64
- }
65
-
66
- function confirm(verdict, confirmed, command) {
67
- if (verdict.verdict === 'deny') throw new OpError(`the project's gate refuses this command: ${verdict.reason}`, 403);
68
- if (verdict.verdict === 'ask' && !confirmed) {
69
- throw new OpError('the project gate asks for confirmation', 409, { needsConfirmation: true, command, reason: verdict.reason });
70
- }
71
- }
72
-
73
- function startDev(jobs, project, wtPath, { confirmed = false } = {}) {
74
- const wt = resolveWorktree(project.root, wtPath);
75
- const dev = devInfo(project.root);
76
- if (!dev.command) throw new OpError('this project declares no commands.dev in its profile', 400);
77
- if (jobs.find(project.id, 'dev', wt.path)) throw new OpError('a dev server is already running in this worktree', 409);
78
- confirm(gateVerdict(project.root, dev.command, wt.path), confirmed, dev.command);
79
- return jobs.start({ projectId: project.id, kind: 'dev', tag: wt.path, label: `dev · ${path.basename(wt.path)}`, cwd: wt.path,
80
- command: dev.command, ready: dev.ready });
81
- }
82
-
83
- function stopJob(jobs, project, jobId) {
84
- const job = jobs.get(jobId);
85
- if (!job || job.projectId !== project.id) throw new OpError('unknown job', 404);
86
- return jobs.stop(job);
87
- }
88
-
89
- function createWorktree(jobs, project, feature, { confirmed = false } = {}) {
90
- if (typeof feature !== 'string' || !FEATURE_ID.test(feature)) throw new OpError('the feature id must be kebab-case (a-z, 0-9, -; at most 63 chars)');
91
- const root = project.root;
92
- const scripts = isolationScripts(root);
93
- const label = `worktree · ${feature}`;
94
- if (scripts.create) {
95
- const command = `scripts/new-feature.sh ${feature}`;
96
- confirm(gateVerdict(root, command, root), confirmed, command);
97
- return jobs.start({ projectId: project.id, kind: 'worktree-create', tag: feature, label, cwd: root, file: 'bash', args: ['scripts/new-feature.sh', feature] });
98
- }
99
- // No isolation script: a plain sibling worktree on a new branch, off the remote default branch when there is one.
100
- const profile = readProfile(root);
101
- const vcs = profile.vcs || {};
102
- const prefix = typeof vcs.feature_branch_prefix === 'string' ? vcs.feature_branch_prefix : 'feature/';
103
- const def = typeof vcs.default_branch === 'string' && vcs.default_branch ? vcs.default_branch : 'main';
104
- const base = git(root, 'rev-parse', '--verify', '-q', `origin/${def}`).status === 0 ? `origin/${def}` : 'HEAD';
105
- const dir = path.join(path.dirname(root), `${path.basename(root)}-${feature}`);
106
- if (fs.existsSync(dir)) throw new OpError(`${dir} already exists`, 409);
107
- return jobs.start({ projectId: project.id, kind: 'worktree-create', tag: feature, label, cwd: root,
108
- file: 'git', args: ['worktree', 'add', '-b', `${prefix}${feature}`, dir, base] });
109
- }
110
-
111
- function removeWorktree(jobs, project, wtPath, { confirmed = false } = {}) {
112
- const root = project.root;
113
- const all = registry.worktrees(root);
114
- const wt = resolveWorktree(root, wtPath);
115
- if (all[0] && realOr(all[0].path) === realOr(wt.path)) throw new OpError('the main checkout cannot be removed', 400);
116
- if (jobs.find(project.id, 'dev', wt.path)) throw new OpError('stop the dev server in this worktree first', 409);
117
- const label = `remove · ${path.basename(wt.path)}`;
118
- const scripts = isolationScripts(root);
119
- const prefix = ((readProfile(root).vcs || {}).feature_branch_prefix) || 'feature/';
120
- const id = wt.branch && wt.branch.startsWith(prefix) ? wt.branch.slice(prefix.length) : null;
121
- if (scripts.remove && id && FEATURE_ID.test(id)) {
122
- const command = `scripts/remove-feature.sh ${id}`;
123
- confirm(gateVerdict(root, command, root), confirmed, command);
124
- return jobs.start({ projectId: project.id, kind: 'worktree-remove', tag: wt.path, label, cwd: root, file: 'bash', args: ['scripts/remove-feature.sh', id] });
125
- }
126
- // Never --force: git itself refuses a worktree with changes in it. The branch is left alone.
127
- return jobs.start({ projectId: project.id, kind: 'worktree-remove', tag: wt.path, label, cwd: root, file: 'git', args: ['worktree', 'remove', wt.path] });
128
- }
129
-
130
- // The pipeline commands this machine has (`cohorte install` wrote them), with their one-line description.
131
- function listCommands(globalDir) {
132
- const dir = path.join(globalDir, 'commands');
133
- let files = [];
134
- try { files = fs.readdirSync(dir).filter((f) => /^cohorte-[a-z0-9-]+\.md$/.test(f)).sort(); } catch { return []; }
135
- return files.map((f) => {
136
- const txt = fs.readFileSync(path.join(dir, f), 'utf8');
137
- const fm = txt.match(/^---\r?\n([\s\S]*?)\r?\n---/);
138
- const d = fm && fm[1].match(/^description:\s*(.*)$/m);
139
- const h = fm && fm[1].match(/^argument-hint:\s*(.*)$/m);
140
- return { name: f.slice(0, -3), description: d ? d[1].replace(/^["']|["']$/g, '').trim() : '', argumentHint: h ? h[1].replace(/^["']|["']$/g, '').trim() : '' };
141
- });
142
- }
143
-
144
- // Starts `/cohorte-<name> <args>` in a worktree. What the human may pass is a command NAME this machine has
145
- // and a one-line argument; both reach Claude as prompt text, never a shell.
146
- function startRun(runs, project, globalDir, body) {
147
- const wt = resolveWorktree(project.root, body.worktree);
148
- const name = typeof body.command === 'string' ? body.command.replace(/^\//, '') : '';
149
- if (!listCommands(globalDir).some((c) => c.name === name)) throw new OpError('unknown cohorte command — run `cohorte install`', 400);
150
- const args = typeof body.args === 'string' ? body.args.trim() : '';
151
- if (args.length > 500 || /[\r\n]/.test(args)) throw new OpError('arguments must be one line of at most 500 characters');
152
- if (runs.find(project.id, wt.path)) throw new OpError('a run is already in progress in this worktree', 409);
153
- // Under `claude -p`, an untrusted folder's permissions.allow are ignored: every pipeline script would prompt.
154
- const trust = checkTrust(wt.path, globalDir);
155
- if (trust.status === 'warn' && body.acknowledgeUntrusted !== true) {
156
- throw new OpError(trust.detail, 409, { untrusted: true, fix: trust.fix });
157
- }
158
- if (fs.existsSync(path.join(project.root, '.claude', 'hooks', 'cohorte-gate.py')) && spawnSync('python3', ['--version'], { stdio: 'ignore' }).status !== 0) {
159
- throw new OpError('python3 is not on PATH: the project gate is fail-closed, so every tool call would be refused', 400);
160
- }
161
- return runs.start({ projectId: project.id, cwd: wt.path, command: `/${name}${args ? ` ${args}` : ''}`, permissionMode: body.permissionMode });
162
- }
163
-
164
- module.exports = { gateVerdict, confirm, readProfile, listCommands, startRun, startDev, stopJob, createWorktree, removeWorktree, devInfo, isolationScripts, resolveWorktree, OpError, FEATURE_ID };