@coda-console/antigravity 1.3.0 → 1.3.2
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 -1
- package/agent/entry.mjs +26 -2
- package/agent/exit.mjs +12 -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
|
|
package/agent/entry.mjs
CHANGED
|
@@ -10,13 +10,23 @@
|
|
|
10
10
|
// `_meta.coda.probe: true` opens a session of this connection alone, answered from the catalog and never sent to agy; so
|
|
11
11
|
// does every request about a session of the `coda-probe:` namespace. What real sessions say of their options is held to
|
|
12
12
|
// the catalog, which one that differs marks to be collected again.
|
|
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
|
+
// 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).
|
|
13
17
|
import { spawn } from 'node:child_process';
|
|
14
18
|
import { agyBinary } from '../scripts/agy.mjs';
|
|
15
19
|
import { createCatalog } from './catalog.mjs';
|
|
16
20
|
import { PREFIX, Probes, probeMark } from './probe.mjs';
|
|
21
|
+
import { describeExit, endedError } from './exit.mjs';
|
|
22
|
+
import { retryNotice } from './retry.mjs';
|
|
17
23
|
|
|
18
24
|
const binary = agyBinary() ?? 'agy';
|
|
19
|
-
const agy = spawn(binary, ['acp'], { stdio: ['pipe', 'pipe', '
|
|
25
|
+
const agy = spawn(binary, ['acp'], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
26
|
+
let stderr = '';
|
|
27
|
+
agy.stderr.on('data', chunk => { process.stderr.write(chunk); stderr = (stderr + chunk).slice(-2048); });
|
|
28
|
+
// The ids of the prompts Coda has asked and agy has not answered yet.
|
|
29
|
+
const prompts = new Set();
|
|
20
30
|
const initializing = new Set();
|
|
21
31
|
const sessionRequests = new Set();
|
|
22
32
|
const configRequests = new Map(); // request id -> { sessionId, was }: a set_config_option, whose answer lists the options; `was` for a mode switch, undone if agy refuses it
|
|
@@ -76,6 +86,7 @@ relay(process.stdin, agy.stdin, message => {
|
|
|
76
86
|
if ('id' in message) answer(id, probes.handle(method, params));
|
|
77
87
|
return false;
|
|
78
88
|
}
|
|
89
|
+
if (method === 'session/prompt' && 'id' in message) prompts.add(id);
|
|
79
90
|
if (method === 'initialize' && 'id' in message) initializing.add(id);
|
|
80
91
|
if (['session/new', 'session/load', 'session/resume'].includes(method)) { delete params?.additionalDirectories; sessionRequests.add(id); }
|
|
81
92
|
if (method === 'session/set_mode' && typeof params?.sessionId === 'string') {
|
|
@@ -93,6 +104,7 @@ relay(process.stdin, agy.stdin, message => {
|
|
|
93
104
|
relay(agy.stdout, process.stdout, message => {
|
|
94
105
|
const { method, params, id } = message;
|
|
95
106
|
if (!method) {
|
|
107
|
+
prompts.delete(id);
|
|
96
108
|
if (initializing.delete(id) && message.result?.agentCapabilities) {
|
|
97
109
|
const capabilities = message.result.agentCapabilities;
|
|
98
110
|
for (const key of ['sessionCapabilities', 'session_capabilities']) delete capabilities[key]?.additionalDirectories;
|
|
@@ -114,6 +126,11 @@ relay(agy.stdout, process.stdout, message => {
|
|
|
114
126
|
return;
|
|
115
127
|
}
|
|
116
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
|
+
}
|
|
117
134
|
if (method === 'session/update' && update?.sessionUpdate === 'current_mode_update') {
|
|
118
135
|
if (!full.has(params.sessionId)) return;
|
|
119
136
|
if (update.currentModeId === 'default') update.currentModeId = 'full'; else full.delete(params.sessionId);
|
|
@@ -133,6 +150,13 @@ const stop = () => {
|
|
|
133
150
|
};
|
|
134
151
|
agy.stdin.on('error', () => {});
|
|
135
152
|
agy.on('error', () => process.exit(1));
|
|
136
|
-
agy.on('close', code =>
|
|
153
|
+
agy.on('close', (code, signal) => {
|
|
154
|
+
if (!stopping && (code !== 0 || prompts.size)) {
|
|
155
|
+
const message = describeExit({ code, signal, stderr });
|
|
156
|
+
process.stderr.write(`${message}\n`);
|
|
157
|
+
for (const id of prompts) answer(id, { error: endedError(message) });
|
|
158
|
+
}
|
|
159
|
+
process.stdout.write('', () => process.exit(stopping ? 0 : code ?? 1));
|
|
160
|
+
});
|
|
137
161
|
process.stdin.on('end', stop);
|
|
138
162
|
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) process.once(signal, stop);
|
package/agent/exit.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// How `agy acp` ended, as the plugin's log and the turns it leaves waiting say it: its exit code or the signal that killed it,
|
|
2
|
+
// and the last lines it wrote to stderr. Told when the process ends on its own with a prompt unanswered, or with a non-zero exit code or a signal.
|
|
3
|
+
export function describeExit({ code, signal, stderr }) {
|
|
4
|
+
const tail = stderr.trim().split('\n').slice(-5).join('\n').slice(-1000);
|
|
5
|
+
return `Antigravity 进程意外退出(${signal ? `被信号 ${signal} 终止` : `退出码 ${code}`})${tail ? `,stderr 末尾:\n${tail}` : ''}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// The error that ends a prompt as the process ends (docs/agent-protocol.md「原生会话已结束」): the category tells Coda the native
|
|
9
|
+
// session is over, not that the service failed. `input` is not written: nothing the
|
|
10
|
+
// process said proves this prompt was read, and Coda then resumes by checking first, with the whole original input.
|
|
11
|
+
export const endedError = message => ({ code: -32603, message,
|
|
12
|
+
data: { _meta: { coda: { failure: { kind: 'session_ended' } } } } });
|
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
|
+
}
|