Skip to content

phuoctrung-ppt/coding-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coding Agent

A local AI coding assistant powered by Ollama, built with TypeScript. Supports agentic workflows — reads files, writes code, runs commands, and iterates until the task is done.

Features

  • Agentic loop — model autonomously calls tools until task is complete
  • 6 built-in toolsread_file, write_file, str_replace, delete_file, list_dir, run_command, search_code
  • Safety guards — path traversal protection, readonly file guard, dangerous command blocking, file size limit
  • Diff view — shows changes before applying, requires confirmation for destructive operations
  • Streaming output — token-by-token display as model thinks
  • Slash commands/reset, /history, /help, /exit
  • Fully local — no API keys, no internet required after model download

Stack

  • Runtime: Node.js 20+ with TypeScript
  • LLM: Ollama (llama3.1:8b or qwen2.5-coder:7b)
  • CLI: Chalk, Ora, Inquirer, Commander

Prerequisites

Setup

# Clone the repo
git clone https://github.com/phuoctrung-ppt/coding-agent
cd coding-agent

# Install dependencies
npm install

# Pull the model
ollama pull llama3.1:8b
ollama pull nomic-embed-text

# Create your model with system prompt
ollama create fullstack-dev -f Modelfile

# Copy and configure environment
cp .env.example .env

Edit .env:

OLLAMA_MODEL=fullstack-dev
PROJECT_DIR=./path/to/your/project   # point to the codebase you want to work with

Usage

npm run dev
You: list all files in src and explain the project structure
You: add a soft delete method to UserService
You: find all places where any type is used and fix them

How it works

The agent follows a simple loop:

  1. User sends a message
  2. Model decides: respond with text, or call a tool
  3. If tool call → agent executes it and feeds result back to model
  4. Loop repeats until model returns plain text (task done)

This is the same pattern used by Claude Code, Cursor, and most AI coding assistants — the difference is the underlying model.

Upgrading to a stronger model

The agent uses the OpenAI-compatible API format. To use a more capable model, update OLLAMA_MODEL in .env or swap the Ollama client for the Anthropic/OpenAI SDK — no other code changes needed.

Project structure

src/
├── agent/
│   ├── core.ts       # agentic loop + tool routing
│   ├── tools.ts      # file and shell tool implementations
│   └── guards.ts     # safety checks for all tool calls
├── cli/
│   └── app.ts        # terminal interface, streaming, diff view
├── config/
│   └── settings.ts   # environment config
└── index.ts          # entry point

License

MIT

About

Local AI coding assistant built with TypeScript + Ollama. Agentic loop with file R/W, shell execution, safety guards, and diff view — runs 100% offline.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors