Operational instructions for AI coding agents working in Rig. Contributor policy and PR etiquette live in CONTRIBUTING.md; verification, review, and publication in DEVELOPING.md; test conventions and commands in tests/README.md. This file states rules, not APIs: read the code and manifests for names, signatures, module paths, and feature flags.
- Read the existing implementation before changing code.
- Keep changes scoped to the user's request.
- Prefer existing Rig traits, builders, modules, and error types over new abstractions.
- Do not add TODOs, stubs, placeholder implementations, speculative APIs, or backwards compatibility shims.
- Do not make commits, comments, stage changes, push branches, or open PRs unless the user explicitly asks.
- Do not discard user changes.
- Iterate with
cargo nextest run --locked --profile local -p <crate> [filter]; leave workspace-wide and facade--all-featuresruns to CI. - Before pushing, run
cargo xtask verify --affected --base origin/main: the checks CI's plan selects for the diff, but the Docker and macOS jobs. - Keep incremental compilation on.
- Reuse instructions and unchanged source already in context. Read the relevant sections of linked documents, not every document for every task.
- Use the repository map below to narrow searches to the owning crate or test target. Read complete relevant constructs; widen only when needed.
- Check actual signatures and existing test conventions before writing examples or smoke programs, rather than discovering APIs through compiler errors.
- Keep commands and edits on the intended worktree. Confirm the language server indexes it before trusting references; empty results outside its workspace are not proof of no callers. Inspect native/WASM branches explicitly.
- Request only decision-relevant output. Recover missing diagnostic context from truncated output rather than dumping or fetching the entire log again.
- Root facade crate:
rig(re-exports the core crate, exposes companion crates behind feature flags, and ships therigbinary, a call intocrates/rig-clibehind the defaultclifeature) - Core crate:
crates/rig-core - Companion provider, vector-store, memory, and integration crates:
crates/rig-* - Derive macros:
crates/rig-derive - The rig coding agent: its launcher
crates/rig-cli(the library the root package'srigbinary runs), its corecrates/rig-harness(oncrates/rig-ecsandcrates/rig-tools), the settings and layout both share incrates/rig-harness-protocol, the markdown rendering and word wrapping its terminal view and print mode share incrates/rig-markdown, its plugin cratesplugins/rig-*, their shared test supporttest-support/rig-harness-test-support, andtest-support/rig-defaults-test-support(the default plugins for tests, and the test that each can be left out); all but the two test-support crates are published - The plugin corpus
corpus/*: plugins written against the harness's public API that shaped and prove the kernel, one per module (src/<plugin>.rswith its tests insrc/<plugin>/tests.rs) of a fewpublish = falsepackages namedcorpus-<directory>(shared, which the others build on;base; one per held-out series;library, programs with no Bevy), so their tests link nine binaries, not one per plugin. CI builds, lints and tests every one, so a kernel change that breaks one fails CI - Verification planner and source-tree checks:
xtask/ - Workspace example packages:
examples/*; per-crate examples:crates/<crate>/examples/ - Integration tests: one binary per package,
integration, with one module per suite (tests/integration/main.rs, ortests/integration.rsinrig-cassette); rig-core also keepswebsocket_off_runtime, which needs its own process - Record/replay home:
crates/rig-cassette— the engine (src/), the provider cassette corpus (fixtures/cassettes/<provider>/), the effect-log golden corpus (fixtures/effects/), every cassette-backed provider suite (tests/providers/<provider>/, with the shared drivers intests/common/), the cache-prefix guard, and the effect-bus verification suiteverify. Corpora andtests/are excluded from the published package. - Live-only provider test modules stay in the facade:
tests/providers/<provider>/, declared intests/integration/main.rs - External-service integration tests:
tests/integrations/ - Unpublished vector-store test runner:
test-support/service-tests
Check the root manifest and facade source before documenting or changing exposed features, integrations, or module paths. When adding or exposing a companion crate, update the root dependency, feature, facade re-export, examples, README, and crate docs as applicable.
Rig supports WebAssembly targets. Use Rig's WASM-compatible WasmSend/WasmSync
alias bounds instead of raw Send and Sync, and its WASM-compatible boxed
future alias for boxed futures. When an error type stores boxed errors, gate
the Send + Sync bound on target_family = "wasm" the way existing error
types do.
- Do not use
Stringas an error type for new fallible APIs; - Workspace clippy lints forbid
unwrap,expect,todo, andunimplemented. - Tests are linted too:
indexing_slicingandpanic_in_result_fnapply in test code, so index with.get(..), and do not assert in a test that returnsResult. - Prefer
?and meaningful error conversions.
- Keep examples current with actual APIs, model constants, module paths, and feature flags; mark examples
no_runwhen they require external credentials or services. - Do not document integrations, features, model constants, or crate paths without checking the code and manifests.
- Keep root README, crate READMEs, and crate-level Rust docs consistent when changing public-facing behavior.
- Never edit
CHANGELOG.md,crates/*/CHANGELOG.md,MIGRATING.md, ordocs/migrations/. CI rejects the PR. - Put changelog bullets and migration notes in the PR description under
## Changelogand## Migration, following the PR template. When the user asks to "update the changelog" or "add a migration note", that is what it means. The repository squash-merges, so those sections become the merge commit body. - These files are regenerated on the release PR by
scripts/release-notes.shand the editorial pass inscripts/release-notes-prompt.md. Only touch them when the user explicitly says the branch is a release PR.
Before implementing or modifying a provider, study the closest existing provider implementation and mirror it. Providers whose wire format is a dialect of an existing one (OpenAI-chat-compatible, Anthropic-compatible) MUST reuse the shared generic completion model for that dialect and express their differences through its extension hooks — never a hand-rolled completion model, request struct, or message conversion.
Vector stores should live in companion crates. Implement both the scored-document and the id-only search methods, use an appropriate backend-specific filter type, return the vector-store error enum's variants instead of ad hoc string errors, and use the WASM-compatible bounds.
- Module docs state the module's purpose in at most three paragraphs and include one short example when there is a public entry point. No headers, tables, history, or rhetorical phrasing.
- Item docs state the contract, inputs, outputs, errors, and caller invariants. Allow one sentence of non-obvious rationale. No issue numbers, bug narratives, or comparisons with other providers.
- Inline comments explain a non-obvious why in one or two sentences. Delete restated code, control-flow narration, and design discussions.
- Use short sentences and no em-dashes. Keep true
# Safetyand# Panicssections. Doc examples must compile with current APIs; useno_runfor credentials, network access, or services. - Move needed design rationale to the crate's CONTRACT.md or README, checking for and merging existing coverage rather than duplicating it.
- Follow local naming, module layout, and test patterns.
- Test modules are sibling files, never inline blocks: write
#[cfg(test)] mod tests;and put the body infoo/tests.rs(forfoo.rs) ortests.rsbesidemod.rs/lib.rs.cargo xtask check-test-layoutenforces this in CI. - Avoid unrelated refactors.
- Prefer the cleanest implementation.
- Break things if the result is better.
Provider regressions should usually include cassette-backed tests. Follow tests/README.md for replay/record commands and fixture safety review; never record or rewrite fixtures merely to make verification pass.
Follow DEVELOPING.md for check selection, independent review, and authorized publication. Run the smallest useful local check; docs-only edits get diff and link review, not Rust builds. Keep progress reports outside the repository and never claim merge readiness with required checks pending.
main merges through a merge queue, and gh pr merge is refused here with
or without --squash, --auto or --delete-branch. When the owner has
approved merging that PR and its required checks have passed, add it to the
queue:
gh api graphql \
-f query='mutation($id: ID!) { enqueuePullRequest(input: {pullRequestId: $id}) { mergeQueueEntry { position state } } }' \
-f id="$(gh pr view <number> --json id -q .id)"The queue runs its own checks and squash-merges some minutes later. Confirm
with gh pr view <number> --json state,mergedAt before reporting it merged.