Skip to content

at264939-ctrl/Heisenberg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•
โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ–ˆโ•—
โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•‘โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘
โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•
โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•
Heisenberg

"I am the one who knocks."


GitHub Stars GitHub Forks License: MIT Built with Rust Runs Locally RAM Budget Models Platform


A fully local, production-grade autonomous AI agent. Runs 9B-class GGUF models on constrained hardware using adaptive TurboQuant strategies โ€” all within a strict 3 GB RAM budget, no cloud required.


๐Ÿš€ Quick Start ยท ๐Ÿ—๏ธ Architecture ยท ๐Ÿง  TurboQuant ยท ๐Ÿ“ Structure ยท ๐Ÿ”’ Security ยท โ˜• Support


๐ŸŒŸ What Is Heisenberg?

Heisenberg is not just another AI wrapper. It is a production-oriented autonomous agent built from the ground up for developers who refuse to compromise on privacy, performance, or control.

Feature Detail
๐Ÿงฑ Core Language Rust โ€” zero-cost abstractions, memory safety, raw speed
๐Ÿค– Inference Engine llama-cpp via FFI/subprocess (GGUF native)
๐Ÿ’พ Memory Model Adaptive 3 GB hard cap with graceful degradation
๐Ÿš Execution Layer Bash-first, auditable, sandboxed via ulimit
๐Ÿงฌ Long-term Memory PostgreSQL (mike module)
๐ŸŒ Browser Automation Sandboxed via the_rv + scripts/drive.sh
โ˜๏ธ Cloud Dependency Zero โ€” fully offline, fully private
๐Ÿ“ฆ Model Format GGUF (drop .gguf in models/ and go)

๐Ÿ—๏ธ System Architecture

High-Level Flow

flowchart TD
    U(["๐Ÿ‘ค User Terminal"]) -->|natural language input| H

    subgraph HEISENBERG ["๐Ÿงช Heisenberg Orchestrator (Rust)"]
        H["๐ŸŽฏ REPL / Action Loop"]
        H -->|structured JSON commands| J["๐Ÿ”ง Jesse\nBash Executor"]
        H -->|inference requests| L["โš—๏ธ The Lab\nllama-cpp + GGUF Loader"]
        H -->|memory ops| M["๐Ÿ—„๏ธ Mike\nMemory Manager"]
        H -->|schedule tasks| G["โฑ๏ธ Gus\nScheduler"]
        H -.->|self-patch| B["๐Ÿ”ต Blue Sky\nSelf-Modification"]
        H -.->|screen events| K["๐Ÿ‘๏ธ Hank\nScreen Observer"]
        H -.->|browser tasks| RV["๐ŸŒ The RV\nBrowser Sandbox"]
    end

    J -->|shell result JSON| H
    L -->|streamed tokens| H
    M <-->|read/write| DB[("๐Ÿ˜ PostgreSQL\nLong-term Memory")]
    RV -->|page data| H

    style HEISENBERG fill:#1a1a2e,stroke:#e94560,color:#fff
    style U fill:#16213e,stroke:#0f3460,color:#fff
    style DB fill:#0f3460,stroke:#533483,color:#fff
Loading

IPC Sequence: Rust โ†” Bash

sequenceDiagram
    autonumber
    participant U  as ๐Ÿ‘ค User
    participant R  as ๐ŸŽฏ Rust Orchestrator
    participant CF as ๐Ÿ“จ CMD_FIFO
    participant BW as ๐Ÿ”ง Bash Worker (Jesse)
    participant RF as ๐Ÿ“ฉ RESP_FIFO
    participant DB as ๐Ÿ—„๏ธ PostgreSQL (Mike)

    U->>R: "Analyze logs and summarize"
    R->>CF: write {cmd: "run", script: "cook.sh", args: [...]}
    CF->>BW: Execute script under ulimit sandbox
    BW->>BW: Run, collect stdout/stderr
    BW->>RF: write {status: "ok", pid: 1234, output: "..."}
    RF->>R: Read response
    R->>DB: Persist summary to long-term memory
    DB-->>R: ACK
    R-->>U: Stream result tokens
Loading

TurboQuant Memory Planning Pipeline

