Table of Contents
Build a Mini Coding Agent in JavaScript
A tiny Node coding-agent harness, built one runnable stage at a time.
- Preface
- Before you start
- Part 0 The idea before the code
-
Phase A
A chatbot that talks
- Stage 0 Scaffold
- Stage 1 Terminal language (
ui.js) - Stage 2 Config and the model client
- Stage 3 The simplest chat loop
- Stage 4 Conversation history
- Stage 5 The system prompt
-
Phase B
Give the chatbot hands
- Stage 6 Path policy
- Stage 7 Read-only file tools
- Stage 8 Sandbox and write tools
- Stage 9 Command execution
-
Phase C
Memory and observability
- Stage 10 Long-term memory
- Stage 11 Lifecycle hooks
-
Phase D
The agent loop and polish
- Stage 12 The ReAct loop
- Stage 13 Offline demo
- Stage 14 Sessions, trimming and CLI polish
-
Phase E
Hardening and documentation
- Stage 15 The full test suite
- Stage 16 Documentation and final acceptance
-
Appendices
Protocol, safety, bounds, debugging, glossary and reading map
- A The message protocol
- B The safety model in one page
- C Every bound and cap
- D Debugging by symptom
- E Glossary
- F Reading the finished code
- Part II The teacher's handbook
- Part III The student workbook
- Part IV Deep dives on harness engineering
-
Part V
Reference
- A Configuration reference
- B CLI and exit-code reference
- C Tool response reference
- D Hook payload reference
- E File and API map
- F Final acceptance checklist
- G unction reference
- H Architecture Q&A
- About the author
Build order: each stage is a complete, runnable Node project. By Stage 3 the program is a chatbot; by Stage 12 it is a testable ReAct loop with tools, memory, hooks and a workspace sandbox.