gcf-board 0.26.0 → 0.28.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.
@@ -24,8 +24,8 @@ 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, holdProject, retryWaiting, runsOf, setAutopilot, startRun, unqueue, ticketState, watchTickets, } from './runs.js';
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';
27
+ import { activeRuns, adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, holdProject, retryWaiting, runsOf, setAutopilot, startRun, allowOf, whileAllowing, unqueue, ticketState, watchTickets, } from './runs.js';
28
+ import { acceptProposal, agentDefaults, agentPresets, chatCard, deniedRuleIn, lastDeniedOf, lastRunEnd, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
29
29
  import { accountSettings, saveAccountSettings, threadDir, threadOfEntry } from 'gcf-session';
30
30
  const send = (res, status, body) => {
31
31
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
@@ -80,6 +80,7 @@ const PLAY_START_MS = 30 * 60_000;
80
80
  const WORD_RE = /^[\w][\w-]*$/;
81
81
  // A device id goes into a shell command: the core takes only these characters (d5).
82
82
  const DEVICE_RE = /^\w[\w.:-]*$/;
83
+ const PROFILE_RE = /^(?:debug|release)$/;
83
84
  /** The core's command for a Play route, its body checked: words where words go. */
84
85
  export function playArgs(what, body) {
85
86
  const word = (v, name, re = WORD_RE) => {
@@ -94,6 +95,9 @@ export function playArgs(what, body) {
94
95
  };
95
96
  // A card, or the checkout as it is ("Play main", docs/Play-Setup-Plan.md d30).
96
97
  const who = () => (flag(body.main, 'main') ? ['--main'] : [word(body.id, 'id')]);
98
+ const opt = (v, name, re = WORD_RE) => v === undefined || v === null ? [] : [`--${name}`, word(v, name, re)];
99
+ // Which profile (docs/Handoff-Plan.md t18): debug when none is named.
100
+ const profile = () => opt(body.profile, 'profile', PROFILE_RE);
97
101
  if (what === 'stop')
98
102
  return ['gcf', 'playtest', 'stop', '--json'];
99
103
  if (what === 'devices')
@@ -103,13 +107,15 @@ export function playArgs(what, body) {
103
107
  ...['gcf', 'playtest', 'build', ...who(), '--queue', '--json'],
104
108
  // "Build again" (d23): a snapshot of the same code is replaced, not taken.
105
109
  ...(flag(body.fresh, 'fresh') ? ['--fresh'] : []),
110
+ // Which build (t16): else the card's own, else auto_build.
111
+ ...opt(body.of, 'of'),
112
+ ...profile(),
106
113
  ];
107
114
  return [
108
115
  ...['gcf', 'playtest', 'start', ...who(), '--queue', '--json'],
109
116
  ...['--target', word(body.target, 'target')],
110
- ...(body.device === undefined || body.device === null
111
- ? []
112
- : ['--device', word(body.device, 'device', DEVICE_RE)]),
117
+ ...opt(body.device, 'device', DEVICE_RE),
118
+ ...profile(),
113
119
  ];
114
120
  }
115
121
  function jsonOf(r, what) {
@@ -496,12 +502,12 @@ export function createApp(o) {
496
502
  i.chat_card = chatCard(chat);
497
503
  if (i.running_kind === 'run')
498
504
  i.running_kind = mine.has(i.id) ? 'board' : 'console';
499
- // A block for a refused command: the deny group its run's last refusal named, for
500
- // "Allow <group> and run again" (docs/Autonomy-Plan.md, E). Never git-history.
505
+ // A block for a refused call: the deny rule its run's last refusal named, for "Allow
506
+ // <rule> for one run" (docs/Permission-Stop-Plan.md, d3). Never git-history.
501
507
  if (i.status === 'blocked' && /needs permission/.test(i.blocked ?? '')) {
502
- const group = deniedGroupIn(chat);
503
- if (group)
504
- i.denied_group = group;
508
+ const rule = deniedRuleIn(chat);
509
+ if (rule)
510
+ i.denied_rule = rule;
505
511
  }
506
512
  }
507
513
  send(res, 200, { ...board, ...own });
@@ -1229,12 +1235,29 @@ export function createApp(o) {
1229
1235
  const ids = runIds(body);
1230
1236
  const fresh = body.fresh === true;
1231
1237
  const agent = runAgent(body);
1238
+ if (body.allow !== undefined && !allowOf(body.allow))
1239
+ throw new HttpError(400, 'allow is a list of up to 8 one-line deny rules');
1240
+ const allow = allowOf(body.allow) ?? undefined;
1232
1241
  // One run per mode: a main one queues behind the main run going, a worktree one starts.
1233
1242
  const parts = Map.groupBy(ids, (id) => runModeOf(board, id, body.mode));
1234
1243
  // Each part checks first: a refused one starts no other.
1235
1244
  for (const part of parts.values())
1236
1245
  busyCheck(p, part);
1237
- const started = [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, fresh, harness, agent));
1246
+ const start = () => [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, { fresh, harness, agent, allow }));
1247
+ // "Allow for one run" (Permission-Stop-Plan d3): the unblock and the start as one step,
1248
+ // the autopilot held off between them, so no run takes the card without its allowance.
1249
+ const started = body.unblock === true && allow
1250
+ ? await whileAllowing(p.name, async () => {
1251
+ for (const id of ids) {
1252
+ const args = moveArgs({ cmd: 'unblock', id }, board.domain.moves);
1253
+ const r = await cli(p, args);
1254
+ if (!r.ok)
1255
+ throw new HttpError(409, `unblock ${id}: ${briefError(r.err)}`);
1256
+ }
1257
+ broadcast({ type: 'board', project: p.name });
1258
+ return start();
1259
+ })
1260
+ : start();
1238
1261
  send(res, 202, {
1239
1262
  started: started.flatMap((s) => s.started ?? []),
1240
1263
  queued: started.flatMap((s) => s.queued ?? []),
@@ -122,6 +122,19 @@ const paused = new Set();
122
122
  // The projects the operator holds (Hold-Plan d20): no queued or autopilot run starts; the
123
123
  // operator's own Run goes at once. Apart from `paused`: Release resumes the queue, nothing else.
124
124
  const projectHolds = new Set();
125
+ // Projects where the operator's "Allow for one run" unblocks a card (Permission-Stop-Plan d3):
126
+ // no autopilot run starts in the gap, or it would take the card without the allowance.
127
+ const allowing = new Set();
128
+ /** Hold off the autopilot while `fn` unblocks and starts a card with its allowance. */
129
+ export async function whileAllowing(project, fn) {
130
+ allowing.add(project);
131
+ try {
132
+ return await fn();
133
+ }
134
+ finally {
135
+ allowing.delete(project);
136
+ }
137
+ }
125
138
  // The paused projects whose pause the usage limit set: a run that ended paused by it (AD-19).
126
139
  const limitPaused = new Set();
127
140
  // When the usage limit that paused a project's queue resets, ISO; none when it was not one.
@@ -252,6 +265,16 @@ const WORD = /^[A-Za-z0-9][\w.-]*$/;
252
265
  const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
253
266
  const list = (v) => (Array.isArray(v) ? v : []);
254
267
  const pick = (v) => (typeof v === 'string' && WORD.test(v) ? v : null);
268
+ /**
269
+ * The deny rules a run goes without, or null: a short list of one-line rules. Whether each is a
270
+ * rule in force is the harness's check; here only what reaches its command line is bounded.
271
+ */
272
+ export function allowOf(v) {
273
+ if (!Array.isArray(v) || !v.length || v.length > 8)
274
+ return null;
275
+ const ok = v.every((r) => typeof r === 'string' && r.trim() && r.length <= 200 && !/[\r\n]/.test(r));
276
+ return ok ? v : null;
277
+ }
255
278
  /**
256
279
  * A queued request as `queue.json` holds it, or null: its ids go to the harness's command line,
257
280
  * so each must be an item id; its mode one of the two; its pick plain words.
@@ -274,6 +297,7 @@ function queuedOf(v) {
274
297
  mode: v.mode,
275
298
  harness: v.harness,
276
299
  ...(v.fresh === true ? { fresh: true } : {}),
300
+ ...(allowOf(v.allow) ? { allow: allowOf(v.allow) } : {}),
277
301
  ...(v.waitLimit === true ? { waitLimit: true } : {}),
278
302
  ...(typeof v.waited === 'string' ? { waited: v.waited } : {}),
279
303
  ...(agent ? { agent } : {}),
@@ -610,6 +634,8 @@ function spawnRun(q, mode) {
610
634
  if (q.kind !== 'card') {
611
635
  if (q.fresh)
612
636
  args.push('--fresh');
637
+ for (const rule of q.allow ?? [])
638
+ args.push('--allow', rule);
613
639
  // This run's pick: the items keep their own (Board-V2-Data-Plan §2.5).
614
640
  if (model)
615
641
  args.push('--model', model);
@@ -933,8 +959,9 @@ export function busyCheck(p, ids) {
933
959
  * `fresh` starts new agent sessions where the harness would resume the interrupted ones.
934
960
  * `harness` is the domain's (`domain.harness`); the tests take GCF's. Its sessions are open to
935
961
  * the operator's chat. `agent`: a model and effort for this run only, over each item's own.
962
+ * `allow`: deny rules in force this run goes without (docs/Permission-Stop-Plan.md, d2).
936
963
  */
937
- export function startRun(entry, p, ids, mode = 'worktree', fresh = false, harness = 'gcf-harness', agent) {
964
+ export function startRun(entry, p, ids, mode = 'worktree', { fresh = false, harness = 'gcf-harness', agent, allow, } = {}) {
938
965
  // A second click on the same card: the harness would refuse it on its lock, noisily.
939
966
  paths.set(p.name, p.path);
940
967
  busyCheck(p, ids);
@@ -944,12 +971,13 @@ export function startRun(entry, p, ids, mode = 'worktree', fresh = false, harnes
944
971
  if (mode === 'main' && (held || going.some((r) => r.mode === 'main'))) {
945
972
  queues.set(p.name, [
946
973
  ...(queues.get(p.name) ?? []),
947
- { entry, p, ids, mode, fresh, harness, agent },
974
+ { entry, p, ids, mode, fresh, harness, agent, ...(allow?.length ? { allow } : {}) },
948
975
  ]);
949
976
  changed(p.name);
950
977
  return { queued: ids };
951
978
  }
952
- return { started: spawnRun({ entry, p, ids, mode, fresh, harness, agent }, mode) };
979
+ const q = { entry, p, ids, mode, fresh, harness, agent, ...(allow?.length ? { allow } : {}) };
980
+ return { started: spawnRun(q, mode) };
953
981
  }
954
982
  const pilots = new Map();
955
983
  // The projects whose autopilot is asking the harness now: one ask at a time.
@@ -1097,8 +1125,10 @@ export const reserveText = (r) => r?.weekly
1097
1125
  ? "the quota is at its reserve: the automation stands until the week's reset"
1098
1126
  : `the quota is at its reserve: the automation waits for the reset${r?.until ? ` at ${r.until}` : ''}`;
1099
1127
  /** Whether the project is idle for the autopilot: no run, no queue to go, no pause. */
1100
- const idle = (project) => !paused.has(project) &&
1128
+ /** Whether nothing goes or waits in the project: the autopilot starts only then. */
1129
+ export const idle = (project) => !paused.has(project) &&
1101
1130
  !projectHolds.has(project) &&
1131
+ !allowing.has(project) &&
1102
1132
  !clickBuilding(project) &&
1103
1133
  !activeRuns(project).length &&
1104
1134
  !queues.get(project)?.some((q) => !q.waiting);
@@ -213,22 +213,30 @@ function playLines(board, item) {
213
213
  'a tech card with propose_item_new that adds them and names them in AGENTS.md.',
214
214
  '',
215
215
  ];
216
- const b = item.build;
217
- const targets = board.play.targets.map((t) => `${t.name} (${t.open})`).join(', ') || 'none';
218
- const shared = b?.shared_with?.length ? ` The same build as ${b.shared_with.join(', ')}.` : '';
219
- const said = b?.building
216
+ // Its builds by build and profile (schema 5): what is ready, what is made now.
217
+ const builds = item.builds ?? [];
218
+ const targets = board.play.targets
219
+ .map((t) => `${t.name} (${t.open}${t.build ? `, plays ${t.build}` : ''})`)
220
+ .join(', ') || 'none';
221
+ const ready = builds.filter((b) => b.ok);
222
+ const shared = ready.find((b) => b.shared_with?.length)?.shared_with ?? [];
223
+ const sharedText = shared.length ? ` The same build as ${shared.join(', ')}.` : '';
224
+ const said = builds.some((b) => b.building)
220
225
  ? 'its build is being made now.'
221
- : b?.ok
222
- ? `its build is ready: commit ${b.commit?.slice(0, 7) ?? 'unknown'}, built ${b.built_at}, ` +
223
- `${b.source === 'click' ? 'by hand, so it may hold later cards' : 'by its run'}.${shared}`
226
+ : ready.length
227
+ ? `its builds are ready: ${ready
228
+ .map((b) => `${b.build} ${b.profile} at commit ${b.commit?.slice(0, 7) ?? 'unknown'}, built ` +
229
+ `${b.built_at}, ${b.source === 'click' ? 'by hand, so it may hold later cards' : 'by its run'}`)
230
+ .join('; ')}.${sharedText}`
224
231
  : 'it has no build yet: its Play button builds it first.';
232
+ const problem = builds.find((b) => b.problem)?.problem;
225
233
  const running = board.play.running?.id === item.id
226
234
  ? [`It plays now on ${board.play.running.target}: ${board.play.running.open}.`]
227
235
  : [];
228
236
  return [
229
237
  '',
230
238
  `To play it: ${said}`,
231
- ...(b?.problem ? [`The last build failed: ${b.problem.split('\n')[0]}`] : []),
239
+ ...(problem ? [`The last build failed: ${problem.split('\n')[0]}`] : []),
232
240
  ...running,
233
241
  `Targets: ${targets}.`,
234
242
  'Never answer that you cannot build it: the card has its Play button, which builds first;',
@@ -485,7 +493,7 @@ function eventsOf(td) {
485
493
  return chatEvents(path.join(td, 'chat.jsonl'));
486
494
  }
487
495
  const runs = new Map();
488
- const NONE = { stamp: '', card: null, end: null, denied: null, group: null };
496
+ const NONE = { stamp: '', card: null, end: null, denied: null, rule: null };
489
497
  /** A run's chat file's facts, read again only when the file changed. */
490
498
  function runChat(file) {
491
499
  let stamp = '';
@@ -509,7 +517,7 @@ function runChat(file) {
509
517
  card: cardIn(events),
510
518
  end,
511
519
  denied: lastDenied(events),
512
- group: deniedGroupOf(events),
520
+ rule: deniedRuleOf(events),
513
521
  };
514
522
  runs.set(file, facts);
515
523
  return facts;
@@ -518,8 +526,8 @@ function runChat(file) {
518
526
  export const chatCard = (file) => runChat(file).card;
519
527
  /** How the last run in a run's chat file ended (`run_end`), or null. */
520
528
  export const lastRunEnd = (file) => runChat(file).end;
521
- /** The deny group the last refusal of a run's chat file named (deniedGroupOf), or null. */
522
- export const deniedGroupIn = (file) => runChat(file).group;
529
+ /** The deny rule the last refusal of a run's chat file named (deniedRuleOf), or null. */
530
+ export const deniedRuleIn = (file) => runChat(file).rule;
523
531
  /** The last call a deny rule refused in a run's chat file, or null. */
524
532
  export const lastDeniedOf = (file) => runChat(file).denied;
525
533
  /**
@@ -539,18 +547,23 @@ export function lastDenied(events) {
539
547
  }
540
548
  /** The events of a chat file: a thread's, or a run's `<id>.chat.jsonl`; none without one. */
541
549
  /**
542
- * The deny group the last session of a run's chat was refused by, for "Allow <group> and run
543
- * again" (docs/Autonomy-Plan.md, E): its last refusal's, none from an older run. Never a group
544
- * that guards history or the operator's own moves, nor an old alias.
550
+ * The deny rule the last session of a run's chat was refused by, for "Allow <rule> for one run"
551
+ * (docs/Permission-Stop-Plan.md, d3): its last refusal's, none from an older run, none when two
552
+ * rules held (the event names no rule then). Never a rule of a group that guards history or the
553
+ * operator's own moves.
545
554
  */
546
- export function deniedGroupOf(events) {
555
+ export function deniedRuleOf(events) {
547
556
  const start = events.findLastIndex((e) => e.type === 'session' && e.kind === 'start');
548
- const denied = events.slice(Math.max(0, start)).filter((e) => e.type === 'denied');
549
- const group = denied.at(-1)?.group ?? null;
557
+ const last = events
558
+ .slice(Math.max(0, start))
559
+ .findLast((e) => e.type === 'denied' && e.by === 'rule');
560
+ const { rule, group } = (last ?? {});
561
+ if (!rule)
562
+ return null;
550
563
  // `run-play`: a run builds by the harness, never by its agent (Play-Setup-Plan d32).
551
- return group && !['git-history', 'git-destroy', 'human-moves', 'run-play'].includes(group)
552
- ? group
553
- : null;
564
+ if (group && ['git-history', 'git-destroy', 'human-moves', 'run-play'].includes(group))
565
+ return null;
566
+ return group ? { rule, group } : { rule };
554
567
  }
555
568
  export function chatEvents(file) {
556
569
  let text = '';
@@ -1,6 +1,6 @@
1
1
  // The read model of `ai-factory gcf board --json` (Methodology §11): the board refuses a schema
2
2
  // it does not know. Types only, plus the version this board reads.
3
- export const BOARD_SCHEMA = 4;
3
+ export const BOARD_SCHEMA = 5;
4
4
  // Where a project keeps files given to an item or an inbox entry (Board-PRD §5.3, §5.6): only
5
5
  // there may the board hand out a file that is not text. One list: a later kind is one line.
6
6
  const ATTACHED = [