workbuddy 0.1.9: Codex and Claude Code chats pass WorkBuddy's channel check (magpie #182)

WorkBuddy answers "Illegal API invocation from an unapproved channel" to a
few exact phrases anywhere in a chat, case-insensitively: Claude Code's
billing header and identity line, its gitStatus "Main branch (you will
usually use this for PRs)", and Codex 0.159.2's first paragraph as a whole.
The plugin rewrites each to words that say the same and pass (each tried
against both builds), drops the billing header, and leaves every other
message as it was. Tested with real accounts through Cindy's bundled Codex
0.159.2 and Claude Code 2.1.280: workbuddy/glm-5.3-flash and
workbuddy-ai/deepseek-v4.1-flash answer from both; before, Codex got the
refusal. unflag.test.mjs fails 3 of 4 without the change.
This commit is contained in:
yetone
2026-10-06 03:09:56 +08:00
parent 17f46b7a15
commit 697803308a
3 changed files with 117 additions and 8 deletions
+65 -7
View File
@@ -257,17 +257,75 @@ function sign(site, a, headers) {
headers.set("X-Request-ID", msg)
}
// FLAGGED are the words WorkBuddy refuses a chat for, "Illegal API
// invocation from an unapproved channel" (magpie #182), each with words
// that say the same and pass: tried one by one against both builds with
// the requests Claude Code 2.1.280 and Codex 0.159.2 send. WorkBuddy reads
// every message, not only the system prompt (Claude Code puts its main
// branch in the first user message), and pays no mind to case. Claude
// Code's billing header means nothing to WorkBuddy's models and goes.
const FLAGGED = [
[/x-anthropic-billing-header:[^\n]*\n?/gi, ""],
[/You are Claude Code, Anthropic['’]s official CLI for Claude/gi, "You are Claude Code, Anthropic's CLI for Claude"],
[/Main branch \(you will usually use this for PRs\)/gi, "Main branch (usually the base for PRs)"],
[/(?<!the )Codex CLI is an open source project led by OpenAI\./gi, "The Codex CLI is an open source project led by OpenAI."],
]
function unflagged(text) {
for (const [re, to] of FLAGGED) text = text.replace(re, to)
return text
}
// unflag puts FLAGGED's words in place in every message of a chat, and
// leaves out a text that had nothing else (the billing header's system
// block). It says whether it changed anything.
function unflag(messages) {
let changed = false
for (let i = messages.length - 1; i >= 0; i--) {
const m = messages[i]
if (typeof m?.content === "string") {
const t = unflagged(m.content)
if (t === m.content) continue
changed = true
if (t.trim() || m.role !== "system") m.content = t
else messages.splice(i, 1)
} else if (Array.isArray(m?.content)) {
const parts = []
let here = false
for (const p of m.content) {
const t = typeof p?.text === "string" ? unflagged(p.text) : null
if (t === null || t === p.text) {
parts.push(p)
continue
}
here = true
if (t.trim()) parts.push({ ...p, text: t })
}
if (!here) continue
changed = true
if (parts.length || m.role !== "system") m.content = parts
else messages.splice(i, 1)
}
}
return changed
}
// withSystem gives a chat that doesn't open with a system message
// WorkBuddy's default one, as its app does.
// WorkBuddy's default one, as its app does, and takes FLAGGED's words out
// of it.
function withSystem(body) {
// a body magpie or OpenCode hands over as bytes is read as the text it is
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) body = new TextDecoder().decode(body)
if (typeof body !== "string") return body
try {
const b = JSON.parse(body)
if (!Array.isArray(b?.messages) || !b.messages.length || b.messages[0]?.role === "system") return body
b.messages.unshift({ role: "system", content: "You are a helpful assistant." })
return JSON.stringify(b)
if (!Array.isArray(b?.messages) || !b.messages.length) return body
let changed = unflag(b.messages)
if (b.messages[0]?.role !== "system") {
b.messages.unshift({ role: "system", content: "You are a helpful assistant." })
changed = true
}
return changed ? JSON.stringify(b) : body
} catch {
return body
}
@@ -696,8 +754,8 @@ function makePlugin(site) {
// REFUSED_HINT is what the user can do about WorkBuddy's "Illegal API
// invocation from an unapproved channel": both builds answer it to a chat
// whose system prompt is Codex's or Claude Code's own (magpie #182),
// whatever the headers. It ends the error's message, as magpie's built-in
// holding words of Codex's or Claude Code's own (magpie #182), whatever the
// headers. FLAGGED rewrites the ones known; this is for one it doesn't know. It ends the error's message, as magpie's built-in
// put it (provider.WBRefusedHint), so magpie's routing page says it apart.
const REFUSED_HINT =
"WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group"
@@ -746,4 +804,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
// for tests
export const _internal = { withSystem, usageOf, desktopHeld, explained, REFUSED_HINT, freeCredits, creditsOf, fresh, SITES, renewing, renewed }
export const _internal = { withSystem, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, freeCredits, creditsOf, fresh, SITES, renewing, renewed }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.1.8",
"version": "0.1.9",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./index.mjs",
+51
View File
@@ -0,0 +1,51 @@
// WorkBuddy refuses a chat holding words of Codex's or Claude Code's own
// prompts (magpie #182); withSystem puts words that pass in their place,
// in every message, as tried against both builds.
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { withSystem, unflagged } = _internal
test("each flagged phrase is put in other words, whatever its case", () => {
expect(unflagged("You are Claude Code, Anthropic's official CLI for Claude.")).toBe("You are Claude Code, Anthropic's CLI for Claude.")
expect(unflagged("Main branch (you will usually use this for PRs): main")).toBe("Main branch (usually the base for PRs): main")
expect(unflagged("MAIN BRANCH (YOU WILL USUALLY USE THIS FOR PRS): main")).toBe("Main branch (usually the base for PRs): main")
const codex = "You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful."
expect(unflagged(codex)).toBe(codex.replace("Codex CLI is an open", "The Codex CLI is an open"))
expect(unflagged(unflagged(codex))).toBe(unflagged(codex))
expect(unflagged("x-anthropic-billing-header: cc_version=2.1.280.31f; cc_entrypoint=sdk-cli;\nhello")).toBe("hello")
expect(unflagged("nothing to see")).toBe("nothing to see")
})
test("Claude Code's request through magpie passes: header block gone, the rest rewritten", () => {
const body = JSON.stringify({
model: "glm-5.3",
messages: [
{ role: "system", content: [
{ type: "text", text: "x-anthropic-billing-header: cc_version=2.1.280.31f; cc_entrypoint=cli;" },
{ type: "text", text: "You are Claude Code, Anthropic's official CLI for Claude." },
] },
{ role: "user", content: [{ type: "text", text: "gitStatus\nMain branch (you will usually use this for PRs): main" }, { type: "image_url", image_url: { url: "data:," } }] },
],
})
const b = JSON.parse(withSystem(body))
expect(b.messages[0]).toEqual({ role: "system", content: [{ type: "text", text: "You are Claude Code, Anthropic's CLI for Claude." }] })
expect(b.messages[1].content[0].text).toBe("gitStatus\nMain branch (usually the base for PRs): main")
expect(b.messages[1].content[1]).toEqual({ type: "image_url", image_url: { url: "data:," } })
})
test("a system message of the header alone goes, and WorkBuddy's default takes its place", () => {
const body = JSON.stringify({ messages: [
{ role: "system", content: "x-anthropic-billing-header: cc_version=2.1.280; cc_entrypoint=cli;" },
{ role: "user", content: "hi" },
] })
expect(JSON.parse(withSystem(body)).messages).toEqual([
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "hi" },
])
})
test("a chat with nothing flagged is sent as it came", () => {
const body = JSON.stringify({ messages: [{ role: "system", content: "be brief" }, { role: "user", content: "hi" }] })
expect(withSystem(body)).toBe(body)
})