Module: Clacky::Advisor

Defined in:
lib/clacky/default_extensions/advisor/hooks/advisor.rb

Defined Under Namespace

Classes: Worker

Constant Summary collapse

RULE_PATH =
File.expand_path("../advisors/general.md", __dir__)
USER_CONFIG_PATH =
File.expand_path("~/.clacky/advisor.yml")
AGENTS_DIR =
File.expand_path("~/.clacky/agents")
PROFILE_CHARS =
1000
DEFAULTS =
{
  "enabled" => false,
  "max_tokens" => 8000
}.freeze
WRITE_TOOLS =
%w[write edit file_write file_edit].freeze
TRAIL_LIMIT =
30
BRIEF_ACTIONS =
8
CONVERSATION_TURNS =
8
SUMMARY_LIMIT =
200
MESSAGE_LIMIT =
200
MAX_OPTIONS =
3
ACTION_LIMIT =
500
REASON_LIMIT =
200
FALLBACK_REASON_SEPARATOR =

Models copy the panel's own " · " separator when they drop the JSON format. Deliberately structural: a localized "Reason:" label would need one pattern per language, so those lines keep the label inside the action.

/\s+·\s+/.freeze
THINK_BLOCK =

Some providers keep thinking inline in content (e.g. MiniMax), and the closing tag is missing whenever the reply gets cut short.

%r{<think>.*?</think>}m.freeze
UNCLOSED_THINK =
/<think>[\s\S]*\z/.freeze
FALLBACK_LIST_MARKER =

A degraded line only counts as an option when the model marked it up as one: a list bullet or a [action] wrapper. Without this, reasoning prose turns into three bogus suggestions.

/\A(?:[-*•]|\d+[.)])\s+/.freeze
FALLBACK_BRACKETED =
/\A\[([^\]]+)\]\s*(.*)\z/m.freeze

Class Method Summary collapse

Class Method Details

.config_for(_agent) ⇒ Object



61
62
63
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 61

def config_for(_agent)
  DEFAULTS.merge(user_config)
end

.enabled?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 57

def enabled?
  config_for(nil)["enabled"] != false
end

.enabled_for?(agent) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 52

def enabled_for?(agent)
  return false if agent.instance_variable_get(:@is_subagent)
  enabled?
end

.reset_user_config!Object



78
79
80
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 78

def reset_user_config!
  @user_config = nil
end

.set_enabled(value) ⇒ Object

Persist the enabled flag to ~/.clacky/advisor.yml, keeping any other user-set keys (model, max_tokens) intact. Resets the cache so the next enabled?/config_for read reflects the new value immediately.



68
69
70
71
72
73
74
75
76
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 68

def set_enabled(value)
  reset_user_config!
  current = user_config
  current["enabled"] = value ? true : false
  FileUtils.mkdir_p(File.dirname(USER_CONFIG_PATH))
  File.write(USER_CONFIG_PATH, YAML.dump(current))
  reset_user_config!
  true
end

.worker_for(agent) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/clacky/default_extensions/advisor/hooks/advisor.rb', line 82

def worker_for(agent)
  worker = agent.instance_variable_get(:@advisor_worker)
  return worker if worker

  worker = Worker.new(agent)
  agent.instance_variable_set(:@advisor_worker, worker)
  worker
end