agy-cli: Codex's GPT-5 lines go reworded in a user's turn too (0.1.53)
pocoxliu on X (tweet 2121731813270077946) gets 429s from agy-cli under Codex and Claude Code and put it down to unslimmed system and MCP prompts. It is content, not size (#1151: a neutral system prompt of the same 66,622 characters went through). Since 11-14 Antigravity also turns away Codex's two GPT-5 lines ("You are Codex, (a coding) agent based on GPT-5") in a user's turn; magpie's cloak and the antigravity plugin (fb7bbebd) reword them there, andfb7bbebdnoted agy-cli as not tried. agy-cli reworded only system text, so AGENTS.md text, a <system-reminder> and replayed history in a user's turn went to agy as written. - cloak.mjs: USER_TURNED_AWAY (the two Codex lines) and cloakUser(). - index.mjs: every text part of the prompt goes through cloakUser before agy gets it. Parked sessions carry userCloak: 1; one parked before this version (whose agy copy may hold the line as written) is not resumed. - READMEs (zh, en) say so. Run: HOME=$(mktemp -d) bun test packages/agy-cli on mica: 22 pass, 0 fail (cloak.test 6, agy-cli.test 16 incl. conversation-key 36 cases); bun scripts/check.mjs agy-cli: ok. Broken by hand (on mote): the userTurnParts call and the userCloak check removed, the two new conversation-key tests fail (34 pass, 2 fail); restored, all pass. Not tried: a real request. The one probe on the owner's account got "This service has been disabled in this account for violation of Terms of Service" as a 200 (#1163), so no 429 could be reproduced or cleared on a real agy. The reporter's exact agent and prompt are not known.
This commit is contained in:
@@ -246,7 +246,10 @@ plugin leaves the billing line out and rewords the others with the same
|
||||
meaning before agy sends them ("built on the Claude Agent SDK by Anthropic",
|
||||
"built on GPT-5", "RFC 2119 key words: …", "You're Hermes Agent / OpenCode /
|
||||
a coding agent running in the Codex CLI", "running within pi"), as the
|
||||
Antigravity provider does (`cloak.mjs`). Zero-width spaces no longer help:
|
||||
Antigravity provider does (`cloak.mjs`). Codex's two GPT-5 lines
|
||||
("You are Codex, a coding agent based on GPT-5", "You are Codex, an agent based on GPT-5")
|
||||
are turned away in a user's turn too (AGENTS.md, a `<system-reminder>`),
|
||||
so they go as "built on GPT-5" there as well. Zero-width spaces no longer help:
|
||||
since 11-14 Google's check reads past them. Should such a 429 still come
|
||||
back, it is reported as a 400 about the prompt, not as a quota.
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ magpie quota refresh agy-cli --json
|
||||
|
||||
Antigravity 对几行系统提示词(Claude Code 的计费行、Claude Agent SDK、Codex、Hermes Agent、OpenCode
|
||||
和 pi 的身份句、oh-my-pi 的 RFC 2119 行)不论余量多少都回 429 "Resource has been exhausted"。插件在
|
||||
agy 发出之前去掉计费那一行,其余几行换成同义的说法("built on the Claude Agent SDK by Anthropic"、"built on GPT-5"、"RFC 2119 key words: …"、"You're Hermes Agent / OpenCode / a coding agent running in the Codex CLI"、"running within pi"),和 Antigravity 提供商的做法一样(`cloak.mjs`)。零宽空格已经没用:11-14 起 Google 的检查会忽略它们。如果仍然
|
||||
agy 发出之前去掉计费那一行,其余几行换成同义的说法("built on the Claude Agent SDK by Anthropic"、"built on GPT-5"、"RFC 2119 key words: …"、"You're Hermes Agent / OpenCode / a coding agent running in the Codex CLI"、"running within pi"),和 Antigravity 提供商的做法一样(`cloak.mjs`)。Codex 的两句 GPT-5 行("You are Codex, a coding agent based on GPT-5"、"You are Codex, an agent based on GPT-5")出现在用户的轮次里(AGENTS.md、`<system-reminder>`)也会被拒,所以用户轮次里也换成 "built on GPT-5"。零宽空格已经没用:11-14 起 Google 的检查会忽略它们。如果仍然
|
||||
回了这样的 429,会报成针对提示词的 400,而不是额度用完。
|
||||
|
||||
DeepSeek Harness 的 `@` 路径说明段("Tokens prefixed with @ are paths…")也和 Antigravity 提供商一样
|
||||
|
||||
@@ -116,10 +116,23 @@ const SAID_AS = {
|
||||
"a coding assistant running inside pi": (line) => line.replace(/inside/i, "within"),
|
||||
}
|
||||
|
||||
export function cloak(system) {
|
||||
// USER_TURNED_AWAY are the lines Antigravity also turns away in a user's
|
||||
// turn: since 11-14 Codex's GPT-5 lines there got a bare 429 "Resource has
|
||||
// been exhausted" 3 of 3 on a real account, where a pasted AGENTS.md or a
|
||||
// developer message told after a reply puts them, and went through
|
||||
// reworded. The others went through as written there, 3 of 3 each, and so
|
||||
// did all of them in the model's turns and in tool results
|
||||
// (packages/antigravity's USER_TURNED_AWAY). Everything agy-cli hands agy as
|
||||
// a prompt goes to Antigravity in a user's turn, the history it replays and
|
||||
// the tool results it renders included, so cloakUser runs over all of it.
|
||||
export const USER_TURNED_AWAY = TURNED_AWAY.filter((l) => l.startsWith("you are codex, "))
|
||||
|
||||
// cloak rewords the lines of only, or of TURNED_AWAY when only is left out
|
||||
export function cloak(system, only) {
|
||||
if (typeof system !== "string" || !turnsAway(system)) return system
|
||||
const at = []
|
||||
TURNED_AWAY_RE.forEach((re, i) => {
|
||||
if (only && !only.includes(TURNED_AWAY[i])) return
|
||||
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])
|
||||
@@ -151,6 +164,10 @@ export function reword(system) {
|
||||
return system
|
||||
}
|
||||
|
||||
// cloakUser is the text of a prompt agy is handed (a user's turn upstream)
|
||||
// with USER_TURNED_AWAY's lines reworded and everything else as written
|
||||
export const cloakUser = (text) => cloak(text, USER_TURNED_AWAY)
|
||||
|
||||
// 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))
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// (#980) and its REWORDED (#1028): these fail when the two packages stop
|
||||
// agreeing.
|
||||
import { expect, test } from "bun:test"
|
||||
import { REWORDED, TURNED_AWAY, cloak, hint, outgoing, turnsAway } from "./cloak.mjs"
|
||||
import { REWORDED, TURNED_AWAY, cloak, cloakUser, hint, outgoing, turnsAway } from "./cloak.mjs"
|
||||
import { _internal as antigravity } from "../antigravity/index.mjs"
|
||||
|
||||
const ZW = ""
|
||||
@@ -94,3 +94,14 @@ test("agy-cli and antigravity send the same system text, reworded", () => {
|
||||
expect(outgoing(s)).toBe(antigravitySends(s))
|
||||
}
|
||||
})
|
||||
|
||||
// the user's text antigravity sends for s (its shape() rewords Codex's
|
||||
// GPT-5 lines in every non-model part)
|
||||
const antigravitySendsUser = (s) =>
|
||||
antigravity.shape({ contents: [{ role: "user", parts: [{ text: s }] }] }, "gemini-3-flash", "", "").contents[0].parts[0].text
|
||||
|
||||
test("a user's turn goes with Codex's GPT-5 lines reworded, as antigravity sends it", () => {
|
||||
expect(cloakUser("Read AGENTS.md:\nYou are Codex, a coding agent based on GPT-5.")).toBe("Read AGENTS.md:\nYou are Codex, a coding agent built on GPT-5.")
|
||||
expect(cloakUser("You are Hermes Agent, built by Nous Research.")).toBe("You are Hermes Agent, built by Nous Research.")
|
||||
for (const s of samples.filter(Boolean)) expect(cloakUser(s)).toBe(antigravitySendsUser(s))
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ import { startLogin } from "./login.mjs"
|
||||
import { ensureGeminiArrayItems } from "./array-items.mjs"
|
||||
import { expandToolSchema } from "./tool-schema.mjs"
|
||||
import { fitTools } from "./tool-budget.mjs"
|
||||
import { hint, outgoing, turnsAway } from "./cloak.mjs"
|
||||
import { cloakUser, hint, outgoing, turnsAway } from "./cloak.mjs"
|
||||
import { modelUsageCursor, modelUsageAfter, sessionDbPath } from "./step-usage.mjs"
|
||||
|
||||
const PROVIDER_ID = "agy-cli"
|
||||
@@ -2086,6 +2086,9 @@ class Proc {
|
||||
turn.arm()
|
||||
unpark(this.convKey)
|
||||
this.hasSentFirstTurn = true
|
||||
// agy hands Antigravity the prompt as a user's turn, where Codex's
|
||||
// GPT-5 lines are turned away too (cloak.mjs, USER_TURNED_AWAY)
|
||||
promptParts = userTurnParts(promptParts)
|
||||
const promptNumber = turn.beginPrompt(promptParts, lateCalls)
|
||||
turn.promptInFlight = true
|
||||
let result
|
||||
@@ -2563,6 +2566,13 @@ function toPromptParts(content) {
|
||||
return out
|
||||
}
|
||||
|
||||
// userTurnParts is parts with each text part as cloakUser says
|
||||
function userTurnParts(parts) {
|
||||
return parts.map((part) => part?.type === "text" && typeof part.text === "string"
|
||||
? { ...part, text: cloakUser(part.text) }
|
||||
: part)
|
||||
}
|
||||
|
||||
function mergePromptParts(first, second) {
|
||||
const a = toPromptParts(first)
|
||||
const b = toPromptParts(second)
|
||||
@@ -2749,6 +2759,7 @@ function park(proc) {
|
||||
historyHashSansInputs: digest(historyKey(stripToolUseInputs(proc.expectedMessages))),
|
||||
toolUseIdentitiesHash: digest(toolUseIdentitiesKey(proc.expectedMessages) ?? ""),
|
||||
instructionsHash: digest(sentInstructionsIdentity(proc.instructions)),
|
||||
userCloak: USER_CLOAK,
|
||||
workDir: proc.workDir,
|
||||
at: Date.now(),
|
||||
})
|
||||
@@ -2764,7 +2775,8 @@ function takeParked(convKey, opts) {
|
||||
unparked.add(convKey)
|
||||
saveParked()
|
||||
if (Date.now() - entry.at > RESUME_TTL_MS || (entry.workDir ?? null) !== (opts.workDir ?? null) ||
|
||||
entry.instructionsHash !== digest(sentInstructionsIdentity(opts.instructions))) return null
|
||||
entry.instructionsHash !== digest(sentInstructionsIdentity(opts.instructions)) ||
|
||||
entry.userCloak !== USER_CLOAK) return null
|
||||
const incoming = digest(historyKey(opts.history))
|
||||
if (entry.historyHash === incoming) return { sessionId: entry.sessionId, expectedMessages: opts.history }
|
||||
// Sans-inputs resume needs the hashes written by current park(). Old
|
||||
@@ -3377,6 +3389,12 @@ function instructionsIdentity(text) {
|
||||
// rewords keeps that line in its own copy, and every turn on it is turned
|
||||
// away, so when the rewording changes, the session is not resumed and a
|
||||
// new one is opened with the instructions as they go now (#1151).
|
||||
// USER_CLOAK marks a session parked since its prompts went as cloakUser
|
||||
// says. One parked before keeps a user's turn with Codex's GPT-5 line as
|
||||
// written in agy's own copy, and every turn on it would be turned away, so
|
||||
// it is not resumed: a new session gets the history as it goes now.
|
||||
const USER_CLOAK = 1
|
||||
|
||||
function sentInstructionsIdentity(text) {
|
||||
return compactIdentity(outgoing(stripVolatileSystem(text)))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.52",
|
||||
"version": "0.1.53",
|
||||
"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",
|
||||
|
||||
@@ -15,7 +15,7 @@ process.env.AGY_BRIDGE_STATE_FILE = path.join(workspace, "sessions.json")
|
||||
process.env.HOME = workspace
|
||||
fs.writeFileSync(
|
||||
path.join(workspace, "bridge.mjs"),
|
||||
source + "\nexport { conversationKey, stripVolatileOpening, stripVolatileSystem, isContinuedOpening, openingTextOf, sameInstructions, historyKey, takeParked, park, instructionsIdentity, digest, Turn };\n",
|
||||
source + "\nexport { conversationKey, stripVolatileOpening, stripVolatileSystem, isContinuedOpening, openingTextOf, sameInstructions, historyKey, takeParked, park, parked, instructionsIdentity, digest, Turn };\n",
|
||||
)
|
||||
const {
|
||||
conversationKey,
|
||||
@@ -27,6 +27,7 @@ const {
|
||||
historyKey,
|
||||
takeParked,
|
||||
park,
|
||||
parked,
|
||||
instructionsIdentity,
|
||||
digest,
|
||||
Turn,
|
||||
@@ -791,3 +792,49 @@ test("a turn lets go of each earlier request body once the next one arrives", ()
|
||||
assert.equal(typeof steps[2].contentSnapshot, "function")
|
||||
assert.equal(turn.responseSteps.length, 3)
|
||||
})
|
||||
|
||||
test("a session parked before a user's turn was cloaked is not resumed", () => {
|
||||
// agy keeps the user's turns it was sent; one with Codex's GPT-5 line as
|
||||
// written is turned away on every later turn.
|
||||
const convKey = "test-parked-user-cloak"
|
||||
const history = [{ role: "user", content: STABLE }, { role: "assistant", content: "ok" }]
|
||||
const proc = {
|
||||
convKey, sessionId: "sess-user-cloak", expectedMessages: history, instructions: "Rules.\n",
|
||||
workDir: "/tmp/agy-park-test", hasSentFirstTurn: true, historyInvalid: false, turn: null, dead: false,
|
||||
canPark() { return true },
|
||||
}
|
||||
park(proc)
|
||||
const file = process.env.AGY_BRIDGE_STATE_FILE
|
||||
const state = JSON.parse(fs.readFileSync(file, "utf8"))
|
||||
const saved = state.entries.find((e) => e.key === convKey)
|
||||
assert.ok(saved.userCloak, "a parked session says its prompts were cloaked")
|
||||
assert.equal(takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions: "Rules.\n", history })?.sessionId, "sess-user-cloak")
|
||||
// the same entry as an older version wrote it
|
||||
park(proc)
|
||||
delete parked.get(convKey).userCloak
|
||||
assert.equal(takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions: "Rules.\n", history }), null)
|
||||
})
|
||||
|
||||
test("a user's turn goes to agy with Codex's GPT-5 lines reworded", async () => {
|
||||
await withKit({}, async (kit) => {
|
||||
const sent = []
|
||||
kit.defaultPrompt = async (agent) => {
|
||||
sent.push(agent.prompt.map((p) => p.type === "text" ? p.text : "").join(""))
|
||||
await agent.text("ok")
|
||||
return { stopReason: "end_turn" }
|
||||
}
|
||||
const agents = "# AGENTS.md\nYou are Codex, a coding agent based on GPT-5.\nYou are Hermes Agent, built by Nous Research."
|
||||
const first = [{ role: "user", content: agents + "\n\nlist the files" }]
|
||||
const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "user-cloak" }, messages: first })))
|
||||
assert.equal(parsed.error, null)
|
||||
const second = [...first, { role: "assistant", content: "ok" },
|
||||
{ role: "user", content: "<system-reminder>\nYou are Codex, an agent based on GPT-5.\n</system-reminder>\nand now?" }]
|
||||
await readSse(await kit.request(baseBody({ metadata: { user_id: "user-cloak" }, messages: second })))
|
||||
assert.equal(sent.length, 2)
|
||||
const all = sent.join("\n")
|
||||
assert.ok(!/based on GPT-5/i.test(all), all)
|
||||
assert.ok(all.includes("You are Codex, a coding agent built on GPT-5."), all)
|
||||
assert.ok(all.includes("You are Codex, an agent built on GPT-5."), all)
|
||||
assert.ok(all.includes("You are Hermes Agent, built by Nous Research."), "other lines go as written in a user's turn")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user