@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,165 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "os"
6
+ "path/filepath"
7
+ "strings"
8
+ "testing"
9
+
10
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
11
+ )
12
+
13
+ func setupTestProject(t *testing.T, tmpDir, slug string) {
14
+ specDir := filepath.Join(".specforce", "specs", slug)
15
+ err := os.MkdirAll(specDir, 0755)
16
+ if err != nil {
17
+ t.Fatal(err)
18
+ }
19
+
20
+ tasksMD := `
21
+ # Implementation Roadmap
22
+
23
+ ## 1. Execution Strategy
24
+ Strategy
25
+
26
+ ## 2. Tasks
27
+
28
+ ### T1.1: [SCAFFOLD] Task 1
29
+ **State:** [PENDING]
30
+ **Target:** target/1
31
+ **Context:** context/1
32
+
33
+ **Action Steps:**
34
+ - step 1
35
+
36
+ **Verification (TDD):**
37
+ verify 1
38
+
39
+ ## 3. Pre-emptive Mitigations
40
+ Mitigation
41
+ `
42
+ if err := os.WriteFile(filepath.Join(specDir, "tasks.md"), []byte(tasksMD), 0644); err != nil {
43
+ t.Fatal(err)
44
+ }
45
+ if err := os.WriteFile(filepath.Join(specDir, "requirements.md"), []byte("req"), 0644); err != nil {
46
+ t.Fatal(err)
47
+ }
48
+ if err := os.WriteFile(filepath.Join(specDir, "design.md"), []byte("design"), 0644); err != nil {
49
+ t.Fatal(err)
50
+ }
51
+ }
52
+
53
+ func TestHandleImplementationStatus(t *testing.T) {
54
+ tmpDir, err := os.MkdirTemp("", "specforce-test-*")
55
+ if err != nil {
56
+ t.Fatal(err)
57
+ }
58
+ defer func() { _ = os.RemoveAll(tmpDir) }()
59
+
60
+ origDir, _ := os.Getwd()
61
+ if err := os.Chdir(tmpDir); err != nil {
62
+ t.Fatal(err)
63
+ }
64
+ defer func() { _ = os.Chdir(origDir) }()
65
+
66
+ slug := "0015-test"
67
+ setupTestProject(t, tmpDir, slug)
68
+
69
+ executor := NewExecutor("1.0.0")
70
+ executor.DevMode = false
71
+ ui := tui.NewUI()
72
+
73
+ t.Run("TUI Mode", func(t *testing.T) {
74
+ err := executor.HandleImplementation(context.Background(), ui, "status", slug)
75
+ if err != nil {
76
+ t.Errorf("HandleImplementation failed: %v", err)
77
+ }
78
+ })
79
+
80
+ t.Run("JSON Mode", func(t *testing.T) {
81
+ err := executor.HandleImplementation(context.Background(), ui, "status", slug, "--json")
82
+ if err != nil {
83
+ t.Errorf("HandleImplementation failed: %v", err)
84
+ }
85
+ })
86
+ }
87
+
88
+ func TestHandleImplementationUpdate(t *testing.T) {
89
+ tmpDir, err := os.MkdirTemp("", "specforce-test-*")
90
+ if err != nil {
91
+ t.Fatal(err)
92
+ }
93
+ defer func() { _ = os.RemoveAll(tmpDir) }()
94
+
95
+ origDir, _ := os.Getwd()
96
+ if err := os.Chdir(tmpDir); err != nil {
97
+ t.Fatal(err)
98
+ }
99
+ defer func() { _ = os.Chdir(origDir) }()
100
+
101
+ t.Run("Update status to finished", testUpdateStatusToFinished)
102
+ t.Run("Hook failure blocks update and returns error", testHookFailureBlocksUpdate)
103
+ }
104
+
105
+ func testUpdateStatusToFinished(t *testing.T) {
106
+ slug := "0015-test-update"
107
+ specDir := filepath.Join(".specforce", "specs", slug)
108
+ _ = os.MkdirAll(specDir, 0755)
109
+
110
+ tasksMD := `
111
+ ### T1.1: Task 1
112
+ **State:** [PENDING]
113
+ `
114
+ _ = os.WriteFile(filepath.Join(specDir, "tasks.md"), []byte(tasksMD), 0644)
115
+
116
+ executor := &Executor{Version: "1.0.0"}
117
+ ui := tui.NewUI()
118
+
119
+ err := executor.HandleImplementationUpdate(context.Background(), ui, slug, "T1.1", "finished")
120
+ if err != nil {
121
+ t.Errorf("HandleImplementationUpdate failed: %v", err)
122
+ }
123
+
124
+ content, _ := os.ReadFile(filepath.Join(specDir, "tasks.md"))
125
+ if !strings.Contains(string(content), "**State:** [FINISHED]") {
126
+ t.Errorf("Expected status to be [FINISHED], got:\n%s", string(content))
127
+ }
128
+ }
129
+
130
+ func testHookFailureBlocksUpdate(t *testing.T) {
131
+ slug := "hook-fail-test"
132
+ specDir := filepath.Join(".specforce", "specs", slug)
133
+ _ = os.MkdirAll(specDir, 0755)
134
+
135
+ tasksMD := `
136
+ ### T1.1: Task 1
137
+ **State:** [PENDING]
138
+ `
139
+ _ = os.WriteFile(filepath.Join(specDir, "tasks.md"), []byte(tasksMD), 0644)
140
+
141
+ configContent := `
142
+ hooks:
143
+ on_task_finished:
144
+ - "false"
145
+ `
146
+ _ = os.MkdirAll(".specforce", 0755)
147
+ _ = os.WriteFile(filepath.Join(".specforce", "config.yaml"), []byte(configContent), 0644)
148
+
149
+ executor := &Executor{Version: "1.0.0"}
150
+ ui := tui.NewUI()
151
+
152
+ err := executor.HandleImplementationUpdate(context.Background(), ui, slug, "T1.1", "finished")
153
+ if err == nil {
154
+ t.Errorf("Expected error from HandleImplementationUpdate due to hook failure, got nil")
155
+ }
156
+
157
+ if !strings.Contains(err.Error(), "hook failures") {
158
+ t.Errorf("Expected error message to contain 'hook failures', got: %v", err)
159
+ }
160
+
161
+ content, _ := os.ReadFile(filepath.Join(specDir, "tasks.md"))
162
+ if !strings.Contains(string(content), "**State:** [PENDING]") {
163
+ t.Errorf("Expected status to remain [PENDING], got:\n%s", string(content))
164
+ }
165
+ }
@@ -0,0 +1,369 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "fmt"
7
+ "io/fs"
8
+ "os"
9
+ "path/filepath"
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
+ // HandleSpec dispatches to the correct spec sub-command.
19
+ func (e *Executor) HandleSpec(ctx context.Context, ui core.UI, args ...string) error {
20
+ if len(args) == 0 {
21
+ fmt.Println("Available commands: init, list, status, artifact, archive")
22
+ return nil
23
+ }
24
+
25
+ subCommand := args[0]
26
+ jsonMode := false
27
+ for _, arg := range args {
28
+ if arg == "--json" {
29
+ jsonMode = true
30
+ break
31
+ }
32
+ }
33
+
34
+ switch subCommand {
35
+ case "init":
36
+ return e.handleSpecInitCmd(ctx, ui, args, jsonMode)
37
+ case "list":
38
+ return e.HandleSpecList(ctx, ui, jsonMode)
39
+ case "status":
40
+ return e.handleSpecStatusCmd(ctx, ui, args, jsonMode)
41
+ case "artifact":
42
+ return e.handleSpecArtifactCmd(ctx, ui, args, jsonMode)
43
+ case "archive":
44
+ return e.handleSpecArchiveCmd(ctx, ui, args)
45
+ default:
46
+ fmt.Printf("Unknown spec command: %s\n", subCommand)
47
+ fmt.Println("Available commands: init, list, status, artifact, archive")
48
+ return nil
49
+ }
50
+ }
51
+
52
+ func (e *Executor) handleSpecInitCmd(ctx context.Context, ui core.UI, args []string, jsonMode bool) error {
53
+ if len(args) < 2 {
54
+ return fmt.Errorf("missing slug for spec init. Usage: specforce spec init <slug>")
55
+ }
56
+ return e.HandleSpecInit(ctx, ui, args[1], jsonMode)
57
+ }
58
+
59
+ func (e *Executor) handleSpecStatusCmd(ctx context.Context, ui core.UI, args []string, jsonMode bool) error {
60
+ if len(args) < 2 {
61
+ return fmt.Errorf("missing slug for spec status. Usage: specforce spec status <slug>")
62
+ }
63
+ return e.HandleSpecStatus(ctx, ui, args[1], jsonMode)
64
+ }
65
+
66
+ func (e *Executor) handleSpecArtifactCmd(ctx context.Context, ui core.UI, args []string, jsonMode bool) error {
67
+ slug := ""
68
+ if len(args) > 1 && args[1] != "--json" {
69
+ slug = args[1]
70
+ }
71
+ return e.HandleSpecArtifact(ctx, ui, slug, jsonMode)
72
+ }
73
+
74
+ func (e *Executor) handleSpecArchiveCmd(ctx context.Context, ui core.UI, args []string) error {
75
+ if len(args) < 2 {
76
+ return fmt.Errorf("missing slug for spec archive. Usage: specforce spec archive <slug>")
77
+ }
78
+ force := false
79
+ for _, arg := range args {
80
+ if arg == "--force" {
81
+ force = true
82
+ break
83
+ }
84
+ }
85
+ return e.HandleSpecArchive(ctx, ui, args[1], force)
86
+ }
87
+
88
+ // HandleSpecInit processes the 'spec init' command.
89
+ func (e *Executor) HandleSpecInit(ctx context.Context, ui core.UI, slug string, jsonMode bool) error {
90
+ projectRoot, err := spec.FindProjectRoot()
91
+ if err != nil {
92
+ return err
93
+ }
94
+
95
+ exists, status := spec.SpecExists(projectRoot, slug)
96
+ if exists {
97
+ var errObj error
98
+ if status == "active" {
99
+ errObj = core.ErrSpecAlreadyActive
100
+ } else {
101
+ errObj = core.ErrSpecAlreadyArchived
102
+ }
103
+
104
+ if jsonMode {
105
+ res := map[string]string{
106
+ "status": "error",
107
+ "error": errObj.Error(),
108
+ }
109
+ data, _ := json.MarshalIndent(res, "", " ")
110
+ fmt.Println(string(data))
111
+ return nil
112
+ }
113
+ return errObj
114
+ }
115
+
116
+ specDir := filepath.Join(projectRoot, ".specforce", "specs", slug)
117
+ if err := os.MkdirAll(specDir, 0750); err != nil {
118
+ return fmt.Errorf("failed to create spec directory %s: %w", specDir, err)
119
+ }
120
+
121
+ if jsonMode {
122
+ res := map[string]string{
123
+ "status": "ok",
124
+ "message": fmt.Sprintf("Spec directory initialized: .specforce/specs/%s", slug),
125
+ }
126
+ data, _ := json.MarshalIndent(res, "", " ")
127
+ fmt.Println(string(data))
128
+ return nil
129
+ }
130
+
131
+ fmt.Printf("[OK] Spec directory initialized: .specforce/specs/%s\n", slug)
132
+ return nil
133
+ }
134
+
135
+ // HandleSpecList processes the 'spec list' command.
136
+ func (e *Executor) HandleSpecList(ctx context.Context, ui core.UI, jsonMode bool) error {
137
+ projectRoot, err := spec.FindProjectRoot()
138
+ if err != nil {
139
+ return err
140
+ }
141
+
142
+ specs, err := spec.ListActiveSpecs(ctx, projectRoot)
143
+ if err != nil {
144
+ return fmt.Errorf("failed to list active specs: %w", err)
145
+ }
146
+
147
+ if jsonMode {
148
+ data, err := json.MarshalIndent(specs, "", " ")
149
+ if err != nil {
150
+ return fmt.Errorf("failed to marshal JSON: %w", err)
151
+ }
152
+ fmt.Println(string(data))
153
+ return nil
154
+ }
155
+
156
+ if len(specs) == 0 {
157
+ fmt.Println("No active specs found.")
158
+ return nil
159
+ }
160
+
161
+ for _, s := range specs {
162
+ fmt.Println(s.Slug)
163
+ }
164
+
165
+ return nil
166
+ }
167
+
168
+ // HandleSpecStatus processes the 'spec status' command.
169
+ func (e *Executor) HandleSpecStatus(ctx context.Context, ui core.UI, slug string, jsonMode bool) error {
170
+ artifactsFS, err := e.GetArtifactsFS(ui)
171
+ if err != nil {
172
+ return err
173
+ }
174
+ specFS, err := fs.Sub(artifactsFS, "spec")
175
+ if err != nil {
176
+ return fmt.Errorf("failed to load spec artifacts: %w", err)
177
+ }
178
+
179
+ // Initialize SpecService lazily
180
+ if e.SpecService == nil {
181
+ registry, err := spec.NewRegistry(specFS)
182
+ if err != nil {
183
+ return fmt.Errorf("failed to initialize spec registry: %w", err)
184
+ }
185
+ // Initialize ProjectService if needed to pass as ConfigProvider
186
+ if e.ProjectService == nil {
187
+ kitFS, _ := e.GetKitFS(ui)
188
+ e.ProjectService = project.NewService(kitFS, artifactsFS, ".")
189
+ }
190
+ e.SpecService = spec.NewService(registry, e.ProjectService)
191
+ }
192
+
193
+ status, err := e.SpecService.GetStatus(ctx, ".", slug)
194
+ if err != nil {
195
+ if jsonMode {
196
+ errData := map[string]string{"error": err.Error()}
197
+ data, _ := json.MarshalIndent(errData, "", " ")
198
+ fmt.Println(string(data))
199
+ os.Exit(1)
200
+ }
201
+ return err
202
+ }
203
+
204
+ if jsonMode {
205
+ data, err := json.MarshalIndent(status, "", " ")
206
+ if err != nil {
207
+ return fmt.Errorf("failed to marshal status to JSON: %w", err)
208
+ }
209
+ fmt.Println(string(data))
210
+ return nil
211
+ }
212
+
213
+ e.renderSpecStatusTUI(slug, status)
214
+ return nil
215
+ }
216
+
217
+ func (e *Executor) renderSpecStatusTUI(slug string, status spec.SpecStatus) {
218
+ if tui.IsTTY() {
219
+ tui.PrintBranding()
220
+ }
221
+
222
+ fmt.Println("\n" + tui.HeaderStyle.Render("SPEC COMPLETENESS REPORT: "+strings.ToUpper(slug)))
223
+ fmt.Println(tui.SubtitleStyle.Render("Target: .specforce/specs/"+slug+"/"))
224
+ fmt.Println()
225
+
226
+ fmt.Print(tui.RenderSpecStatus(status))
227
+ fmt.Println()
228
+
229
+ // Progress Bar
230
+ fmt.Println(tui.RenderProgressBar(status.Progress, 40))
231
+ fmt.Println()
232
+
233
+ if tui.IsTTY() {
234
+ tui.PrintFooter(e.Version)
235
+ }
236
+ }
237
+
238
+ // HandleSpecArtifact processes the 'spec artifact' command.
239
+ func (e *Executor) HandleSpecArtifact(ctx context.Context, ui core.UI, slug string, jsonMode bool) error {
240
+ artifactsFS, err := e.GetArtifactsFS(ui)
241
+ if err != nil {
242
+ return err
243
+ }
244
+ specFS, err := fs.Sub(artifactsFS, "spec")
245
+ if err != nil {
246
+ return fmt.Errorf("failed to load spec artifacts: %w", err)
247
+ }
248
+ registry, err := spec.NewRegistry(specFS)
249
+ if err != nil {
250
+ return fmt.Errorf("failed to initialize spec registry: %w", err)
251
+ }
252
+
253
+ if slug == "" {
254
+ return e.ListSpecArtifacts(ui, registry, jsonMode)
255
+ }
256
+
257
+ // Initialize SpecService lazily
258
+ if e.SpecService == nil {
259
+ // Initialize ProjectService if needed to pass as ConfigProvider
260
+ if e.ProjectService == nil {
261
+ kitFS, _ := e.GetKitFS(ui)
262
+ e.ProjectService = project.NewService(kitFS, artifactsFS, ".")
263
+ }
264
+ e.SpecService = spec.NewService(registry, e.ProjectService)
265
+ }
266
+
267
+ art, err := e.SpecService.GetArtifact(ctx, slug)
268
+ if err != nil {
269
+ fmt.Printf("Unknown spec artifact slug: %s\n", slug)
270
+ fmt.Println("Use 'specforce spec artifact' to list available slugs.")
271
+ return nil
272
+ }
273
+
274
+ if jsonMode {
275
+ data, err := json.MarshalIndent(art, "", " ")
276
+ if err != nil {
277
+ return fmt.Errorf("failed to marshal JSON: %w", err)
278
+ }
279
+ fmt.Println(string(data))
280
+ return nil
281
+ }
282
+
283
+ e.renderSpecArtifactTUI(art)
284
+ return nil
285
+ }
286
+
287
+ func (e *Executor) renderSpecArtifactTUI(art *spec.Artifact) {
288
+ if tui.IsTTY() {
289
+ tui.PrintBranding()
290
+ }
291
+
292
+ fmt.Println("\n" + tui.HeaderStyle.Render("SPEC ARTIFACT: "+strings.ToUpper(art.Name)))
293
+ fmt.Println(tui.SubtitleStyle.Render("Description: " + art.Description))
294
+ if art.Dependency != "" {
295
+ fmt.Println(tui.SubtitleStyle.Render("Dependency: " + art.Dependency))
296
+ }
297
+ fmt.Println()
298
+
299
+ fmt.Println(tui.HeaderStyle.Render("> INSTRUCTIONS"))
300
+ fmt.Println(tui.BodyStyle.Render(art.Instruction))
301
+ fmt.Println()
302
+
303
+ fmt.Println(tui.HeaderStyle.Render("> TEMPLATE"))
304
+ fmt.Println(tui.BodyStyle.Render(art.Template))
305
+ fmt.Println()
306
+
307
+ if tui.IsTTY() {
308
+ tui.PrintFooter(e.Version)
309
+ }
310
+ }
311
+
312
+
313
+ // ListSpecArtifacts lists all available spec artifacts.
314
+ func (e *Executor) ListSpecArtifacts(ui core.UI, registry *spec.Registry, jsonMode bool) error {
315
+ artifacts := registry.List()
316
+
317
+ if jsonMode {
318
+ data, err := json.MarshalIndent(artifacts, "", " ")
319
+ if err != nil {
320
+ return fmt.Errorf("failed to marshal JSON: %w", err)
321
+ }
322
+ fmt.Println(string(data))
323
+ return nil
324
+ }
325
+
326
+ displayItems := make([]tui.ArtifactDisplay, len(artifacts))
327
+ for i, art := range artifacts {
328
+ displayItems[i] = tui.ArtifactDisplay{
329
+ ID: art.Name,
330
+ Description: art.Description,
331
+ }
332
+ }
333
+
334
+ tui.PrintArtifactList(
335
+ "AVAILABLE SPEC ARTIFACTS",
336
+ "Use 'specforce spec artifact [slug]' to see full details.",
337
+ displayItems,
338
+ e.Version,
339
+ )
340
+
341
+ return nil
342
+ }
343
+
344
+ // HandleSpecArchive processes the 'spec archive' command.
345
+ func (e *Executor) HandleSpecArchive(ctx context.Context, ui core.UI, slug string, force bool) error {
346
+ projectRoot, err := spec.FindProjectRoot()
347
+ if err != nil {
348
+ return err
349
+ }
350
+
351
+ // [REQ-4] Check task completion
352
+ tasksPath := filepath.Join(projectRoot, ".specforce", "specs", slug, "tasks.md")
353
+ if _, err := os.Stat(tasksPath); err == nil {
354
+ report, err := spec.ParseTasks(ctx, projectRoot, slug)
355
+ if err == nil && report.Status != "finished" && !force {
356
+ err := fmt.Errorf("cannot archive '%s': pending tasks remain. Use --force to override", slug)
357
+ ui.Error(err.Error() + "\n")
358
+ return err
359
+ }
360
+ }
361
+
362
+ if err := spec.ArchiveSpec(ctx, projectRoot, slug); err != nil {
363
+ ui.Error(fmt.Sprintf("Archive failed: %v\n", err))
364
+ return err
365
+ }
366
+
367
+ ui.Success(fmt.Sprintf("Spec successfully archived: %s\n", slug))
368
+ return nil
369
+ }
@@ -0,0 +1,85 @@
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 TestHandleSpecList(t *testing.T) {
13
+ // Setup temp project root
14
+ tmpDir := filepath.Join("testdata", "cli_spec")
15
+ if err := os.MkdirAll(filepath.Join(tmpDir, ".specforce", "specs", "test-spec"), 0755); err != nil {
16
+ t.Fatal(err)
17
+ }
18
+ cwd, _ := os.Getwd()
19
+ _ = os.Chdir(tmpDir)
20
+ defer func() { _ = os.Chdir(cwd) }()
21
+ defer func() { _ = os.RemoveAll(filepath.Join(cwd, "testdata")) }()
22
+
23
+ e := NewExecutor("1.0.0")
24
+ ui := tui.NewUI()
25
+
26
+ t.Run("TUI Mode", func(t *testing.T) {
27
+ err := e.HandleSpecList(context.Background(), ui, false)
28
+ if err != nil {
29
+ t.Errorf("unexpected error: %v", err)
30
+ }
31
+ })
32
+
33
+ t.Run("JSON Mode", func(t *testing.T) {
34
+ err := e.HandleSpecList(context.Background(), ui, true)
35
+ if err != nil {
36
+ t.Errorf("unexpected error: %v", err)
37
+ }
38
+ })
39
+ }
40
+
41
+ func TestHandleSpecInit(t *testing.T) {
42
+ // Setup temp project root
43
+ tmpDir := filepath.Join("testdata", "cli_init")
44
+ if err := os.MkdirAll(filepath.Join(tmpDir, ".specforce", "specs", "active-spec"), 0755); err != nil {
45
+ t.Fatal(err)
46
+ }
47
+ if err := os.MkdirAll(filepath.Join(tmpDir, ".specforce", "archive", "archived-spec"), 0755); err != nil {
48
+ t.Fatal(err)
49
+ }
50
+ cwd, _ := os.Getwd()
51
+ _ = os.Chdir(tmpDir)
52
+ defer func() { _ = os.Chdir(cwd) }()
53
+ defer func() { _ = os.RemoveAll(filepath.Join(cwd, "testdata")) }()
54
+
55
+ e := NewExecutor("1.0.0")
56
+ ui := tui.NewUI()
57
+
58
+ t.Run("Success", func(t *testing.T) {
59
+ err := e.HandleSpecInit(context.Background(), ui, "new-spec", false)
60
+ if err != nil {
61
+ t.Errorf("expected success, got %v", err)
62
+ }
63
+ })
64
+
65
+ t.Run("Collision Active", func(t *testing.T) {
66
+ err := e.HandleSpecInit(context.Background(), ui, "active-spec", false)
67
+ if err == nil {
68
+ t.Errorf("expected error for active spec collision, got nil")
69
+ }
70
+ })
71
+
72
+ t.Run("Collision Archived", func(t *testing.T) {
73
+ err := e.HandleSpecInit(context.Background(), ui, "archived-spec", false)
74
+ if err == nil {
75
+ t.Errorf("expected error for archived spec collision, got nil")
76
+ }
77
+ })
78
+
79
+ t.Run("JSON Success", func(t *testing.T) {
80
+ err := e.HandleSpecInit(context.Background(), ui, "json-spec", true)
81
+ if err != nil {
82
+ t.Errorf("expected success, got %v", err)
83
+ }
84
+ })
85
+ }