regent-build
Consume a REgent spec tree and produce runnable code that satisfies the spec's
R-/S- requirements, every line of functional-checklist.md, AND every
entry of inventory/test-oracle.md. The oracle is the second, white-box
grading key — it pins per-function invariants that a black-box checklist
cannot catch (e.g. greet(" ") must raise ValueError, not strip).
This is the second half of the roundtrip pipeline (the first half is
regent-reverse).
When to Use
- A
spec/ tree exists (typically produced by regent-reverse) and the
user wants to verify it is sufficient — i.e. an independent agent
reading only the spec can rebuild the project.
- The user invokes
build, reconstruct from spec, verify spec,
regent build <spec-dir>, or similar.
- Bulk scenario: stress-test a spec without paying for a human rebuild.
Don't use for:
- Building from a fresh description (no spec yet) — use
regent-reverse
first to produce one.
- Modifying an existing project without a spec — that is refactor, not
rebuild; do it manually or write a new skill for it later.
- Production deploys — the rebuild artifact is a research/verification
output, not a release artifact.
Inputs
spec_dir — path to the spec tree (REQUIRED). Must contain
AGENTS.md, inventory/functional-checklist.md, and conventions/.
out_dir — where to put the rebuild. Default:
/tmp/rebuild-<repo-name>/, taken from the spec's
README.md first heading.
strategy — single-subagent (default) | multi-subagent.
Default is one subagent with the whole spec; multi-subagent only if
the spec has 5+ R- heavy specs/*.spec.md files.
Workflow (MUST follow in order)
Each step ends with a checkable condition. Do not advance until satisfied.
1. Verify the spec is buildable
Before spawning anything, check the spec itself is ready:
AGENTS.md exists and is non-empty.
inventory/functional-checklist.md exists and has at least 5
- [ ] entries (fewer → spec too thin for a meaningful build;
recommend running regent-refine first instead).
inventory/test-oracle.md exists and contains at least one entry
per public surface that the rebuild must satisfy on the white-box
level (input/expects/pins triples). Without this, the rebuild's own
tests are the only test set — and the roundtrip is self-graded.
- If
specs/_scope.md exists, read it. Default strategy is
scoped (not whole-repo).
- Target language/build-tool: read it from
conventions/dev-env.md.
If any check fails, stop. Report the missing piece, do not
build.
2. Confirm the rebuilder cannot see the original source
This is the roundtrip property we are testing. The rebuilder MUST NOT
have access to the original repo tree (no path given, no clone hint).
Whitelist only the spec directory.
Explicit guard: when delegating, set the subagent's task to start with
"You may ONLY read files under <spec_dir>. Do NOT touch any path
outside it. The original repo exists at <original_path_hint> but is
not for reading."
(If a previous step accidentally left a copy of the repo under
out_dir, delete it before spawning.)
3. Spawn the rebuilder subagent
Use delegate_task with these properties:
role: leaf (the rebuilder cannot delegate further; keeps the
roundtrip tight).
- The subagent's goal MUST contain: the spec path, the out path,
the language hint, the constraint to read-only the spec.
- Tell the subagent: read
AGENTS.md first, then follow its
rebuild order.
- Tell the subagent: do not invent CLI features, error messages,
formats, or behavior NOT explicitly given in the spec.
When in doubt, prefer omission over invention.
- Tell the subagent: when done, report in the response a bullet
list of spec sections it had to invent beyond (so the spec author
can patch).
4. Run the verification
After the subagent reports done:
cd <out_dir>
- Read
conventions/dev-env.md for the exact test/build commands.
- Run the test command. Capture exit code.
- Cross-check
functional-checklist.md line by line against the
rebuild artifact (run each command / import each module as the
checklist prescribes).
- Read
inventory/test-oracle.md. For each ### <symbol> block,
call the rebuilt function/method with the documented input and
assert equality with the documented expects. Tick or fail with
the actual vs expected.
- The two lists together (black-box checklist + white-box oracle)
must BOTH be green before declaring PASS. A green checklist
with a red oracle means the rebuild ships the right CLI but got
the function semantics wrong (e.g.
greet(" ") strips instead
of raising) — the spec test-oracle catches what the behavioural
checklist cannot.
- Tick or fail each item; record evidence (output, exit code, log
line).
5. Decide
- All green: the spec is sufficient. Report.
- Any red: the spec has a hole. Report each failing item with
the exact failure message. Do not edit the rebuild to make it
pass. That would hide the spec gap. Recommend the spec author
add the missing piece in
R- and re-run this skill.
- Re-builder invented something not in spec: that is a separate
signal — list it. It is not a fail (the build may still pass),
but it is a spec-debt item to fix in the next reverse iteration.
6. Self-review
Before declaring done, verify:
- The rebuilder subagent received NO path to the original repo.
- The rebuild artifact was NOT mutated to mask failures.
- Every checklist item has a tick or a fail reason (no skipped).
- The spec-debt list is non-empty whenever the rebuilder reported
invention.
Common Pitfalls
- Letting the rebuilder peek at the original source. Defeats the
whole roundtrip. The whitelist is the contract.
- Patching the rebuild until tests pass. You are testing the
spec, not the rebuild. A green rebuild with a tweaked file is a
false green; the spec still has the gap.
- Skipping
conventions/dev-env.md. The rebuild needs the
project's build/test commands, not the agent's defaults. uv vs
pip vs poetry, cargo vs rustup, go vs cgo — these matter.
- Treating the rebuild artifact as production code. It is a
research output. Burn it after the report if you want.
- Re-using the previous rebuild directory without cleaning.
Stale
.venv, stale Cargo.lock target/ etc. produce false
passes. Always start from an empty (or freshly rm -rf'd)
out_dir.
- Running a multi-pass refine loop on spec-debt inside this
skill. That is a different skill. regent-build runs once,
reports, exits.
Verification Checklist
One-Shot Recipe
# After regent-reverse has produced spec at ./spec-out/<repo>/spec/
rm -rf /tmp/rebuild-<repo>
# Then invoke regent-build with:
# spec_dir = ./spec-out/<repo>/spec
# out_dir = /tmp/rebuild-<repo>
# strategy = single-subagent
# Expect a pass/fail report, a tick-by-tick checklist, and a
# spec-debt list.
1---2name: regent-build3description: Use when the user asks to rebuild a project from a REgent spec tree, run "spec → code + tests" roundtrip, or verify that a reverse-engineered spec is sufficient to reconstruct the original. Triggers on phrases like "按 spec 重建", "build from spec", "reconstruct from <spec_dir>", "verify spec sufficiency", or just "build". Pairs with `regent-reverse` — reverse produces the spec, this skill consumes it and produces runnable code graded against both `functional-checklist.md` (black-box) and `inventory/test-oracle.md` (white-box, per-function invariants). Works across languages via hermes subagent delegation.4license: GPL-3.0-or-later5---67# regent-build89Consume a REgent spec tree and produce runnable code that satisfies the spec's10`R-`/`S-` requirements, every line of `functional-checklist.md`, AND every11entry of `inventory/test-oracle.md`. The oracle is the second, white-box12grading key — it pins per-function invariants that a black-box checklist13cannot catch (e.g. `greet(" ")` must raise `ValueError`, not strip).14This is the second half of the roundtrip pipeline (the first half is15`regent-reverse`).1617## When to Use1819- A `spec/` tree exists (typically produced by `regent-reverse`) and the20 user wants to verify it is **sufficient** — i.e. an independent agent21 reading only the spec can rebuild the project.22- The user invokes `build`, `reconstruct from spec`, `verify spec`,23 `regent build <spec-dir>`, or similar.24- Bulk scenario: stress-test a spec without paying for a human rebuild.2526**Don't use for**:27- Building from a fresh description (no spec yet) — use `regent-reverse`28 first to produce one.29- Modifying an existing project without a spec — that is refactor, not30 rebuild; do it manually or write a new skill for it later.31- Production deploys — the rebuild artifact is a research/verification32 output, not a release artifact.3334## Inputs3536- `spec_dir` — path to the spec tree (REQUIRED). Must contain37 `AGENTS.md`, `inventory/functional-checklist.md`, and `conventions/`.38- `out_dir` — where to put the rebuild. Default:39 `/tmp/rebuild-<repo-name>/`, taken from the spec's40 `README.md` first heading.41- `strategy` — `single-subagent` (default) | `multi-subagent`.42 Default is one subagent with the whole spec; multi-subagent only if43 the spec has 5+ `R-` heavy `specs/*.spec.md` files.4445## Workflow (MUST follow in order)4647Each step ends with a checkable condition. Do not advance until satisfied.4849### 1. Verify the spec is buildable5051Before spawning anything, check the spec itself is ready:5253- `AGENTS.md` exists and is non-empty.54- `inventory/functional-checklist.md` exists and has at least 555 `- [ ]` entries (fewer → spec too thin for a meaningful build;56 recommend running `regent-refine` first instead).57- `inventory/test-oracle.md` exists and contains at least one entry58 per public surface that the rebuild must satisfy on the white-box59 level (input/expects/pins triples). Without this, the rebuild's own60 tests are the only test set — and the roundtrip is self-graded.61- If `specs/_scope.md` exists, read it. Default strategy is62 scoped (not whole-repo).63- Target language/build-tool: read it from `conventions/dev-env.md`.6465If any check fails, **stop**. Report the missing piece, do not66build.6768### 2. Confirm the rebuilder cannot see the original source6970This is the roundtrip property we are testing. The rebuilder MUST NOT71have access to the original repo tree (no path given, no clone hint).72Whitelist only the spec directory.7374Explicit guard: when delegating, set the subagent's task to start with75"You may ONLY read files under `<spec_dir>`. Do NOT touch any path76outside it. The original repo exists at `<original_path_hint>` but is77not for reading."7879(If a previous step accidentally left a copy of the repo under80`out_dir`, delete it before spawning.)8182### 3. Spawn the rebuilder subagent8384Use `delegate_task` with these properties:8586- `role: leaf` (the rebuilder cannot delegate further; keeps the87 roundtrip tight).88- The subagent's goal MUST contain: the spec path, the out path,89 the language hint, the constraint to read-only the spec.90- Tell the subagent: read `AGENTS.md` first, then follow its91 rebuild order.92- Tell the subagent: do not invent CLI features, error messages,93 formats, or behavior NOT explicitly given in the spec.94 When in doubt, prefer omission over invention.95- Tell the subagent: when done, report in the response a bullet96 list of spec sections it had to invent beyond (so the spec author97 can patch).9899### 4. Run the verification100101After the subagent reports done:102103- `cd <out_dir>`104- Read `conventions/dev-env.md` for the exact test/build commands.105- Run the test command. Capture exit code.106- Cross-check `functional-checklist.md` line by line against the107 rebuild artifact (run each command / import each module as the108 checklist prescribes).109- Read `inventory/test-oracle.md`. For each `### <symbol>` block,110 call the rebuilt function/method with the documented `input` and111 assert equality with the documented `expects`. Tick or fail with112 the actual vs expected.113- The two lists together (black-box checklist + white-box oracle)114 must BOTH be green before declaring PASS. A green checklist115 with a red oracle means the rebuild ships the right CLI but got116 the function semantics wrong (e.g. `greet(" ")` strips instead117 of raising) — the spec test-oracle catches what the behavioural118 checklist cannot.119- Tick or fail each item; record evidence (output, exit code, log120 line).121122### 5. Decide123124- **All green:** the spec is sufficient. Report.125- **Any red:** the spec has a hole. Report each failing item with126 the exact failure message. **Do not edit the rebuild to make it127 pass.** That would hide the spec gap. Recommend the spec author128 add the missing piece in `R-` and re-run this skill.129- **Re-builder invented something not in spec:** that is a separate130 signal — list it. It is not a fail (the build may still pass),131 but it is a spec-debt item to fix in the next reverse iteration.132133### 6. Self-review134135Before declaring done, verify:136137- The rebuilder subagent received NO path to the original repo.138- The rebuild artifact was NOT mutated to mask failures.139- Every checklist item has a tick or a fail reason (no skipped).140- The spec-debt list is non-empty whenever the rebuilder reported141 invention.142143## Common Pitfalls1441451. **Letting the rebuilder peek at the original source.** Defeats the146 whole roundtrip. The whitelist is the contract.1472. **Patching the rebuild until tests pass.** You are testing the148 spec, not the rebuild. A green rebuild with a tweaked file is a149 false green; the spec still has the gap.1503. **Skipping `conventions/dev-env.md`.** The rebuild needs the151 project's build/test commands, not the agent's defaults. uv vs152 pip vs poetry, cargo vs rustup, go vs cgo — these matter.1534. **Treating the rebuild artifact as production code.** It is a154 research output. Burn it after the report if you want.1555. **Re-using the previous rebuild directory without cleaning.**156 Stale `.venv`, stale `Cargo.lock` target/ etc. produce false157 passes. Always start from an empty (or freshly `rm -rf`'d)158 out_dir.1596. **Running a multi-pass refine loop on spec-debt inside this160 skill.** That is a different skill. regent-build runs once,161 reports, exits.162163## Verification Checklist164165- [ ] `AGENTS.md` and `inventory/functional-checklist.md` both exist166 and are non-empty.167- [ ] Out directory was empty (or freshly cleaned) before the168 rebuilder started.169- [ ] The subagent received only the spec path; the original repo170 path was given as a "do not read" hint at most.171- [ ] Verification commands ran from `conventions/dev-env.md` (not172 agent defaults).173- [ ] Every `- [ ]` line in `functional-checklist.md` has tick or174 fail reason; nothing skipped silently.175- [ ] Every `### <symbol>` block in `inventory/test-oracle.md` has176 been executed against the rebuild with PASS or FAIL evidence;177 nothing skipped silently.178- [ ] Spec-debt list was produced even when the build passed.179- [ ] The rebuild artifact was NOT edited to mask failures.180181## One-Shot Recipe182183```bash184# After regent-reverse has produced spec at ./spec-out/<repo>/spec/185rm -rf /tmp/rebuild-<repo>186# Then invoke regent-build with:187# spec_dir = ./spec-out/<repo>/spec188# out_dir = /tmp/rebuild-<repo>189# strategy = single-subagent190# Expect a pass/fail report, a tick-by-tick checklist, and a191# spec-debt list.192```