gcf-aif-ext 0.7.9 → 0.7.10
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 +9 -0
- package/commands/gcf.js +62 -2
- package/extension.json +1 -1
- package/lib/board.js +6 -1
- package/lib/config-set.js +5 -0
- package/lib/gcf-paths.js +3 -1
- package/lib/inbox.js +13 -3
- package/lib/lessons.js +131 -0
- package/lib/playtest-list.js +16 -2
- package/lib/verify.js +118 -9
- package/lib/work-ops.js +2 -0
- package/package.json +1 -1
- package/skills/gcf-triage/SKILL.md +8 -7
- package/templates/config.yml +12 -1
package/README.md
CHANGED
|
@@ -50,6 +50,15 @@ Updating preserves `gcf/`, `cnlp.config.json` and the pre-commit hook. Run `ai-f
|
|
|
50
50
|
|
|
51
51
|
On Windows, run `extension add` and `extension update` from PowerShell or cmd, not Git Bash: the installer unpacks with `tar`, and Git Bash's GNU tar reads `C:\…` as a remote host (`Cannot connect to C: resolve failed`). The Windows `tar.exe` handles it.
|
|
52
52
|
|
|
53
|
+
### 0.7.10
|
|
54
|
+
|
|
55
|
+
- Lessons: what got in an agent's way, asked at the end of its session (Methodology §5.2.2). `gcf lessons prompt <id>` prints the questions: tools and their workarounds, project rules that are missing or conflict, trouble with GCF itself, and, with `lessons.template` in `gcf/config.yml`, what the project's template should learn; `lessons.questions` adds the operator's own, `lessons.off: true` turns them off. `gcf lessons add <id>` records each answer as an inbox entry with the source `lesson:<kind>:<item>`; `gcf board --json` gives such an entry `source: lesson`, `kind` and `item`, and each item its `lessons` count. The harness 0.9.2 asks them in a turn of its own after each session, so they stay out of the agent's working context; `/gcf-run` without the harness asks them at its end. `/gcf-triage` proposes a fix for each.
|
|
56
|
+
|
|
57
|
+
- `gcf verify` kills a `dod.test` or `dod.build` command that runs longer than `dod_timeout_min` minutes (60 by default, 0 for no limit), with every process it started, and fails the DoD: `dod.test timed out after 60 min (dod_timeout_min), killed: <command>`. Before, a hung engine held the check, and a run with it, for hours.
|
|
58
|
+
- `gcf prioritize` takes an item made with `gcf item new` and never committed, and commits it with its rank. Before, it refused the item as an uncommitted file. An item with uncommitted edits is still refused.
|
|
59
|
+
- `gcf playtest session` lists the items awaiting a decision in a section of their own: before, they were missing from the sheet.
|
|
60
|
+
- `plan_passes` defaults to 3 (was 5). A plan converges when an improve pass finds nothing blocking (Methodology §5.2.1); a project that sets `plan_passes` keeps its value.
|
|
61
|
+
|
|
53
62
|
### 0.7.9
|
|
54
63
|
|
|
55
64
|
- `gcf done`, `gcf drop` (a design unit), `gcf pillar rename|retire`, `gcf phase next` and `gcf question answer` hold the main lock from their first read to their commit, as the work item moves do. Before, two at once could both pass their checks and write over each other: an answer lost, a unit in the history twice.
|
package/commands/gcf.js
CHANGED
|
@@ -308,7 +308,16 @@ function sessionHead(s) {
|
|
|
308
308
|
/** The session sheet: the build, then per item what to check and how to get there. */
|
|
309
309
|
function sessionText(s) {
|
|
310
310
|
const lines = sessionHead(s);
|
|
311
|
-
|
|
311
|
+
const decide = s.decisions.length
|
|
312
|
+
? [
|
|
313
|
+
'',
|
|
314
|
+
'## decide: no verdict, a go or a no; play it first where the build shows it',
|
|
315
|
+
...s.decisions.map(
|
|
316
|
+
(d) => `[ ] ${d.id} [${d.system.join(',')}] ${d.title ?? d.intent ?? ''}`,
|
|
317
|
+
),
|
|
318
|
+
]
|
|
319
|
+
: [];
|
|
320
|
+
if (!s.items.length) return [...lines, 'nothing waits for a playtest', ...decide].join('\n');
|
|
312
321
|
let group = null;
|
|
313
322
|
// Items come sorted by their first subsystem: one header each, so play goes system by system.
|
|
314
323
|
for (const c of s.items) {
|
|
@@ -326,8 +335,10 @@ function sessionText(s) {
|
|
|
326
335
|
|
|
327
336
|
return [
|
|
328
337
|
...lines,
|
|
338
|
+
...decide,
|
|
329
339
|
'',
|
|
330
340
|
'after play: a verdict per item — /gcf-verdict <id> keep|tune|kill;',
|
|
341
|
+
...(s.decisions.length ? ['a decision — /gcf-verdict <id> go|no;'] : []),
|
|
331
342
|
'free notes — ai-factory gcf inbox add --source playtest "<note>"',
|
|
332
343
|
].join('\n');
|
|
333
344
|
}
|
|
@@ -846,7 +857,15 @@ function registerInbox(gcf) {
|
|
|
846
857
|
const { gcfRoot } = await lib('gcf-paths');
|
|
847
858
|
const list = await (await lib('inbox')).listInbox(gcfRoot());
|
|
848
859
|
out(o.json, list, (l) =>
|
|
849
|
-
l.length
|
|
860
|
+
l.length
|
|
861
|
+
? l
|
|
862
|
+
.map((e) => {
|
|
863
|
+
const source = e.kind ? `lesson:${e.kind}:${e.item}` : e.source;
|
|
864
|
+
|
|
865
|
+
return `${e.id} [${source}] ${e.text}`;
|
|
866
|
+
})
|
|
867
|
+
.join('\n')
|
|
868
|
+
: 'inbox empty',
|
|
850
869
|
);
|
|
851
870
|
});
|
|
852
871
|
inbox
|
|
@@ -881,6 +900,46 @@ function registerInbox(gcf) {
|
|
|
881
900
|
});
|
|
882
901
|
}
|
|
883
902
|
|
|
903
|
+
function registerLessons(gcf) {
|
|
904
|
+
const lessons = gcf
|
|
905
|
+
.command('lessons')
|
|
906
|
+
.description("What got in an agent's way, asked at the end of its session (into the inbox)");
|
|
907
|
+
lessons
|
|
908
|
+
.command('prompt <id>')
|
|
909
|
+
.description('Print the end-of-session questions for the agent that worked item <id>')
|
|
910
|
+
.option('--json', 'machine output: {off, prompt}, the prompt asking for a JSON reply')
|
|
911
|
+
.action(async (id, o) => {
|
|
912
|
+
const r = await (
|
|
913
|
+
await lib('lessons')
|
|
914
|
+
).lessonsPrompt(process.cwd(), id, { reply: o.json ? 'json' : 'cli' });
|
|
915
|
+
out(o.json, r, (p) => (p.off ? 'lessons are off (gcf/config.yml lessons.off)' : p.prompt));
|
|
916
|
+
});
|
|
917
|
+
lessons
|
|
918
|
+
.command('add <id>')
|
|
919
|
+
.description('Record lessons of item <id> as inbox entries')
|
|
920
|
+
.option('--kind <kind>', 'tool | rules | framework | template | other')
|
|
921
|
+
.option('--text <text>', 'one finding')
|
|
922
|
+
.option('--where <place>', 'file:line it is about')
|
|
923
|
+
.option('--from <file>', 'a JSON array [{kind, text, where}] instead of --kind/--text')
|
|
924
|
+
.option('--commit', 'commit it (gcf(lessons)): for a caller with no console, e.g. the harness')
|
|
925
|
+
.action(async (id, o) => {
|
|
926
|
+
const { addLessons, lessonsFile, KINDS } = await lib('lessons');
|
|
927
|
+
if (Boolean(o.from) === Boolean(o.text))
|
|
928
|
+
throw new Error('give the lessons once: --from <file>, or --kind and --text');
|
|
929
|
+
if (o.text && !KINDS.includes(o.kind)) throw new Error(`--kind must be ${KINDS.join(' | ')}`);
|
|
930
|
+
const list = o.from
|
|
931
|
+
? await lessonsFile(o.from)
|
|
932
|
+
: [{ kind: o.kind, text: o.text, where: o.where }];
|
|
933
|
+
if (!Array.isArray(list)) throw new Error(`${o.from}: lessons must be a JSON array`);
|
|
934
|
+
if (!list.length) return console.log(`recorded 0 lessons for ${id}`);
|
|
935
|
+
let n = 0;
|
|
936
|
+
const hash = await inboxMove(o.commit, `gcf(lessons): ${id}`, async (root) => {
|
|
937
|
+
n = (await addLessons(root, id, list)).length;
|
|
938
|
+
});
|
|
939
|
+
console.log(`recorded ${n} lessons for ${id}${shortHash(hash)}`);
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
|
|
884
943
|
function registerLive(gcf) {
|
|
885
944
|
const live = gcf
|
|
886
945
|
.command('live')
|
|
@@ -1188,6 +1247,7 @@ export function register(program) {
|
|
|
1188
1247
|
registerSession(gcf);
|
|
1189
1248
|
registerDecide(gcf);
|
|
1190
1249
|
registerInbox(gcf);
|
|
1250
|
+
registerLessons(gcf);
|
|
1191
1251
|
registerLive(gcf);
|
|
1192
1252
|
registerPlan(gcf);
|
|
1193
1253
|
registerVerify(gcf);
|
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-aif-ext",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.10",
|
|
5
5
|
"description": "Game Context Framework for AI Factory",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/gcf-init",
|
package/lib/board.js
CHANGED
|
@@ -213,6 +213,8 @@ async function itemOf(projectDir, c, verified) {
|
|
|
213
213
|
moves: running ? [] : movesOf(c.data),
|
|
214
214
|
file: `gcf/work/${c.name}`,
|
|
215
215
|
log: logOf(projectDir, id),
|
|
216
|
+
// Filled by board() from the inbox.
|
|
217
|
+
lessons: 0,
|
|
216
218
|
...(await progress(projectDir, c)),
|
|
217
219
|
};
|
|
218
220
|
}
|
|
@@ -224,6 +226,9 @@ export async function board(projectDir) {
|
|
|
224
226
|
const items = [];
|
|
225
227
|
for (const c of ledger.items) items.push(await itemOf(projectDir, c, verified));
|
|
226
228
|
inRunOrder(items);
|
|
229
|
+
const inbox = await listInbox(root);
|
|
230
|
+
// Where agents struggle: the lessons in the inbox each item's sessions left.
|
|
231
|
+
for (const i of items) i.lessons = inbox.filter((e) => e.item === i.id).length;
|
|
227
232
|
|
|
228
233
|
const config = await readConfig(root);
|
|
229
234
|
const live = await readLive(root);
|
|
@@ -248,7 +253,7 @@ export async function board(projectDir) {
|
|
|
248
253
|
),
|
|
249
254
|
items,
|
|
250
255
|
wip: wipOf(ledger.items, config),
|
|
251
|
-
inbox
|
|
256
|
+
inbox,
|
|
252
257
|
questions: await listQuestions(root),
|
|
253
258
|
history: await historyOf(root),
|
|
254
259
|
graveyard: await graveyardOf(root),
|
package/lib/config-set.js
CHANGED
|
@@ -50,6 +50,11 @@ export const SETTINGS = [
|
|
|
50
50
|
label: 'improve passes a plan may take before the item blocks',
|
|
51
51
|
},
|
|
52
52
|
{ key: 'dod_attempts', kind: 'number', label: 'DoD attempts before the item blocks' },
|
|
53
|
+
{
|
|
54
|
+
key: 'dod_timeout_min',
|
|
55
|
+
kind: 'number',
|
|
56
|
+
label: 'minutes a DoD command may take before it is killed (0: no limit)',
|
|
57
|
+
},
|
|
53
58
|
{
|
|
54
59
|
key: 'wip_built_limit',
|
|
55
60
|
kind: 'number',
|
package/lib/gcf-paths.js
CHANGED
|
@@ -14,8 +14,10 @@ export const DEFAULT_CONFIG = {
|
|
|
14
14
|
pillars_budget: 1500,
|
|
15
15
|
envelope_default_spread: 0.3,
|
|
16
16
|
unplayed_warn_after: 5,
|
|
17
|
-
plan_passes:
|
|
17
|
+
plan_passes: 3,
|
|
18
18
|
dod_attempts: 2,
|
|
19
|
+
// Minutes a dod.test or dod.build command may take before it is killed (0: no limit).
|
|
20
|
+
dod_timeout_min: 60,
|
|
19
21
|
// A run hands its item to a fresh session at this share of the context window (0: never);
|
|
20
22
|
// the window comes from the model unless context_window sets it (Harness-PRD §7).
|
|
21
23
|
context_handoff_pct: 60,
|
package/lib/inbox.js
CHANGED
|
@@ -12,18 +12,27 @@ export const INBOX_HEAD =
|
|
|
12
12
|
'is erased\n';
|
|
13
13
|
export const SOURCES = ['playtest', 'ci', 'agent', 'operator'];
|
|
14
14
|
const LINE = /^- (in-[0-9a-f]+) \| (\S+) \| (.+)$/;
|
|
15
|
+
// An agent's lesson (lessons.js): `lesson:<kind>:<item-id>`.
|
|
16
|
+
const LESSON = /^lesson:([a-z]+):([a-z0-9][a-z0-9-]*)$/;
|
|
15
17
|
|
|
16
18
|
const inboxFile = (root) => path.join(root, 'inbox.md');
|
|
17
19
|
|
|
18
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Every entry; a lesson reads as source `lesson` with its `kind` and the `item` it came from.
|
|
22
|
+
* @typedef {{id: string, source: string, text: string, kind?: string, item?: string}} Entry
|
|
23
|
+
* @returns {Promise<Entry[]>}
|
|
24
|
+
*/
|
|
19
25
|
export async function listInbox(root) {
|
|
20
26
|
const file = inboxFile(root);
|
|
21
27
|
if (!existsSync(file)) return [];
|
|
22
28
|
|
|
23
29
|
return (await readFile(file, 'utf8')).split(/\r?\n/).flatMap((l) => {
|
|
24
30
|
const m = l.match(LINE);
|
|
31
|
+
if (!m) return [];
|
|
32
|
+
const lesson = m[2].match(LESSON);
|
|
33
|
+
const entry = { id: m[1], source: m[2], text: m[3].trim() };
|
|
25
34
|
|
|
26
|
-
return
|
|
35
|
+
return [lesson ? { ...entry, source: 'lesson', kind: lesson[1], item: lesson[2] } : entry];
|
|
27
36
|
});
|
|
28
37
|
}
|
|
29
38
|
|
|
@@ -31,7 +40,8 @@ export async function listInbox(root) {
|
|
|
31
40
|
export async function addInbox(root, text, source = 'operator', now = new Date().toISOString()) {
|
|
32
41
|
const clean = String(text).replace(/\s+/g, ' ').trim();
|
|
33
42
|
if (!clean) throw new Error('an inbox entry needs text');
|
|
34
|
-
if (!SOURCES.includes(source)
|
|
43
|
+
if (!SOURCES.includes(source) && !LESSON.test(source))
|
|
44
|
+
throw new Error(`source must be ${SOURCES.join(' | ')}`);
|
|
35
45
|
const id = `in-${createHash('sha1').update(`${now}\n${clean}`).digest('hex').slice(0, 8)}`;
|
|
36
46
|
const file = inboxFile(root);
|
|
37
47
|
const old = existsSync(file) ? await readFile(file, 'utf8') : INBOX_HEAD;
|
package/lib/lessons.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Lessons (Methodology §5.2.2): at the end of a session on a work item, its agent says what got in
|
|
2
|
+
// its way — a tool, a rule, the framework, the project's template. Each answer is an inbox entry
|
|
3
|
+
// with the source `lesson:<kind>:<item>`, so the operator triages it like any raw input and the
|
|
4
|
+
// board shows where agents struggle. The questions stay out of the agent's working context until
|
|
5
|
+
// the session ends: the harness asks them in one more turn, `/gcf-run` asks them at its close.
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { readRawConfig } from './gcf-paths.js';
|
|
9
|
+
import { addInbox } from './inbox.js';
|
|
10
|
+
import { isValidId } from './id.js';
|
|
11
|
+
|
|
12
|
+
export const KINDS = ['tool', 'rules', 'framework', 'template', 'other'];
|
|
13
|
+
|
|
14
|
+
const QUESTIONS = {
|
|
15
|
+
tool:
|
|
16
|
+
'a tool, the editor or the environment behaved wrongly or cost time: what happened, and ' +
|
|
17
|
+
'what was the workaround?',
|
|
18
|
+
rules:
|
|
19
|
+
'a project rule was missing, unclear or contradicted another: name the file and line of ' +
|
|
20
|
+
'each, and what the rule should say',
|
|
21
|
+
framework:
|
|
22
|
+
'GCF got in the way: ai-factory gcf, the gcf-run steps, the harness or its hooks - what ' +
|
|
23
|
+
'cost time, and what would have helped?',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The project's lessons settings from the `lessons:` section of gcf/config.yml: `off`, the
|
|
28
|
+
* project `template` the lessons may feed, and `questions` the operator adds. Throws on a
|
|
29
|
+
* section of the wrong shape.
|
|
30
|
+
*/
|
|
31
|
+
export function lessonsConfig(raw) {
|
|
32
|
+
const l = raw?.lessons ?? {};
|
|
33
|
+
if (typeof l !== 'object' || Array.isArray(l))
|
|
34
|
+
throw new Error('gcf/config.yml: lessons must map off:, template: and questions:');
|
|
35
|
+
const questions = l.questions ?? [];
|
|
36
|
+
if (!Array.isArray(questions) || questions.some((q) => typeof q !== 'string' || !q.trim()))
|
|
37
|
+
throw new Error('gcf/config.yml: lessons.questions must be a list of questions');
|
|
38
|
+
if (l.template != null && typeof l.template !== 'string')
|
|
39
|
+
throw new Error('gcf/config.yml: lessons.template must be a path');
|
|
40
|
+
|
|
41
|
+
return { off: l.off === true, template: l.template?.trim() || null, questions };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The questions the agent answers, each with the kind its answer records as. */
|
|
45
|
+
function questionsOf(config) {
|
|
46
|
+
return [
|
|
47
|
+
...Object.entries(QUESTIONS).map(([kind, text]) => ({ kind, text })),
|
|
48
|
+
...(config.template
|
|
49
|
+
? [
|
|
50
|
+
{
|
|
51
|
+
kind: 'template',
|
|
52
|
+
text:
|
|
53
|
+
`what would the next project made from the template ${config.template} need ` +
|
|
54
|
+
'that this one had to build, fix or work around?',
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
: []),
|
|
58
|
+
...config.questions.map((text) => ({ kind: 'other', text })),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The end-of-session prompt for item `id`. `reply: 'json'` asks for a JSON array (the harness
|
|
64
|
+
* records it); `reply: 'cli'` asks the agent to record each answer with `gcf lessons add`.
|
|
65
|
+
*/
|
|
66
|
+
export async function lessonsPrompt(projectDir, id, { reply = 'cli' } = {}) {
|
|
67
|
+
if (!isValidId(id)) throw new Error(`${id} is not an item id`);
|
|
68
|
+
const config = lessonsConfig(await readRawConfig(path.join(path.resolve(projectDir), 'gcf')));
|
|
69
|
+
const asked = questionsOf(config)
|
|
70
|
+
.map((q, i) => `${i + 1}. ${q.kind}: ${q.text}`)
|
|
71
|
+
.join('\n');
|
|
72
|
+
const how =
|
|
73
|
+
reply === 'json'
|
|
74
|
+
? 'Reply with ONLY a JSON array, no other text: ' +
|
|
75
|
+
'[{"kind": "<the kind of its question>", "text": "<one finding>", ' +
|
|
76
|
+
'"where": "<file:line or null>"}]; ' +
|
|
77
|
+
'reply [] when nothing got in the way.'
|
|
78
|
+
: `Record each finding with: ai-factory gcf lessons add ${id} --kind <the kind of its ` +
|
|
79
|
+
'question> --text "<one finding>" [--where <file:line>]. Record nothing when nothing ' +
|
|
80
|
+
'got in the way.';
|
|
81
|
+
const prompt = [
|
|
82
|
+
`The work on ${id} in this session is over. Before the session ends, tell the operator ` +
|
|
83
|
+
'what got in your way, so it can be removed.',
|
|
84
|
+
'Answer from this session only, one finding per entry, in a sentence or two; skip a ' +
|
|
85
|
+
'question with nothing to say, and never invent one.',
|
|
86
|
+
asked,
|
|
87
|
+
// The harness's turn comes after the item's commit and its verified trailer: an edit then
|
|
88
|
+
// would leave the checkout dirty or move the trailer off the tip.
|
|
89
|
+
reply === 'json'
|
|
90
|
+
? 'Do not edit, write or commit any file in this turn: only answer.'
|
|
91
|
+
: 'If the project keeps its own lessons file (its rules name it), update it now as they say.',
|
|
92
|
+
how,
|
|
93
|
+
].join('\n\n');
|
|
94
|
+
|
|
95
|
+
return { off: config.off, prompt };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A lesson as the agent gave it, checked: `{kind, text, where}`. */
|
|
99
|
+
function lessonOf(raw, i) {
|
|
100
|
+
const kind = KINDS.includes(raw?.kind) ? raw.kind : 'other';
|
|
101
|
+
const text = String(raw?.text ?? '')
|
|
102
|
+
.replace(/\s+/g, ' ')
|
|
103
|
+
.trim();
|
|
104
|
+
if (!text) throw new Error(`lesson ${i + 1} has no text`);
|
|
105
|
+
const where = raw?.where ? String(raw.where).replace(/\s+/g, ' ').trim() : '';
|
|
106
|
+
|
|
107
|
+
return { kind, text: where ? `${text} (${where})` : text };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Record `lessons` of item `id` as inbox entries; `{kind, text, where?}` each, a kind outside
|
|
112
|
+
* KINDS reads as other. Returns the entries written.
|
|
113
|
+
*/
|
|
114
|
+
export async function addLessons(root, id, lessons) {
|
|
115
|
+
if (!isValidId(id)) throw new Error(`${id} is not an item id`);
|
|
116
|
+
if (!Array.isArray(lessons)) throw new Error('lessons must be a JSON array');
|
|
117
|
+
const checked = lessons.map(lessonOf);
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const l of checked) out.push(await addInbox(root, l.text, `lesson:${l.kind}:${id}`));
|
|
120
|
+
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The lessons of a JSON file: an array, as the harness writes it. */
|
|
125
|
+
export async function lessonsFile(file) {
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(await readFile(file, 'utf8'));
|
|
128
|
+
} catch (e) {
|
|
129
|
+
throw new Error(`cannot read lessons from ${file}: ${e.message}`, { cause: e });
|
|
130
|
+
}
|
|
131
|
+
}
|
package/lib/playtest-list.js
CHANGED
|
@@ -41,6 +41,19 @@ export async function playtestList(root) {
|
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** Items awaiting a decision: no verdict, but the human may need the build to make it. */
|
|
45
|
+
async function decisionList(root) {
|
|
46
|
+
return (await listItems(root))
|
|
47
|
+
.filter((c) => c.data.status === 'awaiting-decision')
|
|
48
|
+
.map((c) => ({
|
|
49
|
+
id: c.data.id,
|
|
50
|
+
title: c.data.title ?? null,
|
|
51
|
+
system: c.data.system ?? [],
|
|
52
|
+
intent: firstBullet(c.body, 'intent') || null,
|
|
53
|
+
}))
|
|
54
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
const git = (projectDir, args) => {
|
|
45
58
|
const res = spawnSync('git', args, { cwd: projectDir, encoding: 'utf8' });
|
|
46
59
|
|
|
@@ -73,10 +86,11 @@ export async function playtestSession(
|
|
|
73
86
|
commit: git(projectDir, ['rev-parse', '--short', 'HEAD']),
|
|
74
87
|
// No commit (no repository, or none yet): the build is unknown, not clean.
|
|
75
88
|
dirty: dirty === null ? null : Boolean(dirty),
|
|
76
|
-
build: /** @type {ReturnType<typeof runDod
|
|
89
|
+
build: /** @type {Awaited<ReturnType<typeof runDod>> | null} */ (null),
|
|
77
90
|
items,
|
|
91
|
+
decisions: await decisionList(root),
|
|
78
92
|
};
|
|
79
|
-
if (build) session.build = runDod(projectDir, await readConfig(root), 'build', stdio);
|
|
93
|
+
if (build) session.build = await runDod(projectDir, await readConfig(root), 'build', stdio);
|
|
80
94
|
|
|
81
95
|
return session;
|
|
82
96
|
}
|
package/lib/verify.js
CHANGED
|
@@ -1,15 +1,111 @@
|
|
|
1
1
|
// `gcf verify <id>` (Methodology §6): the auto-DoD checks code can run — the GCF checks of the
|
|
2
2
|
// pre-commit gate, the item's live: delta against LIVE.md, then the project's `dod.build` and
|
|
3
3
|
// `dod.test`. The second-agent review is the run's job; the attempt count lives in the run.
|
|
4
|
-
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
5
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { readConfig } from './gcf-paths.js';
|
|
7
8
|
import { readLive, applyDelta } from './live.js';
|
|
8
9
|
import { gateProblems } from './gate.js';
|
|
9
10
|
import { unplayedCloseProblem } from './work-ops.js';
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Every process's parent, `[pid, ppid]` (POSIX): from /proc on Linux, which a slim image has
|
|
14
|
+
* with no procps; from `ps` elsewhere.
|
|
15
|
+
*/
|
|
16
|
+
function parents() {
|
|
17
|
+
if (existsSync('/proc/self/stat'))
|
|
18
|
+
return readdirSync('/proc')
|
|
19
|
+
.filter((d) => /^\d+$/.test(d))
|
|
20
|
+
.flatMap((d) => {
|
|
21
|
+
try {
|
|
22
|
+
// `pid (comm) state ppid …`: comm may hold spaces and parentheses.
|
|
23
|
+
const stat = readFileSync(`/proc/${d}/stat`, 'utf8');
|
|
24
|
+
|
|
25
|
+
return [[Number(d), Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1])]];
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const res = spawnSync('ps', ['-A', '-o', 'pid=,ppid='], { encoding: 'utf8' });
|
|
31
|
+
|
|
32
|
+
return (res.stdout ?? '')
|
|
33
|
+
.split('\n')
|
|
34
|
+
.map((l) => l.trim().split(/\s+/).map(Number))
|
|
35
|
+
.filter((p) => p.length === 2 && p.every(Number.isFinite));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Stop `p` where it is, or kill it; a process gone already is no error. */
|
|
39
|
+
const signal = (p, sig) => {
|
|
40
|
+
try {
|
|
41
|
+
process.kill(p, sig);
|
|
42
|
+
} catch {
|
|
43
|
+
// Gone already.
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* End a command with everything it started: an engine the shell spawned outlives the shell. The
|
|
49
|
+
* command stays in its caller's process group, so a harness that kills its session's group
|
|
50
|
+
* kills the command too. On POSIX each process found is stopped first, so none forks a child the
|
|
51
|
+
* walk would miss; then all are killed.
|
|
52
|
+
* shortcut: a grandchild whose parent exited before the walk is init's and is not found; a
|
|
53
|
+
* process group of its own per command would catch it, at the cost of the harness's group kill.
|
|
54
|
+
*/
|
|
55
|
+
function killTree(pid) {
|
|
56
|
+
if (process.platform === 'win32') {
|
|
57
|
+
spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' });
|
|
58
|
+
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const doomed = new Set([pid]);
|
|
63
|
+
// finally: a walk that throws (an unreadable /proc) must not leave what it stopped frozen.
|
|
64
|
+
try {
|
|
65
|
+
while (stopChildren(doomed));
|
|
66
|
+
} finally {
|
|
67
|
+
for (const p of doomed) signal(p, 'SIGKILL');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Stop every process of `doomed`, then add their children; true when one was added. */
|
|
72
|
+
function stopChildren(doomed) {
|
|
73
|
+
let grew = false;
|
|
74
|
+
for (const p of doomed) signal(p, 'SIGSTOP');
|
|
75
|
+
for (const [p, parent] of parents())
|
|
76
|
+
if (doomed.has(parent) && !doomed.has(p)) grew = Boolean(doomed.add(p));
|
|
77
|
+
|
|
78
|
+
return grew;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Run `cmd` in a shell; past `ms` (0: never) it is killed with its whole tree. `exit`, not
|
|
83
|
+
* `close`: a helper the command left running may hold the inherited stdio open.
|
|
84
|
+
*/
|
|
85
|
+
function runCommand(cmd, cwd, stdio, ms) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
const child = spawn(cmd, { cwd, shell: true, stdio });
|
|
88
|
+
let timedOut = false;
|
|
89
|
+
const timer =
|
|
90
|
+
ms > 0
|
|
91
|
+
? setTimeout(() => {
|
|
92
|
+
timedOut = true;
|
|
93
|
+
killTree(child.pid);
|
|
94
|
+
}, ms)
|
|
95
|
+
: null;
|
|
96
|
+
child.on('error', (error) => {
|
|
97
|
+
clearTimeout(timer ?? undefined);
|
|
98
|
+
resolve({ error, timedOut });
|
|
99
|
+
});
|
|
100
|
+
child.on('exit', (status, signal) => {
|
|
101
|
+
clearTimeout(timer ?? undefined);
|
|
102
|
+
resolve({ status, signal, timedOut });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
11
107
|
/** Run a `dod.<key>` command in the project; `none` says the project has no such step. */
|
|
12
|
-
export function runDod(projectDir, config, key, stdio) {
|
|
108
|
+
export async function runDod(projectDir, config, key, stdio) {
|
|
13
109
|
if (config.dod !== undefined && (typeof config.dod !== 'object' || Array.isArray(config.dod)))
|
|
14
110
|
return { name: key, ok: false, problems: ['dod in gcf/config.yml must map test: and build:'] };
|
|
15
111
|
const cmd = config.dod?.[key];
|
|
@@ -20,13 +116,26 @@ export function runDod(projectDir, config, key, stdio) {
|
|
|
20
116
|
ok: false,
|
|
21
117
|
problems: [`dod.${key} is not set in gcf/config.yml — the project's command, or none`],
|
|
22
118
|
};
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
119
|
+
// stdin is closed; a command that never ends (a hung engine, a watch mode) meets the timeout.
|
|
120
|
+
const minutes = config.dod_timeout_min ?? 0;
|
|
121
|
+
const problem = failureOf(
|
|
122
|
+
key,
|
|
123
|
+
cmd,
|
|
124
|
+
minutes,
|
|
125
|
+
await runCommand(cmd, projectDir, stdio, minutes * 60000),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return { name: key, ok: !problem, problems: problem ? [problem] : [] };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Why a finished DoD command failed, or null when it passed. */
|
|
132
|
+
function failureOf(key, cmd, minutes, res) {
|
|
133
|
+
if (res.timedOut)
|
|
134
|
+
return `dod.${key} timed out after ${minutes} min (dod_timeout_min), killed: ${cmd}`;
|
|
135
|
+
if (res.status === 0) return null;
|
|
27
136
|
const why = res.error ? res.error.message : `exit ${res.status ?? res.signal}`;
|
|
28
137
|
|
|
29
|
-
return
|
|
138
|
+
return `dod.${key} failed (${why}): ${cmd}`;
|
|
30
139
|
}
|
|
31
140
|
|
|
32
141
|
/**
|
|
@@ -65,8 +174,8 @@ export async function verifyItem(projectDir, id, { stdio = ['ignore', 2, 2] } =
|
|
|
65
174
|
const checks = [
|
|
66
175
|
{ name: 'gcf', ok: !problems.length, problems },
|
|
67
176
|
{ name: 'live', ok: !live.length, problems: live },
|
|
68
|
-
runDod(projectDir, config, 'build', stdio),
|
|
69
|
-
runDod(projectDir, config, 'test', stdio),
|
|
177
|
+
await runDod(projectDir, config, 'build', stdio),
|
|
178
|
+
await runDod(projectDir, config, 'test', stdio),
|
|
70
179
|
];
|
|
71
180
|
|
|
72
181
|
return { id, checks, ok: checks.every((c) => c.ok) };
|
package/lib/work-ops.js
CHANGED
|
@@ -905,6 +905,8 @@ async function prioritizeItemsUnlocked(projectDir, ids, { commit = true } = {})
|
|
|
905
905
|
});
|
|
906
906
|
const hash = await commitMove(projectDir, `gcf(priority): ${ids.join(', ')}`, {
|
|
907
907
|
files: items.map((i) => i.file),
|
|
908
|
+
// An item made with `item new` and never committed rides along: all of it is new work.
|
|
909
|
+
inputs: items.map((i) => i.file).filter((f) => !tracked(projectDir, f)),
|
|
908
910
|
mutate: async () => {
|
|
909
911
|
for (const [n, i] of items.entries())
|
|
910
912
|
await atomicWrite(i.file, serialize({ ...i.data, priority: ranks[n] }, i.body));
|
package/package.json
CHANGED
|
@@ -23,13 +23,14 @@ forbidden_behaviors:
|
|
|
23
23
|
workflow:
|
|
24
24
|
1. run `ai-factory gcf inbox --json`; read `gcf/LIVE.md` and `gcf/INDEX.md` to know what exists and what is in work
|
|
25
25
|
2. classify each entry: bug, tune of a live or unplayed item, idea for the design, request (an asset file, a question), duplicate, or noise; search `gcf/graveyard.md` for each idea and bug
|
|
26
|
-
3.
|
|
27
|
-
4.
|
|
28
|
-
5.
|
|
29
|
-
6. a
|
|
30
|
-
7. an
|
|
31
|
-
8.
|
|
32
|
-
9.
|
|
26
|
+
3. a lesson (`source: lesson`, with its `kind` and the `item` it came from) is what got in an agent's way: propose the fix it asks for - a project rule, a tech item, a note for the framework or the template - or noise
|
|
27
|
+
4. for each entry propose one call with its fields: a bug gets type `bug`, severity and a repro; a tune names the item and the note; an idea names the subsystem; a duplicate names the item it repeats
|
|
28
|
+
5. present the calls to the human, calls per message <= 5, and apply only the approved ones
|
|
29
|
+
6. a bug or other work: run `ai-factory gcf item new <id> --type <type> [--severity <level>] --from <in-id>`, then write its `intent:` and `repro:`
|
|
30
|
+
7. a tune of an item waiting for its verdict: keep the note for the verdict session and run `ai-factory gcf inbox drop <in-id>`; the note goes in through `/gcf-verdict … tune --note`
|
|
31
|
+
8. an idea for the design: write a unit with `TBD` slots in `gcf/design/<system>.md` and its backlog line, then run `ai-factory gcf inbox drop <in-id>`
|
|
32
|
+
9. a duplicate or noise: run `ai-factory gcf inbox drop <in-id>`
|
|
33
|
+
10. report what each entry became and how many entries remain
|
|
33
34
|
|
|
34
35
|
invocation:
|
|
35
36
|
- run after a playtest session, after a CI run that added entries, or when the user asks to triage
|
package/templates/config.yml
CHANGED
|
@@ -7,14 +7,25 @@ context_budget: 30000
|
|
|
7
7
|
pillars_budget: 1500
|
|
8
8
|
envelope_default_spread: 0.3
|
|
9
9
|
unplayed_warn_after: 5
|
|
10
|
-
plan_passes:
|
|
10
|
+
plan_passes: 3
|
|
11
11
|
dod_attempts: 2
|
|
12
|
+
# Minutes a dod.test or dod.build command may take before it is killed with all it started
|
|
13
|
+
# (0: no limit): a hung engine fails the DoD instead of holding the run.
|
|
14
|
+
dod_timeout_min: 60
|
|
12
15
|
# Agent runs (Harness-PRD §7): the share of the context window at which a run hands its item
|
|
13
16
|
# to a fresh session (0: never), the window when the model's is unknown (0: the model's), and
|
|
14
17
|
# the agent's auto-compaction share (0: its default; at least the handoff share + 15).
|
|
15
18
|
context_handoff_pct: 60
|
|
16
19
|
context_window: 0
|
|
17
20
|
auto_compact_pct: 0
|
|
21
|
+
# Lessons (Methodology §5.2.2): at the end of each session on an item its agent says what got in
|
|
22
|
+
# its way, into the inbox. `ai-factory gcf lessons prompt <id>` prints the questions. Uncomment to
|
|
23
|
+
# turn them off, to ask what the project's template should learn, or to add questions:
|
|
24
|
+
# lessons:
|
|
25
|
+
# off: true
|
|
26
|
+
# template: ../my-template
|
|
27
|
+
# questions:
|
|
28
|
+
# - which step of this item took the longest, and why?
|
|
18
29
|
# What agent runs may not do lives in an `agent:` section that `ai-factory gcf permissions`
|
|
19
30
|
# and the board write; without it the default deny groups hold.
|
|
20
31
|
# The project's own commands for the auto DoD (Methodology §6); the engine does not matter.
|