Class: RubynCode::Checkpoint::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/checkpoint/hook.rb

Overview

A :pre_tool_use hook that snapshots a file’s original contents into the current checkpoint just before a mutating tool changes it. Only the file-mutating tools are watched; everything else is ignored.

Constant Summary collapse

MUTATING_TOOLS =
%w[write_file edit_file].freeze

Instance Method Summary collapse

Constructor Details

#initialize(manager:) ⇒ Hook

Returns a new instance of Hook.

Parameters:



12
13
14
# File 'lib/rubyn_code/checkpoint/hook.rb', line 12

def initialize(manager:)
  @manager = manager
end

Instance Method Details

#call(tool_name:, tool_input: {}, **_kwargs) ⇒ nil

Returns never blocks the tool (returns no deny decision).

Returns:

  • (nil)

    never blocks the tool (returns no deny decision)



17
18
19
20
21
22
23
# File 'lib/rubyn_code/checkpoint/hook.rb', line 17

def call(tool_name:, tool_input: {}, **_kwargs)
  return nil unless MUTATING_TOOLS.include?(tool_name.to_s)

  path = tool_input[:path] || tool_input['path']
  @manager.record_file(path) if path
  nil
end