gm-plugkit 2.0.1147 → 2.0.1148

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.
Files changed (2) hide show
  1. package/cli.js +86 -26
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -1,18 +1,52 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const { ensureReady, startSpoolDaemon, getBinaryPath, isReady } = require('./bootstrap');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { ensureReady, startSpoolDaemon } = require('./bootstrap');
5
7
 
6
8
  const usage = `gm-plugkit — Bootstrap and daemon-spawn for gm plugkit binary.
7
9
 
8
10
  Usage:
9
11
  bun x gm-plugkit@latest Bootstrap + start spool daemon
10
- bun x gm-plugkit@latest --daemon Same as default
11
- bun x gm-plugkit@latest --binary Print binary path only
12
- bun x gm-plugkit@latest --status JSON status check
13
- bun x gm-plugkit@latest --help Show this help
12
+ bun x gm-plugkit@latest spool Same as default (explicit)
13
+ bun x gm-plugkit@latest --daemon Same as default
14
+ bun x gm-plugkit@latest --binary Print binary path only
15
+ bun x gm-plugkit@latest --status JSON status check
16
+ bun x gm-plugkit@latest --help Show this help
14
17
  `;
15
18
 
19
+ function spoolDir() {
20
+ const projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
21
+ return path.join(projectDir, '.gm', 'exec-spool');
22
+ }
23
+
24
+ function ensureSpoolDir() {
25
+ try { fs.mkdirSync(spoolDir(), { recursive: true }); } catch (_) {}
26
+ }
27
+
28
+ function writeCliStatus(spec) {
29
+ try {
30
+ ensureSpoolDir();
31
+ fs.writeFileSync(
32
+ path.join(spoolDir(), '.cli-status.json'),
33
+ JSON.stringify({ ts: new Date().toISOString(), pid: process.pid, ...spec }, null, 2)
34
+ );
35
+ } catch (_) {}
36
+ }
37
+
38
+ function writeCliError(phase, err) {
39
+ try {
40
+ ensureSpoolDir();
41
+ const msg = err && err.message ? err.message : String(err);
42
+ const stack = err && err.stack ? err.stack : null;
43
+ fs.writeFileSync(
44
+ path.join(spoolDir(), '.bootstrap-error.json'),
45
+ JSON.stringify({ ts: new Date().toISOString(), pid: process.pid, error_phase: phase, error_message: msg, stack }, null, 2)
46
+ );
47
+ } catch (_) {}
48
+ }
49
+
16
50
  (async () => {
17
51
  const args = process.argv.slice(2);
18
52
 
@@ -21,28 +55,54 @@ Usage:
21
55
  process.exit(0);
22
56
  }
23
57
 
58
+ ensureSpoolDir();
59
+ writeCliStatus({ phase: 'starting', args });
60
+
61
+ let bootstrapResult;
24
62
  try {
25
- const result = await ensureReady();
26
- if (!result.ok) {
27
- console.error('Bootstrap failed:', result.error);
28
- process.exit(1);
29
- }
30
-
31
- const daemon = startSpoolDaemon();
32
- if (!daemon.ok) {
33
- console.error('Daemon start failed:', daemon.error);
34
- process.exit(1);
35
- }
36
-
37
- console.log(JSON.stringify({
38
- ok: true,
39
- binary: result.binaryPath,
40
- daemon: daemon,
41
- message: 'plugkit ready, spool watcher running'
42
- }));
43
- process.exit(0);
63
+ bootstrapResult = await ensureReady();
64
+ } catch (err) {
65
+ writeCliError('ensure-ready', err);
66
+ console.error('Bootstrap failed:', err.message);
67
+ process.exit(1);
68
+ }
69
+
70
+ if (!bootstrapResult || !bootstrapResult.ok) {
71
+ const errMsg = (bootstrapResult && bootstrapResult.error) || 'ensureReady returned non-ok';
72
+ writeCliError('ensure-ready', new Error(errMsg));
73
+ console.error('Bootstrap failed:', errMsg);
74
+ process.exit(1);
75
+ }
76
+
77
+ writeCliStatus({ phase: 'bootstrapped', version: bootstrapResult.version, binary: bootstrapResult.binaryPath });
78
+
79
+ let daemon;
80
+ try {
81
+ daemon = startSpoolDaemon();
44
82
  } catch (err) {
45
- console.error('gm-plugkit failed:', err.message);
83
+ writeCliError('start-daemon', err);
84
+ console.error('Daemon start failed:', err.message);
46
85
  process.exit(1);
47
86
  }
48
- })();
87
+
88
+ if (!daemon || !daemon.ok) {
89
+ const errMsg = (daemon && daemon.error) || 'startSpoolDaemon returned non-ok';
90
+ writeCliError('start-daemon', new Error(errMsg));
91
+ console.error('Daemon start failed:', errMsg);
92
+ process.exit(1);
93
+ }
94
+
95
+ writeCliStatus({ phase: 'ready', version: bootstrapResult.version, daemon_pid: daemon.pid, log: daemon.logPath });
96
+
97
+ console.log(JSON.stringify({
98
+ ok: true,
99
+ binary: bootstrapResult.binaryPath,
100
+ daemon,
101
+ message: 'plugkit ready, spool watcher running'
102
+ }));
103
+ process.exit(0);
104
+ })().catch((err) => {
105
+ writeCliError('uncaught', err);
106
+ console.error('gm-plugkit failed:', err && err.message ? err.message : err);
107
+ process.exit(1);
108
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-plugkit",
3
- "version": "2.0.1147",
3
+ "version": "2.0.1148",
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": {