Repository navigation
Description
Outcome
Every behaviour reachable from both brain CLI commands and brain_* MCP tools is implemented once in packages/core/src/lib/ and called by thin surface adapters. CLI commands contain no SQL. Provider availability is decided in one place. Markdown writes go through one safe writer. The two surfaces cannot drift on limits, validation or degraded-mode decisions, because there is only one implementation to drift.
Why now
Found by the 2026-10-09 code-quality review of main @ 0c69e0cb. The CLI --json shapes and MCP schemas are a versioned contract. The following observations describe that review SHA, before the deliveries described in Current source below:
brain list --limitis an uncheckedparseIntwith no cap (packages/core/src/cli/commands/list.ts:29); MCPbrain_listclamps the same limit to 1..100 (packages/core/src/mcp-server.ts:441).- Provider availability is decided three times with a hard-coded default key name (
resolveProviders,packages/core/src/cli/brain.ts:113-131;packages/core/src/mcp-server.ts:104-113;packages/core/src/cli/commands/doctor.ts:389). - Index staleness is computed in the MCP server (
indexStalenessWarning,packages/core/src/mcp-server.ts:134-174) and again indoctor(packages/core/src/cli/commands/doctor.ts:312-330). startMcpServeris one 600-line function (packages/core/src/mcp-server.ts:91-691) holding business logic the CLI cannot reuse, including the wholebrain_updateflow (packages/core/src/mcp-server.ts:564-640).
Current source — 2026-11-04
At inspected main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36:
- CLI list parsing (
parseListLimit,packages/core/src/cli/commands/list.ts:30) and MCP share the 1–100 integer rule. Provider availability is registry-owned; the CLI'scliProviderswrapper consumesresolveProviders(packages/core/src/cli/brain.ts:95). - Doctor and MCP use the shared
indexStaleness; MCP's cached warning adapter isstalenessWarning(packages/core/src/mcp-server.ts:115). The update adapter delegates to sharedupdateDocumentFields(packages/core/src/lib/ops/write.ts:77). - core: CLI flags read through unchecked casts accept bare, non-integer and unknown enum values #1352/core: move raw SQL out of CLI commands and keep one silent-edit query #1353/core: two graph readers over the same tables with a stale comment explaining why #1354 are delivered on main through CONTRACT: refactor(core): land epic #1341 — shared CLI/MCP core operations #3505, as the landing receipt records. No CLI command contains direct SQL;
bun run test packages/core/tests/cli-no-sql.test.tspassed 2 tests at this SHA. That focused control does not independently requalify all delivered PRs. - The only open native child is core: brain_update has no CLI equivalent #1356, which still needs a driving CLI update use case or a recorded MCP-only disposition. Independently check the registration/delegation part of the full definition of done before parent closure.
Shared context
- Core has no import cycles and a strict public/internal split (
packages/core/src/index.ts:1-10,packages/core/src/internal.ts:1-8); keep both true. - The original five raw-SQL command sites are migrated; the no-SQL guard above owns recurrence coverage.
- Contract tests snapshot both surfaces (
packages/core/tests/cli-contract.test.ts,packages/core/tests/mcp-contract.test.ts). They are the guard that this refactor changes no observable shape unless a task says so. - Supported external index reads are being moved onto query results under docs: retire direct brain.db SQL guarantees after query migration #701; that is the external contract. This epic is the internal structure and must not widen or narrow
./queries.
Constraints and non-goals
- ROADMAP binding decisions 1, 3 and 4 apply: markdown is the source of truth, the CLI executes, the machine surface is a versioned contract.
- No new seam. A shared operations module is concrete code, not an extension point.
- No behaviour change unless the task states it and carries
contract. - Not a rewrite of the search or indexing pipeline.
Breakdown
Sub-issues carry the plan. Order: provider resolution and ops extraction first (they are independent), then SQL extraction, then the smaller parity fixes.
Definition of done
startMcpServer registers tools and delegates; no file under packages/core/src/cli/commands/ calls .prepare(, .query( or .run( on a database; one function decides provider availability; contract snapshots are unchanged except where a sub-issue's ruling changed them.
2026-10-10 triage at main 7e398dc207f2c4725f6c364331c3cd5d3112954d: 1349 shared MCP operations are delivered by1468/62cf4d6c,1350 registry-driven provider availability by1458/a8f884f8,1351 strict shared1–100 list limit by1470/6cb61cba, and1355 atomic document writes by1435/20557bf5. The approved additive/behavioral contract records travel with those squashes. Remaining native SQL/index-reader/other parity tasks keep the full outcome open; derived1356 use-case work is not implicitly approved. This triage inspected landed source/ancestry and current issue receipts, not a fresh test suite or independent automatic-main CI audit. Native child lists retain progress; epic readiness remains absent.
2026-10-16 triage: separated original review observations from verified current-source behavior so delivered list-limit, provider and shared-operation changes are not presented as outstanding defects. Preserved the remaining native tasks, contract constraints and epic-not-ready status.
2026-10-29 source review at main 83252add0357908a00fa4181b8e7b731938c69e7: refreshed the active shared-limit and provider-resolution anchors and rechecked the staleness/update adapters. Direct SQL still exists in all five listed command files. The native child inventory remains four closed deliveries and four open tasks (#1352, #1353, #1354, #1356); child closure alone is not the no-SQL/shared-reader outcome. Preserve the historical review observations and delivery receipts, priority p2 and no epic readiness. No new runtime proof or completion is claimed.
2026-11-04 triage at main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36: Folded the later main landing into the active specification and removed the contradictory still-present SQL claim; #1356 and the full epic outcome remain open. No new runtime qualification or implementation is claimed.
Triage 2026-11-08 at main 8752570331ffebdbb9233196412781f6cd71f3d9: Verified the moved active source anchors and refreshed navigation. Historical measurements and source-bound failure receipts keep their identities; existing scope, rulings, needs, priority, assignment and release attribution are preserved. This source review supplies no new runtime qualification or epic completion.
Activity
chore(ci): map the code-quality epics to board tracks
schlessera commentedon Oct 9, 2026
Planned order (2026-10-09), so the PRs that all edit
mcp-server.ts,doctor.tsandcli/brain.tsland one at a time:#1368 (row validation, in #1344) waits on #1353 and #1367.
chore(ci): map the code-quality epics to board tracks (#1395)
Merge pull request #3505 from schlessera/epic/1341-shared-core-ops
schlessera commentedon Nov 3, 2026
2026-11-03 integration-lane landing: #3505 merged the epic branch into
mainas merge commit06473ef31. It delivered #1352 (#3292), #1353 (#3293) and #1354 (#3295), and each of those issues is now closed with milestone 0.45.0. All native children are closed except #1356, which still hasneeds: use-case; it needs a driving CLI workflow, or a ruling thatbrain updatestays MCP-only.Against the definition of done: no file under
packages/core/src/cli/commands/runs SQL, andpackages/core/tests/cli-no-sql.test.tsenforces it. Provider availability is decided in one place in the registry (#1350). The contract snapshots changed only where #1352's ruling changed them. Not re-audited in this landing: whetherstartMcpServernow only registers tools and delegates. Check that before closing the epic.#3295 preserved four graph-profile differences that each need a separate maintainer ruling if they are to change: the CLI never truncates, the CLI does not clamp
staleDays, the CLI coerces root link values to integers, and the UI counts a NULL asset type as a node.schlessera commentedon Nov 9, 2026
Closing (2026-11-09). The last open child, #1356, closed as not planned after the maintainer ruled that
brain_updateis MCP-only by design (the documentation note is #3780). All other native children are closed: #1349, #1350, #1351, #1355 (0.41.0) and #1352, #1353, #1354 (0.45.0, via the 2026-11-03 integration landing #3505, merge commit06473ef31).Definition of done checked at main
fb999b8ba:startMcpServer(packages/core/src/mcp-server.ts:723) only composes, registers and delegates to the ops layer, and no.prepare(,.query(or.run(database calls remain underpackages/core/src/cli/commands/. Milestone 0.45.0 is set because the epic's final deliveries shipped in that release.