ccjk 12.0.7 → 12.0.8

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 (299) hide show
  1. package/package.json +1 -1
  2. package/dist/chunks/agent-teams.mjs +0 -136
  3. package/dist/chunks/agent.mjs +0 -1439
  4. package/dist/chunks/agents.mjs +0 -3778
  5. package/dist/chunks/api-cli.mjs +0 -132
  6. package/dist/chunks/api-providers.mjs +0 -129
  7. package/dist/chunks/api.mjs +0 -112
  8. package/dist/chunks/auto-bootstrap.mjs +0 -358
  9. package/dist/chunks/auto-init.mjs +0 -7584
  10. package/dist/chunks/auto-updater.mjs +0 -410
  11. package/dist/chunks/banner.mjs +0 -188
  12. package/dist/chunks/bash.mjs +0 -187
  13. package/dist/chunks/boost.mjs +0 -397
  14. package/dist/chunks/ccjk-agents.mjs +0 -414
  15. package/dist/chunks/ccjk-all.mjs +0 -1028
  16. package/dist/chunks/ccjk-config.mjs +0 -261
  17. package/dist/chunks/ccjk-hooks.mjs +0 -1074
  18. package/dist/chunks/ccjk-mcp.mjs +0 -761
  19. package/dist/chunks/ccjk-setup.mjs +0 -763
  20. package/dist/chunks/ccjk-skills.mjs +0 -514
  21. package/dist/chunks/ccr.mjs +0 -98
  22. package/dist/chunks/ccu.mjs +0 -40
  23. package/dist/chunks/check-updates.mjs +0 -108
  24. package/dist/chunks/claude-code-config-manager.mjs +0 -750
  25. package/dist/chunks/claude-code-incremental-manager.mjs +0 -623
  26. package/dist/chunks/claude-config.mjs +0 -236
  27. package/dist/chunks/claude-wrapper.mjs +0 -85
  28. package/dist/chunks/cleanup-migration.mjs +0 -20
  29. package/dist/chunks/cli-hook.mjs +0 -2285
  30. package/dist/chunks/cloud-sync.mjs +0 -29
  31. package/dist/chunks/codex-config-switch.mjs +0 -451
  32. package/dist/chunks/codex-provider-manager.mjs +0 -236
  33. package/dist/chunks/codex-uninstaller.mjs +0 -404
  34. package/dist/chunks/codex.mjs +0 -2077
  35. package/dist/chunks/commands.mjs +0 -108
  36. package/dist/chunks/commands2.mjs +0 -413
  37. package/dist/chunks/commit.mjs +0 -138
  38. package/dist/chunks/completion.mjs +0 -515
  39. package/dist/chunks/config-consolidator.mjs +0 -172
  40. package/dist/chunks/config-switch.mjs +0 -317
  41. package/dist/chunks/config.mjs +0 -379
  42. package/dist/chunks/config2.mjs +0 -477
  43. package/dist/chunks/config3.mjs +0 -470
  44. package/dist/chunks/constants.mjs +0 -133
  45. package/dist/chunks/context-loader.mjs +0 -343
  46. package/dist/chunks/context.mjs +0 -372
  47. package/dist/chunks/convoy-manager.mjs +0 -880
  48. package/dist/chunks/dashboard.mjs +0 -476
  49. package/dist/chunks/doctor.mjs +0 -964
  50. package/dist/chunks/evolution.mjs +0 -382
  51. package/dist/chunks/features.mjs +0 -698
  52. package/dist/chunks/fish.mjs +0 -181
  53. package/dist/chunks/fs-operations.mjs +0 -192
  54. package/dist/chunks/health-alerts.mjs +0 -304
  55. package/dist/chunks/health-check.mjs +0 -532
  56. package/dist/chunks/help.mjs +0 -340
  57. package/dist/chunks/hook-installer.mjs +0 -45
  58. package/dist/chunks/index.mjs +0 -24
  59. package/dist/chunks/index10.mjs +0 -1171
  60. package/dist/chunks/index11.mjs +0 -1008
  61. package/dist/chunks/index12.mjs +0 -193
  62. package/dist/chunks/index13.mjs +0 -218
  63. package/dist/chunks/index14.mjs +0 -663
  64. package/dist/chunks/index2.mjs +0 -19
  65. package/dist/chunks/index3.mjs +0 -19092
  66. package/dist/chunks/index4.mjs +0 -8
  67. package/dist/chunks/index5.mjs +0 -7600
  68. package/dist/chunks/index6.mjs +0 -171
  69. package/dist/chunks/index7.mjs +0 -3583
  70. package/dist/chunks/index8.mjs +0 -19
  71. package/dist/chunks/index9.mjs +0 -616
  72. package/dist/chunks/init.mjs +0 -1606
  73. package/dist/chunks/installer.mjs +0 -690
  74. package/dist/chunks/installer2.mjs +0 -179
  75. package/dist/chunks/interview.mjs +0 -2927
  76. package/dist/chunks/json-config.mjs +0 -60
  77. package/dist/chunks/linux.mjs +0 -3863
  78. package/dist/chunks/macos.mjs +0 -69
  79. package/dist/chunks/main.mjs +0 -635
  80. package/dist/chunks/manager.mjs +0 -1048
  81. package/dist/chunks/marketplace.mjs +0 -949
  82. package/dist/chunks/mcp-cli.mjs +0 -204
  83. package/dist/chunks/mcp-performance.mjs +0 -187
  84. package/dist/chunks/mcp.mjs +0 -1231
  85. package/dist/chunks/menu.mjs +0 -652
  86. package/dist/chunks/metrics-display.mjs +0 -153
  87. package/dist/chunks/migrator.mjs +0 -178
  88. package/dist/chunks/monitor.mjs +0 -1856
  89. package/dist/chunks/notification.mjs +0 -1864
  90. package/dist/chunks/onboarding.mjs +0 -385
  91. package/dist/chunks/package.mjs +0 -3
  92. package/dist/chunks/paradigm.mjs +0 -74
  93. package/dist/chunks/permission-manager.mjs +0 -132
  94. package/dist/chunks/permissions.mjs +0 -265
  95. package/dist/chunks/persistence-manager.mjs +0 -794
  96. package/dist/chunks/persistence.mjs +0 -667
  97. package/dist/chunks/platform.mjs +0 -391
  98. package/dist/chunks/plugin.mjs +0 -1936
  99. package/dist/chunks/powershell.mjs +0 -213
  100. package/dist/chunks/prompts.mjs +0 -241
  101. package/dist/chunks/providers.mjs +0 -260
  102. package/dist/chunks/quick-actions.mjs +0 -320
  103. package/dist/chunks/quick-provider.mjs +0 -682
  104. package/dist/chunks/quick-setup.mjs +0 -412
  105. package/dist/chunks/remote.mjs +0 -497
  106. package/dist/chunks/session.mjs +0 -878
  107. package/dist/chunks/sessions.mjs +0 -106
  108. package/dist/chunks/silent-updater.mjs +0 -396
  109. package/dist/chunks/simple-config.mjs +0 -98
  110. package/dist/chunks/skill.mjs +0 -117
  111. package/dist/chunks/skill2.mjs +0 -9003
  112. package/dist/chunks/skills-sync.mjs +0 -6460
  113. package/dist/chunks/skills.mjs +0 -567
  114. package/dist/chunks/slash-commands.mjs +0 -207
  115. package/dist/chunks/smart-defaults.mjs +0 -412
  116. package/dist/chunks/smart-guide.mjs +0 -194
  117. package/dist/chunks/startup.mjs +0 -487
  118. package/dist/chunks/stats.mjs +0 -410
  119. package/dist/chunks/status.mjs +0 -289
  120. package/dist/chunks/team.mjs +0 -63
  121. package/dist/chunks/thinking.mjs +0 -626
  122. package/dist/chunks/trace.mjs +0 -57
  123. package/dist/chunks/uninstall.mjs +0 -849
  124. package/dist/chunks/update.mjs +0 -167
  125. package/dist/chunks/upgrade-manager.mjs +0 -204
  126. package/dist/chunks/version-checker.mjs +0 -881
  127. package/dist/chunks/vim.mjs +0 -903
  128. package/dist/chunks/windows.mjs +0 -14
  129. package/dist/chunks/workflows.mjs +0 -633
  130. package/dist/chunks/wsl.mjs +0 -129
  131. package/dist/chunks/zero-config.mjs +0 -374
  132. package/dist/chunks/zsh.mjs +0 -182
  133. package/dist/cli.d.mts +0 -1
  134. package/dist/cli.d.ts +0 -1
  135. package/dist/cli.mjs +0 -2199
  136. package/dist/i18n/locales/en/agent-teams.json +0 -18
  137. package/dist/i18n/locales/en/agentBrowser.json +0 -79
  138. package/dist/i18n/locales/en/agents.json +0 -135
  139. package/dist/i18n/locales/en/api.json +0 -63
  140. package/dist/i18n/locales/en/ccjk-agents.json +0 -33
  141. package/dist/i18n/locales/en/ccjk-all.json +0 -23
  142. package/dist/i18n/locales/en/ccjk-skills.json +0 -22
  143. package/dist/i18n/locales/en/ccjk.json +0 -276
  144. package/dist/i18n/locales/en/ccr.json +0 -65
  145. package/dist/i18n/locales/en/claude-md.json +0 -73
  146. package/dist/i18n/locales/en/cli.json +0 -152
  147. package/dist/i18n/locales/en/cloud-setup.json +0 -31
  148. package/dist/i18n/locales/en/cloud-sync.json +0 -147
  149. package/dist/i18n/locales/en/cloud.json +0 -40
  150. package/dist/i18n/locales/en/cloudPlugins.json +0 -118
  151. package/dist/i18n/locales/en/codex.json +0 -127
  152. package/dist/i18n/locales/en/cometix.json +0 -29
  153. package/dist/i18n/locales/en/common.json +0 -68
  154. package/dist/i18n/locales/en/config.json +0 -108
  155. package/dist/i18n/locales/en/configuration.json +0 -226
  156. package/dist/i18n/locales/en/context.json +0 -85
  157. package/dist/i18n/locales/en/dashboard.json +0 -78
  158. package/dist/i18n/locales/en/errors.json +0 -26
  159. package/dist/i18n/locales/en/evolution.json +0 -54
  160. package/dist/i18n/locales/en/hooks.json +0 -74
  161. package/dist/i18n/locales/en/hooksSync.json +0 -133
  162. package/dist/i18n/locales/en/installation.json +0 -83
  163. package/dist/i18n/locales/en/interview.json +0 -104
  164. package/dist/i18n/locales/en/language.json +0 -19
  165. package/dist/i18n/locales/en/lsp.json +0 -78
  166. package/dist/i18n/locales/en/marketplace.json +0 -116
  167. package/dist/i18n/locales/en/mcp.json +0 -178
  168. package/dist/i18n/locales/en/memory.json +0 -92
  169. package/dist/i18n/locales/en/menu.json +0 -143
  170. package/dist/i18n/locales/en/multi-config.json +0 -79
  171. package/dist/i18n/locales/en/notification.json +0 -307
  172. package/dist/i18n/locales/en/permissions.json +0 -95
  173. package/dist/i18n/locales/en/persistence.json +0 -127
  174. package/dist/i18n/locales/en/plugins.json +0 -146
  175. package/dist/i18n/locales/en/quick-actions.json +0 -78
  176. package/dist/i18n/locales/en/registry.json +0 -54
  177. package/dist/i18n/locales/en/remote.json +0 -93
  178. package/dist/i18n/locales/en/sandbox.json +0 -44
  179. package/dist/i18n/locales/en/setup.json +0 -44
  180. package/dist/i18n/locales/en/shencha.json +0 -14
  181. package/dist/i18n/locales/en/skills.json +0 -100
  182. package/dist/i18n/locales/en/skillsSync.json +0 -74
  183. package/dist/i18n/locales/en/smartGuide.json +0 -49
  184. package/dist/i18n/locales/en/stats.json +0 -20
  185. package/dist/i18n/locales/en/subagent.json +0 -69
  186. package/dist/i18n/locales/en/superpowers.json +0 -117
  187. package/dist/i18n/locales/en/team.json +0 -7
  188. package/dist/i18n/locales/en/thinking.json +0 -65
  189. package/dist/i18n/locales/en/tools.json +0 -42
  190. package/dist/i18n/locales/en/uninstall.json +0 -56
  191. package/dist/i18n/locales/en/updater.json +0 -29
  192. package/dist/i18n/locales/en/vim.json +0 -169
  193. package/dist/i18n/locales/en/workflow.json +0 -55
  194. package/dist/i18n/locales/en/workspace.json +0 -108
  195. package/dist/i18n/locales/zh-CN/agent-teams.json +0 -18
  196. package/dist/i18n/locales/zh-CN/agentBrowser.json +0 -79
  197. package/dist/i18n/locales/zh-CN/agents.json +0 -135
  198. package/dist/i18n/locales/zh-CN/api.json +0 -63
  199. package/dist/i18n/locales/zh-CN/ccjk-agents.json +0 -33
  200. package/dist/i18n/locales/zh-CN/ccjk-all.json +0 -23
  201. package/dist/i18n/locales/zh-CN/ccjk-skills.json +0 -22
  202. package/dist/i18n/locales/zh-CN/ccjk.json +0 -276
  203. package/dist/i18n/locales/zh-CN/ccr.json +0 -65
  204. package/dist/i18n/locales/zh-CN/claude-md.json +0 -73
  205. package/dist/i18n/locales/zh-CN/cli.json +0 -152
  206. package/dist/i18n/locales/zh-CN/cloud-setup.json +0 -31
  207. package/dist/i18n/locales/zh-CN/cloud-sync.json +0 -147
  208. package/dist/i18n/locales/zh-CN/cloud.json +0 -40
  209. package/dist/i18n/locales/zh-CN/cloudPlugins.json +0 -118
  210. package/dist/i18n/locales/zh-CN/codex.json +0 -127
  211. package/dist/i18n/locales/zh-CN/cometix.json +0 -29
  212. package/dist/i18n/locales/zh-CN/common.json +0 -68
  213. package/dist/i18n/locales/zh-CN/config.json +0 -108
  214. package/dist/i18n/locales/zh-CN/configuration.json +0 -224
  215. package/dist/i18n/locales/zh-CN/context.json +0 -85
  216. package/dist/i18n/locales/zh-CN/dashboard.json +0 -78
  217. package/dist/i18n/locales/zh-CN/errors.json +0 -26
  218. package/dist/i18n/locales/zh-CN/evolution.json +0 -54
  219. package/dist/i18n/locales/zh-CN/hooks.json +0 -74
  220. package/dist/i18n/locales/zh-CN/hooksSync.json +0 -133
  221. package/dist/i18n/locales/zh-CN/installation.json +0 -83
  222. package/dist/i18n/locales/zh-CN/interview.json +0 -104
  223. package/dist/i18n/locales/zh-CN/language.json +0 -19
  224. package/dist/i18n/locales/zh-CN/lsp.json +0 -78
  225. package/dist/i18n/locales/zh-CN/marketplace.json +0 -116
  226. package/dist/i18n/locales/zh-CN/mcp.json +0 -178
  227. package/dist/i18n/locales/zh-CN/memory.json +0 -92
  228. package/dist/i18n/locales/zh-CN/menu.json +0 -143
  229. package/dist/i18n/locales/zh-CN/multi-config.json +0 -79
  230. package/dist/i18n/locales/zh-CN/notification.json +0 -307
  231. package/dist/i18n/locales/zh-CN/permissions.json +0 -95
  232. package/dist/i18n/locales/zh-CN/persistence.json +0 -127
  233. package/dist/i18n/locales/zh-CN/plugins.json +0 -146
  234. package/dist/i18n/locales/zh-CN/quick-actions.json +0 -78
  235. package/dist/i18n/locales/zh-CN/registry.json +0 -54
  236. package/dist/i18n/locales/zh-CN/remote.json +0 -93
  237. package/dist/i18n/locales/zh-CN/sandbox.json +0 -44
  238. package/dist/i18n/locales/zh-CN/setup.json +0 -44
  239. package/dist/i18n/locales/zh-CN/shencha.json +0 -14
  240. package/dist/i18n/locales/zh-CN/skills.json +0 -100
  241. package/dist/i18n/locales/zh-CN/skillsSync.json +0 -74
  242. package/dist/i18n/locales/zh-CN/smartGuide.json +0 -49
  243. package/dist/i18n/locales/zh-CN/stats.json +0 -20
  244. package/dist/i18n/locales/zh-CN/subagent.json +0 -69
  245. package/dist/i18n/locales/zh-CN/superpowers.json +0 -117
  246. package/dist/i18n/locales/zh-CN/team.json +0 -7
  247. package/dist/i18n/locales/zh-CN/thinking.json +0 -65
  248. package/dist/i18n/locales/zh-CN/tools.json +0 -42
  249. package/dist/i18n/locales/zh-CN/uninstall.json +0 -56
  250. package/dist/i18n/locales/zh-CN/updater.json +0 -29
  251. package/dist/i18n/locales/zh-CN/vim.json +0 -169
  252. package/dist/i18n/locales/zh-CN/workflow.json +0 -55
  253. package/dist/i18n/locales/zh-CN/workspace.json +0 -108
  254. package/dist/index.d.mts +0 -5295
  255. package/dist/index.d.ts +0 -5295
  256. package/dist/index.mjs +0 -4941
  257. package/dist/shared/ccjk.B364Fu0N.mjs +0 -1819
  258. package/dist/shared/ccjk.BAGoDD49.mjs +0 -36
  259. package/dist/shared/ccjk.BBtCGd_g.mjs +0 -899
  260. package/dist/shared/ccjk.BFQ7yr5S.mjs +0 -16
  261. package/dist/shared/ccjk.BFxsJM0k.mjs +0 -599
  262. package/dist/shared/ccjk.BIxuVL3_.mjs +0 -25
  263. package/dist/shared/ccjk.BRZ9ww8S.mjs +0 -142
  264. package/dist/shared/ccjk.BoApaI4j.mjs +0 -28
  265. package/dist/shared/ccjk.BrPUmTqm.mjs +0 -266
  266. package/dist/shared/ccjk.BtB1e5jm.mjs +0 -171
  267. package/dist/shared/ccjk.BwfbSKN2.mjs +0 -1051
  268. package/dist/shared/ccjk.BxSmJ8B7.mjs +0 -243
  269. package/dist/shared/ccjk.Bx_rmYfN.mjs +0 -69
  270. package/dist/shared/ccjk.C2jHOZVP.mjs +0 -52
  271. package/dist/shared/ccjk.CL4Yat0G.mjs +0 -303
  272. package/dist/shared/ccjk.COweQ1RR.mjs +0 -5
  273. package/dist/shared/ccjk.CePkJq2S.mjs +0 -223
  274. package/dist/shared/ccjk.CfKKcvWy.mjs +0 -126
  275. package/dist/shared/ccjk.Cjgrln_h.mjs +0 -297
  276. package/dist/shared/ccjk.Cjj8SVrn.mjs +0 -54
  277. package/dist/shared/ccjk.CxpGa6MC.mjs +0 -2724
  278. package/dist/shared/ccjk.D5MFQT7w.mjs +0 -400
  279. package/dist/shared/ccjk.D6ycHbak.mjs +0 -270
  280. package/dist/shared/ccjk.D8ZLYSZZ.mjs +0 -299
  281. package/dist/shared/ccjk.DG_o24cZ.mjs +0 -88
  282. package/dist/shared/ccjk.DLLw-h4Y.mjs +0 -460
  283. package/dist/shared/ccjk.DOwtZMk8.mjs +0 -4019
  284. package/dist/shared/ccjk.DS7UESmF.mjs +0 -2451
  285. package/dist/shared/ccjk.DTdjs-qK.mjs +0 -1447
  286. package/dist/shared/ccjk.DXRAZcix.mjs +0 -66
  287. package/dist/shared/ccjk.DsYaCCx4.mjs +0 -317
  288. package/dist/shared/ccjk.J8YiPsOw.mjs +0 -259
  289. package/dist/shared/ccjk.KfSWcGlE.mjs +0 -38
  290. package/dist/shared/ccjk.RyizuzOI.mjs +0 -21
  291. package/dist/shared/ccjk.SPoXMvZD.mjs +0 -1242
  292. package/dist/shared/ccjk.T_cX87dY.mjs +0 -15
  293. package/dist/shared/ccjk.UIvifqNE.mjs +0 -1486
  294. package/dist/shared/ccjk._dESH4Rk.mjs +0 -111
  295. package/dist/shared/ccjk.bQ7Dh1g4.mjs +0 -249
  296. package/dist/shared/ccjk.c-ETfBZ_.mjs +0 -617
  297. package/dist/shared/ccjk.gDEDGD_t.mjs +0 -38
  298. package/dist/shared/ccjk.hoqrwWdN.mjs +0 -333
  299. package/dist/shared/ccjk.waa2ikKJ.mjs +0 -351
