macro-agent 0.0.13 → 0.0.15

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 (143) hide show
  1. package/.claude/settings.local.json +59 -0
  2. package/dist/agent/agent-manager.d.ts.map +1 -1
  3. package/dist/agent/agent-manager.js +10 -4
  4. package/dist/agent/agent-manager.js.map +1 -1
  5. package/dist/cli/acp.d.ts +6 -0
  6. package/dist/cli/acp.d.ts.map +1 -1
  7. package/dist/cli/acp.js +16 -2
  8. package/dist/cli/acp.js.map +1 -1
  9. package/dist/map/adapter/index.d.ts +1 -1
  10. package/dist/map/adapter/index.d.ts.map +1 -1
  11. package/dist/map/adapter/index.js +1 -1
  12. package/dist/map/adapter/index.js.map +1 -1
  13. package/dist/map/utils/address-translation.d.ts +99 -0
  14. package/dist/map/utils/address-translation.d.ts.map +1 -0
  15. package/dist/map/utils/address-translation.js +285 -0
  16. package/dist/map/utils/address-translation.js.map +1 -0
  17. package/dist/map/utils/index.d.ts +7 -0
  18. package/dist/map/utils/index.d.ts.map +1 -0
  19. package/dist/map/utils/index.js +7 -0
  20. package/dist/map/utils/index.js.map +1 -0
  21. package/dist/server/combined-server.d.ts.map +1 -1
  22. package/dist/server/combined-server.js +8 -1
  23. package/dist/server/combined-server.js.map +1 -1
  24. package/dist/store/event-store.js +9 -2
  25. package/dist/store/event-store.js.map +1 -1
  26. package/dist/store/types/agents.d.ts +2 -0
  27. package/dist/store/types/agents.d.ts.map +1 -1
  28. package/package.json +4 -4
  29. package/references/acp-factory-ref/CHANGELOG.md +33 -0
  30. package/references/acp-factory-ref/LICENSE +21 -0
  31. package/references/acp-factory-ref/README.md +341 -0
  32. package/references/acp-factory-ref/package-lock.json +3102 -0
  33. package/references/acp-factory-ref/package.json +96 -0
  34. package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
  35. package/references/acp-factory-ref/python/LICENSE +21 -0
  36. package/references/acp-factory-ref/python/Makefile +57 -0
  37. package/references/acp-factory-ref/python/README.md +253 -0
  38. package/references/acp-factory-ref/python/pyproject.toml +73 -0
  39. package/references/acp-factory-ref/python/tests/__init__.py +0 -0
  40. package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
  41. package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
  42. package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
  43. package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
  44. package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
  45. package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
  46. package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
  47. package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
  48. package/references/claude-code-acp/.prettierrc.json +4 -0
  49. package/references/claude-code-acp/CHANGELOG.md +249 -0
  50. package/references/claude-code-acp/LICENSE +222 -0
  51. package/references/claude-code-acp/README.md +53 -0
  52. package/references/claude-code-acp/docs/RELEASES.md +24 -0
  53. package/references/claude-code-acp/eslint.config.js +48 -0
  54. package/references/claude-code-acp/package-lock.json +4570 -0
  55. package/references/claude-code-acp/package.json +88 -0
  56. package/references/claude-code-acp/scripts/release.sh +119 -0
  57. package/references/claude-code-acp/src/acp-agent.ts +2079 -0
  58. package/references/claude-code-acp/src/index.ts +26 -0
  59. package/references/claude-code-acp/src/lib.ts +38 -0
  60. package/references/claude-code-acp/src/mcp-server.ts +911 -0
  61. package/references/claude-code-acp/src/settings.ts +522 -0
  62. package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
  63. package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
  64. package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
  65. package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
  66. package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
  67. package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
  68. package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
  69. package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
  70. package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
  71. package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
  72. package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
  73. package/references/claude-code-acp/src/tools.ts +819 -0
  74. package/references/claude-code-acp/src/utils.ts +171 -0
  75. package/references/claude-code-acp/tsconfig.json +18 -0
  76. package/references/claude-code-acp/vitest.config.ts +19 -0
  77. package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
  78. package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
  79. package/references/multi-agent-protocol/LICENSE +21 -0
  80. package/references/multi-agent-protocol/README.md +113 -0
  81. package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
  82. package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
  83. package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
  84. package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
  85. package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
  86. package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
  87. package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
  88. package/references/multi-agent-protocol/docs/07-federation.md +259 -0
  89. package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
  90. package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
  91. package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
  92. package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
  93. package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
  94. package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
  95. package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
  96. package/references/multi-agent-protocol/docs-site/README.md +82 -0
  97. package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
  98. package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
  99. package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
  100. package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
  101. package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
  102. package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
  103. package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
  104. package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
  105. package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
  106. package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
  107. package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
  108. package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
  109. package/references/multi-agent-protocol/docs-site/index.md +136 -0
  110. package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
  111. package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
  112. package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
  113. package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
  114. package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
  115. package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
  116. package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
  117. package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
  118. package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
  119. package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
  120. package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
  121. package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
  122. package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
  123. package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
  124. package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
  125. package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
  126. package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
  127. package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
  128. package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
  129. package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
  130. package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
  131. package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
  132. package/references/multi-agent-protocol/package-lock.json +3886 -0
  133. package/references/multi-agent-protocol/package.json +56 -0
  134. package/references/multi-agent-protocol/schema/meta.json +467 -0
  135. package/references/multi-agent-protocol/schema/schema.json +2558 -0
  136. package/src/agent/__tests__/agent-manager.test.ts +67 -1
  137. package/src/agent/agent-manager.ts +10 -4
  138. package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
  139. package/src/cli/acp.ts +17 -2
  140. package/src/map/adapter/index.ts +3 -0
  141. package/src/server/combined-server.ts +10 -0
  142. package/src/store/event-store.ts +10 -3
  143. package/src/store/types/agents.ts +2 -0
