bd prime: Auto-detect ephemeral branches and adjust workflow
When running on a branch with no upstream (e.g., gastown polecats), output
different SESSION CLOSE PROTOCOL instructions:
- Use 'bd sync --from-main' instead of 'bd sync'
- Skip git push step (branch is local-only)
- Update Sync & Collaboration section to show --from-main
- Update Completing work workflow accordingly
Detection: git rev-parse --abbrev-ref --symbolic-full-name @{u} returns
error if no upstream configured.
Closes bd-4l5
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -102,6 +103,15 @@ func isMCPActive() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isEphemeralBranch detects if current branch has no upstream (ephemeral/local-only)
|
||||||
|
func isEphemeralBranch() bool {
|
||||||
|
// git rev-parse --abbrev-ref --symbolic-full-name @{u}
|
||||||
|
// Returns error code 128 if no upstream configured
|
||||||
|
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
|
||||||
|
err := cmd.Run()
|
||||||
|
return err != nil
|
||||||
|
}
|
||||||
|
|
||||||
// outputPrimeContext outputs workflow context in markdown format
|
// outputPrimeContext outputs workflow context in markdown format
|
||||||
func outputPrimeContext(mcpMode bool) error {
|
func outputPrimeContext(mcpMode bool) error {
|
||||||
if mcpMode {
|
if mcpMode {
|
||||||
@@ -112,11 +122,20 @@ func outputPrimeContext(mcpMode bool) error {
|
|||||||
|
|
||||||
// outputMCPContext outputs minimal context for MCP users
|
// outputMCPContext outputs minimal context for MCP users
|
||||||
func outputMCPContext() error {
|
func outputMCPContext() error {
|
||||||
|
ephemeral := isEphemeralBranch()
|
||||||
|
|
||||||
|
var closeProtocol string
|
||||||
|
if ephemeral {
|
||||||
|
closeProtocol = "Before saying \"done\": git status → git add → bd sync --from-main → git commit (no push - ephemeral branch)"
|
||||||
|
} else {
|
||||||
|
closeProtocol = "Before saying \"done\": git status → git add → bd sync → git commit → bd sync → git push"
|
||||||
|
}
|
||||||
|
|
||||||
context := `# Beads Issue Tracker Active
|
context := `# Beads Issue Tracker Active
|
||||||
|
|
||||||
# 🚨 SESSION CLOSE PROTOCOL 🚨
|
# 🚨 SESSION CLOSE PROTOCOL 🚨
|
||||||
|
|
||||||
Before saying "done": git status → git add → bd sync → git commit → bd sync → git push
|
` + closeProtocol + `
|
||||||
|
|
||||||
## Core Rules
|
## Core Rules
|
||||||
- Track ALL work in beads (no TodoWrite tool, no markdown TODOs)
|
- Track ALL work in beads (no TodoWrite tool, no markdown TODOs)
|
||||||
@@ -130,6 +149,47 @@ Start: Check ` + "`ready`" + ` tool for available work.
|
|||||||
|
|
||||||
// outputCLIContext outputs full CLI reference for non-MCP users
|
// outputCLIContext outputs full CLI reference for non-MCP users
|
||||||
func outputCLIContext() error {
|
func outputCLIContext() error {
|
||||||
|
ephemeral := isEphemeralBranch()
|
||||||
|
|
||||||
|
var closeProtocol string
|
||||||
|
var closeNote string
|
||||||
|
var syncSection string
|
||||||
|
var completingWorkflow string
|
||||||
|
|
||||||
|
if ephemeral {
|
||||||
|
closeProtocol = `[ ] 1. git status (check what changed)
|
||||||
|
[ ] 2. git add <files> (stage code changes)
|
||||||
|
[ ] 3. bd sync --from-main (pull beads updates from main)
|
||||||
|
[ ] 4. git commit -m "..." (commit code changes)`
|
||||||
|
closeNote = "**Note:** This is an ephemeral branch (no upstream). Code is merged to main locally, not pushed."
|
||||||
|
syncSection = `### Sync & Collaboration
|
||||||
|
- ` + "`bd sync --from-main`" + ` - Pull beads updates from main (for ephemeral branches)
|
||||||
|
- ` + "`bd sync --status`" + ` - Check sync status without syncing`
|
||||||
|
completingWorkflow = `**Completing work:**
|
||||||
|
` + "```bash" + `
|
||||||
|
bd close <id> # Mark done
|
||||||
|
bd sync --from-main # Pull latest beads from main
|
||||||
|
git add . && git commit -m "..." # Commit your changes
|
||||||
|
# Merge to main when ready (local merge, not push)
|
||||||
|
` + "```"
|
||||||
|
} else {
|
||||||
|
closeProtocol = `[ ] 1. git status (check what changed)
|
||||||
|
[ ] 2. git add <files> (stage code changes)
|
||||||
|
[ ] 3. bd sync (commit beads changes)
|
||||||
|
[ ] 4. git commit -m "..." (commit code)
|
||||||
|
[ ] 5. bd sync (commit any new beads changes)
|
||||||
|
[ ] 6. git push (push to remote)`
|
||||||
|
closeNote = "**NEVER skip this.** Work is not done until pushed."
|
||||||
|
syncSection = `### Sync & Collaboration
|
||||||
|
- ` + "`bd sync`" + ` - Sync with git remote (run at session end)
|
||||||
|
- ` + "`bd sync --status`" + ` - Check sync status without syncing`
|
||||||
|
completingWorkflow = `**Completing work:**
|
||||||
|
` + "```bash" + `
|
||||||
|
bd close <id> # Mark done
|
||||||
|
bd sync # Push to remote
|
||||||
|
` + "```"
|
||||||
|
}
|
||||||
|
|
||||||
context := `# Beads Workflow Context
|
context := `# Beads Workflow Context
|
||||||
|
|
||||||
> **Context Recovery**: Run ` + "`bd prime`" + ` after compaction, clear, or new session
|
> **Context Recovery**: Run ` + "`bd prime`" + ` after compaction, clear, or new session
|
||||||
@@ -140,15 +200,10 @@ func outputCLIContext() error {
|
|||||||
**CRITICAL**: Before saying "done" or "complete", you MUST run this checklist:
|
**CRITICAL**: Before saying "done" or "complete", you MUST run this checklist:
|
||||||
|
|
||||||
` + "```" + `
|
` + "```" + `
|
||||||
[ ] 1. git status (check what changed)
|
` + closeProtocol + `
|
||||||
[ ] 2. git add <files> (stage code changes)
|
|
||||||
[ ] 3. bd sync (commit beads changes)
|
|
||||||
[ ] 4. git commit -m "..." (commit code)
|
|
||||||
[ ] 5. bd sync (commit any new beads changes)
|
|
||||||
[ ] 6. git push (push to remote)
|
|
||||||
` + "```" + `
|
` + "```" + `
|
||||||
|
|
||||||
**NEVER skip this.** Work is not done until pushed.
|
` + closeNote + `
|
||||||
|
|
||||||
## Core Rules
|
## Core Rules
|
||||||
- Track ALL work in beads (no TodoWrite tool, no markdown TODOs)
|
- Track ALL work in beads (no TodoWrite tool, no markdown TODOs)
|
||||||
@@ -176,9 +231,7 @@ func outputCLIContext() error {
|
|||||||
- ` + "`bd blocked`" + ` - Show all blocked issues
|
- ` + "`bd blocked`" + ` - Show all blocked issues
|
||||||
- ` + "`bd show <id>`" + ` - See what's blocking/blocked by this issue
|
- ` + "`bd show <id>`" + ` - See what's blocking/blocked by this issue
|
||||||
|
|
||||||
### Sync & Collaboration
|
` + syncSection + `
|
||||||
- ` + "`bd sync`" + ` - Sync with git remote (run at session end)
|
|
||||||
- ` + "`bd sync --status`" + ` - Check sync status without syncing
|
|
||||||
|
|
||||||
### Project Health
|
### Project Health
|
||||||
- ` + "`bd stats`" + ` - Project statistics (open/closed/blocked counts)
|
- ` + "`bd stats`" + ` - Project statistics (open/closed/blocked counts)
|
||||||
@@ -193,11 +246,7 @@ bd show <id> # Review issue details
|
|||||||
bd update <id> --status=in_progress # Claim it
|
bd update <id> --status=in_progress # Claim it
|
||||||
` + "```" + `
|
` + "```" + `
|
||||||
|
|
||||||
**Completing work:**
|
` + completingWorkflow + `
|
||||||
` + "```bash" + `
|
|
||||||
bd close <id> # Mark done
|
|
||||||
bd sync # Push to remote
|
|
||||||
` + "```" + `
|
|
||||||
|
|
||||||
**Creating dependent work:**
|
**Creating dependent work:**
|
||||||
` + "```bash" + `
|
` + "```bash" + `
|
||||||
|
|||||||
Reference in New Issue
Block a user