diff --git a/packages/agy-cli/README.en.md b/packages/agy-cli/README.en.md index 01d4b23..157e4e3 100644 --- a/packages/agy-cli/README.en.md +++ b/packages/agy-cli/README.en.md @@ -229,6 +229,11 @@ plugin breaks each of them up with zero-width spaces before agy sends it, as the Antigravity provider does (`cloak.mjs`). Should such a 429 still come back, it is reported as a 400 about the prompt, not as a quota. +DeepSeek Harness's paragraph on `@` paths ("Tokens prefixed with @ are +paths…") goes reworded with the same meaning, as the Antigravity provider +sends it: word for word, it got most `gemini-4-argon` answers fast, without +thinking and shallow (#1028). + Set to `1`, the temporary agent carries `excludeDefaultComponents: true`. The request that goes upstream then has none of agy's own system prompt, only the plugin's one-line tool note and the client's system prompt (sent in one diff --git a/packages/agy-cli/README.md b/packages/agy-cli/README.md index 9326f39..508e233 100644 --- a/packages/agy-cli/README.md +++ b/packages/agy-cli/README.md @@ -175,6 +175,9 @@ Antigravity 对几行系统提示词(Claude Code 的计费行、Claude Agent S agy 发出之前用零宽空格把这几行拆开,和 Antigravity 提供商的做法一样(`cloak.mjs`)。如果仍然 回了这样的 429,会报成针对提示词的 400,而不是额度用完。 +DeepSeek Harness 的 `@` 路径说明段("Tokens prefixed with @ are paths…")也和 Antigravity 提供商一样 +换成同义的说法再发:原文照发时 `gemini-4-argon` 大多很快答完、不思考、只走一步(#1028)。 + 设为 `1` 后,临时 agent 带上 `excludeDefaultComponents: true`:发往上游的请求里不再有 agy 自己的系统提示词,只剩插件的一行工具说明和客户端的系统提示词(同样以上面两种方式之一 发送)。原作者实测每次模型调用的输入从约 8,400 token 降到约 500 token。代价是上游看到的 diff --git a/packages/agy-cli/cloak.mjs b/packages/agy-cli/cloak.mjs index f4bd3ee..0d73ce2 100644 --- a/packages/agy-cli/cloak.mjs +++ b/packages/agy-cli/cloak.mjs @@ -1,7 +1,8 @@ -// System prompt lines Antigravity turns away, the same list and the same -// break-up as packages/antigravity/index.mjs (TURNED_AWAY, breakUp, cloak, -// hint). Each package ships on its own, so the code is a copy; cloak.test.mjs -// fails when the two give a different answer for any line. +// System prompt lines Antigravity turns away, and paragraphs it answers +// badly, the same lists and the same rewrites as +// packages/antigravity/index.mjs (TURNED_AWAY, breakUp, cloak, hint, +// REWORDED, reword, outgoing). Each package ships on its own, so the code is +// a copy; cloak.test.mjs fails when the two give a different answer. // // Antigravity answers a 429 "Resource has been exhausted" to a request whose // system prompt has one of these lines, whatever quota is left, and lets the @@ -59,6 +60,27 @@ export function cloak(system) { return out + system.slice(prev) } +// REWORDED are paragraphs that go through but are answered badly, each with +// a rewording that keeps its meaning. DeepSeek Harness's desktop app puts +// the first in every system prompt; word for word, gemini-4-argon answered +// most requests in about 3s with no thinking and ended after one shallow +// step (antigravity #1028). +export const REWORDED = [ + [ + "Tokens prefixed with @ are paths the user explicitly referenced. Relative paths resolve from the workspace root; absolute paths identify files or directories on the host. A trailing slash marks a directory: list it when its contents matter. Anything else is a file: use the read tool when its contents are needed, and do not claim to have inspected it before reading. @\"...\" quotes a path containing spaces.", + "When the user writes @ followed by a path, they are pointing at that file or folder. Relative paths start at the workspace root; absolute paths are host paths. A path ending in a slash is a folder, so list it if its contents matter; otherwise it is a file, so open it with the read tool before relying on it. Paths with spaces appear as @\"...\".", + ], +] + +export function reword(system) { + if (typeof system !== "string") return system + for (const [from, to] of REWORDED) if (system.includes(from)) system = system.split(from).join(to) + return system +} + +// outgoing is system text as agy is handed it: broken up, then reworded +export const outgoing = (system) => reword(cloak(system)) + const HINT = "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group" diff --git a/packages/agy-cli/cloak.test.mjs b/packages/agy-cli/cloak.test.mjs index 5fbfa68..1b62ba8 100644 --- a/packages/agy-cli/cloak.test.mjs +++ b/packages/agy-cli/cloak.test.mjs @@ -1,7 +1,8 @@ // cloak.mjs is a copy of packages/antigravity's TURNED_AWAY, cloak and hint -// (#980): these fail when the two packages stop agreeing. +// (#980) and its REWORDED (#1028): these fail when the two packages stop +// agreeing. import { expect, test } from "bun:test" -import { TURNED_AWAY, cloak, hint, turnsAway } from "./cloak.mjs" +import { REWORDED, TURNED_AWAY, cloak, hint, outgoing, turnsAway } from "./cloak.mjs" import { _internal as antigravity } from "../antigravity/index.mjs" const ZW = "​" @@ -46,3 +47,28 @@ test("agy-cli and antigravity break up and explain the same lines", () => { expect(hint(s)).toBe(antigravity.hint(s)) } }) + +const DSH = "Tokens prefixed with @ are paths the user explicitly referenced. Relative paths resolve from the workspace root; absolute paths identify files or directories on the host. A trailing slash marks a directory: list it when its contents matter. Anything else is a file: use the read tool when its contents are needed, and do not claim to have inspected it before reading. @\"...\" quotes a path containing spaces." + +// the system text antigravity sends for s (its shape() runs outgoing on it) +const antigravitySends = (s) => + antigravity.shape({ systemInstruction: { parts: [{ text: s }] }, contents: [] }, "gemini-3-flash", "", "").systemInstruction.parts[0].text + +test("DeepSeek Harness's @-path paragraph goes reworded, the rest as written (#1028)", () => { + const sys = "You are DeepSeek Harness.\n\n" + DSH + "\n\nBe brief." + expect(outgoing(sys)).toBe("You are DeepSeek Harness.\n\nWhen the user writes @ followed by a path, they are pointing at that file or folder. Relative paths start at the workspace root; absolute paths are host paths. A path ending in a slash is a folder, so list it if its contents matter; otherwise it is a file, so open it with the read tool before relying on it. Paths with spaces appear as @\"...\".\n\nBe brief.") + expect(outgoing("Tokens prefixed with @ are paths. Be brief.")).toBe("Tokens prefixed with @ are paths. Be brief.") + const both = outgoing("x-anthropic-billing-header: cc\n" + DSH) + expect(both).toContain("x-a" + ZW + "n" + ZW + "thropic") + expect(both).toContain("When the user writes @ followed by a path") +}) + +test("agy-cli and antigravity send the same system text, reworded and broken up", () => { + for (const [from, to] of REWORDED) { + expect(outgoing(from)).toBe(to) + expect(antigravitySends(from)).toBe(to) + } + for (const s of [...samples.filter(Boolean), DSH, "Lead.\n" + DSH + "\n" + DSH, "x-anthropic-billing-header: cc\n" + DSH]) { + expect(outgoing(s)).toBe(antigravitySends(s)) + } +}) diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 3a95e43..212d6c5 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -12,7 +12,7 @@ import { sanitizePatternFields } from "./re2-pattern.mjs" import { startLogin } from "./login.mjs" import { ensureGeminiArrayItems } from "./array-items.mjs" import { expandToolSchema } from "./tool-schema.mjs" -import { cloak, hint, turnsAway } from "./cloak.mjs" +import { hint, outgoing, turnsAway } from "./cloak.mjs" import { modelUsageCursor, modelUsageAfter, sessionDbPath } from "./step-usage.mjs" const PROVIDER_ID = "agy-cli" @@ -1482,7 +1482,7 @@ class Proc { const resumable = !!(capabilities.sessionCapabilities?.resume ?? capabilities.session_capabilities?.resume) this.instructionsInSession = appendable && !!this.instructions const meta = this.instructionsInSession - ? { _meta: { antigravity: { systemPrompt: { append: cloak(this.instructions) } } } } + ? { _meta: { antigravity: { systemPrompt: { append: outgoing(this.instructions) } } } } : {} let session = null @@ -3866,7 +3866,7 @@ function renderTurnMessageParts(message) { if (message.role !== "user" || !Array.isArray(message.content)) { let text = renderTurnMessage(message) // a system or developer message later in the chat is system text too - if (message.role === "system" || message.role === "developer") text = cloak(text) + if (message.role === "system" || message.role === "developer") text = outgoing(text) return text === "" ? [] : [{ type: "text", text }] } const parts = [] @@ -4046,7 +4046,7 @@ function renderInitialPromptParts(body, callerWorkDir, instructionsInSession, re const head = [] if (!instructionsInSession) { const system = systemText(body) - if (system.trim()) appendPrompt(head, `\n${cloak(system)}\n\n`) + if (system.trim()) appendPrompt(head, `\n${outgoing(system)}\n\n`) if (callerWorkDir) appendPrompt(head, `\n${workDirNote(callerWorkDir)}\n\n`) } const currentParts = renderTurnMessagesParts(current) @@ -4406,11 +4406,11 @@ function inspectToolTurn(results, body) { // the gateway's wrapper for a developer message, or a system one const inner = wrapped ? wrapped[1] : rest if (extractQueuedPrompt(inner) !== null || userInterruption.test(inner)) userSteered = true - else if (!isNoise(inner)) notices.push(cloak(inner)) + else if (!isNoise(inner)) notices.push(outgoing(inner)) } else if (message.role === "user") { userSteered = true } else if (!isNoise(rest)) { - notices.push(cloak(rest)) + notices.push(outgoing(rest)) } continue } @@ -4418,7 +4418,7 @@ function inspectToolTurn(results, body) { if (extractQueuedPrompt(rest) !== null || userInterruption.test(rest)) { userSteered = true } else if (!isNoise(rest)) { - notices.push(cloak(rest)) + notices.push(outgoing(rest)) } } else if (!isNoise(rest)) { if ((hookOutput.test(rest) || claudeMetaFeedback.test(rest)) && !userInterruption.test(rest)) { @@ -4429,7 +4429,7 @@ function inspectToolTurn(results, body) { } else { // text from neither the user nor the system (an assistant message // that landed after the result): the model is told it, as a notice - notices.push(cloak(rest)) + notices.push(outgoing(rest)) } } } diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index fee9046..a37a015 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.32", + "version": "0.1.33", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/smoke.mjs b/packages/agy-cli/test/smoke.mjs index 99b6598..7741da1 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -1390,6 +1390,39 @@ for (const change of ["tools", "model"]) { check("#980 the same 429 to any other prompt is still a rate limit", quotaError?.type === "rate_limit_error", JSON.stringify(quotaError)) } +// antigravity #1028: DeepSeek Harness's @-path paragraph reaches agy +// reworded, as the antigravity plugin sends it, in the session +// instructions, in and in a later system +// message. +{ + const dsh = "Tokens prefixed with @ are paths the user explicitly referenced. Relative paths resolve from the workspace root; absolute paths identify files or directories on the host. A trailing slash marks a directory: list it when its contents matter. Anything else is a file: use the read tool when its contents are needed, and do not claim to have inspected it before reading. @\"...\" quotes a path containing spaces." + const reworded = "When the user writes @ followed by a path, they are pointing at that file or folder." + const system = `You are DeepSeek Harness.\n\n${dsh}\n\nDSH-MARKER` + await readSSE(await callFetch({ model, system, messages: [{ role: "user", content: "dsh session instructions" }] })) + const sent = inits().at(-1).systemAppend ?? "" + check("#1028 DSH's @-path paragraph goes reworded in the session instructions", + sent.includes("DSH-MARKER") && !sent.includes("Tokens prefixed with @") && sent.includes(reworded), JSON.stringify(sent)) + + process.env.FAKE_AGY_APPEND = "0" + await readSSE(await callFetch({ model, system: system + " NOAPPEND", messages: [{ role: "user", content: "dsh in the prompt" }] })) + const prompted = lastOf("user").text + check("#1028 DSH's @-path paragraph goes reworded in ", + prompted.includes("") && prompted.includes("DSH-MARKER") && !prompted.includes("Tokens prefixed with @") && prompted.includes(reworded), + JSON.stringify(prompted)) + delete process.env.FAKE_AGY_APPEND + + const later = { model, system: "DSH-LATER", messages: [{ role: "user", content: "dsh later system" }] } + const laterEvents = (await readSSE(await callFetch(later))).events + const next = nextTurn(later, laterEvents, "after the dsh note") + next.messages.splice(next.messages.length - 1, 0, { role: "system", content: dsh }) + await readSSE(await callFetch(next)) + const laterText = lastOf("user").text + check("#1028 a later system message with the paragraph goes reworded", !laterText.includes("Tokens prefixed with @") && laterText.includes(reworded), JSON.stringify(laterText)) + + await readSSE(await callFetch({ model, system: "DSH-USER", messages: [{ role: "user", content: `user wrote ${dsh}` }] })) + check("#1028 what the user wrote goes as written", lastOf("user").text.includes(dsh), JSON.stringify(lastOf("user").text)) +} + { process.env.AGY_BRIDGE_START_TIMEOUT_MS = "40" process.env.FAKE_AGY_INIT_MODE = "slow"