@acemarke/diffloupe 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -0
  3. package/dist/index.js +547 -0
  4. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Erikson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # DiffLoupe
2
+
3
+ Understand your diffs before you merge them.
4
+
5
+ ## The Problem
6
+
7
+ Reading diffs is hard. You're staring at fragments of code without the full picture, trying to reconstruct what the change *actually does* and whether it's correct.
8
+
9
+ Good code review requires a mental model of the existing system - understanding where features live, how components interact, what a change will impact. But diffs show you disconnected hunks across files, and you're left mentally stitching them together.
10
+
11
+ This problem gets worse with AI-generated code. When an AI assistant produces 50 files of changes, you can't just skim and approve. You need to understand what was built, verify it matches your intent, and catch the subtle issues that LLMs introduce.
12
+
13
+ ## The Solution
14
+
15
+ DiffLoupe uses AI to analyze diffs and tell you what they *mean*:
16
+
17
+ - **"What does this change do?"** - Get a clear summary of purpose, scope, and affected areas
18
+ - **"What could go wrong?"** - Surface risks with concrete evidence, not vague warnings
19
+ - **"Does it match my intent?"** - Compare what you asked for against what was actually built
20
+
21
+ The key differentiator is **intent alignment**: provide your stated intent (commit message, PR description, or explicit description), and DiffLoupe compares it against what the code actually does. This surfaces scope creep, incomplete implementations, and mislabeled changes before they cause problems.
22
+
23
+ ## Features
24
+
25
+ - **Intent Derivation** - Analyzes diffs to determine purpose, scope, and affected areas
26
+ - **Risk Assessment** - Identifies potential issues with severity levels and concrete evidence
27
+ - **Intent Alignment** - Compares stated intent vs derived intent to catch mismatches
28
+ - **Smart Context Loading** - Includes sibling files and new file source to reduce false positives
29
+ - **Large Diff Handling** - Automatic decomposition strategies (two-pass, flow-based) for big changes
30
+ - **GitHub PR Support** - Analyze PRs directly using PR metadata as stated intent
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install -g @acemarke/diffloupe
36
+ ```
37
+
38
+ Requires Node.js 18+.
39
+
40
+ ## Configuration
41
+
42
+ Set your Anthropic API key as an environment variable:
43
+
44
+ ```bash
45
+ export ANTHROPIC_API_KEY=sk-ant-api03-...
46
+ ```
47
+
48
+ Add to your shell profile (`~/.bashrc`, `~/.zshrc`) for persistence.
49
+
50
+ ## Quick Start
51
+
52
+ ```bash
53
+ # Analyze staged changes
54
+ diffloupe analyze
55
+
56
+ # Analyze with your stated intent
57
+ diffloupe analyze --intent "Add rate limiting to API endpoints"
58
+
59
+ # Analyze a commit (uses commit message as intent)
60
+ diffloupe analyze commit:HEAD
61
+
62
+ # Analyze a GitHub PR (uses title + description as intent)
63
+ diffloupe pr 123
64
+
65
+ # Preview what will be sent to the LLM (no API call)
66
+ diffloupe summarize --stats
67
+ ```
68
+
69
+ ## Commands
70
+
71
+ ### `diffloupe analyze [target]`
72
+
73
+ Analyze code changes with AI assistance.
74
+
75
+ **Targets:**
76
+
77
+ | Target | Description |
78
+ |--------|-------------|
79
+ | `staged` | Staged changes (default) |
80
+ | `unstaged` | Unstaged working tree changes |
81
+ | `HEAD` | All uncommitted changes |
82
+ | `branch:name` | Compare current HEAD to branch |
83
+ | `commit:hash` | Analyze a specific commit |
84
+ | `range:a..b` | Analyze a commit range |
85
+
86
+ **Options:**
87
+
88
+ | Option | Description |
89
+ |--------|-------------|
90
+ | `-i, --intent <text>` | Describe the intent of the changes |
91
+ | `--intent-file <path>` | Read intent from a file |
92
+ | `-v, --verbose` | Show detailed output |
93
+ | `--json` | Output results as JSON |
94
+ | `-C, --cwd <path>` | Run in a different directory |
95
+ | `--strategy <name>` | Force decomposition strategy (direct, two-pass, flow-based) |
96
+ | `--demo` | Show example output without API call |
97
+
98
+ **Intent sources** (in priority order):
99
+ 1. `--intent` flag
100
+ 2. `--intent-file` contents
101
+ 3. Commit message (for `commit:` targets)
102
+ 4. Piped stdin
103
+
104
+ ### `diffloupe pr <identifier>`
105
+
106
+ Analyze a GitHub PR. Requires `gh` CLI to be installed and authenticated.
107
+
108
+ **Identifier formats:**
109
+
110
+ ```bash
111
+ diffloupe pr 123 # PR in current repo
112
+ diffloupe pr owner/repo#123 # Cross-repo PR
113
+ diffloupe pr https://github.com/owner/repo/pull/123 # Full URL
114
+ ```
115
+
116
+ **Options:**
117
+
118
+ | Option | Description |
119
+ |--------|-------------|
120
+ | `-R, --repo <owner/repo>` | Specify repository |
121
+ | `-v, --verbose` | Show detailed output |
122
+ | `--json` | Output results as JSON |
123
+
124
+ The PR's title and description are automatically used as stated intent.
125
+
126
+ ### `diffloupe summarize [target]`
127
+
128
+ Preview diff formatting without running LLM analysis. Useful for debugging and understanding token usage.
129
+
130
+ **Options:**
131
+
132
+ | Option | Description |
133
+ |--------|-------------|
134
+ | `--stats` | Show only file list and token estimates |
135
+ | `--files-only` | Show only file list |
136
+ | `--json` | Output as JSON |
137
+ | `--no-tokens` | Skip token estimates |
138
+
139
+ ## Output
140
+
141
+ DiffLoupe provides three types of analysis:
142
+
143
+ **Derived Intent** - What the change actually does:
144
+ - Summary and purpose
145
+ - Scope (feature, bugfix, refactor, etc.)
146
+ - Affected areas
147
+ - Suggested review order
148
+
149
+ **Risk Assessment** - Potential issues:
150
+ - Severity (low, medium, high, critical)
151
+ - Category (security, performance, error-handling, etc.)
152
+ - Evidence from the actual code
153
+ - Suggested mitigations
154
+
155
+ **Intent Alignment** (when stated intent provided):
156
+ - Alignment level (aligned, partial, misaligned)
157
+ - What matches between stated and actual
158
+ - Mismatches, missing implementations, and unstated changes (scope creep)
159
+
160
+ ## How It Works
161
+
162
+ 1. **Parse** - Load and parse the git diff
163
+ 2. **Classify** - Tier files by importance (skip lock files, generated code)
164
+ 3. **Gather Context** - Load sibling files in touched directories
165
+ 4. **Select Strategy** - Choose decomposition approach based on diff size
166
+ 5. **Analyze** - Run intent derivation and risk assessment
167
+ 6. **Align** - Compare stated intent vs derived intent (if provided)
168
+
169
+ For large diffs, DiffLoupe automatically selects a decomposition strategy:
170
+ - **Direct** - Small diffs analyzed in one pass
171
+ - **Two-pass** - Medium diffs: quick overview, then deep-dive on flagged files
172
+ - **Flow-based** - Large diffs: group files by logical flow, analyze each flow
173
+
174
+ ## Inspirations
175
+
176
+ DiffLoupe builds on ideas from several excellent tools:
177
+
178
+ - [LaReview](https://github.com/puemos/lareview) - Flow-based grouping concept
179
+ - [GitHuman](https://github.com/mcollina/githuman) - Pre-commit review philosophy
180
+ - [Diffray](https://github.com/diffray/diffray) - Validation patterns, confidence scoring
181
+ - [Critique](https://github.com/remorses/critique) - Prompt engineering principles
182
+ - [CodeRabbit](https://coderabbit.ai) - Incremental review patterns
183
+
184
+ ## Development
185
+
186
+ DiffLoupe is built with Bun and TypeScript, published as a Node.js-compatible package.
187
+
188
+ ```bash
189
+ # Install dependencies
190
+ bun install
191
+
192
+ # Run in dev mode
193
+ bun run dev
194
+
195
+ # Run tests
196
+ bun test
197
+
198
+ # Type check
199
+ bun run typecheck
200
+
201
+ # Build for distribution
202
+ bun run build
203
+ ```
204
+
205
+ **Tech stack:** Bun, TypeScript, TanStack AI, ArkType, Commander
206
+
207
+ ## License
208
+
209
+ MIT