fix(mitm): inject x-omniroute-source and x-omniroute-agent headers in server.cjs intercept (C2, master plan §3.5)

`MitmHandlerBase.fetchRouter` already injects the AgentBridge correlation
headers, but the CJS proxy in `src/mitm/server.cjs` had never been
updated to match. As a result the running Antigravity flow was hitting
the OmniRoute router with no source/agent identification, breaking the
contract documented in master-plan-group-A.md §3.5 and §12 acceptance #17.

This commit adds:

- `x-omniroute-source: agent-bridge` — distinguishes AgentBridge traffic
  from other inbound clients.
- `x-omniroute-agent: <id>` — IDE agent id resolved from the Host header
  via the existing `TARGET_HOST_AGENT` map (populated by `targets.json`
  + the antigravity baseline). Defensive fallback to `"unknown"` for
  hosts that were never registered, so router-side filters never get
  an empty value.

Antigravity non-regression preserved: `daily-cloudcode-pa.googleapis.com`
continues to resolve to `agentId="antigravity"` via the baseline seed in
`TARGET_HOST_AGENT.set(h, "antigravity")` at the top of the file.
This commit is contained in:
diegosouzapw
2026-05-28 16:48:24 -03:00
parent bcfc87f31b
commit 669b5fe4f5

View File

@@ -367,11 +367,21 @@ async function intercept(req, res, bodyBuffer, mappedModel) {
const body = JSON.parse(bodyBuffer.toString());
body.model = mappedModel;
// C2 — Inject AgentBridge correlation headers per master plan §3.5.
// The OmniRoute router uses these to distinguish AgentBridge traffic from
// other inbound clients and to record the originating IDE agent id.
// Resolve agent id from the Host header against the target map; defensive
// fallback to "unknown" when the host is somehow not in the map.
const reqHost = String(req.headers.host || "").split(":")[0].toLowerCase();
const agentId = TARGET_HOST_AGENT.get(reqHost) || "unknown";
const response = await fetch(ROUTER_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
"x-omniroute-source": "agent-bridge",
"x-omniroute-agent": agentId,
},
body: JSON.stringify(body),
});