@simular-ai/simulang-js 5.5.0 → 6.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.
- package/CLAUDE.md +30 -4
- package/examples/log-window.mjs +12 -8
- package/index.d.ts +12 -3
- package/index.js +52 -52
- package/package.json +13 -11
- package/wrapped.d.ts +25 -0
- package/wrapped.js +139 -0
package/CLAUDE.md
CHANGED
|
@@ -31,6 +31,28 @@ restatement elsewhere.
|
|
|
31
31
|
screen is 3840×2160 in these coordinates. Image and screenshot dimensions
|
|
32
32
|
are likewise in physical pixels.
|
|
33
33
|
|
|
34
|
+
## Logging is on by default
|
|
35
|
+
|
|
36
|
+
`import '@simular-ai/simulang-js'` auto-installs a stderr logger sink — no
|
|
37
|
+
explicit `initLogger()` call required. Records from simulang-rs (clipboard
|
|
38
|
+
reads/writes, keyboard input, app launches, window state changes, …) show
|
|
39
|
+
up on the host process's stderr formatted as `[level] message`. The Rust
|
|
40
|
+
`target` (module path, e.g. `simulang_rs::common::clipboard`) is omitted
|
|
41
|
+
from the default format to keep terminal output readable; install a
|
|
42
|
+
custom callback via `initLogger(cb)` to access it on the record payload.
|
|
43
|
+
|
|
44
|
+
Filter resolution: `RUST_LOG` if set, otherwise `simulang_rs=info,warn` —
|
|
45
|
+
info-level records from simulang's own actions, warn-level from every
|
|
46
|
+
other crate. Override at any time with `initLogger(...)`:
|
|
47
|
+
|
|
48
|
+
- `initLogger(null, 'off')` — silence everything
|
|
49
|
+
- `initLogger(null, 'simulang_rs=debug,warn')` — bump verbosity
|
|
50
|
+
- `initLogger(cb)` — forward records to a JS callback (log window, file
|
|
51
|
+
appender, pino/winston, Electron renderer over IPC, …) instead of stderr
|
|
52
|
+
|
|
53
|
+
`initLogger` atomically swaps both the sink and the filter on every call,
|
|
54
|
+
so it composes cleanly with the auto-install.
|
|
55
|
+
|
|
34
56
|
## Live log viewer (optional)
|
|
35
57
|
|
|
36
58
|
`@simular-ai/simulang-log-viewer` is a **human-facing aid**: a floating,
|
|
@@ -52,7 +74,8 @@ else, also shown inside the window) toggles "grab mode": pressing it once
|
|
|
52
74
|
turns click-through off, pauses execution, and makes the window draggable;
|
|
53
75
|
pressing it again restores click-through and resumes.
|
|
54
76
|
|
|
55
|
-
|
|
77
|
+
Re-route records into the window via `initLogger` (overriding the
|
|
78
|
+
default stderr sink) and respect the pause inside automation loops:
|
|
56
79
|
|
|
57
80
|
```js
|
|
58
81
|
import { initLogger } from '@simular-ai/simulang-js'
|
|
@@ -66,12 +89,15 @@ initLogger((rec) => win.log(`[${rec.level}] [${rec.target}] ${rec.message}`), 'i
|
|
|
66
89
|
await win.waitIfPaused()
|
|
67
90
|
```
|
|
68
91
|
|
|
92
|
+
(The simpler way is to `import '@simular-ai/simulang-log-viewer'` for its
|
|
93
|
+
side effect — the package's auto-install entry point spawns the window,
|
|
94
|
+
registers the pause hook, and calls `initLogger` for you.)
|
|
95
|
+
|
|
69
96
|
The second argument to `initLogger` is a filter spec in the `RUST_LOG`
|
|
70
97
|
environment-variable syntax used by Rust's `env_logger` / `log` crates —
|
|
71
98
|
e.g. `'info'` for a global level, `'simulang_rs=debug,warn'` for per-module
|
|
72
|
-
scoping.
|
|
73
|
-
|
|
74
|
-
`index.d.ts` for the full grammar.
|
|
99
|
+
scoping. See `initLogger`'s JSDoc in `index.d.ts` for the full grammar
|
|
100
|
+
and the auto-install default.
|
|
75
101
|
|
|
76
102
|
Other methods: `clear()` drops displayed messages, `isPaused` getter for a
|
|
77
103
|
non-blocking check, `close()` to shut the viewer (also automatic on parent
|
package/examples/log-window.mjs
CHANGED
|
@@ -26,29 +26,33 @@ win.spawn()
|
|
|
26
26
|
|
|
27
27
|
// `'info'` mirrors `RUST_LOG=info`. Use e.g. `'simulang_rs=debug,warn'` to
|
|
28
28
|
// scope per-module. Omit the second argument to fall back to `RUST_LOG`.
|
|
29
|
+
//
|
|
30
|
+
// `win.log` already mirrors every line to the host's stderr internally,
|
|
31
|
+
// so a single call here gets the record into both the floating viewer
|
|
32
|
+
// and the terminal — no extra `console.log` needed.
|
|
29
33
|
initLogger((rec) => {
|
|
30
|
-
|
|
31
|
-
console.log(line)
|
|
32
|
-
win.log(line)
|
|
34
|
+
win.log(`[${rec.level}] ${rec.message}`)
|
|
33
35
|
}, 'info')
|
|
34
36
|
|
|
35
37
|
// Run a few simulang-js calls so there's actually something to look at.
|
|
36
|
-
|
|
38
|
+
// Each call emits its own `[info]` record via `initLogger` above, so the
|
|
39
|
+
// `win.log` lines below stick to script-level milestones rather than
|
|
40
|
+
// re-narrating every call.
|
|
41
|
+
win.log('clipboard + screenshot demo')
|
|
37
42
|
try {
|
|
38
43
|
const cb = new Clipboard()
|
|
39
44
|
const previous = cb.setString('hello from simulang-js')
|
|
40
|
-
|
|
45
|
+
cb.getString()
|
|
41
46
|
if (previous !== null) cb.setString(previous)
|
|
42
47
|
|
|
43
|
-
win.log('--- starting screenshot demo ---')
|
|
44
48
|
const shot = screenshotFull(true, Screen.mainScreen())
|
|
45
49
|
shot.shrink(640, 480)
|
|
46
|
-
win.log(`captured ${shot.base64().length} bytes
|
|
50
|
+
win.log(`screenshot captured: ${shot.base64().length} bytes base64`)
|
|
47
51
|
} catch (err) {
|
|
48
52
|
win.log(`demo failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
win.log('
|
|
55
|
+
win.log('holding window open for 30s, press the grab hotkey to pause')
|
|
52
56
|
await new Promise((resolve) => setTimeout(resolve, 30_000))
|
|
53
57
|
// In real automation, scatter `await win.waitIfPaused()` between actions
|
|
54
58
|
// so the script yields whenever the user has grabbed the window.
|
package/index.d.ts
CHANGED
|
@@ -1230,16 +1230,25 @@ export declare function hasScreenCapturePermission(): boolean
|
|
|
1230
1230
|
/**
|
|
1231
1231
|
* Initialize the logger.
|
|
1232
1232
|
*
|
|
1233
|
+
* **You usually don't need to call this.** The package's `main` entry
|
|
1234
|
+
* (`wrapped.js`) calls `initLogger()` with no arguments on first
|
|
1235
|
+
* evaluation, so simply `import '@simular-ai/simulang-js'` is enough to
|
|
1236
|
+
* see `[level] message` records on stderr. Call this directly
|
|
1237
|
+
* only when you want to *override* that default — to forward records to
|
|
1238
|
+
* a JS callback, change the filter spec, or silence everything.
|
|
1239
|
+
*
|
|
1233
1240
|
* - **No callback** (`initLogger()` or `initLogger(null, spec)`): records
|
|
1234
|
-
* are formatted as `[level]
|
|
1241
|
+
* are formatted as `[level] message` and written to stderr.
|
|
1235
1242
|
* - **With a callback** (`initLogger(cb, spec)`): records are forwarded to
|
|
1236
1243
|
* the JS callback via a non-blocking, unref'd threadsafe function. Use
|
|
1237
1244
|
* this for GUI panels, file appenders, or routing through a logging
|
|
1238
1245
|
* library like pino. The unref'd dispatch means the logger does not keep
|
|
1239
1246
|
* the Node event loop alive on its own.
|
|
1240
1247
|
*
|
|
1241
|
-
* Omit `spec` to read `RUST_LOG` (
|
|
1242
|
-
*
|
|
1248
|
+
* Omit `spec` to read `RUST_LOG` (falls back to `"simulang_rs=info,warn"`
|
|
1249
|
+
* when `RUST_LOG` is unset — info-level records from simulang's own
|
|
1250
|
+
* actions, warn-level from every other crate). Pass an explicit `spec`
|
|
1251
|
+
* to override `RUST_LOG`. Syntax is identical to `RUST_LOG`:
|
|
1243
1252
|
*
|
|
1244
1253
|
* - `"info"` — global level
|
|
1245
1254
|
* - `"simulang_rs=debug,warn"` — per-module override + default
|
package/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@simular-ai/simulang-js-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@simular-ai/simulang-js-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
80
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('@simular-ai/simulang-js-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@simular-ai/simulang-js-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
96
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('@simular-ai/simulang-js-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
117
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('@simular-ai/simulang-js-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
133
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@simular-ai/simulang-js-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
150
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('@simular-ai/simulang-js-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
166
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('@simular-ai/simulang-js-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
185
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('@simular-ai/simulang-js-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
201
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('@simular-ai/simulang-js-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
217
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@simular-ai/simulang-js-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@simular-ai/simulang-js-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
237
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('@simular-ai/simulang-js-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@simular-ai/simulang-js-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
253
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('@simular-ai/simulang-js-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
274
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('@simular-ai/simulang-js-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
290
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('@simular-ai/simulang-js-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
308
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('@simular-ai/simulang-js-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
324
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('@simular-ai/simulang-js-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
342
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('@simular-ai/simulang-js-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
358
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('@simular-ai/simulang-js-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
376
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('@simular-ai/simulang-js-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
392
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@simular-ai/simulang-js-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
410
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('@simular-ai/simulang-js-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
426
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@simular-ai/simulang-js-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
443
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@simular-ai/simulang-js-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
459
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@simular-ai/simulang-js-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
479
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@simular-ai/simulang-js-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
495
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('@simular-ai/simulang-js-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
511
|
+
if (bindingPackageVersion !== '6.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 6.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simular-ai/simulang-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Node.js bindings for simulang-rs",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "wrapped.js",
|
|
6
|
+
"types": "./wrapped.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
10
|
-
"default": "./
|
|
9
|
+
"types": "./wrapped.d.ts",
|
|
10
|
+
"default": "./wrapped.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"index.d.ts",
|
|
36
36
|
"index.js",
|
|
37
|
+
"wrapped.d.ts",
|
|
38
|
+
"wrapped.js",
|
|
37
39
|
"CLAUDE.md",
|
|
38
40
|
"bin/init-claude.mjs",
|
|
39
41
|
"bin/postinstall-hint.mjs",
|
|
@@ -114,11 +116,11 @@
|
|
|
114
116
|
"arrowParens": "always"
|
|
115
117
|
},
|
|
116
118
|
"optionalDependencies": {
|
|
117
|
-
"@simular-ai/simulang-js-win32-x64-msvc": "
|
|
118
|
-
"@simular-ai/simulang-js-win32-arm64-msvc": "
|
|
119
|
-
"@simular-ai/simulang-js-darwin-x64": "
|
|
120
|
-
"@simular-ai/simulang-js-darwin-arm64": "
|
|
121
|
-
"@simular-ai/simulang-js-linux-x64-gnu": "
|
|
122
|
-
"@simular-ai/simulang-js-linux-arm64-gnu": "
|
|
119
|
+
"@simular-ai/simulang-js-win32-x64-msvc": "6.0.0",
|
|
120
|
+
"@simular-ai/simulang-js-win32-arm64-msvc": "6.0.0",
|
|
121
|
+
"@simular-ai/simulang-js-darwin-x64": "6.0.0",
|
|
122
|
+
"@simular-ai/simulang-js-darwin-arm64": "6.0.0",
|
|
123
|
+
"@simular-ai/simulang-js-linux-x64-gnu": "6.0.0",
|
|
124
|
+
"@simular-ai/simulang-js-linux-arm64-gnu": "6.0.0"
|
|
123
125
|
}
|
|
124
126
|
}
|
package/wrapped.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-authored entry that re-exports the napi-generated bindings from
|
|
3
|
+
* `index.d.ts` and adds the `setPauseHook` API used by
|
|
4
|
+
* `@simular-ai/simulang-log-viewer` to weave pause-handshake behavior
|
|
5
|
+
* through every simulang-js call.
|
|
6
|
+
*
|
|
7
|
+
* The package's `types` field points here. `index.d.ts` stays as the
|
|
8
|
+
* napi-rs codegen output (and the source of truth for the public API
|
|
9
|
+
* surface that auto-docs and Claude skills consume).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './index'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Register a function to be called synchronously before every
|
|
16
|
+
* simulang-js method or free function executes. Used by
|
|
17
|
+
* `@simular-ai/simulang-log-viewer` to make the log window's
|
|
18
|
+
* pause/grab-hotkey state transparently affect every simulang-js call.
|
|
19
|
+
* Pass `null` to clear.
|
|
20
|
+
*
|
|
21
|
+
* The hook runs on the calling thread, before delegating to the
|
|
22
|
+
* native binding. It must not call back into simulang-js — that would
|
|
23
|
+
* recurse.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setPauseHook(fn: (() => void) | null): void
|
package/wrapped.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Re-export the napi bindings, but with a global pause hook woven into
|
|
2
|
+
// every callable. Set the hook via `setPauseHook(fn)`; clear with `null`.
|
|
3
|
+
// While set, the hook runs synchronously before every method or
|
|
4
|
+
// free-function call delegates to the native binding — that lets
|
|
5
|
+
// `@simular-ai/simulang-log-viewer` make its grab/pause state apply to
|
|
6
|
+
// every simulang-js call transparently, without forcing user code to
|
|
7
|
+
// switch import paths or add awaits.
|
|
8
|
+
//
|
|
9
|
+
// The package's `main` points here, so `import '@simular-ai/simulang-js'`
|
|
10
|
+
// resolves to this wrapper. The napi-rs codegen still owns `index.js`
|
|
11
|
+
// and `index.d.ts` verbatim — auto-doc and Claude-skill tooling that
|
|
12
|
+
// reads those files keeps working unchanged.
|
|
13
|
+
//
|
|
14
|
+
// Wrapping happens once at module load against `index.js`'s own
|
|
15
|
+
// exports, so any new function or class added to the napi crate is
|
|
16
|
+
// picked up automatically as long as `napi build` emits it through
|
|
17
|
+
// the generated `index.js`.
|
|
18
|
+
|
|
19
|
+
module.exports = require('./index.js')
|
|
20
|
+
const binding = module.exports
|
|
21
|
+
|
|
22
|
+
let pauseHook = null
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Register a function to call synchronously before every simulang-js
|
|
26
|
+
* method or free function executes. Pass `null` to clear. The hook
|
|
27
|
+
* must not call back into simulang-js — that would recurse.
|
|
28
|
+
*/
|
|
29
|
+
function setPauseHook(fn) {
|
|
30
|
+
pauseHook = typeof fn === 'function' ? fn : null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function wrap(orig) {
|
|
34
|
+
return function pauseAware(...args) {
|
|
35
|
+
if (pauseHook) pauseHook()
|
|
36
|
+
return orig.apply(this, args)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Patch instance methods in place on the prototype. napi-rs emits these
|
|
41
|
+
// as writable+configurable properties, so direct assignment works and
|
|
42
|
+
// every existing or future instance — wherever the class is imported
|
|
43
|
+
// from — sees the wrapped method through prototype lookup.
|
|
44
|
+
function patchPrototype(klass) {
|
|
45
|
+
for (const name of Object.getOwnPropertyNames(klass.prototype)) {
|
|
46
|
+
if (name === 'constructor') continue
|
|
47
|
+
const desc = Object.getOwnPropertyDescriptor(klass.prototype, name)
|
|
48
|
+
// Skip accessor properties (getters/setters): reading a property
|
|
49
|
+
// shouldn't trigger pause-wait. Only wrap method-valued slots.
|
|
50
|
+
if (typeof desc?.value !== 'function') continue
|
|
51
|
+
klass.prototype[name] = wrap(desc.value)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const RESERVED_STATIC_KEYS = new Set(['length', 'name', 'prototype'])
|
|
56
|
+
|
|
57
|
+
// Static methods on napi-rs classes are non-writable AND non-configurable,
|
|
58
|
+
// so direct assignment fails and Proxy invariants forbid returning a
|
|
59
|
+
// different value through `get`. We work around it by exporting a thin
|
|
60
|
+
// subclass that redefines the statics as writable properties; the
|
|
61
|
+
// subclass's own prototype chain delegates everything else to the
|
|
62
|
+
// original class.
|
|
63
|
+
//
|
|
64
|
+
// `[Symbol.hasInstance]` is overridden so that instances returned by
|
|
65
|
+
// the underlying napi factories (which carry the original prototype, not
|
|
66
|
+
// the subclass's) still satisfy `inst instanceof WrappedKlass`.
|
|
67
|
+
function wrapStatics(klass) {
|
|
68
|
+
const statics = []
|
|
69
|
+
for (const name of Object.getOwnPropertyNames(klass)) {
|
|
70
|
+
if (RESERVED_STATIC_KEYS.has(name)) continue
|
|
71
|
+
const desc = Object.getOwnPropertyDescriptor(klass, name)
|
|
72
|
+
if (typeof desc?.value !== 'function') continue
|
|
73
|
+
statics.push([name, wrap(desc.value)])
|
|
74
|
+
}
|
|
75
|
+
if (statics.length === 0) return klass
|
|
76
|
+
|
|
77
|
+
class Wrapped extends klass {
|
|
78
|
+
static [Symbol.hasInstance](inst) {
|
|
79
|
+
return inst instanceof klass
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Plain assignment (`Wrapped[name] = wrapped`) walks the prototype
|
|
83
|
+
// chain and silently fails when it finds the inherited non-writable
|
|
84
|
+
// static. defineProperty bypasses the chain and installs an own,
|
|
85
|
+
// shadowing slot.
|
|
86
|
+
for (const [name, wrapped] of statics) {
|
|
87
|
+
Object.defineProperty(Wrapped, name, {
|
|
88
|
+
value: wrapped,
|
|
89
|
+
writable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
enumerable: false,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
// Preserve `name` for stack traces / `toString()` output.
|
|
95
|
+
Object.defineProperty(Wrapped, 'name', { value: klass.name, configurable: true })
|
|
96
|
+
return Wrapped
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// napi-rs classes carry either instance methods on the prototype (beyond
|
|
100
|
+
// `constructor`) or static methods on the class itself, or both. Plain
|
|
101
|
+
// free function exports have neither. Enums are plain objects.
|
|
102
|
+
//
|
|
103
|
+
// The static-method check has to look for function-VALUED own properties
|
|
104
|
+
// specifically, not just any own property beyond the reserved set: Node
|
|
105
|
+
// 24's `napi_create_function` installs legacy `arguments` and `caller`
|
|
106
|
+
// slots on every napi-emitted function object (Node 25+ does not), and
|
|
107
|
+
// without the function-value filter those would make every free function
|
|
108
|
+
// (`keyFromString`, `ariaRoleToString`, …) misclassify as a class and
|
|
109
|
+
// silently bypass the `wrap(fn)` branch — pause hooks never firing for
|
|
110
|
+
// free-function calls is exactly what that bug looked like.
|
|
111
|
+
function isClass(value) {
|
|
112
|
+
if (typeof value !== 'function' || !value.prototype) return false
|
|
113
|
+
if (Object.getOwnPropertyNames(value.prototype).length > 1) return true
|
|
114
|
+
for (const name of Object.getOwnPropertyNames(value)) {
|
|
115
|
+
if (RESERVED_STATIC_KEYS.has(name)) continue
|
|
116
|
+
const desc = Object.getOwnPropertyDescriptor(value, name)
|
|
117
|
+
if (typeof desc?.value === 'function') return true
|
|
118
|
+
}
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (const key of Object.keys(binding)) {
|
|
123
|
+
const value = binding[key]
|
|
124
|
+
if (isClass(value)) {
|
|
125
|
+
patchPrototype(value)
|
|
126
|
+
module.exports[key] = wrapStatics(value)
|
|
127
|
+
} else if (typeof value === 'function') {
|
|
128
|
+
module.exports[key] = wrap(value)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
module.exports.setPauseHook = setPauseHook
|
|
132
|
+
|
|
133
|
+
// Auto-install the stderr logger sink so simulang-rs `log::*!` records
|
|
134
|
+
// (clipboard reads/writes, keyboard input, app launches, window state,
|
|
135
|
+
// etc.) are visible in the terminal as soon as `import
|
|
136
|
+
// '@simular-ai/simulang-js'` evaluates — no explicit `initLogger()` call
|
|
137
|
+
// required. Without this, the `log` crate has no logger registered at
|
|
138
|
+
// all, so every `log::*!` is a silent no-op regardless of `RUST_LOG`.
|
|
139
|
+
binding.initLogger()
|