gcf-board 0.16.9 → 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 +164 -12
- 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/moves.js +25 -0
- 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 +273 -21
- package/dist/server/talks.js +132 -28
- 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/activity.js +19 -6
- package/node_modules/gcf-session/lib/chat.js +115 -8
- package/node_modules/gcf-session/lib/store.js +14 -2
- package/node_modules/gcf-session/lib/thread.js +6 -17
- 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-BMO2AlDy.js +0 -66
- package/dist/web/assets/index-i3nTqHUr.css +0 -1
|
@@ -13,11 +13,87 @@ import {
|
|
|
13
13
|
readSync,
|
|
14
14
|
statSync,
|
|
15
15
|
} from 'node:fs';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
16
17
|
import path from 'node:path';
|
|
17
18
|
import { CHAT_FLAGS, encode as claudeInput } from './adapter/claude.js';
|
|
18
19
|
|
|
19
20
|
export { CHAT_FLAGS };
|
|
20
21
|
|
|
22
|
+
// The kinds whose pattern is a path glob (AD-4).
|
|
23
|
+
const FILE_KINDS = new Set(['read', 'search', 'edit']);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a neutral rule `{kind, pattern}` holds for a call (`{kind, tool, title}`): its kind,
|
|
27
|
+
* its glob on the title; a shell rule on each command of a chain too (`cd x && git push` is a
|
|
28
|
+
* `git *`), claude's old `cmd:*` as `cmd*`; a path rule on the path's end, as a project glob
|
|
29
|
+
* holds for the absolute path a call names (`.claude/**`, `~/.ssh/**`); an MCP rule on the tool.
|
|
30
|
+
* shortcut: claude's own matcher refuses or asks; this one names the rule, and may miss a form
|
|
31
|
+
* claude reads otherwise (`other` rules, web domains): the refusal then names none.
|
|
32
|
+
*/
|
|
33
|
+
export function ruleHolds(rule, e) {
|
|
34
|
+
if (rule.kind !== e.kind) return false;
|
|
35
|
+
if (!rule.pattern) return true;
|
|
36
|
+
// A server's rule (`unity`) holds for each of its tools, as claude's `mcp__unity` does.
|
|
37
|
+
if (rule.kind === 'mcp')
|
|
38
|
+
return e.tool === `mcp__${rule.pattern}` || e.tool.startsWith(`mcp__${rule.pattern}__`);
|
|
39
|
+
const slash = (p) => p.replaceAll('\\', '/');
|
|
40
|
+
const esc = (p) => p.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
|
|
41
|
+
const title = String(e.title ?? '');
|
|
42
|
+
if (FILE_KINDS.has(rule.kind)) {
|
|
43
|
+
const pattern = slash(rule.pattern.replace(/^~(?=\/)/, homedir()));
|
|
44
|
+
// A path glob: `**/` is any folders, none too; `**` anything; `*` within one folder.
|
|
45
|
+
const glob = pattern
|
|
46
|
+
.split(/(\*\*\/|\*\*|\*)/)
|
|
47
|
+
.map((t) => PATH_GLOB[t] ?? esc(t))
|
|
48
|
+
.join('');
|
|
49
|
+
const re = new RegExp(`(?:^|/)${glob}$`, process.platform === 'win32' ? 'i' : '');
|
|
50
|
+
|
|
51
|
+
return re.test(slash(title));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const re = new RegExp(`^${esc(rule.pattern.replace(/:\*$/, '*')).replaceAll('*', '.*')}$`);
|
|
55
|
+
const parts = rule.kind === 'shell' ? commandsOf(title) : [];
|
|
56
|
+
|
|
57
|
+
return [title, ...parts].some((x) => re.test(x.trim()));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const PATH_GLOB = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' };
|
|
61
|
+
|
|
62
|
+
// How much of a refused call the chat keeps: its command or file, and what it was for.
|
|
63
|
+
const TITLE_MAX = 2000;
|
|
64
|
+
const WHY_MAX = 500;
|
|
65
|
+
const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}…` : s);
|
|
66
|
+
|
|
67
|
+
// A shell line's pieces: a quoted string whole (an unclosed one to the end), a separator, a run
|
|
68
|
+
// of plain characters.
|
|
69
|
+
const SHELL_PIECE = /'[^']*'?|"(?:\\.|[^"\\])*"?|&&|\|\||[;|\n]|[^'";|&\n]+|&/g;
|
|
70
|
+
const SEPARATOR = new Set(['&&', '||', ';', '|', '\n']);
|
|
71
|
+
|
|
72
|
+
/** The commands of a shell chain, split on `&&`, `||`, `;`, `|` and new lines outside quotes. */
|
|
73
|
+
function commandsOf(line) {
|
|
74
|
+
const parts = [''];
|
|
75
|
+
for (const [piece] of line.matchAll(SHELL_PIECE))
|
|
76
|
+
if (SEPARATOR.has(piece)) parts.push('');
|
|
77
|
+
else parts[parts.length - 1] += piece;
|
|
78
|
+
|
|
79
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* What refused a call (`deny`, the rules the session runs by): the rule only when one alone
|
|
84
|
+
* holds, its group when every rule that holds is of it.
|
|
85
|
+
*/
|
|
86
|
+
function refusedBy(deny, call) {
|
|
87
|
+
const held = deny.filter((r) => ruleHolds(r, call));
|
|
88
|
+
const group = held[0]?.group;
|
|
89
|
+
const rule = held.length === 1 ? held[0] : null;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
...(rule ? { rule: rule.pattern ? `${rule.kind}: ${rule.pattern}` : rule.kind } : {}),
|
|
93
|
+
...(group && held.every((r) => r.group === group) ? { group } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
21
97
|
/** How long a question waits for the operator when neither the flag nor the config says. */
|
|
22
98
|
export const CHAT_TIMEOUT_MIN = 15;
|
|
23
99
|
|
|
@@ -601,13 +677,28 @@ function waitCards(c) {
|
|
|
601
677
|
/**
|
|
602
678
|
* A tool call the session's permissions leave to someone: the engine refuses it when its
|
|
603
679
|
* policy says (`gate`, AD-29, no card), a run refuses it (nobody approves there), a project
|
|
604
|
-
* chat asks the operator by an approval card (AD-5)
|
|
680
|
+
* chat asks the operator by an approval card (AD-5), or allows the call itself while the
|
|
681
|
+
* operator's YOLO is on (AD-54), with no rule saved. "Always" is offered only for a rule the
|
|
605
682
|
* session does not ask for anyway (`asks`): an allow would not beat that ask (AD-2).
|
|
606
683
|
*/
|
|
607
684
|
function permit(c, e) {
|
|
608
685
|
const why = c.gate(e);
|
|
609
686
|
if (why) return refuse(c, e, why, { title: e.title, reason: why });
|
|
610
687
|
if (!c.approvals) return refuse(c, e, `${e.tool} needs an approval no one gives in a run`);
|
|
688
|
+
if (c.yolo()) {
|
|
689
|
+
send(c, c.encode.allow(e.request_id, e.input));
|
|
690
|
+
|
|
691
|
+
return post(c, {
|
|
692
|
+
type: 'allowed',
|
|
693
|
+
request_id: e.request_id,
|
|
694
|
+
by: 'yolo',
|
|
695
|
+
tool: e.tool,
|
|
696
|
+
kind: e.kind,
|
|
697
|
+
title: e.title,
|
|
698
|
+
...(e.reason ? { reason: e.reason } : {}),
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
|
|
611
702
|
const always = e.always && !c.asks(e) ? e.always : null;
|
|
612
703
|
c.cards.set(e.request_id, {
|
|
613
704
|
approval: true,
|
|
@@ -658,20 +749,31 @@ const SEEN = {
|
|
|
658
749
|
},
|
|
659
750
|
question: asked,
|
|
660
751
|
permission: permit,
|
|
661
|
-
// A deny rule of the settings refused it: no card was ever due.
|
|
662
|
-
|
|
752
|
+
// A deny rule of the settings refused it: no card was ever due. The refused call says what
|
|
753
|
+
// was asked (`title`) and what for (`description`), not its whole input: a write's content
|
|
754
|
+
// stays out of the chat. The session's rule that holds for it, and the rule's group, say what
|
|
755
|
+
// refused it (refusedBy).
|
|
756
|
+
refused: (c, e) => {
|
|
757
|
+
const call = c.calls.get(e.id);
|
|
758
|
+
const why = typeof call?.input?.description === 'string' ? call.input.description : '';
|
|
663
759
|
post(c, {
|
|
664
760
|
type: 'denied',
|
|
665
761
|
tool: e.tool,
|
|
666
762
|
by: 'rule',
|
|
763
|
+
...(call ? { title: cut(call.title, TITLE_MAX), ...refusedBy(c.deny, call) } : {}),
|
|
764
|
+
...(why ? { description: cut(why, WHY_MAX) } : {}),
|
|
667
765
|
...(e.reason ? { reason: e.reason } : {}),
|
|
668
|
-
})
|
|
669
|
-
|
|
766
|
+
});
|
|
767
|
+
},
|
|
768
|
+
// A proposal (AD-12): the call of the center's MCP tool, posted when it succeeded. Each call
|
|
769
|
+
// is kept until its result: a refusal names it by its id.
|
|
670
770
|
tool_call: (c, e) => {
|
|
771
|
+
c.calls.set(e.id, e);
|
|
671
772
|
const m = /^mcp__gcf__propose_(\w+)$/.exec(e.tool);
|
|
672
773
|
if (!e.sub && m) c.proposals.set(e.id, { move: m[1].replaceAll('_', '-'), fields: e.input });
|
|
673
774
|
},
|
|
674
775
|
tool_result: (c, e) => {
|
|
776
|
+
c.calls.delete(e.id);
|
|
675
777
|
const p = c.proposals.get(e.id);
|
|
676
778
|
if (!p) return;
|
|
677
779
|
c.proposals.delete(e.id);
|
|
@@ -716,7 +818,8 @@ function see(c, events) {
|
|
|
716
818
|
* (`{context, context_pct}`); `pause(on)` stops the session's timeout while it waits for the
|
|
717
819
|
* operator; `prompt` is the first message; `kind` how the session started (`start`, `resume`,
|
|
718
820
|
* `handoff`); `pick` the model and effort a project chat's session was started with;
|
|
719
|
-
* `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says
|
|
821
|
+
* `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says; `deny` the neutral
|
|
822
|
+
* deny rules the session runs by (each with its `group`, if any): a refusal names its rule.
|
|
720
823
|
* `see(events)` takes the neutral events of each line the agent prints; `event(e)` posts one
|
|
721
824
|
* the run saw; `encode` writes its input as the agent reads it;
|
|
722
825
|
* `close(code, seen)` stops reading and posts the session's end.
|
|
@@ -724,7 +827,8 @@ function see(c, events) {
|
|
|
724
827
|
* A project chat (AD-5) sets `approvals`: a permission request is an approval card;
|
|
725
828
|
* `gate(e)` names why the engine refuses a call outright, or null; `asks(e)` whether the
|
|
726
829
|
* session asks for such a call anyway (no "always" then); `saveAlways(rule)` keeps an
|
|
727
|
-
* "always" rule; `
|
|
830
|
+
* "always" rule; `yolo()` whether the engine allows a call itself, with no card (AD-54);
|
|
831
|
+
* `onHandoff()` takes the operator's fresh-agent input. `files` names the chat's
|
|
728
832
|
* two files when they are not `<id>.chat*.jsonl` under `logs`.
|
|
729
833
|
*/
|
|
730
834
|
export function openChat(opts) {
|
|
@@ -773,6 +877,8 @@ const CHAT_DEFAULTS = {
|
|
|
773
877
|
approvals: false,
|
|
774
878
|
gate: () => null,
|
|
775
879
|
asks: () => false,
|
|
880
|
+
yolo: () => false,
|
|
881
|
+
deny: [],
|
|
776
882
|
saveAlways: async () => {},
|
|
777
883
|
handover: null,
|
|
778
884
|
prefix: null,
|
|
@@ -793,7 +899,8 @@ function chatState(opts) {
|
|
|
793
899
|
fresh: o.fresh ?? o.kind === 'handoff',
|
|
794
900
|
...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
|
|
795
901
|
...{ stopped: false, grace: null, idle: false, inTurn: true, tasks: [] },
|
|
796
|
-
...{ proposals: new Map(), heard: false, summary: null, wanted: null
|
|
902
|
+
...{ proposals: new Map(), calls: new Map(), heard: false, summary: null, wanted: null },
|
|
903
|
+
why: null,
|
|
797
904
|
...{ hold: false, late: false, pending: [], echoes: [] },
|
|
798
905
|
};
|
|
799
906
|
}
|
|
@@ -12,15 +12,27 @@ export const runsDir = (dir) => path.join(dir, ROOT, 'runs');
|
|
|
12
12
|
/** `.gcf-session/chats`: the project chat's threads. */
|
|
13
13
|
export const chatsDir = (dir) => path.join(dir, ROOT, 'chats');
|
|
14
14
|
|
|
15
|
+
// What a rename over a file another process holds open meets on Windows (a scanner, an indexer).
|
|
16
|
+
const HELD = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* Write `text` to `file` whole or not at all: a temporary file beside it, then a rename. A
|
|
17
|
-
* reader never sees half of it, and two writers leave one whole file.
|
|
20
|
+
* reader never sees half of it, and two writers leave one whole file. A file held for a moment
|
|
21
|
+
* is tried again for up to half a second.
|
|
18
22
|
*/
|
|
19
23
|
export function writeAtomic(file, text) {
|
|
20
24
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
21
25
|
try {
|
|
22
26
|
writeFileSync(tmp, text);
|
|
23
|
-
|
|
27
|
+
for (let i = 0; ; i++)
|
|
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
|
+
}
|
|
24
36
|
} catch (e) {
|
|
25
37
|
rmSync(tmp, { force: true });
|
|
26
38
|
throw e;
|
|
@@ -21,7 +21,7 @@ import { createHash } from 'node:crypto';
|
|
|
21
21
|
import { PICKS } from './adapter/claude.js';
|
|
22
22
|
import { adapterFor } from './adapter/index.js';
|
|
23
23
|
import { runJob } from './job.js';
|
|
24
|
-
import { postTo, readFrom } from './chat.js';
|
|
24
|
+
import { postTo, readFrom, ruleHolds } from './chat.js';
|
|
25
25
|
import { realClock } from './limit.js';
|
|
26
26
|
import { alive } from './proc.js';
|
|
27
27
|
import { chatsDir, runsDir, writeAtomic } from './store.js';
|
|
@@ -270,21 +270,6 @@ export function listThreads(dir) {
|
|
|
270
270
|
.sort((a, b) => String(b.created_at).localeCompare(String(a.created_at)));
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
/**
|
|
274
|
-
* Whether a neutral rule `{kind, pattern}` holds for a call: its kind, its glob on the title; a
|
|
275
|
-
* shell rule on each command of a chain too (`cd x && git push` is a `git *`).
|
|
276
|
-
*/
|
|
277
|
-
function ruleHolds(rule, e) {
|
|
278
|
-
if (rule.kind !== e.kind) return false;
|
|
279
|
-
if (!rule.pattern) return true;
|
|
280
|
-
const glob = rule.pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replaceAll('*', '.*');
|
|
281
|
-
const re = new RegExp(`^${glob}$`);
|
|
282
|
-
const title = String(e.title ?? '');
|
|
283
|
-
const parts = e.kind === 'shell' ? title.split(/\s*(?:&&|\|\||[;|\n])\s*/) : [];
|
|
284
|
-
|
|
285
|
-
return [title, ...parts].some((x) => re.test(x.trim()));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
273
|
/** Whether the main run's lock (`runs/<main>.lock`) names a live process. */
|
|
289
274
|
function mainBusy(file) {
|
|
290
275
|
if (!file) return false;
|
|
@@ -350,7 +335,8 @@ function flagsOf({ dir, td, spec, adapter }, settings) {
|
|
|
350
335
|
* Run thread `t` of project `dir` until its session idles out, is stopped, or ends: a job of
|
|
351
336
|
* sessions (AD-41), each resumed from the one before, a fresh one after a handoff (AD-42).
|
|
352
337
|
* `spec` (its `spec.json`): `agent`, `rules` `{deny, ask, allow}`, `mcp` (config files),
|
|
353
|
-
* `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `
|
|
338
|
+
* `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `yolo` (a file: present, the engine
|
|
339
|
+
* allows each call with no card, AD-54), `timeoutMin`, `pick` (the project's
|
|
354
340
|
* model and effort, under the thread's own, over the agent's defaults). `stopped()` says the
|
|
355
341
|
* operator stopped it.
|
|
356
342
|
* @param {{stopped?: () => boolean}} [opts]
|
|
@@ -555,6 +541,9 @@ function chatOf(s, kind, prev) {
|
|
|
555
541
|
approvals: true,
|
|
556
542
|
gate: gateOf(spec),
|
|
557
543
|
asks: (e) => (spec.rules?.ask ?? []).some((r) => ruleHolds(r, e)),
|
|
544
|
+
// Read at each request: the operator's switch holds at once.
|
|
545
|
+
yolo: () => Boolean(spec.yolo) && existsSync(spec.yolo),
|
|
546
|
+
deny: spec.rules?.deny ?? [],
|
|
558
547
|
saveAlways: (rule) => s.adapter.saveAlways(dir, rule),
|
|
559
548
|
handover: handoverOf(s),
|
|
560
549
|
summary: kind === 'handoff' ? s.summary : null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.4",
|
|
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",
|
|
@@ -75,6 +75,16 @@ export type ChatEvent = At &
|
|
|
75
75
|
always_wide?: boolean;
|
|
76
76
|
}
|
|
77
77
|
| { type: 'allowed'; request_id: string; by: 'operator'; always: boolean; rule?: string }
|
|
78
|
+
/** The engine allowed the call itself, with no card: the operator's YOLO (AD-54). */
|
|
79
|
+
| {
|
|
80
|
+
type: 'allowed';
|
|
81
|
+
request_id: string;
|
|
82
|
+
by: 'yolo';
|
|
83
|
+
tool: string;
|
|
84
|
+
kind: string;
|
|
85
|
+
title: string;
|
|
86
|
+
reason?: string;
|
|
87
|
+
}
|
|
78
88
|
| {
|
|
79
89
|
type: 'denied';
|
|
80
90
|
tool: string;
|
|
@@ -102,6 +112,20 @@ export type ChatEvent = At &
|
|
|
102
112
|
by?: 'operator' | 'threshold' | 'compacted';
|
|
103
113
|
error?: string;
|
|
104
114
|
}
|
|
115
|
+
| {
|
|
116
|
+
// How an item's run ended: the harness posts it last (Tails «Первым» 2).
|
|
117
|
+
type: 'run_end';
|
|
118
|
+
outcome:
|
|
119
|
+
'submitted' | 'blocked' | 'failed' | 'paused' | 'stopped' | 'no-result' | 'skipped';
|
|
120
|
+
move: string;
|
|
121
|
+
reason: string | null;
|
|
122
|
+
cost_usd: number | null;
|
|
123
|
+
duration_ms: number | null;
|
|
124
|
+
commit: string | null;
|
|
125
|
+
unticked: number | null;
|
|
126
|
+
lessons: number;
|
|
127
|
+
process: string | null;
|
|
128
|
+
}
|
|
105
129
|
| { type: 'step'; step: 'plan'; passes: number }
|
|
106
130
|
| {
|
|
107
131
|
type: 'step';
|
|
@@ -159,6 +183,8 @@ export interface ThreadSpec {
|
|
|
159
183
|
window?: number;
|
|
160
184
|
skill?: string;
|
|
161
185
|
mainLock?: string | null;
|
|
186
|
+
/** A file whose presence turns the operator's YOLO on: calls go with no card (AD-54). */
|
|
187
|
+
yolo?: string;
|
|
162
188
|
timeoutMin?: number;
|
|
163
189
|
/** The project's model and effort: a session takes them where the thread picked none. */
|
|
164
190
|
pick?: AgentPick;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
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",
|