forge-terminal 0.0.0-stage → 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 (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1036 -2
  3. package/dist/cli/args.js +278 -0
  4. package/dist/cli/args.js.map +1 -0
  5. package/dist/cli/config-command.js +55 -0
  6. package/dist/cli/config-command.js.map +1 -0
  7. package/dist/cli/execute.js +377 -0
  8. package/dist/cli/execute.js.map +1 -0
  9. package/dist/cli/report.js +123 -0
  10. package/dist/cli/report.js.map +1 -0
  11. package/dist/cli/spinner.js +60 -0
  12. package/dist/cli/spinner.js.map +1 -0
  13. package/dist/cli/stdin.js +47 -0
  14. package/dist/cli/stdin.js.map +1 -0
  15. package/dist/config/preferences.js +143 -0
  16. package/dist/config/preferences.js.map +1 -0
  17. package/dist/core/actions/compress.js +157 -0
  18. package/dist/core/actions/compress.js.map +1 -0
  19. package/dist/core/actions/convert.js +270 -0
  20. package/dist/core/actions/convert.js.map +1 -0
  21. package/dist/core/actions/extract.js +94 -0
  22. package/dist/core/actions/extract.js.map +1 -0
  23. package/dist/core/actions/index.js +23 -0
  24. package/dist/core/actions/index.js.map +1 -0
  25. package/dist/core/actions/merge.js +16 -0
  26. package/dist/core/actions/merge.js.map +1 -0
  27. package/dist/core/actions/rotate.js +36 -0
  28. package/dist/core/actions/rotate.js.map +1 -0
  29. package/dist/core/actions/split.js +65 -0
  30. package/dist/core/actions/split.js.map +1 -0
  31. package/dist/core/atomic.js +61 -0
  32. package/dist/core/atomic.js.map +1 -0
  33. package/dist/core/capabilities.js +59 -0
  34. package/dist/core/capabilities.js.map +1 -0
  35. package/dist/core/compress.js +76 -0
  36. package/dist/core/compress.js.map +1 -0
  37. package/dist/core/describe.js +49 -0
  38. package/dist/core/describe.js.map +1 -0
  39. package/dist/core/errors.js +469 -0
  40. package/dist/core/errors.js.map +1 -0
  41. package/dist/core/execute-jobs.js +122 -0
  42. package/dist/core/execute-jobs.js.map +1 -0
  43. package/dist/core/formats.js +108 -0
  44. package/dist/core/formats.js.map +1 -0
  45. package/dist/core/order.js +44 -0
  46. package/dist/core/order.js.map +1 -0
  47. package/dist/core/output-path.js +176 -0
  48. package/dist/core/output-path.js.map +1 -0
  49. package/dist/core/pages.js +107 -0
  50. package/dist/core/pages.js.map +1 -0
  51. package/dist/core/pdf-compress.js +206 -0
  52. package/dist/core/pdf-compress.js.map +1 -0
  53. package/dist/core/plan.js +42 -0
  54. package/dist/core/plan.js.map +1 -0
  55. package/dist/core/resolve.js +115 -0
  56. package/dist/core/resolve.js.map +1 -0
  57. package/dist/core/run.js +66 -0
  58. package/dist/core/run.js.map +1 -0
  59. package/dist/core/suggest.js +50 -0
  60. package/dist/core/suggest.js.map +1 -0
  61. package/dist/core/types.js +2 -0
  62. package/dist/core/types.js.map +1 -0
  63. package/dist/core/units.js +94 -0
  64. package/dist/core/units.js.map +1 -0
  65. package/dist/core/write-safety.js +128 -0
  66. package/dist/core/write-safety.js.map +1 -0
  67. package/dist/engines/heic.js +166 -0
  68. package/dist/engines/heic.js.map +1 -0
  69. package/dist/engines/image.js +342 -0
  70. package/dist/engines/image.js.map +1 -0
  71. package/dist/engines/pdf.js +444 -0
  72. package/dist/engines/pdf.js.map +1 -0
  73. package/dist/engines/pdfium.js +161 -0
  74. package/dist/engines/pdfium.js.map +1 -0
  75. package/dist/engines/registry.js +65 -0
  76. package/dist/engines/registry.js.map +1 -0
  77. package/dist/engines/types.js +2 -0
  78. package/dist/engines/types.js.map +1 -0
  79. package/dist/engines/word.js +385 -0
  80. package/dist/engines/word.js.map +1 -0
  81. package/dist/index.js +96 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/shell/App.js +1972 -0
  84. package/dist/shell/App.js.map +1 -0
  85. package/dist/shell/ClickTargets.js +183 -0
  86. package/dist/shell/ClickTargets.js.map +1 -0
  87. package/dist/shell/ThemeContext.js +21 -0
  88. package/dist/shell/ThemeContext.js.map +1 -0
  89. package/dist/shell/blocks.js +160 -0
  90. package/dist/shell/blocks.js.map +1 -0
  91. package/dist/shell/clipboard.js +64 -0
  92. package/dist/shell/clipboard.js.map +1 -0
  93. package/dist/shell/commands.js +51 -0
  94. package/dist/shell/commands.js.map +1 -0
  95. package/dist/shell/components/Banner.js +73 -0
  96. package/dist/shell/components/Banner.js.map +1 -0
  97. package/dist/shell/components/CommandPalette.js +37 -0
  98. package/dist/shell/components/CommandPalette.js.map +1 -0
  99. package/dist/shell/components/FileCard.js +59 -0
  100. package/dist/shell/components/FileCard.js.map +1 -0
  101. package/dist/shell/components/HintBar.js +18 -0
  102. package/dist/shell/components/HintBar.js.map +1 -0
  103. package/dist/shell/components/Hints.js +21 -0
  104. package/dist/shell/components/Hints.js.map +1 -0
  105. package/dist/shell/components/MergeList.js +268 -0
  106. package/dist/shell/components/MergeList.js.map +1 -0
  107. package/dist/shell/components/ModeHeader.js +21 -0
  108. package/dist/shell/components/ModeHeader.js.map +1 -0
  109. package/dist/shell/components/PageGrid.js +324 -0
  110. package/dist/shell/components/PageGrid.js.map +1 -0
  111. package/dist/shell/components/PathInput.js +147 -0
  112. package/dist/shell/components/PathInput.js.map +1 -0
  113. package/dist/shell/components/Progress.js +43 -0
  114. package/dist/shell/components/Progress.js.map +1 -0
  115. package/dist/shell/components/Prompt.js +667 -0
  116. package/dist/shell/components/Prompt.js.map +1 -0
  117. package/dist/shell/components/ResultLinks.js +26 -0
  118. package/dist/shell/components/ResultLinks.js.map +1 -0
  119. package/dist/shell/components/Select.js +152 -0
  120. package/dist/shell/components/Select.js.map +1 -0
  121. package/dist/shell/components/Slider.js +48 -0
  122. package/dist/shell/components/Slider.js.map +1 -0
  123. package/dist/shell/components/StagedFiles.js +92 -0
  124. package/dist/shell/components/StagedFiles.js.map +1 -0
  125. package/dist/shell/components/ThemePicker.js +18 -0
  126. package/dist/shell/components/ThemePicker.js.map +1 -0
  127. package/dist/shell/components/UnitRow.js +30 -0
  128. package/dist/shell/components/UnitRow.js.map +1 -0
  129. package/dist/shell/flows/pdf.js +424 -0
  130. package/dist/shell/flows/pdf.js.map +1 -0
  131. package/dist/shell/frame-geometry.js +56 -0
  132. package/dist/shell/frame-geometry.js.map +1 -0
  133. package/dist/shell/hyperlink.js +27 -0
  134. package/dist/shell/hyperlink.js.map +1 -0
  135. package/dist/shell/intro.js +101 -0
  136. package/dist/shell/intro.js.map +1 -0
  137. package/dist/shell/launch.js +75 -0
  138. package/dist/shell/launch.js.map +1 -0
  139. package/dist/shell/mark.js +134 -0
  140. package/dist/shell/mark.js.map +1 -0
  141. package/dist/shell/mouse.js +209 -0
  142. package/dist/shell/mouse.js.map +1 -0
  143. package/dist/shell/redraw.js +36 -0
  144. package/dist/shell/redraw.js.map +1 -0
  145. package/dist/shell/reveal.js +24 -0
  146. package/dist/shell/reveal.js.map +1 -0
  147. package/dist/shell/stage.js +34 -0
  148. package/dist/shell/stage.js.map +1 -0
  149. package/dist/shell/terminal-write.js +16 -0
  150. package/dist/shell/terminal-write.js.map +1 -0
  151. package/dist/shell/theme.js +178 -0
  152. package/dist/shell/theme.js.map +1 -0
  153. package/dist/shell/useFrameOrigin.js +175 -0
  154. package/dist/shell/useFrameOrigin.js.map +1 -0
  155. package/dist/shell/useKeys.js +28 -0
  156. package/dist/shell/useKeys.js.map +1 -0
  157. package/dist/shell/useMouse.js +150 -0
  158. package/dist/shell/useMouse.js.map +1 -0
  159. package/dist/shell/useMouseRouting.js +69 -0
  160. package/dist/shell/useMouseRouting.js.map +1 -0
  161. package/dist/shell/width.js +62 -0
  162. package/dist/shell/width.js.map +1 -0
  163. package/dist/utils/display-path.js +31 -0
  164. package/dist/utils/display-path.js.map +1 -0
  165. package/dist/utils/unescape-path.js +68 -0
  166. package/dist/utils/unescape-path.js.map +1 -0
  167. package/package.json +77 -4
package/README.md CHANGED
@@ -1,3 +1,1037 @@
1
- # Temporary Holding Version
1
+ # Forge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Convert** — a terminal-native file converter for macOS. Command: `forge`.
4
+
5
+ ## What it is
6
+
7
+ Forge takes a file and turns it into another format without leaving the
8
+ terminal. No web upload, no GUI app to open, no ImageMagick incantations to
9
+ remember — point it at a file or a folder, say what you want it to become,
10
+ and it writes the result next to the original (or wherever you tell it to).
11
+
12
+ Version 0.1 converts images: JPEG, PNG, WebP, AVIF, GIF, TIFF, and reads
13
+ HEIC. It also converts between PDF and Word documents (DOCX both ways, DOC
14
+ one way in) — install [LibreOffice](https://www.libreoffice.org/) for
15
+ full-fidelity results; without it, Forge still converts, using a plain-text
16
+ fallback and a note in the result saying so. It runs correctly, not just fast — auto-orienting phone photos,
17
+ flattening transparency instead of turning it black, and stripping GPS data
18
+ from EXIF by default so a converted photo doesn't quietly leak where it was
19
+ taken.
20
+
21
+ The command is `forge` rather than `convert` on purpose: `convert` is
22
+ ImageMagick's legacy binary name, and Homebrew still installs it — a command
23
+ called `convert` would silently shadow or collide with that. The product is
24
+ still called Convert; the binary just has a name of its own.
25
+
26
+ Forge is both a flag-driven CLI, built to be scriptable and usable for daily
27
+ conversions, and an interactive shell — run `forge` with no arguments in a
28
+ real terminal and it walks you through the same conversion by drag-and-drop
29
+ and arrow keys instead of flags. See [Interactive shell](#interactive-shell).
30
+
31
+ ## Installation
32
+
33
+ **Requires macOS and Node 20 or newer** (developed and tested on Node 24).
34
+ Check with `node --version`; if you don't have it, `brew install node`.
35
+
36
+ ```bash
37
+ npm install -g forge-terminal
38
+ ```
39
+
40
+ That puts `forge` on your `PATH`, so it works from any directory. Verify:
41
+
42
+ ```bash
43
+ forge --version
44
+ # 0.1.0
45
+
46
+ forge photo.jpg --to webp
47
+ ```
48
+
49
+ Nothing else needs Homebrew; image conversion is entirely self-contained.
50
+
51
+ ### From source
52
+
53
+ ```bash
54
+ git clone https://github.com/AtharvaN16/forge-terminal.git
55
+ cd forge-terminal
56
+ npm install
57
+ npm run build
58
+ chmod +x dist/index.js # tsc does not preserve the executable bit
59
+ npm link
60
+ ```
61
+
62
+ `npm link` puts your working copy on your `PATH` instead of the published
63
+ package. If you have both, whichever was installed last wins —
64
+ `npm uninstall -g forge-terminal` removes the published one.
65
+
66
+ ### A name to watch out for
67
+
68
+ If you write Solidity, you may already have a `forge` on your `PATH`:
69
+ Foundry ships a binary by that name, and whichever was installed last wins.
70
+ Check before installing:
71
+
72
+ ```bash
73
+ which -a forge
74
+ ```
75
+
76
+ If more than one path comes back, they're shadowing each other. You can
77
+ rename Forge's command when installing from source, by editing the `bin`
78
+ field in `package.json` before running `npm link`:
79
+
80
+ ```json
81
+ "bin": { "convert-forge": "./dist/index.js" }
82
+ ```
83
+
84
+ (The command isn't called `convert` for the same reason: ImageMagick's
85
+ legacy binary already claims that name and Homebrew still installs it.)
86
+
87
+ ### Updating and removing
88
+
89
+ ```bash
90
+ npm update -g forge-terminal # update
91
+ npm uninstall -g forge-terminal # remove
92
+ ```
93
+
94
+ From source, `git pull && npm install && npm run build` updates and
95
+ `npm unlink -g forge-terminal` removes.
96
+
97
+ ## Configuration
98
+
99
+ Forge stores preferences at `~/.config/forge/config.json`, or
100
+ `$XDG_CONFIG_HOME/forge/config.json` when that is set.
101
+
102
+ ```bash
103
+ forge config list # show every setting and where it lives
104
+ forge config set output ~/Desktop # default output folder
105
+ forge config set theme light # dark or light
106
+ forge config set quality 80 # what the quality slider opens on
107
+ forge config path # print the file location
108
+ ```
109
+
110
+ A corrupt or unreadable config never blocks a conversion. Forge falls back to
111
+ defaults, says so once, and carries on — and it validates key by key, so one
112
+ bad setting does not cost you the ones that are fine. Keys written by a newer
113
+ version of Forge survive a write from an older one.
114
+
115
+ ### Themes
116
+
117
+ Forge ships two palettes, built separately rather than one dimmed: a colour
118
+ that reads on `#0e1016` does not read on paper white. The first time you run
119
+ the shell it asks which suits your terminal and remembers the answer.
120
+
121
+ Change it later with `/theme` in the shell, or:
122
+
123
+ ```bash
124
+ forge config set theme light
125
+ ```
126
+
127
+ `NO_COLOR` is honoured and turns both palettes off entirely. Every status
128
+ still carries a symbol *and* a word — `✓ done`, `✕ failed`, `⚠ warning` — so
129
+ nothing depends on colour to be readable.
130
+
131
+ ### Default output folder
132
+
133
+ Desktop is the factory default. The shell's **Save to** step marks whichever
134
+ folder is currently your default and preselects it:
135
+
136
+ ```
137
+ Save to
138
+ ❯ Desktop ~/Desktop default
139
+ Same folder ~/Pictures
140
+ Downloads ~/Downloads
141
+ New subfolder ~/Pictures/converted
142
+
143
+ → ~/Desktop/diagram.webp
144
+ ↑↓ choose · ↵ save · d make default · esc back
145
+ ```
146
+
147
+ Press `d` on any row to make it the new default. It takes effect immediately
148
+ — the tag moves, the banner updates — and it does not advance the flow, since
149
+ you are still choosing where *this* conversion goes.
150
+
151
+ ### Naming the output
152
+
153
+ After choosing where the file goes, Forge asks what to call it, pre-filled
154
+ with the current name and showing the resolved path as you type. `ctrl-u`
155
+ clears the field, arrow keys move the caret, and `esc` goes back to the
156
+ folder list. If a file of that name is already there, Forge asks — keep
157
+ both, rename, replace, or cancel.
158
+
159
+ ## Commands
160
+
161
+ Type `/` in the shell and a list opens:
162
+
163
+ ```
164
+ /convert change a file's format
165
+ /compress make a file smaller
166
+ /pdf page operations on a PDF
167
+ /theme switch between light and dark
168
+ /help list these commands
169
+ ```
170
+
171
+ Typing narrows it, arrows move, Enter runs. Dropping a file without typing
172
+ anything converts, so the common path costs nothing.
173
+
174
+ A leading slash alone does not open the palette — `/Users/me/photo.png` is a
175
+ path, and paths are what this prompt is mostly for. A command has no further
176
+ slashes and no spaces.
177
+
178
+ ## Compressing
179
+
180
+ `/compress` keeps the format and makes the file smaller. It never changes a
181
+ file's extension — that is what `/convert` is for.
182
+
183
+ Two ways to ask:
184
+
185
+ - **By quality** — pick a level on the slider and see what it produced.
186
+ - **To a target size** — say `500kb` and Forge searches for the highest
187
+ quality that fits, reporting each attempt as a real position in a bounded
188
+ sequence. If even the lowest quality overshoots, it writes nothing and tells
189
+ you the smallest size achievable, rather than handing you a file that misses
190
+ the number you asked for.
191
+
192
+ From the flag CLI:
193
+
194
+ ```bash
195
+ forge photo.jpg --quality 60 # compress, same format
196
+ forge photo.jpg --max-size 500kb # compress to fit
197
+ forge *.jpg --max-size 1mb # a whole folder
198
+ ```
199
+
200
+ `--quality` without `--to` compresses; with `--to` it converts, as it always
201
+ has. `--quality` and `--max-size` are mutually exclusive — they ask the same
202
+ question two ways, and Forge will not guess which wins.
203
+
204
+ Compression only applies to formats with a quality dial. A PNG is lossless, so
205
+ there is nothing to trade away; `/convert` it to WebP instead, and Forge says
206
+ so if you try.
207
+
208
+ After compressing, if another format would be meaningfully smaller, Forge says
209
+ so — and it encodes a candidate to find out rather than guessing:
210
+
211
+ ```
212
+ ✓ done photo.jpg → photo-small.jpg
213
+ 4.2 MB → 1.1 MB · 73% smaller
214
+
215
+ ⚠ WebP would be 480 KB — 56% smaller again.
216
+ ↵ convert another · c convert to WebP · o open · s show in finder · ctrl-c close app
217
+ ```
218
+
219
+ ## PDF
220
+
221
+ Five page operations, one flag each: merge, split, extract, delete and
222
+ rotate. None of them take `--to` — a PDF stays a PDF — and only one
223
+ operation runs per invocation:
224
+
225
+ ```bash
226
+ forge a.pdf b.pdf --merge # combine, in argument order
227
+ forge report.pdf --split every-page # one file per page
228
+ forge report.pdf --split every=5 # groups of 5; the last group is shorter
229
+ forge report.pdf --split at=4,8 # cut after pages 4 and 8 → three parts
230
+ forge report.pdf --extract 3-7,12 # keep only these pages, one output file
231
+ forge report.pdf --extract 1,3 --separate # one output file per selected page
232
+ forge report.pdf --delete 1,2 # drop these pages
233
+ forge report.pdf --rotate 90 # quarter turn clockwise
234
+ ```
235
+
236
+ Asking for two at once is rejected outright, not merged into some combined
237
+ behaviour:
238
+
239
+ ```
240
+ $ forge report.pdf --merge --split every-page
241
+ ✕ Invalid arguments
242
+
243
+ Use one operation at a time — got --merge and --split.
244
+ ```
245
+
246
+ ### Page ranges
247
+
248
+ `--extract` and `--delete` share one grammar: comma-separated terms, each
249
+ `N`, `N-M`, or `N-` for "to the end" — `3-7, 12, 20-`. Page numbers are
250
+ 1-based. A page outside the document is an error naming the actual count,
251
+ never a silent clamp:
252
+
253
+ ```
254
+ $ forge report.pdf --extract 1-100
255
+ ✕ Page range not understood
256
+
257
+ "1-100" is outside 1 and 12.
258
+
259
+ This document has 12 pages. Use numbers and spans, like "3-7, 12, 20-".
260
+ ```
261
+
262
+ ### `--split`
263
+
264
+ Three forms, checked in this order:
265
+
266
+ | Form | Meaning |
267
+ | --- | --- |
268
+ | `--split every-page` | one file per page |
269
+ | `--split every=N` | groups of `N` pages; the last group takes whatever's left |
270
+ | `--split at=N,N,...` | cuts after the named 1-based pages — `at=4,8` on a 12-page document gives pages 1-4, 5-8, 9-12 |
271
+
272
+ Anything else is rejected: `--split takes every-page, every=N or at=N,N`.
273
+
274
+ ### `--rotate`
275
+
276
+ Degrees only, and only a multiple of 90 below 360: `90` (quarter turn
277
+ clockwise), `180` (upside down) or `270` (quarter turn back). `45` or `360`
278
+ are both refused rather than rounded. Rotation is additive — rotating an
279
+ already-rotated PDF by another 90° lands at 180°, it doesn't reset to 90°.
280
+
281
+ ### Output names
282
+
283
+ | Operation | Name |
284
+ | --- | --- |
285
+ | `--split` | `report-01.pdf` … `report-12.pdf` — zero-padded to the width of the part count, so a 12-part split doesn't sort `-10` before `-2` in a file listing |
286
+ | `--extract` | `report-extract.pdf` (one output for the whole selection) |
287
+ | `--extract --separate` | `report-p3.pdf`, `report-p12.pdf` — named by page number, not by sequence |
288
+ | `--delete` | `report-trimmed.pdf` |
289
+ | `--rotate` | `report-rotated.pdf` |
290
+ | `--merge` | derived from the inputs' shared parent folder — merging everything in `~/invoices/` writes `invoices-merged.pdf` into that folder; inputs spanning different folders fall back to `<first-file>-merged.pdf` |
291
+
292
+ Every one of these writes beside its source(s) — page operations have no
293
+ `--output` flag, and passing one is refused rather than quietly ignored.
294
+
295
+ ### Write safety
296
+
297
+ A page operation refuses to overwrite an existing output, and refuses to
298
+ write over one of its own inputs. `--force` overrides both of those — but
299
+ never a collision between two of a job's own outputs, which is a bug in the
300
+ request rather than a preference. This is what makes running the same merge
301
+ twice safe rather than destructive: the second run stops instead of folding
302
+ the first run's output back in as one of its own inputs.
303
+
304
+ ```
305
+ $ forge invoices/jan.pdf invoices/feb.pdf --merge
306
+ ✓ 1 file · invoices-merged.pdf
307
+ $ forge invoices/jan.pdf invoices/feb.pdf --merge
308
+ ✕ File already exists
309
+
310
+ invoices-merged.pdf is already there.
311
+
312
+ Pass --force to replace it, or move the existing file out of the way.
313
+ ```
314
+
315
+ (A glob like `invoices/*.pdf --merge` run twice hits a sharper version of the
316
+ same problem: the second run's glob also matches the first run's
317
+ `invoices-merged.pdf`, so it fails with "Output would replace the original"
318
+ instead — one of its own inputs, not just a stale file on disk. Either way,
319
+ nothing gets overwritten without `--force`.)
320
+
321
+ ### PDF → image
322
+
323
+ A PDF can also become a JPEG or PNG — this is `--to`, not one of the five
324
+ page operations above, so it composes with the rest of the flag CLI rather
325
+ than living in `--merge`/`--split`/etc.:
326
+
327
+ ```bash
328
+ forge report.pdf --to jpeg --pages 2-4 --dpi 150
329
+ ```
330
+
331
+ ```
332
+ $ forge report.pdf --to jpeg --pages 2-4 --dpi 150
333
+ ✓ report.pdf → 3 files
334
+ report-2.jpg, report-3.jpg, report-4.jpg
335
+ 1.6 KB → 11.6 KB total
336
+ ```
337
+
338
+ `--pages` uses the same grammar as `--extract`/`--delete` (see
339
+ [Page ranges](#page-ranges) above) and defaults to every page when omitted.
340
+ `--dpi` sets the rasterisation resolution, `36`-`600`, default `150`:
341
+
342
+ ```
343
+ $ forge report.pdf --to png --dpi 35
344
+ ✕ Invalid resolution
345
+
346
+ 35 is not a resolution Forge can use.
347
+
348
+ Give a number between 36 and 600. The default is 150.
349
+ ```
350
+
351
+ A PDF's only targets are `jpeg`, `png`, and `pdf` itself (page operations) —
352
+ asking for anything else is rejected the same way an unsupported image
353
+ target is:
354
+
355
+ ```
356
+ $ forge report.pdf --to webp
357
+ ✕ Can't convert report.pdf to webp
358
+
359
+ report.pdf is a PDF image.
360
+
361
+ Available: jpeg, png, pdf
362
+ ```
363
+
364
+ Output files are named by 1-based page number and zero-padded to the width of
365
+ the *highest page number being written*, not the size of the `--pages`
366
+ selection — so picking pages 1 and 10 still sorts correctly rather than
367
+ listing `-10` before `-2`:
368
+
369
+ ```
370
+ $ forge big.pdf --to jpeg --pages 1,10
371
+ ✓ big.pdf → 2 files
372
+ big-01.jpg, big-10.jpg
373
+ 2.9 KB → 7.7 KB total
374
+ ```
375
+
376
+ The padding follows the pages actually written, so a small selection out of a
377
+ long document is not padded to that document's width:
378
+
379
+ ```
380
+ $ forge big.pdf --to png --pages 1,2 # big.pdf has 300 pages
381
+ ✓ big.pdf → 2 files
382
+ big-1.png, big-2.png
383
+ 4.2 KB → 928 B total
384
+ ```
385
+
386
+ ### image → PDF
387
+
388
+ ```
389
+ $ forge report-1.png --to pdf
390
+ ✓ report-1.png → report-1.pdf
391
+ 5.9 KB → 6.2 KB · 5.8% larger
392
+ ```
393
+
394
+ Each image becomes its own single-page PDF — converting several images with
395
+ `--to pdf` writes one PDF per image, not one PDF containing all of them.
396
+ Combining several files into one PDF is `--merge`, and `--merge` only takes
397
+ PDFs as input.
398
+
399
+ ### Encrypted PDFs
400
+
401
+ Forge can **read** a password-protected PDF — probing and `--to jpeg`/`--to
402
+ png` both work once it has the password. Page operations (`--merge`,
403
+ `--split`, `--extract`, `--delete`, `--rotate`) refuse an encrypted PDF
404
+ outright: they rewrite the file, and Forge cannot write an encrypted one.
405
+
406
+ It cannot **remove** a password either; there is no unlock or decrypt-and-resave
407
+ feature, on purpose. The only libraries that can decrypt and rewrite a PDF
408
+ are AGPL-licensed, and Forge is MIT, so that feature was cut rather than
409
+ shipped under a licence the rest of the project doesn't carry.
410
+
411
+ There is deliberately no `--password` flag — an argument lands in shell
412
+ history and in `ps` output, and PDF passwords are reused often enough that
413
+ leaking one leaks more than one file. Two routes instead:
414
+
415
+ ```
416
+ $ echo -n "hunter2" | forge locked-hunter2.pdf --to png --password-stdin
417
+ ✓ locked-hunter2.pdf → 3 files
418
+ locked-hunter2-1.png, locked-hunter2-2.png, locked-hunter2-3.png
419
+ 2.7 KB → 22.4 KB total
420
+ ```
421
+
422
+ or leave `--password-stdin` off and Forge prompts on stderr, reading one
423
+ line without echoing it back:
424
+
425
+ ```
426
+ $ forge locked-hunter2.pdf --to jpeg
427
+ Password:
428
+ ✓ locked-hunter2.pdf → 3 files
429
+ locked-hunter2-1.jpg, locked-hunter2-2.jpg, locked-hunter2-3.jpg
430
+ 2.7 KB → 16.6 KB total
431
+ ```
432
+
433
+ A wrong password gets the same message an unattempted password does — Forge
434
+ doesn't echo back anything about the attempt itself:
435
+
436
+ ```
437
+ $ echo -n "wrongpass" | forge locked-hunter2.pdf --to png --password-stdin
438
+ ✕ This PDF is password-protected
439
+
440
+ locked-hunter2.pdf is password-protected.
441
+
442
+ Convert it to images instead: forge locked-hunter2.pdf --to jpeg --password-stdin
443
+ ```
444
+
445
+ ### In the shell
446
+
447
+ `/pdf` needs at least one staged PDF (drop a file, then drop another to
448
+ stage a second one — that's how two files end up ready for merge). It opens
449
+ a hub listing all five operations, dimming whichever don't apply to what's
450
+ staged — merge stays dimmed with fewer than two PDFs, the other four need
451
+ exactly one PDF (split additionally needs it to have more than one page) —
452
+ then walks that operation's own options: extract and delete open a page grid
453
+ (`space` toggles, `a` selects all, `r` switches to a typed range) that falls
454
+ back straight to the typed field on a terminal too narrow to fit the grid;
455
+ split's "at points I choose" opens the same grid in cut mode; merge opens a
456
+ reorderable list where files can be picked up and dropped into a new order,
457
+ sorted, removed, or renamed before confirming. A confirm screen lists the
458
+ planned output filenames before anything runs.
459
+
460
+ Choosing an image target for a staged PDF (see [PDF → image](#pdf--image)
461
+ above) adds two steps of its own between target and destination: which pages
462
+ to render — all, or choose from a page grid the same way extract/delete
463
+ does — and the rasterisation resolution. Rendering itself runs a live
464
+ progress bar tracking pages completed against the page count, rather than
465
+ the shell's usual single-file "no percentage" convert step, since a
466
+ multi-page render has a real count to report against.
467
+
468
+ ### Not yet
469
+
470
+ This phase adds PDF↔image conversion and reading a password-protected PDF
471
+ (see [PDF → image](#pdf--image) and [Encrypted PDFs](#encrypted-pdfs)
472
+ above — including in the shell). Still not implemented: compressing a PDF
473
+ and splitting one to a target size, which are phase 4b, and Markdown, HTML
474
+ and Office conversion, which are phase 5. Removing a password from a PDF is
475
+ not planned at all — see [Encrypted PDFs](#encrypted-pdfs) for why.
476
+ Separately, and not specific to PDFs: the shell refuses to convert or
477
+ compress several staged files at once today — that's a deliberate limit
478
+ while batch handling through the shell is still unbuilt, not a bug.
479
+
480
+ ## Usage
481
+
482
+ ```
483
+ forge <inputs...> --to <format> [options]
484
+ ```
485
+
486
+ | Flag | Meaning |
487
+ | --- | --- |
488
+ | `-t, --to <format>` | target format (required) |
489
+ | `-o, --output <path>` | output file or directory |
490
+ | `-q, --quality <n>` | 1–100, lossy targets only, **requires `--to`** |
491
+ | `--background <css>` | fill colour when flattening alpha (default white) |
492
+ | `--keep-metadata` | preserve EXIF/GPS instead of stripping it |
493
+ | `--recursive` | descend into subdirectories |
494
+ | `--force` | allow overwriting an existing output file |
495
+ | `--concurrency <n>` | batch parallelism (default `min(cpus, 4)`) |
496
+ | `--debug` | include stack traces in error output |
497
+ | `--formats` | print the capability matrix |
498
+ | `-V, --version` / `-h, --help` | the usual |
499
+
500
+ `--quality` is rejected unless `--to` is also given — even though it looks
501
+ like it should stand alone. That's deliberate: a future `compress` action
502
+ will accept `--quality` on its own with different semantics (compress in
503
+ place, no format change), and letting `--quality` alone mean something today
504
+ would make it a breaking change later. So for now it's tied to `--to`.
505
+
506
+ ### A single conversion
507
+
508
+ ```
509
+ $ forge sample.jpg --to webp
510
+ ✓ sample.jpg → sample.webp
511
+ 11.5 KB → 3.5 KB · 69.6% smaller
512
+ ```
513
+
514
+ Run it again without `--force` and it refuses to clobber the existing file:
515
+
516
+ ```
517
+ $ forge sample.jpg --to webp
518
+ ✕ File already exists
519
+
520
+ sample.webp is already there.
521
+
522
+ Pass --force to replace it, or choose a different --output.
523
+ $ echo $?
524
+ 1
525
+ ```
526
+
527
+ ```
528
+ $ forge sample.jpg --to webp --force
529
+ ✓ sample.jpg → sample.webp
530
+ 11.5 KB → 3.5 KB · 69.6% smaller
531
+ $ echo $?
532
+ 0
533
+ ```
534
+
535
+ ### Errors are specific, not stack traces
536
+
537
+ ```
538
+ $ forge ghost.jpg --to webp
539
+ ✕ File not found
540
+
541
+ ghost.jpg could not be found.
542
+
543
+ Check the filename and try again.
544
+ $ echo $?
545
+ 1
546
+ ```
547
+
548
+ ```
549
+ $ forge sample.jpg --to mp4
550
+ ✕ Invalid arguments
551
+
552
+ mp4 is not a format Forge knows.
553
+
554
+ Run forge --formats to see what is available.
555
+ $ echo $?
556
+ 2
557
+ ```
558
+
559
+ ```
560
+ $ forge sample.jpg --to heic
561
+ ✕ Can't convert sample.jpg to heic
562
+
563
+ sample.jpg is a JPEG image.
564
+
565
+ Available: jpeg, png, webp, avif, gif, tiff
566
+ $ echo $?
567
+ 1
568
+ ```
569
+
570
+ ```
571
+ $ forge sample.jpg
572
+ ✕ Invalid arguments
573
+
574
+ No target format given.
575
+
576
+ Add --to <format>, for example: forge photo.jpg --to webp
577
+ $ echo $?
578
+ 2
579
+ ```
580
+
581
+ No stack trace ever reaches the terminal unless you pass `--debug`.
582
+
583
+ ### Batches and folders
584
+
585
+ Point Forge at a directory and it converts everything inside (one level
586
+ deep, unless you pass `--recursive`):
587
+
588
+ ```
589
+ $ forge photos --to webp -o ./out/
590
+ ✓ 3 converted
591
+ 6.2 KB → 1.9 KB · 69.6% smaller
592
+
593
+ Output: ./out/
594
+ ```
595
+
596
+ With `--recursive`, the source tree is recreated under the output directory
597
+ instead of being flattened:
598
+
599
+ ```
600
+ $ forge photos --to png -o ./t/ --recursive
601
+ ✓ 4 converted
602
+ 8.3 KB → 1.7 KB · 80% smaller
603
+
604
+ Output: ./t/
605
+ ```
606
+
607
+ ```
608
+ $ find t -type f
609
+ t/photo1.png
610
+ t/photo2.png
611
+ t/photo3.png
612
+ t/sub/deeper/bottom.png
613
+ ```
614
+
615
+ Both glob forms work — `forge *.jpg --to webp` (expanded by your shell) and
616
+ `forge "*.jpg" --to webp` (expanded internally).
617
+
618
+ ### Output path rules
619
+
620
+ | Invocation | Result |
621
+ | --- | --- |
622
+ | `forge a.jpg --to webp` | `./a.webp` |
623
+ | `forge a.jpg --to webp -o ./dist/` | `./dist/a.webp` |
624
+ | `forge a.jpg --to webp -o ./dist/x.webp` | `./dist/x.webp` |
625
+ | `forge ./photos --to webp` | alongside each source |
626
+ | `forge ./photos --to webp -o ./dist/` | flattened into `./dist/` |
627
+ | `forge ./photos --to webp -o ./dist/ --recursive` | tree recreated under `./dist/` |
628
+
629
+ A trailing slash, or an existing directory, means directory. Anything else
630
+ without a file extension is also treated as a directory (`-o dist` is far
631
+ more often a folder than a file named `dist`). Missing intermediate
632
+ directories are created. Exit codes: `0` all succeeded, `1` some failed,
633
+ `2` invalid arguments.
634
+
635
+ ### Bare `forge`
636
+
637
+ Run `forge` with no arguments in a real terminal and it launches the
638
+ interactive shell instead of erroring — see [Interactive shell](#interactive-shell)
639
+ below for the full flow. That launch is gated on stdout actually being a
640
+ TTY, so it only ever happens in a terminal you're sitting at.
641
+
642
+ Piped or non-interactive invocations (no TTY) get a hint instead, and never
643
+ hang waiting for input:
644
+
645
+ ```
646
+ $ forge | cat
647
+ Forge needs a file and a target format.
648
+ Try: forge photo.jpg --to webp
649
+ $ echo $?
650
+ 2
651
+ ```
652
+
653
+ ## Interactive shell
654
+
655
+ Ink/React are only loaded (via a dynamic `import()`) once the TTY check
656
+ above passes, so a normal flag invocation like `forge photo.jpg --to webp`
657
+ never pays to load a UI framework it doesn't use — confirmed by hand: the
658
+ flag CLI's own tests and manual runs are unaffected by the shell's
659
+ existence.
660
+
661
+ The flow is one path, start to finish: drop a file → pick a target format →
662
+ a quality slider, for a lossy target only → pick a destination → convert →
663
+ see the result. What follows is a real session, captured verbatim (with the
664
+ ANSI styling stripped for readability) converting an 11.5 KB JPEG to WebP
665
+ in a 100-column terminal:
666
+
667
+ ```
668
+ ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
669
+ │ › drop a file or type a path │
670
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
671
+ ↵ send · ctrl-c close app
672
+ ```
673
+
674
+ Drag a file in from Finder (its path arrives shell-escaped, e.g. `my\ photo.jpg`,
675
+ and is unescaped automatically) or type a path, then press Enter. Forge
676
+ probes it and shows a one-line card:
677
+
678
+ ```
679
+ sample.jpg · 11.5 KB · JPEG 1600×1200
680
+ ```
681
+
682
+ Then a target menu — built from what the source can actually become, never
683
+ a hardcoded list, which is why HEIC never appears here (see
684
+ [Supported formats](#supported-formats)):
685
+
686
+ ```
687
+ Convert to
688
+ ❯ JPEG universal
689
+ PNG lossless
690
+ WebP smaller, modern
691
+ AVIF smallest
692
+ GIF animation
693
+ TIFF archival
694
+ ↑↓ choose · ↵ confirm · esc back
695
+ ```
696
+
697
+ Arrow keys move `❯`; Enter accepts the highlighted format. Choosing a lossy
698
+ target (WebP, JPEG, AVIF) adds a quality slider; PNG, GIF and TIFF skip
699
+ straight to the destination step:
700
+
701
+ ```
702
+ Quality
703
+ ━━━━━━━━━━━━━━━●━━━━ 80
704
+ ←→ adjust · ↵ confirm · esc back
705
+ ```
706
+
707
+ The destination step offers the source folder, a new `converted/`
708
+ subfolder, `~/Downloads`, or a typed path — the preview line below follows
709
+ whichever preset is highlighted:
710
+
711
+ ```
712
+ Save to
713
+ ❯ Same folder .
714
+ New subfolder converted
715
+ Downloads /Users/you/Downloads
716
+ Type a path…
717
+ → ./sample.webp
718
+ ```
719
+
720
+ Enter on a preset converts immediately — unless writing there would destroy
721
+ something. The shell runs the same `buildPlan()` write-safety checks the flag
722
+ CLI does (§ *Safety* above): converting a JPEG to JPEG in its own folder, which
723
+ is what accepting every default does, resolves the output onto the input and is
724
+ refused outright rather than replacing your original with a lossy re-encode:
725
+
726
+ ```
727
+ ✕ Output would replace the original
728
+ sample.jpg is both the input and the output.
729
+ ```
730
+
731
+ and an output that already exists asks instead of clobbering it:
732
+
733
+ ```
734
+ sample.webp already exists
735
+ ❯ Keep both sample (1).webp
736
+ Replace the existing file is lost
737
+ Cancel pick a different folder
738
+ ```
739
+
740
+ Either way you land back on the destination step. Otherwise:
741
+
742
+ ```
743
+ ✓ sample.jpg → sample.webp
744
+ 11.5 KB → 3.5 KB · 69.6% smaller
745
+
746
+ file:///private/tmp/forge-shell-check/sample.webp · file:///private/tmp/forge-shell-check
747
+ ↵ convert another · o open · r reveal · ctrl-c close app
748
+ ```
749
+
750
+ `o` opens the converted file in its default app and `o` reveals it in
751
+ Finder — both just shell out to macOS's `open`; both actually launched
752
+ Preview and Finder in this run, confirmed by asking each app afterward what
753
+ it had open. `↵` clears the picker and returns to the prompt with this
754
+ result still sitting above it: finished entries are written to the
755
+ terminal with Ink's `<Static>`, which commits them to the real scrollback
756
+ once rather than redrawing them on every frame — confirmed by inspecting
757
+ the raw output stream, which contains no full-screen or scrollback-clearing
758
+ escape codes once a card or result has been printed, only the small live
759
+ region below it being rewritten. `ctrl-c` closes the app.
760
+
761
+ Those two links print as bare `file://` URLs (to wherever the file actually
762
+ landed — `/tmp/forge-shell-check` was this session's scratch directory)
763
+ rather than as the words "Open file" and "Reveal in Finder". Both are
764
+ rendered as OSC 8 hyperlinks — a link *target* wrapped around a label — and
765
+ a terminal that understands OSC 8 (iTerm2, Ghostty, WezTerm, Kitty, VS
766
+ Code's terminal) shows just the label, clickable. Terminal.app doesn't
767
+ understand OSC 8, and neither did the scripted terminal this transcript was
768
+ captured in, so both degrade to the bare, still cmd+clickable URL instead
769
+ of dropping the link entirely — which is exactly what's shown above.
770
+
771
+ ### Terminal support
772
+
773
+ The layout adapts to width rather than wrapping: below 60 columns the
774
+ bordered prompt box, the per-item format hints (`universal`, `lossless`,
775
+ ...), the destination presets' folder paths, and the file card's
776
+ format/dimensions are all dropped so every line stays inside the terminal
777
+ edge; above that, a preset's path is middle-truncated to whatever the width
778
+ leaves for it; at 60 columns and above everything renders
779
+ as pictured above. This re-bands live if you resize the window mid-session,
780
+ not just at launch. Long filenames and paths are truncated from the middle
781
+ (keeping both the start and the extension visible) rather than overflowing
782
+ or wrapping. Meaning is never colour-only: every status is a symbol plus a
783
+ word (`✓`/`✕`/`⚠`), and the selected item in every list is marked with `❯`
784
+ and rendered bold.
785
+
786
+ ### What the shell doesn't do yet
787
+
788
+ - **Batch convert or compress.** `/convert` and `/compress` refuse to run
789
+ against more than one staged file, rather than silently acting on just the
790
+ first — point the flag CLI at a folder instead. Several files *can* be
791
+ staged at once now, but only `/pdf`'s merge is defined by having more than
792
+ one; a paste containing several paths is still read as one path and fails
793
+ to probe as such.
794
+ - **PDF compression and splitting to a target size.** Not in this phase —
795
+ see [PDF § Not yet](#not-yet) above for what's coming and when.
796
+ - **No recent-files list** — every session starts at an empty prompt.
797
+
798
+ ## Keyboard shortcuts
799
+
800
+ In the text field:
801
+
802
+ | Action | Keys |
803
+ | --- | --- |
804
+ | Move a word | Option+Left / Option+Right (also Ctrl+Left / Ctrl+Right) |
805
+ | Start / end of line | Home / End, or Ctrl+A / Ctrl+E |
806
+ | Delete the word before the caret | Option+Backspace, or Ctrl+W |
807
+ | Delete the word after the caret | Option+fn+Delete |
808
+ | Delete to start / end of line | Ctrl+U / Ctrl+K |
809
+ | Cut / paste the selection | Ctrl+X / Ctrl+Y |
810
+ | Extend a selection | Shift+Left / Shift+Right |
811
+
812
+ **On Cmd shortcuts.** Cmd is the line-scoped counterpart to Option's
813
+ word-scoped one, not a word-movement shortcut itself: Cmd+Left/Right go to
814
+ the start/end of the line and Cmd+Backspace deletes to the line start — the
815
+ same three things Home/End (or Ctrl+A/Ctrl+E) and Ctrl+U already do above.
816
+ Cmd+A selects the whole field and has no other binding. All four work only
817
+ in terminals that speak the kitty keyboard protocol — iTerm2, Ghostty,
818
+ WezTerm, kitty, and the VS Code integrated terminal. Terminal.app cannot
819
+ report Cmd at all: its key-mapping UI does not offer Command as a modifier,
820
+ so no Cmd chord produces any bytes there. Home/End, Ctrl+A/Ctrl+E and Ctrl+U
821
+ cover the same ground everywhere; selecting the whole field has no fallback
822
+ in Terminal.app.
823
+
824
+ ## Supported formats
825
+
826
+ ```
827
+ $ forge --formats
828
+ Formats
829
+
830
+ JPEG .jpg .jpeg read and write
831
+ PNG .png read and write
832
+ WebP .webp read and write
833
+ AVIF .avif read and write
834
+ HEIC .heic .heif read only
835
+ GIF .gif read and write
836
+ TIFF .tif .tiff read and write
837
+ PDF .pdf read and write
838
+
839
+ HEIC is read only because the image library cannot encode it.
840
+ ```
841
+
842
+ PDF's "read and write" covers the five page operations plus rasterising to
843
+ JPEG/PNG and encoding images to PDF — see [PDF](#pdf) above for the actual
844
+ grammar; it isn't a peer of the image formats above it in every respect
845
+ (there's no `--quality` for it, for one).
846
+
847
+ **Why HEIC is read-only:** Forge's image engine is Sharp/libvips, and the
848
+ prebuilt libvips binary can decode HEVC (what iPhones save HEIC as) but
849
+ cannot encode it — encoding attempts fail with `heifsave: Unsupported
850
+ compression`. So converting *from* `.heic` works normally; converting *to*
851
+ `.heic` is refused with a clear error listing what you can target instead,
852
+ rather than failing partway through an encode.
853
+
854
+ Formats are probed by file content (Sharp's magic-byte detection), not by
855
+ extension — a `.jpg` that's secretly a PNG is handled correctly, and the
856
+ target list is never a hardcoded string list.
857
+
858
+ ### HEIC
859
+
860
+ Reading HEIC needs a decoder Sharp's prebuilt binary does not ship. HEVC sits
861
+ in a patent pool, so upstream's position is that HEIC support requires a
862
+ globally installed libvips built against libheif, libde265 and x265 — AVIF
863
+ works in the same container only because AV1 is royalty-free.
864
+
865
+ Forge decodes HEIC with `/usr/bin/sips` instead, which uses the same system
866
+ codec Preview does. No install, no build step. If `sips` is missing, HEIC
867
+ conversion is the only thing that stops working.
868
+
869
+ Writing HEIC is still unavailable: Sharp cannot encode HEVC at all.
870
+
871
+ ## Correctness rules
872
+
873
+ These apply automatically, unconditionally, unless a flag opts out:
874
+
875
+ 1. **Auto-orient first.** EXIF orientation is applied before any other
876
+ operation, so photos from phones don't come out sideways.
877
+ 2. **Flatten alpha when the target can't carry it.** Converting a
878
+ transparent PNG to JPEG fills with white (or `--background`), not black.
879
+ 3. **Strip metadata by default, always keep colour profile.** EXIF and GPS
880
+ are removed unless `--keep-metadata`; the ICC colour profile is always
881
+ kept so colours don't shift on wide-gamut displays.
882
+ 4. **Never drop animation silently.** An animated source converting to a
883
+ format that can't animate keeps only the first frame — and attaches a
884
+ warning to the result, rather than converting quietly and losing frames.
885
+ 5. **Bounded concurrency.** Batches run `min(cpus, 4)` conversions at a
886
+ time, so Sharp's threadpool isn't overwhelmed.
887
+
888
+ Writes are atomic: output goes to a temp file in the destination directory
889
+ and is renamed into place only on success, so a crash mid-encode never
890
+ leaves a truncated file where a good one used to be.
891
+
892
+ ## Architecture
893
+
894
+ ```
895
+ src/
896
+ ├── core/ pure logic — no stdout, no UI framework
897
+ │ ├── types.ts shared types: SourceInfo, Job, Result, FormatId...
898
+ │ ├── formats.ts format registry (labels, extensions, capabilities)
899
+ │ ├── capabilities.ts readable/writable format sets, targetsFor()
900
+ │ ├── actions.ts Action/OptionSpec — what convert asks for, and in what order
901
+ │ ├── resolve.ts paths / globs / directories → SourceInfo[]
902
+ │ ├── plan.ts (sources, target, options) → Job[]
903
+ │ ├── run.ts bounded-concurrency batch runner, emits events
904
+ │ ├── output-path.ts output path resolution (the table above)
905
+ │ ├── units.ts byte / percentage formatting
906
+ │ └── errors.ts ForgeError taxonomy and rendering
907
+ │
908
+ ├── engines/
909
+ │ ├── types.ts Engine interface (reads, writes, probe, convert)
910
+ │ ├── image.ts Sharp-backed engine — the correctness rules live here
911
+ │ └── registry.ts engine list, format→engine lookup, engine-agnostic probe()
912
+ │
913
+ ├── cli/
914
+ │ ├── args.ts Commander wiring → Intent
915
+ │ ├── execute.ts runs an Intent, returns exit code + stdout/stderr
916
+ │ └── report.ts stdout formatting (success, batch, errors, --formats)
917
+ │
918
+ ├── shell/ the interactive shell (Ink + React) — the only place
919
+ │ │ that renders to a real terminal frame by frame
920
+ │ ├── App.tsx the state machine: file → target → quality →
921
+ │ │ destination → convert → result; the only file
922
+ │ │ that knows the flow
923
+ │ ├── blocks.tsx HistoryBlock/HistoryEntry — what gets committed to
924
+ │ │ <Static> scrollback (file cards, results, errors)
925
+ │ ├── launch.tsx render(<App/>), awaits waitUntilExit()
926
+ │ ├── width.ts width bands (<60 compact) and middle-ellipsis
927
+ │ │ truncation, so nothing overflows or wraps
928
+ │ ├── theme.ts symbols and colour tokens — meaning is carried by
929
+ │ │ symbol + word, never colour alone
930
+ │ ├── hyperlink.ts OSC 8 links with a plain-URL fallback
931
+ │ ├── reveal.ts shells out to macOS `open` / `open -R`
932
+ │ └── components/
933
+ │ ├── Prompt.tsx the bordered/unbordered text input; drop target
934
+ │ ├── Select.tsx arrow-key list picker (❯ + bold selection)
935
+ │ ├── Slider.tsx the quality bar
936
+ │ ├── PathInput.tsx destination picker: presets, plus type-a-path
937
+ │ ├── FileCard.tsx the dropped-file summary line
938
+ │ └── Hints.tsx the "key · action" row under each stage
939
+ │
940
+ ├── utils/
941
+ │ └── unescape-path.ts undoes shell escaping on a dragged-and-dropped path
942
+ │
943
+ └── index.ts entry point: TTY detection, dispatches to execute()
944
+ or (on a real TTY, bare invocation) launchShell()
945
+ ```
946
+
947
+ **The invariant:** `core/` and `engines/` import no UI framework and never
948
+ write to stdout — everything they produce is data (`Job`, `Result`,
949
+ `ForgeError`, `RunEvent`). This is what keeps the engine testable without a
950
+ terminal, and it's also what lets the shell consume the exact same
951
+ `core`/`engines` layer the flag CLI does, unchanged — `App.tsx` calls
952
+ `convertAction.plan()` and `runJobs()` directly, the same functions
953
+ `cli/execute.ts` calls. `src/index.ts` detects whether stdout is a TTY:
954
+ non-interactive invocations (piped, scripted, or no TTY) resolve to the CLI
955
+ path and print a hint rather than blocking; a bare `forge` on a real TTY
956
+ dynamically imports `shell/launch.js` and hands off to it instead.
957
+
958
+ ## Development
959
+
960
+ ```bash
961
+ npm run dev # run from source with tsx, no build step
962
+ npm run build # tsc -p tsconfig.json → dist/
963
+ npm run typecheck # tsc --noEmit over src + tests
964
+ npm run lint # biome check src tests
965
+ npm run format # biome format --write src tests
966
+ ```
967
+
968
+ TypeScript runs in strict mode with `noUncheckedIndexedAccess` and
969
+ `noImplicitOverride` on. Biome replaces ESLint + Prettier with one dependency
970
+ and one config.
971
+
972
+ ## Testing
973
+
974
+ ```bash
975
+ npm test # vitest run
976
+ npm run test:watch
977
+ ```
978
+
979
+ 789 tests, all passing. Fixtures (transparent PNGs, EXIF-rotated JPEGs,
980
+ animated GIFs, HEIC/AVIF samples) are generated by Sharp — or, for HEIC,
981
+ `sips` — at test time, never committed as binaries; the one exception is
982
+ `tests/fixtures/locked-hunter2.pdf`, a real encrypted PDF (password
983
+ `hunter2`) checked in because pdf-lib can't produce an encrypted document
984
+ itself. Coverage includes:
985
+
986
+ - **Engine correctness** — the two reproduced defects (transparent-PNG→JPEG
987
+ going black, EXIF-rotated images staying sideways) as regression tests,
988
+ plus animation handling and the JPEG/PNG/WebP/HEIC/AVIF conversion pairs.
989
+ - **Core** — output path resolution, the capability graph, glob and
990
+ directory resolution, concurrency limiting, atomic writes leaving no temp
991
+ file behind on failure.
992
+ - **Errors** — one test per `ErrorCode`, including that no stack trace
993
+ leaks without `--debug`.
994
+ - **CLI** — argument parsing and exit codes, including the `--quality`
995
+ without `--to` rejection above, and that a bare `forge` on a TTY hands off
996
+ to the shell rather than erroring.
997
+ - **PDF rasterisation** — page selection and DPI bounds, zero-padded output
998
+ naming keyed to the document's page count, reading an encrypted PDF by
999
+ both password routes, and that a wrong password never leaks the attempted
1000
+ string into an error message.
1001
+ - **Shell** — `ink-testing-library` driving real keystrokes through every
1002
+ stage: arrow-key selection, the quality slider, the destination presets
1003
+ and typed-path fallback, a full probe-to-result conversion, dropped paths
1004
+ that are shell-escaped or carry an embedded CR/LF, that no rendered line
1005
+ exceeds the terminal width at four widths, and — new this phase — the
1006
+ page-grid and resolution steps for PDF→image plus the live per-page
1007
+ progress bar.
1008
+
1009
+ ## Roadmap
1010
+
1011
+ Not yet built, in rough order:
1012
+
1013
+ - **Batch conversion through the shell** — the flag CLI already converts a
1014
+ whole folder; the shell only ever probes and converts one file per
1015
+ session right now.
1016
+ - **A real action menu** — the shell's data model already supports more
1017
+ than one `Action` (`actionsFor(source)`), but with only `convert`
1018
+ registered it skips straight past a menu of one. This is what the next
1019
+ two roadmap items would turn on.
1020
+ - **Compress action** — quality/size reduction without a format change;
1021
+ the reason `--quality` requires `--to` today.
1022
+ - **Resize action.**
1023
+ - **`/slash` commands** in the shell, and **a recent-files list** so a
1024
+ session doesn't always start from an empty prompt.
1025
+ - **A video engine** — Sharp can't do it; it will sit behind the same
1026
+ `Engine` interface `image.ts` and the PDF engine already implement, so the
1027
+ CLI and format menu won't need to change to support it. The PDF engine
1028
+ itself now covers page operations and PDF↔image (see [PDF](#pdf) above);
1029
+ PDF compression and splitting to a target size are still to come.
1030
+
1031
+ Explicitly out of scope for 0.1: HEIC encoding (the underlying library
1032
+ can't), DOCX/PPTX/SVG output, MP4/MP3, recursive watch mode, config files,
1033
+ presets.
1034
+
1035
+ ## License
1036
+
1037
+ MIT