Class: RosettAi::Mcp::Tools::HookPreviewTool

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/mcp/tools/hook_preview_tool.rb

Overview

MCP tool: preview a generated enforcement hook script.

Generates a Ruby hook script from behaviour rules without writing anything to disk. Allows inspection before installing via HookInstallTool. Strictly read-only.

Delegates generation to Enforcement::HookGenerator and validation to Enforcement::Validator.

Author:

  • hugo

  • claude

Constant Summary collapse

TOOL_NAME =

Returns MCP tool identifier string.

Returns:

  • (String)

    MCP tool identifier string.

'rai_hook_preview'
DESCRIPTION =

Returns Human-readable description of this tool.

Returns:

  • (String)

    Human-readable description of this tool.

'Preview generated enforcement hook script (read-only, no side effects)'
ANNOTATIONS =

Returns MCP protocol annotations describing tool capabilities.

Returns:

  • (Hash)

    MCP protocol annotations describing tool capabilities.

{
  'readOnlyHint' => true,
  'destructiveHint' => false,
  'idempotentHint' => true,
  'openWorldHint' => false
}.freeze
INPUT_SCHEMA =

Returns JSON Schema defining the tool input parameters.

Returns:

  • (Hash)

    JSON Schema defining the tool input parameters.

{
  type: 'object',
  properties: {
    behaviour_name: {
      type: 'string',
      description: 'Behaviour to preview hook for (default: all enforceable)'
    },
    rule_id: {
      type: 'string',
      description: 'Specific rule ID to preview hook for'
    },
    scope: {
      type: 'string',
      description: 'Preview scope context'
    }
  }
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(behaviour_name: nil, rule_id: nil, scope: nil) ⇒ Hash

Generates a preview of the enforcement hook script.

Parameters:

  • behaviour_name (String, nil) (defaults to: nil)

    specific behaviour to generate for

  • rule_id (String, nil) (defaults to: nil)

    specific rule within the behaviour

  • scope (String, nil) (defaults to: nil)

    scope filter ('global', 'project')

Returns:

  • (Hash)

    generated script content and metadata



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rosett_ai/mcp/tools/hook_preview_tool.rb', line 62

def call(behaviour_name: nil, rule_id: nil, scope: nil)
  behaviours = load_behaviours(behaviour_name, scope)
  validated = validate_and_collect(behaviours, rule_id)

  return ResponseHelper.error('No enforceable rules found') if validated[:rules].empty?

  script = generate_script(validated)
  build_response(script, validated, scope)
rescue StandardError => e
  ResponseHelper.error("Hook preview failed: #{e.message}")
end