macro-agent 0.1.8 → 0.1.10

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 (258) hide show
  1. package/CLAUDE.md +166 -33
  2. package/README.md +781 -131
  3. package/dist/acp/claude-code-replay.d.ts +11 -0
  4. package/dist/acp/claude-code-replay.d.ts.map +1 -0
  5. package/dist/acp/claude-code-replay.js +190 -0
  6. package/dist/acp/claude-code-replay.js.map +1 -0
  7. package/dist/acp/macro-agent.d.ts.map +1 -1
  8. package/dist/acp/macro-agent.js +155 -6
  9. package/dist/acp/macro-agent.js.map +1 -1
  10. package/dist/acp/types.d.ts +9 -0
  11. package/dist/acp/types.d.ts.map +1 -1
  12. package/dist/acp/types.js.map +1 -1
  13. package/dist/agent/agent-manager-v2.d.ts +21 -0
  14. package/dist/agent/agent-manager-v2.d.ts.map +1 -1
  15. package/dist/agent/agent-manager-v2.js +234 -43
  16. package/dist/agent/agent-manager-v2.js.map +1 -1
  17. package/dist/agent/agent-manager.d.ts +12 -0
  18. package/dist/agent/agent-manager.d.ts.map +1 -1
  19. package/dist/agent/agent-manager.js.map +1 -1
  20. package/dist/agent/types.d.ts +15 -2
  21. package/dist/agent/types.d.ts.map +1 -1
  22. package/dist/agent/types.js.map +1 -1
  23. package/dist/boot-v2.d.ts +41 -0
  24. package/dist/boot-v2.d.ts.map +1 -1
  25. package/dist/boot-v2.js +16 -1
  26. package/dist/boot-v2.js.map +1 -1
  27. package/dist/cli/index.js +56 -0
  28. package/dist/cli/index.js.map +1 -1
  29. package/dist/cognitive/macro-agent-backend.d.ts.map +1 -1
  30. package/dist/cognitive/macro-agent-backend.js +40 -22
  31. package/dist/cognitive/macro-agent-backend.js.map +1 -1
  32. package/dist/integrations/skilltree.d.ts.map +1 -1
  33. package/dist/integrations/skilltree.js +1 -0
  34. package/dist/integrations/skilltree.js.map +1 -1
  35. package/dist/lifecycle/cleanup.d.ts +33 -2
  36. package/dist/lifecycle/cleanup.d.ts.map +1 -1
  37. package/dist/lifecycle/cleanup.js +28 -6
  38. package/dist/lifecycle/cleanup.js.map +1 -1
  39. package/dist/lifecycle/handlers-v2.d.ts +7 -0
  40. package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
  41. package/dist/lifecycle/handlers-v2.js +28 -2
  42. package/dist/lifecycle/handlers-v2.js.map +1 -1
  43. package/dist/lifecycle/types.d.ts +11 -0
  44. package/dist/lifecycle/types.d.ts.map +1 -1
  45. package/dist/lifecycle/types.js.map +1 -1
  46. package/dist/map/acp-bridge.d.ts +9 -0
  47. package/dist/map/acp-bridge.d.ts.map +1 -1
  48. package/dist/map/acp-bridge.js +15 -2
  49. package/dist/map/acp-bridge.js.map +1 -1
  50. package/dist/map/cascade-bridge.d.ts +44 -0
  51. package/dist/map/cascade-bridge.d.ts.map +1 -0
  52. package/dist/map/cascade-bridge.js +257 -0
  53. package/dist/map/cascade-bridge.js.map +1 -0
  54. package/dist/map/lifecycle-bridge.d.ts +1 -1
  55. package/dist/map/lifecycle-bridge.d.ts.map +1 -1
  56. package/dist/map/lifecycle-bridge.js +58 -23
  57. package/dist/map/lifecycle-bridge.js.map +1 -1
  58. package/dist/map/server.d.ts.map +1 -1
  59. package/dist/map/server.js +47 -6
  60. package/dist/map/server.js.map +1 -1
  61. package/dist/map/sidecar.d.ts.map +1 -1
  62. package/dist/map/sidecar.js +33 -2
  63. package/dist/map/sidecar.js.map +1 -1
  64. package/dist/map/types.d.ts +20 -0
  65. package/dist/map/types.d.ts.map +1 -1
  66. package/dist/mcp/tools/done-v2.d.ts.map +1 -1
  67. package/dist/mcp/tools/done-v2.js +8 -0
  68. package/dist/mcp/tools/done-v2.js.map +1 -1
  69. package/dist/teams/team-manager-v2.d.ts.map +1 -1
  70. package/dist/teams/team-manager-v2.js +26 -0
  71. package/dist/teams/team-manager-v2.js.map +1 -1
  72. package/dist/teams/team-runtime-v2.d.ts.map +1 -1
  73. package/dist/teams/team-runtime-v2.js +16 -3
  74. package/dist/teams/team-runtime-v2.js.map +1 -1
  75. package/dist/workspace/config.d.ts +10 -10
  76. package/dist/workspace/config.d.ts.map +1 -1
  77. package/dist/workspace/config.js +4 -4
  78. package/dist/workspace/config.js.map +1 -1
  79. package/dist/workspace/git-cascade-adapter.d.ts +510 -0
  80. package/dist/workspace/git-cascade-adapter.d.ts.map +1 -0
  81. package/dist/workspace/git-cascade-adapter.js +908 -0
  82. package/dist/workspace/git-cascade-adapter.js.map +1 -0
  83. package/dist/workspace/index.d.ts +3 -3
  84. package/dist/workspace/index.d.ts.map +1 -1
  85. package/dist/workspace/index.js +4 -4
  86. package/dist/workspace/index.js.map +1 -1
  87. package/dist/workspace/landing/direct-push.d.ts +20 -0
  88. package/dist/workspace/landing/direct-push.d.ts.map +1 -0
  89. package/dist/workspace/landing/direct-push.js +74 -0
  90. package/dist/workspace/landing/direct-push.js.map +1 -0
  91. package/dist/workspace/landing/index.d.ts +29 -0
  92. package/dist/workspace/landing/index.d.ts.map +1 -0
  93. package/dist/workspace/landing/index.js +37 -0
  94. package/dist/workspace/landing/index.js.map +1 -0
  95. package/dist/workspace/landing/merge-to-parent.d.ts +41 -0
  96. package/dist/workspace/landing/merge-to-parent.d.ts.map +1 -0
  97. package/dist/workspace/landing/merge-to-parent.js +185 -0
  98. package/dist/workspace/landing/merge-to-parent.js.map +1 -0
  99. package/dist/workspace/landing/optimistic-push.d.ts +16 -0
  100. package/dist/workspace/landing/optimistic-push.d.ts.map +1 -0
  101. package/dist/workspace/landing/optimistic-push.js +27 -0
  102. package/dist/workspace/landing/optimistic-push.js.map +1 -0
  103. package/dist/workspace/landing/queue-to-branch.d.ts +24 -0
  104. package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -0
  105. package/dist/workspace/landing/queue-to-branch.js +79 -0
  106. package/dist/workspace/landing/queue-to-branch.js.map +1 -0
  107. package/dist/workspace/merge-queue/merge-queue.d.ts +10 -0
  108. package/dist/workspace/merge-queue/merge-queue.d.ts.map +1 -1
  109. package/dist/workspace/merge-queue/merge-queue.js +10 -0
  110. package/dist/workspace/merge-queue/merge-queue.js.map +1 -1
  111. package/dist/workspace/merge-queue/types.d.ts +16 -2
  112. package/dist/workspace/merge-queue/types.d.ts.map +1 -1
  113. package/dist/workspace/merge-queue/types.js +9 -0
  114. package/dist/workspace/merge-queue/types.js.map +1 -1
  115. package/dist/workspace/pool/types.d.ts +1 -0
  116. package/dist/workspace/pool/types.d.ts.map +1 -1
  117. package/dist/workspace/pool/worktree-pool.d.ts.map +1 -1
  118. package/dist/workspace/pool/worktree-pool.js +1 -0
  119. package/dist/workspace/pool/worktree-pool.js.map +1 -1
  120. package/dist/workspace/recovery/abandon.d.ts +15 -0
  121. package/dist/workspace/recovery/abandon.d.ts.map +1 -0
  122. package/dist/workspace/recovery/abandon.js +45 -0
  123. package/dist/workspace/recovery/abandon.js.map +1 -0
  124. package/dist/workspace/recovery/auto-resolve.d.ts +27 -0
  125. package/dist/workspace/recovery/auto-resolve.d.ts.map +1 -0
  126. package/dist/workspace/recovery/auto-resolve.js +99 -0
  127. package/dist/workspace/recovery/auto-resolve.js.map +1 -0
  128. package/dist/workspace/recovery/defer.d.ts +15 -0
  129. package/dist/workspace/recovery/defer.d.ts.map +1 -0
  130. package/dist/workspace/recovery/defer.js +16 -0
  131. package/dist/workspace/recovery/defer.js.map +1 -0
  132. package/dist/workspace/recovery/escalate.d.ts +16 -0
  133. package/dist/workspace/recovery/escalate.d.ts.map +1 -0
  134. package/dist/workspace/recovery/escalate.js +24 -0
  135. package/dist/workspace/recovery/escalate.js.map +1 -0
  136. package/dist/workspace/recovery/index.d.ts +32 -0
  137. package/dist/workspace/recovery/index.d.ts.map +1 -0
  138. package/dist/workspace/recovery/index.js +45 -0
  139. package/dist/workspace/recovery/index.js.map +1 -0
  140. package/dist/workspace/recovery/spawn-resolver.d.ts +45 -0
  141. package/dist/workspace/recovery/spawn-resolver.d.ts.map +1 -0
  142. package/dist/workspace/recovery/spawn-resolver.js +111 -0
  143. package/dist/workspace/recovery/spawn-resolver.js.map +1 -0
  144. package/dist/workspace/recovery/types.d.ts +63 -0
  145. package/dist/workspace/recovery/types.d.ts.map +1 -0
  146. package/dist/workspace/recovery/types.js +12 -0
  147. package/dist/workspace/recovery/types.js.map +1 -0
  148. package/dist/workspace/topology/index.d.ts +9 -0
  149. package/dist/workspace/topology/index.d.ts.map +1 -0
  150. package/dist/workspace/topology/index.js +8 -0
  151. package/dist/workspace/topology/index.js.map +1 -0
  152. package/dist/workspace/topology/no-workspace.d.ts +18 -0
  153. package/dist/workspace/topology/no-workspace.d.ts.map +1 -0
  154. package/dist/workspace/topology/no-workspace.js +25 -0
  155. package/dist/workspace/topology/no-workspace.js.map +1 -0
  156. package/dist/workspace/topology/types.d.ts +97 -0
  157. package/dist/workspace/topology/types.d.ts.map +1 -0
  158. package/dist/workspace/topology/types.js +20 -0
  159. package/dist/workspace/topology/types.js.map +1 -0
  160. package/dist/workspace/topology/yaml-driven.d.ts +69 -0
  161. package/dist/workspace/topology/yaml-driven.d.ts.map +1 -0
  162. package/dist/workspace/topology/yaml-driven.js +273 -0
  163. package/dist/workspace/topology/yaml-driven.js.map +1 -0
  164. package/dist/workspace/types-v3.d.ts +110 -0
  165. package/dist/workspace/types-v3.d.ts.map +1 -0
  166. package/dist/workspace/types-v3.js +20 -0
  167. package/dist/workspace/types-v3.js.map +1 -0
  168. package/dist/workspace/types.d.ts +145 -17
  169. package/dist/workspace/types.d.ts.map +1 -1
  170. package/dist/workspace/workspace-manager.d.ts +92 -13
  171. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  172. package/dist/workspace/workspace-manager.js +373 -13
  173. package/dist/workspace/workspace-manager.js.map +1 -1
  174. package/dist/workspace/yaml-schema.d.ts +254 -0
  175. package/dist/workspace/yaml-schema.d.ts.map +1 -0
  176. package/dist/workspace/yaml-schema.js +170 -0
  177. package/dist/workspace/yaml-schema.js.map +1 -0
  178. package/docs/conflict-recovery.md +472 -0
  179. package/docs/git-cascade-integration-gaps.md +678 -0
  180. package/docs/workspace-interfaces.md +731 -0
  181. package/docs/workspace-redesign-plan.md +302 -0
  182. package/package.json +4 -4
  183. package/src/__tests__/e2e/auto-sync.e2e.test.ts +257 -0
  184. package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +254 -0
  185. package/src/__tests__/e2e/cli-run.e2e.test.ts +167 -0
  186. package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +197 -0
  187. package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +200 -0
  188. package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +30 -22
  189. package/src/__tests__/e2e/workspace-v3.e2e.test.ts +413 -0
  190. package/src/acp/__tests__/claude-code-replay.test.ts +225 -0
  191. package/src/acp/__tests__/macro-agent.test.ts +39 -1
  192. package/src/acp/claude-code-replay.ts +208 -0
  193. package/src/acp/macro-agent.ts +167 -9
  194. package/src/acp/types.ts +10 -0
  195. package/src/agent/__tests__/agent-manager-topology.test.ts +73 -0
  196. package/src/agent/__tests__/agent-manager-v2.test.ts +66 -0
  197. package/src/agent/__tests__/task-ref-resolution.test.ts +231 -0
  198. package/src/agent/agent-manager-v2.ts +293 -48
  199. package/src/agent/agent-manager.ts +14 -0
  200. package/src/agent/types.ts +16 -2
  201. package/src/boot-v2.ts +68 -1
  202. package/src/cli/index.ts +61 -0
  203. package/src/cognitive/macro-agent-backend.ts +45 -29
  204. package/src/integrations/skilltree.ts +1 -0
  205. package/src/lifecycle/cleanup.ts +52 -3
  206. package/src/lifecycle/handlers-v2.ts +40 -3
  207. package/src/lifecycle/types.ts +12 -0
  208. package/src/map/__tests__/cascade-bridge.test.ts +229 -0
  209. package/src/map/__tests__/lifecycle-bridge.test.ts +86 -10
  210. package/src/map/acp-bridge.ts +26 -3
  211. package/src/map/cascade-bridge.ts +301 -0
  212. package/src/map/lifecycle-bridge.ts +52 -17
  213. package/src/map/server.ts +47 -6
  214. package/src/map/sidecar.ts +31 -1
  215. package/src/map/types.ts +20 -0
  216. package/src/mcp/tools/done-v2.ts +9 -0
  217. package/src/teams/team-manager-v2.ts +37 -0
  218. package/src/teams/team-runtime-v2.ts +23 -3
  219. package/src/workspace/__tests__/{dataplane-adapter.test.ts → git-cascade-adapter.test.ts} +209 -14
  220. package/src/workspace/__tests__/self-driving-yaml.test.ts +114 -0
  221. package/src/workspace/__tests__/shared-worktree-refcount.test.ts +154 -0
  222. package/src/workspace/__tests__/standalone-mode.test.ts +118 -0
  223. package/src/workspace/__tests__/workspace-manager-v3.test.ts +245 -0
  224. package/src/workspace/__tests__/yaml-schema.test.ts +210 -0
  225. package/src/workspace/config.ts +11 -11
  226. package/src/workspace/git-cascade-adapter.ts +1186 -0
  227. package/src/workspace/index.ts +11 -11
  228. package/src/workspace/landing/__tests__/strategies.test.ts +142 -0
  229. package/src/workspace/landing/direct-push.ts +91 -0
  230. package/src/workspace/landing/index.ts +40 -0
  231. package/src/workspace/landing/merge-to-parent.ts +228 -0
  232. package/src/workspace/landing/optimistic-push.ts +36 -0
  233. package/src/workspace/landing/queue-to-branch.ts +108 -0
  234. package/src/workspace/merge-queue/merge-queue.ts +10 -0
  235. package/src/workspace/merge-queue/types.ts +16 -2
  236. package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +5 -5
  237. package/src/workspace/pool/types.ts +1 -0
  238. package/src/workspace/pool/worktree-pool.ts +1 -0
  239. package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +127 -0
  240. package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +139 -0
  241. package/src/workspace/recovery/__tests__/strategies.test.ts +145 -0
  242. package/src/workspace/recovery/abandon.ts +51 -0
  243. package/src/workspace/recovery/auto-resolve.ts +119 -0
  244. package/src/workspace/recovery/defer.ts +23 -0
  245. package/src/workspace/recovery/escalate.ts +30 -0
  246. package/src/workspace/recovery/index.ts +58 -0
  247. package/src/workspace/recovery/spawn-resolver.ts +145 -0
  248. package/src/workspace/recovery/types.ts +54 -0
  249. package/src/workspace/topology/__tests__/yaml-driven.test.ts +345 -0
  250. package/src/workspace/topology/index.ts +18 -0
  251. package/src/workspace/topology/no-workspace.ts +39 -0
  252. package/src/workspace/topology/types.ts +116 -0
  253. package/src/workspace/topology/yaml-driven.ts +316 -0
  254. package/src/workspace/types-v3.ts +155 -0
  255. package/src/workspace/types.ts +191 -20
  256. package/src/workspace/workspace-manager.ts +474 -19
  257. package/src/workspace/yaml-schema.ts +216 -0
  258. package/src/workspace/dataplane-adapter.ts +0 -546
