From 669b5fe4f57585728bb1fcec60fd86ae7c96a63b Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Thu, 28 May 2026 16:48:24 -0300 Subject: [PATCH] =?UTF-8?q?fix(mitm):=20inject=20x-omniroute-source=20and?= =?UTF-8?q?=20x-omniroute-agent=20headers=20in=20server.cjs=20intercept=20?= =?UTF-8?q?(C2,=20master=20plan=20=C2=A73.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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: ` — 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. --- src/mitm/server.cjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mitm/server.cjs b/src/mitm/server.cjs index a22428b098..0543b80a23 100644 --- a/src/mitm/server.cjs +++ b/src/mitm/server.cjs @@ -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), });