gm-plugkit 2.0.1116 → 2.0.1118
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 +16 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-plugkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1118",
|
|
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
|
@@ -660,10 +660,14 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
660
660
|
const dir = path.dirname(relPath);
|
|
661
661
|
const verb = dir === '.' ? path.basename(filePath, path.extname(filePath)) : dir;
|
|
662
662
|
const body = content.trim() || '{}';
|
|
663
|
+
const taskBase = path.basename(filePath, path.extname(filePath));
|
|
663
664
|
|
|
664
665
|
const verbBytes = new TextEncoder().encode(verb);
|
|
665
666
|
const bodyBytes = new TextEncoder().encode(body);
|
|
666
667
|
|
|
668
|
+
const t0 = Date.now();
|
|
669
|
+
console.log(`[dispatch] → verb=${verb} task=${taskBase} body=${bodyBytes.length}b`);
|
|
670
|
+
|
|
667
671
|
const verbPtr = instance.exports.plugkit_alloc(verbBytes.length);
|
|
668
672
|
const bodyPtr = instance.exports.plugkit_alloc(bodyBytes.length);
|
|
669
673
|
new Uint8Array(instance.exports.memory.buffer, verbPtr, verbBytes.length).set(verbBytes);
|
|
@@ -676,9 +680,9 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
676
680
|
const resultBytes = new Uint8Array(instance.exports.memory.buffer, ptr, len);
|
|
677
681
|
const resultStr = new TextDecoder().decode(resultBytes);
|
|
678
682
|
|
|
679
|
-
const taskBase = path.basename(filePath, path.extname(filePath));
|
|
680
683
|
const outName = dir === '.' ? `${taskBase}.json` : `${verb}-${taskBase}.json`;
|
|
681
684
|
fs.writeFileSync(path.join(outDir, outName), resultStr);
|
|
685
|
+
console.log(`[dispatch] ← verb=${verb} task=${taskBase} ms=${Date.now() - t0} out=${resultStr.length}b`);
|
|
682
686
|
|
|
683
687
|
try { instance.exports.plugkit_free(verbPtr, verbBytes.length); } catch (_) {}
|
|
684
688
|
try { instance.exports.plugkit_free(bodyPtr, bodyBytes.length); } catch (_) {}
|
|
@@ -742,19 +746,22 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
742
746
|
setInterval(() => {
|
|
743
747
|
try {
|
|
744
748
|
const cutoff = Date.now() - 3600_000;
|
|
749
|
+
let swept = 0;
|
|
745
750
|
for (const entry of fs.readdirSync(outDir)) {
|
|
746
751
|
try {
|
|
747
752
|
const fp = path.join(outDir, entry);
|
|
748
753
|
const s = fs.statSync(fp);
|
|
749
|
-
if (s.mtimeMs < cutoff) fs.unlinkSync(fp);
|
|
750
|
-
} catch (
|
|
754
|
+
if (s.mtimeMs < cutoff) { fs.unlinkSync(fp); swept++; }
|
|
755
|
+
} catch (e) { console.error(`[retention] failed to sweep ${entry}: ${e.message}`); }
|
|
751
756
|
}
|
|
752
|
-
|
|
757
|
+
if (swept > 0) console.log(`[retention] swept ${swept} out/ files older than 1h`);
|
|
758
|
+
} catch (e) { console.error(`[retention] sweep error: ${e.message}`); }
|
|
753
759
|
}, 60_000);
|
|
754
760
|
|
|
755
761
|
setInterval(() => {
|
|
756
762
|
try {
|
|
757
763
|
const cutoff = Date.now() - 600_000;
|
|
764
|
+
let stale = 0;
|
|
758
765
|
const walk = (dir) => {
|
|
759
766
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
760
767
|
const fp = path.join(dir, entry.name);
|
|
@@ -768,14 +775,16 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
768
775
|
const outName = verbDir === '.' ? `${base}.json` : `${verbDir}-${base}.json`;
|
|
769
776
|
try {
|
|
770
777
|
fs.writeFileSync(path.join(outDir, outName), JSON.stringify({ ok: false, error: 'stale input — never dispatched or watcher crash mid-flight' }));
|
|
771
|
-
} catch (
|
|
772
|
-
try { fs.unlinkSync(fp); } catch (
|
|
778
|
+
} catch (e) { console.error(`[stale-sweep] failed to write error for ${rel}: ${e.message}`); }
|
|
779
|
+
try { fs.unlinkSync(fp); stale++; } catch (e) { console.error(`[stale-sweep] failed to unlink ${rel}: ${e.message}`); }
|
|
780
|
+
console.error(`[stale-sweep] auto-failed ${rel} (age >${600}s)`);
|
|
773
781
|
}
|
|
774
782
|
}
|
|
775
783
|
}
|
|
776
784
|
};
|
|
777
785
|
walk(inDir);
|
|
778
|
-
|
|
786
|
+
if (stale > 0) console.log(`[stale-sweep] failed ${stale} orphaned inputs`);
|
|
787
|
+
} catch (e) { console.error(`[stale-sweep] sweep error: ${e.message}`); }
|
|
779
788
|
}, 300_000);
|
|
780
789
|
|
|
781
790
|
const existing = walkDir(inDir);
|