gcf-board 0.18.8 → 0.20.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.
@@ -63,6 +63,11 @@ const PATH_GLOB = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' };
63
63
  // How much of a refused call the chat keeps: its command or file, and what it was for.
64
64
  const TITLE_MAX = 2000;
65
65
  const WHY_MAX = 500;
66
+ // A task's start keeps the head of what it was told, its end the head of its report; one
67
+ // progress in TASK_EVERY_MS per task reaches the chat (one comes after each call it makes).
68
+ const TASK_PROMPT_MAX = 1000;
69
+ const TASK_SUMMARY_MAX = 4000;
70
+ const TASK_EVERY_MS = 2000;
66
71
  const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}…` : s);
67
72
 
68
73
  // A shell line's pieces: a quoted string whole (an unclosed one to the end), a separator, a run
@@ -730,6 +735,47 @@ function permit(c, e) {
730
735
  waitCards(c);
731
736
  }
732
737
 
738
+ /**
739
+ * Whether a task's event (`{phase, id}`) reaches the chat at `now`: one progress per
740
+ * TASK_EVERY_MS per task. Within the gap the last one waits, and `later` posts it as the gap
741
+ * ends: a long step after it keeps its words. Any event that goes now drops the one held, which
742
+ * is older: a late timer would post it over the newer (the audit of 2026-11-03).
743
+ * `c` holds `taskAt` and `taskHeld` (maps by task id).
744
+ */
745
+ export function taskGate(c, e, now, later) {
746
+ const held = c.taskHeld.get(e.id);
747
+ if (e.phase === 'progress') {
748
+ const left = (c.taskAt.get(e.id) ?? 0) + TASK_EVERY_MS - now;
749
+ if (left > 0) {
750
+ if (held) held.e = e;
751
+ else {
752
+ const h = { e, timer: setTimeout(later, left) };
753
+ h.timer.unref?.();
754
+ c.taskHeld.set(e.id, h);
755
+ }
756
+
757
+ return false;
758
+ }
759
+ c.taskAt.set(e.id, now);
760
+ }
761
+ if (held) {
762
+ clearTimeout(held.timer);
763
+ c.taskHeld.delete(e.id);
764
+ }
765
+ if (e.phase === 'end') c.taskAt.delete(e.id);
766
+
767
+ return true;
768
+ }
769
+
770
+ /** The progress a task held back, taken out once its gap is over: it is posted now. */
771
+ function flushed(c, id) {
772
+ const { e } = c.taskHeld.get(id);
773
+ c.taskHeld.delete(id);
774
+ c.taskAt.set(id, 0);
775
+
776
+ return e;
777
+ }
778
+
733
779
  /** Refuse a tool call (`{request_id, tool}`) by the engine's own word, with no card before it. */
734
780
  function refuse(c, { request_id: requestId, tool }, message, more = {}) {
735
781
  send(c, c.encode.deny(requestId, message));
@@ -792,6 +838,31 @@ const SEEN = {
792
838
  },
793
839
  cancel: (c, e) => dropCard(c, e.request_id),
794
840
  result: (c, e) => turnEnd(c, e),
841
+ // A subagent or a background shell: what it was started for, what it does, how it ended. A
842
+ // progress comes after each call it makes: one in TASK_EVERY_MS reaches the chat.
843
+ task: (c, e) => {
844
+ const later = () => {
845
+ const last = flushed(c, e.id);
846
+ if (!c.closed) SEEN.task(c, last);
847
+ };
848
+ if (!taskGate(c, e, Date.now(), later)) return;
849
+ const prompt = e.phase === 'start' ? e.prompt : null;
850
+ post(c, {
851
+ type: 'task',
852
+ phase: e.phase,
853
+ id: e.id,
854
+ ...(e.kind ? { kind: e.kind } : {}),
855
+ ...(e.agent ? { agent: e.agent } : {}),
856
+ ...(e.description ? { description: cut(e.description, WHY_MAX) } : {}),
857
+ ...(e.doing ? { doing: cut(e.doing, WHY_MAX) } : {}),
858
+ ...(prompt ? { prompt: cut(prompt, TASK_PROMPT_MAX) } : {}),
859
+ ...(e.calls !== null ? { calls: e.calls } : {}),
860
+ ...(e.ms !== null ? { ms: e.ms } : {}),
861
+ ...(e.status ? { status: e.status } : {}),
862
+ ...(e.summary ? { summary: cut(e.summary, TASK_SUMMARY_MAX) } : {}),
863
+ ...(e.background ? { background: true } : {}),
864
+ });
865
+ },
795
866
  // While they run, no answer is waited for; claude starts a turn itself as they end. Their end
796
867
  // with no new turn after the grace settles the session, so it is not held for good.
797
868
  background: (c, e) => {
@@ -911,6 +982,9 @@ function chatState(opts) {
911
982
  ...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
912
983
  ...{ stopped: false, grace: null, idle: false, inTurn: true, tasks: [] },
913
984
  ...{ proposals: new Map(), calls: new Map(), heard: false, summary: null, wanted: null },
985
+ // When each task's last progress reached the chat; the last one it held back since.
986
+ taskAt: new Map(),
987
+ taskHeld: new Map(),
914
988
  why: null,
915
989
  ...{ hold: false, late: false, pending: [], echoes: [] },
916
990
  };
@@ -39,12 +39,18 @@ function absorb(seen, a) {
39
39
  /**
40
40
  * The handoff watch of one session (see `runSession`): `see(a, model)` takes each activity,
41
41
  * flags the session past its share or at a compaction (`handoff.flag`), and calls `stop` once it
42
- * works on past more. `windowOf(model)` is the window the share is taken of.
42
+ * works on past more. `windowOf(model)` is the window the share is taken of. A run's `fresh`
43
+ * session (no resume) over the share at its first reading starts there: a fresh one after it,
44
+ * on the same prompt, would too, so the share does not hand it over (a live run at 10%, 2026-11-03: three sessions of 19% each
45
+ * handed over before any work, and the item blocked); a compaction still does.
43
46
  */
44
- function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
47
+ function handoffWatch(handoff, windowOf, write, { stop, onFlag, fresh = false }) {
45
48
  /** @type {{flagged: boolean, after: number, context: number, turn?: string, unknown: boolean,
46
- * info?: object}} */
47
- const w = { flagged: false, after: 0, context: 0, turn: undefined, unknown: false };
49
+ * info?: object, readings: number, under: boolean}} */
50
+ const w = {
51
+ ...{ flagged: false, after: 0, context: 0, turn: undefined, unknown: false },
52
+ ...{ readings: 0, under: false },
53
+ };
48
54
  const unknownOnce = (model) => {
49
55
  if (w.unknown) return;
50
56
  w.unknown = true;
@@ -69,7 +75,16 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
69
75
  // No share is under every threshold: a session of an unknown window hands over at a compaction.
70
76
  const share = pct ?? 0;
71
77
  if (pct === null && !compacted) unknownOnce(model);
72
- if (!w.flagged && (compacted || share >= handoff.pct)) flag(win, pct, compacted);
78
+ // A run's fresh session starts from the same prompt; a project chat's, from a summary.
79
+ const under = fresh && !handoff.soft && w.readings === 1 && share >= handoff.pct;
80
+ if (under && !compacted && !w.under) {
81
+ w.under = true;
82
+ write([
83
+ `[${clock()}] handoff: off, the session starts at ${pct}% of the window, over ` +
84
+ `context_handoff_pct ${handoff.pct}: a fresh session would start there too; raise it`,
85
+ ]);
86
+ }
87
+ if (!w.flagged && (compacted || (share >= handoff.pct && !w.under))) flag(win, pct, compacted);
73
88
  // A project chat hands over by its summary turn, which goes on past the flag (AD-42).
74
89
  if (handoff.soft) return;
75
90
  if (w.flagged && (w.after > HARD_TURNS || share >= handoff.pct + HARD_OVER)) {
@@ -83,6 +98,7 @@ function handoffWatch(handoff, windowOf, write, { stop, onFlag }) {
83
98
  see(a, model) {
84
99
  if (a.context !== undefined) {
85
100
  w.context = a.context;
101
+ w.readings++;
86
102
  if (w.flagged && a.turn !== w.turn) w.after++;
87
103
  w.turn = a.turn;
88
104
  }
@@ -292,6 +308,7 @@ export function runSession(s) {
292
308
  const watch = handoffWatch(handoff, windowOf, write, {
293
309
  stop: stop('handoff'),
294
310
  onFlag: flagged,
311
+ fresh: !s.resume,
295
312
  });
296
313
  const limit = sessionTimeout(timeoutMs, stop('timeout'), { halt, stop: stop('stopped') });
297
314
  /** @type {((tokens: number, model?: string) => void) | null} */
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-session",
3
- "version": "0.17.6",
3
+ "version": "0.18.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",
@@ -46,6 +46,22 @@ export type ChatEvent = At &
46
46
  /** `id`: the input line of the operator's message it did not send, when it has one. */
47
47
  | { type: 'error'; text: string; id?: string }
48
48
  | { type: 'background'; tasks: { id: string; description: string }[] }
49
+ /** A subagent's or a background shell's start, progress (one in 2 s) or end. */
50
+ | {
51
+ type: 'task';
52
+ phase: 'start' | 'progress' | 'end';
53
+ id: string;
54
+ kind?: string;
55
+ agent?: string;
56
+ description?: string;
57
+ doing?: string;
58
+ prompt?: string;
59
+ calls?: number;
60
+ ms?: number;
61
+ status?: string;
62
+ summary?: string;
63
+ background?: boolean;
64
+ }
49
65
  | {
50
66
  type: 'question';
51
67
  request_id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-board",
3
- "version": "0.18.8",
3
+ "version": "0.20.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",