Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix plugins installing during init and plugins add #3451

Open
wants to merge 3 commits into
base: v2-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# No configuration needed for SQLite
# No configuration needed for SQLite
ELIZA_BRANCH=v2-develop
23 changes: 9 additions & 14 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { handleError } from "@/src/utils/handle-error"
import { logger } from "@/src/utils/logger"
import { getAvailableDatabases, getRegistryIndex, listPluginsByType } from "@/src/utils/registry"
import { createDatabaseTemplate, createPluginsTemplate, createEnvTemplate } from "@/src/utils/templates"
import { runBunCommand } from "@/src/utils/run-bun"
import { installPlugin } from "@/src/utils/install-plugin"
import chalk from "chalk"
import { Command } from "commander"
import { execa } from "execa"
Expand All @@ -18,7 +20,7 @@ const initOptionsSchema = z.object({

async function cloneStarterRepo(targetDir: string) {
logger.info("Setting up project structure...")
await execa("git", ["clone", "-b", "develop", "https://github.com/elizaos/eliza", "."], {
await execa("git", ["clone", "-b", process.env.ELIZA_BRANCH || "v2-develop", "https://github.com/elizaos/eliza", "."], {
cwd: targetDir,
stdio: "inherit",
})
Expand Down Expand Up @@ -74,21 +76,14 @@ async function installDependencies(targetDir: string, database: string, selected
})

// Use bun for installation
await execa("bun", ["install", "--no-frozen-lockfile"], {
cwd: targetDir,
stdio: "inherit"
})

await execa("bun", ["add", `@elizaos/adapter-${database}`, "--workspace-root"], {
cwd: targetDir,
stdio: "inherit"
})
await runBunCommand(["install", "--no-frozen-lockfile"], targetDir);
await runBunCommand(["add", `@elizaos/adapter-${database}`, "--workspace-root"], targetDir);

if (selectedPlugins.length > 0) {
await execa("bun", ["add", ...selectedPlugins, "--workspace-root"], {
cwd: targetDir,
stdio: "inherit"
})
console.log(selectedPlugins)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This console.log statement appears to be a debugging artifact and should be removed before merging.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

for (const plugin of selectedPlugins) {
await installPlugin(plugin, targetDir)
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from "@/src/utils/logger"
import { getPluginRepository, getRegistryIndex } from "@/src/utils/registry"
import { Command } from "commander"
import { execa } from "execa"
import { installPlugin } from "@/src/utils/install-plugin"

export const plugins = new Command()
.name("plugins")
Expand Down Expand Up @@ -58,10 +59,7 @@ plugins

// Install from GitHub
logger.info(`Installing ${plugin}...`)
await execa("bun", ["add", repo], {
cwd,
stdio: "inherit"
})
await installPlugin(repo, cwd)

logger.success(`Successfully installed ${plugin}`)

Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/utils/install-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { execa } from "execa";
import path from "node:path";
import { logger } from "@/src/utils/logger";
import { runBunCommand } from "@/src/utils/run-bun";
import { promises as fs } from "fs";

export async function installPlugin(
pluginName: string,
cwd: string,
): Promise<void> {
// Remove 'github:' or leading '@' prefix if present
const cleanedName = pluginName.replace(/^github:|^@/, "");
let installed = false;
try {
//logger.info(`Attempting to install ${pluginName} using bun add...`);
//await runBunCommand(["add", `${pluginName}`], cwd);
//logger.success(`Successfully installed ${pluginName} via bun add.`);
//installed = true;
// Set the directory to clone into the packages folder (each plugin gets its own subfolder)
const cloneDir = path.join(cwd, "packages", cleanedName.replace(/\S+\//, ""));
logger.info(`Cloning ${pluginName} from https://github.com/${cleanedName}.git to ${cloneDir}`);
await execa("git",["clone", `https://github.com/${cleanedName}.git`, cloneDir],{ cwd, stdio: "inherit" });
logger.success(`Successfully cloned repository for ${cleanedName}.`);
installed = true;
} catch (error: any) {
logger.warn(
`failed to install packages for ${cleanedName}, falling back: ${error.message}`
);
}

if (installed) {
// Try to read the package.json file from the cloned plugin repo
let pkgName = cleanedName;
const pkgPath = path.join(cwd, "packages", cleanedName.replace(/\S+\//, ""), "package.json");
try {
const pkgContent = await fs.readFile(pkgPath, "utf-8");
const pkg = JSON.parse(pkgContent);
if (pkg.name) {
pkgName = pkg.name;
logger.info(`Found package.json name: ${pkgName}`);
logger.info(`Add ${pkgName} to your character's plugins config (packages/agent/defaultCharacter.ts)`);
}
} catch (err: any) {
logger.warn(`Could not read package.json from ${pkgPath}: ${err.message}`);
}
}
}
5 changes: 5 additions & 0 deletions packages/cli/src/utils/run-bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execa } from "execa";

export async function runBunCommand(args: string[], cwd: string): Promise<void> {
await execa("bun", args, { cwd, stdio: "inherit" });
}
Loading