Skip to content

[deep-review][duplication] D5: Models.cs (1972 lines) contains ~700 lines of non-DTO helper classes #368

Closed

Description

@codemonkeychris

Summary

src/OpenClaw.Shared/Models.cs is 1,972 lines. It's named Models.cs and most of its content is DTOs — but ~700 lines belong to four static helper classes that aren't models at all and have no business sharing this file.

Where

In Models.cs:

  • CommandCenterDiagnostics (static helper)
  • CommandCenterCommandGroups (static taxonomy: safe-companion command list, privacy-sensitive command list — referenced from App.xaml.cs:1141-1146)
  • GatewayTopologyClassifier (logic for classifying gateway topology from a GatewaySelfInfo)
  • ModelFormatting (display-name and tooltip formatters)

Total: ~700 lines.

Plus the file mixes three coexisting parser conventions:

  • static class ChannelHealthParser with Parse(JsonElement) returning a typed ChannelHealth
  • Inline TryParse... static methods on record types
  • Inline From... factory methods on record types (e.g., GatewaySelfInfo.FromHealthPayload)

Why it matters

  1. Models.cs is the file new contributors search when looking for a model. They find static helpers instead. Cognitive overhead.
  2. Code-quality review found this file has grown alongside App.xaml.cs — uncapped growth signal.
  3. The four helper classes have different lifecycles than the DTOs. They're called from UI code (App.xaml.cs:1141); the DTOs are owned by the protocol layer. Coupling.

Proposed fix

Split into:

  • src/OpenClaw.Shared/Models.cs — keep only the DTO record types. Should drop to ~1,200 lines.
  • src/OpenClaw.Shared/Diagnostics/CommandCenterDiagnostics.cs
  • src/OpenClaw.Shared/Diagnostics/CommandCenterCommandGroups.cs
  • src/OpenClaw.Shared/Diagnostics/GatewayTopologyClassifier.cs
  • src/OpenClaw.Shared/Diagnostics/ModelFormatting.cs
  • src/OpenClaw.Shared/Parsing/ChannelHealthParser.cs (or fold into Models.cs as nested static)

Followup: pick one parser convention (suggest: static TryParse on each record) and migrate the others.

Severity

Low (cosmetic) but high-payoff for new-contributor onboarding.

Activity

  1. github-actions commented on May 17, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Looked at Models.cs — the 1,972-line count is accurate and the proposed split makes sense. A couple of observations from reading the file:

    What's safe to move immediately:

    • ModelFormatting and GatewayTopologyClassifier are pure static helpers with no circular references; they can move to separate files with a simple cut-paste.
    • CommandCenterDiagnostics / CommandCenterCommandGroups are called from App.xaml.cs — moving them doesn't change the using directives already present, so it's mechanically safe.

    What needs care:

    • ChannelHealthParser.Parse(JsonElement) returns a ChannelHealth record that lives in Models.cs. Moving the parser to a sibling file (Parsing/ChannelHealthParser.cs) requires ChannelHealth to remain in Models.cs or be moved first — otherwise there's a cyclic dependency between the two new files.

    Suggested ordering:

    1. Move the four static helpers first (no DTO dependencies).
    2. Standardise on one parse convention (static TryParse on each record) as a follow-up — this is the larger change and benefits from being separate.

    The Models.cs reduction from ~1,970 to ~1,270 lines is the real payoff: it makes the file scannable in a way it currently isn't. New contributors looking for a DTO today have to scroll past hundreds of lines of helper logic.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a
    
  2. shanselman commented on May 18, 2026

    @shanselman
    Collaborator

    Closing during the post-refactor deep-review cleanup. Models.cs bloat is reduced/changed after refactors and is consolidated into #372 as architecture debt. This keeps the signal while reducing stale one-off issue noise.

  3. locked as resolved and limited conversation to collaborators on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions