Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/capy/lhf-wave-b' into capy/lhf-wave
garrytanc8569f707503
diff --cc CHANGELOG.mdindex 2da07ed3d8,219c5f98bb..9f725d704d--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -14,38 -14,11 +14,43 @@@ identifiers and attribution are availab### Itemized changes+- **`query` expands only when the search mode says so (GBRA-81 item 1b).** The `query` operation used to send `expand: true` on every call, so every mode, `balanced` included, made one expansion LLM call before retrieval. It now leaves `expand` unset unless the caller passes it, so the resolved mode decides: on in `tokenmax`, off in `balanced` and `conservative`. `expand: true` (CLI `--expand`) forces it and `expand: false` (`--no-expand`) skips it; `gbrain config set search.expansion true` restores it by default for a brain, and a `search.expansion` value set earlier, which `query` ignored, now takes effect. The expander stays wired whenever expansion can resolve on, so `tokenmax` still expands. CRAG's caller-expanded check reads `expansion_applied`; eval capture records the raw `expand` param (null when unset) and `gbrain eval replay` maps null to the mode default. The tool description, the concept-search hint, `gbrain search modes`, `search tune`, top-level help, the picker copy and the docs say the same, and a guard test rejects "in every mode" / "always expands" phrasing in `src/` and `docs/`. `test/search/operation-expansion-contract.serial.test.ts` is rewritten to pin the new contract.+- **`gbrain init` recommends `balanced` (GBRA-81 item 1).** The picker recommends `balanced` for brains with a chat key, Opus-class models included. Measured evidence: on LongMemEval-S (direct harness, top 5) `balanced` found every gold session for 451 of 470 questions and `tokenmax` for 442. New `balanced` installs do not run the paid nightly conversation-parser probe, which `tokenmax` turns on; that coupling is kept. Existing brains keep their mode; a brain on picker-chosen `tokenmax` gets one owner-only `search_mode_coaching` notice (CLI and stdio MCP, never HTTP, once per brain, muteable) naming what switching changes, with `gbrain config set search.mode balanced` as an ask-first fix.+- **`gbrain init` reads keys the way the gateway does.** Provider keys are read through `mergedProviderEnv`, so a key saved in `~/.gbrain/config.json` counts, and a brain with a ready reranker but no chat key gets `balanced` instead of `conservative` (the reranker branch uses `rerankerReadiness`, not a key name); `conservative` stays for a Haiku subagent or when neither a chat key nor a ready reranker exists.+- **`gbrain init --search-mode <mode>` and `search.mode_source`.** An agent that knows the operator's choice records it at install time: no recommendation, no first-run `search_mode` ask, `search.mode_source: operator`. On a brain with a different mode it refuses unless `--force`. Picker choices record `auto`; `gbrain config set search.mode` records `operator`.+- **One source for the mode advice.** `src/core/search/mode-advice.ts` holds the recommendation, its reasons and evidence, the `[AGENT]` and upgrade banners, init's first-run decision text and the cost matrix, now priced for Haiku 5.5, Sonnet 5.5 and Opus 5.5 from `src/core/model-pricing.ts` (about a 200x corner-to-corner spread). `INSTALL_FOR_AGENTS.md` Step 3.5 carries the generated matrix, kept in sync by a test. Switching modes no longer promises a cache refill while semantic result caching is off.+- **`gbrain eval longmemeval --via-operation query|search`.** Runs each question through the real operation with an agent's stdio MCP context (remote, stdio, source `default`) at the operation's default limit, with `--op-expand on|off` for `query`. Rows record the context, the `expand` sent, model calls per touchpoint, latency, the CRAG grade and the expansion outcome; `run_config.via_operation_summary` has the tree, p50/p95 latency and model calls per query. A run that expects expansion fails when any question did not expand.+ - **Lean search rows drop `id` where `fetch` is not callable.** Remote `search` and `query` lean rows carry `id` (the deep-research `fetch` key, base64 of `source_id` and `slug`, so a duplicate of two fields already in the row) only when `fetch` is callable on the caller's surface at call time. MCP dispatch threads one `isCallable(op)` predicate into `OperationContext`, built from the same check tools/list uses: the stdio session's surface after any `request_tools` widening, the HTTP client's effective surface and scopes under the server ceiling. `fields: "full"`, `mcp.result_rows: full`, gbrain's thin client and the local CLI are unchanged. On the committed Cat 40 Hard transcripts (served on `starter`, 3,169 `search` calls) a keyless replay (`scripts/replay-lean-row-savings.ts`) saves 9.52% of `search` characters on the starter surface and 1.35% on the full surface, where `id` stays and only score rounding applies.+ - **Lean-row `score` prints 4 significant digits.** Rounding happens only in `leanRow`, so full rows and trusted local callers keep the raw float; RRF-scale scores are small, so fixed decimals would have collapsed them. Two scores print equal only when they agree to 4 significant digits, and order never inverts.+ - **`fetch` without an id names both routes.** The refusal says to re-run `search` once `fetch` is callable, or to pass the row's slug (accepted when unambiguous in the caller's read scope).+ - **`degraded_recall` shows on every affected call on stdio and the CLI.** Transient degradations (`rerank_failed`, `embed_timeout`, a failed keyword or title arm, every other per-call stage) are no longer deduped per session, so a failure after a different earlier failure, or the same failure after a recovery, always carries its notice. A notice made only of configuration-persistent stages (a keyless brain's `embed_unavailable`, about 600 characters on every search otherwise) carries an unrendered `dedupe_key` of its sorted unique stage/reason pairs, which the notice ledger dedupes on per session and the wire never shows. HTTP stays per call. `docs/protocol/AGENT_OPERATOR_v1.md` now states one rule for stdio, CLI and HTTP.++## [0.60.180.0] - 2026-10-12++**When `remember` refuses a forgotten claim, the refusal now says when and how widely it was forgotten.** An agent that re-saves a claim the user forgot gets `fact_withdrawn` as before, and the refusal now carries `withdrawn: { at, subject, visibility }`, where `subject` is the entity the claim was forgotten for or `all_entities`. The agent can tell the user "you asked me to forget that on <date>" instead of retrying. The object rides the immediate refusal, the batch item error, the failed write receipt and `get_write_request`. It covers the exact claim only, the message, code and suggestion are unchanged, and nothing is ever restored.++### Itemized changes++- `src/core/facts/single-prepare.ts` (`factWithdrawnRefusal`): the object comes from the withdrawal ledger only (never a purge): the named entity's withdrawal over `all_entities`, then the newest, among withdrawals whose forgotten rows the caller can read. When it cannot read them, the refusal is the one v0.60.176.0 returns, with no object. `src/core/facts/write-single.ts` applies the same rule, fail-closed when the caller is unknown.+- `src/core/ops/contract.ts`, `src/core/agent-output.ts`, `src/core/remember-batch.ts`, `src/core/persistence/verb-errors.ts`: `withdrawn` on `OperationError`, the agent envelope (stdio, HTTP, CLI) and batch item errors.+- `src/core/facts/withdrawal.ts`, `src/core/persistence/coordinator.ts`, `src/core/persistence/service.ts`, `src/core/ops/persistence.ts`: a refusal at preparation stores the object in the receipt's versioned `error_detail`, read back by the failed response, replay and `get_write_request`.+- `src/core/verbs.ts` (`ERROR_SCHEMA.withdrawn`), the conformance fixture for re-remembering a forgotten claim, the `gbrain errors fact_withdrawn` row, MEMORY_VERBS v1 "remember withdrawn refusal detail (additive)".+- Tests: `test/withdrawn-detail.test.ts` (PGLite) and `test/e2e/withdrawn-detail-postgres.test.ts` (Postgres) share `test/helpers/withdrawn-detail-scenarios.ts`; `test/agent-contract-goldens.test.ts` pins one object on stdio, HTTP and CLI.++## [0.60.179.0] - 2026-10-12++**A managed sync cursor can no longer deadlock on its own canonical correction (#6513).** On a live checkout, a pinned import whose sanitization (a fixable fence, reflowed frontmatter) has to rewrite the file used to refuse `source_changed` / `pinned_git_worktree_conflict` ("Canonical sanitization cannot overwrite newer working-tree bytes.") when the file already held newer uncommitted bytes, and that refusal blocked the cursor with no exit: `--retry-failed` replayed the same pin against the same bytes, `sources refresh` refused `sync_in_progress` on the unfinished cursor, `--acknowledge-managed` refused `cursor_unfinished`, and doctor called the cursor `resumable`. The production brain's `default` source went 38 hours without a sync and recurred the same day; the only way out was deleting `op_checkpoints` rows by hand. The refusal is now the `worktree_dirty` hold the other pinned-worktree conflict already earned (#6340): the file is held, the local edit is untouched, the rest of the source syncs and the cursor finishes, so the checkout is movable again; committing the file (or `gbrain sync unblock --source <id> --apply`) imports it with its correction, and a file committed at HEAD meanwhile is re-frozen and imported as HEAD has it. A cursor an older release left blocked this way converts in place on its next `--retry-failed` run, without rediscovery. Working-tree bytes that already *are* the correction (gbrain's own writeback, published before the request that carried it settled) are no longer a conflict: the page imports and the file is left as it is.++### Itemized changes++- **The canonical-writeback refusal holds the page, not the run.** `pinnedWorktreeConflict` (`sync-page-fault.ts`) recognizes the sync-prepare.ts sanitization refusal, so the run's receipt branch, the start-of-run conversion of an older blocked cursor and the `--retry-failed` conversion all turn it into a `worktree_dirty` hold whose message names the canonical correction; the hold carries the pinned blob and the working hash as before, counts attempts, and clears when the file is committed and re-screened.+- **An already-applied correction is not a conflict.** When the working-tree bytes hash to exactly the canonical file this import would write, the import proceeds with no file write (`sync-prepare.ts`); any other newer bytes are protected as before.+- Tests: `test/managed-sync-page-fault-holds.test.ts` adds the three probes on PGLite and Postgres (live run held and cleared by the commit, already-applied writeback, older blocked cursor converted under `--retry-failed`); each fails on the previous release.+- Docs: [write refusals](docs/guides/write-refusals.md#worktree_dirty) describes the new hold case.+- **A CLI call that lands while `gbrain serve` is still starting waits for the owner socket instead of failing `owner_unavailable` (`submission_status: not_sent`).** The serve takes the PGLite datastore lock before it binds its persistence socket (the MCP handshake sits in between), so a local command in that window saw a serve holder and no socket. `maybeDelegateLocalOperation` / `maybeDelegateLocalAdministration` now repeat the capability probe for up to 3 s while the same serve holds the lock; a released lock, a different holder or any other transport failure ends the wait at once, and nothing falls through to the engine path. Surfaced as a CI flake in `test/shared-skills-live-cli.test.ts`; probe in `test/persistence-local-client.test.ts` (fails on master).++Fixes #6513.+## [0.60.178.0] - 2026-10-12**Batch entity lookups respect quarantine.** `entity` with `names` now hides quarantined pages from remote callers the way a single-name `entity` lookup and `get_page` already do, whichever way the name resolves, and a quarantined identity sibling no longer appears beside a page for remote callers, in batch rows or in a single-name card. Trusted local callers see the same results as before. No migration, no paid call.diff --cc skills/skills.lock.jsonindex 0750716043,8a26a1d24b..aa6bf70981--- a/skills/skills.lock.json+++ b/skills/skills.lock.json@@@ -44,7 -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": "0bc91b8b146436933166839246ce387db6b1af479dcd378f5b4d3a8fcef4c685",- "conventions/agent-operator-protocol.md": "3fbd096433e83a428a5db4e65aa786d1f6dc7eb2ccea757810aee04bdb5ec0a1",++ "conventions/agent-operator-protocol.md": "a6ce48d76cd13080a5f0414d3cf03506e7e3d64fbc25fa3e97cb2492b6dfb7aa","conventions/brain-first.md": "d9b18321150830d38586f5bd23ce9de735f08ac3b54d7ac63bc3184a61e17ef1","conventions/brain-routing.md": "392998d9a109b330c9225af4ca5c8798b0ff02eba4d441c93fdb7c263687d0c6","conventions/calibration.md": "500dc26bd7c8400f50dc4c16fd83f1a588f3e7e68c59050a21fd8a0f69e4d198",diff --cc src/core/behavior-change-notice.tsindex 4ccd649664,46c4a06592..121c30396b--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -466,14 -466,10 +466,17 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.177.0', text: 'Fact extraction on explicit lanes (sync import, put_page) now measures same-page rewordings: when a page is re-extracted and a new claim sits within cosine 0.85 of a fact the same page produced earlier without changing a number, date, amount or negation, the run counts it as `would_dedup_same_page` and prints one stderr line naming the matched fact id. Nothing is dropped or expired; the counter exists so the rule\'s false-positive rate can be measured before any automatic dedup ships.' },{ since: '0.60.177.0', text: 'The atom-extraction phase (`extract_atoms`) now honors a schema pack that declares one of the built-in extractable types (meeting, source, article, video, book, original) as `extractable: false`, the way facts extraction already did: such pages are no longer mined into atoms. gbrain-base declares meeting and source extractable and is unchanged; on gbrain-recommended, `source` pages stop being atom-extracted. A pack that does not mention a built-in type keeps it extractable.' },// Fix wave 15 group 1 (managed sync authority and data safety).+ // Cat 40 next wave, Part 3 step 1. `since` is provisional; the integrator restamps it at the merge slot.+ { since: '0.60.180.0', text: 'A `remember` refused with `fact_withdrawn` now carries an additive `withdrawn` object (`at`, `subject`: the entity slug or `all_entities`, `visibility`) on the immediate refusal, the batch item error, the failed write receipt and `get_write_request`, so an agent can tell the user when and how widely the exact claim was forgotten instead of retrying. The message, code and suggestion are unchanged; the object is absent when the caller cannot read the forgotten rows.' },{ since: '0.60.177.0', text: 'A brain whose persistence mode cannot be read (no `persistence_brain` row, more than one, or an `enabled` value that is not a boolean) now refuses every write, sync, connector run, activation and maintenance step that depends on it with `storage_error` (`detail: persistence_mode_unknown`, fix: `gbrain sources writer status --probe --json`) instead of treating the brain as unmanaged and writing around the owner; only a well-formed `enabled: false` row selects the unmanaged path. A managed `gbrain sync --full` tree walk no longer soft-deletes a page it imported from an untracked working-tree file: a page whose stored import provenance is the working tree, or is unknown, is kept while its file is still present (`working_tree_kept` in the result), and a page imported from a Git blob still follows Git. A soft deletion is not harmless (recall stops at once and the purge lifecycle follows), so this applies on the next sync without opt-in. A first sync, a `--full` sync or one commit that alone exceeds the 100,000-entry / 16 MiB cursor bound now completes in path slices (every import slice, then bounded deletion slices, pinned at one target; the slice cursor is checkpointed with each slice and `last_commit` moves only when the whole target settles) instead of refusing with `request_too_large`; a scheduled sync takes one slice per run and `gbrain sync --drain` takes them all. One file whose manifest entry alone exceeds the byte bound still refuses by name.' },+ { since: '0.60.179.0', text: 'A managed sync no longer parks forever on a pinned import whose canonical correction (a fixable fence, reflowed frontmatter) would rewrite a file that holds newer uncommitted bytes: the file is held `worktree_dirty` with the rest of the source synced, the cursor finishes, and committing the file (or `gbrain sync unblock --source <id> --apply`) imports it. Before, that refusal (`source_changed` / `pinned_git_worktree_conflict`, "Canonical sanitization cannot overwrite newer working-tree bytes.") blocked the cursor with no exit: `--retry-failed` replayed the same pin, `sources refresh` refused `sync_in_progress` and `--acknowledge-managed` refused `cursor_unfinished`. A cursor an older release left blocked this way converts on its next `--retry-failed` run. Working-tree bytes that already are the correction (gbrain\'s own writeback, published before its request settled) import without a second write.' },+ // Low-hanging-fruit wave lane A (GBRA-81 items 1 and 1b). `since` is provisional (this branch's VERSION, 0.60.180.0); the integrator restamps it to the release at the merge slot.+ { since: '0.60.180.0', text: '`query` now expands only when the search mode says so: on in `tokenmax`, off in `balanced` (the default) and `conservative`, so `query` on a `balanced` brain no longer makes an expansion LLM call before retrieval. `expand: true` (CLI `--expand`) expands one call in any mode, and `gbrain config set search.expansion true` restores expansion by default for the brain; `expand: false` (`--no-expand`) still skips it. A `search.expansion` value set earlier, which `query` used to ignore, now takes effect on `query`; `gbrain search modes` shows it. `search` never expands, as before. CRAG escalation now reads whether the first pass actually expanded (`expansion_applied`), and eval capture records the `expand` the caller sent (null when unset) so `gbrain eval replay` replays the mode default.' },+ { since: '0.60.180.0', text: '`gbrain init` now recommends `balanced` instead of `tokenmax` for brains with a chat key, Opus-class models included (on LongMemEval-S, direct harness, top 5, `balanced` found every gold session for 451 of 470 questions and `tokenmax` for 442). New `balanced` installs do not run the paid nightly conversation-parser probe, which `tokenmax` turns on (`gbrain config set autopilot.conversation_parser_probe.enabled true` runs it in any mode). Existing brains keep their mode; one that runs `tokenmax` because init chose it gets one `search_mode_coaching` notice on the CLI or stdio MCP (never HTTP) naming what switching changes, and nothing changes unless the user agrees.' },+ { since: '0.60.180.0', text: '`gbrain init --search-mode <conservative|balanced|tokenmax>` records the operator\'s choice: no recommendation, no first-run `search_mode` question, and `search.mode_source: operator` (picker choices record `auto`, and `gbrain config set search.mode` records `operator`). On a brain that already has a different mode it refuses unless `--force`. Init now recommends `balanced` instead of `conservative` when a reranker is ready but no chat key exists, and provider keys saved in `~/.gbrain/config.json` count toward the recommendation. The install matrix now prices Haiku 5.5, Sonnet 5.5 and Opus 5.5 from gbrain\'s pricing table (about a 200x corner-to-corner spread), and switching modes no longer promises a cache refill while semantic result caching is off.' },+ // Low-hanging fruit wave lane B (GBRA-81, items 2 and 3). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.- { since: '0.60.178.0', text: 'Lean `search` and `query` rows (remote callers) now carry `id`, the `fetch` key, only when the connection can call `fetch` at that moment: a `full` surface, a stdio session `request_tools` widened, or an HTTP client whose surface and scopes include it. On `starter` and `verbs` connections, `fetch` was never callable, so the row\'s `slug` and `source_id` identify the page; `fields: "full"` returns every field, `id` included, and the `mcp.result_rows: full` host setting does so for every remote caller. Lean-row `score` now prints 4 significant digits. The local CLI and gbrain\'s thin client keep full rows, unchanged. `fetch` called without an id now says to re-run `search` once `fetch` is callable, or to pass the row\'s slug.' },- { since: '0.60.178.0', text: 'On stdio MCP and the CLI, the `degraded_recall` notice now shows on every call a transient degradation affects (`rerank_failed`, `embed_timeout`, a failed keyword or title arm, and every other per-call stage); it used to show once per session, so a rerank failure after an earlier embedding timeout returned fused-order results with no notice. A keyless brain whose only degradation is `embed_unavailable` still shows it once per session. HTTP is unchanged: every affected call. `_meta.retrieval.degraded` still records every call\'s stages.' },++ { since: '0.60.180.0', text: 'Lean `search` and `query` rows (remote callers) now carry `id`, the `fetch` key, only when the connection can call `fetch` at that moment: a `full` surface, a stdio session `request_tools` widened, or an HTTP client whose surface and scopes include it. On `starter` and `verbs` connections, `fetch` was never callable, so the row\'s `slug` and `source_id` identify the page; `fields: "full"` returns every field, `id` included, and the `mcp.result_rows: full` host setting does so for every remote caller. Lean-row `score` now prints 4 significant digits. The local CLI and gbrain\'s thin client keep full rows, unchanged. `fetch` called without an id now says to re-run `search` once `fetch` is callable, or to pass the row\'s slug.' },++ { since: '0.60.180.0', text: 'On stdio MCP and the CLI, the `degraded_recall` notice now shows on every call a transient degradation affects (`rerank_failed`, `embed_timeout`, a failed keyword or title arm, and every other per-call stage); it used to show once per session, so a rerank failure after an earlier embedding timeout returned fused-order results with no notice. A keyless brain whose only degradation is `embed_unavailable` still shows it once per session. HTTP is unchanged: every affected call. `_meta.retrieval.degraded` still records every call\'s stages.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */