@ponderdev/justfits 1.2.0 → 1.3.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
@@ -18,8 +18,9 @@ Hitting an exact size is arithmetic, not guesswork:
18
18
  intelligible far below the point where picture falls apart, so audio gives
19
19
  way first, and drops to mono before it drops below 48kbps.
20
20
  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.
21
+ enough bits per pixel to look like the source. Over 32 frames a second, it
22
+ tries every size at the full frame rate first, then every size at 30, and
23
+ only then settles for a rougher picture.
23
24
  5. Encode in two passes, which is precisely what two-pass is for.
24
25
  6. Measure what actually came out. x264 overshoots on hard footage, so if it
25
26
  missed, correct by the measured amount and go again. Three attempts.
@@ -43,7 +44,8 @@ Gmail says 25MB and will bounce a 25MB file, so the Gmail preset targets 18.2MB.
43
44
  ## The rules it follows
44
45
 
45
46
  - **Your original is only ever read.** Output goes to `name-fits.mp4` beside
46
- it, and never to a path that already exists.
47
+ it (a folder's go into a new folder beside it), and never to a path that
48
+ already exists.
47
49
  - **Nothing is uploaded.** There is no network code in the app at all.
48
50
  - **No account, no telemetry, no update checker.** The build you have is the
49
51
  build you keep.
@@ -52,11 +54,27 @@ Gmail says 25MB and will bounce a 25MB file, so the Gmail preset targets 18.2MB.
52
54
  ## Running it
53
55
 
54
56
  ```sh
55
- npm install
57
+ nvm use # Node 22, per .nvmrc, and 22.12 or newer. See below.
58
+ npm ci
59
+ npx install-electron # Electron 43 has no postinstall, see below.
56
60
  npm run fetch-ffmpeg # puts ffmpeg and ffprobe in vendor/
57
61
  npm start
58
62
  ```
59
63
 
64
+ Two steps there look redundant and are not:
65
+
66
+ **Node 22.12 or newer matters.** Electron's installer does
67
+ `require('@electron/get')`, which is now an ES module, so it needs
68
+ `require(esm)`. That arrived in Node 22.12. On Node 18 the install fails with
69
+ `ERR_REQUIRE_ESM` and you get a checkout that tests fine and cannot open a
70
+ window.
71
+
72
+ **`npx install-electron` gets the binary now.** Electron 43 dropped its
73
+ postinstall script, so `npm ci` completes in seconds and downloads none of the
74
+ 295MB binary. Electron fetches it the first time it starts instead, which needs
75
+ a network connection and Node 22.12 at that moment. Running the installer up
76
+ front gets that over with while you are watching.
77
+
60
78
  ## The command line
61
79
 
62
80
  ```sh
@@ -77,9 +95,32 @@ justfits clip.mp4 # beside it, as clip-fits.mp4 (a picture
77
95
  justfits clip.mp4 --to gmail # any preset, or a size like 25MB
78
96
  justfits clip.mp4 -o small.mp4 # somewhere specific
79
97
  justfits clip.mp4 --json # for scripting
98
+ justfits a.mp4 b.mov photo.heic # several, each fitted on its own
99
+ justfits "Beach day" # a folder, its subfolders too, into "Beach day (fitted)"
100
+ justfits "Beach day" --beside # a folder, each saved beside its original as name-fits
80
101
  cat clip.mp4 | justfits --to 8MB > small.mp4
81
102
  ```
82
103
 
104
+ Several files, or a folder, are each fitted on their own to the same target,
105
+ one after another. Files named on their own are saved beside their originals.
106
+ A folder's results go into a new folder beside it, `Beach day (fitted)`, with
107
+ its subfolders mirrored and each result named `name-fits` as beside the original (a file that already fits is copied in under that name,
108
+ so the new folder holds the whole folder), and the folder itself
109
+ is left as it was; done again, they go into `Beach day (fitted) 2`. `--beside`
110
+ (in the app, Save next to the originals instead) saves each beside its original
111
+ as `name-fits` instead. In a folder it takes the videos and pictures, and
112
+ passes over hidden files, the `._name` files a Mac leaves on other disks, and
113
+ its own earlier results (`name-fits.mp4` and the `(fitted)` folders), so a
114
+ folder done twice is not fitted on top of itself. `-o` and stdin take one file
115
+ only. In the app, drop several files or a folder on the window, or pick them
116
+ (on a Mac the picker takes folders too; on Windows and Linux, Choose a folder
117
+ brings one in). Cancel stops at once: the file being fitted is left as it was,
118
+ the ones already fitted are kept, and no more are started.
119
+
120
+ `-o` names the one result. A video has to be given an `.mp4` name and a picture
121
+ a `.jpg` name, and anything else is refused before the encode (a file that
122
+ already fits is copied to `-o` as it is, so it may keep its own extension).
123
+
83
124
  If the name is taken it writes `clip-fits 2.mp4`, then 3, and never over an
84
125
  existing file. A file that is neither video nor picture is refused with a
85
126
  sentence saying so (exit 1). With input from stdin and no `-o`, the result goes
@@ -89,19 +130,29 @@ Progress goes to stderr, so stdout stays clean to pipe. Piped input is buffered
89
130
  to a temp file first and it says so: two-pass encoding reads the input twice
90
131
  and a pipe cannot be rewound.
91
132
 
133
+ The piped example is for macOS and Linux shells. In PowerShell, `cat` reads
134
+ the file as text, and Windows PowerShell 5.1 also turns anything piped between
135
+ programs into text, so the video comes out broken. On Windows, name the files
136
+ instead: `justfits clip.mp4 -o small.mp4`.
137
+
92
138
  ### For scripts and assistants
93
139
 
94
140
  - `--json` prints one JSON line per thing it did, then a `done` line: a
95
141
  `result` (written), a `skip` (it already fit) or an `error`. Errors are JSON
96
142
  too. When the video itself goes to stdout, the JSON goes to stderr instead.
143
+ With several files there is one line per file, each with its `input`, and
144
+ one that fails does not stop the rest. One file gives the same lines as
145
+ before.
97
146
  - `--describe` prints every option, its type and default, the targets and the
98
147
  exit codes, as JSON, so nothing has to be guessed from `--help`.
99
148
  - `--dry-run` says what would happen and writes nothing.
100
149
  - `--help`, `--version` and `--describe` answer at once and do nothing else.
101
150
 
102
151
  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.
152
+ target or missing file (nothing was started), **3** several files where some
153
+ were done and some failed, **4** still over the target after every try. With
154
+ several files, 1 means every one failed, and 4 that none failed but some
155
+ stayed over. 129, 130 and 143 mean it was stopped, with part files removed.
105
156
 
106
157
  **Changed in 1.2.0**, for anyone with a script from before: still over the
107
158
  target is now 4 (it was 2, which is now a usage error), and `--json` ends with a
@@ -111,8 +162,43 @@ The fields in a result are the same as before.
111
162
  The maths and the ffmpeg work are shared with the desktop app rather than
112
163
  reimplemented, so both produce the same output for the same input.
113
164
 
165
+ ### For Claude and other assistants
166
+
167
+ The package carries an agent skill, `agents/skills/justfits/SKILL.md`, that
168
+ tells an AI assistant when to reach for Just Fits and how to drive it. Installing
169
+ the command line with `npm install -g` links it in for the assistants set up on
170
+ the machine: into Claude Code's skills folder (`~/.claude/skills/justfits`, or
171
+ under `$CLAUDE_CONFIG_DIR`), and into `~/.agents/skills/justfits`, the shared
172
+ folder that Codex, Gemini CLI, Copilot, Cursor, OpenCode, Amp and Goose read.
173
+ Updating the package updates the skill with it. It never replaces a folder, or
174
+ a link to anywhere else; it only mends a link that an earlier install of Just
175
+ Fits left behind (an uninstall leaves one pointing at nothing). `npm install -g
176
+ --ignore-scripts` skips it. After `npm uninstall -g @ponderdev/justfits`, remove
177
+ the leftover links: on macOS and Linux
178
+ `rm -f ~/.claude/skills/justfits ~/.agents/skills/justfits`, on Windows
179
+ `rmdir "%USERPROFILE%\.claude\skills\justfits" "%USERPROFILE%\.agents\skills\justfits"`
180
+ (each only if it exists; with `CLAUDE_CONFIG_DIR` set, the first is under that).
181
+
182
+ ## On Linux
183
+
184
+ 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).
185
+
186
+ ## Keeping an older version
187
+
188
+ Installing a new version the usual way replaces the old one. To keep both:
189
+
190
+ - **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.
191
+ - **Windows:** the installer replaces the old version, so use the portable download instead (the .exe, or the .zip), each version in its own folder.
192
+ - **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.
193
+
194
+ 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.
195
+
114
196
  ## Licences
