use xchecker::{Config, OrchestratorHandle, PhaseId};
fn demo_environment_based_config() {
println!("=== Demo 1: Environment-Based Config Discovery ===\n");
let spec_id = "embed-demo-env";
match OrchestratorHandle::new(spec_id) {
Ok(handle) => {
println!(
"✓ Created OrchestratorHandle for spec: {}",
handle.spec_id()
);
match handle.legal_next_phases() {
Ok(phases) => {
println!(" Legal next phases: {:?}", phases);
}
Err(e) => {
println!(" Could not determine legal phases: {}", e);
}
}
match handle.status() {
Ok(status) => {
println!(" Current artifacts: {}", status.artifacts.len());
println!(" Schema version: {}", status.schema_version);
}
Err(e) => {
println!(" Could not get status: {}", e);
}
}
}
Err(e) => {
println!("✗ Failed to create handle: {}", e.display_for_user());
println!(" Exit code would be: {:?}", e.to_exit_code());
}
}
println!();
}
fn demo_explicit_config() {
println!("=== Demo 2: Explicit Configuration ===\n");
let spec_id = "embed-demo-explicit";
let config_result = Config::builder()
.model("haiku") .packet_max_bytes(65536) .packet_max_lines(1200) .phase_timeout(std::time::Duration::from_secs(300)) .verbose(false) .llm_provider("claude-cli") .execution_strategy("controlled") .build();
match config_result {
Ok(config) => {
println!("✓ Built explicit configuration");
match OrchestratorHandle::from_config(spec_id, config) {
Ok(handle) => {
println!(
"✓ Created OrchestratorHandle for spec: {}",
handle.spec_id()
);
match handle.status() {
Ok(status) => {
println!(" Artifacts: {}", status.artifacts.len());
}
Err(e) => {
println!(" Could not get status: {}", e);
}
}
}
Err(e) => {
println!("✗ Failed to create handle: {}", e.display_for_user());
}
}
}
Err(e) => {
println!("✗ Failed to build config: {}", e.display_for_user());
}
}
println!();
}
#[tokio::main]
async fn main() {
println!("╔════════════════════════════════════════════════════════════╗");
println!("║ xchecker Embedding Example - Requirements Phase ║");
println!("╚════════════════════════════════════════════════════════════╝\n");
demo_environment_based_config();
demo_explicit_config();
println!("=== Demo 3: Running Requirements Phase (Dry-Run) ===\n");
let spec_id = "embed-demo-run";
match OrchestratorHandle::new(spec_id) {
Ok(mut handle) => {
handle.set_dry_run(true);
println!("✓ Created handle with dry-run enabled");
match handle.can_run_phase(PhaseId::Requirements) {
Ok(true) => {
println!("✓ Requirements phase can be executed");
println!(" Running Requirements phase...");
match handle.run_phase(PhaseId::Requirements).await {
Ok(result) => {
println!(" Phase completed!");
println!(" Success: {}", result.success);
if let Some(receipt) = handle.last_receipt_path() {
println!(" Receipt: {}", receipt.display());
}
}
Err(e) => {
println!(" Phase failed: {}", e);
}
}
}
Ok(false) => {
println!("✗ Requirements phase cannot be executed (dependencies not met)");
}
Err(e) => {
println!("✗ Could not check phase eligibility: {}", e);
}
}
match handle.status() {
Ok(status) => {
println!("\n Final status:");
println!(" Schema version: {}", status.schema_version);
println!(" Artifacts: {}", status.artifacts.len());
for artifact in &status.artifacts {
println!(" - {} ({})", artifact.path, artifact.blake3_first8);
}
}
Err(e) => {
println!(" Could not get final status: {}", e);
}
}
}
Err(e) => {
println!("✗ Failed to create handle: {}", e.display_for_user());
println!("\n Note: This example requires a valid .xchecker/ directory.");
println!(" Run 'xchecker init' in your workspace first.");
}
}
println!("\n=== Example Complete ===");
println!("\nKey Takeaways:");
println!(" • Use OrchestratorHandle::new() for CLI-like behavior");
println!(" • Use OrchestratorHandle::from_config() for deterministic behavior");
println!(" • Use set_dry_run(true) for testing without LLM calls");
println!(" • Check status() to inspect artifacts and spec state");
println!(" • Use can_run_phase() to validate before execution");
}