Story 33: Copy-paste diff commands for agent worktrees
- Add base_branch detection to WorktreeInfo (from project root HEAD)
- Expose base_branch in AgentInfo API response
- Add {{base_branch}} template variable to agent config rendering
- Show git difftool command with copy-to-clipboard in AgentPanel UI
- Add diff command instruction to coder agent prompts
- Add AgentPanel tests for diff command rendering and clipboard
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ use std::process::Command;
|
||||
pub struct WorktreeInfo {
|
||||
pub path: PathBuf,
|
||||
pub branch: String,
|
||||
pub base_branch: String,
|
||||
}
|
||||
|
||||
/// Worktree path as a sibling of the project root: `{project_root}-story-{id}`.
|
||||
@@ -24,6 +25,23 @@ fn branch_name(story_id: &str) -> String {
|
||||
format!("feature/story-{story_id}")
|
||||
}
|
||||
|
||||
/// Detect the current branch of the project root (the base branch worktrees fork from).
|
||||
fn detect_base_branch(project_root: &Path) -> String {
|
||||
Command::new("git")
|
||||
.args(["rev-parse", "--abbrev-ref", "HEAD"])
|
||||
.current_dir(project_root)
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
if o.status.success() {
|
||||
Some(String::from_utf8_lossy(&o.stdout).trim().to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| "master".to_string())
|
||||
}
|
||||
|
||||
/// Create a git worktree for the given story.
|
||||
///
|
||||
/// - Creates the worktree at `{project_root}-story-{story_id}` (sibling directory)
|
||||
@@ -37,6 +55,7 @@ pub async fn create_worktree(
|
||||
) -> Result<WorktreeInfo, String> {
|
||||
let wt_path = worktree_path(project_root, story_id);
|
||||
let branch = branch_name(story_id);
|
||||
let base_branch = detect_base_branch(project_root);
|
||||
let root = project_root.to_path_buf();
|
||||
|
||||
// Already exists — reuse
|
||||
@@ -45,6 +64,7 @@ pub async fn create_worktree(
|
||||
return Ok(WorktreeInfo {
|
||||
path: wt_path,
|
||||
branch,
|
||||
base_branch,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,6 +80,7 @@ pub async fn create_worktree(
|
||||
Ok(WorktreeInfo {
|
||||
path: wt_path,
|
||||
branch,
|
||||
base_branch,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user