Skip to main content

perspt_sdk/prompt/
stage.rs

1//! Prompt stages (PSP-10 system 23's runtime types).
2
3use serde::{Deserialize, Serialize};
4
5/// The declared prompt stages. Platform stages compose the universal
6/// envelope; domain stages compose the domain program layered on top.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum PromptStage {
10    // Platform stages.
11    SessionBootstrap,
12    GraphPlan,
13    ToolDiscovery,
14    ConversationCompact,
15    ExternalReconcile,
16    // Domain stages.
17    RepositoryExplore,
18    BranchStrategy,
19    BranchPropose,
20    BranchCorrect,
21    BranchReview,
22    Adjudicate,
23    EvidenceSummarize,
24}
25
26impl PromptStage {
27    /// The directory name a stage's section files live under.
28    pub fn dir_name(&self) -> &'static str {
29        match self {
30            PromptStage::SessionBootstrap => "session_bootstrap",
31            PromptStage::GraphPlan => "graph_plan",
32            PromptStage::ToolDiscovery => "tool_discovery",
33            PromptStage::ConversationCompact => "conversation_compact",
34            PromptStage::ExternalReconcile => "external_reconcile",
35            PromptStage::RepositoryExplore => "repository_explore",
36            PromptStage::BranchStrategy => "branch_strategy",
37            PromptStage::BranchPropose => "branch_propose",
38            PromptStage::BranchCorrect => "branch_correct",
39            PromptStage::BranchReview => "branch_review",
40            PromptStage::Adjudicate => "adjudicate",
41            PromptStage::EvidenceSummarize => "evidence_summarize",
42        }
43    }
44
45    /// Parse a stage directory name.
46    pub fn from_dir_name(name: &str) -> Option<Self> {
47        [
48            PromptStage::SessionBootstrap,
49            PromptStage::GraphPlan,
50            PromptStage::ToolDiscovery,
51            PromptStage::ConversationCompact,
52            PromptStage::ExternalReconcile,
53            PromptStage::RepositoryExplore,
54            PromptStage::BranchStrategy,
55            PromptStage::BranchPropose,
56            PromptStage::BranchCorrect,
57            PromptStage::BranchReview,
58            PromptStage::Adjudicate,
59            PromptStage::EvidenceSummarize,
60        ]
61        .into_iter()
62        .find(|stage| stage.dir_name() == name)
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn dir_names_round_trip() {
72        for stage in [
73            PromptStage::SessionBootstrap,
74            PromptStage::GraphPlan,
75            PromptStage::BranchCorrect,
76            PromptStage::EvidenceSummarize,
77        ] {
78            assert_eq!(PromptStage::from_dir_name(stage.dir_name()), Some(stage));
79        }
80        assert_eq!(PromptStage::from_dir_name("nonsense"), None);
81    }
82}