aia 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/CHANGELOG.md +9 -3
- data/lib/aia/context_manager.rb +17 -1
- data/lib/aia/directive_processor.rb +16 -2
- data/lib/aia/ruby_llm_adapter.rb +62 -0
- data/lib/aia/session.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22c90e43d930e16211a66eca8d8698791de4e0c3d867ddcbf9ad6cec98e88202
|
4
|
+
data.tar.gz: 5350fd33ec94debce7dc1f055cdb1b8eef6663506e6ae6b3d4d7f057537c1ea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f6953cb27609d45712b76c154ba949ac3b745004314ad48c1b234a49084db9594938a2a039e56650226cf821c0f52ed834b208665299b8b1677491860f8afd
|
7
|
+
data.tar.gz: 03f418e5e112be5cd5f3d31a923e628e9c66a59838272fa0d80899b00cfc4065a079f06d03bb92e4139a3b1089f1d7bb05aee89ba3d820bf460bad177cebb52e
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.1
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
## [Unreleased]
|
3
|
-
### [0.9.0] WIP
|
4
|
-
- Adding MCP Client suppot
|
5
|
-
- removed the CLI options --erb and --shell but kept them in the config file with a default of true for both
|
6
3
|
|
7
4
|
## Released
|
8
5
|
|
6
|
+
### [0.9.1] 2025-05-16
|
7
|
+
- rethink MCP approach in favor of just RubyLLM::Tool
|
8
|
+
- fixed problem with //clear
|
9
|
+
- fixed a problem with a priming prompt in a chat loop
|
10
|
+
|
11
|
+
### [0.9.0] 2025-05-13
|
12
|
+
- Adding experimental MCP Client suppot
|
13
|
+
- removed the CLI options --erb and --shell but kept them in the config file with a default of true for both
|
14
|
+
|
9
15
|
### [0.8.6] 2025-04-23
|
10
16
|
- Added a client adapter for the ruby_llm gem
|
11
17
|
- Added the adapter config item and the --adapter option to select at runtime which client to use ai_client or ruby_llm
|
data/lib/aia/context_manager.rb
CHANGED
@@ -41,7 +41,23 @@ module AIA
|
|
41
41
|
@context = [@context.first]
|
42
42
|
else
|
43
43
|
@context = []
|
44
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
# Attempt to clear the LLM client's context as well
|
47
|
+
begin
|
48
|
+
if AIA.config.client && AIA.config.client.respond_to?(:clear_context)
|
49
|
+
AIA.config.client.clear_context
|
50
|
+
end
|
51
|
+
|
52
|
+
if AIA.config.respond_to?(:llm) && AIA.config.llm && AIA.config.llm.respond_to?(:clear_context)
|
53
|
+
AIA.config.llm.clear_context
|
54
|
+
end
|
55
|
+
|
56
|
+
if defined?(RubyLLM) && RubyLLM.respond_to?(:chat) && RubyLLM.chat.respond_to?(:clear_history)
|
57
|
+
RubyLLM.chat.clear_history
|
58
|
+
end
|
59
|
+
rescue => e
|
60
|
+
AIA.debug_me(tag: '== context_manager clear_context error =='){[ :e, e.message, e.backtrace ]}
|
45
61
|
end
|
46
62
|
end
|
47
63
|
|
@@ -51,14 +51,28 @@ module AIA
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def directive?(a_string)
|
54
|
-
|
54
|
+
# Handle RubyLLM::Message objects by extracting their content first
|
55
|
+
content = if a_string.is_a?(RubyLLM::Message)
|
56
|
+
a_string.content rescue a_string.to_s
|
57
|
+
else
|
58
|
+
a_string.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
content.strip.start_with?(PromptManager::Prompt::DIRECTIVE_SIGNAL)
|
55
62
|
end
|
56
63
|
|
57
64
|
# Used with the chat loop to allow user to enter a single directive
|
58
65
|
def process(a_string, context_manager)
|
59
66
|
return a_string unless directive?(a_string)
|
60
67
|
|
61
|
-
|
68
|
+
# Handle RubyLLM::Message objects by extracting their content first
|
69
|
+
content = if a_string.is_a?(RubyLLM::Message)
|
70
|
+
a_string.content rescue a_string.to_s
|
71
|
+
else
|
72
|
+
a_string.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
key = content.strip
|
62
76
|
sans_prefix = key[@prefix_size..]
|
63
77
|
args = sans_prefix.split(' ')
|
64
78
|
method_name = args.shift.downcase
|
data/lib/aia/ruby_llm_adapter.rb
CHANGED
@@ -82,6 +82,68 @@ module AIA
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
# Clear the chat context/history
|
86
|
+
# Needed for the //clear directive
|
87
|
+
def clear_context
|
88
|
+
AIA.debug_me(tag: '== AGGRESSIVELY clearing LLM context ==') do
|
89
|
+
begin
|
90
|
+
# Option 1: Directly clear the messages array in the current chat object
|
91
|
+
if @chat.instance_variable_defined?(:@messages)
|
92
|
+
AIA.debug_me("Directly clearing @messages array")
|
93
|
+
old_messages = @chat.instance_variable_get(:@messages)
|
94
|
+
AIA.debug_me{[:old_messages, old_messages.length]}
|
95
|
+
# Force a completely empty array, not just attempting to clear it
|
96
|
+
@chat.instance_variable_set(:@messages, [])
|
97
|
+
end
|
98
|
+
|
99
|
+
# Option 2: Force RubyLLM to create a new chat instance at the global level
|
100
|
+
# This ensures any shared state is reset
|
101
|
+
AIA.debug_me("Force global RubyLLM chat reset")
|
102
|
+
model_info = extract_model_parts(@model)
|
103
|
+
RubyLLM.instance_variable_set(:@chat, nil) if RubyLLM.instance_variable_defined?(:@chat)
|
104
|
+
|
105
|
+
# Option 3: Create a completely fresh chat instance for this adapter
|
106
|
+
@chat = nil # First nil it to help garbage collection
|
107
|
+
@chat = RubyLLM.chat(model: model_info[:model])
|
108
|
+
AIA.debug_me("Created fresh RubyLLM::Chat instance")
|
109
|
+
|
110
|
+
# Option 4: Call official clear_history method if it exists
|
111
|
+
if @chat.respond_to?(:clear_history)
|
112
|
+
AIA.debug_me("Calling clear_history method")
|
113
|
+
@chat.clear_history
|
114
|
+
end
|
115
|
+
|
116
|
+
# Option 5: If chat has messages, force set it to empty again as a final check
|
117
|
+
if @chat.instance_variable_defined?(:@messages) && !@chat.instance_variable_get(:@messages).empty?
|
118
|
+
AIA.debug_me("FINAL CHECK: @messages still not empty, forcing empty")
|
119
|
+
@chat.instance_variable_set(:@messages, [])
|
120
|
+
end
|
121
|
+
|
122
|
+
# Reset any MCP tools configuration
|
123
|
+
begin
|
124
|
+
mcp_client, mcp_tools = generate_mcp_tools(model_info[:provider])
|
125
|
+
if mcp_tools && !mcp_tools.empty?
|
126
|
+
AIA.debug_me("Reconfiguring MCP tools")
|
127
|
+
RubyLLM::Chat.with_mcp(client: mcp_client, call_tool_method: :call_tool, tools: mcp_tools)
|
128
|
+
end
|
129
|
+
rescue => mcp_error
|
130
|
+
AIA.debug_me{[:mcp_error, mcp_error.message]}
|
131
|
+
end
|
132
|
+
|
133
|
+
# Final verification
|
134
|
+
new_messages = @chat.instance_variable_defined?(:@messages) ? @chat.instance_variable_get(:@messages) : []
|
135
|
+
AIA.debug_me{[:new_messages, new_messages.length]}
|
136
|
+
|
137
|
+
return "Chat context successfully cleared."
|
138
|
+
rescue => e
|
139
|
+
AIA.debug_me{
|
140
|
+
[ :e, e.message, e.backtrace ]
|
141
|
+
}
|
142
|
+
return "Error clearing chat context: #{e.message}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
85
147
|
def respond_to_missing?(method, include_private = false)
|
86
148
|
@chat.respond_to?(method) || super
|
87
149
|
end
|
data/lib/aia/session.rb
CHANGED
@@ -257,6 +257,26 @@ module AIA
|
|
257
257
|
directive_output = @directive_processor.process(follow_up_prompt, @context_manager)
|
258
258
|
|
259
259
|
if follow_up_prompt.strip.start_with?('//clear')
|
260
|
+
# The directive processor has called context_manager.clear_context
|
261
|
+
# but we need a more aggressive approach to fully clear all context
|
262
|
+
|
263
|
+
# First, clear the context manager's context
|
264
|
+
@context_manager.clear_context(keep_system_prompt: true)
|
265
|
+
|
266
|
+
# Second, try clearing the client's context
|
267
|
+
if AIA.config.client && AIA.config.client.respond_to?(:clear_context)
|
268
|
+
AIA.config.client.clear_context
|
269
|
+
end
|
270
|
+
|
271
|
+
# Third, completely reinitialize the client to ensure fresh state
|
272
|
+
# This is the most aggressive approach to ensure no context remains
|
273
|
+
begin
|
274
|
+
AIA.config.client = AIA::RubyLLMAdapter.new
|
275
|
+
AIA.debug_me("Completely reinitialized client for //clear directive")
|
276
|
+
rescue => e
|
277
|
+
AIA.debug_me("Error reinitializing client: #{e.message}")
|
278
|
+
end
|
279
|
+
|
260
280
|
@ui_presenter.display_info("Chat context cleared.")
|
261
281
|
next
|
262
282
|
elsif directive_output.nil? || directive_output.strip.empty?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
351
|
- !ruby/object:Gem::Version
|
352
352
|
version: '0'
|
353
353
|
requirements: []
|
354
|
-
rubygems_version: 3.6.
|
354
|
+
rubygems_version: 3.6.9
|
355
355
|
specification_version: 4
|
356
356
|
summary: 'AI Assistant: dynamic prompts, shell & Ruby integration, and seamless chat
|
357
357
|
workflows.'
|