gm-plugkit 2.0.1292 → 2.0.1294
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/package.json +1 -1
- package/plugkit-wasm-wrapper.js +40 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-plugkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1294",
|
|
4
4
|
"description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
package/plugkit-wasm-wrapper.js
CHANGED
|
@@ -709,7 +709,9 @@ function findInstalledChromiumBinary() {
|
|
|
709
709
|
}
|
|
710
710
|
|
|
711
711
|
function startManagedBrowser(pw, profileDir) {
|
|
712
|
-
const
|
|
712
|
+
const headless = process.env.GM_BROWSER_HEADLESS === '1';
|
|
713
|
+
const args = [...pw.baseArgs, 'browser', 'start', '--user-data-dir', profileDir];
|
|
714
|
+
if (headless) args.push('--headless');
|
|
713
715
|
const env = { ...process.env };
|
|
714
716
|
if (!env.GM_BROWSER_RUNNER_PATH && !env.PLAYWRITER_BROWSER_PATH) {
|
|
715
717
|
const browserBin = findInstalledChromiumBinary();
|
|
@@ -875,10 +877,25 @@ function cosineSim(a, b) {
|
|
|
875
877
|
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
876
878
|
}
|
|
877
879
|
|
|
880
|
+
let __wasmAbortFlag = { aborted: false, code: 0 };
|
|
878
881
|
function createWasiShim(instanceRef) {
|
|
879
882
|
const getMemory = () => instanceRef.value.exports.memory.buffer;
|
|
880
883
|
const shim = {
|
|
881
|
-
proc_exit: (code) =>
|
|
884
|
+
proc_exit: (code) => {
|
|
885
|
+
__wasmAbortFlag.aborted = true;
|
|
886
|
+
__wasmAbortFlag.code = code;
|
|
887
|
+
try {
|
|
888
|
+
const spoolDir = spoolDirForSentinel();
|
|
889
|
+
fs.mkdirSync(spoolDir, { recursive: true });
|
|
890
|
+
fs.writeFileSync(path.join(spoolDir, '.wasm-abort.json'), JSON.stringify({
|
|
891
|
+
ts: Date.now(),
|
|
892
|
+
exit_code: code,
|
|
893
|
+
verb_in_flight: __currentVerbContext,
|
|
894
|
+
}));
|
|
895
|
+
} catch (_) {}
|
|
896
|
+
try { console.error(`[plugkit-wasm] wasm proc_exit(${code}) intercepted; throwing to abort current verb without killing watcher`); } catch (_) {}
|
|
897
|
+
throw new Error(`wasm proc_exit(${code}) during verb ${__currentVerbContext && __currentVerbContext.verb}`);
|
|
898
|
+
},
|
|
882
899
|
fd_write: (fd, iovs_ptr, iovs_len, nwritten_ptr) => {
|
|
883
900
|
try {
|
|
884
901
|
const buf = getMemory();
|
|
@@ -2022,6 +2039,27 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
2022
2039
|
if (isProcessed(key)) return;
|
|
2023
2040
|
markProcessed(key);
|
|
2024
2041
|
|
|
2042
|
+
if (__wasmAbortFlag.aborted) {
|
|
2043
|
+
try {
|
|
2044
|
+
const taskBase = path.basename(filePath, path.extname(filePath));
|
|
2045
|
+
const relPath = path.relative(inDir, filePath);
|
|
2046
|
+
const dir = path.dirname(relPath);
|
|
2047
|
+
const verb = dir === '.' ? taskBase : dir;
|
|
2048
|
+
const outName = dir === '.' ? `${taskBase}.json` : `${verb}-${taskBase}.json`;
|
|
2049
|
+
fs.writeFileSync(path.join(outDir, outName), JSON.stringify({
|
|
2050
|
+
ok: false,
|
|
2051
|
+
error: `wasm aborted earlier (exit_code=${__wasmAbortFlag.code}); watcher will respawn`,
|
|
2052
|
+
wasm_aborted: true,
|
|
2053
|
+
}));
|
|
2054
|
+
try { fs.unlinkSync(filePath); } catch (_) {}
|
|
2055
|
+
} catch (_) {}
|
|
2056
|
+
unmarkProcessed(key);
|
|
2057
|
+
emitShutdownReason('wasm-abort-graceful', new Error(`wasm proc_exit(${__wasmAbortFlag.code}) earlier; clean watcher restart`));
|
|
2058
|
+
try { console.error('[plugkit-wasm] exiting after wasm abort to allow supervisor respawn'); } catch (_) {}
|
|
2059
|
+
setTimeout(() => process.exit(2), 100).unref();
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2025
2063
|
try {
|
|
2026
2064
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
2027
2065
|
const relPath = path.relative(inDir, filePath);
|