gcf-board 0.8.2 → 0.9.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 +106 -104
- package/dist/server/app.js +137 -9
- package/dist/server/chat.js +21 -9
- package/dist/server/cli.js +5 -0
- package/dist/server/files.js +17 -0
- package/dist/server/runs.js +22 -6
- package/dist/server/talks.js +22 -1
- package/dist/web/assets/{index-aCBpVSeA.css → index-UzVgbCWq.css} +1 -1
- package/dist/web/assets/index-m10Wkvhe.js +39 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/index.js +1 -0
- package/node_modules/gcf-session/lib/thread.js +71 -21
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +7 -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-m10Wkvhe.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-UzVgbCWq.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
|
@@ -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) =>
|
|
@@ -142,10 +147,10 @@ export function setThreadAgent(dir, t, pick) {
|
|
|
142
147
|
return kept;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
/** The thread
|
|
146
|
-
|
|
150
|
+
/** The thread of mark `kind/key`, or null. */
|
|
151
|
+
function boundTo(dir, kind, key) {
|
|
147
152
|
try {
|
|
148
|
-
const t = readFileSync(
|
|
153
|
+
const t = readFileSync(markOf(dir, kind, key), 'utf8').trim();
|
|
149
154
|
|
|
150
155
|
return THREAD_ID.test(t) && existsSync(threadDir(dir, t)) ? t : null;
|
|
151
156
|
} catch {
|
|
@@ -153,26 +158,71 @@ export function threadOf(dir, item) {
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
|
|
161
|
+
/** The thread bound to `item`, or null (AD-46). */
|
|
162
|
+
export const threadOf = (dir, item) => boundTo(dir, 'items', item);
|
|
163
|
+
|
|
164
|
+
/** The thread bound to inbox entry `entry` (Draft with agent), or null. */
|
|
165
|
+
export const threadOfEntry = (dir, entry) => boundTo(dir, 'entries', entry);
|
|
166
|
+
|
|
156
167
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
168
|
+
* Bind new thread `t` to `key`, exclusively: the thread that holds the mark, `t` when it took
|
|
169
|
+
* it. Taken by a thread made just now: that one, and `t` goes. A mark whose thread is gone (its
|
|
170
|
+
* folder erased by hand) is stale: `t` takes it over.
|
|
159
171
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
function takeMark(dir, kind, key, t) {
|
|
173
|
+
const had = markOnce(dir, [kind, key], t);
|
|
174
|
+
if (had) return had;
|
|
175
|
+
// A stale mark is moved aside under this thread's own name, then taken exclusively again: of
|
|
176
|
+
// two at once, the one whose move fails finds the other's mark on its last try.
|
|
177
|
+
// shortcut: a mark read between another's create and its write looks stale (empty); two boards
|
|
178
|
+
// on one project in that instant could still split a thread.
|
|
179
|
+
const aside = `${markOf(dir, kind, key)}.${t}`;
|
|
180
|
+
try {
|
|
181
|
+
renameSync(markOf(dir, kind, key), aside);
|
|
182
|
+
rmSync(aside, { force: true });
|
|
183
|
+
} catch {
|
|
184
|
+
// Moved by the other one: its mark wins below.
|
|
172
185
|
}
|
|
173
186
|
|
|
187
|
+
return markOnce(dir, [kind, key], t, true);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* One exclusive try at the mark: `t` when taken, the thread that holds it, or null for a stale
|
|
192
|
+
* one (`last`: throw then). `t`'s folder goes when it does not get the mark.
|
|
193
|
+
*/
|
|
194
|
+
function markOnce(dir, [kind, key], t, last = false) {
|
|
195
|
+
try {
|
|
196
|
+
writeFileSync(markOf(dir, kind, key), t, { flag: 'wx' });
|
|
197
|
+
|
|
198
|
+
return t;
|
|
199
|
+
} catch (e) {
|
|
200
|
+
const taken = /** @type {any} */ (e).code === 'EEXIST';
|
|
201
|
+
const won = taken ? boundTo(dir, kind, key) : null;
|
|
202
|
+
if (!won && taken && !last) return null;
|
|
203
|
+
rmSync(threadDir(dir, t), { recursive: true, force: true });
|
|
204
|
+
if (won) return won;
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A new thread, its id; bound to `item` or to inbox `entry`, the one it already has (AD-46).
|
|
211
|
+
* Ids and the marks are made exclusively: two at once never take one id, nor give an item or an
|
|
212
|
+
* entry two threads. Both `item` and `entry` is a RangeError.
|
|
213
|
+
*/
|
|
214
|
+
export function createThread(dir, { item = null, entry = null } = {}) {
|
|
215
|
+
if (item && entry) throw new RangeError('a thread is bound to an item or an entry, not both');
|
|
216
|
+
const [kind, key] = item ? ['items', item] : ['entries', entry];
|
|
217
|
+
const had = key ? boundTo(dir, kind, key) : null;
|
|
218
|
+
if (had) return had;
|
|
219
|
+
mkdirSync(path.join(chatsDir(dir), kind), { recursive: true });
|
|
220
|
+
const t = newDir(dir);
|
|
221
|
+
const won = key ? takeMark(dir, kind, key, t) : t;
|
|
222
|
+
if (won !== t) return won;
|
|
223
|
+
|
|
174
224
|
const now = new Date().toISOString();
|
|
175
|
-
writeThread(dir, t, { id: t, item, sessions: [], created_at: now, in_at: 0 });
|
|
225
|
+
writeThread(dir, t, { id: t, item, entry, sessions: [], created_at: now, in_at: 0 });
|
|
176
226
|
|
|
177
227
|
return t;
|
|
178
228
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|
|
@@ -132,6 +132,8 @@ export interface Rule {
|
|
|
132
132
|
export interface Thread {
|
|
133
133
|
id: string;
|
|
134
134
|
item: string | null;
|
|
135
|
+
/** The inbox entry the thread drafts an item from (Draft with agent); null for none. */
|
|
136
|
+
entry: string | null;
|
|
135
137
|
sessions: { session_id?: string; ended: string; kind: string; summary?: string }[];
|
|
136
138
|
created_at: string;
|
|
137
139
|
in_at: number;
|
|
@@ -169,8 +171,12 @@ export declare function setThreadAgent(
|
|
|
169
171
|
pick: { model?: string | null; effort?: string | null },
|
|
170
172
|
): AgentPick;
|
|
171
173
|
export declare function presetsOf(agent: string): AgentPresets;
|
|
172
|
-
export declare function createThread(
|
|
174
|
+
export declare function createThread(
|
|
175
|
+
dir: string,
|
|
176
|
+
opts?: { item?: string | null; entry?: string | null },
|
|
177
|
+
): string;
|
|
173
178
|
export declare function threadOf(dir: string, item: string): string | null;
|
|
179
|
+
export declare function threadOfEntry(dir: string, entry: string): string | null;
|
|
174
180
|
export declare function threadDir(dir: string, t: string): string;
|
|
175
181
|
export declare function readThread(dir: string, t: string): Thread;
|
|
176
182
|
export declare function listThreads(dir: string): Thread[];
|
package/package.json
CHANGED