Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(chronicle): one reason table and the chronicle_backstop receipt field (#5876)
garrytan42b61b9da748
diff --git a/docs/guides/life-chronicle.md b/docs/guides/life-chronicle.mdnew file mode 100644index 0000000000..a3f38b250b--- /dev/null+++ b/docs/guides/life-chronicle.md@@ -0,0 +1,156 @@+# Life Chronicle: automatic timeline events++**Say to your agent:** *"What happened in my meetings last Tuesday?"*++**Say to your agent:** *"Turn off automatic event extraction."*++**Say to your agent:** *"Extract events from my older meeting notes."*++When you save a meeting, conversation or calendar page, gbrain turns it into+timeline events (`life/events/` pages plus a day-by-day projection) so+`gbrain day <date>`, `gbrain since <date>` and `gbrain on-this-day` can answer+"what happened". This runs automatically and is **on by default**. Each+eligible page costs one paid chat call.++To turn it off:++```bash+gbrain config set auto_chronicle false+```++Unsetting the key restores the default, which is on. Use `set ... false` to+opt out.++## What qualifies++A page is extracted automatically when all of these hold:++- Its type is `meeting`, `conversation` or `calendar-event`, or its slug starts+ with `meetings/`, `conversations/`, `cal/` or `calendar/`.+- Its body has at least 80 characters. Dream-generated pages, diary pages+ (`life/diary/`) and event pages themselves are never extracted.+- It was written or changed after this release activated on the brain. History+ is never swept automatically.+- Its own date (frontmatter `date`, `start` or an authored effective date) is+ within `chronicle.auto_recent_days` (default 30). Undated pages count as+ recent.+- A calendar invite has ended. An invite for next week is picked up once its+ end time passes, with no edit needed. An ended invite is not proof that you+ attended; its events carry `kind: meeting`, `captured_via:+ life-chronicle:auto` and a link to the invite page.+- The writer is not confined. Slug-bound, delegated or namespace-restricted+ clients, and grants without `extract_facts`, never trigger extraction.+- The sync did not run with `--no-extract`. A remote sync never extracts.++The page must also stay unchanged for `chronicle.auto_settle_seconds` (default+180) so a note written in several passes is extracted once.++## Cost and limits++| Setting | Default | What it does |+|---|---|---|+| `auto_chronicle` | on (unset) | `gbrain config set auto_chronicle false` turns automatic extraction off. |+| `chronicle.job_budget_usd` | `0.25` | Cap for one page's extraction call. This is a per-call cap, not a daily budget. |+| `chronicle.auto_daily_limit` | `200` | Automatic extraction calls per rolling 24 hours, across every writer. Retries count. |+| `chronicle.auto_recent_days` | `30` | How old a page's own date may be for automatic extraction. |+| `chronicle.auto_settle_seconds` | `180` | How long a page must stay unchanged before extraction. |+| `chronicle.judge_max_tokens` | `4000` | Output-token cap for one extraction call. |++`gbrain config set` refuses values outside each range and names the range. A+value already stored out of range falls back to its default, and doctor warns+(`chronicle_config_invalid`).++The worst case per day is `auto_daily_limit` x `job_budget_usd`, so $50 at the+defaults for a priced model. Typical pages cost far less. If gbrain has no price+for your chat model, the default cap cannot apply: extraction warns and runs,+still limited by the daily call count. If you set `chronicle.job_budget_usd`+yourself, an unpriced model refuses with `no_pricing`; register its price with+`gbrain pricing set` (see [spend controls](../operations/spend-controls.md)).++Page text is sent to the configured chat provider. Events derived from a private+page stay private to remote callers, including after the page is renamed or+purged.++## Check that it works++1. Write a meeting page. Its write receipt carries+ `chronicle_backstop: { "pending": "next_cycle", "daily_remaining": <n> }`.+ A skip carries `chronicle_backstop: { "skipped": "<code>", "why": ..., "fix": ... }`+ (codes below). Ordinary notes have no `chronicle_backstop` field.+2. Wait for the next autopilot cycle, or run the phase now (paid):+ ```bash+ gbrain dream --phase chronicle+ ```+ On PGLite this is how pending pages run when autopilot is not running.+3. Read the day back:+ ```bash+ gbrain day 2026-04-03+ ```++`gbrain doctor` reports the `auto_chronicle` check: whether it is on, 24 h use+of the daily limit and the largest writer's share, 7-day outcomes and spend+(priced dollars, unpriced calls and calls without a cost record are listed+apart), pending pages and the command that runs them.++## After upgrading++Automatic extraction turned on by default in this release. Until you answer,+doctor shows `auto_chronicle_default_on` (info) and the advisor shows the same+finding with `ask_user: true`. The agent relays the cost to you, then records+your answer:++```bash+gbrain config set auto_chronicle true # keep it+gbrain config set auto_chronicle false # opt out+```++A brain that already had `auto_chronicle true` sees the notice too, because+that setting had no effect before this release.++## History: backfill on request++Older pages are extracted only when you ask. Backfill is paid, so preview it+first and agree to the cost:++```bash+gbrain chronicle-backfill --since 2026-09-01 --limit 50 --dry-run+gbrain chronicle-backfill --since 2026-09-01 --limit 50+```++`--since` filters on the page's last update, not its own date. Re-running is+safe: content already extracted is not paid for again.++## Skip and failure codes++Write receipts, doctor and the advisor use these codes. `decision` codes come+from the write; `execution` codes come from the chronicle phase. Values in angle+brackets are filled in with real values on each surface.++<!-- chronicle-reasons:begin -->+| Code | Stage | Meaning | Fix | Who acts | Consent |+|---|---|---|---|---|---|+| `auto_chronicle_off` | decision | Automatic event extraction is off on this brain by choice (`gbrain config set auto_chronicle false`). | — | — | — |+| `auto_chronicle_invalid` | decision | auto_chronicle holds a value that is neither true nor false, so it reads as off. | `gbrain config set auto_chronicle true` | agent | paid |+| `slug_bound_client` | decision | The writer is confined (slug-bound, delegated or namespace-restricted), so its writes never trigger extraction into life/events/. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | host_admin | paid |+| `operation_bound_client` | decision | The writer's grant lists operations without extract_facts, the permission that covers derived extraction. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | host_admin | paid |+| `no_extract` | decision | The sync ran with extraction turned off (--no-extract, or a remote sync, which never extracts). | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |+| `history` | decision | The page's own date is more than 30 days old (chronicle.auto_recent_days); history is extracted only on request. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |+| `not_yet_happened` | decision | The calendar event has not ended yet; it is picked up automatically after its end time, with no edit needed. | — | — | — |+| `too_short` | decision | The page body is under 80 characters, too short to hold events. | — | — | — |+| `dream_generated` | decision | Dream-generated pages are never mined for events. | — | — | — |+| `decision_error` | decision | The extraction decision failed for this write; the write itself committed. | `gbrain doctor --json` | agent | — |+| `no_write_decision` | execution | This revision has no recorded write decision (written by an older binary or before this release activated), so only a trusted backfill extracts it. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |+| `superseded` | execution | A newer revision replaced this content before extraction ran; the newer revision carries its own decision. | — | — | — |+| `daily_limit` | execution | The automatic daily limit (chronicle.auto_daily_limit = 200 calls per rolling 24 hours) was used up. | `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50` (preview: `gbrain chronicle-backfill --source <source> --since <YYYY-MM-DD> --limit 50 --dry-run`) | agent | paid |+| `judge_llm_unavailable` | execution | No chat provider is configured on the brain host, so extraction cannot run. | — | user | credentials |+| `no_pricing` | execution | chronicle.job_budget_usd was set explicitly, and gbrain has no price for <provider:model>, so the cap cannot be enforced. | `gbrain pricing set <provider:model> --input <usd-per-1M-input-tokens> --output <usd-per-1M-output-tokens> --source <pricing-page-url>` | agent | — |+| `job_budget_exceeded` | execution | The extraction call cost more than chronicle.job_budget_usd allows for one page. | `gbrain config set chronicle.job_budget_usd 0.50` | agent | paid |+| `chat_error` | execution | The chat provider returned an error; the page retries with backoff. | — | provider | — |+| `judge_truncated` | execution | The extraction output hit chronicle.judge_max_tokens and was cut off, so nothing was written. | `gbrain config set chronicle.judge_max_tokens 8000` | agent | paid |+| `malformed_proposal` | execution | The extraction output was not valid event JSON, so nothing was written; the page is tried again when its content changes. | — | — | — |+| `judge_refused` | execution | The chat model refused or filtered the page; no events were written. | — | — | — |+| `page_not_found` | execution | The page was deleted or renamed before extraction ran. | — | — | — |+<!-- chronicle-reasons:end -->++Don't hand-write `life/events/` pages: extraction owns them and retires events+the page no longer supports. Edit the meeting page instead.diff --git a/src/core/chronicle/reasons.ts b/src/core/chronicle/reasons.tsnew file mode 100644index 0000000000..8286130b12--- /dev/null+++ b/src/core/chronicle/reasons.ts@@ -0,0 +1,173 @@+// Life Chronicle (#5876): the one reason table for automatic event extraction, and the+// `chronicle_backstop` write-receipt field built from it. Docs (docs/guides/life-chronicle.md)+// and tests render from CHRONICLE_REASONS; nothing else spells these codes out.++/**+ * Local equivalent of the agent-operator `Action` (GBRA-42 `src/core/agent-output.ts`), same field+ * names. Stored form: never carries `next` or a rendered command; both are derived at render time.+ */+export type ChronicleEffect = 'paid' | 'destructive' | 'credentials' | 'egress' | 'persistent_install';+export type ChronicleActor = 'agent' | 'user' | 'host_admin' | 'provider';+export interface ChronicleAction {+ argv?: string[];+ preview_argv?: string[];+ consent: ChronicleEffect[];+ actor: ChronicleActor;+ why: string;+ requires_exclusive: boolean;+ inputs?: Array<{ name: string; how: string }>;+}++/** `decision`: decided when the page was written (receipt). `execution`: decided when the chronicle phase ran. */+export type ChronicleStage = 'decision' | 'execution';++export interface ChronicleReasonContext {+ /** Omitted on brain-wide surfaces (doctor, advisor): the pointer then covers every source. */+ sourceId?: string;+ /** The day to scope a backfill pointer to (YYYY-MM-DD, compared with the page's updated date). */+ since: string;+ /** Configured chat model, for the pricing registration command. */+ model?: string;+ dailyLimit?: number;+ recentDays?: number;+}++interface ChronicleReason {+ stage: ChronicleStage;+ meaning: (ctx: ChronicleReasonContext) => string;+ fix?: (ctx: ChronicleReasonContext) => ChronicleAction;+}++/** The backfill pointer every surface emits. Swap here when backfill gains a consent flag. */+export function chronicleBackfillArgv(opts: { sourceId?: string; since: string; limit?: number; dryRun: boolean }): string[] {+ return ['gbrain', 'chronicle-backfill', ...(opts.sourceId ? ['--source', opts.sourceId] : []),+ '--since', opts.since, '--limit', String(opts.limit ?? 50), ...(opts.dryRun ? ['--dry-run'] : [])];+}++const backfill = (actor: ChronicleActor, why: string) => (ctx: ChronicleReasonContext): ChronicleAction => ({+ argv: chronicleBackfillArgv({ sourceId: ctx.sourceId, since: ctx.since, dryRun: false }),+ preview_argv: chronicleBackfillArgv({ sourceId: ctx.sourceId, since: ctx.since, dryRun: true }),+ consent: ['paid'], actor, why, requires_exclusive: false,+});++const FIX_BY_BACKFILL = 'Preview with the dry run, then backfill these pages if the user agrees to one paid chat call per page.';+const FIX_ON_HOST = 'Only the brain host operator can extract these pages: preview and backfill on the brain host if the user agrees to the cost.';++export const CHRONICLE_REASONS = {+ auto_chronicle_off: { stage: 'decision',+ meaning: () => 'Automatic event extraction is off on this brain by choice (`gbrain config set auto_chronicle false`).' },+ auto_chronicle_invalid: { stage: 'decision',+ meaning: () => 'auto_chronicle holds a value that is neither true nor false, so it reads as off.',+ fix: () => ({ argv: ['gbrain', 'config', 'set', 'auto_chronicle', 'true'], consent: ['paid'], actor: 'agent',+ why: 'Ask the user whether automatic extraction should be on (one paid chat call per eligible page) or off (`gbrain config set auto_chronicle false`).',+ requires_exclusive: false }) },+ slug_bound_client: { stage: 'decision',+ meaning: () => 'The writer is confined (slug-bound, delegated or namespace-restricted), so its writes never trigger extraction into life/events/.',+ fix: backfill('host_admin', FIX_ON_HOST) },+ operation_bound_client: { stage: 'decision',+ meaning: () => 'The writer\'s grant lists operations without extract_facts, the permission that covers derived extraction.',+ fix: backfill('host_admin', FIX_ON_HOST) },+ no_extract: { stage: 'decision',+ meaning: () => 'The sync ran with extraction turned off (--no-extract, or a remote sync, which never extracts).',+ fix: backfill('agent', FIX_BY_BACKFILL) },+ history: { stage: 'decision',+ meaning: (ctx) => `The page's own date is more than ${ctx.recentDays ?? 30} days old (chronicle.auto_recent_days); history is extracted only on request.`,+ fix: backfill('agent', FIX_BY_BACKFILL) },+ not_yet_happened: { stage: 'decision',+ meaning: () => 'The calendar event has not ended yet; it is picked up automatically after its end time, with no edit needed.' },+ too_short: { stage: 'decision',+ meaning: () => 'The page body is under 80 characters, too short to hold events.' },+ dream_generated: { stage: 'decision',+ meaning: () => 'Dream-generated pages are never mined for events.' },+ decision_error: { stage: 'decision',+ meaning: () => 'The extraction decision failed for this write; the write itself committed.',+ fix: () => ({ argv: ['gbrain', 'doctor', '--json'], consent: [], actor: 'agent',+ why: 'Read the auto_chronicle check for the cause, then backfill the page if the user agrees.', requires_exclusive: false }) },+ no_write_decision: { stage: 'execution',+ meaning: () => 'This revision has no recorded write decision (written by an older binary or before this release activated), so only a trusted backfill extracts it.',+ fix: backfill('agent', FIX_BY_BACKFILL) },+ superseded: { stage: 'execution',+ meaning: () => 'A newer revision replaced this content before extraction ran; the newer revision carries its own decision.' },+ daily_limit: { stage: 'execution',+ meaning: (ctx) => `The automatic daily limit (chronicle.auto_daily_limit = ${ctx.dailyLimit ?? 200} calls per rolling 24 hours) was used up.`,+ fix: backfill('agent', FIX_BY_BACKFILL) },+ judge_llm_unavailable: { stage: 'execution',+ meaning: () => 'No chat provider is configured on the brain host, so extraction cannot run.',+ fix: () => ({ consent: ['credentials'], actor: 'user', requires_exclusive: false,+ why: 'Ask the user to configure a chat provider key on the brain host (see docs/ai-providers/); pending pages run on the next cycle.' }) },+ no_pricing: { stage: 'execution',+ meaning: (ctx) => `chronicle.job_budget_usd was set explicitly, and gbrain has no price for ${ctx.model ?? 'the chat model'}, so the cap cannot be enforced.`,+ fix: (ctx) => ({ argv: ['gbrain', 'pricing', 'set', ctx.model ?? '<model>', '--input', '<usd-per-1M-input-tokens>',+ '--output', '<usd-per-1M-output-tokens>', '--source', '<pricing-page-url>'], consent: [], actor: 'agent', requires_exclusive: false,+ why: 'Look up the model\'s current price and register it on the brain host; extraction retries on the next cycle.',+ inputs: [{ name: 'usd-per-1M-input-tokens', how: 'the provider pricing page' },+ { name: 'usd-per-1M-output-tokens', how: 'the provider pricing page' },+ { name: 'pricing-page-url', how: 'the URL you read the price from' }] }) },+ job_budget_exceeded: { stage: 'execution',+ meaning: () => 'The extraction call cost more than chronicle.job_budget_usd allows for one page.',+ fix: () => ({ argv: ['gbrain', 'config', 'set', 'chronicle.job_budget_usd', '0.50'], consent: ['paid'], actor: 'agent',+ requires_exclusive: false, why: 'Raising the per-page cap lets long pages finish; ask the user before raising spend.' }) },+ chat_error: { stage: 'execution',+ meaning: () => 'The chat provider returned an error; the page retries with backoff.',+ fix: () => ({ consent: [], actor: 'provider', requires_exclusive: false,+ why: 'Wait for the retry; if it keeps failing, check the provider status and key.' }) },+ judge_truncated: { stage: 'execution',+ meaning: () => 'The extraction output hit chronicle.judge_max_tokens and was cut off, so nothing was written.',+ fix: () => ({ argv: ['gbrain', 'config', 'set', 'chronicle.judge_max_tokens', '8000'], consent: ['paid'], actor: 'agent',+ requires_exclusive: false, why: 'A higher output cap lets event-dense pages finish; ask the user before raising spend.' }) },+ malformed_proposal: { stage: 'execution',+ meaning: () => 'The extraction output was not valid event JSON, so nothing was written; the page is tried again when its content changes.' },+ judge_refused: { stage: 'execution',+ meaning: () => 'The chat model refused or filtered the page; no events were written.' },+ page_not_found: { stage: 'execution',+ meaning: () => 'The page was deleted or renamed before extraction ran.' },+} as const satisfies Record<string, ChronicleReason>;++export type ChronicleReasonCode = keyof typeof CHRONICLE_REASONS;++/** Eligibility reasons for pages that are not chronicle-shaped: the receipt omits the field for them. */+const NOT_CHRONICLE_SHAPED = /^(kind:|diary_excluded$|event_self$|subagent_scratch$)/;++export type ChronicleDecision = { state: 'pending' } | { state: 'skipped'; reason: string };++export type ChronicleBackstopReceipt =+ | { pending: 'next_cycle'; daily_remaining?: number }+ | { skipped: string; stage: ChronicleStage; why: string; fix?: ChronicleAction };++/**+ * The `chronicle_backstop` receipt field (sibling of `facts_backstop`). Omitted (undefined) for pages+ * that are not chronicle-shaped, so ordinary notes carry no `kind:<type>` noise. An unknown reason+ * still reports itself with a doctor pointer rather than disappearing.+ */+export function chronicleBackstopReceipt(decision: ChronicleDecision, ctx: ChronicleReasonContext & { dailyRemaining?: number }): ChronicleBackstopReceipt | undefined {+ if (decision.state === 'pending') {+ return { pending: 'next_cycle', ...(ctx.dailyRemaining === undefined ? {} : { daily_remaining: ctx.dailyRemaining }) };+ }+ if (NOT_CHRONICLE_SHAPED.test(decision.reason)) return undefined;+ const entry: ChronicleReason | undefined = (CHRONICLE_REASONS as Record<string, ChronicleReason>)[decision.reason];+ if (!entry) {+ return { skipped: decision.reason, stage: 'decision', why: `Extraction was skipped (${decision.reason}).`,+ fix: { argv: ['gbrain', 'doctor', '--json'], consent: [], actor: 'agent', requires_exclusive: false,+ why: 'Read the auto_chronicle check for details.' } };+ }+ const fix = entry.fix?.(ctx);+ return { skipped: decision.reason, stage: entry.stage, why: entry.meaning(ctx), ...(fix ? { fix } : {}) };+}++function shellWord(word: string): string {+ return /^[\w.:/@+=<>-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;+}++/** Markdown reason table for docs/guides/life-chronicle.md (rendered with placeholder values). */+export function renderChronicleReasonTable(): string {+ const ctx: ChronicleReasonContext = { sourceId: '<source>', since: '<YYYY-MM-DD>', model: '<provider:model>', dailyLimit: 200, recentDays: 30 };+ const rows = Object.entries(CHRONICLE_REASONS).map(([code, reason]) => {+ const entry: ChronicleReason = reason;+ const fix = entry.fix?.(ctx);+ const command = fix?.argv ? `\`${fix.argv.map(shellWord).join(' ')}\`` : '—';+ const preview = fix?.preview_argv ? ` (preview: \`${fix.preview_argv.map(shellWord).join(' ')}\`)` : '';+ const consent = fix && fix.consent.length > 0 ? fix.consent.join(', ') : '—';+ return `| \`${code}\` | ${entry.stage} | ${entry.meaning(ctx)} | ${fix ? `${command}${preview}` : '—'} | ${fix?.actor ?? '—'} | ${consent} |`;+ });+ return ['| Code | Stage | Meaning | Fix | Who acts | Consent |', '|---|---|---|---|---|---|', ...rows].join('\n');+}diff --git a/test/chronicle-reasons-5876.test.ts b/test/chronicle-reasons-5876.test.tsnew file mode 100644index 0000000000..d324d1f2d1--- /dev/null+++ b/test/chronicle-reasons-5876.test.ts@@ -0,0 +1,82 @@+/**+ * #5876 (T12): the `chronicle_backstop` receipt field and the one reason table.+ *+ * Protects: pending writes report `{ pending: 'next_cycle', daily_remaining }`; skips carry the+ * code, stage, why and a stored fix Action (argv/preview_argv/consent/actor, never `next`) with+ * real values; pages that are not chronicle-shaped get no field; the guide's table is rendered+ * from CHRONICLE_REASONS.+ * Fails when: receipts drift from facts_backstop's plain-field shape, an ordinary note grows+ * `kind:<type>` noise, a paid fix loses its consent, or the docs table drifts from the code.+ * Seams: none. Regenerate the docs table with GBRAIN_TEST_UPDATE_GOLDENS=1.+ */+import { describe, expect, test } from 'bun:test';+import { readFileSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { CHRONICLE_REASONS, chronicleBackstopReceipt, renderChronicleReasonTable } from '../src/core/chronicle/reasons.ts';++const GUIDE = join(import.meta.dir, '..', 'docs', 'guides', 'life-chronicle.md');+const ctx = { sourceId: 'work', since: '2026-10-04', dailyLimit: 200, recentDays: 30, model: 'openai:gpt-new' };++describe('chronicle_backstop receipt', () => {+ test('pending is a plain hint with the remaining daily calls', () => {+ expect(chronicleBackstopReceipt({ state: 'pending' }, { ...ctx, dailyRemaining: 187 }))+ .toEqual({ pending: 'next_cycle', daily_remaining: 187 });+ });++ test('a history skip names the scoped backfill with its preview, paid consent and real values', () => {+ expect(chronicleBackstopReceipt({ state: 'skipped', reason: 'history' }, ctx)).toEqual({+ skipped: 'history', stage: 'decision',+ why: "The page's own date is more than 30 days old (chronicle.auto_recent_days); history is extracted only on request.",+ fix: {+ argv: ['gbrain', 'chronicle-backfill', '--source', 'work', '--since', '2026-10-04', '--limit', '50'],+ preview_argv: ['gbrain', 'chronicle-backfill', '--source', 'work', '--since', '2026-10-04', '--limit', '50', '--dry-run'],+ consent: ['paid'], actor: 'agent', requires_exclusive: false,+ why: 'Preview with the dry run, then backfill these pages if the user agrees to one paid chat call per page.',+ },+ });+ });++ test('confined writers route the fix to the brain host; off-by-choice carries no fix', () => {+ expect(chronicleBackstopReceipt({ state: 'skipped', reason: 'slug_bound_client' }, ctx)).toMatchObject({ fix: { actor: 'host_admin' } });+ const off = chronicleBackstopReceipt({ state: 'skipped', reason: 'auto_chronicle_off' }, ctx);+ expect(off).toMatchObject({ skipped: 'auto_chronicle_off', stage: 'decision' });+ expect(off && 'fix' in off).toBe(false);+ });++ test('pages that are not chronicle-shaped get no field', () => {+ for (const reason of ['kind:note', 'kind:person', 'diary_excluded', 'event_self', 'subagent_scratch']) {+ expect(chronicleBackstopReceipt({ state: 'skipped', reason }, ctx)).toBeUndefined();+ }+ });++ test('no stored fix carries `next` or a rendered command', () => {+ for (const reason of Object.keys(CHRONICLE_REASONS)) {+ const r = chronicleBackstopReceipt({ state: 'skipped', reason }, ctx);+ expect(r).toBeDefined();+ if (r && 'fix' in r && r.fix) {+ expect(Object.keys(r.fix)).not.toContain('next');+ expect(Object.keys(r.fix)).not.toContain('command');+ }+ }+ });++ test('an unknown reason still reports itself with a doctor pointer', () => {+ expect(chronicleBackstopReceipt({ state: 'skipped', reason: 'something_new' }, ctx))+ .toMatchObject({ skipped: 'something_new', fix: { argv: ['gbrain', 'doctor', '--json'] } });+ });+});++describe('docs/guides/life-chronicle.md reason table', () => {+ test('matches CHRONICLE_REASONS', () => {+ const doc = readFileSync(GUIDE, 'utf8');+ const begin = '<!-- chronicle-reasons:begin -->\n';+ const end = '\n<!-- chronicle-reasons:end -->';+ const block = doc.slice(doc.indexOf(begin) + begin.length, doc.indexOf(end));+ const expected = renderChronicleReasonTable();+ if (process.env.GBRAIN_TEST_UPDATE_GOLDENS === '1' && block !== expected) {+ writeFileSync(GUIDE, doc.replace(block, expected));+ return;+ }+ expect(block).toBe(expected);+ });+});