package/CLAUDE.md CHANGED
@@ -7,9 +7,10 @@ A multi-agent orchestration system for spawning and managing hierarchical AI cod
7
7
  macro-agent enables coordinated work across multiple AI agents with:
8
8
  - **Role-based agents** (Worker, Integrator, Coordinator, Monitor, Analyst + custom team roles)
9
9
  - **Team templates** for declarative multi-agent topologies (YAML config)
10
- - **Pluggable integration strategies** (queue, trunk, optimistic)
11
- - **Workspace isolation** via git worktrees (powered by git-cascade)
12
- - **Merge queue** for serialized integration
10
+ - **Stream-first workspace layer (V3)** YAML-driven `TopologyPolicy` compiles role config into per-spawn workspace decisions; falls back to capability-based dispatch for programmatic callers
11
+ - **Pluggable `LandingStrategy`** `merge-to-parent`, `queue-to-branch`, `direct-push`, `optimistic-push` built-ins; registered on WorkspaceManager, selected per-role via YAML
12
+ - **Pluggable `ConflictRecoveryStrategy`** `defer`, `abandon`, `escalate`, `auto-resolve` (real git `-X` merge), `spawn-resolver` (LLM resolver agent)
13
+ - **Workspace isolation** via git worktrees + Change-Id tracking (powered by git-cascade 0.0.3+)
13
14
  - **Messaging** via agent-inbox (structured inbox/outbox, threading, federation)
