From ce83cf1cc23e4e4ec5317a360edc8a58ac92492f Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 9 Mar 2026 06:41:41 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=20AGENTS.md=20with=20conf?= =?UTF-8?q?ig=20system=20changes=20and=20testing=20guidelines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 61c9bf1..74f23bc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,11 +14,19 @@ - **Formatting**: Always run `go fmt` before commits (included in test target) - **Types**: Use explicit types (e.g., `int64`, `float64`). Convert numbers appropriately when unmarshaling JSON - **Naming**: PascalCase for exported, camelCase for unexported. Use descriptive names +- **Don't reinvent the wheel**: Use standard library functions (e.g., `slices.Contains` instead of custom contains functions) - **Error handling**: Return wrapped errors with context. Define custom errors in models/errors.go. Use `ErrorIs` for error checking -- **Testing**: Use github.com/nalgeon/be. Table-driven tests with helper functions. Test both marshal/unmarshal for encoding types +- **Testing**: Use github.com/nalgeon/be. Table-driven tests with helper functions. Test both marshal/unmarshal for encoding types. Use `t.ArtifactDir()` instead of `t.TempDir()` and `t.Context()` instead of `context.Background()` - **Concurrency**: Use channels and goroutines with WaitGroups for parallel processing (see entry.go patterns) - **Comments**: Include license header on cmd files. Document exported functions and types +## Config System +- Viper instance is stored in context using a custom key type (`confKeyType`) +- Use `config.New(path, overrides)` to create a new viper instance +- Use `config.RetrieveFromContext(ctx)` to get both viper and the unmarshaled Config struct +- Formatters can use `v.Sub("formatters." + kind)` to get their own sub-config and unmarshal into their specific config struct +- Test files must create viper instances and add them to context using `config.AddToContext` + ## Git Commit Guidelines - **Format**: Prepend commit messages with a gitmoji emoji (see https://gitmoji.dev) - **Style**: Write detailed commit messages that explain what changed and why @@ -39,9 +47,10 @@ ## Project Structure - `cmd/my-log/`: Main application entrypoint -- `internal/cmd/`: Cobra commands (root, drop, config) +- `internal/testutil/bep`: Reusable test assertions to complement those used by github.com/nalgeon/be +- `cli/`: Cobra commands (root, drop, config) - `models/`: Core types (Entry, Log, Meta) with marshal/unmarshal implementations -- `config/`: TOML-based configuration with env overrides -- `formatters/`: Output formatters (plain, json, null) +- `config/`: TOML-based configuration with viper, env overrides, and context propagation +- `formatters/`: Output formatters (plain, json, null) with their own sub-configs - `files/`: File operations (append) - `tools/`: Utilities (date parsing, string parsing, write buffers)