feat(q): add --parent for hierarchical quick capture (#4597)

bd q is designed for scripting and agent integration, but batch-creating
epic breakdowns required falling back to the heavier bd create --parent.

Mirrors create.go's parent handling: validate the parent exists, inherit
its labels (create's default), reserve the hierarchical child ID via
GetNextChildID/WithReservedChildCounter, add the parent-child dependency
after CreateIssue, and follow up with the post-write Dolt commit
(GH#2009 pattern). Output stays ID-only.

Closes #4596

Assisted-by: Claude:claude-fable-5 [Cursor]

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin Glynn 2026-07-07 08:50:25 -04:00 • committed by GitHub
commit c36afd74e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 4 deletions

View file

@ -1,11 +1,13 @@
package main
import (
"errors"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/metrics"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/validation"
)
@ -20,7 +22,8 @@ Designed for scripting and AI agent integration.
Example:
bd q "Fix login bug" # Outputs: bd-a1b2
ISSUE=$(bd q "New feature") # Capture ID in variable
bd q "Task" | xargs bd show # Pipe to other commands`,
bd q "Task" | xargs bd show # Pipe to other commands
bd q "Subtask" --parent=bd-a1b2 # Hierarchical child (outputs: bd-a1b2.1)`,
Args: cobra.MinimumNArgs(1),
SilenceUsage: true,
SilenceErrors: true,
@ -42,27 +45,76 @@ Example:
priorityStr, _ := cmd.Flags().GetString("priority")
issueType, _ := cmd.Flags().GetString("type")
labels, _ := cmd.Flags().GetStringSlice("labels")
parentID, _ := cmd.Flags().GetString("parent")
priority, err := validation.ValidatePriority(priorityStr)
if err != nil {
return HandleError("%v", err)
}
ctx := rootCtx
// Mirrors bd create's parent handling: validate the parent exists,
// inherit its labels, and reserve a hierarchical child ID.
var inheritedLabels []string
if parentID != "" {
if _, err := store.GetIssue(ctx, parentID); err != nil {
if errors.Is(err, storage.ErrNotFound) {
return HandleError("parent issue %s not found", parentID)
}
return HandleError("failed to check parent issue: %v", err)
}
inheritedLabels, _ = store.GetLabels(ctx, parentID)
}
issue := &types.Issue{
Title: title,
Status: types.StatusOpen,
Priority: priority,
IssueType: types.IssueType(issueType).Normalize(),
Labels: mergeCreateLabels(labels, nil),
Labels: mergeCreateLabels(labels, inheritedLabels),
}
if parentID != "" {
childID, err := store.GetNextChildID(ctx, parentID)
if err != nil {
return HandleError("%v", err)
}
issue.ID = childID
ctx = storage.WithReservedChildCounter(ctx, parentID, childID)
}
ctx := rootCtx
if err := store.CreateIssue(ctx, issue, actor); err != nil {
return HandleError("%v", err)
}
commandDidWrite.Store(true)
if parentID != "" {
dep := &types.Dependency{
IssueID: issue.ID,
DependsOnID: parentID,
Type: types.DepParentChild,
}
if err := store.AddDependency(ctx, dep, actor); err != nil {
WarnError("failed to add parent-child dependency %s -> %s: %v", issue.ID, parentID, err)
} else {
// CreateIssue commits internally, but the dependency write
// only lands in the working set (GH#2009) — same follow-up
// commit bd create performs.
shouldCommit, err := shouldCommitCreatePostWrites(issue, true)
if err != nil {
return HandleError("dolt auto-commit failed: %v", err)
}
if shouldCommit {
commitMsg := fmt.Sprintf("bd: create %s", issue.ID)
if err := store.Commit(ctx, commitMsg); err != nil && !isDoltNothingToCommit(err) {
WarnError("failed to commit: %v", err)
}
}
}
}
fmt.Println(issue.ID)
return nil
},
@ -72,5 +124,6 @@ func init() {
quickCmd.Flags().StringP("priority", "p", "2", "Priority (0-4 or P0-P4)")
quickCmd.Flags().StringP("type", "t", "task", "Issue type")
quickCmd.Flags().StringSliceP("labels", "l", []string{}, "Labels")
quickCmd.Flags().String("parent", "", "Parent issue ID for hierarchical child (e.g., 'bd-a3f8e9')")
rootCmd.AddCommand(quickCmd)
}

View file

@ -29,7 +29,7 @@ func TestEmbeddedQuick(t *testing.T) {
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "qq")
dir, beadsDir, _ := bdInit(t, bd, "--prefix", "qq")
t.Run("basic_quick_create", func(t *testing.T) {
id := bdQuick(t, bd, dir, "Quick task")
@ -129,6 +129,51 @@ func TestEmbeddedQuick(t *testing.T) {
t.Fatalf("expected bd q with no title to fail, got: %s", out)
}
})
t.Run("quick_parent", func(t *testing.T) {
parent := bdCreate(t, bd, dir, "Quick parent epic", "-t", "epic")
id := bdQuick(t, bd, dir, "Quick child", "--parent", parent.ID)
if !strings.HasPrefix(id, parent.ID+".") {
t.Errorf("child ID %q should start with %q.", id, parent.ID)
}
// Output contract: still ID-only, single line
if lines := strings.Split(id, "\n"); len(lines) != 1 {
t.Errorf("expected single-line ID output, got %d lines: %q", len(lines), id)
}
assertDepExists(t, beadsDir, "qq", id, parent.ID)
})
t.Run("quick_parent_label_inheritance", func(t *testing.T) {
parent := bdCreate(t, bd, dir, "Quick labeled parent", "-t", "epic", "-l", "team-q,inherited")
id := bdQuick(t, bd, dir, "Quick labeled child", "--parent", parent.ID, "-l", "own")
m := bdShowDetails(t, bd, dir, id)
labels, _ := m["labels"].([]interface{})
labelSet := map[string]bool{}
for _, l := range labels {
labelSet[l.(string)] = true
}
for _, want := range []string{"team-q", "inherited", "own"} {
if !labelSet[want] {
t.Errorf("expected label %q, got %v", want, labels)
}
}
})
t.Run("quick_parent_not_found_fails", func(t *testing.T) {
cmd := exec.Command(bd, "q", "Orphan child", "--parent", "qq-doesnotexist")
cmd.Dir = dir
cmd.Env = bdEnv(dir)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("expected bd q --parent with nonexistent parent to fail, got: %s", out)
}
if !strings.Contains(string(out), "not found") {
t.Errorf("expected 'not found' in error output, got: %s", out)
}
})
}
// TestEmbeddedQuickConcurrent exercises quick-create concurrently.

