openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

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

Open codemonkeychris opened this issue 6 months ago • 2 comments

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.

codemonkeychris avatar May 14 '26 00:05 codemonkeychris

🤖 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

github-actions[bot] avatar May 17 '26 01:05 github-actions[bot]

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.

shanselman avatar May 18 '26 00:05 shanselman