Expand description
Render a mined/remembered rule as a concrete code-spec instead of a free-prose blob (roadmap item ⑥).
The output is a single slot-based Markdown template with progressive
disclosure: a section is emitted only when its source data exists, and a
missing slot is silently dropped rather than rendered as “N/A” (an empty
placeholder reads as fabricated emptiness). Every rendered slot traces to a
field we already store or a stored rule_example — nothing here invents a
contract, a validation condition, a trigger, or a metric. The mapping is
pure, deterministic string reshaping with no LLM call and no new persisted
data.
This module is intentionally public and DB-free so item ① (rule packs)
can import the same render_* helpers and serialize a published pack in the
exact format a locally-recalled rule renders in — see the roadmap’s
“missing-field decision table” which both surfaces honor.
The MCP get_rules detail path drives this via
[crate::mcp_server::tools::util::render_full_rule_with_examples], which
builds a RuleRenderInput from its private SkillDetailRow and calls
render_code_spec. The PostToolUse hook keeps its own compact render
(serve_render::render_rule_block) by design — it renders from the indexed
body string, not a row, and enforces a tight per-injection token budget.
Structs§
- Rule
Render Input - Borrowed, DB-free view of the fields a renderer needs. Built from the MCP
layer’s private
SkillDetailRow(which can’t leak out ofmcp_server) and — for item ① — from a pack row, so both surfaces render identically.
Enums§
- Polarity
- Whether a directive states a positive obligation (
MUST) or a prohibition (AVOID). Cheap keyword classify; defaults toMustwhen ambiguous.
Functions§
- directive_
polarity - Classify a directive statement as a positive obligation or a prohibition by
scanning for negative-polarity keywords. Pure and unit-testable; ambiguous
statements default to
Polarity::Must. - render_
cases_ block ### Casesblock, orNonewhen there are no examples. Framed as a conformance test (❌ Counter-example/✅ Conforming) rather than decoration so the agent reads the pair as the acceptance criterion.- render_
code_ spec - Render a full rule as the §3 code-spec template. Pure and DB-free: the
caller supplies a
RuleRenderInput; every section is derived deterministically from those fields with progressive disclosure. - render_
contract_ block ### Contractblock. Always present (the verbatim-description fallback guarantees body text is never dropped). For mined rules theRule:statement becomes a singleMUST:/AVOID:obligation; for verb-led conversation rules the first sentence becomes the obligation and the rest becomes aRationale:sub-line (the WHY is the value, so it is kept).- render_
provenance_ block ### Provenanceblock. Reuses the candidate source-proof parser to pull the PRSource:, theComment:URL and a short reviewer excerpt out of a mined description. ReturnsNoneonly when there is neither parseable source proof nor asource_repo— the header’s← learned fromsegment already carries the top-level attribution, so a conversation rule with no proof omits this section rather than repeating the header.- render_
validation_ matrix ### Validation / Error matrixblock, orNonewhen no row is derivable.