feat(less-computer): Less Computer 语音 Agent —— 专用键 + 动作模式 + 流式聊天弹框 + 内联审批(启发式)#597
feat(less-computer): Less Computer 语音 Agent —— 专用键 + 动作模式 + 流式聊天弹框 + 内联审批(启发式)#597appergb wants to merge 25 commits into
Conversation
issue #579 骨架的首个垂直切片(UCW 版):只接 Claude Code、放行 + 护栏。 后端 coding_agent/ 模块(19 单测全绿,已对真实 claude v2.1.161 验证链路): - args: claude -p 无头流式 argv 构造 - stream: stream-json 逐行解析为 CodingAgentEvent - guard: 高风险命令分类 + acceptEdits + deny 清单护栏 settings - detect: 解析 claude --version / mcp list(computer use 检测口径) - mod: tokio 异步运行器(超时 / 取消 / stderr 排空)+ git stash create 快照 - commands: detect / run_test(护栏流式)/ cancel / command_risk,注册入 lib.rs 前端 Claude 控制台(设置 → 高级): - 检测面板 + 终端观感流式输出 + 用量;权限模式 / 工作目录 / 可执行路径 - ipc 封装 + 类型 + 5 语言 i18n;控制台测试默认 sonnet 控成本 未含(后续阶段):语音双热键 + coordinator 接线 + 面板 + prefs 持久化。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…/权限/工作目录) - UserPreferences 新增 7 字段(coding_agent_*):启用开关、后端 provider、模型、 权限模式、工作目录、面板热键、快取用热键;贯穿 struct/Wire/双向转换/默认。 - 前端 types.ts/ipc.ts 同步类型与 mock;CodingAgentPermissionMode 收敛到 types.ts 单一来源。 - 新增 CodingAgentSection(设置→高级):启用开关、Claude/OpenCode 选择、两个 ShortcutRecorder(可启用/停用)、权限模式、模型、工作目录。 - i18n 全 5 语言新增 settings.codingAgent.*。 热键实时注册与触发执行链路(coordinator 接线)随后续提交。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR Reviewer Guide 🔍(Review updated until commit 8c1e4df)Here are some key observations to aid the review process:
|
- 新增 coding_agent_hotkey.rs:双绑定全局热键监听器(面板键 + 快取用键), 镜像 qa_hotkey,3 单测。 - coordinator 接线:Inner 加 coding_agent_hotkey;新增 supervisor(仅 coding_agent_enabled 时注册)+ bridge loop + handler;lib.rs 启动调用。 - handler:capture_selection → 护栏化 run_claude_agent(sonnet 默认、deny 清单、 git 快照、成本封顶)→ TextInserter 回插光标。本版面板键暂同走快取用, 语音 + 面板随后续版本。 cargo check 绿;coding_agent 全模块 22 单测通过。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
更新(0463c30):「按键 → 操作」执行链路已接通 ✅
|
|
Persistent review updated to latest commit 0463c30 |
- 快取用键 = 选中文本润色:选中→Claude 润色→回插替换;全程胶囊反馈 (没选中提示"请先选中文本";润色中/完成/出错都显示),纯文本 plan 只读、无 guard、便宜可靠。 - 面板键 = Cloud Agent(语音→ASR→Claude→结果弹窗),完整流程开发中,先给可见提示。 - 两个热键从「高级」移到「通用→快捷键」,停用按钮置于录制器左边、常驻行。 - CodingAgentSection 精简为开关/后端/模型/权限/工作目录 + 热键位置提示;5 语言 i18n。 cargo check + tsc + vite 均绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 8211dea |
目标 2(快速 Agent 完全不生效)根因:用户把 Cloud Agent 绑成单修饰键 "Right ⌘",而 global-hotkey 无法注册单修饰键 → 注册无限失败、按下无任何反应。 - coding_agent_hotkey: 单个坏 binding 只跳过、不再拖垮整体注册,也不再无限重试空转 - coordinator: 启动时自愈无效绑定(单修饰键)→ 换成有效组合键(⌘⇧Enter/⌘⇧J)并持久化+通知前端 - types: 新增 default_coding_agent_quick_hotkey,panel/quick 默认值供自愈回退 - ShortcutRecorder: 新增 comboOnly(拒绝单修饰键并提示)+ 内联停用旋钮, 停用按钮紧贴录制按钮左侧成组靠右(两个旋钮布局) - ShortcutsSection: 切风格/打开App/选区问答/选中文本润色/Cloud Agent 全部统一为内联停用旋钮 - i18n(5 语言): 新增 settings.recording.comboNeedKey;选中文本润色标签去掉"(Claude)"后缀 验证:cargo check ✅ / cargo test(hotkey+binding) ✅ / tsc ✅ / hotkey-injection gate ✅
|
Persistent review updated to latest commit b532ef9 |
把 supervisor 里内联的「无效单修饰键→有效组合键」自愈逻辑抽成可测纯函数, 新增单测复现用户故障(Right ⌘ 面板键 → 自愈为可注册的 ⌘⇧Enter),并覆盖 快取键、有效组合键不动、None 不动等分支。 验证:cargo test coding_agent_hotkey 7 passed / tsc ✅
|
Persistent review updated to latest commit 51d1587 |
emit_capsule 在校验 app 句柄前记录 last_capsule_state(廉价单锁,用户行为不变), 让无 GUI 测试能断言热键事件确实触发了可见胶囊。新增集成测试 coding_agent_panel_ press_emits_visible_capsule:开启功能→驱动 handler→断言下发 Error 胶囊(开发中提示), headless 复现并验证目标 2(a)「按下有反馈」。 验证:cargo test coding_agent 27 passed / cargo check 仅余既有 warning
|
Persistent review updated to latest commit 1b2a15d |
handle_coding_agent_panel 之前用 CapsuleState::Error(红色),用户读成"报错"。 其实只是"敬请期待"信息提示 → 改用 Done(中性色)。同步更新集成测试断言。 日志确认:之前的红色就是这条占位提示,并非真实崩溃。
按用户新交互方案:toggle 听写模式下,长按右 Option(>550ms)把当前会话升级成 语音 Agent —— 录音→ASR→把转写交给无头 Claude 跑任务→结果弹胶囊(不插入光标)。 短按仍是普通听写,行为完全不变。 实现(最大化复用、最小化对核心听写的改动): - coordinator_state: SessionState 加 voice_agent 标志,begin_session_state 必复位(安全护栏 + 单测) - dictation: handle_pressed(Toggle,Idle) 武装长按计时器;计时器到点且仍按住→置 voice_agent; handle_released(Toggle) 若 voice_agent→end_session(按住说话语义); end_session 拿到转写后分流到 run_voice_agent_transcript(Plan 只读、安全 MVP) - 退役组合键:supervisor 清空 panel/quick 绑定并停止注册;移除两个设置行, 改为只读提示「长按听写键」;删除已无用的 sanitize_agent_hotkeys + 测试 + default_quick - i18n(5 语言):新增 agentVoiceHint / agentVoiceTrigger 限制(已知):仅 toggle 听写模式接长按;hold 模式的「点按=Agent」未接。结果走胶囊, 长文本展示有限。权限固定 Plan 只读,不产生副作用。 验证:cargo check 0 error / coordinator 64 + dictation 33 + coding_agent 23 单测全过 / tsc 0
arm_voice_agent_long_press 之前在 begin_session(含 ASR 握手)之后才睡 550ms, 握手慢时实际长按阈值被拉长、判定不稳。改为从 state.started_at(≈按下时刻)算起 睡剩余时间,阈值稳定。
|
Persistent review updated to latest commit ee50665 |
|
Persistent review updated to latest commit e9e7ba5 |
无头 claude -p 单次运行没有多轮兜底,模型中途提问/给半成品这一轮就废了。新增 coding_agent::autonomous_prompt(task):把真实需求包进目标驱动(/goal 式)的自动化指令—— 要求先定目标与完成标准、自主连续执行到彻底完成、不提问、不给计划/半成品、长任务也在本次跑完、 只回最终结果。语音 Agent 改用它构造 prompt。 验证:autonomous_prompt 单测过 / cargo check 0 error
|
Persistent review updated to latest commit ff918ec |
把「长按听写键」方案换成独立专用键 coding_agent_voice_hotkey(默认 LeftControl, 支持 Ctrl/Option/Fn 等单修饰键,亦支持组合键),按住说话、松开处理: - 单修饰键 → 第二个 CGEventTap(HotkeyMonitor,Hold 模式);组合键 → ComboHotkeyMonitor - handle_less_computer_pressed/released:按下开始录音并标记 voice_agent,松开 end_session → 复用既有 run_voice_agent_transcript(autonomous_prompt + Plan 只读) - 完整冲突校验(Less Computer vs 听写/QA/翻译/切风格/打开应用) - 移除旧 coding_agent_hotkey(global-hotkey panel/quick)模块;macOS-only - 设置 UI、i18n(5 语言)、mock/types 同步 审核结论:后端实现完整、已测试可跑。65 coordinator + 20 coding_agent 单测全过 (含 less_computer_press_emits_visible_capsule、冲突校验测试)。 注:当前 Less Computer 配置在「高级」里,下一步按用户要求挪到「通用」并做弹框 + UI 整理。
- 通用 → 快捷键 新增 Less Computer 行(macOS):可直接启用并录制按住说话键, 和听写/翻译/QA/切风格/打开应用一排,用户一眼就能看到(之前埋在高级里)。 启用按钮一键置 codingAgentEnabled=true + 默认键,保存即触发后端重新注册。 - 高级 → Less Computer 移除重复的按住说话键行,只留后端/模型/权限/工作目录。 - tsc 0。
|
Persistent review updated to latest commit dae966f |
根因:run_voice_agent_transcript 之前硬编码 Plan 只读 + 无工具,所以 Agent 只能返回文本、 根本不会真的开 Chrome / 跑命令。改成项目既有的「放行 + 护栏」动作模式: - permission_mode = acceptEdits(尊重高级里的设置;coding_agent_mode_from_pref 映射) - allowed_tools = Bash/Read/Edit/Write/Glob/Grep/WebFetch/WebSearch(能真正动手) - 护栏 settings:deny 高风险(rm -rf / sudo / 强推等)自动拦截 = 用户选的「混合:仅高风险」MVP - cwd = workdir 或 $HOME(--add-dir 限定文件作用域);运行前 git 快照便于回滚;用后清理临时护栏文件 真实链路实测(claude v2.1.161,haiku):让它「在 /tmp 建 lesscomputer_probe.txt 内容 ok」 → 文件真的被创建、result=success/「done」、15.8s/$0.05。证明无头链路确实会执行动作。 「开 Chrome」走同一条 Bash 路径(open -a)。 注:交互式弹审批(高风险在弹框点同意)+ 自适应弹框 UI 为后续;当前高风险=自动拦截。 cargo check 0 / less_computer + guard + autonomous_prompt 单测全过。
|
Persistent review updated to latest commit 8fd3ca4 |
|
Persistent review updated to latest commit 5546e50 |
…affolding Adds a macOS-only fluid chat popup (window label=less-computer) for the Less Computer voice agent. Streams user bubble + assistant Delta + tool chips + final result/cost as the agent runs, instead of only showing the final capsule. Content-adaptive height (bottom-anchored, clamped 120-520, scrolls past max), non-movable, always-on-top, frost aesthetic mirroring the QA panel. Esc / close button dismiss. High-risk guard hits surface an inline Approve/Deny card; Approve re-runs the task once with that pattern lifted from the deny list. Windows/Linux keep it hidden and inert (no hotkey, no emit). i18n added to all 5 locales. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit d6ca97d |
|
Persistent review updated to latest commit 26e7c48 |
|
Persistent review updated to latest commit 93c54ca |
|
Persistent review updated to latest commit cf933cb |
…动(顶栏拖把手+resize原位锚定); agent超时120→300s/预算0.5→2$
|
Persistent review updated to latest commit 120cc15 |
|
@claude 审核一下。这个代码是否可以合并? |
|
Claude finished @appergb's task in 2m 36s —— View job PR #597 代码审核任务清单
结论:暂不建议合并功能和架构本身很扎实,测试覆盖充分,但下面列出的安全问题未解决前,这条「语音 → shell 执行」链路的风险不可控。以下按严重程度分级: 🔴 必须修复(阻塞合并)1. 护栏配置写入失败后仍传入无效路径(
|
| 层 | 状态 |
|---|---|
| 架构 / 功能 | ✅ 整体合理,流式浮窗 + 护栏设计清晰 |
| 测试覆盖 | ✅ 单测充分,关键逻辑都有覆盖 |
| 护栏写入失败 bug | 🔴 必须修复 |
| Deny 清单不完整 | 🔴 必须修复 |
| Approve 格式不一致 | 🔴 必须修复 |
| bypassPermissions 可激活 | 🟡 应修复 |
| WebFetch 无限制 | 🟡 应修复 |
| 审批重跑幂等性 | 🟡 建议改进 |
| 死代码 / DOMPurify | 🟢 次优先 |
最关键的是第 1 条:写护栏配置失败时的静默降级会让整条链路在无护栏下裸跑,这在「语音→shell 执行」场景下是不可接受的。修复后,加上 deny 清单补全,整体已经是一个很好的 MVP。
|
本轮收尾更新(commit
验证:
本地安装包: 备注:按项目要求尝试了 |
|
Persistent review updated to latest commit 8c1e4df |
User description
这个 PR 是什么
Less Computer:语音操控电脑的 Agent。按住一个专用全局键(默认 LeftControl)说话 → ASR 转写 →
无头
claude -p自主完成电脑任务(开应用 / 跑命令 / 读写文件)→ 结果以流式聊天弹框 + 全屏彩虹描边呈现。能力一览
coding_agent_voice_hotkey):第二个 CGEventTap 跑裸修饰键(Ctrl/Option/Fn),组合键走 ComboHotkeyMonitor;按住说话、松开处理。配置在「通用 → 快捷键」。--settingsdeny 高风险命令 + 运行前 git 快照。实测能真正建文件/开应用。claude --continue续会话;弹框开着时每轮带上下文,关闭即重开。前端聊天多气泡。less-computer):用户气泡 → 助手逐字流式 → 工具芯片 → 内联审批卡 → 结果/花费;内容自适应高度、可拖动(顶栏把手 + resize 原位锚定)、Esc/✕ 关。less-computer-glow):全屏点击穿透浮层,沿屏幕圆角的高斯柔光跑马灯(边缘清晰、向内羽化),按下键即亮、完成熄灭。参考开源 MacEdgeLight / Apple Edge Light。请重点审查(已知薄弱点,欢迎严查)
coordinator/dictation.rs::maybe_request_approval):一轮跑完后扫终局文本关键词 + 高风险模式 → 弹审批卡 → Approve 则放行该模式重跑一轮。关键词匹配脆、重跑对不可重入操作(删/写)有幂等性风险。deny.retain用精确字符串比较,HIGH_RISK_PATTERNS与default_deny_rules格式不一致处会静默失效。建议合并前降级为「auto-deny + 告知」直到有真正的 MCP permission 通道。coding_agent/guard.rs):上轮安全审查指出缺osascript/launchctl/写~/.zshrc/~/Library/LaunchAgents/chmod/curl|python等 macOS 持久化&外泄面;WebFetch无出站限制;默认 cwd=$HOME 范围偏大;bypassPermissions可由 prefs 激活使护栏失效。这条语音→shell 链路是高敏感面,建议这轮一并收口。coding_agent_hotkey.rs(lib.rs 已无mod声明)、未调用的handle_coding_agent_quick、残留 prefscoding_agent_panel_hotkey/quick_hotkey+ 对应 i18n。LessComputerPanel.tsx的dangerouslySetInnerHTML(markdown) —— 已用自定义 renderer 转义 + 协议白名单,建议确认是否再加 DOMPurify 兜底。测试
cargo check 0 / coordinator + dictation + coding_agent 单测全过(含 less_computer 触发、冲突校验、autonomous_prompt、voice_agent 复位);tsc 0。真机 macOS:按住键→录音→Claude 动作→流式弹框 + 全屏描边,已跑通。
平台:macOS 优先(Less Computer 仅 macOS 生效,Win/Linux 隐藏)。已并入 origin/beta 的 Linux/i18n 修复。
🤖 Generated with Claude Code
PR Type
Enhancement, Tests
Description
Voice agent with dedicated hotkey and Claude Code backend
Streaming chat panel and full-screen rainbow glow feedback
Inline approval flow for high-risk command interception
Continuous conversation mode and settings UI configuration
Diagram Walkthrough
File Walkthrough
16 files
Add coding agent hotkey supervisor and state machinesAdd window show/hide/resize for Less Computer and glowAdd Less Computer dismiss, resize, approve commands and hotkeyconflict checksImplement voice agent transcript handling, approval, and continuousconversationCreate Claude Code runner module with autonomous prompt and gitsnapshotBuild claude args and CodingAgentRequest structExpose detect, run_test, cancel, command_risk Tauri commandsParse stream-json lines into CodingAgentEvent enumDefine high-risk patterns and guard settings JSON builderParse claude version and MCP server listNew streaming chat panel with user/assistant bubbles and inlineapprovalFull-screen rainbow glow overlay with edge light effectClaude console settings with terminal UI and usage displayVoice agent settings UI with provider, model, hotkey, and permissionmodeAdd new UserPreferences fields for coding agent andCapsulePayload.operatingAdd voice_agent field for session state1 files
Fix held latch reset in update_shared_binding for hold mode2 files
Minor formatting and improve plugin detection logicAdd cfg_attr for Linux dead_code allowance26 files