Class: ClaudeMemory::Commands::HookCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- ClaudeMemory::Commands::HookCommand
- Defined in:
- lib/claude_memory/commands/hook_command.rb
Overview
Handles hook entrypoints (ingest, sweep, publish) Supports –async flag to fork and run in background
Constant Summary collapse
- ASYNC_SUBCOMMANDS =
%w[ingest sweep publish].freeze
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
Methods inherited from BaseCommand
Constructor Details
This class inherits a constructor from ClaudeMemory::Commands::BaseCommand
Instance Method Details
#call(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/claude_memory/commands/hook_command.rb', line 12 def call(args) subcommand = args.first unless subcommand stderr.puts "Usage: claude-memory hook <ingest|sweep|publish|context> [options]" stderr.puts "\nReads hook payload JSON from stdin." stderr.puts "Options: --async Run in background (ingest, sweep, publish only)" return Hook::ExitCodes::ERROR end unless %w[ingest sweep publish context].include?(subcommand) stderr.puts "Unknown hook command: #{subcommand}" stderr.puts "Available: ingest, sweep, publish, context" return Hook::ExitCodes::ERROR end opts = (args[1..] || [], {db: ClaudeMemory.project_db_path, async: false}) do |o| OptionParser.new do |parser| parser.on("--db PATH", "Database path") { |v| o[:db] = v } parser.on("--async", "Run in background (non-blocking)") { o[:async] = true } end end return Hook::ExitCodes::ERROR if opts.nil? payload = parse_hook_payload return Hook::ExitCodes::ERROR unless payload if opts[:async] && ASYNC_SUBCOMMANDS.include?(subcommand) return run_async(subcommand, payload, opts) end execute_sync(subcommand, payload, opts) rescue ClaudeMemory::Hook::Handler::PayloadError => e stderr.puts "Payload error: #{e.}" Hook::ExitCodes::ERROR rescue => e classify_error(e) end |