Files
gh-kylesnowschwartz-simplec…/hooks/entrypoints/subagent_stop.rb
2025-11-30 08:36:27 +08:00

48 lines
1.6 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
# SubagentStop Entrypoint
#
# This entrypoint orchestrates all SubagentStop handlers when Claude Code completes a subagent task.
# It reads JSON input from STDIN, executes all configured handlers, merges their outputs,
# and returns the final result to Claude Code via STDOUT.
require 'claude_hooks'
require 'json'
# Require all SubagentStop handler classes
require_relative '../handlers/subagent_stop_handler'
# Add additional handler requires here as needed:
# require_relative '../handlers/subagent_stop/result_processor'
# require_relative '../handlers/subagent_stop/performance_tracker'
# require_relative '../handlers/subagent_stop/cache_manager'
begin
# Read input data from Claude Code
input_data = JSON.parse($stdin.read)
hook = SubagentStopHandler.new(input_data)
hook.call
hook.output_and_exit
rescue JSON::ParserError => e
warn "[SubagentStop] JSON parsing error: #{e.message}"
puts JSON.generate({
continue: false,
stopReason: "SubagentStop hook JSON parsing error: #{e.message}",
suppressOutput: false
})
exit 1 # JSON error
rescue StandardError => e
warn "[SubagentStop] Hook execution error: #{e.message}"
warn e.backtrace.join("\n") if ENV['RUBY_CLAUDE_HOOKS_DEBUG']
puts JSON.generate({
continue: false,
stopReason: "SubagentStop hook execution error: #{e.message}",
suppressOutput: false
})
exit 1 # General error
end