palladius / palladius/antigravity-ruby-sdk
🪝 [P1] Full Lifecycle Hooks (session, turn, tool error, compaction)
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 0
- Forks
- 0
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
Feature: Full Lifecycle Hooks System
Parent epic: #20 (Feature Parity with Python SDK)
Current State (v0.4.3)
We have 4 hooks + generic events in lib/antigravity/hooks.rb:
hooks.before_prompt { |text| ... } # pre-turn
hooks.after_response { |msg| ... } # post-turn
hooks.before_tool_call { |name, params| :allow / :deny }
hooks.after_tool_call { |name, params, result| modified_result }
hooks.on(:ws_message) { |msg| ... } # generic events (Ruby-only!)
Target: Full Python SDK Parity
| Hook | Python | Ruby | Status |
|---|---|---|---|
on_session_start |
✅ | ❌ | NEW |
on_session_end |
✅ | ❌ | NEW |
pre_turn |
✅ | ✅ before_prompt |
Rename? |
post_turn |
✅ | ✅ after_response |
Rename? |
pre_tool_call_decide |
✅ | ✅ before_tool_call |
✅ |
post_tool_call |
✅ | ✅ after_tool_call |
✅ |
on_tool_error |
✅ | ❌ | NEW — error recovery |
on_compaction |
✅ | ❌ | NEW — context window mgmt |
on_interaction |
✅ | ❌ | NEW — ask_question events |
| Generic events | ❌ | ✅ hooks.on(:event) |
Ruby-only! |
Proposed Ruby API
agent = Antigravity::Agent.new do |a|
# Session lifecycle
a.on_session_start { |session| puts "Session #{session.conversation_id} started" }
a.on_session_end { |session| puts "#{session.turn_count} turns, #{session.total_tokens} tokens" }
# Turn lifecycle
a.before_prompt { |text| puts ">>> #{text}" } # existing
a.after_response { |msg| puts "<<< #{msg.content}" } # existing
# Tool lifecycle
a.before_tool_call { |name, params| :allow } # existing
a.after_tool_call { |name, params, result| } # existing
a.on_tool_error { |name, params, error| "Fallback: #{error.message}" } # NEW
# Context management
a.on_compaction { |info| puts "Context compacted at turn #{info[:turn]}" } # NEW
end
Rails-Friendly Defaults 🛤️
When RAILS_ENV or RACK_ENV is set to test, auto-attach verbose hooks:
# In lib/antigravity/hooks/test_defaults.rb
module Antigravity::Hooks::TestDefaults
def self.attach!(agent)
agent.on_session_start { |s| puts "[TEST] 🟢 Session started: #{s.conversation_id}" }
agent.on_session_end { |s| puts "[TEST] 🔴 Session ended: #{s.turn_count} turns" }
agent.before_prompt { |t| puts "[TEST] ➡️ Prompt: #{t[0..80]}..." }
agent.after_response { |m| puts "[TEST] ⬅️ Response: #{m.content[0..80]}..." }
agent.before_tool_call { |n, p| puts "[TEST] 🔧 Tool: #{n}(#{p.keys.join(", ")})"; :allow }
agent.on_tool_error { |n, _, e| puts "[TEST] 💥 Tool #{n} failed: #{e.message}" }
end
end
# Auto-attach in test/development:
Antigravity.configure do |c|
c.test_hooks = true # or auto-detect from RAILS_ENV
end
Deliverables
- Add
on_session_start,on_session_endhooks (fire inconnect!/close!) - Add
on_tool_errorhook (fire inclient.rbrescue block, allow recovery) - Add
on_compactionhook (detect compaction events from WebSocket) - Add
Hooks::TestDefaultsmodule with verbose logging - Auto-attach test hooks when
ENV["RAILS_ENV"] == "test"orENV["ANTIGRAVITY_DEBUG"] - Example
11_e2e_lifecycle_hooks.rbdemonstrating all hooks - Keep backward compat:
before_prompt/after_responsestill work (aliases) - Update docs/FEATURE_PARITY.md
Priority
P1 -- hooks are the extensibility backbone. Policy engine (#21) and MCP will build on top of this.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/antigravity/hooks.rb, then trace connect! and close! for session events and the rescue block in client.rb for tool errors. Review WebSocket event handling for compaction, and the proposed lib/antigravity/hooks/test_defaults.rb structure. Done means all listed hooks and aliases work, test defaults attach under the stated environments, the example runs, and docs/FEATURE_PARITY.md is updated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100