defmodule Mix.Tasks.Excessibility.Latest do @shortdoc "Display the most recent debug report" @moduledoc """ Display the most recent debug report without re-running tests. ## Usage mix excessibility.latest mix excessibility.latest --format=json ## Description Re-displays the last debug report generated by `mix excessibility.debug`. Useful for: - Returning to a debug session after doing something else - Sharing debug output with Claude without re-running tests - Comparing multiple runs ## Formats - `markdown` (default) - Display the markdown report - `json` - Display the JSON report """ use Mix.Task @impl Mix.Task def run(args) do {opts, _, _} = OptionParser.parse(args, strict: [format: :string], aliases: [f: :format] ) format = Keyword.get(opts, :format, "markdown") output_path = Application.get_env( :excessibility, :excessibility_output_path, "test/excessibility" ) file_path = case format do "json" -> Path.join(output_path, "latest_debug.json") _ -> Path.join(output_path, "latest_debug.md") end if File.exists?(file_path) do content = File.read!(file_path) Mix.shell().info(content) else Mix.shell().error("No previous debug report found at #{file_path}") Mix.shell().info("Run `mix excessibility.debug test/path_test.exs` first.") exit({:shutdown, 1}) end end end