View file

@ -1152,6 +1152,7 @@ Example:
bd q "Fix login bug" # Outputs: bd-a1b2
ISSUE=$(bd q "New feature") # Capture ID in variable
bd q "Task" | xargs bd show # Pipe to other commands
bd q "Subtask" --parent=bd-a1b2 # Hierarchical child (outputs: bd-a1b2.1)
```
bd q [title] [flags]
@ -1161,6 +1162,7 @@ bd q [title] [flags]
```
-l, --labels strings Labels
--parent string Parent issue ID for hierarchical child (e.g., 'bd-a3f8e9')
-p, --priority string Priority (0-4 or P0-P4) (default "2")
-t, --type string Issue type (default "task")
```

View file

@ -17,6 +17,7 @@ Example:
bd q "Fix login bug" # Outputs: bd-a1b2
ISSUE=$(bd q "New feature") # Capture ID in variable
bd q "Task" | xargs bd show # Pipe to other commands
bd q "Subtask" --parent=bd-a1b2 # Hierarchical child (outputs: bd-a1b2.1)
```
bd q [title] [flags]
@ -26,6 +27,7 @@ bd q [title] [flags]
```
-l, --labels strings Labels
--parent string Parent issue ID for hierarchical child (e.g., 'bd-a3f8e9')
-p, --priority string Priority (0-4 or P0-P4) (default "2")
-t, --type string Issue type (default "task")
```