English · 中文
This guide explains how to contribute code to mega2: how to propose a change,
prepare the development environment, run the required checks, and follow the
repository's conventions. The current checkout and ../AGENTS.md
are the sources of truth. If this guide conflicts with either, follow the
source and open an issue to correct the documentation.
For a large change, agree on the scope and approach with the maintainers before implementation:
- 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. Start from the English contributor template
plan/plan-template.en.mdand save the working plan asdocs/plan/plan-YYYYMMDD.md. Do not delete mandatory sections; writeN/Aand the reason when a section does not apply. The canonical template isplan/plan-template.md(Chinese), and plan rules (naming, fact baseline, task cards, index registration) are inplan/README.md(Chinese). - 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. When drafting a plan, verify its assumptions against the current source, tests, config, and docs. Historical plans and agreements in issue discussions are useful context, but they do not replace the verification commands on a task card.
Environment setup, the Compose data plane, the integration-test stack, and
troubleshooting are documented in development.md
(Chinese); this guide does not repeat them. Use the unified entry script ../scripts/dev-test.sh
to prepare the Compose data plane and run tests (up-full / basic / full /
gates, etc.). Its shared logic is in
../scripts/lib/mega2-it.sh. The test
environment template is ../.env.test.example;
dev-test.sh creates a local .env.test when needed, and that file must not
be committed. Use ./scripts/dev-test.sh --help for available workflows.
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, run
./scripts/dev-test.sh up-full to generate and populate the local test
environment (details in development.md (Chinese)); 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). The helper's per-test schema is dropped with the connection, or when the test thread ends if something still holds it;test_db_configreturns aTestSchemaGuardinstead, which must stay bound for the whole test (let (db_config, _schema) = ..., never_).
- Plan documents: use the English contributor template
plan/plan-template.en.md; do not invent your own format. Rules for templates, naming, fact baseline, task-card executability, and index/status sync are inplan/README.md(Chinese); the plan archive remains Chinese-first. - 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,deployment.md,deploy-trunk.md(Chinese),user-guide.md,development.md(Chinese),../scripts/dev-test.sh,../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). Keep both versions in sync and give them the same structure, while writing the English version naturally rather than translating sentence by sentence. Add a language-switcher line at the top, following../README.md. - Relative links in docs must resolve to files that exist in the current checkout; verify each one before submitting.
Mega was the first-generation monorepo platform; Mega2 is the second-generation engine built for Agent workflows, with Monorepo hosting and Agent Session Capture as its core capabilities. Mega2 ports and refactors selected parts of the first-generation Mega project; it is not a mirror. Before adopting an upstream change, check that it applies to a module and behavior present in this checkout. Compare the actual source and tests rather than copying a list of changed files, and classify changes that depend on upstream-only services or repository structure as out of scope.
For dependency updates, compare the resolved versions in Cargo.lock, inspect
the release's behavioral changes, and test any affected wire or object-identity
contracts. In particular, changes to Git object serialization can change
object IDs even when public APIs stay the same. Record the upstream revision,
the compatibility decision, and any required regression coverage in the plan
or change notes. Dependencies owned by a separate repository should be
evaluated there rather than upgraded through mega2's manifest.
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.
README.md— index of user, operator, and developer guides- 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(Chinese) — local development and testing; entry script:../scripts/dev-test.shplan/README.md(Chinese) — plan document rules; templates:plan/plan-template.md(Chinese) andplan/plan-template.en.md../README.md— project overview (its Contributing section is a summary of this document)