GitHub

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

  1. 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.
  2. 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

ToolWhat it does
read_file_toolRead a file's contents
write_file_toolCreate/overwrite a file
edit_file_toolReplace text in an existing file (oldText → newText edits)
bash_func_toolRun a shell command (30s timeout)
deploy_html_fileServe a static site via http-server on localhost:8080

Runtime

  • Runs on Bun v1.3+ with a single GEMINI_API_KEY env var — no other setup.