backburn 0.1.0-arm64-darwin

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.
@@ -0,0 +1,226 @@
1
+ # Backburn — CLI and outputs
2
+
3
+ Nov 23, 2026 · @Sophie
4
+
5
+ Backburn becomes a command with subcommands: `scan` reports dead code, `batches` plans its removal, `explain` answers why something is live or dead, and every command speaks text, TSV, JSON and SARIF with the same fields.
6
+
7
+ ## Commands
8
+
9
+ ```
10
+ backburn [COMMAND] [OPTIONS] [PATH]
11
+ ```
12
+
13
+ `PATH` is the project root and defaults to the current directory. With no command, Backburn runs `scan`.
14
+
15
+ | Command | Answers | Its own options |
16
+ | --- | --- | --- |
17
+ | `scan` | What code can no production path reach? | `--only REASONS`, `--test-refs include\|exclude\|only` |
18
+ | `batches` | In what independent pieces can I delete it? | `--max-lines N`, `--untested` (only batches no test names) |
19
+ | `explain NAME` | Why is this live, or why is it dead? | `--all-paths` |
20
+ | `roots` | Which entry points matched, and which patterns matched nothing? | `--unused` (only patterns that matched nothing) |
21
+ | `gems` | Which Gemfile gems does the app still need? | `--gem-src DIR` |
22
+ | `init` | Write a starting config for this project | `--force` |
23
+
24
+ **`scan`** is today's report: every candidate with its reason, test tag and dead callers, then the uncertain definitions (what a computed `send` on self may call, never counted as candidates), then the dynamic dispatch sites that could hide callers. `--only` takes a comma list of `unreferenced`, `dead-chain`, `dead-cycle`. `--test-refs exclude` drops candidates that tests name; `--test-refs only` shows just those.
25
+
26
+ **`batches`** is today's `--batches`: dead code joined by references or containment, ordered untested first, then largest. Each batch lists its lines, files and the test files that name it.
27
+
28
+ **`explain NAME`** takes a qualified name (`Order#total`, `Admin::Report`, `Version.owned_by`). For a live definition it prints one path from a root, which is the question people ask when they expected something to be dead:
29
+
30
+ ```
31
+ Order#price_of is live
32
+ root OrdersController#show public action (< ActionController::Base)
33
+ calls Order#total app/controllers/orders_controller.rb:4
34
+ calls Order#price_of app/models/order.rb:10
35
+ ```
36
+
37
+ For a dead definition it prints its reason, its dead callers, and its batch. `--all-paths` lists every root that reaches it. This needs the marking step to keep one parent edge per definition, a 4-byte array.
38
+
39
+ **`roots`** prints each root rule with how many definitions it matched, so a roots file can be tuned: a pattern matching thousands is too broad, one matching nothing is stale.
40
+
41
+ **`gems`** is `gem_usage.rb` folded in. Run inside `bundle exec`, it reads every gem's source; outside a bundle it uses the app alone and says so in its header.
42
+
43
+ **`init`** detects Rails, GraphQL-ruby, Sidekiq, Phlex and Pundit from the Gemfile.lock and writes `.backburn.yml` with the matching roots files listed, plus an empty project roots file.
44
+
45
+ ## Global options and configuration
46
+
47
+ Every command takes these. Command-line options win over the config file, which wins over built-in defaults.
48
+
49
+ | Option | Default | Effect |
50
+ | --- | --- | --- |
51
+ | `--preset NAME` | from `init` | built-in roots: `rails`, `graphql`, `sidekiq`, `phlex`, `pundit`, `rails-framework`; repeatable |
52
+ | `--roots FILE` | none | an extra roots file; repeatable, read after presets |
53
+ | `--public-api` | off | every public, documented method, class and constant is a root; `:nodoc:` marks internal |
54
+ | `--inflect` | off | `:line_items` also reaches `LineItem` and `LineItems` |
55
+ | `--exclude GLOB` | `vendor/**`, `node_modules/**`, `tmp/**`, `log/**`, `coverage/**` | skip matching paths; repeatable |
56
+ | `--tests GLOB` | `test/**`, `spec/**`, `**/*_test.rb`, `**/*_spec.rb` | what counts as a test file; repeatable, replaces the default |
57
+ | `--format FMT` | `text` | `text`, `tsv`, `json`, `sarif` |
58
+ | `--output FILE` | stdout | write the report to a file |
59
+ | `--color WHEN` | `auto` | `auto`, `always`, `never` |
60
+ | `--config FILE` | `.backburn.yml` | read another config; `--no-config` ignores it |
61
+ | `-q`, `--quiet` | off | no header or summary line in `text` |
62
+ | `--version`, `--help` | | |
63
+
64
+ The roots-file grammar stays as it is today (`Pattern`, `public Pattern`, `< Superclass`, `path:glob`). Presets are the same files, compiled into the binary so a single executable works anywhere.
65
+
66
+ **`.backburn.yml`**, at the project root. Backburn reads a small, flat subset of YAML: scalars and lists of strings, no anchors or nesting beyond one level. That keeps the binary free of a YAML library.
67
+
68
+ ```yaml
69
+ presets: [rails, graphql]
70
+ roots: [.backburn.roots] # project-specific patterns, committed
71
+ inflect: true
72
+ exclude: [db/migrate/**, script/**]
73
+ tests: [spec/**]
74
+ baseline: .backburn-baseline.json
75
+ ```
76
+
77
+ `init` writes this file and an empty `.backburn.roots` with a comment header explaining the grammar, and leaves the project's `.gitignore` alone.
78
+
79
+ **What is committed and what isn't.** `.backburn.yml`, `.backburn.roots` and `.backburn-baseline.json` sit at the repository root and are committed: CI and everyone on the team need the same roots and baseline. `.backburn/` is local and never tracked: whichever command creates it first also writes `.backburn/.gitignore` containing `*`, which ignores the whole folder, that file included, without touching the project's own `.gitignore`. It holds the parse cache that makes reruns fast, the last report (`.backburn/last.json`, which `explain` reuses), and `--output` files when no path is given.
80
+
81
+ ## Output formats
82
+
83
+ All four formats carry the same facts; only the shape changes. Every definition has a stable **id**, `kind:QualifiedName` (`method:Order#legacy_total`), so baselines and other tools survive line moves. When one name is defined in two files (a reopened class), the id gains `@path`.
84
+
85
+ **Reasons**, the same words everywhere:
86
+
87
+ | Reason | Meaning |
88
+ | --- | --- |
89
+ | `unreferenced` | nothing names it |
90
+ | `dead-chain` | only dead code reaches it |
91
+ | `dead-cycle` | it is reached only from a group that calls itself |
92
+
93
+ “Test-only” is a flag beside the reason (`tests: true`), never a reason of its own.
94
+
95
+ ### text
96
+
97
+ For people. Grouped by reason for `scan`, by batch for `batches`; paths are relative to `PATH`; colour only on a terminal.
98
+
99
+ ```
100
+ backburn 0.1 · 490 files · 1675 definitions · 80 ms · presets: rails, graphql
101
+ 32 dead · 29 unreferenced · 3 dead-chain · 0 dead-cycle · 25 used only by tests
102
+
103
+ Unreferenced (29)
104
+ app/graphql/base/node.rb:4 module Base::Node
105
+ app/models/print_queue/fit.rb:68 method PrintQueue::Fit#cannot?
106
+ app/models/print_queue/hold.rb:9 class PrintQueue::Hold [tests]
107
+ …
108
+
109
+ Uncertain: a computed send may reach these (1)
110
+ lib/dispatcher.rb:6 method Dispatcher#start ← send(<computed>) lib/dispatcher.rb:3
111
+
112
+ Dynamic dispatch that may hide callers (11)
113
+ app/models/gcode/slicer.rb:33 constantize(<computed>)
114
+ ```
115
+
116
+ ### tsv
117
+
118
+ One row per definition, a header row, tabs, no quoting. Columns, in order:
119
+
120
+ | Command | Columns |
121
+ | --- | --- |
122
+ | `scan` | `id`, `kind`, `name`, `file`, `line`, `end_line`, `reason`, `tests` (`0`/`1`), `batch` |
123
+ | `batches` | the same, sorted by batch, then reason, then location |
124
+ | `roots` | `rule`, `source` (preset or file:line), `matched` |
125
+ | `gems` | `gem`, `groups`, `verdict`, `evidence`, `needed_by` |
126
+
127
+ ### json
128
+
129
+ For tools such as connascent and editors. One object; `schema` bumps on breaking changes.
130
+
131
+ ```json
132
+ {
133
+ "schema": 1,
134
+ "tool": { "name": "backburn", "version": "0.1.0" },
135
+ "project": { "root": "/path/to/app", "presets": ["rails", "graphql"], "git": "0ddf4da" },
136
+ "stats": { "files": 490, "definitions": 1675, "references": 22849, "ms": 80 },
137
+ "candidates": [
138
+ {
139
+ "id": "method:Order#old_rounding",
140
+ "kind": "method",
141
+ "name": "Order#old_rounding",
142
+ "location": { "file": "app/models/order.rb", "line": 17, "end_line": 19 },
143
+ "visibility": "public",
144
+ "reason": "dead-chain",
145
+ "tests": false,
146
+ "test_files": [],
147
+ "callers": ["method:Order#legacy_total"],
148
+ "batch": 1
149
+ }
150
+ ],
151
+ "batches": [
152
+ { "id": 1, "lines": 6, "files": ["app/models/order.rb"], "definitions": ["method:Order#legacy_total", "method:Order#old_rounding"], "test_files": [] }
153
+ ],
154
+ "uncertain": [
155
+ {
156
+ "id": "method:Dispatcher#start",
157
+ "kind": "method",
158
+ "name": "Dispatcher#start",
159
+ "location": { "file": "lib/dispatcher.rb", "line": 6, "end_line": 6 },
160
+ "visibility": "public",
161
+ "tests": false,
162
+ "send": { "file": "lib/dispatcher.rb", "line": 3, "call": "send" }
163
+ }
164
+ ],
165
+ "dynamic_sites": [
166
+ { "file": "app/models/gcode/slicer.rb", "line": 33, "call": "constantize" }
167
+ ]
168
+ }
169
+ ```
170
+
171
+ `scan` and `batches` print this same document; `batches` is always filled in, so one JSON run serves both. `uncertain` lists definitions a computed send on self may reach, each with that send; they are never candidates. `explain` prints `{ "id", "live", "reason", "path": [{ "id", "via", "location" }] }`. For an uncertain definition, `live` is `false`, `reason` is `"uncertain"`, and the path step through the send has `"via": "send"` with the send's location.
172
+
173
+ ### sarif
174
+
175
+ SARIF 2.1.0, so GitHub code scanning shows dead code as annotations on pull requests. One rule per reason (`backburn/unreferenced`, `backburn/dead-chain`, `backburn/dead-cycle`), level `note`. Each result carries the definition's location as its region, the batch as `properties.batch`, and the stable id as its `partialFingerprints.backburnId`, so GitHub tracks a finding across commits.
176
+
177
+ ## Exit codes, baselines and CI
178
+
179
+ Backburn exits like a linter, so CI can gate on it.
180
+
181
+ | Code | Meaning |
182
+ | --- | --- |
183
+ | `0` | ran; nothing to report under `--fail-on` |
184
+ | `1` | ran; found dead code that `--fail-on` counts |
185
+ | `2` | usage error: unknown option, missing `PATH`, unreadable config or roots file |
186
+ | `3` | some Ruby files could not be parsed; the report still prints, and lists them |
187
+
188
+ `--fail-on` decides what counts:
189
+
190
+ - `none` (the default with no baseline): always exit `0`, for reading reports.
191
+ - `any`: any candidate fails.
192
+ - `new` (default when a baseline is set): only candidates whose id is not in the baseline fail.
193
+
194
+ **Baselines** make adoption on an old codebase possible: you accept today's dead code, and CI only stops new dead code. `backburn scan --write-baseline` writes `.backburn-baseline.json`, a sorted list of ids with the commit it was taken at. Ids, not line numbers, so moving code doesn't churn it. Removing a batch shrinks the baseline; `--write-baseline` rewrites it, and `scan` prints a hint when baseline entries no longer exist.
195
+
196
+ **CI recipe** for GitHub Actions:
197
+
198
+ ```yaml
199
+ - run: backburn scan --format sarif --output backburn.sarif --fail-on new
200
+ - uses: github/codeql-action/upload-sarif@v3
201
+ if: always()
202
+ with:
203
+ sarif_file: backburn.sarif
204
+ ```
205
+
206
+ The job fails on new dead code, and the annotations show where it is.
207
+
208
+ ## Migration and open questions
209
+
210
+ Today's flags map onto the new commands one to one; the old spellings keep working for one release with a deprecation line on stderr.
211
+
212
+ | Today | Proposed |
213
+ | --- | --- |
214
+ | `backburn DIR` | `backburn scan DIR` (or just `backburn DIR`) |
215
+ | `--roots rails.roots` | `--preset rails` (`--roots FILE` stays for project files) |
216
+ | `--batches` | `backburn batches` |
217
+ | `--tsv` | `--format tsv` |
218
+ | `never_referenced`, `only_dead_callers`, `dead_cycle` | `unreferenced`, `dead-chain`, `dead-cycle` |
219
+ | `only_in_tests` column | `tests` column |
220
+ | `ruby gem_usage.rb DIR` | `backburn gems DIR` |
221
+
222
+ **Open questions**
223
+
224
+ - [ ] **How does `gems` read the bundle from C?** Proposal: the binary runs `bundle exec ruby -e` once to print each gem's name and source path, then indexes those paths with Prism itself, as it does the app. That keeps one parser and drops `gem_usage.rb`.
225
+ - [ ] **How is it installed?** A gem named `backburn` with a native extension (compiled on `gem install`, ships the `backburn` executable) fits Ruby teams best; prebuilt binaries on GitHub releases are the fallback for CI images without a compiler.
226
+ - [ ] **Should `explain` take `file:line` as well as a name?** It's what an editor integration would send.