Skip to main content

blyte_cli/
instructions_cmd.rs

1//! Implementation of the `blyte instructions` command.
2
3use std::path::{Path, PathBuf};
4use std::process::Command;
5
6use blyte_agent::orchestrator::Answers;
7use blyte_agent::run::ORCHESTRATOR_FIXED;
8
9use crate::orchestrator_text;
10
11pub fn repo_root() -> Result<PathBuf, String> {
12    let out = Command::new("git")
13        .args(["rev-parse", "--show-toplevel"])
14        .output()
15        .map_err(|_| "not inside a git repository".to_string())?;
16    if !out.status.success() {
17        return Err("not inside a git repository".to_string());
18    }
19    let text = String::from_utf8_lossy(&out.stdout);
20    let trimmed = text.trim();
21    if trimmed.is_empty() {
22        return Err("not inside a git repository".to_string());
23    }
24    Ok(PathBuf::from(trimmed))
25}
26
27pub fn render(dispatch_tool: bool, answers: Answers, root: &Path) -> Result<String, String> {
28    let built = orchestrator_text::build(dispatch_tool, answers, root)?;
29    let mut out = String::new();
30    for line in &built.start_lines {
31        out.push_str(line);
32        out.push('\n');
33    }
34    out.push('\n');
35    out.push_str(&built.instructions);
36    if !built.instructions.ends_with("\n\n") {
37        if !built.instructions.ends_with('\n') {
38            out.push('\n');
39        }
40        out.push('\n');
41    }
42    out.push_str("## Always sent\n");
43    out.push_str(ORCHESTRATOR_FIXED);
44    if !ORCHESTRATOR_FIXED.ends_with('\n') {
45        out.push('\n');
46    }
47    out.push('\n');
48    out.push_str("## Tool descriptions\n");
49    for tool in blyte_agent::tools::specs() {
50        out.push_str(&format!("### {}\n{}\n\n", tool.name, tool.description));
51    }
52    out.push_str("The request and a description of the environment are added when a run starts.\n");
53    Ok(out)
54}