@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,255 +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.DataLoader = void 0;
37
- exports.createStepData = createStepData;
38
- exports.createReportData = createReportData;
39
- const fs = __importStar(require("fs"));
40
- const path = __importStar(require("path"));
41
- const logger_1 = require("../../../common/logger");
42
- function createStepData(stepNumber) {
43
- return { stepNumber, thinking: '', toolCall: {}, toolResult: {}, screenshots: [] };
44
- }
45
- function createReportData() {
46
- return { task: '', status: '', resultText: '', steps: [] };
47
- }
48
- function readJson(filePath) {
49
- let content = fs.readFileSync(filePath, 'utf-8');
50
- content = content.replace(/^\ufeff/, '');
51
- return JSON.parse(content);
52
- }
53
- function listReportJsons(reportDir) {
54
- const results = [];
55
- for (const entry of fs.readdirSync(reportDir)) {
56
- const fullPath = path.join(reportDir, entry);
57
- if (fs.statSync(fullPath).isFile() && entry.endsWith('.json') && entry !== 'analysis_result.json') {
58
- results.push(fullPath);
59
- }
60
- }
61
- return results;
62
- }
63
- function findReportJson(reportDir) {
64
- const jsonFiles = listReportJsons(reportDir);
65
- let latest = jsonFiles[0];
66
- let latestMtime = 0;
67
- for (const f of jsonFiles) {
68
- const mtime = fs.statSync(f).mtimeMs;
69
- if (mtime > latestMtime) {
70
- latestMtime = mtime;
71
- latest = f;
72
- }
73
- }
74
- return latest;
75
- }
76
- function resolveScreenshotPath(screenshotPath, screenshotDir) {
77
- if (!screenshotPath)
78
- return null;
79
- if (screenshotDir === null)
80
- return null;
81
- const p = path.resolve(screenshotPath);
82
- if (path.isAbsolute(screenshotPath) && fs.existsSync(p))
83
- return p;
84
- const candidates = [path.join(screenshotDir, path.basename(screenshotPath)), path.join(path.dirname(screenshotDir), path.basename(screenshotPath))];
85
- for (const cand of candidates) {
86
- if (fs.existsSync(cand))
87
- return cand;
88
- }
89
- return null;
90
- }
91
- function normalizePoint(point) {
92
- if (!point)
93
- return null;
94
- if (Array.isArray(point) && point.length >= 2)
95
- return { x: Number(point[0]), y: Number(point[1]) };
96
- if (typeof point === 'object' && point !== null && 'x' in point && 'y' in point)
97
- return { x: Number(point.x), y: Number(point.y) };
98
- return null;
99
- }
100
- class DataLoader {
101
- constructor() { }
102
- load(reportDir) {
103
- this.validateReportDir(reportDir);
104
- const reportJsonPath = findReportJson(reportDir);
105
- const data = readJson(reportJsonPath);
106
- const screenshotDir = path.join(reportDir, 'screenPath');
107
- return this.loadFromEvents(data, screenshotDir);
108
- }
109
- loadFromEvents(data, screenshotDir = null) {
110
- const events = data['events'] ?? [];
111
- const steps = this.groupEventsByStep(events, screenshotDir);
112
- const [status, resultText] = this.extractStatusAndResult(data);
113
- return { task: data['task'] ?? '', status, resultText, steps };
114
- }
115
- validateReportDir(reportDir) {
116
- if (!fs.existsSync(reportDir))
117
- throw new Error(`Report directory does not exist: ${reportDir}`);
118
- if (!fs.statSync(reportDir).isDirectory())
119
- throw new Error(`Path is not a directory: ${reportDir}`);
120
- const jsonFiles = listReportJsons(reportDir);
121
- if (jsonFiles.length === 0)
122
- throw new Error(`No JSON report file found in: ${reportDir}`);
123
- const screenPath = path.join(reportDir, 'screenPath');
124
- if (!fs.existsSync(screenPath))
125
- logger_1.logger.warn(`Screenshot directory does not exist: ${screenPath}`);
126
- }
127
- groupEventsByStep(events, screenshotDir) {
128
- const stepMap = new Map();
129
- for (const ev of events) {
130
- const evtType = ev['event_type'] ?? '';
131
- const stepNum = ev['step_number'];
132
- if (stepNum === null || stepNum === undefined)
133
- continue;
134
- if (!stepMap.has(stepNum))
135
- stepMap.set(stepNum, createStepData(stepNum));
136
- const sd = stepMap.get(stepNum);
137
- this.populateEvent(sd, evtType, ev, screenshotDir);
138
- }
139
- if (screenshotDir !== null) {
140
- for (const sd of stepMap.values())
141
- this.resolveScreenshots(sd, screenshotDir);
142
- }
143
- return Array.from(stepMap.values()).sort((a, b) => a.stepNumber - b.stepNumber);
144
- }
145
- populateEvent(sd, evtType, ev, screenshotDir) {
146
- const content = ev['content'] ?? '';
147
- const data = ev['data'] ?? {};
148
- const screenshotPath = ev['screenshot_path'];
149
- if (evtType === 'planner_observation' || evtType === 'planner_output') {
150
- if (screenshotPath) {
151
- const r = resolveScreenshotPath(screenshotPath, screenshotDir);
152
- if (r)
153
- sd.screenshots.push(r);
154
- }
155
- }
156
- else if (evtType === 'planner_thinking') {
157
- sd.thinking = content;
158
- }
159
- else if (evtType === 'planner_tool_call') {
160
- const args = data['arguments'] ?? {};
161
- const pfRaw = args['point'] ?? args['pos'] ?? {};
162
- const pf = normalizePoint(pfRaw);
163
- const et = sd.toolCall ?? {};
164
- const ea = et['arguments'] ?? {};
165
- const ma = { ...args };
166
- if (ea['point'])
167
- ma['point'] = ea['point'];
168
- else if (pf)
169
- ma['point'] = pf;
170
- sd.toolCall = { tool_name: et['tool_name'] || (data['tool_name'] ?? '') || '', arguments: ma };
171
- }
172
- else if (evtType === 'mcp_tool_start') {
173
- const mp = normalizePoint(data['point']);
174
- const et = sd.toolCall ?? {};
175
- const ea = et['arguments'] ?? {};
176
- const ma = { ...ea };
177
- if (mp)
178
- ma['point'] = mp;
179
- sd.toolCall = { tool_name: (data['tool_name'] ?? '') || et['tool_name'] || '', arguments: ma };
180
- if (screenshotPath) {
181
- const r = resolveScreenshotPath(screenshotPath, screenshotDir);
182
- if (r)
183
- sd.screenshots.push(r);
184
- }
185
- }
186
- else if (evtType === 'mcp_tool_end') {
187
- sd.toolResult = { tool_name: data['tool_name'] ?? '', result: data['result'] ?? '', raw_result: data['raw_result'] ?? {}, success: data['success'] ?? true };
188
- if (screenshotPath) {
189
- const r = resolveScreenshotPath(screenshotPath, screenshotDir);
190
- if (r)
191
- sd.screenshots.push(r);
192
- }
193
- }
194
- else if (evtType === 'model_action' || evtType === 'glm_action' || evtType === 'model_step_end' || evtType === 'glm_step_end') {
195
- if (screenshotPath) {
196
- const r = resolveScreenshotPath(screenshotPath, screenshotDir);
197
- if (r)
198
- sd.screenshots.push(r);
199
- }
200
- }
201
- }
202
- resolveScreenshots(sd, screenshotDir) {
203
- let candidates = [];
204
- try {
205
- candidates = fs.readdirSync(screenshotDir).filter(f => {
206
- const prefix = `step_${sd.stepNumber}_`;
207
- return (f.startsWith(prefix) && f.endsWith('.jpeg')) || f.endsWith('.png');
208
- }).map(f => path.join(screenshotDir, f));
209
- candidates.sort((a, b) => fs.statSync(a).mtimeMs - fs.statSync(b).mtimeMs);
210
- }
211
- catch { }
212
- const existing = new Set(sd.screenshots);
213
- for (const p of candidates) {
214
- if (!existing.has(p)) {
215
- sd.screenshots.push(p);
216
- existing.add(p);
217
- }
218
- }
219
- }
220
- extractStatusAndResult(data) {
221
- const events = data['events'] ?? [];
222
- let status = 'unknown';
223
- let resultText = '';
224
- for (let i = events.length - 1; i >= 0; i--) {
225
- const ev = events[i];
226
- if (ev['event_type'] === 'task_end') {
227
- const evData = ev['data'] ?? {};
228
- status = evData['status'] ?? '';
229
- resultText = ev['content'] ?? '';
230
- if (!status) {
231
- const cl = resultText.toLowerCase();
232
- if (cl.includes('failed') || cl.includes('fail'))
233
- status = 'failed';
234
- else if (cl.includes('pass'))
235
- status = 'pass';
236
- else
237
- status = 'unknown';
238
- }
239
- break;
240
- }
241
- }
242
- if (!resultText) {
243
- for (let i = events.length - 1; i >= 0; i--) {
244
- const ev = events[i];
245
- if (ev['event_type'] === 'planner_end') {
246
- const evData = ev['data'] ?? {};
247
- resultText = evData['output'] || (ev['content'] ?? '');
248
- break;
249
- }
250
- }
251
- }
252
- return [status, resultText];
253
- }
254
- }
255
- exports.DataLoader = DataLoader;
@@ -1,99 +0,0 @@
1
- "use strict";
2
- // Output guardrail: output validation + process validation.
3
- // Two guardrail functions:
4
- // 1. validateOutput: validate RootCauseResult structural integrity (category/reason/evidence/accuracy)
5
- // 2. validateProcess: validate analysis process soundness (screenshot_calls non-empty + claim consistency)
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SCREENSHOT_CLAIM_PATTERN = void 0;
8
- exports.validateOutput = validateOutput;
9
- exports.validateProcess = validateProcess;
10
- const logger_1 = require("../../../common/logger");
11
- const types_1 = require("./types");
12
- // Screenshot claim keyword regex: expressions in evidence that explicitly claim screenshot analysis
13
- exports.SCREENSHOT_CLAIM_PATTERN = /screenshot\s*shows|screenshot\s*indicates|screenshot\s*reveals|screenshot\s*confirms|seen\s*in\s*(?:the\s*)?screenshot|visible\s*in\s*(?:the\s*)?screenshot|from\s*screenshot|in\s*screenshot|screenshot\s*displays/i;
14
- // Effective top-level category codes (same as VALID_CATEGORY_LABELS)
15
- const VALID_CATEGORY_CODES = types_1.VALID_CATEGORY_LABELS;
16
- async function validateOutput(context, output) {
17
- // Validate RootCauseResult field integrity and validity:
18
- // - rootCauseCategory non-empty and in valid set
19
- // - rootCauseReason non-empty and length >= 20
20
- // - confidence in 0.0-1.0 range
21
- // - evidence list non-empty
22
- // - accuracy non-empty and in valid set (missing -> warning only, no tripwire)
23
- const issues = [];
24
- if (!output.rootCauseCategory) {
25
- issues.push('root_cause_category is empty');
26
- }
27
- else if (!VALID_CATEGORY_CODES.has(output.rootCauseCategory)) {
28
- issues.push(`root_cause_category '${output.rootCauseCategory}' is not in valid set ${[...VALID_CATEGORY_CODES].join(', ')}`);
29
- }
30
- const reasonTrimmed = (output.rootCauseReason ?? '').trim();
31
- if (!output.rootCauseReason || reasonTrimmed.length < 20) {
32
- issues.push(`root_cause_reason too short (current ${reasonTrimmed.length} chars, need >= 20)`);
33
- }
34
- if (output.confidence < 0.0 || output.confidence > 1.0) {
35
- issues.push(`confidence out of range (current ${output.confidence}, need 0.0-1.0)`);
36
- }
37
- if (!output.evidence || output.evidence.length === 0) {
38
- issues.push('evidence list is empty');
39
- }
40
- if (output.accuracy && !types_1.VALID_ACCURACY_VALUES.has(output.accuracy)) {
41
- issues.push(`accuracy '${output.accuracy}' is not in valid set ${[...types_1.VALID_ACCURACY_VALUES].join(', ')}`);
42
- }
43
- if (issues.length > 0) {
44
- const reason = issues.join('; ');
45
- logger_1.logger.warn(`[Guardrail] validateOutput tripwire: ${reason}`);
46
- return {
47
- tripwireTriggered: true,
48
- outputInfo: { reason },
49
- };
50
- }
51
- if (!output.accuracy) {
52
- logger_1.logger.warn('[Guardrail] validateOutput: accuracy field missing (allowed in precheck downgrade scenarios)');
53
- }
54
- return { tripwireTriggered: false, outputInfo: {} };
55
- }
56
- async function validateProcess(context, output) {
57
- // Validate analysis process soundness:
58
- // - when enable_multimodal=true, screenshot_calls must be non-empty (agent called the screenshot tool)
59
- // - evidence explicitly claiming screenshot analysis must reference steps present in screenshot_calls
60
- const config = context.config;
61
- if (config === null || config === undefined) {
62
- logger_1.logger.debug('[Guardrail] validateProcess: config not provided, skipping process check');
63
- return { tripwireTriggered: false, outputInfo: {} };
64
- }
65
- const issues = [];
66
- if (config.enableMultimodal && context.screenshotCalls.length === 0) {
67
- issues.push('enable_multimodal=true but get_step_screenshot was never called; call the screenshot tool at least once');
68
- }
69
- if (config.enableMultimodal && context.screenshotCalls.length > 0) {
70
- const screenshotStepSet = new Set(context.screenshotCalls);
71
- const fabricatedSteps = new Set();
72
- for (const ev of output.evidence) {
73
- if (!exports.SCREENSHOT_CLAIM_PATTERN.test(ev))
74
- continue;
75
- // Extract step numbers referenced in this evidence line
76
- const stepMatches = ev.matchAll(/step\s*(\d+)/gi);
77
- for (const m of stepMatches) {
78
- const num = parseInt(m[1], 10);
79
- if (!screenshotStepSet.has(num)) {
80
- fabricatedSteps.add(num);
81
- }
82
- }
83
- }
84
- if (fabricatedSteps.size > 0) {
85
- issues.push(`evidence claims screenshot analysis for steps ${[...fabricatedSteps].join(', ')} ` +
86
- `but these steps are not in screenshot_calls (${[...screenshotStepSet].join(', ')}); ` +
87
- `the screenshot analysis may be fabricated`);
88
- }
89
- }
90
- if (issues.length > 0) {
91
- const reason = issues.join('; ');
92
- logger_1.logger.warn(`[Guardrail] validateProcess tripwire: ${reason}`);
93
- return {
94
- tripwireTriggered: true,
95
- outputInfo: { reason },
96
- };
97
- }
98
- return { tripwireTriggered: false, outputInfo: {} };
99
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- // AnalyzerHooks: inject pending_images into the next LLM call as a user message.
3
- //
4
- // Some models (e.g. qwen) handle images in tool messages poorly, so get_step_screenshot
5
- // stashes images into context.pendingImages. Before each LLM call, pendingImages are
6
- // consumed (extended into the input as a user message) and cleared.
7
- //
8
- // In the TS port the agent loop consumes pendingImages directly when building the
9
- // LLMCaller call, so this class provides a helper to drain the pending queue.
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.AnalyzerHooks = void 0;
12
- const logger_1 = require("../../../common/logger");
13
- class AnalyzerHooks {
14
- // Drain pending images from the context, returning them for injection into the next call.
15
- drainPendingImages(context) {
16
- const pending = context.pendingImages;
17
- if (pending.length > 0) {
18
- const drained = pending.splice(0, pending.length);
19
- logger_1.logger.debug(`AnalyzerHooks: drained ${drained.length} pending image groups`);
20
- return drained;
21
- }
22
- return [];
23
- }
24
- // Reset the pending image queue (e.g. between retries).
25
- clearPendingImages(context) {
26
- if (context.pendingImages.length > 0) {
27
- context.pendingImages.length = 0;
28
- }
29
- }
30
- }
31
- exports.AnalyzerHooks = AnalyzerHooks;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- // Public entry point for the ReportAnalyzerAgent module.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.expandWithContext = exports.selectKeySteps = exports.MAIN_AGENT_PROMPT = exports.AnalyzerHooks = exports.getStepScreenshot = exports.parseMarkdownToDict = exports.parseRootCauseResult = exports.createPrecheckOutput = exports.createErrorOutput = exports.mapResultToOutput = exports.SCREENSHOT_CLAIM_PATTERN = exports.validateProcess = exports.validateOutput = exports.ROOT_CAUSE_SUB_CATEGORIES = exports.ROOT_CAUSE_CATEGORY_LABELS = exports.VALID_CATEGORY_LABELS = exports.VALID_ACCURACY_VALUES = exports.EVIDENCE_NONE = exports.EVIDENCE_MISSING = exports.EVIDENCE_PARTIAL = exports.EVIDENCE_COMPLETE = exports.CONSISTENCY_SEVERITY_ERROR = exports.CONSISTENCY_SEVERITY_WARNING = exports.CONSISTENCY_SEVERITY_INFO = exports.ANALYSIS_SUBDIR = exports.createRootCauseResult = exports.createAnalyzerContext = exports.resolveSubCategory = exports.AccuracyVerdict = exports.RootCauseCategory = exports.RootCauseClassification = exports.AnalyzerOutput = exports.ReportWriter = exports.DataLoader = exports.resolveModelConfig = exports.ReportAnalyzerAgent = void 0;
5
- var agent_1 = require("./agent");
6
- Object.defineProperty(exports, "ReportAnalyzerAgent", { enumerable: true, get: function () { return agent_1.ReportAnalyzerAgent; } });
7
- var config_1 = require("./config");
8
- Object.defineProperty(exports, "resolveModelConfig", { enumerable: true, get: function () { return config_1.resolveModelConfig; } });
9
- var data_loader_1 = require("./data_loader");
10
- Object.defineProperty(exports, "DataLoader", { enumerable: true, get: function () { return data_loader_1.DataLoader; } });
11
- var report_writer_1 = require("./report_writer");
12
- Object.defineProperty(exports, "ReportWriter", { enumerable: true, get: function () { return report_writer_1.ReportWriter; } });
13
- var types_1 = require("./types");
14
- Object.defineProperty(exports, "AnalyzerOutput", { enumerable: true, get: function () { return types_1.AnalyzerOutput; } });
15
- Object.defineProperty(exports, "RootCauseClassification", { enumerable: true, get: function () { return types_1.RootCauseClassification; } });
16
- Object.defineProperty(exports, "RootCauseCategory", { enumerable: true, get: function () { return types_1.RootCauseCategory; } });
17
- Object.defineProperty(exports, "AccuracyVerdict", { enumerable: true, get: function () { return types_1.AccuracyVerdict; } });
18
- Object.defineProperty(exports, "resolveSubCategory", { enumerable: true, get: function () { return types_1.resolveSubCategory; } });
19
- Object.defineProperty(exports, "createAnalyzerContext", { enumerable: true, get: function () { return types_1.createAnalyzerContext; } });
20
- Object.defineProperty(exports, "createRootCauseResult", { enumerable: true, get: function () { return types_1.createRootCauseResult; } });
21
- Object.defineProperty(exports, "ANALYSIS_SUBDIR", { enumerable: true, get: function () { return types_1.ANALYSIS_SUBDIR; } });
22
- Object.defineProperty(exports, "CONSISTENCY_SEVERITY_INFO", { enumerable: true, get: function () { return types_1.CONSISTENCY_SEVERITY_INFO; } });
23
- Object.defineProperty(exports, "CONSISTENCY_SEVERITY_WARNING", { enumerable: true, get: function () { return types_1.CONSISTENCY_SEVERITY_WARNING; } });
24
- Object.defineProperty(exports, "CONSISTENCY_SEVERITY_ERROR", { enumerable: true, get: function () { return types_1.CONSISTENCY_SEVERITY_ERROR; } });
25
- Object.defineProperty(exports, "EVIDENCE_COMPLETE", { enumerable: true, get: function () { return types_1.EVIDENCE_COMPLETE; } });
26
- Object.defineProperty(exports, "EVIDENCE_PARTIAL", { enumerable: true, get: function () { return types_1.EVIDENCE_PARTIAL; } });
27
- Object.defineProperty(exports, "EVIDENCE_MISSING", { enumerable: true, get: function () { return types_1.EVIDENCE_MISSING; } });
28
- Object.defineProperty(exports, "EVIDENCE_NONE", { enumerable: true, get: function () { return types_1.EVIDENCE_NONE; } });
29
- Object.defineProperty(exports, "VALID_ACCURACY_VALUES", { enumerable: true, get: function () { return types_1.VALID_ACCURACY_VALUES; } });
30
- Object.defineProperty(exports, "VALID_CATEGORY_LABELS", { enumerable: true, get: function () { return types_1.VALID_CATEGORY_LABELS; } });
31
- Object.defineProperty(exports, "ROOT_CAUSE_CATEGORY_LABELS", { enumerable: true, get: function () { return types_1.ROOT_CAUSE_CATEGORY_LABELS; } });
32
- Object.defineProperty(exports, "ROOT_CAUSE_SUB_CATEGORIES", { enumerable: true, get: function () { return types_1.ROOT_CAUSE_SUB_CATEGORIES; } });
33
- var guardrails_1 = require("./guardrails");
34
- Object.defineProperty(exports, "validateOutput", { enumerable: true, get: function () { return guardrails_1.validateOutput; } });
35
- Object.defineProperty(exports, "validateProcess", { enumerable: true, get: function () { return guardrails_1.validateProcess; } });
36
- Object.defineProperty(exports, "SCREENSHOT_CLAIM_PATTERN", { enumerable: true, get: function () { return guardrails_1.SCREENSHOT_CLAIM_PATTERN; } });
37
- var mapping_1 = require("./mapping");
38
- Object.defineProperty(exports, "mapResultToOutput", { enumerable: true, get: function () { return mapping_1.mapResultToOutput; } });
39
- Object.defineProperty(exports, "createErrorOutput", { enumerable: true, get: function () { return mapping_1.createErrorOutput; } });
40
- Object.defineProperty(exports, "createPrecheckOutput", { enumerable: true, get: function () { return mapping_1.createPrecheckOutput; } });
41
- var parse_1 = require("./parse");
42
- Object.defineProperty(exports, "parseRootCauseResult", { enumerable: true, get: function () { return parse_1.parseRootCauseResult; } });
43
- Object.defineProperty(exports, "parseMarkdownToDict", { enumerable: true, get: function () { return parse_1.parseMarkdownToDict; } });
44
- var tools_1 = require("./tools");
45
- Object.defineProperty(exports, "getStepScreenshot", { enumerable: true, get: function () { return tools_1.getStepScreenshot; } });
46
- var hooks_1 = require("./hooks");
47
- Object.defineProperty(exports, "AnalyzerHooks", { enumerable: true, get: function () { return hooks_1.AnalyzerHooks; } });
48
- var prompt_1 = require("./prompt");
49
- Object.defineProperty(exports, "MAIN_AGENT_PROMPT", { enumerable: true, get: function () { return prompt_1.MAIN_AGENT_PROMPT; } });
50
- var key_steps_builder_1 = require("./key_steps_builder");
51
- Object.defineProperty(exports, "selectKeySteps", { enumerable: true, get: function () { return key_steps_builder_1.selectKeySteps; } });
52
- Object.defineProperty(exports, "expandWithContext", { enumerable: true, get: function () { return key_steps_builder_1.expandWithContext; } });
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectKeySteps = selectKeySteps;
4
- exports.expandWithContext = expandWithContext;
5
- function selectKeySteps(stepVerdicts, maxKeySteps = 5) {
6
- const scored = [];
7
- for (const sv of stepVerdicts) {
8
- let score = 0;
9
- if (sv.overallStepVerdict === 'critical_failure') {
10
- score += 10;
11
- }
12
- else if (sv.overallStepVerdict === 'problematic') {
13
- score += 5;
14
- }
15
- if (sv.needsScreenshotRefine) {
16
- score += 3;
17
- }
18
- if (sv.thinkingCorrect === 'incorrect') {
19
- score += 2;
20
- }
21
- if (sv === stepVerdicts[stepVerdicts.length - 1] && sv.overallStepVerdict !== 'correct') {
22
- score += 4;
23
- }
24
- scored.push({ score, step: sv.stepNumber });
25
- }
26
- scored.sort((a, b) => b.score - a.score);
27
- const keySteps = scored.slice(0, maxKeySteps).filter((s) => s.score > 0).map((s) => s.step);
28
- return keySteps.sort((a, b) => a - b);
29
- }
30
- function expandWithContext(keySteps, totalSteps) {
31
- const expanded = new Set();
32
- for (const s of keySteps) {
33
- expanded.add(s);
34
- if (s - 1 >= 1) {
35
- expanded.add(s - 1);
36
- }
37
- if (s + 1 <= totalSteps) {
38
- expanded.add(s + 1);
39
- }
40
- }
41
- return Array.from(expanded).sort((a, b) => a - b);
42
- }
@@ -1,133 +0,0 @@
1
- "use strict";
2
- // RootCauseResult -> AnalyzerOutput mapping functions.
3
- // Convert the agent's internal RootCauseResult into the external AnalyzerOutput interface.
4
- // Keeps AnalyzerOutput.toDict() format unchanged (consumed by ReportWriter).
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapResultToOutput = mapResultToOutput;
7
- exports.createErrorOutput = createErrorOutput;
8
- exports.createPrecheckOutput = createPrecheckOutput;
9
- const logger_1 = require("../../../common/logger");
10
- const types_1 = require("./types");
11
- // category string -> RootCauseCategory enum mapping (English label keys)
12
- const _CATEGORY_STR_TO_ENUM = {
13
- [types_1.RootCauseCategory.APP_ISSUE]: types_1.RootCauseCategory.APP_ISSUE,
14
- [types_1.RootCauseCategory.AGENT_ISSUE]: types_1.RootCauseCategory.AGENT_ISSUE,
15
- [types_1.RootCauseCategory.CASE_ISSUE]: types_1.RootCauseCategory.CASE_ISSUE,
16
- [types_1.RootCauseCategory.ENV_ISSUE]: types_1.RootCauseCategory.ENV_ISSUE,
17
- [types_1.RootCauseCategory.NO_ISSUE]: types_1.RootCauseCategory.NO_ISSUE,
18
- '应用问题': types_1.RootCauseCategory.APP_ISSUE,
19
- 'Agent问题': types_1.RootCauseCategory.AGENT_ISSUE,
20
- '用例问题': types_1.RootCauseCategory.CASE_ISSUE,
21
- '环境问题': types_1.RootCauseCategory.ENV_ISSUE,
22
- '无问题': types_1.RootCauseCategory.NO_ISSUE,
23
- };
24
- // Compute evidence completeness stats (checkpoints removed; based on evidence count).
25
- // - checkpoints_verified_count: evidence count
26
- // - pass_count: 0 (no longer distinguishing pass/fail checkpoints)
27
- // - missing_evidence_count: 0
28
- // - summary: complete if evidence present, none otherwise
29
- function computeEvidenceCompleteness(evidence) {
30
- const total = evidence.length;
31
- const summary = total === 0 ? types_1.EVIDENCE_NONE : types_1.EVIDENCE_COMPLETE;
32
- return {
33
- checkpoints_verified_count: total,
34
- pass_count: 0,
35
- missing_evidence_count: 0,
36
- summary,
37
- };
38
- }
39
- // Map RootCauseResult to AnalyzerOutput (external interface).
40
- function mapResultToOutput(result, reportData, modelUsed, duration, llmCalls) {
41
- // root_cause mapping: string -> RootCauseCategory enum -> RootCauseClassification
42
- const categoryEnum = _CATEGORY_STR_TO_ENUM[result.rootCauseCategory] ?? types_1.RootCauseCategory.AGENT_ISSUE;
43
- const rootCause = new types_1.RootCauseClassification({
44
- category: categoryEnum,
45
- subCategory: result.rootCauseSubCategory,
46
- reason: result.rootCauseReason,
47
- confidence: result.confidence,
48
- evidence: result.evidence,
49
- accuracy: result.accuracy,
50
- });
51
- // accuracy mapping: fully AI-decided, use LLM output directly; empty if not provided
52
- const accuracy = result.accuracy || '';
53
- const evidenceCompleteness = computeEvidenceCompleteness(result.evidence);
54
- const output = new types_1.AnalyzerOutput({
55
- taskDescription: reportData.task,
56
- taskIntent: result.taskIntent,
57
- taskResultStatus: reportData.status,
58
- rootCause,
59
- summary: result.summary,
60
- improvementSuggestions: result.improvementSuggestions,
61
- reverseVerification: result.reverseVerification,
62
- analysisTime: new Date().toISOString(),
63
- modelUsed,
64
- analysisDurationSeconds: duration,
65
- totalLlmCalls: llmCalls,
66
- accuracy,
67
- checkpoints: [], // checkpoints removed, kept empty for compatibility
68
- evidenceCompleteness,
69
- });
70
- logger_1.logger.info(`[AnalyzerAgent] mapResultToOutput: category=${result.rootCauseCategory}, ` +
71
- `sub=${result.rootCauseSubCategory}, accuracy=${accuracy}`);
72
- return output;
73
- }
74
- // Create an error downgrade output (used when retries are exhausted or an exception occurs).
75
- function createErrorOutput(reportDir, errorMsg, modelUsed, duration) {
76
- return new types_1.AnalyzerOutput({
77
- taskDescription: reportDir,
78
- taskIntent: 'Analysis retries exhausted',
79
- taskResultStatus: 'error',
80
- rootCause: null,
81
- summary: `All 3 retries failed: ${errorMsg}`,
82
- improvementSuggestions: [],
83
- analysisTime: new Date().toISOString(),
84
- modelUsed,
85
- analysisDurationSeconds: duration,
86
- totalLlmCalls: 0,
87
- accuracy: 'Inconclusive',
88
- evidenceCompleteness: {
89
- checkpoints_verified_count: 0,
90
- pass_count: 0,
91
- missing_evidence_count: 0,
92
- summary: types_1.EVIDENCE_NONE,
93
- },
94
- consistencyNotes: [
95
- {
96
- rule_id: 'retry_exceeded',
97
- severity: types_1.CONSISTENCY_SEVERITY_ERROR,
98
- message: `All 3 retries failed: ${errorMsg.slice(0, 100)}`,
99
- },
100
- ],
101
- });
102
- }
103
- // Build a precheck downgrade AnalyzerOutput.
104
- // When precheck conditions hit (no screenshots / no judgment block / no steps / abnormal status),
105
- // judge "Inconclusive" -- the report data is incomplete, don't force-guess a root cause.
106
- function createPrecheckOutput(reportData, reason, modelUsed, duration) {
107
- return new types_1.AnalyzerOutput({
108
- taskDescription: reportData.task,
109
- taskIntent: 'Report data incomplete, cannot analyze',
110
- taskResultStatus: reportData.status,
111
- rootCause: null,
112
- summary: `Precheck downgrade: ${reason}`,
113
- improvementSuggestions: [],
114
- analysisTime: new Date().toISOString(),
115
- modelUsed,
116
- analysisDurationSeconds: duration,
117
- totalLlmCalls: 0,
118
- accuracy: 'Inconclusive',
119
- evidenceCompleteness: {
120
- checkpoints_verified_count: 0,
121
- pass_count: 0,
122
- missing_evidence_count: 0,
123
- summary: types_1.EVIDENCE_NONE,
124
- },
125
- consistencyNotes: [
126
- {
127
- rule_id: 'precheck',
128
- severity: types_1.CONSISTENCY_SEVERITY_WARNING,
129
- message: `Precheck downgrade: ${reason.slice(0, 100)}`,
130
- },
131
- ],
132
- });
133
- }