gcf-aif-ext 0.27.1 → 0.29.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 +4 -2
- package/commands/gcf.js +190 -20
- package/extension.json +1 -1
- package/lib/agent-permissions.js +1 -0
- package/lib/audit-core.js +12 -2
- package/lib/board.js +16 -6
- package/lib/build-queue.js +235 -0
- package/lib/build-waiter.js +5 -0
- package/lib/devices.js +133 -0
- package/lib/domain.js +27 -2
- package/lib/handoff.js +316 -0
- package/lib/main-lock.js +25 -1
- package/lib/play-notes.js +189 -0
- package/lib/play-on.js +42 -0
- package/lib/play.js +1122 -268
- package/lib/playtest-list.js +24 -6
- package/lib/validate-item.js +1 -1
- package/lib/verify.js +8 -2
- package/lib/work-ops.js +39 -2
- package/package.json +1 -1
- package/skills/gcf-adopt/SKILL.md +3 -1
- package/skills/gcf-card/SKILL.md +1 -0
- package/skills/gcf-chat/SKILL.md +8 -4
- package/skills/gcf-verdict/SKILL.md +1 -1
- package/templates/agents-block.md +16 -2
package/lib/handoff.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// A card's handoff to play (docs/Handoff-Plan.md d4): read live, not stored. The core's blocks come
|
|
2
|
+
// from the card, its plan, its build, the queue, the questions and its submit commit; the agent's
|
|
3
|
+
// fields from the plan's `## Play notes` (lib/play-notes.js). Devices are not asked here (d5):
|
|
4
|
+
// only the Play panel and `gcf playtest devices` run a target's script.
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { firstBullet, readConfig, scalarOf } from './gcf-paths.js';
|
|
8
|
+
import { buildLedger } from './ledger.js';
|
|
9
|
+
import { defaultBuild, itemBuilds, lanAddress, playOf, queueOf } from './play.js';
|
|
10
|
+
import { planPasses, planTicks } from './plan-check.js';
|
|
11
|
+
import { listQuestions } from './questions.js';
|
|
12
|
+
import { recordsOf } from './verdict-fs.js';
|
|
13
|
+
import { serves } from './devices.js';
|
|
14
|
+
import { planTextOf, playNotesOf, playNotesProblems, rowsFor } from './play-notes.js';
|
|
15
|
+
|
|
16
|
+
/** A row's state without asking devices: what is set up and built (the panel asks the rest). */
|
|
17
|
+
function rowOf(play, build, ok, row) {
|
|
18
|
+
const entry = Object.entries(play.targets).find(([, t]) => serves(t, build, row));
|
|
19
|
+
const base = {
|
|
20
|
+
device: row.device,
|
|
21
|
+
os: row.os ?? null,
|
|
22
|
+
os_min: row.os_min ?? null,
|
|
23
|
+
input: row.input ?? [],
|
|
24
|
+
target: entry?.[0] ?? null,
|
|
25
|
+
devices: [],
|
|
26
|
+
note: row.note ?? null,
|
|
27
|
+
};
|
|
28
|
+
if (!entry) return { ...base, status: 'not set up' };
|
|
29
|
+
if (!ok) return { ...base, status: 'not built' };
|
|
30
|
+
const t = entry[1];
|
|
31
|
+
if (t.devices) return { ...base, status: 'built' };
|
|
32
|
+
// This computer plays what has no devices script.
|
|
33
|
+
if (row.device === 'pc')
|
|
34
|
+
return {
|
|
35
|
+
...base,
|
|
36
|
+
status: 'ready',
|
|
37
|
+
devices: [{ id: null, name: 'this computer', state: 'ready', play: true }],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return { ...base, status: 'not detected', address: t.open.replaceAll('{lan}', lanAddress()) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Play by platform (block 2): each build of the card's `play_on` by each row of its `plays_on`.
|
|
45
|
+
* `built`: each profile of the build the card has a snapshot or an attempt of.
|
|
46
|
+
*/
|
|
47
|
+
function playBlock(play, item, builds, notes) {
|
|
48
|
+
if (!play) return [];
|
|
49
|
+
const all = Object.keys(play.builds);
|
|
50
|
+
const playOn = item.data.play_on ?? [];
|
|
51
|
+
const names = playOn.some((b) => all.includes(b)) ? playOn.filter((b) => all.includes(b)) : all;
|
|
52
|
+
const noteOf = (b, r) =>
|
|
53
|
+
notes?.rows.find((n) => n.build === b && n.device === r.device && n.os === (r.os ?? null))
|
|
54
|
+
?.note || null;
|
|
55
|
+
|
|
56
|
+
return names.map((b) => {
|
|
57
|
+
const built = builds
|
|
58
|
+
.filter((x) => x.build === b)
|
|
59
|
+
.map((x) => ({
|
|
60
|
+
profile: x.profile,
|
|
61
|
+
ok: x.ok,
|
|
62
|
+
built_at: x.built_at,
|
|
63
|
+
building: x.building,
|
|
64
|
+
cold: x.cold,
|
|
65
|
+
problem: x.problem,
|
|
66
|
+
}));
|
|
67
|
+
const ok = built.some((x) => x.ok);
|
|
68
|
+
const rows = play.builds[b].plays_on;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
build: b,
|
|
72
|
+
profiles: Object.keys(play.builds[b].profiles),
|
|
73
|
+
built,
|
|
74
|
+
rows: rows.length
|
|
75
|
+
? rows.map((r) => rowOf(play, b, ok, { ...r, note: noteOf(b, r) }))
|
|
76
|
+
: targetRows(play, b, ok),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A build with no `plays_on` yet (a setup from before them): a row per target of it, so Play
|
|
83
|
+
* stays where the Play bar had it. `device: any`: no row of the core's says which.
|
|
84
|
+
*/
|
|
85
|
+
function targetRows(play, build, ok) {
|
|
86
|
+
return Object.entries(play.targets)
|
|
87
|
+
.filter(([, t]) => t.build === build)
|
|
88
|
+
.map(([name, t]) => ({
|
|
89
|
+
device: 'any',
|
|
90
|
+
os: null,
|
|
91
|
+
os_min: null,
|
|
92
|
+
input: [],
|
|
93
|
+
target: name,
|
|
94
|
+
devices: [],
|
|
95
|
+
note: null,
|
|
96
|
+
status: !ok ? 'not built' : t.devices ? 'built' : 'ready',
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The card's own build: the one a run gives it (`defaultBuild`), debug; else the first it has. */
|
|
101
|
+
function ownBuild(play, item, builds) {
|
|
102
|
+
const name = play ? defaultBuild(play, item.data.play_on) : null;
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
builds.find((b) => b.build === name && b.profile === 'debug') ??
|
|
106
|
+
builds.find((b) => b.build === name) ??
|
|
107
|
+
builds[0] ??
|
|
108
|
+
null
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The outcome (block 0): where the card stands, its build, a ticket that waits for it. */
|
|
113
|
+
function outcomeOf(item, build, queue) {
|
|
114
|
+
const ticket = queue.find((q) => q.job.build === item.data.id);
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
word: item.data.status,
|
|
118
|
+
build: build && {
|
|
119
|
+
name: build.build,
|
|
120
|
+
profile: build.profile,
|
|
121
|
+
ok: build.ok,
|
|
122
|
+
built_at: build.built_at,
|
|
123
|
+
building: build.building,
|
|
124
|
+
// A snapshot there, and a later attempt that failed: what is played is the old one.
|
|
125
|
+
stale: build.ok && Boolean(build.problem),
|
|
126
|
+
problem: build.problem,
|
|
127
|
+
},
|
|
128
|
+
queued: ticket ? ticket.ticket : null,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** What the agent said in its Outcome that the gates did not let it do: in its submit's subject. */
|
|
133
|
+
function saidOf(projectDir, id) {
|
|
134
|
+
const res = spawnSync(
|
|
135
|
+
'git',
|
|
136
|
+
['log', '-1', '--format=%s', '--fixed-strings', `--grep=gcf(submit): ${id}`],
|
|
137
|
+
{ cwd: projectDir, encoding: 'utf8' },
|
|
138
|
+
);
|
|
139
|
+
const m = /\((agent: [^)]*)\)\s*$/.exec(res.stdout?.trim() ?? '');
|
|
140
|
+
|
|
141
|
+
return m ? m[1] : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** What waits for the operator's word (block 6): the run's assumptions, its questions, its say. */
|
|
145
|
+
async function waitsOf(dir, id) {
|
|
146
|
+
const qs = await listQuestions(path.join(dir, 'gcf')).catch(() => []);
|
|
147
|
+
const blocksIt = (q) =>
|
|
148
|
+
String(q.blocks ?? '')
|
|
149
|
+
.split(/[\s,[\]]+/)
|
|
150
|
+
.includes(id);
|
|
151
|
+
const said = saidOf(dir, id);
|
|
152
|
+
|
|
153
|
+
return [
|
|
154
|
+
...qs
|
|
155
|
+
.filter((q) => q.class === 'D2' && q.lens === id && q.assumed && !q.answer)
|
|
156
|
+
.map((q) => ({ kind: 'assume', id: q.id, text: `${q.question}: ${q.assumed}` })),
|
|
157
|
+
...qs
|
|
158
|
+
.filter((q) => blocksIt(q) && !q.answer)
|
|
159
|
+
.map((q) => ({ kind: 'question', id: q.id, text: q.question, blocks: id })),
|
|
160
|
+
...(said ? [{ kind: 'said', text: said }] : []),
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** `play:` of the project, or null when it has none or a broken one (its own command says so). */
|
|
165
|
+
async function playIn(dir, config) {
|
|
166
|
+
try {
|
|
167
|
+
return playOf(config ?? (await readConfig(path.join(dir, 'gcf'))));
|
|
168
|
+
} catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The main question (block 1): the card's criterion word for word; a decision's is its intent. */
|
|
174
|
+
function questionOf(item, notes, decision) {
|
|
175
|
+
const criterion = scalarOf(item.body, 'miss_criterion') || null;
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
criterion: decision ? (criterion ?? (firstBullet(item.body, 'intent') || null)) : criterion,
|
|
179
|
+
has_criterion: Boolean(criterion),
|
|
180
|
+
notes: notes?.question ?? [],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Block 7, folded: what a person rarely reads, kept for the one who does. */
|
|
185
|
+
function technicalOf(c) {
|
|
186
|
+
const ticks = planTicks(c.dir, c.item.data);
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
commit: c.item.data.since ?? null,
|
|
190
|
+
code: c.build?.key ?? null,
|
|
191
|
+
unticked: ticks.tasks === null ? null : ticks.tasks - ticks.done,
|
|
192
|
+
passes: planPasses(c.text),
|
|
193
|
+
notes: c.notes?.notes || null,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Blocks 2, 4 and 5 with what the agent wrote; a decision has no Play and no Try. */
|
|
198
|
+
function playedBlocks(c) {
|
|
199
|
+
const n = c.notes;
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
play: c.decision ? null : playBlock(c.play, c.item, c.builds, n),
|
|
203
|
+
try: c.decision ? null : (n?.try ?? []),
|
|
204
|
+
try_from_behavior: recordsOf(c.item.body, 'behavior')
|
|
205
|
+
.map((r) => r.input)
|
|
206
|
+
.filter(Boolean),
|
|
207
|
+
attention: n?.watch_out ?? [],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** What the handoff lacks: the agent's notes, the card's criterion. */
|
|
212
|
+
function warningsOf(c, question) {
|
|
213
|
+
const warnings = c.decision
|
|
214
|
+
? []
|
|
215
|
+
: playNotesProblems(c.notes, rowsFor(c.play, c.item.data.play_on));
|
|
216
|
+
if (!question.has_criterion)
|
|
217
|
+
warnings.push("the card has no miss criterion: the question is the agent's");
|
|
218
|
+
|
|
219
|
+
return warnings;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** A row of block 2 as words, and the command the board has a button for. */
|
|
223
|
+
function rowLines(id, build, r) {
|
|
224
|
+
const where = [r.device, r.os, r.os_min && `${r.os_min}+`].filter(Boolean).join(' ');
|
|
225
|
+
const lines = [` ${build} ${where}: ${r.status}${r.note ? ` — ${r.note}` : ''}`];
|
|
226
|
+
const wait = r.status === 'not built' ? ' --wait' : '';
|
|
227
|
+
if (r.target && r.status !== 'not set up')
|
|
228
|
+
lines.push(` ai-factory gcf playtest start ${id} --target ${r.target}${wait}`);
|
|
229
|
+
if (r.address) lines.push(` then open ${r.address}`);
|
|
230
|
+
if (r.status === 'built') lines.push(` devices: ai-factory gcf playtest devices ${r.target}`);
|
|
231
|
+
|
|
232
|
+
return lines;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const list = (head, items) => (items?.length ? [head, ...items.map((x) => ` - ${x}`)] : []);
|
|
236
|
+
|
|
237
|
+
/** The outcome line (block 0). */
|
|
238
|
+
function outcomeLine(o) {
|
|
239
|
+
const b = o.build;
|
|
240
|
+
const build = !b
|
|
241
|
+
? 'no build'
|
|
242
|
+
: b.building
|
|
243
|
+
? 'building'
|
|
244
|
+
: b.ok
|
|
245
|
+
? `build ${b.name} ${b.profile} ${b.built_at ?? ''}${b.stale ? ` (old: ${b.problem})` : ''}`
|
|
246
|
+
: `no build: ${b.problem}`;
|
|
247
|
+
|
|
248
|
+
return `outcome: ${o.word} · ${build}${o.queued ? ` · ticket ${o.queued} waits` : ''}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The technical line (block 7, folded to one line). */
|
|
252
|
+
function technicalLine(t) {
|
|
253
|
+
const parts = [
|
|
254
|
+
t.commit && `code at ${String(t.commit).slice(0, 7)}`,
|
|
255
|
+
t.unticked !== null && `unticked ${t.unticked}`,
|
|
256
|
+
t.passes.length && `plan passes ${t.passes.length}`,
|
|
257
|
+
t.notes,
|
|
258
|
+
].filter(Boolean);
|
|
259
|
+
|
|
260
|
+
return parts.length ? [`technical: ${parts.join(' · ')}`] : [];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The handoff as the terminal reads it: blocks 0-6, then the technical one in a line. */
|
|
264
|
+
export function handoffLines(id, h) {
|
|
265
|
+
const q = h.question;
|
|
266
|
+
|
|
267
|
+
return [
|
|
268
|
+
outcomeLine(h.outcome),
|
|
269
|
+
`question: ${q.criterion ?? '(the card has no miss criterion)'}`,
|
|
270
|
+
...q.notes.map((n) => ` - ${n}`),
|
|
271
|
+
...(h.play?.length ? ['play:'] : []),
|
|
272
|
+
...(h.play ?? []).flatMap((p) => p.rows.flatMap((r) => rowLines(id, p.build, r))),
|
|
273
|
+
...list('changed:', h.changed),
|
|
274
|
+
...list('try:', h.try?.length ? h.try : h.try === null ? [] : h.try_from_behavior),
|
|
275
|
+
...list('watch out:', h.attention),
|
|
276
|
+
...list(
|
|
277
|
+
'waits for you:',
|
|
278
|
+
h.waits.map((w) => (w.kind === 'question' ? `${w.id}: ${w.text}` : w.text)),
|
|
279
|
+
),
|
|
280
|
+
...technicalLine(h.technical),
|
|
281
|
+
...list('warnings:', h.warnings),
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Blocks 0-7 of card `id`'s handoff, or null when it has none (it waits for nothing). `links`:
|
|
287
|
+
* the snapshots' links, read once for a whole board.
|
|
288
|
+
*/
|
|
289
|
+
export async function handoffOf(projectDir, id, { ledger = null, config = null, links } = {}) {
|
|
290
|
+
const dir = path.resolve(projectDir);
|
|
291
|
+
const item = (ledger ?? (await buildLedger(dir))).item(id);
|
|
292
|
+
if (!item || !String(item.data.status).startsWith('awaiting-')) return null;
|
|
293
|
+
const text = planTextOf(dir, item);
|
|
294
|
+
const decision = item.data.status === 'awaiting-decision';
|
|
295
|
+
const c = {
|
|
296
|
+
dir,
|
|
297
|
+
item,
|
|
298
|
+
text,
|
|
299
|
+
decision,
|
|
300
|
+
play: await playIn(dir, config),
|
|
301
|
+
notes: playNotesOf(text),
|
|
302
|
+
builds: decision ? [] : itemBuilds(dir, id, item.data.status, links),
|
|
303
|
+
};
|
|
304
|
+
c.build = ownBuild(c.play, item, c.builds);
|
|
305
|
+
const question = questionOf(item, c.notes, decision);
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
outcome: outcomeOf(item, c.build, queueOf(dir)),
|
|
309
|
+
question,
|
|
310
|
+
changed: (item.data.live?.changes ?? []).map((x) => x.summary).filter(Boolean),
|
|
311
|
+
...playedBlocks(c),
|
|
312
|
+
waits: await waitsOf(dir, id),
|
|
313
|
+
technical: technicalOf(c),
|
|
314
|
+
warnings: warningsOf(c, question),
|
|
315
|
+
};
|
|
316
|
+
}
|
package/lib/main-lock.js
CHANGED
|
@@ -71,21 +71,45 @@ export function lockedItem(projectDir, id) {
|
|
|
71
71
|
* A move on that item from anywhere else would race the run's own record of it.
|
|
72
72
|
*/
|
|
73
73
|
export function runHolder(projectDir, id) {
|
|
74
|
+
const other = (pid) => Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid);
|
|
74
75
|
try {
|
|
75
76
|
const file = path.join(path.resolve(projectDir), '.gcf-session', 'runs', `${id}.lock`);
|
|
76
77
|
const pid = Number(readFileSync(file, 'utf8').split('\n')[0]);
|
|
78
|
+
if (other(pid)) return pid;
|
|
79
|
+
} catch {
|
|
80
|
+
// No lock: a builder a yield let in may still hold the checkout.
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const builder = id === MAIN_RUN ? builderPid(projectDir) : null;
|
|
84
|
+
|
|
85
|
+
return other(builder) ? builder : null;
|
|
86
|
+
}
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
/**
|
|
89
|
+
* The builder a main run's yield let in (lib/build-queue.js): a second holder of the checkout,
|
|
90
|
+
* live even when its run died (docs/Handoff-Plan.md d6). Read here: that module needs this one.
|
|
91
|
+
*/
|
|
92
|
+
function builderPid(projectDir) {
|
|
93
|
+
try {
|
|
94
|
+
const file = path.join(path.resolve(projectDir), '.gcf-session', `${MAIN_RUN}.yield`);
|
|
95
|
+
|
|
96
|
+
return Number(JSON.parse(readFileSync(file, 'utf8')).builder) || null;
|
|
79
97
|
} catch {
|
|
80
98
|
return null;
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
|
|
102
|
+
/** The builder of the yield beside a main run lock (`<dir>/.gcf-session/runs/.main-run.lock`). */
|
|
103
|
+
const builderAt = (file) => builderPid(path.dirname(path.dirname(path.dirname(file))));
|
|
104
|
+
|
|
84
105
|
/** The lock's text when its holder is gone, else null. The file appears whole: see `take`. */
|
|
85
106
|
async function staleText(file) {
|
|
86
107
|
try {
|
|
87
108
|
const text = await readFile(file, 'utf8');
|
|
88
109
|
const pid = Number(text.split('\n')[0]);
|
|
110
|
+
// The main run's lock lives on while the builder its yield let in does.
|
|
111
|
+
const builder = path.basename(file) === `${MAIN_RUN}.lock` ? builderAt(file) : null;
|
|
112
|
+
if (builder && alive(builder)) return null;
|
|
89
113
|
if (Number.isInteger(pid) && pid > 0) return alive(pid) ? null : text;
|
|
90
114
|
|
|
91
115
|
// Not ours to read: a lock in some other shape counts as dead only once it is old.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// The agent's part of a card's handoff to play (docs/Handoff-Plan.md d3): `## Play notes` in the
|
|
2
|
+
// card's plan, written before the commit of gcf-run's step 16, in main and in a worktree alike. The
|
|
3
|
+
// core reads it mechanically and checks its form; what is missing is a warning, never a refusal.
|
|
4
|
+
// The rest of the handoff the core reads live (lib/handoff.js).
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { readConfig } from './gcf-paths.js';
|
|
8
|
+
import { buildLedger } from './ledger.js';
|
|
9
|
+
import { playOf } from './play.js';
|
|
10
|
+
|
|
11
|
+
const HEAD_RE = /^## Play notes[ \t]*\r?$/m;
|
|
12
|
+
const SECTIONS = {
|
|
13
|
+
question: 'Question',
|
|
14
|
+
try: 'Try',
|
|
15
|
+
rows: 'Rows',
|
|
16
|
+
watch_out: 'Watch out',
|
|
17
|
+
notes: 'Notes',
|
|
18
|
+
};
|
|
19
|
+
const ROW_RE = /^[-*]\s+(\w[\w-]*)\s+([\w-]+)(?:\s+([\w-]+))?\s*:\s*(.*)$/;
|
|
20
|
+
|
|
21
|
+
/** The section's lines, up to the next heading of level 1 or 2 (as `## Outcome` is read). */
|
|
22
|
+
function blockOf(text) {
|
|
23
|
+
const at = String(text ?? '').search(HEAD_RE);
|
|
24
|
+
if (at < 0) return null;
|
|
25
|
+
const lines = text.slice(at).split(/\r?\n/).slice(1);
|
|
26
|
+
const end = lines.findIndex((l) => /^#{1,2} /.test(l));
|
|
27
|
+
|
|
28
|
+
return end < 0 ? lines : lines.slice(0, end);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A list's items: a bullet starts one, a line under it goes on with it. */
|
|
32
|
+
function itemsOf(lines) {
|
|
33
|
+
const items = [];
|
|
34
|
+
for (const line of lines) {
|
|
35
|
+
const m = /^\s*[-*]\s+(.*)$/.exec(line);
|
|
36
|
+
if (m) items.push(m[1].trim());
|
|
37
|
+
else if (line.trim() && items.length) items[items.length - 1] += ` ${line.trim()}`;
|
|
38
|
+
else if (line.trim()) items.push(line.trim());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return items.filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The plan's `## Play notes`, or null when it has none.
|
|
46
|
+
* @returns {null | {question: string[], try: string[], rows: Array<{build: string, device: string,
|
|
47
|
+
* os: string | null, note: string}>, bad_rows: string[], watch_out: string[], notes: string,
|
|
48
|
+
* unknown: string[]}}
|
|
49
|
+
*/
|
|
50
|
+
export function playNotesOf(planText) {
|
|
51
|
+
const block = blockOf(planText);
|
|
52
|
+
if (!block) return null;
|
|
53
|
+
const { parts, unknown } = partsOf(block);
|
|
54
|
+
const rows = [];
|
|
55
|
+
const badRows = [];
|
|
56
|
+
for (const line of parts.rows.filter((l) => l.trim())) {
|
|
57
|
+
const m = ROW_RE.exec(line.trim());
|
|
58
|
+
if (m) rows.push({ build: m[1], device: m[2], os: m[3] ?? null, note: m[4].trim() });
|
|
59
|
+
else badRows.push(line.trim());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
question: itemsOf(parts.question),
|
|
64
|
+
try: itemsOf(parts.try),
|
|
65
|
+
rows,
|
|
66
|
+
bad_rows: badRows,
|
|
67
|
+
watch_out: itemsOf(parts.watch_out),
|
|
68
|
+
notes: parts.notes.join('\n').trim(),
|
|
69
|
+
unknown,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The lines under each `### ` heading; a heading the format lacks goes to `unknown`. */
|
|
74
|
+
function partsOf(block) {
|
|
75
|
+
const parts = Object.fromEntries(Object.keys(SECTIONS).map((k) => [k, []]));
|
|
76
|
+
const unknown = [];
|
|
77
|
+
let key = null;
|
|
78
|
+
for (const line of block) {
|
|
79
|
+
const h = /^###\s+(.+?)\s*$/.exec(line);
|
|
80
|
+
if (!h) {
|
|
81
|
+
if (key) parts[key].push(line);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
key = Object.keys(SECTIONS).find((k) => SECTIONS[k].toLowerCase() === h[1].toLowerCase());
|
|
86
|
+
if (!key) unknown.push(h[1]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { parts, unknown };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The plan of card `item`, its text or '' when it has none. */
|
|
93
|
+
export function planTextOf(projectDir, item) {
|
|
94
|
+
const file = path.join(projectDir, item.data.plan ?? `.ai-factory/plans/${item.data.id}.md`);
|
|
95
|
+
|
|
96
|
+
return existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The rows a card's handoff has: each build of its `play_on` (none: every build) by each row of
|
|
101
|
+
* that build's `plays_on`.
|
|
102
|
+
* @returns {Array<{build: string, device: string, os: string | null}>}
|
|
103
|
+
*/
|
|
104
|
+
export function rowsFor(play, playOn) {
|
|
105
|
+
if (!play) return [];
|
|
106
|
+
const names = Object.keys(play.builds);
|
|
107
|
+
const builds = playOn?.length ? playOn.filter((b) => names.includes(b)) : names;
|
|
108
|
+
|
|
109
|
+
return builds.flatMap((b) =>
|
|
110
|
+
play.builds[b].plays_on.map((r) => ({ build: b, device: r.device, os: r.os ?? null })),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const rowKey = (r) => `${r.build} ${r.device}${r.os ? ` ${r.os}` : ''}`;
|
|
115
|
+
|
|
116
|
+
/** `gcf play-notes <id> --template`: the section with the card's rows filled in. */
|
|
117
|
+
export async function playNotesTemplate(projectDir, id) {
|
|
118
|
+
const dir = path.resolve(projectDir);
|
|
119
|
+
const item = (await buildLedger(dir)).item(id);
|
|
120
|
+
if (!item) throw new Error(`${id} is not on the board`);
|
|
121
|
+
const rows = rowsFor(playOf(await readConfig(path.join(dir, 'gcf'))), item.data.play_on);
|
|
122
|
+
|
|
123
|
+
return [
|
|
124
|
+
'## Play notes',
|
|
125
|
+
'',
|
|
126
|
+
'### Question',
|
|
127
|
+
'- ',
|
|
128
|
+
'',
|
|
129
|
+
'### Try',
|
|
130
|
+
'- ',
|
|
131
|
+
'',
|
|
132
|
+
'### Rows',
|
|
133
|
+
...(rows.length ? rows.map((r) => `- ${rowKey(r)}: `) : ['- ']),
|
|
134
|
+
'',
|
|
135
|
+
'### Watch out',
|
|
136
|
+
'- ',
|
|
137
|
+
'',
|
|
138
|
+
'### Notes',
|
|
139
|
+
'',
|
|
140
|
+
].join('\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* What the section lacks, one warning each: the form and what is in it, not its language.
|
|
145
|
+
* @param {ReturnType<typeof playNotesOf>} notes
|
|
146
|
+
* @param {Array<{build: string, device: string, os: string | null}>} rows the card's rows
|
|
147
|
+
*/
|
|
148
|
+
export function playNotesProblems(notes, rows) {
|
|
149
|
+
if (!notes) return ['the plan has no ## Play notes: ai-factory gcf play-notes <id> --template'];
|
|
150
|
+
const problems = notes.unknown.map((h) => `## Play notes has no section ### ${h}`);
|
|
151
|
+
if (!notes.question.length) problems.push('### Question is empty');
|
|
152
|
+
if (!notes.try.length) problems.push('### Try is empty');
|
|
153
|
+
for (const line of notes.bad_rows)
|
|
154
|
+
problems.push(`### Rows: not "<build> <device> [os]: …": ${line}`);
|
|
155
|
+
const known = new Set(rows.map(rowKey));
|
|
156
|
+
for (const r of notes.rows)
|
|
157
|
+
if (!known.has(rowKey(r))) problems.push(`### Rows: ${rowKey(r)} is no row of this card`);
|
|
158
|
+
const noted = new Set(notes.rows.filter((r) => r.note).map(rowKey));
|
|
159
|
+
for (const r of rows)
|
|
160
|
+
if (!noted.has(rowKey(r))) problems.push(`### Rows: ${rowKey(r)} has no note`);
|
|
161
|
+
|
|
162
|
+
return problems;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The card's notes and their warnings, from its plan in `projectDir` (main or its worktree). */
|
|
166
|
+
export async function playNotesCheck(projectDir, item) {
|
|
167
|
+
const dir = path.resolve(projectDir);
|
|
168
|
+
let play = null;
|
|
169
|
+
try {
|
|
170
|
+
play = playOf(await readConfig(path.join(dir, 'gcf')));
|
|
171
|
+
} catch {
|
|
172
|
+
// A broken play: is its own command's to report; the rows are unknown then.
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const notes = playNotesOf(planTextOf(dir, item));
|
|
176
|
+
|
|
177
|
+
return { notes, warnings: playNotesProblems(notes, rowsFor(play, item.data.play_on)) };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The plan's text without `## Play notes`: a move back to `ready` takes it (d3). */
|
|
181
|
+
export function withoutPlayNotes(text) {
|
|
182
|
+
const lines = String(text).split(/(?<=\n)/);
|
|
183
|
+
const at = lines.findIndex((l) => /^## Play notes[ \t]*\r?\n?$/.test(l));
|
|
184
|
+
if (at < 0) return text;
|
|
185
|
+
const rest = lines.slice(at + 1).findIndex((l) => /^#{1,2} /.test(l));
|
|
186
|
+
const end = rest < 0 ? lines.length : at + 1 + rest;
|
|
187
|
+
|
|
188
|
+
return lines.slice(0, at).join('') + lines.slice(end).join('');
|
|
189
|
+
}
|
package/lib/play-on.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// A card's `play_on` and `played_on` name builds of `play.builds` (docs/Handoff-Plan.md d8). Seen
|
|
2
|
+
// where the config and game.md are: one card file alone cannot tell a build from a typo.
|
|
3
|
+
import { playOf } from './play.js';
|
|
4
|
+
|
|
5
|
+
const FIELDS = ['play_on', 'played_on'];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What the cards' build names lack. A line of game.md `platforms` (the old form) or a line of
|
|
9
|
+
* words is a warning until Set up translates it; one word that names no build is an error. A
|
|
10
|
+
* project with no `play:` (or a broken one: its own command says so) has no names to check.
|
|
11
|
+
* @param {{data: object}[]} items
|
|
12
|
+
* @param {string[]} platforms the `platforms` lines of game.md
|
|
13
|
+
* @returns {{errors: string[], warnings: string[]}}
|
|
14
|
+
*/
|
|
15
|
+
export function playOnIssues(items, config, platforms = []) {
|
|
16
|
+
const issues = { errors: [], warnings: [] };
|
|
17
|
+
let play;
|
|
18
|
+
try {
|
|
19
|
+
play = playOf(config);
|
|
20
|
+
} catch {
|
|
21
|
+
return issues;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!play) return issues;
|
|
25
|
+
const names = Object.keys(play.builds);
|
|
26
|
+
const values = items.flatMap((c) =>
|
|
27
|
+
FIELDS.flatMap((field) =>
|
|
28
|
+
[c.data[field] ?? []].flat().map((v) => ({ id: c.data.id, field, v })),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
for (const { id, field, v } of values) {
|
|
32
|
+
if (typeof v !== 'string' || names.includes(v)) continue;
|
|
33
|
+
if (/\s/.test(v.trim()) || platforms.includes(v))
|
|
34
|
+
issues.warnings.push(
|
|
35
|
+
`${id}: ${field} "${v}" is a line of platforms, not a build: name one of ` +
|
|
36
|
+
`${names.join(', ')} (a Set up pass translates it)`,
|
|
37
|
+
);
|
|
38
|
+
else issues.errors.push(`${id}: ${field} names no build: ${v} (${names.join(', ')})`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return issues;
|
|
42
|
+
}
|