@memtensor/memos-local-openclaw-plugin 0.3.13 → 0.3.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 +1 -1
- package/scripts/postinstall.cjs +81 -49
package/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -13,16 +13,20 @@ const CYAN = "\x1b[36m";
|
|
|
13
13
|
const BOLD = "\x1b[1m";
|
|
14
14
|
const DIM = "\x1b[2m";
|
|
15
15
|
|
|
16
|
-
function log(msg) { console.log(
|
|
17
|
-
function warn(msg) { console.log(
|
|
18
|
-
function ok(msg) { console.log(
|
|
19
|
-
function fail(msg) { console.log(
|
|
16
|
+
function log(msg) { console.log(` ${CYAN}[memos-local]${RESET} ${msg}`); }
|
|
17
|
+
function warn(msg) { console.log(` ${YELLOW}⚠ [memos-local]${RESET} ${msg}`); }
|
|
18
|
+
function ok(msg) { console.log(` ${GREEN}✔ [memos-local]${RESET} ${msg}`); }
|
|
19
|
+
function fail(msg) { console.log(` ${RED}✖ [memos-local]${RESET} ${msg}`); }
|
|
20
|
+
|
|
21
|
+
function phase(n, title) {
|
|
22
|
+
console.log(`\n${CYAN}${BOLD} ─── Phase ${n}: ${title} ───${RESET}\n`);
|
|
23
|
+
}
|
|
20
24
|
|
|
21
25
|
const pluginDir = path.resolve(__dirname, "..");
|
|
22
26
|
|
|
23
27
|
console.log(`
|
|
24
28
|
${CYAN}${BOLD}┌──────────────────────────────────────────────────┐
|
|
25
|
-
│ MemOS Local Memory — postinstall
|
|
29
|
+
│ MemOS Local Memory — postinstall setup │
|
|
26
30
|
└──────────────────────────────────────────────────┘${RESET}
|
|
27
31
|
`);
|
|
28
32
|
|
|
@@ -34,37 +38,43 @@ log(`Node: ${process.version} Platform: ${process.platform}-${process.arch}`);
|
|
|
34
38
|
* ═══════════════════════════════════════════════════════════ */
|
|
35
39
|
|
|
36
40
|
function ensureDependencies() {
|
|
41
|
+
phase(0, "检测核心依赖 / Check core dependencies");
|
|
42
|
+
|
|
37
43
|
const coreDeps = ["@sinclair/typebox", "uuid", "posthog-node", "@huggingface/transformers"];
|
|
38
44
|
const missing = [];
|
|
39
45
|
for (const dep of coreDeps) {
|
|
40
46
|
try {
|
|
41
47
|
require.resolve(dep, { paths: [pluginDir] });
|
|
48
|
+
log(` ${dep} ${GREEN}✔${RESET}`);
|
|
42
49
|
} catch {
|
|
43
50
|
missing.push(dep);
|
|
51
|
+
log(` ${dep} ${RED}✖ missing${RESET}`);
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
if (missing.length === 0) {
|
|
48
|
-
ok("All dependencies present.");
|
|
56
|
+
ok("All core dependencies present.");
|
|
49
57
|
return;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
warn(`Missing dependencies: ${missing.join(", ")}`);
|
|
53
|
-
log("Running: npm install --omit=dev
|
|
60
|
+
warn(`Missing ${missing.length} dependencies: ${BOLD}${missing.join(", ")}${RESET}`);
|
|
61
|
+
log("Running: npm install --omit=dev ...");
|
|
54
62
|
|
|
55
63
|
const startMs = Date.now();
|
|
56
64
|
const result = spawnSync("npm", ["install", "--omit=dev"], {
|
|
57
65
|
cwd: pluginDir,
|
|
58
|
-
stdio: "
|
|
66
|
+
stdio: "pipe",
|
|
59
67
|
shell: true,
|
|
60
68
|
timeout: 120_000,
|
|
61
69
|
});
|
|
62
70
|
const elapsed = ((Date.now() - startMs) / 1000).toFixed(1);
|
|
71
|
+
const stderr = (result.stderr || "").toString().trim();
|
|
63
72
|
|
|
64
73
|
if (result.status === 0) {
|
|
65
|
-
ok(`Dependencies installed (${elapsed}s).`);
|
|
74
|
+
ok(`Dependencies installed successfully (${elapsed}s).`);
|
|
66
75
|
} else {
|
|
67
76
|
fail(`npm install exited with code ${result.status} (${elapsed}s).`);
|
|
77
|
+
if (stderr) warn(`stderr: ${stderr.slice(0, 300)}`);
|
|
68
78
|
warn("Some features may not work. Try running manually:");
|
|
69
79
|
warn(` cd ${pluginDir} && npm install --omit=dev`);
|
|
70
80
|
}
|
|
@@ -73,7 +83,7 @@ function ensureDependencies() {
|
|
|
73
83
|
try {
|
|
74
84
|
ensureDependencies();
|
|
75
85
|
} catch (e) {
|
|
76
|
-
warn(`Dependency check
|
|
86
|
+
warn(`Dependency check error: ${e.message}`);
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
/* ═══════════════════════════════════════════════════════════
|
|
@@ -81,15 +91,15 @@ try {
|
|
|
81
91
|
* ═══════════════════════════════════════════════════════════ */
|
|
82
92
|
|
|
83
93
|
function cleanupLegacy() {
|
|
94
|
+
phase(1, "清理旧版本插件 / Clean up legacy plugins");
|
|
95
|
+
|
|
84
96
|
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
85
|
-
if (!home) return;
|
|
97
|
+
if (!home) { log("Cannot determine HOME directory, skipping."); return; }
|
|
86
98
|
const ocHome = path.join(home, ".openclaw");
|
|
87
|
-
if (!fs.existsSync(ocHome)) return;
|
|
99
|
+
if (!fs.existsSync(ocHome)) { log("No ~/.openclaw directory found, skipping."); return; }
|
|
88
100
|
|
|
89
101
|
const extDir = path.join(ocHome, "extensions");
|
|
90
|
-
if (!fs.existsSync(extDir)) return;
|
|
91
|
-
|
|
92
|
-
log("Checking for legacy plugin versions...");
|
|
102
|
+
if (!fs.existsSync(extDir)) { log("No extensions directory found, skipping."); return; }
|
|
93
103
|
|
|
94
104
|
const legacyDirs = [
|
|
95
105
|
path.join(extDir, "memos-lite"),
|
|
@@ -102,7 +112,7 @@ function cleanupLegacy() {
|
|
|
102
112
|
if (fs.existsSync(dir)) {
|
|
103
113
|
try {
|
|
104
114
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
105
|
-
ok(`Removed legacy
|
|
115
|
+
ok(`Removed legacy dir: ${DIM}${dir}${RESET}`);
|
|
106
116
|
cleaned++;
|
|
107
117
|
} catch (e) {
|
|
108
118
|
warn(`Could not remove ${dir}: ${e.message}`);
|
|
@@ -125,11 +135,11 @@ function cleanupLegacy() {
|
|
|
125
135
|
const oldEntry = entries[oldKey];
|
|
126
136
|
if (!entries["memos-local-openclaw-plugin"]) {
|
|
127
137
|
entries["memos-local-openclaw-plugin"] = oldEntry;
|
|
128
|
-
log(`Migrated config: ${DIM}${oldKey}${RESET}
|
|
138
|
+
log(`Migrated config: ${DIM}${oldKey}${RESET} → ${GREEN}memos-local-openclaw-plugin${RESET}`);
|
|
129
139
|
}
|
|
130
140
|
delete entries[oldKey];
|
|
131
141
|
cfgChanged = true;
|
|
132
|
-
ok(`Removed legacy config
|
|
142
|
+
ok(`Removed legacy config key: ${DIM}${oldKey}${RESET}`);
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
|
|
@@ -141,7 +151,7 @@ function cleanupLegacy() {
|
|
|
141
151
|
.replace(/memos-lite-openclaw-plugin/g, "memos-local-openclaw-plugin")
|
|
142
152
|
.replace(/memos-lite/g, "memos-local");
|
|
143
153
|
if (newEntry.source !== oldSource) {
|
|
144
|
-
log(`Updated source path: ${DIM}${oldSource}${RESET}
|
|
154
|
+
log(`Updated source path: ${DIM}${oldSource}${RESET} → ${GREEN}${newEntry.source}${RESET}`);
|
|
145
155
|
cfgChanged = true;
|
|
146
156
|
}
|
|
147
157
|
}
|
|
@@ -152,6 +162,8 @@ function cleanupLegacy() {
|
|
|
152
162
|
fs.copyFileSync(cfgPath, backup);
|
|
153
163
|
fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
154
164
|
ok(`Config updated. Backup: ${DIM}${backup}${RESET}`);
|
|
165
|
+
} else {
|
|
166
|
+
log("No legacy config entries found.");
|
|
155
167
|
}
|
|
156
168
|
}
|
|
157
169
|
} catch (e) {
|
|
@@ -160,78 +172,98 @@ function cleanupLegacy() {
|
|
|
160
172
|
}
|
|
161
173
|
|
|
162
174
|
if (cleaned > 0) {
|
|
163
|
-
ok(`Legacy cleanup
|
|
175
|
+
ok(`Legacy cleanup done: ${cleaned} old dir(s) removed.`);
|
|
164
176
|
} else {
|
|
165
|
-
|
|
177
|
+
ok("No legacy plugin directories found. Clean.");
|
|
166
178
|
}
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
try {
|
|
170
182
|
cleanupLegacy();
|
|
171
183
|
} catch (e) {
|
|
172
|
-
warn(`Legacy cleanup
|
|
184
|
+
warn(`Legacy cleanup error: ${e.message}`);
|
|
173
185
|
}
|
|
174
186
|
|
|
175
187
|
/* ═══════════════════════════════════════════════════════════
|
|
176
188
|
* Phase 2: Verify better-sqlite3 native module
|
|
177
189
|
* ═══════════════════════════════════════════════════════════ */
|
|
178
190
|
|
|
179
|
-
|
|
191
|
+
phase(2, "检查 better-sqlite3 原生模块 / Check native module");
|
|
180
192
|
|
|
181
193
|
try {
|
|
182
194
|
require("better-sqlite3");
|
|
183
195
|
ok("better-sqlite3 is ready.");
|
|
184
|
-
console.log(
|
|
196
|
+
console.log(`
|
|
197
|
+
${GREEN}${BOLD} ┌──────────────────────────────────────────────────┐
|
|
198
|
+
│ ✔ Setup complete! │
|
|
199
|
+
│ │
|
|
200
|
+
│ Restart gateway: │
|
|
201
|
+
│ ${CYAN}openclaw gateway stop && openclaw gateway start${GREEN} │
|
|
202
|
+
└──────────────────────────────────────────────────┘${RESET}
|
|
203
|
+
`);
|
|
185
204
|
process.exit(0);
|
|
186
205
|
} catch (_) {
|
|
187
|
-
warn("better-sqlite3 native bindings not found
|
|
206
|
+
warn("better-sqlite3 native bindings not found.");
|
|
207
|
+
log("Running: npm rebuild better-sqlite3 (may take 30-60s)...");
|
|
188
208
|
}
|
|
189
209
|
|
|
190
|
-
log("Running: npm rebuild better-sqlite3 (this may take 30-60 seconds)...");
|
|
191
|
-
|
|
192
210
|
const startMs = Date.now();
|
|
193
211
|
|
|
194
212
|
const result = spawnSync("npm", ["rebuild", "better-sqlite3"], {
|
|
195
213
|
cwd: pluginDir,
|
|
196
|
-
stdio: "
|
|
214
|
+
stdio: "pipe",
|
|
197
215
|
shell: true,
|
|
198
216
|
timeout: 180_000,
|
|
199
217
|
});
|
|
200
218
|
|
|
201
219
|
const elapsed = ((Date.now() - startMs) / 1000).toFixed(1);
|
|
220
|
+
const stdout = (result.stdout || "").toString().trim();
|
|
221
|
+
const stderr = (result.stderr || "").toString().trim();
|
|
222
|
+
|
|
223
|
+
if (stdout) log(`rebuild output: ${DIM}${stdout.slice(0, 500)}${RESET}`);
|
|
224
|
+
if (stderr) warn(`rebuild stderr: ${DIM}${stderr.slice(0, 500)}${RESET}`);
|
|
202
225
|
|
|
203
226
|
if (result.status === 0) {
|
|
204
227
|
try {
|
|
205
228
|
delete require.cache[require.resolve("better-sqlite3")];
|
|
206
229
|
require("better-sqlite3");
|
|
207
230
|
ok(`better-sqlite3 rebuilt successfully (${elapsed}s).`);
|
|
208
|
-
console.log(
|
|
231
|
+
console.log(`
|
|
232
|
+
${GREEN}${BOLD} ┌──────────────────────────────────────────────────┐
|
|
233
|
+
│ ✔ Setup complete! │
|
|
234
|
+
│ │
|
|
235
|
+
│ Restart gateway: │
|
|
236
|
+
│ ${CYAN}openclaw gateway stop && openclaw gateway start${GREEN} │
|
|
237
|
+
└──────────────────────────────────────────────────┘${RESET}
|
|
238
|
+
`);
|
|
209
239
|
process.exit(0);
|
|
210
|
-
} catch (
|
|
211
|
-
fail(`Rebuild completed but module still
|
|
240
|
+
} catch (retryErr) {
|
|
241
|
+
fail(`Rebuild completed but module still fails (${elapsed}s): ${retryErr.message}`);
|
|
212
242
|
}
|
|
213
243
|
} else {
|
|
214
244
|
fail(`Rebuild failed with exit code ${result.status} (${elapsed}s).`);
|
|
215
245
|
}
|
|
216
246
|
|
|
217
247
|
console.log(`
|
|
218
|
-
${YELLOW}${BOLD}╔══════════════════════════════════════════════════════════════╗
|
|
219
|
-
║ better-sqlite3 native module build failed
|
|
220
|
-
╠══════════════════════════════════════════════════════════════╣${RESET}
|
|
221
|
-
${YELLOW}║${RESET}
|
|
222
|
-
${YELLOW}║${RESET}
|
|
223
|
-
${YELLOW}║${RESET}
|
|
224
|
-
${YELLOW}║${RESET}
|
|
225
|
-
${YELLOW}║${RESET}
|
|
226
|
-
${YELLOW}║${RESET}
|
|
227
|
-
${YELLOW}║${RESET} ${CYAN}
|
|
228
|
-
${YELLOW}║${RESET} ${CYAN}
|
|
229
|
-
${YELLOW}║${RESET}
|
|
230
|
-
${YELLOW}║${RESET}
|
|
231
|
-
${YELLOW}║${RESET} ${
|
|
232
|
-
${YELLOW}║${RESET} ${GREEN}
|
|
233
|
-
${YELLOW}║${RESET} ${GREEN}
|
|
234
|
-
${YELLOW}${
|
|
248
|
+
${YELLOW}${BOLD} ╔══════════════════════════════════════════════════════════════╗
|
|
249
|
+
║ ✖ better-sqlite3 native module build failed ║
|
|
250
|
+
╠══════════════════════════════════════════════════════════════╣${RESET}
|
|
251
|
+
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
252
|
+
${YELLOW} ║${RESET} This plugin requires C/C++ build tools to compile ${YELLOW}║${RESET}
|
|
253
|
+
${YELLOW} ║${RESET} the SQLite native module on first install. ${YELLOW}║${RESET}
|
|
254
|
+
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
255
|
+
${YELLOW} ║${RESET} ${BOLD}Install build tools:${RESET} ${YELLOW}║${RESET}
|
|
256
|
+
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
257
|
+
${YELLOW} ║${RESET} ${CYAN}macOS:${RESET} xcode-select --install ${YELLOW}║${RESET}
|
|
258
|
+
${YELLOW} ║${RESET} ${CYAN}Ubuntu:${RESET} sudo apt install build-essential python3 ${YELLOW}║${RESET}
|
|
259
|
+
${YELLOW} ║${RESET} ${CYAN}Windows:${RESET} npm install -g windows-build-tools ${YELLOW}║${RESET}
|
|
260
|
+
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
261
|
+
${YELLOW} ║${RESET} ${BOLD}Then retry:${RESET} ${YELLOW}║${RESET}
|
|
262
|
+
${YELLOW} ║${RESET} ${GREEN}cd ${pluginDir}${RESET}
|
|
263
|
+
${YELLOW} ║${RESET} ${GREEN}npm rebuild better-sqlite3${RESET} ${YELLOW}║${RESET}
|
|
264
|
+
${YELLOW} ║${RESET} ${GREEN}openclaw gateway stop && openclaw gateway start${RESET} ${YELLOW}║${RESET}
|
|
265
|
+
${YELLOW} ║${RESET} ${YELLOW}║${RESET}
|
|
266
|
+
${YELLOW}${BOLD} ╚══════════════════════════════════════════════════════════════╝${RESET}
|
|
235
267
|
`);
|
|
236
268
|
|
|
237
269
|
process.exit(0);
|