Skip to content

Commit 7ebb408

Browse files
committed
feat: auto-install bm CLI on first plugin start
When the plugin starts and bm is not found on PATH: 1. Check if uv is available 2. If yes, run uv tool install basic-memory automatically 3. If uv is missing, log actionable error message This eliminates the manual setup step since openclaw plugins install runs npm with --ignore-scripts (postinstall hooks are blocked).
1 parent 31093cb commit 7ebb408

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from "node:child_process"
12
import type { Server } from "node:http"
23
import type { OpenClawPluginApi } from "openclaw/plugin-sdk"
34
import { BmClient } from "./bm-client.ts"
@@ -89,6 +90,40 @@ export default {
8990
start: async (ctx: { config?: unknown; workspaceDir?: string }) => {
9091
log.info("starting...")
9192

93+
// Auto-install bm CLI if not found
94+
const bmBin = cfg.bmPath || "bm"
95+
try {
96+
execSync(`command -v ${bmBin}`, { stdio: "ignore" })
97+
} catch {
98+
log.info("bm CLI not found on PATH — attempting auto-install...")
99+
try {
100+
execSync("command -v uv", { stdio: "ignore" })
101+
log.info(
102+
"installing basic-memory via uv (this may take a minute)...",
103+
)
104+
const result = execSync(
105+
'uv tool install "basic-memory @ git+https://github.com/basicmachines-co/basic-memory.git@main" --force',
106+
{ encoding: "utf-8", timeout: 120_000, stdio: "pipe" },
107+
)
108+
log.info(`basic-memory installed: ${result.trim().split("\n").pop()}`)
109+
// Verify it worked
110+
try {
111+
execSync(`command -v ${bmBin}`, { stdio: "ignore" })
112+
log.info("bm CLI now available on PATH")
113+
} catch {
114+
log.error(
115+
"bm installed but not found on PATH. You may need to add uv's bin directory to your PATH (typically ~/.local/bin).",
116+
)
117+
}
118+
} catch (uvErr) {
119+
log.error(
120+
"Cannot auto-install basic-memory: uv not found. " +
121+
"Install uv first (brew install uv, or curl -LsSf https://astral.sh/uv/install.sh | sh), " +
122+
"then restart the gateway.",
123+
)
124+
}
125+
}
126+
92127
const workspace = ctx.workspaceDir ?? process.cwd()
93128
const projectPath = resolveProjectPath(cfg.projectPath, workspace)
94129
cfg.projectPath = projectPath

0 commit comments

Comments
 (0)