fix(mitm): route Claude Code standalone MITM traffic - #7574
diegosouzapw merged 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces agent-specific routing configurations in the MITM server to support Claude Code and Kiro alongside Antigravity, mapping models dynamically using their respective alias keys and forwarding their traffic to an Anthropic-compatible messages endpoint. Unit tests have also been added to verify this routing behavior. The review feedback suggests a great improvement to avoid hardcoding specific agent IDs in the interception logic by leveraging the newly introduced route configuration's routerPath property, and updating the unit tests accordingly to prevent fragile string matching.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const forward = | ||
| agentId === "claude-code" || agentId === "kiro" | ||
| ? { format: "anthropic", url: ROUTER_MESSAGES_URL } | ||
| : forwardShim.resolveForwardTarget(ROUTER_BASE_URL, body); |
There was a problem hiding this comment.
Instead of hardcoding specific agent IDs (claude-code and kiro) in the intercept function, you should leverage the newly introduced AGENT_ROUTE_CONFIG and check the configured routerPath. This makes the routing logic much more maintainable and extensible when new agents are added in the future.
const config = getAgentRouteConfig(agentId);
const forward =
config.routerPath === "/v1/messages"
? { format: "anthropic", url: ROUTER_MESSAGES_URL }
: forwardShim.resolveForwardTarget(ROUTER_BASE_URL, body);
| test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => { | ||
| assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/); | ||
| assert.match(src, /agentId === "claude-code" \|\| agentId === "kiro"/); | ||
| assert.match(src, /url: ROUTER_MESSAGES_URL/); | ||
| }); |
There was a problem hiding this comment.
Asserting on exact source code string matches (like /agentId === "claude-code" \|\| agentId === "kiro"/) makes the tests highly fragile and prevents refactoring. Since we refactored the routing logic to use the AGENT_ROUTE_CONFIG's routerPath property, we should update this test assertion accordingly.
| test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => { | |
| assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/); | |
| assert.match(src, /agentId === "claude-code" \|\| agentId === "kiro"/); | |
| assert.match(src, /url: ROUTER_MESSAGES_URL/); | |
| }); | |
| test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => { | |
| assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/); | |
| assert.match(src, /config\.routerPath === "\/v1\/messages"/); | |
| assert.match(src, /url: ROUTER_MESSAGES_URL/); | |
| }); |
|
Thanks for tackling #7572 — the standalone MITM server genuinely has no Claude Code/Kiro routing today, and the per-agent AGENT_ROUTE_CONFIG shape you introduced is a clean fit with the existing AgentId naming (targets/claudeCode.ts, targets/kiro.ts). This PR is opened against Could you: (1) retarget/rebase this PR onto Separately, heads up: PR #7582 touches the same function for a related but different fix (route-alias fallback) and is also branched slightly before #7228 landed — whichever of the two lands first, the other will need a follow-up rebase. |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
9d6aedf to
c390cb3
Compare
|
Review feedback addressed.
Verification run locally: node --import tsx/esm --test tests/unit/mitm-server-claude-code-routing.test.ts tests/unit/mitm-alias-config-shim.test.ts tests/unit/mitm-forward-target.test.tsResult: 14 tests passed. Current PR state: mergeable, Semgrep passed. |
Sync with the current release tip (9 commits ahead of this PR's fork point; none touch src/mitm/ or the standaloneRouting shim, so no conflict resolution was needed here). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
|
Merged into |
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Summary
/v1/messagestraffic to OmniRoute/v1/messagesmitmAliasnamespace instead of always usingantigravityCloses #7572
Tests
node --import tsx/esm --test tests/unit/mitm-server-claude-code-routing.test.tsnode --import tsx/esm --test tests/unit/mitm-handler-claudeCode.test.ts tests/unit/mitm-handler-antigravity.test.ts tests/unit/antigravity-mitm-model-resolution.test.ts