gcf-harness-aif-ext 0.15.0 → 0.18.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,13 +47,19 @@ 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.18.1 runs an item with no model or effort of its own and none in the project on the agent's default, Opus / High (bundled gcf-session 0.17.0, Board-PRD decision 36); `run-log.csv` records the model and effort that ran.
51
+
52
+ 0.18.0 needs gcf-aif-ext 0.18.0 (docs/Round6-Functional-Plan.md): `/gcf-run` files its inbox entries with a category (`inbox add --category <c>`), as the core now asks of an agent; the bundled session engine offers `fable` among claude's model presets. After the update run `ai-factory gcf inbox migrate` once: it writes the entries from before the categories in one commit.
53
+
54
+ 0.16.1 needs gcf-aif-ext 0.16.1: an older core would merge a worktree branch under a main run's agent (Board-PRD decision 28). Without `--mode` each item runs where its own `run_mode` says, else the project's; a batch of both is two parts at once under one gate, one report (`mode: main+worktree`, in the order the items came). A main run's own sessions still run `gcf integrate` at their start, as before. A main run names the items it has yet to reach in `.gcf-session/runs/.main-run.queue`, and the gate counts them as running, so a worktree run beside it cannot take them. While a main run holds the checkout, core 0.16 merges nothing: a worktree item whose branch is green reads `verified` ("its branch merges when that run ends"), and the main run merges it as it ends (its `orphans`).
55
+
50
56
  0.15.0 works with gcf-aif-ext 0.14.0 or 0.15.0. A run on main refreshes and, at the end, clears its item's session mark only while the mark is its own (`GCF_RUN_OWNER`) or names nobody: a mark another session claimed after a `gcf release` by hand stays that session's.
51
57
 
52
58
  0.14.0 needs gcf-aif-ext 0.14.0 (docs/Base-A-Plan.md). Without `--timeout` a session's limit is `session_timeout_min` of `gcf/config.yml` (120 without it); an item without its own `model:` / `effort:` runs on the project's `agent.model` / `agent.effort` (the run's override still goes over both); `ai-factory gcf-harness gate --each [<id>…] --json` gives the gate of each named item (none: every ready one) run alone now, from one audit, `{items: {<id>: {pass, reason}}}`, exit 0: the board shows a refusal before the click. The bundled session engine offers Always for one MCP tool, marked `always_wide`.
53
59
 
54
60
  0.13.0 keeps its past runs for the board (docs/Board-V2-Data-Plan.md) and needs gcf-aif-ext 0.13.0 for the moves' `GCF-By`. `run-log.csv` lines get six columns at their end (`run_id, started, model, effort, log_from, log_to`; older lines still read); `ai-factory gcf-harness runs [--item <id>] [--limit <n>] --json` lists the runs; `run --model <m> --effort <e>` runs every item on another model for that run only, the item unchanged; a run sets `GCF_MOVE_BY=run` for its core calls and its agents.
55
61
 
56
- 0.12.2 reads an item as it starts it: in a main-mode batch, an item the run has yet to reach takes a model or effort set meanwhile (`ai-factory gcf item agent`, core 0.12.3; a worktree run locks its items first). A stored `default` gives no `--model` or `--effort` flag.
62
+ 0.12.2 reads an item as it starts it: in a main-mode batch, an item the run has yet to reach takes a model or effort set meanwhile (`ai-factory gcf item agent`, core 0.12.3; a worktree run locks its items first). A stored `default` takes the project's setting, else the agent's default (claude: `opus`, `high`; Board-PRD decision 36).
57
63
 
58
64
  0.12.0 moves the session mechanics into the bundled session engine `gcf-session` (docs/Session-Engine.md) and needs gcf-aif-ext 0.12.0: a core without neutral rules (`agent.rules`) is refused before any item is claimed. The hooks keep their files and matchers: no new `init` is needed.
59
65
  - **The usage limit waits.** A session cut by the limit with a known reset waits for it (plus 60 s) and goes on in the same session. Before the wait its record is written (`<id>.agent.json`, `ended: limit`, `resets` as ISO), so a run killed meanwhile resumes the same session; the chat gets `limit {until}`; the wait does not count against `--timeout`; `gcf-harness stop` ends it. It does not wait for the week's limit, an unknown reset, a reset over 6 h away, an item's third limit in a run, or a lessons turn: those end `paused` as before. `--wait-limit` (a queued start from the board) also holds each session while a known reset is ahead. `--json` says `limit_wait: true`.
@@ -9,7 +9,15 @@ import { spawnSync } from 'node:child_process';
9
9
  import path from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
11
  import { metricsCommand, runsCommand } from './metrics.js';
12
- import { run, cliCore, DEFAULT_AGENT, DEFAULT_TIMEOUT_MIN, MAIN_RUN, stopOf } from './run.js';
12
+ import {
13
+ run,
14
+ cliCore,
15
+ DEFAULT_AGENT,
16
+ DEFAULT_TIMEOUT_MIN,
17
+ MAIN_RUN,
18
+ queueOf,
19
+ stopOf,
20
+ } from './run.js';
13
21
  import { CHAT_TIMEOUT_MIN, ChatRefusal, alive, chatInput, killTree, readText } from 'gcf-session';
14
22
 
15
23
  const EXT_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
@@ -139,13 +147,35 @@ export function gate(report, ids) {
139
147
  );
140
148
  }
