feat: Phase5C+5D /compact AI摘要压缩 + 多行输入支持

/compact 增强:
- 用AI生成对话历史摘要替代简单清空
- 压缩后保留:原始系统提示 + AI摘要 + 最后一轮对话
- AI摘要保留关键决策、代码变更、文件路径等技术细节
- 摘要生成失败时静默降级(仅保留最近对话)

多行输入:
- 支持反斜杠(\\)续行:行末输入\\后回车继续下一行
- 续行提示符: '  ... '
- JLine SECONDARY_PROMPT_PATTERN 配置

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liuzh
2026-04-01 21:38:01 +08:00
co-authored by Copilot
parent 399cea4478
commit 094057f0d2
2 changed files with 100 additions and 26 deletions
@@ -114,35 +114,33 @@ public class ReplSession {
.streams(System.in, System.out)
.build()) {
// 检测是否为 dumb 终端并提示
boolean isDumb = "dumb".equals(terminal.getType());
if (isDumb) {
log.info("当前为 dumb 终端模式,建议使用 Windows Terminal / PowerShell / cmd 获得完整体验");
}
// 配置 Parser:支持反斜杠续行 (\) 和 三引号块 (""")
DefaultParser parser = new DefaultParser();
parser.setEscapeChars(new char[]{'\\'}); // 反斜杠续行
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.parser(new DefaultParser())
.parser(parser)
.completer(new ClaudeCodeCompleter(commandRegistry, toolRegistry))
.variable(LineReader.HISTORY_FILE, historyDir.resolve("history"))
.variable(LineReader.HISTORY_SIZE, 1000)
.variable(LineReader.SECONDARY_PROMPT_PATTERN, "%P ... ")
.option(LineReader.Option.CASE_INSENSITIVE, true)
.option(LineReader.Option.AUTO_LIST, true)
.build();
// 构建彩色提示符
// 提示符
String prompt = new AttributedStringBuilder()
.style(AttributedStyle.BOLD.foreground(AttributedStyle.CYAN))
.append(" ")
.style(AttributedStyle.DEFAULT)
.toAnsi(terminal);
// 续行提示符(多行输入时显示)
String rightPrompt = new AttributedStringBuilder()
.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.BRIGHT))
.append("")
.toAnsi(terminal);
printBanner(terminal);
CommandContext cmdContext = new CommandContext(agentLoop, toolRegistry, out, () -> running = false);
@@ -152,12 +150,10 @@ public class ReplSession {
try {
input = reader.readLine(prompt).strip();
} catch (UserInterruptException e) {
// Ctrl+C —— 取消当前输入,继续等待
spinner.stop();
out.println(AnsiStyle.dim(" ^C"));
continue;
} catch (EndOfFileException e) {
// Ctrl+D —— 退出
break;
}