@prplkane/agentlink 0.3.0-beta.3 → 0.3.0-beta.4
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 +15 -11
- package/docs/acp-qualification.md +16 -0
- package/docs/architecture.md +14 -4
- package/docs/laptop-testing.md +4 -0
- package/package.json +1 -1
- package/src/bridges.mjs +26 -10
- package/src/child-process.mjs +19 -3
- package/src/discovery.mjs +5 -3
- package/src/doctor.mjs +6 -0
- package/src/gateway.mjs +45 -13
- package/src/probe.mjs +2 -2
- package/src/process.mjs +3 -3
- package/src/version.mjs +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ AgentLink saves the launch command for each profile. Any client that speaks the
|
|
|
6
6
|
Agent Client Protocol (ACP) can use that name to open a session with the selected
|
|
7
7
|
agent. The client owns the conversation, and the agent supplies its capabilities.
|
|
8
8
|
|
|
9
|
-
Requires Node.js 22 or newer. The public beta, `0.3.0-beta.
|
|
9
|
+
Requires Node.js 22 or newer. The public beta, `0.3.0-beta.4`, has no npm runtime
|
|
10
10
|
dependencies. See the [qualification results](docs/acp-qualification.md) for tested
|
|
11
11
|
providers, platforms and known limits.
|
|
12
12
|
|
|
@@ -127,8 +127,12 @@ All ACP clients launching that profile inherit the choices on their next
|
|
|
127
127
|
`session/new`, including on an open connection. Running and resumed sessions
|
|
128
128
|
keep their settings. A client may explicitly override a choice for its session.
|
|
129
129
|
If a saved ID disappears, session creation reports the unavailable choice so
|
|
130
|
-
you can replace it once for every project.
|
|
131
|
-
|
|
130
|
+
you can replace it once for every project. AgentLink can only detect a retired
|
|
131
|
+
model once the bridge stops advertising that ID. While a bridge still lists
|
|
132
|
+
it, the saved choice is accepted and any failure comes from the vendor. If
|
|
133
|
+
the profile file cannot be read when a session is created, only that request
|
|
134
|
+
fails; the connection and its other sessions stay open. Bridge updates still
|
|
135
|
+
check ACP initialization. Actual model and effort support is checked in the session.
|
|
132
136
|
|
|
133
137
|
## Discover an unfamiliar agent
|
|
134
138
|
|
|
@@ -279,7 +283,8 @@ Current boundaries:
|
|
|
279
283
|
its owner and path; remove a stale lock only after that process has stopped.
|
|
280
284
|
|
|
281
285
|
`agentlink doctor [--json]` checks local profiles, launch files, managed
|
|
282
|
-
installation metadata and locks without starting agents or changing anything.
|
|
286
|
+
installation metadata, connection leases and locks without starting agents or changing anything.
|
|
287
|
+
An abandoned lease appears as a note. Run `agentlink bridge prune` to remove it.
|
|
283
288
|
It exits with status 1 for detected errors. It does not test sign-in or ACP
|
|
284
289
|
compatibility; use `check PROFILE` for initialization.
|
|
285
290
|
|
|
@@ -299,9 +304,9 @@ synthetic profiles, checks model and effort inheritance on every prompt, and
|
|
|
299
304
|
verifies lease cleanup after each batch.
|
|
300
305
|
Python installation coverage runs when Python is available. No vendor account
|
|
301
306
|
or paid model call is needed.
|
|
302
|
-
A GitHub Actions workflow
|
|
303
|
-
and Python 3.13
|
|
304
|
-
|
|
307
|
+
A GitHub Actions workflow runs the offline suite on Windows, Linux and macOS
|
|
308
|
+
with Node 22 and 24 and Python 3.13. Results are on the repository's
|
|
309
|
+
[Actions page](https://github.com/prplkane/agentlink/actions).
|
|
305
310
|
|
|
306
311
|
See [laptop testing](docs/laptop-testing.md) for real-agent checks and
|
|
307
312
|
[architecture](docs/architecture.md) for the maintenance boundaries.
|
|
@@ -313,9 +318,9 @@ the standard gateway; the helper's limitations do not define the gateway.
|
|
|
313
318
|
## Working on this repository
|
|
314
319
|
|
|
315
320
|
Read [CONTRIBUTING.md](https://github.com/prplkane/agentlink/blob/main/CONTRIBUTING.md) and the shared
|
|
316
|
-
[AGENTS.md](https://github.com/prplkane/agentlink/blob/main/AGENTS.md).
|
|
317
|
-
|
|
318
|
-
|
|
321
|
+
[AGENTS.md](https://github.com/prplkane/agentlink/blob/main/AGENTS.md). Work records for
|
|
322
|
+
non-trivial changes are kept locally and are not part of the repository; see the
|
|
323
|
+
[working agreement](https://github.com/prplkane/agentlink/blob/main/docs/work/README.md).
|
|
319
324
|
|
|
320
325
|
The [source-document review](https://github.com/prplkane/agentlink/blob/main/docs/process/source-document-review.md) describes
|
|
321
326
|
the guidance adapted from Roundtable and Career Hub, grouped by project, with
|
|
@@ -326,4 +331,3 @@ explicit reasons for each inclusion and exclusion. See
|
|
|
326
331
|
|
|
327
332
|
[Apache License 2.0](LICENSE), copyright 2026 prplkane.
|
|
328
333
|
[NOTICE](NOTICE) retains attribution for adapted process documentation.
|
|
329
|
-
The license does not change the repository's private visibility.
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# ACP and Roundtable qualification — 2026-11-09
|
|
2
2
|
|
|
3
|
+
> **Addendum, 2026-11-21.** This document describes the 2026-11-09 run and is
|
|
4
|
+
> kept as history. Two things have changed since:
|
|
5
|
+
>
|
|
6
|
+
> - Since `0.3.0-beta.3` a profile can hold a model and effort default
|
|
7
|
+
> (`agentlink models` and `agentlink defaults`, described in the README).
|
|
8
|
+
> That supersedes the statement below that no effort setting is needed in
|
|
9
|
+
> AgentLink. The `CODEX_CONFIG` route used here still works.
|
|
10
|
+
> - The bridge versions in the table are the ones tested on 2026-11-09. On
|
|
11
|
+
> 2026-11-21 the maintainer's machine had `codex-acp` 2.7.0 and
|
|
12
|
+
> `claude-agent-acp` 0.109.0 installed.
|
|
13
|
+
>
|
|
14
|
+
> Saved defaults were checked live with Codex, Claude and Antigravity on
|
|
15
|
+
> Windows before `0.3.0-beta.3` was published. Each bridge confirmed the
|
|
16
|
+
> selected model and effort in its session response. The bridge versions
|
|
17
|
+
> used in that check were not recorded.
|
|
18
|
+
|
|
3
19
|
The three real providers completed text prompts and two discussion rounds through
|
|
4
20
|
AgentLink and Roundtable. The deterministic small-agent mimic did too. The live
|
|
5
21
|
Codex chairman initially reached the test's 60-second deadline. The user-requested
|
package/docs/architecture.md
CHANGED
|
@@ -44,6 +44,12 @@ sessions on the same connection read later edits. Existing sessions, resume
|
|
|
44
44
|
operations and explicit client setters pass through. The connection keeps
|
|
45
45
|
its original bridge lease throughout.
|
|
46
46
|
|
|
47
|
+
If the gateway cannot prepare a creation, for example because the profile
|
|
48
|
+
file is unreadable at that moment, it answers that request with JSON-RPC
|
|
49
|
+
error `-32603` and the AgentLink or OS code in `data.code`. The request is
|
|
50
|
+
not forwarded to the bridge, and the reason is also written to stderr. The
|
|
51
|
+
connection and its other sessions continue.
|
|
52
|
+
|
|
47
53
|
Each configured creation keeps its own outstanding request ID. The gateway
|
|
48
54
|
reuses that ID upstream after the bridge's creation response and holds the
|
|
49
55
|
downstream response until configuration finishes. It replaces only the JSON
|
|
@@ -52,9 +58,11 @@ follow the creation reply. Intermediate configuration notifications are
|
|
|
52
58
|
superseded by the setter's complete option list. Pending setup and buffered
|
|
53
59
|
notifications have per-connection limits.
|
|
54
60
|
|
|
55
|
-
The connection owns one bridge process.
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
The connection owns one bridge process. When the client closes stdin, the
|
|
62
|
+
gateway forwards EOF and allows up to five seconds for the bridge to finish
|
|
63
|
+
and report its own exit status. If the bridge is still running, the gateway
|
|
64
|
+
stops its process tree where the host supports it. Existing ACP sessions
|
|
65
|
+
stay with that process when profiles or installations change.
|
|
58
66
|
Normal shutdown drains queued responses even for slow readers. Explicit
|
|
59
67
|
termination cancels both pumps and interrupts a blocked output drain, allowing
|
|
60
68
|
the connection to release its installation lease.
|
|
@@ -158,7 +166,9 @@ Windows process-tree cleanup uses taskkill while the owned bridge is alive.
|
|
|
158
166
|
Native Job Object containment is not implemented, so descendants orphaned by a
|
|
159
167
|
previously exited parent are a known limitation. Process ownership is not a
|
|
160
168
|
sandbox. Abrupt process death may leave a lock or lease; stale locks produce a
|
|
161
|
-
diagnostic
|
|
169
|
+
diagnostic. Doctor reports a lease whose process has exited as a note, and
|
|
170
|
+
pruning removes it. A management probe, help command or installer retains
|
|
171
|
+
its result if process cleanup fails. A warning on stderr identifies the PID.
|
|
162
172
|
Very deep Python virtual environments can exceed Windows launcher limits.
|
|
163
173
|
Installation detects an interpreter path of 260 or more characters before
|
|
164
174
|
running venv/pip and requests a shorter store. No path virtualization layer,
|
package/docs/laptop-testing.md
CHANGED
|
@@ -160,6 +160,10 @@ The requested rerun used a separate temporary profile with
|
|
|
160
160
|
the same model then completed chairman synthesis in 12.2 seconds. No AgentLink
|
|
161
161
|
runtime change was needed. Bridge defaults are provider-specific; merge the
|
|
162
162
|
setting with the profile's existing configuration rather than discarding it.
|
|
163
|
+
|
|
164
|
+
Since `0.3.0-beta.3`, `agentlink defaults PROFILE --effort ID` saves the same
|
|
165
|
+
choice on the profile and checks it against the bridge's advertised levels.
|
|
166
|
+
Prefer it for new setups; the environment route above still works.
|
|
163
167
|
Choose a suitable profile default and a realistic per-call deadline before a live
|
|
164
168
|
review; do not automatically retry a timed-out verdict. Unknown usage remains unknown.
|
|
165
169
|
|
package/package.json
CHANGED
package/src/bridges.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { chmod, mkdir, open, readdir, realpath, rm, stat,
|
|
2
|
+
import { chmod, mkdir, open, readdir, realpath, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { basename, delimiter, dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
5
|
import { error, profileName, strings } from './profiles.mjs';
|
|
@@ -220,6 +220,26 @@ export class BridgeStore extends BridgeRegistry {
|
|
|
220
220
|
}
|
|
221
221
|
}, installTimeoutMs, signal);
|
|
222
222
|
}
|
|
223
|
+
async *inspectLeases() {
|
|
224
|
+
let names;
|
|
225
|
+
try { names = await readdir(this.leases); } catch (cause) { if (cause.code === 'ENOENT') return; throw cause; }
|
|
226
|
+
for (const name of names) {
|
|
227
|
+
if (!name.endsWith('.json')) continue;
|
|
228
|
+
const file = inside(this.leases, name);
|
|
229
|
+
try {
|
|
230
|
+
const lease = await readJson(file);
|
|
231
|
+
if (!Number.isSafeInteger(lease?.pid) || lease.pid < 1 || !/^[a-f0-9]{64}$/.test(lease.installKey)) {
|
|
232
|
+
throw error('INVALID_BRIDGE', 'Invalid running-connection lease.');
|
|
233
|
+
}
|
|
234
|
+
let alive = true;
|
|
235
|
+
try { process.kill(lease.pid, 0); } catch (cause) { if (cause.code === 'ESRCH') alive = false; else throw cause; }
|
|
236
|
+
yield { file, pid: lease.pid, installKey: lease.installKey, alive };
|
|
237
|
+
} catch (cause) {
|
|
238
|
+
// A connection can release its lease between readdir and readJson.
|
|
239
|
+
if (cause.code !== 'ENOENT') yield { file, error: cause };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
223
243
|
async prune({ cache = false, profiles = [] } = {}) {
|
|
224
244
|
const records = await this.list();
|
|
225
245
|
if (records.some(record => record.error)) throw error('INVALID_BRIDGE', 'Repair unreadable bridge records before pruning installations.');
|
|
@@ -228,15 +248,11 @@ export class BridgeStore extends BridgeRegistry {
|
|
|
228
248
|
if (profile.bridge) continue; // Managed profiles resolve the active record, not their old snapshot.
|
|
229
249
|
for (const key of this.referencedInstallations(profile)) used.add(key);
|
|
230
250
|
}
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
if (!Number.isSafeInteger(lease.pid) || lease.pid < 1) throw error('INVALID_BRIDGE', 'Invalid running-connection lease.');
|
|
237
|
-
let alive = true;
|
|
238
|
-
try { process.kill(lease.pid, 0); } catch (cause) { if (cause.code === 'ESRCH') alive = false; else throw cause; }
|
|
239
|
-
if (alive) used.add(lease.installKey); else await unlink(file);
|
|
251
|
+
let installations = [];
|
|
252
|
+
for await (const lease of this.inspectLeases()) {
|
|
253
|
+
if (lease.error) throw lease.error;
|
|
254
|
+
if (lease.alive) used.add(lease.installKey);
|
|
255
|
+
else await rm(lease.file, { force: true });
|
|
240
256
|
}
|
|
241
257
|
try { installations = await readdir(this.installations); } catch (cause) { if (cause.code !== 'ENOENT') throw cause; }
|
|
242
258
|
const removed = [];
|
package/src/child-process.mjs
CHANGED
|
@@ -11,7 +11,7 @@ function waitForExit(child, timeoutMs) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
async function stopTree(child) {
|
|
15
15
|
if (child.pid) {
|
|
16
16
|
if (process.platform === 'win32') {
|
|
17
17
|
if (child.exitCode === null && child.signalCode === null) {
|
|
@@ -19,7 +19,8 @@ export async function stopProcess(child) {
|
|
|
19
19
|
['/PID', String(child.pid), '/T', '/F'], { shell: false, windowsHide: true, stdio: 'ignore' });
|
|
20
20
|
await new Promise(resolveStop => {
|
|
21
21
|
const finish = () => { clearTimeout(timer); resolveStop(); };
|
|
22
|
-
|
|
22
|
+
// A busy Windows host can take several seconds to start taskkill.
|
|
23
|
+
const timer = setTimeout(() => { killer.kill(); finish(); }, 5000);
|
|
23
24
|
killer.once('error', finish); killer.once('exit', finish);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -28,6 +29,21 @@ export async function stopProcess(child) {
|
|
|
28
29
|
catch (cause) { if (cause.code !== 'ESRCH') throw cause; }
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
await waitForExit(child, 1500);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function stopProcess(child) {
|
|
36
|
+
try { await stopTree(child); }
|
|
32
37
|
finally { child.stdin?.destroy(); child.stdout?.destroy(); child.stderr?.destroy(); }
|
|
33
38
|
}
|
|
39
|
+
|
|
40
|
+
// Management commands have a result of their own. Keep it (including its
|
|
41
|
+
// error code) while reporting a separate failure to terminate the owned PID.
|
|
42
|
+
export async function finishCommand(child) {
|
|
43
|
+
try { await stopProcess(child); }
|
|
44
|
+
catch (cause) {
|
|
45
|
+
child.unref();
|
|
46
|
+
process.emitWarning('Could not confirm cleanup of child PID ' + child.pid + ': ' + cause.message,
|
|
47
|
+
{ code: 'PROCESS_STOP_FAILED' });
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/discovery.mjs
CHANGED
|
@@ -63,9 +63,11 @@ export async function inProbeDirectory(callback) {
|
|
|
63
63
|
finally {
|
|
64
64
|
if (dirname(directory) !== base || !basename(directory).startsWith('agentlink-probe-')) throw error('INVALID_PATH', 'Unexpected probe directory.');
|
|
65
65
|
// Windows may retain a just-stopped descendant's cwd for a short time.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
try { await rm(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); }
|
|
67
|
+
catch (cause) {
|
|
68
|
+
process.emitWarning('Could not remove probe directory ' + directory + ': ' + cause.message,
|
|
69
|
+
{ code: 'PROBE_CLEANUP_FAILED' });
|
|
70
|
+
}
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
package/src/doctor.mjs
CHANGED
|
@@ -34,6 +34,12 @@ export async function doctor(runtime) {
|
|
|
34
34
|
await launchFiles(record.launch);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
for await (const lease of runtime.bridges.inspectLeases()) {
|
|
38
|
+
if (lease.error) checks.push({ scope: 'lease', name: lease.file, status: 'error',
|
|
39
|
+
code: 'INVALID_LEASE', message: 'Cannot verify connection lease: ' + lease.error.message });
|
|
40
|
+
else if (!lease.alive) checks.push({ scope: 'lease', name: lease.file, status: 'note', pid: lease.pid,
|
|
41
|
+
code: 'STALE_LEASE', message: 'Connection owner has exited. Run agentlink bridge prune to remove its lease.' });
|
|
42
|
+
}
|
|
37
43
|
const lockFiles = [join(runtime.home, 'management.lock'), join(runtime.home, 'leases.lock')];
|
|
38
44
|
try {
|
|
39
45
|
for (const name of await readdir(join(runtime.home, 'locks'))) {
|
package/src/gateway.mjs
CHANGED
|
@@ -4,16 +4,32 @@ import { AcpFrames } from './wire.mjs';
|
|
|
4
4
|
import { stopProcess } from './child-process.mjs';
|
|
5
5
|
import { error, strings } from './profiles.mjs';
|
|
6
6
|
import { authMarker, terminalAuthReply } from './terminal-auth.mjs';
|
|
7
|
+
import { member, whitespace } from './json-spans.mjs';
|
|
8
|
+
|
|
9
|
+
// The reply to a session/new that AgentLink could not prepare, for example
|
|
10
|
+
// because the profile file was unreadable at that moment. The request ID is
|
|
11
|
+
// copied as raw text so large numeric IDs keep their exact bytes.
|
|
12
|
+
function sessionSetupError(source, cause) {
|
|
13
|
+
const id = source.slice(...member(source, whitespace(source, 0), 'id'));
|
|
14
|
+
// The request itself was valid, so this is an internal error (-32603), not
|
|
15
|
+
// invalid params. data.code carries the stable AgentLink or OS error code.
|
|
16
|
+
const detail = { code: -32603, message: 'AgentLink could not prepare this session: ' + cause.message,
|
|
17
|
+
data: { code: cause.code || 'SESSION_SETUP_FAILED' } };
|
|
18
|
+
return Buffer.from('{"jsonrpc":"2.0","id":' + id + ',"error":' + JSON.stringify(detail) + '}\n');
|
|
19
|
+
}
|
|
7
20
|
|
|
8
21
|
// One process/connection per caller; installed bridges and profiles are shared.
|
|
9
22
|
// No initialize, session/new, task, approval, download or discovery is injected.
|
|
10
23
|
export async function runGateway(launch, { cwd = process.cwd(), env = process.env,
|
|
11
24
|
input = process.stdin, output = process.stdout, diagnostics = process.stderr,
|
|
12
25
|
signal, readDefaults, extraArgs = [], interactive = Boolean(process.stdin.isTTY),
|
|
13
|
-
maxMessageBytes = 16 * 1024 * 1024, shutdownGraceMs
|
|
14
|
-
if (!strings(extraArgs) || !Number.isSafeInteger(shutdownGraceMs) || shutdownGraceMs < 1) {
|
|
26
|
+
maxMessageBytes = 16 * 1024 * 1024, shutdownGraceMs } = {}) {
|
|
27
|
+
if (!strings(extraArgs) || (shutdownGraceMs !== undefined && (!Number.isSafeInteger(shutdownGraceMs) || shutdownGraceMs < 1))) {
|
|
15
28
|
throw new TypeError('Invalid gateway arguments.');
|
|
16
29
|
}
|
|
30
|
+
// A healthy bridge can spend several seconds cleaning up after EOF.
|
|
31
|
+
const eofGraceMs = shutdownGraceMs ?? 5000;
|
|
32
|
+
const pipeGraceMs = shutdownGraceMs ?? 750;
|
|
17
33
|
signal?.throwIfAborted();
|
|
18
34
|
// ACP terminal-auth methods append argv to the configured launch command.
|
|
19
35
|
// Append those bytes to the bridge's base argv, not to management option parsing.
|
|
@@ -43,28 +59,44 @@ export async function runGateway(launch, { cwd = process.cwd(), env = process.en
|
|
|
43
59
|
let inputPump = Promise.resolve();
|
|
44
60
|
let outputFrames;
|
|
45
61
|
if (!terminal) {
|
|
46
|
-
let defaultsRelay, protocolVersion;
|
|
62
|
+
let defaultsRelay, protocolVersion, refusal;
|
|
47
63
|
async function prepareSession(message, source) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
try {
|
|
65
|
+
const defaults = readDefaults ? await readDefaults() : launch.defaults;
|
|
66
|
+
if (!defaults || !Object.keys(defaults).length) return;
|
|
67
|
+
if (!defaultsRelay) {
|
|
68
|
+
const { SessionDefaults } = await import('./session-defaults.mjs');
|
|
69
|
+
defaultsRelay = new SessionDefaults(frame => child.stdin.write(frame), maxMessageBytes);
|
|
70
|
+
}
|
|
71
|
+
defaultsRelay.expectSession(message, source, defaults, protocolVersion);
|
|
72
|
+
} catch (cause) {
|
|
73
|
+
// Only this creation fails. The bridge never sees it, and the other
|
|
74
|
+
// sessions on this connection keep running.
|
|
75
|
+
refusal = sessionSetupError(source, cause);
|
|
76
|
+
// The client may not show error details, so the reason also goes to the log.
|
|
77
|
+
diagnostics.write((cause.code || 'SESSION_SETUP_FAILED') + ': ' + cause.message + '\n');
|
|
53
78
|
}
|
|
54
|
-
defaultsRelay.expectSession(message, source, defaults, protocolVersion);
|
|
55
79
|
}
|
|
56
80
|
const initializeIds = new Set();
|
|
57
81
|
inputPump = pipeline(input, new AcpFrames({ maxMessageBytes, onMessage(message, source) {
|
|
58
82
|
if (message.method === 'session/new' && Object.hasOwn(message, 'id')) return prepareSession(message, source);
|
|
59
83
|
if (message.method === 'initialize' && Object.hasOwn(message, 'id')) initializeIds.add(message.id);
|
|
84
|
+
}, mapMessage() {
|
|
85
|
+
if (!refusal) return;
|
|
86
|
+
// Reply through the output pump so the frame keeps its place in the stream.
|
|
87
|
+
if (!outputFrames.writableEnded && !outputFrames.destroyed) outputFrames.push(refusal);
|
|
88
|
+
refusal = undefined;
|
|
89
|
+
return null;
|
|
60
90
|
} }), child.stdin, { signal: pumps.signal }).then(() => {
|
|
61
|
-
if (!closing
|
|
91
|
+
if (!closing && child.exitCode === null && child.signalCode === null) {
|
|
92
|
+
inputTimer = setTimeout(() => { void stop(); }, eofGraceMs);
|
|
93
|
+
}
|
|
62
94
|
}, cause => {
|
|
63
95
|
if (closing) return;
|
|
64
96
|
// A normally exiting bridge can close its stdin before the exit event.
|
|
65
97
|
// Give it time to finish and drain stdout instead of destroying its reply.
|
|
66
98
|
if (['EPIPE', 'ERR_STREAM_PREMATURE_CLOSE', 'ERR_STREAM_DESTROYED'].includes(cause.code)) {
|
|
67
|
-
if (child.exitCode === null && child.signalCode === null) inputTimer = setTimeout(() => fail(cause),
|
|
99
|
+
if (child.exitCode === null && child.signalCode === null) inputTimer = setTimeout(() => fail(cause), pipeGraceMs);
|
|
68
100
|
} else fail(cause);
|
|
69
101
|
});
|
|
70
102
|
outputFrames = new AcpFrames({ maxMessageBytes, mapMessage(message, source) {
|
|
@@ -94,13 +126,13 @@ export async function runGateway(launch, { cwd = process.cwd(), env = process.en
|
|
|
94
126
|
if (done) return;
|
|
95
127
|
if (!failure && !output.destroyed && (output.writableLength || output.writableNeedDrain || child.stdout?.readableLength ||
|
|
96
128
|
outputFrames?.readableLength || outputFrames?.writableLength)) {
|
|
97
|
-
flushTimer = setTimeout(idle,
|
|
129
|
+
flushTimer = setTimeout(idle, pipeGraceMs);
|
|
98
130
|
} else finish();
|
|
99
131
|
};
|
|
100
132
|
// end:false leaves the caller's stream open and may resolve before its
|
|
101
133
|
// final write callback; also wait for that queued output to drain.
|
|
102
134
|
outputPump.then(() => { if (failure || !output.writableLength || output.destroyed) finish(); });
|
|
103
|
-
flushTimer = setTimeout(idle,
|
|
135
|
+
flushTimer = setTimeout(idle, pipeGraceMs);
|
|
104
136
|
});
|
|
105
137
|
if (failure) throw failure;
|
|
106
138
|
return { exitCode };
|
package/src/probe.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { version } from './version.mjs';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { AcpFrames } from './wire.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { finishCommand } from './child-process.mjs';
|
|
5
5
|
import { error } from './profiles.mjs';
|
|
6
6
|
import { describeOptions, sessionSelections } from './session-options.mjs';
|
|
7
7
|
|
|
@@ -80,5 +80,5 @@ export async function probeAcp(launch, { cwd, env = process.env, defaults, timeo
|
|
|
80
80
|
child.once('exit', code => reject(error('PROCESS_EXIT', 'Agent exited during the ACP probe (' + code + ').')));
|
|
81
81
|
request('initialize', { protocolVersion: 2, capabilities: {}, info: { name: 'agentlink-discovery', version } });
|
|
82
82
|
});
|
|
83
|
-
} finally { clearTimeout(timer); signal?.removeEventListener('abort', abort); await
|
|
83
|
+
} finally { clearTimeout(timer); signal?.removeEventListener('abort', abort); await finishCommand(child); }
|
|
84
84
|
}
|
package/src/process.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { constants } from 'node:fs';
|
|
|
4
4
|
import { basename, delimiter, dirname, extname, isAbsolute, join, resolve } from 'node:path';
|
|
5
5
|
import { stripVTControlCharacters } from 'node:util';
|
|
6
6
|
import { error, strings } from './profiles.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { finishCommand } from './child-process.mjs';
|
|
8
8
|
export { stopProcess } from './child-process.mjs';
|
|
9
9
|
|
|
10
10
|
export async function resolveCommand(command, prefixArgs = [], env = process.env) {
|
|
@@ -79,7 +79,7 @@ export async function readHelp({ command, args, cwd, env = process.env, timeoutM
|
|
|
79
79
|
child.stdin.end();
|
|
80
80
|
});
|
|
81
81
|
return { code, text: stripVTControlCharacters(Buffer.concat(buffers).toString('utf8')) };
|
|
82
|
-
} finally { signal?.removeEventListener('abort', abort); await
|
|
82
|
+
} finally { signal?.removeEventListener('abort', abort); await finishCommand(child); }
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export async function runCommand(command, args, { cwd, env = process.env, timeoutMs = 180000, signal } = {}) {
|
|
@@ -107,6 +107,6 @@ export async function runCommand(command, args, { cwd, env = process.env, timeou
|
|
|
107
107
|
});
|
|
108
108
|
} finally {
|
|
109
109
|
clearTimeout(timer); signal?.removeEventListener('abort', abort);
|
|
110
|
-
await
|
|
110
|
+
await finishCommand(child);
|
|
111
111
|
}
|
|
112
112
|
}
|
package/src/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.3.0-beta.
|
|
1
|
+
export const version = '0.3.0-beta.4';
|