@jjanczur/tyran 0.1.32 → 0.1.34
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +149 -0
- package/README.md +1 -1
- package/hooks/scripts/session-start.mjs +89 -3
- package/package.json +1 -1
- package/scripts/board-daemon.mjs +412 -0
- package/scripts/board-html.mjs +123 -0
- package/scripts/board.mjs +180 -13
- package/scripts/doctor.mjs +12 -1
- package/scripts/overnight.mjs +24 -2
- package/scripts/project.mjs +35 -1
- package/scripts/scan-repo.mjs +14 -0
- package/scripts/schema.mjs +51 -1
- package/skills/run/SKILL.md +26 -0
- package/skills/setup/SKILL.md +14 -3
- package/templates/config.yaml +18 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* board-daemon — the part of `board.mjs --serve` that lets it be STARTED by
|
|
3
|
+
* something other than a human with a spare terminal.
|
|
4
|
+
*
|
|
5
|
+
* `--serve` blocks forever, which is correct for an operator who typed it and
|
|
6
|
+
* fatal for everything else. Setup's "turn the dashboard on" step handed an
|
|
7
|
+
* AGENT that command: the board came up, the agent's tool call then sat on it
|
|
8
|
+
* until the platform's timeout, and setup's remaining steps — validate,
|
|
9
|
+
* report, ask for the `.tyran/` commit — never ran. Measured: still listening
|
|
10
|
+
* three seconds after spawn, with nothing to return to the caller.
|
|
11
|
+
*
|
|
12
|
+
* So this module owns starting a server the caller does not have to wait for,
|
|
13
|
+
* and the harder half of that: knowing whether one is ALREADY running.
|
|
14
|
+
*
|
|
15
|
+
* THE LIVENESS CONTRACT, because a pid is the obvious answer and the wrong
|
|
16
|
+
* one. `session-start.mjs` states the general case — a pid recorded by a
|
|
17
|
+
* short-lived process is dead before anyone reads it, and once the OS recycles
|
|
18
|
+
* the number it names a stranger. A board that trusted its own record would
|
|
19
|
+
* therefore report "already running" about somebody else's process and never
|
|
20
|
+
* start. Liveness here is an HTTP question instead:
|
|
21
|
+
*
|
|
22
|
+
* 1. GET `/health.json` on the port,
|
|
23
|
+
* 2. and believe it only if it names THIS `.tyran` directory.
|
|
24
|
+
*
|
|
25
|
+
* Both halves are load-bearing. Without (1) a recycled pid is a false
|
|
26
|
+
* positive; without (2) the board of a DIFFERENT repository — same program,
|
|
27
|
+
* same route, same shape — answers and this one silently never starts, which
|
|
28
|
+
* is the failure mode of every "is my dev server up" check that only probes a
|
|
29
|
+
* port. The recorded pid is kept for exactly one job, `--stop`, where a stale
|
|
30
|
+
* one costs a refusal rather than a wrong answer.
|
|
31
|
+
*
|
|
32
|
+
* Everything is best-effort by construction. A caller that cannot start a
|
|
33
|
+
* board still has a working repository, so no function here throws on a
|
|
34
|
+
* failure to reach the network, the filesystem or a child process.
|
|
35
|
+
*/
|
|
36
|
+
import { spawn as spawnProcess } from 'node:child_process';
|
|
37
|
+
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
38
|
+
import { get as httpGet } from 'node:http';
|
|
39
|
+
import { connect as netConnect } from 'node:net';
|
|
40
|
+
import { dirname, join, resolve } from 'node:path';
|
|
41
|
+
import { fileURLToPath } from 'node:url';
|
|
42
|
+
|
|
43
|
+
/** Where the running server records itself, relative to `.tyran`. */
|
|
44
|
+
export const SERVER_RECORD_FILE = 'board-server.json';
|
|
45
|
+
export const SERVER_RECORD_RELPATH = join('state', SERVER_RECORD_FILE);
|
|
46
|
+
|
|
47
|
+
/** Bumped when the record's shape changes; an older one reads as absent. */
|
|
48
|
+
export const SERVER_RECORD_SCHEMA = 1;
|
|
49
|
+
|
|
50
|
+
/** The route that answers the liveness question above. */
|
|
51
|
+
export const HEALTH_ROUTE = '/health.json';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* How many ports to try from the preferred one.
|
|
55
|
+
*
|
|
56
|
+
* One board per repository, and people work in several repositories at once,
|
|
57
|
+
* so "the port is busy" is the ordinary case rather than an error. Ten is
|
|
58
|
+
* enough for any plausible number of simultaneous repos and small enough that
|
|
59
|
+
* an exhausted search is fast.
|
|
60
|
+
*/
|
|
61
|
+
export const PORT_SEARCH_SPAN = 10;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A probe budget, not a timeout in the usual sense: this runs inside the
|
|
65
|
+
* SessionStart hook, whose whole deadline is 4 s and which already spends
|
|
66
|
+
* half of it on doctor. A loopback server either answers in single-digit
|
|
67
|
+
* milliseconds or is not there.
|
|
68
|
+
*/
|
|
69
|
+
export const PROBE_TIMEOUT_MS = 400;
|
|
70
|
+
|
|
71
|
+
/** How long `--detach` waits for the child to answer before reporting. */
|
|
72
|
+
export const START_DEADLINE_MS = 5000;
|
|
73
|
+
|
|
74
|
+
const POLL_INTERVAL_MS = 100;
|
|
75
|
+
|
|
76
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
77
|
+
const BOARD_SCRIPT = join(HERE, 'board.mjs');
|
|
78
|
+
|
|
79
|
+
export function serverRecordPath(dir) {
|
|
80
|
+
return join(dir, SERVER_RECORD_RELPATH);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The record, or null. Garbage, a wrong schema and an unreadable file are all
|
|
85
|
+
* "no record" — this file is a convenience, and a caller that crashed on a
|
|
86
|
+
* half-written one would be worse than the problem it solves.
|
|
87
|
+
*/
|
|
88
|
+
export function readServerRecord(dir) {
|
|
89
|
+
try {
|
|
90
|
+
const path = serverRecordPath(dir);
|
|
91
|
+
if (!existsSync(path)) return null;
|
|
92
|
+
const doc = JSON.parse(readFileSync(path, 'utf8'));
|
|
93
|
+
if (doc === null || typeof doc !== 'object' || Array.isArray(doc)) return null;
|
|
94
|
+
if (doc.schema !== SERVER_RECORD_SCHEMA) return null;
|
|
95
|
+
return doc;
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Atomic, same rename dance as every other runtime file Tyran writes. */
|
|
102
|
+
export function writeServerRecord(dir, record) {
|
|
103
|
+
try {
|
|
104
|
+
const target = serverRecordPath(dir);
|
|
105
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
106
|
+
const temp = join(dirname(target), `.board-server-${process.pid}.tmp`);
|
|
107
|
+
writeFileSync(temp, `${JSON.stringify({ schema: SERVER_RECORD_SCHEMA, ...record }, null, 2)}\n`);
|
|
108
|
+
renameSync(temp, target);
|
|
109
|
+
return true;
|
|
110
|
+
} catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function removeServerRecord(dir) {
|
|
116
|
+
try {
|
|
117
|
+
rmSync(serverRecordPath(dir), { force: true });
|
|
118
|
+
return true;
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* GET `/health.json` on one port. Resolves to the parsed document, or null for
|
|
126
|
+
* every failure — closed port, wrong program, timeout, unparseable body.
|
|
127
|
+
*
|
|
128
|
+
* The body is capped: this asks an arbitrary local port a question, and the
|
|
129
|
+
* thing that answers is not necessarily a board. A megabyte of response to a
|
|
130
|
+
* health probe is not a health response, and reading it in full would let any
|
|
131
|
+
* process on loopback decide how much memory this one spends.
|
|
132
|
+
*/
|
|
133
|
+
export function probeHealth(port, { timeoutMs = PROBE_TIMEOUT_MS, request = httpGet } = {}) {
|
|
134
|
+
return new Promise((resolvePromise) => {
|
|
135
|
+
let settled = false;
|
|
136
|
+
const done = (value) => {
|
|
137
|
+
if (settled) return;
|
|
138
|
+
settled = true;
|
|
139
|
+
resolvePromise(value);
|
|
140
|
+
};
|
|
141
|
+
let req;
|
|
142
|
+
try {
|
|
143
|
+
req = request(
|
|
144
|
+
{ host: '127.0.0.1', port, path: HEALTH_ROUTE, headers: { host: `127.0.0.1:${port}` } },
|
|
145
|
+
(res) => {
|
|
146
|
+
if (res.statusCode !== 200) {
|
|
147
|
+
res.resume();
|
|
148
|
+
done(null);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let body = '';
|
|
152
|
+
res.setEncoding('utf8');
|
|
153
|
+
res.on('data', (chunk) => {
|
|
154
|
+
body += chunk;
|
|
155
|
+
if (body.length > 8192) {
|
|
156
|
+
req.destroy();
|
|
157
|
+
done(null);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
res.on('end', () => {
|
|
161
|
+
try {
|
|
162
|
+
const doc = JSON.parse(body);
|
|
163
|
+
done(doc !== null && typeof doc === 'object' && doc.tyran_board === true ? doc : null);
|
|
164
|
+
} catch {
|
|
165
|
+
done(null);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
res.on('error', () => done(null));
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
} catch {
|
|
172
|
+
done(null);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
req.on('error', () => done(null));
|
|
176
|
+
req.setTimeout?.(timeoutMs, () => {
|
|
177
|
+
req.destroy();
|
|
178
|
+
done(null);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Two directories are the same board when they resolve to the same path. */
|
|
184
|
+
function sameDir(a, b) {
|
|
185
|
+
try {
|
|
186
|
+
return resolve(String(a)) === resolve(String(b));
|
|
187
|
+
} catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Is a board for THIS directory already answering — and on which port?
|
|
194
|
+
*
|
|
195
|
+
* The recorded port is tried first because it is nearly always right and one
|
|
196
|
+
* probe is the whole cost. The span is then swept so that a server whose
|
|
197
|
+
* record was lost (a `git clean`, a crash between listen and write) is still
|
|
198
|
+
* found rather than duplicated.
|
|
199
|
+
*/
|
|
200
|
+
export async function findLiveServer(dir, preferredPort, { probe = probeHealth } = {}) {
|
|
201
|
+
const record = readServerRecord(dir);
|
|
202
|
+
const ports = [];
|
|
203
|
+
if (record !== null && Number.isInteger(record.port)) ports.push(record.port);
|
|
204
|
+
for (let i = 0; i < PORT_SEARCH_SPAN; i += 1) {
|
|
205
|
+
const port = preferredPort + i;
|
|
206
|
+
if (!ports.includes(port)) ports.push(port);
|
|
207
|
+
}
|
|
208
|
+
for (const port of ports) {
|
|
209
|
+
const health = await probe(port);
|
|
210
|
+
if (health !== null && sameDir(health.dir, dir)) return { port, health };
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Is anything at all listening on this port?
|
|
217
|
+
*
|
|
218
|
+
* A TCP connect, because the health probe CANNOT answer this. `probeHealth`
|
|
219
|
+
* returns null for "nothing is there" and for "something is there and it is
|
|
220
|
+
* not a board" alike, and a caller that reads that null as "free" will bind a
|
|
221
|
+
* port already in use. Measured exactly that way: an unrelated local server
|
|
222
|
+
* on the port answered `/health.json` with `not a board`, the health probe
|
|
223
|
+
* reported null, the port was declared free, the child died on EADDRINUSE,
|
|
224
|
+
* and `--detach` spent its whole 5 s deadline before reporting a failure that
|
|
225
|
+
* was knowable in one millisecond.
|
|
226
|
+
*/
|
|
227
|
+
export function isPortFree(port, { timeoutMs = PROBE_TIMEOUT_MS, connect = netConnect } = {}) {
|
|
228
|
+
return new Promise((resolvePromise) => {
|
|
229
|
+
let settled = false;
|
|
230
|
+
const done = (value) => {
|
|
231
|
+
if (settled) return;
|
|
232
|
+
settled = true;
|
|
233
|
+
resolvePromise(value);
|
|
234
|
+
};
|
|
235
|
+
let socket;
|
|
236
|
+
try {
|
|
237
|
+
socket = connect({ host: '127.0.0.1', port });
|
|
238
|
+
} catch {
|
|
239
|
+
done(true); // could not even try to connect — treat as free and let bind decide
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
socket.setTimeout?.(timeoutMs);
|
|
243
|
+
socket.on('connect', () => { socket.destroy(); done(false); });
|
|
244
|
+
socket.on('timeout', () => { socket.destroy(); done(true); });
|
|
245
|
+
socket.on('error', () => { socket.destroy?.(); done(true); }); // ECONNREFUSED — nothing there
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The first port this board may take: one that is genuinely free, or one it
|
|
251
|
+
* already owns. A port held by ANY other program — another repository's
|
|
252
|
+
* board, or something with no opinion about Tyran at all — is skipped rather
|
|
253
|
+
* than fought over.
|
|
254
|
+
*
|
|
255
|
+
* The order of the two probes is deliberate. Ownership is asked FIRST because
|
|
256
|
+
* a board of ours answering is the case worth reusing, and only then is the
|
|
257
|
+
* cheaper "is anything there" question used to tell free from foreign.
|
|
258
|
+
*
|
|
259
|
+
* Returns null when the whole span is occupied — a real condition to report,
|
|
260
|
+
* not one to paper over by binding somewhere unpredictable.
|
|
261
|
+
*/
|
|
262
|
+
export async function pickPort(dir, preferred, { probe = probeHealth, free = isPortFree } = {}) {
|
|
263
|
+
for (let i = 0; i < PORT_SEARCH_SPAN; i += 1) {
|
|
264
|
+
const port = preferred + i;
|
|
265
|
+
const health = await probe(port);
|
|
266
|
+
if (health !== null && sameDir(health.dir, dir)) return { port, reuse: true };
|
|
267
|
+
if (health !== null) continue; // a board, but not ours
|
|
268
|
+
if (await free(port)) return { port, reuse: false };
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Start a server nobody has to wait for, and wait just long enough to be able
|
|
275
|
+
* to say whether it worked.
|
|
276
|
+
*
|
|
277
|
+
* `detached` + `stdio: 'ignore'` + `unref()` is what actually severs it from
|
|
278
|
+
* the caller: without all three the child keeps the parent's event loop or its
|
|
279
|
+
* pipes alive and the caller blocks anyway — which is the bug this file
|
|
280
|
+
* exists to fix, reintroduced one flag at a time.
|
|
281
|
+
*
|
|
282
|
+
* The CHILD writes the record, not this function, and that ordering is the
|
|
283
|
+
* point: it writes from inside its own `listen` callback, so a record exists
|
|
284
|
+
* only for a server that actually bound a port. A parent writing it first
|
|
285
|
+
* would be recording an intention.
|
|
286
|
+
*/
|
|
287
|
+
export async function startDetached(
|
|
288
|
+
dir,
|
|
289
|
+
{ port, write = true, open = false, transcripts = [], spawn = spawnProcess, probe = probeHealth, deadlineMs = START_DEADLINE_MS, sleep = defaultSleep } = {},
|
|
290
|
+
) {
|
|
291
|
+
const existing = await findLiveServer(dir, port, { probe });
|
|
292
|
+
if (existing !== null) {
|
|
293
|
+
return { started: false, reused: true, port: existing.port, url: urlFor(existing.port), pid: existing.health.pid ?? null };
|
|
294
|
+
}
|
|
295
|
+
const chosen = await pickPort(dir, port, { probe });
|
|
296
|
+
if (chosen === null) {
|
|
297
|
+
return {
|
|
298
|
+
started: false,
|
|
299
|
+
reused: false,
|
|
300
|
+
error:
|
|
301
|
+
`ports ${port}-${port + PORT_SEARCH_SPAN - 1} are all in use by other programs — ` +
|
|
302
|
+
'pass --port <n> to start somewhere else',
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const args = [BOARD_SCRIPT, '--dir', dir, '--serve', '--port', String(chosen.port)];
|
|
306
|
+
if (write) args.push('--write');
|
|
307
|
+
if (open) args.push('--open');
|
|
308
|
+
for (const t of transcripts) args.push('--transcripts', t);
|
|
309
|
+
let child;
|
|
310
|
+
try {
|
|
311
|
+
child = spawn(process.execPath, args, { stdio: 'ignore', detached: true });
|
|
312
|
+
child.on?.('error', () => { /* reported by the health probe below, not by a throw */ });
|
|
313
|
+
child.unref?.();
|
|
314
|
+
} catch (err) {
|
|
315
|
+
return { started: false, reused: false, error: `could not spawn the board: ${String(err?.message ?? err)}` };
|
|
316
|
+
}
|
|
317
|
+
// Poll rather than trust the spawn: a child that exits immediately (a bad
|
|
318
|
+
// --dir, a port that raced) is indistinguishable from a healthy one at
|
|
319
|
+
// spawn time, and reporting a URL nothing answers is worse than an error.
|
|
320
|
+
const deadline = deadlineMs;
|
|
321
|
+
for (let waited = 0; waited < deadline; waited += POLL_INTERVAL_MS) {
|
|
322
|
+
await sleep(POLL_INTERVAL_MS);
|
|
323
|
+
const health = await probe(chosen.port);
|
|
324
|
+
if (health !== null && sameDir(health.dir, dir)) {
|
|
325
|
+
return { started: true, reused: false, port: chosen.port, url: urlFor(chosen.port), pid: health.pid ?? child.pid ?? null };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return { started: false, reused: false, error: `the board did not answer on port ${chosen.port} within ${deadline} ms` };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Start one without waiting for it to ANSWER — for callers on a hook's budget.
|
|
333
|
+
*
|
|
334
|
+
* Everything the polling version buys (a URL known to answer, a real pid, an
|
|
335
|
+
* error when the child died) is given up here on purpose: `SessionStart` has
|
|
336
|
+
* a 4 s deadline it shares with doctor, and spending seconds of it confirming
|
|
337
|
+
* a convenience would cost the user their session summary. The next session
|
|
338
|
+
* finds the server through `findLiveServer` and reports it then.
|
|
339
|
+
*
|
|
340
|
+
* What is NOT given up is choosing a port that can actually be bound. Skipping
|
|
341
|
+
* that would make the caller spawn a child onto an occupied port, where it
|
|
342
|
+
* dies on EADDRINUSE with `stdio: 'ignore'` — no output, no exit code anyone
|
|
343
|
+
* reads, and a board that never starts on EVERY session, silently, for as long
|
|
344
|
+
* as the other program holds the port. Port selection costs two immediate
|
|
345
|
+
* ECONNREFUSEDs in the normal case, which the budget can afford; being wrong
|
|
346
|
+
* here costs the whole feature.
|
|
347
|
+
*
|
|
348
|
+
* Returns the chosen port, or null if nothing was started.
|
|
349
|
+
*/
|
|
350
|
+
export async function startDetachedNoWait(
|
|
351
|
+
dir,
|
|
352
|
+
{ port, write = true, transcripts = [], spawn = spawnProcess, probe = probeHealth, free = isPortFree } = {},
|
|
353
|
+
) {
|
|
354
|
+
const chosen = await pickPort(dir, port, { probe, free });
|
|
355
|
+
if (chosen === null) return null;
|
|
356
|
+
const args = [BOARD_SCRIPT, '--dir', dir, '--serve', '--port', String(chosen.port)];
|
|
357
|
+
if (write) args.push('--write');
|
|
358
|
+
for (const t of transcripts) args.push('--transcripts', t);
|
|
359
|
+
try {
|
|
360
|
+
const child = spawn(process.execPath, args, { stdio: 'ignore', detached: true });
|
|
361
|
+
child.on?.('error', () => { /* nothing to report to; the next session probes */ });
|
|
362
|
+
child.unref?.();
|
|
363
|
+
return chosen.port;
|
|
364
|
+
} catch {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Stop the recorded server.
|
|
371
|
+
*
|
|
372
|
+
* The pid is only trusted this far because the cost of being wrong is bounded
|
|
373
|
+
* and visible: the health probe runs FIRST, so a pid is signalled only when a
|
|
374
|
+
* board for this directory is genuinely answering on the recorded port. That
|
|
375
|
+
* closes the recycled-pid window to the case where a stranger inherited the
|
|
376
|
+
* pid AND a real board answers AND the record is stale — at which point the
|
|
377
|
+
* kill fails or hits the board, never an unrelated process by luck alone.
|
|
378
|
+
*/
|
|
379
|
+
export async function stopServer(dir, { probe = probeHealth, kill = process.kill.bind(process) } = {}) {
|
|
380
|
+
const record = readServerRecord(dir);
|
|
381
|
+
if (record === null) return { stopped: false, reason: 'no board server is recorded for this directory' };
|
|
382
|
+
const health = await probe(record.port);
|
|
383
|
+
if (health === null || !sameDir(health.dir, dir)) {
|
|
384
|
+
removeServerRecord(dir);
|
|
385
|
+
return { stopped: false, reason: `nothing is answering on port ${record.port} — cleared the stale record` };
|
|
386
|
+
}
|
|
387
|
+
const pid = health.pid ?? record.pid;
|
|
388
|
+
if (!Number.isInteger(pid)) return { stopped: false, reason: 'the running board did not report a pid' };
|
|
389
|
+
try {
|
|
390
|
+
kill(pid, 'SIGTERM');
|
|
391
|
+
} catch (err) {
|
|
392
|
+
return { stopped: false, reason: `could not signal pid ${pid}: ${String(err?.message ?? err)}` };
|
|
393
|
+
}
|
|
394
|
+
removeServerRecord(dir);
|
|
395
|
+
return { stopped: true, pid, port: record.port };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function urlFor(port) {
|
|
399
|
+
return `http://127.0.0.1:${port}/`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* NOT unref'd, and that is the whole function.
|
|
404
|
+
*
|
|
405
|
+
* An unref'd timer does not hold the event loop open, so `--detach` drained
|
|
406
|
+
* its loop and exited between the spawn and the first poll — reporting
|
|
407
|
+
* nothing at all about a server that then started fine half a second later.
|
|
408
|
+
* The command looked instantaneous and successful and printed no URL.
|
|
409
|
+
*/
|
|
410
|
+
function defaultSleep(ms) {
|
|
411
|
+
return new Promise((r) => { setTimeout(r, ms); });
|
|
412
|
+
}
|
package/scripts/board-html.mjs
CHANGED
|
@@ -135,6 +135,12 @@ h3{font-family:var(--font);color:var(--heading);font-size:.85rem;margin:1.1rem 0
|
|
|
135
135
|
.file .fname{color:var(--steel-bright);font-family:var(--mono);font-weight:600;min-width:6rem}
|
|
136
136
|
.file code{color:var(--muted);font-size:.72rem;word-break:break-all}
|
|
137
137
|
|
|
138
|
+
/* ---- what actually ran on a ticket ---- */
|
|
139
|
+
.runs{width:100%;border-collapse:collapse;margin-top:.3rem;font-size:.74rem;display:block;overflow-x:auto}
|
|
140
|
+
.runs th{text-align:left;color:var(--muted);font-weight:600;padding:.2rem .5rem .2rem 0;border-bottom:1px solid var(--hairline);white-space:nowrap}
|
|
141
|
+
.runs td{padding:.22rem .5rem .22rem 0;border-bottom:1px solid var(--hairline);vertical-align:top}
|
|
142
|
+
.runs td:first-child{font-family:var(--mono);color:var(--steel-bright)}
|
|
143
|
+
|
|
138
144
|
/* ---- lanes ---- */
|
|
139
145
|
.lanes{display:grid;grid-template-columns:repeat(auto-fill,minmax(15rem,1fr));gap:.6rem;align-items:start}
|
|
140
146
|
.lane{background:var(--bg-sunken);border:1px solid var(--hairline-soft);border-radius:var(--radius);padding:.55rem}
|
|
@@ -195,6 +201,20 @@ pre.how .c{color:var(--muted)}
|
|
|
195
201
|
input against the 5-minute write's 1.25x. Without a distinct colour the
|
|
196
202
|
most expensive caching decision on the page is invisible. */
|
|
197
203
|
.comp .s-cache_write_1h{background:var(--ink)}
|
|
204
|
+
/* ---- initiatives ---- */
|
|
205
|
+
.inits{display:flex;flex-direction:column;gap:.3rem;margin:.5rem 0}
|
|
206
|
+
.initrow{display:grid;grid-template-columns:minmax(0,1.6fr) 5rem auto minmax(0,1fr);
|
|
207
|
+
gap:.6rem;align-items:center;padding:.35rem .5rem;border-radius:4px}
|
|
208
|
+
/* An initiative nobody can move without the operator is the one thing on this
|
|
209
|
+
section worth catching an eye. */
|
|
210
|
+
.initrow.waiting{background:color-mix(in srgb,var(--brass) 12%,transparent)}
|
|
211
|
+
.initrow .il{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
212
|
+
.initrow .islug{color:var(--muted);margin-left:.4rem;font-size:.85em}
|
|
213
|
+
.initrow .ib{height:6px;background:var(--line);border-radius:3px;overflow:hidden}
|
|
214
|
+
.initrow .ib i{display:block;height:100%;background:var(--sage)}
|
|
215
|
+
.initrow .iv,.initrow .iw{color:var(--muted);font-size:.9em;white-space:nowrap}
|
|
216
|
+
.initrow .iw.warn{color:var(--brass);font-weight:600}
|
|
217
|
+
|
|
198
218
|
/* ---- the per-day series ---- */
|
|
199
219
|
.days{display:flex;align-items:flex-end;gap:2px;height:74px;margin:.5rem 0 .3rem;
|
|
200
220
|
overflow-x:auto;padding-bottom:2px}
|
|
@@ -572,6 +592,59 @@ if (data.schema !== 1) {
|
|
|
572
592
|
ov.appendChild(first);
|
|
573
593
|
}
|
|
574
594
|
|
|
595
|
+
// ---- initiatives, and the ones that have stopped moving ----------------
|
|
596
|
+
//
|
|
597
|
+
// MEASURED, and the reason this section exists rather than an archive: of 63
|
|
598
|
+
// real journals, 43 were waiting on a question nobody answered and only 6
|
|
599
|
+
// were finished-and-archivable. The board was not cluttered with completed
|
|
600
|
+
// work; it was full of ABANDONED work, and archiving the finished 6 would
|
|
601
|
+
// have removed the only initiatives at 100% and pulled the headline
|
|
602
|
+
// percentage down.
|
|
603
|
+
//
|
|
604
|
+
// "Waiting" is the initiative's own count of open operator questions. The
|
|
605
|
+
// idle time is computed HERE, from last_ts, because the payload is
|
|
606
|
+
// byte-compared and reads no clock — the same split the agent strip uses.
|
|
607
|
+
var inits = Array.isArray(data.initiatives) ? data.initiatives : [];
|
|
608
|
+
if (inits.length > 0) {
|
|
609
|
+
var stalled = inits.filter(function (i) { return i.waiting > 0; }).sort(function (a, b) {
|
|
610
|
+
return (ageMsOf(b.last_ts) || 0) - (ageMsOf(a.last_ts) || 0);
|
|
611
|
+
});
|
|
612
|
+
ov.appendChild(el('h2', null, 'Initiatives'));
|
|
613
|
+
if (stalled.length > 0) {
|
|
614
|
+
ov.appendChild(el('div', 'hint',
|
|
615
|
+
stalled.length + ' of ' + inits.length + ' are waiting on an answer from you. ' +
|
|
616
|
+
'Longest-waiting first — an initiative with an open question does not move until it is answered.'));
|
|
617
|
+
}
|
|
618
|
+
var table = el('div', 'inits');
|
|
619
|
+
var ordered = stalled.concat(inits.filter(function (i) { return !(i.waiting > 0); }));
|
|
620
|
+
ordered.forEach(function (i) {
|
|
621
|
+
var row = el('div', i.waiting > 0 ? 'initrow waiting' : 'initrow');
|
|
622
|
+
// The TITLE, which the journal has carried all along while this page
|
|
623
|
+
// showed a directory slug.
|
|
624
|
+
var label = el('div', 'il');
|
|
625
|
+
label.appendChild(el('b', null, i.title || i.name));
|
|
626
|
+
if (i.title) label.appendChild(el('span', 'islug', i.name));
|
|
627
|
+
row.appendChild(label);
|
|
628
|
+
var bar = el('div', 'ib');
|
|
629
|
+
var fill = el('i');
|
|
630
|
+
fill.style.width = (typeof i.percent === 'number' ? i.percent : 0) + '%';
|
|
631
|
+
bar.appendChild(fill);
|
|
632
|
+
row.appendChild(bar);
|
|
633
|
+
var counts = i.merged + '/' + i.tickets + ' merged';
|
|
634
|
+
// Named only when there is something to name. A findings count of zero
|
|
635
|
+
// on every row is noise that teaches the eye to skip the column.
|
|
636
|
+
if (i.findings > 0) counts += ' \u00b7 ' + i.findings + ' finding' + (i.findings === 1 ? '' : 's');
|
|
637
|
+
row.appendChild(el('div', 'iv', counts));
|
|
638
|
+
var age = ageMsOf(i.last_ts);
|
|
639
|
+
row.appendChild(el('div', i.waiting > 0 ? 'iw warn' : 'iw',
|
|
640
|
+
i.waiting > 0
|
|
641
|
+
? i.waiting + ' waiting on you \u00b7 quiet ' + ago(i.last_ts)
|
|
642
|
+
: (age === null ? '' : 'last moved ' + ago(i.last_ts))));
|
|
643
|
+
table.appendChild(row);
|
|
644
|
+
});
|
|
645
|
+
ov.appendChild(table);
|
|
646
|
+
}
|
|
647
|
+
|
|
575
648
|
ov.appendChild(el('h2', null, 'Agents'));
|
|
576
649
|
// Named, not implied by the order: the strip is sorted stalest-first by the
|
|
577
650
|
// server, and a reader who does not know that reads the first chip as the
|
|
@@ -664,6 +737,16 @@ if (data.schema !== 1) {
|
|
|
664
737
|
// a ticket had come back and never why, which is the one thing the card is
|
|
665
738
|
// opened for.
|
|
666
739
|
row('reported', card.report_text);
|
|
740
|
+
// The two lifecycle facts the lane could only imply: which commit a
|
|
741
|
+
// merged ticket became, and who wrote the review that sent it back.
|
|
742
|
+
if (card.review) {
|
|
743
|
+
row('review', card.review.verdict + (card.review.by ? ' by ' + card.review.by : '')
|
|
744
|
+
+ (card.review.ts ? ' · ' + ago(card.review.ts) : ''));
|
|
745
|
+
}
|
|
746
|
+
if (card.merge) {
|
|
747
|
+
row('merged', (card.merge.sha || 'no sha') + (card.merge.mode ? ' (' + card.merge.mode + ')' : '')
|
|
748
|
+
+ (card.merge.ts ? ' · ' + ago(card.merge.ts) : ''));
|
|
749
|
+
}
|
|
667
750
|
row('last event', card.since ? ago(card.since) + ' (' + card.since + ')' : null);
|
|
668
751
|
if (cost) {
|
|
669
752
|
var hit = (cost.by_ticket || []).filter(function (r) { return r.ticket === card.id; })[0];
|
|
@@ -672,6 +755,30 @@ if (data.schema !== 1) {
|
|
|
672
755
|
row('spend', costError);
|
|
673
756
|
}
|
|
674
757
|
box.appendChild(dl);
|
|
758
|
+
// What actually ran on this ticket: agent, model, when, verdict. A table
|
|
759
|
+
// rather than more dl rows, because the interesting reading is DOWN a
|
|
760
|
+
// column — three implementers on one ticket, or the same story reopened
|
|
761
|
+
// on a bigger model — and that comparison is what a list of prose rows
|
|
762
|
+
// makes impossible.
|
|
763
|
+
var runs = card.execution || [];
|
|
764
|
+
if (runs.length > 0) {
|
|
765
|
+
box.appendChild(el('div', 'dt', 'Execution'));
|
|
766
|
+
var tbl = el('table', 'runs');
|
|
767
|
+
var head = el('tr');
|
|
768
|
+
['agent', 'model', 'started', 'verdict'].forEach(function (h) { head.appendChild(el('th', null, h)); });
|
|
769
|
+
tbl.appendChild(head);
|
|
770
|
+
runs.forEach(function (r) {
|
|
771
|
+
var tr = el('tr');
|
|
772
|
+
tr.appendChild(el('td', null, r.agent + (r.role ? ' (' + r.role + ')' : '')));
|
|
773
|
+
// A spawn that named no model is a real state, not a gap to hide: it
|
|
774
|
+
// means the conductor let the platform default decide.
|
|
775
|
+
tr.appendChild(el('td', null, r.model || '—'));
|
|
776
|
+
tr.appendChild(el('td', null, r.started ? ago(r.started) : '—'));
|
|
777
|
+
tr.appendChild(el('td', null, r.verdict || (r.ended ? 'no verdict' : 'running')));
|
|
778
|
+
tbl.appendChild(tr);
|
|
779
|
+
});
|
|
780
|
+
box.appendChild(tbl);
|
|
781
|
+
}
|
|
675
782
|
// The files this initiative ACTUALLY has, listed by the server after an
|
|
676
783
|
// existsSync — never a fixed list of what a well-run initiative ought to
|
|
677
784
|
// contain. Paths, not links: the board serves three URLs and derives a
|
|
@@ -805,6 +912,21 @@ if (data.schema !== 1) {
|
|
|
805
912
|
send.setAttribute('type', 'button');
|
|
806
913
|
var useDefault = hasDefault ? el('button', 'sbtn', 'Take the default') : null;
|
|
807
914
|
if (useDefault) useDefault.setAttribute('type', 'button');
|
|
915
|
+
// The recommendation was already shown, as TEXT, and the only way to
|
|
916
|
+
// accept it was to retype it into the box below it. For an operator who
|
|
917
|
+
// is not an engineer that gap is most of the difficulty of the whole
|
|
918
|
+
// page: the agent has said what it thinks should happen and the human is
|
|
919
|
+
// asked to transcribe it. This fills the box instead of submitting, so
|
|
920
|
+
// the wording stays editable and the answer is still deliberate.
|
|
921
|
+
var useRec = a.recommendation ? el('button', 'sbtn', 'Use the recommendation') : null;
|
|
922
|
+
if (useRec) {
|
|
923
|
+
useRec.setAttribute('type', 'button');
|
|
924
|
+
useRec.addEventListener('click', function () {
|
|
925
|
+
input.value = a.recommendation;
|
|
926
|
+
input.focus();
|
|
927
|
+
holdRefresh();
|
|
928
|
+
});
|
|
929
|
+
}
|
|
808
930
|
var status = el('div', 'sstat');
|
|
809
931
|
|
|
810
932
|
var submit = function (text) {
|
|
@@ -847,6 +969,7 @@ if (data.schema !== 1) {
|
|
|
847
969
|
|
|
848
970
|
box.appendChild(input);
|
|
849
971
|
acts.appendChild(send);
|
|
972
|
+
if (useRec) acts.appendChild(useRec);
|
|
850
973
|
if (useDefault) acts.appendChild(useDefault);
|
|
851
974
|
box.appendChild(acts);
|
|
852
975
|
box.appendChild(status);
|