@autotest/agent 0.0.5 → 0.0.7

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 (192) hide show
  1. package/README.md +10 -0
  2. package/dist/api/agent_api.d.ts +2 -2
  3. package/dist/autotest-cli.js +1 -397
  4. package/dist/common/config/config.yaml +5 -0
  5. package/dist/common/config/manager.d.ts +7 -7
  6. package/dist/common/config/types.d.ts +33 -1
  7. package/dist/common/dfx/index.d.ts +1 -1
  8. package/dist/common/image_helper.d.ts +2 -2
  9. package/dist/common/llm_cache/cache_transport.d.ts +1 -1
  10. package/dist/common/llm_cache/prompt_cache.d.ts +2 -2
  11. package/dist/common/utils.d.ts +5 -5
  12. package/dist/core/agent/layered_agent/agent_registry.d.ts +3 -1
  13. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +1 -1
  14. package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +1 -1
  15. package/dist/core/agent/report_analyzer_agent/prompt.d.ts +1 -1
  16. package/dist/core/agent/report_analyzer_agent/tools.d.ts +1 -1
  17. package/dist/core/agent/rewrite_agent/agent.d.ts +5 -5
  18. package/dist/core/agent/rewrite_agent/guardrails.d.ts +1 -1
  19. package/dist/core/agent/rewrite_agent/mapping.d.ts +1 -1
  20. package/dist/core/agent/rewrite_agent/parse.d.ts +1 -1
  21. package/dist/core/agent/rewrite_agent/types.d.ts +1 -1
  22. package/dist/core/agent/single_agent/agent.d.ts +2 -2
  23. package/dist/core/agent/single_agent/hook_manager.d.ts +1 -2
  24. package/dist/core/agent/single_agent/image_utils.d.ts +1 -2
  25. package/dist/core/agent/single_agent/scroll_search_agent.d.ts +5 -5
  26. package/dist/core/agent/single_agent/subagent_manager.d.ts +1 -2
  27. package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +3 -3
  28. package/dist/core/device/device_protocol.d.ts +1 -1
  29. package/dist/core/device/hdc/device.d.ts +1 -1
  30. package/dist/core/device/index.d.ts +2 -2
  31. package/dist/core/knowledge/knowledge_manager.d.ts +1 -1
  32. package/dist/core/knowledge/vectordb.d.ts +1 -1
  33. package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
  34. package/dist/core/mcp/mcp_tools.d.ts +11 -2
  35. package/dist/core/mcp/verify_tool.d.ts +12 -0
  36. package/dist/core/memory/_utils.d.ts +1 -1
  37. package/dist/core/memory/index.d.ts +1 -1
  38. package/dist/core/memory/memory_manager.d.ts +1 -1
  39. package/dist/core/memory/replan_manager.d.ts +1 -1
  40. package/dist/core/memory/tool_player.d.ts +5 -5
  41. package/dist/core/memory/tool_player_popup.d.ts +1 -1
  42. package/dist/core/memory/tool_player_replan.d.ts +1 -1
  43. package/dist/core/memory/tool_player_xpath.d.ts +3 -3
  44. package/dist/core/prompt/prompt_loader.d.ts +1 -1
  45. package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
  46. package/dist/core/skill/skill_manager.d.ts +2 -2
  47. package/dist/data_types/device.d.ts +1 -1
  48. package/dist/data_types/index.d.ts +1 -1
  49. package/dist/index.d.ts +5 -5
  50. package/dist/index.js +1 -164
  51. package/dist/loop/cli.d.ts +4 -4
  52. package/dist/loop/orchestrator.d.ts +6 -6
  53. package/dist/loop/result_writer.d.ts +1 -1
  54. package/dist/loop/types.d.ts +1 -1
  55. package/dist/tools/batch_runner.js +1 -745
  56. package/dist/tools/case_runner/report.d.ts +1 -1
  57. package/dist/tools/case_runner/runner.d.ts +3 -3
  58. package/dist/tools/case_runner/runner.js +1 -410
  59. package/dist/tools/config/config_tool.d.ts +6 -6
  60. package/dist/tools/config/config_tool.js +1 -339
  61. package/dist/tools/prompt_compare/compare_runner.d.ts +2 -2
  62. package/dist/tools/prompt_compare/compare_runner.js +1 -360
  63. package/package.json +2 -2
  64. package/dist/api/agent_api.js +0 -550
  65. package/dist/api/autotest_agent.js +0 -205
  66. package/dist/api/types.js +0 -11
  67. package/dist/common/case_manager.js +0 -91
  68. package/dist/common/collect_case.js +0 -128
  69. package/dist/common/common_errors.js +0 -66
  70. package/dist/common/config/config_validator.js +0 -28
  71. package/dist/common/config/manager.js +0 -257
  72. package/dist/common/config/output.js +0 -59
  73. package/dist/common/config/types.js +0 -184
  74. package/dist/common/dfx/client_factory.js +0 -62
  75. package/dist/common/dfx/context.js +0 -23
  76. package/dist/common/dfx/index.js +0 -15
  77. package/dist/common/dfx/recorder.js +0 -191
  78. package/dist/common/dfx/recording_fetch.js +0 -228
  79. package/dist/common/dfx/source.js +0 -13
  80. package/dist/common/image_cacher.js +0 -36
  81. package/dist/common/image_helper.js +0 -128
  82. package/dist/common/image_similarity.js +0 -171
  83. package/dist/common/llm_cache/cache_transport.js +0 -102
  84. package/dist/common/llm_cache/prompt_cache.js +0 -113
  85. package/dist/common/logger.js +0 -158
  86. package/dist/common/model/custom_model.js +0 -525
  87. package/dist/common/model/index.js +0 -5
  88. package/dist/common/path_utils.js +0 -88
  89. package/dist/common/result_parser.js +0 -49
  90. package/dist/common/usage/token_usage.js +0 -117
  91. package/dist/common/utils.js +0 -125
  92. package/dist/core/agent/layered_agent/ability_helper.js +0 -125
  93. package/dist/core/agent/layered_agent/agent.js +0 -37
  94. package/dist/core/agent/layered_agent/agent_registry.js +0 -75
  95. package/dist/core/agent/layered_agent/decision.js +0 -516
  96. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
  97. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
  98. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
  99. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
  100. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
  101. package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
  102. package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
  103. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
  104. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
  105. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
  106. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
  107. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
  108. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
  109. package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
  110. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
  111. package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
  112. package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
  113. package/dist/core/agent/report_analyzer_agent/config.js +0 -22
  114. package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
  115. package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
  116. package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
  117. package/dist/core/agent/report_analyzer_agent/index.js +0 -52
  118. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
  119. package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
  120. package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
  121. package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
  122. package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
  123. package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
  124. package/dist/core/agent/report_analyzer_agent/types.js +0 -274
  125. package/dist/core/agent/rewrite_agent/agent.js +0 -209
  126. package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
  127. package/dist/core/agent/rewrite_agent/mapping.js +0 -56
  128. package/dist/core/agent/rewrite_agent/parse.js +0 -121
  129. package/dist/core/agent/rewrite_agent/types.js +0 -37
  130. package/dist/core/agent/single_agent/agent.js +0 -798
  131. package/dist/core/agent/single_agent/hook_manager.js +0 -60
  132. package/dist/core/agent/single_agent/hooks.js +0 -288
  133. package/dist/core/agent/single_agent/image_utils.js +0 -159
  134. package/dist/core/agent/single_agent/scroll_search_agent.js +0 -376
  135. package/dist/core/agent/single_agent/subagent_manager.js +0 -73
  136. package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
  137. package/dist/core/agent/types.js +0 -2
  138. package/dist/core/agent/utils/message_builder.js +0 -138
  139. package/dist/core/device/device_protocol.js +0 -2
  140. package/dist/core/device/hdc/apps.js +0 -437
  141. package/dist/core/device/hdc/device.js +0 -219
  142. package/dist/core/device/hdc/index.js +0 -31
  143. package/dist/core/device/hdc/input.js +0 -74
  144. package/dist/core/device/hdc/screenshot.js +0 -171
  145. package/dist/core/device/index.js +0 -70
  146. package/dist/core/device/types.js +0 -2
  147. package/dist/core/knowledge/knowledge_manager.js +0 -70
  148. package/dist/core/knowledge/vectordb.js +0 -283
  149. package/dist/core/mcp/adapter_factory.js +0 -99
  150. package/dist/core/mcp/android_adapter.js +0 -286
  151. package/dist/core/mcp/base_adapter.js +0 -86
  152. package/dist/core/mcp/harmony_hdc_adapter.js +0 -782
  153. package/dist/core/mcp/ios_adapter.js +0 -286
  154. package/dist/core/mcp/local_tools.js +0 -41
  155. package/dist/core/mcp/mcp_tools.js +0 -410
  156. package/dist/core/mcp/types.js +0 -6
  157. package/dist/core/memory/_utils.js +0 -140
  158. package/dist/core/memory/compressed_session.js +0 -182
  159. package/dist/core/memory/context_compressor.js +0 -176
  160. package/dist/core/memory/index.js +0 -22
  161. package/dist/core/memory/memory_manager.js +0 -28
  162. package/dist/core/memory/reflector.js +0 -95
  163. package/dist/core/memory/replan_manager.js +0 -12
  164. package/dist/core/memory/session_factory.js +0 -29
  165. package/dist/core/memory/tool_player.js +0 -225
  166. package/dist/core/memory/tool_player_popup.js +0 -276
  167. package/dist/core/memory/tool_player_replan.js +0 -226
  168. package/dist/core/memory/tool_player_xpath.js +0 -139
  169. package/dist/core/memory/tool_recorder.js +0 -126
  170. package/dist/core/preprocessor/task_splitter.js +0 -112
  171. package/dist/core/prompt/prompt_loader.js +0 -315
  172. package/dist/core/skill/skill_manager.js +0 -302
  173. package/dist/data_types/action.js +0 -2
  174. package/dist/data_types/agent.js +0 -2
  175. package/dist/data_types/case.js +0 -57
  176. package/dist/data_types/device.js +0 -2
  177. package/dist/data_types/index.js +0 -11
  178. package/dist/data_types/report.js +0 -6
  179. package/dist/data_types/screen.js +0 -23
  180. package/dist/data_types/task.js +0 -2
  181. package/dist/loop/cli.js +0 -127
  182. package/dist/loop/orchestrator.js +0 -314
  183. package/dist/loop/result_writer.js +0 -260
  184. package/dist/loop/types.js +0 -82
  185. package/dist/mcp-server/server.js +0 -341
  186. package/dist/mcp-server/types.js +0 -224
  187. package/dist/reporter/batch_summary.js +0 -197
  188. package/dist/reporter/generator.js +0 -286
  189. package/dist/reporter/html_template/index.js +0 -524
  190. package/dist/reporter/json_report.js +0 -6
  191. package/dist/reporter/types.js +0 -45
  192. package/dist/tools/case_runner/report.js +0 -264
