diff --git a/README.md b/README.md index 200f90d..06fa340 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ Once installed, use the skills with the `nextflow:` namespace: /nextflow:launch-workflow ``` +## Hooks + +A `PostToolUse` hook runs `nextflow lint` on any `.nf` or `.config` file the plugin writes or edits, feeding errors back so they get fixed automatically. It requires `nextflow` on `PATH` and skips silently when Nextflow isn't installed. + ## Local Development To test the plugin locally without installing: diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..eecc1e1 --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,16 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit|MultiEdit", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/nextflow-lint.sh", + "timeout": 120 + } + ] + } + ] + } +} diff --git a/hooks/scripts/nextflow-lint.sh b/hooks/scripts/nextflow-lint.sh new file mode 100755 index 0000000..253f68a --- /dev/null +++ b/hooks/scripts/nextflow-lint.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# PostToolUse hook: lint Nextflow files after Claude writes or edits them. +# Surfaces `nextflow lint` errors back to Claude (exit 2) so it can self-correct. +set -euo pipefail + +input="$(cat)" +file_path="$(printf '%s' "$input" | jq -r '.tool_input.file_path // empty')" + +[ -n "$file_path" ] || exit 0 + +case "$file_path" in + *.nf | *.config) ;; + *) exit 0 ;; +esac + +[ -f "$file_path" ] || exit 0 + +# Skip silently if Nextflow isn't installed; the install-nextflow skill covers setup. +command -v nextflow >/dev/null 2>&1 || exit 0 + +if output="$(nextflow lint "$file_path" 2>&1)"; then + exit 0 +fi + +{ + echo "nextflow lint reported issues in ${file_path}:" + echo "$output" + echo + echo "Fix the lint errors above." +} >&2 +exit 2