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,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conflict Handler
|
|
3
|
+
*
|
|
4
|
+
* Detects, parses, and resolves git merge conflicts with multiple strategies.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from "fs/promises";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { isInMergeConflict, getConflictedFiles, getMergeHeads, stageFile, completeMerge, abortMerge, checkoutFileVersion, } from "../utils/git.js";
|
|
9
|
+
import { parseConflictsInFile, resolveConflictContent, hasConflictMarkers, } from "./conflict-parser.js";
|
|
10
|
+
import { createLogger } from "../observability/logger.js";
|
|
11
|
+
export class ConflictHandler {
|
|
12
|
+
worktreePath;
|
|
13
|
+
logger;
|
|
14
|
+
cachedConflicts = null;
|
|
15
|
+
constructor(worktreePath) {
|
|
16
|
+
this.worktreePath = worktreePath;
|
|
17
|
+
this.logger = createLogger({ name: "conflict-handler" });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if the worktree has merge conflicts.
|
|
21
|
+
*/
|
|
22
|
+
async hasConflicts() {
|
|
23
|
+
return isInMergeConflict(this.worktreePath);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Detect and parse all conflicts in the worktree.
|
|
27
|
+
*/
|
|
28
|
+
async detectConflicts() {
|
|
29
|
+
const conflictedFiles = await getConflictedFiles(this.worktreePath);
|
|
30
|
+
if (conflictedFiles.length === 0) {
|
|
31
|
+
this.cachedConflicts = new Map();
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
this.logger.info("Detected conflicted files", {
|
|
35
|
+
count: conflictedFiles.length,
|
|
36
|
+
files: conflictedFiles,
|
|
37
|
+
});
|
|
38
|
+
const fileConflicts = [];
|
|
39
|
+
this.cachedConflicts = new Map();
|
|
40
|
+
for (const file of conflictedFiles) {
|
|
41
|
+
const fullPath = path.join(this.worktreePath, file);
|
|
42
|
+
try {
|
|
43
|
+
const markers = await parseConflictsInFile(fullPath);
|
|
44
|
+
this.cachedConflicts.set(file, markers);
|
|
45
|
+
if (markers.length > 0) {
|
|
46
|
+
fileConflicts.push({
|
|
47
|
+
file,
|
|
48
|
+
conflicts: markers,
|
|
49
|
+
totalConflicts: markers.length,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.logger.warn("Failed to parse conflicts in file", { file, error });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return fileConflicts;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get conflict state for tracking.
|
|
61
|
+
*/
|
|
62
|
+
async getConflictState(taskId, worktreeId) {
|
|
63
|
+
const files = await this.detectConflicts();
|
|
64
|
+
return {
|
|
65
|
+
taskId,
|
|
66
|
+
worktreeId,
|
|
67
|
+
detectedAt: Date.now(),
|
|
68
|
+
files,
|
|
69
|
+
totalConflicts: files.reduce((sum, f) => sum + f.totalConflicts, 0),
|
|
70
|
+
resolved: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolve conflicts using the specified strategy.
|
|
75
|
+
*/
|
|
76
|
+
async resolveConflicts(strategy, manualResolutions) {
|
|
77
|
+
this.logger.info("Resolving conflicts", { strategy });
|
|
78
|
+
switch (strategy) {
|
|
79
|
+
case "ours":
|
|
80
|
+
return this.resolveWithOurs();
|
|
81
|
+
case "theirs":
|
|
82
|
+
return this.resolveWithTheirs();
|
|
83
|
+
case "auto":
|
|
84
|
+
return this.resolveWithAuto();
|
|
85
|
+
case "manual":
|
|
86
|
+
if (!manualResolutions || manualResolutions.length === 0) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
strategy,
|
|
90
|
+
resolvedFiles: [],
|
|
91
|
+
remainingConflicts: await this.detectConflicts(),
|
|
92
|
+
error: "Manual resolutions required but none provided",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return this.resolveManually(manualResolutions);
|
|
96
|
+
default:
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
strategy,
|
|
100
|
+
resolvedFiles: [],
|
|
101
|
+
remainingConflicts: await this.detectConflicts(),
|
|
102
|
+
error: `Unknown strategy: ${strategy}`,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolve all conflicts by accepting "ours" (current branch) version.
|
|
108
|
+
*/
|
|
109
|
+
async resolveWithOurs() {
|
|
110
|
+
const conflictedFiles = await getConflictedFiles(this.worktreePath);
|
|
111
|
+
const resolvedFiles = [];
|
|
112
|
+
const errors = [];
|
|
113
|
+
for (const file of conflictedFiles) {
|
|
114
|
+
try {
|
|
115
|
+
await checkoutFileVersion(this.worktreePath, file, "ours");
|
|
116
|
+
await stageFile(this.worktreePath, file);
|
|
117
|
+
resolvedFiles.push(file);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
errors.push(`Failed to resolve ${file}: ${error}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const remaining = await this.detectConflicts();
|
|
124
|
+
return {
|
|
125
|
+
success: remaining.length === 0,
|
|
126
|
+
strategy: "ours",
|
|
127
|
+
resolvedFiles,
|
|
128
|
+
remainingConflicts: remaining,
|
|
129
|
+
error: errors.length > 0 ? errors.join("; ") : undefined,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resolve all conflicts by accepting "theirs" (incoming branch) version.
|
|
134
|
+
*/
|
|
135
|
+
async resolveWithTheirs() {
|
|
136
|
+
const conflictedFiles = await getConflictedFiles(this.worktreePath);
|
|
137
|
+
const resolvedFiles = [];
|
|
138
|
+
const errors = [];
|
|
139
|
+
for (const file of conflictedFiles) {
|
|
140
|
+
try {
|
|
141
|
+
await checkoutFileVersion(this.worktreePath, file, "theirs");
|
|
142
|
+
await stageFile(this.worktreePath, file);
|
|
143
|
+
resolvedFiles.push(file);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
errors.push(`Failed to resolve ${file}: ${error}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const remaining = await this.detectConflicts();
|
|
150
|
+
return {
|
|
151
|
+
success: remaining.length === 0,
|
|
152
|
+
strategy: "theirs",
|
|
153
|
+
resolvedFiles,
|
|
154
|
+
remainingConflicts: remaining,
|
|
155
|
+
error: errors.length > 0 ? errors.join("; ") : undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Attempt automatic resolution by combining non-overlapping changes.
|
|
160
|
+
* Falls back to keeping both versions separated by a marker.
|
|
161
|
+
*/
|
|
162
|
+
async resolveWithAuto() {
|
|
163
|
+
const conflictedFiles = await getConflictedFiles(this.worktreePath);
|
|
164
|
+
const resolvedFiles = [];
|
|
165
|
+
const remainingConflicts = [];
|
|
166
|
+
for (const file of conflictedFiles) {
|
|
167
|
+
const fullPath = path.join(this.worktreePath, file);
|
|
168
|
+
try {
|
|
169
|
+
const content = await fs.readFile(fullPath, "utf-8");
|
|
170
|
+
// For auto strategy, we try to keep both changes
|
|
171
|
+
// This is a simple approach - real auto-merge would be more sophisticated
|
|
172
|
+
const resolved = this.autoMergeContent(content);
|
|
173
|
+
if (!hasConflictMarkers(resolved)) {
|
|
174
|
+
await fs.writeFile(fullPath, resolved);
|
|
175
|
+
await stageFile(this.worktreePath, file);
|
|
176
|
+
resolvedFiles.push(file);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// Still has conflicts - can't auto-resolve
|
|
180
|
+
const markers = await parseConflictsInFile(fullPath);
|
|
181
|
+
remainingConflicts.push({
|
|
182
|
+
file,
|
|
183
|
+
conflicts: markers,
|
|
184
|
+
totalConflicts: markers.length,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
this.logger.warn("Auto-merge failed for file", { file, error });
|
|
190
|
+
const markers = await parseConflictsInFile(fullPath).catch(() => []);
|
|
191
|
+
if (markers.length > 0) {
|
|
192
|
+
remainingConflicts.push({
|
|
193
|
+
file,
|
|
194
|
+
conflicts: markers,
|
|
195
|
+
totalConflicts: markers.length,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
success: remainingConflicts.length === 0,
|
|
202
|
+
strategy: "auto",
|
|
203
|
+
resolvedFiles,
|
|
204
|
+
remainingConflicts,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Simple auto-merge: combine both versions with a separator comment.
|
|
209
|
+
* For code files, this often results in both changes being kept.
|
|
210
|
+
*/
|
|
211
|
+
autoMergeContent(content) {
|
|
212
|
+
// For now, use a simple strategy: keep ours for auto
|
|
213
|
+
// A more sophisticated version could analyze the changes
|
|
214
|
+
return resolveConflictContent(content, "ours");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Apply manual resolutions provided by the user.
|
|
218
|
+
*/
|
|
219
|
+
async resolveManually(resolutions) {
|
|
220
|
+
const resolvedFiles = [];
|
|
221
|
+
const errors = [];
|
|
222
|
+
for (const resolution of resolutions) {
|
|
223
|
+
const fullPath = path.join(this.worktreePath, resolution.file);
|
|
224
|
+
try {
|
|
225
|
+
// Validate no conflict markers in resolved content
|
|
226
|
+
if (hasConflictMarkers(resolution.resolvedContent)) {
|
|
227
|
+
errors.push(`${resolution.file}: Resolved content still contains conflict markers`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
await fs.writeFile(fullPath, resolution.resolvedContent);
|
|
231
|
+
await stageFile(this.worktreePath, resolution.file);
|
|
232
|
+
resolvedFiles.push(resolution.file);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
errors.push(`Failed to apply resolution for ${resolution.file}: ${error}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const remaining = await this.detectConflicts();
|
|
239
|
+
return {
|
|
240
|
+
success: remaining.length === 0 && errors.length === 0,
|
|
241
|
+
strategy: "manual",
|
|
242
|
+
resolvedFiles,
|
|
243
|
+
remainingConflicts: remaining,
|
|
244
|
+
error: errors.length > 0 ? errors.join("; ") : undefined,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Complete the merge after all conflicts are resolved.
|
|
249
|
+
*/
|
|
250
|
+
async completeMerge(message) {
|
|
251
|
+
try {
|
|
252
|
+
const hasConflicts = await this.hasConflicts();
|
|
253
|
+
if (hasConflicts) {
|
|
254
|
+
const remaining = await this.detectConflicts();
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: `Cannot complete merge: ${remaining.length} files still have conflicts`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const commitHash = await completeMerge(this.worktreePath, message);
|
|
261
|
+
this.cachedConflicts = null;
|
|
262
|
+
this.logger.info("Merge completed", { commitHash });
|
|
263
|
+
return { success: true, commitHash };
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
return {
|
|
267
|
+
success: false,
|
|
268
|
+
error: error instanceof Error ? error.message : String(error),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Abort the merge and return to pre-merge state.
|
|
274
|
+
*/
|
|
275
|
+
async abortMerge() {
|
|
276
|
+
await abortMerge(this.worktreePath);
|
|
277
|
+
this.cachedConflicts = null;
|
|
278
|
+
this.logger.info("Merge aborted");
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Get merge head information.
|
|
282
|
+
*/
|
|
283
|
+
async getMergeInfo() {
|
|
284
|
+
return getMergeHeads(this.worktreePath);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=conflict-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-handler.js","sourceRoot":"","sources":["../../src/worktrees/conflict-handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,aAAa,EACb,UAAU,EACV,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAU1D,MAAM,OAAO,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;QAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY;QAMhB,OAAO,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conflict Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses git merge conflict markers from files to extract
|
|
5
|
+
* structured conflict information.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConflictMarker, FileConflict } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parse a single file for conflict markers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseConflictsInFile(filePath: string): Promise<ConflictMarker[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Parse conflict markers from file content.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseConflictMarkers(filePath: string, content: string): ConflictMarker[];
|
|
16
|
+
/**
|
|
17
|
+
* Parse multiple files for conflicts.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseConflictsInFiles(filePaths: string[]): Promise<FileConflict[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Check if file content contains conflict markers.
|
|
22
|
+
*/
|
|
23
|
+
export declare function hasConflictMarkers(content: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Remove conflict markers from content, keeping specified side.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveConflictContent(content: string, strategy: "ours" | "theirs"): string;
|
|
28
|
+
//# sourceMappingURL=conflict-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-parser.d.ts","sourceRoot":"","sources":["../../src/worktrees/conflict-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhE;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,EAAE,CAAC,CAG3B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,cAAc,EAAE,CAwDlB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,YAAY,EAAE,CAAC,CAoBzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAC1B,MAAM,CA6CR"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conflict Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses git merge conflict markers from files to extract
|
|
5
|
+
* structured conflict information.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "fs/promises";
|
|
8
|
+
// Git conflict marker patterns
|
|
9
|
+
const CONFLICT_START = /^<<<<<<<\s*(.*)$/;
|
|
10
|
+
const CONFLICT_SEPARATOR = /^=======$/;
|
|
11
|
+
const CONFLICT_END = /^>>>>>>>\s*(.*)$/;
|
|
12
|
+
/**
|
|
13
|
+
* Parse a single file for conflict markers.
|
|
14
|
+
*/
|
|
15
|
+
export async function parseConflictsInFile(filePath) {
|
|
16
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
17
|
+
return parseConflictMarkers(filePath, content);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse conflict markers from file content.
|
|
21
|
+
*/
|
|
22
|
+
export function parseConflictMarkers(filePath, content) {
|
|
23
|
+
const lines = content.split("\n");
|
|
24
|
+
const conflicts = [];
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < lines.length) {
|
|
27
|
+
const startMatch = lines[i].match(CONFLICT_START);
|
|
28
|
+
if (startMatch) {
|
|
29
|
+
const startLine = i + 1; // 1-indexed
|
|
30
|
+
const oursLabel = startMatch[1] || "HEAD";
|
|
31
|
+
const oursLines = [];
|
|
32
|
+
const theirsLines = [];
|
|
33
|
+
let inOurs = true;
|
|
34
|
+
let theirsLabel = "";
|
|
35
|
+
i++;
|
|
36
|
+
while (i < lines.length) {
|
|
37
|
+
if (CONFLICT_SEPARATOR.test(lines[i])) {
|
|
38
|
+
inOurs = false;
|
|
39
|
+
i++;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const endMatch = lines[i].match(CONFLICT_END);
|
|
43
|
+
if (endMatch) {
|
|
44
|
+
theirsLabel = endMatch[1] || "MERGE_HEAD";
|
|
45
|
+
conflicts.push({
|
|
46
|
+
file: filePath,
|
|
47
|
+
startLine,
|
|
48
|
+
endLine: i + 1, // 1-indexed
|
|
49
|
+
oursContent: oursLines.join("\n"),
|
|
50
|
+
theirsContent: theirsLines.join("\n"),
|
|
51
|
+
oursLabel,
|
|
52
|
+
theirsLabel,
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (inOurs) {
|
|
57
|
+
oursLines.push(lines[i]);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
theirsLines.push(lines[i]);
|
|
61
|
+
}
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
return conflicts;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parse multiple files for conflicts.
|
|
71
|
+
*/
|
|
72
|
+
export async function parseConflictsInFiles(filePaths) {
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const filePath of filePaths) {
|
|
75
|
+
try {
|
|
76
|
+
const conflicts = await parseConflictsInFile(filePath);
|
|
77
|
+
if (conflicts.length > 0) {
|
|
78
|
+
results.push({
|
|
79
|
+
file: filePath,
|
|
80
|
+
conflicts,
|
|
81
|
+
totalConflicts: conflicts.length,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// File might have been deleted or is inaccessible
|
|
87
|
+
console.warn(`Could not parse conflicts in ${filePath}:`, error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return results;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if file content contains conflict markers.
|
|
94
|
+
*/
|
|
95
|
+
export function hasConflictMarkers(content) {
|
|
96
|
+
return CONFLICT_START.test(content) && CONFLICT_END.test(content);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Remove conflict markers from content, keeping specified side.
|
|
100
|
+
*/
|
|
101
|
+
export function resolveConflictContent(content, strategy) {
|
|
102
|
+
const lines = content.split("\n");
|
|
103
|
+
const result = [];
|
|
104
|
+
let i = 0;
|
|
105
|
+
while (i < lines.length) {
|
|
106
|
+
const startMatch = lines[i].match(CONFLICT_START);
|
|
107
|
+
if (startMatch) {
|
|
108
|
+
const oursLines = [];
|
|
109
|
+
const theirsLines = [];
|
|
110
|
+
let inOurs = true;
|
|
111
|
+
i++;
|
|
112
|
+
while (i < lines.length) {
|
|
113
|
+
if (CONFLICT_SEPARATOR.test(lines[i])) {
|
|
114
|
+
inOurs = false;
|
|
115
|
+
i++;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (CONFLICT_END.test(lines[i])) {
|
|
119
|
+
// Add the chosen side's content
|
|
120
|
+
const chosen = strategy === "ours" ? oursLines : theirsLines;
|
|
121
|
+
result.push(...chosen);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
if (inOurs) {
|
|
125
|
+
oursLines.push(lines[i]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
theirsLines.push(lines[i]);
|
|
129
|
+
}
|
|
130
|
+
i++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
result.push(lines[i]);
|
|
135
|
+
}
|
|
136
|
+
i++;
|
|
137
|
+
}
|
|
138
|
+
return result.join("\n");
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=conflict-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-parser.js","sourceRoot":"","sources":["../../src/worktrees/conflict-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlC,+BAA+B;AAC/B,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,kBAAkB,GAAG,WAAW,CAAC;AACvC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAgB;IAEhB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAgB,EAChB,OAAe;IAEf,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,SAAS,GAAqB,EAAE,CAAC;IAEvC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAElD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY;YACrC,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;YAC1C,MAAM,SAAS,GAAa,EAAE,CAAC;YAC/B,MAAM,WAAW,GAAa,EAAE,CAAC;YACjC,IAAI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,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACtC,MAAM,GAAG,KAAK,CAAC;oBACf,CAAC,EAAE,CAAC;oBACJ,SAAS;gBACX,CAAC;gBAED,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChC,gCAAgC;oBAChC,MAAM,MAAM,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;oBAC7D,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;oBACvB,MAAM;gBACR,CAAC;gBAED,IAAI,MAAM,EAAE,CAAC;oBACX,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3B,CAAC;qBAAM,CAAC;oBACN,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,CAAC;gBAED,CAAC,EAAE,CAAC;YACN,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;QAED,CAAC,EAAE,CAAC;IACN,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktrees Module
|
|
3
|
+
*
|
|
4
|
+
* Provides git worktree management for parallel agent execution.
|
|
5
|
+
* Exports the WorktreeManager for lifecycle management,
|
|
6
|
+
* BranchManager for git branch operations, PipelineMergeOrchestrator
|
|
7
|
+
* for ordered merge operations, ConflictHandler for conflict resolution,
|
|
8
|
+
* conflict parser utilities, WorktreePool for pre-warming,
|
|
9
|
+
* and instruction builders for coding agent context.
|
|
10
|
+
*/
|
|
11
|
+
export { WorktreeManager } from "./manager.js";
|
|
12
|
+
export { BranchManager } from "./branch-manager.js";
|
|
13
|
+
export { ResourceManager } from "./resource-manager.js";
|
|
14
|
+
export { WorktreePool, type PoolConfig, type PoolStats, } from "./pool.js";
|
|
15
|
+
export { PipelineMergeOrchestrator, type MergeConflict, type StepMergeResult, type MergeOrchestratorConfig, } from "./pipeline-merge-orchestrator.js";
|
|
16
|
+
export { ConflictHandler } from "./conflict-handler.js";
|
|
17
|
+
export { buildWorktreeInstructions, buildCompactInstructions, injectWorktreeContext, } from "./instructions.js";
|
|
18
|
+
export { parseConflictsInFile, parseConflictMarkers, parseConflictsInFiles, hasConflictMarkers, resolveConflictContent, } from "./conflict-parser.js";
|
|
19
|
+
export { RecoveryManager, type OrphanedWorktree, type OrphanedTask, type OrphanedBranch, type ReconciliationResult, type RecoveryOptions, } from "./recovery.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worktrees/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,yBAAyB,EACzB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,uBAAuB,GAC7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktrees Module
|
|
3
|
+
*
|
|
4
|
+
* Provides git worktree management for parallel agent execution.
|
|
5
|
+
* Exports the WorktreeManager for lifecycle management,
|
|
6
|
+
* BranchManager for git branch operations, PipelineMergeOrchestrator
|
|
7
|
+
* for ordered merge operations, ConflictHandler for conflict resolution,
|
|
8
|
+
* conflict parser utilities, WorktreePool for pre-warming,
|
|
9
|
+
* and instruction builders for coding agent context.
|
|
10
|
+
*/
|
|
11
|
+
export { WorktreeManager } from "./manager.js";
|
|
12
|
+
export { BranchManager } from "./branch-manager.js";
|
|
13
|
+
export { ResourceManager } from "./resource-manager.js";
|
|
14
|
+
export { WorktreePool, } from "./pool.js";
|
|
15
|
+
export { PipelineMergeOrchestrator, } from "./pipeline-merge-orchestrator.js";
|
|
16
|
+
export { ConflictHandler } from "./conflict-handler.js";
|
|
17
|
+
export { buildWorktreeInstructions, buildCompactInstructions, injectWorktreeContext, } from "./instructions.js";
|
|
18
|
+
export { parseConflictsInFile, parseConflictMarkers, parseConflictsInFiles, hasConflictMarkers, resolveConflictContent, } from "./conflict-parser.js";
|
|
19
|
+
export { RecoveryManager, } from "./recovery.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worktrees/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,YAAY,GAGb,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,yBAAyB,GAI1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,GAMhB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree Instructions Builder
|
|
3
|
+
*
|
|
4
|
+
* Generates markdown instructions for coding agents explaining
|
|
5
|
+
* how to work within their assigned git worktree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Worktree, WorktreeInstructions } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build comprehensive worktree instructions for a coding agent
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildWorktreeInstructions(worktree: Worktree): WorktreeInstructions;
|
|
12
|
+
/**
|
|
13
|
+
* Build a compact version of instructions (for context-limited scenarios)
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildCompactInstructions(worktree: Worktree): string;
|
|
16
|
+
/**
|
|
17
|
+
* Inject worktree instructions into an existing prompt
|
|
18
|
+
*/
|
|
19
|
+
export declare function injectWorktreeContext(originalPrompt: string, worktree: Worktree, format?: "full" | "compact"): string;
|
|
20
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/worktrees/instructions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAElE;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,QAAQ,GACjB,oBAAoB,CAkDtB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAOnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,QAAQ,EAClB,MAAM,GAAE,MAAM,GAAG,SAAkB,GAClC,MAAM,CAWR"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree Instructions Builder
|
|
3
|
+
*
|
|
4
|
+
* Generates markdown instructions for coding agents explaining
|
|
5
|
+
* how to work within their assigned git worktree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Build comprehensive worktree instructions for a coding agent
|
|
9
|
+
*/
|
|
10
|
+
export function buildWorktreeInstructions(worktree) {
|
|
11
|
+
const instructions = `
|
|
12
|
+
## 🔧 WORKTREE ENVIRONMENT
|
|
13
|
+
|
|
14
|
+
You are working in an **isolated git worktree**. This ensures your changes don't conflict with other parallel agents.
|
|
15
|
+
|
|
16
|
+
### Your Working Directory
|
|
17
|
+
\`\`\`
|
|
18
|
+
${worktree.path}
|
|
19
|
+
\`\`\`
|
|
20
|
+
|
|
21
|
+
### Git Branch Information
|
|
22
|
+
- **Your Branch**: \`${worktree.branch}\`
|
|
23
|
+
- **Base Branch**: \`${worktree.baseBranch}\`
|
|
24
|
+
|
|
25
|
+
### ⚠️ CRITICAL RULES
|
|
26
|
+
|
|
27
|
+
1. **ALWAYS work within your worktree directory**
|
|
28
|
+
- All file paths should be relative to: \`${worktree.path}\`
|
|
29
|
+
- Do NOT navigate outside this directory
|
|
30
|
+
|
|
31
|
+
2. **Commit your changes frequently**
|
|
32
|
+
- Use commit prefix: \`[${worktree.taskId || "task"}]\`
|
|
33
|
+
- Example: \`git commit -m "[${worktree.taskId || "task"}] Add feature X"\`
|
|
34
|
+
|
|
35
|
+
3. **DO NOT perform these git operations**:
|
|
36
|
+
- ❌ \`git checkout\` to another branch
|
|
37
|
+
- ❌ \`git merge\` or \`git rebase\`
|
|
38
|
+
- ❌ \`git push\` (merging is handled automatically)
|
|
39
|
+
|
|
40
|
+
4. **If you need files from the base branch**:
|
|
41
|
+
- They're already available - your branch was created from \`${worktree.baseBranch}\`
|
|
42
|
+
- If you need latest changes, inform the orchestrator
|
|
43
|
+
|
|
44
|
+
### Example Workflow
|
|
45
|
+
\`\`\`bash
|
|
46
|
+
cd ${worktree.path}
|
|
47
|
+
# Make your changes
|
|
48
|
+
git add .
|
|
49
|
+
git commit -m "[${worktree.taskId || "task"}] Implement feature"
|
|
50
|
+
\`\`\`
|
|
51
|
+
`.trim();
|
|
52
|
+
return {
|
|
53
|
+
workingDirectory: worktree.path,
|
|
54
|
+
branch: worktree.branch,
|
|
55
|
+
baseBranch: worktree.baseBranch,
|
|
56
|
+
commitPrefix: `[${worktree.taskId || "task"}]`,
|
|
57
|
+
instructions,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build a compact version of instructions (for context-limited scenarios)
|
|
62
|
+
*/
|
|
63
|
+
export function buildCompactInstructions(worktree) {
|
|
64
|
+
return `
|
|
65
|
+
WORKTREE: ${worktree.path}
|
|
66
|
+
BRANCH: ${worktree.branch}
|
|
67
|
+
COMMIT PREFIX: [${worktree.taskId || "task"}]
|
|
68
|
+
RULES: Stay in worktree dir, commit with prefix, no checkout/merge/push
|
|
69
|
+
`.trim();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Inject worktree instructions into an existing prompt
|
|
73
|
+
*/
|
|
74
|
+
export function injectWorktreeContext(originalPrompt, worktree, format = "full") {
|
|
75
|
+
const instructions = format === "full"
|
|
76
|
+
? buildWorktreeInstructions(worktree).instructions
|
|
77
|
+
: buildCompactInstructions(worktree);
|
|
78
|
+
return `${instructions}
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
${originalPrompt}`;
|
|
83
|
+
}
|
|
84
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