@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.
- package/index.js +46 -0
- package/package.json +12 -28
- package/.geminiignore +0 -15
- package/.github/workflows/ci.yml +0 -104
- package/.github/workflows/release.yml +0 -51
- package/.golangci.yml +0 -24
- package/.goreleaser.yaml +0 -39
- package/.rgignore +0 -13
- package/.specforce/archive/agents-md-hooks-config/design.md +0 -38
- package/.specforce/archive/agents-md-hooks-config/requirements.md +0 -35
- package/.specforce/archive/agents-md-hooks-config/tasks.md +0 -76
- package/.specforce/config.yaml +0 -32
- package/.specforce/docs/.gitkeep +0 -0
- package/.specforce/docs/architecture.md +0 -98
- package/.specforce/docs/engineering.md +0 -84
- package/.specforce/docs/governance.md +0 -30
- package/.specforce/docs/memorial.md +0 -45
- package/.specforce/docs/principles.md +0 -31
- package/.specforce/docs/security.md +0 -31
- package/.specforce/docs/ui-ux.md +0 -129
- package/.specforce/specs/.gitkeep +0 -0
- package/AGENTS.md +0 -46
- package/CONTRIBUTING.md +0 -81
- package/Makefile +0 -49
- package/assets/logo-header.png +0 -0
- package/assets/logo.png +0 -0
- package/docs/artifacts.md +0 -41
- package/docs/cli.md +0 -73
- package/docs/configuration.md +0 -59
- package/docs/getting-started.md +0 -110
- package/docs/supported-tools.md +0 -28
- package/go.mod +0 -35
- package/go.sum +0 -61
- package/src/cmd/specforce/main.go +0 -23
- package/src/cmd/specforce/main_test.go +0 -7
- package/src/internal/agent/artifacts/constitution/architecture.yaml +0 -70
- package/src/internal/agent/artifacts/constitution/engineering.yaml +0 -52
- package/src/internal/agent/artifacts/constitution/governance.yaml +0 -41
- package/src/internal/agent/artifacts/constitution/memorial.yaml +0 -55
- package/src/internal/agent/artifacts/constitution/principles.yaml +0 -54
- package/src/internal/agent/artifacts/constitution/security.yaml +0 -47
- package/src/internal/agent/artifacts/constitution/ui-ux.yaml +0 -158
- package/src/internal/agent/artifacts/spec/design.yaml +0 -50
- package/src/internal/agent/artifacts/spec/requirements.yaml +0 -48
- package/src/internal/agent/artifacts/spec/tasks.yaml +0 -55
- package/src/internal/agent/compatibility_test.go +0 -120
- package/src/internal/agent/cwd_test.go +0 -9
- package/src/internal/agent/embed.go +0 -19
- package/src/internal/agent/integration_test.go +0 -138
- package/src/internal/agent/kit/agents/product-analyst.yaml +0 -31
- package/src/internal/agent/kit/agents/technical-developer.yaml +0 -28
- package/src/internal/agent/kit/agents/technical-project-planner.yaml +0 -30
- package/src/internal/agent/kit/agents/technical-qa-engineer.yaml +0 -36
- package/src/internal/agent/kit/agents/technical-solution-architect.yaml +0 -32
- package/src/internal/agent/kit/commands/archive.yaml +0 -25
- package/src/internal/agent/kit/commands/constitution.yaml +0 -132
- package/src/internal/agent/kit/commands/implement.yaml +0 -96
- package/src/internal/agent/kit/commands/spec.yaml +0 -94
- package/src/internal/agent/kit/instructions/archive.md +0 -68
- package/src/internal/agent/kit/kit.yaml +0 -111
- package/src/internal/agent/kit/skills/opportunity-framing/SKILL.yaml +0 -56
- package/src/internal/agent/kit/skills/pragmatic-product-owner/SKILL.yaml +0 -58
- package/src/internal/agent/kit/skills/pragmatic-product-owner/references/spec-artifacts.yaml +0 -38
- package/src/internal/agent/kit/skills/spec-clarification-interview/SKILL.yaml +0 -52
- package/src/internal/agent/kit/skills/task-atomic-decomposition/SKILL.yaml +0 -137
- package/src/internal/agent/kit/skills/task-atomic-decomposition/references/roadmap-patterns.yaml +0 -103
- package/src/internal/agent/kit_manifests_test.go +0 -58
- package/src/internal/agent/manifest.go +0 -15
- package/src/internal/agent/registry.go +0 -69
- package/src/internal/agent/registry_test.go +0 -51
- package/src/internal/agent/translator.go +0 -334
- package/src/internal/agent/translator_test.go +0 -734
- package/src/internal/cli/archive.go +0 -91
- package/src/internal/cli/archive_test.go +0 -67
- package/src/internal/cli/cli.go +0 -259
- package/src/internal/cli/cli_test.go +0 -130
- package/src/internal/cli/cobra/archive.go +0 -26
- package/src/internal/cli/cobra/console.go +0 -21
- package/src/internal/cli/cobra/constitution.go +0 -44
- package/src/internal/cli/cobra/dummy_test.go +0 -7
- package/src/internal/cli/cobra/implementation.go +0 -50
- package/src/internal/cli/cobra/init.go +0 -23
- package/src/internal/cli/cobra/install.go +0 -21
- package/src/internal/cli/cobra/root.go +0 -47
- package/src/internal/cli/cobra/spec.go +0 -91
- package/src/internal/cli/console.go +0 -48
- package/src/internal/cli/constitution.go +0 -190
- package/src/internal/cli/constitution_test.go +0 -50
- package/src/internal/cli/implementation.go +0 -153
- package/src/internal/cli/implementation_test.go +0 -165
- package/src/internal/cli/spec.go +0 -369
- package/src/internal/cli/spec_test.go +0 -85
- package/src/internal/constitution/registry.go +0 -139
- package/src/internal/constitution/registry_test.go +0 -97
- package/src/internal/constitution/status.go +0 -70
- package/src/internal/constitution/status_test.go +0 -160
- package/src/internal/core/blueprint.go +0 -49
- package/src/internal/core/blueprint_test.go +0 -58
- package/src/internal/core/config.go +0 -124
- package/src/internal/core/config_test.go +0 -145
- package/src/internal/core/constants.go +0 -13
- package/src/internal/core/errors.go +0 -31
- package/src/internal/core/errors_test.go +0 -48
- package/src/internal/core/hooks.go +0 -89
- package/src/internal/core/hooks_test.go +0 -51
- package/src/internal/core/kit.go +0 -15
- package/src/internal/core/kit_test.go +0 -65
- package/src/internal/core/path.go +0 -115
- package/src/internal/core/path_test.go +0 -101
- package/src/internal/core/ui.go +0 -19
- package/src/internal/installer/dependencies.go +0 -23
- package/src/internal/installer/install.go +0 -89
- package/src/internal/installer/installer.go +0 -45
- package/src/internal/installer/installer_test.go +0 -96
- package/src/internal/project/agents_md.go +0 -155
- package/src/internal/project/agents_md_test.go +0 -147
- package/src/internal/project/bootstrapper.go +0 -64
- package/src/internal/project/bootstrapper_test.go +0 -89
- package/src/internal/project/detector.go +0 -35
- package/src/internal/project/detector_test.go +0 -96
- package/src/internal/project/refresh_integration_test.go +0 -86
- package/src/internal/project/service.go +0 -93
- package/src/internal/project/service_test.go +0 -135
- package/src/internal/spec/archive.go +0 -49
- package/src/internal/spec/archive_test.go +0 -55
- package/src/internal/spec/discovery.go +0 -53
- package/src/internal/spec/discovery_test.go +0 -60
- package/src/internal/spec/implementation.go +0 -296
- package/src/internal/spec/implementation_test.go +0 -253
- package/src/internal/spec/registry.go +0 -142
- package/src/internal/spec/registry_test.go +0 -105
- package/src/internal/spec/scanner.go +0 -219
- package/src/internal/spec/scanner_test.go +0 -243
- package/src/internal/spec/service.go +0 -157
- package/src/internal/spec/service_test.go +0 -238
- package/src/internal/spec/status.go +0 -94
- package/src/internal/spec/status_test.go +0 -146
- package/src/internal/spec/tasks.go +0 -103
- package/src/internal/spec/tasks_test.go +0 -137
- package/src/internal/tui/components.go +0 -132
- package/src/internal/tui/console.go +0 -247
- package/src/internal/tui/console_test.go +0 -19
- package/src/internal/tui/constitution.go +0 -36
- package/src/internal/tui/constitution_test.go +0 -32
- package/src/internal/tui/implementation.go +0 -151
- package/src/internal/tui/logo.go +0 -89
- package/src/internal/tui/multiselect.go +0 -199
- package/src/internal/tui/progressbar.go +0 -37
- package/src/internal/tui/progressbar_test.go +0 -30
- package/src/internal/tui/spec.go +0 -35
- package/src/internal/tui/spinner.go +0 -66
- package/src/internal/tui/terminal.go +0 -18
- package/src/internal/tui/theme.go +0 -125
- package/src/internal/tui/ui.go +0 -52
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
package project
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
"testing"
|
|
8
|
-
"testing/fstest"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
type mockUI struct {
|
|
12
|
-
warnCalled bool
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
func (m *mockUI) Log(msg string) {}
|
|
16
|
-
func (m *mockUI) Success(msg string) {}
|
|
17
|
-
func (m *mockUI) Warn(msg string) { m.warnCalled = true }
|
|
18
|
-
func (m *mockUI) Error(msg string) {}
|
|
19
|
-
func (m *mockUI) SubTask(msg string) {}
|
|
20
|
-
func (m *mockUI) StartSpinner(msg string) {}
|
|
21
|
-
func (m *mockUI) StopSpinner() {}
|
|
22
|
-
func (m *mockUI) Confirm(msg string) bool { return true }
|
|
23
|
-
|
|
24
|
-
func TestBootstrapProject_Success(t *testing.T) {
|
|
25
|
-
tmpDir := t.TempDir()
|
|
26
|
-
ctx := context.Background()
|
|
27
|
-
|
|
28
|
-
// Mock artifacts filesystem
|
|
29
|
-
artifactsFS := fstest.MapFS{}
|
|
30
|
-
|
|
31
|
-
err := BootstrapProject(ctx, tmpDir, nil, artifactsFS, &mockUI{})
|
|
32
|
-
if err != nil {
|
|
33
|
-
t.Fatalf("expected no error, got %v", err)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
dirs := []string{
|
|
37
|
-
".specforce/docs",
|
|
38
|
-
".specforce/specs",
|
|
39
|
-
".specforce/archive",
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
for _, dir := range dirs {
|
|
43
|
-
path := filepath.Join(tmpDir, dir)
|
|
44
|
-
if info, err := os.Stat(path); err != nil || !info.IsDir() {
|
|
45
|
-
t.Errorf("expected directory %s to exist", path)
|
|
46
|
-
}
|
|
47
|
-
if _, err := os.Stat(filepath.Join(path, ".gitkeep")); os.IsNotExist(err) {
|
|
48
|
-
t.Errorf("expected .gitkeep in %s", path)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Verify .specforce/templates does NOT exist
|
|
53
|
-
templatesPath := filepath.Join(tmpDir, ".specforce/templates")
|
|
54
|
-
if _, err := os.Stat(templatesPath); !os.IsNotExist(err) {
|
|
55
|
-
t.Errorf("expected directory %s NOT to exist", templatesPath)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
func TestBootstrapProject_Errors(t *testing.T) {
|
|
60
|
-
tmpDir := t.TempDir()
|
|
61
|
-
ctx := context.Background()
|
|
62
|
-
artifactsFS := fstest.MapFS{}
|
|
63
|
-
|
|
64
|
-
t.Run("already initialized", func(t *testing.T) {
|
|
65
|
-
if err := os.Mkdir(filepath.Join(tmpDir, ".specforce"), 0755); err != nil {
|
|
66
|
-
t.Fatal(err)
|
|
67
|
-
}
|
|
68
|
-
err := BootstrapProject(ctx, tmpDir, nil, artifactsFS, nil)
|
|
69
|
-
if err == nil {
|
|
70
|
-
t.Fatal("expected error when already initialized")
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
t.Run("cancelled context", func(t *testing.T) {
|
|
75
|
-
cancelCtx, cancel := context.WithCancel(ctx)
|
|
76
|
-
cancel()
|
|
77
|
-
err := BootstrapProject(cancelCtx, t.TempDir(), nil, artifactsFS, nil)
|
|
78
|
-
if err == nil {
|
|
79
|
-
t.Fatal("expected error for cancelled context")
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
t.Run("nil ui success", func(t *testing.T) {
|
|
84
|
-
err := BootstrapProject(ctx, t.TempDir(), nil, artifactsFS, nil)
|
|
85
|
-
if err != nil {
|
|
86
|
-
t.Fatalf("BootstrapProject failed with nil UI: %v", err)
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
package project
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
|
|
8
|
-
"github.com/jeancodogno/specforce-kit/src/internal/agent"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// DetectExistingAgents checks for existing agent directories in the current project using the registry.
|
|
12
|
-
func DetectExistingAgents(ctx context.Context, root string, reg *agent.Registry) []string {
|
|
13
|
-
var existing []string
|
|
14
|
-
if reg == nil {
|
|
15
|
-
return existing
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
for _, agent := range reg.GetAgents() {
|
|
19
|
-
if err := ctx.Err(); err != nil {
|
|
20
|
-
return existing
|
|
21
|
-
}
|
|
22
|
-
path := filepath.Join(root, agent.DirName)
|
|
23
|
-
if info, err := os.Stat(path); err == nil && info.IsDir() {
|
|
24
|
-
existing = append(existing, agent.ID)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return existing
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// IsInitialized checks if the project has been initialized by looking for the .specforce directory.
|
|
32
|
-
func IsInitialized(root string) bool {
|
|
33
|
-
info, err := os.Stat(filepath.Join(root, ".specforce"))
|
|
34
|
-
return err == nil && info.IsDir()
|
|
35
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
package project
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
"testing"
|
|
8
|
-
"testing/fstest"
|
|
9
|
-
|
|
10
|
-
"github.com/jeancodogno/specforce-kit/src/internal/agent"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
func TestDetectExistingAgents(t *testing.T) {
|
|
14
|
-
ctx := context.Background()
|
|
15
|
-
tmpDir := t.TempDir()
|
|
16
|
-
|
|
17
|
-
// Mock kitFS
|
|
18
|
-
kitFS := fstest.MapFS{
|
|
19
|
-
"kit.yaml": &fstest.MapFile{Data: []byte(`
|
|
20
|
-
tools:
|
|
21
|
-
gemini:
|
|
22
|
-
name: "Gemini"
|
|
23
|
-
target: ".gemini/"
|
|
24
|
-
claude:
|
|
25
|
-
name: "Claude"
|
|
26
|
-
target: ".claude/"
|
|
27
|
-
`)},
|
|
28
|
-
"agents/gemini.yaml": &fstest.MapFile{Data: []byte("content: gemini")},
|
|
29
|
-
"agents/claude.yaml": &fstest.MapFile{Data: []byte("content: claude")},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
reg := &agent.Registry{}
|
|
33
|
-
_ = reg.Initialize(kitFS)
|
|
34
|
-
|
|
35
|
-
t.Run("no existing agents", func(t *testing.T) {
|
|
36
|
-
got := DetectExistingAgents(ctx, tmpDir, reg)
|
|
37
|
-
if len(got) != 0 {
|
|
38
|
-
t.Errorf("expected no agents, got %v", got)
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
t.Run("existing agents", func(t *testing.T) {
|
|
43
|
-
if err := os.Mkdir(filepath.Join(tmpDir, ".gemini"), 0755); err != nil {
|
|
44
|
-
t.Fatal(err)
|
|
45
|
-
}
|
|
46
|
-
got := DetectExistingAgents(ctx, tmpDir, reg)
|
|
47
|
-
if len(got) != 1 || got[0] != "gemini" {
|
|
48
|
-
t.Errorf("expected [gemini], got %v", got)
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
t.Run("nil registry", func(t *testing.T) {
|
|
53
|
-
got := DetectExistingAgents(ctx, tmpDir, nil)
|
|
54
|
-
if len(got) != 0 {
|
|
55
|
-
t.Errorf("expected no agents for nil registry, got %v", got)
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
t.Run("cancelled context", func(t *testing.T) {
|
|
60
|
-
cancelCtx, cancel := context.WithCancel(ctx)
|
|
61
|
-
cancel()
|
|
62
|
-
got := DetectExistingAgents(cancelCtx, tmpDir, reg)
|
|
63
|
-
if len(got) != 0 {
|
|
64
|
-
t.Errorf("expected no agents for cancelled context, got %v", got)
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
func TestIsInitialized(t *testing.T) {
|
|
70
|
-
tmpDir := t.TempDir()
|
|
71
|
-
|
|
72
|
-
t.Run("not initialized", func(t *testing.T) {
|
|
73
|
-
if IsInitialized(tmpDir) {
|
|
74
|
-
t.Fatal("expected IsInitialized to be false")
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
t.Run("is initialized", func(t *testing.T) {
|
|
79
|
-
if err := os.Mkdir(filepath.Join(tmpDir, ".specforce"), 0755); err != nil {
|
|
80
|
-
t.Fatal(err)
|
|
81
|
-
}
|
|
82
|
-
if !IsInitialized(tmpDir) {
|
|
83
|
-
t.Fatal("expected IsInitialized to be true")
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
t.Run("is file not dir", func(t *testing.T) {
|
|
88
|
-
anotherTmp := t.TempDir()
|
|
89
|
-
if err := os.WriteFile(filepath.Join(anotherTmp, ".specforce"), []byte("not a dir"), 0644); err != nil {
|
|
90
|
-
t.Fatal(err)
|
|
91
|
-
}
|
|
92
|
-
if IsInitialized(anotherTmp) {
|
|
93
|
-
t.Fatal("expected IsInitialized to be false when .specforce is a file")
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
package project_test
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
"strings"
|
|
8
|
-
"testing"
|
|
9
|
-
"testing/fstest"
|
|
10
|
-
|
|
11
|
-
"github.com/jeancodogno/specforce-kit/src/internal/project"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
func createMockKitFS() fstest.MapFS {
|
|
15
|
-
return fstest.MapFS{
|
|
16
|
-
"kit.yaml": &fstest.MapFile{Data: []byte(`
|
|
17
|
-
tools:
|
|
18
|
-
gemini:
|
|
19
|
-
name: "Gemini"
|
|
20
|
-
target: ".gemini/"
|
|
21
|
-
mappings:
|
|
22
|
-
agents: { path: "agents", ext: ".md" }
|
|
23
|
-
skills: { path: "skills", ext: ".md" }
|
|
24
|
-
commands: { path: "commands", ext: ".md" }
|
|
25
|
-
`)},
|
|
26
|
-
"agents/coder.yaml": &fstest.MapFile{Data: []byte("content: kit-agent-content")},
|
|
27
|
-
"skills/tdd.yaml": &fstest.MapFile{Data: []byte("content: kit-skill-content")},
|
|
28
|
-
"commands/run.yaml": &fstest.MapFile{Data: []byte("content: kit-command-content")},
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func TestService_UpdateTools_RefreshesAllCategories(t *testing.T) {
|
|
33
|
-
kitFS := createMockKitFS()
|
|
34
|
-
artifactsFS := fstest.MapFS{}
|
|
35
|
-
tmpDir := t.TempDir()
|
|
36
|
-
|
|
37
|
-
svc := project.NewService(kitFS, artifactsFS, tmpDir)
|
|
38
|
-
ui := &mockUI{}
|
|
39
|
-
|
|
40
|
-
// 1. Initial Installation
|
|
41
|
-
err := svc.UpdateTools(context.Background(), ui, []string{"gemini"})
|
|
42
|
-
if err != nil {
|
|
43
|
-
t.Fatalf("Initial UpdateTools failed: %v", err)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Paths
|
|
47
|
-
agentPath := filepath.Join(tmpDir, ".gemini/agents/coder.md")
|
|
48
|
-
skillPath := filepath.Join(tmpDir, ".gemini/skills/tdd.md")
|
|
49
|
-
commandPath := filepath.Join(tmpDir, ".gemini/commands/run.md")
|
|
50
|
-
|
|
51
|
-
// 2. Modify files manually (simulate user customization or old version)
|
|
52
|
-
filesToModify := []string{agentPath, skillPath, commandPath}
|
|
53
|
-
for _, p := range filesToModify {
|
|
54
|
-
if err := os.WriteFile(p, []byte("user-modified-content"), 0644); err != nil {
|
|
55
|
-
t.Fatalf("failed to modify file %s: %v", p, err)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 3. Run Update
|
|
60
|
-
err = svc.UpdateTools(context.Background(), ui, []string{"gemini"})
|
|
61
|
-
if err != nil {
|
|
62
|
-
t.Fatalf("Second UpdateTools failed: %v", err)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 4. Verify Refresh
|
|
66
|
-
tests := []struct {
|
|
67
|
-
path string
|
|
68
|
-
expected string
|
|
69
|
-
}{
|
|
70
|
-
{agentPath, "kit-agent-content"},
|
|
71
|
-
{skillPath, "kit-skill-content"},
|
|
72
|
-
{commandPath, "kit-command-content"},
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for _, tt := range tests {
|
|
76
|
-
content, err := os.ReadFile(tt.path)
|
|
77
|
-
if err != nil {
|
|
78
|
-
t.Errorf("failed to read file %s: %v", tt.path, err)
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
// Note: AdaptArtifacts might inject headers, so we check if it contains the kit content
|
|
82
|
-
if !strings.Contains(string(content), tt.expected) {
|
|
83
|
-
t.Errorf("file %s was not refreshed. Got: %s, Expected to contain: %s", tt.path, string(content), tt.expected)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
package project
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"errors"
|
|
6
|
-
"fmt"
|
|
7
|
-
"io/fs"
|
|
8
|
-
|
|
9
|
-
"github.com/jeancodogno/specforce-kit/src/internal/agent"
|
|
10
|
-
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
11
|
-
"github.com/jeancodogno/specforce-kit/src/internal/installer"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
// InitConfig contains project root, selected agents, and options for project initialization.
|
|
15
|
-
type InitConfig struct {
|
|
16
|
-
ProjectRoot string
|
|
17
|
-
SelectedAgents []string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Service orchestrates project-related domain logic.
|
|
21
|
-
type Service struct {
|
|
22
|
-
kitFS fs.FS
|
|
23
|
-
artifactsFS fs.FS
|
|
24
|
-
projectRoot string
|
|
25
|
-
config *core.ProjectConfig
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// NewService creates a new instance of the project service.
|
|
29
|
-
func NewService(kitFS, artifactsFS fs.FS, projectRoot string) *Service {
|
|
30
|
-
return &Service{
|
|
31
|
-
kitFS: kitFS,
|
|
32
|
-
artifactsFS: artifactsFS,
|
|
33
|
-
projectRoot: projectRoot,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// GetConfig returns the project-specific configuration.
|
|
38
|
-
func (s *Service) GetConfig(ctx context.Context) (*core.ProjectConfig, error) {
|
|
39
|
-
if s.config == nil {
|
|
40
|
-
s.config = core.LoadConfig(s.projectRoot)
|
|
41
|
-
}
|
|
42
|
-
return s.config, nil
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// InitializeProject orchestrates the project initialization flow.
|
|
46
|
-
func (s *Service) InitializeProject(ctx context.Context, ui core.UI, config InitConfig) error {
|
|
47
|
-
if err := BootstrapProject(ctx, config.ProjectRoot, s.kitFS, s.artifactsFS, ui); err != nil {
|
|
48
|
-
if !errors.Is(err, core.ErrProjectAlreadyInitialized) {
|
|
49
|
-
return err
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for _, a := range config.SelectedAgents {
|
|
54
|
-
if err := agent.AdaptArtifacts(ctx, config.ProjectRoot, s.kitFS, a, ui, installer.Options{}); err != nil {
|
|
55
|
-
return fmt.Errorf("failed to adapt artifacts for %s: %w", a, err)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return nil
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// UpdateTools refreshes agent tools and instructions while preserving the .specforce/ directory.
|
|
63
|
-
func (s *Service) UpdateTools(ctx context.Context, ui core.UI, selectedAgents []string) error {
|
|
64
|
-
if ui != nil {
|
|
65
|
-
ui.SubTask("Updating agent tools and instructions...")
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
opts := installer.Options{ToolsOnly: true}
|
|
69
|
-
|
|
70
|
-
// Iterate through selected tools and update them
|
|
71
|
-
for _, agentID := range selectedAgents {
|
|
72
|
-
if err := ctx.Err(); err != nil {
|
|
73
|
-
return err
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if err := agent.AdaptArtifacts(ctx, s.projectRoot, s.kitFS, agentID, ui, opts); err != nil {
|
|
77
|
-
// We log but continue if one agent fails to update
|
|
78
|
-
if ui != nil {
|
|
79
|
-
ui.Warn(fmt.Sprintf("Failed to update tools for %s: %v", agentID, err))
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if ui != nil {
|
|
85
|
-
ui.Success("Agent tools and instructions updated successfully.")
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if err := EnsureAgentsMD(s.projectRoot, ui); err != nil {
|
|
89
|
-
return fmt.Errorf("failed to update AGENTS.md: %w", err)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return nil
|
|
93
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
package project_test
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"testing"
|
|
6
|
-
"testing/fstest"
|
|
7
|
-
|
|
8
|
-
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
9
|
-
"github.com/jeancodogno/specforce-kit/src/internal/project"
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
var _ core.UI = (*mockUI)(nil)
|
|
13
|
-
|
|
14
|
-
type mockUI struct {
|
|
15
|
-
subtasks []string
|
|
16
|
-
warnings []string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func (m *mockUI) Log(msg string) {}
|
|
20
|
-
func (m *mockUI) Success(msg string) {}
|
|
21
|
-
func (m *mockUI) Warn(msg string) { m.warnings = append(m.warnings, msg) }
|
|
22
|
-
func (m *mockUI) Error(msg string) {}
|
|
23
|
-
func (m *mockUI) SubTask(msg string) {
|
|
24
|
-
m.subtasks = append(m.subtasks, msg)
|
|
25
|
-
}
|
|
26
|
-
func (m *mockUI) StartSpinner(msg string) {}
|
|
27
|
-
func (m *mockUI) StopSpinner() {}
|
|
28
|
-
func (m *mockUI) Confirm(msg string) bool { return true }
|
|
29
|
-
|
|
30
|
-
func TestService_InitializeProject(t *testing.T) {
|
|
31
|
-
kitFS := fstest.MapFS{
|
|
32
|
-
"kit.yaml": &fstest.MapFile{Data: []byte(`
|
|
33
|
-
tools:
|
|
34
|
-
test-agent:
|
|
35
|
-
name: "Test Agent"
|
|
36
|
-
target: ".test-agent"
|
|
37
|
-
`)},
|
|
38
|
-
"agents/test-agent.yaml": &fstest.MapFile{Data: []byte("content: hello")},
|
|
39
|
-
}
|
|
40
|
-
tmpDir := t.TempDir()
|
|
41
|
-
artifactsFS := fstest.MapFS{}
|
|
42
|
-
|
|
43
|
-
svc := project.NewService(kitFS, artifactsFS, tmpDir)
|
|
44
|
-
ui := &mockUI{}
|
|
45
|
-
|
|
46
|
-
t.Run("success", func(t *testing.T) {
|
|
47
|
-
config := project.InitConfig{
|
|
48
|
-
ProjectRoot: tmpDir,
|
|
49
|
-
SelectedAgents: []string{"test-agent"},
|
|
50
|
-
}
|
|
51
|
-
err := svc.InitializeProject(context.Background(), ui, config)
|
|
52
|
-
if err != nil {
|
|
53
|
-
t.Fatalf("InitializeProject failed: %v", err)
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
t.Run("agent not found", func(t *testing.T) {
|
|
58
|
-
config := project.InitConfig{
|
|
59
|
-
ProjectRoot: t.TempDir(),
|
|
60
|
-
SelectedAgents: []string{"non-existent"},
|
|
61
|
-
}
|
|
62
|
-
err := svc.InitializeProject(context.Background(), ui, config)
|
|
63
|
-
if err == nil {
|
|
64
|
-
t.Fatal("expected error for non-existent agent")
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
func TestService_GetConfig(t *testing.T) {
|
|
70
|
-
kitFS := fstest.MapFS{}
|
|
71
|
-
artifactsFS := fstest.MapFS{}
|
|
72
|
-
tmpDir := t.TempDir()
|
|
73
|
-
|
|
74
|
-
svc := project.NewService(kitFS, artifactsFS, tmpDir)
|
|
75
|
-
|
|
76
|
-
// Initially, it should return an empty config
|
|
77
|
-
conf, err := svc.GetConfig(context.Background())
|
|
78
|
-
if err != nil {
|
|
79
|
-
t.Fatalf("GetConfig failed: %v", err)
|
|
80
|
-
}
|
|
81
|
-
if conf == nil || len(conf.Instructions) != 0 {
|
|
82
|
-
t.Errorf("Expected empty config, got %v", conf)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
func TestService_UpdateTools(t *testing.T) {
|
|
87
|
-
kitFS := fstest.MapFS{
|
|
88
|
-
"kit.yaml": &fstest.MapFile{Data: []byte(`
|
|
89
|
-
tools:
|
|
90
|
-
gemini:
|
|
91
|
-
name: "Gemini"
|
|
92
|
-
target: ".gemini/"
|
|
93
|
-
`)},
|
|
94
|
-
"agents/gemini.yaml": &fstest.MapFile{Data: []byte("content: gemini-content")},
|
|
95
|
-
}
|
|
96
|
-
artifactsFS := fstest.MapFS{}
|
|
97
|
-
tmpDir := t.TempDir()
|
|
98
|
-
|
|
99
|
-
svc := project.NewService(kitFS, artifactsFS, tmpDir)
|
|
100
|
-
ui := &mockUI{}
|
|
101
|
-
|
|
102
|
-
t.Run("success", func(t *testing.T) {
|
|
103
|
-
err := svc.UpdateTools(context.Background(), ui, []string{"gemini"})
|
|
104
|
-
if err != nil {
|
|
105
|
-
t.Fatalf("UpdateTools failed: %v", err)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
t.Run("agent update failure", func(t *testing.T) {
|
|
110
|
-
uiWithWarnings := &mockUI{}
|
|
111
|
-
err := svc.UpdateTools(context.Background(), uiWithWarnings, []string{"non-existent"})
|
|
112
|
-
if err != nil {
|
|
113
|
-
t.Fatalf("UpdateTools should not return error if one agent fails: %v", err)
|
|
114
|
-
}
|
|
115
|
-
if len(uiWithWarnings.warnings) == 0 {
|
|
116
|
-
t.Fatal("expected warning for failed agent update")
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
t.Run("cancelled context", func(t *testing.T) {
|
|
121
|
-
ctx, cancel := context.WithCancel(context.Background())
|
|
122
|
-
cancel()
|
|
123
|
-
err := svc.UpdateTools(ctx, ui, []string{"gemini"})
|
|
124
|
-
if err == nil {
|
|
125
|
-
t.Fatal("expected error for cancelled context")
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
t.Run("nil ui", func(t *testing.T) {
|
|
130
|
-
err := svc.UpdateTools(context.Background(), nil, []string{"gemini"})
|
|
131
|
-
if err != nil {
|
|
132
|
-
t.Fatalf("UpdateTools failed with nil UI: %v", err)
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
package spec
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"fmt"
|
|
6
|
-
"os"
|
|
7
|
-
"path/filepath"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
// ArchiveSpec moves a specification from the specs directory to the archive directory.
|
|
11
|
-
func ArchiveSpec(ctx context.Context, basePath, slug string) error {
|
|
12
|
-
if err := ctx.Err(); err != nil {
|
|
13
|
-
return err
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
specsDir := filepath.Join(basePath, ".specforce", "specs", slug)
|
|
17
|
-
archiveDir := filepath.Join(basePath, ".specforce", "archive", slug)
|
|
18
|
-
|
|
19
|
-
// Check if source exists
|
|
20
|
-
srcInfo, err := os.Stat(specsDir)
|
|
21
|
-
if os.IsNotExist(err) {
|
|
22
|
-
return fmt.Errorf("spec not found: %s", slug)
|
|
23
|
-
}
|
|
24
|
-
if !srcInfo.IsDir() {
|
|
25
|
-
return fmt.Errorf("spec path is not a directory: %s", specsDir)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Check if destination already exists
|
|
29
|
-
_, err = os.Stat(archiveDir)
|
|
30
|
-
if err == nil {
|
|
31
|
-
return fmt.Errorf("archive already exists: %s", slug)
|
|
32
|
-
}
|
|
33
|
-
if !os.IsNotExist(err) {
|
|
34
|
-
return fmt.Errorf("failed to check archive destination: %w", err)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Ensure archive parent directory exists
|
|
38
|
-
if err := os.MkdirAll(filepath.Dir(archiveDir), 0750); err != nil {
|
|
39
|
-
return fmt.Errorf("failed to create archive base directory: %w", err)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Perform atomic move
|
|
43
|
-
if err := os.Rename(specsDir, archiveDir); err != nil {
|
|
44
|
-
// Fallback for cross-partition move or other rename failures could be implemented here
|
|
45
|
-
return fmt.Errorf("failed to archive spec: %w", err)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return nil
|
|
49
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
package spec
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
"testing"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
func TestArchiveSpec(t *testing.T) {
|
|
11
|
-
tempDir, err := os.MkdirTemp("", "specforce-test-*")
|
|
12
|
-
if err != nil {
|
|
13
|
-
t.Fatalf("failed to create temp dir: %v", err)
|
|
14
|
-
}
|
|
15
|
-
defer func() { _ = os.RemoveAll(tempDir) }()
|
|
16
|
-
|
|
17
|
-
slug := "0001-test"
|
|
18
|
-
specsPath := filepath.Join(tempDir, ".specforce", "specs", slug)
|
|
19
|
-
archivePath := filepath.Join(tempDir, ".specforce", "archive", slug)
|
|
20
|
-
|
|
21
|
-
if err := os.MkdirAll(specsPath, 0755); err != nil {
|
|
22
|
-
t.Fatalf("failed to create specs path: %v", err)
|
|
23
|
-
}
|
|
24
|
-
if err := os.WriteFile(filepath.Join(specsPath, "requirements.md"), []byte("test content"), 0644); err != nil {
|
|
25
|
-
t.Fatalf("failed to create test file: %v", err)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Happy Path
|
|
29
|
-
if err := ArchiveSpec(context.Background(), tempDir, slug); err != nil {
|
|
30
|
-
t.Errorf("expected no error, got %v", err)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if _, err := os.Stat(archivePath); os.IsNotExist(err) {
|
|
34
|
-
t.Errorf("expected archive path to exist")
|
|
35
|
-
}
|
|
36
|
-
if _, err := os.Stat(specsPath); !os.IsNotExist(err) {
|
|
37
|
-
t.Errorf("expected source path to be removed")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Error Case: Spec not found
|
|
41
|
-
err = ArchiveSpec(context.Background(), tempDir, "9999-missing")
|
|
42
|
-
if err == nil || err.Error() != "spec not found: 9999-missing" {
|
|
43
|
-
t.Errorf("expected 'spec not found' error, got %v", err)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Error Case: Archive already exists
|
|
47
|
-
// Re-create source
|
|
48
|
-
if err := os.MkdirAll(specsPath, 0755); err != nil {
|
|
49
|
-
t.Fatalf("failed to recreate specs path: %v", err)
|
|
50
|
-
}
|
|
51
|
-
err = ArchiveSpec(context.Background(), tempDir, slug)
|
|
52
|
-
if err == nil || err.Error() != "archive already exists: 0001-test" {
|
|
53
|
-
t.Errorf("expected 'archive already exists' error, got %v", err)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
package spec
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"os"
|
|
6
|
-
"path/filepath"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
// SpecInfo contains basic information about a specification.
|
|
10
|
-
type SpecInfo struct {
|
|
11
|
-
Slug string `json:"slug"`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ListActiveSpecs returns a list of all non-archived specs.
|
|
15
|
-
func ListActiveSpecs(ctx context.Context, projectRoot string) ([]SpecInfo, error) {
|
|
16
|
-
if err := ctx.Err(); err != nil {
|
|
17
|
-
return nil, err
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
specsDir := filepath.Join(projectRoot, ".specforce", "specs")
|
|
21
|
-
entries, err := os.ReadDir(specsDir)
|
|
22
|
-
if err != nil {
|
|
23
|
-
if os.IsNotExist(err) {
|
|
24
|
-
return []SpecInfo{}, nil
|
|
25
|
-
}
|
|
26
|
-
return nil, err
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var specs []SpecInfo
|
|
30
|
-
for _, entry := range entries {
|
|
31
|
-
// Ignore hidden directories and non-directories
|
|
32
|
-
if entry.IsDir() && entry.Name()[0] != '.' {
|
|
33
|
-
specs = append(specs, SpecInfo{Slug: entry.Name()})
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return specs, nil
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// SpecExists checks if a spec slug already exists in either specs or archive.
|
|
41
|
-
func SpecExists(projectRoot string, slug string) (bool, string) {
|
|
42
|
-
specsDir := filepath.Join(projectRoot, ".specforce", "specs", slug)
|
|
43
|
-
if _, err := os.Stat(specsDir); err == nil {
|
|
44
|
-
return true, "active"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
archiveDir := filepath.Join(projectRoot, ".specforce", "archive", slug)
|
|
48
|
-
if _, err := os.Stat(archiveDir); err == nil {
|
|
49
|
-
return true, "archived"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return false, ""
|
|
53
|
-
}
|