gcf-board 0.16.5 → 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.
- package/dist/server/app.js +23 -5
- package/dist/server/moves.js +25 -0
- package/dist/server/runs.js +270 -21
- package/dist/server/talks.js +42 -9
- package/dist/web/assets/index-DiCpr5s0.js +66 -0
- package/dist/web/assets/index-gRDl4h3I.css +1 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/activity.js +42 -11
- package/node_modules/gcf-session/lib/chat.js +96 -6
- package/node_modules/gcf-session/lib/job.js +2 -1
- package/node_modules/gcf-session/lib/session.js +11 -2
- package/node_modules/gcf-session/lib/thread.js +2 -16
- package/node_modules/gcf-session/package.json +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-Bkuzk0Ea.js +0 -66
- package/dist/web/assets/index-DwanTUVJ.css +0 -1
package/dist/server/app.js
CHANGED
|
@@ -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,
|
|
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
|
},
|
|
@@ -792,9 +800,7 @@ export function createApp(o) {
|
|
|
792
800
|
throw new HttpError(409, 'the usage limit holds for the account: start after its reset');
|
|
793
801
|
drafting.add(key);
|
|
794
802
|
try {
|
|
795
|
-
const
|
|
796
|
-
await prepareTalk(p, board, id);
|
|
797
|
-
await sendTalk(p, id, { type: 'say', text: say }, board);
|
|
803
|
+
const id = await startDesign(p, board, m[2], startGiven(body), (t, say) => sendTalk(p, t, { type: 'say', text: say }, board));
|
|
798
804
|
broadcast({ type: 'talks', project: p.name });
|
|
799
805
|
send(res, 201, { thread: id });
|
|
800
806
|
}
|
|
@@ -895,6 +901,18 @@ export function createApp(o) {
|
|
|
895
901
|
send(res, 200, { ok: true });
|
|
896
902
|
},
|
|
897
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
|
+
],
|
|
898
916
|
[
|
|
899
917
|
'DELETE',
|
|
900
918
|
/^\/api\/p\/([^/]+)\/reports\/(r\d+)$/,
|
package/dist/server/moves.js
CHANGED
|
@@ -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));
|
package/dist/server/runs.js
CHANGED
|
@@ -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([
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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 = {
|
|
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();
|
package/dist/server/talks.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// and what became of them (AD-33) are in `proposals.json`.
|
|
8
8
|
import { spawn, spawnSync } from 'node:child_process';
|
|
9
9
|
import { randomBytes } from 'node:crypto';
|
|
10
|
-
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, statSync, writeFileSync, } from 'node:fs';
|
|
10
|
+
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
11
11
|
import os from 'node:os';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
@@ -271,14 +271,14 @@ export function talkLive(p, t) {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
274
|
-
* What a thread's engine runs with
|
|
275
|
-
*
|
|
276
|
-
*
|
|
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: '
|
|
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();
|
|
@@ -335,10 +335,17 @@ export function designTalk(p, board, start, given) {
|
|
|
335
335
|
const t = createThread(p.path, { start: { id: start } });
|
|
336
336
|
let file = '';
|
|
337
337
|
if (given.file && name) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
try {
|
|
339
|
+
const att = path.join(writeDir(p, t), 'att');
|
|
340
|
+
mkdirSync(att, { recursive: true });
|
|
341
|
+
writeFileSync(path.join(att, name), given.file.text);
|
|
342
|
+
file = path.relative(p.path, path.join(att, name)).replaceAll('\\', '/');
|
|
343
|
+
}
|
|
344
|
+
catch (e) {
|
|
345
|
+
// The GDD not kept: no thread stays for it, as for a first message that never went.
|
|
346
|
+
rmSync(dirOf(p, t), { recursive: true, force: true });
|
|
347
|
+
throw e;
|
|
348
|
+
}
|
|
342
349
|
}
|
|
343
350
|
const say = s.say
|
|
344
351
|
.replaceAll('{file}', file)
|
|
@@ -347,6 +354,21 @@ export function designTalk(p, board, start, given) {
|
|
|
347
354
|
.replaceAll('{text}', text);
|
|
348
355
|
return { id: t, say };
|
|
349
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Design start `start` (designTalk), its first message sent by `send`: the thread's id. A send
|
|
359
|
+
* that fails takes the thread away with it, so no empty thread stays in the list.
|
|
360
|
+
*/
|
|
361
|
+
export async function startDesign(p, board, start, given, send) {
|
|
362
|
+
const { id, say } = designTalk(p, board, start, given);
|
|
363
|
+
try {
|
|
364
|
+
await send(id, say);
|
|
365
|
+
}
|
|
366
|
+
catch (e) {
|
|
367
|
+
rmSync(dirOf(p, id), { recursive: true, force: true });
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
370
|
+
return id;
|
|
371
|
+
}
|
|
350
372
|
// A GDD's name kept in gcf/source/: the board's file route shows `[\w./-]` names only.
|
|
351
373
|
const GDD_NAME = /^[\w][\w.-]*\.md$/;
|
|
352
374
|
/**
|
|
@@ -429,6 +451,17 @@ export function chatCard(file) {
|
|
|
429
451
|
return card;
|
|
430
452
|
}
|
|
431
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
|
+
}
|
|
432
465
|
export function chatEvents(file) {
|
|
433
466
|
let text = '';
|
|
434
467
|
try {
|