@ai-setting/roy-agent-core 1.4.12 → 1.4.14

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.
Files changed (127) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
  45. package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
  48. package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
  55. package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
  67. package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
  68. package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
  69. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  70. package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
  71. package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
  72. package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
  90. package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
  91. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  94. package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
  95. package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
  96. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  99. package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
  100. package/package.json +3 -2
  101. package/dist/env/agent/index.js +0 -3035
  102. package/dist/env/commands/index.js +0 -1685
  103. package/dist/env/debug/index.js +0 -2300
  104. package/dist/env/index.js +0 -12591
  105. package/dist/env/llm/index.js +0 -2736
  106. package/dist/env/log-trace/index.js +0 -1779
  107. package/dist/env/mcp/index.js +0 -2173
  108. package/dist/env/mcp/tool/index.js +0 -1149
  109. package/dist/env/memory/index.js +0 -2171
  110. package/dist/env/memory/plugin/index.js +0 -1263
  111. package/dist/env/prompt/index.js +0 -2107
  112. package/dist/env/session/index.js +0 -3594
  113. package/dist/env/session/storage/index.js +0 -2049
  114. package/dist/env/skill/index.js +0 -1635
  115. package/dist/env/skill/tool/index.js +0 -114
  116. package/dist/env/task/delegate/index.js +0 -1844
  117. package/dist/env/task/index.js +0 -3578
  118. package/dist/env/task/plugins/index.js +0 -1626
  119. package/dist/env/task/storage/index.js +0 -1464
  120. package/dist/env/tool/built-in/index.js +0 -1151
  121. package/dist/env/tool/index.js +0 -2284
  122. package/dist/env/workflow/engine/index.js +0 -4391
  123. package/dist/env/workflow/index.js +0 -6214
  124. package/dist/env/workflow/storage/index.js +0 -1236
  125. package/dist/env/workflow/tools/index.js +0 -1081
  126. package/dist/env/workflow/utils/index.js +0 -1631
  127. package/dist/index.js +0 -22778
