macro-agent 0.1.8 → 0.1.11

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 (306) hide show
  1. package/CLAUDE.md +263 -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 +192 -7
  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/adapters/tasks-adapter.d.ts.map +1 -1
  14. package/dist/adapters/tasks-adapter.js +3 -0
  15. package/dist/adapters/tasks-adapter.js.map +1 -1
  16. package/dist/adapters/types.d.ts +1 -0
  17. package/dist/adapters/types.d.ts.map +1 -1
  18. package/dist/agent/agent-manager-v2.d.ts +21 -0
  19. package/dist/agent/agent-manager-v2.d.ts.map +1 -1
  20. package/dist/agent/agent-manager-v2.js +308 -54
  21. package/dist/agent/agent-manager-v2.js.map +1 -1
  22. package/dist/agent/agent-manager.d.ts +12 -0
  23. package/dist/agent/agent-manager.d.ts.map +1 -1
  24. package/dist/agent/agent-manager.js.map +1 -1
  25. package/dist/agent/agent-store.d.ts +10 -0
  26. package/dist/agent/agent-store.d.ts.map +1 -1
  27. package/dist/agent/agent-store.js +22 -0
  28. package/dist/agent/agent-store.js.map +1 -1
  29. package/dist/agent/types.d.ts +15 -2
  30. package/dist/agent/types.d.ts.map +1 -1
  31. package/dist/agent/types.js.map +1 -1
  32. package/dist/boot-v2.d.ts +129 -1
  33. package/dist/boot-v2.d.ts.map +1 -1
  34. package/dist/boot-v2.js +359 -8
  35. package/dist/boot-v2.js.map +1 -1
  36. package/dist/cli/acp.js +4 -0
  37. package/dist/cli/acp.js.map +1 -1
  38. package/dist/cli/index.js +56 -0
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cognitive/macro-agent-backend.d.ts.map +1 -1
  41. package/dist/cognitive/macro-agent-backend.js +40 -22
  42. package/dist/cognitive/macro-agent-backend.js.map +1 -1
  43. package/dist/integrations/skilltree.d.ts.map +1 -1
  44. package/dist/integrations/skilltree.js +1 -0
  45. package/dist/integrations/skilltree.js.map +1 -1
  46. package/dist/lifecycle/cascade.d.ts +25 -2
  47. package/dist/lifecycle/cascade.d.ts.map +1 -1
  48. package/dist/lifecycle/cascade.js +70 -2
  49. package/dist/lifecycle/cascade.js.map +1 -1
  50. package/dist/lifecycle/cleanup.d.ts +33 -2
  51. package/dist/lifecycle/cleanup.d.ts.map +1 -1
  52. package/dist/lifecycle/cleanup.js +28 -6
  53. package/dist/lifecycle/cleanup.js.map +1 -1
  54. package/dist/lifecycle/handlers-v2.d.ts +7 -0
  55. package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
  56. package/dist/lifecycle/handlers-v2.js +28 -2
  57. package/dist/lifecycle/handlers-v2.js.map +1 -1
  58. package/dist/lifecycle/types.d.ts +11 -0
  59. package/dist/lifecycle/types.d.ts.map +1 -1
  60. package/dist/lifecycle/types.js.map +1 -1
  61. package/dist/map/acp-bridge.d.ts +9 -0
  62. package/dist/map/acp-bridge.d.ts.map +1 -1
  63. package/dist/map/acp-bridge.js +15 -2
  64. package/dist/map/acp-bridge.js.map +1 -1
  65. package/dist/map/cascade-action-handler.d.ts +24 -0
  66. package/dist/map/cascade-action-handler.d.ts.map +1 -0
  67. package/dist/map/cascade-action-handler.js +170 -0
  68. package/dist/map/cascade-action-handler.js.map +1 -0
  69. package/dist/map/cascade-bridge.d.ts +44 -0
  70. package/dist/map/cascade-bridge.d.ts.map +1 -0
  71. package/dist/map/cascade-bridge.js +294 -0
  72. package/dist/map/cascade-bridge.js.map +1 -0
  73. package/dist/map/coordination-handler.d.ts.map +1 -1
  74. package/dist/map/coordination-handler.js +12 -1
  75. package/dist/map/coordination-handler.js.map +1 -1
  76. package/dist/map/lifecycle-bridge.d.ts +1 -1
  77. package/dist/map/lifecycle-bridge.d.ts.map +1 -1
  78. package/dist/map/lifecycle-bridge.js +58 -23
  79. package/dist/map/lifecycle-bridge.js.map +1 -1
  80. package/dist/map/server.d.ts.map +1 -1
  81. package/dist/map/server.js +219 -7
  82. package/dist/map/server.js.map +1 -1
  83. package/dist/map/sidecar.d.ts.map +1 -1
  84. package/dist/map/sidecar.js +49 -2
  85. package/dist/map/sidecar.js.map +1 -1
  86. package/dist/map/types.d.ts +22 -0
  87. package/dist/map/types.d.ts.map +1 -1
  88. package/dist/mcp/tools/done-v2.d.ts.map +1 -1
  89. package/dist/mcp/tools/done-v2.js +8 -0
  90. package/dist/mcp/tools/done-v2.js.map +1 -1
  91. package/dist/teams/team-manager-v2.d.ts.map +1 -1
  92. package/dist/teams/team-manager-v2.js +26 -0
  93. package/dist/teams/team-manager-v2.js.map +1 -1
  94. package/dist/teams/team-runtime-v2.d.ts.map +1 -1
  95. package/dist/teams/team-runtime-v2.js +16 -3
  96. package/dist/teams/team-runtime-v2.js.map +1 -1
  97. package/dist/workspace/config.d.ts +10 -10
  98. package/dist/workspace/config.d.ts.map +1 -1
  99. package/dist/workspace/config.js +4 -4
  100. package/dist/workspace/config.js.map +1 -1
  101. package/dist/workspace/git-cascade-adapter.d.ts +510 -0
  102. package/dist/workspace/git-cascade-adapter.d.ts.map +1 -0
  103. package/dist/workspace/git-cascade-adapter.js +934 -0
  104. package/dist/workspace/git-cascade-adapter.js.map +1 -0
  105. package/dist/workspace/index.d.ts +3 -3
  106. package/dist/workspace/index.d.ts.map +1 -1
  107. package/dist/workspace/index.js +4 -4
  108. package/dist/workspace/index.js.map +1 -1
  109. package/dist/workspace/landing/direct-push.d.ts +20 -0
  110. package/dist/workspace/landing/direct-push.d.ts.map +1 -0
  111. package/dist/workspace/landing/direct-push.js +74 -0
  112. package/dist/workspace/landing/direct-push.js.map +1 -0
  113. package/dist/workspace/landing/index.d.ts +29 -0
  114. package/dist/workspace/landing/index.d.ts.map +1 -0
  115. package/dist/workspace/landing/index.js +37 -0
  116. package/dist/workspace/landing/index.js.map +1 -0
  117. package/dist/workspace/landing/merge-to-parent.d.ts +41 -0
  118. package/dist/workspace/landing/merge-to-parent.d.ts.map +1 -0
  119. package/dist/workspace/landing/merge-to-parent.js +186 -0
  120. package/dist/workspace/landing/merge-to-parent.js.map +1 -0
  121. package/dist/workspace/landing/optimistic-push.d.ts +16 -0
  122. package/dist/workspace/landing/optimistic-push.d.ts.map +1 -0
  123. package/dist/workspace/landing/optimistic-push.js +27 -0
  124. package/dist/workspace/landing/optimistic-push.js.map +1 -0
  125. package/dist/workspace/landing/queue-to-branch.d.ts +24 -0
  126. package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -0
  127. package/dist/workspace/landing/queue-to-branch.js +79 -0
  128. package/dist/workspace/landing/queue-to-branch.js.map +1 -0
  129. package/dist/workspace/merge-queue/merge-queue.d.ts +10 -0
  130. package/dist/workspace/merge-queue/merge-queue.d.ts.map +1 -1
  131. package/dist/workspace/merge-queue/merge-queue.js +10 -0
  132. package/dist/workspace/merge-queue/merge-queue.js.map +1 -1
  133. package/dist/workspace/merge-queue/types.d.ts +16 -2
  134. package/dist/workspace/merge-queue/types.d.ts.map +1 -1
  135. package/dist/workspace/merge-queue/types.js +9 -0
  136. package/dist/workspace/merge-queue/types.js.map +1 -1
  137. package/dist/workspace/pool/types.d.ts +1 -0
  138. package/dist/workspace/pool/types.d.ts.map +1 -1
  139. package/dist/workspace/pool/worktree-pool.d.ts.map +1 -1
  140. package/dist/workspace/pool/worktree-pool.js +1 -0
  141. package/dist/workspace/pool/worktree-pool.js.map +1 -1
  142. package/dist/workspace/recovery/abandon.d.ts +15 -0
  143. package/dist/workspace/recovery/abandon.d.ts.map +1 -0
  144. package/dist/workspace/recovery/abandon.js +45 -0
  145. package/dist/workspace/recovery/abandon.js.map +1 -0
  146. package/dist/workspace/recovery/auto-resolve.d.ts +27 -0
  147. package/dist/workspace/recovery/auto-resolve.d.ts.map +1 -0
  148. package/dist/workspace/recovery/auto-resolve.js +99 -0
  149. package/dist/workspace/recovery/auto-resolve.js.map +1 -0
  150. package/dist/workspace/recovery/defer.d.ts +15 -0
  151. package/dist/workspace/recovery/defer.d.ts.map +1 -0
  152. package/dist/workspace/recovery/defer.js +16 -0
  153. package/dist/workspace/recovery/defer.js.map +1 -0
  154. package/dist/workspace/recovery/escalate.d.ts +16 -0
  155. package/dist/workspace/recovery/escalate.d.ts.map +1 -0
  156. package/dist/workspace/recovery/escalate.js +24 -0
  157. package/dist/workspace/recovery/escalate.js.map +1 -0
  158. package/dist/workspace/recovery/index.d.ts +32 -0
  159. package/dist/workspace/recovery/index.d.ts.map +1 -0
  160. package/dist/workspace/recovery/index.js +45 -0
  161. package/dist/workspace/recovery/index.js.map +1 -0
  162. package/dist/workspace/recovery/spawn-resolver.d.ts +45 -0
  163. package/dist/workspace/recovery/spawn-resolver.d.ts.map +1 -0
  164. package/dist/workspace/recovery/spawn-resolver.js +118 -0
  165. package/dist/workspace/recovery/spawn-resolver.js.map +1 -0
  166. package/dist/workspace/recovery/types.d.ts +63 -0
  167. package/dist/workspace/recovery/types.d.ts.map +1 -0
  168. package/dist/workspace/recovery/types.js +12 -0
  169. package/dist/workspace/recovery/types.js.map +1 -0
  170. package/dist/workspace/topology/index.d.ts +9 -0
  171. package/dist/workspace/topology/index.d.ts.map +1 -0
  172. package/dist/workspace/topology/index.js +8 -0
  173. package/dist/workspace/topology/index.js.map +1 -0
  174. package/dist/workspace/topology/no-workspace.d.ts +18 -0
  175. package/dist/workspace/topology/no-workspace.d.ts.map +1 -0
  176. package/dist/workspace/topology/no-workspace.js +25 -0
  177. package/dist/workspace/topology/no-workspace.js.map +1 -0
  178. package/dist/workspace/topology/types.d.ts +97 -0
  179. package/dist/workspace/topology/types.d.ts.map +1 -0
  180. package/dist/workspace/topology/types.js +20 -0
  181. package/dist/workspace/topology/types.js.map +1 -0
  182. package/dist/workspace/topology/yaml-driven.d.ts +69 -0
  183. package/dist/workspace/topology/yaml-driven.d.ts.map +1 -0
  184. package/dist/workspace/topology/yaml-driven.js +273 -0
  185. package/dist/workspace/topology/yaml-driven.js.map +1 -0
  186. package/dist/workspace/types-v3.d.ts +117 -0
  187. package/dist/workspace/types-v3.d.ts.map +1 -0
  188. package/dist/workspace/types-v3.js +20 -0
  189. package/dist/workspace/types-v3.js.map +1 -0
  190. package/dist/workspace/types.d.ts +162 -17
  191. package/dist/workspace/types.d.ts.map +1 -1
  192. package/dist/workspace/workspace-manager.d.ts +101 -13
  193. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  194. package/dist/workspace/workspace-manager.js +416 -13
  195. package/dist/workspace/workspace-manager.js.map +1 -1
  196. package/dist/workspace/yaml-schema.d.ts +254 -0
  197. package/dist/workspace/yaml-schema.d.ts.map +1 -0
  198. package/dist/workspace/yaml-schema.js +170 -0
  199. package/dist/workspace/yaml-schema.js.map +1 -0
  200. package/docs/conflict-recovery.md +472 -0
  201. package/docs/design/task-dispatcher.md +880 -0
  202. package/docs/git-cascade-integration-gaps.md +678 -0
  203. package/docs/workspace-interfaces.md +731 -0
  204. package/docs/workspace-redesign-plan.md +302 -0
  205. package/package.json +6 -5
  206. package/src/__tests__/boot-v2.test.ts +435 -0
  207. package/src/__tests__/e2e/acp-over-map.e2e.test.ts +92 -0
  208. package/src/__tests__/e2e/auto-sync.e2e.test.ts +257 -0
  209. package/src/__tests__/e2e/bootstrap.e2e.test.ts +319 -0
  210. package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +254 -0
  211. package/src/__tests__/e2e/cli-run.e2e.test.ts +167 -0
  212. package/src/__tests__/e2e/dispatch-coordination.e2e.test.ts +495 -0
  213. package/src/__tests__/e2e/dispatch-live.e2e.test.ts +564 -0
  214. package/src/__tests__/e2e/dispatch-opentasks.e2e.test.ts +496 -0
  215. package/src/__tests__/e2e/dispatch-phase2-live.e2e.test.ts +456 -0
  216. package/src/__tests__/e2e/dispatch-phase2.e2e.test.ts +386 -0
  217. package/src/__tests__/e2e/dispatch.e2e.test.ts +376 -0
  218. package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +197 -0
  219. package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +200 -0
  220. package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +30 -22
  221. package/src/__tests__/e2e/workspace-v3.e2e.test.ts +413 -0
  222. package/src/acp/__tests__/claude-code-replay.test.ts +225 -0
  223. package/src/acp/__tests__/macro-agent.test.ts +39 -1
  224. package/src/acp/claude-code-replay.ts +208 -0
  225. package/src/acp/macro-agent.ts +203 -10
  226. package/src/acp/types.ts +10 -0
  227. package/src/adapters/__tests__/tasks-adapter.test.ts +1 -0
  228. package/src/adapters/tasks-adapter.ts +3 -0
  229. package/src/adapters/types.ts +1 -0
  230. package/src/agent/__tests__/agent-manager-topology.test.ts +73 -0
  231. package/src/agent/__tests__/agent-manager-v2.test.ts +66 -0
  232. package/src/agent/__tests__/agent-store.test.ts +52 -0
  233. package/src/agent/__tests__/task-ref-resolution.test.ts +231 -0
  234. package/src/agent/agent-manager-v2.ts +372 -59
  235. package/src/agent/agent-manager.ts +14 -0
  236. package/src/agent/agent-store.ts +24 -0
  237. package/src/agent/types.ts +16 -2
  238. package/src/boot-v2.ts +589 -35
  239. package/src/cli/acp.ts +4 -0
  240. package/src/cli/index.ts +61 -0
  241. package/src/cognitive/macro-agent-backend.ts +45 -29
  242. package/src/integrations/skilltree.ts +1 -0
  243. package/src/lifecycle/__tests__/cascade-consolidation.test.ts +240 -0
  244. package/src/lifecycle/cascade.ts +77 -2
  245. package/src/lifecycle/cleanup.ts +52 -3
  246. package/src/lifecycle/handlers-v2.ts +40 -3
  247. package/src/lifecycle/types.ts +12 -0
  248. package/src/map/__tests__/cascade-bridge.test.ts +229 -0
  249. package/src/map/__tests__/emit-event.test.ts +71 -0
  250. package/src/map/__tests__/lifecycle-bridge.test.ts +86 -10
  251. package/src/map/acp-bridge.ts +26 -3
  252. package/src/map/cascade-action-handler.ts +205 -0
  253. package/src/map/cascade-bridge.ts +339 -0
  254. package/src/map/coordination-handler.ts +13 -1
  255. package/src/map/lifecycle-bridge.ts +52 -17
  256. package/src/map/server.ts +225 -7
  257. package/src/map/sidecar.ts +48 -1
  258. package/src/map/types.ts +23 -0
  259. package/src/mcp/tools/done-v2.ts +9 -0
  260. package/src/teams/team-manager-v2.ts +37 -0
  261. package/src/teams/team-runtime-v2.ts +23 -3
  262. package/src/workspace/__tests__/{dataplane-adapter.test.ts → git-cascade-adapter.test.ts} +209 -14
  263. package/src/workspace/__tests__/land-dispatch.test.ts +214 -0
  264. package/src/workspace/__tests__/self-driving-yaml.test.ts +114 -0
  265. package/src/workspace/__tests__/shared-worktree-refcount.test.ts +154 -0
  266. package/src/workspace/__tests__/standalone-mode.test.ts +118 -0
  267. package/src/workspace/__tests__/workspace-manager-v3.test.ts +245 -0
  268. package/src/workspace/__tests__/yaml-schema.test.ts +210 -0
  269. package/src/workspace/config.ts +11 -11
  270. package/src/workspace/git-cascade-adapter.ts +1213 -0
  271. package/src/workspace/index.ts +11 -11
  272. package/src/workspace/landing/__tests__/strategies.test.ts +184 -0
  273. package/src/workspace/landing/direct-push.ts +91 -0
  274. package/src/workspace/landing/index.ts +40 -0
  275. package/src/workspace/landing/merge-to-parent.ts +229 -0
  276. package/src/workspace/landing/optimistic-push.ts +36 -0
  277. package/src/workspace/landing/queue-to-branch.ts +108 -0
  278. package/src/workspace/merge-queue/merge-queue.ts +10 -0
  279. package/src/workspace/merge-queue/types.ts +16 -2
  280. package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +5 -5
  281. package/src/workspace/pool/types.ts +1 -0
  282. package/src/workspace/pool/worktree-pool.ts +1 -0
  283. package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +127 -0
  284. package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +139 -0
  285. package/src/workspace/recovery/__tests__/strategies.test.ts +145 -0
  286. package/src/workspace/recovery/abandon.ts +51 -0
  287. package/src/workspace/recovery/auto-resolve.ts +119 -0
  288. package/src/workspace/recovery/defer.ts +23 -0
  289. package/src/workspace/recovery/escalate.ts +30 -0
  290. package/src/workspace/recovery/index.ts +58 -0
  291. package/src/workspace/recovery/spawn-resolver.ts +152 -0
  292. package/src/workspace/recovery/types.ts +54 -0
  293. package/src/workspace/topology/__tests__/yaml-driven.test.ts +345 -0
  294. package/src/workspace/topology/index.ts +18 -0
  295. package/src/workspace/topology/no-workspace.ts +39 -0
  296. package/src/workspace/topology/types.ts +116 -0
  297. package/src/workspace/topology/yaml-driven.ts +316 -0
  298. package/src/workspace/types-v3.ts +162 -0
  299. package/src/workspace/types.ts +211 -20
  300. package/src/workspace/workspace-manager.ts +533 -19
  301. package/src/workspace/yaml-schema.ts +216 -0
  302. package/dist/workspace/dataplane-adapter.d.ts +0 -260
  303. package/dist/workspace/dataplane-adapter.d.ts.map +0 -1
  304. package/dist/workspace/dataplane-adapter.js +0 -416
  305. package/dist/workspace/dataplane-adapter.js.map +0 -1
  306. package/src/workspace/dataplane-adapter.ts +0 -546
