Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(chronicle): keep runConfig and runPostUpgrade within their size ratchets (#5876)

garrytan9c85d8644da5
diff --git a/scripts/function-size-baseline.tsv b/scripts/function-size-baseline.tsv
index 65e75800a5..cda6ab32e2 100644
--- a/scripts/function-size-baseline.tsv
+++ b/scripts/function-size-baseline.tsv
@@ -25,7 +25,6 @@ src/commands/migrate-embeddings.ts runMigrateEmbeddings 325 seed: W5 baseline, r
src/commands/migrate-engine.ts runMigrateEngine 405 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/serve.ts installStdioLifecycle 315 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/sources.ts runAdd 365 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 fix wave 4 #5673: connector sources print that autopilot keeps them synced after the first sync
-src/commands/upgrade.ts runPostUpgrade 319 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/ai/gateway.ts chat 311 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/bootstrap/harness.ts applyHarness 1167 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/brainstorm/orchestrator.ts _runBrainstormInner 413 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 #5890 close-set spreads INTERNAL_BREADTH_SEARCH_OPTS
diff --git a/src/commands/config.ts b/src/commands/config.ts
index 8dbec73faa..2f61d0230e 100644
--- a/src/commands/config.ts
+++ b/src/commands/config.ts
@@ -278,15 +278,19 @@ export async function tryRunConfigEngineFree(args: string[]): Promise<boolean> {
/**
* System One: decide.* keys validate at set time (enums, numeric ranges), and a
* decide.slots.* write prints the requested-versus-effective mode line after it
- * persists (best-effort).
+ * persists (best-effort). #5876: auto_chronicle and chronicle.* gate paid
+ * extraction, so they validate here too, and an explicit auto_chronicle set
+ * records the operator's answer to the default-on change.
*/
-async function setConfigWithDecideHooks(engine: BrainEngine, key: string, value: string): Promise<void> {
+async function setConfigWithDecideHooks(engine: BrainEngine, key: string, value: string, force = false): Promise<void> {
if (key.startsWith('decide.')) {
const { validateDecideConfigValue } = await import('../core/ai/decide/config.ts');
const err = validateDecideConfigValue(key, value);
if (err) { console.error(`[config] ${err}`); process.exit(1); }
}
+ if (key === 'auto_chronicle' || key.startsWith('chronicle.')) await refuseInvalidChronicleValue(key, value, force);
await engine.setConfig(key, value);
+ if (key === 'auto_chronicle') await acknowledgeAutoChronicle(engine, value);
if (!key.startsWith('decide.slots.')) return;
try {
const { printEffectiveModeLines } = await import('./decide.ts');
@@ -294,6 +298,23 @@ async function setConfigWithDecideHooks(engine: BrainEngine, key: string, value:
} catch { /* the value already persisted */ }
}
+const AUTO_CHRONICLE_UNSET_NOTE = '\nauto_chronicle now uses its default, which is ON: eligible new or changed meeting, conversation and calendar pages each get one paid extraction call.' +
+ '\nTo turn automatic extraction off, run: gbrain config set auto_chronicle false';
+
+/** #5876: refuse unknown chronicle.* leaves (unless forced) and out-of-range values; nothing is written. */
+async function refuseInvalidChronicleValue(key: string, value: string, force: boolean): Promise<void> {
+ const { validateChronicleConfigValue, CHRONICLE_CONFIG_KEYS } = await import('../core/chronicle/config.ts');
+ if (key.startsWith('chronicle.') && !CHRONICLE_CONFIG_KEYS.includes(key) && !force) {
+ const { suggestNearest } = await import('../core/levenshtein.ts');
+ const suggestion = suggestNearest(key, [...CHRONICLE_CONFIG_KEYS], 3);
+ console.error(`[config] Unknown config key "${key}".${suggestion ? ` Did you mean "${suggestion}"?` : ''}`);
+ console.error(`[config] chronicle keys: ${CHRONICLE_CONFIG_KEYS.join(', ')}. Nothing was written.`);
+ process.exit(1);
+ }
+ const err = validateChronicleConfigValue(key, value);
+ if (err) { console.error(`[config] ${err}`); process.exit(1); }
+}
+
/**
* #5876: an explicit `config set auto_chronicle` answers the default-on change, which clears the
* durable doctor/advisor `auto_chronicle_default_on` notice. Best-effort: the value already persisted.
@@ -680,12 +701,8 @@ export async function runConfig(engine: BrainEngine, args: string[]) {
}
const n = await engine.unsetConfig(key);
if (n > 0) {
- console.log(`Unset ${key}`);
+ console.log(`Unset ${key}${key === 'auto_chronicle' ? AUTO_CHRONICLE_UNSET_NOTE : ''}`);
if (key === 'facts.default_visibility') await restampVisibilityPosture(null);
- if (key === 'auto_chronicle') {
- console.log('auto_chronicle now uses its default, which is ON: eligible new or changed meeting, conversation and calendar pages each get one paid extraction call.');
- console.log('To turn automatic extraction off, run: gbrain config set auto_chronicle false');
- }
} else {
console.error(`Config key not found: ${key}`);
process.exit(1);
@@ -1109,21 +1126,6 @@ export async function runConfig(engine: BrainEngine, args: string[]) {
}
}
- // #5876: auto_chronicle and chronicle.* knobs gate paid extraction, so a
- // typo is refused here instead of silently falling back at run time.
- if (key === 'auto_chronicle' || key.startsWith('chronicle.')) {
- const { validateChronicleConfigValue, CHRONICLE_CONFIG_KEYS } = await import('../core/chronicle/config.ts');
- if (key.startsWith('chronicle.') && !CHRONICLE_CONFIG_KEYS.includes(key) && !forceFlag) {
- const { suggestNearest } = await import('../core/levenshtein.ts');
- const suggestion = suggestNearest(key, [...CHRONICLE_CONFIG_KEYS], 3);
- console.error(`[config] Unknown config key "${key}".${suggestion ? ` Did you mean "${suggestion}"?` : ''}`);
- console.error(`[config] chronicle keys: ${CHRONICLE_CONFIG_KEYS.join(', ')}. Nothing was written.`);
- process.exit(1);
- }
- const err = validateChronicleConfigValue(key, value);
- if (err) { console.error(`[config] ${err}`); process.exit(1); }
- }
-
if (key === 'embedding_columns') {
try {
const parsed = JSON.parse(value);
@@ -1235,13 +1237,12 @@ export async function runConfig(engine: BrainEngine, args: string[]) {
}
}
- await setConfigWithDecideHooks(engine, key, value);
+ await setConfigWithDecideHooks(engine, key, value, forceFlag);
// v0.36.x #892: redact sensitive values in confirmation output. API
// keys / tokens / passwords are commonly set from terminals with
// scrollback; echoing the raw value to stderr leaks the secret.
console.log(`Set ${key} = ${redactConfigValue(key, value)}`);
if (key === 'facts.default_visibility') await restampVisibilityPosture(value);
- if (key === 'auto_chronicle') await acknowledgeAutoChronicle(engine, value);
// v0.40.3.0 (D3 + Phase 2B): mode-switch UX. Fires only on
// search.mode writes. Honors GBRAIN_NO_MODE_SWITCH_UX=1 + non-TTY.
diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts
index 604c010cb1..17c5bae5e7 100644
--- a/src/commands/upgrade.ts
+++ b/src/commands/upgrade.ts
@@ -1,3 +1,4 @@
+import type { BrainEngine } from '../core/engine.ts';
import { execSync, execFileSync, spawnSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync, realpathSync } from 'fs';
import { basename, join, dirname, resolve } from 'path';
@@ -523,6 +524,58 @@ function saveUpgradeState(oldVersion: string, newVersion: string) {
* skills/migrations/*.md, so compiled binaries see the same set source
* installs do.
*/
+/**
+ * v0.32.3 search-lite mode banner, moved out of runPostUpgrade unchanged.
+ */
+async function printSearchModeUpgradeBanner(engine: BrainEngine): Promise<void> {
+ // v0.32.3 search-lite mode banner. One-shot: fires at most once per
+ // install (state persisted via `search.mode_upgrade_notice_shown`).
+ // Reframes from "behavior is regressing" to "named modes available"
+ // per [CDX-1+2+3]: the production query op still defaults expand=true
+ // and limit=20 — Garry's behavior is NOT regressing.
+ try {
+ const shown = await engine.getConfig('search.mode_upgrade_notice_shown');
+ const existingMode = await engine.getConfig('search.mode');
+ if (shown !== 'true' && !existingMode) {
+ console.log('');
+ console.log('═══════════════════════════════════════════════════════════════');
+ console.log('[gbrain] v0.32.3 added named search modes (conservative/balanced/tokenmax).');
+ console.log('[gbrain] Your current behavior is unchanged — the `query` op still defaults');
+ console.log('[gbrain] expand=true and limit=20, same as v0.31.x.');
+ console.log('═══════════════════════════════════════════════════════════════');
+ console.log('');
+ console.log('[AGENT] Relay this matrix to your operator and ask which mode they want.');
+ console.log('[AGENT] Recommended default: tokenmax (preserves current retrieval shape).');
+ console.log('[AGENT] Run `gbrain config set search.mode <mode>` after they decide.');
+ console.log('');
+ console.log('Per-query cost @ 10K queries/mo (typical single-user volume):');
+ console.log('');
+ console.log(' Haiku 4.5 Sonnet 4.6 Opus 4.7');
+ console.log(' ($1/M) ($3/M) ($5/M)');
+ console.log(' conservative $40/mo $120/mo $200/mo');
+ console.log(' balanced $100/mo $300/mo $500/mo');
+ console.log(' tokenmax $200/mo $600/mo $1,000/mo');
+ console.log('');
+ console.log(' (scales linearly — multiply by 10 for 100K/mo)');
+ console.log(' 25x corner-to-corner spread. Natural diagonal pairings span ~4x.');
+ console.log('');
+ console.log('To pick:');
+ console.log(' gbrain search modes # see what is running');
+ console.log(' gbrain config set search.mode <conservative|balanced|tokenmax>');
+ console.log(' gbrain search tune # data-driven recommendations');
+ console.log('');
+ console.log('tokenmax bumps limit to 50 (current default is 20). To preserve');
+ console.log('your EXACT current shape:');
+ console.log(' gbrain config set search.mode tokenmax');
+ console.log(' gbrain config set search.searchLimit 20');
+ console.log('');
+ await engine.setConfig('search.mode_upgrade_notice_shown', 'true');
+ }
+ } catch {
+ // Banner is cosmetic; never block the upgrade.
+ }
+}
+
/**
* v0.42 self-upgrade setup (file plane; idempotent). Default existing installs
* to `notify` (a nudge, not autonomy — `auto` stays an explicit opt-in), show a
@@ -660,59 +713,11 @@ export async function runPostUpgrade(args: string[] = []): Promise<void> {
await engine.initSchema();
console.log(' Schema up to date.');
- // v0.32.3 search-lite mode banner. One-shot: fires at most once per
- // install (state persisted via `search.mode_upgrade_notice_shown`).
- // Reframes from "behavior is regressing" to "named modes available"
- // per [CDX-1+2+3]: the production query op still defaults expand=true
- // and limit=20 — Garry's behavior is NOT regressing.
- try {
- const shown = await engine.getConfig('search.mode_upgrade_notice_shown');
- const existingMode = await engine.getConfig('search.mode');
- if (shown !== 'true' && !existingMode) {
- console.log('');
- console.log('═══════════════════════════════════════════════════════════════');
- console.log('[gbrain] v0.32.3 added named search modes (conservative/balanced/tokenmax).');
- console.log('[gbrain] Your current behavior is unchanged — the `query` op still defaults');
- console.log('[gbrain] expand=true and limit=20, same as v0.31.x.');
- console.log('═══════════════════════════════════════════════════════════════');
- console.log('');
- console.log('[AGENT] Relay this matrix to your operator and ask which mode they want.');
- console.log('[AGENT] Recommended default: tokenmax (preserves current retrieval shape).');
- console.log('[AGENT] Run `gbrain config set search.mode <mode>` after they decide.');
- console.log('');
- console.log('Per-query cost @ 10K queries/mo (typical single-user volume):');
- console.log('');
- console.log(' Haiku 4.5 Sonnet 4.6 Opus 4.7');
- console.log(' ($1/M) ($3/M) ($5/M)');
- console.log(' conservative $40/mo $120/mo $200/mo');
- console.log(' balanced $100/mo $300/mo $500/mo');
- console.log(' tokenmax $200/mo $600/mo $1,000/mo');
- console.log('');
- console.log(' (scales linearly — multiply by 10 for 100K/mo)');
- console.log(' 25x corner-to-corner spread. Natural diagonal pairings span ~4x.');
- console.log('');
- console.log('To pick:');
- console.log(' gbrain search modes # see what is running');
- console.log(' gbrain config set search.mode <conservative|balanced|tokenmax>');
- console.log(' gbrain search tune # data-driven recommendations');
- console.log('');
- console.log('tokenmax bumps limit to 50 (current default is 20). To preserve');
- console.log('your EXACT current shape:');
- console.log(' gbrain config set search.mode tokenmax');
- console.log(' gbrain config set search.searchLimit 20');
- console.log('');
- await engine.setConfig('search.mode_upgrade_notice_shown', 'true');
- }
- } catch {
- // Banner is cosmetic; never block the upgrade.
- }
+ // v0.32.3 search-lite mode banner (one-shot, `search.mode_upgrade_notice_shown`).
+ await printSearchModeUpgradeBanner(engine);
- // #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);
- }
+ // #5876: auto_chronicle now defaults on; one-shot [AGENT] cost + opt-out notice, best-effort.
+ await (await import('../core/chronicle/upgrade-notice.ts')).printAutoChronicleUpgradeNotice(engine);
// Ambient-writeback consent ask (WP8): one-shot for EXISTING installs
// upgrading into the feature. Personal brains only; double-gated on
diff --git a/src/core/config.ts b/src/core/config.ts
index 0263b9508c..fd090f7877 100644
--- a/src/core/config.ts
+++ b/src/core/config.ts
@@ -1572,12 +1572,7 @@ export const KNOWN_CONFIG_KEYS: readonly string[] = [
// pages overflowed the old hardcoded 1500 and were misrecorded as
// no_events; the cap is now configurable and truncation is surfaced.
'chronicle.judge_max_tokens',
- // #5876: automatic extraction rails, validated at `config set` by
- // core/chronicle/config.ts (CHRONICLE_NUMERIC_KEYS).
- 'chronicle.job_budget_usd',
- 'chronicle.auto_daily_limit',
- 'chronicle.auto_recent_days',
- 'chronicle.auto_settle_seconds',
+ 'chronicle.job_budget_usd', 'chronicle.auto_daily_limit', 'chronicle.auto_recent_days', 'chronicle.auto_settle_seconds', // #5876 rails (chronicle/config.ts validates)
// Takes bootstrap (v0.41.18.0, A12). The onboard remediation's two-gate
// consent reads this key, and enabling it is the documented path to
// `gbrain takes extract --from-pages` — same unregistered-key class.