Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge origin/master into capy/gbra72-content-repair
garrytanf3c03ed57cc6
diff --cc CHANGELOG.mdindex 465f1f8172,104831931c..52a30eca16--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,40 -10,40 +10,74 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.132.0] - 2026-10-09++**Sync holds clear themselves. gbrain merges repeated fact tables, closes tables that were never ended, and removes stray `slug:` lines on its own; a repair model decides the cases that need judgment; a person is asked only when gbrain says so, in plain words, with the one command that applies what it proposes.**++A managed sync holds a file it cannot import instead of failing the run. Until now every content hold ended with "gbrain will not guess this repair" and an operator editing the file. On one brain five holds sat for 16 hours; the week before, an external agent made hundreds of fence and frontmatter repairs by hand against gbrain's error messages. This release adds a content-repair lane that clears those holds itself, under the preview → hash-bound apply → receipt contract fence repair already uses, and runs it in the maintenance cycle and from `gbrain sync unblock --apply`.++### What you'd see++- Two `## Facts` (or `## Takes`) tables in one section (`repeated_marker`) become one: later rows append in order, byte-identical rows are dropped and recorded, colliding numbers are renumbered with their `superseded by #N` references following, and the second heading goes. The validator proves every original row survived the merge. No model, no cost.+- A table that never got its end marker, with text after it (`unclosed_trailing_content`): on a private page gbrain adds the end marker after the last row. On a world-visible page those trailing lines would become visible to readers, so gbrain never does that unattended: the preview (`gbrain repair fences --source <id> --only <path>`) prints the exact lines and the apply command, and the hold reads `tail_exposure_approval` until you approve. A tail that holds a pipe goes to the repair model, which answers only prose / rows / unsure; rows or unsure is `unclosed_ambiguous_tail` with the exact edit.+- A frontmatter `slug:` naming another page (`frontmatter_slug_conflict`): when nothing can be merged into (no such page, or a page of another type with no title in common) gbrain removes the line itself. Otherwise the model reads both pages and answers remove the line, "these are the same thing, merge into X", or ask a person. A merge is **recommended, never executed**: the hold shows `merge_recommended` with the canonical page in plain words. New kind `gbrain repair slug-conflicts`.+- `gbrain repair content --source <id>` previews the whole lane (fences, then slug conflicts) with one hash per kind; `--apply --expect <h1>,<h2>` applies exactly that; `--max-usd` caps the run's model spend. `gbrain sync unblock --apply` now performs these repairs instead of refusing them and reports each path as `repaired`, `held`, `needs_human` or `skipped`; `--no-repair` restores the old behaviour, `--no-llm` keeps to the free tiers.+- The maintenance cycle gains a `content_repair` phase right after `fence_repair`. Every repair commit carries the trailer `gbrain-repair: <hold_code> <tier> <confidence>` and a receipt with the sha256 before and after; `git revert` of that commit restores the file and the hold re-screens.+- Which model may judge a slug conflict is measured, not assumed: `claude-opus-5-5`, `gpt-6.1-sol` and `claude-sonnet-5-5` each gave zero harmful answers on 48 preregistered pairs (never deleted a true duplicate's slug, never merged two different pages) and recognised 92%, 85% and 80% of true duplicates. `models.content_repair` overrides; the fence-repair caps (`fences.repair.max_usd_per_page` $0.30, `fences.repair.max_usd_per_day` $1.00) and ledger govern the whole lane, `fences.repair.llm false` turns its model tier off.++### What to watch for++- Fence merging and the private-page close also run on write paths under `fences.normalize` (default on), as every lossless Tier 1 rule does. A page that previously refused with `repeated_marker` now imports merged.+- `gbrain sync unblock --apply` writes repairs; before this release it refused repair-class holds and wrote nothing. Use `--no-repair` for the old behaviour.+- A hold the lane decided needs a person (`merge_recommended`, `content_repair_needs_human`, `tail_exposure_approval`, a manual fence reason) now reports `needs_human: true` in `gbrain sync status` with the paragraph in `human_reason`, and `unblock` lists it instead of retrying it.+- Page merges are not executed in this release; the hold names the canonical page and nothing is changed until a person merges by hand. The executor is a follow-up (TODOS.md).++### Itemized changes++- **`merge_fences` (`src/core/fence-repair/merge.ts`, `structure.ts`, `validate.ts`, `receipt.ts`).** Tier 1 merges balanced same-kind fences in one section; the validator pairs merged rows through the mapping (gate (e) accepts exactly the recorded duplicates; (b), (c), (d), (f) run per mapped row); the receipt carries occurrence identities. `FENCE_RULES_VERSION` 3 re-screens older holds.+- **`close_fence_trailing` and the tail classifier (`structure.ts`, `llm-tail.ts`, `repair-tiers.ts`, `hold-fix.ts`).** Gate (g) admits exactly the trailing lines the fix shows; the structural rule admits that fix only on a private page or under `approveTailExposure`, which explicit previews and `--expect` applies carry and unattended runs never do. New reasons `tail_exposure_approval` (actor user) and `unclosed_ambiguous_tail`; `unclosed_trailing_content` is now the Tier 3 tail question.+- **`slug-conflicts` kind (`src/core/repair/slug-conflicts.ts`, `src/core/content-repair/*`).** Alias-resolved identity, the two deterministic rules, the judgment prompt and parser (`JUDGMENT_PROMPT_VERSION` 1), the model call under `FENCE_REPAIR_LEDGER` with a memo keyed on both participants, `content_repair` receipts and the commit trailer through the coordinated `managed_file_repair` intent. Hold metadata gains `content_repair` (codes and slugs only), kept across a re-screen of the same bytes; `sync status` renders the paragraph from templates.+- **The lane (`src/core/repair/content-lane.ts`, `src/commands/repair-content.ts`, `src/core/cycle/content-repair.ts`, `sync-status.ts`).** `gbrain repair content`, the `content_repair` phase, `unblock --apply` repairs with structured per-path outcomes, and every hold surface routing fence and slug-conflict holds to the lane. An empty preview's hash binds "nothing to apply", so a lane apply with one hash per kind succeeds when a kind has no candidates.+- **Eval (`evals/content-repair-judgment/`).** 48 pairs, preregistration, harness, scorer; verdict mirrored in gbrain-evals.++### For contributors++- `test/fence-repair-merge.test.ts`, `test/fence-repair-llm-tail.test.ts`, `test/repair-slug-conflicts.test.ts`, `test/content-repair-judgment.test.ts`, `test/repair-content.test.ts`, `test/cycle-content-repair.test.ts`, `test/eval-content-repair-judgment.test.ts`; `sync-status-unblock`, `persistence-sync-holds`, `fence-repair-normalize`, `fence-repair-validate`, `fence-repair-reasons`, `sync-hold-surfaces` extended. Goldens regenerated: `test/fixtures/goldens/exports/types.json` (new codes in the `canonical` union, `RepairResult.preview_hash`, `outcome_items[].llm_usd`).+- Plan and review record: `docs/plans/2026-10-09-001-fix-content-repair-lane-6377-plan.md`.+ ## [0.60.131.0] - 2026-10-09++ **Vector search scoped to one source now finds that source's true nearest chunks, and a remote reader's scoped search no longer runs for seconds. Unscoped search runs the same statement as before. Rescoring fetches embeddings about twice as fast.**++ A source-scoped vector search walked the HNSW index over the whole brain and kept the rows in scope. For a source holding a few percent of a large brain, the nearest chunks overall were rarely in it: the walk came back with a fraction of the true neighbours, and with the private-page rule the fallback statement ran for 4-8 s. Now a source with up to about 25,000 chunks is scanned exactly over its own chunks, reached page by page through the chunk index. A larger source under 30% of pages walks the index deep enough to keep about two in-scope rows per result slot, then falls back to the exact scan when the walk still comes back short. Hybrid rescoring now reads each chunk's embedding in pgvector's binary format instead of its text literal, with the same values.++ ### What you'd see++ 4 vCPU box, Postgres 16 + pgvector 0.8.7, synthetic brain of 50,010 pages / 248,802 chunks (1024-dim vectors), warm, N=25 queries, `limit` 20. Recall is result pages against the exact statement (no index) for the same scope. Sources hold the given share of pages, spread over the whole brain:++ | source share | before p50/p95 ms | recall | after p50/p95 ms | recall |+ |---|---|---|---|---|+ | 0.1% | 13/18 | 1.00 | 11/17 | 1.00 |+ | 1% | 73/124 | 1.00 | 22/134 | 1.00 |+ | 4% | 38/67 | 0.38 | 62/84 | 0.98 |+ | 8% | 15/184 | 0.47 | 105/132 | 0.98 |+ | 16% | 46/57 | 0.45 | 57/99 | 0.82 |+ | 50% | 24/46 | 0.56 | 31/46 | 0.81 |+ | unscoped | 37/42 | 0.64 | 25/28 | 0.64 |++ The same 4% source for a remote reader (private-page rule) went from 187/234 to 58/85 ms. A 1% source whose content sits away from most queries went from 4,390/6,475 ms to 42/68 ms for a remote reader. A 16% clustered source went from 40/8,135 ms (recall 0.42) to 381/474 ms (recall 0.95). PGLite at 5,001 pages: a 16% source went from 133/199 to 32/33 ms, recall 1.00 both. Fetching 100 embeddings for rescoring went from 11.0 to 4.9 ms.++ ### What to watch for++ - Scoped results can differ from earlier releases wherever the index had missed closer matches. Unscoped search and scopes holding 30% or more of pages keep the approximate index walk.+ - A scope of 25,000-60,000 chunks whose content sits away from the query pays for the exact scan after the walk: about 0.4 s at 75,000 chunks on the box above, in exchange for complete results.++ ### Itemized changes++ - **Scope scan (`src/core/search/vector-statement.ts`).** `scopeScanSql` orders chunk ids by exact distance over `cc.page_id = ANY(ARRAY(eligible pages))`, every page filter, visibility and the private-page rule applied once per page, then joins the window back for its columns. It returns the joined statement's rows. Each engine's `vectorScopeLoader` estimates the scope's share of pages and chunks from planner statistics, at most once a minute.+ - **Share-scaled walk.** The walk over-fetches `ceil(2 / share)` rows per window slot, sizes `hnsw.ef_search` and `hnsw.max_scan_tuples` for that window, and runs for scopes holding at least 4% of pages (was 10%). Unscoped, it is the same statement.+ - **First attempts (`src/core/search/vector-pool.ts`).** `searchIndexWalk` runs the walk, then the scope scan, before the bounded pool; a scan whose window is short (the scope ran out of chunks) answers on its own.+ - **Binary embedding fetch (`src/core/engine-sql/chunks.ts`).** `getEmbeddingsByChunkIds` reads `vector_send(col::vector)` and decodes it with `decodeVectorSend`, bit for bit the text literal's values.+ - **Bench.** `scripts/bench/vector-scope-share.ts` reports latency and recall per scope on any Postgres or PGLite brain.## [0.60.130.0] - 2026-10-09diff --cc src/core/behavior-change-notice.tsindex e554621e6f,acd25034b5..004991c326--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -351,11 -350,7 +351,10 @@@ export const BEHAVIOR_CHANGES: Readonly// Budgeted delivery PR 1. `since` equals the branch's VERSION; the integrator sets it to the merge-slot stamp by hand (release:restamp does not rewrite this table).{ since: '0.60.124.0', text: 'A token budget passed under `auto` evidence delivery (`token_budget` on query, search and assemble_evidence, `budget_tokens` on recall with `return_unit: "auto"`) is now a hard cap on the delivered titles and evidence: the best hit comes first, and conversations or notes that do not fit are listed in `delivery.dropped_reasons` instead of being appended as extra chunks. A budget below 32 tokens is refused with `invalid_params`. Calls without a budget, and a bare query `token_budget` (legacy chunk budgeting), are unchanged. `gbrain config set search.auto_packing off` restores the uncapped behavior.' },{ since: '0.60.126.0', text: '`context_pack` cards now list the newest pages that mention each entity and are dated after the entity\'s own page (up to 8 per card, 2,000 characters per card and 6,000 per pack, each with its date, slug, title and preview), so a later mail or note that corrects the page reaches the agent on its first call. A remote caller never sees a private page or another source there, and the section packs last under `budget_tokens`. `gbrain config set mentions.newer_on_cards false` turns it off.' },- // #6377 (GBRA-72). `since` is a placeholder equal to the branch's VERSION so a fresh install's baseline covers it; the integrator sets it- // to the merge-slot stamp (master plus one PATCH) by hand, because release:restamp rewrites VERSION, CHANGELOG and TODOS, never this table.- { since: '0.60.130.0', text: 'The maintenance run now repairs the content holds managed sync records, by itself and without consent: two facts or takes fences of one kind in one section are merged into one (exact duplicate rows dropped, colliding numbers renumbered, the validator proving every original row survived), an unclosed fence followed by text on a private page is closed after its last row, and a stray frontmatter `slug:` that names no page (or a page of a different type with no title in common) is removed; each repair is one committed file write carrying the trailer `gbrain-repair: <hold_code> <tier> <confidence>` and a receipt, so `git revert` of that commit undoes it. The `fence_repair` phase runs the fences, the new `content_repair` phase right after it runs the rest of the lane (`gbrain repair content --source <id>` previews both); `gbrain config set fences.repair.enabled false` pauses all of it.' },- { since: '0.60.130.0', text: `The repair model (\`models.fence_repair\`, or \`models.content_repair\` for slug conflicts) now also classifies the cases the deterministic rules mark ambiguous, under the same \`fences.repair.max_usd_per_page\` ($0.30) and \`fences.repair.max_usd_per_day\` ($1.00) caps and one shared daily ledger: whether the lines after an unclosed fence on a world-visible page are prose or table rows, and whether two pages a \`slug:\` line ties together are the same thing. The model chooses among coded answers and never writes text: a world-page close that would expose hidden lines waits for your hash-bound approval (\`tail_exposure_approval\`), a page merge is recommended, never executed (\`merge_recommended\` names the canonical page), and an undecided case is \`needs_human\`. ${CONTENT_REPAIR_MEASURED} \`gbrain config set fences.repair.llm false\` turns the model tier off for the whole lane; \`--no-llm\` keeps one run to the free tiers.` },- { since: '0.60.130.0', text: '`gbrain sync unblock --source <id> --apply` now writes: for every held file the content-repair lane clears (`invalid_fence` and `frontmatter_slug_conflict`) it runs the lane on exactly those paths as one bounded hash-bound apply under the `fences.repair` caps, prints a receipt per file and schedules the re-screen, and reports each path as `repaired`, `held`, `needs_human` or `skipped` with the reason and its next step; a hold whose stored state waits on a person, your spend decision or the owner host is listed, never retried. Before this release unblock refused every repair-class hold. `--no-llm` keeps the repairs to the free tiers; `--no-repair` restores the refuse-only behaviour. `gbrain sync status` now reports a fence hold the lane marked manual or paid, and a recommended merge, as `needs_human` with the paragraph in `human_reason`.' },+ { since: '0.60.131.0', text: 'Vector search scoped to a source that holds a small part of the brain now returns its true nearest chunks: a source with up to about 25,000 chunks is scanned exactly instead of through the HNSW index, and a larger one falls back to that scan when the index comes back short. Unscoped search is unchanged; scoped results can differ from earlier releases where the index had missed closer matches.' },++ { since: '0.60.132.0', text: 'The maintenance run now repairs the content holds managed sync records, by itself and without consent: two facts or takes fences of one kind in one section are merged into one (exact duplicate rows dropped, colliding numbers renumbered, the validator proving every original row survived), an unclosed fence followed by text on a private page is closed after its last row, and a stray frontmatter `slug:` that names no page (or a page of a different type with no title in common) is removed; each repair is one committed file write carrying the trailer `gbrain-repair: <hold_code> <tier> <confidence>` and a receipt, so `git revert` of that commit undoes it. The `fence_repair` phase runs the fences, the new `content_repair` phase right after it runs the rest of the lane (`gbrain repair content --source <id>` previews both); `gbrain config set fences.repair.enabled false` pauses all of it.' },++ { since: '0.60.132.0', text: `The repair model (\`models.fence_repair\`, or \`models.content_repair\` for slug conflicts) now also classifies the cases the deterministic rules mark ambiguous, under the same \`fences.repair.max_usd_per_page\` ($0.30) and \`fences.repair.max_usd_per_day\` ($1.00) caps and one shared daily ledger: whether the lines after an unclosed fence on a world-visible page are prose or table rows, and whether two pages a \`slug:\` line ties together are the same thing. The model chooses among coded answers and never writes text: a world-page close that would expose hidden lines waits for your hash-bound approval (\`tail_exposure_approval\`), a page merge is recommended, never executed (\`merge_recommended\` names the canonical page), and an undecided case is \`needs_human\`. ${CONTENT_REPAIR_MEASURED} \`gbrain config set fences.repair.llm false\` turns the model tier off for the whole lane; \`--no-llm\` keeps one run to the free tiers.` },++ { since: '0.60.132.0', text: '`gbrain sync unblock --source <id> --apply` now writes: for every held file the content-repair lane clears (`invalid_fence` and `frontmatter_slug_conflict`) it runs the lane on exactly those paths as one bounded hash-bound apply under the `fences.repair` caps, prints a receipt per file and schedules the re-screen, and reports each path as `repaired`, `held`, `needs_human` or `skipped` with the reason and its next step; a hold whose stored state waits on a person, your spend decision or the owner host is listed, never retried. Before this release unblock refused every repair-class hold. `--no-llm` keeps the repairs to the free tiers; `--no-repair` restores the refuse-only behaviour. `gbrain sync status` now reports a fence hold the lane marked manual or paid, and a recommended merge, as `needs_human` with the paragraph in `human_reason`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */