Class: Clacky::RichUI::EntryTracker
- Inherits:
-
Object
- Object
- Clacky::RichUI::EntryTracker
- Defined in:
- lib/clacky/rich_ui/entry_tracker.rb
Overview
Lightweight id-based entry tracker for RubyRich Transcript entries.
Replaces the fragile @tool_ids stack with explicit id-based tracking. RubyRich’s AgentShell already returns stable ids from start_tool_call and accepts ids on finish_tool_call / update_tool_call / remove_entry. EntryTracker wraps these with a semantic API and is ready for future expansion (tracking markdown blocks, thinking entries, etc.).
Instance Method Summary collapse
-
#current_tool_id ⇒ Object
The most recent tool_call id without popping.
-
#initialize ⇒ EntryTracker
constructor
A new instance of EntryTracker.
-
#pending_count ⇒ Object
Number of pending tool calls.
-
#pending_tool? ⇒ Boolean
Are there any pending (unfinished) tool calls?.
-
#pop_tool_id ⇒ Object
Pop and return the most recent tool_call id.
-
#register_tool(id) ⇒ Object
Record a newly started tool call.
-
#remove(id) ⇒ Object
Remove a specific entry by id.
Constructor Details
#initialize ⇒ EntryTracker
Returns a new instance of EntryTracker.
13 14 15 16 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 13 def initialize @tool_stack = [] # ordered tool_call ids (push on start, pop on finish/error) @entries = {} # id => { type:, ... } for future cross-type tracking end |
Instance Method Details
#current_tool_id ⇒ Object
The most recent tool_call id without popping.
35 36 37 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 35 def current_tool_id @tool_stack.last end |
#pending_count ⇒ Object
Number of pending tool calls.
51 52 53 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 51 def pending_count @tool_stack.length end |
#pending_tool? ⇒ Boolean
Are there any pending (unfinished) tool calls?
40 41 42 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 40 def pending_tool? !@tool_stack.empty? end |
#pop_tool_id ⇒ Object
Pop and return the most recent tool_call id. Returns nil when the stack is empty (tool output without a preceding call).
28 29 30 31 32 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 28 def pop_tool_id id = @tool_stack.pop @entries.delete(id) if id id end |
#register_tool(id) ⇒ Object
Record a newly started tool call. Returns the id for chaining convenience.
20 21 22 23 24 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 20 def register_tool(id) @tool_stack << id @entries[id] = { type: :tool_call } id end |
#remove(id) ⇒ Object
Remove a specific entry by id.
45 46 47 48 |
# File 'lib/clacky/rich_ui/entry_tracker.rb', line 45 def remove(id) @entries.delete(id) @tool_stack.delete(id) end |