Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
chore: rebase onto master: speaker attribution migration v207 (master took v206), master's starter budget cuts with query +175 for the explain params, ceilings and goldens
garrytan8836dc97f118
diff --git a/docs/architecture/key-files/graph-and-facts.md b/docs/architecture/key-files/graph-and-facts.mdindex e59bcb1bed..fe203ee378 100644--- a/docs/architecture/key-files/graph-and-facts.md+++ b/docs/architecture/key-files/graph-and-facts.md@@ -100,7 +100,7 @@ rejection of serve-only flags before a brain opens.- `src/core/extraction-review.ts` — Extraction quarantine lane markers, sibling of `src/core/quarantine.ts` / `embed-skip.ts` (frontmatter-key pattern, no schema migration). Auto-extracted stubs from untrusted input carry the PAIR `provenance: 'auto-extracted'` + `status: 'unverified'` (both required — user pages with their own `status`/`provenance` never match). Exports `quarantineMarkers()`, `isUnverifiedExtraction()` (JS predicate) and `unverifiedExtractionFragment(alias)` — the single SQL source of truth consumed by `buildSourceFactorCase` (namespace source-boost guard), both engines' `getUnverifiedExtractionPageIds`, the `extraction_pending` op, and the `unverified_extractions` doctor check, so filter and marker keys can never drift. Consequences: unverified stubs are excluded from the compiled-truth fusion boost + the `people/`/`companies/` source-boost (rank as ordinary content), stamped `unverified: true` in search results (`stampUnverifiedExtractions`, hybrid.ts), listed by `extraction_pending`, promoted (status → `verified`, provenance kept for audit) or rejected (soft-delete) by the owner-only `extraction_review` op. Pinned by `test/extraction-review.test.ts` (PGLite) + `test/e2e/extraction-review-postgres.test.ts` (live Postgres parity).- `src/core/facts-fence.ts` — the `## Facts` fence primitives: parse (`parseFactsFence`; a confidence cell outside 0..1 or not a plain number is `FACTS_TABLE_MALFORMED`, a `claim_value` cell parses strictly (plain/scientific numbers, `1,234,567` separators, a leading currency symbol, a k/M/B suffix that scales; anything else such as `1,5` or `0.9abc` is `FACTS_TABLE_MALFORMED`), `formatFenceDate` writes UTC-midnight dates as `YYYY-MM-DD` and any other instant as a UTC timestamp so TTLs and write-time `valid_from` round-trip, so the page is non-authoritative instead of failing the DB CHECK), render (`renderFactsTable`), and strip (`stripFactsFence({keepVisibility})` — the remote-read privacy boundary `get_page`/`fetch_page`/the chunker apply), plus the remote write-back merge, plus the ONE fence-placement rule: `replaceOrInsertFactsFence(body, fenceBlock)` replaces an existing fence in place or inserts a fresh `## Facts` section ABOVE the timeline sentinel (`timelineSentinelOffset`, #4756 — below it splitBody() files the fence into page.timeline where extract_facts refuses to reconcile it), EOF only when the page has no sentinel; every writer that materializes a fence (`upsertFactRow`, the phantom-redirect canonical append, the importer's hidden-row merge) routes through it, so no writer can re-grow its own EOF append. `restoreHiddenFactRows(incoming, existing)` is the row-level, visibility-aware merge `import-file.ts` applies per fence-bearing column (compiled_truth AND timeline) when a remote caller writes back a page it read with hidden rows stripped — without it, a remote get→edit→put round-trip would silently drop every non-`world` fact row. Rules: only non-`world` rows of the existing fence are restoration candidates (a caller's deletion of a VISIBLE row stays honored — world rows are never restored); a hidden row whose rowNum is absent from the incoming fence is restored at its stable rowNum (cross-page `#F<N>` refs survive); a rowNum collision (a caller-authored addition landing on a hidden number the caller never saw) keeps the hidden row's number and renumbers the CALLER's row onto fresh appended numbers (upsertFactRow's append-only contract); same rowNum + same claim keeps the incoming version (idempotent full-content write-throughs); either side parsing with warnings returns null — re-rendering a fence that didn't fully parse would drop the caller's unparsed rows — and `factsGapWarning` surfaces exactly that residual loss. Pure and side-effect-free. Pinned by `test/facts-fence.test.ts` + the remote write-back describes in `test/privacy-strip-and-forget.test.ts` (row-level merge, world-only deletion honored, timeline-embedded fence round-trip).-- `src/core/facts/attribution.ts` — speaker attribution's one dedup rule: `attributionCompatible(a, b)` is false only for two different known speakers (`user`, `assistant`, `other`); NULL (no recorded speaker) is compatible with either. Every dedup path applies it before candidate limits: `findCandidateDuplicates` (`attributedTo` option, SQL pre-limit), `decideSingleFact` exact and cosine matches, capture exact/near matches, hot-memory collapse (`collapseHotFacts` splits a fingerprint group by speaker when it holds two), fence reindex (`duplicateActiveFenceRows`) and the managed batch key (`facts-prepare.ts`). `facts.attributed_to` (migration v206) is written by the extractor when `facts.attribution` is on, carried in the fence's 15th cell (only on rows that have it), returned by `recall` and hot memory, rendered `(assistant said)` in context packs, and kept out of `consolidate` (takes are the user's own). Pinned by `test/facts/speaker-attribution.test.ts`.+- `src/core/facts/attribution.ts` — speaker attribution's one dedup rule: `attributionCompatible(a, b)` is false only for two different known speakers (`user`, `assistant`, `other`); NULL (no recorded speaker) is compatible with either. Every dedup path applies it before candidate limits: `findCandidateDuplicates` (`attributedTo` option, SQL pre-limit), `decideSingleFact` exact and cosine matches, capture exact/near matches, hot-memory collapse (`collapseHotFacts` splits a fingerprint group by speaker when it holds two), fence reindex (`duplicateActiveFenceRows`) and the managed batch key (`facts-prepare.ts`). `facts.attributed_to` (migration v207) is written by the extractor when `facts.attribution` is on, carried in the fence's 15th cell (only on rows that have it), returned by `recall` and hot memory, rendered `(assistant said)` in context packs, and kept out of `consolidate` (takes are the user's own). Pinned by `test/facts/speaker-attribution.test.ts`.- `src/core/fence-shared.ts` — shared pipe-table primitives for the `## Takes` (`takes-fence.ts`) and `## Facts` (`facts-fence.ts`) fences: `parseRowCells`, `isSeparatorRow`, `stripStrikethrough`, `parseStringCell`, `escapeFenceCell`. `parseRowCells` is escape-aware: `\|` stays inside its cell and decodes back to a literal `|` (exact inverse of `escapeFenceCell`), while any other backslash passes through verbatim so existing fence text (e.g. Windows paths) is byte-stable across a render → parse cycle. This matters because the fence is canonical and reconcile is wipe-and-reinsert — a pipe inside a cell shifting the column layout would corrupt every row behind it on the next reconcile. Pinned by the escape cases in `test/facts-fence.test.ts` + the full render → parse → reconcile round-trip in `test/e2e/facts-fence-reconcile-postgres.test.ts`.diff --git a/src/core/engine.ts b/src/core/engine.tsindex da69fcccf4..97cc93732b 100644--- a/src/core/engine.ts+++ b/src/core/engine.ts@@ -594,7 +594,7 @@ export interface NewFact {* set this — leaving it undefined preserves pre-v0.40 behavior.*/event_type?: string | null;- /** Speaker attribution (migration v206). Undefined/null → NULL (unavailable). */+ /** Speaker attribution (migration v207). Undefined/null → NULL (unavailable). */attributed_to?: FactAttribution | null;}diff --git a/src/core/schema-migrations/v206-facts-attributed-to.ts b/src/core/schema-migrations/v207-facts-attributed-to.tssimilarity index 96%rename from src/core/schema-migrations/v206-facts-attributed-to.tsrename to src/core/schema-migrations/v207-facts-attributed-to.tsindex 13d6c4f992..c5b2e1b04e 100644--- a/src/core/schema-migrations/v206-facts-attributed-to.ts+++ b/src/core/schema-migrations/v207-facts-attributed-to.ts@@ -13,8 +13,8 @@ import { WRITE_ATTRIBUTION_SCHEMA_SQL } from '../persistence/attribution-schema.// (v045), so there is no schema.sql mirror. The column is canonical content// (attribution-schema.ts), so the write-attribution trigger function is// re-created here to include it in the content-change comparison.-export const v206: Migration = {- version: 206,+export const v207: Migration = {+ version: 207,name: 'facts_attributed_to',idempotent: true,sql: `diff --git a/test/facts/speaker-attribution.test.ts b/test/facts/speaker-attribution.test.tsindex a330476ad9..fffdb769ee 100644--- a/test/facts/speaker-attribution.test.ts+++ b/test/facts/speaker-attribution.test.ts@@ -1,5 +1,5 @@/**- * Speaker attribution on saved facts (`facts.attribution`, migration v206).+ * Speaker attribution on saved facts (`facts.attribution`, migration v207).** Protects: the attribution variant asks for and parses `attributed_to`* (anything outside user|assistant|other parses as null) and the defaultdiff --git a/test/fixtures/goldens/cli/help-and-errors.json b/test/fixtures/goldens/cli/help-and-errors.jsonindex 05da7cc873..ada51f283c 100644--- a/test/fixtures/goldens/cli/help-and-errors.json+++ b/test/fixtures/goldens/cli/help-and-errors.json@@ -706,7 +706,9 @@" --embedding-column Registered embedding column."," --adaptive-return true when one answer is wanted (fewer rows; never returns empty); omit for breadth."," --autocut Default on (never returns empty); false gives full top-K for breadth, unlike adaptive_return.",- " --relational Relationship-graph arm (default on)."+ " --relational Relationship-graph arm (default on).",+ " --explain Per-row score_details.",+ " --explain-target Expected page (slug or source:slug): why it is missing."]},{diff --git a/test/schema-bootstrap-coverage.test.ts b/test/schema-bootstrap-coverage.test.tsindex 9257fdbac9..2650bea9aa 100644--- a/test/schema-bootstrap-coverage.test.ts+++ b/test/schema-bootstrap-coverage.test.ts@@ -961,7 +961,7 @@ const COLUMN_EXEMPTIONS = new Set<string>([// brains is invisible to them). Migration is column-only, no FK,// no index — bootstrap probe would be pure overhead.'facts.event_type',- // migration v206 — speaker attribution. The facts table is migration-created+ // migration v207 — speaker attribution. The facts table is migration-created// (absent from PGLITE_SCHEMA_SQL), so no schema-blob forward reference can// exist; nullable column only, no index or FK.'facts.attributed_to',