Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(cli): print one upgrade-available line per version (#7147)
garrytanf2368405ac8d
diff --git a/docs/guides/upgrades-auto-update.md b/docs/guides/upgrades-auto-update.mdindex 5bd5a01944..7fce736080 100644--- a/docs/guides/upgrades-auto-update.md+++ b/docs/guides/upgrades-auto-update.md@@ -20,9 +20,10 @@ schema. The user gets new capabilities automatically.gbrain stays current the way gstack does: it rides invocation frequency. Athrottled, cache-read-only check runs at the start of every `gbrain` invocation-(CLI and MCP) and emits an `UPGRADE_AVAILABLE <old> <new>` marker on stderr. The-raw marker line is suppressed when stderr is an interactive TTY (a human sees-only the plain `gbrain X -> Y available` sentence, not the machine token); set+(CLI and MCP) and emits an `UPGRADE_AVAILABLE <old> <new>` marker on stderr,+once per 30 minutes per version under one GBRAIN_HOME (a newer version shows at+once). It is one line: when stderr is an interactive TTY a human sees only the+plain `gbrain X -> Y available` sentence instead of the machine token; set`GBRAIN_FORCE_UPGRADE_MARKER=1` if an agent harness parses the token but runsunder a PTY. `<old>` is always the RUNNING binary's version, so a stale orforeign-written cache never nags about an upgrade this binary already has. Nodiff --git a/plugin/skills/gbrain-upgrade/SKILL.md b/plugin/skills/gbrain-upgrade/SKILL.mdindex 7b82f10801..98e86763fc 100644--- a/plugin/skills/gbrain-upgrade/SKILL.md+++ b/plugin/skills/gbrain-upgrade/SKILL.md@@ -25,7 +25,8 @@ when_to_use: "Use when the user asks: \"gbrain update available\", \"UPGRADE_AVA# GBrain Self-Upgrade> gbrain rides invocation frequency (like gstack): every `gbrain` call checks for-> updates and prints `UPGRADE_AVAILABLE <old> <new>` on stderr when one exists.+> updates and prints `UPGRADE_AVAILABLE <old> <new>` on stderr when one exists+> (once per 30 minutes per version, so act on the first one you see).> This skill turns that marker into the right action for the operator's chosen> mode.diff --git a/skills/gbrain-upgrade/SKILL.md b/skills/gbrain-upgrade/SKILL.mdindex 8b404fcf42..813e8ffcd7 100644--- a/skills/gbrain-upgrade/SKILL.md+++ b/skills/gbrain-upgrade/SKILL.md@@ -24,7 +24,8 @@ mutating: true# GBrain Self-Upgrade> gbrain rides invocation frequency (like gstack): every `gbrain` call checks for-> updates and prints `UPGRADE_AVAILABLE <old> <new>` on stderr when one exists.+> updates and prints `UPGRADE_AVAILABLE <old> <new>` on stderr when one exists+> (once per 30 minutes per version, so act on the first one you see).> This skill turns that marker into the right action for the operator's chosen> mode.diff --git a/skills/skills.lock.json b/skills/skills.lock.jsonindex 843b6c5d7b..17ce96b3ab 100644--- a/skills/skills.lock.json+++ b/skills/skills.lock.json@@ -44,7 +44,7 @@"concept-synthesis/routing-eval.jsonl": "96dbd7d9c1b606e9e06262d0c06282399741e2bccb8eeb7b9ca88c20f44cda0e","context-audit/SKILL.md": "6d786629d40544ddaab4f4e6e333569d270bcb8b581589dc16fb9f8bcb4f6207","context-audit/routing-eval.jsonl": "fb1832e24cc1b04163a74c5cde72bca53050a66246ca902e1a5f40303f52b5ab",- "conventions/agent-operator-protocol.md": "d7cfc7e4c84f61392658cbe969058b1e8237b7d44c3ebdeec352569ffddbe001",+ "conventions/agent-operator-protocol.md": "202845f8f71e517923007c5a96245fa1b92efb16261447eec5f93424ea7e3064","conventions/brain-first.md": "987223ce443b3e8cdcd22975aafabce778016f238deddf544c346238dbde1bd9","conventions/brain-routing.md": "392998d9a109b330c9225af4ca5c8798b0ff02eba4d441c93fdb7c263687d0c6","conventions/calibration.md": "500dc26bd7c8400f50dc4c16fd83f1a588f3e7e68c59050a21fd8a0f69e4d198",@@ -88,7 +88,7 @@"functional-area-resolver/SKILL.md": "fe6e35fbb34dffec7af9ce4a6cc9c0b0eaa8345f97f33262a2abe0983431b421","functional-area-resolver/routing-eval.jsonl": "f80674d915acdfe229046737a5b171da834be15ac6524b5a3fd18048e9b37028","gbrain-advisor/SKILL.md": "976b3c5c3798f9fec764fa5bacd1567f751875bd837fe188a0c6df041805ed51",- "gbrain-upgrade/SKILL.md": "7b069a21f0354b04f370a817cb265632af0fe62f8ca7903f0b4f2783305fe685",+ "gbrain-upgrade/SKILL.md": "3acd674fd78af095b3a40fb4b437475552c166b6dd57014d7db6ce6ea94ce9c0","google-loops/SKILL.md": "20955fac0a94bbe9298a8aa7416e851cac86eb145bc551ed0fc556d2f583fa5e","idea-ingest/SKILL.md": "863be3660ead12a45d3b86309d73df0ffda6c5db6ca69873cce1810680df79b4","idea-lineage/SKILL.md": "8cb36179dbf94abc17065613b8e773b1bb2b22670742aa77347b91ac885a05c5",diff --git a/src/cli/main.ts b/src/cli/main.tsindex 4e5c06ecab..d85b1fd834 100755--- a/src/cli/main.ts+++ b/src/cli/main.ts@@ -76,7 +76,8 @@ import {type CliDispatchContext,} from './command-table.ts';import { formatRememberResult } from './remember-format.ts';-import { applyCliOpNotices, captureCapacityNotices, captureOpNotice } from './op-notices.ts';+import { applyCliOpNotices, captureCapacityNotices, captureOpNotice, retrievalIncompleteLine } from './op-notices.ts';+import { admitAcrossCliCalls } from '../core/notice-ledger.ts';// db-availability loop: best-effort brain-id for the GBRAIN_DB_ACCESS marker,// so a MOUNT's DB failure reads as `brain=<id>` instead of masquerading as a@@ -250,20 +251,15 @@ function maybeEmitUpdateMarker(command: string): void {if (latest) {// notify mode honors a per-version snooze; auto mode ignores it.if (mode === 'notify' && isSnoozeActive(readSnooze(), latest, now)) return;- // The raw `UPGRADE_AVAILABLE <cur> <latest>` line is a MACHINE marker- // (parsed by the self-upgrade skill / MCP via parseMarker). A human at- // an interactive terminal should never see the token as the literal- // first line of output — so emit it only when stderr is NOT a TTY- // (agent harnesses capture stderr non-interactively and still get it).- // GBRAIN_FORCE_UPGRADE_MARKER=1 forces it for the rarer agent harness- // that allocates a PTY yet still parses the token. The human sentence- // prints on both.- if (!process.stderr.isTTY || process.env.GBRAIN_FORCE_UPGRADE_MARKER === '1') {- process.stderr.write(`UPGRADE_AVAILABLE ${VERSION} ${latest}\n`);- }- process.stderr.write(- `gbrain ${VERSION} -> ${latest} available. Run: gbrain self-upgrade\n`,- );+ // One line, once per COVERAGE_NOTICE_WINDOW_MS across calls under+ // GBRAIN_HOME (a newer latest prints at once, #7147). An agent harness+ // (stderr not a TTY, or GBRAIN_FORCE_UPGRADE_MARKER=1 under a PTY) gets+ // the raw `UPGRADE_AVAILABLE <cur> <latest>` MACHINE marker the+ // self-upgrade skill parses; a human at a terminal gets the sentence.+ if (!admitAcrossCliCalls(`upgrade_available|${VERSION}|${latest}`, 1)) return;+ process.stderr.write(!process.stderr.isTTY || process.env.GBRAIN_FORCE_UPGRADE_MARKER === '1'+ ? `UPGRADE_AVAILABLE ${VERSION} ${latest}\n`+ : `gbrain ${VERSION} -> ${latest} available. Run: gbrain self-upgrade\n`);}return;}@@ -1653,16 +1649,10 @@ export function formatResult(case 'search':case 'query': {const { results, meta } = redactRetrievalOutput(result as any[], lastRetrievalMeta);- const incompleteStages = Array.isArray(meta?.degraded)- ? [...new Set((meta.degraded as Array<{ stage?: string }>).map(d => d.stage)- .filter(stage => stage === 'vector_candidates_incomplete' || stage === 'projection_pending' || stage === 'projection_status_unknown'))]- : [];- const incompleteNotice = incompleteStages.length > 0- ? `Retrieval incomplete: ${incompleteStages.join(', ')}.\n`- : '';const answerId = typeof meta?.answer_id === 'string' ? meta.answer_id : undefined;if (answerId && results.length > 0) process.stderr.write(`answer: ${answerId} (rate with: gbrain rate ${answerId} 1-5)\n`);if (params.json === true) {+ const incompleteNotice = retrievalIncompleteLine(meta);if (incompleteNotice) process.stderr.write(incompleteNotice);// --explain --json: the same per-row score_details object MCP `explain: true` returns.if (getCliOptions().explain) for (const r of results) r.score_details ??= require('../core/search/explain-formatter.ts').buildScoreDetails(r);@@ -1683,7 +1673,7 @@ export function formatResult(// (autocut decision, `degraded: reranker_skipped (no_key)`) render.return formatResultsExplain(results, meta ?? undefined);}- return incompleteNotice + results.map(r =>+ return retrievalIncompleteLine(meta) + results.map(r =>`[${r.score?.toFixed(4) || '?'}] ${r.slug} -- ${r.chunk_text?.slice(0, 100) || ''}${r.stale ? ' (stale)' : ''}`,).join('\n') + '\n';}diff --git a/test/e2e/self-upgrade-marker.test.ts b/test/e2e/self-upgrade-marker.test.tsindex 92244f5ce7..ab123da46a 100644--- a/test/e2e/self-upgrade-marker.test.ts+++ b/test/e2e/self-upgrade-marker.test.ts@@ -65,7 +65,16 @@ describe('self-upgrade marker on a real invocation', () => {writeCache(`UPGRADE_AVAILABLE ${VERSION} 0.99.0`);const { stderr } = runGbrain('notify');expect(stderr).toContain(`UPGRADE_AVAILABLE ${VERSION} 0.99.0`);- expect(stderr).toContain('Run: gbrain self-upgrade');+ expect(stderr).not.toContain('Run: gbrain self-upgrade');+ });++ test('#7147: one banner per window across calls; a newer latest prints again at once', () => {+ writeCache(`UPGRADE_AVAILABLE ${VERSION} 0.99.0`);+ const banners = (stderr: string) => stderr.split('\n').filter(line => line.startsWith('UPGRADE_AVAILABLE') || line.includes('available. Run: gbrain self-upgrade'));+ expect(banners(runGbrain('notify').stderr)).toEqual([`UPGRADE_AVAILABLE ${VERSION} 0.99.0`]);+ expect(banners(runGbrain('notify').stderr)).toEqual([]);+ writeCache(`UPGRADE_AVAILABLE ${VERSION} 0.99.1`);+ expect(banners(runGbrain('notify').stderr)).toEqual([`UPGRADE_AVAILABLE ${VERSION} 0.99.1`]);});test('off mode → no marker (update checks disabled)', () => {