@autotest/agent 0.0.6 → 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 (153) hide show
  1. package/README.md +7 -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 +4 -0
  5. package/dist/common/config/manager.d.ts +4 -4
  6. package/dist/common/config/types.d.ts +5 -0
  7. package/dist/common/dfx/index.d.ts +1 -1
  8. package/dist/core/agent/single_agent/agent.d.ts +1 -0
  9. package/dist/core/device/device_protocol.d.ts +1 -1
  10. package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
  11. package/dist/core/knowledge/vectordb.d.ts +5 -5
  12. package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
  13. package/dist/core/mcp/mcp_tools.d.ts +1 -0
  14. package/dist/core/mcp/verify_tool.d.ts +12 -0
  15. package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
  16. package/dist/data_types/device.d.ts +1 -1
  17. package/dist/data_types/index.d.ts +1 -1
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +1 -163
  20. package/dist/tools/batch_runner.js +1 -745
  21. package/dist/tools/case_runner/runner.js +1 -410
  22. package/dist/tools/config/config_tool.js +1 -339
  23. package/dist/tools/prompt_compare/compare_runner.js +1 -360
  24. package/package.json +2 -2
  25. package/dist/api/agent_api.js +0 -550
  26. package/dist/api/autotest_agent.js +0 -205
  27. package/dist/api/types.js +0 -11
  28. package/dist/common/case_manager.js +0 -91
  29. package/dist/common/collect_case.js +0 -128
  30. package/dist/common/common_errors.js +0 -66
  31. package/dist/common/config/config_validator.js +0 -28
  32. package/dist/common/config/manager.js +0 -257
  33. package/dist/common/config/output.js +0 -59
  34. package/dist/common/config/types.js +0 -185
  35. package/dist/common/dfx/client_factory.js +0 -62
  36. package/dist/common/dfx/context.js +0 -23
  37. package/dist/common/dfx/index.js +0 -15
  38. package/dist/common/dfx/recorder.js +0 -191
  39. package/dist/common/dfx/recording_fetch.js +0 -228
  40. package/dist/common/dfx/source.js +0 -13
  41. package/dist/common/image_cacher.js +0 -36
  42. package/dist/common/image_helper.js +0 -128
  43. package/dist/common/image_similarity.js +0 -171
  44. package/dist/common/llm_cache/cache_transport.js +0 -102
  45. package/dist/common/llm_cache/prompt_cache.js +0 -113
  46. package/dist/common/logger.js +0 -158
  47. package/dist/common/model/custom_model.js +0 -487
  48. package/dist/common/model/index.js +0 -5
  49. package/dist/common/path_utils.js +0 -88
  50. package/dist/common/result_parser.js +0 -49
  51. package/dist/common/usage/token_usage.js +0 -117
  52. package/dist/common/utils.js +0 -125
  53. package/dist/core/agent/layered_agent/ability_helper.js +0 -125
  54. package/dist/core/agent/layered_agent/agent.js +0 -37
  55. package/dist/core/agent/layered_agent/agent_registry.js +0 -82
  56. package/dist/core/agent/layered_agent/decision.js +0 -518
  57. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
  58. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
  59. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
  60. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
  61. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
  62. package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
  63. package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
  64. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
  65. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
  66. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
  67. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
  68. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
  69. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
  70. package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
  71. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
  72. package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
  73. package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
  74. package/dist/core/agent/report_analyzer_agent/config.js +0 -22
  75. package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
  76. package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
  77. package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
  78. package/dist/core/agent/report_analyzer_agent/index.js +0 -52
  79. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
  80. package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
  81. package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
  82. package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
  83. package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
  84. package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
  85. package/dist/core/agent/report_analyzer_agent/types.js +0 -274
  86. package/dist/core/agent/rewrite_agent/agent.js +0 -209
  87. package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
  88. package/dist/core/agent/rewrite_agent/mapping.js +0 -56
  89. package/dist/core/agent/rewrite_agent/parse.js +0 -121
  90. package/dist/core/agent/rewrite_agent/types.js +0 -37
  91. package/dist/core/agent/single_agent/agent.js +0 -801
  92. package/dist/core/agent/single_agent/hook_manager.js +0 -59
  93. package/dist/core/agent/single_agent/hooks.js +0 -288
  94. package/dist/core/agent/single_agent/image_utils.js +0 -158
  95. package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
  96. package/dist/core/agent/single_agent/subagent_manager.js +0 -72
  97. package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
  98. package/dist/core/agent/types.js +0 -2
  99. package/dist/core/agent/utils/message_builder.js +0 -138
  100. package/dist/core/device/device_protocol.js +0 -2
  101. package/dist/core/device/hdc/apps.js +0 -437
  102. package/dist/core/device/hdc/device.js +0 -219
  103. package/dist/core/device/hdc/index.js +0 -31
  104. package/dist/core/device/hdc/input.js +0 -74
  105. package/dist/core/device/hdc/screenshot.js +0 -171
  106. package/dist/core/device/index.js +0 -70
  107. package/dist/core/device/types.js +0 -2
  108. package/dist/core/knowledge/knowledge_manager.js +0 -70
  109. package/dist/core/knowledge/vectordb.js +0 -283
  110. package/dist/core/mcp/adapter_factory.js +0 -99
  111. package/dist/core/mcp/android_adapter.js +0 -286
  112. package/dist/core/mcp/base_adapter.js +0 -86
  113. package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
  114. package/dist/core/mcp/ios_adapter.js +0 -286
  115. package/dist/core/mcp/local_tools.js +0 -41
  116. package/dist/core/mcp/mcp_tools.js +0 -473
  117. package/dist/core/mcp/types.js +0 -6
  118. package/dist/core/memory/_utils.js +0 -140
  119. package/dist/core/memory/compressed_session.js +0 -182
  120. package/dist/core/memory/context_compressor.js +0 -176
  121. package/dist/core/memory/index.js +0 -22
  122. package/dist/core/memory/memory_manager.js +0 -28
  123. package/dist/core/memory/reflector.js +0 -95
  124. package/dist/core/memory/replan_manager.js +0 -12
  125. package/dist/core/memory/session_factory.js +0 -29
  126. package/dist/core/memory/tool_player.js +0 -225
  127. package/dist/core/memory/tool_player_popup.js +0 -276
  128. package/dist/core/memory/tool_player_replan.js +0 -226
  129. package/dist/core/memory/tool_player_xpath.js +0 -139
  130. package/dist/core/memory/tool_recorder.js +0 -126
  131. package/dist/core/preprocessor/task_splitter.js +0 -112
  132. package/dist/core/prompt/prompt_loader.js +0 -315
  133. package/dist/core/skill/skill_manager.js +0 -302
  134. package/dist/data_types/action.js +0 -2
  135. package/dist/data_types/agent.js +0 -2
  136. package/dist/data_types/case.js +0 -57
  137. package/dist/data_types/device.js +0 -2
  138. package/dist/data_types/index.js +0 -11
  139. package/dist/data_types/report.js +0 -6
  140. package/dist/data_types/screen.js +0 -23
  141. package/dist/data_types/task.js +0 -2
  142. package/dist/loop/cli.js +0 -127
  143. package/dist/loop/orchestrator.js +0 -314
  144. package/dist/loop/result_writer.js +0 -260
  145. package/dist/loop/types.js +0 -82
  146. package/dist/mcp-server/server.js +0 -341
  147. package/dist/mcp-server/types.js +0 -224
  148. package/dist/reporter/batch_summary.js +0 -197
  149. package/dist/reporter/generator.js +0 -286
  150. package/dist/reporter/html_template/index.js +0 -529
  151. package/dist/reporter/json_report.js +0 -6
  152. package/dist/reporter/types.js +0 -45
  153. package/dist/tools/case_runner/report.js +0 -264
