Files
gh-oneryalcin-nexus-plugin/hooks/session-start.sh
2025-11-30 08:45:28 +08:00

54 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# SessionStart hook for nexus plugin
set -euo pipefail
# Set NEXUS_SKILLS_ROOT environment variable
export NEXUS_SKILLS_ROOT="${HOME}/.config/nexus/skills"
# Run skills initialization script (handles clone/fetch/auto-update)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
init_output=$("${PLUGIN_ROOT}/lib/initialize-skills.sh" 2>&1 || echo "")
# Extract status flags
skills_updated=$(echo "$init_output" | grep "SKILLS_UPDATED=true" || echo "")
skills_behind=$(echo "$init_output" | grep "SKILLS_BEHIND=true" || echo "")
# Remove status flags from display output
init_output=$(echo "$init_output" | grep -v "SKILLS_UPDATED=true" | grep -v "SKILLS_BEHIND=true" || true)
# Run find-skill to show all available skills
find_skills_output=$("${NEXUS_SKILLS_ROOT}/getting-started/find-skill" 2>&1 || echo "Error running find-skill")
# Read getting-started content
getting_started_content=$(cat "${NEXUS_SKILLS_ROOT}/getting-started/SKILL.md" 2>&1 || echo "Error reading getting-started")
# Escape outputs for JSON
init_escaped=$(echo "$init_output" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')
find_skills_escaped=$(echo "$find_skills_output" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')
getting_started_escaped=$(echo "$getting_started_content" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')
# Build initialization output message if present
init_message=""
if [ -n "$init_escaped" ]; then
init_message="${init_escaped}\n\n"
fi
# Build status messages that go at the end
status_message=""
if [ -n "$skills_behind" ]; then
status_message="\n\n⚠ New skills available from upstream. Manual merge needed."
fi
# Output context injection as JSON
cat <<EOF
{
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": "<session-start-hook><EXTREMELY_IMPORTANT>\nYou have specialized skills for domain work.\n\n${init_message}**The content below is from getting-started/SKILL.md - your operating procedures:**\n\n${getting_started_escaped}\n\n**Tool paths:**\n- find-skill: \${NEXUS_SKILLS_ROOT}/getting-started/find-skill\n\n**Skills root:** ${NEXUS_SKILLS_ROOT}\n\n**Available skills (output of find-skill):**\n\n${find_skills_escaped}${status_message}\n</EXTREMELY_IMPORTANT></session-start-hook>"
}
}
EOF
exit 0