Skip to content

refactor: AI features cleanup wave 2 (chat tools, providers, HIG)#1113

Merged
datlechin merged 5 commits intomainfrom
refactor/ai-chat-tools-and-hig
May 8, 2026
Merged

refactor: AI features cleanup wave 2 (chat tools, providers, HIG)#1113
datlechin merged 5 commits intomainfrom
refactor/ai-chat-tools-and-hig

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Wave 2 of the AI features audit (follow-up to #1111). 5 commits, all scoped, all conventional. Production builds clean, AI tests pass.

What changed

  • Chat tool schemas (refactor(ai-chat): extract ChatToolSchemaBuilder...): introduced ChatToolSchemaBuilder with composable builders (object, string, enumString, boolean, integer) and named constants (connectionId, databaseName, schemaName, tableName). All 9 tools now express their inputSchema in 1-2 lines instead of 10-15. Lifted resolveConnectionId from a free function in GetConnectionStatusChatTool to ChatToolContext+Helpers.swift so every tool calls context.resolveConnectionId(input). Net -98 LOC across the tool files.

  • Mention detection Unicode safety (fix(ai-chat): handle non-BMP characters...): MentionDetector walked NSString UTF-16 units, so an @ placed right after an emoji or other non-BMP scalar saw a low surrogate first and produced a malformed query. Rewritten to walk String.UnicodeScalarView backward via String.Index, replaced the magic 0x40 with Unicode.Scalar(\"@\"). Added regression tests for emoji-before-trigger, emoji-inside-query, and non-BMP-after-caret cases.

  • Tool mode declaration (refactor(ai-chat): declare per-tool mode...): added ChatToolMode { readOnly, write, agentOnly } to the ChatTool protocol. Each tool declares its own mode. The registry no longer carries hardcoded readOnlyToolNames/editModeToolNames sets, so adding a tool to ChatToolBootstrap is now sufficient for it to participate in Ask/Edit/Agent modes correctly.

  • Provider polish (refactor(ai-providers): refresh known models...): Anthropic testConnection() uses the configured model with knownModels.first fallback (no more pinned claude-haiku-4-5-20251001). Refreshed knownModels to include claude-opus-4-7-20260101 and claude-sonnet-4-6-20251101. AIProvider.collectErrorBody() logs an OSLog warning when it truncates at 2000 bytes (previously silent). Ollama detector now logs the URLError code or generic error type instead of swallowing every failure as 'not running'.

  • HIG alignment (refactor(hig): align AI chat views...):

    • Replaced custom rounded-rect pill backgrounds with .background(.quaternary, in: RoundedRectangle(cornerRadius: 6)) on tool-use and tool-result block headers.
    • Context chip moved to .tint.opacity(0.08) fill and 0.5pt stroke (macOS divider weight).
    • Mention list selected text is .alternateSelectedControlTextColor (canonical AppKit foreground for selectedContentBackgroundColor), no more Color.white that fails contrast in dark mode.
    • Markdown theme uses .em(...) relative sizing (1.0 body, 1.15/1.3/1.5 for h3/h2/h1) so Dynamic Type works.
    • 8-pt grid for spacing across MessageView, ContextChipView, MentionSuggestionListView.
    • Pulled the user-bubble accent opacity into a named constant.
    • Pulled the warning-row yellow opacity into a named constant (kept Color(nsColor: .systemYellow) because .yellow.tertiary is macOS 15+ and the deployment target is 14.0).
    • Added .accessibilityLabel to icon-only buttons: scroll-to-latest, edit pencil, send, stop, mention @ menu, slash-command menu.

Files

  • 30+ files changed across all 5 commits (run git diff main...HEAD --stat for the breakdown)

Critical: not touched

  • IntelligenceFocusBorder and IntelligenceShimmer in ChatComposerView.swift are intentional. They mimic Apple Intelligence's animated gradient stroke around AI input fields (Writing Tools, Image Playground, Siri border), which is the post-Sequoia native HIG pattern for AI surfaces. Wave 1 reverted an over-eager removal of these in commit 0d78c126.

Test plan

  • xcodebuild build green for the production target across all 5 commits
  • swiftlint lint --strict clean on every touched file
  • AI test classes pass: MentionDetectorTests, ChatToolRegistryTests, ChatToolRegistryModeTests, ChatToolArgumentDecoderTests, ChatToolSpecCopilotTests, ExecuteToolUsesTests, AnthropicProviderEncodingTests, AnthropicProviderParserTests, AIProviderErrorTests, AIProviderFactoryResolveTests
  • Manual smoke: open AI chat, exercise mention popover with emoji-prefixed text, verify Ask/Edit/Agent mode tool visibility, confirm chat bubble visuals in light + dark mode
  • VoiceOver pass over the chat panel to verify icon-only buttons announce their labels

Out of scope (Wave 3)

The audit roadmap is now mostly closed. Remaining items if desired later:

  • Pre-existing OpenTableTabTests assertion at MainContentCoordinator+FilterState.swift:311 (test fixture issue, not AI code)
  • fixError* MongoDB/Redis test failures (plugin loading in test target)

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin merged commit a1bd6b3 into main May 8, 2026
2 checks passed
@datlechin datlechin deleted the refactor/ai-chat-tools-and-hig branch May 8, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant