Skip to content

Commit b9e96c5

Browse files
committed
fix: updating a large amount of cli code for canary
1 parent 9e89e3b commit b9e96c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2556
-2364
lines changed

cmd/canary/bug.go renamed to cli/bug/bug.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For more details, see the LICENSE file in the root directory of this
44
// source code repository or contact Developer Network at info@devnw.com.
55

6-
package main
6+
package bug
77

88
import (
99
"encoding/json"
@@ -19,7 +19,7 @@ import (
1919
"go.devnw.com/canary/internal/storage"
2020
)
2121

22-
var bugCmd = &cobra.Command{
22+
var BugCmd = &cobra.Command{
2323
Use: "bug",
2424
Short: "Manage BUG-* CANARY tokens for tracking defects",
2525
Long: `Bug command manages BUG-* CANARY tokens for defect tracking.
@@ -588,10 +588,10 @@ func createBugCanaryComment(token *storage.Token, severity, priority string) err
588588

589589
func init() {
590590
// Add subcommands
591-
bugCmd.AddCommand(bugListCmd)
592-
bugCmd.AddCommand(bugCreateCmd)
593-
bugCmd.AddCommand(bugUpdateCmd)
594-
bugCmd.AddCommand(bugShowCmd)
591+
BugCmd.AddCommand(bugListCmd)
592+
BugCmd.AddCommand(bugCreateCmd)
593+
BugCmd.AddCommand(bugUpdateCmd)
594+
BugCmd.AddCommand(bugShowCmd)
595595

596596
// List command flags
597597
bugListCmd.Flags().String("aspect", "", "Filter by aspect (API, CLI, Engine, Storage, etc.)")

cmd/canary/bug_integration_test.go renamed to cli/bug/bug_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For more details, see the LICENSE file in the root directory of this
44
// source code repository or contact Developer Network at info@devnw.com.
55

6-
package main
6+
package bug
77

88
import (
99
"bytes"

cmd/canary/bug_test.go renamed to cli/bug/bug_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For more details, see the LICENSE file in the root directory of this
44
// source code repository or contact Developer Network at info@devnw.com.
55

6-
package main
6+
package bug
77

88
import (
99
"path/filepath"

cli/checkpoint/checkpoint.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package checkpoint
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os/exec"
7+
"strings"
8+
9+
"github.com/spf13/cobra"
10+
"go.devnw.com/canary/internal/storage"
11+
"go.devnw.com/canary/cli/internal/utils"
12+
)
13+
14+
// CANARY: REQ=CBIN-128; FEATURE="CheckpointCmd"; ASPECT=CLI; STATUS=IMPL; OWNER=canary; UPDATED=2025-10-16
15+
var CheckpointCmd = &cobra.Command{
16+
Use: "checkpoint <name> [description]",
17+
Short: "Create a state snapshot checkpoint",
18+
Long: `Create a checkpoint to capture current state of all tokens.
19+
20+
Checkpoints include:
21+
- Counts by status (STUB, IMPL, TESTED, BENCHED)
22+
- Commit hash and timestamp
23+
- Full JSON snapshot of all tokens
24+
25+
Useful for tracking progress over time.`,
26+
Args: cobra.MinimumNArgs(1),
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
dbPath, _ := cmd.Flags().GetString("db")
29+
name := args[0]
30+
description := ""
31+
if len(args) > 1 {
32+
description = strings.Join(args[1:], " ")
33+
}
34+
35+
db, err := storage.Open(dbPath)
36+
if err != nil {
37+
return fmt.Errorf("open database: %w", err)
38+
}
39+
40+
defer db.Close()
41+
42+
// Get current commit hash
43+
commitHash := ""
44+
if gitCmd := exec.Command("git", "rev-parse", "HEAD"); gitCmd.Dir == "" {
45+
if output, err := gitCmd.Output(); err == nil {
46+
commitHash = strings.TrimSpace(string(output))
47+
}
48+
}
49+
50+
// Load project config for ID pattern filtering
51+
cfg, _ := utils.LoadProjectConfig()
52+
idPattern := ""
53+
if cfg != nil && cfg.Requirements.IDPattern != "" {
54+
idPattern = cfg.Requirements.IDPattern
55+
}
56+
57+
// Get all tokens for snapshot
58+
tokens, err := db.ListTokens(nil, idPattern, "", 0)
59+
if err != nil {
60+
return fmt.Errorf("get tokens: %w", err)
61+
}
62+
63+
snapshotJSON, err := json.Marshal(tokens)
64+
if err != nil {
65+
return fmt.Errorf("marshal snapshot: %w", err)
66+
}
67+
68+
if err := db.CreateCheckpoint(name, description, commitHash, string(snapshotJSON)); err != nil {
69+
return fmt.Errorf("create checkpoint: %w", err)
70+
}
71+
72+
fmt.Printf("✅ Created checkpoint: %s\n", name)
73+
if commitHash != "" {
74+
fmt.Printf("Commit: %s\n", commitHash[:8])
75+
}
76+
fmt.Printf("Tokens: %d\n", len(tokens))
77+
78+
return nil
79+
},
80+
}

cli/constitution/constitution.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package constitution
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/spf13/cobra"
9+
"go.devnw.com/canary/cli/internal/utils"
10+
)
11+
12+
// CANARY: REQ=CBIN-119; FEATURE="ConstitutionCmd"; ASPECT=CLI; STATUS=IMPL; OWNER=canary; UPDATED=2025-10-16
13+
var ConstitutionCmd = &cobra.Command{
14+
Use: "constitution [description]",
15+
Short: "Create or update project governing principles",
16+
Long: `Create or update the project's constitutional principles in .canary/memory/constitution.md.
17+
18+
If no arguments are provided, creates the default constitution.
19+
If arguments are provided, updates or adds specific principles.`,
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
constitutionPath := ".canary/memory/constitution.md"
22+
23+
if _, err := os.Stat(constitutionPath); os.IsNotExist(err) {
24+
// Read template from embedded FS
25+
content, err := utils.ReadEmbeddedFile("base/memory/constitution.md")
26+
if err != nil {
27+
return fmt.Errorf("read constitution template: %w", err)
28+
}
29+
30+
// Ensure directory exists
31+
if err := os.MkdirAll(filepath.Dir(constitutionPath), 0755); err != nil {
32+
return fmt.Errorf("create memory directory: %w", err)
33+
}
34+
35+
// Write constitution
36+
if err := os.WriteFile(constitutionPath, content, 0644); err != nil {
37+
return fmt.Errorf("write constitution: %w", err)
38+
}
39+
40+
fmt.Printf("✅ Created constitution at: %s\n", constitutionPath)
41+
fmt.Println("\nConstitutional Principles:")
42+
fmt.Println(" I. Requirement-First Development")
43+
fmt.Println(" II. Specification Discipline")
44+
fmt.Println(" III. Token-Driven Planning")
45+
fmt.Println(" IV. Test-First Imperative")
46+
fmt.Println(" V. Simplicity and Anti-Abstraction")
47+
fmt.Println(" VI. Integration-First Testing")
48+
fmt.Println(" VII. Documentation Currency")
49+
fmt.Println(" VIII. Continuous Improvement")
50+
fmt.Println(" IX. Amendment Process")
51+
} else {
52+
fmt.Printf("✅ Constitution already exists at: %s\n", constitutionPath)
53+
if len(args) > 0 {
54+
fmt.Println("\nTo update specific principles, edit the file directly.")
55+
}
56+
}
57+
58+
return nil
59+
},
60+
}

cli/create/create.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package create
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/spf13/cobra"
8+
"go.devnw.com/canary/internal/reqid"
9+
)
10+
11+
// CreateCmd generates a new CANARY token template
12+
var CreateCmd = &cobra.Command{
13+
Use: "create <req-id> <feature-name>",
14+
Short: "Generate a new CANARY token template",
15+
Long: `Create a properly formatted CANARY token for a new requirement.
16+
17+
Example:
18+
canary create CBIN-CLI-105 "UserProfile" --aspect CLI --status IMPL
19+
20+
Outputs a ready-to-paste CANARY token comment.`,
21+
Args: cobra.MinimumNArgs(2),
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
reqID := args[0]
24+
feature := args[1]
25+
26+
aspect, _ := cmd.Flags().GetString("aspect")
27+
status, _ := cmd.Flags().GetString("status")
28+
owner, _ := cmd.Flags().GetString("owner")
29+
test, _ := cmd.Flags().GetString("test")
30+
bench, _ := cmd.Flags().GetString("bench")
31+
32+
// Validate aspect
33+
if err := reqid.ValidateAspect(aspect); err != nil {
34+
return fmt.Errorf("invalid aspect: %w", err)
35+
}
36+
37+
// Normalize aspect to canonical form
38+
aspect = reqid.NormalizeAspect(aspect)
39+
40+
// Get today's date
41+
today := time.Now().UTC().Format("2006-01-02")
42+
43+
// Build token
44+
token := fmt.Sprintf("// CANARY: REQ=%s; FEATURE=\"%s\"; ASPECT=%s; STATUS=%s",
45+
reqID, feature, aspect, status)
46+
47+
if test != "" {
48+
token += fmt.Sprintf("; TEST=%s", test)
49+
}
50+
if bench != "" {
51+
token += fmt.Sprintf("; BENCH=%s", bench)
52+
}
53+
if owner != "" {
54+
token += fmt.Sprintf("; OWNER=%s", owner)
55+
}
56+
57+
token += fmt.Sprintf("; UPDATED=%s", today)
58+
59+
fmt.Println(token)
60+
fmt.Println("\n// Paste this above your implementation:")
61+
fmt.Printf("// func %s() { ... }\n", feature)
62+
63+
return nil
64+
},
65+
}

cli/db/db.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package db
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"go.devnw.com/canary/internal/storage"
8+
)
9+
10+
// CANARY: REQ=CBIN-129; FEATURE="MigrateCmd"; ASPECT=CLI; STATUS=IMPL; OWNER=canary; UPDATED=2025-10-16
11+
var MigrateCmd = &cobra.Command{
12+
Use: "migrate <steps>",
13+
Short: "Run database migrations",
14+
Long: `Apply database migrations to the CANARY database.
15+
16+
Steps can be:
17+
- "all" to migrate to the latest version
18+
- A positive integer to migrate forward by that many steps
19+
- A negative integer to roll back by that many steps`,
20+
Args: cobra.ExactArgs(1),
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
dbPath, _ := cmd.Flags().GetString("db")
23+
steps := args[0]
24+
25+
fmt.Printf("Running migrations on: %s\n", dbPath)
26+
27+
if err := storage.MigrateDB(dbPath, steps); err != nil {
28+
return fmt.Errorf("migration failed: %w", err)
29+
}
30+
31+
fmt.Println("✅ Migrations completed successfully")
32+
return nil
33+
},
34+
}
35+
36+
// CANARY: REQ=CBIN-129; FEATURE="RollbackCmd"; ASPECT=CLI; STATUS=IMPL; OWNER=canary; UPDATED=2025-10-16
37+
var RollbackCmd = &cobra.Command{
38+
Use: "rollback <steps>",
39+
Short: "Roll back database migrations",
40+
Long: `Roll back database migrations.
41+
42+
Steps can be:
43+
- "all" to roll back all migrations
44+
- A positive integer to roll back by that many steps`,
45+
Args: cobra.ExactArgs(1),
46+
RunE: func(cmd *cobra.Command, args []string) error {
47+
dbPath, _ := cmd.Flags().GetString("db")
48+
steps := args[0]
49+
50+
fmt.Printf("Rolling back migrations on: %s\n", dbPath)
51+
52+
if err := storage.TeardownDB(dbPath, steps); err != nil {
53+
return fmt.Errorf("rollback failed: %w", err)
54+
}
55+
56+
fmt.Println("✅ Rollback completed successfully")
57+
return nil
58+
},
59+
}

cmd/canary/deps.go renamed to cli/deps/deps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package deps
22

33
import (
44
"fmt"
@@ -13,8 +13,8 @@ import (
1313

1414
// CANARY: REQ=CBIN-147; FEATURE="DepsParentCommand"; ASPECT=CLI; STATUS=TESTED; TEST=TestDepsParentCommand; UPDATED=2025-10-18
1515

16-
// createDepsCommand creates the parent deps command
17-
func createDepsCommand() *cobra.Command {
16+
// CreateDepsCommand creates the parent deps command
17+
func CreateDepsCommand() *cobra.Command {
1818
cmd := &cobra.Command{
1919
Use: "deps",
2020
Short: "Manage requirement dependencies",

cmd/canary/deps_test.go renamed to cli/deps/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package deps
22

33
import (
44
"bytes"

cmd/canary/doc_commands.go renamed to cli/doc/doc_commands.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// CANARY: REQ=CBIN-136; FEATURE="DocCLICommands"; ASPECT=CLI; STATUS=TESTED; TEST=TestCANARY_CBIN_136_CLI_DocWorkflow; DOC=user:docs/user/documentation-tracking-guide.md; DOC_HASH=1e32f44252c80284; UPDATED=2025-10-16
77

8-
package main
8+
package doc
99

1010
import (
1111
"encoding/json"
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// CANARY: REQ=CBIN-136; FEATURE="DocParentCommand"; ASPECT=CLI; STATUS=IMPL; UPDATED=2025-10-16
24-
var docCmd = &cobra.Command{
24+
var DocCmd = &cobra.Command{
2525
Use: "doc",
2626
Short: "Documentation management commands",
2727
Long: `Manage documentation tracking, creation, and verification for CANARY requirements.
@@ -609,11 +609,11 @@ The report includes:
609609
}
610610

611611
func init() {
612-
// Add sub-commands to docCmd
613-
docCmd.AddCommand(docCreateCmd)
614-
docCmd.AddCommand(docUpdateCmd)
615-
docCmd.AddCommand(docStatusCmd)
616-
docCmd.AddCommand(docReportCmd)
612+
// Add sub-commands to DocCmd
613+
DocCmd.AddCommand(docCreateCmd)
614+
DocCmd.AddCommand(docUpdateCmd)
615+
DocCmd.AddCommand(docStatusCmd)
616+
DocCmd.AddCommand(docReportCmd)
617617

618618
// docCreateCmd flags
619619
docCreateCmd.Flags().String("type", "", "Documentation type (user, technical, feature, api, architecture)")

0 commit comments

Comments
 (0)