Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
# Function-size ratchet baseline (refactor wave 1, W5). Enforced by
# scripts/check-function-size.ts via `bun run check:function-size` (in verify).
# One row per function over 300 lines in src/**/*.ts (excluding *.generated.ts),
# keyed by path + name path (never line numbers). Rows only shrink: lower a row
# when its function shrinks, remove it when the function drops to 300 lines or
# fewer. Raising a row or adding one needs an issue/TODO id in the justification.
# docs/TESTING.md#function-size-ratchet
path name lines justification
src/commands/bootstrap.ts runHooks 603 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 #4618: --seat/--no-seat parse + refusal/note (logic in core/bootstrap/hooks.ts parseSeatFlags); +1 #8426: the user-scope MCP registration writes the hook launcher before naming it (logic in core/setup/hook-launcher.ts); +2 #8435: the user-global opencode entry starts serve through the hook launcher
src/commands/bootstrap.ts runHooks>withLock(#1) 451 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 #8435: the user-global opencode entry starts serve through the hook launcher (logic in core/setup/hook-launcher.ts)
src/commands/config.ts runConfig 782 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 #5232: persistence.write_wait_ms dispatch line (logic in setFileWriteWait); wave 10 collector: master and the #4907/#5958 config-set range refusals compose at 775; re-summed at the #6015 merge (767 master baseline + 4 integration lines); re-summed at the wave 10 merge on actual lines; +1 C4: dream.auto_think.* replacement note (logic in questions/auto-think-migration.ts); +5 wave 15 P7.4 #5461: set-time refusal of think.pages_budget_chars / think.excerpt_ceiling_chars (range text from think/pages-budget.ts pagesBudgetConfigError); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig)
src/commands/doctor/bootstrap-checks.ts bootstrapDoctorChecks 476 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/doctor/checks/extraction-sync.ts checkSyncFreshness 333 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/doctor/report-remote.ts doctorReportRemote 416 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/dream-retriage.ts runDreamRetriage 524 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/embed.ts embedAllStale 570 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +9 #5804: a null projection snapshot is a counted failure (archived sources left to reportArchived) with one end-of-run batch summary; +4 wave 8 lane D1 #5527: subtract current-model chunks from the mixed-space warning; +2 Foundations 1 F4d: a time-budget stop with stale chunks left records reason, remaining count and resume command (src/core/embed-budget-stop.ts); +3 TODO: large-pages A9/T3: per-page spend cap meters each page (logic in core/page-embedding-budget.ts meterStaleBatch/spendGrant); +1 TODO: large-pages Wave B PR 1 lane 1e: a segmented page's stale rows route to the keyset sweep (logic in core/page-body/segmented-embedding.ts)
src/commands/embed.ts runEmbedCore 381 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +5 wave 8 lane D1 #5885: stale-drain takes pass call and its watchdog progress counter
src/commands/eval-longmemeval.ts runEvalLongMemEval 740 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/extract-conversation-facts.ts runExtractConversationFactsCore 355 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 #5757: managed flag threaded into ExtractCoreState; +4 #5823: shared default-cap wiring and structured budget reason/model; decision logic is in facts/conversation-budget.ts; +2 #5330: strict-eligibility read and the enumeration filter through the shared predicate (rule lives in facts/conversation-types.ts); lowered to 355 at the wave-9 follow-ups merge (zero result via emptyExtractConversationFactsResult)
src/commands/extract.ts runExtract 398 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/import.ts runImport 978 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +4 GBRA-40 F4b: planner-stats refresh every import.analyze_every_pages files (logic in planner-stats.ts); +6 #5988: onFileResult hook so full sync holds content refusals (logic in commands/sync/holds.ts); +3 #5988: heldPaths skip so a full sync never imports a rename destination it held this run (logic in commands/sync/holds.ts); +1 Wave B lane 1d (TODO wave-b PR 1): reads the segmented-storage policy once per run for the streamed import of files over the single-string ceiling; +1 GBRA-218 A2: the import barrier installs the tree's folder rules before any page (logic in access/policy-transfer.ts); +4 GST-2462: the noticeRun option, the privacy_label_ignored notice call and its JSON and result fields (logic in core/search/ignored-privacy-labels.ts)
src/commands/mcp-expose.ts runPublish 444 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 GBRA-583: one printInstallLinks call in the Next block (link building and lines live in core/connector-install-links.ts)
src/commands/migrate-engine.ts runMigrateEngine 405 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/sources.ts runAdd 365 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 fix wave 4 #5673: connector sources print that autopilot keeps them synced after the first sync
src/core/bootstrap/harness.ts applyHarness 1167 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/brainstorm/orchestrator.ts _runBrainstormInner 413 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 #5890 close-set spreads INTERNAL_BREADTH_SEARCH_OPTS
src/core/check-resolvable.ts checkResolvable 419 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/config.ts loadConfigWithEngine 362 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 #5824: search.vector_legacy_guard DB-plane merge
src/core/context-engine.ts createGBrainContextEngine 520 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 #4618: seat sidecar call before the segment spool (helper recordOpenclawSeat)
src/core/context/retrieval-reflex.ts resolveEntitiesToPointers 362 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +7 fix wave 11 #6195: multi-word weak n-gram norms and the weak-title arm call (logic in weakTitleHits)
src/core/cycle.ts runCycleUnscoped 1292 #6696 (A5): the body of runCycle, renamed when runCycle became its background-origin wrapper (9 lines shorter); seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +5 #5809: extract_atoms phase gets a real abort signal; +2 #5809: cycle_already_running names the lock holder; +1 #4578: a lock steal during the last selected phase reports lock_stolen (one phase per runCycle call); +4 GBRA-40 F4b: planner-stats refresh after the freshness phases; +14 #5876: Life Chronicle phase dispatch block; +6 GBRA-40 Lane D: facts_drain phase dispatch; +10 GBRA-49: edge_contradictions phase dispatch block (adapter in cycle/edge-contradictions.ts); +6 #6188: fence_repair phase dispatch block (logic in cycle/fence-repair.ts); +2 fix wave 12 #6242: lease-set result and the maintenance-busy skip call (logic in skipBrainWidePhases and cycle/lock-set.ts); +7 C4: standing_questions phase dispatch block (logic in questions/phase.ts); +13 GBRA-438: bookkeeping_gc phase dispatch block (logic in cycle/bookkeeping-gc.ts) and the CycleOpts.stamp switch on the freshness stamp block; +2 GBRA-387 storage manifest: a cycle scoped to the storage shelf returns skipped storage_manifest_source (check in storage-manifest/door.ts); these two lines land on top of growth master already took (1290 at 9563d748, 1292 measured after the merge), and splitting the function to hide two lines is left to the wave-2 decomposition
src/core/cycle/extract-atoms.ts runPhaseExtractAtoms 790 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +12 #5809/#5832: hard/soft stop checks, chat-call signal, abortable pacing, no post-stop writes; +1 #5856: one BudgetTracker per drain attempt (reuse the attempt's tracker); +2 fix wave 9 lane P (#5041): opt-in write-through hook creation and its per-item call (derived-write-through.ts); +1 #5031: per-run page-atom title memo for the case-insensitive adoption fallback
src/core/cycle/extract-atoms.ts runPhaseExtractAtoms>withBudgetTracker(#1) 302 +2 #7923: an idempotency conflict on a batch another run of the origin admitted waits on that batch and is counted (logic in persistence/atom-maintenance.ts concurrentAtomBatch); decomposition deferred with runPhaseExtractAtoms (refactor wave 2, plan D1)
src/core/cycle/extract-facts.ts runExtractFacts 385 +3 GBRA-438: a macrotask yield every 50 pages of the walk so idle upkeep can abort it, re-measured at the master 3f138e1b4 merge; seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); -129 wave 9 follow-ups (receipts): the page reconcile plan and writes moved into planFenceReconcile/reconcileWrites/writeFenceReconcile, shared with the managed preparer; +2 #6264 (landed alongside): ontology observations never gate the unfenced-rows count; +2 #6259 (landed alongside): a quarantined page projects no fence facts; +1 #5575 I2 (L1a-taint): the run result sums the write-gate tally each page reconcile returns; +1 merge v0.60.249.0: Wave B PR 1 segmented-page skip (+4, absorbed before) and master growth compose at 382; +2 GBRA-438 PR 2: the reconcile walk yields a macrotask every 50 pages so an abort from a timer or stdin lands mid-walk on PGLite
src/core/cycle/grade-takes.ts GradeTakesPhase.process 402 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/cycle/propose-takes.ts ProposeTakesPhase.process 430 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 #5958 (issue #5874): call_timeout_ms read and its per-page bound (phaseBoundedCallTimeout); +1 #5425 [UC4]: the one attribution-check call after the extractor returns (logic in propose-takes-attribution.ts)
src/core/cycle/synthesize-concepts.ts runPhaseSynthesizeConcepts 498 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +4 #5490 review: a narrative a chat_fallback_chain model wrote is hashed under that model so the next cycle re-synthesizes it; +13 fix wave 9 lane P (D-N3): fence-stripped member hash with legacy-hash grandfathering, and the classic write moved to publishClassicConcept (concept-publication.ts); +3 (#5041): opt-in concept write-through hook and the import callback publishClassicConcept runs under the page lock; +6 #4907 (issue #4906): configured budget read, budget-capped counter, summary clause and details.warnings (message text in budgetWarnings); +4 fix wave 11 #6161: concept redirects in grouping and the skipped_deleted pre-check (logic in cycle/concept-redirects.ts); +13 fix wave 12 #6260: a narrative stopped before the end is a counted failure, and the per-member-hash retry bound (state in cycle/concept-retry-bound.ts); +8 #6643 PR B: drifted concepts skipped before spend (state and the live check in persistence/drift-conflicts.ts ConceptDriftSkips), with the warn status, summary clause and skipped_file_drift details; +10 #7269 (GBRA-161 PR 4): a T3 group hashes without the synthesis model, and a rewrite that would leave a deterministic-tier page at its current template body and visibility is skipped unchanged; -94 GBRA-60 G6: the publication steps (managed batches, provenance edges, world promotion) moved to cycle/concept-writes.ts
src/core/cycle/synthesize.ts runPhaseSynthesizeInner 1057 +1 #7805: the session-source routing parameter the discovery call site fills (logic in cycle/synthesize-source-routing.ts); +1 #5575 I2: output refs take their transcript taint before the provenance stamp (the stamp line stays the signal-guarded literal cycle-abort pins); seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 #5854: publish_pending from postprocess, a pending summary publish deferred instead of failing the phase; +1 fix wave 11 #6160: oneshot_task_prefixes on the child job data; +6 GBRA-161 PR 4 (#7065): the synthesis generation activation after postprocess (logic in cycle/synthesize-generations.ts), its file holds and details.synthesis_generations; +1 GBRA-161 PR 5 (S-2): the summary revision read before the children are submitted; +1 GBRA-60: a managed child carries dream_output, so it writes each page verified and stamped (logic in cycle/synthesize-child-verify.ts)
src/core/embed-stale.ts embedStaleForSource 302 PR 4 E round 2 (gbrain-evals#180): the page embedding lease gives up at the drain deadline with a busy lease (page skipped) and is renewed inside the install transaction; lease logic lives in core/page-embedding-lease.ts
src/core/facts/backstop.ts runPipelineBodyInner 358 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/facts/fence-write.ts writeFactsToFence 301 GST-2203 (#9034): the created facts section carries the rows a dropped section held (withHeldFactsFence), one line over the limit; TODO(GST-2203 follow-up): move the held-section step out of writeFactsToFence
src/core/import-file.ts importFromContent 698 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 wave 8 lane D1 #5158: key-order fallback equality and legacy-hash ordering; lowered to 807 (#5988: screen and sanity config peeled to core/import-screen.ts); +1 #6007: the prepared apply reports its written page and seal (PreparedImportApplied) so put_page skips a re-read and a second seal; +1 #5333: embed-skip transition defeats the unchanged fast paths (the stale-marker clear stays inside the sanity block); +3 #6188: Tier 1 fence step in place before the hidden-row merge (logic in fence-repair/import-step.ts); -146 #5575: content-sanity/write-gate disposition moved to import-screen.ts settleContentDisposition; +4 TODO: large-pages A6/T33: a page over PAGE_INLINE_MAX_BYTES commits with NULL vectors and embeds through the metered stale sweep; +1 #6722: an embed_skip page is chunked and never embedded (noEmbed folds the marker); +16 Wave B lane 1d (TODO wave-b PR 1): a body above the inline threshold takes the segmented stage and generation flip at the storage step (logic in persistence/segmented-apply.ts); +3 Wave B review: reuseSegments option (a rename re-preparation reuses the staged segmented body) and the remote fence merge over fenceBody; +2 Wave B gem A: a coordinated demotion versions the segmented page before demoting it; +2 #8523 B3a: the screened body runs as the importScreened closure, entered in an embedded engine's scope after the engine-free screen and the source check; +1 GBRA-217 #7798 (memory train #8481): the history option (a sync import's Git reason and history-gap marker) on the opts type; +3 GST-2112: the expectedBaseRevision option (opts type) and its base check, so a webhook capture writes only over the revision its readers check read
src/core/import-file.ts importFromContent>importScreened 570 #8523 B3a: importFromContent's body after the engine-free screen and the source check, run in an embedded engine's scope (seed: W5 baseline, refactor wave 1; decomposition deferred to wave 2, plan D1); +1 GST-2112: the expectedBaseRevision base check
src/core/minions/handlers/subagent-oneshot.ts runSubagentOneshot 378 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 fix wave 9 lane B #4921: the oneshot sub-budget is passed as the call timeoutMs so the 300 s gateway backstop cannot cut it
src/core/minions/handlers/subagent.ts makeSubagentHandler 890 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 fix wave 9 lane B #4921: per-turn timeout read once, passed to oneshot and gateway loop; +2 GBRA-60: a trusted dream child gets the put_pages batch tool (buildBrainPutPagesTool) from the oneshot tool options; +1 #7850: a dream synthesis child re-checks its session source before any model call (one call line; the check is refuseChangedSessionSource in cycle/synthesize-source-routing.ts)
src/core/minions/handlers/subagent.ts makeSubagentHandler>subagentHandlerInner 820 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 fix wave 9 lane B #4921: per-turn timeout read once, passed to oneshot and gateway loop; +2 GBRA-60: a trusted dream child gets the put_pages batch tool (buildBrainPutPagesTool) from the oneshot tool options; +1 #7850: a dream synthesis child re-checks its session source before any model call (one call line; the check is refuseChangedSessionSource in cycle/synthesize-source-routing.ts)
src/core/minions/handlers/subagent.ts runSubagentViaGateway 329 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 fix wave 9 lane B #4921: turnTimeoutMs forwarded to gateway.toolLoop
src/core/minions/queue.ts MinionQueue.add 498 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/minions/queue.ts MinionQueue.add>result=this.engine.transaction(#0) 359 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/minions/worker.ts MinionWorker.start 470 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/ops/facts.ts recall.handler 358 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 #4830 (W14 PR3): every hit names its source_id, falling back to the scope's single source (the federated case stays absent); +3 W5: recall threads the page-unit ranking cut into its hybrid page arm (logic in search/page-rank-cut.ts; delivery reports it); +3 #7043: copies of one claim collapse before the limit cut (the collapse lives in facts/capture-dedup.ts collapseFactReads) and the row names its entity_slugs/collapsed_count; +1 HARN-15: max_chars is parsed before any read (the bound lives in boundRecallChars)
src/core/ops/search.ts query.handler 338 +5 GBRA-81 item 5 per-stage search timings: the request's SearchTimings and setup-stage binding, the image branch's limit read hoisted out of the timed vector call, and its response stage wrapper (collector logic in search/stage-timings.ts); seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 GBRA-49 explain_target: one TargetTrace prep line and its HybridSearchOpts thread (diagnosis/meta live in prepareExplainTarget/finishExplainTarget); +1 W5 (#6445): query passes the page-unit ranking cut to hybrid search (logic in search/page-rank-cut.ts), merged with master growth
src/core/persistence/page-prepare.ts prepareInlineOrSegmentedMutation 304 +3 #7841: a put_page that asks for visibility: private is kept or refused (visibility_not_applied), checked before the no-op test and after the trust stamp (logic in persistence/visibility-request.ts); +1 #9036: a put over a soft-deleted page takes its tags from its own content and skips the deleted page's timeline rows
src/core/progressive-batch/orchestrator.ts runProgressiveBatch 348 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/remediation/run.ts runRemediation 428 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/skillopt/orchestrator.ts runOptimizationLoop 644 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/sources-ops.ts addSource 317 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/think/index.ts runThink 450 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/mcp/http-transport.ts startHttpTransport 409 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 cat40 cost wave C1 (garrytan/gbrain-evals#57 follow-ups): dispatch resultRows from X-Gbrain-Client / mcp.result_rows (logic in mcp/result-rows.ts)