[deep-review][duplication] D6: DeepLinkActions and AppCapability are the same delegate-per-verb pattern open-coded twice
Summary
Two places in the codebase implement the same "delegate-per-verb registry" pattern with no shared abstraction:
-
DeepLinkActions— a struct insrc/OpenClaw.Tray.WinUI/Services/DeepLinkHandler.cs:269-301with 28 delegate fields (OpenSettings,OpenChat,RunHealthCheck,CopyDebugBundle, ...). Wired inApp.xaml.cs:4286-4324with a ~200-linenew DeepLinkActions { ... }initializer block. Dispatched via switch inDeepLinkHandler.Handle(DeepLinkHandler.cs:54-266). -
AppCapability— atsrc/OpenClaw.Shared/Capabilities/AppCapability.cs, with 10 public mutableFunc<...>?fields. Wired inApp.xaml.cs:WireAppCapabilityHandlerswith a similar bulk assignment. Dispatched via 13-arm switch insideAppCapability.ExecuteAsync.
Why it matters
Three problems:
- Open-coded ten ten times — adding a new deep-link verb is: add a field to
DeepLinkActions, add a case to the switch inDeepLinkHandler, add a=> ...in the wiring block inApp.xaml.cs. Three sites for one verb. Same forAppCapability. - Public mutable fields —
AppCapability's tenpublic Func<...>?fields can be reassigned anywhere in the AppDomain. Testable but not safe. - No discoverability for callers — the deep-link dispatch table lives in
DeepLinkHandler.Handle, but the contract (what each action does) lives inApp.xaml.cs. Splitting the action from its implementation makes the surface harder to read.
Proposed fix
A small IDispatchRegistry<TVerb, TArgs, TResult> abstraction:
public interface IDispatchRegistry<TArgs, TResult>
{
void Register(string verb, Func<TArgs, TResult> handler);
TResult Dispatch(string verb, TArgs args);
bool IsRegistered(string verb);
}
Migrate DeepLinkActions and AppCapability to use it. Side benefit: the dispatch site becomes table-driven, so adding a verb is one Register call instead of three edits.
For AppCapability: this also addresses the public-mutable-field smell. Handlers are registered through Register, not assigned to fields.
Lower-priority alternative: introduce a [DeepLinkAction("settings")] attribute and source-generate the dispatch table.
Severity
Low — code-shape smell, not a bug. Becomes Medium next time someone adds a deep-link verb.
[!NOTE] The pull request was not created — a fallback review issue was created instead due to protected file changes: #431
🤖 This is an automated response from Repo Assist.
The IDispatchRegistry abstraction is sound, but it's worth flagging one practical concern before committing to it: the two patterns have different type shapes.
DeepLinkActionshas 28 mostly-distinct delegate signatures (some takestring, someCancellationToken, some areFunc<string, Task>, someAction, etc).AppCapabilityhas 10 fields, but they're similarly heterogeneous.
A generic IDispatchRegistry<TArgs, TResult> would only help if you constrain handlers to a single signature (e.g. everything becomes Func<JsonElement, CancellationToken, Task<JsonElement>>). If you try to preserve the distinct signatures, you end up boxing through object delegates and losing type safety.
Two lower-risk alternatives worth considering:
-
Source-generated dispatch — a
[DeepLinkAction("settings")]attribute on a method, with a Roslyn source generator that emits theswitchat compile time. The wiring block inApp.xaml.csbecomes zero LOC. The switch inDeepLinkHandlerbecomes a generated partial method. This keeps distinct signatures, adds discoverability, and removes the three-site requirement. Complexity cost: writing the generator (or usingSystem.CommandLineas a model). -
Staged cleanup — don't unify the two patterns yet. First, replace
AppCapability's public mutable fields with aRegister(string verb, Func<JsonElement, CancellationToken, Task<JsonElement?>> handler)API (internal to the assembly), keeping the existing dispatch switch intact. This fixes the mutable-field smell without requiring a shared abstraction. Then revisit unification after you've seen whether the two registration sites actually share a natural common shape.
The three-edit problem for DeepLinkActions is real, but a [DeepLinkAction] attribute-based approach would solve it more ergonomically than a runtime registry.
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
Closing during the post-refactor deep-review cleanup. Delegate-pattern duplication is consolidated into #372 as architecture debt. This keeps the signal while reducing stale one-off issue noise.