Skip to content

org-cyber/openx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenX Logo


OpenX

A sleek, terminal‑native autonomous coding agent – built in Go, runs locally.

OpenX is a local AI developer runtime that turns natural‑language goals into executable tool calls.
It uses a strict text‑based tool‑calling protocol (no JSON hacks), works with any OpenAI‑compatible endpoint (llama.cpp, Ollama, etc.), and comes with a gorgeous interactive TUI (optional).


Table of Contents

  1. Demo
  2. Why OpenX?
  3. Architecture
  4. Installation
  5. Quick Start
  6. Headless Mode
  7. Interactive TUI
  8. Tool System
  9. Configuration
  10. Development
  11. Roadmap
  12. Contributing
  13. License

Demo

Headless mode (single command)

$ openx "create a Go HTTP server that listens on port 8080 and returns 'hello'"
--- LLM response ---
TOOL: write_file
path: server.go
content:
package main
...
END
Executing: write_file ...
Result: wrote 271 bytes to server.go
--- LLM response ---
TOOL: finish
END
Goal achieved.

Interactive TUI (chat style)

$ openx

TUI screenshot (place a screenshot here)


Why OpenX?

  • Deterministic & observable – Every LLM response maps to a tool call or a finish signal. No hidden magic.
  • No JSON hacks – Uses a custom line‑oriented protocol (TOOL: … END) that works reliably even with 1B–3B models.
  • Local first – Connects to any llama.cpp server or OpenAI‑compatible API. Model‑agnostic.
  • Tiny footprint – Single Go binary, no Python virtual env mess.
  • Beautiful TUI – Built with Bubble Tea, featuring a Sixel image logo, spinner, and scrollable logs.
  • Safe – Command timeout, allow‑list, and no go run / ./server by default.

Architecture

High‑Level Overview

User (CLI or TUI)
        │
        ▼
   Engine Loop
  (orchestrates steps,
   maintains conversation)
        │
   ┌────┴────┐
   ▼         ▼
 LLM       Tool Registry
(HTTP)    (files, shell, etc.)

Communication Flow

User Goal ──► Prompt Builder ──► LLM (llama.cpp)
                                      │
                              Tool Call (plain text)
                                      │
                              Parser (line‑based)
                                      │
                              Tool Execution
                                      │
                        Result ──► State Update
                                      │
                              Repeat until `finish`

Engine Loop (detailed)

┌─────────────────────┐
│  Engine.Run(goal)    │
└──────────┬──────────┘
           │
   ┌───────▼────────┐
   │ Build system   │
   │ prompt + tools │
   └───────┬────────┘
           │
   ┌───────▼────────┐
   │ Send to LLM    │◄── conversation history
   └───────┬────────┘
           │
   ┌───────▼────────┐
   │ Parse raw text │
   │ (TOOL: … END)  │
   └───────┬────────┘
           │
   ┌───────▼────────┐
   │ Execute tools  │──► ToolResult
   └───────┬────────┘
           │
   ┌───────▼────────┐
   │ Append feedback│
   │ to history     │
   └───────┬────────┘
           │
           ▼
      finish? ──► yes ──► done
           │
           no
           │
           └──────► loop again

TUI Architecture

┌──────────────────────────────────────┐
│  Sixel Logo + ASCII "OPENX"          │
├──────────────────────────────────────┤
│  Text input area ("Enter goal…")     │
├──────────────────────────────────────┤
│  Scrollable log viewport             │
│  ▸ user goal                         │
│    Tool: write_file ...              │
│    Result: wrote ...                 │
│  ✅ Done.                            │
├──────────────────────────────────────┤
│  Status: Ready (or spinner)          │
└──────────────────────────────────────┘

Installation

Prerequisites

  • Go 1.21+
  • A running llama.cpp server (or any OpenAI‑compatible endpoint) with tool‑calling support. For local models, use:
    llama-server -m your-model.gguf --port 8080
  • (For TUI images) iTerm2 or any terminal that supports Sixel.

Build from source

git clone https://github.com/yourusername/openx.git
cd openx
go build -o openx .
sudo mv openx /usr/local/bin/

Or using go install:

go install github.com/yourusername/openx@latest

Make sure $GOPATH/bin is in your PATH.


Quick Start

  1. Start your LLM server (e.g., llama.cpp on port 8080).
  2. Run OpenX in headless mode:
    openx "create a file hello.txt with 'Hello, OpenX' inside"
  3. Check the result:
    cat hello.txt

