gcf-board 0.21.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,7 @@ 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)
9
10
  - for 0.21: `gcf-aif-ext` ≥ 0.23 for **amend** (an older core offers no such move)
10
11
  - for 0.20: `gcf-aif-ext` ≥ 0.22 for **Changes** (an older core shows neither the screen nor its marker)
11
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`)
@@ -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). */
@@ -822,6 +825,9 @@ export function createApp(o) {
822
825
  await rm(dir, { recursive: true, force: true });
823
826
  }
824
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);
825
831
  // A refusal the board can act on (core 0.20): the page offers its fixes.
826
832
  const refusal = r.ok ? undefined : refusalOf(r.err);
827
833
  send(res, 200, {
@@ -1015,6 +1021,28 @@ export function createApp(o) {
1015
1021
  send(res, 200, jsonOf(r, 'gcf changes'));
1016
1022
  },
1017
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
+ ],
1018
1046
  [
1019
1047
  'GET',
1020
1048
  /^\/api\/p\/([^/]+)\/changes\/diff$/,
@@ -77,9 +77,11 @@ export function refusalOf(err) {
77
77
  catch {
78
78
  return undefined;
79
79
  }
80
- const { code, paths, left } = (data ?? {});
80
+ const { code, paths, left, reason } = (data ?? {});
81
81
  if (code === 'running' || code === 'stale')
82
82
  return { code };
83
+ if (code === 'shelve')
84
+ return { code, reason: typeof reason === 'string' ? reason : '' };
83
85
  if (!Array.isArray(paths))
84
86
  return undefined;
85
87
  const safe = (a) => (Array.isArray(a) ? a : []).filter(gatePath);
@@ -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
  }
@@ -415,6 +450,8 @@ function spawnRun(q, mode) {
415
450
  effort,
416
451
  ...(q.kind ? { kind: q.kind } : {}),
417
452
  ...(q.pilot ? { pilot: true } : {}),
453
+ ...(q.queued ? { queued: true } : {}),
454
+ ...(q.waited ? { waited: q.waited } : {}),
418
455
  };
419
456
  try {
420
457
  if (relay.pid) {
@@ -491,10 +528,20 @@ function land(q, run, rid, live, message = '') {
491
528
  limitPaused.delete(p.name);
492
529
  pausedUntil.delete(p.name);
493
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);
494
540
  const note = !kept
495
541
  ? ''
496
542
  : [
497
543
  live ? '' : 'it ended while the board was stopped',
544
+ waits ? `${waits.id} stays in the queue` : '',
498
545
  limited(q, result) ||
499
546
  (stop ? 'the queue is paused: fix the cause, then resume it on the board' : ''),
500
547
  ]
@@ -524,11 +571,11 @@ function land(q, run, rid, live, message = '') {
524
571
  err: (brief + message).trim(),
525
572
  note,
526
573
  };
527
- // A project removed meanwhile has no board to show it on.
528
- if (kept)
574
+ // A project removed meanwhile has no board to show it on; the same refusal again says nothing.
575
+ if (kept && !sameWords)
529
576
  reports.set(p.name, [...(reports.get(p.name) ?? []), report].slice(-KEEP_REPORTS));
530
577
  // The checkout is free now, for whatever queue the name has: a project added back meanwhile.
531
- if (mode === 'main')
578
+ if (mode === 'main' || retried)
532
579
  advance(p.name);
533
580
  if (kept && q.pilot)
534
581
  piloted(p.name, ok, result);
@@ -625,6 +672,8 @@ export function adoptRuns(entry, p) {
625
672
  ...{ entry, p, ids: f.ids, mode: f.mode, harness: f.harness, agent },
626
673
  ...(f.kind === 'card' ? { kind: 'card' } : {}),
627
674
  ...(f.pilot ? { pilot: true } : {}),
675
+ ...(f.queued ? { queued: true } : {}),
676
+ ...(f.waited ? { waited: f.waited } : {}),
628
677
  };
629
678
  active.add(run);
630
679
  flights.set(rid, run);
@@ -829,11 +878,17 @@ function piloted(project, ok, result) {
829
878
  const failed = items.filter((i) => ['error', 'conflict'].includes(i.result ?? ''));
830
879
  if (!ok || failed.length)
831
880
  return off('error', `a run failed${failed.length ? `: ${failed.map((i) => i.id).join(', ')}` : ''}`);
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`);
832
885
  if (none.length && none.length === items.filter((i) => i.result !== 'skipped').length)
833
886
  off('no-move', `a run of ${items.map((i) => i.id).join(', ')} made no move`);
834
887
  }
835
- /** Whether the project is idle for the autopilot: no run, no queue, no pause. */
836
- 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);
837
892
  /** Main's loose work outside gcf/ a main batch would carry; none when the gate cannot say. */
838
893
  async function looseOf(s, ids) {
839
894
  const g = await runCli(s.entry, s.p.path, [s.harness, 'gate', '--each', ...ids, '--json']);