@coda-console/antigravity 1.1.0 → 1.2.1

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 CHANGED
@@ -3,11 +3,13 @@
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
- 入口只改两处,其余消息原样双向转发:把 `initialize` 答复里的 `additionalDirectories` 能力去掉,Coda 就不再给它传附加目录;
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
+ 第二处是虚拟模式 `full`(「全部放行」),见下面「全部放行」一节。
12
+
11
13
  需要带会话指令兜底的 Coda(2026-11-13 部署版,coda#2500)或更新版本;旧版 Coda 不会给 Antigravity 送入会话指令。
12
14
 
13
15
  要求 Antigravity CLI **1.5.9 及以上**:`agy acp` 从 1.5.0 才有,Auto 模式与模式保持的修复在 1.5.4,上下文用量在 1.5.8;
@@ -57,8 +59,8 @@
57
59
  | 设置 | 来源 |
58
60
  | --- | --- |
59
61
  | 模型、思考档位 | 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
+ | 工作模式 | `default`、`accept-edits`、`auto`、`plan`,加上插件虚拟的 `full`「全部放行」(「工作模式」,没选时用 Antigravity 自己的默认);清单的 `modes.auto` 指向 `auto`、`modes.full` 指向 `full`,供委派子会话与流程步骤的「自动审批」「全部放行」使用 |
63
+ | 审批 | `default` 与 `accept-edits` 下跑命令发 `session/request_permission`,选项是 `allow`(allow_once)与 `deny`(reject_once),Mac 与 iPhone 出审批卡片;`auto` 对安全命令不再询问;`full` 下一律不出卡片 |
62
64
  | 恢复 | Antigravity 声明 `loadSession`,后端或托管重启后用 `session/load` 接着聊 |
63
65
  | skills | 读工作副本的 `.agents/skills`(清单的 `skillsDir`) |
64
66
  | 上下文占用、标题 | Antigravity 报 `usage_update` 与会话标题更新 |
@@ -69,15 +71,16 @@
69
71
 
70
72
  | 功能 | 情况 |
71
73
  | --- | --- |
72
- | Auto 的审批 | Auto 对不可逆操作仍会请求审批:无人值守的子会话遇到会停下等人。官方文档说明 Auto 需要终端沙箱,企业账号与沙箱不可用的机器可能没有 Auto |
73
- | 全部放行 | 没有:Antigravity 没有原生的「全部放行」模式(`full`、`yolo` 回 -32602),清单不写 `modes.full` |
74
+ | Auto 的审批 | Auto 对不可逆操作仍会请求审批:无人值守的子会话遇到会停下等人,要不停就选「全部放行」。官方文档说明 Auto 需要终端沙箱,企业账号与沙箱不可用的机器可能没有 Auto |
75
+ | 全部放行 | 插件自己实现,Antigravity 没有这个模式(`full`、`yolo` 回 -32602,按会话的配置项和 `_meta` 也不起效)。选了它,入口给 agy 的底层模式是 `default`,之后 agy 发来的每条 `session/request_permission`,入口直接答复 `allow_once` 的选项,不转给 Coda,所以 Mac 与 iPhone 都不出审批卡片;用 `allow_once` 而不是 `allow_always`,免得把放行写进 agy 的项目权限。选项里没有 `allow_once` 就照常转给 Coda。会话中途可以切进切出,当场生效、不重启进程;切到别的模式即停止代答,agy 自己报出别的模式(例如退出 plan)也算离开。agy 拒绝切换时,会话不进入全部放行。切换那一瞬间已在路上的审批不处理。记录在入口进程里,每个会话一个进程,重启后用 `session/load` 接着聊时回到 `default`,要再选一次。它和 agy 的 `--dangerously-skip-permissions`、settings 里的 `toolPermission: always-proceed` 不同:那两个只在进程启动时读,按进程或整台机器生效,插件都不用,也不碰你的 `settings.json` |
74
76
  | 会话指令 | Antigravity 只认私有的 `_meta.antigravity.systemPrompt`,不认 ACP 标准字段;插件不处理它,由 Coda 把指令作为单独一段放在新会话第一次非斜杠命令的用户输入前面,分量不如系统提示词 |
75
77
  | 插话 | 不声明:Antigravity 的原生插话会提前结束旧一轮的回复,由 Coda 停下这一轮再发出新消息 |
76
78
  | 额度的口径 | 报告按模型组给额度:同组模型共享每周与 5 小时限额,不是每个模型各算一份;报告里没有套餐名。第一次在某个目录运行 `/usage` 时,CLI 会在 `implicit/` 下留一个小文件;插件固定在系统临时目录运行,之后复用,不新增会话与项目记录 |
77
79
  | 等待项登记 `_coda/wait` | 不登记,会话底部不列它在等什么 |
78
80
  | Plan 模式 | 产出计划文件并要求审阅,审阅前不动手;plan 下只读的 shell 命令也按权限规则请求审批,这是 agy 的设计 |
81
+ | 删除会话 | 不支持:agy 1.5.9 的 ACP 没有 `session/delete`(回 -32601),`session/close` 也不删除,所以 Coda 探测模型和模式时会在 agy 历史里留下零步的空会话。插件不自己删文件:那会绕过 agy 的取消、摘要缓存和搜索索引,agy 运行中删也不安全;等上游提供删除接口再接 |
79
82
  | 附加目录 | 不交给 Antigravity:读工作副本外的附件、会话临时目录、skill 真实文件可能要审批;`.agents/skills` 的链接照旧 |
80
- | Coda 的 MCP 工具在 auto 下也要审批 | 无人值守的子会话、流程步骤调用它们会停下。放行写法是在运行机的 `~/.gemini/antigravity-cli/settings.json` 里加 `{"permissions": {"allow": ["mcp(coda/*)"]}}`,出处是官方[权限文档](https://antigravity.google/docs/permissions/);插件不替你改这个文件 |
83
+ | Coda 的 MCP 工具在 auto 下也要审批 | 无人值守的子会话、流程步骤调用它们会停下;「全部放行」下不会。要在 auto 下放行,写法是在运行机的 `~/.gemini/antigravity-cli/settings.json` 里加 `{"permissions": {"allow": ["mcp(coda/*)"]}}`,出处是官方[权限文档](https://antigravity.google/docs/permissions/);插件不替你改这个文件 |
81
84
  | 额度耗尽 | 没有真实样本,不做失败分类,Coda 只看到 Antigravity 给的错误文字 |
82
85
  | 没有桌面会话的 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
86
  | 第三方模型 | 账号里的 Claude、GPT-OSS 未实测 |
@@ -90,5 +93,5 @@ node bin/check.mjs plugins/antigravity # 握手:protocolVersion 1
90
93
  node bin/check.mjs plugins/antigravity --live # 一轮:会话指令、回复、取消、session/load
91
94
  ```
92
95
 
93
- 然后在 Coda 里:发一句话收到回复;选 plan 出计划文件并停在审阅;选 default 跑一个要审批的命令,Mac 与 iPhone 都出卡片;选 auto 跑安全命令不再询问;
96
+ 然后在 Coda 里:发一句话收到回复;选 plan 出计划文件并停在审阅;选 default 跑一个要审批的命令,Mac 与 iPhone 都出卡片;选 auto 跑安全命令不再询问;选「全部放行」跑 `rm -rf`、写工作区外文件、调 MCP 工具都不出卡片,再切回 default 又出卡片;
94
97
  重启后端后接着聊(`session/load`);资源页登录一遍(贴授权码)。
package/agent/entry.mjs CHANGED
@@ -1,34 +1,101 @@
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.
1
+ // Starts `agy acp` and relays its ACP both ways, line for line, with two changes.
2
+ // 1. Coda gives it no additional directories: agy 1.5.9 runs a command with no Cwd in the lexicographically first
3
+ // additional root, not in the session's cwd (observed, not promised upstream). The `initialize` answer loses the
4
+ // additionalDirectories capability (Coda only passes the directories to an agent that declares it), and a session
5
+ // request loses `additionalDirectories` should one come anyway.
6
+ // 2. A virtual mode `full` ("allow everything"). agy has no such mode and cannot change its permission policy once it
7
+ // runs, so a session in `full` runs in agy's `default` and the entry answers each of its permission requests itself
8
+ // with the allow_once option. Switching in and out is rewritten on the way: Coda sees `full` as an ordinary mode.
5
9
  import { spawn } from 'node:child_process';
6
10
  import { agyBinary } from '../scripts/agy.mjs';
7
11
 
8
12
  const agy = spawn(agyBinary() ?? 'agy', ['acp'], { stdio: ['pipe', 'pipe', 'inherit'] });
9
13
  const initializing = new Set();
14
+ const sessionRequests = new Set();
15
+ 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
16
+ const full = new Set(); // sessions in `full`
17
+ const FULL_NAME = '全部放行';
18
+ const FULL_DESCRIPTION = 'Approve everything without asking.';
10
19
  let stopping = false;
11
20
 
12
21
  // 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.
22
+ // A line that is not a JSON object passes through as it is. `change` returns false for a message that is not forwarded.
14
23
  function relay(from, to, change) {
15
24
  let rest = '';
16
25
  const take = text => {
17
26
  const lines = (rest + text).split('\n'); rest = lines.pop();
18
27
  for (const line of lines) {
19
28
  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`);
29
+ if (message && typeof message === 'object' && !Array.isArray(message)) { if (change(message) !== false) to.write(`${JSON.stringify(message)}\n`); } else to.write(`${line}\n`);
21
30
  }
22
31
  };
