@ai-setting/roy-agent-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -0
- package/dist/bin/roy.js +127297 -0
- package/dist/roy-agent-darwin-arm64/bin/roy.js +127297 -0
- package/dist/roy-agent-darwin-x64/bin/roy.js +127297 -0
- package/dist/roy-agent-linux-arm64/bin/roy.js +127297 -0
- package/dist/roy-agent-linux-x64/bin/roy.js +127297 -0
- package/dist/roy-agent-windows-x64/bin/roy.js +127297 -0
- package/package.json +91 -0
- package/src/bin/roy.ts +12 -0
- package/src/cli.ts +101 -0
- package/src/commands/act.ts +480 -0
- package/src/commands/commands-add.ts +110 -0
- package/src/commands/commands-dirs.ts +70 -0
- package/src/commands/commands-info.ts +90 -0
- package/src/commands/commands-list.ts +161 -0
- package/src/commands/commands-remove.ts +147 -0
- package/src/commands/commands.ts +55 -0
- package/src/commands/config/config-service.test.ts +449 -0
- package/src/commands/config/config-service.ts +312 -0
- package/src/commands/config/deep-merge.test.ts +168 -0
- package/src/commands/config/deep-merge.ts +63 -0
- package/src/commands/config/export.ts +97 -0
- package/src/commands/config/filter-history-e2e.test.ts +141 -0
- package/src/commands/config/import-preserve-refs.test.ts +212 -0
- package/src/commands/config/import.ts +119 -0
- package/src/commands/config/index.ts +35 -0
- package/src/commands/config/list.ts +281 -0
- package/src/commands/config/roy-config-e2e.test.ts +297 -0
- package/src/commands/config/types.ts +54 -0
- package/src/commands/debug/index.ts +38 -0
- package/src/commands/debug/log.test.ts +233 -0
- package/src/commands/debug/log.ts +123 -0
- package/src/commands/debug/span.test.ts +297 -0
- package/src/commands/debug/span.ts +211 -0
- package/src/commands/debug/trace.test.ts +254 -0
- package/src/commands/debug/trace.ts +140 -0
- package/src/commands/eventsource/add.ts +133 -0
- package/src/commands/eventsource/index.ts +48 -0
- package/src/commands/eventsource/list.ts +194 -0
- package/src/commands/eventsource/remove.ts +95 -0
- package/src/commands/eventsource/start.ts +103 -0
- package/src/commands/eventsource/status.ts +185 -0
- package/src/commands/eventsource/stop.ts +89 -0
- package/src/commands/index.ts +22 -0
- package/src/commands/input-handler.test.ts +76 -0
- package/src/commands/input-handler.ts +43 -0
- package/src/commands/interactive-esc.test.ts +254 -0
- package/src/commands/interactive.shutdown.test.ts +122 -0
- package/src/commands/interactive.test.ts +221 -0
- package/src/commands/interactive.ts +1015 -0
- package/src/commands/lsp/check.ts +92 -0
- package/src/commands/lsp/index.ts +32 -0
- package/src/commands/lsp/install.ts +126 -0
- package/src/commands/lsp/list.ts +64 -0
- package/src/commands/mcp/index.ts +27 -0
- package/src/commands/mcp/list.ts +116 -0
- package/src/commands/mcp/reload.ts +70 -0
- package/src/commands/mcp/tools.ts +121 -0
- package/src/commands/memory/extract-e2e.test.ts +388 -0
- package/src/commands/memory/index.ts +11 -0
- package/src/commands/memory/memory-simplified.test.ts +58 -0
- package/src/commands/memory/memory.ts +25 -0
- package/src/commands/memory/organize.ts +300 -0
- package/src/commands/memory/recall.test.ts +120 -0
- package/src/commands/memory/recall.ts +88 -0
- package/src/commands/memory/record-extract-handle-query.test.ts +385 -0
- package/src/commands/memory/record-prompt-component.test.ts +343 -0
- package/src/commands/memory/record.test.ts +92 -0
- package/src/commands/memory/record.ts +332 -0
- package/src/commands/plugin.test.ts +292 -0
- package/src/commands/plugin.ts +267 -0
- package/src/commands/sessions/active.ts +96 -0
- package/src/commands/sessions/add-message.ts +96 -0
- package/src/commands/sessions/checkpoints.ts +154 -0
- package/src/commands/sessions/compact.test.ts +215 -0
- package/src/commands/sessions/compact.ts +269 -0
- package/src/commands/sessions/delete.ts +236 -0
- package/src/commands/sessions/get.ts +165 -0
- package/src/commands/sessions/grep.ts +233 -0
- package/src/commands/sessions/index.ts +95 -0
- package/src/commands/sessions/list.ts +210 -0
- package/src/commands/sessions/messages.test.ts +333 -0
- package/src/commands/sessions/messages.ts +248 -0
- package/src/commands/sessions/mock.ts +194 -0
- package/src/commands/sessions/new.ts +82 -0
- package/src/commands/sessions/rename.ts +98 -0
- package/src/commands/shared/event-handler.ts +213 -0
- package/src/commands/shared/event-message-formatter.ts +295 -0
- package/src/commands/shared/index.ts +11 -0
- package/src/commands/shared/query-executor.test.ts +434 -0
- package/src/commands/shared/query-executor.ts +324 -0
- package/src/commands/shared/repl-engine.test.ts +354 -0
- package/src/commands/shared/session-manager.test.ts +212 -0
- package/src/commands/shared/session-manager.ts +114 -0
- package/src/commands/skills/get.ts +90 -0
- package/src/commands/skills/index.ts +39 -0
- package/src/commands/skills/list.ts +129 -0
- package/src/commands/skills/reload.ts +59 -0
- package/src/commands/skills/search.ts +132 -0
- package/src/commands/skills/show-config.ts +93 -0
- package/src/commands/tasks/complete.ts +92 -0
- package/src/commands/tasks/create.ts +118 -0
- package/src/commands/tasks/delete.ts +86 -0
- package/src/commands/tasks/get.ts +116 -0
- package/src/commands/tasks/index.ts +53 -0
- package/src/commands/tasks/list.ts +140 -0
- package/src/commands/tasks/operations.ts +120 -0
- package/src/commands/tasks/update.ts +122 -0
- package/src/commands/tools/exec-tool.ts +128 -0
- package/src/commands/tools/get.ts +114 -0
- package/src/commands/tools/index.ts +35 -0
- package/src/commands/tools/list.ts +107 -0
- package/src/commands/tools/shared/index.ts +7 -0
- package/src/commands/tools/shared/schema-helper.ts +111 -0
- package/src/commands/workflow/commands/add.ts +315 -0
- package/src/commands/workflow/commands/get.ts +193 -0
- package/src/commands/workflow/commands/list.ts +137 -0
- package/src/commands/workflow/commands/nodes.ts +528 -0
- package/src/commands/workflow/commands/remove.ts +94 -0
- package/src/commands/workflow/commands/run.ts +398 -0
- package/src/commands/workflow/commands/status.ts +147 -0
- package/src/commands/workflow/commands/stop.ts +91 -0
- package/src/commands/workflow/commands/update.ts +130 -0
- package/src/commands/workflow/commands/validate.ts +139 -0
- package/src/commands/workflow/commands/workflow-cli.test.ts +196 -0
- package/src/commands/workflow/index.ts +65 -0
- package/src/commands/workflow/renderers.ts +358 -0
- package/src/commands/workflow/validators/index.ts +8 -0
- package/src/commands/workflow/validators/node-validator-factory.ts +40 -0
- package/src/commands/workflow/validators/node-validator.ts +125 -0
- package/src/commands/workflow/validators/nodes/agent-node-validator.ts +58 -0
- package/src/commands/workflow/validators/nodes/condition-node-validator.ts +34 -0
- package/src/commands/workflow/validators/nodes/decorator-node-validator.ts +45 -0
- package/src/commands/workflow/validators/nodes/merge-node-validator.ts +46 -0
- package/src/commands/workflow/validators/nodes/skill-node-validator.ts +33 -0
- package/src/commands/workflow/validators/nodes/tool-node-validator.ts +54 -0
- package/src/commands/workflow/validators/nodes/workflow-node-validator.ts +33 -0
- package/src/commands/workflow/validators/types.ts +78 -0
- package/src/commands/workflow/validators/workflow-validator.test.ts +273 -0
- package/src/commands/workflow/validators/workflow-validator.ts +320 -0
- package/src/index.ts +19 -0
- package/src/plugin/apply.ts +103 -0
- package/src/plugin/discover.ts +219 -0
- package/src/plugin/index.ts +45 -0
- package/src/plugin/registry.ts +272 -0
- package/src/plugin/types.ts +165 -0
- package/src/services/context-handler.service.test.ts +501 -0
- package/src/services/context-handler.service.ts +372 -0
- package/src/services/environment.service.commands-prompt.test.ts +167 -0
- package/src/services/environment.service.ts +656 -0
- package/src/services/output.service.test.ts +92 -0
- package/src/services/output.service.ts +122 -0
- package/src/services/quiet-mode.service.test.ts +114 -0
- package/src/services/quiet-mode.service.ts +81 -0
- package/src/services/stream-output.service.test.ts +214 -0
- package/src/services/stream-output.service.ts +323 -0
- package/src/util/which.test.ts +101 -0
- package/src/util/which.ts +55 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Plugin Registry
|
|
3
|
+
*
|
|
4
|
+
* 插件注册表,管理所有已注册的插件
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
RoyCliPlugin,
|
|
9
|
+
PluginCommandDefinition,
|
|
10
|
+
PluginComponentDefinition,
|
|
11
|
+
ComponentPluginDefinition,
|
|
12
|
+
ComponentPluginInstance,
|
|
13
|
+
} from "./types";
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Built-in Plugins
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Task-Tag Plugin - 内置组件插件
|
|
21
|
+
*/
|
|
22
|
+
const taskTagPlugin: RoyCliPlugin = {
|
|
23
|
+
info: {
|
|
24
|
+
name: "task-tag",
|
|
25
|
+
version: "1.0.0",
|
|
26
|
+
description: "Intelligent tag suggestion and similar task experience injection",
|
|
27
|
+
},
|
|
28
|
+
getComponentPlugins() {
|
|
29
|
+
return [{
|
|
30
|
+
name: "task-tag",
|
|
31
|
+
targetComponent: "task",
|
|
32
|
+
factory: async () => {
|
|
33
|
+
// 动态导入避免循环依赖
|
|
34
|
+
const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
|
|
35
|
+
return new TaskTagPlugin();
|
|
36
|
+
},
|
|
37
|
+
}];
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 内置插件列表
|
|
43
|
+
*/
|
|
44
|
+
const BUILTIN_PLUGINS: RoyCliPlugin[] = [
|
|
45
|
+
taskTagPlugin,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Plugin Registry
|
|
50
|
+
// ============================================================================
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 插件注册表
|
|
54
|
+
*
|
|
55
|
+
* 管理插件的注册、获取和遍历
|
|
56
|
+
*/
|
|
57
|
+
export class PluginRegistry {
|
|
58
|
+
private plugins = new Map<string, RoyCliPlugin>();
|
|
59
|
+
|
|
60
|
+
constructor() {
|
|
61
|
+
// 自动注册内置插件
|
|
62
|
+
for (const plugin of BUILTIN_PLUGINS) {
|
|
63
|
+
this.registerBuiltin(plugin);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 注册插件
|
|
69
|
+
*
|
|
70
|
+
* @param plugin - 要注册的插件
|
|
71
|
+
* @throws 如果插件名称已存在则抛出错误
|
|
72
|
+
*/
|
|
73
|
+
register(plugin: RoyCliPlugin): void {
|
|
74
|
+
if (this.plugins.has(plugin.info.name)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Plugin "${plugin.info.name}" is already registered`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
this.plugins.set(plugin.info.name, plugin);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 注册内置插件(不抛错)
|
|
84
|
+
*/
|
|
85
|
+
private registerBuiltin(plugin: RoyCliPlugin): void {
|
|
86
|
+
if (!this.plugins.has(plugin.info.name)) {
|
|
87
|
+
this.plugins.set(plugin.info.name, plugin);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 注销插件
|
|
93
|
+
*
|
|
94
|
+
* @param name - 插件名称
|
|
95
|
+
*/
|
|
96
|
+
unregister(name: string): void {
|
|
97
|
+
this.plugins.delete(name);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 获取插件
|
|
102
|
+
*
|
|
103
|
+
* @param name - 插件名称
|
|
104
|
+
* @returns 插件实例,如果不存在则返回 undefined
|
|
105
|
+
*/
|
|
106
|
+
get(name: string): RoyCliPlugin | undefined {
|
|
107
|
+
return this.plugins.get(name);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 检查插件是否已注册
|
|
112
|
+
*
|
|
113
|
+
* @param name - 插件名称
|
|
114
|
+
*/
|
|
115
|
+
has(name: string): boolean {
|
|
116
|
+
return this.plugins.has(name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 获取所有已注册插件
|
|
121
|
+
*
|
|
122
|
+
* @returns 按优先级降序排列的插件数组
|
|
123
|
+
*/
|
|
124
|
+
getAll(): RoyCliPlugin[] {
|
|
125
|
+
return Array.from(this.plugins.values()).sort(
|
|
126
|
+
(a, b) => (b.priority ?? 0) - (a.priority ?? 0)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 获取所有插件数量
|
|
132
|
+
*/
|
|
133
|
+
get size(): number {
|
|
134
|
+
return this.plugins.size;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 获取所有插件提供的命令
|
|
139
|
+
*
|
|
140
|
+
* @returns 所有插件命令定义数组
|
|
141
|
+
*/
|
|
142
|
+
getAllCommands(): PluginCommandDefinition[] {
|
|
143
|
+
const commands: PluginCommandDefinition[] = [];
|
|
144
|
+
for (const plugin of this.getAll()) {
|
|
145
|
+
commands.push(...(plugin.getCommands?.() ?? []));
|
|
146
|
+
}
|
|
147
|
+
return commands;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 获取所有插件提供的组件
|
|
152
|
+
*
|
|
153
|
+
* @returns 所有插件组件定义数组
|
|
154
|
+
*/
|
|
155
|
+
getAllComponents(): PluginComponentDefinition[] {
|
|
156
|
+
const components: PluginComponentDefinition[] = [];
|
|
157
|
+
for (const plugin of this.getAll()) {
|
|
158
|
+
components.push(...(plugin.getComponents?.() ?? []));
|
|
159
|
+
}
|
|
160
|
+
return components;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 获取所有插件提供的组件插件
|
|
165
|
+
*
|
|
166
|
+
* @returns 所有组件插件定义数组
|
|
167
|
+
*/
|
|
168
|
+
getAllComponentPlugins(): ComponentPluginDefinition[] {
|
|
169
|
+
const componentPlugins: ComponentPluginDefinition[] = [];
|
|
170
|
+
for (const plugin of this.getAll()) {
|
|
171
|
+
componentPlugins.push(...(plugin.getComponentPlugins?.() ?? []));
|
|
172
|
+
}
|
|
173
|
+
return componentPlugins;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 根据名称获取组件插件定义
|
|
178
|
+
*
|
|
179
|
+
* @param name - 组件插件名称
|
|
180
|
+
* @returns 组件插件定义,如果不存在则返回 undefined
|
|
181
|
+
*/
|
|
182
|
+
getComponentPlugin(name: string): ComponentPluginDefinition | undefined {
|
|
183
|
+
for (const plugin of this.getAll()) {
|
|
184
|
+
const componentPlugins = plugin.getComponentPlugins?.() ?? [];
|
|
185
|
+
for (const cp of componentPlugins) {
|
|
186
|
+
if (cp.name === name) {
|
|
187
|
+
return cp;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 遍历所有插件及其组件定义
|
|
196
|
+
*
|
|
197
|
+
* @yields 插件和其组件定义
|
|
198
|
+
*/
|
|
199
|
+
*getPluginComponents(): Generator<{
|
|
200
|
+
plugin: RoyCliPlugin;
|
|
201
|
+
definition: PluginComponentDefinition;
|
|
202
|
+
}> {
|
|
203
|
+
for (const plugin of this.getAll()) {
|
|
204
|
+
for (const definition of plugin.getComponents?.() ?? []) {
|
|
205
|
+
yield { plugin, definition };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 清空所有已注册的插件(保留内置插件)
|
|
212
|
+
*/
|
|
213
|
+
clear(): void {
|
|
214
|
+
// 先移除所有非内置插件
|
|
215
|
+
for (const name of this.plugins.keys()) {
|
|
216
|
+
const plugin = this.plugins.get(name)!;
|
|
217
|
+
if (!BUILTIN_PLUGINS.some(p => p.info.name === name)) {
|
|
218
|
+
this.plugins.delete(name);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 执行所有插件的生命周期钩子
|
|
225
|
+
*
|
|
226
|
+
* @param phase - 生命周期阶段
|
|
227
|
+
* @param env - Environment 实例
|
|
228
|
+
*/
|
|
229
|
+
async executeLifecycleHooks(
|
|
230
|
+
phase: "beforeInit" | "afterInit",
|
|
231
|
+
env: import("@ai-setting/roy-agent-core").BaseEnvironment
|
|
232
|
+
): Promise<void> {
|
|
233
|
+
const hookName =
|
|
234
|
+
phase === "beforeInit" ? "onBeforeInit" : "onAfterInit";
|
|
235
|
+
|
|
236
|
+
for (const plugin of this.getAll()) {
|
|
237
|
+
const hook = plugin[hookName];
|
|
238
|
+
if (hook) {
|
|
239
|
+
try {
|
|
240
|
+
await hook({ env });
|
|
241
|
+
} catch (err) {
|
|
242
|
+
console.warn(
|
|
243
|
+
`[roy] Plugin "${plugin.info.name}" ${hookName} failed:`,
|
|
244
|
+
err
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 全局插件注册表实例
|
|
254
|
+
*/
|
|
255
|
+
export const globalPluginRegistry = new PluginRegistry();
|
|
256
|
+
|
|
257
|
+
// ============================================================================
|
|
258
|
+
// Helper Functions
|
|
259
|
+
// ============================================================================
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 加载内置组件插件
|
|
263
|
+
*/
|
|
264
|
+
export async function loadBuiltinComponentPlugin(
|
|
265
|
+
name: string
|
|
266
|
+
): Promise<ComponentPluginInstance | null> {
|
|
267
|
+
const definition = globalPluginRegistry.getComponentPlugin(name);
|
|
268
|
+
if (!definition) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
return definition.factory();
|
|
272
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Roy CLI Plugin Types
|
|
3
|
+
*
|
|
4
|
+
* 定义插件协议,供插件开发者使用
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { CommandModule } from "yargs";
|
|
8
|
+
import type { Component } from "@ai-setting/roy-agent-core";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 插件元信息
|
|
12
|
+
*/
|
|
13
|
+
export interface PluginInfo {
|
|
14
|
+
/** 插件名称 */
|
|
15
|
+
name: string;
|
|
16
|
+
|
|
17
|
+
/** 插件版本 */
|
|
18
|
+
version: string;
|
|
19
|
+
|
|
20
|
+
/** 插件描述 */
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 插件组件定义
|
|
26
|
+
*/
|
|
27
|
+
export interface PluginComponentDefinition {
|
|
28
|
+
/** 组件名称 */
|
|
29
|
+
name: string;
|
|
30
|
+
|
|
31
|
+
/** 组件类构造函数 */
|
|
32
|
+
component: new (...args: any[]) => Component;
|
|
33
|
+
|
|
34
|
+
/** 组件配置选项 */
|
|
35
|
+
options?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* CLI 命令定义
|
|
40
|
+
*/
|
|
41
|
+
export interface PluginCommandDefinition {
|
|
42
|
+
/** yargs CommandModule */
|
|
43
|
+
command: CommandModule;
|
|
44
|
+
|
|
45
|
+
/** 是否为默认命令 */
|
|
46
|
+
default?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 环境钩子上下文
|
|
51
|
+
*/
|
|
52
|
+
export interface PluginEnvironmentContext {
|
|
53
|
+
/** Environment 实例 */
|
|
54
|
+
env: import("@ai-setting/roy-agent-core").BaseEnvironment;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 组件插件实例
|
|
59
|
+
*/
|
|
60
|
+
export interface ComponentPluginInstance {
|
|
61
|
+
/** 插件名称 */
|
|
62
|
+
name: string;
|
|
63
|
+
|
|
64
|
+
/** Hook 定义 */
|
|
65
|
+
hooks: Array<{ point: string; priority?: number }>;
|
|
66
|
+
|
|
67
|
+
/** 执行 Hook */
|
|
68
|
+
execute(ctx: unknown): void | Promise<void>;
|
|
69
|
+
|
|
70
|
+
/** 设置依赖组件 */
|
|
71
|
+
setComponents?(...components: unknown[]): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 组件插件定义
|
|
76
|
+
*/
|
|
77
|
+
export interface ComponentPluginDefinition {
|
|
78
|
+
/** 插件名称 */
|
|
79
|
+
name: string;
|
|
80
|
+
|
|
81
|
+
/** 目标组件名称 (如 "task", "memory") */
|
|
82
|
+
targetComponent: string;
|
|
83
|
+
|
|
84
|
+
/** 插件实例工厂函数 */
|
|
85
|
+
factory: () => Promise<ComponentPluginInstance>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Roy CLI 插件接口
|
|
90
|
+
*
|
|
91
|
+
* 用于扩展 roy-cli 的功能:
|
|
92
|
+
* - 注册 CLI 命令
|
|
93
|
+
* - 注册 Environment 组件
|
|
94
|
+
* - 注册组件插件(注入到现有组件)
|
|
95
|
+
* - 钩入 Environment 生命周期
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* export const myPlugin: RoyCliPlugin = {
|
|
100
|
+
* info: {
|
|
101
|
+
* name: "my-plugin",
|
|
102
|
+
* version: "1.0.0",
|
|
103
|
+
* description: "My custom plugin"
|
|
104
|
+
* },
|
|
105
|
+
*
|
|
106
|
+
* getCommands() {
|
|
107
|
+
* return [{ command: MyCommand }];
|
|
108
|
+
* },
|
|
109
|
+
*
|
|
110
|
+
* getComponents() {
|
|
111
|
+
* return [{ name: "my-component", component: MyComponent }];
|
|
112
|
+
* },
|
|
113
|
+
*
|
|
114
|
+
* getComponentPlugins() {
|
|
115
|
+
* return [{
|
|
116
|
+
* name: "my-component-plugin",
|
|
117
|
+
* targetComponent: "task",
|
|
118
|
+
* factory: async () => new MyComponentPlugin(),
|
|
119
|
+
* }];
|
|
120
|
+
* }
|
|
121
|
+
* };
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export interface RoyCliPlugin {
|
|
125
|
+
/** 插件元信息 */
|
|
126
|
+
readonly info: PluginInfo;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 获取插件提供的 CLI 命令
|
|
130
|
+
*/
|
|
131
|
+
getCommands?(): PluginCommandDefinition[];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取插件提供的组件
|
|
135
|
+
*/
|
|
136
|
+
getComponents?(): PluginComponentDefinition[];
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 获取插件提供的组件插件
|
|
140
|
+
*
|
|
141
|
+
* 组件插件是注入到现有组件(如 TaskComponent)中的插件,
|
|
142
|
+
* 通过 Hook 机制扩展组件功能
|
|
143
|
+
*/
|
|
144
|
+
getComponentPlugins?(): ComponentPluginDefinition[];
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Environment 初始化前调用
|
|
148
|
+
*
|
|
149
|
+
* @param ctx - 环境上下文
|
|
150
|
+
*/
|
|
151
|
+
onBeforeInit?(ctx: PluginEnvironmentContext): void | Promise<void>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Environment 初始化后调用
|
|
155
|
+
*
|
|
156
|
+
* @param ctx - 环境上下文
|
|
157
|
+
*/
|
|
158
|
+
onAfterInit?(ctx: PluginEnvironmentContext): void | Promise<void>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 优先级,数字越大越先加载
|
|
162
|
+
* 默认值为 0
|
|
163
|
+
*/
|
|
164
|
+
priority?: number;
|
|
165
|
+
}
|