forge-terminal 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +1317 -2
- package/dist/chunks/adm-zip-SQKLKBDP.js +3 -0
- package/dist/chunks/available-2VX7K7W6.js +3 -0
- package/dist/chunks/boot-ODZZHFUI.js +3 -0
- package/dist/chunks/cfb-V6M2PYOD.js +13 -0
- package/dist/chunks/chunk-2WYHI73Y.js +3 -0
- package/dist/chunks/chunk-4YHKTP7I.js +3 -0
- package/dist/chunks/chunk-5PYTOHLZ.js +3 -0
- package/dist/chunks/chunk-7YQR2MVH.js +3 -0
- package/dist/chunks/chunk-DRBA23IQ.js +3 -0
- package/dist/chunks/chunk-EOYBXOCV.js +4 -0
- package/dist/chunks/chunk-FQV57RMH.js +3 -0
- package/dist/chunks/chunk-IMKI5F4I.js +4 -0
- package/dist/chunks/chunk-J7FLFHQJ.js +3 -0
- package/dist/chunks/chunk-L2WK7CJG.js +3 -0
- package/dist/chunks/chunk-LFE3WRU4.js +3 -0
- package/dist/chunks/chunk-MHFY7HF6.js +10 -0
- package/dist/chunks/chunk-PBIS2ONZ.js +3 -0
- package/dist/chunks/chunk-QVACE4IE.js +3 -0
- package/dist/chunks/chunk-TMUK2DD3.js +3 -0
- package/dist/chunks/chunk-UNVHKJW4.js +41 -0
- package/dist/chunks/chunk-V4GHQGQM.js +4 -0
- package/dist/chunks/chunk-VB665HTV.js +3 -0
- package/dist/chunks/chunk-YHK5VE5R.js +3 -0
- package/dist/chunks/colour-QV2C3R7R.js +3 -0
- package/dist/chunks/config-command-UXJY623L.js +3 -0
- package/dist/chunks/dist-J2V6ITHG.js +29 -0
- package/dist/chunks/es-T2U7NBLD.js +3 -0
- package/dist/chunks/execute-4WJCUM7J.js +3 -0
- package/dist/chunks/extensions-command-6WZV2AES.js +3 -0
- package/dist/chunks/launch-2OI4ZLBQ.js +66 -0
- package/dist/chunks/lib-TPEJ5CJJ.js +46 -0
- package/dist/chunks/lock-R6GZXCCW.js +3 -0
- package/dist/chunks/manager-H52ENJOH.js +4 -0
- package/dist/chunks/paths-XY2345OS.js +3 -0
- package/dist/chunks/pdf-compress-IMRFBLZF.js +3 -0
- package/dist/chunks/react-devtools-core-UM4FS6CU.js +3 -0
- package/dist/chunks/run-N3F4EM7E.js +4 -0
- package/dist/chunks/server-5RWSVTOM.js +73 -0
- package/dist/chunks/theme-GW7CQPUO.js +3 -0
- package/dist/chunks/word-OGQ2KZAJ.js +24 -0
- package/dist/index.js +68 -0
- package/dist/third-party-licenses.txt +2856 -0
- package/package.json +84 -4
- package/skills/forge/SKILL.md +128 -0
package/README.md
CHANGED
|
@@ -1,3 +1,1318 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Forge
|
|
2
2
|
|
|
3
|
-
|
|
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.2.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
|
+
## Boost resolution and remove background
|
|
220
|
+
|
|
221
|
+
Two image operations that need a model, so they are optional extensions rather
|
|
222
|
+
than part of the install. Both need macOS 14 or later. Nothing downloads until
|
|
223
|
+
you ask:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
forge extensions # list: installed or not, size, licence
|
|
227
|
+
forge extensions add boost # about 15 MB; Apple Silicon only for now
|
|
228
|
+
forge extensions add remove-background # about 32 KB
|
|
229
|
+
forge extensions remove boost
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
forge photo.jpg --sharpen # photo-sharp.png (the same size, sharper)
|
|
234
|
+
forge photo.jpg --boost # photo-2x.png (2x, the default)
|
|
235
|
+
forge photo.jpg --boost 4 # photo-4x.png
|
|
236
|
+
forge photo.jpg --remove-bg # photo-cutout.png
|
|
237
|
+
forge photo.jpg --remove-bg --to webp
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Output goes beside the source unless `-o` says otherwise. Boost keeps
|
|
241
|
+
transparency, and flattens it onto `--background` only when `--to` names a
|
|
242
|
+
format that cannot carry it. A cutout must be saved in a format that holds
|
|
243
|
+
transparency (PNG, WebP, AVIF, TIFF); JPEG is refused, because flattening would
|
|
244
|
+
undo the cutout. Without the extension installed, either flag stops with
|
|
245
|
+
`extension-missing` and the install command (exit 1). Output more than 16,384
|
|
246
|
+
px on a side, or over 100 MP, is refused before anything runs.
|
|
247
|
+
|
|
248
|
+
`forge probe` lists `boost` / `remove-background` among a file's `actions` only
|
|
249
|
+
while that extension is installed, and `--json` results report `op: "boost"` or
|
|
250
|
+
`op: "remove-background"`. `forge_convert` accepts `sharpen: true`, `boost: 2 | 4` and
|
|
251
|
+
`removeBackground: true`, with the same `extension-missing` tool error.
|
|
252
|
+
|
|
253
|
+
The shell's enhance Done shows the real pictures in iTerm2, WezTerm, Kitty and Ghostty (a half-block close-up elsewhere); `FORGE_INLINE_IMAGES=0` turns them off, `=1` forces them on (e.g. tmux with passthrough).
|
|
254
|
+
|
|
255
|
+
## PDF
|
|
256
|
+
|
|
257
|
+
Five page operations, one flag each: merge, split, extract, delete and
|
|
258
|
+
rotate. None of them take `--to` — a PDF stays a PDF — and only one
|
|
259
|
+
operation runs per invocation:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
forge a.pdf b.pdf --merge # combine, in argument order
|
|
263
|
+
forge report.pdf --split every-page # one file per page
|
|
264
|
+
forge report.pdf --split every=5 # groups of 5; the last group is shorter
|
|
265
|
+
forge report.pdf --split at=4,8 # cut after pages 4 and 8 → three parts
|
|
266
|
+
forge report.pdf --extract 3-7,12 # keep only these pages, one output file
|
|
267
|
+
forge report.pdf --extract 1,3 --separate # one output file per selected page
|
|
268
|
+
forge report.pdf --delete 1,2 # drop these pages
|
|
269
|
+
forge report.pdf --rotate 90 # quarter turn clockwise
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Asking for two at once is rejected outright, not merged into some combined
|
|
273
|
+
behaviour:
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
$ forge report.pdf --merge --split every-page
|
|
277
|
+
✕ Invalid arguments
|
|
278
|
+
|
|
279
|
+
Use one operation at a time — got --merge and --split.
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Page ranges
|
|
283
|
+
|
|
284
|
+
`--extract` and `--delete` share one grammar: comma-separated terms, each
|
|
285
|
+
`N`, `N-M`, or `N-` for "to the end" — `3-7, 12, 20-`. Page numbers are
|
|
286
|
+
1-based. A page outside the document is an error naming the actual count,
|
|
287
|
+
never a silent clamp:
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
$ forge report.pdf --extract 1-100
|
|
291
|
+
✕ Page range not understood
|
|
292
|
+
|
|
293
|
+
"1-100" is outside 1 and 12.
|
|
294
|
+
|
|
295
|
+
This document has 12 pages. Use numbers and spans, like "3-7, 12, 20-".
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### `--split`
|
|
299
|
+
|
|
300
|
+
Three forms, checked in this order:
|
|
301
|
+
|
|
302
|
+
| Form | Meaning |
|
|
303
|
+
| --- | --- |
|
|
304
|
+
| `--split every-page` | one file per page |
|
|
305
|
+
| `--split every=N` | groups of `N` pages; the last group takes whatever's left |
|
|
306
|
+
| `--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 |
|
|
307
|
+
|
|
308
|
+
Anything else is rejected: `--split takes every-page, every=N or at=N,N`.
|
|
309
|
+
|
|
310
|
+
### `--rotate`
|
|
311
|
+
|
|
312
|
+
Degrees only, and only a multiple of 90 below 360: `90` (quarter turn
|
|
313
|
+
clockwise), `180` (upside down) or `270` (quarter turn back). `45` or `360`
|
|
314
|
+
are both refused rather than rounded. Rotation is additive — rotating an
|
|
315
|
+
already-rotated PDF by another 90° lands at 180°, it doesn't reset to 90°.
|
|
316
|
+
|
|
317
|
+
### Output names
|
|
318
|
+
|
|
319
|
+
| Operation | Name |
|
|
320
|
+
| --- | --- |
|
|
321
|
+
| `--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 |
|
|
322
|
+
| `--extract` | `report-extract.pdf` (one output for the whole selection) |
|
|
323
|
+
| `--extract --separate` | `report-p3.pdf`, `report-p12.pdf` — named by page number, not by sequence |
|
|
324
|
+
| `--delete` | `report-trimmed.pdf` |
|
|
325
|
+
| `--rotate` | `report-rotated.pdf` |
|
|
326
|
+
| `--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` |
|
|
327
|
+
|
|
328
|
+
Every one of these writes beside its source(s) — page operations have no
|
|
329
|
+
`--output` flag, and passing one is refused rather than quietly ignored.
|
|
330
|
+
|
|
331
|
+
### Write safety
|
|
332
|
+
|
|
333
|
+
A page operation refuses to overwrite an existing output, and refuses to
|
|
334
|
+
write over one of its own inputs. `--force` overrides both of those — but
|
|
335
|
+
never a collision between two of a job's own outputs, which is a bug in the
|
|
336
|
+
request rather than a preference. This is what makes running the same merge
|
|
337
|
+
twice safe rather than destructive: the second run stops instead of folding
|
|
338
|
+
the first run's output back in as one of its own inputs.
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
$ forge invoices/jan.pdf invoices/feb.pdf --merge
|
|
342
|
+
✓ 1 file · invoices-merged.pdf
|
|
343
|
+
$ forge invoices/jan.pdf invoices/feb.pdf --merge
|
|
344
|
+
✕ File already exists
|
|
345
|
+
|
|
346
|
+
invoices-merged.pdf is already there.
|
|
347
|
+
|
|
348
|
+
Pass --force to replace it, or move the existing file out of the way.
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
(A glob like `invoices/*.pdf --merge` run twice hits a sharper version of the
|
|
352
|
+
same problem: the second run's glob also matches the first run's
|
|
353
|
+
`invoices-merged.pdf`, so it fails with "Output would replace the original"
|
|
354
|
+
instead — one of its own inputs, not just a stale file on disk. Either way,
|
|
355
|
+
nothing gets overwritten without `--force`.)
|
|
356
|
+
|
|
357
|
+
### PDF → image
|
|
358
|
+
|
|
359
|
+
A PDF can also become a JPEG or PNG — this is `--to`, not one of the five
|
|
360
|
+
page operations above, so it composes with the rest of the flag CLI rather
|
|
361
|
+
than living in `--merge`/`--split`/etc.:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
forge report.pdf --to jpeg --pages 2-4 --dpi 150
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
$ forge report.pdf --to jpeg --pages 2-4 --dpi 150
|
|
369
|
+
✓ report.pdf → 3 files
|
|
370
|
+
report-2.jpg, report-3.jpg, report-4.jpg
|
|
371
|
+
1.6 KB → 11.6 KB total
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
`--pages` uses the same grammar as `--extract`/`--delete` (see
|
|
375
|
+
[Page ranges](#page-ranges) above) and defaults to every page when omitted.
|
|
376
|
+
`--dpi` sets the rasterisation resolution, `36`-`600`, default `150`:
|
|
377
|
+
|
|
378
|
+
```
|
|
379
|
+
$ forge report.pdf --to png --dpi 35
|
|
380
|
+
✕ Invalid resolution
|
|
381
|
+
|
|
382
|
+
35 is not a resolution Forge can use.
|
|
383
|
+
|
|
384
|
+
Give a number between 36 and 600. The default is 150.
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
A PDF's only targets are `jpeg`, `png`, and `pdf` itself (page operations) —
|
|
388
|
+
asking for anything else is rejected the same way an unsupported image
|
|
389
|
+
target is:
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
$ forge report.pdf --to webp
|
|
393
|
+
✕ Can't convert report.pdf to webp
|
|
394
|
+
|
|
395
|
+
report.pdf is a PDF image.
|
|
396
|
+
|
|
397
|
+
Available: jpeg, png, pdf
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Output files are named by 1-based page number and zero-padded to the width of
|
|
401
|
+
the *highest page number being written*, not the size of the `--pages`
|
|
402
|
+
selection — so picking pages 1 and 10 still sorts correctly rather than
|
|
403
|
+
listing `-10` before `-2`:
|
|
404
|
+
|
|
405
|
+
```
|
|
406
|
+
$ forge big.pdf --to jpeg --pages 1,10
|
|
407
|
+
✓ big.pdf → 2 files
|
|
408
|
+
big-01.jpg, big-10.jpg
|
|
409
|
+
2.9 KB → 7.7 KB total
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
The padding follows the pages actually written, so a small selection out of a
|
|
413
|
+
long document is not padded to that document's width:
|
|
414
|
+
|
|
415
|
+
```
|
|
416
|
+
$ forge big.pdf --to png --pages 1,2 # big.pdf has 300 pages
|
|
417
|
+
✓ big.pdf → 2 files
|
|
418
|
+
big-1.png, big-2.png
|
|
419
|
+
4.2 KB → 928 B total
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### image → PDF
|
|
423
|
+
|
|
424
|
+
```
|
|
425
|
+
$ forge report-1.png --to pdf
|
|
426
|
+
✓ report-1.png → report-1.pdf
|
|
427
|
+
5.9 KB → 6.2 KB · 5.8% larger
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Each image becomes its own single-page PDF — converting several images with
|
|
431
|
+
`--to pdf` writes one PDF per image, not one PDF containing all of them.
|
|
432
|
+
Combining several files into one PDF is `--merge`, and `--merge` only takes
|
|
433
|
+
PDFs as input.
|
|
434
|
+
|
|
435
|
+
### Encrypted PDFs
|
|
436
|
+
|
|
437
|
+
Forge can **read** a password-protected PDF — probing and `--to jpeg`/`--to
|
|
438
|
+
png` both work once it has the password. Page operations (`--merge`,
|
|
439
|
+
`--split`, `--extract`, `--delete`, `--rotate`) refuse an encrypted PDF
|
|
440
|
+
outright: they rewrite the file, and Forge cannot write an encrypted one.
|
|
441
|
+
`forge probe` says so: for an encrypted PDF it lists only the image formats
|
|
442
|
+
as targets and `convert` as the only action.
|
|
443
|
+
|
|
444
|
+
It cannot **remove** a password either; there is no unlock or decrypt-and-resave
|
|
445
|
+
feature, on purpose. The only libraries that can decrypt and rewrite a PDF
|
|
446
|
+
are AGPL-licensed, and Forge is MIT, so that feature was cut rather than
|
|
447
|
+
shipped under a licence the rest of the project doesn't carry.
|
|
448
|
+
|
|
449
|
+
There is deliberately no `--password` flag — an argument lands in shell
|
|
450
|
+
history and in `ps` output, and PDF passwords are reused often enough that
|
|
451
|
+
leaking one leaks more than one file. Two routes instead:
|
|
452
|
+
|
|
453
|
+
```
|
|
454
|
+
$ echo -n "hunter2" | forge locked-hunter2.pdf --to png --password-stdin
|
|
455
|
+
✓ locked-hunter2.pdf → 3 files
|
|
456
|
+
locked-hunter2-1.png, locked-hunter2-2.png, locked-hunter2-3.png
|
|
457
|
+
2.7 KB → 22.4 KB total
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
or, at a terminal, leave `--password-stdin` off and Forge prompts on stderr,
|
|
461
|
+
reading one line without echoing it back:
|
|
462
|
+
|
|
463
|
+
```
|
|
464
|
+
$ forge locked-hunter2.pdf --to jpeg
|
|
465
|
+
Password:
|
|
466
|
+
✓ locked-hunter2.pdf → 3 files
|
|
467
|
+
locked-hunter2-1.jpg, locked-hunter2-2.jpg, locked-hunter2-3.jpg
|
|
468
|
+
2.7 KB → 16.6 KB total
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
A wrong password is told apart from a missing one, and Forge never echoes the
|
|
472
|
+
attempt itself:
|
|
473
|
+
|
|
474
|
+
```
|
|
475
|
+
$ echo -n "wrongpass" | forge locked-hunter2.pdf --to png --password-stdin
|
|
476
|
+
✕ This PDF is password-protected
|
|
477
|
+
|
|
478
|
+
locked-hunter2.pdf is password-protected.
|
|
479
|
+
|
|
480
|
+
That password didn't open it. Check it and try again.
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
`--password-stdin` reads one line, so a pipe that stays open after sending
|
|
484
|
+
the password does not hold Forge up. Without a terminal (piped, scripted, or
|
|
485
|
+
driven by an agent) Forge never prompts: an encrypted PDF without
|
|
486
|
+
`--password-stdin` fails at once with exit 1.
|
|
487
|
+
|
|
488
|
+
### In the shell
|
|
489
|
+
|
|
490
|
+
`/pdf` needs at least one staged PDF (drop a file, then drop another to
|
|
491
|
+
stage a second one — that's how two files end up ready for merge). It opens
|
|
492
|
+
a hub listing all five operations, dimming whichever don't apply to what's
|
|
493
|
+
staged — merge stays dimmed with fewer than two PDFs, the other four need
|
|
494
|
+
exactly one PDF (split additionally needs it to have more than one page) —
|
|
495
|
+
then walks that operation's own options: extract and delete open a page grid
|
|
496
|
+
(`space` toggles, `a` selects all, `r` switches to a typed range) that falls
|
|
497
|
+
back straight to the typed field on a terminal too narrow to fit the grid;
|
|
498
|
+
split's "at points I choose" opens the same grid in cut mode; merge opens a
|
|
499
|
+
reorderable list where files can be picked up and dropped into a new order,
|
|
500
|
+
sorted, removed, or renamed before confirming. A confirm screen lists the
|
|
501
|
+
planned output filenames before anything runs.
|
|
502
|
+
|
|
503
|
+
Choosing an image target for a staged PDF (see [PDF → image](#pdf--image)
|
|
504
|
+
above) adds two steps of its own between target and destination: which pages
|
|
505
|
+
to render — all, or choose from a page grid the same way extract/delete
|
|
506
|
+
does — and the rasterisation resolution. Rendering itself runs a live
|
|
507
|
+
progress bar tracking pages completed against the page count, rather than
|
|
508
|
+
the shell's usual single-file "no percentage" convert step, since a
|
|
509
|
+
multi-page render has a real count to report against.
|
|
510
|
+
|
|
511
|
+
### Not yet
|
|
512
|
+
|
|
513
|
+
PDF↔image conversion, reading a password-protected PDF (see [PDF →
|
|
514
|
+
image](#pdf--image) and [Encrypted PDFs](#encrypted-pdfs) above — including
|
|
515
|
+
in the shell), and compressing a PDF that holds images (`forge scan.pdf
|
|
516
|
+
--max-size 2mb`) all work. A PDF that is only text and layout has nothing
|
|
517
|
+
compression can shrink, and Forge says so. Still not implemented: Markdown,
|
|
518
|
+
HTML and Office conversion beyond Word. Removing a password from a PDF is not
|
|
519
|
+
planned at all — see [Encrypted PDFs](#encrypted-pdfs) for why. Separately,
|
|
520
|
+
and not specific to PDFs: the shell refuses to convert or compress several
|
|
521
|
+
staged files at once today — that's a deliberate limit while batch handling
|
|
522
|
+
through the shell is still unbuilt, not a bug.
|
|
523
|
+
|
|
524
|
+
## Colour
|
|
525
|
+
|
|
526
|
+
Two things for designers: an image's palette, and a tonal scale from one
|
|
527
|
+
colour. Both are in the shell as its fourth mode, and on the command line.
|
|
528
|
+
|
|
529
|
+
### In the shell
|
|
530
|
+
|
|
531
|
+
Press **4** (or type `/colour`). Home shows two cards, **Palette** and
|
|
532
|
+
**Scale**. Choose one with ←→ and open it with ↵. You can also drop an image
|
|
533
|
+
straight onto colour's home, or press `#` to type a colour.
|
|
534
|
+
|
|
535
|
+
- **Palette.** Drop an image, or type its path into the field at the top. The
|
|
536
|
+
photo is drawn in its own colours next to the list, with each colour's share
|
|
537
|
+
of the image.
|
|
538
|
+
- ↑↓ choose a colour; it stays lit in the photo and the rest dim.
|
|
539
|
+
- → goes inside a colour: its shades, lit where they are in the photo.
|
|
540
|
+
← comes back.
|
|
541
|
+
- `s` makes a scale from the chosen colour.
|
|
542
|
+
- **Scale.** Type a hex code. You get 50–950 with your colour at 500, and a
|
|
543
|
+
preview of the chosen step: "Aa" in white and black, with each rated
|
|
544
|
+
(AAA, AA, large, fails).
|
|
545
|
+
- ←→ choose a step.
|
|
546
|
+
- `r` makes that step the new centre and rebuilds the scale around it.
|
|
547
|
+
- `#` types a new colour.
|
|
548
|
+
|
|
549
|
+
On both screens, ↵ copies the chosen hex and `c` copies the whole set. Paste
|
|
550
|
+
it into Figma with ⌘V: you get real shapes and text layers, named
|
|
551
|
+
`blue-500` and so on. esc goes back one step, and the bar at the top shows
|
|
552
|
+
the way back. Under `NO_COLOR`, both screens are plain text with every key
|
|
553
|
+
still working.
|
|
554
|
+
|
|
555
|
+
### On the command line
|
|
556
|
+
|
|
557
|
+
```
|
|
558
|
+
$ forge palette photo.jpg
|
|
559
|
+
#B897E4 16%
|
|
560
|
+
#86B627 16%
|
|
561
|
+
#256129 14%
|
|
562
|
+
…
|
|
563
|
+
$ forge palette photo.jpg --inside F96363 # the shades one colour is made of
|
|
564
|
+
#FF665A 63%
|
|
565
|
+
#F35949 15%
|
|
566
|
+
#E58A9F 14%
|
|
567
|
+
#BE5C38 8%
|
|
568
|
+
$ forge scale 6579FD
|
|
569
|
+
50 #F4F6FF white 1.0 fails · black 19.4 AAA
|
|
570
|
+
…
|
|
571
|
+
500 #6579FD white 3.6 large · black 5.7 AA
|
|
572
|
+
…
|
|
573
|
+
950 #161B58 white 15.7 AAA · black 1.3 fails
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
- **`forge palette <image>`** gives an image's main colours, most of the image
|
|
577
|
+
first. Each one is a real pixel from the image, not an average, and the
|
|
578
|
+
percentages add up to 100. The image is probed by content, so a PDF named
|
|
579
|
+
`.png` is refused as not an image.
|
|
580
|
+
- **`forge scale <colour>`** gives 50–950 built in OKLCH, with your colour
|
|
581
|
+
exactly at 500. Each step is rated for white and black text (WCAG: AAA, AA,
|
|
582
|
+
large, fails). Ratios are rounded down, so 4.48:1 shows as `4.4 large` and
|
|
583
|
+
is never passed off as AA. Pass the colour without the `#`, or quote it (`'#6579FD'`):
|
|
584
|
+
an unquoted `#` starts a comment in the shell.
|
|
585
|
+
- **`--svg`** prints a card of swatches. Pipe it to `pbcopy` and press ⌘V in
|
|
586
|
+
Figma to get real shapes and text layers: `forge scale 6579FD --svg | pbcopy`.
|
|
587
|
+
- **`--json`** returns `palette` (`source`, `colours[]` with `hex`, `rgb`,
|
|
588
|
+
`oklch`, `share`) or `scale` (`reference`, `steps[]` with `step`, `hex`,
|
|
589
|
+
`oklch`, `white`, `black`).
|
|
590
|
+
|
|
591
|
+
On a colour terminal each row starts with a swatch. Piped, or under
|
|
592
|
+
`NO_COLOR`, the rows are plain text.
|
|
593
|
+
|
|
594
|
+
## Usage
|
|
595
|
+
|
|
596
|
+
```
|
|
597
|
+
forge <inputs...> --to <format> [options]
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
| Flag | Meaning |
|
|
601
|
+
| --- | --- |
|
|
602
|
+
| `-t, --to <format>` | target format (required) |
|
|
603
|
+
| `-o, --output <path>` | output file or directory |
|
|
604
|
+
| `-q, --quality <n>` | 1–100, lossy targets only, **requires `--to`** |
|
|
605
|
+
| `--background <css>` | fill colour when flattening alpha (default white) |
|
|
606
|
+
| `--keep-metadata` | preserve EXIF/GPS instead of stripping it |
|
|
607
|
+
| `--recursive` | descend into subdirectories |
|
|
608
|
+
| `--force` | allow overwriting an existing output file |
|
|
609
|
+
| `--concurrency <n>` | batch parallelism (default `min(cpus, 4)`) |
|
|
610
|
+
| `--debug` | include stack traces in error output |
|
|
611
|
+
| `--formats` | print the capability matrix |
|
|
612
|
+
| `-V, --version` / `-h, --help` | the usual |
|
|
613
|
+
|
|
614
|
+
`--quality` is rejected unless `--to` is also given — even though it looks
|
|
615
|
+
like it should stand alone. That's deliberate: a future `compress` action
|
|
616
|
+
will accept `--quality` on its own with different semantics (compress in
|
|
617
|
+
place, no format change), and letting `--quality` alone mean something today
|
|
618
|
+
would make it a breaking change later. So for now it's tied to `--to`.
|
|
619
|
+
|
|
620
|
+
### A single conversion
|
|
621
|
+
|
|
622
|
+
```
|
|
623
|
+
$ forge sample.jpg --to webp
|
|
624
|
+
✓ sample.jpg → sample.webp
|
|
625
|
+
11.5 KB → 3.5 KB · 69.6% smaller
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
Run it again without `--force` and it refuses to clobber the existing file:
|
|
629
|
+
|
|
630
|
+
```
|
|
631
|
+
$ forge sample.jpg --to webp
|
|
632
|
+
✕ File already exists
|
|
633
|
+
|
|
634
|
+
sample.webp is already there.
|
|
635
|
+
|
|
636
|
+
Pass --force to replace it, or choose a different --output.
|
|
637
|
+
$ echo $?
|
|
638
|
+
1
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
```
|
|
642
|
+
$ forge sample.jpg --to webp --force
|
|
643
|
+
✓ sample.jpg → sample.webp
|
|
644
|
+
11.5 KB → 3.5 KB · 69.6% smaller
|
|
645
|
+
$ echo $?
|
|
646
|
+
0
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
### Errors are specific, not stack traces
|
|
650
|
+
|
|
651
|
+
```
|
|
652
|
+
$ forge ghost.jpg --to webp
|
|
653
|
+
✕ File not found
|
|
654
|
+
|
|
655
|
+
ghost.jpg could not be found.
|
|
656
|
+
|
|
657
|
+
Check the filename and try again.
|
|
658
|
+
$ echo $?
|
|
659
|
+
1
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
```
|
|
663
|
+
$ forge sample.jpg --to mp4
|
|
664
|
+
✕ Invalid arguments
|
|
665
|
+
|
|
666
|
+
mp4 is not a format Forge knows.
|
|
667
|
+
|
|
668
|
+
Run forge --formats to see what is available.
|
|
669
|
+
$ echo $?
|
|
670
|
+
2
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
```
|
|
674
|
+
$ forge sample.jpg --to heic
|
|
675
|
+
✕ Can't convert sample.jpg to heic
|
|
676
|
+
|
|
677
|
+
sample.jpg is a JPEG image.
|
|
678
|
+
|
|
679
|
+
Available: jpeg, png, webp, avif, gif, tiff
|
|
680
|
+
$ echo $?
|
|
681
|
+
1
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
```
|
|
685
|
+
$ forge sample.jpg
|
|
686
|
+
✕ Invalid arguments
|
|
687
|
+
|
|
688
|
+
No target format given.
|
|
689
|
+
|
|
690
|
+
Add --to <format>, for example: forge photo.jpg --to webp
|
|
691
|
+
$ echo $?
|
|
692
|
+
2
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
No stack trace ever reaches the terminal unless you pass `--debug`.
|
|
696
|
+
|
|
697
|
+
### Batches and folders
|
|
698
|
+
|
|
699
|
+
Point Forge at a directory and it converts everything inside (one level
|
|
700
|
+
deep, unless you pass `--recursive`):
|
|
701
|
+
|
|
702
|
+
```
|
|
703
|
+
$ forge photos --to webp -o ./out/
|
|
704
|
+
✓ 3 converted
|
|
705
|
+
6.2 KB → 1.9 KB · 69.6% smaller
|
|
706
|
+
out/photo1.webp
|
|
707
|
+
out/photo2.webp
|
|
708
|
+
out/photo3.webp
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
With `--recursive`, the source tree is recreated under the output directory
|
|
712
|
+
instead of being flattened:
|
|
713
|
+
|
|
714
|
+
```
|
|
715
|
+
$ forge photos --to png -o ./t/ --recursive
|
|
716
|
+
✓ 4 converted
|
|
717
|
+
8.3 KB → 1.7 KB · 80% smaller
|
|
718
|
+
t/photo1.png
|
|
719
|
+
t/photo2.png
|
|
720
|
+
t/photo3.png
|
|
721
|
+
t/sub/deeper/bottom.png
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
```
|
|
725
|
+
$ find t -type f
|
|
726
|
+
t/photo1.png
|
|
727
|
+
t/photo2.png
|
|
728
|
+
t/photo3.png
|
|
729
|
+
t/sub/deeper/bottom.png
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
Both glob forms work — `forge *.jpg --to webp` (expanded by your shell) and
|
|
733
|
+
`forge "*.jpg" --to webp` (expanded internally).
|
|
734
|
+
|
|
735
|
+
### Output path rules
|
|
736
|
+
|
|
737
|
+
| Invocation | Result |
|
|
738
|
+
| --- | --- |
|
|
739
|
+
| `forge a.jpg --to webp` | `./a.webp` |
|
|
740
|
+
| `forge a.jpg --to webp -o ./dist/` | `./dist/a.webp` |
|
|
741
|
+
| `forge a.jpg --to webp -o ./dist/x.webp` | `./dist/x.webp` |
|
|
742
|
+
| `forge ./photos --to webp` | alongside each source |
|
|
743
|
+
| `forge ./photos --to webp -o ./dist/` | flattened into `./dist/` |
|
|
744
|
+
| `forge ./photos --to webp -o ./dist/ --recursive` | tree recreated under `./dist/` |
|
|
745
|
+
|
|
746
|
+
A trailing slash, or an existing directory, means directory. Anything else
|
|
747
|
+
without a file extension is also treated as a directory (`-o dist` is far
|
|
748
|
+
more often a folder than a file named `dist`). Missing intermediate
|
|
749
|
+
directories are created. Exit codes: `0` all succeeded, `1` some failed,
|
|
750
|
+
`2` invalid arguments.
|
|
751
|
+
|
|
752
|
+
### Bare `forge`
|
|
753
|
+
|
|
754
|
+
Run `forge` with no arguments in a real terminal and it launches the
|
|
755
|
+
interactive shell instead of erroring — see [Interactive shell](#interactive-shell)
|
|
756
|
+
below for the full flow. That launch is gated on stdout actually being a
|
|
757
|
+
TTY, so it only ever happens in a terminal you're sitting at.
|
|
758
|
+
|
|
759
|
+
Piped or non-interactive invocations (no TTY) get a hint instead, and never
|
|
760
|
+
hang waiting for input:
|
|
761
|
+
|
|
762
|
+
```
|
|
763
|
+
$ forge | cat
|
|
764
|
+
Forge needs a file and a target format.
|
|
765
|
+
Try: forge photo.jpg --to webp
|
|
766
|
+
$ echo $?
|
|
767
|
+
2
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
## Use with AI agents
|
|
771
|
+
|
|
772
|
+
Tell an agent *"take this image and use Forge on it"* and it can: Forge is
|
|
773
|
+
local, private, and built to be driven without a person at the keyboard.
|
|
774
|
+
|
|
775
|
+
### As an MCP server
|
|
776
|
+
|
|
777
|
+
```bash
|
|
778
|
+
claude mcp add forge -- forge mcp # Claude Code
|
|
779
|
+
codex mcp add forge -- forge mcp # Codex / ChatGPT desktop's Codex
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
Claude Desktop and Cursor:
|
|
783
|
+
|
|
784
|
+
```json
|
|
785
|
+
{ "mcpServers": { "forge": { "command": "forge", "args": ["mcp"] } } }
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
Seven tools, deliberately few:
|
|
789
|
+
|
|
790
|
+
| Tool | Does |
|
|
791
|
+
| --- | --- |
|
|
792
|
+
| `forge_probe` | what files are and what Forge can do with them |
|
|
793
|
+
| `forge_formats` | the capability matrix |
|
|
794
|
+
| `forge_convert` | convert to a target format (`quality`, `dpi`, `pages`, `background`, `password`, `overwrite`; images also `sharpen`, `boost: 2 \| 4` and `removeBackground`, which need the optional extensions) |
|
|
795
|
+
| `forge_compress` | compress by `quality` or to a `maxSize` (also `dpi` for PDFs, `output`, `overwrite`; no `password`: compression refuses encrypted PDFs) |
|
|
796
|
+
| `forge_pdf` | `merge`, `split`, `extract`, `delete`, `rotate` |
|
|
797
|
+
| `forge_palette` | an image's main colours with their shares; `inside` gives one colour's shades (read-only) |
|
|
798
|
+
| `forge_scale` | a 50–950 tonal scale with the colour at 500, rated for white and black text (read-only) |
|
|
799
|
+
|
|
800
|
+
Paths must be absolute. Results come back as structured content in the
|
|
801
|
+
`--json` shape below, with a `file://` link to every output, and never as
|
|
802
|
+
file contents. Nothing is overwritten unless the call passes
|
|
803
|
+
`overwrite: true`. An encrypted PDF takes a `password` argument to
|
|
804
|
+
`forge_convert`; there is no prompt. The server speaks MCP over stdio,
|
|
805
|
+
negotiates protocol revision 2025-11-25 with current Claude Code, writes
|
|
806
|
+
nothing but protocol messages to stdout, and exits when its client closes
|
|
807
|
+
stdin.
|
|
808
|
+
|
|
809
|
+
**Limitation:** an image pasted into a chat app is not a file on disk, so a
|
|
810
|
+
path-based tool cannot see it. Agents with file access (Claude Code, Cursor,
|
|
811
|
+
Codex) are the natural fit.
|
|
812
|
+
|
|
813
|
+
### As a CLI, with the skill
|
|
814
|
+
|
|
815
|
+
[`skills/forge/SKILL.md`](skills/forge/SKILL.md) teaches an agent with a
|
|
816
|
+
shell to probe before converting, pass `--json`, read exit codes, and never
|
|
817
|
+
pass `--force` unless asked. For Claude Code, copy it to
|
|
818
|
+
`~/.claude/skills/forge/SKILL.md`. It ships in the npm package: after
|
|
819
|
+
`npm install -g forge-terminal` it is at
|
|
820
|
+
`$(npm root -g)/forge-terminal/skills/forge/SKILL.md`.
|
|
821
|
+
|
|
822
|
+
### `forge probe`
|
|
823
|
+
|
|
824
|
+
```
|
|
825
|
+
$ forge probe locked.pdf photo.png
|
|
826
|
+
locked.pdf · PDF · 2.7 KB · 3 pages · password-protected
|
|
827
|
+
converts to jpeg, png, pdf, docx
|
|
828
|
+
actions convert, split, extract, delete, rotate
|
|
829
|
+
|
|
830
|
+
photo.png · PNG · 122 KB · 2756×774
|
|
831
|
+
converts to jpeg, png, webp, avif, gif, tiff, pdf
|
|
832
|
+
actions convert
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
With `--json`:
|
|
836
|
+
|
|
837
|
+
```json
|
|
838
|
+
{"forge":"0.2.0","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
`targets` and `actions` come from the engines' own capabilities, so they are
|
|
842
|
+
always true for that file. `format` is read from the file's content, not its
|
|
843
|
+
name. `actions` lists `convert` plus what else applies: `compress`,
|
|
844
|
+
`split`, `extract`, `delete`, `rotate`; `merge` appears only when several
|
|
845
|
+
PDFs are probed together. `compress` appears when quality or size can be
|
|
846
|
+
reduced: lossy images, and PDFs that contain compressible images (a PNG has
|
|
847
|
+
only `convert`). Run it as `--quality N` or `--max-size S` without `--to`;
|
|
848
|
+
its `--json` result reports `op: "convert"`. The encrypted PDF above omits
|
|
849
|
+
`compress` and `merge`; a plain PDF with images would also list `compress`.
|
|
850
|
+
A probe has `width`/`height` for an image,
|
|
851
|
+
`pages` and `encrypted` for a PDF. Probing writes nothing. A file that cannot
|
|
852
|
+
be probed goes in `failures` and does not stop the others.
|
|
853
|
+
|
|
854
|
+
### `--json`
|
|
855
|
+
|
|
856
|
+
Every command accepts `--json`. stdout then carries exactly one JSON document
|
|
857
|
+
on one line, and nothing else: no colour, no glyphs, no progress. Every
|
|
858
|
+
document has `forge` (the version), `ok` (true only if every input
|
|
859
|
+
succeeded) and `failures`. A conversion, compression or page operation adds
|
|
860
|
+
`results`:
|
|
861
|
+
|
|
862
|
+
```jsonc
|
|
863
|
+
{
|
|
864
|
+
"forge": "0.2.0",
|
|
865
|
+
"ok": false,
|
|
866
|
+
"results": [
|
|
867
|
+
{
|
|
868
|
+
"op": "convert", // convert | merge | split | extract | delete | rotate
|
|
869
|
+
"source": "/abs/photo.heic", // = sources[0]
|
|
870
|
+
"sources": ["/abs/photo.heic"], // all of them, for a merge
|
|
871
|
+
"outputs": ["/abs/photo.webp"], // always absolute, always every file written
|
|
872
|
+
"inputBytes": 52074,
|
|
873
|
+
"outputBytes": 42684,
|
|
874
|
+
"warnings": [{ "code": "animation-flattened", "message": "…" }]
|
|
875
|
+
}
|
|
876
|
+
],
|
|
877
|
+
"failures": [
|
|
878
|
+
{
|
|
879
|
+
"path": "/abs/locked.pdf", // absent for a command-level error
|
|
880
|
+
"code": "encrypted-source", // a stable ErrorCode
|
|
881
|
+
"title": "…", "detail": "…", "hint": "…"
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
}
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
`--formats --json` returns `formats` (`id`, `label`, `extensions`, `read`,
|
|
888
|
+
`write`, `lossy`). `forge probe --json` returns `probes`. `forge palette
|
|
889
|
+
--json` returns `palette`, and `forge scale --json` returns `scale` (see
|
|
890
|
+
[Colour](#colour)). `forge config
|
|
891
|
+
--json` returns `config` and `warnings`. An argument error is a document with
|
|
892
|
+
one `invalid-arguments` failure and exit code 2. Fields are not renamed or
|
|
893
|
+
removed within a minor version; the `forge` field says which version you are
|
|
894
|
+
reading. `--help` and `--version` print text even with `--json`.
|
|
895
|
+
|
|
896
|
+
### Exit codes
|
|
897
|
+
|
|
898
|
+
| Code | Meaning |
|
|
899
|
+
| --- | --- |
|
|
900
|
+
| 0 | Every input succeeded |
|
|
901
|
+
| 1 | The command was understood, and at least one input failed or was refused |
|
|
902
|
+
| 2 | The command itself was invalid: an unknown flag, a missing argument, contradictory flags |
|
|
903
|
+
|
|
904
|
+
If the same flags could succeed on a different file, it's 1; otherwise it's 2.
|
|
905
|
+
The table is also in `forge --help`.
|
|
906
|
+
|
|
907
|
+
### No terminal, no prompt
|
|
908
|
+
|
|
909
|
+
Without a TTY, Forge never waits for input. An encrypted PDF without
|
|
910
|
+
`--password-stdin` fails at once (exit 1), and `--password-stdin` reads a
|
|
911
|
+
single line, so a pipe left open by the caller does not hold it up.
|
|
912
|
+
|
|
913
|
+
### By hand, before a release
|
|
914
|
+
|
|
915
|
+
Registering a server in a real agent config is a human step, so it is not
|
|
916
|
+
part of the test suite:
|
|
917
|
+
|
|
918
|
+
1. `npm run build && npm link`, then `claude mcp add forge -- forge mcp`. In
|
|
919
|
+
Claude Code: "convert ~/Desktop/x.heic to jpeg", "compress it to 200kb",
|
|
920
|
+
"split ~/Desktop/doc.pdf into pages". Each must succeed and name its
|
|
921
|
+
outputs. `/mcp` should show the server connected.
|
|
922
|
+
2. Repeat in Claude Desktop with the `mcpServers` snippet above, and record
|
|
923
|
+
which protocol revision it negotiates (its MCP log shows the `initialize`
|
|
924
|
+
exchange).
|
|
925
|
+
3. If either client cannot connect, read its MCP log before changing code.
|
|
926
|
+
|
|
927
|
+
## Interactive shell
|
|
928
|
+
|
|
929
|
+
Ink/React are only loaded (via a dynamic `import()`) once the TTY check
|
|
930
|
+
above passes, so a normal flag invocation like `forge photo.jpg --to webp`
|
|
931
|
+
never pays to load a UI framework it doesn't use — confirmed by hand: the
|
|
932
|
+
flag CLI's own tests and manual runs are unaffected by the shell's
|
|
933
|
+
existence.
|
|
934
|
+
|
|
935
|
+
The flow is one path, start to finish: drop a file → pick a target format →
|
|
936
|
+
a quality slider, for a lossy target only → pick a destination → convert →
|
|
937
|
+
see the result. What follows is a real session, captured verbatim (with the
|
|
938
|
+
ANSI styling stripped for readability) converting an 11.5 KB JPEG to WebP
|
|
939
|
+
in a 100-column terminal:
|
|
940
|
+
|
|
941
|
+
```
|
|
942
|
+
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
|
|
943
|
+
│ › drop a file or type a path │
|
|
944
|
+
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
945
|
+
↵ send · ctrl-c close app
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
Drag a file in from Finder (its path arrives shell-escaped, e.g. `my\ photo.jpg`,
|
|
949
|
+
and is unescaped automatically) or type a path, then press Enter. Forge
|
|
950
|
+
probes it and shows a one-line card:
|
|
951
|
+
|
|
952
|
+
```
|
|
953
|
+
sample.jpg · 11.5 KB · JPEG 1600×1200
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
Then a target menu — built from what the source can actually become, never
|
|
957
|
+
a hardcoded list, which is why HEIC never appears here (see
|
|
958
|
+
[Supported formats](#supported-formats)):
|
|
959
|
+
|
|
960
|
+
```
|
|
961
|
+
Convert to
|
|
962
|
+
❯ JPEG universal
|
|
963
|
+
PNG lossless
|
|
964
|
+
WebP smaller, modern
|
|
965
|
+
AVIF smallest
|
|
966
|
+
GIF animation
|
|
967
|
+
TIFF archival
|
|
968
|
+
↑↓ choose · ↵ confirm · esc back
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
Arrow keys move `❯`; Enter accepts the highlighted format. Choosing a lossy
|
|
972
|
+
target (WebP, JPEG, AVIF) adds a quality slider; PNG, GIF and TIFF skip
|
|
973
|
+
straight to the destination step:
|
|
974
|
+
|
|
975
|
+
```
|
|
976
|
+
Quality
|
|
977
|
+
━━━━━━━━━━━━━━━●━━━━ 80
|
|
978
|
+
←→ adjust · ↵ confirm · esc back
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
The destination step offers the source folder, a new `converted/`
|
|
982
|
+
subfolder, `~/Downloads`, or a typed path — the preview line below follows
|
|
983
|
+
whichever preset is highlighted:
|
|
984
|
+
|
|
985
|
+
```
|
|
986
|
+
Save to
|
|
987
|
+
❯ Same folder .
|
|
988
|
+
New subfolder converted
|
|
989
|
+
Downloads /Users/you/Downloads
|
|
990
|
+
Type a path…
|
|
991
|
+
→ ./sample.webp
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
Enter on a preset converts immediately — unless writing there would destroy
|
|
995
|
+
something. The shell runs the same `buildPlan()` write-safety checks the flag
|
|
996
|
+
CLI does (§ *Safety* above): converting a JPEG to JPEG in its own folder, which
|
|
997
|
+
is what accepting every default does, resolves the output onto the input and is
|
|
998
|
+
refused outright rather than replacing your original with a lossy re-encode:
|
|
999
|
+
|
|
1000
|
+
```
|
|
1001
|
+
✕ Output would replace the original
|
|
1002
|
+
sample.jpg is both the input and the output.
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
and an output that already exists asks instead of clobbering it:
|
|
1006
|
+
|
|
1007
|
+
```
|
|
1008
|
+
sample.webp already exists
|
|
1009
|
+
❯ Keep both sample (1).webp
|
|
1010
|
+
Replace the existing file is lost
|
|
1011
|
+
Cancel pick a different folder
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
Either way you land back on the destination step. Otherwise:
|
|
1015
|
+
|
|
1016
|
+
```
|
|
1017
|
+
✓ sample.jpg → sample.webp
|
|
1018
|
+
11.5 KB → 3.5 KB · 69.6% smaller
|
|
1019
|
+
|
|
1020
|
+
file:///private/tmp/forge-shell-check/sample.webp · file:///private/tmp/forge-shell-check
|
|
1021
|
+
↵ convert another · o open · r reveal · ctrl-c close app
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
`o` opens the converted file in its default app and `o` reveals it in
|
|
1025
|
+
Finder — both just shell out to macOS's `open`; both actually launched
|
|
1026
|
+
Preview and Finder in this run, confirmed by asking each app afterward what
|
|
1027
|
+
it had open. `↵` clears the picker and returns to the prompt with this
|
|
1028
|
+
result still sitting above it: finished entries are written to the
|
|
1029
|
+
terminal with Ink's `<Static>`, which commits them to the real scrollback
|
|
1030
|
+
once rather than redrawing them on every frame — confirmed by inspecting
|
|
1031
|
+
the raw output stream, which contains no full-screen or scrollback-clearing
|
|
1032
|
+
escape codes once a card or result has been printed, only the small live
|
|
1033
|
+
region below it being rewritten. `ctrl-c` closes the app.
|
|
1034
|
+
|
|
1035
|
+
Those two links print as bare `file://` URLs (to wherever the file actually
|
|
1036
|
+
landed — `/tmp/forge-shell-check` was this session's scratch directory)
|
|
1037
|
+
rather than as the words "Open file" and "Reveal in Finder". Both are
|
|
1038
|
+
rendered as OSC 8 hyperlinks — a link *target* wrapped around a label — and
|
|
1039
|
+
a terminal that understands OSC 8 (iTerm2, Ghostty, WezTerm, Kitty, VS
|
|
1040
|
+
Code's terminal) shows just the label, clickable. Terminal.app doesn't
|
|
1041
|
+
understand OSC 8, and neither did the scripted terminal this transcript was
|
|
1042
|
+
captured in, so both degrade to the bare, still cmd+clickable URL instead
|
|
1043
|
+
of dropping the link entirely — which is exactly what's shown above.
|
|
1044
|
+
|
|
1045
|
+
### Terminal support
|
|
1046
|
+
|
|
1047
|
+
The layout adapts to width rather than wrapping: below 60 columns the
|
|
1048
|
+
bordered prompt box, the per-item format hints (`universal`, `lossless`,
|
|
1049
|
+
...), the destination presets' folder paths, and the file card's
|
|
1050
|
+
format/dimensions are all dropped so every line stays inside the terminal
|
|
1051
|
+
edge; above that, a preset's path is middle-truncated to whatever the width
|
|
1052
|
+
leaves for it; at 60 columns and above everything renders
|
|
1053
|
+
as pictured above. This re-bands live if you resize the window mid-session,
|
|
1054
|
+
not just at launch. Long filenames and paths are truncated from the middle
|
|
1055
|
+
(keeping both the start and the extension visible) rather than overflowing
|
|
1056
|
+
or wrapping. Meaning is never colour-only: every status is a symbol plus a
|
|
1057
|
+
word (`✓`/`✕`/`⚠`), and the selected item in every list is marked with `❯`
|
|
1058
|
+
and rendered bold.
|
|
1059
|
+
|
|
1060
|
+
### What the shell doesn't do yet
|
|
1061
|
+
|
|
1062
|
+
- **Batch convert or compress.** `/convert` and `/compress` refuse to run
|
|
1063
|
+
against more than one staged file, rather than silently acting on just the
|
|
1064
|
+
first — point the flag CLI at a folder instead. Several files *can* be
|
|
1065
|
+
staged at once now, but only `/pdf`'s merge is defined by having more than
|
|
1066
|
+
one; a paste containing several paths is still read as one path and fails
|
|
1067
|
+
to probe as such.
|
|
1068
|
+
- **PDF compression and splitting to a target size.** Not in this phase —
|
|
1069
|
+
see [PDF § Not yet](#not-yet) above for what's coming and when.
|
|
1070
|
+
- **No recent-files list** — every session starts at an empty prompt.
|
|
1071
|
+
|
|
1072
|
+
## Keyboard shortcuts
|
|
1073
|
+
|
|
1074
|
+
In the text field:
|
|
1075
|
+
|
|
1076
|
+
| Action | Keys |
|
|
1077
|
+
| --- | --- |
|
|
1078
|
+
| Move a word | Option+Left / Option+Right (also Ctrl+Left / Ctrl+Right) |
|
|
1079
|
+
| Start / end of line | Home / End, or Ctrl+A / Ctrl+E |
|
|
1080
|
+
| Delete the word before the caret | Option+Backspace, or Ctrl+W |
|
|
1081
|
+
| Delete the word after the caret | Option+fn+Delete |
|
|
1082
|
+
| Delete to start / end of line | Ctrl+U / Ctrl+K |
|
|
1083
|
+
| Cut / paste the selection | Ctrl+X / Ctrl+Y |
|
|
1084
|
+
| Extend a selection | Shift+Left / Shift+Right |
|
|
1085
|
+
|
|
1086
|
+
**On Cmd shortcuts.** Cmd is the line-scoped counterpart to Option's
|
|
1087
|
+
word-scoped one, not a word-movement shortcut itself: Cmd+Left/Right go to
|
|
1088
|
+
the start/end of the line and Cmd+Backspace deletes to the line start — the
|
|
1089
|
+
same three things Home/End (or Ctrl+A/Ctrl+E) and Ctrl+U already do above.
|
|
1090
|
+
Cmd+A selects the whole field and has no other binding. All four work only
|
|
1091
|
+
in terminals that speak the kitty keyboard protocol — iTerm2, Ghostty,
|
|
1092
|
+
WezTerm, kitty, and the VS Code integrated terminal. Terminal.app cannot
|
|
1093
|
+
report Cmd at all: its key-mapping UI does not offer Command as a modifier,
|
|
1094
|
+
so no Cmd chord produces any bytes there. Home/End, Ctrl+A/Ctrl+E and Ctrl+U
|
|
1095
|
+
cover the same ground everywhere; selecting the whole field has no fallback
|
|
1096
|
+
in Terminal.app.
|
|
1097
|
+
|
|
1098
|
+
## Supported formats
|
|
1099
|
+
|
|
1100
|
+
```
|
|
1101
|
+
$ forge --formats
|
|
1102
|
+
Formats
|
|
1103
|
+
|
|
1104
|
+
JPEG .jpg .jpeg read and write
|
|
1105
|
+
PNG .png read and write
|
|
1106
|
+
WebP .webp read and write
|
|
1107
|
+
AVIF .avif read and write
|
|
1108
|
+
HEIC .heic .heif read only
|
|
1109
|
+
GIF .gif read and write
|
|
1110
|
+
TIFF .tif .tiff read and write
|
|
1111
|
+
PDF .pdf read and write
|
|
1112
|
+
|
|
1113
|
+
HEIC is read only because the image library cannot encode it.
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
PDF's "read and write" covers the five page operations plus rasterising to
|
|
1117
|
+
JPEG/PNG and encoding images to PDF — see [PDF](#pdf) above for the actual
|
|
1118
|
+
grammar; it isn't a peer of the image formats above it in every respect
|
|
1119
|
+
(there's no `--quality` for it, for one).
|
|
1120
|
+
|
|
1121
|
+
**Why HEIC is read-only:** Forge's image engine is Sharp/libvips, and the
|
|
1122
|
+
prebuilt libvips binary can decode HEVC (what iPhones save HEIC as) but
|
|
1123
|
+
cannot encode it — encoding attempts fail with `heifsave: Unsupported
|
|
1124
|
+
compression`. So converting *from* `.heic` works normally; converting *to*
|
|
1125
|
+
`.heic` is refused with a clear error listing what you can target instead,
|
|
1126
|
+
rather than failing partway through an encode.
|
|
1127
|
+
|
|
1128
|
+
Formats are probed by file content (Sharp's magic-byte detection), not by
|
|
1129
|
+
extension — a `.jpg` that's secretly a PNG is handled correctly, and the
|
|
1130
|
+
target list is never a hardcoded string list.
|
|
1131
|
+
|
|
1132
|
+
### HEIC
|
|
1133
|
+
|
|
1134
|
+
Reading HEIC needs a decoder Sharp's prebuilt binary does not ship. HEVC sits
|
|
1135
|
+
in a patent pool, so upstream's position is that HEIC support requires a
|
|
1136
|
+
globally installed libvips built against libheif, libde265 and x265 — AVIF
|
|
1137
|
+
works in the same container only because AV1 is royalty-free.
|
|
1138
|
+
|
|
1139
|
+
Forge decodes HEIC with `/usr/bin/sips` instead, which uses the same system
|
|
1140
|
+
codec Preview does. No install, no build step. If `sips` is missing, HEIC
|
|
1141
|
+
conversion is the only thing that stops working.
|
|
1142
|
+
|
|
1143
|
+
Writing HEIC is still unavailable: Sharp cannot encode HEVC at all.
|
|
1144
|
+
|
|
1145
|
+
## Correctness rules
|
|
1146
|
+
|
|
1147
|
+
These apply automatically, unconditionally, unless a flag opts out:
|
|
1148
|
+
|
|
1149
|
+
1. **Auto-orient first.** EXIF orientation is applied before any other
|
|
1150
|
+
operation, so photos from phones don't come out sideways.
|
|
1151
|
+
2. **Flatten alpha when the target can't carry it.** Converting a
|
|
1152
|
+
transparent PNG to JPEG fills with white (or `--background`), not black.
|
|
1153
|
+
3. **Strip metadata by default, always keep colour profile.** EXIF and GPS
|
|
1154
|
+
are removed unless `--keep-metadata`; the ICC colour profile is always
|
|
1155
|
+
kept so colours don't shift on wide-gamut displays.
|
|
1156
|
+
4. **Never drop animation silently.** An animated source converting to a
|
|
1157
|
+
format that can't animate keeps only the first frame — and attaches a
|
|
1158
|
+
warning to the result, rather than converting quietly and losing frames.
|
|
1159
|
+
5. **Bounded concurrency.** Batches run `min(cpus, 4)` conversions at a
|
|
1160
|
+
time, so Sharp's threadpool isn't overwhelmed.
|
|
1161
|
+
|
|
1162
|
+
Writes are atomic: output goes to a temp file in the destination directory
|
|
1163
|
+
and is renamed into place only on success, so a crash mid-encode never
|
|
1164
|
+
leaves a truncated file where a good one used to be.
|
|
1165
|
+
|
|
1166
|
+
## Architecture
|
|
1167
|
+
|
|
1168
|
+
```
|
|
1169
|
+
src/
|
|
1170
|
+
├── core/ pure logic — no stdout, no UI framework
|
|
1171
|
+
│ ├── types.ts shared types: SourceInfo, Job, Result, FormatId...
|
|
1172
|
+
│ ├── formats.ts format registry (labels, extensions, capabilities)
|
|
1173
|
+
│ ├── capabilities.ts readable/writable format sets, targetsFor()
|
|
1174
|
+
│ ├── actions.ts Action/OptionSpec — what convert asks for, and in what order
|
|
1175
|
+
│ ├── resolve.ts paths / globs / directories → SourceInfo[]
|
|
1176
|
+
│ ├── plan.ts (sources, target, options) → Job[]
|
|
1177
|
+
│ ├── run.ts bounded-concurrency batch runner, emits events
|
|
1178
|
+
│ ├── output-path.ts output path resolution (the table above)
|
|
1179
|
+
│ ├── units.ts byte / percentage formatting
|
|
1180
|
+
│ ├── errors.ts ForgeError taxonomy and rendering
|
|
1181
|
+
│ └── colour/ OKLab/OKLCH, contrast, palette (k-means), scale, the Figma card
|
|
1182
|
+
│
|
|
1183
|
+
├── engines/
|
|
1184
|
+
│ ├── types.ts Engine interface (reads, writes, probe, convert)
|
|
1185
|
+
│ ├── image.ts Sharp-backed engine — the correctness rules live here
|
|
1186
|
+
│ └── registry.ts engine list, format→engine lookup, engine-agnostic probe()
|
|
1187
|
+
│
|
|
1188
|
+
├── cli/
|
|
1189
|
+
│ ├── args.ts Commander wiring → Intent
|
|
1190
|
+
│ ├── execute.ts runIntent() → RunReport (data); execute() renders text or --json
|
|
1191
|
+
│ └── report.ts stdout formatting (success, batch, errors, --formats)
|
|
1192
|
+
│
|
|
1193
|
+
├── mcp/ the MCP server — a third front end, loaded only by `forge mcp`
|
|
1194
|
+
│ ├── server.ts createForgeServer(): seven tools; runMcpServer(): stdio
|
|
1195
|
+
│ ├── tools.ts tool handlers → the same intents and runIntent() the CLI uses
|
|
1196
|
+
│ ├── schemas.ts zod input/output schemas, vocabularies read from core/actions
|
|
1197
|
+
│ └── stdout-guard.ts stdout belongs to the protocol; stray writes go to stderr
|
|
1198
|
+
│
|
|
1199
|
+
├── shell/ the interactive shell (Ink + React) — the only place
|
|
1200
|
+
│ │ that renders to a real terminal frame by frame
|
|
1201
|
+
│ ├── App.tsx the state machine: file → target → quality →
|
|
1202
|
+
│ │ destination → convert → result; the only file
|
|
1203
|
+
│ │ that knows the flow
|
|
1204
|
+
│ ├── blocks.tsx HistoryBlock/HistoryEntry — what gets committed to
|
|
1205
|
+
│ │ <Static> scrollback (file cards, results, errors)
|
|
1206
|
+
│ ├── launch.tsx render(<App/>), awaits waitUntilExit()
|
|
1207
|
+
│ ├── width.ts width bands (<60 compact) and middle-ellipsis
|
|
1208
|
+
│ │ truncation, so nothing overflows or wraps
|
|
1209
|
+
│ ├── theme.ts symbols and colour tokens — meaning is carried by
|
|
1210
|
+
│ │ symbol + word, never colour alone
|
|
1211
|
+
│ ├── hyperlink.ts OSC 8 links with a plain-URL fallback
|
|
1212
|
+
│ ├── reveal.ts shells out to macOS `open` / `open -R`
|
|
1213
|
+
│ └── components/
|
|
1214
|
+
│ ├── Prompt.tsx the bordered/unbordered text input; drop target
|
|
1215
|
+
│ ├── Select.tsx arrow-key list picker (❯ + bold selection)
|
|
1216
|
+
│ ├── Slider.tsx the quality bar
|
|
1217
|
+
│ ├── PathInput.tsx destination picker: presets, plus type-a-path
|
|
1218
|
+
│ ├── FileCard.tsx the dropped-file summary line
|
|
1219
|
+
│ └── Hints.tsx the "key · action" row under each stage
|
|
1220
|
+
│
|
|
1221
|
+
├── utils/
|
|
1222
|
+
│ └── unescape-path.ts undoes shell escaping on a dragged-and-dropped path
|
|
1223
|
+
│
|
|
1224
|
+
└── index.ts entry point: TTY detection, dispatches to execute()
|
|
1225
|
+
or (on a real TTY, bare invocation) launchShell()
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
**The invariant:** `core/` and `engines/` import no UI framework and never
|
|
1229
|
+
write to stdout — everything they produce is data (`Job`, `Result`,
|
|
1230
|
+
`ForgeError`, `RunEvent`). This is what keeps the engine testable without a
|
|
1231
|
+
terminal, and it's also what lets the shell consume the exact same
|
|
1232
|
+
`core`/`engines` layer the flag CLI does, unchanged — `App.tsx` calls
|
|
1233
|
+
`convertAction.plan()` and `runJobs()` directly, the same functions
|
|
1234
|
+
`cli/execute.ts` calls. `src/index.ts` detects whether stdout is a TTY:
|
|
1235
|
+
non-interactive invocations (piped, scripted, or no TTY) resolve to the CLI
|
|
1236
|
+
path and print a hint rather than blocking; a bare `forge` on a real TTY
|
|
1237
|
+
dynamically imports `shell/launch.js` and hands off to it instead.
|
|
1238
|
+
|
|
1239
|
+
## Development
|
|
1240
|
+
|
|
1241
|
+
```bash
|
|
1242
|
+
npm run dev # run from source with tsx, no build step
|
|
1243
|
+
npm run build # one esbuild bundle → dist/ (scripts/build.mjs)
|
|
1244
|
+
npm run typecheck # tsc --noEmit over src + tests
|
|
1245
|
+
npm run lint # biome check src tests
|
|
1246
|
+
npm run format # biome format --write src tests
|
|
1247
|
+
```
|
|
1248
|
+
|
|
1249
|
+
TypeScript runs in strict mode with `noUncheckedIndexedAccess` and
|
|
1250
|
+
`noImplicitOverride` on. Biome replaces ESLint + Prettier with one dependency
|
|
1251
|
+
and one config.
|
|
1252
|
+
|
|
1253
|
+
## Testing
|
|
1254
|
+
|
|
1255
|
+
```bash
|
|
1256
|
+
npm test # vitest run
|
|
1257
|
+
npm run test:watch
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
1413 tests (4 skipped), all passing. Fixtures (transparent PNGs, EXIF-rotated JPEGs,
|
|
1261
|
+
animated GIFs, HEIC/AVIF samples) are generated by Sharp — or, for HEIC,
|
|
1262
|
+
`sips` — at test time, never committed as binaries; the one exception is
|
|
1263
|
+
`tests/fixtures/locked-hunter2.pdf`, a real encrypted PDF (password
|
|
1264
|
+
`hunter2`) checked in because pdf-lib can't produce an encrypted document
|
|
1265
|
+
itself. Coverage includes:
|
|
1266
|
+
|
|
1267
|
+
- **Engine correctness** — the two reproduced defects (transparent-PNG→JPEG
|
|
1268
|
+
going black, EXIF-rotated images staying sideways) as regression tests,
|
|
1269
|
+
plus animation handling and the JPEG/PNG/WebP/HEIC/AVIF conversion pairs.
|
|
1270
|
+
- **Core** — output path resolution, the capability graph, glob and
|
|
1271
|
+
directory resolution, concurrency limiting, atomic writes leaving no temp
|
|
1272
|
+
file behind on failure.
|
|
1273
|
+
- **Errors** — one test per `ErrorCode`, including that no stack trace
|
|
1274
|
+
leaks without `--debug`.
|
|
1275
|
+
- **CLI** — argument parsing and exit codes, including the `--quality`
|
|
1276
|
+
without `--to` rejection above, and that a bare `forge` on a TTY hands off
|
|
1277
|
+
to the shell rather than erroring.
|
|
1278
|
+
- **PDF rasterisation** — page selection and DPI bounds, zero-padded output
|
|
1279
|
+
naming keyed to the document's page count, reading an encrypted PDF by
|
|
1280
|
+
both password routes, and that a wrong password never leaks the attempted
|
|
1281
|
+
string into an error message.
|
|
1282
|
+
- **Shell** — `ink-testing-library` driving real keystrokes through every
|
|
1283
|
+
stage: arrow-key selection, the quality slider, the destination presets
|
|
1284
|
+
and typed-path fallback, a full probe-to-result conversion, dropped paths
|
|
1285
|
+
that are shell-escaped or carry an embedded CR/LF, that no rendered line
|
|
1286
|
+
exceeds the terminal width at four widths, and — new this phase — the
|
|
1287
|
+
page-grid and resolution steps for PDF→image plus the live per-page
|
|
1288
|
+
progress bar.
|
|
1289
|
+
|
|
1290
|
+
## Roadmap
|
|
1291
|
+
|
|
1292
|
+
Not yet built, in rough order:
|
|
1293
|
+
|
|
1294
|
+
- **Batch conversion through the shell** — the flag CLI already converts a
|
|
1295
|
+
whole folder; the shell only ever probes and converts one file per
|
|
1296
|
+
session right now.
|
|
1297
|
+
- **A real action menu** — the shell's data model already supports more
|
|
1298
|
+
than one `Action` (`actionsFor(source)`), but with only `convert`
|
|
1299
|
+
registered it skips straight past a menu of one. This is what the next
|
|
1300
|
+
two roadmap items would turn on.
|
|
1301
|
+
- **Compress action** — quality/size reduction without a format change;
|
|
1302
|
+
the reason `--quality` requires `--to` today.
|
|
1303
|
+
- **Resize action.**
|
|
1304
|
+
- **`/slash` commands** in the shell, and **a recent-files list** so a
|
|
1305
|
+
session doesn't always start from an empty prompt.
|
|
1306
|
+
- **A video engine** — Sharp can't do it; it will sit behind the same
|
|
1307
|
+
`Engine` interface `image.ts` and the PDF engine already implement, so the
|
|
1308
|
+
CLI and format menu won't need to change to support it. The PDF engine
|
|
1309
|
+
itself now covers page operations and PDF↔image (see [PDF](#pdf) above);
|
|
1310
|
+
splitting a PDF to a target size is still to come.
|
|
1311
|
+
|
|
1312
|
+
Explicitly out of scope for 0.1: HEIC encoding (the underlying library
|
|
1313
|
+
can't), DOCX/PPTX/SVG output, MP4/MP3, recursive watch mode, config files,
|
|
1314
|
+
presets.
|
|
1315
|
+
|
|
1316
|
+
## License
|
|
1317
|
+
|
|
1318
|
+
MIT
|