Skip to content

feat: enhance message input with system tag parsing and double-click navigation#76

Closed
heiboy0070 wants to merge 9 commits intowxtsky:mainfrom
heiboy0070:feature/message-input
Closed

feat: enhance message input with system tag parsing and double-click navigation#76
heiboy0070 wants to merge 9 commits intowxtsky:mainfrom
heiboy0070:feature/message-input

Conversation

@heiboy0070
Copy link
Copy Markdown

概述

增强刘海面板的消息输入功能,支持直接向 AI 终端发送消息,并优化用户交互体验。

主要变更

1. 消息输入功能

  • 添加 MessageInputBar 组件,在刘海面板中直接输入消息
  • 支持显示会话上下文(最近对话、AI 状态、工具历史)
  • 集成 TerminalWriter 模块,支持多种终端(iTerm2、tmux、WezTerm、kitty 等)

2. 权限批准附加内容

  • ApprovalBar 添加常驻输入框
  • 允许在批准/拒绝权限时附带额外内容
  • 内容通过 TerminalWriter 发送到终端

3. 系统标签解析

  • 解析并结构化显示系统标签(task-notification、system-reminder 等)
  • 过滤指令性文本,只保留用户关心的信息
  • 支持基本 Markdown 渲染

4. 交互优化

  • 双击刘海顶部返回会话列表
  • 点击 Session 卡片直接进入消息输入
  • Apple 风格滚动条样式(参考 DESIGN.md)

技术细节

  • 使用 NSRegularExpression 处理多行 XML 标签
  • 通过 DispatchQueue.main.asyncAfter 延迟发送内容,确保权限已处理
  • 使用 ChatMessageTextFormatter 复用项目现有的 Markdown 渲染

测试

  • 在 Claude Code/Cursor 中触发权限请求
  • 在输入框添加附加内容并批准
  • 验证终端收到附加内容

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Copy link
Copy Markdown
Owner

@wxtsky wxtsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢这个功能!消息输入和 TerminalWriter 的覆盖面很全面。Review 后发现几个需要修复的问题:

🚫 Blocker: 中文输入法(IME)不兼容

复现步骤

  1. 使用中文输入法在 MessageInputBar 输入中文(如输入 "哦哦哦")
  2. 按 Enter 发送

预期:发送 "哦哦哦" 到终端
实际:输入框内容变为原始键盘输入(如 "aaa"),消息未发送

原因:SwiftUI TextField.onSubmit 与 macOS 输入法的 Enter 键冲突。IME 先捕获 Enter 键处理 composition,导致 .onSubmit 拿到的是 raw input 而非已转换的中文。

建议修复方向

  • 使用 NSViewRepresentable 包装 NSTextField,在 textView(_:doCommandBy:) 中检查 hasMarkedText,仅在无活跃 composition 时处理 Enter
  • 或者:移除 .onSubmit,改用 onKeyPress(.return)(macOS 14+),它在 IME commit 之后才触发

其他建议

  1. UX 变更需谨慎:Session 卡片点击从「跳转终端」改为「打开消息输入」,这是一个影响所有用户习惯的变更。建议保持原有点击行为(跳转终端),仅通过 💬 按钮进入消息输入

  2. Magic delayapprovePermissionasyncAfter(deadline: .now() + 0.5) 硬编码延迟不可靠,建议用 completion handler

  3. L10n:新增的 4 个 key(send_message_placeholder 等)缺少日韩翻译,会与 PR #72 冲突

  4. 编译 warning:3 处 ?? "..." nil coalescing 多余(L10n subscript 返回非 optional),可以移除

Copy link
Copy Markdown
Owner

@wxtsky wxtsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢这个功能!消息输入和 TerminalWriter 的覆盖面很全面。Review 后发现几个需要修复的问题:

Blocker: 中文输入法(IME)不兼容

复现步骤

  1. 使用中文输入法在 MessageInputBar 输入中文(如输入 "哦哦哦")
  2. 按 Enter 发送

预期:发送 "哦哦哦" 到终端
实际:输入框内容变为原始键盘输入(如 "aaa"),消息未发送

原因:SwiftUI TextField 的 .onSubmit 与 macOS 输入法的 Enter 键冲突。IME 先捕获 Enter 键处理 composition,导致 .onSubmit 拿到的是 raw input 而非已转换的中文。

建议修复方向

  • 使用 NSViewRepresentable 包装 NSTextField,在 textView(_:doCommandBy:) 中检查 hasMarkedText,仅在无活跃 composition 时处理 Enter
  • 或者:移除 .onSubmit,改用 onKeyPress(.return)(macOS 14+),它在 IME commit 之后才触发

