Skip to content

About

A guided tour of changes in Hunk - CLI diff viewer in the age of AI

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

hunk-guide

hunk-guide adds guided walkthroughs to Hunk. Instead of reviewing a changeset only in filesystem order, it groups related edits into an ordered narrative and navigates through the actual diff.

Hunk's normal diff remains the primary UI. hunk-guide adds an independent pane, section-focused presentation, exact-line navigation, session-local review progress, and explicit change checkpoints for live edits. A sticky Show all changes control restores full context without leaving the guide. Guide and files panes maintain independent open state. The extension does not create comments, replace Hunk's renderer, or call AI providers. An optional external command can generate a session-local guide without a shell or model SDK.

hunk-guide requires Hunk extension API 30, currently available on upstream main but not in the latest release (0.23.0). See building Hunk main.

Choose an authoring workflow

  • A coding agent can write .hunk/guide.json directly. Point it to the portable create-hunk-guide skill, which checks every target with bin/check.ts.
  • Alt+Y can generate a guide from Hunk's exact review snapshot. The bundled agent provider runs a coding-agent CLI such as claude -p, codex exec -, or pi -p. Adapter authors should follow the provider protocol.

Direct authoring creates a durable artifact immediately. Provider output stays in memory until the reviewer runs Guide: save generated guide. See review workflows for setup, automatic guides for every change, and pull requests.

Try the examples

Start with the runnable examples. They progress from a status badge to a departure board, a live review with checkpoints, and a change you guide with your own coding agent.

Original fixture

From this checkout:

bun install
HUNK_GUIDE_FILE=fixtures/basic-guide.json hunk patch fixtures/basic-review.patch --extension .

Do not run the demo command unattended: Hunk is an interactive terminal application.

The fixture demonstrates six conceptual sections, multiple files, multi-target sections, tests, and a supporting change. The explicit guide path keeps the fixture guide paired with its patch instead of loading it during unrelated reviews. The repository's example Hunk config documents the remaining settings for adaptation.

Keybindings

Action Default
Toggle Guide Alt+G
Next section Alt+J
Previous section Alt+K
Next target Alt+L
Previous target Alt+H
Toggle target reviewed Alt+R
Toggle section reviewed Alt+Shift+R
Set change checkpoint Alt+C
Toggle all/changed Alt+V
Focus section/show all Alt+A
Show overview Alt+O

Progress, overview, checkpoint, changed/all scope, and reload commands are also available in Hunk's Extensions menu without default bindings.

Install

Stable release:

hunk extension install brettinternet/hunk-guide@v0.1.0

Latest development from main:

hunk extension install brettinternet/hunk-guide

hunk extension update preserves tag pins because Hunk does not currently resolve newer SemVer releases. Upgrade tagged installs by specifying the new tag explicitly.

Local development:

# Pass the checkout root, including from a renamed checkout or worktree:
# The local hunk-guide entry takes precedence over an installed copy.
hunk diff --extension .
# Or replace the managed install with a local checkout:
hunk extension install /path/to/hunk-guide

Load a guide

Set HUNK_GUIDE_FILE (recommended for coding agents):

HUNK_GUIDE_FILE=./guide.json hunk diff

File resolution precedence:

  1. HUNK_GUIDE_FILE (explicit user input; can point anywhere)
  2. [extension.hunk-guide].file in Hunk config (must resolve within the reviewed working directory)
  3. ./.hunk/guide.json when present
  4. ./hunk-guide.json when present (legacy compatibility)

Relative paths resolve from the reviewed working directory.

Generated guide lifecycle

.hunk/guide.json is the uncommitted active guide for one checkout or worktree. Generate or replace it for each new changeset; switching branches in the same checkout does not remove the ignored file. Separate worktrees have separate active guides.

If Hunk is already open after replacing the file, run Guide: reload guide file. Use HUNK_GUIDE_FILE when selecting a named guide or a file stored elsewhere. Commit guides only when they are intentionally maintained fixtures, examples, or durable project documentation.

Configuration

Optional settings in .hunk/config.toml:

[extension.hunk-guide]
file = ".hunk/guide.json"
default_open = true
placement = "right" # or "left"
density = "balanced" # compact | balanced | thorough
show_verification = true
show_supporting = false
show_mechanical = false
provider_timeout_seconds = 300 # bounded to 10..1800 seconds
  • density: Generation preference rather than a quota: compact (roughly 3-5 sections), balanced (default, 4-7 sections), or thorough (6-10 sections). Small changes may need fewer. It is passed to the external generator and never changes a loaded guide.
  • provider_timeout_seconds: Maximum external-command runtime, bounded to 10 through 1,800 seconds. Output is bounded and both stdout and stderr are drained concurrently.
  • Keybindings: Every guide action is a named command in the hunk-guide.* namespace (e.g. hunk-guide.next-section, hunk-guide.toggle-reviewed) and rebindable under [keybindings]. Hunk's public API does not currently let extensions add rows to the built-in Controls help; the Guide pane displays effective remapped navigation keys instead.

External command generation

Set HUNK_GUIDE_COMMAND to either one executable path or a JSON argv array. It is executed directly with no shell expansion, pipes, redirects, or string-splitting. The command is trusted code: it runs from the review directory and inherits Hunk's environment, filesystem, credentials, and network access. Repository configuration cannot select the executable.

HUNK_GUIDE_COMMAND='["./tools/make-guide", "--format", "hunk-guide-v1"]' hunk diff
# or
HUNK_GUIDE_COMMAND=./tools/make-guide hunk diff

Use Guide: generate with external command (Alt+Y) to generate a guide for the latest changeset, or Guide: cancel generation (Alt+Shift+Y) to stop it. Generation sends a versioned JSON request containing public paths, patches, hunk ranges, review metadata, content identities, and the configured density. Runtime renderer IDs are never sent. See the provider protocol for the complete contract. The command must write one versioned response envelope to stdout:

{
    "protocolVersion": 1,
    "requestId": "<request id>",
    "guide": {
        "version": 1,
        "id": "example",
        "sections": [
            {
                "id": "first-change",
                "title": "First change",
                "targets": [
                    { "id": "first-target", "path": "src/main.ts", "side": "new", "startLine": 1 }
                ]
            }
        ]
    }
}

The guide document is strictly validated, and every target must resolve against both the captured and current changesets before replacing the last known-good guide. Invalid output, timeout, cancellation, reload, or shutdown leaves the previous guide visible.

To generate guides with a coding agent, use the agent provider. Run the bundled transport example with:

HUNK_GUIDE_COMMAND='["node","./examples/providers/minimal-adapter.mjs"]' hunk diff

The example proves request and response framing. It does not produce a semantic guide.

Save a generated guide

Run Guide: save generated guide from Hunk's Extensions menu to persist the current generated guide to .hunk/guide.json. Saving is available only for a generated guide from the current changeset. A different existing file requires confirmation, and the extension writes the replacement atomically inside .hunk.

An explicit HUNK_GUIDE_FILE or configured file still takes load precedence over the saved default. Static guides loaded from disk are never rewritten by this command.

Guide JSON

Coding agents should follow the authoring guide for narrative ordering, section density, concise explanations, and grouping examples.

{
    "$schema": "https://raw.githubusercontent.com/brettinternet/hunk-guide/main/hunk-guide.schema.json",
    "version": 1,
    "id": "authentication-retry",
    "title": "Authentication retry",
    "summary": "Retries move behind one policy and propagate through token refresh.",
    "sections": [
        {
            "id": "retry-policy",
            "kind": "change",
            "title": "Introduce the retry policy",
            "explanation": "Start with the policy shared by refresh and API clients.",
            "targets": [
                {
                    "id": "retry-policy-type",
                    "path": "auth/retry.ts",
                    "side": "new",
                    "startLine": 12,
                    "endLine": 28,
                    "symbol": "RetryPolicy"
                }
            ]
        }
    ]
}

The checked-in hunk-guide.schema.json provides coding-agent guidance plus editor completion and validation. Add the $schema property shown above, or use a relative path to a local copy of the schema.

Schema rules

  • $schema: Optional JSON Schema URI for authoring tools; it does not affect guide behavior.
  • version: Currently 1.
  • IDs: Stable non-empty strings. Target IDs must be globally unique within the guide.
  • Sections: Represent one logical change and can span multiple files.
  • kind: Optional; defaults to change. Valid kinds are change, verification, supporting, and mechanical. Classify by review purpose rather than path: behavior and contracts are change, tests and benchmarks are verification, secondary context is supporting, and generated output, formatting, or bulk renames are mechanical.
  • side: Defaults to "new".
  • Lines: 1-based and inclusive. Target ranges must fit inside a single changed Hunk range.
  • symbol: Reserved for future target reconciliation; Phase 1 does not resolve it.
  • Ordering: Preserved exactly as declared. Recommended sequence: contracts/models, implementation, consumers, boundaries, errors/observability, tests, and mechanical work.
  • Invalid or unresolved targets appear as unavailable; hunk-guide never clamps lines or navigates to guessed locations.

Default to a separate verification section near the end for tests, after reviewers understand the behavior they prove. Keep a test in a change section only when it best explains that behavior. Cross-cutting, integration, and end-to-end tests belong in verification; metadata and secondary context belong in supporting; generated output, formatting, and bulk renames belong in mechanical. Split mixed-purpose sections so visibility remains predictable.

