Day 4 of 960 minCipher CadetHands-on lab
Day 4: Build a Task App with the Agent and Review Every Diff
Taught by Mr Elite Updated
By the end of today you can
- Write a prompt that gives the agent clear context, limits and a definition of done
- Build a frontend, API and database in small steps and run the app locally
- Read a multi-file diff and decide to accept, change or reject it
- Spot generated code that looks fine but should not be trusted
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
Name the three files that make up a spec and what each one answers.
requirements.md says what to build, design.md says how, tasks.md says the order of work.
What does an EARS line look like, and why does it help?
WHEN a trigger happens, THE SYSTEM SHALL give a result. Each line can be tested.
Imagine you type 'build me a task app' and thirty seconds later twelve files appear. It runs. You click around, it works, and you feel like a genius. Then someone asks what the code does with the text a user types into a task, and you have no idea. You never read it.
That gap, between code that runs and code you understand, is where most AI-assisted mistakes live. Today you build a real task manager with a frontend, an API and a database. The skill I care about is not typing the prompt. It is reading what comes back before you say yes.
Write prompts the agent can actually use
The agent only knows what you tell it and what it can see in your project. A vague prompt gets a confident guess. The agent fills every gap with its own assumptions, and you will not know which assumptions it made until you read the code. A good prompt gives context, a goal, limits and a way to tell when it is finished.
I use four parts. Context: what already exists. Goal: the one thing to build now. Limits: what to use and what to leave alone. Done: how we will check it. Keep each prompt to one layer of the app, so every diff stays small enough to read. A diff of forty lines you understand beats a diff of four hundred lines you skimmed.
Context: <what already exists in the folder>
Goal: <the one thing to build now>
Limits: <tools to use, things to avoid, security rules>
Done: <a check I can run myself>- Frontend
- The part in the browser that the user sees and clicks.
- API
- The set of web addresses the frontend calls to ask the backend to do things, such as list or create tasks.
- Database
- Where the data is stored so it survives a restart. We will use SQLite, a database that lives in a single file.
- Diff
- A view of exactly which lines were added, removed or changed in a file.
Notice that the Limits line is where security lives. If you do not say 'use parameterised queries', the agent may or may not. Asking costs you one sentence. Not asking can cost you a vulnerability you never see.
Quick check
Which prompt is best for the first step of the app?
It names context, goal, limits and a way to check, and it covers one layer only.
Watch me do it: the API and database first
We build from the bottom up: database and API first, then the frontend. Everything runs on your own machine. Nothing here touches any other system. You need Node.js LTS installed. Check it before you start.
node --version
npm --versionContext: this folder is empty. Goal: create a small task manager backend. Use Node.js, Express and SQLite (better-sqlite3). Add GET /tasks, POST /tasks and DELETE /tasks/:id. Store tasks in a file called tasks.db with columns id, title, done. Limits: use parameterised queries only, validate that title is a non-empty string under 200 characters, listen on 127.0.0.1 only, and do not add authentication yet. Done when I can create, list and delete a task with curl.curl -X POST http://127.0.0.1:3000/tasks -H "Content-Type: application/json" -d '{"title":"Buy milk"}'
curl http://127.0.0.1:3000/tasks{"id":1,"title":"Buy milk","done":0}
[{"id":1,"title":"Buy milk","done":0}]Now test the limit you asked for. Send an empty title and see that the API refuses it. Then delete the task and list again.
curl -X POST http://127.0.0.1:3000/tasks -H "Content-Type: application/json" -d '{"title":""}'
curl -X DELETE http://127.0.0.1:3000/tasks/1
curl http://127.0.0.1:3000/tasksIf the empty title was accepted, the validation you asked for is missing. That is a real finding. Tell the agent, 'The empty title was accepted. Add the validation I asked for', and read the new diff. Checking the limits you set is as important as reading the code.
Add the frontend and read multi-file diffs
Now the browser part. A frontend change usually touches several files at once: an HTML page, a script and maybe a stylesheet. A multi-file diff is easy to skim and hard to read well, so I go file by file and keep one question in mind: where does user input go?
Quick check
The agent's frontend diff also changes a file you never mentioned, package.json. What should you do?
Unexpected changes are exactly what a diff review is for. Read them and question them.
Spot generated code you should not trust
Generated code tends to be tidy, and tidy code feels trustworthy. It is not a signal. I scan every diff for a short list of warning signs.
- String-built SQL
- A query made by joining text with user input, such as "SELECT * FROM tasks WHERE id=" + id. This allows SQL injection. Safe code uses placeholders like ?.
- innerHTML with user data
- Puts text into the page as HTML, which can run attacker script.
- Hard-coded secrets
- Keys or passwords typed straight into code, which end up in Git.
- Open network binding
- Listening on 0.0.0.0 exposes the app to other machines on your network.
- Unknown packages
- A dependency you did not ask for, or one with a name that is slightly off. Check it exists and is well used before installing.
Here is what the difference looks like in a search route. The first version joins the search text into the SQL. The second passes it separately, so the database treats it as data and never as part of the command.
// Unsafe: input is joined into the SQL text
const rows = db.prepare("SELECT * FROM tasks WHERE title LIKE '%" + q + "%'").all();
// Safe: input travels separately through a placeholder
const rows = db.prepare('SELECT * FROM tasks WHERE title LIKE ?').all('%' + q + '%');Now try one safe experiment on your own app. Ask the agent: 'Add a search route, GET /tasks/search?q=, that finds tasks by title.' Before accepting, look at how the query is written. If you see the input joined into the SQL string, reject the diff and say: 'Use a parameterised query.' Then confirm the new diff uses a ? placeholder.
If the agent got it right the first time, good. You still did the work of checking, and that habit is what we are building. Write down what you looked for, because tomorrow we turn those checks into rules the agent follows automatically.
Lab: review the AI's pull request
You have now reviewed small diffs you asked for. The lab gives you a bigger one that someone else's agent wrote. It passes tests and looks neat. Five lines in it are dangerous. Your job is to find them using the warning list above.
Treat it as a real review. Give yourself a fixed time, keep a plain list of file name, line and reason, and resist reading only the files that sound important. Dangerous lines often sit in a helper or a config file. Hints are in the lab panel, and the answers are for you to find.
Your turn
Review the AI's Pull Request
A pull request is a proposed change that a human reviews before it joins the main code. This one was written by an AI agent and reads well, which is why reviewers approve these too quickly. It is the same skill as today's diff review, with higher stakes.
What to try
What to notice
- How much of the code is perfectly fine, and how that makes the bad lines easier to miss
- Whether passing tests told you anything about safety
- How the flaws sit next to ordinary code rather than standing out
If it did not work
Accepting all changes with one click because the app runs
Open each file's diff and read the added lines. Running proves it works, not that it is safe.
Asking for the whole app in one prompt
Build one layer at a time so each diff is short enough to understand.
Approving terminal commands without reading them
Read every command the agent wants to run. Be wary of anything that deletes files or installs packages you did not expect.
Binding the server to 0.0.0.0 for convenience
Keep 127.0.0.1 during development so only your machine can reach it.
Recap
- A good prompt has context, goal, limits and a definition of done
- Build in layers: database and API, then frontend
- Read every diff file by file and ask where user input goes
- Unexpected file changes deserve questions
- Tidy code is not trustworthy code; look for string-built SQL, innerHTML, secrets and open bindings
- Passing tests do not prove safety
Cheat sheet
node server.js- Starts the app from the project folder
curl http://127.0.0.1:3000/tasks- Lists tasks from your local API
127.0.0.1- Your own machine only, the safe default for development
? placeholder- Parameterised query, the safe way to put input into SQL
textContent- Shows text safely, unlike innerHTML
EADDRINUSE- The port is already taken, so stop the other program or pick a new port
Before the next day
Mission: Build, run and review the task app
Build the task app on your own machine, use it in the browser, and record what you decided about two diffs. The note is the real deliverable, because it proves you read the code and did not just accept it.
About 40 min
You are done when: A running task app plus a short note listing two inspected diffs and your decision on each.
Want more? Ask the agent to add the search route, find out whether it used a parameterised query, and describe in your note how you would have fixed it if it had not.
Quiz
4 questions. Your score is saved with your progress.
1. Why do we build the database and API before the frontend?
Small layered steps keep every diff readable and let you test each part before building on it.
2. The app runs and the tests pass. What does that tell you about its security?
Working code can still contain injection, unsafe output or exposed secrets that nothing tests.
3. Which line in a diff is the most worrying?
It joins user input into SQL text, which allows SQL injection. The others use safe patterns.
4. The agent edits a file you did not mention. What is the best response?
Surprise changes are a core reason for reviewing diffs before accepting.
Finish the day
Mark the day complete to save your progress.
Next: Tomorrow you create steering files so the agent follows your rules, such as parameterised queries and safe output, without you repeating them in every prompt. Today's review habits tell you which rules are worth writing down.
Your notes
Private to this device. Write what you want to remember from today.