Skip to content

refactor: tighten domain boundaries, drop dead code and Manager/Impl names - #1283

Merged
edenreich merged 4 commits into
mainfrom
refactor/domain-boundaries
Sep 23, 2026
Merged

edenreich merged 4 commits into
mainfrom
refactor/domain-boundaries

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

A DDD / Clean Architecture / over-engineering audit of the domains, followed by fixes. Four commits, one per phase; each passes task precommit:run on its own. Net −4,183 lines.

1. Dead code and duplicates (050c101f)

  • Removes 17 event types that nothing has emitted since feat(agent): interactive subagent management and unified background-work tracking #684 unified background tracking, plus every receiver: the a2acoord package, the conversation-view background-task bar, and the chat-handler/tool-coordinator handlers. The /tasks view already covers A2A tasks, shells and subagents.
  • Removes interface methods only tests called (ImageService, FileService, GitHubSetupService, A2ATaskTracker, ToolService), and the unused workflow templates behind them.
  • Collapses duplicates:
    • plugins now reuses skills' GitHub FetchTree/DownloadFile instead of carrying its own copy.
    • One CommandRunner, one ModelSelectedEvent, one AgentNameFromURL.
    • One SubagentResultFile writer and reader. The headless copy wrote 0o644 and ignored marshal errors; the shared one uses 0o600 and checks errors.
  • The judge verdict/input/approver types move out of agent/domain into the agent package, their only user.

2. Misplaced code moved to its owning context (627b7475)

  • A2A tracking belongs to the scheduler: the port moves to scheduler/domain, and the trackers move from platform/utils to scheduler/infrastructure.
  • Subprocess runner: agentrunner moves to platform/agentrunner, together with FormatAgentMessage, which parses its output.
  • Headless: presentation/headless no longer imports internal/container. cmd/headless passes a Services port instead, and the container owns StartScreenshotServer for both chat and headless.
  • UI types: TUI-only state (sessions, the approval/plan/question prompts, their enums), TUI-only events and ToolFormatter move from agent/domain to presentation/tui. The agent keeps a single-method RetryStatusSink.
  • Conversation ports: conversation/domain gains PersistentConversationRepository and SessionRollover, plus the pure BuildAgentMessagesFromEntries/EnsureToolCallsClosed. The TUI no longer casts to concrete conversation types.
  • Injection: the container now provides the agent's tokenizer, rollover, hooks and plugin instructions instead of the agent building them.
  • Small edges:
    • download takes an explicit progress callback.
    • The container runtime takes a plain session id.
    • CapInstructions moves to platform/formatting.
    • ParseCron moves to scheduler/domain and uses one shared parser.
  • ScheduledJob gets NewScheduledJob and Apply(JobPatch), so schedule validation and timestamps live on the entity.

3. Domain names instead of Manager / Impl (f83be330)

  • Lifecycle owners of external processes become Supervisors (AgentSupervisor, gateway.Supervisor, mcp.Supervisor).
  • Download helpers become Stores (audio BinaryStore/ModelStore/TTSModelStore, history.Store).
  • The rest get role names: keybinding.Dispatcher, web.Sessions, conversation.SessionRollover, scheduler.TitleBackfill, statemanager.Store, tui.ViewNavigator.
  • 15 *Impl types drop the suffix. Container getters and file names follow.
  • Done with gopls rename, so every reference is updated.

4. Enforcement (9cebcd3f)

  • New depguard rule domain-is-pure: a domain/ package may import only stdlib, external types and agent/domain, which is now documented as the shared kernel.
  • New depguard rule container-is-the-root: nothing under internal/ (tests excepted) may import internal/container.
  • Both rules were checked by planting a violation. AGENTS.md is updated.

Not done (deliberately)

  • Tool interface split: every tool already renders its own UI in FormatResult, so splitting the interface would touch ~60 tools without removing any UI code from them.
  • Audio synthesizer injection: the TTS tool also calls audio.WAVDurationSeconds, so injecting the synthesizer alone would not remove the dependency.
  • Deferred:
    • storage ports living in platform
    • where platform/render sits
    • the mutable globals in platform/models
    • SDK types in the domain
    • splitting the fat ImageService/MCPSupervisor interfaces
    • local variable and field names that still say "Manager"

Test plan

  • task precommit:run (mod tidy, mocks, fmt, lint, markdownlint) on every commit
  • go test ./..., task test:race, task test:e2e
  • INFER_GATEWAY_MOCK=true infer headless --model mock/openai/gpt-4o "hi", including --result-file (written 0o600) and the early --format error
  • Chat TUI in tmux against the mock gateway: chat, /tasks, /model switch, !echo