Review progress and live changes

  • Session-local: Mark targets or sections reviewed (Alt+R / Alt+Shift+R). A reviewed target becomes stale if its definition or containing changed file later differs. Stable IDs make persistence possible later, but the MVP writes no review database.
  • Explicit checkpoints: "Changed since last viewed" would imply viewport tracking that Hunk's public API does not expose; hunk-guide uses an explicit checkpoint instead:
    1. Run Guide: set change checkpoint (Alt+C).
    2. Keep Hunk running with --watch while an agent edits the tree.
    3. Run Guide: toggle all/changed scope (Alt+V) to show only affected, new, missing, or incomparable guide targets.
    4. Toggle back to all targets at any time.
  • Checkpoint presentation: Changed (~), missing (!), new (+), and incomparable (?) states are labeled independently from cursor and review progress. Files outside the guide are listed by path and identified as changed, new, or unknown.
  • Section focus: Selecting a section focuses the diff on the deduplicated union of its target-containing hunks while preserving Hunk's canonical order. Show all changes (Alt+A) is sticky: while enabled, guide navigation jumps without re-entering focus. Closing Guide, showing overview, an unavailable section, or an extension failure restores the full diff.
  • Guide visibility: Changed scope and the toggle verification/supporting/mechanical sections commands determine Guide navigation and which section can be focused. Initial visibility comes from show_verification (defaults to true), plus show_supporting and show_mechanical (both default to false). Files in hidden sections remain represented, while changed files outside the guide are counted so stale guides remain visible.
  • Reloads: Guide order is not regenerated during a Hunk reload. Run Guide: reload guide file to reload manually; failed reloads retain the last valid guide.

Development

mise trust
mise install
task init
task test
task check

TypeScript is imported directly with no build step. Hunk supplies React, OpenTUI, and hunkdiff/extension at runtime (devDependencies).

The checkout is an extension container. Its hunk-guide/ directory declares the entry point and minimum API version, so the extension ID stays hunk-guide regardless of the checkout name. Keep React components and other runtime imports of host-owned modules inside hunk-guide/. Hunk only shares its React and OpenTUI instances with files under the extension entry directory; components outside it can load a second React and fail with a null hooks dispatcher. Pure helpers can stay in src/ without an index.* entry; otherwise Hunk would discover them as a second extension. Hunk does not support the proposed hunk.id manifest field.

Building Hunk main

Verified against d2e85a0847fc (API 30). Until API 30 is released, build upstream rather than the old hunk-guide fork:

gh repo clone modem-dev/hunk /path/to/hunk
cd /path/to/hunk
git checkout d2e85a0847fcee8911ce386ea7b03888586049e4
mise exec bun@1.4.2 -- bun install --frozen-lockfile
mise exec bun@1.4.2 -- bun run build:bin
mise link hunk@main-d2e85a0847fc /path/to/hunk/dist

cd /path/to/hunk-guide
mise use --env local hunk@main-d2e85a0847fc
mise exec hunk -- hunk --version

Keep the linked build directory in place. mise.local.toml is ignored and copied into development worktrees; the shared toolchain does not depend on a machine-local build. This snapshot still reports 0.23.0, so use the pinned commit, not the version string, to identify it.

The development dependency uses the latest published hunkdiff (0.23.0, API 29). src/hunk-v30.d.ts bridges only the unreleased public declarations; it adds no runtime fallback. Remove it when the npm release includes API 30. Compatibility checks against the built upstream declarations must exclude this bridge.

For an interactive smoke test, run the fixture above and check section navigation (Alt+J/K), sticky Show all (Alt+A), and closing Guide (Alt+G) without losing normal diff navigation. Do not launch this TUI as an unattended check.

Releases

main is the latest development version. Published versions use immutable SemVer tags matching package.json (v0.x.x) and remain on the 0.x line while the Hunk extension API and Guide behavior are evolving.

  1. Run the Release workflow from main with the package version (e.g. 0.1.0) and concise release notes.
  2. The workflow runs the full CI matrix, verifies the version and tag, then creates the GitHub release only after CI passes.
  3. Published tags cannot be moved or deleted because GitHub immutable releases are enabled.

See DESIGN.md for current API research, architectural decisions, known public API gaps, and the deferred external-command generator boundary.

Upstream status

As of 2026-10-11:

Capability Upstream work Status
Section-focused presentation Proposal #1117, PR #1118 Merged into main; not released
Stable extension manifest IDs PR #1119 Closed without merge; fixed-name container layout used instead

Use an upstream main build with API 30. No fork patches are needed. Wait for a released Hunk API 30 before publishing another hunk-guide release.

Current limitations

  • External generation is opt-in through HUNK_GUIDE_COMMAND; no model SDK is included. Commands are direct argv processes and are bounded by timeout and output limits.
  • Review progress and checkpoints are session-local.
  • Target identity is path + side + line/range. Symbols and content fingerprints are future enhancements.
  • A target hidden by Hunk's active file filter remains valid but cannot be revealed through the public navigation API until the filter is cleared.
  • Section focus requires Hunk extension API 30; Hunk 0.23.0 and older releases cannot load this development version.
  • Hunk currently shares visibility across vertical pane edges. Opening Guide may also reveal a logically open files pane (Hunk #1114).
  • Hunk's public API does not let extensions contribute rows to the built-in Controls help; use the Extensions menu or the live shortcut labels in the Guide pane.

About

A guided tour of changes in Hunk - CLI diff viewer in the age of AI

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages