@stackmemoryai/stackmemory 1.12.0 → 1.14.0

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 (162) hide show
  1. package/LICENSE +131 -64
  2. package/README.md +3 -1
  3. package/bin/claude-sm +16 -1
  4. package/bin/claude-smd +16 -1
  5. package/bin/codex-smd +16 -1
  6. package/bin/gemini-sm +16 -1
  7. package/bin/hermes-sm +21 -0
  8. package/bin/hermes-smd +21 -0
  9. package/bin/opencode-sm +16 -1
  10. package/dist/src/cli/codex-sm.js +51 -11
  11. package/dist/src/cli/commands/brain.js +206 -0
  12. package/dist/src/cli/commands/company-os.js +184 -0
  13. package/dist/src/cli/commands/context.js +5 -0
  14. package/dist/src/cli/commands/operator.js +127 -0
  15. package/dist/src/cli/commands/orchestrate.js +2 -0
  16. package/dist/src/cli/commands/orchestrator.js +3 -2
  17. package/dist/src/cli/commands/patterns.js +254 -0
  18. package/dist/src/cli/commands/portal.js +161 -0
  19. package/dist/src/cli/commands/scaffold.js +92 -0
  20. package/dist/src/cli/commands/setup.js +1 -4
  21. package/dist/src/cli/commands/sync.js +253 -0
  22. package/dist/src/cli/commands/tasks.js +130 -1
  23. package/dist/src/cli/commands/vision.js +221 -0
  24. package/dist/src/cli/hermes-sm.js +224 -0
  25. package/dist/src/cli/index.js +15 -10
  26. package/dist/src/cli/utils/real-cli-bin.js +72 -0
  27. package/dist/src/core/brain/brain-store.js +187 -0
  28. package/dist/src/core/brain/brain-sync.js +193 -0
  29. package/dist/src/core/brain/index.js +78 -0
  30. package/dist/src/core/brain/types.js +10 -0
  31. package/dist/src/core/cache/token-estimator.js +24 -1
  32. package/dist/src/core/config/feature-flags.js +2 -6
  33. package/dist/src/core/context/frame-database.js +44 -0
  34. package/dist/src/core/context/recursive-context-manager.js +1 -1
  35. package/dist/src/core/context/rehydration.js +2 -1
  36. package/dist/src/core/database/sqlite-adapter.js +14 -1
  37. package/dist/src/core/models/model-router.js +33 -1
  38. package/dist/src/core/models/provider-pricing.js +58 -4
  39. package/dist/src/core/patterns/index.js +22 -0
  40. package/dist/src/core/patterns/pattern-applier.js +39 -0
  41. package/dist/src/core/patterns/pattern-observer.js +157 -0
  42. package/dist/src/core/patterns/pattern-store.js +259 -0
  43. package/dist/src/core/patterns/types.js +19 -0
  44. package/dist/src/core/retrieval/llm-context-retrieval.js +5 -4
  45. package/dist/src/core/retrieval/unified-context-assembler.js +11 -66
  46. package/dist/src/core/skill-packs/types.js +14 -1
  47. package/dist/src/core/storage/cloud-sync-manager.js +116 -0
  48. package/dist/src/core/storage/cloud-sync.js +574 -0
  49. package/dist/src/core/storage/two-tier-storage.js +5 -1
  50. package/dist/src/core/tasks/master-tasks-template.js +43 -0
  51. package/dist/src/core/tasks/md-task-parser.js +138 -0
  52. package/dist/src/core/vision/index.js +27 -0
  53. package/dist/src/core/vision/signals.js +79 -0
  54. package/dist/src/core/vision/types.js +22 -0
  55. package/dist/src/core/vision/vision-file.js +146 -0
  56. package/dist/src/core/vision/vision-loop.js +220 -0
  57. package/dist/src/core/wiki/wiki-compiler.js +103 -1
  58. package/dist/src/daemon/daemon-config.js +45 -0
  59. package/dist/src/daemon/services/desire-path-service.js +566 -0
  60. package/dist/src/daemon/services/research-stream-service.js +320 -0
  61. package/dist/src/daemon/services/telemetry-service.js +192 -0
  62. package/dist/src/daemon/unified-daemon.js +28 -1
  63. package/dist/src/features/browser/cli-browser-agent.js +417 -0
  64. package/dist/src/features/browser/stagehand-workflows.js +578 -0
  65. package/dist/src/features/operator/adapter-factory.js +62 -0
  66. package/dist/src/features/operator/browser-adapter.js +109 -0
  67. package/dist/src/features/operator/desktop-adapter.js +125 -0
  68. package/dist/src/features/operator/index.js +39 -0
  69. package/dist/src/features/operator/llm-decision.js +137 -0
  70. package/dist/src/features/operator/operator-logger.js +92 -0
  71. package/dist/src/features/operator/overnight-runner.js +327 -0
  72. package/dist/src/features/operator/screen-adapter.js +91 -0
  73. package/dist/src/features/operator/session-manager.js +127 -0
  74. package/dist/src/features/operator/state-machine.js +227 -0
  75. package/dist/src/features/operator/task-queue.js +81 -0
  76. package/dist/src/features/portal/index.js +26 -0
  77. package/dist/src/features/portal/server.js +240 -0
  78. package/dist/src/features/portal/types.js +14 -0
  79. package/dist/src/features/portal/ui.js +195 -0
  80. package/dist/src/features/tasks/task-aware-context.js +2 -1
  81. package/dist/src/features/tui/simple-monitor.js +0 -23
  82. package/dist/src/features/tui/swarm-monitor.js +8 -66
  83. package/dist/src/{integrations/diffmem/index.js → features/web/client/hooks/use-socket.js} +6 -5
  84. package/dist/src/features/web/client/lib/utils.js +12 -0
  85. package/dist/src/features/web/client/stores/session-store.js +12 -0
  86. package/dist/src/features/web/server/gcp-billing.js +76 -0
  87. package/dist/src/features/web/server/index.js +10 -0
  88. package/dist/src/features/web/server/spend-calculator.js +228 -0
  89. package/dist/src/hooks/schemas.js +4 -1
  90. package/dist/src/integrations/anthropic/client.js +3 -2
  91. package/dist/src/integrations/claude-code/agent-bridge.js +0 -3
  92. package/dist/src/integrations/claude-code/subagent-client.js +218 -11
  93. package/dist/src/integrations/claude-code/task-coordinator.js +2 -1
  94. package/dist/src/integrations/linear/webhook-retry.js +196 -0
  95. package/dist/src/integrations/linear/webhook-server.js +18 -22
  96. package/dist/src/integrations/mcp/handlers/cloud-sync-handlers.js +101 -0
  97. package/dist/src/integrations/mcp/handlers/index.js +27 -52
  98. package/dist/src/integrations/mcp/server.js +122 -335
  99. package/dist/src/integrations/mcp/tool-alias-registry.js +0 -73
  100. package/dist/src/integrations/mcp/tool-definitions.js +111 -510
  101. package/dist/src/mcp/stackmemory-mcp-server.js +404 -379
  102. package/dist/src/orchestrators/multimodal/determinism.js +2 -1
  103. package/dist/src/orchestrators/multimodal/harness.js +2 -1
  104. package/dist/src/skills/recursive-agent-orchestrator.js +2 -4
  105. package/dist/src/utils/process-cleanup.js +1 -7
  106. package/docs/README.md +42 -0
  107. package/docs/guides/README_INSTALL.md +208 -0
  108. package/package.json +18 -9
  109. package/scripts/claude-code-wrapper.sh +11 -0
  110. package/scripts/claude-sm-setup.sh +12 -1
  111. package/scripts/codex-wrapper.sh +11 -0
  112. package/scripts/git-hooks/branch-context-manager.sh +11 -0
  113. package/scripts/git-hooks/post-checkout-stackmemory.sh +11 -0
  114. package/scripts/git-hooks/post-commit-stackmemory.sh +11 -0
  115. package/scripts/git-hooks/pre-commit-stackmemory.sh +11 -0
  116. package/scripts/hooks/cleanup-shell.sh +12 -1
  117. package/scripts/hooks/task-complete.sh +12 -1
  118. package/scripts/install-code-execution-hooks.sh +12 -1
  119. package/scripts/install-sweep-hook.sh +12 -0
  120. package/scripts/install.sh +11 -0
  121. package/scripts/opencode-wrapper.sh +11 -0
  122. package/scripts/portal/cloud-init.yaml +69 -0
  123. package/scripts/portal/setup.sh +69 -0
  124. package/scripts/portal/stackmemory-portal.service +34 -0
  125. package/scripts/setup-claude-integration.sh +12 -1
  126. package/scripts/smoke-init-db.sh +23 -0
  127. package/scripts/stackmemory-daemon.sh +11 -0
  128. package/scripts/verify-dist.cjs +11 -4
  129. package/dist/src/cli/commands/ralph.js +0 -1053
  130. package/dist/src/hooks/diffmem-hooks.js +0 -376
  131. package/dist/src/integrations/diffmem/client.js +0 -208
  132. package/dist/src/integrations/diffmem/config.js +0 -14
  133. package/dist/src/integrations/greptile/client.js +0 -101
  134. package/dist/src/integrations/greptile/config.js +0 -14
  135. package/dist/src/integrations/greptile/index.js +0 -11
  136. package/dist/src/integrations/mcp/handlers/cross-search-handlers.js +0 -188
  137. package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +0 -455
  138. package/dist/src/integrations/mcp/handlers/greptile-handlers.js +0 -456
  139. package/dist/src/integrations/mcp/handlers/provider-handlers.js +0 -227
  140. package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -863
  141. package/dist/src/integrations/ralph/context/context-budget-manager.js +0 -308
  142. package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +0 -354
  143. package/dist/src/integrations/ralph/index.js +0 -17
  144. package/dist/src/integrations/ralph/learning/pattern-learner.js +0 -416
  145. package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
  146. package/dist/src/integrations/ralph/loopmax.js +0 -488
  147. package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +0 -293
  148. package/dist/src/integrations/ralph/monitoring/swarm-registry.js +0 -107
  149. package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -508
  150. package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -407
  151. package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +0 -495
  152. package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +0 -387
  153. package/dist/src/integrations/ralph/performance/performance-optimizer.js +0 -357
  154. package/dist/src/integrations/ralph/recovery/crash-recovery.js +0 -461
  155. package/dist/src/integrations/ralph/state/state-reconciler.js +0 -420
  156. package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +0 -444
  157. package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +0 -1005
  158. package/dist/src/integrations/ralph/visualization/ralph-debugger.js +0 -635
  159. package/scripts/ralph-loop-implementation.js +0 -404
  160. /package/dist/src/{integrations/diffmem/types.js → core/storage/cloud-sync-types.js} +0 -0
  161. /package/dist/src/{integrations/greptile → features/operator}/types.js +0 -0
  162. /package/dist/src/{integrations/ralph/types.js → features/web/client/next-env.d.js} +0 -0
