ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
feat: add merge conflict resolve skill and trigger (#34)
Fynn FlΓΌggef985f5fb1175
diff --git a/CLAUDE.md b/CLAUDE.mdindex 8496fb5..142e912 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -284,6 +284,15 @@ Plugin defaults to the project's active plugin (set via `P` on the board).- Git diffs (`{slug}.diff`) from `git diff main..{branch}`- Worktree files (`.agtx/skills/`, `.planning/`) if the referenced worktree still exists+### Auto Merge-Conflict Resolution+- During `apply_session_refresh`, Review tasks are checked for merge conflicts with the default branch (main/master)+- Uses `git merge-tree --write-tree` (Git 2.38+) for a non-destructive virtual merge check β does not modify the worktree+- Triggers when a Review task becomes **newly Ready** or has been **Idle for 30+ seconds**+- If conflicts detected, sends the `/agtx:merge-conflicts` skill + prompt to the agent's tmux session+- One-shot per task: `merge_conflict_checked: HashSet<String>` guard ensures each task is only checked once+- Works with all plugins β the merge-conflicts skill is a builtin skill deployed to every worktree+- The skill instructs the agent to: commit current work β merge origin/main β resolve conflicts β review only conflicted files against both parents β run tests+### Agent Integration- Agents spawned via `build_interactive_command()` in `src/agent/mod.rs`- Each agent has its own flags: Claude (`--dangerously-skip-permissions`), Codex (`--approval-mode full-auto`), Gemini (`--approval-mode yolo`), Copilot (`--allow-all-tools`)diff --git a/README.md b/README.mdindex 0b4d33e..ada31d2 100644--- a/README.md+++ b/README.md@@ -116,6 +116,7 @@ When writing a task description, you can reference files, skills, and other task- Sessions automatically resume when moving Review β Running- Full conversation context is preserved across the task lifecycle- View live agent output in the task popup+- **Auto merge-conflict resolution**: When a Review task becomes idle, agtx checks for merge conflicts with the default branch. If conflicts are detected, the agent is automatically instructed to resolve them.## Configurationdiff --git a/plugins/agtx/skills/merge-conflicts.md b/plugins/agtx/skills/merge-conflicts.mdnew file mode 100644index 0000000..9512a6a--- /dev/null+++ b/plugins/agtx/skills/merge-conflicts.md@@ -0,0 +1,52 @@+---+name: agtx-merge-conflicts+description: Resolve merge conflicts by merging the default branch into the current feature branch.+---++# Merge Conflict Resolution++Your feature branch has **merge conflicts** with the default branch (main/master).++## Instructions++1. First, commit all current work so nothing is lost:+ - Review the staged/unstaged changes with `git diff` and `git diff --cached`+ - Write a descriptive commit message that summarizes the actual changes+ - `git add -A && git commit -m "<your message>"`+ - If there is nothing to commit, skip this step.++2. Merge the default branch into your current branch:+ ```bash+ git fetch origin+ git merge origin/main+ ```+ If the project uses `master` instead of `main`, use `origin/master`.++3. Resolve ALL merge conflicts:+ - **Before resolving**, note which files have conflicts: `git diff --name-only --diff-filter=U`+ - Open each conflicted file+ - Remove conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`)+ - Choose the correct resolution for each conflict, preserving both sides' intent when possible++4. After resolving all conflicts:+ - `git add -A && git commit --no-edit`++5. **Review only the conflicted files** to catch resolution mistakes:+ - For each file that had conflicts (from step 3), compare your resolution against both parents:+ - `git diff HEAD^2..HEAD -- <file>` (what changed vs the default branch β shows only your feature's additions). **Start here** β this is usually the smaller, more focused diff.+ - `git diff HEAD^1..HEAD -- <file>` (what changed vs your branch before merge β shows what main brought in). This can be very large; if so, focus on the areas around the conflict markers you resolved rather than reading the entire diff.+ - Verify:+ - No code was accidentally dropped from either side+ - The combined logic is coherent (e.g., imports, function signatures, variable names all consistent)+ - No duplicate code blocks were introduced+ - If you find a problem, fix it immediately and commit the fix separately++6. Run tests to verify nothing is broken. Fix any issues introduced by the merge.++## Rules++- **Always merge, never rebase.** The branch may have been shared or pushed.+- Do NOT squash commits.+- Do NOT force push.+- After committing the merge, say: "Merge conflicts resolved and committed."+- Then **stop and wait** for further instructions.diff --git a/src/git/operations.rs b/src/git/operations.rsindex 8a94ccc..34a680c 100644--- a/src/git/operations.rs+++ b/src/git/operations.rs@@ -48,6 +48,11 @@ pub trait GitOperations: Send + Sync {/// Push branch to originfn push(&self, worktree_path: &Path, branch: &str, set_upstream: bool) -> Result<()>;+ /// Fetch from origin and check if the feature branch has merge conflicts with the default branch.+ /// Uses `git merge-tree --write-tree` (Git 2.38+) which does NOT modify the working tree.+ /// Returns Ok(true) if conflicts exist, Ok(false) if clean merge.+ fn fetch_and_check_conflicts(&self, worktree_path: &Path) -> Result<bool>;+/// List all files (tracked + untracked, respects .gitignore)fn list_files(&self, project_path: &Path) -> Vec<String>;@@ -190,6 +195,40 @@ impl GitOperations for RealGitOps {Ok(())}+ fn fetch_and_check_conflicts(&self, worktree_path: &Path) -> Result<bool> {+ // 1. Fetch latest from origin+ let fetch = std::process::Command::new("git")+ .current_dir(worktree_path)+ .args(["fetch", "origin"])+ .output()?;+ if !fetch.status.success() {+ let stderr = String::from_utf8_lossy(&fetch.stderr);+ anyhow::bail!("git fetch failed: {}", stderr);+ }++ // 2. Detect default branch on remote (origin/main or origin/master)+ let main_ref = if std::process::Command::new("git")+ .current_dir(worktree_path)+ .args(["rev-parse", "--verify", "origin/main"])+ .output()+ .map(|o| o.status.success())+ .unwrap_or(false)+ {+ "origin/main"+ } else {+ "origin/master"+ };++ // 3. Virtual merge check (Git 2.38+) β does not modify working tree+ let merge_tree = std::process::Command::new("git")+ .current_dir(worktree_path)+ .args(["merge-tree", "--write-tree", "HEAD", main_ref])+ .output()?;++ // Exit 0 = clean merge, non-zero = conflicts+ Ok(!merge_tree.status.success())+ }+fn list_files(&self, project_path: &Path) -> Vec<String> {std::process::Command::new("git").current_dir(project_path)diff --git a/src/skills.rs b/src/skills.rsindex 550ee9b..6e529fe 100644--- a/src/skills.rs+++ b/src/skills.rs@@ -6,6 +6,7 @@ pub const RESEARCH_SKILL: &str = include_str!("../plugins/agtx/skills/research.mpub const PLAN_SKILL: &str = include_str!("../plugins/agtx/skills/plan.md");pub const EXECUTE_SKILL: &str = include_str!("../plugins/agtx/skills/execute.md");pub const REVIEW_SKILL: &str = include_str!("../plugins/agtx/skills/review.md");+pub const MERGE_CONFLICTS_SKILL: &str = include_str!("../plugins/agtx/skills/merge-conflicts.md");/// Default built-in skills: (directory_name, SKILL.md content)/// Used for worktree phases (Research, Planning, Running, Review)@@ -14,6 +15,7 @@ pub const BUILTIN_SKILLS: &[(&str, &str)] = &[("agtx-plan", PLAN_SKILL),("agtx-execute", EXECUTE_SKILL),("agtx-review", REVIEW_SKILL),+ ("agtx-merge-conflicts", MERGE_CONFLICTS_SKILL),];/// Load a bundled plugin by name from compile-time embedded TOML.diff --git a/src/tui/app.rs b/src/tui/app.rsindex 1540aff..db5a46c 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -232,6 +232,8 @@ struct AppState {spinner_frame: usize,// Idle detection: (content_hash, last_change_time) per taskpane_content_hashes: HashMap<String, (u64, Instant)>,+ // Guard: task IDs for which merge-conflict check has already been performed+ merge_conflict_checked: HashSet<String>,cached_plugin: Option<Option<WorkflowPlugin>>,// Transient warning message shown in footer (auto-clears after a few seconds)warning_message: Option<(String, Instant)>,@@ -292,6 +294,16 @@ struct SessionTaskStatus {phase_status: PhaseStatus,/// Content hash from tmux capture (for idle detection on main thread).content_hash: Option<u64>,+ /// Task status (needed for merge-conflict check on main thread).+ status: TaskStatus,+ /// Worktree path (needed for merge-conflict check).+ worktree_path: Option<String>,+ /// Tmux session name (needed for merge-conflict check).+ session_name: Option<String>,+ /// Agent name (needed for merge-conflict skill dispatch).+ agent: String,+ /// Whether this task was already Ready before this refresh cycle.+ was_ready: bool,}/// Results sent back from the background session refresh thread.@@ -526,6 +538,7 @@ impl App {phase_status_cache: HashMap::new(),spinner_frame: 0,pane_content_hashes: HashMap::new(),+ merge_conflict_checked: HashSet::new(),cached_plugin: None,warning_message: None,plugin_select_popup: None,@@ -625,6 +638,7 @@ impl App {phase_status_cache: HashMap::new(),spinner_frame: 0,pane_content_hashes: HashMap::new(),+ merge_conflict_checked: HashSet::new(),cached_plugin: None,warning_message: None,plugin_select_popup: None,@@ -4220,7 +4234,7 @@ impl App {.map(|t| {let was_ready = self.state.phase_status_cache.get(&t.id).map_or(false, |(prev, _)| *prev == PhaseStatus::Ready);- (t.id.clone(), t.status, t.worktree_path.clone(), t.plugin.clone(), t.session_name.clone(), t.cycle, was_ready)+ (t.id.clone(), t.status, t.worktree_path.clone(), t.plugin.clone(), t.session_name.clone(), t.cycle, was_ready, t.agent.clone())}).collect();@@ -4239,7 +4253,7 @@ impl App {let mut plugin_cache: HashMap<Option<String>, Option<WorkflowPlugin>> = HashMap::new();let mut statuses = Vec::new();- for (task_id, status, worktree_path, task_plugin, session_name, cycle, was_ready) in tasks_to_check {+ for (task_id, status, worktree_path, task_plugin, session_name, cycle, was_ready, agent) in tasks_to_check {let plugin = plugin_cache.entry(task_plugin.clone()).or_insert_with(|| {match &task_plugin {Some(name) => WorkflowPlugin::load(name, project_path.as_deref()).ok(),@@ -4314,6 +4328,11 @@ impl App {task_id,phase_status,content_hash,+ status,+ worktree_path,+ session_name,+ agent,+ was_ready,});}@@ -4344,7 +4363,58 @@ impl App {self.state.pane_content_hashes.remove(&task_status.task_id);}- self.state.phase_status_cache.insert(task_status.task_id, (phase, now));+ self.state.phase_status_cache.insert(task_status.task_id.clone(), (phase, now));++ // Auto merge-conflict check for Review tasks+ if task_status.status == TaskStatus::Review && !self.state.merge_conflict_checked.contains(&task_status.task_id) {+ let newly_ready = phase == PhaseStatus::Ready && !task_status.was_ready;+ let should_check = match phase {+ PhaseStatus::Ready => newly_ready,+ PhaseStatus::Idle => {+ self.state.pane_content_hashes.get(&task_status.task_id)+ .map_or(false, |(_, last_change)| {+ now.duration_since(*last_change) >= std::time::Duration::from_secs(30)+ })+ }+ _ => false,+ };++ if should_check {+ if let (Some(ref wt), Some(ref sn)) = (&task_status.worktree_path, &task_status.session_name) {+ if self.state.tmux_ops.window_exists(sn).unwrap_or(false) {+ self.state.merge_conflict_checked.insert(task_status.task_id.clone());++ let git_ops = Arc::clone(&self.state.git_ops);+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let wt = wt.clone();+ let sn = sn.clone();+ let agent_name = task_status.agent.clone();++ std::thread::spawn(move || {+ match git_ops.fetch_and_check_conflicts(Path::new(&wt)) {+ Ok(true) => {+ let skill_cmd = skills::transform_plugin_command(+ "/agtx:merge-conflicts",+ &agent_name,+ );+ send_skill_and_prompt(+ &tmux_ops,+ &sn,+ &skill_cmd,+ "The feature branch has merge conflicts with the default branch. Please resolve them now.",+ &None,+ "",+ &agent_name,+ &[],+ );+ }+ Ok(false) | Err(_) => {}+ }+ });+ }+ }+ }+ }}self.state.spinner_frame = self.state.spinner_frame.wrapping_add(1);@@ -4386,6 +4456,9 @@ impl App {// Ensure tmux session existsensure_project_tmux_session(&project.name, &project_path, self.state.tmux_ops.as_ref());+ // Clear per-task caches from previous project+ self.state.merge_conflict_checked.clear();+// Reload tasks for new projectself.refresh_tasks()?;diff --git a/src/tui/app_tests.rs b/src/tui/app_tests.rsindex 1f4cd02..615bc8b 100644--- a/src/tui/app_tests.rs+++ b/src/tui/app_tests.rs@@ -1819,12 +1819,13 @@ fn test_agtx_plugin_has_commands() {#[test]fn test_enumerate_available_skills_claude() {let skills = skills::enumerate_available_skills("claude");- assert_eq!(skills.len(), 4);+ assert_eq!(skills.len(), 5);let commands: Vec<&str> = skills.iter().map(|(c, _)| c.as_str()).collect();assert!(commands.contains(&"/agtx:research"));assert!(commands.contains(&"/agtx:plan"));assert!(commands.contains(&"/agtx:execute"));assert!(commands.contains(&"/agtx:review"));+ assert!(commands.contains(&"/agtx:merge-conflicts"));// Each should have a descriptionfor (_, desc) in &skills {assert!(!desc.is_empty());@@ -3490,6 +3491,44 @@ fn test_quit_sets_should_quit() {assert!(app.state.should_quit);}+#[test]+fn test_merge_conflicts_skill_name_to_command() {+ assert_eq!(skills::skill_name_to_command("agtx-merge-conflicts"), "agtx:merge-conflicts");+}++#[test]+fn test_merge_conflicts_transform_plugin_command() {+ assert_eq!(+ skills::transform_plugin_command("/agtx:merge-conflicts", "claude"),+ Some("/agtx:merge-conflicts".to_string())+ );+ assert_eq!(+ skills::transform_plugin_command("/agtx:merge-conflicts", "gemini"),+ Some("/agtx:merge-conflicts".to_string())+ );+ assert_eq!(+ skills::transform_plugin_command("/agtx:merge-conflicts", "opencode"),+ Some("/agtx-merge-conflicts".to_string())+ );+ assert_eq!(+ skills::transform_plugin_command("/agtx:merge-conflicts", "codex"),+ Some("$agtx-merge-conflicts".to_string())+ );+ assert_eq!(+ skills::transform_plugin_command("/agtx:merge-conflicts", "copilot"),+ None+ );+}++#[test]+fn test_merge_conflicts_skill_registered() {+ // Verify the merge-conflicts skill is in BUILTIN_SKILLS+ assert!(+ skills::BUILTIN_SKILLS.iter().any(|(name, _)| *name == "agtx-merge-conflicts"),+ "agtx-merge-conflicts should be registered in BUILTIN_SKILLS"+ );+}+// --- Wizard: Agent & Plugin Selection ---/// Helper: create a test app with multiple agents available.@@ -3515,6 +3554,24 @@ fn make_test_app_with_agents() -> App {app}+#[test]+#[cfg(feature = "test-mocks")]+fn test_merge_conflict_checked_guard() {+ let mut app = make_test_app();+ let task_id = "test-task-123".to_string();++ // Initially not checked+ assert!(!app.state.merge_conflict_checked.contains(&task_id));++ // After inserting, should be guarded+ app.state.merge_conflict_checked.insert(task_id.clone());+ assert!(app.state.merge_conflict_checked.contains(&task_id));++ // Clear resets the guard+ app.state.merge_conflict_checked.clear();+ assert!(!app.state.merge_conflict_checked.contains(&task_id));+}+#[test]#[cfg(feature = "test-mocks")]fn test_wizard_plugin_selection() {