fix: community plugin loading, settings path, and onboard init

- Load community plugins from registry on startup (main.ts)
- Fix path resolution for local and npm plugins (absolute paths, ESM entry point)
- Scan node_modules when plugin name differs from npm package name
- Align settings basePath to ~/.openacp/plugins/data/ across all CLI commands
- Initialize plugin system in onboard command
- Add debug logging for settings resolution in lifecycle-manager

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
EthanMiller0x 2026-03-27 18:16:27 +07:00
parent 8c85d5b2d1
commit 68ca2e4c78
4 changed files with 62 additions and 12 deletions

View File

@ -6,8 +6,18 @@ const PLUGINS_DATA_DIR = path.join(OPENACP_DIR, 'plugins', 'data')
const REGISTRY_PATH = path.join(OPENACP_DIR, 'plugins.json')
export async function cmdOnboard(): Promise<void> {
const os = await import('node:os')
const path = await import('node:path')
const { ConfigManager } = await import('../../core/config/config.js')
const { SettingsManager } = await import('../../core/plugin/settings-manager.js')
const { PluginRegistry } = await import('../../core/plugin/plugin-registry.js')
const cm = new ConfigManager()
const pluginsDataDir = path.join(os.homedir(), '.openacp', 'plugins', 'data')
const registryPath = path.join(os.homedir(), '.openacp', 'plugins.json')
const settingsManager = new SettingsManager(pluginsDataDir)
const pluginRegistry = new PluginRegistry(registryPath)
await pluginRegistry.load()
if (await cm.exists()) {
const { runReconfigure } = await import('../../core/setup/index.js')

View File

@ -184,7 +184,7 @@ async function configurePlugin(name: string): Promise<void> {
process.exit(1)
}
const basePath = path.join(os.homedir(), '.openacp', 'plugins')
const basePath = path.join(os.homedir(), '.openacp', 'plugins', 'data')
const settingsManager = new SettingsManager(basePath)
const ctx = createInstallContext({ pluginName: name, settingsManager, basePath })
@ -261,7 +261,7 @@ async function installPlugin(input: string): Promise<void> {
const { corePlugins } = await import('../../plugins/core-plugins.js')
const builtinPlugin = corePlugins.find(p => p.name === pkgName)
const basePath = path.join(os.homedir(), '.openacp', 'plugins')
const basePath = path.join(os.homedir(), '.openacp', 'plugins', 'data')
const settingsManager = new SettingsManager(basePath)
const registryPath = path.join(os.homedir(), '.openacp', 'plugins.json')
const pluginRegistry = new PluginRegistry(registryPath)
@ -302,8 +302,10 @@ async function installPlugin(input: string): Promise<void> {
// Read installed plugin's package.json for compatibility check
const cliVersion = getCurrentVersion()
const isLocalPath = pkgName.startsWith('/') || pkgName.startsWith('.')
try {
const installedPkgPath = path.join(nodeModulesDir, pkgName, 'package.json')
const pluginRoot = isLocalPath ? path.resolve(pkgName) : path.join(nodeModulesDir, pkgName)
const installedPkgPath = path.join(pluginRoot, 'package.json')
const { readFileSync } = await import('node:fs')
const installedPkg = JSON.parse(readFileSync(installedPkgPath, 'utf-8'))
@ -318,7 +320,7 @@ async function installPlugin(input: string): Promise<void> {
}
// Try to load and run install hook
const pluginModule = await import(path.join(nodeModulesDir, pkgName, installedPkg.main ?? 'dist/index.js'))
const pluginModule = await import(path.join(pluginRoot, installedPkg.main ?? 'dist/index.js'))
const plugin = pluginModule.default
if (plugin?.install) {
@ -377,7 +379,7 @@ async function uninstallPlugin(name: string, purge: boolean): Promise<void> {
if (plugin?.uninstall) {
const { SettingsManager } = await import('../../core/plugin/settings-manager.js')
const { createInstallContext } = await import('../../core/plugin/install-context.js')
const basePath = path.join(os.homedir(), '.openacp', 'plugins')
const basePath = path.join(os.homedir(), '.openacp', 'plugins', 'data')
const settingsManager = new SettingsManager(basePath)
const ctx = createInstallContext({ pluginName: name, settingsManager, basePath })
await plugin.uninstall(ctx, { purge })

View File

@ -205,11 +205,14 @@ export class LifecycleManager {
let pluginConfig: Record<string, unknown>
if (this.settingsManager) {
pluginConfig = await this.settingsManager.loadSettings(plugin.name)
const settingsPath = this.settingsManager.getSettingsPath(plugin.name)
this.getPluginLogger(plugin.name).debug(`Settings loaded from ${settingsPath}: ${Object.keys(pluginConfig).length} keys`)
if (Object.keys(pluginConfig).length === 0) {
pluginConfig = resolvePluginConfig(plugin.name, this.config)
}
} else {
pluginConfig = resolvePluginConfig(plugin.name, this.config)
this.getPluginLogger(plugin.name).debug('No settingsManager, using legacy config')
}
// Create context for this plugin

View File

@ -140,14 +140,49 @@ export async function startServer(opts?: StartServerOptions) {
try {
let modulePath: string
if (entry.source === 'local') {
// Local plugin: name is the filesystem path or resolves directly
modulePath = name.startsWith('/') || name.startsWith('.')
? path.resolve(name)
: path.join(OPENACP_DIR, 'plugins', 'node_modules', name)
if (name.startsWith('/') || name.startsWith('.')) {
// Absolute or relative path (local install via `plugin add /path/to/plugin`)
const resolved = path.resolve(name)
const pkgPath = path.join(resolved, 'package.json')
const pkg = JSON.parse(await fs.promises.readFile(pkgPath, 'utf-8'))
modulePath = path.join(resolved, pkg.main || 'dist/index.js')
} else {
// npm plugin: installed under ~/.openacp/plugins/node_modules/<name>
modulePath = path.join(OPENACP_DIR, 'plugins', 'node_modules', name)
// npm package: try direct name first, then scan node_modules for matching plugin name
const nodeModulesDir = path.join(OPENACP_DIR, 'plugins', 'node_modules')
let pkgDir = path.join(nodeModulesDir, name)
if (!fs.existsSync(path.join(pkgDir, 'package.json'))) {
// Plugin name doesn't match npm package name — scan installed packages
let found = false
const scopes = fs.readdirSync(nodeModulesDir).filter(d => d.startsWith('@'))
for (const scope of scopes) {
const scopeDir = path.join(nodeModulesDir, scope)
const pkgs = fs.readdirSync(scopeDir)
for (const pkg of pkgs) {
const candidateDir = path.join(scopeDir, pkg)
const candidatePkgPath = path.join(candidateDir, 'package.json')
if (fs.existsSync(candidatePkgPath)) {
try {
const candidatePkg = JSON.parse(fs.readFileSync(candidatePkgPath, 'utf-8'))
const mainPath = path.join(candidateDir, candidatePkg.main || 'dist/index.js')
if (fs.existsSync(mainPath)) {
const testMod = await import(mainPath)
if (testMod.default?.name === name) {
pkgDir = candidateDir
found = true
break
}
}
} catch { /* skip */ }
}
}
if (found) break
}
}
const pkgJsonPath = path.join(pkgDir, 'package.json')
const pkg = JSON.parse(await fs.promises.readFile(pkgJsonPath, 'utf-8'))
modulePath = path.join(pkgDir, pkg.main || 'dist/index.js')
}
log.debug({ plugin: name, modulePath }, 'Loading community plugin')