flowchart LR
    A["๐Ÿ“‚ GGUF Header Scan\n(layers, heads, dim, tokenizer)"]
    --> B["๐Ÿ“ KV Cache Estimator\n(context ร— layers ร— heads ร— dtype)"]
    --> C["๐Ÿ“Š Memory Planner\n(weights + KV + OS overhead)"]

    C --> D{"> 3 GB?"}
    D -- YES --> E["โšก Quantization Selector\nQ8_0 โ†’ Q5_0 โ†’ Q4_0"]
    D -- YES --> F["๐Ÿ“‰ Context Reducer\n2048 โ†’ 1024 โ†’ 512"]
    D -- NO  --> G["โœ… Launch as-is"]
    E --> H["๐Ÿš€ cook.sh Launcher\nulimit -v 3072 MB"]
    F --> H
    G --> H

    H --> I["๐Ÿ” Mike Live Monitor\n(RSS polling)"]
    I -->|pressure detected| J["๐Ÿ”„ Runtime Mitigation\n(shrink ctx / cancel tasks)"]
    J --> I

    style D fill:#e94560,stroke:#c23152,color:#fff
    style H fill:#0f3460,stroke:#533483,color:#fff
    style I fill:#16213e,stroke:#e94560,color:#fff
Loading

๐Ÿ”ฌ Module Reference

Each module in src/ has a named role inspired by Breaking Bad โ€” intentional, consistent, and memorable.

mindmap
  root((๐Ÿงช Heisenberg))
    ๐ŸŽฏ heisenberg
      REPL loop
      Action dispatcher
      Agent state machine
    โš—๏ธ the_lab
      GGUF loader
      llama-cpp FFI
      TurboQuant Planner
      Token streamer
    ๐Ÿ”ง jesse
      Bash executor
      FIFO IPC
      ulimit sandbox
      Script runner
    โฑ๏ธ gus
      Task scheduler
      Priority queue
      Retry logic
    ๐Ÿ—„๏ธ mike
      Memory manager
      PostgreSQL glue
      Context compaction
      Pressure monitor
    โš™๏ธ saul
      Config parser
      CLI interface
      Argument validation
    ๐Ÿ‘๏ธ hank
      Screen observer
      Event capture
      Display hooks
    ๐ŸŒ the_rv
      Browser sandbox
      Automation layer
      Allow-list engine
    ๐Ÿ”ต blue_sky
      Self-modification
      Patch generator
      Safe apply
Loading

๐Ÿ“ Project Structure

Heisenberg/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ฆ src/
โ”‚   โ”œโ”€โ”€ heisenberg/      # ๐ŸŽฏ Orchestrator โ€” REPL, action loop, agent state machine
โ”‚   โ”œโ”€โ”€ the_lab/         # โš—๏ธ  Inference engine โ€” GGUF loader, llama-cpp, TurboQuant
โ”‚   โ”œโ”€โ”€ jesse/           # ๐Ÿ”ง Bash executor โ€” FIFO IPC, sandboxed shell worker
โ”‚   โ”œโ”€โ”€ gus/             # โฑ๏ธ  Scheduler โ€” task queue, priority, retries
โ”‚   โ”œโ”€โ”€ mike/            # ๐Ÿ—„๏ธ  Memory manager โ€” PostgreSQL glue, context compaction
โ”‚   โ”œโ”€โ”€ saul/            # โš™๏ธ  Config & CLI โ€” argument parsing, env vars
โ”‚   โ”œโ”€โ”€ hank/            # ๐Ÿ‘๏ธ  Screen observer โ€” display hooks, event capture
โ”‚   โ”œโ”€โ”€ the_rv/          # ๐ŸŒ Browser sandbox โ€” automation, allow-list control
โ”‚   โ””โ”€โ”€ blue_sky/        # ๐Ÿ”ต Self-modification โ€” patch generator, safe apply
โ”‚
โ”œโ”€โ”€ ๐Ÿ› ๏ธ scripts/
โ”‚   โ”œโ”€โ”€ build.sh         # Full build (release mode)
โ”‚   โ”œโ”€โ”€ say-my-name.sh   # Launch agent with shell UI
โ”‚   โ”œโ”€โ”€ cook.sh          # Inference wrapper โ€” ulimit enforcement
โ”‚   โ””โ”€โ”€ drive.sh         # Browser automation entry point
โ”‚
โ”œโ”€โ”€ ๐Ÿค– models/           # Drop your .gguf files here (do NOT commit large files)
โ”‚   โ””โ”€โ”€ *.gguf
โ”‚
โ”œโ”€โ”€ ๐Ÿ—ƒ๏ธ sql/              # PostgreSQL schema โ€” long-term memory tables
โ”‚
โ””โ”€โ”€ ๐Ÿ“‹ Cargo.toml        # Rust workspace manifest

๐Ÿš€ Quick Start

Prerequisites