@@ -1,286 +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.ReportGeneratorImpl = void 0;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
39
- const result_parser_1 = require("../common/result_parser");
40
- const types_1 = require("./types");
41
- const html_template_1 = require("./html_template");
42
- const json_report_1 = require("./json_report");
43
- class ReportGeneratorImpl {
44
- events = [];
45
- totalTokens = {
46
- total: 0, inputTokens: 0, outputTokens: 0, reasoningTokens: 0, cachedTokens: 0, sources: {},
47
- };
48
- stepTokens = [];
49
- taskDesc = '';
50
- testCase = '';
51
- startTime = null;
52
- endTime = null;
53
- status = null;
54
- reportDir;
55
- embedImages;
56
- embedMaxPixels;
57
- constructor(reportDir, embedImages = false, embedMaxPixels = 800) {
58
- this.reportDir = reportDir;
59
- this.embedImages = embedImages;
60
- this.embedMaxPixels = embedMaxPixels;
61
- if (!fs.existsSync(reportDir)) {
62
- fs.mkdirSync(reportDir, { recursive: true });
63
- }
64
- }
65
- addEvent(event) {
66
- const parsed = types_1.ReportEventSchema.safeParse(event);
67
- if (parsed.success) {
68
- this.events.push(parsed.data);
69
- }
70
- else {
71
- this.events.push({
72
- eventType: event.eventType,
73
- timestamp: event.timestamp ?? new Date().toISOString(),
74
- content: event.content ?? '',
75
- data: event.data ?? {},
76
- screenshotPath: event.screenshotPath,
77
- stepNumber: event.stepNumber,
78
- });
79
- }
80
- this.flushJson();
81
- }
82
- getCurrentStepNumber() {
83
- for (let i = this.events.length - 1; i >= 0; i--) {
84
- const sn = this.events[i].stepNumber;
85
- if (sn != null) {
86
- return sn;
87
- }
88
- }
89
- return 0;
90
- }
91
- flushJson() {
92
- if (!this.reportDir)
93
- return;
94
- try {
95
- const data = this.serializeForJson();
96
- fs.writeFileSync(path.join(this.reportDir, 'report.json'), (0, json_report_1.generateJson)(data), 'utf-8');
97
- }
98
- catch {
99
- // flush failure is non-blocking
100
- }
101
- }
102
- addTokenUsage(usage, source, stepNumber) {
103
- const u = usage;
104
- if (!u)
105
- return;
106
- const input = u.inputTokens ?? u.input_tokens ?? 0;
107
- const output = u.outputTokens ?? u.output_tokens ?? 0;
108
- const reasoning = u.reasoningTokens ?? u.reasoning_tokens ?? 0;
109
- const cached = u.cachedTokens ?? u.cached_tokens ?? 0;
110
- const total = input + output + reasoning + cached;
111
- const uncached = input - cached;
112
- const normalized = Math.round((uncached * 1.0 + cached * 0.2 + output * 1.0) * 10) / 10;
113
- this.totalTokens.total += total;
114
- this.totalTokens.inputTokens += input;
115
- this.totalTokens.outputTokens += output;
116
- this.totalTokens.reasoningTokens += reasoning;
117
- this.totalTokens.cachedTokens += cached;
118
- if (source) {
119
- if (!this.totalTokens.sources[source]) {
120
- this.totalTokens.sources[source] = { total: 0, inputTokens: 0, outputTokens: 0, reasoningTokens: 0, cachedTokens: 0, sources: {} };
121
- }
122
- const src = this.totalTokens.sources[source];
123
- src.total += total;
124
- src.inputTokens += input;
125
- src.outputTokens += output;
126
- src.reasoningTokens += reasoning;
127
- src.cachedTokens += cached;
128
- }
129
- if (stepNumber !== undefined) {
130
- this.stepTokens.push({
131
- step_number: stepNumber, timestamp: new Date().toISOString(),
132
- input_tokens: input, output_tokens: output, reasoning_tokens: reasoning,
133
- cached_tokens: cached, total_tokens: total, normalized_tokens: normalized,
134
- ...(source ? { source } : {}),
135
- });
136
- }
137
- }
138
- setTask(task) { this.taskDesc = task; }
139
- setTestCase(testCase) { this.testCase = testCase; }
140
- startTask() {
141
- this.startTime = new Date().toISOString();
142
- this.addEvent({
143
- eventType: types_1.EventType.TASK_START, timestamp: this.startTime,
144
- content: `Task started: ${this.taskDesc}`,
145
- data: { testCase: this.testCase, task: this.taskDesc }, stepNumber: null,
146
- });
147
- }
148
- endTask(result, status) {
149
- this.endTime = new Date().toISOString();
150
- if (!status) {
151
- this.status = (0, result_parser_1.parseTaskResult)(null, result).status;
152
- }
153
- else {
154
- this.status = status.toUpperCase();
155
- }
156
- this.addEvent({
157
- eventType: types_1.EventType.TASK_END, timestamp: this.endTime,
158
- content: `Task completed: ${result}`,
159
- data: { result, status: this.status.toLowerCase() }, stepNumber: null,
160
- });
161
- }
162
- saveScreenshot(base64Data, layoutData, prefix) {
163
- const screenshotsDir = path.join(this.reportDir, 'screenPath');
164
- if (!fs.existsSync(screenshotsDir)) {
165
- fs.mkdirSync(screenshotsDir, { recursive: true });
166
- }
167
- const p = prefix ?? 'screenshot';
168
- const now = new Date();
169
- const pad = (n) => String(n).padStart(2, '0');
170
- const timestamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}_${String(now.getMilliseconds()).padStart(3, '0')}`;
171
- const filename = `${p}_${timestamp}.jpeg`;
172
- const filepath = path.join(screenshotsDir, filename);
173
- fs.writeFileSync(filepath, Buffer.from(base64Data, 'base64'));
174
- const layoutDir = path.join(this.reportDir, 'layout');
175
- if (!fs.existsSync(layoutDir)) {
176
- fs.mkdirSync(layoutDir, { recursive: true });
177
- }
178
- const layoutFilename = `${p}_${timestamp}.json`;
179
- fs.writeFileSync(path.join(layoutDir, layoutFilename), layoutData ?? '');
180
- return filepath;
181
- }
182
- saveJson() { this.flushJson(); }
183
- async saveAll(baseFilename) {
184
- const name = baseFilename ?? 'report';
185
- const reportData = this.buildReportData();
186
- const jsonPath = path.join(this.reportDir, `${name}.json`);
187
- fs.writeFileSync(jsonPath, (0, json_report_1.generateJson)(this.serializeForJson()), 'utf-8');
188
- const mdPath = path.join(this.reportDir, `${name}.md`);
189
- fs.writeFileSync(mdPath, this.generateMarkdown(reportData), 'utf-8');
190
- const htmlPath = path.join(this.reportDir, `${name}.html`);
191
- fs.writeFileSync(htmlPath, await (0, html_template_1.generateHtmlFromJson)(reportData, {
192
- reportDir: this.reportDir,
193
- embedImages: this.embedImages,
194
- embedMaxPixels: this.embedMaxPixels,
195
- }), 'utf-8');
196
- return { json: jsonPath, markdown: mdPath, html: htmlPath };
197
- }
198
- getReportDir() { return this.reportDir; }
199
- buildReportData() {
200
- return {
201
- test_case: this.testCase, task: this.taskDesc,
202
- start_time: this.startTime, end_time: this.endTime,
203
- total_tokens: this.totalTokens, step_tokens: this.stepTokens, events: this.events,
204
- };
205
- }
206
- serializeForJson() {
207
- return {
208
- test_case: this.testCase,
209
- task: this.taskDesc,
210
- start_time: this.startTime,
211
- end_time: this.endTime,
212
- total_tokens: this.totalTokens,
213
- step_tokens: this.stepTokens,
214
- events: this.events.map(e => this.eventToDict(e)),
215
- };
216
- }
217
- eventToDict(ev) {
218
- const d = {
219
- event_type: ev.eventType,
220
- timestamp: ev.timestamp,
221
- content: ev.content,
222
- data: ev.data,
223
- screenshot_path: ev.screenshotPath ?? null,
224
- step_number: ev.stepNumber ?? null,
225
- };
226
- if (ev.subEvents && ev.subEvents.length > 0) {
227
- d['sub_events'] = ev.subEvents;
228
- }
229
- return d;
230
- }
231
- generateMarkdown(data) {
232
- const lines = [];
233
- lines.push('# 执行报告', '');
234
- lines.push('## 任务信息', '');
235
- lines.push(`- **测试用例**: ${data.test_case || 'N/A'}`);
236
- lines.push(`- **任务描述**: ${data.task || 'N/A'}`);
237
- lines.push(`- **开始时间**: ${data.start_time ?? 'N/A'}`);
238
- lines.push(`- **结束时间**: ${data.end_time ?? 'N/A'}`);
239
- lines.push(`- **耗时**: ${(0, html_template_1.formatDuration)(data.start_time, data.end_time)}`, '');
240
- lines.push('### Token 消耗', '');
241
- lines.push(`- **总 Token**: ${(0, html_template_1.formatTokenCount)(data.total_tokens.total)}`);
242
- lines.push(`- **输入**: ${data.total_tokens.inputTokens}`);
243
- lines.push(`- **输出**: ${data.total_tokens.outputTokens}`);
244
- lines.push(`- **推理**: ${data.total_tokens.reasoningTokens}`);
245
- lines.push(`- **缓存**: ${data.total_tokens.cachedTokens}`);
246
- const sk = Object.keys(data.total_tokens.sources);
247
- if (sk.length > 0)
248
- lines.push(`- **来源**: ${sk.map(s => `${s}: ${data.total_tokens.sources[s].total}`).join(' | ')}`);
249
- lines.push(`- **总事件数**: ${data.events.length}`, '');
250
- const steps = (0, html_template_1.groupSteps)(data, this.reportDir);
251
- if (steps.length > 0) {
252
- lines.push('## 执行时间线', '');
253
- const fr = (0, html_template_1.getFinalStatus)(data, this.reportDir);
254
- lines.push(`**最终结果**: ${fr.status} ${fr.result ? '— ' + fr.result : ''}`, '');
255
- for (const g of steps) {
256
- const t = (0, html_template_1.getStepTokens)(data, g.step);
257
- const title = (0, html_template_1.extractStepTitle)(g);
258
- lines.push(`### Step ${g.step}: ${title}`, '');
259
- lines.push(`- **时间**: ${g.stepStartTime ? (0, html_template_1.formatTime)(g.stepStartTime) : 'N/A'} ~ ${g.stepEndTime ? (0, html_template_1.formatTime)(g.stepEndTime) : 'N/A'}`);
260
- lines.push(`- **Token**: 输入 ${t.input} | 输出 ${t.output} | 缓存 ${t.cached} | 推理 ${t.reasoning} | 归一化 ${t.normalized}`, '');
261
- if (g.reasoning) {
262
- lines.push('#### 💭 思考过程', '', g.reasoning, '');
263
- }
264
- if (g.thinking && g.thinking !== g.reasoning) {
265
- lines.push('#### 📌 模型输出', '', g.thinking, '');
266
- }
267
- if (g.toolCall) {
268
- lines.push('#### 🔧 工具调用', '', `**工具**: ${g.toolCall.name}`, '', '```json', g.toolCall.args, '```', '');
269
- }
270
- const ss = [{ l: '观察', p: g.observationScreenshot }, { l: '操作前', p: g.beforeScreenshot }, { l: '操作后', p: g.afterScreenshot }].filter(s => s.p);
271
- if (ss.length > 0) {
272
- lines.push('#### 📸 截图', '');
273
- for (const s of ss) {
274
- lines.push(`**${s.l}**:`, '', `<img src="${s.p}" width="300" />`, '');
275
- }
276
- }
277
- if (g.toolResult) {
278
- lines.push('#### ⚙️ 执行结果', '', '```json', g.toolResult, '```', '');
279
- }
280
- lines.push('---', '');
281
- }
282
- }
283
- return lines.join('\n');
284
- }
285
- }
286
- exports.ReportGeneratorImpl = ReportGeneratorImpl;