@@ -1,444 +0,0 @@
1
- import { fileURLToPath as __fileURLToPath } from 'url';
2
- import { dirname as __pathDirname } from 'path';
3
- const __filename = __fileURLToPath(import.meta.url);
4
- const __dirname = __pathDirname(__filename);
5
- import { execSync } from "child_process";
6
- import { logger } from "../../../core/monitoring/logger.js";
7
- class GitWorkflowError extends Error {
8
- constructor(message, context) {
9
- super(message);
10
- this.context = context;
11
- this.name = "GitWorkflowError";
12
- }
13
- }
14
- class GitWorkflowManager {
15
- config;
16
- agentBranches = /* @__PURE__ */ new Map();
17
- baselineBranch;
18
- mainBranch;
19
- constructor(config) {
20
- this.config = {
21
- enableGitWorkflow: true,
22
- branchStrategy: "agent",
23
- autoCommit: true,
24
- commitFrequency: 5,
25
- mergStrategy: "squash",
26
- requirePR: false,
27
- ...config
28
- };
29
- try {
30
- this.baselineBranch = this.getCurrentBranch();
31
- this.mainBranch = this.getMainBranch();
32
- } catch {
33
- logger.warn("Git not initialized, workflow features disabled");
34
- this.config.enableGitWorkflow = false;
35
- }
36
- }
37
- /**
38
- * Initialize git workflow for an agent
39
- */
40
- async initializeAgentWorkflow(agent, task) {
41
- if (!this.config.enableGitWorkflow) return;
42
- let branchName = this.generateBranchName(agent, task);
43
- try {
44
- if (this.branchExists(branchName)) {
45
- const existingHasChanges = this.branchHasUnmergedChanges(branchName);
46
- if (existingHasChanges) {
47
- const timestamp = Date.now();
48
- branchName = `${branchName}-${timestamp}`;
49
- logger.info(
50
- `Branch already exists with changes, creating unique branch: ${branchName}`
51
- );
52
- this.createBranch(branchName);
53
- } else {
54
- logger.info(
55
- `Reusing existing branch for agent ${agent.role}: ${branchName}`
56
- );
57
- this.checkoutBranch(branchName);
58
- }
59
- } else {
60
- this.createBranch(branchName);
61
- logger.info(
62
- `Created git branch for agent ${agent.role}: ${branchName}`
63
- );
64
- }
65
- this.agentBranches.set(agent.id, branchName);
66
- if (this.config.autoCommit) {
67
- this.scheduleAutoCommit(agent, task);
68
- }
69
- } catch (error) {
70
- logger.error(
71
- `Failed to initialize git workflow for agent ${agent.role}`,
72
- error
73
- );
74
- }
75
- }
76
- /**
77
- * Commit agent work
78
- */
79
- async commitAgentWork(agent, task, message) {
80
- if (!this.config.enableGitWorkflow) return;
81
- const branchName = this.agentBranches.get(agent.id);
82
- if (!branchName) {
83
- logger.warn(`No branch found for agent ${agent.id}`);
84
- return;
85
- }
86
- try {
87
- this.checkoutBranch(branchName);
88
- const hasChanges = this.hasUncommittedChanges();
89
- if (!hasChanges) {
90
- logger.debug(`No changes to commit for agent ${agent.role}`);
91
- return;
92
- }
93
- execSync("git add -A", { encoding: "utf8" });
94
- const commitMessage = message || this.generateCommitMessage(agent, task);
95
- execSync(`git commit -m "${commitMessage}"`, { encoding: "utf8" });
96
- logger.info(`Agent ${agent.role} committed: ${commitMessage}`);
97
- if (this.hasRemote()) {
98
- try {
99
- execSync(`git push origin ${branchName}`, { encoding: "utf8" });
100
- logger.info(`Pushed branch ${branchName} to remote`);
101
- } catch (error) {
102
- logger.warn(`Could not push to remote: ${error}`);
103
- }
104
- }
105
- } catch (error) {
106
- logger.error(`Failed to commit agent work`, error);
107
- }
108
- }
109
- /**
110
- * Merge agent work back to baseline
111
- */
112
- async mergeAgentWork(agent, task) {
113
- if (!this.config.enableGitWorkflow) return;
114
- const branchName = this.agentBranches.get(agent.id);
115
- if (!branchName) {
116
- logger.warn(`No branch found for agent ${agent.id}`);
117
- return;
118
- }
119
- try {
120
- this.checkoutBranch(this.baselineBranch);
121
- if (this.config.requirePR) {
122
- await this.createPullRequest(agent, task, branchName);
123
- } else {
124
- this.mergeBranch(branchName);
125
- logger.info(`Merged agent ${agent.role} work from ${branchName}`);
126
- }
127
- this.deleteBranch(branchName);
128
- this.agentBranches.delete(agent.id);
129
- } catch (error) {
130
- logger.error(`Failed to merge agent work`, error);
131
- }
132
- }
133
- /**
134
- * Coordinate merges between multiple agents
135
- */
136
- async coordinateMerges(agents) {
137
- if (!this.config.enableGitWorkflow) return;
138
- logger.info("Coordinating merges from all agents");
139
- const integrationBranch = `swarm-integration-${Date.now()}`;
140
- this.createBranch(integrationBranch);
141
- for (const agent of agents) {
142
- const branchName = this.agentBranches.get(agent.id);
143
- if (branchName && this.branchExists(branchName)) {
144
- try {
145
- this.mergeBranch(branchName);
146
- logger.info(`Integrated ${agent.role} work`);
147
- } catch (error) {
148
- logger.error(`Failed to integrate ${agent.role} work: ${error}`);
149
- }
150
- }
151
- }
152
- const testsPass = await this.runIntegrationTests();
153
- if (testsPass) {
154
- this.checkoutBranch(this.baselineBranch);
155
- this.mergeBranch(integrationBranch);
156
- logger.info("Successfully integrated all agent work");
157
- } else {
158
- logger.warn(
159
- "Integration tests failed, keeping changes in branch: " + integrationBranch
160
- );
161
- }
162
- }
163
- /**
164
- * Handle merge conflicts
165
- */
166
- async resolveConflicts(agent) {
167
- const conflicts = this.getConflictedFiles();
168
- if (conflicts.length === 0) return;
169
- logger.warn(
170
- `Agent ${agent.role} encountering merge conflicts: ${conflicts.join(", ")}`
171
- );
172
- for (const file of conflicts) {
173
- try {
174
- if (this.isAgentFile(file, agent)) {
175
- execSync(`git checkout --ours ${file}`, { encoding: "utf8" });
176
- execSync(`git add ${file}`, { encoding: "utf8" });
177
- } else {
178
- execSync(`git checkout --theirs ${file}`, { encoding: "utf8" });
179
- execSync(`git add ${file}`, { encoding: "utf8" });
180
- }
181
- } catch {
182
- logger.error(`Could not auto-resolve conflict in ${file}`);
183
- }
184
- }
185
- const remainingConflicts = this.getConflictedFiles();
186
- if (remainingConflicts.length === 0) {
187
- execSync("git commit --no-edit", { encoding: "utf8" });
188
- logger.info("All conflicts resolved automatically");
189
- } else {
190
- logger.error(
191
- `Manual intervention needed for: ${remainingConflicts.join(", ")}`
192
- );
193
- }
194
- }
195
- // Private helper methods
196
- getCurrentBranch() {
197
- try {
198
- return execSync("git rev-parse --abbrev-ref HEAD", {
199
- encoding: "utf8"
200
- }).trim();
201
- } catch (error) {
202
- logger.warn("Failed to get current branch", error);
203
- return "main";
204
- }
205
- return execSync("git rev-parse --abbrev-ref HEAD", {
206
- encoding: "utf8"
207
- }).trim();
208
- }
209
- getMainBranch() {
210
- try {
211
- const branches = execSync("git branch -r", { encoding: "utf8" });
212
- if (branches.includes("origin/main")) return "main";
213
- if (branches.includes("origin/master")) return "master";
214
- } catch (error) {
215
- logger.debug("Could not detect main branch from remotes", error);
216
- }
217
- return this.getCurrentBranch();
218
- }
219
- generateBranchName(agent, task) {
220
- const sanitizedTitle = task.title.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").substring(0, 30);
221
- switch (this.config.branchStrategy) {
222
- case "feature":
223
- return `feature/${sanitizedTitle}`;
224
- case "task":
225
- return `task/${task.id}`;
226
- case "agent":
227
- default:
228
- return `swarm/${agent.role}-${sanitizedTitle}`;
229
- }
230
- }
231
- createBranch(branchName) {
232
- try {
233
- try {
234
- const currentBranch = execSync("git branch --show-current", {
235
- encoding: "utf8"
236
- }).trim();
237
- if (currentBranch === branchName) {
238
- try {
239
- execSync("git checkout main", { encoding: "utf8" });
240
- } catch {
241
- execSync("git checkout master", { encoding: "utf8" });
242
- }
243
- }
244
- try {
245
- const worktrees = execSync("git worktree list --porcelain", {
246
- encoding: "utf8"
247
- });
248
- const lines = worktrees.split("\n");
249
- for (let i = 0; i < lines.length; i++) {
250
- if (lines[i].startsWith("branch ") && lines[i].includes(branchName)) {
251
- const worktreetPath = lines[i - 1].replace("worktree ", "");
252
- execSync(`git worktree remove --force "${worktreetPath}"`, {
253
- encoding: "utf8"
254
- });
255
- logger.info(
256
- `Removed worktree at ${worktreetPath} for branch ${branchName}`
257
- );
258
- }
259
- }
260
- } catch (worktreeError) {
261
- logger.warn(
262
- "Failed to check/remove worktrees",
263
- worktreeError
264
- );
265
- }
266
- execSync(`git branch -D ${branchName}`, { encoding: "utf8" });
267
- logger.info(`Deleted existing branch ${branchName} for fresh start`);
268
- } catch {
269
- }
270
- execSync(`git checkout -b ${branchName}`, { encoding: "utf8" });
271
- } catch (error) {
272
- logger.error(`Failed to create branch ${branchName}`, error);
273
- throw new GitWorkflowError(`Failed to create branch: ${branchName}`, {
274
- branchName
275
- });
276
- }
277
- }
278
- checkoutBranch(branchName) {
279
- try {
280
- execSync(`git checkout ${branchName}`, { encoding: "utf8" });
281
- } catch (error) {
282
- logger.error(`Failed to checkout branch ${branchName}`, error);
283
- throw new GitWorkflowError(`Failed to checkout branch: ${branchName}`, {
284
- branchName
285
- });
286
- }
287
- }
288
- branchExists(branchName) {
289
- try {
290
- execSync(`git rev-parse --verify ${branchName}`, {
291
- encoding: "utf8",
292
- stdio: "pipe"
293
- });
294
- return true;
295
- } catch {
296
- return false;
297
- }
298
- }
299
- deleteBranch(branchName) {
300
- try {
301
- execSync(`git branch -d ${branchName}`, { encoding: "utf8" });
302
- } catch {
303
- execSync(`git branch -D ${branchName}`, { encoding: "utf8" });
304
- }
305
- }
306
- mergeBranch(branchName) {
307
- const strategy = this.config.mergStrategy;
308
- switch (strategy) {
309
- case "squash":
310
- execSync(`git merge --squash ${branchName}`, { encoding: "utf8" });
311
- execSync('git commit -m "Squashed agent changes"', {
312
- encoding: "utf8"
313
- });
314
- break;
315
- case "rebase":
316
- execSync(`git rebase ${branchName}`, { encoding: "utf8" });
317
- break;
318
- case "merge":
319
- default:
320
- execSync(`git merge ${branchName}`, { encoding: "utf8" });
321
- break;
322
- }
323
- }
324
- hasUncommittedChanges() {
325
- try {
326
- const status = execSync("git status --porcelain", { encoding: "utf8" });
327
- return status.trim().length > 0;
328
- } catch (error) {
329
- logger.warn("Failed to check git status", error);
330
- return false;
331
- }
332
- }
333
- hasRemote() {
334
- try {
335
- execSync("git remote get-url origin", { encoding: "utf8" });
336
- return true;
337
- } catch {
338
- return false;
339
- }
340
- }
341
- getConflictedFiles() {
342
- try {
343
- const conflicts = execSync("git diff --name-only --diff-filter=U", {
344
- encoding: "utf8"
345
- });
346
- return conflicts.trim().split("\n").filter((f) => f.length > 0);
347
- } catch {
348
- return [];
349
- }
350
- }
351
- isAgentFile(file, agent) {
352
- if (!file || !agent?.role || !agent?.id) {
353
- return false;
354
- }
355
- return file.includes(agent.role) || file.includes(agent.id);
356
- }
357
- generateCommitMessage(agent, task) {
358
- const role = agent?.role || "agent";
359
- const title = task?.title || "task";
360
- const iteration = agent?.performance?.tasksCompleted || 1;
361
- return `[${role}] ${title} - Iteration ${iteration}`;
362
- }
363
- scheduleAutoCommit(agent, task) {
364
- const intervalMs = this.config.commitFrequency * 60 * 1e3;
365
- setInterval(async () => {
366
- await this.commitAgentWork(
367
- agent,
368
- task,
369
- `[${agent.role}] Auto-commit: ${task.title}`
370
- );
371
- }, intervalMs);
372
- }
373
- async createPullRequest(agent, task, _branchName) {
374
- try {
375
- const title = `[Swarm ${agent.role}] ${task.title}`;
376
- const body = `
377
- ## Agent: ${agent.role}
378
- ## Task: ${task.title}
379
-
380
- ### Acceptance Criteria:
381
- ${task.acceptanceCriteria.map((c) => `- ${c}`).join("\n")}
382
-
383
- ### Status:
384
- - Tasks Completed: ${agent.performance?.tasksCompleted || 0}
385
- - Success Rate: ${agent.performance?.successRate || 0}%
386
-
387
- Generated by Swarm Coordinator
388
- `;
389
- execSync(
390
- `gh pr create --title "${title}" --body "${body}" --base ${this.baselineBranch}`,
391
- {
392
- encoding: "utf8"
393
- }
394
- );
395
- logger.info(`Created PR for agent ${agent.role}`);
396
- } catch (error) {
397
- logger.warn(`Could not create PR: ${error}`);
398
- }
399
- }
400
- async runIntegrationTests() {
401
- try {
402
- execSync("npm test", { encoding: "utf8" });
403
- return true;
404
- } catch {
405
- return false;
406
- }
407
- }
408
- branchHasUnmergedChanges(branchName) {
409
- try {
410
- const currentBranch = this.getCurrentBranch();
411
- const unmerged = execSync(
412
- `git log ${currentBranch}..${branchName} --oneline`,
413
- { encoding: "utf8", stdio: "pipe" }
414
- );
415
- return unmerged.trim().length > 0;
416
- } catch {
417
- return true;
418
- }
419
- }
420
- /**
421
- * Get status of all agent branches
422
- */
423
- getGitStatus() {
424
- const status = {
425
- enabled: this.config.enableGitWorkflow,
426
- currentBranch: this.getCurrentBranch(),
427
- agentBranches: Array.from(this.agentBranches.entries()).map(
428
- ([agentId, branch]) => ({
429
- agentId,
430
- branch,
431
- exists: this.branchExists(branch)
432
- })
433
- ),
434
- hasUncommittedChanges: this.hasUncommittedChanges()
435
- };
436
- return status;
437
- }
438
- }
439
- const gitWorkflowManager = new GitWorkflowManager();
440
- export {
441
- GitWorkflowError,
442
- GitWorkflowManager,
443
- gitWorkflowManager
444
- };