agy-delegate-mcp 1.1.0 → 1.2.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 +21 -0
- package/package.json +1 -1
- package/src/acp-client.js +11 -3
- package/src/delegate.js +17 -2
- package/src/doctor.js +4 -2
- package/src/server.js +7 -2
- package/src/spawn.js +20 -0
- package/src/turn-state.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,27 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.2.0] - 2026-11-22
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `resultSource: "unfinished-tool"`: a turn that ends with a tool call still running returns agy's
|
|
14
|
+
message from while it ran, and `protocolWarnings` names the tool. agy ends a turn this way when
|
|
15
|
+
it moves a shell command to the background after the wait it set for it (`WaitMsBeforeAsync`),
|
|
16
|
+
which stops with agy when the delegation returns, and when it asks a question through
|
|
17
|
+
`ask_question`, which a resume answers. The result was empty, with a warning that agy sent no
|
|
18
|
+
message.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- agy starts in the workspace. Started in the MCP server's directory, it listed that directory and
|
|
23
|
+
ran `git status` and `git diff` there during a delegation to another workspace.
|
|
24
|
+
- A missing agy on Windows is reported as `spawn-failed` with the install hint, and `doctor`
|
|
25
|
+
reports `found: false`. Launched through cmd.exe it read as `agent-exit` quoting cmd's
|
|
26
|
+
"is not recognized" line, and `doctor` reported `found: true`.
|
|
27
|
+
- `cancel` with `force` returns as soon as the turn settles, in about 60 ms, instead of waiting out
|
|
28
|
+
its 5 s grace.
|
|
29
|
+
|
|
9
30
|
## [1.1.0] - 2026-11-22
|
|
10
31
|
|
|
11
32
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"mcpName": "io.github.andreilungeanu/agy-delegate-mcp",
|
|
5
5
|
"type": "module",
|
|
6
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.",
|
package/src/acp-client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from "node:events";
|
|
|
3
3
|
import { StringDecoder } from "node:string_decoder";
|
|
4
4
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
5
5
|
import { createRequestRouter } from "./request-router.js";
|
|
6
|
-
import { resolveAcpSpawn } from "./spawn.js";
|
|
6
|
+
import { commandExists, resolveAcpSpawn } from "./spawn.js";
|
|
7
7
|
import { DETACHED, isChildAlive, treeKill } from "./proc.js";
|
|
8
8
|
import { VERSION } from "./version.js";
|
|
9
9
|
import { makeError } from "./errors.js";
|
|
@@ -19,9 +19,14 @@ export class AcpClient extends EventEmitter {
|
|
|
19
19
|
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
20
20
|
* }} [opts]
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
/** @param {{ spawnSpec?: any, cwd?: string }} [opts] */
|
|
23
|
+
constructor({ spawnSpec, cwd } = {}) {
|
|
23
24
|
super();
|
|
24
25
|
this.spawnSpec = spawnSpec || resolveAcpSpawn();
|
|
26
|
+
// agy treats its process directory as part of the workspace, not only the session's cwd:
|
|
27
|
+
// started from the MCP server's directory it listed that directory and ran git status and
|
|
28
|
+
// git diff there (measured, agy 1.5.14). Started in the workspace, there is nothing else to see.
|
|
29
|
+
this.cwd = cwd;
|
|
25
30
|
this._stderrChunks = [];
|
|
26
31
|
this._stderrLength = 0;
|
|
27
32
|
/** @type {Promise<boolean> | null} */
|
|
@@ -41,11 +46,14 @@ export class AcpClient extends EventEmitter {
|
|
|
41
46
|
|
|
42
47
|
start() {
|
|
43
48
|
const { command, args, options } = this.spawnSpec;
|
|
49
|
+
if (/** @type {{ shell?: boolean }} */ (options)?.shell && !commandExists(command)) {
|
|
50
|
+
return Promise.reject(makeError("spawn-failed", `Failed to spawn agent (${command}): not found on PATH. Install the Antigravity CLI (agy) and sign in by running agy once.`));
|
|
51
|
+
}
|
|
44
52
|
this._stderrChunks = [];
|
|
45
53
|
this._stderrLength = 0;
|
|
46
54
|
const stderrDecoder = new StringDecoder("utf8");
|
|
47
55
|
this._exitEmitted = false;
|
|
48
|
-
this.child = spawn(command, args, { ...options, detached: DETACHED, stdio: ["pipe", "pipe", "pipe"] });
|
|
56
|
+
this.child = spawn(command, args, { ...options, ...(this.cwd ? { cwd: this.cwd } : {}), detached: DETACHED, stdio: ["pipe", "pipe", "pipe"] });
|
|
49
57
|
this.child.stderr.on("data", (chunk) => {
|
|
50
58
|
const text = stderrDecoder.write(chunk);
|
|
51
59
|
if (text) {
|
package/src/delegate.js
CHANGED
|
@@ -271,7 +271,7 @@ export async function runDelegate({
|
|
|
271
271
|
const state = makeTurnState({ onProgress, progressThrottleMs });
|
|
272
272
|
|
|
273
273
|
const make = clientFactory || ((opts) => new AcpClient(opts));
|
|
274
|
-
const client = make({});
|
|
274
|
+
const client = make({ cwd: workspace });
|
|
275
275
|
// Handed over before the spawn, because from client.start() there is an agent process and the
|
|
276
276
|
// caller needs something that can stop it.
|
|
277
277
|
onClientReady?.(client);
|
|
@@ -362,6 +362,7 @@ export async function runDelegate({
|
|
|
362
362
|
if (up.sessionUpdate === "agent_message_chunk" && up.content?.text) {
|
|
363
363
|
const text = up.content.text;
|
|
364
364
|
if (state.collectingResult()) state.appendResult(text);
|
|
365
|
+
else if (state.activeToolCalls.size > 0) state.unfinishedToolText += text;
|
|
365
366
|
state.messages.push(text);
|
|
366
367
|
}
|
|
367
368
|
});
|
|
@@ -421,7 +422,21 @@ export async function runDelegate({
|
|
|
421
422
|
? (state.sawToolCall ? "post-tool" : "tool-free-stream")
|
|
422
423
|
: "none";
|
|
423
424
|
const protocolWarnings = [];
|
|
424
|
-
if (!finalMessageAvailable && state.
|
|
425
|
+
if (!finalMessageAvailable && state.activeToolCalls.size > 0) {
|
|
426
|
+
// agy ends a turn with a call unfinished in two measured cases (agy 1.5.14): it moves a
|
|
427
|
+
// shell command to the background once it outlasts the call's WaitMsBeforeAsync, a wait agy
|
|
428
|
+
// picks per command, or it waits on ask_question.
|
|
429
|
+
// The bridge stops agy when the delegation returns, so a backgrounded command stops with it.
|
|
430
|
+
result = state.unfinishedToolText;
|
|
431
|
+
resultSource = result ? "unfinished-tool" : "none";
|
|
432
|
+
protocolWarnings.push(
|
|
433
|
+
`the turn ended with a tool call still running (${state.lastToolLabel ?? "unnamed tool"}).`
|
|
434
|
+
+ " agy does this when it moves a shell command to the background after the wait it set for it (WaitMsBeforeAsync) —"
|
|
435
|
+
+ " the command stops when the bridge stops agy — and when it asks a question (ask_question),"
|
|
436
|
+
+ " which a resume answers."
|
|
437
|
+
+ (result ? " result is agy's message from while it ran." : " agy sent no message while it ran.")
|
|
438
|
+
);
|
|
439
|
+
} else if (!finalMessageAvailable && state.discardedResult) {
|
|
425
440
|
result = state.discardedResult;
|
|
426
441
|
resultSource = "pre-tool-fallback";
|
|
427
442
|
protocolWarnings.push(
|
package/src/doctor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { AcpClient } from "./acp-client.js";
|
|
4
|
-
import { resolveAcpSpawn } from "./spawn.js";
|
|
4
|
+
import { commandExists, resolveAcpSpawn } from "./spawn.js";
|
|
5
5
|
import { DETACHED, treeKill } from "./proc.js";
|
|
6
6
|
import { readPackageVersion } from "./version.js";
|
|
7
7
|
import { allowedValues, describeOptions } from "./model-options.js";
|
|
@@ -40,6 +40,8 @@ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_M
|
|
|
40
40
|
const isJsScript = isJsLauncher(launcher);
|
|
41
41
|
const execCommand = isJsScript ? process.execPath : command;
|
|
42
42
|
const execArgs = isJsScript ? [launcher, "--version"] : ["--version"];
|
|
43
|
+
// Through a shell, a missing launcher still spawns (the shell does) and would read as found.
|
|
44
|
+
if (options?.shell && !isJsScript && !commandExists(launcher)) return Promise.resolve({ found: false, version: null });
|
|
43
45
|
return new Promise((resolve) => {
|
|
44
46
|
let settled = false;
|
|
45
47
|
let stdout = "";
|
|
@@ -83,8 +85,8 @@ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_M
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs }) {
|
|
86
|
-
const client = clientFactory({ spawnSpec });
|
|
87
88
|
const workspaceDir = workspace || process.cwd();
|
|
89
|
+
const client = clientFactory({ spawnSpec, cwd: workspaceDir });
|
|
88
90
|
let timer;
|
|
89
91
|
try {
|
|
90
92
|
const details = {};
|
package/src/server.js
CHANGED
|
@@ -76,7 +76,7 @@ export const SERVER_INSTRUCTIONS = `Delegate coding work to Antigravity (agy) th
|
|
|
76
76
|
// its tool description.
|
|
77
77
|
export const delegateOutputShape = {
|
|
78
78
|
result: z.string(),
|
|
79
|
-
resultSource: z.enum(["pre-tool-fallback", "none"]).optional(),
|
|
79
|
+
resultSource: z.enum(["pre-tool-fallback", "unfinished-tool", "none"]).optional(),
|
|
80
80
|
effectiveModel: z.string().optional(),
|
|
81
81
|
effectiveEffort: z.record(z.string(), z.string()).optional(),
|
|
82
82
|
stopReason: z.string().optional(),
|
|
@@ -305,7 +305,12 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
305
305
|
// finally removes its handle when the turn actually settles.
|
|
306
306
|
return cancelResult("cancelled", sessionId);
|
|
307
307
|
}
|
|
308
|
-
|
|
308
|
+
// Watched rather than slept through: agy stops a cancelled turn in milliseconds, and the
|
|
309
|
+
// delegation's finally drops its handle the moment the turn settles.
|
|
310
|
+
const graceEnds = Date.now() + forceGraceMs;
|
|
311
|
+
while (Date.now() < graceEnds && inFlight.get(sessionId)?.size) {
|
|
312
|
+
await new Promise((r) => setTimeout(r, Math.min(50, Math.max(1, graceEnds - Date.now()))));
|
|
313
|
+
}
|
|
309
314
|
const stillRunning = inFlight.get(sessionId);
|
|
310
315
|
if (!stillRunning || stillRunning.size === 0) return cancelResult("cancelled", sessionId);
|
|
311
316
|
// Snapshot before awaiting stop. A resume that registers during teardown must not be
|
package/src/spawn.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
|
|
3
5
|
export function splitArgs(raw) {
|
|
4
6
|
const args = [];
|
|
@@ -27,3 +29,21 @@ export function resolveAcpSpawn() {
|
|
|
27
29
|
: [...DEFAULT_AGENT_ARGS];
|
|
28
30
|
return { command, args, options: { shell: process.platform === "win32" } };
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
// Through a shell the spawn itself always succeeds: cmd.exe starts, fails to find the launcher and
|
|
34
|
+
// exits 1 with a localized "is not recognized" line, so Node's spawn 'error' event never fires and
|
|
35
|
+
// a missing agy reads as an agent crash. Resolving the launcher first is what lets that case be
|
|
36
|
+
// reported as not installed. Mirrors cmd's lookup: a path is checked as given, a bare name against
|
|
37
|
+
// each PATH entry, both with and without each PATHEXT extension.
|
|
38
|
+
export function commandExists(command, env = process.env) {
|
|
39
|
+
const name = String(command || "").replace(/^["']|["']$/g, "");
|
|
40
|
+
if (!name) return false;
|
|
41
|
+
const pathKey = Object.keys(env).find((k) => k.toUpperCase() === "PATH");
|
|
42
|
+
const extKey = Object.keys(env).find((k) => k.toUpperCase() === "PATHEXT");
|
|
43
|
+
const exts = ["", ...String((extKey && env[extKey]) || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)];
|
|
44
|
+
const isFile = (p) => { try { return existsSync(p) && statSync(p).isFile(); } catch { return false; } };
|
|
45
|
+
const hit = (base) => exts.some((ext) => isFile(base + ext) || isFile(base + ext.toLowerCase()));
|
|
46
|
+
if (/[\\/]/.test(name)) return hit(name);
|
|
47
|
+
const dirs = String((pathKey && env[pathKey]) || "").split(path.delimiter).filter(Boolean);
|
|
48
|
+
return dirs.some((dir) => hit(path.join(dir.replace(/^"|"$/g, ""), name)));
|
|
49
|
+
}
|
package/src/turn-state.js
CHANGED
|
@@ -52,6 +52,10 @@ function freshFields() {
|
|
|
52
52
|
// caller "" with stopReason end_turn and no error. Kept so it can be handed back when
|
|
53
53
|
// nothing survived — labelled, never blended with a real final message.
|
|
54
54
|
discardedResult: "",
|
|
55
|
+
// Message text sent while a tool call was still running, since that call started. Not part of
|
|
56
|
+
// the result: it is handed back only when the turn ends with the call still unfinished, which
|
|
57
|
+
// is how agy reports moving a long shell command to the background.
|
|
58
|
+
unfinishedToolText: "",
|
|
55
59
|
sawToolCall: false,
|
|
56
60
|
collectingPostToolResult: false,
|
|
57
61
|
activeToolCalls: new Set(),
|
|
@@ -100,6 +104,7 @@ export function makeTurnState({ onProgress, progressThrottleMs = 2000 } = {}) {
|
|
|
100
104
|
},
|
|
101
105
|
|
|
102
106
|
startTool(toolCallId, status) {
|
|
107
|
+
state.unfinishedToolText = "";
|
|
103
108
|
state.sawToolCall = true;
|
|
104
109
|
state.collectingPostToolResult = false;
|
|
105
110
|
state.resetResult();
|