|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to coding agents collaborating on this repository. |
| 4 | + |
| 5 | +## Mission |
| 6 | + |
| 7 | +Chilli is a command-line interface (CLI) microframework for Zig. |
| 8 | +It turns a declarative description of commands, flags, and positional arguments into a parser, help generator, and dispatcher, with zero external |
| 9 | +dependencies. |
| 10 | +Priorities, in order: |
| 11 | + |
| 12 | +1. Correctness of argument parsing, flag resolution, and help output. |
| 13 | +2. Minimal public API for defining and running command trees from other Zig projects. |
| 14 | +3. Zero non-Zig dependencies, maintainable, and well-tested code. |
| 15 | +4. Cross-platform support (Linux, macOS, and Windows). |
| 16 | + |
| 17 | +## Core Rules |
| 18 | + |
| 19 | +- Use English for code, comments, docs, and tests. |
| 20 | +- Prefer small, focused changes over large refactoring. |
| 21 | +- Add comments only when they clarify non-obvious behavior. |
| 22 | +- Do not add features, error handling, or abstractions beyond what is needed for the current task. |
| 23 | +- Keep the project dependency-free: no external Zig packages or C libraries unless explicitly agreed. |
| 24 | + |
| 25 | +## Writing Style |
| 26 | + |
| 27 | +- Use Oxford commas in inline lists: "a, b, and c" not "a, b, c". |
| 28 | +- Do not use em dashes. Restructure the sentence, or use a colon or semicolon instead. |
| 29 | +- Avoid colorful adjectives and adverbs. Write "TCP proxy" not "lightweight TCP proxy", "scoring components" not "transparent scoring components". |
| 30 | +- Use noun phrases for checklist items, not imperative verbs. Write "redundant index detection" not "detect redundant indexes". |
| 31 | +- Headings in Markdown files must be in the title case: "Build from Source" not "Build from source". Minor words (a, an, the, and, but, or, for, in, |
| 32 | + on, at, to, by, of, is, are, was, were, be) stay lowercase unless they are the first word. |
| 33 | + |
| 34 | +## Repository Layout |
| 35 | + |
| 36 | +- `src/lib.zig`: Public API entry point. Re-exports `Command`, `CommandOptions`, `Flag`, `FlagType`, `FlagValue`, `PositionalArg`, `CommandContext`, |
| 37 | + `styles`, and `Error`. |
| 38 | +- `src/chilli/command.zig`: The `Command` struct (command tree, init/deinit, `run`, subcommand and flag registration). |
| 39 | +- `src/chilli/types.zig`: Core types (`CommandOptions`, `Flag`, `FlagType`, `FlagValue`, `PositionalArg`) and the `parseValue` helper. |
| 40 | +- `src/chilli/parser.zig`: Argument-string parser (`ArgIterator`, `ParsedFlag`, long/short/grouped flag handling, positional handling). |
| 41 | +- `src/chilli/context.zig`: The `CommandContext` passed to each command's `exec` function for typed flag and argument access. |
| 42 | +- `src/chilli/errors.zig`: Error types produced by parsing and type coercion. |
| 43 | +- `src/chilli/utils.zig`: Shared helpers (`styles` for ANSI colors, `parseBool`, and other small utilities). |
| 44 | +- `examples/`: Self-contained example programs (`e1_simple_cli.zig` through `e8_flags_and_args.zig`) built as executables via `build.zig`. |
| 45 | +- `.github/workflows/`: CI workflows (`tests.yml` for unit tests on Linux and Windows, `docs.yml` for API doc deployment). |
| 46 | +- `build.zig` / `build.zig.zon`: Zig build configuration and package metadata. |
| 47 | +- `Makefile`: GNU Make wrapper around `zig build` targets. |
| 48 | +- `docs/`: Generated API docs land in `docs/api/` (produced by `make docs`). |
| 49 | + |
| 50 | +## Architecture |
| 51 | + |
| 52 | +### Command Tree |
| 53 | + |
| 54 | +A Chilli application is a tree of `Command` nodes. Each node owns its `flags`, `positional_args`, optional `exec` |
| 55 | +function, and a list of subcommands. `Command.init` allocates a node; `Command.deinit` recursively frees the subtree, so |
| 56 | +downstream users call `deinit` only on the root. |
| 57 | + |
| 58 | +### Parsing Pipeline |
| 59 | + |
| 60 | +Arguments flow through: `ArgIterator` over `[][]const u8` (`parser.zig`) -> per-node flag and positional resolution |
| 61 | +(`parser.zig` + `command.zig`) -> `CommandContext` population (`context.zig`) -> `exec` dispatch on the resolved leaf |
| 62 | +command. |
| 63 | + |
| 64 | +### Flag and Positional Types |
| 65 | + |
| 66 | +`FlagType` (`types.zig`) enumerates the supported value kinds (`Bool`, `Int`, `Float`, `String`). `FlagValue` is the matching-tagged union. |
| 67 | +`types.parseValue` is the single conversion point from raw strings into a `FlagValue`; every new type or coercion belongs here. |
| 68 | + |
| 69 | +### Help and Version Output |
| 70 | + |
| 71 | +Help and version text are generated automatically from the command tree at runtime by `command.zig`, using the metadata in `CommandOptions` (name, |
| 72 | +description, version, sections) and the registered flags and positional args. Grouping into |
| 73 | +named sections is supported; custom help formatting beyond that should be added sparingly. |
| 74 | + |
| 75 | +### Public API Surface |
| 76 | + |
| 77 | +Everything re-exported from `src/lib.zig` is part of the public API. Changes to names or signatures there are breaking. |
| 78 | +The rest of `src/chilli/` is internal and may be refactored freely as long as the public surface and its behavior are |
| 79 | +preserved. |
| 80 | + |
| 81 | +### Dependencies |
| 82 | + |
| 83 | +Chilli has **no external Zig or C dependencies**. |
| 84 | +The only `build.zig.zon` entries should be Chilli itself. |
| 85 | +Please do not add dependencies without prior discussion. |
| 86 | + |
| 87 | +## Zig Conventions |
| 88 | + |
| 89 | +- Zig version: 0.16.0 (as declared in `build.zig.zon` and the Makefile's `ZIG_LOCAL` path). |
| 90 | +- Formatting is enforced by `zig fmt`. Run `make format` before committing. |
| 91 | +- Naming follows Zig standard-library conventions: `camelCase` for functions (e.g. `addFlag`, `getFlag`, `parseBool`), `snake_case` for local |
| 92 | + variables and struct fields, `PascalCase` for types and structs, and `SCREAMING_SNAKE_CASE` for top-level compile-time constants. |
| 93 | + |
| 94 | +## Required Validation |
| 95 | + |
| 96 | +Run the relevant targets for any change: |
| 97 | + |
| 98 | +| Target | Command | What It Runs | |
| 99 | +|----------------|----------------------------------|------------------------------------------------------------------| |
| 100 | +| Unit tests | `make test` | Inline `test` blocks across `src/lib.zig` and `src/chilli/*.zig` | |
| 101 | +| Lint | `make lint` | Checks Zig formatting with `zig fmt --check src examples` | |
| 102 | +| Single example | `make run EXAMPLE=e1_simple_cli` | Builds and runs one example program | |
| 103 | +| All examples | `make run` | Builds and runs every example under `examples/` | |
| 104 | +| Docs | `make docs` | Generates API docs into `docs/api` | |
| 105 | +| Everything | `make all` | Runs `build`, `test`, `lint`, and `docs` | |
| 106 | + |
| 107 | +## First Contribution Flow |
| 108 | + |
| 109 | +1. Read the relevant module under `src/chilli/` (often `command.zig`, `parser.zig`, or `types.zig`). |
| 110 | +2. Implement the smallest change that covers the requirement. |
| 111 | +3. Add or update inline `test` blocks in the changed Zig module to cover the new behavior. |
| 112 | +4. Run `make test` and `make lint`. |
| 113 | +5. If parser or help-output behavior changed, also exercise the examples with `make run` and confirm the `--help` output is still correct. |
| 114 | + |
| 115 | +Good first tasks: |
| 116 | + |
| 117 | +- New example under `examples/` that demonstrates an API pattern, listed in `examples/README.md`. |
| 118 | +- New flag-coercion case in `src/chilli/types.zig` `parseValue` (with an inline `test` block). |
| 119 | +- Error message refinement in `src/chilli/errors.zig`, paired with a test that asserts the exact message. |
| 120 | +- Help-formatting refinement in `src/chilli/command.zig`. |
| 121 | + |
| 122 | +## Testing Expectations |
| 123 | + |
| 124 | +- Unit and regression tests live as inline `test` blocks in the module they cover (`src/lib.zig` and `src/chilli/*.zig`). There is no separate |
| 125 | + `tests/` directory. |
| 126 | +- Tests are discovered automatically via `std.testing.refAllDecls(@This())` in `src/lib.zig`, so new `test` blocks only need to live in a module that |
| 127 | + is reachable from `lib.zig`. |
| 128 | +- Every new public function, flag type, or parser branch must ship with at least one `test` block that exercises it, including the error paths where |
| 129 | + applicable. |
| 130 | +- Tests that touch argument parsing should build their input as `[][]const u8` explicitly, not read from `std.process.args()`, so they work under |
| 131 | + `zig test` without a real process-args environment. |
| 132 | +- No public API change is complete without a test covering the new or changed behavior. |
| 133 | + |
| 134 | +## Change Design Checklist |
| 135 | + |
| 136 | +Before coding: |
| 137 | + |
| 138 | +1. Modules affected by the change (`command`, `parser`, `types`, `context`, `errors`, or `utils`). |
| 139 | +2. Whether the change is user-visible in `--help` output, and if so, which examples will surface it. |
| 140 | +3. Public API impact, i.e. whether the change adds to or alters anything re-exported from `src/lib.zig`, and is therefore additive or breaking. |
| 141 | +4. Cross-platform implications, especially for anything that touches environment variables, the filesystem, or process-args encoding. |
| 142 | + |
| 143 | +Before submitting: |
| 144 | + |
| 145 | +1. `make test` passes. |
| 146 | +2. `make lint` passes. |
| 147 | +3. `make run` succeeds for all examples when touching the parser, command dispatch, or help-output code. |
| 148 | +4. Docs updated (`make docs`) if the public API surface changed, and `ROADMAP.md` ticked or updated if a listed item was implemented. |
| 149 | + |
| 150 | +## Commit and PR Hygiene |
| 151 | + |
| 152 | +- Keep commits scoped to one logical change. |
| 153 | +- PR descriptions should include: |
| 154 | + 1. Behavioral change summary. |
| 155 | + 2. Tests added or updated. |
| 156 | + 3. Whether examples were run locally (yes/no), and on which OS. |
0 commit comments