@e2e-dev/acp 0.1.4-nightly-20261123030205 → 0.1.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 +3 -1
- package/dist/.build.json +1 -1
- package/dist/executor.d.ts +1 -1
- package/dist/executor.js +25 -9
- package/dist/presets.d.ts +10 -0
- package/dist/presets.js +162 -14
- package/dist/session.d.ts +9 -2
- package/dist/session.js +24 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Run `agent.act` and `agent.assert` on Claude Code or Codex over the
|
|
4
4
|
[Agent Client Protocol](https://agentclientprotocol.com). The agent signs in
|
|
5
|
-
with its own login
|
|
5
|
+
with its own login or API key (`ANTHROPIC_API_KEY` for Claude Code;
|
|
6
|
+
`OPENAI_API_KEY` for Codex, which saves it as its login when it has none),
|
|
7
|
+
so e2e needs no model provider.
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm install -D @e2e-dev/acp @agentclientprotocol/claude-agent-acp
|
package/dist/.build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.1.4
|
|
1
|
+
{"version":"0.1.4"}
|
package/dist/executor.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ import type { AcpAgentOptions, AcpOptions } from './types.ts';
|
|
|
9
9
|
export declare function acp(options: AcpOptions): StepExecutor;
|
|
10
10
|
/** Claude Code through Zed's adapter (`@agentclientprotocol/claude-agent-acp`), signed in with your `claude` login. */
|
|
11
11
|
export declare function claudeCode(options?: AcpAgentOptions): StepExecutor;
|
|
12
|
-
/** Codex through its adapter (`@agentclientprotocol/codex-acp`), signed in with your `codex` login. */
|
|
12
|
+
/** Codex through its adapter (`@agentclientprotocol/codex-acp`), signed in with your `codex` login, or with `OPENAI_API_KEY` when Codex has none. */
|
|
13
13
|
export declare function codex(options?: AcpAgentOptions): StepExecutor;
|
package/dist/executor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { AgentError } from 'e2e';
|
|
3
|
-
import { BASE_RULES, VERDICT_RULES } from 'e2e/agent';
|
|
3
|
+
import { BASE_RULES, redactSecrets, redactStepText, registerProviderKeys, VERDICT_RULES } from 'e2e/agent';
|
|
4
4
|
import { ConfigurationError } from 'e2e/engine';
|
|
5
|
-
import { claudeCodeLaunch, codexLaunch } from './presets.js';
|
|
5
|
+
import { claudeCodeLaunch, codexLaunch, registerSavedCodexLogin } from './presets.js';
|
|
6
6
|
import { startSession } from './session.js';
|
|
7
7
|
import { activeStep, missingTools, openingScreen, stepTools, verdictOf } from './tools.js';
|
|
8
8
|
/** What the session is, before the built-in agent's rules for the same tools. */
|
|
@@ -36,11 +36,22 @@ export function acp(options) {
|
|
|
36
36
|
export function claudeCode(options = {}) {
|
|
37
37
|
return executor(options.name ?? 'claude-code', options, claudeCodeLaunch(options));
|
|
38
38
|
}
|
|
39
|
-
/** Codex through its adapter (`@agentclientprotocol/codex-acp`), signed in with your `codex` login. */
|
|
39
|
+
/** Codex through its adapter (`@agentclientprotocol/codex-acp`), signed in with your `codex` login, or with `OPENAI_API_KEY` when Codex has none. */
|
|
40
40
|
export function codex(options = {}) {
|
|
41
|
-
return executor(options.name ?? 'codex', options, codexLaunch(options));
|
|
41
|
+
return executor(options.name ?? 'codex', options, codexLaunch(options), () => registerSavedCodexLogin(options.env));
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `registerLogin` has the run redact the login the agent keeps on disk. It
|
|
45
|
+
* runs once when the executor is built, for a login saved before the run,
|
|
46
|
+
* then for each step once the agent is up, since the agent renews a login
|
|
47
|
+
* between turns, and again once the turn is over, before anything the
|
|
48
|
+
* agent said in it is returned.
|
|
49
|
+
*/
|
|
50
|
+
function executor(name, options, launch, registerLogin = () => undefined) {
|
|
51
|
+
// A key only the agent's own `env` holds, known before the first step's text is built.
|
|
52
|
+
registerProviderKeys(options.env ?? {});
|
|
53
|
+
// A login the agent saved before this run, known before its first start: that start's stderr or the first step's text may quote it.
|
|
54
|
+
registerLogin();
|
|
44
55
|
// Where an attempt's session lives in `attempt.memory`: one key per executor, so two ACP agents never share a session.
|
|
45
56
|
const memoryKey = `@e2e-dev/acp.session.${randomUUID()}`;
|
|
46
57
|
return {
|
|
@@ -48,10 +59,12 @@ function executor(name, options, launch) {
|
|
|
48
59
|
version: '1',
|
|
49
60
|
cache: 'inherit',
|
|
50
61
|
async runStep(ctx) {
|
|
51
|
-
|
|
62
|
+
// Once the agent has started, or failed to: signing in is when it writes a login. Before any of the step's text is built.
|
|
63
|
+
const { held, session } = await ready(ctx, launch, memoryKey).finally(registerLogin);
|
|
52
64
|
ctx.signal.throwIfAborted();
|
|
53
65
|
const active = activeStep(ctx);
|
|
54
|
-
|
|
66
|
+
// With the step's own redactor, and only now: `system` is the config's text, which core never saw, and a key the agent's start or its saved login made known may be in step text core built before it knew the key.
|
|
67
|
+
const text = redactStepText(ctx, await untilAborted(stepMessage(active, held.tools, held.introduced ? undefined : [RULES, options.system, ctx.agentContext]), ctx.signal));
|
|
55
68
|
// A step that ended while its screen was read sends no prompt, which no cancel would reach.
|
|
56
69
|
ctx.signal.throwIfAborted();
|
|
57
70
|
held.introduced = true;
|
|
@@ -74,6 +87,7 @@ function executor(name, options, launch) {
|
|
|
74
87
|
if (held.slot.active === active)
|
|
75
88
|
held.slot.active = undefined;
|
|
76
89
|
ctx.signal.removeEventListener('abort', cancel);
|
|
90
|
+
registerLogin();
|
|
77
91
|
}
|
|
78
92
|
ctx.attachTranscript(transcript(text, active, report));
|
|
79
93
|
if (!ctx.signal.aborted)
|
|
@@ -263,11 +277,13 @@ function ownToolUsed(title) {
|
|
|
263
277
|
};
|
|
264
278
|
}
|
|
265
279
|
function noConclusion(report) {
|
|
266
|
-
|
|
280
|
+
// Redacted whole, before the last line is taken and cut: a value can span lines, and half a key is no longer a match.
|
|
281
|
+
const text = redactSecrets(report.text.trim());
|
|
282
|
+
const said = text.slice(text.lastIndexOf('\n') + 1).slice(0, 300);
|
|
267
283
|
return {
|
|
268
284
|
status: 'failed',
|
|
269
285
|
errorCode: 'STEP_NO_CONCLUSION',
|
|
270
|
-
summary: `The agent ended its turn (${report.stopReason}) without complete_step${said ===
|
|
286
|
+
summary: `The agent ended its turn (${report.stopReason}) without complete_step${said === '' ? '' : `: ${said}`}`,
|
|
271
287
|
};
|
|
272
288
|
}
|
|
273
289
|
function transcript(prompt, active, report) {
|
package/dist/presets.d.ts
CHANGED
|
@@ -16,3 +16,13 @@ export declare function claudeCodeLaunch(options: AcpAgentOptions): () => Promis
|
|
|
16
16
|
* subagent, which fails the step like any tool of its own.
|
|
17
17
|
*/
|
|
18
18
|
export declare function codexLaunch(options: AcpAgentOptions): () => Promise<AgentLaunch>;
|
|
19
|
+
/**
|
|
20
|
+
* Has the run redact the login Codex saved in `CODEX_HOME/auth.json`: a key
|
|
21
|
+
* from an earlier `codex login --with-api-key`, which need not be the
|
|
22
|
+
* environment's, or the tokens of a ChatGPT login. Codex signs in with it
|
|
23
|
+
* ahead of any key, and a provider that quotes it back would otherwise put
|
|
24
|
+
* it in the report. A login in the OS keyring cannot be read, and is not
|
|
25
|
+
* redacted; nor is a file that is no login: not a regular file, or larger
|
|
26
|
+
* than any login.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerSavedCodexLogin(env: Readonly<Record<string, string>> | undefined): void;
|
package/dist/presets.js
CHANGED
|
@@ -5,18 +5,38 @@
|
|
|
5
5
|
* from the working directory up, never fetched by name at run time.
|
|
6
6
|
*/
|
|
7
7
|
import { execFile } from 'node:child_process';
|
|
8
|
-
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
8
|
+
import { closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, realpathSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
9
10
|
import { createRequire } from 'node:module';
|
|
10
11
|
import { dirname, join, parse } from 'node:path';
|
|
11
12
|
import { promisify } from 'node:util';
|
|
13
|
+
import { registerProviderKey } from 'e2e/agent';
|
|
12
14
|
import { ConfigurationError } from 'e2e/engine';
|
|
13
15
|
import { z } from 'zod';
|
|
14
|
-
import {
|
|
16
|
+
import { agentEnvironment } from './session.js';
|
|
15
17
|
const execFileAsync = promisify(execFile);
|
|
16
18
|
/** What `codex mcp list --json` prints, as far as the preset reads it. */
|
|
17
19
|
const CodexServerList = z.array(z.object({ name: z.string() }));
|
|
18
20
|
/** The `bin` field of a package manifest. */
|
|
19
21
|
const PackageBin = z.object({ bin: z.union([z.string(), z.record(z.string(), z.string())]).optional() });
|
|
22
|
+
/** The credential Codex ACP reads from an explicit API-key auth request. */
|
|
23
|
+
const CodexApiKeyRequest = z.object({
|
|
24
|
+
methodId: z.literal('api-key'),
|
|
25
|
+
_meta: z.object({ 'api-key': z.object({ apiKey: z.string() }) }),
|
|
26
|
+
});
|
|
27
|
+
function registerCodexRequestKey(request) {
|
|
28
|
+
let decoded;
|
|
29
|
+
try {
|
|
30
|
+
decoded = JSON.parse(request);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// The adapter owns validation and gets the original text.
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const parsed = CodexApiKeyRequest.safeParse(decoded);
|
|
37
|
+
if (parsed.success)
|
|
38
|
+
registerProviderKey('codex.api-key', parsed.data['_meta']['api-key'].apiKey);
|
|
39
|
+
}
|
|
20
40
|
/** Claude Code with no built-in tools, no user or project settings or MCP servers, and no saved session. */
|
|
21
41
|
export function claudeCodeLaunch(options) {
|
|
22
42
|
const bin = adapterBin('@agentclientprotocol/claude-agent-acp', 'claude-agent-acp');
|
|
@@ -51,23 +71,149 @@ export function claudeCodeLaunch(options) {
|
|
|
51
71
|
export function codexLaunch(options) {
|
|
52
72
|
const pkg = adapterPackage('@agentclientprotocol/codex-acp');
|
|
53
73
|
const bin = binOf(pkg, 'codex-acp');
|
|
54
|
-
let
|
|
55
|
-
return () => {
|
|
56
|
-
|
|
74
|
+
let servers;
|
|
75
|
+
return async () => {
|
|
76
|
+
servers ??= codexServers(pkg, options.env);
|
|
77
|
+
servers.catch(() => {
|
|
78
|
+
servers = undefined;
|
|
79
|
+
});
|
|
80
|
+
const config = JSON.stringify(codexConfig(await servers));
|
|
81
|
+
// Read at each session, so a request or key set after the first one counts, and pinned for it.
|
|
82
|
+
const auth = codexAuth(options.env);
|
|
83
|
+
return {
|
|
57
84
|
command: process.execPath,
|
|
58
85
|
args: [bin],
|
|
59
|
-
env: { ...options.env, CODEX_CONFIG:
|
|
86
|
+
env: { ...options.env, ...auth.env, CODEX_CONFIG: config },
|
|
60
87
|
model: options.model,
|
|
61
88
|
mode: 'read-only',
|
|
62
|
-
signIn:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
launch = undefined;
|
|
66
|
-
});
|
|
67
|
-
return launch;
|
|
89
|
+
signIn: auth.signIn,
|
|
90
|
+
loginRefused: auth.loginRefused,
|
|
91
|
+
};
|
|
68
92
|
};
|
|
69
93
|
}
|
|
70
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Signs Codex in with an OpenAI API key when one is set, in `env` or the
|
|
96
|
+
* runner's environment, and no `DEFAULT_AUTH_REQUEST` is. The adapter
|
|
97
|
+
* takes the first nonblank of `CODEX_API_KEY` and `OPENAI_API_KEY`, but
|
|
98
|
+
* logs in with it only when the client asks; `DEFAULT_AUTH_REQUEST` asks
|
|
99
|
+
* whenever Codex has no login of its own. Codex then stores the key as
|
|
100
|
+
* its login, as `codex login --with-api-key` does. The request names the
|
|
101
|
+
* method only.
|
|
102
|
+
*
|
|
103
|
+
* The adapter's log, which `APP_SERVER_LOGS` turns on, records the
|
|
104
|
+
* request at startup and the login call it makes, key included, in plain
|
|
105
|
+
* text. So with that log on the adapter gets no request at all, the
|
|
106
|
+
* user's own included: a saved login still works, and a session Codex
|
|
107
|
+
* refuses says why. A variable in `env` replaces the runner's, blank
|
|
108
|
+
* included, so a config can keep a key from Codex; a blank request or key
|
|
109
|
+
* then counts as none, and none reaches the adapter empty, since the
|
|
110
|
+
* adapter parses a request of spaces and exits. Every variable the decision read is pinned,
|
|
111
|
+
* an unset one as empty, which the adapter reads the same way, so the
|
|
112
|
+
* agent starts on what was decided even if the environment changes
|
|
113
|
+
* before it spawns.
|
|
114
|
+
*/
|
|
115
|
+
function codexAuth(env) {
|
|
116
|
+
const value = (name) => (env !== undefined && Object.hasOwn(env, name) ? env[name] : process.env[name]) ?? '';
|
|
117
|
+
const nonblank = (name) => (value(name).trim() === '' ? '' : value(name));
|
|
118
|
+
const pinned = {
|
|
119
|
+
CODEX_API_KEY: nonblank('CODEX_API_KEY'),
|
|
120
|
+
OPENAI_API_KEY: nonblank('OPENAI_API_KEY'),
|
|
121
|
+
DEFAULT_AUTH_REQUEST: nonblank('DEFAULT_AUTH_REQUEST'),
|
|
122
|
+
APP_SERVER_LOGS: value('APP_SERVER_LOGS'),
|
|
123
|
+
};
|
|
124
|
+
const logged = pinned['APP_SERVER_LOGS'] !== '';
|
|
125
|
+
const request = pinned['DEFAULT_AUTH_REQUEST'] !== '';
|
|
126
|
+
const keyName = pinned['CODEX_API_KEY'] === '' ? 'OPENAI_API_KEY' : 'CODEX_API_KEY';
|
|
127
|
+
const signIn = `run \`codex login\`, or set ${keyName}`;
|
|
128
|
+
const freshAction = request ? 'fix DEFAULT_AUTH_REQUEST' : `set a working ${keyName}`;
|
|
129
|
+
const withLoggingDisabled = `unset APP_SERVER_LOGS and ${freshAction}`;
|
|
130
|
+
const fresh = logged ? `\`codex login\`, or ${withLoggingDisabled}` : `\`codex login\`${request ? ',' : ''} or ${freshAction}`;
|
|
131
|
+
const loginRefused = `the model provider refused Codex's credentials. If Codex signed in with a saved login or key, run \`codex logout\` first, then ${fresh}. If they come from a custom model provider's key, fix that key`;
|
|
132
|
+
const withoutRequest = { ...pinned, DEFAULT_AUTH_REQUEST: '' };
|
|
133
|
+
const key = pinned['CODEX_API_KEY'] !== '' || pinned['OPENAI_API_KEY'] !== '';
|
|
134
|
+
// The adapter logs whenever the variable is not empty, spaces included.
|
|
135
|
+
if (logged && (request || key)) {
|
|
136
|
+
return {
|
|
137
|
+
env: withoutRequest,
|
|
138
|
+
loginRefused,
|
|
139
|
+
signIn: 'APP_SERVER_LOGS is set, and the Codex adapter would write sign-in credentials to its log in plain text, so e2e passes it no sign-in request: unset APP_SERVER_LOGS, or run `codex login`',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (request) {
|
|
143
|
+
registerCodexRequestKey(pinned['DEFAULT_AUTH_REQUEST']);
|
|
144
|
+
return { env: pinned, signIn: 'the DEFAULT_AUTH_REQUEST you set did not sign Codex in: fix or unset it, or run `codex login`', loginRefused };
|
|
145
|
+
}
|
|
146
|
+
if (!key) {
|
|
147
|
+
return { env: withoutRequest, signIn: logged ? 'run `codex login`, or unset APP_SERVER_LOGS and set OPENAI_API_KEY' : signIn, loginRefused };
|
|
148
|
+
}
|
|
149
|
+
return { env: { ...pinned, DEFAULT_AUTH_REQUEST: JSON.stringify({ methodId: 'api-key' }) }, signIn, loginRefused };
|
|
150
|
+
}
|
|
151
|
+
/** More than any `auth.json` holds: a login with its tokens is a few kilobytes. */
|
|
152
|
+
const MAX_SAVED_LOGIN_BYTES = 1_048_576;
|
|
153
|
+
/** What Codex keeps of a login in `auth.json`, as far as it is a credential. */
|
|
154
|
+
const CodexSavedLogin = z.object({
|
|
155
|
+
OPENAI_API_KEY: z.string().nullish().catch(undefined),
|
|
156
|
+
tokens: z
|
|
157
|
+
.object({
|
|
158
|
+
id_token: z.string().nullish().catch(undefined),
|
|
159
|
+
access_token: z.string().nullish().catch(undefined),
|
|
160
|
+
refresh_token: z.string().nullish().catch(undefined),
|
|
161
|
+
})
|
|
162
|
+
.nullish()
|
|
163
|
+
.catch(undefined),
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* Has the run redact the login Codex saved in `CODEX_HOME/auth.json`: a key
|
|
167
|
+
* from an earlier `codex login --with-api-key`, which need not be the
|
|
168
|
+
* environment's, or the tokens of a ChatGPT login. Codex signs in with it
|
|
169
|
+
* ahead of any key, and a provider that quotes it back would otherwise put
|
|
170
|
+
* it in the report. A login in the OS keyring cannot be read, and is not
|
|
171
|
+
* redacted; nor is a file that is no login: not a regular file, or larger
|
|
172
|
+
* than any login.
|
|
173
|
+
*/
|
|
174
|
+
export function registerSavedCodexLogin(env) {
|
|
175
|
+
// Where the agent will look, from the environment it starts with: its CODEX_HOME, an empty one being none, else `.codex` in its home.
|
|
176
|
+
const given = (name) => env?.[name] ?? process.env[name];
|
|
177
|
+
const home = given('CODEX_HOME') || join(given('HOME') || homedir(), '.codex');
|
|
178
|
+
let saved;
|
|
179
|
+
try {
|
|
180
|
+
// No file, or one that is no login, parses as nothing and is refused here like any other shape.
|
|
181
|
+
saved = CodexSavedLogin.parse(JSON.parse(readBounded(join(home, 'auth.json')) ?? 'null'));
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// No saved login, or one this version cannot read.
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
for (const [name, value] of [
|
|
188
|
+
['codex.api-key', saved.OPENAI_API_KEY],
|
|
189
|
+
['codex.id-token', saved.tokens?.id_token],
|
|
190
|
+
['codex.access-token', saved.tokens?.access_token],
|
|
191
|
+
['codex.refresh-token', saved.tokens?.refresh_token],
|
|
192
|
+
]) {
|
|
193
|
+
registerProviderKey(name, value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The text of a regular file of at most `MAX_SAVED_LOGIN_BYTES`, checked and
|
|
198
|
+
* read through one open file, so what is read is what was checked. Opened
|
|
199
|
+
* without waiting: a pipe in the file's place has no writer to wait for.
|
|
200
|
+
* `undefined` for a file that is neither; throws where there is none.
|
|
201
|
+
*/
|
|
202
|
+
function readBounded(file) {
|
|
203
|
+
const descriptor = openSync(file, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
204
|
+
try {
|
|
205
|
+
const stats = fstatSync(descriptor);
|
|
206
|
+
const { size } = stats;
|
|
207
|
+
if (!stats.isFile() || size > MAX_SAVED_LOGIN_BYTES)
|
|
208
|
+
return undefined;
|
|
209
|
+
const bytes = Buffer.alloc(size);
|
|
210
|
+
return bytes.subarray(0, readSync(descriptor, bytes, 0, size, 0)).toString();
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
closeSync(descriptor);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** The Codex features that give the agent a tool of its own, and shell snapshots, which copy the shell's environment, keys included, to disk. */
|
|
71
217
|
const CODEX_FEATURES_OFF = [
|
|
72
218
|
'apps',
|
|
73
219
|
'browser_use',
|
|
@@ -78,6 +224,8 @@ const CODEX_FEATURES_OFF = [
|
|
|
78
224
|
'multi_agent',
|
|
79
225
|
'multi_agent_v2',
|
|
80
226
|
'plugins',
|
|
227
|
+
'shell_snapshot',
|
|
228
|
+
'shell_snapshot_v2',
|
|
81
229
|
'shell_tool',
|
|
82
230
|
'skill_search',
|
|
83
231
|
'tool_suggest',
|
|
@@ -99,7 +247,7 @@ async function codexServers(adapter, env) {
|
|
|
99
247
|
: [codexPath, []];
|
|
100
248
|
try {
|
|
101
249
|
const { stdout } = await execFileAsync(command, [...args, 'mcp', 'list', '--json'], {
|
|
102
|
-
env:
|
|
250
|
+
env: agentEnvironment({ ...process.env, ...env }),
|
|
103
251
|
timeout: 30_000,
|
|
104
252
|
});
|
|
105
253
|
return CodexServerList.parse(JSON.parse(stdout)).map((server) => server.name);
|
package/dist/session.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface AgentLaunch {
|
|
|
21
21
|
readonly sessionMeta?: Readonly<Record<string, unknown>> | undefined;
|
|
22
22
|
/** How the user signs the agent in, for a session it refuses until they do. */
|
|
23
23
|
readonly signIn?: string | undefined;
|
|
24
|
+
/** What to do when a turn is refused although the session opened: credentials the provider no longer accepts. */
|
|
25
|
+
readonly loginRefused?: string | undefined;
|
|
24
26
|
}
|
|
25
27
|
/** What one prompt turn reported. */
|
|
26
28
|
export interface TurnReport {
|
|
@@ -54,5 +56,10 @@ export interface AcpSession {
|
|
|
54
56
|
* that runs without asking, as soon as it starts or finishes.
|
|
55
57
|
*/
|
|
56
58
|
export declare function startSession(launch: AgentLaunch, tools: readonly ServedTool[], signal: AbortSignal, onOwnTool?: (title: string) => void): Promise<AcpSession>;
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
+
/**
|
|
60
|
+
* What a process an executor starts gets of `env`: not the variables e2e
|
|
61
|
+
* reads secrets from, wherever they came from, and not `NODE_DEBUG`, which
|
|
62
|
+
* makes a Node agent print the environment of each process it starts in
|
|
63
|
+
* turn, keys included, to its log or to the run's output.
|
|
64
|
+
*/
|
|
65
|
+
export declare function agentEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
package/dist/session.js
CHANGED
|
@@ -15,6 +15,7 @@ import { rm } from 'node:fs/promises';
|
|
|
15
15
|
import { tmpdir } from 'node:os';
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { Readable, Writable } from 'node:stream';
|
|
18
|
+
import { redactSecrets, registerProviderKeys } from 'e2e/agent';
|
|
18
19
|
import { ConfigurationError } from 'e2e/engine';
|
|
19
20
|
import { MCP_SERVER_NAME, serveTools } from './mcp.js';
|
|
20
21
|
/** Tool kinds an agent uses for its own tools and subagents; never a call of ours without an adapter's mark. */
|
|
@@ -23,6 +24,8 @@ const BUILT_IN_KINDS = new Set(['read', 'edit', 'delete', 'move', 'search', 'exe
|
|
|
23
24
|
const AUTH_REQUIRED = -32000;
|
|
24
25
|
/** Variables e2e reads secret and credential values from: the agent never needs them. Any case, since Windows reads names that way. */
|
|
25
26
|
const SECRET_VARIABLE = /^E2E_(?:SECRET|USER)_/i;
|
|
27
|
+
/** How much of the agent's stderr is kept for the error of an agent that exits. */
|
|
28
|
+
const STDERR_KEPT = 65_536;
|
|
26
29
|
/**
|
|
27
30
|
* Starts the agent, initializes it, and opens a session with the tools.
|
|
28
31
|
* Aborting `signal` before the session is open stops the agent and the tool
|
|
@@ -42,13 +45,17 @@ export async function startSession(launch, tools, signal, onOwnTool = () => unde
|
|
|
42
45
|
serving.catch(() => undefined);
|
|
43
46
|
const toolServerFailed = serving.then(started => started.failed);
|
|
44
47
|
toolServerFailed.catch(() => undefined);
|
|
48
|
+
const env = agentEnvironment({ ...process.env, ...launch.env });
|
|
49
|
+
// A key the agent gets from its own `env` and not the runner's is one the run has not seen yet.
|
|
50
|
+
registerProviderKeys(env);
|
|
45
51
|
const child = spawn(launch.command, [...launch.args], {
|
|
46
52
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
47
|
-
env
|
|
53
|
+
env,
|
|
48
54
|
});
|
|
49
55
|
let stderr = '';
|
|
50
|
-
child.stderr.on('data', (data) => {
|
|
51
|
-
|
|
56
|
+
child.stderr.setEncoding('utf8').on('data', (data) => {
|
|
57
|
+
// Kept raw, and far longer than what is shown of it: a key in pieces across two writes is whole again here.
|
|
58
|
+
stderr = (stderr + data).slice(-STDERR_KEPT);
|
|
52
59
|
});
|
|
53
60
|
// A dead agent must not take the test worker down with a pipe error.
|
|
54
61
|
child.stdin.on('error', () => undefined);
|
|
@@ -145,6 +152,9 @@ export async function startSession(launch, tools, signal, onOwnTool = () => unde
|
|
|
145
152
|
const costBefore = turn.cost;
|
|
146
153
|
const started = Date.now();
|
|
147
154
|
const response = await Promise.race([agent.request(methods.agent.session.prompt, { sessionId, prompt: [{ type: 'text', text }] }), toolServerFailed, exited]).catch((error) => {
|
|
155
|
+
if (isAuthRequired(error) && launch.loginRefused !== undefined) {
|
|
156
|
+
throw new Error(`the agent's credentials were refused: ${launch.loginRefused}`, { cause: error });
|
|
157
|
+
}
|
|
148
158
|
throw withDetails(error);
|
|
149
159
|
});
|
|
150
160
|
const costUsd = turn.cost === undefined ? undefined : turn.cost - (costBefore ?? 0);
|
|
@@ -174,9 +184,14 @@ export async function startSession(launch, tools, signal, onOwnTool = () => unde
|
|
|
174
184
|
},
|
|
175
185
|
};
|
|
176
186
|
}
|
|
177
|
-
/**
|
|
178
|
-
|
|
179
|
-
|
|
187
|
+
/**
|
|
188
|
+
* What a process an executor starts gets of `env`: not the variables e2e
|
|
189
|
+
* reads secrets from, wherever they came from, and not `NODE_DEBUG`, which
|
|
190
|
+
* makes a Node agent print the environment of each process it starts in
|
|
191
|
+
* turn, keys included, to its log or to the run's output.
|
|
192
|
+
*/
|
|
193
|
+
export function agentEnvironment(env) {
|
|
194
|
+
return Object.fromEntries(Object.entries(env).filter(([name]) => !SECRET_VARIABLE.test(name) && name.toUpperCase() !== 'NODE_DEBUG'));
|
|
180
195
|
}
|
|
181
196
|
/** `error` with what the agent said about it beyond its message appended, if anything. */
|
|
182
197
|
function withDetails(error) {
|
|
@@ -295,6 +310,8 @@ const MCP_CALL_FIELDS = new Set(['server', 'serverName', 'server_name', 'tool',
|
|
|
295
310
|
function defined(value) {
|
|
296
311
|
return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined && field !== null));
|
|
297
312
|
}
|
|
313
|
+
/** The end of the last line the agent wrote. Redacted whole, before the line is taken and cut: a value can span lines, and half a key is no longer a match. */
|
|
298
314
|
function lastLine(text) {
|
|
299
|
-
|
|
315
|
+
const written = redactSecrets(text.trim());
|
|
316
|
+
return written.slice(written.lastIndexOf('\n') + 1).slice(-2000);
|
|
300
317
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e2e-dev/acp",
|
|
3
|
-
"version": "0.1.4
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Run e2e agent steps on a coding agent you already use (Claude Code, Codex, Cursor, ...) over the Agent Client Protocol",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"e2e",
|
|
@@ -40,17 +40,17 @@
|
|
|
40
40
|
"NOTICE"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@agentclientprotocol/sdk": "2.
|
|
43
|
+
"@agentclientprotocol/sdk": "2.9.1",
|
|
44
44
|
"@modelcontextprotocol/server": "2.4.0",
|
|
45
45
|
"zod": "4.6.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"e2e": "0.25.0
|
|
48
|
+
"e2e": ">=0.25.0 <1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/client": "2.4.0",
|
|
52
52
|
"@types/node": "26.6.6",
|
|
53
|
-
"e2e": "0.25.0
|
|
53
|
+
"e2e": "0.25.0",
|
|
54
54
|
"typescript": "7.0.2",
|
|
55
55
|
"vitest": "5.1.1"
|
|
56
56
|
},
|