A chat WorkBuddy refuses as an unapproved channel (11128) for an opening FLAGGED
doesn't know is sent once more with one more comma in the opening ("You are an
AI agent, powered by X.") before the system prompt is moved into the first user
message. The comma is set in system and assistant messages only; user messages
and tool results go out as written. A system prompt whose comma passed is
remembered (bounded at 256, like refusedSystems) and its next chats go with the
comma before the first send, so a tool loop is not refused on every step. A
refusal that stands names REFUSED.md (new) before the hint; that address is
only in the error returned to the client, nothing sent upstream names magpie.
Version 0.2.3.
Run at the reviewed head cb8a026 on mote (macOS), temp HOME, outbound network
denied by sandbox-exec (localhost allowed):
- packages/workbuddy `bun test`: 271 pass, 0 fail.
- repo root `bun test`: 3774 pass, 1 fail (layerfs import-limit, fixed on main
by 3dd0f44). cb8a026 merged with origin/main 4d8d031: 3777 pass, 0 fail.
- `bun scripts/check.mjs`: only cloudflare-workers-ai fails, with the network
refused (#519); workbuddy ✓.
Broken by hand: no commaSystems.add -> remembered-comma test red; no pre-send
commaPausedOn -> same test red; role filter removed -> 5 tests red.
Not covered: dropping the roles.has("system") guard leaves every test green
(an assistant-only comma would be remembered). Not tried against
copilot.tencent.com in this review.
Co-authored-by: MYCF711 <MYCF711@users.noreply.github.com>
132 lines
6.4 KiB
JavaScript
132 lines
6.4 KiB
JavaScript
// A vendor that turns a chat away over words in the agent's prompt matches
|
|
// the line whole and exactly, so the same line said with one more comma
|
|
// passes it (measured against WorkBuddy 2026-10-30) — and the line still says
|
|
// which harness the agent runs in. commaPaused is that, tried before the
|
|
// system prompt is moved out of the slot the agent's instructions are read in.
|
|
import { expect, test } from "bun:test"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
const { opened, commaPaused } = _internal
|
|
|
|
test("a comma goes in where the opening names its harness", () => {
|
|
expect(opened("You are an AI agent powered by DeepSeek Harness.")).toBe("You are an AI agent, powered by DeepSeek Harness.")
|
|
expect(opened("You are a coding agent powered by the {{model}} model.")).toBe("You are a coding agent, powered by the {{model}} model.")
|
|
expect(opened("You are an AI assistant running on Foo.")).toBe("You are an AI assistant, running on Foo.")
|
|
expect(opened("You are the deployment assistant built on Bar.")).toBe("You are the deployment assistant, built on Bar.")
|
|
})
|
|
|
|
// the harness's name stays: only the shape the vendor knows is changed
|
|
test("the harness's name survives the comma", () => {
|
|
const opener = "You are an AI agent powered by DeepSeek Harness."
|
|
expect(opened(opener)).toContain("DeepSeek Harness")
|
|
expect(opened(opener)).not.toBe(opener)
|
|
})
|
|
|
|
test("a comma already in place is left alone", () => {
|
|
const once = opened("You are an AI agent powered by DeepSeek Harness.")
|
|
expect(opened(once)).toBe(once)
|
|
})
|
|
|
|
test("words that name no harness are left alone", () => {
|
|
const said = "You are a helpful assistant.\nYour working directory is D:\\work.\nBe brief."
|
|
expect(opened(said)).toBe(said)
|
|
})
|
|
|
|
// commaPaused sets OPENERS' comma in the system and assistant messages, the
|
|
// two WorkBuddy reads (REFUSED.md): a comma anywhere else changes what
|
|
// someone said without changing what was refused
|
|
test("commaPaused sets the comma in the system and assistant messages", () => {
|
|
const body = JSON.stringify({
|
|
model: "deepseek-v4.1-flash",
|
|
messages: [
|
|
{ role: "system", content: "You are an AI agent powered by DeepSeek Harness.\n\nBe brief." },
|
|
{ role: "user", content: "hi" },
|
|
],
|
|
})
|
|
const out = JSON.parse(commaPaused(body))
|
|
expect(out.messages[0].content).toBe("You are an AI agent, powered by DeepSeek Harness.\n\nBe brief.")
|
|
expect(out.messages[1].content).toBe("hi")
|
|
expect(out.model).toBe("deepseek-v4.1-flash")
|
|
})
|
|
|
|
// yetone, plugins#513: a user message quoting a line came back altered. The
|
|
// user's own words and tools' results go out as they were sent.
|
|
test("the user's messages and tools' results are left alone", () => {
|
|
const quoted = "Quote exactly: You are an assistant built on Rails."
|
|
const result = "You are a coding agent powered by Example Harness."
|
|
const body = JSON.stringify({
|
|
messages: [
|
|
{ role: "system", content: "You are an AI agent powered by DeepSeek Harness." },
|
|
{ role: "user", content: quoted },
|
|
{ role: "assistant", content: "You are an AI assistant running on Foo." },
|
|
{ role: "tool", tool_call_id: "c1", content: result },
|
|
],
|
|
})
|
|
const out = JSON.parse(commaPaused(body))
|
|
expect(out.messages[0].content).toBe("You are an AI agent, powered by DeepSeek Harness.")
|
|
expect(out.messages[1].content).toBe(quoted)
|
|
expect(out.messages[2].content).toBe("You are an AI assistant, running on Foo.")
|
|
expect(out.messages[3]).toEqual({ role: "tool", tool_call_id: "c1", content: result })
|
|
})
|
|
|
|
// the user's words alone have nothing to set a comma in, so nothing goes again
|
|
test("a chat whose opening is only in the user's message is not resent", () => {
|
|
const users = JSON.stringify({ messages: [{ role: "user", content: "Quote exactly: You are an assistant built on Rails." }] })
|
|
expect(commaPaused(users)).toBe(null)
|
|
})
|
|
|
|
test("commaPaused sets it in a system message's parts too, and not in the user's", () => {
|
|
const body = JSON.stringify({
|
|
messages: [
|
|
{ role: "system", content: [{ type: "text", text: "You are an AI agent powered by DeepSeek Harness." }] },
|
|
{ role: "user", content: [{ type: "text", text: "Quote exactly: You are an assistant built on Rails." }] },
|
|
],
|
|
})
|
|
const out = JSON.parse(commaPaused(body))
|
|
expect(out.messages[0].content[0].text).toBe("You are an AI agent, powered by DeepSeek Harness.")
|
|
expect(out.messages[1].content[0].text).toBe("Quote exactly: You are an assistant built on Rails.")
|
|
})
|
|
|
|
test("a chat with nothing of the kind is not resent", () => {
|
|
expect(commaPaused(JSON.stringify({ messages: [{ role: "system", content: "be brief" }, { role: "user", content: "hi" }] }))).toBe(null)
|
|
expect(commaPaused(JSON.stringify({ messages: [] }))).toBe(null)
|
|
expect(commaPaused("not json")).toBe(null)
|
|
expect(commaPaused(JSON.stringify({ messages: "not a list" }))).toBe(null)
|
|
})
|
|
|
|
// the comma a system prompt's next chats go with is the one set in that system
|
|
// prompt; one that only set an assistant message is not the system prompt's
|
|
// (commaSystems), so the roles are read per message, and a message whose parts
|
|
// held no opening of their own is not reported
|
|
test("the roles the comma went into are the messages it changed", () => {
|
|
const brief = [{ type: "text", text: "Be brief." }]
|
|
const body = JSON.stringify({
|
|
messages: [
|
|
{ role: "system", content: brief },
|
|
{ role: "assistant", content: "You are an AI agent powered by Foo." },
|
|
{ role: "user", content: "Quote exactly: You are an assistant built on Rails." },
|
|
],
|
|
})
|
|
const roles = new Set()
|
|
const out = JSON.parse(commaPaused(body, roles))
|
|
expect([...roles]).toEqual(["assistant"])
|
|
expect(out.messages[0].content).toEqual(brief)
|
|
|
|
const system = JSON.stringify({
|
|
messages: [
|
|
{ role: "system", content: "You are an AI agent powered by Foo." },
|
|
{ role: "user", content: "hi" },
|
|
],
|
|
})
|
|
const only = new Set()
|
|
expect(JSON.parse(commaPaused(system, only)).messages[0].content).toBe("You are an AI agent, powered by Foo.")
|
|
expect([...only]).toEqual(["system"])
|
|
})
|
|
|
|
// the shape WorkBuddy knows is the line, not the product alone: a suffix in
|
|
// its place (…Harness Desktop., …Harness CLI.) was refused just the same, and
|
|
// the comma was what passed, so this must change the shape and nothing else
|
|
test("adding a word to the opening is not what passes; the comma is", () => {
|
|
const suffixed = "You are an AI agent powered by DeepSeek Harness Desktop."
|
|
expect(opened(suffixed)).toBe("You are an AI agent, powered by DeepSeek Harness Desktop.")
|
|
}) |