Skip to content

Fix the BLE auto connection bug.#36

Merged
9 commits merged into
AhakeyAI:mainfrom
ZephyrKeXiner:feat/ble-link-diagnostics
Jun 22, 2026
Merged

Fix the BLE auto connection bug.#36
9 commits merged into
AhakeyAI:mainfrom
ZephyrKeXiner:feat/ble-link-diagnostics

Conversation

@ZephyrKeXiner

@ZephyrKeXiner ZephyrKeXiner commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

1. 背景

针对 #34(macOS 一直「等待设备」,系统蓝牙/语音可用但 Studio 扫不到),
以及连接、刷新方面的一组可靠性问题。

2. 改动(4 个独立修复)

  1. 链路诊断 + 宽 service 兜底macOS: AhaKey Studio 一直扫描中,系统蓝牙和语音可用但界面等待设备 #34

    • 新增 LinkDiagnostic,把笼统的「等待设备」拆成可区分状态:蓝牙未开/无权限、
      配置链路(0x7340)未连、已连 HID/语音但配置链路未连、Agent 占用中、未发现设备。
      顶栏 pill 展示,hover 有可操作详情。
    • 设备被系统/语音链路连上后会停止广播 → 基于广播的扫描扫不到。
      connectAutomatically() 改用更宽的标准 service 集合(0x7340 / 180A / 180F / 1812)
      retrieve 系统已连接设备并主动 connect,didConnect 再 discover 0x7340。
  2. 识别 vibe code 固件名

    • vibe-coding 固件广播名形如 vibe code XXXX,而 app/agent 只认 AhaKey 前缀 → 被过滤。
      改为前缀白名单 ["AhaKey", "vibe code"] + matchesDeviceName(),app 与 agent 一致。
  3. Agent 起不来时自动回退 App 直连

    • 残留/失效的 LaunchAgent plist(指向旧路径)会让 app 把键盘「交给」一个跑不起来的
      agent,卡在「Agent 占用中」需手动重连。改为 load+start 后用真实 connect() 探测等
      socket,超时仍无则释放占用、App 直连(死 socket 不再误判为 agent 存活)。
  4. 修复状态轮询永久卡死

    • sendCommandAwaitingResponse 超时只 throw、不 resume 挂着的 CheckedContinuation
      withThrowingTaskGroup 会一直等它 → 函数不返回、defer 不清理、
      protocolResponseWaiters 残留 → 1.5s 状态轮询被 guard ...isEmpty 永久挡死
      (设备某模式不回应即触发,表现为页面不随键盘刷新、必须重连)。超时改为原子移除并 resume。

3. 测试

  • swift build 通过
  • 真机 vibe code B1D2 端到端验证:开机自动连上;状态轮询每 ~1.5s 跑、实时捕捉档位
    变化(3→0);agent 失效 plist 场景下自动回退 App 直连。
  • ⚠️ macOS: AhaKey Studio 一直扫描中,系统蓝牙和语音可用但界面等待设备 #34 的「已连未广播 → 主动接管」改动改了实际 BLE 连接行为;当前已验证回退/直连路径,
    但精确复现「系统已连但完全不在 retrieve 列表」的边界仍需更多设备验证。

4. 关联

Closes #34


5. Type of change / 修改类型

请选择本次 PR 的类型。
Please select the type of this PR.

  • Bug fix / Bug 修复
  • Documentation / 文档修改
  • New feature / 新功能
  • Refactor / 重构
  • Build or packaging / 构建或打包
  • Protocol example / 协议示例
  • Community project or showcase / 社区项目或展示
  • Other / 其他

6. Area / 涉及范围

请选择本次修改涉及的部分。
Please select the area affected by this PR.

  • desktop
  • protocol
  • awesome-ahakey
  • firmware
  • docs
  • macOS
  • Windows
  • Other / 其他

ZephyrKeXiner and others added 9 commits June 2, 2026 14:49
JSON-RPC 2.0 over stdio 插件骨架,rebased 到 upstream/main 新结构:

