@qalqi/headless-hermes 0.2.0 → 0.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 +176 -4
- package/agent/.mcp.json +9 -0
- package/agent/AGENTS.md +30 -0
- package/agent/github/workflows/headless-hermes-verify.yml +34 -0
- package/agent/skills/headless-hermes-port/SKILL.md +72 -0
- package/agent/skills/headless-hermes-verify/SKILL.md +58 -0
- package/bin/headless-hermes.js +259 -0
- package/bin/napi-host.js +38 -1
- package/conformance.json +1456 -0
- package/index.js +26 -2
- package/lib/verify.js +102 -0
- package/mcp-server.js +321 -0
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -7,9 +7,14 @@ Metro, no simulator, no device. One `npm i`, and Hermes runs on your laptop and
|
|
|
7
7
|
[](https://github.com/qalqi/headless-hermes-jsi-node-api/actions/workflows/build.yml)
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm i -D @qalqi/headless-hermes
|
|
10
|
+
npm i -D @qalqi/headless-hermes # or
|
|
11
|
+
pnpm add -D @qalqi/headless-hermes # or
|
|
12
|
+
yarn add -D @qalqi/headless-hermes
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
The prebuilt engine comes as a platform package that npm, pnpm and Yarn pick for your machine. Yarn's Plug'n'Play
|
|
16
|
+
unpacks it (`preferUnplugged`), since native binaries can't run from a zip.
|
|
17
|
+
|
|
13
18
|
```js
|
|
14
19
|
// fib.js
|
|
15
20
|
const fib = n => n < 2 ? n : fib(n - 1) + fib(n - 2);
|
|
@@ -21,6 +26,8 @@ $ npx hermes fib.js
|
|
|
21
26
|
fib(25) = 75025 on Hermes 1.0.0
|
|
22
27
|
```
|
|
23
28
|
|
|
29
|
+
`pnpm exec hermes fib.js` and `yarn hermes fib.js` do the same.
|
|
30
|
+
|
|
24
31
|
## Does my code run on Hermes?
|
|
25
32
|
|
|
26
33
|
Node and browsers are not Hermes. Find out on your machine, not on a phone:
|
|
@@ -48,8 +55,68 @@ The same check in GitHub Actions, no install step:
|
|
|
48
55
|
|
|
49
56
|
```yaml
|
|
50
57
|
- run: npx -y -p @qalqi/headless-hermes hermes test/hermes-smoke.js
|
|
58
|
+
# or: pnpm --package=@qalqi/headless-hermes dlx hermes test/hermes-smoke.js
|
|
59
|
+
# or: yarn dlx -p @qalqi/headless-hermes hermes test/hermes-smoke.js
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Does it match my app? `headless-hermes doctor`
|
|
63
|
+
|
|
64
|
+
Checks the installed engine and its tools. In a React Native project, it also compares the bytecode version your
|
|
65
|
+
app's `hermesc` writes with this Hermes, and the Node-API versions your addons declare. Precompiled `.hbc` files
|
|
66
|
+
only run on a VM with the same bytecode version; plain `.js` always runs. For example, React Native 0.85 with its
|
|
67
|
+
default `hermes-compiler`:
|
|
68
|
+
|
|
69
|
+
```console
|
|
70
|
+
$ npx headless-hermes doctor
|
|
71
|
+
ok platform linux-x64: node_modules/@qalqi/headless-hermes-linux-x64
|
|
72
|
+
ok build @qalqi/headless-hermes 0.2.1, Hermes static_h 64d47e223980, Node-API 10
|
|
73
|
+
ok tools hermes runs; HBC bytecode version 100
|
|
74
|
+
info react-native react-native 0.85.3 in package.json (not installed)
|
|
75
|
+
warn bytecode the app's hermesc (hermes-compiler 250829098.0.10) writes bytecode 98, this Hermes runs 100: run the .js sources here, not .hbc files, or use a @qalqi/headless-hermes release on bytecode 98
|
|
76
|
+
info node-api no installed package declares Node-API versions (binary.napi_versions)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`--json` prints the same checks as JSON. The exit code is 1 when a check fails; warnings don't fail it.
|
|
80
|
+
|
|
81
|
+
## Let a coding agent verify it, and CI replay it
|
|
82
|
+
|
|
83
|
+
`init` adds the headless-hermes MCP server, two skills (verify, port), an `AGENTS.md` and a CI workflow to a project.
|
|
84
|
+
It never overwrites a file that exists.
|
|
85
|
+
|
|
86
|
+
```console
|
|
87
|
+
$ cd my-addon && npx headless-hermes init
|
|
88
|
+
init: wrote 6 file(s) under /path/to/my-addon
|
|
89
|
+
+ .claude/skills/headless-hermes-port/SKILL.md
|
|
90
|
+
+ .claude/skills/headless-hermes-verify/SKILL.md
|
|
91
|
+
+ .github/workflows/headless-hermes-verify.yml
|
|
92
|
+
+ AGENTS.md
|
|
93
|
+
+ .mcp.json
|
|
94
|
+
+ .headless/verify.json
|
|
95
|
+
|
|
96
|
+
Ask your agent: "verify my native module on Hermes", or "port my JSI module to Node-API".
|
|
97
|
+
Then run it in CI with: npx napi-host --verify .headless/verify.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The agent runs the addon on `napi-host` through the MCP server and records each test, with its golden output, in
|
|
101
|
+
`.headless/verify.json`. CI replays the file with no AI: each test runs on `napi-host` and its output must match.
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"engine": { "hermesCommit": "64d47e223980", "bytecode": 100 },
|
|
106
|
+
"tests": [
|
|
107
|
+
{ "script": "test/hello.js", "addon": "build/hello.node", "expected": "test/golden/hello.txt" }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```console
|
|
113
|
+
$ npx napi-host --verify .headless/verify.json
|
|
114
|
+
ok engine manifest wants hermes 64d47e223980; the build is 64d47e223980
|
|
115
|
+
ok test/hello.js
|
|
51
116
|
```
|
|
52
117
|
|
|
118
|
+
Until tests are recorded, `--verify` passes with `no tests yet`. The MCP server alone: `npx headless-hermes mcp`.
|
|
119
|
+
|
|
53
120
|
## Compile to bytecode
|
|
54
121
|
|
|
55
122
|
`hermesc` ships too. Precompile once, start instantly:
|
|
@@ -134,7 +201,43 @@ $ npx napi-host demo/app.js
|
|
|
134
201
|
hello from Node-API | add(20, 22) = 42
|
|
135
202
|
```
|
|
136
203
|
|
|
137
|
-
|
|
204
|
+
The host runs the event loop addons need, and they behave as on Node:
|
|
205
|
+
- **Async work**, and **Promises** resolved from other threads.
|
|
206
|
+
- **Thread-safe functions**: a referenced one keeps the process alive, and after `unref`/`release` it exits.
|
|
207
|
+
- **External array buffers**, **finalizers** and **env cleanup hooks**.
|
|
208
|
+
|
|
209
|
+
`gc()` is always there (Hermes' own), so a test can collect garbage and check that its finalizers ran. Every addon
|
|
210
|
+
example in the repository prints the same output on `napi-host` as on Node, and CI runs them under AddressSanitizer
|
|
211
|
+
and Valgrind.
|
|
212
|
+
|
|
213
|
+
**Which Node-API functions?** `napi-host` exports all 155 functions of Node-API 10. Each
|
|
214
|
+
[release](https://github.com/qalqi/headless-hermes-jsi-node-api/releases) attaches `node-api-conformance.md` and
|
|
215
|
+
`.json`, which give for every function:
|
|
216
|
+
- the Node-API version it arrived in;
|
|
217
|
+
- whether `napi-host` exports it;
|
|
218
|
+
- which tested examples call it;
|
|
219
|
+
- known differences: external strings are always copied, and `napi_adjust_external_memory` only keeps a count.
|
|
220
|
+
|
|
221
|
+
### react-native-node-api's tests, headless, on every commit
|
|
222
|
+
|
|
223
|
+
[react-native-node-api](https://github.com/callstackincubator/react-native-node-api) (Callstack Incubator) brings Node-API addons to React Native apps on iOS and Android, on Hermes' Node-API. Its
|
|
224
|
+
test suite (the nodejs/node-addon-examples it selected, plus four tests of its own) runs inside a React Native app on
|
|
225
|
+
a simulator or device. CI here runs the same suite with no app at all: it builds every addon for the machine, runs
|
|
226
|
+
the same `.node` file on `napi-host` and on Node, and compares output and exit code.
|
|
227
|
+
|
|
228
|
+
- **20 of 24 behave exactly as on Node.** That includes react-native-node-api's own `async` and `module-register`
|
|
229
|
+
tests, and its `threadsafe-function` test except the one part a Hermes bug blocks.
|
|
230
|
+
- **The other 4 are explained, each with a reason and a repro:**
|
|
231
|
+
- two examples need libuv (react-native-node-api leaves them out too);
|
|
232
|
+
- `buffers` checks React Native's buffer behaviour (a plain `Uint8Array`), which `napi-host` passes and Node doesn't;
|
|
233
|
+
- one is a **Hermes bug these runs found**: thread-safe function teardown hangs when a producer is blocked. It is
|
|
234
|
+
reproduced with Hermes alone and reported upstream as
|
|
235
|
+
[meta/hermes#2364](https://github.com/meta/hermes/issues/2364).
|
|
236
|
+
- **Pinned and re-checked.** The sources are fetched at fixed commits, and the suite reruns on every Hermes upgrade.
|
|
237
|
+
A known issue that stops happening fails CI, so the list stays true.
|
|
238
|
+
|
|
239
|
+
For an addon author this means an answer in seconds, on a laptop or in CI: does my addon work on Hermes' Node-API?
|
|
240
|
+
No app build, no simulator. The full table is in each CI run's summary.
|
|
138
241
|
|
|
139
242
|
## What you get
|
|
140
243
|
|
|
@@ -153,12 +256,43 @@ const hermes = require('@qalqi/headless-hermes');
|
|
|
153
256
|
hermes.includeDir(); // headers
|
|
154
257
|
hermes.libDir(); // libhermesvm
|
|
155
258
|
hermes.bin('napi-host'); // path to a tool
|
|
156
|
-
hermes.
|
|
259
|
+
hermes.cmakeDir(); // find_package(headless_hermes)
|
|
260
|
+
hermes.pkgConfigDir(); // pkg-config headless-hermes
|
|
261
|
+
hermes.buildInfo(); // { version, platform, hermes: { commit, bytecodeVersion, … }, nodeApi: { version } }
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### From CMake or pkg-config
|
|
265
|
+
|
|
266
|
+
```cmake
|
|
267
|
+
find_package(headless_hermes CONFIG REQUIRED) # -DCMAKE_PREFIX_PATH=$(node -p "require('@qalqi/headless-hermes').cmakeDir()")
|
|
268
|
+
add_executable(host host.cpp)
|
|
269
|
+
target_link_libraries(host PRIVATE headless_hermes::hermesvm)
|
|
157
270
|
```
|
|
158
271
|
|
|
272
|
+
```sh
|
|
273
|
+
export PKG_CONFIG_PATH=$(node -p "require('@qalqi/headless-hermes').pkgConfigDir()")
|
|
274
|
+
g++ host.cpp $(pkg-config --cflags --libs headless-hermes) -o host
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
`headless_hermes::addon` builds a Node-API addon. The GitHub Release archives also carry the VM's static libraries,
|
|
278
|
+
and with them `headless_hermes::napi`, for a Node-API host of your own.
|
|
279
|
+
|
|
159
280
|
## Which Hermes?
|
|
160
281
|
|
|
161
|
-
A pinned commit of Hermes' `static_h` branch, the one with JSI and Node-API (it reports itself as Hermes 1.0.0)
|
|
282
|
+
A pinned commit of Hermes' `static_h` branch, the one with JSI and Node-API (it reports itself as Hermes 1.0.0), on
|
|
283
|
+
HBC bytecode version 100. That is ahead of every React Native release so far: an app's JavaScript runs here, but its
|
|
284
|
+
precompiled `.hbc` files don't (`headless-hermes doctor` checks a project):
|
|
285
|
+
|
|
286
|
+
| React Native | Expo SDK | Its Hermes (`hermes-compiler`) | HBC bytecode |
|
|
287
|
+
|---|---|---|---|
|
|
288
|
+
| 0.83 | 55 | 0.14.1 | 96 |
|
|
289
|
+
| 0.84 | | 250829098.0.7 – 0.9 | 98 |
|
|
290
|
+
| 0.85 | 56 | 250829098.0.10 | 98 |
|
|
291
|
+
| 0.86, 0.87 | 57 (0.86) | 250829098.0.16 – 0.17 | 98 |
|
|
292
|
+
| 0.88 | 58 | 260318099.0.4 – 0.5 | 99 |
|
|
293
|
+
| 0.89 (RC) | | 260318099.0.9 | 99 |
|
|
294
|
+
|
|
295
|
+
|
|
162
296
|
`buildInfo()` prints the commit; the repository's README maps every release to its Hermes commit. Every version is
|
|
163
297
|
built and published by GitHub Actions with [npm provenance](https://docs.npmjs.com/generating-provenance-statements),
|
|
164
298
|
so each tarball links to the run and source that built it.
|
|
@@ -166,6 +300,44 @@ so each tarball links to the run and source that built it.
|
|
|
166
300
|
Only need `hermesc` to compile bytecode for a React Native release build? Use Meta's
|
|
167
301
|
[`hermes-compiler`](https://www.npmjs.com/package/hermes-compiler). This package is for running and embedding Hermes.
|
|
168
302
|
|
|
303
|
+
## What's new in 0.3.0
|
|
304
|
+
|
|
305
|
+
Same Hermes as 0.2.1: `static_h` [`64d47e22`](https://github.com/facebook/hermes/commit/64d47e22398073ca6a5ae65249ddcc65e85df3fd)
|
|
306
|
+
(2026-11-30), bytecode 100.
|
|
307
|
+
|
|
308
|
+
- **[react-native-node-api](https://github.com/callstackincubator/react-native-node-api)'s addon tests run in CI** on `napi-host` and on Node, with the same `.node` files: its
|
|
309
|
+
node-addon-examples list and its own four tests. 20 of 24 match Node; the 4 others are known issues, each with a
|
|
310
|
+
category and a repro. One is a Hermes bug found this way, reported as
|
|
311
|
+
[meta/hermes#2364](https://github.com/meta/hermes/issues/2364).
|
|
312
|
+
- **Agent channel.** `npx headless-hermes init` adds an MCP server (`npx headless-hermes mcp`), two skills (verify,
|
|
313
|
+
port) and a CI workflow to a project; `npx napi-host --verify .headless/verify.json` replays the recorded tests
|
|
314
|
+
against their golden output, with no AI in CI.
|
|
315
|
+
- **`headless-hermes doctor`** checks this machine's build against a React Native project: the bytecode version its
|
|
316
|
+
`hermesc` writes, and the Node-API versions its addons declare.
|
|
317
|
+
- **`buildInfo()`** returns the build's provenance as an object; CMake `find_package(headless_hermes)` and pkg-config
|
|
318
|
+
files come with each platform package.
|
|
319
|
+
- **Exit codes and `--json`** for `napi-host` and `hermes-jsi-run`: 0 ran, 1 JavaScript error, 2 host error.
|
|
320
|
+
`process.exitCode` sets the exit code, as in Node.
|
|
321
|
+
- **`setImmediate` / `clearImmediate`** in `napi-host`.
|
|
322
|
+
- **The Node-API examples run on Node too**, in CI, with the same expected output.
|
|
323
|
+
|
|
324
|
+
## What's new in 0.2.1
|
|
325
|
+
|
|
326
|
+
- **Hermes** `static_h` [`64d47e22`](https://github.com/facebook/hermes/commit/64d47e22398073ca6a5ae65249ddcc65e85df3fd)
|
|
327
|
+
(2026-11-30). 0.2.0 was built on `d41288df`.
|
|
328
|
+
- **The Node-API lifecycle is tested against Node.** New examples cover:
|
|
329
|
+
- external array buffers;
|
|
330
|
+
- blocking thread-safe functions;
|
|
331
|
+
- event-loop liveness (`ref`/`unref`/`release`);
|
|
332
|
+
- finalizers after `gc()`;
|
|
333
|
+
- env cleanup hooks.
|
|
334
|
+
|
|
335
|
+
Each prints the same output on `napi-host` as on Node.
|
|
336
|
+
- **Memory-checked.** The addon examples and their stress variants (8 threads × 256 calls) run under
|
|
337
|
+
AddressSanitizer/LeakSanitizer and Valgrind in CI.
|
|
338
|
+
- **A Node-API conformance table** comes with every release: `node-api-conformance.md` and `.json`. All 155 functions
|
|
339
|
+
of Node-API 10 are exported.
|
|
340
|
+
|
|
169
341
|
## License
|
|
170
342
|
|
|
171
343
|
Packaging: Apache-2.0. Hermes: MIT, Meta Platforms, Inc. and affiliates (`LICENSE-hermes` in each platform package).
|
package/agent/.mcp.json
ADDED
package/agent/AGENTS.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# headless-hermes: agent integration
|
|
2
|
+
|
|
3
|
+
This project verifies its native modules on **headless Hermes** (Node-API on
|
|
4
|
+
the Hermes engine, no React Native, no simulator). A coding agent operates it
|
|
5
|
+
through the headless-hermes MCP server.
|
|
6
|
+
|
|
7
|
+
## Engine
|
|
8
|
+
- Hermes `static_h` {{HERMES_COMMIT}} · napi-host {{NAPI_HOST_VERSION}} ·
|
|
9
|
+
Node-API {{NODE_API_VERSION}} · bytecode pinned in `.headless/verify.json`.
|
|
10
|
+
|
|
11
|
+
## Tools (headless-hermes MCP server)
|
|
12
|
+
- `hermes_run` — run JS on Hermes.
|
|
13
|
+
- `napi_run` — load a `.node` + test on napi-host.
|
|
14
|
+
- `napi_conformance` — the 155-function Node-API catalog + known differences.
|
|
15
|
+
- `build_info` — engine commit / the bytecode version its `hermesc` writes / N-API.
|
|
16
|
+
- `manifest_write` — update `.headless/verify.json`.
|
|
17
|
+
|
|
18
|
+
## The two workflows
|
|
19
|
+
- **verify** (`.claude/skills/headless-hermes-verify/`): prove the addon runs on Hermes; leave
|
|
20
|
+
a replayable manifest. No porting.
|
|
21
|
+
- **port** (`.claude/skills/headless-hermes-port/`): add a Node-API skin to a JSI module,
|
|
22
|
+
additive only, proven by golden-output parity between `hermes-jsi-run` and
|
|
23
|
+
`napi-host`.
|
|
24
|
+
|
|
25
|
+
## CI (no AI)
|
|
26
|
+
`.github/workflows/headless-hermes-verify.yml` replays `.headless/verify.json`
|
|
27
|
+
on every PR: `npx napi-host --verify .headless/verify.json`. The agent writes
|
|
28
|
+
the manifest once; CI replays it forever.
|
|
29
|
+
|
|
30
|
+
Ask your agent: "verify my native module on Hermes."
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Replays .headless/verify.json on every PR with no AI in the loop.
|
|
2
|
+
# The agent writes the manifest once (expensive); this step is cheap and deterministic.
|
|
3
|
+
#
|
|
4
|
+
# Fill in the `Build the addon` step for your build system (node-gyp, cmake, cargo/napi-rs, …).
|
|
5
|
+
# Everything else is generic: install headless-hermes, then `npx napi-host --verify`.
|
|
6
|
+
name: headless-hermes-verify
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
pull_request:
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
verify:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0
|
|
19
|
+
with:
|
|
20
|
+
node-version: 20
|
|
21
|
+
|
|
22
|
+
- name: Install
|
|
23
|
+
run: npm ci --omit=dev || npm install
|
|
24
|
+
|
|
25
|
+
- name: Build the addon
|
|
26
|
+
# TODO: your addon build (node-gyp / cmake / napi-rs). The .node must exist at the
|
|
27
|
+
# path named in .headless/verify.json before this step runs.
|
|
28
|
+
run: echo "TODO: build the .node named in .headless/verify.json"
|
|
29
|
+
|
|
30
|
+
- name: Install headless-hermes
|
|
31
|
+
run: npm install -g @qalqi/headless-hermes@{{NAPI_HOST_VERSION}}
|
|
32
|
+
|
|
33
|
+
- name: Replay the verify manifest (deterministic, no AI)
|
|
34
|
+
run: npx napi-host --verify .headless/verify.json
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: headless-hermes-port
|
|
3
|
+
description: Add a Node-API entry point to an existing JSI module without touching its core, and prove parity by running the same test on hermes-jsi-run and napi-host. Use when asked to port a JSI module to Node-API. Additive only; never publishes.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Skill: port a JSI module to Node-API (additive)
|
|
7
|
+
|
|
8
|
+
Goal: add a Node-API entry point to an existing JSI module **without touching the
|
|
9
|
+
core logic**, then prove parity by running the same test on both shipped hosts.
|
|
10
|
+
This is the "parallel ABI first, switch later" strategy: keep the JSI install
|
|
11
|
+
function, add an N-API skin over the same C++ core, and let the human switch.
|
|
12
|
+
|
|
13
|
+
## The one rule
|
|
14
|
+
**Never modify the core.** The JSI binding layer (`install(jsi::Runtime&)`,
|
|
15
|
+
host functions, `jsi::HostObject` getters/setters) is the only code you may
|
|
16
|
+
change. All business logic, data structures and algorithms stay byte-for-byte.
|
|
17
|
+
You add a new N-API translation unit (e.g. `napi_binding.cpp`) that re-exposes
|
|
18
|
+
the same functions. If a Rust core, skip the table and use `#[napi]` via
|
|
19
|
+
napi-rs instead.
|
|
20
|
+
|
|
21
|
+
## JSI → Node-API mapping (the systematic core of the port)
|
|
22
|
+
| JSI | Node-API |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `jsi::Function::createFromHostFunction` | `napi_create_function` + `napi_get_cb_info` |
|
|
25
|
+
| `jsi::Value::isNumber` / `getNumber` (and `isString`, `isBool`, …) | `napi_typeof` + `napi_get_value_double` (…`_string_utf8`, `_bool`) |
|
|
26
|
+
| `jsi::Value::getString(runtime)` | `napi_get_value_string_utf8` |
|
|
27
|
+
| `jsi::ArrayBuffer` | `napi_create_arraybuffer` / `napi_create_external_arraybuffer` |
|
|
28
|
+
| `jsi::HostObject` subclass | `napi_wrap` / `napi_unwrap` (or `napi_define_class`) |
|
|
29
|
+
| a promise resolved from `std::thread` | `napi_create_threadsafe_function` + `napi_create_promise` |
|
|
30
|
+
| async work on a pool | `napi_create_async_work` + `napi_queue_async_work` |
|
|
31
|
+
| `jsi::Value::getObject(runtime)` | `napi_typeof` is `napi_object`, then use the `napi_value` (`napi_coerce_to_object` to convert) |
|
|
32
|
+
| a `jsi::Value` kept across calls | `napi_create_reference` / `napi_get_reference_value` |
|
|
33
|
+
| throw `jsi::JSError` | `napi_throw_error` |
|
|
34
|
+
|
|
35
|
+
The mapping is systematic — that is why an agent can do this reliably. When a JSI
|
|
36
|
+
call has no row above, stop and ask: do not invent the N-API equivalent.
|
|
37
|
+
|
|
38
|
+
## Steps
|
|
39
|
+
1. **Find the seam.** Grep for `install(jsi::Runtime`, `HostObject`,
|
|
40
|
+
`createFromHostFunction`. List the exported functions and which are pure core
|
|
41
|
+
vs. binding. Confirm with the human which functions to port.
|
|
42
|
+
2. **Check the target.** Call `build_info` (N-API version, Hermes commit). Call
|
|
43
|
+
`napi_conformance` and confirm every function you will use is `exported`
|
|
44
|
+
(and not in `known_differences`, or note the behaviour gap). `exercised_by`
|
|
45
|
+
lists the CI demos that call it; an empty list means it loads but nothing
|
|
46
|
+
here tests its behaviour, so your parity test is the evidence.
|
|
47
|
+
3. **Write the N-API skin.** New file only. Each JSI function gets a
|
|
48
|
+
`napi_callback` that decodes args with `napi_get_cb_info`, calls the same
|
|
49
|
+
core function, and encodes the result. Build against the shipped headers and
|
|
50
|
+
library: `includeDir()` / `libDir()` from the `headless-hermes` index, via
|
|
51
|
+
CMake or node-gyp.
|
|
52
|
+
4. **Prove parity (the move nobody else can make).** Run the **same JS test
|
|
53
|
+
file** against both shipped hosts and diff the outputs:
|
|
54
|
+
- JSI path: `hermes-jsi-run` with the JSI addon.
|
|
55
|
+
- N-API path: `napi-host` (via the MCP `napi_run` tool) with the new `.node`.
|
|
56
|
+
Golden-output parity — identical stdout on both ABIs — is what makes an
|
|
57
|
+
agent-generated port trustworthy enough to merge.
|
|
58
|
+
5. **Write the manifest** covering both ABIs, and the CI workflow.
|
|
59
|
+
6. **Open a PR.** The human reviews. This skill never auto-publishes.
|
|
60
|
+
|
|
61
|
+
## Guards
|
|
62
|
+
- C/C++/napi-rs only. No Windows. No cloud.
|
|
63
|
+
- Additive only: the new N-API file must not `#include`-mutate the JSI core.
|
|
64
|
+
- Parity diff is mandatory before the PR.
|
|
65
|
+
|
|
66
|
+
## Report shape
|
|
67
|
+
```
|
|
68
|
+
Seam: <n> JSI functions, <m> ported
|
|
69
|
+
Conformance: all N functions exported; known-differences used: <list>
|
|
70
|
+
Parity: hermes-jsi-run vs napi-host on <test> → IDENTICAL / <diff>
|
|
71
|
+
Artifact: napi_binding.cpp (new), test/golden/<...>, .headless/verify.json
|
|
72
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: headless-hermes-verify
|
|
3
|
+
description: Prove a Node-API .node addon (or a JSI module) loads and runs on Hermes with headless-hermes, and leave a .headless/verify.json manifest that CI replays with no AI. Use when asked to verify, test or check a native module on Hermes. Does no porting.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Skill: verify a native module on headless-hermes
|
|
7
|
+
|
|
8
|
+
Goal: prove that a Node-API `.node` addon (or a JSI module) builds, loads, and
|
|
9
|
+
behaves on Hermes, and leave a deterministic `.headless/verify.json` manifest
|
|
10
|
+
behind so CI can replay it with no AI. This skill does **no porting**; it only
|
|
11
|
+
proves things work and records the result.
|
|
12
|
+
|
|
13
|
+
## Tools (from the headless-hermes MCP server)
|
|
14
|
+
- `build_info` — engine commit, the bytecode version its `hermesc` writes, N-API version.
|
|
15
|
+
- `napi_run` — load a `.node` + run a test script on `napi-host`; returns stdout/stderr/exit.
|
|
16
|
+
- `napi_conformance` — the 155-function catalog + known differences.
|
|
17
|
+
- `manifest_write` — save/update `.headless/verify.json`.
|
|
18
|
+
|
|
19
|
+
## Steps
|
|
20
|
+
1. **Engine pin.** Call `build_info` and record its commit and bytecode version in
|
|
21
|
+
the manifest's `engine`. For a React Native project, run
|
|
22
|
+
`npx headless-hermes doctor` in it: it compares the bytecode version the app's
|
|
23
|
+
`hermesc` writes with this build's and says whether precompiled `.hbc` files
|
|
24
|
+
load. Report a mismatch; don't guess React Native compatibility from a commit.
|
|
25
|
+
2. **Find the addon + tests.** Locate the built `.node` (search `build/`,
|
|
26
|
+
`out/`, `lib/`, `prebuilds/`) and the project's test entry points
|
|
27
|
+
(`test/`, `__tests__/`, `*.spec.js`, or a script the README names).
|
|
28
|
+
3. **Run it on Hermes.** For each test script, call `napi_run` with the addon.
|
|
29
|
+
A passing run is exit code 0.
|
|
30
|
+
4. **Conformance.** Call `napi_conformance`. If the addon's source calls any
|
|
31
|
+
function in `known_differences` (external-string latin1/utf16,
|
|
32
|
+
adjust_external_memory), flag it: the symbol loads but behaves differently on
|
|
33
|
+
Hermes than Node.
|
|
34
|
+
5. **Capture golden output.** For each passing test, save its stdout to a golden
|
|
35
|
+
file (e.g. `test/golden/<name>.txt`).
|
|
36
|
+
6. **Write the manifest.** Call `manifest_write` with:
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"engine": { "hermesCommit": "<build_info.hermes_commit>", "bytecode": <build_info.bytecode_version> },
|
|
40
|
+
"tests": [
|
|
41
|
+
{ "script": "test/parity.js", "addon": "build/Release/mylib.node",
|
|
42
|
+
"args": [], "expected": "test/golden/parity.txt" }
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
7. **Leave the CI workflow.** Confirm `.github/workflows/headless-hermes-verify.yml`
|
|
47
|
+
exists (init creates it). It runs `npx napi-host --verify .headless/verify.json`
|
|
48
|
+
on every PR — deterministic, no AI.
|
|
49
|
+
|
|
50
|
+
## Report shape
|
|
51
|
+
```
|
|
52
|
+
Engine: Hermes static_h <commit> (bytecode <n>), N-API <v>; doctor: <match / mismatch>
|
|
53
|
+
<name>: PASS/FAIL (<exit code>, <n> bytes matched)
|
|
54
|
+
Conformance: <k> of <total> functions; known differences that this addon uses: <list>
|
|
55
|
+
Manifest: .headless/verify.json written (<n> tests)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Do **not** build, commit, or publish. Verification only.
|