@ponderdev/justfits 1.2.0 → 1.4.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/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Just Fits
2
2
 
3
- Makes a video small enough to send. Point it at a file, pick a limit, and it
3
+ Makes a video, picture or sound file small enough to send. Point it at a file, pick a limit, and it
4
4
  compresses to land just under that limit. Everything happens on your machine.
5
5
 
6
6
  Built because "compress for Discord" is a thing everyone needs and every
7
7
  existing answer is either a website you upload your footage to, or a wall of
8
8
  ffmpeg flags you have to get right yourself.
9
9
 
10
+ Pictures and short clips of it, the newest set for each release, are in its
11
+ press kit on ponderdev.com:
12
+ [press-kit/justfits/manifest.json](https://ponderdev.com/press-kit/justfits/manifest.json)
13
+ lists every one with its address.
14
+
10
15
  ## How it decides
11
16
 
12
17
  Hitting an exact size is arithmetic, not guesswork:
@@ -18,8 +23,9 @@ Hitting an exact size is arithmetic, not guesswork:
18
23
  intelligible far below the point where picture falls apart, so audio gives
19
24
  way first, and drops to mono before it drops below 48kbps.
20
25
  4. Give the rest to picture, then pick the largest frame size that still gets
21
- enough bits per pixel to look like the source. Frame rate halves before the
22
- resolution collapses.
26
+ enough bits per pixel to look like the source. Over 32 frames a second, it
27
+ tries every size at the full frame rate first, then every size at 30, and
28
+ only then settles for a rougher picture.
23
29
  5. Encode in two passes, which is precisely what two-pass is for.
24
30
  6. Measure what actually came out. x264 overshoots on hard footage, so if it
25
31
  missed, correct by the measured amount and go again. Three attempts.
@@ -28,6 +34,17 @@ All of that lives in `src/plan.js` as pure functions, with no ffmpeg and no
28
34
  filesystem anywhere near it, because whether your file comes in under the line
29
35
  is the one thing this has to get right. `test/plan.test.cjs` covers it.
30
36
 
37
+ ### Sound on its own
38
+
39
+ A sound file (mp3, m4a, aac, wav, flac, ogg, opus, aif, aiff) goes through the
40
+ same arithmetic with nothing else to share the budget: the target, minus 5
41
+ percent and a few KB for the m4a's own headers, becomes one AAC bitrate. It is
42
+ never higher than the source's own bitrate or 192kbps, it is stereo from 64kbps
43
+ and mono below that (only for a source that has two channels), and under 16kbps
44
+ it cannot fit and says so the way a video does. If the result comes out over,
45
+ it tries once more, lower by what it measured. The result is an `.m4a`, and
46
+ cover art is left out, since the size is the point.
47
+
31
48
  ## The presets
32
49
 
33
50
  Checked August 2026, and they move, so they live in one list in `src/plan.js`
@@ -43,7 +60,8 @@ Gmail says 25MB and will bounce a 25MB file, so the Gmail preset targets 18.2MB.
43
60
  ## The rules it follows
44
61
 
45
62
  - **Your original is only ever read.** Output goes to `name-fits.mp4` beside
46
- it, and never to a path that already exists.
63
+ it (a folder's go into a new folder beside it), and never to a path that
64
+ already exists.
47
65
  - **Nothing is uploaded.** There is no network code in the app at all.
48
66
  - **No account, no telemetry, no update checker.** The build you have is the
49
67
  build you keep.
@@ -52,11 +70,27 @@ Gmail says 25MB and will bounce a 25MB file, so the Gmail preset targets 18.2MB.
52
70
  ## Running it
53
71
 
54
72
  ```sh
55
- npm install
73
+ nvm use # Node 22, per .nvmrc, and 22.12 or newer. See below.
74
+ npm ci
75
+ npx install-electron # Electron 43 has no postinstall, see below.
56
76
  npm run fetch-ffmpeg # puts ffmpeg and ffprobe in vendor/
57
77
  npm start
58
78
  ```
59
79
 
80
+ Two steps there look redundant and are not:
81
+
82
+ **Node 22.12 or newer matters.** Electron's installer does
83
+ `require('@electron/get')`, which is now an ES module, so it needs
84
+ `require(esm)`. That arrived in Node 22.12. On Node 18 the install fails with
85
+ `ERR_REQUIRE_ESM` and you get a checkout that tests fine and cannot open a
86
+ window.
87
+
88
+ **`npx install-electron` gets the binary now.** Electron 43 dropped its
89
+ postinstall script, so `npm ci` completes in seconds and downloads none of the
90
+ 295MB binary. Electron fetches it the first time it starts instead, which needs
91
+ a network connection and Node 22.12 at that moment. Running the installer up
92
+ front gets that over with while you are watching.
93
+
60
94
  ## The command line
61
95
 
62
96
  ```sh
@@ -64,6 +98,10 @@ npm install -g @ponderdev/justfits
64
98
  justfits clip.mp4 --to discord
65
99
  ```
66
100
 
101
+ Installing or upgrading over Just Fits 1.1.0 or earlier, which installed from
102
+ GitHub under the plain name `justfits`, uninstall that one first with
103
+ `npm uninstall -g justfits`, or npm stops with EEXIST on the `justfits` command.
104
+
67
105
  No dependencies and no bundled encoder, so the install is under 2MB. It uses
68
106
  whatever ffmpeg is on your PATH, which on Linux is one package away
69
107
  (`pacman -S ffmpeg`, `apt install ffmpeg`). The desktop app carries its own
@@ -72,16 +110,47 @@ told to install a video encoder.
72
110
 
73
111
  Needs Node 22 or newer, and an ffmpeg with libx264 on the PATH (no minimum version has been tested).
74
112
 
113
+ What it takes in:
114
+
115
+ - Video: mp4, mov, m4v, mkv, webm, avi. Comes out as `.mp4`.
116
+ - Pictures: jpg, png, heic, webp, gif (not an animated webp). Come out as `.jpg`.
117
+ - Sound: mp3, m4a, aac, wav, flac, ogg, opus, aif, aiff. Comes out as `.m4a`
118
+ (AAC), without cover art.
119
+
75
120
  ```sh
76
121
  justfits clip.mp4 # beside it, as clip-fits.mp4 (a picture becomes clip-fits.jpg)
77
122
  justfits clip.mp4 --to gmail # any preset, or a size like 25MB
78
123
  justfits clip.mp4 -o small.mp4 # somewhere specific
79
124
  justfits clip.mp4 --json # for scripting
125
+ justfits song.wav --to gmail # sound comes out as song-fits.m4a (AAC, no cover art)
126
+ justfits a.mp4 b.mov photo.heic # several, each fitted on its own
127
+ justfits "Beach day" # a folder, its subfolders too, into "Beach day (fitted)"
128
+ justfits "Beach day" --beside # a folder, each saved beside its original as name-fits
80
129
  cat clip.mp4 | justfits --to 8MB > small.mp4
81
130
  ```
82
131
 
132
+ Several files, or a folder, are each fitted on their own to the same target,
133
+ one after another. Files named on their own are saved beside their originals.
134
+ A folder's results go into a new folder beside it, `Beach day (fitted)`, with
135
+ its subfolders mirrored and each result named `name-fits` as beside the original (a file that already fits is copied in under that name,
136
+ so the new folder holds the whole folder), and the folder itself
137
+ is left as it was; done again, they go into `Beach day (fitted) 2`. `--beside`
138
+ (in the app, Save next to the originals instead) saves each beside its original
139
+ as `name-fits` instead. In a folder it takes the videos, pictures and sound files, and
140
+ passes over hidden files, the `._name` files a Mac leaves on other disks, and
141
+ its own earlier results (`name-fits.mp4` and the `(fitted)` folders), so a
142
+ folder done twice is not fitted on top of itself. `-o` and stdin take one file
143
+ only. In the app, drop several files or a folder on the window, or pick them
144
+ (on a Mac the picker takes folders too; on Windows and Linux, Choose a folder
145
+ brings one in). Cancel stops at once: the file being fitted is left as it was,
146
+ the ones already fitted are kept, and no more are started.
147
+
148
+ `-o` names the one result. A video has to be given an `.mp4` name and a picture
149
+ a `.jpg` name, and a sound file an `.m4a` name, and anything else is refused before the encode (a file that
150
+ already fits is copied to `-o` as it is, so it may keep its own extension).
151
+
83
152
  If the name is taken it writes `clip-fits 2.mp4`, then 3, and never over an
84
- existing file. A file that is neither video nor picture is refused with a
153
+ existing file. A file that is none of video, picture or sound is refused with a
85
154
  sentence saying so (exit 1). With input from stdin and no `-o`, the result goes
86
155
  to stdout.
87
156
 
@@ -89,19 +158,29 @@ Progress goes to stderr, so stdout stays clean to pipe. Piped input is buffered
89
158
  to a temp file first and it says so: two-pass encoding reads the input twice
90
159
  and a pipe cannot be rewound.
91
160
 
161
+ The piped example is for macOS and Linux shells. In PowerShell, `cat` reads
162
+ the file as text, and Windows PowerShell 5.1 also turns anything piped between
163
+ programs into text, so the video comes out broken. On Windows, name the files
164
+ instead: `justfits clip.mp4 -o small.mp4`.
165
+
92
166
  ### For scripts and assistants
93
167
 
94
168
  - `--json` prints one JSON line per thing it did, then a `done` line: a
95
169
  `result` (written), a `skip` (it already fit) or an `error`. Errors are JSON
96
170
  too. When the video itself goes to stdout, the JSON goes to stderr instead.
171
+ With several files there is one line per file, each with its `input`, and
172
+ one that fails does not stop the rest. One file gives the same lines as
173
+ before.
97
174
  - `--describe` prints every option, its type and default, the targets and the
98
175
  exit codes, as JSON, so nothing has to be guessed from `--help`.
99
176
  - `--dry-run` says what would happen and writes nothing.
100
177
  - `--help`, `--version` and `--describe` answer at once and do nothing else.
101
178
 
102
179
  Exit status: **0** done or already fits, **1** failed, **2** a bad option,
103
- target or missing file (nothing was started), **4** still over the target
104
- after every try. 129, 130 and 143 mean it was stopped, with part files removed.
180
+ target or missing file (nothing was started), **3** several files where some
181
+ were done and some failed, **4** still over the target after every try. With
182
+ several files, 1 means every one failed, and 4 that none failed but some
183
+ stayed over. 129, 130 and 143 mean it was stopped, with part files removed.
105
184
 
106
185
  **Changed in 1.2.0**, for anyone with a script from before: still over the
107
186
  target is now 4 (it was 2, which is now a usage error), and `--json` ends with a
@@ -111,8 +190,47 @@ The fields in a result are the same as before.
111
190
  The maths and the ffmpeg work are shared with the desktop app rather than
112
191
  reimplemented, so both produce the same output for the same input.
113
192
 
193
+ ### For Claude and other assistants
194
+
195
+ The package carries an agent skill, `agents/skills/justfits/SKILL.md`, that
196
+ tells an AI assistant when to reach for Just Fits and how to drive it. Installing
197
+ the command line with `npm install -g` links it in for the assistants set up on
198
+ the machine: into Claude Code's skills folder (`~/.claude/skills/justfits`, or
199
+ under `$CLAUDE_CONFIG_DIR`) when that folder exists, and into
200
+ `~/.agents/skills/justfits`, the shared folder that Codex, Gemini CLI, Copilot,
201
+ Cursor, OpenCode, Amp and Goose read, only when `~/.agents` is there or one of
202
+ those assistants has its own folder (`~/.codex`, `~/.gemini`, `~/.copilot`,
203
+ `~/.cursor`, or `opencode`, `amp` or `goose` under `~/.config`). With Claude Code
204
+ alone, only the Claude link is made.
205
+ Updating the package updates the skill with it. It never replaces a folder, or
206
+ a link to anywhere else; it only mends a link that an earlier install of Just
207
+ Fits left behind (an uninstall leaves one pointing at nothing). `npm install -g
208
+ --ignore-scripts` skips it. After `npm uninstall -g @ponderdev/justfits`, remove
209
+ the leftover links: on macOS and Linux
210
+ `rm -f ~/.claude/skills/justfits ~/.agents/skills/justfits`, on Windows
211
+ `rmdir "%USERPROFILE%\.claude\skills\justfits" "%USERPROFILE%\.agents\skills\justfits"`
212
+ (each only if it exists; with `CLAUDE_CONFIG_DIR` set, the first is under that).
213
+
214
+ ## On Linux
215
+
216
+ Unpack the .tar.gz and run `./justfits` in the folder; the AppImage needs only to be made executable. Both start the app with Chromium's sandbox where your system allows it, and without it where it does not, because Ubuntu 24.04 forbids the user namespaces the sandbox needs and the program file inside the .tar.gz (`justfits-app`) then stops at once with a "SUID sandbox helper" error unless given `--no-sandbox`. To put Just Fits in your applications menu with its icon, run `./install-desktop-entry.sh` in the unpacked folder (again if you move it).
217
+
218
+ ## Keeping an older version
219
+
220
+ Installing a new version the usual way replaces the old one. To keep both:
221
+
222
+ - **Mac:** rename the old app in Applications first (to "Just Fits 1.2.0", say), then install the new one. Both open, side by side.
223
+ - **Windows:** the installer replaces the old version, so use the portable download instead (the .exe, or the .zip), each version in its own folder.
224
+ - **Linux:** each AppImage is its own file, so keep the old one beside the new. The .tar.gz works the same way, in its own folder.
225
+
226
+ The two versions share your settings. A newer version's settings are kept when the older one saves, and the older one ignores what it does not know.
227
+
114
228
  ## Licences
115
229
 
230
+ Built with kit 1.1.0, the parts every Just tool shares (the start screen, the
231
+ run, the footer, the folder intake), from PonderDev's tools workshop. The app's
232
+ licences page and `justfits --describe` (`"kit"`) say the same.
233
+
116
234
  GPL-3.0-or-later, like the ffmpeg build it carries. `THIRD-PARTY-NOTICES.md`
117
235
  names every bundled component and how the terms are met; `licenses/` holds the
118
236
  full texts; and both are readable from inside the app under **Licences and
@@ -145,15 +263,15 @@ container is a real test of it. The GUI is not testable this way.
145
263
  redistribute through our history, and they move on someone else's schedule.
146
264
  `npm run fetch-ffmpeg` pulls them, `--all` gets every arch a release needs.
147
265
 
148
- Any GPL build with libx264 works. If a host moves, drop the binaries in by
149
- hand as `ffmpeg-x64`, `ffmpeg-arm64`, `ffprobe-x64`, `ffprobe-arm64`, or with
150
- `.exe` on Windows. Nothing in the app cares where they came from.
266
+ Any GPL build with libx264 works, and never a nonfree one: every build, fetched
267
+ or already there, is checked by the configure line it carries, and refused if
268
+ it was built with `--enable-nonfree`, without `--enable-gpl`, or (for ffmpeg)
269
+ without libx264. If a host moves, drop the binaries in by hand as
270
+ `ffmpeg-darwin-arm64`, `ffprobe-linux-x64`, `ffmpeg-win32-x64.exe` and so on
271
+ (the full list is at the top of `scripts/fetch-ffmpeg.mjs`), then run
272
+ `node scripts/fetch-ffmpeg.mjs --verify`, which checks them and fetches nothing.
151
273
 
152
274
  **Apple Silicon** builds come from osxexperts.net, since evermeet publishes
153
275
  x86_64 only. Those are checked against a published SHA256 before installing,
154
276
  and the script refuses rather than installs on a mismatch. Note the published
155
277
  hash is of the binary inside the zip, not of the zip.
156
-
157
- ## Still to do
158
-
159
- - test a packaged build on Apple Silicon and on Windows, on real hardware
@@ -17,11 +17,13 @@ resolution, frame rate and stream layout that `src/plan.js` does its
17
17
  arithmetic on.
18
18
 
19
19
  - Project: <https://ffmpeg.org>, source at <https://github.com/FFmpeg/FFmpeg>
20
- - FFmpeg's core is **LGPL v2.1 or later**. The builds shipped here are
21
- configured with `--enable-gpl` and `--enable-version3`, which pulls in the
22
- GPL-licensed parts and moves the whole binary to **GPL v3 or later**.
20
+ - FFmpeg's core is **LGPL v2.1 or later**. Every build shipped here is
21
+ configured with `--enable-gpl`, which pulls in the GPL-licensed parts and
22
+ moves the whole binary to the GPL. Builds that also carry
23
+ `--enable-version3` are **GPL v3 or later**; builds without it are **GPL v2
24
+ or later**. The table below says which is which.
23
25
  - Full text: `licenses/ffmpeg-license.txt`, and the GPL itself in
24
- `licenses/gpl-3.0.txt`.
26
+ `licenses/gpl-3.0.txt` and `licenses/gpl-2.0.txt`.
25
27
 
26
28
  **On the command line, FFmpeg is not bundled at all.** The `justfits` command
27
29
  uses whatever `ffmpeg` and `ffprobe` are on your PATH, so the terms that apply
@@ -29,12 +31,20 @@ are those of the build your system installed, not of anything shipped here.
29
31
  Only the desktop app carries its own copy.
30
32
 
31
33
  **The bundled binaries are not built here and are not modified.** They are
32
- published builds, taken as-is:
34
+ published builds, taken exactly as the publisher shipped them. The publishers
35
+ differ per platform, and so do their configure lines, so the effective licence
36
+ is stated per build rather than once for all of them:
33
37
 
34
- | Platform | Source |
35
- | --- | --- |
36
- | macOS | [evermeet.cx/ffmpeg](https://evermeet.cx/ffmpeg/) |
37
- | Windows | [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds) |
38
+ | Platform and arch | Publisher | Licence, from the configure line |
39
+ | --- | --- | --- |
40
+ | macOS x86_64 | [evermeet.cx/ffmpeg](https://evermeet.cx/ffmpeg/) | `--enable-gpl --enable-version3`, so **GPL v3 or later** |
41
+ | macOS arm64 | [osxexperts.net](https://www.osxexperts.net) | `--enable-gpl`, no `--enable-version3`, so **GPL v2 or later** |
42
+ | Windows x86_64 | [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds) (the `win64-gpl` build) | `--enable-gpl --enable-version3`, so **GPL v3 or later** |
43
+ | Linux x86_64 | [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds) (the `linux64-gpl` build) | `--enable-gpl --enable-version3`, so **GPL v3 or later** |
44
+
45
+ All four were read out of the builds those sources served, last on 15 November
46
+ 2026. Publishers change their configure lines, so the copy on your machine is
47
+ the authoritative answer for your copy.
38
48
 
39
49
  `scripts/fetch-ffmpeg.mjs` is what downloads them, and it is the complete
40
50
  record of where they came from. To see exactly how the copy on your machine
@@ -82,7 +92,8 @@ The application shell: Chromium for the window, Node for the file handling.
82
92
 
83
93
  ## Meeting the GPL terms
84
94
 
85
- FFmpeg as shipped here is GPL v3. Distributing it inside an application carries
95
+ FFmpeg as shipped here is GPL v3 or later, or GPL v2 or later on Apple Silicon
96
+ (the table above). Distributing it inside an application carries
86
97
  obligations, and Just Fits meets them like this:
87
98
 
88
99
  0. **Compatibility.** Just Fits is GPL-3.0-or-later, the same licence, so there
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: justfits
3
+ description: Shrink a video, picture or sound file to fit a size limit with Just Fits (`justfits`), PonderDev's free command line and app, so it can be sent on Discord, email, WhatsApp, Signal, Slack and the rest. Use when the user wants to send, share, upload or attach a file that is too big: "make this fit Discord", "compress this video", "it's too big to send", "get this under 50MB", "shrink this clip for Gmail", "make every video in this folder fit". Runs entirely on the user's machine. Covers checking it's installed, picking the target, running it, and checking the result.
4
+ ---
5
+
6
+ # Making a file fit with Just Fits
7
+
8
+ **Just Fits** (`justfits`) compresses a video, a picture or a sound file to land just under
9
+ a size limit, and measures the result. It is PonderDev's free tool: page
10
+ https://ponderdev.com/justfits, source `ponder-dev/just-fits`. Use it instead of
11
+ hand-written ffmpeg: it works out the bitrate and size, makes as many tries as
12
+ it needs, and never writes over a file.
13
+
14
+ ## Is it installed?
15
+
16
+ command -v justfits && justfits --version
17
+
18
+ If not, the command line installs with `npm install -g @ponderdev/justfits`
19
+ (Node 22 or newer). That install uses `ffmpeg` from the PATH, so check
20
+ `command -v ffmpeg` too; if it's missing, say so and suggest the system's
21
+ package manager (`brew install ffmpeg`, `apt install ffmpeg`,
22
+ `winget install Gyan.FFmpeg`). The desktop app, from the page's download
23
+ button, carries its own ffmpeg. Ask before installing anything.
24
+
25
+ `justfits --help` and `justfits --describe` only print, so they're safe to run.
26
+ `--help` lists the current targets.
27
+
28
+ ## Pick the target: ask where it's going
29
+
30
+ The limit decides the quality, so ask where the file is going if the user
31
+ hasn't said. A long video into a small target comes out small and soft; say so
32
+ before running.
33
+
34
+ | `--to` | Size | For |
35
+ | --- | --- | --- |
36
+ | `discord` (default) | 10MB | Discord, free account |
37
+ | `discord-basic` | 50MB | Discord Nitro Basic |
38
+ | `discord-boost3` | 100MB | a Discord server boosted to level 3 |
39
+ | `discord-nitro` | 500MB | Discord Nitro |
40
+ | `gmail` | 18.2MB | Gmail (its 25MB limit, less the email encoding) |
41
+ | `outlook` | 14.6MB | Outlook and Microsoft 365 |
42
+ | `whatsapp` | 16MB | WhatsApp video |
43
+ | `signal`, `imessage` | 100MB | Signal, iMessage |
44
+ | `slack` / `telegram` | 1GB / 2GB | Slack, Telegram |
45
+ | `25MB` etc. | any | a plain size |
46
+
47
+ Services change their limits; `justfits --help` on the installed copy is the
48
+ list that counts. If the file already fits, Just Fits says so and writes
49
+ nothing: send the original.
50
+
51
+ ## Run it
52
+
53
+ justfits "/path/to/video.mp4" --to discord-basic --json
54
+
55
+ - Several files, or a folder (subfolders too), go in one run:
56
+ `justfits a.mp4 b.mov --to gmail --json` or `justfits "/path/to/folder" --json`.
57
+ Each is fitted on its own to the same target; nothing is combined. Files
58
+ named on their own are saved beside their originals; a folder's results go
59
+ into a new folder beside it, `folder (fitted)` (subfolders mirrored, results
60
+ named `name-fits`, files that already fit copied in so the folder is
61
+ complete, the folder untouched). `--beside` saves each beside its original as
62
+ `name-fits` instead. In a folder, hidden files, earlier `-fits` results and
63
+ `(fitted)` folders are passed over. `-o` and stdin take one file only.
64
+ - A video comes out as `name-fits.mp4` beside it, a picture as `name-fits.jpg`, a sound file as `name-fits.m4a` (AAC; cover art is
65
+ left out, since the size is the point).
66
+ Then `name-fits 2.mp4` and so on: it never writes over a file, and the
67
+ original is only read. `-o path` writes somewhere else.
68
+ - `-o path` names the one result: a video must end in `.mp4`, a picture in
69
+ `.jpg` and a sound file in `.m4a` (a `.mov` or `.png` for the wrong kind is refused with exit 2, before
70
+ anything is encoded). If the file already fits, `-o` still gets a copy of it,
71
+ as a `result` line; without `-o` it is a `skip` line and nothing is written.
72
+ - It reads video (mp4, mov, m4v, mkv, webm, avi), pictures (jpg, png, heic,
73
+ webp, gif) and sound (mp3, m4a, aac, wav, flac, ogg, opus, aif, aiff). An animated WebP is refused (exit 1, code `animated-webp`) because
74
+ it would lose its animation. A file that is damaged or is not a video or
75
+ picture is refused with exit 1, never reported as "already fits".
76
+ - `--to` takes a preset or a size such as `25MB`, `800KB` or `1.5GB`. `8b` is
77
+ refused as bytes, since it is one letter from 8MB or 8KB.
78
+ - `--dry-run` says what it would do and writes nothing.
79
+ - With `--json`, stdout is JSON lines: a `result` line (`output`, `before` and
80
+ `after` in bytes, `target`, `attempts`, `kind` (`video`, `image` or `audio`),
81
+ `width` and `height` (a sound file has `kbps` and `channels` instead), and `notes`
82
+ when the video or sound is long for the target), or a `skip` line
83
+ when it already fits, or an `error` line; then always a `done` line. With
84
+ several files that is one line per file, each with its `input`.
85
+ - Exit codes: 0 done or already fit; 2 a usage mistake (bad option, unknown
86
+ target, missing file), nothing started; 4 still over the target after every
87
+ try, with the closest result written; 1 failed (with several files, every
88
+ one failed); 3 several files where some were done and some failed; 129, 130 or 143 stopped by a
89
+ signal, part files removed.
90
+ - A video takes every CPU core for a minute or more. On a machine someone is
91
+ using, run it as `nice -n 19 justfits ...` and mention that a game or call
92
+ running at the same time may stutter.
93
+
94
+ ## Report back
95
+
96
+ Give the output path in full, the size before and after, and the resolution it
97
+ chose (`width` x `height`), or for sound the bitrate (`kbps`). If the resolution came out low, say so and offer
98
+ the next target up, or trimming the video first. A `notes` entry or a line on
99
+ stderr saying the video is long for the target means the picture will be soft
100
+ or blurry: pass that on. On exit 4, say it's still
101
+ over and by how much. For several files, sum it up (how many fitted, the total
102
+ before and after) and name each one that failed or stayed over, with its
103
+ reason. Nothing is uploaded by Just Fits; don't send or upload
104
+ the file yourself unless the user asks.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ponderdev/justfits",
3
3
  "productName": "Just Fits",
4
- "version": "1.2.0",
4
+ "version": "1.4.0",
5
5
  "description": "Make a file small enough to send. Compresses video and images to an exact size limit, entirely on your own machine.",
6
6
  "author": {
7
7
  "name": "PonderDev",
@@ -17,28 +17,37 @@
17
17
  },
18
18
  "license": "GPL-3.0-or-later",
19
19
  "main": "src/main.cjs",
20
+ "desktopName": "com.ponderdev.justfits.desktop",
20
21
  "bin": {
21
22
  "justfits": "src/cli.cjs"
22
23
  },
23
24
  "scripts": {
24
- "start": "electron .",
25
- "test": "node test/plan.test.cjs && node test/contract.test.cjs",
25
+ "start": "node scripts/electron.cjs .",
26
+ "test": "node test/plan.test.cjs && node test/contract.test.cjs && node test/skill.test.cjs && node test/scripts.test.cjs && node test/linux-launcher.test.cjs && node test/encode.test.cjs && node test/words.test.cjs",
26
27
  "fetch-ffmpeg": "node scripts/fetch-ffmpeg.mjs",
27
28
  "licences": "node scripts/make-licenses.mjs",
28
- "icon": "node scripts/make-icon.mjs && electron scripts/icons.cjs && ./scripts/make-icns.sh",
29
- "dist:mac": "npm run licences && electron-builder --mac",
30
- "dist:win": "npm run licences && electron-builder --win",
31
- "dist": "npm run licences && electron-builder --mac --win --linux",
29
+ "icon": "npm run icon:svg && npm run icon:raster && npm run icon:icns",
30
+ "dist:mac": "node scripts/fetch-ffmpeg.mjs --mac && npm run icon && npm run licences && electron-builder --mac",
31
+ "dist:win": "node scripts/fetch-ffmpeg.mjs --win && npm run icon:svg && npm run icon:raster && npm run licences && electron-builder --win",
32
+ "dist": "node scripts/fetch-ffmpeg.mjs --all && npm run icon && npm run licences && electron-builder --mac --win --linux",
32
33
  "cli": "node src/cli.cjs",
33
34
  "test:linux": "./scripts/test-linux.sh",
34
35
  "test:cli": "node test/cli.test.cjs && node test/safety.test.cjs",
35
- "test:window": "env -u ELECTRON_RUN_AS_NODE electron test/window.test.cjs",
36
- "dist:linux": "npm run licences && electron-builder --linux"
36
+ "test:window": "node scripts/electron.cjs test/window.test.cjs",
37
+ "dist:linux": "node scripts/fetch-ffmpeg.mjs --linux && npm run icon:ensure && npm run licences && electron-builder --linux",
38
+ "icon:png": "npm run icon:svg && npm run icon:raster",
39
+ "icon:ensure": "node scripts/ensure-icon.cjs",
40
+ "icon:svg": "node scripts/make-icon.mjs",
41
+ "icon:raster": "node scripts/electron.cjs scripts/icons.cjs",
42
+ "icon:icns": "./scripts/make-icns.sh",
43
+ "postinstall": "node scripts/link-skill.cjs"
37
44
  },
38
45
  "files": [
39
46
  "src/**/*",
40
47
  "LICENSE",
41
48
  "THIRD-PARTY-NOTICES.md",
42
- "licenses/**/*"
49
+ "licenses/**/*",
50
+ "agents/**/*",
51
+ "scripts/link-skill.cjs"
43
52
  ]
44
53
  }
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // Links this tool's agent skill into the folders AI assistants read skills
4
+ // from, when the command line is installed globally with npm, so the skill
5
+ // always matches the installed version (decided 2026-11-15: every Just tool
6
+ // ships its own skill; 2026-11-16: link it for Claude and for the shared folder).
7
+ //
8
+ // Two places, each with the same rules:
9
+ //
10
+ // - Claude Code: ~/.claude/skills/<tool>, or $CLAUDE_CONFIG_DIR/skills/<tool>,
11
+ // when that folder exists.
12
+ // - The shared folder most other assistants read (Codex, Gemini CLI,
13
+ // Copilot, Cursor, OpenCode, Amp, Goose): ~/.agents/skills/<tool>, when
14
+ // ~/.agents exists or one of those assistants is set up here.
15
+ //
16
+ // npm runs this as the package's postinstall. It does nothing unless the
17
+ // install is global (npm install -g), never in a project's node_modules or a
18
+ // checkout of this repo. In each place it links only when nothing is there or
19
+ // the link is one an earlier npm install of this tool left (an older Node,
20
+ // say, or one whose package has since been uninstalled); a folder, a file, or a link to anywhere else is left exactly as it is.
21
+ //
22
+ // The link points into the installed package, so updating the package updates
23
+ // the skill with no further step. It never fails the install: npm install
24
+ // --ignore-scripts skips it altogether. On Windows the link is a directory
25
+ // junction, which needs no admin rights.
26
+
27
+ const fs = require('fs');
28
+ const os = require('os');
29
+ const path = require('path');
30
+
31
+ // Folders whose presence says an assistant that reads ~/.agents/skills is set
32
+ // up on this machine.
33
+ const AGENT_HOMES = ['.agents', '.codex', '.gemini', '.copilot', '.cursor',
34
+ path.join('.config', 'opencode'), path.join('.config', 'amp'), path.join('.config', 'goose')];
35
+
36
+ function places(home) {
37
+ const out = [];
38
+ const claude = process.env.CLAUDE_CONFIG_DIR || path.join(home, '.claude');
39
+ if (fs.existsSync(claude)) out.push(path.join(claude, 'skills'));
40
+ if (AGENT_HOMES.some((d) => fs.existsSync(path.join(home, d)))) out.push(path.join(home, '.agents', 'skills'));
41
+ return out;
42
+ }
43
+
44
+ function main() {
45
+ if (process.env.npm_config_global !== 'true') return;
46
+
47
+ const pkg = require('../package.json');
48
+ const id = Object.keys(pkg.bin || {})[0];
49
+ if (!id) return;
50
+
51
+ const source = path.resolve(__dirname, '..', 'agents', 'skills', id);
52
+ if (!fs.existsSync(path.join(source, 'SKILL.md'))) return;
53
+
54
+ for (const skills of places(os.homedir())) {
55
+ try { link(source, skills, id); } catch (err) {
56
+ say(`${id}: skill not linked into ${skills}: ${err.message}`);
57
+ }
58
+ }
59
+ }
60
+
61
+ function link(source, skills, id) {
62
+ const dest = path.join(skills, id);
63
+ let st = null;
64
+ try { st = fs.lstatSync(dest); } catch { /* nothing there */ }
65
+
66
+ if (st && !st.isSymbolicLink()) {
67
+ say(`${id}: ${dest} is already there and not a link, so it was left alone. ` +
68
+ `Remove it and install again to use the skill that comes with ${id}.`);
69
+ return;
70
+ }
71
+ if (st) {
72
+ const old = path.resolve(skills, fs.readlinkSync(dest));
73
+ if (old === source) return;
74
+ // Only a link an earlier install of this tool left is replaced, whether
75
+ // or not its target is still there (an uninstall leaves one dangling).
76
+ // A link to anywhere else is someone's own, even a broken one.
77
+ if (!isOurs(old, id)) {
78
+ say(`${id}: ${dest} links to ${old}, so it was left alone.`);
79
+ return;
80
+ }
81
+ fs.unlinkSync(dest);
82
+ }
83
+
84
+ fs.mkdirSync(skills, { recursive: true });
85
+ fs.symlinkSync(source, dest, process.platform === 'win32' ? 'junction' : 'dir');
86
+ say(`${id}: linked its skill into ${dest}`);
87
+ }
88
+
89
+ // A link an earlier npm install of this same tool left behind.
90
+ function isOurs(target, id) {
91
+ return target.split(path.sep).includes('node_modules') &&
92
+ target.endsWith(path.join('agents', 'skills', id));
93
+ }
94
+
95
+ function say(line) { process.stderr.write(line + '\n'); }
96
+
97
+ try { main(); } catch (err) {
98
+ say(`skill not linked: ${err.message}`);
99
+ }
package/src/binaries.cjs CHANGED
@@ -17,17 +17,33 @@ const { execFileSync } = require('node:child_process');
17
17
 
18
18
  const EXE = process.platform === 'win32' ? '.exe' : '';
19
19
 
20
- function fromDir(dir, name) {
20
+ // What kind of program a file is, from its first bytes: 'linux' (ELF),
21
+ // 'darwin' (Mach-O, thin or universal) or 'win32' (a DOS/PE stub). null for a
22
+ // script or anything else.
23
+ function kindOf(file) {
24
+ try {
25
+ const fd = fs.openSync(file, 'r');
26
+ const head = Buffer.alloc(4);
27
+ try { fs.readSync(fd, head, 0, 4, 0); } finally { fs.closeSync(fd); }
28
+ const hex = head.toString('hex');
29
+ if (hex === '7f454c46') return 'linux';
30
+ if (['cffaedfe', 'cefaedfe', 'feedface', 'feedfacf', 'cafebabe', 'bebafeca'].includes(hex)) return 'darwin';
31
+ if (head.toString('latin1', 0, 2) === 'MZ') return 'win32';
32
+ } catch { /* unreadable, so not usable */ }
33
+ return null;
34
+ }
35
+
36
+ function fromDir(dir, name, platform = process.platform, arch = process.arch) {
21
37
  if (!dir) return null;
22
- // Platform first: linux and mac both call themselves x64, so an arch alone
23
- // is not enough to tell a linux binary from a mac one sitting side by side.
24
- for (const candidate of [
25
- `${name}-${process.platform}-${process.arch}${EXE}`,
26
- `${name}-${process.arch}${EXE}`,
27
- `${name}${EXE}`,
28
- ]) {
38
+ const exe = platform === 'win32' ? '.exe' : '';
39
+ // The platform-and-arch name says what it is. The older names (an arch alone,
40
+ // or none) do not, and linux and mac both call themselves x64, so one of
41
+ // them is taken only if its own bytes say it is a program for this platform.
42
+ const exact = path.join(dir, `${name}-${platform}-${arch}${exe}`);
43
+ if (fs.existsSync(exact)) return exact;
44
+ for (const candidate of [`${name}-${arch}${exe}`, `${name}${exe}`]) {
29
45
  const full = path.join(dir, candidate);
30
- if (fs.existsSync(full)) return full;
46
+ if (fs.existsSync(full) && kindOf(full) === platform) return full;
31
47
  }
32
48
  return null;
33
49
  }
@@ -87,4 +103,4 @@ function resolve(name, dirs = [], allowPath = true) {
87
103
  );
88
104
  }
89
105
 
90
- module.exports = { resolve, fromDir, fromPath };
106
+ module.exports = { resolve, fromDir, fromPath, kindOf };