gcf-board 0.6.0 → 0.8.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/README.md +11 -8
- package/dist/server/app.js +36 -1
- package/dist/server/chat.js +29 -1
- package/dist/server/runs.js +5 -5
- package/dist/server/talks.js +110 -14
- package/dist/web/assets/golos-text-cyrillic-ext-wght-normal-hICkpzq7.woff2 +0 -0
- package/dist/web/assets/golos-text-cyrillic-wght-normal-mKek_fSS.woff2 +0 -0
- package/dist/web/assets/golos-text-latin-ext-wght-normal-B-I5lbAQ.woff2 +0 -0
- package/dist/web/assets/golos-text-latin-wght-normal-BS5oQT7X.woff2 +0 -0
- package/dist/web/assets/index-C56_xyF9.js +39 -0
- package/dist/web/assets/index-D0-5TaR1.css +1 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/adapter/claude.js +13 -0
- package/node_modules/gcf-session/lib/adapter/index.js +6 -0
- package/node_modules/gcf-session/lib/chat.js +10 -3
- package/node_modules/gcf-session/lib/cli.js +2 -0
- package/node_modules/gcf-session/lib/index.js +4 -1
- package/node_modules/gcf-session/lib/job.js +25 -3
- package/node_modules/gcf-session/lib/session.js +33 -6
- package/node_modules/gcf-session/lib/thread.js +147 -25
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +31 -2
- package/package.json +3 -1
- package/dist/web/assets/index-BYAEKw51.css +0 -1
- package/dist/web/assets/index-D_F7OEyk.js +0 -36
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ 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.10 (`gcf board --json` with `schema: 3`: the columns, the moves, the item's fields, the blocks and the Help terms come from it as data)
|
|
9
|
-
- for runs: [`gcf-harness-aif-ext`](../gcf-harness-aif-ext) ≥ 0.11 (every board run opens its chat: `--chat`,
|
|
9
|
+
- for runs: [`gcf-harness-aif-ext`](../gcf-harness-aif-ext) ≥ 0.11 (every board run opens its chat: `--chat`, `gcf-harness chat`; it waits the project's answer time) and Claude Code (`claude -p`); ≥ 0.12 to wait for the usage limit's reset and for queued runs (`--wait-limit`)
|
|
10
10
|
- for the project chat: `gcf-aif-ext` ≥ 0.12 (`domain.chat`, `agent.rules`) and Claude Code
|
|
11
11
|
- gcf-board 0.2 needs `gcf-aif-ext` ≥ 0.7 (priority, questions, session marks, `run_mode`)
|
|
12
12
|
|
|
@@ -31,8 +31,9 @@ It puts **GCF Board** on the desktop (Windows: a shortcut whose server console s
|
|
|
31
31
|
|
|
32
32
|
## What it does
|
|
33
33
|
|
|
34
|
-
The board knows no domain by name: the project's board read gives its columns, moves with their forms, item fields, blocks and Help terms (`domain`, Board-PRD decision 16). For a GCF project:
|
|
34
|
+
The board knows no domain by name: the project's board read gives its columns, moves with their forms, item fields, blocks and Help terms (`domain`, Board-PRD decision 16). The page follows design B (`docs/design/mockup`): a left nav with the project switcher (add a project, take one off the board), the screens **Command**, **Board**, **Chat**, **Inbox**, **Playtest**, **Ended**, **Agent**, **Settings** and **Metrics** (a domain without a block has no screen for it, a project without a harness no Metrics), and a header with the phase, the runs, the limit wait, the quota, WIP, the release, **waiting for me**, **+ item** and **?**. The project and the screen are in the URL hash. On a phone a bottom bar holds Command, Board, Chat, Inbox and More. When the server is gone, the page says so and reconnects by itself. For a GCF project:
|
|
35
35
|
|
|
36
|
+
- **Command**: **waiting for me**, what only the operator moves on (Board-PRD §1.3), by group: failed run reports and a paused queue, a card waiting in a chat (a permission is answered right there, **Always** naming the rule it saves), D1 questions, the items to play and judge, to decide, to unblock (the columns the domain marks `human`), and a `paused: limit` item to resume. Beside it **Live**: the runs going on with their plan progress, **Follow** and **Stop**, the console runs and sessions, **Run next**, the queue, the run reports, and what the board did by itself.
|
|
36
37
|
- **Board**: columns ready, running, blocked, awaiting-verdict, awaiting-decision, unplayed, parked. A card shows the type, the gate, the plan progress (`2/5`), the severity, `verified`, the model. A running card shows when its run log was last written (`active 12 s ago`), and `quiet 6 min` when the log has been silent for 5 minutes or more. A run's end report gives each item's cost when the agent reported it.
|
|
37
38
|
- **An item**: its file, its plan and its run log as it grows, its fields, and the moves the core offers for it (`items[].moves`, Methodology §4.1): run, verdict, decide, block, unblock, drop, close, submit, depends. Each move's form comes from the core; the core still checks the rest itself, and the board shows its answer.
|
|
38
39
|
- **Drag**:
|
|
@@ -45,17 +46,19 @@ The board knows no domain by name: the project's board read gives its columns, m
|
|
|
45
46
|
- `run_mode: worktree`: one worktree and one agent session per item, all at once, then the integrator;
|
|
46
47
|
- `run_mode: main`: one item at a time in the project folder. A run asked for meanwhile waits in the board's **queue**; **remove from queue** takes it out.
|
|
47
48
|
|
|
48
|
-
A run asks first: it spends the subscription. **Stop** on a running item ends its session; the item stays ready and its work is kept. A queued main run that the next one would repeat (the harness did not start, or another run works the checkout) pauses the queue: the header shows **queue paused — resume**; fix the cause, then resume. A card marked **interrupted** had a run that stopped (a timeout, a stop, a crash, the usage limit): **resume** continues its agent session with all its context, **start fresh** drops it. After the usage limit the run itself waits for the reset and goes on in the same session (harness 0.12): the card reads **limit: resumes HH:MM**, and **Stop** ends the wait. A run that could not wait (the week's limit, an unknown reset) ends **paused: limit** and pauses the main queue; **resume** on the header goes on after the reset. When a run ends, a report card lists each item's result and stays until closed, across page reloads. **What the board did by itself** lists its automatic acts with their times: a usage limit, a context handoff, the queue paused, resumed or started. A run confirmation names what each interrupted item picks up. The header shows the usage limit as the last run read it, from the newest `.gcf-session/runs/quota.json` of the board's projects: `quota 19% left · resets 03:00`, the window with the least left, every window in its tooltip; `quota ?` before any reading, or once every window has reset since. The queue, the reports and that list live in the board's memory: a board restart forgets them. A run itself outlives the board: closing it or Ctrl+C in its console leaves the run going, and the board started again shows it running, then its report (a run in flight keeps its record in `~/.gcf/runs/`).
|
|
49
|
+
A run asks first: it spends the subscription. **Stop** on a running item ends its session; the item stays ready and its work is kept. **Stop** during the wait for the usage limit's reset leaves the item **paused: limit** with its reset, and the queue goes on. A queued main run that the next one would repeat (the harness did not start, or another run works the checkout) pauses the queue: the header shows **queue paused — resume**; fix the cause, then resume. A card marked **interrupted** had a run that stopped (a timeout, a stop, a crash, the usage limit): **resume** continues its agent session with all its context, **start fresh** drops it. After the usage limit the run itself waits for the reset and goes on in the same session (harness 0.12): the card reads **limit: resumes HH:MM**, and **Stop** ends the wait. A run that could not wait (the week's limit, an unknown reset) ends **paused: limit** and pauses the main queue; **resume** on the header goes on after the reset. When a run ends, a report card lists each item's result and stays until closed, across page reloads. **What the board did by itself** lists its automatic acts with their times: a usage limit, a context handoff, the queue paused, resumed or started. A run confirmation names what each interrupted item picks up. The header shows the usage limit as the last run read it, from the newest `.gcf-session/runs/quota.json` of the board's projects: `quota 19% left · resets 03:00`, the window with the least left, every window in its tooltip; `quota ?` before any reading, or once every window has reset since. The queue, the reports and that list live in the board's memory: a board restart forgets them. A run itself outlives the board: closing it or Ctrl+C in its console leaves the run going, and the board started again shows it running, then its report (a run in flight keeps its record in `~/.gcf/runs/`).
|
|
49
50
|
- **Who runs it** (core 0.7.13): a running card tells a console run and **your session** (a `gcf claim` mark) from the board's own run; a session offers **release mark** instead of **stop**. A ready card whose dependencies are not built yet shows **waits for <dep>**; the drawer shows when an item began to wait (`since_at`).
|
|
50
51
|
- **Run next N independent**: the framework's gate picks the ready items that can run together now, by priority, and the board runs them after asking.
|
|
51
52
|
- **Priority**: drop a ready card on another to put it before; the column's ranks are committed (`gcf prioritize`).
|
|
52
53
|
- **Questions**: each D1 shows its question and proposed answer; **Answer** writes yours into its record (`gcf question answer`), and the next agent on its units puts it in place.
|
|
53
54
|
- **New item**: `gcf item new … --commit`, its form from the core: a bug asks its severity, a release its version and channel. The item's `model` and `effort` go to its run.
|
|
54
55
|
- **Help** (**?**): the domain's terms, columns, moves and field values with what each means, and the words of runs, under one filter.
|
|
55
|
-
- **Settings**: the keys of `gcf/config.yml` and the agents' language (`language.ui`, `language.artifacts` of `.ai-factory/config.yaml`), each a `gcf config set` commit.
|
|
56
|
-
- **
|
|
57
|
-
- **
|
|
58
|
-
- **
|
|
56
|
+
- **Settings**: the keys of `gcf/config.yml` and the agents' language (`language.ui`, `language.artifacts` of `.ai-factory/config.yaml`), by the core's groups, each a `gcf config set` commit.
|
|
57
|
+
- **Agent**: the deny groups to tick, the rules the ticked groups add, the operator's own deny rules (add, remove) and the allow rules of `agent.allow`, apart; the context limits, read only.
|
|
58
|
+
- **An item's chat** (its drawer's **Chat** tab; harness 0.11.1, core 0.11.1): every run the board starts keeps its agent sessions open; the project's `chat:` settings (Settings: `chat.ask`, `chat.answer_timeout_min`) say what the agent asks and how long a question waits. The tab shows the run's chat, then the item's own thread of the project chat: the talk, question cards (picks, several questions, **Submit**), the run's milestones, its sessions, the limit wait, the context share. A message goes where the server puts it: the live run (its limit wait too), else the item's thread, and the line under the box says where it went. `GET /api/p/<project>/chat/<id>` follows the item's chat from its start, in raw chunks of JSON lines (the page splits them). `POST` there sends `{type: 'say', text, images?, attach?}`, `{type: 'interrupt'}` or `{type: 'answer', request_id, answers}` through `gcf-harness chat`; with no live run a message goes to the item's thread (answer `{talk}`), else a message with no session to read it gets 409, bad input 400. `attach` (`[{kind: item | file, ref}]`) goes into the message's text as a line the agent reads. `GET /api/p/<project>/chat/<id>/att/<file>` serves a chat picture; **attach to item…** under a picture gives it to an item (`gcf item attach`).
|
|
59
|
+
- **Model and effort** (board 0.8.0, core 0.12.3): pickers in the New item form, in the drawer (**change** beside the model and effort, and **model / effort** under **More**) and in a thread's composer: **default** (the agent picks), the agent's presets, or an own word. An item's next run takes them; a thread's next session does (`chats/<t>/agent.json`), and its line in the chat says so.
|
|
60
|
+
- **Project chat** (the **Chat** screen; core 0.12): threads of an agent in the project's folder, listed newest first and filtered by their item; a new thread is made when its first message is sent. Each thread is run by the bundled session engine (`gcf-session`) through the same detached relay as runs. It asks a card before each edit, git command and framework move (**allow once**, **always** — saved in `.claude/settings.local.json`; the card says saved only when it was — or **deny**); a new item it proposes through the board's MCP server `gcf` (tool `propose_item_new`, asked with no card: the proposal card is the question), the proposal card shows every field it proposed, and the operator's **Create** makes it with `POST /move` (`proposal: {talk, id}`), **Edit…** first in the new-item form. A thread's list entry names the card that waits in it and its limit wait (`card`, `limit_until`); a running item names the card of its run's chat (`chat_card`). A long talk hands over to a fresh agent from a summary; an idle agent closes after `chat.answer_timeout_min` (0 means 15) and the next message resumes it. Each item has at most one thread: a message to an item with no live run goes there. `GET /api/p/<project>/talks[?item=]` lists the threads with their proposals' states; `POST` there makes one (`{item?}`); `GET /api/p/<project>/talk/<t>` follows a thread's events; `POST` there sends `say`, `interrupt`, `answer`, `allow`, `deny` or `handoff`; `POST …/talk/<t>/stop` is the composer's **close agent** (board 0.8.1): the thread's agent ends with everything it started, or its limit wait does, and what it had not taken in is dropped with a "not sent" line; the next message resumes the talk; `GET …/talk/<t>/att/<file>` serves its pictures. The files live in `.gcf-session/chats/` (docs/Chat-Plan.md §3).
|
|
61
|
+
- **Inbox**: add an entry (Enter adds, Shift+Enter breaks the line; its source and tags), tag it, erase it, or turn it into an item (its first line the title, the rest the note); search the entries, filter them by tag and by lesson kind. The D1 questions and the agent's D2 assumptions are listed there too.
|
|
59
62
|
- **Lessons** (core 0.7.10, harness 0.9.2): what got in an agent's way, asked at the end of each session, lands in the inbox with its kind (`tool`, `rules`, `framework`, `template`, `other`) and its item. The inbox filters them; a card shows `N lessons`, and the drawer lists the item's lessons with the inbox's buttons. A run's report line ends with `, N lessons`, and with `— code written outside aif-implement` when a session skipped that skill.
|
|
60
63
|
- **Playtest**: `gcf playtest session` with the checklist grouped by subsystem; keep, tune or kill each item from the list. **Build** runs `dod.build`. A note goes to the inbox as `--source playtest`.
|
|
61
64
|
- **Ended**: history (accepted) and graveyard (killed, dropped, won't-fix).
|
|
@@ -87,7 +90,7 @@ Do not put the port on a network. Remote and phone access is planned for v2, beh
|
|
|
87
90
|
|
|
88
91
|
## Roadmap (v2)
|
|
89
92
|
|
|
90
|
-
- **The chat
|
|
93
|
+
- **The chat**: a design unit picked by name as a message's attachment (today a project path).
|
|
91
94
|
- **Phone and remote access**: Tailscale or Claude Remote Control, with their own authentication; push notifications when an item blocks or waits for a verdict.
|
|
92
95
|
|
|
93
96
|
## Develop
|
package/dist/server/app.js
CHANGED
|
@@ -19,7 +19,7 @@ import { HttpError } from './http-error.js';
|
|
|
19
19
|
import { isCenterMove, moveArgs, moveInput, runIds } from './moves.js';
|
|
20
20
|
import { addProject, listProjects, projectOf, removeProject } from './registry.js';
|
|
21
21
|
import { adoptRuns, closeReport, forgetProject, resumeQueue, runsOf, startRun, unqueue, } from './runs.js';
|
|
22
|
-
import { acceptProposal, chatOf, listTalks, openTalk, prepareTalk, startTalk, talkId, talkLive, talkWaits, watchTalks, writeTalk, } from './talks.js';
|
|
22
|
+
import { acceptProposal, agentPresets, chatCard, chatOf, listTalks, openTalk, pickTalk, prepareTalk, startTalk, stopTalk, talkId, talkLive, talkWaits, watchTalks, writeTalk, } from './talks.js';
|
|
23
23
|
import { threadDir } from 'gcf-session';
|
|
24
24
|
const send = (res, status, body) => {
|
|
25
25
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
|
|
@@ -235,6 +235,7 @@ export function createApp(o) {
|
|
|
235
235
|
plans_rev: planRev(p.name),
|
|
236
236
|
board_version: o.version,
|
|
237
237
|
quota: await lastQuota(),
|
|
238
|
+
presets: agentPresets(),
|
|
238
239
|
};
|
|
239
240
|
const board = await boardOf(p);
|
|
240
241
|
// A running item's last log write tells a working session from a stuck one; a run's
|
|
@@ -243,6 +244,11 @@ export function createApp(o) {
|
|
|
243
244
|
for (const i of board.items) {
|
|
244
245
|
if (i.running)
|
|
245
246
|
i.active_at = i.log ? activeAt(path.join(p.path, i.log)) : null;
|
|
247
|
+
// A card waits in its run's chat: it is in "waiting for me" (Board-PRD §1.3).
|
|
248
|
+
if (i.running) {
|
|
249
|
+
const chat = path.join(p.path, '.gcf-session', 'runs', `${i.id}.chat.jsonl`);
|
|
250
|
+
i.chat_card = chatCard(chat);
|
|
251
|
+
}
|
|
246
252
|
if (i.running_kind === 'run')
|
|
247
253
|
i.running_kind = mine.has(i.id) ? 'board' : 'console';
|
|
248
254
|
}
|
|
@@ -405,6 +411,35 @@ export function createApp(o) {
|
|
|
405
411
|
send(res, 202, { ok: true, ...(typeof line.id === 'string' ? { id: line.id } : {}) });
|
|
406
412
|
},
|
|
407
413
|
],
|
|
414
|
+
[
|
|
415
|
+
// Close a thread's agent with all it started (AD-52); the board hears its end by its files.
|
|
416
|
+
'POST',
|
|
417
|
+
/^\/api\/p\/([^/]+)\/talk\/([^/]+)\/stop$/,
|
|
418
|
+
async (_req, res, m) => {
|
|
419
|
+
const p = await projectOf(m[1]);
|
|
420
|
+
const t = talkId(m[2]);
|
|
421
|
+
if (!existsSync(threadDir(p.path, t)))
|
|
422
|
+
throw new HttpError(404, `no thread ${t}`);
|
|
423
|
+
if (!talkLive(p, t))
|
|
424
|
+
throw new HttpError(409, `thread ${t} has no live agent to close`);
|
|
425
|
+
stopTalk(p, t);
|
|
426
|
+
send(res, 202, { ok: true });
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
// The model and effort of a thread's next sessions (Board-PRD decision 24).
|
|
431
|
+
'POST',
|
|
432
|
+
/^\/api\/p\/([^/]+)\/talk\/([^/]+)\/agent$/,
|
|
433
|
+
async (req, res, m) => {
|
|
434
|
+
const p = await projectOf(m[1]);
|
|
435
|
+
const t = talkId(m[2]);
|
|
436
|
+
if (!existsSync(threadDir(p.path, t)))
|
|
437
|
+
throw new HttpError(404, `no thread ${t}`);
|
|
438
|
+
const pick = pickTalk(p, t, await bodyOf(req));
|
|
439
|
+
broadcast({ type: 'talks', project: p.name });
|
|
440
|
+
send(res, 200, { ok: true, ...pick });
|
|
441
|
+
},
|
|
442
|
+
],
|
|
408
443
|
[
|
|
409
444
|
// A picture of a thread (`att/`, where the board put it); never through a link.
|
|
410
445
|
'GET',
|
package/dist/server/chat.js
CHANGED
|
@@ -28,12 +28,40 @@ function images(v) {
|
|
|
28
28
|
return { media_type: type, data };
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
const SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
32
|
+
/**
|
|
33
|
+
* What a message attaches (Round2-review §3): an item, a file of the project. They go into the
|
|
34
|
+
* message's text, as a line the agent reads: it opens them itself.
|
|
35
|
+
*/
|
|
36
|
+
function attachLine(v) {
|
|
37
|
+
if (v === undefined)
|
|
38
|
+
return '';
|
|
39
|
+
if (!Array.isArray(v) || v.length > 10)
|
|
40
|
+
throw bad('attach is a list of up to 10');
|
|
41
|
+
const refs = v.map((a) => {
|
|
42
|
+
const { kind, ref } = (a ?? {});
|
|
43
|
+
if (kind === 'item' && typeof ref === 'string' && SLUG.test(ref))
|
|
44
|
+
return `item ${ref} (gcf/work/${ref}.md)`;
|
|
45
|
+
// A project path, as the operator names it: relative, inside the project, nothing a shell
|
|
46
|
+
// would expand (`~`, `%VAR%`, `$VAR`) and no drive or scheme (`:`).
|
|
47
|
+
const file = typeof ref === 'string' ? ref.trim() : '';
|
|
48
|
+
if (kind === 'file' &&
|
|
49
|
+
file &&
|
|
50
|
+
file.length <= 300 &&
|
|
51
|
+
!/^[\\/~]/.test(file) &&
|
|
52
|
+
!/[:%$]/.test(file) &&
|
|
53
|
+
!file.split(/[\\/]/).some((part) => part.trim() === '..'))
|
|
54
|
+
return `file ${file}`;
|
|
55
|
+
throw bad('an attachment is {kind: item, ref: <id>} or {kind: file, ref: <project path>}');
|
|
56
|
+
});
|
|
57
|
+
return refs.length ? `\n\n[attached: ${refs.join('; ')}]` : '';
|
|
58
|
+
}
|
|
31
59
|
/** The line a request writes into the chat input: a message, a stop of the step, an answer. */
|
|
32
60
|
export function chatInput(body) {
|
|
33
61
|
if (body.type === 'interrupt')
|
|
34
62
|
return { type: 'interrupt' };
|
|
35
63
|
if (body.type === 'say') {
|
|
36
|
-
const
|
|
64
|
+
const text = typeof body.text === 'string' ? body.text + attachLine(body.attach) : body.text;
|
|
37
65
|
if (typeof text !== 'string' || !text.trim() || text.length > TEXT_MAX)
|
|
38
66
|
throw bad(`a message is text, up to ${TEXT_MAX} characters`);
|
|
39
67
|
const list = images(body.images);
|
package/dist/server/runs.js
CHANGED
|
@@ -173,11 +173,11 @@ function spawnRun(q, mode) {
|
|
|
173
173
|
args.push('--fresh');
|
|
174
174
|
if (q.waitLimit)
|
|
175
175
|
args.push('--wait-limit');
|
|
176
|
-
// A board's run is always open to the operator: its chat
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
// A board's run is always open to the operator: its chat waits the project's answer time
|
|
177
|
+
// (`chat.answer_timeout_min`), which the harness reads. GCF_BOARD_CHAT_TIMEOUT: the tests'.
|
|
178
|
+
args.push('--chat');
|
|
179
|
+
if (process.env.GCF_BOARD_CHAT_TIMEOUT)
|
|
180
|
+
args.push('--chat-timeout', process.env.GCF_BOARD_CHAT_TIMEOUT);
|
|
181
181
|
const rid = randomUUID();
|
|
182
182
|
const relay = spawn(process.execPath, [RELAY, recordOf(rid), endOf(rid), ...args], {
|
|
183
183
|
cwd: p.path,
|
package/dist/server/talks.js
CHANGED
|
@@ -11,7 +11,7 @@ import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, statSyn
|
|
|
11
11
|
import os from 'node:os';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { THREAD_ID, createThread, listThreads, readThread, threadDir, threadOf, } from 'gcf-session';
|
|
14
|
+
import { THREAD_ID, createThread, listThreads, presetsOf, readThread, setThreadAgent, threadAgent, threadDir, threadOf, } from 'gcf-session';
|
|
15
15
|
import { writeAtomic } from './atomic.js';
|
|
16
16
|
import { alive } from './events.js';
|
|
17
17
|
import { HttpError } from './http-error.js';
|
|
@@ -30,6 +30,31 @@ const ASK = [
|
|
|
30
30
|
{ kind: 'edit', pattern: '' },
|
|
31
31
|
{ kind: 'shell', pattern: 'git *' },
|
|
32
32
|
];
|
|
33
|
+
/** What the operator picks a model and effort from: the agent's presets (Board-PRD decision 24). */
|
|
34
|
+
export const agentPresets = () => presetsOf(process.env.GCF_SESSION_AGENT ?? DEFAULT_AGENT);
|
|
35
|
+
/**
|
|
36
|
+
* Pick thread `t`'s model and effort (`default` or none: the agent's own); its next session
|
|
37
|
+
* takes them. A word that is not plain is a 400.
|
|
38
|
+
*/
|
|
39
|
+
export function pickTalk(p, t, body) {
|
|
40
|
+
writeDir(p, t);
|
|
41
|
+
const pick = {};
|
|
42
|
+
for (const k of ['model', 'effort']) {
|
|
43
|
+
const v = body[k];
|
|
44
|
+
if (v !== undefined && v !== null && typeof v !== 'string')
|
|
45
|
+
throw new HttpError(400, `${k} must be text`);
|
|
46
|
+
pick[k] = v;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return setThreadAgent(p.path, t, pick);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
// The engine's word check; a failed write is the server's own.
|
|
53
|
+
if (e instanceof RangeError)
|
|
54
|
+
throw new HttpError(400, e.message);
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
33
58
|
/** A thread's id, or a 404. */
|
|
34
59
|
export function talkId(t) {
|
|
35
60
|
if (!THREAD_ID.test(t))
|
|
@@ -96,7 +121,9 @@ export function talkSpec(p, board, mcp) {
|
|
|
96
121
|
rules: {
|
|
97
122
|
deny: [...rules.deny, { kind: 'edit', pattern: '.gcf-session/**' }, ...homeRules()],
|
|
98
123
|
ask: [...ASK, ...chat.confirm],
|
|
99
|
-
|
|
124
|
+
// The center's own MCP server only proposes: the proposal card's Create is the
|
|
125
|
+
// operator's say, so the call asks no permission card before it.
|
|
126
|
+
allow: [{ kind: 'mcp', pattern: 'gcf' }],
|
|
100
127
|
},
|
|
101
128
|
mcp: [mcp],
|
|
102
129
|
answerMin: board.chat?.answer_timeout_min,
|
|
@@ -194,9 +221,12 @@ export async function prepareTalk(p, board, t) {
|
|
|
194
221
|
await writeAtomic(path.join(td, 'context.md'), contextOf(p, board, readThread(p.path, t).item));
|
|
195
222
|
await writeAtomic(path.join(td, 'spec.json'), `${JSON.stringify(spec, null, 2)}\n`);
|
|
196
223
|
}
|
|
197
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Whether thread `t` waits for the usage limit's reset: its last session event is `limit`, not
|
|
226
|
+
* the operator's close after it.
|
|
227
|
+
*/
|
|
198
228
|
export function talkWaits(p, t) {
|
|
199
|
-
const last = eventsOf(dirOf(p, t)).findLast((e) => ['session', 'session_end', 'limit'].includes(e.type));
|
|
229
|
+
const last = eventsOf(dirOf(p, t)).findLast((e) => ['session', 'session_end', 'limit', 'closed'].includes(e.type));
|
|
200
230
|
return last?.type === 'limit';
|
|
201
231
|
}
|
|
202
232
|
/** Whether a session of thread `t` lives: its `open` holds the thread's lock. */
|
|
@@ -258,11 +288,45 @@ export function writeTalk(p, t, input) {
|
|
|
258
288
|
appendFileSync(path.join(td, 'chat-in.jsonl'), `${JSON.stringify(line)}\n`);
|
|
259
289
|
return line;
|
|
260
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Close thread `t`'s agent with all it started, or end its wait for the limit (AD-52): the
|
|
293
|
+
* engine's stop mark. A mark the engine never reads (it ended meanwhile) goes at its next open.
|
|
294
|
+
*/
|
|
295
|
+
export function stopTalk(p, t) {
|
|
296
|
+
const stop = path.join(writeDir(p, t), 'stop');
|
|
297
|
+
if (existsSync(stop) && lstatSync(stop).isSymbolicLink())
|
|
298
|
+
throw new HttpError(400, `${t}'s stop mark goes through a link: refused`);
|
|
299
|
+
writeFileSync(stop, '');
|
|
300
|
+
}
|
|
261
301
|
/** A thread's chat events; a line that is not one is skipped. */
|
|
262
302
|
function eventsOf(td) {
|
|
303
|
+
return chatEvents(path.join(td, 'chat.jsonl'));
|
|
304
|
+
}
|
|
305
|
+
// A run's chat holds every run of its item and grows: its card is read again only when the
|
|
306
|
+
// file changed.
|
|
307
|
+
const cards = new Map();
|
|
308
|
+
/** The card that waits in a run's chat file (`<id>.chat.jsonl`), or null. */
|
|
309
|
+
export function chatCard(file) {
|
|
310
|
+
let stamp = '';
|
|
311
|
+
try {
|
|
312
|
+
const st = statSync(file);
|
|
313
|
+
stamp = `${st.mtimeMs}:${st.size}`;
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const kept = cards.get(file);
|
|
319
|
+
if (kept?.stamp === stamp)
|
|
320
|
+
return kept.card;
|
|
321
|
+
const card = cardIn(chatEvents(file));
|
|
322
|
+
cards.set(file, { stamp, card });
|
|
323
|
+
return card;
|
|
324
|
+
}
|
|
325
|
+
/** The events of a chat file: a thread's, or a run's `<id>.chat.jsonl`; none without one. */
|
|
326
|
+
export function chatEvents(file) {
|
|
263
327
|
let text = '';
|
|
264
328
|
try {
|
|
265
|
-
text = readFileSync(
|
|
329
|
+
text = readFileSync(file, 'utf8');
|
|
266
330
|
}
|
|
267
331
|
catch {
|
|
268
332
|
return [];
|
|
@@ -374,18 +438,41 @@ async function proposalsOf(td, events, ids) {
|
|
|
374
438
|
}
|
|
375
439
|
return out;
|
|
376
440
|
}
|
|
377
|
-
/**
|
|
378
|
-
function
|
|
379
|
-
const open = new
|
|
441
|
+
/** The card that waits for the operator: an approval or a question nobody answered, withdrew or let time out. */
|
|
442
|
+
export function cardIn(events) {
|
|
443
|
+
const open = new Map();
|
|
380
444
|
for (const e of events) {
|
|
381
|
-
if (e.type === 'approval'
|
|
382
|
-
open.
|
|
383
|
-
|
|
445
|
+
if (e.type === 'approval')
|
|
446
|
+
open.set(e.request_id, {
|
|
447
|
+
request_id: e.request_id,
|
|
448
|
+
kind: 'approval',
|
|
449
|
+
text: e.title,
|
|
450
|
+
at: e.at,
|
|
451
|
+
tool: e.tool,
|
|
452
|
+
...(e.reason ? { reason: e.reason } : {}),
|
|
453
|
+
...(e.always ? { always: e.always } : {}),
|
|
454
|
+
});
|
|
455
|
+
else if (e.type === 'question')
|
|
456
|
+
open.set(e.request_id, {
|
|
457
|
+
request_id: e.request_id,
|
|
458
|
+
kind: 'question',
|
|
459
|
+
text: e.questions.map((q) => q.question).join(' · '),
|
|
460
|
+
at: e.at,
|
|
461
|
+
});
|
|
462
|
+
// A new session never holds an older one's card: one killed with a card open left it.
|
|
463
|
+
else if (e.type === 'session' ||
|
|
464
|
+
e.type === 'session_end' ||
|
|
465
|
+
(e.type === 'timeout' && e.kind === 'card'))
|
|
384
466
|
open.clear();
|
|
385
467
|
else if ('request_id' in e && e.request_id)
|
|
386
468
|
open.delete(e.request_id);
|
|
387
469
|
}
|
|
388
|
-
return open.
|
|
470
|
+
return [...open.values()][0] ?? null;
|
|
471
|
+
}
|
|
472
|
+
/** When a thread's agent wakes after the usage limit: its last session event is the wait. */
|
|
473
|
+
export function limitIn(events) {
|
|
474
|
+
const last = events.findLast((e) => e.type === 'limit' || e.type === 'session' || e.type === 'closed');
|
|
475
|
+
return last?.type === 'limit' ? last.until : null;
|
|
389
476
|
}
|
|
390
477
|
/** The text of the operator's first message to a thread, as written; null before one. */
|
|
391
478
|
function sayOf(td) {
|
|
@@ -414,6 +501,10 @@ async function talkOf(p, th, ids) {
|
|
|
414
501
|
const events = eventsOf(td);
|
|
415
502
|
const first = sayOf(td);
|
|
416
503
|
const title = first ? first.trim().split('\n')[0].slice(0, 120) : null;
|
|
504
|
+
const live = talkLive(p, th.id);
|
|
505
|
+
// A dead engine's card went with it: no one takes its answer (a new session drops it too).
|
|
506
|
+
const card = live ? cardIn(events) : null;
|
|
507
|
+
const pick = threadAgent(p.path, th.id);
|
|
417
508
|
const cost = events.reduce((sum, e) => sum + (e.type === 'session_end' ? (e.cost_usd ?? 0) : 0), 0);
|
|
418
509
|
return {
|
|
419
510
|
id: th.id,
|
|
@@ -422,8 +513,13 @@ async function talkOf(p, th, ids) {
|
|
|
422
513
|
created_at: th.created_at,
|
|
423
514
|
last_at: events.at(-1)?.at ?? null,
|
|
424
515
|
cost_usd: Math.round(cost * 100) / 100,
|
|
425
|
-
|
|
426
|
-
|
|
516
|
+
model: pick.model ?? null,
|
|
517
|
+
effort: pick.effort ?? null,
|
|
518
|
+
live,
|
|
519
|
+
waiting: Boolean(card),
|
|
520
|
+
card,
|
|
521
|
+
// A thread whose engine died during the wait waits for nothing.
|
|
522
|
+
limit_until: live ? limitIn(events) : null,
|
|
427
523
|
proposals: await proposalsOf(td, events, ids),
|
|
428
524
|
};
|
|
429
525
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|