OpenWriterControle/plugins/claude-code/hooks/session-start.sh
Darren Hinde 9e5e70a12d
fix(plugin): fix hooks and add missing skills for reliable skill invocation (#227)
* fix: overhaul Claude Code plugin for correctness and spec compliance

- Fix critical bugs: coder-agent name (CoderAgent→coder-agent), manifest
  path in session-start.sh, /oac:setup ghost command replaced with /install-context
- Fix hooks.json: add timeout/async, add description, restore matcher
- Fix session-start.sh: dual-format output (Claude Code + Cursor/OpenCode),
  remove invalid JSON escapes for $ and backtick
- Fix agent spec compliance: disallowedTools on read-only agents, WebFetch
  on external-scout, haiku model on context-scout, example blocks on 3 agents
- Fix skill descriptions: triggering conditions only (no workflow summaries)
  per superpowers empirical testing — prevents Claude shortcutting skill content
- Add Red Flags + Rationalization tables to 4 discipline skills
- Add install-context skill + command replacing oac-setup/oac-plan/oac-add-context
- Add cleanup-tmp.sh (was missing, broke /oac:cleanup)
- Add TypeScript installer (install-context.ts/js) with profile-based download
- Update plugin.json: keywords, homepage for marketplace discoverability
- Update README: correct skill count, fix structure diagram, remove stale refs
- Remove obsolete files: FIRST-TIME-SETUP.md, INSTALL.md, QUICK-START.md,
  download-context.sh, verify-context.sh, load-config.sh, context-manager skill,
  oac-setup/oac-plan/oac-add-context commands

* add TypeScript and OpenCode context standards files

Adds three new context files covering universal TypeScript patterns,
OpenCode-specific patterns (fn() wrapper, namespaces, Instance.state()),
and context-system-specific TypeScript coding standards.

* fix(plugin): fix hooks and add missing skills for reliable skill invocation

- Rewrite using-oac skill with always-on skill-check rule (was conditional on dev task detection)
- Update session-start.sh to dynamically inject full skill catalogue at session start
- Add brainstorming skill: intercepts creative/build work before any implementation
- Add systematic-debugging skill: 4-phase root cause process before any fix
- Add verification-before-completion skill: evidence-before-claims gate
- Add /brainstorm and /debug slash commands as pure skill shortcuts
- Fix oac-help to use disable-model-invocation:true (pure shortcut, not self-rendering)
- Fix oac-status to be simpler bash-based status check
2026-02-19 21:12:20 +00:00

74 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# SessionStart hook for OAC plugin
set -euo pipefail
# Determine plugin root directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
SKILL_FILE="${PLUGIN_ROOT}/skills/using-oac/SKILL.md"
# Read using-oac content
using_oac_content=$(cat "${SKILL_FILE}" 2>&1 || echo "Error reading using-oac skill")
# Escape string for JSON embedding
# SECURITY: Prevents command injection attacks from malicious SKILL.md files
escape_for_json() {
local s="$1"
# Escape backslashes FIRST - order matters!
s="${s//\\/\\\\}"
# Escape double quotes
s="${s//\"/\\\"}"
# Escape newlines, carriage returns, tabs
s="${s//$'\n'/\\n}"
s="${s//$'\r'/\\r}"
s="${s//$'\t'/\\t}"
printf '%s' "$s"
}
using_oac_escaped=$(escape_for_json "$using_oac_content")
# Build skill catalogue from skills directory
skill_catalogue=""
if [ -d "${PLUGIN_ROOT}/skills" ]; then
for skill_dir in "${PLUGIN_ROOT}/skills"/*/; do
skill_name=$(basename "$skill_dir")
skill_file="${skill_dir}SKILL.md"
if [ -f "$skill_file" ]; then
# Extract description from frontmatter
description=$(grep -m1 '^description:' "$skill_file" 2>/dev/null | sed 's/^description: *//;s/^"//;s/"$//' || echo "")
if [ -n "$description" ]; then
skill_catalogue="${skill_catalogue}\n- oac:${skill_name} — ${description}"
else
skill_catalogue="${skill_catalogue}\n- oac:${skill_name}"
fi
fi
done
fi
# Build warning message for first-time users
warning_message=""
if [[ ! -f "${PLUGIN_ROOT}/.context-manifest.json" ]] && [[ ! -f "$(pwd)/.context-manifest.json" ]]; then
warning_message="\n\n<important-reminder>IN YOUR FIRST REPLY AFTER SEEING THIS MESSAGE YOU MUST TELL THE USER:👋 **Welcome to OpenAgents Control!** To get started, run /install-context to download context files. Then use /brainstorm before building anything.</important-reminder>"
fi
warning_escaped=$(escape_for_json "$warning_message")
skill_catalogue_escaped=$(escape_for_json "$skill_catalogue")
# Build context string
OAC_CONTEXT="<EXTREMELY_IMPORTANT>\nYou have OAC (OpenAgents Control) superpowers.\n\n**Below is the full content of your 'oac:using-oac' skill — your introduction to using OAC skills. For all other skills, use the 'Skill' tool:**\n\n${using_oac_escaped}\n\n## Available OAC Skills (invoke with the Skill tool):\n${skill_catalogue_escaped}\n\n${warning_escaped}\n</EXTREMELY_IMPORTANT>"
# Output dual-format JSON for cross-tool compatibility
# - additionalContext: Claude Code (hookSpecificOutput)
# - additional_context: Cursor / OpenCode / other tools
cat <<EOF
{
"additional_context": "${OAC_CONTEXT}",
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": "${OAC_CONTEXT}"
}
}
EOF
exit 0