Skip to content

Commit 5e99fd2

Browse files
uppethuangyaoyue(Joyer)
authored andcommitted
feat: 在批处理模式下添加 /clear 命令支持
- 在 slash-commands.js 中实现 clearCommand - 在 COMMAND_REGISTRY 中注册 /clear 命令 - 修复 executeSlashCommand 调用中缺少的 await - 更新 /help 命令以包含 /clear /clear 命令现在可以在交互式 CLI 和批处理模式下工作, 允许用户清除当前项目的对话历史。 Co-Authored-By: GLM-4.7 & cloco(Closer)
1 parent 9006358 commit 5e99fd2

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/batch-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ async function runBatch() {
256256
formatter.progress('检测到斜杠命令...');
257257

258258
const { executeSlashCommand } = await import('./commands/slash-commands.js');
259-
const result = executeSlashCommand(prompt, { markdown: false });
259+
const result = await executeSlashCommand(prompt, { markdown: false });
260260

261261
if (result) {
262262
// 是斜杠命令,输出结果并退出

src/commands/slash-commands.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* 提供跨交互式和批处理模式的命令实现
44
*/
55

6-
import { getConfig, getConfigPaths } from '../config.js';
6+
import { getConfig, getConfigPaths, clearHistory } from '../config.js';
77
import { createShortcutManager } from '../shortcuts.js';
88
import path from 'path';
99
import 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 = {}) {
376419
Available Commands:
377420
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
378421
Conversation 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
*/
407451
export 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

Comments
 (0)