gcf-board 0.28.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.
@@ -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-CcsKtA2D.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-BCfiz95-.css">
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>
@@ -901,22 +901,7 @@ const SEEN = {
901
901
  };
902
902
 
903
903
  if (!taskGate(c, e, Date.now(), later)) return;
904
- const prompt = e.phase === 'start' ? e.prompt : null;
905
- post(c, {
906
- type: 'task',
907
- phase: e.phase,
908
- id: e.id,
909
- ...(e.kind ? { kind: e.kind } : {}),
910
- ...(e.agent ? { agent: e.agent } : {}),
911
- ...(e.description ? { description: cut(e.description, WHY_MAX) } : {}),
912
- ...(e.doing ? { doing: cut(e.doing, WHY_MAX) } : {}),
913
- ...(prompt ? { prompt: cut(prompt, TASK_PROMPT_MAX) } : {}),
914
- ...(e.calls !== null ? { calls: e.calls } : {}),
915
- ...(e.ms !== null ? { ms: e.ms } : {}),
916
- ...(e.status ? { status: e.status } : {}),
917
- ...(e.summary ? { summary: cut(e.summary, TASK_SUMMARY_MAX) } : {}),
918
- ...(e.background ? { background: true } : {}),
919
- });
904
+ post(c, taskCard(e));
920
905
  },
921
906
  // While they run, no answer is waited for; claude starts a turn itself as they end. Their end
922
907
  // with no new turn after the grace settles the session, so it is not held for good.
@@ -928,6 +913,27 @@ const SEEN = {
928
913
  },
929
914
  };
930
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
+
931
937
  // The events that say a new turn has begun: the messages it echoes count themselves.
932
938
  const TURN = new Set(['said', 'read', 'tool_call', 'tool_result']);
933
939
 
@@ -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) spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' });
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
- // A run's fresh session starts from the same prompt; a project chat's, from a summary.
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
- if (w.flagged && (w.after > HARD_TURNS || share >= handoff.pct + HARD_OVER)) {
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, id, onSpawn, handoff, quota, chat, observe, halt, ownReply } = s;
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
- 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
- }
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
- if (item && entry) throw new RangeError('a thread is bound to an item or an entry, not both');
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'], { stdio: 'ignore' });
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');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-session",
3
- "version": "0.19.2",
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.28.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",