rdev/cmd/sdlc/cmd_artifact.go
jordan 56e3f83955 feat: add auth scopes, OpenAPI docs, SDLC guides, and code quality improvements
- Add auth.RequireScope() to all handler routes for proper authorization
- Add SDLC OpenAPI endpoint documentation (state, features, tasks, branches, merge, archive, orchestrator)
- Add SDLC documentation guides (getting-started, cli-reference, api-reference, command-catalog)
- Add artifact_test.go for SDLC artifact coverage
- Add CLAUDE.md rules: auth scopes requirement, error wrapping with %w
- Fix error wrapping to use %w instead of %v throughout codebase
- Improve CLI merge command with conflict detection and resolution
- Fix handler tests to include auth middleware for RequireScope
- Add cookbook tree runner scripts for automated testing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 13:55:50 -07:00

192 lines
4.1 KiB
Go

package main
import (
"fmt"
"os"
"github.com/orchard9/rdev/internal/sdlc"
"github.com/spf13/cobra"
)
var artifactCmd = &cobra.Command{
Use: "artifact",
Short: "Manage feature artifacts",
}
var artifactCreateCmd = &cobra.Command{
Use: "create <feature> <type>",
Short: "Create an artifact file (sets status to draft)",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
root := mustResolveRoot()
slug, artTypeStr := args[0], args[1]
artType := sdlc.ArtifactType(artTypeStr)
if !sdlc.IsValidArtifactType(artType) {
return fmt.Errorf("invalid artifact type: %s (valid: spec, design, tasks, qa_plan, review, audit, qa_results)", artTypeStr)
}
f, err := sdlc.LoadFeature(root, slug)
if err != nil {
return err
}
// Create the artifact file if it doesn't exist
path := sdlc.ArtifactPath(root, slug, artType)
if _, err := os.Stat(path); os.IsNotExist(err) {
if err := os.WriteFile(path, fmt.Appendf(nil, "# %s: %s\n\n", artType, f.Title), 0o644); err != nil {
return fmt.Errorf("create artifact file: %w", err)
}
}
// Update manifest
art := f.GetArtifact(artType)
if art == nil {
art = sdlc.NewArtifact(artType)
f.SetArtifact(artType, art)
}
art.MarkDraft()
if err := f.Save(root); err != nil {
return err
}
if jsonOutput {
return printJSON(map[string]string{
"feature": slug,
"artifact": string(artType),
"status": string(art.Status),
"path": path,
})
}
fmt.Printf("Created artifact: %s/%s\n", slug, artType)
fmt.Printf(" Status: %s\n", art.Status)
fmt.Printf(" Path: %s\n", path)
return nil
},
}
var artifactApproveCmd = &cobra.Command{
Use: "approve <feature> <type>",
Short: "Approve an artifact",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
root := mustResolveRoot()
slug, artTypeStr := args[0], args[1]
artType := sdlc.ArtifactType(artTypeStr)
f, err := sdlc.LoadFeature(root, slug)
if err != nil {
return err
}
art := f.GetArtifact(artType)
if art == nil {
return sdlc.ErrArtifactNotFound
}
art.Approve("user")
if err := f.Save(root); err != nil {
return err
}
// Record in state
state, err := sdlc.LoadState(root)
if err != nil {
return err
}
state.RecordAction("APPROVE_ARTIFACT", slug, "user", "success")
if err := state.Save(root); err != nil {
return err
}
if jsonOutput {
return printJSON(map[string]string{
"feature": slug,
"artifact": string(artType),
"status": "approved",
})
}
fmt.Printf("Approved: %s/%s\n", slug, artType)
return nil
},
}
var artifactRejectCmd = &cobra.Command{
Use: "reject <feature> <type>",
Short: "Reject an artifact",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
root := mustResolveRoot()
slug, artTypeStr := args[0], args[1]
artType := sdlc.ArtifactType(artTypeStr)
f, err := sdlc.LoadFeature(root, slug)
if err != nil {
return err
}
art := f.GetArtifact(artType)
if art == nil {
return sdlc.ErrArtifactNotFound
}
art.Reject("user")
if err := f.Save(root); err != nil {
return err
}
if jsonOutput {
return printJSON(map[string]string{
"feature": slug,
"artifact": string(artType),
"status": "rejected",
})
}
fmt.Printf("Rejected: %s/%s\n", slug, artType)
return nil
},
}
var artifactStatusCmd = &cobra.Command{
Use: "status <feature>",
Short: "Show all artifact statuses for a feature",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
root := mustResolveRoot()
f, err := sdlc.LoadFeature(root, args[0])
if err != nil {
return err
}
if jsonOutput {
return printJSON(f.Artifacts)
}
fmt.Printf("Artifacts for %s:\n", f.Slug)
for _, at := range sdlc.ValidArtifactTypes {
art := f.GetArtifact(at)
if art == nil {
fmt.Printf(" %-12s -\n", at)
continue
}
fmt.Printf(" %-12s %s\n", at, art.Status)
}
return nil
},
}
func init() {
artifactCmd.AddCommand(
artifactCreateCmd,
artifactApproveCmd,
artifactRejectCmd,
artifactStatusCmd,
)
rootCmd.AddCommand(artifactCmd)
}