@autotest/agent 0.0.1
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 +648 -0
- package/dist/api/agent_api.d.ts +37 -0
- package/dist/api/autotest_agent.d.ts +60 -0
- package/dist/api/types.d.ts +86 -0
- package/dist/autotest-cli.d.ts +2 -0
- package/dist/common/case_manager.d.ts +10 -0
- package/dist/common/collect_case.d.ts +29 -0
- package/dist/common/common_errors.d.ts +30 -0
- package/dist/common/config/config.yaml +113 -0
- package/dist/common/config/config_validator.d.ts +8 -0
- package/dist/common/config/manager.d.ts +38 -0
- package/dist/common/config/output.d.ts +11 -0
- package/dist/common/config/types.d.ts +2963 -0
- package/dist/common/dfx/client_factory.d.ts +23 -0
- package/dist/common/dfx/context.d.ts +4 -0
- package/dist/common/dfx/index.d.ts +6 -0
- package/dist/common/dfx/recorder.d.ts +59 -0
- package/dist/common/dfx/recording_fetch.d.ts +4 -0
- package/dist/common/dfx/source.d.ts +9 -0
- package/dist/common/image_cacher.d.ts +10 -0
- package/dist/common/image_helper.d.ts +19 -0
- package/dist/common/image_similarity.d.ts +7 -0
- package/dist/common/llm_cache/cache_transport.d.ts +10 -0
- package/dist/common/logger.d.ts +17 -0
- package/dist/common/model/custom_model.d.ts +52 -0
- package/dist/common/model/index.d.ts +3 -0
- package/dist/common/path_utils.d.ts +11 -0
- package/dist/common/result_parser.d.ts +10 -0
- package/dist/common/usage/token_usage.d.ts +23 -0
- package/dist/common/utils.d.ts +44 -0
- package/dist/core/agent/layered_agent/ability_helper.d.ts +36 -0
- package/dist/core/agent/layered_agent/agent.d.ts +15 -0
- package/dist/core/agent/layered_agent/agent_registry.d.ts +34 -0
- package/dist/core/agent/layered_agent/decision.d.ts +82 -0
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +26 -0
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +24 -0
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +83 -0
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +33 -0
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +36 -0
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +26 -0
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts +16 -0
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +52 -0
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +4 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +22 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +14 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +7 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +17 -0
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +2 -0
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +13 -0
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +6 -0
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +22 -0
- package/dist/core/agent/report_analyzer_agent/config.d.ts +5 -0
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +26 -0
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +9 -0
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +6 -0
- package/dist/core/agent/report_analyzer_agent/index.d.ts +17 -0
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +9 -0
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +6 -0
- package/dist/core/agent/report_analyzer_agent/parse.d.ts +4 -0
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +2 -0
- package/dist/core/agent/report_analyzer_agent/prompts/main_agent.md +198 -0
- package/dist/core/agent/report_analyzer_agent/prompts/main_agent_v2.0.md +420 -0
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +8 -0
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +26 -0
- package/dist/core/agent/report_analyzer_agent/types.d.ts +97 -0
- package/dist/core/agent/rewrite_agent/agent.d.ts +27 -0
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +16 -0
- package/dist/core/agent/rewrite_agent/mapping.d.ts +25 -0
- package/dist/core/agent/rewrite_agent/parse.d.ts +14 -0
- package/dist/core/agent/rewrite_agent/prompts/rewriter_v1.0.md +168 -0
- package/dist/core/agent/rewrite_agent/types.d.ts +50 -0
- package/dist/core/agent/single_agent/agent.d.ts +43 -0
- package/dist/core/agent/single_agent/hook_manager.d.ts +43 -0
- package/dist/core/agent/single_agent/hooks.d.ts +23 -0
- package/dist/core/agent/single_agent/image_utils.d.ts +38 -0
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +58 -0
- package/dist/core/agent/single_agent/subagent_manager.d.ts +51 -0
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +20 -0
- package/dist/core/agent/types.d.ts +43 -0
- package/dist/core/agent/utils/message_builder.d.ts +38 -0
- package/dist/core/device/device_protocol.d.ts +3 -0
- package/dist/core/device/hdc/apps.d.ts +38 -0
- package/dist/core/device/hdc/device.d.ts +59 -0
- package/dist/core/device/hdc/index.d.ts +9 -0
- package/dist/core/device/hdc/input.d.ts +20 -0
- package/dist/core/device/hdc/screenshot.d.ts +19 -0
- package/dist/core/device/index.d.ts +49 -0
- package/dist/core/device/types.d.ts +37 -0
- package/dist/core/knowledge/knowledge_manager.d.ts +22 -0
- package/dist/core/knowledge/vectordb.d.ts +44 -0
- package/dist/core/mcp/adapter_factory.d.ts +10 -0
- package/dist/core/mcp/android_adapter.d.ts +30 -0
- package/dist/core/mcp/base_adapter.d.ts +26 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +49 -0
- package/dist/core/mcp/ios_adapter.d.ts +30 -0
- package/dist/core/mcp/local_tools.d.ts +20 -0
- package/dist/core/mcp/mcp_tools.d.ts +51 -0
- package/dist/core/mcp/types.d.ts +24 -0
- package/dist/core/memory/compressed_session.d.ts +46 -0
- package/dist/core/memory/context_compressor.d.ts +24 -0
- package/dist/core/memory/index.d.ts +7 -0
- package/dist/core/memory/memory_manager.d.ts +21 -0
- package/dist/core/memory/reflector.d.ts +20 -0
- package/dist/core/memory/session_factory.d.ts +17 -0
- package/dist/core/memory/tool_player.d.ts +82 -0
- package/dist/core/memory/tool_recorder.d.ts +33 -0
- package/dist/core/preprocessor/task_splitter.d.ts +26 -0
- package/dist/core/prompt/prompt_loader.d.ts +24 -0
- package/dist/core/prompt/templates/debug/planner/planner_v0.0.md +290 -0
- package/dist/core/prompt/templates/debug/planner/planner_v1.0.md +221 -0
- package/dist/core/prompt/templates/debug/planner/planner_v1.1-dy.md +74 -0
- package/dist/core/prompt/templates/debug/planner/planner_v2.0.md +319 -0
- package/dist/core/prompt/templates/fast_action/fast_action_v1.0.md +46 -0
- package/dist/core/prompt/templates/hypium/hypium_v1.0.md +33 -0
- package/dist/core/prompt/templates/hypium/hypium_v2.0.md +285 -0
- package/dist/core/prompt/templates/planner/planner_v2.0.md +319 -0
- package/dist/core/prompt/templates/single/single_v1.0.md +452 -0
- package/dist/core/prompt/templates/single/single_v2.0.md +306 -0
- package/dist/core/prompt/templates/single/single_v2.0_eco.md +313 -0
- package/dist/core/prompt/templates/single/single_v3.0.md +200 -0
- package/dist/core/prompt/templates/splitter/task_splitter_v1.0.md +141 -0
- package/dist/core/skill/skill_manager.d.ts +54 -0
- package/dist/data_types/action.d.ts +2 -0
- package/dist/data_types/agent.d.ts +2 -0
- package/dist/data_types/device.d.ts +2 -0
- package/dist/data_types/index.d.ts +6 -0
- package/dist/data_types/report.d.ts +2 -0
- package/dist/data_types/task.d.ts +2 -0
- package/dist/hypium_generator/generator.d.ts +38 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +1 -0
- package/dist/loop/cli.d.ts +39 -0
- package/dist/loop/orchestrator.d.ts +47 -0
- package/dist/loop/result_writer.d.ts +12 -0
- package/dist/loop/types.d.ts +77 -0
- package/dist/mcp-server/server.d.ts +15 -0
- package/dist/mcp-server/types.d.ts +196 -0
- package/dist/reporter/batch_summary.d.ts +19 -0
- package/dist/reporter/generator.d.ts +46 -0
- package/dist/reporter/types.d.ts +88 -0
- package/dist/tools/batch_runner.d.ts +92 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
# @autotest/agent
|
|
2
|
+
|
|
3
|
+
基于 AI 的自动化测试执行代理核心包,通过多模态模型的视觉理解能力自主执行 HarmonyOS/Android/iOS 设备测试。
|
|
4
|
+
|
|
5
|
+
## 项目简介
|
|
6
|
+
|
|
7
|
+
AutoTest Agent 是一个智能化的移动设备自动化测试框架,支持 **单层 Agent**、**双层 Agent**、**Hypium Agent** 三种架构模式,能够理解自然语言指令,通过多模态模型自主执行测试操作、发现 Bug、分析失败根因并生成测试报告。
|
|
8
|
+
|
|
9
|
+
### 核心特性
|
|
10
|
+
|
|
11
|
+
- **多架构模式**:`single`(统一 Agent)、`layered`(Planner + Executor)、`hypium`(自定义循环 + 回归脚本生成)三种模式可切换
|
|
12
|
+
- **多模态视觉理解**:通过多模态模型观察屏幕截图、定位 UI 元素、判断操作结果
|
|
13
|
+
- **自然语言交互**:中文描述测试步骤,自动转换为设备操作
|
|
14
|
+
- **多平台支持**:HarmonyOS(纯 TS 直驱 HDC)、Android、iOS
|
|
15
|
+
- **Bug 自动发现与根因分析**:执行中主动发现异常,`analyze` 命令基于报告生成根因分析与改进建议
|
|
16
|
+
- **多格式报告**:自动生成 HTML / Markdown / JSON 测试报告与汇总
|
|
17
|
+
- **批量执行**:JSONL/JSON 批量用例执行,支持断点续跑、进度报告、分类汇总
|
|
18
|
+
- **Skills 系统**:加载技能步骤指导 Agent 执行复杂操作
|
|
19
|
+
- **知识库**:按 App 维度管理领域知识(如华为商城 vmall)
|
|
20
|
+
- **Debug 调试模式**:任务执行后通过浏览器与 Agent 交互式复盘
|
|
21
|
+
|
|
22
|
+
## 目录结构
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
AutoTest/
|
|
26
|
+
├── src/
|
|
27
|
+
│ ├── autotest-cli.ts # CLI 入口(run/list-devices/analyze/config)
|
|
28
|
+
│ ├── index.ts # 包导出
|
|
29
|
+
│ ├── api/ # AgentAPI 对外接口
|
|
30
|
+
│ │ ├── agent_api.ts
|
|
31
|
+
│ │ └── types.ts
|
|
32
|
+
│ ├── common/ # 公共模块
|
|
33
|
+
│ │ ├── config/ # 配置(config.yaml / manager.ts / types.ts)
|
|
34
|
+
│ │ ├── model/ # LLM 调用封装
|
|
35
|
+
│ │ ├── llm_cache/ # LLM 响应缓存
|
|
36
|
+
│ │ ├── dfx/ # 诊断/可观测性(LLM 流量记录)
|
|
37
|
+
│ │ ├── usage/ # Token 用量统计
|
|
38
|
+
│ │ ├── case_manager.ts # 用例管理
|
|
39
|
+
│ │ ├── collect_case.ts # 用例收集
|
|
40
|
+
│ │ ├── image_helper.ts # 图片处理
|
|
41
|
+
│ │ ├── image_cacher.ts # 图片缓存
|
|
42
|
+
│ │ ├── image_similarity.ts # 图片相似度
|
|
43
|
+
│ │ ├── logger.ts # 日志
|
|
44
|
+
│ │ ├── utils.ts # 工具函数
|
|
45
|
+
│ │ ├── path_utils.ts # 路径工具
|
|
46
|
+
│ │ └── common_errors.ts # 结构化错误(AgentError)
|
|
47
|
+
│ ├── core/
|
|
48
|
+
│ │ ├── agent/ # Agent 实现
|
|
49
|
+
│ │ │ ├── single_agent/ # 单层 Agent
|
|
50
|
+
│ │ │ ├── layered_agent/ # 双层 Agent(Planner + Executor)
|
|
51
|
+
│ │ │ │ ├── decision.ts # Planner 决策
|
|
52
|
+
│ │ │ │ ├── agent_registry.ts # Agent 注册表
|
|
53
|
+
│ │ │ │ ├── ability_helper.ts # 能力辅助
|
|
54
|
+
│ │ │ │ └── execute_agent/ # Executor 执行
|
|
55
|
+
│ │ │ ├── hypium_agent/ # Hypium Agent(自定义循环 + 子Agent)
|
|
56
|
+
│ │ │ │ ├── basic_agent.ts # 基础 Agent
|
|
57
|
+
│ │ │ │ ├── context.ts # 上下文
|
|
58
|
+
│ │ │ │ ├── hooks.ts # 钩子
|
|
59
|
+
│ │ │ │ ├── model_adapter/ # LLM 输出格式适配
|
|
60
|
+
│ │ │ │ ├── subagent/ # 滚动搜索 / 时间选择等
|
|
61
|
+
│ │ │ │ ├── tool_filter.ts # 工具过滤
|
|
62
|
+
│ │ │ │ └── report_adapter.ts # 报告适配
|
|
63
|
+
│ │ │ ├── report_analyzer_agent/ # 失败根因分析 Agent
|
|
64
|
+
│ │ │ ├── utils/
|
|
65
|
+
│ │ │ └── types.ts
|
|
66
|
+
│ │ ├── device/ # 设备抽象层
|
|
67
|
+
│ │ │ ├── device_protocol.ts # 设备协议抽象
|
|
68
|
+
│ │ │ ├── hdc_device.ts # HDC 设备实现
|
|
69
|
+
│ │ │ └── hdc/ # HDC 协议(device/input/screenshot/apps)
|
|
70
|
+
│ │ ├── mcp/ # MCP 适配器
|
|
71
|
+
│ │ │ ├── base_adapter.ts
|
|
72
|
+
│ │ │ ├── harmony_hdc_adapter.ts # HarmonyOS 适配器(纯 TS 直驱 hdc)
|
|
73
|
+
│ │ │ ├── android_adapter.ts # Android 适配器
|
|
74
|
+
│ │ │ ├── ios_adapter.ts # iOS 适配器
|
|
75
|
+
│ │ │ ├── adapter_factory.ts # 适配器工厂
|
|
76
|
+
│ │ │ ├── mcp_tools.ts # 双层 Agent MCP 工具
|
|
77
|
+
│ │ │ └── local_tools.ts # 本地工具(wait / load_skill)
|
|
78
|
+
│ │ ├── prompt/ # 版本化提示词
|
|
79
|
+
│ │ │ ├── prompt_loader.ts
|
|
80
|
+
│ │ │ └── templates/ # single / hypium / planner / splitter 模板
|
|
81
|
+
│ │ ├── skill/ # Skills 系统(skill_manager.ts)
|
|
82
|
+
│ │ ├── knowledge/ # 知识库(knowledge_manager.ts / vectordb.ts)
|
|
83
|
+
│ │ ├── memory/ # 记忆系统
|
|
84
|
+
│ │ ├── preprocessor/ # 任务预处理
|
|
85
|
+
│ │ └── script_generator/ # 测试脚本生成
|
|
86
|
+
│ ├── data_types/ # 数据模型
|
|
87
|
+
│ ├── reporter/ # 报告生成(generator.ts / types.ts)
|
|
88
|
+
│ ├── hypium_generator/ # Hypium 回归脚本生成
|
|
89
|
+
│ ├── mcp-server/ # MCP server 暴露
|
|
90
|
+
│ └── tools/ # 工具
|
|
91
|
+
│ ├── batch_runner.ts # 批量执行
|
|
92
|
+
│ └── runner.mjs # caseTest/batchCaseTest 一键封装(自动 install/build)
|
|
93
|
+
├── tests/ # 单元测试(vitest,172 个)
|
|
94
|
+
├── app_config.json # App bundle/ability 映射
|
|
95
|
+
└── package.json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 架构说明
|
|
99
|
+
|
|
100
|
+
### 架构模式选择
|
|
101
|
+
|
|
102
|
+
| 架构模式 | `agent.mode` | 说明 |
|
|
103
|
+
|----------|--------------|------|
|
|
104
|
+
| **单层 Agent** | `single`(默认) | 统一 Agent 处理规划与执行,基于 AI SDK,效率高 |
|
|
105
|
+
| **双层 Agent** | `layered` | Planner 决策 + Executor 执行,适合复杂任务拆解 |
|
|
106
|
+
| **Hypium Agent** | `hypium` | 自定义循环 + 子 Agent(滚动搜索/时间选择等),可生成 Hypium 回归脚本 |
|
|
107
|
+
|
|
108
|
+
### 单层 Agent 工作流程
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
用户任务 → SingleAgent → 多模态视觉理解 + 决策 → MCP 设备操作 → 报告生成
|
|
112
|
+
(AI SDK) (HDC/ADB/WDA) (HTML/MD/JSON)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
1. **SingleAgent**:接收用户任务,分析屏幕状态,生成操作指令
|
|
116
|
+
2. **多模态视觉理解**:通过多模态模型理解截图,定位 UI 元素,判断操作结果
|
|
117
|
+
3. **设备层**:通过 MCP 适配器与设备通信,执行点击、滑动等操作
|
|
118
|
+
4. **报告生成**:记录执行过程,输出测试报告
|
|
119
|
+
|
|
120
|
+
### 双层 Agent 工作流程
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
用户任务 → Planner(decision) → 原子操作指令 → Executor(execute) → 设备操作
|
|
124
|
+
(HDC 设备)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
1. **Planner**:分析当前状态,生成具体操作指令
|
|
128
|
+
2. **Executor**:通过视觉识别定位 UI 元素,执行点击、滑动等操作
|
|
129
|
+
3. **设备层**:通过 HDC 协议与 HarmonyOS 设备通信
|
|
130
|
+
|
|
131
|
+
## 环境要求
|
|
132
|
+
|
|
133
|
+
### 系统要求
|
|
134
|
+
|
|
135
|
+
- **操作系统**:Windows / Linux / macOS
|
|
136
|
+
- **Node.js**:>= 18(推荐 20 LTS)
|
|
137
|
+
- **包管理器**:pnpm(启用 workspaces)
|
|
138
|
+
|
|
139
|
+
### HarmonyOS 设备驱动(纯 TS)
|
|
140
|
+
|
|
141
|
+
> HarmonyOS 设备测试通过纯 TypeScript 的 HDC 适配器直接驱动 `hdc` 命令。
|
|
142
|
+
|
|
143
|
+
HarmonyOS 适配器(`src/core/mcp/harmony_hdc_adapter.ts`)通过 `hdc shell` 执行 `uitest uiInput`(点击/滑动/输入)、`snapshot_display`(截图)、`uitest dumpLayout`(布局)、`aa`(应用启停)、`bm`(清数据)、`power-shell`(点亮/解锁)等原语,进程内直接完成设备操作,无子进程、无 HTTP 服务。
|
|
144
|
+
|
|
145
|
+
Android/iOS 平台使用 `@mobilenext/mobile-mcp`(通过 npx 自动安装)。
|
|
146
|
+
|
|
147
|
+
### 设备要求
|
|
148
|
+
|
|
149
|
+
- **HarmonyOS 设备**:支持 HDC 协议的设备或模拟器
|
|
150
|
+
- **HDC 工具**:已安装并配置 `hdc` 命令行工具(加入 PATH)
|
|
151
|
+
- **网络连接**:开发机与设备网络连通
|
|
152
|
+
|
|
153
|
+
## 配置说明
|
|
154
|
+
|
|
155
|
+
配置文件位于 `src/common/config/config.yaml`。CLI 可通过 `--config` 指定自定义路径。
|
|
156
|
+
|
|
157
|
+
### 模型配置
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
model:
|
|
161
|
+
unified: # 单层模式使用
|
|
162
|
+
name: "qwen3.7-plus"
|
|
163
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
164
|
+
api_key: "YOUR_API_KEY_HERE" # 必填
|
|
165
|
+
provider: "openai" # openai / azure
|
|
166
|
+
temperature: 0.1
|
|
167
|
+
top_p: 0.9
|
|
168
|
+
frequency_penalty: 0.5
|
|
169
|
+
max_tokens: 1024
|
|
170
|
+
timeout: 600
|
|
171
|
+
max_retries: 3
|
|
172
|
+
prompt_type: "v2.0" # 提示词版本
|
|
173
|
+
|
|
174
|
+
execute: # 双层模式 — 执行模型
|
|
175
|
+
name: "gui-plus-2026-02-26"
|
|
176
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
177
|
+
api_key: "YOUR_API_KEY_HERE" # 必填
|
|
178
|
+
provider: "mai-ui"
|
|
179
|
+
max_steps: 3
|
|
180
|
+
|
|
181
|
+
decision: # 双层模式 — 决策模型
|
|
182
|
+
name: "qwen3.7-plus"
|
|
183
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
184
|
+
api_key: "YOUR_API_KEY_HERE" # 必填
|
|
185
|
+
provider: "openai"
|
|
186
|
+
temperature: 0.0
|
|
187
|
+
top_p: 0.1
|
|
188
|
+
frequency_penalty: 1.0
|
|
189
|
+
|
|
190
|
+
verify: # 验证模型(可选,留空回退到 decision)
|
|
191
|
+
name: ""
|
|
192
|
+
base_url: ""
|
|
193
|
+
api_key: ""
|
|
194
|
+
provider: "openai"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Agent 配置
|
|
198
|
+
|
|
199
|
+
```yaml
|
|
200
|
+
agent:
|
|
201
|
+
mode: "single" # single / layered / hypium
|
|
202
|
+
max_steps: 50 # 最大执行步数
|
|
203
|
+
lang: "zh" # 语言
|
|
204
|
+
enable_preprocess: false # 任务预处理
|
|
205
|
+
enable_hypium_generation: false # 成功执行后生成 Hypium 回归脚本
|
|
206
|
+
stream_log: false # 流式输出模型回复
|
|
207
|
+
debug_mode: null # null / "memory" / "file"
|
|
208
|
+
adapter_class: null # 已废弃:HarmonyOS 默认即 hdc 纯 TS 适配器
|
|
209
|
+
action_interval: 1.5 # 操作间隔(秒)
|
|
210
|
+
max_history_image: 3 # 历史截图保留数量
|
|
211
|
+
screenshot_max_pixels: 1500 # 截图最大像素
|
|
212
|
+
include_previous_screenshot: true # 是否包含上一步截图
|
|
213
|
+
previous_screenshot_compress_ratio: 0.7 # 上一步截图压缩比
|
|
214
|
+
enable_cache: true # 启用 LLM 缓存
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 设备配置
|
|
218
|
+
|
|
219
|
+
```yaml
|
|
220
|
+
device:
|
|
221
|
+
device_sn: null # 设备序列号(留空自动检测)
|
|
222
|
+
ip: "127.0.0.1" # 设备 IP
|
|
223
|
+
port: 8710 # HDC 端口
|
|
224
|
+
device_serial: ""
|
|
225
|
+
hdc_path: "hdc" # HDC 工具路径
|
|
226
|
+
screenshot_quality: 90 # 截图质量
|
|
227
|
+
screenshot_max_width: 1500 # 截图最大宽度
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 日志 / 输出 / 网络配置
|
|
231
|
+
|
|
232
|
+
```yaml
|
|
233
|
+
log:
|
|
234
|
+
level: "INFO"
|
|
235
|
+
device_log_level: "info"
|
|
236
|
+
verbose: true
|
|
237
|
+
max_log_size: 10 # 单文件最大 MB
|
|
238
|
+
max_log_file_num: 5
|
|
239
|
+
enable_console_log: true
|
|
240
|
+
enable_file_log: true
|
|
241
|
+
|
|
242
|
+
output:
|
|
243
|
+
json_output: false
|
|
244
|
+
report_dir: null # 自定义报告目录
|
|
245
|
+
root_dir: "reports" # 报告根目录
|
|
246
|
+
report_name: "autotest_report"
|
|
247
|
+
embed_images: false
|
|
248
|
+
embed_max_pixels: 800
|
|
249
|
+
|
|
250
|
+
network:
|
|
251
|
+
timeout: 600
|
|
252
|
+
max_retries: 3
|
|
253
|
+
no_proxy: ""
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 失败分析配置(`analyze` 命令)
|
|
257
|
+
|
|
258
|
+
```yaml
|
|
259
|
+
analyze:
|
|
260
|
+
model_name: "" # 留空则回退到 decision
|
|
261
|
+
base_url: ""
|
|
262
|
+
api_key: ""
|
|
263
|
+
temperature: 0.1
|
|
264
|
+
max_tokens: 4096
|
|
265
|
+
timeout: 90
|
|
266
|
+
max_retries: 3
|
|
267
|
+
enable_multimodal: true
|
|
268
|
+
max_screenshot_pixels: 800
|
|
269
|
+
max_key_steps: 5
|
|
270
|
+
only_fail: true # 仅分析失败用例
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 使用方法
|
|
274
|
+
|
|
275
|
+
> 以下命令均在 `AutoTest/` 目录下运行。首次使用前需先完成 [安装步骤](../../README.md#安装步骤)。
|
|
276
|
+
|
|
277
|
+
测试用例有三种运行方式,按场景选择:
|
|
278
|
+
|
|
279
|
+
| 方式 | 命令 | 适用场景 |
|
|
280
|
+
|------|------|---------|
|
|
281
|
+
| **caseTest**(推荐) | `npm run caseTest -- <参数>` | 日常单用例运行,自动增量构建 |
|
|
282
|
+
| **batchCaseTest** | `npm run batchCaseTest <文件>` | 批量执行 JSONL/JSON 用例 |
|
|
283
|
+
| **直接 CLI** | `node dist/autotest-cli.js run <参数>` | 需手动 build,适合调试编译产物 |
|
|
284
|
+
|
|
285
|
+
### 方式一:caseTest(推荐)
|
|
286
|
+
|
|
287
|
+
`caseTest` 通过 `runner.mjs` 自动检测源码变更并增量构建,无需手动 `npm run build`,然后以 `run` 子命令调用 `dist/autotest-cli.js`:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
cd AutoTest
|
|
291
|
+
|
|
292
|
+
# 基本用法:-- 后传递 CLI 参数
|
|
293
|
+
npm run caseTest -- --task "打开设置应用,查看 WiFi 列表"
|
|
294
|
+
|
|
295
|
+
# 指定模式 / 平台
|
|
296
|
+
npm run caseTest -- --task "测试任务描述" --mode layered --platform harmony
|
|
297
|
+
|
|
298
|
+
# 从 JSON 用例文件加载(第 10 条用例)
|
|
299
|
+
npm run caseTest -- --case-file cases.json --case-index 10
|
|
300
|
+
|
|
301
|
+
# 指定配置文件
|
|
302
|
+
npm run caseTest -- --task "测试任务" --config /path/to/config.yaml
|
|
303
|
+
|
|
304
|
+
# 列出设备
|
|
305
|
+
npm run caseTest -- list-devices
|
|
306
|
+
|
|
307
|
+
# 查看配置
|
|
308
|
+
npm run caseTest -- config --show
|
|
309
|
+
|
|
310
|
+
# 分析失败任务
|
|
311
|
+
npm run caseTest -- analyze --task-id 20260714_145936_001 --case-idx 0
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### 使用示例
|
|
315
|
+
|
|
316
|
+
#### 示例1:通知栏测试
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
npm run caseTest -- --task "动作:打开 com.example.saltplayerharmony -> 播放歌曲 -> 下拉通知栏观察歌曲显示 -> 切换歌曲 -> 再次下拉通知栏
|
|
320
|
+
预期结果:通知栏显示当前歌曲封面,与 App 内一致;切歌时通知内容自动更新"
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### 示例2:长按预览测试
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
npm run caseTest -- --task "测试步骤:
|
|
327
|
+
1、打开 com.example.webfifth8,点击【6.0.0.37】按钮,点击【SR20250224905259】按钮,
|
|
328
|
+
连续向上滑动找到黑色加粗字体的【地址】,长按【广州市白云区机场路1234号】,5 秒后点击右侧空白
|
|
329
|
+
2、长按【123 Queen's Road, London, UK】,5 秒后点击右侧空白
|
|
330
|
+
预期结果:
|
|
331
|
+
1、弹出预览项和【导航前往】【复制】【选择文本】菜单
|
|
332
|
+
2、不弹出预览项和菜单"
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
#### 示例3:指定模式 / 平台 / 配置文件
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
npm run caseTest -- \
|
|
339
|
+
--task "打开设置应用,查看 WiFi 列表" \
|
|
340
|
+
--mode layered \
|
|
341
|
+
--platform harmony \
|
|
342
|
+
--config /path/to/config.yaml
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
#### 示例4:从 JSON 用例文件加载
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
npm run caseTest -- --case-file cases.json --case-index 10
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### 示例5:列出设备 / 查看配置 / 分析失败
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
npm run caseTest -- list-devices
|
|
355
|
+
npm run caseTest -- config --show
|
|
356
|
+
npm run caseTest -- analyze --task-id 20260714_145936_001 --case-idx 0
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 方式二:批量执行
|
|
360
|
+
|
|
361
|
+
通过 `batchCaseTest` 批量执行 JSONL/JSON 用例,具备断点续跑、进度报告、分类汇总能力。同样通过 `runner.mjs` 自动增量构建。
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
cd AutoTest
|
|
365
|
+
|
|
366
|
+
# 位置参数:第 1 个 = 用例文件,第 2 个 = category(可选,默认 default)
|
|
367
|
+
npm run batchCaseTest cases.jsonl
|
|
368
|
+
npm run batchCaseTest cases.jsonl smoke
|
|
369
|
+
|
|
370
|
+
# 显式用 -- 标志(等价写法)
|
|
371
|
+
npm run batchCaseTest -- --testcases cases.jsonl --category smoke
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### 批量执行特性
|
|
375
|
+
|
|
376
|
+
- 支持断点续执行(自动跳过已完成用例)
|
|
377
|
+
- 支持指定起始索引
|
|
378
|
+
- 定期进度报告(每 10 例)
|
|
379
|
+
- 自动更新原始用例文件状态与分类报告
|
|
380
|
+
- 输出 JSONL/CSV 结果与汇总
|
|
381
|
+
- 单个用例超时 10 分钟
|
|
382
|
+
|
|
383
|
+
### 方式三:直接调用 CLI(需先构建)
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
cd AutoTest
|
|
387
|
+
npm run build # tsc 编译到 dist/
|
|
388
|
+
node dist/autotest-cli.js run --task "打开设置应用,查看 WiFi 列表"
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### CLI 命令参考
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
Usage: autotest <command> [options]
|
|
395
|
+
|
|
396
|
+
Commands:
|
|
397
|
+
run Run a test task
|
|
398
|
+
list-devices List connected devices
|
|
399
|
+
analyze Analyze a failed task
|
|
400
|
+
config Show or update configuration
|
|
401
|
+
|
|
402
|
+
Run options:
|
|
403
|
+
--task <desc> Task description
|
|
404
|
+
--case-file <path> Path to a JSON case file (use with --case-index)
|
|
405
|
+
--case-index <n> 1-based case index in the file
|
|
406
|
+
--device <sn> Device serial number
|
|
407
|
+
--platform <p> Platform: harmony | android | ios
|
|
408
|
+
--mode <m> Agent mode: single | layered | hypium
|
|
409
|
+
--ip <addr> Device IP address
|
|
410
|
+
--port <num> Device port number
|
|
411
|
+
--task-name <name> Test case name
|
|
412
|
+
--case-num <num> Case number
|
|
413
|
+
--report-dir <dir> Report output directory
|
|
414
|
+
--prompt-version <v> Prompt version
|
|
415
|
+
--config <path> Path to config.yaml (default: bundled config.yaml)
|
|
416
|
+
|
|
417
|
+
Analyze options:
|
|
418
|
+
--task-id <id> Task ID to analyze
|
|
419
|
+
--case-idx <n> Case index within the task
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## 测试报告
|
|
423
|
+
|
|
424
|
+
### 报告目录结构
|
|
425
|
+
|
|
426
|
+
```
|
|
427
|
+
reports/
|
|
428
|
+
└── <taskId>/ # 如 20260714_145936_001
|
|
429
|
+
├── <taskId>.html # HTML 报告
|
|
430
|
+
├── <taskId>.md # Markdown 报告
|
|
431
|
+
├── <taskId>.json # JSON 数据
|
|
432
|
+
├── layout/ # 布局数据
|
|
433
|
+
├── log/ # 日志文件
|
|
434
|
+
├── screenPath/ # 截图目录
|
|
435
|
+
└── analysis_report/ # analyze 命令的根因分析报告
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### 报告内容
|
|
439
|
+
|
|
440
|
+
- **执行时间线**:每一步操作与结果
|
|
441
|
+
- **Bug 发现**:异常与缺陷记录
|
|
442
|
+
- **截图记录**:每步操作截图
|
|
443
|
+
- **Token 消耗**:模型 Token 统计
|
|
444
|
+
- **最终判定**:测试通过 / 失败
|
|
445
|
+
- **根因分析**(`analyze` 命令):失败原因、改进建议、关键截图、评分
|
|
446
|
+
|
|
447
|
+
## Debug 调试模式
|
|
448
|
+
|
|
449
|
+
任务执行后可通过浏览器与 Agent 交互式复盘。
|
|
450
|
+
|
|
451
|
+
### 启用方式
|
|
452
|
+
|
|
453
|
+
在 `config.yaml` 中配置:
|
|
454
|
+
|
|
455
|
+
```yaml
|
|
456
|
+
agent:
|
|
457
|
+
debug_mode: "file"
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
- `null` — 不启用
|
|
461
|
+
- `"memory"` — 内存模式(窗口关闭后 session 丢失)
|
|
462
|
+
- `"file"` — 文件模式(session 保存在报告目录,可上传恢复)
|
|
463
|
+
|
|
464
|
+
### 使用流程
|
|
465
|
+
|
|
466
|
+
1. 任务执行完成后,浏览器打开 Dashboard 调试页
|
|
467
|
+
2. 显示任务执行历史(思考过程 + 输出内容)
|
|
468
|
+
3. 可继续对话追问、验证决策逻辑
|
|
469
|
+
4. 输入 `exit` 或点击「退出」结束
|
|
470
|
+
|
|
471
|
+
## 作为三方库集成
|
|
472
|
+
|
|
473
|
+
本包可作为 npm 依赖被其他工程集成,通过 `AutoTestAgent` 门面类创建实例并下发任务。
|
|
474
|
+
|
|
475
|
+
### 安装
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
npm install @autotest/agent
|
|
479
|
+
# 或
|
|
480
|
+
pnpm add @autotest/agent
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### 快速开始
|
|
484
|
+
|
|
485
|
+
```ts
|
|
486
|
+
import { AutoTestAgent } from '@autotest/agent';
|
|
487
|
+
|
|
488
|
+
const agent = new AutoTestAgent({
|
|
489
|
+
apiKey: 'sk-xxx',
|
|
490
|
+
modelName: 'qwen3.7-plus',
|
|
491
|
+
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
|
492
|
+
deviceSn: 'LNG0223721000045', // 可选,留空自动检测
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const result = await agent.runTask('打开设置应用,查看 WiFi 列表');
|
|
496
|
+
console.log(result.status); // 'completed' | 'failed'
|
|
497
|
+
console.log(result.tip); // 执行摘要
|
|
498
|
+
console.log(result.reportDir); // 报告目录路径
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### 配置参数
|
|
502
|
+
|
|
503
|
+
`AutoTestAgent` 构造函数接收 `AutoTestAgentConfig`:
|
|
504
|
+
|
|
505
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
506
|
+
|------|------|------|------|
|
|
507
|
+
| `apiKey` | `string` | 是 | LLM API Key |
|
|
508
|
+
| `modelName` | `string` | 是 | 模型名称 |
|
|
509
|
+
| `baseUrl` | `string` | 是 | LLM API 地址 |
|
|
510
|
+
| `provider` | `string` | 否 | 模型提供商,默认 `'openai'` |
|
|
511
|
+
| `deviceSn` | `string` | 否 | 设备序列号,留空自动检测 |
|
|
512
|
+
| `ip` | `string` | 否 | 设备 IP,默认 `127.0.0.1` |
|
|
513
|
+
| `port` | `number` | 否 | 设备端口,默认 `8710` |
|
|
514
|
+
| `platform` | `'harmony' \| 'android' \| 'ios'` | 否 | 指定平台,跳过自动检测 |
|
|
515
|
+
| `agentMode` | `'single' \| 'layered' \| 'hypium'` | 否 | Agent 模式,默认 `'single'` |
|
|
516
|
+
| `maxSteps` | `number` | 否 | 最大执行步数,默认 `100` |
|
|
517
|
+
| `reportDir` | `string` | 否 | 报告输出目录,默认 `reports` |
|
|
518
|
+
| `enableCache` | `boolean` | 否 | 启用 LLM 缓存,默认 `true` |
|
|
519
|
+
| `configPath` | `string` | 否 | 加载完整 YAML 配置文件路径 |
|
|
520
|
+
| `configOverrides` | `Record<string, unknown>` | 否 | 高级覆盖,结构同 `AppConfig` |
|
|
521
|
+
|
|
522
|
+
### runTask 方法
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
const result = await agent.runTask(task: string, options?: RunTaskOptions);
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
`RunTaskOptions` 可选参数(覆盖构造时的配置):
|
|
529
|
+
|
|
530
|
+
| 参数 | 类型 | 说明 |
|
|
531
|
+
|------|------|------|
|
|
532
|
+
| `agentMode` | `AgentMode` | 覆盖 Agent 模式 |
|
|
533
|
+
| `platform` | `DevicePlatform` | 覆盖平台 |
|
|
534
|
+
| `deviceSn` | `string` | 覆盖设备序列号 |
|
|
535
|
+
| `ip` / `port` | `string` / `number` | 覆盖设备地址 |
|
|
536
|
+
| `reportDir` | `string` | 覆盖报告目录 |
|
|
537
|
+
| `taskName` | `string` | 用例名称 |
|
|
538
|
+
| `caseNum` | `string` | 用例编号 |
|
|
539
|
+
| `maxSteps` | `number` | 覆盖最大步数 |
|
|
540
|
+
| `configOverrides` | `Record<string, unknown>` | 运行时配置覆盖 |
|
|
541
|
+
|
|
542
|
+
### 其他方法
|
|
543
|
+
|
|
544
|
+
```ts
|
|
545
|
+
// 查询任务结果
|
|
546
|
+
const result = await agent.getTaskResult(taskId);
|
|
547
|
+
|
|
548
|
+
// 分析失败根因
|
|
549
|
+
const analysis = await agent.analyzeFailure(taskId, caseIdx);
|
|
550
|
+
|
|
551
|
+
// 列出设备
|
|
552
|
+
const devices = await agent.listDevices();
|
|
553
|
+
|
|
554
|
+
// 停止正在运行的任务
|
|
555
|
+
agent.stopTask();
|
|
556
|
+
|
|
557
|
+
// 读取/更新配置
|
|
558
|
+
const config = agent.getConfig();
|
|
559
|
+
agent.updateConfig({ agent: { maxSteps: 50 } });
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### 使用完整 YAML 配置
|
|
563
|
+
|
|
564
|
+
如果需要配置双层 Agent(execute/decision 模型)、分析模型等高级选项,可通过 `configPath` 加载完整 YAML:
|
|
565
|
+
|
|
566
|
+
```ts
|
|
567
|
+
const agent = new AutoTestAgent({
|
|
568
|
+
apiKey: 'sk-xxx', // 覆盖 YAML 中的 api_key
|
|
569
|
+
modelName: 'qwen3.7-plus',
|
|
570
|
+
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
|
571
|
+
configPath: '/path/to/config.yaml',
|
|
572
|
+
});
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
## 脚本
|
|
576
|
+
|
|
577
|
+
在 `AutoTest/` 目录下:
|
|
578
|
+
|
|
579
|
+
```bash
|
|
580
|
+
npm run build # tsc 编译到 dist/
|
|
581
|
+
npm run caseTest # 单用例运行(自动增量构建,推荐)
|
|
582
|
+
npm run batchCaseTest # 批量用例运行(自动增量构建)
|
|
583
|
+
npm test # 运行单元测试(vitest run)
|
|
584
|
+
npm run test:watch # 监听模式单元测试
|
|
585
|
+
npm run typecheck # 类型检查(tsc --noEmit)
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
## 单元测试
|
|
589
|
+
|
|
590
|
+
单元测试位于 `tests/`,使用 vitest,共 172 个测试(13 个文件):
|
|
591
|
+
|
|
592
|
+
| 测试文件 | 覆盖模块 | 测试数 |
|
|
593
|
+
|---------|---------|-------|
|
|
594
|
+
| `config-manager.test.ts` | 配置加载/合并/Zod 校验 | 22 |
|
|
595
|
+
| `agent-error.test.ts` | 结构化错误/序列化/分类 | 22 |
|
|
596
|
+
| `agent-api.test.ts` | AgentAPI 接口/状态转换 | 24 |
|
|
597
|
+
| `adapter.test.ts` | 适配器/平台差异/工厂选择 | 19 |
|
|
598
|
+
| `llm-caller.test.ts` | LLM 调用封装/mock | 15 |
|
|
599
|
+
| `report-generator.test.ts` | 报告生成/HTML marker/标签剥离 | 11 |
|
|
600
|
+
| `analyzer-parse.test.ts` | 失败分析输出解析 | 10 |
|
|
601
|
+
| `single-agent.test.ts` | Agent 执行/截图注入/abort | 9 |
|
|
602
|
+
| `key-steps-builder.test.ts` | 关键步骤构建 | 9 |
|
|
603
|
+
| `data-loader.test.ts` | 数据加载 | 9 |
|
|
604
|
+
| `hdc-adapter.test.ts` | HarmonyHdcAdapter 命令派发/坐标转换 | 9 |
|
|
605
|
+
| `autotest-agent.test.ts` | 门面类(mock adapter_factory,密闭) | 8 |
|
|
606
|
+
| `logger.test.ts` | 文件日志/格式 | 5 |
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
cd AutoTest
|
|
610
|
+
npm test # 运行全部测试
|
|
611
|
+
npx vitest run tests/config-manager.test.ts # 运行单个文件
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
## 开发扩展
|
|
615
|
+
|
|
616
|
+
### 自定义提示词
|
|
617
|
+
|
|
618
|
+
编辑提示词模板:`src/core/prompt/templates/`(`single/` · `hypium/` · `planner/` · `splitter/`)。
|
|
619
|
+
|
|
620
|
+
### 添加新的 MCP 工具
|
|
621
|
+
|
|
622
|
+
1. 在 `src/core/mcp/mcp_tools.ts`(双层)或 `local_tools.ts`(本地)中添加
|
|
623
|
+
2. 在对应提示词模板中更新工具说明
|
|
624
|
+
|
|
625
|
+
### 自定义适配器
|
|
626
|
+
|
|
627
|
+
参考 `src/core/mcp/harmony_hdc_adapter.ts`,继承 `base_adapter.ts` 中的 `MCPDeviceAdapter`,并在 `adapter_factory.ts` 注册。
|
|
628
|
+
|
|
629
|
+
## 常见问题
|
|
630
|
+
|
|
631
|
+
### Q1: 设备连接失败
|
|
632
|
+
|
|
633
|
+
- 确认 HDC 工具已安装并加入 PATH
|
|
634
|
+
- 运行 `hdc list` 查看设备是否在线
|
|
635
|
+
- 检查 `device.ip` / `device.port` 配置
|
|
636
|
+
|
|
637
|
+
### Q2: 如何使用自定义模型?
|
|
638
|
+
|
|
639
|
+
在 `config.yaml` 修改对应模型的 `base_url` 和 `api_key`,支持所有 OpenAI 兼容 API。
|
|
640
|
+
|
|
641
|
+
### Q3: 如何切换 Agent 架构模式?
|
|
642
|
+
|
|
643
|
+
- 修改 `config.yaml` 的 `agent.mode`
|
|
644
|
+
- 或命令行 `--mode single|layered|hypium`
|
|
645
|
+
|
|
646
|
+
### Q4: 如何查看测试报告?
|
|
647
|
+
|
|
648
|
+
查看 `reports/<taskId>/<taskId>.html`。
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ConfigManager } from '../common/config/manager';
|
|
2
|
+
import type { AppConfig } from '../common/config/types';
|
|
3
|
+
import type { MCPDeviceAdapter } from '../core/mcp/types';
|
|
4
|
+
import type { TaskOptions, TaskResult, AnalysisResult, DeviceInfo } from './types';
|
|
5
|
+
export declare class AgentAPIImpl {
|
|
6
|
+
private configManager;
|
|
7
|
+
private adapter;
|
|
8
|
+
private tasks;
|
|
9
|
+
private currentAbortController;
|
|
10
|
+
constructor(configManager: ConfigManager, adapter?: MCPDeviceAdapter);
|
|
11
|
+
stopTask(): void;
|
|
12
|
+
runTask(task: string, options: TaskOptions): Promise<TaskResult>;
|
|
13
|
+
/**
|
|
14
|
+
* 单次 agent 执行(loop 编排器的 execute 原语)。
|
|
15
|
+
* 假定 adapter 已连接(由 runTaskLoop 在循环前统一连接),在给定 reportDir 跑一轮。
|
|
16
|
+
*/
|
|
17
|
+
private executeOnce;
|
|
18
|
+
/**
|
|
19
|
+
* Loop 闭环执行入口(移植自 python loop/orchestrator.run)。
|
|
20
|
+
* 连接 adapter 一次,注入 execute/analyze/rewrite 三个原语,跑闭环状态机。
|
|
21
|
+
*/
|
|
22
|
+
private runTaskLoop;
|
|
23
|
+
resumeTask(taskId: string, startIndex?: number): Promise<TaskResult>;
|
|
24
|
+
listDevices(): Promise<DeviceInfo[]>;
|
|
25
|
+
getTaskResult(taskId: string): Promise<TaskResult>;
|
|
26
|
+
analyzeFailure(taskId: string, caseIdx: number): Promise<AnalysisResult>;
|
|
27
|
+
getConfig(): AppConfig;
|
|
28
|
+
updateConfig(partial: Record<string, unknown>): AppConfig;
|
|
29
|
+
getPromptVersions(category: string): string[];
|
|
30
|
+
private generateTaskId;
|
|
31
|
+
private transitionTask;
|
|
32
|
+
private createAgent;
|
|
33
|
+
private sourceForMode;
|
|
34
|
+
private createLLMCaller;
|
|
35
|
+
private createRecordingHooks;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=agent_api.d.ts.map
|