feat: Phase2 JLine终端交互增强 - 行编辑、历史、Tab补全、信号处理

JLine 3 集成:
- ReplSession重写: JLine Terminal + LineReader 替代Scanner
- 支持行编辑(光标移动、删除、Home/End等)
- 持久化历史记录(~/.claude-code-java/history)
- 上下箭头浏览输入历史
- Ctrl+C取消当前输入、Ctrl+D退出
- JLine失败时自动降级到Scanner模式

Tab补全:
- ClaudeCodeCompleter: 斜杠命令补全(/后按Tab)
- 支持命令别名补全(如 /q → exit)
- 分组显示(Commands / Aliases)

新增命令:
- /model: 显示当前AI模型信息
- /compact: 压缩对话上下文
- /cost: Token用量显示(占位)

改进:
- HelpCommand清理为统一格式
- Banner增加终端信息显示和快捷键提示
- 彩色提示符使用AttributedStringBuilder

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liuzh
2026-04-01 20:18:59 +08:00
co-authored by Copilot
parent 70c9ebed2b
commit b29d61581a
7 changed files with 358 additions and 53 deletions
@@ -0,0 +1,34 @@
package com.claudecode.command.impl;
import com.claudecode.command.CommandContext;
import com.claudecode.command.SlashCommand;
import com.claudecode.console.AnsiStyle;
/**
* /compact 命令 —— 压缩当前对话上下文。
* <p>
* 对应 claude-code/src/commands/compact.ts。
* 当前为简化实现,直接清空历史并提示用户。
*/
public class CompactCommand implements SlashCommand {
@Override
public String name() {
return "compact";
}
@Override
public String description() {
return "Compact conversation context";
}
@Override
public String execute(String args, CommandContext context) {
if (context.agentLoop() != null) {
int before = context.agentLoop().getMessageHistory().size();
context.agentLoop().reset();
return AnsiStyle.green(" ✓ Context compacted: " + before + " messages → 1 (system prompt only)");
}
return AnsiStyle.yellow(" ⚠ No active conversation to compact.");
}
}