cohorte 3.1.2 → 3.2.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/CHANGELOG.md +31 -0
- package/bin/cli.js +33 -1
- package/core/hooks/gate.py +561 -550
- package/lib/doctor.js +48 -1
- package/lib/registry.js +118 -0
- package/package.json +3 -2
- package/scripts/kanban-move.sh +51 -11
- package/ui/docker.js +147 -0
- package/ui/jobs.js +127 -0
- package/ui/ops.js +164 -0
- package/ui/public/app.js +420 -0
- package/ui/public/index.html +13 -0
- package/ui/public/style.css +35 -0
- package/ui/runs.js +213 -0
- package/ui/server.js +299 -0
package/ui/ops.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
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 };
|
package/ui/public/app.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Every string from a project (titles, check details, reports) goes in through textContent.
|
|
3
|
+
const app = document.getElementById('app');
|
|
4
|
+
let token = null;
|
|
5
|
+
try {
|
|
6
|
+
const m = /token=([0-9a-f]+)/.exec(location.hash);
|
|
7
|
+
if (m) { sessionStorage.setItem('cohorte-token', m[1]); history.replaceState(null, '', location.pathname); }
|
|
8
|
+
token = sessionStorage.getItem('cohorte-token');
|
|
9
|
+
} catch { /* storage blocked */ }
|
|
10
|
+
|
|
11
|
+
const h = (tag, props, ...kids) => {
|
|
12
|
+
const el = document.createElement(tag);
|
|
13
|
+
for (const [k, v] of Object.entries(props || {})) {
|
|
14
|
+
if (k === 'class') el.className = v;
|
|
15
|
+
else if (k.startsWith('on')) el.addEventListener(k.slice(2), v);
|
|
16
|
+
else if (v != null) el.setAttribute(k, v);
|
|
17
|
+
}
|
|
18
|
+
for (const kid of kids.flat()) if (kid != null && kid !== false) el.append(kid.nodeType ? kid : document.createTextNode(String(kid)));
|
|
19
|
+
return el;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
async function api(path, opts = {}) {
|
|
23
|
+
const res = await fetch(`/api${path}`, {
|
|
24
|
+
method: opts.method || 'GET',
|
|
25
|
+
headers: { Authorization: `Bearer ${token}`, ...(opts.body ? { 'Content-Type': 'application/json' } : {}) },
|
|
26
|
+
body: opts.body ? JSON.stringify(opts.body) : undefined,
|
|
27
|
+
});
|
|
28
|
+
const data = await res.json().catch(() => ({}));
|
|
29
|
+
if (!res.ok) { const err = new Error(data.error || `HTTP ${res.status}`); err.data = data; err.needs = data.needsConfirmation === true; err.command = data.command; err.reason = data.reason; throw err; }
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const S = { docker: null, preflight: null, form: null, run: null, commands: null, job: null, projects: [], suggestions: [], sel: null, tab: 'overview', detail: null, spec: null, metrics: null, error: null, busy: false };
|
|
34
|
+
const tone = (s) => (s && s.error ? 'bad' : !s || s.missing ? 'bad' : s.summary.bad ? 'bad' : s.summary.warn ? 'warn' : 'ok');
|
|
35
|
+
const STATUS_TONE = { shipped: 'ok', merged: 'ok', blocked: 'bad', abandoned: 'warn' };
|
|
36
|
+
const usd = (n) => (typeof n === 'number' ? `$${n.toFixed(2)}` : '–');
|
|
37
|
+
const num = (n) => (typeof n === 'number' ? n.toLocaleString() : '–');
|
|
38
|
+
|
|
39
|
+
async function refresh() {
|
|
40
|
+
const [st, dis] = await Promise.all([api('/state'), api('/discover')]);
|
|
41
|
+
S.projects = st.projects; S.version = st.version; S.suggestions = dis.suggestions;
|
|
42
|
+
if (S.sel && !S.projects.some((p) => p.id === S.sel)) S.sel = null;
|
|
43
|
+
if (!S.sel && S.projects.length) S.sel = S.projects[0].id;
|
|
44
|
+
}
|
|
45
|
+
async function loadDetail() {
|
|
46
|
+
S.detail = null; S.spec = null; S.metrics = null;
|
|
47
|
+
if (!S.sel) return;
|
|
48
|
+
try { S.detail = await api(`/projects/${S.sel}`); S.error = null; } catch (e) { S.error = e.message; }
|
|
49
|
+
}
|
|
50
|
+
async function guard(fn) {
|
|
51
|
+
S.busy = true; render();
|
|
52
|
+
try { await fn(); S.error = null; } catch (e) { S.error = e.message; }
|
|
53
|
+
S.busy = false; render();
|
|
54
|
+
}
|
|
55
|
+
const select = (id) => guard(async () => { S.sel = id; S.tab = 'overview'; S.job = null; S.docker = null; S.preflight = null; S.run = null; S.form = null; await loadDetail(); });
|
|
56
|
+
const addProject = (path) => guard(async () => {
|
|
57
|
+
const r = await api('/projects', { method: 'POST', body: { path } });
|
|
58
|
+
await refresh(); S.sel = r.project.id; S.tab = 'overview'; S.docker = null; await loadDetail();
|
|
59
|
+
});
|
|
60
|
+
const removeProject = (id) => guard(async () => { await api(`/projects/${id}`, { method: 'DELETE' }); S.sel = null; S.detail = null; await refresh(); await loadDetail(); });
|
|
61
|
+
const openSpec = (id) => guard(async () => { S.spec = await api(`/projects/${S.sel}/specs/${encodeURIComponent(id)}`); });
|
|
62
|
+
const setTab = (t) => guard(async () => {
|
|
63
|
+
S.tab = t; S.spec = null; clearTimeout(dockerTimer);
|
|
64
|
+
if (t === 'docker') { await loadDocker(); pollDocker(); }
|
|
65
|
+
if (t === 'run' && !S.commands) { try { S.commands = (await api('/commands')).commands; } catch { S.commands = []; } }
|
|
66
|
+
if (t === 'cost' && !S.metrics) { try { S.metrics = await api(`/projects/${S.sel}/metrics`); } catch (e) { S.metrics = { error: e.message }; } }
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function sidebar() {
|
|
70
|
+
const input = h('input', { placeholder: '/path/to/project', 'aria-label': 'Project path' });
|
|
71
|
+
return h('aside', {},
|
|
72
|
+
h('h1', {}, 'Cohorte ', h('span', { class: 'mute mono' }, S.version ? `v${S.version}` : '')),
|
|
73
|
+
h('form', { class: 'add', onsubmit: (e) => { e.preventDefault(); if (input.value.trim()) addProject(input.value.trim()); } },
|
|
74
|
+
input, h('button', { class: 'b', type: 'submit' }, 'Add')),
|
|
75
|
+
S.projects.map((p) => h('button', { class: `proj${p.id === S.sel ? ' sel' : ''}`, onclick: () => select(p.id) },
|
|
76
|
+
h('div', { class: 'n' }, h('span', { class: `dot ${tone(p)}` }), p.title || p.name),
|
|
77
|
+
h('div', { class: 'mute mono' }, p.missing ? 'folder missing' : `${p.specTotal || 0} specs`))),
|
|
78
|
+
S.suggestions.length ? h('h3', {}, 'Found on this machine') : null,
|
|
79
|
+
S.suggestions.map((s) => h('div', { class: 'sug' },
|
|
80
|
+
h('span', {}, h('div', {}, s.name), h('div', { class: 'mute mono' }, s.root)),
|
|
81
|
+
h('button', { class: 'b', onclick: () => addProject(s.root) }, 'Add'))));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function health(d) {
|
|
85
|
+
const s = d.doctor.summary;
|
|
86
|
+
return h('div', {},
|
|
87
|
+
h('div', { class: 'cards' }, ['ok', 'warn', 'bad', 'skip'].map((k) => h('div', { class: 'card' }, h('div', { class: 'v' }, s[k]), h('div', { class: 'mute' }, k)))),
|
|
88
|
+
h('h3', {}, 'Checks'),
|
|
89
|
+
h('table', {}, h('thead', {}, h('tr', {}, h('th', {}, 'Check'), h('th', {}, 'Status'), h('th', {}, 'Detail'))),
|
|
90
|
+
h('tbody', {}, d.doctor.checks.map((c) => h('tr', {},
|
|
91
|
+
h('td', {}, c.label),
|
|
92
|
+
h('td', {}, h('span', { class: `pill ${c.status}` }, c.status)),
|
|
93
|
+
h('td', {}, c.detail, c.fix ? h('div', { class: 'fix' }, `fix: ${c.fix}`) : null))))));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function specs(d) {
|
|
97
|
+
if (S.spec) {
|
|
98
|
+
const r = S.spec.reports;
|
|
99
|
+
return h('div', {},
|
|
100
|
+
h('button', { class: 'b', onclick: () => { S.spec = null; render(); } }, '← Specs'),
|
|
101
|
+
h('h2', { style: 'margin-top:12px' }, S.spec.spec.title || S.spec.spec.id),
|
|
102
|
+
h('div', { class: 'mute mono' }, `${S.spec.spec.id} · ${S.spec.spec.status || 'unknown'}${S.spec.spec.branch ? ` · ${S.spec.spec.branch}` : ''}`),
|
|
103
|
+
Object.entries(r).filter(([, v]) => v).map(([k, v]) => [h('h3', {}, k), h('pre', {}, JSON.stringify(v, null, 2))]),
|
|
104
|
+
h('h3', {}, 'Spec'), h('pre', {}, S.spec.body));
|
|
105
|
+
}
|
|
106
|
+
if (!d.specs.length) return h('div', { class: 'empty' }, 'No specs yet. Run /cohorte-brainstorm in Claude Code.');
|
|
107
|
+
return h('table', {}, h('thead', {}, h('tr', {}, ['Spec', 'Title', 'Status', 'Branch'].map((t) => h('th', {}, t)))),
|
|
108
|
+
h('tbody', {}, d.specs.map((s) => h('tr', { class: 'click', onclick: () => openSpec(s.id) },
|
|
109
|
+
h('td', { class: 'mono' }, s.id), h('td', {}, s.title),
|
|
110
|
+
h('td', {}, h('span', { class: `pill ${STATUS_TONE[s.status] || (s.tone === 'warn' ? 'warn' : '')}` }, s.status)),
|
|
111
|
+
h('td', { class: 'mono' }, s.branch)))));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function cost() {
|
|
115
|
+
const m = S.metrics;
|
|
116
|
+
if (!m) return h('div', { class: 'empty' }, 'Loading…');
|
|
117
|
+
if (m.error) return h('div', { class: 'err' }, m.error);
|
|
118
|
+
const t = m.totals || {};
|
|
119
|
+
return h('div', {},
|
|
120
|
+
h('div', { class: 'cards' },
|
|
121
|
+
[['Total', usd(t.cost)], ['Runs', num(t.runs)], ['Sessions', num(t.sessions)], ['Subagents', num(t.agents)]]
|
|
122
|
+
.map(([l, v]) => h('div', { class: 'card' }, h('div', { class: 'v' }, v), h('div', { class: 'mute' }, l)))),
|
|
123
|
+
h('h3', {}, 'By command (last 30 days)'),
|
|
124
|
+
h('table', {}, h('thead', {}, h('tr', {}, ['Command', 'Runs', 'Cost'].map((x) => h('th', {}, x)))),
|
|
125
|
+
h('tbody', {}, (m.commands || []).map((c) => h('tr', {}, h('td', { class: 'mono' }, c.command), h('td', {}, num(c.runs)),
|
|
126
|
+
h('td', {}, usd(c.cost && typeof c.cost === 'object' ? c.cost.total : c.cost)))))));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// --- jobs: worktree provisioning and dev servers ---------------------------------
|
|
130
|
+
let pollTimer = null;
|
|
131
|
+
const LIVE = ['starting', 'running', 'ready'];
|
|
132
|
+
async function postJob(path, body) {
|
|
133
|
+
try { return await api(path, { method: 'POST', body }); } catch (e) {
|
|
134
|
+
if (e.needs) {
|
|
135
|
+
if (!confirm(`The project's gate asks before running:\n\n${e.command}\n\n${e.reason || ''}\n\nRun it?`)) throw new Error('cancelled');
|
|
136
|
+
return await api(path, { method: 'POST', body: { ...body, confirmed: true } });
|
|
137
|
+
}
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function watch(job) { S.job = { ...job, lines: [], cursor: 0 }; poll(); }
|
|
142
|
+
function poll() {
|
|
143
|
+
clearTimeout(pollTimer);
|
|
144
|
+
if (!S.job) return;
|
|
145
|
+
pollTimer = setTimeout(async () => {
|
|
146
|
+
const j = S.job;
|
|
147
|
+
if (!j || !['worktrees', 'docker'].includes(S.tab)) return poll();
|
|
148
|
+
try {
|
|
149
|
+
const v = await api(`/projects/${S.sel}/jobs/${j.id}/logs?since=${j.cursor}`);
|
|
150
|
+
const was = j.status;
|
|
151
|
+
S.job = { ...v, lines: j.lines.concat(v.lines).slice(-1500), cursor: v.cursor };
|
|
152
|
+
const pre = document.getElementById('joblog');
|
|
153
|
+
if (pre) { pre.textContent = S.job.lines.join('\n'); pre.scrollTop = pre.scrollHeight; }
|
|
154
|
+
const st = document.getElementById('jobstatus');
|
|
155
|
+
if (st) st.textContent = S.job.status;
|
|
156
|
+
if (was !== S.job.status) { await loadDetail(); render(); }
|
|
157
|
+
if (!LIVE.includes(S.job.status) && was === S.job.status) { await loadDetail(); render(); return; }
|
|
158
|
+
} catch (e) { S.error = e.message; }
|
|
159
|
+
poll();
|
|
160
|
+
}, 1200);
|
|
161
|
+
}
|
|
162
|
+
const act = (fn) => guard(async () => { await fn(); await loadDetail(); });
|
|
163
|
+
const startDev = (w) => act(async () => { const r = await postJob(`/projects/${S.sel}/dev`, { worktree: w.path }); watch(r.job); });
|
|
164
|
+
const stopJobBtn = (id) => act(async () => { await api(`/projects/${S.sel}/jobs/${id}/stop`, { method: 'POST', body: {} }); });
|
|
165
|
+
const createWt = (feature, skipDockerCheck) => act(async () => {
|
|
166
|
+
S.preflight = null;
|
|
167
|
+
try { const r = await postJob(`/projects/${S.sel}/worktrees`, { feature, skipDockerCheck }); watch(r.job); } catch (e) {
|
|
168
|
+
if (!(e.data && e.data.dockerPreflight)) throw e;
|
|
169
|
+
S.preflight = { feature, ...e.data.dockerPreflight, message: e.message };
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const removeWt = (w) => act(async () => {
|
|
173
|
+
if (!confirm(`Remove the worktree ${w.path}?\n\nGit refuses if it has uncommitted changes. The branch is kept.`)) return;
|
|
174
|
+
const r = await postJob(`/projects/${S.sel}/worktrees/remove`, { path: w.path }); watch(r.job);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
function worktrees(d) {
|
|
178
|
+
const feature = h('input', { placeholder: 'feature-id (kebab-case)', 'aria-label': 'Feature id' });
|
|
179
|
+
const live = (w) => w.dev && LIVE.includes(w.dev.status);
|
|
180
|
+
return h('div', {},
|
|
181
|
+
h('div', { class: 'mute' }, d.dev.command ? ['Dev command: ', h('span', { class: 'mono' }, d.dev.command)] : 'No commands.dev in this project’s profile — dev servers cannot be started from here.'),
|
|
182
|
+
h('table', {}, h('thead', {}, h('tr', {}, ['Worktree', 'Branch', 'Dev server', ''].map((t) => h('th', {}, t)))),
|
|
183
|
+
h('tbody', {}, d.worktrees.map((w) => h('tr', {},
|
|
184
|
+
h('td', { class: 'mono' }, w.path, w.main ? h('span', { class: 'pill', style: 'margin-left:6px' }, 'main') : null),
|
|
185
|
+
h('td', { class: 'mono' }, w.branch || (w.bare ? 'bare' : 'detached')),
|
|
186
|
+
h('td', {}, w.dev ? h('span', { class: `pill ${w.dev.status === 'ready' ? 'ok' : w.dev.status === 'failed' ? 'bad' : ''}` }, w.dev.status) : h('span', { class: 'mute' }, 'stopped')),
|
|
187
|
+
h('td', {},
|
|
188
|
+
live(w) ? h('button', { class: 'b', onclick: () => stopJobBtn(w.dev.id) }, 'Stop')
|
|
189
|
+
: (d.dev.command && !w.bare ? h('button', { class: 'b', onclick: () => startDev(w) }, 'Start dev') : null),
|
|
190
|
+
' ',
|
|
191
|
+
w.dev ? h('button', { class: 'b', onclick: () => watch(w.dev) }, 'Logs') : null,
|
|
192
|
+
' ',
|
|
193
|
+
!w.main ? h('button', { class: 'b', onclick: () => removeWt(w) }, 'Remove') : null))))),
|
|
194
|
+
h('h3', {}, 'New worktree'),
|
|
195
|
+
h('form', { class: 'add', onsubmit: (e) => { e.preventDefault(); if (feature.value.trim()) createWt(feature.value.trim()); } },
|
|
196
|
+
feature, h('button', { class: 'b', type: 'submit' }, 'Create')),
|
|
197
|
+
h('div', { class: 'mute' }, d.isolation.create ? 'Uses scripts/new-feature.sh (own DB and ports).' : 'Plain git worktree next to the repo, on a new branch.'),
|
|
198
|
+
S.preflight ? h('div', { class: 'card gate' }, h('div', { class: 'pill warn' }, 'Docker is not ready'), h('div', { style: 'margin:6px 0' }, S.preflight.message),
|
|
199
|
+
S.preflight.daemonUp ? h('button', { class: 'b', onclick: () => act(async () => { S.preflight = null; const r = await postJob(`/projects/${S.sel}/docker`, { action: 'up' }); watch(r.job); }) }, 'Start the stack')
|
|
200
|
+
: h('button', { class: 'b', onclick: () => setTab('docker') }, 'Open the Docker tab'), ' ',
|
|
201
|
+
h('button', { class: 'b', onclick: () => { const f = S.preflight.feature; createWt(f, true); } }, 'Create anyway'), ' ',
|
|
202
|
+
h('button', { class: 'b', onclick: () => { S.preflight = null; render(); } }, 'Cancel'),
|
|
203
|
+
S.preflight.daemonUp ? null : h('div', { class: 'fix' }, 'Start Docker Desktop (or the docker service), then try again.')) : null,
|
|
204
|
+
S.job ? [h('h3', {}, `${S.job.label} · `, h('span', { id: 'jobstatus' }, S.job.status),
|
|
205
|
+
LIVE.includes(S.job.status) ? [' ', h('button', { class: 'b', onclick: () => stopJobBtn(S.job.id) }, 'Stop')] : null),
|
|
206
|
+
h('div', { class: 'mute mono' }, S.job.command), h('pre', { id: 'joblog' }, (S.job.lines || []).join('\n'))] : null);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
// --- docker: the project's compose stack ----------------------------------------------
|
|
211
|
+
let dockerTimer = null;
|
|
212
|
+
async function loadDocker() { try { S.docker = await api(`/projects/${S.sel}/docker`); } catch (e) { S.docker = { error: e.message }; } }
|
|
213
|
+
function pollDocker() {
|
|
214
|
+
clearTimeout(dockerTimer);
|
|
215
|
+
dockerTimer = setTimeout(async () => {
|
|
216
|
+
if (S.tab !== 'docker') return;
|
|
217
|
+
const before = JSON.stringify(S.docker);
|
|
218
|
+
await loadDocker();
|
|
219
|
+
if (S.tab === 'docker' && before !== JSON.stringify(S.docker)) render();
|
|
220
|
+
pollDocker();
|
|
221
|
+
}, 4000);
|
|
222
|
+
}
|
|
223
|
+
const dockerAct = (action, service) => act(async () => {
|
|
224
|
+
if (action === 'down' && !confirm('Stop and remove the stack’s containers?\n\nVolumes (your data) are kept.')) return;
|
|
225
|
+
const r = await postJob(`/projects/${S.sel}/docker`, { action, service });
|
|
226
|
+
watch(r.job);
|
|
227
|
+
setTimeout(async () => { if (S.tab === 'docker') { await loadDocker(); render(); } }, 2500);
|
|
228
|
+
});
|
|
229
|
+
const STATE_TONE = { running: 'ok', exited: 'warn', dead: 'bad', restarting: 'warn' };
|
|
230
|
+
function dockerTab(d) {
|
|
231
|
+
const k = S.docker;
|
|
232
|
+
if (!d.docker) return h('div', { class: 'empty' }, 'No compose file here. Declare isolation.compose_file in PIPELINE.md, or add a docker-compose.yml at the repo root.');
|
|
233
|
+
if (!k) return h('div', { class: 'empty' }, 'Loading…');
|
|
234
|
+
if (k.error) return h('div', { class: 'err' }, k.error);
|
|
235
|
+
const live = S.job && LIVE.includes(S.job.status) && /^docker/.test(S.job.label || '');
|
|
236
|
+
return h('div', {},
|
|
237
|
+
h('div', { class: 'cards' },
|
|
238
|
+
h('div', { class: 'card' }, h('div', { class: 'v' }, h('span', { class: `dot ${k.daemon.up ? 'ok' : 'bad'}`, style: 'display:inline-block;margin-right:8px' }), k.daemon.up ? 'Docker up' : 'Docker down'),
|
|
239
|
+
h('div', { class: 'mute' }, k.daemon.up ? `engine ${k.daemon.version || ''}` : k.daemon.error)),
|
|
240
|
+
h('div', { class: 'card' }, h('div', { class: 'v' }, `${k.running || 0}/${k.services.length}`), h('div', { class: 'mute' }, 'services running')),
|
|
241
|
+
h('div', { class: 'card' }, h('div', { class: 'v mono', style: 'font-size:14px' }, k.file), h('div', { class: 'mute' }, 'compose file'))),
|
|
242
|
+
k.configError ? h('div', { class: 'err' }, `compose: ${k.configError}`) : null,
|
|
243
|
+
!k.daemon.up ? h('div', { class: 'mute', style: 'margin:10px 0' }, 'Start Docker Desktop (or the docker service). scripts/new-feature.sh needs it to create a worktree’s database.') : null,
|
|
244
|
+
h('div', { style: 'margin:12px 0' },
|
|
245
|
+
h('button', { class: 'b', disabled: !k.daemon.up || live ? 'disabled' : null, onclick: () => dockerAct('up') }, 'Start stack'), ' ',
|
|
246
|
+
h('button', { class: 'b', disabled: !k.daemon.up || live ? 'disabled' : null, onclick: () => dockerAct('restart') }, 'Restart all'), ' ',
|
|
247
|
+
h('button', { class: 'b', disabled: !k.daemon.up || live ? 'disabled' : null, onclick: () => dockerAct('stop') }, 'Stop all'), ' ',
|
|
248
|
+
h('button', { class: 'b', disabled: !k.daemon.up || live ? 'disabled' : null, onclick: () => dockerAct('down') }, 'Down (keeps volumes)')),
|
|
249
|
+
h('table', {}, h('thead', {}, h('tr', {}, ['Service', 'State', 'Ports', 'Status', ''].map((t) => h('th', {}, t)))),
|
|
250
|
+
h('tbody', {}, k.services.map((v) => h('tr', {},
|
|
251
|
+
h('td', { class: 'mono' }, v.name),
|
|
252
|
+
h('td', {}, h('span', { class: `pill ${STATE_TONE[v.state] || ''}` }, v.state), v.health ? h('span', { class: `pill ${v.health === 'healthy' ? 'ok' : v.health === 'unhealthy' ? 'bad' : 'warn'}`, style: 'margin-left:6px' }, v.health) : null),
|
|
253
|
+
h('td', { class: 'mono' }, v.ports.join(', ')), h('td', { class: 'mute' }, v.status),
|
|
254
|
+
h('td', {}, k.daemon.up ? [
|
|
255
|
+
v.state === 'running' ? h('button', { class: 'b', disabled: live ? 'disabled' : null, onclick: () => dockerAct('stop', v.name) }, 'Stop') : h('button', { class: 'b', disabled: live ? 'disabled' : null, onclick: () => dockerAct('up', v.name) }, 'Start'),
|
|
256
|
+
' ', h('button', { class: 'b', disabled: live ? 'disabled' : null, onclick: () => dockerAct('restart', v.name) }, 'Restart'),
|
|
257
|
+
' ', h('button', { class: 'b', onclick: () => dockerAct('logs', v.name) }, 'Logs')] : null))))),
|
|
258
|
+
S.job && /^docker/.test(S.job.label || '') ? [h('h3', {}, `${S.job.label} · `, h('span', { id: 'jobstatus' }, S.job.status),
|
|
259
|
+
LIVE.includes(S.job.status) ? [' ', h('button', { class: 'b', onclick: () => stopJobBtn(S.job.id) }, 'Stop')] : null),
|
|
260
|
+
h('div', { class: 'mute mono' }, S.job.command), h('pre', { id: 'joblog' }, (S.job.lines || []).join('\n'))] : null);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// --- overview: the project at a glance --------------------------------------------------
|
|
264
|
+
function overview(d) {
|
|
265
|
+
const s = d.doctor.summary;
|
|
266
|
+
const counts = {};
|
|
267
|
+
for (const sp of d.specs) counts[sp.status || 'unknown'] = (counts[sp.status || 'unknown'] || 0) + 1;
|
|
268
|
+
const devs = d.worktrees.filter((w) => w.dev && LIVE.includes(w.dev.status));
|
|
269
|
+
const runs = (d.runs || []).filter((r) => r.status === 'running');
|
|
270
|
+
const todo = d.doctor.checks.filter((c) => c.status === 'bad' || c.status === 'warn');
|
|
271
|
+
const card = (v, l, go, tone) => h('button', { class: `card link${tone ? ` ${tone}` : ''}`, onclick: () => setTab(go) }, h('div', { class: 'v' }, v), h('div', { class: 'mute' }, l));
|
|
272
|
+
return h('div', {},
|
|
273
|
+
h('div', { class: 'cards' },
|
|
274
|
+
card(s.bad ? `${s.bad} failing` : s.warn ? `${s.warn} to review` : 'Healthy', 'pipeline health', 'health', s.bad ? 'bad' : s.warn ? 'warn' : 'ok'),
|
|
275
|
+
card(d.specs.length, `specs${Object.keys(counts).length ? ` · ${Object.entries(counts).map(([k, v]) => `${v} ${k}`).join(', ')}` : ''}`, 'specs'),
|
|
276
|
+
card(d.worktrees.length, `worktree${d.worktrees.length === 1 ? '' : 's'} · ${devs.length} dev server${devs.length === 1 ? '' : 's'} up`, 'worktrees'),
|
|
277
|
+
card(runs.length ? `${runs.length} running` : 'Idle', 'cohorte commands', 'run'),
|
|
278
|
+
d.docker ? card('Docker', d.docker.file, 'docker') : null),
|
|
279
|
+
h('h3', {}, 'Needs attention'),
|
|
280
|
+
todo.length ? h('table', {}, h('tbody', {}, todo.map((c) => h('tr', {}, h('td', {}, h('span', { class: `pill ${c.status}` }, c.status)), h('td', {}, c.label),
|
|
281
|
+
h('td', {}, c.detail, c.fix ? h('div', { class: 'fix' }, `fix: ${c.fix}`) : null))))) : h('div', { class: 'mute' }, 'Nothing — every check passes.'),
|
|
282
|
+
devs.length ? [h('h3', {}, 'Running now'), h('table', {}, h('tbody', {}, devs.map((w) => h('tr', {}, h('td', { class: 'mono' }, w.branch || w.path),
|
|
283
|
+
h('td', {}, h('span', { class: `pill ${w.dev.status === 'ready' ? 'ok' : ''}` }, `dev · ${w.dev.status}`)),
|
|
284
|
+
h('td', {}, h('button', { class: 'b', onclick: () => { watch(w.dev); setTab('worktrees'); } }, 'Logs'))))))] : null,
|
|
285
|
+
d.specs.length ? [h('h3', {}, 'Latest specs'), h('table', {}, h('tbody', {}, d.specs.slice(0, 5).map((sp) => h('tr', { class: 'click', onclick: () => { S.tab = 'specs'; openSpec(sp.id); } },
|
|
286
|
+
h('td', { class: 'mono' }, sp.id), h('td', {}, sp.title), h('td', {}, h('span', { class: `pill ${STATUS_TONE[sp.status] || ''}` }, sp.status))))))] : null);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// --- runs: a pipeline command through `claude -p`, with its gates answered here --------------
|
|
290
|
+
let runTimer = null;
|
|
291
|
+
const RUN_LIVE = ['running'];
|
|
292
|
+
function watchRun(run) { S.run = { ...run, events: run.events || [], cursor: run.cursor || 0 }; pollRun(); }
|
|
293
|
+
function pollRun() {
|
|
294
|
+
clearTimeout(runTimer);
|
|
295
|
+
if (!S.run) return;
|
|
296
|
+
runTimer = setTimeout(async () => {
|
|
297
|
+
const r = S.run;
|
|
298
|
+
if (!r || S.tab !== 'run') return pollRun();
|
|
299
|
+
try {
|
|
300
|
+
const v = await api(`/projects/${S.sel}/runs/${r.id}?since=${r.cursor}`);
|
|
301
|
+
const before = JSON.stringify(r.pending) + r.status + (r.events.length);
|
|
302
|
+
S.run = { ...v, events: r.events.concat(v.events).slice(-1500), cursor: v.cursor };
|
|
303
|
+
if (before !== JSON.stringify(S.run.pending) + S.run.status + S.run.events.length) render();
|
|
304
|
+
if (!RUN_LIVE.includes(S.run.status)) { await loadDetail(); render(); return; }
|
|
305
|
+
} catch (e) { S.error = e.message; }
|
|
306
|
+
pollRun();
|
|
307
|
+
}, 1000);
|
|
308
|
+
}
|
|
309
|
+
async function startRun(form) {
|
|
310
|
+
const c = (S.commands || []).find((x) => x.name === form.cmd.value);
|
|
311
|
+
if (c && c.argumentHint && !form.args.value.trim() &&
|
|
312
|
+
!confirm(`${c.name} usually takes an argument ${c.argumentHint}. Without one it may ask a free-text question this dashboard cannot answer.\n\nRun without?`)) return;
|
|
313
|
+
const body = { worktree: form.wt.value, command: form.cmd.value, args: form.args.value, permissionMode: form.mode.value };
|
|
314
|
+
await guard(async () => {
|
|
315
|
+
let r;
|
|
316
|
+
try { r = await api(`/projects/${S.sel}/runs`, { method: 'POST', body }); } catch (e) {
|
|
317
|
+
if (!e.untrusted) throw e;
|
|
318
|
+
if (!confirm(`${e.message}\n\nFix: ${e.fix || 'run claude once in this folder and accept the trust dialog'}\n\nRun anyway?`)) throw new Error('cancelled');
|
|
319
|
+
r = await api(`/projects/${S.sel}/runs`, { method: 'POST', body: { ...body, acknowledgeUntrusted: true } });
|
|
320
|
+
}
|
|
321
|
+
watchRun(r.run);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const sendReply = (text) => guard(async () => {
|
|
325
|
+
const r = await api(`/projects/${S.sel}/runs/${S.run.id}/reply`, { method: 'POST', body: { text } });
|
|
326
|
+
watchRun({ ...r.run, events: S.run.events.concat(r.run.events.slice(S.run.cursor)), cursor: r.run.cursor });
|
|
327
|
+
});
|
|
328
|
+
const respond = (requestId, behavior, answers) => api(`/projects/${S.sel}/runs/${S.run.id}/respond`, { method: 'POST', body: { requestId, behavior, answers } })
|
|
329
|
+
.then(() => pollRun()).catch((e) => { S.error = e.message; render(); });
|
|
330
|
+
|
|
331
|
+
function pendingCard(p) {
|
|
332
|
+
if (p.kind === 'question') {
|
|
333
|
+
const picked = {};
|
|
334
|
+
const blocks = p.questions.map((q) => {
|
|
335
|
+
const free = h('input', { placeholder: 'Other…', 'aria-label': 'Other answer' });
|
|
336
|
+
free.addEventListener('input', () => { picked[q.question] = free.value ? [free.value] : []; });
|
|
337
|
+
return h('div', { style: 'margin:8px 0' }, h('strong', {}, q.header ? `${q.header} — ` : '', q.question),
|
|
338
|
+
q.options.map((o) => h('label', { style: 'display:block' },
|
|
339
|
+
h('input', { type: q.multiSelect ? 'checkbox' : 'radio', name: q.question, style: 'flex:none;margin-right:6px', onchange: (e) => {
|
|
340
|
+
const cur = picked[q.question] || [];
|
|
341
|
+
picked[q.question] = q.multiSelect ? (e.target.checked ? cur.concat(o.label) : cur.filter((x) => x !== o.label)) : [o.label];
|
|
342
|
+
} }), o.label, o.description ? h('span', { class: 'mute' }, ` — ${o.description}`) : null)), free);
|
|
343
|
+
});
|
|
344
|
+
return h('div', { class: 'card gate' }, h('div', { class: 'pill warn' }, 'Question'), blocks,
|
|
345
|
+
h('button', { class: 'b', onclick: () => respond(p.requestId, 'allow', Object.fromEntries(Object.entries(picked).map(([k, v]) => [k, v]))) }, 'Answer'), ' ',
|
|
346
|
+
h('button', { class: 'b', onclick: () => respond(p.requestId, 'deny') }, 'Skip'));
|
|
347
|
+
}
|
|
348
|
+
return h('div', { class: 'card gate' }, h('div', { class: 'pill warn' }, `Permission · ${p.tool}`, p.via ? ` · ${p.via}` : ''),
|
|
349
|
+
h('pre', { style: 'max-height:140px' }, p.summary), p.reason ? h('div', { class: 'fix' }, p.reason) : null,
|
|
350
|
+
h('button', { class: 'b', onclick: () => respond(p.requestId, 'allow') }, 'Allow'), ' ',
|
|
351
|
+
h('button', { class: 'b', onclick: () => respond(p.requestId, 'deny') }, 'Deny'));
|
|
352
|
+
}
|
|
353
|
+
function eventRow(e, last) {
|
|
354
|
+
if (e.kind === 'text') return h('div', { class: 'ev' }, e.text);
|
|
355
|
+
if (e.kind === 'tool') return h('div', { class: 'ev mute mono' }, `▸ ${e.name} ${e.summary}`);
|
|
356
|
+
if (e.kind === 'tool_result') return e.error ? h('div', { class: 'ev err mono' }, `✗ ${e.text}`) : null;
|
|
357
|
+
if (e.kind === 'reply') return h('div', { class: 'ev reply' }, h('span', { class: 'mute' }, 'you · '), e.text);
|
|
358
|
+
if (e.kind === 'resolved') return h('div', { class: 'ev mute' }, `gate: ${e.decision}`);
|
|
359
|
+
if (e.kind === 'result') return h('div', { class: `ev ${e.ok ? '' : 'err'}` }, h('strong', {}, e.ok ? 'Done' : 'Failed'), e.costUsd != null ? ` · ${usd(e.costUsd)}` : '', e.durationMs ? ` · ${Math.round(e.durationMs / 1000)}s` : '', e.text && e.text !== last ? h('div', {}, e.text) : null);
|
|
360
|
+
if (e.kind === 'stderr' || e.kind === 'system') return h('div', { class: 'ev err mono' }, e.text);
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
function replyBox(r) {
|
|
364
|
+
const ta = h('textarea', { rows: '3', placeholder: `Reply to ${r.command.split(' ')[0]} (same session)…`, 'aria-label': 'Reply to the command' });
|
|
365
|
+
return h('form', { class: 'reply-box', onsubmit: (e) => { e.preventDefault(); if (ta.value.trim()) sendReply(ta.value.trim()); } },
|
|
366
|
+
ta, h('button', { class: 'b', type: 'submit' }, 'Send'),
|
|
367
|
+
h('div', { class: 'mute' }, 'Goes to this Cohorte command only — it is not a general chat.'));
|
|
368
|
+
}
|
|
369
|
+
function runTab(d) {
|
|
370
|
+
const form = {
|
|
371
|
+
wt: h('select', {}, d.worktrees.filter((w) => !w.bare).map((w) => h('option', { value: w.path }, `${w.main ? '(main) ' : ''}${w.branch || w.path}`))),
|
|
372
|
+
cmd: h('select', {}, (S.commands || []).map((c) => h('option', { value: c.name, title: c.description }, c.name))),
|
|
373
|
+
args: h('input', { placeholder: 'argument (feature id, text…)' }),
|
|
374
|
+
mode: h('select', {}, [['default', 'ask for edits'], ['acceptEdits', 'accept edits'], ['plan', 'plan only']].map(([v, l]) => h('option', { value: v }, l))),
|
|
375
|
+
};
|
|
376
|
+
S.form = S.form || {};
|
|
377
|
+
for (const k of ['wt', 'cmd', 'args', 'mode']) {
|
|
378
|
+
if (S.form[k] != null) form[k].value = S.form[k];
|
|
379
|
+
form[k].addEventListener('input', () => { S.form[k] = form[k].value; });
|
|
380
|
+
}
|
|
381
|
+
const hint = () => { const c = (S.commands || []).find((x) => x.name === form.cmd.value); return c ? `${c.description}${c.argumentHint ? ` [${c.argumentHint}]` : ''}` : ''; };
|
|
382
|
+
const hintEl = h('div', { class: 'mute' }, hint());
|
|
383
|
+
form.cmd.addEventListener('change', () => { hintEl.textContent = hint(); });
|
|
384
|
+
const r = S.run;
|
|
385
|
+
return h('div', {},
|
|
386
|
+
!(S.commands || []).length ? h('div', { class: 'mute' }, 'No /cohorte-* commands found in ~/.claude/commands — run `cohorte install`.') : null,
|
|
387
|
+
h('form', { class: 'add', style: 'flex-wrap:wrap', onsubmit: (e) => { e.preventDefault(); startRun(form); } },
|
|
388
|
+
form.wt, form.cmd, form.args, form.mode, h('button', { class: 'b', type: 'submit', disabled: r && r.status === 'running' ? 'disabled' : null }, 'Run')),
|
|
389
|
+
hintEl,
|
|
390
|
+
h('div', { class: 'mute' }, 'Headless run (claude -p): gates and questions appear below. Talking to the agent stays in Claude Code or Francois.'),
|
|
391
|
+
r ? [h('h3', { style: 'text-transform:none' }, `${r.command} · ${r.status}`, r.status === 'running' ? [' ', h('button', { class: 'b', onclick: () => api(`/projects/${S.sel}/runs/${r.id}/stop`, { method: 'POST', body: {} }).then(pollRun) }, 'Stop')] : null),
|
|
392
|
+
(r.pending || []).map(pendingCard), h('div', { class: 'feed' }, r.events.map((e, i) => eventRow(e, (r.events.slice(0, i).reverse().find((x) => x.kind === 'text') || {}).text))),
|
|
393
|
+
r.status !== 'running' && r.sessionId ? replyBox(r) : null]
|
|
394
|
+
: (d.runs || []).length ? [h('h3', {}, 'Earlier runs'), (d.runs || []).map((x) => h('div', { class: 'mono' }, `${x.command} · ${x.status}`))] : null);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function main() {
|
|
398
|
+
if (!S.projects.length) return h('main', {}, h('div', { class: 'empty' }, h('h2', {}, 'No project yet'), 'Add a repo that has a PIPELINE.md using the field on the left.'));
|
|
399
|
+
const sum = S.projects.find((p) => p.id === S.sel);
|
|
400
|
+
const d = S.detail;
|
|
401
|
+
const tabs = [['overview', 'Overview'], ['health', 'Health'], ['specs', 'Specs'], ['run', 'Run'], ['worktrees', 'Worktrees'], ['docker', 'Docker'], ['cost', 'Cost']];
|
|
402
|
+
return h('main', {},
|
|
403
|
+
S.error ? h('div', { class: 'err' }, S.error) : null,
|
|
404
|
+
sum ? h('div', {}, h('h2', {}, sum.title || sum.name), h('div', { class: 'mute' }, sum.oneLiner), h('div', { class: 'mute mono' }, sum.root),
|
|
405
|
+
h('div', { style: 'margin-top:8px' }, h('button', { class: 'b', onclick: () => { if (confirm('Remove this project from the dashboard? Nothing on disk is touched.')) removeProject(sum.id); } }, 'Remove from dashboard'))) : null,
|
|
406
|
+
h('div', { class: 'tabs' }, tabs.map(([k, l]) => h('button', { class: `tab${S.tab === k ? ' sel' : ''}`, onclick: () => setTab(k) }, l))),
|
|
407
|
+
!d ? h('div', { class: 'empty' }, S.busy ? 'Loading…' : 'Nothing to show.')
|
|
408
|
+
: S.tab === 'overview' ? overview(d) : S.tab === 'health' ? health(d) : S.tab === 'docker' ? dockerTab(d) : S.tab === 'specs' ? specs(d) : S.tab === 'cost' ? cost() : S.tab === 'run' ? runTab(d) : worktrees(d));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function render() {
|
|
412
|
+
if (!token) { app.replaceChildren(h('div', { class: 'empty' }, 'Open the URL printed by `cohorte ui` — it carries this session’s token.')); return; }
|
|
413
|
+
app.replaceChildren(h('div', { class: 'layout' }, sidebar(), main()));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
(async () => {
|
|
417
|
+
render();
|
|
418
|
+
if (!token) return;
|
|
419
|
+
await guard(async () => { await refresh(); await loadDetail(); });
|
|
420
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
<title>Cohorte</title>
|
|
7
|
+
<link rel="stylesheet" href="/style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script src="/app.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|