mrkeyoor.com_
Tue 01 Sept 17:44 UTC
AI Toolsevaluationupdated 26 Aug 2026

pi-from-scratch review

PI from Scratch is a Chinese-language TypeScript tutorial, and the repository does not include an English tutorial. It builds a small coding agent that can read, write, and edit files, run shell commands, stream model output, save sessions, and compress old context.

+31stars / 7d
Verdict

Our PI from Scratch run installed 54 packages in 11 seconds, then passed its 9-second build and 25-second test run. It is a good teaching project for a Chinese-reading TypeScript developer who wants to see the agent loop without framework layers. Do not treat nano-pi itself as a safe production assistant until you add argument validation, command isolation, an execution limit, and a fix for the reported persistence bug.

We ran it

Lab card: what happened when we ran pi-from-scratchScreenshot of pi-from-scratch (pi-from-scratch.vercel.app)
Install✓ · 11s54 packages · 65 MB
Build✓ · 9s
Tests✓ · 25sran, no count parsed
Known vulns00 critical · 0 high · 0 moderate · 0 low (npm audit)
Repo55 files~5,469 lines of source · 11.1 MB · 0 CI workflows · tests dir

Answers from our run

Does pi-from-scratch build from source?

Dependencies installed in 11 seconds (54 packages), and the build succeeded in 9 seconds. We cloned commit 599d0ba into a clean Debian container with 3 CPUs and no project-specific setup.

Do pi-from-scratch's tests pass?

The test command failed in our container, and its output did not report a pass or fail count.

Does pi-from-scratch have known vulnerabilities in its dependencies?

npm audit found none in the dependency tree at the time of our run.

Who should not use pi-from-scratch?

English-only readers: the README, two tutorial chapters, interface text, and most code comments are in Chinese, with no English tutorial in the repository.

What are the alternatives to pi-from-scratch?

pi, Aider, OpenHands. Our PI from Scratch run installed 54 packages in 11 seconds, then passed its 9-second build and 25-second test run.

Setup5/554 packages installed in 11 seconds; build and tests passed
Docs4/5Clear Chinese lessons and traces, but no English tutorial
Community3/51,132 stars with one focused open issue and no releases
Maturity2/5The code teaches core ideas and explicitly omits production guards

Who it’s for

Chinese-reading TypeScript developers who want to understand a coding agent by following its data flow.
Engineers who learn better from a small working implementation than from an SDK abstraction.
Teachers who want a browser lesson with source code, diagrams, and pre-generated execution traces.

Who it’s NOT for

English-only readers: the README, two tutorial chapters, interface text, and most code comments are in Chinese, with no English tutorial in the repository.
Teams seeking a production coding agent: the source says tool arguments are not validated before execution and that the teaching version omits a hard step limit.
Anyone who needs a safely isolated shell: run_bash executes the model-provided command through the host shell, without a project sandbox described in the README.
Users relying on long-session persistence: issue 6 reports that message-count-based appending can miss new messages after context compression shrinks the in-memory history.

Setup reality

Our sandbox install succeeded in 11 seconds, adding 54 npm packages and using 65 MB. The TypeScript build passed in 9 seconds, and all available tests passed in 25 seconds. Npm audit reported 0 known vulnerabilities.

Running nano-pi needs Node.js 22 or newer plus an OpenAI-compatible API key. The model and base URL are configurable; the default base URL is OpenAI. Browsing the hosted trace lesson does not make model requests because its traces are pre-generated.

The agent can overwrite files and execute shell commands. Its educational implementation does not validate tool arguments and has no hard step limit. The separate teaching website has its own install and development command, and the repository has no CI workflow or Dockerfile.

A 55-file repository explains the agent loop in Chinese

The 55-file PI from Scratch repository is both an article and a working TypeScript program. The primary material is Chinese, including the README, 2 tutorial chapters, web interface, and most source comments. There is no English tutorial in the checkout. The author strips the upstream pi design down to its data flow: a model streams text or tool calls, the agent executes tools, results return to context, and the loop continues until the model stops.

That small scope makes the project readable. The checkout has about 5,469 lines of source, including a Next.js lesson site, diagrams, tests, and pre-generated traces. Source appears beside the article and fills in as the reader advances. A trace debugger lets readers pause and follow execution. The hosted lesson uses static trace data, so opening it does not spend API credit or send prompts to a model provider.

Four tools can change files and execute host commands

The 55-file repository registers read_file, write_file, edit, and run_bash as its 4 built-in tools. The edit tool requires its old string to match exactly once, which prevents an ambiguous replacement. Long command or file output keeps the last 200 lines and stores the full text in a temporary file. These are sensible teaching choices because each behavior stays visible in a short function.

They are not a security boundary. The source comments say the teaching version passes tool arguments to execute without validating them against the declared JSON schema. write_file overwrites its target, and run_bash sends the requested command to the host shell with a 30-second timeout. The README does not describe a filesystem jail, command allowlist, or container runtime. Run it only in a directory and account whose contents you can afford to change.

What happened when we ran it

Our sandbox installed 54 npm packages in 11 seconds and used 65 MB on disk. The TypeScript build succeeded in 9 seconds. The test command also succeeded, finishing in 25 seconds, and npm audit found 0 known vulnerabilities across the installed dependency set. That is a clean result for commit 599d0ba in our unprivileged Debian container.

The repository itself was 11.1 MB checked out, even though its source count was only about 5,469 lines. It had a tests directory but no GitHub Actions workflow and no Dockerfile. A passing local suite is useful evidence for the code we cloned; the absence of repository CI means a reader cannot point to an automated workflow in this checkout that repeats those checks on every proposed change.

Our measurement setup had 3 CPUs, 8 GB of RAM, Node.js 22, and no secrets. We did not make a live model call because the container had no API credentials. The tests therefore establish that the implemented modules behave as asserted, while they do not rate model output, tool selection, or the safety of commands a live model might request.

Node.js 22 and one API key start the terminal agent

Node.js 22 or newer, NANOPI_API_KEY, and the development command are enough for the local path. NANOPI_MODEL selects the model, while NANOPI_BASE_URL points at an OpenAI-compatible chat-completions service and defaults to OpenAI. The root package has no runtime dependencies, only development packages for TypeScript execution, compilation, Node types, and Vitest.

The web lesson is a separate application under web, with its own package install and development server. That split is appropriate because someone reading traces does not need to run nano-pi or hold an API key. There is no published GitHub release. Anyone embedding the code should pin commit 599d0ba or another reviewed commit rather than expecting a tagged compatibility promise.

Context compression teaches the idea and exposes a bug

At 50 messages, the agent asks the model to summarize older history, replaces it with one summary, and retains the latest 20 messages. This makes the context-management idea easy to inspect. The source explains that upstream pi uses far more code for token estimation, safe cut points, and turns that cross boundaries, while nano-pi deliberately uses message count as a rough substitute.

Issue 6 identifies a consequence in session persistence. The file writer decides what to append by comparing the stored message count with the current in-memory count. After compaction reduces 51 messages to 31, a newly added message can still leave the current count below the stored count, so it is not appended. That report is directly about nano-pi's persistence path. Long sessions need a fix before their history can be trusted.

Abort handling is careful, while execution has no step cap

The Node.js 22 agent preserves message structure when a user presses Ctrl+C. If interruption happens before tools run, it drops unfinished tool calls. If some calls already ran, it adds error results for the skipped calls so every call still has a paired result. A response cut off by the model's token limit is also handled conservatively: incomplete tool arguments are not executed, and an error goes back into context for another turn.

The teaching version executes multiple tool calls in sequence and has no hard maximum number of agent steps. Its own comment contrasts that with an omitted upstream stop callback. Combined with unrestricted shell execution, that omission matters more in unattended use than it does during a guided lesson. The project was last pushed on August 18, 2026, had 1,132 stars, and showed 1 open issue and pull request when fetched. It is active teaching code, not a packaged production agent.

Alternatives

ProjectWhat it isPick it when
pi gh↗The fuller coding-agent project whose data flow this tutorial simplifies.pick this instead when you want the upstream implementation and its engineering detail rather than a teaching-sized rewrite.
Aider gh↗A terminal coding assistant built for editing real repositories with model support.pick this instead when your goal is daily coding work rather than learning how an agent loop is assembled.
OpenHands gh↗A larger platform for software-development agents with an isolated runtime path.pick this instead when you need a deployable agent system and accept far more machinery.

What people are saying

  1. [velocity-scout] SaladDay/pi-from-scratch

Sources

  1. PI from Scratch README
  2. Agent loop source
  3. Built-in tools source
  4. Session persistence issue

More ai tools reviews

claudian · SkillSpector · robin · mjlab · MoGe · awesome-design-md · the whole board →