@@ -0,0 +1,312 @@
1
+ ---
2
+ title: Error Handling
3
+ parent: Protocol
4
+ nav_order: 5
5
+ description: "Error taxonomy, codes, and recovery mechanisms"
6
+ ---
7
+
8
+ # Error Handling
9
+ {: .no_toc }
10
+
11
+ Error taxonomy, failure modes, and recovery mechanisms.
12
+ {: .fs-6 .fw-300 }
13
+
14
+ ## Table of contents
15
+ {: .no_toc .text-delta }
16
+
17
+ 1. TOC
18
+ {:toc}
19
+
20
+ ---
21
+
22
+ ## Design Goals
23
+
24
+ 1. **Graceful degradation** - Partial failures don't cascade to total failure
25
+ 2. **Clear error taxonomy** - Distinct error types with actionable codes
26
+ 3. **Recovery semantics** - Well-defined reconnection and replay behavior
27
+ 4. **Federation resilience** - Cross-system failures handled gracefully
28
+ 5. **Observability** - Errors are traceable and debuggable
29
+
30
+ ---
31
+
32
+ ## Error Structure
33
+
34
+ ```typescript
35
+ interface MAPError {
36
+ code: number; // Numeric code
37
+ category: MAPErrorCategory;
38
+ message: string; // Human-readable
39
+
40
+ details?: {
41
+ agentId?: string;
42
+ messageId?: string;
43
+ method?: string;
44
+ retryable?: boolean;
45
+ retryAfter?: number; // Milliseconds
46
+ recoveryHint?: string;
47
+ };
48
+
49
+ traceId?: string;
50
+ timestamp?: number;
51
+ }
52
+
53
+ type MAPErrorCategory =
54
+ | "protocol" // Wire protocol violations
55
+ | "auth" // Authentication/authorization
56
+ | "routing" // Message delivery failures
57
+ | "agent" // Agent lifecycle errors
58
+ | "resource" // Resource exhaustion
59
+ | "federation" // Cross-system errors
60
+ | "internal"; // Server internal errors
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Error Codes
66
+
67
+ ### Protocol Errors (-32xxx)
68
+
69
+ JSON-RPC compatible error codes:
70
+
71
+ | Code | Name | Description |
72
+ |:-----|:-----|:------------|
73
+ | -32700 | PARSE_ERROR | Invalid JSON |
74
+ | -32600 | INVALID_REQUEST | Invalid request structure |
75
+ | -32601 | METHOD_NOT_FOUND | Method does not exist |
76
+ | -32602 | INVALID_PARAMS | Invalid method parameters |
77
+ | -32603 | INTERNAL_ERROR | Internal server error |
78
+
79
+ ### Authentication Errors (1xxx)
80
+
81
+ | Code | Name | Description | Retryable |
82
+ |:-----|:-----|:------------|:----------|
83
+ | 1000 | AUTH_REQUIRED | Authentication required | Yes (with credentials) |
84
+ | 1001 | AUTH_FAILED | Invalid credentials | No |
85
+ | 1002 | AUTH_EXPIRED | Token expired | Yes (with refresh) |
86
+ | 1003 | PERMISSION_DENIED | Insufficient permissions | No |
87
+
88
+ ### Routing Errors (2xxx)
89
+
90
+ | Code | Name | Description | Retryable |
91
+ |:-----|:-----|:------------|:----------|
92
+ | 2000 | AGENT_NOT_FOUND | Target agent doesn't exist | No |
93
+ | 2001 | AGENT_STOPPED | Target agent has stopped | No |
94
+ | 2002 | AGENT_BUSY | Target agent at capacity | Yes |
95
+ | 2003 | SCOPE_NOT_FOUND | Target scope doesn't exist | No |
96
+ | 2004 | NO_RECIPIENTS | No valid recipients | No |
97
+ | 2005 | PERMISSION_DENIED | Cannot message target | No |
98
+ | 2006 | DELIVERY_FAILED | Message delivery failed | Yes |
99
+ | 2007 | DELIVERY_TIMEOUT | Delivery timed out | Yes |
100
+
101
+ ### Agent Lifecycle Errors (3xxx)
102
+
103
+ | Code | Name | Description | Retryable |
104
+ |:-----|:-----|:------------|:----------|
105
+ | 3000 | AGENT_EXISTS | Agent ID already registered | No |
106
+ | 3001 | INVALID_PARENT | Parent agent doesn't exist | No |
107
+ | 3002 | HIERARCHY_CYCLE | Would create cycle in hierarchy | No |
108
+ | 3003 | MAX_AGENTS_EXCEEDED | System at capacity | Yes |
109
+ | 3004 | INVALID_STATE | Invalid state transition | No |
110
+ | 3005 | SPAWN_FAILED | Child agent spawn failed | Yes |
111
+
112
+ ### Resource Errors (4xxx)
113
+
114
+ | Code | Name | Description | Retryable |
115
+ |:-----|:-----|:------------|:----------|
116
+ | 4000 | RATE_LIMITED | Too many requests | Yes |
117
+ | 4001 | QUOTA_EXCEEDED | Resource quota exceeded | No |
118
+ | 4002 | BUFFER_OVERFLOW | Event buffer overflow | Yes |
119
+ | 4003 | MAX_SUBSCRIPTIONS | Subscription limit reached | No |
120
+ | 4004 | MESSAGE_TOO_LARGE | Payload exceeds limit | No |
121
+
122
+ ### Federation Errors (5xxx)
123
+
124
+ | Code | Name | Description | Retryable |
125
+ |:-----|:-----|:------------|:----------|
126
+ | 5000 | PEER_UNREACHABLE | Cannot connect to peer | Yes |
127
+ | 5001 | PEER_TIMEOUT | Peer response timeout | Yes |
128
+ | 5002 | PEER_REJECTED | Peer rejected connection | No |
129
+ | 5003 | ROUTING_FAILED | Cross-system routing failed | Yes |
130
+
131
+ ---
132
+
133
+ ## Agent Failure Modes
134
+
135
+ ### 1. Graceful Shutdown
136
+
137
+ ```
138
+ Agent: sends shutdown intent
139
+ Server: drains queue, notifies parent, cleans up
140
+ Recovery: None needed (intentional)
141
+ ```
142
+
143
+ ### 2. Crash (Unexpected Termination)
144
+
145
+ ```
146
+ Detection: Heartbeat timeout, process exit
147
+ Server: Marks stopped, notifies parent, orphan handling
148
+ Recovery: Restart with same ID or spawn replacement
149
+ ```
150
+
151
+ ### 3. Hang (Unresponsive)
152
+
153
+ ```
154
+ Detection: Request timeout, no heartbeat
155
+ Server: Marks blocked, notifies parent
156
+ Recovery: Force restart or manual intervention
157
+ ```
158
+
159
+ ### 4. Error Loop (Repeated Failures)
160
+
161
+ ```
162
+ Detection: Error rate threshold exceeded
163
+ Server: Circuit breaker, reduce routing
164
+ Recovery: Exponential backoff restart
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Orphan Handling
170
+
171
+ When an agent fails, its children and pending work must be handled:
172
+
173
+ ```typescript
174
+ interface OrphanPolicy {
175
+ tasks: "reassign" | "return_to_parent" | "fail" | "hold";
176
+ children: "cascade_stop" | "reparent" | "orphan";
177
+ messages: "drop" | "bounce" | "redirect";
178
+ }
179
+ ```
180
+
181
+ ### Default Policy
182
+
183
+ ```typescript
184
+ const DEFAULT_ORPHAN_POLICY: OrphanPolicy = {
185
+ tasks: "return_to_parent",
186
+ children: "cascade_stop",
187
+ messages: "bounce"
188
+ };
189
+ ```
190
+
191
+ ---
192
+
193
+ ## Circuit Breakers
194
+
195
+ Per-agent circuit breakers prevent cascading failures:
196
+
197
+ ```typescript
198
+ interface CircuitBreakerState {
199
+ agentId: string;
200
+ state: "closed" | "open" | "half-open";
201
+
202
+ // Thresholds
203
+ failureThreshold: number; // Failures to open
204
+ successThreshold: number; // Successes to close
205
+ timeout: number; // Time before half-open
206
+
207
+ // Counters
208
+ failureCount: number;
209
+ successCount: number;
210
+ lastFailure: number;
211
+ lastStateChange: number;
212
+ }
213
+ ```
214
+
215
+ ### Circuit Breaker States
216
+
217
+ ```mermaid
218
+ stateDiagram-v2
219
+ [*] --> CLOSED
220
+ CLOSED --> OPEN: failure threshold
221
+ OPEN --> HALF_OPEN: timeout
222
+ HALF_OPEN --> CLOSED: success
223
+ HALF_OPEN --> OPEN: failure
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Retry Policies
229
+
230
+ ```typescript
231
+ interface RetryPolicy {
232
+ maxAttempts: number;
233
+ backoff: {
234
+ type: "exponential" | "linear" | "constant";
235
+ initial: number; // Initial delay (ms)
236
+ max: number; // Maximum delay (ms)
237
+ multiplier?: number; // For exponential
238
+ };
239
+ retryableErrors: number[];
240
+ nonRetryableErrors: number[];
241
+ }
242
+
243
+ // Default policy
244
+ const DEFAULT_RETRY: RetryPolicy = {
245
+ maxAttempts: 3,
246
+ backoff: {
247
+ type: "exponential",
248
+ initial: 1000,
249
+ max: 30000,
250
+ multiplier: 2
251
+ },
252
+ retryableErrors: [2002, 2007, 4000, 5001],
253
+ nonRetryableErrors: [1001, 1003, 2000, 3002]
254
+ };
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Reconnection Protocol
260
+
261
+ ```mermaid
262
+ sequenceDiagram
263
+ participant Client
264
+ participant Server
265
+
266
+ Server--xClient: Connection Lost
267
+ Note over Client: Backoff: 1s, 2s, 4s, 8s...
268
+ Client->>Server: Reconnect Attempt
269
+ Server-->>Client: Connection Accept
270
+ Client->>Server: map/reconnect {lastEventId, subscriptions}
271
+ Server-->>Client: Reconnect Response {missedEvents, newState}
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Distributed Tracing
277
+
278
+ All errors include tracing context:
279
+
280
+ ```typescript
281
+ interface TracingContext {
282
+ traceId: string; // Unique trace identifier
283
+ spanId: string; // Current span
284
+ parentSpanId?: string;
285
+ baggage?: Record<string, string>;
286
+ }
287
+ ```
288
+
289
+ Errors propagate tracing information:
290
+
291
+ ```typescript
292
+ {
293
+ "error": {
294
+ "code": 2006,
295
+ "category": "routing",
296
+ "message": "Delivery failed: agent_001 not responding",
297
+ "details": {
298
+ "agentId": "agent_001",
299
+ "retryable": true,
300
+ "retryAfter": 5000
301
+ },
302
+ "traceId": "abc123def456"
303
+ }
304
+ }
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Next Steps
310
+
311
+ - [Authentication](./authentication.html) - Auth error handling
312
+ - [Federation](./federation.html) - Cross-system error handling