Skip to content

Commit 99902c0

Browse files
authored
add agents md (#32)
* add agents.md file * update with new agent standards
1 parent 788ca58 commit 99902c0

15 files changed

Lines changed: 102 additions & 145 deletions

File tree

‎AGENTS.md‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Patternizer - Agent Guidelines
2+
3+
Patternizer is a Go CLI tool that bootstraps Git repositories containing Helm charts into ready-to-use Validated Patterns. Module path: `github.com/validatedpatterns/patternizer`.
4+
5+
## Build, Lint, and Test
6+
7+
Run `make dev-setup` once to install tooling (golangci-lint, ginkgo).
8+
9+
Key make targets:
10+
11+
- `make ci` - Full CI pipeline: lint, build, test. Run this before considering any change complete.
12+
- `make build` - Build the binary.
13+
- `make test` - Run all tests via Ginkgo.
14+
- `make lint` - Run all linters (gofmt, go vet, golangci-lint).
15+
- `make fmt` - Auto-format Go code.
16+
- `make check` - Quick check: format, vet, build, unit tests.
17+
18+
All Go source lives under `src/`. The Makefile handles `cd src` automatically.
19+
20+
## Code Style
21+
22+
- No unnecessary inline comments. Code should be self-documenting through clear naming and structure.
23+
- No emojis, ASCII art, or non-standard characters anywhere in the codebase.
24+
- Exported functions must have godoc comments (enforced by the revive linter).
25+
- Run `make fmt` before committing. Formatting is checked by `make lint`.
26+
- Follow the existing project layout:
27+
- `src/cmd/` - Cobra CLI command definitions.
28+
- `src/internal/` - Private packages (not importable externally).
29+
- `src/internal/types/` - Shared data structures.
30+
- `src/internal/embedded/` - Embedded resources via `go:embed`.
31+
32+
## Go Best Practices
33+
34+
- Wrap errors with context: `fmt.Errorf("description: %w", err)`.
35+
- Break large functions into smaller, well-named helper functions. Each function should do one thing.
36+
- Keep `main.go` minimal; delegate to `cmd.Execute()`.
37+
- Use `internal/` to keep implementation details private.
38+
- Use `go:embed` for bundled resources (see `internal/embedded/`).
39+
- CLI commands use Cobra. Add new commands by registering them on `rootCmd` in `cmd/root.go`.
40+
41+
## Testing
42+
43+
- Tests must be added or updated when writing new code.
44+
- The project uses Ginkgo v2 and Gomega (BDD style: `Describe`/`Context`/`It`).
45+
- Test files live alongside source files as `*_test.go`.
46+
- Each package with tests needs a `*_suite_test.go` file for Ginkgo bootstrap.
47+
- Use `GinkgoT().TempDir()` for temporary directories in tests.
48+
- Run `make test` to execute all tests (`ginkgo -v ./...`).
49+
50+
## Versioning
51+
52+
The project version is tracked in the shield badge on line 1 of `README.md` (e.g. `![Version: 2.0.0](...)`). Bump it once per session or PR when the CLI binary changes:
53+
54+
- **Patch** (2.0.0 -> 2.0.1): Bug fixes, internal refactors, dependency updates.
55+
- **Minor** (2.0.0 -> 2.1.0): New features, new commands, new flags, or changed behavior.
56+
- **Major**: Ask the user for confirmation before bumping the major version.
57+
- **No bump needed**: Documentation-only changes, CI config, or other changes that do not affect the compiled binary.
58+
59+
Only bump the version once even if multiple code changes are made in the same session.
60+
61+
## Documentation
62+
63+
- Update `README.md` when code changes affect user-facing behavior, CLI usage, or flags.
64+
- Keep the README focused on usage and contribution guidance.
65+
66+
## Verification
67+
68+
Run `make ci` before submitting any change. It runs the full pipeline:
69+
70+
1. Lint (gofmt, go vet, golangci-lint with gocritic, misspell, and revive)
71+
2. Build
72+
3. Test (all Ginkgo suites)

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

‎src/cmd/cmd_suite_test.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ func verifyClusterGroupValues(valuesFile string, expectedClusterGroupValues *typ
124124
}
125125

126126
func createTestDir() string {
127-
dir, err := os.MkdirTemp("", "patternizer-test")
128-
Expect(err).NotTo(HaveOccurred())
129-
return dir
127+
return GinkgoT().TempDir()
130128
}
131129

132130
func runCLI(dir string, args ...string) *gexec.Session {

‎src/cmd/init.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,21 @@ import (
1313

1414
// runInit handles the initialization logic for the init command.
1515
func runInit(withSecrets bool) error {
16-
// Get pattern name and repository root
1716
patternName, repoRoot, err := pattern.GetPatternNameAndRepoRoot()
1817
if err != nil {
1918
return fmt.Errorf("error getting pattern information: %w", err)
2019
}
2120

22-
// Find Helm charts in the repository
2321
chartPaths, err := helm.FindTopLevelCharts(repoRoot)
2422
if err != nil {
2523
return fmt.Errorf("error finding Helm charts: %w", err)
2624
}
2725

28-
// Process values-global.yaml
2926
actualPatternName, clusterGroupName, err := pattern.ProcessGlobalValues(patternName, repoRoot, withSecrets)
3027
if err != nil {
3128
return fmt.Errorf("error processing global values: %w", err)
3229
}
3330

34-
// Process cluster group values using the actual pattern name and cluster group name from the global values
3531
if err := pattern.ProcessClusterGroupValues(actualPatternName, clusterGroupName, repoRoot, chartPaths, withSecrets); err != nil {
3632
return fmt.Errorf("error processing cluster group values: %w", err)
3733
}

‎src/cmd/init_test.go‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ var _ = Describe("patternizer init", func() {
6161
_ = runCLI(tempDir, "init")
6262
})
6363

64-
AfterAll(func() {
65-
os.RemoveAll(tempDir)
66-
})
67-
6864
It("should copy the common pattern scaffold files", func() {
6965
verifyScaffoldFilesCopied(tempDir)
7066
})
@@ -118,10 +114,6 @@ var _ = Describe("patternizer init", func() {
118114
_ = runCLI(tempDir, "init")
119115
})
120116

121-
AfterAll(func() {
122-
os.RemoveAll(tempDir)
123-
})
124-
125117
It("should copy the common pattern scaffold files", func() {
126118
verifyScaffoldFilesCopied(tempDir)
127119
})
@@ -182,10 +174,6 @@ var _ = Describe("patternizer init", func() {
182174
_ = runCLI(tempDir, "init")
183175
})
184176

185-
AfterAll(func() {
186-
os.RemoveAll(tempDir)
187-
})
188-
189177
It("should copy the common pattern scaffold files", func() {
190178
verifyScaffoldFilesCopied(tempDir)
191179
})
@@ -235,10 +223,6 @@ var _ = Describe("patternizer init", func() {
235223
_ = runCLI(tempDir, "init")
236224
})
237225

238-
AfterAll(func() {
239-
os.RemoveAll(tempDir)
240-
})
241-
242226
It("should copy the common pattern scaffold files", func() {
243227
verifyScaffoldFilesCopied(tempDir)
244228
})
@@ -297,10 +281,6 @@ var _ = Describe("patternizer init", func() {
297281
_ = runCLI(tempDir, "init")
298282
})
299283

300-
AfterAll(func() {
301-
os.RemoveAll(tempDir)
302-
})
303-
304284
It("should respect the explicit singleArgoCD override", func() {
305285
globalValuesFile := filepath.Join(tempDir, "values-global.yaml")
306286
expectedGlobalValues := types.ValuesGlobal{
@@ -333,10 +313,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
333313
_ = runCLI(tempDir, "init", "--with-secrets")
334314
})
335315

336-
AfterAll(func() {
337-
os.RemoveAll(tempDir)
338-
})
339-
340316
It("should copy the common pattern scaffold files", func() {
341317
verifyScaffoldFilesCopied(tempDir)
342318
})
@@ -419,10 +395,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
419395
_ = runCLI(tempDir, "init", "--with-secrets")
420396
})
421397

422-
AfterAll(func() {
423-
os.RemoveAll(tempDir)
424-
})
425-
426398
It("should copy the common pattern scaffold files", func() {
427399
verifyScaffoldFilesCopied(tempDir)
428400
})
@@ -515,10 +487,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
515487
_ = runCLI(tempDir, "init", "--with-secrets")
516488
})
517489

518-
AfterAll(func() {
519-
os.RemoveAll(tempDir)
520-
})
521-
522490
It("should copy the common pattern scaffold files", func() {
523491
verifyScaffoldFilesCopied(tempDir)
524492
})
@@ -602,10 +570,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
602570
_ = runCLI(tempDir, "init", "--with-secrets")
603571
})
604572

