@noetic-tools/acp 1.3.1 → 2.0.0-next.1

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.
Files changed (58) hide show
  1. package/dist/agents.d.ts +72 -8
  2. package/dist/agents.js +162 -58
  3. package/dist/bin.d.ts +19 -0
  4. package/dist/bin.js +99 -0
  5. package/dist/client.d.ts +14 -0
  6. package/dist/client.js +50 -0
  7. package/dist/connection.d.ts +3 -0
  8. package/dist/connection.js +26 -4
  9. package/dist/define.d.ts +21 -7
  10. package/dist/define.js +139 -15
  11. package/dist/index.d.ts +13 -3
  12. package/dist/index.js +10 -2
  13. package/dist/mcp/node.d.ts +24 -0
  14. package/dist/mcp/node.js +146 -0
  15. package/dist/mcp/server.d.ts +16 -0
  16. package/dist/mcp/server.js +104 -0
  17. package/dist/permission-channel.d.ts +2 -2
  18. package/dist/permission-channel.js +23 -12
  19. package/dist/permissions.d.ts +6 -0
  20. package/dist/permissions.js +7 -0
  21. package/dist/pi/extension.d.ts +31 -0
  22. package/dist/pi/extension.js +223 -0
  23. package/dist/pi/launch.d.ts +11 -0
  24. package/dist/pi/launch.js +35 -0
  25. package/dist/remote.d.ts +52 -0
  26. package/dist/remote.js +108 -0
  27. package/dist/runner/grants.d.ts +47 -0
  28. package/dist/runner/grants.js +127 -0
  29. package/dist/runner/host.d.ts +21 -0
  30. package/dist/runner/host.js +318 -0
  31. package/dist/runner/options.d.ts +21 -0
  32. package/dist/runner/options.js +82 -0
  33. package/dist/runner/protocol.d.ts +101 -0
  34. package/dist/runner/protocol.js +218 -0
  35. package/dist/runner/serve.d.ts +60 -0
  36. package/dist/runner/serve.js +285 -0
  37. package/dist/runner/ws-link.d.ts +6 -0
  38. package/dist/runner/ws-link.js +47 -0
  39. package/dist/serve-permissions.d.ts +8 -2
  40. package/dist/serve-permissions.js +26 -5
  41. package/dist/serve-types.d.ts +6 -5
  42. package/dist/server-env.d.ts +10 -0
  43. package/dist/server-env.js +47 -0
  44. package/dist/spawn.d.ts +12 -0
  45. package/dist/spawn.js +37 -0
  46. package/dist/stdio.d.ts +9 -1
  47. package/dist/stdio.js +97 -55
  48. package/dist/tool-bridge.d.ts +67 -0
  49. package/dist/tool-bridge.js +62 -0
  50. package/dist/tool-permissions.d.ts +46 -0
  51. package/dist/tool-permissions.js +70 -0
  52. package/dist/tool-wiring.d.ts +46 -0
  53. package/dist/tool-wiring.js +203 -0
  54. package/dist/transport-loopback.d.ts +8 -1
  55. package/dist/transport-loopback.js +22 -1
  56. package/dist/turn.d.ts +11 -5
  57. package/dist/turn.js +39 -16
  58. 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 local child process. */
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
- /** Supply a non-stdio transport (remote agent, test loopback, sandbox bridge). */
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 `@zed-industries/claude-code-acp`, the ACP bridge over the
36
- * Claude Code SDK.
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 `@zed-industries/codex-acp`.
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?: AcpPresetOptions): AcpAgent;
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
- * Defer the `node:child_process` import until a connection is actually opened,
19
- * so importing `@noetic-tools/acp` in a browser or worker stays safe.
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
- function lazyStdioTransport(agentId, spec) {
22
- return async (opts) => {
23
- const { stdioAcpTransport } = await import('./stdio.js');
24
- return await stdioAcpTransport({
25
- agentId,
26
- command: spec.command,
27
- args: spec.args,
28
- env: spec.env,
29
- })(opts);
30
- };
31
- }
32
- function preset(agentId, base, opts = {}) {
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
- transport: opts.transport ?? lazyStdioTransport(agentId, spec),
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 `@zed-industries/claude-code-acp`, the ACP bridge over the
54
- * Claude Code SDK.
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('claude-code', {
59
- command: 'npx',
60
- args: [
61
- '-y',
62
- '@zed-industries/claude-code-acp',
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 `@zed-industries/codex-acp`.
137
+ * OpenAI Codex via `@agentclientprotocol/codex-acp`.
68
138
  * @public
69
139
  */
70
140
  export function codex(opts = {}) {
71
- return preset('codex', {
72
- command: 'npx',
73
- args: [
74
- '-y',
75
- '@zed-industries/codex-acp',
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
- return preset('gemini', {
85
- command: 'gemini',
86
- args: [
87
- '--experimental-acp',
88
- ],
89
- }, opts);
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('opencode', {
97
- command: 'opencode',
98
- args: [
99
- 'acp',
100
- ],
101
- }, opts);
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('pi', {
112
- command: 'npx',
113
- args: [
114
- '-y',
115
- 'pi-acp',
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(opts.agentId, {
129
- command: opts.command ?? '',
130
- args: opts.args,
131
- env: opts.env,
132
- }, {
133
- transport: opts.transport,
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);
@@ -80,6 +88,7 @@ export class NoeticAcpClient {
80
88
  return {
81
89
  policy: this.host.permissions,
82
90
  steer: this.host.steerPermission,
91
+ approve: this.host.approvePermission,
83
92
  handler: this.host.onPermissionRequest,
84
93
  };
85
94
  }
@@ -89,6 +98,15 @@ export class NoeticAcpClient {
89
98
  }
90
99
  //#region Baseline
91
100
  async requestPermission(params) {
101
+ const bridged = this.bridgedAllow(params);
102
+ if (bridged) {
103
+ return {
104
+ outcome: {
105
+ outcome: 'selected',
106
+ optionId: bridged.optionId,
107
+ },
108
+ };
109
+ }
92
110
  const outcome = await resolvePermission(params, this.permissions);
93
111
  const selected = selectPermissionOption(outcome, params.options, this.permissions.policy?.persist === true);
94
112
  if (!selected) {
@@ -105,8 +123,40 @@ export class NoeticAcpClient {
105
123
  };
106
124
  }
107
125
  async sessionUpdate(params) {
126
+ this.trackAnnounced(params.update);
108
127
  this.onNotify(params);
109
128
  }
129
+ /**
130
+ * Keep each `tool_call` until it settles; a permission request can only
131
+ * precede that. A call that never settles (cancelled) ages out once the
132
+ * map holds `ANNOUNCED_LIMIT`.
133
+ */
134
+ trackAnnounced(update) {
135
+ if (update.sessionUpdate === 'tool_call') {
136
+ this.announced.set(update.toolCallId, update);
137
+ const oldest = this.announced.keys().next().value;
138
+ if (this.announced.size > ANNOUNCED_LIMIT && oldest !== undefined) {
139
+ this.announced.delete(oldest);
140
+ }
141
+ return;
142
+ }
143
+ if (update.sessionUpdate === 'tool_call_update' &&
144
+ (update.status === 'completed' || update.status === 'failed')) {
145
+ this.announced.delete(update.toolCallId);
146
+ }
147
+ }
148
+ /** The allow option for a request on a bridged tool, which the bridge gates itself. */
149
+ bridgedAllow(params) {
150
+ const tools = this.host.tools;
151
+ if (!tools || !this.permitsBridged) {
152
+ return undefined;
153
+ }
154
+ const announced = this.announced.get(params.toolCall.toolCallId);
155
+ if (!this.permitsBridged(params, tools, announced)) {
156
+ return undefined;
157
+ }
158
+ return allowOnceOption(params.options);
159
+ }
110
160
  //#endregion
111
161
  //#region File system
112
162
  async readTextFile(params) {
@@ -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