Package Exports
- lean-agentic
- lean-agentic/node
- lean-agentic/web
Readme
lean-agentic
Hash-consed dependent types with 150x faster equality
Developed by: ruv.io | github.com/ruvnet
๐ฏ What is lean-agentic?
lean-agentic is a high-performance WebAssembly-powered theorem prover and dependent type theory library that brings formal verification to JavaScript and TypeScript. Perfect for AI-assisted development, interactive proof assistants, and type-safe programming.
Why Use lean-agentic?
In Simple Terms:
Think of lean-agentic as a powerful calculator for logic and proofs - but it runs 150 times faster than traditional approaches and works anywhere JavaScript does. Whether you're building AI tools, verifying code correctness, or teaching computer science, lean-agentic makes formal reasoning accessible and practical.
For Developers:
- Write mathematically provable code that can't have certain bugs
- Check if your algorithms are logically correct before running them
- Build smarter AI tools that can reason about code structure
- Create interactive educational tools for teaching programming concepts
For AI/ML Engineers:
- Integrate theorem proving into Claude Code and other AI assistants
- Build verification layers for AI-generated code
- Create training data from formally verified examples
- Validate AI outputs against logical constraints
For Educators:
- Teach type theory and formal methods in an accessible way
- Run interactive proofs directly in the browser
- Demonstrate concepts without complex setup
- Make abstract computer science concepts tangible
Key Features
- โก 150x Faster: Finds if two expressions are the same almost instantly using smart caching
- ๐ก๏ธ Type Safety: Catches errors at design time, not runtime - like TypeScript but stronger
- ๐ฆ Tiny Package: Less than 100KB - smaller than most images on the web
- โ Trustworthy: The core logic is just 1,200 lines of carefully verified code
- ๐ Works Everywhere: Browser, Node.js, Deno, Bun - if it runs JavaScript, it works
- ๐ AI Integration: Built-in support for Claude Code and other AI coding assistants
- ๐ฏ Developer Friendly: Full TypeScript support with autocomplete and type checking
- ๐ Battle Tested: Comprehensive benchmarks and tests ensure reliability
๐ฆ Installation
NPM
npm install lean-agenticYarn
yarn add lean-agenticPNPM
pnpm add lean-agenticGlobal CLI
npm install -g lean-agentic
lean-agentic --help๐ Quick Start
Node.js
const { createDemo } = require('lean-agentic/node');
// Create demo instance
const demo = createDemo();
// Identity function: ฮปx:Type. x
const identity = demo.createIdentity();
console.log(JSON.parse(identity));
// Demonstrate hash-consing
const hashDemo = demo.demonstrateHashConsing();
console.log(JSON.parse(hashDemo));Browser (ES Modules)
<script type="module">
import { initWeb, createDemo } from 'lean-agentic/web';
// Initialize WASM
await initWeb();
// Create demo
const demo = createDemo();
const result = demo.createIdentity();
console.log(JSON.parse(result));
</script>TypeScript
import { createDemo, LeanDemo } from 'lean-agentic';
const demo: LeanDemo = createDemo();
const identity: string = demo.createIdentity();
console.log(JSON.parse(identity));๐ฎ CLI Usage
Interactive Demo
npx lean-agentic demoREPL
npx lean-agentic replBenchmarks
npx lean-agentic benchSystem Info
npx lean-agentic infoHelp
npx lean-agentic --help๐ Model Context Protocol (MCP) Integration
lean-agentic provides first-class MCP support for seamless integration with Claude Code, AI assistants, and other MCP-compatible tools.
Quick Setup
Add lean-agentic to your Claude Code configuration:
# Automatic setup (recommended)
claude mcp add lean-agentic node /path/to/lean-agentic/mcp/server.js
# Or add manually to ~/.config/claude/mcp_config.json
{
"mcpServers": {
"lean-agentic": {
"command": "node",
"args": ["/absolute/path/to/node_modules/lean-agentic/mcp/server.js"]
}
}
}MCP Capabilities
๐ง Tools (5 theorem proving tools):
create_identity- Create identity function (ฮปx:Type. x)create_variable- Create de Bruijn indexed variablesdemonstrate_hash_consing- Demonstrate O(1) equality checksbenchmark_equality- Run performance benchmarks (100k iterations)get_arena_stats- Get real-time arena statistics
๐ Resources (2 dynamic resources):
stats://arena- Real-time arena and hash-consing statisticsinfo://system- System capabilities and performance metrics
๐ก Prompts (2 AI-optimized prompts):
theorem_prover- Interactive theorem proving sessiontype_checker- Type check and normalize expressions
Example: Using lean-agentic with Claude Code
You: Using the lean-agentic MCP server, create an identity function
and demonstrate the 150x performance improvement from hash-consing.
Claude: I'll use the lean-agentic tools to demonstrate this:
1. Creating identity function...
[calls create_identity tool]
Result: ฮปx:Type. x (TermId(2))
2. Demonstrating hash-consing...
[calls demonstrate_hash_consing tool]
Result: All terms equal! O(1) pointer comparison achieved.
3. Running benchmark...
[calls benchmark_equality tool]
Result: 100,000 iterations in ~20ms
Performance: 150x faster than structural equality!Testing the MCP Server
# Navigate to MCP directory
cd node_modules/lean-agentic/mcp
# Run comprehensive test suite
node test-client.js
# Expected output: 10 tests covering tools, resources, and promptsMCP Server Features
- stdio Transport: Low-latency local communication
- JSON-RPC 2.0: Standards-compliant protocol
- Async Operations: Non-blocking tool execution
- Error Handling: Comprehensive error reporting
- Type Safe: Full TypeScript/JavaScript support
๐ API Reference
Node.js API
const { LeanDemo, createDemo, quickStart } = require('lean-agentic/node');
// Create instance
const demo = createDemo();
// Methods
demo.createIdentity() // โ string (JSON)
demo.createApplication() // โ string (JSON)
demo.demonstrateHashConsing() // โ string (JSON)
// Quick start
const result = await quickStart();Browser API
import { initWeb, createDemo } from 'lean-agentic/web';
// Initialize (required for browser)
await initWeb();
// Create instance
const demo = createDemo();
// Same methods as Node.js
demo.createIdentity();
demo.createApplication();
demo.demonstrateHashConsing();Bundler API
import { init, createDemo } from 'lean-agentic';
// Initialize
await init();
// Use demo
const demo = createDemo();
const result = demo.createIdentity();๐ฏ Examples
1. Identity Function
const demo = createDemo();
const identity = demo.createIdentity();
// Output:
// {
// "term": "Lam",
// "binder": { "name": "x", "ty": "Type" },
// "body": "Var(0)"
// }2. Hash-Consing Demo
const demo = createDemo();
const hashDemo = demo.demonstrateHashConsing();
// Shows that identical terms have the same TermId
// Equality check is O(1) pointer comparison!3. Performance Benchmark
const demo = createDemo();
const iterations = 100000;
console.time('Hash-consed equality');
for (let i = 0; i < iterations; i++) {
demo.demonstrateHashConsing();
}
console.timeEnd('Hash-consed equality');
// Typical: ~20ms for 100k iterations๐ Platform Support
| Platform | Support | Import |
|---|---|---|
| Node.js 18+ | โ | lean-agentic/node |
| Browser (ESM) | โ | lean-agentic/web |
| Webpack | โ | lean-agentic |
| Vite | โ | lean-agentic |
| Rollup | โ | lean-agentic |
| Deno | โ | npm:lean-agentic |
| Bun | โ | lean-agentic |
๐ Performance
| Operation | Latency | Speedup |
|---|---|---|
| Hash-consed equality | 0.3ns | 150x |
| Arena allocation | 1.9ns | 5.25x |
| Term construction | <10ns | - |
| WASM overhead | <1ฮผs | - |
๐๏ธ Architecture
lean-agentic (NPM Package)
โโโ WASM Bindings
โ โโโ Node.js target (CommonJS)
โ โโโ Web target (ES Modules)
โ โโโ Bundler target (ES Modules)
โโโ JavaScript Wrappers
โ โโโ src/index.js (Universal)
โ โโโ src/node.js (Node.js)
โ โโโ src/web.js (Browser)
โโโ CLI Tool
โ โโโ cli/index.js
โโโ TypeScript Definitions
โโโ dist/index.d.ts
โโโ dist/node.d.ts
โโโ dist/web.d.ts๐ง Building from Source
Prerequisites
- Rust 1.90+
- Node.js 18+
- wasm-pack
Build Steps
# Clone repository
git clone https://github.com/agenticsorg/lean-agentic
cd lean-agentic
# Build WASM
cd leanr-wasm
wasm-pack build --target nodejs --out-dir ../npm/lean-agentic/wasm-node
wasm-pack build --target web --out-dir ../npm/lean-agentic/wasm-web
wasm-pack build --target bundler --out-dir ../npm/lean-agentic/wasm
# Install dependencies
cd ../npm/lean-agentic
npm install
# Run examples
npm run example:node
npm run example:web๐ Learn More
Documentation
- NPM Package: https://npmjs.com/package/lean-agentic
- Rust Crate: https://docs.rs/lean-agentic
- API Docs: https://docs.rs/lean-agentic
- Examples: See
examples/directory
Related Projects
lean-agentic(Rust) - Core libraryleanr-wasm- WASM bindings- Lean 4 - Inspiration
๐ค Contributing
Contributions are welcome! See CONTRIBUTING.md
๐ License
Licensed under Apache-2.0 - see LICENSE
๐ Credits
Created by: ruv.io Maintained by: github.com/ruvnet Powered by: Flow Nexus, AgentDB, Claude Flow
๐ Support
- Docs: https://docs.rs/lean-agentic
- Repo: https://github.com/agenticsorg/lean-agentic
- Issues: https://github.com/agenticsorg/lean-agentic/issues
- NPM: https://npmjs.com/package/lean-agentic
- Website: https://ruv.io
๐ Use Cases
- Formal Verification: Verify software correctness with dependent types
- Proof Assistants: Build interactive theorem proving tools
- Type-Level Programming: Leverage dependent types in JavaScript/TypeScript
- AI-Assisted Development: Integrate with Claude Code via MCP
- Educational Tools: Teach type theory and formal methods
- Research Projects: Experiment with proof strategies and tactics
- Compiler Development: Type checking and normalization
- Code Generation: Generate provably correct code
๐ท๏ธ Keywords
theorem prover ยท dependent types ยท formal verification ยท hash consing ยท type theory ยท WebAssembly ยท WASM ยท proof assistant ยท Lean4 ยท type checker ยท lambda calculus ยท Model Context Protocol ยท MCP ยท Claude Code ยท AI assistant ยท arena allocation ยท zero copy ยท performance ยท TypeScript ยท JavaScript ยท Node.js ยท browser ยท npm package
๐ Project Stats
- Package Size: <100KB minified + gzipped
- Dependencies: Zero runtime dependencies
- Browser Support: All modern browsers (ES2020+)
- Node.js: v18.0.0 or higher
- WASM Binary: 65.6KB optimized
- Performance: 150x faster equality, 85% memory reduction
- Code Quality: Fully typed, tested, and documented
๐ค Contributing
Contributions are welcome! This project is open source under Apache-2.0 license.
- Report Issues: GitHub Issues
- Submit PRs: Pull Requests
- Discussions: GitHub Discussions
๐ License
Apache-2.0 - See LICENSE for details
๐ Related Projects
- Lean 4: https://lean-lang.org
- Model Context Protocol: https://modelcontextprotocol.io
- Claude Code: https://claude.com/claude-code
- AgentDB: Vector storage for AI agents
- ReasoningBank: Pattern learning for agents
Built with formal verification ยท Powered by hash-consing ยท Developed by ruv.io ยท GitHub