gcf-board 0.4.1 → 0.6.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.
Files changed (36) hide show
  1. package/README.md +9 -8
  2. package/dist/server/app.js +259 -25
  3. package/dist/server/chat.js +67 -0
  4. package/dist/server/cli.js +11 -4
  5. package/dist/server/desktop.js +17 -3
  6. package/dist/server/events.js +15 -1
  7. package/dist/server/files.js +8 -4
  8. package/dist/server/mcp.js +28 -0
  9. package/dist/server/moves.js +11 -0
  10. package/dist/server/propose.js +96 -0
  11. package/dist/server/relay.js +50 -0
  12. package/dist/server/runs.js +237 -166
  13. package/dist/server/talks.js +498 -0
  14. package/dist/web/assets/{index-DCkdSzDJ.css → index-BYAEKw51.css} +1 -1
  15. package/dist/web/assets/index-D_F7OEyk.js +36 -0
  16. package/dist/web/index.html +2 -2
  17. package/node_modules/gcf-session/lib/activity.js +371 -0
  18. package/node_modules/gcf-session/lib/adapter/claude.js +226 -0
  19. package/node_modules/gcf-session/lib/adapter/index.js +33 -0
  20. package/node_modules/gcf-session/lib/chat-input.js +260 -0
  21. package/node_modules/gcf-session/lib/chat.js +832 -0
  22. package/node_modules/gcf-session/lib/cli.js +52 -0
  23. package/node_modules/gcf-session/lib/cost.js +29 -0
  24. package/node_modules/gcf-session/lib/index.js +58 -0
  25. package/node_modules/gcf-session/lib/job.js +417 -0
  26. package/node_modules/gcf-session/lib/limit.js +132 -0
  27. package/node_modules/gcf-session/lib/lock.js +81 -0
  28. package/node_modules/gcf-session/lib/proc.js +93 -0
  29. package/node_modules/gcf-session/lib/session.js +320 -0
  30. package/node_modules/gcf-session/lib/store.js +28 -0
  31. package/node_modules/gcf-session/lib/thread.js +423 -0
  32. package/node_modules/gcf-session/lib/windows.js +46 -0
  33. package/node_modules/gcf-session/package.json +23 -0
  34. package/node_modules/gcf-session/types/index.d.ts +152 -0
  35. package/package.json +10 -3
  36. package/dist/web/assets/index-CCeftHBL.js +0 -34
@@ -1,26 +1,41 @@
1
- // Runs the board started: `ai-factory <harness> run <ids> --json` (GCF: gcf-harness), one process per batch, held
2
- // by the server until every agent session ends. A run started from a console shows on the
3
- // board too (its lock or session mark makes the item `running`); only its report is not here.
1
+ // Runs the board started: `ai-factory <harness> run <ids> --json` (GCF: gcf-harness), one per batch,
2
+ // in a relay (relay.ts) the board starts detached: the run outlives the board, and a board started
3
+ // again finds it by its record in `<board home>/runs/` and reads its end from there. A run
4
+ // started from a console shows on the board too (its lock or session mark makes the item
5
+ // `running`); only its report is not here.
4
6
  // In `run_mode: main` the checkout takes one run at a time: a run asked for meanwhile waits in
5
7
  // the project's queue and starts when the one before it ends.
6
8
  import { spawn } from 'node:child_process';
9
+ import { randomUUID } from 'node:crypto';
10
+ import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
7
13
  import { briefError } from './cli.js';
8
- import { broadcast } from './events.js';
14
+ import { alive, broadcast } from './events.js';
9
15
  import { HttpError } from './http-error.js';
16
+ import { homeDir } from './registry.js';
17
+ // The source runs relay.ts, the package its build beside this file.
18
+ const RELAY = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? 'relay.ts' : 'relay.js', import.meta.url));
19
+ const flightsDir = () => path.join(homeDir(), 'runs');
20
+ const recordOf = (rid) => path.join(flightsDir(), `${rid}.json`);
21
+ const endOf = (rid) => path.join(flightsDir(), `${rid}.end.json`);
22
+ // A relay touches its record every BEAT_MS of relay.ts (30 s): on adoption, three missed beats
23
+ // is a dead one.
24
+ const BEAT_STALE_MS = 90_000;
10
25
  // A board that stops leaves its runs going: killing one would lose its integrate step.