14
15
  - **Task management** via opentasks (graph-based dependencies, providers, claiming)
15
16
  - **Control socket** for MCP subprocess lifecycle RPC (NDJSON over UNIX socket)
@@ -271,26 +272,46 @@ src/
271
272
  │ │ └── index.ts
272
273
  │ └── index.ts # Public exports
273
274
 
274
- └── workspace/ # Workspace isolation
275
- ├── workspace-manager.ts # WorkspaceManager implementation
276
- ├── dataplane-adapter.ts # Bridges to git-cascade dataplane
277
- ├── config.ts # Workspace configuration
278
- ├── types.ts # Workspace, WorkspaceManager interface
275
+ └── workspace/ # Workspace isolation — V3 stream-first + legacy role-shaped
276
+ ├── workspace-manager.ts # WorkspaceManager implementation (legacy + V3 surfaces)
277
+ ├── git-cascade-adapter.ts # Wraps git-cascade tracker (40+ primitives surfaced)
278
+ ├── config.ts # GitCascadeConfig + pool config
279
+ ├── types.ts # WorkspaceManager interface (legacy + V3), events
280
+ ├── types-v3.ts # V3 types: Principal, StreamSpec, LandingStrategy, etc.
281
+ ├── yaml-schema.ts # Zod schema for `macro_agent.workspace`
282
+ ├── topology/ # TopologyPolicy — compiles YAML → spawn decisions
283
+ │ ├── types.ts # TopologyPolicy, WorkspaceDecision, contexts
284
+ │ ├── yaml-driven.ts # YamlDrivenTopology (primary)
285
+ │ ├── no-workspace.ts # NoWorkspaceTopology (null policy)
286
+ │ └── index.ts
287
+ ├── landing/ # LandingStrategy — pluggable merge/push algorithms
288
+ │ ├── merge-to-parent.ts # mergeStream into parent + optional cascadeRebase
289
+ │ ├── queue-to-branch.ts # git-cascade built-in merge queue
290
+ │ ├── direct-push.ts # rebase + push
291
+ │ ├── optimistic-push.ts # direct-push + validation event
292
+ │ └── index.ts # registerBuiltinLandingStrategies()
293
+ ├── recovery/ # ConflictRecoveryStrategy
294
+ │ ├── types.ts # ConflictContext, ConflictResolution
295
+ │ ├── defer.ts # Leave conflict record; no-op
296
+ │ ├── abandon.ts # Abandon the conflicted stream
297
+ │ ├── escalate.ts # Pause + notify human
298
+ │ ├── auto-resolve.ts # Replay merge with -X ours|theirs|union
299
+ │ ├── spawn-resolver.ts # Spawn a resolver agent (requires AgentManager)
300
+ │ └── index.ts # buildBuiltinRecoveryRegistry()
279
301
  ├── pool/ # Worktree pool management
