claw-subagent-service 0.0.13 → 0.0.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "虾说静态服务",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -4,16 +4,31 @@
4
4
  */
5
5
  const { exec, execFile, execSync } = require('child_process');
6
6
  const path = require('path');
7
- const fs = require('fs');
8
7
 
9
8
  const SERVICE_NAME = 'claw-subagent-service';
10
9
  const DAEMON_PATH = path.join(__dirname, '..', 'service', 'daemon.js');
11
10
 
12
11
  function isGlobalInstall() {
13
- // 判断是否为全局安装:检查是否在 npm 全局目录下
14
- const cwd = process.cwd();
15
- const globalPrefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
16
- return cwd.includes(globalPrefix) || __dirname.includes(globalPrefix);
12
+ // 方法1: npm 全局安装时会设置此环境变量
13
+ if (process.env.npm_config_global === 'true') {
14
+ console.log('[postinstall] 通过 npm_config_global 检测到全局安装');
15
+ return true;
16
+ }
17
+
18
+ // 方法2: 检查包路径是否在全局 node_modules 下
19
+ try {
20
+ const globalPrefix = execSync('npm prefix -g', { encoding: 'utf8', timeout: 5000 }).trim();
21
+ const globalModules = path.join(globalPrefix, 'node_modules');
22
+ const pkgPath = path.join(__dirname, '..');
23
+ const normalizedPkg = path.normalize(pkgPath).toLowerCase();
24
+ const normalizedGlobal = path.normalize(globalModules).toLowerCase();
25
+ const isGlobal = normalizedPkg.startsWith(normalizedGlobal);
26
+ console.log(`[postinstall] 全局安装检测: pkgPath=${normalizedPkg}, globalModules=${normalizedGlobal}, result=${isGlobal}`);
27
+ return isGlobal;
28
+ } catch (e) {
29
+ console.log(`[postinstall] 全局安装检测失败(${e.message}),默认按全局安装处理`);
30
+ return true;
31
+ }
17
32
  }
18
33
 
19
34
  function isWindowsAdmin() {
@@ -46,7 +61,7 @@ function installAndStartService() {
46
61
  try { execSync(`net stop "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
47
62
  try { execSync(`sc delete "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
48
63
 
49
- // 使用 execFile 直接传参数数组,避免 cmd 引号解析问题(execPath 可能含空格如 C:\Program Files)
64
+ // 使用 execFile 直接传参数数组,避免 cmd 引号解析问题
50
65
  execFile('sc.exe', [
51
66
  'create', SERVICE_NAME,
52
67
  'binPath=', binPath,
@@ -76,6 +91,12 @@ function installAndStartService() {
76
91
  }
77
92
 
78
93
  // 主逻辑
94
+ console.log('[postinstall] 脚本开始执行...');
95
+ console.log(`[postinstall] __dirname=${__dirname}`);
96
+ console.log(`[postinstall] cwd=${process.cwd()}`);
97
+ console.log(`[postinstall] npm_config_global=${process.env.npm_config_global}`);
98
+ console.log(`[postinstall] npm_config_prefix=${process.env.npm_config_prefix}`);
99
+
79
100
  if (isGlobalInstall()) {
80
101
  console.log('[postinstall] 检测到全局安装,准备自动注册服务...');
81
102
  installAndStartService();
package/version.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.0.0",
3
- "updatedAt": "2026-04-20T00:00:00.000Z"
2
+ "version": "0.0.14",
3
+ "updatedAt": "2026-04-30T05:50:00.000Z"
4
4
  }