Skip to content

Commit 9d8793f

Browse files
committed
Add LLM-native files: llms.txt, AGENTS.md, copilot-instructions.md
1 parent d60abd5 commit 9d8793f

5 files changed

Lines changed: 512 additions & 2 deletions

File tree

.github/copilot-instructions.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copilot Instructions for confkit
2+
3+
This is confkit, a Go library for **typed, validated configuration loading** from multiple sources (YAML, JSON, TOML, environment variables, Kubernetes, Vault, Consul, etcd, AWS).
4+
5+
## Before Proposing Changes
6+
7+
- **Run tests first:** `go test ./...` must pass
8+
- **Preserve the public API** — only break it if the issue explicitly requires a breaking change
9+
- **Keep cloud/provider dependencies out of core** — they belong in optional submodules (`confkit/vault`, `confkit/consul`, etc.)
10+
- **Never expose `secret:"true"` fields** — redact them in all error messages, dumps, and logs
11+
- **Update docs when behavior changes** — README.md, docs/, examples/, llms.txt, and AGENTS.md must reflect the change
12+
13+
## Code Quality Rules
14+
15+
- **80%+ test coverage** on core logic (use `go test -cover ./...`)
16+
- **Clear error messages** — include field name, source, rule that failed, and actual value (redacted if secret)
17+
- **No global state** — validators and middleware are per-Load call, never globally registered
18+
- **Minimal dependencies** — core only uses `gopkg.in/yaml.v3` and `github.com/pelletier/go-toml/v2`
19+
- **Table-driven tests** for validators, parsers, and type conversions
20+
- **Comment WHY, not WHAT** — code should be self-documenting; only comment hidden constraints or surprising behavior
21+
22+
## Testing Checklist
23+
24+
- [ ] Unit tests pass: `go test ./...`
25+
- [ ] Coverage acceptable: `go test -cover ./...` shows 80%+ on touched files
26+
- [ ] Example code runs: any new examples in README/docs are tested
27+
- [ ] Integration tests work: multiple sources, precedence, nested structs
28+
- [ ] No regressions: existing tests still pass
29+
- [ ] Error messages are clear and redact secrets
30+
31+
## Documentation Checklist
32+
33+
- [ ] README.md updated (if public API changed)
34+
- [ ] llms.txt updated (if API functions or tag semantics changed)
35+
- [ ] docs/ updated (if behavior changed)
36+
- [ ] examples/ updated (if patterns changed)
37+
- [ ] AGENTS.md updated (if architectural decisions changed)
38+
39+
## Key Principles
40+
41+
1. **Core is iron** — keep loading, validation, errors, and secret redaction rock solid
42+
2. **Type-safe first** — prefer generics and strong types over dynamic/string-based config
43+
3. **Fail fast** — validate at startup, not after hours of debugging
44+
4. **Human-readable errors** — error messages are the killer feature
45+
5. **Secrets protected**`secret:"true"` fields are never exposed anywhere
46+
6. **Lean core** — enterprise features go in optional submodules
47+
48+
## File Structure
49+
50+
- `load.go` — Core Load[T], LoadWithOptions[T], LoadWithWatcher[T] functions
51+
- `field_info.go` — FieldInfo type and struct tag scanning
52+
- `parser.go` — Type parsing (int, float, bool, duration, slices, etc.)
53+
- `sources.go` — Source interface definition
54+
- `*_source.go` — Individual source implementations (env, yaml, json, toml, flags, k8s)
55+
- `validation.go` — Validation engine and built-in validators
56+
- `errors.go` — ErrorReport, FieldError, Explain() function
57+
- `options.go` — Functional options (WithSource, WithValidator, WithMiddleware)
58+
- `interpolation.go` — String interpolation ${VAR} support
59+
- `watcher.go` — Hot reload / file watching
60+
- `vault/`, `consul/`, `etcd/`, `aws/` — Optional enterprise sources (separate modules)
61+
- `examples/` — Runnable examples for each feature
62+
- `Docs/` — Iteration specs and design docs
63+
64+
## Do NOT
65+
66+
- Add feature flags or backwards-compat shims (just change the code)
67+
- Add error handling for impossible scenarios (trust framework guarantees)
68+
- Add TODO comments without a GitHub issue reference
69+
- Validate input that should be validated by the caller (trust at boundaries)
70+
- Export helper functions or types unless they're part of the public API contract
71+
- Break the Source interface or Load[T] signature lightly
72+
73+
## Do
74+
75+
- Run `gofmt -w .` before committing
76+
- Add test cases for edge cases
77+
- Redact secrets in error messages
78+
- Update docs when changing behavior
79+
- Keep commits focused and clear
80+
- Reference GitHub issues in commit messages when fixing bugs
81+
82+
## Questions?
83+
84+
See AGENTS.md for more detailed guidance on architecture, patterns, and LLM-specific use cases.

