* fix(issueops): one create priority default; HTTP absent priority is P2 The CLI defaulted `bd create` to P2, but issues:create, issues:batchCreate and batch:apply create items left Issue.Priority at 0 when `priority` was absent, so a gc/curl create stored P0 (critical) against the spec's "absent means the default". The default now lives in one place, the shared create preparation (PreparePublicCreateRequest), behind a presence flag because Issue.Priority's zero value is P0: - issueops.CreateRequest.DefaultPriority, BatchCreateItem.DefaultPriority and CreateItem.DefaultPriority ask for issueops.DefaultCreatePriority (2); setting it with a non-zero priority is ErrValidation (ValidateCreatePriority, shared with the HTTP client); - every Lifecycle.Create, BatchCreator and BatchApplier leg (dolt, embedded, uow) reaches it; CloneCreateBatchRequest now keeps scalar item members; - the three handlers set the flag for an absent member and never make up 0; the HTTP client omits `priority` for it (wirePriority) only when the server advertises the new additive issues.create.defaultPriority token, read from the cached handshake before the dial; an older server reads an absent priority as P0, so the client sends DefaultCreatePriority (2) explicitly to it (pinCreateDefaultPriority). An explicit 0 is still sent; - `bd create` without --priority, `bd create --graph` nodes without priority and `bd create --file` templates without ### Priority rely on the flag; the flag's displayed default and the dry-run previews read the library constant. CLI output is byte-identical (checked against origin/main). Spec: the three priority descriptions now say the create default is P2 on a server advertising issues.create.defaultPriority (apigen regenerated); the wireshape golden already had priority optional, so no wire-shape change. Conformance: RunLifecycleCreateAppliesTheDefaultPriority, RunBatchCreatorAppliesTheDefaultPriority and RunBatchApplyAppliesTheDefaultPriority on dolt, embedded, uow and http, plus handler and client encoding tests, and TestCreateSendsTheDefaultPriorityToAServerThatPredatesIt (new client, handshake without the token: all three create roles send 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(issueops): apply review fixups for the default create priority (bd-kb61wg) Apply the minor and nit findings from the review of #7426: - CHANGELOG: tell out-of-tree storage backends they must honor DefaultPriority (store issueops.DefaultCreatePriority, refuse it with a non-zero priority as ErrValidation) and which conformance cases check it; scope "CLI output is unchanged" to the in-tree backends. - bd create --file: pin the default-priority path. The e2e test asserts the printed priorities, and a buildMarkdownBatchRequest unit test pins the flag and priority for an absent, a 0 and a 1 `### Priority`. Deleting `DefaultPriority: !template.PrioritySet` now fails both. - bd create --file: warn on stderr about a `### Priority` that does not parse, as the `### Type` case already does, instead of dropping it silently. - httpclient: document pinCreateDefaultPriority's same-build assumption (the handshake is cached per Store, so a stale one is silent here), and test its no-context and failed-handshake branches on all three roles. - Formula steps, `bd q` and `bd todo add` spell issueops.DefaultCreatePriority instead of the literal 2. - Conformance: the batch-creator and batch-apply default-priority cases also pin DefaultPriority with a non-zero priority as ErrValidation with nothing written. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(issueops): mark the out-of-tree DefaultPriority change BREAKING (bd-0tcn1o) Apply the minor findings from the relaunch review of #7426: - CHANGELOG: move the obligation on out-of-tree storage backends out of the `### Fixed` entry into its own `### Changed` entry, led by "BREAKING (out-of-tree storage backends)" as the close-guard change and the earlier out-of-tree contract changes are; RELEASING.md asks breaking changes to carry their migration. The entry says what such a backend used to receive from `bd create`, `--graph` and `--file` (priority 2), what it receives now (priority 0 with DefaultPriority set), the migration, and the conformance cases that check it. The `### Fixed` entry keeps the HTTP P2 fix, points at the new entry, and names the stale-handshake residual that only a code comment named: a create that lands on an older build behind the same URL still stores P0. - bd cook: the proto root, the gate issue and the cooked formula root spell issueops.DefaultCreatePriority instead of the literal 2, as the formula steps in the same file already do. No behavior change. Not taken: - The literal 2s in create_form.go, gate.go and linear.go, and the "default 2" in todo.go's --priority help: explicit P2s outside the migrated paths (the help string also feeds the generated CLI reference). Left for a follow-up sweep. - Reusing in.priorityDefault in the direct bd create route: that route builds no createInput (gatherCreateInput runs only on the proxied and --file routes, and each returns), so there is nothing to reuse. - A member-level range check in the single-create HTTP decode, as the batch shapes have: the asymmetry predates this PR, and the role still refuses an out-of-range priority on all three shapes. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
282 lines
7 KiB
Go
282 lines
7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
"github.com/steveyegge/beads/internal/utils"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
var todoCmd = &cobra.Command{
|
|
Use: "todo",
|
|
GroupID: "issues",
|
|
Short: "Manage TODO items (convenience wrapper for task issues)",
|
|
Long: `Manage TODO items as lightweight task issues.
|
|
|
|
TODOs are regular task-type issues with convenient shortcuts:
|
|
bd todo add "Title" -> bd create "Title" -t task -p 2
|
|
bd todo -> bd list --type task --status open
|
|
bd todo done <id> -> bd close <id>
|
|
|
|
TODOs can be promoted to full issues by changing type or priority:
|
|
bd update todo-123 --type bug --priority 0`,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
evt := metrics.NewCommandEvent("todo")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
// Delegate to the shared, non-emitting list core so a single `bd todo`
|
|
// records exactly one cli_command event ("todo"), not also "todo-list".
|
|
return runTodoListCore(cmd, args)
|
|
},
|
|
}
|
|
|
|
var addTodoCmd = &cobra.Command{
|
|
Use: "add <title>",
|
|
Short: "Add a new TODO item",
|
|
Args: cobra.MinimumNArgs(1),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
CheckReadonly("todo add")
|
|
|
|
evt := metrics.NewCommandEvent("todo-add")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
if usesProxiedServer() {
|
|
return runTodoAddProxiedServer(cmd, rootCtx, args)
|
|
}
|
|
|
|
title := strings.Join(args, " ")
|
|
|
|
priority, _ := cmd.Flags().GetInt("priority")
|
|
description, _ := cmd.Flags().GetString("description")
|
|
|
|
ctx := rootCtx
|
|
|
|
issueType := types.TypeTask
|
|
issue := &types.Issue{
|
|
Title: title,
|
|
Description: description,
|
|
Priority: priority,
|
|
IssueType: issueType,
|
|
Status: types.StatusOpen,
|
|
Assignee: getActorWithGit(),
|
|
Owner: getOwner(),
|
|
CreatedBy: getActorWithGit(),
|
|
}
|
|
|
|
if err := getStore().CreateIssue(ctx, issue, getActorWithGit()); err != nil {
|
|
return HandleError("failed to create TODO: %v", err)
|
|
}
|
|
|
|
commandDidWrite.Store(true)
|
|
|
|
if jsonOutput {
|
|
data, err := json.MarshalIndent(issue, "", " ")
|
|
if err != nil {
|
|
return HandleError("failed to marshal JSON: %v", err)
|
|
}
|
|
fmt.Println(string(data))
|
|
return nil
|
|
}
|
|
fmt.Printf("Created %s: %s\n", ui.RenderID(issue.ID), issue.Title)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var listTodosCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List TODO items",
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
evt := metrics.NewCommandEvent("todo-list")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
return runTodoListCore(cmd, args)
|
|
},
|
|
}
|
|
|
|
// runTodoListCore lists TODO (task) issues. It deliberately emits no metrics
|
|
// event so callers own event emission: `bd todo list` emits "todo-list" and the
|
|
// bare `bd todo` alias emits "todo", each exactly once.
|
|
func runTodoListCore(cmd *cobra.Command, _ []string) error {
|
|
showAll, _ := cmd.Flags().GetBool("all")
|
|
|
|
ctx := rootCtx
|
|
|
|
taskType := types.TypeTask
|
|
filter := types.IssueFilter{
|
|
IssueType: &taskType,
|
|
}
|
|
if !showAll {
|
|
openStatus := types.StatusOpen
|
|
filter.Status = &openStatus
|
|
}
|
|
|
|
var issues []*types.Issue
|
|
if usesProxiedServer() {
|
|
var err error
|
|
issues, err = todoListProxied(ctx, filter)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
var err error
|
|
issues, err = getStore().SearchIssues(ctx, "", filter)
|
|
if err != nil {
|
|
return HandleError("failed to list TODOs: %v", err)
|
|
}
|
|
}
|
|
|
|
if jsonOutput {
|
|
data, err := json.MarshalIndent(issues, "", " ")
|
|
if err != nil {
|
|
return HandleError("failed to marshal JSON: %v", err)
|
|
}
|
|
fmt.Println(string(data))
|
|
return nil
|
|
}
|
|
if len(issues) == 0 {
|
|
fmt.Println("No TODOs found")
|
|
return nil
|
|
}
|
|
|
|
todoSortIssues(issues)
|
|
|
|
for _, issue := range issues {
|
|
statusIcon := ui.RenderStatusIcon(string(issue.Status))
|
|
priority := ui.RenderPriority(issue.Priority)
|
|
fmt.Printf(" %s %s %-40s %s %s\n",
|
|
statusIcon,
|
|
ui.RenderID(issue.ID),
|
|
todoTruncate(issue.Title, 40),
|
|
priority,
|
|
issue.Status)
|
|
}
|
|
fmt.Printf("\nTotal: %d TODOs\n", len(issues))
|
|
return nil
|
|
}
|
|
|
|
var doneTodoCmd = &cobra.Command{
|
|
Use: "done <id> [<id>...]",
|
|
Short: "Mark TODO(s) as done",
|
|
Args: cobra.MinimumNArgs(1),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
CheckReadonly("todo done")
|
|
|
|
evt := metrics.NewCommandEvent("todo-done")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
if usesProxiedServer() {
|
|
return runTodoDoneProxiedServer(cmd, rootCtx, args)
|
|
}
|
|
|
|
ctx := rootCtx
|
|
|
|
reason, _ := cmd.Flags().GetString("reason")
|
|
if reason == "" {
|
|
reason = "Completed"
|
|
}
|
|
|
|
var closedIDs []string
|
|
for _, issueID := range args {
|
|
issue, err := getStore().GetIssue(ctx, issueID)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: failed to get issue %s: %v\n", issueID, err)
|
|
continue
|
|
}
|
|
if issue == nil {
|
|
fmt.Fprintf(os.Stderr, "Error: issue %s not found\n", issueID)
|
|
continue
|
|
}
|
|
|
|
if err := getStore().CloseIssue(ctx, issueID, reason, getActorWithGit(), ""); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: failed to close %s: %v\n", issueID, err)
|
|
continue
|
|
}
|
|
closedIDs = append(closedIDs, issueID)
|
|
}
|
|
|
|
if len(closedIDs) > 0 {
|
|
commandDidWrite.Store(true)
|
|
}
|
|
|
|
if jsonOutput {
|
|
data, err := json.MarshalIndent(map[string]interface{}{
|
|
"closed": closedIDs,
|
|
"reason": reason,
|
|
}, "", " ")
|
|
if err != nil {
|
|
return HandleError("failed to marshal JSON: %v", err)
|
|
}
|
|
fmt.Println(string(data))
|
|
return nil
|
|
}
|
|
for _, id := range closedIDs {
|
|
fmt.Printf("Closed %s\n", ui.RenderID(id))
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
// Add subcommands
|
|
todoCmd.AddCommand(addTodoCmd)
|
|
todoCmd.AddCommand(listTodosCmd)
|
|
todoCmd.AddCommand(doneTodoCmd)
|
|
|
|
// Add flags
|
|
addTodoCmd.Flags().IntP("priority", "p", issueops.DefaultCreatePriority, "Priority (0-4, default 2)")
|
|
addTodoCmd.Flags().StringP("description", "d", "", "Description")
|
|
|
|
listTodosCmd.Flags().Bool("all", false, "Show all TODOs including completed")
|
|
|
|
doneTodoCmd.Flags().String("reason", "", "Reason for closing (default: Completed)")
|
|
|
|
// Register with root
|
|
rootCmd.AddCommand(todoCmd)
|
|
}
|
|
|
|
// todoTruncate truncates a string to the specified length with ellipsis
|
|
func todoTruncate(s string, maxLen int) string {
|
|
return truncate(s, maxLen)
|
|
}
|
|
|
|
// todoSortIssues sorts issues by priority (ascending) then ID
|
|
func todoSortIssues(issues []*types.Issue) {
|
|
slices.SortFunc(issues, func(a, b *types.Issue) int {
|
|
if a.Priority != b.Priority {
|
|
return a.Priority - b.Priority
|
|
}
|
|
return utils.NaturalCompareIDs(a.ID, b.ID)
|
|
})
|
|
}
|