gcf-board 0.27.0 → 0.28.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 +2 -2
- package/dist/server/app.js +26 -9
- package/dist/server/chat.js +27 -1
- package/dist/server/cli.js +6 -2
- package/dist/server/desktop.js +1 -0
- package/dist/server/runs.js +34 -4
- package/dist/server/talks.js +24 -16
- package/dist/shared/board.js +45 -0
- package/dist/web/assets/index-BHNTx9zd.css +1 -0
- package/dist/web/assets/index-UBIHpB-m.js +119 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/chat.js +34 -16
- package/node_modules/gcf-session/lib/proc.js +5 -1
- package/node_modules/gcf-session/lib/session.js +39 -19
- package/node_modules/gcf-session/lib/store.js +14 -9
- package/node_modules/gcf-session/lib/thread.js +9 -3
- package/node_modules/gcf-session/lib/usage.js +12 -1
- package/node_modules/gcf-session/package.json +1 -1
- package/package.json +2 -2
- package/dist/web/assets/index-BCfiz95-.css +0 -1
- package/dist/web/assets/index-Ds32enMs.js +0 -116
package/dist/web/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>GCF board</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-UBIHpB-m.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BHNTx9zd.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
|
@@ -100,6 +100,9 @@ function refusedBy(deny, call) {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/** A call's error text when a deny rule refused it: a path rule's, or a command rule's. */
|
|
104
|
+
const DENIED_TEXT = /denied by your permission settings|Permission to use .+ has been denied/;
|
|
105
|
+
|
|
103
106
|
/** How long a question waits for the operator when neither the flag nor the config says. */
|
|
104
107
|
export const CHAT_TIMEOUT_MIN = 15;
|
|
105
108
|
|
|
@@ -852,6 +855,9 @@ const SEEN = {
|
|
|
852
855
|
// stays out of the chat. The session's rule that holds for it, and the rule's group, say what
|
|
853
856
|
// refused it (refusedBy).
|
|
854
857
|
refused: (c, e) => {
|
|
858
|
+
// One refusal comes as the system event and as its call's error text: it posts once.
|
|
859
|
+
if (c.refusedIds.has(e.id)) return;
|
|
860
|
+
c.refusedIds.add(e.id);
|
|
855
861
|
const call = c.calls.get(e.id);
|
|
856
862
|
const why = typeof call?.input?.description === 'string' ? call.input.description : '';
|
|
857
863
|
post(c, {
|
|
@@ -873,6 +879,11 @@ const SEEN = {
|
|
|
873
879
|
if (!e.sub && m) c.proposals.set(e.id, { move: m[1].replaceAll('_', '-'), fields: e.input });
|
|
874
880
|
},
|
|
875
881
|
tool_result: (c, e) => {
|
|
882
|
+
// A deny rule on a path refuses in the tool's own input check: claude sends no
|
|
883
|
+
// permission_denied then, only this error text (spike in docs/Session-Engine.md).
|
|
884
|
+
const call = c.calls.get(e.id);
|
|
885
|
+
if (e.error && call && DENIED_TEXT.test(e.text))
|
|
886
|
+
SEEN.refused(c, { type: 'refused', id: e.id, tool: call.tool, reason: e.text });
|
|
876
887
|
c.calls.delete(e.id);
|
|
877
888
|
const p = c.proposals.get(e.id);
|
|
878
889
|
if (!p) return;
|
|
@@ -890,22 +901,7 @@ const SEEN = {
|
|
|
890
901
|
};
|
|
891
902
|
|
|
892
903
|
if (!taskGate(c, e, Date.now(), later)) return;
|
|
893
|
-
|
|
894
|
-
post(c, {
|
|
895
|
-
type: 'task',
|
|
896
|
-
phase: e.phase,
|
|
897
|
-
id: e.id,
|
|
898
|
-
...(e.kind ? { kind: e.kind } : {}),
|
|
899
|
-
...(e.agent ? { agent: e.agent } : {}),
|
|
900
|
-
...(e.description ? { description: cut(e.description, WHY_MAX) } : {}),
|
|
901
|
-
...(e.doing ? { doing: cut(e.doing, WHY_MAX) } : {}),
|
|
902
|
-
...(prompt ? { prompt: cut(prompt, TASK_PROMPT_MAX) } : {}),
|
|
903
|
-
...(e.calls !== null ? { calls: e.calls } : {}),
|
|
904
|
-
...(e.ms !== null ? { ms: e.ms } : {}),
|
|
905
|
-
...(e.status ? { status: e.status } : {}),
|
|
906
|
-
...(e.summary ? { summary: cut(e.summary, TASK_SUMMARY_MAX) } : {}),
|
|
907
|
-
...(e.background ? { background: true } : {}),
|
|
908
|
-
});
|
|
904
|
+
post(c, taskCard(e));
|
|
909
905
|
},
|
|
910
906
|
// While they run, no answer is waited for; claude starts a turn itself as they end. Their end
|
|
911
907
|
// with no new turn after the grace settles the session, so it is not held for good.
|
|
@@ -917,6 +913,27 @@ const SEEN = {
|
|
|
917
913
|
},
|
|
918
914
|
};
|
|
919
915
|
|
|
916
|
+
/** The chat's `task` event of a task event `e`: only the fields it has. */
|
|
917
|
+
function taskCard(e) {
|
|
918
|
+
const prompt = e.phase === 'start' ? e.prompt : null;
|
|
919
|
+
|
|
920
|
+
return {
|
|
921
|
+
type: 'task',
|
|
922
|
+
phase: e.phase,
|
|
923
|
+
id: e.id,
|
|
924
|
+
...(e.kind ? { kind: e.kind } : {}),
|
|
925
|
+
...(e.agent ? { agent: e.agent } : {}),
|
|
926
|
+
...(e.description ? { description: cut(e.description, WHY_MAX) } : {}),
|
|
927
|
+
...(e.doing ? { doing: cut(e.doing, WHY_MAX) } : {}),
|
|
928
|
+
...(prompt ? { prompt: cut(prompt, TASK_PROMPT_MAX) } : {}),
|
|
929
|
+
...(e.calls !== null ? { calls: e.calls } : {}),
|
|
930
|
+
...(e.ms !== null ? { ms: e.ms } : {}),
|
|
931
|
+
...(e.status ? { status: e.status } : {}),
|
|
932
|
+
...(e.summary ? { summary: cut(e.summary, TASK_SUMMARY_MAX) } : {}),
|
|
933
|
+
...(e.background ? { background: true } : {}),
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
|
|
920
937
|
// The events that say a new turn has begun: the messages it echoes count themselves.
|
|
921
938
|
const TURN = new Set(['said', 'read', 'tool_call', 'tool_result']);
|
|
922
939
|
|
|
@@ -1029,6 +1046,7 @@ function chatState(opts) {
|
|
|
1029
1046
|
...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
|
|
1030
1047
|
...{ stopped: false, stopWait: false, grace: null, idle: false, inTurn: true, tasks: [] },
|
|
1031
1048
|
...{ proposals: new Map(), calls: new Map(), heard: false, summary: null, wanted: null },
|
|
1049
|
+
refusedIds: new Set(),
|
|
1032
1050
|
// When each task's last progress reached the chat; the last one it held back since.
|
|
1033
1051
|
taskAt: new Map(),
|
|
1034
1052
|
taskHeld: new Map(),
|
|
@@ -21,7 +21,11 @@ export function alive(pid) {
|
|
|
21
21
|
* group (`detached`), and the group gets the signal.
|
|
22
22
|
*/
|
|
23
23
|
export function killTree(pid) {
|
|
24
|
-
if (WIN)
|
|
24
|
+
if (WIN)
|
|
25
|
+
spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], {
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
stdio: 'ignore',
|
|
28
|
+
});
|
|
25
29
|
else {
|
|
26
30
|
try {
|
|
27
31
|
process.kill(-pid, 'SIGKILL');
|
|
@@ -70,29 +70,25 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag, fresh = false })
|
|
|
70
70
|
onFlag(info);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
const pastFlag = (share) => {
|
|
74
|
+
if (w.flagged && (w.after > HARD_TURNS || share >= handoff.pct + HARD_OVER)) {
|
|
75
|
+
write([`[${clock()}] handoff: the session went on past its flag, stopped`]);
|
|
76
|
+
stop();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
73
80
|
const check = (model, compacted) => {
|
|
74
81
|
const win = windowOf(model);
|
|
75
82
|
const pct = win ? Math.round((100 * w.context) / win) : null;
|
|
76
83
|
// No share is under every threshold: a session of an unknown window hands over at a compaction.
|
|
77
84
|
const share = pct ?? 0;
|
|
78
85
|
if (pct === null && !compacted) unknownOnce(model);
|
|
79
|
-
|
|
80
|
-
const under = fresh && !handoff.soft && w.readings === 1 && share >= handoff.pct;
|
|
81
|
-
if (under && !compacted && !w.under) {
|
|
82
|
-
w.under = true;
|
|
83
|
-
write([
|
|
84
|
-
`[${clock()}] handoff: off, the session starts at ${pct}% of the window, over ` +
|
|
85
|
-
`context_handoff_pct ${handoff.pct}: a fresh session would start there too; raise it`,
|
|
86
|
-
]);
|
|
87
|
-
}
|
|
86
|
+
underOnce(w, handoff, write, { fresh, pct, share, compacted });
|
|
88
87
|
|
|
89
88
|
if (!w.flagged && (compacted || (share >= handoff.pct && !w.under))) flag(win, pct, compacted);
|
|
90
89
|
// A project chat hands over by its summary turn, which goes on past the flag (AD-42).
|
|
91
90
|
if (handoff.soft) return;
|
|
92
|
-
|
|
93
|
-
write([`[${clock()}] handoff: the session went on past its flag, stopped`]);
|
|
94
|
-
stop();
|
|
95
|
-
}
|
|
91
|
+
pastFlag(share);
|
|
96
92
|
};
|
|
97
93
|
|
|
98
94
|
return {
|
|
@@ -113,6 +109,34 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag, fresh = false })
|
|
|
113
109
|
};
|
|
114
110
|
}
|
|
115
111
|
|
|
112
|
+
/** The chat of a session with `chat` options (`runSession`), and its context line `shown`. */
|
|
113
|
+
function openSessionChat(s, child, { watch, limit, windowOf, seen }) {
|
|
114
|
+
const parts = { ...sessionOf(child, watch, limit, windowOf), limited: () => !!seen.limit };
|
|
115
|
+
const talk = openChat({
|
|
116
|
+
...s.chat,
|
|
117
|
+
...parts,
|
|
118
|
+
id: s.id,
|
|
119
|
+
prompt: s.prompt,
|
|
120
|
+
encode: s.adapter.encode,
|
|
121
|
+
});
|
|
122
|
+
const shown = contextWatch((e) => talk?.event(e), windowOf);
|
|
123
|
+
|
|
124
|
+
return { talk, shown };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The note, once, of a fresh session at its first reading over the share (`w` its watch). */
|
|
128
|
+
function underOnce(w, handoff, write, { fresh, pct, share, compacted }) {
|
|
129
|
+
// A run's fresh session starts from the same prompt; a project chat's, from a summary.
|
|
130
|
+
const under = fresh && !handoff.soft && w.readings === 1 && share >= handoff.pct;
|
|
131
|
+
if (under && !compacted && !w.under) {
|
|
132
|
+
w.under = true;
|
|
133
|
+
write([
|
|
134
|
+
`[${clock()}] handoff: off, the session starts at ${pct}% of the window, over ` +
|
|
135
|
+
`context_handoff_pct ${handoff.pct}: a fresh session would start there too; raise it`,
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
116
140
|
/** A held session's own hard stop (`w` its watch): `check` runs only with a share to watch. */
|
|
117
141
|
function heldTooLong(w, write, stop) {
|
|
118
142
|
if (!w.held || w.hardStop || w.after <= HARD_TURNS) return;
|
|
@@ -330,7 +354,7 @@ function sessionTimeout(ms, onTimeout, onHalt) {
|
|
|
330
354
|
* held?: string}>}
|
|
331
355
|
*/
|
|
332
356
|
export function runSession(s) {
|
|
333
|
-
const { adapter, fd, timeoutMs,
|
|
357
|
+
const { adapter, fd, timeoutMs, onSpawn, handoff, quota, chat, observe, halt, ownReply } = s;
|
|
334
358
|
|
|
335
359
|
return new Promise((resolve) => {
|
|
336
360
|
const child = launchSession(s);
|
|
@@ -362,11 +386,7 @@ export function runSession(s) {
|
|
|
362
386
|
const limit = sessionTimeout(timeoutMs, stop('timeout'), halts);
|
|
363
387
|
/** @type {((tokens: number, model?: string) => void) | null} */
|
|
364
388
|
let shown = null;
|
|
365
|
-
if (chat) {
|
|
366
|
-
const parts = { ...sessionOf(child, watch, limit, windowOf), limited: () => !!seen.limit };
|
|
367
|
-
talk = openChat({ ...chat, ...parts, id, prompt: s.prompt, encode: adapter.encode });
|
|
368
|
-
shown = contextWatch((e) => talk?.event(e), windowOf);
|
|
369
|
-
}
|
|
389
|
+
if (chat) ({ talk, shown } = openSessionChat(s, child, { watch, limit, windowOf, seen }));
|
|
370
390
|
|
|
371
391
|
const flushOut = byLine(child.stdout, (line) => {
|
|
372
392
|
const a = adapter.parse(line);
|
|
@@ -24,17 +24,22 @@ export function writeAtomic(file, text) {
|
|
|
24
24
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
25
25
|
try {
|
|
26
26
|
writeFileSync(tmp, text);
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
renameSync(tmp, file);
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
} catch (e) {
|
|
33
|
-
if (!HELD.has(e.code) || i >= 10) throw e;
|
|
34
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
|
|
35
|
-
}
|
|
27
|
+
renameHeld(tmp, file);
|
|
36
28
|
} catch (e) {
|
|
37
29
|
rmSync(tmp, { force: true });
|
|
38
30
|
throw e;
|
|
39
31
|
}
|
|
40
32
|
}
|
|
33
|
+
|
|
34
|
+
/** Rename `tmp` over `file`, again for a file held for a moment. */
|
|
35
|
+
function renameHeld(tmp, file) {
|
|
36
|
+
for (let i = 0; ; i++)
|
|
37
|
+
try {
|
|
38
|
+
renameSync(tmp, file);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (!HELD.has(e.code) || i >= 10) throw e;
|
|
43
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -220,9 +220,7 @@ function markOnce(dir, [kind, key], t, last = false) {
|
|
|
220
220
|
* of the thread, a handoff's too, runs by it. A started thread is bound to nothing.
|
|
221
221
|
*/
|
|
222
222
|
export function createThread(dir, { item = null, entry = null, start = null } = {}) {
|
|
223
|
-
|
|
224
|
-
if (start && (item || entry)) throw new RangeError('a started thread is bound to nothing');
|
|
225
|
-
const [kind, key] = item ? ['items', item] : ['entries', entry];
|
|
223
|
+
const [kind, key] = markKey(item, entry, start);
|
|
226
224
|
const had = key ? boundTo(dir, kind, key) : null;
|
|
227
225
|
if (had) return had;
|
|
228
226
|
mkdirSync(path.join(chatsDir(dir), kind), { recursive: true });
|
|
@@ -236,6 +234,14 @@ export function createThread(dir, { item = null, entry = null, start = null } =
|
|
|
236
234
|
return t;
|
|
237
235
|
}
|
|
238
236
|
|
|
237
|
+
/** The mark of a new thread, `[kind, key]` (`createThread`); a RangeError for a bound one twice. */
|
|
238
|
+
function markKey(item, entry, start) {
|
|
239
|
+
if (item && entry) throw new RangeError('a thread is bound to an item or an entry, not both');
|
|
240
|
+
if (start && (item || entry)) throw new RangeError('a started thread is bound to nothing');
|
|
241
|
+
|
|
242
|
+
return item ? ['items', item] : ['entries', entry];
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
/** A thread's folder made exclusively under a fresh id: the id. */
|
|
240
246
|
function newDir(dir) {
|
|
241
247
|
for (;;) {
|
|
@@ -95,7 +95,10 @@ export function reasonOf(e, err, timeoutMs = ASK_TIMEOUT_MS) {
|
|
|
95
95
|
function killAll(child) {
|
|
96
96
|
if (!child.pid) return;
|
|
97
97
|
if (process.platform === 'win32')
|
|
98
|
-
spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
|
|
98
|
+
spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
|
|
99
|
+
windowsHide: true,
|
|
100
|
+
stdio: 'ignore',
|
|
101
|
+
});
|
|
99
102
|
else
|
|
100
103
|
try {
|
|
101
104
|
process.kill(-child.pid, 'SIGKILL');
|
|
@@ -167,6 +170,7 @@ const fresh = (r, maxAgeMs, now) =>
|
|
|
167
170
|
Boolean(r?.at) && now - Date.parse(r.at) < maxAgeMs && !r.failed;
|
|
168
171
|
|
|
169
172
|
// One ask a process: a second caller waits for it (claim gives the lock to its own pid again).
|
|
173
|
+
/** @type {ReturnType<typeof askShared> | null} */
|
|
170
174
|
let inFlight = null;
|
|
171
175
|
|
|
172
176
|
/**
|
|
@@ -248,6 +252,11 @@ const scopedTo = (limit, model) => {
|
|
|
248
252
|
);
|
|
249
253
|
};
|
|
250
254
|
|
|
255
|
+
/**
|
|
256
|
+
* @typedef {{go: true} | {wait: true, until: Date, reserve: true}
|
|
257
|
+
* | {stop: true, why: string, reserve: {weekly?: boolean, until?: string | null}}} Reserve
|
|
258
|
+
*/
|
|
259
|
+
|
|
251
260
|
/**
|
|
252
261
|
* The reserve's gate over a reading (`usage.json`): a failed ask is no reading, so it goes
|
|
253
262
|
* (Hold-Plan d10), as does none.
|
|
@@ -255,6 +264,7 @@ const scopedTo = (limit, model) => {
|
|
|
255
264
|
* @param {string | null | undefined} model
|
|
256
265
|
* @param {number} pct
|
|
257
266
|
* @param {number} [now]
|
|
267
|
+
* @returns {Reserve}
|
|
258
268
|
*/
|
|
259
269
|
export const reserveOfReading = (reading, model, pct, now = Date.now()) =>
|
|
260
270
|
reading && !reading.failed ? reserveOf(reading.limits, model, pct, now) : { go: true };
|
|
@@ -267,6 +277,7 @@ export const reserveOfReading = (reading, model, pct, now = Date.now()) =>
|
|
|
267
277
|
* @param {string | null | undefined} model
|
|
268
278
|
* @param {number} pct
|
|
269
279
|
* @param {number} [now]
|
|
280
|
+
* @returns {Reserve}
|
|
270
281
|
*/
|
|
271
282
|
export function reserveOf(limits, model, pct, now = Date.now()) {
|
|
272
283
|
if (!limits?.length) return { go: true };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "The session engine of GCF: one agent session and a run as a chain of them, the chat protocol, the provider adapters. Bundled by gcf-harness-aif-ext and gcf-board, never published.",
|
|
6
6
|
"type": "module",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "A local web board for GCF game projects: shows `gcf board --json` and runs the same ai-factory gcf commands an operator runs in a console",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"vite": "^8.3.4"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@modelcontextprotocol/server": "2.
|
|
56
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
57
57
|
"gcf-session": "file:../gcf-session"
|
|
58
58
|
},
|
|
59
59
|
"bundleDependencies": [
|