33 * 提供跨交互式和批处理模式的命令实现
44 */
55
6- import { getConfig , getConfigPaths } from '../config.js' ;
6+ import { getConfig , getConfigPaths , clearHistory } from '../config.js' ;
77import { createShortcutManager } from '../shortcuts.js' ;
88import path from 'path' ;
99import os from 'os' ;
@@ -342,6 +342,48 @@ Tips:
342342 }
343343}
344344
345+ /**
346+ * /clear 命令 - 清除对话历史
347+ * @param {Object } options - 命令选项
348+ * @param {boolean } options.markdown - 是否使用 Markdown 格式(默认 true)
349+ * @returns {CommandResult }
350+ */
351+ export function clearCommand ( options = { } ) {
352+ const { markdown = true } = options ;
353+
354+ try {
355+ // 清除当前项目的历史
356+ clearHistory ( ) ;
357+
358+ const content = markdown ? `
359+ ✅ 对话历史已清除
360+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
361+ 当前项目的对话历史已被成功清除。
362+
363+ 下次对话将从头开始。
364+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
365+ ` : `
366+ Conversation history cleared
367+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
368+ The conversation history for the current project has been successfully cleared.
369+
370+ Next conversation will start from scratch.
371+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
372+ ` ;
373+
374+ return {
375+ success : true ,
376+ content : content . trim ( )
377+ } ;
378+ } catch ( error ) {
379+ return {
380+ success : false ,
381+ error : error . message ,
382+ content : `Failed to clear history: ${ error . message } `
383+ } ;
384+ }
385+ }
386+
345387/**
346388 * /help 命令 - 显示帮助信息
347389 * @param {Object } options - 命令选项
@@ -355,6 +397,7 @@ export function helpCommand(options = {}) {
355397可用命令:
356398━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
357399📝 对话命令
400+ /clear 清除对话历史
358401 /plan <task> 创建并执行任务计划
359402 /learn 学习项目模式
360403 /status 显示对话摘要
@@ -376,6 +419,7 @@ export function helpCommand(options = {}) {
376419Available Commands:
377420━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
378421Conversation Commands:
422+ /clear Clear conversation history
379423 /plan <task> Create and execute task plan
380424 /learn Learn project patterns
381425 /status Show conversation summary
@@ -405,6 +449,11 @@ Tips:
405449 * 命令注册表
406450 */
407451export const COMMAND_REGISTRY = {
452+ '/clear' : {
453+ handler : clearCommand ,
454+ description : '清除对话历史' ,
455+ descriptionEn : 'Clear conversation history'
456+ } ,
408457 '/keys' : {
409458 handler : keysCommand ,
410459 description : '显示键盘快捷键参考' ,
@@ -500,4 +549,4 @@ export function getAvailableCommands(chinese = true) {
500549 command : cmd ,
501550 description : chinese ? info . description : info . descriptionEn
502551 } ) ) ;
503- }
552+ }
0 commit comments