280
302
  │ ├── worktree-pool.ts
281
303
  │ ├── types.ts
282
304
  │ └── index.ts
283
- ├── merge-queue/ # SQLite-backed merge queue
284
- │ ├── merge-queue.ts
285
- │ ├── schema.ts
286
- │ ├── types.ts
305
+ ├── merge-queue/ # @deprecated — legacy SQLite-backed queue,
306
+ │ ├── merge-queue.ts # duplicates git-cascade's built-in. Use
307
+ │ ├── schema.ts # GitCascadeAdapter.addToMergeQueue for
308
+ │ ├── types.ts # new code (via QueueToBranchStrategy).
287
309
  │ └── index.ts
288
- ├── strategies/ # Integration strategies
289
- │ ├── types.ts # IntegrationStrategy interface
290
- │ ├── registry.ts # Strategy factory registry
291
- │ ├── queue.ts # Queue strategy (wraps merge queue)
292
- │ ├── trunk.ts # Trunk strategy (direct push + rebase)
293
- │ ├── optimistic.ts # Optimistic strategy (push + validation event)
310
+ ├── strategies/ # @deprecated — old IntegrationStrategy.
311
+ │ ├── types.ts # Superseded by workspace/landing/.
312
+ │ ├── queue.ts # Scheduled for removal once all teams
313
+ │ ├── trunk.ts # migrate to macro_agent.workspace YAML.
314
+ │ ├── optimistic.ts
294
315
  │ └── index.ts
