@autotest/agent 0.0.6 → 0.0.8

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 (155) hide show
  1. package/README.md +7 -0
  2. package/dist/.buildstamp +1 -0
  3. package/dist/api/agent_api.d.ts +2 -2
  4. package/dist/autotest-cli.js +1 -397
  5. package/dist/common/config/config.yaml +4 -0
  6. package/dist/common/config/manager.d.ts +4 -4
  7. package/dist/common/config/types.d.ts +5 -0
  8. package/dist/common/dfx/index.d.ts +1 -1
  9. package/dist/core/agent/single_agent/agent.d.ts +1 -0
  10. package/dist/core/device/device_protocol.d.ts +1 -1
  11. package/dist/core/device/hdc/device.d.ts +5 -2
  12. package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
  13. package/dist/core/knowledge/vectordb.d.ts +5 -5
  14. package/dist/core/mcp/harmony_hdc_adapter.d.ts +2 -0
  15. package/dist/core/mcp/mcp_tools.d.ts +1 -0
  16. package/dist/core/mcp/verify_tool.d.ts +12 -0
  17. package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
  18. package/dist/data_types/device.d.ts +1 -1
  19. package/dist/data_types/index.d.ts +1 -1
  20. package/dist/index.d.ts +4 -4
  21. package/dist/index.js +1 -163
  22. package/dist/tools/batch_runner.js +1 -745
  23. package/dist/tools/case_runner/runner.js +1 -410
  24. package/dist/tools/config/config_tool.js +1 -339
  25. package/dist/tools/prompt_compare/compare_runner.js +1 -360
  26. package/package.json +2 -2
  27. package/dist/api/agent_api.js +0 -550
  28. package/dist/api/autotest_agent.js +0 -205
  29. package/dist/api/types.js +0 -11
  30. package/dist/common/case_manager.js +0 -91
  31. package/dist/common/collect_case.js +0 -128
  32. package/dist/common/common_errors.js +0 -66
  33. package/dist/common/config/config_validator.js +0 -28
  34. package/dist/common/config/manager.js +0 -257
  35. package/dist/common/config/output.js +0 -59
  36. package/dist/common/config/types.js +0 -185
  37. package/dist/common/dfx/client_factory.js +0 -62
  38. package/dist/common/dfx/context.js +0 -23
  39. package/dist/common/dfx/index.js +0 -15
  40. package/dist/common/dfx/recorder.js +0 -191
  41. package/dist/common/dfx/recording_fetch.js +0 -228
  42. package/dist/common/dfx/source.js +0 -13
  43. package/dist/common/image_cacher.js +0 -36
  44. package/dist/common/image_helper.js +0 -128
  45. package/dist/common/image_similarity.js +0 -171
  46. package/dist/common/llm_cache/cache_transport.js +0 -102
  47. package/dist/common/llm_cache/prompt_cache.js +0 -113
  48. package/dist/common/logger.js +0 -158
  49. package/dist/common/model/custom_model.js +0 -487
  50. package/dist/common/model/index.js +0 -5
  51. package/dist/common/path_utils.js +0 -88
  52. package/dist/common/result_parser.js +0 -49
  53. package/dist/common/usage/token_usage.js +0 -117
  54. package/dist/common/utils.js +0 -125
  55. package/dist/core/agent/layered_agent/ability_helper.js +0 -125
  56. package/dist/core/agent/layered_agent/agent.js +0 -37
  57. package/dist/core/agent/layered_agent/agent_registry.js +0 -82
  58. package/dist/core/agent/layered_agent/decision.js +0 -518
  59. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
  60. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
  61. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
  62. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
  63. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
  64. package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
  65. package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
  66. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
  67. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
  68. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
  69. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
  70. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
  71. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
  72. package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
  73. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
  74. package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
  75. package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
  76. package/dist/core/agent/report_analyzer_agent/config.js +0 -22
  77. package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
  78. package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
  79. package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
  80. package/dist/core/agent/report_analyzer_agent/index.js +0 -52
  81. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
  82. package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
  83. package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
  84. package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
  85. package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
  86. package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
  87. package/dist/core/agent/report_analyzer_agent/types.js +0 -274
  88. package/dist/core/agent/rewrite_agent/agent.js +0 -209
  89. package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
  90. package/dist/core/agent/rewrite_agent/mapping.js +0 -56
  91. package/dist/core/agent/rewrite_agent/parse.js +0 -121
  92. package/dist/core/agent/rewrite_agent/types.js +0 -37
  93. package/dist/core/agent/single_agent/agent.js +0 -801
  94. package/dist/core/agent/single_agent/hook_manager.js +0 -59
  95. package/dist/core/agent/single_agent/hooks.js +0 -288
  96. package/dist/core/agent/single_agent/image_utils.js +0 -158
  97. package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
  98. package/dist/core/agent/single_agent/subagent_manager.js +0 -72
  99. package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
  100. package/dist/core/agent/types.js +0 -2
  101. package/dist/core/agent/utils/message_builder.js +0 -138
  102. package/dist/core/device/device_protocol.js +0 -2
  103. package/dist/core/device/hdc/apps.js +0 -437
  104. package/dist/core/device/hdc/device.js +0 -219
  105. package/dist/core/device/hdc/index.js +0 -31
  106. package/dist/core/device/hdc/input.js +0 -74
  107. package/dist/core/device/hdc/screenshot.js +0 -171
  108. package/dist/core/device/index.js +0 -70
  109. package/dist/core/device/types.js +0 -2
  110. package/dist/core/knowledge/knowledge_manager.js +0 -70
  111. package/dist/core/knowledge/vectordb.js +0 -283
  112. package/dist/core/mcp/adapter_factory.js +0 -99
  113. package/dist/core/mcp/android_adapter.js +0 -286
  114. package/dist/core/mcp/base_adapter.js +0 -86
  115. package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
  116. package/dist/core/mcp/ios_adapter.js +0 -286
  117. package/dist/core/mcp/local_tools.js +0 -41
  118. package/dist/core/mcp/mcp_tools.js +0 -473
  119. package/dist/core/mcp/types.js +0 -6
  120. package/dist/core/memory/_utils.js +0 -140
  121. package/dist/core/memory/compressed_session.js +0 -182
  122. package/dist/core/memory/context_compressor.js +0 -176
  123. package/dist/core/memory/index.js +0 -22
  124. package/dist/core/memory/memory_manager.js +0 -28
  125. package/dist/core/memory/reflector.js +0 -95
  126. package/dist/core/memory/replan_manager.js +0 -12
  127. package/dist/core/memory/session_factory.js +0 -29
  128. package/dist/core/memory/tool_player.js +0 -225
  129. package/dist/core/memory/tool_player_popup.js +0 -276
  130. package/dist/core/memory/tool_player_replan.js +0 -226
  131. package/dist/core/memory/tool_player_xpath.js +0 -139
  132. package/dist/core/memory/tool_recorder.js +0 -126
  133. package/dist/core/preprocessor/task_splitter.js +0 -112
  134. package/dist/core/prompt/prompt_loader.js +0 -315
  135. package/dist/core/skill/skill_manager.js +0 -302
  136. package/dist/data_types/action.js +0 -2
  137. package/dist/data_types/agent.js +0 -2
  138. package/dist/data_types/case.js +0 -57
  139. package/dist/data_types/device.js +0 -2
  140. package/dist/data_types/index.js +0 -11
  141. package/dist/data_types/report.js +0 -6
  142. package/dist/data_types/screen.js +0 -23
  143. package/dist/data_types/task.js +0 -2
  144. package/dist/loop/cli.js +0 -127
  145. package/dist/loop/orchestrator.js +0 -314
  146. package/dist/loop/result_writer.js +0 -260
  147. package/dist/loop/types.js +0 -82
  148. package/dist/mcp-server/server.js +0 -341
  149. package/dist/mcp-server/types.js +0 -224
  150. package/dist/reporter/batch_summary.js +0 -197
  151. package/dist/reporter/generator.js +0 -286
  152. package/dist/reporter/html_template/index.js +0 -529
  153. package/dist/reporter/json_report.js +0 -6
  154. package/dist/reporter/types.js +0 -45
  155. 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.IOSMCPAdapter = void 0;
