@coda-console/antigravity 0.0.0-stage → 1.1.0

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 coda-console
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # Antigravity
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
+ 把 [Google Antigravity](https://antigravity.google/cli) 的 Agent 接进 Coda。清单经一个薄转发入口(`agent/entry.mjs`)启动运行机上的 `agy acp`(Antigravity CLI 的 ACP 服务),
4
+ 先找 `~/.local/bin/agy`,没有再用 PATH。每个会话一个进程,不登记等待项。
5
+
6
+ 入口只改两处,其余消息原样双向转发:把 `initialize` 答复里的 `additionalDirectories` 能力去掉,Coda 就不再给它传附加目录;
7
+ `session/new`、`session/load`、`session/resume` 里若仍带 `additionalDirectories` 也删掉。原因:agy 1.5.9 收到附加目录后,
8
+ 没给 Cwd 的命令默认跑在**字典序最前的附加根**,而不是会话的工作副本(实测规律,不是上游的保证;数组顺序、`session/load` 都不改变它);
9
+ 不传附加目录时命令就在工作副本里跑。
10
+
11
+ 需要带会话指令兜底的 Coda(2026-11-13 部署版,coda#2500)或更新版本;旧版 Coda 不会给 Antigravity 送入会话指令。
12
+
13
+ 要求 Antigravity CLI **1.5.9 及以上**:`agy acp` 从 1.5.0 才有,Auto 模式与模式保持的修复在 1.5.4,上下文用量在 1.5.8;
14
+ 插件的核对(握手、`--live`)都跑在 1.5.9 上。
15
+
16
+ ## 安装
17
+
18
+ 1. **运行机装 Antigravity CLI**:插件的设置动作(`scripts/setup.mjs`)在你安装或更新插件时于每台机器上运行:没有 `agy` 就用官方安装程序装上,
19
+ 低于 1.5.9 就用 `agy update` 升级,新的不动;已有的 `agy` 跑不起来时只说明原因并失败,不替你删它。资源页「Antigravity」的「安装」也运行同一个设置动作。
20
+ 也可以自己装:
21
+
22
+ ```sh
23
+ curl -fsSL https://antigravity.google/cli/install.sh | bash
24
+ ```
25
+
26
+ 装到 `~/.local/bin/agy`(`--dir` 可改位置)。官方安装程序在 `~/.local/bin/agy` 已存在时什么都不做,所以升级用 `agy update`;二进制自己也会在后台更新。
27
+ 自己用上面那行装,安装程序最后运行的 `agy install` 会把 `~/.local/bin` 写进已有的 shell 配置(`.bashrc`、`.zshrc`)的 PATH。
28
+ 设置动作不改你的 shell 配置:它在一个临时目录当 `HOME` 的环境里运行安装程序,并用 `--dir` 把二进制装进真正的 `~/.local/bin`,
29
+ 安装程序的暂存文件与 shell 配置改动都落在临时目录,装完即删;要让 `agy` 进终端的 PATH,自己加。
30
+ 启动命令先找 `~/.local/bin/agy`,找不到再用 `PATH` 上的 `agy`:Coda 后端服务的 `PATH` 不一定有 `~/.local/bin`。
31
+
32
+ 2. **登录**,三选一:
33
+ - **资源页**:「资源 › 添加资源」里选「Antigravity」,Coda 显示授权链接,在浏览器里用 Google 账号确认,把授权页给的授权码贴回 Coda。
34
+ - **运行机的终端**(用运行 Coda 后端的那个账户):
35
+
36
+ ```sh
37
+ agy acp --login # 打印授权链接,贴回授权码(或落地页的完整网址),回车;成功打印「Logged in as <邮箱>.」
38
+ ```
39
+
40
+ - API key、Vertex 等其他认证方式:见 [Antigravity CLI 官方文档](https://antigravity.google/docs),插件不处理。
41
+
42
+ 登录保存在这台机器的系统钥匙串里(macOS 钥匙串,条目服务 `gemini`、账号 `antigravity`;Linux 用 Secret Service),由 Antigravity CLI 自己续期。
43
+ 未登录时 `session/new` 回 -32000「Authentication required」,Coda 提示「Antigravity 未登录」。
44
+
45
+ 3. **在 Coda 里装插件**:「设置 › 插件 › 从仓库添加…」,仓库填 `coda-console/coda-plugins`,读取后选「Antigravity」。
46
+ 确认里能看到会运行的命令原文:
47
+
48
+ ```sh
49
+ exec "$CODA_NODE" "$CODA_PLUGIN_PATH/agent/entry.mjs"
50
+ exec "$CODA_NODE" "$CODA_PLUGIN_PATH/scripts/setup.mjs"
51
+ ```
52
+
53
+ 装好后新任务的 Agent 选择里出现 Antigravity。插件在空间里共享,设置动作在每台机器上各装一次;装不上的那台,会话启动失败并提示清单的 `setupHint`。
54
+
55
+ ## 在 Coda 里是什么样
56
+
57
+ | 设置 | 来源 |
58
+ | --- | --- |
59
+ | 模型、思考档位 | Antigravity 给的配置项 `model`、`thought_level`:Gemini 4 系列,账号里有的 Claude、GPT-OSS 也在其中。在 Coda 里切换不写回 `~/.gemini/antigravity-cli/settings.json` |
60
+ | 工作模式 | `default`、`accept-edits`、`auto`、`plan`(「工作模式」,没选时用 Antigravity 自己的默认);清单的 `modes.auto` 指向 `auto`,供委派子会话与流程步骤的「自动审批」使用 |
61
+ | 审批 | `default` 与 `accept-edits` 下跑命令发 `session/request_permission`,选项是 `allow`(allow_once)与 `deny`(reject_once),Mac 与 iPhone 出审批卡片;`auto` 对安全命令不再询问 |
62
+ | 恢复 | Antigravity 声明 `loadSession`,后端或托管重启后用 `session/load` 接着聊 |
63
+ | skills | 读工作副本的 `.agents/skills`(清单的 `skillsDir`) |
64
+ | 上下文占用、标题 | Antigravity 报 `usage_update` 与会话标题更新 |
65
+ | 模型列表何时重读 | `~/.gemini/antigravity-cli/settings.json` 变了时 |
66
+ | 资源页 | 登录后显示一条「Antigravity」,读数是各模型组的每周、每 5 小时剩余比例与重置时间(如「Gemini 每周」「Claude and GPT 5 小时」,组与周期按报告动态给出),最后是 CLI 版本。额度来自官方的只读报告 `agy -p /usage --output-format json`(CLI 1.1.11 起支持,插件要求 1.5.9 及以上):由 CLI 自己回答,不开会话、不花额度、不留对话,插件不读 token;这一次运行只设 `AGY_CLI_DISABLE_AUTO_UPDATE=true`,在系统临时目录里跑。整次读取给自己 25 秒(宿主只给 30 秒):版本和额度都只用剩下的时间并留 1 秒输出,剩下不到 3 秒就不再查额度,直接写「暂时无法获取额度:读取超时」,版本照旧显示。读数最多 8 条:额度最多 7 条,CLI 版本始终在最后。读不到额度(退出非 0、超时、报告不是成功、没有可显示的桶)时那一条带「暂时无法获取额度:原因」(原因是 CLI stderr 的首行,没有才写退出码;整句不超过 80 字,只截原因),版本照旧显示;缺比例、不在 0–1 内或标了 `disabled` 的桶不显示。登录状态只查钥匙串条目在不在(macOS 用 `security find-generic-password -s gemini -a antigravity`,只查条目,不读内容),也不读邮箱;钥匙串问不出来时读数失败,不当作登出(Linux 的细节见下) |
67
+
68
+ ## 已知限制
69
+
70
+ | 功能 | 情况 |
71
+ | --- | --- |
72
+ | Auto 的审批 | Auto 对不可逆操作仍会请求审批:无人值守的子会话遇到会停下等人。官方文档说明 Auto 需要终端沙箱,企业账号与沙箱不可用的机器可能没有 Auto |
73
+ | 全部放行 | 没有:Antigravity 没有原生的「全部放行」模式(`full`、`yolo` 回 -32602),清单不写 `modes.full` |
74
+ | 会话指令 | Antigravity 只认私有的 `_meta.antigravity.systemPrompt`,不认 ACP 标准字段;插件不处理它,由 Coda 把指令作为单独一段放在新会话第一次非斜杠命令的用户输入前面,分量不如系统提示词 |
75
+ | 插话 | 不声明:Antigravity 的原生插话会提前结束旧一轮的回复,由 Coda 停下这一轮再发出新消息 |
76
+ | 额度的口径 | 报告按模型组给额度:同组模型共享每周与 5 小时限额,不是每个模型各算一份;报告里没有套餐名。第一次在某个目录运行 `/usage` 时,CLI 会在 `implicit/` 下留一个小文件;插件固定在系统临时目录运行,之后复用,不新增会话与项目记录 |
77
+ | 等待项登记 `_coda/wait` | 不登记,会话底部不列它在等什么 |
78
+ | Plan 模式 | 产出计划文件并要求审阅,审阅前不动手;plan 下只读的 shell 命令也按权限规则请求审批,这是 agy 的设计 |
79
+ | 附加目录 | 不交给 Antigravity:读工作副本外的附件、会话临时目录、skill 真实文件可能要审批;`.agents/skills` 的链接照旧 |
80
+ | Coda 的 MCP 工具在 auto 下也要审批 | 无人值守的子会话、流程步骤调用它们会停下。放行写法是在运行机的 `~/.gemini/antigravity-cli/settings.json` 里加 `{"permissions": {"allow": ["mcp(coda/*)"]}}`,出处是官方[权限文档](https://antigravity.google/docs/permissions/);插件不替你改这个文件 |
81
+ | 额度耗尽 | 没有真实样本,不做失败分类,Coda 只看到 Antigravity 给的错误文字 |
82
+ | 没有桌面会话的 Linux 登录 | 未实测:Linux 用 Secret Service(D-Bus),二进制里有「keyring 失败就落文件」的回退,但文件路径与触发条件没查清。资源页在 Linux 上用 `secret-tool lookup service gemini username antigravity` 查条目(属性名按 go-keyring 的写法,未在真机上试过),没有 `secret-tool`、查不到条目,或登录落在文件里时,资源页当作未登录(只是仍在「添加资源」里出现,会话不受影响)。装了 `secret-tool` 却联系不上 Secret Service(典型是没有会话 D-Bus 的无桌面机器,它带错误信息退出)时,资源页读数失败、保留上次的显示,首次读取就没有可保留的,也就无法从资源页添加:这样的机器在终端里运行 `agy acp --login` 登录 |
83
+ | 第三方模型 | 账号里的 Claude、GPT-OSS 未实测 |
84
+ | 并发进程 | 不加 `--process-per-session`:Coda 交给 Agent 的 MCP 服务器都是 stdio,官方只对 HTTP MCP 要求这个参数 |
85
+
86
+ ## 验收
87
+
88
+ ```sh
89
+ node bin/check.mjs plugins/antigravity # 握手:protocolVersion 1,session/new 给出会话与当前模型;资源读数合格式
90
+ node bin/check.mjs plugins/antigravity --live # 一轮:会话指令、回复、取消、session/load
91
+ ```
92
+
93
+ 然后在 Coda 里:发一句话收到回复;选 plan 出计划文件并停在审阅;选 default 跑一个要审批的命令,Mac 与 iPhone 都出卡片;选 auto 跑安全命令不再询问;
94
+ 重启后端后接着聊(`session/load`);资源页登录一遍(贴授权码)。
@@ -0,0 +1,43 @@
1
+ // Starts `agy acp` and relays its ACP both ways, line for line, with two things taken out so Coda gives it no additional
2
+ // directories: agy 1.5.9 runs a command with no Cwd in the lexicographically first additional root, not in the session's
3
+ // cwd (observed, not promised upstream). The `initialize` answer loses the additionalDirectories capability (Coda only
4
+ // passes the directories to an agent that declares it), and a session request loses `additionalDirectories` should one come anyway.
5
+ import { spawn } from 'node:child_process';
6
+ import { agyBinary } from '../scripts/agy.mjs';
7
+
8
+ const agy = spawn(agyBinary() ?? 'agy', ['acp'], { stdio: ['pipe', 'pipe', 'inherit'] });
9
+ const initializing = new Set();
10
+ let stopping = false;
11
+
12
+ // Only LF separates JSON messages; readline would also split literal Unicode line separators inside JSON strings.
13
+ // A line that is not a JSON object passes through as it is.
14
+ function relay(from, to, change) {
15
+ let rest = '';
16
+ const take = text => {
17
+ const lines = (rest + text).split('\n'); rest = lines.pop();
18
+ for (const line of lines) {
19
+ let message; try { message = JSON.parse(line); } catch { message = null; }
20
+ if (message && typeof message === 'object' && !Array.isArray(message)) { change(message); to.write(`${JSON.stringify(message)}\n`); } else to.write(`${line}\n`);
21
+ }
22
+ };
23
+ from.setEncoding('utf8').on('data', take).on('end', () => take('\n'));
24
+ }
25
+ relay(process.stdin, agy.stdin, message => {
26
+ if (message.method === 'initialize' && 'id' in message) initializing.add(message.id);
27
+ if (['session/new', 'session/load', 'session/resume'].includes(message.method)) delete message.params?.additionalDirectories;
28
+ });
29
+ relay(agy.stdout, process.stdout, message => {
30
+ if (!message.method && initializing.delete(message.id)) {
31
+ for (const key of ['sessionCapabilities', 'session_capabilities']) delete message.result?.agentCapabilities?.[key]?.additionalDirectories;
32
+ }
33
+ });
34
+ const stop = () => {
35
+ if (stopping) return;
36
+ stopping = true; agy.stdin.end(); agy.kill();
37
+ setTimeout(() => agy.kill('SIGKILL'), 800).unref();
38
+ };
39
+ agy.stdin.on('error', () => {});
40
+ agy.on('error', () => process.exit(1));
41
+ agy.on('close', code => process.exit(stopping ? 0 : code ?? 1));
42
+ process.stdin.on('end', stop);
43
+ for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) process.once(signal, stop);
@@ -0,0 +1,22 @@
1
+ # Antigravity 品牌图形
2
+
3
+ 仅用于标识会话所用的服务,不作为 Coda 自身标志。Google Antigravity is a trademark of Google LLC,商标归各自权利人所有。
4
+
5
+ - `antigravity.svg`:取自 [Antigravity Press Assets](https://antigravity.google/press) 的 Icon – One Color
6
+ (源文件 <https://antigravity.google/assets/image/brand/antigravity-icon__one-color.svg>)。只改了画布:
7
+ `width`、`height` 由 180 改成 256 px(iOS 按 96 pt 光栅化 PDF 时只缩不放,页面太小会画成一个点),
8
+ `viewBox` 由 `0 0 180 180` 裁成以标志为中心的正方形 `19.665 20 140 140`(标志的外框是 x 22.50–156.83、y 28.125–151.875)。
9
+ 路径与填色 `#202124` 一概不动,Google 的品牌规则不许改形、改色。
10
+ 单色,清单里 `template: true`,随文字颜色着色。用于 Antigravity。
11
+
12
+ 提取日期:2026-11-16。SVG 是可审阅的源文件,PDF 是由 CairoSVG 转换的等比矢量资源,清单的 `icon` 指向 PDF。重新生成 PDF(开发工具,不是构建或运行依赖):
13
+
14
+ ```sh
15
+ uv run --with cairosvg python - <<'PY'
16
+ import cairosvg
17
+ for name in ['antigravity']:
18
+ cairosvg.svg2pdf(url=f'{name}.svg', write_to=f'{name}.pdf')
19
+ PY
20
+ ```
21
+
22
+ macOS 上若找不到 libcairo,先 `brew install cairo`,再在命令前加 `DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib`。
Binary file
@@ -0,0 +1,3 @@
1
+ <svg width="256" height="256" viewBox="19.665 20 140 140" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M144.248 149.062C151.748 154.688 162.998 150.938 152.685 140.625C121.748 110.625 128.31 28.125 89.8727 28.125C51.4352 28.125 57.9977 110.625 27.0602 140.625C15.8102 151.875 27.9977 154.688 35.4977 149.062C64.5602 129.375 62.6852 94.6875 89.8727 94.6875C117.06 94.6875 115.185 129.375 144.248 149.062Z" fill="#202124"/>
3
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@coda-console/antigravity",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "id": "antigravity",
4
+ "displayName": "Antigravity",
5
+ "description": "用 Antigravity CLI 跑会话",
6
+ "version": "1.1.0",
7
+ "categories": ["Agent"],
8
+ "contributes": {
9
+ "agents": [
10
+ {
11
+ "id": "antigravity",
12
+ "displayName": "Antigravity",
13
+ "icon": {
14
+ "light": "icons/antigravity.pdf",
15
+ "template": true
16
+ },
17
+ "command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/agent/entry.mjs\"",
18
+ "modes": {
19
+ "title": "工作模式",
20
+ "unset": "Agent 默认",
21
+ "auto": "auto",
22
+ "note": "Auto 对不可逆操作与 Coda 的 MCP 工具仍会询问;权限沿用运行机的 ~/.gemini/antigravity-cli/settings.json,可在那里放行。"
23
+ },
24
+ "skillsDir": ".agents/skills",
25
+ "configFiles": [
26
+ "~/.gemini/antigravity-cli/settings.json"
27
+ ],
28
+ "setupHint": "请在「资源」里为运行机添加 Antigravity。"
29
+ }
30
+ ],
31
+ "resources": [
32
+ {
33
+ "id": "account",
34
+ "title": "Antigravity",
35
+ "command": "node \"$CODA_PLUGIN_PATH/scripts/resources.mjs\"",
36
+ "maxAge": "PT5M",
37
+ "signIn": {
38
+ "command": "a=\"$HOME/.local/bin/agy\"; [ -x \"$a\" ] || a=agy; BROWSER=/usr/bin/true NO_COLOR=1 exec \"$a\" acp --login",
39
+ "installed": "node \"$CODA_PLUGIN_PATH/scripts/setup.mjs\" --check",
40
+ "install": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\"",
41
+ "input": "authorizationCode",
42
+ "note": "登录保存在这台机器的系统钥匙串里,由 Antigravity CLI 自己续期;用 Google 账号确认,把授权页给的授权码贴回来。"
43
+ }
44
+ }
45
+ ],
46
+ "setup": {
47
+ "command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\""
48
+ }
49
+ },
50
+ "license": "MIT",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/coda-console/coda-plugins.git",
54
+ "directory": "plugins/antigravity"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "files": [
60
+ "agent",
61
+ "scripts",
62
+ "icons"
63
+ ]
64
+ }
@@ -0,0 +1,79 @@
1
+ // The Antigravity CLI the plugin's scripts use, found as the agent's command does: ~/.local/bin/agy first (where Google's
2
+ // installer puts it; Coda's back end does not always have that directory on its PATH), then the PATH.
3
+ import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import { homedir, tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+
8
+ export function agyBinary(env = process.env) {
9
+ const installed = join(homedir(), '.local/bin/agy');
10
+ if (existsSync(installed)) return installed;
11
+ return (env.PATH ?? '').split(':').filter(Boolean).map(dir => join(dir, 'agy')).find(path => existsSync(path)) ?? null;
12
+ }
13
+ // `agy --version` run once, and the first x.y.z it printed on either output (null for none): the one reading of the version,
14
+ // which the setup and the resources share (the resources give it what is left of their time).
15
+ export const asked = (binary, timeout = 30_000) => spawnSync(binary, ['--version'], { encoding: 'utf8', timeout, stdio: ['ignore', 'pipe', 'pipe'] });
16
+ export const versionOf = ran => /(\d+)\.(\d+)\.(\d+)/.exec(`${ran.stdout ?? ''}\n${ran.stderr ?? ''}`)?.slice(1).join('.') ?? null;
17
+ // The CLI's usage report, parsed: `agy -p /usage --output-format json`, which the CLI answers itself, without a turn, the
18
+ // quota spent or a conversation left behind. Run from the temporary directory, so that no project of the CLI's is made for
19
+ // a directory of the user's, and with its update off for this run alone. Throws, with the reason in a line, for a CLI that
20
+ // fails or times out (`timeout`, which the resources keep within the 30 seconds Coda gives a reading) or answers anything but
21
+ // a successful usage report.
22
+ export function usageReport(binary, run = spawnSync, timeout = 20_000) {
23
+ const ran = run(binary, ['-p', '/usage', '--output-format', 'json'], { encoding: 'utf8', cwd: tmpdir(), timeout,
24
+ env: { ...process.env, AGY_CLI_DISABLE_AUTO_UPDATE: 'true' }, stdio: ['ignore', 'pipe', 'pipe'] });
25
+ if (ran.error?.code === 'ETIMEDOUT') throw new Error('读取超时');
26
+ if (ran.error) throw new Error(`无法运行 Antigravity CLI:${ran.error.code ?? ran.error.message}`);
27
+ // What the CLI said first is the reason; its exit code only when it said nothing.
28
+ if (ran.status !== 0) throw new Error(`${ran.stderr ?? ''}`.trim().split('\n')[0] || `退出码 ${ran.status ?? ran.signal}`);
29
+ let report;
30
+ try { report = JSON.parse(ran.stdout); } catch { throw new Error('Antigravity CLI 的额度报告不是 JSON'); }
31
+ if (report?.status !== 'SUCCESS') throw new Error(`Antigravity CLI 的额度报告状态不是 SUCCESS(${report?.status ?? '无状态'})`);
32
+ if (report.command?.name !== 'usage') throw new Error('Antigravity CLI 返回的不是额度报告');
33
+ return report;
34
+ }
35
+ // What a reading learns of the CLI before `deadline` (ms, the clock's): its version, asked what is left of the time less a second
36
+ // to print, and, for a CLI not older than `minimum`, its usage report, asked what is left then, or none, with the reason, for
37
+ // too little left to ask (3 seconds) or a report that fails. `ask`, `report` and `now` are the CLI's, as above, and the clock.
38
+ // { version: null } for a CLI that cannot say its version.
39
+ export function reading(binary, deadline, minimum, { ask = asked, report = usageReport, now = Date.now } = {}) {
40
+ const left = () => deadline - now() - 1_000;
41
+ const ran = ask(binary, Math.max(left(), 1));
42
+ const version = ran.status === 0 ? versionOf(ran) : null;
43
+ if (!version) return { version: null };
44
+ if (older(version, minimum)) return { version, tooOld: true };
45
+ if (left() < 3_000) return { version, failure: '读取超时' };
46
+ try { return { version, report: report(binary, undefined, Math.min(left(), 20_000)) }; } catch (error) { return { version, failure: error.message }; }
47
+ }
48
+ // Whether one version is older than another.
49
+ export function older(version, than) {
50
+ const a = version.split('.').map(Number), b = than.split('.').map(Number), i = a.findIndex((n, k) => n !== b[k]);
51
+ return i >= 0 && a[i] < b[i];
52
+ }
53
+
54
+ // Whether the Antigravity CLI has a login on this machine: its credentials entry (service `gemini`, account `antigravity`)
55
+ // is in the keychain, asked for the entry alone, never its secret. macOS: `security`; Linux: the Secret Service through
56
+ // `secret-tool` (the entry's attributes are what go-keyring writes: not tried on a real machine), where the CLI's file
57
+ // fallback for a machine without one is not looked for. True or false for what the keychain answers: on Linux, no
58
+ // `secret-tool`, or one that exits 1 saying nothing (its answer for no entry) is not signed in. An error for a keychain that
59
+ // cannot be asked (macOS: any other answer than found or not found; Linux: `secret-tool` timing out, killed, failing to
60
+ // start, or failing with a message, as for a Secret Service it cannot reach, which it also exits 1 for), which fails the
61
+ // reading rather than showing a sign-out.
62
+ export function signedIn(platform = process.platform, run = spawnSync) {
63
+ if (platform === 'darwin') {
64
+ const ran = run('security', ['find-generic-password', '-s', 'gemini', '-a', 'antigravity'], { encoding: 'utf8', stdio: ['ignore', 'ignore', 'pipe'], timeout: 10_000 });
65
+ // 44 is `security`'s errSecItemNotFound.
66
+ if (ran.status === 0) return true;
67
+ if (ran.status === 44) return false;
68
+ throw new Error(`读不了钥匙串:${`${ran.stderr ?? ''}`.trim().split('\n')[0] || ran.error?.code || ran.signal || ran.status}`);
69
+ }
70
+ if (platform === 'linux') {
71
+ const ran = run('secret-tool', ['lookup', 'service', 'gemini', 'username', 'antigravity'], { encoding: 'utf8', stdio: ['ignore', 'ignore', 'pipe'], timeout: 10_000 });
72
+ if (ran.error?.code === 'ENOENT') return false;
73
+ if (ran.status === 0) return true;
74
+ const said = `${ran.stderr ?? ''}`.trim().split('\n')[0];
75
+ if (ran.status === 1 && !said && !ran.error) return false;
76
+ throw new Error(`读不了 Secret Service:${said || ran.error?.code || ran.signal || ran.status}`);
77
+ }
78
+ return false;
79
+ }
@@ -0,0 +1,19 @@
1
+ // The quota the「Antigravity」resource shows, from the report `agy -p /usage --output-format json` prints (the CLI's own
2
+ // read-only report: no turn, no quota spent, no conversation left behind). The groups and their buckets are the report's:
3
+ // models of a group share its limits, and the report has no plan name.
4
+ const WINDOWS = { weekly: '每周', '5h': '5 小时' };
5
+ const short = name => String(name ?? '').replace(/\s+/g, ' ').trim().replace(/\s+models?$/i, '');
6
+ const instant = value => typeof value === 'string' && Number.isFinite(Date.parse(value)) ? new Date(value).toISOString() : null;
7
+
8
+ // One value for each bucket that says what is left of it, in the report's order. A bucket with no ratio, one outside 0–1 or
9
+ // a disabled one is left out, never shown as full.
10
+ export function windows(report) {
11
+ const groups = Array.isArray(report?.command?.data?.groups) ? report.command.data.groups : [];
12
+ return groups.flatMap(group => (Array.isArray(group?.buckets) ? group.buckets : []).flatMap(bucket => {
13
+ const left = bucket?.remaining_fraction;
14
+ if (bucket?.disabled === true || typeof left !== 'number' || !Number.isFinite(left) || left < 0 || left > 1) return [];
15
+ const percent = Math.round(left * 100), resets = instant(bucket.reset_time);
16
+ const label = [...[short(group.name), WINDOWS[bucket.window] ?? bucket.window].filter(Boolean).join(' ')].slice(0, 80).join('');
17
+ return [{ label, value: `剩余 ${percent}%`, fraction: percent / 100, ...(resets ? { time: resets } : {}) }];
18
+ }));
19
+ }
@@ -0,0 +1,28 @@
1
+ // The「Antigravity」resources, printed once as `{ resources }`. No login here shows nothing (the type is then offered under
2
+ // 「添加资源」); a keychain that cannot be asked fails the reading, which keeps the last one shown. Shown: the quota of each
3
+ // model group (the CLI's own read-only usage report, which opens no session and spends nothing; or why it is not had) and the
4
+ // CLI's version. There is no cheap, reliable place for the email, so no account is shown.
5
+ import { agyBinary, reading, signedIn } from './agy.mjs';
6
+ import { windows } from './quota.mjs';
7
+ import { MINIMUM } from './setup.mjs';
8
+
9
+ // The whole reading gets 25 of the 30 seconds Coda allows, from here, so that it is printed, with the reason, rather than
10
+ // killed by Coda with nothing (agy.mjs `reading`: the version and the quota are asked what is left of it).
11
+ const deadline = Date.now() + 25_000;
12
+ const print = value => console.log(JSON.stringify(value));
13
+ let login;
14
+ try { login = signedIn(); } catch (error) { console.error(error.message); process.exit(1); }
15
+ if (!login) { print({ resources: [] }); process.exit(0); }
16
+ const binary = agyBinary();
17
+ if (!binary) { print({ resources: [{ name: 'Antigravity', error: '这台机器上找不到 Antigravity CLI,请在运行机重新安装' }] }); process.exit(0); }
18
+ const { version, tooOld, report, failure: why } = reading(binary, deadline, MINIMUM);
19
+ if (!version) { console.error(`读不出 Antigravity CLI 的版本(${binary})`); process.exit(1); }
20
+ const values = report ? windows(report) : [];
21
+ const failure = why ?? (report && !values.length ? 'Antigravity CLI 没有给出额度' : null);
22
+ const line = (text, max = 80) => [...text.replace(/\s+/g, ' ').trim()].slice(0, max).join('');
23
+ // A reading lists 8 values at most: the version is always the last, after at most 7 of the quota. Only the reason is cut to
24
+ // what the 80 characters leave after「暂时无法获取额度:」.
25
+ const WHY = '暂时无法获取额度:';
26
+ print({ resources: [{ name: 'Antigravity', values: [...values.slice(0, 7), { label: 'CLI 版本', value: version }],
27
+ ...(tooOld ? { error: `Antigravity CLI 低于所需的 ${MINIMUM},请重新安装插件或在运行机运行 agy update` }
28
+ : failure ? { error: WHY + line(failure, 80 - WHY.length) } : {}) }] });
@@ -0,0 +1,51 @@
1
+ // The plugin's setup (`contributes.setup`), which Coda runs on each machine when the user installs or updates the plugin: it
2
+ // ends well once the machine can run the agent. Without an Antigravity CLI, Google's installer puts the latest in
3
+ // ~/.local/bin, where the agent looks first; one older than MINIMUM (the CLI the `agy acp` entry was checked against: the
4
+ // subcommand is there from 1.5.0, Auto mode and keeping the mode from 1.5.4, context usage from 1.5.8) is brought up with its
5
+ // own `agy update`; a newer one is kept. The installer does nothing where ~/.local/bin/agy exists, so a CLI that does not run
6
+ // is never replaced: it is reported. Why the machine is not ready is said in one line on standard error.
7
+ // `--check` only answers (exit 0) whether the machine is ready: the「Antigravity」type's `installed`.
8
+ import { spawnSync } from 'node:child_process';
9
+ import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
10
+ import { homedir, tmpdir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { agyBinary, asked, older, versionOf } from './agy.mjs';
14
+
15
+ export const MINIMUM = '1.5.9';
16
+
17
+ // What the machine needs, given the CLI found (`binary`, null for none) and how its `--version` runs (`run`):
18
+ // `install`, `upgrade`, `broken` (found, but does not run) or `none`, and why.
19
+ export function needed(binary, run = asked) {
20
+ if (!binary) return { action: 'install', reason: '这台机器上没有 Antigravity CLI' };
21
+ const ran = run(binary);
22
+ if (ran.status !== 0) return { action: 'broken', reason: `Antigravity CLI 无法运行(${binary}),请检查或删除后重试` };
23
+ const version = versionOf(ran);
24
+ if (!version) return { action: 'upgrade', reason: `读不出 Antigravity CLI 的版本(${binary})` };
25
+ if (older(version, MINIMUM)) return { action: 'upgrade', reason: `Antigravity CLI ${version} 低于所需的 ${MINIMUM}` };
26
+ return { action: 'none', version };
27
+ }
28
+
29
+ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
30
+ const before = needed(agyBinary());
31
+ if (process.argv[2] === '--check') process.exit(before.action === 'none' ? 0 : 1);
32
+ if (before.action === 'broken') { console.error(before.reason); process.exit(1); }
33
+ if (before.action !== 'none') {
34
+ // What the installer or the update prints goes to standard error with the rest of its story. The installer ends with
35
+ // `agy install`, which adds ~/.local/bin to the PATH of the shell profiles that exist and has no switch the installer
36
+ // passes on (`--skip-path`): so it runs with a temporary directory as its HOME (its staging and profile edits go there,
37
+ // and are removed) and `--dir` puts the binary in the real ~/.local/bin.
38
+ let done;
39
+ if (before.action === 'install') {
40
+ const scratch = mkdtempSync(join(tmpdir(), 'coda-antigravity-'));
41
+ try {
42
+ done = spawnSync('bash', ['-c', 'set -o pipefail; curl -fsSL https://antigravity.google/cli/install.sh | bash -s -- --dir "$1"', 'bash', join(homedir(), '.local/bin')],
43
+ { stdio: ['ignore', 2, 2], env: { ...process.env, HOME: scratch } });
44
+ } finally { rmSync(scratch, { recursive: true, force: true }); }
45
+ } else done = spawnSync(agyBinary(), ['update'], { stdio: ['ignore', 2, 2], timeout: 5 * 60_000 });
46
+ if (done.status !== 0) { console.error(`${before.reason},${before.action === 'install' ? '安装' : '升级'}失败(退出码 ${done.status ?? done.signal})`); process.exit(1); }
47
+ }
48
+ const after = needed(agyBinary());
49
+ if (after.action !== 'none') { console.error(after.reason); process.exit(1); }
50
+ console.log(`Antigravity CLI ${after.version}`);
51
+ }