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 =
Returns MCP tool identifier string.
'rai_hook_install'- DESCRIPTION =
Returns Human-readable description of this tool.
'Install enforcement hook: generate script, write to disk, register in settings'- ANNOTATIONS =
Returns MCP protocol annotations describing tool capabilities.
{ 'readOnlyHint' => false, 'destructiveHint' => true, 'idempotentHint' => true, 'openWorldHint' => false }.freeze
- INPUT_SCHEMA =
Returns JSON Schema defining the tool input parameters.
{ type: 'object', properties: { behaviour_name: { type: 'string', description: 'Behaviour to generate hook for (default: all enforceable)' }, rule_id: { type: 'string', description: 'Specific rule ID to generate hook for' }, scope: { type: 'string', enum: ['global', 'local'], description: 'Installation scope (default: global)' }, confirm: { type: 'boolean', description: 'Must be true to actually install — safety gate (default: false)' } } }.freeze
- HOOK_DIR_NAME =
Returns Subdirectory name for hook scripts.
'hooks'- HOOK_FILENAME =
Returns Default filename for generated hook scripts.
'rai-enforce.rb'- BACKUP_SUFFIX =
Returns File extension appended to backup copies.
'.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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rosett_ai/mcp/tools/hook_install_tool.rb', line 73 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 |