天衡 / tianheng
懸衡以待,失衡即應。 — Hold the balance ready; react the moment it tips.
The shell of the Tianheng crate family: reactive architectural governance that weighs the shape you declared against the shape the code is, and reacts the moment they no longer balance. Govern by reaction, not instruction.
天衡 (the celestial balance) is the imperative shell + facade — CLI (arg parsing, filesystem,
stdout/stderr) and the run reaction that composes every dimension into one. You declare a
single Constitution carrying all 三儀 (the three instruments) and call run:
use *;
// One declared constitution carries every dimension — the single source of truth.
your-binary check --manifest-path path/to/Cargo.toml reacts against your constitution:
exit 0 (clean / warn-only / fully baselined), 1 (enforced violation), 2
(constitution/scan error). list projects the declared constitution and never reacts.
check --format json projects the reaction as JSON (the machine contract); --format sarif
emits a vendor-neutral SARIF 2.1.0 document for CI code-scanning. The violation's reason is the
repair direction; the human text report and the Markdown projection lead with it.
The instruments (三儀)
tianheng composes the three observation dimensions, each its own crate, each real drift
(declared vs. observed) — never a style lint:
| 儀 | Crate | Observes |
|---|---|---|
| 圭表 (static) | guibiao |
imports, dependencies & their declared source kind (cargo metadata + use scan) |
| 渾儀 (semantic) | hunyi |
type exposure (incl. public re-exports and the opt-in trait-impl surface), impl locality, visibility, forbidden markers, dyn & impl Trait (existential) exposure (shape-only & named-operand), async fn (implicit existential) exposure (AST/syn) |
| 漏刻 (runtime) | louke |
the concrete type behind a dyn Trait crossing a seam (runtime TypeId) |
Beneath them sits xuanji — the dimension-agnostic
reaction model. The 漏刻 prod face is wired in your own binary
(louke::install(constitution().runtime_boundaries()…)); its CI probe-coverage face is run
by tianheng check.
The published
tianhengbinary is a demo bound to a sample constitution (it governs a crate namedexample-core). Tianheng is consumed as a library: declare your own constitution and expose your own binary, as above.
Tianheng governs itself with its own reaction (crates/tianheng/tests/self_governance.rs):
the core must not depend on the shell, syn is quarantined to hunyi, xuanji stays beneath
every dimension.
License
Licensed under either of Apache-2.0 or MIT, at your option.