This document defines the standards and constraints that AI assistants must follow when developing the rc project.
Important: All content must be in English, except for conversations with AI assistants which may use Chinese:
- Code comments
- Commit messages
- PR titles and descriptions
- Documentation in code
- Error messages in code
- Log messages
- Variable and function names
Use first-principles thinking. Do not assume the user always has a fully formed understanding of what they want or how to achieve it. Start from the underlying need and problem, and proceed carefully. If the motivation or goal is unclear, stop and discuss it with the user. If the goal is clear but the proposed path is not the shortest or most effective, say so and recommend a better approach.
- For any code change task, always base work on the latest
origin/main. - Before implementing code changes, run
git fetch originand ensure your working branch is created from or rebased ontoorigin/main. - Exception: if the task explicitly asks to fix or update a specific PR branch, continue on that PR branch instead of rebasing to
origin/mainunless explicitly requested.
- Understand the task goals and acceptance criteria
- Identify related modules and existing tests
- Check if the target file is a protected file
- If it's a protected file, follow the Breaking Change process
- Read related existing code to understand patterns and conventions
- Write tests first (red)
- Implement minimum code to pass tests (green)
- Refactor and clean up code
- Ensure all tests pass
- Run
cargo fmt --all- Code formatting - Run
cargo clippy --workspace -- -D warnings- Static analysis, must have zero warnings - Run
cargo test --workspace- Unit tests, must all pass - Only create a git commit after all above checks pass
- Commit message format:
feat(phase-N): <description> - Example:
feat(phase-1): implement alias commands and core infrastructure
- Commit message format:
Exception (markdown-only non-code updates):
- If the change only updates Markdown files unrelated to executable code (for example
AGENTS.md,README.md, or other documentation.mdfiles), compile/lint/test validation may be skipped. - This exception does not apply when changes affect schemas, config behavior, generated outputs, or any Rust/source code.
Do not commit code when checks have not passed!
The following files require the Breaking Change process for modifications:
| File | Description |
|---|---|
docs/reference/rc/ |
CLI behavior contract |
schemas/output_v1.json |
JSON output schema |
crates/cli/src/exit_code.rs |
Exit code definitions |
crates/core/src/config.rs |
Config schema_version related |
Modifying protected files requires:
-
Update version number
- Config changes: bump
schema_version - Output changes: create new
output_v2.jsonschema
- Config changes: bump
-
Provide migration path
- Config migration: add
migrations/v{N}_to_v{N+1}.rs - Documentation update: update relevant command reference sections
- Config migration: add
-
PR marking
- Include
BREAKINGin PR title or description
- Include
-
Using
use aws_sdk_s3directly inclicrate- Must access S3 functionality through
coretrait abstractions - Violation: breaks dependency boundaries
- Must access S3 functionality through
-
Using
.unwrap()(except in test code)- Must use
?orexpect("reason") - Violation: may cause panic
- Must use
-
Using
unsafeoutside the private NVIDIA SDK bridge- Only the private bridge in
nixl/cuobject-client-sys/src/sdk.rs, enabled by the native executable’scuobjectfeature, may declare the C++ interface and the thread ownership of its opaque window. Keep handwritten Rust operations outside this exception. - Native host slices require an exclusive window. Once a token is exposed, retain it with its registration until confirmed completion or proof that DMA never started. Quarantine an uncertain exchange or failed token release for the life of the process.
- Keep the lint exception on the bridge. The native executable and the
rustfs-cuobject-clientlibrary must retainforbid(unsafe_code).
- Only the private bridge in
-
Printing credentials in logs/errors
- Includes: access_key, secret_key, Authorization headers
- Violation: security risk
-
Modifying protected files without following Breaking Change process
- Violation: breaks backward compatibility
-
Deleting or disabling tests to "fix" CI
- Must fix the root cause of test failures
- Violation: reduces code quality
-
Cross-layer refactoring without ADR
- Example: moving s3 logic to cli
- Requires recording decision in
docs/ADR/
-
Using
--no-verifyto bypass commit hooks- No exceptions
// Recommended: Use thiserror to define error types
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
#[error("Configuration error: {0}")]
Config(String),
#[error("Network error: {0}")]
Network(#[from] std::io::Error),
}
// Recommended: Use ? to propagate errors
fn do_something() -> Result<()> {
let config = load_config()?;
// ...
Ok(())
}
// Forbidden: bare unwrap
fn bad() {
let x = something().unwrap(); // ❌
}
// Allowed: expect with explanation (only when failure is impossible)
fn ok() {
let x = "123".parse::<i32>().expect("hardcoded valid number"); // ✓
}// Recommended: Use tokio
use tokio;
#[tokio::main]
async fn main() {
// ...
}
// Forbidden: Using block_on in async context
fn bad() {
tokio::runtime::Runtime::new().unwrap().block_on(async_fn()); // ❌
}use tracing::{debug, info, warn, error};
// Recommended: Use appropriate log levels
debug!("Detailed debug info");
info!("Normal operation info");
warn!("Warning message");
error!("Error message");
// Forbidden: Logging sensitive information
error!("Auth failed: key={}", secret_key); // ❌ Absolutely forbidden
error!("Auth failed: endpoint={}", endpoint); // ✓ Non-sensitive info is OK// Recommended: Comments explain WHY, not just WHAT
// Using path-style addressing because some S3-compatible services
// don't support virtual-hosted style
let client = S3Client::new_with_path_style();
// Forbidden: Obvious comments
// Increment counter
counter += 1; // ❌ This comment adds no valueNew commands must follow this template:
// crates/cli/src/commands/example.rs
use crate::exit_code::ExitCode;
use crate::output::Formatter;
use core::{ObjectStore, Result};
/// Command description (shown in --help)
#[derive(clap::Args, Debug)]
pub struct ExampleArgs {
/// Argument description
#[arg(short, long)]
pub flag: bool,
/// Path argument
pub path: String,
}
/// Execute the command
pub async fn execute(
args: ExampleArgs,
store: &dyn ObjectStore,
formatter: &Formatter,
) -> ExitCode {
match do_work(args, store).await {
Ok(result) => {
formatter.output(&result);
ExitCode::Success
}
Err(e) => {
formatter.error(&e.to_string());
ExitCode::from_error(&e)
}
}
}
async fn do_work(args: ExampleArgs, store: &dyn ObjectStore) -> Result<OutputType> {
// Implementation logic
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_example_success() {
// Test success scenario
// assert_eq!(result.exit_code, ExitCode::Success);
}
#[tokio::test]
async fn test_example_not_found() {
// Test NOT_FOUND scenario
// assert_eq!(result.exit_code, ExitCode::NotFound);
}
// Each command needs at least 2 exit code tests
}Before submitting a PR, confirm all of the following:
-
cargo fmt --all --checkpasses (required unless the change is markdown-only non-code) -
cargo clippy --workspace -- -D warningspasses (required unless the change is markdown-only non-code) -
cargo test --workspacepasses (required unless the change is markdown-only non-code) - No changes to CLI/JSON/config contracts (or followed Breaking Change process)
- New behaviors have unit tests
- Each new command has at least 2 exit code test scenarios
- Golden tests pass (output schema not broken)
- No sensitive information in logs
- Complex logic has appropriate comments (explaining WHY)
- PR title follows semantic/conventional commit format
- PR description clearly covers related issue(s), background, solution, and test status
- Commit message and PR description are in English
Do not skip checks and commit directly! Code that fails CI should not be merged.
┌─────────────────────────────────────────────────────────┐
│ cli │
│ (command handling, output formatting, progress bar) │
│ │
│ ✓ Can depend on: core │
│ ✗ Cannot depend on: s3, aws-sdk-* │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ core │
│ (config, alias, path parsing, ObjectStore trait) │
│ │
│ ✓ Can depend on: std, serde, tokio, etc. │
│ ✗ Cannot depend on: aws-sdk-* │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ s3 │
│ (aws-sdk-s3 wrapper, implements ObjectStore trait) │
│ │
│ ✓ Can depend on: core, aws-sdk-s3 │
└─────────────────────────────────────────────────────────┘
| Error | Wrong Approach | Correct Approach |
|---|---|---|
| Type mismatch | Delete the code | Understand types, convert correctly |
| Missing trait | Comment out the call | Implement or import required trait |
| Lifetime error | Add 'static |
Analyze ownership, use Clone or refactor |
| Situation | Wrong Approach | Correct Approach |
|---|---|---|
| Test hangs | #[ignore] |
Analyze cause, fix code or test |
| Assertion fails | Change the assertion | Check if it's code error or test error |
| Timeout | Delete the test | Optimize code or increase timeout limit |
- Create workspace structure
- Set up CI configuration
- Create documentation skeleton
- Implement exit codes and error types
- Implement config and Alias management
- Implement path parsing
- Implement ObjectStore trait
- Implement alias command
- Follow command implementation template
- Each command needs tests
- Update the command reference (if needed)
- Update Golden tests
Each completed phase should have a commit:
- Format:
feat(phase-N): <brief description> - Example:
feat(phase-0): initialize project structure and CI - Example:
feat(phase-1): implement core infrastructure and alias commands
Each PR must follow these rules:
- PR title must follow semantic/conventional commit format
- Recommended formats:
feat(scope): <description>,fix(scope): <description>,docs(scope): <description>,refactor(scope): <description> - If the change is breaking, include the breaking change marker as required above
PR descriptions must be clear and easy to review. At minimum, they should include:
- Related issue(s) being resolved
- Problem background and user impact
- Root cause summary
- Solution overview
- Test status and validation commands run