@noetic-tools/acp 1.3.1 → 1.4.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/dist/agents.d.ts +72 -8
- package/dist/agents.js +162 -58
- package/dist/bin.d.ts +19 -0
- package/dist/bin.js +99 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.js +49 -0
- package/dist/connection.d.ts +3 -0
- package/dist/connection.js +26 -4
- package/dist/define.d.ts +21 -7
- package/dist/define.js +139 -15
- package/dist/index.d.ts +13 -3
- package/dist/index.js +10 -2
- package/dist/mcp/node.d.ts +24 -0
- package/dist/mcp/node.js +146 -0
- package/dist/mcp/server.d.ts +16 -0
- package/dist/mcp/server.js +104 -0
- package/dist/pi/extension.d.ts +31 -0
- package/dist/pi/extension.js +223 -0
- package/dist/pi/launch.d.ts +11 -0
- package/dist/pi/launch.js +35 -0
- package/dist/remote.d.ts +52 -0
- package/dist/remote.js +108 -0
- package/dist/runner/grants.d.ts +47 -0
- package/dist/runner/grants.js +127 -0
- package/dist/runner/host.d.ts +21 -0
- package/dist/runner/host.js +318 -0
- package/dist/runner/options.d.ts +21 -0
- package/dist/runner/options.js +82 -0
- package/dist/runner/protocol.d.ts +101 -0
- package/dist/runner/protocol.js +218 -0
- package/dist/runner/serve.d.ts +60 -0
- package/dist/runner/serve.js +285 -0
- package/dist/runner/ws-link.d.ts +6 -0
- package/dist/runner/ws-link.js +47 -0
- package/dist/server-env.d.ts +10 -0
- package/dist/server-env.js +47 -0
- package/dist/spawn.d.ts +12 -0
- package/dist/spawn.js +37 -0
- package/dist/stdio.d.ts +9 -1
- package/dist/stdio.js +97 -55
- package/dist/tool-bridge.d.ts +67 -0
- package/dist/tool-bridge.js +62 -0
- package/dist/tool-permissions.d.ts +46 -0
- package/dist/tool-permissions.js +70 -0
- package/dist/tool-wiring.d.ts +46 -0
- package/dist/tool-wiring.js +203 -0
- package/dist/transport-loopback.d.ts +8 -1
- package/dist/transport-loopback.js +22 -1
- package/dist/turn.d.ts +11 -5
- package/dist/turn.js +39 -16
- package/package.json +17 -4
package/dist/agents.d.ts
CHANGED
|
@@ -13,13 +13,53 @@
|
|
|
13
13
|
* includes `./stdio`. A browser build wanting it excluded should alias or
|
|
14
14
|
* externalise `@noetic-tools/acp/stdio`.
|
|
15
15
|
*/
|
|
16
|
-
import type { AcpAgent, AcpTransportFactory } from '@noetic-tools/types';
|
|
17
|
-
/** @public How to launch an agent as a
|
|
16
|
+
import type { AcpAgent, AcpMachineFactory, AcpTransportFactory } from '@noetic-tools/types';
|
|
17
|
+
/** @public How to launch an agent as a process. */
|
|
18
18
|
export interface AcpProcessSpec {
|
|
19
19
|
command: string;
|
|
20
20
|
args?: ReadonlyArray<string>;
|
|
21
21
|
env?: Record<string, string | undefined>;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The command each preset starts, by agent id. A remote runner started with
|
|
25
|
+
* `--agent <id>` starts only that command.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const PRESET_COMMANDS: {
|
|
29
|
+
readonly 'claude-code': {
|
|
30
|
+
readonly command: "npx";
|
|
31
|
+
readonly args: readonly ["-y", "@agentclientprotocol/claude-agent-acp"];
|
|
32
|
+
};
|
|
33
|
+
readonly codex: {
|
|
34
|
+
readonly command: "npx";
|
|
35
|
+
readonly args: readonly ["-y", "@agentclientprotocol/codex-acp"];
|
|
36
|
+
};
|
|
37
|
+
readonly gemini: {
|
|
38
|
+
readonly command: "gemini";
|
|
39
|
+
readonly args: readonly ["--experimental-acp"];
|
|
40
|
+
};
|
|
41
|
+
readonly opencode: {
|
|
42
|
+
readonly command: "opencode";
|
|
43
|
+
readonly args: readonly ["acp"];
|
|
44
|
+
};
|
|
45
|
+
readonly pi: {
|
|
46
|
+
readonly command: "npx";
|
|
47
|
+
readonly args: readonly ["-y", "pi-acp@0.0.32"];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The environment names each preset's tool settings set on its agent. A
|
|
52
|
+
* remote runner started with `--agent <id>` lets a host set these for that
|
|
53
|
+
* preset's command, and no others.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare const PRESET_ENV: {
|
|
57
|
+
readonly 'claude-code': readonly ["MCP_TOOL_TIMEOUT", "MAX_MCP_OUTPUT_TOKENS"];
|
|
58
|
+
readonly codex: readonly ["CODEX_CONFIG"];
|
|
59
|
+
readonly gemini: readonly ["GEMINI_CLI_TRUST_WORKSPACE"];
|
|
60
|
+
readonly opencode: readonly ["OPENCODE_CONFIG_CONTENT"];
|
|
61
|
+
readonly pi: readonly ["PI_ACP_PI_COMMAND", "NOETIC_PI_COMMAND", "NOETIC_TOOLS_URL", "NOETIC_TOOLS_HEADERS"];
|
|
62
|
+
};
|
|
23
63
|
/** @public Options common to every process-backed preset. */
|
|
24
64
|
export interface AcpPresetOptions {
|
|
25
65
|
/** Override the executable (e.g. a locally built binary). */
|
|
@@ -28,25 +68,43 @@ export interface AcpPresetOptions {
|
|
|
28
68
|
args?: ReadonlyArray<string>;
|
|
29
69
|
/** Environment overrides for the agent process — API keys, feature flags. */
|
|
30
70
|
env?: Record<string, string | undefined>;
|
|
31
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* The machine the agent runs on — a remote runner, a sandbox — when it is
|
|
73
|
+
* not this one. The preset's command runs there, with its tool settings.
|
|
74
|
+
*/
|
|
75
|
+
machine?: AcpMachineFactory;
|
|
76
|
+
/** Attach to an agent this package does not start, in place of the preset's command. */
|
|
32
77
|
transport?: AcpTransportFactory;
|
|
33
78
|
}
|
|
34
79
|
/**
|
|
35
|
-
* Claude Code via `@
|
|
36
|
-
* Claude
|
|
80
|
+
* Claude Code via `@agentclientprotocol/claude-agent-acp`, the ACP bridge over
|
|
81
|
+
* the Claude Agent SDK.
|
|
37
82
|
* @public
|
|
38
83
|
*/
|
|
39
84
|
export declare function claudeCode(opts?: AcpPresetOptions): AcpAgent;
|
|
40
85
|
/**
|
|
41
|
-
* OpenAI Codex via `@
|
|
86
|
+
* OpenAI Codex via `@agentclientprotocol/codex-acp`.
|
|
42
87
|
* @public
|
|
43
88
|
*/
|
|
44
89
|
export declare function codex(opts?: AcpPresetOptions): AcpAgent;
|
|
90
|
+
/** @public Options for {@link gemini}. */
|
|
91
|
+
export interface GeminiOptions extends AcpPresetOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Trust the session's folder for this process (`GEMINI_CLI_TRUST_WORKSPACE`).
|
|
94
|
+
* Gemini starts no MCP server, so serves no Noetic tools, in a folder it does
|
|
95
|
+
* not trust, and it has no way to trust one server alone: trusting the
|
|
96
|
+
* folder also loads its own `.gemini/settings.json` (MCP servers, hooks,
|
|
97
|
+
* tool commands), `GEMINI.md`, and `.env`. A step that gives the agent
|
|
98
|
+
* tools without it fails with `ACP_AGENT_CANNOT_TAKE_TOOLS` before the agent
|
|
99
|
+
* starts. Leave it off for a repository you did not write.
|
|
100
|
+
*/
|
|
101
|
+
trustWorkspace?: boolean;
|
|
102
|
+
}
|
|
45
103
|
/**
|
|
46
104
|
* Gemini CLI, which speaks ACP natively behind its experimental flag.
|
|
47
105
|
* @public
|
|
48
106
|
*/
|
|
49
|
-
export declare function gemini(opts?:
|
|
107
|
+
export declare function gemini(opts?: GeminiOptions): AcpAgent;
|
|
50
108
|
/**
|
|
51
109
|
* opencode, which speaks ACP natively via its `opencode acp` command.
|
|
52
110
|
* @public
|
|
@@ -56,7 +114,11 @@ export declare function opencode(opts?: AcpPresetOptions): AcpAgent;
|
|
|
56
114
|
* The pi coding agent, reached through the community `pi-acp` adapter — the
|
|
57
115
|
* same adapter Zed's agent registry points at. pi itself has no native ACP
|
|
58
116
|
* mode yet, so this preset depends on a third-party bridge; if it misbehaves,
|
|
59
|
-
* the issue belongs there rather than in pi or here.
|
|
117
|
+
* the issue belongs there rather than in pi or here. `pi-acp` drops the MCP
|
|
118
|
+
* servers it is given, so Noetic tools reach pi as native pi tools through
|
|
119
|
+
* the `pi-noetic-tools` extension (see {@link piToolWiring}). The preset pins
|
|
120
|
+
* `pi-acp@0.0.32`, the newest that works with pi 0.73
|
|
121
|
+
* (`@mariozechner/pi-coding-agent`); pass `command`/`args` to run another.
|
|
60
122
|
* @public
|
|
61
123
|
*/
|
|
62
124
|
export declare function pi(opts?: AcpPresetOptions): AcpAgent;
|
|
@@ -70,5 +132,7 @@ export declare function customAcpAgent(opts: {
|
|
|
70
132
|
command?: string;
|
|
71
133
|
args?: ReadonlyArray<string>;
|
|
72
134
|
env?: Record<string, string | undefined>;
|
|
135
|
+
machine?: AcpMachineFactory;
|
|
136
|
+
/** See {@link AcpPresetOptions.transport}. */
|
|
73
137
|
transport?: AcpTransportFactory;
|
|
74
138
|
}): AcpAgent;
|
package/dist/agents.js
CHANGED
|
@@ -14,22 +14,82 @@
|
|
|
14
14
|
* externalise `@noetic-tools/acp/stdio`.
|
|
15
15
|
*/
|
|
16
16
|
import { defineAcpAgent } from './define.js';
|
|
17
|
+
import { claudeToolWiring, codexToolWiring, geminiToolWiring, opencodeToolWiring, piToolWiring, sessionToolWiring, } from './tool-wiring.js';
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* The `pi-acp` the `pi()` preset runs. 0.0.34 waits for an `agent_settled`
|
|
20
|
+
* event `@mariozechner/pi-coding-agent` 0.73.1 never sends, so every prompt
|
|
21
|
+
* hangs; 0.0.32 works with it. pi 1.x (`@earendil-works/pi-coding-agent`) is
|
|
22
|
+
* untested.
|
|
20
23
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
const PI_ACP_VERSION = '0.0.32';
|
|
25
|
+
/**
|
|
26
|
+
* The command each preset starts, by agent id. A remote runner started with
|
|
27
|
+
* `--agent <id>` starts only that command.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const PRESET_COMMANDS = {
|
|
31
|
+
'claude-code': {
|
|
32
|
+
command: 'npx',
|
|
33
|
+
args: [
|
|
34
|
+
'-y',
|
|
35
|
+
'@agentclientprotocol/claude-agent-acp',
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
codex: {
|
|
39
|
+
command: 'npx',
|
|
40
|
+
args: [
|
|
41
|
+
'-y',
|
|
42
|
+
'@agentclientprotocol/codex-acp',
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
gemini: {
|
|
46
|
+
command: 'gemini',
|
|
47
|
+
args: [
|
|
48
|
+
'--experimental-acp',
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
opencode: {
|
|
52
|
+
command: 'opencode',
|
|
53
|
+
args: [
|
|
54
|
+
'acp',
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
pi: {
|
|
58
|
+
command: 'npx',
|
|
59
|
+
args: [
|
|
60
|
+
'-y',
|
|
61
|
+
`pi-acp@${PI_ACP_VERSION}`,
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The environment names each preset's tool settings set on its agent. A
|
|
67
|
+
* remote runner started with `--agent <id>` lets a host set these for that
|
|
68
|
+
* preset's command, and no others.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export const PRESET_ENV = {
|
|
72
|
+
'claude-code': [
|
|
73
|
+
'MCP_TOOL_TIMEOUT',
|
|
74
|
+
'MAX_MCP_OUTPUT_TOKENS',
|
|
75
|
+
],
|
|
76
|
+
codex: [
|
|
77
|
+
'CODEX_CONFIG',
|
|
78
|
+
],
|
|
79
|
+
gemini: [
|
|
80
|
+
'GEMINI_CLI_TRUST_WORKSPACE',
|
|
81
|
+
],
|
|
82
|
+
opencode: [
|
|
83
|
+
'OPENCODE_CONFIG_CONTENT',
|
|
84
|
+
],
|
|
85
|
+
pi: [
|
|
86
|
+
'PI_ACP_PI_COMMAND',
|
|
87
|
+
'NOETIC_PI_COMMAND',
|
|
88
|
+
'NOETIC_TOOLS_URL',
|
|
89
|
+
'NOETIC_TOOLS_HEADERS',
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
function preset({ agentId, base, opts = {}, wiring, }) {
|
|
33
93
|
const spec = {
|
|
34
94
|
command: opts.command ?? base.command,
|
|
35
95
|
args: [
|
|
@@ -43,78 +103,116 @@ function preset(agentId, base, opts = {}) {
|
|
|
43
103
|
};
|
|
44
104
|
return defineAcpAgent({
|
|
45
105
|
agentId,
|
|
46
|
-
|
|
106
|
+
...(opts.transport
|
|
107
|
+
? {
|
|
108
|
+
transport: opts.transport,
|
|
109
|
+
}
|
|
110
|
+
: {
|
|
111
|
+
command: {
|
|
112
|
+
command: spec.command,
|
|
113
|
+
args: spec.args,
|
|
114
|
+
},
|
|
115
|
+
machine: opts.machine,
|
|
116
|
+
}),
|
|
47
117
|
env: spec.env,
|
|
118
|
+
tools: wiring,
|
|
48
119
|
});
|
|
49
120
|
}
|
|
50
121
|
//#endregion
|
|
51
122
|
//#region Presets
|
|
52
123
|
/**
|
|
53
|
-
* Claude Code via `@
|
|
54
|
-
* Claude
|
|
124
|
+
* Claude Code via `@agentclientprotocol/claude-agent-acp`, the ACP bridge over
|
|
125
|
+
* the Claude Agent SDK.
|
|
55
126
|
* @public
|
|
56
127
|
*/
|
|
57
128
|
export function claudeCode(opts = {}) {
|
|
58
|
-
return preset(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, opts);
|
|
129
|
+
return preset({
|
|
130
|
+
agentId: 'claude-code',
|
|
131
|
+
base: PRESET_COMMANDS['claude-code'],
|
|
132
|
+
opts,
|
|
133
|
+
wiring: claudeToolWiring,
|
|
134
|
+
});
|
|
65
135
|
}
|
|
66
136
|
/**
|
|
67
|
-
* OpenAI Codex via `@
|
|
137
|
+
* OpenAI Codex via `@agentclientprotocol/codex-acp`.
|
|
68
138
|
* @public
|
|
69
139
|
*/
|
|
70
140
|
export function codex(opts = {}) {
|
|
71
|
-
return preset(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, opts);
|
|
141
|
+
return preset({
|
|
142
|
+
agentId: 'codex',
|
|
143
|
+
base: PRESET_COMMANDS.codex,
|
|
144
|
+
opts,
|
|
145
|
+
wiring: codexToolWiring,
|
|
146
|
+
});
|
|
78
147
|
}
|
|
79
148
|
/**
|
|
80
149
|
* Gemini CLI, which speaks ACP natively behind its experimental flag.
|
|
81
150
|
* @public
|
|
82
151
|
*/
|
|
83
152
|
export function gemini(opts = {}) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
153
|
+
const { trustWorkspace, ...rest } = opts;
|
|
154
|
+
const agent = preset({
|
|
155
|
+
agentId: 'gemini',
|
|
156
|
+
base: trustWorkspace
|
|
157
|
+
? {
|
|
158
|
+
...PRESET_COMMANDS.gemini,
|
|
159
|
+
env: {
|
|
160
|
+
GEMINI_CLI_TRUST_WORKSPACE: 'true',
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
: PRESET_COMMANDS.gemini,
|
|
164
|
+
opts: rest,
|
|
165
|
+
wiring: geminiToolWiring,
|
|
166
|
+
});
|
|
167
|
+
const trusted = trustWorkspace || rest.env?.GEMINI_CLI_TRUST_WORKSPACE === 'true';
|
|
168
|
+
// An attached agent already refuses tools, for the transport's reason.
|
|
169
|
+
if (trusted || agent.refusesTools) {
|
|
170
|
+
return agent;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
...agent,
|
|
174
|
+
refusesTools: UNTRUSTED_GEMINI,
|
|
175
|
+
};
|
|
90
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Gemini would start without the bridge and serve the step none of its tools,
|
|
179
|
+
* where `callModel` would offer them all.
|
|
180
|
+
*/
|
|
181
|
+
const UNTRUSTED_GEMINI = {
|
|
182
|
+
code: 'ACP_AGENT_CANNOT_TAKE_TOOLS',
|
|
183
|
+
reason: 'Gemini CLI starts no MCP server, the tool bridge included, in a folder it does not trust, so the agent would run with none of the tools.',
|
|
184
|
+
hint: "Pass `gemini({ trustWorkspace: true })` to trust the session's folder for the agent process. That also loads the folder's own `.gemini/settings.json`, `GEMINI.md` and `.env`, so do it only for a repository you wrote; otherwise leave `tools` off the step.",
|
|
185
|
+
};
|
|
91
186
|
/**
|
|
92
187
|
* opencode, which speaks ACP natively via its `opencode acp` command.
|
|
93
188
|
* @public
|
|
94
189
|
*/
|
|
95
190
|
export function opencode(opts = {}) {
|
|
96
|
-
return preset(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
191
|
+
return preset({
|
|
192
|
+
agentId: 'opencode',
|
|
193
|
+
base: PRESET_COMMANDS.opencode,
|
|
194
|
+
opts,
|
|
195
|
+
wiring: opencodeToolWiring,
|
|
196
|
+
});
|
|
102
197
|
}
|
|
103
198
|
/**
|
|
104
199
|
* The pi coding agent, reached through the community `pi-acp` adapter — the
|
|
105
200
|
* same adapter Zed's agent registry points at. pi itself has no native ACP
|
|
106
201
|
* mode yet, so this preset depends on a third-party bridge; if it misbehaves,
|
|
107
|
-
* the issue belongs there rather than in pi or here.
|
|
202
|
+
* the issue belongs there rather than in pi or here. `pi-acp` drops the MCP
|
|
203
|
+
* servers it is given, so Noetic tools reach pi as native pi tools through
|
|
204
|
+
* the `pi-noetic-tools` extension (see {@link piToolWiring}). The preset pins
|
|
205
|
+
* `pi-acp@0.0.32`, the newest that works with pi 0.73
|
|
206
|
+
* (`@mariozechner/pi-coding-agent`); pass `command`/`args` to run another.
|
|
108
207
|
* @public
|
|
109
208
|
*/
|
|
110
209
|
export function pi(opts = {}) {
|
|
111
|
-
return preset(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}, opts);
|
|
210
|
+
return preset({
|
|
211
|
+
agentId: 'pi',
|
|
212
|
+
base: PRESET_COMMANDS.pi,
|
|
213
|
+
opts,
|
|
214
|
+
wiring: piToolWiring,
|
|
215
|
+
});
|
|
118
216
|
}
|
|
119
217
|
/**
|
|
120
218
|
* Any other ACP-speaking agent. Because the protocol is uniform, this is a
|
|
@@ -125,12 +223,18 @@ export function customAcpAgent(opts) {
|
|
|
125
223
|
if (!opts.transport && !opts.command) {
|
|
126
224
|
throw new TypeError(`customAcpAgent(${JSON.stringify(opts.agentId)}) requires either a 'command' to spawn or a 'transport'.`);
|
|
127
225
|
}
|
|
128
|
-
return preset(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
226
|
+
return preset({
|
|
227
|
+
agentId: opts.agentId,
|
|
228
|
+
base: {
|
|
229
|
+
command: opts.command ?? '',
|
|
230
|
+
args: opts.args,
|
|
231
|
+
env: opts.env,
|
|
232
|
+
},
|
|
233
|
+
opts: {
|
|
234
|
+
machine: opts.machine,
|
|
235
|
+
transport: opts.transport,
|
|
236
|
+
},
|
|
237
|
+
wiring: sessionToolWiring,
|
|
134
238
|
});
|
|
135
239
|
}
|
|
136
240
|
//#endregion
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `noetic-acp serve` — the remote runner, run on the machine an ACP agent
|
|
4
|
+
* should run on. Hosts reach it with `webSocketMachine()` (listening) or
|
|
5
|
+
* `commandMachine()` (`--stdio`, started by ssh or `docker exec -i`).
|
|
6
|
+
*
|
|
7
|
+
* noetic-acp serve --stdio [--agent <id>] [--spawn <command>]... [--env <name>]...
|
|
8
|
+
* [--cwd <dir>]
|
|
9
|
+
* noetic-acp serve [--host 127.0.0.1] [--port 0] [--agent <id>] [--spawn <command>]...
|
|
10
|
+
* [--env <name>]... [--cwd <dir>] [--tls-cert <pem> --tls-key <pem>]
|
|
11
|
+
*
|
|
12
|
+
* The WebSocket token comes from NOETIC_ACP_RUNNER_TOKEN, or is made up and
|
|
13
|
+
* printed to stderr. `--agent` and `--spawn` limit the runner to that preset's
|
|
14
|
+
* command and those command lines (split on spaces), each with the preset's
|
|
15
|
+
* environment names plus every `--env` name, inside `--cwd`. For pi the
|
|
16
|
+
* runner names pi's command itself. Whoever holds the token can start what
|
|
17
|
+
* the grants allow, as the runner's user.
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `noetic-acp serve` — the remote runner, run on the machine an ACP agent
|
|
4
|
+
* should run on. Hosts reach it with `webSocketMachine()` (listening) or
|
|
5
|
+
* `commandMachine()` (`--stdio`, started by ssh or `docker exec -i`).
|
|
6
|
+
*
|
|
7
|
+
* noetic-acp serve --stdio [--agent <id>] [--spawn <command>]... [--env <name>]...
|
|
8
|
+
* [--cwd <dir>]
|
|
9
|
+
* noetic-acp serve [--host 127.0.0.1] [--port 0] [--agent <id>] [--spawn <command>]...
|
|
10
|
+
* [--env <name>]... [--cwd <dir>] [--tls-cert <pem> --tls-key <pem>]
|
|
11
|
+
*
|
|
12
|
+
* The WebSocket token comes from NOETIC_ACP_RUNNER_TOKEN, or is made up and
|
|
13
|
+
* printed to stderr. `--agent` and `--spawn` limit the runner to that preset's
|
|
14
|
+
* command and those command lines (split on spaces), each with the preset's
|
|
15
|
+
* environment names plus every `--env` name, inside `--cwd`. For pi the
|
|
16
|
+
* runner names pi's command itself. Whoever holds the token can start what
|
|
17
|
+
* the grants allow, as the runner's user.
|
|
18
|
+
*/
|
|
19
|
+
import { parseArgs } from 'node:util';
|
|
20
|
+
import { runnerOptions, trustWarning } from './runner/options.js';
|
|
21
|
+
import { listenAcpRunner, newRunnerToken, readPem, serveAcpRunnerOverStdio } from './runner/serve.js';
|
|
22
|
+
const USAGE = 'usage: noetic-acp serve [--stdio] [--host <host>] [--port <port>] [--agent <id>] [--spawn <command>]... [--env <name>]... [--cwd <dir>] [--tls-cert <pem> --tls-key <pem>]';
|
|
23
|
+
async function main(argv) {
|
|
24
|
+
const [verb, ...rest] = argv;
|
|
25
|
+
if (verb !== 'serve') {
|
|
26
|
+
fail(USAGE);
|
|
27
|
+
}
|
|
28
|
+
const { values } = parseArgs({
|
|
29
|
+
args: [
|
|
30
|
+
...rest,
|
|
31
|
+
],
|
|
32
|
+
options: {
|
|
33
|
+
stdio: {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
},
|
|
36
|
+
host: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
port: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
agent: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
},
|
|
45
|
+
spawn: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
multiple: true,
|
|
48
|
+
},
|
|
49
|
+
env: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
multiple: true,
|
|
52
|
+
},
|
|
53
|
+
cwd: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
},
|
|
56
|
+
'tls-cert': {
|
|
57
|
+
type: 'string',
|
|
58
|
+
},
|
|
59
|
+
'tls-key': {
|
|
60
|
+
type: 'string',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const options = runnerOptions(values);
|
|
65
|
+
process.stderr.write(`${trustWarning(options)}\n`);
|
|
66
|
+
if (values.stdio) {
|
|
67
|
+
await serveAcpRunnerOverStdio(options);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const token = process.env.NOETIC_ACP_RUNNER_TOKEN ?? newRunnerToken();
|
|
71
|
+
const cert = values['tls-cert'];
|
|
72
|
+
const key = values['tls-key'];
|
|
73
|
+
if ((cert === undefined) !== (key === undefined)) {
|
|
74
|
+
fail('--tls-cert and --tls-key go together.');
|
|
75
|
+
}
|
|
76
|
+
const listener = await listenAcpRunner({
|
|
77
|
+
...options,
|
|
78
|
+
host: values.host,
|
|
79
|
+
port: values.port === undefined ? undefined : Number(values.port),
|
|
80
|
+
token,
|
|
81
|
+
tls: cert && key
|
|
82
|
+
? {
|
|
83
|
+
cert: readPem(cert),
|
|
84
|
+
key: readPem(key),
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
87
|
+
});
|
|
88
|
+
process.stderr.write(`noetic-acp runner listening on ${listener.url}\n`);
|
|
89
|
+
if (!process.env.NOETIC_ACP_RUNNER_TOKEN) {
|
|
90
|
+
process.stderr.write(`token: ${token}\n`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function fail(message) {
|
|
94
|
+
process.stderr.write(`${message}\n`);
|
|
95
|
+
process.exit(2);
|
|
96
|
+
}
|
|
97
|
+
main(process.argv.slice(2)).catch((e) => {
|
|
98
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
99
|
+
});
|
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { AcpClientHost } from '@noetic-tools/types';
|
|
16
16
|
import type * as acp from '@zed-industries/agent-client-protocol';
|
|
17
|
+
import type { BridgedPermissionCheck } from './tool-permissions.js';
|
|
17
18
|
/** Build the `ClientCapabilities` sent during `initialize`. */
|
|
18
19
|
export declare function clientCapabilitiesFor(host: AcpClientHost): acp.ClientCapabilities;
|
|
19
20
|
/**
|
|
@@ -35,6 +36,8 @@ export interface NoeticAcpClientOptions {
|
|
|
35
36
|
* having to wrap (and thereby copy) the host.
|
|
36
37
|
*/
|
|
37
38
|
onNotify: (notification: acp.SessionNotification) => void;
|
|
39
|
+
/** Recognizes this agent's permission requests for bridged tools. */
|
|
40
|
+
permitsBridged?: BridgedPermissionCheck;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* The `Client` handed to the ACP connection. One instance per connection; it
|
|
@@ -46,6 +49,9 @@ export declare class NoeticAcpClient implements acp.Client {
|
|
|
46
49
|
private readonly host;
|
|
47
50
|
private readonly onNotify;
|
|
48
51
|
private readonly terminals;
|
|
52
|
+
/** Each `tool_call` the agent announced, by id, to recognize bridged calls. */
|
|
53
|
+
private readonly announced;
|
|
54
|
+
private readonly permitsBridged?;
|
|
49
55
|
constructor(opts: NoeticAcpClientOptions);
|
|
50
56
|
/**
|
|
51
57
|
* Read the permission tiers off the host at CALL time, never snapshot them.
|
|
@@ -58,6 +64,14 @@ export declare class NoeticAcpClient implements acp.Client {
|
|
|
58
64
|
dispose(): Promise<void>;
|
|
59
65
|
requestPermission(params: acp.RequestPermissionRequest): Promise<acp.RequestPermissionResponse>;
|
|
60
66
|
sessionUpdate(params: acp.SessionNotification): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Keep each `tool_call` until it settles; a permission request can only
|
|
69
|
+
* precede that. A call that never settles (cancelled) ages out once the
|
|
70
|
+
* map holds `ANNOUNCED_LIMIT`.
|
|
71
|
+
*/
|
|
72
|
+
private trackAnnounced;
|
|
73
|
+
/** The allow option for a request on a bridged tool, which the bridge gates itself. */
|
|
74
|
+
private bridgedAllow;
|
|
61
75
|
readTextFile(params: acp.ReadTextFileRequest): Promise<acp.ReadTextFileResponse>;
|
|
62
76
|
writeTextFile(params: acp.WriteTextFileRequest): Promise<acp.WriteTextFileResponse>;
|
|
63
77
|
createTerminal(params: acp.CreateTerminalRequest): Promise<acp.CreateTerminalResponse>;
|
package/dist/client.js
CHANGED
|
@@ -16,6 +16,7 @@ import { RequestError } from '@zed-industries/agent-client-protocol';
|
|
|
16
16
|
import { isAbsolutePath, isWithinRoots } from './paths.js';
|
|
17
17
|
import { resolvePermission, selectPermissionOption } from './permissions.js';
|
|
18
18
|
import { buildCommandLine, TerminalRegistry } from './terminals.js';
|
|
19
|
+
import { allowOnceOption } from './tool-permissions.js';
|
|
19
20
|
//#region Capability advertisement
|
|
20
21
|
/** Build the `ClientCapabilities` sent during `initialize`. */
|
|
21
22
|
export function clientCapabilitiesFor(host) {
|
|
@@ -55,6 +56,9 @@ function parentDir(path) {
|
|
|
55
56
|
}
|
|
56
57
|
return path.slice(0, index);
|
|
57
58
|
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region Client
|
|
61
|
+
const ANNOUNCED_LIMIT = 1e3;
|
|
58
62
|
/**
|
|
59
63
|
* The `Client` handed to the ACP connection. One instance per connection; it
|
|
60
64
|
* owns the terminal registry, so closing the connection kills every command the
|
|
@@ -65,7 +69,11 @@ export class NoeticAcpClient {
|
|
|
65
69
|
host;
|
|
66
70
|
onNotify;
|
|
67
71
|
terminals;
|
|
72
|
+
/** Each `tool_call` the agent announced, by id, to recognize bridged calls. */
|
|
73
|
+
announced = new Map();
|
|
74
|
+
permitsBridged;
|
|
68
75
|
constructor(opts) {
|
|
76
|
+
this.permitsBridged = opts.permitsBridged;
|
|
69
77
|
this.host = opts.host;
|
|
70
78
|
this.onNotify = opts.onNotify;
|
|
71
79
|
this.terminals = new TerminalRegistry(opts.host.shell, opts.host.cwd);
|
|
@@ -89,6 +97,15 @@ export class NoeticAcpClient {
|
|
|
89
97
|
}
|
|
90
98
|
//#region Baseline
|
|
91
99
|
async requestPermission(params) {
|
|
100
|
+
const bridged = this.bridgedAllow(params);
|
|
101
|
+
if (bridged) {
|
|
102
|
+
return {
|
|
103
|
+
outcome: {
|
|
104
|
+
outcome: 'selected',
|
|
105
|
+
optionId: bridged.optionId,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
92
109
|
const outcome = await resolvePermission(params, this.permissions);
|
|
93
110
|
const selected = selectPermissionOption(outcome, params.options, this.permissions.policy?.persist === true);
|
|
94
111
|
if (!selected) {
|
|
@@ -105,8 +122,40 @@ export class NoeticAcpClient {
|
|
|
105
122
|
};
|
|
106
123
|
}
|
|
107
124
|
async sessionUpdate(params) {
|
|
125
|
+
this.trackAnnounced(params.update);
|
|
108
126
|
this.onNotify(params);
|
|
109
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Keep each `tool_call` until it settles; a permission request can only
|
|
130
|
+
* precede that. A call that never settles (cancelled) ages out once the
|
|
131
|
+
* map holds `ANNOUNCED_LIMIT`.
|
|
132
|
+
*/
|
|
133
|
+
trackAnnounced(update) {
|
|
134
|
+
if (update.sessionUpdate === 'tool_call') {
|
|
135
|
+
this.announced.set(update.toolCallId, update);
|
|
136
|
+
const oldest = this.announced.keys().next().value;
|
|
137
|
+
if (this.announced.size > ANNOUNCED_LIMIT && oldest !== undefined) {
|
|
138
|
+
this.announced.delete(oldest);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (update.sessionUpdate === 'tool_call_update' &&
|
|
143
|
+
(update.status === 'completed' || update.status === 'failed')) {
|
|
144
|
+
this.announced.delete(update.toolCallId);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** The allow option for a request on a bridged tool, which the bridge gates itself. */
|
|
148
|
+
bridgedAllow(params) {
|
|
149
|
+
const tools = this.host.tools;
|
|
150
|
+
if (!tools || !this.permitsBridged) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
const announced = this.announced.get(params.toolCall.toolCallId);
|
|
154
|
+
if (!this.permitsBridged(params, tools, announced)) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
return allowOnceOption(params.options);
|
|
158
|
+
}
|
|
110
159
|
//#endregion
|
|
111
160
|
//#region File system
|
|
112
161
|
async readTextFile(params) {
|
package/dist/connection.d.ts
CHANGED
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { AcpAgentConnection, AcpClientHost, AcpContentBlock, AcpTransport } from '@noetic-tools/types';
|
|
18
18
|
import type * as acp from '@zed-industries/agent-client-protocol';
|
|
19
|
+
import type { ToolBridge } from './tool-bridge.js';
|
|
19
20
|
/** @public Options for {@link openAcpConnection}. */
|
|
20
21
|
export interface OpenAcpConnectionOptions {
|
|
21
22
|
agentId: string;
|
|
22
23
|
transport: AcpTransport;
|
|
23
24
|
host: AcpClientHost;
|
|
24
25
|
signal?: AbortSignal;
|
|
26
|
+
/** The tool bridge serving `host.tools`, closed with the connection. */
|
|
27
|
+
tools?: ToolBridge;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* The spec requires clients to restrict prompt content to what the agent
|