Write a Finishable Task

Your docs/tasks.md lists the unreachable-puzzle report as a few small tasks, and task 1 is ready to hand to your agent. That one line works as a reminder for you, because you know the brief, the plan, and why the task exists. Your agent starts a session with none of that.

In this lesson, you’ll write task 1 as a message your agent can finish: what you want and why, where to look, the limits, and how you’ll both know it’s done. You’ll run it on your project, compare what comes back with what a one-line request might have produced, and commit the result. Start with what the line in your task list leaves open.

Find What a Task Leaves Open

Before you write a longer task, find the gaps it has to fill. Your agent works only from what’s in its session and the files it reads, so anything you know but haven’t written down never reaches it.

Here’s task 1 as the reference version’s docs/tasks.md states it:

Language: Markdown Text Filename: docs/tasks.md
- [ ] 1. The checker returns the ids of the puzzles no
  path reaches.
  Check: npm test, with a test on both sample rooms.

Say you pasted that line into your agent as the whole task. Write down three things your agent would have to decide that the line doesn’t settle, and whether you expect it to ask you about each one. Then open the list:

These are the main decisions in the reference version. Your project may have more:

  • Where the code goes: A new function next to checkRoom(), or a change to checkRoom() so that it returns ids instead of its verdict. The command and the first test both use checkRoom(), so changing what it returns breaks them unless the agent edits them too.
  • What “no path reaches” means: The brief defines it, but the line doesn’t point there. In The Smuggler’s Cellar, the trapdoor needs a code from the strongbox, so it’s stuck only because the strongbox is. A quick reading leads the agent to report the strongbox alone.
  • What comes back: The line already settles ids, so returning names would go against it. It doesn’t settle the order or what to return for a room that can be finished, such as an empty array or null.
  • The check: Which test file, which rooms, and whether new test rooms are allowed.
  • Where to stop: Printing the names is task 2. But “report the unreachable puzzles” is a common reading of this line, and the command is right there, so the agent may print them too.

Your agent may ask you about one or two of these.

Watch out: An agent often picks a plausible reading of each gap and reports the task as done instead of stopping to ask, so you find its choices later, in the diff. Ask an agent for “a difficulty score” for a room and nothing else, and it may well come back with a scale and a formula it chose, reported as finished.

Some of these gaps are already closed by your project’s files. The brief defines “can be finished”, and your instruction file may say never to change a room file. Others live only in your head, such as the fact that task 2 owns the output or that checkRoom() must keep returning its verdict. Those are the ones to state, because nothing the agent reads says them.

Your own line may word task 1 differently, and your files settle different things. Paste your task 1 line, your instruction file, and your brief, and ask which gaps they leave:

Write the Parts of a Task

Each gap you found needs an answer the agent can use, and a task gives those answers in a few parts. The reference version’s task 1 is below, written for the course’s project. It’s an example of what each part does. Your files, function names, and wording will differ, so don’t copy it as a template.

The first part is the goal, the behavior you want and why, followed by where to look:

Language: Text
Task 1 from docs/tasks.md: the checker returns the ids
of the puzzles a team can never reach. Task 2 will
print their names, so this task returns ids only.

Read docs/brief.md for what "can be finished" means,
then src/check-room.js and test/check-room.test.js.

The reason in “Task 2 will print their names” tells the agent why ids are enough and where its work ends. The second paragraph points at exact files, so the agent doesn’t decide for itself which code matters.

Next, the task says what the result looks like, with examples instead of adjectives:

Language: Text
Add an exported function to src/check-room.js that
takes a room and returns the ids of the puzzles no
path reaches, in the room's order:
- rooms/lighthouse-keepers-study.json gives [].
- rooms/the-smugglers-cellar.json gives
  ["strongbox", "trapdoor"]. The strongbox needs the
  iron key, which nothing unlocks, and the trapdoor
  needs the code inside the strongbox.

Words such as “correct” or “robust” leave the agent to decide what they mean. An example settles the meaning, because it says that this room gives this array. The first example says what to return for a room that can be finished, and the second settles the trapdoor question from the list above.

Then come the limits. Constraints shape how the agent works, and the files not to touch fence off parts of the project:

Language: Text
Keep checkRoom() and what it returns as they are:
check-room.js and the first test use it. Add no new
dependencies. Don't change check-room.js or its
output, the files in rooms/ or test/rooms/, or
docs/tasks.md.

Each line states something the agent couldn’t tell from the code alone. checkRoom() is the checker’s public interface, so other files depend on it. The command’s output belongs to task 2, the room files belong to the designers, and you tick off docs/tasks.md yourself. “Add no new dependencies” stops the agent from adding packages to package.json.

Last comes done when, a check the agent can run itself, plus what you’ll check:

Language: Text
Done when a new test in test/check-room.test.js
checks both sample rooms and npm test passes, with
the first test unchanged. Then stop and list the
files you changed. I'll read the diff and commit.

The agent can run npm test, read a failure message, and edit again, so the task ends at a result both of you can see. Without that check, the agent decides for itself when it’s finished. “Then stop” tells it where its job ends. A later lesson sets up these checks so your agent runs them without asking first. That’s all you need to know for now.

