@jeancodogno/specforce-kit 0.1.5 → 0.1.7

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 +46 -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,142 +0,0 @@
1
- package spec
2
-
3
- import (
4
- "fmt"
5
- "io/fs"
6
- "strings"
7
-
8
- "gopkg.in/yaml.v3"
9
- )
10
-
11
- // Artifact represents a specification document type.
12
- type Artifact struct {
13
- Name string `json:"name" yaml:"-"`
14
- Description string `json:"description" yaml:"description"`
15
- Instruction string `json:"instruction" yaml:"instruction"`
16
- Template string `json:"template" yaml:"template"`
17
- Dependency string `json:"dependency" yaml:"dependency"`
18
- }
19
-
20
- // Registry manages the collection of spec artifacts.
21
- type Registry struct {
22
- artifacts map[string]Artifact
23
- }
24
-
25
- // NewRegistry initializes a new registry by loading YAML files from the provided filesystem.
26
- func NewRegistry(artifactsFS fs.FS) (*Registry, error) {
27
- r := &Registry{
28
- artifacts: make(map[string]Artifact),
29
- }
30
-
31
- artifactRoot := "."
32
-
33
- err := fs.WalkDir(artifactsFS, artifactRoot, func(path string, d fs.DirEntry, err error) error {
34
- if err != nil {
35
- return err
36
- }
37
- if d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") {
38
- return nil
39
- }
40
-
41
- art, err := loadArtifact(artifactsFS, path, d.Name())
42
- if err != nil {
43
- return err
44
- }
45
-
46
- r.artifacts[art.Name] = art
47
- return nil
48
- })
49
-
50
- if err != nil {
51
- return nil, fmt.Errorf("failed to load spec artifacts: %w", err)
52
- }
53
-
54
- // Circular dependency check
55
- if err := r.checkCircularDependencies(); err != nil {
56
- return nil, err
57
- }
58
-
59
- return r, nil
60
- }
61
-
62
- func loadArtifact(artifactsFS fs.FS, path, fileName string) (Artifact, error) {
63
- data, err := fs.ReadFile(artifactsFS, path)
64
- if err != nil {
65
- return Artifact{}, fmt.Errorf("failed to read artifact %s: %w", path, err)
66
- }
67
-
68
- var art Artifact
69
- if err := yaml.Unmarshal(data, &art); err != nil {
70
- return Artifact{}, fmt.Errorf("failed to parse artifact %s: %w", path, err)
71
- }
72
-
73
- // Validation: Check required fields
74
- if art.Description == "" {
75
- return Artifact{}, fmt.Errorf("artifact %s is missing 'description'", path)
76
- }
77
- if art.Instruction == "" {
78
- return Artifact{}, fmt.Errorf("artifact %s is missing 'instruction'", path)
79
- }
80
- if art.Template == "" {
81
- return Artifact{}, fmt.Errorf("artifact %s is missing 'template'", path)
82
- }
83
-
84
- // Name is derived from the filename without extension
85
- art.Name = strings.TrimSuffix(fileName, ".yaml")
86
-
87
- return art, nil
88
- }
89
-
90
- // Get returns an artifact by its name.
91
- func (r *Registry) Get(name string) (Artifact, bool) {
92
- art, ok := r.artifacts[name]
93
- return art, ok
94
- }
95
-
96
- // List returns all loaded artifacts.
97
- func (r *Registry) List() []Artifact {
98
- list := make([]Artifact, 0, len(r.artifacts))
99
- // Standard order: requirements, design, tasks
100
- order := []string{"requirements", "design", "tasks"}
101
-
102
- for _, name := range order {
103
- if art, ok := r.artifacts[name]; ok {
104
- list = append(list, art)
105
- }
106
- }
107
-
108
- // Catch any artifacts not in the explicit order
109
- for name, art := range r.artifacts {
110
- found := false
111
- for _, orderedName := range order {
112
- if name == orderedName {
113
- found = true
114
- break
115
- }
116
- }
117
- if !found {
118
- list = append(list, art)
119
- }
120
- }
121
-
122
- return list
123
- }
124
-
125
- func (r *Registry) checkCircularDependencies() error {
126
- for name := range r.artifacts {
127
- visited := make(map[string]bool)
128
- curr := name
129
- for curr != "" {
130
- if visited[curr] {
131
- return fmt.Errorf("circular dependency detected involving artifact: %s", curr)
132
- }
133
- visited[curr] = true
134
- art, ok := r.artifacts[curr]
135
- if !ok {
136
- break
137
- }
138
- curr = art.Dependency
139
- }
140
- }
141
- return nil
142
- }
@@ -1,105 +0,0 @@
1
- package spec
2
-
3
- import (
4
- "strings"
5
- "testing"
6
- "testing/fstest"
7
- )
8
-
9
- func TestNewRegistry(t *testing.T) {
10
- fs := fstest.MapFS{
11
- "requirements.yaml": {
12
- Data: []byte("description: Req Desc\ninstruction: Req Inst\ntemplate: Req Temp\n"),
13
- },
14
- "design.yaml": {
15
- Data: []byte("description: Design Desc\ninstruction: Design Inst\ntemplate: Design Temp\ndependency: requirements\n"),
16
- },
17
- "tasks.yaml": {
18
- Data: []byte("description: Task Desc\ninstruction: Task Inst\ntemplate: Task Temp\ndependency: design\n"),
19
- },
20
- }
21
-
22
- registry, err := NewRegistry(fs)
23
- if err != nil {
24
- t.Fatalf("NewRegistry failed: %v", err)
25
- }
26
- if registry == nil {
27
- t.Fatal("NewRegistry returned nil registry")
28
- }
29
-
30
- // Check Get
31
- art, ok := registry.Get("requirements")
32
- if !ok {
33
- t.Error("artifact 'requirements' not found")
34
- }
35
- if art.Name != "requirements" {
36
- t.Errorf("expected name 'requirements', got '%s'", art.Name)
37
- }
38
- if art.Description != "Req Desc" {
39
- t.Errorf("expected description 'Req Desc', got '%s'", art.Description)
40
- }
41
-
42
- art, ok = registry.Get("design")
43
- if !ok {
44
- t.Error("artifact 'design' not found")
45
- }
46
- if art.Dependency != "requirements" {
47
- t.Errorf("expected dependency 'requirements', got '%s'", art.Dependency)
48
- }
49
-
50
- // Check List order
51
- list := registry.List()
52
- if len(list) != 3 {
53
- t.Errorf("expected list length 3, got %d", len(list))
54
- }
55
- if list[0].Name != "requirements" {
56
- t.Errorf("expected first element 'requirements', got '%s'", list[0].Name)
57
- }
58
- if list[1].Name != "design" {
59
- t.Errorf("expected second element 'design', got '%s'", list[1].Name)
60
- }
61
- if list[2].Name != "tasks" {
62
- t.Errorf("expected third element 'tasks', got '%s'", list[2].Name)
63
- }
64
- }
65
-
66
- func TestNewRegistry_CircularDependency(t *testing.T) {
67
- fs := fstest.MapFS{
68
- "a.yaml": {
69
- Data: []byte("description: A\ninstruction: A\ntemplate: A\ndependency: b\n"),
70
- },
71
- "b.yaml": {
72
- Data: []byte("description: B\ninstruction: B\ntemplate: B\ndependency: a\n"),
73
- },
74
- }
75
-
76
- registry, err := NewRegistry(fs)
77
- if err == nil {
78
- t.Fatal("expected error for circular dependency, got nil")
79
- }
80
- if !strings.Contains(err.Error(), "circular dependency detected") {
81
- t.Errorf("expected circular dependency error message, got: %v", err)
82
- }
83
- if registry != nil {
84
- t.Error("expected nil registry on error")
85
- }
86
- }
87
-
88
- func TestNewRegistry_MissingFields(t *testing.T) {
89
- fs := fstest.MapFS{
90
- "invalid.yaml": {
91
- Data: []byte("description: Only Desc\n"),
92
- },
93
- }
94
-
95
- registry, err := NewRegistry(fs)
96
- if err == nil {
97
- t.Fatal("expected error for missing fields, got nil")
98
- }
99
- if !strings.Contains(err.Error(), "missing 'instruction'") {
100
- t.Errorf("expected missing instruction error, got: %v", err)
101
- }
102
- if registry != nil {
103
- t.Error("expected nil registry on error")
104
- }
105
- }
@@ -1,219 +0,0 @@
1
- package spec
2
-
3
- import (
4
- "context"
5
- "os"
6
- "path/filepath"
7
- "sort"
8
- "strings"
9
-
10
- "golang.org/x/text/cases"
11
- "golang.org/x/text/language"
12
- )
13
-
14
- // StateCategory defines the top-level grouping for project state items.
15
- type StateCategory string
16
-
17
- const (
18
- CategoryConstitution StateCategory = "Constitution"
19
- CategoryActiveSpecs StateCategory = "Active Specs"
20
- CategoryImplementations StateCategory = "Active Implementations"
21
- CategoryArchived StateCategory = "Archived"
22
- )
23
-
24
- // StateItem represents a single navigatable entry in the Specforce Console.
25
- type StateItem struct {
26
- Slug string `json:"slug"`
27
- Name string `json:"name"`
28
- Path string `json:"path"`
29
- Category StateCategory `json:"category"`
30
- Status string `json:"status"` // PENDING | IN-PROGRESS | FINISHED
31
- Progress int `json:"progress"`
32
- Description string `json:"description"`
33
- ArtifactCount int `json:"artifact_count"`
34
- ArtifactTotal int `json:"artifact_total"`
35
- TaskCount int `json:"task_count"`
36
- TaskTotal int `json:"task_total"`
37
- AnyTaskWorking bool `json:"any_task_working"`
38
- CurrentTaskID string `json:"current_task_id"`
39
- CurrentTask string `json:"current_task"`
40
- ArchivedDate string `json:"archived_date"`
41
- }
42
-
43
- // StateTree represents the full hierarchical state of a Specforce project.
44
- type StateTree struct {
45
- Categories map[StateCategory][]StateItem `json:"categories"`
46
- }
47
-
48
- // NewStateTree initializes a new, empty state tree.
49
- func NewStateTree() *StateTree {
50
- return &StateTree{
51
- Categories: make(map[StateCategory][]StateItem),
52
- }
53
- }
54
-
55
- // ScanProject synchronously parses the .specforce directory to populate a StateTree.
56
- func ScanProject(ctx context.Context, projectRoot string, registry *Registry) (*StateTree, error) {
57
- if err := ctx.Err(); err != nil {
58
- return nil, err
59
- }
60
-
61
- tree := NewStateTree()
62
-
63
- // 1. Scan Constitution documents (.specforce/docs/)
64
- if err := scanConstitution(ctx, projectRoot, tree); err != nil {
65
- return nil, err
66
- }
67
-
68
- // 2. Scan Active Specs and Implementations (.specforce/specs/)
69
- if err := scanActiveSpecs(ctx, projectRoot, tree, registry); err != nil {
70
- return nil, err
71
- }
72
-
73
- // 3. Scan Archived specs (.specforce/archive/)
74
- if err := scanArchivedSpecs(ctx, projectRoot, tree); err != nil {
75
- return nil, err
76
- }
77
-
78
- return tree, nil
79
- }
80
-
81
- func scanConstitution(ctx context.Context, projectRoot string, tree *StateTree) error {
82
- docsDir := filepath.Join(projectRoot, ".specforce", "docs")
83
- entries, err := os.ReadDir(docsDir)
84
- if err != nil {
85
- return nil // No docs dir is fine
86
- }
87
-
88
- for _, entry := range entries {
89
- if err := ctx.Err(); err != nil {
90
- return err
91
- }
92
- if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") || entry.Name() == "current-state.md" || entry.Name() == "memorial.md" {
93
- continue
94
- }
95
- slug := strings.TrimSuffix(entry.Name(), ".md")
96
- tree.Categories[CategoryConstitution] = append(tree.Categories[CategoryConstitution], StateItem{
97
- Slug: slug,
98
- Name: cases.Title(language.Und).String(strings.ReplaceAll(slug, "-", " ")),
99
- Path: filepath.Join(".specforce", "docs", entry.Name()),
100
- Category: CategoryConstitution,
101
- Status: "FINISHED",
102
- Progress: 100,
103
- })
104
- }
105
- return nil
106
- }
107
-
108
- func scanActiveSpecs(ctx context.Context, projectRoot string, tree *StateTree, registry *Registry) error {
109
- specsDir := filepath.Join(projectRoot, ".specforce", "specs")
110
- entries, err := os.ReadDir(specsDir)
111
- if err != nil {
112
- return nil
113
- }
114
-
115
- for _, entry := range entries {
116
- if err := ctx.Err(); err != nil {
117
- return err
118
- }
119
- if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
120
- continue
121
- }
122
-
123
- item := scanSingleActiveSpec(ctx, projectRoot, entry.Name(), registry)
124
- tree.Categories[item.Category] = append(tree.Categories[item.Category], item)
125
- }
126
- return nil
127
- }
128
-
129
- func scanSingleActiveSpec(ctx context.Context, projectRoot, slug string, registry *Registry) StateItem {
130
- item := StateItem{
131
- Slug: slug,
132
- Name: slug,
133
- Path: filepath.Join(".specforce", "specs", slug),
134
- Category: CategoryActiveSpecs,
135
- Status: "PENDING",
136
- }
137
-
138
- if status, err := GetStatus(ctx, projectRoot, slug, registry); err == nil {
139
- item.Progress = status.Progress
140
- item.ArtifactCount = status.Found
141
- item.ArtifactTotal = status.Total
142
- }
143
-
144
- tasksPath := filepath.Join(projectRoot, ".specforce", "specs", slug, "tasks.md")
145
- if _, err := os.Stat(tasksPath); err == nil {
146
- item.Category = CategoryImplementations
147
- if report, err := ParseTasks(ctx, projectRoot, slug); err == nil {
148
- item.Status = strings.ToUpper(report.Status)
149
- item.TaskTotal = len(report.Tasks())
150
- foundFinished := 0
151
- for _, t := range report.Tasks() {
152
- state := strings.ToUpper(t.State)
153
- if state == "FINISHED" || state == "X" {
154
- foundFinished++
155
- } else {
156
- if state == "IN-PROGRESS" {
157
- item.AnyTaskWorking = true
158
- }
159
- if item.CurrentTaskID == "" {
160
- item.CurrentTaskID = t.ID
161
- item.CurrentTask = t.Title
162
- }
163
- }
164
- }
165
- item.TaskCount = foundFinished
166
- if item.TaskTotal > 0 {
167
- item.Progress = (foundFinished * 100) / item.TaskTotal
168
- }
169
- if item.CurrentTask == "" && foundFinished == item.TaskTotal {
170
- item.CurrentTask = "All tasks complete"
171
- }
172
- }
173
- }
174
- return item
175
- }
176
-
177
- func scanArchivedSpecs(ctx context.Context, projectRoot string, tree *StateTree) error {
178
- archiveDir := filepath.Join(projectRoot, ".specforce", "archive")
179
- entries, err := os.ReadDir(archiveDir)
180
- if err != nil {
181
- return nil
182
- }
183
-
184
- archivedItems := []StateItem{}
185
- for _, entry := range entries {
186
- if err := ctx.Err(); err != nil {
187
- return err
188
- }
189
- if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
190
- continue
191
- }
192
-
193
- date := "2026-04-16"
194
- if info, err := entry.Info(); err == nil {
195
- date = info.ModTime().Format("2006-01-02")
196
- }
197
-
198
- archivedItems = append(archivedItems, StateItem{
199
- Slug: entry.Name(),
200
- Name: entry.Name(),
201
- Path: filepath.Join(".specforce", "archive", entry.Name()),
202
- Category: CategoryArchived,
203
- Status: "FINISHED",
204
- Progress: 100,
205
- ArchivedDate: date,
206
- })
207
- }
208
-
209
- sort.Slice(archivedItems, func(i, j int) bool {
210
- return archivedItems[i].ArchivedDate > archivedItems[j].ArchivedDate
211
- })
212
-
213
- if len(archivedItems) > 10 {
214
- archivedItems = archivedItems[:10]
215
- }
216
-
217
- tree.Categories[CategoryArchived] = archivedItems
218
- return nil
219
- }
@@ -1,243 +0,0 @@
1
- package spec
2
-
3
- import (
4
- "context"
5
- "errors"
6
- "os"
7
- "path/filepath"
8
- "strings"
9
- "testing"
10
-
11
- "github.com/jeancodogno/specforce-kit/src/internal/core"
12
- )
13
-
14
- func setupMockProject(t *testing.T, tempDir string) {
15
- // 1. Setup mock .specforce structure
16
- specforceDir := filepath.Join(tempDir, ".specforce")
17
- docsDir := filepath.Join(specforceDir, "docs")
18
- specsDir := filepath.Join(specforceDir, "specs")
19
- archiveDir := filepath.Join(specforceDir, "archive")
20
-
21
- dirs := []string{docsDir, specsDir, archiveDir}
22
- for _, d := range dirs {
23
- if err := os.MkdirAll(d, 0755); err != nil {
24
- t.Fatalf("Failed to create mock dir %s: %v", d, err)
25
- }
26
- }
27
-
28
- // 2. Add mock files
29
- // Constitution doc
30
- if err := os.WriteFile(filepath.Join(docsDir, "architecture.md"), []byte("# Architecture"), 0644); err != nil {
31
- t.Fatalf("Failed to create mock doc: %v", err)
32
- }
33
- // Active Spec
34
- activeSpecDir := filepath.Join(specsDir, "0001-test-spec")
35
- if err := os.MkdirAll(activeSpecDir, 0755); err != nil {
36
- t.Fatalf("Failed to create mock spec dir: %v", err)
37
- }
38
- if err := os.WriteFile(filepath.Join(activeSpecDir, "requirements.md"), []byte("# Requirements"), 0644); err != nil {
39
- t.Fatalf("Failed to create mock requirement doc: %v", err)
40
- }
41
- // Active Implementation (has tasks.md)
42
- implSpecDir := filepath.Join(specsDir, "0002-test-impl")
43
- if err := os.MkdirAll(implSpecDir, 0755); err != nil {
44
- t.Fatalf("Failed to create mock impl dir: %v", err)
45
- }
46
- if err := os.WriteFile(filepath.Join(implSpecDir, "tasks.md"), []byte("## 2. Tasks\n### T1.1: [SCAFFOLD] Task\n**State:** `[PENDING]`"), 0644); err != nil {
47
- t.Fatalf("Failed to create mock task doc: %v", err)
48
- }
49
- // Archived Spec
50
- archivedSpecDir := filepath.Join(archiveDir, "0003-test-archive")
51
- if err := os.MkdirAll(archivedSpecDir, 0755); err != nil {
52
- t.Fatalf("Failed to create mock archive dir: %v", err)
53
- }
54
- }
55
-
56
- func TestScanProject(t *testing.T) {
57
- tempDir := t.TempDir()
58
- setupMockProject(t, tempDir)
59
-
60
- // 3. Mock registry
61
- registry := &Registry{
62
- artifacts: map[string]Artifact{
63
- "requirements": {Name: "requirements"},
64
- "design": {Name: "design"},
65
- "tasks": {Name: "tasks"},
66
- },
67
- }
68
-
69
- // 4. Execute scan
70
- tree, err := ScanProject(context.Background(), tempDir, registry)
71
- if err != nil {
72
- t.Fatalf("ScanProject failed: %v", err)
73
- }
74
-
75
- // 5. Assertions
76
- if len(tree.Categories[CategoryConstitution]) != 1 {
77
- t.Errorf("Expected 1 constitution doc, got %d", len(tree.Categories[CategoryConstitution]))
78
- }
79
- if len(tree.Categories[CategoryActiveSpecs]) != 1 {
80
- t.Errorf("Expected 1 active spec, got %d", len(tree.Categories[CategoryActiveSpecs]))
81
- }
82
- if len(tree.Categories[CategoryImplementations]) != 1 {
83
- t.Errorf("Expected 1 active implementation, got %d", len(tree.Categories[CategoryImplementations]))
84
- }
85
- if len(tree.Categories[CategoryArchived]) != 1 {
86
- t.Errorf("Expected 1 archived spec, got %d", len(tree.Categories[CategoryArchived]))
87
- }
88
-
89
- // Check status
90
- if tree.Categories[CategoryImplementations][0].Status != "READY" {
91
- t.Errorf("Expected READY status for implementation, got %s", tree.Categories[CategoryImplementations][0].Status)
92
- }
93
- }
94
-
95
- func TestScanProject_Cancellation(t *testing.T) {
96
- tempDir := t.TempDir()
97
-
98
- // Setup many files to increase chance of catching it (though here it's synchronous)
99
- docsDir := filepath.Join(tempDir, ".specforce", "docs")
100
- _ = os.MkdirAll(docsDir, 0755)
101
- for i := 0; i < 100; i++ {
102
- _ = os.WriteFile(filepath.Join(docsDir, filepath.Join(string(rune(i)), ".md")), []byte("# Test"), 0644)
103
- }
104
-
105
- ctx, cancel := context.WithCancel(context.Background())
106
- cancel() // Cancel immediately
107
-
108
- _, err := ScanProject(ctx, tempDir, nil)
109
- if err == nil {
110
- t.Fatal("expected error for cancelled context, got nil")
111
- }
112
- if !errors.Is(err, context.Canceled) {
113
- t.Errorf("expected context.Canceled, got %v", err)
114
- }
115
- }
116
-
117
- func TestParseTasks_InvalidFile_ReturnsErrInvalidSpecFile(t *testing.T) {
118
- tmpDir := t.TempDir()
119
-
120
- slug := "bad-spec"
121
- // Create the spec directory but do NOT create tasks.md
122
- specDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
123
- if err := os.MkdirAll(specDir, 0755); err != nil {
124
- t.Fatalf("failed to create spec dir: %v", err)
125
- }
126
-
127
- _, err := ParseTasks(context.Background(), tmpDir, slug)
128
- if err == nil {
129
- t.Fatal("expected an error for missing tasks.md, got nil")
130
- }
131
-
132
- if !errors.Is(err, core.ErrInvalidSpecFile) {
133
- t.Errorf("expected errors.Is(err, core.ErrInvalidSpecFile) to be true, got: %v", err)
134
- }
135
- }
136
-
137
- func TestScanProject_AnyTaskWorking(t *testing.T) {
138
- tempDir := t.TempDir()
139
-
140
- // 1. Setup mock .specforce structure
141
- specsDir := filepath.Join(tempDir, ".specforce", "specs")
142
- implSpecDir := filepath.Join(specsDir, "working-impl")
143
- if err := os.MkdirAll(implSpecDir, 0755); err != nil {
144
- t.Fatalf("Failed to create mock impl dir: %v", err)
145
- }
146
-
147
- // 2. Add tasks.md with an in-progress task
148
- content := "## 2. Tasks\n### T1.1: [SCAFFOLD] Working Task\n**State:** `[IN-PROGRESS]`"
149
- if err := os.WriteFile(filepath.Join(implSpecDir, "tasks.md"), []byte(content), 0644); err != nil {
150
- t.Fatalf("Failed to create mock tasks.md: %v", err)
151
- }
152
-
153
- // 3. Mock registry
154
- registry := &Registry{
155
- artifacts: map[string]Artifact{
156
- "tasks": {Name: "tasks"},
157
- },
158
- }
159
-
160
- // 4. Execute scan
161
- tree, err := ScanProject(context.Background(), tempDir, registry)
162
- if err != nil {
163
- t.Fatalf("ScanProject failed: %v", err)
164
- }
165
-
166
- // 5. Assertions
167
- found := false
168
- for _, item := range tree.Categories[CategoryImplementations] {
169
- if item.Slug == "working-impl" {
170
- found = true
171
- if !item.AnyTaskWorking {
172
- t.Errorf("Expected AnyTaskWorking to be true for working-impl")
173
- }
174
- }
175
- }
176
- if !found {
177
- t.Errorf("Expected to find working-impl in CategoryImplementations")
178
- }
179
-
180
- t.Run("Task State X", func(t *testing.T) {
181
- implXDir := filepath.Join(specsDir, "x-impl")
182
- if err := os.MkdirAll(implXDir, 0755); err != nil {
183
- t.Fatal(err)
184
- }
185
- contentX := "## 2. Tasks\n### T1.1: Task X\n**State:** `[X]`"
186
- if err := os.WriteFile(filepath.Join(implXDir, "tasks.md"), []byte(contentX), 0644); err != nil {
187
- t.Fatal(err)
188
- }
189
- tree, _ := ScanProject(context.Background(), tempDir, registry)
190
- foundX := false
191
- for _, item := range tree.Categories[CategoryImplementations] {
192
- if item.Slug == "x-impl" {
193
- foundX = true
194
- if item.TaskCount != 1 {
195
- t.Errorf("Expected TaskCount 1 for X state, got %d", item.TaskCount)
196
- }
197
- }
198
- }
199
- if !foundX {
200
- t.Errorf("Expected to find x-impl")
201
- }
202
- })
203
- }
204
-
205
- func TestScanProject_ArchiveLimits(t *testing.T) {
206
- tempDir := t.TempDir()
207
- archiveDir := filepath.Join(tempDir, ".specforce", "archive")
208
- if err := os.MkdirAll(archiveDir, 0755); err != nil {
209
- t.Fatal(err)
210
- }
211
-
212
- // Create 12 archived items
213
- for i := 0; i < 12; i++ {
214
- name := filepath.Join(archiveDir, filepath.Join(string(rune('a'+i)), "folder"))
215
- if err := os.MkdirAll(name, 0755); err != nil {
216
- t.Fatal(err)
217
- }
218
- }
219
-
220
- // Hidden file and hidden dir in archive
221
- if err := os.WriteFile(filepath.Join(archiveDir, ".hidden-file"), []byte("data"), 0644); err != nil {
222
- t.Fatal(err)
223
- }
224
- if err := os.MkdirAll(filepath.Join(archiveDir, ".hidden-dir"), 0755); err != nil {
225
- t.Fatal(err)
226
- }
227
-
228
- tree, err := ScanProject(context.Background(), tempDir, nil)
229
- if err != nil {
230
- t.Fatal(err)
231
- }
232
-
233
- archived := tree.Categories[CategoryArchived]
234
- if len(archived) != 10 {
235
- t.Errorf("Expected archive limit of 10, got %d", len(archived))
236
- }
237
-
238
- for _, item := range archived {
239
- if strings.HasPrefix(item.Slug, ".") {
240
- t.Errorf("Archive scan should ignore hidden entries: %s", item.Slug)
241
- }
242
- }
243
- }