docs(rules): fix contradictions, update technical rules, enforce rule structure
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s

- Resolve contradictions: authorization is never a skipped "boundary check";
  one browser token policy (BFF/HttpOnly cookies first, RFC 10017); one
  sanitizer-bypass rule; Angular responses are unknown until validated.
- Add security rules for AI/LLM integration and Java XXE, concrete crypto
  and password-hashing parameters, and RFC 8725 JWT validation.
- Update version-dependent guidance after checking official sources:
  Angular 22, TypeScript 6/7, Node 24+, .NET 10/C# 14, JDK 21-25, Spring
  Boot 4; add a Spring Boot and Spring Security topic.
- Give every rule a unique level-1 title and scope line, keep language
  security files to language specifics, and fix routing for inbound vs
  outbound HTTP, XML parsing, and WPF/Angular parent rules.
- Validate rule structure and routing in validate-config.py, with tests.
- Fix CI issues found by a local run: shellcheck directive order, pinned
  ruff rule set, Invoke-Python test mock, CRLF-tolerant package checks,
  Windows-only credential test, and refreshed prompt-budget baselines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian LechnerandClaude Opus 5.5 committed 2026-11-05 10:51:08 +01:00
1 parent 79694fbaa2
commit 6159c6373c
62 files changed
+453 -300

No files matched your search

