diff --git a/adapters/lib.sh b/adapters/lib.sh index b1ef850..1dab156 100755 --- a/adapters/lib.sh +++ b/adapters/lib.sh @@ -69,9 +69,16 @@ parse_capabilities() { # should_include # Exit 0 if the component should be included in the given framework's build. # Exit 1 if the component's exclude: list contains the framework. +# Supports both frontmatter-delimited files (agents, skills) and plain YAML +# files (hook .yaml) — falls back to a direct key read if no frontmatter found. should_include() { local file="$1" framework="$2" local raw; raw="$(parse_frontmatter "$file" exclude)" + # If parse_frontmatter returned nothing, try reading exclude: as a plain YAML key + # (hook .yaml files don't have --- delimiters) + if [[ -z "$raw" ]]; then + raw="$(awk '/^exclude:/ { sub(/^exclude:[[:space:]]*/, ""); print; exit }' "$file")" + fi # Treat missing or empty exclude as "include" [[ -z "$raw" || "$raw" == "[]" ]] && return 0 # Tokenize the list and check membership diff --git a/adapters/opencode/adapter.sh b/adapters/opencode/adapter.sh index 6757729..72259e1 100755 --- a/adapters/opencode/adapter.sh +++ b/adapters/opencode/adapter.sh @@ -250,27 +250,30 @@ adapter_translate_hooks() { # Pretty-print registry (2-space indent) local registry_pretty; registry_pretty="$(echo "$registry" | jq '.')" - # Use python3 to substitute placeholders — avoids awk/sed issues with - # multi-line JS content containing backslashes and ampersands. + # Substitute placeholders by reading the template line-by-line. + # We avoid sed/awk gsub because the replacement strings (JS code, JSON) + # contain backslashes and ampersands that break regex replacement. local out="$plugins_out/mbifc-hooks.js" local executor_file="$tpl_dir/bash-executor.js" local stub_file="$tpl_dir/plugin-stub.js.tmpl" - python3 - "$stub_file" "$executor_file" "$out" "$registry_pretty" <<'PYEOF' -import sys - -stub_path, executor_path, out_path, registry = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] - -with open(stub_path, 'r') as f: - content = f.read() -with open(executor_path, 'r') as f: - executor = f.read() - -content = content.replace('__BASH_EXECUTOR__', executor) -content = content.replace('__HOOK_REGISTRY__', registry) - -with open(out_path, 'w') as f: - f.write(content) -PYEOF + while IFS= read -r line; do + case "$line" in + *__BASH_EXECUTOR__*) + cat "$executor_file" + ;; + *__HOOK_REGISTRY__*) + # Replace the placeholder within the line (preserves "const HOOKS = " prefix) + local prefix="${line%%__HOOK_REGISTRY__*}" + local suffix="${line##*__HOOK_REGISTRY__}" + printf '%s' "$prefix" + printf '%s' "$registry_pretty" + printf '%s\n' "$suffix" + ;; + *) + printf '%s\n' "$line" + ;; + esac + done < "$stub_file" > "$out" } # adapter_translate_mcp