mcp-agent-foundry 1.0.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 +21 -0
- package/README.md +477 -0
- package/dist/cli/install-skills.d.ts +11 -0
- package/dist/cli/install-skills.d.ts.map +1 -0
- package/dist/cli/install-skills.js +143 -0
- package/dist/cli/install-skills.js.map +1 -0
- package/dist/cli/recovery-commands.d.ts +41 -0
- package/dist/cli/recovery-commands.d.ts.map +1 -0
- package/dist/cli/recovery-commands.js +241 -0
- package/dist/cli/recovery-commands.js.map +1 -0
- package/dist/cli/setup-wizard.d.ts +25 -0
- package/dist/cli/setup-wizard.d.ts.map +1 -0
- package/dist/cli/setup-wizard.js +1417 -0
- package/dist/cli/setup-wizard.js.map +1 -0
- package/dist/cli/test-connection.d.ts +45 -0
- package/dist/cli/test-connection.d.ts.map +1 -0
- package/dist/cli/test-connection.js +317 -0
- package/dist/cli/test-connection.js.map +1 -0
- package/dist/cli.d.ts +75 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +704 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/defaults.d.ts +57 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +99 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +22 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +184 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +347 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/merger.d.ts +76 -0
- package/dist/config/merger.d.ts.map +1 -0
- package/dist/config/merger.js +189 -0
- package/dist/config/merger.js.map +1 -0
- package/dist/config/schema.d.ts +20 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +20 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/validator.d.ts +254 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +363 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/config/worktree-defaults.d.ts +23 -0
- package/dist/config/worktree-defaults.d.ts.map +1 -0
- package/dist/config/worktree-defaults.js +78 -0
- package/dist/config/worktree-defaults.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/tools/compare-agents.d.ts +25 -0
- package/dist/mcp/tools/compare-agents.d.ts.map +1 -0
- package/dist/mcp/tools/compare-agents.js +177 -0
- package/dist/mcp/tools/compare-agents.js.map +1 -0
- package/dist/mcp/tools/critique-plan.d.ts +26 -0
- package/dist/mcp/tools/critique-plan.d.ts.map +1 -0
- package/dist/mcp/tools/critique-plan.js +162 -0
- package/dist/mcp/tools/critique-plan.js.map +1 -0
- package/dist/mcp/tools/design-feedback.d.ts +26 -0
- package/dist/mcp/tools/design-feedback.d.ts.map +1 -0
- package/dist/mcp/tools/design-feedback.js +216 -0
- package/dist/mcp/tools/design-feedback.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +50 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +191 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/invoke-agent.d.ts +25 -0
- package/dist/mcp/tools/invoke-agent.d.ts.map +1 -0
- package/dist/mcp/tools/invoke-agent.js +141 -0
- package/dist/mcp/tools/invoke-agent.js.map +1 -0
- package/dist/mcp/tools/review-code.d.ts +25 -0
- package/dist/mcp/tools/review-code.d.ts.map +1 -0
- package/dist/mcp/tools/review-code.js +170 -0
- package/dist/mcp/tools/review-code.js.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts +22 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.js +203 -0
- package/dist/mcp/tools/tasks/claim-next-task.js.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts +17 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.js +178 -0
- package/dist/mcp/tools/tasks/create-routed-task.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts +22 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js +401 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts +32 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.js +284 -0
- package/dist/mcp/tools/tasks/execute-task.js.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts +26 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js +460 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js.map +1 -0
- package/dist/mcp/tools/tasks/index.d.ts +36 -0
- package/dist/mcp/tools/tasks/index.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/index.js +66 -0
- package/dist/mcp/tools/tasks/index.js.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js +147 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts +17 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js +123 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js.map +1 -0
- package/dist/mcp/tools/worktree/index.d.ts +41 -0
- package/dist/mcp/tools/worktree/index.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/index.js +69 -0
- package/dist/mcp/tools/worktree/index.js.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.js +136 -0
- package/dist/mcp/tools/worktree/list-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts +19 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js +228 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js.map +1 -0
- package/dist/mcp/transport/stdio.d.ts +13 -0
- package/dist/mcp/transport/stdio.d.ts.map +1 -0
- package/dist/mcp/transport/stdio.js +15 -0
- package/dist/mcp/transport/stdio.js.map +1 -0
- package/dist/observability/logger.d.ts +137 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +235 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +250 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +364 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/persistence/index.d.ts +9 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +9 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/state-schema.d.ts +116 -0
- package/dist/persistence/state-schema.d.ts.map +1 -0
- package/dist/persistence/state-schema.js +28 -0
- package/dist/persistence/state-schema.js.map +1 -0
- package/dist/persistence/state-store.d.ts +111 -0
- package/dist/persistence/state-store.d.ts.map +1 -0
- package/dist/persistence/state-store.js +291 -0
- package/dist/persistence/state-store.js.map +1 -0
- package/dist/providers/anthropic.d.ts +164 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +500 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +151 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +227 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/gemini.d.ts +85 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +414 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/kimi.d.ts +19 -0
- package/dist/providers/kimi.d.ts.map +1 -0
- package/dist/providers/kimi.js +20 -0
- package/dist/providers/kimi.js.map +1 -0
- package/dist/providers/manager.d.ts +160 -0
- package/dist/providers/manager.d.ts.map +1 -0
- package/dist/providers/manager.js +264 -0
- package/dist/providers/manager.js.map +1 -0
- package/dist/providers/ollama.d.ts +83 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +453 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +96 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +457 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/zai.d.ts +19 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +20 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/router/context-manager.d.ts +2 -0
- package/dist/router/context-manager.d.ts.map +1 -0
- package/dist/router/context-manager.js +3 -0
- package/dist/router/context-manager.js.map +1 -0
- package/dist/router/engine.d.ts +169 -0
- package/dist/router/engine.d.ts.map +1 -0
- package/dist/router/engine.js +435 -0
- package/dist/router/engine.js.map +1 -0
- package/dist/router/pattern-executor.d.ts +317 -0
- package/dist/router/pattern-executor.d.ts.map +1 -0
- package/dist/router/pattern-executor.js +571 -0
- package/dist/router/pattern-executor.js.map +1 -0
- package/dist/router/role-resolver.d.ts +59 -0
- package/dist/router/role-resolver.d.ts.map +1 -0
- package/dist/router/role-resolver.js +95 -0
- package/dist/router/role-resolver.js.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +223 -0
- package/dist/server.js.map +1 -0
- package/dist/startup.d.ts +78 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +107 -0
- package/dist/startup.js.map +1 -0
- package/dist/tasks/coordinator.d.ts +141 -0
- package/dist/tasks/coordinator.d.ts.map +1 -0
- package/dist/tasks/coordinator.js +331 -0
- package/dist/tasks/coordinator.js.map +1 -0
- package/dist/tasks/index.d.ts +13 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +13 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/persistent-state-coordinator.d.ts +89 -0
- package/dist/tasks/persistent-state-coordinator.d.ts.map +1 -0
- package/dist/tasks/persistent-state-coordinator.js +371 -0
- package/dist/tasks/persistent-state-coordinator.js.map +1 -0
- package/dist/tasks/pipeline-manager.d.ts +103 -0
- package/dist/tasks/pipeline-manager.d.ts.map +1 -0
- package/dist/tasks/pipeline-manager.js +358 -0
- package/dist/tasks/pipeline-manager.js.map +1 -0
- package/dist/tasks/state-coordinator.d.ts +79 -0
- package/dist/tasks/state-coordinator.d.ts.map +1 -0
- package/dist/tasks/state-coordinator.js +200 -0
- package/dist/tasks/state-coordinator.js.map +1 -0
- package/dist/tasks/worker-mode.d.ts +65 -0
- package/dist/tasks/worker-mode.d.ts.map +1 -0
- package/dist/tasks/worker-mode.js +208 -0
- package/dist/tasks/worker-mode.js.map +1 -0
- package/dist/translation/errors.d.ts +203 -0
- package/dist/translation/errors.d.ts.map +1 -0
- package/dist/translation/errors.js +477 -0
- package/dist/translation/errors.js.map +1 -0
- package/dist/translation/index.d.ts +12 -0
- package/dist/translation/index.d.ts.map +1 -0
- package/dist/translation/index.js +32 -0
- package/dist/translation/index.js.map +1 -0
- package/dist/translation/messages.d.ts +295 -0
- package/dist/translation/messages.d.ts.map +1 -0
- package/dist/translation/messages.js +557 -0
- package/dist/translation/messages.js.map +1 -0
- package/dist/translation/streaming.d.ts +226 -0
- package/dist/translation/streaming.d.ts.map +1 -0
- package/dist/translation/streaming.js +520 -0
- package/dist/translation/streaming.js.map +1 -0
- package/dist/translation/tools.d.ts +209 -0
- package/dist/translation/tools.d.ts.map +1 -0
- package/dist/translation/tools.js +331 -0
- package/dist/translation/tools.js.map +1 -0
- package/dist/types.d.ts +747 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +86 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +175 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +315 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/env.d.ts +2 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +3 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/git.d.ts +58 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +197 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge-ordering.d.ts +45 -0
- package/dist/utils/merge-ordering.d.ts.map +1 -0
- package/dist/utils/merge-ordering.js +128 -0
- package/dist/utils/merge-ordering.js.map +1 -0
- package/dist/utils/retry.d.ts +106 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +188 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/worktrees/branch-manager.d.ts +55 -0
- package/dist/worktrees/branch-manager.d.ts.map +1 -0
- package/dist/worktrees/branch-manager.js +129 -0
- package/dist/worktrees/branch-manager.js.map +1 -0
- package/dist/worktrees/conflict-handler.d.ts +72 -0
- package/dist/worktrees/conflict-handler.d.ts.map +1 -0
- package/dist/worktrees/conflict-handler.js +287 -0
- package/dist/worktrees/conflict-handler.js.map +1 -0
- package/dist/worktrees/conflict-parser.d.ts +28 -0
- package/dist/worktrees/conflict-parser.d.ts.map +1 -0
- package/dist/worktrees/conflict-parser.js +140 -0
- package/dist/worktrees/conflict-parser.js.map +1 -0
- package/dist/worktrees/index.d.ts +20 -0
- package/dist/worktrees/index.d.ts.map +1 -0
- package/dist/worktrees/index.js +20 -0
- package/dist/worktrees/index.js.map +1 -0
- package/dist/worktrees/instructions.d.ts +20 -0
- package/dist/worktrees/instructions.d.ts.map +1 -0
- package/dist/worktrees/instructions.js +84 -0
- package/dist/worktrees/instructions.js.map +1 -0
- package/dist/worktrees/manager.d.ts +76 -0
- package/dist/worktrees/manager.d.ts.map +1 -0
- package/dist/worktrees/manager.js +277 -0
- package/dist/worktrees/manager.js.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts +55 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js +221 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js.map +1 -0
- package/dist/worktrees/pool.d.ts +95 -0
- package/dist/worktrees/pool.d.ts.map +1 -0
- package/dist/worktrees/pool.js +271 -0
- package/dist/worktrees/pool.js.map +1 -0
- package/dist/worktrees/recovery.d.ts +94 -0
- package/dist/worktrees/recovery.d.ts.map +1 -0
- package/dist/worktrees/recovery.js +371 -0
- package/dist/worktrees/recovery.js.map +1 -0
- package/dist/worktrees/resource-manager.d.ts +74 -0
- package/dist/worktrees/resource-manager.d.ts.map +1 -0
- package/dist/worktrees/resource-manager.js +228 -0
- package/dist/worktrees/resource-manager.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree Manager for Agent Foundry
|
|
3
|
+
*
|
|
4
|
+
* Manages the lifecycle of git worktrees for parallel agent execution.
|
|
5
|
+
*/
|
|
6
|
+
import { BranchManager } from './branch-manager.js';
|
|
7
|
+
import type { Worktree, WorktreeStatus, WorktreeConfig, WorktreeInstructions, WorktreeAllocationResult } from '../types.js';
|
|
8
|
+
export declare class WorktreeManager {
|
|
9
|
+
private readonly config;
|
|
10
|
+
private readonly branchManager;
|
|
11
|
+
private readonly repoPath;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private worktrees;
|
|
14
|
+
constructor(repoPath: string, config: WorktreeConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the worktree manager
|
|
17
|
+
*/
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Sync in-memory state with actual git worktrees
|
|
21
|
+
*/
|
|
22
|
+
syncWorktrees(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new worktree for a task
|
|
25
|
+
*/
|
|
26
|
+
create(taskId: string, baseBranch?: string): Promise<Worktree>;
|
|
27
|
+
/**
|
|
28
|
+
* Assign a worktree to an agent
|
|
29
|
+
*/
|
|
30
|
+
assign(worktreeId: string, agentId: string): Promise<Worktree>;
|
|
31
|
+
/**
|
|
32
|
+
* Mark worktree as active (agent is using it)
|
|
33
|
+
*/
|
|
34
|
+
activate(worktreeId: string): Promise<Worktree>;
|
|
35
|
+
/**
|
|
36
|
+
* Release a worktree (task completed)
|
|
37
|
+
*/
|
|
38
|
+
release(worktreeId: string): Promise<Worktree>;
|
|
39
|
+
/**
|
|
40
|
+
* Remove a worktree
|
|
41
|
+
*/
|
|
42
|
+
remove(worktreeId: string, deleteBranch?: boolean): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get worktree by ID
|
|
45
|
+
*/
|
|
46
|
+
get(worktreeId: string): Worktree | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Get worktree by task ID
|
|
49
|
+
*/
|
|
50
|
+
getByTaskId(taskId: string): Worktree | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* List all worktrees
|
|
53
|
+
*/
|
|
54
|
+
list(): Worktree[];
|
|
55
|
+
/**
|
|
56
|
+
* List worktrees by status
|
|
57
|
+
*/
|
|
58
|
+
listByStatus(status: WorktreeStatus): Worktree[];
|
|
59
|
+
/**
|
|
60
|
+
* Generate instructions for an agent to use a worktree
|
|
61
|
+
*/
|
|
62
|
+
generateInstructions(worktree: Worktree): WorktreeInstructions;
|
|
63
|
+
/**
|
|
64
|
+
* Allocate a worktree for a task (create + assign + generate instructions)
|
|
65
|
+
*/
|
|
66
|
+
allocate(taskId: string, agentId: string): Promise<WorktreeAllocationResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Cleanup stale worktrees
|
|
69
|
+
*/
|
|
70
|
+
cleanup(): Promise<number>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the branch manager for advanced operations
|
|
73
|
+
*/
|
|
74
|
+
getBranchManager(): BranchManager;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/worktrees/manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAErB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAGxB,OAAO,CAAC,SAAS,CAAoC;gBAEzC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAYpD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBjC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BpC;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkCpE;;OAEG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkBpE;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAarD;;OAEG;IACG,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAcpD;;OAEG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI7C;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAOjD;;OAEG;IACH,IAAI,IAAI,QAAQ,EAAE;IAIlB;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,EAAE;IAIhD;;OAEG;IACH,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,oBAAoB;IAsB9D;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAuBlF;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IA4BhC;;OAEG;IACH,gBAAgB,IAAI,aAAa;CAGlC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree Manager for Agent Foundry
|
|
3
|
+
*
|
|
4
|
+
* Manages the lifecycle of git worktrees for parallel agent execution.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as fs from 'fs/promises';
|
|
9
|
+
import { createWorktree, removeWorktree, listWorktrees, pruneWorktrees, isGitRepository, getRepoRoot } from '../utils/git.js';
|
|
10
|
+
import { BranchManager } from './branch-manager.js';
|
|
11
|
+
import { createLogger } from '../observability/logger.js';
|
|
12
|
+
export class WorktreeManager {
|
|
13
|
+
config;
|
|
14
|
+
branchManager;
|
|
15
|
+
repoPath;
|
|
16
|
+
logger;
|
|
17
|
+
// In-memory worktree state
|
|
18
|
+
worktrees = new Map();
|
|
19
|
+
constructor(repoPath, config) {
|
|
20
|
+
this.repoPath = repoPath;
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.logger = createLogger({ name: 'worktree-manager' });
|
|
23
|
+
this.branchManager = new BranchManager({
|
|
24
|
+
repoPath,
|
|
25
|
+
defaultBaseBranch: config.git.defaultBaseBranch,
|
|
26
|
+
branchPattern: config.git.branchPattern,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the worktree manager
|
|
31
|
+
*/
|
|
32
|
+
async initialize() {
|
|
33
|
+
// Verify we're in a git repository
|
|
34
|
+
if (!(await isGitRepository(this.repoPath))) {
|
|
35
|
+
throw new Error(`Not a git repository: ${this.repoPath}`);
|
|
36
|
+
}
|
|
37
|
+
// Get actual repo root
|
|
38
|
+
const repoRoot = await getRepoRoot(this.repoPath);
|
|
39
|
+
// Create base directory for worktrees if it doesn't exist
|
|
40
|
+
const worktreeBaseDir = path.join(repoRoot, this.config.baseDir);
|
|
41
|
+
await fs.mkdir(worktreeBaseDir, { recursive: true });
|
|
42
|
+
// Sync with existing worktrees
|
|
43
|
+
await this.syncWorktrees();
|
|
44
|
+
this.logger.info('WorktreeManager initialized', {
|
|
45
|
+
repoPath: repoRoot,
|
|
46
|
+
baseDir: this.config.baseDir,
|
|
47
|
+
existingWorktrees: this.worktrees.size,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sync in-memory state with actual git worktrees
|
|
52
|
+
*/
|
|
53
|
+
async syncWorktrees() {
|
|
54
|
+
const gitWorktrees = await listWorktrees(this.repoPath);
|
|
55
|
+
const repoRoot = await getRepoRoot(this.repoPath);
|
|
56
|
+
const worktreeBaseDir = path.join(repoRoot, this.config.baseDir);
|
|
57
|
+
for (const gitWt of gitWorktrees) {
|
|
58
|
+
// Skip main worktree and worktrees outside our base directory
|
|
59
|
+
if (!gitWt.path.startsWith(worktreeBaseDir))
|
|
60
|
+
continue;
|
|
61
|
+
const id = path.basename(gitWt.path);
|
|
62
|
+
if (!this.worktrees.has(id)) {
|
|
63
|
+
// Discovered existing worktree - add to state
|
|
64
|
+
this.worktrees.set(id, {
|
|
65
|
+
id,
|
|
66
|
+
path: gitWt.path,
|
|
67
|
+
branch: gitWt.branch || '',
|
|
68
|
+
baseBranch: this.config.git.defaultBaseBranch,
|
|
69
|
+
status: 'stale', // Mark as stale since we don't know its state
|
|
70
|
+
createdAt: Date.now(),
|
|
71
|
+
lastActivityAt: Date.now(),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a new worktree for a task
|
|
78
|
+
*/
|
|
79
|
+
async create(taskId, baseBranch) {
|
|
80
|
+
const id = `task-${taskId}-${randomUUID().slice(0, 8)}`;
|
|
81
|
+
const branch = this.branchManager.generateBranchName(taskId);
|
|
82
|
+
const base = baseBranch || this.config.git.defaultBaseBranch;
|
|
83
|
+
const repoRoot = await getRepoRoot(this.repoPath);
|
|
84
|
+
const worktreePath = path.join(repoRoot, this.config.baseDir, id);
|
|
85
|
+
this.logger.info('Creating worktree', { id, branch, baseBranch: base, path: worktreePath });
|
|
86
|
+
// Check limits
|
|
87
|
+
if (this.worktrees.size >= this.config.limits.maxWorktrees) {
|
|
88
|
+
throw new Error(`Maximum worktrees (${this.config.limits.maxWorktrees}) reached`);
|
|
89
|
+
}
|
|
90
|
+
// Create the worktree
|
|
91
|
+
await createWorktree(this.repoPath, worktreePath, branch, base);
|
|
92
|
+
const worktree = {
|
|
93
|
+
id,
|
|
94
|
+
path: worktreePath,
|
|
95
|
+
branch,
|
|
96
|
+
baseBranch: base,
|
|
97
|
+
status: 'available',
|
|
98
|
+
taskId,
|
|
99
|
+
createdAt: Date.now(),
|
|
100
|
+
lastActivityAt: Date.now(),
|
|
101
|
+
};
|
|
102
|
+
this.worktrees.set(id, worktree);
|
|
103
|
+
this.logger.info('Worktree created', { id, branch, path: worktreePath });
|
|
104
|
+
return worktree;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Assign a worktree to an agent
|
|
108
|
+
*/
|
|
109
|
+
async assign(worktreeId, agentId) {
|
|
110
|
+
const worktree = this.worktrees.get(worktreeId);
|
|
111
|
+
if (!worktree) {
|
|
112
|
+
throw new Error(`Worktree not found: ${worktreeId}`);
|
|
113
|
+
}
|
|
114
|
+
if (worktree.status !== 'available') {
|
|
115
|
+
throw new Error(`Worktree ${worktreeId} is not available (status: ${worktree.status})`);
|
|
116
|
+
}
|
|
117
|
+
worktree.status = 'assigned';
|
|
118
|
+
worktree.agentId = agentId;
|
|
119
|
+
worktree.lastActivityAt = Date.now();
|
|
120
|
+
this.logger.info('Worktree assigned', { worktreeId, agentId });
|
|
121
|
+
return worktree;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Mark worktree as active (agent is using it)
|
|
125
|
+
*/
|
|
126
|
+
async activate(worktreeId) {
|
|
127
|
+
const worktree = this.worktrees.get(worktreeId);
|
|
128
|
+
if (!worktree) {
|
|
129
|
+
throw new Error(`Worktree not found: ${worktreeId}`);
|
|
130
|
+
}
|
|
131
|
+
worktree.status = 'active';
|
|
132
|
+
worktree.lastActivityAt = Date.now();
|
|
133
|
+
this.logger.info('Worktree activated', { worktreeId });
|
|
134
|
+
return worktree;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Release a worktree (task completed)
|
|
138
|
+
*/
|
|
139
|
+
async release(worktreeId) {
|
|
140
|
+
const worktree = this.worktrees.get(worktreeId);
|
|
141
|
+
if (!worktree) {
|
|
142
|
+
throw new Error(`Worktree not found: ${worktreeId}`);
|
|
143
|
+
}
|
|
144
|
+
worktree.status = 'completing';
|
|
145
|
+
worktree.agentId = undefined;
|
|
146
|
+
worktree.lastActivityAt = Date.now();
|
|
147
|
+
this.logger.info('Worktree released', { worktreeId });
|
|
148
|
+
return worktree;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Remove a worktree
|
|
152
|
+
*/
|
|
153
|
+
async remove(worktreeId, deleteBranch = false) {
|
|
154
|
+
const worktree = this.worktrees.get(worktreeId);
|
|
155
|
+
if (!worktree) {
|
|
156
|
+
throw new Error(`Worktree not found: ${worktreeId}`);
|
|
157
|
+
}
|
|
158
|
+
this.logger.info('Removing worktree', { worktreeId, deleteBranch });
|
|
159
|
+
// Remove git worktree
|
|
160
|
+
await removeWorktree(this.repoPath, worktree.path, true);
|
|
161
|
+
// Optionally delete the branch
|
|
162
|
+
if (deleteBranch) {
|
|
163
|
+
await this.branchManager.deleteBranch(worktree.branch, true);
|
|
164
|
+
}
|
|
165
|
+
this.worktrees.delete(worktreeId);
|
|
166
|
+
this.logger.info('Worktree removed', { worktreeId });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get worktree by ID
|
|
170
|
+
*/
|
|
171
|
+
get(worktreeId) {
|
|
172
|
+
return this.worktrees.get(worktreeId);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get worktree by task ID
|
|
176
|
+
*/
|
|
177
|
+
getByTaskId(taskId) {
|
|
178
|
+
for (const wt of this.worktrees.values()) {
|
|
179
|
+
if (wt.taskId === taskId)
|
|
180
|
+
return wt;
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* List all worktrees
|
|
186
|
+
*/
|
|
187
|
+
list() {
|
|
188
|
+
return Array.from(this.worktrees.values());
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* List worktrees by status
|
|
192
|
+
*/
|
|
193
|
+
listByStatus(status) {
|
|
194
|
+
return this.list().filter(wt => wt.status === status);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generate instructions for an agent to use a worktree
|
|
198
|
+
*/
|
|
199
|
+
generateInstructions(worktree) {
|
|
200
|
+
return {
|
|
201
|
+
workingDirectory: worktree.path,
|
|
202
|
+
branch: worktree.branch,
|
|
203
|
+
baseBranch: worktree.baseBranch,
|
|
204
|
+
commitPrefix: `[${worktree.taskId}]`,
|
|
205
|
+
instructions: `
|
|
206
|
+
You are working in an isolated git worktree.
|
|
207
|
+
|
|
208
|
+
WORKING DIRECTORY: ${worktree.path}
|
|
209
|
+
BRANCH: ${worktree.branch}
|
|
210
|
+
BASE BRANCH: ${worktree.baseBranch}
|
|
211
|
+
|
|
212
|
+
IMPORTANT:
|
|
213
|
+
1. All file operations should be relative to ${worktree.path}
|
|
214
|
+
2. Commit your changes with prefix: [${worktree.taskId}]
|
|
215
|
+
3. Do NOT switch branches - stay on ${worktree.branch}
|
|
216
|
+
4. Do NOT merge or rebase - that will be handled after your task completes
|
|
217
|
+
`.trim(),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Allocate a worktree for a task (create + assign + generate instructions)
|
|
222
|
+
*/
|
|
223
|
+
async allocate(taskId, agentId) {
|
|
224
|
+
try {
|
|
225
|
+
const worktree = await this.create(taskId);
|
|
226
|
+
await this.assign(worktree.id, agentId);
|
|
227
|
+
await this.activate(worktree.id);
|
|
228
|
+
const instructions = this.generateInstructions(worktree);
|
|
229
|
+
return {
|
|
230
|
+
success: true,
|
|
231
|
+
worktree,
|
|
232
|
+
instructions,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
237
|
+
this.logger.error('Failed to allocate worktree', { taskId, agentId, errorMessage: message });
|
|
238
|
+
return {
|
|
239
|
+
success: false,
|
|
240
|
+
error: message,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Cleanup stale worktrees
|
|
246
|
+
*/
|
|
247
|
+
async cleanup() {
|
|
248
|
+
const staleThreshold = Date.now() - this.config.cleanup.staleThresholdMs;
|
|
249
|
+
let cleaned = 0;
|
|
250
|
+
for (const worktree of this.worktrees.values()) {
|
|
251
|
+
if ((worktree.status === 'stale' || worktree.status === 'available') &&
|
|
252
|
+
worktree.lastActivityAt < staleThreshold) {
|
|
253
|
+
try {
|
|
254
|
+
await this.remove(worktree.id, true);
|
|
255
|
+
cleaned++;
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
this.logger.warn('Failed to cleanup worktree', {
|
|
259
|
+
worktreeId: worktree.id,
|
|
260
|
+
error: error instanceof Error ? error.message : String(error)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Prune git worktree references
|
|
266
|
+
await pruneWorktrees(this.repoPath);
|
|
267
|
+
this.logger.info('Cleanup completed', { cleanedCount: cleaned });
|
|
268
|
+
return cleaned;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get the branch manager for advanced operations
|
|
272
|
+
*/
|
|
273
|
+
getBranchManager() {
|
|
274
|
+
return this.branchManager;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/worktrees/manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAS1D,MAAM,OAAO,eAAe;IACT,MAAM,CAAiB;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,CAAC,CAAC;oBACrC,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE;wBAC7C,UAAU,EAAE,QAAQ,CAAC,EAAE;wBACvB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;qBAC9D,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,gCAAgC;QAChC,MAAM,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline Merge Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates merging of pipeline step worktrees in dependency order.
|
|
5
|
+
* Handles conflict detection and provides merge results.
|
|
6
|
+
*/
|
|
7
|
+
import { type StepDependency } from "../utils/merge-ordering.js";
|
|
8
|
+
import type { StepWorktreeAllocation, PipelineMergeResult } from "../types.js";
|
|
9
|
+
export interface MergeConflict {
|
|
10
|
+
stepId: string;
|
|
11
|
+
branch: string;
|
|
12
|
+
conflictedFiles: string[];
|
|
13
|
+
conflictMarkers?: Array<{
|
|
14
|
+
file: string;
|
|
15
|
+
startLine: number;
|
|
16
|
+
endLine: number;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface StepMergeResult {
|
|
20
|
+
stepId: string;
|
|
21
|
+
branch: string;
|
|
22
|
+
success: boolean;
|
|
23
|
+
mergeCommit?: string;
|
|
24
|
+
conflict?: MergeConflict;
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface MergeOrchestratorConfig {
|
|
28
|
+
repoPath: string;
|
|
29
|
+
targetBranch: string;
|
|
30
|
+
strategy: "sequential" | "parallel-safe";
|
|
31
|
+
onConflict: "halt" | "skip" | "continue";
|
|
32
|
+
}
|
|
33
|
+
export declare class PipelineMergeOrchestrator {
|
|
34
|
+
private readonly config;
|
|
35
|
+
private readonly branchManager;
|
|
36
|
+
private readonly logger;
|
|
37
|
+
constructor(config: MergeOrchestratorConfig);
|
|
38
|
+
/**
|
|
39
|
+
* Check for merge conflicts between a branch and target without actually merging.
|
|
40
|
+
*/
|
|
41
|
+
checkMergeConflicts(sourceBranch: string, targetBranch: string): Promise<MergeConflict | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Merge a single step's branch into target.
|
|
44
|
+
*/
|
|
45
|
+
mergeStep(stepId: string, allocation: StepWorktreeAllocation): Promise<StepMergeResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Merge all pipeline worktrees in dependency order.
|
|
48
|
+
*/
|
|
49
|
+
mergeInDependencyOrder(pipelineId: string, stepAllocations: Map<string, StepWorktreeAllocation>, steps: StepDependency[]): Promise<PipelineMergeResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Delete branches after successful merge.
|
|
52
|
+
*/
|
|
53
|
+
cleanupBranches(branches: string[]): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=pipeline-merge-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-merge-orchestrator.d.ts","sourceRoot":"","sources":["../../src/worktrees/pipeline-merge-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEpF,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,MAA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AO,CAAC,mBAAmB,CAAC;IAyF/B;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAazD"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline Merge Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates merging of pipeline step worktrees in dependency order.
|
|
5
|
+
* Handles conflict detection and provides merge results.
|
|
6
|
+
*/
|
|
7
|
+
import { createGit } from "../utils/git.js";
|
|
8
|
+
import { BranchManager } from "./branch-manager.js";
|
|
9
|
+
import { computeMergeOrder } from "../utils/merge-ordering.js";
|
|
10
|
+
import { createLogger } from "../observability/logger.js";
|
|
11
|
+
export class PipelineMergeOrchestrator {
|
|
12
|
+
config;
|
|
13
|
+
branchManager;
|
|
14
|
+
logger;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.logger = createLogger({ name: "pipeline-merge-orchestrator" });
|
|
18
|
+
this.branchManager = new BranchManager({
|
|
19
|
+
repoPath: config.repoPath,
|
|
20
|
+
defaultBaseBranch: config.targetBranch,
|
|
21
|
+
branchPattern: "task/{taskId}",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check for merge conflicts between a branch and target without actually merging.
|
|
26
|
+
*/
|
|
27
|
+
async checkMergeConflicts(sourceBranch, targetBranch) {
|
|
28
|
+
const git = createGit(this.config.repoPath);
|
|
29
|
+
try {
|
|
30
|
+
// Ensure we're on target branch first
|
|
31
|
+
await git.checkout(targetBranch);
|
|
32
|
+
// Try a dry-run merge
|
|
33
|
+
await git.raw(["merge", "--no-commit", "--no-ff", sourceBranch]);
|
|
34
|
+
// If we get here, no conflicts - abort the merge
|
|
35
|
+
await git.raw(["merge", "--abort"]);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Check if it's a conflict
|
|
40
|
+
const status = await git.status();
|
|
41
|
+
if (status.conflicted.length > 0) {
|
|
42
|
+
// Abort the merge
|
|
43
|
+
try {
|
|
44
|
+
await git.raw(["merge", "--abort"]);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Already aborted or not in merge state
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
stepId: "", // Will be filled by caller
|
|
51
|
+
branch: sourceBranch,
|
|
52
|
+
conflictedFiles: status.conflicted,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Some other error
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Merge a single step's branch into target.
|
|
61
|
+
*/
|
|
62
|
+
async mergeStep(stepId, allocation) {
|
|
63
|
+
const git = createGit(this.config.repoPath);
|
|
64
|
+
this.logger.info("Merging step branch", {
|
|
65
|
+
stepId,
|
|
66
|
+
branch: allocation.branch,
|
|
67
|
+
targetBranch: this.config.targetBranch,
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
// Ensure we're on target branch
|
|
71
|
+
await git.checkout(this.config.targetBranch);
|
|
72
|
+
// Check for conflicts first
|
|
73
|
+
const conflict = await this.checkMergeConflicts(allocation.branch, this.config.targetBranch);
|
|
74
|
+
if (conflict) {
|
|
75
|
+
conflict.stepId = stepId;
|
|
76
|
+
this.logger.warn("Merge conflict detected", {
|
|
77
|
+
stepId,
|
|
78
|
+
conflictedFiles: conflict.conflictedFiles,
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
stepId,
|
|
82
|
+
branch: allocation.branch,
|
|
83
|
+
success: false,
|
|
84
|
+
conflict,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Perform the actual merge
|
|
88
|
+
await git.merge([
|
|
89
|
+
allocation.branch,
|
|
90
|
+
"-m",
|
|
91
|
+
`Merge step ${stepId} (${allocation.branch})`,
|
|
92
|
+
]);
|
|
93
|
+
// Get the merge commit hash
|
|
94
|
+
const log = await git.log({ maxCount: 1 });
|
|
95
|
+
const mergeCommit = log.latest?.hash;
|
|
96
|
+
this.logger.info("Step merged successfully", { stepId, mergeCommit });
|
|
97
|
+
return {
|
|
98
|
+
stepId,
|
|
99
|
+
branch: allocation.branch,
|
|
100
|
+
success: true,
|
|
101
|
+
mergeCommit,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
106
|
+
this.logger.error("Merge failed", { stepId, errorMessage: message });
|
|
107
|
+
// Try to abort any in-progress merge
|
|
108
|
+
try {
|
|
109
|
+
await git.raw(["merge", "--abort"]);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Ignore
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
stepId,
|
|
116
|
+
branch: allocation.branch,
|
|
117
|
+
success: false,
|
|
118
|
+
error: message,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Merge all pipeline worktrees in dependency order.
|
|
124
|
+
*/
|
|
125
|
+
async mergeInDependencyOrder(pipelineId, stepAllocations, steps) {
|
|
126
|
+
const mergeOrder = computeMergeOrder(steps);
|
|
127
|
+
const mergedSteps = [];
|
|
128
|
+
const conflicts = [];
|
|
129
|
+
this.logger.info("Starting pipeline merge", {
|
|
130
|
+
pipelineId,
|
|
131
|
+
totalSteps: stepAllocations.size,
|
|
132
|
+
mergeBatches: mergeOrder.length,
|
|
133
|
+
});
|
|
134
|
+
for (let batchIndex = 0; batchIndex < mergeOrder.length; batchIndex++) {
|
|
135
|
+
const batch = mergeOrder[batchIndex];
|
|
136
|
+
this.logger.info("Processing merge batch", { batchIndex, steps: batch });
|
|
137
|
+
for (const stepId of batch) {
|
|
138
|
+
const allocation = stepAllocations.get(stepId);
|
|
139
|
+
if (!allocation) {
|
|
140
|
+
this.logger.warn("No worktree allocation for step", { stepId });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
// Skip steps that didn't need worktrees (reviewers, etc.)
|
|
144
|
+
if (allocation.status !== "completed") {
|
|
145
|
+
this.logger.debug("Skipping step with status", {
|
|
146
|
+
stepId,
|
|
147
|
+
status: allocation.status,
|
|
148
|
+
});
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const result = await this.mergeStep(stepId, allocation);
|
|
152
|
+
if (result.success) {
|
|
153
|
+
mergedSteps.push({
|
|
154
|
+
stepId: result.stepId,
|
|
155
|
+
branch: result.branch,
|
|
156
|
+
mergeCommit: result.mergeCommit,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else if (result.conflict) {
|
|
160
|
+
conflicts.push({
|
|
161
|
+
stepId: result.stepId,
|
|
162
|
+
branch: result.branch,
|
|
163
|
+
conflictedFiles: result.conflict.conflictedFiles,
|
|
164
|
+
error: result.error,
|
|
165
|
+
});
|
|
166
|
+
if (this.config.onConflict === "halt") {
|
|
167
|
+
this.logger.warn("Halting merge due to conflict", { stepId });
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (result.error) {
|
|
172
|
+
conflicts.push({
|
|
173
|
+
stepId: result.stepId,
|
|
174
|
+
branch: result.branch,
|
|
175
|
+
conflictedFiles: [],
|
|
176
|
+
error: result.error,
|
|
177
|
+
});
|
|
178
|
+
if (this.config.onConflict === "halt") {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Check if we should stop due to conflicts
|
|
184
|
+
if (conflicts.length > 0 && this.config.onConflict === "halt") {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const success = conflicts.length === 0;
|
|
189
|
+
this.logger.info("Pipeline merge completed", {
|
|
190
|
+
pipelineId,
|
|
191
|
+
success,
|
|
192
|
+
mergedCount: mergedSteps.length,
|
|
193
|
+
conflictCount: conflicts.length,
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
pipelineId,
|
|
197
|
+
success,
|
|
198
|
+
mergedSteps,
|
|
199
|
+
conflicts,
|
|
200
|
+
completedAt: Date.now(),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Delete branches after successful merge.
|
|
205
|
+
*/
|
|
206
|
+
async cleanupBranches(branches) {
|
|
207
|
+
for (const branch of branches) {
|
|
208
|
+
try {
|
|
209
|
+
await this.branchManager.deleteBranch(branch, true);
|
|
210
|
+
this.logger.debug("Deleted branch", { branch });
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
this.logger.warn("Failed to delete branch", {
|
|
214
|
+
branch,
|
|
215
|
+
error: error instanceof Error ? error.message : String(error),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=pipeline-merge-orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-merge-orchestrator.js","sourceRoot":"","sources":["../../src/worktrees/pipeline-merge-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAuB,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAiC1D,MAAM,OAAO,yBAAyB;IACnB,MAAM,CAA0B;IAChC,aAAa,CAAgB;IAC7B,MAAM,CAAC;IAExB,YAAY,MAA+B;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC;YACrC,QA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