Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
6.5 KB
Raw Blame

Company-brain ingestion

Subsystem index. Read only the entries relevant to your change. For the operator workflow, see the company-brain ingestion guide.

  • src/core/company-brain/{inspection,revision,types}.ts — bounded, database-free company repository plans from verified committed Git blobs. Selection, aliases, source-local references, audience requirements, dirty inputs, and schema identities are inspected without executing repository hooks, filters, or instructions. Saved plans are revalidated rather than treated as authority; search-hiding markers block readiness. source-local-reference-index.ts is shared with graph reconciliation so inspection never promises a different frontmatter target resolver. Its Git hardening (argv prefix and scrubbed environment) lives in src/core/hardened-git.ts, shared with the writer manifest (persistence/worktree-manifest.ts, which uses the synchronous hardenedGitSync with a timeout and byte cap).

  • src/core/company-brain/{admission,profile,runtime,verification,receipts,receipt-schema}.ts — trusted local new-source admission, persistent keyless source policy, exact-revision managed/legacy sync, durable phase receipts, and exact content/relationship/history verification. Admission composes with topology locks and request replay; managed sync retains owner/incarnation/revision fencing and refuses canonical file overlays. Incomplete receipt-owned checkpoints survive age-based cleanup. Completed state requires verified source content and graph, not just an advanced import bookmark. The receipt table is authoritative; saved JSON is an export.

  • src/commands/company-brain-{inspect,connect,demo}.ts — dedicated source subcommand parsing and versioned JSON/error output. Inspection is engine-free; connect requires explicit brain/source selection and previews through the existing resident-owner route before a probe-only local connection. Human progress is stderr-scoped for JSON output. core/company-brain/{demo,sample,evidence,status}.ts supplies the real-pipeline offline sample, actual source-scoped evidence, and private receipt status without fabricated answers or host-path fields.

  • src/core/{derived-links,link-reconciliation}.ts — source-qualified, revision-fenced atomic replacement of derived edges; manual rows survive. The source reconciliation API supports bounded cursors, refuses changed endpoints (foreign ones included) and resolves a target into another source only under the source policy it shares with put_page's link preparation (makeLinkSourceResolver: link_resolution.cross_source, or a [[source:slug]] reference from a federated origin; #4680). Standard DB extraction passes the same captured endpoint revision fences. #6808: replaceDerivedLinksDeferringConflicts (and the batch replay) turns the guard's PageSourceMissingError for the origin's or an endpoint's source into { unknownSource }; both DB link drains (extract links|all --source db, extract --stale) keep that page's links and watermark, count it as skipped_unknown_source, name the first 20 in unknown_source_pages and print unknownSourceSkipLine, which, unlike the settings-changed and concurrent-write lines, does not suggest a re-run (test/extract-missing-source-6808.test.ts + Postgres twin). capturedLinkEndpoints(links, metadata, origin?) is the one place those fences are built: every endpoint at the resolver census's revision except the source-qualified origin, which expectedRevision already fences at the snapshot that supplied its body and type (#6474: fencing it again at the older census revision deferred a page rewritten between the census and its own read); the managed links-preparation.ts and both DB walks (extract links|all, extract --stale) pass the origin, and a self-reference's target type comes from the live snapshot rather than the census. replaceDerivedLinksBatch (engine member) publishes many origins in one transaction: one relation-semantics prime, one sorted guard lock over every origin and endpoint, one extraction-generation check and one batched origin read (engine.readPageSnapshotsBatch, built on src/core/page-snapshot-batch.ts: each exact ref's readPageSnapshot result in one statement, page-subject purges and the '' purge marker included, line fingerprints only for pages with withdrawals, purges or a '' marker, a body-byte budget per call; Postgres binds the refs' sources for RLS; test/page-snapshot-batch.test.ts), then each origin's own checks and writes in order; any failure rolls the batch back, and replaceDerivedLinksBatchOrReplay then replays the origins one by one through replaceDerivedLinks, so each outcome (settings-changed skip, first error) is the unbatched one (test/extract-db-batch-equivalence.test.ts pins extract all --source db rows to the per-page walk). test/derived-link-reconciliation.test.ts and test/extract-endpoint-revision.serial.test.ts cover both engines and rollback/freshness behavior.

  • src/core/attendance-repair.ts and src/commands/extract-attendance-repair.ts — trusted-local historical attendance preview and exact-receipt apply. Indexed source-page slug windows precede eligibility filtering; explicit Markdown evidence uses capped endpoint and adjacency lookups, while all frontmatter remains report-only and unmaterialized. A narrow derived-links.ts delta preserves unrelated row IDs and evidence; brain/source incarnation, page revisions, ontology/parser and affected-edge hashes fence each origin transaction. Existing op_checkpoints banks commit proof before the private cursor advances across committed origins and revalidated skipped pages, making interruption replay idempotent. No broad derived replacement, normal-extraction watermark updates, MCP administration or provider calls. Covered by the dual-engine test/attendance-repair.test.ts and real CLI test/attendance-repair-cli.serial.test.ts; operator contract and limits are in docs/guides/attendance-evidence.md.

  • src/core/schema-pack/base/company-brain.yaml — optional company vocabulary extending gbrain-base-v2 without normalization rules or maintenance phases. Overrides company aliases and prefixes so product stays a distinct query and path type. Bundled through schema-pack/bundled.ts and bundled-assets.ts; attribution is in third-party/company-brain/. The generic fictional sample in src/core/company-brain/sample/ preserves the upstream layout and relationship metadata. test/company-brain-schema.test.ts pins inherited lint, type closure, folder inference, read-only bundling, and sample references.