pub mod router;
use rmcp::schemars;
use serde::Deserialize;
#[derive(Debug, Deserialize, schemars::JsonSchema)]
pub struct MasterWorkflowArgs {
pub goal: Option<String>,
}
#[derive(Debug, Deserialize, schemars::JsonSchema)]
pub struct PullRequestWorkflowArgs {
pub owner: Option<String>,
pub repo: Option<String>,
pub base_branch: Option<String>,
pub head_branch: Option<String>,
}
pub(crate) fn render_context_header(fields: &[(&str, Option<&str>)]) -> String {
if fields.is_empty() {
return String::new();
}
let mut out = String::from("## Context already provided\n");
let mut any_known = false;
for (name, value) in fields {
if let Some(v) = value {
out.push_str(&format!("- `{name}` = \"{v}\"\n"));
any_known = true;
}
}
if !any_known {
out.push_str("- (none — no arguments were supplied with this prompt request)\n");
}
let missing: Vec<_> = fields
.iter()
.filter(|(_, v)| v.is_none())
.map(|(n, _)| *n)
.collect();
if !missing.is_empty() {
out.push_str(&format!(
"\nStill unknown, ask the user before the step that needs it: {}\n",
missing.join(", ")
));
}
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_field_list_renders_nothing() {
assert_eq!(render_context_header(&[]), "");
}
#[test]
fn all_fields_supplied_lists_each_and_no_missing_section() {
let header =
render_context_header(&[("owner", Some("octocat")), ("repo", Some("hello-world"))]);
assert!(header.contains("`owner` = \"octocat\""));
assert!(header.contains("`repo` = \"hello-world\""));
assert!(!header.contains("Still unknown"));
}
#[test]
fn all_fields_missing_notes_none_supplied_and_lists_all_as_missing() {
let header = render_context_header(&[("owner", None), ("repo", None)]);
assert!(header.contains("(none — no arguments were supplied"));
assert!(
header
.contains("Still unknown, ask the user before the step that needs it: owner, repo")
);
}
#[test]
fn mixed_fields_report_supplied_and_missing_separately() {
let header = render_context_header(&[("owner", Some("octocat")), ("repo", None)]);
assert!(header.contains("`owner` = \"octocat\""));
assert!(!header.contains("`repo` ="));
assert!(header.contains("Still unknown, ask the user before the step that needs it: repo"));
}
}