141
149
 
142
- /** `gcf audit` exits 1 on any finding, so the report is read from stdout whatever the code. */
150
+ /**
151
+ * The report with the items a live main run has yet to reach (`.main-run.queue`) as running:
152
+ * they hold no lock or mark before their turn, and another run must not take them meanwhile.
153
+ */
154
+ export function withMainQueue(report, runs) {
155
+ if (!Array.isArray(report?.items) || !lockOf(path.join(runs, `${MAIN_RUN}.lock`))) return report;
156
+ let queued;
157
+ try {
158
+ queued = new Set(readFileSync(queueOf(runs), 'utf8').split('\n').filter(Boolean));
159
+ } catch {
160
+ return report;
161
+ }
162
+
163
+ return {
164
+ ...report,
165
+ items: report.items.map((i) => (queued.has(i.id) ? { ...i, running: true } : i)),
166
+ };
167
+ }
168
+
169
+ /**
170
+ * `gcf audit` exits 1 on any finding, so the report is read from stdout whatever the code. The
171
+ * items a main run has queued count as running.
172
+ */
143
173
  function auditReport() {
144
174
  // Re-enter the same ai-factory CLI that is running this command: no PATH or .cmd lookup.
145
175
  const args = [process.argv[1], 'gcf', 'audit', '--json'];
146
176
  const res = spawnSync(process.execPath, args, { encoding: 'utf8' });
147
177
  try {
148
- return JSON.parse(res.stdout);
178
+ return withMainQueue(JSON.parse(res.stdout), path.join(process.cwd(), '.gcf-session', 'runs'));
149
179
  } catch (err) {
150
180
  const output = (res.stderr || res.stdout || '').trim();
151
181
  throw new Error(`\`ai-factory gcf audit --json\` produced no report: ${output}`, {
package/commands/run.js CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  chatOut,
24
24
  claim,
25
25
  clock,
26
+ defaultsOf,
26
27
  killTree,
27
28
  permissions,
28
29
  postTo,
@@ -93,6 +94,18 @@ export function cliCore(projectDir) {
93
94
  };
94
95
  }
95
96
 
97
+ /**
98
+ * Merge the verified branches now (`gcf integrate`): their results; none, `waits`, while a main
99
+ * run works in the checkout: the core merges nothing under it, and they go in when it ends.
100
+ */
101
+ async function integrateNow(core) {
102
+ const r = await core(['integrate', '--json']);
103
+ if (!r.ok && /a main run works in the main checkout/.test(r.err + r.out))
104
+ return { results: [], waits: true };
105
+
106
+ return { results: json(r, 'integrate') };
107
+ }
108
+
96
109
  /** The JSON report of a core command, or its refusal as the error. */
97
110
  export function json(res, what) {
98
111
  try {
@@ -116,20 +129,22 @@ const RUN_WORD = /^[A-Za-z0-9][\w.-]*$/;
116
129
  /**
117
130
  * What one item runs on: the run's override (`run --model|--effort`, this run only) over the
118
131
  * item's own `model:` and `effort:`, over the project's (`agent.model|effort` of
119
- * gcf/config.yml); null or `default` at one level falls to the next, none at all leaves it to
120
- * the agent. The values go into a
132
+ * gcf/config.yml), over the agent's `defaults` (gcf-session `defaultsOf`, claude's Opus and High,
133
+ * Board-PRD decision 36); null or `default` at one level falls to the next. The values go into a
121
134
  * shell command, and an item file can be edited by hand: a value that is not one plain word is
122
135
  * refused.
123
136
  * @param {any} item
124
137
  * @param {{model?: string | null, effort?: string | null}} [override]
125
138
  * @param {{model?: string | null, effort?: string | null}} [project]
139
+ * @param {{model?: string | null, effort?: string | null}} [defaults]
126
140
  */
127
- export function choiceOf(item, override = {}, project = {}) {
141
+ export function choiceOf(item, override = {}, project = {}, defaults = {}) {
128
142
  const set = (v) => (v === null || v === undefined || v === 'default' ? null : String(v));
129
143
  /** @type {{model: string | null, effort: string | null}} */
130
144
  const out = { model: null, effort: null };
131
145
  for (const k of /** @type {const} */ (['model', 'effort'])) {
132
- const v = set(override?.[k]) ?? set(item?.[k]) ?? set(project?.[k]);
146
+ const v =
147
+ [override, item, project, defaults].map((l) => set(l?.[k])).find((x) => x !== null) ?? null;
133
148
  if (v !== null && !RUN_WORD.test(v)) throw new Error(`${k}: ${v} is not one plain word`);
134
149
  out[k] = v;
135
150
  }
@@ -146,7 +161,7 @@ export function choiceOf(item, override = {}, project = {}) {
146
161
  * @param {{model?: string | null, effort?: string | null}} [project]
147
162
  */
148
163
  export function agentFor(agent, item, override = {}, project = {}) {
149
- const flags = Object.entries(choiceOf(item, override, project))
164
+ const flags = Object.entries(choiceOf(item, override, project, defaultsOf(agent)))
150
165
  .filter(([, v]) => v !== null)
151
166
  .map(([k, v]) => `--${k} ${v}`);
152
167
 
@@ -789,6 +804,13 @@ function unverify(r) {
789
804
  }
790
805
 
791
806
  /** The result line of an item the integrator handled, or why it has none. */
807
+ /** A verified branch a main run keeps out of the checkout: it merges as that run ends. */
808
+ const waiting = (run) => ({
809
+ id: run.id,
810
+ result: 'verified',
811
+ reason: 'a main run works in the main checkout: its branch merges when that run ends',
812
+ });
813
+
792
814
  function resultOf(run, integrated) {
793
815
  const done = integrated.find((x) => x.id === run.id);
794
816
  if (!done && run.error) return { id: run.id, result: 'error', error: run.error };
@@ -875,14 +897,12 @@ export const MAIN_RUN = '.main-run';
875
897
  * `run_mode: main` (Methodology §7): one item after another in the main checkout, where the
876
898
  * editor the agent works through lives. The agent records each item's move itself, so the item
877
899
  * carries a session mark (`gcf claim`), not a run lock: a lock would refuse the agent's own
878
- * moves. A session that stopped without a move leaves no mark behind.
900
+ * moves. The items it has yet to reach are named in `.main-run.queue`, so another run's gate
901
+ * counts them, and stay free to change: each takes its model as it starts. A session that
902
+ * stopped without a move leaves no mark behind.
879
903
  */
880
- async function runMain(projectDir, ids, ctx) {
904
+ async function runMain(projectDir, ids, releaseMain, ctx) {
881
905
  const { logs } = ctx;
882
- // The owner of the items' marks: this run's core calls and every agent session it starts
883
- // (a fresh one after a handoff included) inherit it, so their `gcf claim` and moves pass.
884
- process.env.GCF_RUN_OWNER = `run:${process.pid}`;
885
- const releaseMain = await claim(lockFile(logs, MAIN_RUN));
886
906
  if (!releaseMain)
887
907
  return ids.map((id) => ({
888
908
  id,
@@ -890,20 +910,51 @@ async function runMain(projectDir, ids, ctx) {
890
910
  error: 'another run works in the main checkout: wait for it, or stop it',
891
911
  started: false,
892
912
  }));
913
+ // The owner of the items' marks: this run's core calls and every agent session it starts
914
+ // (a fresh one after a handoff included) inherit it, so their `gcf claim` and moves pass.
915
+ process.env.GCF_RUN_OWNER = `run:${process.pid}`;
893
916
 
894
917
  const items = [];
895
918
  try {
896
- for (const id of ids) items.push(await mainItem(projectDir, id, ctx));
919
+ for (const [n, id] of ids.entries()) {
920
+ // Its mark holds it from its claim on: the queue lets it go then.
921
+ // Advisory only: a write refused (a file held by a scanner) leaves the item run as it is.
922
+ const dequeue = () => {
923
+ try {
924
+ writeAtomic(queueOf(logs), `${ids.slice(n + 1).join('\n')}\n`);
925
+ } catch {}
926
+ };
927
+ items.push(await mainItem(projectDir, id, { ...ctx, dequeue }));
928
+ }
897
929
  } finally {
930
+ await rm(queueOf(logs), { force: true });
898
931
  await releaseMain();
899
932
  }
900
933
 
901
934
  return items;
902
935
  }
903
936
 
937
+ /** The items a main run has yet to reach, one id a line. */
938
+ export const queueOf = (logs) => path.join(logs, `${MAIN_RUN}.queue`);
939
+
940
+ /** The main checkout for a main run, with its items queued; null while another run holds it. */
941
+ async function holdMain(logs, ids) {
942
+ const release = await claim(lockFile(logs, MAIN_RUN));
943
+ // Whole or not at all: a gate reads it meanwhile. With no queue the checkout is not held:
944
+ // another run's gate would see the items free.
945
+ try {
946
+ if (release) writeAtomic(queueOf(logs), `${ids.join('\n')}\n`);
947
+ } catch (e) {
948
+ await release?.();
949
+ throw e;
950
+ }
951
+
952
+ return release;
953
+ }
954
+
904
955
  /** One item of a main run: marked, its session, its mark cleared, its result read. */
905
956
  async function mainItem(projectDir, id, ctx) {
906
- const { core, logs, agentOf } = ctx;
957
+ const { core, logs, agentOf, dequeue } = ctx;
907
958
  let r;
908
959
  let started = false;
909
960
  let marked = false;
@@ -913,8 +964,12 @@ async function mainItem(projectDir, id, ctx) {
913
964
  writeFileSync(path.join(logs, `${MAIN_RUN}.lock`), `${process.pid}\n${id}\n`);
914
965
  try {
915
966
  const claimed = await core(['claim', id]);
916
- if (!claimed.ok) throw new Error((claimed.err || claimed.out).trim());
967
+ if (!claimed.ok) {
968
+ dequeue();
969
+ throw new Error((claimed.err || claimed.out).trim());
970
+ }
917
971
  marked = true;
972
+ dequeue();
918
973
  const none = async () => {};
919
974
 
920
975
  // The agent recorded the item's move: no fresh session takes it over.
@@ -962,6 +1017,21 @@ async function mainItem(projectDir, id, ctx) {
962
1017
  }
963
1018
 
964
1019
  /** The checkout's HEAD, or null before its first commit. */
1020
+ /** Whether main merged item `id`'s branch since `head`: the integrator's `gcf(integrate): <id>`. */
1021
+ function mergedSince(dir, id, head) {
1022
+ if (!head) return false;
1023
+ const r = spawnSync('git', ['log', '--format=%s', `${head}..HEAD`], {
1024
+ cwd: dir,
1025
+ encoding: 'utf8',
1026
+ });
1027
+ const subject = `gcf(integrate): ${id}`;
1028
+
1029
+ // `tray` must not match `tray-2`: the id ends at the end or at a space (a spike's ` plan`).
1030
+ return (
1031
+ r.status === 0 && r.stdout.split('\n').some((s) => s === subject || s.startsWith(`${subject} `))
1032
+ );
1033
+ }
1034
+
965
1035
  function headOf(dir) {
966
1036
  const r = spawnSync('git', ['rev-parse', '--verify', '-q', 'HEAD'], {
967
1037
  cwd: dir,
@@ -1051,6 +1121,8 @@ const extras = (r, note = null) => {
1051
1121
  /** Every claimed item in its worktree at once; blocks recorded on main, verified ones merged. */
1052
1122
  async function runWorktrees(claims, ctx) {
1053
1123
  const { core, logs } = ctx;
1124
+ // Main as the run starts: a merge since is in its log.
1125
+ const head = headOf(ctx.projectDir);
1054
1126
  // Its items are locked already: no move changes them after the run's first read.
1055
1127
  const { ready, failed } = await prepare(claims, core, ctx.agentFirst);
1056
1128
  // A session that verified its branch, or left an outcome, is done: no fresh one follows.
@@ -1070,8 +1142,33 @@ async function runWorktrees(claims, ctx) {
1070
1142
  }
1071
1143
  }
1072
1144
 
1073
- const integrated = json(await core(['integrate', '--json']), 'integrate');
1074
- for (const r of runs) if (!items.some((i) => i.id === r.id)) items.push(resultOf(r, integrated));
1145
+ const { results: integrated, waits } = await integrateNow(core);
1146
+ const open = runs.filter(
1147
+ (r) => !items.some((i) => i.id === r.id) && !integrated.some((x) => x.id === r.id),
1148
+ );
1149
+ // A branch another run merged meanwhile (a main run, at its end or a session's start): its
1150
+ // move is on the board.
1151
+ const now = open.length ? (json(await core(['board', '--json']), 'board').items ?? []) : [];
1152
+ for (const r of runs) {
1153
+ if (items.some((i) => i.id === r.id)) continue;
1154
+ const after = now.find((i) => i.id === r.id);
1155
+ // Only the integrator's own commit says the branch went in: a drop by hand is no merge.
1156
+ const moved = open.includes(r) && !r.error && mergedSince(ctx.projectDir, r.id, head);
1157
+ const gone = open.includes(r) && !moved && !after;
1158
+ items.push(
1159
+ moved
1160
+ ? {
1161
+ id: r.id,
1162
+ result: after ? (MOVE_OF[after.status] ?? after.status) : 'close',
1163
+ reason: 'its branch was merged by another run meanwhile',
1164
+ }
1165
+ : gone
1166
+ ? { id: r.id, result: 'skipped', reason: 'it left the board meanwhile, by another move' }
1167
+ : waits && verified(r.dir, r.id)
1168
+ ? waiting(r)
1169
+ : resultOf(r, integrated),
1170
+ );
1171
+ }
1075
1172
  // A worktree's session records no move: the chat hears of the one main recorded for it.
1076
1173
  if (ctx.launch?.chat)
1077
1174
  for (const i of items.filter((x) => ['submit', 'close', 'block'].includes(x.result)))
@@ -1105,7 +1202,7 @@ function commandsOf(core, agent, board, override) {
1105
1202
 
1106
1203
  return {
1107
1204
  agent: agentFor(agent, item, override, b.agent),
1108
- choice: choiceOf(item, override, b.agent),
1205
+ choice: choiceOf(item, override, b.agent, defaultsOf(agent)),
1109
1206
  };
1110
1207
  };
1111
1208
  const agentOf = async (id) => {
@@ -1122,13 +1219,15 @@ function commandsOf(core, agent, board, override) {
1122
1219
  return { agentOf, agentFirst: (id) => commandOf(board, id) };
1123
1220
  }
1124
1221
 
1125
- /** The mode a run takes: the one asked for, else the project's. */
1126
- const modeOf = (mode, board) => mode ?? board.run_mode ?? 'worktree';
1222
+ /** Where an item's run goes: the run's mode, else the item's `run_mode`, else the project's. */
1223
+ const modeOf = (mode, board, item) => mode ?? item?.run_mode ?? board.run_mode ?? 'worktree';
1127
1224
 
1128
1225
  /**
1129
- * Pick up orphans, gate the batch, run the items in the project's run mode (`mode` overrides
1130
- * it). `gate(ids)` answers `{pass, reason}`; a session past `timeoutMs` is stopped with all it
1131
- * started, and its item stays ready. `fresh` starts new sessions where kept ones would resume;
1226
+ * Pick up orphans, gate the batch, run each item where it runs: the run's `mode`, else its own
1227
+ * `run_mode`, else the project's. Items of two modes are two parts at once under one gate, one
1228
+ * report: the main part in the checkout, one item after another, the worktree part beside it;
1229
+ * a branch it verifies merges when the main part ends. `gate(ids)` answers `{pass, reason}`; a
1230
+ * session past `timeoutMs` is stopped with all it started, and its item stays ready. `fresh` starts new sessions where kept ones would resume;
1132
1231
  * `waitLimit` holds each session while the account's usage limit is known to reset ahead.
1133
1232
  * `chat` ({answerMs}) keeps each session open to the operator (docs/Chat-Plan.md).
1134
1233
  * The core's moves it and its agents make name the run as their maker (`GCF-By`); the variable
@@ -1177,39 +1276,80 @@ async function runBatch(
1177
1276
  const override = { model, effort };
1178
1277
  // A bad override is the run's error, before anything starts.
1179
1278
  choiceOf(null, override);
1180
- const orphans = json(await core(['integrate', '--json']), 'integrate');
1279
+ const orphans = (await integrateNow(core)).results;
1181
1280
  const logs = path.join(path.resolve(projectDir), '.gcf-session', 'runs');
1182
1281
  await mkdir(logs, { recursive: true });
1183
1282
  const board = json(await core(['board', '--json']), 'board');
1184
- const runMode = modeOf(mode, board);
1283
+ // Each item where it runs: one part per mode, in the order their items came.
1284
+ const parts = [
1285
+ ...Map.groupBy(ids, (id) =>
1286
+ modeOf(
1287
+ mode,
1288
+ board,
1289
+ board.items?.find((i) => i.id === id),
1290
+ ),
1291
+ ),
1292
+ ];
1185
1293
  timeoutMs ??= (board.session_timeout_min ?? DEFAULT_TIMEOUT_MIN) * 60_000;
1186
1294
  // Before any item is claimed: a refusal here leaves no lock behind.
1187
1295
  const launch = await launchOf(logs, managed, board, chat);
1188
- // The gate counts the items other runs hold locks on, so this run's locks go in with its gate.
1189
- // shortcut: a main run marks each item only as its session starts, so the items it has yet
1190
- // to reach do not count for another run's gate; claim them all here if main and worktree
1191
- // runs come to share a project.
1296
+ // One gate over the whole batch, and this run's holds go in with it: the gate counts the items
1297
+ // other runs hold. A worktree part's locks; a main part's checkout with its queue, the items it
1298
+ // has yet to reach.
1192
1299
  const { passed, claims } = await admitted(logs, async () => {
1193
1300
  const verdict = gate(ids);
1194
- const go = verdict.pass && runMode !== 'main';
1301
+ if (!verdict.pass) return { passed: verdict, claims: null };
1302
+ const held = new Map();
1303
+ try {
1304
+ for (const [m, part] of parts)
1305
+ held.set(m, m === 'main' ? await holdMain(logs, part) : await claimAll(part, logs));
1306
+ } catch (e) {
1307
+ // What was taken goes back: a hold the run never uses must not wait for its exit.
1308
+ for (const [m, h] of held)
1309
+ if (m === 'main') await h?.();
1310
+ else for (const c of h.claimed) await c.release();
1311
+ throw e;
1312
+ }
1195
1313
 
1196
- return { passed: verdict, claims: go ? await claimAll(ids, logs) : null };
1314
+ return { passed: verdict, claims: held };
1197
1315
  });
1198
1316
  if (!passed.pass) return { orphans, gate: passed.reason, items: [] };
1199
1317
 
1200
1318
  const { agentOf, agentFirst } = commandsOf(core, agent, board, override);
1201
- const ctx = { core, logs, agentOf, agentFirst, timeoutMs, fresh, launch, waitLimit, limitClock };
1319
+ const ctx = {
1320
+ ...{ projectDir, core, logs, agentOf, agentFirst, timeoutMs },
1321
+ ...{ fresh, launch, waitLimit, limitClock },
1322
+ };
1202
1323
  const unhook = stopWithSessions();
1203
1324
  try {
1204
- const items = await (runMode === 'main'
1205
- ? runMain(projectDir, ids, ctx)
1206
- : runWorktrees(claims, ctx));
1207
1325
  // The run's id: its start alone does not keep two runs started at once apart.
1208
1326
  const runOf = { id: `${started}-${process.pid}`, started };
1209
- logMetrics(projectDir, 'run-log.csv', items.map(runRow(runMode, runOf)));
1327
+ // Each part to its end, a failing one too: the other's sessions are not left behind.
1328
+ const driven = await Promise.allSettled(
1329
+ parts.map(async ([m, part]) => {
1330
+ const items = await (m === 'main'
1331
+ ? runMain(projectDir, part, claims.get(m), ctx)
1332
+ : runWorktrees(claims.get(m), ctx));
1333
+ logMetrics(projectDir, 'run-log.csv', items.map(runRow(m, runOf)));
1334
+
1335
+ return items;
1336
+ }),
1337
+ );
1338
+ const failed = driven.find((d) => d.status === 'rejected');
1339
+ if (failed) throw failed.reason;
1340
+ // The branches worktree runs verified while a main part held the checkout go in now; a main
1341
+ // its session left dirty keeps them for the next run.
1342
+ const after = claims.has('main')
1343
+ ? (await integrateNow(core).catch(() => ({ results: [] }))).results
1344
+ : [];
1210
1345
 
1211
1346
  // `limit_wait`: this harness waits for a usage limit's reset itself (AD-19); a board reads it.
1212
- return { orphans, mode: runMode, items, limit_wait: true };
1347
+ return {
1348
+ orphans: [...orphans, ...after],
1349
+ mode: parts.map(([m]) => m).join('+'),
1350
+ items: driven.flatMap((d) => (d.status === 'fulfilled' ? d.value : [])),
1351
+ limit_wait: true,
1352
+ };
1213
1353
  } finally {
1214
1354
  unhook();
1215
1355
  }
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.15.0",
4
+ "version": "0.18.1",
5
5
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
6
6
  "skills": [
7
7
  "skills/gcf-run",
@@ -219,12 +219,17 @@ export const claude = {
219
219
  .join(' '),
220
220
  /**
221
221
  * What an operator picks a session's model and effort from (Board-PRD decision 24); another
222
- * plain word goes too, and none leaves the choice to claude.
222
+ * plain word goes too.
223
223
  */
224
224
  presets: {
225
- model: ['opus', 'sonnet', 'haiku'],
225
+ model: ['fable', 'opus', 'sonnet', 'haiku'],
226
226
  effort: ['low', 'medium', 'high', 'xhigh', 'max'],
227
227
  },
228
+ /**
229
+ * What a session runs on when neither it nor the project picks (Board-PRD decision 36): aliases,
230
+ * never versions, so the machine's or the account's default never decides.
231
+ */
232
+ defaults: { model: 'opus', effort: 'high' },
228
233
  /** The flags of a picked model and effort (`{model?, effort?}`, plain words). */
229
234
  pickFlags: (pick) => PICKS.flatMap((k) => (pick?.[k] ? [`--${k} ${pick[k]}`] : [])).join(' '),
230
235
  /** The env a session adds: the guards read the session's own checkout. */
@@ -22,6 +22,7 @@ export const raw = {
22
22
  claude.command({ agent, flags, chat, prompt }),
23
23
  // An unknown command takes no claude flags of a model or effort.
24
24
  presets: { model: [], effort: [] },
25
+ defaults: {},
25
26
  pickFlags: () => '',
26
27
  };
27
28
 
@@ -31,9 +32,15 @@ export const raw = {
31
32
  */
32
33
  export const adapterFor = (command) =>
33
34
  /^claude(\s|$)/.test(command) ||
34
- (process.env.GCF_SESSION_AGENT && command === process.env.GCF_SESSION_AGENT)
35
+ // The stand-in with flags (a run's `--model opus`) is still the stand-in.
36
+ (process.env.GCF_SESSION_AGENT &&
37
+ (command === process.env.GCF_SESSION_AGENT ||
38
+ command.startsWith(`${process.env.GCF_SESSION_AGENT} `)))
35
39
  ? claude
36
40
  : raw;
37
41
 
38
42
  /** What an operator picks the model and effort of `command`'s sessions from. */
39
43
  export const presetsOf = (command) => adapterFor(command).presets;
44
+
45
+ /** What `command`'s sessions run on when neither they nor the project pick, `{model?, effort?}`. */
46
+ export const defaultsOf = (command) => adapterFor(command).defaults;
@@ -734,7 +734,7 @@ export function openChat(opts) {
734
734
  // A session that ended under a write to its stdin breaks the pipe: the end is its close.
735
735
  c.stdin.on('error', () => {});
736
736
  const from = opts.summary ? { summary: opts.summary } : {};
737
- // A project chat's session says the model and effort it was started with (null: the agent's).
737
+ // A project chat's session says the model and effort it was started with (null: none passed).
738
738
  const picked = opts.pick
739
739
  ? { model: opts.pick.model ?? null, effort: opts.pick.effort ?? null }
740
740
  : {};
@@ -31,7 +31,7 @@ export {
31
31
  export { addCost, beyond } from './cost.js';
32
32
  export { claim, clearDead, create, dead } from './lock.js';
33
33
  export { WIN, alive, byLine, killTree, sessions, spawnAgent, stopWithSessions } from './proc.js';
34
- export { adapterFor, presetsOf, raw } from './adapter/index.js';
34
+ export { adapterFor, defaultsOf, presetsOf, raw } from './adapter/index.js';
35
35
  export {
36
36
  NO_SESSION,
37
37
  PICKS,
@@ -78,6 +78,7 @@ const markOf = (dir, kind, key) => path.join(chatsDir(dir), kind, key);
78
78
  export function readThread(dir, t) {
79
79
  return {
80
80
  entry: null,
81
+ start: null,
81
82
  ...JSON.parse(readFileSync(path.join(threadDir(dir, t), 'thread.json'), 'utf8')),
82
83
  };
83
84
  }
@@ -100,12 +101,12 @@ function keepTrying(dir, t, rec) {
100
101
  // A picked model or effort goes into the agent's shell command: one plain word, no flag.
101
102
  const PICK_WORD = /^[A-Za-z0-9][\w.-]*$/;
102
103
 
103
- // The pick that leaves the choice to the agent.
104
+ // The pick that takes the thread's own off: the project's then holds, else the agent's defaults.
104
105
  const AGENT_DEFAULT = 'default';
105
106
 
106
107
  const pickFile = (td) => path.join(td, 'agent.json');
107
108
 
108
- /** A pick's word, or null for the agent's own: none, `default`, or a word that is not plain. */
109
+ /** A pick's word, or null for none of its own: none, `default`, or a word that is not plain. */
109
110
  const wordOf = (v) =>
110
111
  typeof v === 'string' && v !== AGENT_DEFAULT && PICK_WORD.test(v) ? v : null;
111
112
 
@@ -122,12 +123,15 @@ function pickIn(td) {
122
123
  }
123
124
  }
124
125
 
125
- /** The model and effort thread `t`'s sessions run on, `{model?, effort?}`; none: the agent's. */
126
+ /**
127
+ * The model and effort thread `t` picked, `{model?, effort?}`; none: the project's, else the
128
+ * agent's defaults (Board-PRD decision 36).
129
+ */
126
130
  export const threadAgent = (dir, t) => pickIn(threadDir(dir, t));
127
131
 
128
132
  /**
129
133
  * Pick the model and effort of thread `t` (Board-PRD decision 24): each a plain word, `default`
130
- * or null the agent's own choice, one left out kept as it is. Its next session takes them (a
134
+ * or null takes the thread's own off, one left out kept as it is. Its next session takes them (a
131
135
  * resume or a fresh agent); the live one keeps its own. Returns the pick kept. A word that is not
132
136
  * plain is a RangeError.
133
137
  * @param {{model?: string | null, effort?: string | null}} pick
@@ -211,10 +215,13 @@ function markOnce(dir, [kind, key], t, last = false) {
211
215
  /**
212
216
  * A new thread, its id; bound to `item` or to inbox `entry`, the one it already has (AD-46).
213
217
  * Ids and the marks are made exclusively: two at once never take one id, nor give an item or an
214
- * entry two threads. Both `item` and `entry` is a RangeError.
218
+ * entry two threads. Both `item` and `entry` is a RangeError. `start` is what the caller started
219
+ * the thread for (a board's design start, `{id, …}`), kept in the record as given: every session
220
+ * of the thread, a handoff's too, runs by it. A started thread is bound to nothing.
215
221
  */
216
- export function createThread(dir, { item = null, entry = null } = {}) {
222
+ export function createThread(dir, { item = null, entry = null, start = null } = {}) {
217
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');
218
225
  const [kind, key] = item ? ['items', item] : ['entries', entry];
219
226
  const had = key ? boundTo(dir, kind, key) : null;
220
227
  if (had) return had;
@@ -224,7 +231,7 @@ export function createThread(dir, { item = null, entry = null } = {}) {
224
231
  if (won !== t) return won;
225
232
 
226
233
  const now = new Date().toISOString();
227
- writeThread(dir, t, { id: t, item, entry, sessions: [], created_at: now, in_at: 0 });
234
+ writeThread(dir, t, { id: t, item, entry, start, sessions: [], created_at: now, in_at: 0 });
228
235
 
229
236
  return t;
230
237
  }
@@ -344,7 +351,8 @@ function flagsOf({ dir, td, spec, adapter }, settings) {
344
351
  * sessions (AD-41), each resumed from the one before, a fresh one after a handoff (AD-42).
345
352
  * `spec` (its `spec.json`): `agent`, `rules` `{deny, ask, allow}`, `mcp` (config files),
346
353
  * `answerMin`, `handoffPct`, `window`, `skill`, `mainLock`, `timeoutMin`, `pick` (the project's
347
- * model and effort, under the thread's own). `stopped()` says the operator stopped it.
354
+ * model and effort, under the thread's own, over the agent's defaults). `stopped()` says the
355
+ * operator stopped it.
348
356
  * @param {{stopped?: () => boolean}} [opts]
349
357
  */
350
358
  export async function runThread(dir, t, spec, opts = {}) {
@@ -580,8 +588,9 @@ function jobOf(s, record) {
580
588
  prompt: (kind, _caps, rec) => (rec?.ended === 'limit' ? AFTER_LIMIT : null),
581
589
  // The flags come before the chat of each session (job.js): the chat says what they picked.
582
590
  flags: (kind) => {
583
- // The thread's own pick over the project's (`spec.pick`, as the thread's agent started).
584
- s.pick = { ...wordsOf(spec.pick), ...pickIn(s.td) };
591
+ // The thread's own pick over the project's (`spec.pick`, as the thread's agent started),
592
+ // over the agent's defaults (Board-PRD decision 36).
593
+ s.pick = { ...s.adapter.defaults, ...wordsOf(spec.pick), ...pickIn(s.td) };
585
594
 
586
595
  return s.flags(kind, s.summary, s.pick);
587
596
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-session",
3
- "version": "0.14.0",
3
+ "version": "0.17.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",
@@ -15,7 +15,7 @@ export type ChatEvent = At &
15
15
  kind: 'start' | 'resume' | 'handoff';
16
16
  v?: number;
17
17
  summary?: string;
18
- /** A project chat's: the model and effort it started with; null, the agent's own. */
18
+ /** A project chat's: the model and effort it started with; null, the agent's own default. */
19
19
  model?: string | null;
20
20
  effort?: string | null;
21
21
  }
@@ -136,11 +136,19 @@ export interface Thread {
136
136
  item: string | null;
137
137
  /** The inbox entry the thread drafts an item from (Draft with agent); null for none. */
138
138
  entry: string | null;
139
+ /** What the thread was started for (a board's design start); null for none. */
140
+ start: ThreadStart | null;
139
141
  sessions: { session_id?: string; ended: string; kind: string; summary?: string }[];
140
142
  created_at: string;
141
143
  in_at: number;
142
144
  }
143
145
 
146
+ /** A start a thread runs by: its id, and what the caller gave it (a file, a unit, a text). */
147
+ export interface ThreadStart {
148
+ id: string;
149
+ [key: string]: string;
150
+ }
151
+
144
152
  /** How a thread runs, `chats/<t>/spec.json`: the center writes it. */
145
153
  export interface ThreadSpec {
146
154
  agent: string;
@@ -156,7 +164,10 @@ export interface ThreadSpec {
156
164
  pick?: AgentPick;
157
165
  }
158
166
 
159
- /** The model and effort an operator picked, `chats/<t>/agent.json`: none, the agent's own. */
167
+ /**
168
+ * The model and effort an operator picked, `chats/<t>/agent.json`: none, the project's, else the
169
+ * agent's defaults (`defaultsOf`, Board-PRD decision 36).
170
+ */
160
171
  export interface AgentPick {
161
172
  model?: string;
162
173
  effort?: string;
@@ -175,9 +186,11 @@ export declare function setThreadAgent(
175
186
  pick: { model?: string | null; effort?: string | null },
176
187
  ): AgentPick;
177
188
  export declare function presetsOf(agent: string): AgentPresets;
189
+ /** What `agent`'s sessions run on when neither they nor the project pick (decision 36). */
190
+ export declare function defaultsOf(agent: string): AgentPick;
178
191
  export declare function createThread(
179
192
  dir: string,
180
- opts?: { item?: string | null; entry?: string | null },
193
+ opts?: { item?: string | null; entry?: string | null; start?: ThreadStart | null },
181
194
  ): string;
182
195
  export declare function threadOf(dir: string, item: string): string | null;
183
196
  export declare function threadOfEntry(dir: string, entry: string): string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-harness-aif-ext",
3
- "version": "0.15.0",
3
+ "version": "0.18.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.14.0 || ^0.15.0"
31
+ "gcf-aif-ext": "^0.18.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "gcf-session": "file:../gcf-session"
@@ -83,7 +83,7 @@ workflow:
83
83
  18. a dependency still waiting for its verdict refuses the close: run `ai-factory gcf block <id> --reason "waits for <dep>"`
84
84
  19. close the run: delete `.gcf-session/readset.json`, run `ai-factory gcf playtest session` and hand its checklist to the human, with one report row per plan pass: pass, blocking, polish, result
85
85
  20. after a tune verdict or an unblock, re-enter this pipeline at step 5: the gates re-run because the counters moved
86
- 21. with `--worktree`: skip the integrate of step 1, steps 2-4 and the playtest of step 19, and change no `gcf/` file but the item's `live:` and new inbox entries (`ai-factory gcf inbox add`)
86
+ 21. with `--worktree`: skip the integrate of step 1, steps 2-4 and the playtest of step 19, and change no `gcf/` file but the item's `live:` and new inbox entries (`ai-factory gcf inbox add --category <c>`)
87
87
  22. with `--worktree`, every stop - a failed gate, an over budget readset, a failed plan check, a refused command, steps 11, 12, 14, 18 - writes `{"block": "<reason>"}` to `.gcf-session/outcome.json` and ends the session
88
88
  23. with `--worktree`, run no `ai-factory gcf block`, `submit` or `close`: the core refuses them on a `work/` branch, and the harness records the move on main
89
89
  24. with `--worktree`, step 17 is: commit everything but `gcf/.metrics`, then run `ai-factory gcf verify <id> --mark`; the harness merges the branch