feat(commands): 实现命令 CRUD 完整功能
Core: - 新增 CommandManager 类,支持创建、更新、删除命令 - 验证命令名称防止路径遍历攻击 - 自动生成 Markdown 文件(含 YAML frontmatter) - 内置命令保护(不可修改/删除) Server: - POST /api/commands - 创建命令 - GET /api/commands/:name/content - 获取命令完整内容 - PUT /api/commands/:name - 更新命令 - DELETE /api/commands/:name - 删除命令 UI: - 新增 createCommand、updateCommand、deleteCommand、getCommandContent 函数 - 新增 CreateCommandInput、UpdateCommandInput、CommandContent 类型
This commit is contained in:
@@ -14,6 +14,9 @@ import type {
|
||||
CommandSearchResult,
|
||||
CommandExecuteResult,
|
||||
CommandListResponse,
|
||||
CreateCommandInput,
|
||||
UpdateCommandInput,
|
||||
CommandContent,
|
||||
} from './types.js';
|
||||
|
||||
// Re-export types
|
||||
@@ -31,6 +34,9 @@ export type {
|
||||
CommandSearchResult,
|
||||
CommandExecuteResult,
|
||||
CommandListResponse,
|
||||
CreateCommandInput,
|
||||
UpdateCommandInput,
|
||||
CommandContent,
|
||||
} from './types.js';
|
||||
|
||||
// API Configuration
|
||||
@@ -203,3 +209,29 @@ export async function reloadCommands(): Promise<{
|
||||
}> {
|
||||
return request('POST', '/commands/reload');
|
||||
}
|
||||
|
||||
// Commands CRUD
|
||||
export async function createCommand(
|
||||
input: CreateCommandInput
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('POST', '/commands', input);
|
||||
}
|
||||
|
||||
export async function getCommandContent(
|
||||
name: string
|
||||
): Promise<{ success: boolean; data?: CommandContent; error?: string }> {
|
||||
return request('GET', `/commands/${encodeURIComponent(name)}/content`);
|
||||
}
|
||||
|
||||
export async function updateCommand(
|
||||
name: string,
|
||||
input: UpdateCommandInput
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('PUT', `/commands/${encodeURIComponent(name)}`, input);
|
||||
}
|
||||
|
||||
export async function deleteCommand(
|
||||
name: string
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('DELETE', `/commands/${encodeURIComponent(name)}`);
|
||||
}
|
||||
|
||||
@@ -128,3 +128,46 @@ export interface CommandListResponse {
|
||||
bySource: Record<string, number>;
|
||||
};
|
||||
}
|
||||
|
||||
// ============ Command CRUD 相关 ============
|
||||
|
||||
export interface CreateCommandInput {
|
||||
/** 命令名称(支持嵌套如 deploy/staging) */
|
||||
name: string;
|
||||
/** 命令描述 */
|
||||
description?: string;
|
||||
/** 提示词模板 */
|
||||
template: string;
|
||||
/** 指定 Agent */
|
||||
agent?: string;
|
||||
/** 指定模型 */
|
||||
model?: string;
|
||||
/** 是否作为子任务执行 */
|
||||
subtask?: boolean;
|
||||
/** 存储位置 */
|
||||
scope: 'user' | 'project';
|
||||
}
|
||||
|
||||
export interface UpdateCommandInput {
|
||||
/** 命令描述 */
|
||||
description?: string;
|
||||
/** 提示词模板 */
|
||||
template?: string;
|
||||
/** 指定 Agent */
|
||||
agent?: string;
|
||||
/** 指定模型 */
|
||||
model?: string;
|
||||
/** 是否作为子任务执行 */
|
||||
subtask?: boolean;
|
||||
}
|
||||
|
||||
export interface CommandContent {
|
||||
name: string;
|
||||
description?: string;
|
||||
template: string;
|
||||
agent?: string;
|
||||
model?: string;
|
||||
subtask?: boolean;
|
||||
source: string;
|
||||
sourcePath?: string;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ export {
|
||||
executeCommand,
|
||||
searchCommands,
|
||||
reloadCommands,
|
||||
// Commands CRUD
|
||||
createCommand,
|
||||
getCommandContent,
|
||||
updateCommand,
|
||||
deleteCommand,
|
||||
} from './api/client.js';
|
||||
|
||||
// Types
|
||||
@@ -45,6 +50,10 @@ export type {
|
||||
CommandSearchResult,
|
||||
CommandExecuteResult,
|
||||
CommandListResponse,
|
||||
// Command CRUD types
|
||||
CreateCommandInput,
|
||||
UpdateCommandInput,
|
||||
CommandContent,
|
||||
} from './api/client.js';
|
||||
|
||||
// Primitives (shadcn/ui style)
|
||||
|
||||
Reference in New Issue
Block a user