Fix crash when hook entries have no matcher (#160)
Claude Code allows hook entries without a `matcher` field (e.g., SessionStart and SubagentStop hooks don't need one). The OpenCode converter assumed `matcher.matcher` was always present, causing "undefined is not an object (evaluating 'matcher.matcher.split')" when converting plugins with matcher-less hooks. Make `matcher` optional in the type and guard all accesses.
This commit is contained in:
@@ -209,9 +209,11 @@ function renderHookStatements(
|
||||
): string[] {
|
||||
if (!matcher.hooks || matcher.hooks.length === 0) return []
|
||||
const tools = matcher.matcher
|
||||
? matcher.matcher
|
||||
.split("|")
|
||||
.map((tool) => tool.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
: []
|
||||
|
||||
const useMatcher = useToolMatcher && tools.length > 0 && !tools.includes("*")
|
||||
const condition = useMatcher
|
||||
@@ -232,10 +234,10 @@ function renderHookStatements(
|
||||
continue
|
||||
}
|
||||
if (hook.type === "prompt") {
|
||||
statements.push(`// Prompt hook for ${matcher.matcher}: ${hook.prompt.replace(/\n/g, " ")}`)
|
||||
statements.push(`// Prompt hook for ${matcher.matcher ?? "*"}: ${hook.prompt.replace(/\n/g, " ")}`)
|
||||
continue
|
||||
}
|
||||
statements.push(`// Agent hook for ${matcher.matcher}: ${hook.agent}`)
|
||||
statements.push(`// Agent hook for ${matcher.matcher ?? "*"}: ${hook.agent}`)
|
||||
}
|
||||
|
||||
return statements
|
||||
|
||||
@@ -79,7 +79,7 @@ export type ClaudeHookAgent = {
|
||||
export type ClaudeHookEntry = ClaudeHookCommand | ClaudeHookPrompt | ClaudeHookAgent
|
||||
|
||||
export type ClaudeHookMatcher = {
|
||||
matcher: string
|
||||
matcher?: string
|
||||
hooks: ClaudeHookEntry[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user