Skip to content

BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.

feat(tui): added direct plugin installation with brainapi plugins install <plugin-name>

Christian6ebe8165701b
diff --git a/README.md b/README.md
index ec2ddd2..84e7c0f 100644
--- a/README.md
+++ b/README.md
@@ -265,11 +265,11 @@ A plugin can:
### Install & publish
```sh
-poetry run brainapi install @community/crm-entities
-poetry run brainapi list --remote
+poetry run brainapi plugins install @community/crm-entities
+poetry run brainapi plugins list --remote
-poetry run brainapi register # become a publisher
-poetry run brainapi publish ./my-plugin.tar.gz
+poetry run brainapi plugins register # become a publisher
+poetry run brainapi plugins publish ./my-plugin.tar.gz
```
Browse and publish at the [Plugin Registry →](https://registry.brain-api.dev/app)
diff --git a/entrypoint.sh b/entrypoint.sh
index 2078175..ea25190 100644
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -16,7 +16,7 @@ if [ -n "$BRAINAPI_PLUGINS" ]; then
version="${plugin_spec##*:}"
[ "$name" = "$version" ] && version="latest"
echo "[brainapi] Installing plugin: $name v$version"
- gosu appuser /app/.venv/bin/python -m src.core.plugins.cli install "$name" --version "$version" || echo "[brainapi] WARNING: Failed to install plugin '$name'"
+ gosu appuser /app/.venv/bin/python -m src.core.plugins.cli plugins install "$name" --version "$version" || echo "[brainapi] WARNING: Failed to install plugin '$name'"
done
fi
diff --git a/src/core/plugins/cli.py b/src/core/plugins/cli.py
index 740bd73..00fd57a 100644
--- a/src/core/plugins/cli.py
+++ b/src/core/plugins/cli.py
@@ -4,7 +4,9 @@ from typing import Optional
import typer
-app = typer.Typer(name="plugins", help="BrainAPI plugin management")
+plugins_app = typer.Typer(name="plugins", help="BrainAPI plugin management")
+app = typer.Typer(name="brainapi", help="BrainAPI CLI", no_args_is_help=True)
+app.add_typer(plugins_app, name="plugins")
PLUGINS_DIR = Path(os.getenv("PLUGINS_DIR", "plugins"))
REGISTRY_URL = os.getenv("PLUGIN_REGISTRY_URL", "https://registry.brain-api.dev")
@@ -23,7 +25,7 @@ def _get_manager():
)
+@plugins_app.command()
def install(
name: str = typer.Argument(..., help="Plugin name to install"),
version: str = typer.Option("latest", "--version", "-v", help="Plugin version"),
@@ -37,7 +39,7 @@ def install(
raise typer.Exit(code=1)
+@plugins_app.command()
def uninstall(
name: str = typer.Argument(..., help="Plugin name to uninstall"),
):
@@ -49,7 +51,7 @@ def uninstall(
raise typer.Exit(code=1)
[email protected](name="list")
+@plugins_app.command(name="list")
def list_plugins(
remote: bool = typer.Option(False, "--remote", "-r", help="List available plugins from registry"),
):
@@ -76,7 +78,7 @@ def list_plugins(
typer.echo(f" {p.name} v{p.version} - {p.description}")
+@plugins_app.command()
def info(
name: str = typer.Argument(..., help="Plugin name to get info for"),
):
@@ -94,7 +96,7 @@ def info(
raise typer.Exit(code=1)
+@plugins_app.command()
def update(
name: str = typer.Argument(..., help="Plugin name to update"),
):
@@ -107,7 +109,7 @@ def update(
raise typer.Exit(code=1)
+@plugins_app.command()
def publish(
archive: Path = typer.Argument(..., help="Path to plugin archive (.tar.gz)"),
name: Optional[str] = typer.Option(None, "--name", "-n", help="Plugin name override"),
@@ -122,7 +124,7 @@ def publish(
raise typer.Exit(code=1)
+@plugins_app.command()
def depublish(
name: str = typer.Argument(..., help="Plugin name to remove from registry"),
version: Optional[str] = typer.Option(None, "--version", "-v", help="Specific version to remove (omit to remove all)"),
@@ -137,7 +139,7 @@ def depublish(
raise typer.Exit(code=1)
+@plugins_app.command()
def register(
publisher_id: Optional[str] = typer.Option(None, "--id", help="Desired publisher ID (auto-generated if omitted)"),
):
diff --git a/tui/README.md b/tui/README.md
index edef895..6d1af3b 100644
--- a/tui/README.md
+++ b/tui/README.md
@@ -27,6 +27,9 @@ brainapi doctor # check Python, Docker, Ollama, and configured services
| `brainapi config` | Re-run the interactive flow and rewrite `.env`. |
| `brainapi doctor` | Check that Python, Docker, Ollama, GCP credentials, and configured services are reachable. |
| `brainapi update` | `git pull` the project and `pip install -e .` again. |
+| `brainapi plugins install <name>` | Install a plugin from the registry (e.g. `brainapi plugins install chatbot`). |
+| `brainapi plugins list` | List installed plugins (`--remote` to browse the registry). |
+| `brainapi plugins uninstall <name>` | Remove an installed plugin. |
### `brainapi start` options
diff --git a/tui/src/commands/plugins.ts b/tui/src/commands/plugins.ts
new file mode 100644
index 0000000..fa9ee0b
--- /dev/null
+++ b/tui/src/commands/plugins.ts
@@ -0,0 +1,80 @@
+import * as p from "@clack/prompts";
+import pc from "picocolors";
+import { installRegistryPlugin, runPluginCli, uninstallPlugin } from "../lib/plugins.js";
+import { readState } from "../lib/state.js";
+
+export type PluginsSubcommand = "install" | "uninstall" | "list" | "info" | "update";
+
+export interface PluginsOptions {
+ subcommand?: PluginsSubcommand;
+ name?: string;
+ version?: string;
+ remote?: boolean;
+}
+
+async function ensureInstalled(): Promise<void> {
+ const state = await readState();
+ if (!state || !state.envWritten) {
+ p.cancel(
+ "No brainapi install detected. Run " + pc.cyan("brainapi init") + " first.",
+ );
+ process.exit(1);
+ }
+}
+
+export async function runPlugins(opts: PluginsOptions): Promise<void> {
+ await ensureInstalled();
+
+ const subcommand = opts.subcommand;
+ if (!subcommand) {
+ p.log.error(
+ "Usage: brainapi plugins <install|uninstall|list|info|update> [name] [--version <ver>] [--remote]",
+ );
+ process.exit(1);
+ }
+
+ p.intro(pc.bgCyan(pc.black(" brainapi ")) + " " + pc.dim(`plugins ${subcommand}`));
+
+ switch (subcommand) {
+ case "install": {
+ if (!opts.name) {
+ p.log.error("Plugin name is required. Example: brainapi plugins install chatbot");
+ process.exit(1);
+ }
+ await installRegistryPlugin(opts.name, opts.version);
+ p.outro(`Installed ${opts.name}`);
+ return;
+ }
+ case "uninstall": {
+ if (!opts.name) {
+ p.log.error("Plugin name is required. Example: brainapi plugins uninstall chatbot");
+ process.exit(1);
+ }
+ await uninstallPlugin(opts.name);
+ p.outro(`Uninstalled ${opts.name}`);
+ return;
+ }
+ case "list": {
+ const args = ["list"];
+ if (opts.remote) args.push("--remote");
+ await runPluginCli(args);
+ return;
+ }
+ case "info": {
+ if (!opts.name) {
+ p.log.error("Plugin name is required. Example: brainapi plugins info chatbot");
+ process.exit(1);
+ }
+ await runPluginCli(["info", opts.name]);
+ return;
+ }
+ case "update": {
+ if (!opts.name) {
+ p.log.error("Plugin name is required. Example: brainapi plugins update chatbot");
+ process.exit(1);
+ }
+ await runPluginCli(["update", opts.name]);
+ return;
+ }
+ }
+}
diff --git a/tui/src/index.ts b/tui/src/index.ts
index 092313c..5ba7ab0 100644
--- a/tui/src/index.ts
+++ b/tui/src/index.ts
@@ -5,10 +5,11 @@ import { runStart } from "./commands/start.js";
import { runConfig } from "./commands/config.js";
import { runDoctor } from "./commands/doctor.js";
import { runUpdate } from "./commands/update.js";
+import { runPlugins, type PluginsOptions, type PluginsSubcommand } from "./commands/plugins.js";
import { readState } from "./lib/state.js";
import { isPipelineMode, type PipelineMode } from "./types.js";
-type Command = "init" | "start" | "config" | "doctor" | "update" | "help";
+type Command = "init" | "start" | "config" | "doctor" | "update" | "plugins" | "help";
interface ParsedArgs {
command: Command;
@@ -22,9 +23,22 @@ interface ParsedArgs {
only?: Array<"api" | "mcp" | "worker" | "services">;
pipeline?: PipelineMode;
invalidPipeline?: string;
+ plugins?: PluginsOptions;
unknown: string[];
}
+const PLUGIN_SUBCOMMANDS = new Set<PluginsSubcommand>([
+ "install",
+ "uninstall",
+ "list",
+ "info",
+ "update",
+]);
+
+function isPluginsSubcommand(value: string): value is PluginsSubcommand {
+ return PLUGIN_SUBCOMMANDS.has(value as PluginsSubcommand);
+}
+
function parseArgs(argv: string[]): ParsedArgs {
const args = [...argv];
let command: Command = "help";
@@ -79,12 +93,36 @@ function parseArgs(argv: string[]): ParsedArgs {
case "config":
case "doctor":
case "update":
+ case "plugins":
case "help":
out.command = arg;
break;
default:
unknown.push(arg);
}
+ } else if (out.command === "plugins") {
+ if (!out.plugins) out.plugins = {};
+ const plugins = out.plugins;
+ if (!plugins.subcommand && !arg.startsWith("-")) {
+ if (isPluginsSubcommand(arg)) {
+ plugins.subcommand = arg;
+ } else {
+ unknown.push(arg);
+ }
+ } else if (arg === "--version") {
+ plugins.version = args.shift();
+ } else if (arg === "--remote" || arg === "-r") {
+ plugins.remote = true;
+ } else if (
+ plugins.subcommand &&
+ plugins.subcommand !== "list" &&
+ !plugins.name &&
+ !arg.startsWith("-")
+ ) {
+ plugins.name = arg;
+ } else {
+ unknown.push(arg);
+ }
} else {
unknown.push(arg);
}
@@ -104,6 +142,7 @@ function printHelp(): void {
" config Re-run the interactive flow and rewrite .env",
" doctor Check Python, Docker, Ollama, GCP credentials, services",
" update Fetch latest source + reinstall Python dependencies",
+ " plugins <cmd> Manage plugins (install, uninstall, list, info, update)",
" help Show this message",
"",
pc.bold("Options:"),
@@ -203,6 +242,9 @@ async function main(): Promise<void> {
case "update":
await runUpdate();
return;
+ case "plugins":
+ await runPlugins(parsed.plugins ?? {});
+ return;
case "help":
printHelp();
return;
diff --git a/tui/src/lib/plugins.ts b/tui/src/lib/plugins.ts
index c15b3fb..27260f7 100644
--- a/tui/src/lib/plugins.ts
+++ b/tui/src/lib/plugins.ts
@@ -111,24 +111,33 @@ export async function searchPlugins(query: string): Promise<PluginSearchResult[]
);
}
+export async function runPluginCli(args: string[]): Promise<void> {
+ const result = await runInherit(
+ venvBin("python"),
+ ["-m", "src.core.plugins.cli", "plugins", ...args],
+ { cwd: sourcePath() },
+ );
+ if (!result.ok) {
+ throw new Error("Plugin command failed");
+ }
+}
+
export async function installRegistryPlugin(name: string, version?: string): Promise<void> {
- const args = ["-m", "src.core.plugins.cli", "install", name];
+ const args = ["install", name];
if (version && version.trim()) {
args.push("--version", version.trim());
}
- const result = await runInherit(venvBin("python"), args, { cwd: sourcePath() });
- if (!result.ok) {
+ try {
+ await runPluginCli(args);
+ } catch {
throw new Error(`Failed to install registry plugin '${name}'`);
}
}
export async function uninstallPlugin(name: string): Promise<void> {
- const result = await runInherit(
- venvBin("python"),
- ["-m", "src.core.plugins.cli", "uninstall", name],
- { cwd: sourcePath() },
- );
- if (!result.ok) {
+ try {
+ await runPluginCli(["uninstall", name]);
+ } catch {
throw new Error(`Failed to uninstall plugin '${name}'`);
}
}