Skip to main content

blyte_cli/
orchestrator_text.rs

1use std::path::Path;
2
3use blyte_agent::orchestrator::{assemble, resolve_sources, start_lines, user_rules_path, Answers};
4use blyte_agent::state::State;
5
6pub const REFERENCE: &str = include_str!("../assets/orchestrator/reference.md");
7pub const REFERENCE_DISPATCH_TOOL: &str =
8    include_str!("../assets/orchestrator/reference-dispatch-tool.md");
9pub const DEFAULT_PROCESS: &str = include_str!("../assets/orchestrator/process.md");
10
11pub struct Built {
12    pub instructions: String,
13    pub start_lines: [String; 2],
14}
15
16pub fn build(dispatch_tool: bool, answers: Answers, root: &Path) -> Result<Built, String> {
17    let (reference, default_process) = if dispatch_tool {
18        (REFERENCE_DISPATCH_TOOL, None)
19    } else {
20        (REFERENCE, Some(DEFAULT_PROCESS))
21    };
22    let user_path = user_rules_path();
23    let sources = resolve_sources(user_path.as_deref(), root, default_process)?;
24    let instructions = assemble(reference, answers, &sources);
25    let start_lines = start_lines(&sources);
26    Ok(Built {
27        instructions,
28        start_lines,
29    })
30}
31
32pub fn set_state_instructions(
33    state: &mut State,
34    dispatch_tool: bool,
35    root: &Path,
36) -> Result<[String; 2], String> {
37    let answers = if state.runtime.conversation.is_some() {
38        Answers::Person
39    } else {
40        Answers::Nobody
41    };
42    let built = build(dispatch_tool, answers, root)?;
43    state.orchestrator.instructions = Some(built.instructions);
44    Ok(built.start_lines)
45}