gcf-aif-ext 0.24.0 → 0.26.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/GLOSSARY.md +12 -0
- package/README.md +5 -2
- package/commands/gcf.js +202 -24
- package/extension.json +1 -1
- package/lib/agent-permissions.js +28 -2
- package/lib/board.js +35 -10
- package/lib/config-set.js +29 -0
- package/lib/domain.js +94 -0
- package/lib/integrate.js +12 -6
- package/lib/main-lock.js +24 -0
- package/lib/plan-check.js +117 -6
- package/lib/play.js +1022 -0
- package/lib/playtest-list.js +9 -12
- package/lib/safe-path.js +1 -1
- package/lib/transitions.js +8 -1
- package/lib/validate-item.js +26 -0
- package/lib/verify.js +7 -7
- package/lib/work-ops.js +85 -6
- package/package.json +1 -1
- package/schemas/item.schema.json +12 -0
- package/skills/gcf-adopt/SKILL.md +2 -1
- package/skills/gcf-chat/SKILL.md +6 -3
- package/skills/gcf-verdict/SKILL.md +4 -0
- package/templates/agents-block.md +17 -2
- package/templates/config.yml +19 -0
package/lib/domain.js
CHANGED
|
@@ -212,6 +212,37 @@ const ITEM_SPECS = {
|
|
|
212
212
|
},
|
|
213
213
|
],
|
|
214
214
|
},
|
|
215
|
+
// Planning that does not converge (Hold-Plan d16): the run's stall, the operator's two answers.
|
|
216
|
+
plan_stall: {
|
|
217
|
+
label: 'planning stall',
|
|
218
|
+
help: "The run's stop: the plan's passes keep finding blocking issues past plan_passes",
|
|
219
|
+
args: ['gcf', 'plan', 'stall', '{id}'],
|
|
220
|
+
fields: [
|
|
221
|
+
{ key: 'passes', label: 'Blocking findings of each pass', kind: 'text', required: true },
|
|
222
|
+
{ key: 'reason', label: 'Reason', kind: 'longtext' },
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
plan_more: {
|
|
226
|
+
label: 'more passes',
|
|
227
|
+
help: 'The plan improves N more passes, then the same check decides',
|
|
228
|
+
args: ['gcf', 'plan', 'more', '{id}'],
|
|
229
|
+
fields: [
|
|
230
|
+
{
|
|
231
|
+
key: 'passes',
|
|
232
|
+
label: 'More passes',
|
|
233
|
+
kind: 'choice',
|
|
234
|
+
required: true,
|
|
235
|
+
default: '2',
|
|
236
|
+
options: ['1', '2', '3', '5'].map((n) => ({ value: n, label: n })),
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
plan_accept: {
|
|
241
|
+
label: 'implement as is',
|
|
242
|
+
help: 'The plan goes to implementation as it is, its open findings with it',
|
|
243
|
+
args: ['gcf', 'plan', 'accept', '{id}'],
|
|
244
|
+
fields: [],
|
|
245
|
+
},
|
|
215
246
|
mode: {
|
|
216
247
|
label: 'run mode',
|
|
217
248
|
help: 'Where its runs go: the project folder or a worktree of their own; the next run takes it',
|
|
@@ -453,6 +484,15 @@ const DESIGN_EDITS = [
|
|
|
453
484
|
'gcf/INDEX.md',
|
|
454
485
|
'gcf/design/**',
|
|
455
486
|
];
|
|
487
|
+
// What the agent of a play start does: it never asks the human for the commands.
|
|
488
|
+
const PLAY_SAY =
|
|
489
|
+
'Set up how this game is played. Find in the project (AGENTS.md, its build and serve scripts) ' +
|
|
490
|
+
'the one command that builds the game into a folder of the project that git ignores, and the ' +
|
|
491
|
+
'command that starts it from that folder ({dir}) on a port ({port}); then call ' +
|
|
492
|
+
'propose_play_setup with them. Do not ask me for the commands. If the project has no such ' +
|
|
493
|
+
'command, or the folder is not ignored, propose a tech card with propose_item_new instead: one ' +
|
|
494
|
+
'command builds the game into an ignored folder, one starts it with the folder and a port, ' +
|
|
495
|
+
'AGENTS.md names both.';
|
|
456
496
|
const STARTS = {
|
|
457
497
|
vision: {
|
|
458
498
|
label: 'Create with agent',
|
|
@@ -555,6 +595,22 @@ const STARTS = {
|
|
|
555
595
|
say: 'Go through the TBDs of unit {unit} with me; take it into work only when I say so.',
|
|
556
596
|
edits: DESIGN_EDITS,
|
|
557
597
|
},
|
|
598
|
+
// How the game is played (docs/Play-Setup-Plan.md d18): the project knows its build and start
|
|
599
|
+
// commands, its agent finds them and proposes; the operator presses Make. No skill: the chat's.
|
|
600
|
+
// No edits: a build script is the project's code, it goes to a card of its own (d20).
|
|
601
|
+
'play-setup': {
|
|
602
|
+
label: 'Set up with agent',
|
|
603
|
+
help: 'The agent finds how this project builds its game into a folder and starts it',
|
|
604
|
+
say: PLAY_SAY,
|
|
605
|
+
edits: [],
|
|
606
|
+
},
|
|
607
|
+
'play-fix': {
|
|
608
|
+
label: 'Find again with agent',
|
|
609
|
+
help: 'The agent looks at the setup and its last failure again, and proposes a new one',
|
|
610
|
+
takes: 'text',
|
|
611
|
+
say: `${PLAY_SAY} The setup now and what went wrong: {text}`,
|
|
612
|
+
edits: [],
|
|
613
|
+
},
|
|
558
614
|
};
|
|
559
615
|
|
|
560
616
|
// The way from an empty project to its first work, in order: the board shows each step done or
|
|
@@ -702,6 +758,36 @@ const BLOCK_SPECS = {
|
|
|
702
758
|
args: ['gcf', 'inbox', 'later', '{id}', '--off', '--commit'],
|
|
703
759
|
fields: [],
|
|
704
760
|
},
|
|
761
|
+
// A chat's button to play: the board opens what it starts (docs/Play-Plan.md d17).
|
|
762
|
+
play: {
|
|
763
|
+
label: 'play',
|
|
764
|
+
help: "Start the card's own build on a target; its verdict stops it",
|
|
765
|
+
args: ['gcf', 'playtest', 'start', '{id}', '--json'],
|
|
766
|
+
fields: [text('target', 'Where to play', { required: true })],
|
|
767
|
+
propose: true,
|
|
768
|
+
},
|
|
769
|
+
// The checkout as it is, hand edits too (d30): built when its code has no snapshot, then started.
|
|
770
|
+
'play-main': {
|
|
771
|
+
label: 'play main',
|
|
772
|
+
help: 'Build the checkout as it is, uncommitted edits too, and start it on a target',
|
|
773
|
+
args: ['gcf', 'playtest', 'start', '--main', '--json'],
|
|
774
|
+
fields: [text('target', 'Where to play', { required: true })],
|
|
775
|
+
propose: true,
|
|
776
|
+
},
|
|
777
|
+
'play-setup': {
|
|
778
|
+
label: 'set up play',
|
|
779
|
+
help: 'How this project builds and starts its game: cards on the same code share one build',
|
|
780
|
+
args: ['gcf', 'playtest', 'setup'],
|
|
781
|
+
fields: [
|
|
782
|
+
text('build', 'Build command'),
|
|
783
|
+
text('output', 'Folder it builds to: inside the project, ignored by git'),
|
|
784
|
+
text('target', 'Target name'),
|
|
785
|
+
text('start', 'Start command: {dir} the build, {port} a free port, {lan} this machine'),
|
|
786
|
+
text('open', 'What to open: a URL or words'),
|
|
787
|
+
text('stop', 'Command after the player stops'),
|
|
788
|
+
],
|
|
789
|
+
propose: true,
|
|
790
|
+
},
|
|
705
791
|
'question-answer': {
|
|
706
792
|
label: 'answer',
|
|
707
793
|
help: 'The answer goes into the record; the next agent on its units puts it in place',
|
|
@@ -900,6 +986,10 @@ const CHANGES = [
|
|
|
900
986
|
'decide',
|
|
901
987
|
'block',
|
|
902
988
|
'unblock',
|
|
989
|
+
'plan pass',
|
|
990
|
+
'plan stall',
|
|
991
|
+
'plan more',
|
|
992
|
+
'plan accept',
|
|
903
993
|
'inbox add',
|
|
904
994
|
'inbox category',
|
|
905
995
|
'inbox later',
|
|
@@ -913,6 +1003,10 @@ const CHANGES = [
|
|
|
913
1003
|
'phase next',
|
|
914
1004
|
'hooks-install',
|
|
915
1005
|
'pillar',
|
|
1006
|
+
'playtest build',
|
|
1007
|
+
'playtest start',
|
|
1008
|
+
'playtest stop',
|
|
1009
|
+
'playtest setup',
|
|
916
1010
|
];
|
|
917
1011
|
|
|
918
1012
|
// The project chat of a GCF project (AD-5, AD-6): its skill, and the commands it asks for.
|
package/lib/integrate.js
CHANGED
|
@@ -497,14 +497,20 @@ export async function integrate(projectDir, ids = []) {
|
|
|
497
497
|
throw new Error(`integrate runs in the main checkout on its branch, not on ${branch}`);
|
|
498
498
|
// The session of the item that run works now merges as before (gcf-run's step 1): it works the
|
|
499
499
|
// checkout itself. A worktree session of the same harness inherits its owner, not that item.
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
500
|
+
const refuseBusy = () => {
|
|
501
|
+
const main = runHolder(projectDir, MAIN_RUN);
|
|
502
|
+
const own =
|
|
503
|
+
process.env.GCF_RUN_OWNER === `run:${main}` &&
|
|
504
|
+
Boolean(process.env.GCF_RUN_ITEM) &&
|
|
505
|
+
process.env.GCF_RUN_ITEM === lockedItem(projectDir, MAIN_RUN);
|
|
506
|
+
if (main && !own) throw new Error(`${MAIN_BUSY} (pid ${main}): integrate after it ends`);
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
refuseBusy();
|
|
506
510
|
|
|
507
511
|
return withMainLock(projectDir, async () => {
|
|
512
|
+
// Again: the checkout may have been taken while this waited for the lock.
|
|
513
|
+
refuseBusy();
|
|
508
514
|
// The run logs go in at every integrate, a main-mode run's first one too: nothing else
|
|
509
515
|
// commits them there. Nothing to merge leaves the rest of main alone: a run's first
|
|
510
516
|
// integrate must not refuse a dirty tree.
|
package/lib/main-lock.js
CHANGED
|
@@ -31,6 +31,30 @@ export const alive = (pid) => {
|
|
|
31
31
|
*/
|
|
32
32
|
export const MAIN_RUN = '.main-run';
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Take the main checkout's run lock for work that is no run (a build by click): a main run refuses
|
|
36
|
+
* to start and `integrate` leaves its branches, as under a run. The second line is a token, no
|
|
37
|
+
* item: no card reads as run by it. The release, or null while a live run holds the checkout.
|
|
38
|
+
*/
|
|
39
|
+
export async function claimMainRun(projectDir) {
|
|
40
|
+
const file = path.join(path.resolve(projectDir), '.gcf-session', 'runs', `${MAIN_RUN}.lock`);
|
|
41
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
42
|
+
const token = randomUUID();
|
|
43
|
+
for (let tries = 0; tries < 3; tries++) {
|
|
44
|
+
if (await take(file, token))
|
|
45
|
+
return async () => {
|
|
46
|
+
if ((await readFile(file, 'utf8').catch(() => '')).includes(token))
|
|
47
|
+
await unlink(file).catch(() => {});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const dead = await staleText(file);
|
|
51
|
+
if (dead === null) return null;
|
|
52
|
+
await clearStale(file, dead);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
34
58
|
/** The item a run lock names on its second line (a main run's: what it works now), or null. */
|
|
35
59
|
export function lockedItem(projectDir, id) {
|
|
36
60
|
try {
|
package/lib/plan-check.js
CHANGED
|
@@ -3,13 +3,74 @@
|
|
|
3
3
|
// Whether the plan is any good is the improve passes' job; this only says it is usable. Its
|
|
4
4
|
// form against the `plan` profile (CNL-P: blocks, one idea a line, no fact twice) is reported
|
|
5
5
|
// as `format` lines, never a problem: a long line must not cost the item its paid passes.
|
|
6
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { bodyIssues } from 'cnlp-kit';
|
|
9
9
|
import { glossaryAvoids, GLOSSARY_NAME } from 'cnlp-kit/config';
|
|
10
10
|
import { buildLedger } from './ledger.js';
|
|
11
11
|
import { buildContext } from './context.js';
|
|
12
12
|
import { loadDocProfile } from './design.js';
|
|
13
|
+
import { readConfig } from './gcf-paths.js';
|
|
14
|
+
|
|
15
|
+
// A pass of the plan's improve loop (Hold-Plan d12): `- pass K[ (cycle C)]: blocking N, polish M[,
|
|
16
|
+
// by codex]`, one line each in its `## Passes` section, written by `gcf plan pass`.
|
|
17
|
+
const PASS_LINE =
|
|
18
|
+
/^- pass (\d+)(?: \(cycle (\d+)\))?: blocking (\d+), polish (\d+)(?:, by (\w+))?$/;
|
|
19
|
+
const PASSES = /^## Passes\s*$/;
|
|
20
|
+
const PASSES_ANY = /^## Passes\s*$/m;
|
|
21
|
+
|
|
22
|
+
/** The passes a plan's `## Passes` section records, of every cycle, in order. */
|
|
23
|
+
export function planPasses(text) {
|
|
24
|
+
const out = [];
|
|
25
|
+
let inside = false;
|
|
26
|
+
for (const line of text.split(/\r?\n/)) {
|
|
27
|
+
if (/^## /.test(line)) inside = PASSES.test(line);
|
|
28
|
+
const m = inside ? PASS_LINE.exec(line.trim()) : null;
|
|
29
|
+
if (!m) continue;
|
|
30
|
+
const by = m[5] ? { by: m[5] } : {};
|
|
31
|
+
out.push({ pass: +m[1], cycle: +(m[2] ?? 0), blocking: +m[3], polish: +m[4], ...by });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The verdict on one cycle's passes (Hold-Plan d12): `converged` when the last found nothing
|
|
39
|
+
* blocking; `continue` while the count is within `plan_passes` (raised by the operator's `more`);
|
|
40
|
+
* `stalled` past it: one technical pass over the limit, then the operator decides.
|
|
41
|
+
*/
|
|
42
|
+
export function passVerdict(passes, planPasses, more = 0) {
|
|
43
|
+
if (planPasses === 0) return 'converged';
|
|
44
|
+
const last = passes.at(-1);
|
|
45
|
+
if (!last) return 'continue';
|
|
46
|
+
if (last.blocking === 0) return 'converged';
|
|
47
|
+
|
|
48
|
+
return passes.length > planPasses + more ? 'stalled' : 'continue';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Where the item's planning stands: the passes of its current cycle (`plan_cycle`), and the
|
|
53
|
+
* verdict on them. The operator's `stall.accepted` converges it; a plan written before this
|
|
54
|
+
* version (no `plan_cycle`, no `## Passes`, a task ticked) counts as converged: work in flight
|
|
55
|
+
* does not stop at an upgrade.
|
|
56
|
+
*/
|
|
57
|
+
async function passesOf(projectDir, data, text, done) {
|
|
58
|
+
const cycle = Number(data.plan_cycle ?? 0);
|
|
59
|
+
const passes = planPasses(text).filter((x) => x.cycle === cycle);
|
|
60
|
+
const stall = data.stall ?? null;
|
|
61
|
+
let limit = 3;
|
|
62
|
+
try {
|
|
63
|
+
limit = Number((await readConfig(path.join(path.resolve(projectDir), 'gcf'))).plan_passes);
|
|
64
|
+
} catch {
|
|
65
|
+
// A broken config.yml: the default limit; the config's own check says what is wrong.
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const legacy = data.plan_cycle === undefined && !PASSES_ANY.test(text) && done > 0;
|
|
69
|
+
const verdict =
|
|
70
|
+
stall?.accepted || legacy ? 'converged' : passVerdict(passes, limit, Number(stall?.more ?? 0));
|
|
71
|
+
|
|
72
|
+
return { cycle, passes, verdict };
|
|
73
|
+
}
|
|
13
74
|
|
|
14
75
|
/**
|
|
15
76
|
* An item's plan and its task checkboxes: `{plan, tasks, done}`, `tasks` null when there is no
|
|
@@ -81,10 +142,60 @@ export async function planCheck(projectDir, id) {
|
|
|
81
142
|
const ctx = await buildContext(projectDir, id);
|
|
82
143
|
if (ctx.over_budget)
|
|
83
144
|
problems.push(`readset ~${ctx.total_tokens_est} tokens is over the budget ${ctx.budget}`);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
145
|
+
const text = found === null ? '' : readFileSync(path.resolve(projectDir, plan), 'utf8');
|
|
146
|
+
const format = found === null ? [] : await planFormat(projectDir, text);
|
|
147
|
+
const { cycle, passes, verdict } = await passesOf(projectDir, item.data, text, done);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
...{ id, plan, tasks, done, problems, format, ok: problems.length === 0 },
|
|
151
|
+
...{ cycle, passes, converged: verdict === 'converged', stalled: verdict === 'stalled' },
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* `gcf plan pass` (Hold-Plan d12): record pass K of the current cycle in the plan's `## Passes`
|
|
157
|
+
* section, K the next number, and answer the verdict on the cycle's passes so far.
|
|
158
|
+
* @param {string} projectDir
|
|
159
|
+
* @param {string} id
|
|
160
|
+
* @param {{blocking: number, polish: number, by?: string}} pass
|
|
161
|
+
*/
|
|
162
|
+
export async function recordPass(projectDir, id, { blocking, polish, by }) {
|
|
163
|
+
passArgs(blocking, polish, by);
|
|
164
|
+
const item = (await buildLedger(projectDir)).item(id);
|
|
165
|
+
if (!item) throw new Error(`${id} is not a work item of gcf/work/`);
|
|
166
|
+
const { plan } = planTicks(projectDir, { ...item.data, id });
|
|
167
|
+
const file = path.resolve(projectDir, plan);
|
|
168
|
+
if (!existsSync(file)) throw new Error(`no plan at ${plan}: write it first`);
|
|
169
|
+
const text = readFileSync(file, 'utf8');
|
|
170
|
+
const cycle = Number(item.data.plan_cycle ?? 0);
|
|
171
|
+
const k = planPasses(text).filter((x) => x.cycle === cycle).length + 1;
|
|
172
|
+
const tag = cycle ? ` (cycle ${cycle})` : '';
|
|
173
|
+
const line = `- pass ${k}${tag}: blocking ${blocking}, polish ${polish}${by ? `, by ${by}` : ''}`;
|
|
174
|
+
writeFileSync(file, withPass(text, line));
|
|
175
|
+
const r = await planCheck(projectDir, id);
|
|
176
|
+
const verdict = r.converged ? 'converged' : r.stalled ? 'stalled' : 'continue';
|
|
177
|
+
|
|
178
|
+
return { id, pass: k, cycle, verdict, passes: r.passes.map((x) => x.blocking) };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The refusal of a pass's counts and reviewer, if any. */
|
|
182
|
+
function passArgs(blocking, polish, by) {
|
|
183
|
+
for (const [k, v] of Object.entries({ blocking, polish }))
|
|
184
|
+
if (!Number.isInteger(v) || v < 0) throw new Error(`--${k} is a count of findings, 0 or more`);
|
|
185
|
+
if (by !== undefined && !/^\w+$/.test(by)) throw new Error('--by is one word: the reviewer');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The plan with `line` at the end of its `## Passes` section, the section added when none. */
|
|
189
|
+
function withPass(text, line) {
|
|
190
|
+
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
191
|
+
const lines = text.split(/\r?\n/);
|
|
192
|
+
const at = lines.findIndex((l) => PASSES.test(l));
|
|
193
|
+
if (at < 0) return `${text.replace(/\s*$/, '')}${eol}${eol}## Passes${eol}${eol}${line}${eol}`;
|
|
194
|
+
let end = lines.findIndex((l, n) => n > at && /^## /.test(l));
|
|
195
|
+
if (end < 0) end = lines.length;
|
|
196
|
+
// After the section's last line with words: its blank lines stay below it.
|
|
197
|
+
while (end > at + 1 && !lines[end - 1].trim()) end--;
|
|
198
|
+
lines.splice(end, 0, line);
|
|
88
199
|
|
|
89
|
-
return
|
|
200
|
+
return lines.join(eol);
|
|
90
201
|
}
|