Requirement Version Check
Rust toolchain 1.70+ rustc --version
Cargo Latest stable cargo --version
PostgreSQL 14+ (for Mike memory) psql --version
A GGUF model 9B-class recommended โ€”

Step-by-step

# 1. Clone the repository
git clone https://github.com/at264939-ctrl/Heisenberg.git
cd Heisenberg

# 2. Place your GGUF model
cp /path/to/your/model.gguf models/
# Recommended: Qwen3.5-9B-Uncensored-HauhauCS-Aggressive-Q4_K_M.gguf

# 3. Build (release mode, optimized)
./scripts/build.sh

# 4. Launch the agent
Heisenberg
# โ€” or โ€”
./scripts/say-my-name.sh chat

# 5. Check system status
Heisenberg status

๐Ÿ’ก Tip: For large models (>2 GB), use Git LFS if you plan to track them in version control.


๐Ÿง  TurboQuant Engine

The secret weapon that makes 9B-class models behave like small models.

TurboQuant is Heisenberg's adaptive runtime strategy layer. It solves a fundamental problem: 9B parameter models have massive KV caches that expand with context length and easily exceed available RAM.

The Core Problem

9B model weights (Q4_K_M) โ‰ˆ ~5.5 GB on disk
But RAM usage during inference = weights + KV cache + OS overhead
KV cache alone at context=2048 can push total usage well over 3 GB

TurboQuant's 5-Stage Response

Stage 1 โ†’ SCAN         Read GGUF header: layers, heads, hidden_dim, tokenizer
Stage 2 โ†’ ESTIMATE     Calculate KV cache size for requested context window
Stage 3 โ†’ PLAN         Aggregate: KV + mmap'd weights + tokenizer + OS overhead
Stage 4 โ†’ ADAPT        If predicted > 3 GB: downgrade KV quant and/or reduce context
Stage 5 โ†’ CONFINE      Launch via cook.sh with ulimit -v enforced at OS level

Live Example: Qwen3.5-9B on 3 GB RAM

Step Action Value
Request User asks for generation context = 2048
Scan Read GGUF metadata layers, heads, hidden_dim extracted
Estimate Compute KV cache ~X MB for context=2048
Plan Total predicted usage Exceeds 3 GB cap โš ๏ธ
Adapt Select stronger KV quant Q8_0 โ†’ Q5_0 โ†’ Q4_0
Adapt Reduce context if needed 2048 โ†’ 1024
Launch cook.sh --mem-mb 3072 ulimit enforced at OS level โœ…
Monitor mike polls RSS live Mitigation triggered if needed

๐Ÿ”’ Security & Privacy

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   SECURITY PRINCIPLES                   โ”‚
โ”‚                                                         โ”‚
โ”‚  โœ…  100% local โ€” zero external API calls               โ”‚
โ”‚  โœ…  Zero telemetry โ€” no usage data ever leaves         โ”‚
โ”‚  โœ…  Bash scripts are auditable first-class citizens    โ”‚
โ”‚  โœ…  Browser automation is allow-listed by default      โ”‚
โ”‚  โœ…  ulimit enforced at OS level for all subprocesses   โ”‚
โ”‚  โœ…  FIFO-based IPC โ€” no shared memory exploits         โ”‚
โ”‚                                                         โ”‚
โ”‚  โš ๏ธ  Review scripts/ before granting execution perms   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โš™๏ธ Memory & Resource Strategy

Heisenberg enforces a 3 GB hard memory cap via sysinfo monitoring. When RAM pressure is detected, the orchestrator responds progressively:

Level 1 โ€” YELLOW  โ–ถ  Shrink inference context + reduce KV cache size
Level 2 โ€” ORANGE  โ–ถ  Lower concurrency โ†’ single-thread fallback for heavy ops
Level 3 โ€” RED     โ–ถ  Persist + compact long-term memory to PostgreSQL
Level 4 โ€” CRITICALโ–ถ  Drop nonessential buffers, disable expensive observers

Design philosophy: Stay responsive under pressure, never crash.


๐Ÿ”ง Extensibility

Add a new inference adaptor

src/the_lab/
โ”œโ”€โ”€ your_adaptor.rs    # Implement the InferenceAdaptor trait
โ””โ”€โ”€ mod.rs             # Register your adaptor

Preferred: FFI to llama-cpp. Fallback: isolated subprocess.

Add a new shell action

src/jesse/
โ”œโ”€โ”€ your_action.rs     # Define the action and its JSON schema
โ””โ”€โ”€ mod.rs             # Register via FIFO IPC

๐ŸŒ ุดุฑุญ TurboQuant ุจุงู„ุนุฑุจูŠุฉ

