gcf-aif-ext 0.18.8 → 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 +22 -1
- package/commands/gcf.js +183 -9
- package/extension.json +1 -1
- package/lib/agent-permissions.js +57 -14
- package/lib/audit-core.js +18 -2
- package/lib/board.js +13 -4
- package/lib/config-set.js +92 -0
- package/lib/design-check.js +11 -1
- package/lib/design-parts.js +5 -2
- package/lib/domain.js +30 -2
- package/lib/gates.js +57 -0
- package/lib/gcf-paths.js +37 -1
- package/lib/git.js +26 -6
- package/lib/history.js +1 -1
- package/lib/integrate.js +71 -7
- package/lib/milestone-state.js +118 -0
- package/lib/phase.js +24 -6
- package/lib/playtest-list.js +64 -2
- package/lib/questions.js +77 -0
- package/lib/transitions.js +2 -0
- package/lib/unit-ops.js +46 -11
- package/lib/validate-item.js +16 -0
- package/lib/verify.js +1 -5
- package/lib/work-ops.js +332 -25
- package/package.json +1 -1
- package/profiles/game.md +2 -2
- package/schemas/item.schema.json +3 -0
- package/skills/gcf-card/SKILL.md +9 -3
- package/skills/gcf-verdict/SKILL.md +5 -2
- package/skills/gcf-vision/SKILL.md +4 -0
- package/templates/agents-block.md +6 -1
package/lib/board.js
CHANGED
|
@@ -24,6 +24,8 @@ import { agentOf } from './agent-permissions.js';
|
|
|
24
24
|
import { projectSettings } from './config-set.js';
|
|
25
25
|
import { designCheck, designUnits } from './design-check.js';
|
|
26
26
|
import { designState } from './design-parts.js';
|
|
27
|
+
import { gatePolicy } from './gates.js';
|
|
28
|
+
import { milestoneState } from './milestone-state.js';
|
|
27
29
|
|
|
28
30
|
// The version of the JSON below (Methodology §11): a board refuses one it does not know. Bump it
|
|
29
31
|
// when a field changes meaning or goes away; a new field does not bump it.
|
|
@@ -219,6 +221,8 @@ const SCALARS = [
|
|
|
219
221
|
'model',
|
|
220
222
|
'effort',
|
|
221
223
|
'run_mode',
|
|
224
|
+
'skip_gates',
|
|
225
|
+
'gate_why',
|
|
222
226
|
];
|
|
223
227
|
|
|
224
228
|
/**
|
|
@@ -243,7 +247,7 @@ function inRunOrder(items) {
|
|
|
243
247
|
);
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
const LISTS = ['children', 'system', 'depends'];
|
|
250
|
+
const LISTS = ['children', 'system', 'depends', 'play_on'];
|
|
247
251
|
|
|
248
252
|
/**
|
|
249
253
|
* Its dependencies not ended in history (Board-PRD §5.2): items on the board, design units,
|
|
@@ -311,7 +315,7 @@ async function attachmentsOf(projectDir, id) {
|
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
/** One item of the board. */
|
|
314
|
-
async function itemOf(projectDir, c, { verified, ledger, harness }) {
|
|
318
|
+
async function itemOf(projectDir, c, { verified, ledger, harness, config }) {
|
|
315
319
|
const id = String(c.data.id);
|
|
316
320
|
// A trailer counts only while the item waits on main for its integrate.
|
|
317
321
|
const ready = c.data.status === 'ready' && verified.has(id);
|
|
@@ -337,6 +341,8 @@ async function itemOf(projectDir, c, { verified, ledger, harness }) {
|
|
|
337
341
|
...Object.fromEntries(LISTS.map((k) => [k, c.data[k] ?? []])),
|
|
338
342
|
...(c.data.severity ? { severity: c.data.severity } : {}),
|
|
339
343
|
...(c.data.blocked ? { blocked: c.data.blocked } : {}),
|
|
344
|
+
// The gates in force for it: the project's, or its card's (docs/Autonomy-Plan.md, B).
|
|
345
|
+
gates: gatePolicy(config, c.data),
|
|
340
346
|
running,
|
|
341
347
|
// `run`: a harness run's lock; `session`: an operator's or agent's session mark (`gcf claim`).
|
|
342
348
|
running_kind: kind,
|
|
@@ -361,9 +367,10 @@ export async function board(projectDir) {
|
|
|
361
367
|
const verified = verifiedOf(projectDir);
|
|
362
368
|
const { extensions, error: extensionsError } = await extensionsOf(projectDir);
|
|
363
369
|
const harness = hasHarness(extensions);
|
|
370
|
+
const config = await readConfig(root);
|
|
364
371
|
const items = [];
|
|
365
372
|
for (const c of ledger.items)
|
|
366
|
-
items.push(await itemOf(projectDir, c, { verified, ledger, harness }));
|
|
373
|
+
items.push(await itemOf(projectDir, c, { verified, ledger, harness, config }));
|
|
367
374
|
inRunOrder(items);
|
|
368
375
|
// When the wait began: the time of the commit `since` names (Board-PRD §13).
|
|
369
376
|
const times = commitTimes(
|
|
@@ -380,7 +387,6 @@ export async function board(projectDir) {
|
|
|
380
387
|
for (const i of items)
|
|
381
388
|
i.needed_by = items.filter((o) => o.depends.includes(i.id)).map((o) => o.id);
|
|
382
389
|
|
|
383
|
-
const config = await readConfig(root);
|
|
384
390
|
const live = await readLive(root);
|
|
385
391
|
const questions = await listQuestions(root);
|
|
386
392
|
const { units, design } = await designOf(projectDir, ledger, questions);
|
|
@@ -388,6 +394,9 @@ export async function board(projectDir) {
|
|
|
388
394
|
return {
|
|
389
395
|
schema: BOARD_SCHEMA,
|
|
390
396
|
run_mode: config.run_mode,
|
|
397
|
+
// The project's gates: and where each milestone stands (docs/Autonomy-Plan.md, B and D).
|
|
398
|
+
gates: config.gates,
|
|
399
|
+
...(await milestoneState(projectDir, ledger, units)),
|
|
391
400
|
// What the harness hands its agent runs (Harness-PRD §7): deny rules and the context limits.
|
|
392
401
|
agent: agentOf(config),
|
|
393
402
|
// The human's settings of config.yml and the agents' language, each with its value and
|
package/lib/config-set.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
CHAT_DEFAULTS,
|
|
20
20
|
configOf,
|
|
21
21
|
DEFAULT_CONFIG,
|
|
22
|
+
GATE_POLICY,
|
|
22
23
|
gcfRoot,
|
|
23
24
|
readRawConfig,
|
|
24
25
|
RUN_MODES,
|
|
@@ -120,6 +121,39 @@ export const SETTINGS = [
|
|
|
120
121
|
'minutes a question waits for your answer before the agent takes its default (0: nobody ' +
|
|
121
122
|
'watches, as for a night run; a main run waits with its whole queue)',
|
|
122
123
|
},
|
|
124
|
+
{
|
|
125
|
+
key: 'gates.milestone',
|
|
126
|
+
kind: 'mode',
|
|
127
|
+
options: GATE_POLICY.milestone,
|
|
128
|
+
label:
|
|
129
|
+
'when a milestone is built: wait (the autopilot stops for you to play it) or go (it ' +
|
|
130
|
+
'builds the next one, the built one waits for your play)',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: 'gates.verdict',
|
|
134
|
+
kind: 'mode',
|
|
135
|
+
options: GATE_POLICY.verdict,
|
|
136
|
+
label:
|
|
137
|
+
'an item with its own verdict gate: wait (it waits for your play) or defer (a mechanic ' +
|
|
138
|
+
'or a resource closes unplayed and is played with its milestone)',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
key: 'gates.decision',
|
|
142
|
+
kind: 'mode',
|
|
143
|
+
options: GATE_POLICY.decision,
|
|
144
|
+
label:
|
|
145
|
+
'a spike or decision item: wait (it waits for your decision) or agent (the agent decides ' +
|
|
146
|
+
'go or no with its reason; a release always waits)',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
key: 'gates.question',
|
|
150
|
+
kind: 'mode',
|
|
151
|
+
options: GATE_POLICY.question,
|
|
152
|
+
label:
|
|
153
|
+
'a question for you: wait (the item blocks, or a run asks) or assume (the agent writes ' +
|
|
154
|
+
'its assumption and goes on; never for a save format, a public API, a new dependency or ' +
|
|
155
|
+
'a pillar conflict)',
|
|
156
|
+
},
|
|
123
157
|
{ key: 'dod.test', kind: 'command', label: "the project's test command for the DoD, or none" },
|
|
124
158
|
{ key: 'dod.build', kind: 'command', label: "the project's build command for the DoD, or none" },
|
|
125
159
|
{
|
|
@@ -189,6 +223,7 @@ const GROUPS = [
|
|
|
189
223
|
],
|
|
190
224
|
],
|
|
191
225
|
['Checks (DoD)', ['dod.test', 'dod.build', 'dod_timeout_min']],
|
|
226
|
+
['Autonomy', ['gates.milestone', 'gates.verdict', 'gates.decision', 'gates.question']],
|
|
192
227
|
['Chat', ['chat.ask', 'chat.answer_timeout_min']],
|
|
193
228
|
['Context', ['context_handoff_pct', 'context_window', 'auto_compact_pct']],
|
|
194
229
|
[
|
|
@@ -211,6 +246,7 @@ function defaultOf(s, aif) {
|
|
|
211
246
|
if (s.key === 'language.artifacts') return languageIn(aif, 'ui') ?? 'en';
|
|
212
247
|
if (s.kind === 'language') return 'en';
|
|
213
248
|
if (head === 'chat') return CHAT_DEFAULTS[sub];
|
|
249
|
+
if (head === 'gates') return 'wait';
|
|
214
250
|
if (sub) return null;
|
|
215
251
|
|
|
216
252
|
return head === 'run_mode' ? 'worktree' : (DEFAULT_CONFIG[head] ?? null);
|
|
@@ -360,3 +396,59 @@ export async function setConfig(projectDir, key, text, { commit = true } = {}) {
|
|
|
360
396
|
|
|
361
397
|
return { key, value, unchanged, ignored, settings, hash };
|
|
362
398
|
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Set several keys of gcf/config.yml in one commit, `gcf(config): <key>, <key>`: a preset of
|
|
402
|
+
* the board (docs/Autonomy-Plan.md, E). Each value as `setConfig` takes it; a key of AI
|
|
403
|
+
* Factory's file is set alone. Nothing changed, nothing committed.
|
|
404
|
+
* @param {string} projectDir
|
|
405
|
+
* @param {[string, string][]} pairs
|
|
406
|
+
*/
|
|
407
|
+
export async function setConfigs(projectDir, pairs, { commit = true } = {}) {
|
|
408
|
+
if (!pairs.length) throw new Error('name a key=value to set');
|
|
409
|
+
const changes = pairs.map(([key, text]) => {
|
|
410
|
+
const setting = BY_KEY.get(key);
|
|
411
|
+
if (!setting) throw new Error(`no setting ${key}: ${SETTINGS.map((s) => s.key).join(' | ')}`);
|
|
412
|
+
if (setting.file) throw new Error(`${key} lives in ${setting.file}: set it on its own`);
|
|
413
|
+
|
|
414
|
+
return { key, keys: key.split('.'), value: valueOf(setting, text) };
|
|
415
|
+
});
|
|
416
|
+
const file = path.join(gcfRoot(projectDir), 'config.yml');
|
|
417
|
+
let unchanged = false;
|
|
418
|
+
const mutate = async () => {
|
|
419
|
+
const text = existsSync(file) ? await readFile(file, 'utf8') : '';
|
|
420
|
+
const doc = configDoc(text, 'gcf/config.yml');
|
|
421
|
+
for (const c of changes) {
|
|
422
|
+
// A reset of a key whose parent is not there changes nothing: no empty map is written.
|
|
423
|
+
if (c.value === null && c.keys.length > 1 && !YAML.isMap(doc.getIn([c.keys[0]], true)))
|
|
424
|
+
continue;
|
|
425
|
+
if (c.keys.length > 1)
|
|
426
|
+
ensureMap(doc, [c.keys[0]], `gcf/config.yml: ${c.keys[0]} must map its keys`);
|
|
427
|
+
if (c.value === null) doc.deleteIn(c.keys);
|
|
428
|
+
else doc.setIn(c.keys, c.value);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const raw = doc.toJS();
|
|
432
|
+
agentOf(configOf(raw));
|
|
433
|
+
if (isDeepStrictEqual(YAML.parse(text) ?? {}, raw ?? {})) {
|
|
434
|
+
unchanged = true;
|
|
435
|
+
throw NO_CHANGE;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
await atomicWrite(file, doc.toString());
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const keys = changes.map((c) => c.key);
|
|
442
|
+
const hash = await commitMove(projectDir, `gcf(config): ${keys.join(', ')}`, {
|
|
443
|
+
files: [file],
|
|
444
|
+
mutate,
|
|
445
|
+
commit,
|
|
446
|
+
key: 'config',
|
|
447
|
+
}).catch((e) => {
|
|
448
|
+
if (e !== NO_CHANGE) throw e;
|
|
449
|
+
|
|
450
|
+
return null;
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
return { keys, unchanged, settings: await projectSettings(projectDir).catch(() => []), hash };
|
|
454
|
+
}
|
package/lib/design-check.js
CHANGED
|
@@ -143,7 +143,7 @@ export async function gameMilestones(root) {
|
|
|
143
143
|
? null
|
|
144
144
|
: recordsIn(game, 'milestones')
|
|
145
145
|
.filter((m) => SLUG_RE.test(m.name ?? ''))
|
|
146
|
-
.map((m) => ({ name: m.name, goal: m.goal ?? null }));
|
|
146
|
+
.map((m) => ({ name: m.name, goal: m.goal ?? null, play: m.play ?? null }));
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/** A D1 record nobody answered yet: only such a question holds its units. */
|
|
@@ -425,6 +425,16 @@ async function checkUnit(u, ctx, ledger) {
|
|
|
425
425
|
const atBody = (line) => (line ? u.bodyLine + line - 1 : u.line);
|
|
426
426
|
for (const [c, line, m] of headerIssues(u, ctx, ledger)) add(c, line, m);
|
|
427
427
|
if (!UNIT_TYPES.includes(u.header.type)) return { issues, values: [] };
|
|
428
|
+
// A soft unit is played with its milestone (docs/Autonomy-Plan.md, C): a reading, not a block.
|
|
429
|
+
const own = u.header.milestone;
|
|
430
|
+
const none = own === undefined || own === 'TBD' || own === 'later';
|
|
431
|
+
if (ctx.milestones?.length && CARD_TYPES.includes(u.header.type) && none)
|
|
432
|
+
add(
|
|
433
|
+
'M2',
|
|
434
|
+
u.line,
|
|
435
|
+
`no milestone: give it the milestone it is played with (${ctx.milestones.join(', ')})`,
|
|
436
|
+
'report',
|
|
437
|
+
);
|
|
428
438
|
|
|
429
439
|
const { profile, issues: shape } = await bodyProblems(u.body, u.header.type, 'design');
|
|
430
440
|
for (const i of shape) add('M1', atBody(i.line), i.message);
|
package/lib/design-parts.js
CHANGED
|
@@ -284,9 +284,12 @@ async function withManualAnswers(text, edited, type) {
|
|
|
284
284
|
if (!owed.length) return text;
|
|
285
285
|
const lines = text.split('\n');
|
|
286
286
|
const at = blocksOf(text).find((b) => b.key === 'provenance');
|
|
287
|
-
// CNL-P §3: records of two lines stand apart, each new one after a blank line
|
|
287
|
+
// CNL-P §3: records of two lines stand apart, each new one after a blank line; a block an
|
|
288
|
+
// import wrote tight stays tight, one spacing per block.
|
|
289
|
+
const own = at ? lines.slice(at.start, at.end) : [];
|
|
290
|
+
const tight = own.filter((l) => l.startsWith('- ')).length > 1 && own.every((l) => l.trim());
|
|
288
291
|
const records = owed.flatMap((slot, i) => [
|
|
289
|
-
...(at || i ? [''] : []),
|
|
292
|
+
...((at || i) && !tight ? [''] : []),
|
|
290
293
|
`- slot: ${slot}`,
|
|
291
294
|
' answer: manual',
|
|
292
295
|
]);
|
package/lib/domain.js
CHANGED
|
@@ -28,7 +28,9 @@ const HUMAN = new Set(['blocked', 'awaiting-verdict', 'awaiting-decision', 'unpl
|
|
|
28
28
|
|
|
29
29
|
const GATE_HELP = {
|
|
30
30
|
verdict: 'Closed by a playtest: keep, tune or kill',
|
|
31
|
-
auto:
|
|
31
|
+
auto:
|
|
32
|
+
'Closed by the run itself when its checks are green; a mechanic or a resource goes ' +
|
|
33
|
+
'unplayed and is played with its milestone',
|
|
32
34
|
decision: 'Closed by the operator: go, no, close or continue',
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -42,6 +44,8 @@ const REASON = { key: 'reason', label: 'Reason', kind: 'longtext', required: tru
|
|
|
42
44
|
const OPTIONAL_REASON = { ...REASON, required: false };
|
|
43
45
|
const REMOVE = { key: 'remove', label: 'Removal item for its code', kind: 'remove' };
|
|
44
46
|
const CONSTRAINT = { key: 'constraint', label: 'Constraint lines', kind: 'list' };
|
|
47
|
+
// Where the operator played it: lines of game.md's platforms, a note for the history (Plan, C).
|
|
48
|
+
const PLAYED_ON = { key: 'played_on', flag: 'played-on', label: 'Played on', kind: 'list' };
|
|
45
49
|
// close and submit need a green gcf verify of the code as it is now; the operator may say why
|
|
46
50
|
// they go without one, and the reason goes into the move's commit.
|
|
47
51
|
const UNVERIFIED = {
|
|
@@ -103,7 +107,7 @@ const ITEM_SPECS = {
|
|
|
103
107
|
rare: true,
|
|
104
108
|
},
|
|
105
109
|
// A keep stores no note (`gcf verdict --note` is a tune's remark, a kill's reason).
|
|
106
|
-
'verdict:keep': verdict('keep', 'Played and kept: it goes to history', [CONSTRAINT]),
|
|
110
|
+
'verdict:keep': verdict('keep', 'Played and kept: it goes to history', [CONSTRAINT, PLAYED_ON]),
|
|
107
111
|
'verdict:tune': verdict('tune', 'Played; needs a change: back to ready with the note', [
|
|
108
112
|
{ key: 'note', label: 'What to change', kind: 'longtext', required: true },
|
|
109
113
|
]),
|
|
@@ -186,6 +190,27 @@ const ITEM_SPECS = {
|
|
|
186
190
|
fields: [MODEL, EFFORT],
|
|
187
191
|
rare: true,
|
|
188
192
|
},
|
|
193
|
+
gates: {
|
|
194
|
+
label: 'gates',
|
|
195
|
+
help:
|
|
196
|
+
"Its stops: skip (a verdict defers to its milestone's play, the agent decides a spike and " +
|
|
197
|
+
"assumes instead of asking), wait, or the project's gates",
|
|
198
|
+
args: ['gcf', 'item', 'gates', '{id}'],
|
|
199
|
+
fields: [
|
|
200
|
+
{
|
|
201
|
+
key: 'skip_gates',
|
|
202
|
+
flag: 'to',
|
|
203
|
+
label: 'Its gates',
|
|
204
|
+
kind: 'choice',
|
|
205
|
+
required: true,
|
|
206
|
+
options: [
|
|
207
|
+
{ value: 'project', label: "the project's gates" },
|
|
208
|
+
{ value: 'skip', label: 'skip: the agent goes on' },
|
|
209
|
+
{ value: 'wait', label: 'wait: they wait for you' },
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
189
214
|
mode: {
|
|
190
215
|
label: 'run mode',
|
|
191
216
|
help: 'Where its runs go: the project folder or a worktree of their own; the next run takes it',
|
|
@@ -670,6 +695,9 @@ const FIELDS = [
|
|
|
670
695
|
{ key: 'model', label: 'model', kind: 'text', card: true, edit: 'agent' },
|
|
671
696
|
{ key: 'effort', label: 'effort', kind: 'text', edit: 'agent' },
|
|
672
697
|
{ key: 'run_mode', label: 'run mode', kind: 'text', edit: 'mode' },
|
|
698
|
+
{ key: 'skip_gates', label: 'gates', kind: 'text', help: "Its card's gates", edit: 'gates' },
|
|
699
|
+
{ key: 'gate_why', label: 'why its own stop', kind: 'text' },
|
|
700
|
+
{ key: 'play_on', label: 'play on', kind: 'list', help: 'Where to play it: lines of platforms' },
|
|
673
701
|
{ key: 'tune_count', label: 'tune', kind: 'text', help: 'Tune verdicts so far', card: true },
|
|
674
702
|
{
|
|
675
703
|
key: 'waits_for',
|
package/lib/gates.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The stops that wait for the operator, per project (`gates:` of gcf/config.yml) and per card
|
|
2
|
+
// (`skip_gates:`) — docs/Autonomy-Plan.md, B. The one place the core reads the policy.
|
|
3
|
+
import { GATE_POLICY } from './gcf-paths.js';
|
|
4
|
+
|
|
5
|
+
const ITEM_GATES = ['verdict', 'decision', 'question'];
|
|
6
|
+
const SECOND = Object.fromEntries(ITEM_GATES.map((g) => [g, GATE_POLICY[g][1]]));
|
|
7
|
+
// A mechanic or a resource closes unplayed; the rest of a verdict's waits (Plan phase 2).
|
|
8
|
+
const DEFERRABLE = ['mechanic', 'resource'];
|
|
9
|
+
// What an agent may decide under `decision: agent`: its own question answered, never a release.
|
|
10
|
+
const AGENT_DECIDES = ['spike', 'decision'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The gates in force for `item` (its frontmatter): the project's, or every item gate on its
|
|
14
|
+
* second value (`skip_gates: true`) or on `wait` (`false`). `milestone` is the project's only.
|
|
15
|
+
* @param {{gates: Record<string, string>}} config readConfig's
|
|
16
|
+
* @param {Record<string, any> | null} [item]
|
|
17
|
+
*/
|
|
18
|
+
export function gatePolicy(config, item = null) {
|
|
19
|
+
const skip = item?.skip_gates;
|
|
20
|
+
if (typeof skip !== 'boolean') return { ...config.gates };
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
milestone: config.gates.milestone,
|
|
24
|
+
...Object.fromEntries(ITEM_GATES.map((g) => [g, skip ? SECOND[g] : 'wait'])),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether `item`'s submit closes it unplayed instead of waiting for a verdict: not one whose
|
|
30
|
+
* delta changes a capability (A4), which waits for the verdict all the same.
|
|
31
|
+
*/
|
|
32
|
+
export const verdictDeferred = (config, item) =>
|
|
33
|
+
item.gate === 'verdict' &&
|
|
34
|
+
DEFERRABLE.includes(item.type) &&
|
|
35
|
+
!(item.live?.changes ?? []).some((c) => c.change !== 'added') &&
|
|
36
|
+
gatePolicy(config, item).verdict === 'defer';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Why an agent may not `decide <choice>` on `item` (its frontmatter), or null: only under
|
|
40
|
+
* `decision: agent`, only go or no of a spike or a decision item waiting for its decision, with
|
|
41
|
+
* a reason; a child's no would pause its feature, so that stays the operator's.
|
|
42
|
+
*/
|
|
43
|
+
export function agentDecideProblem(config, item, choice, reason) {
|
|
44
|
+
const no = (why) => `decide is the operator's here: ${why}`;
|
|
45
|
+
if (gatePolicy(config, item).decision !== 'agent')
|
|
46
|
+
return no('gates.decision is wait (the operator sets agent, or skip_gates on the card)');
|
|
47
|
+
if (!AGENT_DECIDES.includes(item.type) || item.gate !== 'decision')
|
|
48
|
+
return no(`an agent decides only a spike or a decision item, ${item.id} is a ${item.type}`);
|
|
49
|
+
if (item.status !== 'awaiting-decision')
|
|
50
|
+
return no(`${item.id} is ${item.status}, not awaiting-decision: submit it first`);
|
|
51
|
+
if (!['go', 'no'].includes(choice)) return no('an agent decides go or no only');
|
|
52
|
+
if (choice === 'no' && item.parent)
|
|
53
|
+
return no(`${item.id} is a child of ${item.parent}: its death pauses the feature`);
|
|
54
|
+
if (!String(reason ?? '').trim()) return 'an agent decides with --reason "<why>"';
|
|
55
|
+
|
|
56
|
+
return null;
|
|
57
|
+
}
|
package/lib/gcf-paths.js
CHANGED
|
@@ -79,6 +79,37 @@ function chatOf(v = {}) {
|
|
|
79
79
|
return chat;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// The stops that wait for the operator (docs/Autonomy-Plan.md, B): each `wait`, as GCF always
|
|
83
|
+
// did, or its second value, which lets the agent go on. A release always waits.
|
|
84
|
+
export const GATE_POLICY = {
|
|
85
|
+
milestone: ['wait', 'go'],
|
|
86
|
+
verdict: ['wait', 'defer'],
|
|
87
|
+
decision: ['wait', 'agent'],
|
|
88
|
+
question: ['wait', 'assume'],
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function gatesOf(v = {}) {
|
|
92
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
93
|
+
throw new Error('gcf/config.yml: gates must be a key: value mapping');
|
|
94
|
+
const extra = Object.keys(v).find((k) => !(k in GATE_POLICY));
|
|
95
|
+
if (extra)
|
|
96
|
+
throw new Error(
|
|
97
|
+
`gcf/config.yml: gates.${extra} is not a gate (${Object.keys(GATE_POLICY).join(', ')})`,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return Object.fromEntries(
|
|
101
|
+
Object.entries(GATE_POLICY).map(([gate, values]) => {
|
|
102
|
+
const value = v[gate] ?? 'wait';
|
|
103
|
+
if (!values.includes(value))
|
|
104
|
+
throw new Error(
|
|
105
|
+
`gcf/config.yml: gates.${gate} must be ${values.join(' | ')}, got ${value}`,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return [gate, value];
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
82
113
|
/** @returns {Promise<Record<string, any>>} */
|
|
83
114
|
export async function readConfig(root) {
|
|
84
115
|
return configOf(await readRawConfig(root));
|
|
@@ -130,7 +161,12 @@ export function configOf(parsed) {
|
|
|
130
161
|
`(${handoff + 15}), or the compaction comes before the handoff`,
|
|
131
162
|
);
|
|
132
163
|
|
|
133
|
-
return {
|
|
164
|
+
return {
|
|
165
|
+
...config,
|
|
166
|
+
run_mode: runModeOf(config.run_mode),
|
|
167
|
+
chat: chatOf(config.chat),
|
|
168
|
+
gates: gatesOf(config.gates),
|
|
169
|
+
};
|
|
134
170
|
}
|
|
135
171
|
|
|
136
172
|
/** Token estimate: ceil(chars/4). Stability over accuracy (GCF-PRD §9.1). */
|
package/lib/git.js
CHANGED
|
@@ -51,24 +51,44 @@ export function dirtyPaths(projectDir, paths) {
|
|
|
51
51
|
return res.status === 0 ? res.stdout.split('\n').filter(Boolean) : [];
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const BY = ['run', 'session', 'operator'];
|
|
54
|
+
const BY = ['run', 'thread', 'session', 'operator'];
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Who makes a move: `GCF_MOVE_BY` when it names one (the harness sets `run` for both run modes
|
|
58
|
-
* else a harness run's owner, else a Claude Code session,
|
|
59
|
-
* session `GCF_MOVE_BY` cannot name the operator
|
|
60
|
-
*
|
|
61
|
-
*
|
|
57
|
+
* Who makes a move: `GCF_MOVE_BY` when it names one (the harness sets `run` for both run modes,
|
|
58
|
+
* the board `thread` for its threads), else a harness run's owner, else a Claude Code session,
|
|
59
|
+
* else the operator. Inside a run or a session `GCF_MOVE_BY` cannot name the operator, and
|
|
60
|
+
* inside a run (its owner, or the item a worktree session works) not a session either: an agent
|
|
61
|
+
* would claim the operator's moves.
|
|
62
|
+
* shortcut: an agent that unsets its own markers still passes for the operator, a thread's that
|
|
63
|
+
* names itself a session too; a trusted channel of who runs a command would close it.
|
|
62
64
|
*/
|
|
63
65
|
export function moveBy(env = process.env) {
|
|
66
|
+
const run = Boolean(env.GCF_RUN_OWNER || env.GCF_RUN_ITEM);
|
|
64
67
|
const agent = Boolean(env.GCF_RUN_OWNER || env.CLAUDE_CODE_SESSION_ID);
|
|
65
68
|
const named = env.GCF_MOVE_BY ?? '';
|
|
69
|
+
if (run && ['session', 'operator'].includes(named)) return 'run';
|
|
66
70
|
if (BY.includes(named) && !(agent && named === 'operator')) return named;
|
|
67
71
|
if (env.GCF_RUN_OWNER) return 'run';
|
|
68
72
|
|
|
69
73
|
return env.CLAUDE_CODE_SESSION_ID ? 'session' : 'operator';
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Refuse the operator's `move` made by a harness run or a board thread (docs/Autonomy-Plan.md,
|
|
78
|
+
* A). A console session passes: it is the operator's helper (gcf-verdict records the
|
|
79
|
+
* operator's verdict from it). The deny group `human-moves` refuses earlier; this holds a run
|
|
80
|
+
* started with `--agent`, which gets no deny rules.
|
|
81
|
+
* @param {string} move
|
|
82
|
+
*/
|
|
83
|
+
export function needOperator(move, env = process.env) {
|
|
84
|
+
const by = moveBy(env);
|
|
85
|
+
if (by !== 'run' && by !== 'thread') return;
|
|
86
|
+
throw new Error(
|
|
87
|
+
`${move} is the operator's: a ${by === 'run' ? 'harness run' : 'board thread'} does not ` +
|
|
88
|
+
'make it — block the item with the question, or propose the move to the operator',
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
72
92
|
/**
|
|
73
93
|
* The trailer paragraph of a move's commit as `git commit`/`git merge` arguments (`gcf item
|
|
74
94
|
* history` reads it): the items and units it touched, the domain's move key, who made it, and
|
package/lib/history.js
CHANGED
|
@@ -57,7 +57,7 @@ const trailer = (body, key) =>
|
|
|
57
57
|
.match(new RegExp(`^${key}: *(.*)$`, 'm'))?.[1]
|
|
58
58
|
.trim() ?? null;
|
|
59
59
|
|
|
60
|
-
const BY = ['run', 'session', 'operator'];
|
|
60
|
+
const BY = ['run', 'thread', 'session', 'operator'];
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* What one commit says of item `id`: `{move, by}` when it moved the item, else null. A commit
|
package/lib/integrate.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// branch is ready once its tip carries the trailer `GCF-Verified: <id>` — readiness lives in git,
|
|
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
|
-
import { appendFile, mkdir, readFile } from 'node:fs/promises';
|
|
5
|
+
import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
8
|
import path from 'node:path';
|
|
@@ -10,7 +10,9 @@ import { buildLedger } from './ledger.js';
|
|
|
10
10
|
import { parse } from './frontmatter.js';
|
|
11
11
|
import { withMainLock, runHolder, lockedItem, MAIN_RUN } from './main-lock.js';
|
|
12
12
|
import { verifyItem, deltaProblems } from './verify.js';
|
|
13
|
-
import { submitItem, closeItem, blockItem } from './work-ops.js';
|
|
13
|
+
import { submitItem, closeItem, blockItem, decideItem } from './work-ops.js';
|
|
14
|
+
import { readConfig } from './gcf-paths.js';
|
|
15
|
+
import { agentDecideProblem } from './gates.js';
|
|
14
16
|
import { isValidId } from './id.js';
|
|
15
17
|
import { writeIndex } from './index-gen.js';
|
|
16
18
|
import { moveTrailers } from './git.js';
|
|
@@ -227,23 +229,85 @@ function movedSinceMerge(projectDir, id) {
|
|
|
227
229
|
return after.some((s) => move.test(s));
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
/**
|
|
233
|
+
* What a worktree session left for main in its plan's `## Outcome` (docs/Autonomy-Plan.md, B):
|
|
234
|
+
* `decide: go|no` and `reason:` under `gates.decision: agent`, an `assume:` line per assumption
|
|
235
|
+
* it took. Lines may be bullets. Empty when the plan has none.
|
|
236
|
+
*/
|
|
237
|
+
export function planOutcome(text) {
|
|
238
|
+
const out = { decide: null, reason: '', assume: [] };
|
|
239
|
+
const at = String(text ?? '').search(/^## Outcome[ \t]*$/m);
|
|
240
|
+
if (at < 0) return out;
|
|
241
|
+
const block = text.slice(at).split(/\r?\n/).slice(1);
|
|
242
|
+
const end = block.findIndex((l) => /^#{1,2} /.test(l));
|
|
243
|
+
for (const line of end < 0 ? block : block.slice(0, end)) {
|
|
244
|
+
const m = line.match(/^\s*(?:[-*]\s+)?(decide|reason|assume):\s*(.*?)\s*$/);
|
|
245
|
+
if (!m || !m[2]) continue;
|
|
246
|
+
if (m[1] === 'assume') out.assume.push(m[2]);
|
|
247
|
+
else out[m[1]] = m[2];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const outcomeOfPlan = async (projectDir, item) => {
|
|
254
|
+
const plan = path.join(projectDir, item.data.plan ?? `.ai-factory/plans/${item.data.id}.md`);
|
|
255
|
+
|
|
256
|
+
return planOutcome(existsSync(plan) ? await readFile(plan, 'utf8') : '');
|
|
257
|
+
};
|
|
258
|
+
|
|
230
259
|
/**
|
|
231
260
|
* The move a merged item ends its run with. Its delta is checked against main first — the
|
|
232
|
-
* worktree's LIVE.md may be behind.
|
|
233
|
-
*
|
|
261
|
+
* worktree's LIVE.md may be behind. The assumptions of its plan's `## Outcome` go in the move's
|
|
262
|
+
* commit; its decision too, when the gates in force now let an agent decide: the submit
|
|
263
|
+
* without a commit, the decide with one, so the move is one commit and a crash before it leaves
|
|
264
|
+
* the item ready for the next integrate. A move the item refuses blocks it with the reason;
|
|
265
|
+
* when even the block fails, the error goes up and the next integrate records the move again.
|
|
234
266
|
*/
|
|
235
267
|
async function recordMove(projectDir, item) {
|
|
236
268
|
const { id, gate } = item.data;
|
|
237
269
|
const stale = await deltaProblems(projectDir, item);
|
|
238
270
|
try {
|
|
239
271
|
if (stale.length) throw new Error(stale.join('; '));
|
|
240
|
-
|
|
272
|
+
const { decide, reason, assume } = await outcomeOfPlan(projectDir, item);
|
|
273
|
+
if (gate === 'auto') {
|
|
274
|
+
const r = await closeItem(projectDir, id, { assume, dropOutcome: true });
|
|
275
|
+
|
|
276
|
+
// A4: a delta that changes a capability made the close a submit.
|
|
277
|
+
return { move: r.awaits ? 'submit' : 'close', ...r };
|
|
278
|
+
}
|
|
241
279
|
|
|
242
|
-
|
|
280
|
+
const config = await readConfig(path.join(path.resolve(projectDir), 'gcf'));
|
|
281
|
+
const waits = { ...item.data, status: 'awaiting-decision' };
|
|
282
|
+
if (decide && !agentDecideProblem(config, waits, decide, reason)) {
|
|
283
|
+
// The submit writes awaiting-decision with no commit: a decide that fails puts the file
|
|
284
|
+
// back as it was, ready, so the block below and the next integrate both find it there.
|
|
285
|
+
const before = await readFile(item.file, 'utf8');
|
|
286
|
+
try {
|
|
287
|
+
await submitItem(projectDir, id, { commit: false, dropOutcome: false });
|
|
288
|
+
const done = await decideItem(projectDir, id, decide, { reason, assume });
|
|
289
|
+
|
|
290
|
+
return { move: 'decide', ...done };
|
|
291
|
+
} catch (e) {
|
|
292
|
+
await writeFile(item.file, before);
|
|
293
|
+
throw e;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// A decision the gates do not give the agent rides in the submit's commit, for the human.
|
|
298
|
+
const said = decide ? `agent: ${decide}${reason ? ` — ${reason}` : ''}` : '';
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
move: 'submit',
|
|
302
|
+
...(await submitItem(projectDir, id, { assume, said, dropOutcome: true })),
|
|
303
|
+
};
|
|
243
304
|
} catch (e) {
|
|
244
305
|
const reason = `integrate: ${e.message}`;
|
|
245
306
|
|
|
246
|
-
|
|
307
|
+
// The block takes the Outcome out too: the rerun writes its own.
|
|
308
|
+
const blocked = await blockItem(projectDir, id, { reason, dropOutcome: true });
|
|
309
|
+
|
|
310
|
+
return { move: 'block', reason, ...blocked };
|
|
247
311
|
}
|
|
248
312
|
}
|
|
249
313
|
|