feat: codebase map bootstrap (map_id + routing hints)#183
Conversation
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 detectedLatest commit: 676a079 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements hash-stable ChangesCodebase map routing in context bootstrap
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/application/http-server.test.ts (1)
430-436: ⚡ Quick winAvoid hard-coding the
cli_entry_hintscount.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
📒 Files selected for processing (21)
.changeset/codebase-map-bootstrap.mddocs/agents.mddocs/architecture.mddocs/plans/codebase-map-bootstrap.mddocs/roadmap.mdsrc/application/agent-content.tssrc/application/context-engine.test.tssrc/application/context-engine.tssrc/application/http-server.test.tssrc/application/mcp-server.test.tssrc/application/mcp-server.tssrc/application/tool-handlers.test.tssrc/application/tool-handlers.tssrc/cli/aliases.tssrc/cli/cmd-cli-parity.test.tssrc/cli/cmd-context.test.tssrc/cli/cmd-context.tssrc/cli/main.tssrc/outcome-aliases.tstemplates/agent-content/mcp-instructions.mdtemplates/agent-content/skill/10-recipes-context.md
💤 Files with no reviewable changes (1)
- docs/plans/codebase-map-bootstrap.md
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.
Summary
map_idandcodebase_map(hub paths + codemap CLI/MCP routing hints) tocontextresponses on CLI, MCP, and HTTP.initializeinstructions appendmap_idand top three hub paths after bootstrap (after watch prime when--watchis on).--no-codebase-map/include_codebase_map: false; fields omitted whencompact.architecture.md,agents.md, androadmap.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.tsbun run typecheckbun 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")'→ falsebun src/index.ts context --compact --json | jq 'has("codebase_map")'→ falseSummary by CodeRabbit
map_idandcodebase_maprouting information to context responses across CLI, MCP, and HTTP endpoints.--no-codebase-mapCLI flag to exclude codebase routing data from context output.include_codebase_mapoption to context tool for granular control over routing field inclusion.