#!/usr/bin/env bash # Scribe plugin — SessionStart push channel. # # Curls the operator's Scribe instance for always-on rules + active-project # context and emits it as SessionStart `additionalContext`. Config comes from # plugin userConfig, passed in as env by hooks/hooks.json: # SCRIBE_URL base URL, no trailing slash (user_config.api_endpoint) # SCRIBE_TOKEN fmcp_ API key (user_config.api_token) # SCRIBE_PROJECT_ID optional numeric project id (user_config.project_id) # # FAIL-OPEN: any missing tool/config, network error, or unreachable instance # injects nothing and exits 0. A session must never be blocked by Scribe. set -uo pipefail command -v jq >/dev/null 2>&1 || exit 0 command -v curl >/dev/null 2>&1 || exit 0 url=${SCRIBE_URL:-} token=${SCRIBE_TOKEN:-} project_id=${SCRIBE_PROJECT_ID:-} [ -n "$url" ] && [ -n "$token" ] || exit 0 q="" [ -n "$project_id" ] && q="?project_id=${project_id}" body=$(curl -fsS --max-time 8 \ -H "Authorization: Bearer ${token}" \ "${url%/}/api/plugin/context${q}" 2>/dev/null) || exit 0 text=$(printf '%s' "$body" | jq -r '.context // empty' 2>/dev/null) || exit 0 [ -n "$text" ] || exit 0 jq -n --arg c "$text" \ '{hookSpecificOutput: {hookEventName: "SessionStart", additionalContext: $c}}' exit 0