@bitefoundry/linear 0.0.1 → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BiteFoundry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # @bitefoundry/linear
1
+ # linear (`@bitefoundry/linear`)
2
2
 
3
- Bootstrap placeholder for BiteFoundry/linear Trusted Publishing. Real binary ships in v0.1.0.
3
+ Fast, single-binary Rust terminal client & AI agent toolkit for [Linear](https://linear.app) — Issues, Cycles, Projects, Triage, Offline SQLite FTS5 search, hardened local HTTP API (`127.0.0.1:8794`), and **20 typed MCP tools**.
4
+
5
+ ## Highlights
6
+
7
+ - **60fps Linear-Native TUI**: 3-pane layout (`My Issues` / `Triage` / `Active Cycle` / `Teams` / `Projects`), instant `1` List ↔ `2` Kanban Board toggle, Day-1 native drag-and-drop (Kanban cards across workflow columns + issues onto Cycles/Projects/Triage/My Issues with 0ms optimistic updates & rollback), `Ctrl+K` Command Palette, `SafeCursorBackend` (DSR-timeout immune), and **0.0% idle CPU**.
8
+ - **10-Second Sign-In (In-TUI, CLI & CI)**: Paste your Linear Personal API key (`lin_api_...`) directly inside the TUI sign-in screen, authenticate via `linear login` / OAuth 2.0 PKCE, or supply an environment/external token broker.
9
+ - **Offline SQLite WAL + FTS5 Search**: Trigram FTS5 full-text index with automatic CJK/Korean & short-token `LIKE` fallback plus case-insensitive issue identifier lookup (`eng-12` → `ENG-12`).
10
+ - **2-Lane Incremental Delta Sync**: Tracks `updatedAt` Relay cursors and Linear's `X-RateLimit-*` / complexity budget headers with exponential 429 backoff and a single-instance IPC daemon.
11
+ - **20 Safe MCP Tools**: Powered by `bitefoundry-mcp` (8 MiB bounded stdio framing, lazy initialization, `--read-only` mode hiding/blocking all 8 write tools, and literal `confirm: true` guard on `archive_issue`).
12
+ - **Hardened Local HTTP API (`127.0.0.1:8794`)**: Powered by `bitefoundry-serve` (DNS-rebinding `Host` guard, `Sec-Fetch-Site: cross-site` CSRF rejection, strict CORS allowlist, and constant-time 64-hex Bearer token auth).
13
+ - **Script-Ready CLI Contract**: `--json` / `-j` always emits structured `JsonErrorEnvelope` payloads on `stdout` with exit code `1` (canonical `"not_authenticated"` code, zero interactive prompts in non-TTY mode).
14
+
15
+ ## Quick Start
16
+
17
+ ```sh
18
+ # Sign in with a Linear Personal API key (10 seconds)
19
+ linear login --api-key lin_api_...
20
+ # Or pipe non-interactively in scripts/CI
21
+ printf '%s\n' "$LINEAR_API_KEY" | linear login --api-key-stdin
22
+
23
+ # Launch the interactive 60fps TUI (also supports direct in-TUI API key sign-in)
24
+ linear
25
+
26
+ # Sync workspace metadata + incremental issues and query via CLI/JSON
27
+ linear sync
28
+ linear issues list --json
29
+ linear issues get ENG-12 --print
30
+ linear search "cursor pagination" --json
31
+ ```
32
+
33
+ ## Authentication
34
+
35
+ 1. **In-TUI Sign-In**:
36
+ - Running `linear` in an interactive terminal without saved credentials opens a clean **Sign in to Linear** screen with masked API key input (`Ctrl+O` opens `https://linear.app/settings/api`).
37
+ 2. **OS Keyring (`bitefoundry-linear`)**:
38
+ - `linear login` (Personal API key) or `linear login --oauth --client-id <CLIENT_ID>` (OAuth 2.0 PKCE loopback flow with `LINEAR_OAUTH_CLIENT_ID`).
39
+ - Set `LINEAR_DISABLE_KEYRING=1` to use the atomic `0600` fallback file.
40
+ 3. **External Token Broker / Environment** (CI, containers, AI agents):
41
+ - `LINEAR_API_KEY` (Personal API Key `lin_api_...` — sent as raw `Authorization: lin_api_...`, **never** `Bearer `, per Linear API requirements)
42
+ - `LINEAR_ACCESS_TOKEN`, `LINEAR_TOKEN_FILE`, `LINEAR_TOKEN_REFRESH_CMD` (OAuth 2.0 tokens sent as `Authorization: Bearer <token>`)
43
+
44
+ ## CLI Reference
45
+
46
+ ### Global Flags
47
+
48
+ | Flag | Description |
49
+ | :--- | :--- |
50
+ | `-j`, `--json` | Machine-readable JSON output (errors emit `JsonErrorEnvelope` on `stdout` + exit code `1`). |
51
+ | `-p`, `--print` | Clean print-friendly Markdown output without interactive chrome. |
52
+ | `--no-color` | Disable ANSI colors in terminal output. |
53
+ | `--no-nerd-fonts` | Force 7-bit ASCII icon fallback instead of Unicode/Nerd Font glyphs in the TUI. |
54
+ | `--theme <THEME>` | Override TUI color theme preset (`linear-dark`, `linear-light`, or any built-in theme). |
55
+ | `--config-dir <PATH>` | Override configuration directory (isolates config, credentials fallback, and SQLite cache). |
56
+
57
+ ### Commands
58
+
59
+ | Command | Description |
60
+ | :--- | :--- |
61
+ | `linear` | Launch the interactive 60fps Linear TUI (`1` List / `2` Kanban Board, `Ctrl+K` Command Palette, drag-and-drop). |
62
+ | `linear issues` | Manage issues: `list`, `get`, `create`, `update`, `move`, `comment`, `archive --confirm`. |
63
+ | `linear search` | Offline SQLite FTS5 + CJK/short-token search (`--team`, `--limit`). |
64
+ | `linear teams` | List workspace teams. |
65
+ | `linear states` | List workflow states (`--team <KEY>`). |
66
+ | `linear cycles` | List sprint cycles (`--team <KEY>`). |
67
+ | `linear projects` | List workspace projects. |
68
+ | `linear labels` | List workspace or team issue labels (`--team <KEY>`). |
69
+ | `linear sync` | Run metadata bootstrap + incremental `updatedAt` delta sync. |
70
+ | `linear login` | Sign in with `--api-key`, `--api-key-stdin`, or `--oauth`. |
71
+ | `linear logout` | Clear stored credentials from the keyring / fallback store. |
72
+ | `linear whoami` | Show authenticated Linear viewer, organization, and rate-limit status. |
73
+ | `linear doctor` | Inspect config paths, TLS extra CAs, credentials, and daemon status. |
74
+ | `linear serve` | Start the hardened local HTTP API server (default `127.0.0.1:8794`). |
75
+ | `linear mcp` | Start the stdio JSON-RPC 2.0 MCP server (`--read-only`, `--max-output-chars`). |
76
+ | `linear daemon` | Control background sync daemon (`start`, `stop`, `status`). |
77
+ | `linear update` | Check for (`--check`) or install SHA-256 verified GitHub Releases updates. |
78
+
79
+ #### Issue Subcommand Examples
80
+
81
+ ```sh
82
+ linear issues list --team ENG --state "In Progress" --priority 1 --limit 20
83
+ linear issues list --mine
84
+ linear issues list --triage
85
+ linear issues get ENG-12 -p
86
+ linear issues create --team ENG --title "Fix cursor pagination" --priority 2 --labels bug,perf
87
+ linear issues update ENG-12 --state "In Review" --assignee "Alex Kim" --estimate 3
88
+ linear issues move ENG-12 --state Done --cycle 14 --project "Offline SQLite Sync"
89
+ linear issues comment ENG-12 "Verified against staging."
90
+ linear issues archive ENG-12 --confirm
91
+ ```
92
+
93
+ ### MCP Server
94
+
95
+ Exposes 20 Linear tools over bounded stdio JSON-RPC 2.0 (`linear mcp`):
96
+ `whoami`, `list_teams`, `list_workflow_states`, `list_cycles`, `list_projects`, `list_labels`, `list_issues`, `list_my_issues`, `list_triage`, `get_issue`, `search_issues`, `get_rate_limit_status`, `create_issue`, `update_issue`, `transition_issue`, `assign_issue`, `move_issue_to_cycle`, `move_issue_to_project`, `add_comment`, `archive_issue`.
97
+
98
+ See [docs/MCP.md](docs/MCP.md) for full tool schemas, `--read-only` policy, `confirm: true` confirmation gate, and Claude Desktop / Cursor configuration.
99
+
100
+ ### Local HTTP API (`127.0.0.1:8794`)
101
+
102
+ ```sh
103
+ # Loopback bind generates a per-session 64-hex Bearer token automatically
104
+ linear serve
105
+
106
+ # Bind with an explicit Bearer token
107
+ linear serve --port 8794 --token "$LINEAR_SERVE_TOKEN"
108
+ ```
109
+
110
+ See [docs/MCP.md](docs/MCP.md) for endpoint details and [docs/design.md](docs/design.md) for architecture and security invariants.
111
+
112
+ ## License
113
+
114
+ MIT — Copyright (c) 2026 BiteFoundry.
package/bin/linear.js ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawnSync } = require('node:child_process');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+
8
+ const PLATFORM_PACKAGES = {
9
+ 'win32-x64': '@bitefoundry/linear-win32-x64',
10
+ 'win32-arm64': '@bitefoundry/linear-win32-arm64',
11
+ 'darwin-x64': '@bitefoundry/linear-darwin-x64',
12
+ 'darwin-arm64': '@bitefoundry/linear-darwin-arm64',
13
+ 'linux-x64': '@bitefoundry/linear-linux-x64',
14
+ 'linux-arm64': '@bitefoundry/linear-linux-arm64',
15
+ };
16
+
17
+ function resolveBinary() {
18
+ if (process.env.LINEAR_BIN_PATH && fs.existsSync(process.env.LINEAR_BIN_PATH)) {
19
+ return process.env.LINEAR_BIN_PATH;
20
+ }
21
+
22
+ const binaryName = process.platform === 'win32' ? 'linear.exe' : 'linear';
23
+ const localLinked = path.join(__dirname, binaryName);
24
+ if (fs.existsSync(localLinked)) {
25
+ return localLinked;
26
+ }
27
+
28
+ const key = `${process.platform}-${process.arch}`;
29
+ const pkgName = PLATFORM_PACKAGES[key];
30
+ if (!pkgName) {
31
+ console.error(
32
+ `[@bitefoundry/linear] Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_PACKAGES).join(', ')}`,
33
+ );
34
+ process.exit(1);
35
+ }
36
+
37
+ try {
38
+ const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
39
+ const candidate = path.join(path.dirname(pkgJsonPath), 'bin', binaryName);
40
+ if (fs.existsSync(candidate)) {
41
+ return candidate;
42
+ }
43
+ } catch {
44
+ // Fall through to helpful diagnostic error below.
45
+ }
46
+
47
+ console.error(
48
+ `[@bitefoundry/linear] Could not locate prebuilt binary from optional dependency "${pkgName}".\n` +
49
+ `Try reinstalling without --omit=optional, or build from source with \`cargo build --release\`.`,
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ const binPath = resolveBinary();
55
+ const result = spawnSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
56
+
57
+ if (result.error) {
58
+ console.error(`[@bitefoundry/linear] Failed to launch ${binPath}: ${result.error.message}`);
59
+ process.exit(1);
60
+ }
61
+
62
+ if (result.signal) {
63
+ process.kill(process.pid, result.signal);
64
+ }
65
+
66
+ process.exit(result.status ?? 0);
package/package.json CHANGED
@@ -1,10 +1,46 @@
1
- {
2
- "name": "@bitefoundry/linear",
3
- "version": "0.0.1",
4
- "description": "Linear terminal client & AI agent toolkit (CLI, TUI, HTTP API, MCP)",
5
- "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/BiteFoundry/linear.git"
9
- }
1
+ {
2
+ "name": "@bitefoundry/linear",
3
+ "version": "0.1.1",
4
+ "description": "Linear terminal client & AI agent toolkit — Issues, Cycles, Projects, Triage, Offline SQLite FTS5 & Kanban TUI (CLI, TUI, HTTP API, MCP)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/BiteFoundry/linear.git"
8
+ },
9
+ "license": "MIT",
10
+ "bin": {
11
+ "linear": "bin/linear.js"
12
+ },
13
+ "files": [
14
+ "bin/linear.js",
15
+ "scripts/postinstall.mjs",
16
+ "README.md"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "keywords": [
22
+ "linear",
23
+ "linear-cli",
24
+ "linear-tui",
25
+ "issue-tracker",
26
+ "kanban",
27
+ "cycles",
28
+ "projects",
29
+ "cli",
30
+ "tui",
31
+ "mcp"
32
+ ],
33
+ "scripts": {
34
+ "postinstall": "node scripts/postinstall.mjs",
35
+ "sync-version": "node scripts/sync-version.mjs",
36
+ "build:npm": "node scripts/build-npm.mjs"
37
+ },
38
+ "optionalDependencies": {
39
+ "@bitefoundry/linear-win32-x64": "0.1.1",
40
+ "@bitefoundry/linear-win32-arm64": "0.1.1",
41
+ "@bitefoundry/linear-darwin-x64": "0.1.1",
42
+ "@bitefoundry/linear-darwin-arm64": "0.1.1",
43
+ "@bitefoundry/linear-linux-x64": "0.1.1",
44
+ "@bitefoundry/linear-linux-arm64": "0.1.1"
45
+ }
10
46
  }
@@ -0,0 +1,271 @@
1
+ #!/usr/bin/env node
2
+ // Zero-Node-Process npm native binary linker.
3
+ //
4
+ // On Unix (linux/darwin): replaces installed `bin/linear.js` with
5
+ // hardlinks/symlinks directly to `@bitefoundry/linear-<platform>-<arch>/bin/linear` so npm's
6
+ // bin symlink execve's the native Rust binary directly (0ms Node startup, 0MB Node RSS).
7
+ //
8
+ // On Windows (win32): creates NTFS hardlinks (fallback copy) `bin/linear.exe`
9
+ // and rewrites npm's `.bin/linear[.cmd|.ps1]` shims when present to invoke
10
+ // the native executable directly without spawning `node.exe`.
11
+
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { createRequire } from 'node:module';
15
+ import { fileURLToPath } from 'node:url';
16
+
17
+ const BIN_NAMES = ['linear'];
18
+ const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
19
+
20
+ function linkOrCopyFile(source, destination) {
21
+ const tmp = `${destination}.tmp-${process.pid}`;
22
+ try {
23
+ fs.rmSync(tmp, { force: true });
24
+ } catch {
25
+ // Ignore cleanup errors on nonexistent temp paths.
26
+ }
27
+ try {
28
+ fs.linkSync(source, tmp);
29
+ } catch {
30
+ fs.copyFileSync(source, tmp);
31
+ }
32
+ try {
33
+ fs.renameSync(tmp, destination);
34
+ } catch {
35
+ try {
36
+ fs.rmSync(destination, { force: true });
37
+ } catch {
38
+ // Ignore; renameSync below will surface or fail safely.
39
+ }
40
+ fs.renameSync(tmp, destination);
41
+ }
42
+ }
43
+
44
+ function replaceJsWithNativeLinkUnix(binaryPath, destinationJs) {
45
+ const tmp = `${destinationJs}.tmp-${process.pid}`;
46
+ try {
47
+ fs.rmSync(tmp, { force: true });
48
+ } catch {
49
+ // Ignore cleanup errors.
50
+ }
51
+ try {
52
+ fs.linkSync(binaryPath, tmp);
53
+ } catch {
54
+ try {
55
+ fs.rmSync(tmp, { force: true });
56
+ } catch {
57
+ // Ignore cleanup errors.
58
+ }
59
+ fs.symlinkSync(binaryPath, tmp);
60
+ }
61
+ try {
62
+ fs.renameSync(tmp, destinationJs);
63
+ } catch (err) {
64
+ try {
65
+ fs.rmSync(tmp, { force: true });
66
+ } catch {
67
+ // Ignore cleanup errors.
68
+ }
69
+ throw err;
70
+ }
71
+ }
72
+
73
+ function collectWindowsShimDirs(pkgRoot, env = process.env) {
74
+ const dirs = [];
75
+ const parentScope = path.dirname(pkgRoot);
76
+ const nodeModulesDir = path.dirname(parentScope);
77
+ if (
78
+ path.basename(parentScope) === '@bitefoundry' &&
79
+ path.basename(nodeModulesDir) === 'node_modules'
80
+ ) {
81
+ dirs.push(path.join(nodeModulesDir, '.bin'));
82
+ dirs.push(path.dirname(nodeModulesDir));
83
+ }
84
+
85
+ if (env.npm_config_global === 'true' && env.npm_config_prefix) {
86
+ const prefix = path.resolve(env.npm_config_prefix);
87
+ dirs.push(prefix);
88
+ dirs.push(path.join(prefix, 'bin'));
89
+ }
90
+
91
+ return [...new Set(dirs)];
92
+ }
93
+
94
+ function shimReferencesLauncher(content, name) {
95
+ const normalized = content.replace(/\\/g, '/').toLowerCase();
96
+ return (
97
+ normalized.includes('@bitefoundry/linear') &&
98
+ normalized.includes(`bin/${name}.js`)
99
+ );
100
+ }
101
+
102
+ function rewriteWindowsShims(shimDir, pkgRoot) {
103
+ if (!fs.existsSync(shimDir)) return 0;
104
+ let rewritten = 0;
105
+
106
+ for (const name of BIN_NAMES) {
107
+ const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
108
+ if (!fs.existsSync(exePath)) continue;
109
+
110
+ const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
111
+ const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
112
+
113
+ const cmdPath = path.join(shimDir, `${name}.cmd`);
114
+ try {
115
+ if (fs.existsSync(cmdPath)) {
116
+ const content = fs.readFileSync(cmdPath, 'utf8');
117
+ if (shimReferencesLauncher(content, name)) {
118
+ fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
119
+ rewritten += 1;
120
+ }
121
+ }
122
+ } catch {
123
+ // Fall back cleanly to bin/<name>.js if shim is read-only or locked.
124
+ }
125
+
126
+ const ps1Path = path.join(shimDir, `${name}.ps1`);
127
+ try {
128
+ if (fs.existsSync(ps1Path)) {
129
+ const content = fs.readFileSync(ps1Path, 'utf8');
130
+ if (shimReferencesLauncher(content, name)) {
131
+ const ps1Body = [
132
+ '#!/usr/bin/env pwsh',
133
+ '$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
134
+ `$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
135
+ 'if ($MyInvocation.ExpectingInput) {',
136
+ ' $input | & $exePath @args',
137
+ '} else {',
138
+ ' & $exePath @args',
139
+ '}',
140
+ 'exit $LASTEXITCODE',
141
+ '',
142
+ ].join('\n');
143
+ fs.writeFileSync(ps1Path, ps1Body, 'utf8');
144
+ rewritten += 1;
145
+ }
146
+ }
147
+ } catch {
148
+ // Fall back cleanly.
149
+ }
150
+
151
+ const shPath = path.join(shimDir, name);
152
+ try {
153
+ if (fs.existsSync(shPath)) {
154
+ const content = fs.readFileSync(shPath, 'utf8');
155
+ if (shimReferencesLauncher(content, name)) {
156
+ const shBody = [
157
+ '#!/bin/sh',
158
+ 'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
159
+ `exec "$basedir/${relPosix}" "$@"`,
160
+ '',
161
+ ].join('\n');
162
+ fs.writeFileSync(shPath, shBody, 'utf8');
163
+ rewritten += 1;
164
+ }
165
+ }
166
+ } catch {
167
+ // Fall back cleanly.
168
+ }
169
+ }
170
+
171
+ return rewritten;
172
+ }
173
+
174
+ export function runPostinstall(options = {}) {
175
+ const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
176
+ const platform = options.platform || process.platform;
177
+ const arch = options.arch || process.arch;
178
+ const env = options.env || process.env;
179
+
180
+ if (
181
+ fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
182
+ fs.existsSync(path.join(pkgRoot, '.git'))
183
+ ) {
184
+ return { skipped: true, reason: 'dev_repo' };
185
+ }
186
+
187
+ const platformKey = `${platform}-${arch}`;
188
+ const packageName = `@bitefoundry/linear-${platformKey}`;
189
+ const binaryName = platform === 'win32' ? 'linear.exe' : 'linear';
190
+
191
+ let packageDir = null;
192
+ try {
193
+ const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
194
+ packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
195
+ } catch {
196
+ packageDir = null;
197
+ }
198
+
199
+ const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
200
+ if (!binaryPath || !fs.existsSync(binaryPath)) {
201
+ return { skipped: true, reason: 'missing_platform_binary' };
202
+ }
203
+
204
+ const binDir = path.join(pkgRoot, 'bin');
205
+ if (!fs.existsSync(binDir)) {
206
+ return { skipped: true, reason: 'missing_bin_dir' };
207
+ }
208
+
209
+ if (platform === 'win32') {
210
+ let linked = 0;
211
+ for (const name of BIN_NAMES) {
212
+ const destExe = path.join(binDir, `${name}.exe`);
213
+ try {
214
+ linkOrCopyFile(binaryPath, destExe);
215
+ linked += 1;
216
+ } catch {
217
+ // Leave fallback JS launcher untouched.
218
+ }
219
+ }
220
+
221
+ let shimsRewritten = 0;
222
+ for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
223
+ try {
224
+ shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
225
+ } catch {
226
+ // Never fail npm install on read-only or custom shims.
227
+ }
228
+ }
229
+ return { skipped: false, platform, linked, shimsRewritten };
230
+ }
231
+
232
+ try {
233
+ fs.chmodSync(binaryPath, 0o755);
234
+ } catch {
235
+ // Ignore on read-only stores.
236
+ }
237
+
238
+ let linked = 0;
239
+ for (const name of BIN_NAMES) {
240
+ const destJs = path.join(binDir, `${name}.js`);
241
+ try {
242
+ replaceJsWithNativeLinkUnix(binaryPath, destJs);
243
+ linked += 1;
244
+ } catch {
245
+ // Leave fallback JS launcher intact.
246
+ }
247
+ }
248
+
249
+ return { skipped: false, platform, linked };
250
+ }
251
+
252
+ function resolveCanonicalPath(p) {
253
+ try {
254
+ return fs.realpathSync(p);
255
+ } catch {
256
+ return path.resolve(p);
257
+ }
258
+ }
259
+
260
+ if (
261
+ process.argv[1] &&
262
+ resolveCanonicalPath(process.argv[1]) ===
263
+ resolveCanonicalPath(fileURLToPath(import.meta.url))
264
+ ) {
265
+ try {
266
+ runPostinstall();
267
+ } catch {
268
+ // Postinstall optimization must never fail npm install.
269
+ }
270
+ process.exit(0);
271
+ }