Garry's Opinionated OpenClaw/Hermes Agent Brain
Key files: Core Services (2/3, more)
Subsystem index · Previous entries. Read only the entries relevant to your change. Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.
src/core/ops/search.ts— the search-domain op module (search,query,search_stats,search_modes,search_tune,cache_stats). Both resolve their source scope throughops/search-source-scope.tsand return no rows when that scope is empty.queryis the hybrid entry (hybridSearchCached) plus two non-hybrid legs that share ONE effective-row-contract helper,resolveEffectiveLimit(ctx, p): an explicitlimitwins, otherwise the mode-derivedsearchLimitresolved through the same trust-gated chainhybridSearchuses (resolvePerCallModeignores a remote caller'smode, so a remote client cannot select the tokenmax row count); the config reads run lazily on those paths only. The legs: the image-similarity branch (embedding_imagevector search,test/query-image-mode-limit.serial.test.ts) and the CRAG escalation slice — whensearch.crag_escalationis on andshouldEscalateRetrieval(src/core/search/crag.ts) says the first pass gradedweak, was not already escalated, AND did not already run with the caller's expansion on (callerExpanded), the op re-runs once atlimit: max(effectiveLimit, 50)with expansion + relational on and autocut off, keeping the better-graded run.buildRetrievalResponseMeta(ctx, scope, …)is the ONE producer of theretrievalresponse-meta channel (keyword-only path included): when a remote caller's scope holds pages of any kind below the safe-chunk index version (hasUnsealedPagesInScope: sargablechunker_version < SAFE_FENCE_CHUNKER_VERSIONLIMIT 1 probe served by the unsealed-only partialpages_safe_chunk_pending_idx— NOT the COALESCEsafeChunksFilterform; pinned bytest/search-safe-index-probe.test.ts; fail-open; retains source, private, quarantine and live-page policy), it appends thesafe_index_pendingdegraded stage to empty and partial results alike, so neither reads as a clean or complete answer; the drain isgbrain repair safe-chunks. The withholding itself is unchanged. Empty and nonempty replies also carry projection_readiness, with projection_pending/projection_status_unknown degradation when appropriate (projection_by_design when the only unsealed pages in scope are protected-OCR images, #6803). Vector candidate incompleteness and scoped pool details survive the public CLI/MCP serialization boundary; public type filters constrain the current-projection probe. Retrieval output copies and sanitizes result/metadata after grading and capture using the canonical scanner, before snippet truncation; internal pipeline/capture remains unredacted.searchOutputthen projects the returned rows to the caller's row shape (src/core/search/lean-rows.ts: lean for remote callers unlessfields: "full", the transport chose full rows, or the caller is trusted-local; a lean row keepsidonly whenctx.isCallable('fetch'), the MCP dispatch predicatebuildOperationContextthreads in, says the caller can callfetch(unset keeps it), and printsscoreat 4 significant digits) and reports it asretrieval.rowsfor remote callers and wheneverfieldsis passed. The CLI formatter repeats this on JSON, explain and human output. System One: thequeryop asks S4 answerability (decide.answerability, diagnostic only) and surfacesmeta.answerability; the crag escalation re-run keeps S2-S5 off (rerankOnly). Each handler times its request (SearchTimings, search/stage-timings.ts) andsearchOutputemitsretrieval.timingslast. The typed-search type check lives inops/search-type-filter.ts(reconcileTypeFilter): one statement of per-typeEXISTSprobes over each type's schema-expanded set, with theDISTINCTtype list for thetype_filter_noticeevaluated only when a probe misses, runjitOffand unprepared (a generic plan scans every page per missing type); pinned bytest/search-type-filter-reconcile.test.tsandtest/e2e/typed-search-jit-postgres.test.ts.buildRetrievalResponseMetaalso stampsstaleon hits whose page's newer file is held, addsheld_filesper source in scope and emits theheld_filesdegraded notice (persistence/held-reads.ts; Test:test/held-read-signals.test.ts);coveragecounts pending, held and embedding-held items withcould_affect(search/retrieval-coverage.ts). Its safe-index probe, projection readiness, entity saved facts, saved-fact match and held-file coverage run concurrently, each with its own catch; the answer-feedback write runs after them (test/search-response-meta-concurrency.test.ts). The saved-fact match is one statement: anEXISTSprobe skips its scan (idx_facts_fts;LIKE ANYfor CJK) when no fact qualifies. The handlers start the alias fan-out'sresolveQueryEntityalongside the hybrid search, andevidenceOutputreads page trust (loadPageTrustover the rows every delivered row is copied from) alongside evidence delivery (test/search-post-rerank-concurrency.test.ts). The starter list leaves out (fullSurfaceOnly, still accepted)mode,snippet_chars,return_window,token_budget,salience,recency,fields, and onqueryimage/image_mime/embedding_column, the code params,detail,adaptive_return,autocutandrelational.src/core/ops/search-source-scope.ts— per-request scope ofsearch/query:source_idthroughfederatedSearchScope, narrowed bysource_ids(parseSourceIdsParam: trimmed, deduped, validated;__all__refused;[]or a blank string is absent, #5390). Each listed id is authorized like an explicitsource_id(out-of-grant: permission_denied; non-live: unknown_source); with both params the scope is their intersection, and an empty one (sourceIds: []) emitsempty_retrievaland nothing is searched. Tests:test/search/search-source-ids.test.ts(+ itstest/e2e/Postgres twin),test/e2e/serve-http-member-tokens.test.ts.src/core/ops/sources.ts—sources_removeis confined to the caller's WRITE authority viaassertSourceInCallerWriteScope(ctx, id)(context.ts): an untrusted caller may hard-remove only its own write source; a federated read grant naming a source does not make it removable; any other id answersOperationError('not_found', 'Unknown source: <id>'), byte-identical to a nonexistent source so the error is not an existence oracle.sources_statuskeeps the read-scope helper (assertSourceInCallerScope), so a federated grant can still diagnose a source it cannot remove. Trusted local CLI keeps the full operator view. Over HTTP every client carries a write source (registration defaultdefault) and its ownoauth_clients.source_idrow FK-RESTRICTs removing that source, so hard removal is effectively an operator action (gbrain sources remove); a source a remotesources_admincaller just created viasources_addstays outside its authority until the operator rescopes the client. There is nosources_archiveop — archive lives in the CLI (gbrain sources archive). Pinned bytest/sources-mcp.test.ts(federated-read-only id → not_found while status still answers; write-source id → removed; unbound → any; local → any;remote: undefinedfail-closed) andtest/e2e/sources-remote-mcp.test.ts(real server: not_found before AND after a read-grant widen; operator CLI completes; rescoping--sourcemoves the authority).src/core/page-summary.ts—generatePerChunkSynopsis: the per-chunk synopsis call (utility-tier default,thinking: 'off',SYNOPSIS_DOC_MAX_CHARSsurrogate-safe head truncation, D27 failure envelope). One user message of TWO text blocks (PR #6341): the stable title + document block flaggedcache: true(the only prefix every chunk of a page shares) and the per-chunk block; joined with\nthey equal the former single string, soSYNOPSIS_PROMPT_VERSIONstays 1. Pinned bytest/page-summary-prompt-cache.test.ts.src/core/notifier/+src/core/commit-notifier.ts— the commit notifier, wanted markers, residents and search freshness: Commit notifier.