Skip to content

Epic: the brain CLI and MCP server call one operations layer and one index reader #1341

Closed
8 of 8 issues completed

Description

@schlessera

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 --limit is an unchecked parseInt with no cap (packages/core/src/cli/commands/list.ts:29); MCP brain_list clamps 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 in doctor (packages/core/src/cli/commands/doctor.ts:312-330).
  • startMcpServer is one 600-line function (packages/core/src/mcp-server.ts:91-691) holding business logic the CLI cannot reuse, including the whole brain_update flow (packages/core/src/mcp-server.ts:564-640).

Current source — 2026-11-04

At inspected main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36:

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

  1. added
    type: refactor
    area: core
    area: mcp
    priority: p2
    epic
    on Oct 9, 2026
  2. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor
  3. added a commit that references this issue on Nov 3, 2026
  4. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    2026-11-03 integration-lane landing: #3505 merged the epic branch into main as merge commit 06473ef31. 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 has needs: use-case; it needs a driving CLI workflow, or a ruling that brain update stays MCP-only.

    Against the definition of done: no file under packages/core/src/cli/commands/ runs SQL, and packages/core/tests/cli-no-sql.test.ts enforces 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: whether startMcpServer now 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.

  5. schlessera commented on Nov 9, 2026

    @schlessera
    OwnerAuthor

    Closing (2026-11-09). The last open child, #1356, closed as not planned after the maintainer ruled that brain_update is 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 commit 06473ef31).

    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 under packages/core/src/cli/commands/. Milestone 0.45.0 is set because the epic's final deliveries shipped in that release.

  6. added this to the 0.45.0 milestone on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corearea: mcpepicpriority: p2type: refactor

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions