Fix lint errors: handle errors, use fmt.Fprintf, apply De Morgan's law, use switch statements

Amp-Thread-ID: https://ampcode.com/threads/T-afcf56b0-a8bc-4310-bb59-1b63e1d70c89
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-24 12:27:02 -07:00
parent 1d5e89b9bb
commit 9dcb86ebfb
17 changed files with 342 additions and 537 deletions
+2 -1
View File
@@ -16,7 +16,8 @@ import (
"github.com/steveyegge/beads/internal/types"
)
// Core types for working with issues
// Issue represents a tracked work item with metadata, dependencies, and status.
// Status represents the current state of an issue (open, in progress, closed, blocked).
type (
Issue = types.Issue
Status = types.Status
+12 -4
View File
@@ -63,7 +63,9 @@ func TestLibraryIntegration(t *testing.T) {
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
store.CreateIssue(ctx, issue, "test-actor")
if err := store.CreateIssue(ctx, issue, "test-actor"); err != nil {
t.Fatalf("CreateIssue failed: %v", err)
}
// Get it back
retrieved, err := store.GetIssue(ctx, issue.ID)
@@ -89,7 +91,9 @@ func TestLibraryIntegration(t *testing.T) {
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
store.CreateIssue(ctx, issue, "test-actor")
if err := store.CreateIssue(ctx, issue, "test-actor"); err != nil {
t.Fatalf("CreateIssue failed: %v", err)
}
// Update status
updates := map[string]interface{}{
@@ -131,8 +135,12 @@ func TestLibraryIntegration(t *testing.T) {
UpdatedAt: time.Now(),
}
store.CreateIssue(ctx, issue1, "test-actor")
store.CreateIssue(ctx, issue2, "test-actor")
if err := store.CreateIssue(ctx, issue1, "test-actor"); err != nil {
t.Fatalf("CreateIssue failed: %v", err)
}
if err := store.CreateIssue(ctx, issue2, "test-actor"); err != nil {
t.Fatalf("CreateIssue failed: %v", err)
}
// Add dependency: issue2 blocks issue1
dep := &beads.Dependency{
+1 -1
View File
@@ -1038,7 +1038,7 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
}
return
case <-ctx.Done():
log("Context cancelled, shutting down")
log("Context canceled, shutting down")
if err := server.Stop(); err != nil {
log("Error stopping RPC server: %v", err)
}
+1 -1
View File
@@ -249,7 +249,7 @@ func TestDaemonLogFileCreation(t *testing.T) {
timestamp := time.Now().Format("2006-01-02 15:04:05")
msg := "Test log message"
_, err = logF.WriteString(fmt.Sprintf("[%s] %s\n", timestamp, msg))
_, err = fmt.Fprintf(logF, "[%s] %s\n", timestamp, msg)
if err != nil {
t.Fatalf("Failed to write to log file: %v", err)
}
+2 -2
View File
@@ -184,10 +184,10 @@ var closeEligibleEpicsCmd = &cobra.Command{
Reason: "All children completed",
})
if err != nil || !resp.Success {
errMsg := "unknown error"
errMsg := ""
if err != nil {
errMsg = err.Error()
} else {
} else if !resp.Success {
errMsg = resp.Error
}
fmt.Fprintf(os.Stderr, "Error closing %s: %s\n", epicStatus.Epic.ID, errMsg)
+1 -1
View File
@@ -657,7 +657,7 @@ func replaceBoundaryAware(text, oldID, newID string) string {
func isBoundary(c byte) bool {
// Issue IDs contain: lowercase letters, digits, and hyphens
// Boundaries are anything else (space, punctuation, etc.)
return !(c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '-')
return (c < 'a' || c > 'z') && (c < '0' || c > '9') && c != '-'
}
// isNumeric returns true if the string contains only digits
+47 -112
View File
@@ -20,53 +20,50 @@ var labelCmd = &cobra.Command{
Short: "Manage issue labels",
}
// executeLabelCommand executes a label operation and handles output
func executeLabelCommand(issueID, label, operation string, operationFunc func(context.Context, string, string, string) error) {
// Helper function to process label operations for multiple issues
func processBatchLabelOperation(issueIDs []string, label string, operation string,
daemonFunc func(string, string) error, storeFunc func(context.Context, string, string, string) error) {
ctx := context.Background()
results := []map[string]interface{}{}
// Use daemon if available
if daemonClient != nil {
for _, issueID := range issueIDs {
var err error
if operation == "added" {
_, err = daemonClient.AddLabel(&rpc.LabelAddArgs{
ID: issueID,
Label: label,
})
if daemonClient != nil {
err = daemonFunc(issueID, label)
} else {
_, err = daemonClient.RemoveLabel(&rpc.LabelRemoveArgs{
ID: issueID,
Label: label,
})
err = storeFunc(ctx, issueID, label, actor)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
} else {
// Direct mode
if err := operationFunc(ctx, issueID, label, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
fmt.Fprintf(os.Stderr, "Error %s label %s %s: %v\n", operation, operation, issueID, err)
continue
}
// Schedule auto-flush
if jsonOutput {
results = append(results, map[string]interface{}{
"status": operation,
"issue_id": issueID,
"label": label,
})
} else {
green := color.New(color.FgGreen).SprintFunc()
verb := "Added"
prep := "to"
if operation == "removed" {
verb = "Removed"
prep = "from"
}
fmt.Printf("%s %s label '%s' %s %s\n", green("✓"), verb, label, prep, issueID)
}
}
if len(issueIDs) > 0 && daemonClient == nil {
markDirtyAndScheduleFlush()
}
if jsonOutput {
outputJSON(map[string]interface{}{
"status": operation,
"issue_id": issueID,
"label": label,
})
return
if jsonOutput && len(results) > 0 {
outputJSON(results)
}
green := color.New(color.FgGreen).SprintFunc()
// Capitalize first letter manually (strings.Title is deprecated)
capitalizedOp := strings.ToUpper(operation[:1]) + operation[1:]
fmt.Printf("%s %s label '%s' to %s\n", green("✓"), capitalizedOp, label, issueID)
}
var labelAddCmd = &cobra.Command{
@@ -74,48 +71,17 @@ var labelAddCmd = &cobra.Command{
Short: "Add a label to one or more issues",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
// Last arg is the label, everything before is issue IDs
label := args[len(args)-1]
issueIDs := args[:len(args)-1]
ctx := context.Background()
results := []map[string]interface{}{}
for _, issueID := range issueIDs {
var err error
if daemonClient != nil {
_, err = daemonClient.AddLabel(&rpc.LabelAddArgs{
ID: issueID,
Label: label,
})
} else {
err = store.AddLabel(ctx, issueID, label, actor)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding label to %s: %v\n", issueID, err)
continue
}
if jsonOutput {
results = append(results, map[string]interface{}{
"status": "added",
"issue_id": issueID,
"label": label,
})
} else {
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Added label '%s' to %s\n", green("✓"), label, issueID)
}
}
if len(issueIDs) > 0 && daemonClient == nil {
markDirtyAndScheduleFlush()
}
if jsonOutput && len(results) > 0 {
outputJSON(results)
}
processBatchLabelOperation(issueIDs, label, "added",
func(issueID, lbl string) error {
_, err := daemonClient.AddLabel(&rpc.LabelAddArgs{ID: issueID, Label: lbl})
return err
},
func(ctx context.Context, issueID, lbl, act string) error {
return store.AddLabel(ctx, issueID, lbl, act)
})
},
}
@@ -124,48 +90,17 @@ var labelRemoveCmd = &cobra.Command{
Short: "Remove a label from one or more issues",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
// Last arg is the label, everything before is issue IDs
label := args[len(args)-1]
issueIDs := args[:len(args)-1]
ctx := context.Background()
results := []map[string]interface{}{}
for _, issueID := range issueIDs {
var err error
if daemonClient != nil {
_, err = daemonClient.RemoveLabel(&rpc.LabelRemoveArgs{
ID: issueID,
Label: label,
})
} else {
err = store.RemoveLabel(ctx, issueID, label, actor)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error removing label from %s: %v\n", issueID, err)
continue
}
if jsonOutput {
results = append(results, map[string]interface{}{
"status": "removed",
"issue_id": issueID,
"label": label,
})
} else {
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Removed label '%s' from %s\n", green("✓"), label, issueID)
}
}
if len(issueIDs) > 0 && daemonClient == nil {
markDirtyAndScheduleFlush()
}
if jsonOutput && len(results) > 0 {
outputJSON(results)
}
processBatchLabelOperation(issueIDs, label, "removed",
func(issueID, lbl string) error {
_, err := daemonClient.RemoveLabel(&rpc.LabelRemoveArgs{ID: issueID, Label: lbl})
return err
},
func(ctx context.Context, issueID, lbl, act string) error {
return store.RemoveLabel(ctx, issueID, lbl, act)
})
},
}
+213 -297
View File
@@ -48,6 +48,9 @@ const (
FallbackFlagNoDaemon = "flag_no_daemon"
FallbackConnectFailed = "connect_failed"
FallbackHealthFailed = "health_failed"
cmdDaemon = "daemon"
cmdImport = "import"
statusHealthy = "healthy"
FallbackAutoStartDisabled = "auto_start_disabled"
FallbackAutoStartFailed = "auto_start_failed"
FallbackDaemonUnsupported = "daemon_unsupported"
@@ -109,7 +112,7 @@ var rootCmd = &cobra.Command{
}
// Skip database initialization for commands that don't need a database
if cmd.Name() == "init" || cmd.Name() == "daemon" || cmd.Name() == "help" || cmd.Name() == "version" || cmd.Name() == "quickstart" {
if cmd.Name() == "init" || cmd.Name() == cmdDaemon || cmd.Name() == "help" || cmd.Name() == "version" || cmd.Name() == "quickstart" {
return
}
@@ -140,7 +143,7 @@ var rootCmd = &cobra.Command{
// Special case for import: if we found a database but there's a local .beads/
// directory without a database, prefer creating a local database
if cmd.Name() == "import" && localBeadsDir != "" {
if cmd.Name() == cmdImport && localBeadsDir != "" {
if _, err := os.Stat(localBeadsDir); err == nil {
// Check if found database is NOT in the local .beads/ directory
if !strings.HasPrefix(dbPath, localBeadsDir+string(filepath.Separator)) {
@@ -151,7 +154,7 @@ var rootCmd = &cobra.Command{
}
} else {
// For import command, allow creating database if .beads/ directory exists
if cmd.Name() == "import" && localBeadsDir != "" {
if cmd.Name() == cmdImport && localBeadsDir != "" {
if _, err := os.Stat(localBeadsDir); err == nil {
// .beads/ directory exists - set dbPath for import to create
dbPath = filepath.Join(localBeadsDir, "vc.db")
@@ -211,7 +214,7 @@ var rootCmd = &cobra.Command{
// Perform health check
health, healthErr := client.Health()
if healthErr == nil && health.Status == "healthy" {
if healthErr == nil && health.Status == statusHealthy {
// Check version compatibility
if !health.Compatible {
if os.Getenv("BD_DEBUG") != "" {
@@ -230,9 +233,9 @@ var rootCmd = &cobra.Command{
client.SetDatabasePath(absDBPath)
}
health, healthErr = client.Health()
if healthErr == nil && health.Status == "healthy" {
if healthErr == nil && health.Status == statusHealthy {
daemonClient = client
daemonStatus.Mode = "daemon"
daemonStatus.Mode = cmdDaemon
daemonStatus.Connected = true
daemonStatus.Degraded = false
daemonStatus.Health = health.Status
@@ -251,7 +254,7 @@ var rootCmd = &cobra.Command{
} else {
// Daemon is healthy and compatible - use it
daemonClient = client
daemonStatus.Mode = "daemon"
daemonStatus.Mode = cmdDaemon
daemonStatus.Connected = true
daemonStatus.Degraded = false
daemonStatus.Health = health.Status
@@ -309,9 +312,9 @@ var rootCmd = &cobra.Command{
// Check health of auto-started daemon
health, healthErr := client.Health()
if healthErr == nil && health.Status == "healthy" {
if healthErr == nil && health.Status == statusHealthy {
daemonClient = client
daemonStatus.Mode = "daemon"
daemonStatus.Mode = cmdDaemon
daemonStatus.Connected = true
daemonStatus.Degraded = false
daemonStatus.AutoStartSucceeded = true
@@ -487,96 +490,9 @@ func shouldAutoStartDaemon() bool {
func shouldUseGlobalDaemon() bool {
// Global daemon support is deprecated
// Always use local daemon (per-project .beads/ socket)
return false
// Previously supported BEADS_PREFER_GLOBAL_DAEMON env var, but global
// daemon has issues with multi-workspace git workflows
// Heuristic: detect multiple beads repositories
home, err := os.UserHomeDir()
if err != nil {
return false
}
// Count .beads directories under home
repoCount := 0
maxDepth := 5 // Don't scan too deep
var countRepos func(string, int) error
countRepos = func(dir string, depth int) error {
if depth > maxDepth || repoCount > 1 {
return filepath.SkipDir
}
entries, err := os.ReadDir(dir)
if err != nil {
return nil // Skip directories we can't read
}
for _, entry := range entries {
if !entry.IsDir() {
continue
}
name := entry.Name()
// Skip hidden dirs except .beads
if strings.HasPrefix(name, ".") && name != ".beads" {
continue
}
// Skip common large directories
if name == "node_modules" || name == "vendor" || name == "target" || name == ".git" {
continue
}
path := filepath.Join(dir, name)
// Check if this is a .beads directory with a database
if name == ".beads" {
dbPath := filepath.Join(path, "db.sqlite")
if _, err := os.Stat(dbPath); err == nil {
repoCount++
if repoCount > 1 {
return filepath.SkipDir
}
}
continue
}
// Recurse into subdirectories
if depth < maxDepth {
_ = countRepos(path, depth+1)
}
}
return nil
}
// Scan common project directories
projectDirs := []string{
filepath.Join(home, "src"),
filepath.Join(home, "projects"),
filepath.Join(home, "code"),
filepath.Join(home, "workspace"),
filepath.Join(home, "dev"),
}
for _, dir := range projectDirs {
if _, err := os.Stat(dir); err == nil {
_ = countRepos(dir, 0)
if repoCount > 1 {
break
}
}
}
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: found %d beads repositories, prefer global: %v\n", repoCount, repoCount > 1)
}
// Use global daemon if we found more than 1 repository (multi-repo workflow)
// This prevents concurrency issues when multiple repos are being worked on
return repoCount > 1
return false
}
// restartDaemonForVersionMismatch stops the old daemon and starts a new one
@@ -629,11 +545,11 @@ func restartDaemonForVersionMismatch() bool {
// Force kill if still running
if isRunning, _ := isDaemonRunning(pidFile); isRunning {
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: force killing old daemon\n")
}
_ = process.Kill()
forcedKill = true
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: force killing old daemon\n")
}
_ = process.Kill()
forcedKill = true
}
}
@@ -738,7 +654,7 @@ func tryAutoStartDaemon(socketPath string) bool {
if lockPID, err := readPIDFromFile(lockPath); err == nil {
if !isPIDAlive(lockPID) {
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: lock is stale (PID %d dead), removing and retrying\n", lockPID)
fmt.Fprintf(os.Stderr, "Debug: lock is stale (PID %d dead), removing and retrying\n", lockPID)
}
_ = os.Remove(lockPath)
// Retry once
@@ -778,11 +694,11 @@ func tryAutoStartDaemon(socketPath string) bool {
// Socket is stale (connect failed and PID dead/missing) - safe to remove
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: socket is stale, cleaning up\n")
fmt.Fprintf(os.Stderr, "Debug: socket is stale, cleaning up\n")
}
_ = os.Remove(socketPath)
if pidFile != "" {
_ = os.Remove(pidFile)
_ = os.Remove(pidFile)
}
}
@@ -1100,10 +1016,10 @@ func autoImportIfNewer() {
// Use shared import logic (bd-157)
opts := ImportOptions{
ResolveCollisions: true, // Auto-import always resolves collisions
DryRun: false,
SkipUpdate: false,
Strict: false,
ResolveCollisions: true, // Auto-import always resolves collisions
DryRun: false,
SkipUpdate: false,
Strict: false,
SkipPrefixValidation: true, // Auto-import is lenient about prefixes
}
@@ -1928,100 +1844,100 @@ var showCmd = &cobra.Command{
fmt.Println("\n" + strings.Repeat("─", 60))
}
// Parse response and use existing formatting code
type IssueDetails struct {
types.Issue
Labels []string `json:"labels,omitempty"`
Dependencies []*types.Issue `json:"dependencies,omitempty"`
Dependents []*types.Issue `json:"dependents,omitempty"`
}
var details 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
// Parse response and use existing formatting code
type IssueDetails struct {
types.Issue
Labels []string `json:"labels,omitempty"`
Dependencies []*types.Issue `json:"dependencies,omitempty"`
Dependents []*types.Issue `json:"dependents,omitempty"`
}
var details 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
cyan := color.New(color.FgCyan).SprintFunc()
cyan := color.New(color.FgCyan).SprintFunc()
// Format output (same as direct mode below)
tierEmoji := ""
statusSuffix := ""
if issue.CompactionLevel == 1 {
tierEmoji = " 🗜️"
} else if issue.CompactionLevel == 2 {
tierEmoji = " 📦"
}
if issue.CompactionLevel > 0 {
statusSuffix = fmt.Sprintf(" (compacted L%d)", issue.CompactionLevel)
}
// Format output (same as direct mode below)
tierEmoji := ""
statusSuffix := ""
switch issue.CompactionLevel {
case 1:
tierEmoji = " 🗜️"
statusSuffix = " (compacted L1)"
case 2:
tierEmoji = " 📦"
statusSuffix = " (compacted L2)"
}
fmt.Printf("\n%s: %s%s\n", cyan(issue.ID), issue.Title, tierEmoji)
fmt.Printf("Status: %s%s\n", issue.Status, statusSuffix)
fmt.Printf("Priority: P%d\n", issue.Priority)
fmt.Printf("Type: %s\n", issue.IssueType)
if issue.Assignee != "" {
fmt.Printf("Assignee: %s\n", issue.Assignee)
}
if issue.EstimatedMinutes != nil {
fmt.Printf("Estimated: %d minutes\n", *issue.EstimatedMinutes)
}
fmt.Printf("Created: %s\n", issue.CreatedAt.Format("2006-01-02 15:04"))
fmt.Printf("Updated: %s\n", issue.UpdatedAt.Format("2006-01-02 15:04"))
fmt.Printf("\n%s: %s%s\n", cyan(issue.ID), issue.Title, tierEmoji)
fmt.Printf("Status: %s%s\n", issue.Status, statusSuffix)
fmt.Printf("Priority: P%d\n", issue.Priority)
fmt.Printf("Type: %s\n", issue.IssueType)
if issue.Assignee != "" {
fmt.Printf("Assignee: %s\n", issue.Assignee)
}
if issue.EstimatedMinutes != nil {
fmt.Printf("Estimated: %d minutes\n", *issue.EstimatedMinutes)
}
fmt.Printf("Created: %s\n", issue.CreatedAt.Format("2006-01-02 15:04"))
fmt.Printf("Updated: %s\n", issue.UpdatedAt.Format("2006-01-02 15:04"))
// Show compaction status
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("📊 Original: %d bytes | Compressed: %d bytes (%.0f%% reduction)\n",
issue.OriginalSize, currentSize, reduction)
// Show compaction status
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("📊 Original: %d bytes | Compressed: %d bytes (%.0f%% reduction)\n",
issue.OriginalSize, currentSize, reduction)
}
}
tierEmoji2 := "🗜️"
if issue.CompactionLevel == 2 {
tierEmoji2 = "📦"
}
compactedDate := ""
if issue.CompactedAt != nil {
compactedDate = issue.CompactedAt.Format("2006-01-02")
}
fmt.Printf("%s Compacted: %s (Tier %d)\n", tierEmoji2, compactedDate, issue.CompactionLevel)
}
if issue.Description != "" {
fmt.Printf("\nDescription:\n%s\n", issue.Description)
}
if issue.Design != "" {
fmt.Printf("\nDesign:\n%s\n", issue.Design)
}
if issue.Notes != "" {
fmt.Printf("\nNotes:\n%s\n", issue.Notes)
}
if issue.AcceptanceCriteria != "" {
fmt.Printf("\nAcceptance Criteria:\n%s\n", issue.AcceptanceCriteria)
}
if len(details.Labels) > 0 {
fmt.Printf("\nLabels: %v\n", details.Labels)
}
if len(details.Dependencies) > 0 {
fmt.Printf("\nDepends on (%d):\n", len(details.Dependencies))
for _, dep := range details.Dependencies {
fmt.Printf(" → %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
tierEmoji2 := "🗜️"
if issue.CompactionLevel == 2 {
tierEmoji2 = "📦"
}
compactedDate := ""
if issue.CompactedAt != nil {
compactedDate = issue.CompactedAt.Format("2006-01-02")
}
fmt.Printf("%s Compacted: %s (Tier %d)\n", tierEmoji2, compactedDate, issue.CompactionLevel)
}
if issue.Description != "" {
fmt.Printf("\nDescription:\n%s\n", issue.Description)
}
if issue.Design != "" {
fmt.Printf("\nDesign:\n%s\n", issue.Design)
}
if issue.Notes != "" {
fmt.Printf("\nNotes:\n%s\n", issue.Notes)
}
if issue.AcceptanceCriteria != "" {
fmt.Printf("\nAcceptance Criteria:\n%s\n", issue.AcceptanceCriteria)
}
if len(details.Labels) > 0 {
fmt.Printf("\nLabels: %v\n", details.Labels)
}
if len(details.Dependencies) > 0 {
fmt.Printf("\nDepends on (%d):\n", len(details.Dependencies))
for _, dep := range details.Dependencies {
fmt.Printf(" → %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
if len(details.Dependents) > 0 {
fmt.Printf("\nBlocks (%d):\n", len(details.Dependents))
for _, dep := range details.Dependents {
fmt.Printf(" ← %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
}
if len(details.Dependents) > 0 {
fmt.Printf("\nBlocks (%d):\n", len(details.Dependents))
for _, dep := range details.Dependents {
fmt.Printf(" ← %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
fmt.Println()
}
@@ -2069,94 +1985,94 @@ var showCmd = &cobra.Command{
fmt.Println("\n" + strings.Repeat("─", 60))
}
cyan := color.New(color.FgCyan).SprintFunc()
cyan := color.New(color.FgCyan).SprintFunc()
// Add compaction emoji to title line
tierEmoji := ""
statusSuffix := ""
if issue.CompactionLevel == 1 {
tierEmoji = " 🗜️"
} else if issue.CompactionLevel == 2 {
tierEmoji = " 📦"
}
if issue.CompactionLevel > 0 {
statusSuffix = fmt.Sprintf(" (compacted L%d)", issue.CompactionLevel)
}
fmt.Printf("\n%s: %s%s\n", cyan(issue.ID), issue.Title, tierEmoji)
fmt.Printf("Status: %s%s\n", issue.Status, statusSuffix)
fmt.Printf("Priority: P%d\n", issue.Priority)
fmt.Printf("Type: %s\n", issue.IssueType)
if issue.Assignee != "" {
fmt.Printf("Assignee: %s\n", issue.Assignee)
}
if issue.EstimatedMinutes != nil {
fmt.Printf("Estimated: %d minutes\n", *issue.EstimatedMinutes)
}
fmt.Printf("Created: %s\n", issue.CreatedAt.Format("2006-01-02 15:04"))
fmt.Printf("Updated: %s\n", issue.UpdatedAt.Format("2006-01-02 15:04"))
// Show compaction status footer
if issue.CompactionLevel > 0 {
tierEmoji := "🗜️"
if issue.CompactionLevel == 2 {
tierEmoji = "📦"
// Add compaction emoji to title line
tierEmoji := ""
statusSuffix := ""
switch issue.CompactionLevel {
case 1:
tierEmoji = " 🗜️"
statusSuffix = " (compacted L1)"
case 2:
tierEmoji = " 📦"
statusSuffix = " (compacted L2)"
}
tierName := fmt.Sprintf("Tier %d", issue.CompactionLevel)
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("📊 Original: %d bytes | Compressed: %d bytes (%.0f%% reduction)\n",
issue.OriginalSize, currentSize, reduction)
fmt.Printf("\n%s: %s%s\n", cyan(issue.ID), issue.Title, tierEmoji)
fmt.Printf("Status: %s%s\n", issue.Status, statusSuffix)
fmt.Printf("Priority: P%d\n", issue.Priority)
fmt.Printf("Type: %s\n", issue.IssueType)
if issue.Assignee != "" {
fmt.Printf("Assignee: %s\n", issue.Assignee)
}
if issue.EstimatedMinutes != nil {
fmt.Printf("Estimated: %d minutes\n", *issue.EstimatedMinutes)
}
fmt.Printf("Created: %s\n", issue.CreatedAt.Format("2006-01-02 15:04"))
fmt.Printf("Updated: %s\n", issue.UpdatedAt.Format("2006-01-02 15:04"))
// Show compaction status footer
if issue.CompactionLevel > 0 {
tierEmoji := "🗜️"
if issue.CompactionLevel == 2 {
tierEmoji = "📦"
}
tierName := fmt.Sprintf("Tier %d", issue.CompactionLevel)
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("📊 Original: %d bytes | Compressed: %d bytes (%.0f%% reduction)\n",
issue.OriginalSize, currentSize, reduction)
}
}
compactedDate := ""
if issue.CompactedAt != nil {
compactedDate = issue.CompactedAt.Format("2006-01-02")
}
fmt.Printf("%s Compacted: %s (%s)\n", tierEmoji, compactedDate, tierName)
}
if issue.Description != "" {
fmt.Printf("\nDescription:\n%s\n", issue.Description)
}
if issue.Design != "" {
fmt.Printf("\nDesign:\n%s\n", issue.Design)
}
if issue.Notes != "" {
fmt.Printf("\nNotes:\n%s\n", issue.Notes)
}
if issue.AcceptanceCriteria != "" {
fmt.Printf("\nAcceptance Criteria:\n%s\n", issue.AcceptanceCriteria)
}
// Show labels
labels, _ := store.GetLabels(ctx, issue.ID)
if len(labels) > 0 {
fmt.Printf("\nLabels: %v\n", labels)
}
// Show dependencies
deps, _ := store.GetDependencies(ctx, issue.ID)
if len(deps) > 0 {
fmt.Printf("\nDepends on (%d):\n", len(deps))
for _, dep := range deps {
fmt.Printf(" → %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
compactedDate := ""
if issue.CompactedAt != nil {
compactedDate = issue.CompactedAt.Format("2006-01-02")
// Show dependents
dependents, _ := store.GetDependents(ctx, issue.ID)
if len(dependents) > 0 {
fmt.Printf("\nBlocks (%d):\n", len(dependents))
for _, dep := range dependents {
fmt.Printf(" ← %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
fmt.Printf("%s Compacted: %s (%s)\n", tierEmoji, compactedDate, tierName)
}
if issue.Description != "" {
fmt.Printf("\nDescription:\n%s\n", issue.Description)
}
if issue.Design != "" {
fmt.Printf("\nDesign:\n%s\n", issue.Design)
}
if issue.Notes != "" {
fmt.Printf("\nNotes:\n%s\n", issue.Notes)
}
if issue.AcceptanceCriteria != "" {
fmt.Printf("\nAcceptance Criteria:\n%s\n", issue.AcceptanceCriteria)
}
// Show labels
labels, _ := store.GetLabels(ctx, issue.ID)
if len(labels) > 0 {
fmt.Printf("\nLabels: %v\n", labels)
}
// Show dependencies
deps, _ := store.GetDependencies(ctx, issue.ID)
if len(deps) > 0 {
fmt.Printf("\nDepends on (%d):\n", len(deps))
for _, dep := range deps {
fmt.Printf(" → %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
// Show dependents
dependents, _ := store.GetDependents(ctx, issue.ID)
if len(dependents) > 0 {
fmt.Printf("\nBlocks (%d):\n", len(dependents))
for _, dep := range dependents {
fmt.Printf(" ← %s: %s [P%d]\n", dep.ID, dep.Title, dep.Priority)
}
}
// Show comments
comments, _ := store.GetIssueComments(ctx, issue.ID)
@@ -2200,30 +2116,30 @@ var updateCmd = &cobra.Command{
updates["title"] = title
}
if cmd.Flags().Changed("assignee") {
assignee, _ := cmd.Flags().GetString("assignee")
updates["assignee"] = assignee
assignee, _ := cmd.Flags().GetString("assignee")
updates["assignee"] = assignee
}
if cmd.Flags().Changed("description") {
description, _ := cmd.Flags().GetString("description")
updates["description"] = description
description, _ := cmd.Flags().GetString("description")
updates["description"] = description
}
if cmd.Flags().Changed("design") {
design, _ := cmd.Flags().GetString("design")
updates["design"] = design
}
if cmd.Flags().Changed("design") {
design, _ := cmd.Flags().GetString("design")
updates["design"] = design
}
if cmd.Flags().Changed("notes") {
notes, _ := cmd.Flags().GetString("notes")
updates["notes"] = notes
}
if cmd.Flags().Changed("acceptance") || cmd.Flags().Changed("acceptance-criteria") {
var acceptanceCriteria string
if cmd.Flags().Changed("acceptance") {
acceptanceCriteria, _ = cmd.Flags().GetString("acceptance")
} else {
acceptanceCriteria, _ = cmd.Flags().GetString("acceptance-criteria")
var acceptanceCriteria string
if cmd.Flags().Changed("acceptance") {
acceptanceCriteria, _ = cmd.Flags().GetString("acceptance")
} else {
acceptanceCriteria, _ = cmd.Flags().GetString("acceptance-criteria")
}
updates["acceptance_criteria"] = acceptanceCriteria
}
updates["acceptance_criteria"] = acceptanceCriteria
}
if cmd.Flags().Changed("external-ref") {
externalRef, _ := cmd.Flags().GetString("external-ref")
updates["external_ref"] = externalRef
@@ -2251,14 +2167,14 @@ var updateCmd = &cobra.Command{
updateArgs.Title = &title
}
if assignee, ok := updates["assignee"].(string); ok {
updateArgs.Assignee = &assignee
updateArgs.Assignee = &assignee
}
if description, ok := updates["description"].(string); ok {
updateArgs.Description = &description
updateArgs.Description = &description
}
if design, ok := updates["design"].(string); ok {
updateArgs.Design = &design
}
if design, ok := updates["design"].(string); ok {
updateArgs.Design = &design
}
if notes, ok := updates["notes"].(string); ok {
updateArgs.Notes = &notes
}
-7
View File
@@ -7,7 +7,6 @@ import (
"os"
"regexp"
"sort"
"strconv"
"strings"
"github.com/fatih/color"
@@ -358,12 +357,6 @@ func renumberDependencies(ctx context.Context, idMapping map[string]string, allD
return nil
}
// Helper to extract numeric part from issue ID
func extractNumber(issueID, prefix string) (int, error) {
numStr := strings.TrimPrefix(issueID, prefix+"-")
return strconv.Atoi(numStr)
}
func init() {
renumberCmd.Flags().Bool("dry-run", false, "Preview changes without applying them")
renumberCmd.Flags().Bool("force", false, "Actually perform the renumbering")
+6
View File
@@ -13,18 +13,21 @@ const (
defaultConcurrency = 5
)
// CompactConfig holds configuration for the compaction process.
type CompactConfig struct {
APIKey string
Concurrency int
DryRun bool
}
// Compactor handles issue compaction using AI summarization.
type Compactor struct {
store *sqlite.SQLiteStorage
haiku *HaikuClient
config *CompactConfig
}
// New creates a new Compactor instance with the given configuration.
func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Compactor, error) {
if config == nil {
config = &CompactConfig{
@@ -58,6 +61,7 @@ func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Co
}, nil
}
// CompactResult holds the outcome of a compaction operation.
type CompactResult struct {
IssueID string
OriginalSize int
@@ -65,6 +69,7 @@ type CompactResult struct {
Err error
}
// CompactTier1 performs tier-1 compaction on a single issue using AI summarization.
func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
if ctx.Err() != nil {
return ctx.Err()
@@ -137,6 +142,7 @@ func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
return nil
}
// CompactTier1Batch performs tier-1 compaction on multiple issues in a single batch.
func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]*CompactResult, error) {
if len(issueIDs) == 0 {
return nil, nil
+3 -2
View File
@@ -298,11 +298,12 @@ func TestCompactTier1Batch_WithIneligible(t *testing.T) {
}
for _, result := range results {
if result.IssueID == openIssue.ID {
switch result.IssueID {
case openIssue.ID:
if result.Err == nil {
t.Error("expected error for ineligible issue")
}
} else if result.IssueID == closedIssue.ID {
case closedIssue.ID:
if result.Err != nil {
t.Errorf("unexpected error for eligible issue: %v", result.Err)
}
+1
View File
@@ -22,6 +22,7 @@ const (
initialBackoff = 1 * time.Second
)
// ErrAPIKeyRequired is returned when an API key is needed but not provided.
var ErrAPIKeyRequired = errors.New("API key required")
// HaikuClient wraps the Anthropic API for issue summarization.
+1 -1
View File
@@ -193,7 +193,7 @@ func TestCallWithRetry_ContextCancellation(t *testing.T) {
_, err = client.callWithRetry(ctx, "test prompt")
if err == nil {
t.Fatal("expected error when context is cancelled")
t.Fatal("expected error when context is canceled")
}
if err != context.Canceled {
t.Errorf("expected context.Canceled error, got: %v", err)
+2 -2
View File
@@ -145,8 +145,8 @@ func Set(key string, value interface{}) {
// return v.BindPFlag(key, flag)
// }
// ConfigFileUsed returns the path to the config file being used
func ConfigFileUsed() string {
// FileUsed returns the path to the active configuration file.
func FileUsed() string {
if v == nil {
return ""
}
+1 -1
View File
@@ -218,7 +218,7 @@ func (c *Client) Update(args *UpdateArgs) (*Response, error) {
return c.Execute(OpUpdate, args)
}
// Close closes an issue via the daemon (operation, not connection)
// CloseIssue marks an issue as closed via the daemon.
func (c *Client) CloseIssue(args *CloseArgs) (*Response, error) {
return c.Execute(OpClose, args)
}
+31 -71
View File
@@ -28,6 +28,10 @@ import (
// It's set as a var so it can be initialized from main
var ServerVersion = "0.9.10"
const (
statusUnhealthy = "unhealthy"
)
// normalizeLabels trims whitespace, removes empty strings, and deduplicates labels
func normalizeLabels(ss []string) []string {
seen := make(map[string]struct{})
@@ -699,13 +703,6 @@ func strValue(p *string) string {
return *p
}
func strPtr(s string) *string {
if s == "" {
return nil
}
return &s
}
func updatesFromArgs(a UpdateArgs) map[string]interface{} {
u := map[string]interface{}{}
if a.Title != nil {
@@ -780,7 +777,7 @@ func (s *Server) handleHealth(req *Request) Response {
dbResponseMs := time.Since(start).Seconds() * 1000
if pingErr != nil {
status = "unhealthy"
status = statusUnhealthy
dbError = pingErr.Error()
} else if dbResponseMs > 500 {
status = "degraded"
@@ -1270,12 +1267,13 @@ func (s *Server) handleDepAdd(req *Request) Response {
return Response{Success: true}
}
func (s *Server) handleDepRemove(req *Request) Response {
var depArgs DepRemoveArgs
if err := json.Unmarshal(req.Args, &depArgs); err != nil {
// Generic handler for simple store operations with standard error handling
func (s *Server) handleSimpleStoreOp(req *Request, argsPtr interface{}, argDesc string,
opFunc func(context.Context, storage.Storage, string) error) Response {
if err := json.Unmarshal(req.Args, argsPtr); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("invalid dep remove args: %v", err),
Error: fmt.Sprintf("invalid %s args: %v", argDesc, err),
}
}
@@ -1288,70 +1286,35 @@ func (s *Server) handleDepRemove(req *Request) Response {
}
ctx := s.reqCtx(req)
if err := store.RemoveDependency(ctx, depArgs.FromID, depArgs.ToID, s.reqActor(req)); err != nil {
if err := opFunc(ctx, store, s.reqActor(req)); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("failed to remove dependency: %v", err),
Error: fmt.Sprintf("failed to %s: %v", argDesc, err),
}
}
return Response{Success: true}
}
func (s *Server) handleDepRemove(req *Request) Response {
var depArgs DepRemoveArgs
return s.handleSimpleStoreOp(req, &depArgs, "dep remove", func(ctx context.Context, store storage.Storage, actor string) error {
return store.RemoveDependency(ctx, depArgs.FromID, depArgs.ToID, actor)
})
}
func (s *Server) handleLabelAdd(req *Request) Response {
var labelArgs LabelAddArgs
if err := json.Unmarshal(req.Args, &labelArgs); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("invalid label add args: %v", err),
}
}
store, err := s.getStorageForRequest(req)
if err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("storage error: %v", err),
}
}
ctx := s.reqCtx(req)
if err := store.AddLabel(ctx, labelArgs.ID, labelArgs.Label, s.reqActor(req)); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("failed to add label: %v", err),
}
}
return Response{Success: true}
return s.handleSimpleStoreOp(req, &labelArgs, "label add", func(ctx context.Context, store storage.Storage, actor string) error {
return store.AddLabel(ctx, labelArgs.ID, labelArgs.Label, actor)
})
}
func (s *Server) handleLabelRemove(req *Request) Response {
var labelArgs LabelRemoveArgs
if err := json.Unmarshal(req.Args, &labelArgs); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("invalid label remove args: %v", err),
}
}
store, err := s.getStorageForRequest(req)
if err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("storage error: %v", err),
}
}
ctx := s.reqCtx(req)
if err := store.RemoveLabel(ctx, labelArgs.ID, labelArgs.Label, s.reqActor(req)); err != nil {
return Response{
Success: false,
Error: fmt.Sprintf("failed to remove label: %v", err),
}
}
return Response{Success: true}
return s.handleSimpleStoreOp(req, &labelArgs, "label remove", func(ctx context.Context, store storage.Storage, actor string) error {
return store.RemoveLabel(ctx, labelArgs.ID, labelArgs.Label, actor)
})
}
func (s *Server) handleCommentList(req *Request) Response {
@@ -1443,11 +1406,7 @@ func (s *Server) handleBatch(req *Request) Response {
resp := s.handleRequest(subReq)
results = append(results, BatchResult{
Success: resp.Success,
Data: resp.Data,
Error: resp.Error,
})
results = append(results, BatchResult(resp))
if !resp.Success {
break
@@ -1929,7 +1888,8 @@ func (s *Server) handleCompact(req *Request) Response {
if args.All {
var candidates []*sqlite.CompactionCandidate
if args.Tier == 1 {
switch args.Tier {
case 1:
tier1, err := sqliteStore.GetTier1Candidates(ctx)
if err != nil {
return Response{
@@ -1938,7 +1898,7 @@ func (s *Server) handleCompact(req *Request) Response {
}
}
candidates = tier1
} else if args.Tier == 2 {
case 2:
tier2, err := sqliteStore.GetTier2Candidates(ctx)
if err != nil {
return Response{
@@ -1947,7 +1907,7 @@ func (s *Server) handleCompact(req *Request) Response {
}
}
candidates = tier2
} else {
default:
return Response{
Success: false,
Error: fmt.Sprintf("invalid tier: %d (must be 1 or 2)", args.Tier),
@@ -2201,7 +2161,7 @@ func (s *Server) handleExport(req *Request) Response {
result := map[string]interface{}{
"exported_count": len(exportedIDs),
"path": exportArgs.JSONLPath,
"path": exportArgs.JSONLPath,
}
data, _ := json.Marshal(result)
return Response{
+3 -19
View File
@@ -128,14 +128,6 @@ func (s *SQLiteStorage) GetTier2Candidates(ctx context.Context) ([]*CompactionCa
daysStr = "90"
}
depthStr, err := s.GetConfig(ctx, "compact_tier2_dep_levels")
if err != nil {
return nil, fmt.Errorf("failed to get compact_tier2_dep_levels: %w", err)
}
if depthStr == "" {
depthStr = "5"
}
commitsStr, err := s.GetConfig(ctx, "compact_tier2_commits")
if err != nil {
return nil, fmt.Errorf("failed to get compact_tier2_commits: %w", err)
@@ -227,20 +219,12 @@ func (s *SQLiteStorage) CheckEligibility(ctx context.Context, issueID string, ti
return false, "issue has no closed_at timestamp", nil
}
if tier == 1 {
switch tier {
case 1:
if compactionLevel != 0 {
return false, "issue is already compacted", nil
}
// Check if closed long enough
daysStr, err := s.GetConfig(ctx, "compact_tier1_days")
if err != nil {
return false, "", fmt.Errorf("failed to get compact_tier1_days: %w", err)
}
if daysStr == "" {
daysStr = "30"
}
// Check if it appears in tier1 candidates
candidates, err := s.GetTier1Candidates(ctx)
if err != nil {
@@ -255,7 +239,7 @@ func (s *SQLiteStorage) CheckEligibility(ctx context.Context, issueID string, ti
return false, "issue has open dependents or not closed long enough", nil
} else if tier == 2 {
case 2:
if compactionLevel != 1 {
return false, "issue must be at compaction level 1 for tier 2", nil
}