-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
The shortest path from clone to working TinyJuice APIs.
Add the crate once it is published:
cargo add tinyjuiceOr pin it in Cargo.toml:
[dependencies]
tinyjuice = "0.1"The default feature set enables the tokenjuice-treesitter feature, which
includes optional tree-sitter dependencies for richer source-code handling.
git clone https://github.com/tinyhumansai/tinyjuice.git
cd tinyjuice
cargo testCI-equivalent local gates:
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo testRun the small public trait example:
cargo run --example passthroughRun hot-path benchmarks:
cargo benchUse this when you need a stable compression strategy boundary and report shape:
use tinyjuice::{CompressionConfig, CompressionInput, Compressor, PassthroughCompressor};
fn main() -> Result<(), tinyjuice::TinyJuiceError> {
let compressor = PassthroughCompressor;
let input = CompressionInput::new("Keep this text unchanged for now.");
let output = compressor.compress(input, &CompressionConfig::default())?;
assert_eq!(output.text, "Keep this text unchanged for now.");
assert_eq!(output.report.strategy, "passthrough");
Ok(())
}Use this for arbitrary blobs: file contents, web extracts, HTML, command output, or anything large headed toward model context.
use tinyjuice::{CompressOptions, ContentHint, compress_content};
async fn compact_json(payload: &str) {
let hint = ContentHint {
extension: Some("json".to_string()),
source_tool: Some("read_file".to_string()),
..Default::default()
};
let result = compress_content(payload, Some(hint), &CompressOptions::default()).await;
if result.applied {
println!(
"{} compressed by {}: {} -> {} bytes",
result.content_kind.as_str(),
result.compressor.as_str(),
result.original_bytes,
result.compacted_bytes,
);
}
}This is the API an agent runtime usually wants:
use tinyjuice::{AgentTokenjuiceCompression, compact_tool_output_with_policy};
async fn compact_shell_output(output: &str) {
let args = serde_json::json!({ "command": "cargo test" });
let (text, stats) = compact_tool_output_with_policy(
"shell",
Some(&args),
output,
Some(101),
AgentTokenjuiceCompression::Full,
).await;
println!(
"applied={} rule={} ratio={:.3}",
stats.applied,
stats.rule_id,
stats.ratio(),
);
// Show `text` to the model.
}Hosts install process-global options at startup:
use tinyjuice::{CompressOptions, install_config};
let mut opts = CompressOptions::default();
opts.min_bytes_to_compress = 2048;
opts.ccr_min_tokens = 500;
opts.ml_text_enabled = false;
install_config(
opts,
256, // max CCR entries
64 * 1024 * 1024, // max CCR bytes
None, // no TTL
None, // no disk tier
);When a compressed output includes a footer with tokenjuice_retrieve, the
original can be recovered from CCR:
use tinyjuice::cache;
let tokens = cache::parse_markers(&model_visible_text);
if let Some(token) = tokens.first() {
if let Some(original) = cache::retrieve(token) {
println!("recovered {} bytes", original.len());
}
}src/compress.rs router entry point
src/compressors/ per-kind compressors
src/detect/ content detection and hints
src/cache/ CCR marker and store
src/rules/ rule loading and compilation
src/reduce.rs command-output reduction engine
src/tool_integration.rs OpenHuman-style adapter
src/compressor/ simple trait scaffold
src/config/ simple config scaffold
tests/ fixture and e2e tests
benches/ Criterion hot-path benchmarks
interface/ local analytics UI
wiki/ GitHub wiki source
- Read Capabilities for the full API index.
- Read Router and Compressors before changing compression behavior.
- Read CCR Recovery before changing marker, cache, or retrieval semantics.
- Read OpenHuman Integration before wiring TinyJuice into a host runtime.
Token compression for agent context.
Getting started
Concepts
Modules
Agent docs