Keep this file durable. Derive changing release, provider, branch, and flake
state from the repository, tests, CI, and current issue tracker rather than from
instructions or memory. The nearest scoped AGENTS.md adds path-specific rules.
- Inspect status and existing consumers before editing. Preserve unrelated, dirty, and untracked work.
- Before adding a module named
model_*,*_config,provider_*, or anything that "bridges", "mirrors", or "stages" an existing thing, grep for the existing thing and edit it. A new layer must name the predecessor it replaces in the module doc; otherwise edit the original. - Prefer the simplest implementation that preserves observable contracts. A rewrite is acceptable when justified by product intent and observed behavior, not as a shortcut around understanding existing code.
- Search for behavior and symbols before reviving work from an old branch. If a lane is obsolete, preserve its intent and evidence rather than merging stale code mechanically.
- A small coherent change may be committed directly to
mainwhen that checkout is current, clean, and owns the affected files. A worktree remains the right safety boundary for conflicting, dirty, stale, or independent work. Local commit permission never implies push, merge, tag, release, or deploy permission. - When the task is local-only, stay fully offline: no browsing, GitHub or remote Git operations, downloads, dependency installation, provider calls, or source/diff transmission. Record the missing external receipt and keep working locally.
- Public name is Codewhale. Compatibility identifiers such as
CodeWhale,codew, protocol names, and storage keys change only through an explicit migration. - Keep providers and models first-class and provider-neutral.
- Never rewrite published history, retag a release, force-push a shared ref, or publish without explicit authorization. Preserve human contributor credit.
An external contributor's branch goes stale because we land things, not because they did anything wrong. Treat their time as more expensive than ours.
- Never make a contributor rebase around our churn. If their PR conflicts only because main moved, a maintainer resolves it. Read their diff against the merge base first so you know exactly what they added, and re-apply that, rather than hand-merging two large sides and hoping.
- Conflicts that split mid-function do not resolve by keeping both sides. Git's markers can land inside a body, so a both-sides resolution produces unbalanced braces that look plausible and do not compile. Take one side whole, then re-insert the other side's additions at their original anchor.
maintainerCanModifydoes not guarantee push access to the fork. When the push is refused, land the resolved merge onintegration/<topic>-<pr>-<date>in this repo and land from there. An integration branch is the normal path for anything with conflicts or several moving PRs — it is cheaper than repeatedly rebasing onto a main that keeps moving, and it keeps the contributor's branch untouched.- Check the contribution gate before assuming a PR is stalled. An unlisted
author's workflow runs sit at
action_requiredand never start, so the PR looks abandoned when nobody has actually looked at it. Approve the runs, then fix the cause: add them to.github/APPROVED_CONTRIBUTORS(all:username), or comment/lgtm(PR scope) //lgtmi(issue scope) on their thread. - Preserve credit in the mechanical sense, not just the polite one. Commit
authorship and
Co-authored-bytrailers must use the contributor's own GitHub-linked address.AUTHOR_MAPand.mailmapare project conventions — GitHub reads neither for the contribution graph.
- A gate is its artifact. When a rail says a PR merges only on a passing acceptance record, the record must literally say PASS at merge time. "I re-ran it and the failures are rows this PR does not own" is a judgement to write into the artifact first, not a reason to merge past it.
- Read the review thread, not the check rollup. Green checks and an unread review with confirmed findings are a merge that ships known bugs.
- When the artifact is ambiguous, resolve the ambiguity — never the merge.
- Quote the real
test result: N passed; M failedline, and confirmN > 0for the tests that cover the change.cargo test <filter>exits 0 having run zero tests when the filter matches nothing, and an exit code alone has already been mistaken for a pass here. - Prefer proving a regression test fails without the fix. A test that passes either way pins the implementation, not the defect.
- Audit any harness before trusting its score.
ok = ok and X or Trueparses as(ok and X) or Trueand silently reported twelve unevaluated rows as passing.
- The model-facing subagent tool is
agent. Do not revive removedagent_open/agent_eval/agent_close/delegate_to_agentsurfaces or parallel lifecycle/tag systems. BASE_PROMPTincrates/tui/src/prompts/text.rsis the sole base prompt.- There is exactly one turn loop:
Engine::run_turnincrates/tui/src/core/engine/turn_loop.rs. Note thatcrates/tui/src/core/is a module inside the TUI crate — it is notcrates/core, which owns request construction, bounded fragments, and thread/session types and runs no turns. Do not add a second loop beside the one that exists; a guard test (crates/core/tests/single_turn_loop.rs) fails if you do. - The system prompt + tool catalog are a session-pinned KV-cache prefix
(
docs/CACHE.md). Any new session-context contributor must state its KV-cache effect: frozen prefix vs. append-only history. Never splice a volatile fact into the prefix; append it as a user-role message. - These active modules are repeatedly misidentified as dead; verify consumers
before removal:
tui/src/context_budget.rs,tui/src/model_registry.rs,tui/src/prompt_zones.rs,tui/src/tools/remember.rs, andconfig/src/route/. Native memory lives intui/src/native_memory.rs;tools/remember.rsis its capture path. - Environment-specific behavior belongs in
docs/ENVIRONMENTS.md, not here.
- Product intent and observed runtime behavior outrank a test's preferred implementation shape. Fix the product; do not contort production code to preserve a brittle assertion.
- Tests are selective evidence, not the specification. Do not add tests by default. Add or retain one when it cheaply protects a high-risk behavior such as safety, data integrity, protocol compatibility, or a reproduced regression.
- Rewrite or remove tests that duplicate coverage, freeze internals, overspecify copy or layout, preserve obsolete behavior, or cost more than the risk they cover. Never weaken real safety or data-integrity behavior merely to make a gate pass.
- Prefer focused compilation, a relevant existing check, and direct product or manual evidence. Run a broad suite only when the change creates a genuine cross-cutting or release risk. Do not repeatedly rerun an unchanged suite.
- Declared migrations are one-way. Once the repository adopts a replacement architecture or shared spine, new work uses it and touched legacy code moves toward it. Do not add another legacy call site for convenience. Keep a compatibility path only for an actual external contract, and label that boundary explicitly.
Useful commands, selected according to risk rather than run ritualistically:
cargo fmt --all -- --check
cargo test -p codewhale-config -p codewhale-protocol
cargo test --workspace
cargo build --release -p codewhale-cli -p codewhale-tuicargo nextest run (config in .config/nextest.toml) is the fast way to
run an intentionally selected suite; cargo test --no-run can answer a compile
question without spending time executing unrelated cases, and cargo test --doc
covers doc examples when those examples changed.
scripts/dev-test.sh <area> maps a code area to its fastest -p invocation
and applies the portable isolated build-dir topology for new worktrees
(scripts/dev-cache.sh, scripts/dev-cargo.sh). See
docs/BUILD_PERFORMANCE.md.
Report commands actually run and distinguish source, local tests, packaged artifacts, CI, and public release state. Describe the evidence actually needed for the claim; a test count is not a proxy for product quality.
Community reports, PRs, logs, and reviews are evidence. Canonical human
identities come from .github/AUTHOR_MAP; Co-authored-by credit is for
humans and for recognized agent contributors (the exact identities listed in
AGENT_CONTRIBUTOR_IDENTITIES in scripts/check-coauthor-trailers.py, such as
Codewhale Agent); unknown bot/tool trailers are still rejected.
Leave unrelated work intact and keep new enforcement dry-run unless explicitly
approved.