@aiyiran/myclaw 1.0.90 → 1.0.91

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/package.json +1 -1
  2. package/patch-skill.js +30 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.90",
3
+ "version": "1.0.91",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/patch-skill.js CHANGED
@@ -20,45 +20,43 @@ const path = require('path');
20
20
 
21
21
  /**
22
22
  * 探测 OpenClaw 的 skills 目录
23
+ * 优先使用 ~/.openclaw/skills/(标准路径),不存在则自动创建
23
24
  */
24
25
  function findSkillsDir() {
25
- const candidates = [];
26
-
27
- // 全局 node_modules 路径
28
- const globalPaths = [
29
- '/usr/lib/node_modules',
30
- '/usr/local/lib/node_modules',
31
- ];
32
-
33
- try {
34
- const { execSync } = require('child_process');
35
- const prefix = execSync('npm config get prefix 2>/dev/null', { encoding: 'utf8' }).trim();
36
- if (prefix) {
37
- globalPaths.push(path.join(prefix, 'lib', 'node_modules'));
38
- }
39
- } catch {}
26
+ const os = require('os');
27
+
28
+ // 候选根目录(跟 find-config.js 一致的查找逻辑)
29
+ const openclawRoots = [];
40
30
 
41
- for (const globalPath of globalPaths) {
42
- candidates.push(path.join(globalPath, 'openclaw', 'skills'));
31
+ // 1. 环境变量优先
32
+ if (process.env.OPENCLAW_HOME) {
33
+ openclawRoots.push(process.env.OPENCLAW_HOME);
43
34
  }
44
35
 
45
- // 通过 which openclaw 推断
46
- try {
47
- const { execSync } = require('child_process');
48
- const bin = execSync('which openclaw 2>/dev/null', { encoding: 'utf8' }).trim();
49
- if (bin) {
50
- const real = fs.realpathSync(bin);
51
- const pkgRoot = path.dirname(real);
52
- candidates.push(path.join(pkgRoot, 'skills'));
53
- candidates.push(path.join(path.dirname(pkgRoot), 'skills'));
54
- }
55
- } catch {}
36
+ // 2. 标准路径 ~/.openclaw/
37
+ openclawRoots.push(path.join(os.homedir(), '.openclaw'));
38
+
39
+ // 3. WSL /root/.openclaw/
40
+ if (os.platform() === 'linux') {
41
+ openclawRoots.push(path.join('/root', '.openclaw'));
42
+ }
56
43
 
57
- // 找到第一个存在的
58
- for (const dir of candidates) {
44
+ // 找到第一个存在的 .openclaw 根目录
45
+ for (const root of openclawRoots) {
59
46
  try {
60
- if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
61
- return dir;
47
+ if (fs.existsSync(root) && fs.statSync(root).isDirectory()) {
48
+ const skillsDir = path.join(root, 'skills');
49
+ // 如果 skills 目录不存在,试探性创建
50
+ if (!fs.existsSync(skillsDir)) {
51
+ try {
52
+ fs.mkdirSync(skillsDir, { recursive: true });
53
+ console.log('[myclaw-skill] 📁 已创建 skills 目录: ' + skillsDir);
54
+ } catch (err) {
55
+ console.log('[myclaw-skill] ⚠️ 无法创建 skills 目录: ' + err.message);
56
+ continue;
57
+ }
58
+ }
59
+ return skillsDir;
62
60
  }
63
61
  } catch {}
64
62
  }