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.
package/ui/public/app.js DELETED
@@ -1,420 +0,0 @@
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
- })();
@@ -1,13 +0,0 @@
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>
@@ -1,35 +0,0 @@
1
- :root{--bg:#fff;--panel:#f6f7f9;--line:#e1e4e8;--text:#1c2024;--mute:#656d76;--ok:#1a7f37;--warn:#9a6700;--bad:#cf222e;--accent:#6f42c1}
2
- @media (prefers-color-scheme:dark){:root{--bg:#0f1115;--panel:#171a21;--line:#2a2f3a;--text:#e6e8eb;--mute:#8b93a0;--ok:#3fb950;--warn:#d29922;--bad:#f85149;--accent:#a78bfa}}
3
- *{box-sizing:border-box}
4
- body{margin:0;background:var(--bg);color:var(--text);font:14px/1.5 system-ui,-apple-system,Segoe UI,sans-serif}
5
- .layout{display:grid;grid-template-columns:280px 1fr;min-height:100vh}
6
- aside{background:var(--panel);border-right:1px solid var(--line);padding:16px;overflow:auto}
7
- main{padding:24px 32px;overflow:auto;max-width:1100px}
8
- h1{font-size:18px;margin:0 0 16px}h2{font-size:16px;margin:0 0 4px}h3{font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:var(--mute);margin:20px 0 8px}
9
- .mute{color:var(--mute)}.mono{font-family:ui-monospace,Menlo,monospace;font-size:12px}
10
- .proj{display:block;width:100%;text-align:left;background:none;border:1px solid transparent;border-radius:8px;padding:8px 10px;margin-bottom:4px;color:inherit;cursor:pointer;font:inherit}
11
- .proj:hover{background:var(--bg)}.proj.sel{background:var(--bg);border-color:var(--line)}
12
- .proj .n{font-weight:600;display:flex;gap:8px;align-items:center}
13
- .dot{width:8px;height:8px;border-radius:50%;background:var(--mute);flex:none}
14
- .dot.ok{background:var(--ok)}.dot.warn{background:var(--warn)}.dot.bad{background:var(--bad)}
15
- form.add{display:flex;gap:6px;margin:12px 0}
16
- input{flex:1;min-width:0;padding:6px 8px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--text);font:inherit}
17
- button.b{padding:6px 10px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--text);cursor:pointer;font:inherit}
18
- button.b:hover{border-color:var(--accent)}
19
- .tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin:16px 0}
20
- .tab{padding:8px 12px;background:none;border:0;border-bottom:2px solid transparent;color:var(--mute);cursor:pointer;font:inherit}
21
- .tab.sel{color:var(--text);border-color:var(--accent)}
22
- table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:6px 10px;border-bottom:1px solid var(--line);vertical-align:top}
23
- th{font-size:12px;color:var(--mute);font-weight:500}
24
- tr.click{cursor:pointer}tr.click:hover{background:var(--panel)}
25
- .pill{display:inline-block;padding:0 8px;border-radius:10px;border:1px solid var(--line);font-size:12px}
26
- .pill.ok{color:var(--ok)}.pill.warn{color:var(--warn)}.pill.bad{color:var(--bad)}
27
- .cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
28
- .card{border:1px solid var(--line);border-radius:8px;padding:10px 12px}.card .v{font-size:20px;font-weight:600}
29
- pre{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:12px;overflow:auto;white-space:pre-wrap;max-height:480px}
30
- .err{color:var(--bad)}.fix{color:var(--mute);font-size:12px}
31
- .sug{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:4px 0}
32
- .empty{padding:48px 0;text-align:center;color:var(--mute)}
33
- .gate{margin:10px 0;border-color:var(--warn)}.feed{margin-top:10px}.ev{padding:3px 0;white-space:pre-wrap;word-break:break-word}select{padding:6px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--text);font:inherit}label{cursor:pointer}
34
- textarea{width:100%;padding:8px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--text);font:inherit;margin-bottom:6px}.reply-box{margin-top:14px}.reply{border-left:3px solid var(--accent);padding-left:8px}
35
- .card.link{text-align:left;font:inherit;color:inherit;background:none;cursor:pointer}.card.link:hover{border-color:var(--accent)}.card.ok .v{color:var(--ok)}.card.warn .v{color:var(--warn)}.card.bad .v{color:var(--bad)}button:disabled{opacity:.5;cursor:not-allowed}