convert hand-written enum as_str matches to strum derives workspace-wide
This commit is contained in:
parent
0d6c003fa8
commit
299add158f
14 changed files with 70 additions and 113 deletions
|
|
@ -13,6 +13,7 @@ hive-priv-sock.workspace = true
|
|||
hive-types.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
strum.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json.workspace = true
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ use serde::{Deserialize, Serialize};
|
|||
/// config) and expands it to the matching tool names for `--allowedTools`.
|
||||
/// When the env var is absent the harness falls back to `AGENT_DEFAULT`.
|
||||
/// See `docs/process/conventions.md::Tool groups`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, strum::IntoStaticStr)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum ToolGroup {
|
||||
/// `send`, `recv`, `ack_until`
|
||||
Messaging,
|
||||
|
|
@ -154,21 +155,12 @@ impl ToolGroup {
|
|||
];
|
||||
|
||||
/// The `snake_case` wire name for this group (matches `serde(rename_all =
|
||||
/// "snake_case")` serialisation).
|
||||
/// "snake_case")` serialisation) — derived (`#[strum(serialize_all =
|
||||
/// "snake_case")]`) from the same convention rather than a hand-written
|
||||
/// match kept in sync with it by hand.
|
||||
#[must_use]
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Messaging => "messaging",
|
||||
Self::Meta => "meta",
|
||||
Self::Inbox => "inbox",
|
||||
Self::Lifecycle => "lifecycle",
|
||||
Self::Approvals => "approvals",
|
||||
Self::Scheduling => "scheduling",
|
||||
Self::Diagnostics => "diagnostics",
|
||||
Self::Forge => "forge",
|
||||
Self::Execution => "execution",
|
||||
Self::WebTools => "web_tools",
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
|
||||
/// Short human-readable description suitable for a tooltip or help text.
|
||||
|
|
@ -213,8 +205,9 @@ impl ToolGroup {
|
|||
/// `snake_case`) via `meta::render_flake`. The harness reads this to
|
||||
/// conditionally register capability-gated MCP tools so claude only
|
||||
/// sees tools it can actually invoke. See `docs/process/conventions.md::Capabilities`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, strum::IntoStaticStr)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Capability {
|
||||
/// Agent can lifecycle-manage the root agent (kill/start/restart)
|
||||
/// on behalf of the hive when the root has crashed. Named capability
|
||||
|
|
@ -247,14 +240,12 @@ impl Capability {
|
|||
Self::QueryAgentState,
|
||||
];
|
||||
|
||||
/// Canonical `snake_case` name for this capability (matches serde).
|
||||
/// Canonical `snake_case` name for this capability (matches serde) —
|
||||
/// derived rather than a hand-written match, same as
|
||||
/// [`ToolGroup::as_str`].
|
||||
#[must_use]
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::ManageRootAgent => "manage_root_agent",
|
||||
Self::ReadHostJournal => "read_host_journal",
|
||||
Self::QueryAgentState => "query_agent_state",
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
|
||||
/// Short human-readable description suitable for a tooltip or help text.
|
||||
|
|
|
|||
Loading…
Reference in a new issue