@@ -0,0 +1,492 @@
1
+ import {
2
+ envKeyToConfigKey,
3
+ toEnvKey
4
+ } from "./roy-agent-core-jv3b7v9w.js";
5
+ import {
6
+ BaseComponent
7
+ } from "./roy-agent-core-m2x48hw6.js";
8
+ import {
9
+ createLogger,
10
+ init_logger
11
+ } from "./roy-agent-core-yn761yve.js";
12
+
13
+ // packages/core/src/env/commands/commands-component.ts
14
+ import path2 from "path";
15
+ import os from "os";
16
+ init_logger();
17
+ import * as fs2 from "fs/promises";
18
+ import { exec } from "child_process";
19
+ import { promisify } from "util";
20
+
21
+ // packages/core/src/env/commands/parser.ts
22
+ init_logger();
23
+ import fs from "fs/promises";
24
+ import path from "path";
25
+ var logger = createLogger("commands-parser");
26
+ function parseFrontmatter(text) {
27
+ const result = {};
28
+ const lines = text.split(`
29
+ `);
30
+ for (const line of lines) {
31
+ const match = line.match(/^(\w+):\s*"?(.+?)"?\s*$/);
32
+ if (match) {
33
+ const key = match[1];
34
+ let value = match[2];
35
+ if (value.startsWith('"') && value.endsWith('"')) {
36
+ value = value.slice(1, -1);
37
+ }
38
+ result[key] = value;
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ async function parseMetaFile(filePath, source) {
44
+ try {
45
+ const content = await fs.readFile(filePath, "utf-8");
46
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n?/);
47
+ if (!frontmatterMatch) {
48
+ logger.warn(`[Parser] Missing frontmatter in: ${filePath}`);
49
+ return null;
50
+ }
51
+ const frontmatter = parseFrontmatter(frontmatterMatch[1]);
52
+ const name = frontmatter.name;
53
+ const description = frontmatter.description;
54
+ if (!name) {
55
+ logger.warn(`[Parser] Missing name in frontmatter: ${filePath}`);
56
+ return null;
57
+ }
58
+ if (!description) {
59
+ logger.warn(`[Parser] Missing description in frontmatter: ${filePath}`);
60
+ return null;
61
+ }
62
+ return {
63
+ name,
64
+ description,
65
+ tips: frontmatter.tips,
66
+ filePath,
67
+ source
68
+ };
69
+ } catch (error) {
70
+ logger.error(`[Parser] Failed to parse file: ${filePath}`, error);
71
+ return null;
72
+ }
73
+ }
74
+
75
+ // packages/core/src/env/commands/commands-config-registration.ts
76
+ var COMMANDS_CONFIG_REGISTRATION = {
77
+ name: "command",
78
+ sources: [
79
+ { type: "env", envPrefix: "COMMAND", priority: 20, watch: false }
80
+ ],
81
+ keys: [
82
+ { key: "command.userCommandsDir", sources: ["env", "file"] },
83
+ { key: "command.projectCommandsDir", sources: ["env", "file"] },
84
+ { key: "command.cacheDir", sources: ["env", "file"] }
85
+ ]
86
+ };
87
+
88
+ // packages/core/src/env/commands/commands-component.ts
89
+ var execAsync = promisify(exec);
90
+ var logger2 = createLogger("commands");
91
+ var DEFAULT_USER_DIR = ".roy-agent/commands";
92
+ var DEFAULT_PROJECT_DIR = ".roy/commands";
93
+ var DEFAULT_CACHE_DIR = ".cache/roy-agent/commands";
94
+ var DESCRIPTIONS_FILE = "descriptions.json";
95
+ var CONFIG_KEYS = [
96
+ "command.userCommandsDir",
97
+ "command.projectCommandsDir",
98
+ "command.cacheDir"
99
+ ];
100
+
101
+ class CommandsComponent extends BaseComponent {
102
+ name = "commands";
103
+ version = "2.0.0";
104
+ config;
105
+ configComponent;
106
+ userCommandsDir = "";
107
+ projectCommandsDir = "";
108
+ descriptionCache = new Map;
109
+ descriptionCacheFile = "";
110
+ constructor() {
111
+ super();
112
+ this.initDefaultDirs();
113
+ }
114
+ initDefaultDirs() {
115
+ const homeDir = os.homedir();
116
+ this.userCommandsDir = path2.join(homeDir, DEFAULT_USER_DIR);
117
+ this.projectCommandsDir = DEFAULT_PROJECT_DIR;
118
+ this.descriptionCacheFile = path2.join(homeDir, DEFAULT_CACHE_DIR, DESCRIPTIONS_FILE);
119
+ }
120
+ async init(config) {
121
+ await super.init(config);
122
+ const options = config?.options;
123
+ if (!options?.configComponent) {
124
+ throw new Error("ConfigComponent is required for CommandsComponent initialization");
125
+ }
126
+ this.configComponent = options.configComponent;
127
+ await this.registerConfig(options);
128
+ await fs2.mkdir(this.userCommandsDir, { recursive: true });
129
+ await this.loadDescriptionCache();
130
+ logger2.info(`CommandsComponent initialized: user=${this.userCommandsDir}, project=${this.projectCommandsDir}`);
131
+ }
132
+ async registerConfig(options) {
133
+ const configComponent = this.configComponent;
134
+ if (!configComponent)
135
+ return;
136
+ const { configPath, envPrefix, config } = options;
137
+ configComponent.registerComponent(COMMANDS_CONFIG_REGISTRATION);
138
+ if (configPath) {
139
+ configComponent.registerSource({
140
+ type: "file",
141
+ relativePath: configPath,
142
+ optional: true,
143
+ watch: false
144
+ });
145
+ }
146
+ await configComponent.load("command");
147
+ const prefix = envPrefix !== undefined ? envPrefix : "COMMAND";
148
+ for (const key of CONFIG_KEYS) {
149
+ const envKey = toEnvKey(key, prefix);
150
+ const value = process.env[envKey];
151
+ if (value !== undefined) {
152
+ await configComponent.set(key, value);
153
+ }
154
+ }
155
+ const loadedKeys = new Set(CONFIG_KEYS);
156
+ for (const envKey of Object.keys(process.env)) {
157
+ const configKey = envKeyToConfigKey(envKey, prefix, "command");
158
+ if (!configKey)
159
+ continue;
160
+ if (loadedKeys.has(configKey))
161
+ continue;
162
+ loadedKeys.add(configKey);
163
+ const value = process.env[envKey];
164
+ if (value !== undefined) {
165
+ await configComponent.set(configKey, value);
166
+ }
167
+ }
168
+ if (config) {
169
+ const flatConfig = this.flattenConfig(config);
170
+ for (const [key, value] of Object.entries(flatConfig)) {
171
+ if (value !== undefined) {
172
+ await configComponent.set(key, value);
173
+ }
174
+ }
175
+ }
176
+ const homeDir = os.homedir();
177
+ const defaultDirs = {
178
+ "command.userCommandsDir": path2.join(homeDir, DEFAULT_USER_DIR),
179
+ "command.projectCommandsDir": DEFAULT_PROJECT_DIR,
180
+ "command.cacheDir": path2.join(homeDir, DEFAULT_CACHE_DIR)
181
+ };
182
+ for (const [key, value] of Object.entries(defaultDirs)) {
183
+ if (configComponent.get(key) === undefined) {
184
+ await configComponent.set(key, value);
185
+ }
186
+ }
187
+ this.applyConfig(configComponent);
188
+ }
189
+ flattenConfig(config) {
190
+ const result = {};
191
+ if (config.userCommandsDir !== undefined) {
192
+ result["command.userCommandsDir"] = config.userCommandsDir;
193
+ }
194
+ if (config.projectCommandsDir !== undefined) {
195
+ result["command.projectCommandsDir"] = config.projectCommandsDir;
196
+ }
197
+ if (config.cacheDir !== undefined) {
198
+ result["command.cacheDir"] = config.cacheDir;
199
+ }
200
+ return result;
201
+ }
202
+ applyConfig(configComponent) {
203
+ const userDir = configComponent.get("command.userCommandsDir");
204
+ const projectDir = configComponent.get("command.projectCommandsDir");
205
+ const cacheDir = configComponent.get("command.cacheDir");
206
+ this.userCommandsDir = userDir || path2.join(os.homedir(), DEFAULT_USER_DIR);
207
+ this.projectCommandsDir = projectDir || DEFAULT_PROJECT_DIR;
208
+ this.descriptionCacheFile = path2.join(cacheDir || path2.join(os.homedir(), DEFAULT_CACHE_DIR), DESCRIPTIONS_FILE);
209
+ this.config = {
210
+ userCommandsDir: this.userCommandsDir,
211
+ projectCommandsDir: this.projectCommandsDir,
212
+ cacheDir
213
+ };
214
+ }
215
+ async start() {
216
+ await super.start();
217
+ logger2.debug("CommandsComponent started");
218
+ }
219
+ async stop() {
220
+ await this.saveDescriptionCache();
221
+ await super.stop();
222
+ logger2.debug("CommandsComponent stopped");
223
+ }
224
+ async getCommandDirs() {
225
+ return {
226
+ user: this.userCommandsDir,
227
+ project: this.projectCommandsDir
228
+ };
229
+ }
230
+ async discover(options) {
231
+ const commands = [];
232
+ let userCount = 0;
233
+ let projectCount = 0;
234
+ try {
235
+ const projectCommands = await this.scanDir(this.projectCommandsDir, "project", options?.pattern);
236
+ commands.push(...projectCommands);
237
+ projectCount = projectCommands.length;
238
+ } catch (error) {
239
+ logger2.debug(`Failed to scan project dir: ${error}`);
240
+ }
241
+ try {
242
+ const userCommands = await this.scanDir(this.userCommandsDir, "user", options?.pattern);
243
+ for (const cmd of userCommands) {
244
+ const exists = commands.find((c) => c.name === cmd.name);
245
+ if (!exists) {
246
+ commands.push(cmd);
247
+ userCount++;
248
+ }
249
+ }
250
+ } catch (error) {
251
+ logger2.debug(`Failed to scan user dir: ${error}`);
252
+ }
253
+ commands.sort((a, b) => a.name.localeCompare(b.name));
254
+ return {
255
+ commands,
256
+ stats: { userCount, projectCount }
257
+ };
258
+ }
259
+ async add(options) {
260
+ const { name, target, source = "user", description, tips } = options;
261
+ const dir = source === "user" ? this.userCommandsDir : this.projectCommandsDir;
262
+ const targetPath = path2.resolve(target);
263
+ await fs2.mkdir(dir, { recursive: true });
264
+ const commandPath = path2.join(dir, name);
265
+ try {
266
+ await fs2.access(commandPath);
267
+ throw new Error(`Command '${name}' already exists`);
268
+ } catch (error) {
269
+ if (error.code !== "ENOENT") {
270
+ throw error;
271
+ }
272
+ }
273
+ await fs2.symlink(targetPath, commandPath);
274
+ logger2.info(`Added command '${name}' -> ${targetPath} (${source})`);
275
+ const commandDir = path2.join(dir, name);
276
+ await this.createCommandMeta(commandDir, {
277
+ name,
278
+ target: targetPath,
279
+ description: description || `Command: ${name}`,
280
+ tips,
281
+ source
282
+ });
283
+ }
284
+ async createCommandMeta(commandDir, options) {
285
+ const parentDir = path2.dirname(commandDir);
286
+ const metaPath = path2.join(parentDir, `${options.name}.meta.md`);
287
+ const tipsContent = options.tips ? `
288
+ tips: "${options.tips}"` : "";
289
+ const content = `---
290
+ name: ${options.name}
291
+ description: ${options.description}${tipsContent}
292
+ source: ${options.source}
293
+ ---
294
+
295
+ # ${options.name} Command
296
+
297
+ ## Target
298
+ \`${options.target}\`
299
+
300
+ ## 功能
301
+ ${options.description}
302
+
303
+ ## 探索提示
304
+ Run \`${options.name} --help\` to explore full capabilities.
305
+ `;
306
+ await fs2.writeFile(metaPath, content, "utf-8");
307
+ logger2.info(`[CommandsComponent] Created meta.md for '${options.name}'`);
308
+ }
309
+ async getCommandsMeta() {
310
+ const metaList = [];
311
+ try {
312
+ const entries = await fs2.readdir(this.userCommandsDir, { withFileTypes: true });
313
+ for (const entry of entries) {
314
+ if (entry.isFile() && entry.name.endsWith(".meta.md")) {
315
+ const metaPath = path2.join(this.userCommandsDir, entry.name);
316
+ const meta = await parseMetaFile(metaPath, "user");
317
+ if (meta) {
318
+ metaList.push(meta);
319
+ }
320
+ }
321
+ }
322
+ } catch (error) {
323
+ if (error.code !== "ENOENT") {
324
+ logger2.debug(`Failed to scan user commands dir: ${error}`);
325
+ }
326
+ }
327
+ try {
328
+ const entries = await fs2.readdir(this.projectCommandsDir, { withFileTypes: true });
329
+ for (const entry of entries) {
330
+ if (entry.isFile() && entry.name.endsWith(".meta.md")) {
331
+ const metaPath = path2.join(this.projectCommandsDir, entry.name);
332
+ const meta = await parseMetaFile(metaPath, "project");
333
+ if (meta) {
334
+ metaList.push(meta);
335
+ }
336
+ }
337
+ }
338
+ } catch (error) {
339
+ if (error.code !== "ENOENT") {
340
+ logger2.debug(`Failed to scan project commands dir: ${error}`);
341
+ }
342
+ }
343
+ return metaList;
344
+ }
345
+ async remove(options) {
346
+ const { name, source } = options;
347
+ const dirsToCheck = source ? [source === "user" ? this.userCommandsDir : this.projectCommandsDir] : [this.userCommandsDir, this.projectCommandsDir];
348
+ for (const dir of dirsToCheck) {
349
+ const commandPath = path2.join(dir, name);
350
+ try {
351
+ await fs2.unlink(commandPath);
352
+ logger2.info(`Removed command '${name}' from ${dir}`);
353
+ return;
354
+ } catch (error) {
355
+ if (error.code !== "ENOENT") {
356
+ throw error;
357
+ }
358
+ }
359
+ }
360
+ throw new Error(`Command '${name}' not found`);
361
+ }
362
+ async getInfo(name) {
363
+ const dirsToCheck = [this.projectCommandsDir, this.userCommandsDir];
364
+ for (const dir of dirsToCheck) {
365
+ const commandPath = path2.join(dir, name);
366
+ try {
367
+ const stat = await fs2.lstat(commandPath);
368
+ const realPath = stat.isSymbolicLink() ? await fs2.readlink(commandPath) : commandPath;
369
+ const cmdSource = dir === this.projectCommandsDir ? "project" : "user";
370
+ const shortDescription = await this.getDescription(realPath);
371
+ return {
372
+ name,
373
+ path: realPath,
374
+ source: cmdSource,
375
+ shortDescription
376
+ };
377
+ } catch (error) {
378
+ if (error.code !== "ENOENT") {
379
+ throw error;
380
+ }
381
+ }
382
+ }
383
+ return null;
384
+ }
385
+ async exec(options) {
386
+ const { name, args = [], cwd } = options;
387
+ const info = await this.getInfo(name);
388
+ if (!info) {
389
+ return {
390
+ stdout: "",
391
+ stderr: `Command '${name}' not found`,
392
+ exitCode: 127,
393
+ success: false
394
+ };
395
+ }
396
+ const cmd = `${info.path} ${args.join(" ")}`;
397
+ try {
398
+ const { stdout, stderr } = await execAsync(cmd, {
399
+ cwd: cwd || process.cwd(),
400
+ timeout: 30000
401
+ });
402
+ return {
403
+ stdout,
404
+ stderr,
405
+ exitCode: 0,
406
+ success: true
407
+ };
408
+ } catch (error) {
409
+ return {
410
+ stdout: error.stdout || "",
411
+ stderr: error.stderr || error.message,
412
+ exitCode: error.code || 1,
413
+ success: false
414
+ };
415
+ }
416
+ }
417
+ async scanDir(dir, source, pattern) {
418
+ const commands = [];
419
+ try {
420
+ const entries = await fs2.readdir(dir);
421
+ for (const entry of entries) {
422
+ if (entry.startsWith("."))
423
+ continue;
424
+ if (pattern && !this.matchPattern(entry, pattern))
425
+ continue;
426
+ const fullPath = path2.join(dir, entry);
427
+ try {
428
+ const stat = await fs2.lstat(fullPath);
429
+ if (!stat.isSymbolicLink() && !stat.isFile())
430
+ continue;
431
+ if (stat.isFile()) {
432
+ try {
433
+ await fs2.access(fullPath, fs2.constants.X_OK);
434
+ } catch {
435
+ continue;
436
+ }
437
+ }
438
+ const realPath = stat.isSymbolicLink() ? await fs2.readlink(fullPath) : fullPath;
439
+ const shortDescription = await this.getDescription(realPath);
440
+ commands.push({
441
+ name: entry,
442
+ path: realPath,
443
+ source,
444
+ shortDescription
445
+ });
446
+ } catch (error) {
447
+ logger2.debug(`Failed to stat ${fullPath}: ${error}`);
448
+ }
449
+ }
450
+ } catch (error) {
451
+ logger2.debug(`Failed to scan dir ${dir}: ${error}`);
452
+ }
453
+ return commands;
454
+ }
455
+ matchPattern(name, pattern) {
456
+ const regex = new RegExp("^" + pattern.replace(/\*/g, ".*").replace(/\?/g, ".") + "$");
457
+ return regex.test(name);
458
+ }
459
+ async getDescription(commandPath) {
460
+ const cached = this.descriptionCache.get(commandPath);
461
+ if (cached !== undefined)
462
+ return cached;
463
+ try {
464
+ const { stdout } = await execAsync(`${commandPath} --help 2>/dev/null | head -1`, {
465
+ timeout: 2000
466
+ });
467
+ const description = stdout.trim().split(`
468
+ `)[0] || "";
469
+ this.descriptionCache.set(commandPath, description);
470
+ return description;
471
+ } catch {
472
+ return "";
473
+ }
474
+ }
475
+ async loadDescriptionCache() {
476
+ try {
477
+ const content = await fs2.readFile(this.descriptionCacheFile, "utf-8");
478
+ const data = JSON.parse(content);
479
+ this.descriptionCache = new Map(Object.entries(data));
480
+ } catch {}
481
+ }
482
+ async saveDescriptionCache() {
483
+ try {
484
+ await fs2.mkdir(path2.dirname(this.descriptionCacheFile), { recursive: true });
485
+ const data = Object.fromEntries(this.descriptionCache);
486
+ await fs2.writeFile(this.descriptionCacheFile, JSON.stringify(data, null, 2));
487
+ } catch (error) {
488
+ logger2.debug(`Failed to save description cache: ${error}`);
489
+ }
490
+ }
491
+ }
492
+ export { CommandsComponent };
@@ -1,54 +1,3 @@
1
- // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- function __accessProp(key) {
7
- return this[key];
8
- }
9
- var __toCommonJS = (from) => {
10
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
- if (entry)
12
- return entry;
13
- entry = __defProp({}, "__esModule", { value: true });
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (var key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(entry, key))
17
- __defProp(entry, key, {
18
- get: __accessProp.bind(from, key),
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- __moduleCache.set(from, entry);
23
- return entry;
24
- };
25
- var __moduleCache;
26
- var __returnValue = (v) => v;
27
- function __exportSetter(name, newValue) {
28
- this[name] = __returnValue.bind(null, newValue);
29
- }
30
- var __export = (target, all) => {
31
- for (var name in all)
32
- __defProp(target, name, {
33
- get: all[name],
34
- enumerable: true,
35
- configurable: true,
36
- set: __exportSetter.bind(all, name)
37
- });
38
- };
39
- var __legacyDecorateClassTS = function(decorators, target, key, desc) {
40
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
42
- r = Reflect.decorate(decorators, target, key, desc);
43
- else
44
- for (var i = decorators.length - 1;i >= 0; i--)
45
- if (d = decorators[i])
46
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- };
49
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
50
- var __require = import.meta.require;
51
-
52
1
  // packages/core/src/env/workflow/service/workflow-service.ts
53
2
  class WorkflowService {
54
3
  workflowRepository;
@@ -254,9 +203,4 @@ function getWorkflowService() {
254
203
  function registerWorkflowService(service) {
255
204
  WorkflowServiceRegistry.getInstance().register(service);
256
205
  }
257
- export {
258
- registerWorkflowService,
259
- getWorkflowService,
260
- WorkflowServiceRegistry,
261
- WorkflowService
262
- };
206
+ export { WorkflowService, WorkflowServiceRegistry, getWorkflowService, registerWorkflowService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -72,7 +72,8 @@
72
72
  "url": "https://github.com/ai-setting/roy-agent/issues"
73
73
  },
74
74
  "scripts": {
75
- "build": "bun run bunup",
75
+ "build": "bunup -- --entry src/index.ts --entry 'src/**/index.ts' --source-base src",
76
+ "build:main": "bunup -- --entry src/index.ts --source-base src",
76
77
  "clean": "rm -rf dist",
77
78
  "typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
78
79
  }