gcf-harness-aif-ext 0.19.1 → 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.
package/README.md CHANGED
@@ -47,6 +47,8 @@ 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.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.
51
+
50
52
  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
53
 
52
54
  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.
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,14 @@ 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) if (i.result !== 'verified') await postEnd(ctx, i);
1258
+
1259
+ return lines;
1256
1260
  }
1257
1261
 
1258
1262
  /**
@@ -1313,6 +1317,83 @@ export const run = async (projectDir, ids, opts) => {
1313
1317
  }
1314
1318
  };
1315
1319
 
1320
+ // The outcome a run's result word reads as on the board's card.
1321
+ const OUTCOME = {
1322
+ submit: 'submitted',
1323
+ decide: 'submitted',
1324
+ deferred: 'submitted',
1325
+ close: 'submitted',
1326
+ block: 'blocked',
1327
+ error: 'failed',
1328
+ conflict: 'failed',
1329
+ paused: 'paused',
1330
+ };
1331
+ // The words that are a move of the core: the card names them beside the outcome.
1332
+ const MOVES = ['submit', 'close', 'block', 'decide', 'deferred'];
1333
+
1334
+ /**
1335
+ * How an item's run ended, for its chat (`run_end`): the outcome (submitted, blocked, failed,
1336
+ * paused, stopped, no-result, skipped), the move, the reason word for word, what it cost and
1337
+ * took, main's commit, the plan's tasks left unticked, the lessons it filed, a broken step.
1338
+ */
1339
+ export function runEndOf(i, projectDir, launch = null) {
1340
+ const result = String(i.result ?? 'merged');
1341
+ const word = result.split(/[\s:(]/)[0];
1342
+ // A stop is the operator's, a paused wait cut by it too; then a limit, then the result word.
1343
+ const stopped = /\bstopped\b/.test(result) && !OUTCOME[word]?.startsWith('sub');
1344
+ const outcome = stopped
1345
+ ? 'stopped'
1346
+ : i.limit_resets !== undefined
1347
+ ? 'paused'
1348
+ : (OUTCOME[word] ??
1349
+ (word === 'skipped' ? 'skipped' : word === 'merged' ? 'submitted' : 'no-result'));
1350
+ const plan = launch?.planOf?.(i.id) ?? null;
1351
+ let unticked = null;
1352
+ try {
1353
+ if (plan)
1354
+ unticked = (readFileSync(path.join(projectDir, plan), 'utf8').match(/^\s*- \[ \] /gm) ?? [])
1355
+ .length;
1356
+ } catch {
1357
+ // Archived with its item: nothing left.
1358
+ }
1359
+
1360
+ return {
1361
+ type: 'run_end',
1362
+ outcome,
1363
+ move: MOVES.includes(word) ? word : null,
1364
+ // A failure says what failed first; a move without one says why it was made.
1365
+ reason:
1366
+ (outcome === 'failed' ? (i.error ?? i.conflict ?? i.reason) : (i.reason ?? i.error)) ??
1367
+ i.skipped ??
1368
+ (OUTCOME[word] && word !== 'paused' ? null : result),
1369
+ cost_usd: i.cost_usd ?? null,
1370
+ duration_ms: i.duration_ms ?? null,
1371
+ commit: headOf(projectDir)?.slice(0, 7) ?? null,
1372
+ unticked,
1373
+ lessons: i.lessons ?? 0,
1374
+ process: i.process ?? null,
1375
+ };
1376
+ }
1377
+
1378
+ /**
1379
+ * Post an item's run end to its chat (Tails «Первым» 2), when the run has one: not for an item
1380
+ * that never started (another run's lock), whose chat is that run's. The plan is the board's now:
1381
+ * a first run made it.
1382
+ */
1383
+ async function postEnd(ctx, item) {
1384
+ if (!ctx.launch?.chat || item.started === false) return;
1385
+ let plans = {};
1386
+ try {
1387
+ const now = json(await ctx.core(['board', '--json']), 'board');
1388
+ plans = Object.fromEntries((now.items ?? []).map((i) => [i.id, i.plan_file ?? null]));
1389
+ } catch {
1390
+ // No board: no plan count.
1391
+ }
1392
+
1393
+ const end = runEndOf(item, ctx.projectDir, { planOf: (id) => plans[id] ?? null });
1394
+ postTo(chatOut(ctx.logs, item.id), end);
1395
+ }
1396
+
1316
1397
  /** Whether a commit dropped unit `id` (`gcf(drop): <id>`). */
1317
1398
  function droppedSince(projectDir, id) {
1318
1399
  const grep = String.raw`--grep=^gcf\(drop\): ` + `${id}( |$)`;
@@ -1501,13 +1582,32 @@ async function runBatch(
1501
1582
  }),
1502
1583
  );
1503
1584
  const failed = driven.find((d) => d.status === 'rejected');
1504
- if (failed) throw failed.reason;
1585
+ if (failed) {
1586
+ const error = String(failed.reason?.message ?? failed.reason);
1587
+ for (const [n, d] of driven.entries())
1588
+ if (d.status === 'rejected')
1589
+ for (const id of parts[n][1]) await postEnd(ctx, { id, result: 'error', error });
1590
+ throw failed.reason;
1591
+ }
1592
+
1505
1593
  // The branches worktree runs verified while a main part held the checkout go in now; a main
1506
1594
  // its session left dirty keeps them for the next run.
1507
1595
  const after = claims.has('main')
1508
1596
  ? (await integrateNow(core).catch(() => ({ results: [] }))).results
1509
1597
  : [];
1510
1598
  const features = await closeFinishedFeatures(core).catch(() => []);
1599
+ // A branch verified while main was held went in just now: its end is that merge's move.
1600
+ for (const d of driven)
1601
+ if (d.status === 'fulfilled')
1602
+ for (const i of d.value.filter((x) => x.result === 'verified')) {
1603
+ const merged = after.find((r) => r.id === i.id);
1604
+ const result = merged?.move ?? (merged?.conflict ? 'conflict' : i.result);
1605
+ await postEnd(ctx, {
1606
+ ...i,
1607
+ result,
1608
+ ...(merged?.conflict && { conflict: merged.conflict }),
1609
+ });
1610
+ }
1511
1611
 
1512
1612
  // `limit_wait`: this harness waits for a usage limit's reset itself (AD-19); a board reads it.
1513
1613
  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.20.0",
5
5
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
6
6
  "skills": [
7
7
  "skills/gcf-run",
@@ -677,13 +677,28 @@ function waitCards(c) {
677
677
  /**
678
678
  * A tool call the session's permissions leave to someone: the engine refuses it when its
679
679
  * 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
680
+ * chat asks the operator by an approval card (AD-5), or allows the call itself while the
681
+ * operator's YOLO is on (AD-54), with no rule saved. "Always" is offered only for a rule the
681
682
  * session does not ask for anyway (`asks`): an allow would not beat that ask (AD-2).
682
683
  */
683
684
  function permit(c, e) {
684
685
  const why = c.gate(e);
685
686
  if (why) return refuse(c, e, why, { title: e.title, reason: why });
686
687
  if (!c.approvals) return refuse(c, e, `${e.tool} needs an approval no one gives in a run`);
688
+ if (c.yolo()) {
689
+ send(c, c.encode.allow(e.request_id, e.input));
690
+
691
+ return post(c, {
692
+ type: 'allowed',
693
+ request_id: e.request_id,
694
+ by: 'yolo',
695
+ tool: e.tool,
696
+ kind: e.kind,
697
+ title: e.title,
698
+ ...(e.reason ? { reason: e.reason } : {}),
699
+ });
700
+ }
701
+
687
702
  const always = e.always && !c.asks(e) ? e.always : null;
688
703
  c.cards.set(e.request_id, {
689
704
  approval: true,
@@ -812,7 +827,8 @@ function see(c, events) {
812
827
  * A project chat (AD-5) sets `approvals`: a permission request is an approval card;
813
828
  * `gate(e)` names why the engine refuses a call outright, or null; `asks(e)` whether the
814
829
  * 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
830
+ * "always" rule; `yolo()` whether the engine allows a call itself, with no card (AD-54);
831
+ * `onHandoff()` takes the operator's fresh-agent input. `files` names the chat's
816
832
  * two files when they are not `<id>.chat*.jsonl` under `logs`.
817
833
  */
818
834
  export function openChat(opts) {
@@ -861,6 +877,7 @@ const CHAT_DEFAULTS = {
861
877
  approvals: false,
862
878
  gate: () => null,
863
879
  asks: () => false,
880
+ yolo: () => false,
864
881
  deny: [],
865
882
  saveAlways: async () => {},
866
883
  handover: 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.17.4",
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",
@@ -75,6 +75,16 @@ export type ChatEvent = At &
75
75
  always_wide?: boolean;
76
76
  }
77
77
  | { type: 'allowed'; request_id: string; by: 'operator'; always: boolean; rule?: string }
78
+ /** The engine allowed the call itself, with no card: the operator's YOLO (AD-54). */
79
+ | {
80
+ type: 'allowed';
81
+ request_id: string;
82
+ by: 'yolo';
83
+ tool: string;
84
+ kind: string;
85
+ title: string;
86
+ reason?: string;
87
+ }
78
88
  | {
79
89
  type: 'denied';
80
90
  tool: string;
@@ -102,6 +112,20 @@ export type ChatEvent = At &
102
112
  by?: 'operator' | 'threshold' | 'compacted';
103
113
  error?: string;
104
114
  }
115
+ | {
116
+ // How an item's run ended: the harness posts it last (Tails «Первым» 2).
117
+ type: 'run_end';
118
+ outcome:
119
+ 'submitted' | 'blocked' | 'failed' | 'paused' | 'stopped' | 'no-result' | 'skipped';
120
+ move: string;
121
+ reason: string | null;
122
+ cost_usd: number | null;
123
+ duration_ms: number | null;
124
+ commit: string | null;
125
+ unticked: number | null;
126
+ lessons: number;
127
+ process: string | null;
128
+ }
105
129
  | { type: 'step'; step: 'plan'; passes: number }
106
130
  | {
107
131
  type: 'step';
@@ -159,6 +183,8 @@ export interface ThreadSpec {
159
183
  window?: number;
160
184
  skill?: string;
161
185
  mainLock?: string | null;
186
+ /** A file whose presence turns the operator's YOLO on: calls go with no card (AD-54). */
187
+ yolo?: string;
162
188
  timeoutMin?: number;
163
189
  /** The project's model and effort: a session takes them where the thread picked none. */
164
190
  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.20.0",
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"
32
32
  },
33
33
  "dependencies": {
34
34
  "gcf-session": "file:../gcf-session"