mycohive-claw 4.0.4 → 4.0.5
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 +1 -1
- package/scripts/postinstall.cjs +60 -8
package/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* postinstall.cjs
|
|
3
|
-
* Version: 4.0.
|
|
3
|
+
* Version: 4.0.5
|
|
4
4
|
*
|
|
5
5
|
* Auto-register plugin after npm install.
|
|
6
6
|
* No manual configuration needed.
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
const fs = require("fs");
|
|
10
10
|
const path = require("path");
|
|
11
|
-
const { execSync } = require("child_process");
|
|
12
11
|
|
|
13
12
|
// Find OpenClaw config - it uses JSON format at ~/.openclaw/openclaw.json
|
|
14
13
|
function findOpenClawConfig() {
|
|
@@ -25,17 +24,69 @@ function findOpenClawConfig() {
|
|
|
25
24
|
return null;
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
function copyPluginToExtensions(packageDir, pluginId) {
|
|
28
|
+
const extensionsDir = path.join(process.env.HOME || ".", ".openclaw", "extensions");
|
|
29
|
+
const destDir = path.join(extensionsDir, pluginId);
|
|
30
|
+
|
|
31
|
+
// If already installed in extensions, skip
|
|
32
|
+
if (fs.existsSync(destDir)) {
|
|
33
|
+
console.log(`[MycoHive-Claw] Plugin already installed in extensions: ${destDir}`);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Ensure extensions dir exists
|
|
38
|
+
if (!fs.existsSync(extensionsDir)) {
|
|
39
|
+
try {
|
|
40
|
+
fs.mkdirSync(extensionsDir, { recursive: true });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(`[MycoHive-Claw] Cannot create extensions dir ${extensionsDir}: ${err.message}`);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Copy plugin to extensions dir
|
|
48
|
+
try {
|
|
49
|
+
copyDirRecursive(packageDir, destDir);
|
|
50
|
+
console.log(`[MycoHive-Claw] Copied plugin to: ${destDir}`);
|
|
51
|
+
return true;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error(`[MycoHive-Claw] Failed to copy plugin to extensions: ${err.message}`);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function copyDirRecursive(src, dest) {
|
|
59
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
60
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
const srcPath = path.join(src, entry.name);
|
|
63
|
+
const destPath = path.join(dest, entry.name);
|
|
64
|
+
// Skip node_modules, .git, dist from being copied
|
|
65
|
+
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === "dist") continue;
|
|
66
|
+
if (entry.isDirectory()) {
|
|
67
|
+
copyDirRecursive(srcPath, destPath);
|
|
68
|
+
} else {
|
|
69
|
+
fs.copyFileSync(srcPath, destPath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
28
74
|
function main() {
|
|
29
75
|
console.log("[MycoHive-Claw] postinstall running...");
|
|
30
76
|
|
|
31
77
|
const packageDir = path.resolve(__dirname, "..");
|
|
32
|
-
const
|
|
78
|
+
const pluginId = "mycohive";
|
|
33
79
|
|
|
80
|
+
// Check dist exists
|
|
81
|
+
const distIndex = path.join(packageDir, "dist", "index.js");
|
|
34
82
|
if (!fs.existsSync(distIndex)) {
|
|
35
83
|
console.warn("[MycoHive-Claw] dist/index.js not found, skipping");
|
|
36
84
|
return;
|
|
37
85
|
}
|
|
38
86
|
|
|
87
|
+
// Copy plugin to extensions directory
|
|
88
|
+
copyPluginToExtensions(packageDir, pluginId);
|
|
89
|
+
|
|
39
90
|
// Find config
|
|
40
91
|
let configPath = findOpenClawConfig();
|
|
41
92
|
|
|
@@ -70,15 +121,16 @@ function main() {
|
|
|
70
121
|
if (!config.plugins.entries) config.plugins.entries = {};
|
|
71
122
|
if (!config.plugins.allow) config.plugins.allow = [];
|
|
72
123
|
|
|
73
|
-
// Register plugin
|
|
124
|
+
// Register plugin - use the extensions path
|
|
125
|
+
const extensionsPath = path.join(openclawDir, "extensions", pluginId);
|
|
74
126
|
config.plugins.entries.mycohive = {
|
|
75
|
-
path:
|
|
127
|
+
path: extensionsPath,
|
|
76
128
|
enabled: true,
|
|
77
129
|
};
|
|
78
130
|
|
|
79
|
-
// Add "
|
|
80
|
-
if (!config.plugins.allow.includes("
|
|
81
|
-
config.plugins.allow.push("
|
|
131
|
+
// Add plugin ID "mycohive" to allow list (NOT "restart" - that's a CLI command, not a plugin ID)
|
|
132
|
+
if (!config.plugins.allow.includes("mycohive")) {
|
|
133
|
+
config.plugins.allow.push("mycohive");
|
|
82
134
|
}
|
|
83
135
|
|
|
84
136
|
try {
|