@@ -1,880 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { n as nanoid } from '../shared/ccjk.BoApaI4j.mjs';
3
- import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs';
4
- import { homedir } from 'node:os';
5
- import { x as K } from './main.mjs';
6
- import { j as join } from '../shared/ccjk.bQ7Dh1g4.mjs';
7
-
8
- class GitBackedStateManager extends EventEmitter {
9
- config;
10
- worktrees = /* @__PURE__ */ new Map();
11
- initialized = false;
12
- pendingCommits = /* @__PURE__ */ new Map();
13
- constructor(config = {}) {
14
- super();
15
- this.config = {
16
- workspaceRoot: config.workspaceRoot ?? join(homedir(), ".ccjk", "workspace"),
17
- useWorktrees: config.useWorktrees ?? true,
18
- autoCommit: config.autoCommit ?? true,
19
- compressionLevel: config.compressionLevel ?? 6,
20
- verbose: config.verbose ?? false,
21
- commitBatchInterval: config.commitBatchInterval ?? 1e3
22
- };
23
- }
24
- /**
25
- * Initialize the workspace with Git
26
- */
27
- async initialize() {
28
- if (this.initialized)
29
- return;
30
- const { workspaceRoot } = this.config;
31
- try {
32
- if (!existsSync(workspaceRoot)) {
33
- mkdirSync(workspaceRoot, { recursive: true });
34
- this.log(`Created workspace: ${workspaceRoot}`);
35
- }
36
- const gitDir = join(workspaceRoot, ".git");
37
- if (!existsSync(gitDir)) {
38
- await this.exec("git", ["init"], workspaceRoot);
39
- this.log("Initialized Git repository");
40
- const gitignore = `
41
- # Sensitive data
42
- *.env
43
- *.key
44
- *.pem
45
- credentials.json
46
-
47
- # Temporary files
48
- *.tmp
49
- *.log
50
- *.swp
51
-
52
- # OS files
53
- .DS_Store
54
- Thumbs.db
55
- `;
56
- writeFileSync(join(workspaceRoot, ".gitignore"), gitignore.trim());
57
- await this.exec("git", ["add", ".gitignore"], workspaceRoot);
58
- await this.exec("git", ["commit", "-m", "Initial commit"], workspaceRoot);
59
- this.log("Created initial commit");
60
- }
61
- const agentsDir = join(workspaceRoot, "agents");
62
- if (!existsSync(agentsDir)) {
63
- mkdirSync(agentsDir, { recursive: true });
64
- }
65
- await this.loadExistingWorktrees();
66
- this.initialized = true;
67
- this.emit("initialized");
68
- this.log("GitBackedStateManager initialized");
69
- } catch (error) {
70
- const err = error instanceof Error ? error : new Error(String(error));
71
- this.emit("error", err);
72
- throw err;
73
- }
74
- }
75
- /**
76
- * Create isolated worktree for agent
77
- */
78
- async createAgentWorktree(agentId) {
79
- await this.ensureInitialized();
80
- const { workspaceRoot, useWorktrees } = this.config;
81
- if (this.worktrees.has(agentId)) {
82
- return this.worktrees.get(agentId);
83
- }
84
- const agentPath = join(workspaceRoot, "agents", agentId);
85
- if (useWorktrees) {
86
- const branchName = `agent/${agentId}`;
87
- try {
88
- await this.exec("git", ["checkout", "--orphan", branchName], workspaceRoot);
89
- await this.exec("git", ["reset", "--hard"], workspaceRoot);
90
- await this.exec("git", ["checkout", "main"], workspaceRoot).catch(() => {
91
- return this.exec("git", ["checkout", "master"], workspaceRoot);
92
- });
93
- if (!existsSync(agentPath)) {
94
- await this.exec("git", ["worktree", "add", agentPath, branchName], workspaceRoot);
95
- }
96
- } catch {
97
- if (!existsSync(agentPath)) {
98
- mkdirSync(agentPath, { recursive: true });
99
- }
100
- }
101
- } else {
102
- if (!existsSync(agentPath)) {
103
- mkdirSync(agentPath, { recursive: true });
104
- }
105
- }
106
- const stateFile = join(agentPath, "state.json");
107
- const mailboxFile = join(agentPath, "mailbox.json");
108
- if (!existsSync(stateFile)) {
109
- writeFileSync(stateFile, JSON.stringify({ agentId, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
110
- }
111
- if (!existsSync(mailboxFile)) {
112
- writeFileSync(mailboxFile, JSON.stringify({ inbox: [], outbox: [], archive: [] }, null, 2));
113
- }
114
- this.worktrees.set(agentId, agentPath);
115
- this.emit("worktree:created", agentId, agentPath);
116
- this.log(`Created worktree for agent: ${agentId}`);
117
- return agentPath;
118
- }
119
- /**
120
- * Save agent state to Git
121
- */
122
- async saveState(agentId, state) {
123
- await this.ensureInitialized();
124
- const agentPath = await this.getOrCreateAgentPath(agentId);
125
- const stateFile = join(agentPath, "state.json");
126
- let existingState = {};
127
- if (existsSync(stateFile)) {
128
- try {
129
- existingState = JSON.parse(readFileSync(stateFile, "utf-8"));
130
- } catch {
131
- }
132
- }
133
- const newState = {
134
- ...existingState,
135
- ...state,
136
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
137
- };
138
- writeFileSync(stateFile, JSON.stringify(newState, null, 2));
139
- let commitId = "";
140
- if (this.config.autoCommit) {
141
- commitId = await this.batchCommit(agentId, `Update state: ${agentId}`);
142
- }
143
- this.emit("state:saved", agentId, commitId);
144
- this.log(`Saved state for agent: ${agentId}`);
145
- return commitId;
146
- }
147
- /**
148
- * Load agent state from Git
149
- */
150
- async loadState(agentId) {
151
- await this.ensureInitialized();
152
- const agentPath = this.worktrees.get(agentId);
153
- if (!agentPath) {
154
- return null;
155
- }
156
- const stateFile = join(agentPath, "state.json");
157
- if (!existsSync(stateFile)) {
158
- return null;
159
- }
160
- try {
161
- const state = JSON.parse(readFileSync(stateFile, "utf-8"));
162
- this.emit("state:loaded", agentId);
163
- this.log(`Loaded state for agent: ${agentId}`);
164
- return state;
165
- } catch {
166
- return null;
167
- }
168
- }
169
- /**
170
- * Rollback to previous state
171
- */
172
- async rollback(agentId, commitId) {
173
- await this.ensureInitialized();
174
- const agentPath = this.worktrees.get(agentId);
175
- if (!agentPath) {
176
- throw new Error(`Agent not found: ${agentId}`);
177
- }
178
- try {
179
- await this.exec("git", ["reset", "--hard", commitId], agentPath);
180
- this.emit("state:rolled-back", agentId, commitId);
181
- this.log(`Rolled back agent ${agentId} to commit ${commitId}`);
182
- } catch (error) {
183
- const err = error instanceof Error ? error : new Error(String(error));
184
- this.emit("error", err);
185
- throw err;
186
- }
187
- }
188
- /**
189
- * Get state history for agent
190
- */
191
- async getHistory(agentId, limit = 10) {
192
- await this.ensureInitialized();
193
- const agentPath = this.worktrees.get(agentId);
194
- if (!agentPath) {
195
- return [];
196
- }
197
- try {
198
- const result = await this.exec(
199
- "git",
200
- ["log", `--max-count=${limit}`, "--format=%H|%s|%ct", "--", "state.json"],
201
- agentPath
202
- );
203
- const snapshots = [];
204
- for (const line of result.stdout.split("\n").filter(Boolean)) {
205
- const [commitId, message, timestamp] = line.split("|");
206
- const stateResult = await this.exec(
207
- "git",
208
- ["show", `${commitId}:state.json`],
209
- agentPath
210
- ).catch(() => ({ stdout: "{}" }));
211
- let state;
212
- try {
213
- state = JSON.parse(stateResult.stdout);
214
- } catch {
215
- state = {};
216
- }
217
- snapshots.push({
218
- id: nanoid(),
219
- agentId,
220
- commitId,
221
- timestamp: Number.parseInt(timestamp, 10) * 1e3,
222
- message,
223
- state
224
- });
225
- }
226
- return snapshots;
227
- } catch {
228
- return [];
229
- }
230
- }
231
- /**
232
- * Cleanup agent worktree
233
- */
234
- async cleanup(agentId) {
235
- await this.ensureInitialized();
236
- const agentPath = this.worktrees.get(agentId);
237
- if (!agentPath) {
238
- return;
239
- }
240
- try {
241
- if (this.config.useWorktrees) {
242
- await this.exec("git", ["worktree", "remove", agentPath, "--force"], this.config.workspaceRoot);
243
- }
244
- this.worktrees.delete(agentId);
245
- this.emit("worktree:removed", agentId);
246
- this.log(`Cleaned up worktree for agent: ${agentId}`);
247
- } catch (error) {
248
- const err = error instanceof Error ? error : new Error(String(error));
249
- this.emit("error", err);
250
- throw err;
251
- }
252
- }
253
- /**
254
- * Get all agent IDs
255
- */
256
- getAgentIds() {
257
- return Array.from(this.worktrees.keys());
258
- }
259
- /**
260
- * Check if agent exists
261
- */
262
- hasAgent(agentId) {
263
- return this.worktrees.has(agentId);
264
- }
265
- /**
266
- * Get workspace root path
267
- */
268
- getWorkspaceRoot() {
269
- return this.config.workspaceRoot;
270
- }
271
- /**
272
- * Get agent path
273
- */
274
- getAgentPath(agentId) {
275
- return this.worktrees.get(agentId);
276
- }
277
- /**
278
- * Get state history for agent
279
- */
280
- async getStateHistory(agentId, limit = 20) {
281
- await this.ensureInitialized();
282
- const agentPath = this.worktrees.get(agentId);
283
- if (!agentPath) {
284
- return { agentId, commits: [], totalCommits: 0 };
285
- }
286
- try {
287
- const result = await this.exec(
288
- "git",
289
- ["log", `--max-count=${limit}`, "--format=%H|%s|%ct", "--", "state.json"],
290
- agentPath
291
- );
292
- const commits = result.stdout.split("\n").filter(Boolean).map((line) => {
293
- const [id, message, timestamp] = line.split("|");
294
- return {
295
- id,
296
- message,
297
- timestamp: Number.parseInt(timestamp, 10) * 1e3
298
- };
299
- });
300
- const countResult = await this.exec(
301
- "git",
302
- ["rev-list", "--count", "HEAD", "--", "state.json"],
303
- agentPath
304
- ).catch(() => ({ stdout: "0" }));
305
- return {
306
- agentId,
307
- commits,
308
- totalCommits: Number.parseInt(countResult.stdout.trim(), 10) || commits.length
309
- };
310
- } catch {
311
- return { agentId, commits: [], totalCommits: 0 };
312
- }
313
- }
314
- /**
315
- * Create a named snapshot of current state
316
- */
317
- async createSnapshot(agentId, description) {
318
- await this.ensureInitialized();
319
- const agentPath = this.worktrees.get(agentId);
320
- if (!agentPath) {
321
- throw new Error(`Agent not found: ${agentId}`);
322
- }
323
- const commitId = await this.commit(agentId, `Snapshot: ${description}`);
324
- if (!commitId) {
325
- const result = await this.exec("git", ["rev-parse", "HEAD"], agentPath);
326
- const currentCommitId = result.stdout.trim();
327
- const state2 = await this.loadState(agentId);
328
- return {
329
- id: nanoid(),
330
- agentId,
331
- commitId: currentCommitId,
332
- timestamp: Date.now(),
333
- message: description,
334
- state: state2 ?? {}
335
- };
336
- }
337
- const state = await this.loadState(agentId);
338
- return {
339
- id: nanoid(),
340
- agentId,
341
- commitId,
342
- timestamp: Date.now(),
343
- message: description,
344
- state: state ?? {}
345
- };
346
- }
347
- /**
348
- * Restore state from a snapshot
349
- */
350
- async restoreSnapshot(agentId, snapshotId) {
351
- await this.rollback(agentId, snapshotId);
352
- }
353
- /**
354
- * Sync with remote (if configured)
355
- */
356
- async syncWithRemote() {
357
- await this.ensureInitialized();
358
- try {
359
- const remoteResult = await this.exec("git", ["remote"], this.config.workspaceRoot);
360
- if (!remoteResult.stdout.trim()) {
361
- this.log("No remote configured, skipping sync");
362
- return;
363
- }
364
- await this.exec("git", ["pull", "--rebase"], this.config.workspaceRoot);
365
- await this.exec("git", ["push"], this.config.workspaceRoot);
366
- this.log("Synced with remote");
367
- } catch (error) {
368
- this.log(`Sync failed: ${error}`);
369
- }
370
- }
371
- // ========================================================================
372
- // Private Methods
373
- // ========================================================================
374
- async ensureInitialized() {
375
- if (!this.initialized) {
376
- await this.initialize();
377
- }
378
- }
379
- async getOrCreateAgentPath(agentId) {
380
- if (!this.worktrees.has(agentId)) {
381
- await this.createAgentWorktree(agentId);
382
- }
383
- return this.worktrees.get(agentId);
384
- }
385
- async loadExistingWorktrees() {
386
- const agentsDir = join(this.config.workspaceRoot, "agents");
387
- if (!existsSync(agentsDir)) {
388
- return;
389
- }
390
- try {
391
- const { readdirSync, statSync } = await import('node:fs');
392
- const entries = readdirSync(agentsDir);
393
- for (const entry of entries) {
394
- const entryPath = join(agentsDir, entry);
395
- if (statSync(entryPath).isDirectory()) {
396
- this.worktrees.set(entry, entryPath);
397
- this.log(`Loaded existing worktree: ${entry}`);
398
- }
399
- }
400
- } catch {
401
- }
402
- }
403
- async batchCommit(agentId, message) {
404
- const existing = this.pendingCommits.get(agentId);
405
- if (existing) {
406
- clearTimeout(existing);
407
- }
408
- return new Promise((resolve) => {
409
- const timeout = setTimeout(async () => {
410
- this.pendingCommits.delete(agentId);
411
- const commitId = await this.commit(agentId, message);
412
- resolve(commitId);
413
- }, this.config.commitBatchInterval);
414
- this.pendingCommits.set(agentId, timeout);
415
- });
416
- }
417
- async commit(agentId, message) {
418
- const agentPath = this.worktrees.get(agentId);
419
- if (!agentPath) {
420
- return "";
421
- }
422
- try {
423
- await this.exec("git", ["add", "-A"], agentPath);
424
- const statusResult = await this.exec("git", ["status", "--porcelain"], agentPath);
425
- if (!statusResult.stdout.trim()) {
426
- return "";
427
- }
428
- await this.exec("git", ["commit", "-m", message], agentPath);
429
- const result = await this.exec("git", ["rev-parse", "HEAD"], agentPath);
430
- return result.stdout.trim();
431
- } catch {
432
- return "";
433
- }
434
- }
435
- async exec(cmd, args, cwd) {
436
- const result = await K(cmd, args, { nodeOptions: { cwd } });
437
- return {
438
- stdout: result.stdout,
439
- stderr: result.stderr
440
- };
441
- }
442
- log(message) {
443
- if (this.config.verbose) {
444
- console.log(`[GitBackedState] ${message}`);
445
- }
446
- }
447
- }
448
- let globalStateManager = null;
449
- function getGlobalStateManager(config) {
450
- if (!globalStateManager) {
451
- globalStateManager = new GitBackedStateManager(config);
452
- }
453
- return globalStateManager;
454
- }
455
-
456
- const gitBackedState = {
457
- __proto__: null,
458
- GitBackedStateManager: GitBackedStateManager,
459
- getGlobalStateManager: getGlobalStateManager
460
- };
461
-
462
- class ConvoyManager extends EventEmitter {
463
- stateManager;
464
- convoys = /* @__PURE__ */ new Map();
465
- initialized = false;
466
- constructor(stateManager) {
467
- super();
468
- this.stateManager = stateManager ?? getGlobalStateManager();
469
- }
470
- /**
471
- * Initialize convoy manager
472
- */
473
- async initialize() {
474
- if (this.initialized)
475
- return;
476
- await this.stateManager.initialize();
477
- await this.loadConvoys();
478
- this.initialized = true;
479
- }
480
- /**
481
- * Create new convoy
482
- */
483
- async create(name, options = {}) {
484
- await this.ensureInitialized();
485
- const convoy = {
486
- id: `cv-${nanoid(6)}`,
487
- name,
488
- description: options.description ?? "",
489
- tasks: [],
490
- status: "pending",
491
- progress: 0,
492
- totalTasks: 0,
493
- completedTasks: 0,
494
- failedTasks: 0,
495
- cancelledTasks: 0,
496
- skippedTasks: 0,
497
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
498
- createdBy: options.createdBy ?? "system",
499
- notifications: {
500
- onComplete: options.notifyOnComplete ?? false,
501
- onFailure: options.notifyOnFailure ?? true,
502
- onProgress: options.notifyOnProgress ?? false,
503
- notifyHuman: options.notifyHuman ?? false
504
- },
505
- metadata: options.metadata,
506
- tags: options.tags ?? []
507
- };
508
- this.convoys.set(convoy.id, convoy);
509
- await this.persistConvoy(convoy);
510
- this.emit("convoy:created", convoy);
511
- return convoy;
512
- }
513
- /**
514
- * Add task to convoy
515
- */
516
- async addTask(convoyId, title, options = {}) {
517
- await this.ensureInitialized();
518
- const convoy = this.convoys.get(convoyId);
519
- if (!convoy) {
520
- throw new Error(`Convoy not found: ${convoyId}`);
521
- }
522
- const task = {
523
- id: `task-${nanoid(6)}`,
524
- title,
525
- description: options.description ?? "",
526
- status: "pending",
527
- assignedTo: options.assignedTo,
528
- dependsOn: options.dependsOn ?? [],
529
- metadata: options.metadata
530
- };
531
- convoy.tasks.push(task);
532
- convoy.totalTasks = convoy.tasks.length;
533
- this.updateProgress(convoy);
534
- await this.persistConvoy(convoy);
535
- return task;
536
- }
537
- /**
538
- * Add multiple tasks to convoy
539
- */
540
- async addTasks(convoyId, tasks) {
541
- const addedTasks = [];
542
- for (const { title, options } of tasks) {
543
- const task = await this.addTask(convoyId, title, options);
544
- addedTasks.push(task);
545
- }
546
- return addedTasks;
547
- }
548
- /**
549
- * Start convoy execution
550
- */
551
- async start(convoyId) {
552
- await this.ensureInitialized();
553
- const convoy = this.convoys.get(convoyId);
554
- if (!convoy) {
555
- throw new Error(`Convoy not found: ${convoyId}`);
556
- }
557
- if (convoy.status !== "pending" && convoy.status !== "paused") {
558
- throw new Error(`Cannot start convoy in status: ${convoy.status}`);
559
- }
560
- convoy.status = "in_progress";
561
- convoy.startedAt = convoy.startedAt ?? (/* @__PURE__ */ new Date()).toISOString();
562
- await this.persistConvoy(convoy);
563
- this.emit("convoy:started", convoy);
564
- }
565
- /**
566
- * Start a task
567
- */
568
- async startTask(convoyId, taskId, assignedTo) {
569
- await this.ensureInitialized();
570
- const convoy = this.convoys.get(convoyId);
571
- if (!convoy) {
572
- throw new Error(`Convoy not found: ${convoyId}`);
573
- }
574
- const task = convoy.tasks.find((t) => t.id === taskId);
575
- if (!task) {
576
- throw new Error(`Task not found: ${taskId}`);
577
- }
578
- const unmetDeps = this.getUnmetDependencies(convoy, task);
579
- if (unmetDeps.length > 0) {
580
- throw new Error(`Task has unmet dependencies: ${unmetDeps.join(", ")}`);
581
- }
582
- task.status = "in_progress";
583
- task.startedAt = (/* @__PURE__ */ new Date()).toISOString();
584
- if (assignedTo) {
585
- task.assignedTo = assignedTo;
586
- }
587
- if (convoy.status === "pending") {
588
- convoy.status = "in_progress";
589
- convoy.startedAt = (/* @__PURE__ */ new Date()).toISOString();
590
- }
591
- await this.persistConvoy(convoy);
592
- this.emit("task:started", convoy, task);
593
- }
594
- /**
595
- * Complete a task
596
- */
597
- async completeTask(convoyId, taskId, result) {
598
- await this.ensureInitialized();
599
- const convoy = this.convoys.get(convoyId);
600
- if (!convoy) {
601
- throw new Error(`Convoy not found: ${convoyId}`);
602
- }
603
- const task = convoy.tasks.find((t) => t.id === taskId);
604
- if (!task) {
605
- throw new Error(`Task not found: ${taskId}`);
606
- }
607
- task.status = "completed";
608
- task.completedAt = (/* @__PURE__ */ new Date()).toISOString();
609
- task.result = result;
610
- convoy.completedTasks++;
611
- this.updateProgress(convoy);
612
- this.checkConvoyCompletion(convoy);
613
- await this.persistConvoy(convoy);
614
- this.emit("task:completed", convoy, task);
615
- if (convoy.notifications.onProgress) {
616
- this.emit("convoy:progress", convoy, convoy.progress);
617
- }
618
- }
619
- /**
620
- * Fail a task
621
- */
622
- async failTask(convoyId, taskId, error) {
623
- await this.ensureInitialized();
624
- const convoy = this.convoys.get(convoyId);
625
- if (!convoy) {
626
- throw new Error(`Convoy not found: ${convoyId}`);
627
- }
628
- const task = convoy.tasks.find((t) => t.id === taskId);
629
- if (!task) {
630
- throw new Error(`Task not found: ${taskId}`);
631
- }
632
- task.status = "failed";
633
- task.completedAt = (/* @__PURE__ */ new Date()).toISOString();
634
- task.error = error;
635
- convoy.failedTasks++;
636
- this.updateProgress(convoy);
637
- await this.skipDependentTasks(convoy, taskId);
638
- this.checkConvoyCompletion(convoy);
639
- await this.persistConvoy(convoy);
640
- this.emit("task:failed", convoy, task);
641
- if (convoy.notifications.onFailure) {
642
- this.emit("convoy:failed", convoy);
643
- }
644
- }
645
- /**
646
- * Cancel a task
647
- */
648
- async cancelTask(convoyId, taskId) {
649
- await this.ensureInitialized();
650
- const convoy = this.convoys.get(convoyId);
651
- if (!convoy) {
652
- throw new Error(`Convoy not found: ${convoyId}`);
653
- }
654
- const task = convoy.tasks.find((t) => t.id === taskId);
655
- if (!task) {
656
- throw new Error(`Task not found: ${taskId}`);
657
- }
658
- task.status = "cancelled";
659
- task.completedAt = (/* @__PURE__ */ new Date()).toISOString();
660
- convoy.cancelledTasks++;
661
- this.updateProgress(convoy);
662
- await this.skipDependentTasks(convoy, taskId);
663
- this.checkConvoyCompletion(convoy);
664
- await this.persistConvoy(convoy);
665
- this.emit("task:cancelled", convoy, task);
666
- }
667
- /**
668
- * Pause convoy
669
- */
670
- async pause(convoyId) {
671
- await this.ensureInitialized();
672
- const convoy = this.convoys.get(convoyId);
673
- if (!convoy) {
674
- throw new Error(`Convoy not found: ${convoyId}`);
675
- }
676
- if (convoy.status !== "in_progress") {
677
- throw new Error(`Cannot pause convoy in status: ${convoy.status}`);
678
- }
679
- convoy.status = "paused";
680
- await this.persistConvoy(convoy);
681
- this.emit("convoy:paused", convoy);
682
- }
683
- /**
684
- * Resume convoy
685
- */
686
- async resume(convoyId) {
687
- await this.ensureInitialized();
688
- const convoy = this.convoys.get(convoyId);
689
- if (!convoy) {
690
- throw new Error(`Convoy not found: ${convoyId}`);
691
- }
692
- if (convoy.status !== "paused") {
693
- throw new Error(`Cannot resume convoy in status: ${convoy.status}`);
694
- }
695
- convoy.status = "in_progress";
696
- await this.persistConvoy(convoy);
697
- this.emit("convoy:resumed", convoy);
698
- }
699
- /**
700
- * Cancel convoy
701
- */
702
- async cancel(convoyId) {
703
- await this.ensureInitialized();
704
- const convoy = this.convoys.get(convoyId);
705
- if (!convoy) {
706
- throw new Error(`Convoy not found: ${convoyId}`);
707
- }
708
- convoy.status = "cancelled";
709
- convoy.completedAt = (/* @__PURE__ */ new Date()).toISOString();
710
- for (const task of convoy.tasks) {
711
- if (task.status === "pending" || task.status === "in_progress") {
712
- task.status = "cancelled";
713
- task.completedAt = (/* @__PURE__ */ new Date()).toISOString();
714
- convoy.cancelledTasks++;
715
- }
716
- }
717
- this.updateProgress(convoy);
718
- await this.persistConvoy(convoy);
719
- this.emit("convoy:cancelled", convoy);
720
- }
721
- /**
722
- * Get convoy by ID
723
- */
724
- get(convoyId) {
725
- return this.convoys.get(convoyId);
726
- }
727
- /**
728
- * List all convoys
729
- */
730
- list(filter) {
731
- let convoys = Array.from(this.convoys.values());
732
- if (filter) {
733
- if (filter.status) {
734
- convoys = convoys.filter((c) => c.status === filter.status);
735
- }
736
- if (filter.createdBy) {
737
- convoys = convoys.filter((c) => c.createdBy === filter.createdBy);
738
- }
739
- if (filter.tags && filter.tags.length > 0) {
740
- convoys = convoys.filter(
741
- (c) => filter.tags.some((tag) => c.tags.includes(tag))
742
- );
743
- }
744
- }
745
- return convoys.sort(
746
- (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
747
- );
748
- }
749
- /**
750
- * Get active convoys
751
- */
752
- getActive() {
753
- return this.list({ status: "in_progress" });
754
- }
755
- /**
756
- * Get next available tasks (no unmet dependencies)
757
- */
758
- getNextTasks(convoyId) {
759
- const convoy = this.convoys.get(convoyId);
760
- if (!convoy)
761
- return [];
762
- return convoy.tasks.filter((task) => {
763
- if (task.status !== "pending")
764
- return false;
765
- return this.getUnmetDependencies(convoy, task).length === 0;
766
- });
767
- }
768
- /**
769
- * Get convoy summary
770
- */
771
- getSummary(convoyId) {
772
- const convoy = this.convoys.get(convoyId);
773
- if (!convoy)
774
- return "Convoy not found";
775
- const lines = [
776
- `Convoy: ${convoy.name} (${convoy.id})`,
777
- `Status: ${convoy.status}`,
778
- `Progress: ${convoy.progress}%`,
779
- `Tasks: ${convoy.completedTasks}/${convoy.totalTasks} completed`
780
- ];
781
- if (convoy.failedTasks > 0) {
782
- lines.push(`Failed: ${convoy.failedTasks}`);
783
- }
784
- if (convoy.cancelledTasks > 0) {
785
- lines.push(`Cancelled: ${convoy.cancelledTasks}`);
786
- }
787
- if (convoy.skippedTasks > 0) {
788
- lines.push(`Skipped: ${convoy.skippedTasks}`);
789
- }
790
- return lines.join("\n");
791
- }
792
- /**
793
- * Delete convoy
794
- */
795
- async delete(convoyId) {
796
- await this.ensureInitialized();
797
- const convoy = this.convoys.get(convoyId);
798
- if (!convoy)
799
- return false;
800
- this.convoys.delete(convoyId);
801
- return true;
802
- }
803
- // ========================================================================
804
- // Private Methods
805
- // ========================================================================
806
- async ensureInitialized() {
807
- if (!this.initialized) {
808
- await this.initialize();
809
- }
810
- }
811
- updateProgress(convoy) {
812
- const processed = convoy.completedTasks + convoy.failedTasks + convoy.cancelledTasks + convoy.skippedTasks;
813
- convoy.progress = convoy.totalTasks > 0 ? Math.round(processed / convoy.totalTasks * 100) : 0;
814
- }
815
- checkConvoyCompletion(convoy) {
816
- const processed = convoy.completedTasks + convoy.failedTasks + convoy.cancelledTasks + convoy.skippedTasks;
817
- if (processed === convoy.totalTasks) {
818
- convoy.completedAt = (/* @__PURE__ */ new Date()).toISOString();
819
- if (convoy.failedTasks === 0 && convoy.cancelledTasks === 0) {
820
- convoy.status = "completed";
821
- if (convoy.notifications.onComplete) {
822
- this.emit("convoy:completed", convoy);
823
- }
824
- } else {
825
- convoy.status = "failed";
826
- if (convoy.notifications.onFailure) {
827
- this.emit("convoy:failed", convoy);
828
- }
829
- }
830
- }
831
- }
832
- getUnmetDependencies(convoy, task) {
833
- return task.dependsOn.filter((depId) => {
834
- const depTask = convoy.tasks.find((t) => t.id === depId);
835
- return !depTask || depTask.status !== "completed";
836
- });
837
- }
838
- async skipDependentTasks(convoy, failedTaskId) {
839
- for (const task of convoy.tasks) {
840
- if (task.status === "pending" && task.dependsOn.includes(failedTaskId)) {
841
- task.status = "skipped";
842
- task.completedAt = (/* @__PURE__ */ new Date()).toISOString();
843
- task.error = `Skipped due to failed dependency: ${failedTaskId}`;
844
- convoy.skippedTasks++;
845
- this.emit("task:skipped", convoy, task);
846
- await this.skipDependentTasks(convoy, task.id);
847
- }
848
- }
849
- }
850
- async loadConvoys() {
851
- for (const agentId of this.stateManager.getAgentIds()) {
852
- if (agentId.startsWith("convoy-")) {
853
- const state = await this.stateManager.loadState(agentId);
854
- if (state) {
855
- const convoy = state;
856
- this.convoys.set(convoy.id, convoy);
857
- }
858
- }
859
- }
860
- }
861
- async persistConvoy(convoy) {
862
- await this.stateManager.createAgentWorktree(`convoy-${convoy.id}`);
863
- await this.stateManager.saveState(`convoy-${convoy.id}`, convoy);
864
- }
865
- }
866
- let globalConvoyManager = null;
867
- function getGlobalConvoyManager() {
868
- if (!globalConvoyManager) {
869
- globalConvoyManager = new ConvoyManager();
870
- }
871
- return globalConvoyManager;
872
- }
873
-
874
- const convoyManager = {
875
- __proto__: null,
876
- ConvoyManager: ConvoyManager,
877
- getGlobalConvoyManager: getGlobalConvoyManager
878
- };
879
-
880
- export { getGlobalStateManager as a, gitBackedState as b, convoyManager as c, getGlobalConvoyManager as g };