gcf-harness-aif-ext 0.12.1 → 0.12.2

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.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.
51
+
50
52
  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.
51
53
  - **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`.
52
54
  - **Owners.** The handoff flag and the readset manifest name their owner and item: the guards act only on that session, so a project chat or an interactive claude in the same folder goes on. The guards are each a neutral decision and a claude shim, with the same files and input as before.
package/commands/run.js CHANGED
@@ -108,13 +108,13 @@ const RUN_WORD = /^[A-Za-z0-9][\w.-]*$/;
108
108
  /**
109
109
  * The agent command of one item: its `model:` and `effort:` become `--model` and `--effort`,
110
110
  * the flags of `claude`. The command goes through a shell, and an item file can be edited by
111
- * hand: a value that is not one plain word is refused.
111
+ * hand: a value that is not one plain word is refused; `default` leaves it to the agent.
112
112
  */
113
113
  export function agentFor(agent, item) {
114
114
  const flags = [];
115
115
  for (const k of ['model', 'effort']) {
116
116
  const v = item?.[k];
117
- if (v === null || v === undefined) continue;
117
+ if (v === null || v === undefined || v === 'default') continue;
118
118
  if (!RUN_WORD.test(String(v))) throw new Error(`${k}: ${v} is not one plain word`);
119
119
  flags.push(`--${k} ${v}`);
120
120
  }
@@ -882,7 +882,7 @@ async function mainItem(projectDir, id, ctx) {
882
882
  const s = {
883
883
  id,
884
884
  dir: projectDir,
885
- agent: agentOf(id),
885
+ agent: await agentOf(id),
886
886
  release: none,
887
887
  main: true,
888
888
  done,
@@ -984,8 +984,9 @@ const extras = (r, note = null) => {
984
984
 
985
985
  /** Every claimed item in its worktree at once; blocks recorded on main, verified ones merged. */
986
986
  async function runWorktrees(claims, ctx) {
987
- const { core, logs, agentOf } = ctx;
988
- const { ready, failed } = await prepare(claims, core, agentOf);
987
+ const { core, logs } = ctx;
988
+ // Its items are locked already: no move changes them after the run's first read.
989
+ const { ready, failed } = await prepare(claims, core, ctx.agentFirst);
989
990
  // A session that verified its branch, or left an outcome, is done: no fresh one follows.
990
991
  const done = (r) => () =>
991
992
  verified(r.dir, r.id) || existsSync(path.join(r.dir, '.gcf-session', 'outcome.json'));
@@ -1076,9 +1077,22 @@ export async function run(
1076
1077
  });
1077
1078
  if (!passed.pass) return { orphans, gate: passed.reason, items: [] };
1078
1079
 
1079
- const itemOf = (id) => (board.items ?? []).find((i) => i.id === id);
1080
- const agentOf = (id) => agentFor(agent, itemOf(id));
1081
- const ctx = { core, logs, agentOf, timeoutMs, fresh, launch, waitLimit, limitClock };
1080
+ const itemOf = (items, id) => (items ?? []).find((i) => i.id === id);
1081
+ // Read as the item starts: a main run's later items take a model or effort set meanwhile
1082
+ // (`gcf item agent`); a board that cannot be read leaves the run's first read.
1083
+ const agentOf = async (id) => {
1084
+ let now = null;
1085
+ try {
1086
+ now = itemOf(json(await core(['board', '--json']), 'board').items, id);
1087
+ } catch {
1088
+ // The first read below.
1089
+ }
1090
+
1091
+ return agentFor(agent, now ?? itemOf(board.items, id));
1092
+ };
1093
+
1094
+ const agentFirst = (id) => agentFor(agent, itemOf(board.items, id));
1095
+ const ctx = { core, logs, agentOf, agentFirst, timeoutMs, fresh, launch, waitLimit, limitClock };
1082
1096
  const unhook = stopWithSessions();
1083
1097
  try {
1084
1098
  const items = await (runMode === 'main'
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.12.1",
4
+ "version": "0.12.2",
5
5
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
6
6
  "skills": [
7
7
  "skills/gcf-run",
@@ -14,6 +14,9 @@ export const CHAT_FLAGS =
14
14
  // What `claude --resume` prints on stderr for a session it does not have.
15
15
  export const NO_SESSION = /No conversation found with session ID/;
16
16
 
17
+ /** What an operator may pick for a session (a thread's `agent.json`). */
18
+ export const PICKS = ['model', 'effort'];
19
+
17
20
  /** One line of stream-json input. */
18
21
  const line = (e) => `${JSON.stringify(e)}\n`;
19
22
 
@@ -214,6 +217,16 @@ export const claude = {
214
217
  [agent, resume && `--resume ${resume}`, flags, chat ? CHAT_FLAGS : `"${prompt}"`]
215
218
  .filter(Boolean)
216
219
  .join(' '),
220
+ /**
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.
223
+ */
224
+ presets: {
225
+ model: ['opus', 'sonnet', 'haiku'],
226
+ effort: ['low', 'medium', 'high', 'xhigh', 'max'],
227
+ },
228
+ /** The flags of a picked model and effort (`{model?, effort?}`, plain words). */
229
+ pickFlags: (pick) => PICKS.flatMap((k) => (pick?.[k] ? [`--${k} ${pick[k]}`] : [])).join(' '),
217
230
  /** The env a session adds: the guards read the session's own checkout. */
218
231
  env: (dir) => ({ CLAUDE_PROJECT_DIR: dir }),
219
232
  parse: activity,
@@ -20,6 +20,9 @@ export const raw = {
20
20
  },
21
21
  command: ({ agent, flags = '', chat = false, prompt }) =>
22
22
  claude.command({ agent, flags, chat, prompt }),
23
+ // An unknown command takes no claude flags of a model or effort.
24
+ presets: { model: [], effort: [] },
25
+ pickFlags: () => '',
23
26
  };
24
27
 
25
28
  /**
@@ -31,3 +34,6 @@ export const adapterFor = (command) =>
31
34
  (process.env.GCF_SESSION_AGENT && command === process.env.GCF_SESSION_AGENT)
32
35
  ? claude
33
36
  : raw;
37
+
38
+ /** What an operator picks the model and effort of `command`'s sessions from. */
39
+ export const presetsOf = (command) => adapterFor(command).presets;
@@ -708,7 +708,8 @@ function see(c, events) {
708
708
  * (`{flagged}`): a flagged session closes at its turn's end; `context()` the context it holds
709
709
  * (`{context, context_pct}`); `pause(on)` stops the session's timeout while it waits for the
710
710
  * operator; `prompt` is the first message; `kind` how the session started (`start`, `resume`,
711
- * `handoff`); `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says.
711
+ * `handoff`); `pick` the model and effort a project chat's session was started with;
712
+ * `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says.
712
713
  * `see(events)` takes the neutral events of each line the agent prints; `event(e)` posts one
713
714
  * the run saw; `encode` writes its input as the agent reads it;
714
715
  * `close(code, seen)` stops reading and posts the session's end.
@@ -726,7 +727,11 @@ export function openChat(opts) {
726
727
  // A session that ended under a write to its stdin breaks the pipe: the end is its close.
727
728
  c.stdin.on('error', () => {});
728
729
  const from = opts.summary ? { summary: opts.summary } : {};
729
- post(c, { type: 'session', kind: c.kind, v: EVENTS_V, ...from });
730
+ // A project chat's session says the model and effort it was started with (null: the agent's).
731
+ const picked = opts.pick
732
+ ? { model: opts.pick.model ?? null, effort: opts.pick.effort ?? null }
733
+ : {};
734
+ post(c, { type: 'session', kind: c.kind, v: EVENTS_V, ...from, ...picked });
730
735
  // A project chat starts on the operator's message, not on a prompt of its own.
731
736
  // A run's prompt is the run's; a project chat's (after the limit's reset) the engine's.
732
737
  if (opts.prompt) say(c, opts.prompt, c.handover ? 'engine' : 'run');
@@ -31,9 +31,10 @@ 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, raw } from './adapter/index.js';
34
+ export { adapterFor, presetsOf, raw } from './adapter/index.js';
35
35
  export {
36
36
  NO_SESSION,
37
+ PICKS,
37
38
  claude,
38
39
  encode,
39
40
  hookCall,
@@ -52,6 +53,8 @@ export {
52
53
  listThreads,
53
54
  readThread,
54
55
  runThread,
56
+ setThreadAgent,
57
+ threadAgent,
55
58
  threadDir,
56
59
  threadOf,
57
60
  } from './thread.js';
@@ -2,7 +2,8 @@
2
2
  // project's folder, run as a job with a chat policy. Its files live in `.gcf-session/chats/<t>/`:
3
3
  // `thread.json` (its sessions), `chat.jsonl` (what the operator reads), `chat-in.jsonl` (what
4
4
  // the operator writes), `att/` (pictures), `context.md` (what the center gives it to read),
5
- // `handoff-<n>.md` (the summaries its sessions handed over by), `spec.json` (how it runs).
5
+ // `handoff-<n>.md` (the summaries its sessions handed over by), `spec.json` (how it runs),
6
+ // `agent.json` (the model and effort the operator picked).
6
7
  import { randomBytes } from 'node:crypto';
7
8
  import {
8
9
  closeSync,
@@ -16,6 +17,7 @@ import {
16
17
  } from 'node:fs';
17
18
  import path from 'node:path';
18
19
  import { createHash } from 'node:crypto';
20
+ import { PICKS } from './adapter/claude.js';
19
21
  import { adapterFor } from './adapter/index.js';
20
22
  import { runJob } from './job.js';
21
23
  import { alive, killTree } from './proc.js';
@@ -82,6 +84,56 @@ function keepTrying(dir, t, rec) {
82
84
  }
83
85
  }
84
86
 
87
+ // A picked model or effort goes into the agent's shell command: one plain word, no flag.
88
+ const PICK_WORD = /^[A-Za-z0-9][\w.-]*$/;
89
+
90
+ // The pick that leaves the choice to the agent.
91
+ const AGENT_DEFAULT = 'default';
92
+
93
+ const pickFile = (td) => path.join(td, 'agent.json');
94
+
95
+ /** A pick's word, or null for the agent's own: none, `default`, or a word that is not plain. */
96
+ const wordOf = (v) =>
97
+ typeof v === 'string' && v !== AGENT_DEFAULT && PICK_WORD.test(v) ? v : null;
98
+
99
+ /** What `agent.json` of folder `td` picks, `{model?, effort?}`; a hand edit's bad word left out. */
100
+ function pickIn(td) {
101
+ try {
102
+ const v = JSON.parse(readFileSync(pickFile(td), 'utf8'));
103
+
104
+ return Object.fromEntries(PICKS.flatMap((k) => (wordOf(v?.[k]) ? [[k, v[k]]] : [])));
105
+ } catch {
106
+ return {};
107
+ }
108
+ }
109
+
110
+ /** The model and effort thread `t`'s sessions run on, `{model?, effort?}`; none: the agent's. */
111
+ export const threadAgent = (dir, t) => pickIn(threadDir(dir, t));
112
+
113
+ /**
114
+ * Pick the model and effort of thread `t` (Board-PRD decision 24): each a plain word, `default`
115
+ * or null the agent's own choice, one left out kept as it is. Its next session takes them (a
116
+ * resume or a fresh agent); the live one keeps its own. Returns the pick kept. A word that is not
117
+ * plain is a RangeError.
118
+ * @param {{model?: string | null, effort?: string | null}} pick
119
+ */
120
+ export function setThreadAgent(dir, t, pick) {
121
+ for (const k of PICKS)
122
+ if (pick[k] && !PICK_WORD.test(pick[k]))
123
+ throw new RangeError(`${k} is one plain word, e.g. opus`);
124
+ const was = threadAgent(dir, t);
125
+ const kept = Object.fromEntries(
126
+ PICKS.flatMap((k) => {
127
+ const v = pick[k] === undefined ? was[k] : wordOf(pick[k]);
128
+
129
+ return v ? [[k, v]] : [];
130
+ }),
131
+ );
132
+ writeAtomic(pickFile(threadDir(dir, t)), `${JSON.stringify(kept)}\n`);
133
+
134
+ return kept;
135
+ }
136
+
85
137
  /** The thread bound to `item`, or null (AD-46). */
86
138
  export function threadOf(dir, item) {
87
139
  try {
@@ -205,18 +257,20 @@ function promptFile(td, spec, summary) {
205
257
 
206
258
  /**
207
259
  * The flags of a thread's session: ask mode with the spec's rules (AD-5), the project's settings,
208
- * the MCP servers (the project's and the center's), and the prompt file at a start or a handoff.
260
+ * the MCP servers (the project's and the center's), the prompt file at a start or a handoff, and
261
+ * the model and effort picked (`pick`).
209
262
  * shortcut: claude's flags written out here; move them into the adapter with a second provider.
210
263
  */
211
- function flagsOf(dir, td, spec, settings) {
264
+ function flagsOf({ dir, td, spec, adapter }, settings) {
212
265
  const mcp = [
213
266
  ...(existsSync(path.join(dir, '.mcp.json')) ? ['.mcp.json'] : []),
214
267
  ...(spec.mcp ?? []),
215
268
  ];
216
269
 
217
- return (kind, summary) =>
270
+ return (kind, summary, pick) =>
218
271
  [
219
272
  '--permission-mode default --setting-sources project,local',
273
+ adapter.pickFlags(pick),
220
274
  `--settings "${settings}"`,
221
275
  ...(mcp.length ? ['--strict-mcp-config', ...mcp.map((f) => `--mcp-config "${f}"`)] : []),
222
276
  kind === 'resume' ? '' : `--append-system-prompt-file "${promptFile(td, spec, summary)}"`,
@@ -241,7 +295,9 @@ export async function runThread(dir, t, spec, opts = {}) {
241
295
  const last = rec.sessions.at(-1) ?? null;
242
296
  const s = {
243
297
  ...{ dir, t, td, rec, spec, adapter, stopped },
244
- flags: flagsOf(dir, td, spec, settingsOf(td, adapter, spec.rules)),
298
+ flags: flagsOf({ dir, td, spec, adapter }, settingsOf(td, adapter, spec.rules)),
299
+ // The model and effort of the session starting now: read afresh for each (agent.json).
300
+ pick: {},
245
301
  learned: readWindows(runsDir(dir)),
246
302
  input: inputOf(dir, t, rec),
247
303
  // The newest summary: a fresh start after a lost resume goes on from it too.
@@ -374,6 +430,7 @@ function chatOf(s, kind, prev) {
374
430
  saveAlways: (rule) => s.adapter.saveAlways(dir, rule),
375
431
  handover: handoverOf(s),
376
432
  summary: kind === 'handoff' ? s.summary : null,
433
+ pick: s.pick,
377
434
  fresh: kind === 'handoff' || Boolean(rec.unheard),
378
435
  onHeard: () => {
379
436
  rec.unheard = false;
@@ -401,7 +458,12 @@ function jobOf(s, record) {
401
458
  record,
402
459
  // A thread starts on the operator's message; after the usage limit's wait, on this.
403
460
  prompt: (kind, _caps, rec) => (rec?.ended === 'limit' ? AFTER_LIMIT : null),
404
- flags: (kind) => s.flags(kind, s.summary),
461
+ // The flags come before the chat of each session (job.js): the chat says what they picked.
462
+ flags: (kind) => {
463
+ s.pick = pickIn(s.td);
464
+
465
+ return s.flags(kind, s.summary, s.pick);
466
+ },
405
467
  onSpawn: (p) => {
406
468
  s.pid = p;
407
469
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-session",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
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",
@@ -10,7 +10,15 @@ interface At {
10
10
 
11
11
  export type ChatEvent = At &
12
12
  (
13
- | { type: 'session'; kind: 'start' | 'resume' | 'handoff'; v?: number; summary?: string }
13
+ | {
14
+ type: 'session';
15
+ kind: 'start' | 'resume' | 'handoff';
16
+ v?: number;
17
+ summary?: string;
18
+ /** A project chat's: the model and effort it started with; null, the agent's own. */
19
+ model?: string | null;
20
+ effort?: string | null;
21
+ }
14
22
  | {
15
23
  type: 'session_end';
16
24
  code: number | 'timeout' | 'handoff' | 'idle' | string;
@@ -139,6 +147,25 @@ export interface ThreadSpec {
139
147
  timeoutMin?: number;
140
148
  }
141
149
 
150
+ /** The model and effort an operator picked, `chats/<t>/agent.json`: none, the agent's own. */
151
+ export interface AgentPick {
152
+ model?: string;
153
+ effort?: string;
154
+ }
155
+
156
+ /** What an agent command offers to pick from (Board-PRD decision 24). */
157
+ export interface AgentPresets {
158
+ model: string[];
159
+ effort: string[];
160
+ }
161
+
162
+ export declare function threadAgent(dir: string, t: string): AgentPick;
163
+ export declare function setThreadAgent(
164
+ dir: string,
165
+ t: string,
166
+ pick: { model?: string | null; effort?: string | null },
167
+ ): AgentPick;
168
+ export declare function presetsOf(agent: string): AgentPresets;
142
169
  export declare function createThread(dir: string, opts?: { item?: string | null }): string;
143
170
  export declare function threadOf(dir: string, item: string): string | null;
144
171
  export declare function threadDir(dir: string, t: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gcf-harness-aif-ext",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
5
5
  "type": "module",
6
6
  "license": "MIT",