Add GUI visual smoke and bounded actions
This commit is contained in:
parent
a2c44a52a3
commit
21a05368d3
14 changed files with 620 additions and 32 deletions
|
|
@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::process::Command;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct StatusRequest {
|
||||
thread_id: Option<String>,
|
||||
|
|
@ -14,6 +14,14 @@ struct StatusRequest {
|
|||
app_server: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct OperatorActionResult {
|
||||
action: String,
|
||||
artifact_path: String,
|
||||
summary: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ArtifactBundle {
|
||||
|
|
@ -48,14 +56,17 @@ fn load_operator_snapshot(request: Option<StatusRequest>) -> Result<OperatorSnap
|
|||
})
|
||||
}
|
||||
|
||||
impl Default for StatusRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
thread_id: None,
|
||||
cwd: None,
|
||||
codex_home: None,
|
||||
app_server: None,
|
||||
}
|
||||
#[tauri::command]
|
||||
fn run_operator_action(
|
||||
action: String,
|
||||
request: Option<StatusRequest>,
|
||||
) -> Result<OperatorActionResult, String> {
|
||||
let repo_root = repo_root()?;
|
||||
let request = request.unwrap_or_default();
|
||||
match action.as_str() {
|
||||
"statusSnapshot" => run_status_snapshot(&repo_root, request),
|
||||
"coordinatorPlan" => run_coordinator_plan(&repo_root, request),
|
||||
_ => Err(format!("unknown operator action: {action}")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +124,114 @@ fn load_status(repo_root: &Path, request: StatusRequest) -> Result<Value, String
|
|||
.map_err(|err| format!("failed to parse Epiphany status JSON: {err}"))
|
||||
}
|
||||
|
||||
fn run_status_snapshot(
|
||||
repo_root: &Path,
|
||||
request: StatusRequest,
|
||||
) -> Result<OperatorActionResult, String> {
|
||||
let python = find_python()?;
|
||||
let artifact_root = repo_root
|
||||
.join(".epiphany-gui")
|
||||
.join("status-snapshots")
|
||||
.join(unix_millis().to_string());
|
||||
fs::create_dir_all(&artifact_root)
|
||||
.map_err(|err| format!("failed to create status artifact dir: {err}"))?;
|
||||
let result_path = artifact_root.join("status.json");
|
||||
let transcript_path = artifact_root.join("transcript.jsonl");
|
||||
let stderr_path = artifact_root.join("server.stderr.log");
|
||||
let workspace = request
|
||||
.cwd
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_root.to_path_buf());
|
||||
let codex_home = request
|
||||
.codex_home
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_root.join(".epiphany-gui").join("codex-home"));
|
||||
|
||||
let mut command = Command::new(python);
|
||||
command
|
||||
.current_dir(repo_root)
|
||||
.arg(repo_root.join("tools").join("epiphany_mvp_status.py"))
|
||||
.arg("--json")
|
||||
.arg("--cwd")
|
||||
.arg(workspace)
|
||||
.arg("--codex-home")
|
||||
.arg(codex_home)
|
||||
.arg("--result")
|
||||
.arg(&result_path)
|
||||
.arg("--transcript")
|
||||
.arg(transcript_path)
|
||||
.arg("--stderr")
|
||||
.arg(stderr_path);
|
||||
if let Some(thread_id) = request.thread_id {
|
||||
command.arg("--thread-id").arg(thread_id);
|
||||
}
|
||||
if let Some(app_server) = request.app_server {
|
||||
command.arg("--app-server").arg(app_server);
|
||||
}
|
||||
run_command(command, "status snapshot")?;
|
||||
Ok(OperatorActionResult {
|
||||
action: "statusSnapshot".to_string(),
|
||||
artifact_path: artifact_root.display().to_string(),
|
||||
summary: "Status snapshot written.".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn run_coordinator_plan(
|
||||
repo_root: &Path,
|
||||
request: StatusRequest,
|
||||
) -> Result<OperatorActionResult, String> {
|
||||
let python = find_python()?;
|
||||
let artifact_dir = repo_root
|
||||
.join(".epiphany-dogfood")
|
||||
.join(format!("gui-coordinator-plan-{}", unix_millis()));
|
||||
let workspace = request
|
||||
.cwd
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_root.to_path_buf());
|
||||
let codex_home = request
|
||||
.codex_home
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_root.join(".epiphany-gui").join("codex-home"));
|
||||
|
||||
let mut command = Command::new(python);
|
||||
command
|
||||
.current_dir(repo_root)
|
||||
.arg(repo_root.join("tools").join("epiphany_mvp_coordinator.py"))
|
||||
.arg("--mode")
|
||||
.arg("plan")
|
||||
.arg("--max-steps")
|
||||
.arg("2")
|
||||
.arg("--cwd")
|
||||
.arg(workspace)
|
||||
.arg("--codex-home")
|
||||
.arg(codex_home)
|
||||
.arg("--artifact-dir")
|
||||
.arg(&artifact_dir);
|
||||
if let Some(thread_id) = request.thread_id {
|
||||
command.arg("--thread-id").arg(thread_id);
|
||||
}
|
||||
if let Some(app_server) = request.app_server {
|
||||
command.arg("--app-server").arg(app_server);
|
||||
}
|
||||
run_command(command, "coordinator plan")?;
|
||||
Ok(OperatorActionResult {
|
||||
action: "coordinatorPlan".to_string(),
|
||||
artifact_path: artifact_dir.display().to_string(),
|
||||
summary: "Coordinator plan artifact written.".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn run_command(mut command: Command, label: &str) -> Result<(), String> {
|
||||
let output = command
|
||||
.output()
|
||||
.map_err(|err| format!("failed to run {label}: {err}"))?;
|
||||
if output.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
Err(format!("{label} exited with {}: {}", output.status, stderr))
|
||||
}
|
||||
|
||||
fn list_artifacts(repo_root: &Path) -> Result<Vec<ArtifactBundle>, String> {
|
||||
let root = repo_root.join(".epiphany-dogfood");
|
||||
if !root.exists() {
|
||||
|
|
@ -201,7 +320,10 @@ fn system_time_millis(value: SystemTime) -> Option<u128> {
|
|||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![load_operator_snapshot])
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
load_operator_snapshot,
|
||||
run_operator_action
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running Epiphany operator");
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue