agy-delegate-mcp 0.0.0 → 1.1.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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/PRIVACY.md +11 -0
- package/README.md +222 -2
- package/SECURITY.md +35 -0
- package/TERMS.md +9 -0
- package/package.json +59 -3
- package/src/acp-client.js +198 -0
- package/src/agent-reported-files.js +24 -0
- package/src/delegate.js +533 -0
- package/src/doctor.js +202 -0
- package/src/errors.js +20 -0
- package/src/jsonrpc.js +145 -0
- package/src/model-options.js +76 -0
- package/src/proc.js +36 -0
- package/src/request-router.js +33 -0
- package/src/server.js +432 -0
- package/src/session-supervisor.js +125 -0
- package/src/spawn.js +29 -0
- package/src/turn-state.js +159 -0
- package/src/version.js +24 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/), and the project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.1.0] - 2026-11-22
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The README lists install steps for Cursor (one-click deeplink), VS Code (one-click install),
|
|
14
|
+
JetBrains AI Assistant, Devin Desktop, Visual Studio, OpenCode, Kilo Code and Kiro, and shows
|
|
15
|
+
npm, MCP Registry, Glama, Node and test badges.
|
|
16
|
+
|
|
17
|
+
## [1.0.0] - 2026-11-21
|
|
18
|
+
|
|
19
|
+
First public release.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- MCP server that delegates coding tasks to Google Antigravity's CLI (`agy`) over the
|
|
24
|
+
[Agent Client Protocol](https://agentclientprotocol.com/), through `agy acp`.
|
|
25
|
+
- **`delegate`** tool: inline brief, `agent`/`plan`/`ask` modes, session resume, `model` as a
|
|
26
|
+
base id and `effort` as agy's thinking level, `contextFiles` as resource links and images.
|
|
27
|
+
Returns the result, `sessionId`, `filesReportedByEditTools`, the plan agy writes in plan mode,
|
|
28
|
+
and the model and thinking level that ran.
|
|
29
|
+
- **`cancel`** tool: cancels an in-flight delegation; `force` ends the agy process tree.
|
|
30
|
+
- **`doctor`** tool: reports the agy install, version, sign-in, account tier and the models agy
|
|
31
|
+
offers.
|
|
32
|
+
- Plugins for Claude Code, Codex and GitHub Copilot CLI, with a shared `delegate` skill.
|
|
33
|
+
- Listed in the MCP Registry as `io.github.andreilungeanu/agy-delegate-mcp`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrei Lungeanu
|
|
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/PRIVACY.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Privacy
|
|
2
|
+
|
|
3
|
+
Antigravity Delegate runs as a local stdio MCP server. The project author does not operate a backend for the plugin and does not receive your code, prompts, workspace contents, session identifiers, diagnostics, or usage telemetry.
|
|
4
|
+
|
|
5
|
+
Claude Code installs run the server bundled in the plugin cache. On first session, the plugin may run `npm install --omit=dev` inside that cache to fetch its open-source runtime dependencies; it does not install them into your project. Codex, Copilot, VS Code, and standalone MCP configurations start the published package through `npx`, so npm may apply its own registry logging under npm's policies.
|
|
6
|
+
|
|
7
|
+
When you delegate, the local server starts `agy`. Task prompts, selected workspace content, model requests, and Google account usage are handled by Google under the terms and privacy policy that apply to Google Antigravity. agy keeps its own session history and artifacts under `~/.gemini/antigravity-cli/`. Your MCP host may separately process the prompt and tool results under its own terms.
|
|
8
|
+
|
|
9
|
+
The MCP response can contain file paths, agent output, plan text, diagnostic information, and session identifiers. Review that output before sharing logs or bug reports. The plugin does not redact secrets found in prompts, files, agent output, or diagnostics.
|
|
10
|
+
|
|
11
|
+
For security issues, see [SECURITY.md](SECURITY.md) or open a [GitHub Security Advisory](https://github.com/andreilungeanu/agy-delegate-mcp/security/advisories/new).
|
package/README.md
CHANGED
|
@@ -1,3 +1,223 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Antigravity Delegate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Delegate edits to Google Antigravity's CLI agent (`agy`) — your agent writes the brief and reviews the diff.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/agy-delegate-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/agy-delegate-mcp)
|
|
7
|
+
[](https://registry.modelcontextprotocol.io/v0.1/servers?search=agy-delegate&version=latest)
|
|
8
|
+
[](https://glama.ai/mcp/servers/andreilungeanu/agy-delegate-mcp)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://github.com/andreilungeanu/agy-delegate-mcp/actions/workflows/test.yml)
|
|
12
|
+
|
|
13
|
+
<img src="assets/logo-light.png" alt="Antigravity Delegate logo" width="150" align="left" hspace="15">
|
|
14
|
+
|
|
15
|
+
Antigravity Delegate is the MCP bridge that lets Claude Code, ChatGPT/Codex, Copilot — or any MCP client — hand implementation to **agy** over the Agent Client Protocol, then get a structured result back for review.
|
|
16
|
+
|
|
17
|
+
<br clear="left">
|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- 🤝 **Native plugins** — install into Claude Code, ChatGPT/Codex, or GitHub Copilot CLI and say *"delegate this to Antigravity"*. The shared skill teaches your agent how to delegate well.
|
|
26
|
+
- 💬 **No stalled runs** — if agy needs to clarify, it ends the turn and returns the question as a normal result. Your agent answers by resuming the same session.
|
|
27
|
+
- 📦 **Named results** — final answer, changed files, session id, model and thinking level, returned as one compact JSON payload.
|
|
28
|
+
- 📋 **Plan first** — `plan` mode: agy writes a plan, returned in full as `plan`; you review it, then the same session implements it.
|
|
29
|
+
- 🔍 **Ask anything** — `ask` mode: Q&A over your codebase.
|
|
30
|
+
- 🩺 **Self-diagnosing** — a `doctor` tool that reports what is missing, the models agy offers, and the account tier.
|
|
31
|
+
|
|
32
|
+
`plan` and `ask` are instructions to the agent, and `workspace` is its working directory — [Security](SECURITY.md) and the [delegate reference](skills/delegate/reference.md) spell out what the bridge enforces and what it reports back.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
You need [Node.js 20+](https://nodejs.org/) and the Antigravity CLI (`agy`), signed in — run `agy` once and sign in.
|
|
37
|
+
|
|
38
|
+
### Claude Code
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
/plugin marketplace add andreilungeanu/agy-delegate-mcp
|
|
42
|
+
/plugin install agy-delegate@agy-delegate-mcp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then ask:
|
|
46
|
+
|
|
47
|
+
> Delegate to Antigravity: migrate src/api from callbacks to async/await and update the tests, then walk me through what changed.
|
|
48
|
+
|
|
49
|
+
### Cursor
|
|
50
|
+
|
|
51
|
+
[](https://cursor.com/en/install-mcp?name=agy-delegate&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImFneS1kZWxlZ2F0ZS1tY3AiXX0%3D)
|
|
52
|
+
|
|
53
|
+
Or add it under **Customize → MCPs** in the sidebar, or in `~/.cursor/mcp.json` (every project) or `.cursor/mcp.json` (this project):
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"agy-delegate": {
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### ChatGPT desktop / Codex
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
codex plugin marketplace add andreilungeanu/agy-delegate-mcp
|
|
70
|
+
codex plugin add agy-delegate@agy-delegate-mcp
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### GitHub Copilot CLI
|
|
74
|
+
|
|
75
|
+
```shell
|
|
76
|
+
copilot plugin marketplace add andreilungeanu/agy-delegate-mcp
|
|
77
|
+
copilot plugin install agy-delegate@agy-delegate-mcp
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The server alone, without the skill: `copilot mcp add agy-delegate -- npx -y agy-delegate-mcp`.
|
|
81
|
+
|
|
82
|
+
### More clients
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary><strong>VS Code</strong> — one-click install, or <code>.vscode/mcp.json</code></summary>
|
|
86
|
+
|
|
87
|
+
[](https://vscode.dev/redirect/mcp/install?name=agy-delegate&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22agy-delegate-mcp%22%5D%7D)
|
|
88
|
+
[](https://insiders.vscode.dev/redirect/mcp/install?name=agy-delegate&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22agy-delegate-mcp%22%5D%7D&quality=insiders)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"servers": {
|
|
93
|
+
"agy-delegate": {
|
|
94
|
+
"type": "stdio",
|
|
95
|
+
"command": "npx",
|
|
96
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
</details>
|
|
103
|
+
|
|
104
|
+
<details>
|
|
105
|
+
<summary><strong>JetBrains AI Assistant</strong> — Settings → Tools → AI Assistant → MCP</summary>
|
|
106
|
+
|
|
107
|
+
Under **Settings → Tools → AI Assistant → Model Context Protocol (MCP)**, click **Add** and paste this JSON:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"mcpServers": {
|
|
112
|
+
"agy-delegate": {
|
|
113
|
+
"command": "npx",
|
|
114
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
</details>
|
|
121
|
+
|
|
122
|
+
<details>
|
|
123
|
+
<summary><strong>Devin Desktop (formerly Windsurf)</strong> — <code>~/.config/devin/mcp_config.json</code></summary>
|
|
124
|
+
|
|
125
|
+
This config is for Devin Local, the default agent (Local 3.6+). On Windows the file is `%APPDATA%\devin\mcp_config.json`. Legacy Cascade and older Windsurf builds read `~/.codeium/windsurf/mcp_config.json`.
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"mcpServers": {
|
|
130
|
+
"agy-delegate": {
|
|
131
|
+
"command": "npx",
|
|
132
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Heads-up: Devin Desktop's Cascade agent caps you at 100 tools across all servers.
|
|
139
|
+
|
|
140
|
+
</details>
|
|
141
|
+
|
|
142
|
+
<details>
|
|
143
|
+
<summary><strong>Visual Studio 2026 / 2022</strong> — <code>%USERPROFILE%\.mcp.json</code></summary>
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"servers": {
|
|
148
|
+
"agy-delegate": {
|
|
149
|
+
"type": "stdio",
|
|
150
|
+
"command": "npx",
|
|
151
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Visual Studio 2022 needs 17.14+. Note the top-level key is `servers`, not `mcpServers`. A `.mcp.json` in the solution directory scopes it to that solution.
|
|
158
|
+
|
|
159
|
+
</details>
|
|
160
|
+
|
|
161
|
+
<details>
|
|
162
|
+
<summary><strong>OpenCode</strong> — <code>~/.config/opencode/opencode.json</code> or project <code>opencode.json</code></summary>
|
|
163
|
+
|
|
164
|
+
OpenCode does **not** use `mcpServers`. Local servers go under `mcp`, with `type: "local"` and `command` as one array:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"$schema": "https://opencode.ai/config.json",
|
|
169
|
+
"mcp": {
|
|
170
|
+
"agy-delegate": {
|
|
171
|
+
"type": "local",
|
|
172
|
+
"command": ["npx", "-y", "agy-delegate-mcp"],
|
|
173
|
+
"enabled": true
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
This is the v1 shape, which OpenCode v2 still reads (v2's native form is `mcp.servers`).
|
|
180
|
+
|
|
181
|
+
</details>
|
|
182
|
+
|
|
183
|
+
<details>
|
|
184
|
+
<summary><strong>Kilo Code</strong> — <code>kilo.jsonc</code> (<code>mcp</code> key, not <code>mcpServers</code>)</summary>
|
|
185
|
+
|
|
186
|
+
Same shape as OpenCode: `type: "local"` and `command` as one array.
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"mcp": {
|
|
191
|
+
"agy-delegate": {
|
|
192
|
+
"type": "local",
|
|
193
|
+
"command": ["npx", "-y", "agy-delegate-mcp"],
|
|
194
|
+
"enabled": true
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
In the VS Code extension: **Settings → MCP → Add Server → Local (stdio)**. On Windows, if `npx` is not found, use command `cmd` with arguments `/c`, `npx`, `-y`, `agy-delegate-mcp`.
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
### Kiro and any other MCP client
|
|
205
|
+
|
|
206
|
+
Add the following server to the client's MCP config — for Kiro, `~/.kiro/settings/mcp.json` (user) or `.kiro/settings/mcp.json` (workspace):
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"mcpServers": {
|
|
211
|
+
"agy-delegate": {
|
|
212
|
+
"command": "npx",
|
|
213
|
+
"args": ["-y", "agy-delegate-mcp"]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT © [Andrei Lungeanu](https://github.com/andreilungeanu)
|
|
222
|
+
|
|
223
|
+
<sub>[Technical reference](TECHNICAL.md) · [Security](SECURITY.md) · [Privacy](PRIVACY.md) · [Terms](TERMS.md) · [Changelog](CHANGELOG.md)</sub>
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
## What this plugin does
|
|
4
|
+
|
|
5
|
+
`agy-delegate-mcp` spawns **agy** (`agy acp --dangerously-skip-permissions`) in your workspace,
|
|
6
|
+
so agy approves its own tool calls, and the bridge **auto-approves every permission request**
|
|
7
|
+
that still arrives over ACP, in every mode — `agent`, `plan` and `ask`. Each request is answered
|
|
8
|
+
with the broadest allow option agy offered (`allow_always`, else `allow_once`).
|
|
9
|
+
|
|
10
|
+
`workspace` is the agent's working directory, and a run can reach outside it. `mode` is
|
|
11
|
+
passed to the agent as an instruction, so `plan` and `ask` describe how it behaves rather
|
|
12
|
+
than what it is permitted to do. Delegated tasks can create, modify, or delete files
|
|
13
|
+
anywhere your user account can reach, and reach the network.
|
|
14
|
+
|
|
15
|
+
Treat every `delegate` call like handing an engineer a shell on your machine. Your MCP host
|
|
16
|
+
is the orchestrator: it should scope the brief, then review `filesReportedByEditTools` and
|
|
17
|
+
the git diff. That field lists what the agent's edit tools reported touching; the git diff
|
|
18
|
+
is authoritative.
|
|
19
|
+
|
|
20
|
+
## Recommendations
|
|
21
|
+
|
|
22
|
+
- Point `workspace` at the smallest directory that contains the task (not `$HOME` or `/`).
|
|
23
|
+
It scopes what the agent works on, not what it can reach.
|
|
24
|
+
- Review the git diff before committing, after every run — including `plan` and `ask` ones.
|
|
25
|
+
- Run verification (tests, lint) after delegation — the delegate skill asks the orchestrator
|
|
26
|
+
to do this, but automated gates in CI are still your backstop.
|
|
27
|
+
- Do not commit secrets (`.env`, credentials, tokens). The bridge does not redact them from
|
|
28
|
+
agent context.
|
|
29
|
+
|
|
30
|
+
## Reporting vulnerabilities
|
|
31
|
+
|
|
32
|
+
If you find a security issue in this bridge (not in agy or an MCP host),
|
|
33
|
+
please open a [GitHub Security Advisory](https://github.com/andreilungeanu/agy-delegate-mcp/security/advisories/new)
|
|
34
|
+
or email the maintainer listed in `package.json` instead of filing a public issue with
|
|
35
|
+
exploit details.
|
package/TERMS.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Terms of Use
|
|
2
|
+
|
|
3
|
+
Antigravity Delegate is provided under the MIT License on an "as is" basis, without warranties or guarantees.
|
|
4
|
+
|
|
5
|
+
The plugin runs locally and starts `agy` with access to the workspace selected for a delegation. Delegated agent-mode tasks may create, modify, or delete files. You are responsible for choosing an appropriate workspace, reviewing changes, protecting credentials, and complying with the terms that apply to Google Antigravity, your MCP host, and any model you select.
|
|
6
|
+
|
|
7
|
+
The project author does not operate the Antigravity service, receive delegated source code, or control the behavior of third-party models and clients. Do not use the plugin for unlawful activity or in a way that violates third-party rights or service terms.
|
|
8
|
+
|
|
9
|
+
For support, open a [GitHub issue](https://github.com/andreilungeanu/agy-delegate-mcp/issues). For security reports, follow [SECURITY.md](SECURITY.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-delegate-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"mcpName": "io.github.andreilungeanu/agy-delegate-mcp",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Delegate multi-file coding work from Claude Code, Codex, Copilot, or any MCP client to Google's Antigravity CLI (agy) — structured results, plan mode, and changed files.",
|
|
5
7
|
"license": "MIT",
|
|
6
|
-
"
|
|
8
|
+
"author": "Andrei Lungeanu <andrei@lungeanu.ro>",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/andreilungeanu/agy-delegate-mcp.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/andreilungeanu/agy-delegate-mcp/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/andreilungeanu/agy-delegate-mcp#readme",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mcp",
|
|
19
|
+
"antigravity",
|
|
20
|
+
"antigravity-cli",
|
|
21
|
+
"agy",
|
|
22
|
+
"gemini",
|
|
23
|
+
"acp",
|
|
24
|
+
"agent-client-protocol",
|
|
25
|
+
"claude-code",
|
|
26
|
+
"codex",
|
|
27
|
+
"github-copilot",
|
|
28
|
+
"vscode",
|
|
29
|
+
"delegation",
|
|
30
|
+
"coding-agent",
|
|
31
|
+
"ai-agents"
|
|
32
|
+
],
|
|
33
|
+
"main": "src/server.js",
|
|
34
|
+
"bin": {
|
|
35
|
+
"agy-delegate-mcp": "src/server.js"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"src",
|
|
42
|
+
"README.md",
|
|
43
|
+
"PRIVACY.md",
|
|
44
|
+
"SECURITY.md",
|
|
45
|
+
"TERMS.md",
|
|
46
|
+
"LICENSE",
|
|
47
|
+
"CHANGELOG.md"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "node scripts/run-tests.mjs",
|
|
51
|
+
"test:pack": "node test/npm-package-smoke.mjs",
|
|
52
|
+
"start": "node src/server.js",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@modelcontextprotocol/sdk": "^1.23.0",
|
|
57
|
+
"zod": "^4.6.5"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^26.1.1",
|
|
61
|
+
"typescript": "^7.0.2"
|
|
62
|
+
}
|
|
7
63
|
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { StringDecoder } from "node:string_decoder";
|
|
4
|
+
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
5
|
+
import { createRequestRouter } from "./request-router.js";
|
|
6
|
+
import { resolveAcpSpawn } from "./spawn.js";
|
|
7
|
+
import { DETACHED, isChildAlive, treeKill } from "./proc.js";
|
|
8
|
+
import { VERSION } from "./version.js";
|
|
9
|
+
import { makeError } from "./errors.js";
|
|
10
|
+
|
|
11
|
+
const STDERR_CAP = 64 * 1024;
|
|
12
|
+
// How long stop() waits for the child to actually exit after the kill is dispatched. SIGKILL and
|
|
13
|
+
// taskkill /F land in milliseconds, so this only ever elapses when the kill did not work.
|
|
14
|
+
const STOP_EXIT_TIMEOUT_MS = 2000;
|
|
15
|
+
|
|
16
|
+
export class AcpClient extends EventEmitter {
|
|
17
|
+
/**
|
|
18
|
+
* @param {{
|
|
19
|
+
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
20
|
+
* }} [opts]
|
|
21
|
+
*/
|
|
22
|
+
constructor({ spawnSpec } = {}) {
|
|
23
|
+
super();
|
|
24
|
+
this.spawnSpec = spawnSpec || resolveAcpSpawn();
|
|
25
|
+
this._stderrChunks = [];
|
|
26
|
+
this._stderrLength = 0;
|
|
27
|
+
/** @type {Promise<boolean> | null} */
|
|
28
|
+
this._stopping = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// stderr is captured but does not count as activity: the supervisor measures ACP frames, and
|
|
32
|
+
// an agent writing diagnostics is not the same fact as a turn making progress.
|
|
33
|
+
// The tail of stderr, which is what an exit error quotes. Kept as chunks and joined on read:
|
|
34
|
+
// rebuilding a 64KB string per chunk was the whole cost of a noisy agent. A StringDecoder
|
|
35
|
+
// holds partial UTF-8 across chunk boundaries, so a multi-byte character split by the pipe
|
|
36
|
+
// does not land in the error message as a replacement char.
|
|
37
|
+
get stderrBuffer() {
|
|
38
|
+
const joined = this._stderrChunks.join("");
|
|
39
|
+
return joined.length > STDERR_CAP ? joined.slice(-STDERR_CAP) : joined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
start() {
|
|
43
|
+
const { command, args, options } = this.spawnSpec;
|
|
44
|
+
this._stderrChunks = [];
|
|
45
|
+
this._stderrLength = 0;
|
|
46
|
+
const stderrDecoder = new StringDecoder("utf8");
|
|
47
|
+
this._exitEmitted = false;
|
|
48
|
+
this.child = spawn(command, args, { ...options, detached: DETACHED, stdio: ["pipe", "pipe", "pipe"] });
|
|
49
|
+
this.child.stderr.on("data", (chunk) => {
|
|
50
|
+
const text = stderrDecoder.write(chunk);
|
|
51
|
+
if (text) {
|
|
52
|
+
this._stderrChunks.push(text);
|
|
53
|
+
this._stderrLength += text.length;
|
|
54
|
+
// Drop whole chunks from the front only once well past the cap, so the common case
|
|
55
|
+
// costs one push. The joined tail is trimmed exactly on read.
|
|
56
|
+
while (this._stderrChunks.length > 1 && this._stderrLength - this._stderrChunks[0].length >= STDERR_CAP) {
|
|
57
|
+
this._stderrLength -= this._stderrChunks.shift().length;
|
|
58
|
+
}
|
|
59
|
+
// Whole-chunk drops leave a remainder when one pipe read is itself larger than the cap
|
|
60
|
+
// (observed on GitHub Windows runners). Slice that first chunk so retained memory cannot
|
|
61
|
+
// grow with the flood; the public tail is still exactly one cap on read.
|
|
62
|
+
const overflow = this._stderrLength - STDERR_CAP;
|
|
63
|
+
if (overflow > 0) {
|
|
64
|
+
this._stderrChunks[0] = this._stderrChunks[0].slice(overflow);
|
|
65
|
+
this._stderrLength -= overflow;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
this.child.stderr.on("error", () => {});
|
|
70
|
+
// A supervisor trip writes session/cancel, which can land after the agent is already gone.
|
|
71
|
+
// Without a handler that surfaces as an unhandled 'error' event on some platforms, taking
|
|
72
|
+
// the whole MCP server down with it. stdout needs the same guard; readline adds none.
|
|
73
|
+
this.child.stdin.on("error", () => {});
|
|
74
|
+
this.child.stdout.on("error", () => {});
|
|
75
|
+
const emitExit = (code, signal) => {
|
|
76
|
+
if (this._exitEmitted) return;
|
|
77
|
+
this._exitEmitted = true;
|
|
78
|
+
const stderr = this.stderrBuffer;
|
|
79
|
+
const err = makeError(
|
|
80
|
+
"agent-exit",
|
|
81
|
+
// stderr kept whole. This is the one string that says why the agent died — the model
|
|
82
|
+
// that was rejected, the quota that ran out, the login that expired — and the part that
|
|
83
|
+
// names it can sit anywhere in it. The 64KB ring buffer above is the bound.
|
|
84
|
+
`agent exited (code=${code}${signal ? ", signal=" + signal : ""})${stderr ? ": " + String(stderr) : ""}`
|
|
85
|
+
);
|
|
86
|
+
// exit + rejectAllPending both settle the same Promise.race; second rejection is intentional.
|
|
87
|
+
this.peer?.rejectAllPending(err);
|
|
88
|
+
this.emit("exit", { code, signal, stderr });
|
|
89
|
+
};
|
|
90
|
+
this.child.once("exit", emitExit);
|
|
91
|
+
this.child.once("close", emitExit);
|
|
92
|
+
this.router = null;
|
|
93
|
+
this.peer = new JsonRpcPeer(this.child.stdout, this.child.stdin, {
|
|
94
|
+
onNotification: (method, params) => {
|
|
95
|
+
if (method === "session/update") this.emit("update", params);
|
|
96
|
+
},
|
|
97
|
+
// The router is async and its result discarded, so a throw from its own catch would reject
|
|
98
|
+
// unobserved and exit the process. Promise.resolve covers a sync router in tests.
|
|
99
|
+
onRequest: (id, method, params) => {
|
|
100
|
+
if (this.router) Promise.resolve(this.router(id, method, params)).catch(() => {});
|
|
101
|
+
},
|
|
102
|
+
onActivity: () => this.emit("activity"),
|
|
103
|
+
});
|
|
104
|
+
this.router = createRequestRouter({
|
|
105
|
+
respond: (id, r) => this.peer.respond(id, r),
|
|
106
|
+
respondError: (id, c, m) => this.peer.respondError(id, c, m),
|
|
107
|
+
});
|
|
108
|
+
return /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
|
|
109
|
+
this.child.once("error", (e) => {
|
|
110
|
+
// Tagged like every other failure class so the caller gets
|
|
111
|
+
// "delegate failed [spawn-failed]: ..." instead of the one untagged prose error.
|
|
112
|
+
const err = makeError("spawn-failed", `Failed to spawn agent (${command}): ${e.message}. Install the Antigravity CLI (agy) and sign in by running agy once.`);
|
|
113
|
+
reject(err);
|
|
114
|
+
});
|
|
115
|
+
this.child.once("spawn", () => resolve());
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Stashed so the unknown-model pre-flight and doctor --deep can read the agent's real
|
|
120
|
+
// capability and model lists without paying for a second handshake.
|
|
121
|
+
async initialize() {
|
|
122
|
+
const res = await this.peer.request("initialize", { protocolVersion: 1, clientInfo: { name: "agy-delegate-mcp", version: VERSION }, clientCapabilities: {} });
|
|
123
|
+
this.protocolVersion = res?.protocolVersion;
|
|
124
|
+
this.agentCapabilities = res?.agentCapabilities;
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
_captureSession(res) {
|
|
128
|
+
this.sessionModels = res?.models;
|
|
129
|
+
this.sessionModes = res?.modes;
|
|
130
|
+
this.configOptions = res?.configOptions;
|
|
131
|
+
// _meta.antigravity.tier names the account's plan; doctor reports it.
|
|
132
|
+
this.sessionMeta = res?._meta;
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
135
|
+
async newSession(cwd) { return this._captureSession(await this.peer.request("session/new", { cwd, mcpServers: [] })); }
|
|
136
|
+
// resume reopens a session without replaying it. Unlike session/load, which agy answers with a
|
|
137
|
+
// fresh session for an id it has never seen, resume rejects an unknown id.
|
|
138
|
+
async resumeSession(sessionId, cwd) { return this._captureSession(await this.peer.request("session/resume", { sessionId, cwd, mcpServers: [] })); }
|
|
139
|
+
// agy returns every session the account has, ignoring cwd, in one page.
|
|
140
|
+
listSessions(params = {}) { return this.peer.request("session/list", params); }
|
|
141
|
+
setModel(sessionId, modelId) { return this.peer.request("session/set_model", { sessionId, modelId }); }
|
|
142
|
+
setConfigOption(sessionId, configId, value) { return this.peer.request("session/set_config_option", { sessionId, configId, value: String(value) }); } // configId, not optionId; ACP wants a string value
|
|
143
|
+
setMode(sessionId, modeId) { return this.peer.request("session/set_mode", { sessionId, modeId }); }
|
|
144
|
+
prompt(sessionId, blocks) { return this.peer.request("session/prompt", { sessionId, prompt: blocks }); }
|
|
145
|
+
cancel(sessionId) { this.peer.notify("session/cancel", { sessionId }); return Promise.resolve(); }
|
|
146
|
+
|
|
147
|
+
getTranscript(n) { return this.peer ? this.peer.formatLog(n) : ""; }
|
|
148
|
+
|
|
149
|
+
// Idempotent while teardown is in flight and after a confirmed exit. A missed exit is not
|
|
150
|
+
// memoized — force retries with a new treeKill. A confirmed exit stays so later callers join.
|
|
151
|
+
stop({ timeoutMs = STOP_EXIT_TIMEOUT_MS } = {}) {
|
|
152
|
+
if (!this._stopping) {
|
|
153
|
+
this._stopping = this._teardown(timeoutMs).then((observed) => {
|
|
154
|
+
if (!observed) this._stopping = null;
|
|
155
|
+
return observed;
|
|
156
|
+
}, (err) => {
|
|
157
|
+
this._stopping = null;
|
|
158
|
+
throw err;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return this._stopping;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async _teardown(timeoutMs) {
|
|
165
|
+
const child = this.child;
|
|
166
|
+
if (!child?.pid) {
|
|
167
|
+
try { this.peer?.close(); } catch {}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
const alive = isChildAlive(child);
|
|
171
|
+
// Subscribed before the kill is dispatched. A child that dies immediately would otherwise
|
|
172
|
+
// exit in the gap and leave this waiting on an event that has already fired.
|
|
173
|
+
const exited = alive
|
|
174
|
+
? /** @type {Promise<boolean>} */ (new Promise((resolve) => child.once("exit", () => resolve(true))))
|
|
175
|
+
: Promise.resolve(true);
|
|
176
|
+
// Runs for an exited child too: the agent can be gone while the commands it spawned are still
|
|
177
|
+
// running, and on POSIX they stay in its process group, which is the only handle left on them.
|
|
178
|
+
treeKill(child.pid, { childAlive: alive }).catch(() => {});
|
|
179
|
+
/** @type {NodeJS.Timeout | undefined} */
|
|
180
|
+
let timer;
|
|
181
|
+
const bounded = /** @type {Promise<boolean>} */ (new Promise((resolve) => {
|
|
182
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
183
|
+
}));
|
|
184
|
+
const observed = await Promise.race([exited, bounded]);
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
// The exit handler rejects in-flight RPCs with stderr. Doing that here on a confirmed
|
|
187
|
+
// exit would race it and the first settlement would drop the forensics. A stop that
|
|
188
|
+
// did not see the child die never gets that handler, so settle those RPCs only when
|
|
189
|
+
// the process is still alive and emitExit has not run.
|
|
190
|
+
if (!observed && !this._exitEmitted && isChildAlive(child)) {
|
|
191
|
+
try {
|
|
192
|
+
this.peer?.rejectAllPending(makeError("agent-exit", "agent process did not exit after stop"));
|
|
193
|
+
} catch {}
|
|
194
|
+
}
|
|
195
|
+
try { this.peer?.close(); } catch {}
|
|
196
|
+
return observed;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
// Attribution rule: a path is agent-reported only via a native ACP diff event.
|
|
4
|
+
// Never add paths from git, the final message, or shell output — the orchestrator
|
|
5
|
+
// owns workspace diff review.
|
|
6
|
+
|
|
7
|
+
// agy reports a finished edit's diff path as /C:/Users/… on Windows (leading slash, forward
|
|
8
|
+
// slashes) while the same call's args carry C:\Users\…. The slash before the drive letter makes
|
|
9
|
+
// path.resolve read it as rooted on the current drive, so it is stripped before resolving.
|
|
10
|
+
export function fromAgentPath(p) {
|
|
11
|
+
return /^\/[A-Za-z]:[\\/]/.test(p) ? p.slice(1) : p;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function relativize(abs, workspace) {
|
|
15
|
+
if (!workspace) return abs;
|
|
16
|
+
const r = path.relative(workspace, abs);
|
|
17
|
+
if (!r || r.startsWith("..") || path.isAbsolute(r)) return abs;
|
|
18
|
+
return r.split(path.sep).join("/");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function normalizeAgentReportedFiles(paths, workspace) {
|
|
22
|
+
const abs = paths.map((p) => fromAgentPath(p)).map((p) => (workspace ? path.resolve(workspace, p) : path.resolve(p)));
|
|
23
|
+
return [...new Set(abs)].map((f) => relativize(f, workspace));
|
|
24
|
+
}
|