Skip to content

扩展自定义命令

Command 注册到 OpenDesk TUI 命令系统。

字段类型必填说明
namestringCommand 名;注册后由插件 id 限定命名空间
descriptionstring命令说明
executefunction接收原始参数字符串和 PluginCommandContext

PluginCommandContext:

字段类型说明
taskIdstring,可选当前活动任务
workspacestring,可选TUI 当前工作空间
abortAbortSignal当前任务停止信号

execute 可以返回 undefinedstring,或包含可选 title 与必填 output 的对象。

import { definePlugin } from '@bitclub.ai/opendesk-plugin-sdk';
export default definePlugin({
id: 'workspace-commands',
capabilities: ['command'],
setup(ctx) {
return ctx.commands.register({
name: 'where',
description: 'Show the current workspace',
execute(args, context) {
return {
title: 'Workspace',
output: context.workspace || 'No active workspace'
};
}
});
}
});
export default {
id: 'workspace-commands',
capabilities: ['command'],
setup(ctx) {
return ctx.commands.register({
name: 'where',
description: 'Show the current workspace',
execute(args, context) {
return {
title: 'Workspace',
output: context.workspace || 'No active workspace'
};
}
});
}
};

命令注册后由插件 id 限定命名空间,避免与其他插件或内置命令冲突。通过 setup 返回的清理函数或 registration 的 dispose 可以提前移除命令;插件停用、重载或宿主退出时,宿主会统一释放所有注册项。