macro-agent 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/.claude/settings.local.json +59 -0
  2. package/dist/acp/index.d.ts +1 -1
  3. package/dist/acp/index.d.ts.map +1 -1
  4. package/dist/acp/index.js.map +1 -1
  5. package/dist/acp/macro-agent.d.ts +21 -0
  6. package/dist/acp/macro-agent.d.ts.map +1 -1
  7. package/dist/acp/macro-agent.js +182 -0
  8. package/dist/acp/macro-agent.js.map +1 -1
  9. package/dist/acp/types.d.ts +31 -2
  10. package/dist/acp/types.d.ts.map +1 -1
  11. package/dist/acp/types.js.map +1 -1
  12. package/dist/agent/agent-manager.d.ts.map +1 -1
  13. package/dist/agent/agent-manager.js +10 -4
  14. package/dist/agent/agent-manager.js.map +1 -1
  15. package/dist/cli/acp.d.ts +6 -0
  16. package/dist/cli/acp.d.ts.map +1 -1
  17. package/dist/cli/acp.js +16 -2
  18. package/dist/cli/acp.js.map +1 -1
  19. package/dist/map/adapter/acp-over-map.d.ts +5 -0
  20. package/dist/map/adapter/acp-over-map.d.ts.map +1 -1
  21. package/dist/map/adapter/acp-over-map.js +47 -4
  22. package/dist/map/adapter/acp-over-map.js.map +1 -1
  23. package/dist/map/utils/address-translation.d.ts +99 -0
  24. package/dist/map/utils/address-translation.d.ts.map +1 -0
  25. package/dist/map/utils/address-translation.js +285 -0
  26. package/dist/map/utils/address-translation.js.map +1 -0
  27. package/dist/map/utils/index.d.ts +7 -0
  28. package/dist/map/utils/index.d.ts.map +1 -0
  29. package/dist/map/utils/index.js +7 -0
  30. package/dist/map/utils/index.js.map +1 -0
  31. package/dist/store/event-store.js +9 -2
  32. package/dist/store/event-store.js.map +1 -1
  33. package/dist/store/types/agents.d.ts +2 -0
  34. package/dist/store/types/agents.d.ts.map +1 -1
  35. package/package.json +4 -4
  36. package/references/acp-factory-ref/CHANGELOG.md +33 -0
  37. package/references/acp-factory-ref/LICENSE +21 -0
  38. package/references/acp-factory-ref/README.md +341 -0
  39. package/references/acp-factory-ref/package-lock.json +3102 -0
  40. package/references/acp-factory-ref/package.json +96 -0
  41. package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
  42. package/references/acp-factory-ref/python/LICENSE +21 -0
  43. package/references/acp-factory-ref/python/Makefile +57 -0
  44. package/references/acp-factory-ref/python/README.md +253 -0
  45. package/references/acp-factory-ref/python/pyproject.toml +73 -0
  46. package/references/acp-factory-ref/python/tests/__init__.py +0 -0
  47. package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
  48. package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
  49. package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
  50. package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
  51. package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
  52. package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
  53. package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
  54. package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
  55. package/references/claude-code-acp/.prettierrc.json +4 -0
  56. package/references/claude-code-acp/CHANGELOG.md +249 -0
  57. package/references/claude-code-acp/LICENSE +222 -0
  58. package/references/claude-code-acp/README.md +53 -0
  59. package/references/claude-code-acp/docs/RELEASES.md +24 -0
  60. package/references/claude-code-acp/eslint.config.js +48 -0
  61. package/references/claude-code-acp/package-lock.json +4570 -0
  62. package/references/claude-code-acp/package.json +88 -0
  63. package/references/claude-code-acp/scripts/release.sh +119 -0
  64. package/references/claude-code-acp/src/acp-agent.ts +2079 -0
  65. package/references/claude-code-acp/src/index.ts +26 -0
  66. package/references/claude-code-acp/src/lib.ts +38 -0
  67. package/references/claude-code-acp/src/mcp-server.ts +911 -0
  68. package/references/claude-code-acp/src/settings.ts +522 -0
  69. package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
  70. package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
  71. package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
  72. package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
  73. package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
  74. package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
  75. package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
  76. package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
  77. package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
  78. package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
  79. package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
  80. package/references/claude-code-acp/src/tools.ts +819 -0
  81. package/references/claude-code-acp/src/utils.ts +171 -0
  82. package/references/claude-code-acp/tsconfig.json +18 -0
  83. package/references/claude-code-acp/vitest.config.ts +19 -0
  84. package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
  85. package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
  86. package/references/multi-agent-protocol/LICENSE +21 -0
  87. package/references/multi-agent-protocol/README.md +113 -0
  88. package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
  89. package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
  90. package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
  91. package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
  92. package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
  93. package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
  94. package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
  95. package/references/multi-agent-protocol/docs/07-federation.md +259 -0
  96. package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
  97. package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
  98. package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
  99. package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
  100. package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
  101. package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
  102. package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
  103. package/references/multi-agent-protocol/docs-site/README.md +82 -0
  104. package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
  105. package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
  106. package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
  107. package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
  108. package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
  109. package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
  110. package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
  111. package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
  112. package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
  113. package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
  114. package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
  115. package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
  116. package/references/multi-agent-protocol/docs-site/index.md +136 -0
  117. package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
  118. package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
  119. package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
  120. package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
  121. package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
  122. package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
  123. package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
  124. package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
  125. package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
  126. package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
  127. package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
  128. package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
  129. package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
  130. package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
  131. package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
  132. package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
  133. package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
  134. package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
  135. package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
  136. package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
  137. package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
  138. package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
  139. package/references/multi-agent-protocol/package-lock.json +3886 -0
  140. package/references/multi-agent-protocol/package.json +56 -0
  141. package/references/multi-agent-protocol/schema/meta.json +467 -0
  142. package/references/multi-agent-protocol/schema/schema.json +2558 -0
  143. package/src/acp/__tests__/history.test.ts +526 -0
  144. package/src/acp/__tests__/integration.test.ts +2 -1
  145. package/src/acp/index.ts +4 -0
  146. package/src/acp/macro-agent.ts +329 -85
  147. package/src/acp/types.ts +39 -2
  148. package/src/agent/__tests__/agent-manager.test.ts +67 -1
  149. package/src/agent/agent-manager.ts +10 -4
  150. package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
  151. package/src/cli/acp.ts +17 -2
  152. package/src/map/adapter/acp-over-map.ts +57 -2
  153. package/src/store/event-store.ts +10 -3
  154. package/src/store/types/agents.ts +2 -0
