@golden-frijoles/kit 0.31.0 → 0.32.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.
@@ -52,7 +52,10 @@ import { fileURLToPath } from 'node:url';
52
52
  import { resolveTarget } from './build-state.mjs';
53
53
  import { buildRows } from './roadmap-extract.mjs';
54
54
  import { projectRoot } from './lib/project-root.mjs';
55
- import { formatScalar, parseDocFrontmatter } from './lib/roadmap-contract.mjs';
55
+ import { parseDocFrontmatter } from './lib/roadmap-contract.mjs';
56
+ import { stampFrontmatter } from './lib/frontmatter-stamp.mjs';
57
+
58
+ export { stampFrontmatter };
56
59
  import { needSetting } from './lib/config.mjs';
57
60
  import { apiKeyFrom } from './roadmap-push.mjs';
58
61
  import { PRICES_AS_OF, PRICES_SOURCE, TOKEN_KINDS, tokensOf, usdOf } from './lib/model-prices.mjs';
@@ -728,25 +731,7 @@ export async function pushUsage({
728
731
 
729
732
  // ── Stamping actual_* (S1.4 backfill, S2.5 close) ───────────────────────────────────────────────────
730
733
 
731
- /**
732
- * Set `fields` in a doc's frontmatter: an existing `key:` line is replaced in place, a missing one is inserted just
733
- * before the closing fence. No other line is touched. Re-running with the same values is a no-op (idempotent).
734
- */
735
- export function stampFrontmatter(md, fields) {
736
- const lines = md.split('\n');
737
- if (lines[0].trim() !== '---') throw new Error('no frontmatter');
738
- const end = lines.findIndex((l, i) => i > 0 && l.trim() === '---');
739
- if (end === -1) throw new Error('unterminated frontmatter');
740
- const missing = [];
741
- for (const [key, value] of Object.entries(fields)) {
742
- const line = `${key}: ${formatScalar(value)}`;
743
- const at = lines.findIndex((l, i) => i > 0 && i < end && new RegExp(`^${key}:(\\s|$)`).test(l));
744
- if (at === -1) missing.push(line);
745
- else lines[at] = line;
746
- }
747
- lines.splice(end, 0, ...missing);
748
- return lines.join('\n');
749
- }
734
+ // stampFrontmatter moved to lib/frontmatter-stamp.mjs (result-record D8); re-exported above for existing callers.
750
735
 
751
736
  /** The three actual_* fields for an epic's report. */
752
737
  export function actualFields(report, basisPrefix, date) {
@@ -0,0 +1,331 @@
1
+ #!/usr/bin/env node
2
+ // epic-read.mjs — read an epic's result on its read date: draft the verdict with its evidence; write it on approval.
3
+ //
4
+ // node scripts/epic-read.mjs --epic <slug> # when is the read, and what it needs
5
+ // node scripts/epic-read.mjs --epic <slug> --actual 72 --evidence north-star:invoices_paid_on_time@2026-11-04
6
+ // node scripts/epic-read.mjs --epic <slug> --evidence "traffic too low (n = 18)" # no number: unclear
7
+ // node scripts/epic-read.mjs --epic <slug> --verdict proven --evidence https://… # an owner verdict
8
+ // … --write # the approval: stamp verdict_* into the README
9
+ // options: --today YYYY-MM-DD (default: today, UTC) · --repo-root <dir> · --json
10
+ //
11
+ // ── The shape (result-record D8) ─────────────────────────────────────────────────────────────────────────────────
12
+ // The agent does the legwork, the owner decides. Without `--write` this prints a draft and the exact command that
13
+ // approves it, and writes nothing. Inputs are flags, never a prompt: an agent asks the owner in the conversation and
14
+ // passes what they said.
15
+ // • Before the read date it says when the read is due and stops — the date is the README's `read_date`, or, when none
16
+ // was written, 30 days after shipping (lib/result-dates.mjs, the one place that rule lives).
17
+ // • The draft: from `target_from` toward `target_to`; reached or passed → proven, short of it → disproven; no number
18
+ // → unclear, with the reason in `--evidence`. `--verdict` is the owner's word over the draft, and is said as such.
19
+ // • Proven and disproven need evidence that points somewhere (the contract's grammar: an https:// link,
20
+ // `north-star:<input>@YYYY-MM-DD` or `ab:<experiment>`). `--write` runs the contract's own `validateResultFields` on
21
+ // the record it is about to write, so a verdict the contract refuses never lands.
22
+ // • More than 90 days after shipping, the read is still written, and said to be late (the extract marks it).
23
+ // • An epic shipped with no target can be read too — an owner verdict and its evidence, one epic per run.
24
+ //
25
+ // ── With an account, and without ─────────────────────────────────────────────────────────────────────────────────
26
+ // No route reads a North Star reading or an A/B decision for a key yet (the lock checked: `gf north-star` only sets,
27
+ // `GET /api/v1/north-star` lists metrics and inputs with no values), so the actual always comes from the owner. With the
28
+ // project's key (the one `roadmap-push` uses) this asks that route whether `target_metric` is one of the project's
29
+ // inputs — grounded or not. No key, or any failure, is "could not check", and the read carries on.
30
+ //
31
+ // Zero deps — Node 18+.
32
+ import { existsSync, readFileSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';
33
+ import { join, resolve } from 'node:path';
34
+ import { fileURLToPath } from 'node:url';
35
+ import { projectRoot } from './lib/project-root.mjs';
36
+ import {
37
+ VERDICTS,
38
+ isEvidencePointer,
39
+ parseDocFrontmatter,
40
+ validateResultFields,
41
+ } from './lib/roadmap-contract.mjs';
42
+ import { READ_CAP_DAYS, isLate, readDateOf, todayUtc, isDay } from './lib/result-dates.mjs';
43
+ import { stampFrontmatter } from './lib/frontmatter-stamp.mjs';
44
+ import { buildRows } from './roadmap-extract.mjs';
45
+ import { apiKeyFrom } from './roadmap-push.mjs';
46
+
47
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
48
+ /** `2026-11-04` → `4 Nov 2026`. */
49
+ export const longDay = (d) =>
50
+ `${Number(d.slice(8, 10))} ${MONTHS[Number(d.slice(5, 7)) - 1]} ${d.slice(0, 4)}`;
51
+
52
+ const fig = (n) => (Number.isInteger(n) ? String(n) : String(Math.round(n * 100) / 100));
53
+
54
+ /**
55
+ * The draft verdict for a target and a number read. Pure.
56
+ * From → to says the direction: a target above its start is met at or above it, one below at or below it.
57
+ */
58
+ export function draftVerdict({ from, to, actual }) {
59
+ if (actual === null || actual === undefined || !Number.isFinite(actual)) return 'unclear';
60
+ if (!Number.isFinite(from) || !Number.isFinite(to)) return 'unclear';
61
+ const up = to > from;
62
+ return (up ? actual >= to : actual <= to) ? 'proven' : 'disproven';
63
+ }
64
+
65
+ /**
66
+ * Everything the read decides, from the README's frontmatter, the extract's row and the flags. Pure — no I/O.
67
+ * Returns `{ state, … }`: not-shipped · already-read · not-due · needs-input · refused · ready.
68
+ */
69
+ export function planRead({ fm, shippedAt, shipped, today, actual = null, evidence = null, verdict = null }) {
70
+ const target = {
71
+ hypothesis: fm.hypothesis ?? null,
72
+ metric: fm.target_metric ?? null,
73
+ from: typeof fm.target_from === 'number' ? fm.target_from : null,
74
+ to: typeof fm.target_to === 'number' ? fm.target_to : null,
75
+ };
76
+ if (fm.verdict)
77
+ return { state: 'already-read', target, verdict: fm.verdict, verdictAt: fm.verdict_at ?? null };
78
+ if (!shipped) return { state: 'not-shipped', target };
79
+ if (verdict !== null && !VERDICTS.includes(verdict))
80
+ return {
81
+ state: 'refused',
82
+ target,
83
+ reasons: [`--verdict must be one of ${VERDICTS.join(' | ')}, got "${verdict}"`],
84
+ };
85
+
86
+ const { readDate, derived } = readDateOf({
87
+ readDate: fm.read_date,
88
+ targetMetric: target.metric,
89
+ shippedAt,
90
+ });
91
+ if (target.metric && readDate && today < readDate) return { state: 'not-due', target, readDate, derived };
92
+
93
+ const owner = verdict !== null;
94
+ if (!target.metric && !owner)
95
+ return {
96
+ state: 'needs-input',
97
+ target,
98
+ need: 'This epic shipped with no target. An owner verdict is allowed, one epic at a time: --verdict <proven|disproven|unclear> --evidence <pointer, or for unclear the reason> (and --actual <n> for proven/disproven).',
99
+ };
100
+ const drafted = target.metric ? draftVerdict({ from: target.from, to: target.to, actual }) : null;
101
+ const chosen = owner ? verdict : drafted;
102
+ if (chosen === 'unclear' && !evidence)
103
+ return {
104
+ state: 'needs-input',
105
+ target,
106
+ drafted,
107
+ readDate,
108
+ derived,
109
+ need:
110
+ actual === null
111
+ ? `Ask the owner for the number read for ${target.metric ?? 'this epic'} (--actual <n>) and where it came from (--evidence <https://… | north-star:<input>@YYYY-MM-DD | ab:<experiment>>), or why it cannot be told yet (--evidence "<reason>").`
112
+ : 'Unclear needs the reason in --evidence (e.g. "traffic too low to tell (n = 18)").',
113
+ };
114
+ if ((chosen === 'proven' || chosen === 'disproven') && !evidence)
115
+ return {
116
+ state: 'needs-input',
117
+ target,
118
+ drafted,
119
+ readDate,
120
+ derived,
121
+ need: `${chosen} needs evidence that points somewhere: --evidence <https://… | north-star:<input>@YYYY-MM-DD | ab:<experiment>>.`,
122
+ };
123
+
124
+ const fields = {
125
+ verdict: chosen,
126
+ verdict_actual: actual === null || actual === undefined ? null : actual,
127
+ verdict_evidence: evidence,
128
+ verdict_at: today,
129
+ };
130
+ const offenses = validateResultFields({ ...fm, ...fields }).map((o) => o.detail);
131
+ const late = isLate({ verdictAt: today, shippedAt });
132
+ if (offenses.length) return { state: 'refused', target, drafted, fields, reasons: offenses, late };
133
+ return { state: 'ready', target, drafted, owner, fields, late, readDate, derived };
134
+ }
135
+
136
+ /** `metric` against the project's North Star inputs, through the existing read route. Never throws. */
137
+ export async function groundedCheck({ metric, apiKey, baseUrl, fetchFn = fetch }) {
138
+ if (!metric) return { checked: false, why: 'no target metric' };
139
+ if (!apiKey)
140
+ return { checked: false, why: 'no project key (SELF_PROJECT_API_KEY / GROWTH_ENGINE_API_KEY)' };
141
+ try {
142
+ const res = await fetchFn(`${String(baseUrl).replace(/\/$/, '')}/api/v1/north-star`, {
143
+ headers: { Authorization: `Bearer ${apiKey}` },
144
+ signal: AbortSignal.timeout(10_000),
145
+ });
146
+ if (!res.ok) return { checked: false, why: `the engine answered ${res.status}` };
147
+ const body = await res.json();
148
+ const keys = (body?.metrics ?? []).flatMap((m) => (m?.inputs ?? []).map((i) => i?.key)).filter(Boolean);
149
+ return { checked: true, grounded: keys.includes(metric), keys };
150
+ } catch (err) {
151
+ return { checked: false, why: `could not reach ${baseUrl}: ${err?.message ?? err}` };
152
+ }
153
+ }
154
+
155
+ /** The text a person reads. Pure. */
156
+ export function renderPlan(plan, { slug, grounded, write, written }) {
157
+ const out = [];
158
+ const t = plan.target;
159
+ const head = t.metric
160
+ ? `${slug}: ${t.metric}${t.from !== null && t.to !== null ? ` ${fig(t.from)} → ${fig(t.to)}` : ''}${t.hypothesis ? ` — "${t.hypothesis}"` : ''}`
161
+ : `${slug}: no target`;
162
+ out.push(head);
163
+ if (grounded) {
164
+ if (grounded.checked)
165
+ out.push(
166
+ grounded.grounded
167
+ ? ` grounded: ${t.metric} is one of the project's North Star inputs`
168
+ : ` not grounded: ${t.metric} is not one of the project's North Star inputs (${grounded.keys.join(', ') || 'none'})`
169
+ );
170
+ else if (t.metric) out.push(` could not check the metric against the North Star (${grounded.why})`);
171
+ }
172
+ switch (plan.state) {
173
+ case 'already-read':
174
+ out.push(
175
+ ` already read: ${plan.verdict}${plan.verdictAt ? ` on ${longDay(plan.verdictAt)}` : ''}. Nothing to do.`
176
+ );
177
+ break;
178
+ case 'not-shipped':
179
+ out.push(' not shipped yet: there is nothing out there to read.');
180
+ break;
181
+ case 'not-due':
182
+ out.push(
183
+ ` read due ${longDay(plan.readDate)}${plan.derived ? ' (30 days after shipping — no read_date was written)' : ''}. Not yet: come back then.`
184
+ );
185
+ break;
186
+ case 'needs-input':
187
+ if (plan.drafted) out.push(` draft so far: ${plan.drafted}`);
188
+ out.push(` needs: ${plan.need}`);
189
+ break;
190
+ case 'refused':
191
+ out.push(' refused — nothing written:');
192
+ for (const r of plan.reasons) out.push(` · ${r}`);
193
+ break;
194
+ case 'ready': {
195
+ const f = plan.fields;
196
+ const word =
197
+ plan.owner && plan.drafted && plan.drafted !== f.verdict
198
+ ? `${f.verdict} (owner's verdict; drafted ${plan.drafted})`
199
+ : plan.owner
200
+ ? `${f.verdict} (owner's verdict)`
201
+ : f.verdict;
202
+ out.push(` verdict: ${word}`);
203
+ if (f.verdict_actual !== null)
204
+ out.push(` actual: ${fig(f.verdict_actual)}${t.to !== null ? ` (target ${fig(t.to)})` : ''}`);
205
+ out.push(
206
+ ` evidence: ${f.verdict_evidence}${isEvidencePointer(f.verdict_evidence) ? '' : ' (a reason, not a pointer)'}`
207
+ );
208
+ out.push(` read on: ${longDay(f.verdict_at)}`);
209
+ if (plan.late)
210
+ out.push(
211
+ ` late: more than ${READ_CAP_DAYS} days after shipping — it is recorded, and it will not count for the North Star.`
212
+ );
213
+ if (written)
214
+ out.push(
215
+ ` written to ${written}. Commit it, then push the roadmap (node scripts/roadmap-push.mjs).`
216
+ );
217
+ else if (!write) out.push(' Not written. If the owner approves, run the same command with --write.');
218
+ break;
219
+ }
220
+ }
221
+ return out.join('\n');
222
+ }
223
+
224
+ function epicReadme(root, slug) {
225
+ const roadmap = join(root, 'Roadmap');
226
+ for (const macro of existsSync(roadmap) ? readdirSync(roadmap).sort() : []) {
227
+ if (!/^\d{2}-/.test(macro)) continue;
228
+ const p = join(roadmap, macro, slug, 'README.md');
229
+ if (existsSync(p)) return p;
230
+ }
231
+ return null;
232
+ }
233
+
234
+ const arg = (argv, name) => {
235
+ const i = argv.indexOf(name);
236
+ return i === -1 ? null : (argv[i + 1] ?? null);
237
+ };
238
+
239
+ export async function main(argv, { fetchFn = fetch, env = process.env, stdout = process.stdout } = {}) {
240
+ const slug = arg(argv, '--epic');
241
+ if (!slug) {
242
+ process.stderr.write('epic-read: --epic <slug> is required\n');
243
+ return 2;
244
+ }
245
+ const root = resolve(arg(argv, '--repo-root') ?? projectRoot());
246
+ const today = arg(argv, '--today') ?? todayUtc();
247
+ if (!isDay(today)) {
248
+ process.stderr.write(`epic-read: --today must be a day written YYYY-MM-DD, got "${today}"\n`);
249
+ return 2;
250
+ }
251
+ const actualRaw = arg(argv, '--actual');
252
+ const actual = actualRaw === null ? null : Number(actualRaw);
253
+ if (actualRaw !== null && !Number.isFinite(actual)) {
254
+ process.stderr.write(`epic-read: --actual must be a number, got "${actualRaw}"\n`);
255
+ return 2;
256
+ }
257
+ const path = epicReadme(root, slug);
258
+ if (!path) {
259
+ process.stderr.write(`epic-read: no Roadmap/*/${slug}/README.md under ${root}\n`);
260
+ return 2;
261
+ }
262
+ const md = readFileSync(path, 'utf8');
263
+ const parsed = parseDocFrontmatter(md);
264
+ if (!parsed.hasFrontmatter || parsed.error) {
265
+ process.stderr.write(`epic-read: cannot read ${path}'s frontmatter: ${parsed.error ?? 'none'}\n`);
266
+ return 2;
267
+ }
268
+ const row = buildRows({ root, facts: { mode: 'docs', prs: [], branches: [] } }).find(
269
+ (r) => r.grain === 'Epic' && r.slug === slug
270
+ );
271
+ const plan = planRead({
272
+ fm: parsed.data,
273
+ shippedAt: row?.shipped_at ?? null,
274
+ shipped: row?.stage === 'Shipped',
275
+ today,
276
+ actual,
277
+ evidence: arg(argv, '--evidence'),
278
+ verdict: arg(argv, '--verdict'),
279
+ });
280
+ const grounded =
281
+ plan.state === 'already-read' || plan.state === 'not-shipped'
282
+ ? null
283
+ : await groundedCheck({
284
+ metric: plan.target.metric,
285
+ apiKey: apiKeyFrom(env),
286
+ baseUrl: env.GROWTH_ENGINE_URL || 'http://localhost:3000',
287
+ fetchFn,
288
+ });
289
+ const write = argv.includes('--write');
290
+ let written = null;
291
+ if (write && plan.state === 'ready') {
292
+ const next = stampFrontmatter(md, plan.fields);
293
+ // The stamped file must still satisfy the contract as a whole — a second check on what actually lands.
294
+ const after = parseDocFrontmatter(next);
295
+ const offenses = after.error ? [after.error] : validateResultFields(after.data).map((o) => o.detail);
296
+ if (offenses.length) {
297
+ const refused = { ...plan, state: 'refused', reasons: offenses };
298
+ stdout.write(
299
+ argv.includes('--json')
300
+ ? `${JSON.stringify({ slug, ...refused, grounded, written: null })}\n`
301
+ : `${renderPlan(refused, { slug, grounded, write })}\n`
302
+ );
303
+ return 1;
304
+ }
305
+ writeFileSync(path, next);
306
+ written = path.slice(root.length + 1);
307
+ }
308
+ if (argv.includes('--json')) stdout.write(`${JSON.stringify({ slug, ...plan, grounded, written })}\n`);
309
+ else stdout.write(`${renderPlan(plan, { slug, grounded, write, written })}\n`);
310
+ if (plan.state === 'refused') return 1;
311
+ if (write && plan.state !== 'ready') return 1; // asked to write, and there was nothing approvable to write
312
+ return 0;
313
+ }
314
+
315
+ const isMain = (() => {
316
+ try {
317
+ return (
318
+ !!process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))
319
+ );
320
+ } catch {
321
+ return false;
322
+ }
323
+ })();
324
+ if (isMain) {
325
+ try {
326
+ process.exitCode = await main(process.argv.slice(2));
327
+ } catch (err) {
328
+ process.stderr.write(`epic-read: ${err && err.message ? err.message : err}\n`);
329
+ process.exitCode = 2;
330
+ }
331
+ }
@@ -0,0 +1,25 @@
1
+ // frontmatter-stamp.mjs — set fields in a Roadmap doc's frontmatter, in place (zero deps beyond the contract).
2
+ //
3
+ // Written for `epic-actuals.mjs --write` (finops S1.4/S2.5) and moved here when `epic-read.mjs --write` needed the same
4
+ // stamp (result-record D8): two writers of one README must not each keep their own line editor.
5
+ import { formatScalar } from './roadmap-contract.mjs';
6
+
7
+ /**
8
+ * Set `fields` in a doc's frontmatter: an existing `key:` line is replaced in place, a missing one is inserted just
9
+ * before the closing fence. No other line is touched. Re-running with the same values is a no-op (idempotent).
10
+ */
11
+ export function stampFrontmatter(md, fields) {
12
+ const lines = md.split('\n');
13
+ if (lines[0].trim() !== '---') throw new Error('no frontmatter');
14
+ const end = lines.findIndex((l, i) => i > 0 && l.trim() === '---');
15
+ if (end === -1) throw new Error('unterminated frontmatter');
16
+ const missing = [];
17
+ for (const [key, value] of Object.entries(fields)) {
18
+ const line = `${key}: ${formatScalar(value)}`;
19
+ const at = lines.findIndex((l, i) => i > 0 && i < end && new RegExp(`^${key}:(\\s|$)`).test(l));
20
+ if (at === -1) missing.push(line);
21
+ else lines[at] = line;
22
+ }
23
+ lines.splice(end, 0, ...missing);
24
+ return lines.join('\n');
25
+ }
@@ -61,6 +61,8 @@ import {
61
61
  JOURNAL_PATH,
62
62
  } from './lib/session-journal.mjs';
63
63
  import { loadReportingConfig, ReportingConfigError } from './lib/reporting-config.mjs';
64
+ import { isReadDue, todayUtc } from './lib/result-dates.mjs';
65
+ import { buildRows } from './roadmap-extract.mjs';
64
66
 
65
67
  const __dirname = dirname(fileURLToPath(import.meta.url));
66
68
  const DEFAULT_ROOT = join(__dirname, '..');
@@ -495,7 +497,52 @@ export function readMemoryIndex(cwd = process.cwd(), deps = {}) {
495
497
  }
496
498
  }
497
499
 
498
- export function buildAnomalies({ repoStates, migrationResults, expandOrphans = false, memoryIndex }) {
500
+ // result-record D9 — a read that is due is something to act on before anything else, so it rides the anomaly list:
501
+ // one line per epic, from the docs alone (no network), gone as soon as its verdict is written into the README.
502
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
503
+ export function decideReadsDue(rows, today = todayUtc()) {
504
+ return (rows || [])
505
+ .filter(
506
+ (r) =>
507
+ r.grain === 'Epic' &&
508
+ // A target is metric + from + to together (D1); a partial one is never due.
509
+ r.target_from != null &&
510
+ r.target_to != null &&
511
+ isReadDue(
512
+ {
513
+ targetMetric: r.target_metric,
514
+ verdict: r.verdict,
515
+ readDate: r.read_date,
516
+ shipped: r.stage === 'Shipped',
517
+ },
518
+ today
519
+ )
520
+ )
521
+ .sort((a, b) => a.read_date.localeCompare(b.read_date) || a.slug.localeCompare(b.slug))
522
+ .map((r) => ({
523
+ type: 'read-due',
524
+ detail: `Read due: ${r.name} · since ${Number(r.read_date.slice(8, 10))} ${MONTHS[Number(r.read_date.slice(5, 7)) - 1]} · run node scripts/epic-read.mjs --epic ${r.slug}`,
525
+ }));
526
+ }
527
+
528
+ /** The roadmap rows the reads-due check reads, docs only. A failure is a gap, never a silent "nothing due". */
529
+ export function gatherRoadmapRows({ root, buildRowsFn = buildRows, existsSyncFn = existsSync }) {
530
+ // A project with no Roadmap/ has nothing to read: no gap on every run (fresh review, #291).
531
+ if (!existsSyncFn(join(root, 'Roadmap'))) return { available: true, rows: [] };
532
+ try {
533
+ return { available: true, rows: buildRowsFn({ root, facts: { mode: 'docs', prs: [], branches: [] } }) };
534
+ } catch (e) {
535
+ return { available: false, rows: [], reason: e.message };
536
+ }
537
+ }
538
+
539
+ export function buildAnomalies({
540
+ repoStates,
541
+ migrationResults,
542
+ expandOrphans = false,
543
+ memoryIndex,
544
+ readsDue = [],
545
+ }) {
499
546
  const anomalies = [];
500
547
  // First, because it is the one anomaly that changes what the rest of this report is
501
548
  // worth: if the index is truncating, the session is missing facts it does not know it
@@ -504,6 +551,8 @@ export function buildAnomalies({ repoStates, migrationResults, expandOrphans = f
504
551
  const mem = decideMemoryBudgetAnomaly(memoryIndex);
505
552
  if (mem) anomalies.push(mem);
506
553
  }
554
+ // result-record D9 — a due read leads the rest: it is the one line here that asks for a decision, not a cleanup.
555
+ anomalies.push(...readsDue);
507
556
  for (const rs of repoStates || []) {
508
557
  if (rs.git?.available) {
509
558
  const openPrs = rs.gh?.available ? rs.gh.open : undefined; // undefined → decideStrayBranch treats as "unknown"
@@ -531,8 +580,15 @@ export function buildAnomalies({ repoStates, migrationResults, expandOrphans = f
531
580
  // D4: names every degraded source instead of silently dropping it. A missing repo path, an
532
581
  // unauthenticated/unreachable gh, an unavailable migration check, and an empty/unfetchable journal all
533
582
  // land here — distinct from `buildAnomalies`, which only reports CONFIRMED surprising states.
534
- export function buildGaps({ repoStates, migrationResults, journalAvailable, journalReason }) {
583
+ export function buildGaps({
584
+ repoStates,
585
+ migrationResults,
586
+ journalAvailable,
587
+ journalReason,
588
+ roadmapReason = null,
589
+ }) {
535
590
  const gaps = [];
591
+ if (roadmapReason) gaps.push(`reads due unknown — the roadmap could not be read: ${roadmapReason}.`);
536
592
  for (const rs of repoStates || []) {
537
593
  if (!rs.git?.available)
538
594
  gaps.push(`${rs.repo}: git state unavailable — ${rs.git?.reason || 'unknown reason'}.`);
@@ -570,12 +626,14 @@ export function buildReport({
570
626
  journalLimit = JOURNAL_LIMIT_DEFAULT,
571
627
  expandOrphans = false,
572
628
  memoryIndex,
629
+ readsDue = [],
630
+ roadmapReason = null,
573
631
  generatedAt,
574
632
  }) {
575
633
  return {
576
634
  generatedAt: generatedAt || new Date().toISOString(),
577
- anomalies: buildAnomalies({ repoStates, migrationResults, expandOrphans, memoryIndex }),
578
- gaps: buildGaps({ repoStates, migrationResults, journalAvailable, journalReason }),
635
+ anomalies: buildAnomalies({ repoStates, migrationResults, expandOrphans, memoryIndex, readsDue }),
636
+ gaps: buildGaps({ repoStates, migrationResults, journalAvailable, journalReason, roadmapReason }),
579
637
  journal: {
580
638
  available: journalAvailable,
581
639
  reason: journalAvailable ? null : journalReason || null,
@@ -860,6 +918,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
860
918
  now,
861
919
  resolveReposFn = resolveRepos,
862
920
  gatherFactsFn = gatherFacts,
921
+ buildRowsFn = buildRows,
863
922
  } = deps;
864
923
 
865
924
  let args;
@@ -904,6 +963,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
904
963
  spawn,
905
964
  });
906
965
  const journal = gatherJournal({ root: args.root, readLogFromBranchFn });
966
+ const roadmap = gatherRoadmapRows({ root: args.root, buildRowsFn });
907
967
 
908
968
  const report = buildReport({
909
969
  repoStates,
@@ -914,6 +974,8 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
914
974
  journalLimit: args.journalLimit,
915
975
  expandOrphans: args.expandOrphans,
916
976
  memoryIndex: readMemoryIndex(args.root, { stat: statFn, home: homeDir }),
977
+ readsDue: decideReadsDue(roadmap.rows, todayUtc(now || new Date())),
978
+ roadmapReason: roadmap.available ? null : roadmap.reason,
917
979
  generatedAt: (now || new Date()).toISOString(),
918
980
  });
919
981
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golden-frijoles/kit",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "The scripts the Golden Frijoles skills run, packaged so they work in any repo: planning, build-order, reporting and verification rails. Zero dependencies.",
5
5
  "type": "module",
6
6
  "bin": {