diff --git a/package-lock.json b/package-lock.json index c7e1c2e..4d468c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gitcommit90/rerouted", - "version": "0.5.13", + "version": "0.5.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gitcommit90/rerouted", - "version": "0.5.13", + "version": "0.5.14", "license": "MIT", "bin": { "rerouted": "src/cli/index.js" diff --git a/package.json b/package.json index b0fd69a..043afc5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@gitcommit90/rerouted", "productName": "ReRouted", - "version": "0.5.13", + "version": "0.5.14", "description": "A local AI router for connected accounts, models, named routes, and automatic fallback.", "author": "gitcommit90", "license": "MIT", diff --git a/src/lib/providers/claude.js b/src/lib/providers/claude.js index c052b4e..b9c710f 100644 --- a/src/lib/providers/claude.js +++ b/src/lib/providers/claude.js @@ -109,21 +109,19 @@ function generateBillingHeader(payload) { } /** - * Strip third-party agent structure that can trigger extra-usage or proxy - * detection on OAuth traffic. + * Preserve client system context while moving it into the provider-compatible + * reminder location used for OAuth traffic. Truncating this text is unsafe: + * callers rely on late system blocks for policy, memory, and handoff state. */ function sanitizeForwardedSystemPrompt(text) { - if (!String(text || "").trim()) return ""; - // Keep a short neutral reminder; full client system prompts look like non-CLI agents. + const forwarded = String(text || "").trim(); + if (!forwarded) return ""; return [ "Use the available tools when needed to help with software engineering tasks.", "Keep responses concise and focused on the user's request.", "Prefer acting on the user's task over describing product-specific workflows.", - // Preserve a short slice of original context if useful - String(text).trim().slice(0, 400), - ] - .filter(Boolean) - .join("\n"); + forwarded, + ].join("\n"); } /** Wrap forwarded system context in provider-compatible reminder blocks. */ diff --git a/tests/gateway.test.js b/tests/gateway.test.js index 472bc7b..96a845a 100644 --- a/tests/gateway.test.js +++ b/tests/gateway.test.js @@ -745,10 +745,12 @@ describe("OAuth refresh against mock", () => { describe("claude oauth request shaping", () => { it("applyCloaking injects CC system blocks + metadata; moves client system to user", () => { + const lateSystemSentinel = `LATE_SYSTEM_HANDOFF_${"z".repeat(1600)}_END`; const base = claude.toAnthropicBody( { messages: [ { role: "system", content: "You are a custom app agent with secret tools." }, + { role: "system", content: lateSystemSentinel }, { role: "user", content: "hi" }, ], max_tokens: 8, @@ -774,6 +776,9 @@ describe("claude oauth request shaping", () => { ? userContent.map((b) => b.text || "").join("\n") : String(userContent); assert.ok(userText.includes(""), userText.slice(0, 200)); + assert.ok(userText.includes("You are a custom app agent with secret tools.")); + assert.ok(userText.includes(lateSystemSentinel), "late and long client system context must survive OAuth request shaping"); + assert.ok(userText.includes(`${lateSystemSentinel}\n\nIMPORTANT:`), "the complete sentinel must precede the reminder footer"); const uid = JSON.parse(cloaked.metadata.user_id); assert.equal(uid.session_id, sessionId); assert.ok(uid.device_id && uid.account_uuid);