Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ extensions), TLS `rustls`+`ring` (~0.6 MB), `regex` (~0.5 MB), and QuickJS (~0.5
## Build & test

```sh
# Acceptance: a self-contained ~8.9 MB binary carrying the whole pi says hello.
OPENAI_API_KEY=… cargo run --release --example hello # → "Hello! Nice to meet you."

# The full pi bundle is committed + embedded, so the whole suite runs with only
# Rust — no Node, no build step. This includes the offline pi tests: it loads,
# an extension binds to a session, sessions persist to disk.
Expand Down
56 changes: 56 additions & 0 deletions crates/pocket-pi/examples/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Dead-simple acceptance: boot the full, embedded pi on a real model and say
//! hello. This binary carries the WHOLE unmodified pi-coding-agent inside it.
//!
//! OPENAI_API_KEY=… cargo run --release --example hello
//! OPENAI_API_KEY=… OPENAI_MODEL=gpt-5.6 cargo run --release --example hello
use pocket_pi::{HostEvent, PiRuntime};
use std::cell::RefCell;
use std::io::Write;
use std::rc::Rc;

fn main() {
let key = std::env::var("OPENAI_API_KEY").expect("set OPENAI_API_KEY");
let model = std::env::var("OPENAI_MODEL").unwrap_or_else(|_| "gpt-5.6".into());

// The whole pi is embedded — new() stands it up with no external files.
let mut rt = PiRuntime::new().expect("runtime");

let reply = Rc::new(RefCell::new(String::new()));
let r = reply.clone();
rt.on_event(move |ev: &HostEvent| match ev.kind.as_str() {
"text" => {
if let Some(d) = ev.value.get("delta").and_then(|v| v.as_str()) {
r.borrow_mut().push_str(d);
print!("{d}");
std::io::stdout().flush().ok();
}
}
"assistant_text" if r.borrow().is_empty() => {
if let Some(t) = ev.value.get("text").and_then(|v| v.as_str()) {
*r.borrow_mut() = t.to_string();
print!("{t}");
}
}
"error" => eprintln!("\n[error] {}", ev.raw),
_ => {}
});

let cfg = serde_json::json!({
"provider": "openai", "model": model, "apiKey": key,
"maxTokens": 2048,
"systemPrompt": "You are a friendly assistant. Be very brief."
});
eprintln!("booting full pi on {model} …");
rt.boot(&cfg.to_string()).expect("boot");
eprint!("pi > ");
rt.prompt("Say hello in a few words.").expect("prompt");
while !rt.is_idle() {
rt.pump().expect("pump");
std::thread::sleep(std::time::Duration::from_millis(50));
}
println!();
if reply.borrow().trim().is_empty() {
eprintln!("(no reply — check OPENAI_API_KEY / proxy)");
std::process::exit(1);
}
}
Loading