Leanpub Header

Skip to main content

Build a Mini Coding Agent Harness in JavaScript

A tiny Node coding-agent harness, built one runnable stage at a time

Build a Mini Coding Agent Harness in JavaScript

Build a coding agent the way you actually learn: one runnable stage at a time. You will start with a chatbot at Stage 3, give it file tools, memory and lifecycle hooks, then turn the whole thing into a testable ReAct loop — with no framework, no agent SDK and one runtime dependency. By the end you will own a small Node.js coding-agent harness you can explain, test and extend.

Minimum price

$2.99

$4.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

A tiny Node coding-agent harness built one runnable stage at a time.

Most coding-agent books start with the sandbox. They teach you to build the container, the permission model and the tool registry before the program ever says a word. It makes a tidy diagram and a slow lesson — you wait hours before anything talks.

This book does the opposite.

  • By Stage 3 you have a chatbot.
  • By Stage 7 it can read your files.
  • By Stage 9 it can run commands.
  • By Stage 12 it has a real ReAct loop, and by the end it has nine tools, a workspace sandbox, persistent memory, nine lifecycle hooks, an offline demo and a test suite.

Why start with a chatbot?

Because every stage should feel like a superpower, and because you should meet the failure modes in the order a real user does:

- A bad key is a Stage 2 problem.

- A model that forgets the previous turn is a Stage 4 problem.

- A model that writes the wrong file is a Stage 8 problem.

- A command that hangs is a Stage 9 problem.

- A model that loops forever is a Stage 12 problem.

Build the loop first and you hide all of them behind a harness you do not yet understand.

What you get

- **17 stages**, each a complete, runnable Node project

- **9 tools**: list, read, create, write, edit, delete, run commands, remember, recall

- **9 lifecycle hooks** that can observe, rewrite or block a run

- A workspace sandbox that refuses escapes — including symlinks and shell commands

- A testable ReAct loop with step limits and a truncation guard

- An **offline demo** that proves the safety guards with no API key

- An offline test suite and a 20-item acceptance checklist

- A **185-question architecture Q&A** and a function-by-function code reference

- Teacher material: run sheets, a live-demo script, the factory analogy, misconceptions and a rubric

What it deliberately is not

No framework. No agent SDK. No database. One runtime dependency (`chalk`). And no false claims: the sandbox is a teaching policy, not a security boundary — the book says so repeatedly, because overclaiming safety is worse than naming its limits.

Who it is for

Developers who can read modern JavaScript — modules, `async`/`await`, `fetch`, classes. You do not need to have built an agent before. Bring Node.js 20+ and a terminal. The live chapters use an OpenRouter key; the tests and the demo need none.

The promise

By the last page, every coding agent you meet will look like a variation on a program you can read. You will recognise the loop, the tools, the context budget, the safety layers and the extension points — and you will know exactly where the design stops being safe.

Share this book

Author

About the Author

Contents

Table of Contents

Build a Mini Coding Agent in JavaScript — Table of Contents

Table of Contents

Build a Mini Coding Agent in JavaScript

A tiny Node coding-agent harness, built one runnable stage at a time.

By Craig West · 17 runnable stages · 9 tools · 9 lifecycle hooks · 1 runtime dependency

  1. Preface
  2. Before you start
  3. Part 0 The idea before the code
  4. Phase A A chatbot that talks
    1. Stage 0 Scaffold
    2. Stage 1 Terminal language (ui.js)
    3. Stage 2 Config and the model client
    4. Stage 3 The simplest chat loop
    5. Stage 4 Conversation history
    6. Stage 5 The system prompt
  5. Phase B Give the chatbot hands
    1. Stage 6 Path policy
    2. Stage 7 Read-only file tools
    3. Stage 8 Sandbox and write tools
    4. Stage 9 Command execution
  6. Phase C Memory and observability
    1. Stage 10 Long-term memory
    2. Stage 11 Lifecycle hooks
  7. Phase D The agent loop and polish
    1. Stage 12 The ReAct loop
    2. Stage 13 Offline demo
    3. Stage 14 Sessions, trimming and CLI polish
  8. Phase E Hardening and documentation
    1. Stage 15 The full test suite
    2. Stage 16 Documentation and final acceptance
  9. Appendices Protocol, safety, bounds, debugging, glossary and reading map
    1. A The message protocol
    2. B The safety model in one page
    3. C Every bound and cap
    4. D Debugging by symptom
    5. E Glossary
    6. F Reading the finished code
  10. Part II The teacher's handbook
  11. Part III The student workbook
  12. Part IV Deep dives on harness engineering
  13. Part V Reference
    1. A Configuration reference
    2. B CLI and exit-code reference
    3. C Tool response reference
    4. D Hook payload reference
    5. E File and API map
    6. F Final acceptance checklist
    7. G unction reference
    8. H Architecture Q&A
  14. 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.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub