forge-terminal 0.1.0 → 0.2.1

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 (212) hide show
  1. package/README.md +333 -24
  2. package/dist/chunks/adm-zip-SQKLKBDP.js +3 -0
  3. package/dist/chunks/available-HEUREG6L.js +3 -0
  4. package/dist/chunks/boot-BUGERSEB.js +3 -0
  5. package/dist/chunks/catalog-NTACQH5V.js +3 -0
  6. package/dist/chunks/cfb-V6M2PYOD.js +13 -0
  7. package/dist/chunks/chunk-2WYHI73Y.js +3 -0
  8. package/dist/chunks/chunk-4YCO7S4K.js +3 -0
  9. package/dist/chunks/chunk-5B7WODWH.js +3 -0
  10. package/dist/chunks/chunk-C2WYXNRM.js +4 -0
  11. package/dist/chunks/chunk-C7OOWUMU.js +3 -0
  12. package/dist/chunks/chunk-EOYBXOCV.js +4 -0
  13. package/dist/chunks/chunk-G2D6BKOS.js +4 -0
  14. package/dist/chunks/chunk-HUAEVW2A.js +3 -0
  15. package/dist/chunks/chunk-J7FLFHQJ.js +3 -0
  16. package/dist/chunks/chunk-L76Q54MB.js +3 -0
  17. package/dist/chunks/chunk-LFE3WRU4.js +3 -0
  18. package/dist/chunks/chunk-PBIS2ONZ.js +3 -0
  19. package/dist/chunks/chunk-PD5DFBCU.js +3 -0
  20. package/dist/chunks/chunk-PN73WK2S.js +3 -0
  21. package/dist/chunks/chunk-QVACE4IE.js +3 -0
  22. package/dist/chunks/chunk-TEGB7JRM.js +3 -0
  23. package/dist/chunks/chunk-TMUK2DD3.js +3 -0
  24. package/dist/chunks/chunk-UNVHKJW4.js +41 -0
  25. package/dist/chunks/chunk-VH5RWPGZ.js +10 -0
  26. package/dist/chunks/chunk-XFEHJ4C7.js +3 -0
  27. package/dist/chunks/chunk-YXDEOLNA.js +3 -0
  28. package/dist/chunks/colour-DE6N6AZO.js +3 -0
  29. package/dist/chunks/config-command-SQXRTBRO.js +3 -0
  30. package/dist/chunks/dist-J2V6ITHG.js +29 -0
  31. package/dist/chunks/es-T2U7NBLD.js +3 -0
  32. package/dist/chunks/execute-M3C3TTWB.js +3 -0
  33. package/dist/chunks/extensions-command-HJDBUBYO.js +3 -0
  34. package/dist/chunks/image-GYUUMS6H.js +3 -0
  35. package/dist/chunks/launch-WBUFRVQ7.js +65 -0
  36. package/dist/chunks/lib-TPEJ5CJJ.js +46 -0
  37. package/dist/chunks/lock-XD4L3WFM.js +3 -0
  38. package/dist/chunks/manager-KBJTXZ27.js +4 -0
  39. package/dist/chunks/paths-JUM6GKQU.js +3 -0
  40. package/dist/chunks/pdf-compress-IMRFBLZF.js +3 -0
  41. package/dist/chunks/react-devtools-core-UM4FS6CU.js +3 -0
  42. package/dist/chunks/run-RXVQD4DZ.js +4 -0
  43. package/dist/chunks/server-DU7QWDAH.js +73 -0
  44. package/dist/chunks/theme-DESCJOCE.js +3 -0
  45. package/dist/chunks/word-OGQ2KZAJ.js +24 -0
  46. package/dist/index.js +67 -95
  47. package/dist/third-party-licenses.txt +2856 -0
  48. package/package.json +28 -21
  49. package/skills/forge/SKILL.md +149 -0
  50. package/dist/cli/args.js +0 -278
  51. package/dist/cli/args.js.map +0 -1
  52. package/dist/cli/config-command.js +0 -55
  53. package/dist/cli/config-command.js.map +0 -1
  54. package/dist/cli/execute.js +0 -377
  55. package/dist/cli/execute.js.map +0 -1
  56. package/dist/cli/report.js +0 -123
  57. package/dist/cli/report.js.map +0 -1
  58. package/dist/cli/spinner.js +0 -60
  59. package/dist/cli/spinner.js.map +0 -1
  60. package/dist/cli/stdin.js +0 -47
  61. package/dist/cli/stdin.js.map +0 -1
  62. package/dist/config/preferences.js +0 -143
  63. package/dist/config/preferences.js.map +0 -1
  64. package/dist/core/actions/compress.js +0 -157
  65. package/dist/core/actions/compress.js.map +0 -1
  66. package/dist/core/actions/convert.js +0 -270
  67. package/dist/core/actions/convert.js.map +0 -1
  68. package/dist/core/actions/extract.js +0 -94
  69. package/dist/core/actions/extract.js.map +0 -1
  70. package/dist/core/actions/index.js +0 -23
  71. package/dist/core/actions/index.js.map +0 -1
  72. package/dist/core/actions/merge.js +0 -16
  73. package/dist/core/actions/merge.js.map +0 -1
  74. package/dist/core/actions/rotate.js +0 -36
  75. package/dist/core/actions/rotate.js.map +0 -1
  76. package/dist/core/actions/split.js +0 -65
  77. package/dist/core/actions/split.js.map +0 -1
  78. package/dist/core/atomic.js +0 -61
  79. package/dist/core/atomic.js.map +0 -1
  80. package/dist/core/capabilities.js +0 -59
  81. package/dist/core/capabilities.js.map +0 -1
  82. package/dist/core/compress.js +0 -76
  83. package/dist/core/compress.js.map +0 -1
  84. package/dist/core/describe.js +0 -49
  85. package/dist/core/describe.js.map +0 -1
  86. package/dist/core/errors.js +0 -469
  87. package/dist/core/errors.js.map +0 -1
  88. package/dist/core/execute-jobs.js +0 -122
  89. package/dist/core/execute-jobs.js.map +0 -1
  90. package/dist/core/formats.js +0 -108
  91. package/dist/core/formats.js.map +0 -1
  92. package/dist/core/order.js +0 -44
  93. package/dist/core/order.js.map +0 -1
  94. package/dist/core/output-path.js +0 -176
  95. package/dist/core/output-path.js.map +0 -1
  96. package/dist/core/pages.js +0 -107
  97. package/dist/core/pages.js.map +0 -1
  98. package/dist/core/pdf-compress.js +0 -206
  99. package/dist/core/pdf-compress.js.map +0 -1
  100. package/dist/core/plan.js +0 -42
  101. package/dist/core/plan.js.map +0 -1
  102. package/dist/core/resolve.js +0 -115
  103. package/dist/core/resolve.js.map +0 -1
  104. package/dist/core/run.js +0 -66
  105. package/dist/core/run.js.map +0 -1
  106. package/dist/core/suggest.js +0 -50
  107. package/dist/core/suggest.js.map +0 -1
  108. package/dist/core/types.js +0 -2
  109. package/dist/core/types.js.map +0 -1
  110. package/dist/core/units.js +0 -94
  111. package/dist/core/units.js.map +0 -1
  112. package/dist/core/write-safety.js +0 -128
  113. package/dist/core/write-safety.js.map +0 -1
  114. package/dist/engines/heic.js +0 -166
  115. package/dist/engines/heic.js.map +0 -1
  116. package/dist/engines/image.js +0 -342
  117. package/dist/engines/image.js.map +0 -1
  118. package/dist/engines/pdf.js +0 -444
  119. package/dist/engines/pdf.js.map +0 -1
  120. package/dist/engines/pdfium.js +0 -161
  121. package/dist/engines/pdfium.js.map +0 -1
  122. package/dist/engines/registry.js +0 -65
  123. package/dist/engines/registry.js.map +0 -1
  124. package/dist/engines/types.js +0 -2
  125. package/dist/engines/types.js.map +0 -1
  126. package/dist/engines/word.js +0 -385
  127. package/dist/engines/word.js.map +0 -1
  128. package/dist/index.js.map +0 -1
  129. package/dist/shell/App.js +0 -1972
  130. package/dist/shell/App.js.map +0 -1
  131. package/dist/shell/ClickTargets.js +0 -183
  132. package/dist/shell/ClickTargets.js.map +0 -1
  133. package/dist/shell/ThemeContext.js +0 -21
  134. package/dist/shell/ThemeContext.js.map +0 -1
  135. package/dist/shell/blocks.js +0 -160
  136. package/dist/shell/blocks.js.map +0 -1
  137. package/dist/shell/clipboard.js +0 -64
  138. package/dist/shell/clipboard.js.map +0 -1
  139. package/dist/shell/commands.js +0 -51
  140. package/dist/shell/commands.js.map +0 -1
  141. package/dist/shell/components/Banner.js +0 -73
  142. package/dist/shell/components/Banner.js.map +0 -1
  143. package/dist/shell/components/CommandPalette.js +0 -37
  144. package/dist/shell/components/CommandPalette.js.map +0 -1
  145. package/dist/shell/components/FileCard.js +0 -59
  146. package/dist/shell/components/FileCard.js.map +0 -1
  147. package/dist/shell/components/HintBar.js +0 -18
  148. package/dist/shell/components/HintBar.js.map +0 -1
  149. package/dist/shell/components/Hints.js +0 -21
  150. package/dist/shell/components/Hints.js.map +0 -1
  151. package/dist/shell/components/MergeList.js +0 -268
  152. package/dist/shell/components/MergeList.js.map +0 -1
  153. package/dist/shell/components/ModeHeader.js +0 -21
  154. package/dist/shell/components/ModeHeader.js.map +0 -1
  155. package/dist/shell/components/PageGrid.js +0 -324
  156. package/dist/shell/components/PageGrid.js.map +0 -1
  157. package/dist/shell/components/PathInput.js +0 -147
  158. package/dist/shell/components/PathInput.js.map +0 -1
  159. package/dist/shell/components/Progress.js +0 -43
  160. package/dist/shell/components/Progress.js.map +0 -1
  161. package/dist/shell/components/Prompt.js +0 -667
  162. package/dist/shell/components/Prompt.js.map +0 -1
  163. package/dist/shell/components/ResultLinks.js +0 -26
  164. package/dist/shell/components/ResultLinks.js.map +0 -1
  165. package/dist/shell/components/Select.js +0 -152
  166. package/dist/shell/components/Select.js.map +0 -1
  167. package/dist/shell/components/Slider.js +0 -48
  168. package/dist/shell/components/Slider.js.map +0 -1
  169. package/dist/shell/components/StagedFiles.js +0 -92
  170. package/dist/shell/components/StagedFiles.js.map +0 -1
  171. package/dist/shell/components/ThemePicker.js +0 -18
  172. package/dist/shell/components/ThemePicker.js.map +0 -1
  173. package/dist/shell/components/UnitRow.js +0 -30
  174. package/dist/shell/components/UnitRow.js.map +0 -1
  175. package/dist/shell/flows/pdf.js +0 -424
  176. package/dist/shell/flows/pdf.js.map +0 -1
  177. package/dist/shell/frame-geometry.js +0 -56
  178. package/dist/shell/frame-geometry.js.map +0 -1
  179. package/dist/shell/hyperlink.js +0 -27
  180. package/dist/shell/hyperlink.js.map +0 -1
  181. package/dist/shell/intro.js +0 -101
  182. package/dist/shell/intro.js.map +0 -1
  183. package/dist/shell/launch.js +0 -75
  184. package/dist/shell/launch.js.map +0 -1
  185. package/dist/shell/mark.js +0 -134
  186. package/dist/shell/mark.js.map +0 -1
  187. package/dist/shell/mouse.js +0 -209
  188. package/dist/shell/mouse.js.map +0 -1
  189. package/dist/shell/redraw.js +0 -36
  190. package/dist/shell/redraw.js.map +0 -1
  191. package/dist/shell/reveal.js +0 -24
  192. package/dist/shell/reveal.js.map +0 -1
  193. package/dist/shell/stage.js +0 -34
  194. package/dist/shell/stage.js.map +0 -1
  195. package/dist/shell/terminal-write.js +0 -16
  196. package/dist/shell/terminal-write.js.map +0 -1
  197. package/dist/shell/theme.js +0 -178
  198. package/dist/shell/theme.js.map +0 -1
  199. package/dist/shell/useFrameOrigin.js +0 -175
  200. package/dist/shell/useFrameOrigin.js.map +0 -1
  201. package/dist/shell/useKeys.js +0 -28
  202. package/dist/shell/useKeys.js.map +0 -1
  203. package/dist/shell/useMouse.js +0 -150
  204. package/dist/shell/useMouse.js.map +0 -1
  205. package/dist/shell/useMouseRouting.js +0 -69
  206. package/dist/shell/useMouseRouting.js.map +0 -1
  207. package/dist/shell/width.js +0 -62
  208. package/dist/shell/width.js.map +0 -1
  209. package/dist/utils/display-path.js +0 -31
  210. package/dist/utils/display-path.js.map +0 -1
  211. package/dist/utils/unescape-path.js +0 -68
  212. package/dist/utils/unescape-path.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-terminal",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A terminal-native file converter for macOS",