+3 -3
View File
@@ -1,6 +1,6 @@
# WPF Rules
For WPF, XAML, or MVVM work, open only the focused topic rules relevant to the change.
For WPF, XAML, or MVVM work, open only the focused topic rules relevant to the change. WPF code is C#: load the matching C# topic rules (`rules/csharp/index.md` / `rules-csharp`) for language, async, and API guidance, and the shared security rules (`rules/security/index.md` / `rules-security`) for security-relevant changes.
| Topic | Codex rule | Claude skill |
| --- | --- | --- |
@@ -8,5 +8,5 @@ For WPF, XAML, or MVVM work, open only the focused topic rules relevant to the c
| Commands, async, and threading | `references/commands-and-async.md` | `rules-wpf-commands-and-async` |
| Collections and XAML | `references/collections-and-xaml.md` | `rules-wpf-collections-and-xaml` |
| Resources and lifecycle | `references/resources-and-lifecycle.md` | `rules-wpf-resources-and-lifecycle` |
| Security and errors | `references/security-and-errors.md` | `rules-wpf-security-and-errors` |
| Architecture, testing, and performance | `references/architecture-and-quality.md` | `rules-wpf-architecture-and-quality` |
| Security, errors, logging, and validation | `references/security-and-errors.md` | `rules-wpf-security-and-errors` |
| Architecture, dependency injection, testing, and performance | `references/architecture-and-quality.md` | `rules-wpf-architecture-and-quality` |
@@ -1,9 +1,12 @@
# WPF Architecture, Dependency Injection, Testing, and Performance
Apply these rules when structuring a WPF application, wiring dependency injection, testing view models, or optimizing performance. Load the C# rules for language-level guidance.
## Architecture
* Use modern C# and current WPF conventions. Prefer MVVM for non-trivial views and keep code-behind limited to view-specific behavior.
* Use the C# version the project targets (see the C# coding-style rule; .NET Framework 4.x WPF apps default to C# 7.3). Prefer MVVM for non-trivial views and keep code-behind limited to view-specific behavior.
* Keep UI, application, and domain logic separate. Avoid business logic in views and direct service access from controls.
* Keep dependencies explicit and testable; prefer composition over inheritance and avoid unnecessary abstractions or framework wrappers.
* Keep presentation, application, domain and infrastructure concerns separated.
* Avoid direct database access from views or ViewModels.
* Avoid direct HTTP access from controls.
* Keep external integrations behind focused services.
@@ -16,13 +19,11 @@
## Dependency Injection
* Use dependency injection where lifecycle management, substitution or testability benefits from it.
* Avoid service locator patterns.
* Keep constructor dependencies minimal.
* Do not inject dependencies that are not used.
* Choose service lifetimes intentionally.
* Do not make stateful services global without a concrete reason.
* Avoid introducing interfaces solely for dependency injection when no abstraction is needed.
Follow the C# architecture rule for general dependency injection, plus:
* Register views and view models as transient unless they hold intentionally shared state; register shared services as singletons only when they are thread-safe and stateless or own deliberately shared state.
* Do not resolve services from `App.Current` or a static container inside view models; inject them.
* Create EF Core contexts per operation through `IDbContextFactory<T>` (see the C# architecture rule).
## Testing
@@ -37,30 +38,22 @@
## Code Quality
* Use nullable reference types.
* Prefer modern, readable C# syntax.
* Avoid unnecessary interfaces and abstractions.
* Prefer concrete types where no abstraction is required.
* Use descriptive names.
* Remove dead code.
* Add comments only for non-obvious decisions or public contracts.
* Treat compiler, analyzer and binding warnings seriously.
* Do not suppress warnings without a concrete reason.
* Prefer correctness, responsiveness, security and maintainability over cleverness.
Follow the C# coding-style and testing rules, plus:
* Treat binding errors as defects: check the debugger output or XAML binding failures diagnostics for failed bindings after UI changes.
## Performance
* Keep the UI thread responsive.
* Minimize visual tree depth.
* Keep virtualization enabled.
* Keep virtualization enabled (see the virtualization section of the collections rule).
* Avoid unnecessary bindings.
* Avoid unnecessary converters.
* Avoid unnecessary resource lookups.
* Avoid unnecessary property change notifications.
* Avoid frequent full collection refreshes.
* Avoid loading large datasets eagerly.
* Avoid loading large images at full resolution when unnecessary.
* Freeze `Freezable` objects where practical.
* Load images as the images section of the resources rule defines, and freeze `Freezable` objects where practical.
* Reuse immutable resources where appropriate.
* Avoid unnecessary animations.
* Avoid high-frequency timers on the UI thread.
@@ -1,11 +1,15 @@
# WPF Collections, XAML, Layout, and Virtualization
Apply these rules when binding collections, writing XAML, building layouts, or rendering large lists.
## Collections
* Use `ObservableCollection<T>` only when collection change notifications are required.
* Do not use `ObservableCollection<T>` as a general-purpose collection.
* Use `List<T>` or other suitable collections for non-observable internal data.
* Avoid replacing entire observable collections when incremental updates are sufficient.
* Avoid thousands of individual collection notifications when a bulk update is more appropriate.
* Keep collection mutations on the correct thread.
* Use incremental `Add` and `Remove` for small changes. For bulk changes, assign a new collection instance or raise a single `Reset`; never raise multi-item `Add`, `Remove`, or `Replace` notifications to WPF bindings, because `ListCollectionView` throws `NotSupportedException` for range actions.
* Wrap sort and filter changes in `ICollectionView.DeferRefresh()`.
* Mutate bound collections on the UI thread. Use `BindingOperations.EnableCollectionSynchronization` only when off-thread mutation is unavoidable.
* Avoid exposing mutable internal collections unnecessarily.
* Prefer read-only views where consumers should not modify data.
@@ -35,15 +39,10 @@
* Avoid fixed sizes unless the design requires them.
* Prefer responsive sizing with `Auto` and `*`.
* Avoid layout configurations that cause excessive measure/arrange passes.
* Be careful with large visual trees inside scrolling containers.
* Avoid disabling virtualization accidentally.
* Be careful with large visual trees inside scrolling containers; see the virtualization section.
## Virtualization
* Keep UI virtualization enabled for large collections.
* Do not use container layouts that disable virtualization without a reason.
* Avoid wrapping large virtualized item lists in additional scrolling containers.
* Use virtualizing panels where appropriate.
* Verify virtualization when displaying large data sets.
* Avoid rendering thousands of controls simultaneously.
* Prefer paging, incremental loading or virtualization for very large data sets.
* Keep UI virtualization enabled for large collections and use `VirtualizingPanel.VirtualizationMode="Recycling"`.
* These settings silently disable virtualization: `ScrollViewer.CanContentScroll="False"`, grouping without `VirtualizingPanel.IsVirtualizingWhenGrouping="True"`, a non-virtualizing `ItemsPanel` such as `StackPanel` or `WrapPanel`, and placing the list inside a `ScrollViewer` or `StackPanel` that gives it unlimited height.
* Verify virtualization with large data sets, and use paging or incremental loading for very large ones.
@@ -1,3 +1,7 @@
# WPF Commands, Async, and Threading
Apply these rules when implementing commands, async operations, UI-thread work, or event subscriptions in WPF.
## Commands
* Prefer commands over click handlers for ViewModel-driven actions.
@@ -6,8 +10,7 @@
* Keep `CanExecute` logic cheap.
* Refresh command availability only when relevant state changes.
* Avoid command implementations with hidden side effects.
* Handle async commands safely.
* Prevent accidental duplicate execution when an async action must not run concurrently.
* Implement async commands with the project's MVVM library (for example CommunityToolkit.Mvvm `AsyncRelayCommand` or `[RelayCommand]`): disable re-entry unless concurrent runs are intended, expose cancellation for long operations, and surface failures to the user.
* Never use `async void` except for true event handlers.
## Async and Threading
@@ -17,8 +20,7 @@
* Do not block the UI thread.
* Run I/O asynchronously.
* Move expensive CPU work off the UI thread only when necessary.
* Marshal UI updates back to the UI thread when required.
* Keep Dispatcher usage minimal and explicit.
* Let `await` resume on the UI thread in view models instead of calling the Dispatcher. When marshaling is unavoidable, inject a dispatcher abstraction; never use `Application.Current.Dispatcher` in view models, which breaks testing without a UI thread.
* Do not use the Dispatcher to hide incorrect threading design.
* Support `CancellationToken` for cancellable long-running operations.
* Cancel obsolete work when views or selections change.
@@ -27,13 +29,8 @@
## UI Thread
* Treat the UI thread as a scarce resource.
* Keep the interface responsive and do not block the UI thread with I/O or expensive CPU work. Move CPU work off-thread only when needed and marshal UI changes back explicitly.
* Avoid expensive loops, parsing, serialization, database access or network calls on the UI thread.
* Avoid excessive Dispatcher invocations.
* Batch UI updates where practical.
* Do not update UI-bound collections excessively in tight loops.
* Avoid synchronous waits on background work.
* Treat the UI thread as a scarce resource: no I/O, parsing, serialization, database, or network work on it.
* Batch UI updates and avoid updating bound collections in tight loops; see the collections rule for bulk changes.
* Keep rendering-related callbacks lightweight.
## Events
@@ -41,7 +38,7 @@
* Avoid unnecessary event subscriptions.
* Unsubscribe from long-lived publishers when required.
* Prevent memory leaks from event handlers.
* Prefer weak events where publisher lifetime significantly exceeds subscriber lifetime.
* Use `WeakEventManager<TSource, TEventArgs>` where the publisher lives significantly longer than the subscriber.
* Keep event handlers small.
* Do not use events as hidden global communication channels.
* Avoid excessive event chaining.
@@ -1,3 +1,7 @@
# WPF MVVM, Binding, and Properties
Apply these rules when writing view models, data bindings, property notifications, dependency properties, or behaviors.
## MVVM
* Keep ViewModels focused on presentation state and commands.
@@ -38,7 +42,7 @@
* Keep dependent property notifications explicit.
* Avoid hidden notification chains that are difficult to reason about.
* Prefer reusable base implementations only when they reduce duplication without obscuring behavior.
* Do not use reflection-based notification mechanisms unless there is a concrete benefit.
* Use the project's MVVM library for notifications. Without one, prefer CommunityToolkit.Mvvm source generators (`[ObservableProperty]`, `[RelayCommand]`; on partial properties from 8.4.1 with C# 14) or a base class using `[CallerMemberName]`. Avoid reflection- or proxy-based notification frameworks unless the project already uses one.
## Dependency Properties
@@ -1,3 +1,7 @@
# WPF Resources, Windows, and Lifecycle
Apply these rules when managing resources and styles, windows and dialogs, navigation, memory, or images in WPF.
## Resources and Styles
* Use shared resources for repeated styles, brushes, templates and dimensions.
@@ -16,7 +20,7 @@
* Avoid creating duplicate windows unintentionally.
* Do not keep hidden windows alive without a reason.
* Separate dialog logic from business logic.
* Prefer dialog services when ViewModels need to request user interaction.
* Show dialogs through the dialog service described in the MVVM rule.
* Keep ownership relationships explicit.
* Avoid application shutdown behavior that depends on accidental window lifetime.
@@ -40,7 +44,7 @@
* Cached views
* Closures
* Collection views
* Binding-related references
* Binding-related references: binding to a CLR property of a source that does not implement `INotifyPropertyChanged` keeps the source alive; bind only to `INotifyPropertyChanged` or dependency-property sources.
* Dispose resources correctly.
* Stop timers and background work when no longer needed.
* Avoid retaining closed windows or unloaded views.
@@ -49,10 +53,6 @@
## Images and Media
* Load images at an appropriate resolution.
* Avoid decoding images significantly larger than their displayed size.
* Release streams and file handles correctly.
* Avoid locking image files unintentionally.
* Cache images only when there is a clear memory strategy.
* Avoid keeping large bitmaps alive unnecessarily.
* Prefer frozen image resources when they are immutable.
* Decode images at display size with `BitmapImage.DecodePixelWidth` or `DecodePixelHeight`.
* Load file-based images with `BitmapCacheOption.OnLoad` and close the stream, so the file is not locked.
* Call `Freeze()` on immutable bitmaps and brushes, and cache images only with a clear memory limit.
@@ -1,53 +1,37 @@
# WPF Security, Errors, and Validation
Apply these rules when a WPF application handles secrets, files, processes, untrusted data, exceptions, logging, or input validation. Load the C# security rule and the shared security rules as well.
## Security
* Treat all external input as untrusted.
* Never expose secrets, credentials or tokens in UI code.
* Do not store secrets in configuration files committed to source control.
* Avoid leaking sensitive information through logs, dialogs or exception messages.
* Validate file paths and external resources.
* Do not execute external processes or files without explicit validation.
* Avoid insecure deserialization.
* Do not weaken TLS, authentication or certificate validation.
* Prefer secure defaults.
* Never disable security controls for convenience.
* A desktop client cannot keep a secret from its user. Never ship service credentials or API keys in the application; use per-user authentication (for example MSAL with the Windows broker) and server-side authorization.
* Store user tokens and other per-user secrets with DPAPI (`ProtectedData` with `DataProtectionScope.CurrentUser`) or Windows Credential Manager, never in plain settings, `app.config`, or files.
* Follow the C# deserialization rule. Never pass untrusted XAML to `XamlReader.Load` or `XamlReader.Parse`, which can instantiate arbitrary types, and treat clipboard and drag-and-drop payloads from other processes as untrusted input.
* Run with standard user rights; request elevation only for the specific operation that needs it, never for the whole application.
## File and Process Access
* Validate file paths before use.
* Avoid assuming files or directories exist.
* Handle permissions and locked files gracefully.
* Avoid arbitrary shell execution.
* Quote and validate process arguments safely.
* Do not concatenate untrusted input into shell commands.
* Avoid elevated privileges unless explicitly required.
* Clean up temporary files when appropriate.
* Resolve and validate file paths as the C# security rule defines before use.
* Do not assume files or directories exist; handle missing files, permissions, and locked files with clear user feedback.
* Start processes as the C# security rule defines: `UseShellExecute = false` set explicitly (it defaults to `true` on .NET Framework), an absolute executable path, `ArgumentList` on .NET Core 2.1+, and no untrusted arguments to `.bat` or `.cmd` targets.
* Create temporary files with `Path.GetTempFileName` or a private directory and delete them when done.
## Error Handling
* Handle expected errors explicitly.
* Do not swallow exceptions.
* Preserve useful exception context.
* Avoid showing raw technical exceptions directly to end users.
* Log enough information for diagnosis without exposing sensitive data.
* Keep user-facing error messages clear and actionable.
* Avoid using exceptions for normal control flow.
* Ensure background exceptions are observed.
Follow the C# safety and error-handling rule, plus:
* Show users clear, actionable messages instead of raw exception text.
* Wire `Application.DispatcherUnhandledException`, `TaskScheduler.UnobservedTaskException`, and `AppDomain.CurrentDomain.UnhandledException` once at startup to log the failure and decide whether the app can continue.
* Wrap the body of every `async void` event handler in `try`/`catch`, and do not start fire-and-forget tasks whose exceptions nobody observes.
## Logging
* Use structured logging.
* Avoid excessive logging on the UI thread.
* Do not log every property change or binding update.
* Never log secrets, tokens, credentials or sensitive user data.
* Include relevant context for operational failures.
* Avoid logging the same exception repeatedly at multiple layers.
Follow the C# logging rule (message templates, no secrets), plus:
* Do not log every property change or binding update, and keep logging off the UI thread's hot paths.
## Validation
* Validate user input at the appropriate boundary.
* Keep validation logic out of XAML when it becomes complex.
* Prefer reusable validation rules or ViewModel validation for non-trivial cases.
* Display validation errors consistently.
* Do not rely on UI validation as a security boundary.
* Validate again at backend or domain boundaries when required.
* Preserve user input on recoverable errors.
* Implement input validation in view models with `INotifyDataErrorInfo` (or the project's MVVM library, such as CommunityToolkit.Mvvm `ObservableValidator`); keep complex validation out of XAML `ValidationRule`s.
* Display validation errors consistently and preserve user input on recoverable errors.
* UI validation is not a security boundary; validate again in the domain or backend.