Skip to content

refactor: consolidate app and provider runtimes#3

Merged
yanmxa merged 1 commit intomainfrom
architecture-review
Apr 4, 2026
Merged

refactor: consolidate app and provider runtimes#3
yanmxa merged 1 commit intomainfrom
architecture-review

Conversation

@yanmxa
Copy link
Copy Markdown
Owner

@yanmxa yanmxa commented Apr 4, 2026

Summary

  • consolidate app runtime wiring around shared tool execution, cancellation propagation, and conversation helpers
  • split oversized app packages and schema/render files into smaller focused units
  • introduce shared provider stream utilities and add regression coverage for runtime/permission/progress paths

Testing

  • GOCACHE=/tmp/gocache go test ./internal/provider/streamutil ./internal/provider/openai ./internal/provider/anthropic ./internal/provider/google ./internal/provider/moonshot ./internal/provider/alibaba ./internal/app ./internal/core ./internal/agent ./internal/tool

Summary by CodeRabbit

  • Documentation

    • Added architecture review roadmap documenting system design and phased refactoring strategy.
  • Bug Fixes

    • Improved tool execution with proper context cancellation to prevent orphaned operations.
    • Enhanced permission handling with standardized tool classification.
  • Improvements

    • Optimized provider streaming state management across all LLM implementations.
    • Refactored plugin selector and model/provider selection workflows for better usability.
    • Unified tool execution pathway with improved error handling and progress reporting.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @yanmxa, your pull request is larger than the review limit of 150000 diff characters

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 829fe0ff-3d85-4678-8a72-11f3363a00e3

📥 Commits

Reviewing files that changed from the base of the PR and between d40e68c and 5ea3541.

📒 Files selected for processing (50)
  • docs/architecture-review-roadmap.md
  • internal/agent/executor.go
  • internal/app/approval/model.go
  • internal/app/handler_approval.go
  • internal/app/handler_compact.go
  • internal/app/handler_input.go
  • internal/app/handler_input_submit.go
  • internal/app/handler_mode.go
  • internal/app/handler_provider.go
  • internal/app/handler_stream.go
  • internal/app/handler_tool.go
  • internal/app/model.go
  • internal/app/model_init.go
  • internal/app/output/model.go
  • internal/app/output/update.go
  • internal/app/plugin/load.go
  • internal/app/plugin/model.go
  • internal/app/plugin/render.go
  • internal/app/prompt_suggest.go
  • internal/app/provider/handler.go
  • internal/app/provider/load.go
  • internal/app/provider/model.go
  • internal/app/provider/render.go
  • internal/app/render/message.go
  • internal/app/render/message_assistant.go
  • internal/app/render/message_tool.go
  • internal/app/render/progress.go
  • internal/app/runtime_conversation.go
  • internal/app/tool/run.go
  • internal/app/tool/run_test.go
  • internal/app/tool/state.go
  • internal/config/permission.go
  • internal/core/core.go
  • internal/core/core_test.go
  • internal/permission/permission.go
  • internal/permission/permission_test.go
  • internal/provider/alibaba/client.go
  • internal/provider/anthropic/client.go
  • internal/provider/google/client.go
  • internal/provider/moonshot/client.go
  • internal/provider/openai/client.go
  • internal/provider/streamutil/streamutil.go
  • internal/provider/streamutil/streamutil_test.go
  • internal/tool/execute.go
  • internal/tool/execute_test.go
  • internal/tool/schema.go
  • internal/tool/schema_agent.go
  • internal/tool/schema_base.go
  • internal/tool/schema_task.go
  • internal/ui/progress/progress.go

📝 Walkthrough

Walkthrough

This pull request refactors internal systems across tool execution, provider streaming, model initialization, and UI rendering. Changes include extracting executor helper methods, consolidating tool schemas, introducing a shared provider streaming utility, separating UI rendering from business logic in plugin/provider selectors, centralizing progress/output management, and introducing a completion decision abstraction in the core loop.

Changes

