Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/status-funnel
garrytandfc7a145b4c5
diff --cc docs/architecture/key-files/core-utilities-1.mdindex 35d2a6030d,b12cfbc6c3..785b90ddc0--- a/docs/architecture/key-files/core-utilities-1.md+++ b/docs/architecture/key-files/core-utilities-1.md@@@ -44,8 -44,7 +44,8 @@@ The `src/core/cycle.ts` entry is on it- `src/core/filing-audit.ts` + `skills/_brain-filing-rules.json` — Check 6 of `check-resolvable`. Parses `writes_pages:` / `writes_to:` frontmatter on skills and audits their filing claims against the filing-rules JSON (error severity). Internal `parseFrontmatter` is a thin wrapper over the shared `src/core/skill-frontmatter.ts` parser so both filing-audit and skill-brain-first read the same shape (`tools?`, `triggers?`, `brain_first?: 'exempt'`, typed `brain_first_typo`) from one source of truth.- - `src/core/fts-language.ts` — Single source for the FTS configuration name (write side, #6370: `engines-2.md`). `getFtsLanguage()` resolves `GBRAIN_FTS_LANGUAGE` (default `english`), validates against `/^[a-z][a-z0-9_]*$/` (tsvector config names can't be bound as parameters, so the value is interpolated into raw SQL — the allowlist regex is the injection guard; invalid values warn once and fall back to `english`), and caches on first read (`resetFtsLanguageCache()` is test-only). Consumed by both engines' `searchKeyword`/`searchKeywordChunks` (`websearch_to_tsquery` query side), the `configurable_fts_language` migration, and `reindex-search-vector` (write-side trigger functions). `factsFtsDocument`/`factsFtsIndexSql` build the facts keyword document and the `idx_facts_fts` definition (v237); `src/core/facts/fts-index.ts` `ensureFactsFtsIndex` builds it under `idx_facts_fts_next` (CONCURRENTLY on Postgres, via `buildIndexOnline`) and swaps it in with one rename transaction, dropping the old index last; every interrupted step converges on a rerun. Pinned by `test/fts-language.serial.test.ts` + `test/fts-language-migration.serial.test.ts` (includes the `'; DROP TABLE pages; --` injection cases).+ - `src/core/fts-language.ts` — Single source for the FTS configuration name (write side, #6370: `engines-2.md`). `getFtsLanguage()` resolves `GBRAIN_FTS_LANGUAGE` (default `english`), validates against `/^[a-z][a-z0-9_]*$/` (tsvector config names can't be bound as parameters, so the value is interpolated into raw SQL — the allowlist regex is the injection guard; invalid values warn once and fall back to `english`), and caches on first read (`resetFtsLanguageCache()` is test-only). Consumed by both engines' `searchKeyword`/`searchKeywordChunks` (`websearch_to_tsquery` query side), the `configurable_fts_language` migration, and `reindex-search-vector` (write-side trigger functions). `pageSearchVectorSql` and the pages trigger index the first `PAGE_TIMELINE_FTS_MAX_CHARS` (65,536) timeline characters and `PAGE_TIMELINE_ENTRIES_FTS_MAX_CHARS` (32,768) of the joined timeline entries, sized by measurement to keep the densest text under the 1 MB tsvector lexeme cap (v245; pinned by `test/large-pages/page-timeline-tsvector-bound.test.ts`). `factsFtsDocument`/`factsFtsIndexSql` build the facts keyword document and the `idx_facts_fts` definition (v237); `src/core/facts/fts-index.ts` `ensureFactsFtsIndex` builds it under `idx_facts_fts_next` (CONCURRENTLY on Postgres, via `buildIndexOnline`) and swaps it in with one rename transaction, dropping the old index last; every interrupted step converges on a rerun. Pinned by `test/fts-language.serial.test.ts` + `test/fts-language-migration.serial.test.ts` (includes the `'; DROP TABLE pages; --` injection cases).+- `src/core/funnel.ts` — D8 adoption funnel, local and opt-in: recording happens only while `~/.gbrain/funnel.jsonl` exists (created by `gbrain status --funnel --enable`, removed by `--delete`); each line is `{event, at, session}` with no content, and `save`/`recall` are written once per process. Hooks: `remember` (`recordRememberOutcome`: superseded = correction), `forget`/`forget_fact` (withdrawal), `takes_supersede` (correction), `put_page` (save), search/query `searchOutput` and `recall` (`recordRecallOutcome`), `runImport` (import, imported > 0), `runInit` (clean install on a fresh home). `readFunnelReport` turns the record into counts per stage, never rates. No network, no DB table.- `src/core/latin-fold.ts` — leaf text primitive (no engine/graph imports): `NON_DECOMPOSING_LATIN`, the lowercase-keyed table of the eleven Latin stroke/bar/ligature letters Unicode gives no decomposition (đ ð ø ł ħ ŧ ı ß æ œ þ), + `foldNonDecomposingLatin(s)`. Call it AFTER lowercasing and AFTER the combining-mark strip so composed forms reduce in one pass (ǿ → ø → o). Consumers: `entities/resolve.ts:slugify` (entity fallback slugs — pre-fold `Đăng Example` collided onto `ang-example` and an all-stroke name slugged to empty) and `link-extraction.ts:normalizeBasename` (basename-index keys + dir-hint candidates). Deliberately NOT applied to `sync.ts:slugifySegment` — the page-slug grammar keeps these letters (#3417) — so the dir-hint candidate step in `makeResolver` / the FS resolver tries both forms.