Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:45:28 +08:00
commit 8f34f4d52b
5 changed files with 132 additions and 0 deletions

53
hooks/session-start.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/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