A WebAssembly build of the lever-runner intent-to-command carapace, providing near-native performance for intent hashing, embedding, vector similarity search, and a three-gate routing pipeline — all running entirely in the browser with zero server round-trips.
Command palettes (Raycast, Alfred, k9s) and AI-powered shell assistants (GitHub Copilot CLI, warp) traditionally rely on either:
- Server-side NLP — high latency, privacy concerns, requires network.
- Exact string matching — brittle, no semantic understanding.
Lever-runner WASM offers a third path: a complete intent-resolution engine compiled to WebAssembly, running at near-native speed inside the browser. The three-gate pipeline (exact hash → vector similarity → keyword heuristic) ensures O(1) best-case response with graceful degradation.
This matters for:
- Edge computing: run intelligent command resolution on devices with no backend.
- Privacy: user intents never leave the browser.
- Latency: sub-millisecond hash lookups, ~10–50µs vector search — faster than any network call.
Every intent string is hashed using BLAKE2b with a 128-bit digest:
BLAKE2b is a cryptographic hash function faster than MD5 and SHA-1, with a proven security margin. The hash provides O(1) exact-match lookup via hash-table comparison.
The embed_intent function produces a 64-dimensional vector capturing both what characters appear and where they appear:
Dimensions 0–39: Character frequency with positional decay. Each character's contribution is weighted by:
where
Dimensions 40–55: Bigram frequency. 16 hash buckets capture character-pair co-occurrence:
This is a feature-hashing trick (Weinberger et al., 2009), reducing the
Dimensions 56–63: Structural features. Log-normalized length, word count, average word length, character diversity, digit/path presence, separator ratio.
Similarity between query embedding
The threshold for Gate 2 acceptance is
| Gate | Method | Threshold | Latency | Accuracy |
|---|---|---|---|---|
| 1 — Hash | Exact BLAKE2b match | 1.0 | ~0µs | Exact |
| 2 — Vector | Cosine similarity | > 0.75 | ~10–50µs | Semantic |
| 3 — Keyword | Substring matching | > 0.0 | ~50–200µs | Heuristic |
The cascade ensures that easy cases (exact match) are resolved instantly, while harder cases escalate to more expensive (but more flexible) methods.
| Operation | Complexity |
|---|---|
hash_intent(s) |
O(|s|) |
embed_intent(s) |
O(|s|) |
vector_search(q, k) |
O(n \cdot d + n \log n) where |
gate_pipeline(s) |
O(n) worst case (Gate 3) |
import init, { gate_pipeline, teach, seed_commands } from './lever_runner_wasm.js';
await init();
// Seed common commands
seed_commands(); // Loads ~28 default commands
// Teach a new mapping
teach("restart nginx", "systemctl restart nginx");
// Resolve an intent
const result = JSON.parse(gate_pipeline("restart nginx"));
console.log(result);
// { gate: 1, command: "systemctl restart nginx", confidence: 1.0, latency_us: 42 }| Function | Parameters | Returns | Description |
|---|---|---|---|
hash_intent(intent) |
&str |
String (32-char hex) |
BLAKE2b-128 hash |
embed_intent(intent) |
&str |
Vec<f64> (64-dim) |
Position-aware embedding |
vector_search(embedding, top_k) |
&[f64], usize |
JSON string | Ranked results |
gate_pipeline(intent) |
&str |
JSON string | Full three-gate resolution |
teach(intent, command) |
&str, &str |
void |
Add to database |
load_commands(json) |
&str |
usize |
Bulk load |
export_commands() |
— | JSON string | Export database |
clear_commands() |
— | void |
Clear database |
command_count() |
— | usize |
Database size |
seed_commands() |
— | usize |
Load defaults |
The library satisfies γ + η = C in edge computing:
- γ (correctness): the three-gate cascade provides a correctness floor. Gate 1 never produces false positives (exact hash match). Gate 2 uses a calibrated cosine threshold (0.75) balancing precision and recall. Gate 3 provides a deterministic keyword fallback — never returning empty.
-
η (efficiency): the entire pipeline runs in WASM with no I/O. The
opt-level = "z"release profile and LTO minimize binary size for fast initial page load. Vector search isO(n)with$d=64$ — fast enough for thousands of commands. -
C (contract): a complete intent-resolution system in a single
.wasmbinary, deployable to any browser or WASM runtime (Cloudflare Workers, Deno, Node.js) with zero dependencies beyond the WASM standard library.
- Aumasson, J.-P. et al. "BLAKE2: Simpler, Smaller, Fast as MD5." ACM SAC, 2013.
- Weinberger, K. et al. "Feature Hashing for Large Scale Multitask Learning." ICML, 2009.
- Haas, A. et al. "Bringing the Web up to Speed with WebAssembly." PLDI, 2017.
- Mikolov, T. et al. "Distributed Representations of Words and Phrases." NeurIPS, 2013. (Embedding foundations)
MIT