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
@@ -0,0 +1,934 @@
1
+ /**
2
+ * git-cascade Adapter
3
+ *
4
+ * Wraps git-cascade's MultiAgentRepoTracker to integrate with macro-agent's
5
+ * event system and provide a simplified interface for workspace management.
6
+ *
7
+ * @module workspace/git-cascade-adapter
8
+ */
9
+ import { MultiAgentRepoTracker, workerTasks, diffStacks, matchCascadeSuffix, } from 'git-cascade';
10
+ import { DEFAULT_GIT_CASCADE_CONFIG } from './config.js';
11
+ /**
12
+ * GitCascadeAdapter wraps MultiAgentRepoTracker for macro-agent integration.
13
+ *
14
+ * Key responsibilities:
15
+ * - Initialize tracker with shared or dedicated database
16
+ * - Emit events on tracker operations
17
+ * - Provide simplified API for workspace management
18
+ */
19
+ export class GitCascadeAdapter {
20
+ tracker;
21
+ config;
22
+ eventListeners = new Set();
23
+ ownsDb;
24
+ /**
25
+ * Create a new GitCascadeAdapter.
26
+ *
27
+ * @param config - git-cascade configuration
28
+ */
29
+ constructor(config) {
30
+ const mergedConfig = {
31
+ ...DEFAULT_GIT_CASCADE_CONFIG,
32
+ ...config,
33
+ repoPath: config.repoPath ?? process.cwd(),
34
+ };
35
+ this.config = {
36
+ enabled: mergedConfig.enabled ?? true,
37
+ repoPath: mergedConfig.repoPath,
38
+ tablePrefix: mergedConfig.tablePrefix ?? 'git_cascade_',
39
+ verbose: mergedConfig.verbose ?? false,
40
+ skipRecovery: mergedConfig.skipRecovery ?? false,
41
+ };
42
+ // Determine if we own the database connection
43
+ this.ownsDb = !config.db;
44
+ const trackerOptions = {
45
+ repoPath: this.config.repoPath,
46
+ tablePrefix: this.config.tablePrefix,
47
+ verbose: this.config.verbose,
48
+ skipRecovery: this.config.skipRecovery,
49
+ // Wire git-cascade's native event emitter (0.0.2+) so stream lifecycle
50
+ // events are re-published through our own onEvent channel.
51
+ emit: (method, params) => this.forwardCascadeEvent(method, params),
52
+ };
53
+ if (config.db) {
54
+ trackerOptions.db = config.db;
55
+ }
56
+ else if (config.dbPath) {
57
+ trackerOptions.dbPath = config.dbPath;
58
+ }
59
+ // If neither db nor dbPath provided, tracker uses default path
60
+ this.tracker = new MultiAgentRepoTracker(trackerOptions);
61
+ }
62
+ /**
63
+ * Get whether the adapter is enabled.
64
+ */
65
+ get enabled() {
66
+ return this.config.enabled;
67
+ }
68
+ /**
69
+ * Get the repository path.
70
+ */
71
+ get repoPath() {
72
+ return this.config.repoPath;
73
+ }
74
+ /**
75
+ * Get the underlying database connection.
76
+ * Use with caution - prefer adapter methods for operations.
77
+ */
78
+ get db() {
79
+ return this.tracker.db;
80
+ }
81
+ /**
82
+ * Get the underlying tracker.
83
+ * Use with caution - prefer adapter methods for operations.
84
+ */
85
+ get rawTracker() {
86
+ return this.tracker;
87
+ }
88
+ // ─────────────────────────────────────────────────────────────────────────────
89
+ // Event System
90
+ // ─────────────────────────────────────────────────────────────────────────────
91
+ /**
92
+ * Subscribe to git-cascade events.
93
+ *
94
+ * @param callback - Function called when events occur
95
+ * @returns Unsubscribe function
96
+ */
97
+ onEvent(callback) {
98
+ this.eventListeners.add(callback);
99
+ return () => this.eventListeners.delete(callback);
100
+ }
101
+ /**
102
+ * Emit an event to all listeners.
103
+ */
104
+ emit(type, data) {
105
+ const event = {
106
+ type,
107
+ timestamp: Date.now(),
108
+ data,
109
+ };
110
+ for (const listener of this.eventListeners) {
111
+ try {
112
+ listener(event);
113
+ }
114
+ catch (error) {
115
+ console.error('[GitCascadeAdapter] Event listener error:', error);
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * Forward events emitted by git-cascade (`x-cascade/stream.*`) into our
121
+ * structured `GitCascadeEvent` stream. Called via the `emit` callback wired
122
+ * into the tracker constructor.
123
+ *
124
+ * Note: `stream.opened` is mapped to `stream:created`. The local
125
+ * wrapper methods still emit their own events so consumers don't miss out
126
+ * on operations that don't round-trip through git-cascade's emit (e.g.,
127
+ * updateStream, pauseStream, mergeQueue events).
128
+ */
129
+ forwardCascadeEvent(method, params) {
130
+ const suffix = matchCascadeSuffix(method);
131
+ if (!suffix)
132
+ return;
133
+ // Widen to `string` so case labels for suffixes not yet in the installed
134
+ // git-cascade version (e.g. `stream.paused`, `stream.resumed`,
135
+ // `stream.rolled_back` — added after 0.0.7) still compile. The runtime
136
+ // value is always a string either way; this is a version-skew shim.
137
+ switch (suffix) {
138
+ case 'stream.opened': {
139
+ const p = params;
140
+ this.emit('stream:created', {
141
+ streamId: p.stream_id,
142
+ name: p.name,
143
+ agentId: p.agent_id,
144
+ baseCommit: p.base_commit,
145
+ parentStream: p.parent_stream,
146
+ branchName: p.branch_name,
147
+ metadata: p.metadata,
148
+ });
149
+ break;
150
+ }
151
+ case 'stream.committed': {
152
+ const p = params;
153
+ this.emit('stream:committed', {
154
+ streamId: p.stream_id,
155
+ commit: p.commit_hash,
156
+ changeId: p.change_id,
157
+ agentId: p.agent_id,
158
+ messageSummary: p.message_summary,
159
+ filesTouched: p.files_touched,
160
+ parentCommit: p.parent_commit,
161
+ metadata: p.metadata,
162
+ });
163
+ break;
164
+ }
165
+ case 'stream.merged': {
166
+ const p = params;
167
+ this.emit('stream:merged', {
168
+ sourceStreamId: p.source_stream_id,
169
+ targetStreamId: p.target_stream_id,
170
+ mergeCommit: p.merge_commit,
171
+ agentId: p.agent_id,
172
+ strategy: p.strategy,
173
+ sourceCommit: p.source_commit,
174
+ metadata: p.metadata,
175
+ });
176
+ break;
177
+ }
178
+ case 'stream.conflicted': {
179
+ const p = params;
180
+ this.emit('stream:conflicted', {
181
+ streamId: p.stream_id,
182
+ conflictId: p.conflict_id,
183
+ conflictedFiles: p.conflicted_files,
184
+ agentId: p.agent_id,
185
+ conflictingCommit: p.conflicting_commit,
186
+ targetCommit: p.target_commit,
187
+ source: p.source,
188
+ metadata: p.metadata,
189
+ });
190
+ break;
191
+ }
192
+ case 'stream.conflict_resolved': {
193
+ const p = params;
194
+ this.emit('conflict:resolved', {
195
+ streamId: p.stream_id,
196
+ conflictId: p.conflict_id,
197
+ resolutionMethod: p.resolution_method,
198
+ resolvedBy: p.resolved_by,
199
+ resolutionSummary: p.resolution_summary,
200
+ metadata: p.metadata,
201
+ });
202
+ break;
203
+ }
204
+ case 'stream.abandoned': {
205
+ const p = params;
206
+ this.emit('stream:abandoned', {
207
+ streamId: p.stream_id,
208
+ reason: p.reason,
209
+ cascade: p.cascade,
210
+ metadata: p.metadata,
211
+ });
212
+ break;
213
+ }
214
+ case 'cascade.rebased': {
215
+ const p = params;
216
+ this.emit('cascade:rebased', {
217
+ streamId: p.stream_id,
218
+ agentId: p.agent_id,
219
+ triggeredByStreamId: p.triggered_by_stream_id,
220
+ triggeredByAgentId: p.triggered_by_agent_id,
221
+ newBaseCommit: p.new_base_commit,
222
+ newHead: p.new_head,
223
+ newCommits: p.new_commits,
224
+ metadata: p.metadata,
225
+ });
226
+ break;
227
+ }
228
+ case 'cascade.completed': {
229
+ const p = params;
230
+ this.emit('cascade:completed', {
231
+ rootStreamId: p.root_stream_id,
232
+ agentId: p.agent_id,
233
+ strategy: p.strategy,
234
+ updatedStreams: p.updated_streams,
235
+ failedStreams: p.failed_streams,
236
+ skippedStreams: p.skipped_streams,
237
+ deferredStreams: p.deferred_streams,
238
+ metadata: p.metadata,
239
+ });
240
+ break;
241
+ }
242
+ case 'queue.added': {
243
+ const p = params;
244
+ this.emit('mergeQueue:added', {
245
+ entryId: p.entry_id,
246
+ streamId: p.stream_id,
247
+ targetBranch: p.target_branch,
248
+ metadata: p.metadata,
249
+ });
250
+ break;
251
+ }
252
+ case 'queue.ready': {
253
+ const p = params;
254
+ this.emit('mergeQueue:ready', {
255
+ entryId: p.entry_id,
256
+ streamId: p.stream_id,
257
+ targetBranch: p.target_branch,
258
+ });
259
+ break;
260
+ }
261
+ case 'queue.cancelled': {
262
+ const p = params;
263
+ this.emit('mergeQueue:cancelled', {
264
+ entryId: p.entry_id,
265
+ streamId: p.stream_id,
266
+ targetBranch: p.target_branch,
267
+ reason: p.reason,
268
+ });
269
+ break;
270
+ }
271
+ case 'queue.removed': {
272
+ const p = params;
273
+ this.emit('mergeQueue:removed', {
274
+ entryId: p.entry_id,
275
+ streamId: p.stream_id,
276
+ targetBranch: p.target_branch,
277
+ outcome: p.outcome,
278
+ });
279
+ break;
280
+ }
281
+ case 'stream.paused': {
282
+ // Tracker fires stream.paused after pauseStream. The adapter also
283
+ // emits stream:paused locally in its pauseStream() wrapper — the
284
+ // bridge uses the local event (not this cascade-forwarded one) for
285
+ // the MAP translation, so this case is mainly to keep the switch
286
+ // exhaustive. No double-emit: the bridge deduplicates by event type.
287
+ break;
288
+ }
289
+ case 'stream.resumed': {
290
+ // Same as stream.paused — adapter.resumeStream() fires the local event.
291
+ break;
292
+ }
293
+ case 'stream.rolled_back': {
294
+ const p = params;
295
+ this.emit('stream:rolled_back', {
296
+ streamId: p.stream_id,
297
+ strategy: p.strategy,
298
+ target: p.target,
299
+ newHead: p.new_head,
300
+ });
301
+ break;
302
+ }
303
+ }
304
+ }
305
+ // ─────────────────────────────────────────────────────────────────────────────
306
+ // Stream Operations
307
+ // ─────────────────────────────────────────────────────────────────────────────
308
+ /**
309
+ * Create a new stream (integration branch).
310
+ *
311
+ * Note: `stream:created` is emitted by the cascade event forwarder via
312
+ * git-cascade's `x-cascade/stream.opened`. We don't double-emit here.
313
+ *
314
+ * @param options - Stream creation options
315
+ * @returns Stream ID
316
+ */
317
+ createStream(options) {
318
+ return this.tracker.createStream(options);
319
+ }
320
+ /**
321
+ * Get a stream by ID.
322
+ */
323
+ getStream(streamId) {
324
+ return this.tracker.getStream(streamId);
325
+ }
326
+ /**
327
+ * List streams with optional filters.
328
+ */
329
+ listStreams(options) {
330
+ return this.tracker.listStreams(options);
331
+ }
332
+ /**
333
+ * Update a stream.
334
+ */
335
+ updateStream(streamId, updates) {
336
+ this.tracker.updateStream(streamId, updates);
337
+ this.emit('stream:updated', { streamId, updates });
338
+ }
339
+ /**
340
+ * Abandon a stream.
341
+ *
342
+ * Note: `stream:abandoned` is emitted by the cascade event forwarder.
343
+ */
344
+ abandonStream(streamId, options) {
345
+ this.tracker.abandonStream(streamId, options);
346
+ }
347
+ /**
348
+ * Get the git branch name for a stream.
349
+ */
350
+ getStreamBranchName(streamId) {
351
+ return this.tracker.getStreamBranchName(streamId);
352
+ }
353
+ /**
354
+ * Get the HEAD commit of a stream.
355
+ */
356
+ getStreamHead(streamId) {
357
+ return this.tracker.getStreamHead(streamId);
358
+ }
359
+ /**
360
+ * Fork a child stream off a parent.
361
+ */
362
+ forkStream(options) {
363
+ const streamId = this.tracker.forkStream(options);
364
+ this.emit('stream:forked', {
365
+ streamId,
366
+ parentStreamId: options.parentStreamId,
367
+ name: options.name,
368
+ agentId: options.agentId,
369
+ });
370
+ return streamId;
371
+ }
372
+ /**
373
+ * Merge source stream into target stream.
374
+ *
375
+ * Note: `stream:merged` is emitted by the cascade event forwarder on success.
376
+ * On conflict, `stream:conflicted` is also forwarded.
377
+ */
378
+ mergeStream(options) {
379
+ return this.tracker.mergeStream(options);
380
+ }
381
+ /**
382
+ * Rebase a stream onto its parent to pick up new commits.
383
+ */
384
+ syncWithParent(streamId, agentId, worktree, onConflict) {
385
+ return this.tracker.syncWithParent(streamId, agentId, worktree, onConflict);
386
+ }
387
+ /**
388
+ * Rebase a stream onto a specific target stream.
389
+ */
390
+ rebaseOntoStream(options) {
391
+ return this.tracker.rebaseOntoStream(options);
392
+ }
393
+ /**
394
+ * Async version of rebaseOntoStream — supports async conflict handlers.
395
+ */
396
+ rebaseOntoStreamAsync(options) {
397
+ return this.tracker.rebaseOntoStreamAsync(options);
398
+ }
399
+ /**
400
+ * Pause a stream (halt work without abandoning).
401
+ */
402
+ pauseStream(streamId, reason) {
403
+ this.tracker.pauseStream(streamId, reason);
404
+ this.emit('stream:paused', { streamId, reason });
405
+ }
406
+ /**
407
+ * Resume a paused stream.
408
+ */
409
+ resumeStream(streamId) {
410
+ this.tracker.resumeStream(streamId);
411
+ this.emit('stream:resumed', { streamId });
412
+ }
413
+ /**
414
+ * Track an existing branch as a stream (local mode — no new `stream/<id>` branch).
415
+ */
416
+ trackExistingBranch(options) {
417
+ return this.tracker.trackExistingBranch(options);
418
+ }
419
+ /**
420
+ * Get stream hierarchy as a tree.
421
+ */
422
+ getStreamHierarchy(rootStreamId) {
423
+ return this.tracker.getStreamHierarchy(rootStreamId);
424
+ }
425
+ /**
426
+ * Get child streams (direct children only).
427
+ */
428
+ getChildStreams(streamId) {
429
+ return this.tracker.getChildStreams(streamId);
430
+ }
431
+ /**
432
+ * Find the common ancestor of two streams.
433
+ */
434
+ findCommonAncestor(streamIdA, streamIdB) {
435
+ return this.tracker.findCommonAncestor(streamIdA, streamIdB);
436
+ }
437
+ // ─────────────────────────────────────────────────────────────────────────────
438
+ // Stream Dependencies
439
+ // ─────────────────────────────────────────────────────────────────────────────
440
+ /**
441
+ * Declare that one stream depends on another.
442
+ */
443
+ addDependency(streamId, dependsOnId) {
444
+ this.tracker.addDependency(streamId, dependsOnId);
445
+ }
446
+ /**
447
+ * Remove a dependency declaration.
448
+ */
449
+ removeDependency(streamId, dependsOnId) {
450
+ this.tracker.removeDependency(streamId, dependsOnId);
451
+ }
452
+ /**
453
+ * Get direct dependencies of a stream.
454
+ */
455
+ getDependencies(streamId) {
456
+ return this.tracker.getDependencies(streamId);
457
+ }
458
+ /**
459
+ * Get direct dependents of a stream.
460
+ */
461
+ getDependents(streamId) {
462
+ return this.tracker.getDependents(streamId);
463
+ }
464
+ // ─────────────────────────────────────────────────────────────────────────────
465
+ // Cascade Rebase (git-cascade 0.0.3+)
466
+ // ─────────────────────────────────────────────────────────────────────────────
467
+ /**
468
+ * Cascade-rebase all dependents of a root stream.
469
+ *
470
+ * Propagates rebases through the dependency graph. Uses a callback-based
471
+ * worktree provider so not every dependent needs a pre-allocated worktree.
472
+ *
473
+ * @param options - Cascade options including root stream, agent id, and worktree provider
474
+ * @returns CascadeResult with updated/failed/skipped stream lists
475
+ */
476
+ cascadeRebase(options) {
477
+ // Use tracker.cascadeRebase which threads the tracker's emit + eventPrefix
478
+ // into the cascade walk so `cascade.rebased` (per dependent) and
479
+ // `cascade.completed` (at end) both round-trip through our
480
+ // forwardCascadeEvent. No manual emit needed — events are driven by
481
+ // git-cascade 0.0.4+ from inside the walk.
482
+ return this.tracker.cascadeRebase(options);
483
+ }
484
+ // ─────────────────────────────────────────────────────────────────────────────
485
+ // Worktree Operations
486
+ // ─────────────────────────────────────────────────────────────────────────────
487
+ /**
488
+ * Create a worktree for an agent.
489
+ *
490
+ * @param options - Worktree creation options
491
+ * @returns Created worktree info
492
+ */
493
+ createWorktree(options) {
494
+ const worktree = this.tracker.createWorktree(options);
495
+ this.emit('worktree:created', { ...worktree });
496
+ return worktree;
497
+ }
498
+ /**
499
+ * Get a worktree by agent ID.
500
+ */
501
+ getWorktree(agentId) {
502
+ return this.tracker.getWorktree(agentId);
503
+ }
504
+ /**
505
+ * List all worktrees.
506
+ */
507
+ listWorktrees() {
508
+ return this.tracker.listWorktrees();
509
+ }
510
+ /**
511
+ * Update the stream associated with a worktree.
512
+ */
513
+ updateWorktreeStream(agentId, streamId) {
514
+ this.tracker.updateWorktreeStream(agentId, streamId);
515
+ }
516
+ /**
517
+ * Deallocate a worktree.
518
+ */
519
+ deallocateWorktree(agentId) {
520
+ this.tracker.deallocateWorktree(agentId);
521
+ this.emit('worktree:deallocated', { agentId });
522
+ }
523
+ // ─────────────────────────────────────────────────────────────────────────────
524
+ // Worker Task Operations
525
+ // ─────────────────────────────────────────────────────────────────────────────
526
+ /**
527
+ * Create a worker task under a stream.
528
+ *
529
+ * @param options - Task creation options
530
+ * @returns Task ID
531
+ */
532
+ createTask(options) {
533
+ const taskId = this.tracker.createTask(options);
534
+ this.emit('task:created', { taskId, ...options });
535
+ return taskId;
536
+ }
537
+ /**
538
+ * Get a task by ID.
539
+ */
540
+ getTask(taskId) {
541
+ return this.tracker.getTask(taskId);
542
+ }
543
+ /**
544
+ * List tasks for a stream.
545
+ */
546
+ listTasks(streamId, options) {
547
+ return this.tracker.listTasks(streamId, options);
548
+ }
549
+ /**
550
+ * Start a task - assigns agent and creates worker branch.
551
+ *
552
+ * @param options - Start task options
553
+ * @returns Branch name and start commit
554
+ */
555
+ startTask(options) {
556
+ const result = this.tracker.startTask(options);
557
+ this.emit('task:started', {
558
+ taskId: options.taskId,
559
+ agentId: options.agentId,
560
+ branchName: result.branchName,
561
+ startCommit: result.startCommit,
562
+ });
563
+ return result;
564
+ }
565
+ /**
566
+ * Complete a task - merges worker branch to stream.
567
+ *
568
+ * @param options - Complete task options
569
+ * @returns Merge result
570
+ */
571
+ completeTask(options) {
572
+ const result = this.tracker.completeTask(options);
573
+ this.emit('task:completed', { taskId: options.taskId, ...result });
574
+ return result;
575
+ }
576
+ /**
577
+ * Abandon a task.
578
+ *
579
+ * @param taskId - Task ID
580
+ * @param options - Options
581
+ */
582
+ abandonTask(taskId, options) {
583
+ this.tracker.abandonTask(taskId, options);
584
+ this.emit('task:abandoned', { taskId, ...options });
585
+ }
586
+ /**
587
+ * Release a task back to 'open' status.
588
+ */
589
+ releaseTask(taskId) {
590
+ this.tracker.releaseTask(taskId);
591
+ }
592
+ /**
593
+ * Detect conflicts for a task before completing.
594
+ *
595
+ * @param taskId - Task ID
596
+ * @param worktree - Worktree path
597
+ * @returns Array of conflicting file paths, empty if no conflicts
598
+ */
599
+ detectTaskConflicts(taskId, worktree) {
600
+ return workerTasks.detectTaskConflicts(this.tracker.db, this.config.repoPath, taskId, worktree);
601
+ }
602
+ /**
603
+ * Recover stale tasks that have been in_progress too long.
604
+ *
605
+ * @param thresholdMs - Tasks older than this are considered stale
606
+ * @returns Result with released task IDs
607
+ */
608
+ recoverStaleTasks(thresholdMs = 60 * 60 * 1000) {
609
+ return workerTasks.recoverStaleTasks(this.tracker.db, thresholdMs);
610
+ }
611
+ // ─────────────────────────────────────────────────────────────────────────────
612
+ // Checkpoint Operations
613
+ // ─────────────────────────────────────────────────────────────────────────────
614
+ /**
615
+ * Create checkpoints for commits made during a task.
616
+ *
617
+ * Creates a checkpoint for each commit between the task's startCommit and
618
+ * the current HEAD of the task's stream. This captures the work done during
619
+ * the task for future review and merge workflows.
620
+ *
621
+ * @param taskId - Task ID to create checkpoints for
622
+ * @param agentId - Agent ID (used as createdBy)
623
+ * @returns Array of created checkpoints
624
+ */
625
+ createCheckpointsForTask(taskId, agentId) {
626
+ const task = this.getTask(taskId);
627
+ if (!task) {
628
+ console.warn(`[GitCascadeAdapter] Task not found: ${taskId}`);
629
+ return [];
630
+ }
631
+ if (!task.streamId) {
632
+ console.warn(`[GitCascadeAdapter] Task ${taskId} has no streamId`);
633
+ return [];
634
+ }
635
+ if (!task.startCommit) {
636
+ console.warn(`[GitCascadeAdapter] Task ${taskId} has no startCommit`);
637
+ return [];
638
+ }
639
+ try {
640
+ // Create checkpoints from task's startCommit to stream's current HEAD
641
+ const checkpoints = diffStacks.createCheckpointsFromStream(this.tracker.db, this.config.repoPath, task.streamId, {
642
+ from: task.startCommit,
643
+ createdBy: agentId,
644
+ });
645
+ return checkpoints;
646
+ }
647
+ catch (error) {
648
+ console.error(`[GitCascadeAdapter] Failed to create checkpoints for task ${taskId}:`, error);
649
+ return [];
650
+ }
651
+ }
652
+ // ─────────────────────────────────────────────────────────────────────────────
653
+ // Commit Operations
654
+ // ─────────────────────────────────────────────────────────────────────────────
655
+ /**
656
+ * Commit changes in a worktree with Change tracking.
657
+ *
658
+ * @param options - Commit options
659
+ * @returns Commit hash and change ID
660
+ */
661
+ commitChanges(options) {
662
+ return this.tracker.commitChanges(options);
663
+ }
664
+ // ─────────────────────────────────────────────────────────────────────────────
665
+ // Maintenance Operations
666
+ // ─────────────────────────────────────────────────────────────────────────────
667
+ /**
668
+ * Clean up old worker branches.
669
+ *
670
+ * Deletes branches for:
671
+ * - Completed tasks older than threshold (default 24h)
672
+ * - Abandoned tasks
673
+ * - Orphaned branches (no task record)
674
+ *
675
+ * @param options - Cleanup options
676
+ * @returns Deleted branches and any errors
677
+ */
678
+ cleanupWorkerBranches(options) {
679
+ return workerTasks.cleanupWorkerBranches(this.tracker.db, this.config.repoPath, options);
680
+ }
681
+ /**
682
+ * Delete a specific worker branch.
683
+ *
684
+ * @param branchName - Branch name to delete
685
+ * @returns true if deleted, false if branch didn't exist
686
+ */
687
+ deleteWorkerBranch(branchName) {
688
+ try {
689
+ const { execSync } = require('child_process');
690
+ execSync(`git branch -D "${branchName}"`, {
691
+ cwd: this.config.repoPath,
692
+ stdio: 'pipe',
693
+ });
694
+ return true;
695
+ }
696
+ catch {
697
+ return false;
698
+ }
699
+ }
700
+ // ─────────────────────────────────────────────────────────────────────────────
701
+ // Change Operations (Change-Id tracking)
702
+ // ─────────────────────────────────────────────────────────────────────────────
703
+ /**
704
+ * Get a change by ID.
705
+ */
706
+ getChange(changeId) {
707
+ return this.tracker.getChange(changeId);
708
+ }
709
+ /**
710
+ * Get a change by its current commit hash.
711
+ */
712
+ getChangeByCommit(commit) {
713
+ return this.tracker.getChangeByCommit(commit);
714
+ }
715
+ /**
716
+ * Get a change by any of its historical commit hashes (survives rebases).
717
+ */
718
+ getChangeByHistoricalCommit(commit) {
719
+ return this.tracker.getChangeByHistoricalCommit(commit);
720
+ }
721
+ /**
722
+ * List changes for a stream, optionally filtered by status.
723
+ */
724
+ getChangesForStream(streamId, options) {
725
+ return this.tracker.getChangesForStream(streamId, options);
726
+ }
727
+ /**
728
+ * Mark changes as merged.
729
+ */
730
+ markChangesMerged(changeIds) {
731
+ this.tracker.markChangesMerged(changeIds);
732
+ for (const id of changeIds) {
733
+ this.emit('change:merged', { changeId: id });
734
+ }
735
+ }
736
+ /**
737
+ * Mark a single change as dropped.
738
+ */
739
+ markChangeDropped(changeId) {
740
+ this.tracker.markChangeDropped(changeId);
741
+ this.emit('change:dropped', { changeId });
742
+ }
743
+ // ─────────────────────────────────────────────────────────────────────────────
744
+ // Merge Queue (git-cascade built-in)
745
+ // ─────────────────────────────────────────────────────────────────────────────
746
+ /**
747
+ * Add a stream to the merge queue. Local `mergeQueue:added` event fires
748
+ * via forwardCascadeEvent (git-cascade 0.0.7+ emits queue.added natively).
749
+ */
750
+ addToMergeQueue(options) {
751
+ return this.tracker.addToMergeQueue(options);
752
+ }
753
+ /**
754
+ * Get a merge queue entry by id.
755
+ */
756
+ getMergeQueueEntry(entryId) {
757
+ return this.tracker.getMergeQueueEntry(entryId);
758
+ }
759
+ /**
760
+ * List merge queue entries with optional filters.
761
+ */
762
+ listMergeQueue(options) {
763
+ return this.tracker.getMergeQueue(options);
764
+ }
765
+ /**
766
+ * Mark a queue entry as ready to merge. Local `mergeQueue:ready` event
767
+ * fires via forwardCascadeEvent (git-cascade 0.0.7+).
768
+ */
769
+ markMergeQueueReady(entryId) {
770
+ this.tracker.markMergeQueueReady(entryId);
771
+ }
772
+ /**
773
+ * Cancel a queue entry. Local `mergeQueue:cancelled` event fires via
774
+ * forwardCascadeEvent (git-cascade 0.0.7+).
775
+ */
776
+ cancelMergeQueueEntry(entryId) {
777
+ this.tracker.cancelMergeQueueEntry(entryId);
778
+ }
779
+ /**
780
+ * Remove a queue entry. Local `mergeQueue:removed` event fires via
781
+ * forwardCascadeEvent (git-cascade 0.0.7+).
782
+ */
783
+ removeFromMergeQueue(entryId) {
784
+ this.tracker.removeFromMergeQueue(entryId);
785
+ }
786
+ /**
787
+ * Get the next entry to process for a target branch.
788
+ */
789
+ getNextToMerge(targetBranch) {
790
+ return this.tracker.getNextToMerge(targetBranch);
791
+ }
792
+ /**
793
+ * Process the merge queue — drains ready entries per provided handler.
794
+ */
795
+ processMergeQueue(options) {
796
+ return this.tracker.processMergeQueue(options);
797
+ }
798
+ /**
799
+ * Get a stream's position in the queue (lower = sooner).
800
+ */
801
+ getMergeQueuePosition(streamId, targetBranch) {
802
+ return this.tracker.getMergeQueuePosition(streamId, targetBranch);
803
+ }
804
+ // ─────────────────────────────────────────────────────────────────────────────
805
+ // Conflict Operations
806
+ // ─────────────────────────────────────────────────────────────────────────────
807
+ /**
808
+ * Create a conflict record.
809
+ *
810
+ * Usually conflicts are created implicitly by merge/rebase operations.
811
+ * This is for explicit creation (e.g., an external process detected a
812
+ * conflict that git-cascade didn't).
813
+ */
814
+ createConflict(options) {
815
+ const id = this.tracker.createConflict(options);
816
+ this.emit('conflict:created', {
817
+ conflictId: id,
818
+ streamId: options.streamId,
819
+ });
820
+ return id;
821
+ }
822
+ /**
823
+ * Get a conflict record by id.
824
+ */
825
+ getConflict(conflictId) {
826
+ return this.tracker.getConflict(conflictId);
827
+ }
828
+ /**
829
+ * Get the active conflict record for a stream, if any.
830
+ */
831
+ getConflictForStream(streamId) {
832
+ return this.tracker.getConflictForStream(streamId);
833
+ }
834
+ /**
835
+ * Emit a `stream:pushed` event for trunk-style landing strategies that push
836
+ * to a remote rather than merging into another stream. Strategies call this
837
+ * after a successful push so observers (the OpenHive cascade-bridge) can
838
+ * surface the push as `x-cascade/stream.pushed`.
839
+ */
840
+ notifyStreamPushed(args) {
841
+ this.emit('stream:pushed', {
842
+ streamId: args.streamId,
843
+ agentId: args.agentId,
844
+ pushedCommit: args.pushedCommit,
845
+ remote: args.remote,
846
+ remoteRef: args.remoteRef,
847
+ strategy: args.strategy,
848
+ metadata: args.metadata,
849
+ });
850
+ }
851
+ /**
852
+ * Mark a conflict as resolved. Routes through git-cascade's tracker so
853
+ * `x-cascade/stream.conflict_resolved` fires for hub observers (closes
854
+ * cascade_conflicts.status from pending → resolved on the OpenHive side).
855
+ */
856
+ resolveConflict(args) {
857
+ this.tracker.resolveConflict(args.conflictId, args.resolution, {
858
+ metadata: args.metadata,
859
+ });
860
+ }
861
+ /**
862
+ * Abandon a conflict (stream-level give-up). Emits a
863
+ * `stream.conflict_resolved` event with method='abandoned' so observers
864
+ * see the conflict is no longer pending.
865
+ */
866
+ abandonConflict(args) {
867
+ this.tracker.abandonConflict(args.conflictId, {
868
+ agentId: args.agentId,
869
+ reason: args.reason,
870
+ metadata: args.metadata,
871
+ });
872
+ }
873
+ // ─────────────────────────────────────────────────────────────────────────────
874
+ // Reconciliation
875
+ // ─────────────────────────────────────────────────────────────────────────────
876
+ /**
877
+ * Check if a stream's database state is in sync with its git branch.
878
+ */
879
+ checkStreamSync(streamId) {
880
+ return this.tracker.checkStreamSync(streamId);
881
+ }
882
+ /**
883
+ * Check all active streams for sync status.
884
+ */
885
+ checkAllStreamsSync(options) {
886
+ return this.tracker.checkAllStreamsSync(options);
887
+ }
888
+ /**
889
+ * Reconcile database state with git state. Fixes missing branches, resets
890
+ * diverged HEAD (per options), etc. Does NOT handle orphan worktrees — the
891
+ * macro-agent-level reconcile wrapper covers that.
892
+ */
893
+ reconcile(options) {
894
+ return this.tracker.reconcile(options);
895
+ }
896
+ /**
897
+ * Ensure a stream is in sync before performing an operation.
898
+ * @throws DesyncError if out of sync unless `force: true`.
899
+ */
900
+ ensureStreamInSync(streamId, options) {
901
+ this.tracker.ensureStreamInSync(streamId, options);
902
+ }
903
+ // ─────────────────────────────────────────────────────────────────────────────
904
+ // Health & Recovery
905
+ // ─────────────────────────────────────────────────────────────────────────────
906
+ /**
907
+ * Check system health.
908
+ */
909
+ healthCheck() {
910
+ return this.tracker.healthCheck();
911
+ }
912
+ // ─────────────────────────────────────────────────────────────────────────────
913
+ // Lifecycle
914
+ // ─────────────────────────────────────────────────────────────────────────────
915
+ /**
916
+ * Close the adapter and release resources.
917
+ *
918
+ * Only closes the database if we created it (not if using shared DB).
919
+ */
920
+ close() {
921
+ this.eventListeners.clear();
922
+ this.tracker.close();
923
+ }
924
+ }
925
+ /**
926
+ * Create a GitCascadeAdapter instance.
927
+ *
928
+ * @param config - Configuration options
929
+ * @returns GitCascadeAdapter instance
930
+ */
931
+ export function createGitCascadeAdapter(config) {
932
+ return new GitCascadeAdapter(config);
933
+ }
934
+ //# sourceMappingURL=git-cascade-adapter.js.map