Class: CodexNotify::HookRunner
- Inherits:
-
Object
- Object
- CodexNotify::HookRunner
- Defined in:
- lib/codex_notify/hook_runner.rb
Constant Summary collapse
- RESET_THREAD_PROMPT =
'---'- SESSION_RESET_SOURCES =
%w[startup clear].freeze
- INTERNAL_AMBIENT_SUGGESTIONS_PROMPTS =
[ [ '# Overview', 'Generate 0 to 3 hyperpersonalized suggestions for what this user can do with Codex in this local project', "Suggest actionable tasks that they would actually act on/click" ].freeze, [ 'You are an expert at upholding safety and compliance standards for Codex ambient suggestions.', 'ambient suggestion candidates', '## 1. Policies to always exclude' ].freeze ].freeze
- INTERNAL_AMBIENT_SUGGESTIONS_RESPONSES =
[ [ 'exclude', 'suggestion_id', 'Only output the JSON object' ].freeze, [ 'suggestions to exclude', 'reason', 'applicable policy' ].freeze ].freeze
Instance Method Summary collapse
-
#initialize(token:, channel:, user_name:, title:, state_file:, mode: HookConfig::DEFAULT_MODE, stdout: $stdout, client: nil, store: nil, outbox: nil, outbox_dir: nil) ⇒ HookRunner
constructor
A new instance of HookRunner.
- #run(event:) ⇒ Object
Constructor Details
#initialize(token:, channel:, user_name:, title:, state_file:, mode: HookConfig::DEFAULT_MODE, stdout: $stdout, client: nil, store: nil, outbox: nil, outbox_dir: nil) ⇒ HookRunner
Returns a new instance of HookRunner.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/codex_notify/hook_runner.rb', line 39 def initialize(token:, channel:, user_name:, title:, state_file:, mode: HookConfig::DEFAULT_MODE, stdout: $stdout, client: nil, store: nil, outbox: nil, outbox_dir: nil) @store = store || HookStore.new(state_file) client ||= SlackClient.new(token:, channel:) outbox ||= SlackOutbox.new(outbox_dir || "#{state_file}.outbox") @publisher = HookThreadPublisher.new(client:, store: @store, outbox:, channel:) @user_name = user_name @title = title @mode = mode @stdout = stdout end |
Instance Method Details
#run(event:) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/codex_notify/hook_runner.rb', line 51 def run(event:) @store.with_session_lock(event.session_id) do case event.name when 'SessionStart' handle_session_start(event) when 'UserPromptSubmit' handle_user_prompt_submit(event) when 'PreToolUse' handle_pre_tool_use(event) when 'PostToolUse' handle_post_tool_use(event) when 'PermissionRequest' (event) when 'Stop' handle_stop(event) end end result = @publisher.drain result&.failed&.any? || result&.needs_review&.any? ? 1 : 0 end |