Add context settings validation: max_global_items must not exceed max_items
Follow-up to: #3580910 **Description:** ## Problem General settings (`ai_context.settings`) and per-agent overrides (`ai_context.agents`) expose two related limits: - **Max global context items** (`max_global_items`, range 0–10) - **Max context items to inject** (`max_items`, range 1–20) Each field is validated independently (`Range` in schema; `#min`/`#max` on the general settings form). Nothing enforces that `max_global_items <= max_items`. The general settings form already tells admins that global items count toward the total cap, but invalid combinations can still be saved—for example `max_global_items = 10` and `max_items = 5`. ## Current behavior Runtime selection copes: `AiContextSelector` caps globals during candidate loading, then `mergeByPriority()` slices the merged list to `max_items`. So a high global cap with a lower total cap does not break injection, but globals (and other lower-priority groups) may be dropped silently at merge time. That makes the configured global limit misleading and hard for site builders to reason about. ## Proposed solution Add cross-field validation so `max_global_items` cannot exceed `max_items` when both values are set. **General settings (`ai_context.settings`):** - Schema constraint on the config object (preferred for CMI import parity), e.g. custom constraint or `Callback` validating `max_global_items <= max_items`. - Form-level validation on `AiContextSettingsForm` as a backstop for the admin UI. **Agent overrides (`ai_context.agents`):** - Apply the same rule when an agent sets both `max_global_items` and `max_items`. - Consider validation in `AiContextAgentForm` and schema constraints on the agent mapping if feasible. ## Acceptance criteria - [ ] Saving general settings with `max_global_items > max_items` is rejected with a clear validation message. - [ ] Importing config with the same invalid combination fails schema validation (or equivalent config validation). - [ ] Per-agent overrides with both limits set reject `max_global_items > max_items`. - [ ] Valid combinations (including `max_global_items = 0`) still save successfully. - [ ] Kernel tests cover valid/invalid cases for general settings; agent form tests if agent overrides are included. ## Notes - Pre-existing gap; intentionally deferred from the settings validation / `#config_target` MR. - Runtime behavior in `AiContextSelector::mergeByPriority()` can remain as-is; this ticket is about admin UX and config integrity, not changing selection semantics. - Constants live in `AiContextRequest` (`MIN/MAX_MAX_GLOBAL_ITEMS`, `MIN/MAX_MAX_ITEMS`). ## AI usage - [x] AI assisted issue - [ ] AI assisted code
issue