claw-subagent-service 0.0.22 → 0.0.23

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.22",
3
+ "version": "0.0.23",
4
4
  "description": "虾说静态服务",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -1,8 +1,39 @@
1
1
  const { exec } = require('child_process');
2
2
  const { promisify } = require('util');
3
+ const os = require('os');
4
+ const fs = require('fs');
5
+ const path = require('path');
3
6
 
4
7
  const execAsync = promisify(exec);
5
8
 
9
+ /**
10
+ * 获取实际用户主目录(SYSTEM 账户下 os.homedir() 返回 systemprofile)
11
+ */
12
+ function getRealHomeDir() {
13
+ const envHome = process.env.CLAW_SERVICE_HOME || process.env.USERPROFILE || process.env.HOME;
14
+ if (envHome && !envHome.includes('systemprofile')) {
15
+ return envHome;
16
+ }
17
+ const homeDir = os.homedir();
18
+ if (!homeDir.includes('systemprofile')) {
19
+ return homeDir;
20
+ }
21
+ // SYSTEM 账户兜底:扫描 C:\Users 找包含 .openclaw 的实际用户目录
22
+ const usersDir = 'C:\\Users';
23
+ if (fs.existsSync(usersDir)) {
24
+ const entries = fs.readdirSync(usersDir, { withFileTypes: true });
25
+ for (const entry of entries) {
26
+ if (entry.isDirectory() && !['Public', 'Default', 'All Users', 'Default User'].includes(entry.name)) {
27
+ const candidate = path.join(usersDir, entry.name);
28
+ if (fs.existsSync(path.join(candidate, '.openclaw'))) {
29
+ return candidate;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ return homeDir;
35
+ }
36
+
6
37
  class OpenClawClient {
7
38
  constructor(log) {
8
39
  this.log = log;
@@ -29,6 +60,10 @@ class OpenClawClient {
29
60
  this.log?.info(`[OpenClawClient] 执行命令: ${cmd}`);
30
61
  this.log?.info(`[OpenClawClient] Gateway URL: ${gatewayUrl}`);
31
62
 
63
+ // 注入实际用户目录,确保 openclaw CLI 能读取到正确的配置和 API key
64
+ const realHome = getRealHomeDir();
65
+ this.log?.info(`[OpenClawClient] 使用用户目录: ${realHome}`);
66
+
32
67
  try {
33
68
  const { stdout, stderr } = await execAsync(cmd, {
34
69
  timeout: 1200000,
@@ -38,6 +73,8 @@ class OpenClawClient {
38
73
  env: {
39
74
  ...process.env,
40
75
  OPENCLAW_GATEWAY_URL: gatewayUrl,
76
+ USERPROFILE: realHome,
77
+ HOME: realHome,
41
78
  },
42
79
  });
43
80