295
316
  └── index.ts # Public exports
296
317
  ```
@@ -371,16 +392,98 @@ Agents are assigned roles that determine their capabilities:
371
392
 
372
393
  Teams can define custom roles (e.g., planner, grinder, judge) that extend built-in roles via `extends` in `roles/<name>.yaml`. Tool filtering is role-based — `isToolAllowedForRole()` checks the role's capabilities before registering each MCP tool.
373
394
 
374
- ### Integration Strategies
395
+ ### Workspace Layer (V3 Stream-First)
396
+
397
+ The workspace layer went through a v3 redesign. Two paths coexist:
398
+
399
+ **V3 path (YAML-driven, recommended for teams):**
400
+ - `macro_agent.workspace` block in `team.yaml` declares per-role workspace decisions
401
+ - `TopologyPolicy` (`workspace/topology/`) compiles YAML → `WorkspaceDecision` per spawn
402
+ - `LandingStrategy` (`workspace/landing/`) finalizes work at `done()` time
403
+ - `ConflictRecoveryStrategy` (`workspace/recovery/`) dispatches on conflicts
404
+ - Auto-wired by `TeamManagerV2.startTeam()` when workspace config is present
405
+
406
+ **Legacy path (programmatic / capability-based):**
407
+ - Direct `agentManager.spawn({ capabilities: ['workspace.worktree'|'workspace.stream'|'workspace.integrate'], streamId, streamConfig })`
408
+ - `capabilityBasedDispatch` in `AgentManagerV2` routes to role-shaped `WorkspaceManager` methods (`createWorkerWorkspace`, etc.)
409
+ - Retained for programmatic callers (tools, libraries, tests that don't load team YAML)
410
+
411
+ **Dispatch priority in `AgentManagerV2.createWorkspaceForRole()`:**
412
+ 1. If `topologyPolicy` is set → V3 path via `executeWorkspaceDecision`
413
+ 2. Else → `capabilityBasedDispatch` using role-shaped methods
414
+
415
+ ### TopologyPolicy (V3)
416
+
417
+ `TopologyPolicy` (`workspace/topology/types.ts`) is the contract for compiling
418
+ team YAML into per-spawn workspace decisions. Three built-ins:
419
+
420
+ | Policy | Module | Purpose |
421
+ |---|---|---|
422
+ | **YamlDrivenTopology** | `topology/yaml-driven.ts` | Primary; reads `macro_agent.workspace` |
423
+ | **NoWorkspaceTopology** | `topology/no-workspace.ts` | Null policy; returns `share-parent-cwd` for all |
424
+
425
+ Hook methods:
426
+ - `onTeamStart(ctx)` → creates team-root stream if any role needs it
427
+ - `onAgentSpawn(ctx)` → returns `WorkspaceDecision` (`none` / `share-parent-cwd` / `share-with-agent` / `attach-to-stream` / `new-stream`)
428
+ - `onAgentComplete(ctx)` → deallocates the agent's worktree
429
+ - `onTeamStop(ctx)` → applies `on_team_complete` action (`keep` / `merge_to_main` / `abandon`)
430
+
431
+ The YAML schema (`workspace/yaml-schema.ts`) supports:
432
+ - `workspace`: `none` / `attach_to_team_root` / `share_with_agent` / `share_parent_cwd` / `new_stream`
433
+ - `stream_lineage`: `from_team_root` / `fork_from_team_root` / `fork_from_parent` / `independent` / `track_existing_branch`
434
+ - `allocation`, `landing`, `landing_config`, `on_conflict`, `on_conflict_recovery`, `conflict_recovery_config`, `cascade_on_parent_update`, `on_parent_advanced`, `share_with`, `track_branch`, `capabilities`
435
+
436
+ ### LandingStrategies (V3)
437
+
438
+ `LandingStrategy` (`workspace/types-v3.ts`) is how a streamed agent finalizes
439
+ its work. Registered on `WorkspaceManager` via `registerLandingStrategy(s)`
440
+ and selected per-role via YAML `landing:`. Four built-ins registered by
441
+ `registerBuiltinLandingStrategies()`:
442
+
443
+ | Strategy | Module | Semantics |
444
+ |---|---|---|
445
+ | **merge-to-parent** | `landing/merge-to-parent.ts` | `mergeStream(source → parent)`, optional `cascadeRebase` via `strategyConfig.cascade: true` |
446
+ | **queue-to-branch** | `landing/queue-to-branch.ts` | `GitCascadeAdapter.addToMergeQueue(streamId, targetBranch)` — drained by integrator-capable agents |
447
+ | **direct-push** | `landing/direct-push.ts` | Rebase + `git push` with retries (trunk flow) |
448
+ | **optimistic-push** | `landing/optimistic-push.ts` | `direct-push` + emits validation event |
375
449
 
376
- Pluggable strategies for landing worker changes:
377
- - **Queue** (`queue.ts`): Wraps merge queue with serialized integration
378
- - **Trunk** (`trunk.ts`): Direct push with rebase-retry loop
379
- - **Optimistic** (`optimistic.ts`): Same as trunk + emits validation event
450
+ `LandingContext` carries: `agentId`, `streamId`, `sourceWorktree`,
451
+ `targetStreamId`, `strategyConfig` (from YAML `landing_config`), and a back-
452
+ reference to `WorkspaceManager`.
380
453
 
381
- ### Workspace Isolation
454
+ ### Conflict Recovery (V3)
382
455
 
383
- Each worker gets an isolated git worktree via the WorkspaceManager (backed by git-cascade). Changes are merged at the terminate level — `AgentManagerV2.terminate()` calls `terminateWithChangeConsolidation()` which handles merge requests. Agents never construct merge requests directly.
456
+ When a landing returns a conflict, the agent's `done()` flow dispatches to a
457
+ `ConflictRecoveryStrategy` (`workspace/recovery/types.ts`) selected via YAML
458
+ `on_conflict_recovery:` or team default. Five built-ins:
459
+
460
+ | Strategy | Mode | Behavior |
461
+ |---|---|---|
462
+ | **defer** | sync | No-op — leaves conflict record for later manual recovery |
463
+ | **abandon** | sync | `abandonStream(streamId)` — throwaway work |
464
+ | **escalate** | async | `pauseStream` + emit escalation — awaits external `resolve_conflict` MCP call |
465
+ | **auto-resolve** | sync | Replays merge with `-X ours|theirs|union` in the agent's worktree, commits, notifies `workspaceManager.resolveConflict` |
466
+ | **spawn-resolver** | async | Spawns a resolver agent on the conflicted stream; awaits `conflict:resolved` event or timeout |
467
+
468
+ `spawn-resolver` requires `AgentManager` injection (not in default registry;
469
+ register via `createSpawnResolverStrategy({ agentManager })`). Max concurrent
470
+ resolvers per stream is configurable; timeout falls back to `escalated`.
471
+
472
+ `ConflictContext` carries: `conflictId`, `streamId`, `paths`, `operation`
473
+ (`merge` | `sync` | `rebase` | `cascade`), `worktree?` (required for
474
+ `auto-resolve`), `landingAgentId?`, `recoveryDepth`, `strategyConfig`.
475
+
476
+ ### Workspace Isolation (shared across paths)
477
+
478
+ Each streamed agent gets an isolated git worktree via `WorkspaceManager`,
479
+ backed by git-cascade's `MultiAgentRepoTracker`. V3 agents use
480
+ `allocateWorktree({ agentId, streamId })`; legacy agents use role-specific
481
+ `createWorkerWorkspace` / `createIntegratorWorkspace` / `createCoordinatorWorkspace`.
482
+ Both produce the same underlying git worktree structure.
483
+
484
+ Change-Id tracking via `commitChanges({ agentId, streamId, worktree, message })`
485
+ (v3) — each commit gets a stable `Change-Id: c-xxxxxxxx` trailer that survives
486
+ rebases. Legacy callers that use raw `git commit` bypass this tracking.
384
487
 
385
488
  ### MCP Tool Surface
386
489
 
@@ -515,15 +618,16 @@ Teams configure communication via:
515
618
 
516
619
  All filtering is adapter-side — agent-inbox is a dumb pipe, macro-agent enforces policy via composite filters on the InboxAdapter.
517
620
 
518
- ### Done Handler Flow (V2)
621
+ ### Done Handler Flow
519
622
 
520
623
  1. Agent calls `done()` MCP tool with status + summary
521
624
  2. MCPServerV2 dispatches to `createDoneHandlerV2()` which builds a handler using `HandlerDepsV2` (InboxAdapter, TasksAdapter, AgentManager)
522
625
  3. Role-specific handler runs:
523
- - **Worker**: Commits changes, emits `work:done` signal to parent via InboxAdapter
626
+ - **Worker / V3 streamed agent**: Commits changes via `commitChanges` (Change-Id tracked), invokes `LandingStrategy.land()` per YAML config, emits `work:done` signal
524
627
  - **Coordinator**: Emits completion signal, cascade-terminates children if needed
525
628
  - **Monitor**: Emits health report
526
- 4. If `shouldTerminate`, AgentManagerV2 handles termination including workspace cleanup and change consolidation
629
+ 4. If landing returns a conflict, the recovery dispatcher selects a `ConflictRecoveryStrategy` per role's `on_conflict_recovery` YAML (or team default); strategy runs sync or async
630
+ 5. If `shouldTerminate`, AgentManagerV2 handles termination: `TopologyPolicy.onAgentComplete` deallocates the worktree; cascade termination consolidates changes for child agents
527
631
 
528
632
  ## Conventions
529
633
 
@@ -542,8 +646,8 @@ All filtering is adapter-side — agent-inbox is a dumb pipe, macro-agent enforc
542
646
 
543
647
  ### Testing
544
648
 
545
- - **Unit tests**: `*.test.ts` — Fast, mocked dependencies (~40 test files)
546
- - **E2E tests**: `*.e2e.test.ts` — Full system tests (11 test files)
649
+ - **Unit tests**: `*.test.ts` — Fast tests, mixed real-git and mocked dependencies (~58 test files, ~990 tests)
650
+ - **E2E tests**: `*.e2e.test.ts` — Full system tests gated by `RUN_E2E_TESTS=true`
547
651
 
548
652
  Run tests:
549
653
  ```bash
