Skip to content

feat(aiwork): add AiWork GUI and CLI/TUI support - #336

Merged
wxtsky merged 6 commits into
wxtsky:mainfrom
x4vierli:feat/aiwork-gui-tui-task-status
Sep 23, 2026
Merged

wxtsky merged 6 commits into
wxtsky:mainfrom
x4vierli:feat/aiwork-gui-tui-task-status

Conversation

@x4vierli

@x4vierli x4vierli commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

这个 PR 做什么

新增第 16 个工具支持:AiWork,GUI 与 CLI/TUI 都覆盖。

本期是只读可视化:AiWork 的会话状态完整进刘海,但授权 / 计划确认 / 作答这些交互动作本期不支持在刘海里完成,仍需回到 AiWork 侧操作。展示层与现有工具对齐,交互层不对齐。

支持了哪些功能

  • 会话卡片 —— 会话标题、工作目录、来源徽章(AiWork / AiWork CLI)、实时运行状态
  • 工具调用 —— 正在执行什么,实时更新
  • 回复与思考流式显示 —— 回复正文与思考过程按增量实时刷新在会话卡片上,用户提交的 prompt 也保留可见,回合结束后仍可回看最近一段
  • 等待类状态(只读) —— 需要授权、要求确认计划、或反问问题时,刘海会亮起对应的等待状态并显示请求内容 / 问题文本;同意、拒绝、作答都要回 AiWork 侧操作,面板不提供按钮和输入框
  • 回合边界 —— 完成 / 失败 / 中断各有对应结果文案(新增「回复失败」「回复已中断」两条)。完成与失败各有一次提示音,中断静默;提示音沿用现有逐事件开关与静音时段设置
  • 点击跳转 —— 点会话卡片把 AiWork 窗口拉到前台,按工作目录的目录名匹配到具体项目窗口
  • 启动即接管 —— CodeIsland 启动、或打开开关时,已经在跑的 AiWork 会话会被回填进面板,不必等下一个回合
  • 空闲自动收走 —— 回合结束或客户端退出后约 60 秒,该卡片自动离开面板(其他工具是 10 分钟无活动超时,AiWork 明显更快,这是可感知的行为差异);进行中的回合每有新事件就续期,不会被误清

界面与设置:

  • AiWorkBot 吉祥物 —— 新画的像素风角色,GUI 与 CLI 共用,三种状态动画(空闲休眠 / 工作 / 等待响应)
  • CLI 图标 —— 新增 aiwork.png,会话列表与来源徽章都能显示
  • 两个独立开关 —— 设置里 AiWork(GUI)与 AiWork CLI 分开控制,可以只开其中一个
  • iPhone / Watch companion —— 手机与手表能看到 AiWork 会话卡片、状态与 AiWorkBot 形象(新增 AIWORK / AIWORK CLI 标签);远程授权不适用,因为本期不产生可操作的授权请求
  • 多语言 —— 新增的两条提示文案覆盖全部 7 种语言

一个与其他工具不同的点

现有 15 个工具都要往它们自己的配置里装 hook 或插件,AiWork 不需要 —— CodeIsland 主动读取 AiWork 自身暴露的运行时状态,装好 AiWork 就能识别,用户侧零配置。

两个开关沿用现有 cli_enabled_* 的语义:未显式关闭时默认为开。所以升级后本机若装有 AiWork(GUI 或 CLI),无需任何操作就会开始显示;本机没有 AiWork 时探测空转退出,不起计时器也不建连接。要完全关闭请在 Hooks 设置里分别关掉这两项。

顺带修掉一个既有缺陷

接手时 swift test 有 2 个失败(AppStateGitBranchTests,断言读到 nil)。查下来是既有缺陷,与本功能无关,本 PR 一并修掉:

refreshClaudeUsageIfStale() 的 usageScanInFlight 是每实例标志。生产环境只有一个 AppState,所以从未暴露;但测试进程里每个 AppState() 各起一次冷扫描去扫真实 ~/.claude(我这台机器 153 MB / 698 个 .jsonl),把共享的 8 个 .utility 协作线程池线程全部打满,而 git 分支探测同样跑在 .utility 上,于是分不到线程、超过 2 秒预算读到 nil。

证据:sample 活进程显示 8 个线程 340/340 采样全部停在同一个扫描函数里;把 CLAUDE_CONFIG_DIR 指向空目录后两个失败同时消失;其中 testBranchRefreshesOnStopAfterSwitch 在干净 main 的 worktree 上同样失败。

修法是一行语义修正:usageScanInFlight 改为进程级。这个扫描读的是同一份共享历史,两次并发永远是重复劳动,去重本就该是进程级的。生产行为不变,测试套件从 2 failures / 13.4s 变成 0 failures / 6.0s。我没有去抬轮询预算 —— 那只是掩盖问题且仍然依赖负载。

验证

构建:swift build 与 swift build -c release 均干净通过,全包 0 条编译警告。

