Core Workflow
- 1. Scan — Discover nearby devices
- Identify — Match against known profiles or learn new device
- Connect — Establish link with appropriate protocol
- Execute — Send commands, read data, manage state
- Learn — Update device profile based on interaction success/failure
Quick Reference
| Need | Load |
|---|
| CLI commands by platform | INLINECODE0 |
| Device profile management |
profiles.md |
| Security rules and warnings |
security.md |
| Patterns by use case |
use-cases.md |
Workspace
Store device profiles and interaction history:
CODEBLOCK0
Critical Rules
- 1. Never auto-connect to unknown devices — require explicit user confirmation
- Whitelist first — only interact with pre-authorized devices
- Log everything — every connection attempt, command, result
- Fail gracefully — if device unreachable, retry with backoff, then report
- Profile learning — when something works, save it; when it fails, note why
Platform Detection
| OS | Primary Tool | Fallback |
|---|
| Linux | INLINECODE4 | INLINECODE5 , INLINECODE6 |
| macOS |
blueutil |
system_profiler, CoreBluetooth |
| Windows | WinRT/PowerShell |
pnputil for enumeration |
| Cross-platform | Bleak (Python) | Noble (Node.js) |
Device Interaction Pattern
CODEBLOCK1
核心工作流程
- 1. 扫描 — 发现附近设备
- 识别 — 匹配已知配置文件或学习新设备
- 连接 — 使用适当协议建立链路
- 执行 — 发送命令、读取数据、管理状态
- 学习 — 根据交互成功/失败更新设备配置文件
快速参考
| 需求 | 加载文件 |
|---|
| 各平台CLI命令 | tools.md |
| 设备配置文件管理 |
profiles.md |
| 安全规则与警告 | security.md |
| 用例模式 | use-cases.md |
工作空间
存储设备配置文件与交互历史:
~/bluetooth/
├── profiles/ # 已知设备配置(每设备一个文件)
├── history.md # 交互日志(含成功/失败记录)
└── pending.md # 已发现但未配置的设备
关键规则
- 1. 切勿自动连接未知设备 — 需用户明确确认
- 白名单优先 — 仅与预授权设备交互
- 记录一切 — 每次连接尝试、命令、结果
- 优雅失败 — 设备不可达时,退避重试后上报
- 配置文件学习 — 成功时保存配置,失败时记录原因
平台检测
| 操作系统 | 主要工具 | 备用工具 |
|---|
| Linux | bluetoothctl | hcitool、gatttool |
| macOS |
blueutil | system_profiler、CoreBluetooth |
| Windows | WinRT/PowerShell | pnputil(枚举用) |
| 跨平台 | Bleak (Python) | Noble (Node.js) |
设备交互模式
- 1. 检查 ~/bluetooth/profiles/ 中的设备
- 若已知 → 加载配置文件,使用已保存命令
- 若未知 → 扫描特征,发现能力
- 执行请求操作
- 验证结果(读取状态、检查确认)
- 更新配置文件:记录成功项、失败项、时序信息