use std::io::Write as _;
use std::path::{Path, PathBuf};
use crate::config::aion_home;
pub(crate) fn documents() -> [(&'static str, &'static str); 6] {
[
("AWL-REFERENCE.md", aion_awl::guide::reference_text()),
(
"AWL-AUTHORING.md",
include_str!("../../assistant-embed/grounding/AWL-AUTHORING.md"),
),
(
"WORKERS.md",
include_str!("../../assistant-embed/grounding/WORKERS.md"),
),
(
"COMMANDS.md",
include_str!("../../assistant-embed/grounding/COMMANDS.md"),
),
(
"ENVIRONMENT.md",
include_str!("../../assistant-embed/grounding/ENVIRONMENT.md"),
),
(
"AWL-BEST-PRACTICES.md",
include_str!("../../assistant-embed/grounding/AWL-BEST-PRACTICES.md"),
),
]
}
pub(crate) fn directory() -> Result<PathBuf, String> {
let home = aion_home().map_err(|error| error.to_string())?;
Ok(home.path.join("assistant").join("grounding"))
}
pub(crate) fn materialize(dir: &Path) -> Result<(), String> {
std::fs::create_dir_all(dir)
.map_err(|error| format!("cannot create {}: {error}", dir.display()))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt as _;
std::fs::set_permissions(dir, std::fs::Permissions::from_mode(0o700))
.map_err(|error| format!("cannot restrict {}: {error}", dir.display()))?;
}
for (name, content) in documents() {
let path = dir.join(name);
let mut file = std::fs::File::create(&path)
.map_err(|error| format!("cannot write {}: {error}", path.display()))?;
file.write_all(content.as_bytes())
.map_err(|error| format!("cannot write {}: {error}", path.display()))?;
}
Ok(())
}
pub(crate) fn preamble(dir: &Path) -> String {
format!(
"You are the assistant inside an Aion server's ops console. Aion is a durable workflow \
engine whose workflows are written in AWL; the complete, version-true reference for \
this server — the AWL language reference and the authoring, worker, command, \
environment and best-practice guides — is in {}, and reading the relevant file before \
answering an AWL or Aion question beats recalling. The `assistant_context` tool \
fetches what is on the operator's screen right now; `assistant_document_edit` edits \
the document they are editing in place, and `assistant_document_check` runs their \
editor's own AWL check over it.",
dir.display()
)
}