@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.
- package/.geminiignore +15 -0
- package/.github/workflows/ci.yml +100 -0
- package/.github/workflows/release.yml +51 -0
- package/.golangci.yml +21 -0
- package/.goreleaser.yaml +43 -0
- package/.rgignore +13 -0
- package/.specforce/config.yaml +32 -0
- package/.specforce/docs/.gitkeep +0 -0
- package/.specforce/docs/architecture.md +98 -0
- package/.specforce/docs/engineering.md +80 -0
- package/.specforce/docs/governance.md +30 -0
- package/.specforce/docs/memorial.md +44 -0
- package/.specforce/docs/principles.md +31 -0
- package/.specforce/docs/security.md +31 -0
- package/.specforce/docs/ui-ux.md +129 -0
- package/.specforce/specs/.gitkeep +0 -0
- package/AGENTS.md +36 -0
- package/CONTRIBUTING.md +81 -0
- package/LICENSE +21 -0
- package/Makefile +49 -0
- package/README.md +144 -0
- package/assets/logo-header.png +0 -0
- package/assets/logo.png +0 -0
- package/docs/artifacts.md +41 -0
- package/docs/cli.md +73 -0
- package/docs/configuration.md +50 -0
- package/docs/getting-started.md +110 -0
- package/docs/supported-tools.md +14 -0
- package/go.mod +35 -0
- package/go.sum +61 -0
- package/index.js +0 -0
- package/package.json +26 -0
- package/src/cmd/specforce/main.go +23 -0
- package/src/cmd/specforce/main_test.go +7 -0
- package/src/internal/agent/artifacts/constitution/architecture.yaml +70 -0
- package/src/internal/agent/artifacts/constitution/engineering.yaml +52 -0
- package/src/internal/agent/artifacts/constitution/governance.yaml +41 -0
- package/src/internal/agent/artifacts/constitution/memorial.yaml +55 -0
- package/src/internal/agent/artifacts/constitution/principles.yaml +54 -0
- package/src/internal/agent/artifacts/constitution/security.yaml +47 -0
- package/src/internal/agent/artifacts/constitution/ui-ux.yaml +158 -0
- package/src/internal/agent/artifacts/spec/design.yaml +50 -0
- package/src/internal/agent/artifacts/spec/requirements.yaml +48 -0
- package/src/internal/agent/artifacts/spec/tasks.yaml +55 -0
- package/src/internal/agent/compatibility_test.go +120 -0
- package/src/internal/agent/cwd_test.go +9 -0
- package/src/internal/agent/embed.go +19 -0
- package/src/internal/agent/integration_test.go +138 -0
- package/src/internal/agent/kit/agents/product-analyst.yaml +31 -0
- package/src/internal/agent/kit/agents/technical-developer.yaml +28 -0
- package/src/internal/agent/kit/agents/technical-project-planner.yaml +30 -0
- package/src/internal/agent/kit/agents/technical-qa-engineer.yaml +36 -0
- package/src/internal/agent/kit/agents/technical-solution-architect.yaml +32 -0
- package/src/internal/agent/kit/commands/archive.yaml +25 -0
- package/src/internal/agent/kit/commands/constitution.yaml +132 -0
- package/src/internal/agent/kit/commands/implement.yaml +96 -0
- package/src/internal/agent/kit/commands/spec.yaml +94 -0
- package/src/internal/agent/kit/instructions/archive.md +68 -0
- package/src/internal/agent/kit/kit.yaml +111 -0
- package/src/internal/agent/kit/skills/opportunity-framing/SKILL.yaml +56 -0
- package/src/internal/agent/kit/skills/pragmatic-product-owner/SKILL.yaml +58 -0
- package/src/internal/agent/kit/skills/pragmatic-product-owner/references/spec-artifacts.yaml +38 -0
- package/src/internal/agent/kit/skills/spec-clarification-interview/SKILL.yaml +52 -0
- package/src/internal/agent/kit/skills/task-atomic-decomposition/SKILL.yaml +137 -0
- package/src/internal/agent/kit/skills/task-atomic-decomposition/references/roadmap-patterns.yaml +103 -0
- package/src/internal/agent/kit_manifests_test.go +58 -0
- package/src/internal/agent/manifest.go +15 -0
- package/src/internal/agent/registry.go +69 -0
- package/src/internal/agent/registry_test.go +51 -0
- package/src/internal/agent/translator.go +334 -0
- package/src/internal/agent/translator_test.go +734 -0
- package/src/internal/cli/archive.go +91 -0
- package/src/internal/cli/archive_test.go +67 -0
- package/src/internal/cli/cli.go +259 -0
- package/src/internal/cli/cli_test.go +130 -0
- package/src/internal/cli/cobra/archive.go +26 -0
- package/src/internal/cli/cobra/console.go +21 -0
- package/src/internal/cli/cobra/constitution.go +44 -0
- package/src/internal/cli/cobra/dummy_test.go +7 -0
- package/src/internal/cli/cobra/implementation.go +50 -0
- package/src/internal/cli/cobra/init.go +23 -0
- package/src/internal/cli/cobra/install.go +21 -0
- package/src/internal/cli/cobra/root.go +47 -0
- package/src/internal/cli/cobra/spec.go +91 -0
- package/src/internal/cli/console.go +48 -0
- package/src/internal/cli/constitution.go +190 -0
- package/src/internal/cli/constitution_test.go +50 -0
- package/src/internal/cli/implementation.go +153 -0
- package/src/internal/cli/implementation_test.go +165 -0
- package/src/internal/cli/spec.go +369 -0
- package/src/internal/cli/spec_test.go +85 -0
- package/src/internal/constitution/registry.go +139 -0
- package/src/internal/constitution/registry_test.go +97 -0
- package/src/internal/constitution/status.go +70 -0
- package/src/internal/constitution/status_test.go +160 -0
- package/src/internal/core/blueprint.go +49 -0
- package/src/internal/core/blueprint_test.go +58 -0
- package/src/internal/core/config.go +124 -0
- package/src/internal/core/config_test.go +145 -0
- package/src/internal/core/constants.go +13 -0
- package/src/internal/core/errors.go +31 -0
- package/src/internal/core/errors_test.go +48 -0
- package/src/internal/core/hooks.go +89 -0
- package/src/internal/core/hooks_test.go +51 -0
- package/src/internal/core/kit.go +15 -0
- package/src/internal/core/kit_test.go +65 -0
- package/src/internal/core/path.go +115 -0
- package/src/internal/core/path_test.go +101 -0
- package/src/internal/core/ui.go +19 -0
- package/src/internal/installer/dependencies.go +23 -0
- package/src/internal/installer/install.go +89 -0
- package/src/internal/installer/installer.go +45 -0
- package/src/internal/installer/installer_test.go +96 -0
- package/src/internal/project/agents_md.go +108 -0
- package/src/internal/project/agents_md_test.go +101 -0
- package/src/internal/project/bootstrapper.go +64 -0
- package/src/internal/project/bootstrapper_test.go +89 -0
- package/src/internal/project/detector.go +35 -0
- package/src/internal/project/detector_test.go +96 -0
- package/src/internal/project/refresh_integration_test.go +86 -0
- package/src/internal/project/service.go +93 -0
- package/src/internal/project/service_test.go +135 -0
- package/src/internal/spec/archive.go +49 -0
- package/src/internal/spec/archive_test.go +55 -0
- package/src/internal/spec/discovery.go +53 -0
- package/src/internal/spec/discovery_test.go +60 -0
- package/src/internal/spec/implementation.go +296 -0
- package/src/internal/spec/implementation_test.go +253 -0
- package/src/internal/spec/registry.go +142 -0
- package/src/internal/spec/registry_test.go +105 -0
- package/src/internal/spec/scanner.go +219 -0
- package/src/internal/spec/scanner_test.go +243 -0
- package/src/internal/spec/service.go +157 -0
- package/src/internal/spec/service_test.go +238 -0
- package/src/internal/spec/status.go +94 -0
- package/src/internal/spec/status_test.go +146 -0
- package/src/internal/spec/tasks.go +103 -0
- package/src/internal/spec/tasks_test.go +137 -0
- package/src/internal/tui/components.go +132 -0
- package/src/internal/tui/console.go +247 -0
- package/src/internal/tui/console_test.go +19 -0
- package/src/internal/tui/constitution.go +36 -0
- package/src/internal/tui/constitution_test.go +32 -0
- package/src/internal/tui/implementation.go +151 -0
- package/src/internal/tui/logo.go +89 -0
- package/src/internal/tui/multiselect.go +199 -0
- package/src/internal/tui/progressbar.go +37 -0
- package/src/internal/tui/progressbar_test.go +30 -0
- package/src/internal/tui/spec.go +35 -0
- package/src/internal/tui/spinner.go +66 -0
- package/src/internal/tui/terminal.go +18 -0
- package/src/internal/tui/theme.go +125 -0
- package/src/internal/tui/ui.go +52 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"regexp"
|
|
8
|
+
"strings"
|
|
9
|
+
|
|
10
|
+
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// updateTaskStatusFile updates the status of a task in tasks.md.
|
|
14
|
+
func updateTaskStatusFile(projectRoot, slug, taskID, newStatus string) error {
|
|
15
|
+
tasksPath, err := core.SecurePath(projectRoot, filepath.Join(".specforce", "specs", slug, "tasks.md"))
|
|
16
|
+
if err != nil {
|
|
17
|
+
return fmt.Errorf("security: %w", err)
|
|
18
|
+
}
|
|
19
|
+
// #nosec G304 - Path is secured by SecurePath
|
|
20
|
+
content, err := os.ReadFile(tasksPath)
|
|
21
|
+
if err != nil {
|
|
22
|
+
return fmt.Errorf("failed to read tasks.md: %w", err)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
contentStr := string(content)
|
|
26
|
+
start, end, err := findTaskBlock(contentStr, taskID)
|
|
27
|
+
if err != nil {
|
|
28
|
+
return err
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
taskBlock := contentStr[start:end]
|
|
32
|
+
|
|
33
|
+
// 3. Find and replace the state line in the block
|
|
34
|
+
stateRegex := regexp.MustCompile(`\*\*State:\*\* (\x60?)\[(.*?)\](\x60?)`)
|
|
35
|
+
stateMatch := stateRegex.FindStringSubmatchIndex(taskBlock)
|
|
36
|
+
if stateMatch == nil {
|
|
37
|
+
return fmt.Errorf("state field not found for task %s", taskID)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Capture surrounding formatting
|
|
41
|
+
preTick := taskBlock[stateMatch[2]:stateMatch[3]]
|
|
42
|
+
postTick := taskBlock[stateMatch[6]:stateMatch[7]]
|
|
43
|
+
|
|
44
|
+
mappedStatus := mapStatus(newStatus)
|
|
45
|
+
newStateLine := fmt.Sprintf("**State:** %s[%s]%s", preTick, mappedStatus, postTick)
|
|
46
|
+
|
|
47
|
+
// We need to replace it in the original contentStr
|
|
48
|
+
startInContent := start + stateMatch[0]
|
|
49
|
+
endInContent := start + stateMatch[1]
|
|
50
|
+
|
|
51
|
+
newContent := contentStr[:startInContent] + newStateLine + contentStr[endInContent:]
|
|
52
|
+
|
|
53
|
+
// #nosec G306, G703 - Path is secured by SecurePath
|
|
54
|
+
return os.WriteFile(tasksPath, []byte(newContent), 0600)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func findTaskBlock(content, taskID string) (int, int, error) {
|
|
58
|
+
// 1. Find the task header
|
|
59
|
+
taskHeaderRegex := regexp.MustCompile(fmt.Sprintf(`(?m)^#{3,4} %s: .*$`, regexp.QuoteMeta(taskID)))
|
|
60
|
+
headerMatches := taskHeaderRegex.FindAllStringIndex(content, -1)
|
|
61
|
+
|
|
62
|
+
if len(headerMatches) == 0 {
|
|
63
|
+
return 0, 0, fmt.Errorf("task %s not found in tasks.md", taskID)
|
|
64
|
+
}
|
|
65
|
+
if len(headerMatches) > 1 {
|
|
66
|
+
return 0, 0, fmt.Errorf("ambiguous task ID %s: found %d matches", taskID, len(headerMatches))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
headerEnd := headerMatches[0][1]
|
|
70
|
+
|
|
71
|
+
// 2. Find the next task header or end of tasks section to define the block
|
|
72
|
+
nextBoundaryRegex := regexp.MustCompile(`(?m)^#{3,4} (T[\d.]+|Phase [\d.]+): `)
|
|
73
|
+
nextBoundaryMatch := nextBoundaryRegex.FindStringIndex(content[headerEnd:])
|
|
74
|
+
|
|
75
|
+
blockEnd := len(content)
|
|
76
|
+
if nextBoundaryMatch != nil {
|
|
77
|
+
blockEnd = headerEnd + nextBoundaryMatch[0]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Also check for end of section ##
|
|
81
|
+
nextSectionRegex := regexp.MustCompile(`(?m)^## `)
|
|
82
|
+
nextSectionMatch := nextSectionRegex.FindStringIndex(content[headerEnd:])
|
|
83
|
+
if nextSectionMatch != nil && (nextBoundaryMatch == nil || headerEnd+nextSectionMatch[0] < blockEnd) {
|
|
84
|
+
blockEnd = headerEnd + nextSectionMatch[0]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return headerMatches[0][0], blockEnd, nil
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func mapStatus(status string) string {
|
|
91
|
+
statusMap := map[string]string{
|
|
92
|
+
"pending": "PENDING",
|
|
93
|
+
"in-progress": "IN-PROGRESS",
|
|
94
|
+
"finished": "FINISHED",
|
|
95
|
+
"failed": "FAILED",
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
mapped, ok := statusMap[strings.ToLower(status)]
|
|
99
|
+
if !ok {
|
|
100
|
+
return strings.ToUpper(status)
|
|
101
|
+
}
|
|
102
|
+
return mapped
|
|
103
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"path/filepath"
|
|
6
|
+
"testing"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func setupTasksTest(t *testing.T, projectRoot, slug, content string) string {
|
|
10
|
+
tasksDir := filepath.Join(projectRoot, ".specforce", "specs", slug)
|
|
11
|
+
if err := os.MkdirAll(tasksDir, 0755); err != nil {
|
|
12
|
+
t.Fatalf("Failed to create temp dir: %v", err)
|
|
13
|
+
}
|
|
14
|
+
tasksPath := filepath.Join(tasksDir, "tasks.md")
|
|
15
|
+
if err := os.WriteFile(tasksPath, []byte(content), 0644); err != nil {
|
|
16
|
+
t.Fatalf("Failed to write tasks.md: %v", err)
|
|
17
|
+
}
|
|
18
|
+
return tasksPath
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func TestUpdateTaskStatusFile(t *testing.T) {
|
|
22
|
+
tempDir, err := os.MkdirTemp("", "specforce-tasks-*")
|
|
23
|
+
if err != nil {
|
|
24
|
+
t.Fatal(err)
|
|
25
|
+
}
|
|
26
|
+
defer func() { _ = os.RemoveAll(tempDir) }()
|
|
27
|
+
|
|
28
|
+
projectRoot := tempDir
|
|
29
|
+
slug := "test-slug"
|
|
30
|
+
content := `
|
|
31
|
+
## 2. Tasks
|
|
32
|
+
|
|
33
|
+
### T1.1: Task 1
|
|
34
|
+
**State:** [ ]
|
|
35
|
+
**Target:** target1
|
|
36
|
+
|
|
37
|
+
### T1.2: Task 2
|
|
38
|
+
**State:** [PENDING]
|
|
39
|
+
**Target:** target2
|
|
40
|
+
`
|
|
41
|
+
tasksPath := setupTasksTest(t, projectRoot, slug, content)
|
|
42
|
+
|
|
43
|
+
// Test updating T1.1 to finished
|
|
44
|
+
if err := updateTaskStatusFile(projectRoot, slug, "T1.1", "finished"); err != nil {
|
|
45
|
+
t.Fatalf("updateTaskStatusFile failed: %v", err)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
updatedContent, _ := os.ReadFile(tasksPath)
|
|
49
|
+
expected := `
|
|
50
|
+
## 2. Tasks
|
|
51
|
+
|
|
52
|
+
### T1.1: Task 1
|
|
53
|
+
**State:** [FINISHED]
|
|
54
|
+
**Target:** target1
|
|
55
|
+
|
|
56
|
+
### T1.2: Task 2
|
|
57
|
+
**State:** [PENDING]
|
|
58
|
+
**Target:** target2
|
|
59
|
+
`
|
|
60
|
+
if string(updatedContent) != expected {
|
|
61
|
+
t.Errorf("Unexpected content after update:\n%s", string(updatedContent))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Test updating T1.2 to in-progress
|
|
65
|
+
if err := updateTaskStatusFile(projectRoot, slug, "T1.2", "in-progress"); err != nil {
|
|
66
|
+
t.Fatalf("updateTaskStatusFile failed: %v", err)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
updatedContent, _ = os.ReadFile(tasksPath)
|
|
70
|
+
expected2 := `
|
|
71
|
+
## 2. Tasks
|
|
72
|
+
|
|
73
|
+
### T1.1: Task 1
|
|
74
|
+
**State:** [FINISHED]
|
|
75
|
+
**Target:** target1
|
|
76
|
+
|
|
77
|
+
### T1.2: Task 2
|
|
78
|
+
**State:** [IN-PROGRESS]
|
|
79
|
+
**Target:** target2
|
|
80
|
+
`
|
|
81
|
+
if string(updatedContent) != expected2 {
|
|
82
|
+
t.Errorf("Unexpected content after update 2:\n%s", string(updatedContent))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func TestUpdateTaskStatusFile_WithPhases(t *testing.T) {
|
|
87
|
+
projectRoot, _ := os.MkdirTemp("", "specforce-update-tasks-*")
|
|
88
|
+
defer func() { _ = os.RemoveAll(projectRoot) }()
|
|
89
|
+
|
|
90
|
+
slug := "test-slug"
|
|
91
|
+
tasksDir := filepath.Join(projectRoot, ".specforce", "specs", slug)
|
|
92
|
+
_ = os.MkdirAll(tasksDir, 0755)
|
|
93
|
+
tasksPath := filepath.Join(tasksDir, "tasks.md")
|
|
94
|
+
|
|
95
|
+
content := `
|
|
96
|
+
## 2. Tasks
|
|
97
|
+
|
|
98
|
+
### Phase 1: Setup
|
|
99
|
+
#### T1.1: Task One
|
|
100
|
+
**State:** [PENDING]
|
|
101
|
+
**Target:** target/one
|
|
102
|
+
|
|
103
|
+
### Phase 2: Implementation
|
|
104
|
+
#### T2.1: Task Two
|
|
105
|
+
**State:** [PENDING]
|
|
106
|
+
**Target:** target/two
|
|
107
|
+
`
|
|
108
|
+
_ = os.WriteFile(tasksPath, []byte(content), 0644)
|
|
109
|
+
|
|
110
|
+
// Update T1.1
|
|
111
|
+
if err := updateTaskStatusFile(projectRoot, slug, "T1.1", "finished"); err != nil {
|
|
112
|
+
t.Fatalf("updateTaskStatusFile failed for T1.1: %v", err)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Update T2.1
|
|
116
|
+
if err := updateTaskStatusFile(projectRoot, slug, "T2.1", "in-progress"); err != nil {
|
|
117
|
+
t.Fatalf("updateTaskStatusFile failed for T2.1: %v", err)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updatedContent, _ := os.ReadFile(tasksPath)
|
|
121
|
+
expected := `
|
|
122
|
+
## 2. Tasks
|
|
123
|
+
|
|
124
|
+
### Phase 1: Setup
|
|
125
|
+
#### T1.1: Task One
|
|
126
|
+
**State:** [FINISHED]
|
|
127
|
+
**Target:** target/one
|
|
128
|
+
|
|
129
|
+
### Phase 2: Implementation
|
|
130
|
+
#### T2.1: Task Two
|
|
131
|
+
**State:** [IN-PROGRESS]
|
|
132
|
+
**Target:** target/two
|
|
133
|
+
`
|
|
134
|
+
if string(updatedContent) != expected {
|
|
135
|
+
t.Errorf("Unexpected content after update:\n%s", string(updatedContent))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
package tui
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"os"
|
|
6
|
+
"strings"
|
|
7
|
+
|
|
8
|
+
"github.com/charmbracelet/lipgloss"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// TUI Glyphs
|
|
12
|
+
const (
|
|
13
|
+
ArrowGlyph = "›"
|
|
14
|
+
BulletGlyph = "◉"
|
|
15
|
+
EmptyBulletGlyph = "○"
|
|
16
|
+
SeparatorGlyph = "─"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
// Shared Component Styles
|
|
20
|
+
var (
|
|
21
|
+
ActiveArrowStyle = lipgloss.NewStyle().
|
|
22
|
+
Foreground(brandCyan).
|
|
23
|
+
Bold(true)
|
|
24
|
+
|
|
25
|
+
SelectedBulletStyle = lipgloss.NewStyle().
|
|
26
|
+
Foreground(brandCyan)
|
|
27
|
+
|
|
28
|
+
UnselectedBulletStyle = lipgloss.NewStyle().
|
|
29
|
+
Foreground(mutedGrey)
|
|
30
|
+
|
|
31
|
+
SeparatorStyle = lipgloss.NewStyle().
|
|
32
|
+
Foreground(mutedGrey)
|
|
33
|
+
|
|
34
|
+
FooterStyle = lipgloss.NewStyle().
|
|
35
|
+
Foreground(textGrey).
|
|
36
|
+
Background(lipgloss.Color("#111111")).
|
|
37
|
+
Padding(0, 1)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
// RenderSeparator returns a full-width dimmed separator
|
|
41
|
+
func RenderSeparator(width int) string {
|
|
42
|
+
if width <= 0 {
|
|
43
|
+
width = 80 // Default fallback
|
|
44
|
+
}
|
|
45
|
+
return SeparatorStyle.Render(strings.Repeat(SeparatorGlyph, width))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// PrintFooter renders a contextual information bar at the bottom.
|
|
49
|
+
func PrintFooter(version string) {
|
|
50
|
+
cwd, _ := os.Getwd()
|
|
51
|
+
path := cwd
|
|
52
|
+
|
|
53
|
+
footerText := fmt.Sprintf("Specforce %s | Workspace: %s", version, path)
|
|
54
|
+
fmt.Println("\n" + FooterStyle.Render(footerText))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// RenderBadge returns a high-contrast boxed status message.
|
|
58
|
+
func RenderBadge(status string, message string) string {
|
|
59
|
+
var style lipgloss.Style
|
|
60
|
+
var prefix string
|
|
61
|
+
|
|
62
|
+
switch strings.ToLower(status) {
|
|
63
|
+
case "success", "ok":
|
|
64
|
+
style = SuccessBadgeStyle
|
|
65
|
+
prefix = " SUCCESS "
|
|
66
|
+
case "warning", "warn":
|
|
67
|
+
style = WarningBadgeStyle
|
|
68
|
+
prefix = " WARNING "
|
|
69
|
+
case "error", "fail":
|
|
70
|
+
style = ErrorBadgeStyle
|
|
71
|
+
prefix = " ERROR "
|
|
72
|
+
default:
|
|
73
|
+
style = lipgloss.NewStyle().Foreground(textWhite).Background(mutedGrey).Padding(0, 1)
|
|
74
|
+
prefix = " INFO "
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
badge := style.Render(prefix)
|
|
78
|
+
return fmt.Sprintf("\n %s %s\n", badge, BodyStyle.Render(message))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// RenderErrorBadge returns a high-contrast boxed error message.
|
|
82
|
+
func RenderErrorBadge(message string) string {
|
|
83
|
+
return RenderBadge("error", message)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// LogSubTask renders a styled sub-task log with an indented cyan arrow.
|
|
87
|
+
func LogSubTask(message string) {
|
|
88
|
+
prefix := ActiveArrowStyle.Render(" › ")
|
|
89
|
+
fmt.Println(SubTaskStyle.Render(prefix + message))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// PrintCompletionBox renders a high-fidelity summary box for successful operations.
|
|
93
|
+
func PrintCompletionBox(title, message string) {
|
|
94
|
+
header := SuccessStyle.Bold(true).Render(title)
|
|
95
|
+
body := BodyStyle.Render(message)
|
|
96
|
+
fmt.Println("\n" + CompletionBoxStyle.Render(header+"\n\n"+body))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ArtifactDisplay represents a generic artifact for TUI listing.
|
|
100
|
+
type ArtifactDisplay struct {
|
|
101
|
+
ID string
|
|
102
|
+
Description string
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// PrintArtifactList renders a standardized list of artifacts.
|
|
106
|
+
func PrintArtifactList(title, subtitle string, artifacts []ArtifactDisplay, version string) {
|
|
107
|
+
if IsTTY() {
|
|
108
|
+
PrintBranding()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fmt.Println("\n" + HeaderStyle.Render(title))
|
|
112
|
+
fmt.Println(SubtitleStyle.Render(subtitle))
|
|
113
|
+
fmt.Println()
|
|
114
|
+
|
|
115
|
+
for _, art := range artifacts {
|
|
116
|
+
fmt.Printf(" %s %s\n", HeaderStyle.Width(15).Render(art.ID), SubtitleStyle.Render(art.Description))
|
|
117
|
+
}
|
|
118
|
+
fmt.Println()
|
|
119
|
+
|
|
120
|
+
if IsTTY() {
|
|
121
|
+
PrintFooter(version)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Confirm asks a simple yes/no question in the terminal and returns true if yes.
|
|
126
|
+
func Confirm(question string) bool {
|
|
127
|
+
fmt.Printf("\n %s %s (y/N): ", ActiveArrowStyle.Render("?"), BodyStyle.Render(question))
|
|
128
|
+
var response string
|
|
129
|
+
_, _ = fmt.Scanln(&response)
|
|
130
|
+
response = strings.ToLower(strings.TrimSpace(response))
|
|
131
|
+
return response == "y" || response == "yes"
|
|
132
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
package tui
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
7
|
+
"time"
|
|
8
|
+
|
|
9
|
+
"github.com/charmbracelet/bubbles/viewport"
|
|
10
|
+
tea "github.com/charmbracelet/bubbletea"
|
|
11
|
+
"github.com/charmbracelet/lipgloss"
|
|
12
|
+
"github.com/jeancodogno/specforce-kit/src/internal/spec"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// TickMsg is sent when the real-time refresh ticker fires.
|
|
16
|
+
type TickMsg time.Time
|
|
17
|
+
|
|
18
|
+
func tick() tea.Cmd {
|
|
19
|
+
return tea.Tick(time.Second, func(t time.Time) tea.Msg {
|
|
20
|
+
return TickMsg(t)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ConsoleModel represents the state of the Specforce Console TUI.
|
|
25
|
+
type ConsoleModel struct {
|
|
26
|
+
ctx context.Context
|
|
27
|
+
StateTree *spec.StateTree
|
|
28
|
+
registry *spec.Registry
|
|
29
|
+
projectRoot string
|
|
30
|
+
width int
|
|
31
|
+
height int
|
|
32
|
+
viewport viewport.Model
|
|
33
|
+
ready bool
|
|
34
|
+
err error
|
|
35
|
+
errorMsg string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// NewConsoleModel initializes a new ConsoleModel with the project state.
|
|
39
|
+
func NewConsoleModel(ctx context.Context, tree *spec.StateTree, registry *spec.Registry, root string) *ConsoleModel {
|
|
40
|
+
return &ConsoleModel{
|
|
41
|
+
ctx: ctx,
|
|
42
|
+
StateTree: tree,
|
|
43
|
+
registry: registry,
|
|
44
|
+
projectRoot: root,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Init initializes the Bubbletea program.
|
|
49
|
+
func (m *ConsoleModel) Init() tea.Cmd {
|
|
50
|
+
return tea.Batch(tick(), nil)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ErrorMsg is sent when an external operation fails.
|
|
54
|
+
type ErrorMsg struct {
|
|
55
|
+
Err error
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Update handles terminal events and updates the model state.
|
|
59
|
+
func (m *ConsoleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
60
|
+
var cmds []tea.Cmd
|
|
61
|
+
|
|
62
|
+
switch msg := msg.(type) {
|
|
63
|
+
case tea.WindowSizeMsg:
|
|
64
|
+
m.width = msg.Width
|
|
65
|
+
m.height = msg.Height
|
|
66
|
+
|
|
67
|
+
if !m.ready {
|
|
68
|
+
m.viewport = viewport.New(m.width, m.height)
|
|
69
|
+
m.ready = true
|
|
70
|
+
} else {
|
|
71
|
+
m.viewport.Width = m.width
|
|
72
|
+
m.viewport.Height = m.height
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
m.viewport.SetContent(m.renderDashboard())
|
|
76
|
+
|
|
77
|
+
case tea.KeyMsg:
|
|
78
|
+
switch msg.String() {
|
|
79
|
+
case "q", "ctrl+c", "esc":
|
|
80
|
+
return m, tea.Quit
|
|
81
|
+
case "r":
|
|
82
|
+
m.refreshState()
|
|
83
|
+
default:
|
|
84
|
+
// Handle viewport scrolling for keys like up/down/pgup/pgdown
|
|
85
|
+
var cmd tea.Cmd
|
|
86
|
+
m.viewport, cmd = m.viewport.Update(msg)
|
|
87
|
+
cmds = append(cmds, cmd)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
case TickMsg:
|
|
91
|
+
m.refreshState()
|
|
92
|
+
cmds = append(cmds, tick())
|
|
93
|
+
|
|
94
|
+
case ErrorMsg:
|
|
95
|
+
m.err = msg.Err
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Sync content after any change
|
|
99
|
+
if m.ready {
|
|
100
|
+
m.viewport.SetContent(m.renderDashboard())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return m, tea.Batch(cmds...)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func (m *ConsoleModel) refreshState() {
|
|
107
|
+
tree, err := spec.ScanProject(m.ctx, m.projectRoot, m.registry)
|
|
108
|
+
if err == nil {
|
|
109
|
+
m.StateTree = tree
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// View renders the TUI to the terminal.
|
|
114
|
+
func (m *ConsoleModel) View() string {
|
|
115
|
+
if m.err != nil {
|
|
116
|
+
return ErrorStyle.Render("Console Error: " + m.err.Error())
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if !m.ready {
|
|
120
|
+
return "Initializing..."
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return m.viewport.View()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
func (m *ConsoleModel) renderDashboard() string {
|
|
127
|
+
var s strings.Builder
|
|
128
|
+
|
|
129
|
+
// 1. Logo
|
|
130
|
+
s.WriteString(m.renderLogo())
|
|
131
|
+
s.WriteString("\n\n")
|
|
132
|
+
|
|
133
|
+
// Check if everything is empty
|
|
134
|
+
isEmpty := true
|
|
135
|
+
for _, items := range m.StateTree.Categories {
|
|
136
|
+
if len(items) > 0 {
|
|
137
|
+
isEmpty = false
|
|
138
|
+
break
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if isEmpty {
|
|
143
|
+
s.WriteString(m.renderEmptyStateContent())
|
|
144
|
+
return s.String()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 3. Sections
|
|
148
|
+
categories := []struct {
|
|
149
|
+
cat spec.StateCategory
|
|
150
|
+
label string
|
|
151
|
+
}{
|
|
152
|
+
{spec.CategoryConstitution, "🏛️ CONSTITUTION (Foundation)"},
|
|
153
|
+
{spec.CategoryActiveSpecs, "📋 ACTIVE SPECIFICATIONS (Planning Phase)"},
|
|
154
|
+
{spec.CategoryImplementations, "🚀 ACTIVE IMPLEMENTATIONS (Execution Phase)"},
|
|
155
|
+
{spec.CategoryArchived, "📦 RECENTLY ARCHIVED (Completed Features)"},
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for _, config := range categories {
|
|
159
|
+
items, ok := m.StateTree.Categories[config.cat]
|
|
160
|
+
if !ok || len(items) == 0 {
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
s.WriteString(HeaderStyle.Render(config.label))
|
|
165
|
+
s.WriteString("\n")
|
|
166
|
+
|
|
167
|
+
for _, item := range items {
|
|
168
|
+
s.WriteString(m.renderItem(item))
|
|
169
|
+
}
|
|
170
|
+
s.WriteString("\n")
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 4. Error Message
|
|
174
|
+
if m.errorMsg != "" {
|
|
175
|
+
s.WriteString("\n")
|
|
176
|
+
s.WriteString(RenderErrorBadge(m.errorMsg))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return lipgloss.NewStyle().Padding(1, 2).Width(m.width - 4).Render(s.String())
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
func (m *ConsoleModel) renderLogo() string {
|
|
183
|
+
return GenerateLogo(true) + "\n"
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
func (m *ConsoleModel) renderItem(item spec.StateItem) string {
|
|
187
|
+
var s strings.Builder
|
|
188
|
+
|
|
189
|
+
marker := " "
|
|
190
|
+
style := BodyStyle
|
|
191
|
+
|
|
192
|
+
// High-density info based on category
|
|
193
|
+
switch item.Category {
|
|
194
|
+
case spec.CategoryConstitution:
|
|
195
|
+
icon := MutedStyle.Render("○")
|
|
196
|
+
if item.Progress == 100 {
|
|
197
|
+
icon = FinishedStyle.Render("◉")
|
|
198
|
+
}
|
|
199
|
+
name := style.Render(item.Name)
|
|
200
|
+
metadata := MutedStyle.Render(fmt.Sprintf("Active (%s)", item.Path))
|
|
201
|
+
fmt.Fprintf(&s, "%s%s %-15s : %s\n", marker, icon, name, metadata)
|
|
202
|
+
case spec.CategoryActiveSpecs:
|
|
203
|
+
icon := MutedStyle.Render("○")
|
|
204
|
+
if item.Progress == 100 {
|
|
205
|
+
icon = FinishedStyle.Render("◉")
|
|
206
|
+
}
|
|
207
|
+
artifactStatus := MutedStyle.Render(fmt.Sprintf("(%d/%d artifacts)", item.ArtifactCount, item.ArtifactTotal))
|
|
208
|
+
fmt.Fprintf(&s, "%s%s %s - %s %s\n", marker, icon, style.Render(item.Slug), RenderProgressBar(item.Progress, 20), artifactStatus)
|
|
209
|
+
case spec.CategoryImplementations:
|
|
210
|
+
icon := MutedStyle.Render("○")
|
|
211
|
+
if item.Progress == 100 {
|
|
212
|
+
icon = FinishedStyle.Render("◉")
|
|
213
|
+
} else if item.AnyTaskWorking {
|
|
214
|
+
icon = InProgressStyle.Render("◉")
|
|
215
|
+
}
|
|
216
|
+
taskStatus := MutedStyle.Render(fmt.Sprintf("(%d/%d tasks)", item.TaskCount, item.TaskTotal))
|
|
217
|
+
fmt.Fprintf(&s, "%s%s %s - %s %s\n", marker, icon, style.Render(item.Slug), RenderProgressBar(item.Progress, 20), taskStatus)
|
|
218
|
+
// Contextual Task Detail
|
|
219
|
+
var detail string
|
|
220
|
+
if item.Progress == 100 {
|
|
221
|
+
detail = "All tasks complete"
|
|
222
|
+
} else if item.AnyTaskWorking {
|
|
223
|
+
detail = fmt.Sprintf("Working on: %s %s", item.CurrentTaskID, item.CurrentTask)
|
|
224
|
+
} else {
|
|
225
|
+
detail = fmt.Sprintf("Next task: %s %s", item.CurrentTaskID, item.CurrentTask)
|
|
226
|
+
}
|
|
227
|
+
fmt.Fprintf(&s, " %s %s\n", marker, MutedStyle.Render("↳ "+detail))
|
|
228
|
+
case spec.CategoryArchived:
|
|
229
|
+
icon := MutedStyle.Render("○")
|
|
230
|
+
metadata := MutedStyle.Render(fmt.Sprintf("(Archived on: %s)", item.ArchivedDate))
|
|
231
|
+
fmt.Fprintf(&s, "%s%s %-20s %s\n", marker, icon, style.Render(item.Slug), metadata)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return s.String()
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
func (m *ConsoleModel) renderEmptyStateContent() string {
|
|
238
|
+
return `[ NO ACTIVE SPECIFICATIONS FOUND ]
|
|
239
|
+
|
|
240
|
+
Your .specforce/ directory is currently empty or uninitialized.
|
|
241
|
+
|
|
242
|
+
To get started:
|
|
243
|
+
1. Run 'specforce init' to set up the framework.
|
|
244
|
+
2. Run 'specforce spec init <slug>' to create your first spec.
|
|
245
|
+
|
|
246
|
+
Press 'q' or 'Esc' to exit.`
|
|
247
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package tui
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"testing"
|
|
6
|
+
"github.com/jeancodogno/specforce-kit/src/internal/spec"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestConsoleModel_Initialization(t *testing.T) {
|
|
10
|
+
tree := spec.NewStateTree()
|
|
11
|
+
tree.Categories[spec.CategoryConstitution] = []spec.StateItem{{Name: "Architecture", Category: spec.CategoryConstitution}}
|
|
12
|
+
tree.Categories[spec.CategoryImplementations] = []spec.StateItem{{Name: "Feature A", Category: spec.CategoryImplementations}}
|
|
13
|
+
|
|
14
|
+
model := NewConsoleModel(context.Background(), tree, &spec.Registry{}, ".")
|
|
15
|
+
|
|
16
|
+
if model.StateTree == nil {
|
|
17
|
+
t.Errorf("Expected StateTree to be initialized")
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package tui
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"strings"
|
|
6
|
+
|
|
7
|
+
"github.com/charmbracelet/lipgloss"
|
|
8
|
+
"github.com/jeancodogno/specforce-kit/src/internal/constitution"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// RenderConstitutionStatus renders a checklist of the constitution artifacts.
|
|
12
|
+
func RenderConstitutionStatus(status constitution.ConstitutionStatus) string {
|
|
13
|
+
var builder strings.Builder
|
|
14
|
+
|
|
15
|
+
// Styles
|
|
16
|
+
successStyle := lipgloss.NewStyle().Foreground(successGreen)
|
|
17
|
+
errorStyle := lipgloss.NewStyle().Foreground(errorRed)
|
|
18
|
+
descStyle := lipgloss.NewStyle().Foreground(textGrey)
|
|
19
|
+
nameStyle := lipgloss.NewStyle().Foreground(textWhite).Bold(true)
|
|
20
|
+
|
|
21
|
+
for _, artifact := range status.Artifacts {
|
|
22
|
+
glyph := errorStyle.Render(EmptyBulletGlyph)
|
|
23
|
+
if artifact.Exists {
|
|
24
|
+
glyph = successStyle.Render(BulletGlyph)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Align columns: Glyph [Name] Description
|
|
28
|
+
// Assume name max length around 15-20 characters for padding
|
|
29
|
+
name := nameStyle.Render(fmt.Sprintf("%-16s", artifact.Name))
|
|
30
|
+
description := descStyle.Render(artifact.Description)
|
|
31
|
+
|
|
32
|
+
fmt.Fprintf(&builder, " %s %s %s\n", glyph, name, description)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return builder.String()
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package tui
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
"github.com/jeancodogno/specforce-kit/src/internal/constitution"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func TestRenderConstitutionStatus(t *testing.T) {
|
|
11
|
+
status := constitution.ConstitutionStatus{
|
|
12
|
+
Artifacts: []constitution.ArtifactStatus{
|
|
13
|
+
{Name: "principles.md", Description: "Core values", Exists: true},
|
|
14
|
+
{Name: "security.md", Description: "Auth rules", Exists: false},
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
got := RenderConstitutionStatus(status)
|
|
19
|
+
|
|
20
|
+
if !strings.Contains(got, "principles.md") {
|
|
21
|
+
t.Errorf("RenderConstitutionStatus() = %q, want it to contain %q", got, "principles.md")
|
|
22
|
+
}
|
|
23
|
+
if !strings.Contains(got, "security.md") {
|
|
24
|
+
t.Errorf("RenderConstitutionStatus() = %q, want it to contain %q", got, "security.md")
|
|
25
|
+
}
|
|
26
|
+
if !strings.Contains(got, BulletGlyph) {
|
|
27
|
+
t.Errorf("RenderConstitutionStatus() should contain BulletGlyph for exists:true")
|
|
28
|
+
}
|
|
29
|
+
if !strings.Contains(got, EmptyBulletGlyph) {
|
|
30
|
+
t.Errorf("RenderConstitutionStatus() should contain EmptyBulletGlyph for exists:false")
|
|
31
|
+
}
|
|
32
|
+
}
|