Skip to main content

ralph_workflow/prompts/
prompt_config.rs

1//! Prompt configuration types.
2//!
3//! Groups related parameters for prompt generation to reduce function argument count.
4
5use crate::checkpoint::restore::ResumeContext;
6
7/// Configuration for prompt generation.
8///
9/// Groups related parameters to reduce function argument count.
10#[derive(Debug, Clone, Default, PartialEq, Eq)]
11#[must_use]
12pub struct PromptConfig {
13    /// The current iteration number (for developer iteration prompts).
14    pub iteration: Option<u32>,
15    /// The total number of iterations (for developer iteration prompts).
16    pub total_iterations: Option<u32>,
17    /// PROMPT.md content for planning prompts.
18    pub prompt_md_content: Option<String>,
19    /// (PROMPT.md, PLAN.md) content tuple for developer iteration prompts.
20    pub prompt_and_plan: Option<(String, String)>,
21    /// (PROMPT.md, PLAN.md, ISSUES.md) content tuple for fix prompts.
22    pub prompt_plan_and_issues: Option<(String, String, String)>,
23    /// Whether this is a resumed session (from a checkpoint).
24    pub is_resume: bool,
25    /// Rich resume context if available.
26    pub resume_context: Option<ResumeContext>,
27}
28
29impl PromptConfig {
30    /// Create a new prompt configuration with default values.
31    #[must_use = "configuration is required for prompt generation"]
32    pub const fn new() -> Self {
33        Self {
34            iteration: None,
35            total_iterations: None,
36            prompt_md_content: None,
37            prompt_and_plan: None,
38            prompt_plan_and_issues: None,
39            is_resume: false,
40            resume_context: None,
41        }
42    }
43
44    /// Set iteration numbers for developer iteration prompts.
45    #[must_use = "returns the updated configuration for chaining"]
46    pub const fn with_iterations(mut self, iteration: u32, total: u32) -> Self {
47        self.iteration = Some(iteration);
48        self.total_iterations = Some(total);
49        self
50    }
51
52    /// Set PROMPT.md content for planning prompts.
53    #[must_use = "returns the updated configuration for chaining"]
54    pub fn with_prompt_md(mut self, content: String) -> Self {
55        self.prompt_md_content = Some(content);
56        self
57    }
58
59    /// Set (PROMPT.md, PLAN.md) content tuple for developer iteration prompts.
60    #[must_use = "returns the updated configuration for chaining"]
61    pub fn with_prompt_and_plan(mut self, prompt: String, plan: String) -> Self {
62        self.prompt_and_plan = Some((prompt, plan));
63        self
64    }
65
66    /// Set (PROMPT.md, PLAN.md, ISSUES.md) content tuple for fix prompts.
67    pub fn with_prompt_plan_and_issues(
68        mut self,
69        prompt: String,
70        plan: String,
71        issues: String,
72    ) -> Self {
73        self.prompt_plan_and_issues = Some((prompt, plan, issues));
74        self
75    }
76
77    /// Set whether this is a resumed session.
78    #[must_use = "returns the updated configuration for chaining"]
79    pub const fn with_resume(mut self, is_resume: bool) -> Self {
80        self.is_resume = is_resume;
81        self
82    }
83
84    /// Set rich resume context for resumed sessions.
85    #[must_use = "returns the updated configuration for chaining"]
86    pub fn with_resume_context(mut self, context: ResumeContext) -> Self {
87        self.resume_context = Some(context);
88        self.is_resume = true;
89        self
90    }
91}