* Create a Command from a plugin markdown file
(
commandName: string,
file: PluginMarkdownFile,
sourceName: string,
pluginManifest: PluginManifest,
pluginPath: string,
isSkill: boolean,
config: LoadConfig = { isSkillMode: false },
)
| 216 | * Create a Command from a plugin markdown file |
| 217 | */ |
| 218 | function createPluginCommand( |
| 219 | commandName: string, |
| 220 | file: PluginMarkdownFile, |
| 221 | sourceName: string, |
| 222 | pluginManifest: PluginManifest, |
| 223 | pluginPath: string, |
| 224 | isSkill: boolean, |
| 225 | config: LoadConfig = { isSkillMode: false }, |
| 226 | ): Command | null { |
| 227 | try { |
| 228 | const { frontmatter, content } = file |
| 229 | |
| 230 | const validatedDescription = coerceDescriptionToString( |
| 231 | frontmatter.description, |
| 232 | commandName, |
| 233 | ) |
| 234 | const description = |
| 235 | validatedDescription ?? |
| 236 | extractDescriptionFromMarkdown( |
| 237 | content, |
| 238 | isSkill ? 'Plugin skill' : 'Plugin command', |
| 239 | ) |
| 240 | |
| 241 | // Substitute ${CLAUDE_PLUGIN_ROOT} in allowed-tools before parsing |
| 242 | const rawAllowedTools = frontmatter['allowed-tools'] |
| 243 | const substitutedAllowedTools = |
| 244 | typeof rawAllowedTools === 'string' |
| 245 | ? substitutePluginVariables(rawAllowedTools, { |
| 246 | path: pluginPath, |
| 247 | source: sourceName, |
| 248 | }) |
| 249 | : Array.isArray(rawAllowedTools) |
| 250 | ? rawAllowedTools.map(tool => |
| 251 | typeof tool === 'string' |
| 252 | ? substitutePluginVariables(tool, { |
| 253 | path: pluginPath, |
| 254 | source: sourceName, |
| 255 | }) |
| 256 | : tool, |
| 257 | ) |
| 258 | : rawAllowedTools |
| 259 | const allowedTools = parseSlashCommandToolsFromFrontmatter( |
| 260 | substitutedAllowedTools, |
| 261 | ) |
| 262 | |
| 263 | const argumentHint = frontmatter['argument-hint'] as string | undefined |
| 264 | const argumentNames = parseArgumentNames( |
| 265 | frontmatter.arguments as string | string[] | undefined, |
| 266 | ) |
| 267 | const whenToUse = frontmatter.when_to_use as string | undefined |
| 268 | const version = frontmatter.version as string | undefined |
| 269 | const displayName = frontmatter.name as string | undefined |
| 270 | |
| 271 | // Handle model configuration, resolving aliases like 'haiku', 'sonnet', 'opus' |
| 272 | const model = |
| 273 | frontmatter.model === 'inherit' |
| 274 | ? undefined |
| 275 | : frontmatter.model |
no test coverage detected