refactor: remove 171 dead if daemonClient != nil branches from 56 files (-3,384 lines)
Since daemonClient is always nil (daemon_deprecated.go stub), every `if daemonClient != nil` branch was dead code. This removes all 171 occurrences across 56 command files, keeping only the direct storage (else) branches. Also cleans up unused rpc/json/types imports and fixes variable shadowing issues left behind. Part of Dolt transition Phase 2 (dolt-test-woho epic). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Executed-By: beads/crew/emma Rig: beads Role: crew
This commit is contained in:
parent
820ff2bbeb
commit
6a51223b6f
56 changed files with 697 additions and 4081 deletions
338
cmd/bd/agent.go
338
cmd/bd/agent.go
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -151,46 +150,28 @@ func runAgentState(cmd *cobra.Command, args []string) error {
|
|||
var notFound bool
|
||||
var routedResult *RoutedResult
|
||||
|
||||
// Check if routing is needed (bypass daemon for cross-repo lookups)
|
||||
if needsRouting(agentArg) || daemonClient == nil {
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
// Check if it's a "not found" error
|
||||
if strings.Contains(err.Error(), "no issue found matching") {
|
||||
notFound = true
|
||||
agentID = agentArg // Use the input as the ID for creation
|
||||
} else {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
} else if routedResult != nil && routedResult.Issue != nil {
|
||||
agentID = routedResult.ResolvedID
|
||||
} else {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
// Check if it's a "not found" error
|
||||
if strings.Contains(err.Error(), "no issue found matching") {
|
||||
notFound = true
|
||||
agentID = agentArg
|
||||
}
|
||||
} else if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
// Check if it's a "not found" error
|
||||
if strings.Contains(err.Error(), "no issue found matching") {
|
||||
notFound = true
|
||||
agentID = agentArg // Use the input as the ID for creation
|
||||
} else {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
agentID = agentArg // Use the input as the ID for creation
|
||||
} else {
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
} else if routedResult != nil && routedResult.Issue != nil {
|
||||
agentID = routedResult.ResolvedID
|
||||
} else {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
notFound = true
|
||||
agentID = agentArg
|
||||
}
|
||||
|
||||
// Determine which store to use (routed or local)
|
||||
|
|
@ -215,41 +196,22 @@ func runAgentState(cmd *cobra.Command, args []string) error {
|
|||
CreatedBy: actor,
|
||||
}
|
||||
|
||||
if daemonClient != nil && !needsRouting(agentArg) {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
ID: agentID,
|
||||
Title: agent.Title,
|
||||
IssueType: string(types.TypeTask), // Use task type; gt:agent label marks it as agent
|
||||
RoleType: roleType,
|
||||
Rig: rig,
|
||||
CreatedBy: actor,
|
||||
Labels: []string{"gt:agent"}, // Gas Town agent label
|
||||
if err := activeStore.CreateIssue(ctx, agent, actor); err != nil {
|
||||
return fmt.Errorf("failed to auto-create agent bead %s: %w", agentID, err)
|
||||
}
|
||||
// Add gt:agent label to mark as agent bead
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "gt:agent", actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add gt:agent label: %v\n", err)
|
||||
}
|
||||
// Add role_type and rig labels for filtering
|
||||
if roleType != "" {
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "role_type:"+roleType, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add role_type label: %v\n", err)
|
||||
}
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to auto-create agent bead %s: %w", agentID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing create response: %w", err)
|
||||
}
|
||||
} else {
|
||||
if err := activeStore.CreateIssue(ctx, agent, actor); err != nil {
|
||||
return fmt.Errorf("failed to auto-create agent bead %s: %w", agentID, err)
|
||||
}
|
||||
// Add gt:agent label to mark as agent bead
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "gt:agent", actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add gt:agent label: %v\n", err)
|
||||
}
|
||||
// Add role_type and rig labels for filtering
|
||||
if roleType != "" {
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "role_type:"+roleType, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add role_type label: %v\n", err)
|
||||
}
|
||||
}
|
||||
if rig != "" {
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "rig:"+rig, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add rig label: %v\n", err)
|
||||
}
|
||||
}
|
||||
if rig != "" {
|
||||
if err := activeStore.AddLabel(ctx, agent.ID, "rig:"+rig, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add rig label: %v\n", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -260,15 +222,6 @@ func runAgentState(cmd *cobra.Command, args []string) error {
|
|||
agent = routedResult.Issue
|
||||
// Get labels from routed store
|
||||
labels, _ = routedResult.Store.GetLabels(ctx, agentID)
|
||||
} else if daemonClient != nil && !needsRouting(agentArg) {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
labels = agent.Labels
|
||||
} else {
|
||||
var err error
|
||||
agent, err = activeStore.GetIssue(ctx, agentID)
|
||||
|
|
@ -285,24 +238,12 @@ func runAgentState(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Update state and last_activity
|
||||
updateLastActivity := true
|
||||
if daemonClient != nil && !needsRouting(agentArg) {
|
||||
_, err := daemonClient.Update(&rpc.UpdateArgs{
|
||||
ID: agentID,
|
||||
AgentState: &state,
|
||||
LastActivity: &updateLastActivity,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update agent state: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"agent_state": state,
|
||||
"last_activity": time.Now(),
|
||||
}
|
||||
if err := activeStore.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to update agent state: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"agent_state": state,
|
||||
"last_activity": time.Now(),
|
||||
}
|
||||
if err := activeStore.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to update agent state: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -336,33 +277,22 @@ func runAgentHeartbeat(cmd *cobra.Command, args []string) error {
|
|||
var agentID string
|
||||
var routedResult *RoutedResult
|
||||
|
||||
// Check if routing is needed (bypass daemon for cross-repo lookups)
|
||||
if needsRouting(agentArg) || daemonClient == nil {
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("agent bead not found: %s", agentArg)
|
||||
}
|
||||
agentID = routedResult.ResolvedID
|
||||
} else if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("agent bead not found: %s", agentArg)
|
||||
}
|
||||
agentID = routedResult.ResolvedID
|
||||
|
||||
// Determine which store to use (routed or local)
|
||||
activeStore := store
|
||||
|
|
@ -378,15 +308,6 @@ func runAgentHeartbeat(cmd *cobra.Command, args []string) error {
|
|||
// Already have the issue from routed resolution
|
||||
agent = routedResult.Issue
|
||||
labels, _ = routedResult.Store.GetLabels(ctx, agentID)
|
||||
} else if daemonClient != nil && !needsRouting(agentArg) {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
labels = agent.Labels
|
||||
} else {
|
||||
var err error
|
||||
agent, err = activeStore.GetIssue(ctx, agentID)
|
||||
|
|
@ -402,22 +323,11 @@ func runAgentHeartbeat(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Update only last_activity
|
||||
updateLastActivity := true
|
||||
if daemonClient != nil && !needsRouting(agentArg) {
|
||||
_, err := daemonClient.Update(&rpc.UpdateArgs{
|
||||
ID: agentID,
|
||||
LastActivity: &updateLastActivity,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update agent heartbeat: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"last_activity": time.Now(),
|
||||
}
|
||||
if err := activeStore.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to update agent heartbeat: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"last_activity": time.Now(),
|
||||
}
|
||||
if err := activeStore.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to update agent heartbeat: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -448,34 +358,23 @@ func runAgentShow(cmd *cobra.Command, args []string) error {
|
|||
var agentID string
|
||||
var routedResult *RoutedResult
|
||||
|
||||
// Check if routing is needed (bypass daemon for cross-repo lookups)
|
||||
if needsRouting(agentArg) || daemonClient == nil {
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("agent bead not found: %s", agentArg)
|
||||
}
|
||||
agentID = routedResult.ResolvedID
|
||||
defer routedResult.Close()
|
||||
} else if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
// Use routed resolution for cross-repo lookups
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
if routedResult != nil {
|
||||
routedResult.Close()
|
||||
}
|
||||
return fmt.Errorf("agent bead not found: %s", agentArg)
|
||||
}
|
||||
agentID = routedResult.ResolvedID
|
||||
defer routedResult.Close()
|
||||
|
||||
// Get agent bead
|
||||
var agent *types.Issue
|
||||
|
|
@ -484,15 +383,6 @@ func runAgentShow(cmd *cobra.Command, args []string) error {
|
|||
// Already have the issue from routed resolution
|
||||
agent = routedResult.Issue
|
||||
labels, _ = routedResult.Store.GetLabels(ctx, agentID)
|
||||
} else if daemonClient != nil && !needsRouting(agentArg) {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
labels = agent.Labels
|
||||
} else {
|
||||
var err error
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
|
|
@ -585,26 +475,13 @@ func runAgentBackfillLabels(cmd *cobra.Command, args []string) error {
|
|||
ctx := rootCtx
|
||||
|
||||
// List all agent beads (by gt:agent label)
|
||||
var agents []*types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.List(&rpc.ListArgs{
|
||||
Labels: []string{"gt:agent"},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list agents: %w", err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agents); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
filter := types.IssueFilter{
|
||||
Labels: []string{"gt:agent"},
|
||||
}
|
||||
var err error
|
||||
agents, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list agents: %w", err)
|
||||
}
|
||||
filter := types.IssueFilter{
|
||||
Labels: []string{"gt:agent"},
|
||||
}
|
||||
var err error
|
||||
agents, err := store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list agents: %w", err)
|
||||
}
|
||||
|
||||
if len(agents) == 0 {
|
||||
|
|
@ -646,19 +523,7 @@ func runAgentBackfillLabels(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Check if labels already exist
|
||||
var existingLabels []string
|
||||
if daemonClient != nil {
|
||||
// Use show to get full issue with labels
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agent.ID})
|
||||
if err == nil {
|
||||
var fullAgent types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &fullAgent); err == nil {
|
||||
existingLabels = fullAgent.Labels
|
||||
}
|
||||
}
|
||||
} else {
|
||||
existingLabels, _ = store.GetLabels(ctx, agent.ID)
|
||||
}
|
||||
existingLabels, _ := store.GetLabels(ctx, agent.ID)
|
||||
|
||||
// Determine which labels need to be added
|
||||
needsRoleTypeLabel := roleType != "" && !containsLabel(existingLabels, "role_type:"+roleType)
|
||||
|
|
@ -700,49 +565,22 @@ func runAgentBackfillLabels(cmd *cobra.Command, args []string) error {
|
|||
updates["rig"] = rig
|
||||
}
|
||||
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{ID: agent.ID}
|
||||
if _, ok := updates["role_type"]; ok {
|
||||
rt := roleType
|
||||
updateArgs.RoleType = &rt
|
||||
}
|
||||
if _, ok := updates["rig"]; ok {
|
||||
r := rig
|
||||
updateArgs.Rig = &r
|
||||
}
|
||||
if _, err := daemonClient.Update(updateArgs); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to update fields for %s: %v\n", agent.ID, err)
|
||||
}
|
||||
} else {
|
||||
if err := store.UpdateIssue(ctx, agent.ID, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to update fields for %s: %v\n", agent.ID, err)
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, agent.ID, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to update fields for %s: %v\n", agent.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Add labels
|
||||
if needsRoleTypeLabel {
|
||||
label := "role_type:" + roleType
|
||||
if daemonClient != nil {
|
||||
if _, err := daemonClient.AddLabel(&rpc.LabelAddArgs{ID: agent.ID, Label: label}); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
} else {
|
||||
if err := store.AddLabel(ctx, agent.ID, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
if err := store.AddLabel(ctx, agent.ID, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
}
|
||||
if needsRigLabel {
|
||||
label := "rig:" + rig
|
||||
if daemonClient != nil {
|
||||
if _, err := daemonClient.AddLabel(&rpc.LabelAddArgs{ID: agent.ID, Label: label}); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
} else {
|
||||
if err := store.AddLabel(ctx, agent.ID, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
if err := store.AddLabel(ctx, agent.ID, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add label %s to %s: %v\n", label, agent.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,12 +95,7 @@ SEE ALSO:
|
|||
}
|
||||
|
||||
// Ensure we have storage
|
||||
if daemonClient != nil {
|
||||
if err := ensureDirectMode("daemon does not support delete command"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if store == nil {
|
||||
if store == nil {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
194
cmd/bd/close.go
194
cmd/bd/close.go
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -9,7 +8,6 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/hooks"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -73,195 +71,17 @@ create, update, show, or close operation).`,
|
|||
// Resolve partial IDs first, handling cross-rig routing
|
||||
var resolvedIDs []string
|
||||
var routedArgs []string // IDs that need cross-repo routing (bypass daemon)
|
||||
if daemonClient != nil {
|
||||
for _, id := range args {
|
||||
// Check if this ID needs routing to a different beads directory
|
||||
if needsRouting(id) {
|
||||
routedArgs = append(routedArgs, id)
|
||||
continue
|
||||
}
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
// Direct mode - check routing for each ID
|
||||
for _, id := range args {
|
||||
if needsRouting(id) {
|
||||
routedArgs = append(routedArgs, id)
|
||||
} else {
|
||||
resolved, err := utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", id, err)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolvedID)
|
||||
resolvedIDs = append(resolvedIDs, resolved)
|
||||
}
|
||||
} else {
|
||||
// Direct mode - check routing for each ID
|
||||
for _, id := range args {
|
||||
if needsRouting(id) {
|
||||
routedArgs = append(routedArgs, id)
|
||||
} else {
|
||||
resolved, err := utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", id, err)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolved)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
closedIssues := []*types.Issue{}
|
||||
for _, id := range resolvedIDs {
|
||||
// Get issue for template and pinned checks
|
||||
showArgs := &rpc.ShowArgs{ID: id}
|
||||
showResp, showErr := daemonClient.Show(showArgs)
|
||||
if showErr == nil {
|
||||
var issue types.Issue
|
||||
if json.Unmarshal(showResp.Data, &issue) == nil {
|
||||
if err := validateIssueClosable(id, &issue, force); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
continue
|
||||
}
|
||||
// Check gate satisfaction for machine-checkable gates
|
||||
if !force {
|
||||
if err := checkGateSatisfaction(&issue); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot close %s: %s\n", id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closeArgs := &rpc.CloseArgs{
|
||||
ID: id,
|
||||
Reason: reason,
|
||||
Session: session,
|
||||
SuggestNext: suggestNext,
|
||||
Force: force,
|
||||
}
|
||||
resp, err := daemonClient.CloseIssue(closeArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Handle response based on whether SuggestNext was requested
|
||||
if suggestNext {
|
||||
var result rpc.CloseResult
|
||||
if err := json.Unmarshal(resp.Data, &result); err == nil {
|
||||
if result.Closed != nil {
|
||||
// Run close hook
|
||||
if hookRunner != nil {
|
||||
hookRunner.Run(hooks.EventClose, result.Closed)
|
||||
}
|
||||
if jsonOutput {
|
||||
closedIssues = append(closedIssues, result.Closed)
|
||||
}
|
||||
}
|
||||
if !jsonOutput {
|
||||
fmt.Printf("%s Closed %s: %s\n", ui.RenderPass("✓"), id, reason)
|
||||
// Display newly unblocked issues
|
||||
if len(result.Unblocked) > 0 {
|
||||
fmt.Printf("\nNewly unblocked:\n")
|
||||
for _, issue := range result.Unblocked {
|
||||
fmt.Printf(" • %s %q (P%d)\n", issue.ID, issue.Title, issue.Priority)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err == nil {
|
||||
// Run close hook
|
||||
if hookRunner != nil {
|
||||
hookRunner.Run(hooks.EventClose, &issue)
|
||||
}
|
||||
if jsonOutput {
|
||||
closedIssues = append(closedIssues, &issue)
|
||||
}
|
||||
}
|
||||
if !jsonOutput {
|
||||
fmt.Printf("%s Closed %s: %s\n", ui.RenderPass("✓"), id, reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle routed IDs via direct mode (cross-rig)
|
||||
for _, id := range routedArgs {
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := validateIssueClosable(result.ResolvedID, result.Issue, force); err != nil {
|
||||
result.Close()
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check gate satisfaction for machine-checkable gates (GH#1467)
|
||||
if !force {
|
||||
if err := checkGateSatisfaction(result.Issue); err != nil {
|
||||
result.Close()
|
||||
fmt.Fprintf(os.Stderr, "cannot close %s: %s\n", id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Check if issue has open blockers (GH#962)
|
||||
if !force {
|
||||
blocked, blockers, err := result.Store.IsBlocked(ctx, result.ResolvedID)
|
||||
if err != nil {
|
||||
result.Close()
|
||||
fmt.Fprintf(os.Stderr, "Error checking blockers for %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if blocked && len(blockers) > 0 {
|
||||
result.Close()
|
||||
fmt.Fprintf(os.Stderr, "cannot close %s: blocked by open issues %v (use --force to override)\n", id, blockers)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := result.Store.CloseIssue(ctx, result.ResolvedID, reason, actor, session); err != nil {
|
||||
result.Close()
|
||||
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Get updated issue for hook
|
||||
closedIssue, _ := result.Store.GetIssue(ctx, result.ResolvedID)
|
||||
if closedIssue != nil && hookRunner != nil {
|
||||
hookRunner.Run(hooks.EventClose, closedIssue)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
if closedIssue != nil {
|
||||
closedIssues = append(closedIssues, closedIssue)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s Closed %s: %s\n", ui.RenderPass("✓"), result.ResolvedID, reason)
|
||||
}
|
||||
result.Close()
|
||||
}
|
||||
|
||||
// Handle --continue flag in daemon mode
|
||||
// Note: --continue requires direct database access to walk parent-child chain
|
||||
if continueFlag && len(closedIssues) > 0 {
|
||||
fmt.Fprintf(os.Stderr, "\nNote: --continue requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon close %s --continue\n", resolvedIDs[0])
|
||||
}
|
||||
|
||||
if jsonOutput && len(closedIssues) > 0 {
|
||||
outputJSON(closedIssues)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -36,54 +34,19 @@ Examples:
|
|||
localTime, _ := cmd.Flags().GetBool("local-time")
|
||||
issueID := args[0]
|
||||
|
||||
comments := make([]*types.Comment, 0)
|
||||
usedDaemon := false
|
||||
if daemonClient != nil {
|
||||
// Resolve short/partial ID to full ID before sending to daemon (#1070)
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: issueID}
|
||||
resolveResp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", issueID, err)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resolveResp.Data, &resolvedID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
issueID = resolvedID
|
||||
|
||||
resp, err := daemonClient.ListComments(&rpc.CommentListArgs{ID: issueID})
|
||||
if err != nil {
|
||||
if isUnknownOperationError(err) {
|
||||
if err := fallbackToDirectMode("daemon does not support comment_list RPC"); err != nil {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
} else {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err := json.Unmarshal(resp.Data, &comments); err != nil {
|
||||
FatalErrorRespectJSON("decoding comments: %v", err)
|
||||
}
|
||||
usedDaemon = true
|
||||
}
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
ctx := rootCtx
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
issueID = fullID
|
||||
|
||||
if !usedDaemon {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
ctx := rootCtx
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
issueID = fullID
|
||||
|
||||
result, err := store.GetIssueComments(ctx, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
comments = result
|
||||
comments, err := store.GetIssueComments(ctx, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting comments: %v", err)
|
||||
}
|
||||
|
||||
// Normalize nil to empty slice for consistent JSON output
|
||||
|
|
@ -156,58 +119,20 @@ Examples:
|
|||
author = getActorWithGit()
|
||||
}
|
||||
|
||||
var comment *types.Comment
|
||||
if daemonClient != nil {
|
||||
// Resolve short/partial ID to full ID before sending to daemon (#1070)
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: issueID}
|
||||
resolveResp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", issueID, err)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resolveResp.Data, &resolvedID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
issueID = resolvedID
|
||||
|
||||
resp, err := daemonClient.AddComment(&rpc.CommentAddArgs{
|
||||
ID: issueID,
|
||||
Author: author,
|
||||
Text: commentText,
|
||||
})
|
||||
if err != nil {
|
||||
if isUnknownOperationError(err) {
|
||||
if err := fallbackToDirectMode("daemon does not support comment_add RPC"); err != nil {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
} else {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
} else {
|
||||
var parsed types.Comment
|
||||
if err := json.Unmarshal(resp.Data, &parsed); err != nil {
|
||||
FatalErrorRespectJSON("decoding comment: %v", err)
|
||||
}
|
||||
comment = &parsed
|
||||
}
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
ctx := rootCtx
|
||||
|
||||
if comment == nil {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
ctx := rootCtx
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
issueID = fullID
|
||||
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
issueID = fullID
|
||||
|
||||
comment, err = store.AddIssueComment(ctx, issueID, author, commentText)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
comment, err := store.AddIssueComment(ctx, issueID, author, commentText)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("adding comment: %v", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
|
|||
|
|
@ -109,16 +109,12 @@ Examples:
|
|||
|
||||
// Handle compact stats first
|
||||
if compactStats {
|
||||
if daemonClient != nil {
|
||||
runCompactStatsRPC()
|
||||
} else {
|
||||
compactStore, ok := store.(storage.CompactableStorage)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "Error: compact requires CompactableStorage (not supported by current backend)\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
runCompactStats(ctx, compactStore)
|
||||
compactStore, ok := store.(storage.CompactableStorage)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "Error: compact requires CompactableStorage (not supported by current backend)\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
runCompactStats(ctx, compactStore)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -218,13 +214,7 @@ Examples:
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Use RPC if daemon available, otherwise direct mode
|
||||
if daemonClient != nil {
|
||||
runCompactRPC(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// Fallback to direct mode
|
||||
// Direct mode
|
||||
apiKey := os.Getenv("ANTHROPIC_API_KEY")
|
||||
if apiKey == "" && !compactDryRun {
|
||||
fmt.Fprintf(os.Stderr, "Error: --auto mode requires ANTHROPIC_API_KEY environment variable\n")
|
||||
|
|
|
|||
|
|
@ -366,12 +366,7 @@ func runCook(cmd *cobra.Command, args []string) {
|
|||
if flags.persist {
|
||||
CheckReadonly("cook --persist")
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: cook --persist requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon cook %s --persist ...\n", flags.formulaPath)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
111
cmd/bd/count.go
111
cmd/bd/count.go
|
|
@ -2,14 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
|
@ -107,115 +105,6 @@ Examples:
|
|||
ctx := rootCtx
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
countArgs := &rpc.CountArgs{
|
||||
Status: status,
|
||||
IssueType: issueType,
|
||||
Assignee: assignee,
|
||||
GroupBy: groupBy,
|
||||
}
|
||||
if cmd.Flags().Changed("priority") {
|
||||
priority, _ := cmd.Flags().GetInt("priority")
|
||||
countArgs.Priority = &priority
|
||||
}
|
||||
if len(labels) > 0 {
|
||||
countArgs.Labels = labels
|
||||
}
|
||||
if len(labelsAny) > 0 {
|
||||
countArgs.LabelsAny = labelsAny
|
||||
}
|
||||
if titleSearch != "" {
|
||||
countArgs.Query = titleSearch
|
||||
}
|
||||
if idFilter != "" {
|
||||
ids := utils.NormalizeLabels(strings.Split(idFilter, ","))
|
||||
if len(ids) > 0 {
|
||||
countArgs.IDs = ids
|
||||
}
|
||||
}
|
||||
|
||||
// Pattern matching
|
||||
countArgs.TitleContains = titleContains
|
||||
countArgs.DescriptionContains = descContains
|
||||
countArgs.NotesContains = notesContains
|
||||
|
||||
// Date ranges
|
||||
countArgs.CreatedAfter = createdAfter
|
||||
countArgs.CreatedBefore = createdBefore
|
||||
countArgs.UpdatedAfter = updatedAfter
|
||||
countArgs.UpdatedBefore = updatedBefore
|
||||
countArgs.ClosedAfter = closedAfter
|
||||
countArgs.ClosedBefore = closedBefore
|
||||
|
||||
// Empty/null checks
|
||||
countArgs.EmptyDescription = emptyDesc
|
||||
countArgs.NoAssignee = noAssignee
|
||||
countArgs.NoLabels = noLabels
|
||||
|
||||
// Priority range
|
||||
if cmd.Flags().Changed("priority-min") {
|
||||
countArgs.PriorityMin = &priorityMin
|
||||
}
|
||||
if cmd.Flags().Changed("priority-max") {
|
||||
countArgs.PriorityMax = &priorityMax
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Count(countArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if groupBy == "" {
|
||||
// Simple count
|
||||
var result struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &result); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(result)
|
||||
} else {
|
||||
fmt.Println(result.Count)
|
||||
}
|
||||
} else {
|
||||
// Grouped count
|
||||
var result struct {
|
||||
Total int `json:"total"`
|
||||
Groups []struct {
|
||||
Group string `json:"group"`
|
||||
Count int `json:"count"`
|
||||
} `json:"groups"`
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &result); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(result)
|
||||
} else {
|
||||
// Sort groups for consistent output
|
||||
slices.SortFunc(result.Groups, func(a, b struct {
|
||||
Group string `json:"group"`
|
||||
Count int `json:"count"`
|
||||
}) int {
|
||||
return cmp.Compare(a.Group, b.Group)
|
||||
})
|
||||
|
||||
fmt.Printf("Total: %d\n\n", result.Total)
|
||||
for _, g := range result.Groups {
|
||||
fmt.Printf("%s: %d\n", g.Group, g.Count)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
filter := types.IssueFilter{}
|
||||
if status != "" && status != "all" {
|
||||
|
|
|
|||
|
|
@ -488,72 +488,6 @@ var createCmd = &cobra.Command{
|
|||
externalRefPtr = &externalRef
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
ID: explicitID,
|
||||
Parent: parentID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
IssueType: issueType,
|
||||
Priority: priority,
|
||||
Design: design,
|
||||
AcceptanceCriteria: acceptance,
|
||||
Notes: notes,
|
||||
SpecID: specID,
|
||||
Assignee: assignee,
|
||||
ExternalRef: externalRef,
|
||||
EstimatedMinutes: estimatedMinutes,
|
||||
Labels: labels,
|
||||
Dependencies: deps,
|
||||
WaitsFor: waitsFor,
|
||||
WaitsForGate: waitsForGate,
|
||||
Ephemeral: wisp,
|
||||
CreatedBy: getActorWithGit(),
|
||||
Owner: getOwner(),
|
||||
MolType: string(molType),
|
||||
WispType: string(wispType),
|
||||
Rig: agentRig,
|
||||
EventCategory: eventCategory,
|
||||
EventActor: eventActor,
|
||||
EventTarget: eventTarget,
|
||||
EventPayload: eventPayload,
|
||||
DueAt: formatTimeForRPC(dueAt),
|
||||
DeferUntil: formatTimeForRPC(deferUntil),
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
FatalError("%v", err)
|
||||
}
|
||||
|
||||
// Parse response to get issue for hook
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalError("parsing response: %v", err)
|
||||
}
|
||||
|
||||
// Run create hook
|
||||
if hookRunner != nil {
|
||||
hookRunner.Run(hooks.EventCreate, &issue)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
fmt.Println(string(resp.Data))
|
||||
} else if silent {
|
||||
fmt.Println(issue.ID)
|
||||
} else {
|
||||
fmt.Printf("%s Created issue: %s\n", ui.RenderPass("✓"), issue.ID)
|
||||
fmt.Printf(" Title: %s\n", issue.Title)
|
||||
fmt.Printf(" Priority: P%d\n", issue.Priority)
|
||||
fmt.Printf(" Status: %s\n", issue.Status)
|
||||
}
|
||||
|
||||
// Track as last touched issue
|
||||
SetLastTouchedID(issue.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
issue := &types.Issue{
|
||||
ID: explicitID, // Set explicit ID if provided (empty string if not)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
|
@ -10,7 +9,6 @@ import (
|
|||
|
||||
"github.com/charmbracelet/huh"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
|
|
@ -341,38 +339,6 @@ func runCreateForm(cmd *cobra.Command) {
|
|||
// Parse the form input
|
||||
fv := parseCreateFormInput(raw)
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
Title: fv.Title,
|
||||
Description: fv.Description,
|
||||
IssueType: fv.IssueType,
|
||||
Priority: fv.Priority,
|
||||
Design: fv.Design,
|
||||
AcceptanceCriteria: fv.AcceptanceCriteria,
|
||||
Assignee: fv.Assignee,
|
||||
ExternalRef: fv.ExternalRef,
|
||||
Labels: fv.Labels,
|
||||
Dependencies: fv.Dependencies,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
FatalError("%v", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
fmt.Println(string(resp.Data))
|
||||
} else {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalError("parsing response: %v", err)
|
||||
}
|
||||
printCreatedIssue(&issue)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode - use the extracted creation function
|
||||
issue, err := CreateIssueFromFormValues(rootCtx, store, fv, actor)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/timeparsing"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
|
|
@ -48,71 +46,16 @@ Examples:
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
// Resolve partial IDs first
|
||||
var resolvedIDs []string
|
||||
if daemonClient != nil {
|
||||
for _, id := range args {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolvedID)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// Resolve partial IDs
|
||||
_, err := utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
deferredIssues := []*types.Issue{}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
for _, id := range resolvedIDs {
|
||||
status := string(types.StatusDeferred)
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: id,
|
||||
Status: &status,
|
||||
}
|
||||
// Add defer_until if --until specified (GH#820)
|
||||
if deferUntil != nil {
|
||||
s := deferUntil.Format(time.RFC3339)
|
||||
updateArgs.DeferUntil = &s
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error deferring %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err == nil {
|
||||
deferredIssues = append(deferredIssues, &issue)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s Deferred %s\n", ui.RenderAccent("*"), id)
|
||||
}
|
||||
}
|
||||
|
||||
if jsonOutput && len(deferredIssues) > 0 {
|
||||
outputJSON(deferredIssues)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Fall back to direct storage access
|
||||
// Direct storage access
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -10,77 +10,11 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
||||
// deleteViaDaemon uses the RPC daemon to delete issues
|
||||
func deleteViaDaemon(issueIDs []string, force, dryRun, cascade bool, jsonOutput bool, reason string) {
|
||||
// NOTE: The daemon's delete handler implements the core deletion logic.
|
||||
// cascade and detailed dependency handling are not yet implemented in the RPC layer.
|
||||
// For now, we pass force=true to the daemon and rely on its simpler deletion logic.
|
||||
|
||||
deleteArgs := &rpc.DeleteArgs{
|
||||
IDs: issueIDs,
|
||||
Force: force,
|
||||
DryRun: dryRun,
|
||||
Cascade: cascade,
|
||||
Reason: reason,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Delete(deleteArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse response
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(resp.Data, &result); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Pretty print for human output
|
||||
if dryRun {
|
||||
fmt.Printf("Dry run - would delete %v issue(s)\n", result["issue_count"])
|
||||
return
|
||||
}
|
||||
|
||||
deletedCount := int(result["deleted_count"].(float64))
|
||||
totalCount := int(result["total_count"].(float64))
|
||||
|
||||
if deletedCount > 0 {
|
||||
if deletedCount == 1 {
|
||||
fmt.Printf("%s Deleted %s\n", ui.RenderPass("✓"), issueIDs[0])
|
||||
} else {
|
||||
fmt.Printf("%s Deleted %d issue(s)\n", ui.RenderPass("✓"), deletedCount)
|
||||
}
|
||||
}
|
||||
|
||||
if errors, ok := result["errors"].([]interface{}); ok && len(errors) > 0 {
|
||||
fmt.Printf("\n%s Warnings:\n", ui.RenderWarn("⚠"))
|
||||
for _, e := range errors {
|
||||
fmt.Printf(" %s\n", e)
|
||||
}
|
||||
if deletedCount < totalCount {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete <issue-id> [issue-id...]",
|
||||
GroupID: "issues",
|
||||
|
|
@ -151,12 +85,6 @@ the issues will not resurrect from remote branches.`,
|
|||
// Remove duplicates
|
||||
issueIDs = uniqueStrings(issueIDs)
|
||||
|
||||
// Use daemon if available, otherwise use direct mode
|
||||
if daemonClient != nil {
|
||||
deleteViaDaemon(issueIDs, force, dryRun, cascade, jsonOutput, reason)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode - ensure store is available
|
||||
if store == nil {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
|
|
|
|||
318
cmd/bd/dep.go
318
cmd/bd/dep.go
|
|
@ -3,7 +3,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -11,7 +10,6 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/routing"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
|
|
@ -115,38 +113,15 @@ Examples:
|
|||
|
||||
// Resolve partial IDs first
|
||||
var fromID, toID string
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, blocksID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blocksID, err)
|
||||
}
|
||||
|
||||
if daemonClient != nil {
|
||||
// Resolve the blocked issue ID (the one that will depend on the blocker)
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: blocksID}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blocksID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fromID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
|
||||
// Resolve the blocker issue ID
|
||||
resolveArgs = &rpc.ResolveIDArgs{ID: blockerID}
|
||||
resp, err = daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blockerID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &toID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, blocksID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blocksID, err)
|
||||
}
|
||||
|
||||
toID, err = utils.ResolvePartialID(ctx, store, blockerID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blockerID, err)
|
||||
}
|
||||
toID, err = utils.ResolvePartialID(ctx, store, blockerID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", blockerID, err)
|
||||
}
|
||||
|
||||
// Check for child→parent dependency anti-pattern
|
||||
|
|
@ -154,29 +129,15 @@ Examples:
|
|||
FatalErrorRespectJSON("cannot add dependency: %s is already a child of %s. Children inherit dependency on parent completion via hierarchy. Adding an explicit dependency would create a deadlock", fromID, toID)
|
||||
}
|
||||
|
||||
// Add the dependency via daemon or direct mode
|
||||
if daemonClient != nil {
|
||||
depArgs := &rpc.DepAddArgs{
|
||||
FromID: fromID,
|
||||
ToID: toID,
|
||||
DepType: depType,
|
||||
}
|
||||
// Direct mode
|
||||
dep := &types.Dependency{
|
||||
IssueID: fromID,
|
||||
DependsOnID: toID,
|
||||
Type: types.DependencyType(depType),
|
||||
}
|
||||
|
||||
_, err := daemonClient.AddDependency(depArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
dep := &types.Dependency{
|
||||
IssueID: fromID,
|
||||
DependsOnID: toID,
|
||||
Type: types.DependencyType(depType),
|
||||
}
|
||||
|
||||
if err := store.AddDependency(ctx, dep, actor); err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep, actor); err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Check for cycles after adding dependency (both daemon and direct mode)
|
||||
|
|
@ -274,64 +235,29 @@ Examples:
|
|||
// Check if toID is an external reference (don't resolve it)
|
||||
isExternalRef := strings.HasPrefix(dependsOnArg, "external:")
|
||||
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fromID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
|
||||
if isExternalRef {
|
||||
// External references are stored as-is
|
||||
toID = dependsOnArg
|
||||
// Validate format: external:<project>:<capability>
|
||||
if err := validateExternalRef(toID); err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
resolveArgs = &rpc.ResolveIDArgs{ID: dependsOnArg}
|
||||
resp, err = daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
// Resolution failed - try auto-converting to external ref
|
||||
beadsDir := getBeadsDir()
|
||||
if extRef := routing.ResolveToExternalRef(dependsOnArg, beadsDir); extRef != "" {
|
||||
toID = extRef
|
||||
isExternalRef = true
|
||||
} else {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", dependsOnArg, err)
|
||||
}
|
||||
} else if err := json.Unmarshal(resp.Data, &toID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
if isExternalRef {
|
||||
// External references are stored as-is
|
||||
toID = dependsOnArg
|
||||
// Validate format: external:<project>:<capability>
|
||||
if err := validateExternalRef(toID); err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
toID, err = utils.ResolvePartialID(ctx, store, dependsOnArg)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
|
||||
if isExternalRef {
|
||||
// External references are stored as-is
|
||||
toID = dependsOnArg
|
||||
// Validate format: external:<project>:<capability>
|
||||
if err := validateExternalRef(toID); err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
toID, err = utils.ResolvePartialID(ctx, store, dependsOnArg)
|
||||
if err != nil {
|
||||
// Resolution failed - try auto-converting to external ref
|
||||
beadsDir := getBeadsDir()
|
||||
if extRef := routing.ResolveToExternalRef(dependsOnArg, beadsDir); extRef != "" {
|
||||
toID = extRef
|
||||
isExternalRef = true
|
||||
} else {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", dependsOnArg, err)
|
||||
}
|
||||
// Resolution failed - try auto-converting to external ref
|
||||
beadsDir := getBeadsDir()
|
||||
if extRef := routing.ResolveToExternalRef(dependsOnArg, beadsDir); extRef != "" {
|
||||
toID = extRef
|
||||
isExternalRef = true
|
||||
} else {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", dependsOnArg, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -342,29 +268,6 @@ Examples:
|
|||
FatalErrorRespectJSON("cannot add dependency: %s is already a child of %s. Children inherit dependency on parent completion via hierarchy. Adding an explicit dependency would create a deadlock", fromID, toID)
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
depArgs := &rpc.DepAddArgs{
|
||||
FromID: fromID,
|
||||
ToID: toID,
|
||||
DepType: depType,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.AddDependency(depArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
fmt.Println(string(resp.Data))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%s Added dependency: %s depends on %s (%s)\n",
|
||||
ui.RenderPass("✓"), args[0], dependsOnArg, depType)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
dep := &types.Dependency{
|
||||
IssueID: fromID,
|
||||
|
|
@ -423,54 +326,22 @@ Examples:
|
|||
}
|
||||
}()
|
||||
|
||||
if daemonClient != nil && needsRouting(args[0]) {
|
||||
// Cross-rig: bypass daemon, resolve via routing
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
FatalErrorRespectJSON("no issue found: %s", args[0])
|
||||
}
|
||||
fullID = routedResult.ResolvedID
|
||||
// Direct mode - use routing-aware resolution
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
FatalErrorRespectJSON("no issue found: %s", args[0])
|
||||
}
|
||||
fullID = routedResult.ResolvedID
|
||||
if routedResult.Routed {
|
||||
depStore = routedResult.Store
|
||||
} else if daemonClient != nil {
|
||||
// Local daemon resolution
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode - use routing-aware resolution
|
||||
var err error
|
||||
routedResult, err = resolveAndGetIssueWithRouting(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
if routedResult == nil || routedResult.Issue == nil {
|
||||
FatalErrorRespectJSON("no issue found: %s", args[0])
|
||||
}
|
||||
fullID = routedResult.ResolvedID
|
||||
if routedResult.Routed {
|
||||
depStore = routedResult.Store
|
||||
}
|
||||
}
|
||||
|
||||
// If no routed store was used, set up local storage
|
||||
// If no routed store was used, use local storage
|
||||
if depStore == nil {
|
||||
if daemonClient != nil && store == nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(rootCtx, getBeadsDir())
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
depStore = store
|
||||
}
|
||||
|
||||
|
|
@ -482,7 +353,6 @@ Examples:
|
|||
}
|
||||
|
||||
var issues []*types.IssueWithDependencyMetadata
|
||||
var err error
|
||||
|
||||
if direction == "up" {
|
||||
issues, err = depStore.GetDependentsWithMetadata(ctx, fullID)
|
||||
|
|
@ -577,57 +447,15 @@ var depRemoveCmd = &cobra.Command{
|
|||
|
||||
// Resolve partial IDs first
|
||||
var fromID, toID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fromID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
|
||||
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
|
||||
resp, err = daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &toID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
|
||||
toID, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
var err error
|
||||
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
depArgs := &rpc.DepRemoveArgs{
|
||||
FromID: fromID,
|
||||
ToID: toID,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.RemoveDependency(depArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
fmt.Println(string(resp.Data))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%s Removed dependency: %s no longer depends on %s\n",
|
||||
ui.RenderPass("✓"), fromID, toID)
|
||||
return
|
||||
toID, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
|
|
@ -673,32 +501,12 @@ Examples:
|
|||
|
||||
// Resolve partial ID first
|
||||
var fullID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
|
||||
// If daemon is running but doesn't support this command, use direct storage
|
||||
if daemonClient != nil && store == nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(rootCtx, getBeadsDir())
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
|
||||
showAllPaths, _ := cmd.Flags().GetBool("show-all-paths")
|
||||
maxDepth, _ := cmd.Flags().GetInt("max-depth")
|
||||
|
|
@ -725,7 +533,6 @@ Examples:
|
|||
|
||||
// For "both" direction, we need to fetch both trees and merge them
|
||||
var tree []*types.TreeNode
|
||||
var err error
|
||||
|
||||
if direction == "both" {
|
||||
// Get dependencies (down) - what blocks this issue
|
||||
|
|
@ -802,15 +609,6 @@ var depCyclesCmd = &cobra.Command{
|
|||
Use: "cycles",
|
||||
Short: "Detect dependency cycles",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// If daemon is running but doesn't support this command, use direct storage
|
||||
if daemonClient != nil && store == nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(rootCtx, getBeadsDir())
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
|
||||
ctx := rootCtx
|
||||
cycles, err := store.DetectCycles(ctx)
|
||||
|
|
|
|||
|
|
@ -45,13 +45,6 @@ EXAMPLES:
|
|||
|
||||
NOTE: Review detected issues carefully before using --clean. False positives are possible.`,
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
// Check daemon mode - not supported yet (uses direct storage access)
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: detect-pollution command not yet supported in daemon mode\n")
|
||||
fmt.Fprintf(os.Stderr, "Use: bd --no-daemon detect-pollution\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
clean, _ := cmd.Flags().GetBool("clean")
|
||||
yes, _ := cmd.Flags().GetBool("yes")
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -66,31 +65,14 @@ func runDuplicate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve partial IDs
|
||||
var duplicateID, canonicalID string
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[0]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &duplicateID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: duplicateOf})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", duplicateOf, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &canonicalID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
duplicateID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
canonicalID, err = utils.ResolvePartialID(ctx, store, duplicateOf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", duplicateOf, err)
|
||||
}
|
||||
var err error
|
||||
duplicateID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
canonicalID, err = utils.ResolvePartialID(ctx, store, duplicateOf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", duplicateOf, err)
|
||||
}
|
||||
|
||||
if duplicateID == canonicalID {
|
||||
|
|
@ -99,42 +81,19 @@ func runDuplicate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Verify canonical issue exists
|
||||
var canonical *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: canonicalID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("canonical issue not found: %s", canonicalID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &canonical); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
canonical, err = store.GetIssue(ctx, canonicalID)
|
||||
if err != nil || canonical == nil {
|
||||
return fmt.Errorf("canonical issue not found: %s", canonicalID)
|
||||
}
|
||||
canonical, err = store.GetIssue(ctx, canonicalID)
|
||||
if err != nil || canonical == nil {
|
||||
return fmt.Errorf("canonical issue not found: %s", canonicalID)
|
||||
}
|
||||
|
||||
// Update the duplicate issue with duplicate_of and close it
|
||||
closedStatus := string(types.StatusClosed)
|
||||
if daemonClient != nil {
|
||||
// Use RPC for daemon mode
|
||||
_, err := daemonClient.Update(&rpc.UpdateArgs{
|
||||
ID: duplicateID,
|
||||
DuplicateOf: &canonicalID,
|
||||
Status: &closedStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to mark as duplicate: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"duplicate_of": canonicalID,
|
||||
"status": closedStatus,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, duplicateID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to mark as duplicate: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"duplicate_of": canonicalID,
|
||||
"status": closedStatus,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, duplicateID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to mark as duplicate: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -164,31 +123,14 @@ func runSupersede(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve partial IDs
|
||||
var oldID, newID string
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[0]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &oldID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: supersededWith})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", supersededWith, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &newID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
oldID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
newID, err = utils.ResolvePartialID(ctx, store, supersededWith)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", supersededWith, err)
|
||||
}
|
||||
var err error
|
||||
oldID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
newID, err = utils.ResolvePartialID(ctx, store, supersededWith)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", supersededWith, err)
|
||||
}
|
||||
|
||||
if oldID == newID {
|
||||
|
|
@ -197,42 +139,19 @@ func runSupersede(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Verify new issue exists
|
||||
var newIssue *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: newID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("replacement issue not found: %s", newID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &newIssue); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
newIssue, err = store.GetIssue(ctx, newID)
|
||||
if err != nil || newIssue == nil {
|
||||
return fmt.Errorf("replacement issue not found: %s", newID)
|
||||
}
|
||||
newIssue, err = store.GetIssue(ctx, newID)
|
||||
if err != nil || newIssue == nil {
|
||||
return fmt.Errorf("replacement issue not found: %s", newID)
|
||||
}
|
||||
|
||||
// Update the old issue with superseded_by and close it
|
||||
closedStatus := string(types.StatusClosed)
|
||||
if daemonClient != nil {
|
||||
// Use RPC for daemon mode
|
||||
_, err := daemonClient.Update(&rpc.UpdateArgs{
|
||||
ID: oldID,
|
||||
SupersededBy: &newID,
|
||||
Status: &closedStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to mark as superseded: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"superseded_by": newID,
|
||||
"status": closedStatus,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, oldID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to mark as superseded: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"superseded_by": newID,
|
||||
"status": closedStatus,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, oldID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to mark as superseded: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
|
|||
|
|
@ -31,12 +31,6 @@ Example:
|
|||
if autoMerge && !dryRun {
|
||||
CheckReadonly("duplicates --auto-merge")
|
||||
}
|
||||
// Check daemon mode - not supported yet (merge command limitation)
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: duplicates command not yet supported in daemon mode (see bd-190)\n")
|
||||
fmt.Fprintf(os.Stderr, "Use: bd --no-daemon duplicates\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
ctx := rootCtx
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
|
@ -34,14 +31,12 @@ Examples:
|
|||
id := args[0]
|
||||
ctx := rootCtx
|
||||
|
||||
// Resolve partial ID if in direct mode
|
||||
if daemonClient == nil {
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", id, err)
|
||||
}
|
||||
id = fullID
|
||||
// Resolve partial ID
|
||||
fullID, err := utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", id, err)
|
||||
}
|
||||
id = fullID
|
||||
|
||||
// Determine which field to edit
|
||||
fieldToEdit := "description"
|
||||
|
|
@ -74,30 +69,12 @@ Examples:
|
|||
}
|
||||
|
||||
// Get the current issue
|
||||
var issue *types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
// Daemon mode
|
||||
showArgs := &rpc.ShowArgs{ID: id}
|
||||
resp, err := daemonClient.Show(showArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("fetching issue %s: %v", id, err)
|
||||
}
|
||||
|
||||
issue = &types.Issue{}
|
||||
if err := json.Unmarshal(resp.Data, issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing issue data: %v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
issue, err = store.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("fetching issue %s: %v", id, err)
|
||||
}
|
||||
if issue == nil {
|
||||
FatalErrorRespectJSON("issue %s not found", id)
|
||||
}
|
||||
issue, err := store.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("fetching issue %s: %v", id, err)
|
||||
}
|
||||
if issue == nil {
|
||||
FatalErrorRespectJSON("issue %s not found", id)
|
||||
}
|
||||
|
||||
// Get the current field value
|
||||
|
|
@ -167,32 +144,8 @@ Examples:
|
|||
fieldToEdit: newValue,
|
||||
}
|
||||
|
||||
if daemonClient != nil {
|
||||
// Daemon mode
|
||||
updateArgs := &rpc.UpdateArgs{ID: id}
|
||||
|
||||
switch fieldToEdit {
|
||||
case "title":
|
||||
updateArgs.Title = &newValue
|
||||
case "description":
|
||||
updateArgs.Description = &newValue
|
||||
case "design":
|
||||
updateArgs.Design = &newValue
|
||||
case "notes":
|
||||
updateArgs.Notes = &newValue
|
||||
case "acceptance_criteria":
|
||||
updateArgs.AcceptanceCriteria = &newValue
|
||||
}
|
||||
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("updating issue: %v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
if err := store.UpdateIssue(ctx, id, updates, actor); err != nil {
|
||||
FatalErrorRespectJSON("updating issue: %v", err)
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, id, updates, actor); err != nil {
|
||||
FatalErrorRespectJSON("updating issue: %v", err)
|
||||
}
|
||||
|
||||
fieldName := strings.ReplaceAll(fieldToEdit, "_", " ")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"os"
|
||||
|
|
@ -23,34 +21,19 @@ var epicStatusCmd = &cobra.Command{
|
|||
// Use global jsonOutput set by PersistentPreRun
|
||||
var epics []*types.EpicStatus
|
||||
var err error
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.EpicStatus(&rpc.EpicStatusArgs{
|
||||
EligibleOnly: eligibleOnly,
|
||||
})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("communicating with daemon: %v", err)
|
||||
}
|
||||
if !resp.Success {
|
||||
FatalErrorRespectJSON("getting epic status: %s", resp.Error)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &epics); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
} else {
|
||||
ctx := rootCtx
|
||||
epics, err = store.GetEpicsEligibleForClosure(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting epic status: %v", err)
|
||||
}
|
||||
if eligibleOnly {
|
||||
filtered := []*types.EpicStatus{}
|
||||
for _, epic := range epics {
|
||||
if epic.EligibleForClose {
|
||||
filtered = append(filtered, epic)
|
||||
}
|
||||
ctx := rootCtx
|
||||
epics, err = store.GetEpicsEligibleForClosure(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting epic status: %v", err)
|
||||
}
|
||||
if eligibleOnly {
|
||||
filtered := []*types.EpicStatus{}
|
||||
for _, epic := range epics {
|
||||
if epic.EligibleForClose {
|
||||
filtered = append(filtered, epic)
|
||||
}
|
||||
epics = filtered
|
||||
}
|
||||
epics = filtered
|
||||
}
|
||||
if jsonOutput {
|
||||
if epics == nil {
|
||||
|
|
@ -99,29 +82,14 @@ var closeEligibleEpicsCmd = &cobra.Command{
|
|||
}
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
var eligibleEpics []*types.EpicStatus
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.EpicStatus(&rpc.EpicStatusArgs{
|
||||
EligibleOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("communicating with daemon: %v", err)
|
||||
}
|
||||
if !resp.Success {
|
||||
FatalErrorRespectJSON("getting eligible epics: %s", resp.Error)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &eligibleEpics); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
} else {
|
||||
ctx := rootCtx
|
||||
epics, err := store.GetEpicsEligibleForClosure(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting eligible epics: %v", err)
|
||||
}
|
||||
for _, epic := range epics {
|
||||
if epic.EligibleForClose {
|
||||
eligibleEpics = append(eligibleEpics, epic)
|
||||
}
|
||||
ctx := rootCtx
|
||||
epics, err := store.GetEpicsEligibleForClosure(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting eligible epics: %v", err)
|
||||
}
|
||||
for _, epic := range epics {
|
||||
if epic.EligibleForClose {
|
||||
eligibleEpics = append(eligibleEpics, epic)
|
||||
}
|
||||
}
|
||||
if len(eligibleEpics) == 0 {
|
||||
|
|
@ -146,28 +114,10 @@ var closeEligibleEpicsCmd = &cobra.Command{
|
|||
// Actually close the epics
|
||||
closedIDs := []string{}
|
||||
for _, epicStatus := range eligibleEpics {
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.CloseIssue(&rpc.CloseArgs{
|
||||
ID: epicStatus.Epic.ID,
|
||||
Reason: "All children completed",
|
||||
})
|
||||
if err != nil || !resp.Success {
|
||||
errMsg := ""
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
} else if !resp.Success {
|
||||
errMsg = resp.Error
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error closing %s: %s\n", epicStatus.Epic.ID, errMsg)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
ctx := rootCtx
|
||||
err := store.CloseIssue(ctx, epicStatus.Epic.ID, "All children completed", "system", "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", epicStatus.Epic.ID, err)
|
||||
continue
|
||||
}
|
||||
err := store.CloseIssue(ctx, epicStatus.Epic.ID, "All children completed", "system", "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", epicStatus.Epic.ID, err)
|
||||
continue
|
||||
}
|
||||
closedIDs = append(closedIDs, epicStatus.Epic.ID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,12 +168,6 @@ Examples:
|
|||
}
|
||||
|
||||
// Export command requires direct database access for consistent snapshot
|
||||
// If daemon is connected, close it and open direct connection
|
||||
if daemonClient != nil {
|
||||
debug.Logf("Debug: export command forcing direct mode (closes daemon connection)\n")
|
||||
_ = daemonClient.Close()
|
||||
daemonClient = nil
|
||||
}
|
||||
|
||||
// Note: We used to check database file timestamps here, but WAL files
|
||||
// get created when opening the DB, making timestamp checks unreliable.
|
||||
|
|
|
|||
|
|
@ -107,12 +107,6 @@ func runFindDuplicates(cmd *cobra.Command, _ []string) {
|
|||
var issues []*types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: find-duplicates not yet supported in daemon mode\n")
|
||||
fmt.Fprintf(os.Stderr, "Use: bd --no-daemon find-duplicates\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error fetching issues: %v\n", err)
|
||||
|
|
|
|||
201
cmd/bd/gate.go
201
cmd/bd/gate.go
|
|
@ -17,7 +17,6 @@ import (
|
|||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/routing"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -74,37 +73,6 @@ By default, shows only open gates. Use --all to include closed gates.`,
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
listArgs := &rpc.ListArgs{
|
||||
IssueType: "gate",
|
||||
Limit: limit,
|
||||
}
|
||||
if !allFlag {
|
||||
listArgs.ExcludeStatus = []string{"closed"}
|
||||
}
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var issues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(issues)
|
||||
return
|
||||
}
|
||||
|
||||
displayGates(issues, allFlag)
|
||||
return
|
||||
}
|
||||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// Direct mode
|
||||
|
|
@ -221,28 +189,10 @@ This is used by 'gt done --phase-complete' to register for gate wake notificatio
|
|||
var issue *types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
resp, rerr := daemonClient.Show(&rpc.ShowArgs{ID: gateID})
|
||||
if rerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", rerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(resp.Data, &details); uerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", uerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue = &details.Issue
|
||||
} else {
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if issue.IssueType != "gate" {
|
||||
|
|
@ -262,29 +212,12 @@ This is used by 'gt done --phase-complete' to register for gate wake notificatio
|
|||
newWaiters := append(issue.Waiters, waiter)
|
||||
|
||||
// Update the gate
|
||||
if daemonClient != nil {
|
||||
// Use GateWait RPC which handles waiters correctly (bypasses allowedUpdateFields)
|
||||
gateWaitArgs := &rpc.GateWaitArgs{
|
||||
ID: gateID,
|
||||
Waiters: []string{waiter}, // GateWait handles deduplication internally
|
||||
}
|
||||
resp, uerr := daemonClient.GateWait(gateWaitArgs)
|
||||
if uerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", uerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"waiters": newWaiters,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, gateID, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error updating gate: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"waiters": newWaiters,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, gateID, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error updating gate: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%s Added waiter to gate %s: %s\n", ui.RenderPass("✓"), gateID, waiter)
|
||||
|
|
@ -307,28 +240,10 @@ This is similar to 'bd show' but validates that the issue is a gate.`,
|
|||
var issue *types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
resp, rerr := daemonClient.Show(&rpc.ShowArgs{ID: gateID})
|
||||
if rerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", rerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(resp.Data, &details); uerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", uerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue = &details.Issue
|
||||
} else {
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if issue.IssueType != "gate" {
|
||||
|
|
@ -388,28 +303,10 @@ Use --reason to provide context for why the gate was resolved.`,
|
|||
var issue *types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
resp, rerr := daemonClient.Show(&rpc.ShowArgs{ID: gateID})
|
||||
if rerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", rerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(resp.Data, &details); uerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", uerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue = &details.Issue
|
||||
} else {
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue, err = store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: gate not found: %s\n", gateID)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if issue.IssueType != "gate" {
|
||||
|
|
@ -418,25 +315,9 @@ Use --reason to provide context for why the gate was resolved.`,
|
|||
}
|
||||
|
||||
// Close the gate
|
||||
if daemonClient != nil {
|
||||
closeArgs := &rpc.CloseArgs{
|
||||
ID: gateID,
|
||||
Reason: reason,
|
||||
}
|
||||
resp, cerr := daemonClient.CloseIssue(closeArgs)
|
||||
if cerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", cerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !resp.Success {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", resp.Error)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
if err := store.CloseIssue(ctx, gateID, reason, actor, ""); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing gate: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := store.CloseIssue(ctx, gateID, reason, actor, ""); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing gate: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%s Gate resolved: %s\n", ui.RenderPass("✓"), gateID)
|
||||
|
|
@ -504,27 +385,10 @@ Examples:
|
|||
var gates []*types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
listArgs := &rpc.ListArgs{
|
||||
IssueType: "gate",
|
||||
ExcludeStatus: []string{"closed"},
|
||||
Limit: limit,
|
||||
}
|
||||
resp, rerr := daemonClient.List(listArgs)
|
||||
if rerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", rerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
if uerr := json.Unmarshal(resp.Data, &gates); uerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", uerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
gates, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
gates, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Filter by type if specified
|
||||
|
|
@ -927,21 +791,6 @@ func checkBeadGate(ctx context.Context, awaitID string) (bool, string) {
|
|||
|
||||
// closeGate closes a gate issue with the given reason
|
||||
func closeGate(_ interface{}, gateID, reason string) error {
|
||||
if daemonClient != nil {
|
||||
closeArgs := &rpc.CloseArgs{
|
||||
ID: gateID,
|
||||
Reason: reason,
|
||||
}
|
||||
resp, err := daemonClient.CloseIssue(closeArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !resp.Success {
|
||||
return fmt.Errorf("%s", resp.Error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := store.CloseIssue(rootCtx, gateID, reason, actor, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,13 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -75,18 +71,6 @@ Status icons: ○ open ◐ in_progress ● blocked ✓ closed ❄ deferred`,
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// If daemon is running but doesn't support this command, use direct storage
|
||||
// Use factory to respect backend configuration (bd-m2jr: SQLite fallback fix)
|
||||
if daemonClient != nil && store == nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to open database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
|
||||
if store == nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
|
|
@ -128,25 +112,10 @@ Status icons: ○ open ◐ in_progress ● blocked ✓ closed ❄ deferred`,
|
|||
}
|
||||
|
||||
// Single issue mode
|
||||
var issueID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: issue '%s' not found\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &issueID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
issueID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: issue '%s' not found\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
issueID, err := utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: issue '%s' not found\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load the subgraph
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -115,38 +114,13 @@ Examples:
|
|||
filter.Status = &s
|
||||
}
|
||||
|
||||
var issues []*types.Issue
|
||||
|
||||
// Try daemon first
|
||||
if daemonClient != nil {
|
||||
listArgs := &rpc.ListArgs{
|
||||
Labels: []string{"human"},
|
||||
Status: status,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err == nil && !isUnknownOperationError(err) {
|
||||
if jsonOutput {
|
||||
fmt.Printf("%s\n", string(resp.Data))
|
||||
} else {
|
||||
// Parse and format output
|
||||
if err := json.Unmarshal(resp.Data, &issues); err == nil {
|
||||
printHumanList(issues)
|
||||
} else {
|
||||
fmt.Printf("%s\n", string(resp.Data))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("listing human beads: %v", err)
|
||||
}
|
||||
|
||||
var err error
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("listing human beads: %v", err)
|
||||
}
|
||||
|
|
@ -358,30 +332,13 @@ Example:
|
|||
Labels: []string{"human"},
|
||||
}
|
||||
|
||||
var issues []*types.Issue
|
||||
|
||||
// Try daemon first
|
||||
if daemonClient != nil {
|
||||
listArgs := &rpc.ListArgs{
|
||||
Labels: []string{"human"},
|
||||
}
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err == nil && !isUnknownOperationError(err) {
|
||||
if err := json.Unmarshal(resp.Data, &issues); err == nil {
|
||||
printHumanStats(issues)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
FatalErrorRespectJSON("getting human bead stats: %v", err)
|
||||
}
|
||||
|
||||
var err error
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting human bead stats: %v", err)
|
||||
}
|
||||
|
|
|
|||
106
cmd/bd/info.go
106
cmd/bd/info.go
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -61,62 +60,29 @@ Examples:
|
|||
"mode": daemonStatus.Mode,
|
||||
}
|
||||
|
||||
// Add daemon details if connected
|
||||
if daemonClient != nil {
|
||||
info["daemon_connected"] = true
|
||||
info["socket_path"] = daemonStatus.SocketPath
|
||||
// Direct mode
|
||||
info["daemon_connected"] = false
|
||||
if daemonStatus.FallbackReason != "" && daemonStatus.FallbackReason != FallbackNone {
|
||||
info["daemon_fallback_reason"] = daemonStatus.FallbackReason
|
||||
}
|
||||
if daemonStatus.Detail != "" {
|
||||
info["daemon_detail"] = daemonStatus.Detail
|
||||
}
|
||||
|
||||
// Get daemon health
|
||||
health, err := daemonClient.Health()
|
||||
// Get issue count from direct store
|
||||
if store != nil {
|
||||
ctx := rootCtx
|
||||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
filter := types.IssueFilter{}
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
if err == nil {
|
||||
info["daemon_version"] = health.Version
|
||||
info["daemon_status"] = health.Status
|
||||
info["daemon_compatible"] = health.Compatible
|
||||
info["daemon_uptime"] = health.Uptime
|
||||
}
|
||||
|
||||
// Get issue count from daemon
|
||||
resp, err := daemonClient.Stats()
|
||||
if err == nil {
|
||||
var stats types.Statistics
|
||||
if jsonErr := json.Unmarshal(resp.Data, &stats); jsonErr == nil {
|
||||
info["issue_count"] = stats.TotalIssues
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
info["daemon_connected"] = false
|
||||
if daemonStatus.FallbackReason != "" && daemonStatus.FallbackReason != FallbackNone {
|
||||
info["daemon_fallback_reason"] = daemonStatus.FallbackReason
|
||||
}
|
||||
if daemonStatus.Detail != "" {
|
||||
info["daemon_detail"] = daemonStatus.Detail
|
||||
}
|
||||
|
||||
// Get issue count from direct store
|
||||
if store != nil {
|
||||
ctx := rootCtx
|
||||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
filter := types.IssueFilter{}
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
if err == nil {
|
||||
info["issue_count"] = len(issues)
|
||||
}
|
||||
info["issue_count"] = len(issues)
|
||||
}
|
||||
}
|
||||
|
||||
// Add config to info output (requires direct mode to access config table)
|
||||
// Save current daemon state
|
||||
wasDaemon := daemonClient != nil
|
||||
var tempErr error
|
||||
|
||||
if wasDaemon {
|
||||
// Temporarily switch to direct mode to read config
|
||||
tempErr = ensureDirectMode("info: reading config")
|
||||
}
|
||||
|
||||
// Add config to info output
|
||||
if store != nil {
|
||||
ctx := rootCtx
|
||||
configMap, err := store.GetAllConfig(ctx)
|
||||
|
|
@ -125,10 +91,6 @@ Examples:
|
|||
}
|
||||
}
|
||||
|
||||
// Note: We don't restore daemon mode since info is a read-only command
|
||||
// and the process will exit immediately after this
|
||||
_ = tempErr // silence unused warning
|
||||
|
||||
// Add schema information if requested
|
||||
if schemaFlag && store != nil {
|
||||
ctx := rootCtx
|
||||
|
|
@ -190,31 +152,13 @@ Examples:
|
|||
fmt.Printf("Database: %s\n", absDBPath)
|
||||
fmt.Printf("Mode: %s\n", daemonStatus.Mode)
|
||||
|
||||
if daemonClient != nil {
|
||||
fmt.Println("\nDaemon Status:")
|
||||
fmt.Printf(" Connected: yes\n")
|
||||
fmt.Printf(" Socket: %s\n", daemonStatus.SocketPath)
|
||||
|
||||
health, err := daemonClient.Health()
|
||||
if err == nil {
|
||||
fmt.Printf(" Version: %s\n", health.Version)
|
||||
fmt.Printf(" Health: %s\n", health.Status)
|
||||
if health.Compatible {
|
||||
fmt.Printf(" Compatible: ✓ yes\n")
|
||||
} else {
|
||||
fmt.Printf(" Compatible: ✗ no (restart recommended)\n")
|
||||
}
|
||||
fmt.Printf(" Uptime: %.1fs\n", health.Uptime)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("\nDaemon Status:")
|
||||
fmt.Printf(" Connected: no\n")
|
||||
if daemonStatus.FallbackReason != "" && daemonStatus.FallbackReason != FallbackNone {
|
||||
fmt.Printf(" Reason: %s\n", daemonStatus.FallbackReason)
|
||||
}
|
||||
if daemonStatus.Detail != "" {
|
||||
fmt.Printf(" Detail: %s\n", daemonStatus.Detail)
|
||||
}
|
||||
fmt.Println("\nDaemon Status:")
|
||||
fmt.Printf(" Connected: no\n")
|
||||
if daemonStatus.FallbackReason != "" && daemonStatus.FallbackReason != FallbackNone {
|
||||
fmt.Printf(" Reason: %s\n", daemonStatus.FallbackReason)
|
||||
}
|
||||
if daemonStatus.Detail != "" {
|
||||
fmt.Printf(" Detail: %s\n", daemonStatus.Detail)
|
||||
}
|
||||
|
||||
// Show issue count
|
||||
|
|
|
|||
141
cmd/bd/label.go
141
cmd/bd/label.go
|
|
@ -3,10 +3,8 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -28,11 +26,7 @@ func processBatchLabelOperation(issueIDs []string, label string, operation strin
|
|||
results := []map[string]interface{}{}
|
||||
for _, issueID := range issueIDs {
|
||||
var err error
|
||||
if daemonClient != nil {
|
||||
err = daemonFunc(issueID, label)
|
||||
} else {
|
||||
err = storeFunc(ctx, issueID, label, actor)
|
||||
}
|
||||
err = storeFunc(ctx, issueID, label, actor)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error %s label %s %s: %v\n", operation, operation, issueID, err)
|
||||
continue
|
||||
|
|
@ -78,23 +72,10 @@ var labelAddCmd = &cobra.Command{
|
|||
for _, id := range issueIDs {
|
||||
var fullID string
|
||||
var err error
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, fullID)
|
||||
}
|
||||
|
|
@ -107,10 +88,7 @@ var labelAddCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
processBatchLabelOperation(issueIDs, label, "added", jsonOutput,
|
||||
func(issueID, lbl string) error {
|
||||
_, err := daemonClient.AddLabel(&rpc.LabelAddArgs{ID: issueID, Label: lbl})
|
||||
return err
|
||||
},
|
||||
nil,
|
||||
func(ctx context.Context, issueID, lbl, act string) error {
|
||||
return store.AddLabel(ctx, issueID, lbl, act)
|
||||
})
|
||||
|
|
@ -132,32 +110,16 @@ var labelRemoveCmd = &cobra.Command{
|
|||
for _, id := range issueIDs {
|
||||
var fullID string
|
||||
var err error
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, fullID)
|
||||
}
|
||||
issueIDs = resolvedIDs
|
||||
processBatchLabelOperation(issueIDs, label, "removed", jsonOutput,
|
||||
func(issueID, lbl string) error {
|
||||
_, err := daemonClient.RemoveLabel(&rpc.LabelRemoveArgs{ID: issueID, Label: lbl})
|
||||
return err
|
||||
},
|
||||
nil,
|
||||
func(ctx context.Context, issueID, lbl, act string) error {
|
||||
return store.RemoveLabel(ctx, issueID, lbl, act)
|
||||
})
|
||||
|
|
@ -172,41 +134,16 @@ var labelListCmd = &cobra.Command{
|
|||
ctx := rootCtx
|
||||
// Resolve partial ID first
|
||||
var issueID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &issueID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
issueID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
var err error
|
||||
issueID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", args[0], err)
|
||||
}
|
||||
var labels []string
|
||||
// Use daemon if available
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: issueID})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
labels = issue.Labels
|
||||
} else {
|
||||
// Direct mode
|
||||
var err error
|
||||
labels, err = store.GetLabels(ctx, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
// Direct mode
|
||||
labels, err = store.GetLabels(ctx, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
if jsonOutput {
|
||||
// Always output array, even if empty
|
||||
|
|
@ -235,39 +172,21 @@ var labelListAllCmd = &cobra.Command{
|
|||
ctx := rootCtx
|
||||
var issues []*types.Issue
|
||||
var err error
|
||||
// Use daemon if available
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.List(&rpc.ListArgs{})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
issues, err = store.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
// Direct mode
|
||||
issues, err = store.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
// Collect unique labels with counts
|
||||
labelCounts := make(map[string]int)
|
||||
for _, issue := range issues {
|
||||
if daemonClient != nil {
|
||||
// Labels are already in the issue from daemon
|
||||
for _, label := range issue.Labels {
|
||||
labelCounts[label]++
|
||||
}
|
||||
} else {
|
||||
// Direct mode - need to fetch labels
|
||||
labels, err := store.GetLabels(ctx, issue.ID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting labels for %s: %v", issue.ID, err)
|
||||
}
|
||||
for _, label := range labels {
|
||||
labelCounts[label]++
|
||||
}
|
||||
// Direct mode - need to fetch labels
|
||||
labels, err := store.GetLabels(ctx, issue.ID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting labels for %s: %v", issue.ID, err)
|
||||
}
|
||||
for _, label := range labels {
|
||||
labelCounts[label]++
|
||||
}
|
||||
}
|
||||
type labelInfo struct {
|
||||
|
|
|
|||
122
cmd/bd/lint.go
122
cmd/bd/lint.go
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/validation"
|
||||
)
|
||||
|
|
@ -50,104 +49,51 @@ Examples:
|
|||
|
||||
var issues []*types.Issue
|
||||
|
||||
// Use daemon if available, otherwise direct mode
|
||||
if daemonClient != nil {
|
||||
if len(args) > 0 {
|
||||
// Get specific issues via show
|
||||
for _, id := range args {
|
||||
showArgs := &rpc.ShowArgs{ID: id}
|
||||
resp, err := daemonClient.Show(showArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if err := json.Unmarshal(resp.Data, &details); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
issues = append(issues, &details.Issue)
|
||||
}
|
||||
} else {
|
||||
// List issues via daemon
|
||||
listArgs := &rpc.ListArgs{
|
||||
Limit: 1000, // reasonable limit
|
||||
}
|
||||
// Direct mode
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// Default to open issues unless --status specified
|
||||
if statusFilter == "" || statusFilter == "open" {
|
||||
listArgs.Status = "open"
|
||||
} else if statusFilter != "all" {
|
||||
listArgs.Status = statusFilter
|
||||
}
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if typeFilter != "" {
|
||||
listArgs.IssueType = typeFilter
|
||||
}
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if len(args) > 0 {
|
||||
// Lint specific issues
|
||||
for _, id := range args {
|
||||
issue, err := store.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var issuesWithCounts []*types.IssueWithCounts
|
||||
if err := json.Unmarshal(resp.Data, &issuesWithCounts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, iwc := range issuesWithCounts {
|
||||
issues = append(issues, iwc.Issue)
|
||||
if issue == nil {
|
||||
fmt.Fprintf(os.Stderr, "Issue not found: %s\n", id)
|
||||
continue
|
||||
}
|
||||
issues = append(issues, issue)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
requireFreshDB(ctx)
|
||||
// Lint all matching issues
|
||||
filter := types.IssueFilter{}
|
||||
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
// Default to open issues unless --status specified
|
||||
if statusFilter == "" || statusFilter == "open" {
|
||||
s := types.StatusOpen
|
||||
filter.Status = &s
|
||||
} else if statusFilter != "all" {
|
||||
s := types.Status(statusFilter)
|
||||
filter.Status = &s
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
// Lint specific issues
|
||||
for _, id := range args {
|
||||
issue, err := store.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if issue == nil {
|
||||
fmt.Fprintf(os.Stderr, "Issue not found: %s\n", id)
|
||||
continue
|
||||
}
|
||||
issues = append(issues, issue)
|
||||
}
|
||||
} else {
|
||||
// Lint all matching issues
|
||||
filter := types.IssueFilter{}
|
||||
if typeFilter != "" {
|
||||
t := types.IssueType(typeFilter)
|
||||
filter.IssueType = &t
|
||||
}
|
||||
|
||||
// Default to open issues unless --status specified
|
||||
if statusFilter == "" || statusFilter == "open" {
|
||||
s := types.StatusOpen
|
||||
filter.Status = &s
|
||||
} else if statusFilter != "all" {
|
||||
s := types.Status(statusFilter)
|
||||
filter.Status = &s
|
||||
}
|
||||
|
||||
if typeFilter != "" {
|
||||
t := types.IssueType(typeFilter)
|
||||
filter.IssueType = &t
|
||||
}
|
||||
|
||||
var err error
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var err error
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
260
cmd/bd/list.go
260
cmd/bd/list.go
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -16,7 +15,6 @@ import (
|
|||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
|
|
@ -610,264 +608,6 @@ var listCmd = &cobra.Command{
|
|||
ctx := rootCtx
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
// Determine effective status for RPC (--ready overrides to "open")
|
||||
effectiveStatus := status
|
||||
if readyFlag {
|
||||
effectiveStatus = "open"
|
||||
}
|
||||
listArgs := &rpc.ListArgs{
|
||||
Status: effectiveStatus,
|
||||
IssueType: issueType,
|
||||
Assignee: assignee,
|
||||
Limit: effectiveLimit,
|
||||
SpecIDPrefix: specPrefix,
|
||||
}
|
||||
if cmd.Flags().Changed("priority") {
|
||||
priorityStr, _ := cmd.Flags().GetString("priority")
|
||||
priority, err := validation.ValidatePriority(priorityStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
listArgs.Priority = &priority
|
||||
}
|
||||
if len(labels) > 0 {
|
||||
listArgs.Labels = labels
|
||||
}
|
||||
if len(labelsAny) > 0 {
|
||||
listArgs.LabelsAny = labelsAny
|
||||
}
|
||||
if labelPattern != "" {
|
||||
listArgs.LabelPattern = labelPattern
|
||||
}
|
||||
if labelRegex != "" {
|
||||
listArgs.LabelRegex = labelRegex
|
||||
}
|
||||
// Forward title search via Query field (searches title/description/id)
|
||||
if titleSearch != "" {
|
||||
listArgs.Query = titleSearch
|
||||
}
|
||||
if len(filter.IDs) > 0 {
|
||||
listArgs.IDs = filter.IDs
|
||||
}
|
||||
|
||||
// Pattern matching
|
||||
listArgs.TitleContains = titleContains
|
||||
listArgs.DescriptionContains = descContains
|
||||
listArgs.NotesContains = notesContains
|
||||
|
||||
// Date ranges
|
||||
if filter.CreatedAfter != nil {
|
||||
listArgs.CreatedAfter = filter.CreatedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.CreatedBefore != nil {
|
||||
listArgs.CreatedBefore = filter.CreatedBefore.Format(time.RFC3339)
|
||||
}
|
||||
if filter.UpdatedAfter != nil {
|
||||
listArgs.UpdatedAfter = filter.UpdatedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.UpdatedBefore != nil {
|
||||
listArgs.UpdatedBefore = filter.UpdatedBefore.Format(time.RFC3339)
|
||||
}
|
||||
if filter.ClosedAfter != nil {
|
||||
listArgs.ClosedAfter = filter.ClosedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.ClosedBefore != nil {
|
||||
listArgs.ClosedBefore = filter.ClosedBefore.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
// Empty/null checks
|
||||
listArgs.EmptyDescription = filter.EmptyDescription
|
||||
listArgs.NoAssignee = filter.NoAssignee
|
||||
listArgs.NoLabels = filter.NoLabels
|
||||
|
||||
// Priority range
|
||||
listArgs.PriorityMin = filter.PriorityMin
|
||||
listArgs.PriorityMax = filter.PriorityMax
|
||||
|
||||
// Pinned filtering
|
||||
listArgs.Pinned = filter.Pinned
|
||||
|
||||
// Template filtering
|
||||
listArgs.IncludeTemplates = includeTemplates
|
||||
|
||||
// Parent filtering
|
||||
listArgs.ParentID = parentID
|
||||
|
||||
// Status exclusion (GH#788)
|
||||
if len(filter.ExcludeStatus) > 0 {
|
||||
for _, s := range filter.ExcludeStatus {
|
||||
listArgs.ExcludeStatus = append(listArgs.ExcludeStatus, string(s))
|
||||
}
|
||||
}
|
||||
|
||||
// Type exclusion (bd-7zka.2)
|
||||
if len(filter.ExcludeTypes) > 0 {
|
||||
for _, t := range filter.ExcludeTypes {
|
||||
listArgs.ExcludeTypes = append(listArgs.ExcludeTypes, string(t))
|
||||
}
|
||||
}
|
||||
|
||||
// Time-based scheduling filters (GH#820)
|
||||
listArgs.Deferred = filter.Deferred
|
||||
if filter.DeferAfter != nil {
|
||||
listArgs.DeferAfter = filter.DeferAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.DeferBefore != nil {
|
||||
listArgs.DeferBefore = filter.DeferBefore.Format(time.RFC3339)
|
||||
}
|
||||
if filter.DueAfter != nil {
|
||||
listArgs.DueAfter = filter.DueAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.DueBefore != nil {
|
||||
listArgs.DueBefore = filter.DueBefore.Format(time.RFC3339)
|
||||
}
|
||||
listArgs.Overdue = filter.Overdue
|
||||
|
||||
// Pass through --allow-stale flag for resilient queries (bd-dpkdm)
|
||||
listArgs.AllowStale = allowStale
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
// For JSON output, preserve the full response with counts
|
||||
var issuesWithCounts []*types.IssueWithCounts
|
||||
if err := json.Unmarshal(resp.Data, &issuesWithCounts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
outputJSON(issuesWithCounts)
|
||||
return
|
||||
}
|
||||
|
||||
// Show upgrade notification if needed
|
||||
maybeShowUpgradeNotification()
|
||||
|
||||
var issues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
sortIssues(issues, sortBy, reverse)
|
||||
|
||||
// Handle watch mode (GH#654)
|
||||
// Watch mode requires direct store access for file watching
|
||||
if watchMode {
|
||||
if err := ensureDirectMode("watch mode requires direct database access"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
watchIssues(ctx, store, filter, sortBy, reverse)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle pretty/tree format (GH#654)
|
||||
if prettyFormat {
|
||||
// Special handling for --tree --parent combination (hierarchical descendants)
|
||||
if parentID != "" {
|
||||
treeIssues, err := getHierarchicalChildren(ctx, store, dbPath, lockTimeout, parentID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(treeIssues) == 0 {
|
||||
fmt.Printf("Issue '%s' has no children\n", parentID)
|
||||
return
|
||||
}
|
||||
|
||||
// Load all dependencies for tree building
|
||||
var allDeps map[string][]*types.Dependency
|
||||
err = withStorage(ctx, store, dbPath, lockTimeout, func(s storage.Storage) error {
|
||||
allDeps, err = s.GetAllDependencyRecords(ctx)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting dependencies for display: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
displayPrettyListWithDeps(treeIssues, false, allDeps)
|
||||
return
|
||||
}
|
||||
|
||||
// Regular tree display (no parent filter)
|
||||
// Load dependencies for tree structure
|
||||
// In daemon mode, open a read-only store to get dependencies
|
||||
var allDeps map[string][]*types.Dependency
|
||||
if store != nil {
|
||||
allDeps, _ = store.GetAllDependencyRecords(ctx)
|
||||
} else if dbPath != "" {
|
||||
// Daemon mode: open read-only connection for tree deps
|
||||
if roStore, err := sqlite.NewReadOnlyWithTimeout(ctx, dbPath, lockTimeout); err == nil {
|
||||
allDeps, _ = roStore.GetAllDependencyRecords(ctx)
|
||||
_ = roStore.Close()
|
||||
}
|
||||
}
|
||||
displayPrettyListWithDeps(issues, false, allDeps)
|
||||
if effectiveLimit > 0 && len(issues) == effectiveLimit {
|
||||
fmt.Fprintf(os.Stderr, "\nShowing %d issues (use --limit 0 for all)\n", effectiveLimit)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Load dependencies for blocking info display
|
||||
// In daemon mode, open a read-only store to get dependencies
|
||||
var allDepsForList map[string][]*types.Dependency
|
||||
if store != nil {
|
||||
allDepsForList, _ = store.GetAllDependencyRecords(ctx)
|
||||
} else if dbPath != "" {
|
||||
if roStore, err := sqlite.NewReadOnlyWithTimeout(ctx, dbPath, lockTimeout); err == nil {
|
||||
allDepsForList, _ = roStore.GetAllDependencyRecords(ctx)
|
||||
_ = roStore.Close()
|
||||
}
|
||||
}
|
||||
blockedByMap, blocksMap, _ := buildBlockingMaps(allDepsForList)
|
||||
|
||||
// Build output in buffer for pager support (bd-jdz3)
|
||||
var buf strings.Builder
|
||||
if ui.IsAgentMode() {
|
||||
// Agent mode: ultra-compact, no colors, no pager
|
||||
for _, issue := range issues {
|
||||
formatAgentIssue(&buf, issue, blockedByMap[issue.ID], blocksMap[issue.ID])
|
||||
}
|
||||
fmt.Print(buf.String())
|
||||
return
|
||||
} else if longFormat {
|
||||
// Long format: multi-line with details
|
||||
buf.WriteString(fmt.Sprintf("\nFound %d issues:\n\n", len(issues)))
|
||||
for _, issue := range issues {
|
||||
formatIssueLong(&buf, issue, issue.Labels)
|
||||
}
|
||||
} else {
|
||||
// Compact format: one line per issue
|
||||
for _, issue := range issues {
|
||||
formatIssueCompact(&buf, issue, issue.Labels, blockedByMap[issue.ID], blocksMap[issue.ID])
|
||||
}
|
||||
}
|
||||
|
||||
// Output with pager support
|
||||
if err := ui.ToPager(buf.String(), ui.PagerOptions{NoPager: noPager}); err != nil {
|
||||
if _, writeErr := fmt.Fprint(os.Stdout, buf.String()); writeErr != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error writing output: %v\n", writeErr)
|
||||
}
|
||||
}
|
||||
|
||||
// Show truncation hint if we hit the limit (GH#788)
|
||||
if effectiveLimit > 0 && len(issues) == effectiveLimit {
|
||||
fmt.Fprintf(os.Stderr, "\nShowing %d issues (use --limit 0 for all)\n", effectiveLimit)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
// ctx already created above for staleness check
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -121,11 +120,6 @@ func getMergeSlotID() string {
|
|||
// First try config.yaml (issue-prefix)
|
||||
if configPrefix := config.GetString("issue-prefix"); configPrefix != "" {
|
||||
prefix = strings.TrimSuffix(configPrefix, "-")
|
||||
} else if daemonClient != nil {
|
||||
// Daemon mode - use RPC to get config
|
||||
if configResp, err := daemonClient.GetConfig(&rpc.GetConfigArgs{Key: "issue_prefix"}); err == nil && configResp.Value != "" {
|
||||
prefix = strings.TrimSuffix(configResp.Value, "-")
|
||||
}
|
||||
} else if store != nil {
|
||||
// Direct mode - check database config
|
||||
if dbPrefix, err := store.GetConfig(rootCtx, "issue_prefix"); err == nil && dbPrefix != "" {
|
||||
|
|
@ -142,60 +136,31 @@ func runMergeSlotCreate(cmd *cobra.Command, args []string) error {
|
|||
ctx := rootCtx
|
||||
|
||||
// Check if slot already exists
|
||||
var existing *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: slotID})
|
||||
if err == nil && resp.Success {
|
||||
if uerr := json.Unmarshal(resp.Data, &existing); uerr == nil {
|
||||
fmt.Printf("Merge slot already exists: %s\n", slotID)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
existing, _ = store.GetIssue(ctx, slotID)
|
||||
if existing != nil {
|
||||
fmt.Printf("Merge slot already exists: %s\n", slotID)
|
||||
return nil
|
||||
}
|
||||
existing, _ := store.GetIssue(ctx, slotID)
|
||||
if existing != nil {
|
||||
fmt.Printf("Merge slot already exists: %s\n", slotID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create the merge slot bead
|
||||
title := "Merge Slot"
|
||||
description := "Exclusive access slot for serialized conflict resolution in the merge queue."
|
||||
|
||||
if daemonClient != nil {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
ID: slotID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
IssueType: string(types.TypeTask), // Use task type; gt:slot label marks it as slot
|
||||
Priority: 0, // P0 - system infrastructure
|
||||
Labels: []string{"gt:slot"}, // Gas Town slot label
|
||||
}
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create merge slot: %w", err)
|
||||
}
|
||||
if !resp.Success {
|
||||
return fmt.Errorf("failed to create merge slot: %s", resp.Error)
|
||||
}
|
||||
} else {
|
||||
issue := &types.Issue{
|
||||
ID: slotID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
IssueType: types.TypeTask, // Use task type; gt:slot label marks it as slot
|
||||
Status: types.StatusOpen,
|
||||
Priority: 0,
|
||||
}
|
||||
if err := store.CreateIssue(ctx, issue, actor); err != nil {
|
||||
return fmt.Errorf("failed to create merge slot: %w", err)
|
||||
}
|
||||
// Add gt:slot label to mark as slot bead
|
||||
if err := store.AddLabel(ctx, slotID, "gt:slot", actor); err != nil {
|
||||
// Non-fatal: log warning but don't fail creation
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add gt:slot label: %v\n", err)
|
||||
}
|
||||
issue := &types.Issue{
|
||||
ID: slotID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
IssueType: types.TypeTask, // Use task type; gt:slot label marks it as slot
|
||||
Status: types.StatusOpen,
|
||||
Priority: 0,
|
||||
}
|
||||
if err := store.CreateIssue(ctx, issue, actor); err != nil {
|
||||
return fmt.Errorf("failed to create merge slot: %w", err)
|
||||
}
|
||||
// Add gt:slot label to mark as slot bead
|
||||
if err := store.AddLabel(ctx, slotID, "gt:slot", actor); err != nil {
|
||||
// Non-fatal: log warning but don't fail creation
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to add gt:slot label: %v\n", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
@ -217,47 +182,22 @@ func runMergeSlotCheck(cmd *cobra.Command, args []string) error {
|
|||
ctx := rootCtx
|
||||
|
||||
// Get the slot bead
|
||||
var slot *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: slotID})
|
||||
if err != nil {
|
||||
if jsonOutput {
|
||||
result := map[string]interface{}{
|
||||
"id": slotID,
|
||||
"available": false,
|
||||
"error": "not found",
|
||||
}
|
||||
encoder := json.NewEncoder(os.Stdout)
|
||||
encoder.SetIndent("", " ")
|
||||
return encoder.Encode(result)
|
||||
var err error
|
||||
slot, err := store.GetIssue(ctx, slotID)
|
||||
if err != nil || slot == nil {
|
||||
if jsonOutput {
|
||||
result := map[string]interface{}{
|
||||
"id": slotID,
|
||||
"available": false,
|
||||
"error": "not found",
|
||||
}
|
||||
fmt.Printf("Merge slot not found: %s\n", slotID)
|
||||
fmt.Printf("Run 'bd merge-slot create' to create one.\n")
|
||||
return nil
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(resp.Data, &details); uerr != nil {
|
||||
return fmt.Errorf("parsing response: %w", uerr)
|
||||
}
|
||||
slot = &details.Issue
|
||||
} else {
|
||||
var err error
|
||||
slot, err = store.GetIssue(ctx, slotID)
|
||||
if err != nil || slot == nil {
|
||||
if jsonOutput {
|
||||
result := map[string]interface{}{
|
||||
"id": slotID,
|
||||
"available": false,
|
||||
"error": "not found",
|
||||
}
|
||||
encoder := json.NewEncoder(os.Stdout)
|
||||
encoder.SetIndent("", " ")
|
||||
return encoder.Encode(result)
|
||||
}
|
||||
fmt.Printf("Merge slot not found: %s\n", slotID)
|
||||
fmt.Printf("Run 'bd merge-slot create' to create one.\n")
|
||||
return nil
|
||||
encoder := json.NewEncoder(os.Stdout)
|
||||
encoder.SetIndent("", " ")
|
||||
return encoder.Encode(result)
|
||||
}
|
||||
fmt.Printf("Merge slot not found: %s\n", slotID)
|
||||
fmt.Printf("Run 'bd merge-slot create' to create one.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
available := slot.Status == types.StatusOpen
|
||||
|
|
@ -309,37 +249,14 @@ func runMergeSlotAcquire(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Get the slot bead
|
||||
var slot *types.Issue
|
||||
if daemonClient != nil {
|
||||
// Try to resolve the slot ID first
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: slotID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("merge slot not found: %s (run 'bd merge-slot create' first)", slotID)
|
||||
}
|
||||
var resolvedID string
|
||||
if uerr := json.Unmarshal(resp.Data, &resolvedID); uerr != nil {
|
||||
return fmt.Errorf("parsing response: %w", uerr)
|
||||
}
|
||||
|
||||
showResp, showErr := daemonClient.Show(&rpc.ShowArgs{ID: resolvedID})
|
||||
if showErr != nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(showResp.Data, &details); uerr != nil {
|
||||
return fmt.Errorf("parsing response: %w", uerr)
|
||||
}
|
||||
slot = &details.Issue
|
||||
} else {
|
||||
var err error
|
||||
resolvedID, err := utils.ResolvePartialID(ctx, store, slotID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("merge slot not found: %s (run 'bd merge-slot create' first)", slotID)
|
||||
}
|
||||
slot, err = store.GetIssue(ctx, resolvedID)
|
||||
if err != nil || slot == nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
var err error
|
||||
resolvedID, err := utils.ResolvePartialID(ctx, store, slotID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("merge slot not found: %s (run 'bd merge-slot create' first)", slotID)
|
||||
}
|
||||
slot, err := store.GetIssue(ctx, resolvedID)
|
||||
if err != nil || slot == nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
|
||||
// Check slot availability
|
||||
|
|
@ -357,22 +274,11 @@ func runMergeSlotAcquire(cmd *cobra.Command, args []string) error {
|
|||
|
||||
if !alreadyWaiting {
|
||||
newWaiters := append(slot.Waiters, holder)
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: slot.ID,
|
||||
Waiters: newWaiters,
|
||||
}
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add waiter: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"waiters": newWaiters,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to add waiter: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"waiters": newWaiters,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to add waiter: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -411,25 +317,12 @@ func runMergeSlotAcquire(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Slot is available - acquire it
|
||||
inProgressStatus := string(types.StatusInProgress)
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: slot.ID,
|
||||
Status: &inProgressStatus,
|
||||
Holder: &holder,
|
||||
}
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to acquire slot: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"status": types.StatusInProgress,
|
||||
"holder": holder,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to acquire slot: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"status": types.StatusInProgress,
|
||||
"holder": holder,
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to acquire slot: %w", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
@ -455,23 +348,10 @@ func runMergeSlotRelease(cmd *cobra.Command, args []string) error {
|
|||
ctx := rootCtx
|
||||
|
||||
// Get the slot bead
|
||||
var slot *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: slotID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
var details types.IssueDetails
|
||||
if uerr := json.Unmarshal(resp.Data, &details); uerr != nil {
|
||||
return fmt.Errorf("parsing response: %w", uerr)
|
||||
}
|
||||
slot = &details.Issue
|
||||
} else {
|
||||
var err error
|
||||
slot, err = store.GetIssue(ctx, slotID)
|
||||
if err != nil || slot == nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
var err error
|
||||
slot, err := store.GetIssue(ctx, slotID)
|
||||
if err != nil || slot == nil {
|
||||
return fmt.Errorf("merge slot not found: %s", slotID)
|
||||
}
|
||||
|
||||
// Verify holder if specified
|
||||
|
|
@ -499,26 +379,12 @@ func runMergeSlotRelease(cmd *cobra.Command, args []string) error {
|
|||
waiters := slot.Waiters
|
||||
|
||||
// Release the slot
|
||||
openStatus := string(types.StatusOpen)
|
||||
emptyHolder := ""
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: slot.ID,
|
||||
Status: &openStatus,
|
||||
Holder: &emptyHolder,
|
||||
}
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to release slot: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{
|
||||
"status": types.StatusOpen,
|
||||
"holder": "",
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to release slot: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{
|
||||
"status": types.StatusOpen,
|
||||
"holder": "",
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, slot.ID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to release slot: %w", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
|
|||
|
|
@ -89,12 +89,7 @@ func runMolBond(cmd *cobra.Command, args []string) {
|
|||
|
||||
// mol bond requires direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: mol bond requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon mol bond %s %s ...\n", args[0], args[1])
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,12 +104,7 @@ func runMolDistill(cmd *cobra.Command, args []string) {
|
|||
|
||||
// mol distill requires direct store access for reading the epic
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: mol distill requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon mol distill %s ...\n", args[0])
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,7 @@ Example:
|
|||
|
||||
// mol progress requires direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: mol progress requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon mol progress\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,12 +51,7 @@ func runMolReadyGated(cmd *cobra.Command, args []string) {
|
|||
|
||||
// --gated mode requires direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: bd ready --gated requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon ready --gated\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,7 @@ Example:
|
|||
|
||||
// mol show requires direct store access for subgraph loading
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: mol show requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon mol show %s\n", args[0])
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,7 @@ func runPour(cmd *cobra.Command, args []string) {
|
|||
|
||||
// Pour requires direct store access for cloning
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: pour requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon pour %s ...\n", args[0])
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
|
@ -41,74 +38,6 @@ Examples:
|
|||
comment += ": " + reason
|
||||
}
|
||||
|
||||
// Resolve partial ID and handle routing
|
||||
if daemonClient != nil {
|
||||
// Check if this ID needs routing to a different beads directory
|
||||
if needsRouting(id) {
|
||||
promoteRouted(id, comment)
|
||||
return
|
||||
}
|
||||
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", id, err)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
id = resolvedID
|
||||
|
||||
// Verify the issue is actually a wisp
|
||||
showArgs := &rpc.ShowArgs{ID: id}
|
||||
showResp, err := daemonClient.Show(showArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("getting issue %s: %v", id, err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(showResp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("decoding issue: %v", err)
|
||||
}
|
||||
if !issue.Ephemeral {
|
||||
FatalErrorRespectJSON("%s is not a wisp (already persistent)", id)
|
||||
}
|
||||
|
||||
// Set ephemeral=false via update RPC
|
||||
ephemeral := false
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: id,
|
||||
Ephemeral: &ephemeral,
|
||||
}
|
||||
if _, err := daemonClient.Update(updateArgs); err != nil {
|
||||
FatalErrorRespectJSON("promoting %s: %v", id, err)
|
||||
}
|
||||
|
||||
// Add promotion comment
|
||||
commentArgs := &rpc.CommentAddArgs{
|
||||
ID: id,
|
||||
Author: actor,
|
||||
Text: comment,
|
||||
}
|
||||
if _, err := daemonClient.AddComment(commentArgs); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add promotion comment to %s: %v\n", id, err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
// Re-fetch to return updated issue
|
||||
showResp2, err := daemonClient.Show(showArgs)
|
||||
if err == nil {
|
||||
var updated types.Issue
|
||||
if err := json.Unmarshal(showResp2.Data, &updated); err == nil {
|
||||
outputJSON(&updated)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s Promoted %s to permanent bead\n", ui.RenderPass("✓"), id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -129,56 +128,36 @@ Examples:
|
|||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
var issues []*types.Issue
|
||||
// Direct mode
|
||||
if store == nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: no storage available\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Execute query
|
||||
if daemonClient != nil {
|
||||
// Daemon mode: use RPC with filter
|
||||
// Convert filter to ListArgs
|
||||
listArgs := filterToListArgs(&result.Filter)
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
// If we need predicate filtering, we may need to fetch more results
|
||||
// to ensure we get enough after filtering
|
||||
searchFilter := result.Filter
|
||||
if result.RequiresPredicate && limit > 0 {
|
||||
// Fetch more to account for predicate filtering
|
||||
searchFilter.Limit = limit * 3
|
||||
if searchFilter.Limit < 100 {
|
||||
searchFilter.Limit = 100
|
||||
}
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
if store == nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: no storage available\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
issues, err := store.SearchIssues(ctx, "", searchFilter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// If we need predicate filtering, we may need to fetch more results
|
||||
// to ensure we get enough after filtering
|
||||
searchFilter := result.Filter
|
||||
if result.RequiresPredicate && limit > 0 {
|
||||
// Fetch more to account for predicate filtering
|
||||
searchFilter.Limit = limit * 3
|
||||
if searchFilter.Limit < 100 {
|
||||
searchFilter.Limit = 100
|
||||
}
|
||||
}
|
||||
|
||||
issues, err = store.SearchIssues(ctx, "", searchFilter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// If no issues found, check if git has issues and auto-import
|
||||
if len(issues) == 0 {
|
||||
if checkAndAutoImport(ctx, store) {
|
||||
issues, err = store.SearchIssues(ctx, "", searchFilter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// If no issues found, check if git has issues and auto-import
|
||||
if len(issues) == 0 {
|
||||
if checkAndAutoImport(ctx, store) {
|
||||
issues, err = store.SearchIssues(ctx, "", searchFilter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/validation"
|
||||
)
|
||||
|
|
@ -39,28 +37,6 @@ Example:
|
|||
FatalError("%v", err)
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
Title: title,
|
||||
Priority: priority,
|
||||
IssueType: issueType,
|
||||
Labels: labels,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
FatalError("%v", err)
|
||||
}
|
||||
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalError("parsing response: %v", err)
|
||||
}
|
||||
fmt.Println(issue.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode
|
||||
issue := &types.Issue{
|
||||
Title: title,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -110,84 +106,6 @@ This is useful for agents executing molecules to see which steps can run next.`,
|
|||
fmt.Fprintf(os.Stderr, "Error: invalid sort policy '%s'. Valid values: hybrid, priority, oldest\n", sortPolicy)
|
||||
os.Exit(1)
|
||||
}
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
readyArgs := &rpc.ReadyArgs{
|
||||
Status: "open", // Only show open issues, not in_progress (matches bd list --ready)
|
||||
Assignee: assignee,
|
||||
Unassigned: unassigned,
|
||||
Type: issueType,
|
||||
Limit: limit,
|
||||
SortPolicy: sortPolicy,
|
||||
Labels: labels,
|
||||
LabelsAny: labelsAny,
|
||||
ParentID: parentID,
|
||||
MolType: molTypeStr,
|
||||
IncludeDeferred: includeDeferred, // GH#820
|
||||
}
|
||||
if cmd.Flags().Changed("priority") {
|
||||
priority, _ := cmd.Flags().GetInt("priority")
|
||||
readyArgs.Priority = &priority
|
||||
}
|
||||
resp, err := daemonClient.Ready(readyArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var issues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if jsonOutput {
|
||||
if issues == nil {
|
||||
issues = []*types.Issue{}
|
||||
}
|
||||
outputJSON(issues)
|
||||
return
|
||||
}
|
||||
|
||||
// Show upgrade notification if needed
|
||||
maybeShowUpgradeNotification()
|
||||
|
||||
if len(issues) == 0 {
|
||||
// Check if there are any open issues at all
|
||||
statsResp, statsErr := daemonClient.Stats()
|
||||
hasOpenIssues := false
|
||||
if statsErr == nil {
|
||||
var stats types.Statistics
|
||||
if json.Unmarshal(statsResp.Data, &stats) == nil {
|
||||
hasOpenIssues = stats.OpenIssues > 0 || stats.InProgressIssues > 0
|
||||
}
|
||||
}
|
||||
if hasOpenIssues {
|
||||
fmt.Printf("\n%s No ready work found (all issues have blocking dependencies)\n\n",
|
||||
ui.RenderWarn("✨"))
|
||||
} else {
|
||||
fmt.Printf("\n%s No open issues\n\n", ui.RenderPass("✨"))
|
||||
}
|
||||
return
|
||||
}
|
||||
if prettyFormat {
|
||||
displayPrettyList(issues, false)
|
||||
} else {
|
||||
fmt.Printf("\n%s Ready work (%d issues with no blockers):\n\n", ui.RenderAccent("📋"), len(issues))
|
||||
for i, issue := range issues {
|
||||
fmt.Printf("%d. [%s] [%s] %s: %s\n", i+1,
|
||||
ui.RenderPriority(issue.Priority),
|
||||
ui.RenderType(string(issue.IssueType)),
|
||||
ui.RenderID(issue.ID), issue.Title)
|
||||
if issue.EstimatedMinutes != nil {
|
||||
fmt.Printf(" Estimate: %d min\n", *issue.EstimatedMinutes)
|
||||
}
|
||||
if issue.Assignee != "" {
|
||||
fmt.Printf(" Assignee: %s\n", issue.Assignee)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
return
|
||||
}
|
||||
// Direct mode
|
||||
ctx := rootCtx
|
||||
|
||||
|
|
@ -276,17 +194,8 @@ var blockedCmd = &cobra.Command{
|
|||
Short: "Show blocked issues",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Use global jsonOutput set by PersistentPreRun (respects config.yaml + env vars)
|
||||
// If daemon is running but doesn't support this command, use direct storage
|
||||
// Use factory to respect backend configuration (bd-m2jr: SQLite fallback fix)
|
||||
ctx := rootCtx
|
||||
if daemonClient != nil && store == nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
parentID, _ := cmd.Flags().GetString("parent")
|
||||
var blockedFilter types.WorkFilter
|
||||
if parentID != "" {
|
||||
|
|
@ -330,12 +239,7 @@ func runMoleculeReady(_ *cobra.Command, molIDArg string) {
|
|||
|
||||
// Molecule-ready requires direct store access for subgraph loading
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: bd ready --mol requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon ready --mol %s\n", molIDArg)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
221
cmd/bd/relate.go
221
cmd/bd/relate.go
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -68,31 +67,14 @@ func runRelate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve partial IDs
|
||||
var id1, id2 string
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[0]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &id1); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[1]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &id2); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
id1, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
id2, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
var err error
|
||||
id1, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
id2, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
|
||||
if id1 == id2 {
|
||||
|
|
@ -101,31 +83,13 @@ func runRelate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Get both issues
|
||||
var issue1, issue2 *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.Show(&rpc.ShowArgs{ID: id1})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &issue1); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.Show(&rpc.ShowArgs{ID: id2})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &issue2); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
issue1, err = store.GetIssue(ctx, id1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
issue2, err = store.GetIssue(ctx, id2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
issue1, err = store.GetIssue(ctx, id1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
issue2, err = store.GetIssue(ctx, id2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
|
||||
if issue1 == nil {
|
||||
|
|
@ -137,44 +101,23 @@ func runRelate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Add relates-to dependency: id1 -> id2 (bidirectional, so also id2 -> id1)
|
||||
// Per Decision 004, relates-to links are now stored in dependencies table
|
||||
if daemonClient != nil {
|
||||
// Add id1 -> id2
|
||||
_, err := daemonClient.AddDependency(&rpc.DepAddArgs{
|
||||
FromID: id1,
|
||||
ToID: id2,
|
||||
DepType: string(types.DepRelatesTo),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Add id2 -> id1 (bidirectional)
|
||||
_, err = daemonClient.AddDependency(&rpc.DepAddArgs{
|
||||
FromID: id2,
|
||||
ToID: id1,
|
||||
DepType: string(types.DepRelatesTo),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
} else {
|
||||
// Add id1 -> id2
|
||||
dep1 := &types.Dependency{
|
||||
IssueID: id1,
|
||||
DependsOnID: id2,
|
||||
Type: types.DepRelatesTo,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep1, actor); err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Add id2 -> id1 (bidirectional)
|
||||
dep2 := &types.Dependency{
|
||||
IssueID: id2,
|
||||
DependsOnID: id1,
|
||||
Type: types.DepRelatesTo,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep2, actor); err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
// Add id1 -> id2
|
||||
dep1 := &types.Dependency{
|
||||
IssueID: id1,
|
||||
DependsOnID: id2,
|
||||
Type: types.DepRelatesTo,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep1, actor); err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Add id2 -> id1 (bidirectional)
|
||||
dep2 := &types.Dependency{
|
||||
IssueID: id2,
|
||||
DependsOnID: id1,
|
||||
Type: types.DepRelatesTo,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep2, actor); err != nil {
|
||||
return fmt.Errorf("failed to add relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -204,60 +147,25 @@ func runUnrelate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve partial IDs
|
||||
var id1, id2 string
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[0]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &id1); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: args[1]})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &id2); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
id1, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
id2, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
var err error
|
||||
id1, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[0], err)
|
||||
}
|
||||
id2, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s: %w", args[1], err)
|
||||
}
|
||||
|
||||
// Get both issues
|
||||
var issue1, issue2 *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp1, err := daemonClient.Show(&rpc.ShowArgs{ID: id1})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp1.Data, &issue1); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
resp2, err := daemonClient.Show(&rpc.ShowArgs{ID: id2})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp2.Data, &issue2); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
issue1, err = store.GetIssue(ctx, id1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
issue2, err = store.GetIssue(ctx, id2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
issue1, err = store.GetIssue(ctx, id1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id1, err)
|
||||
}
|
||||
issue2, err = store.GetIssue(ctx, id2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get issue %s: %w", id2, err)
|
||||
}
|
||||
|
||||
if issue1 == nil {
|
||||
|
|
@ -269,34 +177,13 @@ func runUnrelate(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Remove relates-to dependency in both directions
|
||||
// Per Decision 004, relates-to links are now stored in dependencies table
|
||||
if daemonClient != nil {
|
||||
// Remove id1 -> id2
|
||||
_, err := daemonClient.RemoveDependency(&rpc.DepRemoveArgs{
|
||||
FromID: id1,
|
||||
ToID: id2,
|
||||
DepType: string(types.DepRelatesTo),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Remove id2 -> id1 (bidirectional)
|
||||
_, err = daemonClient.RemoveDependency(&rpc.DepRemoveArgs{
|
||||
FromID: id2,
|
||||
ToID: id1,
|
||||
DepType: string(types.DepRelatesTo),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
} else {
|
||||
// Remove id1 -> id2
|
||||
if err := store.RemoveDependency(ctx, id1, id2, actor); err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Remove id2 -> id1 (bidirectional)
|
||||
if err := store.RemoveDependency(ctx, id2, id1, actor); err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
// Remove id1 -> id2
|
||||
if err := store.RemoveDependency(ctx, id1, id2, actor); err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id1, id2, err)
|
||||
}
|
||||
// Remove id2 -> id1 (bidirectional)
|
||||
if err := store.RemoveDependency(ctx, id2, id1, actor); err != nil {
|
||||
return fmt.Errorf("failed to remove relates-to %s -> %s: %w", id2, id1, err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
|
|||
|
|
@ -67,12 +67,7 @@ NOTE: This is a rare operation. Most users never need this command.`,
|
|||
ctx := rootCtx
|
||||
|
||||
// rename-prefix requires direct mode (not supported by daemon)
|
||||
if daemonClient != nil {
|
||||
if err := ensureDirectMode("daemon does not support rename-prefix command"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if store == nil {
|
||||
if store == nil {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
"os"
|
||||
)
|
||||
|
||||
var reopenCmd = &cobra.Command{
|
||||
|
|
@ -23,75 +22,14 @@ This is more explicit than 'bd update --status open' and emits a Reopened event.
|
|||
reason, _ := cmd.Flags().GetString("reason")
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
ctx := rootCtx
|
||||
// Resolve partial IDs first
|
||||
var resolvedIDs []string
|
||||
if daemonClient != nil {
|
||||
for _, id := range args {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolvedID)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// Resolve partial IDs
|
||||
_, err := utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
reopenedIssues := []*types.Issue{}
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
for _, id := range resolvedIDs {
|
||||
openStatus := string(types.StatusOpen)
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: id,
|
||||
Status: &openStatus,
|
||||
}
|
||||
resp, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reopening %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
// Add reason as a comment if provided
|
||||
if reason != "" {
|
||||
commentArgs := &rpc.CommentAddArgs{
|
||||
ID: id,
|
||||
Author: actor,
|
||||
Text: reason,
|
||||
}
|
||||
if _, err := daemonClient.AddComment(commentArgs); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add comment to %s: %v\n", id, err)
|
||||
}
|
||||
}
|
||||
if jsonOutput {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err == nil {
|
||||
reopenedIssues = append(reopenedIssues, &issue)
|
||||
}
|
||||
} else {
|
||||
reasonMsg := ""
|
||||
if reason != "" {
|
||||
reasonMsg = ": " + reason
|
||||
}
|
||||
fmt.Printf("%s Reopened %s%s\n", ui.RenderAccent("↻"), id, reasonMsg)
|
||||
}
|
||||
}
|
||||
if jsonOutput && len(reopenedIssues) > 0 {
|
||||
outputJSON(reopenedIssues)
|
||||
}
|
||||
return
|
||||
}
|
||||
// Fall back to direct storage access
|
||||
// Direct storage access
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
"github.com/steveyegge/beads/internal/validation"
|
||||
|
|
@ -206,86 +203,6 @@ Examples:
|
|||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
listArgs := &rpc.ListArgs{
|
||||
Query: query, // This will search title/description/id with OR logic
|
||||
Status: status,
|
||||
IssueType: issueType,
|
||||
Assignee: assignee,
|
||||
Limit: limit,
|
||||
}
|
||||
|
||||
if len(labels) > 0 {
|
||||
listArgs.Labels = labels
|
||||
}
|
||||
|
||||
if len(labelsAny) > 0 {
|
||||
listArgs.LabelsAny = labelsAny
|
||||
}
|
||||
|
||||
// Date ranges
|
||||
if filter.CreatedAfter != nil {
|
||||
listArgs.CreatedAfter = filter.CreatedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.CreatedBefore != nil {
|
||||
listArgs.CreatedBefore = filter.CreatedBefore.Format(time.RFC3339)
|
||||
}
|
||||
if filter.UpdatedAfter != nil {
|
||||
listArgs.UpdatedAfter = filter.UpdatedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.UpdatedBefore != nil {
|
||||
listArgs.UpdatedBefore = filter.UpdatedBefore.Format(time.RFC3339)
|
||||
}
|
||||
if filter.ClosedAfter != nil {
|
||||
listArgs.ClosedAfter = filter.ClosedAfter.Format(time.RFC3339)
|
||||
}
|
||||
if filter.ClosedBefore != nil {
|
||||
listArgs.ClosedBefore = filter.ClosedBefore.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
// Priority range
|
||||
listArgs.PriorityMin = filter.PriorityMin
|
||||
listArgs.PriorityMax = filter.PriorityMax
|
||||
|
||||
// Pattern matching
|
||||
listArgs.DescriptionContains = descContains
|
||||
listArgs.NotesContains = notesContains
|
||||
|
||||
// Empty/null checks
|
||||
listArgs.EmptyDescription = filter.EmptyDescription
|
||||
listArgs.NoAssignee = filter.NoAssignee
|
||||
listArgs.NoLabels = filter.NoLabels
|
||||
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
var issuesWithCounts []*types.IssueWithCounts
|
||||
if err := json.Unmarshal(resp.Data, &issuesWithCounts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
outputJSON(issuesWithCounts)
|
||||
return
|
||||
}
|
||||
|
||||
var issues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
sortIssues(issues, sortBy, reverse)
|
||||
|
||||
outputSearchResults(issues, query, longFormat)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct mode - search using store
|
||||
// The query parameter in SearchIssues already searches across title, description, and id
|
||||
issues, err := store.SearchIssues(ctx, query, filter)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -53,38 +49,10 @@ func runShip(cmd *cobra.Command, args []string) {
|
|||
var issues []*types.Issue
|
||||
var err error
|
||||
|
||||
// Ship requires direct store access for label operations
|
||||
// Use factory to respect backend configuration (bd-m2jr: SQLite fallback fix)
|
||||
if daemonClient != nil && store == nil {
|
||||
beadsDir := filepath.Dir(dbPath)
|
||||
store, err = factory.NewFromConfig(ctx, beadsDir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to open database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
}
|
||||
|
||||
if daemonClient != nil {
|
||||
// Use RPC to list issues with the export label
|
||||
listArgs := &rpc.ListArgs{
|
||||
LabelsAny: []string{exportLabel},
|
||||
}
|
||||
resp, err := daemonClient.List(listArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing issues: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling issues: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
issues, err = store.GetIssuesByLabel(ctx, exportLabel)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing issues: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
issues, err = store.GetIssuesByLabel(ctx, exportLabel)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing issues: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(issues) == 0 {
|
||||
|
|
|
|||
311
cmd/bd/show.go
311
cmd/bd/show.go
|
|
@ -1,14 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -68,37 +66,11 @@ var showCmd = &cobra.Command{
|
|||
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// Resolve partial IDs first (daemon mode only - direct mode uses routed resolution)
|
||||
var resolvedIDs []string
|
||||
var routedArgs []string // IDs that need cross-repo routing (bypass daemon)
|
||||
if daemonClient != nil {
|
||||
// In daemon mode, resolve via RPC - but check routing first
|
||||
for _, id := range args {
|
||||
// Check if this ID needs routing to a different beads directory
|
||||
if needsRouting(id) {
|
||||
routedArgs = append(routedArgs, id)
|
||||
continue
|
||||
}
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving ID %s: %v", id, err)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolvedID)
|
||||
}
|
||||
}
|
||||
// Note: Direct mode uses resolveAndGetIssueWithRouting for prefix-based routing
|
||||
|
||||
// Handle --thread flag: show full conversation thread
|
||||
if showThread {
|
||||
if daemonClient != nil && len(resolvedIDs) > 0 {
|
||||
showMessageThread(ctx, resolvedIDs[0], jsonOutput)
|
||||
return
|
||||
} else if len(args) > 0 {
|
||||
if len(args) > 0 {
|
||||
// Direct mode - resolve first arg with routing
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, args[0])
|
||||
if result != nil {
|
||||
|
|
@ -113,290 +85,13 @@ var showCmd = &cobra.Command{
|
|||
|
||||
// Handle --refs flag: show issues that reference this issue
|
||||
if showRefs {
|
||||
showIssueRefs(ctx, args, resolvedIDs, routedArgs, jsonOutput)
|
||||
showIssueRefs(ctx, args, nil, nil, jsonOutput)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle --children flag: show only children of this issue
|
||||
if showChildren {
|
||||
showIssueChildren(ctx, args, resolvedIDs, routedArgs, jsonOutput, shortMode)
|
||||
return
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC (but fall back to direct mode for routed IDs)
|
||||
if daemonClient != nil {
|
||||
allDetails := []interface{}{}
|
||||
displayIdx := 0
|
||||
foundCount := 0
|
||||
|
||||
// First, handle routed IDs via direct mode
|
||||
for _, id := range routedArgs {
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
issue := result.Issue
|
||||
issueStore := result.Store
|
||||
foundCount++
|
||||
if shortMode {
|
||||
fmt.Println(formatShortIssue(issue))
|
||||
result.Close()
|
||||
continue
|
||||
}
|
||||
if jsonOutput {
|
||||
// Get labels and deps for JSON output
|
||||
details := &types.IssueDetails{Issue: *issue}
|
||||
details.Labels, _ = issueStore.GetLabels(ctx, issue.ID)
|
||||
details.Dependencies, _ = issueStore.GetDependenciesWithMetadata(ctx, issue.ID)
|
||||
details.Dependents, _ = issueStore.GetDependentsWithMetadata(ctx, issue.ID)
|
||||
details.Comments, _ = issueStore.GetIssueComments(ctx, issue.ID)
|
||||
// Compute parent from dependencies
|
||||
for _, dep := range details.Dependencies {
|
||||
if dep.DependencyType == types.DepParentChild {
|
||||
details.Parent = &dep.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
allDetails = append(allDetails, details)
|
||||
} else {
|
||||
if displayIdx > 0 {
|
||||
fmt.Println("\n" + ui.RenderMuted(strings.Repeat("─", 60)))
|
||||
fmt.Printf("\n%s\n", formatIssueHeader(issue))
|
||||
} else {
|
||||
fmt.Printf("%s\n", formatIssueHeader(issue))
|
||||
}
|
||||
// Metadata: Owner · Type | Created · Updated
|
||||
fmt.Println(formatIssueMetadata(issue))
|
||||
if issue.Description != "" {
|
||||
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESCRIPTION"), ui.RenderMarkdown(issue.Description))
|
||||
}
|
||||
fmt.Println()
|
||||
displayIdx++
|
||||
}
|
||||
result.Close() // Close immediately after processing each routed ID
|
||||
}
|
||||
|
||||
// Then, handle local IDs via daemon
|
||||
for _, id := range resolvedIDs {
|
||||
showArgs := &rpc.ShowArgs{ID: id}
|
||||
resp, err := daemonClient.Show(showArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
var details types.IssueDetails
|
||||
if err := json.Unmarshal(resp.Data, &details); err == nil {
|
||||
// Compute parent from dependencies
|
||||
for _, dep := range details.Dependencies {
|
||||
if dep.DependencyType == types.DepParentChild {
|
||||
details.Parent = &dep.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
allDetails = append(allDetails, details)
|
||||
foundCount++
|
||||
}
|
||||
} else {
|
||||
// Check if issue exists (daemon returns null for non-existent issues)
|
||||
if string(resp.Data) == "null" || len(resp.Data) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
foundCount++
|
||||
|
||||
// Parse response first to check shortMode before output
|
||||
var details types.IssueDetails
|
||||
if err := json.Unmarshal(resp.Data, &details); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
issue := &details.Issue
|
||||
|
||||
if shortMode {
|
||||
fmt.Println(formatShortIssue(issue))
|
||||
continue
|
||||
}
|
||||
|
||||
if displayIdx > 0 {
|
||||
fmt.Println("\n" + ui.RenderMuted(strings.Repeat("─", 60)))
|
||||
fmt.Printf("\n%s\n", formatIssueHeader(issue))
|
||||
} else {
|
||||
fmt.Printf("%s\n", formatIssueHeader(issue))
|
||||
}
|
||||
displayIdx++
|
||||
|
||||
|
||||
// Metadata: Owner · Type | Created · Updated
|
||||
fmt.Println(formatIssueMetadata(issue))
|
||||
|
||||
// Compaction info (if applicable)
|
||||
if issue.CompactionLevel > 0 {
|
||||
fmt.Println()
|
||||
if issue.OriginalSize > 0 {
|
||||
currentSize := len(issue.Description) + len(issue.Design) + len(issue.Notes) + len(issue.AcceptanceCriteria)
|
||||
saved := issue.OriginalSize - currentSize
|
||||
if saved > 0 {
|
||||
reduction := float64(saved) / float64(issue.OriginalSize) * 100
|
||||
fmt.Printf("📊 %d → %d bytes (%.0f%% reduction)\n",
|
||||
issue.OriginalSize, currentSize, reduction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Content sections
|
||||
if issue.Description != "" {
|
||||
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESCRIPTION"), ui.RenderMarkdown(issue.Description))
|
||||
}
|
||||
if issue.Design != "" {
|
||||
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESIGN"), ui.RenderMarkdown(issue.Design))
|
||||
}
|
||||
if issue.Notes != "" {
|
||||
fmt.Printf("\n%s\n%s\n", ui.RenderBold("NOTES"), ui.RenderMarkdown(issue.Notes))
|
||||
}
|
||||
if issue.AcceptanceCriteria != "" {
|
||||
fmt.Printf("\n%s\n%s\n", ui.RenderBold("ACCEPTANCE CRITERIA"), ui.RenderMarkdown(issue.AcceptanceCriteria))
|
||||
}
|
||||
|
||||
if len(details.Labels) > 0 {
|
||||
fmt.Printf("\n%s %s\n", ui.RenderBold("LABELS:"), strings.Join(details.Labels, ", "))
|
||||
}
|
||||
|
||||
// Collect related issues from both directions for deduplication
|
||||
// (relates-to is bidirectional, so we merge and show once)
|
||||
relatedSeen := make(map[string]*types.IssueWithDependencyMetadata)
|
||||
|
||||
// Dependencies grouped by type with semantic colors
|
||||
if len(details.Dependencies) > 0 {
|
||||
var blocks, parent, discovered []*types.IssueWithDependencyMetadata
|
||||
for _, dep := range details.Dependencies {
|
||||
switch dep.DependencyType {
|
||||
case types.DepBlocks:
|
||||
blocks = append(blocks, dep)
|
||||
case types.DepParentChild:
|
||||
parent = append(parent, dep)
|
||||
case types.DepRelated, types.DepRelatesTo:
|
||||
relatedSeen[dep.ID] = dep
|
||||
case types.DepDiscoveredFrom:
|
||||
discovered = append(discovered, dep)
|
||||
default:
|
||||
blocks = append(blocks, dep)
|
||||
}
|
||||
}
|
||||
|
||||
if len(parent) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("PARENT"))
|
||||
for _, dep := range parent {
|
||||
fmt.Println(formatDependencyLine("↑", dep))
|
||||
}
|
||||
}
|
||||
if len(blocks) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("DEPENDS ON"))
|
||||
for _, dep := range blocks {
|
||||
fmt.Println(formatDependencyLine("→", dep))
|
||||
}
|
||||
}
|
||||
if len(discovered) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("DISCOVERED FROM"))
|
||||
for _, dep := range discovered {
|
||||
fmt.Println(formatDependencyLine("◊", dep))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dependents grouped by type with semantic colors
|
||||
if len(details.Dependents) > 0 {
|
||||
var blocks, children, discovered []*types.IssueWithDependencyMetadata
|
||||
for _, dep := range details.Dependents {
|
||||
switch dep.DependencyType {
|
||||
case types.DepBlocks:
|
||||
blocks = append(blocks, dep)
|
||||
case types.DepParentChild:
|
||||
children = append(children, dep)
|
||||
case types.DepRelated, types.DepRelatesTo:
|
||||
relatedSeen[dep.ID] = dep
|
||||
case types.DepDiscoveredFrom:
|
||||
discovered = append(discovered, dep)
|
||||
default:
|
||||
blocks = append(blocks, dep)
|
||||
}
|
||||
}
|
||||
|
||||
if len(children) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("CHILDREN"))
|
||||
for _, dep := range children {
|
||||
fmt.Println(formatDependencyLine("↳", dep))
|
||||
}
|
||||
}
|
||||
if len(blocks) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("BLOCKS"))
|
||||
for _, dep := range blocks {
|
||||
fmt.Println(formatDependencyLine("←", dep))
|
||||
}
|
||||
}
|
||||
if len(discovered) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("DISCOVERED"))
|
||||
for _, dep := range discovered {
|
||||
fmt.Println(formatDependencyLine("◊", dep))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print deduplicated RELATED section (bidirectional links shown once)
|
||||
if len(relatedSeen) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("RELATED"))
|
||||
for _, dep := range relatedSeen {
|
||||
fmt.Println(formatDependencyLine("↔", dep))
|
||||
}
|
||||
}
|
||||
|
||||
if len(details.Comments) > 0 {
|
||||
fmt.Printf("\n%s\n", ui.RenderBold("COMMENTS"))
|
||||
for _, comment := range details.Comments {
|
||||
fmt.Printf(" %s %s\n", ui.RenderMuted(formatTime(comment.CreatedAt)), comment.Author)
|
||||
rendered := ui.RenderMarkdown(comment.Text)
|
||||
// TrimRight removes trailing newlines that Glamour adds, preventing extra blank lines
|
||||
for _, line := range strings.Split(strings.TrimRight(rendered, "\n"), "\n") {
|
||||
fmt.Printf(" %s\n", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
if len(allDetails) > 0 {
|
||||
outputJSON(allDetails)
|
||||
} else {
|
||||
// No issues found - exit non-zero with structured JSON error
|
||||
// so downstream consumers (e.g., gt bd move) get a proper error
|
||||
// instead of empty stdout causing "unexpected end of JSON input"
|
||||
FatalErrorRespectJSON("no issues found matching the provided IDs")
|
||||
}
|
||||
} else if foundCount == 0 {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Track first shown issue as last touched
|
||||
if len(resolvedIDs) > 0 {
|
||||
SetLastTouchedID(resolvedIDs[0])
|
||||
} else if len(routedArgs) > 0 {
|
||||
SetLastTouchedID(routedArgs[0])
|
||||
}
|
||||
showIssueChildren(ctx, args, nil, nil, jsonOutput, shortMode)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -59,44 +57,27 @@ func showIssueChildren(ctx context.Context, args []string, resolvedIDs []string,
|
|||
result.Close()
|
||||
}
|
||||
|
||||
// Handle resolved IDs (daemon mode)
|
||||
if daemonClient != nil {
|
||||
for _, id := range resolvedIDs {
|
||||
// Need to open direct connection for GetDependentsWithMetadata
|
||||
// Use factory to respect backend configuration (bd-m2jr: SQLite fallback fix)
|
||||
dbStore, err := factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening database: %v\n", err)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(id, dbStore); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting children for %s: %v\n", id, err)
|
||||
}
|
||||
_ = dbStore.Close()
|
||||
// Direct mode - process each arg
|
||||
for _, id := range args {
|
||||
if containsStr(routedArgs, id) {
|
||||
continue // Already processed above
|
||||
}
|
||||
} else {
|
||||
// Direct mode - process each arg
|
||||
for _, id := range args {
|
||||
if containsStr(routedArgs, id) {
|
||||
continue // Already processed above
|
||||
}
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(result.ResolvedID, result.Store); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting children for %s: %v\n", id, err)
|
||||
}
|
||||
result.Close()
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(result.ResolvedID, result.Store); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting children for %s: %v\n", id, err)
|
||||
}
|
||||
result.Close()
|
||||
}
|
||||
|
||||
// Output results
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -47,44 +45,27 @@ func showIssueRefs(ctx context.Context, args []string, resolvedIDs []string, rou
|
|||
result.Close()
|
||||
}
|
||||
|
||||
// Handle resolved IDs (daemon mode)
|
||||
if daemonClient != nil {
|
||||
for _, id := range resolvedIDs {
|
||||
// Need to open direct connection for GetDependentsWithMetadata
|
||||
// Use factory to respect backend configuration (bd-m2jr: SQLite fallback fix)
|
||||
dbStore, err := factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening database: %v\n", err)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(id, dbStore); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting refs for %s: %v\n", id, err)
|
||||
}
|
||||
_ = dbStore.Close()
|
||||
// Direct mode - process each arg
|
||||
for _, id := range args {
|
||||
if containsStr(routedArgs, id) {
|
||||
continue // Already processed above
|
||||
}
|
||||
} else {
|
||||
// Direct mode - process each arg
|
||||
for _, id := range args {
|
||||
if containsStr(routedArgs, id) {
|
||||
continue // Already processed above
|
||||
}
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(result.ResolvedID, result.Store); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting refs for %s: %v\n", id, err)
|
||||
}
|
||||
result.Close()
|
||||
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
if result == nil || result.Issue == nil {
|
||||
if result != nil {
|
||||
result.Close()
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
||||
continue
|
||||
}
|
||||
if err := processIssue(result.ResolvedID, result.Store); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting refs for %s: %v\n", id, err)
|
||||
}
|
||||
result.Close()
|
||||
}
|
||||
|
||||
// Output results
|
||||
|
|
|
|||
|
|
@ -20,22 +20,10 @@ func showMessageThread(ctx context.Context, messageID string, jsonOutput bool) {
|
|||
var startMsg *types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: messageID})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error fetching message %s: %v\n", messageID, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &startMsg); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
startMsg, err = store.GetIssue(ctx, messageID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error fetching message %s: %v\n", messageID, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
startMsg, err = store.GetIssue(ctx, messageID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error fetching message %s: %v\n", messageID, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if startMsg == nil {
|
||||
|
|
@ -60,18 +48,7 @@ func showMessageThread(ctx context.Context, messageID string, jsonOutput bool) {
|
|||
}
|
||||
seen[parentID] = true
|
||||
|
||||
var parentMsg *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: parentID})
|
||||
if err != nil {
|
||||
break // Parent not found, use current as root
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &parentMsg); err != nil {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
parentMsg, _ = store.GetIssue(ctx, parentID)
|
||||
}
|
||||
parentMsg, _ := store.GetIssue(ctx, parentID)
|
||||
if parentMsg == nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -163,30 +140,6 @@ func showMessageThread(ctx context.Context, messageID string, jsonOutput bool) {
|
|||
// findRepliesTo finds the parent ID that this issue replies to via replies-to dependency.
|
||||
// Returns empty string if no parent found.
|
||||
func findRepliesTo(ctx context.Context, issueID string, daemonClient *rpc.Client, store storage.Storage) string {
|
||||
if daemonClient != nil {
|
||||
// In daemon mode, use Show to get dependencies with metadata
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: issueID})
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
// Parse the full show response to get dependencies
|
||||
type showResponse struct {
|
||||
Dependencies []struct {
|
||||
ID string `json:"id"`
|
||||
DependencyType string `json:"dependency_type"`
|
||||
} `json:"dependencies"`
|
||||
}
|
||||
var details showResponse
|
||||
if err := json.Unmarshal(resp.Data, &details); err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, dep := range details.Dependencies {
|
||||
if dep.DependencyType == string(types.DepRepliesTo) {
|
||||
return dep.ID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
// Direct mode - query storage
|
||||
deps, err := store.GetDependencyRecords(ctx, issueID)
|
||||
if err != nil {
|
||||
|
|
@ -202,32 +155,6 @@ func findRepliesTo(ctx context.Context, issueID string, daemonClient *rpc.Client
|
|||
|
||||
// findReplies finds all issues that reply to this issue via replies-to dependency.
|
||||
func findReplies(ctx context.Context, issueID string, daemonClient *rpc.Client, store storage.Storage) []*types.Issue {
|
||||
if daemonClient != nil {
|
||||
// In daemon mode, use Show to get dependents with metadata
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: issueID})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
// Parse the full show response to get dependents
|
||||
type showResponse struct {
|
||||
Dependents []struct {
|
||||
types.Issue
|
||||
DependencyType string `json:"dependency_type"`
|
||||
} `json:"dependents"`
|
||||
}
|
||||
var details showResponse
|
||||
if err := json.Unmarshal(resp.Data, &details); err != nil {
|
||||
return nil
|
||||
}
|
||||
var replies []*types.Issue
|
||||
for _, dep := range details.Dependents {
|
||||
if dep.DependencyType == string(types.DepRepliesTo) {
|
||||
issue := dep.Issue // Copy to avoid aliasing
|
||||
replies = append(replies, &issue)
|
||||
}
|
||||
}
|
||||
return replies
|
||||
}
|
||||
// Direct mode - query storage
|
||||
deps, err := store.GetDependentsWithMetadata(ctx, issueID)
|
||||
if err != nil {
|
||||
|
|
|
|||
179
cmd/bd/slot.go
179
cmd/bd/slot.go
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -102,20 +101,10 @@ func runSlotSet(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve agent ID
|
||||
var agentID string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
|
||||
// Resolve bead ID - use routing for cross-beads references (e.g., hq-* from rig beads)
|
||||
|
|
@ -133,14 +122,6 @@ func runSlotSet(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("failed to resolve bead %s: no issue found matching %q", beadArg, beadArg)
|
||||
}
|
||||
beadID = result.ResolvedID
|
||||
} else if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: beadArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve bead %s: %w", beadArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &beadID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
beadID, err = utils.ResolvePartialID(ctx, store, beadArg)
|
||||
|
|
@ -151,20 +132,9 @@ func runSlotSet(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Get current agent bead to check cardinality
|
||||
var agent *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
|
||||
// Verify agent bead is actually an agent
|
||||
|
|
@ -178,29 +148,15 @@ func runSlotSet(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Update the slot
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{ID: agentID}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updateArgs.HookBead = &beadID
|
||||
case "role":
|
||||
updateArgs.RoleBead = &beadID
|
||||
}
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set slot: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updates["hook_bead"] = beadID
|
||||
case "role":
|
||||
updates["role_bead"] = beadID
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to set slot: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updates["hook_bead"] = beadID
|
||||
case "role":
|
||||
updates["role_bead"] = beadID
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to set slot: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -238,38 +194,17 @@ func runSlotClear(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve agent ID
|
||||
var agentID string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
|
||||
// Get current agent bead to verify it's an agent
|
||||
var agent *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
|
||||
// Verify agent bead is actually an agent
|
||||
|
|
@ -278,30 +213,15 @@ func runSlotClear(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
// Clear the slot (set to empty string)
|
||||
emptyStr := ""
|
||||
if daemonClient != nil {
|
||||
updateArgs := &rpc.UpdateArgs{ID: agentID}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updateArgs.HookBead = &emptyStr
|
||||
case "role":
|
||||
updateArgs.RoleBead = &emptyStr
|
||||
}
|
||||
_, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to clear slot: %w", err)
|
||||
}
|
||||
} else {
|
||||
updates := map[string]interface{}{}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updates["hook_bead"] = ""
|
||||
case "role":
|
||||
updates["role_bead"] = ""
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to clear slot: %w", err)
|
||||
}
|
||||
updates := map[string]interface{}{}
|
||||
switch slotName {
|
||||
case "hook":
|
||||
updates["hook_bead"] = ""
|
||||
case "role":
|
||||
updates["role_bead"] = ""
|
||||
}
|
||||
if err := store.UpdateIssue(ctx, agentID, updates, actor); err != nil {
|
||||
return fmt.Errorf("failed to clear slot: %w", err)
|
||||
}
|
||||
|
||||
// Trigger auto-flush
|
||||
|
|
@ -331,38 +251,17 @@ func runSlotShow(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Resolve agent ID
|
||||
var agentID string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.ResolveID(&rpc.ResolveIDArgs{ID: agentArg})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agentID); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
var err error
|
||||
agentID, err = utils.ResolvePartialID(ctx, store, agentArg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve agent %s: %w", agentArg, err)
|
||||
}
|
||||
|
||||
// Get agent bead
|
||||
var agent *types.Issue
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: agentID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &agent); err != nil {
|
||||
return fmt.Errorf("parsing response: %w", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
agent, err = store.GetIssue(ctx, agentID)
|
||||
if err != nil || agent == nil {
|
||||
return fmt.Errorf("agent bead not found: %s", agentID)
|
||||
}
|
||||
|
||||
// Verify agent bead is actually an agent
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -36,33 +34,6 @@ This helps identify:
|
|||
Status: status,
|
||||
Limit: limit,
|
||||
}
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
staleArgs := &rpc.StaleArgs{
|
||||
Days: days,
|
||||
Status: status,
|
||||
Limit: limit,
|
||||
}
|
||||
resp, err := daemonClient.Stale(staleArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var issues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if jsonOutput {
|
||||
if issues == nil {
|
||||
issues = []*types.Issue{}
|
||||
}
|
||||
outputJSON(issues)
|
||||
return
|
||||
}
|
||||
displayStaleIssues(issues, days)
|
||||
return
|
||||
}
|
||||
// Direct mode
|
||||
ctx := rootCtx
|
||||
|
||||
|
|
|
|||
216
cmd/bd/state.go
216
cmd/bd/state.go
|
|
@ -5,12 +5,10 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -41,41 +39,17 @@ Examples:
|
|||
|
||||
// Resolve partial ID
|
||||
var fullID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: issueID}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", issueID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
|
||||
// Get labels for the issue
|
||||
var labels []string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: fullID})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
labels = issue.Labels
|
||||
} else {
|
||||
var err error
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Find label matching dimension:*
|
||||
|
|
@ -150,41 +124,17 @@ The --reason flag provides context for the event bead (recommended).`,
|
|||
|
||||
// Resolve partial ID
|
||||
var fullID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: issueID}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", issueID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
|
||||
// Get current labels to find existing dimension value
|
||||
var labels []string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: fullID})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
labels = issue.Labels
|
||||
} else {
|
||||
var err error
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Find existing label for this dimension
|
||||
|
|
@ -229,81 +179,47 @@ The --reason flag provides context for the event bead (recommended).`,
|
|||
}
|
||||
|
||||
var eventID string
|
||||
if daemonClient != nil {
|
||||
createArgs := &rpc.CreateArgs{
|
||||
Parent: fullID,
|
||||
Title: eventTitle,
|
||||
Description: eventDesc,
|
||||
IssueType: string(types.TypeEvent),
|
||||
Priority: 4, // Low priority for events
|
||||
CreatedBy: getActorWithGit(),
|
||||
}
|
||||
resp, err := daemonClient.Create(createArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("creating event: %v", err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing event response: %v", err)
|
||||
}
|
||||
eventID = issue.ID
|
||||
} else {
|
||||
// Get next child ID for the event
|
||||
childID, err := store.GetNextChildID(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("generating child ID: %v", err)
|
||||
}
|
||||
|
||||
event := &types.Issue{
|
||||
ID: childID,
|
||||
Title: eventTitle,
|
||||
Description: eventDesc,
|
||||
Status: types.StatusClosed, // Events are immediately closed
|
||||
Priority: 4,
|
||||
IssueType: types.TypeEvent,
|
||||
CreatedBy: getActorWithGit(),
|
||||
}
|
||||
if err := store.CreateIssue(ctx, event, actor); err != nil {
|
||||
FatalErrorRespectJSON("creating event: %v", err)
|
||||
}
|
||||
|
||||
// Add parent-child dependency
|
||||
dep := &types.Dependency{
|
||||
IssueID: childID,
|
||||
DependsOnID: fullID,
|
||||
Type: types.DepParentChild,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep, actor); err != nil {
|
||||
WarnError("failed to add parent-child dependency: %v", err)
|
||||
}
|
||||
|
||||
eventID = childID
|
||||
// Get next child ID for the event
|
||||
childID, err := store.GetNextChildID(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("generating child ID: %v", err)
|
||||
}
|
||||
|
||||
event := &types.Issue{
|
||||
ID: childID,
|
||||
Title: eventTitle,
|
||||
Description: eventDesc,
|
||||
Status: types.StatusClosed, // Events are immediately closed
|
||||
Priority: 4,
|
||||
IssueType: types.TypeEvent,
|
||||
CreatedBy: getActorWithGit(),
|
||||
}
|
||||
if err := store.CreateIssue(ctx, event, actor); err != nil {
|
||||
FatalErrorRespectJSON("creating event: %v", err)
|
||||
}
|
||||
|
||||
// Add parent-child dependency
|
||||
dep := &types.Dependency{
|
||||
IssueID: childID,
|
||||
DependsOnID: fullID,
|
||||
Type: types.DepParentChild,
|
||||
}
|
||||
if err := store.AddDependency(ctx, dep, actor); err != nil {
|
||||
WarnError("failed to add parent-child dependency: %v", err)
|
||||
}
|
||||
|
||||
eventID = childID
|
||||
|
||||
// 2. Remove old label if exists
|
||||
if oldLabel != "" {
|
||||
if daemonClient != nil {
|
||||
_, err := daemonClient.RemoveLabel(&rpc.LabelRemoveArgs{ID: fullID, Label: oldLabel})
|
||||
if err != nil {
|
||||
WarnError("failed to remove old label %s: %v", oldLabel, err)
|
||||
}
|
||||
} else {
|
||||
if err := store.RemoveLabel(ctx, fullID, oldLabel, actor); err != nil {
|
||||
WarnError("failed to remove old label %s: %v", oldLabel, err)
|
||||
}
|
||||
if err := store.RemoveLabel(ctx, fullID, oldLabel, actor); err != nil {
|
||||
WarnError("failed to remove old label %s: %v", oldLabel, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Add new label
|
||||
if daemonClient != nil {
|
||||
_, err := daemonClient.AddLabel(&rpc.LabelAddArgs{ID: fullID, Label: newLabel})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("adding label: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err := store.AddLabel(ctx, fullID, newLabel, actor); err != nil {
|
||||
FatalErrorRespectJSON("adding label: %v", err)
|
||||
}
|
||||
if err := store.AddLabel(ctx, fullID, newLabel, actor); err != nil {
|
||||
FatalErrorRespectJSON("adding label: %v", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
@ -351,41 +267,17 @@ Example:
|
|||
|
||||
// Resolve partial ID
|
||||
var fullID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: issueID}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving issue ID %s: %v", issueID, err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &fullID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
var err error
|
||||
fullID, err = utils.ResolvePartialID(ctx, store, issueID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving %s: %v", issueID, err)
|
||||
}
|
||||
|
||||
// Get labels for the issue
|
||||
var labels []string
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: fullID})
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
labels = issue.Labels
|
||||
} else {
|
||||
var err error
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
labels, err = store.GetLabels(ctx, fullID)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Extract state labels (those with colon)
|
||||
|
|
|
|||
|
|
@ -76,23 +76,10 @@ Examples:
|
|||
ctx := rootCtx
|
||||
requireFreshDB(ctx)
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
resp, rpcErr := daemonClient.Stats()
|
||||
if rpcErr != nil {
|
||||
FatalErrorRespectJSON("%v", rpcErr)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(resp.Data, &stats); err != nil {
|
||||
FatalErrorRespectJSON("parsing response: %v", err)
|
||||
}
|
||||
} else {
|
||||
// Direct mode
|
||||
ctx := rootCtx
|
||||
stats, err = store.GetStatistics(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
// Direct mode
|
||||
stats, err = store.GetStatistics(ctx)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Filter by assignee if requested (overrides stats with filtered counts)
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -160,16 +158,7 @@ Examples:
|
|||
|
||||
// Swarm commands require direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
} else {
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
|
||||
// Resolve epic ID
|
||||
|
|
@ -626,16 +615,7 @@ Examples:
|
|||
|
||||
// Swarm commands require direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
} else {
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
|
||||
// Resolve ID
|
||||
|
|
@ -920,16 +900,7 @@ Examples:
|
|||
|
||||
// Swarm commands require direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
} else {
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
|
||||
// Resolve the input ID
|
||||
|
|
@ -1102,16 +1073,7 @@ Examples:
|
|||
|
||||
// Swarm commands require direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
var err error
|
||||
store, err = factory.NewFromConfig(ctx, filepath.Dir(dbPath))
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("failed to open database: %v", err)
|
||||
}
|
||||
defer func() { _ = store.Close() }()
|
||||
} else {
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
FatalErrorRespectJSON("no database connection")
|
||||
}
|
||||
|
||||
// Query for all swarm molecules
|
||||
|
|
|
|||
|
|
@ -172,12 +172,6 @@ The --full flag provides the legacy full sync behavior for backwards compatibili
|
|||
// When connected to daemon, PersistentPreRun skips store initialization.
|
||||
// Just closing daemon leaves store=nil, causing "no database store available"
|
||||
// errors in post-checkout hook's `bd sync --import-only`.
|
||||
if daemonClient != nil {
|
||||
debug.Logf("sync: forcing direct mode for consistency")
|
||||
if err := fallbackToDirectMode("sync requires direct database access"); err != nil {
|
||||
FatalError("failed to initialize direct mode: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize local store after daemon disconnect.
|
||||
// When daemon was connected, PersistentPreRun returns early without initializing
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/debug"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
|
|
@ -194,23 +193,6 @@ func exportToJSONLDeferred(ctx context.Context, jsonlPath string) (*ExportResult
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
// Note: daemon already handles its own metadata updates
|
||||
if daemonClient != nil {
|
||||
exportArgs := &rpc.ExportArgs{
|
||||
JSONLPath: jsonlPath,
|
||||
}
|
||||
resp, err := daemonClient.Export(exportArgs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("daemon export failed: %w", err)
|
||||
}
|
||||
if !resp.Success {
|
||||
return nil, fmt.Errorf("daemon export error: %s", resp.Error)
|
||||
}
|
||||
// Daemon handles its own metadata updates, return nil result
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Direct mode: access store directly
|
||||
// Ensure store is initialized
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
|
|
@ -373,11 +355,6 @@ func exportToJSONLIncrementalDeferred(ctx context.Context, jsonlPath string) (*E
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// If daemon is running, delegate to it (daemon has its own optimization)
|
||||
if daemonClient != nil {
|
||||
return exportToJSONLDeferred(ctx, jsonlPath)
|
||||
}
|
||||
|
||||
// Ensure store is initialized
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize store: %w", err)
|
||||
|
|
|
|||
|
|
@ -84,24 +84,7 @@ var templateListCmd = &cobra.Command{
|
|||
ctx := rootCtx
|
||||
var beadsTemplates []*types.Issue
|
||||
|
||||
if daemonClient != nil {
|
||||
resp, err := daemonClient.List(&rpc.ListArgs{})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error loading templates: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var allIssues []*types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &allIssues); err == nil {
|
||||
for _, issue := range allIssues {
|
||||
for _, label := range issue.Labels {
|
||||
if label == BeadsTemplateLabel {
|
||||
beadsTemplates = append(beadsTemplates, issue)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if store != nil {
|
||||
if store != nil {
|
||||
var err error
|
||||
beadsTemplates, err = store.GetIssuesByLabel(ctx, BeadsTemplateLabel)
|
||||
if err != nil {
|
||||
|
|
@ -150,18 +133,7 @@ var templateShowCmd = &cobra.Command{
|
|||
ctx := rootCtx
|
||||
var templateID string
|
||||
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: template '%s' not found\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &templateID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if store != nil {
|
||||
if store != nil {
|
||||
var err error
|
||||
templateID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
|
|
@ -176,11 +148,7 @@ var templateShowCmd = &cobra.Command{
|
|||
// Load and show Beads template
|
||||
var subgraph *TemplateSubgraph
|
||||
var err error
|
||||
if daemonClient != nil {
|
||||
subgraph, err = loadTemplateSubgraphViaDaemon(daemonClient, templateID)
|
||||
} else {
|
||||
subgraph, err = loadTemplateSubgraph(ctx, store, templateID)
|
||||
}
|
||||
subgraph, err = loadTemplateSubgraph(ctx, store, templateID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error loading template: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
@ -253,18 +221,7 @@ Example:
|
|||
|
||||
// Resolve template ID
|
||||
var templateID string
|
||||
if daemonClient != nil {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving template ID %s: %v\n", args[0], err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &templateID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if store != nil {
|
||||
if store != nil {
|
||||
var err error
|
||||
templateID, err = utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
|
|
@ -331,11 +288,7 @@ Example:
|
|||
Ephemeral: false,
|
||||
}
|
||||
var result *InstantiateResult
|
||||
if daemonClient != nil {
|
||||
result, err = cloneSubgraphViaDaemon(daemonClient, subgraph, opts)
|
||||
} else {
|
||||
result, err = cloneSubgraph(ctx, store, subgraph, opts)
|
||||
}
|
||||
result, err = cloneSubgraph(ctx, store, subgraph, opts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error instantiating template: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
|
|
@ -29,68 +27,16 @@ Examples:
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
// Resolve partial IDs first
|
||||
var resolvedIDs []string
|
||||
if daemonClient != nil {
|
||||
for _, id := range args {
|
||||
resolveArgs := &rpc.ResolveIDArgs{ID: id}
|
||||
resp, err := daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var resolvedID string
|
||||
if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error unmarshaling resolved ID: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
resolvedIDs = append(resolvedIDs, resolvedID)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// Resolve partial IDs
|
||||
_, err := utils.ResolvePartialIDs(ctx, store, args)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
undeferredIssues := []*types.Issue{}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
for _, id := range resolvedIDs {
|
||||
status := string(types.StatusOpen)
|
||||
emptyStr := "" // Clear defer_until by sending empty string (GH#820)
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: id,
|
||||
Status: &status,
|
||||
DeferUntil: &emptyStr, // Clear defer_until timestamp
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error undeferring %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err == nil {
|
||||
undeferredIssues = append(undeferredIssues, &issue)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), id)
|
||||
}
|
||||
}
|
||||
|
||||
if jsonOutput && len(undeferredIssues) > 0 {
|
||||
outputJSON(undeferredIssues)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Fall back to direct storage access
|
||||
// Direct storage access
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
|
|
@ -10,7 +9,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -353,7 +351,7 @@ func runWispList(cmd *cobra.Command, args []string) {
|
|||
showAll, _ := cmd.Flags().GetBool("all")
|
||||
|
||||
// Check for database connection
|
||||
if store == nil && daemonClient == nil {
|
||||
if store == nil {
|
||||
if jsonOutput {
|
||||
outputJSON(WispListResult{
|
||||
Wisps: []WispListItem{},
|
||||
|
|
@ -367,28 +365,10 @@ func runWispList(cmd *cobra.Command, args []string) {
|
|||
|
||||
// Query wisps from main database using Ephemeral filter
|
||||
ephemeralFlag := true
|
||||
var issues []*types.Issue
|
||||
var err error
|
||||
|
||||
if daemonClient != nil {
|
||||
// Use daemon RPC
|
||||
resp, rpcErr := daemonClient.List(&rpc.ListArgs{
|
||||
Ephemeral: &ephemeralFlag,
|
||||
})
|
||||
if rpcErr != nil {
|
||||
err = rpcErr
|
||||
} else {
|
||||
if jsonErr := json.Unmarshal(resp.Data, &issues); jsonErr != nil {
|
||||
err = jsonErr
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Direct database access
|
||||
filter := types.IssueFilter{
|
||||
Ephemeral: &ephemeralFlag,
|
||||
}
|
||||
issues, err = store.SearchIssues(ctx, "", filter)
|
||||
filter := types.IssueFilter{
|
||||
Ephemeral: &ephemeralFlag,
|
||||
}
|
||||
issues, err := store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing wisps: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue