Skip to content

core: decide provider availability once in the registry instead of in three callers #1350

Closed

Description

@schlessera

Part of #1341.

Context

Whether an embedding provider is usable is decided three times: resolveProviders (packages/core/src/cli/brain.ts:113-131), the MCP server (packages/core/src/mcp-server.ts:104-113) and doctor (packages/core/src/cli/commands/doctor.ts:389). Each hard-codes "GEMINI_API_KEY" as the default key name, which also appears in packages/core/src/cli/brain.ts:96, :101, :128 and packages/core/src/cli/commands/init.ts:74, while the providers already own their default (packages/core/src/providers/embeddings/gemini.ts:47, packages/core/src/providers/completions/gemini.ts:54). The registry is a plain record of factories (packages/core/src/lib/registry.ts:35-70) with no key metadata.

Scope

  • Each built-in registry entry declares its default key variable.
  • One resolveProviders(config) (or equivalent) in lib/registry.ts returns the resolved providers plus degraded-mode warnings.
  • CLI, MCP and doctor call it.

Out of scope

  • Adding a provider; changing the custom-implementation path ({ provider: value }).
  • Changing warning text in --json envelopes.

Acceptance criteria

  • grep -rn '"GEMINI_API_KEY"' packages/core/src matches only the registry/provider definitions and the env descriptor.
  • A test registers a fake built-in with a different key name and proves CLI and MCP both honour it, failing before the change.
  • CLI and MCP contract snapshots are unchanged.

Verification

bun run test packages/core
bun run typecheck

Contract impact

None intended.

Blocked by #1355

2026-10-09: sequenced against the other code-quality issues to avoid overlapping edits; see the epic's planned-order comment.

Activity

  1. added
    type: refactor
    area: core
    area: mcp
    priority: p2
    agent-ready
    on Oct 9, 2026
  2. added
    blocked
    on Oct 9, 2026
  3. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1355 is closed, so scripts/sync-project.ts is removing the blocked label.

  4. removed
    blocked
    on Oct 10, 2026
  5. self-assigned this
    on Oct 10, 2026
  6. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Claimed (claim token wi-1350-a7). Working on branch refactor/1350-registry-provider-availability.

  7. added this to the 0.41.0 milestone on Oct 10, 2026
  8. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Merged in #1458 as a8f884f (parent 02fd0b9). Built-in embedding and completion entries in lib/registry.ts now declare their key variable, and resolveProviders(config) decides availability for the CLI, the MCP server and brain doctor. "GEMINI_API_KEY" appears only in the two Gemini provider definitions and the env descriptor. provider-availability.test.ts runs a fake built-in with its own key through the real CLI and MCP server: it failed first on the pre-change tree for both hosts, and three mutations fail on the expected assertions (receipts in the PR). The CLI and MCP contract snapshots are unchanged. CI run 38026939921 passed every selected job on head 72ff4a6 (merge checkout b6658a6 onto d4eff9f). Main then advanced only by 02fd0b9 (ui-sdk/backends, no core changes). The combined tree merged cleanly and passed typecheck and the citation test locally; the squash tree equals that combined tree. #1349 is unblocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: corearea: mcppriority: p2type: refactor

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions