@coda-console/antigravity 1.3.1 → 1.3.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/README.md +5 -2
- package/agent/catalog.mjs +93 -22
- package/agent/entry.mjs +8 -0
- package/agent/retry.mjs +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
把 [Google Antigravity](https://antigravity.google/cli) 的 Agent 接进 Coda。清单经一个薄转发入口(`agent/entry.mjs`)启动运行机上的 `agy acp`(Antigravity CLI 的 ACP 服务),
|
|
4
4
|
先找 `~/.local/bin/agy`,没有再用 PATH。每个会话一个进程,不登记等待项。
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
入口改四处,其余消息原样双向转发。第一处:把 `initialize` 答复里的 `additionalDirectories` 能力去掉,Coda 就不再给它传附加目录;
|
|
7
7
|
`session/new`、`session/load`、`session/resume` 里若仍带 `additionalDirectories` 也删掉。原因:agy 1.5.9 收到附加目录后,
|
|
8
8
|
没给 Cwd 的命令默认跑在**字典序最前的附加根**,而不是会话的工作副本(实测规律,不是上游的保证;数组顺序、`session/load` 都不改变它);
|
|
9
9
|
不传附加目录时命令就在工作副本里跑。
|
|
10
10
|
|
|
11
11
|
第二处是虚拟模式 `full`(「全部放行」),见下面「全部放行」一节。第三处是配置探测:入口在 `initialize` 声明 `_meta.coda.probe`,
|
|
12
12
|
带探测标记的 `session/new` 由入口用本机的目录缓存应答,不转给 agy,见「已知限制」的「配置探测」。
|
|
13
|
+
第四处:agy 内部重试模型请求时会发一条 `agent_message_chunk`,整段文本形如 `⚠ API error (attempt 1): request failed: stream idle timeout (5m0s): context deadline exceeded`,
|
|
14
|
+
Coda 会把它存成回复正文,像答到一半出错,其实这一轮还在跑。入口不转发这一种(整段去掉首尾空白后恰为单行此格式),原文写到插件自己的 stderr;
|
|
15
|
+
多行或夹在正文里的同样字样照常转发。最终失败怎样结束这一轮未查到实例,入口不改它(不改报 `session/prompt` 错误)。
|
|
13
16
|
|
|
14
17
|
需要带会话指令兜底的 Coda(2026-11-13 部署版,coda#2500)或更新版本;旧版 Coda 不会给 Antigravity 送入会话指令。
|
|
15
18
|
|
|
@@ -86,7 +89,7 @@
|
|
|
86
89
|
| 额度耗尽 | 没有真实样本,不做失败分类,Coda 只看到 Antigravity 给的错误文字 |
|
|
87
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 的无桌面机器,它带错误信息退出)时,资源页读数失败、保留上次的显示,首次读取就没有可保留的,也就无法从资源页添加:这样的机器在终端里运行 `agy acp --login` 登录 |
|
|
88
91
|
| 第三方模型 | 账号里的 Claude、GPT-OSS 未实测 |
|
|
89
|
-
| 配置探测 | 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 每次探测仍各建一条空会话 |
|
|
90
93
|
| 并发进程 | 不加 `--process-per-session`:Coda 交给 Agent 的 MCP 服务器都是 stdio,官方只对 HTTP MCP 要求这个参数 |
|
|
91
94
|
|
|
92
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/agent/entry.mjs
CHANGED
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
// the catalog, which one that differs marks to be collected again.
|
|
13
13
|
// 4. When agy ends on its own (not as Coda's input closing or a signal to this process stops it) with a non-zero exit code, a
|
|
14
14
|
// signal or a prompt unanswered, the log and the prompts still waiting say how (exit.mjs).
|
|
15
|
+
// 5. agy's notice that it retries a model request ("⚠ API error (attempt N): ...", an agent_message_chunk) is not passed on: Coda
|
|
16
|
+
// would keep it as the reply's text, while the turn goes on. The entry writes it to its own stderr instead (retry.mjs).
|
|
15
17
|
import { spawn } from 'node:child_process';
|
|
16
18
|
import { agyBinary } from '../scripts/agy.mjs';
|
|
17
19
|
import { createCatalog } from './catalog.mjs';
|
|
18
20
|
import { PREFIX, Probes, probeMark } from './probe.mjs';
|
|
19
21
|
import { describeExit, endedError } from './exit.mjs';
|
|
22
|
+
import { retryNotice } from './retry.mjs';
|
|
20
23
|
|
|
21
24
|
const binary = agyBinary() ?? 'agy';
|
|
22
25
|
const agy = spawn(binary, ['acp'], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
@@ -123,6 +126,11 @@ relay(agy.stdout, process.stdout, message => {
|
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
const update = params?.update;
|
|
129
|
+
const notice = retryNotice(message);
|
|
130
|
+
if (notice !== null) {
|
|
131
|
+
process.stderr.write(`agy 重试模型请求,提示不转给 Coda:${notice.trim()}\n`);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
126
134
|
if (method === 'session/update' && update?.sessionUpdate === 'current_mode_update') {
|
|
127
135
|
if (!full.has(params.sessionId)) return;
|
|
128
136
|
if (update.currentModeId === 'default') update.currentModeId = 'full'; else full.delete(params.sessionId);
|
package/agent/retry.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// agy retries a failed model request inside the turn and says so with an agent_message_chunk, "\n⚠ API error (attempt N): <why>\n"
|
|
2
|
+
// (agy 1.5.9: the ACP layer writes "\n⚠ %s\n" around the Go format "API error (attempt %d): %v"). Coda would keep it as the
|
|
3
|
+
// reply's text, which then looks like an answer that broke off, while the turn goes on. Only a chunk that is exactly that one line
|
|
4
|
+
// is the notice; text with anything else in it (more lines, or around other text) is the answer's and goes on.
|
|
5
|
+
const NOTICE = /^⚠ API error \(attempt [1-9]\d*\): [^\r\n\u2028\u2029]+$/;
|
|
6
|
+
|
|
7
|
+
// The text of an agent message that is agy's retry notice, or null for any other message.
|
|
8
|
+
export function retryNotice(message) {
|
|
9
|
+
const update = message?.params?.update;
|
|
10
|
+
if (message?.method !== 'session/update' || update?.sessionUpdate !== 'agent_message_chunk' || update.content?.type !== 'text') return null;
|
|
11
|
+
const text = update.content.text;
|
|
12
|
+
return typeof text === 'string' && NOTICE.test(text.trim()) ? text : null;
|
|
13
|
+
}
|