gcf-harness-aif-ext 0.19.1 → 0.21.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 CHANGED
@@ -47,6 +47,12 @@ Updating keeps the hook entry valid — it points into the extension's install d
47
47
 
48
48
  0.5.1 is a fix release. During a run, `gcf/config.yml` is always readable, and a Grep inside `gcf/` reads only readset files. An import breaks a `depends:` cycle the pair checks closed and asks a D1 about it. It cuts a section longer than a segment at paragraphs, and lens and pair prompts carry a window around the quote. `/gcf-run` checks the plan against each pillar's invariant and asks each pillar's review question over the diff. Use it with core 0.4.1, which brings the parent feature into the readset.
49
49
 
50
+ 0.21.1: `/gcf-run` treats a `format:` line of `gcf plan check` (core 0.21: the plan's form against the plan profile) as polish its improve passes apply, never a block. It takes core 0.20 or 0.21 (the peer range of 0.21.0 left 0.21 out).
51
+
52
+ 0.21.0 (bundled gcf-session 0.18.0): `run_end` also names the run's last DoD (`green`, `red`, `unknown`) and review, and the files a worktree run left uncommitted (`left`: the worktree, how many files; a rerun goes on there). A run's chat carries its subagents' and background shells' `task` events: the board shows what each does.
53
+
54
+ 0.20.0 (bundled gcf-session 0.17.4): each item's run chat ends with `run_end`: the outcome, the reason word for word, cost, duration, main's commit, plan tasks left unticked, lessons, a broken step. The board draws it as the run's end card.
55
+
50
56
  0.19.1: `next --plan` first closes the features whose children are all finished: a keep by the operator, with no run after it, finishes them too. `card` reports a unit that left design without its item as `drop` (a `gcf(drop)` commit) or `none`, not `card`.
51
57
 
52
58
  0.19.0 (gcf-aif-ext 0.19.0): `next --plan` gives the batch of the milestone being built, the units to card first and why nothing goes (a built milestone to play, an empty one); `--skip` leaves ids out. `gcf-harness card <units>` takes units into work in one session on main (gcf-card `--assume`). After a run the features whose children are all finished close. A run's result reads its move from the commit (`deferred`, `decide`). The skill gets `--assume` and `--decide` from the item's gates.
@@ -111,7 +117,7 @@ Updating keeps the hook entry valid — it points into the extension's install d
111
117
  0.9.0, to update together with core 0.7.6:
112
118
  - The harness's own agent runs with `--permission-mode bypassPermissions`: it may do everything but the project's deny rules, which hold in every mode. The rules come from the deny groups of `gcf/config.yml` (`ai-factory gcf permissions`, or the board): git history and uncommitted work, recursive delete, publishing, the human's GCF moves and the guards are on by default; secrets, changes outside the project and killing processes are off. `git push` is allowed. Deny rules match the command as written: they catch accidents, not a rewording, and `/gcf-run` makes a refused command a stop with `needs permission: <command>`.
113
119
  - A run loads the project's settings and MCP servers only (`--setting-sources project,local --strict-mcp-config --mcp-config .mcp.json`): the operator's plugins, hooks and claude.ai connectors stay out. So does `env` or `apiKeyHelper` in `~/.claude/settings.json`: an operator who logs in through them, not `claude login`, names the agent with `--agent`. The deny rules and the handoff guard come in `.gcf-session/runs/agent-settings.json` (`--settings`), so a worktree gets them without a commit.
114
- - Context handoff: past `context_handoff_pct` (60 by default) of the window, or at a compaction, the run flags the session; the handoff guard then denies every call of the main agent but the plan's read and edit with the instruction to write `## Handoff` into the plan and end. The run starts a fresh session with `/gcf-run <id> --handoff`, which goes on from the plan: the ticked tasks stay done. A session that works on past its flag is stopped; after 3 handoffs in a row the item is blocked with `context handoff limit`. The window is `context_window`, else the one a result of the same model reported (`.gcf-session/runs/windows.json`); with neither, the first session of a model runs without a handoff and says so. The sessions of an item share one timeout, and their costs add up; `--json` gives `handoffs`.
120
+ - Context handoff: past `context_handoff_pct` (60 by default) of the window, or at a compaction, the run flags the session; the handoff guard then denies every call of the main agent but the plan's read and edit with the instruction to write `## Handoff` into the plan and end. The run starts a fresh session with `/gcf-run <id> --handoff`, which goes on from the plan: the ticked tasks stay done. A session that works on past its flag is stopped; after 3 handoffs in a row the item is blocked with `context handoff limit`. The window is `context_window`, else the one a result of the same model reported (`.gcf-session/runs/windows.json`); with neither, the first session of a model runs without a handoff and says so. A fresh session already over the share at its first turn (claude's own prompt and the skills hold about 40k tokens) is not handed over by the share, for a fresh one would start there too: its log says `handoff: off, the session starts at N% of the window, over context_handoff_pct P`; a compaction still hands it over (0.21.0). The sessions of an item share one timeout, and their costs add up; `--json` gives `handoffs`.
115
121
  - `auto_compact_pct` sets the agent's `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE`, at least 15 points above the handoff share.
