English · 中文
This is the entry document for contributing code to mega2: process, gates,
conventions, and how-tos for common tasks. The fact baseline is the current
checkout plus ../AGENTS.md; where the two conflict,
AGENTS.md and the source win — open an Issue to fix this document.
Do not start a large change cold. The order is:
- Open an Issue first. State the problem, motivation, scope, and explicit non-goals. Wait until maintainers (or the discussion) accept the direction.
- Then write a plan. Copy the structure from
plan/plan-template.md(in-repo operational original, Chinese) orplan/plan-template.en.md(English contributor edition) intodocs/plan/plan-YYYYMMDD.md. Do not delete mandatory sections; writeN/Aand the reason when a section does not apply. Plan rules (naming, fact baseline, task cards, index registration) live inplan/README.md. - Implement only after the plan is reviewed. Split the work into independently executable task cards (clear scope / dependencies / file targets / acceptance criteria / verification commands), add tests and docs, and pass the three gates in section 3 before merge.
A plan is not an implementation. At write time, the fact baseline is the current checkout's source, tests, config, and docs; historical plans and verbal Issue agreements are clues only and cannot replace the verification commands on a task card.
Environment setup, the compose data plane, the integration-test stack, and
troubleshooting all live in development.md; this document
does not duplicate them. Prefer the unified entry script
../scripts/dev-test.sh (up-full / basic /
full / gates, etc.) over hand-pasted commands; shared logic is in
../scripts/lib/mega2-it.sh. The test env
template is ../.env.test.example (dev-test.sh
auto-creates a local .env.test, which is never committed).
Every code change must pass all three gates before submit (same as
../AGENTS.md; equivalent wrapper: ./scripts/dev-test.sh gates):
cargo +nightly fmt --all --check
cargo clippy --all-targets --all-features -- -D warnings
source .env.test && cargo test --allRequirements: fmt reports no diff (nightly toolchain, because rustfmt.toml
may enable unstable options); clippy exits with 0 warnings and 0 errors, with
no blanket #[allow(...)] bypasses; all tests pass — never force green with
#[ignore] or deleted asserts. If .env.test is missing, generate it per
development.md first; do not skip the source.
The full conventions are in ../AGENTS.md, sections Code
Conventions and Common Pitfalls; only the most frequently tripped items are
listed here:
- Import grouping:
std→ external crates →crate::; nouse crate::*wildcards in library code (fine insidemod tests). - Error types: per module, use one of
MegaError/MegaResult,anyhow::Result, orthiserror, matching the module's existing style; never mix them within the same module. - Logging: use the
tracing::{info, warn, error, debug, trace}macros, notprintln!; prefer structured fields. - DB access: go through the
*Storagetypes insrc/jupiter/storage/; do not callsea_ormdirectly from API / handler code. - Dependencies: justify any new
Cargo.tomldependency (compile time / binary size / license); prefer reusing what is already vendored. - Allocator: do not touch the
#[global_allocator]blocks insrc/main.rsunless intentionally changing allocators on a platform. - Comments: sparse, English, matching the surrounding file's density.
- There is no top-level
mod vault: import Vault types fromlibvault::*andcrate::contract::vault::*(see the Pitfalls section of AGENTS.md).
Adding a CLI subcommand (step details in ../AGENTS.md,
"Adding a New Subcommand"):
- Implement the command module under
src/commands/<name>.rs. - Register the clap
Commandinbuiltin()insrc/commands/mod.rs, and wire the executor inbuiltin_exec()(signaturefn(config: Config, args: &ArgMatches) -> MegaResult). - Add unit tests next to the command, plus a CLI parsing test in
src/cli.rs::testsmirroring the existing ones.
Adding a DB entity / migration (step details in
../AGENTS.md, "Adding a New DB Entity / Migration"):
- Put the entity file at
src/callisto/<table>.rsand register it insrc/callisto/mod.rs. - Put the migrator under
src/jupiter/migration/and register it in that module's migrator list. - If a new domain storage is needed, add
<domain>_storage.rsundersrc/jupiter/storage/and re-export it fromstorage/mod.rs. - Cover it with
#[cfg(test)]tests usingcrate::jupiter::tests::test_db_connection+crate::jupiter::migration::apply_migrations(example:notification/dispatcher.rs::tests).
- Plan documents: mandatory template, naming, fact baseline, task-card
executability, and index/status sync rules are in
plan/README.md; do not invent your own format. - Fact baseline: documents only state what is verifiable in the current checkout; plan documents never claim an implementation is complete.
- Link, don't copy: content with an authoritative home — full config key
tables, token values, command flag lists
(
../config/config.toml,refactoring/config.md,deploy-trunk.md,monorepo.md,development.md,../AGENTS.md) — is always linked, never re-printed in a new document. - Bilingual docs: English is the default file (e.g.
foo.md); Chinese lives in the same-named.zh.mdsibling (e.g.foo.zh.md). Both versions keep identical structure as faithful translations, with a language-switcher line at the top (same convention as../README.md). This document is maintained under that convention. - Relative links in docs must resolve to files that exist in the current checkout; verify each one before submitting.
This repository uses Libra as its VCS (not git; there is no .git
directory): libra add / libra commit / libra push, etc. Interactive
browsing of the monorepo is done via Libra's libra mega2 browser.
Task-card release flow (details in ../AGENTS.md, "Task card
release"):
- Once a task card is complete (Lifecycle=done, dual review PASS), bump
Cargo.tomlversionby the card'sVersion increment(default patch +1) and refresh themega2entry inCargo.lock. libra add+libra commit -m— commit that card only.libra push origin main. Never--force; if the branch has diverged from origin, stop and report instead of resolving it yourself.- Start the next card only after the previous card's commit and push succeed.
- This documentation set:
quick-start.md·user-guide.md·configuration.md·deployment.md·architecture.md ../AGENTS.md— authoritative home for gates, code conventions, common pitfalls, and the task-card release flowdevelopment.md— local development and testingplan/README.md— plan document rules../README.md— project overview (its Contributing section is the English summary of this document)