Skip to content
Hands-on Coding Assistants

Part 4 — Build the Harness Chapter 16

Custom Agents & Sub-Agents

In this chapter

The implementation session has already spent time defending a patch. A new review session starts with the criterion and the changed line. Give it the spec, the tests, and a diff with a known base.

Give the reviewer a copy of the diff

Use a clean working tree and start from the review checkpoint.

git switch -c reviewer-exercise lab-review
mkdir -p .opencode/agents notes
git diff lab-registration lab-review -- src/app.ts > notes/review.patch

Read notes/review.patch yourself. The two refs put the intended change in the file even when the working tree is clean. Keep the patch with the base and head SHAs when you pass it to someone else.

Give the reviewer a different job

Create .opencode/agents/reviewer.md. OpenCode loads the Markdown body as the agent’s instructions. mode: all makes the agent available directly and as a child. The child can inherit your selected model and uses its own permission rules.

---
description: Reviews a known Task API diff against its spec and contract
mode: all
permissions:
  - action: "*"
    resource: "*"
    effect: deny
  - action: read
    resource: "specs/*"
    effect: allow
  - action: read
    resource: "contracts/*"
    effect: allow
  - action: read
    resource: "src/*"
    effect: allow
  - action: read
    resource: "test/*"
    effect: allow
  - action: read
    resource: "notes/review.patch"
    effect: allow
---

Read the named spec, the relevant contract, and notes/review.patch.
Cite the changed file and line for each finding. Give a request that
would demonstrate it, the expected result, and the result implied by
the code. Say which checks still need a human to run them.

The broad denial comes first. The later read rules grant the inputs this review needs. Run and inspect the shell checks yourself. The same repository can give Build more tools for a later task.

Run an independent pass

Open OpenCode from the repository root, choose reviewer with /agents, and send this request.

Read specs/registration-validation.md, contracts/registration.test.ts,
and notes/review.patch. Identify a request where this patch diverges
from the spec. Tell me how I can reproduce it using a fresh server.

Watch for actual reads of the requested files. In a separate session, ask the reviewer to try the shell tool with the exact command git status --short to exercise the boundary. The tool should be unavailable or the request should be denied. A prose refusal alone gives you weaker evidence. The setup files and patch are expected in the working tree. Confirm that the reviewer itself added no changes.

You can also open a fresh Build session and ask it to call reviewer with the same input. Check that the parent started a child and got a report. Build controls which children it can launch. Give the child the paths and task explicitly, since it starts with its own context. Keep one of the review findings and test it in the next chapter.

References