@@ -0,0 +1,341 @@
1
+ # acp-factory
2
+
3
+ A TypeScript library for spawning and managing AI agents through the [Agent Client Protocol (ACP)](https://agentclientprotocol.com/).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install acp-factory
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ - Node.js 18+
14
+ - [Claude Code](https://claude.ai/claude-code) installed and authenticated (run `claude` once to set up)
15
+ - Or set `ANTHROPIC_API_KEY` environment variable
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { AgentFactory } from "acp-factory";
21
+
22
+ // Spawn a Claude Code agent
23
+ const agent = await AgentFactory.spawn("claude-code", {
24
+ permissionMode: "auto-approve",
25
+ });
26
+
27
+ // Create a session
28
+ const session = await agent.createSession(process.cwd());
29
+
30
+ // Send a prompt and stream responses
31
+ for await (const update of session.prompt("What files are in this directory?")) {
32
+ if (update.sessionUpdate === "agent_message_chunk") {
33
+ if (update.content.type === "text") {
34
+ process.stdout.write(update.content.text);
35
+ }
36
+ }
37
+ }
38
+
39
+ // Clean up
40
+ await agent.close();
41
+ ```
42
+
43
+ ## API Reference
44
+
45
+ ### AgentFactory
46
+
47
+ Static class for managing agent types and spawning agents.
48
+
49
+ ```typescript
50
+ // List available agents
51
+ AgentFactory.listAgents(); // ["claude-code"]
52
+
53
+ // Register a custom agent
54
+ AgentFactory.register("my-agent", {
55
+ command: "npx",
56
+ args: ["my-agent-acp"],
57
+ env: { MY_VAR: "value" },
58
+ });
59
+
60
+ // Spawn an agent
61
+ const agent = await AgentFactory.spawn("claude-code", options);
62
+ ```
63
+
64
+ ### AgentHandle
65
+
66
+ Represents a running agent process.
67
+
68
+ ```typescript
69
+ // Agent capabilities
70
+ agent.capabilities; // { loadSession: true, ... }
71
+
72
+ // Create a new session
73
+ const session = await agent.createSession("/path/to/cwd", {
74
+ mode: "code", // Optional: initial mode
75
+ mcpServers: [], // Optional: MCP servers to connect
76
+ });
77
+
78
+ // Load an existing session
79
+ const session = await agent.loadSession(sessionId, "/path/to/cwd");
80
+
81
+ // Fork an existing session (experimental)
82
+ const forkedSession = await agent.forkSession(sessionId);
83
+
84
+ // Close the agent
85
+ await agent.close();
86
+
87
+ // Check if running
88
+ agent.isRunning(); // true/false
89
+ ```
90
+
91
+ ### Session
92
+
93
+ High-level interface for interacting with an agent session.
94
+
95
+ ```typescript
96
+ // Session properties
97
+ session.id; // Session ID
98
+ session.modes; // Available modes ["code", "ask", ...]
99
+ session.models; // Available models ["claude-sonnet-4-...", ...]
100
+
101
+ // Send a prompt (returns async iterable)
102
+ for await (const update of session.prompt("Hello!")) {
103
+ // Handle updates
104
+ }
105
+
106
+ // Cancel the current prompt
107
+ await session.cancel();
108
+
109
+ // Set the session mode
110
+ await session.setMode("ask");
111
+
112
+ // Interrupt and redirect with new context
113
+ for await (const update of session.interruptWith("Focus on tests only")) {
114
+ // Handle updates from new prompt
115
+ }
116
+
117
+ // Fork the session (experimental)
118
+ const forkedSession = await session.fork();
119
+ ```
120
+
121
+ ## Session Updates
122
+
123
+ The `prompt()` method yields `SessionUpdate` objects:
124
+
125
+ ```typescript
126
+ for await (const update of session.prompt("Hello")) {
127
+ switch (update.sessionUpdate) {
128
+ case "agent_message_chunk":
129
+ // Text or image content from the agent
130
+ if (update.content.type === "text") {
131
+ process.stdout.write(update.content.text);
132
+ }
133
+ break;
134
+
135
+ case "tool_call":
136
+ // Agent is calling a tool
137
+ console.log(`Tool: ${update.title}`);
138
+ break;
139
+
140
+ case "tool_call_update":
141
+ // Tool call status changed
142
+ if (update.status === "completed") {
143
+ console.log("Tool completed");
144
+ }
145
+ break;
146
+
147
+ case "agent_thought_chunk":
148
+ // Agent's thinking (if enabled)
149
+ break;
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## Permission Modes
155
+
156
+ Control how permission requests are handled:
157
+
158
+ ```typescript
159
+ // Auto-approve all requests (default)
160
+ await AgentFactory.spawn("claude-code", {
161
+ permissionMode: "auto-approve",
162
+ });
163
+
164
+ // Auto-deny all requests
165
+ await AgentFactory.spawn("claude-code", {
166
+ permissionMode: "auto-deny",
167
+ });
168
+
169
+ // Use a callback handler
170
+ await AgentFactory.spawn("claude-code", {
171
+ permissionMode: "callback",
172
+ onPermissionRequest: async (request) => {
173
+ // Return permission response
174
+ return {
175
+ outcome: { outcome: "selected", optionId: "allow" },
176
+ };
177
+ },
178
+ });
179
+
180
+ // Interactive mode - permissions emitted as session updates
181
+ await AgentFactory.spawn("claude-code", {
182
+ permissionMode: "interactive",
183
+ });
184
+ ```
185
+
186
+ ### Interactive Permissions
187
+
188
+ With `permissionMode: "interactive"`, permission requests appear as session updates:
189
+
190
+ ```typescript
191
+ import { type ExtendedSessionUpdate } from "acp-factory";
192
+
193
+ for await (const update of session.prompt("Write a file")) {
194
+ if (update.sessionUpdate === "permission_request") {
195
+ // Show options to user
196
+ console.log(`Permission needed: ${update.toolCall.title}`);
197
+ update.options.forEach((opt, i) => {
198
+ console.log(`${i + 1}. ${opt.name}`);
199
+ });
200
+
201
+ // Respond to the request
202
+ session.respondToPermission(update.requestId, update.options[0].optionId);
203
+ // Or cancel it
204
+ // session.cancelPermission(update.requestId);
205
+ }
206
+ }
207
+ ```
208
+
209
+ ## Interrupting and Redirecting
210
+
211
+ Interrupt an agent mid-execution and redirect with new context:
212
+
213
+ ```typescript
214
+ const promptIterator = session.prompt("Analyze this codebase")[Symbol.asyncIterator]();
215
+
216
+ while (true) {
217
+ const { done, value } = await promptIterator.next();
218
+ if (done) break;
219
+
220
+ handleUpdate(value);
221
+
222
+ if (userWantsToRedirect) {
223
+ // Interrupt and provide new direction
224
+ for await (const update of session.interruptWith("Focus only on the tests")) {
225
+ handleUpdate(update);
226
+ }
227
+ break;
228
+ }
229
+ }
230
+ ```
231
+
232
+ ## Forking Sessions
233
+
234
+ Fork a session to create an independent copy with shared history:
235
+
236
+ ```typescript
237
+ // Original session continues normally
238
+ const session = await agent.createSession(process.cwd());
239
+ await consumePrompt(session.prompt("Analyze the codebase"));
240
+
241
+ // Fork to generate summary without affecting original
242
+ const summarySession = await session.fork();
243
+ for await (const update of summarySession.prompt("Summarize our conversation")) {
244
+ // This doesn't affect the original session
245
+ }
246
+
247
+ // Original session can continue independently
248
+ for await (const update of session.prompt("Now implement the feature")) {
249
+ // Continues from original context
250
+ }
251
+ ```
252
+
253
+ ## Custom File and Terminal Handlers
254
+
255
+ Override default file operations or provide terminal support:
256
+
257
+ ```typescript
258
+ const agent = await AgentFactory.spawn("claude-code", {
259
+ // Custom file handling
260
+ onFileRead: async (path) => {
261
+ return await myCustomRead(path);
262
+ },
263
+ onFileWrite: async (path, content) => {
264
+ await myCustomWrite(path, content);
265
+ },
266
+
267
+ // Terminal support (all handlers required)
268
+ onTerminalCreate: async (params) => {
269
+ const id = createTerminal(params.command, params.args);
270
+ return { terminalId: id };
271
+ },
272
+ onTerminalOutput: async (terminalId) => {
273
+ return getTerminalOutput(terminalId);
274
+ },
275
+ onTerminalKill: async (terminalId) => {
276
+ killTerminal(terminalId);
277
+ },
278
+ onTerminalRelease: async (terminalId) => {
279
+ releaseTerminal(terminalId);
280
+ },
281
+ onTerminalWaitForExit: async (terminalId) => {
282
+ return await waitForExit(terminalId);
283
+ },
284
+ });
285
+ ```
286
+
287
+ ## Examples
288
+
289
+ See the [examples](./examples) directory:
290
+
291
+ - [`basic-usage.ts`](./examples/basic-usage.ts) - Simple prompt and response
292
+ - [`interactive-permissions.ts`](./examples/interactive-permissions.ts) - Handle permissions in UI
293
+ - [`interrupt-context.ts`](./examples/interrupt-context.ts) - Interrupt and redirect agent
294
+
295
+ Run examples with:
296
+
297
+ ```bash
298
+ npx tsx examples/basic-usage.ts
299
+ ```
300
+
301
+ ## Type Exports
302
+
303
+ The library exports all necessary types:
304
+
305
+ ```typescript
306
+ import {
307
+ // Core classes
308
+ AgentFactory,
309
+ AgentHandle,
310
+ Session,
311
+
312
+ // Configuration types
313
+ type AgentConfig,
314
+ type SpawnOptions,
315
+ type SessionOptions,
316
+ type PermissionMode,
317
+
318
+ // Session update types
319
+ type SessionUpdate,
320
+ type ExtendedSessionUpdate,
321
+ type PermissionRequestUpdate,
322
+
323
+ // Content types
324
+ type ContentBlock,
325
+ type TextContent,
326
+ type ImageContent,
327
+
328
+ // Tool types
329
+ type ToolCall,
330
+ type ToolCallUpdate,
331
+
332
+ // Permission types
333
+ type PermissionOption,
334
+ type RequestPermissionRequest,
335
+ type RequestPermissionResponse,
336
+ } from "acp-factory";
337
+ ```
338
+
339
+ ## License
340
+
341
+ MIT