@@ -1,546 +0,0 @@
1
- /**
2
- * Dataplane Adapter
3
- *
4
- * Wraps MultiAgentRepoTracker to integrate with macro-agent's event system
5
- * and provide a simplified interface for workspace management.
6
- *
7
- * @module workspace/dataplane-adapter
8
- * @implements [[s-7ktd]] Dataplane Integration section
9
- */
10
-
11
- import Database from 'better-sqlite3';
12
- import {
13
- MultiAgentRepoTracker,
14
- type TrackerOptions,
15
- type Stream,
16
- type StreamStatus,
17
- type CreateStreamOptions,
18
- type AgentWorktree,
19
- type CreateWorktreeOptions,
20
- type WorkerTask,
21
- type CreateTaskOptions,
22
- type StartTaskOptions,
23
- type CompleteTaskOptions,
24
- type StartTaskResult,
25
- type CompleteTaskResult,
26
- type ListTasksOptions,
27
- type CleanupWorkerBranchesOptions,
28
- type CleanupResult,
29
- type Checkpoint,
30
- workerTasks,
31
- diffStacks,
32
- } from 'git-cascade';
33
- import type { DataplaneConfig } from './config.js';
34
- import { DEFAULT_DATAPLANE_CONFIG } from './config.js';
35
-
36
- /**
37
- * Event types emitted by DataplaneAdapter
38
- */
39
- export type DataplaneEventType =
40
- | 'stream:created'
41
- | 'stream:updated'
42
- | 'stream:abandoned'
43
- | 'worktree:created'
44
- | 'worktree:deallocated'
45
- | 'task:created'
46
- | 'task:started'
47
- | 'task:completed'
48
- | 'task:abandoned';
49
-
50
- /**
51
- * Event payload for dataplane events
52
- */
53
- export interface DataplaneEvent {
54
- type: DataplaneEventType;
55
- timestamp: number;
56
- data: Record<string, unknown>;
57
- }
58
-
59
- /**
60
- * Callback for dataplane events
61
- */
62
- export type DataplaneEventCallback = (event: DataplaneEvent) => void;
63
-
64
- /**
65
- * DataplaneAdapter wraps MultiAgentRepoTracker for macro-agent integration.
66
- *
67
- * Key responsibilities:
68
- * - Initialize dataplane with shared or dedicated database
69
- * - Emit events on dataplane operations
70
- * - Provide simplified API for workspace management
71
- */
72
- export class DataplaneAdapter {
73
- private readonly tracker: MultiAgentRepoTracker;
74
- private readonly config: Required<
75
- Pick<DataplaneConfig, 'enabled' | 'tablePrefix' | 'verbose' | 'skipRecovery'>
76
- > & { repoPath: string };
77
- private readonly eventListeners: Set<DataplaneEventCallback> = new Set();
78
- private readonly ownsDb: boolean;
79
-
80
- /**
81
- * Create a new DataplaneAdapter.
82
- *
83
- * @param config - Dataplane configuration
84
- */
85
- constructor(config: DataplaneConfig) {
86
- const mergedConfig = {
87
- ...DEFAULT_DATAPLANE_CONFIG,
88
- ...config,
89
- repoPath: config.repoPath ?? process.cwd(),
90
- };
91
-
92
- this.config = {
93
- enabled: mergedConfig.enabled ?? true,
94
- repoPath: mergedConfig.repoPath,
95
- tablePrefix: mergedConfig.tablePrefix ?? 'dataplane_',
96
- verbose: mergedConfig.verbose ?? false,
97
- skipRecovery: mergedConfig.skipRecovery ?? false,
98
- };
99
-
100
- // Determine if we own the database connection
101
- this.ownsDb = !config.db;
102
-
103
- const trackerOptions: TrackerOptions = {
104
- repoPath: this.config.repoPath,
105
- tablePrefix: this.config.tablePrefix,
106
- verbose: this.config.verbose,
107
- skipRecovery: this.config.skipRecovery,
108
- };
109
-
110
- if (config.db) {
111
- trackerOptions.db = config.db;
112
- } else if (config.dbPath) {
113
- trackerOptions.dbPath = config.dbPath;
114
- }
115
- // If neither db nor dbPath provided, tracker uses default path
116
-
117
- this.tracker = new MultiAgentRepoTracker(trackerOptions);
118
- }
119
-
120
- /**
121
- * Get whether dataplane is enabled.
122
- */
123
- get enabled(): boolean {
124
- return this.config.enabled;
125
- }
126
-
127
- /**
128
- * Get the repository path.
129
- */
130
- get repoPath(): string {
131
- return this.config.repoPath;
132
- }
133
-
134
- /**
135
- * Get the underlying database connection.
136
- * Use with caution - prefer adapter methods for operations.
137
- */
138
- get db(): Database.Database {
139
- return this.tracker.db;
140
- }
141
-
142
- /**
143
- * Get the underlying tracker.
144
- * Use with caution - prefer adapter methods for operations.
145
- */
146
- get rawTracker(): MultiAgentRepoTracker {
147
- return this.tracker;
148
- }
149
-
150
- // ─────────────────────────────────────────────────────────────────────────────
151
- // Event System
152
- // ─────────────────────────────────────────────────────────────────────────────
153
-
154
- /**
155
- * Subscribe to dataplane events.
156
- *
157
- * @param callback - Function called when events occur
158
- * @returns Unsubscribe function
159
- */
160
- onEvent(callback: DataplaneEventCallback): () => void {
161
- this.eventListeners.add(callback);
162
- return () => this.eventListeners.delete(callback);
163
- }
164
-
165
- /**
166
- * Emit an event to all listeners.
167
- */
168
- private emit(type: DataplaneEventType, data: Record<string, unknown>): void {
169
- const event: DataplaneEvent = {
170
- type,
171
- timestamp: Date.now(),
172
- data,
173
- };
174
- for (const listener of this.eventListeners) {
175
- try {
176
- listener(event);
177
- } catch (error) {
178
- console.error('[DataplaneAdapter] Event listener error:', error);
179
- }
180
- }
181
- }
182
-
183
- // ─────────────────────────────────────────────────────────────────────────────
184
- // Stream Operations
185
- // ─────────────────────────────────────────────────────────────────────────────
186
-
187
- /**
188
- * Create a new stream (integration branch).
189
- *
190
- * @param options - Stream creation options
191
- * @returns Stream ID
192
- */
193
- createStream(options: CreateStreamOptions): string {
194
- const streamId = this.tracker.createStream(options);
195
- this.emit('stream:created', { streamId, ...options });
196
- return streamId;
197
- }
198
-
199
- /**
200
- * Get a stream by ID.
201
- */
202
- getStream(streamId: string): Stream | null {
203
- return this.tracker.getStream(streamId);
204
- }
205
-
206
- /**
207
- * List streams with optional filters.
208
- */
209
- listStreams(options?: { agentId?: string; status?: StreamStatus }): Stream[] {
210
- return this.tracker.listStreams(options);
211
- }
212
-
213
- /**
214
- * Update a stream.
215
- */
216
- updateStream(
217
- streamId: string,
218
- updates: Partial<Pick<Stream, 'name' | 'status' | 'metadata'>>
219
- ): void {
220
- this.tracker.updateStream(streamId, updates);
221
- this.emit('stream:updated', { streamId, updates });
222
- }
223
-
224
- /**
225
- * Abandon a stream.
226
- */
227
- abandonStream(
228
- streamId: string,
229
- options?: { reason?: string; cascade?: boolean }
230
- ): void {
231
- this.tracker.abandonStream(streamId, options);
232
- this.emit('stream:abandoned', { streamId, ...options });
233
- }
234
-
235
- /**
236
- * Get the git branch name for a stream.
237
- */
238
- getStreamBranchName(streamId: string): string {
239
- return this.tracker.getStreamBranchName(streamId);
240
- }
241
-
242
- /**
243
- * Get the HEAD commit of a stream.
244
- */
245
- getStreamHead(streamId: string): string {
246
- return this.tracker.getStreamHead(streamId);
247
- }
248
-
249
- // ─────────────────────────────────────────────────────────────────────────────
250
- // Worktree Operations
251
- // ─────────────────────────────────────────────────────────────────────────────
252
-
253
- /**
254
- * Create a worktree for an agent.
255
- *
256
- * @param options - Worktree creation options
257
- * @returns Created worktree info
258
- */
259
- createWorktree(options: CreateWorktreeOptions): AgentWorktree {
260
- const worktree = this.tracker.createWorktree(options);
261
- this.emit('worktree:created', { ...worktree });
262
- return worktree;
263
- }
264
-
265
- /**
266
- * Get a worktree by agent ID.
267
- */
268
- getWorktree(agentId: string): AgentWorktree | null {
269
- return this.tracker.getWorktree(agentId);
270
- }
271
-
272
- /**
273
- * List all worktrees.
274
- */
275
- listWorktrees(): AgentWorktree[] {
276
- return this.tracker.listWorktrees();
277
- }
278
-
279
- /**
280
- * Update the stream associated with a worktree.
281
- */
282
- updateWorktreeStream(agentId: string, streamId: string | null): void {
283
- this.tracker.updateWorktreeStream(agentId, streamId);
284
- }
285
-
286
- /**
287
- * Deallocate a worktree.
288
- */
289
- deallocateWorktree(agentId: string): void {
290
- this.tracker.deallocateWorktree(agentId);
291
- this.emit('worktree:deallocated', { agentId });
292
- }
293
-
294
- // ─────────────────────────────────────────────────────────────────────────────
295
- // Worker Task Operations
296
- // ─────────────────────────────────────────────────────────────────────────────
297
-
298
- /**
299
- * Create a worker task under a stream.
300
- *
301
- * @param options - Task creation options
302
- * @returns Task ID
303
- */
304
- createTask(options: CreateTaskOptions): string {
305
- const taskId = this.tracker.createTask(options);
306
- this.emit('task:created', { taskId, ...options });
307
- return taskId;
308
- }
309
-
310
- /**
311
- * Get a task by ID.
312
- */
313
- getTask(taskId: string): WorkerTask | null {
314
- return this.tracker.getTask(taskId);
315
- }
316
-
317
- /**
318
- * List tasks for a stream.
319
- */
320
- listTasks(streamId: string, options?: ListTasksOptions): WorkerTask[] {
321
- return this.tracker.listTasks(streamId, options);
322
- }
323
-
324
- /**
325
- * Start a task - assigns agent and creates worker branch.
326
- *
327
- * @param options - Start task options
328
- * @returns Branch name and start commit
329
- */
330
- startTask(options: StartTaskOptions): StartTaskResult {
331
- const result = this.tracker.startTask(options);
332
- this.emit('task:started', {
333
- taskId: options.taskId,
334
- agentId: options.agentId,
335
- branchName: result.branchName,
336
- startCommit: result.startCommit,
337
- });
338
- return result;
339
- }
340
-
341
- /**
342
- * Complete a task - merges worker branch to stream.
343
- *
344
- * @param options - Complete task options
345
- * @returns Merge result
346
- */
347
- completeTask(options: CompleteTaskOptions): CompleteTaskResult {
348
- const result = this.tracker.completeTask(options);
349
- this.emit('task:completed', { taskId: options.taskId, ...result });
350
- return result;
351
- }
352
-
353
- /**
354
- * Abandon a task.
355
- *
356
- * @param taskId - Task ID
357
- * @param options - Options
358
- */
359
- abandonTask(taskId: string, options?: { deleteBranch?: boolean }): void {
360
- this.tracker.abandonTask(taskId, options);
361
- this.emit('task:abandoned', { taskId, ...options });
362
- }
363
-
364
- /**
365
- * Release a task back to 'open' status.
366
- */
367
- releaseTask(taskId: string): void {
368
- this.tracker.releaseTask(taskId);
369
- }
370
-
371
- /**
372
- * Detect conflicts for a task before completing.
373
- *
374
- * @param taskId - Task ID
375
- * @param worktree - Worktree path
376
- * @returns Array of conflicting file paths, empty if no conflicts
377
- */
378
- detectTaskConflicts(taskId: string, worktree: string): string[] {
379
- return workerTasks.detectTaskConflicts(
380
- this.tracker.db,
381
- this.config.repoPath,
382
- taskId,
383
- worktree
384
- );
385
- }
386
-
387
- /**
388
- * Recover stale tasks that have been in_progress too long.
389
- *
390
- * @param thresholdMs - Tasks older than this are considered stale
391
- * @returns Result with released task IDs
392
- */
393
- recoverStaleTasks(thresholdMs: number = 60 * 60 * 1000): { released: string[] } {
394
- return workerTasks.recoverStaleTasks(this.tracker.db, thresholdMs);
395
- }
396
-
397
- // ─────────────────────────────────────────────────────────────────────────────
398
- // Checkpoint Operations
399
- // ─────────────────────────────────────────────────────────────────────────────
400
-
401
- /**
402
- * Create checkpoints for commits made during a task.
403
- *
404
- * Creates a checkpoint for each commit between the task's startCommit and
405
- * the current HEAD of the task's stream. This captures the work done during
406
- * the task for future review and merge workflows.
407
- *
408
- * @param taskId - Task ID to create checkpoints for
409
- * @param agentId - Agent ID (used as createdBy)
410
- * @returns Array of created checkpoints
411
- */
412
- createCheckpointsForTask(taskId: string, agentId: string): Checkpoint[] {
413
- const task = this.getTask(taskId);
414
- if (!task) {
415
- console.warn(`[DataplaneAdapter] Task not found: ${taskId}`);
416
- return [];
417
- }
418
-
419
- if (!task.streamId) {
420
- console.warn(`[DataplaneAdapter] Task ${taskId} has no streamId`);
421
- return [];
422
- }
423
-
424
- if (!task.startCommit) {
425
- console.warn(`[DataplaneAdapter] Task ${taskId} has no startCommit`);
426
- return [];
427
- }
428
-
429
- try {
430
- // Create checkpoints from task's startCommit to stream's current HEAD
431
- const checkpoints = diffStacks.createCheckpointsFromStream(
432
- this.tracker.db,
433
- this.config.repoPath,
434
- task.streamId,
435
- {
436
- from: task.startCommit,
437
- createdBy: agentId,
438
- }
439
- );
440
-
441
- return checkpoints;
442
- } catch (error) {
443
- console.error(
444
- `[DataplaneAdapter] Failed to create checkpoints for task ${taskId}:`,
445
- error
446
- );
447
- return [];
448
- }
449
- }
450
-
451
- // ─────────────────────────────────────────────────────────────────────────────
452
- // Commit Operations
453
- // ─────────────────────────────────────────────────────────────────────────────
454
-
455
- /**
456
- * Commit changes in a worktree with Change tracking.
457
- *
458
- * @param options - Commit options
459
- * @returns Commit hash and change ID
460
- */
461
- commitChanges(options: {
462
- streamId: string;
463
- agentId: string;
464
- worktree: string;
465
- message: string;
466
- }): { commit: string; changeId: string } {
467
- return this.tracker.commitChanges(options);
468
- }
469
-
470
- // ─────────────────────────────────────────────────────────────────────────────
471
- // Maintenance Operations
472
- // ─────────────────────────────────────────────────────────────────────────────
473
-
474
- /**
475
- * Clean up old worker branches.
476
- *
477
- * Deletes branches for:
478
- * - Completed tasks older than threshold (default 24h)
479
- * - Abandoned tasks
480
- * - Orphaned branches (no task record)
481
- *
482
- * @param options - Cleanup options
483
- * @returns Deleted branches and any errors
484
- */
485
- cleanupWorkerBranches(options?: CleanupWorkerBranchesOptions): CleanupResult {
486
- return workerTasks.cleanupWorkerBranches(
487
- this.tracker.db,
488
- this.config.repoPath,
489
- options
490
- );
491
- }
492
-
493
- /**
494
- * Delete a specific worker branch.
495
- *
496
- * @param branchName - Branch name to delete
497
- * @returns true if deleted, false if branch didn't exist
498
- */
499
- deleteWorkerBranch(branchName: string): boolean {
500
- try {
501
- const { execSync } = require('child_process');
502
- execSync(`git branch -D "${branchName}"`, {
503
- cwd: this.config.repoPath,
504
- stdio: 'pipe',
505
- });
506
- return true;
507
- } catch {
508
- return false;
509
- }
510
- }
511
-
512
- // ─────────────────────────────────────────────────────────────────────────────
513
- // Health & Recovery
514
- // ─────────────────────────────────────────────────────────────────────────────
515
-
516
- /**
517
- * Check system health.
518
- */
519
- healthCheck(): ReturnType<MultiAgentRepoTracker['healthCheck']> {
520
- return this.tracker.healthCheck();
521
- }
522
-
523
- // ─────────────────────────────────────────────────────────────────────────────
524
- // Lifecycle
525
- // ─────────────────────────────────────────────────────────────────────────────
526
-
527
- /**
528
- * Close the adapter and release resources.
529
- *
530
- * Only closes the database if we created it (not if using shared DB).
531
- */
532
- close(): void {
533
- this.eventListeners.clear();
534
- this.tracker.close();
535
- }
536
- }
537
-
538
- /**
539
- * Create a DataplaneAdapter instance.
540
- *
541
- * @param config - Configuration options
542
- * @returns DataplaneAdapter instance
543
- */
544
- export function createDataplaneAdapter(config: DataplaneConfig): DataplaneAdapter {
545
- return new DataplaneAdapter(config);
546
- }