* AhaKeyPluginKit (library)
  - JSONRPC.swift       协议类型 (JSONValue / Request / Response / Error)
  - PluginClient.swift  actor 客户端 (readabilityHandler 事件驱动 stdin/stdout)
  - PluginHost.swift    host/* 方法 + 权限白名单
  - PluginLifecycle.swift initialize / initialized / shutdown / exit
  - PluginManifest.swift plugin.json + ${pluginDir} 占位符
  - PluginManager.swift  扫描目录、批量加载、错误隔离

* Plugin (executable demo)
  - `swift run Plugin` 跑一遍 PluginManager 流程
  - 用 AHAKEY_PLUGINS_DIR 指定插件目录

* AhaKeyConfig 主 app
  - dependencies 加 AhaKeyPluginKit (可直接 import)
  - exclude AhaKeyPlugin / AhaKeyPluginKit 避免被当成主 app sources

兼容 macOS 12:URL(filePath:) 全部改回 URL(fileURLWithPath:)
A small background plugin that polls the physical switch state once a
second, counts auto/manual flips, tracks per-mode dwell time, and exposes
demo/flowStats. Falls back to ~/.ahakey-fake-lever when no agent/keyboard
is reachable, so it can be demoed without hardware. Wired into the SDK
build / typecheck / clean scripts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ci.yml runs on push/PR: TypeScript SDK typecheck + tests, compile-check
all Swift targets, then package the macOS app and upload it as an artifact.
package_app.sh assembles AhaKeyConfig into an ad-hoc signed
"AhaKey Studio.app", shared by local builds and CI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Examples resolve @ahakey/plugin-sdk via package self-reference to
dist/index.d.ts, but dist/ is gitignored and absent on a clean CI
checkout, so `npm run typecheck` failed with "Cannot find module
'@ahakey/plugin-sdk'". Make typecheck self-contained by running
build:sdk first, the same way the test script already builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…stream layout

Upstream/main 把多平台目录从 platforms/<os>/ 拍扁成 ahakeyconfig-<os>/。
这一 commit 只做目录重命名,路径里引用 platforms/macos 的脚本/CI/docs
留到下一个 commit 处理。
Update platforms/macos -> ahakeyconfig-mac in path references that
belonged to feat/plugin's own commits (TS SDK npm scripts, CI
workflow working-directory, package_app.sh comments). README/CHANGELOG/
docs path references are left for the upcoming merge with upstream/main
to overwrite, since upstream already rewrote them.
Upstream/main 新增内容:
- bf49f5a: 灯效自定义 + 4 Mode + 权限延迟 + 编辑态优化 (AhakeyAI#33)
- README/CHANGELOG/docs 全部重写以反映多平台目录布局 (AhakeyAI#35)
- LICENSE 改为 placeholder(待与上游统一)

冲突解决:
- ahakeyconfig-mac/Sources/Agent/AhaKeyAgent.swift:人手 3-way merge
  保留 HEAD 的 hasLiveSocket() 检测 + Bool 返回值 (避免双 agent)
  并入 upstream 的 startWatchdog() 调用
- 6 个文件 (HookClient/AhaKeyConfigApp/AhaKeyStudioView/ContentView/
  generate_dmg_background.swift/generate_icons.swift):feat/plugin
  本身没改过内容,直接接受 upstream 版本
- Makefile + VibeCodeKeyboard.ico:跟随 upstream 搬到 repo root
- cursor_0.gif + build.local.env*:接受上游删除
@ZephyrKeXiner ZephyrKeXiner self-assigned this Jun 22, 2026
@ZephyrKeXiner ZephyrKeXiner changed the title Add AhaKeyPluginKit and demo executable with CI improvements Fix the BLE auto connection bug. Jun 22, 2026
@TheNorthStarYang TheNorthStarYang closed this pull request by merging all changes into AhakeyAI:main in c518f9f Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: AhaKey Studio 一直扫描中,系统蓝牙和语音可用但界面等待设备

2 participants