|
| 1 | +import { execSync } from "node:child_process" |
1 | 2 | import type { Server } from "node:http" |
2 | 3 | import type { OpenClawPluginApi } from "openclaw/plugin-sdk" |
3 | 4 | import { BmClient } from "./bm-client.ts" |
@@ -89,6 +90,40 @@ export default { |
89 | 90 | start: async (ctx: { config?: unknown; workspaceDir?: string }) => { |
90 | 91 | log.info("starting...") |
91 | 92 |
|
| 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 | + |
92 | 127 | const workspace = ctx.workspaceDir ?? process.cwd() |
93 | 128 | const projectPath = resolveProjectPath(cfg.projectPath, workspace) |
94 | 129 | cfg.projectPath = projectPath |
|
0 commit comments