Skip to content

feat: codebase map bootstrap (map_id + routing hints)#183

Merged
SutuSebastian merged 4 commits into
mainfrom
feat/codebase-map-bootstrap
Jun 11, 2026
Merged

feat: codebase map bootstrap (map_id + routing hints)#183
SutuSebastian merged 4 commits into
mainfrom
feat/codebase-map-bootstrap

Conversation

@SutuSebastian

@SutuSebastian SutuSebastian commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add hash-stable map_id and codebase_map (hub paths + codemap CLI/MCP routing hints) to context responses on CLI, MCP, and HTTP.
  • MCP initialize instructions append map_id and top three hub paths after bootstrap (after watch prime when --watch is on).
  • Opt out via --no-codebase-map / include_codebase_map: false; fields omitted when compact.
  • Retire plan doc; lift to architecture.md, agents.md, and roadmap.md.

Test plan

  • bun test src/application/context-engine.test.ts src/application/tool-handlers.test.ts src/application/mcp-server.test.ts src/application/http-server.test.ts src/cli/cmd-context.test.ts
  • bun run typecheck
  • bun src/index.ts context --json | jq '.map_id, .codebase_map.cli_entry_hints | length'
  • bun src/index.ts context --no-codebase-map --json | jq 'has("map_id")' → false
  • bun src/index.ts context --compact --json | jq 'has("codebase_map")' → false

Summary by CodeRabbit

  • New Features
    • Added map_id and codebase_map routing information to context responses across CLI, MCP, and HTTP endpoints.
    • Introduced --no-codebase-map CLI flag to exclude codebase routing data from context output.
    • Added include_codebase_map option to context tool for granular control over routing field inclusion.
    • Map identifiers now included in MCP session initialization instructions with top hub paths.
    • Routing fields automatically omitted when using compact mode.

Agents get a hash-stable routing card on context (CLI/MCP/HTTP) plus MCP
initialize instructions appendix; opt out via --no-codebase-map or compact.
Align skill shard, MCP tool description, and HTTP tests with map_id
fields; prime watch before baking initialize instructions appendix.
@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 676a079

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stainless-code/codemap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SutuSebastian, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e737044f-542e-4bc8-bfad-53cb0fc98200

📥 Commits

Reviewing files that changed from the base of the PR and between 7c30ccb and 676a079.

📒 Files selected for processing (2)
  • src/application/mcp-server.test.ts
  • src/application/mcp-server.ts
📝 Walkthrough

Walkthrough

This PR implements hash-stable map_id and routing codebase_map metadata in the context bootstrap response across CLI, MCP, and HTTP surfaces. It adds a new --no-codebase-map CLI flag, refactors outcome aliases to a shared module, and enables MCP server instruction customization via database-backed appendix generation.

Changes

Codebase map routing in context bootstrap

Layer / File(s) Summary
Outcome aliases extraction
src/outcome-aliases.ts, src/cli/aliases.ts
Moves OUTCOME_ALIASES and OutcomeAlias type to a new shared module and re-exports from CLI layer, decoupling alias definitions from CLI-specific code.
Context engine map_id and codebase_map support
src/application/context-engine.ts, src/application/context-engine.test.ts
Extends ContextEnvelope with optional map_id and codebase_map fields, adds routing/hint types, and exports helpers to build CLI entry hints, compute hash-stable map IDs, and construct codebase map payloads. Updates buildContextEnvelope to compute and attach routing data when not compact.
Context tool map_id/codebase_map parameter and HTTP response
src/application/tool-handlers.ts, src/application/http-server.test.ts
Extends ContextArgs to accept optional include_codebase_map boolean and passes through to buildContextEnvelope. Tests verify map_id and codebase_map are included by default and omitted when include_codebase_map: false.
CLI --no-codebase-map flag and wiring
src/cli/cmd-context.ts, src/cli/main.ts, src/cli/cmd-context.test.ts, src/cli/cmd-cli-parity.test.ts
Adds --no-codebase-map flag to codemap context command. parseContextRest tracks includeCodebaseMap (default true), sets false when flag provided, includes in result, and runContextCmd forwards to handleContext. All CLI parsing tests updated.
MCP server instructions override and bootstrap with map data
src/application/agent-content.ts, src/application/mcp-server.ts, src/application/mcp-server.test.ts
assembleMcpInstructions accepts optional appendix and concatenates when provided. ServerOpts gains optional instructions field; createMcpServer uses provided instructions or defaults. runMcpServer builds database-backed instructions with codebase map appendix, falls back on error. Integration test verifies MCP handshake includes map_id: and context tool.
Documentation and agent templates update
docs/agents.md, docs/architecture.md, docs/roadmap.md, templates/agent-content/mcp-instructions.md, templates/agent-content/skill/10-recipes-context.md, .changeset/codebase-map-bootstrap.md, docs/plans/codebase-map-bootstrap.md
Documents map_id and codebase_map behavior in context response, MCP initialization, CLI opt-out via --no-codebase-map, and omission conditions (compact, include_codebase_map: false). Roadmap marks feature complete. Removes completed plan.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

