gcf-board 0.16.9 → 0.17.1

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.
@@ -22,8 +22,8 @@ import { isCenterMove, moveArgs, moveInput, runIds } from './moves.js';
22
22
  import { isUpload, saveUpload, UPLOAD_MAX } from './upload.js';
23
23
  import { addProject, listProjects, projectOf, removeProject } from './registry.js';
24
24
  import { allThemes } from './themes.js';
25
- import { adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, runsOf, startRun, unqueue, } from './runs.js';
26
- import { acceptProposal, agentDefaults, agentPresets, chatCard, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
25
+ import { adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, runsOf, setAutopilot, startRun, unqueue, } from './runs.js';
26
+ import { acceptProposal, agentDefaults, agentPresets, chatCard, chatEvents, deniedGroupOf, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
27
27
  import { threadDir, threadOfEntry } from 'gcf-session';
28
28
  const send = (res, status, body) => {
29
29
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
@@ -345,6 +345,14 @@ export function createApp(o) {
345
345
  }
346
346
  if (i.running_kind === 'run')
347
347
  i.running_kind = mine.has(i.id) ? 'board' : 'console';
348
+ // A block for a refused command: the deny group its run's last refusal named, for
349
+ // "Allow <group> and run again" (docs/Autonomy-Plan.md, E). Never git-history.
350
+ if (i.status === 'blocked' && /needs permission/.test(i.blocked ?? '')) {
351
+ const chat = path.join(p.path, '.gcf-session', 'runs', `${i.id}.chat.jsonl`);
352
+ const group = deniedGroupOf(chatEvents(chat));
353
+ if (group)
354
+ i.denied_group = group;
355
+ }
348
356
  }
349
357
  send(res, 200, { ...board, ...own });
350
358
  },
@@ -893,6 +901,18 @@ export function createApp(o) {
893
901
  send(res, 200, { ok: true });
894
902
  },
895
903
  ],
