Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .claude/skills/agy-cli-fork/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ fork/fork.sh sync # 默认合并上游 main;也可以指定 ref:for
5. fetch 里 `let keptSession = false` 后面、匹配工具结果之前的入口判断。

`fork/patch-e2e.mjs` 的两个 retry 用例可以验证。容量不足改 503 的补丁上游 0.1.95 已自带,不再是我们的补丁;`patch-e2e.mjs` 里的 busy 用例留着当回归测试。
- 工具被拒后回空的修复(`Denied ending (local patch)`),挂在三个位置(0.1.161 起上游改用默认 agent,`bridgeAgentFiles` 的说明已写明 agy 自带工具关闭、带媒体时只开 read_file,原来加在 agent 说明里的那行删了):
1. `#onRequest` 的拒绝分支,在 `deniedPermissions++` 后面记下 `turn.denied`;
2. `Turn.emitText` 开头清掉 `this.denied`;
3. `#runTurn` 里 `turn.flushText()` 之后:`turn.denied` 还在、并且这期间没有新的客户端工具调用时,抛出 `AgentTurnError`。

`fork/patch-e2e.mjs` 的两个 denied 用例可以验证这几处接得对不对。
- 工具被拒后回空的修复(`Denied ending`)0.1.186 起已退役,用上游 0.1.182 的 `noteDenied()`/`TOOL_OFF_PROMPT`;合并时 `#onRequest` 拒绝分支一律用上游的。
- 并行通道(`Parallel lanes (local patch)`),挂在六个位置:
1. `acquireProcLocked` 前面的整段 helper(`LANE_TAG` 到 `heldFor`);
2. `acquireProcLocked` 开头用 `pickLane` 取 `existing` 和 `key`(原来是 `pool.get(convKey)`,`key` 原来在后面才 `let key = convKey`,那一行已删);
2. `acquireProcLocked` 开头(上游 0.1.181 的 `await checkBridge()` 之后)用 `pickLane` 取 `existing` 和 `key`(原来是 `pool.get(convKey)`,`key` 原来在后面才 `let key = convKey`,那一行已删);
3. 同一函数里,上游 `lineageVerdict` 那段之前插入的 `laneWanted` 分支,以及上游 `superseded` 事件后面的 `noteSuperseded`;`findLiveContinuedProc` 的条件多了 `key === convKey`,`why` 先取 `laneWhy`,`takeParked` 用 `key`;
4. `takeParked(key, …)` 用通道的键;0.1.163 的 `parkRebase` 要求 `proc.convKey === convKey`,通道进程上不做 rebase、按旧办法整段重放;
4b. `recoverStaleTurn` 里 `current` 按 `ctx.proc.convKey` 取,重放时带 `laneKey`;
Expand Down Expand Up @@ -102,7 +97,7 @@ fork/fork.sh release
`fork/swap-agy-cli.sh <新spec>` 在容器里以 abc 身份运行,它会:

- 备份插件配置,rm 旧来源,add 新来源。add 失败时自动把旧来源装回去。
- 检查四项:来源对不对、登录状态和换之前是否一致、四处补丁是否都在(按 Video、Retry attach、Denied ending、Parallel lanes、Thinking when disabled、Chat routing 六种标记数)、插件进程是否重启(最多等 60 秒)。
- 检查四项:来源对不对、登录状态和换之前是否一致、四处补丁是否都在(按 Video、Retry attach、Parallel lanes、Thinking when disabled、Chat routing 五种标记数)、插件进程是否重启(最多等 60 秒)。
- 任何一项不符就以非 0 退出。

