cargo-kimi
Cargo subcommand for kimi-dotfiles — structured contracts for Rust.
Installation
Commands
cargo kimi init
Initialize AI coding guidelines in the current project.
Templates:
minimal— Core rules only (AGENTS.md)rust-only— Core rules + Rust-specific lints (default)full— Core rules + Rust + CI + benchmarksmodular— Split rules into.kimi/parts/directory for large projects
cargo kimi check
Run mechanized checks and compute a 0–100 contract score.
Scoring breakdown:
- Hoare triples on
pub fn— 30 pts - No
unwrap/expect/panic— 20 pts - Newtype wrappers — 10 pts
PhantomDatausage — 10 pts- Typestate patterns — 10 pts
- Average function length ≤ 40 lines — 10 pts
- Proper
Resulthandling — 10 pts
Score exemptions: Add // kimi:score-ignore=unwrap,unsafe in the first 10 lines of a file to waive specific penalties (issues are still reported with [EXEMPT]). Useful for FFI boundaries and generated code.
cargo kimi fix
Auto-fix mechanical issues: insert Hoare triple stubs, replace unwrap() with ?,
and add // SAFETY: comments before unsafe blocks.
What it does:
- Adds
/// { precondition }//// { postcondition }doc comments abovepub fn - Replaces
.unwrap()→?where the return type allows it - Replaces
.expect("msg")→.map_err(|e| format!("msg: {e}"))? - Adds
// SAFETY: TODO: explain why this is safebeforeunsafeblocks
cargo kimi trend
Show score history as an ASCII bar chart.
Scores are appended to .kimi/score-history.jsonl after every cargo kimi check.
cargo kimi verify
Run formal verification with Kani (requires kani-verifier).
cargo kimi init-skill
Generate a SKILL.md with YAML frontmatter compatible with agentskills.io.
cargo kimi mcp
Start an MCP server over stdio for Claude Code, Codex, and other MCP clients.
Exposes the check_contracts tool natively — no shell execution required.
Strictness Levels
relaxed— Only critical violations failstandard— Critical + major (default)strict— All violations including minor and info
Options
| Flag | Description |
|---|---|
--template <NAME> |
Template to install (init only) |
--strictness <LEVEL> |
Strictness level |
--yes |
Skip confirmation prompts |
--dry-run |
Preview changes without applying (fix only) |
--days <N> |
Number of days for trend chart (trend only) |
Kimi Skills
Two skills are included for use inside Kimi Code CLI:
kimi-check—/kimi.check [--strictness strict]runs contract checks and reports scoreskimi-fix—/kimi.fix [--dry-run]applies mechanical fixes
Install them by copying skills/kimi-check/ and skills/kimi-fix/ to your ~/.claude/skills/ directory.
GitHub Action
Add contract checking to your CI with automatic PR comments:
# .github/workflows/kimi.yml
name: Kimi Contract Check
on:
pull_request:
paths:
- '**.rs'
- 'Cargo.toml'
jobs:
contracts:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: ekhodzitsky/cargo-kimi/.github/actions/cargo-kimi@main
with:
strictness: standard
fail-on-drop: 60
post-comment: true
Inputs:
| Input | Default | Description |
|---|---|---|
strictness |
standard |
Contract strictness level |
fail-on-drop |
0 |
Fail CI if score drops below threshold (0 = off) |
post-comment |
true |
Post PR comment with results |
Example Workflow
# Initialize a Rust project with strict rules
# Check current score
# Preview auto-fixes
# Apply mechanical fixes
# Re-check after fixes
# View score trend over time