5
5
  "keywords": [
6
6
  "convert",
@@ -30,7 +30,8 @@
30
30
  "forge": "dist/index.js"
31
31
  },
32
32
  "files": [
33
- "dist"
33
+ "dist",
34
+ "skills"
34
35
  ],
35
36
  "engines": {
36
37
  "node": ">=20"
@@ -40,40 +41,46 @@
40
41
  ],
41
42
  "license": "MIT",
42
43
  "scripts": {
43
- "build": "tsc -p tsconfig.json",
44
+ "build": "node scripts/build.mjs",
44
45
  "dev": "tsx src/index.ts",
46
+ "bench": "node scripts/bench.mjs",
45
47
  "test": "vitest run",
46
48
  "test:watch": "vitest",
47
49
  "typecheck": "tsc -p tsconfig.typecheck.json",
48
- "lint": "biome check src tests",
49
- "format": "biome format --write src tests",
50
- "prepublishOnly": "rm -rf dist && npm run build && npm run typecheck && npm run lint && npm test"
50
+ "lint": "biome check src tests scripts extensions",
51
+ "format": "biome format --write src tests scripts extensions",
52
+ "prepublishOnly": "npm run build && npm run typecheck && npm run lint && npm test"
51
53
  },
52
54
  "dependencies": {
53
55
  "@hyzyla/pdfium": "^2.1.13",
54
- "adm-zip": "^0.6.0",
55
- "cfb": "^1.2.2",
56
- "commander": "^15.0.0",
57
- "docx": "^9.7.1",
58
- "ink": "^7.1.1",
59
- "mammoth": "^1.12.1",
60
- "pdf-lib": "^1.17.1",
61
- "pdf-parse": "^2.4.5",
62
- "react": "^19.2.8",
63
- "sharp": "^0.35.3",
64
- "string-width": "^8.2.2",
65
- "supports-hyperlinks": "^4.5.0",
66
- "tinyglobby": "^0.2.17",
67
- "word-extractor": "^1.0.4"
56
+ "sharp": "^0.35.5"
68
57
  },