```sh
Expand Down
9 changes: 3 additions & 6 deletions FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

本仓库 fork 自 [magpie-community/plugins](https://github.com/magpie-community/plugins) 的 `packages/agy-cli`,npm 包名是 `@magpie-community/opencode-agy-cli-auth`。上游的 LICENSE(MIT)和 NOTICE.md 原样保留。

和上游相比多六处改动,都在 `index.mjs` 里(“容量不足报错改为 503”上游 0.1.95 已经自带,分叉里那份已删除):
和上游相比多五处改动,都在 `index.mjs` 里(“容量不足报错改为 503”上游 0.1.95 已经自带、“工具被拒后不再回空”上游 0.1.182 已经自带,分叉里那两份已删除):

1. **视频和图片链接(OpenAI 写法)**:上游 0.1.155 起自带视频/音频输入,但只收 `video`/`audio` 块里的 base64;图片也只收 base64,链接一律 400(agy 本身不收图片链接)。补丁把 `image_url` 里的视频(`data:video/…` 或 http(s) 链接)、图片链接,以及 Magpie 从部分 `/v1/responses` 写法原样留下的 `image_url` / `input_image` 块,下载或解码后转成上游的 base64 `image`/`video` 块,之后全走上游。链接下载禁止内网地址,最大 100 MB,缓存一小时。代码里搜 `Video (local patch)`。
2. **重发的请求接上原来那一轮**:客户端等不到首字就断开,把同一份请求再发一遍,而原请求还在跑;或者原请求的回复(一次工具调用)在路上丢了。上游插件对这种重发返回错误(0.1.106 之前一律是 409 `no active MCP call matches these tool results`,0.1.106 起原请求还在出流时是 503),要等原来那一轮结束才变,而原请求照常跑完并计费,产出没人收。现在重发的请求会等原请求出结果,拿到同一份回复,用量记 0,不重复计费。原请求失败或被取消时,重发的请求收到 503,客户端再发一次就会重新跑。已经正常结束、没有待答工具调用的回复不走这条路,再发一遍仍然重新生成。带工具结果的请求、原请求已经结束时,交给上游 0.1.131 的 `replay_tool_step`(比对整份请求的摘要,回放同一个消息 id);本补丁只接原请求还在跑的重发,以及不带工具结果的请求丢了回复的重发。代码里搜 `Retry attach (local patch)`。
3. **工具被拒后不再回空**:带视频的会话开放 agy 的读文件工具以后,模型有时会拿它去读客户端机器上的路径,比如 ZCode 用户 Mac 上的 `~/.zcode/...`。这个工具在服务器上跑,读会话目录以外的路径要先申请权限,插件会拒绝;agy 被拒后就直接结束这一轮。上游插件把这样的结束原样交给客户端,结果是空正文、没有工具调用,客户端看上去就是卡住不动。现在改成两处:
- (上游 0.1.161 起自带)会话说明写明 agy 自带工具都关着,带媒体时只开 `read_file` 读附带的文件。
- 一轮在被拒的工具上结束、之后既没有正文也没有客户端工具调用时,返回 `api_error`,错误信息写明是哪个工具被拒、为什么被拒。
代码里搜 `Denied ending (local patch)`。
2. **重发的请求接上原来那一轮**:客户端等不到首字就断开,把同一份请求再发一遍,而原请求还在跑;或者原请求的回复(一次工具调用)在路上丢了。上游插件对这种重发返回错误(0.1.106 之前一律是 409 `no active MCP call matches these tool results`,0.1.106 起原请求还在出流时是 503),要等原来那一轮结束才变,而原请求照常跑完并计费,产出没人收。现在重发的请求会等原请求出结果,拿到同一份回复,用量记 0,不重复计费。原请求失败或被取消时,重发的请求收到 503,客户端再发一次就会重新跑。已经正常结束、没有待答工具调用的回复不走这条路,再发一遍仍然重新生成。带工具结果的请求、原请求已经结束时,交给上游 0.1.131 的 `replay_tool_step`(比对整份请求的摘要,回放同一个消息 id);本补丁只接原请求还在跑的重发,以及不带工具结果的请求丢了回复的重发。代码里搜 `R3. **工具被拒后不再回空**(已退役):上游 0.1.182(#1805)自带:agy 自带工具被拒后这一轮既没正文也没工具调用时,先带说明重问一次(`TOOL_OFF_PROMPT`),再空才报错。分叉原来的 `Denied ending (local patch)` 是直接报错,而且排在上游重问之前,会把上游的重问截掉,所以 0.1.186 合并时删了。编号留着,免得别处引用对不上。
nied ending (local patch)`。
4. **同一对话的并行线各用各的 agy 进程**:插件按“user_id + system + 第一条消息”认对话,一个对话只有一个 agy 进程。有的客户端在同一个会话里同时跑两条线,比如 ZCode 带着整份主对话另跑一个有工具调用的后台任务,两条线这三样都一样。上游会让后到的那条抢掉对方挂着的工具轮,或者让它等对方出完流(503 `this conversation still has an unfinished response`);被抢的一方送回工具结果时,0.1.106 之前收到 409 `no active MCP call matches these tool results`;0.1.106 起改为重放,但会反过来抢掉对方挂着的那一轮,对方正在出流时则回 503。两条线来回互抢,每抢一次都要重放整份历史。现在:
- 对方正在出流时,新来的另一条线(不带对方的工具调用)直接另开一个进程(一条“通道”),不等也不抢;
- 对方挂着工具轮、没在出流时,仍按上游的规则抢占;被抢的那一轮的工具结果回来时,不抢回对方、也不回 503,而是开一条通道用请求里的历史重放,并把这个对话记为“并行”;
Expand Down
5 changes: 5 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ then comes from what agy acp offers (plugins#1602). With no tier, the
account shows agy's refusal and no numbers. On Windows, where the plugin has
no terminal to give agy, the refusal stays.

A usage call with `printOnly` (what magpie sends for the one reading it makes
when you ask for it) runs `agy -p /usage` and nothing else: the refusal
stands, and neither agy acp nor agy's terminal UI is started for it
(plugins#1824).

While Antigravity's app has its gateway on (`gateway.enabled` in
`~/.gemini/config/config.json`, as when magpie takes over Antigravity), agy
reads the same file and goes to that gateway instead of your Google account,
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ agy 因地区拒绝 `/usage`("not currently available in your location")时
(plugins#1602)。没有档位时,账号显示 agy 的拒绝原因,不显示数字。Windows 上插件没有终端可给 agy,
仍显示拒绝。

带 `printOnly` 的额度查询(Magpie 在你手动读取时发出的那一次)只运行 `agy -p /usage`:拒绝原样显示,
不为它启动 agy acp,也不启动 agy 的终端界面(plugins#1824)。

Antigravity 应用的网关打开时(`~/.gemini/config/config.json` 里 `gateway.enabled`,例如 Magpie
接管了 Antigravity),agy 读同一个文件,会走网关而不是你的 Google 账号,`/usage` 只得到
`groups: []`。从 0.1.148 起,插件启动的每个 agy(对话和额度)都用不带网关的目录:登录在系统钥匙串里时
Expand Down
1 change: 1 addition & 0 deletions agy-cli.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ for (const [name, mocks] of [
["account-scope.mjs", false],
["stateless-reuse.mjs", false],
["tools-listed.mjs", false],
["bridge-heal.mjs", false],
["slash-commands.mjs", false],
["concurrent-convs.mjs", false],
["masking-drift.mjs", false],
Expand Down
14 changes: 9 additions & 5 deletions default-agent.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Every agy session the plugin opens runs on agy's default agent. From agy
// 1.5.17 a session of a custom agent (--agent, .agents/agents/*) costs about
// four times the quota (google-antigravity/antigravity-cli#1890), and Google's
// answer is to drop --agent and give the instructions as rules. So a session's
// folder gets, in place of an agent.md:
// Every agy session the plugin opens runs on agy's default agent. It moved
// there when agy 1.5.17 charged a custom agent's session (--agent,
// .agents/agents/*) about four times the quota
// (google-antigravity/antigravity-cli#1890). Google reverted that charge on
// 2026-11-30, but the plugin stays on the default agent: it is the session
// agy itself opens, and with Antigravity accounts being disabled for terms
// violations (#1741) the session shape isn't changed until the owner rules on
// going back (#1777). Without --agent the instructions go in as rules, so a
// session's folder gets, in place of an agent.md:
// - AGENTS.md, the instructions: agy loads it as a workspace rule, also with
// --include-default-customizations=false (agy 1.5.19, measured).
// - .agents/skills.json excludes agy's bundled skills from the prompt index.
Expand Down
47 changes: 0 additions & 47 deletions fork/patch-e2e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,53 +149,6 @@ test("the image model stays out of provider.models unless AGY_BRIDGE_IMAGE_MODEL
}, { agyPath: null, env: { AGY_BRIDGE_IMAGE_MODEL: "1" } })
})

// agy asks the client to allow its own read_file on a path outside the media
// folder (a client path), as agy 1.5.10 does; returns the bridge's answer.
async function askReadFile(kit, agent, file) {
const { child } = kit.acpSpawns[kit.acpLog.findLast((e) => e.method === "session/prompt").spawn]
const answered = new Promise((resolve) => {
const own = child.onStdin
child.onStdin = (chunk) => {
own(chunk)
for (const line of String(chunk).split("\n")) if (line.includes('"id":"perm"')) resolve(JSON.parse(line))
}
})
child.stdout.emit("data", JSON.stringify({ jsonrpc: "2.0", id: "perm", method: "session/request_permission", params: {
sessionId: agent.sessionId,
toolCall: { toolCallId: "call_rf", title: `Read ${file}`, kind: "read" },
options: [{ optionId: "allow", name: "Allow", kind: "allow_once" }, { optionId: "deny", name: "Deny", kind: "reject_once" }],
} }) + "\n")
return (await answered).result
}

test("a turn agy ends at its own denied read_file fails with the reason, not an empty reply", async () => {
await withKit(async (kit) => {
kit.defaultPrompt = async (agent) => {
const answer = await askReadFile(kit, agent, "/Users/someone/video_dl/video.mp4")
assert.equal(answer.outcome.optionId, "deny")
return { stopReason: "end_turn" }
}
const text = await (await kit.request(baseBody({ metadata: { user_id: "denied" }, messages: [{ role: "user", content: "look at /Users/someone/video_dl/video.mp4" }] }))).text()
const error = sseError(text)
assert.equal(error.type, "api_error")
assert.match(error.message, /agy's own tool \(Read \/Users\/someone\/video_dl\/video\.mp4\).*denied/)
assert.ok(!text.includes("text_delta"))
})
})

test("a denied read_file the model answers after is a normal reply", async () => {
await withKit(async (kit) => {
kit.defaultPrompt = async (agent) => {
await askReadFile(kit, agent, "/Users/someone/notes.md")
await agent.text("I can't open that here.")
return { stopReason: "end_turn" }
}
const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "denied-then-text" }, messages: [{ role: "user", content: "read /Users/someone/notes.md" }] })))
assert.equal(parsed.error, null)
assert.equal(parsed.content.filter((b) => b.type === "text").map((b) => b.text).join(""), "I can't open that here.")
})
})

// Retry attach (local patch)
const toolRound = (body, parsed, result) => ({ ...body, messages: [...body.messages,
{ role: "assistant", content: parsed.content.filter((b) => b.type === "tool_use").map((b) => ({ type: "tool_use", id: b.id, name: b.name, input: b.input })) },
Expand Down
4 changes: 2 additions & 2 deletions fork/swap-agy-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi
now=$(spec)
after=$(state)
# distinct patch markers present (one per patch, however many lines carry it)
p=$(grep -o -e "Video (local patch)" -e "Retry attach (local patch)" -e "Denied ending (local patch)" -e "Parallel lanes (local patch)" -e "Thinking when disabled (local patch)" -e "Chat routing (local patch)" \
p=$(grep -o -e "Video (local patch)" -e "Retry attach (local patch)" -e "Parallel lanes (local patch)" -e "Thinking when disabled (local patch)" -e "Chat routing (local patch)" \
"$C/plugins/node_modules/@magpie-community/opencode-agy-cli-auth/index.mjs" | sort -u | wc -l | tr -d " ")
h=""
for _ in $(seq 1 60); do
Expand All @@ -48,4 +48,4 @@ for _ in $(seq 1 60); do
done

echo "$old -> $now | $before -> $after | patches=$p | plugin host $h0 -> $h | backup $B"
[ "$now" = "$NEW" ] && [ "$after" = "$before" ] && [ "$p" = 6 ] && [ -n "$h" ] && [ "$h" != "$h0" ] || exit 7
[ "$now" = "$NEW" ] && [ "$after" = "$before" ] && [ "$p" = 5 ] && [ -n "$h" ] && [ "$h" != "$h0" ] || exit 7
Loading
Loading