@magpie-community/opencode-agy-tui-auth 0.0.0-stage → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DylanLIiii
4
+ Copyright (c) 2026 gitxm
5
+ Copyright (c) 2026 yce
6
+ Copyright (c) 2026 magpie-community
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,31 @@
1
+ # agy-tui
2
+
3
+ Antigravity's models through agy's own interactive mode (its TUI). Each request starts the real `agy` in a terminal magpie gives it (`magpie tui-helper`), pastes the conversation into its prompt as a person would, and reads the answer from the transcript agy writes. The plugin calls none of Google's endpoints: agy does, as it does for anyone typing at its prompt.
4
+
5
+ **[中文 → README.md](README.md)**
6
+
7
+ ## Use
8
+
9
+ 1. Install the [Antigravity CLI](https://antigravity.google/docs/cli) (`agy`), version 1.5.19 or newer. An older agy is refused with "Update agy".
10
+ 2. Install this plugin from magpie's Plugins page, add **Antigravity (agy TUI)** under Providers and pick "Sign in with Google": magpie opens agy's sign-in link, and you paste back the code the page shows.
11
+ 3. The models are the ones `agy models` lists.
12
+
13
+ Each account has a home of its own (`~/.local/state/magpie-agy-tui/accounts/<id>`), where agy keeps its sign-in as a file. Your own `~/.gemini`, skills and MCP servers are neither used nor changed.
14
+
15
+ agy runs on its default agent, never a custom one (`--agent`), which agy 1.5.17 and newer bill at about four times the quota. The turn's folder holds an `AGENTS.md` telling the model to answer in text, an `.agents/skills.json` that leaves agy's bundled skills out, and a PreToolUse hook (`.agents/hooks.json`) that turns down every tool call.
16
+
17
+ ## Limits (v0.1)
18
+
19
+ - Text, images and videos: the caller's tools are not offered to the model, and a tool result is refused (400).
20
+ - Images (PNG, JPEG, GIF, WebP, BMP, TIFF, SVG; up to 10 MB each) and videos (MP4, MOV, WebM, AVI; up to 50 MB each), sent inline as a data: URL, go to agy as attachments, the way a file dragged into its prompt does: what agy 1.5.19's prompt attaches, at its own size limits. Images work with Gemini and Claude models, videos with Gemini models. Each file is written to the turn's folder and deleted with it.
21
+ - Anything else agy's prompt doesn't attach, so it is refused (400) with what it was, never dropped: a PDF, audio, a text or code file, a HEIC, a link to a file instead of the file itself, and a video for a Claude model.
22
+ - Each request is a new agy conversation; the conversation before it is pasted with it as text.
23
+ - The answer comes whole when the turn ends (a streamed request gets keep-alives first, then the answer).
24
+ - It needs magpie v0.1.5027 or newer (with `tui-helper`). Not yet tried on Windows.
25
+
26
+ ## Options (environment)
27
+
28
+ - `AGY_PATH`: where agy is.
29
+ - `AGY_TUI_TURN_TIMEOUT_MS`: the longest a turn may take, 15 minutes by default.
30
+ - `AGY_TUI_ATTACH_TIMEOUT_MS`: how long agy may take to attach a turn's images and videos, 15 seconds by default.
31
+ - `AGY_TUI_KEEP=1`: keep each turn's folder (its images and videos too) and agy's conversation, to look into a problem.
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # agy-tui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 用 agy 自己的交互界面(TUI)跑 Antigravity 的模型。每个请求都会在 magpie 提供的终端里(`magpie tui-helper`)启动真正的 `agy`,像人一样把对话粘贴进它的输入框,再从 agy 自己写的对话记录里读出回答。插件本身不调用 Google 的任何接口,全部由 agy 完成,和人在 agy 的提示符前打字一样。
4
+
5
+ **[English → README.en.md](README.en.md)**
6
+
7
+ ## 用法
8
+
9
+ 1. 安装 [Antigravity CLI](https://antigravity.google/docs/cli)(`agy`),需要 1.5.19 或更新;更旧的 agy 会被拒绝,并提示「Update agy」。
10
+ 2. 在 magpie 的插件页安装本插件,然后在 Providers 里添加 **Antigravity (agy TUI)**,选「使用 Google 登录」:magpie 打开 agy 的登录链接,把页面上显示的代码粘贴回来即可。
11
+ 3. 模型列表来自 `agy models`。
12
+
13
+ 每个账号都有自己的 home(`~/.local/state/magpie-agy-tui/accounts/<id>`),agy 的登录信息以文件形式存在那里。你自己的 `~/.gemini`、skills 和 MCP 服务器都不会被用到,也不会被改动。
14
+
15
+ agy 运行的是它的默认 agent,不用自定义 agent(`--agent`):agy 1.5.17 起,自定义 agent 的会话大约按 4 倍额度计费。每轮的临时目录里放一个 `AGENTS.md`(让模型只用文字回答)、一个 `.agents/skills.json`(不加载 agy 自带的 skills),以及一个 PreToolUse hook(`.agents/hooks.json`),拒绝所有工具调用。
16
+
17
+ ## 限制(v0.1)
18
+
19
+ - 文本、图片和视频:调用方的工具不会交给模型,工具结果会被拒绝(400)。
20
+ - 图片(PNG、JPEG、GIF、WebP、BMP、TIFF、SVG,每张不超过 10 MB)和视频(MP4、MOV、WebM、AVI,每个不超过 50 MB)以 data: URL 内联发送,会像拖进 agy 输入框的文件一样作为附件交给 agy:正是 agy 1.5.19 输入框能附加的类型,大小限制也和 agy 自己的一样。图片适用于 Gemini 和 Claude 模型,视频只适用于 Gemini 模型。每个文件写进本轮的临时目录,随目录一起删除。
21
+ - 其它 agy 输入框不能附加的内容会被拒绝(400)并说明是什么,不会被悄悄丢掉:PDF、音频、文本或代码文件、HEIC、文件链接(而不是文件本身),以及发给 Claude 模型的视频。
22
+ - 每个请求都是一次新的 agy 会话,之前的对话会整理成文字一起粘贴进去。
23
+ - 回答在一轮结束后一次性返回(流式请求会先收到心跳,再收到完整回答)。
24
+ - 需要 magpie v0.1.5027 或更新(带 `tui-helper`)。Windows 尚未测试。
25
+
26
+ ## 选项(环境变量)
27
+
28
+ - `AGY_PATH`:agy 的路径。
29
+ - `AGY_TUI_TURN_TIMEOUT_MS`:一轮的最长时间,默认 15 分钟。
30
+ - `AGY_TUI_ATTACH_TIMEOUT_MS`:agy 附加本轮图片和视频的最长等待时间,默认 15 秒。
31
+ - `AGY_TUI_KEEP=1`:保留每轮的临时目录(包括图片和视频)和 agy 的对话记录,方便排查。
@@ -0,0 +1,16 @@
1
+ // A copy of packages/agy-cli/agy-version.mjs: a change to one goes to the other.
2
+ // Default-agent instructions and hooks were verified on agy 1.5.19.
3
+ export const MIN_AGY_VERSION = "1.5.19"
4
+
5
+ export function agyTooOld(version) {
6
+ const parse = value => /^v?(\d+)\.(\d+)\.(\d+)/.exec(String(value ?? "").trim())?.slice(1).map(Number)
7
+ const have = parse(version)
8
+ // An ACP peer can omit its version. Keep the existing handshake behavior.
9
+ if (!have) return null
10
+ const need = parse(MIN_AGY_VERSION)
11
+ for (let i = 0; i < 3; i++) {
12
+ if (have[i] > need[i]) return null
13
+ if (have[i] < need[i]) return `agy ${version} is older than ${MIN_AGY_VERSION}, the oldest version this plugin was checked on. Update agy.`
14
+ }
15
+ return null
16
+ }
@@ -0,0 +1,131 @@
1
+ // A copy of packages/agy-cli/default-agent.mjs (each package is published
2
+ // alone): a change to one goes to the other.
3
+ // Every agy session the plugin opens runs on agy's default agent. From agy
4
+ // 1.5.17 a session of a custom agent (--agent, .agents/agents/*) costs about
5
+ // four times the quota (google-antigravity/antigravity-cli#1890), and Google's
6
+ // answer is to drop --agent and give the instructions as rules. So a session's
7
+ // folder gets, in place of an agent.md:
8
+ // - AGENTS.md, the instructions: agy loads it as a workspace rule, also with
9
+ // --include-default-customizations=false (agy 1.5.19, measured).
10
+ // - .agents/skills.json excludes agy's bundled skills from the prompt index.
11
+ // - .agents/hooks.json, a PreToolUse hook (tool-gate.mjs) that denies every
12
+ // tool call but the ones named. The default agent lists all of agy's own
13
+ // tools and no setting takes them away, so a call to one is failed before
14
+ // it runs, and the model goes on without it. A hook that fails to run
15
+ // fails the call too (agy 1.5.19, measured), never lets it through.
16
+ // What a custom agent had and the default agent has no equivalent for:
17
+ // tools: [...] (the model still sees agy's tools), inheritCustomizations:
18
+ // false, and excludeDefaultComponents.
19
+ import { randomUUID } from "node:crypto"
20
+ import fs from "node:fs/promises"
21
+ import path from "node:path"
22
+ import { fileURLToPath } from "node:url"
23
+
24
+ export const TOOL_GATE_PATH = fileURLToPath(new URL("./tool-gate.mjs", import.meta.url))
25
+ const HOOK_NAME = "magpie-tool-gate"
26
+ // agy 1.5.19's bundled skills, including the two whose directory and skill names differ.
27
+ const BUNDLED_SKILLS = [
28
+ "agy-customizations", "antigravity-guide", "antigravity_guide", "automation", "conversations",
29
+ "generative_ui", "mcp-app-development", "migrate-agent-settings", "migrate-workflows",
30
+ "native_swarm", "permissioned-github", "plugin", "run-workflow", "swarm", "swarm_monitor",
31
+ "swarm_narrator", "swarm_pane", "ui-plugin-navigation",
32
+ ]
33
+
34
+ export function toolGateCommand(allowed, { execPath = process.execPath, gate = TOOL_GATE_PATH, platform = process.platform, wrapper } = {}) {
35
+ if (platform === "win32") {
36
+ // cmd /c gets a single quoted path. Metacharacters can cause it to strip
37
+ // the quotes or expand the path before it enters the batch file.
38
+ if (!wrapper || /["\x00-\x1f\x7f%!&<>()@^|\uD800-\uDFFF]/u.test(wrapper)) throw new Error("invalid Windows hook wrapper path")
39
+ return `"${wrapper}"`
40
+ }
41
+ const quote = value => `'${String(value).replace(/'/g, `'\\''`)}'`
42
+ return [execPath, gate, ...allowed].map(quote).join(" ")
43
+ }
44
+
45
+ function windowsToolGate(allowed, { execPath = process.execPath, gate = TOOL_GATE_PATH }) {
46
+ const env = {}
47
+ const quote = (value, variable) => {
48
+ if (/["\x00-\x1f\x7f\uD800-\uDFFF]/u.test(value)) throw new Error("invalid Windows hook argument")
49
+ // Duplicate final backslashes for the called runtime's argv parser.
50
+ const argument = value.replace(/\\+$/, "$&$&")
51
+ if (/[^\x20-\x7e]/.test(value)) {
52
+ // Keep the batch file ASCII on any cmd code page. Windows gives cmd
53
+ // the paths as Unicode, and one %VAR% expansion leaves their % literal.
54
+ if (!variable) throw new Error("invalid Windows hook argument")
55
+ env[variable] = argument
56
+ return `"%${variable}%"`
57
+ }
58
+ // ^ and & inside quotes are literal; % still needs doubling in a batch.
59
+ return `"${argument.replace(/%/g, "%%")}"`
60
+ }
61
+ const args = [quote(execPath, "MAGPIE_AGY_HOOK_RUNTIME"), quote(gate, "MAGPIE_AGY_HOOK_GATE"), ...allowed.map(value => quote(value))]
62
+ return { content: `@echo off\r\nsetlocal DisableDelayedExpansion\r\n${args.join(" ")}\r\n`, env }
63
+ }
64
+
65
+ function toolGateHooks(command) {
66
+ return {
67
+ [HOOK_NAME]: {
68
+ PreToolUse: [{ matcher: "*", hooks: [{ type: "command", command, timeout: 10 }] }],
69
+ },
70
+ }
71
+ }
72
+
73
+ async function writeIfChanged(file, content) {
74
+ const bytes = Buffer.from(content)
75
+ const previous = await fs.readFile(file).catch(error => {
76
+ if (error.code !== "ENOENT") throw error
77
+ })
78
+ if (previous?.equals(bytes)) return
79
+ const temporary = `${file}.${randomUUID()}.tmp`
80
+ const handle = await fs.open(temporary, "wx", 0o600)
81
+ try {
82
+ try {
83
+ await handle.writeFile(bytes)
84
+ } finally {
85
+ await handle.close()
86
+ }
87
+ await fs.rename(temporary, file)
88
+ } catch (error) {
89
+ await fs.unlink(temporary).catch(() => {})
90
+ throw error
91
+ }
92
+ }
93
+
94
+ async function removeIfThere(file) {
95
+ const stat = await fs.lstat(file).catch(error => {
96
+ if (error.code !== "ENOENT") throw error
97
+ })
98
+ if (stat) await fs.rm(file, { recursive: true, force: true })
99
+ }
100
+
101
+ async function bundledSkills(geminiDir) {
102
+ if (!geminiDir) return BUNDLED_SKILLS
103
+ const entries = await fs.readdir(path.join(geminiDir, "antigravity-cli", "builtin", "skills"), { withFileTypes: true }).catch(error => {
104
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error
105
+ return []
106
+ })
107
+ const names = entries.filter(entry => entry.isDirectory()).map(entry => entry.name).sort()
108
+ return [...new Set([...BUNDLED_SKILLS, ...names])]
109
+ }
110
+
111
+ // writeDefaultAgentFiles readies dir for a session on the default agent.
112
+ // allowed: the tool names its model may call (a trailing * a prefix); null
113
+ // leaves every tool to agy's own permissions, with no hook. A folder used
114
+ // before keeps nothing of an older plugin's agent definition.
115
+ export async function writeDefaultAgentFiles(dir, { instructions, allowed, geminiDir }, options = {}) {
116
+ const agents = path.join(dir, ".agents")
117
+ const hooks = path.join(agents, "hooks.json")
118
+ const wrapper = path.join(agents, "tool-gate.cmd")
119
+ const platform = options.platform ?? process.platform
120
+ const command = allowed && toolGateCommand(allowed, { ...options, platform, wrapper })
121
+ const batch = command && platform === "win32" ? windowsToolGate(allowed, options) : null
122
+ await fs.mkdir(agents, { recursive: true, mode: 0o700 })
123
+ await removeIfThere(path.join(agents, "agents"))
124
+ await writeIfChanged(path.join(dir, "AGENTS.md"), instructions.endsWith("\n") ? instructions : instructions + "\n")
125
+ await writeIfChanged(path.join(agents, "skills.json"), JSON.stringify({ exclude: await bundledSkills(geminiDir) }) + "\n")
126
+ if (batch) await writeIfChanged(wrapper, batch.content)
127
+ if (command) await writeIfChanged(hooks, JSON.stringify(toolGateHooks(command), null, 2) + "\n")
128
+ else await removeIfThere(hooks)
129
+ if (!batch) await removeIfThere(wrapper)
130
+ return batch?.env
131
+ }