mcacp 0.1.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 +190 -0
- package/README.md +195 -0
- package/dist/acp/agent-requests.d.ts +19 -0
- package/dist/acp/agent-requests.js +166 -0
- package/dist/acp/agent-requests.js.map +1 -0
- package/dist/acp/lifecycle.d.ts +50 -0
- package/dist/acp/lifecycle.js +127 -0
- package/dist/acp/lifecycle.js.map +1 -0
- package/dist/acp/status.d.ts +31 -0
- package/dist/acp/status.js +72 -0
- package/dist/acp/status.js.map +1 -0
- package/dist/acp/transport.d.ts +34 -0
- package/dist/acp/transport.js +175 -0
- package/dist/acp/transport.js.map +1 -0
- package/dist/config/index.d.ts +27 -0
- package/dist/config/index.js +162 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/permissions/index.d.ts +16 -0
- package/dist/permissions/index.js +70 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/registry/index.d.ts +52 -0
- package/dist/registry/index.js +240 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +271 -0
- package/dist/server/index.js.map +1 -0
- package/dist/sessions/index.d.ts +91 -0
- package/dist/sessions/index.js +151 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/prompt.d.ts +78 -0
- package/dist/sessions/prompt.js +361 -0
- package/dist/sessions/prompt.js.map +1 -0
- package/dist/types/acp.d.ts +343 -0
- package/dist/types/acp.js +17 -0
- package/dist/types/acp.js.map +1 -0
- package/dist/types/config.d.ts +135 -0
- package/dist/types/config.js +43 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/tools.d.ts +619 -0
- package/dist/types/tools.js +441 -0
- package/dist/types/tools.js.map +1 -0
- package/docs/configuration.md +164 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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 the 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 the 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 any 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
|
+
Copyright 2026 MCACP Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# MCACP
|
|
2
|
+
|
|
3
|
+
**Bridge any MCP client to any ACP coding agent.**
|
|
4
|
+
|
|
5
|
+
MCACP is an [MCP](https://modelcontextprotocol.io/) server that speaks the [Agent Control Protocol](https://agentclientprotocol.com/) on behalf of your MCP host. It lets Claude Code, Zed, VS Code, or any MCP-compatible client spawn, manage, and interact with ACP coding agents — turning a single chat window into a multi-agent control plane.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
MCP Client (Claude Code, Zed, VS Code, ...)
|
|
9
|
+
|
|
|
10
|
+
| MCP (stdio)
|
|
11
|
+
v
|
|
12
|
+
MCACP
|
|
13
|
+
|
|
|
14
|
+
| ACP (stdio, per agent)
|
|
15
|
+
v
|
|
16
|
+
Claude Code · Gemini CLI · Codex · Auggie · Copilot · ...
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What can you do with this?
|
|
20
|
+
|
|
21
|
+
**Run any ACP agent from any MCP client.** You don't need a dedicated IDE plugin for each agent. Install Gemini from Claude Code. Run Codex from Zed. Mix and match.
|
|
22
|
+
|
|
23
|
+
**Compare agents side by side.** Give the same task to Claude Code ACP and Gemini CLI in parallel sessions and compare the results.
|
|
24
|
+
|
|
25
|
+
**Build agent-driven pipelines.** One agent writes code, another reviews it, a third runs the tests. MCACP handles the lifecycle and permission flow for all of them.
|
|
26
|
+
|
|
27
|
+
**Control permissions interactively.** On hosts that support MCP elicitation (Zed), permission requests pop up as interactive forms. On hosts that don't (Claude Code), they fall back to operator mode where the host agent decides.
|
|
28
|
+
|
|
29
|
+
**Resume where you left off.** Sessions persist to disk. Shut down, restart, `load_session` — the agent picks up where it stopped.
|
|
30
|
+
|
|
31
|
+
**Discover and install agents from chat.** Browse the ACP registry, install agents, check for upgrades — without leaving your conversation.
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
### Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install -g mcacp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or run directly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx mcacp
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Add to your MCP client
|
|
48
|
+
|
|
49
|
+
**Claude Code** (`~/.claude/settings.json`):
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"mcacp": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["-y", "mcacp"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Zed** (`settings.json`):
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"context_servers": {
|
|
65
|
+
"mcacp": {
|
|
66
|
+
"command": { "path": "npx", "args": ["-y", "mcacp"] }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Then from chat:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
"Search for available agents" → registry_search
|
|
76
|
+
"Install the Gemini agent" → agent_install
|
|
77
|
+
"Initialize it and start a session" → initialize + new_session
|
|
78
|
+
"Ask it to refactor auth" → prompt_start + prompt
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## MCP tools
|
|
82
|
+
|
|
83
|
+
MCACP exposes 22 tools organized into five groups.
|
|
84
|
+
|
|
85
|
+
### Registry
|
|
86
|
+
|
|
87
|
+
| Tool | Description |
|
|
88
|
+
|------|-------------|
|
|
89
|
+
| `list_installed_agents` | List locally installed agents |
|
|
90
|
+
| `registry_search` | Search the ACP agent registry |
|
|
91
|
+
| `agent_install` | Install an agent from the registry |
|
|
92
|
+
| `agent_uninstall` | Remove an installed agent |
|
|
93
|
+
| `agent_check_upgrades` | Check for available upgrades |
|
|
94
|
+
| `discover_agents` | Scan editor configs (Zed, JetBrains) for agents |
|
|
95
|
+
| `reload_config` | Reload `mcacp.json` from disk |
|
|
96
|
+
|
|
97
|
+
### Lifecycle
|
|
98
|
+
|
|
99
|
+
| Tool | Description |
|
|
100
|
+
|------|-------------|
|
|
101
|
+
| `initialize` | Spawn an agent process and perform the ACP handshake |
|
|
102
|
+
| `shutdown` | Gracefully shut down an agent |
|
|
103
|
+
|
|
104
|
+
### Sessions
|
|
105
|
+
|
|
106
|
+
| Tool | Description |
|
|
107
|
+
|------|-------------|
|
|
108
|
+
| `new_session` | Create a session with working directory and permission policy |
|
|
109
|
+
| `load_session` | Resume a persisted session |
|
|
110
|
+
| `list_sessions` | List stored sessions for an agent |
|
|
111
|
+
| `close_session` | Close a session (preserved for later resume) |
|
|
112
|
+
|
|
113
|
+
### Interaction
|
|
114
|
+
|
|
115
|
+
| Tool | Description |
|
|
116
|
+
|------|-------------|
|
|
117
|
+
| `prompt_start` | Send a prompt (returns immediately) |
|
|
118
|
+
| `prompt` | Block until events are available |
|
|
119
|
+
| `prompt_events` | Non-blocking poll for events |
|
|
120
|
+
| `grant_permission` | Resolve a pending permission request (operator mode) |
|
|
121
|
+
| `request_permission` | Send an MCP elicitation to the host for a permission decision |
|
|
122
|
+
| `cancel` | Cancel an in-progress prompt |
|
|
123
|
+
| `set_mode` | Switch agent operating mode |
|
|
124
|
+
|
|
125
|
+
### Status
|
|
126
|
+
|
|
127
|
+
| Tool | Description |
|
|
128
|
+
|------|-------------|
|
|
129
|
+
| `list_running_agents` | List all agents with status and sessions |
|
|
130
|
+
| `get_agent_status` | Detailed status of a running agent |
|
|
131
|
+
| `set_agent_status` | Set status text for an agent |
|
|
132
|
+
|
|
133
|
+
## Permission policies
|
|
134
|
+
|
|
135
|
+
Each session can use a different policy:
|
|
136
|
+
|
|
137
|
+
| Policy | Behavior |
|
|
138
|
+
|--------|----------|
|
|
139
|
+
| `allow_all` | Auto-approve all agent actions |
|
|
140
|
+
| `deny_all` | Block all tool use |
|
|
141
|
+
| `elicit` | Forward as MCP elicitations to the host; falls back to `operator` if unsupported |
|
|
142
|
+
| `operator` | Queue as events — the host agent decides via `grant_permission` |
|
|
143
|
+
|
|
144
|
+
### Operator flow
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
Orchestrator MCACP ACP Agent
|
|
148
|
+
| | |
|
|
149
|
+
|-- prompt(sessionId, ...) ->| |
|
|
150
|
+
| |-- session/prompt --------->|
|
|
151
|
+
| |<- request_permission ------|
|
|
152
|
+
|<- {pendingPermission: ...} | |
|
|
153
|
+
| | |
|
|
154
|
+
|-- grant_permission ------->| |
|
|
155
|
+
| {toolCallId, optionId} |-- permission outcome ----->|
|
|
156
|
+
| |<- prompt result -----------|
|
|
157
|
+
|<- {stopReason, updates} | |
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
MCACP looks for `mcacp.json` in these locations (first found wins):
|
|
163
|
+
|
|
164
|
+
1. `--config` flag or `MCACP_CONFIG` env var
|
|
165
|
+
2. `.mcacp/mcacp.json` in the current directory
|
|
166
|
+
3. `~/.config/mcacp/mcacp.json`
|
|
167
|
+
|
|
168
|
+
```jsonc
|
|
169
|
+
{
|
|
170
|
+
"registries": ["https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json"],
|
|
171
|
+
"defaultPermissionPolicy": "elicit",
|
|
172
|
+
"agent_servers": {
|
|
173
|
+
"my-custom-agent": {
|
|
174
|
+
"command": "node",
|
|
175
|
+
"args": ["my-agent.js"]
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
See [docs/configuration.md](docs/configuration.md) for the full schema.
|
|
182
|
+
|
|
183
|
+
## Building from source
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
git clone https://github.com/Oortonaut/mcacp.git
|
|
187
|
+
cd mcacp
|
|
188
|
+
npm install
|
|
189
|
+
npm run build
|
|
190
|
+
node dist/index.js
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SessionId } from '../types/acp.js';
|
|
2
|
+
export declare class AgentRequestHandler {
|
|
3
|
+
private terminals;
|
|
4
|
+
private nextTerminalId;
|
|
5
|
+
private sessionCwds;
|
|
6
|
+
private sessionTerminals;
|
|
7
|
+
registerSession(sessionId: SessionId, cwd: string): void;
|
|
8
|
+
unregisterSession(sessionId: SessionId): void;
|
|
9
|
+
dispatch(method: string, params: unknown): Promise<unknown>;
|
|
10
|
+
private resolvePath;
|
|
11
|
+
private readTextFile;
|
|
12
|
+
private writeTextFile;
|
|
13
|
+
private createTerminal;
|
|
14
|
+
private getTerminalOutput;
|
|
15
|
+
private waitForExit;
|
|
16
|
+
private killTerminal;
|
|
17
|
+
private releaseTerminal;
|
|
18
|
+
private getTerminal;
|
|
19
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve, isAbsolute, sep } from 'node:path';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
export class AgentRequestHandler {
|
|
5
|
+
terminals = new Map();
|
|
6
|
+
nextTerminalId = 1;
|
|
7
|
+
sessionCwds = new Map();
|
|
8
|
+
sessionTerminals = new Map();
|
|
9
|
+
registerSession(sessionId, cwd) {
|
|
10
|
+
this.sessionCwds.set(sessionId, cwd);
|
|
11
|
+
this.sessionTerminals.set(sessionId, new Set());
|
|
12
|
+
}
|
|
13
|
+
unregisterSession(sessionId) {
|
|
14
|
+
// Kill and release all terminals belonging to this session
|
|
15
|
+
const terminalIds = this.sessionTerminals.get(sessionId);
|
|
16
|
+
if (terminalIds) {
|
|
17
|
+
for (const id of terminalIds) {
|
|
18
|
+
const terminal = this.terminals.get(id);
|
|
19
|
+
if (terminal) {
|
|
20
|
+
if (!terminal.process.killed)
|
|
21
|
+
terminal.process.kill();
|
|
22
|
+
this.terminals.delete(id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
this.sessionTerminals.delete(sessionId);
|
|
26
|
+
}
|
|
27
|
+
this.sessionCwds.delete(sessionId);
|
|
28
|
+
}
|
|
29
|
+
async dispatch(method, params) {
|
|
30
|
+
if (!params || typeof params !== 'object') {
|
|
31
|
+
throw Object.assign(new Error('Invalid params: expected an object'), { code: -32602 });
|
|
32
|
+
}
|
|
33
|
+
switch (method) {
|
|
34
|
+
case 'fs/read_text_file': return this.readTextFile(params);
|
|
35
|
+
case 'fs/write_text_file': return this.writeTextFile(params);
|
|
36
|
+
case 'terminal/create': return this.createTerminal(params);
|
|
37
|
+
case 'terminal/output': return this.getTerminalOutput(params);
|
|
38
|
+
case 'terminal/wait_for_exit': return this.waitForExit(params);
|
|
39
|
+
case 'terminal/kill': return this.killTerminal(params);
|
|
40
|
+
case 'terminal/release': return this.releaseTerminal(params);
|
|
41
|
+
default: throw Object.assign(new Error(`Unknown method: ${method}`), { code: -32601 });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
resolvePath(sessionId, filePath) {
|
|
45
|
+
const cwd = this.sessionCwds.get(sessionId);
|
|
46
|
+
if (!cwd)
|
|
47
|
+
throw new Error(`No working directory for session "${sessionId}"`);
|
|
48
|
+
const resolved = isAbsolute(filePath) ? resolve(filePath) : resolve(cwd, filePath);
|
|
49
|
+
const normalizedCwd = resolve(cwd);
|
|
50
|
+
// Prevent path traversal outside the session working directory
|
|
51
|
+
if (resolved !== normalizedCwd && !resolved.startsWith(normalizedCwd + sep)) {
|
|
52
|
+
throw new Error(`Path "${filePath}" resolves outside session working directory`);
|
|
53
|
+
}
|
|
54
|
+
return resolved;
|
|
55
|
+
}
|
|
56
|
+
readTextFile(params) {
|
|
57
|
+
const path = this.resolvePath(params.sessionId, params.path);
|
|
58
|
+
const content = readFileSync(path, 'utf-8');
|
|
59
|
+
if (params.line !== undefined || params.limit !== undefined) {
|
|
60
|
+
const lines = content.split('\n');
|
|
61
|
+
const start = Math.max(0, (params.line ?? 1) - 1);
|
|
62
|
+
const limit = params.limit !== undefined ? Math.max(0, params.limit) : undefined;
|
|
63
|
+
const end = limit !== undefined ? start + limit : lines.length;
|
|
64
|
+
return { content: lines.slice(start, end).join('\n') };
|
|
65
|
+
}
|
|
66
|
+
return { content };
|
|
67
|
+
}
|
|
68
|
+
writeTextFile(params) {
|
|
69
|
+
const path = this.resolvePath(params.sessionId, params.path);
|
|
70
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
71
|
+
writeFileSync(path, params.content);
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
createTerminal(params) {
|
|
75
|
+
const id = `term_${this.nextTerminalId++}`;
|
|
76
|
+
const cwd = params.cwd ?? this.sessionCwds.get(params.sessionId);
|
|
77
|
+
const env = { ...process.env };
|
|
78
|
+
if (params.env) {
|
|
79
|
+
for (const { name, value } of params.env)
|
|
80
|
+
env[name] = value;
|
|
81
|
+
}
|
|
82
|
+
const child = spawn(params.command, params.args ?? [], {
|
|
83
|
+
cwd, env, shell: false, stdio: ['pipe', 'pipe', 'pipe'],
|
|
84
|
+
});
|
|
85
|
+
const terminal = {
|
|
86
|
+
process: child, output: '', truncated: false,
|
|
87
|
+
outputByteLimit: params.outputByteLimit ?? 1_048_576, waiters: [],
|
|
88
|
+
};
|
|
89
|
+
const appendOutput = (chunk) => {
|
|
90
|
+
if (terminal.truncated)
|
|
91
|
+
return;
|
|
92
|
+
const text = chunk.toString();
|
|
93
|
+
if (terminal.output.length + text.length > terminal.outputByteLimit) {
|
|
94
|
+
terminal.output += text.slice(0, terminal.outputByteLimit - terminal.output.length);
|
|
95
|
+
terminal.truncated = true;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
terminal.output += text;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
child.stdout?.on('data', appendOutput);
|
|
102
|
+
child.stderr?.on('data', appendOutput);
|
|
103
|
+
child.on('exit', (code, signal) => {
|
|
104
|
+
terminal.exitCode = code ?? undefined;
|
|
105
|
+
terminal.signal = signal ?? undefined;
|
|
106
|
+
for (const waiter of terminal.waiters)
|
|
107
|
+
waiter({ exitCode: terminal.exitCode, signal: terminal.signal });
|
|
108
|
+
terminal.waiters = [];
|
|
109
|
+
});
|
|
110
|
+
this.terminals.set(id, terminal);
|
|
111
|
+
// Track which session owns this terminal for cleanup
|
|
112
|
+
const sessionTerms = this.sessionTerminals.get(params.sessionId);
|
|
113
|
+
if (sessionTerms)
|
|
114
|
+
sessionTerms.add(id);
|
|
115
|
+
return { terminalId: id };
|
|
116
|
+
}
|
|
117
|
+
getTerminalOutput(params) {
|
|
118
|
+
const terminal = this.getTerminal(params.terminalId);
|
|
119
|
+
return {
|
|
120
|
+
output: terminal.output, truncated: terminal.truncated,
|
|
121
|
+
exitStatus: terminal.exitCode !== undefined
|
|
122
|
+
? { exitCode: terminal.exitCode, signal: terminal.signal } : undefined,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
waitForExit(params) {
|
|
126
|
+
const terminal = this.getTerminal(params.terminalId);
|
|
127
|
+
if (terminal.exitCode !== undefined) {
|
|
128
|
+
return Promise.resolve({ exitCode: terminal.exitCode, signal: terminal.signal });
|
|
129
|
+
}
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const timeout = setTimeout(() => {
|
|
132
|
+
const idx = terminal.waiters.indexOf(waiter);
|
|
133
|
+
if (idx !== -1)
|
|
134
|
+
terminal.waiters.splice(idx, 1);
|
|
135
|
+
reject(new Error(`Timeout waiting for terminal "${params.terminalId}" to exit`));
|
|
136
|
+
}, 300_000); // 5 minute safety timeout
|
|
137
|
+
const waiter = (result) => {
|
|
138
|
+
clearTimeout(timeout);
|
|
139
|
+
resolve(result);
|
|
140
|
+
};
|
|
141
|
+
terminal.waiters.push(waiter);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
killTerminal(params) {
|
|
145
|
+
const terminal = this.getTerminal(params.terminalId);
|
|
146
|
+
if (!terminal.process.killed)
|
|
147
|
+
terminal.process.kill();
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
releaseTerminal(params) {
|
|
151
|
+
const terminal = this.terminals.get(params.terminalId);
|
|
152
|
+
if (terminal) {
|
|
153
|
+
if (!terminal.process.killed)
|
|
154
|
+
terminal.process.kill();
|
|
155
|
+
this.terminals.delete(params.terminalId);
|
|
156
|
+
}
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
getTerminal(id) {
|
|
160
|
+
const terminal = this.terminals.get(id);
|
|
161
|
+
if (!terminal)
|
|
162
|
+
throw new Error(`Terminal "${id}" not found`);
|
|
163
|
+
return terminal;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=agent-requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-requests.js","sourceRoot":"","sources":["../../src/acp/agent-requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAqB9D,MAAM,OAAO,mBAAmB;IACtB,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC/C,cAAc,GAAG,CAAC,CAAC;IACnB,WAAW,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC3C,gBAAgB,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE7D,eAAe,CAAC,SAAoB,EAAE,GAAW;QAC/C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,EAAE,CAAC,CA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AO,CAAC,MAAM;YAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,eAAe,CAAC,MAA6B;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM;gBAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACtD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,WAAW,CAAC,EAAc;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AcpTransport } from './transport.js';
|
|
2
|
+
import type { InitializeParams, AgentCapabilities, Implementation, SessionId } from '../types/acp.js';
|
|
3
|
+
import type { McacpConfig } from '../types/config.js';
|
|
4
|
+
export interface InstalledAgent {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
description: string;
|
|
9
|
+
command: string;
|
|
10
|
+
args?: string[];
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
distribution: 'npx' | 'binary' | 'local' | 'import';
|
|
13
|
+
installedAt: string;
|
|
14
|
+
registryUrl?: string;
|
|
15
|
+
/** Where this agent was registered from */
|
|
16
|
+
source?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentHandle {
|
|
19
|
+
agentId: string;
|
|
20
|
+
transport: AcpTransport;
|
|
21
|
+
capabilities: AgentCapabilities;
|
|
22
|
+
agentInfo?: Implementation;
|
|
23
|
+
protocolVersion: number;
|
|
24
|
+
activeSessions: Set<SessionId>;
|
|
25
|
+
startedAt: number;
|
|
26
|
+
lastActivityAt: number;
|
|
27
|
+
reapTimer: ReturnType<typeof setTimeout> | null;
|
|
28
|
+
status: {
|
|
29
|
+
text: string;
|
|
30
|
+
updatedAt: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare class LifecycleManager {
|
|
34
|
+
private config;
|
|
35
|
+
private agents;
|
|
36
|
+
private installedAgents;
|
|
37
|
+
constructor(config: McacpConfig, installedAgents: Map<string, InstalledAgent>);
|
|
38
|
+
initialize(agentId: string, protocolVersion?: number, clientInfo?: Implementation, clientCapabilities?: InitializeParams['clientCapabilities']): Promise<{
|
|
39
|
+
protocolVersion: number;
|
|
40
|
+
agentInfo?: Implementation;
|
|
41
|
+
agentCapabilities: AgentCapabilities;
|
|
42
|
+
}>;
|
|
43
|
+
shutdown(agentId: string): Promise<void>;
|
|
44
|
+
getAgent(agentId: string): AgentHandle;
|
|
45
|
+
isRunning(agentId: string): boolean;
|
|
46
|
+
getAllAgents(): AgentHandle[];
|
|
47
|
+
touchActivity(agentId: string): void;
|
|
48
|
+
updateInstalledAgents(installed: Map<string, InstalledAgent>): void;
|
|
49
|
+
private resetReapTimer;
|
|
50
|
+
}
|