ironflow_core/provider/system_prompt.rs
1//! Appending to the system prompt instead of replacing it.
2
3use super::AgentConfig;
4
5impl<Tools, Schema> AgentConfig<Tools, Schema> {
6 /// Append `prompt` to the system prompt instead of replacing it.
7 ///
8 /// Use it to give Claude Code project rules while keeping its default
9 /// system prompt (skills, slash commands, tools), which
10 /// [`system_prompt`](Self::system_prompt) would replace. The Claude CLI
11 /// receives it as `--append-system-prompt`; HTTP providers send
12 /// [`full_system_prompt`](Self::full_system_prompt).
13 ///
14 /// # Examples
15 ///
16 /// ```
17 /// use ironflow_core::provider::AgentConfig;
18 ///
19 /// let config = AgentConfig::new("/code-review medium main...HEAD")
20 /// .append_system_prompt("Never hardcode a tenant id.");
21 /// assert_eq!(
22 /// config.append_system_prompt.as_deref(),
23 /// Some("Never hardcode a tenant id."),
24 /// );
25 /// ```
26 pub fn append_system_prompt(mut self, prompt: &str) -> Self {
27 self.append_system_prompt = Some(prompt.to_string());
28 self
29 }
30
31 /// The system prompt a provider without an append flag sends:
32 /// [`system_prompt`](Self::system_prompt) then
33 /// [`append_system_prompt`](Self::append_system_prompt), separated by a
34 /// blank line. `None` when neither is set.
35 ///
36 /// # Examples
37 ///
38 /// ```
39 /// use ironflow_core::provider::AgentConfig;
40 ///
41 /// let config = AgentConfig::new("hi")
42 /// .system_prompt("Be brief")
43 /// .append_system_prompt("Rules");
44 /// assert_eq!(config.full_system_prompt().as_deref(), Some("Be brief\n\nRules"));
45 /// ```
46 pub fn full_system_prompt(&self) -> Option<String> {
47 match (&self.system_prompt, &self.append_system_prompt) {
48 (Some(base), Some(extra)) => Some(format!("{base}\n\n{extra}")),
49 (Some(only), None) | (None, Some(only)) => Some(only.clone()),
50 (None, None) => None,
51 }
52 }
53}