@stackmemoryai/stackmemory 0.3.22 → 0.3.25
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.
- package/dist/cli/commands/ralph.js +294 -0
- package/dist/cli/commands/ralph.js.map +7 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +2 -2
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js +586 -0
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +7 -0
- package/dist/integrations/ralph/context/context-budget-manager.js +297 -0
- package/dist/integrations/ralph/context/context-budget-manager.js.map +7 -0
- package/dist/integrations/ralph/context/stackmemory-context-loader.js +356 -0
- package/dist/integrations/ralph/context/stackmemory-context-loader.js.map +7 -0
- package/dist/integrations/ralph/index.js +14 -0
- package/dist/integrations/ralph/index.js.map +7 -0
- package/dist/integrations/ralph/learning/pattern-learner.js +397 -0
- package/dist/integrations/ralph/learning/pattern-learner.js.map +7 -0
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js +444 -0
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js.map +7 -0
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js +459 -0
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +7 -0
- package/dist/integrations/ralph/performance/performance-optimizer.js +354 -0
- package/dist/integrations/ralph/performance/performance-optimizer.js.map +7 -0
- package/dist/integrations/ralph/ralph-integration-demo.js +178 -0
- package/dist/integrations/ralph/ralph-integration-demo.js.map +7 -0
- package/dist/integrations/ralph/state/state-reconciler.js +400 -0
- package/dist/integrations/ralph/state/state-reconciler.js.map +7 -0
- package/dist/integrations/ralph/swarm/git-workflow-manager.js +309 -0
- package/dist/integrations/ralph/swarm/git-workflow-manager.js.map +7 -0
- package/dist/integrations/ralph/swarm/swarm-coordinator.js +656 -0
- package/dist/integrations/ralph/swarm/swarm-coordinator.js.map +7 -0
- package/dist/integrations/ralph/types.js +1 -0
- package/dist/integrations/ralph/types.js.map +7 -0
- package/dist/integrations/ralph/visualization/ralph-debugger.js +581 -0
- package/dist/integrations/ralph/visualization/ralph-debugger.js.map +7 -0
- package/package.json +1 -1
- package/scripts/deploy-ralph-swarm.sh +365 -0
- package/scripts/ralph-integration-test.js +274 -0
- package/scripts/ralph-loop-implementation.js +404 -0
- package/scripts/swarm-monitor.js +509 -0
- package/scripts/test-parallel-swarms.js +443 -0
- package/scripts/test-pre-publish-quick.sh +4 -2
- package/scripts/test-swarm-git-workflow.js +338 -0
- package/scripts/testing/ralph-cli-test.js +88 -0
- package/scripts/testing/ralph-integration-validation.js +727 -0
- package/scripts/testing/ralph-swarm-test-scenarios.js +613 -0
- package/scripts/validate-swarm-implementation.js +467 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { logger } from "../../../core/monitoring/logger.js";
|
|
3
|
+
class GitWorkflowManager {
|
|
4
|
+
config;
|
|
5
|
+
agentBranches = /* @__PURE__ */ new Map();
|
|
6
|
+
baselineBranch;
|
|
7
|
+
mainBranch;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = {
|
|
10
|
+
enableGitWorkflow: true,
|
|
11
|
+
branchStrategy: "agent",
|
|
12
|
+
autoCommit: true,
|
|
13
|
+
commitFrequency: 5,
|
|
14
|
+
mergStrategy: "squash",
|
|
15
|
+
requirePR: false,
|
|
16
|
+
...config
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
this.baselineBranch = this.getCurrentBranch();
|
|
20
|
+
this.mainBranch = this.getMainBranch();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
logger.warn("Git not initialized, workflow features disabled");
|
|
23
|
+
this.config.enableGitWorkflow = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Initialize git workflow for an agent
|
|
28
|
+
*/
|
|
29
|
+
async initializeAgentWorkflow(agent, task) {
|
|
30
|
+
if (!this.config.enableGitWorkflow) return;
|
|
31
|
+
const branchName = this.generateBranchName(agent, task);
|
|
32
|
+
try {
|
|
33
|
+
this.createBranch(branchName);
|
|
34
|
+
this.agentBranches.set(agent.id, branchName);
|
|
35
|
+
logger.info(`Created git branch for agent ${agent.role}: ${branchName}`);
|
|
36
|
+
if (this.config.autoCommit) {
|
|
37
|
+
this.scheduleAutoCommit(agent, task);
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger.error(`Failed to initialize git workflow for agent ${agent.role}`, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Commit agent work
|
|
45
|
+
*/
|
|
46
|
+
async commitAgentWork(agent, task, message) {
|
|
47
|
+
if (!this.config.enableGitWorkflow) return;
|
|
48
|
+
const branchName = this.agentBranches.get(agent.id);
|
|
49
|
+
if (!branchName) {
|
|
50
|
+
logger.warn(`No branch found for agent ${agent.id}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
this.checkoutBranch(branchName);
|
|
55
|
+
const hasChanges = this.hasUncommittedChanges();
|
|
56
|
+
if (!hasChanges) {
|
|
57
|
+
logger.debug(`No changes to commit for agent ${agent.role}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
execSync("git add -A", { encoding: "utf8" });
|
|
61
|
+
const commitMessage = message || this.generateCommitMessage(agent, task);
|
|
62
|
+
execSync(`git commit -m "${commitMessage}"`, { encoding: "utf8" });
|
|
63
|
+
logger.info(`Agent ${agent.role} committed: ${commitMessage}`);
|
|
64
|
+
if (this.hasRemote()) {
|
|
65
|
+
try {
|
|
66
|
+
execSync(`git push origin ${branchName}`, { encoding: "utf8" });
|
|
67
|
+
logger.info(`Pushed branch ${branchName} to remote`);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
logger.warn(`Could not push to remote: ${error}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.error(`Failed to commit agent work`, error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Merge agent work back to baseline
|
|
78
|
+
*/
|
|
79
|
+
async mergeAgentWork(agent, task) {
|
|
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(this.baselineBranch);
|
|
88
|
+
if (this.config.requirePR) {
|
|
89
|
+
await this.createPullRequest(agent, task, branchName);
|
|
90
|
+
} else {
|
|
91
|
+
this.mergeBranch(branchName);
|
|
92
|
+
logger.info(`Merged agent ${agent.role} work from ${branchName}`);
|
|
93
|
+
}
|
|
94
|
+
this.deleteBranch(branchName);
|
|
95
|
+
this.agentBranches.delete(agent.id);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
logger.error(`Failed to merge agent work`, error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Coordinate merges between multiple agents
|
|
102
|
+
*/
|
|
103
|
+
async coordinateMerges(agents) {
|
|
104
|
+
if (!this.config.enableGitWorkflow) return;
|
|
105
|
+
logger.info("Coordinating merges from all agents");
|
|
106
|
+
const integrationBranch = `swarm-integration-${Date.now()}`;
|
|
107
|
+
this.createBranch(integrationBranch);
|
|
108
|
+
for (const agent of agents) {
|
|
109
|
+
const branchName = this.agentBranches.get(agent.id);
|
|
110
|
+
if (branchName && this.branchExists(branchName)) {
|
|
111
|
+
try {
|
|
112
|
+
this.mergeBranch(branchName);
|
|
113
|
+
logger.info(`Integrated ${agent.role} work`);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
logger.error(`Failed to integrate ${agent.role} work: ${error}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const testsPass = await this.runIntegrationTests();
|
|
120
|
+
if (testsPass) {
|
|
121
|
+
this.checkoutBranch(this.baselineBranch);
|
|
122
|
+
this.mergeBranch(integrationBranch);
|
|
123
|
+
logger.info("Successfully integrated all agent work");
|
|
124
|
+
} else {
|
|
125
|
+
logger.warn("Integration tests failed, keeping changes in branch: " + integrationBranch);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Handle merge conflicts
|
|
130
|
+
*/
|
|
131
|
+
async resolveConflicts(agent) {
|
|
132
|
+
const conflicts = this.getConflictedFiles();
|
|
133
|
+
if (conflicts.length === 0) return;
|
|
134
|
+
logger.warn(`Agent ${agent.role} encountering merge conflicts: ${conflicts.join(", ")}`);
|
|
135
|
+
for (const file of conflicts) {
|
|
136
|
+
try {
|
|
137
|
+
if (this.isAgentFile(file, agent)) {
|
|
138
|
+
execSync(`git checkout --ours ${file}`, { encoding: "utf8" });
|
|
139
|
+
execSync(`git add ${file}`, { encoding: "utf8" });
|
|
140
|
+
} else {
|
|
141
|
+
execSync(`git checkout --theirs ${file}`, { encoding: "utf8" });
|
|
142
|
+
execSync(`git add ${file}`, { encoding: "utf8" });
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.error(`Could not auto-resolve conflict in ${file}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const remainingConflicts = this.getConflictedFiles();
|
|
149
|
+
if (remainingConflicts.length === 0) {
|
|
150
|
+
execSync("git commit --no-edit", { encoding: "utf8" });
|
|
151
|
+
logger.info("All conflicts resolved automatically");
|
|
152
|
+
} else {
|
|
153
|
+
logger.error(`Manual intervention needed for: ${remainingConflicts.join(", ")}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Private helper methods
|
|
157
|
+
getCurrentBranch() {
|
|
158
|
+
return execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).trim();
|
|
159
|
+
}
|
|
160
|
+
getMainBranch() {
|
|
161
|
+
try {
|
|
162
|
+
const branches = execSync("git branch -r", { encoding: "utf8" });
|
|
163
|
+
if (branches.includes("origin/main")) return "main";
|
|
164
|
+
if (branches.includes("origin/master")) return "master";
|
|
165
|
+
} catch (error) {
|
|
166
|
+
}
|
|
167
|
+
return this.getCurrentBranch();
|
|
168
|
+
}
|
|
169
|
+
generateBranchName(agent, task) {
|
|
170
|
+
const sanitizedTitle = task.title.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").substring(0, 30);
|
|
171
|
+
switch (this.config.branchStrategy) {
|
|
172
|
+
case "feature":
|
|
173
|
+
return `feature/${sanitizedTitle}`;
|
|
174
|
+
case "task":
|
|
175
|
+
return `task/${task.id}`;
|
|
176
|
+
case "agent":
|
|
177
|
+
default:
|
|
178
|
+
return `swarm/${agent.role}-${sanitizedTitle}`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
createBranch(branchName) {
|
|
182
|
+
execSync(`git checkout -b ${branchName}`, { encoding: "utf8" });
|
|
183
|
+
}
|
|
184
|
+
checkoutBranch(branchName) {
|
|
185
|
+
execSync(`git checkout ${branchName}`, { encoding: "utf8" });
|
|
186
|
+
}
|
|
187
|
+
branchExists(branchName) {
|
|
188
|
+
try {
|
|
189
|
+
execSync(`git rev-parse --verify ${branchName}`, {
|
|
190
|
+
encoding: "utf8",
|
|
191
|
+
stdio: "pipe"
|
|
192
|
+
});
|
|
193
|
+
return true;
|
|
194
|
+
} catch {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
deleteBranch(branchName) {
|
|
199
|
+
try {
|
|
200
|
+
execSync(`git branch -d ${branchName}`, { encoding: "utf8" });
|
|
201
|
+
} catch (error) {
|
|
202
|
+
execSync(`git branch -D ${branchName}`, { encoding: "utf8" });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
mergeBranch(branchName) {
|
|
206
|
+
const strategy = this.config.mergStrategy;
|
|
207
|
+
switch (strategy) {
|
|
208
|
+
case "squash":
|
|
209
|
+
execSync(`git merge --squash ${branchName}`, { encoding: "utf8" });
|
|
210
|
+
execSync('git commit -m "Squashed agent changes"', { encoding: "utf8" });
|
|
211
|
+
break;
|
|
212
|
+
case "rebase":
|
|
213
|
+
execSync(`git rebase ${branchName}`, { encoding: "utf8" });
|
|
214
|
+
break;
|
|
215
|
+
case "merge":
|
|
216
|
+
default:
|
|
217
|
+
execSync(`git merge ${branchName}`, { encoding: "utf8" });
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
hasUncommittedChanges() {
|
|
222
|
+
const status = execSync("git status --porcelain", { encoding: "utf8" });
|
|
223
|
+
return status.trim().length > 0;
|
|
224
|
+
}
|
|
225
|
+
hasRemote() {
|
|
226
|
+
try {
|
|
227
|
+
execSync("git remote get-url origin", { encoding: "utf8" });
|
|
228
|
+
return true;
|
|
229
|
+
} catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
getConflictedFiles() {
|
|
234
|
+
try {
|
|
235
|
+
const conflicts = execSync("git diff --name-only --diff-filter=U", {
|
|
236
|
+
encoding: "utf8"
|
|
237
|
+
});
|
|
238
|
+
return conflicts.trim().split("\n").filter((f) => f.length > 0);
|
|
239
|
+
} catch {
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
isAgentFile(file, agent) {
|
|
244
|
+
return file.includes(agent.role) || file.includes(agent.id);
|
|
245
|
+
}
|
|
246
|
+
generateCommitMessage(agent, task) {
|
|
247
|
+
return `[${agent.role}] ${task.title} - Iteration ${agent.performance?.tasksCompleted || 1}`;
|
|
248
|
+
}
|
|
249
|
+
scheduleAutoCommit(agent, task) {
|
|
250
|
+
const intervalMs = this.config.commitFrequency * 60 * 1e3;
|
|
251
|
+
setInterval(async () => {
|
|
252
|
+
await this.commitAgentWork(agent, task, `[${agent.role}] Auto-commit: ${task.title}`);
|
|
253
|
+
}, intervalMs);
|
|
254
|
+
}
|
|
255
|
+
async createPullRequest(agent, task, branchName) {
|
|
256
|
+
try {
|
|
257
|
+
const title = `[Swarm ${agent.role}] ${task.title}`;
|
|
258
|
+
const body = `
|
|
259
|
+
## Agent: ${agent.role}
|
|
260
|
+
## Task: ${task.title}
|
|
261
|
+
|
|
262
|
+
### Acceptance Criteria:
|
|
263
|
+
${task.acceptanceCriteria.map((c) => `- ${c}`).join("\n")}
|
|
264
|
+
|
|
265
|
+
### Status:
|
|
266
|
+
- Tasks Completed: ${agent.performance?.tasksCompleted || 0}
|
|
267
|
+
- Success Rate: ${agent.performance?.successRate || 0}%
|
|
268
|
+
|
|
269
|
+
Generated by Swarm Coordinator
|
|
270
|
+
`;
|
|
271
|
+
execSync(`gh pr create --title "${title}" --body "${body}" --base ${this.baselineBranch}`, {
|
|
272
|
+
encoding: "utf8"
|
|
273
|
+
});
|
|
274
|
+
logger.info(`Created PR for agent ${agent.role}`);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
logger.warn(`Could not create PR: ${error}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async runIntegrationTests() {
|
|
280
|
+
try {
|
|
281
|
+
execSync("npm test", { encoding: "utf8" });
|
|
282
|
+
return true;
|
|
283
|
+
} catch {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get status of all agent branches
|
|
289
|
+
*/
|
|
290
|
+
getGitStatus() {
|
|
291
|
+
const status = {
|
|
292
|
+
enabled: this.config.enableGitWorkflow,
|
|
293
|
+
currentBranch: this.getCurrentBranch(),
|
|
294
|
+
agentBranches: Array.from(this.agentBranches.entries()).map(([agentId, branch]) => ({
|
|
295
|
+
agentId,
|
|
296
|
+
branch,
|
|
297
|
+
exists: this.branchExists(branch)
|
|
298
|
+
})),
|
|
299
|
+
hasUncommittedChanges: this.hasUncommittedChanges()
|
|
300
|
+
};
|
|
301
|
+
return status;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const gitWorkflowManager = new GitWorkflowManager();
|
|
305
|
+
export {
|
|
306
|
+
GitWorkflowManager,
|
|
307
|
+
gitWorkflowManager
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=git-workflow-manager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/integrations/ralph/swarm/git-workflow-manager.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Git Workflow Manager for Swarm Agents\n * Manages git operations, branching, and commits for each agent\n */\n\nimport { execSync } from 'child_process';\nimport { logger } from '../../../core/monitoring/logger.js';\nimport { Agent, SwarmTask } from '../types.js';\n\nexport interface GitConfig {\n enableGitWorkflow: boolean;\n branchStrategy: 'feature' | 'agent' | 'task';\n autoCommit: boolean;\n commitFrequency: number; // minutes\n mergStrategy: 'squash' | 'merge' | 'rebase';\n requirePR: boolean;\n}\n\nexport class GitWorkflowManager {\n private config: GitConfig;\n private agentBranches: Map<string, string> = new Map();\n private baselineBranch: string;\n private mainBranch: string;\n\n constructor(config?: Partial<GitConfig>) {\n this.config = {\n enableGitWorkflow: true,\n branchStrategy: 'agent',\n autoCommit: true,\n commitFrequency: 5,\n mergStrategy: 'squash',\n requirePR: false,\n ...config\n };\n\n // Get current branch as baseline\n try {\n this.baselineBranch = this.getCurrentBranch();\n this.mainBranch = this.getMainBranch();\n } catch (error) {\n logger.warn('Git not initialized, workflow features disabled');\n this.config.enableGitWorkflow = false;\n }\n }\n\n /**\n * Initialize git workflow for an agent\n */\n async initializeAgentWorkflow(agent: Agent, task: SwarmTask): Promise<void> {\n if (!this.config.enableGitWorkflow) return;\n\n const branchName = this.generateBranchName(agent, task);\n \n try {\n // Create and checkout new branch\n this.createBranch(branchName);\n this.agentBranches.set(agent.id, branchName);\n \n logger.info(`Created git branch for agent ${agent.role}: ${branchName}`);\n\n // Set up commit timer if auto-commit enabled\n if (this.config.autoCommit) {\n this.scheduleAutoCommit(agent, task);\n }\n } catch (error: unknown) {\n logger.error(`Failed to initialize git workflow for agent ${agent.role}`, error as Error);\n }\n }\n\n /**\n * Commit agent work\n */\n async commitAgentWork(\n agent: Agent, \n task: SwarmTask,\n message?: string\n ): Promise<void> {\n if (!this.config.enableGitWorkflow) return;\n\n const branchName = this.agentBranches.get(agent.id);\n if (!branchName) {\n logger.warn(`No branch found for agent ${agent.id}`);\n return;\n }\n\n try {\n // Ensure we're on the agent's branch\n this.checkoutBranch(branchName);\n\n // Check for changes\n const hasChanges = this.hasUncommittedChanges();\n if (!hasChanges) {\n logger.debug(`No changes to commit for agent ${agent.role}`);\n return;\n }\n\n // Stage all changes\n execSync('git add -A', { encoding: 'utf8' });\n\n // Generate commit message\n const commitMessage = message || this.generateCommitMessage(agent, task);\n \n // Commit changes\n execSync(`git commit -m \"${commitMessage}\"`, { encoding: 'utf8' });\n \n logger.info(`Agent ${agent.role} committed: ${commitMessage}`);\n\n // Push if remote exists\n if (this.hasRemote()) {\n try {\n execSync(`git push origin ${branchName}`, { encoding: 'utf8' });\n logger.info(`Pushed branch ${branchName} to remote`);\n } catch (error) {\n logger.warn(`Could not push to remote: ${error}`);\n }\n }\n } catch (error: unknown) {\n logger.error(`Failed to commit agent work`, error as Error);\n }\n }\n\n /**\n * Merge agent work back to baseline\n */\n async mergeAgentWork(agent: Agent, task: SwarmTask): Promise<void> {\n if (!this.config.enableGitWorkflow) return;\n\n const branchName = this.agentBranches.get(agent.id);\n if (!branchName) {\n logger.warn(`No branch found for agent ${agent.id}`);\n return;\n }\n\n try {\n // Switch to baseline branch\n this.checkoutBranch(this.baselineBranch);\n\n if (this.config.requirePR) {\n // Create pull request\n await this.createPullRequest(agent, task, branchName);\n } else {\n // Direct merge based on strategy\n this.mergeBranch(branchName);\n logger.info(`Merged agent ${agent.role} work from ${branchName}`);\n }\n\n // Clean up branch\n this.deleteBranch(branchName);\n this.agentBranches.delete(agent.id);\n\n } catch (error: unknown) {\n logger.error(`Failed to merge agent work`, error as Error);\n }\n }\n\n /**\n * Coordinate merges between multiple agents\n */\n async coordinateMerges(agents: Agent[]): Promise<void> {\n if (!this.config.enableGitWorkflow) return;\n\n logger.info('Coordinating merges from all agents');\n\n // Create integration branch\n const integrationBranch = `swarm-integration-${Date.now()}`;\n this.createBranch(integrationBranch);\n\n // Merge each agent's work\n for (const agent of agents) {\n const branchName = this.agentBranches.get(agent.id);\n if (branchName && this.branchExists(branchName)) {\n try {\n this.mergeBranch(branchName);\n logger.info(`Integrated ${agent.role} work`);\n } catch (error) {\n logger.error(`Failed to integrate ${agent.role} work: ${error}`);\n }\n }\n }\n\n // Run tests on integration branch\n const testsPass = await this.runIntegrationTests();\n \n if (testsPass) {\n // Merge to baseline\n this.checkoutBranch(this.baselineBranch);\n this.mergeBranch(integrationBranch);\n logger.info('Successfully integrated all agent work');\n } else {\n logger.warn('Integration tests failed, keeping changes in branch: ' + integrationBranch);\n }\n }\n\n /**\n * Handle merge conflicts\n */\n async resolveConflicts(agent: Agent): Promise<void> {\n const conflicts = this.getConflictedFiles();\n \n if (conflicts.length === 0) return;\n\n logger.warn(`Agent ${agent.role} encountering merge conflicts: ${conflicts.join(', ')}`);\n\n // Strategy 1: Try to auto-resolve\n for (const file of conflicts) {\n try {\n // Accept current changes for agent's own files\n if (this.isAgentFile(file, agent)) {\n execSync(`git checkout --ours ${file}`, { encoding: 'utf8' });\n execSync(`git add ${file}`, { encoding: 'utf8' });\n } else {\n // Accept incoming changes for other files\n execSync(`git checkout --theirs ${file}`, { encoding: 'utf8' });\n execSync(`git add ${file}`, { encoding: 'utf8' });\n }\n } catch (error) {\n logger.error(`Could not auto-resolve conflict in ${file}`);\n }\n }\n\n // Complete merge if all conflicts resolved\n const remainingConflicts = this.getConflictedFiles();\n if (remainingConflicts.length === 0) {\n execSync('git commit --no-edit', { encoding: 'utf8' });\n logger.info('All conflicts resolved automatically');\n } else {\n logger.error(`Manual intervention needed for: ${remainingConflicts.join(', ')}`);\n }\n }\n\n // Private helper methods\n private getCurrentBranch(): string {\n return execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();\n }\n\n private getMainBranch(): string {\n try {\n // Try to detect main branch\n const branches = execSync('git branch -r', { encoding: 'utf8' });\n if (branches.includes('origin/main')) return 'main';\n if (branches.includes('origin/master')) return 'master';\n } catch (error) {\n // Fallback to current branch\n }\n return this.getCurrentBranch();\n }\n\n private generateBranchName(agent: Agent, task: SwarmTask): string {\n const sanitizedTitle = task.title.toLowerCase()\n .replace(/\\s+/g, '-')\n .replace(/[^a-z0-9-]/g, '')\n .substring(0, 30);\n\n switch (this.config.branchStrategy) {\n case 'feature':\n return `feature/${sanitizedTitle}`;\n case 'task':\n return `task/${task.id}`;\n case 'agent':\n default:\n return `swarm/${agent.role}-${sanitizedTitle}`;\n }\n }\n\n private createBranch(branchName: string): void {\n execSync(`git checkout -b ${branchName}`, { encoding: 'utf8' });\n }\n\n private checkoutBranch(branchName: string): void {\n execSync(`git checkout ${branchName}`, { encoding: 'utf8' });\n }\n\n private branchExists(branchName: string): boolean {\n try {\n execSync(`git rev-parse --verify ${branchName}`, { \n encoding: 'utf8',\n stdio: 'pipe'\n });\n return true;\n } catch {\n return false;\n }\n }\n\n private deleteBranch(branchName: string): void {\n try {\n execSync(`git branch -d ${branchName}`, { encoding: 'utf8' });\n } catch (error) {\n // Force delete if needed\n execSync(`git branch -D ${branchName}`, { encoding: 'utf8' });\n }\n }\n\n private mergeBranch(branchName: string): void {\n const strategy = this.config.mergStrategy;\n \n switch (strategy) {\n case 'squash':\n execSync(`git merge --squash ${branchName}`, { encoding: 'utf8' });\n execSync('git commit -m \"Squashed agent changes\"', { encoding: 'utf8' });\n break;\n case 'rebase':\n execSync(`git rebase ${branchName}`, { encoding: 'utf8' });\n break;\n case 'merge':\n default:\n execSync(`git merge ${branchName}`, { encoding: 'utf8' });\n break;\n }\n }\n\n private hasUncommittedChanges(): boolean {\n const status = execSync('git status --porcelain', { encoding: 'utf8' });\n return status.trim().length > 0;\n }\n\n private hasRemote(): boolean {\n try {\n execSync('git remote get-url origin', { encoding: 'utf8' });\n return true;\n } catch {\n return false;\n }\n }\n\n private getConflictedFiles(): string[] {\n try {\n const conflicts = execSync('git diff --name-only --diff-filter=U', { \n encoding: 'utf8' \n });\n return conflicts.trim().split('\\n').filter(f => f.length > 0);\n } catch {\n return [];\n }\n }\n\n private isAgentFile(file: string, agent: Agent): boolean {\n // Simple heuristic: check if file is in agent's working directory\n return file.includes(agent.role) || file.includes(agent.id);\n }\n\n private generateCommitMessage(agent: Agent, task: SwarmTask): string {\n return `[${agent.role}] ${task.title} - Iteration ${agent.performance?.tasksCompleted || 1}`;\n }\n\n private scheduleAutoCommit(agent: Agent, task: SwarmTask): void {\n const intervalMs = this.config.commitFrequency * 60 * 1000;\n \n setInterval(async () => {\n await this.commitAgentWork(agent, task, `[${agent.role}] Auto-commit: ${task.title}`);\n }, intervalMs);\n }\n\n private async createPullRequest(agent: Agent, task: SwarmTask, branchName: string): Promise<void> {\n try {\n const title = `[Swarm ${agent.role}] ${task.title}`;\n const body = `\n## Agent: ${agent.role}\n## Task: ${task.title}\n\n### Acceptance Criteria:\n${task.acceptanceCriteria.map(c => `- ${c}`).join('\\n')}\n\n### Status:\n- Tasks Completed: ${agent.performance?.tasksCompleted || 0}\n- Success Rate: ${agent.performance?.successRate || 0}%\n\nGenerated by Swarm Coordinator\n `;\n\n execSync(`gh pr create --title \"${title}\" --body \"${body}\" --base ${this.baselineBranch}`, {\n encoding: 'utf8'\n });\n \n logger.info(`Created PR for agent ${agent.role}`);\n } catch (error) {\n logger.warn(`Could not create PR: ${error}`);\n }\n }\n\n private async runIntegrationTests(): Promise<boolean> {\n try {\n // Try to run tests\n execSync('npm test', { encoding: 'utf8' });\n return true;\n } catch {\n // Tests failed or not available\n return false;\n }\n }\n\n /**\n * Get status of all agent branches\n */\n getGitStatus(): object {\n const status: any = {\n enabled: this.config.enableGitWorkflow,\n currentBranch: this.getCurrentBranch(),\n agentBranches: Array.from(this.agentBranches.entries()).map(([agentId, branch]) => ({\n agentId,\n branch,\n exists: this.branchExists(branch)\n })),\n hasUncommittedChanges: this.hasUncommittedChanges()\n };\n\n return status;\n }\n}\n\nexport const gitWorkflowManager = new GitWorkflowManager();"],
|
|
5
|
+
"mappings": "AAKA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAYhB,MAAM,mBAAmB;AAAA,EACtB;AAAA,EACA,gBAAqC,oBAAI,IAAI;AAAA,EAC7C;AAAA,EACA;AAAA,EAER,YAAY,QAA6B;AACvC,SAAK,SAAS;AAAA,MACZ,mBAAmB;AAAA,MACnB,gBAAgB;AAAA,MAChB,YAAY;AAAA,MACZ,iBAAiB;AAAA,MACjB,cAAc;AAAA,MACd,WAAW;AAAA,MACX,GAAG;AAAA,IACL;AAGA,QAAI;AACF,WAAK,iBAAiB,KAAK,iBAAiB;AAC5C,WAAK,aAAa,KAAK,cAAc;AAAA,IACvC,SAAS,OAAO;AACd,aAAO,KAAK,iDAAiD;AAC7D,WAAK,OAAO,oBAAoB;AAAA,IAClC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,wBAAwB,OAAc,MAAgC;AAC1E,QAAI,CAAC,KAAK,OAAO,kBAAmB;AAEpC,UAAM,aAAa,KAAK,mBAAmB,OAAO,IAAI;AAEtD,QAAI;AAEF,WAAK,aAAa,UAAU;AAC5B,WAAK,cAAc,IAAI,MAAM,IAAI,UAAU;AAE3C,aAAO,KAAK,gCAAgC,MAAM,IAAI,KAAK,UAAU,EAAE;AAGvE,UAAI,KAAK,OAAO,YAAY;AAC1B,aAAK,mBAAmB,OAAO,IAAI;AAAA,MACrC;AAAA,IACF,SAAS,OAAgB;AACvB,aAAO,MAAM,+CAA+C,MAAM,IAAI,IAAI,KAAc;AAAA,IAC1F;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBACJ,OACA,MACA,SACe;AACf,QAAI,CAAC,KAAK,OAAO,kBAAmB;AAEpC,UAAM,aAAa,KAAK,c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