116
122
  - The readset-guard reads the manifest of the directory the session started in (`CLAUDE_PROJECT_DIR`): an agent's `cd` no longer lifts the readset.
117
123
  - `/gcf-run` writes a plan task's code through aif-implement, so the plan ticks show the item's progress, and answers aif-implement's questions itself: no commit, stash or merge.
@@ -447,13 +447,17 @@ export function gateEach(report, ids) {
447
447
  }
448
448
 
449
449
  /**
450
- * The checkout's uncommitted paths outside `gcf/`, untracked ones too (a new folder as one): a
451
- * main run's code lands among them, so the board warns before its click (Tails "Первым" 6). The
452
- * moves' own refusals guard `gcf/`. Null outside a git checkout.
450
+ * The checkout's uncommitted paths outside `gcf/` and `GLOSSARY.md`, untracked ones too (a new
451
+ * folder as one): a main run's code lands among them, so the board warns before its click (Tails
452
+ * "Первым" 6). The moves' own refusals guard `gcf/` and the glossary (core 0.21's gate scope).
453
+ * Null outside a git checkout.
453
454
  */
454
455
  export function loosePaths(dir) {
455
456
  // No optional locks: a main run's agent may be committing in the same checkout.
456
- const args = ['--no-optional-locks', 'status', '--porcelain', '-z', '--', '.', ':(exclude)gcf'];
457
+ const args = [
458
+ ...['--no-optional-locks', 'status', '--porcelain', '-z', '--', '.'],
459
+ ...[':(exclude)gcf', ':(exclude)GLOSSARY.md'],
460
+ ];
457
461
  const res = spawnSync('git', args, { cwd: dir, encoding: 'utf8' });
458
462
  if (res.status !== 0) return null;
459
463
  const parts = res.stdout.split('\0').filter(Boolean);
@@ -88,7 +88,8 @@ export function summarize(dir, since = '') {
88
88
  const finished = runs.filter((r) => !UNFINISHED.includes(r[3]));
89
89
  const reached = finished.filter((r) => ['submit', 'close', 'decide', 'deferred'].includes(r[3]));
90
90
  const spent = runs.map((r) => num(r[5])).filter((v) => v !== null);
91
- // plan-log: at, item, ok, problems; verify-log: at, item, ok, failed checks, mark
91
+ // plan-log: at, item, ok, problems, format lines (core 0.21); verify-log: at, item, ok,
92
+ // failed checks, mark
92
93
  const plans = rows(dir, 'plan-log.csv', since);
93
94
  const verifies = rows(dir, 'verify-log.csv', since).filter((r) => r[4] !== '1');
94
95
  // guard-log: at, item, hook, tool
package/commands/run.js CHANGED
@@ -988,6 +988,7 @@ async function runMain(projectDir, ids, releaseMain, ctx) {
988
988
  };
989
989
 
990
990
  items.push(await mainItem(projectDir, id, { ...ctx, dequeue }));
991
+ await postEnd(ctx, items.at(-1));
991
992
  }
992
993
  } finally {
993
994
  await rm(queueOf(logs), { force: true });
@@ -1248,11 +1249,15 @@ async function runWorktrees(claims, ctx) {
1248
1249
  );
1249
1250
 
1250
1251
  // What each session spent rides on its item's line, when the agent reported it.
1251
- return items.map((i) => {
1252
+ const lines = items.map((i) => {
1252
1253
  const r = runs.find((x) => x.id === i.id);
1253
1254
 
1254
1255
  return { ...i, ...r?.cost, ...extras(r) };
1255
1256
  });
1257
+ for (const i of lines)
1258
+ if (i.result !== 'verified') await postEnd(ctx, i, runs.find((x) => x.id === i.id)?.dir);
1259
+
1260
+ return lines;
1256
1261
  }
1257
1262
 
1258
1263
  /**
@@ -1313,6 +1318,168 @@ export const run = async (projectDir, ids, opts) => {
1313
1318
  }
1314
1319
  };
1315
1320
 
1321
+ // The outcome a run's result word reads as on the board's card.
1322
+ const OUTCOME = {
1323
+ submit: 'submitted',
1324
+ decide: 'submitted',
1325
+ deferred: 'submitted',
1326
+ close: 'submitted',
1327
+ block: 'blocked',
1328
+ error: 'failed',
1329
+ conflict: 'failed',
1330
+ paused: 'paused',
1331
+ };
1332
+ // The words that are a move of the core: the card names them beside the outcome.
1333
+ const MOVES = ['submit', 'close', 'block', 'decide', 'deferred'];
1334
+
1335
+ /** Where the core keeps item `id`'s worktree (`gcf worktree`, `worktreeOf` of the core). */
1336
+ const worktreeAt = (projectDir, id) =>
1337
+ path.join(path.resolve(projectDir), '.gcf-session', 'worktrees', id);
1338
+
1339
+ // What a run leaves in its worktree that is not its work: the gate's metrics, the session's files.
1340
+ const NOT_WORK = /^(gcf\/\.metrics\/|\.gcf-session\/)/;
1341
+
1342
+ /**
1343
+ * The paths of `git status --porcelain -z`, a rename or copy at where it went: each entry is
1344
+ * `XY path`, NUL-ended, and a rename's source follows as one more. Not ` -> ` in a line: a
1345
+ * POSIX name may hold it (the audit of 2026-11-03).
1346
+ */
1347
+ export function statusPaths(out) {
1348
+ const parts = out.split('\0');
1349
+ const paths = [];
1350
+ for (let i = 0; i < parts.length; i++) {
1351
+ const entry = parts[i];
1352
+ if (entry.length < 4) continue;
1353
+ paths.push(entry.slice(3));
1354
+ if (/[RC]/.test(entry.slice(0, 2))) i++;
1355
+ }
1356
+
1357
+ return paths;
1358
+ }
1359
+
1360
+ /**
1361
+ * The work a run left uncommitted in its worktree (`{worktree, files}`, the path from the
1362
+ * project), or null: none, or no worktree. A rerun goes on in that worktree.
1363
+ */
1364
+ export function leftIn(dir, projectDir) {
1365
+ if (!dir || !existsSync(dir)) return null;
1366
+ const res = spawnSync('git', ['status', '--porcelain', '-z', '--untracked-files=all'], {
1367
+ cwd: dir,
1368
+ encoding: 'utf8',
1369
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
1370
+ });
1371
+ if (res.status !== 0) return null;
1372
+ const files = statusPaths(res.stdout).filter((p) => !NOT_WORK.test(p)).length;
1373
+
1374
+ return files ? { worktree: path.relative(projectDir, dir).replaceAll('\\', '/'), files } : null;
1375
+ }
1376
+
1377
+ /** A step's `ok` (`step` events, milestones.js) as the run's end names it. */
1378
+ const DOD = (ok) => (ok === true ? 'green' : ok === false ? 'red' : 'unknown');
1379
+
1380
+ /**
1381
+ * How an item's run ended, for its chat (`run_end`): the outcome (submitted, blocked, failed,
1382
+ * paused, stopped, no-result, skipped), the move, the reason word for word, what it cost and
1383
+ * took, main's commit, the plan's tasks left unticked, the lessons it filed, a broken step, the
1384
+ * run's last DoD and review (from `launch.events`, its chat's events since the last run's end),
1385
+ * the work it left uncommitted in its worktree (`launch.worktree`).
1386
+ */
1387
+ export function runEndOf(i, projectDir, launch = null) {
1388
+ const result = String(i.result ?? 'merged');
1389
+ const word = result.split(/[\s:(]/)[0];
1390
+ // A stop is the operator's, a paused wait cut by it too; then a limit, then the result word.
1391
+ const stopped = /\bstopped\b/.test(result) && !OUTCOME[word]?.startsWith('sub');
1392
+ const outcome = stopped
1393
+ ? 'stopped'
1394
+ : i.limit_resets !== undefined
1395
+ ? 'paused'
1396
+ : (OUTCOME[word] ??
1397
+ (word === 'skipped' ? 'skipped' : word === 'merged' ? 'submitted' : 'no-result'));
1398
+ const plan = launch?.planOf?.(i.id) ?? null;
1399
+ let unticked = null;
1400
+ try {
1401
+ if (plan)
1402
+ unticked = (readFileSync(path.join(projectDir, plan), 'utf8').match(/^\s*- \[ \] /gm) ?? [])
1403
+ .length;
1404
+ } catch {
1405
+ // Archived with its item: nothing left.
1406
+ }
1407
+ const steps = (launch?.events ?? []).filter((e) => e.type === 'step');
1408
+ const dod = steps.findLast((e) => e.step === 'dod');
1409
+ const review = steps.findLast((e) => e.step === 'review');
1410
+
1411
+ return {
1412
+ type: 'run_end',
1413
+ outcome,
1414
+ move: MOVES.includes(word) ? word : null,
1415
+ // A failure says what failed first; a move without one says why it was made.
1416
+ reason:
1417
+ (outcome === 'failed' ? (i.error ?? i.conflict ?? i.reason) : (i.reason ?? i.error)) ??
1418
+ i.skipped ??
1419
+ (OUTCOME[word] && word !== 'paused' ? null : result),
1420
+ cost_usd: i.cost_usd ?? null,
1421
+ duration_ms: i.duration_ms ?? null,
1422
+ commit: headOf(projectDir)?.slice(0, 7) ?? null,
1423
+ unticked,
1424
+ lessons: i.lessons ?? 0,
1425
+ process: i.process ?? null,
1426
+ // null: the run reached no DoD, no review.
1427
+ dod: dod ? DOD(dod.ok) : null,
1428
+ review: review ? (review.ok === false ? 'failed' : 'done') : null,
1429
+ // A branch that went in took its work along.
1430
+ left: outcome === 'submitted' ? null : leftIn(launch?.worktree, projectDir),
1431
+ };
1432
+ }
1433
+
1434
+ /** The events of an item's chat file that are this run's. */
1435
+ export function runEvents(file) {
1436
+ let lines;
1437
+ try {
1438
+ lines = readFileSync(file, 'utf8').split('\n');
1439
+ } catch {
1440
+ return [];
1441
+ }
1442
+ const events = lines.flatMap((l) => {
1443
+ try {
1444
+ return l.trim() ? [JSON.parse(l)] : [];
1445
+ } catch {
1446
+ return [];
1447
+ }
1448
+ });
1449
+
1450
+ // A run begins after the last one's end, or at its own first session (a run killed with no
1451
+ // end left none): a handoff's session goes on in the same run.
1452
+ const from = events.findLastIndex(
1453
+ (e) => e.type === 'run_end' || (e.type === 'session' && e.kind !== 'handoff'),
1454
+ );
1455
+
1456
+ return events.slice(from < 0 ? 0 : events[from].type === 'run_end' ? from + 1 : from);
1457
+ }
1458
+
1459
+ /**
1460
+ * Post an item's run end to its chat (Tails «Первым» 2), when the run has one: not for an item
1461
+ * that never started (another run's lock), whose chat is that run's. The plan is the board's now:
1462
+ * a first run made it.
1463
+ */
1464
+ async function postEnd(ctx, item, worktree = null) {
1465
+ if (!ctx.launch?.chat || item.started === false) return;
1466
+ let plans = {};
1467
+ try {
1468
+ const now = json(await ctx.core(['board', '--json']), 'board');
1469
+ plans = Object.fromEntries((now.items ?? []).map((i) => [i.id, i.plan_file ?? null]));
1470
+ } catch {
1471
+ // No board: no plan count.
1472
+ }
1473
+
1474
+ const file = chatOut(ctx.logs, item.id);
1475
+ const end = runEndOf(item, ctx.projectDir, {
1476
+ planOf: (id) => plans[id] ?? null,
1477
+ events: runEvents(file),
1478
+ worktree,
1479
+ });
1480
+ postTo(file, end);
1481
+ }
1482
+
1316
1483
  /** Whether a commit dropped unit `id` (`gcf(drop): <id>`). */
1317
1484
  function droppedSince(projectDir, id) {
1318
1485
  const grep = String.raw`--grep=^gcf\(drop\): ` + `${id}( |$)`;
@@ -1501,13 +1668,37 @@ async function runBatch(
1501
1668
  }),
1502
1669
  );
1503
1670
  const failed = driven.find((d) => d.status === 'rejected');
1504
- if (failed) throw failed.reason;
1671
+ if (failed) {
1672
+ const error = String(failed.reason?.message ?? failed.reason);
1673
+ for (const [n, d] of driven.entries())
1674
+ if (d.status === 'rejected')
1675
+ for (const id of parts[n][1])
1676
+ await postEnd(
1677
+ ctx,
1678
+ { id, result: 'error', error },
1679
+ parts[n][0] === 'main' ? null : worktreeAt(projectDir, id),
1680
+ );
1681
+ throw failed.reason;
1682
+ }
1683
+
1505
1684
  // The branches worktree runs verified while a main part held the checkout go in now; a main
1506
1685
  // its session left dirty keeps them for the next run.
1507
1686
  const after = claims.has('main')
1508
1687
  ? (await integrateNow(core).catch(() => ({ results: [] }))).results
1509
1688
  : [];
1510
1689
  const features = await closeFinishedFeatures(core).catch(() => []);
1690
+ // A branch verified while main was held went in just now: its end is that merge's move.
1691
+ for (const d of driven)
1692
+ if (d.status === 'fulfilled')
1693
+ for (const i of d.value.filter((x) => x.result === 'verified')) {
1694
+ const merged = after.find((r) => r.id === i.id);
1695
+ const result = merged?.move ?? (merged?.conflict ? 'conflict' : i.result);
1696
+ await postEnd(
1697
+ ctx,
1698
+ { ...i, result, ...(merged?.conflict && { conflict: merged.conflict }) },
1699
+ worktreeAt(projectDir, i.id),
1700
+ );
1701
+ }
1511
1702
 
1512
1703
  // `limit_wait`: this harness waits for a usage limit's reset itself (AD-19); a board reads it.
1513
1704
  return {
package/extension.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/lee-to/ai-factory/2.x/schemas/extension.schema.json",
3
3
  "name": "gcf-harness-aif-ext",
4
- "version": "0.19.1",
4
+ "version": "0.21.1",
5
5
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
6
6
  "skills": [
7
7
  "skills/gcf-run",
@@ -201,10 +201,15 @@ export const kindOf = (tool) => KINDS[tool] ?? (/^mcp__/.test(tool) ? 'mcp' : 'o
201
201
  * | {type: 'cancel', request_id: string}
202
202
  * | {type: 'result', subtype?: string, total_cost_usd: number | null}
203
203
  * | {type: 'background', tasks: {id: string, description: string}[]}
204
+ * | {type: 'task', phase: 'start' | 'progress' | 'end', id: string, kind: string | null,
205
+ * agent: string | null, description: string | null, doing: string | null,
206
+ * prompt: string | null, calls: number | null, ms: number | null, status: string | null,
207
+ * summary: string | null, call: string | null, background: boolean}
204
208
  * | {type: 'compacted'}} Neutral
205
209
  * The events a session's work is read by, the same from any agent: what the main agent (or a
206
210
  * subagent, `sub`) said and called, the results, the operator's messages it took in, the
207
- * question and permission requests, a turn's end, the background tasks, a compaction.
211
+ * question and permission requests, a turn's end, the background tasks, each task's start,
212
+ * progress and end, a compaction.
208
213
  */
209
214
 
210
215
  /** @returns {Neutral[]} */
@@ -319,6 +324,9 @@ function systemEvents(e) {
319
324
  reason: String(e.message ?? ''),
320
325
  },
321
326
  ];
327
+ // An ambient task (claude's own, e.g. a memory pass) is none of the agent's work.
328
+ if (Object.hasOwn(TASK_PHASE, e.subtype))
329
+ return e.ambient === true ? [] : [taskOf(e, TASK_PHASE[e.subtype])];
322
330
  if (e.subtype !== 'background_tasks_changed') return [];
323
331
  const tasks = (Array.isArray(e.tasks) ? e.tasks : []).map((t) => ({
324
332
  id: String(t.task_id ?? t.id ?? ''),
@@ -328,6 +336,42 @@ function systemEvents(e) {
328
336
  return [{ type: 'background', tasks }];
329
337
  }
330
338
 
339
+ // A task of the session (a subagent, a background shell), claude 2.1.317: its start, its
340
+ // progress after each call it makes, its end.
341
+ const TASK_PHASE = { task_started: 'start', task_progress: 'progress', task_notification: 'end' };
342
+ // claude's task types, as the operator reads them.
343
+ const TASK_KIND = { local_agent: 'agent', local_bash: 'shell' };
344
+
345
+ /**
346
+ * One phase of a task: what it is (`kind`, the subagent's type `agent`), what it was started
347
+ * for (`description`, a subagent's `prompt`), what it does now (`doing`, from a progress), the
348
+ * calls it made and how long it took so far (`calls`, `ms`), how it ended (`status`, `summary`),
349
+ * the main agent's call that started it (`call`) and whether it runs in the background.
350
+ * @returns {Neutral}
351
+ */
352
+ function taskOf(e, phase) {
353
+ const str = (v) => (typeof v === 'string' && v ? v : null);
354
+ const num = (v) => (typeof v === 'number' ? v : null);
355
+
356
+ return {
357
+ type: 'task',
358
+ phase,
359
+ id: String(e.task_id ?? ''),
360
+ kind: TASK_KIND[e.task_type] ?? str(e.task_type),
361
+ agent: str(e.subagent_type),
362
+ // A progress's description says what the task does now, not what it was started for.
363
+ description: phase === 'progress' ? null : str(e.description),
364
+ doing: phase === 'progress' ? str(e.description) : null,
365
+ prompt: str(e.prompt),
366
+ calls: num(e.usage?.tool_uses),
367
+ ms: num(e.usage?.duration_ms),
368
+ status: str(e.status),
369
+ summary: str(e.summary),
370
+ call: str(e.tool_use_id),
371
+ background: e.is_backgrounded === true,
372
+ };
373
+ }
374
+
331
375
  /**
332
376
  * The account's usage-limit state as the stream gives it, raw: kept to learn its fields before
333
377
  * the board shows the quota (Board-PRD decision 17). Any other event gives nothing.
@@ -16,6 +16,7 @@ import {
16
16
  import { homedir } from 'node:os';
17
17
  import path from 'node:path';
18
18
  import { CHAT_FLAGS, encode as claudeInput } from './adapter/claude.js';
19
+ import { kindOf } from './activity.js';
19
20
 
20
21
  export { CHAT_FLAGS };
21
22
 
@@ -62,6 +63,11 @@ const PATH_GLOB = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' };
62
63
  // How much of a refused call the chat keeps: its command or file, and what it was for.
63
64
  const TITLE_MAX = 2000;
64
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;
65
71
  const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}…` : s);
66
72
 
67
73
  // A shell line's pieces: a quoted string whole (an unclosed one to the end), a separator, a run
@@ -414,7 +420,8 @@ function say(c, text, by, m = {}) {
414
420
  if (entry) entry.echo = true;
415
421
  const shown = paths.length ? { images: paths } : {};
416
422
  const again = retry ? { retry: true } : {};
417
- post(c, { type: 'say', by, text, ...shown, n: c.sent, ...(id ? { id } : {}), ...again });
423
+ // The chat shows what the operator wrote: the context that went before it is the agent's.
424
+ post(c, { type: 'say', by, text: own, ...shown, n: c.sent, ...(id ? { id } : {}), ...again });
418
425
 
419
426
  return true;
420
427
  }
@@ -531,7 +538,14 @@ async function decided(c, requestId, { allow, by = 'operator', always = false })
531
538
  if (!allow) {
532
539
  send(c, c.encode.deny(requestId, `the operator refused: ${title}`));
533
540
 
534
- return post(c, { type: 'denied', request_id: requestId, tool: card.tool, by, title });
541
+ return post(c, {
542
+ type: 'denied',
543
+ request_id: requestId,
544
+ tool: card.tool,
545
+ kind: kindOf(card.tool),
546
+ by,
547
+ title,
548
+ });
535
549
  }
536
550
 
537
551
  let rule = always ? card.always : null;
@@ -677,13 +691,28 @@ function waitCards(c) {
677
691
  /**
678
692
  * A tool call the session's permissions leave to someone: the engine refuses it when its
679
693
  * policy says (`gate`, AD-29, no card), a run refuses it (nobody approves there), a project
680
- * chat asks the operator by an approval card (AD-5). "Always" is offered only for a rule the
694
+ * chat asks the operator by an approval card (AD-5), or allows the call itself while the
695
+ * operator's YOLO is on (AD-54), with no rule saved. "Always" is offered only for a rule the
681
696
  * session does not ask for anyway (`asks`): an allow would not beat that ask (AD-2).
682
697
  */
683
698
  function permit(c, e) {
684
699
  const why = c.gate(e);
685
700
  if (why) return refuse(c, e, why, { title: e.title, reason: why });
686
701
  if (!c.approvals) return refuse(c, e, `${e.tool} needs an approval no one gives in a run`);
702
+ if (c.yolo()) {
703
+ send(c, c.encode.allow(e.request_id, e.input));
704
+
705
+ return post(c, {
706
+ type: 'allowed',
707
+ request_id: e.request_id,
708
+ by: 'yolo',
709
+ tool: e.tool,
710
+ kind: e.kind,
711
+ title: e.title,
712
+ ...(e.reason ? { reason: e.reason } : {}),
713
+ });
714
+ }
715
+
687
716
  const always = e.always && !c.asks(e) ? e.always : null;
688
717
  c.cards.set(e.request_id, {
689
718
  approval: true,
@@ -706,10 +735,51 @@ function permit(c, e) {
706
735
  waitCards(c);
707
736
  }
708
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
+
709
779
  /** Refuse a tool call (`{request_id, tool}`) by the engine's own word, with no card before it. */
710
780
  function refuse(c, { request_id: requestId, tool }, message, more = {}) {
711
781
  send(c, c.encode.deny(requestId, message));
712
- post(c, { type: 'denied', tool, by: 'engine', ...more });
782
+ post(c, { type: 'denied', tool, kind: kindOf(tool), by: 'engine', ...more });
713
783
  }
714
784
 
715
785
  // What the operator reads of each neutral event of the session, by its type.
@@ -744,6 +814,8 @@ const SEEN = {
744
814
  post(c, {
745
815
  type: 'denied',
746
816
  tool: e.tool,
817
+ // The kind a card names (shell, edit…): the board folds the refusal into a line under it.
818
+ kind: kindOf(e.tool),
747
819
  by: 'rule',
748
820
  ...(call ? { title: cut(call.title, TITLE_MAX), ...refusedBy(c.deny, call) } : {}),
749
821
  ...(why ? { description: cut(why, WHY_MAX) } : {}),
@@ -766,6 +838,31 @@ const SEEN = {
766
838
  },
767
839
  cancel: (c, e) => dropCard(c, e.request_id),
768
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
+ },
769
866
  // While they run, no answer is waited for; claude starts a turn itself as they end. Their end
770
867
  // with no new turn after the grace settles the session, so it is not held for good.
771
868
  background: (c, e) => {
@@ -812,7 +909,8 @@ function see(c, events) {
812
909
  * A project chat (AD-5) sets `approvals`: a permission request is an approval card;
813
910
  * `gate(e)` names why the engine refuses a call outright, or null; `asks(e)` whether the
814
911
  * session asks for such a call anyway (no "always" then); `saveAlways(rule)` keeps an
815
- * "always" rule; `onHandoff()` takes the operator's fresh-agent input. `files` names the chat's
912
+ * "always" rule; `yolo()` whether the engine allows a call itself, with no card (AD-54);
913
+ * `onHandoff()` takes the operator's fresh-agent input. `files` names the chat's
816
914
  * two files when they are not `<id>.chat*.jsonl` under `logs`.
817
915
  */
818
916
  export function openChat(opts) {
@@ -861,6 +959,7 @@ const CHAT_DEFAULTS = {
861
959
  approvals: false,
862
960
  gate: () => null,
863
961
  asks: () => false,
962
+ yolo: () => false,
864
963
  deny: [],
865
964
  saveAlways: async () => {},
866
965
  handover: null,
@@ -883,6 +982,9 @@ function chatState(opts) {
883
982
  ...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
884
983
  ...{ stopped: false, grace: null, idle: false, inTurn: true, tasks: [] },
885
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(),
886
988
  why: null,
887
989
  ...{ hold: false, late: false, pending: [], echoes: [] },
888
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} */
@@ -12,15 +12,27 @@ export const runsDir = (dir) => path.join(dir, ROOT, 'runs');
12
12
  /** `.gcf-session/chats`: the project chat's threads. */
13
13
  export const chatsDir = (dir) => path.join(dir, ROOT, 'chats');
14
14
 
15
+ // What a rename over a file another process holds open meets on Windows (a scanner, an indexer).
16
+ const HELD = new Set(['EPERM', 'EACCES', 'EBUSY']);
17
+
15
18
  /**
16
19
  * Write `text` to `file` whole or not at all: a temporary file beside it, then a rename. A
17
- * reader never sees half of it, and two writers leave one whole file.
20
+ * reader never sees half of it, and two writers leave one whole file. A file held for a moment
21
+ * is tried again for up to half a second.
18
22
  */
19
23
  export function writeAtomic(file, text) {
20
24
  const tmp = `${file}.${process.pid}.tmp`;
21
25
  try {
22
26
  writeFileSync(tmp, text);
23
- renameSync(tmp, file);
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
+ }
24
36
  } catch (e) {
25
37
  rmSync(tmp, { force: true });
26
38
  throw e;
@@ -335,7 +335,8 @@ function flagsOf({ dir, td, spec, adapter }, settings) {
335
335
  * Run thread `t` of project `dir` until its session idles out, is stopped, or ends: a job of
336
336
  * sessions (AD-41), each resumed from the one before, a fresh one after a handoff (AD-42).
337
337
  * `spec` (its `spec.json`): `agent`, `rules` `{deny, ask, allow}`, `mcp` (config files),
338
- * `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `timeoutMin`, `pick` (the project's
338
+ * `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `yolo` (a file: present, the engine
339
+ * allows each call with no card, AD-54), `timeoutMin`, `pick` (the project's
339
340
  * model and effort, under the thread's own, over the agent's defaults). `stopped()` says the
340
341
  * operator stopped it.
341
342
  * @param {{stopped?: () => boolean}} [opts]
@@ -540,6 +541,8 @@ function chatOf(s, kind, prev) {
540
541
  approvals: true,
541
542
  gate: gateOf(spec),
542
543
  asks: (e) => (spec.rules?.ask ?? []).some((r) => ruleHolds(r, e)),
544
+ // Read at each request: the operator's switch holds at once.
545
+ yolo: () => Boolean(spec.yolo) && existsSync(spec.yolo),
543
546
  deny: spec.rules?.deny ?? [],
544
547
  saveAlways: (rule) => s.adapter.saveAlways(dir, rule),
545
548
  handover: handoverOf(s),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-session",
3
- "version": "0.17.3",
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;
@@ -75,6 +91,16 @@ export type ChatEvent = At &
75
91
  always_wide?: boolean;
76
92
  }
77
93
  | { type: 'allowed'; request_id: string; by: 'operator'; always: boolean; rule?: string }
94
+ /** The engine allowed the call itself, with no card: the operator's YOLO (AD-54). */
95
+ | {
96
+ type: 'allowed';
97
+ request_id: string;
98
+ by: 'yolo';
99
+ tool: string;
100
+ kind: string;
101
+ title: string;
102
+ reason?: string;
103
+ }
78
104
  | {
79
105
  type: 'denied';
80
106
  tool: string;
@@ -102,6 +128,20 @@ export type ChatEvent = At &
102
128
  by?: 'operator' | 'threshold' | 'compacted';
103
129
  error?: string;
104
130
  }
131
+ | {
132
+ // How an item's run ended: the harness posts it last (Tails «Первым» 2).
133
+ type: 'run_end';
134
+ outcome:
135
+ 'submitted' | 'blocked' | 'failed' | 'paused' | 'stopped' | 'no-result' | 'skipped';
136
+ move: string;
137
+ reason: string | null;
138
+ cost_usd: number | null;
139
+ duration_ms: number | null;
140
+ commit: string | null;
141
+ unticked: number | null;
142
+ lessons: number;
143
+ process: string | null;
144
+ }
105
145
  | { type: 'step'; step: 'plan'; passes: number }
106
146
  | {
107
147
  type: 'step';
@@ -159,6 +199,8 @@ export interface ThreadSpec {
159
199
  window?: number;
160
200
  skill?: string;
161
201
  mainLock?: string | null;
202
+ /** A file whose presence turns the operator's YOLO on: calls go with no card (AD-54). */
203
+ yolo?: string;
162
204
  timeoutMin?: number;
163
205
  /** The project's model and effort: a session takes them where the thread picked none. */
164
206
  pick?: AgentPick;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-harness-aif-ext",
3
- "version": "0.19.1",
3
+ "version": "0.21.1",
4
4
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "prepack": "node -e \"const p=require('./package.json'),e=require('./extension.json');if(p.version!==e.version)throw new Error('version mismatch: package.json '+p.version+' vs extension.json '+e.version);require('node:fs').statSync('node_modules/gcf-session/lib/index.js')\""
29
29
  },
30
30
  "peerDependencies": {
31
- "gcf-aif-ext": "^0.19.0"
31
+ "gcf-aif-ext": ">=0.20.0 <0.22.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "gcf-session": "file:../gcf-session"
@@ -48,6 +48,7 @@ forbidden_behaviors:
48
48
  - a plan pass sorts each finding as blocking or polish, and reports how many of each it found
49
49
  - blocking: a wrong or missing behavior, a missing or wrong task, a broken pillar invariant, a conflict with a project rule, a task no check can prove
50
50
  - polish: wording, splitting or merging tasks, their order, more detail - the pass applies it, and it does not keep the plan from converging
51
+ - a `format:` line of `ai-factory gcf plan check` is polish: the pass brings the plan into the plan form it names, and it never blocks
51
52
  - do not edit `status:` or `gcf/LIVE.md` by hand: `submit`, `close` and `block` own them
52
53
  - do not write a plan task's first implementation outside the aif-implement skill: it ticks the task done in the plan, and the board shows the item's progress from those ticks
53
54
  - a fix for a red DoD or a review finding goes in directly, without aif-implement