|
| 1 | +# Narrative walkthrough — authoring guide |
| 2 | + |
| 3 | +This is Codiff's guidance for authoring a **narrative walkthrough**: a story-shaped |
| 4 | +review of a change. Unlike Codiff's built-in walkthrough (which only orders files), a |
| 5 | +narrative walkthrough tells the _story_ of the change — ordered stops grouped into |
| 6 | +chapters, each pinned to a specific slice of the diff, with your narration and the prior |
| 7 | +conversation attached so Codiff can answer follow-up questions. |
| 8 | + |
| 9 | +You — the agent — author a JSON document conforming to the schema printed at the end of |
| 10 | +this guide. Write it to a **temporary file outside the repository** (e.g. a unique path in |
| 11 | +the system temp directory) so it never clutters the working tree; pass that path to Codiff |
| 12 | +with `--walkthrough-file`. Set the document's `"$schema"` to |
| 13 | +`https://raw.githubusercontent.com/nkzw-tech/codiff/main/src/walkthrough/narrative-walkthrough.schema.json` |
| 14 | +for editor validation. |
| 15 | + |
| 16 | +Default to the **staged** diff (`git diff --staged`). If the user named a target (a commit, |
| 17 | +`HEAD`, a PR, a path), use that. If nothing is staged, fall back to the working tree |
| 18 | +(`git diff`) and say so. |
| 19 | + |
| 20 | +## The shape, and why it's shaped this way |
| 21 | + |
| 22 | +The document separates **segments** (order-independent slices of the diff) from **orders** |
| 23 | +(reading views over them). The same segment can lead one order and sit in another order's |
| 24 | +"rest". This is what lets one changeset present as both _key-changes-first_ and |
| 25 | +_results-first_ without duplicating data. |
| 26 | + |
| 27 | +- **`segments[]`** — the order-independent atoms. Each is one addressable slice of the diff: |
| 28 | + - `id` — stable within the document, e.g. `"s1"`. |
| 29 | + - `path`, `oldPath?`, `status` (`added` | `deleted` | `modified` | `renamed` | `untracked`). |
| 30 | + - `granularity` — `line` | `hunk` | `file`. Choose per stop: pull out a single `line` for a |
| 31 | + one-line bug, a `hunk` for a focused change, a whole `file` for a new test that reads as a |
| 32 | + spec. |
| 33 | + - `added`, `deleted` — line counts for the slice. |
| 34 | + - `anchor` — where it points into the live diff: `display` (e.g. `"src/App.tsx:311"`), |
| 35 | + optional `sectionId` (`<path>:staged` for staged diffs, `<path>:unstaged` for working-tree |
| 36 | + edits), `sectionKind`, `side` (`additions` | `deletions` | `both`), and `startLine`/`endLine` |
| 37 | + for `line`/`hunk` granularity (omit for `file`). Codiff repairs anchors against the live diff, |
| 38 | + so a missing or slightly-off `sectionId` is fine — it's pinned to a real section on load. |
| 39 | + - `title?`, `summary?` — default framing; an order's stop may override the title. |
| 40 | + - `comments?` — review comments to seed, anchored by `side` + `lineNumber` (+ optional range). |
| 41 | + |
| 42 | +- **`orders[]`** — one or more reading views over the segments. Each has: |
| 43 | + - `id` (e.g. `"keys"`, `"results"`), `label`, `tagline`. |
| 44 | + - `phases[]` — named chapters, each with an `icon` (`bug` | `wrench` | `path` | `flask` | |
| 45 | + `beaker` | `doc` | `gear`) and a `blurb`. |
| 46 | + - `sequence[]` — the ordered stops. Each is `{ segmentId, phaseId, importance, prose, title? }`. |
| 47 | + - `rest[]` — files changed alongside the work but kept off the narrative path, each |
| 48 | + `{ segmentId, reason, note? }`. Group by `reason` (e.g. `Generated`, `Lockfile`, `Snapshot`, |
| 49 | + `Mechanical`). |
| 50 | + - `restLabel`, `restBlurb` — how "the rest" is presented. |
| 51 | + |
| 52 | +- **`defaultOrder`** — the order id Codiff opens first. Choose `results` when the change has a |
| 53 | + strong test/snapshot/contract that previews it well; otherwise `keys`. |
| 54 | + |
| 55 | +- **`context`** — a compact summary of the originating conversation (objective, decisions, |
| 56 | + risks, validation, a few key messages), so Codiff can answer questions without you. Use the |
| 57 | + `WalkthroughContext` shape (`version: 1`, `source: { type: "claude-session" | "codex-session", generatedAt }`). |
| 58 | + |
| 59 | +## How to think about it |
| 60 | + |
| 61 | +- Order stops by **review leverage and story**, not by file path. It is good for the arc to |
| 62 | + cross files and return to an earlier one (the bug, the fix, the refactor, the proof). |
| 63 | +- Write `prose` as the agent's voice explaining _why this matters now_. It may use inline |
| 64 | + markdown / code. Keep review comments separate (`comments[]`), not baked into prose. |
| 65 | +- Use `importance: "critical"` sparingly — only the genuine root cause or the defining test. |
| 66 | +- Push generated files, lockfiles, and snapshots into each order's `rest[]` with a `reason`. In |
| 67 | + a results-first order you may instead promote a signal-bearing one (a snapshot, a widened |
| 68 | + contract) to a lead stop. |
| 69 | + |
| 70 | +- Provide **two orders** when both make sense (`keys` and `results`); one is fine for small |
| 71 | + changes. Do not invent bugs or produce review findings — describe what changed and why. |
| 72 | +- Every `segmentId` referenced by a `sequence` or `rest` entry must exist in `segments[]`, and |
| 73 | + every segment `path` should be a file in the diff. Codiff drops dangling references on load, |
| 74 | + but a clean document renders best. |
| 75 | + |
| 76 | +## The schema |
| 77 | + |
| 78 | +The document must conform to the following JSON schema: |
0 commit comments