@e2e-dev/acp 0.0.0-stage → 0.0.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +28 -2
- package/dist/.build.json +1 -0
- package/dist/executor.d.ts +13 -0
- package/dist/executor.js +284 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/mcp.d.ts +35 -0
- package/dist/mcp.js +89 -0
- package/dist/presets.d.ts +18 -0
- package/dist/presets.js +136 -0
- package/dist/session.d.ts +58 -0
- package/dist/session.js +287 -0
- package/dist/tools.d.ts +53 -0
- package/dist/tools.js +131 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +1 -0
- package/package.json +62 -3
package/dist/tools.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools a session offers: the built-in agent's action tools
|
|
3
|
+
* (`createGrammarTools` from `e2e/agent`) and its `complete_step`
|
|
4
|
+
* (`createVerdictTool`). An ACP session lists its tools once, while e2e
|
|
5
|
+
* builds them per step, so the session lists them from its first step and
|
|
6
|
+
* each call runs the active step's own tool of that name. Every action goes
|
|
7
|
+
* through `ctx.actions`, where the runner authorizes, counts, and records
|
|
8
|
+
* it, so steps replay from the cache as the built-in agent's do.
|
|
9
|
+
*/
|
|
10
|
+
import { createGrammarTools, createVerdictTool, isRuntimeHardStop } from 'e2e/agent';
|
|
11
|
+
/** Tools that change nothing in the app, so an assertion may use them. */
|
|
12
|
+
const READ_ONLY = new Set(['observe', 'screenshot', 'scroll', 'scroll_to', 'hover', 'hover_at']);
|
|
13
|
+
/** The step a session starts serving, with nothing concluded yet. */
|
|
14
|
+
export function activeStep(ctx) {
|
|
15
|
+
return { ctx, conclusion: createVerdictTool(), halted: undefined, denied: undefined, calls: [] };
|
|
16
|
+
}
|
|
17
|
+
/** The verdict the agent concluded the step with, if it did. */
|
|
18
|
+
export function verdictOf(active) {
|
|
19
|
+
return active.conclusion.verdict();
|
|
20
|
+
}
|
|
21
|
+
/** The active step's action tools, built once per step so its screens report changes against the one before. */
|
|
22
|
+
function toolsOf(active) {
|
|
23
|
+
// The guard runs when a call's turn in the queue comes, so a call batched behind the verdict or a stop is skipped.
|
|
24
|
+
active.tools ??= createGrammarTools(active.ctx, { guard: (body) => (stopped(active) ? Promise.resolve(STEP_ENDED) : body()) });
|
|
25
|
+
return active.tools;
|
|
26
|
+
}
|
|
27
|
+
/** Whether the step takes no more actions: concluded, halted by a runtime error, or stopped for a tool of the agent's own. */
|
|
28
|
+
function stopped(active) {
|
|
29
|
+
return active.conclusion.concluded() || active.halted !== undefined || active.denied !== undefined;
|
|
30
|
+
}
|
|
31
|
+
const STEP_ENDED = 'The step has ended. Wait for the next instruction.';
|
|
32
|
+
/** Runs one tool and returns what it answered. */
|
|
33
|
+
async function run(tools, name, input) {
|
|
34
|
+
const tool = tools[name];
|
|
35
|
+
if (tool?.execute === undefined)
|
|
36
|
+
throw new Error(unavailable(name));
|
|
37
|
+
return (await tool.execute(input, { toolCallId: name, messages: [] }));
|
|
38
|
+
}
|
|
39
|
+
/** The step's first screen, whole: the first look of its action tools, which later results report changes against. */
|
|
40
|
+
export async function openingScreen(active) {
|
|
41
|
+
const output = await run(toolsOf(active), 'observe', {});
|
|
42
|
+
return typeof output === 'string' ? output : output.text;
|
|
43
|
+
}
|
|
44
|
+
/** The listed tools the active step does not offer, by the reason it would give. */
|
|
45
|
+
export function missingTools(active, listed) {
|
|
46
|
+
const own = toolsOf(active);
|
|
47
|
+
return listed.filter((tool) => tool.name !== 'complete_step' && own[tool.name] === undefined).map((tool) => `${tool.name} (${unavailable(tool.name)})`);
|
|
48
|
+
}
|
|
49
|
+
/** The session's tools, listed from its first step. */
|
|
50
|
+
export function stepTools(slot, first) {
|
|
51
|
+
const current = (name) => {
|
|
52
|
+
const active = slot.active;
|
|
53
|
+
if (active === undefined || stopped(active)) {
|
|
54
|
+
throw new Error('No step is active. Wait for the next instruction.');
|
|
55
|
+
}
|
|
56
|
+
active.calls.push(name);
|
|
57
|
+
return active;
|
|
58
|
+
};
|
|
59
|
+
/** Runs a tool body against the active step; a runtime error ends the turn, anything else goes back to the agent as the call's error. */
|
|
60
|
+
const guarded = async (name, body) => {
|
|
61
|
+
let active;
|
|
62
|
+
try {
|
|
63
|
+
active = current(name);
|
|
64
|
+
return await body(active);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (active !== undefined && isRuntimeHardStop(error)) {
|
|
68
|
+
active.halted = error;
|
|
69
|
+
slot.halt();
|
|
70
|
+
return { text: `The step has ended (${error.code}). Stop and wait for the next instruction.`, isError: true };
|
|
71
|
+
}
|
|
72
|
+
return { text: `${name} failed: ${firstLine(error)}`, isError: true };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const tools = [];
|
|
76
|
+
for (const [name, tool] of Object.entries(listing(first))) {
|
|
77
|
+
const readOnly = READ_ONLY.has(name);
|
|
78
|
+
tools.push({
|
|
79
|
+
name,
|
|
80
|
+
description: name === 'type_secret' ? TYPE_SECRET : (tool.description ?? name),
|
|
81
|
+
inputSchema: tool.inputSchema,
|
|
82
|
+
readOnly,
|
|
83
|
+
run: (args) => guarded(name, async (active) => {
|
|
84
|
+
if (!readOnly && active.ctx.step.kind === 'assert') {
|
|
85
|
+
throw new Error('this step is an assertion: read the screen and conclude, do not change it');
|
|
86
|
+
}
|
|
87
|
+
return result(await run(toolsOf(active), name, args));
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const conclusion = createVerdictTool().tool;
|
|
92
|
+
tools.push({
|
|
93
|
+
name: 'complete_step',
|
|
94
|
+
description: conclusion.description ?? 'complete_step',
|
|
95
|
+
inputSchema: conclusion.inputSchema,
|
|
96
|
+
readOnly: true,
|
|
97
|
+
run: (args) => guarded('complete_step', async (active) => {
|
|
98
|
+
const answer = await run({ complete_step: active.conclusion.tool }, 'complete_step', args);
|
|
99
|
+
const text = typeof answer === 'string' ? answer : answer.text;
|
|
100
|
+
return { text: active.conclusion.concluded() ? `${text} Wait for the next instruction.` : text };
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
return tools;
|
|
104
|
+
}
|
|
105
|
+
/** Listed in place of the grammar's own description, which names one step's secrets. */
|
|
106
|
+
const TYPE_SECRET = 'Fill one declared secret into an input by its name; the plaintext never passes through you. A password fills only a password field; a generic-secret fills any editable input. The step message lists the secrets it declares.';
|
|
107
|
+
/**
|
|
108
|
+
* Every action tool any step of the attempt can get: the first step's, with
|
|
109
|
+
* `type_secret` added. It is built only for a step that declares secrets; a
|
|
110
|
+
* call of it where the active step has none says why.
|
|
111
|
+
*/
|
|
112
|
+
function listing(first) {
|
|
113
|
+
const widest = Object.create(first, {
|
|
114
|
+
step: { value: { ...first.step, secrets: [{ name: 'secret', purpose: 'password' }] } },
|
|
115
|
+
});
|
|
116
|
+
return createGrammarTools(widest);
|
|
117
|
+
}
|
|
118
|
+
function unavailable(name) {
|
|
119
|
+
if (name === 'type_secret')
|
|
120
|
+
return 'this step declares no secrets';
|
|
121
|
+
return `${name} is not available in this step`;
|
|
122
|
+
}
|
|
123
|
+
/** A rendered screen as an MCP result: its text, and the screenshot as an image when it carries one. */
|
|
124
|
+
function result(output) {
|
|
125
|
+
if (typeof output === 'string')
|
|
126
|
+
return { text: output };
|
|
127
|
+
return { text: output.text, image: { data: Buffer.from(output.pixels.data).toString('base64'), mimeType: output.pixels.mediaType } };
|
|
128
|
+
}
|
|
129
|
+
function firstLine(error) {
|
|
130
|
+
return (error instanceof Error ? error.message : String(error)).split('\n')[0] ?? '';
|
|
131
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Options every ACP executor takes, whichever agent it starts. */
|
|
2
|
+
export interface AcpAgentOptions {
|
|
3
|
+
/** Variables added to the agent's environment, on top of this process's. */
|
|
4
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
5
|
+
/**
|
|
6
|
+
* A value of the session's `model` config option, e.g. `sonnet`. The
|
|
7
|
+
* session fails to start when the agent does not offer it; the error lists
|
|
8
|
+
* what it does offer. Omitted, the agent's own default model runs.
|
|
9
|
+
*/
|
|
10
|
+
readonly model?: string;
|
|
11
|
+
/** Appended to the built-in rules the agent gets with the first step. */
|
|
12
|
+
readonly system?: string;
|
|
13
|
+
/** The executor name in reports. */
|
|
14
|
+
readonly name?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Options for an executor that runs agent steps on any coding agent over the Agent Client Protocol. */
|
|
17
|
+
export interface AcpOptions extends AcpAgentOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The command that starts the agent in ACP mode on stdio, e.g. Cursor's
|
|
20
|
+
* `agent` with `['acp']`. The agent signs in the way it does on its own
|
|
21
|
+
* (its CLI login or its own API key variable).
|
|
22
|
+
*/
|
|
23
|
+
readonly command: string;
|
|
24
|
+
readonly args?: readonly string[];
|
|
25
|
+
/** A session mode id to select, e.g. Codex's `read-only`. */
|
|
26
|
+
readonly mode?: string;
|
|
27
|
+
/** `_meta` for `session/new`: options only one agent reads (its adapter documents them). */
|
|
28
|
+
readonly sessionMeta?: Readonly<Record<string, unknown>>;
|
|
29
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e2e-dev/acp",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Run e2e agent steps on a coding agent you already use (Claude Code, Codex, Cursor, ...) over the Agent Client Protocol",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"e2e",
|
|
7
|
+
"end-to-end",
|
|
8
|
+
"testing",
|
|
9
|
+
"ai-testing",
|
|
10
|
+
"acp",
|
|
11
|
+
"agent-client-protocol",
|
|
12
|
+
"claude-code",
|
|
13
|
+
"codex",
|
|
14
|
+
"cursor"
|
|
15
|
+
],
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/tester-army/e2e.git",
|
|
20
|
+
"directory": "packages/acp"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/tester-army/e2e/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/tester-army/e2e/tree/main/packages/acp#readme",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org/",
|
|
28
|
+
"access": "public",
|
|
29
|
+
"tag": "latest"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"NOTICE"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@agentclientprotocol/sdk": "1.7.0",
|
|
44
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
45
|
+
"zod": "4.6.7"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"e2e": ">=0.21.4 <1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@modelcontextprotocol/client": "2.4.0",
|
|
52
|
+
"@types/node": "26.6.5",
|
|
53
|
+
"e2e": "0.21.3",
|
|
54
|
+
"typescript": "7.0.2",
|
|
55
|
+
"vitest": "5.0.5"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": "^22.22.3 || >=24.8.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run"
|
|
64
|
+
}
|
|
6
65
|
}
|