feat(aiwork): add AiWork GUI and CLI/TUI support - #335
Closed
x4vierli wants to merge 1 commit into
Closed
Conversation
…on watch 新增第 16 个工具支持:AiWork(原 DTCoder),GUI 与 CLI/TUI 都覆盖。 它和现有 15 个工具的根本差异是**不安装任何 hook**:CodeIsland 直接连 Agentix 守护进程的 Unix socket(~/.agentix/run/*/agent.sock,需同时存在 agent.ready 才算就绪),订阅 sessions.watch,把 20 个 stream.* 事件映射成 会话卡片;sessions.get 补齐 title/cwd/client_type,agent.stats 与 sessions.list 在连接建立时回填在跑的会话。GUI 与 CLI 在 Hooks 设置里是两个 独立开关,共用一个 AiWorkBot 吉祥物。 入方向是 Agentix 自定义的 V2 信封(顶层 kind 为 response/event,换行分帧), 不是标准 JSON-RPC 通知,见 agentix crates/common/src/rpc_protocol.rs 的 ResponseEnvelopeV2 / StreamEventV2;出方向仍写标准 JSON-RPC 2.0 请求。 守护进程的两个特性决定了两处设计: - 它的会话存储把每个会话永久标记为 status:"active",从不发送关闭事件。所以 空闲会话会在最后一次活动后 60 秒被清扫,否则跑完的 eval 会在刘海里堆到 10 分钟无监控超时为止。实时回合每个 stream 事件都会刷新 lastActivity, 正在用的会话不会被误清。 - client_type 只能通过 sessions.get 拿到,而现代 aiwork tui 同样使用 acp: 前缀,所以 GUI/TUI 无法单靠 session id 判断。注水返回前只做临时归属。 命名:对外与内部标识统一为 AiWork/aiwork。bundle id 仍是 com.alipay.dtcoder.ide,daemon 的 client_type 仍可能是 DTCoderGUI/DTCoderTUI, 这两类外部协议值原样保留并继续识别。 顺带修一处既有缺陷(本次改动使其暴露):refreshClaudeUsageIfStale 的 usageScanInFlight 是每实例标志,构造多个 AppState 时会同时发起 N 次冷扫描, 在共享的 .utility 协作线程池上互相饿死。改为进程级去重 —— 该扫描读的是同一份 ~/.claude 历史,两次并发永远是重复劳动。这让整个测试套件从 2 个失败 / 13.4 秒 变成 0 失败 / 6.0 秒,并消除了包内最后一条 Swift 6 并发警告。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
|
抱歉打扰,描述需要重写(去掉了不必要的实现细节),关掉这个重新提一个。 |
Author
|
重新提交在 #336,内容相同,只是描述重写过。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 做什么
新增第 16 个工具支持:AiWork,GUI 与 CLI/TUI 都覆盖。
支持了哪些功能
刘海面板对 AiWork 会话的支持与现有工具完全对齐:
配套的界面与设置:
aiwork.png,会话列表和终端徽章都能显示一个与其他工具不同的点
现有 15 个工具都要往配置里写 hook,AiWork 不需要 —— CodeIsland 主动读取 AiWork 自身暴露的运行时状态,装好 AiWork 打开开关就能识别,用户侧零配置。
另外,AiWork 侧不会主动通知"会话结束",所以空闲会话会在最后一次活动之后自动离开面板,避免跑完的任务一直占着刘海。正在进行的回合每次有新事件都会续期,不会被误清。
顺带修掉一个既有缺陷
接手时
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 秒,连跑三次一致。新增 24 个用例,覆盖连接读写分帧、状态映射、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 或你本地编译报错,我立刻跟进修。
兼容性
usageScanInFlight,以及刘海文字动画新增了一个默认关闭的开关(只对 AiWork 打开,其余工具行为逐像素不变)