@jeancodogno/specforce-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/.geminiignore +15 -0
  2. package/.github/workflows/ci.yml +100 -0
  3. package/.github/workflows/release.yml +51 -0
  4. package/.golangci.yml +21 -0
  5. package/.goreleaser.yaml +43 -0
  6. package/.rgignore +13 -0
  7. package/.specforce/config.yaml +32 -0
  8. package/.specforce/docs/.gitkeep +0 -0
  9. package/.specforce/docs/architecture.md +98 -0
  10. package/.specforce/docs/engineering.md +80 -0
  11. package/.specforce/docs/governance.md +30 -0
  12. package/.specforce/docs/memorial.md +44 -0
  13. package/.specforce/docs/principles.md +31 -0
  14. package/.specforce/docs/security.md +31 -0
  15. package/.specforce/docs/ui-ux.md +129 -0
  16. package/.specforce/specs/.gitkeep +0 -0
  17. package/AGENTS.md +36 -0
  18. package/CONTRIBUTING.md +81 -0
  19. package/LICENSE +21 -0
  20. package/Makefile +49 -0
  21. package/README.md +144 -0
  22. package/assets/logo-header.png +0 -0
  23. package/assets/logo.png +0 -0
  24. package/docs/artifacts.md +41 -0
  25. package/docs/cli.md +73 -0
  26. package/docs/configuration.md +50 -0
  27. package/docs/getting-started.md +110 -0
  28. package/docs/supported-tools.md +14 -0
  29. package/go.mod +35 -0
  30. package/go.sum +61 -0
  31. package/index.js +0 -0
  32. package/package.json +26 -0
  33. package/src/cmd/specforce/main.go +23 -0
  34. package/src/cmd/specforce/main_test.go +7 -0
  35. package/src/internal/agent/artifacts/constitution/architecture.yaml +70 -0
  36. package/src/internal/agent/artifacts/constitution/engineering.yaml +52 -0
  37. package/src/internal/agent/artifacts/constitution/governance.yaml +41 -0
  38. package/src/internal/agent/artifacts/constitution/memorial.yaml +55 -0
  39. package/src/internal/agent/artifacts/constitution/principles.yaml +54 -0
  40. package/src/internal/agent/artifacts/constitution/security.yaml +47 -0
  41. package/src/internal/agent/artifacts/constitution/ui-ux.yaml +158 -0
  42. package/src/internal/agent/artifacts/spec/design.yaml +50 -0
  43. package/src/internal/agent/artifacts/spec/requirements.yaml +48 -0
  44. package/src/internal/agent/artifacts/spec/tasks.yaml +55 -0
  45. package/src/internal/agent/compatibility_test.go +120 -0
  46. package/src/internal/agent/cwd_test.go +9 -0
  47. package/src/internal/agent/embed.go +19 -0
  48. package/src/internal/agent/integration_test.go +138 -0
  49. package/src/internal/agent/kit/agents/product-analyst.yaml +31 -0
  50. package/src/internal/agent/kit/agents/technical-developer.yaml +28 -0
  51. package/src/internal/agent/kit/agents/technical-project-planner.yaml +30 -0
  52. package/src/internal/agent/kit/agents/technical-qa-engineer.yaml +36 -0
  53. package/src/internal/agent/kit/agents/technical-solution-architect.yaml +32 -0
  54. package/src/internal/agent/kit/commands/archive.yaml +25 -0
  55. package/src/internal/agent/kit/commands/constitution.yaml +132 -0
  56. package/src/internal/agent/kit/commands/implement.yaml +96 -0
  57. package/src/internal/agent/kit/commands/spec.yaml +94 -0
  58. package/src/internal/agent/kit/instructions/archive.md +68 -0
  59. package/src/internal/agent/kit/kit.yaml +111 -0
  60. package/src/internal/agent/kit/skills/opportunity-framing/SKILL.yaml +56 -0
  61. package/src/internal/agent/kit/skills/pragmatic-product-owner/SKILL.yaml +58 -0
  62. package/src/internal/agent/kit/skills/pragmatic-product-owner/references/spec-artifacts.yaml +38 -0
  63. package/src/internal/agent/kit/skills/spec-clarification-interview/SKILL.yaml +52 -0
  64. package/src/internal/agent/kit/skills/task-atomic-decomposition/SKILL.yaml +137 -0
  65. package/src/internal/agent/kit/skills/task-atomic-decomposition/references/roadmap-patterns.yaml +103 -0
  66. package/src/internal/agent/kit_manifests_test.go +58 -0
  67. package/src/internal/agent/manifest.go +15 -0
  68. package/src/internal/agent/registry.go +69 -0
  69. package/src/internal/agent/registry_test.go +51 -0
  70. package/src/internal/agent/translator.go +334 -0
  71. package/src/internal/agent/translator_test.go +734 -0
  72. package/src/internal/cli/archive.go +91 -0
  73. package/src/internal/cli/archive_test.go +67 -0
  74. package/src/internal/cli/cli.go +259 -0
  75. package/src/internal/cli/cli_test.go +130 -0
  76. package/src/internal/cli/cobra/archive.go +26 -0
  77. package/src/internal/cli/cobra/console.go +21 -0
  78. package/src/internal/cli/cobra/constitution.go +44 -0
  79. package/src/internal/cli/cobra/dummy_test.go +7 -0
  80. package/src/internal/cli/cobra/implementation.go +50 -0
  81. package/src/internal/cli/cobra/init.go +23 -0
  82. package/src/internal/cli/cobra/install.go +21 -0
  83. package/src/internal/cli/cobra/root.go +47 -0
  84. package/src/internal/cli/cobra/spec.go +91 -0
  85. package/src/internal/cli/console.go +48 -0
  86. package/src/internal/cli/constitution.go +190 -0
  87. package/src/internal/cli/constitution_test.go +50 -0
  88. package/src/internal/cli/implementation.go +153 -0
  89. package/src/internal/cli/implementation_test.go +165 -0
  90. package/src/internal/cli/spec.go +369 -0
  91. package/src/internal/cli/spec_test.go +85 -0
  92. package/src/internal/constitution/registry.go +139 -0
  93. package/src/internal/constitution/registry_test.go +97 -0
  94. package/src/internal/constitution/status.go +70 -0
  95. package/src/internal/constitution/status_test.go +160 -0
  96. package/src/internal/core/blueprint.go +49 -0
  97. package/src/internal/core/blueprint_test.go +58 -0
  98. package/src/internal/core/config.go +124 -0
  99. package/src/internal/core/config_test.go +145 -0
  100. package/src/internal/core/constants.go +13 -0
  101. package/src/internal/core/errors.go +31 -0
  102. package/src/internal/core/errors_test.go +48 -0
  103. package/src/internal/core/hooks.go +89 -0
  104. package/src/internal/core/hooks_test.go +51 -0
  105. package/src/internal/core/kit.go +15 -0
  106. package/src/internal/core/kit_test.go +65 -0
  107. package/src/internal/core/path.go +115 -0
  108. package/src/internal/core/path_test.go +101 -0
  109. package/src/internal/core/ui.go +19 -0
  110. package/src/internal/installer/dependencies.go +23 -0
  111. package/src/internal/installer/install.go +89 -0
  112. package/src/internal/installer/installer.go +45 -0
  113. package/src/internal/installer/installer_test.go +96 -0
  114. package/src/internal/project/agents_md.go +108 -0
  115. package/src/internal/project/agents_md_test.go +101 -0
  116. package/src/internal/project/bootstrapper.go +64 -0
  117. package/src/internal/project/bootstrapper_test.go +89 -0
  118. package/src/internal/project/detector.go +35 -0
  119. package/src/internal/project/detector_test.go +96 -0
  120. package/src/internal/project/refresh_integration_test.go +86 -0
  121. package/src/internal/project/service.go +93 -0
  122. package/src/internal/project/service_test.go +135 -0
  123. package/src/internal/spec/archive.go +49 -0
  124. package/src/internal/spec/archive_test.go +55 -0
  125. package/src/internal/spec/discovery.go +53 -0
  126. package/src/internal/spec/discovery_test.go +60 -0
  127. package/src/internal/spec/implementation.go +296 -0
  128. package/src/internal/spec/implementation_test.go +253 -0
  129. package/src/internal/spec/registry.go +142 -0
  130. package/src/internal/spec/registry_test.go +105 -0
  131. package/src/internal/spec/scanner.go +219 -0
  132. package/src/internal/spec/scanner_test.go +243 -0
  133. package/src/internal/spec/service.go +157 -0
  134. package/src/internal/spec/service_test.go +238 -0
  135. package/src/internal/spec/status.go +94 -0
  136. package/src/internal/spec/status_test.go +146 -0
  137. package/src/internal/spec/tasks.go +103 -0
  138. package/src/internal/spec/tasks_test.go +137 -0
  139. package/src/internal/tui/components.go +132 -0
  140. package/src/internal/tui/console.go +247 -0
  141. package/src/internal/tui/console_test.go +19 -0
  142. package/src/internal/tui/constitution.go +36 -0
  143. package/src/internal/tui/constitution_test.go +32 -0
  144. package/src/internal/tui/implementation.go +151 -0
  145. package/src/internal/tui/logo.go +89 -0
  146. package/src/internal/tui/multiselect.go +199 -0
  147. package/src/internal/tui/progressbar.go +37 -0
  148. package/src/internal/tui/progressbar_test.go +30 -0
  149. package/src/internal/tui/spec.go +35 -0
  150. package/src/internal/tui/spinner.go +66 -0
  151. package/src/internal/tui/terminal.go +18 -0
  152. package/src/internal/tui/theme.go +125 -0
  153. package/src/internal/tui/ui.go +52 -0
