Add Agent manager
Change-Id: Iaa68e9228165bd274f9c5be9d4320ef49a009ca8
diff --git a/server/git/clone_manager.go b/server/git/clone_manager.go
index afedd65..7bc9cde 100644
--- a/server/git/clone_manager.go
+++ b/server/git/clone_manager.go
@@ -12,10 +12,10 @@
// CloneManager manages separate Git repository clones for each agent
// This eliminates Git concurrency issues by giving each agent its own working directory
type CloneManager struct {
- baseRepoURL string
- workspacePath string
- agentClones map[string]string // agent name -> clone path
- mu sync.RWMutex
+ baseRepoURL string
+ workspacePath string
+ agentClones map[string]string // agent name -> clone path
+ mu sync.RWMutex
}
// NewCloneManager creates a new CloneManager
@@ -45,7 +45,7 @@
// Create new clone for the agent
clonePath := filepath.Join(cm.workspacePath, fmt.Sprintf("agent-%s", agentName))
-
+
// Ensure workspace directory exists
if err := os.MkdirAll(cm.workspacePath, 0755); err != nil {
return "", fmt.Errorf("failed to create workspace directory: %w", err)
@@ -63,14 +63,14 @@
// Store the clone path
cm.agentClones[agentName] = clonePath
-
+
return clonePath, nil
}
// cloneRepository performs the actual Git clone operation
func (cm *CloneManager) cloneRepository(clonePath string) error {
ctx := context.Background()
-
+
// Clone the repository
cmd := exec.CommandContext(ctx, "git", "clone", cm.baseRepoURL, clonePath)
if err := cmd.Run(); err != nil {
@@ -91,7 +91,7 @@
}
ctx := context.Background()
-
+
// Change to clone directory and pull latest changes
cmd := exec.CommandContext(ctx, "git", "-C", clonePath, "pull", "origin")
if err := cmd.Run(); err != nil {
@@ -118,7 +118,7 @@
// Remove from tracking
delete(cm.agentClones, agentName)
-
+
return nil
}
@@ -128,7 +128,7 @@
defer cm.mu.Unlock()
var errors []error
-
+
for agentName, clonePath := range cm.agentClones {
if err := os.RemoveAll(clonePath); err != nil {
errors = append(errors, fmt.Errorf("failed to remove clone for agent %s: %w", agentName, err))
@@ -155,6 +155,6 @@
for agent, path := range cm.agentClones {
result[agent] = path
}
-
+
return result
-}
\ No newline at end of file
+}