@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,91 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "io/fs"
7
+
8
+ "github.com/jeancodogno/specforce-kit/src/internal/constitution"
9
+ "github.com/jeancodogno/specforce-kit/src/internal/core"
10
+ )
11
+
12
+ // HandleArchive dispatches to the correct archive sub-command.
13
+ func (e *Executor) HandleArchive(ctx context.Context, ui core.UI, args ...string) error {
14
+ subCommand := ""
15
+ if len(args) > 0 {
16
+ subCommand = args[0]
17
+ }
18
+
19
+ switch subCommand {
20
+ case "instructions":
21
+ return e.HandleArchiveInstructions(ctx, ui)
22
+ default:
23
+ fmt.Printf("Unknown archive command: %s\n", subCommand)
24
+ fmt.Println("Available commands: instructions")
25
+ return nil
26
+ }
27
+ }
28
+
29
+ // HandleArchiveInstructions processes the 'archive instructions' command.
30
+ func (e *Executor) HandleArchiveInstructions(ctx context.Context, ui core.UI) error {
31
+ // 1. Fetch Constitution Status
32
+ artifactsFS, err := e.GetArtifactsFS(ui)
33
+ if err != nil {
34
+ return err
35
+ }
36
+ constitutionFS, err := fs.Sub(artifactsFS, "constitution")
37
+ if err != nil {
38
+ return fmt.Errorf("failed to sub-filesystem for constitution: %w", err)
39
+ }
40
+ registry, err := constitution.NewRegistry(constitutionFS)
41
+ if err != nil {
42
+ return fmt.Errorf("failed to initialize constitution registry: %w", err)
43
+ }
44
+ status, err := constitution.GetStatus(ctx, ".", registry)
45
+ if err != nil {
46
+ return fmt.Errorf("failed to scan constitution: %w", err)
47
+ }
48
+
49
+ // 2. Fetch Kit Instructions
50
+ kitFS, err := e.GetKitFS(ui)
51
+ if err != nil {
52
+ return err
53
+ }
54
+ kitInstructions, err := fs.ReadFile(kitFS, "instructions/archive.md")
55
+ if err != nil {
56
+ // Fallback if file doesn't exist
57
+ kitInstructions = []byte("Follow the standard archiving procedure.")
58
+ }
59
+
60
+ // 3. Fetch Config Instructions
61
+ config := core.LoadConfig(".")
62
+ customInstructions := config.Instructions["archive"]
63
+
64
+ // 4. Print Combined Output
65
+ fmt.Println("# ARCHIVE INSTRUCTIONS")
66
+ fmt.Println()
67
+ fmt.Println("## 1. Project Constitution Context")
68
+ fmt.Println("These are the global standards of the project:")
69
+ for _, art := range status.Artifacts {
70
+ existsStr := "[MISSING]"
71
+ if art.Exists {
72
+ existsStr = "[EXISTS]"
73
+ }
74
+ fmt.Printf("- %s %s: %s (Path: %s)\n", existsStr, art.Name, art.Description, art.Path)
75
+ }
76
+ fmt.Println()
77
+
78
+ fmt.Println("## 2. Core Archiving Rules")
79
+ fmt.Println(string(kitInstructions))
80
+ fmt.Println()
81
+
82
+ if len(customInstructions) > 0 {
83
+ fmt.Println("## 3. Project-Specific Rules (config.yaml)")
84
+ for _, instr := range customInstructions {
85
+ fmt.Printf("- %s\n", instr)
86
+ }
87
+ fmt.Println()
88
+ }
89
+
90
+ return nil
91
+ }
@@ -0,0 +1,67 @@
1
+ package cli
2
+
3
+ import (
4
+ "bytes"
5
+ "context"
6
+ "io"
7
+ "os"
8
+ "strings"
9
+ "testing"
10
+ )
11
+
12
+ type archiveMockUI struct {
13
+ confirmResponse bool
14
+ logs []string
15
+ warns []string
16
+ errors []string
17
+ successes []string
18
+ }
19
+
20
+ func (m *archiveMockUI) Log(msg string) { m.logs = append(m.logs, msg) }
21
+ func (m *archiveMockUI) Warn(msg string) { m.warns = append(m.warns, msg) }
22
+ func (m *archiveMockUI) Error(msg string) { m.errors = append(m.errors, msg) }
23
+ func (m *archiveMockUI) Success(msg string) { m.successes = append(m.successes, msg) }
24
+ func (m *archiveMockUI) SubTask(msg string) { m.logs = append(m.logs, msg) }
25
+ func (m *archiveMockUI) StartSpinner(_ string) {}
26
+ func (m *archiveMockUI) StopSpinner() {}
27
+ func (m *archiveMockUI) Confirm(_ string) bool { return m.confirmResponse }
28
+
29
+ func TestHandleArchiveInstructions(t *testing.T) {
30
+ // Setup executor in DevMode to read from local src/internal/agent/kit
31
+ e := NewExecutor("test")
32
+ e.DevMode = true
33
+ e.KitRoot = "../agent/kit"
34
+ e.ArtifactsRoot = "../agent/artifacts"
35
+
36
+ // Mock UI
37
+ ui := &archiveMockUI{}
38
+
39
+ // Capture stdout
40
+ oldStdout := os.Stdout
41
+ r, w, _ := os.Pipe()
42
+ os.Stdout = w
43
+
44
+ err := e.HandleArchiveInstructions(context.Background(), ui)
45
+
46
+ _ = w.Close()
47
+ os.Stdout = oldStdout
48
+
49
+ if err != nil {
50
+ t.Fatalf("HandleArchiveInstructions failed: %v", err)
51
+ }
52
+
53
+ var buf bytes.Buffer
54
+ _, _ = io.Copy(&buf, r)
55
+ output := buf.String()
56
+
57
+ // Assertions
58
+ if !strings.Contains(output, "# ARCHIVE INSTRUCTIONS") {
59
+ t.Errorf("Output missing header")
60
+ }
61
+ if !strings.Contains(output, "## 1. Project Constitution Context") {
62
+ t.Errorf("Output missing constitution context")
63
+ }
64
+ if !strings.Contains(output, "## 2. Core Archiving Rules") {
65
+ t.Errorf("Output missing core rules")
66
+ }
67
+ }
@@ -0,0 +1,259 @@
1
+ package cli
2
+
3
+ import (
4
+ "context"
5
+ "errors"
6
+ "fmt"
7
+ "io/fs"
8
+ "os"
9
+ "strings"
10
+
11
+ "github.com/jeancodogno/specforce-kit/src/internal/agent"
12
+ "github.com/jeancodogno/specforce-kit/src/internal/core"
13
+ "github.com/jeancodogno/specforce-kit/src/internal/installer"
14
+ "github.com/jeancodogno/specforce-kit/src/internal/project"
15
+ "github.com/jeancodogno/specforce-kit/src/internal/spec"
16
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
17
+ )
18
+
19
+ // Executor handles the CLI command orchestration and routing.
20
+ type Executor struct {
21
+ Version string
22
+ DevMode bool
23
+ KitRoot string
24
+ ArtifactsRoot string
25
+ Registry *agent.Registry
26
+ ProjectService *project.Service
27
+ SpecService *spec.Service
28
+ }
29
+
30
+ // NewExecutor creates a new CLI executor.
31
+ func NewExecutor(Version string) *Executor {
32
+ return &Executor{
33
+ Version: Version,
34
+ KitRoot: "src/internal/agent/kit",
35
+ ArtifactsRoot: "src/internal/agent/artifacts",
36
+ Registry: &agent.Registry{},
37
+ }
38
+ }
39
+
40
+ func (e *Executor) HandleInstall(ctx context.Context, ui core.UI) error {
41
+ if tui.IsTTY() {
42
+ tui.PrintBranding()
43
+ }
44
+ err := installer.Install(ctx, ui)
45
+ if err != nil {
46
+ switch {
47
+ case errors.Is(err, core.ErrInstallerPermissionDenied):
48
+ // installer already printed the sudo suggestion; exit gracefully
49
+ return nil
50
+ }
51
+ }
52
+ return err
53
+ }
54
+
55
+ func (e *Executor) HandleInit(ctx context.Context, ui core.UI, agents ...string) error {
56
+ if tui.IsTTY() {
57
+ tui.PrintBranding()
58
+ }
59
+
60
+ kitFS, err := e.GetKitFS(ui)
61
+ if err != nil {
62
+ return err
63
+ }
64
+
65
+ selected, err := e.ResolveSelectedAgents(ctx, ui, agents...)
66
+ if err != nil {
67
+ return err
68
+ }
69
+
70
+ // Check if already initialized for update flow
71
+ if project.IsInitialized(".") {
72
+ return e.handleUpdateFlow(ctx, ui, kitFS, selected)
73
+ }
74
+
75
+ return e.handleNewInitFlow(ctx, ui, kitFS, selected)
76
+ }
77
+
78
+ func (e *Executor) handleUpdateFlow(ctx context.Context, ui core.UI, kitFS fs.FS, selected []string) error {
79
+ if ui != nil && ui.Confirm("Do you want to update agent tools and instructions (.gemini, .claude, etc)?") {
80
+ // Initialize ProjectService lazily
81
+ if e.ProjectService == nil {
82
+ e.ProjectService = project.NewService(kitFS, nil, ".")
83
+ }
84
+
85
+ if err := e.ProjectService.UpdateTools(ctx, ui, selected); err != nil {
86
+ return err
87
+ }
88
+ if tui.IsTTY() {
89
+ tui.PrintCompletionBox("UPDATE COMPLETE", "Agent tools and instructions updated successfully.")
90
+ }
91
+ return nil
92
+ }
93
+ if ui != nil {
94
+ ui.Warn("Initialization cancelled. Project remains unchanged.")
95
+ }
96
+ return nil
97
+ }
98
+
99
+ func (e *Executor) handleNewInitFlow(ctx context.Context, ui core.UI, kitFS fs.FS, selected []string) error {
100
+ if tui.IsTTY() {
101
+ ui.SubTask(fmt.Sprintf("Initializing project with agents: %s", strings.Join(selected, ", ")))
102
+ }
103
+
104
+ artifactsFS, err := e.GetArtifactsFS(ui)
105
+ if err != nil {
106
+ return err
107
+ }
108
+
109
+ // Initialize ProjectService lazily
110
+ if e.ProjectService == nil {
111
+ e.ProjectService = project.NewService(kitFS, artifactsFS, ".")
112
+ }
113
+
114
+ config := project.InitConfig{
115
+ ProjectRoot: ".",
116
+ SelectedAgents: selected,
117
+ }
118
+
119
+ if err := e.ProjectService.InitializeProject(ctx, ui, config); err != nil {
120
+ return err
121
+ }
122
+
123
+ // Auto-initialize config.yaml if it doesn't exist
124
+ if err := core.EnsureConfigExists("."); err != nil {
125
+ fmt.Fprintf(os.Stderr, "Warning: Failed to initialize config.yaml: %v\n", err)
126
+ }
127
+
128
+ if tui.IsTTY() {
129
+ tui.PrintCompletionBox("MISSION ACCOMPLISHED", "Specforce initialized successfully!\nYou can now start using SDD with your selected AI agents.")
130
+ }
131
+ return nil
132
+ }
133
+
134
+ func (e *Executor) GetKitFS(ui core.UI) (fs.FS, error) {
135
+ if e.DevMode {
136
+ if tui.IsTTY() {
137
+ ui.Warn(fmt.Sprintf("DEVELOPMENT MODE ACTIVE: Using local %s", e.KitRoot))
138
+ }
139
+ return os.DirFS(e.KitRoot), nil
140
+ }
141
+
142
+ kitFS, err := agent.GetKitFS()
143
+ if err != nil {
144
+ return nil, fmt.Errorf("failed to load embedded kit: %w", err)
145
+ }
146
+ return kitFS, nil
147
+ }
148
+
149
+ func (e *Executor) GetArtifactsFS(ui core.UI) (fs.FS, error) {
150
+ if e.DevMode {
151
+ if tui.IsTTY() {
152
+ ui.Warn(fmt.Sprintf("DEVELOPMENT MODE ACTIVE: Using local %s", e.ArtifactsRoot))
153
+ }
154
+ return os.DirFS(e.ArtifactsRoot), nil
155
+ }
156
+
157
+ artifactsFS, err := agent.GetArtifactsFS()
158
+ if err != nil {
159
+ return nil, fmt.Errorf("failed to load embedded artifacts: %w", err)
160
+ }
161
+ return artifactsFS, nil
162
+ }
163
+
164
+ func (e *Executor) ResolveSelectedAgents(ctx context.Context, ui core.UI, agents ...string) ([]string, error) {
165
+ // For HandleInit, we need a kitFS
166
+ kitFS, err := e.GetKitFS(ui)
167
+ if err != nil {
168
+ return nil, err
169
+ }
170
+
171
+ // Ensure registry is initialized
172
+ if err := e.Registry.Initialize(kitFS); err != nil {
173
+ return nil, fmt.Errorf("failed to initialize agent registry: %w", err)
174
+ }
175
+
176
+ if len(agents) > 0 {
177
+ // Normalize and validate provided agents
178
+ normalized := make([]string, len(agents))
179
+ for i, a := range agents {
180
+ n := a
181
+ // Aliases normalization
182
+ switch a {
183
+ case "opencode":
184
+ n = "open-code"
185
+ case "kilocode":
186
+ n = "kilo-code"
187
+ case "qwen-code":
188
+ n = "qwen"
189
+ case "kimicode":
190
+ n = "kimi-code"
191
+ }
192
+
193
+ if _, ok := e.Registry.GetAgent(n); !ok {
194
+ return nil, fmt.Errorf("agent %q is not supported. Use 'specforce init' without arguments to see available agents", a)
195
+ }
196
+ normalized[i] = n
197
+ }
198
+ return normalized, nil
199
+ }
200
+
201
+ if !tui.IsTTY() {
202
+ return nil, fmt.Errorf("no agents specified and no TTY detected")
203
+ }
204
+
205
+ existing := project.DetectExistingAgents(ctx, ".", e.Registry)
206
+ selected, err := tui.SelectAgents(e.Registry.GetAgents(), existing)
207
+ if err != nil {
208
+ if err.Error() == "aborted" {
209
+ fmt.Println("Project initialization aborted.")
210
+ os.Exit(0)
211
+ }
212
+ return nil, fmt.Errorf("TUI failure: %w", err)
213
+ }
214
+
215
+ if len(selected) == 0 {
216
+ return nil, fmt.Errorf("no agents selected; project initialization aborted")
217
+ }
218
+
219
+ return selected, nil
220
+ }
221
+
222
+ func (e *Executor) HandleConsole(ctx context.Context, ui core.UI) error {
223
+ return e.RunConsole(ctx, ui)
224
+ }
225
+
226
+ func (e *Executor) HandleHelp() {
227
+ if tui.IsTTY() {
228
+ tui.PrintBranding()
229
+ }
230
+ e.PrintUsage()
231
+ if tui.IsTTY() {
232
+ tui.PrintFooter(e.Version)
233
+ }
234
+ }
235
+
236
+ func (e *Executor) HandleUnknown(command string) {
237
+ if tui.IsTTY() {
238
+ tui.PrintBranding()
239
+ }
240
+ fmt.Printf("Unknown command: %s\n", command)
241
+ e.PrintUsage()
242
+ if tui.IsTTY() {
243
+ tui.PrintFooter(e.Version)
244
+ }
245
+ }
246
+
247
+ func (e *Executor) PrintUsage() {
248
+ fmt.Println("\nUsage:")
249
+ fmt.Println(" specforce [flags] [command]")
250
+ fmt.Println("\nAvailable Commands:")
251
+ fmt.Println(" install Global framework installation")
252
+ fmt.Println(" init Project initialization with TUI")
253
+ fmt.Println(" constitution Manage project constitution docs")
254
+ fmt.Println(" spec Manage feature specification artifacts")
255
+ fmt.Println(" implementation Task tracking and implementation status")
256
+ fmt.Println(" console Launch the Specforce Console TUI")
257
+ fmt.Println("\nFlags:")
258
+ // flag.PrintDefaults() - no longer using standard flags here.
259
+ }
@@ -0,0 +1,130 @@
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/agent"
11
+ )
12
+
13
+ // mockUI captures UI calls for assertions.
14
+ type mockUI struct {
15
+ logs []string
16
+ warns []string
17
+ errors []string
18
+ successes []string
19
+ confirmResponse bool
20
+ }
21
+
22
+ func (m *mockUI) Log(msg string) { m.logs = append(m.logs, msg) }
23
+ func (m *mockUI) Warn(msg string) { m.warns = append(m.warns, msg) }
24
+ func (m *mockUI) Error(msg string) { m.errors = append(m.errors, msg) }
25
+ func (m *mockUI) Success(msg string) { m.successes = append(m.successes, msg) }
26
+ func (m *mockUI) SubTask(msg string) { m.logs = append(m.logs, msg) }
27
+ func (m *mockUI) StartSpinner(_ string) {}
28
+ func (m *mockUI) StopSpinner() {}
29
+ func (m *mockUI) Confirm(_ string) bool { return m.confirmResponse }
30
+
31
+ func (m *mockUI) hasWarnContaining(substr string) bool {
32
+ for _, w := range m.warns {
33
+ if strings.Contains(strings.ToLower(w), strings.ToLower(substr)) {
34
+ return true
35
+ }
36
+ }
37
+ return false
38
+ }
39
+
40
+ func TestHandleInit_AlreadyInitialized_PrintsFriendlyMessage(t *testing.T) {
41
+ // Resolve repo root (test runs from package dir, go up to find src/internal/agent/kit)
42
+ pkgDir, err := os.Getwd()
43
+ if err != nil {
44
+ t.Fatal(err)
45
+ }
46
+ repoRoot := filepath.Join(pkgDir, "..", "..", "..")
47
+
48
+ tmpDir := t.TempDir()
49
+ // Pre-create .specforce to simulate an already-initialized project
50
+ if err := os.MkdirAll(filepath.Join(tmpDir, ".specforce"), 0755); err != nil {
51
+ t.Fatalf("failed to pre-init .specforce: %v", err)
52
+ }
53
+ if err := os.WriteFile(filepath.Join(tmpDir, "kit.yaml"), []byte(`tools:
54
+ claude:
55
+ target: ".claude/"
56
+ mappings:
57
+ agents:
58
+ path: "agents"
59
+ ext: ".md"
60
+ `), 0644); err != nil {
61
+ t.Fatalf("failed to pre-init kit.yaml: %v", err)
62
+ }
63
+
64
+ // Change working directory so HandleInit uses tmpDir as "."
65
+ original, _ := os.Getwd()
66
+ if err := os.Chdir(tmpDir); err != nil {
67
+ t.Fatalf("failed to chdir: %v", err)
68
+ }
69
+ defer func() { _ = os.Chdir(original) }()
70
+
71
+ executor := &Executor{
72
+ Version: "test",
73
+ DevMode: true,
74
+ KitRoot: filepath.Join(repoRoot, "src/internal/agent/kit"),
75
+ ArtifactsRoot: filepath.Join(repoRoot, "src/internal/agent/artifacts"),
76
+ Registry: &agent.Registry{},
77
+ }
78
+
79
+ ui := &mockUI{}
80
+ err = executor.HandleInit(context.Background(), ui, "claude")
81
+
82
+ // Must handle gracefully - no error, and should now succeed in adapting agents
83
+ if err != nil {
84
+ t.Errorf("expected nil error for already-initialized project, got: %v", err)
85
+ }
86
+
87
+ // In the new behavior, it should not warn but succeed
88
+ if ui.hasWarnContaining("already initialized") {
89
+ t.Error("did not expect 'already initialized' warning when agents are specified")
90
+ }
91
+ }
92
+
93
+ func TestInitCmd_UpdateToolsFlow(t *testing.T) {
94
+ pkgDir, _ := os.Getwd()
95
+ repoRoot := filepath.Join(pkgDir, "..", "..", "..")
96
+ tmpDir := t.TempDir()
97
+
98
+ // 1. Initialize project
99
+ if err := os.MkdirAll(filepath.Join(tmpDir, ".specforce"), 0755); err != nil {
100
+ t.Fatal(err)
101
+ }
102
+
103
+ original, _ := os.Getwd()
104
+ if err := os.Chdir(tmpDir); err != nil {
105
+ t.Fatal(err)
106
+ }
107
+ defer func() { _ = os.Chdir(original) }()
108
+
109
+ executor := &Executor{
110
+ Version: "test",
111
+ DevMode: true,
112
+ KitRoot: filepath.Join(repoRoot, "src/internal/agent/kit"),
113
+ ArtifactsRoot: filepath.Join(repoRoot, "src/internal/agent/artifacts"),
114
+ Registry: &agent.Registry{},
115
+ }
116
+
117
+ // 2. Mock UI with positive confirmation
118
+ ui := &mockUI{confirmResponse: true}
119
+ err := executor.HandleInit(context.Background(), ui, "claude")
120
+ if err != nil {
121
+ t.Errorf("HandleInit failed: %v", err)
122
+ }
123
+
124
+ // 3. Mock UI with negative confirmation
125
+ ui = &mockUI{confirmResponse: false}
126
+ err = executor.HandleInit(context.Background(), ui, "claude")
127
+ if err != nil {
128
+ t.Errorf("HandleInit failed: %v", err)
129
+ }
130
+ }
@@ -0,0 +1,26 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var archiveCmd = &cobra.Command{
9
+ Use: "archive",
10
+ Short: "Manage feature archiving and lifecycle",
11
+ }
12
+
13
+ var archiveInstructionsCmd = &cobra.Command{
14
+ Use: "instructions",
15
+ Short: "Show instructions for archiving a feature",
16
+ RunE: func(cmd *cobra.Command, args []string) error {
17
+ executor := GetExecutor()
18
+ appUI := tui.NewUI()
19
+ return executor.HandleArchiveInstructions(cmd.Context(), appUI)
20
+ },
21
+ }
22
+
23
+ func init() {
24
+ archiveCmd.AddCommand(archiveInstructionsCmd)
25
+ rootCmd.AddCommand(archiveCmd)
26
+ }
@@ -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 consoleCmd = &cobra.Command{
9
+ Use: "console",
10
+ Short: "Launch the Specforce Console TUI",
11
+ Long: `Launch an interactive console to manage specifications, constitution, and implementation tasks.`,
12
+ RunE: func(cmd *cobra.Command, args []string) error {
13
+ executor := GetExecutor()
14
+ appUI := tui.NewUI()
15
+ return executor.HandleConsole(cmd.Context(), appUI)
16
+ },
17
+ }
18
+
19
+ func init() {
20
+ rootCmd.AddCommand(consoleCmd)
21
+ }
@@ -0,0 +1,44 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var constitutionCmd = &cobra.Command{
9
+ Use: "constitution",
10
+ Short: "Manage project constitution docs",
11
+ }
12
+
13
+ var constitutionStatusCmd = &cobra.Command{
14
+ Use: "status",
15
+ Short: "Show the completeness status of the project constitution",
16
+ RunE: func(cmd *cobra.Command, args []string) error {
17
+ executor := GetExecutor()
18
+ appUI := tui.NewUI()
19
+ return executor.HandleConstitutionStatus(cmd.Context(), appUI, jsonMode)
20
+ },
21
+ }
22
+
23
+ var constitutionArtifactCmd = &cobra.Command{
24
+ Use: "artifact [slug]",
25
+ Short: "Show details of a specific constitution artifact",
26
+ RunE: func(cmd *cobra.Command, args []string) error {
27
+ executor := GetExecutor()
28
+ appUI := tui.NewUI()
29
+ slug := ""
30
+ if len(args) > 0 {
31
+ slug = args[0]
32
+ }
33
+ return executor.HandleConstitutionArtifact(cmd.Context(), appUI, slug, jsonMode)
34
+ },
35
+ }
36
+
37
+ func init() {
38
+ constitutionStatusCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
39
+ constitutionArtifactCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
40
+
41
+ constitutionCmd.AddCommand(constitutionStatusCmd)
42
+ constitutionCmd.AddCommand(constitutionArtifactCmd)
43
+ rootCmd.AddCommand(constitutionCmd)
44
+ }
@@ -0,0 +1,7 @@
1
+ package cobra
2
+
3
+ import "testing"
4
+
5
+ func TestDummy(t *testing.T) {
6
+ // Dummy test to avoid 'no such tool covdata' error in Go 1.25+
7
+ }
@@ -0,0 +1,50 @@
1
+ package cobra
2
+
3
+ import (
4
+ "github.com/spf13/cobra"
5
+ "github.com/jeancodogno/specforce-kit/src/internal/tui"
6
+ )
7
+
8
+ var implementationCmd = &cobra.Command{
9
+ Use: "implementation",
10
+ Short: "Task tracking and implementation status",
11
+ }
12
+
13
+ var implementationStatusCmd = &cobra.Command{
14
+ Use: "status [slug]",
15
+ Short: "Show implementation status for a feature",
16
+ Args: cobra.ExactArgs(1),
17
+ RunE: func(cmd *cobra.Command, args []string) error {
18
+ executor := GetExecutor()
19
+ appUI := tui.NewUI()
20
+ return executor.HandleImplementationStatus(cmd.Context(), appUI, args[0], jsonMode)
21
+ },
22
+ }
23
+
24
+ var implementationUpdateCmd = &cobra.Command{
25
+ Use: "update [slug]",
26
+ Short: "Update task status for a feature",
27
+ Args: cobra.ExactArgs(1),
28
+ RunE: func(cmd *cobra.Command, args []string) error {
29
+ executor := GetExecutor()
30
+ appUI := tui.NewUI()
31
+ // We'll need to pass the other flags too.
32
+ return executor.HandleImplementationUpdate(cmd.Context(), appUI, args[0], taskId, taskStatus)
33
+ },
34
+ }
35
+
36
+ var taskId string
37
+ var taskStatus string
38
+
39
+ func init() {
40
+ implementationStatusCmd.Flags().BoolVar(&jsonMode, "json", false, "output in machine-readable JSON format")
41
+
42
+ implementationUpdateCmd.Flags().StringVar(&taskId, "task", "", "task ID to update")
43
+ implementationUpdateCmd.Flags().StringVar(&taskStatus, "status", "", "new status for the task")
44
+ _ = implementationUpdateCmd.MarkFlagRequired("task")
45
+ _ = implementationUpdateCmd.MarkFlagRequired("status")
46
+
47
+ implementationCmd.AddCommand(implementationStatusCmd)
48
+ implementationCmd.AddCommand(implementationUpdateCmd)
49
+ rootCmd.AddCommand(implementationCmd)
50
+ }