@stackmemoryai/stackmemory 1.10.5 → 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.
- package/LICENSE +131 -64
- package/README.md +107 -24
- package/bin/claude-sm +16 -1
- package/bin/claude-smd +16 -1
- package/bin/codex-smd +16 -1
- package/bin/gemini-sm +16 -1
- package/bin/hermes-sm +21 -0
- package/bin/hermes-smd +21 -0
- package/bin/opencode-sm +16 -1
- package/dist/src/cli/claude-sm.js +266 -84
- package/dist/src/cli/codex-sm.js +225 -33
- package/dist/src/cli/commands/bench.js +209 -2
- package/dist/src/cli/commands/brain.js +206 -0
- package/dist/src/cli/commands/cache.js +126 -0
- package/dist/src/cli/commands/company-os.js +184 -0
- package/dist/src/cli/commands/context.js +5 -0
- package/dist/src/cli/commands/daemon.js +41 -0
- package/dist/src/cli/commands/handoff.js +40 -9
- package/dist/src/cli/commands/onboard.js +70 -3
- package/dist/src/cli/commands/operator.js +127 -0
- package/dist/src/cli/commands/optimize.js +117 -0
- package/dist/src/cli/commands/orchestrate.js +232 -5
- package/dist/src/cli/commands/orchestrator.js +315 -26
- package/dist/src/cli/commands/pack.js +322 -0
- package/dist/src/cli/commands/patterns.js +254 -0
- package/dist/src/cli/commands/portal.js +161 -0
- package/dist/src/cli/commands/scaffold.js +92 -0
- package/dist/src/cli/commands/search.js +40 -1
- package/dist/src/cli/commands/setup.js +178 -11
- package/dist/src/cli/commands/skills.js +10 -1
- package/dist/src/cli/commands/state.js +265 -0
- package/dist/src/cli/commands/sync.js +253 -0
- package/dist/src/cli/commands/tasks.js +130 -1
- package/dist/src/cli/commands/vision.js +221 -0
- package/dist/src/cli/gemini-sm.js +19 -29
- package/dist/src/cli/hermes-sm.js +224 -0
- package/dist/src/cli/index.js +105 -39
- package/dist/src/cli/opencode-sm.js +38 -21
- package/dist/src/cli/utils/determinism-watcher.js +66 -0
- package/dist/src/cli/utils/real-cli-bin.js +116 -0
- package/dist/src/core/brain/brain-store.js +187 -0
- package/dist/src/core/brain/brain-sync.js +193 -0
- package/dist/src/core/brain/index.js +78 -0
- package/dist/src/core/brain/types.js +10 -0
- package/dist/src/core/cache/content-cache.js +238 -0
- package/dist/src/{integrations/diffmem → core/cache}/index.js +5 -5
- package/dist/src/core/cache/token-estimator.js +39 -0
- package/dist/src/core/config/feature-flags.js +2 -6
- package/dist/src/core/context/frame-database.js +79 -27
- package/dist/src/core/context/recursive-context-manager.js +1 -1
- package/dist/src/core/context/rehydration.js +2 -1
- package/dist/src/core/cross-search/cross-project-search.js +269 -0
- package/dist/src/core/cross-search/index.js +10 -0
- package/dist/src/core/database/sqlite-adapter.js +14 -84
- package/dist/src/core/extensions/provider-adapter.js +5 -0
- package/dist/src/core/models/model-router.js +54 -2
- package/dist/src/core/models/provider-pricing.js +58 -4
- package/dist/src/core/monitoring/logger.js +2 -1
- package/dist/src/core/optimization/trace-optimizer.js +413 -0
- package/dist/src/core/patterns/index.js +22 -0
- package/dist/src/core/patterns/pattern-applier.js +39 -0
- package/dist/src/core/patterns/pattern-observer.js +157 -0
- package/dist/src/core/patterns/pattern-store.js +259 -0
- package/dist/src/core/patterns/types.js +19 -0
- package/dist/src/core/provenance/confidence-scorer.js +128 -0
- package/dist/src/core/provenance/index.js +40 -0
- package/dist/src/core/provenance/provenance-store.js +194 -0
- package/dist/src/core/provenance/types.js +82 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +5 -4
- package/dist/src/core/retrieval/unified-context-assembler.js +11 -66
- package/dist/src/core/session/project-handoff.js +64 -0
- package/dist/src/core/session/session-manager.js +28 -0
- package/dist/src/core/shared-state/canonical-store.js +564 -0
- package/dist/src/core/skill-packs/index.js +18 -0
- package/dist/src/core/skill-packs/parser.js +42 -0
- package/dist/src/core/skill-packs/registry.js +224 -0
- package/dist/src/core/skill-packs/types.js +79 -0
- package/dist/src/core/storage/cloud-sync-manager.js +116 -0
- package/dist/src/core/storage/cloud-sync.js +574 -0
- package/dist/src/core/storage/two-tier-storage.js +5 -1
- package/dist/src/core/tasks/master-tasks-template.js +43 -0
- package/dist/src/core/tasks/md-task-parser.js +138 -0
- package/dist/src/core/trace/trace-event-store.js +282 -0
- package/dist/src/core/vision/index.js +27 -0
- package/dist/src/core/vision/signals.js +79 -0
- package/dist/src/core/vision/types.js +22 -0
- package/dist/src/core/vision/vision-file.js +146 -0
- package/dist/src/core/vision/vision-loop.js +220 -0
- package/dist/src/core/wiki/wiki-compiler.js +103 -1
- package/dist/src/daemon/daemon-config.js +52 -0
- package/dist/src/daemon/services/desire-path-service.js +566 -0
- package/dist/src/daemon/services/github-service.js +126 -0
- package/dist/src/daemon/services/research-stream-service.js +320 -0
- package/dist/src/daemon/services/telemetry-service.js +192 -0
- package/dist/src/daemon/unified-daemon.js +58 -1
- package/dist/src/features/browser/cli-browser-agent.js +417 -0
- package/dist/src/features/browser/stagehand-workflows.js +578 -0
- package/dist/src/features/operator/adapter-factory.js +62 -0
- package/dist/src/features/operator/browser-adapter.js +109 -0
- package/dist/src/features/operator/desktop-adapter.js +125 -0
- package/dist/src/features/operator/index.js +39 -0
- package/dist/src/features/operator/llm-decision.js +137 -0
- package/dist/src/features/operator/operator-logger.js +92 -0
- package/dist/src/features/operator/overnight-runner.js +327 -0
- package/dist/src/features/operator/screen-adapter.js +91 -0
- package/dist/src/features/operator/session-manager.js +127 -0
- package/dist/src/features/operator/state-machine.js +227 -0
- package/dist/src/features/operator/task-queue.js +81 -0
- package/dist/src/features/portal/index.js +26 -0
- package/dist/src/features/portal/server.js +240 -0
- package/dist/src/features/portal/types.js +14 -0
- package/dist/src/features/portal/ui.js +195 -0
- package/dist/src/features/sweep/pty-wrapper.js +13 -5
- package/dist/src/features/tasks/task-aware-context.js +2 -1
- package/dist/src/features/tui/simple-monitor.js +0 -23
- package/dist/src/features/tui/swarm-monitor.js +8 -66
- package/dist/src/features/web/client/hooks/use-socket.js +12 -0
- package/dist/src/{core/merge/index.js → features/web/client/lib/utils.js} +8 -4
- package/dist/src/features/web/client/next-env.d.js +4 -0
- package/dist/src/features/web/client/stores/session-store.js +12 -0
- package/dist/src/features/web/server/gcp-billing.js +76 -0
- package/dist/src/features/web/server/index.js +10 -0
- package/dist/src/features/web/server/spend-calculator.js +228 -0
- package/dist/src/hooks/schemas.js +6 -1
- package/dist/src/integrations/anthropic/client.js +3 -2
- package/dist/src/integrations/claude-code/agent-bridge.js +0 -3
- package/dist/src/integrations/claude-code/subagent-client.js +307 -11
- package/dist/src/integrations/claude-code/task-coordinator.js +2 -1
- package/dist/src/integrations/github/pr-state.js +158 -0
- package/dist/src/integrations/linear/client.js +4 -1
- package/dist/src/integrations/linear/webhook-retry.js +196 -0
- package/dist/src/integrations/linear/webhook-server.js +18 -22
- package/dist/src/integrations/mcp/handlers/cloud-sync-handlers.js +101 -0
- package/dist/src/integrations/mcp/handlers/index.js +40 -84
- package/dist/src/integrations/mcp/server.js +542 -641
- package/dist/src/integrations/mcp/tool-alias-registry.js +297 -0
- package/dist/src/integrations/mcp/tool-definitions.js +152 -682
- package/dist/src/mcp/stackmemory-mcp-server.js +571 -231
- package/dist/src/orchestrators/multimodal/determinism.js +244 -0
- package/dist/src/orchestrators/multimodal/harness.js +149 -78
- package/dist/src/orchestrators/multimodal/providers.js +44 -3
- package/dist/src/skills/recursive-agent-orchestrator.js +2 -4
- package/dist/src/utils/hook-installer.js +0 -8
- package/dist/src/utils/process-cleanup.js +1 -7
- package/docs/README.md +42 -0
- package/docs/guides/README_INSTALL.md +208 -0
- package/package.json +27 -9
- package/packs/coding/python-fastapi/instructions.md +60 -0
- package/packs/coding/python-fastapi/pack.yaml +28 -0
- package/packs/coding/typescript-react/instructions.md +47 -0
- package/packs/coding/typescript-react/pack.yaml +28 -0
- package/packs/core/commands/capture.md +32 -0
- package/packs/core/commands/learn.md +73 -0
- package/packs/core/commands/next.md +36 -0
- package/packs/core/commands/restart.md +58 -0
- package/packs/core/commands/restore.md +29 -0
- package/packs/core/commands/start.md +57 -0
- package/packs/core/commands/stop.md +65 -0
- package/packs/core/commands/summary.md +40 -0
- package/packs/core/manifest.json +24 -0
- package/packs/ops/decision-recovery/instructions.md +65 -0
- package/packs/ops/decision-recovery/pack.yaml +89 -0
- package/scripts/claude-code-wrapper.sh +11 -0
- package/scripts/claude-sm-setup.sh +12 -1
- package/scripts/codex-wrapper.sh +11 -0
- package/scripts/git-hooks/branch-context-manager.sh +11 -0
- package/scripts/git-hooks/post-checkout-stackmemory.sh +11 -0
- package/scripts/git-hooks/post-commit-stackmemory.sh +11 -0
- package/scripts/git-hooks/pre-commit-stackmemory.sh +11 -0
- package/scripts/hooks/cleanup-shell.sh +12 -1
- package/scripts/hooks/task-complete.sh +12 -1
- package/scripts/install-code-execution-hooks.sh +12 -1
- package/scripts/install-sweep-hook.sh +12 -0
- package/scripts/install.sh +11 -0
- package/scripts/opencode-wrapper.sh +11 -0
- package/scripts/portal/cloud-init.yaml +69 -0
- package/scripts/portal/setup.sh +69 -0
- package/scripts/portal/stackmemory-portal.service +34 -0
- package/scripts/setup-claude-integration.sh +12 -1
- package/scripts/smoke-init-db.sh +23 -0
- package/scripts/stackmemory-daemon.sh +11 -0
- package/scripts/verify-dist.cjs +11 -4
- package/dist/src/cli/commands/ralph.js +0 -1053
- package/dist/src/cli/commands/team.js +0 -168
- package/dist/src/core/context/shared-context-layer.js +0 -620
- package/dist/src/core/context/stack-merge-resolver.js +0 -748
- package/dist/src/core/merge/conflict-detector.js +0 -430
- package/dist/src/core/merge/resolution-engine.js +0 -557
- package/dist/src/core/merge/stack-diff.js +0 -531
- package/dist/src/core/merge/unified-merge-resolver.js +0 -302
- package/dist/src/hooks/diffmem-hooks.js +0 -376
- package/dist/src/integrations/diffmem/client.js +0 -208
- package/dist/src/integrations/diffmem/config.js +0 -14
- package/dist/src/integrations/greptile/client.js +0 -101
- package/dist/src/integrations/greptile/config.js +0 -14
- package/dist/src/integrations/greptile/index.js +0 -11
- package/dist/src/integrations/mcp/handlers/cord-handlers.js +0 -397
- package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +0 -455
- package/dist/src/integrations/mcp/handlers/greptile-handlers.js +0 -456
- package/dist/src/integrations/mcp/handlers/provider-handlers.js +0 -227
- package/dist/src/integrations/mcp/handlers/team-handlers.js +0 -211
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -863
- package/dist/src/integrations/ralph/context/context-budget-manager.js +0 -308
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +0 -391
- package/dist/src/integrations/ralph/index.js +0 -17
- package/dist/src/integrations/ralph/learning/pattern-learner.js +0 -435
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
- package/dist/src/integrations/ralph/loopmax.js +0 -488
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +0 -293
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js +0 -107
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -508
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -407
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +0 -495
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +0 -387
- package/dist/src/integrations/ralph/performance/performance-optimizer.js +0 -357
- package/dist/src/integrations/ralph/recovery/crash-recovery.js +0 -461
- package/dist/src/integrations/ralph/state/state-reconciler.js +0 -420
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +0 -444
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +0 -1007
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js +0 -635
- package/scripts/ralph-loop-implementation.js +0 -404
- /package/dist/src/core/{merge → cache}/types.js +0 -0
- /package/dist/src/{integrations/diffmem/types.js → core/storage/cloud-sync-types.js} +0 -0
- /package/dist/src/{integrations/greptile/types.js → core/trace/trace-event.js} +0 -0
- /package/dist/src/{integrations/ralph → features/operator}/types.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
|
-
};
|