23
32
  from.setEncoding('utf8').on('data', take).on('end', () => take('\n'));
24
33
  }
34
+
35
+ // The mode option of a configOptions list gains `full`; a session in `full` shows it as the current value, and a mode of
36
+ // agy's own other than `default` ends it.
37
+ function fixConfigOptions(sessionId, configOptions) {
38
+ const mode = Array.isArray(configOptions) ? configOptions.find(option => option?.id === 'mode' && Array.isArray(option.options)) : null;
39
+ if (!mode) return;
40
+ mode.options.push({ value: 'full', name: FULL_NAME, description: FULL_DESCRIPTION });
41
+ if (!full.has(sessionId)) return;
42
+ if (mode.currentValue === 'default') mode.currentValue = 'full'; else full.delete(sessionId);
43
+ }
44
+
45
+ // The session is in `full` from the moment the switch is sent, and back where it was if agy answers with an error.
46
+ function switchMode(message, to) {
47
+ const { sessionId } = message.params;
48
+ configRequests.set(message.id, { sessionId, was: full.has(sessionId) });
49
+ if (to === 'full') full.add(sessionId); else full.delete(sessionId);
50
+ }
51
+
25
52
  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;
53
+ const { method, params, id } = message;
54
+ if (method === 'initialize' && 'id' in message) initializing.add(id);
55
+ if (['session/new', 'session/load', 'session/resume'].includes(method)) { delete params?.additionalDirectories; sessionRequests.add(id); }
56
+ if (method === 'session/set_mode' && typeof params?.sessionId === 'string') {
57
+ switchMode(message, params.modeId);
58
+ if (params.modeId === 'full') params.modeId = 'default';
59
+ }
60
+ if (method === 'session/set_config_option' && typeof params?.sessionId === 'string') {
61
+ if (params.configId !== 'mode') configRequests.set(id, { sessionId: params.sessionId });
62
+ else {
63
+ switchMode(message, params.value);
64
+ if (params.value === 'full') params.value = 'default';
65
+ }
66
+ }
28
67
  });
