Terminal AI Coding Agent (pi-self)
- TypeScript
- Bun
- Gemini
- React
- OpenTUI
Demo
Overview
A tiny AI coding agent that runs in your terminal. Type what you want to build, and it reads files, writes files, and runs shell commands until the task is done — powered by Gemini, rendered with a React-based TUI.
Highlights
- Live streaming: the TUI spawns the agent as a subprocess per prompt and streams its stdout into a scrolling log as tokens arrive.
- Real tools: read, write, edit (oldText → newText), bash (30s timeout), and a static-site deploy tool that serves a preview on localhost:8080.
- Headless mode: run one-shot prompts directly with
bun src/services/ai-agent.ts "your prompt here".
Architecture
Structure
┌─────────────────────────────┐
│ Terminal UI (OpenTUI) │ src/index.tsx
│ input box + scrolling log │
└──────────────┬──────────────┘
│ spawns per prompt, streams stdout live
┌──────────────▼──────────────┐
│ Agent loop (Gemini) │ src/services/ai-agent.ts
│ streams text ⇄ tool calls │
│ until no more calls │
└──────────────┬──────────────┘
│
┌─────┬─────┼──────┬───────┐
▼ ▼ ▼ ▼ ▼
read write edit bash deploy src/tools/
Flow
- The TUI (
src/index.tsx, OpenTUI + React) takes the prompt and spawns the agent as a subprocess, streaming its stdout into the scrollbox live as tokens arrive. - The agent (
src/services/ai-agent.ts) sends the prompt to Gemini with tool definitions, streams the model's text, executes any tool calls, feeds results back, and loops until the model stops calling tools.
Tools
| Tool | What it does |
|---|---|
read_file_tool | Read a file's contents |
write_file_tool | Create/overwrite a file |
edit_file_tool | Replace text in an existing file (oldText → newText edits) |
bash_func_tool | Run a shell command (30s timeout) |
deploy_html_file | Serve a static site via http-server on localhost:8080 |
Runtime
- Runs on Bun v1.3+ with a single
GEMINI_API_KEYenv var — no other setup.