gcf-board 0.28.1 → 0.30.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 -1
- package/dist/server/aif-entry.js +76 -0
- package/dist/server/app.js +59 -5
- package/dist/server/chat.js +34 -0
- package/dist/server/cli.js +17 -2
- package/dist/server/moves.js +3 -2
- package/dist/server/reviewPresets.js +35 -0
- package/dist/server/runs.js +6 -3
- package/dist/server/talks.js +23 -8
- package/dist/web/assets/index-BhGhi45o.css +1 -0
- package/dist/web/assets/index-zKctM0qB.js +123 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/adapter/claude.js +1 -1
- package/node_modules/gcf-session/lib/adapter/codex.js +137 -0
- package/node_modules/gcf-session/lib/chat-input.js +14 -1
- package/node_modules/gcf-session/lib/chat.js +14 -2
- package/node_modules/gcf-session/lib/cli.js +7 -2
- package/node_modules/gcf-session/lib/index.js +10 -0
- package/node_modules/gcf-session/lib/job.js +93 -15
- package/node_modules/gcf-session/lib/limit.js +9 -5
- package/node_modules/gcf-session/lib/thread.js +5 -4
- package/node_modules/gcf-session/lib/usage.js +19 -4
- package/node_modules/gcf-session/lib/wake.js +141 -0
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +52 -2
- package/package.json +1 -1
- package/dist/web/assets/index-BHNTx9zd.css +0 -1
- package/dist/web/assets/index-UBIHpB-m.js +0 -119
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The early wake of a usage-limit wait (Operator-Tasks-Plan t1 d1): the operator's mark, which
|
|
2
|
+
// only they can set (they know the limit was reset early), or a fresh `/usage` reading that says
|
|
3
|
+
// the limit is back. A card's run and a project chat thread build theirs here alike.
|
|
4
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { alive } from './proc.js';
|
|
7
|
+
import { THREAD_ID, threadDir } from './thread.js';
|
|
8
|
+
import { USAGE_MAX_AGE_MS, limitBack, readUsage } from './usage.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The claude that answers `/usage` for an agent: GCF_USAGE_AGENT, else claude for a claude
|
|
12
|
+
* agent; null for another agent, which has no `/usage` (the framework is stack-agnostic).
|
|
13
|
+
* @param {string | null | undefined} agent
|
|
14
|
+
*/
|
|
15
|
+
export function usageCommand(agent) {
|
|
16
|
+
if (process.env.GCF_USAGE_AGENT) return process.env.GCF_USAGE_AGENT;
|
|
17
|
+
|
|
18
|
+
return /^"?claude(\.exe|\.cmd)?"?(\s|$)/.test(String(agent ?? '')) ? 'claude' : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} Wake the job's `wake` (job.js `limitWait`)
|
|
23
|
+
* @property {(o: {now: number, until: Date, pct?: number, usage?: boolean}) => void} begin a
|
|
24
|
+
* wait starts: an old mark goes, readings count from `now`; `pct` the reserve's percent (0:
|
|
25
|
+
* the limit's wait); `usage` false: only the mark wakes it
|
|
26
|
+
* @property {(now: number) => 'operator' | 'usage' | null} by what woke the wait, if anything
|
|
27
|
+
* @property {() => void} end the wait ended: no more asks
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The wake of a limit wait. `mark` is the operator's file (`<logs>/<id>.wake`,
|
|
32
|
+
* `chats/<t>/wake`); `reading()` gives the reading another watch already keeps (automation's
|
|
33
|
+
* reserve), else `command` is asked every `pollMs` while a wait lives; neither: the mark alone.
|
|
34
|
+
* `onWake(by, until)` hears each wake.
|
|
35
|
+
* @param {{mark: string, model?: string | null, command?: string | null,
|
|
36
|
+
* reading?: (() => any) | null, pollMs?: number,
|
|
37
|
+
* onWake?: (by: 'operator' | 'usage', until: Date) => void}} o
|
|
38
|
+
* @returns {Wake}
|
|
39
|
+
*/
|
|
40
|
+
export function wakeWatch({
|
|
41
|
+
mark,
|
|
42
|
+
model = null,
|
|
43
|
+
command = null,
|
|
44
|
+
reading = null,
|
|
45
|
+
pollMs = USAGE_MAX_AGE_MS,
|
|
46
|
+
onWake,
|
|
47
|
+
}) {
|
|
48
|
+
let since = 0;
|
|
49
|
+
let pct = 0;
|
|
50
|
+
let usage = false;
|
|
51
|
+
/** @type {Date} */
|
|
52
|
+
let until = new Date(0);
|
|
53
|
+
let own = null;
|
|
54
|
+
/** @type {ReturnType<typeof setInterval> | null} */
|
|
55
|
+
let timer = null;
|
|
56
|
+
const read = async () => {
|
|
57
|
+
try {
|
|
58
|
+
own = await readUsage({ command: /** @type {string} */ (command), maxAgeMs: pollMs });
|
|
59
|
+
} catch {
|
|
60
|
+
// No reading: the wait goes on by the clock and the mark.
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const woke = (by) => {
|
|
65
|
+
onWake?.(by, until);
|
|
66
|
+
|
|
67
|
+
return by;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
begin(o) {
|
|
72
|
+
// A mark left from an earlier wait, or written as one ended, would end this one at once.
|
|
73
|
+
rmSync(mark, { force: true });
|
|
74
|
+
({ now: since, until } = o);
|
|
75
|
+
pct = o.pct ?? 0;
|
|
76
|
+
usage = o.usage !== false && Boolean(reading || command);
|
|
77
|
+
if (!usage || reading) return;
|
|
78
|
+
void read();
|
|
79
|
+
timer = setInterval(() => void read(), pollMs);
|
|
80
|
+
timer.unref?.();
|
|
81
|
+
},
|
|
82
|
+
by(now) {
|
|
83
|
+
if (existsSync(mark)) {
|
|
84
|
+
rmSync(mark, { force: true });
|
|
85
|
+
|
|
86
|
+
return woke('operator');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return usage && limitBack(reading ? reading() : own, since, { model, pct, now })
|
|
90
|
+
? woke('usage')
|
|
91
|
+
: null;
|
|
92
|
+
},
|
|
93
|
+
end() {
|
|
94
|
+
if (timer) clearInterval(timer);
|
|
95
|
+
timer = null;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The last wait event of a chat file's lines: `limit` while a wait lives, else another. */
|
|
101
|
+
export function lastWaitEvent(text) {
|
|
102
|
+
const lines = text.split('\n').filter(Boolean);
|
|
103
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
104
|
+
const type = /"type":"(session|session_end|limit|limit_end)"/.exec(lines[i])?.[1];
|
|
105
|
+
if (type) return type;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Whether project chat thread `t` waits for the limit's reset now (t1 d1): its feed's last wait
|
|
113
|
+
* event is `limit` and its opener lives.
|
|
114
|
+
* @param {string} dir the project
|
|
115
|
+
* @param {string} t
|
|
116
|
+
*/
|
|
117
|
+
export function threadWaits(dir, t) {
|
|
118
|
+
const td = threadDir(dir, t);
|
|
119
|
+
try {
|
|
120
|
+
const text = readFileSync(path.join(td, 'chat.jsonl'), 'utf8');
|
|
121
|
+
const pid = Number(readFileSync(path.join(td, 'open.lock'), 'utf8').trim());
|
|
122
|
+
|
|
123
|
+
return lastWaitEvent(text) === 'limit' && alive(pid);
|
|
124
|
+
} catch {
|
|
125
|
+
// No feed or no opener: nothing waits.
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Wake thread `t`'s limit wait (t1 d4): its mark, only while a wait lives. Returns what it did.
|
|
132
|
+
* @param {string} dir the project
|
|
133
|
+
* @param {string} t
|
|
134
|
+
*/
|
|
135
|
+
export function wakeThread(dir, t) {
|
|
136
|
+
if (!THREAD_ID.test(t)) throw new Error(`${t} is not a thread id`);
|
|
137
|
+
if (!threadWaits(dir, t)) return `nothing waits in thread ${t}`;
|
|
138
|
+
writeFileSync(path.join(threadDir(dir, t), 'wake'), `${new Date().toISOString()}\n`);
|
|
139
|
+
|
|
140
|
+
return `woke thread ${t}: its session goes on now`;
|
|
141
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|
|
@@ -25,7 +25,8 @@ export type ChatEvent = At &
|
|
|
25
25
|
cost_usd: number | null;
|
|
26
26
|
limit_resets?: string | null;
|
|
27
27
|
}
|
|
28
|
-
| { type: 'limit'; until: string }
|
|
28
|
+
| { type: 'limit'; until: string; reserve?: boolean; pct?: number }
|
|
29
|
+
| { type: 'limit_end'; by: 'operator' | 'usage' | 'clock' | 'stop' | 'hold' }
|
|
29
30
|
/** The operator's Hold or the quota's reserve: the session hands over (Hold-Plan d4). */
|
|
30
31
|
| { type: 'held'; reason: 'hold' | 'reserve' | string }
|
|
31
32
|
/** A project chat's: the operator closed its agent; `dropped` messages it never took in. */
|
|
@@ -265,7 +266,7 @@ export interface UsageReading {
|
|
|
265
266
|
}
|
|
266
267
|
export type ReserveGate =
|
|
267
268
|
| { go: true }
|
|
268
|
-
| { wait: true; until: Date; reserve: true }
|
|
269
|
+
| { wait: true; until: Date; reserve: true; pct?: number; keep?: number }
|
|
269
270
|
| { stop: true; why: 'reserve'; reserve: { weekly?: boolean; until?: string | null } };
|
|
270
271
|
export declare const RESERVE_PCT: number;
|
|
271
272
|
export declare const USAGE_MAX_AGE_MS: number;
|
|
@@ -303,3 +304,52 @@ export declare function reserveOfReading(
|
|
|
303
304
|
pct: number,
|
|
304
305
|
now?: number,
|
|
305
306
|
): ReserveGate;
|
|
307
|
+
|
|
308
|
+
// The early wake of a usage-limit wait (Operator-Tasks-Plan t1).
|
|
309
|
+
export declare function limitBack(
|
|
310
|
+
reading: UsageReading | null | undefined,
|
|
311
|
+
since: number,
|
|
312
|
+
o?: { model?: string | null; pct?: number; now?: number },
|
|
313
|
+
): boolean;
|
|
314
|
+
export declare function usageCommand(agent: string | null | undefined): string | null;
|
|
315
|
+
export interface Wake {
|
|
316
|
+
begin(o: { now: number; until: Date; pct?: number; usage?: boolean }): void;
|
|
317
|
+
by(now: number): 'operator' | 'usage' | null;
|
|
318
|
+
end(): void;
|
|
319
|
+
}
|
|
320
|
+
export declare function wakeWatch(o: {
|
|
321
|
+
mark: string;
|
|
322
|
+
model?: string | null;
|
|
323
|
+
command?: string | null;
|
|
324
|
+
reading?: (() => UsageReading | null) | null;
|
|
325
|
+
pollMs?: number;
|
|
326
|
+
onWake?: (by: 'operator' | 'usage', until: Date) => void;
|
|
327
|
+
}): Wake;
|
|
328
|
+
export declare function lastWaitEvent(text: string): string | null;
|
|
329
|
+
export declare function threadWaits(dir: string, t: string): boolean;
|
|
330
|
+
export declare function wakeThread(dir: string, t: string): string;
|
|
331
|
+
|
|
332
|
+
// The Codex CLI as a reviewer (Operator-Tasks-Plan t2 d4).
|
|
333
|
+
export interface CodexModel {
|
|
334
|
+
slug: string;
|
|
335
|
+
family: string;
|
|
336
|
+
version: number[];
|
|
337
|
+
priority: number;
|
|
338
|
+
efforts: string[];
|
|
339
|
+
}
|
|
340
|
+
export interface CodexCommand {
|
|
341
|
+
exe: string;
|
|
342
|
+
pre: string[];
|
|
343
|
+
shell: boolean;
|
|
344
|
+
}
|
|
345
|
+
export declare function codexCommand(): CodexCommand;
|
|
346
|
+
export declare function codexInstalled(cmd?: CodexCommand): boolean;
|
|
347
|
+
export declare function codexModels(o?: {
|
|
348
|
+
cache?: string;
|
|
349
|
+
cmd?: CodexCommand;
|
|
350
|
+
}): CodexModel[] | null;
|
|
351
|
+
export declare function familyOf(slug: string): { family: string; version: number[] } | null;
|
|
352
|
+
export declare function slugOf(models: CodexModel[] | null, model: string): string | null;
|
|
353
|
+
export declare function codexPresets(
|
|
354
|
+
models: CodexModel[] | null,
|
|
355
|
+
): { model: string; slug: string; efforts: string[] }[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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",
|