@autotest/agent 0.0.1 → 0.0.3

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 (248) hide show
  1. package/README.md +43 -27
  2. package/dist/api/agent_api.d.ts +1 -1
  3. package/dist/api/agent_api.js +555 -0
  4. package/dist/api/autotest_agent.d.ts +0 -1
  5. package/dist/api/autotest_agent.js +205 -0
  6. package/dist/api/types.d.ts +0 -1
  7. package/dist/api/types.js +11 -0
  8. package/dist/autotest-cli.d.ts +1 -1
  9. package/dist/autotest-cli.js +391 -0
  10. package/dist/common/case_manager.d.ts +0 -1
  11. package/dist/common/case_manager.js +91 -0
  12. package/dist/common/collect_case.d.ts +0 -1
  13. package/dist/common/collect_case.js +128 -0
  14. package/dist/common/common_errors.d.ts +0 -1
  15. package/dist/common/common_errors.js +66 -0
  16. package/dist/common/config/config_validator.d.ts +0 -1
  17. package/dist/common/config/config_validator.js +28 -0
  18. package/dist/common/config/manager.d.ts +0 -1
  19. package/dist/common/config/manager.js +257 -0
  20. package/dist/common/config/output.d.ts +0 -1
  21. package/dist/common/config/output.js +59 -0
  22. package/dist/common/config/types.d.ts +2243 -2244
  23. package/dist/common/config/types.js +184 -0
  24. package/dist/common/dfx/client_factory.d.ts +0 -1
  25. package/dist/common/dfx/client_factory.js +62 -0
  26. package/dist/common/dfx/context.d.ts +0 -1
  27. package/dist/common/dfx/context.js +23 -0
  28. package/dist/common/dfx/index.d.ts +0 -1
  29. package/dist/common/dfx/index.js +15 -0
  30. package/dist/common/dfx/recorder.d.ts +0 -1
  31. package/dist/common/dfx/recorder.js +191 -0
  32. package/dist/common/dfx/recording_fetch.d.ts +0 -1
  33. package/dist/common/dfx/recording_fetch.js +228 -0
  34. package/dist/common/dfx/source.d.ts +0 -1
  35. package/dist/common/dfx/source.js +13 -0
  36. package/dist/common/image_cacher.d.ts +0 -1
  37. package/dist/common/image_cacher.js +36 -0
  38. package/dist/common/image_helper.d.ts +0 -1
  39. package/dist/common/image_helper.js +128 -0
  40. package/dist/common/image_similarity.d.ts +0 -1
  41. package/dist/common/image_similarity.js +171 -0
  42. package/dist/common/llm_cache/cache_transport.d.ts +2 -1
  43. package/dist/common/llm_cache/cache_transport.js +102 -0
  44. package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
  45. package/dist/common/llm_cache/prompt_cache.js +113 -0
  46. package/dist/common/logger.d.ts +0 -1
  47. package/dist/common/logger.js +158 -0
  48. package/dist/common/model/custom_model.d.ts +0 -1
  49. package/dist/common/model/custom_model.js +467 -0
  50. package/dist/common/model/index.d.ts +0 -1
  51. package/dist/common/model/index.js +5 -0
  52. package/dist/common/path_utils.d.ts +0 -1
  53. package/dist/common/path_utils.js +81 -0
  54. package/dist/common/result_parser.d.ts +0 -1
  55. package/dist/common/result_parser.js +49 -0
  56. package/dist/common/usage/token_usage.d.ts +0 -1
  57. package/dist/common/usage/token_usage.js +117 -0
  58. package/dist/common/utils.d.ts +0 -1
  59. package/dist/common/utils.js +125 -0
  60. package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
  61. package/dist/core/agent/layered_agent/ability_helper.js +125 -0
  62. package/dist/core/agent/layered_agent/agent.d.ts +0 -1
  63. package/dist/core/agent/layered_agent/agent.js +37 -0
  64. package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
  65. package/dist/core/agent/layered_agent/agent_registry.js +75 -0
  66. package/dist/core/agent/layered_agent/decision.d.ts +0 -1
  67. package/dist/core/agent/layered_agent/decision.js +478 -0
  68. package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
  69. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +155 -0
  70. package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
  71. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +41 -0
  72. package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
  73. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +112 -0
  74. package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
  75. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +207 -0
  76. package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
  77. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +241 -0
  78. package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
  79. package/dist/core/agent/layered_agent/execute_agent/i18n.js +34 -0
  80. package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
  81. package/dist/core/agent/layered_agent/execute_agent/index.js +67 -0
  82. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
  83. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +316 -0
  84. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +0 -1
  85. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +154 -0
  86. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
  87. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +243 -0
  88. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
  89. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +139 -0
  90. package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
  91. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +9 -0
  92. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
  93. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +94 -0
  94. package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +0 -1
  95. package/dist/core/agent/layered_agent/execute_agent/prompts.js +109 -0
  96. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
  97. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +33 -0
  98. package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
  99. package/dist/core/agent/layered_agent/execute_agent/utils.js +52 -0
  100. package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
  101. package/dist/core/agent/report_analyzer_agent/agent.js +565 -0
  102. package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
  103. package/dist/core/agent/report_analyzer_agent/config.js +22 -0
  104. package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
  105. package/dist/core/agent/report_analyzer_agent/data_loader.js +255 -0
  106. package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
  107. package/dist/core/agent/report_analyzer_agent/guardrails.js +99 -0
  108. package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
  109. package/dist/core/agent/report_analyzer_agent/hooks.js +31 -0
  110. package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
  111. package/dist/core/agent/report_analyzer_agent/index.js +52 -0
  112. package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
  113. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +42 -0
  114. package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
  115. package/dist/core/agent/report_analyzer_agent/mapping.js +133 -0
  116. package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
  117. package/dist/core/agent/report_analyzer_agent/parse.js +375 -0
  118. package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
  119. package/dist/core/agent/report_analyzer_agent/prompt.js +300 -0
  120. package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
  121. package/dist/core/agent/report_analyzer_agent/report_writer.js +558 -0
  122. package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
  123. package/dist/core/agent/report_analyzer_agent/tools.js +150 -0
  124. package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
  125. package/dist/core/agent/report_analyzer_agent/types.js +274 -0
  126. package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
  127. package/dist/core/agent/rewrite_agent/agent.js +209 -0
  128. package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
  129. package/dist/core/agent/rewrite_agent/guardrails.js +95 -0
  130. package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
  131. package/dist/core/agent/rewrite_agent/mapping.js +56 -0
  132. package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
  133. package/dist/core/agent/rewrite_agent/parse.js +121 -0
  134. package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
  135. package/dist/core/agent/rewrite_agent/types.js +37 -0
  136. package/dist/core/agent/single_agent/agent.d.ts +0 -1
  137. package/dist/core/agent/single_agent/agent.js +798 -0
  138. package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
  139. package/dist/core/agent/single_agent/hook_manager.js +60 -0
  140. package/dist/core/agent/single_agent/hooks.d.ts +0 -1
  141. package/dist/core/agent/single_agent/hooks.js +288 -0
  142. package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
  143. package/dist/core/agent/single_agent/image_utils.js +159 -0
  144. package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
  145. package/dist/core/agent/single_agent/scroll_search_agent.js +376 -0
  146. package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
  147. package/dist/core/agent/single_agent/subagent_manager.js +73 -0
  148. package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
  149. package/dist/core/agent/single_agent/tool_recorder_hook.js +42 -0
  150. package/dist/core/agent/types.d.ts +0 -1
  151. package/dist/core/agent/types.js +2 -0
  152. package/dist/core/agent/utils/message_builder.d.ts +0 -1
  153. package/dist/core/agent/utils/message_builder.js +138 -0
  154. package/dist/core/device/device_protocol.d.ts +0 -1
  155. package/dist/core/device/device_protocol.js +2 -0
  156. package/dist/core/device/hdc/apps.d.ts +0 -1
  157. package/dist/core/device/hdc/apps.js +437 -0
  158. package/dist/core/device/hdc/device.d.ts +0 -1
  159. package/dist/core/device/hdc/device.js +219 -0
  160. package/dist/core/device/hdc/index.d.ts +0 -1
  161. package/dist/core/device/hdc/index.js +31 -0
  162. package/dist/core/device/hdc/input.d.ts +0 -1
  163. package/dist/core/device/hdc/input.js +74 -0
  164. package/dist/core/device/hdc/screenshot.d.ts +0 -1
  165. package/dist/core/device/hdc/screenshot.js +171 -0
  166. package/dist/core/device/index.d.ts +0 -1
  167. package/dist/core/device/index.js +70 -0
  168. package/dist/core/device/types.d.ts +0 -1
  169. package/dist/core/device/types.js +2 -0
  170. package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
  171. package/dist/core/knowledge/knowledge_manager.js +70 -0
  172. package/dist/core/knowledge/vectordb.d.ts +0 -1
  173. package/dist/core/knowledge/vectordb.js +283 -0
  174. package/dist/core/mcp/adapter_factory.d.ts +0 -1
  175. package/dist/core/mcp/adapter_factory.js +99 -0
  176. package/dist/core/mcp/android_adapter.d.ts +1 -2
  177. package/dist/core/mcp/android_adapter.js +286 -0
  178. package/dist/core/mcp/base_adapter.d.ts +0 -1
  179. package/dist/core/mcp/base_adapter.js +86 -0
  180. package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
  181. package/dist/core/mcp/harmony_hdc_adapter.js +782 -0
  182. package/dist/core/mcp/ios_adapter.d.ts +1 -2
  183. package/dist/core/mcp/ios_adapter.js +286 -0
  184. package/dist/core/mcp/local_tools.d.ts +0 -1
  185. package/dist/core/mcp/local_tools.js +41 -0
  186. package/dist/core/mcp/mcp_tools.d.ts +0 -1
  187. package/dist/core/mcp/mcp_tools.js +382 -0
  188. package/dist/core/mcp/types.d.ts +0 -1
  189. package/dist/core/mcp/types.js +6 -0
  190. package/dist/core/memory/compressed_session.d.ts +0 -1
  191. package/dist/core/memory/compressed_session.js +182 -0
  192. package/dist/core/memory/context_compressor.d.ts +0 -1
  193. package/dist/core/memory/context_compressor.js +176 -0
  194. package/dist/core/memory/index.d.ts +0 -1
  195. package/dist/core/memory/index.js +22 -0
  196. package/dist/core/memory/memory_manager.d.ts +0 -1
  197. package/dist/core/memory/memory_manager.js +28 -0
  198. package/dist/core/memory/reflector.d.ts +0 -1
  199. package/dist/core/memory/reflector.js +95 -0
  200. package/dist/core/memory/session_factory.d.ts +0 -1
  201. package/dist/core/memory/session_factory.js +29 -0
  202. package/dist/core/memory/tool_player.d.ts +0 -1
  203. package/dist/core/memory/tool_player.js +225 -0
  204. package/dist/core/memory/tool_recorder.d.ts +0 -1
  205. package/dist/core/memory/tool_recorder.js +126 -0
  206. package/dist/core/preprocessor/task_splitter.d.ts +0 -1
  207. package/dist/core/preprocessor/task_splitter.js +112 -0
  208. package/dist/core/prompt/prompt_loader.d.ts +0 -1
  209. package/dist/core/prompt/prompt_loader.js +313 -0
  210. package/dist/core/skill/skill_manager.d.ts +0 -1
  211. package/dist/core/skill/skill_manager.js +299 -0
  212. package/dist/data_types/action.d.ts +0 -1
  213. package/dist/data_types/action.js +2 -0
  214. package/dist/data_types/agent.d.ts +0 -1
  215. package/dist/data_types/agent.js +2 -0
  216. package/dist/data_types/device.d.ts +0 -1
  217. package/dist/data_types/device.js +2 -0
  218. package/dist/data_types/index.d.ts +0 -1
  219. package/dist/data_types/index.js +6 -0
  220. package/dist/data_types/report.d.ts +0 -1
  221. package/dist/data_types/report.js +6 -0
  222. package/dist/data_types/task.d.ts +0 -1
  223. package/dist/data_types/task.js +2 -0
  224. package/dist/index.d.ts +1 -2
  225. package/dist/index.js +164 -1
  226. package/dist/loop/cli.d.ts +0 -1
  227. package/dist/loop/cli.js +127 -0
  228. package/dist/loop/orchestrator.d.ts +0 -1
  229. package/dist/loop/orchestrator.js +314 -0
  230. package/dist/loop/result_writer.d.ts +0 -1
  231. package/dist/loop/result_writer.js +260 -0
  232. package/dist/loop/types.d.ts +0 -1
  233. package/dist/loop/types.js +82 -0
  234. package/dist/mcp-server/server.d.ts +0 -1
  235. package/dist/mcp-server/server.js +341 -0
  236. package/dist/mcp-server/types.d.ts +283 -118
  237. package/dist/mcp-server/types.js +202 -0
  238. package/dist/reporter/batch_summary.d.ts +0 -1
  239. package/dist/reporter/batch_summary.js +197 -0
  240. package/dist/reporter/generator.d.ts +0 -1
  241. package/dist/reporter/generator.js +772 -0
  242. package/dist/reporter/types.d.ts +14 -15
  243. package/dist/reporter/types.js +44 -0
  244. package/dist/tools/batch_runner.d.ts +1 -1
  245. package/dist/tools/batch_runner.js +731 -0
  246. package/package.json +5 -3
  247. package/dist/common/config/config.yaml +0 -113
  248. package/dist/hypium_generator/generator.d.ts +0 -38