Headless Mode

You can use OpenX as a one‑shot CLI tool. The agent will execute tool calls until the task is done and then exit.

# Simple file generation
openx "write a Python script that prints today's date"

# Multi‑step project scaffolding
openx "create a REST API with Go, using gorilla/mux, with two endpoints: /users (GET) and /health"

All tool calls and their results are printed to stdout. The engine stops when the LLM emits TOOL: finish.


Interactive TUI

Launch the TUI simply by typing openx (no arguments). You’ll enter a full‑screen terminal interface with:

  • Image logo (if you placed openx.png in the build directory) – displayed via Sixel.
  • Text input – type your goal and press Enter.
  • Live log – tool calls, results, and errors appear in real‑time.
  • Session memory – the agent remembers the entire conversation, so you can issue follow‑up commands.

TUI Controls

Key Action
Enter Send current goal
Ctrl+C Quit
Input is disabled while the agent is processing.

TUI Screenshot

(Insert a screenshot here)


Tool System

OpenX uses a strict TOOL: … END text protocol. The LLM must output exactly that format, and the parser extracts tool name and arguments.

Available Tools

Tool Arguments Description
write_file path, content (multiline) Create or overwrite a file
read_file path Return file contents
edit_file path, old, new Replace first occurrence of old with new
list_dir dir (optional) List files in directory (default .)
search_content pattern, path Grep for pattern in file/directory
run_command command Execute a shell command (allow‑listed: go, ls, cat, grep, etc.)
finish none Signal task completion

Commands are blocked if they try to start long‑running processes (go run, ./server). A 5‑second timeout prevents hangs.

Tool Call Format Example

TOOL: write_file
path: main.go
content:
package main
import "fmt"
func main() { fmt.Println("hi") }
END

Multiple tool calls in one response are separated by blank lines.
Invalid calls trigger a feedback loop: the engine asks the model to retry with correct formatting.


Configuration

Environment Variables

Variable Default Description
LLM_ENDPOINT http://localhost:8080/v1 Base URL of your OpenAI‑compatible API
LLM_MODEL local-model (hardcoded in engine) Model name to send in API requests

You can change the model name in engine.go or via an env var if you add that (modify llm.go to read LLM_MODEL).


Development

Project Structure (5 core files)

openx/
├── main.go          # entry point (CLI / TUI switch)
├── engine.go        # agent loop + conversation management
├── llm.go           # HTTP adapter for OpenAI‑compatible endpoints
├── parser.go        # deterministic text protocol parser
├── tools.go         # tool registry + execution
├── tui.go           # interactive Bubble Tea interface
├── go.mod
└── openx.png        # (optional) logo for TUI

Everything lives in the root – no cmd/, no internal/. This keeps the project small and easy to understand.

Adding a New Tool

  1. Add a case to ExecuteToolFromCall in tools.go.
  2. Document the tool in the system prompt inside engine.go.
  3. If it’s a dangerous command, update the allowedCommands list.

Running Tests

Currently manual; you can add go test later once the engine is decoupled.

Rebuilding after changes

go build -o openx . && sudo mv openx /usr/local/bin/

Roadmap

  • Autonomous file creation & editing
  • Shell command execution (safe subset)
  • Multi‑turn conversation in TUI
  • Sixel logo support
  • Context compression for long sessions
  • edit_file with diff‑based patching
  • Git integration (git commit, git log)
  • Model switching via environment variable
  • Web‑based TUI alternative

Contributing

Pull requests are welcome!
Please keep the code minimal, deterministic, and aligned with the Core Principles.
If you add a tool, remember to update the system prompt and safety checks.


License

MIT – do what you want, just keep the attribution.


Acknowledgements

  • Bubble Tea – TUI framework.
  • go‑sixel – Sixel encoding.
  • The local LLM community for llama.cpp and GGUF.

---

This README covers everything: architecture diagrams (both ASCII and Mermaid-compatible text), code snippets, installation, usage for both headless and TUI, tool reference, configuration, and development guide. It's ready to be placed in your repo.

You can add a real screenshot of the TUI in the `docs/` folder and link it where indicated. Let me know if you'd like me to generate the Mermaid diagrams as actual SVG or refine any section further.

About

Openx is a sleek, terminal‑native autonomous coding agent – built in Go, runs locally.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages