| 1 |
# AGENTS.md |
| 2 |
|
| 3 |
## Overview |
| 4 |
clnkr is a coding agent CLI that queries LLMs and executes bash commands in a loop. Core library is stdlib only. Talks to the Anthropic Messages API and any OpenAI-compatible endpoint. Ships `clnkr` (plain CLI) and `clnkrd` (stdio JSONL adapter). Evals run through the standalone `clankerval` project. |
| 5 |
|
| 6 |
## Commands |
| 7 |
``` |
| 8 |
make build # Build shipped binaries (default target) |
| 9 |
make test # Run all tests |
| 10 |
make check # Run the full quality suite |
| 11 |
make man # Generate staged man pages from doc/*.1.md |
| 12 |
make docs # Build the documentation site |
| 13 |
make docs-serve # Run the documentation site locally |
| 14 |
allium check specs/ # Validate Allium specs |
| 15 |
allium analyse specs/ # Analyse spec process gaps |
| 16 |
make _fmt # Format source |
| 17 |
make _hooks # Configure repo-local Git hooks |
| 18 |
``` |
| 19 |
Run `make _fmt` then `make check` before committing. Do not commit if either fails. |
| 20 |
|
| 21 |
## Rules |
| 22 |
- No external deps in root go.mod. Stdlib only. |
| 23 |
- Assume Unix (`bash`, process groups, `/usr/bin/env`). Windows unsupported. |
| 24 |
- Root `clnkr` is the only public import surface. `internal/` is allowed when it clarifies ownership. |
| 25 |
- Output goes through typed events. Do not add `io.Writer` parameters. |
| 26 |
- Policy logic in `Run()`, shared logic in `Step()`. No policy in `Step()`. |
| 27 |
- CLI config resolution stays in `cmd/internal/providerconfig`: env/flag precedence, `CLNKR_*`, API keys, base URL parsing, provider parsing, and user-facing config errors. |
| 28 |
- Provider request semantics stay in `internal/providers/providerconfig`: provider/API constants, request options, model capability checks, and provider-specific validation. |
| 29 |
- Provider adapters serialize validated options; they do not resolve CLI config. |
| 30 |
- `clnkrd` is a machine-facing stdio JSONL adapter over shared driver behavior for tools, editors, wrappers, eval harnesses, and automation. It is not the model's default delegation or subagent machinery. The host does not special-case `/delegate`, process counters, or process lifecycle events. |
| 31 |
- Wrap errors: `fmt.Errorf("context: %w", err)`. No bare returns or third-party error packages. |
| 32 |
- Adapter tests use external packages (`package anthropic_test`). Core tests use internal (`package clnkr`). CLI tests use internal (`package main`). Match the existing pattern. |
| 33 |
- `exhaustive` linter is enabled. Switch on sealed types must cover all cases. `default` counts as exhaustive. |
| 34 |
- Do not manually edit `CHANGELOG.md`; generated by the release pipeline. |
| 35 |
- Do not hand-edit generated files in `build/docs/`, `site/content/docs/clnkr.md`, `site/content/docs/clnkrd.md`, or `site/public/`. |
| 36 |
- Public-facing docs describe current behavior, not implementation history. No `in this pass`, `for now`, `currently deferred`. |
| 37 |
- SLOC gates count non-test Go only. Treat them as invariants and honesty constraints: do not shrink counted CLI help, diagnostics, UX, or error clarity to satisfy them, and do not weaken tests or docs to normalize that kind of regression. Agents must not raise SLOC limits unless the user explicitly gives a target number. If raising a gate is the only reasonable path, stop and ask for clarification. |
| 38 |
- For changes that touch clnkr's agent design, read `doc/clnkr.7.md` for current architecture context: act protocol, transcript, provider boundary, and command execution. It is descriptive, not prescriptive. Verify behavior in code and follow this file for rules. |
| 39 |
- Repo-maintenance helpers live under `scripts/`. Read `scripts/README.md` before adding new ones. |
| 40 |
|
| 41 |
## Architecture |
| 42 |
Core importable library at module root. Two command adapters. `evaluations/` consumed by external `clankerval` runner. |
| 43 |
``` |
| 44 |
clnkr/ # core: types, Agent, events (stdlib only) |
| 45 |
├── internal/providers/ # Anthropic/OpenAI adapters |
| 46 |
├── internal/session # Session persistence runtime boundary |
| 47 |
├── cmd/clnkr/ # Plain CLI (root go.mod, no external deps) |
| 48 |
├── cmd/clnkrd/ # Stdio JSONL adapter |
| 49 |
└── evaluations/ # Eval suites for clankerval |
| 50 |
``` |
| 51 |
|
| 52 |
**Agent API:** `Step()` = one typed-turn cycle, no policy. `ExecuteTurn()` = run an act turn, update state, emit events. `Run()` = full-send policy loop (3 consecutive protocol failures = exit). |
| 53 |
|
| 54 |
**Act protocol:** Three turn types: `act`, `clarify`, `done`. Providers own wire translation. Root `ParseTurn` validates canonical internal JSON for replay/tests only. |
| 55 |
|
| 56 |
**Events:** Sealed interface for typed agent notifications. Keep new event types explicit and exhaustive in adapters. Nil `Notify` = silent. |
| 57 |
|
| 58 |
**Command results (host→model):** JSON with `stdout`, `stderr`, `outcome`, and optional `feedback`. Exit outcomes include `exit_code`; non-exit outcomes include timeout, cancelled, denied, skipped, and error. |
| 59 |
|
| 60 |
**Machine-facing stdio adapter:** `clnkrd` is the composable JSONL process surface over shared driver behavior. Tools, editors, wrappers, eval harnesses, and automation may launch it through bash and read stdout, stderr, or event logs. It is not the model's default delegation or subagent machinery. `Driver`, provider adapters, `ShellExecutor`, and `Agent.Step()` do not participate in caller-specific orchestration policy. |
| 61 |
|
| 62 |
## Allium Specs |
| 63 |
Allium specs live under `specs/`. They describe observable behavior, not implementation history or Go structure. Keep them current when a change alters the intended behavior of a specified area. |
| 64 |
|
| 65 |
Allium setup and CLI install instructions live in the upstream README: |
| 66 |
https://github.com/juxt/allium/tree/main#get-started and |
| 67 |
https://github.com/juxt/allium/tree/main#command-line-tooling. |
| 68 |
|
| 69 |
Run `allium check specs/` after editing specs. Run `allium analyse specs/` when rules, surfaces, or process flow change. Fix diagnostics before committing. |
| 70 |
|
| 71 |
## Release |
| 72 |
Tag-driven. Push feature to `main`, wait for CI/evals/site to go green, then push the plain semantic version tag. Release workflow triggers from semver tags, updates `debian/main`, and generates Debian changelog. Remote `main` may move. Fetch and rebase before follow-up pushes. |
| 73 |
|
| 74 |
## Commit Metadata |
| 75 |
Before creating a commit, choose the functional area for the work. Every commit made by a coding agent must include exactly one `Functional-Area:` git trailer. |
| 76 |
|
| 77 |
Use a stable hyphenated area name. Pick it from the user-named feature, active roadmap item, or relevant atuin memory key when available. If the area is unclear, ask before committing. |
| 78 |
|
| 79 |
Examples: |
| 80 |
- `Functional-Area: context-management` for transcript, compaction, or context-budget changes |
| 81 |
- `Functional-Area: provider-config` for provider option and API configuration changes |
| 82 |
- `Functional-Area: docs` for documentation-only changes |
| 83 |
|
| 84 |
Commit with the trailer: |
| 85 |
``` |
| 86 |
git commit --trailer "Functional-Area: context-management" |
| 87 |
``` |
| 88 |
|
| 89 |
## Evals |
| 90 |
Optimize for live runs that measure actual agent behavior. Fixture evals exist for harness determinism in CI, not as the primary signal. `clankerval` requires a clean checkout. Make a temporary commit from a dirty worktree, run, then unroll. |
| 91 |
|
| 92 |
## Site |
| 93 |
Hugo site under `site/`. Source of truth for reference docs is `doc/*.1.md`. Run `make docs` to regenerate. Do not commit `site/public/`. Deployment to `gh-pages` is automatic from `main`. |
| 94 |
|
| 95 |
## Testing |
| 96 |
- Provider adapters: `httptest.NewServer`, external test packages, no real API calls |
| 97 |
- Agent loop: `fakeModel`/`fakeExecutor` in `agent_test.go` |
| 98 |
- CLI: inject via narrowest local interface, not concrete structs |
| 99 |
- Executor: real shell integration tests; handles macOS `/private/tmp` symlink |
| 100 |
|
| 101 |
## CI |
| 102 |
GitHub Actions on push to `main` and PRs. Runs lint, tests (`-race`), build, docs, and evals. `make check` also enforces architecture edges and core SLOC accounting. Run `make _hooks` for local pre-commit. golangci-lint required. |