reconstruct
Invocation
On request by default. reconstruct runs when you ask for it: the agent may call
it when you request a reconstruction or product specs, and you can invoke it
directly with $reconstruct in Codex, /reconstruct in Claude Code or OpenCode.
The agent does not pick it up on its own, and CLI commands are unchanged. One
setting makes it explicit-only — see Manual or automatic.
Turn any repository — or a greenfield idea — into reconstruction PRDs an AI agent can
rebuild the project from: faithful to the original (logic, routes, translations, schema,
config), optionally improved, and buildable enough that a fresh agent gets the contracts
right — enforced by a --check gate.
reconstruct is an Agent Skill (the open agent-skills
ecosystem by Vercel). It pairs a thin deterministic scaffold with a thick AI
playbook: a bundled, dependency-free Node script extracts universal facts, resolves routes
(with their HTTP method) for the major frameworks, and surfaces candidate hints for
everything else; the AI agent that runs the skill supplies the deeper framework-aware
understanding — the full interface surface, the data model, and the real features — for
any stack.
📖 Full documentation: DOCUMENTATION.md — concept, CLI
reference, the analyzer pipeline, how to extend it, and FAQ.
Install
# into the current project (committed, team-shared)
npx skills add maxgfr/reconstruct
# or globally for all your projects
npx skills add -g maxgfr/reconstruct
# optionally target specific agents (default: the ones detected)
npx skills add maxgfr/reconstruct -a codex opencode
This installs the skill into your agent (Codex, OpenCode, Claude Code, Cursor, …). Invoke it
explicitly — $reconstruct in Codex, /reconstruct in Claude Code or OpenCode, or just ask:
reconstruct this repo in redesign + complex mode.
Recommended: install rea too
rea reads what source analysis cannot: native libraries and
executables, WebAssembly, .NET, Android, Electron and JavaScript apps. With it installed, every
scaffold of a repo that ships compiled artifacts inspects them and writes citable evidence
(rea underneath). Without it, those artifacts stay opaque unknowns.
node scripts/analyze.mjs --install-rea # shows what will run, then asks
# or by hand:
npm install --global rea-agents # puts `rea` on PATH — all reconstruct needs
rea setup # optional: register rea's MCP server + skill with your agents
rea doctor --json # check the install and its engines
rea needs Node 22.23.4+, 24.22.1+ or 26.12.1+. Its deep engines are optional and yours to add:
Ghidra 12.1 with JDK 21 (GHIDRA_INSTALL_DIR), Hopper, IDA, and WABT for WebAssembly. Details:
DOCUMENTATION § Installing rea.
What it produces
reconstruction/
├── REBUILD.md # master plan: build order + validation checklist
├── RECONSTRUCTION.md # (--merge) the whole tree in one markdown, WITH embedded source
├── SPECS.md # (--specs) the whole spec, code-free — the file to implement from
├── FEATURES.md # (--features) every feature PRD only, in build order
├── SUMMARY.md # one-page digest — written on EVERY run; read it to orient
├── 00-overview/PRD.md # product summary, stack, metrics, feature index
├── architecture/
│ ├── ARCHITECTURE.md # architecture + external services, cross-cutting policies, i18n message catalog
│ ├── INTERFACES.md # interface surface (method · path · kind · handler) + per-op input/output/side-effect contracts
│ ├── DATA-MODEL.md # entities, fields, relations, indexes + enums & domain types
│ ├── DESIGN-SYSTEM.md # design tokens, theming, typography, components & a11y (UI products)
│ └── diagram.md # mermaid module diagram
├── features/
│ └── NN-<slug>/PRD.md # one PRD per feature/module (build-order tiered)
├── data/ # ground truth, copied verbatim
│ ├── translations/ # i18n files
│ ├── schema/ # DB schema / models
│ └── config/ # build/lint/env config
├── source/ # (fidelity=mirror) copied real source, per feature
├── UNKNOWNS.json # (--unknowns) residual unknowns: revisioned, hash-chained, evidence-backed
├── OBLIGATIONS.json # (--verify --apply) every requirement: closed / open / failed + closure digest
└── inventory.json # machine-readable manifest + evidence[] (file · line · content hash)
Evidence model
Every route and env var the engine resolves gets a content-addressed record in
inventory.json evidence[] — ev_<hash>, its file, line and content hash, plus two
independent axes: confidence (observed · derived · inferred) and authority (source ·
test · config · manifest · doc · plan · analyzer · agent). Verdicts cite those ids (and rea:ev_… ids exported from the rea reverse-engineering MCP server, for compiled artifacts the source walk cannot see); a supported verdict
resting on the agent's inference alone never closes an obligation; --check --repo flags
evidence whose file changed since generation; and what nobody could settle goes into a
fail-closed unknowns ledger instead of a confident guess. Details:
references/evidence-model.md.
rea underneath
What the source does not show (a vendored native library, a .wasm module, an Electron
.asar, an APK), rea can inspect. When the repo ships such
artifacts and rea is installed (npx rea-agents setup), the scaffold drives rea's MCP server
itself, using static inspection tools only. It writes one inspection per artifact, rea's evidence
bundle and an INDEX.json into <out>/evidence/rea/, so every rea:ev_… id is citable from
the first enrichment pass. The gate checks those citations against the exported files.
--rea auto|on|off (default auto) controls it, and REA_BIN points at a specific executable.
Without rea, nothing changes: the artifacts become unknowns for the agent.
DOCUMENTATION § rea underneath.
Two axes + fidelity
| Axis |
Values |
Effect |
| Mode |
preserve | redesign | scratch |
Keep the current architecture, design a fresh one for the same features, or build greenfield from an interview (see From scratch). |
| Level |
light | complex |
Faithful & concise, or also suggest improvements the agent folds in. |
| Fidelity |
mirror | embed | describe |
Copy real files / inline key code / text-only. |
Fidelity defaults are derived (override with --fidelity):
| Mode + Level |
Fidelity |
| preserve + light |
mirror |
| preserve + complex |
embed |
| redesign + light |
embed |
| redesign + complex |
describe |
Translations, schema, and config are always copied into data/ verbatim,
regardless of fidelity — you can't faithfully "rewrite" data.
Standalone CLI
The deterministic engine also runs on its own (no agent, no API key):
node scripts/analyze.mjs --repo ./my-app --out ./my-app/reconstruction \
--mode preserve --level light --fidelity mirror
# inspect the raw inventory without writing anything
node scripts/analyze.mjs --repo ./my-app --json
Run node scripts/analyze.mjs --help for all flags.
Bundling: one file or a digest
Four optional, combinable flags collapse the multi-file tree:
--merge → RECONSTRUCTION.md: the whole tree in one coherent markdown
(single H1, linked table of contents, headings demoted one level; ordered
overview → architecture → features → build order), with the embedded original
source. The complete archive.
--specs → SPECS.md: the same whole tree as --merge — overview,
architecture (interfaces + data model), every feature PRD, build order — but
with each document's ## Source material section (the embedded original source
code) stripped. Self-sufficient (it carries the contracts the feature PRDs
reference) yet code-free, so it's the single file you hand an agent to
(re)implement the project from.
--features → FEATURES.md: every feature PRD only — the product
functionality — in build order, in one file (single H1 + table of contents).
The features-only counterpart to --merge.
SUMMARY.md: a one-page digest from the inventory (stack, libraries, size,
features in build order, interface/data counts, locales, unknowns, next steps).
Written on every run — it is the cheap orientation document, a few KB against
an inventory.json that grows linearly with the repo. --summary only selects it
for the standalone post-step below.
# inline: produce the tree and the bundles in one run
node scripts/analyze.mjs --repo ./my-app --out ./my-app/reconstruction --merge --specs --features
# standalone post-step: (re)build the bundles from an existing output, no --repo
node scripts/analyze.mjs --merge --specs --features --summary --out ./my-app/reconstruction
# just the code-free spec to implement from, from an existing reconstruction:
node scripts/analyze.mjs --specs --out ./my-app/reconstruction
The standalone form reads <OUT>/inventory.json + the .md files, is idempotent,
and errors clearly if the directory holds no inventory.json.
Validation: is it actually buildable?
A reconstruction is only useful if a fresh agent can rebuild each unit correctly from
the PRD + architecture docs alone. Once the PRDs are enriched, run the buildability gate:
node scripts/analyze.mjs --check --out ./my-app/reconstruction
It exits non-zero on the structural failures — unresolved 🧠 callouts or fill this in
placeholders, a feature that references an undocumented entity/operation, a feature PRD
missing its spine, an uncovered locale, and a gutted data model / interface surface /
feature PRD (an emptied contract fails too, not just a callout-laden one).
--check covers structure; the ten contract categories a PRD must actually carry —
field-level data model, fully-enumerated enums, operation & write contracts (a public write
can't require an owner foreign key), format validations, external services, quantified
policies, the i18n message catalog, shared/owned UI components, and — for UI products — the
design-system contract (tokens, theming, components, a11y) — are in
references/buildability-checklist.md. In
greenfield mode the engine also validates the plan's consistency before rendering, so
dangling references and anonymous-write-to-owner-FK contradictions are caught up front.
Two validation layers: deterministic gate + AI review
--check is deterministic — it proves structure (no leftover callouts, the docs
declare entities/operations, every PRD keeps its spine). It can't judge substance: a PRD
can pass the gate and still be unbuildable (vague requirements, happy-path-only criteria, an
unsatisfiable write contract, an enum value that contradicts the data model). That second
judgement is the AI review — performed via the skill, not the script: there is no
--ai flag and no API key, because the agent running the skill is the reviewer. After
--check passes, the agent re-reads the tree and applies
references/ai-review-rubric.md (story completeness,
testable requirements, real Given/When/Then incl. failure paths, satisfiable write contracts,
enum fidelity, cross-doc consistency, faithfulness, i18n, and the rebuild self-test), fixing
every blocker in place. Layer 1 is fast and CI-friendly; layer 2 is where a smart model
earns its keep.
The layer-2 review is itself orchestrated by a review ledger so it terminates instead of
looping by feel. --review writes a per-feature worklist (REVIEW.todo.json), flagging only
the units whose content hash changed since the last round; an agent fans out one reviewer per
flagged unit plus one independent verifier per blocker, then --review --apply findings.json reduces the structured findings to REVIEW.json (ok, residual,
noProgress/staleRounds):
node scripts/analyze.mjs --review --out ./my-app/reconstruction
node scripts/analyze.mjs --review --apply findings.json --out ./my-app/reconstruction
--check --semantic folds both semantic gates into the structural one — VERIFY.json
(requirements that don't trace to source) and REVIEW.json