ู†ู‚ุทุฉ ุงู„ู‚ูˆุฉ ุงู„ุญู‚ูŠู‚ูŠุฉ ููŠ Heisenberg ู‡ูŠ ู‚ุฏุฑุฉ TurboQuant Planner ุนู„ู‰ ุชุดุบูŠู„ ู…ูˆุฏูŠู„ 9B ู…ุญู„ูŠู‹ุง ุจุฐุงูƒุฑุฉ 3 ุฌูŠุฌุงุจุงูŠุช ูู‚ุท.

ูƒูŠู ูŠุดุชุบู„ุŸ

  1. ุงู„ู…ุณุญ: ู†ู‚ุฑุฃ header ู…ู„ู ุงู„ู€ GGUF ูˆู†ุณุชุฎุฑุฌ ู…ูˆุงุตูุงุช ุงู„ู†ู…ูˆุฐุฌ (ุนุฏุฏ ุงู„ุทุจู‚ุงุชุŒ ุงู„ุฃุจุนุงุฏุŒ ุนุฏุฏ ุงู„ู€ heads)
  2. ุงู„ุชู‚ุฏูŠุฑ: ู†ุญุณุจ ุญุฌู… ุงู„ู€ KV cache ุงู„ู…ุทู„ูˆุจ ุจู†ุงุกู‹ ุนู„ู‰ ุทูˆู„ ุงู„ุณูŠุงู‚ ุงู„ู…ุทู„ูˆุจ
  3. ุงู„ุชุฎุทูŠุท: ู†ุฌู…ุน: KV cache + ุงู„ุฃูˆุฒุงู† ุงู„ู…ุญู…ู„ุฉ + overhead ุงู„ู†ุธุงู… ูˆู†ู‚ุงุฑู† ุจุงู„ุณู‚ู
  4. ุงู„ุชูƒูŠู‘ู: ู„ูˆ ุงู„ุชูˆู‚ุนุงุช ุชุฌุงูˆุฒุช 3GBุŒ ู†ู‚ู„ู‘ู„ ุฌูˆุฏุฉ ุงู„ู€ KV cache ุชู„ู‚ุงุฆูŠู‹ุง ุฃูˆ ู†ู‚ู„ู‘ุต ู†ุงูุฐุฉ ุงู„ุณูŠุงู‚
  5. ุงู„ุนุฒู„: ู†ุดุบู‘ู„ ุงู„ู€ inference ุฏุงุฎู„ cook.sh ู…ุน ulimit -v ู„ู…ู†ุน ุฃูŠ ุชุฌุงูˆุฒ ููŠ ุงู„ุฐุงูƒุฑุฉ

ุงู„ู†ุชูŠุฌุฉ: ุชู‚ุฏุฑ ุชุดุบู‘ู„ Qwen3.5-9B-Q4_K_M.gguf ุนู„ู‰ ุฌู‡ุงุฒ ุนุงุฏูŠ ุจุฏูˆู† ุณุญุงุจุŒ ุจุฏูˆู† ุฎุตูˆุตูŠุฉ ู…ูƒุดูˆูุฉุŒ ูˆุจุฃุฏุงุก ู…ุชุฏุฑุฌ ุจุฏู„ู‹ุง ู…ู† ุงู„ุงู†ู‡ูŠุงุฑ.


โ˜• Support Me

If Heisenberg helped you cook something great โ€” consider buying me a coffee.

Building and maintaining a production-grade local AI agent takes serious time and effort. If this project saved you hours of work or sparked something useful in your own projects, your support means the world.

Donate with PayPal

Every contribution โ€” big or small โ€” goes directly toward:

  • ๐Ÿ–ฅ๏ธ Better hardware for testing on constrained environments
  • ๐Ÿงช Experimenting with new GGUF models and quantization strategies
  • ๐Ÿ“š Documentation, tutorials, and community support
  • โšก Continued active development of new features

๐Ÿ“ฌ Contact

Have questions, ideas, or want to collaborate? Reach out!

Channel Info
๐Ÿ“ง Email ibrahimtarek1245@gmail.com
๐Ÿ“ฑ Phone / WhatsApp +201030553763
๐Ÿ™ GitHub at264939-ctrl/Heisenberg

Feel free to open an Issue or Discussion directly on GitHub for bugs, feature requests, or general feedback.


๐Ÿ“„ License

MIT License โ€” Copyright (c) Ibrahim Tarek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...

See the full LICENSE file for details.


Built with โค๏ธ and Rust by Ibrahim Tarek

"Say my name."

GitHub PayPal

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors