Files
plugins/packages/agy-cli/cloak.test.mjs
T
yetone 9ec696258d agy-cli 0.1.18: turned-away system lines are broken up before agy sends them, and a 429 to one is not a quota (#980)
Antigravity answers 429 "Resource has been exhausted" to a few system
prompt lines whatever quota is left (Claude Code's billing line, the Claude
Agent SDK, Codex's and Hermes Agent's identities, oh-my-pi's RFC 2119
line). The antigravity provider breaks them up with zero-width spaces
(TURNED_AWAY / breakUp / cloak); agy-cli sent the client's system prompt
to agy as written, and called the 429 an exhausted quota
(rate_limit_error), so a client or routing group retried a prompt that
fails every time.

- cloak.mjs is a copy of antigravity's TURNED_AWAY, cloak and hint (the
  two-zero-width-space break-up of 11-11). Each package ships on its own,
  so cloak.test.mjs imports packages/antigravity's _internal and fails
  when the two give a different answer for any line or sample.
- Every route the system text reaches agy is cloaked: the session's
  systemPrompt.append (session/new and session/resume),
  <external_system_instructions> when agy can't append, a later system
  or developer message in the turn or the replayed history
  (renderTurnMessageParts), and a system/developer notice delivered
  beside a tool result (extractToolResults).
- What the bridge keys and hashes on is unchanged: proc.instructions,
  sameInstructions, instructionsIdentity, stripVolatileSystem and the
  session store keep the prompt as the client wrote it; cloak is applied
  only where the text is sent. User text is not touched.
- #formatAgentError: a "code 429 ... Resource has been exhausted" with a
  turned-away line in the session's instructions is an
  invalid_request_error, "Antigravity answered 429 to this system prompt:
  <detail> — <hint>", with the antigravity provider's hint. Any other 429
  stays rate_limit_error.
- READMEs (en, zh) say so under the minimal-agent section.

Run (wsl-run, magpie-desktop, HOME=$(mktemp -d), at f85f9ad0 + this change):
- bun test packages/agy-cli: 13 pass 0 fail (smoke ALL OK, 333 checks)
- bun scripts/check.mjs: exit 0
- root bun test: 8189 pass, 19 skip, 0 fail (580 files, 408s)
- rebased on 84ee9b88 (day-card, autoclaw, sap-aicore only): bun test packages/agy-cli
  13 pass 0 fail and bun scripts/check.mjs exit 0 again at this head

Broken by hand (each red, then restored):
- append: this.instructions uncloaked -> "#980 ... session instructions" BAD
- <external_system_instructions> uncloaked -> its #980 check BAD
- later system message uncloaked -> "#980 a later system message" BAD
- tool-result notice uncloaked -> "#980 ... system notice beside a tool
  result" BAD
- the turned-away branch of #formatAgentError off -> the 429 came back
  rate_limit_error, "#980 a 429 ... prompt rejection" BAD
- cloak.mjs back to one zero-width space after the first letter -> both
  cloak.test.mjs tests red

Not tried: against real Antigravity or a real agy (no vendor API was
reached; the fake agy in test/smoke.mjs stands in). Whether agy's own
request puts the appended instructions where Google matches them is
taken from the report and the antigravity provider, not measured here.
A turned-away line the user pastes into their own message is sent as
written, as the antigravity provider does.

Reported-by: shaohongwu
2026-11-11 17:54:13 +08:00

49 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// cloak.mjs is a copy of packages/antigravity's TURNED_AWAY, cloak and hint
// (#980): these fail when the two packages stop agreeing.
import { expect, test } from "bun:test"
import { TURNED_AWAY, cloak, hint, turnsAway } from "./cloak.mjs"
import { _internal as antigravity } from "../antigravity/index.mjs"
const ZW = "​"
const samples = [
"x-anthropic-billing-header: cc_version=2.1.0.abc; cc_entrypoint=cli; cch=1a2b3;",
"You are a Claude agent, built on Anthropic's Claude Agent SDK.",
"You are Codex, an agent based on GPT-5. You are running as a coding agent.",
"You are Codex, a coding agent based on GPT-5.",
"You are Hermes Agent, an intelligent AI assistant created by Nous Research.",
"RFC 2119 keywords: MUST, REQUIRED, SHOULD, RECOMMENDED, MAY, OPTIONAL.\n\nYou are omp.",
"Two: RFC 2119 KEYWORDS: must, required, should, recommended, may, optional. and x-anthropic-billing-header: x",
"Nothing to see here; Claude Agent SDK alone is fine.",
"",
]
test("every turned-away line is broken up, and the model still reads it", () => {
for (const s of samples) {
const out = cloak(s)
expect(out.replaceAll(ZW, "")).toBe(s)
if (turnsAway(s)) {
expect(out).not.toBe(s)
expect(turnsAway(out)).toBe(false)
} else {
expect(out).toBe(s)
}
}
expect(cloak("RFC 2119 keywords: MUST, REQUIRED, SHOULD, RECOMMENDED, MAY, OPTIONAL.")).toBe(
`R${ZW}F${ZW}C 2${ZW}1${ZW}19 k${ZW}e${ZW}ywords: M${ZW}U${ZW}ST, R${ZW}E${ZW}QUIRED, S${ZW}H${ZW}OULD, R${ZW}E${ZW}COMMENDED, M${ZW}A${ZW}Y, O${ZW}P${ZW}TIONAL.`,
)
})
test("agy-cli and antigravity break up and explain the same lines", () => {
for (const line of TURNED_AWAY) {
expect(antigravity.turnsAway(line)).toBe(true)
expect(cloak(line)).toBe(antigravity.cloak(line))
expect(hint(line)).toBe(antigravity.hint(line))
}
for (const s of samples) {
expect(turnsAway(s)).toBe(antigravity.turnsAway(s))
expect(cloak(s)).toBe(antigravity.cloak(s))
expect(hint(s)).toBe(antigravity.hint(s))
}
})