beads/cmd/bd/ready_input.go
Isis Anisoptera 190e358681 fix(create): close code-review findings in --graph and waits-for paths
Correctness:
- Guard against nil WaitsForSpec so `bd create --waits-for " "`
  (whitespace-only) no longer panics; also use the trimmed
  spec.SpawnerID as the dependency target in embedded mode so padded
  input matches the proxied path instead of targeting a bogus ID.
- Reject graph edges that combine spawner_key with to_id: an explicit
  to_id overrides to_key at apply time, so a key-named spawner could
  never match the ID-resolved target and the recorded gate spawner was
  silently ignored.
- Look up unknown-field hints case-insensitively, matching the
  case-insensitive known-field check, so typos like "Estimate" still
  get their corrective hint.
- Add repair migrations 0052 (issues) and ignored/0011 (wisps) that
  re-run the mixed is_blocked recompute with a NULL-safe gate predicate
  (COALESCE ... 'all-children'); migration 0047 and ignored/0007 left
  gate-less waits-for rows mis-marked as unblocked.

Cleanup:
- Return the resolved useWisp from validateGraphApplyStorageClasses
  instead of re-deriving it from Nodes[0] in the proxied path.
- Extract shared types.NewGraphEdgeDependency and types.MergeMetadataRefs
  so the embedded and domain apply paths cannot drift.
- Add types.ValidWispTypeNames/ValidMolTypeNames and use them in place of
  the hand-maintained valid-value strings scattered across create/list/ready.
- Carry custom statuses in CreateContext to drop the extra proxied-server
  config round trip.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 11:52:56 -07:00

170 lines
5.2 KiB
Go

package main
import (
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/utils"
)
type readyInput struct {
filter types.WorkFilter
limit int
offset int
claim bool
gated bool
molID string
explain bool
prettyFormat bool
plainFormat bool
parentID string
jsonOut bool
}
func gatherReadyInput(cmd *cobra.Command) (readyInput, error) {
in := readyInput{}
in.claim, _ = cmd.Flags().GetBool("claim")
in.gated, _ = cmd.Flags().GetBool("gated")
in.molID, _ = cmd.Flags().GetString("mol")
in.explain, _ = cmd.Flags().GetBool("explain")
in.prettyFormat, _ = cmd.Flags().GetBool("pretty")
in.plainFormat, _ = cmd.Flags().GetBool("plain")
in.jsonOut = jsonOutput
in.limit, _ = cmd.Flags().GetInt("limit")
if cmd.Flags().Changed("offset") {
offset, _ := cmd.Flags().GetInt("offset")
if offset < 0 {
return in, HandleError("--offset must be >= 0")
}
in.offset = offset
}
assignee, _ := cmd.Flags().GetString("assignee")
unassigned, _ := cmd.Flags().GetBool("unassigned")
sortPolicy, _ := cmd.Flags().GetString("sort")
labels, _ := cmd.Flags().GetStringSlice("label")
labelsAny, _ := cmd.Flags().GetStringSlice("label-any")
excludeLabels, _ := cmd.Flags().GetStringSlice("exclude-label")
issueType, _ := cmd.Flags().GetString("type")
issueType = utils.NormalizeIssueType(issueType)
in.parentID, _ = cmd.Flags().GetString("parent")
molTypeStr, _ := cmd.Flags().GetString("mol-type")
includeDeferred, _ := cmd.Flags().GetBool("include-deferred")
includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral")
excludeTypeStrs, _ := cmd.Flags().GetStringSlice("exclude-type")
var molType *types.MolType
if molTypeStr != "" {
mt := types.MolType(molTypeStr)
if !mt.IsValid() {
return in, HandleError("invalid mol-type %q (must be %s)", molTypeStr, types.ValidMolTypeNames())
}
molType = &mt
}
if in.claim && assignee != "" {
return in, HandleErrorRespectJSON("--claim cannot be combined with --assignee")
}
if in.claim && in.gated {
return in, HandleErrorRespectJSON("--claim cannot be combined with --gated")
}
if in.claim && in.molID != "" {
return in, HandleErrorRespectJSON("--claim cannot be combined with --mol")
}
if in.claim && in.explain {
return in, HandleErrorRespectJSON("--claim cannot be combined with --explain")
}
if in.offset > 0 && in.claim {
return in, HandleErrorRespectJSON("--offset cannot be combined with --claim")
}
if in.offset > 0 && in.gated {
return in, HandleErrorRespectJSON("--offset cannot be combined with --gated")
}
if in.offset > 0 && in.molID != "" {
return in, HandleErrorRespectJSON("--offset cannot be combined with --mol")
}
if in.offset > 0 && in.explain {
return in, HandleErrorRespectJSON("--offset cannot be combined with --explain")
}
labels = utils.NormalizeLabels(labels)
labelsAny = utils.NormalizeLabels(labelsAny)
excludeLabels = utils.NormalizeLabels(excludeLabels)
if len(labels) == 0 && len(labelsAny) == 0 {
if dirLabels := config.GetDirectoryLabels(); len(dirLabels) > 0 {
labelsAny = dirLabels
}
}
var excludeTypes []types.IssueType
for _, raw := range excludeTypeStrs {
for _, t := range strings.Split(raw, ",") {
t = strings.TrimSpace(t)
if t != "" {
excludeTypes = append(excludeTypes, types.IssueType(utils.NormalizeIssueType(t)))
}
}
}
in.filter = types.WorkFilter{
Status: "open",
Type: issueType,
Limit: in.limit,
Offset: in.offset,
Unassigned: unassigned,
SortPolicy: types.SortPolicy(sortPolicy),
Labels: labels,
LabelsAny: labelsAny,
ExcludeLabels: excludeLabels,
IncludeDeferred: includeDeferred,
IncludeEphemeral: includeEphemeral,
ExcludeTypes: excludeTypes,
}
if cmd.Flags().Changed("priority") {
priority, _ := cmd.Flags().GetInt("priority")
in.filter.Priority = &priority
}
if assignee != "" && !unassigned {
in.filter.Assignee = &assignee
}
if in.parentID != "" {
in.filter.ParentID = &in.parentID
}
if molType != nil {
in.filter.MolType = molType
}
metadataFieldFlags, _ := cmd.Flags().GetStringArray("metadata-field")
if len(metadataFieldFlags) > 0 {
in.filter.MetadataFields = make(map[string]string, len(metadataFieldFlags))
for _, mf := range metadataFieldFlags {
k, v, ok := strings.Cut(mf, "=")
if !ok || k == "" {
return in, HandleError("invalid --metadata-field: expected key=value, got %q", mf)
}
if err := storage.ValidateMetadataKey(k); err != nil {
return in, HandleError("invalid --metadata-field key: %v", err)
}
in.filter.MetadataFields[k] = v
}
}
hasMetadataKey, _ := cmd.Flags().GetString("has-metadata-key")
if hasMetadataKey != "" {
if err := storage.ValidateMetadataKey(hasMetadataKey); err != nil {
return in, HandleError("invalid --has-metadata-key: %v", err)
}
in.filter.HasMetadataKey = hasMetadataKey
}
if !in.filter.SortPolicy.IsValid() {
return in, HandleError("invalid sort policy '%s'. Valid values: hybrid, priority, oldest", sortPolicy)
}
return in, nil
}