convert hand-written enum as_str matches to strum derives workspace-wide

This commit is contained in:
damocles 2026-09-11 21:06:54 +02:00
commit 299add158f
14 changed files with 70 additions and 113 deletions

View file

@ -40,8 +40,11 @@ pub struct Approval {
/// What action the approval, when granted, will trigger.
/// Variant-specific payload encoding + flow lives in
/// `docs/agent-lifecycle/approvals.md::Approval kinds (wire shapes)`.
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(
Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, strum::IntoStaticStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ApprovalKind {
/// Create + start a new sub-agent container with the given name
/// (under the default `agent.nix` template).
@ -70,18 +73,12 @@ pub enum ApprovalKind {
impl ApprovalKind {
/// Wire/UI string — the same value serde's `snake_case` rename
/// produces. The single source of truth for every place that needs
/// the kind as a `&'static str` (sqlite storage, dashboard events),
/// so adding a variant can't silently miss a hand-rolled match.
/// produces, via the same derive (`#[strum(serialize_all =
/// "snake_case")]`) rather than a hand-rolled match a new variant
/// could silently miss.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
ApprovalKind::Spawn => "spawn",
ApprovalKind::InitConfig => "init_config",
ApprovalKind::UpdateMetaInputs => "update_meta_inputs",
ApprovalKind::SchedulePrompt => "schedule_prompt",
ApprovalKind::MergeConfigPr => "merge_config_pr",
}
self.into()
}
}