Files
yvgude--lean-ctx/rust/crates/lean-ctx-sdk/examples/embed.rs
T
wehub-resource-sync 26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:30 +08:00

46 lines
1.7 KiB
Rust

//! In-process embedding demo for `lean-ctx-sdk`.
//!
//! Run from the repo root: cargo run -p lean-ctx-sdk --example embed
//!
//! It builds an [`Engine`] rooted at the current directory and shows the
//! read → re-read token delta, plus the stateless helpers.
use lean_ctx_sdk::{Engine, ReadMode};
fn main() -> Result<(), lean_ctx_sdk::Error> {
println!("lean-ctx-sdk v{}\n", lean_ctx_sdk::VERSION);
// ── Stateless helpers (no project root needed) ──
let text = "The quick brown fox jumps over the lazy dog.";
println!("tokens = {}", lean_ctx_sdk::tokens::count(text));
println!("blake3 = {}\n", lean_ctx_sdk::hash::blake3_str(text));
// ── The Engine: shared-cache reads against this repo ──
let engine = Engine::builder(".").build()?;
println!("engine rooted at {}\n", engine.project_root());
let target = "Cargo.toml";
let first = engine.read(target, ReadMode::Full)?;
println!(
"read #1 {target}: {} original tokens, saved {} ({:.0}%)",
first.original_tokens,
first.saved_tokens,
first.saved_pct()
);
let again = engine.read(target, ReadMode::Full)?;
println!(
"read #2 {target}: saved {} ({:.0}%) <- shared-cache delta\n",
again.saved_tokens,
again.saved_pct()
);
// ── Author + audit an addon entirely in-process ──
let slug = lean_ctx_sdk::addon::slugify("My Plan Runner").unwrap();
let manifest = lean_ctx_sdk::addon::scaffold(&slug, lean_ctx_sdk::addon::Transport::Stdio);
let report = lean_ctx_sdk::addon::audit(&manifest).expect("audit");
println!("addon `{slug}` audit verdict = {:?}", report.verdict);
Ok(())
}