use std::path::PathBuf;
use serde::Deserialize;
use crate::TuiError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RalphHomeAction {
#[serde(alias = "plan")]
Plan,
#[serde(alias = "save-draft")]
SaveDraft,
#[serde(alias = "view-draft")]
ViewDraft,
#[serde(alias = "revise-draft")]
ReviseDraft,
#[serde(alias = "rebuild-loop-context")]
RebuildLoopContext,
#[serde(alias = "approve-draft")]
ApproveDraft,
#[serde(alias = "create-from-draft")]
CreateFromDraft,
#[serde(alias = "apply-draft-to-loop")]
ApplyDraftToLoop,
#[serde(alias = "start")]
Start,
Run,
Approve,
Stop,
Resume,
Status,
Runs,
Iterations,
Open,
Audit,
Replan,
Goal,
}
pub(crate) async fn open_root_ralph_home_surface(
repo_path: PathBuf,
flash_message: Option<&str>,
) -> Result<bcode_plugin_sdk::tui::BoxedPluginTuiSurface, TuiError> {
open_ralph_home_surface(repo_path, flash_message).await
}
async fn open_ralph_home_surface(
repo_path: PathBuf,
flash_message: Option<&str>,
) -> Result<bcode_plugin_sdk::tui::BoxedPluginTuiSurface, TuiError> {
let runtime = load_ralph_tui_runtime()?;
let options = flash_message.map_or(
serde_json::Value::Null,
|message| serde_json::json!({ "flash_message": message }),
);
crate::plugin_tui::open_plugin_tui_surface(
&runtime,
"bcode.ralph",
"ralph-home",
bcode_plugin_sdk::tui::PluginTuiSurfaceOpenRequest {
instance_id: "ralph-home".to_string(),
repo_path: Some(repo_path),
session_id: None,
target: None,
options,
},
)
.await
.map_err(|error| TuiError::PluginService {
code: "tui_surface_open_failed".to_string(),
message: error.to_string(),
})
}
fn load_ralph_tui_runtime() -> Result<bcode_plugin::PluginRuntimeHost, TuiError> {
bcode_plugin::PluginRuntimeHost::load_defaults_with_static_bundled(
&bcode_plugin::PluginSelection::all_enabled(),
&crate::static_bundled_plugins(),
)
.map_err(|error| TuiError::PluginService {
code: "plugin_runtime_load_failed".to_string(),
message: error.to_string(),
})
}