Fix bd-51: Add git hooks to eliminate auto-flush race condition

- Added --flush-only flag to bd sync command
- Created pre-commit hook to flush pending changes before commit
- Created post-merge hook to import changes after pull/merge
- Added install script for easy setup
- Updated AGENTS.md with git hooks workflow
- Resolves race condition where daemon auto-flush fires after commit

Amp-Thread-ID: https://ampcode.com/threads/T-00b80d3a-4194-4c75-a60e-25a318cf9f91
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-24 22:17:06 -07:00
parent c87f9007a5
commit 0344e1f08b
7 changed files with 199 additions and 265 deletions

View File

@@ -26,7 +26,9 @@ var syncCmd = &cobra.Command{
4. Import updated JSONL
5. Push local commits to remote
This command wraps the entire git-based sync workflow for multi-device use.`,
This command wraps the entire git-based sync workflow for multi-device use.
Use --flush-only to just export pending changes to JSONL (useful for pre-commit hooks).`,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
@@ -35,6 +37,7 @@ This command wraps the entire git-based sync workflow for multi-device use.`,
noPush, _ := cmd.Flags().GetBool("no-push")
noPull, _ := cmd.Flags().GetBool("no-pull")
renameOnImport, _ := cmd.Flags().GetBool("rename-on-import")
flushOnly, _ := cmd.Flags().GetBool("flush-only")
// Find JSONL path
jsonlPath := findJSONLPath()
@@ -43,6 +46,19 @@ This command wraps the entire git-based sync workflow for multi-device use.`,
os.Exit(1)
}
// If flush-only mode, just export and exit
if flushOnly {
if dryRun {
fmt.Println("→ [DRY RUN] Would export pending changes to JSONL")
} else {
if err := exportToJSONL(ctx, jsonlPath); err != nil {
fmt.Fprintf(os.Stderr, "Error exporting: %v\n", err)
os.Exit(1)
}
}
return
}
// Check if we're in a git repository
if !isGitRepo() {
fmt.Fprintf(os.Stderr, "Error: not in a git repository\n")
@@ -148,6 +164,7 @@ func init() {
syncCmd.Flags().Bool("no-push", false, "Skip pushing to remote")
syncCmd.Flags().Bool("no-pull", false, "Skip pulling from remote")
syncCmd.Flags().Bool("rename-on-import", false, "Rename imported issues to match database prefix (updates all references)")
syncCmd.Flags().Bool("flush-only", false, "Only export pending changes to JSONL (skip git operations)")
rootCmd.AddCommand(syncCmd)
}