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>
This commit is contained in:
@@ -3,7 +3,6 @@ package com.claudecode.tui;
|
|||||||
import com.claudecode.command.CommandContext;
|
import com.claudecode.command.CommandContext;
|
||||||
import com.claudecode.command.CommandRegistry;
|
import com.claudecode.command.CommandRegistry;
|
||||||
import com.claudecode.console.BannerPrinter;
|
import com.claudecode.console.BannerPrinter;
|
||||||
import com.claudecode.console.MarkdownRenderer;
|
|
||||||
import com.claudecode.core.AgentLoop;
|
import com.claudecode.core.AgentLoop;
|
||||||
import com.claudecode.core.TokenTracker;
|
import com.claudecode.core.TokenTracker;
|
||||||
import com.claudecode.tui.UIMessage.*;
|
import com.claudecode.tui.UIMessage.*;
|
||||||
@@ -64,7 +63,6 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
private final int toolCount;
|
private final int toolCount;
|
||||||
private final int cmdCount;
|
private final int cmdCount;
|
||||||
private final TokenTracker tokenTracker;
|
private final TokenTracker tokenTracker;
|
||||||
private final MarkdownRenderer markdownRenderer;
|
|
||||||
private final Runnable onExit;
|
private final Runnable onExit;
|
||||||
|
|
||||||
// --- 内部状态 ---
|
// --- 内部状态 ---
|
||||||
@@ -76,8 +74,8 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
/** 权限确认回调(由权限请求设置,用户输入后调用) */
|
/** 权限确认回调(由权限请求设置,用户输入后调用) */
|
||||||
private volatile Consumer<String> permissionCallback;
|
private volatile Consumer<String> permissionCallback;
|
||||||
|
|
||||||
/** 流式 Markdown 渲染状态 */
|
/** 首次用户输入回调(用于 conversation summary) */
|
||||||
private MarkdownRenderer.StreamState streamMdState = new MarkdownRenderer.StreamState();
|
private Consumer<String> onFirstUserInput;
|
||||||
|
|
||||||
public ClaudeCodeComponent(AgentLoop agentLoop,
|
public ClaudeCodeComponent(AgentLoop agentLoop,
|
||||||
CommandRegistry commandRegistry,
|
CommandRegistry commandRegistry,
|
||||||
@@ -94,7 +92,6 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
this.toolCount = toolCount;
|
this.toolCount = toolCount;
|
||||||
this.cmdCount = cmdCount;
|
this.cmdCount = cmdCount;
|
||||||
this.tokenTracker = tokenTracker;
|
this.tokenTracker = tokenTracker;
|
||||||
this.markdownRenderer = new MarkdownRenderer(null); // 不直接打印,用 renderLine()
|
|
||||||
this.onExit = onExit;
|
this.onExit = onExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,6 +512,10 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Agent 调用
|
// Agent 调用
|
||||||
|
if (onFirstUserInput != null) {
|
||||||
|
onFirstUserInput.accept(text);
|
||||||
|
onFirstUserInput = null; // 只触发一次
|
||||||
|
}
|
||||||
addMessage(new UserMsg(text));
|
addMessage(new UserMsg(text));
|
||||||
setState(new TuiState("", getState().messages, 0, true, ""));
|
setState(new TuiState("", getState().messages, 0, true, ""));
|
||||||
runAgent(text);
|
runAgent(text);
|
||||||
@@ -523,7 +524,6 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
/** 在后台线程运行 Agent 循环 */
|
/** 在后台线程运行 Agent 循环 */
|
||||||
private void runAgent(String userInput) {
|
private void runAgent(String userInput) {
|
||||||
agentRunning.set(true);
|
agentRunning.set(true);
|
||||||
streamMdState = new MarkdownRenderer.StreamState();
|
|
||||||
|
|
||||||
Thread.startVirtualThread(() -> {
|
Thread.startVirtualThread(() -> {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
@@ -617,6 +617,11 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
setState(new TuiState(s.inputText, s.messages, s.scrollOffset, thinking, text));
|
setState(new TuiState(s.inputText, s.messages, s.scrollOffset, thinking, text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 设置首次用户输入回调 */
|
||||||
|
public void setOnFirstUserInput(Consumer<String> callback) {
|
||||||
|
this.onFirstUserInput = callback;
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== 历史导航 ====================
|
// ==================== 历史导航 ====================
|
||||||
|
|
||||||
private void browseHistoryUp(TuiState s) {
|
private void browseHistoryUp(TuiState s) {
|
||||||
|
|||||||
@@ -87,6 +87,11 @@ public class JinkReplSession {
|
|||||||
setupAgentCallbacks();
|
setupAgentCallbacks();
|
||||||
setupToolContextCallbacks();
|
setupToolContextCallbacks();
|
||||||
|
|
||||||
|
// 注册首次用户输入回调(用于对话摘要)
|
||||||
|
component.setOnFirstUserInput(text -> {
|
||||||
|
conversationSummary = text.length() > 40 ? text.substring(0, 40) : text;
|
||||||
|
});
|
||||||
|
|
||||||
// 启动 jink 渲染
|
// 启动 jink 渲染
|
||||||
inkApp = Ink.render(component);
|
inkApp = Ink.render(component);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user