gcf-board 0.8.2 → 0.10.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 +12 -8
- package/dist/server/app.js +202 -18
- package/dist/server/atomic.js +24 -0
- package/dist/server/chat.js +21 -9
- package/dist/server/cli.js +5 -0
- package/dist/server/files.js +47 -1
- package/dist/server/runs.js +291 -64
- package/dist/server/talks.js +25 -1
- package/dist/shared/board.js +8 -0
- package/dist/web/assets/{index-aCBpVSeA.css → index-BlCYzxb6.css} +1 -1
- package/dist/web/assets/index-Ds-_gzfR.js +39 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/activity.js +12 -4
- package/node_modules/gcf-session/lib/chat.js +2 -0
- package/node_modules/gcf-session/lib/index.js +1 -0
- package/node_modules/gcf-session/lib/thread.js +80 -27
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +11 -1
- package/package.json +1 -1
- package/dist/web/assets/index-D8JZaQgt.js +0 -39
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-Ds-_gzfR.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BlCYzxb6.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
|
@@ -260,24 +260,32 @@ function requested(e) {
|
|
|
260
260
|
input,
|
|
261
261
|
title: String(title),
|
|
262
262
|
reason: typeof e.request.description === 'string' ? e.request.description : null,
|
|
263
|
-
|
|
263
|
+
...alwaysOf(e.request.permission_suggestions),
|
|
264
264
|
},
|
|
265
265
|
];
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// One tool of one MCP server, as claude names it (letters, digits, - and _): it suggests it
|
|
269
|
+
// bare, with no content to narrow it.
|
|
270
|
+
const MCP_TOOL = /^mcp__[A-Za-z0-9-][\w-]*__[A-Za-z0-9-][\w-]*$/;
|
|
271
|
+
|
|
268
272
|
/**
|
|
269
273
|
* The rule "always" would save (AD-2): claude's suggestion of an allow rule for the local
|
|
270
|
-
* settings, as `Tool(content)`; null for none,
|
|
274
|
+
* settings, as `Tool(content)`; `always: null` for none, a bare `*`, or a bare tool, which is too
|
|
275
|
+
* wide, except one tool of an MCP server: the operator sees its name and decides, and the card
|
|
276
|
+
* says it holds for any arguments (`always_wide`).
|
|
271
277
|
*/
|
|
272
278
|
function alwaysOf(suggestions) {
|
|
273
279
|
const add = (Array.isArray(suggestions) ? suggestions : []).find(
|
|
274
280
|
(s) => s?.type === 'addRules' && s.behavior === 'allow' && s.destination === 'localSettings',
|
|
275
281
|
);
|
|
276
282
|
const r = add?.rules?.[0];
|
|
283
|
+
const tool = typeof r?.toolName === 'string' ? r.toolName : '';
|
|
277
284
|
const content = typeof r?.ruleContent === 'string' ? r.ruleContent.trim() : '';
|
|
278
|
-
if (
|
|
285
|
+
if (!tool || /^\*+$/.test(content)) return { always: null };
|
|
286
|
+
if (!content) return MCP_TOOL.test(tool) ? { always: tool, always_wide: true } : { always: null };
|
|
279
287
|
|
|
280
|
-
return `${
|
|
288
|
+
return { always: `${tool}(${content})` };
|
|
281
289
|
}
|
|
282
290
|
|
|
283
291
|
/** @returns {Neutral[]} */
|
|
@@ -624,6 +624,8 @@ function permit(c, e) {
|
|
|
624
624
|
title: e.title,
|
|
625
625
|
...(e.reason ? { reason: e.reason } : {}),
|
|
626
626
|
...(always ? { always } : {}),
|
|
627
|
+
// The rule holds for any arguments of the tool: the card says so before Always.
|
|
628
|
+
...(always && e.always_wide ? { always_wide: true } : {}),
|
|
627
629
|
});
|
|
628
630
|
waitCards(c);
|
|
629
631
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
openSync,
|
|
13
13
|
readFileSync,
|
|
14
14
|
readdirSync,
|
|
15
|
+
renameSync,
|
|
15
16
|
rmSync,
|
|
16
17
|
writeFileSync,
|
|
17
18
|
} from 'node:fs';
|
|
@@ -70,11 +71,15 @@ const GIT_OPTS = String.raw`(?:(?:${GIT_OPT})\s+)*`;
|
|
|
70
71
|
const GIT_CHANGES = new RegExp(String.raw`\bgit\s+${GIT_OPTS}(?:${GIT_VERBS})\b`);
|
|
71
72
|
|
|
72
73
|
export const threadDir = (dir, t) => path.join(chatsDir(dir), t);
|
|
73
|
-
|
|
74
|
+
// A bound thread's mark: `chats/items/<item>` or `chats/entries/<entry>`, the thread's id.
|
|
75
|
+
const markOf = (dir, kind, key) => path.join(chatsDir(dir), kind, key);
|
|
74
76
|
|
|
75
|
-
/** The thread `t`'s record, `{id, item, sessions, created_at, in_at}
|
|
77
|
+
/** The thread `t`'s record, `{id, item, entry, sessions, created_at, in_at}`; no `entry`: null. */
|
|
76
78
|
export function readThread(dir, t) {
|
|
77
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
entry: null,
|
|
81
|
+
...JSON.parse(readFileSync(path.join(threadDir(dir, t), 'thread.json'), 'utf8')),
|
|
82
|
+
};
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
const writeThread = (dir, t, rec) =>
|
|
@@ -104,12 +109,14 @@ const pickFile = (td) => path.join(td, 'agent.json');
|
|
|
104
109
|
const wordOf = (v) =>
|
|
105
110
|
typeof v === 'string' && v !== AGENT_DEFAULT && PICK_WORD.test(v) ? v : null;
|
|
106
111
|
|
|
112
|
+
/** The plain words of a pick, `{model?, effort?}`; a bad word left out. */
|
|
113
|
+
const wordsOf = (v) =>
|
|
114
|
+
Object.fromEntries(PICKS.flatMap((k) => (wordOf(v?.[k]) ? [[k, v[k]]] : [])));
|
|
115
|
+
|
|
107
116
|
/** What `agent.json` of folder `td` picks, `{model?, effort?}`; a hand edit's bad word left out. */
|
|
108
117
|
function pickIn(td) {
|
|
109
118
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return Object.fromEntries(PICKS.flatMap((k) => (wordOf(v?.[k]) ? [[k, v[k]]] : [])));
|
|
119
|
+
return wordsOf(JSON.parse(readFileSync(pickFile(td), 'utf8')));
|
|
113
120
|
} catch {
|
|
114
121
|
return {};
|
|
115
122
|
}
|
|
@@ -142,10 +149,10 @@ export function setThreadAgent(dir, t, pick) {
|
|
|
142
149
|
return kept;
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
/** The thread
|
|
146
|
-
|
|
152
|
+
/** The thread of mark `kind/key`, or null. */
|
|
153
|
+
function boundTo(dir, kind, key) {
|
|
147
154
|
try {
|
|
148
|
-
const t = readFileSync(
|
|
155
|
+
const t = readFileSync(markOf(dir, kind, key), 'utf8').trim();
|
|
149
156
|
|
|
150
157
|
return THREAD_ID.test(t) && existsSync(threadDir(dir, t)) ? t : null;
|
|
151
158
|
} catch {
|
|
@@ -153,26 +160,71 @@ export function threadOf(dir, item) {
|
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
|
|
163
|
+
/** The thread bound to `item`, or null (AD-46). */
|
|
164
|
+
export const threadOf = (dir, item) => boundTo(dir, 'items', item);
|
|
165
|
+
|
|
166
|
+
/** The thread bound to inbox entry `entry` (Draft with agent), or null. */
|
|
167
|
+
export const threadOfEntry = (dir, entry) => boundTo(dir, 'entries', entry);
|
|
168
|
+
|
|
156
169
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
170
|
+
* Bind new thread `t` to `key`, exclusively: the thread that holds the mark, `t` when it took
|
|
171
|
+
* it. Taken by a thread made just now: that one, and `t` goes. A mark whose thread is gone (its
|
|
172
|
+
* folder erased by hand) is stale: `t` takes it over.
|
|
159
173
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
function takeMark(dir, kind, key, t) {
|
|
175
|
+
const had = markOnce(dir, [kind, key], t);
|
|
176
|
+
if (had) return had;
|
|
177
|
+
// A stale mark is moved aside under this thread's own name, then taken exclusively again: of
|
|
178
|
+
// two at once, the one whose move fails finds the other's mark on its last try.
|
|
179
|
+
// shortcut: a mark read between another's create and its write looks stale (empty); two boards
|
|
180
|
+
// on one project in that instant could still split a thread.
|
|
181
|
+
const aside = `${markOf(dir, kind, key)}.${t}`;
|
|
182
|
+
try {
|
|
183
|
+
renameSync(markOf(dir, kind, key), aside);
|
|
184
|
+
rmSync(aside, { force: true });
|
|
185
|
+
} catch {
|
|
186
|
+
// Moved by the other one: its mark wins below.
|
|
172
187
|
}
|
|
173
188
|
|
|
189
|
+
return markOnce(dir, [kind, key], t, true);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* One exclusive try at the mark: `t` when taken, the thread that holds it, or null for a stale
|
|
194
|
+
* one (`last`: throw then). `t`'s folder goes when it does not get the mark.
|
|
195
|
+
*/
|
|
196
|
+
function markOnce(dir, [kind, key], t, last = false) {
|
|
197
|
+
try {
|
|
198
|
+
writeFileSync(markOf(dir, kind, key), t, { flag: 'wx' });
|
|
199
|
+
|
|
200
|
+
return t;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
const taken = /** @type {any} */ (e).code === 'EEXIST';
|
|
203
|
+
const won = taken ? boundTo(dir, kind, key) : null;
|
|
204
|
+
if (!won && taken && !last) return null;
|
|
205
|
+
rmSync(threadDir(dir, t), { recursive: true, force: true });
|
|
206
|
+
if (won) return won;
|
|
207
|
+
throw e;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A new thread, its id; bound to `item` or to inbox `entry`, the one it already has (AD-46).
|
|
213
|
+
* Ids and the marks are made exclusively: two at once never take one id, nor give an item or an
|
|
214
|
+
* entry two threads. Both `item` and `entry` is a RangeError.
|
|
215
|
+
*/
|
|
216
|
+
export function createThread(dir, { item = null, entry = null } = {}) {
|
|
217
|
+
if (item && entry) throw new RangeError('a thread is bound to an item or an entry, not both');
|
|
218
|
+
const [kind, key] = item ? ['items', item] : ['entries', entry];
|
|
219
|
+
const had = key ? boundTo(dir, kind, key) : null;
|
|
220
|
+
if (had) return had;
|
|
221
|
+
mkdirSync(path.join(chatsDir(dir), kind), { recursive: true });
|
|
222
|
+
const t = newDir(dir);
|
|
223
|
+
const won = key ? takeMark(dir, kind, key, t) : t;
|
|
224
|
+
if (won !== t) return won;
|
|
225
|
+
|
|
174
226
|
const now = new Date().toISOString();
|
|
175
|
-
writeThread(dir, t, { id: t, item, sessions: [], created_at: now, in_at: 0 });
|
|
227
|
+
writeThread(dir, t, { id: t, item, entry, sessions: [], created_at: now, in_at: 0 });
|
|
176
228
|
|
|
177
229
|
return t;
|
|
178
230
|
}
|
|
@@ -291,8 +343,8 @@ function flagsOf({ dir, td, spec, adapter }, settings) {
|
|
|
291
343
|
* Run thread `t` of project `dir` until its session idles out, is stopped, or ends: a job of
|
|
292
344
|
* sessions (AD-41), each resumed from the one before, a fresh one after a handoff (AD-42).
|
|
293
345
|
* `spec` (its `spec.json`): `agent`, `rules` `{deny, ask, allow}`, `mcp` (config files),
|
|
294
|
-
* `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `timeoutMin
|
|
295
|
-
* operator stopped it.
|
|
346
|
+
* `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `timeoutMin`, `pick` (the project's
|
|
347
|
+
* model and effort, under the thread's own). `stopped()` says the operator stopped it.
|
|
296
348
|
* @param {{stopped?: () => boolean}} [opts]
|
|
297
349
|
*/
|
|
298
350
|
export async function runThread(dir, t, spec, opts = {}) {
|
|
@@ -528,7 +580,8 @@ function jobOf(s, record) {
|
|
|
528
580
|
prompt: (kind, _caps, rec) => (rec?.ended === 'limit' ? AFTER_LIMIT : null),
|
|
529
581
|
// The flags come before the chat of each session (job.js): the chat says what they picked.
|
|
530
582
|
flags: (kind) => {
|
|
531
|
-
s.pick
|
|
583
|
+
// The thread's own pick over the project's (`spec.pick`, as the thread's agent started).
|
|
584
|
+
s.pick = { ...wordsOf(spec.pick), ...pickIn(s.td) };
|
|
532
585
|
|
|
533
586
|
return s.flags(kind, s.summary, s.pick);
|
|
534
587
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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",
|
|
@@ -71,6 +71,8 @@ export type ChatEvent = At &
|
|
|
71
71
|
title: string;
|
|
72
72
|
reason?: string;
|
|
73
73
|
always?: string;
|
|
74
|
+
/** `always` holds for any arguments of the tool (one MCP tool, bare). */
|
|
75
|
+
always_wide?: boolean;
|
|
74
76
|
}
|
|
75
77
|
| { type: 'allowed'; request_id: string; by: 'operator'; always: boolean; rule?: string }
|
|
76
78
|
| {
|
|
@@ -132,6 +134,8 @@ export interface Rule {
|
|
|
132
134
|
export interface Thread {
|
|
133
135
|
id: string;
|
|
134
136
|
item: string | null;
|
|
137
|
+
/** The inbox entry the thread drafts an item from (Draft with agent); null for none. */
|
|
138
|
+
entry: string | null;
|
|
135
139
|
sessions: { session_id?: string; ended: string; kind: string; summary?: string }[];
|
|
136
140
|
created_at: string;
|
|
137
141
|
in_at: number;
|
|
@@ -148,6 +152,8 @@ export interface ThreadSpec {
|
|
|
148
152
|
skill?: string;
|
|
149
153
|
mainLock?: string | null;
|
|
150
154
|
timeoutMin?: number;
|
|
155
|
+
/** The project's model and effort: a session takes them where the thread picked none. */
|
|
156
|
+
pick?: AgentPick;
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
/** The model and effort an operator picked, `chats/<t>/agent.json`: none, the agent's own. */
|
|
@@ -169,8 +175,12 @@ export declare function setThreadAgent(
|
|
|
169
175
|
pick: { model?: string | null; effort?: string | null },
|
|
170
176
|
): AgentPick;
|
|
171
177
|
export declare function presetsOf(agent: string): AgentPresets;
|
|
172
|
-
export declare function createThread(
|
|
178
|
+
export declare function createThread(
|
|
179
|
+
dir: string,
|
|
180
|
+
opts?: { item?: string | null; entry?: string | null },
|
|
181
|
+
): string;
|
|
173
182
|
export declare function threadOf(dir: string, item: string): string | null;
|
|
183
|
+
export declare function threadOfEntry(dir: string, entry: string): string | null;
|
|
174
184
|
export declare function threadDir(dir: string, t: string): string;
|
|
175
185
|
export declare function readThread(dir: string, t: string): Thread;
|
|
176
186
|
export declare function listThreads(dir: string): Thread[];
|
package/package.json
CHANGED