use crate::agent_content::{AgentContentError, ContentError, ResolvedContent, describe_source};
pub const HARNESS_DOC_DIRS: [&str; 2] = [
"instructions/harness_understanding",
"harness_understanding",
];
const SECTION_FILES: [&str; 4] = [
"HARNESS_AGNOSTIC.md",
"HARNESS_MPM_SM.md",
"HARNESS_TCODE.md",
"HARNESS_OVERSEER.md",
];
#[derive(Debug, Clone)]
pub struct HarnessDoc {
agnostic: String,
mpm_session_manager: String,
tcode: String,
overseer: String,
}
impl HarnessDoc {
pub fn load(content: &ResolvedContent) -> Result<Self, AgentContentError> {
let [agnostic, mpm_session_manager, tcode, overseer] =
SECTION_FILES.map(|file| read_section(content, file));
Ok(Self {
agnostic: agnostic?,
mpm_session_manager: mpm_session_manager?,
tcode: tcode?,
overseer: overseer?,
})
}
pub fn agnostic(&self) -> &str {
&self.agnostic
}
pub fn mpm_session_manager(&self) -> &str {
&self.mpm_session_manager
}
pub fn tcode(&self) -> &str {
&self.tcode
}
pub fn overseer(&self) -> &str {
&self.overseer
}
pub fn harness_understanding(&self) -> String {
[
self.agnostic(),
self.mpm_session_manager(),
self.tcode(),
self.overseer(),
]
.iter()
.map(|s| s.trim())
.collect::<Vec<_>>()
.join("\n\n")
}
}
fn read_section(content: &ResolvedContent, file: &str) -> Result<String, AgentContentError> {
for dir in HARNESS_DOC_DIRS {
match content.read_to_string(&format!("{dir}/{file}")) {
Ok(text) => return Ok(text),
Err(ContentError::NotFound { .. }) => continue,
Err(other) => return Err(other.into()),
}
}
Err(AgentContentError::Missing {
origin: describe_source(content.source()),
path: format!("{}/{file}", HARNESS_DOC_DIRS[0]),
})
}
#[cfg(test)]
#[path = "harness_doc_tests.rs"]
mod tests;