- Delete 17 event types nothing emits since #684 unified background
  tracking (A2ATask*, A2AToolCallExecuted, ToolCall{Update,Ready},
  Subagent*, Shell{Completed,Failed,Cancelled}) with every receiver:
  the a2acoord package, the conversation-view background-task bar and
  the chat-handler/tool-coordinator handlers.
- Drop test-only interface methods (ImageService, FileService,
  GitHubSetupService, A2ATaskTracker, ToolService) and the dead
  workflow templates behind them.
- Drop agentdomain.MCPServerEntry (duplicate of config), unused Has*
  context helpers; unexport the context keys.
- plugins.Installer reuses skills' FetchTree/DownloadFile instead of a
  copy; githubscheduler uses githubsetup.CommandRunner.
- One SubagentResultFile writer/reader (0o600, marshal errors checked)
  and convdomain.LastAssistantText replace the diverged copies.
- One ModelSelectedEvent, one AgentNameFromURL.
- Judge verdict/input/approver move from agent/domain into the agent
  package, their only user.
- Remove the depguard rule already covered by presentation-is-a-leaf.
…them

- A2A task tracking lives in the scheduler context: the A2ATaskTracker
  port and TaskPollingState move to scheduler/domain, and the A2A, shell
  and subagent trackers move from platform/utils to
  scheduler/infrastructure.
- agentrunner (a generic `infer headless` subprocess runner) moves to
  platform/agentrunner together with FormatAgentMessage, its stdout
  parser.
- presentation/headless no longer imports the composition root:
  cmd/headless passes a constructor for a headless.Services port, and
  the container owns StartScreenshotServer for chat and headless.
- TUI-only state (chat/tool-execution sessions, approval, plan-approval
  and question prompts, their enums), TUI-only events and ToolFormatter
  move from agent/domain to presentation/tui; the agent keeps a
  one-method RetryStatusSink.
- conversation/domain gains the PersistentConversationRepository and
  SessionRollover ports plus the pure BuildAgentMessagesFromEntries and
  EnsureToolCallsClosed; presentation stops casting to concrete
  conversation types.
- The container injects the tokenizer, rollover, hook provider and
  plugin instructions into the agent instead of the agent building them.
- download takes an explicit progress callback, the container runtime
  takes a plain session id, the conversation line formatter moves into
  tui/components, CapInstructions into platform/formatting, ParseCron
  (one shared parser) into scheduler/domain.
- ScheduledJob gets NewScheduledJob and Apply(JobPatch) so schedule
  validation and timestamps live on the entity.
- Lifecycle owners of external processes become Supervisors:
  AgentSupervisor, gateway.Supervisor, mcp.Supervisor / MCPSupervisor.
- Download/resolve helpers become stores (audio BinaryStore, ModelStore,
  TTSModelStore; history.Store), the rest are named for what they do:
  keybinding.Dispatcher, web.Sessions, conversation.SessionRollover,
  scheduler.TitleBackfill, filewriter ChunkBuffer / Backup,
  statemanager.Store with StateStore / stateStore consumer interfaces,
  tui.ViewNavigator, AgentReadiness.
- Agent-side state ports: AgentModeState, TodoList, ComputerUsePause.
- Drop the Impl suffix from 15 concrete types (agent.Agent,
  agent.StateMachine, agentapp.A2AClient, FileService, PricingService,
  the TUI views and selectors; TaskManagerImpl becomes TaskView).
- Container getters follow: GetAgentSupervisor, GetMCPSupervisor,
  GetGatewaySupervisor, GetSessionRollover, GetStateStore,
  GetTitleBackfill. Files are renamed to match.
- domain-is-pure: a domain/ package may import only stdlib, external
  types and agent/domain, now documented as the shared kernel.
- container-is-the-root: nothing under internal/ (tests aside) imports
  internal/container; cmd/ builds it and passes ports in.
- AGENTS.md describes the shared kernel, <context>/infrastructure and the
  schedinfra alias.
@edenreich
edenreich requested a review from a team as a code owner September 23, 2026 21:08
@edenreich
edenreich merged commit b9abcae into main Sep 23, 2026
1 check passed
@edenreich
edenreich deleted the refactor/domain-boundaries branch September 23, 2026 21:53
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.207.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant