agy-delegate-mcp 1.4.0 → 1.6.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 +58 -0
- package/package.json +1 -1
- package/src/acp-client.js +85 -75
- package/src/agent-reported-files.js +4 -6
- package/src/delegate.js +222 -159
- package/src/doctor.js +69 -35
- package/src/errors.js +2 -4
- package/src/jsonrpc.js +10 -26
- package/src/model-options.js +10 -18
- package/src/proc.js +10 -19
- package/src/request-router.js +4 -10
- package/src/server.js +137 -116
- package/src/session-supervisor.js +10 -9
- package/src/spawn.js +112 -23
- package/src/turn-state.js +19 -29
- package/src/version.js +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,64 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.6.0] - 2026-11-22
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- On Windows the launcher is found first and started by file type. agy.exe runs directly rather
|
|
14
|
+
than through cmd.exe, so its arguments arrive exactly; a `.ps1` runs through Windows PowerShell; a
|
|
15
|
+
`.cmd` or `.bat` runs through cmd.exe with its arguments quoted. A Store app alias counts as
|
|
16
|
+
found, a file with no extension never matches, and a bare name is no longer run from the
|
|
17
|
+
workspace.
|
|
18
|
+
- In `ACP_AGENT_ARGS` a quoted section after `=` belongs to its argument, so
|
|
19
|
+
`--log-file="C:\a b\x.log"` is one argument. A quote inside a word stays a character.
|
|
20
|
+
- A resume that omits `model` on a server with no record of the session says so in
|
|
21
|
+
`protocolWarnings`.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- A launcher path or argument with spaces reaches a `.cmd` launcher whole.
|
|
26
|
+
- `force` cancel kills unsettled turns alongside the other turns' closes, not after them.
|
|
27
|
+
- A delegation cancelled during setup carries `resultSource: "none"`.
|
|
28
|
+
- The unfinished-tool warning and the background wait's progress line name the command still
|
|
29
|
+
running. The wait's limit is named only when it ran out, and a cancel or steer in its last check
|
|
30
|
+
is honoured.
|
|
31
|
+
- An effort reply that omits the model keeps the model recorded for the session.
|
|
32
|
+
- An aborted `doctor` spawns no version probe, and an aborted probe returns only once it has
|
|
33
|
+
closed, also when the abort falls just before its timeout.
|
|
34
|
+
- A signal after stdin closes sets the exit code. A second signal kills every agent shutdown
|
|
35
|
+
stopped, except one whose exit was already confirmed.
|
|
36
|
+
|
|
37
|
+
## [1.5.0] - 2026-11-22
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- A resume that leaves out `model` or `effort` uses what this server last set on that session; agy
|
|
42
|
+
reopens a resumed session at its defaults.
|
|
43
|
+
- `cancel` and `steer` reject a blank `sessionId`. `resumeSessionId` is trimmed, and a blank one
|
|
44
|
+
means no resume.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- A cancel during session setup sends no prompt and returns `stopReason: "cancelled"` at once, even
|
|
49
|
+
if a config call hangs or fails. The prompt still ran in full.
|
|
50
|
+
- `steer` reports `not-running` once the turn has ended, been cancelled or lost its agent; it said
|
|
51
|
+
`not-ready`. A steer agy accepted that then fails fails the delegation, and a steer queued behind a
|
|
52
|
+
failed one supplies the result.
|
|
53
|
+
- `cancel` after the turn ended reports `not-running` and leaves the result alone; `force` cuts
|
|
54
|
+
agy's close short as each turn settles.
|
|
55
|
+
- A host abort during agy's close, or during `doctor`'s probe, handshake or close, ends it at once.
|
|
56
|
+
Shutdown stops `doctor`'s agent.
|
|
57
|
+
- The background wait runs only after `end_turn`, on one clock per delegation. A refusal or output
|
|
58
|
+
cap that leaves a command open names the command, not a question.
|
|
59
|
+
- `usage` keeps a cached or thought count one reply left out. `context` ignores other sessions'
|
|
60
|
+
frames, and frames sent while attachments are read stay out of the result.
|
|
61
|
+
- A delegation returns only once agy's descendants are killed. An exit the bridge does not see is
|
|
62
|
+
retried and reported in `protocolWarnings`.
|
|
63
|
+
- No DEP0190 warning under Node 24 on Windows.
|
|
64
|
+
- On Linux and macOS, SIGHUP stops the agents, and only a second signal cuts shutdown short, killing
|
|
65
|
+
their process groups first.
|
|
66
|
+
|
|
9
67
|
## [1.4.0] - 2026-11-22
|
|
10
68
|
|
|
11
69
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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
|
@@ -1,33 +1,36 @@
|
|
|
1
|
+
import process from "node:process";
|
|
1
2
|
import { spawn } from "node:child_process";
|
|
2
3
|
import { EventEmitter } from "node:events";
|
|
3
4
|
import { StringDecoder } from "node:string_decoder";
|
|
4
5
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
5
6
|
import { createRequestRouter } from "./request-router.js";
|
|
6
|
-
import {
|
|
7
|
+
import { resolveAcpSpawn, spawnArgv, spawnCommandLine } from "./spawn.js";
|
|
7
8
|
import { DETACHED, isChildAlive, treeKill } from "./proc.js";
|
|
8
9
|
import { VERSION } from "./version.js";
|
|
9
10
|
import { makeError } from "./errors.js";
|
|
10
11
|
|
|
11
12
|
const STDERR_CAP = 64 * 1024;
|
|
12
|
-
// How long stop() waits for the
|
|
13
|
-
//
|
|
13
|
+
// How long stop() waits for the exit and the tree kill; it elapses when the kill failed or the
|
|
14
|
+
// tree walk is slow.
|
|
14
15
|
const STOP_EXIT_TIMEOUT_MS = 2000;
|
|
15
16
|
// How long a graceful stop gives agy to exit by itself before the kill. agy took 200–400 ms.
|
|
16
17
|
export const GRACEFUL_STOP_MS = 2000;
|
|
17
18
|
|
|
19
|
+
// Settlement order of prompt replies: a refused steer settles before the turn it targets, one agy
|
|
20
|
+
// took over settles after it. Attached at request time, so it records when the reply came.
|
|
21
|
+
let settleSeq = 0;
|
|
22
|
+
/** @returns {Promise<{ ok: true, value: any, seq: number } | { ok: false, error: any, seq: number }>} */
|
|
23
|
+
export function stampSettlement(promise) {
|
|
24
|
+
return promise.then((value) => ({ ok: true, value, seq: ++settleSeq }), (error) => ({ ok: false, error, seq: ++settleSeq }));
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export class AcpClient extends EventEmitter {
|
|
19
|
-
/**
|
|
20
|
-
* @param {{
|
|
21
|
-
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
22
|
-
* }} [opts]
|
|
23
|
-
*/
|
|
24
28
|
/** @param {{ spawnSpec?: any, cwd?: string }} [opts] */
|
|
25
29
|
constructor({ spawnSpec, cwd } = {}) {
|
|
26
30
|
super();
|
|
27
31
|
this.spawnSpec = spawnSpec || resolveAcpSpawn();
|
|
28
|
-
// agy treats its process directory as part of the workspace
|
|
29
|
-
//
|
|
30
|
-
// git diff there (measured, agy 1.5.14). Started in the workspace, there is nothing else to see.
|
|
32
|
+
// agy treats its process directory as part of the workspace: started elsewhere, it ran git
|
|
33
|
+
// status there (measured, agy 1.5.14).
|
|
31
34
|
this.cwd = cwd;
|
|
32
35
|
this._stderrChunks = [];
|
|
33
36
|
this._stderrLength = 0;
|
|
@@ -36,17 +39,15 @@ export class AcpClient extends EventEmitter {
|
|
|
36
39
|
// Sessions opened on this process, which a graceful stop closes.
|
|
37
40
|
/** @type {Set<string>} */
|
|
38
41
|
this._sessions = new Set();
|
|
39
|
-
|
|
42
|
+
// setup until the prompt is on the wire, open while the turn runs, then closed for good.
|
|
43
|
+
/** @type {"setup" | "open" | "closed"} */
|
|
44
|
+
this._steerWindow = "setup";
|
|
40
45
|
/** @type {Promise<any>[]} */
|
|
41
46
|
this._steers = [];
|
|
42
47
|
}
|
|
43
48
|
|
|
44
|
-
// stderr
|
|
45
|
-
//
|
|
46
|
-
// The tail of stderr, which is what an exit error quotes. Kept as chunks and joined on read:
|
|
47
|
-
// rebuilding a 64KB string per chunk was the whole cost of a noisy agent. A StringDecoder
|
|
48
|
-
// holds partial UTF-8 across chunk boundaries, so a multi-byte character split by the pipe
|
|
49
|
-
// does not land in the error message as a replacement char.
|
|
49
|
+
// The stderr tail an exit error quotes; not counted as activity. Kept as chunks and joined on
|
|
50
|
+
// read, which is cheap for a noisy agent; the StringDecoder keeps split UTF-8 characters whole.
|
|
50
51
|
get stderrBuffer() {
|
|
51
52
|
const joined = this._stderrChunks.join("");
|
|
52
53
|
return joined.length > STDERR_CAP ? joined.slice(-STDERR_CAP) : joined;
|
|
@@ -54,27 +55,28 @@ export class AcpClient extends EventEmitter {
|
|
|
54
55
|
|
|
55
56
|
start() {
|
|
56
57
|
const { command, args, options } = this.spawnSpec;
|
|
57
|
-
|
|
58
|
+
// Found before the spawn: through cmd.exe a missing launcher still spawns, and would read as an
|
|
59
|
+
// agent crash.
|
|
60
|
+
const launch = spawnArgv(command, args, options);
|
|
61
|
+
if (!launch) {
|
|
58
62
|
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.`));
|
|
59
63
|
}
|
|
60
64
|
this._stderrChunks = [];
|
|
61
65
|
this._stderrLength = 0;
|
|
62
66
|
const stderrDecoder = new StringDecoder("utf8");
|
|
63
67
|
this._exitEmitted = false;
|
|
64
|
-
|
|
68
|
+
const [file, argv] = spawnCommandLine(launch.command, launch.args, launch.options);
|
|
69
|
+
this.child = spawn(file, argv, { ...launch.options, ...(this.cwd ? { cwd: this.cwd } : {}), detached: DETACHED, stdio: ["pipe", "pipe", "pipe"] });
|
|
65
70
|
this.child.stderr.on("data", (chunk) => {
|
|
66
71
|
const text = stderrDecoder.write(chunk);
|
|
67
72
|
if (text) {
|
|
68
73
|
this._stderrChunks.push(text);
|
|
69
74
|
this._stderrLength += text.length;
|
|
70
|
-
//
|
|
71
|
-
// costs one push. The joined tail is trimmed exactly on read.
|
|
75
|
+
// Whole chunks are dropped once past the cap; the tail is trimmed exactly on read.
|
|
72
76
|
while (this._stderrChunks.length > 1 && this._stderrLength - this._stderrChunks[0].length >= STDERR_CAP) {
|
|
73
77
|
this._stderrLength -= this._stderrChunks.shift().length;
|
|
74
78
|
}
|
|
75
|
-
//
|
|
76
|
-
// (observed on GitHub Windows runners). Slice that first chunk so retained memory cannot
|
|
77
|
-
// grow with the flood; the public tail is still exactly one cap on read.
|
|
79
|
+
// A single read larger than the cap (seen on GitHub Windows runners) is sliced.
|
|
78
80
|
const overflow = this._stderrLength - STDERR_CAP;
|
|
79
81
|
if (overflow > 0) {
|
|
80
82
|
this._stderrChunks[0] = this._stderrChunks[0].slice(overflow);
|
|
@@ -83,22 +85,19 @@ export class AcpClient extends EventEmitter {
|
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
87
|
this.child.stderr.on("error", () => {});
|
|
86
|
-
// A
|
|
87
|
-
//
|
|
88
|
-
// the whole MCP server down with it. stdout needs the same guard; readline adds none.
|
|
88
|
+
// A write after the agent is gone raises 'error' on stdin. readline forwards stdout's errors only
|
|
89
|
+
// until it closes. Unhandled, either takes down the server.
|
|
89
90
|
this.child.stdin.on("error", () => {});
|
|
90
91
|
this.child.stdout.on("error", () => {});
|
|
91
92
|
const emitExit = (code, signal) => {
|
|
92
93
|
if (this._exitEmitted) return;
|
|
93
94
|
this._exitEmitted = true;
|
|
94
95
|
// A steer to an exited agent has nowhere to go.
|
|
95
|
-
this.
|
|
96
|
+
this._steerWindow = "closed";
|
|
96
97
|
const stderr = this.stderrBuffer;
|
|
97
98
|
const err = makeError(
|
|
98
99
|
"agent-exit",
|
|
99
|
-
//
|
|
100
|
-
// that was rejected, the quota that ran out, the login that expired — and the part that
|
|
101
|
-
// names it can sit anywhere in it. The 64KB ring buffer above is the bound.
|
|
100
|
+
// All of the (capped) stderr: the reason the agent died can sit anywhere in it.
|
|
102
101
|
`agent exited (code=${code}${signal ? ", signal=" + signal : ""})${stderr ? ": " + String(stderr) : ""}`
|
|
103
102
|
);
|
|
104
103
|
// exit + rejectAllPending both settle the same Promise.race; second rejection is intentional.
|
|
@@ -112,8 +111,7 @@ export class AcpClient extends EventEmitter {
|
|
|
112
111
|
onNotification: (method, params) => {
|
|
113
112
|
if (method === "session/update") this.emit("update", params);
|
|
114
113
|
},
|
|
115
|
-
//
|
|
116
|
-
// unobserved and exit the process. Promise.resolve covers a sync router in tests.
|
|
114
|
+
// Caught: an unobserved rejection would exit the process. Promise.resolve covers a sync router.
|
|
117
115
|
onRequest: (id, method, params) => {
|
|
118
116
|
if (this.router) Promise.resolve(this.router(id, method, params)).catch(() => {});
|
|
119
117
|
},
|
|
@@ -125,8 +123,6 @@ export class AcpClient extends EventEmitter {
|
|
|
125
123
|
});
|
|
126
124
|
return /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
|
|
127
125
|
this.child.once("error", (e) => {
|
|
128
|
-
// Tagged like every other failure class so the caller gets
|
|
129
|
-
// "delegate failed [spawn-failed]: ..." instead of the one untagged prose error.
|
|
130
126
|
const err = makeError("spawn-failed", `Failed to spawn agent (${command}): ${e.message}. Install the Antigravity CLI (agy) and sign in by running agy once.`);
|
|
131
127
|
reject(err);
|
|
132
128
|
});
|
|
@@ -134,8 +130,7 @@ export class AcpClient extends EventEmitter {
|
|
|
134
130
|
}));
|
|
135
131
|
}
|
|
136
132
|
|
|
137
|
-
//
|
|
138
|
-
// capability and model lists without paying for a second handshake.
|
|
133
|
+
// Kept for the model check and doctor, without a second handshake.
|
|
139
134
|
async initialize() {
|
|
140
135
|
const res = await this.peer.request("initialize", { protocolVersion: 1, clientInfo: { name: "agy-delegate-mcp", version: VERSION }, clientCapabilities: {} });
|
|
141
136
|
this.protocolVersion = res?.protocolVersion;
|
|
@@ -150,9 +145,8 @@ export class AcpClient extends EventEmitter {
|
|
|
150
145
|
this.sessionMeta = res?._meta;
|
|
151
146
|
return res;
|
|
152
147
|
}
|
|
153
|
-
// appendSystemPrompt goes in _meta.antigravity.systemPrompt.append
|
|
154
|
-
//
|
|
155
|
-
// and a _meta sent on resume is ignored (measured, agy 1.5.14).
|
|
148
|
+
// appendSystemPrompt goes in _meta.antigravity.systemPrompt.append. agy stores it with the session
|
|
149
|
+
// and ignores a _meta sent on resume (measured, agy 1.5.14).
|
|
156
150
|
/** @param {string} cwd @param {{ appendSystemPrompt?: string }} [opts] */
|
|
157
151
|
async newSession(cwd, { appendSystemPrompt } = {}) {
|
|
158
152
|
const params = { cwd, mcpServers: [] };
|
|
@@ -174,37 +168,54 @@ export class AcpClient extends EventEmitter {
|
|
|
174
168
|
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
|
|
175
169
|
setMode(sessionId, modeId) { return this.peer.request("session/set_mode", { sessionId, modeId }); }
|
|
176
170
|
prompt(sessionId, blocks) { return this.peer.request("session/prompt", { sessionId, prompt: blocks }); }
|
|
177
|
-
// agy takes a session/prompt sent
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
171
|
+
// agy takes a session/prompt sent mid-turn as a redirect: the prompt in flight settles at once
|
|
172
|
+
// with end_turn, the new one when the redirected turn ends (measured, agy 1.5.14). The window is
|
|
173
|
+
// open only while the delegation's prompt runs, and a cancel or exit closes it for good. prefix
|
|
174
|
+
// goes ahead of each steer, as ask mode's instruction goes ahead of the spec.
|
|
175
|
+
acceptSteers(on, prefix) {
|
|
176
|
+
if (!on) { this._steerWindow = "closed"; return; }
|
|
177
|
+
if (this._steerWindow === "setup" && !this.cancelRequested && !this._exitEmitted) {
|
|
178
|
+
this._steerWindow = "open";
|
|
179
|
+
this._steerPrefix = prefix;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** @returns {"steered" | "not-ready" | "not-running"} */
|
|
183
183
|
steer(sessionId, text) {
|
|
184
|
-
if (
|
|
184
|
+
if (this._steerWindow === "setup") return "not-ready";
|
|
185
|
+
if (this._steerWindow !== "open" || !this.peer) return "not-running";
|
|
185
186
|
const body = this._steerPrefix ? `${this._steerPrefix}\n\n${text}` : text;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this._steers.push(reply);
|
|
190
|
-
return true;
|
|
187
|
+
// Stamped, so it never rejects unobserved.
|
|
188
|
+
this._steers.push(stampSettlement(this.peer.request("session/prompt", { sessionId, prompt: [{ type: "text", text: body }] })));
|
|
189
|
+
return "steered";
|
|
191
190
|
}
|
|
192
191
|
hasSteer() { return this._steers.length > 0; }
|
|
193
192
|
takeSteer() { return this._steers.shift(); }
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
cancel(sessionId) {
|
|
193
|
+
// Read by the background wait: after a cancel agy closes the call without the usage_update that
|
|
194
|
+
// ends a continuation. Closes the steer window: a later steer would restart the cancelled turn.
|
|
195
|
+
// delegate listens for the event to end its setup when no prompt has gone out.
|
|
196
|
+
cancel(sessionId) {
|
|
197
|
+
this.cancelRequested = true;
|
|
198
|
+
this._steerWindow = "closed";
|
|
199
|
+
this.peer.notify("session/cancel", { sessionId });
|
|
200
|
+
this.emit("cancel");
|
|
201
|
+
return Promise.resolve();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Last resort for a process about to exit: SIGKILL to the group and the agent, no ps walk. POSIX
|
|
205
|
+
// only; on win32 the kill is taskkill, which stop() runs.
|
|
206
|
+
killNow() {
|
|
207
|
+
const pid = this.child?.pid;
|
|
208
|
+
if (!pid || process.platform === "win32") return;
|
|
209
|
+
try { process.kill(-pid, "SIGKILL"); } catch {}
|
|
210
|
+
if (isChildAlive(this.child)) { try { process.kill(pid, "SIGKILL"); } catch {} }
|
|
211
|
+
}
|
|
198
212
|
|
|
199
213
|
getTranscript(n) { return this.peer ? this.peer.formatLog(n) : ""; }
|
|
200
214
|
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
// conversation database, where a kill leaves its -shm and -wal files (measured, agy 1.5.14).
|
|
206
|
-
// A force stop (graceMs 0) that finds a graceful one in progress ends its grace now rather than
|
|
207
|
-
// waiting it out: force cancel and shutdown mean "kill".
|
|
215
|
+
// Memoized while in flight and after a confirmed exit; a missed exit is not, so a retry kills
|
|
216
|
+
// again. graceMs > 0 first closes the sessions and stdin and waits that long: agy then exits 0 in
|
|
217
|
+
// 200–400 ms with its database closed, where a kill leaves -shm and -wal files (measured, agy
|
|
218
|
+
// 1.5.14). The tree kill follows either way. A force stop ends a grace in progress.
|
|
208
219
|
stop({ timeoutMs = STOP_EXIT_TIMEOUT_MS, graceMs = 0 } = {}) {
|
|
209
220
|
if (this._stopping && graceMs <= 0) this._endGrace?.();
|
|
210
221
|
if (!this._stopping) {
|
|
@@ -219,8 +230,8 @@ export class AcpClient extends EventEmitter {
|
|
|
219
230
|
return this._stopping;
|
|
220
231
|
}
|
|
221
232
|
|
|
222
|
-
// session/close stops
|
|
223
|
-
//
|
|
233
|
+
// session/close stops background commands and subagents a cancel leaves running (agy 1.5.10
|
|
234
|
+
// changelog); stdin EOF then ends agy. Bounded by graceMs.
|
|
224
235
|
async _closeGracefully(child, graceMs) {
|
|
225
236
|
/** @type {NodeJS.Timeout | undefined} */
|
|
226
237
|
let timer;
|
|
@@ -251,25 +262,24 @@ export class AcpClient extends EventEmitter {
|
|
|
251
262
|
}
|
|
252
263
|
if (graceMs > 0 && isChildAlive(child)) await this._closeGracefully(child, graceMs);
|
|
253
264
|
const alive = isChildAlive(child);
|
|
254
|
-
// Subscribed before the kill
|
|
255
|
-
// exit in the gap and leave this waiting on an event that has already fired.
|
|
265
|
+
// Subscribed before the kill, so an immediate exit is not missed.
|
|
256
266
|
const exited = alive
|
|
257
267
|
? /** @type {Promise<boolean>} */ (new Promise((resolve) => child.once("exit", () => resolve(true))))
|
|
258
268
|
: Promise.resolve(true);
|
|
259
|
-
//
|
|
260
|
-
|
|
261
|
-
treeKill(child.pid, { childAlive: alive }).catch(() => {});
|
|
269
|
+
// Also for an exited child: on POSIX its commands can outlive it in its process group.
|
|
270
|
+
const killed = treeKill(child.pid, { childAlive: alive }).catch(() => {});
|
|
262
271
|
/** @type {NodeJS.Timeout | undefined} */
|
|
263
272
|
let timer;
|
|
264
273
|
const bounded = /** @type {Promise<boolean>} */ (new Promise((resolve) => {
|
|
265
274
|
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
266
275
|
}));
|
|
267
276
|
const observed = await Promise.race([exited, bounded]);
|
|
277
|
+
// The tree kill too, on the same deadline: on POSIX it walks the tree with ps first, and an agent
|
|
278
|
+
// exiting meanwhile would resolve stop() before its commands were killed.
|
|
279
|
+
await Promise.race([killed, bounded]);
|
|
268
280
|
clearTimeout(timer);
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
// did not see the child die never gets that handler, so settle those RPCs only when
|
|
272
|
-
// the process is still alive and emitExit has not run.
|
|
281
|
+
// On an exit, emitExit rejects pending RPCs with stderr; rejecting here first would lose it.
|
|
282
|
+
// Only an unobserved exit settles them here.
|
|
273
283
|
if (!observed && !this._exitEmitted && isChildAlive(child)) {
|
|
274
284
|
try {
|
|
275
285
|
this.peer?.rejectAllPending(makeError("agent-exit", "agent process did not exit after stop"));
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// owns workspace diff review.
|
|
3
|
+
// A path is agent-reported only via an ACP diff event, never from git, the message or shell output:
|
|
4
|
+
// the orchestrator owns diff review.
|
|
6
5
|
|
|
7
|
-
// agy
|
|
8
|
-
//
|
|
9
|
-
// path.resolve read it as rooted on the current drive, so it is stripped before resolving.
|
|
6
|
+
// agy writes diff paths as /C:/Users/… on Windows; path.resolve would read the leading slash as
|
|
7
|
+
// the current drive's root, so it is stripped.
|
|
10
8
|
export function fromAgentPath(p) {
|
|
11
9
|
return /^\/[A-Za-z]:[\\/]/.test(p) ? p.slice(1) : p;
|
|
12
10
|
}
|