This task is long because so much was open. A task’s length follows what it leaves open, so a fix to one line in a named file may need one sentence.

When something is open that you can’t settle yourself, ask for questions instead of letting the agent guess. End the task with “Before changing anything, list what’s unclear and the assumption you’d make for each, then wait for my answers.” The agent may still go ahead, and if it does, the diff shows it.

Run Your Task and Compare

You learn how good a task is from what comes back, so write your own and run it. Draft task 1 in your editor, in a new file you don’t save inside the project, with your own file and function names. Give it a goal and the reason for it, where to look, at least one example, the constraints, what not to touch, and a “done when” condition with a command your agent can run.

Before you send it, get a second opinion on the gaps that are left:

Decide which of the gaps Code Mentor names matter for this task, and close each in your draft with a requirement, an example, or a question before you send it.

Run git status and check that it shows nothing to commit apart from your agent’s settings folder, so the agent’s changes will be the only ones. Then start a new agent session in your project folder, so nothing from earlier work is in its context. Paste your task, send it, and answer its approval requests as usual.

When the agent says it’s done, look at what changed rather than at its summary. Run these in your project folder:

Language: Shell
$ git status
$ git diff HEAD
$ npm test

git status lists every file the agent changed or added. git diff HEAD shows the changes since your last commit, including any the agent staged, but not files git status marks as untracked: open those in your editor. npm test lets you run the tests yourself.

In the diff, each changed file starts with a heading such as diff --git a/check-room.js b/check-room.js. Under it, lines starting with - are what your last commit had, lines starting with + replaced or joined them, and unmarked lines are unchanged context.

The command is check-room.js at the top of your project, and the checker is src/check-room.js. If the command’s heading has + lines that print puzzle names, then task 2’s work arrived early. For more on reading a diff, Track Your Project With Git goes further than this course.

Your session will differ from anyone else’s. Here’s what a one-line version of this task might have produced. Look for these outcomes in your own diff:

  • checkRoom() returns something new, and the command or the first test changed to match.
  • The command already prints the names, which is task 2’s work.
  • The checker reports the strongbox but not the trapdoor in The Smuggler’s Cellar.
  • A test covers one sample room only, or new rooms appeared in test/rooms/.
  • The new test expects what the code returns, such as ["strongbox"], not your examples’ arrays, so it passes anyway. Open it and compare.
  • package.json names a package you didn’t ask for.

You may find none of these, or you may find one even after a careful task. A task says what you want, but it can’t enforce it. If the agent changed a file that your task fenced off, run git restore --source=HEAD --staged --worktree -- and the file’s name. It puts the file back as your last commit had it, staged changes included. Delete any new file the agent shouldn’t have added, then give it a short follow-up that names the limit it crossed.

Then paste your task, the agent’s final message, your git diff HEAD, and any untracked files, and compare what you asked for with what you got:

For each choice Code Mentor names, decide whether you can accept it. If not, send your agent a follow-up that settles it, then check again that every changed file belongs to the task and rerun npm test. A later lesson turns this check into a full review.

Tick task 1 off in docs/tasks.md, so its box reads - [x]. Then commit the change and the tick together, with the filenames your git status showed:

Language: Shell
$ git add src/check-room.js test/check-room.test.js docs/tasks.md
$ git commit -m "Return the ids of unreachable puzzles"

Run git status once more. Apart from your agent’s settings folder, it should show nothing to commit.

Check Your Understanding

Answer these before you open the answers:

  1. A task for the escape-room builder says: “Make the command handle bad room files properly.” Name three things it leaves your agent to guess, and rewrite it so each guess becomes a stated requirement, an example, or a question.
  2. A friend starts a new agent session and sends: “Print the stuck puzzles in the format from yesterday.” What does the agent have to work from, and what would you change?
  3. Your agent finishes a short task without asking a single question. Does that show the task was clear enough? How could you get its questions before it changes anything?
  1. Any three of these: which bad files it means (a missing file, invalid JSON, a puzzle without needs), what “properly” means, which files to change, and how to check it. One rewrite: “When check-room.js gets a path that doesn’t exist, it prints No room file at <path>. instead of an error. Change only check-room.js. Done when npm start -- rooms/missing.json prints that line and npm test passes.” For what you can’t settle yet, such as invalid JSON, ask for the agent’s questions, as in answer 3.
  2. Only the message and the files it reads. Yesterday’s conversation was in another session, so it never reaches this one. Give the actual output you want, such as a line after the “cannot be finished” verdict that names each stuck puzzle, and name the file that prints it.
  3. No. An agent often picks a plausible reading of each gap and carries on, so a task with no questions can still hold choices you didn’t make, and you find them in the diff. To get questions first, ask for them and for a pause: end the task with “Before changing anything, list what’s unclear and the assumption you’d make for each, then wait for my answers.”

Task 1 is committed and ticked off, and you’ve seen what writing it out settled that the one-line version left to your agent. Next, in Exercise: Fill the Gaps in a Task, you’ll get a vague task for the escape-room builder and the team’s standing rules. You’ll list what it leaves an agent to decide, then fill in each part of a better task. The exercise runs in your browser, with no agent involved.

Become a Member to join the conversation.