@@ -0,0 +1,255 @@
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;
@@ -6,4 +6,3 @@ export interface GuardrailResult {
6
6
  }
7
7
  export declare function validateOutput(context: AnalyzerContext, output: RootCauseResult): Promise<GuardrailResult>;
8
8
  export declare function validateProcess(context: AnalyzerContext, output: RootCauseResult): Promise<GuardrailResult>;
9
- //# sourceMappingURL=guardrails.d.ts.map
@@ -0,0 +1,99 @@
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
+ }
@@ -3,4 +3,3 @@ export declare class AnalyzerHooks {
3
3
  drainPendingImages(context: AnalyzerContext): PendingImage[];
4
4
  clearPendingImages(context: AnalyzerContext): void;
5
5
  }
6
- //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1,31 @@
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;
@@ -14,4 +14,3 @@ export type { ScreenshotToolResult } from './tools';
14
14
  export { AnalyzerHooks } from './hooks';
15
15
  export { MAIN_AGENT_PROMPT } from './prompt';
16
16
  export { selectKeySteps, expandWithContext, type StepVerdict } from './key_steps_builder';
17
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,52 @@
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; } });
@@ -6,4 +6,3 @@ export interface StepVerdict {
6
6
  }
7
7
  export declare function selectKeySteps(stepVerdicts: StepVerdict[], maxKeySteps?: number): number[];
8
8
  export declare function expandWithContext(keySteps: number[], totalSteps: number): number[];
9
- //# sourceMappingURL=key_steps_builder.d.ts.map
@@ -0,0 +1,42 @@
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
+ }
@@ -3,4 +3,3 @@ import type { ReportData } from './data_loader';
3
3
  export declare function mapResultToOutput(result: RootCauseResult, reportData: ReportData, modelUsed: string, duration: number, llmCalls: number): AnalyzerOutput;
4
4
  export declare function createErrorOutput(reportDir: string, errorMsg: string, modelUsed: string, duration: number): AnalyzerOutput;
5
5
  export declare function createPrecheckOutput(reportData: ReportData, reason: string, modelUsed: string, duration: number): AnalyzerOutput;
6
- //# sourceMappingURL=mapping.d.ts.map
@@ -0,0 +1,133 @@
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
+ }
@@ -1,4 +1,3 @@
1
1
  import { type RootCauseResult } from './types';
2
2
  export declare function parseMarkdownToDict(text: string): Record<string, unknown> | null;
3
3
  export declare function parseRootCauseResult(text: string): RootCauseResult | null;
4
- //# sourceMappingURL=parse.d.ts.map