use crate::start::{self, StartInputs};
use crate::ui_state::UiState;
use litany::mint::SplitMix64;
use super::super::{answer, ceiling, control};
use super::Deps;
const BLANK_GOAL: &str = "the goal is blank: say what the conversation is for";
pub fn prepare(
deps: &Deps,
ts: &str,
workspace: &std::path::Path,
repo: &std::path::Path,
payload: &crate::start::Payload,
) -> Result<crate::start::Prepared, String> {
let inputs = StartInputs {
conversation_names: answer::names_in(&deps.snapshot, workspace),
workspace: workspace.to_path_buf(),
repo: payload.project().map(|_| repo.to_path_buf()),
payload: payload.clone(),
home: deps.home.clone(),
yog_data_root: deps.yog_data_root.clone(),
balls_state_root: deps.balls_state_root.clone(),
};
let start_deps = start::Deps {
bl: deps.bl.clone(),
litany: deps.litany.clone(),
state_root: deps.state_root.clone(),
yog_binary: deps.yog_binary.clone(),
};
start::prepare(&start_deps, &inputs, ts).map_err(|e| e.to_string())
}
pub fn prompt(
deps: &Deps,
ui: &UiState,
ts: &str,
workspace: &std::path::Path,
prepared: &crate::start::Prepared,
goal: &str,
seed: Option<u64>,
) -> Result<String, String> {
if goal.trim().is_empty() {
return Err(BLANK_GOAL.to_owned());
}
control::confinement_gate(workspace)?;
let world: Vec<std::path::PathBuf> =
crate::binding::workspaces(&deps.yog_data_root, &deps.world.litany_data_root())
.into_iter()
.map(|w| w.path)
.collect();
ceiling::gate(ui, &deps.state_root, ts, workspace, &world, prepared.origin)?;
let own_space = prepared.origin != crate::opslog::Origin::Balls;
let litany = deps
.litany
.and_env(crate::world::wall::pairs(&deps.world, workspace))
.and_env(crate::world::marks::pairs(
&deps.world,
workspace,
own_space,
))
.and_wrapper(crate::control::confine::wrapper(&deps.world, workspace));
start::execute_prompt(
&litany,
&deps.state_root,
ts,
&start::Fire {
workspace: workspace.to_path_buf(),
prepared: prepared.clone(),
goal: goal.to_owned(),
},
&answer::names_in(&deps.snapshot, workspace),
&SplitMix64::from_seed(
seed.unwrap_or_else(|| crate::ui_state::content_hash(ts.as_bytes())),
),
)
.map_err(|e| e.to_string())
}