@@ -0,0 +1,23 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var initCmd = &cobra.Command{
9
+ Use: "init [agents...]",
10
+ Short: "Initialize a new Specforce project",
11
+ Long: `Initialize a new Specforce project in the current directory.
12
+ If agents are provided, they will be initialized immediately.
13
+ Otherwise, an interactive TUI will allow you to select agents.`,
14
+ RunE: func(cmd *cobra.Command, args []string) error {
15
+ executor := GetExecutor()
16
+ appUI := tui.NewUI()
17
+ return executor.HandleInit(cmd.Context(), appUI, args...)
18
+ },
19
+ }
20
+
21
+ func init() {
22
+ rootCmd.AddCommand(initCmd)
23
+ }
@@ -0,0 +1,21 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var installCmd = &cobra.Command{
9
+ Use: "install",
10
+ Short: "Global framework installation",
11
+ Long: `Perform the initial setup and install the Specforce framework globally.`,
12
+ RunE: func(cmd *cobra.Command, args []string) error {
13
+ executor := GetExecutor()
14
+ appUI := tui.NewUI()
15
+ return executor.HandleInstall(cmd.Context(), appUI)
16
+ },
17
+ }
18
+
19
+ func init() {
20
+ rootCmd.AddCommand(installCmd)
21
+ }
@@ -0,0 +1,47 @@
1
+ package cobra
2
+
3
+ import (
4
+ "context"
5
+
6
+ "github.com/spf13/cobra"
7
+ "github.com/jeancodogno/specforce-kit/src/internal/cli"
8
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
9
+ )
10
+
11
+ var (
12
+ devMode bool
13
+ )
14
+
15
+ var rootCmd = &cobra.Command{
16
+ Use: "specforce",
17
+ Short: "Specforce: AI-Native Software Design and Delivery Framework",
18
+ Long: `Specforce is an AI-native framework designed to streamline the software
19
+ development lifecycle through Spec-Driven Development (SDD). It coordinates
20
+ AI agents and human developers to build high-quality software from
21
+ well-defined specifications.`,
22
+ }
23
+
24
+ // Execute adds all child commands to the root command and sets flags appropriately.
25
+ // This is called by main.main(). It only needs to happen once to the rootCmd.
26
+ func Execute(ctx context.Context, v string) error {
27
+ rootCmd.Version = v
28
+ rootCmd.SetVersionTemplate("specforce version {{.Version}}\n")
29
+ tui.AppVersion = v
30
+ return rootCmd.ExecuteContext(ctx)
31
+ }
32
+
33
+ func init() {
34
+ rootCmd.PersistentFlags().BoolVar(&devMode, "dev", false, "use local kit/ for development instead of embedded FS")
35
+ }
36
+
37
+ // GetDevMode returns whether development mode is active.
38
+ func GetDevMode() bool {
39
+ return devMode
40
+ }
41
+
42
+ // GetExecutor returns a new CLI executor with current settings.
43
+ func GetExecutor() *cli.Executor {
44
+ e := cli.NewExecutor(rootCmd.Version)
45
+ e.DevMode = devMode
46
+ return e
47
+ }
@@ -0,0 +1,91 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var jsonMode bool
9
+ var forceArchive bool
10
+
11
+ var specCmd = &cobra.Command{
12
+ Use: "spec",
13
+ Short: "Manage feature specification artifacts",
14
+ Long: `Manage feature specification artifacts, including initialization, status tracking, and archiving.`,
15
+ }
16
+
17
+ var specInitCmd = &cobra.Command{
18
+ Use: "init [slug]",
19
+ Short: "Initialize a new feature specification",
20
+ Args: cobra.ExactArgs(1),
21
+ RunE: func(cmd *cobra.Command, args []string) error {
22
+ executor := GetExecutor()
23
+ appUI := tui.NewUI()
24
+ // We'll pass the slug as the first argument in a slice
25
+ return executor.HandleSpecInit(cmd.Context(), appUI, args[0], jsonMode)
26
+ },
27
+ }
28
+
29
+ var specListCmd = &cobra.Command{
30
+ Use: "list",
31
+ Short: "List all active feature specifications",
32
+ RunE: func(cmd *cobra.Command, args []string) error {
33
+ executor := GetExecutor()
34
+ appUI := tui.NewUI()
35
+ return executor.HandleSpecList(cmd.Context(), appUI, jsonMode)
36
+ },
37
+ }
38
+
39
+ var specStatusCmd = &cobra.Command{
40
+ Use: "status [slug]",
41
+ Short: "Show the completeness status of a feature specification",
42
+ Args: cobra.ExactArgs(1),
43
+ RunE: func(cmd *cobra.Command, args []string) error {
44
+ executor := GetExecutor()
45
+ appUI := tui.NewUI()
46
+ // We need to pass the json flag somehow.
47
+ // For now, I'll keep the existing handler's internal flag parsing if possible,
48
+ // or refactor the handler.
49
+ return executor.HandleSpecStatus(cmd.Context(), appUI, args[0], jsonMode)
50
+ },
51
+ }
52
+
53
+ var specArtifactCmd = &cobra.Command{
54
+ Use: "artifact [slug]",
55
+ Short: "Show details of a specific spec artifact",
56
+ RunE: func(cmd *cobra.Command, args []string) error {
57
+ executor := GetExecutor()
58
+ appUI := tui.NewUI()
59
+ slug := ""
60
+ if len(args) > 0 {
61
+ slug = args[0]
62
+ }
63
+ return executor.HandleSpecArtifact(cmd.Context(), appUI, slug, jsonMode)
64
+ },
65
+ }
66
+
67
+ var specArchiveCmd = &cobra.Command{
68
+ Use: "archive [slug]",
69
+ Short: "Archive a completed feature specification",
70
+ Args: cobra.ExactArgs(1),
71
+ RunE: func(cmd *cobra.Command, args []string) error {
72
+ executor := GetExecutor()
73
+ appUI := tui.NewUI()
74
+ return executor.HandleSpecArchive(cmd.Context(), appUI, args[0], forceArchive)
75
+ },
76
+ }
77
+
78
+ func init() {
79
+ specInitCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
80
+ specListCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
81
+ specStatusCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
82
+ specArtifactCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
83
+ specArchiveCmd.Flags().BoolVar(&forceArchive, "force", false, "force archive even if pending tasks remain")
84
+
85
+ specCmd.AddCommand(specInitCmd)
86
+ specCmd.AddCommand(specListCmd)
87
+ specCmd.AddCommand(specStatusCmd)
88
+ specCmd.AddCommand(specArtifactCmd)
89
+ specCmd.AddCommand(specArchiveCmd)
90
+ rootCmd.AddCommand(specCmd)
91
+ }
@@ -0,0 +1,48 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "io/fs"
7
+
8
+ tea "github.com/charmbracelet/bubbletea"
9
+ "github.com/jeancodogno/specforce-kit/src/internal/core"
10
+ "github.com/jeancodogno/specforce-kit/src/internal/spec"
11
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
12
+ )
13
+
14
+ // RunConsole launches the interactive TUI console.
15
+ func (e *Executor) RunConsole(ctx context.Context, ui core.UI) error {
16
+ if !tui.IsTTY() {
17
+ return fmt.Errorf("console requires an interactive TTY terminal")
18
+ }
19
+
20
+ artifactsFS, err := e.GetArtifactsFS(ui)
21
+ if err != nil {
22
+ return err
23
+ }
24
+
25
+ specFS, err := fs.Sub(artifactsFS, "spec")
26
+ if err != nil {
27
+ return fmt.Errorf("failed to sub-filesystem for spec: %w", err)
28
+ }
29
+
30
+ registry, err := spec.NewRegistry(specFS)
31
+ if err != nil {
32
+ return fmt.Errorf("failed to initialize spec registry: %w", err)
33
+ }
34
+
35
+ tree, err := spec.ScanProject(ctx, ".", registry)
36
+ if err != nil {
37
+ return fmt.Errorf("failed to scan project state: %w", err)
38
+ }
39
+
40
+ model := tui.NewConsoleModel(ctx, tree, registry, ".")
41
+ p := tea.NewProgram(model, tea.WithAltScreen())
42
+
43
+ if _, err := p.Run(); err != nil {
44
+ return fmt.Errorf("TUI error: %w", err)
45
+ }
46
+
47
+ return nil
48
+ }
@@ -0,0 +1,190 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "fmt"
7
+ "io/fs"
8
+ "strings"
9
+
10
+ "github.com/jeancodogno/specforce-kit/src/internal/constitution"
11
+ "github.com/jeancodogno/specforce-kit/src/internal/core"
12
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
13
+ )
14
+
15
+ // HandleConstitution dispatches to the correct constitution sub-command.
16
+ func (e *Executor) HandleConstitution(ctx context.Context, ui core.UI, args ...string) error {
17
+ subCommand := ""
18
+ if len(args) > 0 {
19
+ subCommand = args[0]
20
+ }
21
+
22
+ switch subCommand {
23
+ case "status":
24
+ jsonMode := false
25
+ if len(args) > 1 && args[1] == "--json" {
26
+ jsonMode = true
27
+ }
28
+ return e.HandleConstitutionStatus(ctx, ui, jsonMode)
29
+ case "artifact":
30
+ slug := ""
31
+ if len(args) > 1 {
32
+ slug = args[1]
33
+ }
34
+ jsonMode := false
35
+ if len(args) > 2 && args[2] == "--json" {
36
+ jsonMode = true
37
+ }
38
+ return e.HandleConstitutionArtifact(ctx, ui, slug, jsonMode)
39
+ default:
40
+ fmt.Printf("Unknown constitution command: %s\n", subCommand)
41
+ fmt.Println("Available commands: status, artifact")
42
+ return nil
43
+ }
44
+ }
45
+
46
+ // HandleConstitutionStatus processes the 'constitution status' command.
47
+ func (e *Executor) HandleConstitutionStatus(ctx context.Context, ui core.UI, jsonMode bool) error {
48
+ artifactsFS, err := e.GetArtifactsFS(ui)
49
+ if err != nil {
50
+ return err
51
+ }
52
+
53
+ constitutionFS, err := fs.Sub(artifactsFS, "constitution")
54
+ if err != nil {
55
+ return fmt.Errorf("failed to sub-filesystem for constitution: %w", err)
56
+ }
57
+
58
+ registry, err := constitution.NewRegistry(constitutionFS)
59
+ if err != nil {
60
+ return fmt.Errorf("failed to initialize constitution registry: %w", err)
61
+ }
62
+
63
+ status, err := constitution.GetStatus(ctx, ".", registry)
64
+ if err != nil {
65
+ return fmt.Errorf("failed to scan constitution: %w", err)
66
+ }
67
+
68
+ if jsonMode {
69
+ data, err := json.MarshalIndent(status, "", " ")
70
+ if err != nil {
71
+ return fmt.Errorf("failed to marshal JSON: %w", err)
72
+ }
73
+ fmt.Println(string(data))
74
+ return nil
75
+ }
76
+
77
+ // TUI Mode
78
+ if tui.IsTTY() {
79
+ tui.PrintBranding()
80
+ }
81
+
82
+ fmt.Println("\n" + tui.HeaderStyle.Render("CONSTITUTION COMPLETENESS REPORT"))
83
+ fmt.Println(tui.SubtitleStyle.Render("Target: .specforce/docs/"))
84
+ fmt.Println()
85
+
86
+ fmt.Print(tui.RenderConstitutionStatus(status))
87
+ fmt.Println()
88
+
89
+ // Progress Bar (width 40 as per design or standard)
90
+ fmt.Println(tui.RenderProgressBar(status.Progress, 40))
91
+ fmt.Println()
92
+
93
+ if tui.IsTTY() {
94
+ tui.PrintFooter(e.Version)
95
+ }
96
+
97
+ return nil
98
+ }
99
+
100
+ // HandleConstitutionArtifact processes the 'constitution artifact' command.
101
+ func (e *Executor) HandleConstitutionArtifact(ctx context.Context, ui core.UI, slug string, jsonMode bool) error {
102
+ artifactsFS, err := e.GetArtifactsFS(ui)
103
+ if err != nil {
104
+ return err
105
+ }
106
+
107
+ constitutionFS, err := fs.Sub(artifactsFS, "constitution")
108
+ if err != nil {
109
+ return fmt.Errorf("failed to sub-filesystem for constitution: %w", err)
110
+ }
111
+
112
+ registry, err := constitution.NewRegistry(constitutionFS)
113
+ if err != nil {
114
+ return fmt.Errorf("failed to initialize constitution registry: %w", err)
115
+ }
116
+
117
+ if slug == "" {
118
+ return e.ListArtifacts(ui, registry, jsonMode)
119
+ }
120
+
121
+ art, ok := registry.Get(slug)
122
+ if !ok {
123
+ fmt.Printf("Unknown artifact slug: %s\n", slug)
124
+ fmt.Println("Use 'specforce constitution artifact' to list available slugs.")
125
+ return nil
126
+ }
127
+
128
+ if jsonMode {
129
+ data, err := json.MarshalIndent(art, "", " ")
130
+ if err != nil {
131
+ return fmt.Errorf("failed to marshal JSON: %w", err)
132
+ }
133
+ fmt.Println(string(data))
134
+ return nil
135
+ }
136
+
137
+ // TUI Mode
138
+ if tui.IsTTY() {
139
+ tui.PrintBranding()
140
+ }
141
+
142
+ fmt.Println("\n" + tui.HeaderStyle.Render("CONSTITUTION ARTIFACT: "+strings.ToUpper(art.Slug)))
143
+ fmt.Println(tui.SubtitleStyle.Render("Description: " + art.Description))
144
+ fmt.Println()
145
+
146
+ fmt.Println(tui.HeaderStyle.Render("> INSTRUCTIONS"))
147
+ fmt.Println(tui.BodyStyle.Render(art.Instruction))
148
+ fmt.Println()
149
+
150
+ fmt.Println(tui.HeaderStyle.Render("> TEMPLATE"))
151
+ fmt.Println(tui.BodyStyle.Render(art.Template))
152
+ fmt.Println()
153
+
154
+ if tui.IsTTY() {
155
+ tui.PrintFooter(e.Version)
156
+ }
157
+
158
+ return nil
159
+ }
160
+
161
+ // ListArtifacts lists all available constitution artifacts.
162
+ func (e *Executor) ListArtifacts(ui core.UI, registry *constitution.Registry, jsonMode bool) error {
163
+ artifacts := registry.List()
164
+
165
+ if jsonMode {
166
+ data, err := json.MarshalIndent(artifacts, "", " ")
167
+ if err != nil {
168
+ return fmt.Errorf("failed to marshal JSON: %w", err)
169
+ }
170
+ fmt.Println(string(data))
171
+ return nil
172
+ }
173
+
174
+ displayItems := make([]tui.ArtifactDisplay, len(artifacts))
175
+ for i, art := range artifacts {
176
+ displayItems[i] = tui.ArtifactDisplay{
177
+ ID: art.Slug,
178
+ Description: art.Description,
179
+ }
180
+ }
181
+
182
+ tui.PrintArtifactList(
183
+ "AVAILABLE CONSTITUTION ARTIFACTS",
184
+ "Use 'specforce constitution artifact [slug]' to see full details.",
185
+ displayItems,
186
+ e.Version,
187
+ )
188
+
189
+ return nil
190
+ }
@@ -0,0 +1,50 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "os"
6
+ "path/filepath"
7
+ "testing"
8
+
9
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
10
+ )
11
+
12
+ func TestHandleConstitutionArtifact(t *testing.T) {
13
+ wd, _ := os.Getwd()
14
+ projectRoot := filepath.Join(wd, "..", "..", "..")
15
+
16
+ executor := &Executor{
17
+ Version: "1.0.0",
18
+ DevMode: true,
19
+ ArtifactsRoot: filepath.Join(projectRoot, "src", "internal", "agent", "artifacts"),
20
+ }
21
+ ui := tui.NewUI()
22
+
23
+ t.Run("Valid artifact", func(t *testing.T) {
24
+ err := executor.HandleConstitutionArtifact(context.Background(), ui, "architecture", false)
25
+ if err != nil {
26
+ t.Errorf("HandleConstitutionArtifact failed: %v", err)
27
+ }
28
+ })
29
+
30
+ t.Run("Invalid artifact", func(t *testing.T) {
31
+ err := executor.HandleConstitutionArtifact(context.Background(), ui, "invalid", false)
32
+ if err != nil {
33
+ t.Errorf("HandleConstitutionArtifact failed: %v", err)
34
+ }
35
+ })
36
+
37
+ t.Run("JSON mode", func(t *testing.T) {
38
+ err := executor.HandleConstitutionArtifact(context.Background(), ui, "architecture", true)
39
+ if err != nil {
40
+ t.Errorf("HandleConstitutionArtifact failed: %v", err)
41
+ }
42
+ })
43
+
44
+ t.Run("List mode", func(t *testing.T) {
45
+ err := executor.HandleConstitutionArtifact(context.Background(), ui, "", false)
46
+ if err != nil {
47
+ t.Errorf("HandleConstitutionArtifact failed: %v", err)
48
+ }
49
+ })
50
+ }
@@ -0,0 +1,153 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "errors"
7
+ "fmt"
8
+ "io/fs"
9
+ "os"
10
+ "strings"
11
+
12
+ "github.com/jeancodogno/specforce-kit/src/internal/core"
13
+ "github.com/jeancodogno/specforce-kit/src/internal/project"
14
+ "github.com/jeancodogno/specforce-kit/src/internal/spec"
15
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
16
+ )
17
+
18
+ // HandleImplementation dispatches to the correct implementation sub-command.
19
+ func (e *Executor) HandleImplementation(ctx context.Context, ui core.UI, args ...string) error {
20
+ subCommand := ""
21
+ if len(args) > 0 {
22
+ subCommand = args[0]
23
+ }
24
+
25
+ switch subCommand {
26
+ case "status":
27
+ if len(args) < 2 {
28
+ return fmt.Errorf("missing slug for implementation status. Usage: specforce implementation status <slug>")
29
+ }
30
+ jsonMode := false
31
+ if len(args) > 2 && args[2] == "--json" {
32
+ jsonMode = true
33
+ }
34
+ return e.HandleImplementationStatus(ctx, ui, args[1], jsonMode)
35
+ case "update":
36
+ // This is just for legacy switch, but we'll use Cobra for real work.
37
+ return fmt.Errorf("update command requires specific flags, use Cobra-based CLI")
38
+ default:
39
+ fmt.Printf("Unknown implementation command: %s\n", subCommand)
40
+ fmt.Println("Available commands: status, update")
41
+ return nil
42
+ }
43
+ }
44
+
45
+ // HandleImplementationStatus processes the 'implementation status' command.
46
+ func (e *Executor) HandleImplementationStatus(ctx context.Context, ui core.UI, slug string, jsonMode bool) error {
47
+ projectRoot, err := spec.FindProjectRoot()
48
+ if err != nil {
49
+ return err
50
+ }
51
+
52
+ // Initialize SpecService lazily
53
+ if e.SpecService == nil {
54
+ artifactsFS, err := e.GetArtifactsFS(ui)
55
+ if err != nil {
56
+ return err
57
+ }
58
+ specFS, err := fs.Sub(artifactsFS, "spec")
59
+ if err != nil {
60
+ return fmt.Errorf("failed to load spec artifacts: %w", err)
61
+ }
62
+ registry, err := spec.NewRegistry(specFS)
63
+ if err != nil {
64
+ return fmt.Errorf("failed to initialize spec registry: %w", err)
65
+ }
66
+
67
+ // Initialize ProjectService if needed to pass as ConfigProvider
68
+ if e.ProjectService == nil {
69
+ kitFS, _ := e.GetKitFS(ui)
70
+ e.ProjectService = project.NewService(kitFS, artifactsFS, ".")
71
+ }
72
+ e.SpecService = spec.NewService(registry, e.ProjectService)
73
+ }
74
+
75
+ report, err := e.SpecService.GetImplementationStatus(ctx, projectRoot, slug)
76
+ if err != nil {
77
+ if jsonMode {
78
+ errData := map[string]string{"error": err.Error()}
79
+ data, _ := json.MarshalIndent(errData, "", " ")
80
+ fmt.Println(string(data))
81
+ os.Exit(1)
82
+ }
83
+ return fmt.Errorf("failed to get implementation status for %s: %w", slug, err)
84
+ }
85
+
86
+ if jsonMode {
87
+ data, err := json.MarshalIndent(report, "", " ")
88
+ if err != nil {
89
+ return fmt.Errorf("failed to marshal JSON: %w", err)
90
+ }
91
+ fmt.Println(string(data))
92
+ return nil
93
+ }
94
+
95
+ // TUI Mode
96
+ return tui.RenderImplementationStatus(report)
97
+ }
98
+
99
+ // HandleImplementationUpdate processes the 'implementation update' command.
100
+ func (e *Executor) HandleImplementationUpdate(ctx context.Context, ui core.UI, slug, taskId, status string) error {
101
+ projectRoot, err := spec.FindProjectRoot()
102
+ if err != nil {
103
+ return err
104
+ }
105
+
106
+ // Initialize SpecService lazily
107
+ if e.SpecService == nil {
108
+ artifactsFS, err := e.GetArtifactsFS(ui)
109
+ if err != nil {
110
+ return err
111
+ }
112
+ specFS, err := fs.Sub(artifactsFS, "spec")
113
+ if err != nil {
114
+ return fmt.Errorf("failed to load spec artifacts: %w", err)
115
+ }
116
+ registry, err := spec.NewRegistry(specFS)
117
+ if err != nil {
118
+ return fmt.Errorf("failed to initialize spec registry: %w", err)
119
+ }
120
+
121
+ // Initialize ProjectService if needed to pass as ConfigProvider
122
+ if e.ProjectService == nil {
123
+ kitFS, _ := e.GetKitFS(ui)
124
+ e.ProjectService = project.NewService(kitFS, artifactsFS, ".")
125
+ }
126
+ e.SpecService = spec.NewService(registry, e.ProjectService)
127
+ }
128
+
129
+ if err := e.SpecService.UpdateTaskStatus(ctx, projectRoot, slug, taskId, status); err != nil {
130
+ var hookErr *core.HookError
131
+ if errors.As(err, &hookErr) {
132
+ fmt.Println("\n[HOOK FAILURE] The following verification hooks failed:")
133
+ for _, res := range hookErr.Results {
134
+ if !res.Success {
135
+ fmt.Printf("\n--- Command: %s ---\n", res.Command)
136
+ if res.Stdout != "" {
137
+ fmt.Printf("Stdout:\n%s\n", strings.TrimSpace(res.Stdout))
138
+ }
139
+ if res.Stderr != "" {
140
+ fmt.Printf("Stderr:\n%s\n", strings.TrimSpace(res.Stderr))
141
+ }
142
+ fmt.Printf("Exit Code: %d\n", res.ExitCode)
143
+ }
144
+ }
145
+ fmt.Println("\nUpdate aborted. Please fix the issues and try again.")
146
+ return fmt.Errorf("task update blocked by hook failures")
147
+ }
148
+ return fmt.Errorf("failed to update task %s for %s: %w", taskId, slug, err)
149
+ }
150
+
151
+ fmt.Printf("[OK] Task %s status updated to %s in %s\n", taskId, status, slug)
152
+ return nil
153
+ }