605-
AfterAll(func() {
606-
os.RemoveAll(tempDir)
607-
})
608-
609573
It("should copy the secrets template file", func() {
610574
verifySecretTemplateCopied(tempDir)
611575
})
@@ -695,10 +659,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
695659
_ = runCLI(tempDir, "init", "--with-secrets")
696660
})
697661

698-
AfterAll(func() {
699-
os.RemoveAll(tempDir)
700-
})
701-
702662
It("should copy the common pattern scaffold files", func() {
703663
verifyScaffoldFilesCopied(tempDir)
704664
})
@@ -789,10 +749,6 @@ var _ = Describe("patternizer init --with-secrets", func() {
789749
_ = runCLI(tempDir, "init", "--with-secrets")
790750
})
791751

792-
AfterAll(func() {
793-
os.RemoveAll(tempDir)
794-
})
795-
796752
It("should not modify the secrets template file", func() {
797753
actual, err := os.ReadFile(filepath.Join(tempDir, "values-secret.yaml.template"))
798754
Expect(err).NotTo(HaveOccurred())

‎src/cmd/root.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ for a validated pattern, including values-global.yaml and values-<clustergroup>.
2929
When --with-secrets is specified, it also copies the secrets template and
3030
configures the pattern.sh script for secrets usage.`,
3131
RunE: func(cmd *cobra.Command, args []string) error {
32-
// Check if "help" is passed as an argument
3332
if len(args) > 0 && args[0] == "help" {
3433
return cmd.Help()
3534
}

‎src/cmd/upgrade.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ import (
1212

1313
// runUpgrade handles the upgrade logic for the upgrade command.
1414
func runUpgrade(replaceMakefile bool) error {
15-
// Determine repository root
1615
_, repoRoot, err := pattern.GetPatternNameAndRepoRoot()
1716
if err != nil {
1817
return fmt.Errorf("error getting pattern information: %w", err)
1918
}
2019

21-
// Paths
2220
commonDirPath := filepath.Join(repoRoot, "common")
2321
patternShPath := filepath.Join(repoRoot, "pattern.sh")
2422

25-
// Remove common/ directory if it exists
2623
if err := fileutils.RemovePathIfExists(commonDirPath); err != nil {
2724
return fmt.Errorf("error removing common directory: %w", err)
2825
}
2926

30-
// Remove ./pattern.sh if it exists (symlink or file)
3127
if err := fileutils.RemovePathIfExists(patternShPath); err != nil {
3228
return fmt.Errorf("error removing pattern.sh: %w", err)
3329
}

‎src/cmd/upgrade_test.go‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ var _ = Describe("patternizer upgrade", func() {
5151
_ = runCLI(tempDir, "upgrade")
5252
})
5353

54-
AfterAll(func() {
55-
os.RemoveAll(tempDir)
56-
})
57-
5854
It("should copy the common scaffold files (except Makefile)", func() {
5955
verifyPattenShCopied(tempDir)
6056
verifyMakefileCommonCopied(tempDir)
@@ -92,10 +88,6 @@ var _ = Describe("patternizer upgrade", func() {
9288
_ = runCLI(tempDir, "upgrade")
9389
})
9490

95-
AfterAll(func() {
96-
os.RemoveAll(tempDir)
97-
})
98-
9991
It("should not update Makefiles that already include Makefile-common", func() {
10092
f, err := os.ReadFile(filepath.Join(tempDir, "Makefile"))
10193
Expect(err).NotTo(HaveOccurred())
@@ -115,10 +107,6 @@ var _ = Describe("patternizer upgrade --replace-makefile", func() {
115107
_ = runCLI(tempDir, "upgrade", "--replace-makefile")
116108
})
117109

118-
AfterAll(func() {
119-
os.RemoveAll(tempDir)
120-
})
121-
122110
It("should update the common scaffold files (including Makefile)", func() {
123111
verifyScaffoldFilesCopied(tempDir)
124112
})

‎src/internal/embedded/embedded.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package embedded
22

33
import "embed"
44

5+
// Resources holds the embedded resources directory tree (pattern.sh, Makefile, etc.).
6+
//
57
//go:embed resources/*
68
var Resources embed.FS
79

10+
// Skills holds the embedded skills directory tree for IDE integrations.
11+
//
812
//go:embed all:skills
913
var Skills embed.FS

0 commit comments

Comments
 (0)