view source

Reverse Spec: Reconstruct the Task Behind a Diff

skill

Reconstruct the task behind a commit, branch or diff: the prompt as it likely arrived plus a clarified spec, with every hunk bucketed by intent.

Apache-2.0 Requires git and a checked-out repository.

agents that use this skill

instructions

Overview

Read an implemented change (commits, a feature branch, a pasted diff) and reconstruct the task that most plausibly produced it. Work backwards from code to intent. The output is what a requester would have written before the change existed, in requester language (behavior, features, user-visible effects), never a description of the diff.

The skill reconstructs and classifies. It does not write forward specs from an idea, comment on code in review, or write changelogs, and it never judges code quality: it recovers what was asked.

Rules

Phase 1: retrieve (parallel)

  • Pasted diff: use as is. Commit or range: git show or git log -p. Branch: diff against the merge-base with main or master. Nothing given: git status plus git diff (staged and unstaged).
  • git log for messages: intent hints, never ground truth; the code decides.
  • Read the final state of every touched region (file outline, then targeted reads). Hunks alone lie about meaning.
  • Shell is git-only here; code reading goes through file outlines, file reads and code search.

Phase 2: understand

  • Group changes into logical intents. One branch usually is one task; genuinely unrelated intents become separate reconstructed tasks.
  • For each user-visible surface in the diff (flag, endpoint, config key, error message, default value, UI text), decide: could only the task have specified this, or is it an implementer's pick? Use semantic and symbol search to check whether names follow existing codebase conventions; convention-following names are implementer picks.

Phase 3: reconstruct

Write the task at two fidelities:

  • Prompt: how the request most likely arrived. 1 to 6 sentences, informal, feature-level, allowed to be slightly vague the way real tasks are. It references only what a requester could know: existing features, visible behavior, user pain, never internal symbols.
  • Clarified spec: the same task with every ambiguity resolved the way the diff resolved it: behavioral requirements, the concrete values the requester must have stated (limits, defaults, exact messages where product-worded), acceptance checks. Still behavior-level: if two different implementations would both satisfy a statement and the diff picked one, that pick does not belong in the spec.

Phase 4: coverage check

Walk every hunk and bind it to exactly one bucket: covered by a requirement; implementer discretion (naming, structure, an enabling refactor the task needed); unrequested (a drive-by no plausible task line explains). Contorting the task to absorb a drive-by is a defect: flag it instead.

Then invert: every requirement must be backed by at least one hunk. A requirement nothing in the diff implements is invented: delete it.

Voice and evidence

  • Requester's voice: product and behavior language. Internal function, type and module names appear only where the requester would see them (public API, CLI, config). "Make the retry stop hanging forever", not "add backoff to HttpClient::retry_with". File paths follow the same test: requester-visible files (README, config files, CLI docs) may be named; every other path lives in Evidence only.
  • Pre-change voice: write the prompt and spec as if the change does not exist yet. Requirements state what the system shall do, never what the change did.
  • Realism beats completeness in the prompt: real tasks arrive underspecified. The missing precision goes in the clarified spec, never back into the prompt.
  • Intent evidence hierarchy: user-visible behavior in code, then commit message, then test names and assertions, then inference. Mark pure inference as (inferred).
  • Tests in the diff are requirement fossils: each new assertion usually encodes an acceptance criterion. Mine them.
  • Version bumps, lockfiles, formatting churn: ignore entirely, no bucket.
  • Multiple unrelated intents: one Reverse Spec section per intent, ordered by diff size.
  • Output goes to the conversation; save to a file only when asked.

Situations

  • No input and a clean repo: one line, "Nothing to reverse-spec. Give me a commit, range, branch, or diff."
  • Ambiguous branch base: merge-base with main or master; neither exists: ask once.
  • "Make it rougher" or "more realistic": rewrite only the prompt, more casual and less complete; the clarified spec stays intact.
  • Otherwise one pass, no confirmations, stop after Evidence.

Output format

markdown
# Reverse Spec: <task name>

## Task Prompt (as it likely arrived)
> <1-6 sentences, informal requester voice>

## Clarified Spec
<One-paragraph goal — WHAT and WHY.>

Requirements:
- R1: <behavioral statement with concrete values from the diff>
- R2: …

Acceptance checks:
- [ ] <binary check a requester could verify, mined from tests where possible>

## Implementer Discretion
- <decision visible in the diff the task did not need to state — naming, structure, algorithm>

## Unrequested Changes (omit if none)
- <file/hunk — drive-by no plausible task explains>

## Evidence
- `path/file.rs:42` — <why this grounds a requirement or bucket>
Confidence: HIGH/MEDIUM/LOW — <one line: what was evidenced vs inferred>

The task prompt and clarified spec must stand alone: no references to the diff, the commits or the other sections. A reader given only those two sections can implement the task from scratch. Evidence and Implementer Discretion carry all pointers into the actual change.

Checklist

  • The output reconstructs what preceded the change; it does not describe the diff.
  • No implementation pick in the spec; requester-mandated surfaces (flags, endpoints, messages, defaults) are not under Implementer Discretion.
  • Every hunk bucketed; no stretched task to cover a drive-by.
  • No internal symbol named in the prompt or spec unless user-visible.
  • Inferences marked (inferred) and reflected in the confidence line.

Composition / References

  • spec-authoring writes forward specs from an idea; developer-diff-briefing explains a change for reviewers.