gcf-board 0.31.0 → 0.34.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 +3 -0
- package/dist/server/app.js +85 -18
- package/dist/server/cli.js +15 -6
- package/dist/server/events.js +54 -2
- package/dist/server/main.js +11 -0
- package/dist/server/runs.js +121 -14
- package/dist/server/talks.js +13 -1
- package/dist/shared/board.js +10 -4
- package/dist/web/assets/index-Fq42leVT.css +1 -0
- package/dist/web/assets/index-WMT9LmvP.js +124 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/activity.js +6 -2
- package/node_modules/gcf-session/package.json +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-BwvzIZyG.css +0 -1
- package/dist/web/assets/index-D3a54brO.js +0 -122
package/README.md
CHANGED
|
@@ -6,6 +6,9 @@ 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.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
|
|
10
|
+
- for 0.33: `gcf-aif-ext` ≥ 0.33 for a move that waits behind a card's main run: a form, the Design dialog, a chat proposal or Commit/Discard shows "Waits behind <card>" with **Cancel**, 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
|
|
11
|
+
- 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
|
|
9
12
|
- 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)
|
|
10
13
|
- for 0.23: `gcf-aif-ext` ≥ 0.25 and `gcf-harness-aif-ext` ≥ 0.24 for **Play** (an older core shows no bar)
|
|
11
14
|
- for 0.22: `gcf-aif-ext` ≥ 0.24 and `gcf-harness-aif-ext` ≥ 0.23 for the **shelved** chip (an older pair stops a main batch at a card's loose code, as before)
|
package/dist/server/app.js
CHANGED
|
@@ -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, 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,50 @@ 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
|
+
const cli = (p, args, timeout, input, env) => runCli(o.entry, p.path, args, timeout, input, env);
|
|
319
|
+
// This board's moves going now, tag → project folder: a board that stops cancels the ones
|
|
320
|
+
// waiting behind a main run (Main-Run-Moves-Plan d9), none goes on with no page to tell.
|
|
321
|
+
const ownMoves = new Map();
|
|
322
|
+
const cancelOwnMoves = () => {
|
|
323
|
+
for (const [tag, dir] of ownMoves)
|
|
324
|
+
for (const w of movesWaiting(dir))
|
|
325
|
+
if (w.tag === tag && !w.going)
|
|
326
|
+
try {
|
|
327
|
+
writeFileSync(w.cancel, '');
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// Gone with its move meanwhile.
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* The operator's move `args`, tagged (GCF_MOVE_TAG): behind a main run the core waits for the
|
|
335
|
+
* run's edits instead of refusing, the request open the while (d7).
|
|
336
|
+
*/
|
|
337
|
+
const tagged = async (p, tag, args, input) => {
|
|
338
|
+
// One move a tag: a second would share its record's name, and its Cancel.
|
|
339
|
+
if (ownMoves.has(tag))
|
|
340
|
+
throw new HttpError(409, `a move tagged ${tag} goes already`);
|
|
341
|
+
ownMoves.set(tag, p.path);
|
|
342
|
+
try {
|
|
343
|
+
return await cli(p, args, undefined, input, { GCF_MOVE_TAG: tag });
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
ownMoves.delete(tag);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
/** Unblock item `id` for "Allow for one run": null when it went or the card is unblocked already. */
|
|
350
|
+
const unblock = async (p, id) => {
|
|
351
|
+
const moves = (domains.get(p.name) ?? (await boardOf(p)).domain).moves;
|
|
352
|
+
const r = await cli(p, moveArgs({ cmd: 'unblock', id }, moves));
|
|
353
|
+
if (r.ok)
|
|
354
|
+
return null;
|
|
355
|
+
// Unblocked meanwhile (another click, a console): the start goes on.
|
|
356
|
+
const status = (await boardOf(p)).items.find((i) => i.id === id)?.status;
|
|
357
|
+
return status && !['blocked', 'parked'].includes(status)
|
|
358
|
+
? null
|
|
359
|
+
: `unblock ${id}: ${briefError(r.err)}`;
|
|
360
|
+
};
|
|
361
|
+
setUnblocker(unblock);
|
|
317
362
|
// The run gate's answers being worked out, by project and ids (GET …/gate).
|
|
318
363
|
const gates = new Map();
|
|
319
364
|
// The last domain each project's board read gave: an item move is built from its form.
|
|
@@ -891,6 +936,20 @@ export function createApp(o) {
|
|
|
891
936
|
}
|
|
892
937
|
},
|
|
893
938
|
],
|
|
939
|
+
[
|
|
940
|
+
// The operator's Cancel of a move waiting behind a main run (d7): its cancel file, which
|
|
941
|
+
// the core reads while it waits. One that waits no more is recorded, or refused, already.
|
|
942
|
+
'POST',
|
|
943
|
+
/^\/api\/p\/([^/]+)\/waiting\/([\w.-]{1,200})\/cancel$/,
|
|
944
|
+
async (_req, res, m) => {
|
|
945
|
+
const p = await projectOf(m[1]);
|
|
946
|
+
const w = movesWaiting(p.path).find((x) => x.tag === m[2] && !x.going);
|
|
947
|
+
if (!w)
|
|
948
|
+
throw new HttpError(409, 'already recorded: the move waits no more');
|
|
949
|
+
writeFileSync(w.cancel, '');
|
|
950
|
+
send(res, 200, { ok: true });
|
|
951
|
+
},
|
|
952
|
+
],
|
|
894
953
|
[
|
|
895
954
|
'POST',
|
|
896
955
|
/^\/api\/p\/([^/]+)\/move$/,
|
|
@@ -927,11 +986,12 @@ export function createApp(o) {
|
|
|
927
986
|
body.from = entry;
|
|
928
987
|
}
|
|
929
988
|
let args = moveArgs(body, domain?.moves);
|
|
930
|
-
const run = () =>
|
|
989
|
+
const run = (tag) => tagged(p, tag, args, moveInput(body, domain?.moves));
|
|
931
990
|
// An agent's proposal made (AD-16, AD-33): its record goes with the move.
|
|
932
991
|
const { talk, id } = (body.proposal ?? {});
|
|
992
|
+
// The page's own tag finds its move among the waiting ones (d7).
|
|
933
993
|
if (body.proposal === undefined)
|
|
934
|
-
r = await run();
|
|
994
|
+
r = await run(typeof body.tag === 'string' && TAG.test(body.tag) ? body.tag : randomUUID());
|
|
935
995
|
else {
|
|
936
996
|
if (typeof talk !== 'string' || typeof id !== 'string' || !/^[\w-]+$/.test(id))
|
|
937
997
|
throw new HttpError(400, 'a proposal names its talk and its id');
|
|
@@ -959,7 +1019,8 @@ export function createApp(o) {
|
|
|
959
1019
|
const read = await boardOf(p);
|
|
960
1020
|
const ids = idsOf(read);
|
|
961
1021
|
const question = questionText(read, String(body.cmd), item);
|
|
962
|
-
|
|
1022
|
+
const go = () => run(proposalTag(talk, id));
|
|
1023
|
+
r = await acceptProposal(p, talk, id, String(body.cmd), item, ids, go, mark, question);
|
|
963
1024
|
broadcast({ type: 'talks', project: p.name });
|
|
964
1025
|
}
|
|
965
1026
|
}
|
|
@@ -1298,17 +1359,21 @@ export function createApp(o) {
|
|
|
1298
1359
|
const start = () => [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, { fresh, harness, agent, allow }));
|
|
1299
1360
|
// "Allow for one run" (Permission-Stop-Plan d3): the unblock and the start as one step,
|
|
1300
1361
|
// the autopilot held off between them, so no run takes the card without its allowance.
|
|
1362
|
+
// Behind a main run the whole step waits in the queue, in any mode (Main-Run-Moves-Plan
|
|
1363
|
+
// d10): an unblock now would wait in the core, the autopilot held off all the while.
|
|
1364
|
+
const behind = mainTaken(p.name);
|
|
1301
1365
|
const started = body.unblock === true && allow
|
|
1302
|
-
?
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1366
|
+
? behind
|
|
1367
|
+
? [...parts].map(([mode, part]) => startRun(o.entry, p, part, mode, { fresh, harness, agent, allow, unblock: part }))
|
|
1368
|
+
: await whileAllowing(p.name, async () => {
|
|
1369
|
+
for (const id of ids) {
|
|
1370
|
+
const why = await unblock(p, id);
|
|
1371
|
+
if (why)
|
|
1372
|
+
throw new HttpError(409, why);
|
|
1373
|
+
}
|
|
1374
|
+
broadcast({ type: 'board', project: p.name });
|
|
1375
|
+
return start();
|
|
1376
|
+
})
|
|
1312
1377
|
: start();
|
|
1313
1378
|
send(res, 202, {
|
|
1314
1379
|
started: started.flatMap((s) => s.started ?? []),
|
|
@@ -1467,6 +1532,8 @@ export function createApp(o) {
|
|
|
1467
1532
|
for (const k of ['close', 'closeAllConnections']) {
|
|
1468
1533
|
const own = server[k].bind(server);
|
|
1469
1534
|
server[k] = ((...a) => {
|
|
1535
|
+
if (k === 'close')
|
|
1536
|
+
cancelOwnMoves();
|
|
1470
1537
|
for (const s of pages)
|
|
1471
1538
|
s.destroy();
|
|
1472
1539
|
return own(...a);
|
package/dist/server/cli.js
CHANGED
|
@@ -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) =>
|
|
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.
|
package/dist/server/events.js
CHANGED
|
@@ -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)
|
|
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();
|
package/dist/server/main.js
CHANGED
|
@@ -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();
|
package/dist/server/runs.js
CHANGED
|
@@ -13,7 +13,7 @@ import path from 'node:path';
|
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
14
|
import { writeAtomicSync } from './atomic.js';
|
|
15
15
|
import { briefError, runCli, startOf } from './cli.js';
|
|
16
|
-
import { alive, broadcast } from './events.js';
|
|
16
|
+
import { alive, broadcast, movesWaiting } from './events.js';
|
|
17
17
|
import { HttpError } from './http-error.js';
|
|
18
18
|
import { homeDir } from './registry.js';
|
|
19
19
|
import { accountSettings, lastReading, reserveOfReading } from 'gcf-session';
|
|
@@ -123,16 +123,21 @@ const paused = new Set();
|
|
|
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
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
|
-
|
|
126
|
+
// no autopilot run starts in the gap, or it would take the card without the allowance. A count:
|
|
127
|
+
// two such steps at once hold it until both end.
|
|
128
|
+
const allowing = new Map();
|
|
128
129
|
/** Hold off the autopilot while `fn` unblocks and starts a card with its allowance. */
|
|
129
130
|
export async function whileAllowing(project, fn) {
|
|
130
|
-
allowing.
|
|
131
|
+
allowing.set(project, (allowing.get(project) ?? 0) + 1);
|
|
131
132
|
try {
|
|
132
133
|
return await fn();
|
|
133
134
|
}
|
|
134
135
|
finally {
|
|
135
|
-
allowing.
|
|
136
|
+
const left = (allowing.get(project) ?? 1) - 1;
|
|
137
|
+
if (left)
|
|
138
|
+
allowing.set(project, left);
|
|
139
|
+
else
|
|
140
|
+
allowing.delete(project);
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
// The paused projects whose pause the usage limit set: a run that ended paused by it (AD-19).
|
|
@@ -184,7 +189,8 @@ function save() {
|
|
|
184
189
|
projects[name] = {
|
|
185
190
|
path: where,
|
|
186
191
|
// `waiting` stays behind: a board started again tries it, the dependency may have ended.
|
|
187
|
-
|
|
192
|
+
// An unblock going now is kept as not begun: a board started again tries it again.
|
|
193
|
+
queue: (queues.get(name) ?? []).map(({ entry: _e, p: _p, waiting: _w, busy: _b, ...q }) => q),
|
|
188
194
|
// The queue's own pause; the hold beside it, so a restart keeps both.
|
|
189
195
|
paused_by: paused.has(name) ? (limitPaused.has(name) ? 'limit' : 'failure') : null,
|
|
190
196
|
held: projectHolds.has(name),
|
|
@@ -292,6 +298,11 @@ function queuedOf(v) {
|
|
|
292
298
|
const agent = isObject(v.agent)
|
|
293
299
|
? { model: pick(v.agent.model), effort: pick(v.agent.effort) }
|
|
294
300
|
: undefined;
|
|
301
|
+
// Its unblock goes to a command line too; one that does not read would start a blocked card.
|
|
302
|
+
const unblock = list(v.unblock);
|
|
303
|
+
const slugs = unblock.length > 0 && unblock.every((id) => typeof id === 'string' && SLUG.test(id));
|
|
304
|
+
if (v.unblock !== undefined && !(Array.isArray(v.unblock) && slugs))
|
|
305
|
+
return null;
|
|
295
306
|
return {
|
|
296
307
|
ids: ids,
|
|
297
308
|
mode: v.mode,
|
|
@@ -301,6 +312,7 @@ function queuedOf(v) {
|
|
|
301
312
|
...(v.waitLimit === true ? { waitLimit: true } : {}),
|
|
302
313
|
...(typeof v.waited === 'string' ? { waited: v.waited } : {}),
|
|
303
314
|
...(agent ? { agent } : {}),
|
|
315
|
+
...(unblock.length ? { unblock: unblock } : {}),
|
|
304
316
|
};
|
|
305
317
|
}
|
|
306
318
|
/** The state a board before this one kept of project `p`: its queue, pause, reports and trace. */
|
|
@@ -374,6 +386,11 @@ export function runsOf(project) {
|
|
|
374
386
|
reports: reports.get(project) ?? [],
|
|
375
387
|
acts: acts.get(project) ?? [],
|
|
376
388
|
autopilot: autopilotOf(project),
|
|
389
|
+
moves_waiting: paths.has(project)
|
|
390
|
+
? movesWaiting(paths.get(project))
|
|
391
|
+
.filter((w) => !w.going)
|
|
392
|
+
.map(({ cancel: _, going: __, ...w }) => w)
|
|
393
|
+
: [],
|
|
377
394
|
};
|
|
378
395
|
}
|
|
379
396
|
/** A project left the board: nothing of it may run any more. */
|
|
@@ -422,7 +439,7 @@ function limited(run, result) {
|
|
|
422
439
|
}
|
|
423
440
|
/** Start the next queued batch when the checkout is free: after a run, or on the operator's resume. */
|
|
424
441
|
function advance(project) {
|
|
425
|
-
if (adopting.has(project))
|
|
442
|
+
if (adopting.has(project) || unblocking.has(project))
|
|
426
443
|
return;
|
|
427
444
|
if (paused.has(project) || projectHolds.has(project) || clickBuilding(project))
|
|
428
445
|
return;
|
|
@@ -441,11 +458,87 @@ function advance(project) {
|
|
|
441
458
|
return;
|
|
442
459
|
}
|
|
443
460
|
reserveWaits.delete(project);
|
|
444
|
-
const
|
|
461
|
+
const next = queue[at];
|
|
462
|
+
// It stays queued while it unblocks: a second click is busy, a restart keeps it.
|
|
463
|
+
if (next.unblock) {
|
|
464
|
+
void unblockAndRun(next);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
queue.splice(at, 1);
|
|
445
468
|
trace(project, 'queue-run', `the queue starts ${next.ids.join(', ')}`);
|
|
446
469
|
// Nobody clicked it now: it waits while the usage limit's reset is ahead.
|
|
447
470
|
spawnRun({ ...next, waitLimit: true, queued: true }, next.mode);
|
|
448
471
|
}
|
|
472
|
+
// The projects whose queue unblocks a card now: nothing else of it starts meanwhile.
|
|
473
|
+
const unblocking = new Set();
|
|
474
|
+
/** Whether a main run has the checkout, or a queued unblock takes it next (d10). */
|
|
475
|
+
export const mainTaken = (project) => unblocking.has(project) || activeRuns(project).some((r) => r.mode === 'main');
|
|
476
|
+
/**
|
|
477
|
+
* The unblock of item `id` by the domain's move: null when it went, or the card is unblocked
|
|
478
|
+
* already; else why not. The board's server sets it (app.ts): the move is the domain's.
|
|
479
|
+
*/
|
|
480
|
+
let unblocker = async (_p, id) => `unblock ${id}: no board server to make it`;
|
|
481
|
+
export function setUnblocker(fn) {
|
|
482
|
+
unblocker = fn;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* "Allow for one run" queued behind a main run (Main-Run-Moves-Plan d10): its unblock, then its
|
|
486
|
+
* start, the autopilot held off between them; the queue waits for both. A refused unblock is a
|
|
487
|
+
* refused start: the entry goes, its report says why.
|
|
488
|
+
*/
|
|
489
|
+
async function unblockAndRun(q) {
|
|
490
|
+
const project = q.p.name;
|
|
491
|
+
unblocking.add(project);
|
|
492
|
+
// The entry as the queue holds it now: the operator may take a card out meanwhile (unqueue).
|
|
493
|
+
const mark = randomUUID();
|
|
494
|
+
q.busy = mark;
|
|
495
|
+
const entry = () => (queues.get(project) ?? []).find((x) => x.busy === mark);
|
|
496
|
+
let why = null;
|
|
497
|
+
try {
|
|
498
|
+
await whileAllowing(project, async () => {
|
|
499
|
+
for (const id of q.unblock ?? [])
|
|
500
|
+
if (entry()?.unblock?.includes(id) && (why = await unblocker(q.p, id)))
|
|
501
|
+
return;
|
|
502
|
+
const now = entry();
|
|
503
|
+
// Taken out of the queue meanwhile: nothing to start.
|
|
504
|
+
if (!now)
|
|
505
|
+
return;
|
|
506
|
+
// A main run that came meanwhile has the checkout: it waits where it is, its unblock made
|
|
507
|
+
// (an unblocked card is no refusal of the next try).
|
|
508
|
+
if (now.mode === 'main' && activeRuns(project).some((r) => r.mode === 'main'))
|
|
509
|
+
return;
|
|
510
|
+
const queue = queues.get(project) ?? [];
|
|
511
|
+
queue.splice(queue.indexOf(now), 1);
|
|
512
|
+
const { unblock: _, busy: __, ...go } = now;
|
|
513
|
+
trace(project, 'queue-run', `the queue unblocks and starts ${now.ids.join(', ')}`);
|
|
514
|
+
spawnRun({ ...go, waitLimit: true, queued: true }, now.mode);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
catch (e) {
|
|
518
|
+
why = `unblock ${q.ids.join(', ')}: ${e.message}`;
|
|
519
|
+
}
|
|
520
|
+
finally {
|
|
521
|
+
unblocking.delete(project);
|
|
522
|
+
const left = entry();
|
|
523
|
+
const queue = queues.get(project) ?? [];
|
|
524
|
+
// A refused unblock is a refused start: the entry goes; one waiting on is free again.
|
|
525
|
+
if (left && why)
|
|
526
|
+
queue.splice(queue.indexOf(left), 1);
|
|
527
|
+
else if (left)
|
|
528
|
+
delete left.busy;
|
|
529
|
+
}
|
|
530
|
+
if (why) {
|
|
531
|
+
trace(project, 'queue-refused', why);
|
|
532
|
+
const report = { id: `r${++reportSeq}`, at: new Date().toISOString(), ids: q.ids };
|
|
533
|
+
reports.set(project, [
|
|
534
|
+
...(reports.get(project) ?? []),
|
|
535
|
+
{ ...report, ok: false, result: null, err: why, note: '' },
|
|
536
|
+
].slice(-KEEP_REPORTS));
|
|
537
|
+
}
|
|
538
|
+
changed(project);
|
|
539
|
+
// A worktree run, or none, leaves the checkout free: what queues behind it goes now.
|
|
540
|
+
advance(project);
|
|
541
|
+
}
|
|
449
542
|
// The projects a run reported stopped by the reserve: the board does not know the run's model,
|
|
450
543
|
// so it judges every model's week until a reading under the reserve in all (Codex review).
|
|
451
544
|
const reserveStrict = new Set();
|
|
@@ -570,8 +663,10 @@ export function resumeQueue(project) {
|
|
|
570
663
|
}
|
|
571
664
|
/** Take an item out of the queue before its run starts. */
|
|
572
665
|
export function unqueue(project, id) {
|
|
666
|
+
const without = (ids) => ids.filter((x) => x !== id);
|
|
667
|
+
// An "Allow for one run" entry unblocks only the cards it still starts.
|
|
573
668
|
const queue = (queues.get(project) ?? [])
|
|
574
|
-
.map((q) => ({ ...q, ids: q.ids
|
|
669
|
+
.map((q) => ({ ...q, ids: without(q.ids), ...(q.unblock && { unblock: without(q.unblock) }) }))
|
|
575
670
|
.filter((q) => q.ids.length);
|
|
576
671
|
queues.set(project, queue);
|
|
577
672
|
changed(project);
|
|
@@ -963,18 +1058,30 @@ export function busyCheck(p, ids) {
|
|
|
963
1058
|
* `harness` is the domain's (`domain.harness`); the tests take GCF's. Its sessions are open to
|
|
964
1059
|
* the operator's chat. `agent`: a model and effort for this run only, over each item's own.
|
|
965
1060
|
* `allow`: deny rules in force this run goes without (docs/Permission-Stop-Plan.md, d2).
|
|
1061
|
+
* `unblock`: these ids are unblocked first, in the queue, in any mode (Main-Run-Moves-Plan d10).
|
|
966
1062
|
*/
|
|
967
|
-
export function startRun(entry, p, ids, mode = '
|
|
1063
|
+
export function startRun(entry, p, ids, mode = 'main', { fresh = false, harness = 'gcf-harness', agent, allow, unblock, } = {}) {
|
|
968
1064
|
// A second click on the same card: the harness would refuse it on its lock, noisily.
|
|
969
1065
|
paths.set(p.name, p.path);
|
|
970
1066
|
busyCheck(p, ids);
|
|
971
1067
|
const { active: going } = runsOf(p.name);
|
|
972
1068
|
// A paused queue holds a new main run too: it would repeat the failure, and jump the queue.
|
|
973
|
-
|
|
974
|
-
|
|
1069
|
+
// A queued "Allow for one run" unblocking now takes the checkout next: a main run waits for it.
|
|
1070
|
+
const held = paused.has(p.name) || clickBuilding(p.name) || unblocking.has(p.name);
|
|
1071
|
+
if (unblock?.length || (mode === 'main' && (held || going.some((r) => r.mode === 'main')))) {
|
|
975
1072
|
queues.set(p.name, [
|
|
976
1073
|
...(queues.get(p.name) ?? []),
|
|
977
|
-
{
|
|
1074
|
+
{
|
|
1075
|
+
entry,
|
|
1076
|
+
p,
|
|
1077
|
+
ids,
|
|
1078
|
+
mode,
|
|
1079
|
+
fresh,
|
|
1080
|
+
harness,
|
|
1081
|
+
agent,
|
|
1082
|
+
...(allow?.length ? { allow } : {}),
|
|
1083
|
+
...(unblock?.length ? { unblock } : {}),
|
|
1084
|
+
},
|
|
978
1085
|
]);
|
|
979
1086
|
changed(p.name);
|
|
980
1087
|
return { queued: ids };
|
|
@@ -1195,7 +1302,7 @@ async function pilot(project) {
|
|
|
1195
1302
|
});
|
|
1196
1303
|
return;
|
|
1197
1304
|
}
|
|
1198
|
-
const mode = plan.mode ?? '
|
|
1305
|
+
const mode = plan.mode ?? 'main';
|
|
1199
1306
|
let loose = [];
|
|
1200
1307
|
try {
|
|
1201
1308
|
loose = mode === 'main' ? await looseOf(s, plan.ids) : [];
|
package/dist/server/talks.js
CHANGED
|
@@ -15,7 +15,7 @@ import { THREAD_ID, createThread, defaultsOf, listThreads, presetsOf, readThread
|
|
|
15
15
|
import { runModeOf, toolOf } from '../shared/board.js';
|
|
16
16
|
import { writeAtomic } from './atomic.js';
|
|
17
17
|
import { briefError, refusalOf } from './cli.js';
|
|
18
|
-
import { alive } from './events.js';
|
|
18
|
+
import { alive, movesWaiting } from './events.js';
|
|
19
19
|
import { HttpError } from './http-error.js';
|
|
20
20
|
import { IMAGE_EXT, saysPast } from './chat.js';
|
|
21
21
|
import { homeDir, yoloFile } from './registry.js';
|
|
@@ -638,6 +638,11 @@ function addRecord(td, id, rec) {
|
|
|
638
638
|
}
|
|
639
639
|
// The proposals whose move runs now, `<td> <id>`: a second click waits for none.
|
|
640
640
|
const accepting = new Set();
|
|
641
|
+
/**
|
|
642
|
+
* The GCF_MOVE_TAG of proposal `id` of thread `t`'s move (Main-Run-Moves-Plan d7, d9): a board
|
|
643
|
+
* started again finds it waiting by it. The dot keeps it apart from a page's tag.
|
|
644
|
+
*/
|
|
645
|
+
export const proposalTag = (t, id) => `${t}.${id}`;
|
|
641
646
|
/**
|
|
642
647
|
* Make proposal `id` of thread `t` by its move (AD-16, AD-33): `accepting` is written first,
|
|
643
648
|
* with the item it makes, whether that id was taken already and HEAD before it; then `accepted`
|
|
@@ -669,6 +674,9 @@ export async function acceptProposal(p, t, id, move, item, ids, run, mark, quest
|
|
|
669
674
|
const made = await settled(td, id, readRecords(td)[id], async () => ids, true);
|
|
670
675
|
if (made?.state === 'accepted')
|
|
671
676
|
throw new HttpError(409, `proposal ${id} is made already: ${made.item ?? ''}`);
|
|
677
|
+
// Its move of a board before this one waits behind a main run (d9).
|
|
678
|
+
if (made?.state === 'accepting')
|
|
679
|
+
throw new HttpError(409, `proposal ${id} is being made already`);
|
|
672
680
|
const head = git(projectOf(td), 'rev-parse', 'HEAD');
|
|
673
681
|
await setRecord(td, id, {
|
|
674
682
|
state: 'accepting',
|
|
@@ -734,6 +742,10 @@ async function settled(td, id, rec, ids, mine = false) {
|
|
|
734
742
|
if (latest?.state !== 'accepting' || (!mine && accepting.has(`${td} ${id}`)))
|
|
735
743
|
return latest;
|
|
736
744
|
const projectDir = projectOf(td);
|
|
745
|
+
// Its move waits behind a main run still, outliving the board that made it (d9): not over.
|
|
746
|
+
const tag = proposalTag(path.basename(td), id);
|
|
747
|
+
if (movesWaiting(projectDir).some((w) => w.tag === tag))
|
|
748
|
+
return latest;
|
|
737
749
|
const ours = !rec.mark ||
|
|
738
750
|
git(projectDir, 'log', '-1', '--format=%H', `--grep=^GCF-Proposal: ${rec.mark}$`) !== '';
|
|
739
751
|
// A new item: there now and not before, by its own commit. A move on what is already there
|
package/dist/shared/board.js
CHANGED
|
@@ -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 =
|
|
3
|
+
export const BOARD_SCHEMA = 6;
|
|
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 = [
|
|
@@ -10,13 +10,19 @@ const ATTACHED = [
|
|
|
10
10
|
/** Whether project path `rel` lies where attachments are: the board serves it as one. */
|
|
11
11
|
export const attachedShape = (rel) => ATTACHED.some((r) => r.test(rel));
|
|
12
12
|
/**
|
|
13
|
-
* Where item `id`'s run goes (Methodology §7): the run's pick, else the
|
|
14
|
-
*
|
|
13
|
+
* Where item `id`'s run goes (Methodology §7): the run's pick, else the core's choice (`runs_in`,
|
|
14
|
+
* core 0.32: where its kept session ran, worktree while its copy lives, Fallback-Fidelity-Plan
|
|
15
|
+
* d1), else, from an older core,
|
|
16
|
+
* the item's own `run_mode` (core 0.16, Board-PRD decision 28), else the project's.
|
|
15
17
|
*/
|
|
16
18
|
export function runModeOf(board, id, asked) {
|
|
17
19
|
if (asked === 'main' || asked === 'worktree')
|
|
18
20
|
return asked;
|
|
19
|
-
const
|
|
21
|
+
const item = board.items.find((i) => i.id === id);
|
|
22
|
+
const core = item?.runs_in;
|
|
23
|
+
if (core === 'main' || core === 'worktree')
|
|
24
|
+
return core;
|
|
25
|
+
const own = item?.run_mode;
|
|
20
26
|
return own === 'main' || own === 'worktree' ? own : board.run_mode;
|
|
21
27
|
}
|
|
22
28
|
/** A refusal whose paths a board can show and fix. */
|