Skip to content

feat: Add configurable stats mode with Git integration#17

Open
krfantasy wants to merge 4 commits intomasterfrom
stats-mode
Open

feat: Add configurable stats mode with Git integration#17
krfantasy wants to merge 4 commits intomasterfrom
stats-mode

Conversation

@krfantasy
Copy link
Owner

Summary

Introduces a new stats mode output option that provides concise change statistics instead of full tree diffs, along with automated Git integration for .als files.

Motivation

Current limitations:

  • Tree mode output can be overwhelming for large Ableton Live projects with many tracks/devices
  • Git integration for .als files requires manual configuration of .gitattributes
  • Commit messages for .als changes must be manually written or copy-pasted from diff output
  • Stats types were hardcoded in the renderer with no user customization

What this PR solves:

  • Provides a quick overview of changes without full detail
  • Automates Git integration with an interactive setup script
  • Auto-generates commit message summaries from .als changes
  • Makes stats mode fully configurable via existing config system

Changes Overview

🆕 New Stats Mode

  • New module: lib/output/stats_renderer.ml (84 lines)
  • New flag: --mode stats
  • New tests: test/test_stats_renderer.ml (165 lines, 8 tests)

Example output:

Tracks: 2 Added, 1 Removed, 5 Modified
Devices: 3 Added, 0 Removed, 2 Modified
Clips: 8 Added, 2 Removed, 1 Modified

⚙️ Configurable Type Filtering

Refactored from hardcoded reportable_types list to config-driven filtering via get_effective_detail()

Added stats_default preset in lib/output/config.ml with 7 historically tracked types:

  • LiveSet, Track, Device, Clip, Note, Automation, Mixer, Routing, Locator

🐙 Automated Git Integration

New script: scripts/setup-git.sh (111 lines)

Features:

  • Prerequisite checks (alsdiff in PATH, git repository)
  • Automatic .gitattributes configuration for .als files
  • Interactive prompt for custom command line arguments
  • Optional prepare-commit-msg hook installation

📝 Prepare-commit-msg Hook

Auto-generates commit message summaries using alsdiff --mode stats on staged .als files

🔧 Code Refactoring

  • Moved: render_views from bin/alsdiff.mllib/output/text_renderer.ml
  • Extracted: build_base_renderer_config() helper to eliminate duplicate config building logic

Files Changed

File Changes
bin/alsdiff.ml Main entry point - mode handling
lib/output/config.ml Added stats_default preset
lib/output/stats_renderer.ml New stats renderer module
lib/output/text_renderer.ml Moved render_views function
scripts/setup-git.sh Git integration setup script
test/test_stats_renderer.ml Comprehensive test suite

Total: 8 files changed, 527 insertions(+), 80 deletions(-)

Usage Examples

# Stats mode
alsdiff --mode stats old.als new.als

# With custom config
alsdiff --mode stats --config project-config.json old.als new.als

# Git integration
./scripts/setup-git.sh
git diff song.als

# Commit with auto-generated message
git add song.als
git commit  # Hook auto-generates stats summary

Testing

All tests pass: 8 new tests + existing tests unaffected

Backwards Compatibility

No breaking changes: Tree mode remains default, new --mode flag is optional

krfantasy and others added 4 commits February 13, 2026 02:07
Add --mode flag with tree (default) and stats options:
- Stats mode shows flat summary of change counts by type
- Example: "Tracks: 2 Added, 1 Removed, 5 Modified"
- Validates incompatibility with tree-specific flags

Create lib/output/stats_renderer.ml module:
- collect_view: recursively counts changes by domain_type
- render: formats statistics as multi-line summary
- display_name: provides plural labels (Tracks, Devices, etc.)

Add test/test_stats_renderer.ml with 8 tests:
- Empty/unchanged handling
- Single/multiple change types
- Non-reportable types excluded
- Fixed ordering per reportable_types list
- Deep nesting and zero count omissions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…mit messages

Add an interactive option to setup-git.sh that installs a prepare-commit-msg
git hook using 'alsdiff --mode stats' to auto-generate commit message
summaries from staged .als file changes.

Co-Authored-By: Claude <noreply@anthropic.com>
…tering

Refactor stats_renderer from hardcoded reportable_types list to config-driven
type filtering via get_effective_detail. Stats mode now supports --config
and --preset flags for customizing which types appear in statistics.

Changes:
- bin/alsdiff.ml: Extract build_base_renderer_config helper to eliminate
  duplicate config building logic between Stats and Tree modes
- lib/output/config.ml: Add stats_default preset (7 historically tracked types)
- lib/output/stats_renderer.ml: Replace reportable_types with stats_from_config,
  making render/collect/collect_view functions accept detail_config parameter
- test/test_stats_renderer.ml: Update tests to pass stats_default config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65c0cf5e73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +145 to +148
if config.output_mode = Stats && stats_incompatible_flags_provided config then begin
Fmt.epr "Error: --mode stats is incompatible with --prefix-*, \
--note-name-style, and --max-collection-items@.";
1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return git-mode argument errors with exit code 2

This branch returns 1 for a stats-mode argument error even when --git is active, which makes Git (trustExitCode) interpret the failure as "differences found" instead of an invalid invocation. In practice, alsdiff --git --mode stats --prefix-added ... will look like a real diff result rather than a configuration error, despite the command documentation in this file defining exit code 2 for invalid arguments. Return 2 in git mode for this path so misconfiguration is surfaced correctly.

Useful? React with 👍 / 👎.


while IFS=$'"'"'\t'"'"' read -r status filepath; do
filename=$(basename "$filepath")
case "$status" in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle renamed .als files in commit-message hook

The generated hook only branches on M, A, and D, but git diff --cached --name-status can emit rename/copy statuses (for example R100\told.als\tnew.als). Those entries currently fall through and produce no summary text, so commits that rename .als files silently miss stats output for those changes. Add handling for R* (and ideally C*) statuses so commit summaries cover all staged .als changes.

Useful? React with 👍 / 👎.

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