Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Prism — Intelligent Token Optimization for Kiro CLI

A transparent PTY proxy that compresses prompts before they reach the model, reducing token usage without changing how you work.

User Input ──► Prism (detects + compresses) ──► Kiro CLI Classic ──► Model

Optimized for Kiro Classic — no character limits, full pipeline on every prompt.


How It Works

Prism intercepts your prompts via a PTY wrapper around kiro-cli --classic, runs them through a multi-stage compression pipeline, and forwards the optimized version. You type normally — compression is invisible.

Pipeline

┌─────────────────────────────────────────────────┐
│  1. Noise Stripping (greetings, filler, typos)  │
│  2. Content Detection (code/logs/diff/HTML/text) │
│  3. ML Compression (Kompress ModernBERT model)   │
│  4. Metrics Logging (SQLite + Dashboard)         │
└─────────────────────────────────────────────────┘

Quick Start

# Clone and setup
git clone <repo-url> prism && cd prism
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Run (starts model warm-up + dashboard + Kiro proxy)
./start

Prerequisite: kiro-cli must be installed and kiro-cli --classic must work.

By default, Kiro opens at your home directory. To start in a specific project:

./start ~/projects/my-app

To launch the dashboard separately:

streamlit run dashboard.py

Features

Feature Description
Noise Stripping Removes greetings, filler words, punctuation spam — with fuzzy matching for typos like "hellloooo"
Content-Aware Routing Detects content type and routes to specialized compressors
Tree-Sitter AST Compression Removes comments, collapses whitespace while preserving code logic (Python, JS, TS, Rust, Go)
Log Compression Pattern deduplication, timestamp normalization
Diff Compression Hunks-only extraction, metadata stripping
HTML Extraction Content extraction, tag removal
ML Token Compression ModernBERT-based per-token keep/discard inference via Kompress
Adaptive Prediction 6-feature ML model predicts optimal compression ratio per prompt
Safety Fallback Reverts to original if compression exceeds 65% or expands the prompt
Live Dashboard Streamlit dashboard with real-time compression metrics

Content-Specific Compressors

Content Type Strategy
Source Code Tree-sitter AST-aware — removes comments, collapses whitespace, preserves logic
Logs Pattern deduplication, timestamp normalization
Git Diffs Hunks-only extraction, metadata stripping
HTML Content extraction, tag removal
JSON Arrays Structural deduplication
Plain Text Greeting/filler removal + ML token compression

Project Structure

prism/
├── kiro_optimizer.py          # Main entry point — PTY proxy + optimization pipeline
├── dashboard.py               # Streamlit metrics dashboard
├── prism_warm.py              # Model warm-up script
├── start                      # Quick-start launcher
├── requirements.txt
├── README.md
└── prism/                     # Core library
    ├── __init__.py
    ├── model_pool.py          # Shared ONNX/SentenceTransformer model pool
    ├── context_pruner.py      # Context pruning (standalone module)
    ├── prediction.py          # Feature extraction + compression ratio prediction
    ├── eval.py                # Quality evaluation (semantic similarity scoring)
    ├── cache/
    │   └── semantic.py        # FAISS-based semantic cache (standalone module)
    ├── transforms/
    │   ├── base.py            # Base transform interface
    │   ├── content_router.py  # Content detection + routing
    │   ├── kompress_ml.py     # ModernBERT ML compression
    │   ├── code_compressor.py # Regex-based code compression
    │   ├── tree_sitter_compressor.py  # AST-aware code compression
    │   ├── diff_compressor.py # Git diff compression
    │   ├── html_extractor.py  # HTML content extraction
    │   ├── log_compressor.py  # Log deduplication
    │   └── smart_crusher.py   # Aggressive last-resort compression
    ├── compression/
    │   ├── masks.py           # Token masking strategies
    │   └── universal.py       # Universal compression wrapper
    ├── observability/
    │   ├── metrics.py         # SQLite metrics collector
    │   └── tracing.py         # Request tracing

Dashboard

Launch with streamlit run dashboard.py to see:

  • Total tokens saved
  • Compression ratio per request
  • Content type distribution
  • Per-request history with before/after

What's Next

Prism works fully as a standalone prompt optimizer today. Additional features are built and ready to activate with minimal integration:

Feature Hook Needed Impact
Context Pruning beforeSubmit with conversation history access Auto-drop irrelevant turns, keep context window lean
IDE Integration beforeSubmit prompt-transform in Kiro VS Code extension Same compression inside the IDE
Semantic Cache beforeSubmit + ability to short-circuit with a cached response Skip API call entirely for 92%+ similar prompts

Notes

  • First launch downloads models from HuggingFace (~2s) — ./start handles warm-up automatically
  • Tree-sitter compression requires language packages (included in requirements.txt)

Tech Stack

  • Python 3.10+
  • ONNX Runtime — fast inference for embedding + compression models
  • FAISS — vector similarity search
  • Tree-sitter — AST parsing for code compression
  • Kompress — ModernBERT token compression model
  • Streamlit + Plotly — live dashboard
  • tiktoken — token counting (cl100k_base)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages