@qalqi/headless-hermes 0.2.1 → 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 +143 -3
- 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 +11 -6
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:
|
|
@@ -151,6 +218,27 @@ and Valgrind.
|
|
|
151
218
|
- which tested examples call it;
|
|
152
219
|
- known differences: external strings are always copied, and `napi_adjust_external_memory` only keeps a count.
|
|
153
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.
|
|
241
|
+
|
|
154
242
|
## What you get
|
|
155
243
|
|
|
156
244
|
| Platform | Package (installed for you) |
|
|
@@ -168,12 +256,43 @@ const hermes = require('@qalqi/headless-hermes');
|
|
|
168
256
|
hermes.includeDir(); // headers
|
|
169
257
|
hermes.libDir(); // libhermesvm
|
|
170
258
|
hermes.bin('napi-host'); // path to a tool
|
|
171
|
-
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)
|
|
172
270
|
```
|
|
173
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
|
+
|
|
174
280
|
## Which Hermes?
|
|
175
281
|
|
|
176
|
-
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
|
+
|
|
177
296
|
`buildInfo()` prints the commit; the repository's README maps every release to its Hermes commit. Every version is
|
|
178
297
|
built and published by GitHub Actions with [npm provenance](https://docs.npmjs.com/generating-provenance-statements),
|
|
179
298
|
so each tarball links to the run and source that built it.
|
|
@@ -181,6 +300,27 @@ so each tarball links to the run and source that built it.
|
|
|
181
300
|
Only need `hermesc` to compile bytecode for a React Native release build? Use Meta's
|
|
182
301
|
[`hermes-compiler`](https://www.npmjs.com/package/hermes-compiler). This package is for running and embedding Hermes.
|
|
183
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
|
+
|
|
184
324
|
## What's new in 0.2.1
|
|
185
325
|
|
|
186
326
|
- **Hermes** `static_h` [`64d47e22`](https://github.com/facebook/hermes/commit/64d47e22398073ca6a5ae65249ddcc65e85df3fd)
|
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.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// headless-hermes <doctor|init|mcp> [options]
|
|
4
|
+
//
|
|
5
|
+
// doctor [--json] [<project dir>] (or --dir <project dir>) Is this machine's prebuilt Hermes installed and working, and does it match
|
|
6
|
+
// the React Native project? (checks platform pkg, tools, provenance, RN, bytecode,
|
|
7
|
+
// Node-API versions). Exits 1 on a failed check; warnings don't fail.
|
|
8
|
+
// init [<project dir>] (or --dir <project dir>) Scaffold the agent integration into a project: the MCP
|
|
9
|
+
// server registration, the two skills (.claude/skills/headless-hermes-{verify,port}),
|
|
10
|
+
// an AGENTS.md, a starter .headless/verify.json and the CI workflow that replays it.
|
|
11
|
+
// No build; it only writes files, and never overwrites one that exists.
|
|
12
|
+
// mcp Start the headless-hermes MCP server on stdio (JSON-RPC). Used by MCP clients.
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const { spawnSync } = require('child_process');
|
|
17
|
+
const hh = require('..');
|
|
18
|
+
|
|
19
|
+
const NODE_API_VERSION = 10;
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
const command = args.shift();
|
|
22
|
+
const json = args.includes('--json');
|
|
23
|
+
|
|
24
|
+
function optValue(name, def) {
|
|
25
|
+
const i = args.indexOf(name);
|
|
26
|
+
return i !== -1 && args[i + 1] && !args[i + 1].startsWith('-') ? args[i + 1] : def;
|
|
27
|
+
}
|
|
28
|
+
// The project dir: --dir <dir>, or the first argument that isn't an option (as doctor took it in 0.2.1).
|
|
29
|
+
function projectArg() {
|
|
30
|
+
const i = args.indexOf('--dir');
|
|
31
|
+
return optValue('--dir', null) || args.find((a, j) => !a.startsWith('-') && (i === -1 || j !== i + 1)) || '.';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (command === 'mcp') {
|
|
35
|
+
// Run the MCP server in-process (stdio JSON-RPC).
|
|
36
|
+
require(path.join(__dirname, '..', 'mcp-server.js'));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (command === 'init') {
|
|
41
|
+
runInit(projectArg());
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (command !== 'doctor') {
|
|
46
|
+
console.error('usage: headless-hermes <doctor [--json] [<project dir>] | init [--dir <project dir>] | mcp>');
|
|
47
|
+
process.exit(2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const projectDir = path.resolve(projectArg());
|
|
51
|
+
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// init: scaffold the agent integration into a project (templates live in the
|
|
54
|
+
// package's agent/ directory; placeholders are filled with this build's provenance).
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
function runInit(targetDir) {
|
|
57
|
+
const target = path.resolve(targetDir);
|
|
58
|
+
const pkgRoot = path.join(__dirname, '..');
|
|
59
|
+
const tpl = path.join(pkgRoot, 'agent');
|
|
60
|
+
if (!fs.existsSync(tpl)) {
|
|
61
|
+
console.error('init: agent templates not found in the installed package (this is a source checkout without agent/).');
|
|
62
|
+
process.exit(2);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let build = {};
|
|
66
|
+
try {
|
|
67
|
+
build = hh.buildInfo();
|
|
68
|
+
build.version = build.version || require('../package.json').version;
|
|
69
|
+
build.hermesCommit = (build.hermes && build.hermes.commit || '').slice(0, 12);
|
|
70
|
+
build.bytecode = (build.hermes && build.hermes.bytecodeVersion) || null;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
build = { version: require('../package.json').version, hermesCommit: '', bytecode: null };
|
|
73
|
+
}
|
|
74
|
+
const values = {
|
|
75
|
+
'{{NAPI_HOST_VERSION}}': build.version,
|
|
76
|
+
'{{HERMES_COMMIT}}': build.hermesCommit || '(not installed on this machine)',
|
|
77
|
+
'{{NODE_API_VERSION}}': String(NODE_API_VERSION),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const out = [];
|
|
81
|
+
const kept = [];
|
|
82
|
+
const copyTree = (srcDir, dstDir) => {
|
|
83
|
+
fs.mkdirSync(dstDir, { recursive: true });
|
|
84
|
+
for (const e of fs.readdirSync(srcDir, { withFileTypes: true })) {
|
|
85
|
+
const s = path.join(srcDir, e.name);
|
|
86
|
+
const d = path.join(dstDir, e.name);
|
|
87
|
+
if (e.isDirectory()) { copyTree(s, d); continue; }
|
|
88
|
+
if (fs.existsSync(d)) { kept.push(path.relative(target, d)); continue; }
|
|
89
|
+
fs.writeFileSync(d, fill(s));
|
|
90
|
+
out.push(path.relative(target, d));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// .claude/skills/ + AGENTS.md + .mcp.json + .github/workflows/
|
|
95
|
+
copyTree(path.join(tpl, 'skills'), path.join(target, '.claude', 'skills'));
|
|
96
|
+
copyTree(path.join(tpl, 'github'), path.join(target, '.github'));
|
|
97
|
+
const writeIfAbsent = (rel, content) => {
|
|
98
|
+
const p = path.join(target, rel);
|
|
99
|
+
if (!fs.existsSync(p)) { fs.writeFileSync(p, content); out.push(rel); } else kept.push(rel);
|
|
100
|
+
};
|
|
101
|
+
writeIfAbsent('AGENTS.md', fill(path.join(tpl, 'AGENTS.md')));
|
|
102
|
+
writeIfAbsent('.mcp.json', fill(path.join(tpl, '.mcp.json')));
|
|
103
|
+
|
|
104
|
+
// Starter manifest, pinned to this build when its provenance is known. No tests yet: --verify passes with a note
|
|
105
|
+
// until the agent (or you) adds them.
|
|
106
|
+
const manifest = {
|
|
107
|
+
engine: build.hermesCommit ? { hermesCommit: build.hermesCommit, bytecode: build.bytecode } : {},
|
|
108
|
+
tests: [],
|
|
109
|
+
};
|
|
110
|
+
const manifestPath = path.join(target, '.headless', 'verify.json');
|
|
111
|
+
if (!fs.existsSync(manifestPath)) {
|
|
112
|
+
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
113
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
|
|
114
|
+
out.push('.headless/verify.json');
|
|
115
|
+
} else kept.push('.headless/verify.json');
|
|
116
|
+
|
|
117
|
+
function fill(p) {
|
|
118
|
+
let t = fs.readFileSync(p, 'utf8');
|
|
119
|
+
for (const [k, v] of Object.entries(values)) t = t.split(k).join(v);
|
|
120
|
+
return t;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(`init: wrote ${out.length} file(s) under ${target}`);
|
|
124
|
+
for (const f of out) console.log(` + ${f}`);
|
|
125
|
+
for (const f of kept) console.log(` = ${f} (exists, kept)`);
|
|
126
|
+
console.log('\nAsk your agent: "verify my native module on Hermes", or "port my JSI module to Node-API".');
|
|
127
|
+
console.log('Then run it in CI with: npx napi-host --verify .headless/verify.json');
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// doctor: unchanged from 0.2.1.
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
const checks = [];
|
|
135
|
+
const add = (status, name, message) => checks.push({ status, name, message });
|
|
136
|
+
|
|
137
|
+
function bytecodeOf(binary) {
|
|
138
|
+
const r = spawnSync(binary, ['--version'], { encoding: 'utf8' });
|
|
139
|
+
const m = /HBC bytecode version:\s*(\d+)/.exec(`${r.stdout || ''}${r.stderr || ''}`);
|
|
140
|
+
return m ? Number(m[1]) : null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function readJson(file) {
|
|
144
|
+
try {
|
|
145
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
146
|
+
} catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Resolves <name>/package.json as Node would from the project, or from react-native (pnpm keeps transitive
|
|
152
|
+
// dependencies out of the project's node_modules). Returns its directory, or null.
|
|
153
|
+
function resolvePackage(name, from) {
|
|
154
|
+
try {
|
|
155
|
+
return path.dirname(require.resolve(`${name}/package.json`, { paths: from }));
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function findFile(dir, name, depth = 4) {
|
|
162
|
+
if (depth < 0 || !fs.existsSync(dir)) return null;
|
|
163
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
164
|
+
const p = path.join(dir, e.name);
|
|
165
|
+
if (e.isFile() && e.name === name) return p;
|
|
166
|
+
if (e.isDirectory()) {
|
|
167
|
+
const found = findFile(p, name, depth - 1);
|
|
168
|
+
if (found) return found;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 1. This machine's prebuilt.
|
|
175
|
+
let info = null;
|
|
176
|
+
let ourBytecode = null;
|
|
177
|
+
try {
|
|
178
|
+
info = hh.buildInfo();
|
|
179
|
+
const where = path.relative(process.cwd(), hh.platformPackageDir());
|
|
180
|
+
add('ok', 'platform', `${process.platform}-${process.arch}: ${where.startsWith('..') ? hh.platformPackageDir() : where}`);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
add('fail', 'platform', e.message);
|
|
183
|
+
}
|
|
184
|
+
if (info) {
|
|
185
|
+
const commit = info.hermes && info.hermes.commit;
|
|
186
|
+
ourBytecode = (info.hermes && info.hermes.bytecodeVersion) || null;
|
|
187
|
+
add('ok', 'build', `@qalqi/headless-hermes ${info.version || require('../package.json').version}, Hermes static_h ${commit ? commit.slice(0, 12) : 'unknown'}, Node-API ${NODE_API_VERSION}`);
|
|
188
|
+
const hermes = hh.bin('hermes');
|
|
189
|
+
const bc = fs.existsSync(hermes) ? bytecodeOf(hermes) : null;
|
|
190
|
+
if (bc === null) {
|
|
191
|
+
add('fail', 'tools', `${hermes} doesn't run (or doesn't report its bytecode version)`);
|
|
192
|
+
} else {
|
|
193
|
+
ourBytecode = bc;
|
|
194
|
+
add('ok', 'tools', `hermes runs; HBC bytecode version ${bc}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 2. The project.
|
|
199
|
+
const pkg = readJson(path.join(projectDir, 'package.json'));
|
|
200
|
+
if (!pkg) {
|
|
201
|
+
add('info', 'project', `no package.json in ${projectDir}: project checks skipped`);
|
|
202
|
+
} else {
|
|
203
|
+
const deps = { ...pkg.devDependencies, ...pkg.dependencies };
|
|
204
|
+
const rnDir = resolvePackage('react-native', [projectDir]);
|
|
205
|
+
const rnPkg = rnDir && readJson(path.join(rnDir, 'package.json'));
|
|
206
|
+
if (rnPkg) add('info', 'react-native', `react-native ${rnPkg.version} installed`);
|
|
207
|
+
else if (deps['react-native']) add('info', 'react-native', `react-native ${deps['react-native']} in package.json (not installed)`);
|
|
208
|
+
else add('info', 'react-native', 'no react-native dependency');
|
|
209
|
+
|
|
210
|
+
// The bytecode the app's hermesc writes: precompiled .hbc runs only on a VM with the same bytecode version.
|
|
211
|
+
const hcDir = resolvePackage('hermes-compiler', [projectDir, ...(rnDir ? [rnDir] : [])]);
|
|
212
|
+
const hc = hcDir && readJson(path.join(hcDir, 'package.json'));
|
|
213
|
+
if (!hc) {
|
|
214
|
+
add('info', 'bytecode', 'hermes-compiler not installed: no app bytecode to compare (plain .js always runs)');
|
|
215
|
+
} else {
|
|
216
|
+
const hermesc = findFile(hcDir, process.platform === 'win32' ? 'hermesc.exe' : 'hermesc');
|
|
217
|
+
const appBytecode = hermesc ? bytecodeOf(hermesc) : null;
|
|
218
|
+
if (appBytecode === null) {
|
|
219
|
+
add('warn', 'bytecode', `hermes-compiler ${hc.version}: couldn't run its hermesc to read the bytecode version`);
|
|
220
|
+
} else if (ourBytecode === null) {
|
|
221
|
+
add('warn', 'bytecode', `the app's hermesc (hermes-compiler ${hc.version}) writes bytecode ${appBytecode}; this build's version is unknown`);
|
|
222
|
+
} else if (appBytecode === ourBytecode) {
|
|
223
|
+
add('ok', 'bytecode', `the app's hermesc (hermes-compiler ${hc.version}) and this Hermes both use bytecode ${appBytecode}: its .hbc files run here`);
|
|
224
|
+
} else {
|
|
225
|
+
add('warn', 'bytecode', `the app's hermesc (hermes-compiler ${hc.version}) writes bytecode ${appBytecode}, this Hermes runs ${ourBytecode}: run the .js sources here, not .hbc files, or use a @qalqi/headless-hermes release on bytecode ${appBytecode}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Node-API versions the project's addons declare (node-pre-gyp / prebuild: "binary": { "napi_versions": [...] }).
|
|
230
|
+
const nodeModules = path.join(projectDir, 'node_modules');
|
|
231
|
+
const needs = [];
|
|
232
|
+
const scan = (dir) => {
|
|
233
|
+
if (!fs.existsSync(dir)) return;
|
|
234
|
+
for (const name of fs.readdirSync(dir)) {
|
|
235
|
+
if (name.startsWith('.')) continue;
|
|
236
|
+
if (name.startsWith('@')) { scan(path.join(dir, name)); continue; }
|
|
237
|
+
const p = readJson(path.join(dir, name, 'package.json'));
|
|
238
|
+
const versions = p && p.binary && p.binary.napi_versions;
|
|
239
|
+
if (Array.isArray(versions) && versions.length) needs.push({ name: p.name, min: Math.min(...versions) });
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
scan(nodeModules);
|
|
243
|
+
const tooNew = needs.filter((n) => n.min > NODE_API_VERSION);
|
|
244
|
+
if (tooNew.length) {
|
|
245
|
+
add('warn', 'node-api', `needs Node-API above ${NODE_API_VERSION}: ${tooNew.map((n) => `${n.name} (${n.min})`).join(', ')}`);
|
|
246
|
+
} else if (needs.length) {
|
|
247
|
+
add('ok', 'node-api', `${needs.length} addon package(s) declare Node-API versions; all within ${NODE_API_VERSION}`);
|
|
248
|
+
} else {
|
|
249
|
+
add('info', 'node-api', 'no installed package declares Node-API versions (binary.napi_versions)');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const failed = checks.some((c) => c.status === 'fail');
|
|
254
|
+
if (json) {
|
|
255
|
+
console.log(JSON.stringify({ ok: !failed, checks }, null, 1));
|
|
256
|
+
} else {
|
|
257
|
+
for (const c of checks) console.log(`${c.status.padEnd(5)} ${c.name.padEnd(13)} ${c.message}`);
|
|
258
|
+
}
|
|
259
|
+
process.exit(failed ? 1 : 0);
|