From 3a918c7d331c410e958a5a1a0564436f10fff35a Mon Sep 17 00:00:00 2001 From: muava12 Date: Tue, 24 Feb 2026 11:37:49 +0800 Subject: [PATCH] refactor(skills): eliminate shared/ folder, co-locate scripts per skill Copy ntfy_send.sh into each skill's own scripts/ directory instead of referencing a shared utility folder. The skills/ directory should only contain individual skill folders. - prayer-times: ntfy_send.sh now at scripts/ntfy_send.sh (local) - reminder: ntfy_send.sh now at scripts/ntfy_send.sh (local) - Delete skills/shared/ directory entirely --- .../scripts/ntfy_send.sh | 0 .../prayer-times/scripts/prayer_notify.sh | 4 +- workspace/skills/reminder/SKILL.md | 10 ++--- .../skills/reminder/scripts/ntfy_send.sh | 44 +++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) rename workspace/skills/{shared => prayer-times}/scripts/ntfy_send.sh (100%) create mode 100644 workspace/skills/reminder/scripts/ntfy_send.sh diff --git a/workspace/skills/shared/scripts/ntfy_send.sh b/workspace/skills/prayer-times/scripts/ntfy_send.sh similarity index 100% rename from workspace/skills/shared/scripts/ntfy_send.sh rename to workspace/skills/prayer-times/scripts/ntfy_send.sh diff --git a/workspace/skills/prayer-times/scripts/prayer_notify.sh b/workspace/skills/prayer-times/scripts/prayer_notify.sh index e0f1fd98a..1d891cd55 100644 --- a/workspace/skills/prayer-times/scripts/prayer_notify.sh +++ b/workspace/skills/prayer-times/scripts/prayer_notify.sh @@ -19,8 +19,8 @@ SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" DATA_DIR="${PRAYER_DATA_DIR:-$SKILL_DIR/data}" CONFIG_FILE="$DATA_DIR/config" -# Locate shared ntfy_send.sh relative to this script -NTFY_SEND="${SCRIPT_DIR}/../../shared/scripts/ntfy_send.sh" +# ntfy_send.sh lives alongside this script +NTFY_SEND="${SCRIPT_DIR}/ntfy_send.sh" mkdir -p "$DATA_DIR" diff --git a/workspace/skills/reminder/SKILL.md b/workspace/skills/reminder/SKILL.md index 124409dcf..beaa48c1c 100644 --- a/workspace/skills/reminder/SKILL.md +++ b/workspace/skills/reminder/SKILL.md @@ -167,11 +167,11 @@ mkdir -p skills/reminder/data && echo 'NTFY_TOPIC="https://ntfy.sh/USER_TOPIC"' ## ntfy Push Notification -Gunakan shared helper script. **WAJIB source config sendiri sebelum panggil ntfy_send.sh**: +Gunakan helper script milik skill ini. **WAJIB source config sendiri sebelum panggil ntfy_send.sh**: ```bash # Semua perintah ntfy harus diawali source config -source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash skills/shared/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock +source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash skills/reminder/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock ``` > **JANGAN pakai curl langsung** ke ntfy. Selalu gunakan `ntfy_send.sh` agar URL dibaca dari config. @@ -186,7 +186,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash ``` **Job 2 — ntfy push:** ```json -{"action": "add", "message": "ntfy: meeting", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600} +{"action": "add", "message": "ntfy: meeting", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600} ``` ### Recurring reminder (2 jobs) @@ -197,7 +197,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash ``` **Job 2 — ntfy push:** ```json -{"action": "add", "message": "ntfy: minum air", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600} +{"action": "add", "message": "ntfy: minum air", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600} ``` ### Daily cron reminder (2 jobs) @@ -208,7 +208,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash ``` **Job 2 — ntfy push:** ```json -{"action": "add", "message": "ntfy: daily review", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"} +{"action": "add", "message": "ntfy: daily review", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"} ``` ### Daily report via agent (1 job only, no ntfy) diff --git a/workspace/skills/reminder/scripts/ntfy_send.sh b/workspace/skills/reminder/scripts/ntfy_send.sh new file mode 100644 index 000000000..fe34d098a --- /dev/null +++ b/workspace/skills/reminder/scripts/ntfy_send.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# ntfy_send.sh — Stateless ntfy notification sender utility +# Does NOT manage its own config. Reads NTFY_TOPIC from environment variable. +# Each skill is responsible for setting NTFY_TOPIC from its own config. +# +# Usage: +# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message" +# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message" --title "T" --tags "t" --priority "high" +# +# If NTFY_TOPIC is empty, silently skips (exit 0). + +set -euo pipefail + +if [ -z "${NTFY_TOPIC:-}" ]; then + # No topic configured — skip silently so cron jobs don't fail + exit 0 +fi + +message="${1:-}" +if [ -z "$message" ]; then + echo "Usage: ntfy_send.sh \"message\" [--title T] [--tags T] [--priority P]" + exit 1 +fi +shift + +# Parse optional flags +title="" tags="" priority="" +while [ $# -gt 0 ]; do + case "$1" in + --title) title="$2"; shift 2 ;; + --tags) tags="$2"; shift 2 ;; + --priority) priority="$2"; shift 2 ;; + *) shift ;; + esac +done + +# Build curl args +curl_args=(-sf) +[ -n "$title" ] && curl_args+=(-H "Title: $title") +[ -n "$tags" ] && curl_args+=(-H "Tags: $tags") +[ -n "$priority" ] && curl_args+=(-H "Priority: $priority") +curl_args+=(-d "$message" "$NTFY_TOPIC") + +curl "${curl_args[@]}" > /dev/null 2>&1 || true