mirror of
https://github.com/gnekt/My-Brain-Is-Full-Crew.git
synced 2026-08-31 04:25:36 +00:00
fix: address Copilot review round 3
- adapters/opencode/adapter.sh: replace python3 template substitution with pure bash (while-read loop with case matching), removing python3 dependency - adapters/lib.sh: should_include now falls back to plain YAML key read for files without frontmatter delimiters (fixes hook .yaml exclude: support)
This commit is contained in:
@@ -69,9 +69,16 @@ parse_capabilities() {
|
||||
# should_include <component_file> <framework>
|
||||
# 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
|
||||
|
||||
@@ -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 <source_mcp_dir> <dest_root>
|
||||
|
||||
Reference in New Issue
Block a user