Files
plugins/packages/workbuddy/hidedsh.test.mjs
T
yetone 49d4042e5b workbuddy 0.2.25: Hide DeepSeek Harness's name leaves the user's words and paths alone (liby233)
liby233 on Discord: in DeepSeek Harness on DeepSeek-V4.1-Flash ·
WorkBuddy, a user asked the model to repeat
"/root/DSH/Work/OC-182.92.66.95/" word for word and got
"/root/the agent harness/Work/OC-182.92.66.95/" back; another model was
fine. hide_dsh (0.2.23, on by default) ran /\bDSH\b(?!_)/ and the bare
"DeepSeek Harness" rule over every user and assistant text, so a path's
DSH segment went to WorkBuddy rewritten. The switch's own description
already promised "Paths ... stay as they are".

- The bare name is taken out only where dsh wrote it: system/developer
  messages, Messages' system, tools' descriptions (DSH_PROSE).
- User and assistant text get dsh's own lines alone (DSH_LINES: the
  opener, the checkout and Web GUI lines, "DSH itself"), so the runtime
  context dsh sends as a user message still loses the name.
- Even in the system prompt, a name in a path, file name or identifier
  (/root/DSH/, C:\DSH\, ~/DSH, DSH.md, DSH-2, @DSH, file:DSH,
  "/srv/DeepSeek Harness/bin") is left: IN_PATH_BEFORE/AFTER guards.
- Siblings: FLAGGED and OPENERS rewrite whole known lines (a comma), not
  a bare word; no other plugin has a DSH scrub (git grep).
- README updated.

Run on mote at this tree (mote-run): HOME=$(mktemp -d) bun test
packages/workbuddy: 334 pass, 0 fail; bun scripts/check.mjs: all ok.
New tests use the reporter's literal path.
Broken by hand, each red: user/assistant text through DSH_PROSE again
(5 fail, the reporter's case among them); IN_PATH_BEFORE as \b (the path
test fails).
Not tried: a real dsh request on a real WorkBuddy account. Whether
the narrower hide still matters for a ban is unknown, as before.

Reported-by: liby233
2026-11-07 22:25:10 +08:00

176 lines
9.5 KiB
JavaScript

