openclaw-langcache 1.0.1 → 1.1.0

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Postinstall script for @openclaw/langcache
4
- * Copies the skill to the user's OpenClaw workspace
3
+ * Postinstall script for openclaw-langcache
4
+ * Installs the skill to both OpenClaw and Claude Code workspaces
5
5
  */
6
6
 
7
7
  const fs = require('fs');
@@ -10,22 +10,20 @@ const os = require('os');
10
10
 
11
11
  const SKILL_NAME = 'langcache';
12
12
 
13
- // Determine OpenClaw workspace path
14
- function getOpenClawPath() {
15
- // Check OPENCLAW_HOME environment variable first
16
- if (process.env.OPENCLAW_HOME) {
17
- return path.join(process.env.OPENCLAW_HOME, 'workspace', 'skills');
18
- }
19
-
20
- // Default paths by platform
13
+ // Get installation paths
14
+ function getInstallPaths() {
21
15
  const home = os.homedir();
22
16
 
23
- if (process.platform === 'win32') {
24
- return path.join(home, '.openclaw', 'workspace', 'skills');
25
- }
26
-
27
- // macOS and Linux
28
- return path.join(home, '.openclaw', 'workspace', 'skills');
17
+ return {
18
+ openclaw: path.join(
19
+ process.env.OPENCLAW_HOME || path.join(home, '.openclaw'),
20
+ 'workspace', 'skills'
21
+ ),
22
+ claude: path.join(
23
+ process.env.CLAUDE_HOME || path.join(home, '.claude'),
24
+ 'skills'
25
+ )
26
+ };
29
27
  }
30
28
 
31
29
  // Recursively copy directory
@@ -43,59 +41,75 @@ function copyDir(src, dest) {
43
41
  } else {
44
42
  fs.copyFileSync(srcPath, destPath);
45
43
 
46
- // Make shell scripts executable
47
- if (entry.name.endsWith('.sh')) {
44
+ // Make shell scripts and python files executable
45
+ if (entry.name.endsWith('.sh') || entry.name.endsWith('.py')) {
48
46
  fs.chmodSync(destPath, 0o755);
49
47
  }
50
48
  }
51
49
  }
52
50
  }
53
51
 
52
+ function installSkill(name, srcDir, destDir, skillSrcPath) {
53
+ const destPath = path.join(destDir, SKILL_NAME);
54
+
55
+ if (!fs.existsSync(skillSrcPath)) {
56
+ console.log(` ⚠ ${name}: Source not found, skipping`);
57
+ return false;
58
+ }
59
+
60
+ // Create skills directory if needed
61
+ fs.mkdirSync(destDir, { recursive: true });
62
+
63
+ // Check if already exists
64
+ if (fs.existsSync(destPath)) {
65
+ console.log(` ⚠ ${name}: Already exists at ${destPath}`);
66
+ console.log(` To update: rm -rf ${destPath} && npm install openclaw-langcache`);
67
+ return false;
68
+ }
69
+
70
+ // Copy skill
71
+ copyDir(skillSrcPath, destPath);
72
+ console.log(` ✓ ${name}: Installed to ${destPath}`);
73
+ return true;
74
+ }
75
+
54
76
  function main() {
55
- try {
56
- const skillsPath = getOpenClawPath();
57
- const destPath = path.join(skillsPath, SKILL_NAME);
77
+ console.log('\n📦 Installing langcache skill...\n');
58
78
 
59
- // Find the source skill directory
60
- // When installed via npm, we're in node_modules/@openclaw/langcache
79
+ try {
80
+ const paths = getInstallPaths();
61
81
  const packageRoot = path.dirname(__dirname);
62
- const srcPath = path.join(packageRoot, 'skills', SKILL_NAME);
63
82
 
64
- if (!fs.existsSync(srcPath)) {
65
- console.log(`Source skill not found at ${srcPath}, skipping installation`);
66
- return;
67
- }
68
-
69
- // Create skills directory if it doesn't exist
70
- fs.mkdirSync(skillsPath, { recursive: true });
83
+ let installed = 0;
71
84
 
72
- // Check if skill already exists
73
- if (fs.existsSync(destPath)) {
74
- console.log(`Skill '${SKILL_NAME}' already exists at ${destPath}`);
75
- console.log('To update, remove the existing skill and reinstall:');
76
- console.log(` rm -rf ${destPath}`);
77
- console.log(' npm install @openclaw/langcache');
78
- return;
85
+ // Install OpenClaw skill
86
+ const openclawSrc = path.join(packageRoot, 'skills', SKILL_NAME);
87
+ if (installSkill('OpenClaw', 'skills', paths.openclaw, openclawSrc)) {
88
+ installed++;
79
89
  }
80
90
 
81
- // Copy skill to workspace
82
- copyDir(srcPath, destPath);
91
+ // Install Claude Code skill
92
+ const claudeSrc = path.join(packageRoot, 'claude-skills', SKILL_NAME);
93
+ if (installSkill('Claude Code', 'claude-skills', paths.claude, claudeSrc)) {
94
+ installed++;
95
+ }
83
96
 
84
- console.log(`\n✓ Installed '${SKILL_NAME}' skill to ${destPath}\n`);
85
- console.log('Next steps:');
86
- console.log('1. Add your Redis LangCache credentials to ~/.openclaw/secrets.env:');
87
- console.log(' LANGCACHE_HOST=your-instance.redis.cloud');
88
- console.log(' LANGCACHE_CACHE_ID=your-cache-id');
89
- console.log(' LANGCACHE_API_KEY=your-api-key');
90
- console.log('');
91
- console.log('2. The skill will auto-activate when you mention "semantic caching"');
92
- console.log(' or use the CLI: langcache.sh search "your query"');
93
- console.log('');
97
+ if (installed > 0) {
98
+ console.log('\n✅ Installation complete!\n');
99
+ console.log('Next steps:');
100
+ console.log('1. Set your Redis LangCache credentials:');
101
+ console.log(' export LANGCACHE_HOST=your-instance.redis.cloud');
102
+ console.log(' export LANGCACHE_CACHE_ID=your-cache-id');
103
+ console.log(' export LANGCACHE_API_KEY=your-api-key');
104
+ console.log('');
105
+ console.log('2. The skill auto-activates when you mention "semantic caching"');
106
+ console.log(' or invoke manually with /langcache');
107
+ console.log('');
108
+ }
94
109
 
95
110
  } catch (err) {
96
- // Don't fail the npm install if postinstall fails
97
- console.warn(`Warning: Could not install skill to OpenClaw workspace: ${err.message}`);
98
- console.warn('You can manually copy the skill from node_modules/@openclaw/langcache/skills/');
111
+ console.warn(`⚠ Warning: ${err.message}`);
112
+ console.warn('You can manually copy skills from node_modules/openclaw-langcache/');
99
113
  }
100
114
  }
101
115