gcf-aif-ext 0.31.0 → 0.34.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 +30 -3
- package/commands/gcf.js +89 -38
- package/extension.json +1 -1
- package/injections/plan-context.md +3 -0
- package/lib/audit-core.js +96 -134
- package/lib/board.js +29 -13
- package/lib/commit-files.js +1 -0
- package/lib/commit-move.js +1 -0
- package/lib/config-set.js +1 -1
- package/lib/context.js +29 -16
- package/lib/d2-states.js +208 -0
- package/lib/design-parts.js +37 -7
- package/lib/domain.js +6 -1
- package/lib/gcf-paths.js +32 -4
- package/lib/git.js +26 -5
- package/lib/integrate.js +58 -1
- package/lib/main-lock.js +195 -3
- package/lib/plan-check.js +34 -12
- package/lib/play.js +24 -22
- package/lib/review.js +5 -3
- package/lib/session-mark.js +2 -1
- package/lib/systems-doc.js +60 -13
- package/lib/work-ops.js +3 -2
- package/package.json +1 -1
- package/skills/gcf-audit/SKILL.md +10 -5
- package/skills/gcf-card/SKILL.md +12 -10
- package/skills/gcf-verdict/SKILL.md +7 -5
- package/templates/agents-block.md +11 -1
- package/templates/config.yml +9 -4
package/lib/d2-states.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// The state and age of each record of gcf/open-questions.md, and whether an until trigger fired
|
|
2
|
+
// (GCF-PRD §7.3, §7.4): the audit, the board and the readset read them alike. It imports no
|
|
3
|
+
// work-ops.js: context.js reads it, and audit-core → work-ops → plan-check → context is a cycle.
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { fieldOf } from './question-fields.js';
|
|
9
|
+
|
|
10
|
+
export function git(args, cwd) {
|
|
11
|
+
// A blame of a long file overflows the 1 MiB default, and an overflow reads as a git failure.
|
|
12
|
+
const res = spawnSync('git', args, {
|
|
13
|
+
windowsHide: true,
|
|
14
|
+
cwd,
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return res.status === 0 ? res.stdout.trim() : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const UNTIL_RE =
|
|
23
|
+
/\[until:\s*(verdict\([a-z0-9-]+\)|retune\([a-z0-9-]+\)|manual\([^)]*\))\]/g;
|
|
24
|
+
const D2_UNTIL_RE = /^(verdict\([a-z0-9-]+\)|retune\([a-z0-9-]+\)|manual\([^)]*\))/;
|
|
25
|
+
// The two markers GCF writes itself (systems-doc.js purposeLines, gcf-adopt): no human's manual().
|
|
26
|
+
export const PLACEHOLDER_RE = /\[until:\s*manual\((?:purpose of|first verdict touching) [^)]+\)\]/;
|
|
27
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
+
// An uncommitted line blames to the all-zero hash: it is new, not old.
|
|
29
|
+
const isUncommitted = (hash) => /^0+$/.test(hash);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Each line of `rel` with the commit that last changed it beyond whitespace (-w: a respaced or
|
|
33
|
+
* re-ended CRLF/LF line keeps the commit that wrote it), or null for an untracked file or
|
|
34
|
+
* outside a repository.
|
|
35
|
+
*/
|
|
36
|
+
export function blameLines(projectDir, rel) {
|
|
37
|
+
const blame = git(['blame', '-w', '--porcelain', '--', rel], projectDir);
|
|
38
|
+
if (blame === null) return null;
|
|
39
|
+
const lines = [];
|
|
40
|
+
let hash = '';
|
|
41
|
+
for (const line of blame.split('\n')) {
|
|
42
|
+
const head = line.match(/^([0-9a-f]{40,64}) \d+ \d+/);
|
|
43
|
+
if (head) hash = head[1];
|
|
44
|
+
else if (line.startsWith('\t')) lines.push({ hash, text: line.slice(1).replace(/\r$/, '') });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Commits since `hash`, memoized; null when the ref no longer resolves. */
|
|
51
|
+
function commitsSince(projectDir) {
|
|
52
|
+
const ages = new Map();
|
|
53
|
+
|
|
54
|
+
return (hash) => {
|
|
55
|
+
if (!ages.has(hash)) {
|
|
56
|
+
const raw = git(['rev-list', '--count', `${hash}..HEAD`], projectDir);
|
|
57
|
+
// Number(null) is 0, "fresh" — the one answer that must never be guessed.
|
|
58
|
+
ages.set(hash, raw === null ? null : Number(raw));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return ages.get(hash);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether a verdict fired. `verdict(id)` reads the files, as the ledger does (GCF-PRD §5.8): a
|
|
67
|
+
* keep or kill left a history or graveyard line, a tune left the item's tune_count. `retune(sys,
|
|
68
|
+
* birth)` reads the tune verdicts' subjects after `birth`, the commit that wrote the record: a
|
|
69
|
+
* tune before it is the one the record already knows. An uncommitted record is new, so open.
|
|
70
|
+
* With no birth (no blame: no repository, an untracked file) it guesses as before: an item of
|
|
71
|
+
* the subsystem with a tune_count, or any tune in the log.
|
|
72
|
+
*/
|
|
73
|
+
export function verdictMatchers(projectDir, ledger, items) {
|
|
74
|
+
const tuned = items.filter((c) => (c.data.tune_count ?? 0) > 0);
|
|
75
|
+
const logs = new Map();
|
|
76
|
+
const verdictLog = (birth) => {
|
|
77
|
+
if (!logs.has(birth)) {
|
|
78
|
+
const range = birth ? [`${birth}..HEAD`] : [];
|
|
79
|
+
const args = ['log', '--basic-regexp', '--grep', '^gcf(verdict):', '--format=%s', ...range];
|
|
80
|
+
logs.set(birth, git(args, projectDir) ?? '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return logs.get(birth);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// `tune <id> → <sys>,<sys>` and maybe ` (played on: …)` (work-ops.js verdictItemUnlocked).
|
|
87
|
+
const tuneOf = (system) =>
|
|
88
|
+
new RegExp(`^gcf\\(verdict\\): tune .*→ (?:\\S*,)?${escapeRe(system)}(?:,| \\(|$)`, 'm');
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
verdict: (id) =>
|
|
92
|
+
ledger.where(id).terminal.some((t) => t !== 'done') || tuned.some((c) => c.data.id === id),
|
|
93
|
+
/** @param {string} system @param {string} [birth] */
|
|
94
|
+
retune: (system, birth) => {
|
|
95
|
+
if (birth) return !isUncommitted(birth) && tuneOf(system).test(verdictLog(birth));
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
tuned.some((c) => (c.data.system ?? []).includes(system)) ||
|
|
99
|
+
tuneOf(system).test(verdictLog(birth))
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A question as the board and its Design screen show it: an unanswered D2 whose trigger fired
|
|
107
|
+
* (`fired`), or of `manual(...)` or no trigger past the age limit (`aged`, `commits` its age), is
|
|
108
|
+
* the Operator's decision now (Until-Records-Plan d3). An agent writes every question record:
|
|
109
|
+
* its origin is one.
|
|
110
|
+
*/
|
|
111
|
+
export function questionRow(q, state) {
|
|
112
|
+
const fired = state?.status === 'stale';
|
|
113
|
+
const aged = Boolean(state?.d2 && state.aged);
|
|
114
|
+
const decision = /^D1\b/.test(q.class ?? '') || fired || aged;
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...q,
|
|
118
|
+
category: decision ? 'decision' : 'assumption',
|
|
119
|
+
origin: 'agent',
|
|
120
|
+
fired,
|
|
121
|
+
aged,
|
|
122
|
+
...(aged && { commits: state.commits }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `stale` (fired), `open` or `manual`; `birth` as for retune. */
|
|
127
|
+
export function untilStatus(trigger, fired, birth) {
|
|
128
|
+
if (trigger.startsWith('verdict(')) {
|
|
129
|
+
return fired.verdict(trigger.slice(8, -1)) ? 'stale' : 'open';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (trigger.startsWith('retune(')) {
|
|
133
|
+
return fired.retune(trigger.slice(7, -1), birth) ? 'stale' : 'open';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return 'manual';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Every record of open-questions.md with its state: `trigger` a D2's until (null for a D1 or
|
|
141
|
+
* none); `status` a D2's `answered`, `stale`, `open` or `manual` (null for a D1 or no trigger);
|
|
142
|
+
* `commits` since the commit that wrote its `- id:` line (undefined with no such commit: an
|
|
143
|
+
* uncommitted record, no blame; null when that commit no longer resolves); `aged` an unanswered
|
|
144
|
+
* record the human owes past `limit` commits — a D1, or a D2 with `manual(...)` or no trigger
|
|
145
|
+
* (GCF-PRD §7.4): an acting D2 waits for its trigger, a fired one is a stale until record.
|
|
146
|
+
* shortcut: a blame, a git log and a rev-list per call, the board's included; cache by HEAD
|
|
147
|
+
* when the board's refresh feels it.
|
|
148
|
+
*/
|
|
149
|
+
export async function d2States(projectDir, { fired, limit }) {
|
|
150
|
+
const file = path.join(path.resolve(projectDir), 'gcf', 'open-questions.md');
|
|
151
|
+
if (!existsSync(file)) return [];
|
|
152
|
+
const text = noBom(await readFile(file, 'utf8')).replace(/\r\n/g, '\n');
|
|
153
|
+
const at = { fired, limit, births: birthsOf(projectDir), since: commitsSince(projectDir) };
|
|
154
|
+
|
|
155
|
+
return text.split(/\n(?=- id:)/).flatMap((rec) => {
|
|
156
|
+
const id = rec.match(/^- id:\s*(\S+)/)?.[1];
|
|
157
|
+
|
|
158
|
+
return id ? [recordState(id, rec, at)] : [];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const BOM = String.fromCharCode(0xfeff);
|
|
163
|
+
const noBom = (s) => (s.startsWith(BOM) ? s.slice(1) : s);
|
|
164
|
+
|
|
165
|
+
/** The commit that wrote each record's `- id:` line, or null without a blame. */
|
|
166
|
+
function birthsOf(projectDir) {
|
|
167
|
+
const blamed = blameLines(projectDir, 'gcf/open-questions.md');
|
|
168
|
+
if (!blamed) return null;
|
|
169
|
+
const births = new Map();
|
|
170
|
+
for (const { hash, text } of blamed) {
|
|
171
|
+
const id = noBom(text).match(/^- id:\s*(\S+)/)?.[1];
|
|
172
|
+
if (id) births.set(id, hash);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return births;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function recordState(id, rec, { fired, limit, births, since }) {
|
|
179
|
+
const d2 = /^D2\b/.test(fieldOf(rec, 'class') ?? '');
|
|
180
|
+
const answered = Boolean(fieldOf(rec, 'answer'));
|
|
181
|
+
const trigger = d2 ? triggerOf(rec) : null;
|
|
182
|
+
// No blame: no birth, retune as before; a record the blame does not show is uncommitted.
|
|
183
|
+
const birth = births ? (births.get(id) ?? '0') : undefined;
|
|
184
|
+
const status = statusOf({ d2, answered, trigger }, fired, birth);
|
|
185
|
+
const commits = birth && !isUncommitted(birth) ? since(birth) : undefined;
|
|
186
|
+
const owed = !answered && (!trigger || status === 'manual');
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
id,
|
|
190
|
+
d2,
|
|
191
|
+
trigger,
|
|
192
|
+
status,
|
|
193
|
+
commits,
|
|
194
|
+
aged: owed && isOld(commits, limit),
|
|
195
|
+
sys: fieldOf(rec, 'sys'),
|
|
196
|
+
text: rec.trim(),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const triggerOf = (rec) => fieldOf(rec, 'until')?.match(D2_UNTIL_RE)?.[1] ?? null;
|
|
201
|
+
// No commit to age from is fresh; a commit that no longer resolves is never guessed fresh.
|
|
202
|
+
const isOld = (commits, limit) => commits !== undefined && (commits === null || commits > limit);
|
|
203
|
+
|
|
204
|
+
function statusOf({ d2, answered, trigger }, fired, birth) {
|
|
205
|
+
if (d2 && answered) return 'answered';
|
|
206
|
+
|
|
207
|
+
return trigger ? untilStatus(trigger, fired, birth) : null;
|
|
208
|
+
}
|
package/lib/design-parts.js
CHANGED
|
@@ -44,7 +44,7 @@ import { buildLedger } from './ledger.js';
|
|
|
44
44
|
import { deriveId } from './id.js';
|
|
45
45
|
import { renamePillar } from './pillars.js';
|
|
46
46
|
import { dirtyPaths, restoreFromHead } from './git.js';
|
|
47
|
-
import { blocksOf, putBlock } from './systems-doc.js';
|
|
47
|
+
import { blocksOf, fillPurpose, purposeTarget, putBlock } from './systems-doc.js';
|
|
48
48
|
|
|
49
49
|
// The work stage writes these blocks: a unit in design/ has not reached them.
|
|
50
50
|
const WORK_ONLY = ['contract', 'interactions', 'tuning', 'notes'];
|
|
@@ -556,6 +556,27 @@ const noteOf = (p) =>
|
|
|
556
556
|
// Nothing of the bundle applied: no commit to make.
|
|
557
557
|
class NothingApplied extends Error {}
|
|
558
558
|
|
|
559
|
+
/**
|
|
560
|
+
* The subsystems of the design/<s>.md among `files` whose systems doc still waits on its purpose
|
|
561
|
+
* and gets it from this move (fillPurpose), each with that doc. `parts`: a bundle's, whose system
|
|
562
|
+
* part is the purpose the move is about to write.
|
|
563
|
+
* @param {string} root
|
|
564
|
+
* @param {string[]} files
|
|
565
|
+
* @param {{kind: string, name: string, text: string}[]} [parts]
|
|
566
|
+
*/
|
|
567
|
+
async function purposeFills(root, files, parts = []) {
|
|
568
|
+
const fills = new Map();
|
|
569
|
+
for (const f of files) {
|
|
570
|
+
const s = path.basename(f, '.md');
|
|
571
|
+
if (path.dirname(f) !== path.join(root, 'design') || !SLUG_RE.test(s) || fills.has(s)) continue;
|
|
572
|
+
const part = parts.find((p) => p.kind === 'system' && p.name === s);
|
|
573
|
+
const doc = await purposeTarget(root, s, part?.text);
|
|
574
|
+
if (doc) fills.set(s, doc);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return fills;
|
|
578
|
+
}
|
|
579
|
+
|
|
559
580
|
/**
|
|
560
581
|
* Bring `text` in through the import and commit what it wrote. `strict`: a part the import
|
|
561
582
|
* reports refuses the whole move. Files with changes not recorded yet refuse it up front: the
|
|
@@ -573,8 +594,9 @@ async function bundleMove(
|
|
|
573
594
|
{ key, items = [], strict = false, draft = false, commit = true },
|
|
574
595
|
) {
|
|
575
596
|
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
597
|
+
const { parts } = parseBundle(text);
|
|
576
598
|
// Only the names a write may take (bundle.js validName): no other path gets staged.
|
|
577
|
-
const files =
|
|
599
|
+
const files = parts.flatMap((p) => {
|
|
578
600
|
if (p.kind === 'doc')
|
|
579
601
|
return Object.hasOwn(DOC_FILES, p.name) ? [path.join(root, DOC_FILES[p.name])] : [];
|
|
580
602
|
const sys = p.kind === 'system' ? p.name : p.system;
|
|
@@ -583,7 +605,8 @@ async function bundleMove(
|
|
|
583
605
|
? [path.join(root, 'design', `${sys}.md`)]
|
|
584
606
|
: [];
|
|
585
607
|
});
|
|
586
|
-
const
|
|
608
|
+
const fills = await purposeFills(root, files, parts);
|
|
609
|
+
const touched = [...new Set([...files, path.join(root, 'backlog.md'), ...fills.values()])];
|
|
587
610
|
const rel = (f) => path.relative(path.resolve(projectDir), f).replaceAll('\\', '/');
|
|
588
611
|
// A form's save over an agent's draft of its own file takes the draft along (decision 35): the
|
|
589
612
|
// operator saw it in the form. Another file's changes would ride along unseen.
|
|
@@ -611,6 +634,7 @@ async function bundleMove(
|
|
|
611
634
|
if (strict && refused.length)
|
|
612
635
|
throw new Error(refused.map((p) => `${p.outcome} ${p.part}: ${noteOf(p)}`).join('\n'));
|
|
613
636
|
if (!result.applied.length) throw new NothingApplied();
|
|
637
|
+
for (const s of fills.keys()) await fillPurpose(root, s);
|
|
614
638
|
},
|
|
615
639
|
});
|
|
616
640
|
|
|
@@ -690,16 +714,21 @@ async function commitUnlocked(projectDir, { message = null, commit = true } = {}
|
|
|
690
714
|
}
|
|
691
715
|
|
|
692
716
|
const abs = files.map((f) => path.join(path.resolve(projectDir), f));
|
|
717
|
+
const root = path.join(path.resolve(projectDir), 'gcf');
|
|
718
|
+
const fills = await purposeFills(root, abs);
|
|
693
719
|
const why = oneLine(message) || 'record the design';
|
|
694
720
|
const hash = await commitMove(projectDir, `gcf(design): ${why}`, {
|
|
695
|
-
files: abs,
|
|
721
|
+
files: [...abs, ...fills.values()],
|
|
696
722
|
inputs: abs,
|
|
697
|
-
mutate: async () => {
|
|
723
|
+
mutate: async () => {
|
|
724
|
+
for (const s of fills.keys()) await fillPurpose(root, s);
|
|
725
|
+
},
|
|
698
726
|
commit,
|
|
699
727
|
key: 'design-commit',
|
|
700
728
|
});
|
|
729
|
+
const rel = (f) => path.relative(path.resolve(projectDir), f).replaceAll('\\', '/');
|
|
701
730
|
|
|
702
|
-
return { files, hash };
|
|
731
|
+
return { files: [...files, ...[...fills.values()].map(rel)], hash };
|
|
703
732
|
}
|
|
704
733
|
|
|
705
734
|
// What an agent's draft writes (decision 35), and so what `design discard` may take back: not an
|
|
@@ -760,7 +789,8 @@ export async function designState(projectDir, { report, questions, items }) {
|
|
|
760
789
|
const units = new Set(report.units.map((u) => u.id));
|
|
761
790
|
const sources = await sourcesOf(root);
|
|
762
791
|
const asked = questions.filter((q) => isDesignQuestion(q, units));
|
|
763
|
-
|
|
792
|
+
// The board's rows (d2-states.js questionRow): a fired or aged D2 waits on the Operator too.
|
|
793
|
+
const open = asked.filter((q) => q.category === 'decision' && !q.answer);
|
|
764
794
|
const pillars = recordsIn(pillarsText, 'pillars').map((p) => ({
|
|
765
795
|
id: p.id ?? null,
|
|
766
796
|
// The few words the operator knows it by (decision 34); an old file has none.
|
package/lib/domain.js
CHANGED
|
@@ -261,7 +261,12 @@ const ITEM_SPECS = {
|
|
|
261
261
|
kind: 'choice',
|
|
262
262
|
required: true,
|
|
263
263
|
options: [
|
|
264
|
-
{
|
|
264
|
+
{
|
|
265
|
+
value: 'default',
|
|
266
|
+
label:
|
|
267
|
+
'default: where its kept session ran, else its live worktree copy, ' +
|
|
268
|
+
"else the project's run_mode",
|
|
269
|
+
},
|
|
265
270
|
...RUN_MODES.map((m) => ({ value: m, label: m, help: RUN_MODE_HELP[m] })),
|
|
266
271
|
],
|
|
267
272
|
},
|
package/lib/gcf-paths.js
CHANGED
|
@@ -46,9 +46,11 @@ export function gcfRoot(projectDir = process.cwd()) {
|
|
|
46
46
|
// How a harness run drives an item (Methodology §7): `worktree` — each in its own copy, several
|
|
47
47
|
// at once; `main` — one at a time in the project's own folder, for an agent that works through
|
|
48
48
|
// a running editor bound to that folder. The project chooses; the framework knows no engine.
|
|
49
|
+
// `main` unless set (Fallback-Fidelity-Plan d1); a card whose copy lives stays in its worktree
|
|
50
|
+
// (integrate.js `cardRunMode`).
|
|
49
51
|
export const RUN_MODES = ['worktree', 'main'];
|
|
50
52
|
|
|
51
|
-
function runModeOf(v = '
|
|
53
|
+
function runModeOf(v = 'main') {
|
|
52
54
|
if (!RUN_MODES.includes(v))
|
|
53
55
|
throw new Error(`gcf/config.yml: run_mode must be ${RUN_MODES.join(' | ')}, got ${v}`);
|
|
54
56
|
|
|
@@ -115,16 +117,42 @@ function gatesOf(v = {}) {
|
|
|
115
117
|
export const REVIEW_AGENTS = ['claude', 'codex'];
|
|
116
118
|
export const REVIEW_DEFAULTS = {
|
|
117
119
|
plan: [
|
|
118
|
-
{ agent: 'claude', model: 'opus', effort: 'high' },
|
|
119
|
-
{ agent: 'claude', model: 'opus', effort: 'high' },
|
|
120
120
|
{ agent: 'codex', model: 'astra', effort: 'medium' },
|
|
121
|
+
{ agent: 'claude', model: 'fable', effort: 'medium' },
|
|
122
|
+
{ agent: 'claude', model: 'fable', effort: 'medium' },
|
|
121
123
|
],
|
|
122
124
|
code: [
|
|
123
|
-
{ agent: '
|
|
125
|
+
{ agent: 'codex', model: 'sol', effort: 'high' },
|
|
124
126
|
{ agent: 'claude', model: 'opus', effort: 'high' },
|
|
125
127
|
],
|
|
126
128
|
};
|
|
127
129
|
|
|
130
|
+
// Who makes a pass its row cannot make (Fallback-Fidelity-Plan d2): the first rule that matches
|
|
131
|
+
// the row (`model` null: any) gives its stand-ins in order; no rule, none. The board reads it.
|
|
132
|
+
const FABLE_MEDIUM = { agent: 'claude', model: 'fable', effort: 'medium' };
|
|
133
|
+
const OPUS_HIGH = { agent: 'claude', model: 'opus', effort: 'high' };
|
|
134
|
+
export const REVIEW_FALLBACK = [
|
|
135
|
+
{ agent: 'codex', model: null, effort: 'medium', rows: [FABLE_MEDIUM, OPUS_HIGH] },
|
|
136
|
+
{ agent: 'codex', model: null, effort: 'high', rows: [OPUS_HIGH] },
|
|
137
|
+
{ agent: 'claude', model: 'fable', effort: 'medium', rows: [OPUS_HIGH] },
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
/** A Codex model as its family: the slug `gpt-6-astra` is `astra` (gcf-session `familyOf`). */
|
|
141
|
+
export const modelFamily = (model) =>
|
|
142
|
+
/^[a-z]+-\d+(?:\.\d+)*-([a-z]+)$/.exec(String(model))?.[1] ?? String(model);
|
|
143
|
+
|
|
144
|
+
/** The stand-ins of a review row `{agent, model, effort}`, in order; none: `[]`. */
|
|
145
|
+
export function fallbackOf(row) {
|
|
146
|
+
const rule = REVIEW_FALLBACK.find(
|
|
147
|
+
(r) =>
|
|
148
|
+
r.agent === row?.agent &&
|
|
149
|
+
r.effort === row.effort &&
|
|
150
|
+
(r.model === null || r.model === modelFamily(row.model)),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return rule ? rule.rows.map((r) => ({ ...r })) : [];
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
/** A review row's refusal, if any: three plain words, the agent one GCF runs. */
|
|
129
157
|
export function reviewRowProblem(r) {
|
|
130
158
|
if (typeof r !== 'object' || r === null || Array.isArray(r))
|
package/lib/git.js
CHANGED
|
@@ -119,7 +119,18 @@ export const GATE_SCOPE = [
|
|
|
119
119
|
export function dirtyGcf(projectDir, skip = []) {
|
|
120
120
|
const res = spawnSync(
|
|
121
121
|
'git',
|
|
122
|
-
|
|
122
|
+
// No index.lock: a move waiting behind a run asks this each second, and would break its commit.
|
|
123
|
+
[
|
|
124
|
+
'--no-optional-locks',
|
|
125
|
+
'-c',
|
|
126
|
+
'core.quotePath=false',
|
|
127
|
+
'status',
|
|
128
|
+
'--porcelain',
|
|
129
|
+
'-z',
|
|
130
|
+
'-uall',
|
|
131
|
+
'--',
|
|
132
|
+
...GATE_SCOPE,
|
|
133
|
+
],
|
|
123
134
|
{ windowsHide: true, cwd: projectDir, encoding: 'utf8' },
|
|
124
135
|
);
|
|
125
136
|
if (res.status !== 0) return [];
|
|
@@ -152,12 +163,16 @@ export function dirtyGcf(projectDir, skip = []) {
|
|
|
152
163
|
|
|
153
164
|
/**
|
|
154
165
|
* The refusal of a move that uncommitted gcf/ edits stop: `dirty` with `paths` (dirtyGcf) when
|
|
155
|
-
* there are any, so a board offers to show, commit or discard them; else the words alone.
|
|
166
|
+
* there are any, so a board offers to show, commit or discard them; else the words alone. `move`
|
|
167
|
+
* names the move it stops: one that waits behind a main run says it (lib/main-lock.js).
|
|
156
168
|
* @param {string[]} paths
|
|
157
169
|
* @param {string} message
|
|
170
|
+
* @param {{message: string, items?: string[]}} move
|
|
158
171
|
*/
|
|
159
|
-
export const dirtyRefusal = (paths, message) =>
|
|
160
|
-
paths.length ? refusal('dirty', { paths }, message) : new Error(message)
|
|
172
|
+
export const dirtyRefusal = (paths, message, move) =>
|
|
173
|
+
Object.assign(paths.length ? refusal('dirty', { paths }, message) : new Error(message), {
|
|
174
|
+
move: { ...move, items: move.items ?? [] },
|
|
175
|
+
});
|
|
161
176
|
|
|
162
177
|
/** A path from the project with `/`, from an absolute one or one already relative. */
|
|
163
178
|
const relOf = (projectDir, p) =>
|
|
@@ -288,7 +303,12 @@ export function commitPaths(projectDir, message, paths, move = {}) {
|
|
|
288
303
|
// nothing: no pathspec.
|
|
289
304
|
const real = paths.filter((p) => existsSync(p) || inHead(projectDir, p));
|
|
290
305
|
|
|
291
|
-
|
|
306
|
+
try {
|
|
307
|
+
return commitOnly(projectDir, message, real, ['-m', message, ...moveTrailers(move)]);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
if (e.move) e.move.items = move.items ?? [];
|
|
310
|
+
throw e;
|
|
311
|
+
}
|
|
292
312
|
}
|
|
293
313
|
|
|
294
314
|
/**
|
|
@@ -327,6 +347,7 @@ export function commitOnly(projectDir, message, paths, msg) {
|
|
|
327
347
|
loose,
|
|
328
348
|
`cannot record ${message} while gcf/ holds uncommitted changes: ${loose.join(', ')} — ` +
|
|
329
349
|
'commit or discard them, then try again',
|
|
350
|
+
{ message },
|
|
330
351
|
);
|
|
331
352
|
}
|
|
332
353
|
|
package/lib/integrate.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// not in memory. `integrate` merges such a branch into main and records the item's move there,
|
|
4
4
|
// under the main lock; without an id it picks up every verified branch a dead run left behind.
|
|
5
5
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
6
|
-
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { buildLedger } from './ledger.js';
|
|
@@ -208,6 +208,63 @@ export function verifiedBranches(projectDir) {
|
|
|
208
208
|
.filter((id) => isVerified(projectDir, id));
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* The ids whose worktree run left a copy that lives (Fallback-Fidelity-Plan d1): its folder, or
|
|
213
|
+
* its branch `work/<id>` whose tip is no main-mode shelf (lib/shelf.js `GCF-Shelved`). None
|
|
214
|
+
* outside a repository.
|
|
215
|
+
*/
|
|
216
|
+
export function liveCopies(projectDir) {
|
|
217
|
+
const home = path.dirname(worktreeOf(projectDir, 'x'));
|
|
218
|
+
const ids = new Set();
|
|
219
|
+
try {
|
|
220
|
+
for (const e of readdirSync(home, { withFileTypes: true }))
|
|
221
|
+
if (e.isDirectory() && isValidId(e.name)) ids.add(e.name);
|
|
222
|
+
} catch {
|
|
223
|
+
// No worktree folder: no copy there.
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const format = '--format=%(refname:short)%00%(trailers:key=GCF-Shelved,valueonly,separator=%x2C)';
|
|
227
|
+
const refs = git(projectDir, ['for-each-ref', format, 'refs/heads/work/'], { check: false });
|
|
228
|
+
for (const l of refs.ok ? refs.out.split('\n') : []) {
|
|
229
|
+
const [ref, shelved = ''] = l.split('\0');
|
|
230
|
+
const id = ref.slice('work/'.length);
|
|
231
|
+
if (ref.startsWith('work/') && !shelved.split(',').some((v) => v.trim() === id)) ids.add(id);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return ids;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The mode a run of the card takes when the run asks none (Fallback-Fidelity-Plan d1): the
|
|
239
|
+
* card's own `run_mode`; the mode its last session ran in, while the harness keeps its record
|
|
240
|
+
* (`.gcf-session/runs/<id>.agent.json` `mode`: a resume goes on where its work is, a fresh
|
|
241
|
+
* start too); `worktree` while a copy of it lives; else the project's. Its work is not left
|
|
242
|
+
* behind when the project's mode or its default changes. `live`: one `liveCopies` read for many.
|
|
243
|
+
* @param {string} projectDir
|
|
244
|
+
* @param {string} id
|
|
245
|
+
* @param {{own?: string | null, project: string, live?: Set<string>}} o
|
|
246
|
+
*/
|
|
247
|
+
export function cardRunMode(projectDir, id, { own, project, live }) {
|
|
248
|
+
if (own) return own;
|
|
249
|
+
const saved = savedMode(projectDir, id);
|
|
250
|
+
if (saved) return saved;
|
|
251
|
+
|
|
252
|
+
return (live ?? liveCopies(projectDir)).has(id) ? 'worktree' : project;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** The mode the harness's record of the card's last session names, or null. */
|
|
256
|
+
function savedMode(projectDir, id) {
|
|
257
|
+
if (!isValidId(id)) return null;
|
|
258
|
+
const file = path.join(path.resolve(projectDir), '.gcf-session', 'runs', `${id}.agent.json`);
|
|
259
|
+
try {
|
|
260
|
+
const mode = JSON.parse(readFileSync(file, 'utf8'))?.mode;
|
|
261
|
+
|
|
262
|
+
return mode === 'main' || mode === 'worktree' ? mode : null;
|
|
263
|
+
} catch {
|
|
264
|
+
return null; // No record, or none to read.
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
211
268
|
/**
|
|
212
269
|
* Take the worktree and the branch away once the branch is in main (or tagged, for a spike).
|
|
213
270
|
* Without --force: work left uncommitted in the worktree stops the removal and is named.
|