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 formattedDescription = `(${scope}) ${originalDescription}`
|
||||||
|
|
||||||
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
||||||
|
const modelString = mappedModelOverride
|
||||||
|
? `${mappedModelOverride.providerID}/${mappedModelOverride.modelID}`
|
||||||
|
: undefined
|
||||||
|
|
||||||
const config: ClaudeCodeAgentConfig = {
|
const config: ClaudeCodeAgentConfig = {
|
||||||
description: formattedDescription,
|
description: formattedDescription,
|
||||||
mode: data.mode || "subagent",
|
mode: data.mode || "subagent",
|
||||||
prompt: body.trim(),
|
prompt: body.trim(),
|
||||||
...(mappedModelOverride ? { model: mappedModelOverride } : {}),
|
...(modelString ? { model: modelString } : {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolsConfig = parseToolsConfig(data.tools)
|
const toolsConfig = parseToolsConfig(data.tools)
|
||||||
|
|||||||
@@ -47,12 +47,15 @@ export function loadPluginAgents(plugins: LoadedPlugin[]): Record<string, Claude
|
|||||||
const formattedDescription = `(plugin: ${plugin.name}) ${originalDescription}`
|
const formattedDescription = `(plugin: ${plugin.name}) ${originalDescription}`
|
||||||
|
|
||||||
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
const mappedModelOverride = mapClaudeModelToOpenCode(data.model)
|
||||||
|
const modelString = mappedModelOverride
|
||||||
|
? `${mappedModelOverride.providerID}/${mappedModelOverride.modelID}`
|
||||||
|
: undefined
|
||||||
|
|
||||||
const config: ClaudeCodeAgentConfig = {
|
const config: ClaudeCodeAgentConfig = {
|
||||||
description: formattedDescription,
|
description: formattedDescription,
|
||||||
mode: "subagent",
|
mode: "subagent",
|
||||||
prompt: body.trim(),
|
prompt: body.trim(),
|
||||||
...(mappedModelOverride ? { model: mappedModelOverride } : {}),
|
...(modelString ? { model: modelString } : {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolsConfig = parseToolsConfig(data.tools)
|
const toolsConfig = parseToolsConfig(data.tools)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { join } from "path"
|
|||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import type {
|
import type {
|
||||||
InstalledPluginsDatabase,
|
InstalledPluginsDatabase,
|
||||||
|
InstalledPluginEntryV3,
|
||||||
PluginInstallation,
|
PluginInstallation,
|
||||||
PluginManifest,
|
PluginManifest,
|
||||||
LoadedPlugin,
|
LoadedPlugin,
|
||||||
@@ -96,9 +97,38 @@ function isPluginEnabled(
|
|||||||
return true
|
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(
|
function extractPluginEntries(
|
||||||
db: InstalledPluginsDatabase,
|
db: InstalledPluginsDatabase,
|
||||||
): Array<[string, PluginInstallation | undefined]> {
|
): Array<[string, PluginInstallation | undefined]> {
|
||||||
|
if (Array.isArray(db)) {
|
||||||
|
return db
|
||||||
|
.filter(isValidV3Entry)
|
||||||
|
.map((entry) => [
|
||||||
|
`${entry.name}@${entry.marketplace}`,
|
||||||
|
v3EntryToInstallation(entry),
|
||||||
|
])
|
||||||
|
}
|
||||||
if (db.version === 1) {
|
if (db.version === 1) {
|
||||||
return Object.entries(db.plugins).map(([key, installation]) => [key, installation])
|
return Object.entries(db.plugins).map(([key, installation]) => [key, installation])
|
||||||
}
|
}
|
||||||
@@ -111,7 +141,7 @@ export function discoverInstalledPlugins(options?: PluginLoaderOptions): PluginL
|
|||||||
const plugins: LoadedPlugin[] = []
|
const plugins: LoadedPlugin[] = []
|
||||||
const errors: PluginLoadError[] = []
|
const errors: PluginLoadError[] = []
|
||||||
|
|
||||||
if (!db || !db.plugins) {
|
if (!db || (!Array.isArray(db) && !db.plugins)) {
|
||||||
return { plugins, errors }
|
return { plugins, errors }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,19 +30,42 @@ export interface InstalledPluginsDatabaseV1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installed plugins database v2 (current)
|
* Installed plugins database v2
|
||||||
* plugins stored as arrays
|
* plugins stored as arrays keyed by plugin identifier
|
||||||
*/
|
*/
|
||||||
export interface InstalledPluginsDatabaseV2 {
|
export interface InstalledPluginsDatabaseV2 {
|
||||||
version: 2
|
version: 2
|
||||||
plugins: Record<string, PluginInstallation[]>
|
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
|
* Installed plugins database structure
|
||||||
* Located at ~/.claude/plugins/installed_plugins.json
|
* 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
|
* Plugin author information
|
||||||
|
|||||||
Reference in New Issue
Block a user