Merge pull request #2563 from robinmordasiewicz/fix/claude-code-plugin-v3-array-format
fix(plugin-loader): support Claude Code v3 flat array format for installed_plugins.json
This commit is contained in:
@@ -43,12 +43,15 @@ function loadAgentsFromDir(agentsDir: string, scope: AgentScope): LoadedAgent[]
|
||||
const formattedDescription = `(${scope}) ${originalDescription}`
|
||||
|
||||
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
||||
const modelString = mappedModelOverride
|
||||
? `${mappedModelOverride.providerID}/${mappedModelOverride.modelID}`
|
||||
: undefined
|
||||
|
||||
const config: ClaudeCodeAgentConfig = {
|
||||
description: formattedDescription,
|
||||
mode: data.mode || "subagent",
|
||||
prompt: body.trim(),
|
||||
...(mappedModelOverride ? { model: mappedModelOverride } : {}),
|
||||
...(modelString ? { model: modelString } : {}),
|
||||
}
|
||||
|
||||
const toolsConfig = parseToolsConfig(data.tools)
|
||||
|
||||
@@ -47,12 +47,15 @@ export function loadPluginAgents(plugins: LoadedPlugin[]): Record<string, Claude
|
||||
const formattedDescription = `(plugin: ${plugin.name}) ${originalDescription}`
|
||||
|
||||
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
||||
const modelString = mappedModelOverride
|
||||
? `${mappedModelOverride.providerID}/${mappedModelOverride.modelID}`
|
||||
: undefined
|
||||
|
||||
const config: ClaudeCodeAgentConfig = {
|
||||
description: formattedDescription,
|
||||
mode: "subagent",
|
||||
prompt: body.trim(),
|
||||
...(mappedModelOverride ? { model: mappedModelOverride } : {}),
|
||||
...(modelString ? { model: modelString } : {}),
|
||||
}
|
||||
|
||||
const toolsConfig = parseToolsConfig(data.tools)
|
||||
|
||||
@@ -4,6 +4,7 @@ import { join } from "path"
|
||||
import { log } from "../../shared/logger"
|
||||
import type {
|
||||
InstalledPluginsDatabase,
|
||||
InstalledPluginEntryV3,
|
||||
PluginInstallation,
|
||||
PluginManifest,
|
||||
LoadedPlugin,
|
||||
@@ -96,9 +97,38 @@ function isPluginEnabled(
|
||||
return true
|
||||
}
|
||||
|
||||
function v3EntryToInstallation(entry: InstalledPluginEntryV3): PluginInstallation {
|
||||
return {
|
||||
scope: entry.scope,
|
||||
installPath: entry.installPath,
|
||||
version: entry.version,
|
||||
installedAt: entry.lastUpdated,
|
||||
lastUpdated: entry.lastUpdated,
|
||||
gitCommitSha: entry.gitCommitSha,
|
||||
}
|
||||
}
|
||||
|
||||
function isValidV3Entry(entry: unknown): entry is InstalledPluginEntryV3 {
|
||||
return (
|
||||
entry != null &&
|
||||
typeof entry === "object" &&
|
||||
typeof (entry as Record<string, unknown>).name === "string" &&
|
||||
typeof (entry as Record<string, unknown>).marketplace === "string" &&
|
||||
typeof (entry as Record<string, unknown>).installPath === "string"
|
||||
)
|
||||
}
|
||||
|
||||
function extractPluginEntries(
|
||||
db: InstalledPluginsDatabase,
|
||||
): Array<[string, PluginInstallation | undefined]> {
|
||||
if (Array.isArray(db)) {
|
||||
return db
|
||||
.filter(isValidV3Entry)
|
||||
.map((entry) => [
|
||||
`${entry.name}@${entry.marketplace}`,
|
||||
v3EntryToInstallation(entry),
|
||||
])
|
||||
}
|
||||
if (db.version === 1) {
|
||||
return Object.entries(db.plugins).map(([key, installation]) => [key, installation])
|
||||
}
|
||||
@@ -111,7 +141,7 @@ export function discoverInstalledPlugins(options?: PluginLoaderOptions): PluginL
|
||||
const plugins: LoadedPlugin[] = []
|
||||
const errors: PluginLoadError[] = []
|
||||
|
||||
if (!db || !db.plugins) {
|
||||
if (!db || (!Array.isArray(db) && !db.plugins)) {
|
||||
return { plugins, errors }
|
||||
}
|
||||
|
||||
|
||||
@@ -30,19 +30,42 @@ export interface InstalledPluginsDatabaseV1 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Installed plugins database v2 (current)
|
||||
* plugins stored as arrays
|
||||
* Installed plugins database v2
|
||||
* plugins stored as arrays keyed by plugin identifier
|
||||
*/
|
||||
export interface InstalledPluginsDatabaseV2 {
|
||||
version: 2
|
||||
plugins: Record<string, PluginInstallation[]>
|
||||
}
|
||||
|
||||
/**
|
||||
* Installed plugins database v3 entry (current Claude Code format)
|
||||
* A flat array of plugin entries, each containing name and marketplace fields
|
||||
* used to construct the plugin key as "name@marketplace".
|
||||
*/
|
||||
export interface InstalledPluginEntryV3 {
|
||||
name: string
|
||||
marketplace: string
|
||||
scope: PluginScope
|
||||
version: string
|
||||
installPath: string
|
||||
lastUpdated: string
|
||||
gitCommitSha?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Installed plugins database structure
|
||||
* Located at ~/.claude/plugins/installed_plugins.json
|
||||
*
|
||||
* Supports three formats:
|
||||
* - v1: { version: 1, plugins: Record<string, PluginInstallation> }
|
||||
* - v2: { version: 2, plugins: Record<string, PluginInstallation[]> }
|
||||
* - v3: InstalledPluginEntryV3[] (flat array, current Claude Code format)
|
||||
*/
|
||||
export type InstalledPluginsDatabase = InstalledPluginsDatabaseV1 | InstalledPluginsDatabaseV2
|
||||
export type InstalledPluginsDatabase =
|
||||
| InstalledPluginsDatabaseV1
|
||||
| InstalledPluginsDatabaseV2
|
||||
| InstalledPluginEntryV3[]
|
||||
|
||||
/**
|
||||
* Plugin author information
|
||||
|
||||
Reference in New Issue
Block a user