@bitefoundry/notion 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # `@bitefoundry/notion`
4
+
5
+ **Notion-native terminal workspace & AI agent toolkit — Editorial Pages, Interactive Blocks, Databases (Table/Board/List), CLI · TUI · HTTP API · MCP.**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/%40bitefoundry%2Fnotion?style=flat-square&color=191919)](https://www.npmjs.com/package/@bitefoundry/notion)
8
+ [![platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-24292F?style=flat-square)](docs/NPM.md)
9
+ [![Rust & Ratatui](https://img.shields.io/badge/built%20with-Rust%20%2B%20Ratatui-DEA584?style=flat-square&logo=rust)](Cargo.toml)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-00875A?style=flat-square)](package.json)
11
+
12
+ <br />
13
+
14
+ ![Notion TUI Demo](assets/demo.gif)
15
+
16
+ </div>
17
+
18
+ ---
19
+
20
+ ## Highlights
21
+
22
+ | Pillar | Capabilities |
23
+ | :--- | :--- |
24
+ | **Minimal-Chrome TUI** | Authentic Notion editorial aesthetic (`notion` / `nt`): 1-line **Breadcrumb Bar**, collapsible **Workspace Sidebar (`[`)** with Favorites & nested tree, **Centered (~88 col) / Full Width (`w`) Page Canvas**, 10 canonical Notion pill colors, live interactive **`to_do` checkboxes (`Space`/`x`)** & **`toggle` blocks**, **Database Table (`1`) / Board Kanban (`2`) / List (`3`) views**, **Comments Peek Drawer (`C`)**, **Quick Find (`Ctrl+K`)**, **Multi-Workspace Switcher (`Ctrl+S`)**, and **5 curated palettes** (`Clean Dark`, `Warm Paper`, `Tokyo Night`, `Catppuccin`, `Nord`). |
25
+ | **High-Res Terminal Images** | Native inline image previews for Notion-hosted & external media via **Kitty Graphics**, **iTerm2**, **Sixel**, and **24-bit Truecolor Half-Block (`▀`)** fallback (`v` HD modal & `notion download`). |
26
+ | **Local SQLite FTS5 + IPC Daemon** | Workspace-scoped SQLite WAL + FTS5 cache (`pages`, `databases`, `blocks`, `comments`, `pages_fts`) with automatic `<3`-char Korean/CJK `LIKE` fallback, plus single-instance background sync IPC daemon (`notion daemon start`). |
27
+ | **4-in-1 Agent Interface** | Same binary powers the **Interactive TUI**, scriptable **`--json` CLI**, local **HTTP JSON API** (`notion serve`, `:8791`), and **stdio MCP server** (`notion mcp`, **18 typed tools** with `confirm: true` archive guard). |
28
+
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ```bash
34
+ # 1. Install globally (links `notion` and `nt` native binaries)
35
+ npm i -g @bitefoundry/notion
36
+
37
+ # 2. Authenticate — Internal Integration Token (30-second setup) or Public OAuth 2.0
38
+ notion login --token ntn_...
39
+ # Or Public OAuth 2.0 loopback:
40
+ notion login --oauth --client-id "$NOTION_CLIENT_ID" --client-secret "$NOTION_CLIENT_SECRET"
41
+
42
+ # 3. Sync your workspace & launch the Notion-native TUI
43
+ notion sync
44
+ notion # alias: nt
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Keybindings Cheat Sheet
50
+
51
+ | Key | Action | Context |
52
+ | :--- | :--- | :--- |
53
+ | `[` / `Ctrl+B` | Toggle collapsible Workspace Sidebar | Global |
54
+ | `Tab` / `Shift+Tab` | Cycle focus across Sidebar, Canvas, and Comments Drawer | Global |
55
+ | `j` `k` / `↑` `↓` | Move across sidebar tree, page blocks, or database rows | Global |
56
+ | `Space` / `x` | Check/uncheck live `to_do` block or expand/collapse `toggle` block | Page Canvas |
57
+ | `w` / `f` / `y` | Toggle Centered vs Full Width / Favorite star / Copy code block | Page Canvas |
58
+ | `a` / `n` / `e` | Slash Quick Append (`/h1`, `/todo`, `/callout`) / New Page / `$EDITOR` | Page / Database |
59
+ | `C` | Toggle right-split Comments Peek Drawer & reply inline | Page Canvas |
60
+ | `1` / `2` / `3` | Switch Database views: **Table** / **Board (Kanban)** / **List** | Database |
61
+ | `f` / `s` / `m` | Filter rows / Cycle sort / Move Kanban card to another Status column | Database |
62
+ | `Ctrl+K` / `Ctrl+P` | Quick Find & Command Palette (FTS5 search + workspace commands) | Global |
63
+ | `u` / `Ctrl+F` / `v` | Link Extractor / File Picker (`z` zoxide) / HD Image Preview | Global |
64
+ | `Ctrl+S` / `Ctrl+,` / `?` | Switch Workspace / Settings & Palettes / Keyboard Shortcuts Help | Global |
65
+
66
+ ---
67
+
68
+ ## CLI, HTTP API & MCP
69
+
70
+ ### CLI (`--json` ready)
71
+
72
+ ```bash
73
+ # Search, read, append & export Notion pages
74
+ notion search "Q4 Roadmap" --json
75
+ notion pages list --json
76
+ notion pages get "Q4 Launch Plan"
77
+ notion pages append "Q4 Launch Plan" "/todo Tag v1.0 release"
78
+ notion pages export "Q4 Launch Plan" --out launch-plan.md
79
+ notion blocks toggle <block-id>
80
+
81
+ # Query & create Notion database items
82
+ notion db list --json
83
+ notion db query "Q4 Roadmap" --json
84
+ notion db create-item "Q4 Roadmap" --title "Ship v1.0" --status "In Progress"
85
+ notion comments add "Q4 Launch Plan" "Green light for launch!"
86
+ notion download <url-or-block-id> --json
87
+
88
+ # Multi-workspace profiles & background sync daemon
89
+ notion workspaces list
90
+ notion workspaces add work --token ntn_...
91
+ notion workspaces use work
92
+ notion daemon start
93
+ ```
94
+
95
+ ### Local HTTP JSON API (`notion serve`)
96
+
97
+ ```bash
98
+ notion serve --bind 127.0.0.1 --port 8791 --token "$API_TOKEN"
99
+ curl -H "Authorization: Bearer $API_TOKEN" "http://127.0.0.1:8791/search?q=Roadmap"
100
+ ```
101
+
102
+ Full endpoint catalog and OpenAPI schema: **[docs/API.md](docs/API.md)** · **[docs/openapi.yaml](docs/openapi.yaml)**.
103
+
104
+ ### MCP Server (`notion mcp` — 18 Tools)
105
+
106
+ ```json
107
+ {
108
+ "mcpServers": {
109
+ "notion": {
110
+ "command": "notion",
111
+ "args": ["mcp"]
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ Full tool catalog and argument schemas: **[docs/MCP.md](docs/MCP.md)** · npm packaging details: **[docs/NPM.md](docs/NPM.md)**.
118
+
119
+ ---
120
+
121
+ ## `@bitefoundry` Enterprise Terminal Suite
122
+
123
+ | Package | Commands | Workspace | Interfaces |
124
+ | :--- | :--- | :--- | :--- |
125
+ | [`@bitefoundry/teams`](https://www.npmjs.com/package/@bitefoundry/teams) | `teams` | Microsoft Teams (Chats, Channels, Meetings & Threads) | TUI · CLI · HTTP · MCP |
126
+ | [`@bitefoundry/outlook`](https://www.npmjs.com/package/@bitefoundry/outlook) | `outlook`, `ol` | Microsoft Outlook (Mail, Calendar & Contacts) | TUI · CLI · HTTP · MCP |
127
+ | [`@bitefoundry/onenote`](https://www.npmjs.com/package/@bitefoundry/onenote) | `onenote`, `on` | Microsoft OneNote (Notebooks, Sections & Pages) | TUI · CLI · HTTP · MCP |
128
+ | [`@bitefoundry/sharepoint`](https://www.npmjs.com/package/@bitefoundry/sharepoint) | `sharepoint`, `sp` | Microsoft SharePoint & OneDrive (Sites, Libraries & Lists) | TUI · CLI · HTTP · MCP |
129
+ | [`@bitefoundry/atlassian`](https://www.npmjs.com/package/@bitefoundry/atlassian) | `atlassian`, `jira`, `confluence`, `conf` | Atlassian Jira (Kanban, Sprints, JQL) & Confluence Wiki | TUI · CLI · HTTP · MCP |
130
+ | **`@bitefoundry/notion`** | `notion`, `nt` | Notion (Editorial Pages, Interactive Blocks & Databases) | TUI · CLI · HTTP · MCP |
131
+
132
+ ---
133
+
134
+ > **Disclaimer:** Unofficial terminal client for Notion. Not affiliated with, endorsed by, or sponsored by Notion Labs, Inc.
package/bin/notion.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/notion-win32-x64',
10
+ 'win32-arm64': '@bitefoundry/notion-win32-arm64',
11
+ 'darwin-x64': '@bitefoundry/notion-darwin-x64',
12
+ 'darwin-arm64': '@bitefoundry/notion-darwin-arm64',
13
+ 'linux-x64': '@bitefoundry/notion-linux-x64',
14
+ 'linux-arm64': '@bitefoundry/notion-linux-arm64',
15
+ };
16
+
17
+ function resolveBinary() {
18
+ if (process.env.NOTION_BIN_PATH && fs.existsSync(process.env.NOTION_BIN_PATH)) {
19
+ return process.env.NOTION_BIN_PATH;
20
+ }
21
+
22
+ const binaryName = process.platform === 'win32' ? 'notion.exe' : 'notion';
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/notion] 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/notion] 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/notion] 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/bin/nt.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ require('./notion.js');
package/docs/NPM.md ADDED
@@ -0,0 +1,21 @@
1
+ # `@bitefoundry/notion` 6-Platform npm Distribution
2
+
3
+ `@bitefoundry/notion` distributes prebuilt native Rust binaries via npm `optionalDependencies`, installing both `notion` and `nt` commands with zero Node.js runtime overhead after `postinstall` hardlinking.
4
+
5
+ ## Platform Packages
6
+
7
+ | Platform Package | Rust Target | Binary |
8
+ |---|---|---|
9
+ | `@bitefoundry/notion-win32-x64` | `x86_64-pc-windows-msvc` | `bin/notion.exe` |
10
+ | `@bitefoundry/notion-win32-arm64` | `aarch64-pc-windows-msvc` | `bin/notion.exe` |
11
+ | `@bitefoundry/notion-darwin-x64` | `x86_64-apple-darwin` | `bin/notion` |
12
+ | `@bitefoundry/notion-darwin-arm64` | `aarch64-apple-darwin` | `bin/notion` |
13
+ | `@bitefoundry/notion-linux-x64` | `x86_64-unknown-linux-gnu.2.28` | `bin/notion` |
14
+ | `@bitefoundry/notion-linux-arm64` | `aarch64-unknown-linux-gnu.2.28` | `bin/notion` |
15
+
16
+ ## Packaging Scripts
17
+
18
+ - `node scripts/sync-version.mjs --check`: verifies `Cargo.toml`, root `package.json`, and all 6 `npm/notion-*/package.json` manifests match version `0.1.0`.
19
+ - `node scripts/verify-glibc.mjs --self-test`: verifies the GLIBC <= 2.28 ELF symbol checker used in GitHub Actions Linux releases.
20
+ - `node scripts/build-npm.mjs [--target <triple>] [--all]`: stages Cargo release binaries into `npm/notion-*/bin/`.
21
+ - `scripts/postinstall.mjs`: links `notion` and `nt` directly to the native binary on Unix/Windows while guarding against mutating a git development checkout.
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@bitefoundry/notion",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Notion terminal client & AI agent toolkit — Pages, Blocks, Databases (Table/Board/List), Comments & Multi-Workspace (CLI, TUI, HTTP API, MCP)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/BiteFoundry/notion.git"
8
+ },
9
+ "license": "MIT",
10
+ "bin": {
11
+ "notion": "bin/notion.js",
12
+ "nt": "bin/nt.js"
13
+ },
14
+ "files": [
15
+ "bin/notion.js",
16
+ "bin/nt.js",
17
+ "scripts/postinstall.mjs",
18
+ "docs/NPM.md",
19
+ "README.md"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "keywords": [
25
+ "notion",
26
+ "notion-cli",
27
+ "notion-tui",
28
+ "nt",
29
+ "knowledge-base",
30
+ "kanban",
31
+ "database",
32
+ "markdown",
33
+ "cli",
34
+ "tui",
35
+ "mcp"
36
+ ],
37
+ "scripts": {
38
+ "postinstall": "node scripts/postinstall.mjs",
39
+ "sync-version": "node scripts/sync-version.mjs",
40
+ "build:npm": "node scripts/build-npm.mjs"
41
+ },
42
+ "optionalDependencies": {
43
+ "@bitefoundry/notion-win32-x64": "0.1.1",
44
+ "@bitefoundry/notion-win32-arm64": "0.1.1",
45
+ "@bitefoundry/notion-darwin-x64": "0.1.1",
46
+ "@bitefoundry/notion-darwin-arm64": "0.1.1",
47
+ "@bitefoundry/notion-linux-x64": "0.1.1",
48
+ "@bitefoundry/notion-linux-arm64": "0.1.1"
49
+ }
50
+ }
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/env node
2
+ // Zero-Node-Process npm native binary linker.
3
+ //
4
+ // On Unix (linux/darwin): replaces installed `bin/notion.js` and `bin/nt.js` with
5
+ // hardlinks/symlinks directly to `@bitefoundry/notion-<platform>-<arch>/bin/notion` 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/notion.exe` & `bin/nt.exe`
9
+ // and rewrites npm's `.bin/{notion,nt}[.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 = ['notion', 'nt'];
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
+ // On global Windows npm installs (`%APPDATA%\npm\node_modules\@bitefoundry\notion`),
83
+ // shims sit directly in the parent of `node_modules` even when `npm_config_prefix` is unset in npm v9+.
84
+ dirs.push(path.dirname(nodeModulesDir));
85
+ }
86
+
87
+ if (env.npm_config_global === 'true' && env.npm_config_prefix) {
88
+ const prefix = path.resolve(env.npm_config_prefix);
89
+ dirs.push(prefix);
90
+ dirs.push(path.join(prefix, 'bin'));
91
+ }
92
+
93
+ return [...new Set(dirs)];
94
+ }
95
+
96
+ function shimReferencesLauncher(content, name) {
97
+ const normalized = content.replace(/\\/g, '/').toLowerCase();
98
+ return (
99
+ normalized.includes('@bitefoundry/notion') &&
100
+ normalized.includes(`bin/${name}.js`)
101
+ );
102
+ }
103
+
104
+ function rewriteWindowsShims(shimDir, pkgRoot) {
105
+ if (!fs.existsSync(shimDir)) return 0;
106
+ let rewritten = 0;
107
+
108
+ for (const name of BIN_NAMES) {
109
+ const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
110
+ if (!fs.existsSync(exePath)) continue;
111
+
112
+ const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
113
+ const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
114
+
115
+ // 1. `<name>.cmd`
116
+ const cmdPath = path.join(shimDir, `${name}.cmd`);
117
+ try {
118
+ if (fs.existsSync(cmdPath)) {
119
+ const content = fs.readFileSync(cmdPath, 'utf8');
120
+ if (shimReferencesLauncher(content, name)) {
121
+ fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
122
+ rewritten += 1;
123
+ }
124
+ }
125
+ } catch {
126
+ // Fall back cleanly to bin/<name>.js if shim is read-only or locked.
127
+ }
128
+
129
+ // 2. `<name>.ps1`
130
+ const ps1Path = path.join(shimDir, `${name}.ps1`);
131
+ try {
132
+ if (fs.existsSync(ps1Path)) {
133
+ const content = fs.readFileSync(ps1Path, 'utf8');
134
+ if (shimReferencesLauncher(content, name)) {
135
+ const ps1Body = [
136
+ '#!/usr/bin/env pwsh',
137
+ '$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
138
+ `$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
139
+ 'if ($MyInvocation.ExpectingInput) {',
140
+ ' $input | & $exePath @args',
141
+ '} else {',
142
+ ' & $exePath @args',
143
+ '}',
144
+ 'exit $LASTEXITCODE',
145
+ '',
146
+ ].join('\n');
147
+ fs.writeFileSync(ps1Path, ps1Body, 'utf8');
148
+ rewritten += 1;
149
+ }
150
+ }
151
+ } catch {
152
+ // Fall back cleanly.
153
+ }
154
+
155
+ // 3. `<name>` (Git Bash / MSYS2 POSIX shell shim)
156
+ const shPath = path.join(shimDir, name);
157
+ try {
158
+ if (fs.existsSync(shPath)) {
159
+ const content = fs.readFileSync(shPath, 'utf8');
160
+ if (shimReferencesLauncher(content, name)) {
161
+ const shBody = [
162
+ '#!/bin/sh',
163
+ 'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
164
+ `exec "$basedir/${relPosix}" "$@"`,
165
+ '',
166
+ ].join('\n');
167
+ fs.writeFileSync(shPath, shBody, 'utf8');
168
+ rewritten += 1;
169
+ }
170
+ }
171
+ } catch {
172
+ // Fall back cleanly.
173
+ }
174
+ }
175
+
176
+ return rewritten;
177
+ }
178
+
179
+ export function runPostinstall(options = {}) {
180
+ const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
181
+ const platform = options.platform || process.platform;
182
+ const arch = options.arch || process.arch;
183
+ const env = options.env || process.env;
184
+
185
+ // CRITICAL SAFETY GUARD: Never mutate files inside the git development repository.
186
+ if (
187
+ fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
188
+ fs.existsSync(path.join(pkgRoot, '.git'))
189
+ ) {
190
+ return { skipped: true, reason: 'dev_repo' };
191
+ }
192
+
193
+ const platformKey = `${platform}-${arch}`;
194
+ const packageName = `@bitefoundry/notion-${platformKey}`;
195
+ const binaryName = platform === 'win32' ? 'notion.exe' : 'notion';
196
+
197
+ let packageDir = null;
198
+ try {
199
+ const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
200
+ packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
201
+ } catch {
202
+ packageDir = null;
203
+ }
204
+
205
+ const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
206
+ if (!binaryPath || !fs.existsSync(binaryPath)) {
207
+ return { skipped: true, reason: 'missing_platform_binary' };
208
+ }
209
+
210
+ const binDir = path.join(pkgRoot, 'bin');
211
+ if (!fs.existsSync(binDir)) {
212
+ return { skipped: true, reason: 'missing_bin_dir' };
213
+ }
214
+
215
+ if (platform === 'win32') {
216
+ let linked = 0;
217
+ for (const name of BIN_NAMES) {
218
+ const destExe = path.join(binDir, `${name}.exe`);
219
+ try {
220
+ linkOrCopyFile(binaryPath, destExe);
221
+ linked += 1;
222
+ } catch {
223
+ // Leave fallback JS launcher untouched.
224
+ }
225
+ }
226
+
227
+ let shimsRewritten = 0;
228
+ for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
229
+ try {
230
+ shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
231
+ } catch {
232
+ // Never fail npm install on read-only or custom shims.
233
+ }
234
+ }
235
+ return { skipped: false, platform, linked, shimsRewritten };
236
+ }
237
+
238
+ // Unix (linux, darwin): chmod once and replace bin/*.js with hardlink/symlink to native binary.
239
+ try {
240
+ fs.chmodSync(binaryPath, 0o755);
241
+ } catch {
242
+ // Ignore on read-only stores.
243
+ }
244
+
245
+ let linked = 0;
246
+ for (const name of BIN_NAMES) {
247
+ const destJs = path.join(binDir, `${name}.js`);
248
+ try {
249
+ replaceJsWithNativeLinkUnix(binaryPath, destJs);
250
+ linked += 1;
251
+ } catch {
252
+ // Leave fallback JS launcher intact.
253
+ }
254
+ }
255
+
256
+ return { skipped: false, platform, linked };
257
+ }
258
+
259
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
260
+ try {
261
+ runPostinstall();
262
+ } catch {
263
+ // Postinstall optimization must never fail npm install.
264
+ }
265
+ process.exit(0);
266
+ }