其他建议

  1. UX 变更需谨慎:Session 卡片点击从「跳转终端」改为「打开消息输入」,这是一个影响所有用户习惯的变更。建议保持原有点击行为(跳转终端),仅通过消息按钮进入消息输入

  2. Magic delay:approvePermission 中 asyncAfter(deadline: .now() + 0.5) 硬编码延迟不可靠,建议用 completion handler

  3. L10n:新增的 4 个 key(send_message_placeholder 等)缺少日韩翻译,会与 PR #72 冲突

  4. 编译 warning:3 处 ?? nil coalescing 多余(L10n subscript 返回非 optional),可以移除

Copy link
Copy Markdown
Owner

@wxtsky wxtsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: IME bug + suggestions

Blocker: Chinese IME incompatibility

Steps: Type Chinese (e.g. 哦哦哦) in MessageInputBar, press Enter.
Expected: Send Chinese text to terminal.
Actual: Input becomes raw keystrokes (e.g. aaa), message not sent.

Root cause: SwiftUI TextField onSubmit conflicts with macOS IME Enter key handling. IME captures Enter for composition, so onSubmit receives raw input instead of converted Chinese.

Fix suggestion: Use NSViewRepresentable wrapping NSTextField, check hasMarkedText in textView doCommandBy, only handle Enter when no active composition. Or use onKeyPress(.return) on macOS 14+ which fires after IME commit.

Other suggestions

  1. UX: Session card click changed from jump-to-terminal to open-message-input. This breaks existing user habits. Suggest keeping original click behavior, use message button only.
  2. Magic delay: asyncAfter 0.5s in approvePermission is fragile. Use completion handler instead.
  3. L10n: 4 new keys missing ja/ko translations, will conflict with PR 72.
  4. Warnings: 3 unnecessary nil coalescing operators (L10n subscript is non-optional).

@wxtsky
Copy link
Copy Markdown
Owner

wxtsky commented Apr 13, 2026

Hi, thanks for the latest commit (Markdown renderer)! However, the previous review issues are still unresolved:

  1. 🚫 Blocker: IMEMessageInputBar and ApprovalBar still use TextField + .onSubmit, Chinese input is still broken
  2. Session card click — Card click still opens message input instead of jumping to terminal. Please revert to original behavior, keep message input accessible via the 💬 button only
  3. Magic delayasyncAfter(0.5) still hardcoded in both approvePermission and denyPermission
  4. L10n — 4 new keys still missing ja/ko translations
  5. Nil coalescing — 3 unnecessary ?? "..." still present

Please address these before the next review round. The IME blocker is the highest priority. Thanks!

@heiboy0070 heiboy0070 force-pushed the feature/message-input branch from 0d904ac to d2b7b41 Compare April 13, 2026 08:10
heiboy0070 and others added 6 commits April 13, 2026 16:22
- Add IslandSurface.messageInput state for message input UI
- Create TerminalWriter module to send text to various terminals
- Add MessageInputBar with session context preview
- Integrate message input into notch panel and session cards
- Support content attachment in permission approval flow
- Add L10n support for new features
…ll UI

- Add TerminalWriter.sendText() for sending text to various terminals
- Add MessageInputBar with session context preview and markdown rendering
- Parse system tags (task-notification, system-reminder) to show structured info
- Improve approval bar with inline input for attaching content to decisions
- Add Apple-style scroll view wrapper following DESIGN.md guidelines

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add TapGesture(count: 2) to the notch bar area
- Use contentShape(Rectangle()) to make entire bar clickable
- Animate transition back to .sessionList with NotchAnimation.close

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix Chinese IME compatibility using NSTextField with hasMarkedText check
- Restore session card click behavior to activate terminal (UX fix)
- Add global ESC key handler using NSEvent monitor
- Add input text persistence across session navigation
- Improve table rendering with inline markdown support
- Remove redundant nil coalescing operators
@heiboy0070 heiboy0070 force-pushed the feature/message-input branch from d2b7b41 to 1dd1239 Compare April 13, 2026 08:24
@heiboy0070 heiboy0070 requested a review from wxtsky April 13, 2026 08:44
heiboy0070 and others added 3 commits April 13, 2026 17:09
Add a new setting in Behavior section to choose what happens when clicking a session card:
- Activate Terminal (default)
- Open Message Input

This allows users who prefer the message input panel to set it as the default click action.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add timestamp-based debouncing to prevent duplicate sends
- Fix memory leak in ESC key monitor (add cleanup onDisappear)
- Add clipboard-based fallback for terminal text sending
- Add error status display on session cards (5 min window)
- Add horizontal scroll for wide markdown tables
问题:当通过消息输入框发送消息时,消息会被发送两次