115
197
 
198
+ Built with kit 1.0.0, the parts every Just tool shares (the start screen, the
199
+ run, the footer, the folder intake), from PonderDev's tools workshop. The app's
200
+ licences page and `justfits --describe` (`"kit"`) say the same.
201
+
116
202
  GPL-3.0-or-later, like the ffmpeg build it carries. `THIRD-PARTY-NOTICES.md`
117
203
  names every bundled component and how the terms are met; `licenses/` holds the
118
204
  full texts; and both are readable from inside the app under **Licences and
@@ -153,7 +239,3 @@ hand as `ffmpeg-x64`, `ffmpeg-arm64`, `ffprobe-x64`, `ffprobe-arm64`, or with
153
239
  x86_64 only. Those are checked against a published SHA256 before installing,
154
240
  and the script refuses rather than installs on a mismatch. Note the published
155
241
  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,102 @@
1
+ ---
2
+ name: justfits
3
+ description: Shrink a video or picture 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, or a picture, 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`.
65
+ Then `name-fits 2.mp4` and so on: it never writes over a file, and the
66
+ original is only read. `-o path` writes somewhere else.
67
+ - `-o path` names the one result: a video must end in `.mp4` and a picture in
68
+ `.jpg` (a `.mov` or `.png` for the wrong kind is refused with exit 2, before
69
+ anything is encoded). If the file already fits, `-o` still gets a copy of it,
70
+ as a `result` line; without `-o` it is a `skip` line and nothing is written.
71
+ - It reads video (mp4, mov, m4v, mkv, webm, avi) and pictures (jpg, png, heic,
72
+ webp, gif). An animated WebP is refused (exit 1, code `animated-webp`) because
73
+ it would lose its animation. A file that is damaged or is not a video or
74
+ picture is refused with exit 1, never reported as "already fits".
75
+ - `--to` takes a preset or a size such as `25MB`, `800KB` or `1.5GB`. `8b` is
76
+ refused as bytes, since it is one letter from 8MB or 8KB.
77
+ - `--dry-run` says what it would do and writes nothing.
78
+ - With `--json`, stdout is JSON lines: a `result` line (`output`, `before` and
79
+ `after` in bytes, `target`, `attempts`, `width`, `height`, and `notes` when the video is long
80
+ for the target), or a `skip` line
81
+ when it already fits, or an `error` line; then always a `done` line. With
82
+ several files that is one line per file, each with its `input`.
83
+ - Exit codes: 0 done or already fit; 2 a usage mistake (bad option, unknown
84
+ target, missing file), nothing started; 4 still over the target after every
85
+ try, with the closest result written; 1 failed (with several files, every
86
+ one failed); 3 several files where some were done and some failed; 129, 130 or 143 stopped by a
87
+ signal, part files removed.
88
+ - A video takes every CPU core for a minute or more. On a machine someone is
89
+ using, run it as `nice -n 19 justfits ...` and mention that a game or call
90
+ running at the same time may stutter.
91
+
92
+ ## Report back
93
+
94
+ Give the output path in full, the size before and after, and the resolution it
95
+ chose (`width` x `height`). If the resolution came out low, say so and offer
96
+ the next target up, or trimming the video first. A `notes` entry or a line on
97
+ stderr saying the video is long for the target means the picture will be soft
98
+ or blurry: pass that on. On exit 4, say it's still
99
+ over and by how much. For several files, sum it up (how many fitted, the total
100
+ before and after) and name each one that failed or stayed over, with its
101
+ reason. Nothing is uploaded by Just Fits; don't send or upload
102
+ 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.3.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",
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 };