Files
plugins/packages/agy-cli/cloak.mjs
T
yetone 5bb4194140 antigravity 0.1.12, agy-cli 0.1.41, antigravity-cloak 0.1.7: turned-away lines go reworded (#1118)
Since 11-14 Google's check reads past invisible characters: a system
prompt with Claude Code's billing line and Agent SDK line, broken up with
two U+200B in every word as the cloak sent them, was turned away 5 of 5
with the bare 429 "Resource has been exhausted". Claude Desktop's Code
tab through magpie to Antigravity failed every turn (hc295971796 and
daoche_wuzui on X, 11-14).

Each line Google turns away now goes reworded instead, as plain words:
- the x-anthropic-billing-header line is left out (to its line's end);
  a system part or message holding only it is dropped;
- "built on Anthropic's Claude Agent SDK" -> "built on the Claude Agent
  SDK by Anthropic";
- Codex's "based on GPT-5" -> "built on GPT-5";
- Hermes' "created by Nous Research" -> "built by Nous Research";
- omp's RFC "keywords" -> "key words" (as before).
A copy an older magpie or cloak broke up (U+200B, U+2060, soft hyphen,
in or between words) is matched and reworded as the line. The Code tab's
main line ("You are Claude Code, Anthropic's official CLI for Claude,
running within the Claude Agent SDK.") passes as written and is kept.
antigravity-cloak gains a saidAs {phrase: replacement} option; extraWords
still breaks words up and the README says it no longer gets past
Google.

Run:
- real Antigravity account, sandbox HOME, gemini-3.8-flash, 10
  sequential requests each through packages/antigravity at this head:
  Code tab main prompt as Claude Desktop sends it (billing + main line +
  rest) 10/10 200; Agent SDK subagent line 10/10; an old two-U+200B
  copy 10/10; Codex GPT-5 10/10; Hermes' earlier persona 10/10; omp's
  RFC line 10/10. Each rewording alone was first tried 5/5 against the
  zero-width break, which went 0/5.
- wsl-run, HOME=$(mktemp -d) bun test (whole repo) before the last test
  fixes: 8735 pass, 19 skip, 3 fail, all three in these packages' own
  tests still expecting zero-width; after fixing them,
  bun test packages/antigravity packages/agy-cli packages/antigravity-cloak:
  133 pass, 0 fail.
Broken by hand: the three packages' source files from origin/main with
these tests: 19 fail (shape, cloak parity, smoke, every cases.json case).
Not tried: agy-cli against the real agy binary (smoke runs a fake agy);
models other than gemini-3.8-flash.
2026-11-14 11:04:28 +08:00

145 lines
8.3 KiB
JavaScript

// 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, SAID_AS, 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
// same prompt through reworded. agy-cli hands the client's system prompt to
// agy (session instructions, or <external_system_instructions> in the
// prompt), and agy sends it to Antigravity as written, so it is reworded
// here before it goes. What the bridge keys sessions on (instructionsIdentity) is the
// prompt as the client wrote it.
// TURNED_AWAY are the lines, lower-cased, Antigravity answers a 429 to
// whatever quota is left. Each goes as SAID_AS says instead.
export const TURNED_AWAY = [
"x-anthropic-billing-header:",
"built on anthropic's claude agent sdk",
"you are codex, an agent based on gpt-5",
"you are codex, a coding agent based on gpt-5",
"hermes agent, an intelligent ai assistant created by nous research",
"rfc 2119 keywords: must, required, should, recommended, may, optional.",
]
// INVISIBLE are the characters Google's check reads past: since 11-14 a
// line with a zero-width space (U+200B) after the first and second
// character of each word, or after every character, or U+2060, is turned
// away as the line itself, 5 of 5 on a real account for every line here
// (hc295971796 on X, Claude Desktop's Code tab). A copy someone broke up
// that way (the antigravity-cloak middleware before 0.1.7, an older magpie)
// is matched as the line.
const INVISIBLE = "[\\u00ad\\u180e\\u200b-\\u200f\\u2060-\\u2064\\ufeff]"
const INVISIBLE_RE = new RegExp(INVISIBLE, "g")
const escape = (c) => c.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
// lineRe matches line in any case, with any run of white space between its
// words and any invisible characters inside them: Google's check reads a
// line break, a tab, two spaces or a no-break space where the line has one
// space, and turned omp's line away wrapped after "REQUIRED," or after
// "RFC 2119" as it did on one line, while a missing period, a space dropped
// after a comma or the words in another order went through (a real
// account, 11-14). Claude Code's billing line is matched to its end, since
// it goes whole.
const lineRe = (line) => {
const words = line.split(" ").map((w) => [...w].map(escape).join(`${INVISIBLE}*`))
const tail = line === "x-anthropic-billing-header:" ? "[^\\n]*\\n?" : ""
return new RegExp(words.join(`${INVISIBLE}*\\s+${INVISIBLE}*`) + tail, "gi")
}
const TURNED_AWAY_RE = TURNED_AWAY.map(lineRe)
const has = (s, re) => {
re.lastIndex = 0
const yes = re.test(s)
re.lastIndex = 0
return yes
}
const said = (system, line) => has(system, TURNED_AWAY_RE[TURNED_AWAY.indexOf(line)])
export function turnsAway(system) {
const s = String(system ?? "")
return TURNED_AWAY_RE.some((re) => has(s, re))
}
// SAID_AS is how each line goes, with its invisible characters taken out
// and its white space as it was: a rewording that keeps its meaning, each
// answered 5 of 5 on a real account on 11-14 while the line itself, broken
// up or not, was turned away 5 of 5.
// - Claude Code's billing line is left out: it is Anthropic's, and no
// Antigravity model reads anything in it.
// - "built on Anthropic's Claude Agent SDK", the Agent SDK's identity
// line (Claude Desktop's Code tab and its subagents), goes as "built on
// the Claude Agent SDK by Anthropic".
// - Codex's GPT-5 lines go "built on GPT-5" for "based on GPT-5".
// - Hermes' earlier persona goes "built by Nous Research", as Hermes'
// current one says it, for "created by".
// - omp's RFC 2119 line goes as "key words", the RFC's own term (10 of 10
// on 11-14, eric_li8983 on X).
const SAID_AS = {
"x-anthropic-billing-header:": () => "",
"built on anthropic's claude agent sdk": (line) => line.replace(/^(built\s+on\s+)anthropic's(\s+)(claude\s+agent\s+sdk)$/i, "$1the$2$3 by Anthropic"),
"you are codex, an agent based on gpt-5": (line) => line.replace(/based(\s+)on/i, "built$1on"),
"you are codex, a coding agent based on gpt-5": (line) => line.replace(/based(\s+)on/i, "built$1on"),
"hermes agent, an intelligent ai assistant created by nous research": (line) => line.replace(/created(\s+)by/i, "built$1by"),
"rfc 2119 keywords: must, required, should, recommended, may, optional.": (line) => line.replace(/(key)(words)/i, "$1 $2"),
}
export function cloak(system) {
if (typeof system !== "string" || !turnsAway(system)) return system
const at = []
TURNED_AWAY_RE.forEach((re, i) => {
for (const m of system.matchAll(re)) at.push([m.index, m.index + m[0].length, SAID_AS[TURNED_AWAY[i]]])
})
at.sort((a, b) => a[0] - b[0])
let out = ""
let prev = 0
for (const [from, to, as] of at) {
if (from < prev) continue
out += system.slice(prev, from) + as(system.slice(from, to).replace(INVISIBLE_RE, ""))
prev = to
}
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: each turned-away line and
// each paragraph of REWORDED 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"
const CODEX_HINT =
"Antigravity answers this 429 to Codex's own system prompt for GPT-5 models whatever quota is left, so it is not a quota and waiting won't help; a Codex chat begun on a GPT model keeps that prompt after a model switch or a fork, so start a new chat on this model"
const HERMES_HINT =
"Antigravity answers this 429 to Hermes Agent's earlier default persona (its SOUL.md) whatever quota is left, so it is not a quota and waiting won't help; Hermes' current default persona goes through, so put it in SOUL.md, or use another provider for these chats"
const RFC_HINT =
"Antigravity answers this 429 to the line \"RFC 2119 keywords: MUST, REQUIRED, SHOULD, RECOMMENDED, MAY, OPTIONAL.\" that starts oh-my-pi (omp)'s system prompt, and to any prompt that has it, whatever quota is left, so it is not a quota and waiting won't help; magpie sends that line as \"RFC 2119 key words: …\", which goes through, so this one came from a copy of it that was worded another way"
export function hint(system) {
system = String(system ?? "")
if (said(system, "rfc 2119 keywords: must, required, should, recommended, may, optional.")) return RFC_HINT
if (said(system, "you are codex, an agent based on gpt-5") || said(system, "you are codex, a coding agent based on gpt-5")) return CODEX_HINT
if (said(system, "hermes agent, an intelligent ai assistant created by nous research")) return HERMES_HINT
return HINT
}