|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`kat` is a rule-based rendering engine and terminal UI for Kubernetes manifests. It automatically invokes manifest generators (Helm, Kustomize, etc.) and provides a navigable view of rendered resources with live reloading, validation, and an optional MCP server. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Format code |
| 13 | +task format |
| 14 | + |
| 15 | +# Lint all (Go, YAML, Actions, Renovate, GoReleaser) |
| 16 | +task lint |
| 17 | + |
| 18 | +# Run tests |
| 19 | +task test |
| 20 | + |
| 21 | +# Run a single test |
| 22 | +go test ./pkg/config -run TestConfigLoader |
| 23 | +``` |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +### Entry Point & CLI |
| 28 | + |
| 29 | +- `cmd/kat/main.go` - Entry point using charmbracelet/fang |
| 30 | +- `internal/cli/` - CLI commands, flags, and environment binding |
| 31 | + |
| 32 | +### Core Packages (`pkg/`) |
| 33 | + |
| 34 | +**Rendering Pipeline:** |
| 35 | + |
| 36 | +- `pkg/command/` - Command execution orchestration, file watching, event broadcasting |
| 37 | +- `pkg/profile/` - Profile definitions with CEL-based source/reload expressions, hooks, plugins |
| 38 | +- `pkg/rule/` - CEL-based rule matching for automatic profile selection |
| 39 | +- `pkg/expr/` - CEL expression compilation and evaluation with custom functions (pathBase, pathExt, yamlPath, etc.) |
| 40 | + |
| 41 | +**Kubernetes & YAML:** |
| 42 | + |
| 43 | +- `pkg/kube/` - Kubernetes resource parsing and object representation |
| 44 | +- `pkg/yaml/` - YAML encoding/decoding, validation, error formatting |
| 45 | + |
| 46 | +**UI (Bubble Tea):** |
| 47 | + |
| 48 | +- `pkg/ui/` - Main TUI program and state management |
| 49 | +- `pkg/ui/list/` - Resource list with fuzzy filtering |
| 50 | +- `pkg/ui/pager/` - YAML document viewer with syntax highlighting |
| 51 | +- `pkg/ui/menu/` - Configuration menu for profile/path changes |
| 52 | +- `pkg/ui/overlay/` - Error/loading overlays |
| 53 | +- `pkg/ui/theme/` - Chroma-based theming |
| 54 | + |
| 55 | +**Other:** |
| 56 | + |
| 57 | +- `pkg/config/` - Configuration loading, validation, and default config embedding |
| 58 | +- `pkg/mcp/` - Model Context Protocol server for AI integrations |
| 59 | +- `pkg/execs/` - Command execution utilities |
| 60 | +- `pkg/keys/` - Keybinding definitions |
| 61 | + |
| 62 | +### Data Flow |
| 63 | + |
| 64 | +1. CLI parses args and loads config from `$XDG_CONFIG_HOME/kat/config.yaml` |
| 65 | +2. `command.Runner` matches path against rules to select a profile |
| 66 | +3. Profile executes command with hooks (init, preRender, postRender) |
| 67 | +4. Rendered YAML is parsed into `kube.Resource` objects |
| 68 | +5. Events broadcast to UI and MCP server subscribers |
| 69 | +6. UI displays resources in list/pager views |
| 70 | + |
| 71 | +## Code Style |
| 72 | + |
| 73 | +### Go Conventions |
| 74 | + |
| 75 | +- Document all exported items with doc comments |
| 76 | +- Use `[Name]` syntax for Go doc links |
| 77 | +- Package documentation in `doc.go` files |
| 78 | +- Wrap errors with `fmt.Errorf("context: %w", err)` - no "failed" or "error" in messages |
| 79 | +- Use global error variables for common errors |
| 80 | + |
| 81 | +### Testing |
| 82 | + |
| 83 | +- Use `github.com/stretchr/testify/assert` and `require` |
| 84 | +- Table-driven tests with `map[string]struct{}` format |
| 85 | +- Field names: `input`, `want`, `got`, `err` |
| 86 | +- Always use `t.Parallel()` in all tests |
| 87 | +- Create test packages (`package foo_test`) testing public API |
| 88 | +- Use `require.ErrorIs` for error type checking |
| 89 | + |
| 90 | +## Key Dependencies |
| 91 | + |
| 92 | +- `github.com/charmbracelet/bubbletea` - TUI framework |
| 93 | +- `github.com/google/cel-go` - CEL expression engine |
| 94 | +- `github.com/alecthomas/chroma/v2` - Syntax highlighting |
| 95 | +- `github.com/goccy/go-yaml` - YAML with anchors/aliases support |
| 96 | +- `github.com/fsnotify/fsnotify` - File watching |
| 97 | +- `github.com/modelcontextprotocol/go-sdk` - MCP server |
0 commit comments