🐰 A map to every hub, now hashed with care,
Bootstrap routes stable through the codebase air,
Skip the compass when compact, or flag says "no way"—
Fresh sessions detect drift, cross-compare each day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding hash-stable map_id and codebase_map routing hints to context responses across CLI, MCP, and HTTP.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/codebase-map-bootstrap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/application/http-server.test.ts (1)

430-436: ⚡ Quick win

Avoid hard-coding the cli_entry_hints count.

Line 435 hard-codes 12, which can drift when aliases or session-start MCP tools change. Deriving expected count from shared constants keeps this test contract-focused.

♻️ Suggested update
+import { OUTCOME_ALIASES } from "../outcome-aliases";
+import { SESSION_START_MCP_TOOLS } from "./context-engine";
...
-    expect(r.json.codebase_map?.cli_entry_hints?.length).toBe(12);
+    expect(r.json.codebase_map?.cli_entry_hints?.length).toBe(
+      Object.keys(OUTCOME_ALIASES).length + SESSION_START_MCP_TOOLS.length,
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/application/http-server.test.ts` around lines 430 - 436, The test
"context includes map_id and codebase_map by default" currently hard-codes 12
for r.json.codebase_map?.cli_entry_hints?.length; change the assertion to derive
the expected count from the shared source of truth instead (e.g., import the
exported array/constant that defines CLI entry hints such as CLI_ENTRY_HINTS or
defaultCliEntryHints) and assert length equals that constant (for example:
expect(...length).toBe(CLI_ENTRY_HINTS.length)); update imports at the top of
the test file and keep the existing calls to startServer and postTool and the
reference to r.json.codebase_map?.cli_entry_hints to locate where to change the
assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/application/mcp-server.ts`:
- Around line 684-700: The current code always overwrites any caller-provided
opts.instructions when constructing the server (createMcpServer({ ...opts,
instructions })), so change the logic to honor an explicit opts.instructions:
set instructions = opts.instructions if present, otherwise run the existing
DB-based assembly/fallback path (use opts.instructions ?? <assembled/inferred
value>). Update the block that currently assigns to instructions (and the final
createMcpServer call) so you only build/override instructions when
opts.instructions is undefined or null, leaving createMcpServer called with the
original opts when instructions was supplied.

---

Nitpick comments:
In `@src/application/http-server.test.ts`:
- Around line 430-436: The test "context includes map_id and codebase_map by
default" currently hard-codes 12 for
r.json.codebase_map?.cli_entry_hints?.length; change the assertion to derive the
expected count from the shared source of truth instead (e.g., import the
exported array/constant that defines CLI entry hints such as CLI_ENTRY_HINTS or
defaultCliEntryHints) and assert length equals that constant (for example:
expect(...length).toBe(CLI_ENTRY_HINTS.length)); update imports at the top of
the test file and keep the existing calls to startServer and postTool and the
reference to r.json.codebase_map?.cli_entry_hints to locate where to change the
assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: faf7c1fe-06d5-4688-8b35-6fbe0467daf3

📥 Commits

Reviewing files that changed from the base of the PR and between e4f6087 and 7c30ccb.

📒 Files selected for processing (21)
  • .changeset/codebase-map-bootstrap.md
  • docs/agents.md
  • docs/architecture.md
  • docs/plans/codebase-map-bootstrap.md
  • docs/roadmap.md
  • src/application/agent-content.ts
  • src/application/context-engine.test.ts
  • src/application/context-engine.ts
  • src/application/http-server.test.ts
  • src/application/mcp-server.test.ts
  • src/application/mcp-server.ts
  • src/application/tool-handlers.test.ts
  • src/application/tool-handlers.ts
  • src/cli/aliases.ts
  • src/cli/cmd-cli-parity.test.ts
  • src/cli/cmd-context.test.ts
  • src/cli/cmd-context.ts
  • src/cli/main.ts
  • src/outcome-aliases.ts
  • templates/agent-content/mcp-instructions.md
  • templates/agent-content/skill/10-recipes-context.md
💤 Files with no reviewable changes (1)
  • docs/plans/codebase-map-bootstrap.md

Comment thread src/application/mcp-server.ts Outdated
Only assemble codebase-map appendix when caller did not supply instructions.
Extract instructions resolver from runMcpServer so CodeRabbit fix has
regression coverage without stdio integration harness.
@SutuSebastian SutuSebastian merged commit b509e4c into main Jun 11, 2026
11 checks passed
@SutuSebastian SutuSebastian deleted the feat/codebase-map-bootstrap branch June 11, 2026 09:16
@github-actions github-actions Bot mentioned this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant