Commit Graph
29 Commits
Author SHA1 Message Date
abel533andCopilot 3b47c5e818 feat: cursor movement in input field
- Left/Right arrow keys move cursor within text
- Home/End jump to line start/end
- Insert text at cursor position (not just at end)
- Backspace/Delete work at cursor position
- Paste inserts at cursor position
- History browsing sets cursor to end
- Visual cursor: inverse style on character under cursor
- Hide terminal hardware cursor in normal input (use rendered cursor)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:43:40 +08:00
abel533andCopilot 8946ca93f2 feat: dynamic terminal title matching official Claude Code behavior
- Title updates on every user message (not just the first)
- Shows current tool name during execution: '⠂ Bash · user topic'
- Animation pauses during permission prompts (matches isWaitingForApproval)
- Clears tool name when tool completes
- Priority: sessionTitle (from user input) > 'Claude Code' (fallback)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:28:09 +08:00
abel533andCopilot d63a10c221 fix: hide cursor during selection mode and agent execution
- Permission selection: cursor hidden (❯ marker indicates selection)
- AskUser selection: cursor hidden (same reason)
- Agent running: cursor hidden (no text input needed)
- AskUser input mode: cursor still visible at text position
- Normal idle: cursor visible at input position

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:12:18 +08:00
abel533andCopilot f05732a60c fix: terminal title uses jink writeRaw instead of raw PrintStream
Terminal title now writes OSC 0 through Ink.Instance.writeRaw()
which goes directly to the JLine terminal. This eliminates garbled
characters caused by writing through intercepted System.out/err or
to streams that bypass the terminal's ANSI processing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:27:15 +08:00
abel533andCopilot ecb88b25a0 fix: restore header border, defer title init, fix title encoding
- Restore bordered headerBox as single scrollable item in messagesArea
- Defer terminal title init to first render() (after jink ready)
- Title uses ConsolePatcher.getOriginalOut() to bypass interception
- Ctrl+C fix in jink: INT signal handler now respects exitOnCtrlC flag

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:18:34 +08:00
abel533andCopilot db3de65c3c fix: header scrolls with messages, auto-scroll pauses on scroll-up
- Header/logo moved from fixed layout to messagesArea first items
  (matches official LogoHeader behavior: scrolls with messages, not pinned)
- addMessageInternal preserves scrollOffset when user has scrolled up
  (matches official sticky-scroll: only auto-scrolls when at bottom)
- Terminal title uses ConsolePatcher.getOriginalOut() to bypass interception

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:08:08 +08:00
abel533andCopilot 4523e7e4d3 fix: markdown ####, Ctrl+C exit bug, terminal title
- MarkdownToText: support heading levels 1-6 (was 1-3, causing #### raw display)
- Ctrl+C: agent cancel no longer starts exit window (matching official double-press flow)
- Terminal title: dynamic OSC 0 title with animated spinner during work, static idle prefix
  - Matches official useTerminalTitle hook + AnimatedTerminalTitle component
  - Session title inferred from first user message (simplified vs AI generation)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:55:20 +08:00
abel533andCopilot 54c3cb41a9 feat: 工具执行流式输出预览
- ToolEvent 新增 PROGRESS 阶段,工具可在执行中报告进度
- ToolContext 添加 progressCallback,工具可通过 reportProgress() 报告输出行
- BashTool 在读取每行输出时实时报告进度
- AgentLoop 在工具执行前设置进度回调,执行后清除
- ToolCallMsg 支持 outputLines 字段,保留最后 5 行流式预览
- 运行中的工具在消息区显示实时输出(灰色,截断至 120 字符)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:22:35 +08:00
abel533andCopilot 012d5dfae6 feat: 添加 Ctrl+R 反向历史搜索
- Ctrl+R 进入搜索模式,输入关键词实时过滤历史记录
- 输入区显示 bash 风格搜索提示: (reverse-i-search)\query': result
- 再按 Ctrl+R 搜索更旧的匹配项
- Enter 选定结果放入输入框,Esc 退出搜索
- 快捷键栏显示搜索模式操作提示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:15:45 +08:00
abel533andCopilot 6c5580ccd7 feat: 添加斜杠命令 Tab 自动补全
- 输入 / 开头时,前缀匹配所有已注册命令
- Tab 键补全唯一匹配,多个匹配时循环选择
- 输入区显示 ghost text(灰色补全后缀提示)
- 快捷键栏显示匹配命令列表(最多5个)
- 当前 Tab 选中项高亮显示
- Backspace/Esc/Submit 时同步更新建议列表

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:13:24 +08:00
abel533andCopilot f995a34d66 feat: 对齐官方快捷键和动画行为
Phase A (快速修复):
- Ctrl+C 双击窗口从 2000ms 改为 800ms(匹配官方)
- 添加 Ctrl+L 强制重绘
- 添加 Ctrl+Home/End 跳到顶部/底部

Phase B (动画改进):
- Thinking 显示持续时间: 'Thinking...' → 'Thinking (5s)...'
  (2秒后开始显示时间,匹配官方行为)
- Processing 显示输出 token 计数
- 底部自动滚动已正确实现(新消息 scrollOffset=0)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:06:34 +08:00
abel533andCopilot 99a4ccf059 feat: 块光标 + 动画移至消息区 + 权限交互选择
块光标:
- 输入区使用 █ 块光标(匹配原版 Claude Code 风格)
- Agent 运行中输入区只显示 ❯ █

动画效果:
- 思考/处理动画从输入区移至消息区底部
- 使用旋转帧 ◐◓◑◒ + Thinking.../Processing... 文字
- Agent 运行中快捷键栏显示 'esc to interrupt'

权限确认:
- 从 Y/A/N/D 文本输入改为交互选择模式
- 3个选项:Yes / Yes, and don't ask again / No
- 支持 ↑↓ 选择、Enter 确认、Esc 取消、1-3 快捷选择
- Tool use 消息显示蓝色分隔线 + 工具详情
- 新增 requestTextInput() 用于无选项的简单文本输入

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:51:21 +08:00
abel533andCopilot 5ad2628b1a feat: Ctrl+C 双击退出(匹配原版 Claude Code 行为)
- 第一次 Ctrl+C: Agent 运行中则取消任务,空闲时清空输入
- 第二次 Ctrl+C (2秒内): 退出应用
- 快捷键栏显示 'Press Ctrl-C again to exit' 黄色提示
- 2秒超时后自动清除提示(虚拟线程定时)
- 移除未使用的 cmdCount 字段
- 保留 Esc 中断和 Ctrl+D 退出作为备选

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:43:17 +08:00
abel533andCopilot a20dffa7a0 fix: 改进滚动 maxOffset 计算
使用 totalItems - visibleLines 替代 totalItems - 1
避免滚动到只剩1行内容的极端情况

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:35:10 +08:00
abel533andCopilot a30dfa9ad0 fix: 修复滚动限制 + 自动检测Shell类型
滚动修复:
- scroll() 使用实际渲染行数而非消息数计算 maxOffset
- 解决 /help 等多行输出无法滚动到顶部的问题

Shell 检测:
- Windows 自动检测 PowerShell 7+ > Windows PowerShell > cmd.exe
- 动态调整 BashTool 描述,告知AI使用正确的命令语法
- 系统提示词包含详细的 Shell 使用指南(PowerShell cmdlets)
- header 显示检测到的 Shell 类型
- Unix 优先 bash,回退 sh

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:33:42 +08:00
abel533andCopilot e47a3445df fix: 修复代码审查发现的线程安全和边界问题
- render() 中对 volatile 字段取快照,避免跨线程竞争
- 光标位置 clamp 到 >= 0,防止小终端越界
- spinner 线程使用独立 spinnerLock 保护启停操作
- PrintStream 使用 try-with-resources 避免资源泄漏
- 终端高度 < 20 时隐藏标题框腾出空间

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:44:32 +08:00
abel533andCopilot ffb94bb2f7 feat: 添加 Escape/Ctrl+C 中断 Agent 运行功能
- AgentLoop 添加 cancel()/resetCancel() 中断机制
- executeLoop 在每次迭代前和API调用后检查取消标志
- Escape 键和 Ctrl+C 在 Agent 运行时触发中断
- 快捷键栏更新提示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:34:55 +08:00
abel533andCopilot 91190e180b ui: 改进消息显示,添加空行分隔和更友好的初始提示
- 初始消息改为 Ready 提示(header已包含工具/命令信息)
- 用户消息前添加空行分隔,提升对话可读性
- 保持工具调用和系统消息紧凑展示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:32:17 +08:00
abel533andCopilot f28d2328ef refactor: 权限/AskUser回调改为虚拟线程执行,避免锁竞争
- handlePermissionInput 回调在虚拟线程中执行
- confirmAskUser 回调在虚拟线程中执行
- 移除 confirmAskUser 中多余的 synchronized 嵌套

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:28:57 +08:00
abel533andCopilot 7199b4f2dd fix: 修复消息区溢出布局问题,恢复Spacer弹性空白
- 消息区添加 .height(maxMessageLines) + .overflow(HIDDEN) 防止溢出
- 恢复 Spacer.create() 在消息少时填充空白
- AskUser工具添加调试日志帮助排查结构化回调

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:25:47 +08:00
abel533andCopilot 65bd5b5d9a feat: interactive AskUser with arrow-key selection
- Add interactive option selection for AskUserQuestion tool
  (arrow keys ↑↓, Enter confirm, 1-9 quick select, Esc cancel)
- Last option with '其他/Other' enters free text input mode
- New ASK_USER_STRUCTURED_CALLBACK in AskUserQuestionTool
  accepts (question, options) BiFunction for structured interaction
- ClaudeCodeComponent renders option list with ❯ indicator
- Cursor position adjusts for variable-height ask area
- Falls back to simple text prompt when no options provided

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 16:03:23 +08:00
abel533andCopilot 2f645b9d85 enhance: improve header colors, streaming markdown, scroll preservation
- Header: use colored values (API cyan, model green, dir yellow, etc.)
- Markdown: render progressively during streaming (not just after completion)
  - Streaming cursor appended to last rendered line
- Scroll: preserve user scroll offset during streaming token updates
  - Previously reset to 0 on every token, now keeps user position
- All process info (tool calls, thinking) persists after completion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:51:23 +08:00
abel533andCopilot 9a437889b7 enhance: ASCII logo header, thinking animation, markdown rendering
- Restore original ASCII coffee cup logo in header (dual-column layout)
- Fix shortcutBar to single line with height(1) constraint
- Add spinning animation for thinking indicator (◐◓◑◒ cycle at 120ms)
- Create MarkdownToText converter for assistant messages:
  - Headers (# ## ###) with distinct colors and prefixes
  - Bold (**text**) rendering
  - Inline code (\code\) in yellow
  - Code blocks with language label and │ prefix
  - Ordered/unordered lists with bullet points
- Streaming messages show raw text; completed messages use markdown

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:42:53 +08:00
abel533andCopilot b72fcfea79 fix: add thread safety for concurrent state modifications
- Add stateLock to synchronize all getState/setState read-modify-write
  operations across UI thread and AgentLoop background threads
- Synchronize onInput, onPaste, addMessage, appendToStreamingMessage,
  finishStreamingMessage, completeLastToolCall, setThinking, runAgent
- Extract addMessageInternal() to avoid double-locking
- Harden extractToolSummary with explicit indexOf checks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:08:04 +08:00
abel533andCopilot 75ecaeca58 enhance: improve tool call display with smart arg extraction
- Add extractToolSummary() to show human-readable tool arguments
  (command: $ ..., file_path: path, pattern: ..., query: ...)
- Tool running state shows 'running...' suffix
- Tool completed state shows 'done' suffix
- Match original Claude Code tool status rendering style

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:03:23 +08:00
abel533andCopilot 02ab8c2777 enhance: improve assistant message rendering and console patching
- Split multi-line assistant messages into separate rendered lines
- Add streaming cursor (▌) indicator for in-progress responses
- Add patchConsole() to intercept System.out/err during TUI mode
- Handle empty assistant message edge case

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:02:04 +08:00
abel533andCopilot 45283c87e4 fix: improve command handling and add paste support
- Add ToolRegistry to ClaudeCodeComponent for proper command context
- Use ByteArrayOutputStream to capture command output in TUI mode
- Add onPaste() override for efficient multi-line paste handling
- Fix constructor to accept toolRegistry parameter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:00:29 +08:00
abel533andCopilot 199ad6259b refactor: cleanup unused imports, add conversation summary tracking
- Remove unused MarkdownRenderer import and field from ClaudeCodeComponent
- Add onFirstUserInput callback for conversation summary tracking
- Wire conversation summary in JinkReplSession

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 14:57:05 +08:00
abel533andCopilot 601a1c9ea9 feat: add jink TUI framework integration
- Add jink dependency (io.mybatis.jink:jink:0.3.0-SNAPSHOT)
- Create UIMessage sealed interface for TUI message model
- Create ClaudeCodeComponent (main jink Component with full layout)
  - Header box with rounded magenta border
  - Message list with virtual scrolling
  - Separator lines above/below input area
  - Input area with prompt and placeholder
  - Status bar and shortcut key bar
- Create JinkReplSession (jink-based REPL replacing JLine readLine loop)
  - AgentLoop integration via callbacks -> setState
  - Permission confirmation inline in TUI
  - Streaming token display
- Update ClaudeCodeRunner to prefer jink TUI with legacy fallback
- Update AppConfig with JinkReplSession bean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 14:52:55 +08:00