11
26
  const active = new Set();
12
27
  const queues = new Map();
13
28
  // Projects whose queue waits after a failure the next run would repeat (`stalled`).
14
29
  const paused = new Set();
15
- // shortcut: the scheduled resume after a usage limit lives in memory, like the queue: a board
16
- // restart loses it, and the operator resumes by hand; persist it if restarts become common.
17
- const scheduled = new Map();
18
- // The paused projects whose pause the usage limit set: its reset may lift it, nothing else.
30
+ // The paused projects whose pause the usage limit set: a run that ended paused by it (AD-19).
19
31
  const limitPaused = new Set();
20
32
  // Runs going on for a project the operator removed: their end touches no project state.
21
33
  const forgotten = new WeakSet();
22
- // shortcut: reports and acts live in memory, like the queue: a board restart forgets them;
23
- // persist them with the queue if restarts become common.
34
+ // The runs in flight by their record's id: a project added back must not take one twice.
35
+ const flights = new Map();
36
+ // shortcut: reports and acts live in memory, like the queue: a board restart forgets the ones
37
+ // it showed (a run in flight is not lost, its record waits); persist them with the queue if
38
+ // restarts become common.
24
39
  const reports = new Map();
25
40
  const acts = new Map();
26
41
  const KEEP_REPORTS = 20;
