Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(chronicle): post-upgrade notice and migration guide for the default flip (#5876)
garrytanf45f4aa02444
diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.mdindex cae5e0f277..b01d18d61c 100644--- a/docs/guides/troubleshooting.md+++ b/docs/guides/troubleshooting.md@@ -221,25 +221,8 @@ at the deadline).**Say to your agent:** *"Why aren't my meetings showing up as timeline events?"*-`gbrain config set auto_chronicle true` is accepted, but in this version no-write or cycle step reads it: nothing enqueues chronicle extraction, so new-meetings and conversations are not swept into `life/events/` pages on their-own. `gbrain doctor` reports this as the `auto_chronicle` check (code-`auto_chronicle_no_effect`) and the advisor shows the same finding.--Sweep recent meetings by hand instead. Preview first, then run it:--```bash-gbrain chronicle-backfill --dry-run-gbrain chronicle-backfill-```--To clear the setting so the warning stops:--```bash-gbrain config unset auto_chronicle-```--The backfill is not yet idempotent, so run it when you want new events rather-than on a schedule. Restoring the automatic trigger is tracked for a later-release.+Automatic event extraction works again and is on by default. See the+[Life Chronicle guide](life-chronicle.md) for what qualifies, the cost, the+three-step check, and the skip codes. `gbrain doctor` reports it as the+`auto_chronicle` check. To turn it off, run+`gbrain config set auto_chronicle false`.diff --git a/skills/migrations/vNEXT-auto-chronicle.md b/skills/migrations/vNEXT-auto-chronicle.mdnew file mode 100644index 0000000000..fbb4cc0800--- /dev/null+++ b/skills/migrations/vNEXT-auto-chronicle.md@@ -0,0 +1,73 @@+# Upgrade: automatic event extraction is on (auto_chronicle)++<!-- Integrator: rename to skills/migrations/v<this release>.md and add the+ schema-migration numbers for the chronicle ledger in step 1. -->++This release turns automatic event extraction back on, and on by default. When+the user saves a meeting, conversation or calendar page, gbrain turns it into+timeline events (`life/events/`) so `gbrain day <date>` can answer "what+happened". Each eligible page costs one paid chat call. Tell the user before+anything else in this file.++Anything that spends money needs the user's agreement. Never run+`gbrain chronicle-backfill` without `--dry-run`, or `gbrain dream --phase+chronicle`, on the user's behalf without asking.++1. **Finish the migration.** `gbrain upgrade` runs it. To be sure, run on the+ brain host:+ ```bash+ gbrain apply-migrations --yes --no-autopilot-install+ ```+ It creates the `chronicle_page_state` ledger, the record of which page+ content was extracted. It rewrites no existing rows. Restart every+ `gbrain serve`, autopilot and worker.++2. **Relay the cost and ask.** Say to the user, with the real numbers from+ `gbrain doctor` (`auto_chronicle_default_on`):+ - Each new or changed meeting, conversation or calendar page dated within+ the last 30 days gets one chat call, capped at `chronicle.job_budget_usd`+ ($0.25 by default) per page.+ - At most `chronicle.auto_daily_limit` calls run per rolling day (200 by+ default). The worst case is limit x cap, $50 per day at the defaults. That+ is a per-page cap times a call count, not a daily budget; typical pages+ cost far less.+ - If gbrain has no price for the configured chat model, the per-page cap+ cannot apply. Calls still run, limited by the daily count. A cap the user+ sets explicitly refuses an unpriced model with `no_pricing` instead.+ - Page text is sent to the configured chat provider. Events from a private+ page stay private.+ - Pages already in the brain are not swept. Only pages written after this+ upgrade run automatically.++ Then record the answer. Either command clears the doctor and advisor+ notice:+ ```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` must ask too: that setting+ had no effect before this release.++3. **Know how it runs.** The chronicle phase of the maintenance cycle extracts+ pending pages. With autopilot running, nothing else is needed. On PGLite+ without autopilot, or to run pending pages now (paid):+ ```bash+ gbrain dream --phase chronicle+ ```+ No chat provider configured means nothing runs; doctor names the missing+ provider.++4. **Check one page.** After writing a meeting page, its write receipt carries+ `chronicle_backstop: { "pending": "next_cycle" }`, or+ `{ "skipped": "<code>", "why": ..., "fix": ... }`. After the phase runs,+ `gbrain day <date>` shows the events. Every code, its meaning and its fix+ are in `docs/guides/life-chronicle.md`.++5. **History is on request.** Backfill spends money. Preview it, show the user+ the count, and run it only if they agree:+ ```bash+ gbrain chronicle-backfill --since <YYYY-MM-DD> --limit 50 --dry-run+ ```++The opt-out is always `gbrain config set auto_chronicle false`. Unsetting the+key restores the default, which is on.diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.tsindex 3019c3f6bc..604c010cb1 100644--- a/src/commands/upgrade.ts+++ b/src/commands/upgrade.ts@@ -707,6 +707,13 @@ export async function runPostUpgrade(args: string[] = []): Promise<void> {// Banner is cosmetic; never block the upgrade.}+ // #5876: auto_chronicle now defaults on. One-shot [AGENT] notice naming+ // the per-page cost, the daily ceiling and the opt-out; best-effort.+ {+ const { printAutoChronicleUpgradeNotice } = await import('../core/chronicle/upgrade-notice.ts');+ await printAutoChronicleUpgradeNotice(engine);+ }+// Ambient-writeback consent ask (WP8): one-shot for EXISTING installs// upgrading into the feature. Personal brains only; double-gated on// its own sentinel + the setting being unset; [AGENT]-relayed;diff --git a/src/core/chronicle/upgrade-notice.ts b/src/core/chronicle/upgrade-notice.tsnew file mode 100644index 0000000000..0aa771b78d--- /dev/null+++ b/src/core/chronicle/upgrade-notice.ts@@ -0,0 +1,78 @@+// #5876: one-shot post-upgrade notice for the auto_chronicle default flip. Printed by+// `gbrain post-upgrade` while the operator has not answered the change (key unset, or an explicit+// `true` written before this release, when it had no effect). The doctor/advisor+// `auto_chronicle_default_on` notice stays visible after this prints, until the key is set.+import type { BrainEngine } from '../engine.ts';+import {+ AUTO_CHRONICLE_KEEP_ARGV, AUTO_CHRONICLE_OPT_OUT_ARGV, CHRONICLE_NOTICE_SHOWN_KEY, autoChronicleNeedsAcknowledgement,+ readChronicleSettings,+} from './config.ts';+import { chronicleBackfillArgv } from './reasons.ts';++export interface ChronicleProviderView {+ /** Configured chat model id, or null when it cannot be resolved. */+ model: string | null;+ priced: boolean;+ chatAvailable: boolean;+}++async function providerView(engine: BrainEngine): Promise<ChronicleProviderView> {+ try {+ const { getChatModel, isAvailable } = await import('../ai/gateway.ts');+ const { isModelPriceable, loadPricingOverrides } = await import('../budget/budget-tracker.ts');+ const model = getChatModel();+ return { model, priced: isModelPriceable(model, 'chat', await loadPricingOverrides(engine)), chatAvailable: isAvailable('chat') };+ } catch {+ return { model: null, priced: false, chatAvailable: false };+ }+}++/** The notice lines, or null when it must not print (already shown, opted out, or acknowledged). */+export async function autoChronicleUpgradeNotice(engine: BrainEngine, view?: ChronicleProviderView): Promise<string[] | null> {+ const shown = await engine.getConfig(CHRONICLE_NOTICE_SHOWN_KEY);+ if (shown != null && shown.trim() !== '') return null;+ if (!(await autoChronicleNeedsAcknowledgement(engine))) return null;+ const settings = await readChronicleSettings(engine);+ const provider = view ?? await providerView(engine);+ const ceiling = settings.autoDailyLimit * settings.jobBudgetUsd;+ const since = new Date(Date.now() - 30 * 86_400_000).toISOString().slice(0, 10);+ const runs = engine.kind === 'pglite'+ ? 'On this PGLite brain, pending pages run inside the autopilot cycle; `gbrain dream --phase chronicle` runs them now.'+ : 'On this Postgres brain, pending pages run in the autopilot cycle; `gbrain dream --phase chronicle` runs them now.';+ const cost = provider.priced+ ? `Worst case: ${settings.autoDailyLimit} calls/day x $${settings.jobBudgetUsd.toFixed(2)} per-page cap = $${ceiling.toFixed(2)}/day with ${provider.model}. ` ++ 'The cap is per page, not a daily budget; typical pages cost far less.'+ : `gbrain has no price for ${provider.model ?? 'the configured chat model'}, so the per-page cap ($${settings.jobBudgetUsd.toFixed(2)}) cannot apply: ` ++ `calls are unbounded in dollars (still at most ${settings.autoDailyLimit} per day).`;+ return [+ '',+ '═══════════════════════════════════════════════════════════════',+ '[gbrain] Automatic event extraction (auto_chronicle) is now ON by default.',+ '[gbrain] Each new or changed meeting, conversation or calendar page gets one',+ '[gbrain] paid chat call that turns it into timeline events (life/events/).',+ '═══════════════════════════════════════════════════════════════',+ `[AGENT] Relay this to the user: it spends money and sends page text to the configured chat provider${provider.model ? ` (${provider.model})` : ''}.`,+ `[AGENT] ${cost}`,+ `[AGENT] Only pages written after this upgrade, dated within ${settings.autoRecentDays} days, run automatically; history is not swept.`,+ `[AGENT] ${runs}`,+ ...(provider.chatAvailable ? [] : ['[AGENT] No chat provider is configured, so nothing runs until the user sets one up.']),+ `[AGENT] Keep it (records the user's answer): ${AUTO_CHRONICLE_KEEP_ARGV.join(' ')}`,+ `[AGENT] Opt out: ${AUTO_CHRONICLE_OPT_OUT_ARGV.join(' ')}`,+ `[AGENT] History is paid too; ask before running it. Preview: ${chronicleBackfillArgv({ since, dryRun: true }).join(' ')}`,+ '[AGENT] Guide: docs/guides/life-chronicle.md',+ '',+ ];+}++/** Prints the notice once and stamps it. Best-effort: never blocks the upgrade. */+export async function printAutoChronicleUpgradeNotice(engine: BrainEngine, log: (line: string) => void = console.log): Promise<boolean> {+ try {+ const lines = await autoChronicleUpgradeNotice(engine);+ if (!lines) return false;+ for (const line of lines) log(line);+ await engine.setConfig(CHRONICLE_NOTICE_SHOWN_KEY, new Date().toISOString());+ return true;+ } catch {+ return false;+ }+}diff --git a/test/chronicle-upgrade-notice-5876.test.ts b/test/chronicle-upgrade-notice-5876.test.tsnew file mode 100644index 0000000000..4f88ca886f--- /dev/null+++ b/test/chronicle-upgrade-notice-5876.test.ts@@ -0,0 +1,71 @@+/**+ * #5876 (T13): the post-upgrade notice for the auto_chronicle default flip, and the opt-out wording.+ *+ * Protects: the notice prints once while the operator has not answered (unset, or an explicit `true`+ * written before this release), never after `config set auto_chronicle` or on an opted-out brain; it+ * names the per-page cap, the daily ceiling (or that an unpriced model has no cap), provider egress,+ * the missing-provider case, the set-false opt-out and a previewed backfill; no surface in src/, docs/+ * or skills/ tells anyone to clear auto_chronicle with `config unset` (unset now means on).+ * Fails when: the notice repeats, is skipped for legacy-true brains, drops the cost or opt-out, or+ * stale unset advice comes back.+ * Seams: the provider view is passed in (pricing/provider state is config, not under test here).+ */+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { CHRONICLE_ACK_KEY, CHRONICLE_NOTICE_SHOWN_KEY } from '../src/core/chronicle/config.ts';+import { autoChronicleUpgradeNotice, printAutoChronicleUpgradeNotice } from '../src/core/chronicle/upgrade-notice.ts';++let engine: PGLiteEngine;+const priced = { model: 'anthropic:claude-sonnet-4-6', priced: true, chatAvailable: true };++beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); }, 120_000);+afterAll(async () => { await engine.disconnect(); });+beforeEach(async () => { for (const k of ['auto_chronicle', CHRONICLE_ACK_KEY, CHRONICLE_NOTICE_SHOWN_KEY]) await engine.unsetConfig(k); });++describe('auto_chronicle upgrade notice', () => {+ test('unset: names cost, ceiling, egress, opt-out and a previewed backfill', async () => {+ const text = (await autoChronicleUpgradeNotice(engine, priced))!.join('\n');+ expect(text).toContain('now ON by default');+ expect(text).toContain('200 calls/day x $0.25 per-page cap = $50.00/day with anthropic:claude-sonnet-4-6');+ expect(text).toContain('sends page text to the configured chat provider');+ expect(text).toContain('[AGENT] Opt out: gbrain config set auto_chronicle false');+ expect(text).toMatch(/gbrain chronicle-backfill --since \d{4}-\d{2}-\d{2} --limit 50 --dry-run/);+ expect(text).toContain('gbrain dream --phase chronicle');+ expect(text).not.toContain('No chat provider is configured');+ });++ test('unpriced model and no provider are stated plainly', async () => {+ const text = (await autoChronicleUpgradeNotice(engine, { model: 'openai:gpt-new', priced: false, chatAvailable: false }))!.join('\n');+ expect(text).toContain('no price for openai:gpt-new');+ expect(text).toContain('No chat provider is configured, so nothing runs');+ });++ test('prints once, then never again', async () => {+ const lines: string[] = [];+ expect(await printAutoChronicleUpgradeNotice(engine, (l) => lines.push(l))).toBe(true);+ expect(lines.join('\n')).toContain('auto_chronicle');+ expect(await engine.getConfig(CHRONICLE_NOTICE_SHOWN_KEY)).not.toBeNull();+ expect(await printAutoChronicleUpgradeNotice(engine, (l) => lines.push(l))).toBe(false);+ });++ test('a pre-release explicit true is notified; an answered or opted-out brain is not', async () => {+ await engine.setConfig('auto_chronicle', 'true');+ expect(await autoChronicleUpgradeNotice(engine, priced)).not.toBeNull();+ await engine.setConfig(CHRONICLE_ACK_KEY, '2026-10-04T00:00:00Z');+ expect(await autoChronicleUpgradeNotice(engine, priced)).toBeNull();+ await engine.unsetConfig(CHRONICLE_ACK_KEY);+ await engine.setConfig('auto_chronicle', 'false');+ expect(await autoChronicleUpgradeNotice(engine, priced)).toBeNull();+ });+});++describe('opt-out wording guard', () => {+ test('no surface tells anyone to clear auto_chronicle with config unset', () => {+ // Unset restores the default, which is now on; the only opt-out is `gbrain config set auto_chronicle false`.+ const result = Bun.spawnSync(['git', 'grep', '-n', '-I', '-E', 'config unset (--pattern )?auto_chronicle', '--', 'src', 'docs', 'skills'],+ { cwd: `${import.meta.dir}/..` });+ const hits = result.stdout.toString().split('\n').filter(Boolean)+ .filter((line) => !line.startsWith('docs/fix-wave-notes/') && !line.startsWith('docs/test-audit/'));+ expect(hits).toEqual([]);+ });+});