@adhdev/ghostty-vt-node 0.8.51 → 1.0.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.
Files changed (32) hide show
  1. package/README.md +80 -0
  2. package/index.js +83 -6
  3. package/package.json +3 -2
  4. package/prebuilt/darwin-arm64-node115/ghostty_vt_node.node +0 -0
  5. package/prebuilt/darwin-arm64-node115/libghostty-vt.0.1.0.dylib +0 -0
  6. package/prebuilt/darwin-arm64-node115/libghostty-vt.dylib +0 -0
  7. package/prebuilt/darwin-arm64-node127/ghostty_vt_node.node +0 -0
  8. package/prebuilt/darwin-arm64-node127/libghostty-vt.0.1.0.dylib +0 -0
  9. package/prebuilt/darwin-arm64-node127/libghostty-vt.dylib +0 -0
  10. package/prebuilt/darwin-arm64-node137/libghostty-vt.0.1.0.dylib +0 -0
  11. package/prebuilt/darwin-arm64-node137/libghostty-vt.dylib +0 -0
  12. package/prebuilt/linux-x64-node115/ghostty_vt_node.node +0 -0
  13. package/prebuilt/linux-x64-node115/libghostty-vt.so +0 -0
  14. package/prebuilt/linux-x64-node115/libghostty-vt.so.0.1.0 +0 -0
  15. package/prebuilt/linux-x64-node127/ghostty_vt_node.node +0 -0
  16. package/prebuilt/linux-x64-node127/libghostty-vt.so +0 -0
  17. package/prebuilt/linux-x64-node127/libghostty-vt.so.0.1.0 +0 -0
  18. package/prebuilt/linux-x64-node137/libghostty-vt.so +0 -0
  19. package/prebuilt/{linux-x64-node141/libghostty-vt.so → linux-x64-node137/libghostty-vt.so.0} +0 -0
  20. package/prebuilt/linux-x64-node137/libghostty-vt.so.0.1.0 +0 -0
  21. package/prebuilt/win32-x64-node115/ghostty-vt.dll +0 -0
  22. package/prebuilt/win32-x64-node115/ghostty_vt_node.node +0 -0
  23. package/prebuilt/win32-x64-node127/ghostty-vt.dll +0 -0
  24. package/prebuilt/win32-x64-node127/ghostty_vt_node.node +0 -0
  25. package/prebuilt/win32-x64-node137/ghostty-vt.dll +0 -0
  26. package/prebuilt/win32-x64-node137/ghostty_vt_node.node +0 -0
  27. package/scripts/build-or-use-prebuilt.mjs +23 -0
  28. package/prebuilt/darwin-arm64-node141/ghostty_vt_node.node +0 -0
  29. package/prebuilt/darwin-arm64-node141/libghostty-vt.0.1.0.dylib +0 -0
  30. package/prebuilt/darwin-arm64-node141/libghostty-vt.dylib +0 -0
  31. package/prebuilt/linux-x64-node141/ghostty_vt_node.node +0 -0
  32. package/prebuilt/linux-x64-node141/libghostty-vt.so.0.1.0 +0 -0
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # @adhdev/ghostty-vt-node
2
+
3
+ Native Node binding for `libghostty-vt` — exposes a headless ghostty virtual
4
+ terminal (`createTerminal`) used by daemon-core's `GhosttyVtTerminalBackend`.
5
+
6
+ ## ABI portability (read this first)
7
+
8
+ The addon is a pure **Node-API (N-API)** binding (it exports
9
+ `napi_register_module_v1`). N-API is **ABI-stable across Node major versions**, so
10
+ a single compiled `.node` loads on every Node runtime that supports the N-API
11
+ version it targets — **independent of `process.versions.modules`**
12
+ (`NODE_MODULE_VERSION`, a.k.a. the "ABI" number: 115 ≈ node20, 127 ≈ node22,
13
+ 137 ≈ node24).
14
+
15
+ Practically: you do **not** need a separate native build per Node version. The
16
+ per-`nodeNNN` directory names under `prebuilt/` are an addressing convenience, not
17
+ a hard requirement — the binaries are byte-identical per platform/arch.
18
+
19
+ ### Why prebuilts are committed
20
+
21
+ `prebuilt/` is committed to git (only the `*-node137` triplet per platform) so
22
+ that worktree/CI clones load the binding **without a build toolchain**. A clone
23
+ with no committed prebuilt would fall through to compiling from source
24
+ (cmake-js + zig + a `libghostty` fetch); when that toolchain is absent the loader
25
+ throws `ghostty-vt binding unavailable`, which previously surfaced as an
26
+ environment blocker on node24/ABI137 runners.
27
+
28
+ Shipped triplets:
29
+
30
+ ```
31
+ prebuilt/darwin-arm64-node137/ # macOS Apple Silicon
32
+ prebuilt/linux-x64-node137/ # Linux x64
33
+ prebuilt/win32-x64-node137/ # Windows x64
34
+ ```
35
+
36
+ ## Loader resolution order (`index.js`)
37
+
38
+ 1. `ADHDEV_GHOSTTY_VT_PREBUILT_DIR/<triplet>/ghostty_vt_node.node` (explicit override)
39
+ 2. `ADHDEV_GHOSTTY_VT_PREBUILT_DIR/ghostty_vt_node.node`
40
+ 3. `build/Release` or `build/Debug` (a local compile)
41
+ 4. `prebuilt/<exact-triplet>/ghostty_vt_node.node`
42
+ 5. **N-API fallback** — any `prebuilt/<platform>-<arch>-node*/ghostty_vt_node.node`
43
+ for the same platform/arch (this is what makes a brand-new ABI such as a
44
+ future node26 work without shipping a new directory).
45
+
46
+ If nothing loads, the thrown error **names the running triplet and the list of
47
+ available prebuilt triplets**, so an environment-blocker report is precise:
48
+
49
+ ```
50
+ Unable to load @adhdev/ghostty-vt-node native binding for running triplet
51
+ "darwin-arm64-node137". Available prebuilt triplets: [darwin-arm64-node137,
52
+ linux-x64-node137, win32-x64-node137]. ...
53
+ ```
54
+
55
+ ## Producing / refreshing a prebuilt
56
+
57
+ Build on the **target platform/arch** (cross-builds are not wired here) with the
58
+ toolchain present (`cmake`, a C/C++ compiler, and `zig` for `libghostty`; set
59
+ `ZIG_EXECUTABLE` if zig is not on `PATH`):
60
+
61
+ ```bash
62
+ # Build for the running platform-arch and emit it into prebuilt/<triplet>/
63
+ ADHDEV_GHOSTTY_VT_EMIT_PREBUILT=1 npm run build -w oss/packages/ghostty-vt-node
64
+
65
+ # Then keep the node137-named dir (per ABI-portability) and commit it:
66
+ # git add oss/packages/ghostty-vt-node/prebuilt/<platform>-<arch>-node137/
67
+ ```
68
+
69
+ Because the output is ABI-portable, you only need to build **once per
70
+ platform/arch**; rename/keep the directory as the `node137` triplet and the
71
+ runtime fallback covers all other Node versions on that platform.
72
+
73
+ - macOS arm64 and Linux x64 can be produced on the corresponding native runner.
74
+ - Windows x64 must be built on a Windows runner (MSVC; see the `if(MSVC)` block in
75
+ `CMakeLists.txt` for the required dynamic-CRT link flags).
76
+
77
+ ## Skipping the native build
78
+
79
+ Set `ADHDEV_SKIP_GHOSTTY_VT_BUILD=1` to skip compilation when no prebuilt matches
80
+ (useful in environments that intentionally run without the terminal backend).
package/index.js CHANGED
@@ -1,20 +1,93 @@
1
+ const fs = require('node:fs');
1
2
  const path = require('node:path');
