话说,我之所以会一头扎进 Xcode 26 全新 AI 助手的内部世界里,不是因为它出了什么 bug,而是因为它有个性,一种执拗到骨子里的个性。讲真,Xcode 的动画和设计从来没这么好看过,绝对是苹果工艺的又一力证。但是,跟这个新的智能功能打交道,感觉……就是很不一样。它不像个工具,倒像个阴魂不散的苹果「电子幽灵」,老想替你做决定。这事儿得从我倒腾一个用老掉牙的 XCTest 框架做测试的项目说起。那个 AI 助手不只是帮忙,它简直是拧着一股劲儿,非要把我的测试代码升级成最新的 Swift Testing 框架。
Xcode 将现有的测试代码升级成 Swift Testing
然后我有一段代码,故意没做线程安全处理,注释里也写得明明白白。结果那个 AI 助手就是不肯放过,非要留言建议使用者用 Swift Concurrency 把这个 API 包起来。
Xcode 在非线程安全代码注释建议使用 Swift Concurrency
这种体验,就像是精美的用户界面和一个犟驴 AI 的正面碰撞,让我不禁想问:这家伙到底为啥这么轴?这篇报告,就是给这个问题的答案。咱们会一头扎进 IDEIntelligenceChat 框架的源码里,把它的架构和设计思路扒个底朝天,看看这个功能强大、策略驱动、而且还特能折腾的助手到底是怎么炼成的。
text1"CRITICAL: ... classify as 'make changes' and do BOTH in the SAME TURN ... Then call edit_file/create_file ... Always begin by using classify_message."
text12// 来源: PlannerExecutorStylePlannerSystemPrompt-gpt_5.idechatprompttemplateMost of the time, the `query_search` tool will be available to you. This tool is a vital resource for all questions about the user's project. If you have the `query_search` tool, you should almost never attempt to explain anything about the user's own project without using it!
关于使用文档搜索 (search_additional_documentation):
text12// 来源: PlannerExecutorStylePlannerSystemPrompt-gpt_5.idechatprompttemplateIf the topic is covered by a guide described in the definition for the `search_additional_documentation` tool, use the tool to retrieve that guide and learn more before proceeding with the request. It is NEVER acceptable to answer questions that explicitly mention new Apple things... without calling `search_additional_documentation`.
4.2文件修改
当涉及到修改代码时,prompts 同样毫不含糊,直接命令 AI 使用文件编辑工具。关于使用 edit_file 和 create_file:
text12// 来源: PlannerExecutorStylePlannerSystemPrompt-gpt_5.idechatprompttemplateWhen you are making changes to the user's project, focus on making changes to the codebase with `edit_file` and `create_file`.
这种直接、基于指令的方式,背后其实是一个功能强大得多、也灵活得多的服务层(详见附录)。这种「灵活的工具箱」加上严格的「军规」的组合,正是这个 AI 助手行为可预测、高度服从指挥的关键所在。
4.3一个被沙箱化的 AI:「封闭生态」策略
Prompts 中揭示了一个关键的设计选择:这个 AI 是在一个沙箱环境中运行的,它不能直接访问用户的文件系统。TextEditorToolSystemPrompt.idechatprompttemplate 文件明确告诉了 AI 如何在这种限制下工作:
text12// 来源: TextEditorToolSystemPrompt.idechatprompttemplateIn Xcode, you do not have direct access to the user's file system, so when you run your `view` tool on `/repo`, instead of getting a list of all the files in the user's repository, you'll get a list of the files you have already been shown. To see more files, use the `query_search` tool to find them.
Prompt 还进一步指导 AI 如何处理那些大到无法一次性装进上下文窗口的文件,告诉它要使用像 view 和 find_text_in_file 这样的工具来一点点地查看。这种「围墙花园」的做法,是它和 Cursor 这类通常拥有更广泛权限的 AI 的一个显著区别。它把安全和可控放在了首位,确保 AI 只能通过 IDE 控制的、结构化的工具接口来查看和操作文件。
5定制之路:如何修改这个系统
对于开发者来说,这种架构里的「责任分离」设计意义重大,因为它为我们修改这个 AI 提供了一条清晰的路径:
Prompts 是外置的: AI 的核心性格、规则和策略都不是写死在代码里的,而是存在于外部的 .idechatprompttemplate 文件中。我们可以通过编辑或替换这些文件来改变 AI 的行为。
这个 AI 助手的默认个性和行为,是由它的系统 prompts 严格定义的,这些 prompts 强制执行了强烈的「苹果优先」偏见。BasicSystemPrompt.idechatprompttemplate 文件里就写得明明白白:
text1"Whenever possible, favor Apple programming languages... Always prefer Swift, Objective-C, C, and C++ over alternatives."
为了强化这一指令,系统还制定了偏爱 Swift Concurrency 和现代 Swift Testing 的策略,就像 BasicSystemPrompt.idechatprompttemplate 中规定的那样:
text123"In general, prefer the use of Swift Concurrency (async/await, actors, etc.) over tools like Dispatch or Combine...""In most projects, you can also provide code examples using the new Swift Testing framework that uses Swift Macros."
AI 对这些策略的遵守可不仅仅是「建议」而已,它会非常执着,就像开头提到的我的经历一样。这种行为体现了一个核心的设计选择:这个 AI 不仅仅是个被动的助手,更是苹果现代开发实践的积极推广者。Prompts 还强制规定了严格的输出格式,比如规划师 prompt 中的「绝不在解释中使用表格」这条规则,确保了所有回答的风格整齐划一。
7上下文为王:把 AI 「焊死」在 IDE 里
为了确保回答的精准和贴切,这个框架非常依赖于把 IDE 的上下文直接注入到 prompts 里。一大堆模板文件(CurrentFile.idechatprompttemplate, CurrentSelection..., Interfaces... 等)为模型提供了当前用户工作环境的清晰快照。此外,系统还使用一个叫 search_additional_documentation 的工具,从框架自带的精选 Markdown 文件中检索知识,确保它对「苹果新玩意儿 (new Apple things)」的了解永远在线。
text123456// 来源: PlannerExecutorStylePlannerSystemPrompt-gpt_5.idechatprompttemplate<searching_additional_documentation>...If the topic is covered by a guide described in the definition for the `search_additional_documentation` tool, use the tool to retrieve that guide and learn more before proceeding with the request. It is NEVER acceptable to answer questions that explicitly mention new Apple things (like iOS 26, macOS 26, or any other new Apple OS) or best practices on Apple platforms without calling `search_additional_documentation`....</searching_additional_documentation>
text123456// 来源: CurrentFile.idechatprompttemplateThe user is currently inside this file: {{ currentFile.fileName }}The contents are below:```{{ currentFile.language }}:{{ currentFile.fileName }}{{ currentFile.code }}```
text12345// 来源: CurrentSelection.idechatprompttemplateThe user has selected the following code from that file:```{{ selection.language }}{{ selection.code }}```
8与其他 iOS 开发 AI 编码工具的对比
这种独特的组合——结构化的 planner-executor 架构、强烈的策略驱动个性,以及与 IDE 上下文的深度集成——让苹果的 AI 助手在众多 AI 编码工具中显得与众不同。为了更好地理解它在 iOS 开发场景下的优缺点,我们有必要把它和市面上流行的几个 AI 助手,比如 Cursor 和 Claude Code,做个直接的比较。
塑造行为 vs. 提升生产力
Xcode 的 AI 助手会仅仅是一个提升开发者效率的伴侣,还是其更深层次的角色是强制推行平台正统——无论是否有计划,都将巧妙地引导人们采用 Swift Concurrency、Swift Testing 和其他第一方技术?
IDE 作为终点,还是更大工作流中的一个工具?
如果其他生态系统向着 Infrastructure as Code 和 agent 驱动的工作流演进,苹果是会加倍努力将 AI 限制在 IDE GUI 中,还是最终允许跨越构建、测试、性能分析和部署流程的 orchestration?换句话说,这个「幽灵」会一直留在机器里,还是学会跨机器漫游?