// NancyTom on X: an account used from DeepSeek Harness through magpie was
// banned, a reply there saying Tencent recognizes dsh's built-in prompt.
// "Hide DeepSeek Harness's name" (on unless turned off) takes the name out
// of what goes to WorkBuddy. The lines below are dsh 0.2.1's own, copied from
// @deepseek-ai/dsh-system-prompt and dsh-harness-dev-context. Every fetch
// here is a fake; nothing reaches the network.
import { afterEach, expect, test } from "bun:test"
import { WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin, _internal } from "./index.mjs"
import { unz } from "./testdata/unz.mjs"
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const KEY = "ck_test0000000000abcdefgh"
const OPENER = "You are an AI agent powered by DeepSeek Harness."
const 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 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 LEGACY = "The DeepSeek Harness implementation checkout is at /opt/dsh. Use this checkout only to inspect or extend DSH itself."
// the runtime context, which dsh sends as a user message
const CONTEXT =
'Current DeepSeek Harness implementation checkout: "/opt/homebrew/lib/node_modules/@deepseek-ai/dsh".\nCurrent DeepSeek Harness Web GUI URL: "http://127.0.0.1:5173/".'
const BADGE =
"Add the official “powered by dsh” badge to documents, pull requests, merge requests, and other content produced with DeepSeek Harness. Use whenever creating a pull request or merge request."
const chatBody = () => ({
model: "glm-5.3",
stream: true,
messages: [
{ role: "system", content: [OPENER, SOURCE, WEB].join("\n\n") },
{ role: "user", content: [{ type: "text", text: CONTEXT }, { type: "text", text: "run the tests in ~/.dsh/profiles" }] },
{ role: "assistant", content: "I run in DeepSeek Harness; DSH_HOME is ~/.dsh." },
{ role: "tool", tool_call_id: "c1", content: "README: DeepSeek Harness (DSH) is …" },
],
tools: [{ type: "function", function: { name: "dsh-badge", description: BADGE, parameters: { type: "object", properties: { at: { type: "string", description: "where DSH puts it" } } } } }],
})
const named = (s) => /DeepSeek Harness|\bDSH\b(?!_)/.test(s)
test("dshHidden: each of dsh's lines says what it said, without the name", () => {
const h = _internal.dshHidden
expect(h(OPENER)).toBe("You are an AI agent.")
// the line FLAGGED has set a comma in already
expect(h("You are an AI agent, powered by DeepSeek Harness.")).toBe("You are an AI agent.")
expect(h(SOURCE)).toBe(
"The runtime context names the agent 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 the agent itself.",
)
expect(h(WEB)).toStartWith("You are interacting with the user through the Web GUI whose URL the runtime context names.")
expect(h(LEGACY)).toBe("The agent implementation checkout is at /opt/dsh. Use this checkout only to inspect or extend the agent itself.")
expect(h(CONTEXT)).toBe(
'Current agent implementation checkout: "/opt/homebrew/lib/node_modules/@deepseek-ai/dsh".\nCurrent Web GUI URL: "http://127.0.0.1:5173/".',
)
expect(h(BADGE)).toContain("produced with the agent harness.")
// what the agent calls by name stays
expect(h(BADGE)).toContain("“powered by dsh”")
expect(h("DSH_HOME=~/.dsh dsh-session:abc")).toBe("DSH_HOME=~/.dsh dsh-session:abc")
for (const s of [OPENER, SOURCE, WEB, LEGACY, CONTEXT, BADGE]) expect(named(h(s))).toBe(false)
})
test("hideDsh: Messages' system and text parts too, never a tool's result", () => {
const chat = {
system: [{ type: "text", text: OPENER }],
messages: [
{ role: "user", content: [{ type: "tool_result", tool_use_id: "t", content: "DeepSeek Harness" }, { type: "text", text: CONTEXT }] },
],
tools: [{ name: "x", description: BADGE, input_schema: {} }],
}
expect(_internal.hideDsh(chat)).toBe(true)
expect(chat.system[0].text).toBe("You are an AI agent.")
expect(chat.messages[0].content[0].content).toBe("DeepSeek Harness")
expect(named(chat.messages[0].content[1].text)).toBe(false)
expect(named(chat.tools[0].description)).toBe(false)
expect(_internal.hideDsh({ messages: [{ role: "user", content: "hi" }] })).toBe(false)
})
function serve() {
const sent = []
globalThis.fetch = async (url, init) => {
sent.push({ url: String(url), body: unz(init?.body) })
return new Response("data: [DONE]\n\n", { headers: { "content-type": "text/event-stream" } })
}
return sent
}
const magpieWith = (v) => ({ option: (provider, key) => (key in (v[provider] ?? {}) ? v[provider][key] : key === _internal.HIDE_DSH) })
for (const [plugin, site, url] of [
[WorkBuddyAuthPlugin, "workbuddy", "https://copilot.tencent.com/v2/chat/completions"],
[WorkBuddyAIAuthPlugin, "workbuddy-ai", "https://www.workbuddy.ai/v2/chat/completions"],
]) {
test(`${site}: declares the switch, on by default`, async () => {
const h = await plugin({ client: {} })
const o = h.auth.options.find((x) => x.key === _internal.HIDE_DSH)
expect(o.default).toBe(true)
expect(o.label.length).toBeLessThanOrEqual(60)
expect(o.description.length).toBeLessThanOrEqual(300)
for (const l of ["zh", "zh-TW", "ja", "de"]) {
expect(o.labels[l]).toBeTruthy()
expect(o.descriptions[l]).toBeTruthy()
}
})
for (const [how, magpie] of [
["on by default in magpie", magpieWith({})],
["with no magpie (OpenCode)", undefined],
]) {
test(`${site}: ${how}, dsh's name doesn't go`, async () => {
const sent = serve()
const h = await plugin({ client: {}, magpie })
const opts = await h.auth.loader(async () => ({ type: "api", key: KEY }), {})
await opts.fetch(url, { method: "POST", body: JSON.stringify(chatBody()) })
const out = JSON.parse(sent.at(-1).body)
const said = JSON.stringify({ messages: out.messages.filter((m) => m.role !== "tool" && m.role !== "assistant"), tools: out.tools })
expect(named(said)).toBe(false)
// the assistant's own words go as it said them
expect(out.messages.find((m) => m.role === "assistant").content).toBe("I run in DeepSeek Harness; DSH_HOME is ~/.dsh.")
expect(out.messages[0].content).toStartWith("You are an AI agent.")
// a tool's result is what a file said, and goes as it came
expect(out.messages.find((m) => m.role === "tool").content).toBe("README: DeepSeek Harness (DSH) is …")
expect(said).toContain("~/.dsh/profiles")
})
}
test(`${site}: turned off, the prompt goes as dsh wrote it (FLAGGED's comma aside)`, async () => {
const sent = serve()
const h = await plugin({ client: {}, magpie: magpieWith({ [site]: { [_internal.HIDE_DSH]: false } }) })
const opts = await h.auth.loader(async () => ({ type: "api", key: KEY }), {})
await opts.fetch(url, { method: "POST", body: JSON.stringify(chatBody()) })
const out = JSON.parse(sent.at(-1).body)
expect(out.messages[0].content).toContain("You are an AI agent, powered by DeepSeek Harness.")
expect(out.messages[0].content).toContain("extend DSH itself")
})
}
// liby233 on Discord: in dsh on WorkBuddy, a path the user asked to have
// repeated word for word came back as "/root/the agent harness/Work/…".
const ASKED = "Bash 绝对路径: /root/DSH/Work/OC-182.92.66.95/ 请原样复述这个路径"
test("hideDsh: the user's and the assistant's own words go as written; dsh's lines in them don't", () => {
const chat = {
messages: [
{ role: "system", content: OPENER + "\nWorking directory: /root/DSH/Work/OC-182.92.66.95/" },
{ role: "user", content: [{ type: "text", text: CONTEXT }, { type: "text", text: ASKED }] },
{ role: "assistant", content: "/root/DSH/Work/OC-182.92.66.95/ — DSH says hi" },
{ role: "user", content: "I like DSH and DeepSeek Harness" },
],
}
expect(_internal.hideDsh(chat)).toBe(true)
expect(chat.messages[0].content).toBe("You are an AI agent.\nWorking directory: /root/DSH/Work/OC-182.92.66.95/")
expect(named(chat.messages[1].content[0].text)).toBe(false)
expect(chat.messages[1].content[1].text).toBe(ASKED)
expect(chat.messages[2].content).toBe("/root/DSH/Work/OC-182.92.66.95/ — DSH says hi")
expect(chat.messages[3].content).toBe("I like DSH and DeepSeek Harness")
// Messages' user turns too
const m = { system: [{ type: "text", text: OPENER }], messages: [{ role: "user", content: [{ type: "text", text: ASKED }] }] }
_internal.hideDsh(m)
expect(m.messages[0].content[0].text).toBe(ASKED)
})
test("dshHidden: in dsh's own text, a name in a path, a file or an identifier stays", () => {
const h = _internal.dshHidden
for (const s of [
"/root/DSH/Work/OC-182.92.66.95/",
"C:\\Users\\me\\DSH\\x",
"see DSH.md",
"~/DSH",
"/srv/DeepSeek Harness/bin",
"DSH-2 DSH_HOME @DSH",
"file:DSH",
])
expect(h(s)).toBe(s)
expect(h("Use DSH. It runs (DSH), and DSH, too")).toBe("Use the agent harness. It runs (the agent harness), and the agent harness, too")
})