测试:swift test 裸跑(不需要任何环境变量)—— 973 tests, 3 skipped, 0 failures,6.0 秒,连跑三次一致。仓库用例数从 933 增至 973,新增 40 个用例,覆盖连接读写、状态映射、GUI/TUI 归属判定、空闲清扫判定、占位文案本地化等。

一项未经编译验证,如实说明

iOS / Watch 端的改动我无法在本机编译验证 —— 本机 Xcode 26.6 没有装 iOS 平台 SDK(iOS 26.5 is not installed),xcodegen 也未安装。我做了力所能及的静态验证:

  • AiWorkView.swift 只 import SwiftUI,零 AppKit / NS* 用法,与已在 iOS target 正常编译的 ClineView.swift 同构
  • project.pbxproj 通过 plutil -lint 校验
  • 该文件已按 ClineView.swift 的现有条目逐字段镜像:1 个 PBXFileReference + 4 个 PBXBuildFile + group 条目 + 4 个 target 的 Sources 阶段
  • project.yml 也同步加了(4 个 target),xcodegen generate 可复现同样结果

如果 CI 或你本地编译报错,我立刻跟进修。

兼容性

  • macOS 端以新增为主:不改动任何现有工具的行为,未新增任何依赖(Package.swift 零改动)
  • 触及共享代码的只有这几处,且都行为中立:usageScanInFlight 改进程级、AgentStatus 增加 Equatable 一致性、enqueueCompletion 放宽可见性、SessionSnapshot 新增一个字段与几个 source 别名、Hooks 页开关回调统一入口,以及刘海文字动画新增一个默认关闭的内部参数(只对 AiWork 打开,其余工具动画逐像素不变)

x4vierli and others added 6 commits September 23, 2026 11:10
新增第 16 个工具支持:AiWork,GUI 与 CLI/TUI 都覆盖。本期是只读可视化 ——
状态完整进刘海,但授权 / 计划确认 / 作答这些交互动作仍需回到 AiWork 侧操作。

刘海里可以看到:会话标题、工作目录、来源徽章、实时运行状态、正在执行的工具,
以及回复正文与思考过程的流式增量。需要授权、确认计划或被反问时会亮起对应的
等待状态并显示请求内容,但面板不提供按钮和输入框。完成 / 失败 / 中断各有结果
文案(新增「回复失败」「回复已中断」两条,覆盖 7 种语言),完成与失败各有一次
提示音,中断静默。点会话卡片把 AiWork 窗口拉到前台,按工作目录匹配项目窗口。
启动或打开开关时会回填已经在跑的会话;空闲会话在最后一次活动后约 60 秒自动
离开面板。GUI 与 CLI 是两个独立开关,共用一个 AiWorkBot 像素风吉祥物。
iOS / Watch companion 能看到会话与形象(远程授权不适用)。

与现有 15 个工具不同,AiWork 不需要往配置里装 hook 或插件:CodeIsland 主动
读取 AiWork 自身暴露的运行时状态,装好即可识别。两个开关沿用现有 cli_enabled_*
语义,未显式关闭时默认为开;本机没有 AiWork 时探测空转退出。

顺带修一处既有缺陷(本次改动使其暴露):refreshClaudeUsageIfStale 的
usageScanInFlight 是每实例标志,构造多个 AppState 时会同时发起 N 次冷扫描,
在共享的 .utility 协作线程池上互相饿死。改为进程级去重 —— 该扫描读的是同一份
~/.claude 历史,两次并发永远是重复劳动。测试套件因此从 2 个失败 / 13.4 秒
变成 0 失败 / 6.0 秒,并消除了包内最后一条 Swift 6 并发警告。

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…stop per-token pushes

- startAiWorkWatcher now returns before scheduling its 3s rediscovery timer
  when AiWork is absent. Both toggles default on, so every install carried the
  timer; aiworkIsPresent() already existed but was never called.
- aiworkCliIsPresent looked for "aiwork" twice; the second entry is the legacy
  "dtcoder" binary. The state-dir check honours AGENTIX_STATE_DIR like the
  watcher's own discovery.
- A TUI (aiwork-cli) session no longer carries the AiWork IDE bundle id. With
  it, TerminalActivator took the native-app branch and raised (or launched,
  via openApplication) the desktop app on click, and isIDETerminal reported an
  IDE host. Identity is now applied after client_type is known and clears an
  earlier GUI guess.
- text/thinking deltas skip refreshDerivedState unless status changed. It
  notifies the companion (Multipeer + BLE) and Buddy (ESP32 BLE) publishers on
  every call, which meant one push per streamed token.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Approvals, plan confirmations and answers still happen in AiWork itself, so
"Full" in the supported-tools table overstated it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
unaryCall waits on a DispatchGroup for up to its timeout, and all three
callers (hydrate, backfill, the busy-status reconcile) ran it inside
Task.detached. A daemon that accepts but never answers therefore pinned one
thread of Swift's cooperative pool per in-flight call, and with more calls
than cores every other Task in the app stalled.

unaryCallAsync now does the blocking wait on a dedicated serial GCD queue and
resumes the caller through a continuation; fetchBusyDaemonSessionIds is async
on top of it, and every call site awaits it. Serial means one hung daemon
pins at most one GCD thread; the RPCs are few and rate-limited, so queuing is
fine.

