Normalize token/item limit naming — eliminate `tokenBudget` and align on `maxTokens`/`maxItems`
Follow-up to: #3584838 Went back and forth with opus 4.6 on this: --- **Title:** Normalize token/item limit naming — eliminate `tokenBudget` and align on `maxTokens`/`maxItems` **Problem:** The concept "maximum tokens for rendered context" uses three different names as it flows through the codebase: - Public API: `tokenLimit` (`retrieve(tokenLimit: 2000)`) - Request DTO: `maxTokens` (`$request->getMaxTokens()`) - Result VO: `tokenBudget` (`$result->getTokenBudget()`) Similarly for items: - Public API: no public param yet - Request DTO: `maxItems` (`$request->getMaxItems()`) - Config: `max_items` The `tokenBudget` naming is the main inconsistency — it implies allocation planning rather than a simple cap, and doesn't match the config key (`max_tokens`) or the request DTO (`getMaxTokens()`). **Approach: Standardize on `maxTokens` / `maxItems`** This aligns with AI industry API convention (`max_tokens`), matches the existing config keys and request DTO naming, and has the smallest blast radius. **PHP renames — tokens:** - `AiContextResult::getTokenBudget()` / `$tokenBudget` -> `getMaxTokens()` / `$maxTokens` - `AiContextRequestFactory::retrieve()` / `getRenderedContext()` param `$tokenLimit` -> `$maxTokens` - Internal local variables in `AiContextSelector` and `AiContextRenderer` that use `$tokenLimit` -> `$maxTokens` (for consistency with the named arg and config key) **PHP renames — items:** - No changes needed; `maxItems` / `max_items` is already consistent throughout **No config changes, no update hook, no schema changes.** The config keys `max_tokens` and `max_items` already use the target convention. `DEFAULT_MAX_TOKENS` and `DEFAULT_MAX_ITEMS` constants already match. The request DTO `getMaxTokens()` / `getMaxItems()` already match. **Tests:** - Update `getTokenBudget()` calls to `getMaxTokens()` in test assertions - Update any `tokenLimit:` named args in test calls to `maxTokens:` **Docs:** - Update `docs/developers/services.md` parameter name from `tokenLimit` to `maxTokens` **Scope:** Rename result getter + public API param + local variables. No config migration. No update hook. ---
issue