Show HN: AgentSwift – 开源 iOS 构建代理
发布: (2026年4月28日 GMT+8 09:14)
3 分钟阅读
原文: Hacker News
Source: Hacker News
Dependencies
- Xcode
- Xcode command line tools
xcodebuildmcpopenspec
一个原生 macOS 应用,可为 Apple 平台开发运行自主的 AI 编码代理。描述你想要构建的内容,AgentSwift 使用 Claude 来发现你的项目、实现更改、构建、运行并验证——无需你手动打开 Xcode。
功能概述
AgentSwift 驱动多阶段的代理工作流:
- Discover – Claude 检查你的 Xcode 项目结构和 scheme
- Implement – 编辑源文件以满足你的请求
- Build – 运行
xcodebuildmcp进行编译 - Launch / Validate – 在模拟器或 macOS 上启动应用,运行 UI 自动化以验证行为
- Archive – 标记任务完成
要求
- macOS 26.1+
- Xcode
- Node.js / npm
- 一个 Anthropic API 密钥
依赖项
在运行代理之前先安装以下两个 CLI:
xcodebuildmcp
为 Xcode 项目提供构建、启动和 UI 自动化功能。
npm install -g xcodebuildmcp
openspec
在代理会话之间跟踪实现规范。
npm install -g @fission-ai/openspec
设置步骤
- 在 Xcode 中构建并运行该应用。
- 打开 Settings 并输入你的 Anthropic API 密钥。
- 选择 Project Folder(你的 Xcode 项目根目录)。
- 可选地从下拉菜单中挑选一个 iOS Simulator。
- 输入你想要构建的内容,然后按 Cmd + Return。
首次运行时,代理会发现项目的 scheme 和模拟器目标。后续运行会跳过发现阶段,直接进入实现阶段。
模型
| Model | Use when |
|---|---|
| Claude Opus 4.7 | 复杂任务、大型代码库 |
| Claude Sonnet 4.6 | 更快迭代、轻量任务 |
关键行为
- Message queuing – 如果在代理运行时发送新消息,最新的会覆盖之前的。
- Build caching – 第一次构建后会提取 scheme、项目路径和模拟器 ID,并自动复用。
- Error escalation – 代理在失败时尝试一次修复,若仍失败则将错误呈现给你,而不是循环重试。
架构
AgentSwiftApp.swift // app entry point
ContentView.swift // UI, view models, agentic loop
AnthropicService.swift // Anthropic API client (streaming SSE)
ToolExecutor.swift // bash / read_file / write_file execution
Item.swift // chat message model
无外部 Swift 依赖——纯 SwiftUI + Foundation。

