dsh-plugin-antigravity-acp 0.0.0-stage → 0.7.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 dsh-plugin-antigravity-acp contributors
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,55 @@
1
- # Temporary Holding Version
1
+ # dsh-plugin-antigravity-acp (v0.7.0)
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 CLI (`agy acp`)** 标准 **ACP(Agent Client Protocol)** 协议,将 Google Antigravity 原生接入 **DeepSeek Harness (DSH)**,并内置 **`agy-fast`** 批量加速工具。
4
+
5
+ **零命令、开箱即用、跨平台(Windows / macOS / Linux)**:安装插件后,所有操作均在 DSH **设置 -> Antigravity ACP** 图形界面中点击完成。
6
+
7
+ ## 核心特性
8
+
9
+ 1. **基于官方 ACP 协议与隔离凭据设计**
10
+ - 不内置任何第三方 OAuth Client ID,不抓包、不提取或反代任何客户端私有 Token。
11
+ - 全部 Google 账号认证与推理均由 Google 官方签名的 `agy acp` 进程本地执行,并使用独立隔离的 Profile 目录。
12
+ - *说明:本项目为社区第三方集成插件,使用前请自行遵守 Google Antigravity 服务条款与使用配额政策。*
13
+ 2. **纯图形化设置页(`设置 -> Antigravity ACP`)**
14
+ - **安装官方 CLI**:一键从 Google 官方公开 CDN 下载并校验 SHA-512 安装官方 `agy`(无需手动装 CLI)。
15
+ - **多 Google 账号管理**:支持新增多个独立隔离账号、一键切换使用、直显每个账号的套餐等级(如 `Google AI Pro`)与今日 Token 用量。
16
+ - **模型列表**:可视化查看账号下所有主模型(`Gemini 4 Neon`、`Gemini 4 Carbon`、`Claude Opus 5.5` 等)与 Thinking Level 档位。
17
+ - **连接与高级**:查看常驻进程与多轮会话缓存命中统计,一键启停 `agy-fast` 批量加速工具。
18
+ 3. **DSH 原生状态栏统计 + 底部用量胶囊**
19
+ - 完整透传官方 `agy acp` 逐轮精确 Token 用量,原生点亮 DSH 底部状态栏的 **`tok/s`、`总 Token · 缓存命中 %`、`◯ 上下文占比环`**。
20
+ - 在对话底部状态栏新增轻量「**账号套餐 + 今日用量**」胶囊(仅在选中 `antigravity-acp` 模型时显示,切到其他供应商自动隐藏),点击可查看当前账号今日/累计明细并支持清零统计。
21
+ 4. **DSH 原生模型选择器 + 高缓存命中 + 多模态看图 + 复杂编排**
22
+ - 通过官方原生 `session/new._meta.antigravity.systemPrompt.append` 注入宿主协议,历史与最新轮次清晰隔离,图片附件精确限定于当前轮次。
23
+ - 支持多轮热 ACP Session 增量复用(动态时间戳归一化保护 KV Cache 命中率)、重启后 `session/resume` 跨进程恢复、新对话后台零消耗空白会话预热与 `--process-per-session` 窗口隔离。
24
+ - 支持原生图片附件多模态看图、DSH 复杂多轮工具编排(含 Markdown 代码块防误触发与畸形 JSON 容错),以及配额限流/网络异常的友好中文提示。
25
+ 5. **内置 `agy-fast` 批量加速工具(开箱即用)**
26
+ - 内置 5 个批量加速工具(`agy_fast_batch_search`、`agy_fast_apply_edits`、`agy_fast_quick_outline`、`agy_fast_read_slices`、`agy_fast_run_checks`),所有 DSH 模型均可调用,显著减少多轮搜索、编辑与检查耗时。
27
+
28
+ ## 安装方式
29
+
30
+ ### 方式一:通过 DSH 插件市场图形化一键安装(推荐)
31
+ 1. 在 DSH Desktop 打开 **插件 → 实验性插件**,开启 **自定义插件索引**。
32
+ 2. 切换到 **发现** 标签页,点击 **添加索引源**,填入以下地址:
33
+ ```text
34
+ https://raw.githubusercontent.com/ayu-node/dsh-plugin-antigravity-acp/main/market-index.json
35
+ ```
36
+ 3. 搜索 **Antigravity ACP** 并点击 **安装**,重启后在 **设置 -> Antigravity ACP** 中即可一键安装官方 CLI 并登录 Google 账号。
37
+
38
+ ### 方式二:通过 DSH CLI 一键安装
39
+ ```bash
40
+ dsh plugin --profile desktop add github:ayu-node/dsh-plugin-antigravity-acp
41
+ ```
42
+ 安装完成后重启 DSH Desktop,打开 **设置 -> Antigravity ACP** 即可完成官方 CLI 安装与 Google 账号登录。
43
+
44
+ ### 方式三:手动链接本地仓库
45
+ 将本仓库链接到 DSH profile 的 `package.json`(`dependencies` + `dsh.profile.bundles`),重启 DSH Desktop 即可在 **设置 -> Antigravity ACP** 中使用。
46
+
47
+ ## 本地测试
48
+
49
+ ```bash
50
+ npm test
51
+ ```
52
+
53
+ ## 开源致谢
54
+
55
+ - 内置的 `vendor/agy-fast/mcp-server.mjs` 来自开源项目 [INK-Q/agy-fast](https://github.com/INK-Q/agy-fast)(MIT License,版权归原作者 inkwhite 所有,原许可证保留于 `vendor/agy-fast/LICENSE`)。
@@ -0,0 +1,6 @@
1
+ # dsh-plugin-antigravity-acp 挂载补丁:
2
+ # 将 Antigravity ACP 子 Agent 工具、/agy 斜杠命令与系统提示词注入到 DSH profile 中。
3
+ - insert:
4
+ - id: antigravity-acp
5
+ name: dsh-plugin-antigravity-acp
6
+ config: {}
@@ -0,0 +1,298 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { defaultProfileDir } from './agy-binary.js';
5
+
6
+ function getLocalDateKey(date = new Date()) {
7
+ const y = date.getFullYear();
8
+ const m = String(date.getMonth() + 1).padStart(2, '0');
9
+ const d = String(date.getDate()).padStart(2, '0');
10
+ return `${y}-${m}-${d}`;
11
+ }
12
+
13
+ function emptyUsageBucket() {
14
+ return {
15
+ requests: 0,
16
+ inputTokens: 0,
17
+ outputTokens: 0,
18
+ cacheReadTokens: 0,
19
+ cacheWriteTokens: 0,
20
+ reasoningTokens: 0,
21
+ totalTokens: 0,
22
+ };
23
+ }
24
+
25
+ function normalizeUsageBucket(raw) {
26
+ const base = emptyUsageBucket();
27
+ if (!raw || typeof raw !== 'object') return base;
28
+ for (const key of Object.keys(base)) {
29
+ const n = Number(raw[key]);
30
+ base[key] = Number.isFinite(n) && n >= 0 ? Math.trunc(n) : 0;
31
+ }
32
+ return base;
33
+ }
34
+
35
+ function normalizeAccountUsage(raw, todayKey = getLocalDateKey()) {
36
+ const sameDay = raw?.todayDate === todayKey;
37
+ return {
38
+ todayDate: todayKey,
39
+ today: sameDay ? normalizeUsageBucket(raw?.today) : emptyUsageBucket(),
40
+ total: normalizeUsageBucket(raw?.total),
41
+ lastUpdatedAt: typeof raw?.lastUpdatedAt === 'string' ? raw.lastUpdatedAt : '',
42
+ };
43
+ }
44
+
45
+ /**
46
+ * 管理多个独立隔离的 Antigravity Google 账号 Profile。
47
+ * 默认包含一个 id="default" 的主账号,直接复用原有 profile 目录,100% 向下兼容。
48
+ */
49
+ export class AntigravityAccountStore {
50
+ /**
51
+ * @param {{ baseDir?: string, defaultProfileDir?: string }} [options]
52
+ */
53
+ constructor(options = {}) {
54
+ const defProfile = options.defaultProfileDir?.trim() || defaultProfileDir();
55
+ this.baseDir = options.baseDir?.trim() || dirname(defProfile);
56
+ this.defaultProfileDir = defProfile;
57
+ this.storePath = join(this.baseDir, 'accounts.json');
58
+ this.state = this._load();
59
+ }
60
+
61
+ _defaultState() {
62
+ return {
63
+ activeAccountId: 'default',
64
+ settings: {
65
+ agyFastEnabled: true,
66
+ },
67
+ accounts: [
68
+ {
69
+ id: 'default',
70
+ label: '主账号',
71
+ profileDir: this.defaultProfileDir,
72
+ createdAt: new Date().toISOString(),
73
+ },
74
+ ],
75
+ };
76
+ }
77
+
78
+ _load() {
79
+ try {
80
+ if (existsSync(this.storePath)) {
81
+ const parsed = JSON.parse(readFileSync(this.storePath, 'utf8'));
82
+ if (parsed && Array.isArray(parsed.accounts) && parsed.accounts.length > 0) {
83
+ const activeExists = parsed.accounts.some((a) => a.id === parsed.activeAccountId);
84
+ return {
85
+ activeAccountId: activeExists ? parsed.activeAccountId : parsed.accounts[0].id,
86
+ settings: {
87
+ agyFastEnabled: parsed.settings?.agyFastEnabled !== false,
88
+ },
89
+ accounts: parsed.accounts,
90
+ };
91
+ }
92
+ }
93
+ } catch {
94
+ // 配置文件损坏时安全回退默认状态
95
+ }
96
+ return this._defaultState();
97
+ }
98
+
99
+ getSettings() {
100
+ return { agyFastEnabled: this.state.settings?.agyFastEnabled !== false };
101
+ }
102
+
103
+ setAgyFastEnabled(enabled) {
104
+ this.state.settings = {
105
+ ...(this.state.settings ?? {}),
106
+ agyFastEnabled: Boolean(enabled),
107
+ };
108
+ this._save();
109
+ return this.getSettings();
110
+ }
111
+
112
+ _save() {
113
+ mkdirSync(this.baseDir, { recursive: true });
114
+ writeFileSync(this.storePath, JSON.stringify(this.state, null, 2), 'utf8');
115
+ }
116
+
117
+ list(now = new Date()) {
118
+ const todayKey = getLocalDateKey(now);
119
+ return {
120
+ activeAccountId: this.state.activeAccountId,
121
+ accounts: this.state.accounts.map((a) => ({
122
+ ...a,
123
+ authMeta: {
124
+ authenticated: a?.authMeta?.authenticated === true,
125
+ tierName: typeof a?.authMeta?.tierName === 'string' ? a.authMeta.tierName : '',
126
+ },
127
+ usage: normalizeAccountUsage(a?.usage, todayKey),
128
+ })),
129
+ };
130
+ }
131
+
132
+ getActive() {
133
+ return (
134
+ this.state.accounts.find((a) => a.id === this.state.activeAccountId) ??
135
+ this.state.accounts[0]
136
+ );
137
+ }
138
+
139
+ /** 读取指定(或当前激活)账号的今日与累计 Token 用量快照 */
140
+ getUsage(accountId, now = new Date()) {
141
+ const acc = accountId
142
+ ? this.state.accounts.find((a) => a.id === accountId)
143
+ : this.getActive();
144
+ const todayKey = getLocalDateKey(now);
145
+ return normalizeAccountUsage(acc?.usage, todayKey);
146
+ }
147
+
148
+ /** 记录一轮真实 ACP Token 消耗到指定(或当前激活)账号 */
149
+ recordUsage(usage, accountId, now = new Date()) {
150
+ if (!usage || typeof usage !== 'object') return this.getUsage(accountId, now);
151
+ const acc = accountId
152
+ ? this.state.accounts.find((a) => a.id === accountId)
153
+ : this.getActive();
154
+ if (!acc) return normalizeAccountUsage(undefined, getLocalDateKey(now));
155
+
156
+ const todayKey = getLocalDateKey(now);
157
+ const current = normalizeAccountUsage(acc.usage, todayKey);
158
+ const toInt = (v) => {
159
+ const n = Number(v);
160
+ return Number.isFinite(n) && n >= 0 ? Math.trunc(n) : 0;
161
+ };
162
+ const input = toInt(usage.inputTokens);
163
+ const output = toInt(usage.outputTokens);
164
+ const cacheRead = toInt(usage.cacheReadTokens);
165
+ const cacheWrite = toInt(usage.cacheWriteTokens);
166
+ const reasoning = toInt(usage.reasoningTokens);
167
+ const total = Math.max(toInt(usage.totalTokens), input + cacheRead + cacheWrite + output);
168
+
169
+ for (const bucket of [current.today, current.total]) {
170
+ bucket.requests += 1;
171
+ bucket.inputTokens += input;
172
+ bucket.outputTokens += output;
173
+ bucket.cacheReadTokens += cacheRead;
174
+ bucket.cacheWriteTokens += cacheWrite;
175
+ bucket.reasoningTokens += reasoning;
176
+ bucket.totalTokens += total;
177
+ }
178
+ current.lastUpdatedAt = now.toISOString();
179
+ acc.usage = current;
180
+ try {
181
+ this._save();
182
+ } catch {
183
+ // 持久化失败不阻断对话
184
+ }
185
+ return normalizeAccountUsage(acc.usage, todayKey);
186
+ }
187
+
188
+ /** 清零指定(或当前激活)账号的本地用量统计 */
189
+ resetUsage(accountId, now = new Date()) {
190
+ const acc = accountId
191
+ ? this.state.accounts.find((a) => a.id === accountId)
192
+ : this.getActive();
193
+ const todayKey = getLocalDateKey(now);
194
+ if (!acc) return normalizeAccountUsage(undefined, todayKey);
195
+ acc.usage = {
196
+ todayDate: todayKey,
197
+ today: emptyUsageBucket(),
198
+ total: emptyUsageBucket(),
199
+ lastUpdatedAt: now.toISOString(),
200
+ };
201
+ this._save();
202
+ return normalizeAccountUsage(acc.usage, todayKey);
203
+ }
204
+
205
+ /** 读取指定(或当前激活)账号持久化的认证与套餐快照(用于冷启动 0ms 展示状态栏) */
206
+ getAuthMeta(accountId) {
207
+ const acc = accountId
208
+ ? this.state.accounts.find((a) => a.id === accountId)
209
+ : this.getActive();
210
+ return {
211
+ authenticated: acc?.authMeta?.authenticated === true,
212
+ tierName: typeof acc?.authMeta?.tierName === 'string' ? acc.authMeta.tierName : '',
213
+ };
214
+ }
215
+
216
+ /** 更新指定(或当前激活)账号持久化的认证与套餐快照 */
217
+ setAuthMeta(meta, accountId) {
218
+ if (!meta || typeof meta !== 'object') return this.getAuthMeta(accountId);
219
+ const acc = accountId
220
+ ? this.state.accounts.find((a) => a.id === accountId)
221
+ : this.getActive();
222
+ if (!acc) return { authenticated: false, tierName: '' };
223
+
224
+ const prev = this.getAuthMeta(acc.id);
225
+ const next = {
226
+ authenticated:
227
+ typeof meta.authenticated === 'boolean' ? meta.authenticated : prev.authenticated,
228
+ tierName:
229
+ typeof meta.tierName === 'string' ? meta.tierName.trim() : prev.tierName,
230
+ };
231
+ if (prev.authenticated === next.authenticated && prev.tierName === next.tierName) {
232
+ return next;
233
+ }
234
+ acc.authMeta = next;
235
+ try {
236
+ this._save();
237
+ } catch {
238
+ // 持久化失败不阻断主流程
239
+ }
240
+ return next;
241
+ }
242
+
243
+ /** 新增独立账号并切换为当前账号 */
244
+ add(rawLabel) {
245
+ const idx = this.state.accounts.length + 1;
246
+ const label = String(rawLabel ?? '').trim() || `账号 ${idx}`;
247
+ const id = `acc_${randomUUID().replace(/-/gu, '').slice(0, 10)}`;
248
+ const profileDir = join(this.baseDir, 'profiles', id);
249
+ mkdirSync(profileDir, { recursive: true });
250
+
251
+ const account = {
252
+ id,
253
+ label,
254
+ profileDir,
255
+ createdAt: new Date().toISOString(),
256
+ };
257
+ this.state.accounts.push(account);
258
+ this.state.activeAccountId = id;
259
+ this._save();
260
+ return { ...account };
261
+ }
262
+
263
+ /** 切换当前激活账号 */
264
+ switchTo(accountId) {
265
+ const hit = this.state.accounts.find((a) => a.id === accountId);
266
+ if (!hit) {
267
+ throw new Error(`未找到指定账号:${accountId}`);
268
+ }
269
+ this.state.activeAccountId = hit.id;
270
+ this._save();
271
+ return { ...hit };
272
+ }
273
+
274
+ /** 移除指定账号(不允许删除默认主账号) */
275
+ remove(accountId) {
276
+ if (accountId === 'default') {
277
+ throw new Error('默认主账号不可删除,如需换号请使用「退出登录」。');
278
+ }
279
+ const idx = this.state.accounts.findIndex((a) => a.id === accountId);
280
+ if (idx === -1) {
281
+ throw new Error(`未找到指定账号:${accountId}`);
282
+ }
283
+ const [removed] = this.state.accounts.splice(idx, 1);
284
+ if (this.state.activeAccountId === accountId) {
285
+ this.state.activeAccountId = this.state.accounts[0]?.id ?? 'default';
286
+ }
287
+ this._save();
288
+
289
+ try {
290
+ if (removed.profileDir && removed.profileDir !== this.defaultProfileDir) {
291
+ rmSync(removed.profileDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
292
+ }
293
+ } catch {
294
+ // 忽略 Windows 文件锁导致的延迟清理错误
295
+ }
296
+ return this.getActive();
297
+ }
298
+ }