You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,11 @@ In the codex-rs folder where the rust code lives:
11
11
- Always collapse if statements per https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
12
12
- Always inline format! args when possible per https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
13
13
- Use method references over closures when possible per https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
14
+
- Avoid bool or ambiguous `Option` parameters that force callers to write hard-to-read code such as `foo(false)` or `bar(None)`. Prefer enums, named methods, newtypes, or other idiomatic Rust API shapes when they keep the callsite self-documenting.
15
+
- When you cannot make that API change and still need a small positional-literal callsite in Rust, follow the `argument_comment_lint` convention:
16
+
- Use an exact `/*param_name*/` comment before opaque literal arguments such as `None`, booleans, and numeric literals when passing them by position.
17
+
- Do not add these comments for string or char literals unless the comment adds real clarity; those literals are intentionally exempt from the lint.
18
+
- If you add one of these comments, the parameter name must exactly match the callee signature.
14
19
- When possible, make `match` statements exhaustive and avoid wildcard arms.
15
20
- When writing tests, prefer comparing the equality of entire objects over fields one by one.
16
21
- When making a change that adds or changes an API, ensure that the documentation in the `docs/` folder is up to date if applicable.
@@ -19,7 +24,23 @@ In the codex-rs folder where the rust code lives:
19
24
repo root to refresh `MODULE.bazel.lock`, and include that lockfile update in the same change.
20
25
- After dependency changes, run `just bazel-lock-check` from the repo root so lockfile drift is caught
21
26
locally before CI.
27
+
- Bazel does not automatically make source-tree files available to compile-time Rust file access. If
28
+
you add `include_str!`, `include_bytes!`, `sqlx::migrate!`, or similar build-time file or
29
+
directory reads, update the crate's `BUILD.bazel` (`compile_data`, `build_script_data`, or test
30
+
data) or Bazel may fail even when Cargo passes.
22
31
- Do not create small helper methods that are referenced only once.
32
+
- Avoid large modules:
33
+
- Prefer adding new modules instead of growing existing ones.
34
+
- Target Rust modules under 500 LoC, excluding tests.
35
+
- If a file exceeds roughly 800 LoC, add new functionality in a new module instead of extending
36
+
the existing file unless there is a strong documented reason not to.
37
+
- This rule applies especially to high-touch files that already attract unrelated changes, such
38
+
as `codex-rs/tui/src/app.rs`, `codex-rs/tui/src/bottom_pane/chat_composer.rs`,
`codex-rs/tui/src/bottom_pane/mod.rs`, and similarly central orchestration modules.
41
+
- When extracting code from a large module, move the related tests and module/type docs toward
42
+
the new implementation so the invariants stay close to the code that owns them.
43
+
- When running Rust commands (e.g. `just fix` or `cargo test`) be patient with the command and never try to kill them using the PID. Rust lock can make the execution slow, this is expected.
23
44
24
45
Run `just fmt` (in `codex-rs` directory) automatically after you have finished making Rust code changes; do not ask for approval to run it. Additionally, run the tests:
25
46
@@ -30,6 +51,19 @@ Before finalizing a large change to `codex-rs`, run `just fix -p <project>` (in
30
51
31
52
Also run `just argument-comment-lint` to ensure the codebase is clean of comment lint errors.
32
53
54
+
## The `codex-core` crate
55
+
56
+
Over time, the `codex-core` crate (defined in `codex-rs/core/`) has become bloated because it is the largest crate, so it is often easier to add something new to `codex-core` rather than refactor out the library code you need so your new code neither takes a dependency on, nor contributes to the size of, `codex-core`.
57
+
58
+
To that end: **resist adding code to codex-core**!
59
+
60
+
Particularly when introducing a new concept/feature/API, before adding to `codex-core`, consider whether:
61
+
62
+
- There is an existing crate other than `codex-core` that is an appropriate place for your new code to live.
63
+
- It is time to introduce a new crate to the Cargo workspace for your new functionality. Refactor existing code as necessary to make this happen.
64
+
65
+
Likewise, when reviewing code, do not hesitate to push back on PRs that would unnecessarily add code to `codex-core`.
0 commit comments