69
58
  "devDependencies": {
70
59
  "@biomejs/biome": "^2.5.9",
60
+ "@modelcontextprotocol/client": "^2.3.1",
61
+ "@modelcontextprotocol/server": "^2.3.1",
71
62
  "@types/node": "^26.2.0",
72
63
  "@types/react": "^19.2.18",
73
64
  "@types/word-extractor": "^1.0.6",
65
+ "adm-zip": "^0.6.1",
66
+ "cfb": "^1.2.2",
67
+ "chalk": "^5.6.2",
68
+ "commander": "^15.0.0",
69
+ "docx": "^9.10.0",
70
+ "esbuild": "^0.28.2",
71
+ "ink": "^7.1.1",
74
72
  "ink-testing-library": "^4.0.0",
73
+ "mammoth": "^1.13.0",
74
+ "onnxruntime-node": "1.23.2",
75
+ "pdf-lib": "^1.17.1",
76
+ "react": "^19.3.0",
77
+ "string-width": "^8.3.0",
78
+ "supports-hyperlinks": "^4.6.0",
79
+ "tinyglobby": "^0.2.17",
75
80
  "tsx": "^4.23.12",
76
81
  "typescript": "^7.0.2",
77
- "vitest": "^4.1.11"
82
+ "vitest": "^4.1.11",
83
+ "word-extractor": "^1.0.4",
84
+ "zod": "^4.6.5"
78
85
  }
