@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.
- package/README.md +43 -27
- package/dist/api/agent_api.d.ts +1 -1
- package/dist/api/agent_api.js +555 -0
- package/dist/api/autotest_agent.d.ts +0 -1
- package/dist/api/autotest_agent.js +205 -0
- package/dist/api/types.d.ts +0 -1
- package/dist/api/types.js +11 -0
- package/dist/autotest-cli.d.ts +1 -1
- package/dist/autotest-cli.js +391 -0
- package/dist/common/case_manager.d.ts +0 -1
- package/dist/common/case_manager.js +91 -0
- package/dist/common/collect_case.d.ts +0 -1
- package/dist/common/collect_case.js +128 -0
- package/dist/common/common_errors.d.ts +0 -1
- package/dist/common/common_errors.js +66 -0
- package/dist/common/config/config_validator.d.ts +0 -1
- package/dist/common/config/config_validator.js +28 -0
- package/dist/common/config/manager.d.ts +0 -1
- package/dist/common/config/manager.js +257 -0
- package/dist/common/config/output.d.ts +0 -1
- package/dist/common/config/output.js +59 -0
- package/dist/common/config/types.d.ts +2243 -2244
- package/dist/common/config/types.js +184 -0
- package/dist/common/dfx/client_factory.d.ts +0 -1
- package/dist/common/dfx/client_factory.js +62 -0
- package/dist/common/dfx/context.d.ts +0 -1
- package/dist/common/dfx/context.js +23 -0
- package/dist/common/dfx/index.d.ts +0 -1
- package/dist/common/dfx/index.js +15 -0
- package/dist/common/dfx/recorder.d.ts +0 -1
- package/dist/common/dfx/recorder.js +191 -0
- package/dist/common/dfx/recording_fetch.d.ts +0 -1
- package/dist/common/dfx/recording_fetch.js +228 -0
- package/dist/common/dfx/source.d.ts +0 -1
- package/dist/common/dfx/source.js +13 -0
- package/dist/common/image_cacher.d.ts +0 -1
- package/dist/common/image_cacher.js +36 -0
- package/dist/common/image_helper.d.ts +0 -1
- package/dist/common/image_helper.js +128 -0
- package/dist/common/image_similarity.d.ts +0 -1
- package/dist/common/image_similarity.js +171 -0
- package/dist/common/llm_cache/cache_transport.d.ts +2 -1
- package/dist/common/llm_cache/cache_transport.js +102 -0
- package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
- package/dist/common/llm_cache/prompt_cache.js +113 -0
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +158 -0
- package/dist/common/model/custom_model.d.ts +0 -1
- package/dist/common/model/custom_model.js +467 -0
- package/dist/common/model/index.d.ts +0 -1
- package/dist/common/model/index.js +5 -0
- package/dist/common/path_utils.d.ts +0 -1
- package/dist/common/path_utils.js +81 -0
- package/dist/common/result_parser.d.ts +0 -1
- package/dist/common/result_parser.js +49 -0
- package/dist/common/usage/token_usage.d.ts +0 -1
- package/dist/common/usage/token_usage.js +117 -0
- package/dist/common/utils.d.ts +0 -1
- package/dist/common/utils.js +125 -0
- package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
- package/dist/core/agent/layered_agent/ability_helper.js +125 -0
- package/dist/core/agent/layered_agent/agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent.js +37 -0
- package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent_registry.js +75 -0
- package/dist/core/agent/layered_agent/decision.d.ts +0 -1
- package/dist/core/agent/layered_agent/decision.js +478 -0
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +155 -0
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +41 -0
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +112 -0
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +207 -0
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +241 -0
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +34 -0
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.js +67 -0
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +316 -0
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +154 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +243 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +139 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +9 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +94 -0
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +109 -0
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +33 -0
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.js +52 -0
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.js +565 -0
- package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/config.js +22 -0
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.js +255 -0
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.js +99 -0
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.js +31 -0
- package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/index.js +52 -0
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +42 -0
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.js +133 -0
- package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.js +375 -0
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js +300 -0
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.js +558 -0
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.js +150 -0
- package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/types.js +274 -0
- package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/agent.js +209 -0
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.js +95 -0
- package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/mapping.js +56 -0
- package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/parse.js +121 -0
- package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/types.js +37 -0
- package/dist/core/agent/single_agent/agent.d.ts +0 -1
- package/dist/core/agent/single_agent/agent.js +798 -0
- package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/hook_manager.js +60 -0
- package/dist/core/agent/single_agent/hooks.d.ts +0 -1
- package/dist/core/agent/single_agent/hooks.js +288 -0
- package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
- package/dist/core/agent/single_agent/image_utils.js +159 -0
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.js +376 -0
- package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/subagent_manager.js +73 -0
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.js +42 -0
- package/dist/core/agent/types.d.ts +0 -1
- package/dist/core/agent/types.js +2 -0
- package/dist/core/agent/utils/message_builder.d.ts +0 -1
- package/dist/core/agent/utils/message_builder.js +138 -0
- package/dist/core/device/device_protocol.d.ts +0 -1
- package/dist/core/device/device_protocol.js +2 -0
- package/dist/core/device/hdc/apps.d.ts +0 -1
- package/dist/core/device/hdc/apps.js +437 -0
- package/dist/core/device/hdc/device.d.ts +0 -1
- package/dist/core/device/hdc/device.js +219 -0
- package/dist/core/device/hdc/index.d.ts +0 -1
- package/dist/core/device/hdc/index.js +31 -0
- package/dist/core/device/hdc/input.d.ts +0 -1
- package/dist/core/device/hdc/input.js +74 -0
- package/dist/core/device/hdc/screenshot.d.ts +0 -1
- package/dist/core/device/hdc/screenshot.js +171 -0
- package/dist/core/device/index.d.ts +0 -1
- package/dist/core/device/index.js +70 -0
- package/dist/core/device/types.d.ts +0 -1
- package/dist/core/device/types.js +2 -0
- package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
- package/dist/core/knowledge/knowledge_manager.js +70 -0
- package/dist/core/knowledge/vectordb.d.ts +0 -1
- package/dist/core/knowledge/vectordb.js +283 -0
- package/dist/core/mcp/adapter_factory.d.ts +0 -1
- package/dist/core/mcp/adapter_factory.js +99 -0
- package/dist/core/mcp/android_adapter.d.ts +1 -2
- package/dist/core/mcp/android_adapter.js +286 -0
- package/dist/core/mcp/base_adapter.d.ts +0 -1
- package/dist/core/mcp/base_adapter.js +86 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
- package/dist/core/mcp/harmony_hdc_adapter.js +782 -0
- package/dist/core/mcp/ios_adapter.d.ts +1 -2
- package/dist/core/mcp/ios_adapter.js +286 -0
- package/dist/core/mcp/local_tools.d.ts +0 -1
- package/dist/core/mcp/local_tools.js +41 -0
- package/dist/core/mcp/mcp_tools.d.ts +0 -1
- package/dist/core/mcp/mcp_tools.js +382 -0
- package/dist/core/mcp/types.d.ts +0 -1
- package/dist/core/mcp/types.js +6 -0
- package/dist/core/memory/compressed_session.d.ts +0 -1
- package/dist/core/memory/compressed_session.js +182 -0
- package/dist/core/memory/context_compressor.d.ts +0 -1
- package/dist/core/memory/context_compressor.js +176 -0
- package/dist/core/memory/index.d.ts +0 -1
- package/dist/core/memory/index.js +22 -0
- package/dist/core/memory/memory_manager.d.ts +0 -1
- package/dist/core/memory/memory_manager.js +28 -0
- package/dist/core/memory/reflector.d.ts +0 -1
- package/dist/core/memory/reflector.js +95 -0
- package/dist/core/memory/session_factory.d.ts +0 -1
- package/dist/core/memory/session_factory.js +29 -0
- package/dist/core/memory/tool_player.d.ts +0 -1
- package/dist/core/memory/tool_player.js +225 -0
- package/dist/core/memory/tool_recorder.d.ts +0 -1
- package/dist/core/memory/tool_recorder.js +126 -0
- package/dist/core/preprocessor/task_splitter.d.ts +0 -1
- package/dist/core/preprocessor/task_splitter.js +112 -0
- package/dist/core/prompt/prompt_loader.d.ts +0 -1
- package/dist/core/prompt/prompt_loader.js +313 -0
- package/dist/core/skill/skill_manager.d.ts +0 -1
- package/dist/core/skill/skill_manager.js +299 -0
- package/dist/data_types/action.d.ts +0 -1
- package/dist/data_types/action.js +2 -0
- package/dist/data_types/agent.d.ts +0 -1
- package/dist/data_types/agent.js +2 -0
- package/dist/data_types/device.d.ts +0 -1
- package/dist/data_types/device.js +2 -0
- package/dist/data_types/index.d.ts +0 -1
- package/dist/data_types/index.js +6 -0
- package/dist/data_types/report.d.ts +0 -1
- package/dist/data_types/report.js +6 -0
- package/dist/data_types/task.d.ts +0 -1
- package/dist/data_types/task.js +2 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +164 -1
- package/dist/loop/cli.d.ts +0 -1
- package/dist/loop/cli.js +127 -0
- package/dist/loop/orchestrator.d.ts +0 -1
- package/dist/loop/orchestrator.js +314 -0
- package/dist/loop/result_writer.d.ts +0 -1
- package/dist/loop/result_writer.js +260 -0
- package/dist/loop/types.d.ts +0 -1
- package/dist/loop/types.js +82 -0
- package/dist/mcp-server/server.d.ts +0 -1
- package/dist/mcp-server/server.js +341 -0
- package/dist/mcp-server/types.d.ts +283 -118
- package/dist/mcp-server/types.js +202 -0
- package/dist/reporter/batch_summary.d.ts +0 -1
- package/dist/reporter/batch_summary.js +197 -0
- package/dist/reporter/generator.d.ts +0 -1
- package/dist/reporter/generator.js +772 -0
- package/dist/reporter/types.d.ts +14 -15
- package/dist/reporter/types.js +44 -0
- package/dist/tools/batch_runner.d.ts +1 -1
- package/dist/tools/batch_runner.js +731 -0
- package/package.json +5 -3
- package/dist/common/config/config.yaml +0 -113
- package/dist/hypium_generator/generator.d.ts +0 -38
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loop 结果落盘 — 移植自 python loop/result_writer.py
|
|
4
|
+
*
|
|
5
|
+
* writeLoopResultJson: 序列化 LoopResult → loop_result.json(写在 finalReportDir 父目录)。
|
|
6
|
+
* writeLoopSummaryHtml: 生成 loop_summary.html(Loop 汇总 + 各轮执行/分析报告 iframe 标签页)。
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.writeLoopResultJson = writeLoopResultJson;
|
|
43
|
+
exports.writeLoopSummaryHtml = writeLoopSummaryHtml;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const logger_1 = require("../common/logger");
|
|
47
|
+
const types_1 = require("./types");
|
|
48
|
+
function findReportHtml(reportDir) {
|
|
49
|
+
if (!reportDir || !fs.existsSync(reportDir))
|
|
50
|
+
return null;
|
|
51
|
+
const conventional = path.join(reportDir, `${path.basename(reportDir)}.html`);
|
|
52
|
+
if (fs.existsSync(conventional))
|
|
53
|
+
return conventional;
|
|
54
|
+
const htmls = fs
|
|
55
|
+
.readdirSync(reportDir)
|
|
56
|
+
.filter((f) => f.endsWith('.html'))
|
|
57
|
+
.sort();
|
|
58
|
+
return htmls.length > 0 ? path.join(reportDir, htmls[0]) : null;
|
|
59
|
+
}
|
|
60
|
+
function findAnalysisHtml(reportDir) {
|
|
61
|
+
if (!reportDir || !fs.existsSync(reportDir))
|
|
62
|
+
return null;
|
|
63
|
+
// Node.js analyzer 写 analysis_report/,Python 写 analysis/,兼容两者
|
|
64
|
+
for (const sub of ['analysis_report', 'analysis']) {
|
|
65
|
+
const dir = path.join(reportDir, sub);
|
|
66
|
+
if (fs.existsSync(dir)) {
|
|
67
|
+
const htmls = fs.readdirSync(dir).filter((f) => f.endsWith('.html')).sort();
|
|
68
|
+
if (htmls.length > 0)
|
|
69
|
+
return path.join(dir, htmls[0]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function escapeHtml(s) {
|
|
75
|
+
return (s ?? '')
|
|
76
|
+
.replace(/&/g, '&')
|
|
77
|
+
.replace(/</g, '<')
|
|
78
|
+
.replace(/>/g, '>')
|
|
79
|
+
.replace(/"/g, '"');
|
|
80
|
+
}
|
|
81
|
+
const ACTION_LABELS = {
|
|
82
|
+
rewrite_task: '改写任务',
|
|
83
|
+
add_knowledge: '追加知识',
|
|
84
|
+
both: '改写+知识',
|
|
85
|
+
no_rewrite: '无需改写',
|
|
86
|
+
};
|
|
87
|
+
function buildIterationOverviewHtml(iterations) {
|
|
88
|
+
if (iterations.length === 0)
|
|
89
|
+
return '<p class="warn">无迭代记录</p>';
|
|
90
|
+
const rows = iterations
|
|
91
|
+
.map((it) => {
|
|
92
|
+
const summary = it.analyzerOutputSummary ?? {};
|
|
93
|
+
const iterStatus = String(summary['task_result_status'] ?? '—') || '—';
|
|
94
|
+
const rc = summary['root_cause'];
|
|
95
|
+
const iterCategory = rc ? String(rc['category'] ?? '—') : '—';
|
|
96
|
+
const iterSubCategory = rc ? String(rc['sub_category'] ?? '—') : '—';
|
|
97
|
+
const actionRaw = it.rewriteAction ?? '';
|
|
98
|
+
const actionLabel = actionRaw === '' ? '—' : ACTION_LABELS[actionRaw] ?? actionRaw;
|
|
99
|
+
return (`<tr><td>${it.iteration}</td>` +
|
|
100
|
+
`<td class="status-${escapeHtml(iterStatus.toLowerCase())}">${escapeHtml(iterStatus)}</td>` +
|
|
101
|
+
`<td>${escapeHtml(iterCategory)}</td>` +
|
|
102
|
+
`<td>${escapeHtml(iterSubCategory)}</td>` +
|
|
103
|
+
`<td>${escapeHtml(actionLabel)}</td></tr>`);
|
|
104
|
+
})
|
|
105
|
+
.join('');
|
|
106
|
+
return ('<div class="iteration-overview"><h2>各轮概览</h2>' +
|
|
107
|
+
'<table class="iter-overview-table"><thead><tr>' +
|
|
108
|
+
'<th>轮次</th><th>执行结果</th><th>根因分类</th><th>根因子类</th><th>改写动作</th>' +
|
|
109
|
+
`</tr></thead><tbody>${rows}</tbody></table></div>`);
|
|
110
|
+
}
|
|
111
|
+
function buildTaskEvolutionHtml(originalTask, finalTask, iterations) {
|
|
112
|
+
const rewriteEntries = [];
|
|
113
|
+
for (const it of iterations) {
|
|
114
|
+
if ((it.rewriteAction === 'rewrite_task' || it.rewriteAction === 'both') &&
|
|
115
|
+
it.rewrittenTask) {
|
|
116
|
+
rewriteEntries.push({ iter: it.iteration, task: it.rewrittenTask });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const cards = [];
|
|
120
|
+
cards.push(`<div class="evolution-card evolution-start"><div class="card-label">原始任务</div>` +
|
|
121
|
+
`<div class="card-text">${escapeHtml(originalTask)}</div></div>`);
|
|
122
|
+
for (const e of rewriteEntries) {
|
|
123
|
+
cards.push(`<div class="evolution-card evolution-rewrite"><div class="card-label">第 ${e.iter} 轮改写</div>` +
|
|
124
|
+
`<div class="card-text">${escapeHtml(e.task)}</div></div>`);
|
|
125
|
+
}
|
|
126
|
+
cards.push(`<div class="evolution-card evolution-end"><div class="card-label">最终任务</div>` +
|
|
127
|
+
`<div class="card-text">${escapeHtml(finalTask)}</div></div>`);
|
|
128
|
+
const note = rewriteEntries.length === 0 && originalTask === finalTask
|
|
129
|
+
? '<p class="evolution-note">任务未发生变化</p>'
|
|
130
|
+
: '';
|
|
131
|
+
return (`<div class="task-evolution"><h2>任务演进</h2>` +
|
|
132
|
+
`<div class="evolution-timeline">${cards.join('')}</div>${note}</div>`);
|
|
133
|
+
}
|
|
134
|
+
/** 写 loop_result.json。finalReportDir 为空时安全降级返回 null。 */
|
|
135
|
+
function writeLoopResultJson(result, finalReportDir) {
|
|
136
|
+
if (!finalReportDir) {
|
|
137
|
+
logger_1.logger.warn('writeLoopResultJson: finalReportDir 为空,跳过 loop_result.json');
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const outputPath = path.join(path.dirname(finalReportDir), 'loop_result.json');
|
|
141
|
+
try {
|
|
142
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
143
|
+
fs.writeFileSync(outputPath, JSON.stringify((0, types_1.loopResultToDict)(result), null, 2), 'utf-8');
|
|
144
|
+
logger_1.logger.info(`Loop result written to ${outputPath}`);
|
|
145
|
+
return outputPath;
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
logger_1.logger.error(`Failed to write loop_result.json to ${outputPath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** 生成 loop_summary.html(iframe 内嵌各轮报告)。 */
|
|
153
|
+
function writeLoopSummaryHtml(result, finalReportDir) {
|
|
154
|
+
if (!finalReportDir) {
|
|
155
|
+
logger_1.logger.warn('writeLoopSummaryHtml: finalReportDir 为空,跳过 loop_summary.html');
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
// report 根:多轮(iter_N)→ 父目录;单轮 → 本身
|
|
159
|
+
const summaryDir = path.basename(finalReportDir).startsWith('iter_')
|
|
160
|
+
? path.dirname(finalReportDir)
|
|
161
|
+
: finalReportDir;
|
|
162
|
+
const outputPath = path.join(summaryDir, 'loop_summary.html');
|
|
163
|
+
try {
|
|
164
|
+
fs.mkdirSync(summaryDir, { recursive: true });
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
logger_1.logger.error(`Failed to create summary dir ${summaryDir}: ${e instanceof Error ? e.message : String(e)}`);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const tabButtons = [];
|
|
171
|
+
const tabContents = [];
|
|
172
|
+
let lastIterNum = 0;
|
|
173
|
+
// Tab 1: Loop 汇总
|
|
174
|
+
tabButtons.push(`<button class="tab" onclick="showTab('loop-summary')">Loop 汇总</button>`);
|
|
175
|
+
const iterOverview = buildIterationOverviewHtml(result.iterations);
|
|
176
|
+
const taskEvolution = buildTaskEvolutionHtml(result.originalTask, result.finalTask, result.iterations);
|
|
177
|
+
tabContents.push(`<div class="tab-content" id="loop-summary" style="display:none">` +
|
|
178
|
+
`<div class="header"><h1>Loop 汇总报告</h1>` +
|
|
179
|
+
`<p><strong>终止原因:</strong><span class="term">${escapeHtml(result.terminationReason || 'unknown')}</span></p>` +
|
|
180
|
+
`<p><strong>总迭代数:</strong>${result.totalIterations}</p>` +
|
|
181
|
+
`<p><strong>原始任务:</strong>${escapeHtml(result.originalTask)}</p>` +
|
|
182
|
+
`<p><strong>最终任务:</strong>${escapeHtml(result.finalTask)}</p></div>` +
|
|
183
|
+
`${iterOverview}${taskEvolution}</div>`);
|
|
184
|
+
// 各轮:执行报告 + 分析报告
|
|
185
|
+
for (const it of result.iterations) {
|
|
186
|
+
lastIterNum = it.iteration;
|
|
187
|
+
tabButtons.push(`<button class="tab" onclick="showTab('iter-${it.iteration}-exec')">Iter ${it.iteration} 执行报告</button>`);
|
|
188
|
+
tabButtons.push(`<button class="tab" onclick="showTab('iter-${it.iteration}-analysis')">Iter ${it.iteration} 分析报告</button>`);
|
|
189
|
+
const execHtml = findReportHtml(it.reportDir);
|
|
190
|
+
const execContent = execHtml
|
|
191
|
+
? `<iframe src="${escapeHtml(path.relative(summaryDir, execHtml).split(path.sep).join('/'))}"></iframe>`
|
|
192
|
+
: '<p class="warn">未找到执行报告 HTML</p>';
|
|
193
|
+
tabContents.push(`<div class="tab-content" id="iter-${it.iteration}-exec" style="display:none">${execContent}</div>`);
|
|
194
|
+
const analysisHtml = findAnalysisHtml(it.reportDir);
|
|
195
|
+
const analysisContent = analysisHtml
|
|
196
|
+
? `<iframe src="${escapeHtml(path.relative(summaryDir, analysisHtml).split(path.sep).join('/'))}"></iframe>`
|
|
197
|
+
: '<p class="warn">未找到分析报告 HTML</p>';
|
|
198
|
+
tabContents.push(`<div class="tab-content" id="iter-${it.iteration}-analysis" style="display:none">${analysisContent}</div>`);
|
|
199
|
+
}
|
|
200
|
+
const defaultTab = lastIterNum > 0 ? `'iter-${lastIterNum}-exec'` : `'loop-summary'`;
|
|
201
|
+
const pageHtml = `<!DOCTYPE html>
|
|
202
|
+
<html lang="zh">
|
|
203
|
+
<head><meta charset="utf-8"><title>Loop 汇总报告</title>
|
|
204
|
+
<style>
|
|
205
|
+
body { font-family: -apple-system, "Segoe UI", sans-serif; margin: 0; display: flex; flex-direction: column; height: 100vh; background: #f7f7f7; }
|
|
206
|
+
.header { background: #fff; padding: 16px 20px; border-radius: 8px; margin: 12px 20px 16px 20px; }
|
|
207
|
+
.header h1 { margin: 0 0 12px 0; font-size: 22px; }
|
|
208
|
+
.header p { margin: 4px 0; font-size: 14px; word-break: break-all; }
|
|
209
|
+
.term { color: #c0392b; font-weight: 600; }
|
|
210
|
+
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex-shrink: 0; }
|
|
211
|
+
.tab { padding: 8px 16px; border: 1px solid #ddd; border-bottom: none; border-radius: 6px 6px 0 0; background: #eee; cursor: pointer; font-size: 14px; color: #555; outline: none; }
|
|
212
|
+
.tab:hover { background: #e0e0e0; }
|
|
213
|
+
.tab.active { background: #fff; color: #2980b9; font-weight: 600; }
|
|
214
|
+
.tab-content { background: #fff; flex: 1; overflow: auto; padding: 0; }
|
|
215
|
+
iframe { width: 100%; height: 100%; border: none; background: #fff; }
|
|
216
|
+
.warn { color: #b8860b; font-style: italic; font-size: 13px; padding: 12px 20px; }
|
|
217
|
+
.iteration-overview, .task-evolution { margin: 0 20px 16px 20px; }
|
|
218
|
+
.iteration-overview h2, .task-evolution h2 { font-size: 18px; margin: 0 0 10px 0; }
|
|
219
|
+
.iter-overview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
220
|
+
.iter-overview-table th, .iter-overview-table td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
|
|
221
|
+
.iter-overview-table th { background: #f5f5f5; font-weight: 600; }
|
|
222
|
+
.iter-overview-table .status-pass { color: #27ae60; font-weight: 600; }
|
|
223
|
+
.iter-overview-table .status-fail { color: #c0392b; font-weight: 600; }
|
|
224
|
+
.evolution-timeline { position: relative; padding-left: 24px; border-left: 2px solid #ddd; }
|
|
225
|
+
.evolution-card { position: relative; margin-bottom: 14px; padding: 10px 14px; background: #f9f9f9; border-radius: 6px; border: 1px solid #eee; }
|
|
226
|
+
.evolution-card::before { content: ''; position: absolute; left: -30px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: #3498db; border: 2px solid #fff; }
|
|
227
|
+
.card-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
|
|
228
|
+
.card-text { font-size: 13px; word-break: break-all; white-space: pre-wrap; }
|
|
229
|
+
.evolution-note { color: #7f8c8d; font-style: italic; font-size: 13px; margin: 8px 0 0 0; }
|
|
230
|
+
</style>
|
|
231
|
+
</head>
|
|
232
|
+
<body>
|
|
233
|
+
<div class="tabs">${tabButtons.join('')}</div>
|
|
234
|
+
${tabContents.join('')}
|
|
235
|
+
<script>
|
|
236
|
+
function showTab(tabId) {
|
|
237
|
+
var contents = document.querySelectorAll('.tab-content');
|
|
238
|
+
for (var i = 0; i < contents.length; i++) { contents[i].style.display = 'none'; }
|
|
239
|
+
var target = document.getElementById(tabId);
|
|
240
|
+
if (target) target.style.display = 'block';
|
|
241
|
+
var tabs = document.querySelectorAll('.tab');
|
|
242
|
+
for (var i = 0; i < tabs.length; i++) {
|
|
243
|
+
tabs[i].classList.remove('active');
|
|
244
|
+
if (tabs[i].getAttribute('onclick') === "showTab('" + tabId + "')") { tabs[i].classList.add('active'); }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
showTab(${defaultTab});
|
|
248
|
+
</script>
|
|
249
|
+
</body>
|
|
250
|
+
</html>`;
|
|
251
|
+
try {
|
|
252
|
+
fs.writeFileSync(outputPath, pageHtml, 'utf-8');
|
|
253
|
+
logger_1.logger.info(`Loop summary HTML written to ${outputPath}`);
|
|
254
|
+
return outputPath;
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
logger_1.logger.error(`Failed to write loop_summary.html to ${outputPath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
}
|
package/dist/loop/types.d.ts
CHANGED
|
@@ -74,4 +74,3 @@ export declare function createLoopResult(): LoopResult;
|
|
|
74
74
|
export declare function iterationRecordToDict(it: IterationRecord): Record<string, unknown>;
|
|
75
75
|
/** 序列化 LoopResult 为普通对象(用于 loop_result.json 落盘)。 */
|
|
76
76
|
export declare function loopResultToDict(result: LoopResult): Record<string, unknown>;
|
|
77
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loop 闭环类型定义 — 移植自 python/AutoTest/loop/types.py
|
|
4
|
+
*
|
|
5
|
+
* 5 种执行模式 + 6 个状态机状态 + 5 类终止原因 + 迭代记录 + 闭环结果。
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.TerminationReason = exports.LoopStatus = exports.LoopMode = void 0;
|
|
9
|
+
exports.createLoopResult = createLoopResult;
|
|
10
|
+
exports.iterationRecordToDict = iterationRecordToDict;
|
|
11
|
+
exports.loopResultToDict = loopResultToDict;
|
|
12
|
+
/** Loop 执行模式枚举(决定状态机跳步策略)。 */
|
|
13
|
+
var LoopMode;
|
|
14
|
+
(function (LoopMode) {
|
|
15
|
+
/** 完整闭环:执行→归因→改写→重执行,最多 max_loops 轮,生成 iter_N 目录 + loop_summary.html + loop_result.json */
|
|
16
|
+
LoopMode["FULL_LOOP"] = "full_loop";
|
|
17
|
+
/** 执行 + 归因(不触发改写,单轮即终止) */
|
|
18
|
+
LoopMode["EXECUTE_ANALYZE"] = "execute_analyze";
|
|
19
|
+
/** 仅执行(不做归因和改写,单轮即终止) */
|
|
20
|
+
LoopMode["EXECUTE_ONLY"] = "execute_only";
|
|
21
|
+
/** 仅归因(跳过执行,直接对已有报告做根因分析) */
|
|
22
|
+
LoopMode["ANALYZE_ONLY"] = "analyze_only";
|
|
23
|
+
/** 仅改写(跳过执行和归因,直接对已有分析结果做改写) */
|
|
24
|
+
LoopMode["REWRITE_ONLY"] = "rewrite_only";
|
|
25
|
+
})(LoopMode || (exports.LoopMode = LoopMode = {}));
|
|
26
|
+
/** Loop 编排器状态枚举(状态机各阶段)。 */
|
|
27
|
+
var LoopStatus;
|
|
28
|
+
(function (LoopStatus) {
|
|
29
|
+
LoopStatus["INIT"] = "init";
|
|
30
|
+
LoopStatus["EXECUTING"] = "executing";
|
|
31
|
+
LoopStatus["ATTRIBUTING"] = "attributing";
|
|
32
|
+
LoopStatus["REWRITING"] = "rewriting";
|
|
33
|
+
LoopStatus["RE_EXECUTING"] = "re_executing";
|
|
34
|
+
LoopStatus["TERMINATED"] = "terminated";
|
|
35
|
+
})(LoopStatus || (exports.LoopStatus = LoopStatus = {}));
|
|
36
|
+
/** Loop 终止原因枚举。 */
|
|
37
|
+
var TerminationReason;
|
|
38
|
+
(function (TerminationReason) {
|
|
39
|
+
/** 任务通过 */
|
|
40
|
+
TerminationReason["PASSED"] = "passed";
|
|
41
|
+
/** 不可改写(应用/环境/无问题/未知 category/决策表 NO_REWRITE) */
|
|
42
|
+
TerminationReason["UNREWRITEABLE"] = "unrewriteable";
|
|
43
|
+
/** 达到 max_loops 上限 */
|
|
44
|
+
TerminationReason["MAX_LOOPS"] = "max_loops";
|
|
45
|
+
/** 连续 2 次相同 failure signature */
|
|
46
|
+
TerminationReason["DEAD_LOOP"] = "dead_loop";
|
|
47
|
+
/** analyzer 或 rewriter 异常 */
|
|
48
|
+
TerminationReason["ERROR"] = "error";
|
|
49
|
+
})(TerminationReason || (exports.TerminationReason = TerminationReason = {}));
|
|
50
|
+
/** 构造一个空的 LoopResult。 */
|
|
51
|
+
function createLoopResult() {
|
|
52
|
+
return {
|
|
53
|
+
iterations: [],
|
|
54
|
+
finalReportDir: null,
|
|
55
|
+
terminationReason: '',
|
|
56
|
+
totalIterations: 0,
|
|
57
|
+
originalTask: '',
|
|
58
|
+
finalTask: '',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** 序列化 IterationRecord 为普通对象(用于 JSON 落盘)。 */
|
|
62
|
+
function iterationRecordToDict(it) {
|
|
63
|
+
return {
|
|
64
|
+
iteration: it.iteration,
|
|
65
|
+
report_dir: it.reportDir,
|
|
66
|
+
analyzer_output_summary: it.analyzerOutputSummary,
|
|
67
|
+
rewrite_action: it.rewriteAction,
|
|
68
|
+
rewritten_task: it.rewrittenTask ?? null,
|
|
69
|
+
knowledge_text: it.knowledgeText ?? '',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** 序列化 LoopResult 为普通对象(用于 loop_result.json 落盘)。 */
|
|
73
|
+
function loopResultToDict(result) {
|
|
74
|
+
return {
|
|
75
|
+
iterations: result.iterations.map(iterationRecordToDict),
|
|
76
|
+
final_report_dir: result.finalReportDir,
|
|
77
|
+
termination_reason: result.terminationReason,
|
|
78
|
+
total_iterations: result.totalIterations,
|
|
79
|
+
original_task: result.originalTask,
|
|
80
|
+
final_task: result.finalTask,
|
|
81
|
+
};
|
|
82
|
+
}
|