Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
repair secret-spans: classify the writer in the write censuses; a preview with no --slug reads nothing and exits 0
garrytancf96130a7821
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsvindex 2c4363aadf..c3e6280c79 100644--- a/docs/architecture/canonical-writers.tsv+++ b/docs/architecture/canonical-writers.tsv@@ -233,6 +233,7 @@ src/core/source-delete.ts 1 engine_guard Unmanaged source delete with its incarnsrc/core/repair/extractor-facts.ts 1 coordinator `gbrain repair extractor-facts` (#5731) clears expired_at on preview-approved conversation-extractor facts and gives each a fresh row number. On a managed brain the UPDATE runs only inside the managed_maintenance_restore_extractor_facts publication (withCoordinatedWrite, page key locked, each fact reclassified first); an unmanaged brain runs the same function in one transaction under the page lock.src/core/repair/captured-facts.ts 1 coordinator `gbrain repair captured-facts` expires preview-approved capture-lane facts that have no fence row. On a managed brain the UPDATE runs only inside the managed_maintenance_expire_captured_facts publication (owner-checked by maintenancePreflight, page key locked); an unmanaged brain runs it in one transaction. Fenced rows are never updated here: they are struck in the page and expired by the canonical projection of a revision-bound put_page.src/core/repair/redacted-facts.ts 1 coordinator `gbrain repair redacted-facts` (#7125) rewrites the text of preview-approved database-only facts to the words a source page proves. On a managed brain the UPDATE runs only inside the managed_maintenance_restore_redacted_facts publication (owner-checked by maintenancePreflight, page key locked); an unmanaged brain runs it in one maintenanceTransaction. The UPDATE compares text, visibility, entity and holding page under the row lock. Fenced rows are never updated here: their claim is rewritten in the page through a revision-bound put_page and the canonical projection replaces the row.+src/core/repair/secret-spans.ts 2 coordinator `gbrain repair secret-spans` (GST-327) replaces only the credential spans the secret scanner finds in the preview-approved pages' stored copies with <REDACTED:rule> markers, one page per transaction under the page key after a digest recheck: inside withCoordinatedWrite with maintenance attribution on a managed brain, withWriteAttribution on an unmanaged one. Database only: the file side of a redaction goes through Git, history is kept, and a sync hold stays.src/core/repair/ontology-facts.ts 1 coordinator `gbrain repair ontology-facts` (#6264) gives preview-approved ontology observations their own provenance back, clears their fence row number and expiry. On a managed brain the UPDATE runs only inside coordinatedDatabaseWrite (the ontology_propose path: write authority checked, source incarnation revalidated, entity and page keys locked); an unmanaged brain runs it in one maintenance transaction. It writes database-only ontology rows and never a page or file.src/core/repair/facts-rehome.ts 1 coordinator `gbrain repair facts-rehome` (B-7, #6925) moves preview-approved database-only facts off a page-less entity_slug onto the page the strict resolver reaches. On a managed brain the UPDATE runs only inside coordinatedDatabaseWrite (the relink_facts operation: write authority checked, source incarnation revalidated, both slugs locked); an unmanaged brain runs one maintenance transaction per slug. It rechecks the slug, target and fact ids against the preview and never writes a page or file.src/core/repair/consolidate-ties.ts 1 coordinator `gbrain repair consolidate-ties` (#6023) sets preview-approved typed facts that consolidation closed at their own effective instant back to open validity. On a managed brain the UPDATE runs only inside coordinatedDatabaseWrite (the relink_facts operation: write authority checked, source incarnation revalidated, the entity key locked); an unmanaged brain runs one maintenance transaction per fact. It rechecks the fact, take and instant against the preview and never writes a page or file.diff --git a/docs/architecture/coordinated-writes.tsv b/docs/architecture/coordinated-writes.tsvindex 0787a18a60..5322c19d09 100644--- a/docs/architecture/coordinated-writes.tsv+++ b/docs/architecture/coordinated-writes.tsv@@ -33,6 +33,7 @@ src/core/repair/facts-rehome.ts apply 1 facts_lane Moves database-only facts ofsrc/core/repair/frontmatter-keys.ts apply 1 projection Strips parser-reserved keys older imports stored in pages.frontmatter; they never render, so the stripped row equals what the file parses to.src/core/repair/ontology-facts.ts apply 1 facts_lane Restores ontology-observation facts; G4 (GBRA-190) gives ontology observations a page home.src/core/repair/segmented-mirror.ts admitRemirror 1 door Admits a journaled re-mirror request and queues its withdrawal-mirror and Git effects, which rewrite the canonical file.+src/core/repair/secret-spans.ts apply 1 projection Replaces only the credential spans the secret scanner finds in a named page's stored rows with <REDACTED:rule> markers and adds no content; it is the database side of a redaction whose file edit goes through Git, and chunks are rebuilt from the redacted body.src/core/repair/timeline-comments.ts cleanRows 1 projection Rewrites or deletes timeline rows still carrying markup so they equal the tuple the parser reads from the page text.src/core/shared-skills/publication.ts validate 1 operational Prunes retained shared-skill revisions inside a skill-bundle publication; retention bookkeeping, the bundle files are published separately.src/core/shared-skills/retention.ts pruneSharedSkillRevisions 1 operational Prunes retained shared-skill revisions past the retention limits; retention bookkeeping, not memory content.diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.mdindex 067bca3fae..caa04a8219 100644--- a/docs/architecture/system-of-record.md+++ b/docs/architecture/system-of-record.md@@ -305,6 +305,7 @@ or a physical projection that leaves attribution untouched):- `src/core/repair/ontology-facts.ts` (1): a coordinated database-only write (`coordinatedDatabaseWrite`, the `ontology_propose` path) on managed brains; the unmanaged ontology-facts restore runs in `maintenanceTransaction`.- `src/core/repair/redacted-facts.ts` (1): a `managed_maintenance_restore_redacted_facts` request on managed brains; the unmanaged restore of database-only fact text runs in `maintenanceTransaction`.- `src/core/repair/rename-identity.ts` (5): `gbrain repair rename-identity` carry, unmanaged brains only (a managed brain refuses `managed_remedy_unavailable` before writing); the fence-row merge, the provisional page's retirement, the slug move and the import run in one `maintenanceTransaction` under both page locks after the plan-hash recheck.+- `src/core/repair/secret-spans.ts` (1): `gbrain repair secret-spans` (GST-327) rewrites the credential spans of each preview-approved page under the page key: inside `withCoordinatedWrite` with maintenance attribution on managed brains, `withWriteAttribution` with maintenance attribution on unmanaged ones.- `src/core/repair/stale-atoms.ts` (1): the retirement stamp. On managed brains it runs in the `managed_maintenance_retire_stale_atoms` request's apply; on unmanaged brains the retirement is an approved atom generation (`publishGeneration`, one `maintenanceTransaction`) and the stamp runs in its `onRetired` callback inside that transaction.- `src/core/repair/take-supersession.ts` (1): `gbrain repair take-supersession` reprojection: a receipted `managed_maintenance_take_reproject` request on managed brains, `maintenanceTransaction` on unmanaged ones; fence edits go through a revision-bound `put_page`.- `src/core/repair/timeline-comments.ts` (1): `gbrain repair timeline-comments` row cleanup: `withCoordinatedWrite` under the page key on managed brains, `maintenanceTransaction` otherwise.diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 39a0b24ea5..bf1d4dc2fd 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -1221,7 +1221,9 @@ gbrain repair secret-spans --source <id> --slug <slug>... --apply --expect <hash`openai`, `aws_access_key`, `github_token`, `jwt`, `bearer` and`private_key_pem`). The two broad heuristics, `high_entropy_assignment` and`labeled_credential`, run only when named, because they also match things that-are not keys. An unknown rule name refuses before anything is read.+are not keys. An unknown rule name refuses before anything is read. A preview+with no `--slug` (the command `gbrain doctor --remediation-plan` lists) reads+nothing and prints how to name the pages; an apply still needs both.What it reads and rewrites for each page: the title, every string value in thefrontmatter (keys are never touched), the body (inline, or the live generationdiff --git a/src/core/repair/secret-spans.ts b/src/core/repair/secret-spans.tsindex 978ccb0340..582201c67f 100644--- a/src/core/repair/secret-spans.ts+++ b/src/core/repair/secret-spans.ts@@ -353,6 +353,10 @@ export const secretSpansRepair: RepairHandler = {publication: 'projection',async plan(engine, scope, after, opts): Promise<RepairPlan> {if (opts?.remote !== false) throw trustedCliRequired('gbrain repair secret-spans reads and rewrites stored credentials, so it runs only from the trusted local CLI on the brain host.');+ if (!opts.apply && !opts.slugs?.length) {+ return { items: [], residuals: { pages_to_redact: 0, spans: 0, clean: 0, refused: 0, retained_versions: 0 },+ warnings: ['No page named, so nothing was read. Preview the pages to redact: gbrain repair secret-spans --source <id> --slug <slug>... (repeatable).'] };+ }const selection = selectionOf(scope, opts.slugs, opts.rules);const rules = resolveSecretRules(selection.rules);const command = previewCommand(selection);diff --git a/test/receipt-coverage.test.ts b/test/receipt-coverage.test.tsindex 694ce35dd1..f35881bb50 100644--- a/test/receipt-coverage.test.ts+++ b/test/receipt-coverage.test.ts@@ -48,6 +48,7 @@ const RECEIPT_COVERAGE: Record<string, Coverage> = {'src/core/trust/page-handlers.ts': { sites: 1, tables: ['pages', 'facts', 'takes', 'timeline_entries'], todo: 'TODO(receipts): owner tier decisions (confirm/lower) change only trust_tier/write_origin in withCoordinatedWrite as maintenance without a request; publish them as owner requests' },'src/core/trust/backfill.ts': { sites: 3, tables: ['pages', 'facts', 'takes', 'timeline_entries'], todo: 'TODO(receipts): gbrain trust backfill and claim-sources --relower (#6533) set legacy trust_tier/write_origin (no content column) as attributed coordinated maintenance without a request; publish each batch as a maintenance intent' },'src/core/repair/frontmatter-keys.ts': { sites: 1, tables: ['pages'], todo: 'TODO(receipts): gbrain repair frontmatter-keys (#6454) strips the four parser-reserved keys from pages.frontmatter (no content column) in withCoordinatedWrite batches as explicit-only maintenance without a request; publish each batch as a maintenance intent' },+ 'src/core/repair/secret-spans.ts': { sites: 1, tables: ['pages', 'facts', 'takes', 'timeline_entries'], todo: 'TODO(receipts): gbrain repair secret-spans (GST-327) replaces credential spans in preview-approved pages, their facts, takes and timeline rows in withCoordinatedWrite as explicit-only maintenance without a request, with its own per-page op_checkpoints receipt; publish each page as a maintenance intent' },'src/core/cycle/concept-publication.ts': { sites: 1, tables: [], other: 'concept provenance links (links is not a guarded table)' },'src/core/persistence/links-maintenance.ts': { sites: 1, tables: [], other: 'derived links and the pages attendance-blocked stamp (a physical column the guard exempts)' },'src/core/persistence/database-write.ts': { sites: 1, tables: [], other: 'manual links and chronicle ontology observations (unguarded tables)' },@@ -60,7 +61,7 @@ const RECEIPT_COVERAGE: Record<string, Coverage> = {};/** Facts/takes writers allowed without a receipt this wave, each with its TODO above. */-const RECEIPT_EXCEPTIONS = new Set(['src/core/bootstrap/verify.ts', 'src/core/trust/backfill.ts', 'src/core/trust/held-removals.ts', 'src/core/trust/owner-actions.ts', 'src/core/trust/page-handlers.ts']);+const RECEIPT_EXCEPTIONS = new Set(['src/core/bootstrap/verify.ts', 'src/core/repair/secret-spans.ts', 'src/core/trust/backfill.ts', 'src/core/trust/held-removals.ts', 'src/core/trust/owner-actions.ts', 'src/core/trust/page-handlers.ts']);const ROOT = join(import.meta.dir, '..');diff --git a/test/repair-secret-spans.test.ts b/test/repair-secret-spans.test.tsindex 5774056fd3..df0364ae8a 100644--- a/test/repair-secret-spans.test.ts+++ b/test/repair-secret-spans.test.ts@@ -118,7 +118,11 @@ describe('GST-327 gbrain repair secret-spans on a repo-less brain', () => {const remote = { engine, config: { engine: engine.kind }, logger, dryRun: true, remote: true, sourceId: 'default' } as never;await expect(runRepair(remote, secretSpansRepair, scope, { apply: false, explicit: true, slugs })).rejects.toMatchObject({ code: 'permission_denied' });await expect(repairRunner(engine, { apply: true, logger }).then(runner => runner.run('secret-spans', scope, { explicit: true, slugs }))).rejects.toThrow(/preview/i);- await expect(repairRunner(engine, { apply: false, logger }).then(runner => runner.run('secret-spans', scope, { explicit: true }))).rejects.toThrow(/--slug/);+ await expect(repairRunner(engine, { apply: true, logger }).then(runner => runner.run('secret-spans', scope, { explicit: true, expect: 'x' }))).rejects.toThrow(/--slug/);+ const before0 = await snapshotDb(engine);+ const unnamed = await repairRunner(engine, { apply: false, logger }).then(runner => runner.run('secret-spans', scope, { explicit: true }));+ expect({ affected: unnamed.affected, hash: unnamed.preview_hash, warning: unnamed.warnings?.[0] }).toEqual({ affected: 0, hash: undefined, warning: expect.stringContaining('--slug <slug>') });+ expect(await snapshotDb(engine)).toEqual(before0);const before = await snapshotDb(engine);const first = await preview();