AGENTS.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Agent Instructions for confkit
2+
3+
confkit is a Go library for **typed, validated configuration loading** from multiple sources (YAML, JSON, TOML, environment variables, Kubernetes, Vault, Consul, etcd, AWS SSM, AWS Secrets Manager).
4+
5+
## Project Intent
6+
7+
Use confkit when Go services need:
8+
9+
- **Type-safe config** via `Load[T]` generics (no `GetString()` accessors)
10+
- **Validation at startup** (fail fast with clear error messages)
11+
- **Automatic secret redaction** (fields tagged `secret:"true"` are never exposed in errors or logs)
12+
- **Multiple sources** with explicit precedence (YAML → env vars → CLI flags)
13+
- **Optional enterprise integrations** (Vault, Consul, etcd, AWS) without bloating the core package
14+
- **Hot reload** support for config changes without restart
15+
16+
## Project Structure
17+
18+
```
19+
confkit/
20+
├── load.go # Load[T], LoadWithOptions[T], LoadWithWatcher[T]
21+
├── field_info.go # FieldInfo type and struct tag scanning
22+
├── parser.go # Type parsing (int, float, bool, duration, etc.)
23+
├── sources.go # Source interface
24+
├── env_source.go # FromEnv()
25+
├── yaml_source.go # FromYAML(path)
26+
├── json_source.go # FromJSON(path)
27+
├── toml_source.go # FromTOML(path)
28+
├── flags_source.go # FromFlags()
29+
├── validation.go # Built-in validators (required, min, max, oneof)
30+
├── errors.go # ErrorReport with field-level errors and redaction
31+
├── options.go # Functional options (WithSource, WithValidator, etc.)
32+
├── interpolation.go # String interpolation ${VAR}
33+
├── watcher.go # Hot reload / file watching
34+
├── observability.go # Config dump, metrics
35+
├── k8s_source.go # Kubernetes ConfigMap/Secret
36+
├── vault/ # HashiCorp Vault (separate module)
37+
├── consul/ # HashiCorp Consul KV (separate module)
38+
├── etcd/ # etcd v3 (separate module)
39+
├── aws/ # AWS SSM + Secrets Manager (separate module)
40+
└── examples/ # Runnable examples for each feature
41+
```
42+
43+
## Important Commands
44+
45+
**Run tests:**
46+
```bash
47+
go test ./...
48+
go test -cover ./...
49+
```
50+
51+
**Format code:**
52+
```bash
53+
gofmt -w .
54+
```
55+
56+
**Check module health:**
57+
```bash
58+
go mod tidy
59+
go test ./...
60+
```
61+
62+
**Run linter:**
63+
```bash
64+
golangci-lint run
65+
```
66+
67+
## Code Style & Principles
68+
69+
- **Core is iron:** The five core pieces (loading, defaulting, validation, errors, types) must be rock solid. Don't add experimental features to core.
70+
- **Keep core lightweight:** Only depend on `gopkg.in/yaml.v3` and `github.com/pelletier/go-toml/v2` in the main package.
71+
- **Cloud SDKs belong in submodules:** Vault, Consul, etcd, AWS, Kubernetes integrations go in optional `confkit/vault`, `confkit/consul`, etc.
72+
- **Preserve clear error messages:** This is the killer feature. Error messages must identify: field name, rule that failed, actual value (redacted if secret), and source.
73+
- **Never expose secret-tagged fields:** Any field with `secret:"true"` must be redacted in errors, dumps, logs, and anywhere else.
74+
- **No global state:** Validators and middleware are registered per Load[T] call, never globally.
75+
76+
## Public API Stability
77+
78+
Be very careful when modifying these (breaking changes require major version bump):
79+
80+
- `Load[T](...Source) (T, error)`
81+
- `LoadWithOptions[T](...Option) (T, error)`
82+
- `LoadWithWatcher[T](filePath string, ...Source) (T, *ConfigWatcher, error)`
83+
- `Explain(err error) string`
84+
- `Source` interface (`Name()`, `Lookup(*FieldInfo)`)
85+
- `FieldInfo` type
86+
- Validation tag semantics (`required`, `min`, `max`, `oneof`)
87+
- Secret redaction behavior (fields tagged `secret:"true"` must always be redacted)
88+
89+
Internal types like `ErrorReport`, `FieldError` can be modified with better backwards-compat.
90+
91+
## Documentation Updates
92+
93+
When changing public behavior:
94+
95+
1. Update `README.md` with examples and explanations
96+
2. Update `docs/` (on GitHub Pages) with guides and tutorials
97+
3. Update `llms.txt` with new API functions or tag semantics
98+
4. Add/update examples in `examples/` folder
99+
5. Update relevant iteration doc in `Docs/` (e.g., `Docs/03-iteration-v03.md`)
100+
101+
## Testing Guidelines
102+
103+
- **Unit tests:** Each source, parser, and validator tested independently
104+
- **Integration tests:** Multiple sources, precedence, nested structs, full workflows
105+
- **Example tests:** Every documented example must run and produce expected output
106+
- **Coverage target:** 80%+ on core logic
107+
108+
Write table-driven tests for validators and type parsing.
109+
110+
## Release Process
111+
112+
1. Bump version in `go.mod` (follows semantic versioning)
113+
2. Update `CHANGELOG.md` with summary of changes
114+
3. Create git tag: `git tag v0.X.Y`
115+
4. Push tag: `git push origin v0.X.Y`
116+
5. GitHub Actions builds and publishes release notes automatically
117+
118+
## LLM & AI Agent Patterns
119+
120+
confkit is well-suited for Go services that use LLMs:
121+
122+
**Pattern 1: LLM API client config**
123+
```go
124+
type LLMConfig struct {
125+
Provider string `env:"LLM_PROVIDER" validate:"oneof=claude,openai,anthropic"`
126+
APIKey string `env:"LLM_API_KEY" secret:"true" validate:"required"`
127+
Model string `env:"LLM_MODEL" default:"claude-3-5-sonnet"`
128+
Temperature float64 `env:"LLM_TEMPERATURE" default:"0.7" validate:"min=0,max=1"`
129+
MaxTokens int `env:"LLM_MAX_TOKENS" default:"4096"`
130+
}
131+
132+
cfg, err := confkit.Load[LLMConfig](confkit.FromEnv())
133+
```
134+
135+
**Pattern 2: Multi-model configuration**
136+
```go
137+
type Config struct {
138+
Primary LLMConfig
139+
Fallback LLMConfig
140+
CacheTTL time.Duration `env:"CACHE_TTL" default:"1h"`
141+
}
142+
143+
cfg, err := confkit.Load[Config](
144+
confkit.FromYAML("llm-config.yaml"),
145+
confkit.FromEnv(),
146+
)
147+
```
148+
149+
**Pattern 3: Hot reload for prompt templates or LLM parameters**
150+
```go
151+
cfg, watcher, err := confkit.LoadWithWatcher[Config](
152+
"llm-config.yaml",
153+
confkit.FromYAML("llm-config.yaml"),
154+
)
155+
156+
go func() {
157+
for newCfg := range watcher.Changes() {
158+
// Update LLM client with new parameters
159+
updateLLMClient(newCfg)
160+
}
161+
}()
162+
```
163+
164+
## Questions for Agent Implementation?
165+
166+
- How to add a new source type? → Implement `Source` interface, look at `env_source.go` as reference
167+
- How to add custom validation? → Use `confkit.WithValidator("name", func(v reflect.Value) error { ... })`
168+
- How to handle secrets safely? → Tag with `secret:"true"` and use `confkit.Explain()` for errors
169+
- How to support nested config? → Use nested struct fields; optional `prefix` tag for env prefix
170+
- How to debug config loading? → Call `confkit.Explain(err)` for human-readable errors
171+
172+
## Key Files to Reference
173+
174+
- `llms.txt` — LLM-readable API summary (this file is served at `https://mimojanra.github.io/confkit/llms.txt`)
175+
- `README.md` — Project overview, quick start, examples
176+
- `SECURITY.md` — Vulnerability reporting, security best practices
177+
- `docs/` — Full documentation (Getting Started, API Reference, Examples)
178+
- `Docs/01-iteration-v01-mvp.md` — v0.1 specification and design decisions
179+
- `CONTRIBUTING.md` — Contribution guidelines

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
[![GitHub Release](https://img.shields.io/github/v/release/MimoJanra/confkit.svg)](https://github.com/MimoJanra/confkit/releases)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/MimoJanra/confkit)](https://goreportcard.com/report/github.com/MimoJanra/confkit)
77
[![Documentation](https://img.shields.io/badge/docs-mimojanra.github.io-blue)](https://mimojanra.github.io/confkit/)
8+
[![LLM Context](https://img.shields.io/badge/llms.txt-reference-brightgreen)](./llms.txt)
89

910
**[📖 Full Documentation](https://mimojanra.github.io/confkit/)** — Getting started, API reference, examples, and cloud integrations.
1011

12+
**[🤖 LLM Context](./llms.txt)** — Machine-readable API reference for Claude, Copilot, and other AI coding assistants.
13+
1114
> **Typed, validated configuration loading for Go** — the Pydantic equivalent for Go services.
1215
>
1316
> Load configuration from multiple sources (environment, YAML, JSON, TOML, Kubernetes, AWS, Vault, Consul, etcd) with type safety, validation, and human-readable error messages.

0 commit comments

Comments
 (0)