gcf-harness-aif-ext 0.18.1 → 0.19.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 +8 -0
- package/commands/harness.js +167 -15
- package/commands/metrics.js +1 -1
- package/commands/milestones.js +1 -1
- package/commands/run.js +177 -9
- package/extension.json +1 -1
- package/hooks/implement-guard.js +4 -1
- package/node_modules/gcf-session/lib/activity.js +42 -11
- package/node_modules/gcf-session/lib/chat.js +96 -6
- package/node_modules/gcf-session/lib/job.js +2 -1
- package/node_modules/gcf-session/lib/session.js +11 -2
- package/node_modules/gcf-session/lib/thread.js +2 -16
- package/node_modules/gcf-session/package.json +1 -1
- package/package.json +2 -2
- package/skills/gcf-run/SKILL.md +15 -4
package/README.md
CHANGED
|
@@ -47,6 +47,14 @@ 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.19.1: `next --plan` first closes the features whose children are all finished: a keep by the operator, with no run after it, finishes them too. `card` reports a unit that left design without its item as `drop` (a `gcf(drop)` commit) or `none`, not `card`.
|
|
51
|
+
|
|
52
|
+
0.19.0 (gcf-aif-ext 0.19.0): `next --plan` gives the batch of the milestone being built, the units to card first and why nothing goes (a built milestone to play, an empty one); `--skip` leaves ids out. `gcf-harness card <units>` takes units into work in one session on main (gcf-card `--assume`). After a run the features whose children are all finished close. A run's result reads its move from the commit (`deferred`, `decide`). The skill gets `--assume` and `--decide` from the item's gates.
|
|
53
|
+
|
|
54
|
+
0.18.4 (bundled gcf-session 0.17.3): a refusal keeps only the call's command or file and its `description`, not its whole input; a chain's separators inside quotes split nothing; `**/` matches no folder too; a rule is named only when one alone holds.
|
|
55
|
+
|
|
56
|
+
0.18.3: `gate --each --json` gives `dirty`, the checkout's uncommitted paths outside `gcf/`: the board warns before a main run lands among them. A run's chat names a deny rule's refusal: the refused call's input, the project's rule that holds for it and the rule's group (bundled gcf-session 0.17.2, gcf-aif-ext 0.18.10 for the group).
|
|
57
|
+
|
|
50
58
|
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
59
|
|
|
52
60
|
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.
|
package/commands/harness.js
CHANGED
|
@@ -11,6 +11,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import { metricsCommand, runsCommand } from './metrics.js';
|
|
12
12
|
import {
|
|
13
13
|
run,
|
|
14
|
+
card,
|
|
15
|
+
closeFinishedFeatures,
|
|
14
16
|
cliCore,
|
|
15
17
|
DEFAULT_AGENT,
|
|
16
18
|
DEFAULT_TIMEOUT_MIN,
|
|
@@ -68,8 +70,10 @@ function itemProblem(id, item, report) {
|
|
|
68
70
|
function batchProblem(items, wip, elsewhere = []) {
|
|
69
71
|
// Only an item that ends waiting for a verdict takes a WIP place; `wip.over` is false at
|
|
70
72
|
// count === limit, and this run adds every such item of the batch — and of the other runs.
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
+
// One whose verdict the gates defer closes unplayed and takes none (core 0.19).
|
|
74
|
+
const waits = (i) => i.gate === 'verdict' && !i.deferred;
|
|
75
|
+
const waiting = items.filter(waits).length;
|
|
76
|
+
const coming = elsewhere.filter(waits).length;
|
|
73
77
|
if (waiting && wip.count + coming + waiting > wip.limit) {
|
|
74
78
|
const others = coming ? ` + ${coming} in other runs` : '';
|
|
75
79
|
|
|
@@ -100,23 +104,97 @@ const verdict = (reason) => ({ pass: !reason, reason: reason ?? '' });
|
|
|
100
104
|
const rank = (i) => i.priority ?? Number.MAX_SAFE_INTEGER;
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
|
-
* The
|
|
104
|
-
*
|
|
105
|
-
*
|
|
107
|
+
* The items of the milestone being built (docs/Autonomy-Plan.md, D): those of `build_milestone`,
|
|
108
|
+
* those with no milestone game.md knows, and every item they depend on through a later
|
|
109
|
+
* milestone (the audit names that order a finding). Null when game.md lists no milestones.
|
|
106
110
|
*/
|
|
107
|
-
|
|
111
|
+
function inScope(report) {
|
|
112
|
+
const milestones = report.milestones ?? [];
|
|
113
|
+
if (!milestones.length) return null;
|
|
114
|
+
const names = new Set(milestones.map((m) => m.name));
|
|
115
|
+
const byId = new Map((report.items ?? []).map((i) => [i.id, i]));
|
|
116
|
+
const scope = new Set(
|
|
117
|
+
(report.items ?? [])
|
|
118
|
+
.filter((i) => i.milestone === report.build_milestone || !names.has(i.milestone))
|
|
119
|
+
.map((i) => i.id),
|
|
120
|
+
);
|
|
121
|
+
const todo = [...scope];
|
|
122
|
+
while (todo.length) {
|
|
123
|
+
for (const d of byId.get(todo.pop())?.depends ?? [])
|
|
124
|
+
if (byId.has(d) && !scope.has(d)) {
|
|
125
|
+
scope.add(d);
|
|
126
|
+
todo.push(d);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return scope;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Why nothing goes on by itself now (the autopilot's stop), or null: a milestone built and
|
|
135
|
+
* waiting for its play under `gates.milestone: wait`, or one nobody laid out.
|
|
136
|
+
*/
|
|
137
|
+
function milestoneStop(report) {
|
|
138
|
+
const milestones = report.milestones ?? [];
|
|
139
|
+
const at = (name) => milestones.findIndex((m) => m.name === name);
|
|
140
|
+
const play = report.play_milestone;
|
|
141
|
+
const build = report.build_milestone;
|
|
142
|
+
// A later milestone built first does not stop the one before it.
|
|
143
|
+
if (play && report.gates?.milestone !== 'go' && (build === null || at(play) < at(build)))
|
|
144
|
+
return { kind: 'play', milestone: play, text: `milestone ${play} is built: play it` };
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The batch the gate lets go now, up to `count`, by priority, from the milestone being built:
|
|
151
|
+
* each item is taken while the batch with it still passes the gate — a dependency not played,
|
|
152
|
+
* a shared subsystem, a full WIP leave it out. `units`: the milestone's design units no D1
|
|
153
|
+
* holds, for `gcf-harness card` before their items exist. `stop`: why nothing goes, when the
|
|
154
|
+
* milestones say so. A release is the operator's: no batch takes it. `skip`: ids an autopilot
|
|
155
|
+
* leaves out (its loop guard), items and units alike.
|
|
156
|
+
*/
|
|
157
|
+
export function nextPlan(report, count, skip = []) {
|
|
158
|
+
const stop = milestoneStop(report);
|
|
159
|
+
if (stop) return { ids: [], mode: null, units: [], stop };
|
|
160
|
+
const scope = inScope(report);
|
|
108
161
|
const batch = [];
|
|
109
162
|
const ready = (report.items ?? [])
|
|
110
163
|
.filter((i) => i.status === 'ready' && !i.running && i.type !== 'feature')
|
|
164
|
+
.filter((i) => i.type !== 'release' && (!scope || scope.has(i.id)) && !skip.includes(i.id))
|
|
111
165
|
.sort((a, b) => rank(a) - rank(b));
|
|
166
|
+
// One run mode a batch: an autopilot starts it as one run, a main one in the checkout.
|
|
167
|
+
let mode = null;
|
|
112
168
|
for (const i of ready) {
|
|
113
169
|
if (batch.length >= count) break;
|
|
114
|
-
if (
|
|
170
|
+
if (mode && (i.run_mode ?? mode) !== mode) continue;
|
|
171
|
+
if (gate(report, [...batch, i.id]).pass) {
|
|
172
|
+
batch.push(i.id);
|
|
173
|
+
mode ??= i.run_mode ?? null;
|
|
174
|
+
}
|
|
115
175
|
}
|
|
116
176
|
|
|
117
|
-
|
|
177
|
+
const building = (report.milestones ?? []).find((m) => m.name === report.build_milestone);
|
|
178
|
+
const units = (building?.units ?? [])
|
|
179
|
+
.filter((u) => !u.blocked_by && !skip.includes(u.id))
|
|
180
|
+
.map((u) => u.id);
|
|
181
|
+
|
|
182
|
+
// A milestone nobody laid out stops it only once nothing else is left to take.
|
|
183
|
+
const empty =
|
|
184
|
+
!batch.length && !units.length && building?.empty
|
|
185
|
+
? {
|
|
186
|
+
kind: 'empty',
|
|
187
|
+
milestone: building.name,
|
|
188
|
+
text: `milestone ${building.name} is empty: lay it out`,
|
|
189
|
+
}
|
|
190
|
+
: null;
|
|
191
|
+
|
|
192
|
+
return { ids: batch, mode, units, stop: empty };
|
|
118
193
|
}
|
|
119
194
|
|
|
195
|
+
/** The ids of `nextPlan`: what a board's Run offers. */
|
|
196
|
+
export const nextBatch = (report, count) => nextPlan(report, count).ids;
|
|
197
|
+
|
|
120
198
|
/**
|
|
121
199
|
* Decides whether the work items may enter the paid stages, from one `gcf audit --json` report.
|
|
122
200
|
* Pure: the report is the whole input, so every rule has a test and no model compares numbers.
|
|
@@ -368,13 +446,43 @@ export function gateEach(report, ids) {
|
|
|
368
446
|
return { items: Object.fromEntries(named.map((id) => [id, gate(report, [id])])) };
|
|
369
447
|
}
|
|
370
448
|
|
|
449
|
+
/**
|
|
450
|
+
* The checkout's uncommitted paths outside `gcf/`, untracked ones too (a new folder as one): a
|
|
451
|
+
* main run's code lands among them, so the board warns before its click (Tails "Первым" 6). The
|
|
452
|
+
* moves' own refusals guard `gcf/`. Null outside a git checkout.
|
|
453
|
+
*/
|
|
454
|
+
export function loosePaths(dir) {
|
|
455
|
+
// No optional locks: a main run's agent may be committing in the same checkout.
|
|
456
|
+
const args = ['--no-optional-locks', 'status', '--porcelain', '-z', '--', '.', ':(exclude)gcf'];
|
|
457
|
+
const res = spawnSync('git', args, { cwd: dir, encoding: 'utf8' });
|
|
458
|
+
if (res.status !== 0) return null;
|
|
459
|
+
const parts = res.stdout.split('\0').filter(Boolean);
|
|
460
|
+
const paths = [];
|
|
461
|
+
// A rename or a copy gives its old path as the next part: the new one names it.
|
|
462
|
+
for (let i = 0; i < parts.length; i++) {
|
|
463
|
+
paths.push(parts[i].slice(3));
|
|
464
|
+
if (/^(?:[RC].|.[RC])/.test(parts[i])) i++;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return paths;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* `gate --each` as text: each item's answer, then the loose paths.
|
|
472
|
+
* @param {{ items: Record<string, { pass: boolean, reason: string }>, dirty?: string[] }} each
|
|
473
|
+
*/
|
|
474
|
+
function printEach({ items, dirty }) {
|
|
475
|
+
for (const [id, v] of Object.entries(items))
|
|
476
|
+
console.log(v.pass ? `${id}: pass` : `${id}: ${v.reason}`);
|
|
477
|
+
if (dirty?.length) console.log(`uncommitted outside gcf/: ${dirty.join(', ')}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
371
480
|
function runGate(ids, opts) {
|
|
372
481
|
if (opts.each) {
|
|
373
|
-
const
|
|
482
|
+
const dirty = loosePaths(process.cwd());
|
|
483
|
+
const result = { ...gateEach(auditReport(), [...new Set(ids)]), ...(dirty && { dirty }) };
|
|
374
484
|
if (opts.json) console.log(JSON.stringify(result));
|
|
375
|
-
else
|
|
376
|
-
for (const [id, v] of Object.entries(result.items))
|
|
377
|
-
console.log(v.pass ? `${id}: pass` : `${id}: ${v.reason}`);
|
|
485
|
+
else printEach(result);
|
|
378
486
|
|
|
379
487
|
return;
|
|
380
488
|
}
|
|
@@ -425,9 +533,51 @@ export function register(program) {
|
|
|
425
533
|
.command('next [count]')
|
|
426
534
|
.description('The ready items that can run together now, by priority (the gate decides)')
|
|
427
535
|
.option('--json', 'machine output: a list of ids')
|
|
428
|
-
.
|
|
429
|
-
|
|
430
|
-
|
|
536
|
+
.option(
|
|
537
|
+
'--plan',
|
|
538
|
+
'machine output for an autopilot: {ids, units (to card first), stop (why nothing goes)}',
|
|
539
|
+
)
|
|
540
|
+
.option('--skip <ids>', 'items and units to leave out, comma-separated')
|
|
541
|
+
.action(async (count, o) => {
|
|
542
|
+
// An autopilot's ask first closes the features the operator's verdicts finished: no run
|
|
543
|
+
// follows a keep, and nothing else would close them.
|
|
544
|
+
const features = o.plan ? await closeFinishedFeatures(cliCore(process.cwd())) : [];
|
|
545
|
+
const skip = String(o.skip ?? '')
|
|
546
|
+
.split(',')
|
|
547
|
+
.map((x) => x.trim())
|
|
548
|
+
.filter(Boolean);
|
|
549
|
+
const plan = nextPlan(auditReport(), Math.max(1, Number(count ?? 1) || 1), skip);
|
|
550
|
+
if (o.plan) return console.log(JSON.stringify({ ...plan, features }));
|
|
551
|
+
const { ids } = plan;
|
|
552
|
+
console.log(
|
|
553
|
+
o.json ? JSON.stringify(ids) : ids.join('\n') || plan.stop?.text || 'nothing can run now',
|
|
554
|
+
);
|
|
555
|
+
});
|
|
556
|
+
harness
|
|
557
|
+
.command('card <units...>')
|
|
558
|
+
.description(
|
|
559
|
+
'Take design units into work with no questions: one agent session on main runs gcf-card ' +
|
|
560
|
+
'--assume; a question only you can answer becomes a D1 that holds its unit',
|
|
561
|
+
)
|
|
562
|
+
.option(
|
|
563
|
+
'--agent <command>',
|
|
564
|
+
'the agent command',
|
|
565
|
+
process.env.GCF_SESSION_AGENT ?? process.env.GCF_RUN_AGENT ?? DEFAULT_AGENT,
|
|
566
|
+
)
|
|
567
|
+
.option('--json', 'machine output: {units: [{id, result}]}')
|
|
568
|
+
.action(async (units, o) => {
|
|
569
|
+
try {
|
|
570
|
+
const r = await card(process.cwd(), units, { agent: o.agent });
|
|
571
|
+
if (o.json) console.log(JSON.stringify(r, null, 2));
|
|
572
|
+
else for (const u of r.units) console.log(`${u.id}: ${u.result}`);
|
|
573
|
+
if (r.error) {
|
|
574
|
+
console.error(`gcf-harness card: ${r.error}`);
|
|
575
|
+
process.exitCode = 1;
|
|
576
|
+
}
|
|
577
|
+
} catch (e) {
|
|
578
|
+
console.error(`gcf-harness card: ${e.message}`);
|
|
579
|
+
process.exitCode = 1;
|
|
580
|
+
}
|
|
431
581
|
});
|
|
432
582
|
harness
|
|
433
583
|
.command('metrics')
|
|
@@ -588,6 +738,8 @@ function printRun(r) {
|
|
|
588
738
|
console.log(`orphan ${o.id}: ${o.move ?? o.conflict ?? o.error ?? o.skipped}`);
|
|
589
739
|
if (r.gate) console.error(`gcf gate: ${r.gate}`);
|
|
590
740
|
for (const i of r.items) console.log(itemLine(i));
|
|
741
|
+
for (const f of r.features ?? [])
|
|
742
|
+
console.log(`feature ${f.id}: ${f.result}${f.error ? ` — ${f.error}` : ''}`);
|
|
591
743
|
|
|
592
744
|
if (!r.gate) console.log(`\n${cliCore(process.cwd())(['playtest', 'session']).out.trim()}`);
|
|
593
745
|
}
|
package/commands/metrics.js
CHANGED
|
@@ -86,7 +86,7 @@ export function summarize(dir, since = '') {
|
|
|
86
86
|
// duration_ms, handoffs, process (then run_id, started, model, effort, log_from, log_to)
|
|
87
87
|
const runs = rows(dir, 'run-log.csv', since);
|
|
88
88
|
const finished = runs.filter((r) => !UNFINISHED.includes(r[3]));
|
|
89
|
-
const reached = finished.filter((r) => ['submit', 'close'].includes(r[3]));
|
|
89
|
+
const reached = finished.filter((r) => ['submit', 'close', 'decide', 'deferred'].includes(r[3]));
|
|
90
90
|
const spent = runs.map((r) => num(r[5])).filter((v) => v !== null);
|
|
91
91
|
// plan-log: at, item, ok, problems; verify-log: at, item, ok, failed checks, mark
|
|
92
92
|
const plans = rows(dir, 'plan-log.csv', since);
|
package/commands/milestones.js
CHANGED
|
@@ -15,7 +15,7 @@ const BASH = [
|
|
|
15
15
|
[/\bai-factory\s+gcf\s+plan\s+check\b/, 'plan-check'],
|
|
16
16
|
[/\bai-factory\s+gcf\s+verify\b/, 'dod'],
|
|
17
17
|
[/\bgit\s+commit\b/, 'commit'],
|
|
18
|
-
[/\bai-factory\s+gcf\s+(submit|close|block)\b/, 'move'],
|
|
18
|
+
[/\bai-factory\s+gcf\s+(submit|close|block|decide)\b/, 'move'],
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
/** The step a shell command is, or null. */
|
package/commands/run.js
CHANGED
|
@@ -98,6 +98,37 @@ export function cliCore(projectDir) {
|
|
|
98
98
|
* Merge the verified branches now (`gcf integrate`): their results; none, `waits`, while a main
|
|
99
99
|
* run works in the checkout: the core merges nothing under it, and they go in when it ends.
|
|
100
100
|
*/
|
|
101
|
+
/**
|
|
102
|
+
* Close each feature every child of which is finished (ended, unplayed or parked): nobody
|
|
103
|
+
* else would — a run drives no feature (docs/Autonomy-Plan.md, D). A close is an agent's move;
|
|
104
|
+
* one the core refuses (no live: delta, an open dependency) goes into the report as it is.
|
|
105
|
+
*/
|
|
106
|
+
export async function closeFinishedFeatures(core) {
|
|
107
|
+
const read = await core(['board', '--json']);
|
|
108
|
+
if (!read.ok) return [];
|
|
109
|
+
const items = json(read, 'board').items ?? [];
|
|
110
|
+
const byId = new Map(items.map((i) => [i.id, i]));
|
|
111
|
+
const finished = (c) => !byId.has(c) || ['unplayed', 'parked'].includes(byId.get(c).status);
|
|
112
|
+
const done = items.filter(
|
|
113
|
+
(i) =>
|
|
114
|
+
i.type === 'feature' &&
|
|
115
|
+
i.status === 'ready' &&
|
|
116
|
+
i.children?.length &&
|
|
117
|
+
i.children.every(finished),
|
|
118
|
+
);
|
|
119
|
+
const out = [];
|
|
120
|
+
for (const f of done) {
|
|
121
|
+
const r = await core(['close', f.id]);
|
|
122
|
+
out.push(
|
|
123
|
+
r.ok
|
|
124
|
+
? { id: f.id, result: 'close' }
|
|
125
|
+
: { id: f.id, result: 'error', error: (r.err || r.out).trim().split('\n')[0] },
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
101
132
|
async function integrateNow(core) {
|
|
102
133
|
const r = await core(['integrate', '--json']);
|
|
103
134
|
if (!r.ok && /a main run works in the main checkout/.test(r.err + r.out))
|
|
@@ -418,13 +449,21 @@ const STAYED = / stays ready, a rerun /;
|
|
|
418
449
|
// on main; in a worktree it records none (shortcut: ask them on main after the merge if it
|
|
419
450
|
// matters). `--ask d1|all`: what the skill asks the operator by a question card in a chat; none
|
|
420
451
|
// without.
|
|
452
|
+
// `--assume` under `gates.question: assume`: a D2 and on, no question card; `--decide` under
|
|
453
|
+
// `gates.decision: agent`: the skill decides its spike go or no (docs/Autonomy-Plan.md, B).
|
|
421
454
|
const taskOf = (r, launch, after) => {
|
|
422
|
-
|
|
455
|
+
// A session that is no item's /gcf-run (a card session) brings its own task.
|
|
456
|
+
if (r.task) return r.task;
|
|
457
|
+
const gates = launch?.gatesOf?.(r.id) ?? null;
|
|
458
|
+
const assume = gates?.question === 'assume';
|
|
459
|
+
const ask = assume ? null : launch?.chat?.ask;
|
|
423
460
|
|
|
424
461
|
return (
|
|
425
462
|
`/gcf-run ${r.id}${r.main ? '' : ' --worktree'}` +
|
|
426
463
|
(after ? ' --no-lessons' : '') +
|
|
427
|
-
(ask && ask !== 'none' ? ` --ask ${ask}` : '')
|
|
464
|
+
(ask && ask !== 'none' ? ` --ask ${ask}` : '') +
|
|
465
|
+
(assume ? ' --assume' : '') +
|
|
466
|
+
(gates?.decision === 'agent' ? ' --decide' : '')
|
|
428
467
|
);
|
|
429
468
|
};
|
|
430
469
|
|
|
@@ -849,7 +888,10 @@ async function launchOf(logs, managed, board, chat) {
|
|
|
849
888
|
},
|
|
850
889
|
learned,
|
|
851
890
|
planOf: (id) => board.items?.find((i) => i.id === id)?.plan_file ?? null,
|
|
852
|
-
|
|
891
|
+
// The gates in force for the item (core 0.19): the skill assumes, decides or asks by them.
|
|
892
|
+
gatesOf: (id) => board.items?.find((i) => i.id === id)?.gates ?? null,
|
|
893
|
+
// The deny rules the session runs by: a refusal in its chat names the rule and its group.
|
|
894
|
+
chat: chat && { ...chatOf(chat, board.chat), deny: managed ? board.agent.rules.deny : [] },
|
|
853
895
|
};
|
|
854
896
|
}
|
|
855
897
|
|
|
@@ -870,7 +912,7 @@ export function chatOf({ answerMin = null, graceMs }, config = {}) {
|
|
|
870
912
|
};
|
|
871
913
|
}
|
|
872
914
|
|
|
873
|
-
// The move an item's status shows after a run on main
|
|
915
|
+
// The move an item's status shows after a run on main, when no commit names it.
|
|
874
916
|
const MOVE_OF = {
|
|
875
917
|
'awaiting-verdict': 'submit',
|
|
876
918
|
'awaiting-decision': 'submit',
|
|
@@ -878,14 +920,34 @@ const MOVE_OF = {
|
|
|
878
920
|
blocked: 'block',
|
|
879
921
|
};
|
|
880
922
|
|
|
881
|
-
/**
|
|
923
|
+
/**
|
|
924
|
+
* The move the item's latest move commit names (`gcf(<move>): …`): a status cannot tell a
|
|
925
|
+
* deferred submit from a close (both unplayed), nor a decide (the item is gone). Null without.
|
|
926
|
+
*/
|
|
927
|
+
export function moveOfCommit(projectDir, id) {
|
|
928
|
+
const grep = String.raw`--grep=^gcf\((submit|close|block|decide)\): (go |no )?` + `${id}( |$)`;
|
|
929
|
+
const res = spawnSync('git', ['log', '-1', '-E', grep, '--format=%s'], {
|
|
930
|
+
cwd: projectDir,
|
|
931
|
+
encoding: 'utf8',
|
|
932
|
+
});
|
|
933
|
+
const m = res.status === 0 ? res.stdout.trim().match(/^gcf\((\w+)\): /) : null;
|
|
934
|
+
if (!m) return null;
|
|
935
|
+
|
|
936
|
+
return m[1] === 'submit' && /→ unplayed \(deferred\)/.test(res.stdout) ? 'deferred' : m[1];
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/** What a run on main left: the item's move read from its commit, else its status, or none. */
|
|
882
940
|
async function mainResult(core, r) {
|
|
883
941
|
const after = json(await core(['board', '--json']), 'board').items?.find((i) => i.id === r.id);
|
|
884
942
|
if (r.error) return { id: r.id, result: 'error', error: r.error };
|
|
885
|
-
// An item that ended left the board: its run closed it.
|
|
886
|
-
if (!after) return { id: r.id, result: 'close' };
|
|
943
|
+
// An item that ended left the board: its run closed or decided it.
|
|
944
|
+
if (!after) return { id: r.id, result: moveOfCommit(r.dir, r.id) ?? 'close' };
|
|
887
945
|
if (after.status !== 'ready')
|
|
888
|
-
return {
|
|
946
|
+
return {
|
|
947
|
+
id: r.id,
|
|
948
|
+
result: moveOfCommit(r.dir, r.id) ?? MOVE_OF[after.status] ?? after.status,
|
|
949
|
+
reason: after.blocked,
|
|
950
|
+
};
|
|
889
951
|
|
|
890
952
|
return noResult(r, 'a rerun picks it up');
|
|
891
953
|
}
|
|
@@ -924,6 +986,7 @@ async function runMain(projectDir, ids, releaseMain, ctx) {
|
|
|
924
986
|
writeAtomic(queueOf(logs), `${ids.slice(n + 1).join('\n')}\n`);
|
|
925
987
|
} catch {}
|
|
926
988
|
};
|
|
989
|
+
|
|
927
990
|
items.push(await mainItem(projectDir, id, { ...ctx, dequeue }));
|
|
928
991
|
}
|
|
929
992
|
} finally {
|
|
@@ -968,6 +1031,7 @@ async function mainItem(projectDir, id, ctx) {
|
|
|
968
1031
|
dequeue();
|
|
969
1032
|
throw new Error((claimed.err || claimed.out).trim());
|
|
970
1033
|
}
|
|
1034
|
+
|
|
971
1035
|
marked = true;
|
|
972
1036
|
dequeue();
|
|
973
1037
|
const none = async () => {};
|
|
@@ -1169,9 +1233,12 @@ async function runWorktrees(claims, ctx) {
|
|
|
1169
1233
|
: resultOf(r, integrated),
|
|
1170
1234
|
);
|
|
1171
1235
|
}
|
|
1236
|
+
|
|
1172
1237
|
// A worktree's session records no move: the chat hears of the one main recorded for it.
|
|
1173
1238
|
if (ctx.launch?.chat)
|
|
1174
|
-
for (const i of items.filter((x) =>
|
|
1239
|
+
for (const i of items.filter((x) =>
|
|
1240
|
+
['submit', 'close', 'block', 'decide', 'deferred'].includes(x.result),
|
|
1241
|
+
))
|
|
1175
1242
|
postTo(chatOut(logs, i.id), { type: 'step', step: 'move', move: i.result, ok: true });
|
|
1176
1243
|
for (const r of runs)
|
|
1177
1244
|
await remember(
|
|
@@ -1205,6 +1272,7 @@ function commandsOf(core, agent, board, override) {
|
|
|
1205
1272
|
choice: choiceOf(item, override, b.agent, defaultsOf(agent)),
|
|
1206
1273
|
};
|
|
1207
1274
|
};
|
|
1275
|
+
|
|
1208
1276
|
const agentOf = async (id) => {
|
|
1209
1277
|
let now = null;
|
|
1210
1278
|
try {
|
|
@@ -1245,6 +1313,103 @@ export const run = async (projectDir, ids, opts) => {
|
|
|
1245
1313
|
}
|
|
1246
1314
|
};
|
|
1247
1315
|
|
|
1316
|
+
/** Whether a commit dropped unit `id` (`gcf(drop): <id>`). */
|
|
1317
|
+
function droppedSince(projectDir, id) {
|
|
1318
|
+
const grep = String.raw`--grep=^gcf\(drop\): ` + `${id}( |$)`;
|
|
1319
|
+
const res = spawnSync('git', ['log', '-1', '-E', grep, '--format=%h'], {
|
|
1320
|
+
cwd: projectDir,
|
|
1321
|
+
encoding: 'utf8',
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
return res.status === 0 && Boolean(res.stdout.trim());
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// The pseudo item a card session runs as: its log, lock and stop file (`gcf-harness stop card`).
|
|
1328
|
+
export const CARD_RUN = 'card';
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* Units an autopilot takes into work (docs/Autonomy-Plan.md, D): one agent session on main,
|
|
1332
|
+
* holding the main checkout as a main run does, gives the gcf-card skill the units with
|
|
1333
|
+
* `--assume` — it asks nothing, and a question only the human can answer becomes a D1 record
|
|
1334
|
+
* with `blocks: <unit>`. Each unit's result: `card` (its work item is there), `question` (a D1
|
|
1335
|
+
* holds it), or `none`. The core's moves its agent makes are the run's.
|
|
1336
|
+
* @param {string} projectDir
|
|
1337
|
+
* @param {string[]} units
|
|
1338
|
+
*/
|
|
1339
|
+
export const card = async (projectDir, units, opts = {}) => {
|
|
1340
|
+
const was = { by: process.env.GCF_MOVE_BY, owner: process.env.GCF_RUN_OWNER };
|
|
1341
|
+
process.env.GCF_MOVE_BY = 'run';
|
|
1342
|
+
process.env.GCF_RUN_OWNER = `run:${process.pid}`;
|
|
1343
|
+
try {
|
|
1344
|
+
return await cardUnits(projectDir, units, opts);
|
|
1345
|
+
} finally {
|
|
1346
|
+
for (const [k, v] of [
|
|
1347
|
+
['GCF_MOVE_BY', was.by],
|
|
1348
|
+
['GCF_RUN_OWNER', was.owner],
|
|
1349
|
+
])
|
|
1350
|
+
if (v === undefined) delete process.env[k];
|
|
1351
|
+
else process.env[k] = v;
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
async function cardUnits(
|
|
1356
|
+
projectDir,
|
|
1357
|
+
units,
|
|
1358
|
+
{ core = cliCore(projectDir), agent = DEFAULT_AGENT, timeoutMs = undefined, managed } = {},
|
|
1359
|
+
) {
|
|
1360
|
+
const bad = units.find((id) => !/^[a-z0-9]+(-[a-z0-9]+)*$/.test(id));
|
|
1361
|
+
if (bad) throw new Error(`${bad} is not a unit id (a lowercase hyphen slug)`);
|
|
1362
|
+
if (!units.length) throw new Error('name the units to card');
|
|
1363
|
+
const logs = path.join(path.resolve(projectDir), '.gcf-session', 'runs');
|
|
1364
|
+
await mkdir(logs, { recursive: true });
|
|
1365
|
+
const board = json(await core(['board', '--json']), 'board');
|
|
1366
|
+
const release = await holdMain(logs, []);
|
|
1367
|
+
if (!release) throw new Error('another run works in the main checkout: wait for it, or stop it');
|
|
1368
|
+
let launch;
|
|
1369
|
+
let agentFirst;
|
|
1370
|
+
try {
|
|
1371
|
+
launch = await launchOf(logs, managed ?? agent === DEFAULT_AGENT, board, null);
|
|
1372
|
+
({ agentFirst } = commandsOf(core, agent, board, {}));
|
|
1373
|
+
} catch (e) {
|
|
1374
|
+
// Its session never starts: the checkout goes back now, not at the process's end.
|
|
1375
|
+
await release();
|
|
1376
|
+
throw e;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// The units still in design, and the D1 records that hold each: what is left to card.
|
|
1380
|
+
const left = async () => {
|
|
1381
|
+
const now = json(await core(['board', '--json']), 'board');
|
|
1382
|
+
const held = new Map((now.units ?? []).map((u) => [u.id, u.blocked_by ?? []]));
|
|
1383
|
+
const items = new Set((now.items ?? []).map((i) => i.id));
|
|
1384
|
+
// Out of design: its item is there (card), it was dropped (`gcf(drop)`, "already ships"),
|
|
1385
|
+
// or it left with neither (lost: none).
|
|
1386
|
+
const gone = (id) => (items.has(id) ? 'card' : droppedSince(projectDir, id) ? 'drop' : 'none');
|
|
1387
|
+
|
|
1388
|
+
return units.map((id) => ({
|
|
1389
|
+
id,
|
|
1390
|
+
result: !held.has(id) ? gone(id) : held.get(id).length ? 'question' : 'none',
|
|
1391
|
+
}));
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
const r = {
|
|
1395
|
+
id: CARD_RUN,
|
|
1396
|
+
dir: projectDir,
|
|
1397
|
+
...agentFirst(CARD_RUN),
|
|
1398
|
+
task: `/gcf-card ${units.join(' ')} --assume`,
|
|
1399
|
+
main: true,
|
|
1400
|
+
release,
|
|
1401
|
+
done: async () => (await left()).every((u) => u.result !== 'none'),
|
|
1402
|
+
};
|
|
1403
|
+
const timeout = timeoutMs ?? (board.session_timeout_min ?? DEFAULT_TIMEOUT_MIN) * 60_000;
|
|
1404
|
+
// Fresh: a card session cut before was for other units, nothing of it is to be resumed.
|
|
1405
|
+
const ran = await session(r, { core, logs, timeoutMs: timeout, launch, fresh: true });
|
|
1406
|
+
|
|
1407
|
+
const done = await left();
|
|
1408
|
+
|
|
1409
|
+
// `items`: the units as a run report's lines, for a board.
|
|
1410
|
+
return { units: done, items: done, ...(ran.error ? { error: ran.error } : {}), ...ran.cost };
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1248
1413
|
async function runBatch(
|
|
1249
1414
|
projectDir,
|
|
1250
1415
|
ids,
|
|
@@ -1342,12 +1507,15 @@ async function runBatch(
|
|
|
1342
1507
|
const after = claims.has('main')
|
|
1343
1508
|
? (await integrateNow(core).catch(() => ({ results: [] }))).results
|
|
1344
1509
|
: [];
|
|
1510
|
+
const features = await closeFinishedFeatures(core).catch(() => []);
|
|
1345
1511
|
|
|
1346
1512
|
// `limit_wait`: this harness waits for a usage limit's reset itself (AD-19); a board reads it.
|
|
1347
1513
|
return {
|
|
1348
1514
|
orphans: [...orphans, ...after],
|
|
1349
1515
|
mode: parts.map(([m]) => m).join('+'),
|
|
1350
1516
|
items: driven.flatMap((d) => (d.status === 'fulfilled' ? d.value : [])),
|
|
1517
|
+
// The features this run finished, closed after it: their close or the core's refusal.
|
|
1518
|
+
features,
|
|
1351
1519
|
limit_wait: true,
|
|
1352
1520
|
};
|
|
1353
1521
|
} finally {
|
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.19.1",
|
|
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/implement-guard.js
CHANGED
|
@@ -63,7 +63,10 @@ const started = (call, name) => skillIs(call, name) || promptIs(call, name);
|
|
|
63
63
|
// The move that ends a run's item, run as a command (not echoed or searched for): the session's
|
|
64
64
|
// work on it is over. A move the core then refuses frees the session too: fail open.
|
|
65
65
|
const CLI = String.raw`((npx\s+|pnpm\s+exec\s+|\S*[\\/])?ai-factory(\.cmd)?\s+)?`;
|
|
66
|
-
const ENDS = new RegExp(
|
|
66
|
+
const ENDS = new RegExp(
|
|
67
|
+
String.raw`(^|[;&|(])\s*${CLI}gcf\s+(block|submit|close|decide)\s+[a-z0-9]`,
|
|
68
|
+
'm',
|
|
69
|
+
);
|
|
67
70
|
const endsRun = (call) => call.kind === 'shell' && ENDS.test(String(call.command ?? ''));
|
|
68
71
|
// A move past the DoD gate (Methodology §6) is the human's: a session that ran /gcf-run never
|
|
69
72
|
// makes one, even after its end move (a close the core refused must not free it for a skip).
|
|
@@ -15,6 +15,20 @@ export const clock = (now = new Date()) => now.toTimeString().slice(0, 8);
|
|
|
15
15
|
|
|
16
16
|
const cut = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A text whole on one line: the board cuts what it shows (Tails 2026-10-25, the log cut it as
|
|
20
|
+
* it wrote). A failing test run's output is tens of kilobytes: past `LOG_MAX` it says how much
|
|
21
|
+
* more there was.
|
|
22
|
+
*/
|
|
23
|
+
const whole = (text) => {
|
|
24
|
+
const line = firstLines(text, Infinity);
|
|
25
|
+
|
|
26
|
+
return line.length > LOG_MAX
|
|
27
|
+
? `${line.slice(0, LOG_MAX)}… (${line.length - LOG_MAX} more characters)`
|
|
28
|
+
: line;
|
|
29
|
+
};
|
|
30
|
+
const LOG_MAX = 8000;
|
|
31
|
+
|
|
18
32
|
/** The first `n` non-empty lines of a text, trimmed, on one line. */
|
|
19
33
|
const firstLines = (text, n) =>
|
|
20
34
|
String(text)
|
|
@@ -30,7 +44,7 @@ const TELLING = ['file_path', 'command', 'pattern', 'url', 'description'];
|
|
|
30
44
|
function toolLine(use) {
|
|
31
45
|
const key = TELLING.find((k) => typeof use.input?.[k] === 'string');
|
|
32
46
|
|
|
33
|
-
return key ? `tool: ${use.name} ${
|
|
47
|
+
return key ? `tool: ${use.name} ${whole(use.input[key])}` : `tool: ${use.name}`;
|
|
34
48
|
}
|
|
35
49
|
|
|
36
50
|
/** A tool result's text: a string, or a list of text blocks. */
|
|
@@ -115,7 +129,7 @@ function limitIn(text, whole = true) {
|
|
|
115
129
|
* @returns {{lines: string[], events: Neutral[], cost?: Cost, session_id?: string,
|
|
116
130
|
* limit?: {resets: string | null},
|
|
117
131
|
* context?: number, turn?: string, model?: string, windows?: Record<string, number>,
|
|
118
|
-
* compacted?: boolean, failed?: string[], quota?: Record<string, unknown
|
|
132
|
+
* compacted?: boolean, failed?: string[], quota?: Record<string, unknown>, errored?: boolean}}
|
|
119
133
|
*/
|
|
120
134
|
export function activity(line, now = new Date()) {
|
|
121
135
|
let e;
|
|
@@ -140,9 +154,7 @@ function logged(e, now) {
|
|
|
140
154
|
const errors = content.filter((b) => b.type === 'tool_result' && b.is_error);
|
|
141
155
|
|
|
142
156
|
return {
|
|
143
|
-
lines: errors.map(
|
|
144
|
-
(b) => `${at} tool error: ${cut(firstLines(resultText(b.content), 1), 300)}`,
|
|
145
|
-
),
|
|
157
|
+
lines: errors.map((b) => `${at} tool error: ${whole(resultText(b.content))}`),
|
|
146
158
|
// A refused or failed call wrote nothing: its write does not count.
|
|
147
159
|
...(errors.length ? { failed: errors.map((b) => String(b.tool_use_id)) } : {}),
|
|
148
160
|
};
|
|
@@ -178,13 +190,14 @@ export const kindOf = (tool) => KINDS[tool] ?? (/^mcp__/.test(tool) ? 'mcp' : 'o
|
|
|
178
190
|
|
|
179
191
|
/**
|
|
180
192
|
* @typedef {{type: 'said', sub: boolean, text: string}
|
|
181
|
-
* | {type: 'tool_call', sub: boolean, id: string, kind: string, tool: string, input: any
|
|
193
|
+
* | {type: 'tool_call', sub: boolean, id: string, kind: string, tool: string, input: any,
|
|
194
|
+
* title: string}
|
|
182
195
|
* | {type: 'tool_result', sub: boolean, id: string, error: boolean, text: string}
|
|
183
196
|
* | {type: 'read'}
|
|
184
197
|
* | {type: 'question', request_id: string, input: any}
|
|
185
198
|
* | {type: 'permission', request_id: string, tool: string, kind: string, input: any,
|
|
186
199
|
* title: string, reason: string | null, always: string | null}
|
|
187
|
-
* | {type: 'refused', tool: string, reason: string}
|
|
200
|
+
* | {type: 'refused', id: string, tool: string, reason: string}
|
|
188
201
|
* | {type: 'cancel', request_id: string}
|
|
189
202
|
* | {type: 'result', subtype?: string, total_cost_usd: number | null}
|
|
190
203
|
* | {type: 'background', tasks: {id: string, description: string}[]}
|
|
@@ -211,6 +224,7 @@ function eventsOf(e) {
|
|
|
211
224
|
kind: kindOf(b.name),
|
|
212
225
|
tool: String(b.name),
|
|
213
226
|
input: b.input ?? {},
|
|
227
|
+
title: titleOf(String(b.name), b.input ?? {}),
|
|
214
228
|
})),
|
|
215
229
|
{ type: 'said', sub, text: text.join('\n') },
|
|
216
230
|
];
|
|
@@ -225,6 +239,12 @@ function eventsOf(e) {
|
|
|
225
239
|
return e.type === 'system' ? systemEvents(e) : [];
|
|
226
240
|
}
|
|
227
241
|
|
|
242
|
+
/** What a call is about, as a card names it: its file, command, address or pattern; its tool. */
|
|
243
|
+
const titleOf = (tool, input) =>
|
|
244
|
+
String(
|
|
245
|
+
input.file_path ?? input.notebook_path ?? input.command ?? input.url ?? input.pattern ?? tool,
|
|
246
|
+
);
|
|
247
|
+
|
|
228
248
|
/** A user event: a message echoed as read (`--replay-user-messages`), or tool results. */
|
|
229
249
|
function userEvents(e, sub, content) {
|
|
230
250
|
if (e.isReplay) return [{ type: /** @type {const} */ ('read') }];
|
|
@@ -248,8 +268,6 @@ function requested(e) {
|
|
|
248
268
|
if (e.request?.subtype !== 'can_use_tool') return [];
|
|
249
269
|
const { tool_name: tool, input = {} } = e.request;
|
|
250
270
|
if (tool === 'AskUserQuestion') return [{ type: 'question', request_id: e.request_id, input }];
|
|
251
|
-
const title =
|
|
252
|
-
input.file_path ?? input.notebook_path ?? input.command ?? input.url ?? input.pattern ?? tool;
|
|
253
271
|
|
|
254
272
|
return [
|
|
255
273
|
{
|
|
@@ -258,7 +276,7 @@ function requested(e) {
|
|
|
258
276
|
tool,
|
|
259
277
|
kind: kindOf(tool),
|
|
260
278
|
input,
|
|
261
|
-
title:
|
|
279
|
+
title: titleOf(tool, input),
|
|
262
280
|
reason: typeof e.request.description === 'string' ? e.request.description : null,
|
|
263
281
|
...alwaysOf(e.request.permission_suggestions),
|
|
264
282
|
},
|
|
@@ -293,7 +311,14 @@ function systemEvents(e) {
|
|
|
293
311
|
if (e.subtype === 'compact_boundary') return [{ type: 'compacted' }];
|
|
294
312
|
// A deny rule of the settings refused a call (spike 8).
|
|
295
313
|
if (e.subtype === 'permission_denied')
|
|
296
|
-
return [
|
|
314
|
+
return [
|
|
315
|
+
{
|
|
316
|
+
type: 'refused',
|
|
317
|
+
id: String(e.tool_use_id ?? ''),
|
|
318
|
+
tool: String(e.tool_name ?? ''),
|
|
319
|
+
reason: String(e.message ?? ''),
|
|
320
|
+
},
|
|
321
|
+
];
|
|
297
322
|
if (e.subtype !== 'background_tasks_changed') return [];
|
|
298
323
|
const tasks = (Array.isArray(e.tasks) ? e.tasks : []).map((t) => ({
|
|
299
324
|
id: String(t.task_id ?? t.id ?? ''),
|
|
@@ -317,6 +342,11 @@ const quotaOf = (e) =>
|
|
|
317
342
|
* agent's context summarized; the rest (hooks, thinking) give nothing.
|
|
318
343
|
*/
|
|
319
344
|
function system(e, at) {
|
|
345
|
+
// A deny rule of the settings refused a call: a line of its own, not one tool error among many.
|
|
346
|
+
if (e.subtype === 'permission_denied')
|
|
347
|
+
return {
|
|
348
|
+
lines: [`${at} denied: ${[e.tool_name, whole(e.message ?? '')].filter(Boolean).join(' ')}`],
|
|
349
|
+
};
|
|
320
350
|
if (e.subtype === 'compact_boundary')
|
|
321
351
|
return { lines: [`${at} compacted: the agent's context was summarized`], compacted: true };
|
|
322
352
|
if (e.subtype !== 'init' || typeof e.session_id !== 'string') return { lines: [] };
|
|
@@ -372,6 +402,7 @@ function ended(e, at) {
|
|
|
372
402
|
lines: [...text, `${at} ${summary(e, cost, Boolean(limit.limit))}`],
|
|
373
403
|
// The reply itself: a lessons turn answers with its JSON here.
|
|
374
404
|
...(typeof e.result === 'string' ? { result: e.result } : {}),
|
|
405
|
+
...(e.is_error ? { errored: true } : {}),
|
|
375
406
|
cost,
|
|
376
407
|
...limit,
|
|
377
408
|
...(windows.length ? { windows: Object.fromEntries(windows) } : {}),
|
|
@@ -13,11 +13,87 @@ import {
|
|
|
13
13
|
readSync,
|
|
14
14
|
statSync,
|
|
15
15
|
} from 'node:fs';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
16
17
|
import path from 'node:path';
|
|
17
18
|
import { CHAT_FLAGS, encode as claudeInput } from './adapter/claude.js';
|
|
18
19
|
|
|
19
20
|
export { CHAT_FLAGS };
|
|
20
21
|
|
|
22
|
+
// The kinds whose pattern is a path glob (AD-4).
|
|
23
|
+
const FILE_KINDS = new Set(['read', 'search', 'edit']);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a neutral rule `{kind, pattern}` holds for a call (`{kind, tool, title}`): its kind,
|
|
27
|
+
* its glob on the title; a shell rule on each command of a chain too (`cd x && git push` is a
|
|
28
|
+
* `git *`), claude's old `cmd:*` as `cmd*`; a path rule on the path's end, as a project glob
|
|
29
|
+
* holds for the absolute path a call names (`.claude/**`, `~/.ssh/**`); an MCP rule on the tool.
|
|
30
|
+
* shortcut: claude's own matcher refuses or asks; this one names the rule, and may miss a form
|
|
31
|
+
* claude reads otherwise (`other` rules, web domains): the refusal then names none.
|
|
32
|
+
*/
|
|
33
|
+
export function ruleHolds(rule, e) {
|
|
34
|
+
if (rule.kind !== e.kind) return false;
|
|
35
|
+
if (!rule.pattern) return true;
|
|
36
|
+
// A server's rule (`unity`) holds for each of its tools, as claude's `mcp__unity` does.
|
|
37
|
+
if (rule.kind === 'mcp')
|
|
38
|
+
return e.tool === `mcp__${rule.pattern}` || e.tool.startsWith(`mcp__${rule.pattern}__`);
|
|
39
|
+
const slash = (p) => p.replaceAll('\\', '/');
|
|
40
|
+
const esc = (p) => p.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
|
|
41
|
+
const title = String(e.title ?? '');
|
|
42
|
+
if (FILE_KINDS.has(rule.kind)) {
|
|
43
|
+
const pattern = slash(rule.pattern.replace(/^~(?=\/)/, homedir()));
|
|
44
|
+
// A path glob: `**/` is any folders, none too; `**` anything; `*` within one folder.
|
|
45
|
+
const glob = pattern
|
|
46
|
+
.split(/(\*\*\/|\*\*|\*)/)
|
|
47
|
+
.map((t) => PATH_GLOB[t] ?? esc(t))
|
|
48
|
+
.join('');
|
|
49
|
+
const re = new RegExp(`(?:^|/)${glob}$`, process.platform === 'win32' ? 'i' : '');
|
|
50
|
+
|
|
51
|
+
return re.test(slash(title));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const re = new RegExp(`^${esc(rule.pattern.replace(/:\*$/, '*')).replaceAll('*', '.*')}$`);
|
|
55
|
+
const parts = rule.kind === 'shell' ? commandsOf(title) : [];
|
|
56
|
+
|
|
57
|
+
return [title, ...parts].some((x) => re.test(x.trim()));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const PATH_GLOB = { '**/': '(?:.*/)?', '**': '.*', '*': '[^/]*' };
|
|
61
|
+
|
|
62
|
+
// How much of a refused call the chat keeps: its command or file, and what it was for.
|
|
63
|
+
const TITLE_MAX = 2000;
|
|
64
|
+
const WHY_MAX = 500;
|
|
65
|
+
const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}…` : s);
|
|
66
|
+
|
|
67
|
+
// A shell line's pieces: a quoted string whole (an unclosed one to the end), a separator, a run
|
|
68
|
+
// of plain characters.
|
|
69
|
+
const SHELL_PIECE = /'[^']*'?|"(?:\\.|[^"\\])*"?|&&|\|\||[;|\n]|[^'";|&\n]+|&/g;
|
|
70
|
+
const SEPARATOR = new Set(['&&', '||', ';', '|', '\n']);
|
|
71
|
+
|
|
72
|
+
/** The commands of a shell chain, split on `&&`, `||`, `;`, `|` and new lines outside quotes. */
|
|
73
|
+
function commandsOf(line) {
|
|
74
|
+
const parts = [''];
|
|
75
|
+
for (const [piece] of line.matchAll(SHELL_PIECE))
|
|
76
|
+
if (SEPARATOR.has(piece)) parts.push('');
|
|
77
|
+
else parts[parts.length - 1] += piece;
|
|
78
|
+
|
|
79
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* What refused a call (`deny`, the rules the session runs by): the rule only when one alone
|
|
84
|
+
* holds, its group when every rule that holds is of it.
|
|
85
|
+
*/
|
|
86
|
+
function refusedBy(deny, call) {
|
|
87
|
+
const held = deny.filter((r) => ruleHolds(r, call));
|
|
88
|
+
const group = held[0]?.group;
|
|
89
|
+
const rule = held.length === 1 ? held[0] : null;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
...(rule ? { rule: rule.pattern ? `${rule.kind}: ${rule.pattern}` : rule.kind } : {}),
|
|
93
|
+
...(group && held.every((r) => r.group === group) ? { group } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
21
97
|
/** How long a question waits for the operator when neither the flag nor the config says. */
|
|
22
98
|
export const CHAT_TIMEOUT_MIN = 15;
|
|
23
99
|
|
|
@@ -658,20 +734,31 @@ const SEEN = {
|
|
|
658
734
|
},
|
|
659
735
|
question: asked,
|
|
660
736
|
permission: permit,
|
|
661
|
-
// A deny rule of the settings refused it: no card was ever due.
|
|
662
|
-
|
|
737
|
+
// A deny rule of the settings refused it: no card was ever due. The refused call says what
|
|
738
|
+
// was asked (`title`) and what for (`description`), not its whole input: a write's content
|
|
739
|
+
// stays out of the chat. The session's rule that holds for it, and the rule's group, say what
|
|
740
|
+
// refused it (refusedBy).
|
|
741
|
+
refused: (c, e) => {
|
|
742
|
+
const call = c.calls.get(e.id);
|
|
743
|
+
const why = typeof call?.input?.description === 'string' ? call.input.description : '';
|
|
663
744
|
post(c, {
|
|
664
745
|
type: 'denied',
|
|
665
746
|
tool: e.tool,
|
|
666
747
|
by: 'rule',
|
|
748
|
+
...(call ? { title: cut(call.title, TITLE_MAX), ...refusedBy(c.deny, call) } : {}),
|
|
749
|
+
...(why ? { description: cut(why, WHY_MAX) } : {}),
|
|
667
750
|
...(e.reason ? { reason: e.reason } : {}),
|
|
668
|
-
})
|
|
669
|
-
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
// A proposal (AD-12): the call of the center's MCP tool, posted when it succeeded. Each call
|
|
754
|
+
// is kept until its result: a refusal names it by its id.
|
|
670
755
|
tool_call: (c, e) => {
|
|
756
|
+
c.calls.set(e.id, e);
|
|
671
757
|
const m = /^mcp__gcf__propose_(\w+)$/.exec(e.tool);
|
|
672
758
|
if (!e.sub && m) c.proposals.set(e.id, { move: m[1].replaceAll('_', '-'), fields: e.input });
|
|
673
759
|
},
|
|
674
760
|
tool_result: (c, e) => {
|
|
761
|
+
c.calls.delete(e.id);
|
|
675
762
|
const p = c.proposals.get(e.id);
|
|
676
763
|
if (!p) return;
|
|
677
764
|
c.proposals.delete(e.id);
|
|
@@ -716,7 +803,8 @@ function see(c, events) {
|
|
|
716
803
|
* (`{context, context_pct}`); `pause(on)` stops the session's timeout while it waits for the
|
|
717
804
|
* operator; `prompt` is the first message; `kind` how the session started (`start`, `resume`,
|
|
718
805
|
* `handoff`); `pick` the model and effort a project chat's session was started with;
|
|
719
|
-
* `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says
|
|
806
|
+
* `steps.see(e)` the steps an event ends; `defaultAnswer` what silence says; `deny` the neutral
|
|
807
|
+
* deny rules the session runs by (each with its `group`, if any): a refusal names its rule.
|
|
720
808
|
* `see(events)` takes the neutral events of each line the agent prints; `event(e)` posts one
|
|
721
809
|
* the run saw; `encode` writes its input as the agent reads it;
|
|
722
810
|
* `close(code, seen)` stops reading and posts the session's end.
|
|
@@ -773,6 +861,7 @@ const CHAT_DEFAULTS = {
|
|
|
773
861
|
approvals: false,
|
|
774
862
|
gate: () => null,
|
|
775
863
|
asks: () => false,
|
|
864
|
+
deny: [],
|
|
776
865
|
saveAlways: async () => {},
|
|
777
866
|
handover: null,
|
|
778
867
|
prefix: null,
|
|
@@ -793,7 +882,8 @@ function chatState(opts) {
|
|
|
793
882
|
fresh: o.fresh ?? o.kind === 'handoff',
|
|
794
883
|
...{ sent: 0, read: 0, cards: new Map(), wait: null, defaulted: false, closed: false },
|
|
795
884
|
...{ stopped: false, grace: null, idle: false, inTurn: true, tasks: [] },
|
|
796
|
-
...{ proposals: new Map(), heard: false, summary: null, wanted: null
|
|
885
|
+
...{ proposals: new Map(), calls: new Map(), heard: false, summary: null, wanted: null },
|
|
886
|
+
why: null,
|
|
797
887
|
...{ hold: false, late: false, pending: [], echoes: [] },
|
|
798
888
|
};
|
|
799
889
|
}
|
|
@@ -258,7 +258,8 @@ async function after(j, ran, base) {
|
|
|
258
258
|
prompt,
|
|
259
259
|
resume: ran.session_id,
|
|
260
260
|
timeoutMs,
|
|
261
|
-
// One reply, past the work: no handoff watch, no quota, no chat.
|
|
261
|
+
// One reply, past the work: no handoff watch, no quota, no chat; the policy logs the reply.
|
|
262
|
+
ownReply: true,
|
|
262
263
|
handoff: null,
|
|
263
264
|
quota: null,
|
|
264
265
|
chat: null,
|
|
@@ -17,6 +17,13 @@ const HALT_POLL_MS = 1000;
|
|
|
17
17
|
/**
|
|
18
18
|
* Keep what a session's activity told: the last of each, and the model's window from the result.
|
|
19
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* A log line of the reply a caller reads (`ownReply`): the agent's words and the result's text,
|
|
22
|
+
* but an error's: it is why the turn gave no reply.
|
|
23
|
+
*/
|
|
24
|
+
const replyLine = (l, a) =>
|
|
25
|
+
/^\[[\d:]+\] agent: /.test(l) || (!a.errored && a.result && l.endsWith(`result:\n${a.result}`));
|
|
26
|
+
|
|
20
27
|
function absorb(seen, a) {
|
|
21
28
|
seen.cost = a.cost ?? seen.cost;
|
|
22
29
|
seen.result = a.result ?? seen.result;
|
|
@@ -234,6 +241,8 @@ function sessionTimeout(ms, onTimeout, onHalt) {
|
|
|
234
241
|
* @property {any} [chat] the chat's options (chat.js `openChat`)
|
|
235
242
|
* @property {() => boolean} [halt] the operator stopped the work: the session ends at once
|
|
236
243
|
* @property {((events: import('./activity.js').Neutral[]) => void) | null} [observe]
|
|
244
|
+
* @property {boolean} [ownReply] the caller reads the reply and logs what it made of it: the log
|
|
245
|
+
* does not get the reply's text (a lessons turn's JSON)
|
|
237
246
|
*/
|
|
238
247
|
|
|
239
248
|
/**
|
|
@@ -258,7 +267,7 @@ function sessionTimeout(ms, onTimeout, onHalt) {
|
|
|
258
267
|
* handedOver: boolean, model?: string, window?: number, result?: string, waited: number}>}
|
|
259
268
|
*/
|
|
260
269
|
export function runSession(s) {
|
|
261
|
-
const { adapter, fd, timeoutMs, id, onSpawn, handoff, quota, chat, observe, halt } = s;
|
|
270
|
+
const { adapter, fd, timeoutMs, id, onSpawn, handoff, quota, chat, observe, halt, ownReply } = s;
|
|
262
271
|
|
|
263
272
|
return new Promise((resolve) => {
|
|
264
273
|
const child = launchSession(s);
|
|
@@ -301,7 +310,7 @@ export function runSession(s) {
|
|
|
301
310
|
if (talk && open) talk.see(a.events);
|
|
302
311
|
if (a.quota && quota) keepQuota(quota, a.quota);
|
|
303
312
|
observe?.(a.events);
|
|
304
|
-
write(a.lines);
|
|
313
|
+
write(ownReply ? a.lines.filter((l) => !replyLine(l, a)) : a.lines);
|
|
305
314
|
if (open && a.context !== undefined) shown?.(a.context, seen.model);
|
|
306
315
|
if (open) watch.see(a, seen.model);
|
|
307
316
|
});
|
|
@@ -21,7 +21,7 @@ import { createHash } from 'node:crypto';
|
|
|
21
21
|
import { PICKS } from './adapter/claude.js';
|
|
22
22
|
import { adapterFor } from './adapter/index.js';
|
|
23
23
|
import { runJob } from './job.js';
|
|
24
|
-
import { postTo, readFrom } from './chat.js';
|
|
24
|
+
import { postTo, readFrom, ruleHolds } from './chat.js';
|
|
25
25
|
import { realClock } from './limit.js';
|
|
26
26
|
import { alive } from './proc.js';
|
|
27
27
|
import { chatsDir, runsDir, writeAtomic } from './store.js';
|
|
@@ -270,21 +270,6 @@ export function listThreads(dir) {
|
|
|
270
270
|
.sort((a, b) => String(b.created_at).localeCompare(String(a.created_at)));
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
/**
|
|
274
|
-
* Whether a neutral rule `{kind, pattern}` holds for a call: its kind, its glob on the title; a
|
|
275
|
-
* shell rule on each command of a chain too (`cd x && git push` is a `git *`).
|
|
276
|
-
*/
|
|
277
|
-
function ruleHolds(rule, e) {
|
|
278
|
-
if (rule.kind !== e.kind) return false;
|
|
279
|
-
if (!rule.pattern) return true;
|
|
280
|
-
const glob = rule.pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replaceAll('*', '.*');
|
|
281
|
-
const re = new RegExp(`^${glob}$`);
|
|
282
|
-
const title = String(e.title ?? '');
|
|
283
|
-
const parts = e.kind === 'shell' ? title.split(/\s*(?:&&|\|\||[;|\n])\s*/) : [];
|
|
284
|
-
|
|
285
|
-
return [title, ...parts].some((x) => re.test(x.trim()));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
273
|
/** Whether the main run's lock (`runs/<main>.lock`) names a live process. */
|
|
289
274
|
function mainBusy(file) {
|
|
290
275
|
if (!file) return false;
|
|
@@ -555,6 +540,7 @@ function chatOf(s, kind, prev) {
|
|
|
555
540
|
approvals: true,
|
|
556
541
|
gate: gateOf(spec),
|
|
557
542
|
asks: (e) => (spec.rules?.ask ?? []).some((r) => ruleHolds(r, e)),
|
|
543
|
+
deny: spec.rules?.deny ?? [],
|
|
558
544
|
saveAlways: (rule) => s.adapter.saveAlways(dir, rule),
|
|
559
545
|
handover: handoverOf(s),
|
|
560
546
|
summary: kind === 'handoff' ? s.summary : null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
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",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-harness-aif-ext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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.
|
|
31
|
+
"gcf-aif-ext": "^0.19.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"gcf-session": "file:../gcf-session"
|
package/skills/gcf-run/SKILL.md
CHANGED
|
@@ -19,13 +19,22 @@ inputs:
|
|
|
19
19
|
- `--handoff` when the harness started this session after the last one filled its context: the plan's `## Handoff` says where it stopped
|
|
20
20
|
- `--no-lessons` when the harness asks this session's lessons itself, in a turn after it ends
|
|
21
21
|
- `--ask d1` or `--ask all` when the harness opened this session to the operator's chat: what to ask them with the AskUserQuestion tool; without it ask no one that way
|
|
22
|
+
- `--assume` when the project's or the card's gates say `question: assume`: a question goes as your assumption, not to the human
|
|
23
|
+
- `--decide` when they say `decision: agent`: you decide your spike or decision item go or no
|
|
22
24
|
|
|
23
25
|
preconditions:
|
|
24
26
|
- `gcf/` exists and `ai-factory gcf audit` runs (the gcf-aif-ext extension provides it)
|
|
25
27
|
- the agent is Claude Code: this pipeline needs its subagents and the harness hooks; another agent drives the item with aif-plan and aif-implement instead
|
|
26
28
|
|
|
27
29
|
forbidden_behaviors:
|
|
28
|
-
- do not give a verdict
|
|
30
|
+
- do not give a verdict: `verdict` belongs to the human; a decision too, but under `--decide`: then only `go` or `no` of the item you drive, a spike or a decision item, with `--reason`
|
|
31
|
+
- under `--assume`, a question of step 12 that is not one of its four goes as an assumption: take your safe default, write it into the plan, and pass `--assume "<question> = <value>"` on the item's move; the core files it as a D2 in the move's commit
|
|
32
|
+
- do not assume a save format, a public API, a new dependency or a pillar conflict: those stay the human's question of step 12
|
|
33
|
+
- under `--decide`, after the submit of a spike or a decision item, run `ai-factory gcf decide <id> go|no --reason "<why>"`
|
|
34
|
+
- `--unticked "<why>"` only for a task the work made moot: its reason goes into the commit
|
|
35
|
+
- with `--worktree`, a `--decide` decision and each `--assume` assumption go into the plan under `## Outcome` before the commit of step 24
|
|
36
|
+
- its lines: `- decide: go|no`, `- reason: <why>`, one `- assume: <question> = <value>` each; the harness records them on main in the item's move
|
|
37
|
+
- a plan that already holds a `## Outcome` from an earlier run gets this run's in its place, not a second one
|
|
29
38
|
- do not read a `gcf/` file outside the readset from `ai-factory gcf context`, but `gcf/INDEX.md` and `gcf/config.yml`
|
|
30
39
|
- do not continue past a failed gate: report the one-line reason, delete `.gcf-session/readset.json`, and stop - a stop is a normal outcome
|
|
31
40
|
- do not compare the audit numbers yourself: the gate command is the only judge of whether an item may go
|
|
@@ -56,9 +65,11 @@ forbidden_behaviors:
|
|
|
56
65
|
- a call the handoff guard denies with "context at" is no refusal: block nothing, write the `## Handoff` it asks for and end the reply
|
|
57
66
|
- a read the readset guard denies is no refusal either: drop that read; never add a `system:` or `depends:` only to read a file - when one of them is wrong in substance, fix it on main, and under `--worktree` stop with a block that names the fix
|
|
58
67
|
- the context's `graveyard_hits` and `d2` lines belong to the readset: hand them to every fresh subagent of steps 8 and 14 in its prompt
|
|
59
|
-
- a design question of step 12 also gets a D1 record
|
|
68
|
+
- a design question of step 12 also gets a D1 record: `ai-factory gcf question add --class D1 --question "<question>" --proposed "<your answer>" --blocks <id>`, before the block
|
|
60
69
|
- under `--worktree` that question goes into the block reason only, and the human files its D1 on main
|
|
61
70
|
- delete one file with `rm -f <file>` or `Remove-Item -Force <file>`, never with `-r`: the deny rules refuse a recursive delete
|
|
71
|
+
- do not run `git stash`: its stack is the checkout's and every worktree's, and a pop may take the human's work
|
|
72
|
+
- for a clean tree to build or check in, run `git worktree add --detach <tmp> HEAD` and work there
|
|
62
73
|
- write the `live:` delta as `live: {none: "<why>"}`, or as `changes:`, each `{id: <capability slug>, change: added | modified | removed, summary: "<two sentences at most>"}`
|
|
63
74
|
- do not leave a done plan task unticked: `submit` and `close` refuse a plan with unticked tasks, as they refuse code changed since its green verify
|
|
64
75
|
|
|
@@ -79,9 +90,9 @@ workflow:
|
|
|
79
90
|
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
|
|
80
91
|
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
|
|
81
92
|
16. after a review fix, run `ai-factory gcf verify <id>` again (a red run counts against `dod_attempts`); tick the plan tasks done outside aif-implement, the verify and the review; then commit the code, its plan and the `live:` delta via aif-commit
|
|
82
|
-
17. gate `verdict` or `decision`: run `ai-factory gcf submit <id>`; gate `auto`:
|
|
93
|
+
17. gate `verdict` or `decision`: run `ai-factory gcf submit <id>`; gate `auto`: `ai-factory gcf close <id>` - a soft unit closes unplayed; the core defers what the gates defer; never pass `--unverified`, the human's call
|
|
83
94
|
18. a dependency still waiting for its verdict refuses the close: run `ai-factory gcf block <id> --reason "waits for <dep>"`
|
|
84
|
-
19. close the run: delete `.gcf-session/readset.json
|
|
95
|
+
19. close the run: delete `.gcf-session/readset.json`; report a row per plan pass: pass, blocking, polish, result; hand the human `ai-factory gcf playtest session` when the audit's `play_milestone` is set or an item waits for its verdict
|
|
85
96
|
20. after a tune verdict or an unblock, re-enter this pipeline at step 5: the gates re-run because the counters moved
|
|
86
97
|
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
98
|
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
|