gm-plugkit 2.0.1226 → 2.0.1228
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 +27 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-plugkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1228",
|
|
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
|
@@ -47,6 +47,9 @@ const SPOOL_POLL_PATTERNS = [
|
|
|
47
47
|
/\\b(?:cat|head|tail|less|more|type|Get-Content|gc)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
|
|
48
48
|
/\\b(?:ls|dir|Get-ChildItem|gci)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
|
|
49
49
|
/\\b(?:test|Test-Path|tp)\\s+(?:-[A-Za-z]+\\s+)?['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
|
|
50
|
+
/\\bfind\\b[^|]*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)\\b/i,
|
|
51
|
+
/\\b(?:stat|file|wc|Get-Item|gi|Get-Acl|Resolve-Path|Select-String|sls)\\b[^|]*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]?/i,
|
|
52
|
+
/\\b(?:xargs|parallel|fzf)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)/i,
|
|
50
53
|
];
|
|
51
54
|
|
|
52
55
|
const SPOOL_POLL_REASON = 'spool polling and bash-reads of .gm/exec-spool/ are forbidden — plugkit is synchronous from your view, and the Read tool is the canonical way to inspect spool files. Specific replacements:\\n\\n- Instead of \`cat .gm/exec-spool/.status.json\` → use the Read tool: \`Read .gm/exec-spool/.status.json\`\\n- Instead of \`ls .gm/exec-spool/out/\` → check the specific response file you wrote, e.g. \`Read .gm/exec-spool/out/<verb>-<N>.json\`\\n- Instead of \`cat .gm/exec-spool/.watcher.log\` → use the Read tool with offset for tailing\\n- Instead of \`sleep N; cat .gm/exec-spool/<...>\` → just Read the response file directly; if it doesn\\'t exist yet, the watcher is dead (Read .gm/exec-spool/.status.json — fresh ts means alive) or the verb is slow (Read .gm/exec-spool/.watcher.log for the dispatch trace)\\n\\nYou are the state machine. Plugkit serves the response the moment you write the request file. If you find yourself thinking "let me just check whether the file is there yet" — use Read. If you find yourself thinking "the watcher might have died" — Read .gm/exec-spool/.status.json. Bash on .gm/exec-spool/ is wrong every single time.';
|
|
@@ -741,19 +744,36 @@ function isPortReachableSync(host, port, timeoutMs) {
|
|
|
741
744
|
s.on('connect', () => { done = true; s.destroy(); process.exit(0); });
|
|
742
745
|
s.on('error', () => { if (!done) process.exit(1); });
|
|
743
746
|
setTimeout(() => { if (!done) { s.destroy(); process.exit(1); } }, ${timeoutMs || 800});
|
|
744
|
-
`], { timeout: (timeoutMs || 800) + 2000 });
|
|
747
|
+
`], { timeout: (timeoutMs || 800) + 2000, windowsHide: true });
|
|
745
748
|
return r.status === 0;
|
|
746
749
|
}
|
|
747
750
|
|
|
748
|
-
let _acptoapiBoot = { spawned_at: 0, pid: null };
|
|
751
|
+
let _acptoapiBoot = { spawned_at: 0, pid: null, last_check_ts: 0, last_check_ok: false };
|
|
749
752
|
function ensureAcptoapi() {
|
|
750
753
|
const host = '127.0.0.1';
|
|
751
754
|
const port = 4800;
|
|
752
755
|
try {
|
|
753
|
-
|
|
754
|
-
|
|
756
|
+
// Two-strike port check: localhost connect can race against node cold-
|
|
757
|
+
// start on Windows. If the first check fails, retry once with a longer
|
|
758
|
+
// timeout before declaring the port dead. iter9 sniff reported 29
|
|
759
|
+
// bootstrap.acptoapi.spawned events in 30m despite acptoapi being alive
|
|
760
|
+
// on :4800 (HTTP 200) — the check flaked under heartbeat-tick load.
|
|
761
|
+
let reachable = isPortReachableSync(host, port, 1500);
|
|
762
|
+
if (!reachable) {
|
|
763
|
+
reachable = isPortReachableSync(host, port, 3000);
|
|
764
|
+
}
|
|
765
|
+
if (reachable) {
|
|
766
|
+
const wasDown = _acptoapiBoot.spawned_at > 0 || !_acptoapiBoot.last_check_ok;
|
|
767
|
+
_acptoapiBoot = { spawned_at: 0, pid: null, status: 'already-running', last_check_ts: Date.now(), last_check_ok: true };
|
|
768
|
+
// Only log on transitions (down → up) so the heartbeat doesn't spam
|
|
769
|
+
// bootstrap.jsonl every 60s with redundant "alive" events.
|
|
770
|
+
if (wasDown) {
|
|
771
|
+
logEvent('bootstrap', 'acptoapi.heartbeat-ok', { port, transition: 'down-to-up' });
|
|
772
|
+
}
|
|
755
773
|
return;
|
|
756
774
|
}
|
|
775
|
+
_acptoapiBoot.last_check_ok = false;
|
|
776
|
+
_acptoapiBoot.last_check_ts = Date.now();
|
|
757
777
|
if (_acptoapiBoot.spawned_at && Date.now() - _acptoapiBoot.spawned_at < 30000) {
|
|
758
778
|
return;
|
|
759
779
|
}
|
|
@@ -766,7 +786,9 @@ function ensureAcptoapi() {
|
|
|
766
786
|
shell: false,
|
|
767
787
|
});
|
|
768
788
|
child.unref();
|
|
769
|
-
_acptoapiBoot =
|
|
789
|
+
_acptoapiBoot.spawned_at = Date.now();
|
|
790
|
+
_acptoapiBoot.pid = child.pid;
|
|
791
|
+
_acptoapiBoot.status = 'spawned';
|
|
770
792
|
logEvent('bootstrap', 'acptoapi.spawned', { pid: child.pid, port });
|
|
771
793
|
} catch (e) {
|
|
772
794
|
logEvent('bootstrap', 'acptoapi.spawn-failed', { error: e && e.message });
|