@jeancodogno/specforce-kit 0.1.5 → 0.1.6

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 (154) hide show
  1. package/index.js +0 -0
  2. package/package.json +12 -28
  3. package/.geminiignore +0 -15
  4. package/.github/workflows/ci.yml +0 -104
  5. package/.github/workflows/release.yml +0 -51
  6. package/.golangci.yml +0 -24
  7. package/.goreleaser.yaml +0 -39
  8. package/.rgignore +0 -13
  9. package/.specforce/archive/agents-md-hooks-config/design.md +0 -38
  10. package/.specforce/archive/agents-md-hooks-config/requirements.md +0 -35
  11. package/.specforce/archive/agents-md-hooks-config/tasks.md +0 -76
  12. package/.specforce/config.yaml +0 -32
  13. package/.specforce/docs/.gitkeep +0 -0
  14. package/.specforce/docs/architecture.md +0 -98
  15. package/.specforce/docs/engineering.md +0 -84
  16. package/.specforce/docs/governance.md +0 -30
  17. package/.specforce/docs/memorial.md +0 -45
  18. package/.specforce/docs/principles.md +0 -31
  19. package/.specforce/docs/security.md +0 -31
  20. package/.specforce/docs/ui-ux.md +0 -129
  21. package/.specforce/specs/.gitkeep +0 -0
  22. package/AGENTS.md +0 -46
  23. package/CONTRIBUTING.md +0 -81
  24. package/Makefile +0 -49
  25. package/assets/logo-header.png +0 -0
  26. package/assets/logo.png +0 -0
  27. package/docs/artifacts.md +0 -41
  28. package/docs/cli.md +0 -73
  29. package/docs/configuration.md +0 -59
  30. package/docs/getting-started.md +0 -110
  31. package/docs/supported-tools.md +0 -28
  32. package/go.mod +0 -35
  33. package/go.sum +0 -61
  34. package/src/cmd/specforce/main.go +0 -23
  35. package/src/cmd/specforce/main_test.go +0 -7
  36. package/src/internal/agent/artifacts/constitution/architecture.yaml +0 -70
  37. package/src/internal/agent/artifacts/constitution/engineering.yaml +0 -52
  38. package/src/internal/agent/artifacts/constitution/governance.yaml +0 -41
  39. package/src/internal/agent/artifacts/constitution/memorial.yaml +0 -55
  40. package/src/internal/agent/artifacts/constitution/principles.yaml +0 -54
  41. package/src/internal/agent/artifacts/constitution/security.yaml +0 -47
  42. package/src/internal/agent/artifacts/constitution/ui-ux.yaml +0 -158
  43. package/src/internal/agent/artifacts/spec/design.yaml +0 -50
  44. package/src/internal/agent/artifacts/spec/requirements.yaml +0 -48
  45. package/src/internal/agent/artifacts/spec/tasks.yaml +0 -55
  46. package/src/internal/agent/compatibility_test.go +0 -120
  47. package/src/internal/agent/cwd_test.go +0 -9
  48. package/src/internal/agent/embed.go +0 -19
  49. package/src/internal/agent/integration_test.go +0 -138
  50. package/src/internal/agent/kit/agents/product-analyst.yaml +0 -31
  51. package/src/internal/agent/kit/agents/technical-developer.yaml +0 -28
  52. package/src/internal/agent/kit/agents/technical-project-planner.yaml +0 -30
  53. package/src/internal/agent/kit/agents/technical-qa-engineer.yaml +0 -36
  54. package/src/internal/agent/kit/agents/technical-solution-architect.yaml +0 -32
  55. package/src/internal/agent/kit/commands/archive.yaml +0 -25
  56. package/src/internal/agent/kit/commands/constitution.yaml +0 -132
  57. package/src/internal/agent/kit/commands/implement.yaml +0 -96
  58. package/src/internal/agent/kit/commands/spec.yaml +0 -94
  59. package/src/internal/agent/kit/instructions/archive.md +0 -68
  60. package/src/internal/agent/kit/kit.yaml +0 -111
  61. package/src/internal/agent/kit/skills/opportunity-framing/SKILL.yaml +0 -56
  62. package/src/internal/agent/kit/skills/pragmatic-product-owner/SKILL.yaml +0 -58
  63. package/src/internal/agent/kit/skills/pragmatic-product-owner/references/spec-artifacts.yaml +0 -38
  64. package/src/internal/agent/kit/skills/spec-clarification-interview/SKILL.yaml +0 -52
  65. package/src/internal/agent/kit/skills/task-atomic-decomposition/SKILL.yaml +0 -137
  66. package/src/internal/agent/kit/skills/task-atomic-decomposition/references/roadmap-patterns.yaml +0 -103
  67. package/src/internal/agent/kit_manifests_test.go +0 -58
  68. package/src/internal/agent/manifest.go +0 -15
  69. package/src/internal/agent/registry.go +0 -69
  70. package/src/internal/agent/registry_test.go +0 -51
  71. package/src/internal/agent/translator.go +0 -334
  72. package/src/internal/agent/translator_test.go +0 -734
  73. package/src/internal/cli/archive.go +0 -91
  74. package/src/internal/cli/archive_test.go +0 -67
  75. package/src/internal/cli/cli.go +0 -259
  76. package/src/internal/cli/cli_test.go +0 -130
  77. package/src/internal/cli/cobra/archive.go +0 -26
  78. package/src/internal/cli/cobra/console.go +0 -21
  79. package/src/internal/cli/cobra/constitution.go +0 -44
  80. package/src/internal/cli/cobra/dummy_test.go +0 -7
  81. package/src/internal/cli/cobra/implementation.go +0 -50
  82. package/src/internal/cli/cobra/init.go +0 -23
  83. package/src/internal/cli/cobra/install.go +0 -21
  84. package/src/internal/cli/cobra/root.go +0 -47
  85. package/src/internal/cli/cobra/spec.go +0 -91
  86. package/src/internal/cli/console.go +0 -48
  87. package/src/internal/cli/constitution.go +0 -190
  88. package/src/internal/cli/constitution_test.go +0 -50
  89. package/src/internal/cli/implementation.go +0 -153
  90. package/src/internal/cli/implementation_test.go +0 -165
  91. package/src/internal/cli/spec.go +0 -369
  92. package/src/internal/cli/spec_test.go +0 -85
  93. package/src/internal/constitution/registry.go +0 -139
  94. package/src/internal/constitution/registry_test.go +0 -97
  95. package/src/internal/constitution/status.go +0 -70
  96. package/src/internal/constitution/status_test.go +0 -160
  97. package/src/internal/core/blueprint.go +0 -49
  98. package/src/internal/core/blueprint_test.go +0 -58
  99. package/src/internal/core/config.go +0 -124
  100. package/src/internal/core/config_test.go +0 -145
  101. package/src/internal/core/constants.go +0 -13
  102. package/src/internal/core/errors.go +0 -31
  103. package/src/internal/core/errors_test.go +0 -48
  104. package/src/internal/core/hooks.go +0 -89
  105. package/src/internal/core/hooks_test.go +0 -51
  106. package/src/internal/core/kit.go +0 -15
  107. package/src/internal/core/kit_test.go +0 -65
  108. package/src/internal/core/path.go +0 -115
  109. package/src/internal/core/path_test.go +0 -101
  110. package/src/internal/core/ui.go +0 -19
  111. package/src/internal/installer/dependencies.go +0 -23
  112. package/src/internal/installer/install.go +0 -89
  113. package/src/internal/installer/installer.go +0 -45
  114. package/src/internal/installer/installer_test.go +0 -96
  115. package/src/internal/project/agents_md.go +0 -155
  116. package/src/internal/project/agents_md_test.go +0 -147
  117. package/src/internal/project/bootstrapper.go +0 -64
  118. package/src/internal/project/bootstrapper_test.go +0 -89
  119. package/src/internal/project/detector.go +0 -35
  120. package/src/internal/project/detector_test.go +0 -96
  121. package/src/internal/project/refresh_integration_test.go +0 -86
  122. package/src/internal/project/service.go +0 -93
  123. package/src/internal/project/service_test.go +0 -135
  124. package/src/internal/spec/archive.go +0 -49
  125. package/src/internal/spec/archive_test.go +0 -55
  126. package/src/internal/spec/discovery.go +0 -53
  127. package/src/internal/spec/discovery_test.go +0 -60
  128. package/src/internal/spec/implementation.go +0 -296
  129. package/src/internal/spec/implementation_test.go +0 -253
  130. package/src/internal/spec/registry.go +0 -142
  131. package/src/internal/spec/registry_test.go +0 -105
  132. package/src/internal/spec/scanner.go +0 -219
  133. package/src/internal/spec/scanner_test.go +0 -243
  134. package/src/internal/spec/service.go +0 -157
  135. package/src/internal/spec/service_test.go +0 -238
  136. package/src/internal/spec/status.go +0 -94
  137. package/src/internal/spec/status_test.go +0 -146
  138. package/src/internal/spec/tasks.go +0 -103
  139. package/src/internal/spec/tasks_test.go +0 -137
  140. package/src/internal/tui/components.go +0 -132
  141. package/src/internal/tui/console.go +0 -247
  142. package/src/internal/tui/console_test.go +0 -19
  143. package/src/internal/tui/constitution.go +0 -36
  144. package/src/internal/tui/constitution_test.go +0 -32
  145. package/src/internal/tui/implementation.go +0 -151
  146. package/src/internal/tui/logo.go +0 -89
  147. package/src/internal/tui/multiselect.go +0 -199
  148. package/src/internal/tui/progressbar.go +0 -37
  149. package/src/internal/tui/progressbar_test.go +0 -30
  150. package/src/internal/tui/spec.go +0 -35
  151. package/src/internal/tui/spinner.go +0 -66
  152. package/src/internal/tui/terminal.go +0 -18
  153. package/src/internal/tui/theme.go +0 -125
  154. package/src/internal/tui/ui.go +0 -52
@@ -1,165 +0,0 @@
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
- }
@@ -1,369 +0,0 @@
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
- }
@@ -1,85 +0,0 @@
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
- }