diff --git a/packages/autoclaw/README.en.md b/packages/autoclaw/README.en.md index 6d7718c..d789075 100644 --- a/packages/autoclaw/README.en.md +++ b/packages/autoclaw/README.en.md @@ -124,6 +124,7 @@ A 406's upstream body is empty and magpie keeps only token counts — diagnosing - An exhausted quota is not a signed-out account: a `403` + `{"code":810000,"message":"GLM-5.3 免费额度已用完,…"}` answer (or a 403 body about quotas/balances) becomes a `429` carrying the upstream's own words, the sign-in is kept (`X-Magpie-Sign-In: kept`), and the international side stops host-hopping (plugins#274). - A banned account is not a signed-out account: a `403` + `{"code":410004,"message":"The account has been banned"}` answer (or code/message fields saying banned / 封禁 / 账号异常 / 账号被冻结) flows through on chat, refresh, credits and check-in with the upstream's own words; chat becomes a `403 permission_error`, the sign-in is kept, no host-hopping. Other 401/403s still mark the sign-in expired. - A request too large is not a signed-out account (plugins#891): the CN gateway answers a ~200k-token request `401 AutoClaw 登录状态失效` while the same token's smaller requests seconds before and after get 200. A 401/403 for a body larger than the largest this process has seen answered has its sign-in checked on the credits route: a sign-in that holds turns it into `413 request_too_large` with the sign-in kept, so magpie tries another route or has the agent compact. A sign-in refused there too, a check that fails, or a body no larger than one answered is still the sign-in. No threshold is guessed; the comparison is with the largest request answered. +- DeepSeek Harness is masked throughout system, not only in its identity line (plugins#924): the gateway refuses the name anywhere in system or developer text, so every `DeepSeek Harness` there becomes `DeepSeek`, and the identity line (with or without a comma) becomes `You are an AI agent powered by a local coding harness.` A `powered by the glm- model` sentence in any case is written in the `GLM-` form. User messages and tool arguments are never changed. - The upstream model whitelist changes with versions; a retired model returns `400 illegal model` (the error message passes through). - Refresh tokens are **mutually evicting** with the AutoClaw desktop app (both rotate) — do not stay signed in on desktop with the same account. - When the upstream changes protocols, `CLIENT_VERSION` / endpoint paths may need to follow the official client. diff --git a/packages/autoclaw/README.md b/packages/autoclaw/README.md index b8b37e5..26e47f6 100644 --- a/packages/autoclaw/README.md +++ b/packages/autoclaw/README.md @@ -124,6 +124,7 @@ AutoClaw 对话网关对请求形状有硬性要求,缺任一条都回 `406 No - 额度用完不算登录失效:上游以 `403` + `{"code":810000,"message":"GLM-5.3 免费额度已用完,…"}` 回答时(或 403 正文说额度/余额已用完),插件转成 `429`,原样带上游文案,登录保留(`X-Magpie-Sign-In: kept`),国际版也不再换 host 重试(plugins#274)。 - 账号被封不算登录失效:上游以 `403` + `{"code":410004,"message":"The account has been banned"}` 回答时(或 code/message 字段说 banned / 封禁 / 账号异常 / 账号被冻结等),对话、刷新、积分与签到都原样带上游文案,对话转成 `403 permission_error`,登录保留(`X-Magpie-Sign-In: kept`),不再换 host 重试。其他 401/403 仍按登录失效处理。 - 请求过大不算登录失效(plugins#891):国内网关会对约 200k tokens 的请求回 `401 AutoClaw 登录状态失效`,而同一凭据前后几秒的小请求都是 200。请求体比本进程见过的最大成功请求还大时遇到 401/403,插件先用积分接口确认登录:登录有效就转成 `413 request_too_large`(登录保留),magpie 换一条路由或让 agent 压缩对话;登录也被拒、确认失败,或请求不比已成功的大,仍按登录失效处理。不猜阈值,只拿已成功的最大请求作比较。 +- DeepSeek Harness 在 system 全文遮蔽,不只改身份句(plugins#924):网关只要在 system / developer 文本任意位置看到这个名字就拒绝,所以其中每处 `DeepSeek Harness` 都改成 `DeepSeek`,身份句(有无逗号均可)改成 `You are an AI agent powered by a local coding harness.`;任意大小写的 `powered by the glm- model` 句式统一写成 `GLM-` 形式。用户消息与工具参数从不改动。 - 上游模型白名单随版本变化,模型下线时上游返回 `400 非法模型`(原样透传错误消息)。 - refresh token 与 AutoClaw 桌面端**共用会互踢**(双方都轮换),插件账号请勿同时在桌面端登录。 - 上游偶发改协议时,`CLIENT_VERSION` / 端点路径可能需要随官方客户端更新。 diff --git a/packages/autoclaw/index.mjs b/packages/autoclaw/index.mjs index 350a1db..b146e33 100644 --- a/packages/autoclaw/index.mjs +++ b/packages/autoclaw/index.mjs @@ -70,7 +70,19 @@ const FLAGGED = [ // a sentence, not "assistant.." or "Anthropic's the agent framework". [/You are a Claude agent, built on Anthropic's Claude Agent SDK\.?/gi, "You are a coding assistant."], [/(?:Anthropic's |the )?Claude Agent SDK/gi, "the agent framework"], - [/You are an AI agent powered by DeepSeek Harness/gi, "You are an AI agent powered by DeepSeek-Harness"], + // DeepSeek Harness (dsh) opens "You are an AI agent powered by DeepSeek + // Harness." (dsh-system-prompt's harness:identity section), and its dev + // context names the product again further down: "The runtime context names + // the DeepSeek Harness implementation checkout.", "...through the DeepSeek + // Harness Web GUI whose URL...", "Current DeepSeek Harness implementation + // checkout: ...". The gateway 406s while the name is anywhere in system, not + // only on the first line (#924: the reporter's replay, five sends each, + // was 406 with the identity line alone rewritten and 200 x5 with every + // occurrence masked). The comma before "powered by" is optional, as the + // reporter saw it with one. The identity rule runs first so that line + // reads as a sentence; the bare name is masked everywhere after it. + [/You are an AI agent,?\s+powered by DeepSeek\s+Harness\.?/gi, "You are an AI agent powered by a local coding harness."], + [/\bDeepSeek\s+Harness\b/gi, "DeepSeek"], [/You are Claude Code/gi, "You are the Claude Code CLI"], // 11-05: subagent prompts (fork/Explore) open "You are an agent for Claude // Code, …" — ten 406 dumps that afternoon, all the same one line; the plain @@ -96,6 +108,13 @@ const FLAGGED = [ // 4.6-turbo") is not one the gateway has been seen to refuse. [/This conversation is powered by GLM-([\w-]+(?:\.[\w-]+)*)/gi, "This conversation is powered by the GLM-$1 model"], [/(powered by )the model GLM-([\w-]+(?:\.[\w-]+)*)(\s*\[[\w-]+\])?/gi, "$1the GLM-$2 model"], + // #924: "You are a coding agent powered by the glm-5.3-flash model." (a + // lowercase name, the version before "model") was reported refused; the + // form the two rules above write, "powered by the GLM-5.3-flash model", + // is the one probed to pass on 11-03. So every "powered by the glm- + // model" sentence, in any case, comes out in that one form. Only that + // sentence: a glm-5.3 in a path, a model id or code elsewhere is left. + [/(powered by )the GLM-([\w-]+(?:\.[\w-]+)*)(\s*\[[\w-]+\])?(\s+model\b)/gi, "$1the GLM-$2$4"], // WorkBuddy's CLI template still opens "You are CodeBuddy Code." (#466); // "You are CodeBuddy" alone passes. [/You are CodeBuddy Code/gi, "You are the CodeBuddy Code CLI"], diff --git a/packages/autoclaw/index.test.mjs b/packages/autoclaw/index.test.mjs index 88f36c3..1c8f1c1 100644 --- a/packages/autoclaw/index.test.mjs +++ b/packages/autoclaw/index.test.mjs @@ -233,6 +233,91 @@ test("WorkBuddy's GLM opening line and CodeBuddy Code's identity line are rewrit expect(messages[1].content).toBe("This conversation is powered by GLM-5.3") }) +// #924 (connoryang331): DeepSeek Harness names itself three times in system, +// and the gateway 406s while any one is left; the reporter's replay was 200 +// five of five once every occurrence was masked. The fixtures are dsh's own +// strings byte for byte (@deepseek-ai/dsh 0.2.1-rc.2: dsh-system-prompt's +// harness:identity section, dsh-harness-dev-context's HARNESS_SOURCE_PROMPT, +// WEB_SURFACE_PROMPT's opening and its runtime-context line), plus the +// reporter's comma form and their lowercase GLM sentence. +const DSH_IDENTITY = "You are an AI agent powered by DeepSeek Harness." +const DSH_SOURCE = "The runtime context names the DeepSeek Harness implementation checkout. The checkout location and current working directory are separate values and may differ; never infer the working directory from the checkout path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself." +const DSH_WEB = "You are interacting with the user through the DeepSeek Harness Web GUI whose URL the runtime context names. When the user refers to \"this page\", \"this GUI\", or \"this app\" without naming another target, they mean this GUI." +const DSH_RUNTIME = 'Current DeepSeek Harness implementation checkout: "/Users/me/dsh".' +const DSH_SYSTEM = [DSH_IDENTITY, "# Tools\nUse the tools to complete the task.", DSH_SOURCE, DSH_WEB, DSH_RUNTIME].join("\n\n") + +test("DeepSeek Harness is masked everywhere in system, not only its identity line", () => { + const out = unflagged(DSH_SYSTEM) + expect(out).not.toMatch(/DeepSeek\s+Harness/i) + expect(out).toBe([ + "You are an AI agent powered by a local coding harness.", + "# Tools\nUse the tools to complete the task.", + DSH_SOURCE.replace("DeepSeek Harness", "DeepSeek"), + DSH_WEB.replace("DeepSeek Harness", "DeepSeek"), + 'Current DeepSeek implementation checkout: "/Users/me/dsh".', + ].join("\n\n")) + // the reporter's identity line carries a comma + expect(unflagged("You are an AI agent, powered by DeepSeek Harness.")).toBe("You are an AI agent powered by a local coding harness.") + expect(unflagged("you are an ai agent, powered by deepseek harness")).toBe("You are an AI agent powered by a local coding harness.") + expect(unflagged(unflagged(DSH_SYSTEM))).toBe(out) + // a hyphenated name, a package or a path is not the product name + for (const t of ["@deepseek-ai/dsh-system-prompt", "deepseek-harness", "DeepSeek is a model."]) expect(unflagged(t)).toBe(t) +}) + +test("a lowercase glm powered-by sentence comes out in the GLM form the gateway takes", () => { + expect(unflagged("You are a coding agent powered by the glm-5.3-flash model.")).toBe("You are a coding agent powered by the GLM-5.3-flash model.") + expect(unflagged("Powered by the glm-4.5-air[1m] model, you help.")).toBe("Powered by the GLM-4.5-air model, you help.") + // the reporter's other sentence was already rewritten before #924 + expect(unflagged("You are powered by the model glm-5.3-flash.")).toBe("You are powered by the GLM-5.3-flash model.") + // the form written is left as it is + expect(unflagged("You are powered by the GLM-5.3-flash model.")).toBe("You are powered by the GLM-5.3-flash model.") + // only the powered-by sentence: model ids, paths and code are left + for (const t of [ + "Set model: glm-5.3-flash in config.yaml.", + "~/models/the glm-5.3-flash model/weights.bin is large", + "const m = 'glm-5.3-flash' // the glm-5.3 model", + "built by the glm-5.3-flash model.", + ]) expect(unflagged(t)).toBe(t) +}) + +test("the loader masks DeepSeek Harness in system and developer text only, on both gateways", async () => { + const realFetch = globalThis.fetch + const calls = [] + globalThis.fetch = async (input, init) => { + calls.push(JSON.parse(String(init?.body ?? "{}"))) + return new Response("{}") + } + try { + for (const Plugin of [AutoclawAuthPlugin, AutoclawCnAuthPlugin]) { + const hooks = await Plugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const toolArgs = JSON.stringify({ query: "DeepSeek Harness powered by the glm-5.3-flash model." }) + const body = JSON.stringify({ + model: "zai_glm-5.3-flash", + messages: [ + { role: "system", content: [{ type: "text", text: DSH_SYSTEM }] }, + { role: "developer", content: DSH_WEB }, + { role: "user", content: "Is DeepSeek Harness powered by the glm-5.3-flash model?" }, + { role: "assistant", content: null, tool_calls: [{ id: "c1", type: "function", function: { name: "search", arguments: toolArgs } }] }, + { role: "tool", tool_call_id: "c1", content: "DeepSeek Harness docs" }, + ], + }) + expect((await loader.fetch("x", { method: "POST", body })).status).toBe(200) + const sent = calls.at(-1) + const sys = sent.messages.find((m) => m.role === "system") + const dev = sent.messages.find((m) => m.role === "developer") + expect(JSON.stringify(sys)).not.toMatch(/DeepSeek\s+Harness/i) + expect(JSON.stringify(sys)).toContain("You are an AI agent powered by a local coding harness.") + expect(dev.content).toBe(DSH_WEB.replace("DeepSeek Harness", "DeepSeek")) + expect(sent.messages.find((m) => m.role === "user").content).toBe("Is DeepSeek Harness powered by the glm-5.3-flash model?") + expect(sent.messages.find((m) => m.role === "assistant").tool_calls[0].function.arguments).toBe(toolArgs) + expect(sent.messages.find((m) => m.role === "tool").content).toBe("DeepSeek Harness docs") + } + } finally { + globalThis.fetch = realFetch + } +}) + // Hermes Agent 0.22.1 (Discord, 01huadalang, 10-30): every chat through // AutoClaw 国内 was a 406. The fixtures are Hermes' own strings byte for // byte: DEFAULT_SOUL_MD (hermes_cli/default_soul.py, the SOUL.md every @@ -302,7 +387,10 @@ test("a system prompt carrying every known line at once comes out clean in one p ["an agent for Claude Code CLI, ask it", "an agent for Claude Code CLI, ask it"], ["You are a Claude agent, built on Anthropic's Claude Agent SDK.", "You are a coding assistant."], ["We build on the Claude Agent SDK; see docs.", "We build on the agent framework; see docs."], - ["You are an AI agent powered by DeepSeek Harness.", "You are an AI agent powered by DeepSeek-Harness."], + ["You are an AI agent powered by DeepSeek Harness.", "You are an AI agent powered by a local coding harness."], + ["You are an AI agent, powered by DeepSeek Harness.", "You are an AI agent powered by a local coding harness."], + ["The runtime context names the DeepSeek Harness implementation checkout.", "The runtime context names the DeepSeek implementation checkout."], + ["You are a coding agent powered by the glm-5.3-flash model.", "You are a coding agent powered by the GLM-5.3-flash model."], ["You are Codex, OpenAI's coding agent.", "You are the Codex agent, OpenAI's coding agent."], ["Codex CLI is the tool you run.", "Codex command-line tool is the tool you run."], ["You are opencode, an AI coding agent.", "You are the opencode agent, an AI coding agent."], diff --git a/packages/autoclaw/package.json b/packages/autoclaw/package.json index ddfd26d..96ccdca 100644 --- a/packages/autoclaw/package.json +++ b/packages/autoclaw/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-autoclaw-auth", - "version": "0.2.20", + "version": "0.2.21", "description": "OpenCode provider plugin for AutoClaw (Zhipu OpenClaw): oversea web sign-in (Google/z.ai) and CN phone SMS, multi-account pool, credit balance and daily check-in", "type": "module", "main": "./opencode.mjs",