refactor(hooks): consolidate duplicate JSONL file lists into shared constant

- Add jsonlFilePaths constant to eliminate duplicate file list definitions
- Update all usages in hook.go and hooks.go to use the shared constant
- Include beads.jsonl for backwards compatibility with older installations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beads/crew/elinor
2026-01-20 19:15:04 -08:00
committed by Steve Yegge
parent 2fe15e2328
commit 4b2d1791ee
2 changed files with 19 additions and 14 deletions

View File

@@ -20,6 +20,15 @@ import (
"github.com/steveyegge/beads/internal/storage/factory"
)
// jsonlFilePaths lists all JSONL files that should be staged/tracked.
// Includes beads.jsonl for backwards compatibility with older installations.
var jsonlFilePaths = []string{
".beads/issues.jsonl",
".beads/deletions.jsonl",
".beads/interactions.jsonl",
".beads/beads.jsonl", // Legacy filename, kept for backwards compatibility
}
// hookCmd is the main "bd hook" command that git hooks call into.
// This is distinct from "bd hooks" (plural) which manages hook installation.
var hookCmd = &cobra.Command{
@@ -368,17 +377,16 @@ func hookPreCommit() int {
}
// Stage JSONL files
jsonlFiles := []string{".beads/beads.jsonl", ".beads/issues.jsonl", ".beads/deletions.jsonl", ".beads/interactions.jsonl"}
if os.Getenv("BEADS_NO_AUTO_STAGE") == "" {
rc, rcErr := beads.GetRepoContext()
ctx := context.Background()
for _, f := range jsonlFiles {
for _, f := range jsonlFilePaths {
if _, err := os.Stat(f); err == nil {
var gitAdd *exec.Cmd
if rcErr == nil {
gitAdd = rc.GitCmdCWD(ctx, "add", f)
} else {
// #nosec G204 -- f comes from jsonlFiles (controlled, hardcoded paths)
// #nosec G204 -- f comes from jsonlFilePaths (controlled, hardcoded paths)
gitAdd = exec.Command("git", "add", f)
}
_ = gitAdd.Run()
@@ -532,14 +540,13 @@ func stageJSONLFiles(ctx context.Context) {
}
rc, rcErr := beads.GetRepoContext()
jsonlFiles := []string{".beads/issues.jsonl", ".beads/deletions.jsonl", ".beads/interactions.jsonl"}
for _, f := range jsonlFiles {
for _, f := range jsonlFilePaths {
if _, err := os.Stat(f); err == nil {
var gitAdd *exec.Cmd
if rcErr == nil {
gitAdd = rc.GitCmdCWD(ctx, "add", f)
} else {
// #nosec G204 -- f comes from jsonlFiles (hardcoded)
// #nosec G204 -- f comes from jsonlFilePaths (controlled, hardcoded paths)
gitAdd = exec.Command("git", "add", f)
}
_ = gitAdd.Run()