Class: RosettAi::Mcp::Tools::HookInstallTool
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Tools::HookInstallTool
- Defined in:
- lib/rosett_ai/mcp/tools/hook_install_tool.rb
Overview
MCP tool: install enforcement hook + register in settings.json.
MUTATION tool — writes hook script to disk and updates Claude Code settings.json. Auto-backs up affected files before writing. Confirmation is required by default.
Constant Summary collapse
- TOOL_NAME =
'rai_hook_install'- DESCRIPTION =
'Install enforcement hook: generate script, write to disk, register in settings'- ANNOTATIONS =
{ 'readOnlyHint' => false, 'destructiveHint' => true, 'idempotentHint' => true, 'openWorldHint' => false }.freeze
- HOOK_DIR_NAME =
'hooks'- HOOK_FILENAME =
'rai-enforce.rb'- BACKUP_SUFFIX =
'.rai-backup'
Instance Method Summary collapse
-
#call(behaviour_name: nil, rule_id: nil, scope: 'global', confirm: false) ⇒ Hash
Installs the enforcement hook.
Instance Method Details
#call(behaviour_name: nil, rule_id: nil, scope: 'global', confirm: false) ⇒ Hash
Installs the enforcement hook.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rosett_ai/mcp/tools/hook_install_tool.rb', line 43 def call(behaviour_name: nil, rule_id: nil, scope: 'global', confirm: false) return confirmation_required_response unless confirm preview = HookPreviewTool.new.call( behaviour_name: behaviour_name, rule_id: rule_id, scope: scope ) return preview if preview[:error] hook_path = resolve_hook_path(scope) backup_path = backup_existing(hook_path) write_hook(hook_path, preview[:script]) settings_diff = register_in_settings(hook_path, scope) { installed: true, hook_path: hook_path.to_s, backup_path: backup_path&.to_s, rules_count: preview[:rules_count], behaviours: preview[:behaviours], scope: scope, settings_updated: settings_diff[:updated], message: "Hook installed at #{hook_path} with #{preview[:rules_count]} rule(s)" } rescue StandardError => e ResponseHelper.error("Hook install failed: #{e.}") end |