Skip to content

Commit e200e45

Browse files
authored
Preserve Claude OAuth system context (#28)
Preserve complete Claude OAuth system context and advance embedded package metadata to 0.5.14. Signed-off-by: Joseph Yaksich <294273268+gitcommit90@users.noreply.github.com>
1 parent 46dd339 commit e200e45

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@gitcommit90/rerouted",
33
"productName": "ReRouted",
4-
"version": "0.5.13",
4+
"version": "0.5.14",
55
"description": "A local AI router for connected accounts, models, named routes, and automatic fallback.",
66
"author": "gitcommit90",
77
"license": "MIT",

src/lib/providers/claude.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,19 @@ function generateBillingHeader(payload) {
109109
}
110110

111111
/**
112-
* Strip third-party agent structure that can trigger extra-usage or proxy
113-
* detection on OAuth traffic.
112+
* Preserve client system context while moving it into the provider-compatible
113+
* reminder location used for OAuth traffic. Truncating this text is unsafe:
114+
* callers rely on late system blocks for policy, memory, and handoff state.
114115
*/
115116
function sanitizeForwardedSystemPrompt(text) {
116-
if (!String(text || "").trim()) return "";
117-
// Keep a short neutral reminder; full client system prompts look like non-CLI agents.
117+
const forwarded = String(text || "").trim();
118+
if (!forwarded) return "";
118119
return [
119120
"Use the available tools when needed to help with software engineering tasks.",
120121
"Keep responses concise and focused on the user's request.",
121122
"Prefer acting on the user's task over describing product-specific workflows.",
122-
// Preserve a short slice of original context if useful
123-
String(text).trim().slice(0, 400),
124-
]
125-
.filter(Boolean)
126-
.join("\n");
123+
forwarded,
124+
].join("\n");
127125
}
128126

129127
/** Wrap forwarded system context in provider-compatible reminder blocks. */

tests/gateway.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,12 @@ describe("OAuth refresh against mock", () => {
745745

746746
describe("claude oauth request shaping", () => {
747747
it("applyCloaking injects CC system blocks + metadata; moves client system to user", () => {
748+
const lateSystemSentinel = `LATE_SYSTEM_HANDOFF_${"z".repeat(1600)}_END`;
748749
const base = claude.toAnthropicBody(
749750
{
750751
messages: [
751752
{ role: "system", content: "You are a custom app agent with secret tools." },
753+
{ role: "system", content: lateSystemSentinel },
752754
{ role: "user", content: "hi" },
753755
],
754756
max_tokens: 8,
@@ -774,6 +776,9 @@ describe("claude oauth request shaping", () => {
774776
? userContent.map((b) => b.text || "").join("\n")
775777
: String(userContent);
776778
assert.ok(userText.includes("<system-reminder>"), userText.slice(0, 200));
779+
assert.ok(userText.includes("You are a custom app agent with secret tools."));
780+
assert.ok(userText.includes(lateSystemSentinel), "late and long client system context must survive OAuth request shaping");
781+
assert.ok(userText.includes(`${lateSystemSentinel}\n\nIMPORTANT:`), "the complete sentinel must precede the reminder footer");
777782
const uid = JSON.parse(cloaked.metadata.user_id);
778783
assert.equal(uid.session_id, sessionId);
779784
assert.ok(uid.device_id && uid.account_uuid);

0 commit comments

Comments
 (0)