Class: RosettAi::Behaviour::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/behaviour/manager.rb

Overview

MCP-facing facade for behaviour file management.

Provides add/modify/delete operations for behaviour YAML files, matching the interface expected by Mcp::Tools::BehaviourManageTool.

Author:

  • hugo

  • claude

Instance Method Summary collapse

Constructor Details

#initialize(behaviour_dir: nil) ⇒ Manager

Returns a new instance of Manager.

Parameters:

  • behaviour_dir (Pathname, String, nil) (defaults to: nil)

    override for testing; defaults to XDG user path (~/.config/rosett-ai/conf/behaviour/)



24
25
26
# File 'lib/rosett_ai/behaviour/manager.rb', line 24

def initialize(behaviour_dir: nil)
  @behaviour_dir = Pathname.new(behaviour_dir || RosettAi.paths.rai_conf_dir.join('behaviour'))
end

Instance Method Details

#add(name, description: nil) ⇒ Pathname

Creates a new behaviour file.

Parameters:

  • name (String)

    behaviour name

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

    behaviour description

Returns:

  • (Pathname)

    path to created file

Raises:



33
34
35
36
37
38
39
40
41
42
# File 'lib/rosett_ai/behaviour/manager.rb', line 33

def add(name, description: nil)
  path = behaviour_path(name)
  raise RosettAi::BehaviourError, "Behaviour '#{name}' already exists" if path.exist?

  data = build_template(name, description || "#{name} behaviour")
  FileUtils.mkdir_p(path.dirname)
  path.write(YAML.dump(data))
  validate_behaviour!(path)
  path
end

#delete(name, options: {}) ⇒ Boolean

Deletes a behaviour file.

Parameters:

  • name (String)

    behaviour name

  • options (Hash) (defaults to: {})

    :force_delete to skip existence check

Returns:

  • (Boolean)

    true on success

Raises:



63
64
65
66
67
68
69
70
71
# File 'lib/rosett_ai/behaviour/manager.rb', line 63

def delete(name, options: {})
  path = behaviour_path(name)
  force_delete = options.fetch(:force_delete, false)
  raise RosettAi::BehaviourError, "Behaviour '#{name}' not found" unless force_delete || path.exist?

  path.delete if path.exist?
  cleanup_compiled_rules(name)
  path
end

#modify(name, description: nil) ⇒ Pathname

Modifies an existing behaviour file.

Parameters:

  • name (String)

    behaviour name

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

    new description

Returns:

  • (Pathname)

    path to modified file

Raises:



49
50
51
52
53
54
55
56
# File 'lib/rosett_ai/behaviour/manager.rb', line 49

def modify(name, description: nil)
  path = behaviour_path(name)
  raise RosettAi::BehaviourError, "Behaviour '#{name}' not found" unless path.exist?

  update_behaviour_file(path, description)
  validate_behaviour!(path)
  path
end