@@ -38,65 +53,20 @@ export function closeReport(project, id) {
38
53
  export const activeRuns = (project) => [...active].filter((r) => r.project === project);
39
54
  /** What runs and what waits, for a project; a paused queue waits for `resumeQueue`. */
40
55
  export function runsOf(project) {
41
- const s = scheduled.get(project);
42
56
  return {
43
57
  active: activeRuns(project),
44
58
  queued: (queues.get(project) ?? []).flatMap((q) => q.ids),
45
59
  paused: paused.has(project),
46
- // Why it waits: the usage limit (its reset may lift it) or a failure (only the operator).
60
+ // Why it waits: a run the usage limit ended paused, or a failure; the operator resumes it.
47
61
  paused_by: paused.has(project) ? (limitPaused.has(project) ? 'limit' : 'failure') : null,
48
- // When the items a usage limit stopped run again by themselves, and the queue with them.
49
- resume: s ? { at: s.at.toISOString(), ids: s.run.ids } : null,
50
62
  reports: reports.get(project) ?? [],
51
63
  acts: acts.get(project) ?? [],
52
64
  };
53
65
  }
54
- /**
55
- * The time a usage limit resets, as Claude names it (`3am`, `3:30pm`, `15:00`, with or without
56
- * `(Europe/Berlin)`): its next occurrence after `now`, a minute late to be safe; null when the
57
- * text is no such time.
58
- */
59
- export function resetAt(text, now = new Date()) {
60
- // shortcut: the time is read on this machine's clock and the zone it names is ignored: the
61
- // board runs where the operator's claude does; convert through Intl if a zone ever differs.
62
- const m = /^\s*(\d{1,2})(?::(\d{2}))?\s*([ap]m)?\s*(\(.*\))?\s*$/i.exec(text);
63
- if (!m || (!m[2] && !m[3]))
64
- return null;
65
- let hour = Number(m[1]);
66
- const minute = Number(m[2] ?? 0);
67
- if (m[3]) {
68
- if (hour < 1 || hour > 12)
69
- return null;
70
- hour = (hour % 12) + (m[3].toLowerCase() === 'pm' ? 12 : 0);
71
- }
72
- if (hour > 23 || minute > 59)
73
- return null;
74
- const at = new Date(now);
75
- at.setHours(hour, minute + 1, 0, 0);
76
- if (at <= now)
77
- at.setDate(at.getDate() + 1);
78
- return at;
79
- }
80
- /** Drop the scheduled resume; the queue stays as it is. */
81
- export function cancelResume(project) {
82
- const s = scheduled.get(project);
83
- if (s?.run.ids.length)
84
- trace(project, 'resume-cancelled', `the resume of ${s.run.ids.join(', ')} is cancelled`);
85
- clearTimeout(s?.timer);
86
- scheduled.delete(project);
87
- broadcast({ type: 'board', project });
88
- }
89
- /** Lift a pause the usage limit set; a pause for another cause waits for the operator. */
90
- function liftLimitPause(project) {
91
- if (limitPaused.delete(project))
92
- paused.delete(project);
93
- }
94
- /** A project left the board: nothing of it may run or fire any more. */
66
+ /** A project left the board: nothing of it may run any more. */
95
67
  export function forgetProject(project) {
96
68
  for (const r of activeRuns(project))
97
69
  forgotten.add(r);
98
- clearTimeout(scheduled.get(project)?.timer);
99
- scheduled.delete(project);
100
70
  queues.delete(project);
101
71
  paused.delete(project);
102
72
  limitPaused.delete(project);
@@ -104,43 +74,9 @@ export function forgetProject(project) {
104
74
  acts.delete(project);
105
75
  }
106
76
  /**
107
- * At the reset: run the stopped items again (the harness resumes their sessions), then the queue.
108
- * A second limited run joins the first: all their items go, at the later reset.
109
- */
110
- function schedule(run, at) {
111
- const project = run.p.name;
112
- const before = scheduled.get(project);
113
- clearTimeout(before?.timer);
114
- const ids = [...new Set([...(before?.run.ids ?? []), ...run.ids])];
115
- const when = before && before.at > at ? before.at : at;
116
- const timer = setTimeout(() => {
117
- const s = scheduled.get(project);
118
- scheduled.delete(project);
119
- liftLimitPause(project);
120
- try {
121
- if (s) {
122
- const r = startRun(s.run.entry, s.run.p, s.run.ids, s.run.mode, false, s.run.harness);
123
- const how = 'queued' in r ? 'wait in the queue' : 'run again';
124
- trace(project, 'resume', `the usage limit reset: ${s.run.ids.join(', ')} ${how}`);
125
- }
126
- }
127
- catch (e) {
128
- // The board's own run of an item takes it out of the schedule first, so this is rare;
129
- // the queue still goes on.
130
- const why = e instanceof Error ? e.message : String(e);
131
- if (s)
132
- trace(project, 'resume-failed', `${s.run.ids.join(', ')}: ${why}`);
133
- advance(project);
134
- }
135
- broadcast({ type: 'board', project });
136
- }, when.getTime() - Date.now());
137
- timer.unref();
138
- scheduled.set(project, { at: when, run: { ...run, ids }, timer });
139
- }
140
- /**
141
- * A run some of whose items hit the usage limit: the main queue would hit it too, so it pauses,
142
- * and those items run again at the reset when the message names a time. The reason, for its
143
- * report.
77
+ * A run some of whose items the usage limit ended paused: the harness waits for a reset it
78
+ * knows (AD-19), so these are the week's limit, an unknown reset, one too far, or a third
79
+ * limit. The main queue would meet it too: it pauses. The reason, for its report.
144
80
  */
145
81
  function limited(run, result) {
146
82
  const hit = (result?.items ?? []).filter((i) => i.limit_resets !== undefined);
@@ -152,12 +88,12 @@ function limited(run, result) {
152
88
  limitPaused.add(project);
153
89
  }
154
90
  const resets = hit.find((i) => i.limit_resets)?.limit_resets ?? '';
155
- const at = resetAt(resets);
156
- if (at)
157
- schedule({ ...run, ids: hit.map((i) => i.id), fresh: false }, at);
158
- const when = at ? `they resume at ${at.toTimeString().slice(0, 5)}` : 'run them after the reset';
91
+ // A harness before 0.12 does not wait for the reset by itself.
92
+ const old = result?.limit_wait
93
+ ? ''
94
+ : '; gcf-harness-aif-ext 0.12 waits for the reset by itself: update it in the project';
159
95
  const queue = run.mode === 'main' ? ', the queue is paused' : '';
160
- const reason = `usage limit${resets ? `, resets ${resets}` : ''}${queue}: ${when}`;
96
+ const reason = `usage limit${resets ? `, resets ${resets}` : ''}${queue}: run them after the reset${old}`;
161
97
  trace(project, 'limit', `${hit.map((i) => i.id).join(', ')}: ${reason}`);
162
98
  return reason;
163
99
  }
@@ -169,14 +105,11 @@ function advance(project) {
169
105
  if (!next)
170
106
  return;
171
107
  trace(project, 'queue-run', `the queue starts ${next.ids.join(', ')}`);
172
- spawnRun(next, next.mode);
108
+ // Nobody clicked it now: it waits while the usage limit's reset is ahead.
109
+ spawnRun({ ...next, waitLimit: true }, next.mode);
173
110
  }
174
111
  /** The operator resumes a paused queue (after fixing what stopped it). */
175
112
  export function resumeQueue(project) {
176
- // The limit still holds until its reset: the next run would hit it again.
177
- const s = scheduled.get(project);
178
- if (s && limitPaused.has(project))
179
- throw new HttpError(409, `the queue resumes by itself at ${s.at.toTimeString().slice(0, 5)}, after the usage limit; cancel that first to resume now`);
180
113
  if (paused.has(project))
181
114
  trace(project, 'queue-resumed', 'the operator resumed the queue');
182
115
  paused.delete(project);
@@ -205,7 +138,7 @@ export function stalled(ok, result) {
205
138
  }
206
139
  /**
207
140
  * The harness report a run printed, or null for none. A report of another shape counts as none:
208
- * the close listener that reads it would throw, and take the server down with it.
141
+ * the end of the run that reads it would throw, and take the server down with it.
209
142
  */
210
143
  export function harnessReport(out) {
211
144
  let r;
@@ -224,7 +157,7 @@ export function harnessReport(out) {
224
157
  ? r
225
158
  : null;
226
159
  }
227
- // The fields read as more than text: the id, and the reset a resume is scheduled at.
160
+ // The fields read as more than text: the id, and the usage limit's reset.
228
161
  function isItem(i) {
229
162
  if (typeof i !== 'object' || i === null)
230
163
  return false;
@@ -235,66 +168,215 @@ function spawnRun(q, mode) {
235
168
  const { entry, p, ids, harness } = q;
236
169
  const run = { project: p.name, ids, started: new Date().toISOString(), mode };
237
170
  active.add(run);
238
- const args = [entry, harness, 'run', ...ids, '--json', ...(q.fresh ? ['--fresh'] : [])];
239
- const child = spawn(process.execPath, args, {
171
+ const args = [entry, harness, 'run', ...ids, '--json'];
172
+ if (q.fresh)
173
+ args.push('--fresh');
174
+ if (q.waitLimit)
175
+ args.push('--wait-limit');
176
+ // A board's run is always open to the operator: its chat settings say who waits for whom.
177
+ // shortcut: the page shows no chat yet, so nobody could answer a question there: the run
178
+ // waits for none (as `answer_timeout_min: 0`); drop the timeout when the chat screen ships.
179
+ // GCF_BOARD_CHAT_TIMEOUT: the scenario tests, which answer through the API, wait.
180
+ args.push('--chat', '--chat-timeout', process.env.GCF_BOARD_CHAT_TIMEOUT ?? '0');
181
+ const rid = randomUUID();
182
+ const relay = spawn(process.execPath, [RELAY, recordOf(rid), endOf(rid), ...args], {
240
183
  cwd: p.path,
241
- shell: false,
242
- stdio: ['ignore', 'pipe', 'pipe'],
184
+ detached: true,
185
+ stdio: 'ignore',
186
+ windowsHide: true,
243
187
  });
244
- child.stdout.setEncoding('utf8');
245
- child.stderr.setEncoding('utf8');
246
- let out = '';
247
- let err = '';
248
- child.stdout.on('data', (d) => (out += d));
249
- child.stderr.on('data', (d) => (err += d));
250
- const end = (ok, message = '') => {
251
- // A spawn that fails fires both error and close: one end only.
252
- if (!active.delete(run))
253
- return;
254
- const result = harnessReport(out);
255
- // A run of a project removed meanwhile only reports: it pauses and schedules nothing.
256
- const kept = !forgotten.has(run);
257
- const stop = kept && mode === 'main' && queues.get(p.name)?.length && stalled(ok, result);
258
- if (stop) {
259
- paused.add(p.name);
260
- limitPaused.delete(p.name);
188
+ relay.unref();
189
+ // Only a relay that started has a pid, and a run to find again; at once, the board may stop next.
190
+ const record = {
191
+ project: p.name,
192
+ path: p.path,
193
+ ids,
194
+ mode,
195
+ started: run.started,
196
+ harness,
197
+ pid: relay.pid ?? 0,
198
+ };
199
+ try {
200
+ if (relay.pid) {
201
+ mkdirSync(flightsDir(), { recursive: true });
202
+ writeFileSync(recordOf(rid), JSON.stringify(record));
203
+ flights.set(rid, run);
204
+ }
205
+ }
206
+ catch {
207
+ // No record: this board still reports the run, a board after it will not find it.
208
+ }
209
+ relay.on('error', (e) => land(q, run, rid, true, e.message));
210
+ relay.on('exit', () => land(q, run, rid, true));
211
+ return run;
212
+ }
213
+ /**
214
+ * A run's end: its report from the end file its relay wrote, or what went wrong. `live`: a
215
+ * board saw it end, so a usage limit or a stalled queue acts on it; a run that ended while no
216
+ * board was up only reports (a reset counted from now could be a day late).
217
+ */
218
+ function land(q, run, rid, live, message = '') {
219
+ // A spawn that fails fires both error and exit: one end only.
220
+ if (!active.has(run))
221
+ return;
222
+ let end = null;
223
+ try {
224
+ end = JSON.parse(readFileSync(endOf(rid), 'utf8'));
225
+ }
226
+ catch {
227
+ // No end: the relay died or never started, the message below says so.
228
+ }
229
+ // A run with no record (its write failed) has nothing to claim.
230
+ let claimed = true;
231
+ if (flights.delete(rid)) {
232
+ // The record is the claim: a second board on the same home that took it reports it there.
233
+ // shortcut: the loser does not see the result, so its main queue goes on even after a limit
234
+ // or a stall the winner paused for; two boards on one home is not a setup the board offers.
235
+ try {
236
+ unlinkSync(recordOf(rid));
261
237
  }
262
- const note = !kept
263
- ? ''
238
+ catch (e) {
239
+ if (e.code === 'ENOENT') {
240
+ active.delete(run);
241
+ if (q.mode === 'main')
242
+ advance(q.p.name);
243
+ broadcast({ type: 'board', project: run.project });
244
+ return;
245
+ }
246
+ // Held by a scanner for a moment: report now; the end stays for a board after this one,
247
+ // which reports it again.
248
+ claimed = false;
249
+ }
250
+ }
251
+ try {
252
+ if (claimed)
253
+ rmSync(endOf(rid), { force: true });
254
+ }
255
+ catch {
256
+ // Held by a scanner: its id is no other run's, so it only stays behind.
257
+ }
258
+ active.delete(run);
259
+ const { p, ids, mode } = q;
260
+ const ok = end?.code === 0;
261
+ const result = harnessReport(end?.out ?? '');
262
+ if (!end && !message)
263
+ message = "the run's relay ended without a result";
264
+ // A run of a project removed meanwhile only reports: it pauses nothing.
265
+ const kept = !forgotten.has(run);
266
+ const acting = kept && live;
267
+ const stop = acting && mode === 'main' && queues.get(p.name)?.length && stalled(ok, result);
268
+ if (stop) {
269
+ paused.add(p.name);
270
+ limitPaused.delete(p.name);
271
+ }
272
+ const note = !kept
273
+ ? ''
274
+ : !live
275
+ ? 'it ended while the board was stopped: nothing was paused'
264
276
  : limited(q, result) ||
265
277
  (stop ? 'the queue is paused: fix the cause, then resume it on the board' : '');
266
- if (stop)
267
- trace(p.name, 'queue-paused', `after ${ids.join(', ')}: ${note}`);
268
- for (const i of result?.items ?? [])
269
- if (kept && i.handoffs)
270
- trace(p.name, 'handoff', `${i.id}: ${i.handoffs} context handoff(s) to a fresh session`);
271
- const brief = err && briefError(err);
272
- const report = {
273
- id: `r${++reportSeq}`,
274
- at: new Date().toISOString(),
275
- ids,
276
- ok,
277
- result,
278
- err: (brief + message).trim(),
279
- note,
280
- };
281
- // A project removed meanwhile has no board to show it on.
282
- if (kept)
283
- reports.set(p.name, [...(reports.get(p.name) ?? []), report].slice(-KEEP_REPORTS));
284
- // The checkout is free now, for whatever queue the name has: a project added back meanwhile.
285
- if (mode === 'main')
286
- advance(p.name);
287
- broadcast({ type: 'board', project: p.name });
278
+ if (stop)
279
+ trace(p.name, 'queue-paused', `after ${ids.join(', ')}: ${note}`);
280
+ for (const i of result?.items ?? [])
281
+ if (acting && i.handoffs)
282
+ trace(p.name, 'handoff', `${i.id}: ${i.handoffs} context handoff(s) to a fresh session`);
283
+ // A harness before 0.11 refuses the chat flags every board run passes, one before 0.12 the
284
+ // limit wait of a queued start: say what to update.
285
+ const old = /unknown option '--chat|--chat-timeout is a number of minutes above 0/;
286
+ const brief = !end?.err
287
+ ? ''
288
+ : old.test(end.err)
289
+ ? 'board runs need gcf-harness-aif-ext 0.11 or later: update it in the project'
290
+ : /unknown option '--wait-limit'/.test(end.err)
291
+ ? 'queued runs need gcf-harness-aif-ext 0.12 or later: update it in the project'
292
+ : briefError(end.err);
293
+ const report = {
294
+ id: `r${++reportSeq}`,
295
+ at: new Date().toISOString(),
296
+ ids,
297
+ ok,
298
+ result,
299
+ err: (brief + message).trim(),
300
+ note,
288
301
  };
289
- child.on('error', (e) => end(false, e.message));
290
- child.on('close', (code) => end(code === 0));
291
- return run;
302
+ // A project removed meanwhile has no board to show it on.
303
+ if (kept)
304
+ reports.set(p.name, [...(reports.get(p.name) ?? []), report].slice(-KEEP_REPORTS));
305
+ // The checkout is free now, for whatever queue the name has: a project added back meanwhile.
306
+ if (mode === 'main')
307
+ advance(p.name);
308
+ broadcast({ type: 'board', project: p.name });
309
+ }
310
+ /**
311
+ * Whether the relay of a run found on adoption still goes: its pid lives and it touched its
312
+ * record lately (relay.ts). A pid alone is not enough: another process may hold it after a
313
+ * restart of Windows, whose fast startup keeps the uptime going.
314
+ */
315
+ function going(rid, pid) {
316
+ try {
317
+ return alive(pid) && Date.now() - statSync(recordOf(rid)).mtimeMs < BEAT_STALE_MS;
318
+ }
319
+ catch {
320
+ return false;
321
+ }
322
+ }
323
+ /**
324
+ * The runs a board before this one started for the project: one going shows as active until it
325
+ * ends, one that ended meanwhile as its report, one whose relay died with no end as a failure.
326
+ * shortcut: the records of a project removed while no board was up stay in the board home until
327
+ * it is added back; sweep the ones of unregistered projects at the start if they pile up.
328
+ */
329
+ export function adoptRuns(entry, p) {
330
+ let names;
331
+ try {
332
+ names = readdirSync(flightsDir());
333
+ }
334
+ catch {
335
+ return;
336
+ }
337
+ for (const name of names) {
338
+ if (!name.endsWith('.json') || name.endsWith('.end.json'))
339
+ continue;
340
+ const rid = name.slice(0, -'.json'.length);
341
+ if (flights.has(rid))
342
+ continue;
343
+ let f;
344
+ try {
345
+ f = JSON.parse(readFileSync(recordOf(rid), 'utf8'));
346
+ }
347
+ catch {
348
+ continue;
349
+ }
350
+ if (f.project !== p.name || f.path !== p.path)
351
+ continue;
352
+ const run = { project: p.name, ids: f.ids, started: f.started, mode: f.mode };
353
+ const q = { entry, p, ids: f.ids, mode: f.mode, harness: f.harness };
354
+ active.add(run);
355
+ flights.set(rid, run);
356
+ // shortcut: off Windows a dead relay leaves its harness going (no job object), reported
357
+ // failed here; record the harness pid if that bites. A board started within a beat of the
358
+ // machine waking takes a run going since before the sleep for a dead one (its beat is late):
359
+ // a main queue then starts in a busy checkout, and the end that relay writes stays behind.
360
+ // Once adopted, only the pid's death ends it: a sleep stops the beats too.
361
+ if (going(rid, f.pid)) {
362
+ const poll = setInterval(() => {
363
+ if (alive(f.pid))
364
+ return;
365
+ clearInterval(poll);
366
+ land(q, run, rid, true);
367
+ }, 2000);
368
+ poll.unref();
369
+ }
370
+ else
371
+ land(q, run, rid, false);
372
+ }
373
+ broadcast({ type: 'board', project: p.name });
292
374
  }
293
375
  /**
294
376
  * Start a batch in the project's run mode, or queue it behind the main run going on. Its end
295
377
  * is a run report with the harness report, or what went wrong. `fresh` starts new agent
296
378
  * sessions where the harness would resume the interrupted ones. `harness` is the domain's
297
- * (`domain.harness`); the tests take GCF's.
379
+ * (`domain.harness`); the tests take GCF's. Its sessions are open to the operator's chat.
298
380
  */
299
381
  export function startRun(entry, p, ids, mode = 'worktree', fresh = false, harness = 'gcf-harness') {
300
382
  // A second click on the same card: the harness would refuse it on its lock, noisily.
@@ -302,17 +384,6 @@ export function startRun(entry, p, ids, mode = 'worktree', fresh = false, harnes
302
384
  const busy = ids.filter((id) => queued.includes(id) || going.some((r) => r.ids.includes(id)));
303
385
  if (busy.length)
304
386
  throw new HttpError(409, `already running from this board: ${busy.join(', ')}`);
305
- // The operator runs an item the limit stopped before its reset: they know better, so it goes
306
- // now, and the limit's pause with it; the rest of the schedule stays.
307
- const s = scheduled.get(p.name);
308
- if (s?.run.ids.some((id) => ids.includes(id))) {
309
- const early = s.run.ids.filter((id) => ids.includes(id));
310
- trace(p.name, 'resume-cancelled', `${early.join(', ')}: the operator runs them before the reset`);
311
- s.run = { ...s.run, ids: s.run.ids.filter((id) => !ids.includes(id)) };
312
- if (!s.run.ids.length)
313
- cancelResume(p.name);
314
- liftLimitPause(p.name);
315
- }
316
387
  // A paused queue holds a new main run too: it would repeat the failure, and jump the queue.
317
388
  if (mode === 'main' && (paused.has(p.name) || going.some((r) => r.mode === 'main'))) {
318
389
  queues.set(p.name, [...(queues.get(p.name) ?? []), { entry, p, ids, mode, fresh, harness }]);