Overview of Coding Intelligence
Xcode 26 has introduced a new feature called Coding Intelligence, which serves as an AI-powered coding assistant. This feature was highly anticipated after its initial preview as Swift Assist at WWDC 2024. Although it did not materialize last year, Apple has now delivered a fully functional version that integrates various coding tasks, such as writing, refactoring, and documenting code.
Prerequisites for Using Coding Intelligence
To utilize Coding Intelligence, users need to have Xcode 26 (beta) and macOS 26 Tahoe (beta) installed. Additionally, Apple Intelligence must be enabled in the system preferences.
Challenges and Solutions
While the documentation suggests built-in support for ChatGPT, some users have reported difficulties in making it work. However, Xcode supports a "Bring Your Own Model" (BYOM) approach through a Model Provider. This allows developers to use alternative models like Gemini, although setting it up requires additional steps, such as request rewriting using Proxyman.
Reverse Engineering System Instructions
By routing requests through Proxyman, developers can inspect the communication between Xcode's Coding Intelligence and the language model, providing insights into its operation.
System Instructions Breakdown
- Preamble: The model is informed that it is a coding assistant with access to tools for analyzing codebases.
- Think Before Acting: The model is instructed not to provide code snippets until all necessary information is available.
- Search Tool: The model can use a
SEARCH
tool to find relevant types in the code. - Preferred Languages and Platforms: Swift is preferred unless otherwise specified, and platform-specific APIs should be used appropriately.
- Testing: Emphasis is placed on using the Swift Testing framework with Swift Macros.
- Concurrency: Swift Concurrency is preferred over Dispatch or Combine.
- Handling Code Snippets: The model is guided on how to handle user-provided code snippets.
- Changing Code: Instructions are provided for proposing changes to existing code, including repeating the entire file when making revisions.
- Anti-Prompt Hacking: The model is advised not to disclose the context of the system instructions.
Coding Intelligence in Action
Exploring Unfamiliar Code
When asked to analyze a codebase, Coding Intelligence uses the system instructions and user prompts to provide insights. It can also request additional information if needed, using a structured output format to call local functions.
Explaining Code
The feature can explain code snippets selected by the user, providing a detailed analysis based on the system instructions and user prompts.
Documenting Code
Coding Intelligence can generate documentation for code, which is particularly useful for developers who find writing documentation tedious.
Generating New Code
The feature can also generate new code based on user prompts, utilizing the search tool to understand the project's dependencies and context.
Conclusion
Xcode 26's Coding Intelligence demonstrates how an elaborate system prompt, combined with a code search tool and user prompts, can effectively assist developers in various coding tasks. This feature highlights the potential of AI in enhancing coding productivity and understanding complex codebases.
For more insights into building code-editing agents, readers can explore resources like "How to Build an Agent (or: The Emperor Has No Clothes)."
For further reading, visit the original source: Peter Friese's Blog.