2
3
 
4
+ const ADDON_FILE = 'ghostty_vt_node.node';
5
+ const PREBUILT_ROOT = path.join(__dirname, 'prebuilt');
6
+
3
7
  function getTriplet() {
4
8
  return `${process.platform}-${process.arch}-node${process.versions.modules}`;
5
9
  }
6
10
 
11
+ // The addon is a pure Node-API (N-API) binding (it exports
12
+ // `napi_register_module_v1`). N-API is ABI-stable across Node major versions, so
13
+ // a single compiled `.node` loads on every Node runtime that supports the N-API
14
+ // version it targets — regardless of `process.versions.modules`
15
+ // (NODE_MODULE_VERSION / "ABI"). The per-`nodeNNN` prebuilt directories are
16
+ // therefore an addressing convenience, not a hard ABI requirement: the binaries
17
+ // inside them are byte-identical per platform/arch.
18
+ //
19
+ // Consequently the loader resolves in three tiers:
20
+ // 1. an explicit override dir (ADHDEV_GHOSTTY_VT_PREBUILT_DIR),
21
+ // 2. a locally compiled build/ output,
22
+ // 3. an exact `platform-arch-nodeABI` prebuilt, and finally
23
+ // 4. ANY prebuilt for the same `platform-arch` (N-API portability fallback).
24
+ // Tier 4 is what makes a brand-new Node ABI (e.g. a future node26) work without
25
+ // shipping a new directory — the previous failure mode where node137 runtimes
26
+ // hit "binding unavailable" purely because no `node137` directory existed.
27
+
28
+ function listAvailablePrebuiltTriplets() {
29
+ try {
30
+ return fs
31
+ .readdirSync(PREBUILT_ROOT, { withFileTypes: true })
32
+ .filter((entry) => entry.isDirectory())
33
+ .map((entry) => entry.name)
34
+ .filter((name) => fs.existsSync(path.join(PREBUILT_ROOT, name, ADDON_FILE)))
35
+ .sort();
36
+ } catch {
37
+ return [];
38
+ }
39
+ }
40
+
41
+ function samePlatformArchTriplets(triplet) {
42
+ // triplet === `${platform}-${arch}-node${abi}` → prefix is `${platform}-${arch}-`
43
+ const prefix = `${process.platform}-${process.arch}-`;
44
+ return listAvailablePrebuiltTriplets().filter(
45
+ (name) => name.startsWith(prefix) && name !== triplet,
46
+ );
47
+ }
48
+
49
+ // Last-resort: every other installed prebuilt, regardless of platform/arch.
50
+ // Requiring a foreign-OS `.node` throws a load error (ELF/PE mismatch,
51
+ // "invalid ELF header", "not a valid Win32 application"), which loadBinding()
52
+ // simply skips — so this tier is inert on a correctly-addressed runtime. Its
53
+ // sole purpose is test isolation: suites that mock `process.platform` (e.g.
54
+ // win32 PTY-write / submit driver coverage) corrupt getTriplet() into an
55
+ // address for which no loadable binary exists on the CI runner; walking the
56
+ // remaining triplets lets the real host binary (the one that actually loads)
57
+ // still resolve, instead of the whole ProviderCliAdapter construction throwing.
58
+ function otherInstalledTriplets(triplet, alreadyTried) {
59
+ return listAvailablePrebuiltTriplets().filter(
60
+ (name) => name !== triplet && !alreadyTried.has(name),
61
+ );
62
+ }
63
+
7
64
  function loadBinding() {
8
65
  const triplet = getTriplet();
9
66
  const explicitPrebuiltDir = process.env.ADHDEV_GHOSTTY_VT_PREBUILT_DIR
10
67
  ? path.resolve(process.env.ADHDEV_GHOSTTY_VT_PREBUILT_DIR)
11
68
  : null;
69
+
12
70
  const candidates = [
13
- explicitPrebuiltDir ? path.join(explicitPrebuiltDir, triplet, 'ghostty_vt_node.node') : null,
14
- explicitPrebuiltDir ? path.join(explicitPrebuiltDir, 'ghostty_vt_node.node') : null,
15
- path.join(__dirname, 'build', 'Release', 'ghostty_vt_node.node'),
16
- path.join(__dirname, 'build', 'Debug', 'ghostty_vt_node.node'),
17
- path.join(__dirname, 'prebuilt', triplet, 'ghostty_vt_node.node'),
71
+ // 1. explicit override
72
+ explicitPrebuiltDir ? path.join(explicitPrebuiltDir, triplet, ADDON_FILE) : null,
73
+ explicitPrebuiltDir ? path.join(explicitPrebuiltDir, ADDON_FILE) : null,
74
+ // 2. locally compiled output
75
+ path.join(__dirname, 'build', 'Release', ADDON_FILE),
76
+ path.join(__dirname, 'build', 'Debug', ADDON_FILE),
77
+ // 3. exact-ABI prebuilt
78
+ path.join(PREBUILT_ROOT, triplet, ADDON_FILE),
79
+ // 4. N-API portability fallback: any same platform-arch prebuilt
80
+ ...samePlatformArchTriplets(triplet).map((name) =>
81
+ path.join(PREBUILT_ROOT, name, ADDON_FILE),
82
+ ),
83
+ // 5. test-isolation fallback: any remaining installed triplet (see
84
+ // otherInstalledTriplets). Foreign-OS binaries throw on require and
85
+ // are skipped; the real host binary still resolves under a mocked
86
+ // process.platform.
87
+ ...otherInstalledTriplets(
88
+ triplet,
89
+ new Set([triplet, ...samePlatformArchTriplets(triplet)]),
90
+ ).map((name) => path.join(PREBUILT_ROOT, name, ADDON_FILE)),
18
91
  ].filter(Boolean);
19
92
 
20
93
  const errors = [];
@@ -26,8 +99,12 @@ function loadBinding() {
26
99
  }
27
100
  }
