gcf-board 0.17.1 → 0.18.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 +1 -0
- package/dist/server/app.js +143 -11
- package/dist/server/atomic.js +30 -7
- package/dist/server/cli.js +28 -2
- package/dist/server/events.js +2 -0
- package/dist/server/main.js +2 -0
- package/dist/server/mcp.js +3 -1
- package/dist/server/propose.js +12 -6
- package/dist/server/registry.js +2 -0
- package/dist/server/relay.js +2 -6
- package/dist/server/runs.js +3 -0
- package/dist/server/talks.js +117 -24
- package/dist/server/usage.js +101 -0
- package/dist/shared/board.js +17 -0
- package/dist/web/assets/index-lDFot1Io.js +81 -0
- package/dist/web/assets/index-r-gA2aJJ.css +1 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/chat.js +19 -2
- package/node_modules/gcf-session/lib/store.js +14 -2
- package/node_modules/gcf-session/lib/thread.js +4 -1
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +26 -0
- package/package.json +1 -1
- package/dist/web/assets/index-DiCpr5s0.js +0 -66
- package/dist/web/assets/index-gRDl4h3I.css +0 -1
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ Do not put the port on a network. Remote and phone access is planned for v2, beh
|
|
|
108
108
|
npm install
|
|
109
109
|
npx playwright install chromium # once: the browser the browser scenarios use
|
|
110
110
|
npm test # server and web tests on Node's type stripping; the browser scenarios need npm run build first
|
|
111
|
+
node --test "server/scenarios/*.test.ts" # the scenarios alone: the real ai-factory CLI, a project per file (server/scenarios/kit.ts)
|
|
111
112
|
npm run typecheck
|
|
112
113
|
npm run build # vite → dist/web, tsc → dist/server
|
|
113
114
|
node dist/server/main.js --port 4318
|
package/dist/server/app.js
CHANGED
|
@@ -6,24 +6,25 @@
|
|
|
6
6
|
import { execFile } from 'node:child_process';
|
|
7
7
|
import { randomBytes } from 'node:crypto';
|
|
8
8
|
import { createServer } from 'node:http';
|
|
9
|
-
import { createReadStream, existsSync, statSync, writeFileSync } from 'node:fs';
|
|
10
|
-
import { lstat, mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
9
|
+
import { closeSync, createReadStream, existsSync, openSync, readSync, statSync, writeFileSync, } from 'node:fs';
|
|
10
|
+
import { lstat, mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { pipeline } from 'node:stream/promises';
|
|
12
12
|
import os from 'node:os';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
-
import { BOARD_SCHEMA, runModeOf, } from '../shared/board.js';
|
|
14
|
+
import { BOARD_SCHEMA, runModeOf, toolOf, } from '../shared/board.js';
|
|
15
15
|
import { admit, cookieName, hostAllowed, tokenInUrl } from './auth.js';
|
|
16
|
-
import { briefError, runCli } from './cli.js';
|
|
16
|
+
import { briefError, refusalOf, runCli } from './cli.js';
|
|
17
17
|
import { broadcast, planRev, SESSION_TTL_MIN, subscribe, watchProject } from './events.js';
|
|
18
18
|
import { attachesUnit, CHAT_BODY_MAX, chatInput, IMAGE_EXT, talkInput, withUploads, } from './chat.js';
|
|
19
19
|
import { attachmentOf, follow, followLog, logPart, readShown, shownShape } from './files.js';
|
|
20
20
|
import { HttpError } from './http-error.js';
|
|
21
21
|
import { isCenterMove, moveArgs, moveInput, runIds } from './moves.js';
|
|
22
22
|
import { isUpload, saveUpload, UPLOAD_MAX } from './upload.js';
|
|
23
|
-
import { addProject, listProjects, projectOf, removeProject } from './registry.js';
|
|
23
|
+
import { addProject, homeDir, listProjects, projectOf, removeProject, yoloFile, } from './registry.js';
|
|
24
24
|
import { allThemes } from './themes.js';
|
|
25
|
+
import { askIfDue, askUsage, configureUsage, lastUsage } from './usage.js';
|
|
25
26
|
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
|
+
import { acceptProposal, agentDefaults, agentPresets, chatCard, chatEvents, deniedGroupOf, lastRunEnd, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
|
|
27
28
|
import { threadDir, threadOfEntry } from 'gcf-session';
|
|
28
29
|
const send = (res, status, body) => {
|
|
29
30
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
|
|
@@ -82,6 +83,18 @@ const idsOf = (b) => new Set([
|
|
|
82
83
|
...(b.history ?? []).map((h) => h.id),
|
|
83
84
|
...(b.graveyard ?? []).map((g) => g.id),
|
|
84
85
|
]);
|
|
86
|
+
/**
|
|
87
|
+
* The text of question `id` when `move` (a domain key, or as the engine names it) is the
|
|
88
|
+
* domain's answer: null when the board holds no such question; undefined for another move.
|
|
89
|
+
*/
|
|
90
|
+
const questionText = (b, move, id) => {
|
|
91
|
+
const answer = b.domain.sections.questions?.answer;
|
|
92
|
+
if (!answer || toolOf(answer) !== toolOf(move))
|
|
93
|
+
return undefined;
|
|
94
|
+
return (b.questions ?? []).find((q) => q.id === id)?.question ?? null;
|
|
95
|
+
};
|
|
96
|
+
/** The most paths one edits diff takes: a refusal past this many is read in the console. */
|
|
97
|
+
const EDIT_PATHS_MAX = 200;
|
|
85
98
|
const SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
86
99
|
// A model or effort word for one run: plain, as the harness takes it.
|
|
87
100
|
const WORD = /^[A-Za-z0-9][\w.-]{0,63}$/;
|
|
@@ -131,6 +144,31 @@ const headOf = (dir) => new Promise((resolve) => execFile('git', ['rev-parse', '
|
|
|
131
144
|
/** Whether the usage limit holds for the account now (decision 22): Draft waits for its reset. */
|
|
132
145
|
const limitHolds = (q) => q?.info.status === 'rejected' && (q.info.resetsAt ?? 0) * 1000 > Date.now();
|
|
133
146
|
/** The ISO time a file was last written, or null when it is not there. */
|
|
147
|
+
/** The last `tool: …` line of a run log's last 16 KB, without its clock; null without one. */
|
|
148
|
+
export function doingOf(file) {
|
|
149
|
+
let text = '';
|
|
150
|
+
try {
|
|
151
|
+
const size = statSync(file).size;
|
|
152
|
+
const fd = openSync(file, 'r');
|
|
153
|
+
try {
|
|
154
|
+
const n = Math.min(size, 16_384);
|
|
155
|
+
const buf = Buffer.alloc(n);
|
|
156
|
+
readSync(fd, buf, 0, n, size - n);
|
|
157
|
+
text = buf.toString('utf8');
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
closeSync(fd);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const line = text
|
|
167
|
+
.split(/\r?\n/)
|
|
168
|
+
.reverse()
|
|
169
|
+
.find((l) => /(^|\] )tool: /.test(l));
|
|
170
|
+
return line ? line.replace(/^\[[^\]]*\] /, '').slice(0, 200) : null;
|
|
171
|
+
}
|
|
134
172
|
const activeAt = (file) => {
|
|
135
173
|
try {
|
|
136
174
|
return statSync(file).mtime.toISOString();
|
|
@@ -184,6 +222,10 @@ async function lastQuota() {
|
|
|
184
222
|
return seen.sort((a, b) => Date.parse(b.at) - Date.parse(a.at))[0] ?? null;
|
|
185
223
|
}
|
|
186
224
|
export function createApp(o) {
|
|
225
|
+
configureUsage(o.usage ?? null);
|
|
226
|
+
// An open page's bar is read again every few minutes: a check each minute.
|
|
227
|
+
const usageTick = setInterval(() => askIfDue(), 60_000);
|
|
228
|
+
usageTick.unref();
|
|
187
229
|
const watchers = new Map();
|
|
188
230
|
let closed = false;
|
|
189
231
|
const watchAll = async () => {
|
|
@@ -287,7 +329,45 @@ export function createApp(o) {
|
|
|
287
329
|
return { ok: true, talk: t, ...(typeof sent.id === 'string' ? { id: sent.id } : {}) };
|
|
288
330
|
};
|
|
289
331
|
const routes = [
|
|
290
|
-
[
|
|
332
|
+
[
|
|
333
|
+
'GET',
|
|
334
|
+
/^\/api\/events$/,
|
|
335
|
+
async (_req, res) => {
|
|
336
|
+
subscribe(res);
|
|
337
|
+
// A page opened after a while reads the limits at once, not at the next tick.
|
|
338
|
+
askIfDue();
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
// A click on the bar's limits: read them now; the reading comes as a `quota` event.
|
|
342
|
+
[
|
|
343
|
+
'POST',
|
|
344
|
+
/^\/api\/usage$/,
|
|
345
|
+
async (_req, res) => {
|
|
346
|
+
if (!o.usage)
|
|
347
|
+
throw new HttpError(409, 'this board asks no usage limits');
|
|
348
|
+
void askUsage();
|
|
349
|
+
send(res, 202, { ok: true });
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
// The operator's YOLO (AD-54): every thread's calls go with no card while it is on.
|
|
353
|
+
['GET', /^\/api\/yolo$/, async (_req, res) => send(res, 200, { on: existsSync(yoloFile()) })],
|
|
354
|
+
[
|
|
355
|
+
'PUT',
|
|
356
|
+
/^\/api\/yolo$/,
|
|
357
|
+
async (req, res) => {
|
|
358
|
+
const b = await bodyOf(req);
|
|
359
|
+
if (typeof b.on !== 'boolean')
|
|
360
|
+
throw new HttpError(400, 'on is true or false');
|
|
361
|
+
if (b.on) {
|
|
362
|
+
await mkdir(homeDir(), { recursive: true });
|
|
363
|
+
await writeFile(yoloFile(), '');
|
|
364
|
+
}
|
|
365
|
+
else
|
|
366
|
+
await rm(yoloFile(), { force: true });
|
|
367
|
+
broadcast({ type: 'yolo' });
|
|
368
|
+
send(res, 200, { on: b.on });
|
|
369
|
+
},
|
|
370
|
+
],
|
|
291
371
|
['GET', /^\/api\/projects$/, async (_req, res) => send(res, 200, await listProjects())],
|
|
292
372
|
['GET', /^\/api\/themes$/, async (_req, res) => send(res, 200, await allThemes())],
|
|
293
373
|
[
|
|
@@ -327,6 +407,7 @@ export function createApp(o) {
|
|
|
327
407
|
plans_rev: planRev(p.name),
|
|
328
408
|
board_version: o.version,
|
|
329
409
|
quota: await lastQuota(),
|
|
410
|
+
usage: lastUsage(),
|
|
330
411
|
presets: agentPresets(),
|
|
331
412
|
defaults: agentDefaults(),
|
|
332
413
|
head: await headOf(p.path),
|
|
@@ -338,6 +419,12 @@ export function createApp(o) {
|
|
|
338
419
|
for (const i of board.items) {
|
|
339
420
|
if (i.running)
|
|
340
421
|
i.active_at = i.log ? activeAt(path.join(p.path, i.log)) : null;
|
|
422
|
+
// What it does now: its log's last tool call (Tails «Первым» 3).
|
|
423
|
+
if (i.running)
|
|
424
|
+
i.doing = i.log ? doingOf(path.join(p.path, i.log)) : null;
|
|
425
|
+
// How its last run ended, while no run goes (Tails «Первым» 2).
|
|
426
|
+
else
|
|
427
|
+
i.run_end = lastRunEnd(path.join(p.path, '.gcf-session', 'runs', `${i.id}.chat.jsonl`));
|
|
341
428
|
// A card waits in its run's chat: it is in "waiting for me" (Board-PRD §1.3).
|
|
342
429
|
if (i.running) {
|
|
343
430
|
const chat = path.join(p.path, '.gcf-session', 'runs', `${i.id}.chat.jsonl`);
|
|
@@ -513,7 +600,16 @@ export function createApp(o) {
|
|
|
513
600
|
async (_req, res, m, url) => {
|
|
514
601
|
const p = await projectOf(m[1]);
|
|
515
602
|
const item = url.searchParams.get('item') ?? undefined;
|
|
516
|
-
|
|
603
|
+
// One board read at most, shared by the settling and the questions' snapshot.
|
|
604
|
+
let read = null;
|
|
605
|
+
const board = () => (read ??= boardOf(p));
|
|
606
|
+
const talks = await listTalks(p, async () => idsOf(await board()), item, async (move, id) => {
|
|
607
|
+
// Only an answer reads the board: a pending block would read it on every poll.
|
|
608
|
+
const answer = domains.get(p.name)?.sections.questions?.answer;
|
|
609
|
+
if (answer && toolOf(answer) !== toolOf(move))
|
|
610
|
+
return undefined;
|
|
611
|
+
return questionText(await board(), move, id);
|
|
612
|
+
});
|
|
517
613
|
send(res, 200, { talks });
|
|
518
614
|
},
|
|
519
615
|
],
|
|
@@ -700,8 +796,10 @@ export function createApp(o) {
|
|
|
700
796
|
}
|
|
701
797
|
const mark = body.cmd === domain?.new_item ? `${talk}/${id}` : undefined;
|
|
702
798
|
const item = typeof body.id === 'string' ? body.id : '';
|
|
703
|
-
const
|
|
704
|
-
|
|
799
|
+
const read = await boardOf(p);
|
|
800
|
+
const ids = idsOf(read);
|
|
801
|
+
const question = questionText(read, String(body.cmd), item);
|
|
802
|
+
r = await acceptProposal(p, talk, id, String(body.cmd), item, ids, run, mark, question);
|
|
705
803
|
broadcast({ type: 'talks', project: p.name });
|
|
706
804
|
}
|
|
707
805
|
}
|
|
@@ -711,7 +809,40 @@ export function createApp(o) {
|
|
|
711
809
|
await rm(dir, { recursive: true, force: true });
|
|
712
810
|
}
|
|
713
811
|
broadcast({ type: 'board', project: p.name });
|
|
714
|
-
|
|
812
|
+
// A refusal the board can act on (core 0.20): the page offers its fixes.
|
|
813
|
+
const refusal = r.ok ? undefined : refusalOf(r.err);
|
|
814
|
+
send(res, 200, {
|
|
815
|
+
ok: r.ok,
|
|
816
|
+
out: r.out.trim(),
|
|
817
|
+
err: briefError(r.err),
|
|
818
|
+
...(refusal && { refusal }),
|
|
819
|
+
});
|
|
820
|
+
},
|
|
821
|
+
],
|
|
822
|
+
[
|
|
823
|
+
// The hand edits a `dirty` refusal names (core 0.20): the staged part and the part not
|
|
824
|
+
// staged, read by `gcf edits diff`. Paths under gcf/ only, as the refusal gives them.
|
|
825
|
+
'GET',
|
|
826
|
+
/^\/api\/p\/([^/]+)\/edits\/diff$/,
|
|
827
|
+
async (_req, res, m, url) => {
|
|
828
|
+
const p = await projectOf(m[1]);
|
|
829
|
+
const paths = url.searchParams.getAll('path');
|
|
830
|
+
// The core takes only paths git names changed; these limits keep the URL and the
|
|
831
|
+
// command line in bounds (Windows' 32K).
|
|
832
|
+
if (!paths.length ||
|
|
833
|
+
paths.length > EDIT_PATHS_MAX ||
|
|
834
|
+
paths.some((x) => !x.startsWith('gcf/') || x.includes('\\') || x.split('/').includes('..')))
|
|
835
|
+
throw new HttpError(400, `path: 1 to ${EDIT_PATHS_MAX} paths under gcf/, with /`);
|
|
836
|
+
const r = await cli(p, [
|
|
837
|
+
'gcf',
|
|
838
|
+
'edits',
|
|
839
|
+
'diff',
|
|
840
|
+
'--json',
|
|
841
|
+
...paths.map((x) => `--path=${x}`),
|
|
842
|
+
]);
|
|
843
|
+
if (!r.ok)
|
|
844
|
+
throw new HttpError(400, briefError(r.err || r.out));
|
|
845
|
+
send(res, 200, jsonOf(r, 'gcf edits diff'));
|
|
715
846
|
},
|
|
716
847
|
],
|
|
717
848
|
[
|
|
@@ -971,6 +1102,7 @@ export function createApp(o) {
|
|
|
971
1102
|
server.on('listening', () => watchAll().catch((e) => console.error(`gcf-board: ${e.message}`)));
|
|
972
1103
|
server.on('close', () => {
|
|
973
1104
|
closed = true;
|
|
1105
|
+
clearInterval(usageTick);
|
|
974
1106
|
for (const stop of watchers.values())
|
|
975
1107
|
stop();
|
|
976
1108
|
watchers.clear();
|
package/dist/server/atomic.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { rename, writeFile } from 'node:fs/promises';
|
|
3
|
-
|
|
4
|
-
export async function writeAtomic(file, text, mode) {
|
|
5
|
-
const tmp = `${file}.${process.pid}.tmp`;
|
|
6
|
-
await writeFile(tmp, text, { mode });
|
|
7
|
-
await rename(tmp, file);
|
|
8
|
-
}
|
|
3
|
+
import { rename, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
9
5
|
// What a rename over a file another process holds open meets on Windows (a scanner, an indexer).
|
|
10
6
|
const HELD = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
7
|
+
/**
|
|
8
|
+
* Write a file whole or not at all: a crash mid-write leaves the old one, never a torn one. A
|
|
9
|
+
* file held for a moment is tried again as `writeAtomicSync` does; then the error goes up and
|
|
10
|
+
* the temporary file goes.
|
|
11
|
+
*/
|
|
12
|
+
export async function writeAtomic(file, text, mode) {
|
|
13
|
+
// A name of its own: two writes of one file in this process at once (a thread's files, made
|
|
14
|
+
// by its watcher and by a message) must not share one temporary file.
|
|
15
|
+
const tmp = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
16
|
+
try {
|
|
17
|
+
await writeFile(tmp, text, { mode });
|
|
18
|
+
for (let i = 0;; i++)
|
|
19
|
+
try {
|
|
20
|
+
await rename(tmp, file);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (!HELD.has(e.code ?? '') || i >= 10)
|
|
25
|
+
throw e;
|
|
26
|
+
await sleep(50);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
await rm(tmp, { force: true });
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
11
34
|
/**
|
|
12
35
|
* The same, at once: for state written as it changes, where two writes must not interleave. A
|
|
13
36
|
* file held for a moment is tried again for up to half a second; then the error goes up and the
|
package/dist/server/cli.js
CHANGED
|
@@ -48,8 +48,34 @@ function globalRoots() {
|
|
|
48
48
|
* first line). Anything else is shown as it came.
|
|
49
49
|
*/
|
|
50
50
|
export function briefError(err) {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// The core's machine line is for the board (refusalOf), not for the operator to read.
|
|
52
|
+
const words = err.replace(REFUSAL_LINE, '');
|
|
53
|
+
const m = words.match(/^\w*Error: ([\s\S]*?)\r?\n {4}at /m) ?? words.match(/^\w*Error: (.+)$/m);
|
|
54
|
+
return (m?.[1] ?? words).replaceAll('\r', '').trim();
|
|
55
|
+
}
|
|
56
|
+
const REFUSAL_LINE = /^gcf-refusal: .*(\r?\n)?/gm;
|
|
57
|
+
/**
|
|
58
|
+
* The core's machine refusal in a command's error (core 0.20): its last `gcf-refusal: {…}`
|
|
59
|
+
* line, read as data, never its words. Only `dirty` is known; a path not under `gcf/`, or one
|
|
60
|
+
* climbing out of it, is left out (the edits commands refuse it too). Undefined for an older
|
|
61
|
+
* core, a broken line or no path left.
|
|
62
|
+
*/
|
|
63
|
+
export function refusalOf(err) {
|
|
64
|
+
const last = [...err.matchAll(/^gcf-refusal: (.+?)\r?$/gm)].at(-1)?.[1];
|
|
65
|
+
if (!last)
|
|
66
|
+
return undefined;
|
|
67
|
+
let data;
|
|
68
|
+
try {
|
|
69
|
+
data = JSON.parse(last);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const { code, paths } = (data ?? {});
|
|
75
|
+
if (code !== 'dirty' || !Array.isArray(paths))
|
|
76
|
+
return undefined;
|
|
77
|
+
const kept = paths.filter((x) => typeof x === 'string' && x.startsWith('gcf/') && !x.split('/').includes('..'));
|
|
78
|
+
return kept.length ? { code, paths: kept } : undefined;
|
|
53
79
|
}
|
|
54
80
|
/**
|
|
55
81
|
* Run `ai-factory <args>` in a project; a move can wait up to a minute on gcf's main lock.
|
package/dist/server/events.js
CHANGED
|
@@ -20,6 +20,8 @@ export function subscribe(res) {
|
|
|
20
20
|
clients.add(openStream(res));
|
|
21
21
|
res.on('close', () => clients.delete(res));
|
|
22
22
|
}
|
|
23
|
+
/** Whether a page is open: the usage limits are asked only for one. */
|
|
24
|
+
export const watched = () => clients.size > 0;
|
|
23
25
|
export function broadcast(event) {
|
|
24
26
|
const line = `data: ${JSON.stringify(event)}\n\n`;
|
|
25
27
|
for (const c of clients)
|
package/dist/server/main.js
CHANGED
|
@@ -74,6 +74,8 @@ async function main() {
|
|
|
74
74
|
port,
|
|
75
75
|
web: webDir(),
|
|
76
76
|
version: version(),
|
|
77
|
+
// The usage limits are the threads' agent's: a dev board on the stand-in asks the stand-in.
|
|
78
|
+
usage: process.env.GCF_SESSION_AGENT ?? 'claude',
|
|
77
79
|
});
|
|
78
80
|
app.on('error', async (e) => {
|
|
79
81
|
if (e.code !== 'EADDRINUSE') {
|
package/dist/server/mcp.js
CHANGED
|
@@ -13,7 +13,9 @@ const moves = JSON.parse(readFileSync(process.argv[2], 'utf8'));
|
|
|
13
13
|
const server = new McpServer({ name: 'gcf', version: '1.0.0' });
|
|
14
14
|
for (const [key, spec] of Object.entries(moves))
|
|
15
15
|
server.registerTool(toolOf(key), {
|
|
16
|
-
description:
|
|
16
|
+
description:
|
|
17
|
+
// The key, not the label alone: verdict:kill and decide:kill are both "kill".
|
|
18
|
+
`Propose to the operator: ${spec.label} (the move ${key}). ${spec.help ?? ''} ` +
|
|
17
19
|
'The operator decides; nothing changes until they click.',
|
|
18
20
|
inputSchema: fromJsonSchema(toolSchema(spec)),
|
|
19
21
|
}, async (args) => {
|
package/dist/server/propose.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
+
// The agent's proposals (docs/Session-Engine.md AD-12, AD-36): a tool of the center's MCP server
|
|
2
|
+
// for each domain move with `propose`, `propose_<key>` (`-` and `:` as `_`). Its input schema is
|
|
3
|
+
// built from the move's form: no hidden field, no model or effort, the run's own; a move on an
|
|
4
|
+
// item, an inbox entry or a question also takes its `id`. The schema says what
|
|
5
|
+
// it can (types, choices, lengths, what is always required); `checkProposal` the rest (a field
|
|
6
|
+
// that goes only with another's value, the defaults).
|
|
7
|
+
import { toolOf } from '../shared/board.js';
|
|
8
|
+
export { toolOf };
|
|
1
9
|
/** The fields of a run an agent does not choose: the operator's run settings. */
|
|
2
10
|
const NOT_PROPOSED = new Set(['model', 'effort']);
|
|
3
11
|
const SLUG = '^[a-z0-9]+(-[a-z0-9]+)*$';
|
|
4
12
|
const TAG = '^[a-z0-9][a-z0-9:-]{0,39}$';
|
|
5
|
-
/** The tool's name for a move. */
|
|
6
|
-
export const toolOf = (key) => `propose_${key.replaceAll('-', '_')}`;
|
|
7
13
|
/** The fields an agent may propose: the form's, without the hidden ones and the run's. */
|
|
8
14
|
export const proposed = (spec) => spec.fields.filter((f) => !f.hidden && !NOT_PROPOSED.has(f.key));
|
|
9
15
|
/**
|
|
10
|
-
* Whether a move acts on an item
|
|
11
|
-
* of its own names it): the agent names it in `id`.
|
|
16
|
+
* Whether a move acts on an item, an inbox entry or a question already there (`{id}` in its
|
|
17
|
+
* words, no field of its own names it): the agent names it in `id`.
|
|
12
18
|
*/
|
|
13
19
|
export const targeted = (spec) => spec.args.includes('{id}') && !spec.fields.some((f) => f.key === 'id');
|
|
14
20
|
const TARGET = {
|
|
15
21
|
type: 'string',
|
|
16
22
|
pattern: SLUG,
|
|
17
|
-
description: 'The id of the item it acts on (of the inbox entry
|
|
23
|
+
description: 'The id of the item it acts on (of the inbox entry for an inbox move, of the question for an answer).',
|
|
18
24
|
};
|
|
19
25
|
/** The schema of one field by its kind; every kind has one (`never` holds the switch whole). */
|
|
20
26
|
export function fieldSchema(f) {
|
|
@@ -96,7 +102,7 @@ export function checkProposal(spec, args) {
|
|
|
96
102
|
const problems = [];
|
|
97
103
|
const target = targeted(spec);
|
|
98
104
|
if (target && (typeof args.id !== 'string' || !new RegExp(SLUG).test(args.id)))
|
|
99
|
-
problems.push('id is required: the item
|
|
105
|
+
problems.push('id is required: the item, inbox entry or question it acts on');
|
|
100
106
|
for (const [key, v] of Object.entries(args)) {
|
|
101
107
|
const f = fields.get(key);
|
|
102
108
|
if (target && key === 'id')
|
package/dist/server/registry.js
CHANGED
|
@@ -9,6 +9,8 @@ import { HttpError } from './http-error.js';
|
|
|
9
9
|
/** The board's own directory; GCF_BOARD_HOME moves it (tests, a second board). */
|
|
10
10
|
export const homeDir = () => process.env.GCF_BOARD_HOME ?? path.join(os.homedir(), '.gcf');
|
|
11
11
|
const registryFile = () => path.join(homeDir(), 'projects.json');
|
|
12
|
+
/** The operator's YOLO for every thread of this board's machine: on while the file exists (AD-54). */
|
|
13
|
+
export const yoloFile = () => path.join(homeDir(), 'chat-yolo');
|
|
12
14
|
const NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
13
15
|
export async function listProjects() {
|
|
14
16
|
if (!existsSync(registryFile()))
|
package/dist/server/relay.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// code, stdout and stderr go to the end file once, whole, when it ends. While it runs, the relay
|
|
7
7
|
// touches the record: a board started again tells it from a dead relay whose pid another took.
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
|
-
import {
|
|
9
|
+
import { utimesSync, writeFileSync } from 'node:fs';
|
|
10
10
|
import { writeAtomic } from './atomic.js';
|
|
11
11
|
// A board that finds the run at its start counts the relay dead after three missed beats
|
|
12
12
|
// (BEAT_STALE_MS in runs.ts).
|
|
@@ -40,11 +40,7 @@ const finish = (code, message = '') => {
|
|
|
40
40
|
done = true;
|
|
41
41
|
const text = JSON.stringify({ code, out, err: err + message });
|
|
42
42
|
// A rename a scanner holds up: the end still goes, written in place.
|
|
43
|
-
writeAtomic(end, text).catch(() =>
|
|
44
|
-
writeFileSync(end, text);
|
|
45
|
-
// writeAtomic's own temporary file, left by the rename that failed.
|
|
46
|
-
rmSync(`${end}.${process.pid}.tmp`, { force: true });
|
|
47
|
-
});
|
|
43
|
+
writeAtomic(end, text).catch(() => writeFileSync(end, text));
|
|
48
44
|
};
|
|
49
45
|
child.on('error', (e) => finish(null, e.message));
|
|
50
46
|
child.on('close', (code) => finish(code));
|
package/dist/server/runs.js
CHANGED
|
@@ -16,6 +16,7 @@ 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';
|
|
19
|
+
import { askUsage } from './usage.js';
|
|
19
20
|
// The source runs relay.ts, the package its build beside this file.
|
|
20
21
|
const RELAY = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? 'relay.ts' : 'relay.js', import.meta.url));
|
|
21
22
|
const flightsDir = () => path.join(homeDir(), 'runs');
|
|
@@ -472,6 +473,8 @@ function land(q, run, rid, live, message = '') {
|
|
|
472
473
|
// Held by a scanner: its id is no other run's, so it only stays behind.
|
|
473
474
|
}
|
|
474
475
|
active.delete(run);
|
|
476
|
+
// A run spent some of the limit: the bar reads it again.
|
|
477
|
+
void askUsage();
|
|
475
478
|
const { p, ids, mode } = q;
|
|
476
479
|
const ok = end?.code === 0;
|
|
477
480
|
const result = harnessReport(end?.out ?? '');
|