@coda-console/antigravity 1.3.2 → 1.4.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/README.md +4 -4
- package/agent/catalog.mjs +93 -22
- package/package.json +15 -12
- package/scripts/resource.mjs +37 -0
- package/scripts/setup.mjs +7 -7
- package/scripts/sign-in.mjs +65 -0
- package/scripts/resources.mjs +0 -28
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Coda 会把它存成回复正文,像答到一半出错,其实这一轮还在
|
|
|
22
22
|
## 安装
|
|
23
23
|
|
|
24
24
|
1. **运行机装 Antigravity CLI**:插件的设置动作(`scripts/setup.mjs`)在你安装或更新插件时于每台机器上运行:没有 `agy` 就用官方安装程序装上,
|
|
25
|
-
低于 1.5.9 就用 `agy update` 升级,新的不动;已有的 `agy` 跑不起来时只说明原因并失败,不替你删它。资源页「Antigravity
|
|
25
|
+
低于 1.5.9 就用 `agy update` 升级,新的不动;已有的 `agy` 跑不起来时只说明原因并失败,不替你删它。资源页「Antigravity」的「安装」是操作 `install`,指向同一个 `scripts/setup.mjs`(结果 `{}`,说明写在标准错误)。
|
|
26
26
|
也可以自己装:
|
|
27
27
|
|
|
28
28
|
```sh
|
|
@@ -69,7 +69,7 @@ Coda 会把它存成回复正文,像答到一半出错,其实这一轮还在
|
|
|
69
69
|
| skills | 读工作副本的 `.agents/skills`(清单的 `skillsDir`) |
|
|
70
70
|
| 上下文占用、标题 | Antigravity 报 `usage_update` 与会话标题更新 |
|
|
71
71
|
| 模型列表何时重读 | `~/.gemini/antigravity-cli/settings.json` 变了时 |
|
|
72
|
-
| 资源页 | 登录后显示一条「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
|
|
72
|
+
| 资源页 | 登录后显示一条「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 的首行,没有才写退出码),Coda 保留上一份记录,资源页显示「更新失败:原因」;缺比例、不在 0–1 内或标了 `disabled` 的桶不显示。登录状态只查钥匙串条目在不在(macOS 用 `security find-generic-password -s gemini -a antigravity`,只查条目,不读内容),也不读邮箱;钥匙串问不出来时命令同样以非零退出并写明原因,不当作登出(Linux 的细节见下)。记录命令是 `scripts/resource.mjs`,不定时(没有 `every`),资源页打开、点「刷新」和每个操作之后运行;登录了却找不到 CLI、或 CLI 低于所需版本时,记录照写:一行说明,登录与安装入口照常在;CLI 读不出版本则命令以非零退出。登录是操作 `sign-in`(`scripts/sign-in.mjs`):运行 `agy acp --login`,把它打印的授权链接用 `coda progress` 报给 Coda(只认完整的行,两路输出各自成行;报完才算登录结束,报失败登录就失败;20 秒内没有链接就失败,原因是那时 CLI 说的最后一行),再用 `coda ask` 要授权码、写进 CLI 的标准输入;CLI 已退出就不再问,码交出后 CLI 说的话不传出 |
|
|
73
73
|
|
|
74
74
|
## 已知限制
|
|
75
75
|
|
|
@@ -87,9 +87,9 @@ Coda 会把它存成回复正文,像答到一半出错,其实这一轮还在
|
|
|
87
87
|
| Coda 的 MCP 工具在 auto 下也要审批 | 无人值守的子会话、流程步骤调用它们会停下;「全部放行」下不会。要在 auto 下放行,写法是在运行机的 `~/.gemini/antigravity-cli/settings.json` 里加 `{"permissions": {"allow": ["mcp(coda/*)"]}}`,出处是官方[权限文档](https://antigravity.google/docs/permissions/);插件不替你改这个文件 |
|
|
88
88
|
| 压缩上下文不上报 Coda | Antigravity 会压缩上下文:`/compact` 在 `agy acp` 1.5.9 上实测会跑一次摘要,对话库里留下摘要步骤;二进制里也有按 token 阈值触发的压缩配置,自动压缩没有实测触发。但 ACP 流和 `acp-server` 日志都不报压缩(没有 `compaction_update`,也没有专门的通知或工具调用),唯一的痕迹在它私有的对话库里,入口不读它,也不从文本或用量反推。所以依赖压缩的功能(如 Ultra 压缩后重发说明)在它上面压缩后不生效 |
|
|
89
89
|
| 额度耗尽 | 没有真实样本,不做失败分类,Coda 只看到 Antigravity 给的错误文字 |
|
|
90
|
-
| 没有桌面会话的 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
|
|
90
|
+
| 没有桌面会话的 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 的无桌面机器,它带错误信息退出)时,资源页读取失败,原因是「读不了 Secret Service」,在这样的机器上要在终端里运行 `agy acp --login` 登录 |
|
|
91
91
|
| 第三方模型 | 账号里的 Claude、GPT-OSS 未实测 |
|
|
92
|
-
| 配置探测 | Coda 读模型、思考档位与模式的目录时,入口用插件状态目录里的缓存(`$CODA_PLUGIN_STATE/catalog-v1.json`)答一个只在当前连接有效的虚拟会话(`coda-probe:` 开头,不接受 prompt、不能恢复、断线即释放):**缓存命中时不建 Antigravity
|
|
92
|
+
| 配置探测 | Coda 读模型、思考档位与模式的目录时,入口用插件状态目录里的缓存(`$CODA_PLUGIN_STATE/catalog-v1.json`)答一个只在当前连接有效的虚拟会话(`coda-probe:` 开头,不接受 prompt、不能恢复、断线即释放):**缓存命中时不建 Antigravity 会话**。缓存不按天数过期:距上次采集或比对满 1 小时后,下一次探测先跑一次 `agy models`(不建会话,约 2~3 秒,限时 8 秒),把它列出的模型(ID 与名称)和采集时记下的清单比对,一样就只记下比对时间(`catalog-v1.check.json`),不一样才重读;`agy models` 失败(未登录、断网、超时)时照旧用缓存,5 分钟后再比对,不因此重读;旧版插件留下的没有清单的缓存,在 `agy models` 第一次答上时重读一次。此外 agy 的路径或版本、`~/.gemini/antigravity-cli/settings.json` 变化、真实会话报的配置与缓存对不上时也重读。重读用一个独立的 `agy acp` 建一条空会话逐个模型读一遍(agy 1.5.9 删不了会话,这条会留在 `~/.gemini/antigravity-cli/conversations/`,会话 ID 记在 `catalog-v1.log`)。读失败时这次探测报错、不改用普通会话,同样的 agy 与设置 5 分钟内不再重读(未登录除外);比对发现变化而重读失败时照旧用原缓存答。要支持配置探测的新版 Coda 才生效;旧版 Coda 每次探测仍各建一条空会话 |
|
|
93
93
|
| 并发进程 | 不加 `--process-per-session`:Coda 交给 Agent 的 MCP 服务器都是 stdio,官方只对 HTTP MCP 要求这个参数 |
|
|
94
94
|
|
|
95
95
|
## 验收
|
package/agent/catalog.mjs
CHANGED
|
@@ -5,11 +5,22 @@
|
|
|
5
5
|
// set_config_option, and the process closed. No prompt, no delete, nothing global set. That collection does leave one
|
|
6
6
|
// empty conversation; its ID goes to the log, `catalog-v1.log`.
|
|
7
7
|
//
|
|
8
|
-
// Out of date:
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
8
|
+
// Out of date: another format, another agy (path or version), another stat of ~/.gemini/antigravity-cli/settings.json, or
|
|
9
|
+
// marked by a real session whose options did not match. There is no age past which it is collected again: models the
|
|
10
|
+
// server adds under the same agy (as Gemini 4 Neon came to 1.5.9) are found by a check instead. Once an hour (`check`) after
|
|
11
|
+
// the collection or the last check, the entry that answers a probe asks `agy models`, which opens no conversation and takes
|
|
12
|
+
// two or three seconds, and holds its list of models (ID and name, sorted by ID) to the one the collection kept
|
|
13
|
+
// (`agyModels`). The same list is written down as checked (`catalog-v1.check.json`, for that collection) and the catalog
|
|
14
|
+
// answers; another list has it collected again. A catalog of an older plugin, with no list kept, is collected again once
|
|
15
|
+
// `agy models` answers. A check that fails (signed out, no network, a timeout) keeps the catalog and is tried again after
|
|
16
|
+
// the cool-down, never collecting for it; a collection a check asked for that fails keeps the catalog there was as well.
|
|
17
|
+
// The check is made in the probe, under the lock, before the answer, not after it: an entry may go as soon as its probe is
|
|
18
|
+
// answered, and what is learnt then would be lost. It is held to `models` (8 seconds) so that the version, a check and a
|
|
19
|
+
// collection stay inside the 60 seconds Coda gives a probe.
|
|
20
|
+
//
|
|
21
|
+
// Entries collect and check one at a time (a lock in the state directory, waited on for a while, the catalog and the last
|
|
22
|
+
// failure read again once it is held); a collection that fails, or answers options that do not hold together, is not tried
|
|
23
|
+
// again for five minutes for the same agy and settings, and leaves the catalog there was.
|
|
13
24
|
//
|
|
14
25
|
// The lock is a line of generations, `catalog-v1.lock.<n>`, each made at once with its holder in it (a hard link); the
|
|
15
26
|
// highest is the lock. It is free once its holder marks it `.free`, is gone, or is past a collection's time, and is then
|
|
@@ -25,8 +36,9 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
25
36
|
import { versionOf } from '../scripts/agy.mjs';
|
|
26
37
|
|
|
27
38
|
export const FORMAT = 1;
|
|
28
|
-
// `collect` stays inside the 60 seconds Coda gives a probe; `wait` is how long an entry waits for another's collection
|
|
29
|
-
|
|
39
|
+
// `collect` stays inside the 60 seconds Coda gives a probe; `wait` is how long an entry waits for another's collection;
|
|
40
|
+
// `check` is how often `agy models` is asked, and `models` how long it is given.
|
|
41
|
+
export const LIMITS = { check: 3600_000, models: 8_000, collect: 40_000, wait: 45_000, cooldown: 5 * 60_000, poll: 200, version: 10_000 };
|
|
30
42
|
const SIGNED_OUT = -32000;
|
|
31
43
|
|
|
32
44
|
export class CatalogError extends Error {
|
|
@@ -55,16 +67,32 @@ async function askVersion(binary, timeout) {
|
|
|
55
67
|
return new Promise(resolve => execFile(binary, ['--version'], { encoding: 'utf8', timeout, env: { ...process.env, AGY_CLI_DISABLE_AUTO_UPDATE: 'true' } },
|
|
56
68
|
(error, stdout, stderr) => resolve(error ? null : versionOf({ stdout, stderr }))));
|
|
57
69
|
}
|
|
70
|
+
// `agy models`: the models it lists, `[id, name]` sorted by ID, from its lines `<id>\t<name>` (the rest of what it says,
|
|
71
|
+
// such as its progress line, goes to the standard error). A CatalogError for one that fails, times out or lists none.
|
|
72
|
+
export async function askModels(binary, timeout, cwd) {
|
|
73
|
+
return new Promise((resolve, reject) => execFile(binary, ['models'], { cwd, encoding: 'utf8', timeout,
|
|
74
|
+
env: { ...process.env, AGY_CLI_DISABLE_AUTO_UPDATE: 'true', NO_COLOR: '1' } }, (error, stdout, stderr) => {
|
|
75
|
+
if (error) {
|
|
76
|
+
const said = `${stderr ?? ''}`.trim().split('\n').filter(line => !/^Fetching available models/.test(line)).at(-1);
|
|
77
|
+
return reject(new CatalogError(`agy models 失败(${error.killed ? `超过 ${timeout / 1000} 秒` : error.code ?? error.signal})${said ? `:${said}` : ''}`));
|
|
78
|
+
}
|
|
79
|
+
const listed = `${stdout}`.split('\n').map(line => line.replace(/\r$/, '')).filter(line => line.includes('\t'))
|
|
80
|
+
.map(line => { const at = line.indexOf('\t'); return [line.slice(0, at).trim(), line.slice(at + 1).trim()]; }).filter(([id]) => id)
|
|
81
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
82
|
+
if (!listed.length) return reject(new CatalogError('agy models 没列出任何模型'));
|
|
83
|
+
resolve(listed);
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
58
86
|
const alive = pid => { try { process.kill(pid, 0); return true; } catch (error) { return error.code === 'EPERM'; } };
|
|
59
87
|
|
|
60
88
|
// `state`: the plugin's state directory; `binary`: agy's path. The clock, the file system (node:fs/promises), the process
|
|
61
|
-
// (node:child_process spawn) and how agy's version
|
|
89
|
+
// (node:child_process spawn) and how agy's version and models are asked are given for the tests.
|
|
62
90
|
export function createCatalog({ state, binary, home = homedir(), now = Date.now, fs = fsPromises, spawn = spawnProcess, version = askVersion,
|
|
63
|
-
limits: given = {} } = {}) {
|
|
91
|
+
models = askModels, limits: given = {} } = {}) {
|
|
64
92
|
const limits = { ...LIMITS, ...given };
|
|
65
93
|
const file = name => join(state, name);
|
|
66
94
|
const paths = state && { catalog: file('catalog-v1.json'), failure: file('catalog-v1.failure.json'),
|
|
67
|
-
stale: file('catalog-v1.stale.json'), log: file('catalog-v1.log'), cwd: file('catalog-cwd') };
|
|
95
|
+
stale: file('catalog-v1.stale.json'), check: file('catalog-v1.check.json'), log: file('catalog-v1.log'), cwd: file('catalog-cwd') };
|
|
68
96
|
const lockFile = n => file(`catalog-v1.lock.${n}`);
|
|
69
97
|
let child = null, holding = 0, aborted = false;
|
|
70
98
|
|
|
@@ -80,11 +108,37 @@ export function createCatalog({ state, binary, home = homedir(), now = Date.now,
|
|
|
80
108
|
s => ({ exists: true, size: s.size, mtimeMs: s.mtimeMs, ctimeMs: s.ctimeMs, ino: s.ino }), () => ({ exists: false }));
|
|
81
109
|
return { format: FORMAT, agy: { path: binary, version: await version(binary, limits.version) }, settings };
|
|
82
110
|
}
|
|
111
|
+
// Whether a catalog answers: 'fresh', 'check' when `agy models` is to be asked first, or false when it is to be collected.
|
|
83
112
|
async function usable(catalog, print) {
|
|
84
113
|
if (!catalog || catalog.format !== print.format || !same(catalog.agy, print.agy) || !same(catalog.settings, print.settings)) return false;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
if ((await readJson(paths.stale))?.collectedAt === catalog.collectedAt) return false;
|
|
115
|
+
// One with no list of agy models is checked at once, save within the cool-down of a check that failed.
|
|
116
|
+
const checked = await readJson(paths.check), last = checked?.collectedAt === catalog.collectedAt ? checked : null;
|
|
117
|
+
const since = last?.at ?? catalog.collectedAt;
|
|
118
|
+
const due = since + (last && !last.ok ? limits.cooldown : Array.isArray(catalog.agyModels) ? limits.check : 0);
|
|
119
|
+
// A clock that went back is due as well.
|
|
120
|
+
return now() >= since && now() < due ? 'fresh' : 'check';
|
|
121
|
+
}
|
|
122
|
+
const noteCheck = async (catalog, ok, reason) => {
|
|
123
|
+
await fs.writeFile(paths.check, JSON.stringify({ collectedAt: catalog.collectedAt, at: now(), ok, ...(reason && { reason }) })).catch(() => {});
|
|
124
|
+
};
|
|
125
|
+
// The check of a catalog: `{ catalog }` to answer with it, or `{ listed }` (agy models' list) to collect it again.
|
|
126
|
+
async function check(catalog) {
|
|
127
|
+
const started = now();
|
|
128
|
+
let listed;
|
|
129
|
+
try { await fs.mkdir(paths.cwd, { recursive: true }); listed = await models(binary, limits.models, paths.cwd); }
|
|
130
|
+
catch (error) {
|
|
131
|
+
await log({ event: 'check.failed', reason: error.message, ms: now() - started });
|
|
132
|
+
await noteCheck(catalog, false, error.message);
|
|
133
|
+
return { catalog };
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(catalog.agyModels) && same(listed, catalog.agyModels)) {
|
|
136
|
+
await noteCheck(catalog, true);
|
|
137
|
+
await log({ event: 'check.same', models: listed.length, ms: now() - started });
|
|
138
|
+
return { catalog };
|
|
139
|
+
}
|
|
140
|
+
await log({ event: 'check.changed', reason: Array.isArray(catalog.agyModels) ? 'agy models 列出的模型变了' : '目录里没有 agy models 的模型清单', ms: now() - started });
|
|
141
|
+
return { listed };
|
|
88
142
|
}
|
|
89
143
|
// The lock, or false while another live entry holds it (or took it first).
|
|
90
144
|
async function lock() {
|
|
@@ -166,11 +220,17 @@ export function createCatalog({ state, binary, home = homedir(), now = Date.now,
|
|
|
166
220
|
setTimeout(() => proc.kill('SIGKILL'), 800).unref();
|
|
167
221
|
}
|
|
168
222
|
}
|
|
169
|
-
// Collects and writes the catalog, all of it or nothing; a failure is remembered.
|
|
170
|
-
|
|
223
|
+
// Collects and writes the catalog, all of it or nothing; a failure is remembered. `listed`: agy models' list, when a check
|
|
224
|
+
// has just asked it; else it is asked here, and a catalog whose asking failed keeps none (and is collected again once a
|
|
225
|
+
// check gets one).
|
|
226
|
+
async function refresh(print, listed) {
|
|
171
227
|
const started = now();
|
|
172
228
|
try {
|
|
173
229
|
const catalog = await collect(print);
|
|
230
|
+
catalog.agyModels = listed ?? await models(binary, limits.models, paths.cwd).catch(async error => {
|
|
231
|
+
await log({ event: 'check.failed', reason: error.message });
|
|
232
|
+
return null;
|
|
233
|
+
});
|
|
174
234
|
const temporary = `${paths.catalog}.${process.pid}.${randomUUID()}.tmp`;
|
|
175
235
|
try { await fs.writeFile(temporary, JSON.stringify(catalog)); await fs.rename(temporary, paths.catalog); }
|
|
176
236
|
catch (error) { await fs.rm(temporary, { force: true }).catch(() => {}); throw new CatalogError(`写不了模型目录(${error.code ?? error.message}):${state}`); }
|
|
@@ -192,21 +252,32 @@ export function createCatalog({ state, binary, home = homedir(), now = Date.now,
|
|
|
192
252
|
async get() {
|
|
193
253
|
if (!state) throw new CatalogError('没有插件状态目录(CODA_PLUGIN_STATE),存不了模型目录');
|
|
194
254
|
const print = await fingerprint(), deadline = now() + limits.wait;
|
|
195
|
-
//
|
|
255
|
+
// `{ catalog }` if it is up to date, `{ check }` if agy models is to be asked first, null if it is to be collected; a
|
|
256
|
+
// failure still cooling down is thrown.
|
|
196
257
|
const settled = async () => {
|
|
197
|
-
const cached = await readJson(paths.catalog);
|
|
198
|
-
if (
|
|
258
|
+
const cached = await readJson(paths.catalog), status = await usable(cached, print);
|
|
259
|
+
if (status === 'fresh') return { catalog: cached };
|
|
260
|
+
if (status === 'check') return { check: cached };
|
|
199
261
|
const failure = await readJson(paths.failure);
|
|
200
262
|
if (failure && same(failure.fingerprint, print) && now() - failure.at < limits.cooldown)
|
|
201
263
|
throw new CatalogError(`读取 Antigravity 的模型目录失败,${Math.ceil((failure.at + limits.cooldown - now()) / 1000)} 秒后再试:${failure.reason}`);
|
|
202
264
|
return null;
|
|
203
265
|
};
|
|
204
266
|
for (;;) {
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
267
|
+
const found = await settled();
|
|
268
|
+
if (found?.catalog) return found.catalog;
|
|
207
269
|
if (await lock()) {
|
|
208
|
-
// Another entry may have collected, or failed to, between the reading and the lock.
|
|
209
|
-
try {
|
|
270
|
+
// Another entry may have collected, checked, or failed to, between the reading and the lock.
|
|
271
|
+
try {
|
|
272
|
+
const again = await settled();
|
|
273
|
+
if (again?.catalog) return again.catalog;
|
|
274
|
+
if (!again) return await refresh(print);
|
|
275
|
+
const checked = await check(again.check);
|
|
276
|
+
if (checked.catalog) return checked.catalog;
|
|
277
|
+
// A collection the check asked for that fails keeps the catalog there was, and the next check waits the cool-down.
|
|
278
|
+
try { return await refresh(print, checked.listed); }
|
|
279
|
+
catch (error) { await noteCheck(again.check, false, error.message); return again.check; }
|
|
280
|
+
} finally { await unlock(); }
|
|
210
281
|
}
|
|
211
282
|
if (now() >= deadline) throw new CatalogError(`等另一个进程读取模型目录超过 ${limits.wait / 1000} 秒`);
|
|
212
283
|
await delay(limits.poll);
|
package/package.json
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
"id": "antigravity",
|
|
4
4
|
"displayName": "Antigravity",
|
|
5
5
|
"description": "用 Antigravity CLI 跑会话",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.4.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"coda": 6
|
|
9
|
+
},
|
|
7
10
|
"categories": ["Agent"],
|
|
8
11
|
"contributes": {
|
|
9
12
|
"agents": [
|
|
@@ -29,21 +32,21 @@
|
|
|
29
32
|
"setupHint": "请在「资源」里为运行机添加 Antigravity。"
|
|
30
33
|
}
|
|
31
34
|
],
|
|
32
|
-
"
|
|
35
|
+
"protocolImplementations": [
|
|
33
36
|
{
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"signIn": {
|
|
39
|
-
"command": "a=\"$HOME/.local/bin/agy\"; [ -x \"$a\" ] || a=agy; BROWSER=/usr/bin/true NO_COLOR=1 exec \"$a\" acp --login",
|
|
40
|
-
"installed": "node \"$CODA_PLUGIN_PATH/scripts/setup.mjs\" --check",
|
|
41
|
-
"install": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\"",
|
|
42
|
-
"input": "authorizationCode",
|
|
43
|
-
"note": "登录保存在这台机器的系统钥匙串里,由 Antigravity CLI 自己续期;用 Google 账号确认,把授权页给的授权码贴回来。"
|
|
37
|
+
"kind": "coda/resource@1",
|
|
38
|
+
"commands": {
|
|
39
|
+
"sign-in": "scripts/sign-in.mjs",
|
|
40
|
+
"install": "scripts/setup.mjs"
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
],
|
|
44
|
+
"records": [
|
|
45
|
+
{
|
|
46
|
+
"kind": "coda/resource@1",
|
|
47
|
+
"command": "scripts/resource.mjs"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
47
50
|
"setup": {
|
|
48
51
|
"command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\""
|
|
49
52
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `coda/resource@1` record of the「Antigravity」type, printed once. No login here shows no resource (the type is then offered
|
|
3
|
+
// under「添加资源」); a login with the CLI gone, or older than the setup needs, is one row saying so, and the sign-in stays offered
|
|
4
|
+
// (it is how a machine without the CLI gets it). Shown with a login: the quota of each model group (the CLI's own read-only usage
|
|
5
|
+
// report, which opens no session and spends nothing) and the CLI's version. There is no cheap, reliable place for the email, so no
|
|
6
|
+
// account is shown. What cannot be read otherwise (a keychain that cannot be asked, a CLI that cannot say its version, a usage
|
|
7
|
+
// report that fails or has no quota) fails the command (exit 1, the reason on the last line of its standard error), which keeps
|
|
8
|
+
// the record Coda has.
|
|
9
|
+
import { agyBinary, asked, reading, signedIn } from './agy.mjs';
|
|
10
|
+
import { windows } from './quota.mjs';
|
|
11
|
+
import { MINIMUM, needed } from './setup.mjs';
|
|
12
|
+
|
|
13
|
+
// The whole reading gets 25 of the 30 seconds Coda allows, from here, so that it is printed, with the reason, rather than
|
|
14
|
+
// killed by Coda with nothing (agy.mjs `reading`: the version and the quota are asked what is left of it).
|
|
15
|
+
const deadline = Date.now() + 25_000;
|
|
16
|
+
const line = (text, max = 80) => [...text.replace(/\s+/g, ' ').trim()].slice(0, max).join('');
|
|
17
|
+
const fail = reason => { console.error(reason.replace(/\s+/g, ' ').trim()); process.exit(1); };
|
|
18
|
+
const problem = error => [{ name: 'Antigravity', values: [], buttons: [], error: line(error) }];
|
|
19
|
+
// Whether the CLI is installed: when it is there, runs and is not older than the setup needs.
|
|
20
|
+
const ready = binary => needed(binary, path => asked(path, Math.max(deadline - Date.now() - 1_000, 1))).action === 'none';
|
|
21
|
+
const print = (resources, installed) => console.log(JSON.stringify([{ key: 'account', spec: { type: 'account', title: 'Antigravity', resources,
|
|
22
|
+
signIn: { installed, installable: true, input: 'authorizationCode',
|
|
23
|
+
note: '登录保存在这台机器的系统钥匙串里,由 Antigravity CLI 自己续期;用 Google 账号确认,把授权页给的授权码贴回来。' } } }]));
|
|
24
|
+
|
|
25
|
+
const binary = agyBinary();
|
|
26
|
+
let login;
|
|
27
|
+
try { login = signedIn(); } catch (error) { fail(error.message); }
|
|
28
|
+
if (!login) { print([], ready(binary)); process.exit(0); }
|
|
29
|
+
if (!binary) { print(problem('这台机器上找不到 Antigravity CLI,请在运行机重新安装'), false); process.exit(0); }
|
|
30
|
+
const { version, tooOld, report, failure: why } = reading(binary, deadline, MINIMUM);
|
|
31
|
+
if (!version) fail(`读不出 Antigravity CLI 的版本(${binary})`);
|
|
32
|
+
if (why) fail(`暂时无法获取额度:${why}`);
|
|
33
|
+
const values = report ? windows(report) : [];
|
|
34
|
+
if (report && !values.length) fail('暂时无法获取额度:Antigravity CLI 没有给出额度');
|
|
35
|
+
// A reading lists 8 values at most: the version is always the last, after at most 7 of the quota.
|
|
36
|
+
print([{ name: 'Antigravity', values: [...values.slice(0, 7), { label: 'CLI 版本', value: version }], buttons: [],
|
|
37
|
+
...(tooOld ? { error: `Antigravity CLI 低于所需的 ${MINIMUM},请重新安装插件或在运行机运行 agy update` } : {}) }], !tooOld);
|
package/scripts/setup.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The plugin's setup (`contributes.setup`), which Coda runs on each machine when the user installs or updates the plugin, and the
|
|
3
|
+
// `install` operation of `coda/resource@1` (「安装」 on the resource page): it ends well once the machine can run the agent.
|
|
4
|
+
// Without an Antigravity CLI, Google's installer puts the latest in ~/.local/bin, where the agent looks first; one older than MINIMUM (the CLI the `agy acp` entry was checked against: the
|
|
4
5
|
// 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
6
|
// 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`.
|
|
7
|
+
// is never replaced: it is reported. Why the machine is not ready is said in one line on standard error; the result, when it is, is `{}`.
|
|
8
8
|
import { spawnSync } from 'node:child_process';
|
|
9
9
|
import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
10
10
|
import { homedir, tmpdir } from 'node:os';
|
|
@@ -28,7 +28,6 @@ export function needed(binary, run = asked) {
|
|
|
28
28
|
|
|
29
29
|
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
30
30
|
const before = needed(agyBinary());
|
|
31
|
-
if (process.argv[2] === '--check') process.exit(before.action === 'none' ? 0 : 1);
|
|
32
31
|
if (before.action === 'broken') { console.error(before.reason); process.exit(1); }
|
|
33
32
|
if (before.action !== 'none') {
|
|
34
33
|
// What the installer or the update prints goes to standard error with the rest of its story. The installer ends with
|
|
@@ -47,5 +46,6 @@ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToP
|
|
|
47
46
|
}
|
|
48
47
|
const after = needed(agyBinary());
|
|
49
48
|
if (after.action !== 'none') { console.error(after.reason); process.exit(1); }
|
|
50
|
-
console.
|
|
49
|
+
console.error(`Antigravity CLI ${after.version}`);
|
|
50
|
+
console.log('{}');
|
|
51
51
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The「Antigravity」resource type's sign-in (the `sign-in` operation of `coda/resource@1`): `agy acp --login`, which prints
|
|
3
|
+
// the Google authorization link and waits for the code the page gives. This reports the link (`coda progress`), asks for the
|
|
4
|
+
// code (`coda ask`), once, and gives it to the CLI, which does the exchange and keeps and renews the credentials in the
|
|
5
|
+
// keychain. What the CLI says after the code is given is not passed on: it may carry the code.
|
|
6
|
+
import { execFile, spawn } from 'node:child_process';
|
|
7
|
+
import { resolve } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
10
|
+
import { agyBinary } from './agy.mjs';
|
|
11
|
+
|
|
12
|
+
// The authorization link a stream printed: the first on a whole line (output arrives in pieces, and a link cut short is not
|
|
13
|
+
// the link), terminal hyperlinks included.
|
|
14
|
+
export function authorizationLink(output) {
|
|
15
|
+
const lines = stripVTControlCharacters(output.slice(0, output.lastIndexOf('\n') + 1));
|
|
16
|
+
try { return new URL(lines.match(/https:\/\/[^\s]+/)?.[0]); } catch { return null; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Coda's own command: what it prints, or why it failed (its last line).
|
|
20
|
+
const coda = (...args) => new Promise((done, fail) => execFile('coda', args, (error, stdout, stderr) =>
|
|
21
|
+
error ? fail(new Error(stderr.trim().split('\n').at(-1) || error.message)) : done(stdout)));
|
|
22
|
+
const lastLine = text => stripVTControlCharacters(text).split('\n').map(line => line.trim()).filter(Boolean).at(-1);
|
|
23
|
+
|
|
24
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
25
|
+
const binary = agyBinary();
|
|
26
|
+
if (!binary) { console.error('找不到 Antigravity CLI'); process.exit(1); }
|
|
27
|
+
const child = spawn(binary, ['acp', '--login'], { env: { ...process.env, BROWSER: '/usr/bin/true', NO_COLOR: '1' }, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
28
|
+
child.stdin.on('error', () => {});
|
|
29
|
+
// What each stream said, kept apart (a line is read from one stream only), and which spoke last.
|
|
30
|
+
const said = { stdout: '', stderr: '' };
|
|
31
|
+
let latest = 'stdout', url = null, reporting = Promise.resolve(), exited = false, submitted = false, failed = null;
|
|
32
|
+
// The first reason stays: what the CLI says when it is ended for it is not the reason.
|
|
33
|
+
const fail = message => { failed ??= message; child.kill(); };
|
|
34
|
+
// Without a link in 20 seconds, the login is over with what the CLI said last.
|
|
35
|
+
const silent = setTimeout(() => fail(lastLine(said[latest]) || '登录没有完成,请重新登录。'), 20_000);
|
|
36
|
+
// What the CLI says is kept until the code is given to it: after that it may carry the code.
|
|
37
|
+
const heard = name => chunk => {
|
|
38
|
+
if (submitted) return;
|
|
39
|
+
said[name] = (said[name] + chunk).slice(-8000); latest = name;
|
|
40
|
+
if (url) return;
|
|
41
|
+
url = authorizationLink(said[name]);
|
|
42
|
+
if (!url) return;
|
|
43
|
+
clearTimeout(silent);
|
|
44
|
+
reporting = coda('progress', JSON.stringify({ url: url.href })).catch(error => fail(error.message));
|
|
45
|
+
reporting.then(async () => {
|
|
46
|
+
// A CLI that has ended is not asked for a code: its last line is the reason.
|
|
47
|
+
if (failed || exited) return;
|
|
48
|
+
const { code } = JSON.parse(await coda('ask', JSON.stringify({ input: 'authorizationCode' })));
|
|
49
|
+
submitted = true;
|
|
50
|
+
child.stdin.write(`${code.trim()}\n`);
|
|
51
|
+
}).catch(error => fail(error.message));
|
|
52
|
+
};
|
|
53
|
+
for (const name of ['stdout', 'stderr']) child[name].setEncoding('utf8').on('data', heard(name));
|
|
54
|
+
child.on('error', () => { failed ??= 'Antigravity CLI 没能启动'; });
|
|
55
|
+
child.on('exit', () => { exited = true; });
|
|
56
|
+
// Coda ends the whole group; one ended alone takes its CLI along.
|
|
57
|
+
for (const signal of ['SIGTERM', 'SIGINT']) process.on(signal, () => { child.kill(); process.exit(1); });
|
|
58
|
+
child.on('close', async code => {
|
|
59
|
+
clearTimeout(silent);
|
|
60
|
+
await reporting;
|
|
61
|
+
if (code === 0 && !failed) { console.log('{}'); process.exit(0); }
|
|
62
|
+
console.error(failed ?? (submitted ? null : lastLine(said[latest])) ?? '登录没有完成,请重新登录。');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
65
|
+
}
|
package/scripts/resources.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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) } : {}) }] });
|