37
- const net = __importStar(require("net"));
38
- const path = __importStar(require("path"));
39
- const fs = __importStar(require("fs"));
40
- const os = __importStar(require("os"));
41
- const child_process_1 = require("child_process");
42
- const base_adapter_1 = require("./base_adapter");
43
- const common_errors_1 = require("../../common/common_errors");
44
- class IOSMCPAdapter extends base_adapter_1.MCPDeviceAdapterBase {
45
- platform = 'ios';
46
- devicectlPath;
47
- mcpProcess = null;
48
- mcpServerUrl = null;
49
- logFilePath = null;
50
- logStream = null;
51
- static MCP_SERVICE_PORT = 8712;
52
- static SCREENSHOT_TOOL_NAME = 'mobile_take_screenshot';
53
- static PRESS_BUTTON_TOOL = 'mobile_press_button';
54
- constructor(devicectlPath = 'devicectl', configManager) {
55
- super(configManager);
56
- this.devicectlPath = devicectlPath;
57
- }
58
- getDefaultServerUrl() {
59
- return `http://127.0.0.1:${IOSMCPAdapter.MCP_SERVICE_PORT}/mcp`;
60
- }
61
- getMcpServicePort() {
62
- return IOSMCPAdapter.MCP_SERVICE_PORT;
63
- }
64
- useSseTransport() {
65
- return true;
66
- }
67
- async startMcpService() {
68
- const config = this.configManager.getEffectiveConfig();
69
- const port = IOSMCPAdapter.MCP_SERVICE_PORT;
70
- await this.killProcessByPort(port);
71
- await new Promise((r) => setTimeout(r, 1000));
72
- const env = {
73
- ...Object.fromEntries(Object.entries(process.env).filter(([, v]) => v != null)),
74
- };
75
- if (config.device.deviceSn) {
76
- env.DEVICE_ID = config.device.deviceSn;
77
- }
78
- const logDir = path.join(config.output.rootDir, 'log');
79
- fs.mkdirSync(logDir, { recursive: true });
80
- const timestamp = new Date().toISOString().replace(/[:.]/g, '').slice(0, 15);
81
- this.logFilePath = path.join(logDir, `mobile_mcp_ios_${timestamp}.log`);
82
- this.logStream = fs.createWriteStream(this.logFilePath, { flags: 'w' });
83
- const npxCmd = os.platform() === 'win32' ? 'npx.cmd' : 'npx';
84
- try {
85
- this.mcpProcess = (0, child_process_1.spawn)(npxCmd, ['-y', '@mobilenext/mobile-mcp@latest', '--listen', `0.0.0.0:${port}`], { env, cwd: process.cwd(), stdio: ['ignore', 'pipe', 'pipe'] });
86
- this.mcpProcess.stdout?.pipe(this.logStream);
87
- this.mcpProcess.stderr?.pipe(this.logStream);
88
- this.mcpProcess.on('error', (err) => {
89
- if (this.logFilePath) {
90
- fs.appendFileSync(this.logFilePath, `mobile_mcp process error: ${err.message}\n`);
91
- }
92
- });
93
- }
94
- catch (err) {
95
- this.closeLogStream();
96
- throw new common_errors_1.AgentError('MCP_SERVICE_TIMEOUT', `mobile-mcp start failed: ${err instanceof Error ? err.message : String(err)}`);
97
- }
98
- const serverUrl = this.getDefaultServerUrl();
99
- for (let attempt = 0; attempt < 20; attempt++) {
100
- await new Promise((r) => setTimeout(r, 1000));
101
- if (await this.isPortListening('127.0.0.1', port)) {
102
- return serverUrl;
103
- }
104
- }
105
- throw new common_errors_1.AgentError('MCP_SERVICE_TIMEOUT', `mobile-mcp service start timeout (20s), port ${port} not listening`);
106
- }
107
- async checkServiceHealth(serverUrl) {
108
- if (this.mcpProcess && this.mcpProcess.exitCode !== null) {
109
- return { isHealthy: false, status: 'notRunning' };
110
- }
111
- const portListening = await this.isPortListening('127.0.0.1', IOSMCPAdapter.MCP_SERVICE_PORT);
112
- if (!portListening) {
113
- return { isHealthy: false, status: 'notRunning' };
114
- }
115
- try {
116
- const response = await fetch(serverUrl, {
117
- method: 'POST',
118
- headers: { 'Content-Type': 'application/json', 'Accept': 'application/json, text/event-stream' },
119
- body: JSON.stringify({ jsonrpc: '2.0', method: 'ping', id: 1 }),
120
- signal: AbortSignal.timeout(5000),
121
- });
122
- if (response.ok) {
123
- return { isHealthy: true, status: 'healthy' };
124
- }
125
- return { isHealthy: false, status: 'error' };
126
- }
127
- catch {
128
- return { isHealthy: false, status: 'error' };
129
- }
130
- }
131
- async killProcessByPort(port) {
132
- const sys = os.platform();
133
- try {
134
- if (sys === 'win32') {
135
- const result = (0, child_process_1.execSync)('netstat -ano', { encoding: 'utf-8', timeout: 5000 });
136
- for (const line of result.split('\n')) {
137
- if (line.includes(`:${port}`) && line.includes('LISTENING')) {
138
- const parts = line.trim().split(/\s+/);
139
- const pid = parts[parts.length - 1];
140
- (0, child_process_1.execSync)(`taskkill /F /PID ${pid}`, { timeout: 5000 });
141
- return;
142
- }
143
- }
144
- }
145
- else {
146
- const result = (0, child_process_1.execSync)(`lsof -ti:${port}`, { encoding: 'utf-8', timeout: 5000 });
147
- if (result.trim()) {
148
- const pid = result.trim().split('\n')[0];
149
- (0, child_process_1.execSync)(`kill -9 ${pid}`, { timeout: 5000 });
150
- }
151
- }
152
- }
153
- catch {
154
- // port cleanup failed, not blocking main flow
155
- }
156
- }
157
- async callTool(toolName, args, timeout, retryOnFailure) {
158
- if (!this.connected) {
159
- throw new common_errors_1.AgentError('DEVICE_NOT_CONNECTED', 'Adapter not connected');
160
- }
161
- const config = this.configManager.getEffectiveConfig();
162
- const effectiveArgs = { ...(args ?? {}) };
163
- if (!effectiveArgs.device && config.device.deviceSn) {
164
- effectiveArgs.device = config.device.deviceSn;
165
- }
166
- const serverUrl = this.mcpServerUrl ?? this.getDefaultServerUrl();
167
- const effectiveTimeout = timeout ?? 60;
168
- const shouldRetry = retryOnFailure ?? true;
169
- try {
170
- const response = await fetch(serverUrl, {
171
- method: 'POST',
172
- headers: { 'Content-Type': 'application/json' },
173
- body: JSON.stringify({
174
- jsonrpc: '2.0',
175
- method: 'tools/call',
176
- id: Date.now(),
177
- params: { name: toolName, arguments: effectiveArgs },
178
- }),
179
- signal: this.getCallSignal(effectiveTimeout * 1000),
180
- });
181
- if (!response.ok) {
182
- throw new Error(`MCP tool call HTTP error: ${response.status}`);
183
- }
184
- const json = await response.json();
185
- if (json.error) {
186
- throw new Error(json.error.message);
187
- }
188
- return json.result;
189
- }
190
- catch (err) {
191
- if (!shouldRetry || this.isAborted()) {
192
- throw new common_errors_1.AgentError('MCP_SERVICE_TIMEOUT', err instanceof Error ? err.message : String(err));
193
- }
194
- try {
195
- await this.ensureServiceRunning(true);
196
- const retryUrl = this.getDefaultServerUrl();
197
- const retryResponse = await fetch(retryUrl, {
198
- method: 'POST',
199
- headers: { 'Content-Type': 'application/json' },
200
- body: JSON.stringify({
201
- jsonrpc: '2.0',
202
- method: 'tools/call',
203
- id: Date.now(),
204
- params: { name: toolName, arguments: effectiveArgs },
205
- }),
206
- signal: this.getCallSignal(effectiveTimeout * 1000),
207
- });
208
- const retryJson = await retryResponse.json();
209
- if (retryJson.error) {
210
- throw new Error(retryJson.error.message);
211
- }
212
- return retryJson.result;
213
- }
214
- catch (retryErr) {
215
- throw new common_errors_1.AgentError('MCP_SERVICE_TIMEOUT', `tool call failed and reconnect failed: ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`);
216
- }
217
- }
218
- }
219
- async getScreenshot() {
220
- if (!this.connected) {
221
- throw new common_errors_1.AgentError('DEVICE_NOT_CONNECTED', 'Adapter not connected');
222
- }
223
- let base64Data = '';
224
- const result = await this.callTool(IOSMCPAdapter.SCREENSHOT_TOOL_NAME);
225
- if (result && typeof result === 'object') {
226
- const content = result.content;
227
- if (Array.isArray(content) && content.length > 0) {
228
- const item = content[0];
229
- if (item.data) {
230
- base64Data = item.data;
231
- }
232
- }
233
- }
234
- return {
235
- base64Data,
236
- layoutData: '',
237
- width: 1080,
238
- height: 1920,
239
- isSensitive: false,
240
- screenshotPath: null,
241
- };
242
- }
243
- async reset() {
244
- if (!this.connected) {
245
- throw new common_errors_1.AgentError('DEVICE_NOT_CONNECTED', 'Adapter not connected');
246
- }
247
- try {
248
- await this.callTool(IOSMCPAdapter.PRESS_BUTTON_TOOL, { button: 'HOME' }, 30, false);
249
- }
250
- catch {
251
- // timeout not treated as failure
252
- }
253
- }
254
- async connect() {
255
- await this.ensureServiceRunning();
256
- this.mcpServerUrl = this.getDefaultServerUrl();
257
- this.connected = true;
258
- }
259
- async disconnect() {
260
- await super.disconnect();
261
- this.mcpServerUrl = null;
262
- this.closeLogStream();
263
- if (this.mcpProcess) {
264
- this.mcpProcess.kill();
265
- this.mcpProcess = null;
266
- }
267
- this.logFilePath = null;
268
- }
269
- closeLogStream() {
270
- if (this.logStream) {
271
- this.logStream.end();
272
- this.logStream = null;
273
- }
274
- }
275
- async isPortListening(host, port) {
276
- return new Promise((resolve) => {
277
- const socket = new net.Socket();
278
- socket.setTimeout(2000);
279
- socket.on('connect', () => { socket.destroy(); resolve(true); });
280
- socket.on('error', () => { socket.destroy(); resolve(false); });
281
- socket.on('timeout', () => { socket.destroy(); resolve(false); });
282
- socket.connect(port, host);
283
- });
284
- }
285
- }
286
- exports.IOSMCPAdapter = IOSMCPAdapter;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /**
3
- * Local helper tools executed directly (not via the MCP protocol).
4
- *
5
- * Current tools:
6
- * - wait: sleep for a number of seconds
7
- * - load_skill: load skill step content from the skill manager
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.wait = wait;
11
- exports.loadSkill = loadSkill;
12
- const logger_1 = require("../../common/logger");
13
- const skill_manager_1 = require("../skill/skill_manager");
14
- /**
15
- * Wait for the given number of seconds.
16
- * @param seconds Seconds to wait (e.g. 1, 2, 5).
17
- * @returns A message confirming the wait completed.
18
- */
19
- async function wait(seconds) {
20
- await sleep(seconds);
21
- logger_1.logger.debug(`[Tool] waited ${seconds} seconds`);
22
- return `Waited ${seconds} seconds`;
23
- }
24
- /**
25
- * Load the detailed steps for a named skill.
26
- * @param skillName The skill name to load.
27
- * @returns The skill content, or a not-found message.
28
- */
29
- async function loadSkill(skillName) {
30
- const skillManager = new skill_manager_1.SkillManager();
31
- const content = skillManager.getSkillContent(skillName);
32
- if (content) {
33
- logger_1.logger.debug(`[Tool] loaded skill '${skillName}'`);
34
- return content;
35
- }
36
- logger_1.logger.warn(`[Tool] skill '${skillName}' not found`);
37
- return `Skill '${skillName}' not found, please check the skill file exists`;
38
- }
39
- function sleep(seconds) {
40
- return new Promise((resolve) => setTimeout(resolve, Math.max(0, seconds) * 1000));
41
- }