fix: CLI交互优化 - 流式缩进+输入框横线+日志降噪
- 流式输出: ● 标识与文本同行,续行4空格缩进对齐 - 输入框: 上下横线(─)分隔输入区域,宽度自适应终端 - 日志: 工具异常日志降为debug级别,避免终端输出stack trace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -192,9 +192,17 @@ public class ReplSession {
|
||||
statusLine.enable(providerInfo.model(), agentLoop.getTokenTracker());
|
||||
}
|
||||
|
||||
// 输入框横线宽度
|
||||
int termWidth = terminal.getWidth();
|
||||
int lineWidth = termWidth > 10 ? termWidth - 2 : 78;
|
||||
String inputLine = AnsiStyle.DIM + "─".repeat(lineWidth) + AnsiStyle.RESET;
|
||||
|
||||
CommandContext cmdContext = new CommandContext(agentLoop, toolRegistry, commandRegistry, out, () -> running = false);
|
||||
|
||||
while (running) {
|
||||
// 输入框上横线
|
||||
out.println(inputLine);
|
||||
|
||||
String input;
|
||||
try {
|
||||
input = reader.readLine(prompt).strip();
|
||||
@@ -206,6 +214,9 @@ public class ReplSession {
|
||||
break;
|
||||
}
|
||||
|
||||
// 输入框下横线
|
||||
out.println(inputLine);
|
||||
|
||||
if (input.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -317,12 +328,25 @@ public class ReplSession {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// AI 回复前的 ● 标识
|
||||
out.println(AnsiStyle.BRIGHT_CYAN + " ● " + AnsiStyle.RESET);
|
||||
// AI 回复前的 ● 标识(不换行,后续流式文本紧跟其后)
|
||||
out.print(AnsiStyle.BRIGHT_CYAN + " ● " + AnsiStyle.RESET);
|
||||
|
||||
// 流式回调:逐 token 输出到终端
|
||||
// 流式回调:逐 token 输出到终端,自动在每行开头加缩进
|
||||
final boolean[] isNewLine = {false}; // 跟踪是否刚输出换行符
|
||||
String response = agentLoop.runStreaming(input, token -> {
|
||||
out.print(token);
|
||||
for (int i = 0; i < token.length(); i++) {
|
||||
char c = token.charAt(i);
|
||||
if (c == '\n') {
|
||||
out.println();
|
||||
isNewLine[0] = true;
|
||||
} else {
|
||||
if (isNewLine[0]) {
|
||||
out.print(" "); // 续行缩进(与 ● 后文本对齐)
|
||||
isNewLine[0] = false;
|
||||
}
|
||||
out.print(c);
|
||||
}
|
||||
}
|
||||
out.flush();
|
||||
});
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class AgentTool implements Tool {
|
||||
log.info("Sub-agent completed, result length: {} chars", result.length());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("Sub-agent execution failed", e);
|
||||
log.debug("Sub-agent execution failed", e);
|
||||
return "Error: Sub-agent failed: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class AskUserQuestionTool implements Tool {
|
||||
return "User response: " + userResponse;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to get user input", e);
|
||||
log.debug("Failed to get user input", e);
|
||||
return "Error: Failed to get user input - " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class WebSearchTool implements Tool {
|
||||
String html = fetchSearchPage(query);
|
||||
return parseResults(html, maxResults);
|
||||
} catch (Exception e) {
|
||||
log.error("Search failed: query={}", query, e);
|
||||
log.debug("Search failed: query={}", query, e);
|
||||
return "Error: Search failed - " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user