Skip to main content

spec_driven_docs/domain/
gate_id.rs

1//! Gate identifiers: one variant per delivered gate.
2//!
3//! A gate ID names an executable check a consumer wires as a pre-commit hook
4//! and invokes as `sdd gate <id>`. This enum is only the identity; what a
5//! gate checks, how it is wired, and its display name live in the gate
6//! registry, and canon-only checks are cargo tests rather than variants here.
7
8use std::fmt;
9
10use clap::ValueEnum;
11
12/// A delivered gate, addressable as `sdd gate <id>` and as a pre-commit hook id.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
14#[value(rename_all = "kebab-case")]
15pub enum GateId {
16    /// Decision record citations resolve to a live rule.
17    AdrCitesALiveRule,
18    /// Decision record filenames are dated-free slugs.
19    AdrFilenameShape,
20    /// Decision record bodies stay within the word cap.
21    AdrWordCap,
22    /// Agent digests stay within their line budgets.
23    AgentsDigestSize,
24    /// Chapters and catalogs stay within their line caps.
25    ChapterSizeCap,
26    /// Comparison tables carry a verification date.
27    ComparisonDatedTables,
28    /// Comparison table pipes are escaped inside cells.
29    ComparisonEscapedPipes,
30    /// Comparison documents carry a legend.
31    ComparisonLegend,
32    /// Comparison cells carry at most one reference.
33    ComparisonOneReferencePerCell,
34    /// Comparison verdicts carry their word.
35    ComparisonVerdictWord,
36    /// Every rule ID a gate can print resolves to a local requirement.
37    GateMessageCitesARule,
38    /// The instance manifest is present and coherent.
39    InstanceManifest,
40    /// Bugzilla-bound report bodies fit the tracker's width.
41    KiBugzillaReportWidth,
42    /// Known-issue filenames are slugged case IDs.
43    KiFilenameShape,
44    /// Known-issue records carry one filing state.
45    KiFiling,
46    /// Known-issue records walk the mechanism.
47    KiMechanismWalkthrough,
48    /// Filed known-issue records carry their report body.
49    KiReportBody,
50    /// Known-issue records carry a retirement condition.
51    KiRetireWhen,
52    /// Known-issue records carry one state.
53    KiState,
54    /// Files carry no absolute path into a person's home directory.
55    NoPersonalPath,
56    /// Documents state the present rather than narrate their edits.
57    NoSelfNarration,
58    /// Paragraphs occupy one source line rather than hard-wrap.
59    ProseStaysUnwrapped,
60    /// Typed clauses in the plan zone carry a well-formed rule ID.
61    SpecChangeIsTyped,
62    /// Spec requirements carry all five parts.
63    SpecRequirementParts,
64    /// Rule IDs are unique across the local specs.
65    SpecRuleIdUnique,
66    /// Specs stay within their line cap and carry a TOC when long.
67    SpecSizeCap,
68    /// Spec verification lines name hooks that exist.
69    SpecVerifyHooksExist,
70    /// Suppression comments name a known-issue case.
71    SuppressionNamesItsCase,
72    /// Prose follows the objective `SimpleEnglish` checks.
73    SimpleEnglish,
74    /// The tracking registry is valid, current, and its dependents exist.
75    TrackingRegistry,
76}
77
78impl GateId {
79    /// Every delivered gate, in id order.
80    pub const ALL: &'static [Self] = &[
81        Self::AdrCitesALiveRule,
82        Self::AdrFilenameShape,
83        Self::AdrWordCap,
84        Self::AgentsDigestSize,
85        Self::ChapterSizeCap,
86        Self::ComparisonDatedTables,
87        Self::ComparisonEscapedPipes,
88        Self::ComparisonLegend,
89        Self::ComparisonOneReferencePerCell,
90        Self::ComparisonVerdictWord,
91        Self::GateMessageCitesARule,
92        Self::InstanceManifest,
93        Self::KiBugzillaReportWidth,
94        Self::KiFilenameShape,
95        Self::KiFiling,
96        Self::KiMechanismWalkthrough,
97        Self::KiReportBody,
98        Self::KiRetireWhen,
99        Self::KiState,
100        Self::NoPersonalPath,
101        Self::NoSelfNarration,
102        Self::ProseStaysUnwrapped,
103        Self::SpecChangeIsTyped,
104        Self::SpecRequirementParts,
105        Self::SpecRuleIdUnique,
106        Self::SpecSizeCap,
107        Self::SpecVerifyHooksExist,
108        Self::SuppressionNamesItsCase,
109        Self::SimpleEnglish,
110        Self::TrackingRegistry,
111    ];
112
113    /// The kebab-case id used on the command line and as the hook id.
114    #[must_use]
115    pub const fn as_str(self) -> &'static str {
116        match self {
117            Self::AdrCitesALiveRule => "adr-cites-a-live-rule",
118            Self::AdrFilenameShape => "adr-filename-shape",
119            Self::AdrWordCap => "adr-word-cap",
120            Self::AgentsDigestSize => "agents-digest-size",
121            Self::ChapterSizeCap => "chapter-size-cap",
122            Self::ComparisonDatedTables => "comparison-dated-tables",
123            Self::ComparisonEscapedPipes => "comparison-escaped-pipes",
124            Self::ComparisonLegend => "comparison-legend",
125            Self::ComparisonOneReferencePerCell => "comparison-one-reference-per-cell",
126            Self::ComparisonVerdictWord => "comparison-verdict-word",
127            Self::GateMessageCitesARule => "gate-message-cites-a-rule",
128            Self::InstanceManifest => "instance-manifest",
129            Self::KiBugzillaReportWidth => "ki-bugzilla-report-width",
130            Self::KiFilenameShape => "ki-filename-shape",
131            Self::KiFiling => "ki-filing",
132            Self::KiMechanismWalkthrough => "ki-mechanism-walkthrough",
133            Self::KiReportBody => "ki-report-body",
134            Self::KiRetireWhen => "ki-retire-when",
135            Self::KiState => "ki-state",
136            Self::NoPersonalPath => "no-personal-path",
137            Self::NoSelfNarration => "no-self-narration",
138            Self::ProseStaysUnwrapped => "prose-stays-unwrapped",
139            Self::SpecChangeIsTyped => "spec-change-is-typed",
140            Self::SpecRequirementParts => "spec-requirement-parts",
141            Self::SpecRuleIdUnique => "spec-rule-id-unique",
142            Self::SpecSizeCap => "spec-size-cap",
143            Self::SpecVerifyHooksExist => "spec-verify-hooks-exist",
144            Self::SuppressionNamesItsCase => "suppression-names-its-case",
145            Self::SimpleEnglish => "simple-english",
146            Self::TrackingRegistry => "tracking-registry",
147        }
148    }
149}
150
151impl std::str::FromStr for GateId {
152    type Err = String;
153
154    fn from_str(s: &str) -> Result<Self, Self::Err> {
155        Self::ALL
156            .iter()
157            .copied()
158            .find(|gate| gate.as_str() == s)
159            .ok_or_else(|| format!("unknown gate: {s}"))
160    }
161}
162
163impl fmt::Display for GateId {
164    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168
169#[cfg(test)]
170mod tests {
171    use super::*;
172
173    #[test]
174    fn all_lists_every_variant_once() {
175        let mut seen = std::collections::BTreeSet::new();
176        for gate in GateId::ALL {
177            assert!(seen.insert(gate.as_str()), "{gate} is duplicated");
178        }
179        assert_eq!(GateId::ALL.len(), 30);
180    }
181
182    #[test]
183    fn clap_value_matches_as_str() {
184        for gate in GateId::ALL {
185            let value = gate.to_possible_value().unwrap();
186            assert_eq!(value.get_name(), gate.as_str());
187        }
188    }
189}