Cohort / File(s) Summary
Documentation
docs/architecture-review-roadmap.md
Adds architecture review roadmap documenting scope, findings, and phased refactor strategy with concrete acceptance criteria.
Core Executor & Loop
internal/agent/executor.go, internal/core/core.go
Extracts executor validation/setup/hooks into helper methods; introduces CompletionDecision and DecideCompletion to centralize post-response control flow logic.
Tool Schema Reorganization
internal/tool/schema*.go, internal/tool/execute.go
Splits monolithic schema definitions into schema_base.go, schema_agent.go, schema_task.go; adds ExecutePreparedTool entry point supporting MCP executor interface.
Provider Streaming Infrastructure
internal/provider/streamutil/*, internal/provider/alibaba/client.go, internal/provider/anthropic/client.go, internal/provider/google/client.go, internal/provider/moonshot/client.go, internal/provider/openai/client.go
Introduces streamutil.State to centralize chunk emission, usage tracking, and response finalization; refactors all provider clients to delegate streaming state to shared utility instead of inline bookkeeping.
Output & Progress Management
internal/app/output/model.go, internal/app/output/update.go, internal/ui/progress/progress.go
Converts progress singleton to instance-scoped Hub; output model now accepts and manages progress hub; adds lazy-init helpers for backward compatibility.
Model Initialization & Runtime
internal/app/model.go, internal/app/model_init.go, internal/app/runtime_conversation.go
Introduces modelInfra, newBaseModel, and conversationRuntime; centralizes initialization of provider/store/settings/hooks/plugins; delegates command-generation to runtime helpers.
Input & Message Handlers
internal/app/handler_input.go, internal/app/handler_input_submit.go, internal/app/handler_approval.go, internal/app/handler_mode.go, internal/app/handler_compact.go, internal/app/handler_provider.go, internal/app/handler_stream.go, internal/app/handler_tool.go, internal/app/prompt_suggest.go
Extracts submission logic into blockPromptSubmission, recordSubmittedInput, handleCommandSubmit, prepareSubmittedUserMessage, startProviderTurn; delegates tool execution to runtime commands with explicit context/hub; uses DecideCompletion for stream handling; consolidates tool reset to m.tool.Reset().
Permission & Approval System
internal/app/approval/model.go, internal/app/provider/handler.go, internal/config/permission.go, internal/permission/permission.go, internal/permission/permission_test.go
Replaces string literals with tool constants (tool.ToolSkill, tool.ToolAgent); moves tool classification source-of-truth to config package; adds "LSP" to read-only tools.
Plugin Manager UI
internal/app/plugin/load.go, internal/app/plugin/model.go, internal/app/plugin/render.go
Separates plugin selector into load/render/model logic; load.go handles marketplace/install refresh and data loading; render.go handles all UI rendering; model.go retains state/navigation/commands.
Provider Selection UI
internal/app/provider/load.go, internal/app/provider/model.go, internal/app/provider/render.go
Splits provider/model selection into load (connection/caching), render (UI display), and model (state/navigation); introduces ConnectProvider, SetModel, EnterProviderSelect, EnterModelSelect; removes inline render/connection from model.
Message & Result Rendering
internal/app/render/message.go, internal/app/render/message_assistant.go, internal/app/render/message_tool.go, internal/app/render/progress.go
Splits message rendering into assistant/tool/system files; removes large render function set from monolithic file; adds specialized parameter types (AssistantParams, ToolCallsParams, ToolResultData); consolidates tool name references to constants.
Tool Execution Context & State
internal/app/tool/run.go, internal/app/tool/run_test.go, internal/app/tool/state.go
Adds context.Context and CancelFunc to ExecState; updates tool execution entry points to accept explicit context/hub; introduces defaultMCPExecutor adapter; adds context cancellation test.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 With helpers extracted and schemas aligned,
Our streaming now unified, progress refined—
The model initialization's a work of great care,
UI rendering split without a tangle of snare.
Tools flow through their context with cancellation so keen,
A refactored warren—the cleanest you've seen!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch architecture-review

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.

@yanmxa yanmxa merged commit 51dd77c into main Apr 4, 2026
3 of 4 checks passed
@yanmxa yanmxa deleted the architecture-review branch April 4, 2026 03:00
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