Usability: - Command aliases (n, p, s, ls, st) and positional step counts for next/prev - next/prev clamp at the tour ends instead of erroring - Color only when stdout is a TTY and NO_COLOR is unset (new style.rs) - reset asks for confirmation; --force required when non-interactive - IO errors carry operation context; friendlier not-started/no-steps errors - list marks the current step; consistent lowercase verb output - Handle SIGPIPE like other CLI tools instead of panicking when piped Efficiency: - Carry-forward hardlinks unchanged files between steps (copy fallback), so a step only costs disk for its changes; copy_path unlinks before overwriting so overlays can't write through a link - Navigation installs only files that differ (inode/size/byte compare) instead of two full-tree copies through a temp dir - Change report reads only changed files; LCS diff trims common prefix/suffix; path validation canonicalizes anchors once Adds 10 integration tests (rm carry-forward, reset --force, clamping, aliases, binary files, piped output, inode sharing, old-format compat, unchanged-file mtimes). Old tours need no migration. Co-Authored-By: Claude Fable 5 <[email protected]>
4.0 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Commands
cargo build # build the project
cargo run -- <cmd> # run a subcommand (e.g. cargo run -- init)
cargo test # run all tests
cargo test <name> # run a single test by name
cargo clippy # lint
What This Project Is
tour is a CLI tool for creating and navigating code tutorials as a series of snapshots. Authors create tours by committing file snapshots with explanations; readers step through them with next/prev.
Author workflow: tour init → tour add <files> → tour commit -m <msg> (repeat) → tour end -m <msg>
Reader workflow: tour start → tour next [n] / tour prev [n] / tour step <n> / tour reset
Architecture
Entry point is main.rs, which uses clap's derive macro to parse subcommands and dispatch to per-command modules.
On-disk format (stored in .tour/ in the project being toured):
.tour/steps/<N>/— one numbered directory per step (each step is a complete file snapshot).tour/steps/<N>/message— the commit message for that step.tour/session— tracks current reader position asSTEP=<n>.tour/staged— list of files staged for the next commit.tour/info— tour metadata (author, description, language, dates).tour/removed— list of files marked for removal in the next commit.tour/ended— marker file indicating the tour is finalized
Module layout:
init.rs— creates.tour/structure, collects tour metadata, updates.gitignoreadd.rs— stages files for the next commit;get_staged()reads the staged file listunstage.rs— removes files from stagingcommit.rs— commits staged files as a new step with carry-forward from previous step; only clears staging when staging was usedrm.rs— marks files for removal in the next commit (skipped during carry-forward)end.rs— finalizes the tour (writes.tour/endedmarker)step.rs— navigation:next,prev,step_n; installs only files that differ between steps, diff display, binary detection;next/prevclamp at the ends instead of erroringreset.rs— resets tour session and removes tracked files from working directory; prompts for confirmation (or--forcewhen non-interactive)status.rs— shows current step position and staged fileslist.rs— lists all steps with their messages, marking the current oneinfo.rs— tour metadata (author, description, language, dates)utils.rs— shared helpers:require_tour,get_current_step,get_tour_step,copy_path,validate_pathserror.rs— unifiedTourErrorenum withDisplayimpl for user-facing messages; includesCorruptedTourfor integrity checks and anIoResultExt::contexthelper for annotating IO errorsstyle.rs— ANSI color helpers; emit color only when stdout is a TTY andNO_COLORis unset
Key design decisions:
- Each step is a complete snapshot —
commit.rscarries forward files from the previous step before overlaying new ones. Carried-forward files are hardlinked (copy fallback), so a step only costs disk for its changes; because of this, anything overwriting a file inside.tour/steps/must unlink it first (seecopy_path), and files installed into the working directory are always real copies, never links into the store - Navigation compares working-dir files against the target step (inode, then size, then bytes) and touches only files that differ
TourErroris the unified error type across all modules, withFrom<io::Error>for automatic conversionmain()catches errors and prints them withDisplayformat (notDebug) for user-friendly messages- Constants
TOUR_DIRandSESSION_PATHare defined inmain.rsand imported viacrate::
Testing: Integration tests in tests/integration.rs use tempfile crate to create isolated tour directories and test via Command-based process spawning.