904
+ [
905
+ // The operator turns the project's autopilot on or off (docs/Autonomy-Plan.md, D).
906
+ 'POST',
907
+ /^\/api\/p\/([^/]+)\/autopilot$/,
908
+ async (req, res, m) => {
909
+ const p = await projectOf(m[1]);
910
+ const { on } = await bodyOf(req);
911
+ if (typeof on !== 'boolean')
912
+ throw new HttpError(400, 'on is true or false');
913
+ send(res, 200, setAutopilot(o.entry, p, await harnessOf(p), on));
914
+ },
915
+ ],
896
916
  [
897
917
  'DELETE',
898
918
  /^\/api\/p\/([^/]+)\/reports\/(r\d+)$/,
@@ -64,6 +64,31 @@ const MOVES = {
64
64
  throw new HttpError(400, 'value must be text');
65
65
  return ['config', 'set', key, `--value=${v}`];
66
66
  },
67
+ // Several keys of gcf/config.yml in one commit: a preset (docs/Autonomy-Plan.md, E).
68
+ 'config-preset': (b) => {
69
+ const pairs = b.pairs;
70
+ if (typeof pairs !== 'object' || pairs === null || Array.isArray(pairs))
71
+ throw new HttpError(400, 'pairs must map config keys to values');
72
+ const args = Object.entries(pairs).map(([key, v]) => {
73
+ if (!/^[a-z_]+(\.[a-z_]+)?$/.test(key))
74
+ throw new HttpError(400, 'key must be a config key');
75
+ if (typeof v !== 'string' || /[\r\n]/.test(v))
76
+ throw new HttpError(400, 'a value is one line of text');
77
+ return `--pair=${key}=${v}`;
78
+ });
79
+ if (!args.length)
80
+ throw new HttpError(400, 'config-preset: name a key');
81
+ return ['config', 'set', ...args];
82
+ },
83
+ // The keep of a whole milestone (core 0.19): every item of it that waits for play, one commit;
84
+ // where the operator played it, a note for the history.
85
+ 'milestone-keep': (b) => [
86
+ 'verdict',
87
+ id(b),
88
+ 'keep',
89
+ '--milestone',
90
+ ...many(b, 'played_on', 'played-on'),
91
+ ],
67
92
  // A deny group on or off, a custom rule added or removed; the core checks the names.
68
93
  permissions: (b) => {
69
94
  const args = ['on', 'off', 'deny', 'undeny'].flatMap((k) => many(b, k));
@@ -6,13 +6,13 @@
6
6
  // In `run_mode: main` the checkout takes one run at a time: a run asked for meanwhile waits in
7
7
  // the project's queue and starts when the one before it ends. The queue, its pause, the reports
8
8
  // and the trace live in `<board home>/queue.json` too: a board started again goes on with them.
9
- import { spawn } from 'node:child_process';
10
- import { randomUUID } from 'node:crypto';
9
+ import { spawn, spawnSync } from 'node:child_process';
10
+ import { createHash, randomUUID } from 'node:crypto';
11
11
  import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
12
12
  import path from 'node:path';
13
13
  import { fileURLToPath } from 'node:url';
14
14
  import { writeAtomicSync } from './atomic.js';
15
- import { briefError } from './cli.js';
15
+ import { briefError, runCli } from './cli.js';
16
16
  import { alive, broadcast } from './events.js';
17
17
  import { HttpError } from './http-error.js';
18
18
  import { homeDir } from './registry.js';
@@ -62,7 +62,13 @@ let loaded = null;
62
62
  */
63
63
  function save() {
64
64
  loaded ??= readSaved();
65
- const names = new Set([...queues.keys(), ...paused, ...reports.keys(), ...acts.keys()]);
65
+ const names = new Set([
66
+ ...queues.keys(),
67
+ ...paused,
68
+ ...reports.keys(),
69
+ ...acts.keys(),
70
+ ...pilots.keys(),
71
+ ]);
66
72
  const projects = loaded !== 'bad' ? { ...loaded } : {};
67
73
  for (const name of names) {
68
74
  const where = paths.get(name);
@@ -75,6 +81,7 @@ function save() {
75
81
  paused_until: pausedUntil.get(name) ?? null,
76
82
  reports: reports.get(name) ?? [],
77
83
  acts: acts.get(name) ?? [],
84
+ ...(pilots.has(name) ? { autopilot: savedPilot(pilots.get(name)) } : {}),
78
85
  };
79
86
  }
80
87
  try {
@@ -210,6 +217,7 @@ function restore(entry, p) {
210
217
  const did = list(s.acts).filter((a) => isObject(a) && typeof a.act === 'string' && typeof a.text === 'string');
211
218
  if (did.length)
212
219
  acts.set(p.name, did);
220
+ restorePilot(entry, p, s.autopilot);
213
221
  // Report ids go on after the kept ones, as after a file before `seq`.
214
222
  for (const r of kept)
215
223
  reportSeq = Math.max(reportSeq, Number(r.id.slice(1)) || 0);
@@ -238,6 +246,7 @@ export function runsOf(project) {
238
246
  paused_until: paused.has(project) ? (pausedUntil.get(project) ?? null) : null,
239
247
  reports: reports.get(project) ?? [],
240
248
  acts: acts.get(project) ?? [],
249
+ autopilot: autopilotOf(project),
241
250
  };
242
251
  }
243
252
  /** A project left the board: nothing of it may run any more. */
@@ -251,6 +260,7 @@ export function forgetProject(project) {
251
260
  reports.delete(project);
252
261
  acts.delete(project);
253
262
  paths.delete(project);
263
+ pilots.delete(project);
254
264
  save();
255
265
  }
256
266
  /**
@@ -358,22 +368,28 @@ function spawnRun(q, mode) {
358
368
  const effort = q.agent?.effort ?? null;
359
369
  const run = { project: p.name, ids, started: new Date().toISOString(), mode, model, effort };
360
370
  active.add(run);
361
- // The board says where it goes: it queued it by that mode (an item's own, the run's pick).
362
- const args = [entry, harness, 'run', ...ids, '--json', '--mode', mode];
363
- if (q.fresh)
364
- args.push('--fresh');
365
- // This run's pick: the items keep their own (Board-V2-Data-Plan §2.5).
366
- if (model)
367
- args.push('--model', model);
368
- if (effort)
369
- args.push('--effort', effort);
370
- if (q.waitLimit)
371
- args.push('--wait-limit');
372
- // A board's run is always open to the operator: its chat waits the project's answer time
373
- // (`chat.answer_timeout_min`), which the harness reads. GCF_BOARD_CHAT_TIMEOUT: the tests'.
374
- args.push('--chat');
375
- if (process.env.GCF_BOARD_CHAT_TIMEOUT)
376
- args.push('--chat-timeout', process.env.GCF_BOARD_CHAT_TIMEOUT);
371
+ // The board says where it goes: it queued it by that mode (an item's own, the run's pick). A
372
+ // card session works the main checkout too, with no item yet.
373
+ const args = q.kind === 'card'
374
+ ? [entry, harness, 'card', ...ids, '--json']
375
+ : [entry, harness, 'run', ...ids, '--json', '--mode', mode];
376
+ // A card session takes none of a run's flags: `gcf-harness card` knows only --agent, --json.
377
+ if (q.kind !== 'card') {
378
+ if (q.fresh)
379
+ args.push('--fresh');
380
+ // This run's pick: the items keep their own (Board-V2-Data-Plan §2.5).
381
+ if (model)
382
+ args.push('--model', model);
383
+ if (effort)
384
+ args.push('--effort', effort);
385
+ if (q.waitLimit)
386
+ args.push('--wait-limit');
387
+ // A board's run is always open to the operator: its chat waits the project's answer time
388
+ // (`chat.answer_timeout_min`), which the harness reads. GCF_BOARD_CHAT_TIMEOUT: the tests'.
389
+ args.push('--chat');
390
+ if (process.env.GCF_BOARD_CHAT_TIMEOUT)
391
+ args.push('--chat-timeout', process.env.GCF_BOARD_CHAT_TIMEOUT);
392
+ }
377
393
  const rid = randomUUID();
378
394
  const relay = spawn(process.execPath, [RELAY, recordOf(rid), endOf(rid), ...args], {
379
395
  cwd: p.path,
@@ -393,6 +409,8 @@ function spawnRun(q, mode) {
393
409
  pid: relay.pid ?? 0,
394
410
  model,
395
411
  effort,
412
+ ...(q.kind ? { kind: q.kind } : {}),
413
+ ...(q.pilot ? { pilot: true } : {}),
396
414
  };
397
415
  try {
398
416
  if (relay.pid) {
@@ -506,7 +524,12 @@ function land(q, run, rid, live, message = '') {
506
524
  // The checkout is free now, for whatever queue the name has: a project added back meanwhile.
507
525
  if (mode === 'main')
508
526
  advance(p.name);
527
+ if (kept && q.pilot)
528
+ piloted(p.name, ok, result);
509
529
  changed(p.name);
530
+ // Every end may let the autopilot go on: its own, and one the operator started.
531
+ if (kept)
532
+ setImmediate(() => void pilot(p.name));
510
533
  }
511
534
  /**
512
535
  * Whether the relay of a run found on adoption still goes: its pid lives and it touched its
@@ -592,7 +615,11 @@ export function adoptRuns(entry, p) {
592
615
  continue;
593
616
  const agent = { model: f.model ?? null, effort: f.effort ?? null };
594
617
  const run = { project: p.name, ids: f.ids, started: f.started, mode: f.mode, ...agent };
595
- const q = { entry, p, ids: f.ids, mode: f.mode, harness: f.harness, agent };
618
+ const q = {
619
+ ...{ entry, p, ids: f.ids, mode: f.mode, harness: f.harness, agent },
620
+ ...(f.kind === 'card' ? { kind: 'card' } : {}),
621
+ ...(f.pilot ? { pilot: true } : {}),
622
+ };
596
623
  active.add(run);
597
624
  flights.set(rid, run);
598
625
  // shortcut: off Windows a dead relay leaves its harness going (no job object), reported
@@ -622,6 +649,7 @@ export function adoptRuns(entry, p) {
622
649
  advance(p.name);
623
650
  }
624
651
  changed(p.name);
652
+ void pilot(p.name);
625
653
  }
626
654
  /** A 409 for the ids a run of this board drives or queues: a second click on the same card. */
627
655
  export function busyCheck(p, ids) {
@@ -653,3 +681,224 @@ export function startRun(entry, p, ids, mode = 'worktree', fresh = false, harnes
653
681
  }
654
682
  return { started: spawnRun({ entry, p, ids, mode, fresh, harness, agent }, mode) };
655
683
  }
684
+ const pilots = new Map();
685
+ // The projects whose autopilot is asking the harness now: one ask at a time.
686
+ const piloting = new Set();
687
+ // The batch size the autopilot asks for.
688
+ const PILOT_BATCH = 3;
689
+ const STOPS = ['play', 'empty', 'idle', 'dirty', 'no-move', 'error'];
690
+ const savedPilot = ({ on, stop, guard, harness }) => ({
691
+ on,
692
+ stop,
693
+ guard,
694
+ harness,
695
+ });
696
+ /** The autopilot `queue.json` kept for project `p`, when it reads as one. */
697
+ function restorePilot(entry, p, v) {
698
+ if (!isObject(v) || typeof v.harness !== 'string' || !SLUG.test(v.harness))
699
+ return;
700
+ const guard = Object.fromEntries(Object.entries(isObject(v.guard) ? v.guard : {}).filter((e) => SLUG.test(e[0]) && typeof e[1] === 'string'));
701
+ const s = v.stop;
702
+ const stop = isObject(s) && STOPS.includes(String(s.kind)) && typeof s.text === 'string'
703
+ ? s
704
+ : null;
705
+ pilots.set(p.name, { on: v.on === true, stop, guard, entry, p, harness: v.harness });
706
+ }
707
+ /**
708
+ * A unit's section of gcf/design/ (`## <id>` to the next `## `) as it is now; '' when no design
709
+ * file holds it.
710
+ */
711
+ function unitText(dir, id) {
712
+ const design = path.join(dir, 'gcf', 'design');
713
+ let files = [];
714
+ try {
715
+ files = readdirSync(design).filter((f) => f.endsWith('.md'));
716
+ }
717
+ catch {
718
+ return '';
719
+ }
720
+ for (const f of files) {
721
+ const lines = readFileSync(path.join(design, f), 'utf8').split(/\r?\n/);
722
+ const at = lines.findIndex((l) => l.trim() === `## ${id}`);
723
+ if (at < 0)
724
+ continue;
725
+ const end = lines.findIndex((l, i) => i > at && l.startsWith('## '));
726
+ return lines.slice(at, end < 0 ? lines.length : end).join('\n');
727
+ }
728
+ return '';
729
+ }
730
+ /** An item's file as it is, or else its unit's section of the design: what a guard compares. */
731
+ function guardHash(dir, id) {
732
+ const sha = (t) => createHash('sha1').update(t).digest('hex');
733
+ try {
734
+ return sha(readFileSync(path.join(dir, 'gcf', 'work', `${id}.md`)));
735
+ }
736
+ catch {
737
+ return `unit:${sha(unitText(dir, id))}`;
738
+ }
739
+ }
740
+ /** The ids the guard still holds: their file is as their last run left it. */
741
+ function guardedOf(s) {
742
+ for (const [id, hash] of Object.entries(s.guard))
743
+ if (guardHash(s.p.path, id) !== hash)
744
+ delete s.guard[id];
745
+ return Object.keys(s.guard);
746
+ }
747
+ export function autopilotOf(project) {
748
+ const s = pilots.get(project);
749
+ return { on: s?.on ?? false, stop: s?.stop ?? null, guarded: s ? Object.keys(s.guard) : [] };
750
+ }
751
+ /** Why it stands now; said once in the trace. */
752
+ function stand(project, stop) {
753
+ const s = pilots.get(project);
754
+ if (!s || JSON.stringify(s.stop) === JSON.stringify(stop))
755
+ return;
756
+ s.stop = stop;
757
+ if (stop)
758
+ trace(project, `autopilot-${stop.kind}`, stop.text);
759
+ changed(project);
760
+ }
761
+ /** The operator turns the autopilot on or off. */
762
+ export function setAutopilot(entry, p, harness, on) {
763
+ paths.set(p.name, p.path);
764
+ // The one object an ask in flight holds too: off now reads off after its awaits.
765
+ const s = pilots.get(p.name);
766
+ if (s)
767
+ Object.assign(s, { on, stop: null, entry, p, harness });
768
+ else
769
+ pilots.set(p.name, { on, stop: null, guard: {}, entry, p, harness });
770
+ const said = on ? 'on' : 'off';
771
+ trace(p.name, `autopilot-${said}`, `the operator turned the autopilot ${said}`);
772
+ changed(p.name);
773
+ if (on)
774
+ void pilot(p.name);
775
+ return autopilotOf(p.name);
776
+ }
777
+ // A run's result that is a move: what its item or unit now is. None: an orphan, merged.
778
+ const MOVED = /^(submit|close|block|decide|deferred|card|drop|question|merged)$/;
779
+ /**
780
+ * An autopilot run ended: each item or unit with no move goes into the guard, unless a usage
781
+ * limit or a timeout cut it (a rerun is meant there). A batch with no move at all turns it off.
782
+ */
783
+ function piloted(project, ok, result) {
784
+ const s = pilots.get(project);
785
+ if (!s)
786
+ return;
787
+ const items = result?.items ?? [];
788
+ const off = (kind, text) => {
789
+ s.on = false;
790
+ stand(project, { kind, text: `${text}: the autopilot is off — see its report` });
791
+ };
792
+ // No report, a refused gate: the next ask would start the same again.
793
+ if (!items.length)
794
+ return off('error', `its run ended with no result${result?.gate ? ` (${result.gate})` : ''}`);
795
+ // A stop is the operator's word: the autopilot takes it, it does not start the item again.
796
+ const stopped = items.filter((i) => /stopped/.test(`${i.result ?? ''} ${i.error ?? ''}`));
797
+ // A timeout or a usage limit cut a session a rerun is meant to go on with.
798
+ const cut = (i) => i.limit_resets !== undefined || /timed out/.test(`${i.result ?? ''} ${i.error ?? ''}`);
799
+ const none = items.filter((i) => !MOVED.test(i.result ?? 'merged') && !cut(i));
800
+ for (const i of none)
801
+ s.guard[i.id] = guardHash(s.p.path, i.id);
802
+ if (stopped.length)
803
+ return off('no-move', `you stopped ${stopped.map((i) => i.id).join(', ')}`);
804
+ const failed = items.filter((i) => ['error', 'conflict'].includes(i.result ?? ''));
805
+ if (!ok || failed.length)
806
+ return off('error', `a run failed${failed.length ? `: ${failed.map((i) => i.id).join(', ')}` : ''}`);
807
+ if (none.length === items.length)
808
+ off('no-move', `a run of ${items.map((i) => i.id).join(', ')} made no move`);
809
+ }
810
+ /** Whether the project is idle for the autopilot: no run, no queue, no pause. */
811
+ const idle = (project) => !paused.has(project) && !activeRuns(project).length && !queues.get(project)?.length;
812
+ /** Main's loose work outside gcf/ a main batch would carry; none when the gate cannot say. */
813
+ async function looseOf(s, ids) {
814
+ const g = await runCli(s.entry, s.p.path, [s.harness, 'gate', '--each', ...ids, '--json']);
815
+ let read = null;
816
+ try {
817
+ read = JSON.parse(g.out);
818
+ }
819
+ catch {
820
+ // No answer: below.
821
+ }
822
+ // A gate that cannot say is no clean main: a main run would land among loose work unwarned.
823
+ if (!g.ok || !read)
824
+ throw new Error(`gate --each: ${briefError(g.err || g.out)}`);
825
+ return read.dirty ?? [];
826
+ }
827
+ /** Ask the harness what goes now, and start it; or stand, with why. */
828
+ async function pilot(project) {
829
+ const s = pilots.get(project);
830
+ if (!s?.on || piloting.has(project) || adopting.has(project) || !idle(project))
831
+ return;
832
+ piloting.add(project);
833
+ try {
834
+ const skip = guardedOf(s);
835
+ const args = [s.harness, 'next', String(PILOT_BATCH), '--plan'];
836
+ if (skip.length)
837
+ args.push('--skip', skip.join(','));
838
+ const r = await runCli(s.entry, s.p.path, args);
839
+ let plan;
840
+ try {
841
+ plan = JSON.parse(r.out);
842
+ }
843
+ catch {
844
+ stand(project, { kind: 'error', text: `${s.harness} next: ${briefError(r.err || r.out)}` });
845
+ return;
846
+ }
847
+ // Something else started meanwhile: its end asks again.
848
+ if (!s.on || !idle(project))
849
+ return;
850
+ if (plan.stop)
851
+ return stand(project, plan.stop);
852
+ const { entry, p, harness } = s;
853
+ if (plan.units.length) {
854
+ stand(project, null);
855
+ trace(project, 'autopilot-card', `the autopilot cards ${plan.units.join(', ')}`);
856
+ const q = { entry, p, ids: plan.units, mode: 'main', harness };
857
+ spawnRun({ ...q, kind: 'card', pilot: true }, 'main');
858
+ changed(project);
859
+ return;
860
+ }
861
+ if (!plan.ids.length) {
862
+ stand(project, {
863
+ kind: 'idle',
864
+ text: 'nothing to take now: what is left waits for you, for a decision, or is blocked',
865
+ });
866
+ return;
867
+ }
868
+ const mode = plan.mode ?? 'worktree';
869
+ let loose = [];
870
+ try {
871
+ loose = mode === 'main' ? await looseOf(s, plan.ids) : [];
872
+ }
873
+ catch (e) {
874
+ s.on = false;
875
+ stand(project, { kind: 'error', text: `${e.message}: the autopilot is off` });
876
+ return;
877
+ }
878
+ if (loose.length) {
879
+ stand(project, {
880
+ kind: 'dirty',
881
+ text: `uncommitted work outside gcf/ (${loose.slice(0, 3).join(', ')}): commit it or set ` +
882
+ 'it aside; the autopilot goes on then',
883
+ });
884
+ return;
885
+ }
886
+ if (!s.on || !idle(project))
887
+ return;
888
+ stand(project, null);
889
+ trace(project, 'autopilot-run', `the autopilot runs ${plan.ids.join(', ')}`);
890
+ spawnRun({ entry, p, ids: plan.ids, mode, harness, pilot: true, waitLimit: true }, mode);
891
+ changed(project);
892
+ }
893
+ finally {
894
+ piloting.delete(project);
895
+ }
896
+ }
897
+ // A standing autopilot looks again now and then: the operator's play and keep, an answer, a
898
+ // fix outside the board move nothing it hears of.
899
+ const PILOT_LOOK_MS = Number(process.env.GCF_BOARD_PILOT_LOOK_MS ?? 30_000);
900
+ setInterval(() => {
901
+ for (const [project, s] of pilots)
902
+ if (s.on)
903
+ void pilot(project);
904
+ }, PILOT_LOOK_MS).unref();
@@ -271,14 +271,14 @@ export function talkLive(p, t) {
271
271
  }
272
272
  }
273
273
  /**
274
- * What a thread's engine runs with: a thread's agent is a session of the operator's, whoever
275
- * started the board. A board started from a run or a session passes neither that one's owner
276
- * nor its maker on (`GCF-By`): the thread's moves are `session`.
274
+ * What a thread's engine runs with, whoever started the board. A board started from a run or a
275
+ * session passes neither that one's owner nor its maker on (`GCF-By`): the thread's moves are
276
+ * `thread`, and the core refuses the operator's moves from it (they go as proposals).
277
277
  */
278
278
  export function talkEnv(env = process.env) {
279
279
  // GCF_RUN_ITEM too: a run's guards would take the thread's agent for that run's.
280
280
  const { CLAUDE_CODE_SESSION_ID: _, GCF_RUN_OWNER: __, GCF_MOVE_BY: ___, GCF_RUN_ITEM: ____, ...rest } = env;
281
- return { ...rest, GCF_MOVE_BY: 'session' };
281
+ return { ...rest, GCF_MOVE_BY: 'thread' };
282
282
  }
283
283
  // When the board last started each thread: a second start meanwhile only finds the lock held.
284
284
  const starts = new Map();
@@ -451,6 +451,17 @@ export function chatCard(file) {
451
451
  return card;
452
452
  }
453
453
  /** The events of a chat file: a thread's, or a run's `<id>.chat.jsonl`; none without one. */
454
+ /**
455
+ * The deny group the last session of a run's chat was refused by, for "Allow <group> and run
456
+ * again" (docs/Autonomy-Plan.md, E): its last refusal's, none from an older run. Never a group
457
+ * that guards history or the operator's own moves, nor an old alias.
458
+ */
459
+ export function deniedGroupOf(events) {
460
+ const start = events.findLastIndex((e) => e.type === 'session' && e.kind === 'start');
461
+ const denied = events.slice(Math.max(0, start)).filter((e) => e.type === 'denied');
462
+ const group = denied.at(-1)?.group ?? null;
463
+ return group && !['git-history', 'git-destroy', 'human-moves'].includes(group) ? group : null;
464
+ }
454
465
  export function chatEvents(file) {
455
466
  let text = '';
456
467
  try {