29
68
  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;
69
+ const { method, params, id } = message;
70
+ if (!method) {
71
+ if (initializing.delete(id)) {
72
+ for (const key of ['sessionCapabilities', 'session_capabilities']) delete message.result?.agentCapabilities?.[key]?.additionalDirectories;
73
+ }
74
+ if (sessionRequests.delete(id) && message.result) {
75
+ const { modes } = message.result;
76
+ if (Array.isArray(modes?.availableModes)) modes.availableModes.push({ id: 'full', name: FULL_NAME, description: FULL_DESCRIPTION });
77
+ fixConfigOptions(message.result.sessionId, message.result.configOptions);
78
+ }
79
+ const config = configRequests.get(id);
80
+ if (config) {
81
+ configRequests.delete(id);
82
+ if (!message.error) fixConfigOptions(config.sessionId, message.result?.configOptions);
83
+ else if (config.was) full.add(config.sessionId);
84
+ else if (config.was === false) full.delete(config.sessionId);
85
+ }
86
+ return;
87
+ }
88
+ const update = params?.update;
89
+ if (method === 'session/update' && update?.sessionUpdate === 'current_mode_update') {
90
+ if (!full.has(params.sessionId)) return;
91
+ if (update.currentModeId === 'default') update.currentModeId = 'full'; else full.delete(params.sessionId);
92
+ } else if (method === 'session/update' && update?.sessionUpdate === 'config_option_update') {
93
+ fixConfigOptions(params.sessionId, update.configOptions);
94
+ } else if (method === 'session/request_permission' && full.has(params?.sessionId)) {
95
+ const allow = params.options?.find(option => option?.kind === 'allow_once');
96
+ if (!allow) return;
97
+ agy.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, result: { outcome: { outcome: 'selected', optionId: allow.optionId } } })}\n`);
98
+ return false;
32
99
  }
33
100
  });
34
101
  const stop = () => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "antigravity",
4
4
  "displayName": "Antigravity",
5
5
  "description": "用 Antigravity CLI 跑会话",
6
- "version": "1.1.0",
6
+ "version": "1.2.1",
7
7
  "categories": ["Agent"],
8
8
  "contributes": {
9
9
  "agents": [
@@ -19,7 +19,8 @@
19
19
  "title": "工作模式",
20
20
  "unset": "Agent 默认",
21
21
  "auto": "auto",
22
- "note": "Auto 对不可逆操作与 Coda 的 MCP 工具仍会询问;权限沿用运行机的 ~/.gemini/antigravity-cli/settings.json,可在那里放行。"
22
+ "full": "full",
23
+ "note": "全部放行由插件代答审批,底层跑 default;Auto 对不可逆操作与 MCP 工具仍会询问。其余权限沿用运行机 ~/.gemini/antigravity-cli/settings.json。"
23
24
  },
24
25
  "skillsDir": ".agents/skills",
25
26
  "configFiles": [