gcf-harness-aif-ext 0.5.0 → 0.6.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 +8 -2
- package/commands/harness.js +46 -0
- package/commands/run.js +186 -0
- package/extension.json +1 -1
- package/hooks/readset-guard.js +20 -10
- package/package.json +2 -2
- package/skills/gcf-run/SKILL.md +19 -12
- package/workflows/ingest.js +111 -9
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ The harness turns policy-as-text into an executable pipeline. It has **no memory
|
|
|
11
11
|
|
|
12
12
|
## Requirements
|
|
13
13
|
|
|
14
|
-
- [`gcf-aif-ext`](../gcf-aif-ext) `^0.
|
|
14
|
+
- [`gcf-aif-ext`](../gcf-aif-ext) `^0.5.0` installed, with a `gcf/` tree in the project — declared as a peer dependency, and `gcf-harness init` refuses when the `gcf` command is not registered
|
|
15
15
|
- Claude Code 2.1.270+ (hooks, dynamic workflows) — the only supported runtime
|
|
16
16
|
- AI Factory 2.x, Node.js ≥ 22.14
|
|
17
17
|
|
|
@@ -45,6 +45,10 @@ Updating keeps the hook entry valid — it points into the extension's install d
|
|
|
45
45
|
|
|
46
46
|
0.5.0 drives work items (`gcf/work/<id>.md`, schema 3) instead of cards and requires `gcf-aif-ext` 0.4.0 — update both together; against an older core the gate refuses with `gcf-aif-ext >= 0.4.0 is required`. A project still holding schema 2 cards in `gcf/cards/` re-creates them first (see the core's "Upgrading from 0.3.x"). What changes for you: `/gcf-run` takes ids of items in `ready`; it no longer stops at `built` but ends each item with `submit`, `close` or `block`; the plan is improved in passes until it converges; the WIP cap counts only items that end waiting for a verdict.
|
|
47
47
|
|
|
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
|
+
|
|
50
|
+
0.6.0 adds `ai-factory gcf-harness run` (a batch at once, a worktree and an agent session per item, then the integrator) and the `--worktree` mode of `/gcf-run`, whose session ritual now integrates the verified branches a dead run left. It requires `gcf-aif-ext` 0.5.0 (`gcf worktree`, `gcf integrate`, `gcf verify`) — update both together and run `ai-factory gcf init`. The DoD of `/gcf-run` is `ai-factory gcf verify <id>`, and the item's `live:` delta is written before it.
|
|
51
|
+
|
|
48
52
|
0.4.1 is a patch release. `/gcf-run` now commits the implementation first, then flips the card to `built` in a second commit, with `built_at` set to the implementation commit's hash. Update the core to 0.3.1 together with the harness: without it, an audit run before a verdict makes the pre-commit gate refuse that verdict.
|
|
49
53
|
|
|
50
54
|
To remove the extension:
|
|
@@ -57,10 +61,12 @@ Removal does not touch `.claude/settings.json`: delete the `PreToolUse` entry wh
|
|
|
57
61
|
|
|
58
62
|
## What it adds
|
|
59
63
|
|
|
60
|
-
**`/gcf-run <item-id…>`** — drives work items through plan, implementation and DoD, with every gate checked *before* the tokens are spent: the audit ritual, the gate below, the context budget. The plan is written by `aif-plan`, then improved in passes, each by a fresh subagent that reads only the plan and the readset and records every default it picks; `ai-factory gcf plan check <id>` runs after each pass, and a pass that changes no task ends the loop. A plan still changing after `plan_passes` passes, or a question only the human can answer (a save format, a public API, a new dependency, a pillar conflict), blocks the item before any code is written. The DoD is the project's `dod.
|
|
64
|
+
**`/gcf-run <item-id…>`** — drives work items through plan, implementation and DoD, with every gate checked *before* the tokens are spent: the audit ritual, the gate below, the context budget. The plan is written by `aif-plan`, then improved in passes, each by a fresh subagent that reads only the plan and the readset and records every default it picks; `ai-factory gcf plan check <id>` runs after each pass, and a pass that changes no task ends the loop. A plan still changing after `plan_passes` passes, or a question only the human can answer (a save format, a public API, a new dependency, a pillar conflict), blocks the item before any code is written. The DoD is `ai-factory gcf verify <id>` — the gate's checks, the item's `live:` delta, and the project's `dod.build` and `dod.test` commands from `gcf/config.yml` — plus a review by a fresh subagent, up to `dod_attempts` attempts. Every item ends in a state the core records: `gcf submit` (gate `verdict` or `decision` — waits for the human), `gcf close` (gate `auto` — done, or a soft unit closed as `unplayed`) or `gcf block` with the reason. The verdict and the decision belong to the human: the pipeline stops at `submit` and prints the playtest list.
|
|
61
65
|
|
|
62
66
|
**`ai-factory gcf-harness gate <item-id…>`** — the `/gcf-run` gate as code. It reads one `gcf audit --json` report and exits 1 with a one-line reason when the items may not go: a core older than 0.4.0, a `schema:` other than 1 in `gcf/config.yml`, an id with no work item, a feature (run its children; the feature closes when they are finished), an item that is not `ready`, an unplayed dependency, no WIP room for the batch (items awaiting a verdict + the batch's `gate: verdict` items over `wip_built_limit`), or two items of the batch touching the same system unless both say `parallel: ok`. The tune limit is not a gate rule: `verdict tune` itself refuses at the limit, and an item tuned up to it still gets its last build. The skill runs it and stops on a non-zero exit — no model compares the numbers.
|
|
63
67
|
|
|
68
|
+
**`ai-factory gcf-harness run <item-id…> [--agent "<cmd>"]`** — runs a batch at once, each item in its own worktree (`gcf worktree <id>`) with its own agent session: `claude -p "/gcf-run <id> --worktree"` by default, or the command in `--agent` / `GCF_RUN_AGENT`. The sessions run unattended, so set the agent's permissions for print mode first. A session ends with a commit and `gcf verify <id> --mark` (the `GCF-Verified` trailer); a question for the human goes into `.gcf-session/outcome.json` in its worktree, and `run` records the block on main. Then `gcf integrate` merges the verified branches and records each move, and `run` prints the playtest session. Its first step, like `/gcf-run`'s, integrates the verified branches a dead run left. A session that ended with no result leaves its item `ready`; the next `run` resumes its worktree. Logs: `.gcf-session/runs/<id>.log`. One run drives an item at a time (`.gcf-session/runs/<id>.lock`), and a resumed worktree first gets main merged in, so the answer from an `unblock` reaches the session. A worktree sees only what is committed: keep `.ai-factory.json`, the installed extensions and `.claude/` (skills, the readset-guard hook) in git, or the session has no `/gcf-run` and no `ai-factory gcf`.
|
|
69
|
+
|
|
64
70
|
**`/gcf-run-ingest <gdd.md>`** — imports a design document as a fan-out workflow: parallel aspect extraction, provenance verified by code rather than by an agent (a quote either is a verbatim substring of its section or it is not), completeness lenses per candidate, and an interaction matrix computed from the candidates that write the same state.
|
|
65
71
|
|
|
66
72
|
**readset-guard** — a `PreToolUse` hook on Read/Grep/Glob. While a run manifest exists at `.gcf-session/readset.json`, a path inside `gcf/` that is not in the readset is denied, and so is a Grep from the project root (no `path`, or a `path` above `gcf/`) unless its `glob` starts with a literal directory other than `gcf` (`src/**`, not `**/*.md`), because such a content search would read the whole tree past the gate. Glob and Greps scoped to the game code are never restricted. No manifest means no restriction: manual work is never gated. An honest limit — `cat` through Bash still bypasses it. This is a discipline tool, not a security perimeter.
|
package/commands/harness.js
CHANGED
|
@@ -7,6 +7,7 @@ import { existsSync } from 'node:fs';
|
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { run, cliCore, DEFAULT_AGENT } from './run.js';
|
|
10
11
|
|
|
11
12
|
const EXT_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
12
13
|
const MARKER = 'gcf-readset-guard';
|
|
@@ -237,4 +238,49 @@ export function register(program) {
|
|
|
237
238
|
.description('Gate work items before the paid stages of /gcf-run: exit 1 with the reason')
|
|
238
239
|
.option('--json', 'machine output: {pass, reason}')
|
|
239
240
|
.action(runGate);
|
|
241
|
+
|
|
242
|
+
harness
|
|
243
|
+
.command('run <ids...>')
|
|
244
|
+
.description('Run items at once, each in its worktree with its own agent, then integrate')
|
|
245
|
+
.option(
|
|
246
|
+
'--agent <command>',
|
|
247
|
+
'the agent command; it gets "/gcf-run <id> --worktree"',
|
|
248
|
+
process.env.GCF_RUN_AGENT ?? DEFAULT_AGENT,
|
|
249
|
+
)
|
|
250
|
+
.option('--json', 'machine output')
|
|
251
|
+
.action(runItems);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The run report a human reads, then the playtest sheet of what now waits for play. */
|
|
255
|
+
function printRun(r) {
|
|
256
|
+
for (const o of r.orphans)
|
|
257
|
+
console.log(`orphan ${o.id}: ${o.move ?? o.conflict ?? o.error ?? o.skipped}`);
|
|
258
|
+
if (r.gate) console.error(`gcf gate: ${r.gate}`);
|
|
259
|
+
for (const i of r.items) {
|
|
260
|
+
const why = i.reason ?? i.conflict ?? i.error ?? i.skipped;
|
|
261
|
+
console.log(`${i.id}: ${i.result}${why ? ` — ${why}` : ''}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!r.gate) console.log(`\n${cliCore(process.cwd())(['playtest', 'session']).out.trim()}`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const failed = (r) =>
|
|
268
|
+
Boolean(r.gate) ||
|
|
269
|
+
r.items.some((i) => ['conflict', 'error'].includes(i.result)) ||
|
|
270
|
+
r.orphans.some((o) => o.conflict || o.error);
|
|
271
|
+
|
|
272
|
+
async function runItems(ids, opts) {
|
|
273
|
+
try {
|
|
274
|
+
const r = await run(process.cwd(), [...new Set(ids)], {
|
|
275
|
+
agent: opts.agent,
|
|
276
|
+
gate: (batch) => gate(auditReport(), batch),
|
|
277
|
+
});
|
|
278
|
+
if (opts.json) console.log(JSON.stringify(r, null, 2));
|
|
279
|
+
else printRun(r);
|
|
280
|
+
if (failed(r)) process.exitCode = 1;
|
|
281
|
+
} catch (e) {
|
|
282
|
+
// A refusal of the core (main not clean, no core) ends the run with its one line.
|
|
283
|
+
console.error(`gcf-harness run: ${e.message}`);
|
|
284
|
+
process.exitCode = 1;
|
|
285
|
+
}
|
|
240
286
|
}
|
package/commands/run.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// `ai-factory gcf-harness run <ids…>` (Methodology §7): every item runs in its own worktree with
|
|
2
|
+
// its own agent session, all at once; the integrator ends the run. The first step picks up the
|
|
3
|
+
// verified branches a dead run left; an agent that needs the human leaves `outcome.json` in its
|
|
4
|
+
// worktree, and the block is recorded on main — a worktree never writes gcf/ status.
|
|
5
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { mkdir, open, readFile, rm, writeFile } from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_AGENT = 'claude -p';
|
|
11
|
+
|
|
12
|
+
/** The core CLI: the same ai-factory that runs this command, in the project. */
|
|
13
|
+
export function cliCore(projectDir) {
|
|
14
|
+
return (args) => {
|
|
15
|
+
const res = spawnSync(process.execPath, [process.argv[1], 'gcf', ...args], {
|
|
16
|
+
cwd: projectDir,
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return { ok: res.status === 0, out: res.stdout ?? '', err: res.stderr ?? '' };
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function json(res, what) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(res.out);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw new Error(`ai-factory gcf ${what} gave no report: ${(res.err || res.out).trim()}`, {
|
|
29
|
+
cause: e,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One agent session in the item's worktree; resolves with its exit code. */
|
|
35
|
+
function startAgent(agent, id, dir, fd) {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
const child = spawn(`${agent} "/gcf-run ${id} --worktree"`, {
|
|
38
|
+
cwd: dir,
|
|
39
|
+
shell: true,
|
|
40
|
+
stdio: ['ignore', fd, fd],
|
|
41
|
+
});
|
|
42
|
+
child.on('error', () => resolve(-1));
|
|
43
|
+
child.on('exit', (code) => resolve(code ?? -1));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** What the agent left for the main checkout: `{block: <reason>}`, or null. */
|
|
48
|
+
async function outcomeOf(dir) {
|
|
49
|
+
const file = path.join(dir, '.gcf-session', 'outcome.json');
|
|
50
|
+
if (!existsSync(file)) return null;
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(await readFile(file, 'utf8'));
|
|
53
|
+
} catch {
|
|
54
|
+
return { block: `the run left an unreadable ${file}` };
|
|
55
|
+
} finally {
|
|
56
|
+
await rm(file, { force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One harness run per item at a time: `.gcf-session/runs/<id>.lock` holds the pid of the run
|
|
62
|
+
* that drives it. A lock whose process is gone is taken over. Returns the release, or null.
|
|
63
|
+
*/
|
|
64
|
+
async function claim(logs, id) {
|
|
65
|
+
const file = path.join(logs, `${id}.lock`);
|
|
66
|
+
try {
|
|
67
|
+
const pid = Number((await readFile(file, 'utf8')).trim());
|
|
68
|
+
process.kill(pid, 0);
|
|
69
|
+
if (pid !== process.pid) return null;
|
|
70
|
+
} catch {
|
|
71
|
+
// no lock, or its process is gone
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await writeFile(file, `${process.pid}\n`);
|
|
75
|
+
|
|
76
|
+
return () => rm(file, { force: true });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Whether the tip of the worktree's branch carries `GCF-Verified: <id>`. */
|
|
80
|
+
function verified(dir, id) {
|
|
81
|
+
const res = spawnSync('git', ['log', '-1', '--format=%(trailers:key=GCF-Verified,valueonly)'], {
|
|
82
|
+
cwd: dir,
|
|
83
|
+
encoding: 'utf8',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return (res.stdout ?? '').split('\n').some((v) => v.trim() === id);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The worktree of each item, claimed for this run; an item that cannot start is an error. */
|
|
90
|
+
async function prepare(ids, core, logs) {
|
|
91
|
+
const ready = [];
|
|
92
|
+
const failed = [];
|
|
93
|
+
for (const id of ids) {
|
|
94
|
+
const release = await claim(logs, id);
|
|
95
|
+
if (!release) {
|
|
96
|
+
failed.push({ id, result: 'error', error: `${id} is already running in another run` });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const wt = json(await core(['worktree', id, '--json']), `worktree ${id}`);
|
|
102
|
+
if (wt.sync) throw new Error(wt.sync);
|
|
103
|
+
ready.push({ id, dir: wt.path, release });
|
|
104
|
+
} catch (e) {
|
|
105
|
+
await release();
|
|
106
|
+
failed.push({ id, result: 'error', error: e.message });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { ready, failed };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** One session per item, its output in `.gcf-session/runs/<id>.log`. */
|
|
114
|
+
async function session(r, agent, logs) {
|
|
115
|
+
const log = await open(path.join(logs, `${r.id}.log`), 'a');
|
|
116
|
+
try {
|
|
117
|
+
return { ...r, code: await startAgent(agent, r.id, r.dir, log.fd) };
|
|
118
|
+
} finally {
|
|
119
|
+
await log.close();
|
|
120
|
+
await r.release();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A run that asked to block is recorded on main. Asked after its branch was verified, the
|
|
126
|
+
* block wins: an empty commit takes the trailer off the tip, so no integrate merges it.
|
|
127
|
+
*/
|
|
128
|
+
async function recordBlock(r, outcome, core) {
|
|
129
|
+
const reason = String(outcome.block);
|
|
130
|
+
if (verified(r.dir, r.id))
|
|
131
|
+
spawnSync('git', ['commit', '--allow-empty', '-m', `gcf(unverified): ${r.id}`], { cwd: r.dir });
|
|
132
|
+
const b = await core(['block', r.id, '--reason', reason]);
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
id: r.id,
|
|
136
|
+
result: b.ok ? 'block' : 'error',
|
|
137
|
+
reason,
|
|
138
|
+
...(b.ok ? {} : { error: (b.err || b.out).trim() }),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The result line of an item the integrator handled, or why it has none. */
|
|
143
|
+
function resultOf(run, integrated) {
|
|
144
|
+
const done = integrated.find((x) => x.id === run.id);
|
|
145
|
+
if (!done)
|
|
146
|
+
return {
|
|
147
|
+
id: run.id,
|
|
148
|
+
result:
|
|
149
|
+
`no result (agent exit ${run.code}): ${run.id} stays ready, a rerun resumes its ` +
|
|
150
|
+
'worktree',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
...done,
|
|
155
|
+
result: done.move ?? (done.conflict ? 'conflict' : done.error ? 'error' : 'skipped'),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Pick up orphans, gate the batch, run every item in its worktree at once, record each block
|
|
161
|
+
* on main, integrate the verified branches. `gate(ids)` answers `{pass, reason}`.
|
|
162
|
+
*/
|
|
163
|
+
export async function run(
|
|
164
|
+
projectDir,
|
|
165
|
+
ids,
|
|
166
|
+
{ core = cliCore(projectDir), agent = DEFAULT_AGENT, gate },
|
|
167
|
+
) {
|
|
168
|
+
const orphans = json(await core(['integrate', '--json']), 'integrate');
|
|
169
|
+
const passed = gate(ids);
|
|
170
|
+
if (!passed.pass) return { orphans, gate: passed.reason, items: [] };
|
|
171
|
+
|
|
172
|
+
const logs = path.join(path.resolve(projectDir), '.gcf-session', 'runs');
|
|
173
|
+
await mkdir(logs, { recursive: true });
|
|
174
|
+
const { ready, failed } = await prepare(ids, core, logs);
|
|
175
|
+
const runs = await Promise.all(ready.map((r) => session(r, agent, logs)));
|
|
176
|
+
const items = [...failed];
|
|
177
|
+
for (const r of runs) {
|
|
178
|
+
const outcome = await outcomeOf(r.dir);
|
|
179
|
+
if (outcome?.block) items.push(await recordBlock(r, outcome, core));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const integrated = json(await core(['integrate', '--json']), 'integrate');
|
|
183
|
+
for (const r of runs) if (!items.some((i) => i.id === r.id)) items.push(resultOf(r, integrated));
|
|
184
|
+
|
|
185
|
+
return { orphans, items };
|
|
186
|
+
}
|
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.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "GCF orchestration harness for Claude Code: one-command card pipeline, readset guard",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/gcf-run",
|
package/hooks/readset-guard.js
CHANGED
|
@@ -49,22 +49,32 @@ function outsideVerdict(input, abs, gcfRoot) {
|
|
|
49
49
|
return { allow: false, reason: UNSCOPED_GREP };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The files a manifest allows, plus the two every stage may always read: the index, and the
|
|
54
|
+
* config whose DoD commands and limits the run reads at its plan and DoD steps.
|
|
55
|
+
*/
|
|
56
|
+
function allowedFiles(manifest) {
|
|
54
57
|
// `gcf context --json` emits files as {path, tokens_est}; accept that shape as well as
|
|
55
58
|
// the projected string list, so a manifest written either way still gates correctly.
|
|
56
59
|
const files = (manifest.files ?? []).map((f) => (typeof f === 'string' ? f : f?.path));
|
|
57
60
|
|
|
58
|
-
return new Set([...files.filter(Boolean), 'gcf/INDEX.md', 'gcf']);
|
|
61
|
+
return new Set([...files.filter(Boolean), 'gcf/INDEX.md', 'gcf/config.yml']);
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A path inside gcf/ passes only through the readset. A Grep reads every file under a
|
|
66
|
+
* directory, so it gets exact files only; Glob and Read may name a directory holding one.
|
|
67
|
+
*/
|
|
68
|
+
function insideVerdict(rel, manifest, tool) {
|
|
69
|
+
const allowed = allowedFiles(manifest);
|
|
64
70
|
if (allowed.has(rel)) return { allow: true };
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
71
|
+
const holds = [...allowed].some((f) => f.startsWith(`${rel}/`));
|
|
72
|
+
if (holds && tool !== 'Grep') return { allow: true };
|
|
73
|
+
if (holds)
|
|
74
|
+
return {
|
|
75
|
+
allow: false,
|
|
76
|
+
reason: `a Grep over ${rel} reads files outside the readset — Grep a readset file by path.`,
|
|
77
|
+
};
|
|
68
78
|
|
|
69
79
|
return {
|
|
70
80
|
allow: false,
|
|
@@ -94,7 +104,7 @@ export function decide(input, projectDir, manifest) {
|
|
|
94
104
|
// The gcf root itself relativizes to '' — unguarded it becomes 'gcf/' and matches nothing.
|
|
95
105
|
const relPosix = relFromGcf.replaceAll('\\', '/');
|
|
96
106
|
|
|
97
|
-
return insideVerdict(relPosix ? `gcf/${relPosix}` : 'gcf', manifest);
|
|
107
|
+
return insideVerdict(relPosix ? `gcf/${relPosix}` : 'gcf', manifest, input.tool_name);
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
function readManifest(projectDir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-harness-aif-ext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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)\""
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"gcf-aif-ext": "^0.
|
|
31
|
+
"gcf-aif-ext": "^0.5.0"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"extension.json",
|
package/skills/gcf-run/SKILL.md
CHANGED
|
@@ -11,6 +11,7 @@ purpose:
|
|
|
11
11
|
|
|
12
12
|
inputs:
|
|
13
13
|
- 1 or more work item or design unit ids; a batch shares one build and one playtest list
|
|
14
|
+
- `--worktree` when `ai-factory gcf-harness run` started this session inside the item's worktree
|
|
14
15
|
|
|
15
16
|
preconditions:
|
|
16
17
|
- `gcf/` exists and `ai-factory gcf audit` runs (the gcf-aif-ext extension provides it)
|
|
@@ -24,7 +25,7 @@ forbidden_behaviors:
|
|
|
24
25
|
- do not edit `status:` or `gcf/LIVE.md` by hand: `submit`, `close` and `block` own them
|
|
25
26
|
|
|
26
27
|
workflow:
|
|
27
|
-
1. session ritual: delete a `.gcf-session/readset.json` left by a killed run; run `ai-factory gcf audit --json`; read `gcf/INDEX.md`; report the audit first line
|
|
28
|
+
1. session ritual: delete a `.gcf-session/readset.json` left by a killed run; run `ai-factory gcf integrate` to merge the verified branches a dead run left; run `ai-factory gcf audit --json`; read `gcf/INDEX.md`; report the audit first line
|
|
28
29
|
2. for a unit still in `gcf/design/`: take it with the gcf-card skill first
|
|
29
30
|
3. for a feature id: replace it with its `ready` children from the audit report's `items` (`parent` names the feature) that are not in `open_depends`; a feature in `awaiting-decision` starts none of them
|
|
30
31
|
4. of those children, keep one per subsystem unless every child sharing it says `parallel: ok`; the rest wait for the next run; an empty list: report "nothing to run" and stop
|
|
@@ -32,16 +33,22 @@ workflow:
|
|
|
32
33
|
6. readset: run `ai-factory gcf context <item-id> --json`; write `{"item":"<id>","files": ctx.files.map(f => f.path)}` to `.gcf-session/readset.json` - paths, not objects; `over_budget: true` stops the run with a D1 question naming the subsystem
|
|
33
34
|
7. plan: run aif-plan full for the item into its `plan:` path, by default `.ai-factory/plans/<id>.md`, reading only the readset files; an existing plan (the item came back after a tune, an unblock or a continue) is kept, not rewritten
|
|
34
35
|
8. improve the plan in passes, each pass a fresh subagent that reads only the plan and the readset and applies aif-improve without questions, writing each default it picks into the plan
|
|
35
|
-
9.
|
|
36
|
-
10.
|
|
37
|
-
11.
|
|
38
|
-
12.
|
|
39
|
-
13.
|
|
40
|
-
14. commit the
|
|
41
|
-
15.
|
|
42
|
-
16.
|
|
43
|
-
17.
|
|
44
|
-
18.
|
|
36
|
+
9. each pass also checks every task against the `invariant` of each pillar in `gcf/PILLARS.md`: the pass reworks a task that breaks one, and a conflict no rework removes is a pillar conflict of step 12
|
|
37
|
+
10. after each pass run `ai-factory gcf plan check <id>`; a failure blocks the item with its reason; a pass that changes no task ends the loop - the plan converged
|
|
38
|
+
11. passes <= `plan_passes` from `gcf/config.yml` (5 by default); a plan still changing after the last pass: run `ai-factory gcf block <id> --reason "plan did not converge"` and stop
|
|
39
|
+
12. a question only the human can answer - a save format, a public API, a new dependency, a pillar conflict: run `ai-factory gcf block <id> --reason "<question>"` and stop
|
|
40
|
+
13. implement with aif-implement, write the item's `live:` delta, then run `ai-factory gcf verify <id>` and check the item's negative constraints; a non-zero exit is a red DoD; attempts <= `dod_attempts`, each with a diagnosis
|
|
41
|
+
14. review the diff with a fresh subagent; fix what it finds before the commit; DoD still red after the attempts: commit no code, run `ai-factory gcf block <id> --reason "<diagnosis>"` - its commit carries the item file with its delta
|
|
42
|
+
15. the reviewer also answers the `review_question` of each pillar in `gcf/PILLARS.md` over the diff: an answer that breaks the pillar is a finding
|
|
43
|
+
16. commit the implementation and the `live:` delta via aif-commit
|
|
44
|
+
17. gate `verdict` or `decision`: run `ai-factory gcf submit <id>`; gate `auto`: run `ai-factory gcf close <id>` - a soft unit closes unplayed
|
|
45
|
+
18. a dependency still waiting for its verdict refuses the close: run `ai-factory gcf block <id> --reason "waits for <dep>"`
|
|
46
|
+
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, tasks changed, result
|
|
47
|
+
20. after a tune verdict or an unblock, re-enter this pipeline at step 5: the gates re-run because the counters moved
|
|
48
|
+
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:`
|
|
49
|
+
22. with `--worktree`, every stop - a failed gate, an over budget readset, a failed plan check, steps 11, 12, 14, 18 - writes `{"block": "<reason>"}` to `.gcf-session/outcome.json` and ends the session
|
|
50
|
+
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
|
|
51
|
+
24. with `--worktree`, step 17 is: commit everything but `gcf/.metrics`, then run `ai-factory gcf verify <id> --mark`; the harness merges the branch
|
|
45
52
|
|
|
46
53
|
invocation:
|
|
47
|
-
- run when the user names a work item or a unit to drive; batches share steps 1 and
|
|
54
|
+
- run when the user names a work item or a unit to drive; batches share steps 1 and 19
|
package/workflows/ingest.js
CHANGED
|
@@ -140,12 +140,13 @@ const COHERENCE = [
|
|
|
140
140
|
const sectionText = (s) => `[${s.anchor}] ${s.heading ?? '(preamble)'}\n${s.body}`;
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
|
-
* GCF-PRD §11.7: a large GDD is cut into segments, each agent sees one. A section
|
|
144
|
-
*
|
|
143
|
+
* GCF-PRD §11.7: a large GDD is cut into segments, each agent sees one. A section longer than
|
|
144
|
+
* a segment is cut at paragraphs, each part keeps the section's anchor: quotes are verified
|
|
145
|
+
* against the whole section (bodyOf). ponytail: chars, not tokens.
|
|
145
146
|
*/
|
|
146
147
|
function packSegments(sections, limit) {
|
|
147
148
|
const segments = [];
|
|
148
|
-
for (const s of sections) {
|
|
149
|
+
for (const s of sections.flatMap((x) => sectionParts(x, limit))) {
|
|
149
150
|
const last = segments[segments.length - 1];
|
|
150
151
|
const text = sectionText(s);
|
|
151
152
|
if (last && last.size + text.length <= limit) {
|
|
@@ -159,6 +160,62 @@ function packSegments(sections, limit) {
|
|
|
159
160
|
return segments;
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
/** A section as parts that fit `limit`: whole paragraphs, a paragraph too long cut by length. */
|
|
164
|
+
function sectionParts(s, limit) {
|
|
165
|
+
if (sectionText(s).length <= limit) return [s];
|
|
166
|
+
// 24: room for the ` (part N of M)` the heading gains. A floor of 500: a segment_chars at or
|
|
167
|
+
// below the heading would otherwise cut the body into one part per character.
|
|
168
|
+
const room = Math.max(500, limit - sectionText({ ...s, body: '' }).length - 24);
|
|
169
|
+
const paras = s.body
|
|
170
|
+
.split(/\n\s*\n/)
|
|
171
|
+
.flatMap((p) =>
|
|
172
|
+
Array.from({ length: Math.ceil(p.length / room) || 1 }, (_, i) =>
|
|
173
|
+
p.slice(i * room, (i + 1) * room),
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
const bodies = [];
|
|
177
|
+
for (const p of paras) {
|
|
178
|
+
const last = bodies.length - 1;
|
|
179
|
+
if (last >= 0 && bodies[last].length + 2 + p.length <= room) bodies[last] += `\n\n${p}`;
|
|
180
|
+
else bodies.push(p);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return bodies.map((body, i) => ({
|
|
184
|
+
...s,
|
|
185
|
+
heading: `${s.heading ?? '(preamble)'} (part ${i + 1} of ${bodies.length})`,
|
|
186
|
+
body,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The part of a section an agent judging one unit needs: the whole body when it fits `limit`,
|
|
194
|
+
* else a window of `limit` chars centred on the quote, its edges pulled in to paragraph breaks
|
|
195
|
+
* that keep the quote. The quote matches across any whitespace, as provenance does, so one
|
|
196
|
+
* spanning two paragraphs is found too; a quote absent from the body yields its head.
|
|
197
|
+
*/
|
|
198
|
+
function around(body, quote, rawLimit) {
|
|
199
|
+
const limit = Math.max(500, rawLimit);
|
|
200
|
+
if (body.length <= limit) return body;
|
|
201
|
+
const words = String(quote ?? '')
|
|
202
|
+
.trim()
|
|
203
|
+
.split(/\s+/)
|
|
204
|
+
.filter(Boolean);
|
|
205
|
+
const m = words.length ? new RegExp(words.map(escapeRe).join('\\s+')).exec(body) : null;
|
|
206
|
+
if (!m) return body.slice(0, limit);
|
|
207
|
+
const qEnd = m.index + m[0].length;
|
|
208
|
+
let start = Math.max(0, m.index - Math.max(0, Math.floor((limit - m[0].length) / 2)));
|
|
209
|
+
let end = Math.min(body.length, start + limit);
|
|
210
|
+
start = Math.max(0, Math.min(start, end - limit));
|
|
211
|
+
const from = body.indexOf('\n\n', start);
|
|
212
|
+
if (start > 0 && from >= 0 && from + 2 <= m.index) start = from + 2;
|
|
213
|
+
const to = body.lastIndexOf('\n\n', end);
|
|
214
|
+
if (end < body.length && to >= qEnd) end = to;
|
|
215
|
+
|
|
216
|
+
return body.slice(start, end);
|
|
217
|
+
}
|
|
218
|
+
|
|
162
219
|
// A line wrap in the GDD is not an edit: whitespace runs compare equal, as in `gcf quotes`.
|
|
163
220
|
const ws = (t) => String(t).replace(/\s+/g, ' ').trim();
|
|
164
221
|
|
|
@@ -212,6 +269,30 @@ function crossingPairs(cands) {
|
|
|
212
269
|
return pairs;
|
|
213
270
|
}
|
|
214
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Drop the edge that closes each cycle of `deps` (id → ids it depends on), in place, and return
|
|
274
|
+
* each dropped edge with its cycle: which of the two really comes first is the designer's call.
|
|
275
|
+
*/
|
|
276
|
+
function breakCycles(deps) {
|
|
277
|
+
const broken = [];
|
|
278
|
+
const state = new Map();
|
|
279
|
+
const visit = (id, trail) => {
|
|
280
|
+
state.set(id, 'open');
|
|
281
|
+
for (const d of [...deps[id]]) {
|
|
282
|
+
if (state.get(d) === 'open') {
|
|
283
|
+
deps[id] = deps[id].filter((x) => x !== d);
|
|
284
|
+
broken.push({ id, dep: d, cycle: [...trail.slice(trail.indexOf(d)), id, d] });
|
|
285
|
+
} else if (!state.has(d)) visit(d, [...trail, id]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
state.set(id, 'done');
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
for (const id of Object.keys(deps)) if (!state.has(id)) visit(id, []);
|
|
292
|
+
|
|
293
|
+
return broken;
|
|
294
|
+
}
|
|
295
|
+
|
|
215
296
|
/** An id no unit has used yet: the agent's slug, suffixed -2, -3… on a collision. */
|
|
216
297
|
function freeId(wanted, taken) {
|
|
217
298
|
const base = /^[a-z0-9]+(-[a-z0-9]+)*$/.test(wanted ?? '') ? wanted : 'unit';
|
|
@@ -342,7 +423,8 @@ const spread = args.spread ?? 0.3;
|
|
|
342
423
|
// Every id the project has used (`ai-factory gcf where --json`): a dropped or done unit's id
|
|
343
424
|
// is never minted again, or the new unit would collide with the old one's history.
|
|
344
425
|
const taken = new Set(Array.isArray(args.taken) ? args.taken : []);
|
|
345
|
-
const
|
|
426
|
+
const segmentChars = Number(args.segment_chars) || 60000;
|
|
427
|
+
const segments = packSegments(sections, segmentChars);
|
|
346
428
|
const bodyOf = new Map(sections.map((s) => [s.anchor, s.body]));
|
|
347
429
|
const multi = segments.length > 1;
|
|
348
430
|
|
|
@@ -370,7 +452,7 @@ log(`${inferred.length} inferred units diverted to questions`);
|
|
|
370
452
|
|
|
371
453
|
phase('Lenses');
|
|
372
454
|
const enriched = await pipeline(candidates, (c) =>
|
|
373
|
-
ask(lensPrompt(c, subsystemNames, bodyOf.get(c.anchor) ?? ''), {
|
|
455
|
+
ask(lensPrompt(c, subsystemNames, around(bodyOf.get(c.anchor) ?? '', c.quote, segmentChars)), {
|
|
374
456
|
label: `lens:${c.name}`,
|
|
375
457
|
phase: 'Lenses',
|
|
376
458
|
schema: CAND_LENS,
|
|
@@ -396,10 +478,19 @@ const coherence = coherenceResults.flatMap((r) => r.findings);
|
|
|
396
478
|
phase('Conflicts');
|
|
397
479
|
const pairs = crossingPairs(cands);
|
|
398
480
|
log(`${pairs.length} crossing pair(s) from the interaction matrix`);
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
481
|
+
// Two units share the prompt, so each section gets half of a segment around its own quote.
|
|
482
|
+
const pairSections = ({ a, b }) => {
|
|
483
|
+
const units = a.anchor === b.anchor ? [a] : [a, b];
|
|
484
|
+
|
|
485
|
+
return units.map((u) => {
|
|
486
|
+
const s = sections.find((x) => x.anchor === u.anchor) ?? { anchor: u.anchor, body: '' };
|
|
487
|
+
const quotes = a.anchor === b.anchor ? [a.quote, b.quote] : [u.quote];
|
|
488
|
+
const body = quotes.map((q) => around(s.body, q, segmentChars / units.length / quotes.length));
|
|
489
|
+
|
|
490
|
+
return sectionText({ ...s, body: [...new Set(body)].join('\n\n[…]\n\n') });
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
|
|
403
494
|
const conflictResults = await pipeline(pairs, (p) =>
|
|
404
495
|
ask(conflictPrompt(p, pairSections(p)), {
|
|
405
496
|
label: `conflict:${p.a.name}×${p.b.name}`,
|
|
@@ -415,6 +506,16 @@ for (const { order, pair } of conflictResults) {
|
|
|
415
506
|
if (order === 'b_first') deps[pair.a.id].push(pair.b.id);
|
|
416
507
|
}
|
|
417
508
|
|
|
509
|
+
// Each pair agent decided alone: their orders may close a cycle the gate would never open.
|
|
510
|
+
const anchorOf = new Map(cands.map((c) => [c.id, c.anchor]));
|
|
511
|
+
const cycleQuestions = breakCycles(deps).map(({ id, dep, cycle }) => ({
|
|
512
|
+
lens: 'depends',
|
|
513
|
+
anchors: [...new Set(cycle.map((x) => anchorOf.get(x)))],
|
|
514
|
+
class: 'D1',
|
|
515
|
+
question: `the pair orders close a cycle ${cycle.join(' -> ')}: which comes first?`,
|
|
516
|
+
proposed: `${id} does not depend on ${dep}`,
|
|
517
|
+
}));
|
|
518
|
+
|
|
418
519
|
// ─── Package: deterministic code — an agent never writes the final report ────────────
|
|
419
520
|
|
|
420
521
|
const provenanceQuestions = inferred.map((u) => ({
|
|
@@ -448,6 +549,7 @@ const questions = [
|
|
|
448
549
|
...gddQuestions,
|
|
449
550
|
...coherence,
|
|
450
551
|
...conflicts,
|
|
552
|
+
...cycleQuestions,
|
|
451
553
|
...provenanceQuestions,
|
|
452
554
|
...envelopeQuestions,
|
|
453
555
|
];
|