|
| 1 | +#!/usr/bin/env bash |
| 2 | +# ============================================================================= |
| 3 | +# poll-skill-submissions.sh — Scan skill-submissions/ for new submissions |
| 4 | +# ============================================================================= |
| 5 | +# |
| 6 | +# Checks the shared skill-submissions directory for new or pending submissions. |
| 7 | +# Each submission is a directory containing at minimum a SKILL.md file. |
| 8 | +# |
| 9 | +# Usage: |
| 10 | +# bash scripts/poll-skill-submissions.sh |
| 11 | +# |
| 12 | +# Output: |
| 13 | +# Lists pending submissions with metadata. Returns exit code: |
| 14 | +# 0 — new submissions found |
| 15 | +# 1 — error |
| 16 | +# 2 — no new submissions |
| 17 | +# |
| 18 | +# ============================================================================= |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +SUBMISSIONS_DIR="${SKILL_SUBMISSIONS_DIR:-/shared/skill-submissions}" |
| 23 | +STATE_FILE="state/skill-submissions-seen.json" |
| 24 | +LOG_PREFIX="[skill-poll]" |
| 25 | + |
| 26 | +# Ensure state file exists |
| 27 | +if [ ! -f "$STATE_FILE" ]; then |
| 28 | + echo '{"seen":[]}' > "$STATE_FILE" |
| 29 | +fi |
| 30 | + |
| 31 | +if [ ! -d "$SUBMISSIONS_DIR" ]; then |
| 32 | + echo "$LOG_PREFIX Submissions directory not found: $SUBMISSIONS_DIR" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Find all submission directories (must contain SKILL.md) |
| 37 | +SUBMISSIONS=$(find "$SUBMISSIONS_DIR" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort) |
| 38 | + |
| 39 | +if [ -z "$SUBMISSIONS" ]; then |
| 40 | + echo "$LOG_PREFIX No submissions found." |
| 41 | + exit 2 |
| 42 | +fi |
| 43 | + |
| 44 | +SEEN=$(cat "$STATE_FILE") |
| 45 | +NEW_COUNT=0 |
| 46 | + |
| 47 | +echo "$LOG_PREFIX Scanning submissions..." |
| 48 | +echo "---" |
| 49 | + |
| 50 | +for DIR in $SUBMISSIONS; do |
| 51 | + NAME=$(basename "$DIR") |
| 52 | + |
| 53 | + # Check if already seen |
| 54 | + if echo "$SEEN" | grep -q "\"$NAME\""; then |
| 55 | + continue |
| 56 | + fi |
| 57 | + |
| 58 | + # Check for required SKILL.md |
| 59 | + if [ ! -f "$DIR/SKILL.md" ]; then |
| 60 | + echo "$LOG_PREFIX ⚠️ $NAME — missing SKILL.md, skipping" |
| 61 | + continue |
| 62 | + fi |
| 63 | + |
| 64 | + # Extract metadata from SKILL.md frontmatter |
| 65 | + DESCRIPTION=$(grep -m1 '^description:' "$DIR/SKILL.md" 2>/dev/null | sed 's/^description: *//' | tr -d '"' || echo "No description") |
| 66 | + AUTHOR=$(ls -ld "$DIR" | awk '{print $3}') |
| 67 | + SUBMITTED=$(stat -c '%y' "$DIR/SKILL.md" 2>/dev/null | cut -d. -f1 || echo "unknown") |
| 68 | + FILE_COUNT=$(find "$DIR" -type f | wc -l) |
| 69 | + |
| 70 | + echo "📦 NEW: $NAME" |
| 71 | + echo " Description: $DESCRIPTION" |
| 72 | + echo " Author: $AUTHOR" |
| 73 | + echo " Submitted: $SUBMITTED" |
| 74 | + echo " Files: $FILE_COUNT" |
| 75 | + echo "" |
| 76 | + |
| 77 | + ((NEW_COUNT++)) |
| 78 | +done |
| 79 | + |
| 80 | +echo "---" |
| 81 | + |
| 82 | +if [ "$NEW_COUNT" -eq 0 ]; then |
| 83 | + echo "$LOG_PREFIX No new submissions." |
| 84 | + exit 2 |
| 85 | +else |
| 86 | + echo "$LOG_PREFIX Found $NEW_COUNT new submission(s) pending review." |
| 87 | + echo "$LOG_PREFIX Run: bash scripts/review-skill-submission.sh <skill-name>" |
| 88 | + exit 0 |
| 89 | +fi |
0 commit comments