agy-cli 0.1.60: the client's system prompt goes in the first turn, not appended to agy's
bzs_1 on X (on 0.1.58): with an agent's system prompt the request is answered 429; with agy's own prompt alone it works. The bridge sent the client's system prompt as session _meta.antigravity.systemPrompt.append, which reaches Google inside the system instruction, and Antigravity turns away a growing set of identity lines there (#1151): reworded ones too ("You're an interactive agent ..."). The user-turn cloak's own record shows only Codex GPT-5 lines refused in a user turn. Now the prompt goes in the first user turn as <external_system_instructions>, through the same outgoing rewording and user cloak as the rest of that turn, and agy's system instruction stays its own. AGY_BRIDGE_SYSTEM_APPEND=1 brings the append back. A parked session records instructionsInSession, and one parked under the other route (or before this field) is not resumed, so a session never ends up with the prompt in both places or in neither. 0.1.59's 400 for a turned-away prompt (84c2a479) still applies when one gets through. Cost, in both READMEs: the prompt now shares the 112 KiB first-prompt budget, and agy's compaction can summarise it. Run at this head (rebased on84c2a479), on mica, HOME=$(mktemp -d): - packages/agy-cli smoke (AGY_BRIDGE_STORED_SIGNIN=skip): ALL OK (353 checks) - packages/agy-cli bun test: 24 pass, 0 fail - root bun test: 8753 pass, 0 fail (8773 tests, 611 files) Red on the old code: origin/main's index.mjs with the new smoke.mjs, 8 FAILURES of 351 (the prompt appended, not in the turn; the four "where client tools run" checks and the trailing-message cwd check, which now read the first turn; a session parked with appended instructions resumed). Broken by hand: park() without instructionsInSession made three conversation-key tests fail (the field must survive JSON). Also asked on X (MndiLysses): agy compacting at ~256K for 1M models. Not changed: agy 1.5.9 clamps the auto-compact threshold at 256,000 in utils.GetCheckpointConfig (min(x, 0x3E800)), so AGY_CLI_AUTO_COMPACT_OVERRIDE can't go above it, and the larger tiers are held to Gemini 4 Argon. Waits on upstream #1432 (dup of #878, #1245). Not tried: a real Antigravity request (the owner's agy account is disabled for ToS; mote, mica and xiaomi-gpu have no agy), so neither whether Google accepts the prompt in the user turn for every agent nor whether compaction keeps it.
This commit is contained in:
@@ -217,6 +217,7 @@ usage reads wait 10 minutes before the next try, doubling up to 6 hours.
|
||||
| `AGY_BRIDGE_THINKING` | on | Set to `0` to stop forwarding thought summaries |
|
||||
| `AGY_BRIDGE_EFFORT` | unset | Force a thinking level: `minimal`, `low`, `medium`, `high`, `xhigh` or `max` |
|
||||
| `AGY_BRIDGE_MINIMAL_AGENT` | off | Set to `1` to drop agy's own prompt components; see "Minimal agent" below |
|
||||
| `AGY_BRIDGE_SYSTEM_APPEND` | off | Set to `1` to append the client's system prompt to agy's own instead of putting it in the first prompt; see below |
|
||||
| `AGY_BRIDGE_IDLE_MS` | 600000 | How long a process may sit idle before it is reclaimed; the session can still resume |
|
||||
| `AGY_BRIDGE_RESUME_TTL_MS` | 21600000 | How long a reclaimed session stays resumable (6 hours) |
|
||||
| `AGY_BRIDGE_STATE_FILE` | `$XDG_STATE_HOME/magpie-agy-bridge/sessions.json` | Where resumable session records are kept |
|
||||
@@ -234,9 +235,16 @@ usage reads wait 10 minutes before the next try, doubling up to 6 hours.
|
||||
## Minimal agent (`AGY_BRIDGE_MINIMAL_AGENT=1`)
|
||||
|
||||
By default agy runs every request with its own system prompt, and the
|
||||
client's system prompt is added to it: in the session when agy advertises
|
||||
`systemPrompt.append`, otherwise as `<external_system_instructions>` at the
|
||||
start of the first prompt.
|
||||
client's system prompt goes as `<external_system_instructions>` at the start
|
||||
of the first prompt. Antigravity answers a bare 429 to a growing set of
|
||||
agents' prompts appended to agy's own (since 11-15 Claude Code's "You are an
|
||||
interactive agent that helps users with software engineering tasks.", even
|
||||
as "You're …"), while the same account answers with agy's prompt alone, so
|
||||
agy's `systemPrompt.append` is no longer used by default.
|
||||
`AGY_BRIDGE_SYSTEM_APPEND=1` goes back to it (in the session, when agy
|
||||
advertises it). The cost: the client's system prompt shares the first
|
||||
prompt's byte budget with replayed history (`AGY_BRIDGE_MAX_PROMPT_BYTES`),
|
||||
and agy's context compaction may summarise it.
|
||||
|
||||
Antigravity answers a 429 "Resource has been exhausted" to a few system
|
||||
prompt lines whatever quota is left (Claude Code's billing line, the Claude
|
||||
|
||||
@@ -160,6 +160,7 @@ magpie quota refresh agy-cli --json
|
||||
| `AGY_BRIDGE_THINKING` | 开启 | 设为 `0` 关闭思考摘要 |
|
||||
| `AGY_BRIDGE_EFFORT` | 未设置 | 强制思考等级:`minimal` / `low` / `medium` / `high` / `xhigh` / `max` |
|
||||
| `AGY_BRIDGE_MINIMAL_AGENT` | 关闭 | 设为 `1` 去掉 agy 自带的提示组件,见下文「精简 agent」 |
|
||||
| `AGY_BRIDGE_SYSTEM_APPEND` | 关闭 | 设为 `1` 把客户端的系统提示词附加到 agy 自己的系统提示词后面,而不是放进第一条提示词,见下文 |
|
||||
| `AGY_BRIDGE_IDLE_MS` | 600000 | 进程空闲多久后回收(会话仍可续接) |
|
||||
| `AGY_BRIDGE_RESUME_TTL_MS` | 21600000 | 回收后的会话可续接的时长(6 小时) |
|
||||
| `AGY_BRIDGE_STATE_FILE` | `$XDG_STATE_HOME/magpie-agy-bridge/sessions.json` | 会话状态文件路径 |
|
||||
@@ -176,9 +177,14 @@ magpie quota refresh agy-cli --json
|
||||
|
||||
## 精简 agent(`AGY_BRIDGE_MINIMAL_AGENT=1`)
|
||||
|
||||
默认情况下,agy 用它自己的系统提示词跑每个请求,客户端的系统提示词附加在后面(agy 声明
|
||||
支持 `systemPrompt.append` 时放进会话,否则作为 `<external_system_instructions>` 放在
|
||||
第一条提示词开头)。
|
||||
默认情况下,agy 用它自己的系统提示词跑每个请求,客户端的系统提示词作为
|
||||
`<external_system_instructions>` 放在第一条提示词开头。Antigravity 对附加在 agy 系统提示词
|
||||
后面的越来越多 agent 的提示词直接回 429(11-15 起包括 Claude Code 的 "You are an interactive
|
||||
agent that helps users with software engineering tasks.",改成 "You're …" 也一样),只用 agy
|
||||
自己的提示词时同一个账号能正常回答,所以默认不再用 agy 的 `systemPrompt.append`。设
|
||||
`AGY_BRIDGE_SYSTEM_APPEND=1` 恢复以前的做法(agy 声明支持时附加到会话)。代价:客户端的系统
|
||||
提示词和重放的历史共用第一条提示词的字节预算(`AGY_BRIDGE_MAX_PROMPT_BYTES`),agy 压缩上下文时
|
||||
它也可能被概括掉。
|
||||
|
||||
Antigravity 对几行系统提示词(Claude Code 的计费行、Claude Agent SDK、Codex、Hermes Agent、OpenCode
|
||||
和 pi 的身份句、oh-my-pi 的 RFC 2119 行)不论余量多少都回 429 "Resource has been exhausted"。插件在
|
||||
|
||||
@@ -142,6 +142,18 @@ const HOLD_MAX = Math.max(...AGENT_ERROR_MARKERS.map((marker) => marker.length))
|
||||
// tokens a model call, against ~500 without them), so the request goes upstream
|
||||
// with the client's system prompt in their place.
|
||||
const minimalAgent = () => process.env.AGY_BRIDGE_MINIMAL_AGENT === "1"
|
||||
// Opt-in. agy's ACP server offers to append the client's system prompt to
|
||||
// its own (session instructions), and Antigravity sends that upstream as
|
||||
// part of the system instruction, where Google's check turns away a widening
|
||||
// set of agents' identity lines with a bare 429 "Resource has been
|
||||
// exhausted" whatever quota is left: since 11-15 "You are an interactive
|
||||
// agent that helps users with software engineering tasks." even as "You're
|
||||
// …" (#1151), and with only agy's own prompt the same account answers
|
||||
// (bzs_1 on X, 11-15). The client's system prompt goes in the first user
|
||||
// turn instead, as <external_system_instructions>, where only Codex's GPT-5
|
||||
// lines were turned away (cloak.mjs, USER_TURNED_AWAY). AGY_BRIDGE_SYSTEM_APPEND=1
|
||||
// goes back to the session instructions.
|
||||
const systemAppend = () => /^(?:1|true|on|yes)$/i.test(process.env.AGY_BRIDGE_SYSTEM_APPEND || "")
|
||||
const FORWARD_THINKING = process.env.AGY_BRIDGE_THINKING !== "0"
|
||||
|
||||
// Until `agy models` answers. Gemini only: agy's ACP server decides which other
|
||||
@@ -1807,7 +1819,7 @@ class Proc {
|
||||
capabilities.prompt_capabilities?.image === true
|
||||
const appendable = capabilities._meta?.antigravity?.systemPrompt?.append === true
|
||||
const resumable = !!(capabilities.sessionCapabilities?.resume ?? capabilities.session_capabilities?.resume)
|
||||
this.instructionsInSession = appendable && !!this.instructions
|
||||
this.instructionsInSession = appendable && systemAppend() && !!this.instructions
|
||||
const meta = this.instructionsInSession
|
||||
? { _meta: { antigravity: { systemPrompt: { append: outgoing(this.instructions) } } } }
|
||||
: {}
|
||||
@@ -2829,6 +2841,7 @@ function park(proc) {
|
||||
toolUseIdentitiesHash: digest(toolUseIdentitiesKey(proc.expectedMessages) ?? ""),
|
||||
instructionsHash: digest(sentInstructionsIdentity(proc.instructions)),
|
||||
userCloak: USER_CLOAK,
|
||||
instructionsInSession: !!proc.instructionsInSession,
|
||||
workDir: proc.workDir,
|
||||
at: Date.now(),
|
||||
})
|
||||
@@ -2845,7 +2858,7 @@ function takeParked(convKey, opts) {
|
||||
saveParked()
|
||||
if (Date.now() - entry.at > RESUME_TTL_MS || (entry.workDir ?? null) !== (opts.workDir ?? null) ||
|
||||
entry.instructionsHash !== digest(sentInstructionsIdentity(opts.instructions)) ||
|
||||
entry.userCloak !== USER_CLOAK) return null
|
||||
entry.userCloak !== USER_CLOAK || entry.instructionsInSession !== (systemAppend() && !!opts.instructions)) 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
|
||||
@@ -3463,6 +3476,12 @@ function instructionsIdentity(text) {
|
||||
// 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
|
||||
// A parked entry's instructionsInSession says where its instructions went.
|
||||
// A session agy opened with them appended keeps them in its own system
|
||||
// instruction, so every turn on it is turned away as before; it is resumed
|
||||
// only while they still go there (AGY_BRIDGE_SYSTEM_APPEND=1). One parked
|
||||
// before the field was written is not resumed: a new session gets them in
|
||||
// its first turn.
|
||||
|
||||
function sentInstructionsIdentity(text) {
|
||||
return compactIdentity(outgoing(stripVolatileSystem(text)))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.59",
|
||||
"version": "0.1.60",
|
||||
"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",
|
||||
|
||||
@@ -815,6 +815,32 @@ test("a session parked before a user's turn was cloaked is not resumed", () => {
|
||||
assert.equal(takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions: "Rules.\n", history }), null)
|
||||
})
|
||||
|
||||
test("a session parked with its instructions appended to agy's is resumed only while they still go there", () => {
|
||||
// bzs_1 on X (11-15): agy keeps appended instructions in its own system
|
||||
// instruction, which Antigravity turns away, so a session opened that way
|
||||
// is not resumed once they go in the first user turn.
|
||||
const convKey = "test-parked-append"
|
||||
const history = [{ role: "user", content: STABLE }, { role: "assistant", content: "ok" }]
|
||||
const proc = {
|
||||
convKey, sessionId: "sess-append", expectedMessages: history, instructions: "Rules.\n", instructionsInSession: true,
|
||||
workDir: "/tmp/agy-park-test", hasSentFirstTurn: true, historyInvalid: false, turn: null, dead: false,
|
||||
canPark() { return true },
|
||||
}
|
||||
park(proc)
|
||||
assert.equal(takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions: "Rules.\n", history }), null)
|
||||
park(proc)
|
||||
process.env.AGY_BRIDGE_SYSTEM_APPEND = "1"
|
||||
try {
|
||||
assert.equal(takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions: "Rules.\n", history })?.sessionId, "sess-append")
|
||||
} finally {
|
||||
delete process.env.AGY_BRIDGE_SYSTEM_APPEND
|
||||
}
|
||||
// the same entry as an older version wrote it, when instructions were appended
|
||||
park({ ...proc, instructionsInSession: false })
|
||||
delete parked.get(convKey).instructionsInSession
|
||||
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 = []
|
||||
|
||||
@@ -875,11 +875,24 @@ async function launchedModel(body) {
|
||||
check("ACP session uses the isolated agent", ["tools: []", "inheritMcp: false", "inheritCustomizations: false"].every(line => init.agentConfig.includes(line)), init.agentConfig)
|
||||
check("agy keeps its own prompt components by default", !init.agentConfig.includes("excludeDefaultComponents"), init.agentConfig)
|
||||
check("ACP client names itself, not an editor", init.clientInfo?.name === "opencode-agy-cli-auth" && init.clientInfo?.version === JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version, JSON.stringify(init.clientInfo))
|
||||
check("client system prompt is appended to the session instructions", init.systemAppend?.includes("SYSTEM-PROMPT-MARKER"))
|
||||
check("fresh prompt carries only the user text", user.text === "hello world", JSON.stringify(user.text))
|
||||
// bzs_1 on X (11-15): Antigravity turns away agents' prompts appended to
|
||||
// agy's own with a bare 429, so they go in the first user turn by default.
|
||||
check("client system prompt is not appended to agy's own", init.systemAppend === null, JSON.stringify(init.systemAppend))
|
||||
check("client system prompt goes in the first user turn",
|
||||
user.text.startsWith("<external_system_instructions>\nSYSTEM-PROMPT-MARKER\n</external_system_instructions>") &&
|
||||
user.text.includes("<current_turn>\nhello world"), JSON.stringify(user.text))
|
||||
check("client tools are served through the ide-tools port", !!init.idePort && !logs().some(event => event.type === "ncExit"))
|
||||
}
|
||||
|
||||
{
|
||||
process.env.AGY_BRIDGE_SYSTEM_APPEND = "1"
|
||||
await readSSE(await callFetch({ model, system: "APPEND-OPT-IN-MARKER", messages: [{ role: "user", content: "hello append" }] }))
|
||||
delete process.env.AGY_BRIDGE_SYSTEM_APPEND
|
||||
check("AGY_BRIDGE_SYSTEM_APPEND=1 appends the client system prompt to the session instructions",
|
||||
inits().at(-1).systemAppend?.includes("APPEND-OPT-IN-MARKER"), JSON.stringify(inits().at(-1).systemAppend))
|
||||
check("an appended system prompt leaves the prompt the user text alone", lastOf("user").text === "hello append", JSON.stringify(lastOf("user").text))
|
||||
}
|
||||
|
||||
{
|
||||
const initialInits = inits().length
|
||||
const first = { model, messages: [{ role: "user", content: "first message" }] }
|
||||
@@ -955,7 +968,8 @@ for (const [name, system, headers, expectedDir, named] of [
|
||||
const final = (await readSSE(await callFetch(body, headers))).events
|
||||
const init = inits().at(-1)
|
||||
check(`${name} uses only an available absolute add-dir`, stopOf(final) === "end_turn" && init.addDir === expectedDir)
|
||||
check(`${name} identifies where client tools run`, init.systemAppend?.includes(JSON.stringify(named)) && init.systemAppend.includes("where every tool runs"))
|
||||
const told = lastOf("user").text
|
||||
check(`${name} identifies where client tools run`, told.includes(JSON.stringify(named)) && told.includes("where every tool runs"), told)
|
||||
check(`${name} keeps agent configuration isolated`, init.cwd !== expectedDir && init.cwd.includes("magpie-agy-bridge-"))
|
||||
}
|
||||
|
||||
@@ -1375,6 +1389,7 @@ for (const [title, tools, want, name] of [
|
||||
const sdkSaid = "You are a Claude agent, built on the Claude Agent SDK by Anthropic."
|
||||
const want = `${rfc.replace("keywords", "key words")}\n${sdkSaid}\nCLOAK-MARKER`
|
||||
const body = { model, system, messages: [{ role: "user", content: "cloak session instructions" }] }
|
||||
process.env.AGY_BRIDGE_SYSTEM_APPEND = "1"
|
||||
const events = (await readSSE(await callFetch(body))).events
|
||||
const init = inits().at(-1)
|
||||
const sent = init.systemAppend ?? ""
|
||||
@@ -1384,6 +1399,7 @@ for (const [title, tools, want, name] of [
|
||||
const convId = init.convId
|
||||
const before = inits().length
|
||||
await readSSE(await callFetch(nextTurn(body, events, "cloak second turn")))
|
||||
delete process.env.AGY_BRIDGE_SYSTEM_APPEND
|
||||
check("#980 the reworded instructions keep the conversation in its session", inits().length === before && lastOf("user").convId === convId,
|
||||
JSON.stringify({ inits: inits().length - before, user: lastOf("user") }))
|
||||
|
||||
@@ -1433,7 +1449,9 @@ for (const [title, tools, want, name] of [
|
||||
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`
|
||||
process.env.AGY_BRIDGE_SYSTEM_APPEND = "1"
|
||||
await readSSE(await callFetch({ model, system, messages: [{ role: "user", content: "dsh session instructions" }] }))
|
||||
delete process.env.AGY_BRIDGE_SYSTEM_APPEND
|
||||
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))
|
||||
@@ -1678,6 +1696,22 @@ for (const location of ["inline", "system", "developer", "user"]) {
|
||||
await readSSE(await again.fetch("agy://local/messages", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(edited) }))
|
||||
check("a changed history is not resumed", inits().at(-1).resumed === false)
|
||||
|
||||
// A session opened with its instructions appended keeps them in agy's own
|
||||
// system instruction, where they are turned away, so it is not resumed
|
||||
// once they go in the first user turn.
|
||||
process.env.AGY_BRIDGE_SYSTEM_APPEND = "1"
|
||||
const appended = { model, system: "APPENDED-PARKED-MARKER", messages: [{ role: "user", content: "MEMORY appended before restart" }] }
|
||||
const appendedEvents = (await readSSE(await callFetch(appended))).events
|
||||
delete process.env.AGY_BRIDGE_SYSTEM_APPEND
|
||||
const appendedInit = inits().at(-1)
|
||||
const { default: thirdDefault } = await import("../index.mjs?restart-3")
|
||||
const third = await (await thirdDefault.server({ client: null, directory: os.tmpdir() }, {})).auth.loader(async () => ({ key: "agy" }))
|
||||
await readSSE(await third.fetch("agy://local/messages", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(nextTurn(appended, appendedEvents, "MEMORY appended after restart")) }))
|
||||
const reopened = inits().at(-1)
|
||||
check("a session parked with appended instructions is not resumed", appendedInit.systemAppend?.includes("APPENDED-PARKED-MARKER") &&
|
||||
reopened.resumed === false && reopened.systemAppend === null && lastOf("user").text.includes("APPENDED-PARKED-MARKER"),
|
||||
JSON.stringify({ reopened, text: lastOf("user").text }))
|
||||
|
||||
const crashFirst = { model, messages: [{ role: "user", content: "MEMORY before mid-turn crash" }] }
|
||||
const crashFirstEvents = (await readSSE(await callFetch(crashFirst))).events
|
||||
const crashTarget = inits().at(-1)
|
||||
@@ -1707,7 +1741,7 @@ for (const location of ["inline", "system", "developer", "user"]) {
|
||||
u1.text.includes("<system-reminder>\nSessionStart hook additional context: ok") &&
|
||||
!u1.text.includes("<conversation_history>"), u1.text)
|
||||
check("caller working directory is recognized from initial trailing system message",
|
||||
init1.systemAppend?.includes('"/remote-wsl/project"'), init1.systemAppend)
|
||||
u1.text.includes('"/remote-wsl/project"'), u1.text)
|
||||
|
||||
const turn2 = {
|
||||
...turn1,
|
||||
|
||||
Reference in New Issue
Block a user