gcf-board 0.20.0 → 0.22.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/README.md CHANGED
@@ -6,6 +6,8 @@ A local web board for game projects on [GCF](../gcf-aif-ext): the items by statu
6
6
 
7
7
  - Node.js ≥ 22.18
8
8
  - [`ai-factory`](https://www.npmjs.com/package/ai-factory) installed globally, and in each project [`gcf-aif-ext`](../gcf-aif-ext) ≥ 0.18 (`gcf board --json` with `schema: 4`: the columns, the moves, the item's fields, the blocks and the Help terms come from it as data)
9
+ - for 0.22: `gcf-aif-ext` ≥ 0.24 and `gcf-harness-aif-ext` ≥ 0.23 for the **shelved** chip (an older pair stops a main batch at a card's loose code, as before)
10
+ - for 0.21: `gcf-aif-ext` ≥ 0.23 for **amend** (an older core offers no such move)
9
11
  - for 0.20: `gcf-aif-ext` ≥ 0.22 for **Changes** (an older core shows neither the screen nor its marker)
10
12
  - for runs: [`gcf-harness-aif-ext`](../gcf-harness-aif-ext) ≥ 0.11 (every board run opens its chat: `--chat`, `gcf-harness chat`; it waits the project's answer time) and Claude Code (`claude -p`); ≥ 0.12 to wait for the usage limit's reset and for queued runs (`--wait-limit`)
11
13
  - for the project chat: `gcf-aif-ext` ≥ 0.12 (`domain.chat`, `agent.rules`) and Claude Code
@@ -42,6 +44,9 @@ The board knows no domain by name: the project's board read gives its columns, m
42
44
  - **Board**: columns ready, running, blocked, awaiting-verdict, awaiting-decision, unplayed, parked. A card shows the type, the gate, the plan progress (`2/5`), the severity, `verified`, the model, **needs N** and **needed by N**. A running card shows when its run log was last written (`active 12 s ago`), and `quiet 6 min` when the log has been silent for 5 minutes or more. A run's end report gives each item's cost when the agent reported it. Pointing at a card (or focusing it from the keyboard) lights up the cards it needs and the cards that need it, each saying how, and dims the rest. The toolbar (board 0.9.0, core 0.13.0) searches ids and titles, keeps **waiting for me**, filters by the fields the domain marks `filter` (GCF: type, gate, severity, system, milestone; several values at once, each a chip to take off) and lays the board out in lanes by a field it marks `group` (system, parent, milestone): an item with two systems stands in both lanes, one with none in **none**, a parent lane is named by the feature's title. The mouse drags the board sideways from its empty space; the wheel over a column with no scroll of its own pans it.
43
45
  - **An item** (a window over the screen, dragged by its head; a page on a phone; board 0.14.0): its **Status** (why it is blocked or waits, its fields, its dependencies; it opens there when it is blocked or waits), its file (the front matter folded, a `key:` body by sections), its plan and its run log as it grows, its **Lessons**, and the moves the core offers for it (`items[].moves`, Methodology §4.1): run, verdict, decide, block, unblock, drop, close, submit, depends. Each move's form comes from the core; the core still checks the rest itself, and the board shows its answer. **Dependencies**: what it needs that has not ended in history (an item with its column, a design unit with its TBDs or the questions that block it, a graveyard line, an unknown id) and the items that need it, each a link; **Edit…** opens the picker of the board's items and design units (search by id and title, or type an id), and Save sends the `depends` move's adds and removes. **History** (core 0.13.0): its moves newest first, when, which, who (a run, your session, you; unknown on a commit older than the framework's marks), the commit and its subject; then its runs, as on the Runs screen. **Related**: its feature's other children, and the graveyard lines tagged with its system ("did we kill this before?"). An item that ended opens from **Ended** with its History.
44
46
  - **Runs** (harness 0.13.0): what runs now with the run's model and effort, its last log lines, **Whole log** and **Stop**; the queue with what each item will run on; the past runs of the harness's run log, newest first, 50 at a time: start, end, mode, cost, and per item its result word, the reason word for word, cost, tokens, turns, handoffs, a broken step and what it ran on. **log** opens the part of the item's log that run wrote, **chat** that run's chat. Every start the operator asks for (Run selected, Run next, a drop on running, this screen) asks first with a model and effort picker for that run only (**default: each item's own**); the drawer's Run is one click. An older harness shows the active runs only, and the dialog has no pickers. The API: `GET /api/p/<project>/runs/past?limit=` (`gcf-harness runs --json`; 404 without a harness that keeps them), `GET …/item/<id>/history` (`{id, moves, runs}`), `GET …/log/<id>?from=&to=` (a past run's part, once: `{text, cut}`, at most its last 2 MB; without `from` and `to` the log as it grows), `POST …/run` with `model` and `effort`, `POST …/inbox/<entry>/draft` (`{thread, created}`).
47
+ - **Log** (board 0.20.1, gcf-session 0.18.1): a subagent's lines say so (`subagent:`, `subagent tool:`, `subagent tool error:`), drawn as the main agent's kinds; the pulse's current action names a subagent's call as one.
48
+ - **Amend** (board 0.21.0, core 0.23.0): under "more" on a card: the form opens on its text, shows old and new lines before the move, and refuses an edit made meanwhile with the text you typed kept beside it. A chat agent's proposal shows the same lines. During that card's run it is refused, and the proposal offers **Send to the run**, to a live session only.
49
+ - **Run again** (board 0.20.1): an item a main batch has ended, blocked for one, can be run again while the batch goes on: it queues behind the batch. An item the batch works or has yet to reach is still refused with `already running from this board`, and so is every item of a worktree batch until that batch ends.
45
50
  - **Changes** (board 0.20.0, core 0.22.0): what is not committed and how it differs, view only: the agent commits. The header's `● 7 changed` counts the main checkout, and says `run writing in main` while a run works there; the screen switches between the main checkout and each run's worktree. A text file opens its diff, a picture its before and after; a binary file, the project's `no_diff:` globs (one glob a line in Settings), links, submodules, nested repositories and Git LFS files are listed and open nothing. It follows a move, a commit or an add at once, a save in an editor within 30 s.
46
51
  - **Drag**:
47
52
  - a ready card into **running** starts its run;
@@ -24,7 +24,7 @@ import { isUpload, saveUpload, UPLOAD_MAX } from './upload.js';
24
24
  import { addProject, homeDir, listProjects, projectOf, removeProject, yoloFile, } from './registry.js';
25
25
  import { allThemes } from './themes.js';
26
26
  import { askIfDue, askUsage, configureUsage, lastUsage } from './usage.js';
27
- import { activeRuns, adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, runsOf, setAutopilot, startRun, unqueue, } from './runs.js';
27
+ import { activeRuns, adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, retryWaiting, runsOf, setAutopilot, startRun, unqueue, } from './runs.js';
28
28
  import { acceptProposal, agentDefaults, agentPresets, chatCard, deniedGroupIn, lastDeniedOf, lastRunEnd, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
29
29
  import { threadDir, threadOfEntry } from 'gcf-session';
30
30
  const send = (res, status, body) => {
@@ -99,6 +99,9 @@ const questionText = (b, move, id) => {
99
99
  return undefined;
100
100
  return (b.questions ?? []).find((q) => q.id === id)?.question ?? null;
101
101
  };
102
+ /** The core lists 2000 rows at most, so a Commit ticks no more. */
103
+ const CHANGE_PATHS_MAX = 2000;
104
+ const COMMIT_TIMEOUT_MS = 600_000;
102
105
  /** The most paths one edits diff takes: a refusal past this many is read in the console. */
103
106
  const EDIT_PATHS_MAX = 2000;
104
107
  /** The same for an older core, each path an argument (core 0.20.1). */
@@ -152,7 +155,7 @@ const headOf = (dir) => new Promise((resolve) => execFile('git', ['rev-parse', '
152
155
  /** Whether the usage limit holds for the account now (decision 22): Draft waits for its reset. */
153
156
  const limitHolds = (q) => q?.info.status === 'rejected' && (q.info.resetsAt ?? 0) * 1000 > Date.now();
154
157
  /** The ISO time a file was last written, or null when it is not there. */
155
- /** The last `tool: …` line of a run log's last 16 KB, without its clock; null without one. */
158
+ /** The last call of a run log's last 16 KB, a subagent's too, without its clock; null without one. */
156
159
  export function doingOf(file) {
157
160
  let text = '';
158
161
  try {
@@ -174,7 +177,7 @@ export function doingOf(file) {
174
177
  const line = text
175
178
  .split(/\r?\n/)
176
179
  .reverse()
177
- .find((l) => /(^|\] )tool: /.test(l));
180
+ .find((l) => /(^|\] )(subagent )?tool: /.test(l));
178
181
  return line ? line.replace(/^\[[^\]]*\] /, '').slice(0, 200) : null;
179
182
  }
180
183
  const activeAt = (file) => {
@@ -555,11 +558,15 @@ export function createApp(o) {
555
558
  const body = await bodyOf(req, CHAT_BODY_MAX);
556
559
  await withUploads(p.path, body);
557
560
  const line = chatInput(body, await unitsFor(p, body));
561
+ // A decision for the run itself: a run ended meanwhile hands it to no other agent.
562
+ const liveOnly = body.live_only === true;
558
563
  let harness;
559
564
  try {
560
565
  harness = await harnessOf(p);
561
566
  }
562
567
  catch (e) {
568
+ if (liveOnly)
569
+ throw new HttpError(409, 'no live session takes it: no harness here');
563
570
  // No harness, so no run: a message goes to the item's thread all the same.
564
571
  const t = line.type === 'say' ? await toThread(p, m[2], line) : null;
565
572
  if (t)
@@ -589,7 +596,7 @@ export function createApp(o) {
589
596
  return send(res, 202, { ok: true });
590
597
  // No live run session: a message goes to the item's thread of the project chat (AD-49).
591
598
  // An item the board read knows: a stale or mistyped id gets no thread.
592
- const t = r.code === 3 && line.type === 'say' ? await toThread(p, m[2], line) : null;
599
+ const t = r.code === 3 && line.type === 'say' && !liveOnly ? await toThread(p, m[2], line) : null;
593
600
  if (t)
594
601
  return send(res, 202, t);
595
602
  const why = briefError(r.err || r.out).replace(/^[\w-]+ chat: /, '');
@@ -818,6 +825,9 @@ export function createApp(o) {
818
825
  await rm(dir, { recursive: true, force: true });
819
826
  }
820
827
  broadcast({ type: 'board', project: p.name });
828
+ // A move may have ended what a queued card waits for, or taken it out of its depends.
829
+ if (r.ok)
830
+ retryWaiting(p.name);
821
831
  // A refusal the board can act on (core 0.20): the page offers its fixes.
822
832
  const refusal = r.ok ? undefined : refusalOf(r.err);
823
833
  send(res, 200, {
@@ -830,6 +840,29 @@ export function createApp(o) {
830
840
  });
831
841
  },
832
842
  ],
843
+ [
844
+ // What a fix of an item's text would change (core 0.23): its `--dry-run --json`, for the
845
+ // form and an agent's proposal. A POST: the text may run past a URL's limit.
846
+ 'POST',
847
+ /^\/api\/p\/([^/]+)\/item\/([a-z0-9][a-z0-9-]*)\/amend\/preview$/,
848
+ async (req, res, m) => {
849
+ const p = await projectOf(m[1]);
850
+ const asked = await bodyOf(req, CHAT_BODY_MAX);
851
+ const { moves } = domains.get(p.name) ?? (await boardOf(p)).domain;
852
+ if (!moves.amend?.preview)
853
+ throw new HttpError(404, 'this core has no preview of a fix');
854
+ const b = {
855
+ cmd: 'amend',
856
+ id: m[2],
857
+ ...Object.fromEntries(['text', 'add', 'title', 'from'].filter((k) => asked[k]).map((k) => [k, asked[k]])),
858
+ };
859
+ const args = [...moveArgs(b, moves), '--dry-run', '--json'];
860
+ const r = await cli(p, args, undefined, moveInput(b, moves));
861
+ if (!r.ok)
862
+ throw new HttpError(400, briefError(r.err || r.out));
863
+ send(res, 200, jsonOf(r, 'item amend --dry-run'));
864
+ },
865
+ ],
833
866
  [
834
867
  // The hand edits a `dirty` refusal names (core 0.20): the staged part and the part not
835
868
  // staged, read by `gcf edits diff`. Paths under gcf/ only, as the refusal gives them.
@@ -988,6 +1021,28 @@ export function createApp(o) {
988
1021
  send(res, 200, jsonOf(r, 'gcf changes'));
989
1022
  },
990
1023
  ],
1024
+ [
1025
+ // The operator's Commit on Changes (`gcf changes commit`, core 0.24): their ticked files and
1026
+ // their text on stdin. Long enough for a slow project hook: a kill would leave index.lock.
1027
+ 'POST',
1028
+ /^\/api\/p\/([^/]+)\/changes\/commit$/,
1029
+ async (req, res, m) => {
1030
+ const p = await projectOf(m[1]);
1031
+ const { message, paths } = await bodyOf(req);
1032
+ if (typeof message !== 'string' || !message.trim())
1033
+ throw new HttpError(400, 'message: the text of the commit');
1034
+ if (!Array.isArray(paths) ||
1035
+ !paths.length ||
1036
+ paths.length > CHANGE_PATHS_MAX ||
1037
+ paths.some((x) => typeof x !== 'string'))
1038
+ throw new HttpError(400, `paths: 1 to ${CHANGE_PATHS_MAX} paths from the list`);
1039
+ const r = await cli(p, ['gcf', 'changes', 'commit', '--fields-file=-', '--json'], COMMIT_TIMEOUT_MS, JSON.stringify({ message, paths }));
1040
+ broadcast({ type: 'board', project: p.name });
1041
+ send(res, 200, r.ok
1042
+ ? { ok: true, ...jsonOf(r, 'gcf changes commit') }
1043
+ : { ok: false, err: briefError(r.err || r.out) });
1044
+ },
1045
+ ],
991
1046
  [
992
1047
  'GET',
993
1048
  /^\/api\/p\/([^/]+)\/changes\/diff$/,
@@ -44,22 +44,27 @@ function globalRoots() {
44
44
  return roots;
45
45
  }
46
46
  /**
47
- * The refusal an operator reads: the core throws, and node prints the stack under an
48
- * `Error: <message>` header, every line of the message (a git failure's cause comes after its
49
- * first line). Anything else is shown as it came.
47
+ * The refusal an operator reads: core 0.22.2 prints its words alone, shown as they came. An
48
+ * older core throws, and node prints the stack under an `Error: <message>` header, every line of
49
+ * the message (a git failure's cause comes after its first line).
50
50
  */
51
51
  export function briefError(err) {
52
52
  // The core's machine line is for the board (refusalOf), not for the operator to read.
53
53
  const words = err.replace(REFUSAL_LINE, '');
54
- const m = words.match(/^\w*Error: ([\s\S]*?)\r?\n {4}at /m) ?? words.match(/^\w*Error: (.+)$/m);
54
+ // Only node's crash opens with its frame or its header: an `Error: …` line further down belongs
55
+ // to the words (a hook's output a refusal quotes).
56
+ const crash = /^(.+:\d+|\w*Error: .*)\r?$/.test(words.trimStart().split('\n', 1)[0]);
57
+ const m = crash
58
+ ? (words.match(/^\w*Error: ([\s\S]*?)\r?\n {4}at /m) ?? words.match(/^\w*Error: (.+)$/m))
59
+ : null;
55
60
  return (m?.[1] ?? words).replaceAll('\r', '').trim();
56
61
  }
57
62
  const REFUSAL_LINE = /^gcf-refusal: .*(\r?\n)?/gm;
58
63
  /**
59
64
  * The core's machine refusal in a command's error (core 0.20): its last `gcf-refusal: {…}`
60
- * line, read as data, never its words. Only `dirty` is known; a path not under `gcf/`, or one
61
- * climbing out of it, is left out (the edits commands refuse it too). Undefined for an older
62
- * core, a broken line or no path left.
65
+ * line, read as data, never its words. Only the codes of `Refusal` are known; a path not under
66
+ * `gcf/`, or one climbing out of it, is left out (the edits commands refuse it too). Undefined
67
+ * for an older core, a broken line or no path left.
63
68
  */
64
69
  export function refusalOf(err) {
65
70
  const last = [...err.matchAll(/^gcf-refusal: (.+?)\r?$/gm)].at(-1)?.[1];
@@ -72,7 +77,11 @@ export function refusalOf(err) {
72
77
  catch {
73
78
  return undefined;
74
79
  }
75
- const { code, paths, left } = (data ?? {});
80
+ const { code, paths, left, reason } = (data ?? {});
81
+ if (code === 'running' || code === 'stale')
82
+ return { code };
83
+ if (code === 'shelve')
84
+ return { code, reason: typeof reason === 'string' ? reason : '' };
76
85
  if (!Array.isArray(paths))
77
86
  return undefined;
78
87
  const safe = (a) => (Array.isArray(a) ? a : []).filter(gatePath);
@@ -63,15 +63,24 @@ async function readChanges(project, w) {
63
63
  // The first read names the files: the next poll has no stamp of them, and reads once more.
64
64
  if (read?.watch && !w.files.length)
65
65
  w.files = [read.watch.index, read.watch.head];
66
- if (busy || read) {
67
- const event = { type: 'changes', count: read ? read.count : null };
68
- w.last = `data: ${JSON.stringify(event)}\n\n`;
69
- for (const c of w.clients)
70
- c.write(w.last);
71
- }
66
+ w.last = `data: ${JSON.stringify(markerEvent(busy, read))}\n\n`;
67
+ for (const c of w.clients)
68
+ c.write(w.last);
72
69
  } while (w.again && changesWatches.get(project) === w);
73
70
  w.reading = false;
74
71
  }
72
+ /**
73
+ * What the marker says: a run's work, or the count. `unknown` when the read failed, or when the
74
+ * project is not in git, whose count of 0 would read as a clean checkout: said, not left out, as
75
+ * a page still shows what the last read told it.
76
+ */
77
+ export function markerEvent(busy, read) {
78
+ if (busy)
79
+ return { type: 'changes', count: null };
80
+ return read && read.base !== null
81
+ ? { type: 'changes', count: read.count }
82
+ : { type: 'changes', count: null, unknown: true };
83
+ }
75
84
  /** A project's files moved, or a run began or ended: read its marker if a page shows it. */
76
85
  export function signalChanges(project) {
77
86
  const w = changesWatches.get(project);
@@ -77,7 +77,8 @@ function save() {
77
77
  continue;
78
78
  projects[name] = {
79
79
  path: where,
80
- queue: (queues.get(name) ?? []).map(({ entry: _e, p: _p, ...q }) => q),
80
+ // `waiting` stays behind: a board started again tries it, the dependency may have ended.
81
+ queue: (queues.get(name) ?? []).map(({ entry: _e, p: _p, waiting: _w, ...q }) => q),
81
82
  paused_by: runsOf(name).paused_by,
82
83
  paused_until: pausedUntil.get(name) ?? null,
83
84
  reports: reports.get(name) ?? [],
@@ -179,6 +180,7 @@ function queuedOf(v) {
179
180
  harness: v.harness,
180
181
  ...(v.fresh === true ? { fresh: true } : {}),
181
182
  ...(v.waitLimit === true ? { waitLimit: true } : {}),
183
+ ...(typeof v.waited === 'string' ? { waited: v.waited } : {}),
182
184
  ...(agent ? { agent } : {}),
183
185
  };
184
186
  }
@@ -299,12 +301,44 @@ function advance(project) {
299
301
  return;
300
302
  if (paused.has(project) || activeRuns(project).some((r) => r.mode === 'main'))
301
303
  return;
302
- const next = queues.get(project)?.shift();
303
- if (!next)
304
+ const queue = queues.get(project) ?? [];
305
+ const at = queue.findIndex((q) => !q.waiting);
306
+ if (at < 0)
304
307
  return;
308
+ const [next] = queue.splice(at, 1);
305
309
  trace(project, 'queue-run', `the queue starts ${next.ids.join(', ')}`);
306
310
  // Nobody clicked it now: it waits while the usage limit's reset is ahead.
307
- spawnRun({ ...next, waitLimit: true }, next.mode);
311
+ spawnRun({ ...next, waitLimit: true, queued: true }, next.mode);
312
+ }
313
+ /** What waits on a dependency is tried again; whether anything did. */
314
+ function clearWaiting(project) {
315
+ const queue = queues.get(project) ?? [];
316
+ const any = queue.some((q) => q.waiting);
317
+ for (const q of queue)
318
+ delete q.waiting;
319
+ return any;
320
+ }
321
+ /**
322
+ * Something may have ended a dependency with no run of this board: a move, an edit of `depends`.
323
+ * shortcut: a console's move is seen at the next run's end or restart; watch `gcf/` if one bites.
324
+ */
325
+ export function retryWaiting(project) {
326
+ if (clearWaiting(project))
327
+ advance(project);
328
+ }
329
+ /**
330
+ * The queue's run the gate refused on a dependency not done: that card stays at the queue's head,
331
+ * passed over until something may have ended it, the rest of its batch goes on. No failure: the
332
+ * queue does not pause.
333
+ */
334
+ function keepWaiting(q, waits, gate) {
335
+ const { queued: _queued, ...entry } = q;
336
+ const others = q.ids.filter((id) => id !== waits.id);
337
+ queues.set(q.p.name, [
338
+ { ...entry, ids: [waits.id], waiting: true, waited: gate },
339
+ ...(others.length ? [{ ...entry, ids: others, waited: undefined }] : []),
340
+ ...(queues.get(q.p.name) ?? []),
341
+ ]);
308
342
  }
309
343
  /** The operator resumes a paused queue (after fixing what stopped it). */
310
344
  export function resumeQueue(project) {
@@ -313,6 +347,7 @@ export function resumeQueue(project) {
313
347
  paused.delete(project);
314
348
  limitPaused.delete(project);
315
349
  pausedUntil.delete(project);
350
+ clearWaiting(project);
316
351
  advance(project);
317
352
  changed(project);
318
353
  }
@@ -333,6 +368,9 @@ export function stalled(ok, result) {
333
368
  if (!ok && result === null)
334
369
  return true;
335
370
  const items = result?.items ?? [];
371
+ // A card left code uncommitted: the next batch would be built on it (harness 0.22).
372
+ if (items.some((i) => i.left?.length))
373
+ return true;
336
374
  return (items.length > 0 && items.every((i) => /another run works in the main/.test(i.error ?? '')));
337
375
  }
338
376
  /**
@@ -412,6 +450,8 @@ function spawnRun(q, mode) {
412
450
  effort,
413
451
  ...(q.kind ? { kind: q.kind } : {}),
414
452
  ...(q.pilot ? { pilot: true } : {}),
453
+ ...(q.queued ? { queued: true } : {}),
454
+ ...(q.waited ? { waited: q.waited } : {}),
415
455
  };
416
456
  try {
417
457
  if (relay.pid) {
@@ -488,10 +528,20 @@ function land(q, run, rid, live, message = '') {
488
528
  limitPaused.delete(p.name);
489
529
  pausedUntil.delete(p.name);
490
530
  }
531
+ // A dependency not done: the queue's card stays. Any other end may have done it.
532
+ const waits = kept && q.queued ? result?.waits : undefined;
533
+ const sameWords = Boolean(waits) && q.waited === result?.gate;
534
+ if (waits) {
535
+ keepWaiting(q, waits, result?.gate ?? '');
536
+ if (!sameWords)
537
+ trace(p.name, 'queue-waits', result?.gate ?? '');
538
+ }
539
+ const retried = kept && !result?.waits && clearWaiting(p.name);
491
540
  const note = !kept
492
541
  ? ''
493
542
  : [
494
543
  live ? '' : 'it ended while the board was stopped',
544
+ waits ? `${waits.id} stays in the queue` : '',
495
545
  limited(q, result) ||
496
546
  (stop ? 'the queue is paused: fix the cause, then resume it on the board' : ''),
497
547
  ]
@@ -521,11 +571,11 @@ function land(q, run, rid, live, message = '') {
521
571
  err: (brief + message).trim(),
522
572
  note,
523
573
  };
524
- // A project removed meanwhile has no board to show it on.
525
- if (kept)
574
+ // A project removed meanwhile has no board to show it on; the same refusal again says nothing.
575
+ if (kept && !sameWords)
526
576
  reports.set(p.name, [...(reports.get(p.name) ?? []), report].slice(-KEEP_REPORTS));
527
577
  // The checkout is free now, for whatever queue the name has: a project added back meanwhile.
528
- if (mode === 'main')
578
+ if (mode === 'main' || retried)
529
579
  advance(p.name);
530
580
  if (kept && q.pilot)
531
581
  piloted(p.name, ok, result);
@@ -622,6 +672,8 @@ export function adoptRuns(entry, p) {
622
672
  ...{ entry, p, ids: f.ids, mode: f.mode, harness: f.harness, agent },
623
673
  ...(f.kind === 'card' ? { kind: 'card' } : {}),
624
674
  ...(f.pilot ? { pilot: true } : {}),
675
+ ...(f.queued ? { queued: true } : {}),
676
+ ...(f.waited ? { waited: f.waited } : {}),
625
677
  };
626
678
  active.add(run);
627
679
  flights.set(rid, run);
@@ -654,10 +706,28 @@ export function adoptRuns(entry, p) {
654
706
  changed(p.name);
655
707
  void pilot(p.name);
656
708
  }
709
+ /**
710
+ * Whether a main run has ended `id`: its lock names the item it works now, one later in its batch.
711
+ * No such word, and the run still holds the id.
712
+ * shortcut: a worktree batch holds an ended item until the batch ends, as no file says it ended;
713
+ * upgrade when one does.
714
+ */
715
+ function gonePast(p, run, id) {
716
+ if (run.mode !== 'main')
717
+ return false;
718
+ try {
719
+ const lock = path.join(p.path, '.gcf-session', 'runs', '.main-run.lock');
720
+ const now = readFileSync(lock, 'utf8').split('\n')[1]?.trim() ?? '';
721
+ return run.ids.indexOf(now) > run.ids.indexOf(id);
722
+ }
723
+ catch {
724
+ return false;
725
+ }
726
+ }
657
727
  /** A 409 for the ids a run of this board drives or queues: a second click on the same card. */
658
728
  export function busyCheck(p, ids) {
659
729
  const { active: going, queued } = runsOf(p.name);
660
- const busy = ids.filter((id) => queued.includes(id) || going.some((r) => r.ids.includes(id)));
730
+ const busy = ids.filter((id) => queued.includes(id) || going.some((r) => r.ids.includes(id) && !gonePast(p, r, id)));
661
731
  if (busy.length)
662
732
  throw new HttpError(409, `already running from this board: ${busy.join(', ')}`);
663
733
  }
@@ -799,7 +869,8 @@ function piloted(project, ok, result) {
799
869
  const stopped = items.filter((i) => /stopped/.test(`${i.result ?? ''} ${i.error ?? ''}`));
800
870
  // A timeout or a usage limit cut a session a rerun is meant to go on with.
801
871
  const cut = (i) => i.limit_resets !== undefined || /timed out/.test(`${i.result ?? ''} ${i.error ?? ''}`);
802
- const none = items.filter((i) => !MOVED.test(i.result ?? 'merged') && !cut(i));
872
+ // `skipped`: no session looked at it, so its next ask is no repeat of this one.
873
+ const none = items.filter((i) => !MOVED.test(i.result ?? 'merged') && !cut(i) && i.result !== 'skipped');
803
874
  for (const i of none)
804
875
  s.guard[i.id] = guardHash(s.p.path, i.id);
805
876
  if (stopped.length)
@@ -807,11 +878,17 @@ function piloted(project, ok, result) {
807
878
  const failed = items.filter((i) => ['error', 'conflict'].includes(i.result ?? ''));
808
879
  if (!ok || failed.length)
809
880
  return off('error', `a run failed${failed.length ? `: ${failed.map((i) => i.id).join(', ')}` : ''}`);
810
- if (none.length === items.length)
881
+ // The folder could not change hands (harness 0.23): the next ask would meet the same refusal.
882
+ const refused = items.find((i) => i.result === 'skipped' && i.left?.length);
883
+ if (refused)
884
+ return off('dirty', refused.reason ?? `${refused.id} did not start`);
885
+ if (none.length && none.length === items.filter((i) => i.result !== 'skipped').length)
811
886
  off('no-move', `a run of ${items.map((i) => i.id).join(', ')} made no move`);
812
887
  }
813
- /** Whether the project is idle for the autopilot: no run, no queue, no pause. */
814
- const idle = (project) => !paused.has(project) && !activeRuns(project).length && !queues.get(project)?.length;
888
+ /** Whether the project is idle for the autopilot: no run, no queue to go, no pause. */
889
+ const idle = (project) => !paused.has(project) &&
890
+ !activeRuns(project).length &&
891
+ !queues.get(project)?.some((q) => !q.waiting);
815
892
  /** Main's loose work outside gcf/ a main batch would carry; none when the gate cannot say. */
816
893
  async function looseOf(s, ids) {
817
894
  const g = await runCli(s.entry, s.p.path, [s.harness, 'gate', '--each', ...ids, '--json']);
@@ -19,6 +19,8 @@ export function runModeOf(board, id, asked) {
19
19
  const own = board.items.find((i) => i.id === id)?.run_mode;
20
20
  return own === 'main' || own === 'worktree' ? own : board.run_mode;
21
21
  }
22
+ /** A refusal whose paths a board can show and fix. */
23
+ export const editsRefusal = (r) => (r && 'paths' in r ? r : undefined);
22
24
  /**
23
25
  * What is left of a refusal's `named` paths after `gcf edits` refused them as `clean`: the ones
24
26
  * still edited, none when another card's Commit or Discard took them all. Null: not that