Skip to content

Add preview mode to all mutators#7

Merged
TroyHernandez merged 2 commits into
mainfrom
preview-mode
Apr 27, 2026
Merged

Add preview mode to all mutators#7
TroyHernandez merged 2 commits into
mainfrom
preview-mode

Conversation

@TroyHernandez
Copy link
Copy Markdown
Contributor

Summary

Implements Task 4 of Plan.md: every function that writes to disk takes preview = FALSE. With preview = TRUE it returns a hacer_preview object describing the change and writes nothing. The HACER_PREVIEW=1 env var flips the default for an entire session or one-shot CLI invocation.

Mutators covered: roll_day, run_monday, fix_parents, next_day, sync_from_daily, instantiate_todo.

Architecture

  • R/preview.R holds the new infrastructure: .preview_default() reads the env var, .new_preview() builds the result object, .line_diff() computes an LCS-based per-file diff, and .write_or_preview() is the single dispatch each mutator calls with its computed targets.
  • R/io.R splits each writer (write_todo_txt, write_markdown, write_simple_html) into a build_*_lines() function plus a thin writeLines wrapper, so mutators can compute new file contents in memory before deciding whether to apply.
  • print.hacer_preview() renders a short summary: created files, modified files with +/- counts, and done.log appends.

run_monday's archive copy and git commit are skipped in preview mode since they're side effects beyond the file system.

README and CLAUDE.md document the new mode with a one-shot CLI example. Version bumped to 0.1.6.

Test plan

  • 32 new tests in inst/tinytest/test_preview.R: zero-mtime guarantee on disk, env-var default flipping, print output, and preview-then-apply equivalence with non-preview runs for roll_day, fix_parents, sync_from_daily, and instantiate_todo
  • All 82 existing tests still pass (114 total, all green)
  • tinyrox::document(); tinypkgr::install(); tinytest::test_package("hacer") clean

Every function that writes to disk takes preview = FALSE. With
preview = TRUE it returns a hacer_preview object describing the
change and writes nothing. The HACER_PREVIEW=1 env var flips the
default for an entire session or one-shot CLI invocation.

Mutators covered: roll_day, run_monday, fix_parents, next_day,
sync_from_daily, instantiate_todo.

Architecture:

- R/preview.R holds the new infrastructure: .preview_default()
  reads the env var, .new_preview() builds the result object,
  .line_diff() computes an LCS-based per-file diff, and
  .write_or_preview() is the single dispatch each mutator calls
  with its computed targets.
- R/io.R splits each writer (write_todo_txt, write_markdown,
  write_simple_html) into a build_*_lines() function plus a thin
  writeLines wrapper, so mutators can compute new file contents
  in memory before deciding whether to apply.
- print.hacer_preview() renders a short summary: created files,
  modified files with +/- counts, and done.log appends.

run_monday's archive copy and git commit are skipped in preview
mode since they're side effects beyond the file system.

32 new tests in test_preview.R cover: zero-mtime guarantee on
disk, env-var default flipping, print output, and preview-then-
apply equivalence with non-preview runs for roll_day,
fix_parents, sync_from_daily, and instantiate_todo.

Bump version to 0.1.6.
README: add a "Look before you leap: preview mode" subsection
under the LLM CLI agents section with print output, the
HACER_PREVIEW=1 one-shot CLI examples, and the list of
functions that support it.

CLAUDE.md: brief Preview mode section pointing at R/preview.R
and the .write_or_preview() dispatch pattern that each mutator
follows.
@TroyHernandez TroyHernandez merged commit c8fd679 into main Apr 27, 2026
4 checks passed
@TroyHernandez TroyHernandez deleted the preview-mode branch April 27, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant