@mastra/acp 0.0.0-ag-example-20260516005230

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/CHANGELOG.md ADDED
@@ -0,0 +1,92 @@
1
+ # @mastra/acp
2
+
3
+ ## 0.0.0-ag-example-20260516005230
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`4d90188`](https://github.com/mastra-ai/mastra/commit/4d9018840fba28d40e9bc3238727bbc28b29e996), [`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`58aadb8`](https://github.com/mastra-ai/mastra/commit/58aadb8a2ab713c945df04351290bb572dffad21), [`2487b50`](https://github.com/mastra-ai/mastra/commit/2487b50af3b11dada6301afcb2f4da25612da1da), [`db58726`](https://github.com/mastra-ai/mastra/commit/db58726abd9cedd990ef40e85cec82aeb47594af), [`7c3a1ad`](https://github.com/mastra-ai/mastra/commit/7c3a1adedd155d126a15ad74b8985aa355af86e2), [`94556bf`](https://github.com/mastra-ai/mastra/commit/94556bffcf30aa1dae02662b80809df8957f81e1)]:
8
+ - @mastra/core@0.0.0-ag-example-20260516005230
9
+
10
+ ## 0.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ - You can now run ACP-compatible coding agents as Mastra tools or lightweight subagents. ACP agents support incremental response streaming and can be used anywhere Mastra accepts a `SubAgent`, including supervisor delegation and workflow steps. ([#16423](https://github.com/mastra-ai/mastra/pull/16423))
15
+
16
+ ```ts
17
+ import { createACPTool, AcpAgent } from '@mastra/acp';
18
+
19
+ export const codingTool = createACPTool({
20
+ id: 'coding-agent',
21
+ command: 'my-acp-agent',
22
+ });
23
+
24
+ export const codingAgent = new AcpAgent({
25
+ id: 'coding-agent',
26
+ command: 'my-acp-agent',
27
+ });
28
+ ```
29
+
30
+ You can also wire an `AcpAgent` into a supervisor or workflow as a `SubAgent`-compatible implementation:
31
+
32
+ ```ts
33
+ import { Agent } from '@mastra/core/agent';
34
+
35
+ export const supervisor = new Agent({
36
+ name: 'supervisor',
37
+ instructions: 'Delegate coding tasks to the ACP agent.',
38
+ model,
39
+ agents: {
40
+ codingAgent,
41
+ },
42
+ });
43
+ ```
44
+
45
+ Workflows and the Inngest workflow adapter now recognize `SubAgent`-compatible implementations when creating agent-backed workflow steps.
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [[`20787de`](https://github.com/mastra-ai/mastra/commit/20787de5965234a1af28fe35f49437c537dbfa0d), [`784ad98`](https://github.com/mastra-ai/mastra/commit/784ad989549de91dc5d33ab8ef36caa6f7dcd34e), [`fceae1f`](https://github.com/mastra-ai/mastra/commit/fceae1f5f5db4722cb078a663c6eb4bd22944123), [`090a647`](https://github.com/mastra-ai/mastra/commit/090a647ba5a66d36f203f9f49457e03a1ff4e6fb), [`bf02acb`](https://github.com/mastra-ai/mastra/commit/bf02acbb8a6110f638ac844e89f1ebf04cb7fe74), [`090a647`](https://github.com/mastra-ai/mastra/commit/090a647ba5a66d36f203f9f49457e03a1ff4e6fb), [`bdb4cbf`](https://github.com/mastra-ai/mastra/commit/bdb4cbf8ba4b685d7481f28bb9dc3de6c79c9ed2), [`0fd3fbe`](https://github.com/mastra-ai/mastra/commit/0fd3fbe40fb63657aedd72f6e7b38c8e8ee6940d), [`f84447d`](https://github.com/mastra-ai/mastra/commit/f84447d6c80f3471836a9b300d246b331fb47e0d), [`a1a5b3e`](https://github.com/mastra-ai/mastra/commit/a1a5b3e42ab2ca5161ea21db59ebf28442680fa7), [`af84f57`](https://github.com/mastra-ai/mastra/commit/af84f571ed762e92e8e61c5f9a72363520914274), [`8b3c6f9`](https://github.com/mastra-ai/mastra/commit/8b3c6f90f7879833ba7d1bc70937e1d8f69d0804), [`fed0475`](https://github.com/mastra-ai/mastra/commit/fed0475ccfea31e4fc251469ac05640d0742c1f0), [`0d53730`](https://github.com/mastra-ai/mastra/commit/0d53730c1ed87ef80c87caa5701c4170ea8028e6), [`522f44d`](https://github.com/mastra-ai/mastra/commit/522f44d947214bfc06cff50599bae1ef3494880d)]:
50
+ - @mastra/core@1.34.0
51
+
52
+ ## 0.1.0-alpha.0
53
+
54
+ ### Minor Changes
55
+
56
+ - You can now run ACP-compatible coding agents as Mastra tools or lightweight subagents. ACP agents support incremental response streaming and can be used anywhere Mastra accepts a `SubAgent`, including supervisor delegation and workflow steps. ([#16423](https://github.com/mastra-ai/mastra/pull/16423))
57
+
58
+ ```ts
59
+ import { createACPTool, AcpAgent } from '@mastra/acp';
60
+
61
+ export const codingTool = createACPTool({
62
+ id: 'coding-agent',
63
+ command: 'my-acp-agent',
64
+ });
65
+
66
+ export const codingAgent = new AcpAgent({
67
+ id: 'coding-agent',
68
+ command: 'my-acp-agent',
69
+ });
70
+ ```
71
+
72
+ You can also wire an `AcpAgent` into a supervisor or workflow as a `SubAgent`-compatible implementation:
73
+
74
+ ```ts
75
+ import { Agent } from '@mastra/core/agent';
76
+
77
+ export const supervisor = new Agent({
78
+ name: 'supervisor',
79
+ instructions: 'Delegate coding tasks to the ACP agent.',
80
+ model,
81
+ agents: {
82
+ codingAgent,
83
+ },
84
+ });
85
+ ```
86
+
87
+ Workflows and the Inngest workflow adapter now recognize `SubAgent`-compatible implementations when creating agent-backed workflow steps.
88
+
89
+ ### Patch Changes
90
+
91
+ - Updated dependencies [[`20787de`](https://github.com/mastra-ai/mastra/commit/20787de5965234a1af28fe35f49437c537dbfa0d), [`784ad98`](https://github.com/mastra-ai/mastra/commit/784ad989549de91dc5d33ab8ef36caa6f7dcd34e), [`0d53730`](https://github.com/mastra-ai/mastra/commit/0d53730c1ed87ef80c87caa5701c4170ea8028e6)]:
92
+ - @mastra/core@1.34.0-alpha.0
package/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
16
+ # Apache License 2.0
17
+
18
+ Copyright (c) 2025 Kepler Software, Inc.
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # @mastra/acp
2
+
3
+ `@mastra/acp` connects Mastra to coding agents that implement the Agent Client Protocol (ACP). Use it to run an ACP-compatible agent from a Mastra tool or as a Mastra sub-agent.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/acp
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ The package exports:
14
+
15
+ - `createACPTool`: Creates a Mastra tool that sends a task to an ACP agent and returns the completed output.
16
+ - `AcpAgent`: Wraps an ACP agent as a Mastra sub-agent with `generate()` and `stream()` support.
17
+
18
+ Use `createACPTool` when the ACP agent should be callable as a tool. Use `AcpAgent` when the ACP agent should participate in Mastra agent delegation.
19
+
20
+ ## Create an ACP tool
21
+
22
+ The following example creates a tool that starts an ACP-compatible agent process and sends the provided task to it.
23
+
24
+ ```typescript
25
+ import { Agent } from '@mastra/core/agent';
26
+ import { createACPTool } from '@mastra/acp';
27
+
28
+ const codeAgentTool = createACPTool({
29
+ id: 'code-agent',
30
+ description: 'Use an ACP-compatible coding agent to make code changes',
31
+ command: 'acp-agent',
32
+ args: ['--stdio'],
33
+ cwd: process.cwd(),
34
+ });
35
+
36
+ export const agent = new Agent({
37
+ name: 'supervisor',
38
+ instructions: 'Use the code-agent tool when a task requires editing code.',
39
+ model,
40
+ tools: {
41
+ codeAgentTool,
42
+ },
43
+ });
44
+ ```
45
+
46
+ The tool accepts a `task` string and returns an `output` string.
47
+
48
+ ```typescript
49
+ const result = await codeAgentTool.execute({
50
+ context: {
51
+ task: 'Update the README with setup instructions.',
52
+ },
53
+ });
54
+
55
+ console.log(result.output);
56
+ ```
57
+
58
+ ## Use an ACP agent as a sub-agent
59
+
60
+ `AcpAgent` implements Mastra's `SubAgent` interface. Add it to another agent's `agents` configuration to let the supervisor delegate work to the ACP agent.
61
+
62
+ ```typescript
63
+ import { Agent } from '@mastra/core/agent';
64
+ import { AcpAgent } from '@mastra/acp';
65
+
66
+ const codeAgent = new AcpAgent({
67
+ id: 'code-agent',
68
+ name: 'Code agent',
69
+ description: 'An ACP-compatible coding agent that can inspect and edit files',
70
+ command: 'acp-agent',
71
+ args: ['--stdio'],
72
+ cwd: process.cwd(),
73
+ });
74
+
75
+ export const supervisor = new Agent({
76
+ name: 'supervisor',
77
+ instructions: 'Delegate code editing tasks to the code-agent sub-agent.',
78
+ model,
79
+ agents: {
80
+ codeAgent,
81
+ },
82
+ });
83
+ ```
84
+
85
+ `AcpAgent.generate()` buffers the ACP response and returns it as text. `AcpAgent.stream()` emits Mastra `text-delta` chunks as ACP `agent_message_chunk` updates arrive.
86
+
87
+ ## Configure permissions
88
+
89
+ ACP agents may request permission before running actions. By default, `@mastra/acp` selects the first permission option. Pass `onPermissionRequest` to handle permission requests yourself.
90
+
91
+ ```typescript
92
+ import { createACPTool } from '@mastra/acp';
93
+
94
+ const codeAgentTool = createACPTool({
95
+ id: 'code-agent',
96
+ description: 'Use an ACP-compatible coding agent',
97
+ command: 'acp-agent',
98
+ args: ['--stdio'],
99
+ async onPermissionRequest(request) {
100
+ const option = request.options.find(option => option.name === 'Allow');
101
+
102
+ if (!option) {
103
+ return { outcome: { outcome: 'cancelled' } };
104
+ }
105
+
106
+ return {
107
+ outcome: {
108
+ outcome: 'selected',
109
+ optionId: option.optionId,
110
+ },
111
+ };
112
+ },
113
+ });
114
+ ```
115
+
116
+ ## Session and workspace behavior
117
+
118
+ `createACPTool` and `AcpAgent` start the configured command on first use and create an ACP session. Sessions persist across calls by default. Set `persistSession: false` to stop the ACP process after each prompt.
119
+
120
+ ```typescript
121
+ const codeAgent = new AcpAgent({
122
+ id: 'code-agent',
123
+ description: 'Run one isolated ACP task',
124
+ command: 'acp-agent',
125
+ args: ['--stdio'],
126
+ cwd: process.cwd(),
127
+ persistSession: false,
128
+ });
129
+ ```
130
+
131
+ By default, the ACP workspace uses `cwd` as its filesystem root. Pass a Mastra `Workspace` with a custom filesystem when you need explicit workspace control.
132
+
133
+ ## Configuration
134
+
135
+ `createACPTool` and `AcpAgent` accept the same ACP connection options.
136
+
137
+ | Option | Type | Description |
138
+ | --------------------- | -------------------------------- | -------------------------------------------------------------------------------------- |
139
+ | `id` | `string` | Unique tool or sub-agent identifier. |
140
+ | `description` | `string` | Description shown to the model when it can call the tool or delegate to the sub-agent. |
141
+ | `command` | `string` | ACP agent executable to spawn. |
142
+ | `args` | `string[]` | Arguments passed to the ACP agent executable. |
143
+ | `env` | `Record<string, string>` | Environment variables to merge with the current process environment. |
144
+ | `cwd` | `string` | Working directory for the ACP process and default workspace. |
145
+ | `session` | `Partial<NewSessionRequest>` | ACP session creation options. |
146
+ | `initialize` | `Partial<InitializeRequest>` | ACP initialization options. |
147
+ | `authMethodId` | `string` | ACP authentication method ID to invoke after initialization. |
148
+ | `persistSession` | `boolean` | Keep the ACP process alive after execution. Defaults to `true`. |
149
+ | `onPermissionRequest` | `(request) => Promise<Response>` | Callback for ACP permission requests. |
150
+ | `workspace` | `Workspace` | Workspace used for ACP file reads and writes. |
151
+
152
+ `AcpAgent` also accepts `name` to set the display name used by Mastra agent delegation.
@@ -0,0 +1,30 @@
1
+ import type { AgentGenerateOptions, AgentStreamOptions, SubAgent, SubAgentGenerateResult, SubAgentStreamResult } from '@mastra/core/agent';
2
+ import type { MessageListInput } from '@mastra/core/agent/message-list';
3
+ import type { Mastra } from '@mastra/core/mastra';
4
+ import type { DynamicArgument } from '@mastra/core/types';
5
+ import { ACPConnection } from './connection.js';
6
+ import type { CreateACPToolOptions } from './types.js';
7
+ export type AcpAgentOptions = CreateACPToolOptions & {
8
+ name?: string;
9
+ };
10
+ export declare class AcpAgent<TId extends string = string, TRequestContext extends Record<string, any> | unknown = unknown> implements SubAgent<TId, TRequestContext> {
11
+ readonly id: TId;
12
+ readonly name: string;
13
+ readonly connection: ACPConnection;
14
+ readonly description: string;
15
+ constructor(options: AcpAgentOptions);
16
+ __registerMastra(_mastra: Mastra): void;
17
+ getDescription(): string;
18
+ getModel(): ReturnType<SubAgent<TId, TRequestContext>['getModel']>;
19
+ hasOwnMemory(): boolean;
20
+ __setMemory(_memory: DynamicArgument<any, any>): void;
21
+ getMemory(): undefined;
22
+ getInstructions(): string;
23
+ generate(messages: MessageListInput, options?: AgentGenerateOptions): Promise<SubAgentGenerateResult>;
24
+ resumeGenerate(): Promise<SubAgentGenerateResult>;
25
+ resumeStream(): Promise<SubAgentStreamResult>;
26
+ stream(messages: MessageListInput, options?: AgentStreamOptions): Promise<SubAgentStreamResult>;
27
+ private getPrompt;
28
+ private createMessageList;
29
+ }
30
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EAEpB,kBAAkB,EAElB,QAAQ,EACR,sBAAs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;IAmBrG,cAAc,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAIjD,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAI7C,MAAM,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAsErG,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,iBAAiB;CAM1B"}
@@ -0,0 +1,31 @@
1
+ import type { SessionUpdate } from '@agentclientprotocol/sdk';
2
+ import type { CreateACPToolOptions } from './types.js';
3
+ export type ACPStreamEvent = {
4
+ type: 'text';
5
+ text: string;
6
+ } | {
7
+ type: 'session-update';
8
+ update: SessionUpdate;
9
+ };
10
+ export declare class ACPConnection {
11
+ readonly options: CreateACPToolOptions;
12
+ private agentProcess?;
13
+ private connection?;
14
+ private session?;
15
+ private initializePromise?;
16
+ private currentPrompt?;
17
+ private stderr;
18
+ constructor(options: CreateACPToolOptions);
19
+ get sessionId(): string | undefined;
20
+ prompt(task: string, signal?: AbortSignal): Promise<string>;
21
+ promptStream(task: string, signal?: AbortSignal): AsyncGenerator<ACPStreamEvent>;
22
+ cancel(): Promise<void>;
23
+ disconnect(): void;
24
+ private ensureConnected;
25
+ private initialize;
26
+ private getInitializeRequest;
27
+ private getNewSessionRequest;
28
+ private throwIfPromptDidNotComplete;
29
+ private withStderr;
30
+ }
31
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAYV,aAAa,EAGd,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAuEhH,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IAEvC,OAAO,CAAC,YAAY,CAAC,CAAiC;IACtD,OAAO,CAAC,UAAU,CAAC,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAAC,CAAqB;IACrC,OAAO,CAAC,iBAAiB,CAAC,CAAgB;IAC1C,OAAO,CAAC,aAAa,CAAC,CAAc;IACpC,OAAO,CAAC,MAAM,CAAM;gBAER,OAAO,EAAE,oBAAoB;IAIzC,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAEK,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAY1D,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC;IAgEjF,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAU7B,UAAU,IAAI,IAAI;YAaJ,eAAe;YASf,UAAU;IA0CxB,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,UAAU;CAanB"}