Skip to content

Refactor agent#40

Merged
yaacov merged 1 commit into
mainfrom
refactor-agent
Jun 3, 2026
Merged

Refactor agent#40
yaacov merged 1 commit into
mainfrom
refactor-agent

Conversation

@yaacov

@yaacov yaacov commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • New Features

    • Added configurable policy system with bundled default policies
    • Added /exit slash command support
    • Added LLM debug traffic dumping capability
  • Improvements

    • Configurable history limits and debug output directory settings
    • Enhanced path handling with home directory expansion support
    • Improved theme selection interface and collapsible UI blocks

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yaacov, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 21 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86581667-f072-4713-8817-b28f9d8dafb7

📥 Commits

Reviewing files that changed from the base of the PR and between cb205d9 and 81c34dd.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .gitignore
  • mtv_agent/server/agent.py
  • mtv_agent/server/app.py
  • mtv_agent/server/commands.py
  • mtv_agent/server/config.py
  • mtv_agent/server/data/config.json.example
  • mtv_agent/server/data/policies.json.example
  • mtv_agent/server/init.py
  • mtv_agent/server/llm/client.py
  • mtv_agent/server/llm/dump.py
  • mtv_agent/server/mcp/manager.py
  • mtv_agent/server/mcp/skills.py
  • mtv_agent/server/tools.py
  • mtv_agent/tui/app.py
  • mtv_agent/tui/widgets/chat.py
  • mtv_agent/tui/widgets/collapsible_block.py
  • mtv_agent/tui/widgets/input.py
  • mtv_agent/tui/widgets/option_selector.py
📝 Walkthrough

Walkthrough

This PR enhances the agent with debug instrumentation, modular tool execution with policy enforcement, and TUI improvements. It introduces HTTP request/response dumping for LLM calls, extracts tool-call handling into a reusable module, externalizes MCP server policies to bundled configuration, and upgrades TUI widgets with a new collapsible framework and interactive theme selection.

Changes

Agent Enhancement: Debug, Execution, and UI

Layer / File(s) Summary
Configuration, Bundled Data, and Settings
mtv_agent/server/config.py, mtv_agent/server/data/config.json.example, mtv_agent/server/data/policies.json.example, mtv_agent/server/init.py, .gitignore
New bundled_policies_example() helper and Settings fields (max_history_chars, dump_llm, dump_dir) added; config.json.example extended with agent.maxHistoryChars and new debug block; policies.json.example introduced with default policy and per-server bash/kubectl configurations; workspace init updated to create policies.json alongside config and MCP files.
LLM HTTP Request/Response Dumping
mtv_agent/server/llm/dump.py, mtv_agent/server/llm/client.py
New LLMDumper class captures outgoing requests and incoming responses via httpx event hooks, serializes to JSON with sanitized Authorization headers, and buffers/flushes per-session files; LLMClient optionally integrates dumper via dump_dir parameter and exposes dumper property.
Tool Execution Module with Policy and Approval
mtv_agent/server/tools.py
New module provides execute_tool_call async generator that checks tool policy, handles reject/ask/allow outcomes, manages approval workflow, executes tools safely, truncates output, and yields structured SSE events; includes trim_history and helper functions for safe execution and output sizing.
Agent Loop: Session Tracking and Tool Delegation
mtv_agent/server/agent.py
run_stream() extended with session_id and max_history_chars parameters; initial messages centralized in _build_messages() helper with history trimming; tool-call handling delegated to execute_tool_call module; LLM dumper session management integrated per iteration.
Application Lifespan: ChatStore and LLMClient Setup
mtv_agent/server/app.py
ChatStore initialization moved to lifespan from main(); LLMClient conditionally receives dump_dir when dump_llm enabled; /api/chat call to run_stream() forwards session_id and max_history_chars; Uvicorn startup switches to direct app invocation.
MCP Manager: Bundled Policy Loading and Defaults
mtv_agent/server/mcp/manager.py
Hardcoded DEFAULT_BASH_POLICY removed; new _load_default_policies() and _parse_server_policy() load bundled policies; MCPManager.start() applies defaults before server registration; _reset_policies() reapplies bundled defaults instead of hardcoded values.
Path Expansion Helpers
mtv_agent/server/commands.py, mtv_agent/server/mcp/skills.py
commands_dir and skills_dir paths now support ~ expansion via Path.expanduser().
TUI: CollapsibleBlock Widget Framework
mtv_agent/tui/widgets/collapsible_block.py
New CollapsibleBlock customizes Collapsible with injected CollapseHeader, consistent CSS styling, and title management for reusable collapsible sections.
TUI: Chat Display and Input Updates
mtv_agent/tui/widgets/chat.py, mtv_agent/tui/widgets/input.py
ThinkingIndicator refactored to inherit from CollapsibleBlock with tool-count tracking (_tool_count) and spinner/timer coordination; ChatInput adds /exit command and updates border styling; hint element removed.
TUI: OptionSelector Widget for Theme Selection
mtv_agent/tui/widgets/option_selector.py
New OptionSelector renders title and OptionList with optional current selection highlighting; posts Selected message on choice.
TUI App: Theme Selection Flow and Info Block Refactor
mtv_agent/tui/app.py
Imports updated for CollapsibleBlock; _info_block() returns CollapsibleBlock; /quit and /exit share exit branch; /theme without args mounts OptionSelector for selection; new _apply_theme() method applies, persists, and updates UI for selected theme; on_option_selected() handler manages selection and refocuses input.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A rabbit hops through configs bright,
Tool execution now done right,
Dumpers trace the LLM's call,
While widgets dance and themes install,
Policies bundled, history trimmed—
The agent's future gently brimmed! 🌙

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Refactor agent' is vague and generic, providing no meaningful information about the specific changes in this comprehensive pull request. Replace with a more descriptive title that highlights the primary change, such as 'Refactor agent loop with policy enforcement and LLM request dumping' or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-agent

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: yaacov <yzamir@redhat.com>
@yaacov yaacov merged commit 1658b95 into main Jun 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant