gcf-board 0.32.0 → 0.36.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,10 @@ 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.36: `gcf-aif-ext` ≥ 0.36 for the Plan and Implement model and effort of a card and in Settings (`agent.phase_defaults`; Inherit options) and the plan review's findings on the plan tab and the stall; an older core hides the phase rows. `gcf-harness-aif-ext` ≥ 0.35 writes `run_end.plan`
10
+ - for 0.35: `gcf-aif-ext` ≥ 0.35 (`gcf board --json` with `schema: 7`; the board refuses an older core's schema, and an older board refuses this core's) for the lessons review, the manual strip, the Rules screen and the Changes mark; `gcf-harness-aif-ext` ≥ 0.34 for the Run ended mark (an older harness writes no `run_end.instructions`). Then run `ai-factory gcf init` in the project (the `AGENTS.md` block changed)
11
+ - for 0.34: `gcf-aif-ext` ≥ 0.34 for an assumption that came due: an unanswered D2 whose trigger fired, or one of `manual(...)` or no trigger unanswered past `question_stale_after_commits`, comes with `category: decision` and stands among the decisions (Waiting for me, Needs you, the Design screen's Questions), its head saying "trigger fired: <until>" or "unanswered for N commits"; answer it with **Overrule**. Then run `ai-factory gcf init` in the project (the `AGENTS.md` block changed). An older core keeps every D2 folded among the assumptions
12
+ - for 0.33: `gcf-aif-ext` ≥ 0.33 for a move that waits behind a card's main run: a dialog closes by itself with a "Waits behind <card>" toast and its answer comes as a toast later, a chat proposal, a question's answer or a Commit under a refusal shows "Waits behind <card>" with **Cancel** in place, the top bar a pill per waiting move (`runs.moves_waiting`, read from `.gcf-session/waiting/`, so it holds over a board restart). "Allow for one run" behind a main run queues its unblock with the start, with any core. A session's or a thread's move is still refused. An older core refuses the move as before
9
13
  - for 0.32: `gcf-aif-ext` ≥ 0.32 (`gcf board --json` with `schema: 6`; the board refuses an older core's schema, and an older board refuses this core's) and `gcf-harness-aif-ext` ≥ 0.31 for the review stand-ins and `run_mode: main` by default
10
14
  - for 0.25: `gcf-aif-ext` ≥ 0.27 for **Push** and **Pull** on Changes and the header's `↑N` (an older core shows no strip)
11
15
  - for 0.23: `gcf-aif-ext` ≥ 0.25 and `gcf-harness-aif-ext` ≥ 0.24 for **Play** (an older core shows no bar)
@@ -41,7 +45,7 @@ It puts **GCF Board** on the desktop (Windows: a shortcut whose server console s
41
45
 
42
46
  ## What it does
43
47
 
44
- The board knows no domain by name: the project's board read gives its columns, moves with their forms, item fields, blocks and Help terms (`domain`, Board-PRD decision 16). The page follows design B (`docs/design/mockup`): a left nav with the project switcher (add a project, take one off the board), the screens **Command**, **Board**, **Chat**, **Inbox**, **Design**, **Runs**, **Playtest**, **Ended**, **Agent** and **Metrics** (a domain without a block has no screen for it, a project without a harness no Runs and no Metrics), and a header with the phase, the runs, the limit wait, the quota, WIP, the release, **waiting for me**, **+ item**, the gear (**Settings**, a dialog over the screen; on a phone in More) and **?**. The project and the screen are in the URL hash. On a phone a bottom bar holds Command, Board, Chat, Inbox and More. When the server is gone, the page says so and reconnects by itself. For a GCF project:
48
+ The board knows no domain by name: the project's board read gives its columns, moves with their forms, item fields, blocks and Help terms (`domain`, Board-PRD decision 16). The page follows design B (`docs/design/mockup`): a left nav with the project switcher (add a project, take one off the board), the screens **Command**, **Board**, **Chat**, **Inbox**, **Design**, **Runs**, **Playtest**, **Ended**, **Agent**, **Rules** and **Metrics** (a domain without a block has no screen for it, a project without a harness no Runs and no Metrics), and a header with the phase, the runs, the limit wait, the quota, WIP, the release, **waiting for me**, **+ item**, the gear (**Settings**, a dialog over the screen; on a phone in More) and **?**. The project and the screen are in the URL hash. On a phone a bottom bar holds Command, Board, Chat, Inbox and More. When the server is gone, the page says so and reconnects by itself. For a GCF project:
45
49
 
46
50
  - **Command**: **waiting for me**, what only the operator moves on (Board-PRD §1.3), by group, each a grid of tiles (board 0.16.0, the designer's final round): failed run reports and a paused queue (its tile opens Runs), a card waiting in a chat (its tile opens the chat), the decisions, the items to play and judge, to decide, to unblock (the columns the domain marks `human`), and a `paused: limit` item to resume. Beside it **Live**: the runs going on with their plan progress, **Follow** and **Stop**, the console runs and sessions, **Run next**, the queue, the run reports, and what the board did by itself.
47
51
  - **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.
@@ -80,6 +84,9 @@ The board knows no domain by name: the project's board read gives its columns, m
80
84
  - **Design**: where a game starts and its design changes. The steps from an empty project to the first work (the design, the pillars, the open questions, a ready unit), each with what does it: **Import GDD** (a markdown file), **Review GDD first**, **Create with agent**, **Draft with agent** for the glossary, **Pillars interview**, **Name with agent** for pillars without a name; each opens a project chat thread that follows its own skill and writes the design files without a card. **Record design** commits what a thread wrote, and **Discard draft…** takes an agent's unrecorded draft back (`gcf design discard`); a form save of the drafted part takes the draft along. The pillars, the vision, the glossary, a subsystem's purpose and each unit open in a form whose fields come from the core; a save goes through the core's checks, a refusal says why. A pillar is edited by its name, its id read-only (a changed name renames the id after the save); Retire. **Add unit** asks a subsystem, a type and a title, no id, and opens the new unit. A subsystem's purpose has **Draft with agent**. A unit's Drop, the design questions with their answer box, the designer's Export and Import. Until the first work, while steps are left, Command says how many and opens Design.
81
85
  - **Keys**: `/` search, `i` a new inbox entry, `n` a new item, `j` / `k` between cards, Enter opens one, `r` runs the focused card (it asks), `1`–`7` a column, `?` Help, `g` then a letter goes to a screen (`g c` Command, `g b` Board, `g t` Chat, `g i` Inbox, `g d` Design, `g r` Runs, `g p` Playtest, `g e` Ended, `g a` Agent, `g m` Metrics, `g s` Settings; the nav's icons say theirs), Esc closes a dialog, Help, the item's or the detail window; none while a field has the focus. Board 0.16.0: the nav is a rail of icons, the project switcher sits at the header's left.
82
86
  - **Lessons** (core 0.7.10, harness 0.9.2): what got in an agent's way, asked at the end of each session, lands in the inbox as the category Lesson, its kind (`tool`, `rules`, `framework`, `template`, `other`) the detail, with its item. The inbox filters them; a card shows `N lessons`, and the item's **Lessons** tab lists them with the inbox's buttons. A run's report line ends with `, N lessons`, and with `— code written outside aif-implement` when a session skipped that skill.
87
+ - **Lessons review** (board 0.35.0, core 0.35.0, harness 0.34.0; Board-PRD decision 66): **Review lessons (N)** in the head of Agent feedback and **Review these** on a repeated lesson's line start a project chat thread (start `lessons-review`, skill gcf-triage) whose agent groups the lessons by cause and proposes one outcome a group: a new item or an amend from the group (`from` a list), a rule (`rules add`), a report to GCF or the template (`lessons report`, a file in `~/.gcf/lessons/`), an erase with its reason, Later. Its agent may not edit `AGENTS.md`, `CLAUDE.md`, `.claude/` or `.ai-factory/`, YOLO or not. A card lists the entries it erases by their titles; a rule's and a report's card show their dry run first (`POST /api/p/<project>/move/preview`: a move with `preview` and no target, its `--dry-run --json`). **Next** under the agent's message asks for the next groups. Without an agent: filter the inbox by Lesson, tick a group, and **→ Item**, **→ Rule**, **Report ▾**, **Erase ▾** (done, duplicate, noise; it goes at once with that reason, no `of`, no confirm) or **Later**. A proposal whose move takes `--proposal` (`proposal_trailer`) is recovered after a board restart only by its own `GCF-Proposal` commit. The board passes its version to the core as `GCF_BOARD_VERSION` (a report names it).
88
+ - **Rules** (board 0.35.0, core 0.35.0): `AGENTS.md` and `CLAUDE.md` as the agent reads them (`GET /api/p/<project>/rules`, `gcf rules --json`): the text before and after GCF's block in text areas, the block folded and read-only, the size in bytes and about tokens, a note when a file has edits not committed; **Save…** shows the diff from HEAD and commits `gcf rules save --base`, refused when the file changed since the edits began; **Discard edits** reads it again. The screen shows with a core that has the move `rules-save`.
89
+ - **The instructions mark** (harness 0.34.0, core 0.35.0): a run whose commits changed the agent's instructions says so on its Run ended card, "changed the agent's instructions: AGENTS.md", with **Show diff** (`GET /api/p/<project>/rules/diff?from=&to=`, `gcf rules diff`, hex hashes only); Changes marks such files `agent instructions`, whoever wrote them. Only a reminder.
83
90
  - **Playtest**: `gcf playtest session` with the checklist grouped by subsystem; keep, tune or kill each item from the list. Each card has its own **Play** bar. A note goes to the inbox as `--category playtest`.
84
91
  - **Ended**: history (accepted) and graveyard (killed, dropped, won't-fix); a line opens the item's History.
85
92
  - **Metrics**: `gcf-harness metrics --json` of the project — how many runs reached submit or close, what they cost, handoffs, plan checks, DoD attempts, guard firings, block reasons — and, with harness 0.9.5, the cost per item over all its runs and per week and day.
@@ -4,7 +4,7 @@
4
4
  // project on the board, a move, a run, a project chat message. Every write of the project is a
5
5
  // command of the framework; a project chat's agent asks the operator for each one (talks.ts).
6
6
  import { execFile } from 'node:child_process';
7
- import { randomBytes } from 'node:crypto';
7
+ import { randomBytes, randomUUID } from 'node:crypto';
8
8
  import { createServer } from 'node:http';
9
9
  import { closeSync, createReadStream, existsSync, openSync, readSync, statSync, writeFileSync, } from 'node:fs';
10
10
  import { lstat, mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
@@ -15,7 +15,7 @@ import { BOARD_SCHEMA, gatePath, runModeOf, toolOf, } from '../shared/board.js';
15
15
  import { admit, cookieName, fromPage, hostAllowed, tokenInUrl } from './auth.js';
16
16
  import { upgrade } from './ws.js';
17
17
  import { briefError, refusalOf, runCli } from './cli.js';
18
- import { broadcast, planRev, SESSION_TTL_MIN, subscribe, watchChanges, watchProject, } from './events.js';
18
+ import { broadcast, movesWaiting, planRev, SESSION_TTL_MIN, subscribe, watchChanges, watchProject, } from './events.js';
19
19
  import { attachesUnit, CHAT_BODY_MAX, chatInput, IMAGE_EXT, pendingInput, talkInput, withUploads, } from './chat.js';
20
20
  import { reviewPresets } from './reviewPresets.js';
21
21
  import { attachmentOf, follow, followLog, logPart, readShown, shownShape } from './files.js';
@@ -25,8 +25,8 @@ import { isUpload, saveUpload, UPLOAD_MAX } from './upload.js';
25
25
  import { addProject, homeDir, listProjects, projectOf, removeProject, yoloFile, } from './registry.js';
26
26
  import { allThemes } from './themes.js';
27
27
  import { askIfDue, askUsage, configureUsage, lastUsage } from './usage.js';
28
- import { activeRuns, adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, holdProject, retryWaiting, runsOf, setAutopilot, startRun, allowOf, whileAllowing, unqueue, ticketState, watchTickets, } from './runs.js';
29
- import { acceptProposal, agentDefaults, agentPresets, chatCard, deniedRuleIn, lastDeniedOf, lastRunEnd, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, wakeTalk, talkEntry, talkId, talkLive, talkPending, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
28
+ import { activeRuns, adoptRuns, busyCheck, keepProjects, mainTaken, sweepRuns, closeReport, forgetProject, resumeQueue, holdProject, retryWaiting, runsOf, setAutopilot, setUnblocker, startRun, allowOf, whileAllowing, unqueue, ticketState, watchTickets, } from './runs.js';
29
+ import { acceptProposal, agentDefaults, agentPresets, runDefaults, chatCard, deniedRuleIn, lastDeniedOf, lastRunEnd, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, proposalTag, startDesign, startTalk, stopTalk, wakeTalk, talkEntry, talkId, talkLive, talkPending, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
30
30
  import { accountSettings, saveAccountSettings, threadDir, threadOfEntry } from 'gcf-session';
31
31
  const send = (res, status, body) => {
32
32
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
@@ -164,6 +164,8 @@ const EDIT_ARGS_MAX = 200;
164
164
  const SLUG = /^[a-z0-9][a-z0-9-]*$/;
165
165
  // A model or effort word for one run: plain, as the harness takes it.
166
166
  const WORD = /^[A-Za-z0-9][\w.-]{0,63}$/;
167
+ // A page's tag of its move (d7): no dot, so never a proposal's (`<thread>.<id>`).
168
+ const TAG = /^[\w-]{1,64}$/;
167
169
  /** A run's pick of model and effort from a request body (Board-PRD §5.9); none: each item's own. */
168
170
  function runAgent(body) {
169
171
  const pick = { model: null, effort: null };
@@ -313,7 +315,55 @@ export function createApp(o) {
313
315
  adoptRuns(o.entry, p);
314
316
  }
315
317
  };
316
- const cli = (p, args, timeout, input) => runCli(o.entry, p.path, args, timeout, input);
318
+ // GCF_BOARD_VERSION: the board's version for what the core writes of it (a lessons report, d5);
319
+ // an older core reads no such variable.
320
+ const cli = (p, args, timeout, input, env) => runCli(o.entry, p.path, args, timeout, input, {
321
+ ...(o.version && { GCF_BOARD_VERSION: o.version }),
322
+ ...env,
323
+ });
324
+ // This board's moves going now, tag → project folder: a board that stops cancels the ones
325
+ // waiting behind a main run (Main-Run-Moves-Plan d9), none goes on with no page to tell.
326
+ const ownMoves = new Map();
327
+ const cancelOwnMoves = () => {
328
+ for (const [tag, dir] of ownMoves)
329
+ for (const w of movesWaiting(dir))
330
+ if (w.tag === tag && !w.going)
331
+ try {
332
+ writeFileSync(w.cancel, '');
333
+ }
334
+ catch {
335
+ // Gone with its move meanwhile.
336
+ }
337
+ };
338
+ /**
339
+ * The operator's move `args`, tagged (GCF_MOVE_TAG): behind a main run the core waits for the
340
+ * run's edits instead of refusing, the request open the while (d7).
341
+ */
342
+ const tagged = async (p, tag, args, input) => {
343
+ // One move a tag: a second would share its record's name, and its Cancel.
344
+ if (ownMoves.has(tag))
345
+ throw new HttpError(409, `a move tagged ${tag} goes already`);
346
+ ownMoves.set(tag, p.path);
347
+ try {
348
+ return await cli(p, args, undefined, input, { GCF_MOVE_TAG: tag });
349
+ }
350
+ finally {
351
+ ownMoves.delete(tag);
352
+ }
353
+ };
354
+ /** Unblock item `id` for "Allow for one run": null when it went or the card is unblocked already. */
355
+ const unblock = async (p, id) => {
356
+ const moves = (domains.get(p.name) ?? (await boardOf(p)).domain).moves;
357
+ const r = await cli(p, moveArgs({ cmd: 'unblock', id }, moves));
358
+ if (r.ok)
359
+ return null;
360
+ // Unblocked meanwhile (another click, a console): the start goes on.
361
+ const status = (await boardOf(p)).items.find((i) => i.id === id)?.status;
362
+ return status && !['blocked', 'parked'].includes(status)
363
+ ? null
364
+ : `unblock ${id}: ${briefError(r.err)}`;
365
+ };
366
+ setUnblocker(unblock);
317
367
  // The run gate's answers being worked out, by project and ids (GET …/gate).
318
368
  const gates = new Map();
319
369
  // The last domain each project's board read gave: an item move is built from its form.
@@ -489,6 +539,7 @@ export function createApp(o) {
489
539
  usage: lastUsage(),
490
540
  presets: agentPresets(),
491
541
  defaults: agentDefaults(),
542
+ run_defaults: runDefaults(),
492
543
  // What a review row offers, and which review CLIs answer (Operator-Tasks-Plan t2 d5).
493
544
  review_presets: reviewPresets().presets,
494
545
  providers: reviewPresets().providers,
@@ -891,6 +942,20 @@ export function createApp(o) {
891
942
  }
892
943
  },
893
944
  ],
945
+ [
946
+ // The operator's Cancel of a move waiting behind a main run (d7): its cancel file, which
947
+ // the core reads while it waits. One that waits no more is recorded, or refused, already.
948
+ 'POST',
949
+ /^\/api\/p\/([^/]+)\/waiting\/([\w.-]{1,200})\/cancel$/,
950
+ async (_req, res, m) => {
951
+ const p = await projectOf(m[1]);
952
+ const w = movesWaiting(p.path).find((x) => x.tag === m[2] && !x.going);
953
+ if (!w)
954
+ throw new HttpError(409, 'already recorded: the move waits no more');
955
+ writeFileSync(w.cancel, '');
956
+ send(res, 200, { ok: true });
957
+ },
958
+ ],
894
959
  [
895
960
  'POST',
896
961
  /^\/api\/p\/([^/]+)\/move$/,
@@ -915,7 +980,9 @@ export function createApp(o) {
915
980
  // A proposal of a Draft thread makes the entry's item (Board-V2-Data-Plan §2.7): the
916
981
  // entry goes with it while it is there; a second proposal, or one after it went, has none.
917
982
  const proposal = (body.proposal ?? {});
918
- if (typeof proposal.talk === 'string' && body.from === undefined) {
983
+ // An empty list names no entry: the thread's own goes in its place.
984
+ const named = Array.isArray(body.from) ? body.from.length > 0 : body.from !== undefined;
985
+ if (typeof proposal.talk === 'string' && !named) {
919
986
  // A thread that is not there has no entry: acceptProposal says it is not there.
920
987
  const entry = existsSync(threadDir(p.path, talkId(proposal.talk)))
921
988
  ? talkEntry(p, proposal.talk)
@@ -924,14 +991,15 @@ export function createApp(o) {
924
991
  if (board &&
925
992
  board.domain.new_item === body.cmd &&
926
993
  board.inbox?.some((e) => e.id === entry))
927
- body.from = entry;
994
+ body.from = [entry];
928
995
  }
929
996
  let args = moveArgs(body, domain?.moves);
930
- const run = () => cli(p, args, undefined, moveInput(body, domain?.moves));
997
+ const run = (tag) => tagged(p, tag, args, moveInput(body, domain?.moves));
931
998
  // An agent's proposal made (AD-16, AD-33): its record goes with the move.
932
999
  const { talk, id } = (body.proposal ?? {});
1000
+ // The page's own tag finds its move among the waiting ones (d7).
933
1001
  if (body.proposal === undefined)
934
- r = await run();
1002
+ r = await run(typeof body.tag === 'string' && TAG.test(body.tag) ? body.tag : randomUUID());
935
1003
  else {
936
1004
  if (typeof talk !== 'string' || typeof id !== 'string' || !/^[\w-]+$/.test(id))
937
1005
  throw new HttpError(400, 'a proposal names its talk and its id');
@@ -951,15 +1019,20 @@ export function createApp(o) {
951
1019
  return;
952
1020
  }
953
1021
  body.id = dry.out.trim().split(/\s/)[0];
954
- // Its commit names the proposal: a recovery tells it from another's of one id.
955
- args = [...withItemId(args, String(body.id)), `--proposal=${talk}/${id}`];
1022
+ args = withItemId(args, String(body.id));
956
1023
  }
957
- const mark = body.cmd === domain?.new_item ? `${talk}/${id}` : undefined;
1024
+ // Its commit names the proposal (a move that takes it, schema 7): a recovery finds
1025
+ // the move by it, a new item told from another's of one id.
1026
+ const spec = domain?.moves[String(body.cmd)];
1027
+ const mark = spec?.proposal_trailer ? `${talk}/${id}` : undefined;
1028
+ if (mark)
1029
+ args = [...args, `--proposal=${mark}`];
958
1030
  const item = typeof body.id === 'string' ? body.id : '';
959
1031
  const read = await boardOf(p);
960
1032
  const ids = idsOf(read);
961
1033
  const question = questionText(read, String(body.cmd), item);
962
- r = await acceptProposal(p, talk, id, String(body.cmd), item, ids, run, mark, question);
1034
+ const go = () => run(proposalTag(talk, id));
1035
+ r = await acceptProposal(p, talk, id, String(body.cmd), item, ids, go, mark, question);
963
1036
  broadcast({ type: 'talks', project: p.name });
964
1037
  }
965
1038
  }
@@ -1007,6 +1080,53 @@ export function createApp(o) {
1007
1080
  send(res, 200, jsonOf(r, 'item amend --dry-run'));
1008
1081
  },
1009
1082
  ],
1083
+ [
1084
+ // What a move with `preview` and no target would do (Lessons-Review-Plan d7): its own args,
1085
+ // `--dry-run --json` in place of `--commit` (a rule's diff, a report's files).
1086
+ 'POST',
1087
+ /^\/api\/p\/([^/]+)\/move\/preview$/,
1088
+ async (req, res, m) => {
1089
+ const p = await projectOf(m[1]);
1090
+ const b = await bodyOf(req, CHAT_BODY_MAX);
1091
+ const { moves } = domains.get(p.name) ?? (await boardOf(p)).domain;
1092
+ const spec = moves[String(b.cmd)];
1093
+ if (!Object.hasOwn(moves, String(b.cmd)) || !spec.preview)
1094
+ throw new HttpError(404, `${String(b.cmd)} has no preview`);
1095
+ const args = [...moveArgs(b, moves).filter((a) => a !== '--commit'), '--dry-run', '--json'];
1096
+ const r = await cli(p, args, undefined, moveInput(b, moves));
1097
+ if (!r.ok)
1098
+ throw new HttpError(400, briefError(r.err || r.out));
1099
+ send(res, 200, jsonOf(r, `${String(b.cmd)} --dry-run`));
1100
+ },
1101
+ ],
1102
+ [
1103
+ // The agent's instruction files for the Rules screen (Lessons-Review-Plan d8): `gcf rules`.
1104
+ 'GET',
1105
+ /^\/api\/p\/([^/]+)\/rules$/,
1106
+ async (_req, res, m) => {
1107
+ const p = await projectOf(m[1]);
1108
+ const r = await cli(p, ['gcf', 'rules', '--json']);
1109
+ if (!r.ok)
1110
+ throw new HttpError(400, briefError(r.err || r.out));
1111
+ send(res, 200, jsonOf(r, 'gcf rules'));
1112
+ },
1113
+ ],
1114
+ [
1115
+ // What a run changed in the agent's instructions (Lessons-Review-Plan d9): `gcf rules diff`
1116
+ // of its run end's `from..to`, hex only (the core refuses any other word too).
1117
+ 'GET',
1118
+ /^\/api\/p\/([^/]+)\/rules\/diff$/,
1119
+ async (_req, res, m, url) => {
1120
+ const p = await projectOf(m[1]);
1121
+ const [from, to] = ['from', 'to'].map((k) => url.searchParams.get(k) ?? '');
1122
+ if (![from, to].every((x) => /^[0-9a-f]{4,64}$/i.test(x)))
1123
+ throw new HttpError(400, 'from and to are commit hashes, hex only');
1124
+ const r = await cli(p, ['gcf', 'rules', 'diff', `--from=${from}`, `--to=${to}`, '--json']);
1125
+ if (!r.ok)
1126
+ throw new HttpError(400, briefError(r.err || r.out));
1127
+ send(res, 200, jsonOf(r, 'gcf rules diff'));
1128
+ },
1129
+ ],
1010
1130
  [
1011
1131
  // The hand edits a `dirty` refusal names (core 0.20): the staged part and the part not
1012
1132
  // staged, read by `gcf edits diff`. Paths under gcf/ only, as the refusal gives them.
@@ -1298,17 +1418,21 @@ export function createApp(o) {
1298
1418
  const start = () => [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, { fresh, harness, agent, allow }));
1299
1419
  // "Allow for one run" (Permission-Stop-Plan d3): the unblock and the start as one step,
1300
1420
  // the autopilot held off between them, so no run takes the card without its allowance.
1421
+ // Behind a main run the whole step waits in the queue, in any mode (Main-Run-Moves-Plan
1422
+ // d10): an unblock now would wait in the core, the autopilot held off all the while.
1423
+ const behind = mainTaken(p.name);
1301
1424
  const started = body.unblock === true && allow
1302
- ? await whileAllowing(p.name, async () => {
1303
- for (const id of ids) {
1304
- const args = moveArgs({ cmd: 'unblock', id }, board.domain.moves);
1305
- const r = await cli(p, args);
1306
- if (!r.ok)
1307
- throw new HttpError(409, `unblock ${id}: ${briefError(r.err)}`);
1308
- }
1309
- broadcast({ type: 'board', project: p.name });
1310
- return start();
1311
- })
1425
+ ? behind
1426
+ ? [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, { fresh, harness, agent, allow, unblock: part }))
1427
+ : await whileAllowing(p.name, async () => {
1428
+ for (const id of ids) {
1429
+ const why = await unblock(p, id);
1430
+ if (why)
1431
+ throw new HttpError(409, why);
1432
+ }
1433
+ broadcast({ type: 'board', project: p.name });
1434
+ return start();
1435
+ })
1312
1436
  : start();
1313
1437
  send(res, 202, {
1314
1438
  started: started.flatMap((s) => s.started ?? []),
@@ -1467,6 +1591,8 @@ export function createApp(o) {
1467
1591
  for (const k of ['close', 'closeAllConnections']) {
1468
1592
  const own = server[k].bind(server);
1469
1593
  server[k] = ((...a) => {
1594
+ if (k === 'close')
1595
+ cancelOwnMoves();
1470
1596
  for (const s of pages)
1471
1597
  s.destroy();
1472
1598
  return own(...a);
@@ -64,7 +64,7 @@ function globalRoots() {
64
64
  */
65
65
  export function briefError(err) {
66
66
  // The core's machine line is for the board (refusalOf), not for the operator to read.
67
- const words = err.replace(REFUSAL_LINE, '');
67
+ const words = err.replace(REFUSAL_LINE, '').replace(WAITING_LINES, '');
68
68
  // Only node's crash opens with its frame or its header: an `Error: …` line further down belongs
69
69
  // to the words (a hook's output a refusal quotes).
70
70
  const crash = /^(.+:\d+|\w*Error: .*)\r?$/.test(words.trimStart().split('\n', 1)[0]);
@@ -74,6 +74,8 @@ export function briefError(err) {
74
74
  return (m?.[1] ?? words).replaceAll('\r', '').trim();
75
75
  }
76
76
  const REFUSAL_LINE = /^gcf-refusal: .*(\r?\n)?/gm;
77
+ // A wait behind a main run (core 0.33): its words and machine line came before the outcome.
78
+ const WAITING_LINES = /^(gcf-waiting: .*|.* waits: the run of .* Nothing is written while it waits\.)\r?$(\r?\n)?/gm;
77
79
  // Push and Pull's refusals with no data (core 0.27).
78
80
  const PUSH_CODES = ['no-remote', 'behind', 'diverged', 'rejected', 'auth', 'timeout'];
79
81
  /**
@@ -94,7 +96,7 @@ export function refusalOf(err) {
94
96
  return undefined;
95
97
  }
96
98
  const { code, paths, left, reason, remotes } = (data ?? {});
97
- if (code === 'running' || code === 'stale')
99
+ if (code === 'running' || code === 'stale' || code === 'cancelled')
98
100
  return { code };
99
101
  if (code === 'shelve')
100
102
  return { code, reason: typeof reason === 'string' ? reason : '' };
@@ -117,9 +119,10 @@ export function refusalOf(err) {
117
119
  }
118
120
  /**
119
121
  * Run `ai-factory <args>` in a project; a move can wait up to a minute on gcf's main lock.
120
- * `input` goes to its stdin: a text longer than a command line may be.
122
+ * `input` goes to its stdin: a text longer than a command line may be. `add`: env over the
123
+ * board's (a move's GCF_MOVE_TAG). GCF_BOARD_CLI_TIMEOUT_MS: the tests' timeout.
121
124
  */
122
- export function runCli(entry, cwd, args, timeoutMs = 120_000, input) {
125
+ export function runCli(entry, cwd, args, timeoutMs = Number(process.env.GCF_BOARD_CLI_TIMEOUT_MS) || 120_000, input, add = {}) {
123
126
  // A move from the board is the operator's: a board started inside a Claude Code session or a
124
127
  // run would otherwise pass as the owner of that session's mark (Methodology §4), and its
125
128
  // commits as the session's or the run's moves (`GCF-By`).
@@ -129,7 +132,7 @@ export function runCli(entry, cwd, args, timeoutMs = 120_000, input) {
129
132
  const child = spawn(process.execPath, [start.script, ...args], {
130
133
  windowsHide: true,
131
134
  cwd,
132
- env: { ...env, ...start.env },
135
+ env: { ...env, ...start.env, ...add },
133
136
  shell: false,
134
137
  stdio: ['pipe', 'pipe', 'pipe'],
135
138
  });
@@ -143,7 +146,13 @@ export function runCli(entry, cwd, args, timeoutMs = 120_000, input) {
143
146
  let out = '';
144
147
  let err = '';
145
148
  child.stdout.on('data', (d) => (out += d));
146
- child.stderr.on('data', (d) => (err += d));
149
+ child.stderr.on('data', (d) => {
150
+ err += d;
151
+ // A move waiting behind a main run (core 0.33) ends with the run's commit or its Cancel:
152
+ // a kill mid-commit would skip its rollback (docs/Main-Run-Moves-Plan.md d5, d7).
153
+ if (/^gcf-waiting: /m.test(err))
154
+ clearTimeout(timer);
155
+ });
147
156
  const timer = setTimeout(() => {
148
157
  err += `\nstopped after ${timeoutMs / 1000} s`;
149
158
  // On Windows a kill stops node alone: a build it started (Unity) would go on.
@@ -151,6 +151,49 @@ export const alive = (pid) => {
151
151
  return e.code === 'EPERM';
152
152
  }
153
153
  };
154
+ /**
155
+ * The moves waiting behind a main run in project `dir` (core 0.33): the records of
156
+ * `.gcf-session/waiting/` whose process lives, read as data. `cancel`: the file a Cancel writes,
157
+ * the core's own beside the record; one a record names elsewhere is no file the board writes.
158
+ * `going`: its paths cleared and it goes again (core 0.33): too late for a Cancel.
159
+ */
160
+ export function movesWaiting(dir) {
161
+ const waiting = path.join(dir, '.gcf-session', 'waiting');
162
+ let names;
163
+ try {
164
+ names = readdirSync(waiting);
165
+ }
166
+ catch {
167
+ return [];
168
+ }
169
+ const strings = (v) => Array.isArray(v) ? v.filter((s) => typeof s === 'string') : [];
170
+ return names.flatMap((name) => {
171
+ const pid = Number(/^(\d+)\.json$/.exec(name)?.[1]);
172
+ if (!alive(pid))
173
+ return [];
174
+ let r;
175
+ try {
176
+ r = JSON.parse(readFileSync(path.join(waiting, name), 'utf8'));
177
+ }
178
+ catch {
179
+ return [];
180
+ }
181
+ const named = typeof r.cancel === 'string' ? path.resolve(r.cancel) : '';
182
+ return [
183
+ {
184
+ tag: typeof r.tag === 'string' ? r.tag : null,
185
+ message: typeof r.message === 'string' ? r.message : '',
186
+ items: strings(r.items),
187
+ behind: typeof r.behind === 'string' ? r.behind : '',
188
+ paths: strings(r.paths),
189
+ cancel: path.dirname(named) === path.resolve(waiting)
190
+ ? named
191
+ : path.join(waiting, `${pid}.cancel`),
192
+ going: r.going === true,
193
+ },
194
+ ];
195
+ });
196
+ }
154
197
  /**
155
198
  * What makes items `running` in a runs directory: its entries, whether each lock's process
156
199
  * lives, whether each session mark is fresh; and how recently each run log was written. A run
@@ -213,8 +256,8 @@ export function playState(project) {
213
256
  }
214
257
  /**
215
258
  * Watch a project: `gcf/` (every move writes there), `.ai-factory/plans` (a plan is written and
216
- * edited), `.gcf-session/runs` (a run's lock or session mark comes, goes or goes stale) and its
217
- * builds and player. The session folder may not exist yet, so it is polled, not watched. Bursts
259
+ * edited), `.gcf-session/runs` (a run's lock or session mark comes, goes or goes stale), its
260
+ * builds and player, and its moves waiting behind a main run. The session folder may not exist yet, so it is polled, not watched. Bursts
218
261
  * of writes make one event. Returns the stop.
219
262
  */
220
263
  export function watchProject(p, debounceMs = 300, ttlMin = () => SESSION_TTL_MIN) {
@@ -261,11 +304,20 @@ export function watchProject(p, debounceMs = 300, ttlMin = () => SESSION_TTL_MIN
261
304
  };
262
305
  let read = quotaAt();
263
306
  let playing = playState(p.path);
307
+ // The moves waiting behind a main run (Main-Run-Moves-Plan d7): one that comes or goes.
308
+ const waitState = () => movesWaiting(p.path)
309
+ .map((w) => `${w.tag}:${w.paths.join(',')}`)
310
+ .join(';');
311
+ let waits = waitState();
264
312
  const poll = setInterval(() => {
265
313
  const now = runsState(runs, ttlMin());
266
314
  if (now !== last)
267
315
  fire();
268
316
  last = now;
317
+ const nowWaits = waitState();
318
+ if (nowWaits !== waits)
319
+ fire();
320
+ waits = nowWaits;
269
321
  const nowPlaying = playState(p.path);
270
322
  if (nowPlaying !== playing)
271
323
  fire();
@@ -92,6 +92,17 @@ async function main() {
92
92
  open();
93
93
  setTimeout(() => process.exit(0), 500);
94
94
  });
95
+ // A stop by Ctrl-C, a kill or the console closed (SIGHUP, SIGBREAK on Windows): the close
96
+ // cancels the board's moves waiting behind a main run (Main-Run-Moves-Plan d9), then it ends.
97
+ let stopping = false;
98
+ for (const sig of ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP'])
99
+ process.on(sig, () => {
100
+ if (stopping)
101
+ return;
102
+ stopping = true;
103
+ app.close();
104
+ process.exit(0);
105
+ });
95
106
  app.listen(port, '127.0.0.1', () => {
96
107
  console.log(`gcf-board ${version()}: ${url}`);
97
108
  open();
@@ -56,6 +56,8 @@ const idList = (b, key, flag = key) => list(b, key, SLUG, 'ids', flag);
56
56
  const tagList = (b, key, flag = key) => list(b, key, TAG, 'tags', flag);
57
57
  /** `--remove` / `--no-remove` when the operator chose; the command's default otherwise. */
58
58
  const remove = (b, key = 'remove', flag = key) => b[key] === true ? [`--${flag}`] : b[key] === false ? [`--no-${flag}`] : [];
59
+ // A config key of up to three levels: `agent.plan.effort` (Plan-Review-Rework-Plan d10).
60
+ const CONFIG_KEY = /^[a-z_]+(\.[a-z_]+){0,2}$/;
59
61
  const MOVES = {
60
62
  // A session's mark taken off: the item no longer shows running (Board-PRD §3.2, kind c).
61
63
  release: (b) => ['release', id(b)],
@@ -63,7 +65,7 @@ const MOVES = {
63
65
  // a number back to its default.
64
66
  'config-set': (b) => {
65
67
  const key = b.key;
66
- if (typeof key !== 'string' || !/^[a-z_]+(\.[a-z_]+)?$/.test(key))
68
+ if (typeof key !== 'string' || !CONFIG_KEY.test(key))
67
69
  throw new HttpError(400, 'key must be a config key');
68
70
  // A missing value is a mistake, not a reset: only an empty one takes the default back.
69
71
  const v = b.value;
@@ -79,7 +81,7 @@ const MOVES = {
79
81
  if (typeof pairs !== 'object' || pairs === null || Array.isArray(pairs))
80
82
  throw new HttpError(400, 'pairs must map config keys to values');
81
83
  const args = Object.entries(pairs).map(([key, v]) => {
82
- if (!/^[a-z_]+(\.[a-z_]+)?$/.test(key))
84
+ if (!CONFIG_KEY.test(key))
83
85
  throw new HttpError(400, 'key must be a config key');
84
86
  // A list (`no_diff`) goes as its lines: Settings saves every key at once (t3 d6).
85
87
  if (typeof v !== 'string')
@@ -140,7 +142,9 @@ function fieldArgs(f, b) {
140
142
  return tagList(b, f.key, flag);
141
143
  if (f.kind === 'choice')
142
144
  return choice(f, b, flag);
143
- // Its text goes on stdin (moveInput): the file `-`.
145
+ // Its text goes on stdin (moveInput): the file `-`. With `clear`, an empty text is a text too.
146
+ if (f.stdin && f.clear && typeof b[f.key] === 'string')
147
+ return [`--${flag}-file=-`];
144
148
  if (f.stdin)
145
149
  return (f.required ? required(b, f.key) : text(b, f.key)) ? [`--${flag}-file=-`] : [];
146
150
  if (f.clear && b[f.key] === '')
@@ -1,7 +1,7 @@
1
1
  // The agent's proposals (docs/Session-Engine.md AD-12, AD-36): a tool of the center's MCP server
2
2
  // for each domain move with `propose`, `propose_<key>` (`-` and `:` as `_`). Its input schema is
3
3
  // built from the move's form: no hidden field, no model or effort, the run's own; a move on an
4
- // item, an inbox entry or a question also takes its `id`. The schema says what
4
+ // item, an inbox entry or a question also takes its `id`, one on several (`{ids}`) their `ids`. The schema says what
5
5
  // it can (types, choices, lengths, what is always required); `checkProposal` the rest (a field
6
6
  // that goes only with another's value, the defaults).
7
7
  import { toolOf } from '../shared/board.js';
@@ -9,14 +9,25 @@ export { toolOf };
9
9
  /** The fields of a run an agent does not choose: the operator's run settings. */
10
10
  const NOT_PROPOSED = new Set(['model', 'effort']);
11
11
  const SLUG = '^[a-z0-9]+(-[a-z0-9]+)*$';
12
+ const SLUG_RE = new RegExp(SLUG);
12
13
  const TAG = '^[a-z0-9][a-z0-9:-]{0,39}$';
14
+ /** Whether an agent fills field `f`: not one the form fills unless it says so, nor the run's. */
15
+ const proposable = (f) => (!f.hidden || f.propose === true) && !NOT_PROPOSED.has(f.key);
13
16
  /** The fields an agent may propose: the form's, without the hidden ones and the run's. */
14
- export const proposed = (spec) => spec.fields.filter((f) => !f.hidden && !NOT_PROPOSED.has(f.key));
17
+ export const proposed = (spec) => spec.fields.filter(proposable);
15
18
  /**
16
19
  * Whether a move acts on an item, an inbox entry or a question already there (`{id}` in its
17
20
  * words, no field of its own names it): the agent names it in `id`.
18
21
  */
19
22
  export const targeted = (spec) => spec.args.includes('{id}') && !spec.fields.some((f) => f.key === 'id');
23
+ /** Whether a move acts on several already there (`{ids}`): the agent names them in `ids`. */
24
+ export const targetsMany = (spec) => spec.args.includes('{ids}') && !spec.fields.some((f) => f.key === 'ids');
25
+ const TARGETS = {
26
+ type: 'array',
27
+ items: { type: 'string', pattern: SLUG },
28
+ minItems: 1,
29
+ description: 'The ids it acts on: the inbox entries for an inbox move, else the items.',
30
+ };
20
31
  const TARGET = {
21
32
  type: 'string',
22
33
  pattern: SLUG,
@@ -77,14 +88,17 @@ export function fieldSchema(f) {
77
88
  export function toolSchema(spec) {
78
89
  const fields = proposed(spec);
79
90
  const target = targeted(spec);
91
+ const many = targetsMany(spec);
80
92
  return {
81
93
  type: 'object',
82
94
  properties: {
83
95
  ...(target && { id: TARGET }),
96
+ ...(many && { ids: TARGETS }),
84
97
  ...Object.fromEntries(fields.map((f) => [f.key, fieldSchema(f)])),
85
98
  },
86
99
  required: [
87
100
  ...(target ? ['id'] : []),
101
+ ...(many ? ['ids'] : []),
88
102
  ...fields.filter((f) => f.required && !f.when).map((f) => f.key),
89
103
  ],
90
104
  additionalProperties: false,
@@ -101,15 +115,19 @@ export function checkProposal(spec, args) {
101
115
  const values = Object.fromEntries(spec.fields.filter((f) => f.default !== undefined).map((f) => [f.key, f.default]));
102
116
  const problems = [];
103
117
  const target = targeted(spec);
104
- if (target && (typeof args.id !== 'string' || !new RegExp(SLUG).test(args.id)))
118
+ if (target && (typeof args.id !== 'string' || !SLUG_RE.test(args.id)))
105
119
  problems.push('id is required: the item, inbox entry or question it acts on');
120
+ const many = targetsMany(spec);
121
+ const slugs = (v) => Array.isArray(v) && v.length > 0 && v.every((x) => typeof x === 'string' && SLUG_RE.test(x));
122
+ if (many && !slugs(args.ids))
123
+ problems.push('ids is required: the inbox entries or items it acts on, one or more');
106
124
  for (const [key, v] of Object.entries(args)) {
107
125
  const f = fields.get(key);
108
- if (target && key === 'id')
126
+ if ((target && key === 'id') || (many && key === 'ids'))
109
127
  continue;
110
128
  if (!f)
111
129
  problems.push(`${key} is not a field of this move`);
112
- else if (f.hidden || NOT_PROPOSED.has(key))
130
+ else if (!proposable(f))
113
131
  problems.push(`${key} is the operator's to set, not proposed`);
114
132
  else if (given(v))
115
133
  values[key] = v;