@@ -553,11 +657,12 @@ npm run test:e2e # E2E tests (mocked agent sessions)
553
657
  npm run test:e2e-full-agents # E2E tests with real agent spawning (RUN_FULL_AGENT_TESTS=true)
554
658
  ```
555
659
 
556
- E2E test files:
660
+ E2E test files (selected):
557
661
  - `agent-lifecycle.e2e.test.ts` — Spawn, prompt, terminate flows
662
+ - `workspace-lifecycle.e2e.test.ts` — Legacy capability-based workspace path (programmatic API)
663
+ - `workspace-v3.e2e.test.ts` — V3 YAML-driven path: peer swarm, merge-to-parent landing, conflict recovery, legacy regression guard
558
664
  - `cognitive-workspace.e2e.test.ts` — Cognitive-core backend workspace operations
559
665
  - `done-scenarios.e2e.test.ts` — Done handler scenarios per role
560
- - `workspace-lifecycle.e2e.test.ts` — Worktree allocation and cleanup
561
666
  - `trigger-wake.e2e.test.ts` — Trigger delivery and wake flows
562
667
  - `resume-continue.e2e.test.ts` — Session continuation
563
668
  - `pull-mode.e2e.test.ts` — Task claiming workflows
@@ -602,6 +707,27 @@ E2E test files:
602
707
  3. Register with `triggerSystem.router.registerStrategy(strategy)`
603
708
  4. Optionally set as default: `triggerSystem.router.setDefaultStrategy(name)`
604
709
 
710
+ ### Adding a Landing Strategy (V3)
711
+
712
+ 1. Implement the `LandingStrategy` interface from `src/workspace/types-v3.ts`
713
+ 2. Define `name`, `land(ctx)`, optionally `canLand(ctx)`, `initialize()`, `close()`
714
+ 3. Register via `workspaceManager.registerLandingStrategy(new YourStrategy())` (typically at boot after built-ins)
715
+ 4. Reference from team YAML: `roles.<role>.landing: your_strategy_name`; pass config via `landing_config`
716
+
717
+ ### Adding a Conflict Recovery Strategy (V3)
718
+
719
+ 1. Implement the `ConflictRecoveryStrategy` interface from `src/workspace/recovery/types.ts`
720
+ 2. Define `name`, `mode` (`sync` | `async`), `recover(ctx)`, optionally `canHandle(ctx)`
721
+ 3. If the strategy needs `AgentManager` (like `spawn-resolver`), expose a factory that accepts it
722
+ 4. Register into the team's recovery registry; selected per-role via `on_conflict_recovery:` or team default
723
+
724
+ ### Adding a Topology Policy (V3)
725
+
726
+ 1. Implement the `TopologyPolicy` interface from `src/workspace/topology/types.ts`
727
+ 2. Define `onTeamStart`, `onAgentSpawn`, `onAgentComplete`, `onTeamStop`
728
+ 3. Return `WorkspaceDecision` values from `onAgentSpawn` (`none` / `share-parent-cwd` / `share-with-agent` / `attach-to-stream` / `new-stream`)
729
+ 4. Inject via `agentManager.setTopologyPolicy(policy)` — or have `TeamManagerV2.startTeam` auto-wire from YAML via `YamlDrivenTopology`
730
+
605
731
  ### Adding a Control Command
606
732
 
607
733
  1. Add the command type to `ControlCommand` union in `src/control/types.ts`
@@ -665,7 +791,7 @@ E2E test files:
665
791
  | `opentasks` | Task graph, dependencies, providers (IPC to daemon) |
666
792
  | `acp-factory` | Agent process management (Claude Code sessions) |
667
793
  | `openteams` | Team template loading and resolution |
668
- | `git-cascade` | Git worktree and merge queue operations |
794
+ | `git-cascade` | Git worktree, stream/fork/merge/rebase, Change-Id tracking, cascade namespace, event emitter (0.0.3+) |
669
795
  | `better-sqlite3` | AgentStore + InboxAdapter persistence |
670
796
  | `@modelcontextprotocol/sdk` | MCP server implementation |
671
797
  | `@multi-agent-protocol/sdk` | MAP protocol types |
@@ -689,5 +815,12 @@ E2E test files:
689
815
 
690
816
  ## References
691
817
 
818
+ ### Team configuration
692
819
  - [docs/teams.md](docs/teams.md) - Team template schema reference
693
820
  - [docs/team-templates.md](docs/team-templates.md) - Team template format and examples
821
+
822
+ ### Workspace redesign (V3)
823
+ - [docs/workspace-redesign-plan.md](docs/workspace-redesign-plan.md) - Implementation plan + status
824
+ - [docs/workspace-interfaces.md](docs/workspace-interfaces.md) - V3 interface contracts (TypeScript)
825
+ - [docs/git-cascade-integration-gaps.md](docs/git-cascade-integration-gaps.md) - Design narrative, workflow traces, migration plan
826
+ - [docs/conflict-recovery.md](docs/conflict-recovery.md) - Conflict recovery strategy design