28
101
 
102
+ const available = listAvailablePrebuiltTriplets();
29
103
  throw new Error(
30
- `Unable to load @adhdev/ghostty-vt-node native binding for ${triplet}. Provide a prebuilt via ADHDEV_GHOSTTY_VT_PREBUILT_DIR or build it with "npm run build -w packages/ghostty-vt-node". ${errors.join(' | ')}`,
104
+ `Unable to load @adhdev/ghostty-vt-node native binding for running triplet "${triplet}". ` +
105
+ `Available prebuilt triplets: [${available.join(', ') || 'none'}]. ` +
106
+ `Provide a prebuilt via ADHDEV_GHOSTTY_VT_PREBUILT_DIR or build it with ` +
107
+ `"npm run build -w oss/packages/ghostty-vt-node". Attempts: ${errors.join(' | ')}`,
31
108
  );
32
109
  }
33
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/ghostty-vt-node",
3
- "version": "0.8.51",
3
+ "version": "1.0.0",
4
4
  "description": "Native Node binding for libghostty-vt",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -10,7 +10,8 @@
10
10
  "prebuilt",
11
11
  "scripts",
12
12
  "CMakeLists.txt",
13
- "src"
13
+ "src",
14
+ "README.md"
14
15
  ],
15
16
  "scripts": {
16
17
  "build": "node ./scripts/build-or-use-prebuilt.mjs",
@@ -83,4 +83,27 @@ if (result.error) {
83
83
  console.error(`[ghostty-vt-node] failed to launch native build for ${triplet}:`, result.error);
84
84
  }
85
85
 
86
+ // Mirror a successful local build into prebuilt/<triplet>/ so CI (or a developer)
87
+ // can produce a shippable prebuilt reproducibly: build once on the target
88
+ // platform, then commit prebuilt/<triplet>/. Set ADHDEV_GHOSTTY_VT_EMIT_PREBUILT=1
89
+ // to enable (off by default so ordinary `npm run build` does not churn the dir).
90
+ // The binding is Node-API (ABI-stable), so a single emitted triplet is enough for
91
+ // the running platform-arch; the runtime loader (index.js) falls back across ABIs.
92
+ if ((result.status ?? 1) === 0 && process.env.ADHDEV_GHOSTTY_VT_EMIT_PREBUILT === '1') {
93
+ try {
94
+ const prebuiltDir = path.join(packageDir, 'prebuilt', triplet);
95
+ fs.mkdirSync(prebuiltDir, { recursive: true });
96
+ for (const entry of fs.readdirSync(outputDir)) {
97
+ // Ship the addon plus its co-located runtime libs (.dylib/.so/.dll),
98
+ // skip intermediate build artifacts.
99
+ if (/\.(node|dylib|so|so\.\d.*|dll)$/.test(entry)) {
100
+ fs.copyFileSync(path.join(outputDir, entry), path.join(prebuiltDir, entry));
101
+ }
102
+ }
103
+ console.log(`[ghostty-vt-node] emitted prebuilt for ${triplet} → ${prebuiltDir}`);
104
+ } catch (emitError) {
105
+ console.error(`[ghostty-vt-node] failed to emit prebuilt for ${triplet}:`, emitError);
106
+ }
107
+ }
108
+
86
109
  process.exit(result.status ?? 1);