@@ -1,315 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.DEFAULT_VERSIONS = exports.PromptCategory = void 0;
37
- exports.clearCache = clearCache;
38
- exports.getAvailableVersions = getAvailableVersions;
39
- exports.load = load;
40
- exports.getPromptVersions = getPromptVersions;
41
- exports.listAllPrompts = listAllPrompts;
42
- exports.registerScanPaths = registerScanPaths;
43
- exports.getScanDirs = getScanDirs;
44
- exports.loadByName = loadByName;
45
- const fs = __importStar(require("fs"));
46
- const path = __importStar(require("path"));
47
- const path_utils_1 = require("../../common/path_utils");
48
- const logger_1 = require("../../common/logger");
49
- var PromptCategory;
50
- (function (PromptCategory) {
51
- PromptCategory["SINGLE"] = "single";
52
- PromptCategory["HYPIUM"] = "hypium";
53
- PromptCategory["PLANNER"] = "planner";
54
- PromptCategory["SPLITTER"] = "splitter";
55
- PromptCategory["FAST_ACTION"] = "fast_action";
56
- PromptCategory["EXECUTOR"] = "executor";
57
- })(PromptCategory || (exports.PromptCategory = PromptCategory = {}));
58
- exports.DEFAULT_VERSIONS = {
59
- [PromptCategory.SINGLE]: 'v2.0',
60
- [PromptCategory.HYPIUM]: 'v2.0',
61
- [PromptCategory.PLANNER]: 'v2.0',
62
- [PromptCategory.SPLITTER]: 'v1.0',
63
- [PromptCategory.FAST_ACTION]: 'v1.0',
64
- [PromptCategory.EXECUTOR]: 'v1.0',
65
- };
66
- const TEMPLATES_DIR = fs.existsSync(path.join(__dirname, 'templates'))
67
- ? path.join(__dirname, 'templates')
68
- : path.join((0, path_utils_1.findDistRoot)(), 'core', 'prompt', 'templates');
69
- const _cache = new Map();
70
- function clearCache() {
71
- _cache.clear();
72
- }
73
- function _getPrefix(category) {
74
- switch (category) {
75
- case PromptCategory.SINGLE:
76
- return 'single';
77
- case PromptCategory.HYPIUM:
78
- return 'hypium';
79
- case PromptCategory.PLANNER:
80
- return 'planner';
81
- case PromptCategory.SPLITTER:
82
- return 'task_splitter';
83
- case PromptCategory.FAST_ACTION:
84
- return 'fast_action';
85
- default:
86
- return category;
87
- }
88
- }
89
- function _parseVersionFromFilename(filename, prefix) {
90
- const pattern = new RegExp(`^${prefix}_([v]?[\\d.]+(?:-[a-zA-Z]+)?)\\.md$`);
91
- const match = filename.match(pattern);
92
- if (match) {
93
- let version = match[1];
94
- if (!version.startsWith('v')) {
95
- version = 'v' + version;
96
- }
97
- return version;
98
- }
99
- return null;
100
- }
101
- function _getCategoryDir(category) {
102
- return path.join(TEMPLATES_DIR, category);
103
- }
104
- function getAvailableVersions(category) {
105
- const catDir = _getCategoryDir(category);
106
- if (!fs.existsSync(catDir)) {
107
- return [];
108
- }
109
- const prefix = _getPrefix(category);
110
- const versions = [];
111
- const files = fs.readdirSync(catDir);
112
- for (const file of files) {
113
- if (file.startsWith(prefix) && file.endsWith('.md')) {
114
- const version = _parseVersionFromFilename(file, prefix);
115
- if (version) {
116
- versions.push(version);
117
- }
118
- }
119
- }
120
- return versions.sort((a, b) => b.localeCompare(a));
121
- }
122
- function _getPromptPath(category, version) {
123
- if (!version.startsWith('v')) {
124
- version = 'v' + version;
125
- }
126
- const catDir = _getCategoryDir(category);
127
- if (!fs.existsSync(catDir)) {
128
- return null;
129
- }
130
- const prefix = _getPrefix(category);
131
- const files = fs.readdirSync(catDir);
132
- for (const file of files) {
133
- if (file.startsWith(prefix) && file.endsWith('.md')) {
134
- const fileVersion = _parseVersionFromFilename(file, prefix);
135
- if (fileVersion === version) {
136
- return path.join(catDir, file);
137
- }
138
- }
139
- }
140
- return null;
141
- }
142
- function _cleanMarkdownLine(line, keepHeaders) {
143
- if (line.startsWith('```')) {
144
- return '';
145
- }
146
- if (keepHeaders) {
147
- return line;
148
- }
149
- if (line.startsWith('### ')) {
150
- return line.slice(4);
151
- }
152
- if (line.startsWith('## ')) {
153
- return line.slice(3);
154
- }
155
- if (line.startsWith('# ')) {
156
- return line.slice(2);
157
- }
158
- return line;
159
- }
160
- function _extractPromptContent(mdContent, keepHeaders) {
161
- const lines = mdContent.split('\n');
162
- const resultLines = [];
163
- let skipMeta = true;
164
- for (const line of lines) {
165
- if (skipMeta) {
166
- if (line.startsWith('##') || line.trim() === '---') {
167
- skipMeta = false;
168
- }
169
- if (line.startsWith('>') || line.startsWith('# ') || !line.trim()) {
170
- continue;
171
- }
172
- }
173
- if (!skipMeta) {
174
- const cleanedLine = _cleanMarkdownLine(line, keepHeaders);
175
- resultLines.push(cleanedLine);
176
- }
177
- }
178
- return resultLines.join('\n').trim();
179
- }
180
- function load(category, version, keepHeaders = true) {
181
- let targetVersion = version ?? exports.DEFAULT_VERSIONS[category] ?? 'v1.0';
182
- if (!targetVersion.startsWith('v')) {
183
- targetVersion = 'v' + targetVersion;
184
- }
185
- const cacheKey = `${category}:${targetVersion}_headers_${keepHeaders}`;
186
- if (_cache.has(cacheKey)) {
187
- return _cache.get(cacheKey);
188
- }
189
- const promptPath = _getPromptPath(category, targetVersion);
190
- if (!promptPath) {
191
- const available = getAvailableVersions(category);
192
- throw new Error(`Prompt version '${targetVersion}' not found for ${category}. Available versions: ${available.join(', ')}`);
193
- }
194
- const content = fs.readFileSync(promptPath, 'utf-8');
195
- const promptText = _extractPromptContent(content, keepHeaders);
196
- _cache.set(cacheKey, promptText);
197
- return promptText;
198
- }
199
- function _getVersionInfo(category, version) {
200
- if (!version.startsWith('v')) {
201
- version = 'v' + version;
202
- }
203
- const promptPath = _getPromptPath(category, version);
204
- if (!promptPath) {
205
- return { version, date: '', description: 'Not found' };
206
- }
207
- const content = fs.readFileSync(promptPath, 'utf-8');
208
- const info = {
209
- version,
210
- date: '',
211
- description: '',
212
- };
213
- for (const line of content.split('\n')) {
214
- if (line.startsWith('> 版本:')) {
215
- info.version = line.split(':').slice(1).join(':').trim();
216
- }
217
- else if (line.startsWith('> 更新日期:')) {
218
- info.date = line.split(':').slice(1).join(':').trim();
219
- }
220
- else if (line.startsWith('> 描述:')) {
221
- info.description = line.split(':').slice(1).join(':').trim();
222
- }
223
- }
224
- return info;
225
- }
226
- function getPromptVersions(category) {
227
- return getAvailableVersions(category);
228
- }
229
- function listAllPrompts(category) {
230
- const versions = getAvailableVersions(category);
231
- return versions.map((v) => _getVersionInfo(category, v));
232
- }
233
- const _extraScanPaths = [];
234
- /** Register extra directories to scan for prompts (aligned with python register_scan_paths). */
235
- function registerScanPaths(paths) {
236
- for (const p of paths) {
237
- if (!p)
238
- continue;
239
- const abs = path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);
240
- if (!_extraScanPaths.includes(abs))
241
- _extraScanPaths.push(abs);
242
- }
243
- }
244
- /** Return the registered extra scan directories. */
245
- function getScanDirs() {
246
- return [..._extraScanPaths];
247
- }
248
- /**
249
- * Find a prompt by filename, searching extra scan paths (recursive, highest
250
- * priority) before the built-in templates dir. Aligned with python
251
- * _find_prompt_by_name. Returns raw file content or null.
252
- */
253
- function _findPromptByName(name) {
254
- const target = name.replace(/\.md$/i, '');
255
- const tryFile = (filePath) => {
256
- try {
257
- const baseName = path.basename(filePath, '.md');
258
- if (baseName === target || path.basename(filePath) === name) {
259
- return fs.readFileSync(filePath, 'utf-8');
260
- }
261
- }
262
- catch {
263
- // ignore unreadable
264
- }
265
- return null;
266
- };
267
- const scanDir = (dir) => {
268
- try {
269
- const entries = fs.readdirSync(dir, { recursive: true });
270
- for (const entry of entries) {
271
- if (!entry.endsWith('.md'))
272
- continue;
273
- const full = path.isAbsolute(entry) ? entry : path.join(dir, entry);
274
- const hit = tryFile(full);
275
- if (hit)
276
- return hit;
277
- }
278
- }
279
- catch {
280
- // ignore unreadable dir
281
- }
282
- return null;
283
- };
284
- // Aligned with python: built-in templates first, then extra scan paths
285
- // 1. built-in templates (recursive)
286
- const hit1 = scanDir(TEMPLATES_DIR);
287
- if (hit1)
288
- return hit1;
289
- // 2. extra scan paths
290
- for (const dir of _extraScanPaths) {
291
- const hit = scanDir(dir);
292
- if (hit)
293
- return hit;
294
- }
295
- return null;
296
- }
297
- function loadByName(name, keepHeaders = true) {
298
- // 1. category/version match (e.g. single_v2.0)
299
- const categories = Object.values(PromptCategory);
300
- for (const category of categories) {
301
- const prefix = _getPrefix(category);
302
- const versions = getAvailableVersions(category);
303
- for (const v of versions) {
304
- if (`${prefix}_${v}` === name || `${prefix}_${v}.md` === name) {
305
- return load(category, v);
306
- }
307
- }
308
- }
309
- // 2. priority filename search (extra scan paths > built-in templates)
310
- const content = _findPromptByName(name);
311
- if (content)
312
- return _extractPromptContent(content, keepHeaders);
313
- logger_1.logger.warn(`Prompt not found by name: ${name}`);
314
- return null;
315
- }
@@ -1,302 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SkillManager = void 0;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
39
- const logger_1 = require("../../common/logger");
40
- const path_utils_1 = require("../../common/path_utils");
41
- function tokenize(text) {
42
- return text
43
- .toLowerCase()
44
- .replace(/[^\p{L}\p{N}\s]/gu, ' ')
45
- .split(/\s+/)
46
- .filter((t) => t.length > 0);
47
- }
48
- /**
49
- * Manages Agent Skills following the Agent Skills specification (aligned with
50
- * python core/skill/skill_manager.py).
51
- *
52
- * Each skill is a directory containing a SKILL.md with YAML frontmatter
53
- * (name/description/license/compatibility) + markdown body, plus optional
54
- * scripts/references/assets subdirectories. Singleton; first instantiation
55
- * auto-loads from the bundled skills dir; extra dirs loadable via loadSkills.
56
- */
57
- class SkillManager {
58
- static instance = null;
59
- skillsDir;
60
- extraSkillsDirs = [];
61
- skills = new Map();
62
- constructor(skillsDir, extraSkillsDirs) {
63
- this.skillsDir =
64
- skillsDir ??
65
- (fs.existsSync(path.join(__dirname, 'skills'))
66
- ? path.join(__dirname, 'skills')
67
- : path.join((0, path_utils_1.findDistRoot)(), 'core', 'skill', 'skills'));
68
- this.loadSkills(this.skillsDir);
69
- if (extraSkillsDirs) {
70
- for (const dir of extraSkillsDirs) {
71
- this.loadSkills(dir);
72
- this.extraSkillsDirs.push(dir);
73
- }
74
- }
75
- SkillManager.instance = this;
76
- }
77
- static getInstance(skillsDir) {
78
- if (SkillManager.instance === null) {
79
- SkillManager.instance = new SkillManager(skillsDir);
80
- }
81
- return SkillManager.instance;
82
- }
83
- // ---- Loading ----
84
- /** Load all skills from a directory. Each direct subdir with SKILL.md is a skill. Re-loadable. */
85
- loadSkills(skillsDir) {
86
- if (!fs.existsSync(skillsDir)) {
87
- logger_1.logger.warn(`SkillManager: skills directory not found: ${skillsDir}`);
88
- return;
89
- }
90
- const entries = fs.readdirSync(skillsDir, { withFileTypes: true });
91
- for (const entry of entries) {
92
- // Skip hidden entries and non-directories.
93
- if (entry.name.startsWith('.') || !entry.isDirectory())
94
- continue;
95
- const skillFile = path.join(skillsDir, entry.name, 'SKILL.md');
96
- if (!fs.existsSync(skillFile))
97
- continue;
98
- try {
99
- const data = this._parseSkillFile(skillFile);
100
- if (data) {
101
- const skillName = data.metadata['name'];
102
- this.skills.set(skillName, data);
103
- logger_1.logger.debug(`SkillManager: loaded skill: ${skillName}`);
104
- }
105
- }
106
- catch (e) {
107
- logger_1.logger.error(`SkillManager: failed to load skill from ${entry.name}: ${e instanceof Error ? e.message : String(e)}`);
108
- }
109
- }
110
- logger_1.logger.info(`SkillManager: loaded ${this.skills.size} skills from ${skillsDir}`);
111
- }
112
- _parseSkillFile(filePath) {
113
- const content = fs.readFileSync(filePath, 'utf-8');
114
- const { metadata, body } = this._parseFrontmatter(content);
115
- if (!metadata || !metadata['name']) {
116
- logger_1.logger.error(`SkillManager: invalid skill file (missing name in frontmatter): ${filePath}`);
117
- return null;
118
- }
119
- if (!this._validateSkillName(metadata['name'])) {
120
- logger_1.logger.error(`SkillManager: invalid skill name format: ${metadata['name']}`);
121
- return null;
122
- }
123
- const skillDir = path.dirname(filePath);
124
- const has = (sub) => fs.existsSync(path.join(skillDir, sub));
125
- return {
126
- metadata,
127
- content: body,
128
- filePath: skillDir,
129
- scriptsDir: has('scripts') ? path.join(skillDir, 'scripts') : undefined,
130
- referencesDir: has('references') ? path.join(skillDir, 'references') : undefined,
131
- assetsDir: has('assets') ? path.join(skillDir, 'assets') : undefined,
132
- };
133
- }
134
- // ---- YAML frontmatter parsing ----
135
- _parseFrontmatter(content) {
136
- const trimmed = content.trim();
137
- if (!trimmed.startsWith('---')) {
138
- logger_1.logger.warn('SkillManager: missing YAML frontmatter delimiter');
139
- return { metadata: null, body: trimmed };
140
- }
141
- const lines = trimmed.split('\n');
142
- let endIndex = -1;
143
- for (let i = 1; i < lines.length; i++) {
144
- if (lines[i].trim() === '---') {
145
- endIndex = i;
146
- break;
147
- }
148
- }
149
- if (endIndex === -1) {
150
- logger_1.logger.warn('SkillManager: missing closing YAML frontmatter delimiter');
151
- return { metadata: null, body: trimmed };
152
- }
153
- const yamlContent = lines.slice(1, endIndex).join('\n');
154
- const metadata = this._parseSimpleYaml(yamlContent);
155
- const body = lines.slice(endIndex + 1).join('\n').trim();
156
- return { metadata, body };
157
- }
158
- _parseSimpleYaml(yamlContent) {
159
- const metadata = {};
160
- let currentKey = null;
161
- for (const line of yamlContent.split('\n')) {
162
- if (!line.trim() || line.trim().startsWith('#'))
163
- continue;
164
- const indent = line.length - line.trimStart().length;
165
- const stripped = line.trim();
166
- if (indent === 0 && stripped.includes(':')) {
167
- const idx = stripped.indexOf(':');
168
- const key = stripped.slice(0, idx).trim();
169
- const value = stripped.slice(idx + 1).trim();
170
- if (value) {
171
- metadata[key] = this._parseYamlValue(value);
172
- currentKey = null;
173
- }
174
- else {
175
- currentKey = key;
176
- metadata[key] = {};
177
- }
178
- }
179
- else if (indent > 0 && currentKey && stripped.includes(':')) {
180
- const idx = stripped.indexOf(':');
181
- const key = stripped.slice(0, idx).trim();
182
- const value = stripped.slice(idx + 1).trim();
183
- metadata[currentKey][key] = this._parseYamlValue(value);
184
- }
185
- }
186
- return metadata;
187
- }
188
- _parseYamlValue(value) {
189
- const v = value.trim();
190
- if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) {
191
- return v.slice(1, -1);
192
- }
193
- return v;
194
- }
195
- /** Validate skill name: 1-64 chars, lowercase alphanumeric + hyphens, no leading/trailing/double hyphens. */
196
- _validateSkillName(name) {
197
- if (!name || name.length > 64)
198
- return false;
199
- if (!/^[a-z0-9-]+$/.test(name))
200
- return false;
201
- if (name.startsWith('-') || name.endsWith('-'))
202
- return false;
203
- if (name.includes('--'))
204
- return false;
205
- return true;
206
- }
207
- // ---- Accessors ----
208
- listSkills() {
209
- return Array.from(this.skills.keys());
210
- }
211
- getSkill(skillName) {
212
- return this.skills.get(skillName);
213
- }
214
- getSkillContent(skillName) {
215
- return this.skills.get(skillName)?.content ?? null;
216
- }
217
- loadSkill(skillName) {
218
- return this.getSkillContent(skillName);
219
- }
220
- getSkillMetadata(skillName) {
221
- return this.skills.get(skillName)?.metadata ?? null;
222
- }
223
- getAllSkillsMetadata() {
224
- return Array.from(this.skills.values()).map((s) => ({
225
- name: s.metadata['name'] ?? '',
226
- description: s.metadata['description'] ?? 'No description',
227
- license: s.metadata['license'] ?? null,
228
- compatibility: s.metadata['compatibility'] ?? null,
229
- }));
230
- }
231
- /** Formatted metadata string for prompt injection (e.g. {skills_metadata}). */
232
- getSkillsMetadata() {
233
- const list = [];
234
- for (const s of this.skills.values()) {
235
- const name = s.metadata['name'] ?? 'Unknown';
236
- const desc = s.metadata['description'] ?? 'No description';
237
- list.push(`- ${name}: ${desc}`);
238
- }
239
- return list.length ? list.join('\n') : 'No skills available.';
240
- }
241
- // ---- Resource path helpers ----
242
- getScriptPath(skillName, scriptName) {
243
- return this._getResourcePath(skillName, scriptName, 'scriptsDir');
244
- }
245
- getReferencePath(skillName, referenceName) {
246
- return this._getResourcePath(skillName, referenceName, 'referencesDir');
247
- }
248
- getAssetPath(skillName, assetName) {
249
- return this._getResourcePath(skillName, assetName, 'assetsDir');
250
- }
251
- _getResourcePath(skillName, resName, dirKey) {
252
- const skill = this.skills.get(skillName);
253
- const dir = skill?.[dirKey];
254
- if (!dir)
255
- return null;
256
- const full = path.join(dir, resName);
257
- return fs.existsSync(full) ? full : null;
258
- }
259
- // ---- Relevance search (Node-specific, kept for planner skill lookup) ----
260
- findRelevantSkill(taskDescription) {
261
- const matches = this.findRelevantSkills(taskDescription, 1);
262
- if (matches.length > 0) {
263
- logger_1.logger.info(`SkillManager.findRelevantSkill: task="${taskDescription}" -> "${matches[0].name}" (score=${matches[0].score})`);
264
- return matches[0].name;
265
- }
266
- return null;
267
- }
268
- findRelevantSkills(taskDescription, topK = 3) {
269
- const queryTokens = tokenize(taskDescription);
270
- if (queryTokens.length === 0)
271
- return [];
272
- const querySet = new Set(queryTokens);
273
- const scored = [];
274
- for (const [name, skill] of this.skills) {
275
- const nameTokens = tokenize(name);
276
- const contentTokens = tokenize(skill.content);
277
- let nameScore = 0;
278
- for (const qt of querySet) {
279
- if (nameTokens.includes(qt))
280
- nameScore += 5;
281
- }
282
- const nameOverlap = nameTokens.filter((nt) => querySet.has(nt)).length;
283
- nameScore += nameOverlap * 3;
284
- const contentTf = new Map();
285
- for (const ct of contentTokens) {
286
- contentTf.set(ct, (contentTf.get(ct) ?? 0) + 1);
287
- }
288
- let contentScore = 0;
289
- for (const qt of querySet) {
290
- const freq = contentTf.get(qt);
291
- if (freq)
292
- contentScore += freq;
293
- }
294
- const totalScore = nameScore + contentScore;
295
- if (totalScore > 0)
296
- scored.push({ name, score: totalScore });
297
- }
298
- scored.sort((a, b) => b.score - a.score);
299
- return scored.slice(0, topK);
300
- }
301
- }
302
- exports.SkillManager = SkillManager;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,57 +0,0 @@
1
- "use strict";
2
- // Aligned with python data_types/case.py: AppInfo / CaseInfo structured case model.
3
- // Used by case_runner (tools/case_runner) and batch runner CaseInfo-mode.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.CaseInfo = exports.AppInfo = void 0;
6
- class AppInfo {
7
- bundleName;
8
- displayName;
9
- constructor(bundleName, displayName) {
10
- this.bundleName = bundleName;
11
- this.displayName = displayName;
12
- }
13
- toDict() {
14
- return {
15
- bundle_name: this.bundleName,
16
- display_name: this.displayName,
17
- };
18
- }
19
- static fromDict(data) {
20
- return new AppInfo(String(data['bundle_name'] ?? ''), String(data['display_name'] ?? ''));
21
- }
22
- }
23
- exports.AppInfo = AppInfo;
24
- class CaseInfo {
25
- caseId;
26
- caseName;
27
- setupSteps;
28
- processSteps;
29
- teardownSteps;
30
- appInfos;
31
- extendTools;
32
- constructor(caseId, caseName, setupSteps, processSteps, teardownSteps, appInfos, extendTools = []) {
33
- this.caseId = caseId;
34
- this.caseName = caseName;
35
- this.setupSteps = setupSteps;
36
- this.processSteps = processSteps;
37
- this.teardownSteps = teardownSteps;
38
- this.appInfos = appInfos;
39
- this.extendTools = extendTools;
40
- }
41
- toDict() {
42
- return {
43
- case_id: this.caseId,
44
- case_name: this.caseName,
45
- setup_steps: this.setupSteps,
46
- process_steps: this.processSteps,
47
- teardown_steps: this.teardownSteps,
48
- app_infos: this.appInfos.map((a) => a.toDict()),
49
- extend_tools: this.extendTools,
50
- };
51
- }
52
- static fromDict(data) {
53
- const appInfosRaw = data['app_infos'] ?? [];
54
- return new CaseInfo(String(data['case_id'] ?? ''), String(data['case_name'] ?? ''), String(data['setup_steps'] ?? ''), String(data['process_steps'] ?? ''), String(data['teardown_steps'] ?? ''), appInfosRaw.map((a) => AppInfo.fromDict(a)), data['extend_tools'] ?? []);
55
- }
56
- }
57
- exports.CaseInfo = CaseInfo;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });