Operational Steps
- 确认输入参数完整
- 执行核心操作(参考本目录下的 scripts/ 或 references/)
- 验证输出符合契约
- 保存结果并报告
Pitfalls
-
-
Verification
-
-
-
-
1. 2. 3.
IO_CONTRACT
- input:
recipient: str, message: str— 用户请求描述、上下文信息 - output:
sent_status: dict — iMessage
对应原则:P2(机械原子暴露输入输出规范)
iMessage
Use imsg to read and send iMessage/SMS via macOS Messages.app.
Prerequisites
- macOS with Messages.app signed in
- Install:
brew install steipete/tap/imsg - Grant Full Disk Access for terminal (System Settings → Privacy → Full Disk Access)
- Grant Automation permission for Messages.app when prompted
When to Use
- User asks to send an iMessage or text message
- Reading iMessage conversation history
- Checking recent Messages.app chats
- Sending to phone numbers or Apple IDs
When NOT to Use
- Telegram/Discord/Slack/WhatsApp messages → use the appropriate gateway channel
- Group chat management (adding/removing members) → not supported
- Bulk/mass messaging → always confirm with user first
Quick Reference
List Chats
imsg chats --limit 10 --json
View History
# By chat ID
imsg history --chat-id 1 --limit 20 --json
# With attachments info
imsg history --chat-id 1 --limit 20 --attachments --json
Send Messages
# Text only
imsg send --to "+14155551212" --text "Hello!"
# With attachment
imsg send --to "+14155551212" --text "Check this out" --file /path/to/image.jpg
# Force iMessage or SMS
imsg send --to "+14155551212" --text "Hi" --service imessage
imsg send --to "+14155551212" --text "Hi" --service sms
Watch for New Messages
imsg watch --chat-id 1 --attachments
Service Options
--service imessage— Force iMessage (requires recipient has iMessage)--service sms— Force SMS (green bubble)--service auto— Let Messages.app decide (default)
Rules
- Always confirm recipient and message content before sending
- Never send to unknown numbers without explicit user approval
- Verify file paths exist before attaching
- Don't spam — rate-limit yourself
Example Workflow
User: "Text mom that I'll be late"
验证清单 · VERIFICATION
-
imsg chats --limit 10 --json正常返回(终端已有 Full Disk Access 与 Messages 自动化权限) - 发送前已通过
imsg chats定位收件人 chat-id/号码,并与用户确认收件人与消息内容 - 目标号码/Apple ID 非陌生号,且获得用户明确批准(批量发送必须二次确认)
- 带附件时
--file路径真实存在(imsg send成功,sent_status 无错误) -
--service显式选择(imessage/sms)符合预期通道,气泡类型与意图一致
约束规则 · RULES
- 输入约束: 参数类型、范围、格式必须校验
- 输出约束: 返回值结构、编码、命名必须一致
- 异常约束: 错误信息必须包含上下文和恢复建议
- 安全约束: 不执行未验证的任意代码,不暴露内部状态
Golden 集合 · GOLDEN SET
- Golden Input: 标准输入样本(覆盖正常路径)
- Golden Output: 预期输出(精确匹配或格式校验)
- Golden Error: 预期错误信息(覆盖失败路径)
Golden 集合是测试的单一真理来源。所有改进必须通过 golden 测试。
违反规则的操作视为不安全,必须拒绝或隔离。
每项验证必须可执行、可记录、可复现。验证失败时记录原因和修复。
# 1. Find mom's chat
imsg chats --limit 20 --json | jq '.[] | select(.displayName | contains("Mom"))'
# 2. Confirm with user: "Found Mom at +1555123456. Send 'I'll be late' via iMessage?"
# 3. Send after confirmation
imsg send --to "+1555123456" --text "I'll be late"
Imessage
Genes (策略基因)
紧凑策略表示。条件→策略。需要深度时参考完整文档。
- [IMES-001] 发送消息前 → 必须向用户确认收件人身份及消息内容
- [IMES-002] 目标号码未知或未经明确批准 → 禁止发送消息
- [IMES-003] 执行批量或大规模群发操作 → 必须先获得用户明确确认
- [IMES-004] 发送包含附件的消息 → 需预先验证文件路径存在且有效
- [IMES-005] 需要区分消息通道(iMessage/SMS) → 使用
--service参数显式指定服务类型 - [IMES-006] 处理非 Apple 生态消息(如 Telegram/WhatsApp) → 拒绝使用 imsg 并引导至对应网关