根因:AppleScript 脚本在找到目标 session 后没有立即 return,
导致继续执行循环并返回 "not_found",然后降级到
sendViaITermCurrentSession,向错误的 session 再次发送。

修复:在 AppleScript 脚本中找到 session 后立即 return "found",
不再降级到错误的 session。
nguyenvanduocit pushed a commit to nguyenvanduocit/CodeIsland that referenced this pull request Apr 15, 2026
- PR wxtsky#80 MERGED: configurable notch height modes → T-026
- PR wxtsky#86 open: auto-collapse after session jump → T-027 (watch)
- PR wxtsky#76 open: message input bar + TerminalWriter → T-028 (watch)
- Issue wxtsky#84: Ghostty quick terminal activation bug → T-029
- Note PR wxtsky#69 and wxtsky#70 now merged upstream (T-024, T-025 ready)
- vibe-island: no new code changes

https://claude.ai/code/session_01Hoa4hooNsWEnv8vC42x8G3
Copy link
Copy Markdown
Owner

@wxtsky wxtsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢持续迭代!IME 兼容和 Session 点击行为配置化都改好了 👍 还有几个问题需要修复:

仍需修复

1. Magic delay 0.5s 仍然存在(上次 review 已提)

AppState.swiftapprovePermissiondenyPermission 里的 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) 还在。硬编码延迟不可靠——网络慢时 0.5s 不够,快时白等。建议用 completion handler 或在权限 response resume 之后再发送。

2. ApprovalBar 输入框未使用 IME 兼容方案

MessageInputBar 已经用了 IMECompatibleTextField(NSTextField 包装),但 ApprovalBar 里新增的附加内容输入框还是用的原生 SwiftUI TextField + .onSubmit——中文输入法 Enter 键冲突问题同样会出现。请统一使用 IMECompatibleTextField

3. L10n 新增 key 缺少土耳其语翻译

新增的 send_to_terminalapproval_input_placeholdersession_click_actionsession_click_action_descclick_action_terminalclick_action_message_inputremote_input_unsupported 等 key 在土耳其语中只补了部分。请补齐,或者至少让 L10n fallback 到英文不会 crash(确认现有 fallback 机制能覆盖)。

4. ESC 键监听可能重复安装

installEscapeKeyMonitor()onAppear 调用,但如果 view 重建(比如外部显示器切换),会重复安装而旧的 monitor 没被清理。建议在安装前先检查 escapeMonitor != nil 则先清理旧的。

已修复 ✅

  • IME 兼容性 → IMECompatibleTextField + hasMarkedText 检查
  • Session 卡片点击行为 → 可配置(默认 terminal)
  • iTerm2 消息重复发送 → AppleScript return 修复
  • 防重复发送 → timestamp debounce

@wxtsky
Copy link
Copy Markdown
Owner

wxtsky commented Apr 16, 2026

Hi @heiboy0070, 这个 PR 已经好几轮 review 了。关键的 blocker 还差几个:

  1. ApprovalBar 附加内容输入框未用 IME 兼容方案NotchPanelView.swift 的新增 TextField 还是原生 SwiftUI + .onSubmit,中文输入法 Enter 键冲突)
  2. AppState.approvePermission / denyPermissionasyncAfter(deadline: .now() + 0.5) 还在 — 硬编码延迟不可靠
  3. TerminalWriter.copyToClipboard 污染系统剪贴板且未备份恢复
  4. TerminalWriter.escapeAppleScript 换行转义错误:AppleScript 字符串不支持 \n 转义,多行消息会在终端显示字面量
  5. sendViaKeystroke 300ms 竞态:期间用户切应用会把剪贴板粘到错位置

另外建议把 PR 拆成几块(TerminalWriter 基建 / MessageInputBar / ApprovalBar 附加内容 / 系统标签解析 / 双击刘海),方便 review 和回滚。1400+ 行的 PR 合进去风险太大。

最近两周如果没动静,我会先 close 掉。非常感谢你的工作,希望能把这几个问题收一下 💪

@heiboy0070 heiboy0070 closed this Apr 17, 2026
nguyenvanduocit pushed a commit to nguyenvanduocit/CodeIsland that referenced this pull request Apr 18, 2026
…retired)

- T-034: ConfigInstaller destructive reformat bug confirmed (issue wxtsky#106)
- T-035: Multi-Space agent visibility issue to investigate (issue wxtsky#104)
- T-028: PR wxtsky#76 closed/abandoned upstream — retired from kanban

https://claude.ai/code/session_0144Meziev1pfqVGh547wmvG
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