79
86
  }
@@ -0,0 +1,149 @@
1
+ ---
2
+ name: forge
3
+ description: Convert, compress and edit local files on macOS with the Forge CLI (`forge`) — images (HEIC, JPEG, PNG, WebP, AVIF, GIF, TIFF), PDFs and Word documents. Use when the user wants a file in another format, smaller or under a size, or a PDF merged, split, trimmed or rotated, or an image's colour palette or a tonal scale from a colour, and `forge` is installed (`npm i -g forge-terminal`).
4
+ ---
5
+
6
+ # Forge
7
+
8
+ Forge converts files on this Mac. Nothing is uploaded.
9
+
10
+ ## Always
11
+
12
+ 1. **Probe first.** `forge probe <file…> --json`. Each entry in `probes` has
13
+ `format` (read from the file's content, not its name), `targets` (every
14
+ format the file can become) and `actions` (what else applies: `compress`,
15
+ `split`, `extract`, `delete`, `rotate`; `convert` is always there).
16
+ `merge` is never listed by probe: to merge, pass `--merge` with two or
17
+ more PDFs. Use these lists; do not
18
+ guess. `compress` appears when quality or size can be reduced: lossy
19
+ images, and PDFs that contain compressible images (a PNG has only
20
+ `convert`). Run it as `--quality N` or `--max-size S` without `--to`. A
21
+ compress run reports `op: "convert"` in `--json` results.
22
+ 2. **Pass `--json`.** stdout is then exactly one JSON document, on one line.
23
+ Read `ok`, `results[].outputs` (the absolute path of every file written)
24
+ and `failures[]` (`path`, `code`, `title`, `detail`, `hint`).
25
+ 3. **Read the exit code** (below).
26
+ 4. **Never pass `--force` unless the user asked to replace files.** Without it
27
+ Forge refuses with `output-exists` and writes nothing. Tell the user, or
28
+ choose another `-o`.
29
+
30
+ ## Exit codes
31
+
32
+ | Code | Meaning | Do |
33
+ | --- | --- | --- |
34
+ | 0 | every input succeeded | report `results[].outputs` |
35
+ | 1 | understood, but an input failed or was refused | read `failures`, act on `code` and `hint` |
36
+ | 2 | the command itself was invalid | fix the flags (`failures[0].code` is `invalid-arguments`) |
37
+
38
+ ## Commands
39
+
40
+ ```bash
41
+ forge probe photo.heic --json
42
+ forge photo.heic --to jpeg --json # convert
43
+ forge ~/Pictures/trip --to webp -o ~/Desktop/web/ --json # a folder
44
+ forge photo.jpg --quality 60 --json # compress, same format -> photo-small.jpg
45
+ forge photo.jpg --max-size 500kb --json # compress to fit
46
+ forge scan.pdf --max-size 2mb --json # a PDF with images
47
+ forge doc.pdf --to png --pages 1-3 --dpi 150 --json # PDF pages -> images
48
+ forge report.docx --to pdf --json
49
+ forge a.pdf b.pdf --merge --json
50
+ forge doc.pdf --split every-page --json # or every=N, at=3,7
51
+ forge doc.pdf --extract 3-7,12 --json # --separate: one file per page
52
+ forge doc.pdf --delete 2 --json
53
+ forge doc.pdf --rotate 90 --json
54
+ forge --formats --json
55
+ forge palette photo.jpg --json # an image's main colours
56
+ forge palette photo.jpg --inside F96363 --json # one colour's shades
57
+ forge scale 6579FD --json # 50–950, the colour at 500
58
+ ```
59
+
60
+ For a colour, pass the hex without `#`, or quote it: an unquoted `#` starts
61
+ a shell comment, and `forge scale` then exits 2 with "No colour given".
62
+
63
+ Outputs go beside the source unless `-o` names a folder (or, for one file, a
64
+ filename). Page operations always write beside the source, take no `-o`, and
65
+ never edit the original.
66
+
67
+ ## Resize and trim edges
68
+
69
+ Built in, images only, format kept unless `--to` is given:
70
+
71
+ ```bash
72
+ forge photo.jpg --resize 50% --json # photo-<W>x<H>.jpg (percent 1-200)
73
+ forge photo.jpg --width 1200 --json # height follows; --height 900 likewise
74
+ forge photo.jpg --trim --json # photo-trimmed.jpg
75
+ forge photo.jpg --trim --width 1200 --to webp --json # photo-trimmed-1200w.webp
76
+ ```
77
+
78
+ One of `--resize` / `--width` / `--height` at a time; not with `--max-size`,
79
+ `--sharpen`, `--boost`, `--remove-bg` or page operations (`invalid-arguments`).
80
+ Runtime refusals: `resize-too-large` (over 16,384 px a side or 100 MP),
81
+ `nothing-to-trim`, `animated-trim`. MCP: `forge_convert` with `trim: true`
82
+ and/or `resize: { percent | width | height }`; `to` is then optional.
83
+
84
+ ## Optional extensions: boost and remove background
85
+
86
+ Two image operations are not built in. They are small downloads, installed once,
87
+ and need macOS 14 or later:
88
+
89
+ ```bash
90
+ forge extensions # what is installed
91
+ forge extensions add boost # about 15 MB; sharpen, 2x / 3x / 4x; Apple Silicon only for now
92
+ forge extensions add remove-background # about 32 KB
93
+ forge photo.jpg --sharpen --json # photo-sharp.png (same size, sharper)
94
+ forge photo.jpg --boost --json # photo-2x.png (--boost 3 -> photo-3x.png, --boost 4 -> photo-4x.png)
95
+ forge photo.jpg --remove-bg --json # photo-cutout.png
96
+ ```
97
+
98
+ `forge probe` lists `boost` / `remove-background` under `actions` only when that
99
+ extension is installed, so trust the probe. `--json` results carry
100
+ `op: "boost"` or `op: "remove-background"`. `--to` picks another output format;
101
+ a cutout needs one that carries transparency (png, webp, avif, tiff) and
102
+ anything else is refused with `invalid-arguments`. If the extension is missing
103
+ the failure code is `extension-missing`, its hint is the install command, and
104
+ the exit code is 1: ask the user before installing, since it downloads.
105
+ Other codes: `no-subject` (no foreground found), `boost-too-large`
106
+ (the result would pass 16,384 px a side or 100 MP; the hint names the largest
107
+ factor that fits) and `extension-outdated` (`--boost 3` needs boost 1.1.0 or
108
+ later; the hint is the same `forge extensions add boost`, which updates it).
109
+ While no released boost makes 3x, `--boost 3` is refused with
110
+ `invalid-arguments` and a hint naming the factors that work; don't update then.
111
+
112
+ ## Encrypted PDFs
113
+
114
+ Forge never prompts when there is no terminal. Send the password on stdin,
115
+ one line:
116
+
117
+ ```bash
118
+ printf '%s\n' "$PASSWORD" | forge locked.pdf --to png --password-stdin --json
119
+ ```
120
+
121
+ Never put a password in an argument; there is no flag for it. Only rendering
122
+ to images works on an encrypted PDF; page operations and compression refuse
123
+ it (`encrypted-source`), so probe lists only the image `targets` and the one
124
+ action `convert` for it. Without `--password-stdin` the run fails at once with
125
+ exit 1 and a hint; a wrong password has its own hint.
126
+
127
+ ## Failure codes worth knowing
128
+
129
+ - `output-exists`: ask before re-running with `--force`.
130
+ - `unsupported-target`: pick from the probe's `targets`.
131
+ - `target-unreachable`: the smallest possible is still too big. Try a larger size or another format.
132
+ - `unsupported-compress`: lossless (PNG) or a PDF with no images. Convert instead.
133
+ - `unsupported-operation`: that page operation does not fit those files (PDFs only; merge needs two or more).
134
+ - `encrypted-source`: a password is needed, or the one given was wrong.
135
+ - `extension-missing`: run the hint's `forge extensions add <id>` (with the user's agreement), then retry.
136
+ - `extension-outdated`: the same command updates it (with the user's agreement, it downloads), then retry.
137
+ - `file-not-found`: check the path; probe reports it per file without failing the rest.
138
+
139
+ ## MCP
140
+
141
+ If a `forge` MCP server is connected (tools `forge_probe`, `forge_formats`,
142
+ `forge_convert`, `forge_compress`, `forge_pdf`, `forge_palette`,
143
+ `forge_scale`), prefer it. It takes absolute
144
+ paths and returns the same JSON as `structuredContent`. It never overwrites
145
+ unless you pass `overwrite: true`, and an encrypted PDF takes a `password`
146
+ argument. `forge_convert` also takes `sharpen: true`, `boost: 2 | 3 | 4` and `removeBackground: true`
147
+ (images only; `to` is then the output format); without the extension they fail
148
+ with `extension-missing`. A hint that says `--force` means `overwrite: true` there;
149
+ `--password-stdin` means `password`.
package/dist/cli/args.js DELETED
@@ -1,278 +0,0 @@
1
- import { Command } from 'commander';
2
- import { invalidArguments, invalidDpi } from '../core/errors.js';
3
- import { formatById } from '../core/formats.js';
4
- import { parseSize } from '../core/units.js';
5
- import { CONFIG_KEYS } from './config-command.js';
6
- /**
7
- * `config` is parsed before Commander sees the argv at all. Commander is
8
- * configured with a variadic `[inputs...]` argument, so it would otherwise
9
- * take `config` for a filename and `set`/`output` for two more — the
10
- * subcommand has to be claimed first or it is indistinguishable from a
11
- * conversion of three files that do not exist.
12
- */
13
- function parseConfigArgs(argv) {
14
- const [, action, key, ...rest] = argv;
15
- if (action === undefined || action === 'list')
16
- return { kind: 'config', action: 'list' };
17
- if (action === 'path')
18
- return { kind: 'config', action: 'path' };
19
- if (action === 'set') {
20
- if (key === undefined || !CONFIG_KEYS.includes(key)) {
21
- throw invalidArguments(`Unknown config setting ${key ?? '(none)'}.`, `Try one of: ${CONFIG_KEYS.join(', ')}.`);
22
- }
23
- // Joined rather than taken as a single token: an unquoted path with a
24
- // space in it arrives as several argv entries, and rejecting that would
25
- // be a papercut on exactly the folders people actually have.
26
- const value = rest.join(' ');
27
- if (value.length === 0)
28
- throw invalidArguments(`forge config set ${key} needs a value.`);
29
- return { kind: 'config', action: 'set', key: key, value };
30
- }
31
- throw invalidArguments(`Unknown config action ${action}.`, 'Try: forge config list, forge config set <setting> <value>, or forge config path.');
32
- }
33
- const ALIASES = { jpg: 'jpeg', tif: 'tiff', heif: 'heic' };
34
- function parseTarget(raw) {
35
- const key = raw.toLowerCase().replace(/^\./, '');
36
- const spec = formatById(ALIASES[key] ?? key);
37
- if (!spec) {
38
- throw invalidArguments(`${raw} is not a format Forge knows.`, 'Run forge --formats to see what is available.');
39
- }
40
- return spec.id;
41
- }
42
- function parseQuality(raw) {
43
- const n = Number(raw);
44
- if (!Number.isInteger(n) || n < 1 || n > 100) {
45
- throw invalidArguments(`Quality must be a whole number between 1 and 100, not ${raw}.`);
46
- }
47
- return n;
48
- }
49
- function parseConcurrency(raw) {
50
- const n = Number(raw);
51
- if (!Number.isInteger(n) || n < 1) {
52
- throw invalidArguments(`Concurrency must be a positive whole number, not ${raw}.`);
53
- }
54
- return n;
55
- }
56
- export function parseArgs(argv) {
57
- if (argv[0] === 'config')
58
- return parseConfigArgs(argv);
59
- const program = new Command()
60
- .name('forge')
61
- .description('Convert — transform your files from the terminal')
62
- .argument('[inputs...]', 'files, folders or globs')
63
- .option('-t, --to <format>', 'target format')
64
- .option('-o, --output <path>', 'output file or directory')
65
- .option('-q, --quality <n>', 'quality for lossy formats, 1-100')
66
- .option('--background <colour>', 'fill colour when flattening transparency', '#ffffff')
67
- .option('--keep-metadata', 'preserve EXIF and GPS data', false)
68
- .option('--recursive', 'descend into subfolders', false)
69
- .option('--force', 'allow overwriting existing files', false)
70
- .option('--max-size <size>', 'compress until the file fits, e.g. 500kb')
71
- .option('--concurrency <n>', 'how many files to convert at once')
72
- .option('--debug', 'show underlying errors', false)
73
- .option('--formats', 'list supported formats', false)
74
- .option('--merge', 'combine several PDFs into one')
75
- .option('--split <mode>', 'every-page | every=N | at=N,N')
76
- .option('--extract <pages>', 'keep only these pages, e.g. 3-7,12')
77
- .option('--delete <pages>', 'drop these pages')
78
- .option('--rotate <degrees>', '90, 180 or 270')
79
- .option('--separate', 'with --extract, write one file per page')
80
- .option('--pages <ranges>', 'with --to, which pages to render, e.g. 3-7,12')
81
- .option('--dpi <n>', 'rasterisation resolution, 36-600', '150')
82
- .option('--password-stdin', "read an encrypted PDF's password from stdin")
83
- .helpOption('-h, --help', 'show this help')
84
- .version('0.1.0', '-V, --version', 'show the version')
85
- .exitOverride()
86
- .allowExcessArguments(false);
87
- program.parse(argv, { from: 'user' });
88
- const opts = program.opts();
89
- const inputs = program.args;
90
- if (opts.formats)
91
- return { kind: 'formats' };
92
- // Checked ahead of every other branch below: --pages only means something
93
- // once a target is known, and none of the later branches (page ops, the
94
- // shell fallback, compression) have anywhere to put it.
95
- if (opts.pages !== undefined && opts.to === undefined) {
96
- throw invalidArguments('--pages needs --to: it chooses which pages to render.');
97
- }
98
- /**
99
- * A page-operation flag is checked ahead of the shell fallback below, not
100
- * just ahead of --to: `forge --merge` with zero inputs must report "no
101
- * files given", not silently open the interactive shell the way a bare
102
- * `forge` does.
103
- */
104
- const chosen = ['merge', 'split', 'extract', 'delete', 'rotate'].filter((name) => opts[name] !== undefined);
105
- if (chosen.length > 1) {
106
- throw invalidArguments(`Use one operation at a time — got ${chosen.map((c) => `--${c}`).join(' and ')}.`);
107
- }
108
- if (chosen.length === 1) {
109
- const action = chosen[0];
110
- if (inputs.length === 0) {
111
- throw invalidArguments('No files given.', `Name a PDF, for example: forge doc.pdf --${action}`);
112
- }
113
- if (opts.separate && action !== 'extract') {
114
- throw invalidArguments(`--separate only applies to --extract, not --${action}.`);
115
- }
116
- /**
117
- * `PageOpIntent` has no `output` field — `intent.output` is set on the
118
- * convert path below, after this `return` — so `-o` was accepted and then
119
- * silently dropped. Refused outright rather than honoured: five
120
- * operations with five different arities (merge is N:1, split is 1:N)
121
- * each need their own rule for what a single `--output` means, which is
122
- * a later phase's work. Ignoring a flag someone typed is the defect;
123
- * saying so plainly is the fix. Same shape as the `--separate` refusal
124
- * just above.
125
- */
126
- if (opts.output !== undefined) {
127
- throw invalidArguments(`--output does not apply to --${action}.`, 'Page operations name their own outputs, beside the source. Rename the result afterwards.');
128
- }
129
- const pageOp = {
130
- kind: 'pageop',
131
- action,
132
- inputs,
133
- force: Boolean(opts.force),
134
- debug: Boolean(opts.debug),
135
- };
136
- if (action === 'rotate') {
137
- const deg = Number(opts.rotate);
138
- if (!Number.isInteger(deg) || deg % 90 !== 0 || deg === 0 || deg >= 360) {
139
- throw invalidArguments(`--rotate takes a multiple of 90 below 360, not "${opts.rotate}".`);
140
- }
141
- pageOp.rotate = deg;
142
- }
143
- if (action === 'extract' || action === 'delete') {
144
- pageOp.pages = String(opts[action]);
145
- if (action === 'extract' && opts.separate)
146
- pageOp.separate = true;
147
- }
148
- if (action === 'split') {
149
- const raw = String(opts.split);
150
- const every = raw.match(/^every=(\d+)$/);
151
- const at = raw.match(/^at=([\d,\s]+)$/);
152
- if (raw === 'every-page')
153
- pageOp.split = { mode: 'every-page' };
154
- else if (every?.[1] !== undefined) {
155
- // `every=0` matches the regex above and "0" is a truthy string, so
156
- // without this it parsed as a real mode and reached `everyNCuts`,
157
- // whose loop never advances with a step of 0. Validated here for the
158
- // same reason `--rotate` is two branches above, and with the same
159
- // rule the shell's own field already applies (`flows/pdf.tsx`).
160
- const n = Number(every[1]);
161
- if (!Number.isInteger(n) || n < 1) {
162
- throw invalidArguments(`--split every=N takes a whole number of pages, at least 1, not "${every[1]}".`);
163
- }
164
- pageOp.split = { mode: 'every-n', n };
165
- }
166
- else if (at?.[1]) {
167
- pageOp.split = { mode: 'points', after: at[1].split(',').map((s) => Number(s.trim())) };
168
- }
169
- else {
170
- throw invalidArguments(`--split takes every-page, every=N or at=N,N — not "${raw}".`);
171
- }
172
- }
173
- return pageOp;
174
- }
175
- if (inputs.length === 0 && !opts.to && opts.quality === undefined && opts.maxSize === undefined) {
176
- return { kind: 'shell' };
177
- }
178
- /**
179
- * Quality or a size ceiling, with no target format, means compression: keep
180
- * the format, make the file smaller.
181
- */
182
- if (!opts.to && (opts.quality !== undefined || opts.maxSize !== undefined)) {
183
- if (opts.quality !== undefined && opts.maxSize !== undefined) {
184
- throw invalidArguments('Use either --quality or --max-size, not both.', 'They are two ways of asking for the same thing, and Forge will not guess which wins.');
185
- }
186
- if (inputs.length === 0) {
187
- throw invalidArguments('No files given.', 'Name a file, for example: forge photo.jpg --max-size 500kb');
188
- }
189
- const maxBytes = opts.maxSize === undefined ? undefined : parseSize(String(opts.maxSize));
190
- if (opts.maxSize !== undefined && maxBytes === undefined) {
191
- throw invalidArguments(`${opts.maxSize} is not a size.`, 'Try a number with a unit, for example 500kb, 2mb or 1.5mb.');
192
- }
193
- const compressOptions = {
194
- background: String(opts.background),
195
- keepMetadata: Boolean(opts.keepMetadata),
196
- };
197
- const compress = {
198
- kind: 'compress',
199
- inputs,
200
- options: compressOptions,
201
- force: Boolean(opts.force),
202
- recursive: Boolean(opts.recursive),
203
- debug: Boolean(opts.debug),
204
- };
205
- if (opts.quality !== undefined)
206
- compress.quality = parseQuality(String(opts.quality));
207
- if (maxBytes !== undefined)
208
- compress.maxBytes = maxBytes;
209
- // Carried, not dropped: this branch used to have no field for it, so
210
- // `-o` was parsed and silently ignored while the output-exists refusal
211
- // told the user to "choose a different --output".
212
- if (opts.output !== undefined)
213
- compress.output = String(opts.output);
214
- /**
215
- * Only a `--dpi` the user actually typed is carried through.
216
- *
217
- * Commander gives the option a default of '150' for the conversion path,
218
- * so `opts.dpi` is always set and cannot distinguish an explicit 150 from
219
- * the fallback. `getOptionValueSource` can — and it reads the parse this
220
- * call performed, unlike `process.argv`, which is the host process's and
221
- * is wrong under test and anywhere `parseArgs` is handed a synthetic argv.
222
- *
223
- * The distinction matters because absent means "use the compression
224
- * default", which is 150 today but is the engine's business, not this
225
- * file's.
226
- */
227
- if (program.getOptionValueSource('dpi') === 'cli') {
228
- const dpi = Number(opts.dpi);
229
- if (!Number.isInteger(dpi) || dpi < 36 || dpi > 600)
230
- throw invalidDpi(opts.dpi);
231
- compress.dpi = dpi;
232
- }
233
- if (opts.concurrency !== undefined) {
234
- compress.concurrency = parseConcurrency(String(opts.concurrency));
235
- }
236
- return compress;
237
- }
238
- if (!opts.to) {
239
- throw invalidArguments('No target format given.', 'Add --to <format>, for example: forge photo.jpg --to webp');
240
- }
241
- if (inputs.length === 0) {
242
- throw invalidArguments('No files given.', 'Name a file, a folder or a glob, for example: forge photo.jpg --to webp');
243
- }
244
- const options = {
245
- background: String(opts.background),
246
- keepMetadata: Boolean(opts.keepMetadata),
247
- };
248
- if (opts.quality !== undefined)
249
- options.quality = parseQuality(String(opts.quality));
250
- // --dpi always has a value (Commander's default is '150'), so this is
251
- // unconditional — unlike --quality and --pages, which are only ever set
252
- // when the user actually typed them.
253
- const dpi = Number(opts.dpi);
254
- if (!Number.isInteger(dpi) || dpi < 36 || dpi > 600)
255
- throw invalidDpi(opts.dpi);
256
- const intent = {
257
- kind: 'convert',
258
- inputs,
259
- target: parseTarget(String(opts.to)),
260
- options,
261
- force: Boolean(opts.force),
262
- recursive: Boolean(opts.recursive),
263
- debug: Boolean(opts.debug),
264
- dpi,
265
- passwordStdin: Boolean(opts.passwordStdin),
266
- };
267
- if (opts.output !== undefined)
268
- intent.output = String(opts.output);
269
- // Carried through as the raw range text, not parsed here: parsing needs
270
- // the source's page count, which is only known once resolveInputs/probe
271
- // has actually read the file (src/cli/execute.ts does that per source).
272
- if (opts.pages !== undefined)
273
- intent.pages = String(opts.pages);
274
- if (opts.concurrency !== undefined)
275
- intent.concurrency = parseConcurrency(String(opts.concurrency));
276
- return intent;
277
- }
278
- //# sourceMappingURL=args.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAqC,MAAM,qBAAqB,CAAA;AAsFpF;;;;;;GAMG;AACH,SAAS,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adPreferences, savePreferences } from '../config/preferences.js';
2
- export const CONFIG_KEYS = ['output', 'theme', 'quality'];
3
- /**
4
- * Returns lines rather than printing them, for the same reason the rest of
5
- * `cli/` does: the caller owns the streams, so this stays testable without
6
- * capturing stdout.
7
- *
8
- * Exit codes follow spec §9 — 0 for success, 2 for a usage error. A rejected
9
- * value writes nothing, so a typo never half-applies.
10
- */
11
- export async function runConfig(intent) {
12
- if (intent.action === 'path') {
13
- return { stdout: [configPath()], exitCode: 0 };
14
- }
15
- if (intent.action === 'list') {
16
- const { prefs, warning } = await loadPreferences();
17
- const lines = [
18
- `output ${prefs.defaultOutput}`,
19
- `theme ${prefs.theme ?? 'not set'}`,
20
- `quality ${prefs.quality}`,
21
- '',
22
- configPath(),
23
- ];
24
- // A config that could not be read is reported here rather than swallowed:
25
- // this is the one command whose whole job is to say what the settings are.
26
- if (warning !== undefined)
27
- lines.unshift(`⚠ ${warning}`, '');
28
- return { stdout: lines, exitCode: 0 };
29
- }
30
- const { key, value } = intent;
31
- if (key === 'theme') {
32
- if (value !== 'dark' && value !== 'light') {
33
- return { stdout: [`Theme must be dark or light, not ${value}.`], exitCode: 2 };
34
- }
35
- await savePreferences({ theme: value });
36
- return { stdout: [`theme is now ${value}`], exitCode: 0 };
37
- }
38
- if (key === 'quality') {
39
- const n = Number(value);
40
- if (!Number.isInteger(n) || n < 1 || n > 100) {
41
- return {
42
- stdout: [`Quality must be a whole number between 1 and 100, not ${value}.`],
43
- exitCode: 2,
44
- };
45
- }
46
- await savePreferences({ quality: n });
47
- return { stdout: [`quality is now ${n}`], exitCode: 0 };
48
- }
49
- if (value.trim().length === 0) {
50
- return { stdout: ['Output must be a folder path.'], exitCode: 2 };
51
- }
52
- await savePreferences({ defaultOutput: value });
53
- return { stdout: [`output is now ${value}`], exitCode: 0 };
54
- }
55
- //# sourceMappingURL=config-command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-command.js","sourceRoot":"","sources":["../../src/cli/config-command.ts"],"names":[],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