@mdsohail99/opencode-agent-teams 0.0.0-stage → 2.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/AGENTS.md +123 -0
- package/CHANGELOG.md +137 -0
- package/LICENSE +21 -0
- package/README.md +350 -2
- package/agents/orchestrators/agent-teams.md +198 -0
- package/agents/orchestrators/ai-data.md +91 -0
- package/agents/orchestrators/backend.md +109 -0
- package/agents/orchestrators/devops.md +89 -0
- package/agents/orchestrators/frontend.md +117 -0
- package/agents/orchestrators/qa.md +89 -0
- package/agents/orchestrators/security.md +98 -0
- package/agents/orchestrators-fork/orchestrator-agent-teams.md +203 -0
- package/agents/specialists/accessibility-auditor.md +322 -0
- package/agents/specialists/ai-engineer.md +152 -0
- package/agents/specialists/ai-generated-code-security-auditor.md +213 -0
- package/agents/specialists/api-platform-engineer.md +169 -0
- package/agents/specialists/api-tester.md +311 -0
- package/agents/specialists/application-security-engineer.md +497 -0
- package/agents/specialists/backend-architect.md +242 -0
- package/agents/specialists/brand-guardian.md +327 -0
- package/agents/specialists/cloud-security-architect.md +526 -0
- package/agents/specialists/code-reviewer.md +83 -0
- package/agents/specialists/codebase-archaeologist.md +347 -0
- package/agents/specialists/codebase-onboarding-engineer.md +180 -0
- package/agents/specialists/compliance-auditor.md +165 -0
- package/agents/specialists/data-engineer.md +312 -0
- package/agents/specialists/data-visualization-engineer.md +158 -0
- package/agents/specialists/database-optimizer.md +183 -0
- package/agents/specialists/database-reliability-engineer.md +169 -0
- package/agents/specialists/desktop-app-engineer.md +211 -0
- package/agents/specialists/developer-tooling-engineer.md +160 -0
- package/agents/specialists/devops-automator.md +380 -0
- package/agents/specialists/finops-engineer.md +160 -0
- package/agents/specialists/frontend-developer.md +230 -0
- package/agents/specialists/git-workflow-master.md +91 -0
- package/agents/specialists/image-prompt-engineer.md +242 -0
- package/agents/specialists/incident-responder.md +443 -0
- package/agents/specialists/incident-response-commander.md +448 -0
- package/agents/specialists/inclusive-visuals-specialist.md +78 -0
- package/agents/specialists/internationalization-engineer.md +191 -0
- package/agents/specialists/iot-fleet-engineer.md +155 -0
- package/agents/specialists/llm-post-training-engineer.md +172 -0
- package/agents/specialists/mcp-builder.md +254 -0
- package/agents/specialists/minimal-change-engineer.md +213 -0
- package/agents/specialists/mobile-app-builder.md +498 -0
- package/agents/specialists/multi-agent-systems-architect.md +593 -0
- package/agents/specialists/payments-billing-engineer.md +201 -0
- package/agents/specialists/penetration-tester.md +405 -0
- package/agents/specialists/performance-benchmarker.md +273 -0
- package/agents/specialists/persona-walkthrough-specialist.md +275 -0
- package/agents/specialists/privacy-engineer.md +159 -0
- package/agents/specialists/prompt-engineer.md +208 -0
- package/agents/specialists/rag-pipeline-engineer.md +435 -0
- package/agents/specialists/rapid-prototyper.md +467 -0
- package/agents/specialists/reality-checker.md +240 -0
- package/agents/specialists/realtime-collaboration-engineer.md +194 -0
- package/agents/specialists/rust-refactoring-specialist.md +320 -0
- package/agents/specialists/search-relevance-engineer.md +244 -0
- package/agents/specialists/secrets-credential-hygiene-engineer.md +182 -0
- package/agents/specialists/section-508-accessibility-specialist.md +338 -0
- package/agents/specialists/security-architect.md +310 -0
- package/agents/specialists/software-architect.md +119 -0
- package/agents/specialists/sre-site-reliability-engineer.md +97 -0
- package/agents/specialists/technical-writer.md +398 -0
- package/agents/specialists/test-automation-engineer.md +186 -0
- package/agents/specialists/test-results-analyzer.md +310 -0
- package/agents/specialists/threat-detection-engineer.md +540 -0
- package/agents/specialists/ui-designer.md +388 -0
- package/agents/specialists/ui-finish-gate-reviewer.md +220 -0
- package/agents/specialists/uswds-developer.md +339 -0
- package/agents/specialists/ux-architect.md +474 -0
- package/agents/specialists/ux-researcher.md +334 -0
- package/agents/specialists/video-streaming-engineer.md +157 -0
- package/agents/specialists/visual-storyteller.md +155 -0
- package/agents/specialists/web-gis-developer.md +115 -0
- package/agents/specialists/webassembly-engineer.md +163 -0
- package/agents/specialists/wechat-mini-program-developer.md +356 -0
- package/agents/specialists/whimsy-injector.md +444 -0
- package/agents/specialists/workflow-architect.md +590 -0
- package/bin/cli.js +351 -0
- package/bin/install.mjs +418 -0
- package/bin/lib/config-root.mjs +51 -0
- package/bin/lib/merge-commands.mjs +138 -0
- package/bin/lib/merge-env-flags.mjs +92 -0
- package/bin/lib/merge-schema.mjs +77 -0
- package/bin/lib/merge-subagent-depth.mjs +133 -0
- package/bin/lib/plugin-park.mjs +48 -0
- package/bin/lib/relay-process.mjs +116 -0
- package/bin/lib/runtime-state.mjs +118 -0
- package/bin/menu.mjs +582 -0
- package/bin/uninstall.mjs +360 -0
- package/package.json +50 -4
- package/src/index.ts +115 -0
- package/src/state/tracker.ts +102 -0
- package/src/tools/broadcast.ts +58 -0
- package/src/tools/delegate.ts +154 -0
- package/src/tools/status.ts +25 -0
- package/src/tools/terminate.ts +70 -0
- package/src/tui.ts +9 -0
- package/src/worktree/manager.ts +142 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import type { Plugin } from "@opencode/plugin"
|
|
3
|
+
import { globalTracker, type TeamMember } from "../state/tracker.js"
|
|
4
|
+
import { WorktreeManager, type WorktreeSandbox } from "../worktree/manager.js"
|
|
5
|
+
import crypto from "node:crypto"
|
|
6
|
+
|
|
7
|
+
export const DelegateInput = Schema.Struct({
|
|
8
|
+
team_name: Schema.String.annotate({
|
|
9
|
+
description: "Departmental team name (e.g. 'Backend', 'Frontend', 'Security', 'QA', 'DevOps')",
|
|
10
|
+
}),
|
|
11
|
+
agent_type: Schema.String.annotate({
|
|
12
|
+
description: "Specialist agent name or role (e.g. 'backend-architect', 'frontend-developer', 'api-tester')",
|
|
13
|
+
}),
|
|
14
|
+
prompt: Schema.String.annotate({
|
|
15
|
+
description: "Detailed instructions and requirements for the teammate",
|
|
16
|
+
}),
|
|
17
|
+
worktree: Schema.optional(Schema.Boolean).annotate({
|
|
18
|
+
description: "Whether to run this task in an isolated git worktree to prevent concurrent write collisions (default: true)",
|
|
19
|
+
}),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
function normalizeAgentId(raw: string): string {
|
|
23
|
+
if (!raw) return "build"
|
|
24
|
+
return raw
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.trim()
|
|
27
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
28
|
+
.replace(/^-|-$/g, "")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createDelegateTool(ctx: Plugin.Context) {
|
|
32
|
+
return {
|
|
33
|
+
id: "team_delegate",
|
|
34
|
+
name: "team_delegate",
|
|
35
|
+
description: "Delegate a task to a departmental teammate with optional git worktree sandboxing.",
|
|
36
|
+
input: DelegateInput,
|
|
37
|
+
execute: async (
|
|
38
|
+
input: { team_name: string; agent_type: string; prompt: string; worktree?: boolean },
|
|
39
|
+
toolCtx: { sessionID: string },
|
|
40
|
+
) => {
|
|
41
|
+
const taskId = crypto.randomUUID().slice(0, 8)
|
|
42
|
+
const baseDir = process.cwd()
|
|
43
|
+
const useWorktree = input.worktree !== false
|
|
44
|
+
const targetAgentId = normalizeAgentId(input.agent_type)
|
|
45
|
+
|
|
46
|
+
let sandbox: WorktreeSandbox | undefined
|
|
47
|
+
let workDir = baseDir
|
|
48
|
+
|
|
49
|
+
if (useWorktree) {
|
|
50
|
+
try {
|
|
51
|
+
sandbox = await WorktreeManager.createSandbox(baseDir, input.team_name, taskId)
|
|
52
|
+
workDir = sandbox.worktreePath
|
|
53
|
+
} catch (err: any) {
|
|
54
|
+
// If worktree creation fails (e.g. not a git repo), gracefully fallback to baseDir
|
|
55
|
+
workDir = baseDir
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Create child session via OpenCode v2 session API
|
|
60
|
+
let childSession: any
|
|
61
|
+
try {
|
|
62
|
+
childSession = await ctx.session.create({
|
|
63
|
+
agent: targetAgentId,
|
|
64
|
+
parentID: toolCtx.sessionID,
|
|
65
|
+
location: { directory: workDir },
|
|
66
|
+
} as any)
|
|
67
|
+
} catch (err: any) {
|
|
68
|
+
if (sandbox) {
|
|
69
|
+
await WorktreeManager.discardSandbox(baseDir, sandbox)
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
content: `Failed to spawn teammate session for ${input.team_name} (${targetAgentId}): ${err.message || String(err)}`,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const sessionId = childSession?.id || `sess_${taskId}`
|
|
77
|
+
const memberRecord: TeamMember = {
|
|
78
|
+
id: taskId,
|
|
79
|
+
teamName: input.team_name,
|
|
80
|
+
agentType: targetAgentId,
|
|
81
|
+
sessionId,
|
|
82
|
+
parentSessionId: toolCtx.sessionID,
|
|
83
|
+
status: "running",
|
|
84
|
+
prompt: input.prompt,
|
|
85
|
+
worktreePath: sandbox?.worktreePath,
|
|
86
|
+
worktreeBranch: sandbox?.branchName,
|
|
87
|
+
createdAt: Date.now(),
|
|
88
|
+
}
|
|
89
|
+
globalTracker.register(memberRecord)
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// Dispatch task text to subagent (OpenCode v2 SessionPromptInput takes 'text')
|
|
93
|
+
const promptResult = await ctx.session.prompt({
|
|
94
|
+
sessionID: sessionId,
|
|
95
|
+
text: input.prompt,
|
|
96
|
+
} as any)
|
|
97
|
+
|
|
98
|
+
if ((ctx.session as any)?.wait) {
|
|
99
|
+
try {
|
|
100
|
+
await (ctx.session as any).wait({ sessionID: sessionId })
|
|
101
|
+
} catch {
|
|
102
|
+
// Non-fatal if wait is unsupported or timed out
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let deliverableText =
|
|
107
|
+
(promptResult as any)?.text ||
|
|
108
|
+
(promptResult as any)?.content ||
|
|
109
|
+
"Task execution dispatched."
|
|
110
|
+
|
|
111
|
+
// If a worktree was used, reconcile and merge changes back to base branch
|
|
112
|
+
let reconcileNotice = ""
|
|
113
|
+
if (sandbox) {
|
|
114
|
+
const shortDesc = input.prompt.replace(/\s+/g, " ").slice(0, 60)
|
|
115
|
+
const reconcile = await WorktreeManager.reconcileAndCleanup(
|
|
116
|
+
baseDir,
|
|
117
|
+
sandbox,
|
|
118
|
+
`feat(${input.team_name.toLowerCase()}): ${shortDesc}`,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
if (reconcile.merged) {
|
|
122
|
+
reconcileNotice = `\n[Git]: Successfully merged changes from ${sandbox.branchName} into ${sandbox.baseBranch}. Worktree cleaned up.`
|
|
123
|
+
} else if (reconcile.error) {
|
|
124
|
+
reconcileNotice = `\n[Git Warning]: ${reconcile.error}`
|
|
125
|
+
} else {
|
|
126
|
+
reconcileNotice = `\n[Git]: No file modifications detected; worktree discarded.`
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
globalTracker.update(sessionId, {
|
|
131
|
+
status: "completed",
|
|
132
|
+
finishedAt: Date.now(),
|
|
133
|
+
deliverable: deliverableText,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
content: `[Teammate Completed] ${input.team_name} (${targetAgentId}):\n${deliverableText}${reconcileNotice}`,
|
|
138
|
+
}
|
|
139
|
+
} catch (err: any) {
|
|
140
|
+
if (sandbox) {
|
|
141
|
+
await WorktreeManager.discardSandbox(baseDir, sandbox)
|
|
142
|
+
}
|
|
143
|
+
globalTracker.update(sessionId, {
|
|
144
|
+
status: "error",
|
|
145
|
+
finishedAt: Date.now(),
|
|
146
|
+
error: err?.message || String(err),
|
|
147
|
+
})
|
|
148
|
+
return {
|
|
149
|
+
content: `[Teammate Error] ${input.team_name} (${targetAgentId}) failed: ${err.message || String(err)}`,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import type { Plugin } from "@opencode/plugin"
|
|
3
|
+
import { globalTracker } from "../state/tracker.js"
|
|
4
|
+
|
|
5
|
+
export const StatusInput = Schema.Struct({
|
|
6
|
+
team_name: Schema.optional(Schema.String).annotate({
|
|
7
|
+
description: "Filter status query to a specific department (optional)",
|
|
8
|
+
}),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export function createStatusTool(ctx: Plugin.Context) {
|
|
12
|
+
return {
|
|
13
|
+
id: "team_status",
|
|
14
|
+
name: "team_status",
|
|
15
|
+
description:
|
|
16
|
+
"Inspect current progress, deliverables, active git worktrees, and hierarchy of all teammates in the swarm.",
|
|
17
|
+
input: StatusInput,
|
|
18
|
+
execute: async (input: { team_name?: string }, toolCtx: { sessionID: string }) => {
|
|
19
|
+
const tree = globalTracker.formatTree(toolCtx.sessionID)
|
|
20
|
+
return {
|
|
21
|
+
content: tree,
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import type { Plugin } from "@opencode/plugin"
|
|
3
|
+
import { globalTracker } from "../state/tracker.js"
|
|
4
|
+
import { WorktreeManager } from "../worktree/manager.js"
|
|
5
|
+
|
|
6
|
+
export const TerminateInput = Schema.Struct({
|
|
7
|
+
target: Schema.String.annotate({
|
|
8
|
+
description: "Teammate ID, team name (e.g. 'Frontend'), or 'all' to terminate all running workers",
|
|
9
|
+
}),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export function createTerminateTool(ctx: Plugin.Context) {
|
|
13
|
+
return {
|
|
14
|
+
id: "team_terminate",
|
|
15
|
+
name: "team_terminate",
|
|
16
|
+
description:
|
|
17
|
+
"Gracefully abort/terminate a running teammate and trigger git worktree cleanup.",
|
|
18
|
+
input: TerminateInput,
|
|
19
|
+
execute: async (input: { target: string }, toolCtx: { sessionID: string }) => {
|
|
20
|
+
const allMembers = globalTracker.list(toolCtx.sessionID)
|
|
21
|
+
const isAll = input.target.toLowerCase() === "all"
|
|
22
|
+
|
|
23
|
+
const targets = allMembers.filter((m) => {
|
|
24
|
+
if (m.status !== "running") return false
|
|
25
|
+
if (isAll) return true
|
|
26
|
+
return (
|
|
27
|
+
m.id === input.target ||
|
|
28
|
+
m.sessionId === input.target ||
|
|
29
|
+
m.teamName.toLowerCase() === input.target.toLowerCase()
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
if (targets.length === 0) {
|
|
34
|
+
return {
|
|
35
|
+
content: `No active running teammates matched target '${input.target}'.`,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const terminated: string[] = []
|
|
40
|
+
const baseDir = process.cwd()
|
|
41
|
+
|
|
42
|
+
for (const member of targets) {
|
|
43
|
+
try {
|
|
44
|
+
if (ctx.session.interrupt) {
|
|
45
|
+
await ctx.session.interrupt({ sessionID: member.sessionId } as any)
|
|
46
|
+
}
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
if (member.worktreePath && member.worktreeBranch) {
|
|
50
|
+
await WorktreeManager.discardSandbox(baseDir, {
|
|
51
|
+
worktreePath: member.worktreePath,
|
|
52
|
+
branchName: member.worktreeBranch,
|
|
53
|
+
baseBranch: "main",
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
globalTracker.update(member.sessionId, {
|
|
58
|
+
status: "terminated",
|
|
59
|
+
finishedAt: Date.now(),
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
terminated.push(`${member.teamName} (${member.id})`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
content: `Terminated and cleaned up ${terminated.length} teammate(s): ${terminated.join(", ")}`,
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/tui.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { execFile } from "node:child_process"
|
|
2
|
+
import { promisify } from "node:util"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import fs from "node:fs/promises"
|
|
5
|
+
|
|
6
|
+
const exec = promisify(execFile)
|
|
7
|
+
|
|
8
|
+
export interface WorktreeSandbox {
|
|
9
|
+
worktreePath: string
|
|
10
|
+
branchName: string
|
|
11
|
+
baseBranch: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ReconcileResult {
|
|
15
|
+
success: boolean
|
|
16
|
+
merged: boolean
|
|
17
|
+
commitHash?: string
|
|
18
|
+
error?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class WorktreeManager {
|
|
22
|
+
static async getCurrentBranch(cwd: string): Promise<string> {
|
|
23
|
+
try {
|
|
24
|
+
const { stdout } = await exec("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd })
|
|
25
|
+
return stdout.trim() || "main"
|
|
26
|
+
} catch {
|
|
27
|
+
return "main"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static async createSandbox(
|
|
32
|
+
baseDir: string,
|
|
33
|
+
teamName: string,
|
|
34
|
+
taskId: string,
|
|
35
|
+
): Promise<WorktreeSandbox> {
|
|
36
|
+
const baseBranch = await this.getCurrentBranch(baseDir)
|
|
37
|
+
const sanitizedTeam = teamName.toLowerCase().replace(/[^a-z0-9]/g, "-")
|
|
38
|
+
const shortId = taskId.replace(/[^a-z0-9]/gi, "").slice(-6)
|
|
39
|
+
const branchName = `agent/${sanitizedTeam}-${shortId}`
|
|
40
|
+
|
|
41
|
+
const worktreeDir = path.join(baseDir, ".opencode", "worktrees", `${sanitizedTeam}-${shortId}`)
|
|
42
|
+
await fs.mkdir(path.dirname(worktreeDir), { recursive: true })
|
|
43
|
+
|
|
44
|
+
// Clean up any stale worktree or branch with identical name
|
|
45
|
+
try {
|
|
46
|
+
await exec("git", ["worktree", "remove", "--force", worktreeDir], { cwd: baseDir })
|
|
47
|
+
} catch {}
|
|
48
|
+
try {
|
|
49
|
+
await exec("git", ["branch", "-D", branchName], { cwd: baseDir })
|
|
50
|
+
} catch {}
|
|
51
|
+
|
|
52
|
+
// Create the worktree on a new branch branched off HEAD
|
|
53
|
+
await exec("git", ["worktree", "add", "-b", branchName, worktreeDir, "HEAD"], { cwd: baseDir })
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
worktreePath: worktreeDir,
|
|
57
|
+
branchName,
|
|
58
|
+
baseBranch,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static async reconcileAndCleanup(
|
|
63
|
+
baseDir: string,
|
|
64
|
+
sandbox: WorktreeSandbox,
|
|
65
|
+
commitMessage: string,
|
|
66
|
+
): Promise<ReconcileResult> {
|
|
67
|
+
const { worktreePath, branchName, baseBranch } = sandbox
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
// 1. Check for modifications inside the worktree
|
|
71
|
+
const { stdout: status } = await exec("git", ["status", "--porcelain"], {
|
|
72
|
+
cwd: worktreePath,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
let committed = false
|
|
76
|
+
if (status.trim().length > 0) {
|
|
77
|
+
await exec("git", ["add", "-A"], { cwd: worktreePath })
|
|
78
|
+
await exec("git", ["commit", "-m", commitMessage], { cwd: worktreePath })
|
|
79
|
+
committed = true
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 2. If nothing changed, just remove the worktree and branch
|
|
83
|
+
if (!committed) {
|
|
84
|
+
await this.discardSandbox(baseDir, sandbox)
|
|
85
|
+
return { success: true, merged: false }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 3. Obtain latest commit hash from the agent branch
|
|
89
|
+
const { stdout: hashOut } = await exec("git", ["rev-parse", "HEAD"], { cwd: worktreePath })
|
|
90
|
+
const commitHash = hashOut.trim()
|
|
91
|
+
|
|
92
|
+
// 4. Merge back to the base branch in baseDir
|
|
93
|
+
try {
|
|
94
|
+
await exec(
|
|
95
|
+
"git",
|
|
96
|
+
["merge", "--no-ff", "-m", `Merge ${branchName}: ${commitMessage}`, branchName],
|
|
97
|
+
{ cwd: baseDir },
|
|
98
|
+
)
|
|
99
|
+
} catch (mergeErr: any) {
|
|
100
|
+
// Conflict detected — abort merge in base repo and preserve branch for review
|
|
101
|
+
try {
|
|
102
|
+
await exec("git", ["merge", "--abort"], { cwd: baseDir })
|
|
103
|
+
} catch {}
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
merged: false,
|
|
107
|
+
commitHash,
|
|
108
|
+
error: `Merge conflict integrating ${branchName} into ${baseBranch}. Branch preserved for inspection.`,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 5. Successful merge — cleanup worktree and delete ephemeral branch
|
|
113
|
+
await exec("git", ["worktree", "remove", "--force", worktreePath], { cwd: baseDir })
|
|
114
|
+
try {
|
|
115
|
+
await exec("git", ["branch", "-d", branchName], { cwd: baseDir })
|
|
116
|
+
} catch {
|
|
117
|
+
await exec("git", ["branch", "-D", branchName], { cwd: baseDir })
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
success: true,
|
|
122
|
+
merged: true,
|
|
123
|
+
commitHash,
|
|
124
|
+
}
|
|
125
|
+
} catch (err: any) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
merged: false,
|
|
129
|
+
error: err?.message || String(err),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static async discardSandbox(baseDir: string, sandbox: WorktreeSandbox): Promise<void> {
|
|
135
|
+
try {
|
|
136
|
+
await exec("git", ["worktree", "remove", "--force", sandbox.worktreePath], { cwd: baseDir })
|
|
137
|
+
} catch {}
|
|
138
|
+
try {
|
|
139
|
+
await exec("git", ["branch", "-D", sandbox.branchName], { cwd: baseDir })
|
|
140
|
+
} catch {}
|
|
141
|
+
}
|
|
142
|
+
}
|