@anureo/adapter-acp 0.0.0-stage → 0.3.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 +201 -0
- package/README.md +106 -2
- package/package.json +47 -4
- package/src/adapter.d.ts +214 -0
- package/src/adapter.js +944 -0
- package/src/diagnostics.d.ts +36 -0
- package/src/diagnostics.js +91 -0
- package/src/dsh.d.ts +32 -0
- package/src/dsh.js +31 -0
- package/src/extensions.d.ts +25 -0
- package/src/extensions.js +30 -0
- package/src/file-changes.d.ts +9 -0
- package/src/file-changes.js +29 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +3 -0
- package/src/mapping.d.ts +119 -0
- package/src/mapping.js +504 -0
- package/src/options.d.ts +103 -0
- package/src/options.js +0 -0
- package/src/request-error.d.ts +6 -0
- package/src/request-error.js +22 -0
- package/src/stdio.d.ts +9 -0
- package/src/stdio.js +108 -0
- package/src/stop.d.ts +18 -0
- package/src/stop.js +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yoichi
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @anureo/adapter-acp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adapter connecting the Anureo SDK to agents implementing the [Agent Client Protocol](https://agentclientprotocol.com) (ACP), using the official `@agentclientprotocol/sdk` 1.4.0. ACP is an editor↔agent protocol; this adapter brings any standard ACP agent behind the AHP session model — the interoperability proof that AHP is a host-side semantic layer, not a competing agent protocol.
|
|
4
|
+
|
|
5
|
+
> Part of the [Anureo SDK workspace](../../../README.md). Install with `npm install @anureo/adapter-acp`.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
This shows the revised workspace API, not the published 0.2.0 API. Root migration and local
|
|
10
|
+
validation are complete.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { createClient } from '@anureo/sdk'
|
|
14
|
+
import { createAcpAdapter } from '@anureo/adapter-acp'
|
|
15
|
+
|
|
16
|
+
const client = await createClient({
|
|
17
|
+
adapter: createAcpAdapter({
|
|
18
|
+
command: 'my-acp-agent', // spawn over stdio; or use connect() below
|
|
19
|
+
args: ['--stdio'],
|
|
20
|
+
cwd: '/workspace',
|
|
21
|
+
}),
|
|
22
|
+
identity: { adapterId: 'acp', runtimeConfigId: 'local' },
|
|
23
|
+
})
|
|
24
|
+
// Use client.sessions.create(...) and session.submit(...); dispose in finally.
|
|
25
|
+
|
|
26
|
+
// Remote or custom transports inject an official v1 message stream:
|
|
27
|
+
// createAcpAdapter({ connect: () => openMyStream() })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## How capabilities are mapped
|
|
31
|
+
|
|
32
|
+
ACP's core protocol covers sessions, turns, messages, and permission requests. AHP-only features are opt-in through an extension object in the agent's `initialize` response (`_meta.ahp`, version 1):
|
|
33
|
+
|
|
34
|
+
- **Optional methods** — `fork`, `revert`, `steer`, `history`, `goalSet`, `goalClear`, `compact`, `review`, each declaring its private `_…` method name, plus fork boundaries and revert scopes where applicable
|
|
35
|
+
- **Client requests** — `userInput` (`_ahp/user_input`) and `dynamicTool` (`_ahp/dynamic_tool`) interactions
|
|
36
|
+
- **Features** — nested subagent events and custom instructions
|
|
37
|
+
|
|
38
|
+
Agents that do not advertise the extension still work: the adapter publishes only the standard ACP baseline (session-scoped interrupt, approval interactions, text/image/file input). fs and terminal capabilities are announced **only** when the host injects the corresponding ports — connecting an adapter never grants filesystem or terminal permission by itself.
|
|
39
|
+
|
|
40
|
+
Session snapshots loaded via ACP `session/load` have no turn boundaries; they are handed to the host through `onLoadSnapshot` instead of being replayed as realtime events.
|
|
41
|
+
|
|
42
|
+
Configuration patches apply one field at a time. Each confirmed field updates
|
|
43
|
+
the session state immediately. If a later field fails, `CONFIG_PARTIAL` reports
|
|
44
|
+
`details.appliedKeys`, `details.failedKey` and the underlying `details.cause.code`;
|
|
45
|
+
confirmed changes remain applied. `outcomeUnknown` describes uncertainty about
|
|
46
|
+
the failed field and requires recovery when true.
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
| Option | Purpose |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `command`, `args`, `cwd`, `env` | Spawn the agent binary and speak nd-JSON over stdio |
|
|
53
|
+
| `connect` | Provide an official `acp.Stream` factory for remote transports or deterministic wire tests |
|
|
54
|
+
| `fs` (`AcpFileSystemPort`) | Host-implemented read/write text-file callbacks |
|
|
55
|
+
| `terminal` (`AcpTerminalPort`) | Host-implemented terminal lifecycle callbacks |
|
|
56
|
+
| `requestTimeoutMs` | Timeout in milliseconds for ACP requests other than `session/prompt` (default 30,000; DSH preset 120,000) |
|
|
57
|
+
| `maxFrameBytes` | Maximum bytes per incoming or outgoing stdio line (default 8 MiB; oversized frames fail with `BACKPRESSURE_EXCEEDED`) |
|
|
58
|
+
| `onLoadSnapshot` | Receive `session/load` snapshot updates separately from the realtime event stream |
|
|
59
|
+
| `stderrTailLines`, `onStderr` | Set the retained stderr line limit (default 200) and receive redacted lines; `0` disables capture and callbacks |
|
|
60
|
+
| `autoRespondPermission` | Answer `session/request_permission` without an AHP interaction; undecided or unoffered kinds fall back to the human path |
|
|
61
|
+
|
|
62
|
+
ACP JSON-RPC error codes map to typed SDK errors (`-32601` → `CAPABILITY_UNSUPPORTED`, `-32602` → `INVALID_PARAMS`, `-32000` → `AUTH_REQUIRED`, `-32002` → `RESOURCE_NOT_FOUND`); a dropped connection surfaces as `ACP_CONNECTION_CLOSED` with `outcomeUnknown`, never as a silent success.
|
|
63
|
+
|
|
64
|
+
For spawned agents, stderr is never forwarded raw: the adapter redacts `sk-…`, bearer tokens, `key=value` secrets, and URL credentials. `stderrTailLines` controls the retained line limit (default 200; `0` disables capture and `onStderr` callbacks). The retained tail is also limited to 32,768 UTF-16 code units, counting each redacted line's length plus one for a separator, so fewer lines may be retained. The adapter attaches that tail to startup and disconnect failures as `details.diagnostics.stderrTail`.
|
|
65
|
+
|
|
66
|
+
`session/prompt` stop reasons map explicitly: `end_turn` and `cancelled` keep their existing meaning, `max_tokens` / `max_turn_requests` complete the turn with an `ACP_STOP_MAX_TOKENS` / `ACP_STOP_MAX_TURN_REQUESTS` notice, `refusal` fails it, and any unclassified reason fails closed with `ACP_STOP_UNKNOWN`. A backend that stops for an unknown reason is never reported as clean success.
|
|
67
|
+
|
|
68
|
+
Automatic approval decisions emit an `ACP_PERMISSION_AUTO_ANSWERED` notice carrying only the tool-call id and chosen option; the request's raw input never reaches the notice. Policies never fabricate an option id: when the agent does not offer the requested kind, the request falls back to `interaction/requested`.
|
|
69
|
+
|
|
70
|
+
## Driving DeepSeek Harness
|
|
71
|
+
|
|
72
|
+
`createDshAcpAdapter()` presets the one-liner for `dsh --profile acp` (DSH 0.2.2+, Node.js ≥ 24.9):
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { createClient } from '@anureo/sdk'
|
|
76
|
+
import { createDshAcpAdapter } from '@anureo/adapter-acp'
|
|
77
|
+
|
|
78
|
+
const client = await createClient({
|
|
79
|
+
adapter: createDshAcpAdapter({ cwd: workspace, autoApprove: true }),
|
|
80
|
+
identity: { adapterId: 'dsh-acp', runtimeConfigId: 'local' },
|
|
81
|
+
})
|
|
82
|
+
const session = await client.sessions.create({ cwd: workspace, model: 'deepseek-v4-flash' })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
DSH advertises the standard ACP v1 baseline only — no `_ahp` extension, no modes, `embeddedContext: false` — so `fork`, `revert`, `steer`, `history`, `goal`, `compact`, `review` and `file` prompt blocks stay unavailable, and `permissionMode` must not be passed. Model values resolve against the advertised `provider/model` enum, so a bare `deepseek-v4-flash` becomes `deepseek-official/deepseek-v4-flash` before it reaches the backend. Auto-approval is opt-in because DSH offers only `allow_once` / `reject_once`; the policy is the only way to run unattended.
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
cd packages/adapter/acp
|
|
91
|
+
bun run typecheck
|
|
92
|
+
bun test tests
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The conformance tests spawn a scripted ACP agent (implementing the standard wire protocol) as a real child process over stdio.
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
- [Architecture](../../../docs/architecture.md) — adapters' role in the SDK (currently in Chinese)
|
|
100
|
+
- [AHP v1 protocol](../../../spec/ahp-v1.md)
|
|
101
|
+
|
|
102
|
+
## AHP v1 lifecycle revision
|
|
103
|
+
|
|
104
|
+
The lifecycle design updates AHP v1 and package root entries in place.
|
|
105
|
+
The root implementation and tests use the revised lifecycle; parallel versioned
|
|
106
|
+
entries have been removed. Local conformance and clean-install checks have passed. Standard ACP remains limited to guarantees it can prove; overlapping input requires an explicit correlation extension, and session cancellation must not masquerade as exact-turn interrupt.
|
|
107
|
+
See the [design and implementation plan](../../../docs/native-harness-lifecycle.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anureo/adapter-acp",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Anureo SDK adapter for standard Agent Client Protocol (ACP) agents",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"anureo",
|
|
8
|
+
"ahp",
|
|
9
|
+
"harness",
|
|
10
|
+
"agent",
|
|
11
|
+
"acp",
|
|
12
|
+
"agent-client-protocol"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/hi-youichi/anureo-sdk#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/hi-youichi/anureo-sdk.git",
|
|
18
|
+
"directory": "packages/adapter/acp"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/hi-youichi/anureo-sdk/issues"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./src/index.d.ts",
|
|
30
|
+
"import": "./src/index.js",
|
|
31
|
+
"default": "./src/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@anureo/sdk": "0.3.0",
|
|
36
|
+
"@anureo/protocol": "0.3.0",
|
|
37
|
+
"@agentclientprotocol/sdk": "1.4.0"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"src",
|
|
44
|
+
"bin",
|
|
45
|
+
"schema",
|
|
46
|
+
"protocol",
|
|
47
|
+
"examples"
|
|
48
|
+
]
|
|
49
|
+
}
|
package/src/adapter.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as acp from '@agentclientprotocol/sdk';
|
|
2
|
+
import { type HarnessAdapter, type BackendSession, type SessionEventSink, type SessionMethod } from '@anureo/sdk';
|
|
3
|
+
import { type Capabilities, type SessionBinding, type SessionOpenParams, type SessionState, type InitializeParams, type InitializeResult, type AhpRequestMap, type AhpResultMap, type JsonObject } from '@anureo/protocol';
|
|
4
|
+
import { type Extensions } from "./extensions.js";
|
|
5
|
+
import type { AcpAdapterOptions } from "./options.js";
|
|
6
|
+
/** Connect an ACP agent to the SDK adapter port. Hosts normally pass a factory result to createClient,
|
|
7
|
+
* which orders initialization, session acquisition and disposal through its output wrapper.
|
|
8
|
+
* Direct adapter users must initialize before opening and await disposal even after setup failure. */
|
|
9
|
+
export declare class AcpAdapter implements HarnessAdapter {
|
|
10
|
+
readonly options: AcpAdapterOptions;
|
|
11
|
+
/** Construct the adapter without I/O; initialize acquires the transport and negotiates capabilities. */
|
|
12
|
+
constructor(options: AcpAdapterOptions);
|
|
13
|
+
/** OutputSession.open queries this after negotiation to select a locally reachable MCP output bridge.
|
|
14
|
+
* Injected transports cannot attest reachability and return undefined. */
|
|
15
|
+
outputBridgeTransport(): 'http' | 'stdio' | undefined;
|
|
16
|
+
/** Native capabilities from the initialize response when available, or an empty descriptor before negotiation. */
|
|
17
|
+
get nativeCapabilities(): acp.AgentCapabilities;
|
|
18
|
+
/** Access the connected native request context; throws ACP_CONNECTION_CLOSED before connection setup. */
|
|
19
|
+
get agent(): acp.ClientContext;
|
|
20
|
+
/** Whether the adapter has installed a connection and has yet to observe transport loss. */
|
|
21
|
+
get connected(): boolean;
|
|
22
|
+
/** Negotiate ACP and return detached AHP capabilities. Calls after a successful handshake reuse its result.
|
|
23
|
+
* Client.initialize awaits this through withStructuredOutput and retains the capabilities for later opens.
|
|
24
|
+
* Handshake request failures include a redacted stderr tail when available. Direct callers must dispose
|
|
25
|
+
* after setup failure and should finish initialization before opening sessions. */
|
|
26
|
+
initialize(params: InitializeParams): Promise<InitializeResult>;
|
|
27
|
+
/** Issue a native request with requestTimeoutMs (30 seconds by default). Rejections are translated
|
|
28
|
+
* to SDK errors. A timeout ends this wait while native work may continue. The adapter's normal
|
|
29
|
+
* session prompt path uses the native context directly because its reply may be terminal. */
|
|
30
|
+
call<M extends acp.AgentRequestMethod>(method: M, params: acp.AgentRequestParamsByMethod[M]): Promise<acp.AgentRequestResponsesByMethod[M]>;
|
|
31
|
+
/** Send a custom native method under the same deadline and error translation as standard methods. */
|
|
32
|
+
call(method: string, params: unknown): Promise<unknown>;
|
|
33
|
+
/** Open, resume/load or fork one native session. Opens run one at a time so early updates
|
|
34
|
+
* can establish the native identity. OutputSession.open supplies the sink and awaits the configured
|
|
35
|
+
* backend before attachment. Supply protocol-valid parameters, including the fork source and boundary
|
|
36
|
+
* in fork mode. Dispatch or attachment failures remove local indexes and release the open slot.
|
|
37
|
+
* Successful backends remain adapter-tracked until teardown. Their owner must dispose them. */
|
|
38
|
+
openSession(params: SessionOpenParams, sink: SessionEventSink): Promise<BackendSession>;
|
|
39
|
+
/** Attempt all tracked session releases, then close the native connection and channel, and clear indexes.
|
|
40
|
+
* Reject RESOURCE_RELEASE_FAILED after all attempts if any fail. Repeated calls after closing begins
|
|
41
|
+
* return immediately; disposal does not prove native executions stopped. */
|
|
42
|
+
dispose(): Promise<void>;
|
|
43
|
+
private connection;
|
|
44
|
+
private channel;
|
|
45
|
+
private info;
|
|
46
|
+
/** Adapter's AHP session index. Disposed sessions remain indexed until adapter teardown. */
|
|
47
|
+
readonly sessions: Map<string, AcpBackendSession>;
|
|
48
|
+
private nativeSessions;
|
|
49
|
+
private openingSession;
|
|
50
|
+
private sessionOpenQueueTail;
|
|
51
|
+
private readonly deliveries;
|
|
52
|
+
private closing;
|
|
53
|
+
private connectionLost;
|
|
54
|
+
private sourceFailure?;
|
|
55
|
+
/** Peer-negotiated features. Backend requests can withdraw a method the peer rejects as unsupported. */
|
|
56
|
+
extension: Extensions;
|
|
57
|
+
/** Negotiated baseline. Each backend clones it before applying session configuration. */
|
|
58
|
+
capabilities: Capabilities;
|
|
59
|
+
/** Install initialize's transport and handlers before sending the handshake. When the SDK reports
|
|
60
|
+
* closure, reject outstanding response deliveries and fail live sessions unless disposal is underway. */
|
|
61
|
+
private installConnection;
|
|
62
|
+
/** Return detached negotiated capabilities so callers can retain their initialization result. */
|
|
63
|
+
private initializedResult;
|
|
64
|
+
/** Notify currently indexed sessions of observation loss. A rejected sink must not stop fan-out. */
|
|
65
|
+
private failSessions;
|
|
66
|
+
/** Build openSession's native request. For resume/load, register the known ID and begin snapshot
|
|
67
|
+
* capture before dispatch so updates received before the reply reach the correct backend. */
|
|
68
|
+
private prepareSessionOpen;
|
|
69
|
+
/** Reconcile the reply with any early notification identity before openSession applies overrides.
|
|
70
|
+
* Index the backend and finish snapshot capture before invoking the host's snapshot callback. */
|
|
71
|
+
private acceptOpenResponse;
|
|
72
|
+
/** Remove the indexes that openSession may have populated before failure, including through early updates. */
|
|
73
|
+
private forgetFailedOpen;
|
|
74
|
+
/** Attach redacted channel diagnostics before initialize rejects a handshake failure or the
|
|
75
|
+
* SDK closure handler reports observation loss. Preserve the error when no tail is available. */
|
|
76
|
+
private withDiagnostics;
|
|
77
|
+
/** Resolve the native ID for SDK callbacks and routeNotification. Only a session/update may
|
|
78
|
+
* identify the current opening backend. Reject other unknown IDs as invalid native parameters. */
|
|
79
|
+
private backend;
|
|
80
|
+
/** Register a native request with the session sink after establishing standard turn correlation.
|
|
81
|
+
* The sink invokes the responder with an answer or cancellation. Resolve the native response first,
|
|
82
|
+
* but keep the responder pending until wrapStream confirms its write, so settlement cannot claim early delivery. */
|
|
83
|
+
private interaction;
|
|
84
|
+
/** Consume session updates and negotiated lifecycle events before the official SDK handles remaining frames.
|
|
85
|
+
* Await sink publication to preserve source order; routing failures end stream observation in wrapStream. */
|
|
86
|
+
private routeNotification;
|
|
87
|
+
/** Route notifications in read order before forwarding other frames to the SDK. A successful
|
|
88
|
+
* response write acknowledges delivery to the interaction responder. Stream errors fail observation. */
|
|
89
|
+
private wrapStream;
|
|
90
|
+
/** Configure the ACP SDK callbacks for installConnection before initialize advertises their
|
|
91
|
+
* capabilities. The SDK invokes them for incoming peer requests and notifications. */
|
|
92
|
+
private createClientApplication;
|
|
93
|
+
/** Handle the ACP SDK's elicitation callback. Cancel unsupported scopes or modes immediately.
|
|
94
|
+
* For a session request, keep URL details in the private payload and return the sink's answer to the peer. */
|
|
95
|
+
private requestElicitation;
|
|
96
|
+
/** Answer the ACP SDK's permission request with an offered option after publishing the policy
|
|
97
|
+
* notice. If policy declines or has no matching option, await the interactive session response. */
|
|
98
|
+
private requestPermission;
|
|
99
|
+
/** Register the filesystem and terminal callbacks supplied by the host. The ACP SDK handler
|
|
100
|
+
* validates session and terminal ownership before returning the port's response to the peer. */
|
|
101
|
+
private registerPorts;
|
|
102
|
+
/** After initialize validates the peer version, store the baseline capability projection and
|
|
103
|
+
* negotiated extension methods. Session construction clones the baseline before applying overrides. */
|
|
104
|
+
private configureCapabilities;
|
|
105
|
+
/** Handle registered _ahp user-input/tool requests only after negotiation; validate before sink registration.
|
|
106
|
+
* Native callers receive a response or cancellation; unavailable extensions reject as method-not-found. */
|
|
107
|
+
private extensionInteraction;
|
|
108
|
+
}
|
|
109
|
+
/** Native session implementation returned by AcpAdapter.openSession and adopted by OutputSession.open.
|
|
110
|
+
* Execution receipts and sink lifecycle events are separate observations; disposal releases handles
|
|
111
|
+
* without asserting that native execution stopped. Routing/state methods support adapter collaboration. */
|
|
112
|
+
export declare class AcpBackendSession implements BackendSession {
|
|
113
|
+
readonly adapter: AcpAdapter;
|
|
114
|
+
private readonly params;
|
|
115
|
+
readonly sink: SessionEventSink;
|
|
116
|
+
/** Create session-local projection and configuration state. AcpAdapter.openSession assigns the
|
|
117
|
+
* native identity. The mapper reads this backend's current turn and applies peer metadata/config
|
|
118
|
+
* updates through configure before publishing snapshots to the supplied sink. */
|
|
119
|
+
constructor(adapter: AcpAdapter, params: SessionOpenParams, sink: SessionEventSink);
|
|
120
|
+
/** Attach the native ACP identity to the requested AHP binding; identity is established before openSession returns. */
|
|
121
|
+
get binding(): SessionBinding;
|
|
122
|
+
/** Expose the current attachment snapshot to OutputSession.open; collection fields are session-owned. */
|
|
123
|
+
get state(): SessionState;
|
|
124
|
+
/** Build state for attachment and sink publication. Configuration and capabilities are session-owned references. */
|
|
125
|
+
snapshot(): SessionState;
|
|
126
|
+
/** AcpAdapter.routeNotification forwards negotiated v2 events here. Bind submissions through the sink,
|
|
127
|
+
* flush a turn's mapper before its terminal event, and reject invalid payloads instead of publishing them. */
|
|
128
|
+
nativeEvent(raw: unknown, scope: Record<string, unknown>): Promise<void>;
|
|
129
|
+
/** Publish legacy _ahp events from AcpAdapter.routeNotification, binding review/input on native start.
|
|
130
|
+
* Release matching terminal admission before publication; conflicting execution identities reject routing. */
|
|
131
|
+
extensionEvent(raw: unknown, scope: Record<string, unknown>): Promise<void>;
|
|
132
|
+
/** Publish a standard turn start before update, interaction registration or terminal prompt handling
|
|
133
|
+
* continues. Bind after start publication, setting the guard before either await to prevent duplicate starts. */
|
|
134
|
+
ensureStandardStarted(): Promise<void>;
|
|
135
|
+
/** Merge native configuration or a session-title patch from open responses and AcpUpdateMapper callbacks.
|
|
136
|
+
* Configuration changes refresh descriptors and revision; title-only changes leave the revision unchanged. */
|
|
137
|
+
configure(data: Record<string, unknown>): void;
|
|
138
|
+
/** AcpAdapter routes session/update here: retain bounded load snapshots without replay, or await live projection.
|
|
139
|
+
* Correlated updates require an observed start; unsupported uncorrelated execution updates reject routing. */
|
|
140
|
+
update(data: Record<string, unknown>): Promise<void>;
|
|
141
|
+
/** Reject peer operations on terminal IDs not successfully created for this session or already released. */
|
|
142
|
+
requireTerminal(id: string): void;
|
|
143
|
+
/** Apply a configuration patch in key order and return the resulting session state. Reject unknown
|
|
144
|
+
* keys before dispatch. AcpAdapter.openSession awaits initial overrides before attachment, and execute
|
|
145
|
+
* returns this state for host patches. Publish each confirmed field. A later native failure rejects
|
|
146
|
+
* with CONFIG_PARTIAL and the confirmed keys, whose changes remain applied. */
|
|
147
|
+
setConfiguration(patch: JsonObject): Promise<SessionState>;
|
|
148
|
+
/** OutputSession.execute dispatches validated session operations here and consumes the native result/failure.
|
|
149
|
+
* Session cancellation only acknowledges notification delivery; completion comes from the prompt/event.
|
|
150
|
+
* Close reports executionStopped=unconfirmed, and unsupported exact-turn operations reject. */
|
|
151
|
+
execute<M extends SessionMethod>(method: M, params: AhpRequestMap[M]): Promise<AhpResultMap[M]>;
|
|
152
|
+
/**
|
|
153
|
+
* Share one cleanup promise across calls. Mark closed before attempting every retained terminal
|
|
154
|
+
* release and optional native close; clear local handles and reject aggregated release failures.
|
|
155
|
+
* OutputSession.dispose awaits this during teardown. OutputSession.open also awaits it when a
|
|
156
|
+
* backend arrives after teardown, and AcpAdapter.dispose calls it for every tracked backend.
|
|
157
|
+
*/
|
|
158
|
+
dispose(): Promise<void>;
|
|
159
|
+
private readonly nativeMappers;
|
|
160
|
+
private readonly nativeStartedTurnIds;
|
|
161
|
+
private standardTurnStarted;
|
|
162
|
+
private standardSubmissionId?;
|
|
163
|
+
/** Standard/legacy lane identity; v2 executions are tracked independently. */
|
|
164
|
+
activeTurn: string | undefined;
|
|
165
|
+
private readonly mapper;
|
|
166
|
+
private releasing?;
|
|
167
|
+
private nativeClosed;
|
|
168
|
+
/** Native identity assigned by openSession, including early update correlation. */
|
|
169
|
+
nativeId: string;
|
|
170
|
+
/** While resume/load is pending, historical updates are captured instead of published. */
|
|
171
|
+
hydrating: boolean;
|
|
172
|
+
/** Bounded historical updates delivered to onLoadSnapshot after opening. */
|
|
173
|
+
readonly loadedSnapshot: JsonObject[];
|
|
174
|
+
/** Successfully created terminal IDs awaiting explicit or disposal release. */
|
|
175
|
+
readonly terminals: Set<string>;
|
|
176
|
+
/** Session-local negotiated capabilities, refreshed by native configuration and extension failures. */
|
|
177
|
+
readonly capabilities: Capabilities;
|
|
178
|
+
private config;
|
|
179
|
+
private configKeys;
|
|
180
|
+
private configurationData;
|
|
181
|
+
private capabilityRevision;
|
|
182
|
+
private sessionTitle?;
|
|
183
|
+
private closed;
|
|
184
|
+
private snapshotBytes;
|
|
185
|
+
/** Save pre-attachment updates for the host snapshot callback. Capture title as attachment metadata
|
|
186
|
+
* and bound the remaining history by count and estimated size before retaining its safe projection. */
|
|
187
|
+
private captureLoadedUpdate;
|
|
188
|
+
/** Return the per-turn mapper used by update. A native start must have been observed before
|
|
189
|
+
* projection. nativeEvent flushes and removes the mapper on completion. */
|
|
190
|
+
private correlatedMapper;
|
|
191
|
+
/** Dispatch a legacy review in the single execution lane. The receipt confirms dispatch.
|
|
192
|
+
* Native start notifications establish binding. Definite pre-start rejection releases admission;
|
|
193
|
+
* unknown outcome retains it, and method-not-found withdraws review capability before rejecting. */
|
|
194
|
+
private submitReview;
|
|
195
|
+
/** Reserve the uncorrelated ACP lane before review or prompt dispatch; reject overlapping submissions. */
|
|
196
|
+
private beginStandardSubmission;
|
|
197
|
+
/** Release only this prompt's lane: terminal observers may already have admitted its successor. */
|
|
198
|
+
private releaseStandardTurn;
|
|
199
|
+
/** Reject closed/unsupported delivery before choosing negotiated native correlation or the single standard ACP lane. */
|
|
200
|
+
private submitInput;
|
|
201
|
+
/** Return the peer's validated acceptance; v2 lifecycle notifications independently bind and complete turns. */
|
|
202
|
+
private submitCorrelatedInput;
|
|
203
|
+
/** Await the uncorrelated prompt's terminal response and publish mapped completion before returning acceptance. */
|
|
204
|
+
private submitStandardInput;
|
|
205
|
+
/** Dispatch a negotiated extension, enrich history tool file changes, and validate the native result.
|
|
206
|
+
* Method-not-found withdraws the affected live capability and publishes state before rejecting. */
|
|
207
|
+
private extension;
|
|
208
|
+
/** Remove the rejected method for future dispatch and update this session's advertised capability.
|
|
209
|
+
* The caller publishes the revised session state before surfacing the native rejection. */
|
|
210
|
+
private withdrawExtension;
|
|
211
|
+
}
|
|
212
|
+
/** Create an ACP adapter without starting I/O. Pass it to createClient for negotiation and owned cleanup,
|
|
213
|
+
* or initialize/open/dispose it directly in that order; connect takes precedence over command. */
|
|
214
|
+
export declare function createAcpAdapter(options: AcpAdapterOptions): AcpAdapter;
|