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 =
'rai_hook_preview'
DESCRIPTION =
'Preview generated enforcement hook script (read-only, no side effects)'
ANNOTATIONS =
{
  'readOnlyHint' => true,
  'destructiveHint' => false,
  'idempotentHint' => true,
  'openWorldHint' => false
}.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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rosett_ai/mcp/tools/hook_preview_tool.rb', line 40

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