From e649731f6b6b636f7c140ad61c15925bde04fa94 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Sat, 28 Feb 2026 20:08:09 +0800 Subject: [PATCH] Normalize command notices --- src/cli/commands.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cli/commands.js b/src/cli/commands.js index e8593e6..b41c9b6 100644 --- a/src/cli/commands.js +++ b/src/cli/commands.js @@ -78,15 +78,15 @@ async function handleCommand(input, ctx) { if (arg) { const conv = loadConversation(workspace, arg); if (!conv) { - console.log('未找到对话'); + printNotice('未找到对话'); return { exit: false }; } state.conversation = conv; state.messages = conv.messages || []; state.thinkingMode = !!conv.metadata?.thinking_mode; state.allowMode = conv.metadata?.allow_mode || state.allowMode; - state.tokenUsage = conv.metadata?.token_usage || 0; - console.log(`已加载对话: ${conv.id}`); + state.tokenUsage = normalizeTokenUsage(conv.metadata?.token_usage); + printNotice(`已加载对话: ${conv.id}`); renderConversation(state.messages); persist(); return { exit: false }; @@ -94,13 +94,13 @@ async function handleCommand(input, ctx) { const items = listConversations(workspace); if (!items.length) { - console.log('暂无对话记录'); + printNotice('暂无对话记录'); return { exit: false }; } const filtered = items.filter((it) => it.id !== state.conversation?.id); if (!filtered.length) { - console.log('暂无可恢复的对话'); + printNotice('暂无可恢复的对话'); return { exit: false }; } const displayItems = filtered.map((item) => { @@ -122,21 +122,21 @@ async function handleCommand(input, ctx) { }); state.conversation = convNew; state.messages = []; - console.log(`已创建新对话: ${convNew.id}`); + printNotice(`已创建新对话: ${convNew.id}`); persist(); return { exit: false }; } const conv = loadConversation(workspace, result.id); if (!conv) { - console.log('未找到对话'); + printNotice('未找到对话'); return { exit: false }; } state.conversation = conv; state.messages = conv.messages || []; state.thinkingMode = !!conv.metadata?.thinking_mode; state.allowMode = conv.metadata?.allow_mode || state.allowMode; - state.tokenUsage = conv.metadata?.token_usage || 0; - console.log(`已加载对话: ${conv.id}`); + state.tokenUsage = normalizeTokenUsage(conv.metadata?.token_usage); + printNotice(`已加载对话: ${conv.id}`); renderConversation(state.messages); persist(); return { exit: false }; @@ -156,7 +156,7 @@ async function handleCommand(input, ctx) { const selected = await runSelect({ rl, message: '', choices, pageSize: 6 }); if (selected) { state.allowMode = selected; - console.log(`运行模式已切换为: ${state.allowMode}`); + printNotice(`运行模式已切换为: ${state.allowMode}`); persist(); } return { exit: false }; @@ -170,9 +170,7 @@ async function handleCommand(input, ctx) { if (!model) return { exit: false }; state.modelKey = model; state.modelId = config.model_id || 'kimi-k2.5'; - console.log(''); - console.log(`模型已切换为: ${state.modelKey}`); - console.log(''); + printNotice(`模型已切换为: ${state.modelKey}`); const thinkingChoices = [ { name: `1. Fast${!state.thinkingMode ? ' (current)' : ''}`, value: 'fast' }, @@ -181,9 +179,7 @@ async function handleCommand(input, ctx) { const mode = await runSelect({ rl, message: '', choices: thinkingChoices, pageSize: 6 }); if (mode) { state.thinkingMode = mode === 'thinking'; - console.log(''); - console.log(`思考模式: ${mode}`); - console.log(''); + printNotice(`思考模式: ${mode}`); persist(); } return { exit: false }; @@ -204,9 +200,11 @@ async function handleCommand(input, ctx) { } if (cmd === '/config') { + console.log(''); console.log(`base_url: ${config.base_url}`); console.log(`modelname: ${config.model_id || 'kimi-k2.5'}`); console.log(`apikey: ${maskKey(config.api_key)}`); + console.log(''); return { exit: false }; } @@ -243,13 +241,13 @@ async function handleCommand(input, ctx) { }); state.conversation = updated; state.messages = cleaned; - spinner.stop('○'); - console.log(`压缩完成:${oldId} -> ${state.conversation.id}`); + spinner.stopSilent(); + printNotice(`压缩完成:${oldId} -> ${state.conversation.id}`); persist(); return { exit: false }; } - console.log(`未知指令: ${cmd},使用 /help 查看指令列表。`); + printNotice(`未知指令: ${cmd},使用 /help 查看指令列表。`); return { exit: false }; }