//! `GET` and `PUT /api/agents/{name}/agents-md`: an agent's `AGENTS.md`, //! read from the copy its harness publishes and edited by a diff the harness //! applies. use serde::{Deserialize, Serialize}; /// Success body of `GET /api/agents/{name}/agents-md`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] pub struct AgentsMdView { /// The file's text as the agent last published it; `""` for an agent /// with no `AGENTS.md`. pub content: String, /// The git blob id of that text, what `git hash-object` prints for it. pub revision: String, } /// Body of `PUT /api/agents/{name}/agents-md`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] pub struct AgentsMdEdit { /// The [`AgentsMdView::revision`] the diff was made against. pub base_revision: String, /// A unified diff as `git diff` writes it, naming `a/AGENTS.md` and /// `b/AGENTS.md`. pub diff: String, } /// Success body of `PUT /api/agents/{name}/agents-md`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] pub struct AgentsMdSaved { /// The file's revision after the edit. pub revision: String, } #[cfg(test)] mod tests { use super::AgentsMdEdit; #[test] fn an_edit_round_trips() { let edit = AgentsMdEdit { base_revision: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391".to_owned(), diff: "--- a/AGENTS.md\n".to_owned(), }; let wire = r#"{"base_revision":"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391","diff":"--- a/AGENTS.md\n"}"#; assert_eq!(serde_json::to_string(&edit).unwrap(), wire); assert_eq!(serde_json::from_str::(wire).unwrap(), edit); } }