Also sets SO_NOSIGPIPE on the daemon socket. The app does not ignore SIGPIPE,
so a send() racing a daemon hang-up (restart, quit) would have killed
CodeIsland instead of failing with EPIPE.

Tests now run against an in-process fake daemon (FakeAgentixDaemon) under a
temp state dir: a round trip, a hang-up that must read as "unreachable" (nil)
rather than "nothing busy", and a hung daemon with more callers than cores
that must not delay an unrelated task (fails at ~2.8s on the old code). The
live test that dialled whatever daemon was running on the developer's
machine is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Stream-event tests hydrate through sessions.get, and hydrate falls back to
discovering daemons under ~/.agentix. On a machine running AiWork, the suite
sent RPCs to the developer's real daemon.

AppState gains aiworkStateDirOverride (nil in production = $AGENTIX_STATE_DIR
or ~/.agentix), and every discovery goes through discoverAiWorkDaemons(). The
AppState AiWork tests point it at a path that does not exist.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A failed hydrate released its marker, and an untitled session re-hydrates on
every stream event, so a daemon that kept failing sessions.get was re-dialled
(new socket, new RPC) by the first token after each failure landed, which in
live streaming means about once per token. A missing socket path did the same
with a directory scan.

A failure now keeps the marker and stamps aiworkHydrateFailedAt; the next
attempt waits out aiworkHydrateRetryCooldown (30s). beginAiWorkHydrateAttempt /
noteAiWorkHydrateFailed / forgetAiWorkHydrateState own the bookkeeping, and
every place that drops a session clears both, so stamps don't outlive it.

Tests: the gate itself (in flight, cooldown edges, reset after the session
leaves), and a fake daemon that fails sessions.get while 25 deltas arrive
after the first failure: exactly one connection (the old code re-dialled).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@wxtsky
wxtsky force-pushed the feat/aiwork-gui-tui-task-status branch from 16a838e to e06c4c2 Compare September 23, 2026 03:11
@wxtsky
wxtsky merged commit 6fc538d into wxtsky:main Sep 23, 2026
@wxtsky

wxtsky commented Sep 23, 2026

Copy link
Copy Markdown
Owner

已合并(6fc538d),感谢这么完整的 PR!验证和说明都很扎实,usageScanInFlight 改成进程级那个修复我们本地也复现了(main 上 GitBranch 测试在全量负载下确实会挂),这次一起解决了。

合并前我在你的分支上补了几处修复,说明一下改了什么:

  1. 没装 AiWork 也会起 3s 计时器:默认开启时,所有用户都会跑一个每 3 秒的计时器,和描述里说的不起计时器不符。aiworkIsPresent() 写了但没被调用,现在检测不到 AiWork 就不启动。
  2. 点 CLI/TUI 卡片会拉起桌面端:TUI 会话也带了 IDE 的 bundle id,点卡片会走原生 App 分支,把 AiWork 桌面端拉到前台,没开就直接启动,正好是注释里说不能发生的情况。现在只有 GUI 会话带 IDE 身份,并补了测试。
  3. 每个 token 推送一次:text/thinking delta 每个 token 都调一次 refreshDerivedState(),会给 iPhone 和 Buddy 各推一次。现在只在状态变化时刷新。
  4. 同步 RPC 占用协作线程池:unaryCall 在 Task.detached 里同步等待,最长 5 秒,和你诊断的线程饿死是同一类问题。已挪到专用串行队列,用 continuation 桥接回来。
  5. sessions.get 失败后逐 token 重连:失败后每来一个 token 就新建一次连接,现在改为 30 秒冷却。
  6. 测试不再连本机真实 daemon:换成临时目录里的进程内假 daemon;AppState 的 hydrate 路径也加了 state dir 覆盖。
  7. SO_NOSIGPIPE:daemon 恰好在写入时断开,CodeIsland 会因 SIGPIPE 直接崩溃,现在只会收到普通的写错误。
  8. 小修:aiworkCliIsPresent 里重复的 aiwork 改成了 dtcoder;README 标注改为「只读」。

另外想确认一下:你是 AiWork / Agentix 团队的同学吗?这个集成读的是 Agentix daemon 的 NDJSON 协议(sessions.watch/get/list),目前没有公开文档,协议一变就会悄悄失效。后续协议有变动的话,希望你能帮忙跟进,或者提供一份兼容性说明。随下一个版本发布。

@x4vierli

x4vierli commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

感谢您愿意在合并前把这些问题一个个修掉,而不是直接打回来让我重做。那 8 处我对着你的改动逐条看过了,确实全是我这边的遗漏,后续的提交中我会加强测试尽可能规避类似的问题。

关于您关心的后续更新的问题,我是 AiWork / Agentix 研发团队的同学。后续 Agentix daemon 这套 NDJSON 协议我会长期负责这边的兼容性,有需要我这边配合的,随时 @ 我。

祝好!

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.

2 participants