{# Shared Jinja2 macros for plugin-source/. Imported by SKILL.md.j2 templates. #}

{# `invoke` renders the platform-appropriate shell invocation of a skill script.

   skill   — the skill folder name (e.g. "learn", "publish")
   script  — the script filename (e.g. "save_entities.py")
   args    — argument string OR list of args. None for no args. When a list is
             passed, claude renders each arg on its own line with backslash
             continuation (matches existing claude SKILL.md formatting); the
             other platforms stay single-line because the whole command is
             either wrapped in `sh -lc '...'` (claw-code) or invoked through
             a single python3 call (codex, bob).
   path_override — when set, the script is invoked from this exact path on
             EVERY platform (e.g. "~/.claude/evolve-lite/adapt_memory.py"), and
             the per-platform plugin-relative path resolution is bypassed. Used
             for scripts the installer ships to a stable, version-proof global
             path so they can be permission-allowlisted (mirrors how EVOLVE.md
             invokes `python3 {{ audit_script }}`). The arg rendering still
             follows the per-platform rules above.

   Path resolution per platform:
     claude    — ${CLAUDE_PLUGIN_ROOT} expanded by the Claude plugin runtime.
     claw-code — walks up from .claw/skills/ to a config-home fallback.
     codex     — git-rev-parse from any cwd inside the project clone.
     bob       — project-rooted .bob/skills/evolve-lite-<skill>/ (post-rename).
#}
{%- macro invoke(skill, script, args=None, path_override=None) -%}
{%- if path_override is not none -%}
{#- Stable global path (installer-shipped, version-proof, allowlistable). Same
   head on every platform; arg formatting follows the per-platform rules. -#}
python3 {{ path_override }}
{%- if args is none %}{# no args; nothing appended #}
{%- elif args is string %} {{ args }}
{%- elif platform == "claude" %} \
  {{ args | join(" \\\n  ") }}
{%- else %} {{ args | join(" ") }}
{%- endif -%}
{%- elif platform == "claude" -%}
python3 ${CLAUDE_PLUGIN_ROOT}/skills/evolve-lite/{{ skill }}/scripts/{{ script }}
{%- if args is none %}{# no args; nothing appended #}
{%- elif args is string %} {{ args }}
{%- else %} \
  {{ args | join(" \\\n  ") }}
{%- endif -%}
{%- elif platform == "claw-code" -%}
sh -lc 'real_home="$(python3 -c "import os,pwd; print(pwd.getpwuid(os.getuid()).pw_dir)")"; config_home="${CLAW_CONFIG_HOME:-$real_home/.claw}"; script=".claw/skills/evolve-lite:{{ skill }}/scripts/{{ script }}"; [ -f "$script" ] || script="$config_home/skills/evolve-lite:{{ skill }}/scripts/{{ script }}"; python3 "$script"
{%- if args is none -%}{# no args; nothing appended -#}
{%- elif args is string %} {{ args }}
{%- else %} {{ args | join(" ") }}
{%- endif -%}
'
{%- elif platform == "codex" -%}
python3 "$(git rev-parse --show-toplevel 2>/dev/null || pwd)/plugins/evolve-lite/skills/evolve-lite/{{ skill }}/scripts/{{ script }}"
{%- if args is none %}{# no args; nothing appended #}
{%- elif args is string %} {{ args }}
{%- else %} {{ args | join(" ") }}
{%- endif -%}
{%- elif platform == "bob" -%}
python3 .bob/skills/evolve-lite-{{ skill }}/scripts/{{ script }}
{%- if args is none %}{# no args; nothing appended #}
{%- elif args is string %} {{ args }}
{%- else %} {{ args | join(" ") }}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

{# `skill_ref` renders the platform-appropriate way to refer to a sibling skill
   in prose (e.g. "see /evolve-lite:sync" on claude, "evolve-lite:sync" on bob).
   Bob uses the colon form to match its SKILL.md frontmatter `name` field
   (e.g. `name: evolve-lite:sync`); the skill folder on disk stays
   colon-free (`.bob/skills/evolve-lite-sync/`) for Windows compatibility.
#}
{%- macro skill_ref(name) -%}
{%- if platform in ["claude", "claw-code"] -%}/evolve-lite:{{ name }}
{%- elif platform == "codex" -%}evolve-lite:{{ name }}
{%- elif platform == "bob" -%}evolve-lite:{{ name }}
{%- endif -%}
{%- endmacro -%}
