@autotest/agent 0.0.5 → 0.0.6
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 +3 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/api/agent_api.js +7 -7
- package/dist/autotest-cli.js +44 -44
- package/dist/common/config/config.yaml +1 -0
- package/dist/common/config/config_validator.js +1 -1
- package/dist/common/config/manager.d.ts +10 -10
- package/dist/common/config/manager.js +12 -12
- package/dist/common/config/output.js +1 -1
- package/dist/common/config/types.d.ts +28 -1
- package/dist/common/config/types.js +12 -11
- package/dist/common/dfx/recording_fetch.js +1 -1
- package/dist/common/dfx/source.js +1 -1
- package/dist/common/image_helper.d.ts +2 -2
- package/dist/common/image_helper.js +2 -2
- package/dist/common/llm_cache/cache_transport.d.ts +1 -1
- package/dist/common/llm_cache/cache_transport.js +1 -1
- package/dist/common/llm_cache/prompt_cache.d.ts +2 -2
- package/dist/common/llm_cache/prompt_cache.js +2 -2
- package/dist/common/model/custom_model.js +5 -43
- package/dist/common/utils.d.ts +5 -5
- package/dist/common/utils.js +5 -5
- package/dist/core/agent/layered_agent/agent_registry.d.ts +3 -1
- package/dist/core/agent/layered_agent/agent_registry.js +12 -5
- package/dist/core/agent/layered_agent/decision.js +3 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +1 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +34 -34
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +1 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +8 -8
- package/dist/core/agent/report_analyzer_agent/agent.js +4 -4
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js +11 -11
- package/dist/core/agent/report_analyzer_agent/report_writer.js +139 -139
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/tools.js +2 -2
- package/dist/core/agent/report_analyzer_agent/types.js +2 -2
- package/dist/core/agent/rewrite_agent/agent.d.ts +5 -5
- package/dist/core/agent/rewrite_agent/agent.js +5 -5
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/guardrails.js +1 -1
- package/dist/core/agent/rewrite_agent/mapping.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/mapping.js +3 -3
- package/dist/core/agent/rewrite_agent/parse.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/parse.js +1 -1
- package/dist/core/agent/rewrite_agent/types.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/types.js +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +1 -2
- package/dist/core/agent/single_agent/agent.js +29 -26
- package/dist/core/agent/single_agent/hook_manager.d.ts +1 -2
- package/dist/core/agent/single_agent/hook_manager.js +1 -2
- package/dist/core/agent/single_agent/image_utils.d.ts +1 -2
- package/dist/core/agent/single_agent/image_utils.js +1 -2
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +5 -5
- package/dist/core/agent/single_agent/scroll_search_agent.js +39 -10
- package/dist/core/agent/single_agent/subagent_manager.d.ts +1 -2
- package/dist/core/agent/single_agent/subagent_manager.js +2 -3
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +3 -3
- package/dist/core/agent/single_agent/tool_recorder_hook.js +3 -3
- package/dist/core/device/hdc/apps.js +1 -1
- package/dist/core/device/hdc/device.d.ts +1 -1
- package/dist/core/device/hdc/device.js +1 -1
- package/dist/core/device/hdc/screenshot.js +1 -1
- package/dist/core/device/index.d.ts +2 -2
- package/dist/core/device/index.js +2 -2
- package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
- package/dist/core/knowledge/knowledge_manager.js +3 -3
- package/dist/core/knowledge/vectordb.d.ts +5 -5
- package/dist/core/knowledge/vectordb.js +5 -5
- package/dist/core/mcp/harmony_hdc_adapter.js +21 -5
- package/dist/core/mcp/mcp_tools.d.ts +10 -2
- package/dist/core/mcp/mcp_tools.js +69 -6
- package/dist/core/memory/_utils.d.ts +1 -1
- package/dist/core/memory/_utils.js +1 -1
- package/dist/core/memory/context_compressor.js +2 -2
- package/dist/core/memory/index.d.ts +1 -1
- package/dist/core/memory/index.js +1 -1
- package/dist/core/memory/memory_manager.d.ts +1 -1
- package/dist/core/memory/memory_manager.js +1 -1
- package/dist/core/memory/replan_manager.d.ts +1 -1
- package/dist/core/memory/replan_manager.js +1 -1
- package/dist/core/memory/tool_player.d.ts +5 -5
- package/dist/core/memory/tool_player.js +5 -5
- package/dist/core/memory/tool_player_popup.d.ts +1 -1
- package/dist/core/memory/tool_player_popup.js +12 -12
- package/dist/core/memory/tool_player_replan.d.ts +1 -1
- package/dist/core/memory/tool_player_replan.js +2 -2
- package/dist/core/memory/tool_player_xpath.d.ts +3 -3
- package/dist/core/memory/tool_player_xpath.js +3 -3
- package/dist/core/prompt/prompt_loader.d.ts +1 -1
- package/dist/core/prompt/prompt_loader.js +3 -3
- package/dist/core/skill/skill_manager.d.ts +2 -2
- package/dist/core/skill/skill_manager.js +1 -1
- package/dist/data_types/case.js +1 -1
- package/dist/data_types/screen.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/loop/cli.d.ts +4 -4
- package/dist/loop/cli.js +4 -4
- package/dist/loop/orchestrator.d.ts +6 -6
- package/dist/loop/orchestrator.js +7 -7
- package/dist/loop/result_writer.d.ts +1 -1
- package/dist/loop/result_writer.js +36 -36
- package/dist/loop/types.d.ts +1 -1
- package/dist/loop/types.js +1 -1
- package/dist/reporter/html_template/index.js +14 -9
- package/dist/tools/batch_runner.js +3 -3
- package/dist/tools/case_runner/report.d.ts +1 -1
- package/dist/tools/case_runner/report.js +59 -59
- package/dist/tools/case_runner/runner.d.ts +3 -3
- package/dist/tools/case_runner/runner.js +8 -8
- package/dist/tools/config/config_tool.d.ts +6 -6
- package/dist/tools/config/config_tool.js +27 -27
- package/dist/tools/prompt_compare/compare_runner.d.ts +2 -2
- package/dist/tools/prompt_compare/compare_runner.js +16 -16
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Type definitions for the ReportAnalyzerAgent.
|
|
3
|
-
// Mirrors the
|
|
3
|
+
// Mirrors the types.py with TypeScript classes/interfaces.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.AnalyzerOutput = exports.RootCauseClassification = exports.VALID_CATEGORY_LABELS = exports.ACCURACY_CN_TO_EN = exports.VALID_ACCURACY_VALUES = exports.ROOT_CAUSE_SUB_CATEGORIES = exports.AccuracyVerdict = exports.ROOT_CAUSE_CATEGORY_LABELS = exports.RootCauseCategory = 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 = void 0;
|
|
6
6
|
exports.resolveSubCategory = resolveSubCategory;
|
|
@@ -15,7 +15,7 @@ exports.EVIDENCE_COMPLETE = 'complete';
|
|
|
15
15
|
exports.EVIDENCE_PARTIAL = 'partial';
|
|
16
16
|
exports.EVIDENCE_MISSING = 'missing';
|
|
17
17
|
exports.EVIDENCE_NONE = 'none';
|
|
18
|
-
// 5 top-level root cause categories
|
|
18
|
+
// 5 top-level root cause categories.
|
|
19
19
|
// Values are English labels used as identifiers throughout the pipeline.
|
|
20
20
|
var RootCauseCategory;
|
|
21
21
|
(function (RootCauseCategory) {
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RewriteAgent — 测试用例改写 Agent —
|
|
2
|
+
* RewriteAgent — 测试用例改写 Agent —
|
|
3
3
|
*
|
|
4
4
|
* 二元门决策 + LLM 自决子动作:
|
|
5
5
|
* 1. decideAction 做二元门判定(NO_REWRITE / REWRITE)
|
|
6
6
|
* 2. NO_REWRITE 直接返回(不调 LLM)——保守终止安全门
|
|
7
7
|
* 3. REWRITE → runAgentWithRetry(max 3):LLMCaller.call → parseRewriteResult →
|
|
8
|
-
*
|
|
8
|
+
* validateRewriteOutput;guardrail 触发带原因重跑;重试超限降级 NO_REWRITE
|
|
9
9
|
*
|
|
10
10
|
* 仿 Node.js ReportAnalyzerAgent 的 LLM 调用模式(LLMCaller.call,无 tools 纯文本输出)。
|
|
11
11
|
*/
|
|
12
12
|
import type { ModelConfig } from '../../../common/config/types';
|
|
13
13
|
import { type RewriteInput, type RewriteOutput } from './types';
|
|
14
14
|
import type { AnalyzerOutput } from '../report_analyzer_agent/types';
|
|
15
|
-
/** 裁剪 AnalyzerOutput 为 summary dict
|
|
15
|
+
/** 裁剪 AnalyzerOutput 为 summary dict(
|
|
16
16
|
* 只含关键字段,喂给 rewriter 与写入 loop_result.json。不喂 trace/screenshot 等。
|
|
17
|
-
* 字段集与
|
|
17
|
+
* 字段集与 对齐(snake_case),category 为 Node.js 分析器的英文标签。 */
|
|
18
18
|
export declare function summarizeAnalyzerOutput(output: AnalyzerOutput): Record<string, unknown>;
|
|
19
19
|
export declare class RewriteAgent {
|
|
20
20
|
private config;
|
|
21
21
|
constructor(config: ModelConfig);
|
|
22
22
|
run(input: RewriteInput): Promise<RewriteOutput>;
|
|
23
23
|
private runAgentWithRetry;
|
|
24
|
-
/** 构建 Agent instructions(填充占位符 + 重试 hint
|
|
24
|
+
/** 构建 Agent instructions(填充占位符 + 重试 hint)。 */
|
|
25
25
|
private buildPrompt;
|
|
26
26
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* RewriteAgent — 测试用例改写 Agent —
|
|
3
|
+
* RewriteAgent — 测试用例改写 Agent —
|
|
4
4
|
*
|
|
5
5
|
* 二元门决策 + LLM 自决子动作:
|
|
6
6
|
* 1. decideAction 做二元门判定(NO_REWRITE / REWRITE)
|
|
7
7
|
* 2. NO_REWRITE 直接返回(不调 LLM)——保守终止安全门
|
|
8
8
|
* 3. REWRITE → runAgentWithRetry(max 3):LLMCaller.call → parseRewriteResult →
|
|
9
|
-
*
|
|
9
|
+
* validateRewriteOutput;guardrail 触发带原因重跑;重试超限降级 NO_REWRITE
|
|
10
10
|
*
|
|
11
11
|
* 仿 Node.js ReportAnalyzerAgent 的 LLM 调用模式(LLMCaller.call,无 tools 纯文本输出)。
|
|
12
12
|
*/
|
|
@@ -56,9 +56,9 @@ const guardrails_1 = require("./guardrails");
|
|
|
56
56
|
const types_1 = require("./types");
|
|
57
57
|
const MAX_RETRIES = 3;
|
|
58
58
|
const REWRITER_PROMPT_PATH = path.join(__dirname, 'prompts', 'rewriter_v1.0.md');
|
|
59
|
-
/** 裁剪 AnalyzerOutput 为 summary dict
|
|
59
|
+
/** 裁剪 AnalyzerOutput 为 summary dict(
|
|
60
60
|
* 只含关键字段,喂给 rewriter 与写入 loop_result.json。不喂 trace/screenshot 等。
|
|
61
|
-
* 字段集与
|
|
61
|
+
* 字段集与 对齐(snake_case),category 为 Node.js 分析器的英文标签。 */
|
|
62
62
|
function summarizeAnalyzerOutput(output) {
|
|
63
63
|
const rc = output.rootCause;
|
|
64
64
|
return {
|
|
@@ -168,7 +168,7 @@ class RewriteAgent {
|
|
|
168
168
|
rawLlmOutput: '',
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
/** 构建 Agent instructions(填充占位符 + 重试 hint
|
|
171
|
+
/** 构建 Agent instructions(填充占位符 + 重试 hint)。 */
|
|
172
172
|
buildPrompt(input, basePrompt, retryReasons) {
|
|
173
173
|
const summary = input.analyzerOutputSummary ?? {};
|
|
174
174
|
const rootCause = summary['root_cause'] ?? null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* 根因→改写决策的二元门判定 —
|
|
3
|
+
* 根因→改写决策的二元门判定 —
|
|
4
4
|
*
|
|
5
5
|
* decideAction(rootCauseCategory, subCategory) -> RewriteDecision
|
|
6
6
|
* 根据归因 Agent 输出的一级根因,执行二元门判定:是否进入改写路径。
|
|
@@ -17,7 +17,7 @@ const types_1 = require("./types");
|
|
|
17
17
|
/**
|
|
18
18
|
* 不可改写的根因 category 集合。
|
|
19
19
|
* Node.js ReportAnalyzerAgent 使用英文标签(RootCauseCategory enum 值),
|
|
20
|
-
* 对应
|
|
20
|
+
* 对应 的 {应用问题, 环境问题, 无问题}。Node.js 无独立 "No Issue" 类别
|
|
21
21
|
* (通过/无问题在 loop Step 3 PASS 检查先行拦截)。
|
|
22
22
|
*/
|
|
23
23
|
const _CATEGORY_CN_TO_EN = {
|
|
@@ -31,7 +31,7 @@ function normalizeCategory(cat) {
|
|
|
31
31
|
return _CATEGORY_CN_TO_EN[cat] ?? cat;
|
|
32
32
|
}
|
|
33
33
|
const NO_REWRITE_CATEGORIES = new Set(['Application Issue', 'Environment Issue', 'No Issue']);
|
|
34
|
-
/** 触发改写的根因 category 集合(对应
|
|
34
|
+
/** 触发改写的根因 category 集合(对应 {用例问题, Agent问题})。 */
|
|
35
35
|
const REWRITE_CATEGORIES = new Set(['Test Case Issue', 'Agent Issue']);
|
|
36
36
|
/**
|
|
37
37
|
* 二元门:根因 → 改写决策(NO_REWRITE vs REWRITE)。
|
|
@@ -33,8 +33,7 @@ export declare class SingleAgent {
|
|
|
33
33
|
private parseTextAction;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* FastActionAgent — ≤5-step quick-execute mode
|
|
37
|
-
* hybrid_agent/agent/fast_action.py). Applies fast defaults: maxSteps=5,
|
|
36
|
+
* FastActionAgent — ≤5-step quick-execute mode. Applies fast defaults: maxSteps=5,
|
|
38
37
|
* no retries, no post-tool screenshots, minimal inject, FAST_ACTION prompt.
|
|
39
38
|
*/
|
|
40
39
|
export declare class FastActionAgent extends SingleAgent {
|
|
@@ -59,7 +59,7 @@ class SingleAgent {
|
|
|
59
59
|
this.reportGenerator.setTestCase(testCase);
|
|
60
60
|
this.reportGenerator.startTask();
|
|
61
61
|
// Initialize compressed session (replaces raw conversationHistory + trimHistory).
|
|
62
|
-
//
|
|
62
|
+
//
|
|
63
63
|
this.session = new compressed_session_1.CompressedSession({
|
|
64
64
|
autoCompress: true,
|
|
65
65
|
modelConfig: this.config.model.unified,
|
|
@@ -79,7 +79,7 @@ class SingleAgent {
|
|
|
79
79
|
for (let attempt = 0; attempt <= this.maxResultRetries; attempt++) {
|
|
80
80
|
this.stepNumber = 0;
|
|
81
81
|
finalStatus = 'UNKNOWN';
|
|
82
|
-
//
|
|
82
|
+
//
|
|
83
83
|
// (max(3, original_max_steps - steps_used)) instead of the full maxSteps.
|
|
84
84
|
const attemptMaxSteps = attempt === 0 ? this.maxSteps : Math.max(3, this.maxSteps - stepsUsed);
|
|
85
85
|
finalOutput = '';
|
|
@@ -194,8 +194,7 @@ class SingleAgent {
|
|
|
194
194
|
async injectScreenshot(phase = 'observation') {
|
|
195
195
|
try {
|
|
196
196
|
const screenshot = await this.adapter.getScreenshot();
|
|
197
|
-
// Save current screenshot as previous for next step
|
|
198
|
-
// hooks/image_utils.py line 562: _previous_screenshot = screenshot.base64_data)
|
|
197
|
+
// Save current screenshot as previous for next step
|
|
199
198
|
if (phase === 'observation' && this.lastScreenshot?.base64Data) {
|
|
200
199
|
this.previousScreenshotB64 = this.lastScreenshot.base64Data;
|
|
201
200
|
}
|
|
@@ -320,7 +319,7 @@ class SingleAgent {
|
|
|
320
319
|
// 坐标防御层:模型可能输出 0-1000 千分制坐标,执行前归一化到 0-1
|
|
321
320
|
(0, utils_1.normalizeToolCoordinates)(toolName, toolArgs);
|
|
322
321
|
// Save action info for drawing markers on next step's screenshots.
|
|
323
|
-
//
|
|
322
|
+
//
|
|
324
323
|
const lowerName = toolName.toLowerCase();
|
|
325
324
|
if (CLICK_LIKE_TOOLS.has(lowerName)) {
|
|
326
325
|
const pos = toolArgs['pos'] ?? toolArgs['point'];
|
|
@@ -358,7 +357,7 @@ class SingleAgent {
|
|
|
358
357
|
}
|
|
359
358
|
const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
|
|
360
359
|
let afterScreenshotPath = null;
|
|
361
|
-
//
|
|
360
|
+
//
|
|
362
361
|
// screenshot when screenshotOnToolEnd is enabled (skip for fast/minimal modes).
|
|
363
362
|
if (this.config.agent.unified.screenshotOnToolEnd) {
|
|
364
363
|
try {
|
|
@@ -463,10 +462,10 @@ class SingleAgent {
|
|
|
463
462
|
data: {},
|
|
464
463
|
stepNumber: this.stepNumber,
|
|
465
464
|
});
|
|
466
|
-
// Prompt priority
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
//
|
|
465
|
+
// Prompt priority:
|
|
466
|
+
// 1. explicit systemPrompt override
|
|
467
|
+
// 2. promptName (loadByName) — e.g. --prompt-name single_v2.0
|
|
468
|
+
// 3. SINGLE category with promptType
|
|
470
469
|
let systemPrompt = this.config.agent.unified.systemPrompt;
|
|
471
470
|
if (!systemPrompt) {
|
|
472
471
|
const promptName = this.config.agent.unified.promptName;
|
|
@@ -477,7 +476,7 @@ class SingleAgent {
|
|
|
477
476
|
systemPrompt = (0, prompt_loader_1.load)(prompt_loader_1.PromptCategory.SINGLE, this.config.model.unified.promptType);
|
|
478
477
|
}
|
|
479
478
|
}
|
|
480
|
-
// Fill {skills_metadata} placeholder with available skills
|
|
479
|
+
// Fill {skills_metadata} placeholder with available skills
|
|
481
480
|
if (systemPrompt && systemPrompt.includes('{skills_metadata}')) {
|
|
482
481
|
try {
|
|
483
482
|
const sm = new skill_manager_1.SkillManager();
|
|
@@ -501,17 +500,17 @@ class SingleAgent {
|
|
|
501
500
|
const userContent = [
|
|
502
501
|
{ type: 'text', text: promptText },
|
|
503
502
|
];
|
|
504
|
-
//
|
|
503
|
+
//
|
|
505
504
|
// 1. Inject previous screenshot with action marker (red dot + crosshair)
|
|
506
|
-
// 2. Inject current screenshot with action marker if last action was click
|
|
507
505
|
const maxPixels = this.config.agent.unified.screenshotMaxPixels || 1500;
|
|
508
506
|
const prevCompressRatio = this.config.agent.unified.previousScreenshotCompressRatio ?? 0.7;
|
|
509
507
|
const includePrev = this.config.agent.unified.includePreviousScreenshot;
|
|
508
|
+
const actionMarkers = this.config.agent.unified.actionMarkers ?? false;
|
|
510
509
|
if (includePrev && this.previousScreenshotB64 && this.stepNumber > 1) {
|
|
511
510
|
const prevPixels = Math.round(maxPixels * prevCompressRatio);
|
|
512
511
|
let prevB64 = await (0, image_helper_1.compressBase64Image)(this.previousScreenshotB64, prevPixels, 70);
|
|
513
512
|
let prevText = '** 上一步页面截图 **';
|
|
514
|
-
if (this.lastActionInfo) {
|
|
513
|
+
if (actionMarkers && this.lastActionInfo) {
|
|
515
514
|
const actionType = CLICK_LIKE_TOOLS.has(this.lastActionInfo.action) ? 'click' : 'swipe';
|
|
516
515
|
const markerInfo = actionType === 'click' && this.lastActionInfo.point
|
|
517
516
|
? { type: 'click', point: this.lastActionInfo.point }
|
|
@@ -538,16 +537,6 @@ class SingleAgent {
|
|
|
538
537
|
if (this.lastScreenshot?.base64Data) {
|
|
539
538
|
let curB64 = this.lastScreenshot.base64Data;
|
|
540
539
|
let curText = '** 当前页面截图 **';
|
|
541
|
-
// Draw action marker on current screenshot if last action was click
|
|
542
|
-
// (aligned with python image_utils.py:530-537)
|
|
543
|
-
const hasMarker = this.lastActionInfo && CLICK_LIKE_TOOLS.has(this.lastActionInfo.action) && this.lastActionInfo.point;
|
|
544
|
-
if (hasMarker) {
|
|
545
|
-
curB64 = await (0, image_utils_1.drawActionMarker)(curB64, { type: 'click', point: this.lastActionInfo.point });
|
|
546
|
-
curText = '** 当前页面截图 **\n'
|
|
547
|
-
+ '图中标记说明:红色圆点 + 十字线 = 上一步的点击位置\n'
|
|
548
|
-
+ '如果页面与上一步相比未变化(点击没点动),检查点击是否落在目标元素上,'
|
|
549
|
-
+ '并据此调整本次坐标;如果页面已变化,忽略此标记';
|
|
550
|
-
}
|
|
551
540
|
// Compress screenshot before sending to LLM (reduces tokens → faster response).
|
|
552
541
|
const finalB64 = await (0, image_helper_1.compressBase64Image)(curB64, maxPixels, 70);
|
|
553
542
|
userContent.push({ type: 'text', text: curText });
|
|
@@ -703,6 +692,15 @@ class SingleAgent {
|
|
|
703
692
|
log: logParam,
|
|
704
693
|
}),
|
|
705
694
|
}),
|
|
695
|
+
start_app_by_deep_link: (0, ai_1.tool)({
|
|
696
|
+
description: '通过 deeplink URI 启动应用(如 settings://wifi、myapp://page1)',
|
|
697
|
+
inputSchema: zod_1.z.object({
|
|
698
|
+
uri: zod_1.z.string().describe('deeplink URI'),
|
|
699
|
+
bundle_name: zod_1.z.string().optional().describe('应用包名(可选,显式指定)'),
|
|
700
|
+
ability_name: zod_1.z.string().optional().describe('Ability 名称(可选)'),
|
|
701
|
+
log: logParam,
|
|
702
|
+
}),
|
|
703
|
+
}),
|
|
706
704
|
stop_app: (0, ai_1.tool)({
|
|
707
705
|
description: '在设备上停止应用程序',
|
|
708
706
|
inputSchema: zod_1.z.object({
|
|
@@ -749,6 +747,12 @@ class SingleAgent {
|
|
|
749
747
|
task_description: zod_1.z.string().describe('子代理的任务描述'),
|
|
750
748
|
}),
|
|
751
749
|
}),
|
|
750
|
+
judge: (0, ai_1.tool)({
|
|
751
|
+
description: '判定任务执行结论:输入任务执行的结论描述,返回 passed(是否通过)/should_continue(是否继续)/reason(原因)',
|
|
752
|
+
inputSchema: zod_1.z.object({
|
|
753
|
+
conclusion: zod_1.z.string().describe('任务执行的结论描述,包含执行结果、遇到的问题等信息'),
|
|
754
|
+
}),
|
|
755
|
+
}),
|
|
752
756
|
};
|
|
753
757
|
}
|
|
754
758
|
parseTextAction(text) {
|
|
@@ -771,8 +775,7 @@ class SingleAgent {
|
|
|
771
775
|
}
|
|
772
776
|
exports.SingleAgent = SingleAgent;
|
|
773
777
|
/**
|
|
774
|
-
* FastActionAgent — ≤5-step quick-execute mode
|
|
775
|
-
* hybrid_agent/agent/fast_action.py). Applies fast defaults: maxSteps=5,
|
|
778
|
+
* FastActionAgent — ≤5-step quick-execute mode. Applies fast defaults: maxSteps=5,
|
|
776
779
|
* no retries, no post-tool screenshots, minimal inject, FAST_ACTION prompt.
|
|
777
780
|
*/
|
|
778
781
|
class FastActionAgent extends SingleAgent {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Global hook registry for cross-cutting agent hooks
|
|
3
|
-
* hybrid_agent/hooks/hook_manager.py).
|
|
2
|
+
* Global hook registry for cross-cutting agent hooks.
|
|
4
3
|
*
|
|
5
4
|
* Unlike the per-agent `AgentHooks` interface (wired directly into an agent),
|
|
6
5
|
* HookManager is a process-wide singleton where cross-cutting hooks (e.g.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Global hook registry for cross-cutting agent hooks
|
|
4
|
-
* hybrid_agent/hooks/hook_manager.py).
|
|
3
|
+
* Global hook registry for cross-cutting agent hooks.
|
|
5
4
|
*
|
|
6
5
|
* Unlike the per-agent `AgentHooks` interface (wired directly into an agent),
|
|
7
6
|
* HookManager is a process-wide singleton where cross-cutting hooks (e.g.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Screenshot injection + action markers
|
|
4
|
-
* hybrid_agent/hooks/image_utils.py inject_screenshots_and_history).
|
|
3
|
+
* Screenshot injection + action markers.
|
|
5
4
|
*
|
|
6
5
|
* Provides:
|
|
7
6
|
* - compressScreenshot: resize via sharp for LLM context window
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ScrollSearchAgent —
|
|
2
|
+
* ScrollSearchAgent — 滚动查找子代理(
|
|
3
3
|
*
|
|
4
4
|
* 在列表、导航栏、时间/日期/数字选择器等滚动场景中,
|
|
5
5
|
* 自动滑动查找目标元素使其进入可见区域。
|
|
6
6
|
*
|
|
7
7
|
* 核心流程:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Phase 1: 截图 → LLM 分析滑动区域/方向/目标
|
|
9
|
+
* 主循环: 截图 → LLM 判断(目标找到?内容变化?弹窗?) → 计算滑动距离 → 执行滑动 → 等待稳定 → 边界/区域检查
|
|
10
|
+
* 退出: 目标找到 或 达到最大步数
|
|
11
11
|
*/
|
|
12
12
|
import type { ModelConfig } from '../../../common/config/types';
|
|
13
13
|
import type { MCPDeviceAdapter } from '../../mcp/types';
|
|
@@ -33,7 +33,7 @@ export interface SearchResult {
|
|
|
33
33
|
}
|
|
34
34
|
export declare class ScrollSearchAgent {
|
|
35
35
|
readonly name = "scroll_search";
|
|
36
|
-
readonly description
|
|
36
|
+
readonly description: string;
|
|
37
37
|
private _llmCaller;
|
|
38
38
|
private _adapter;
|
|
39
39
|
private _config;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* ScrollSearchAgent —
|
|
3
|
+
* ScrollSearchAgent — 滚动查找子代理(
|
|
4
4
|
*
|
|
5
5
|
* 在列表、导航栏、时间/日期/数字选择器等滚动场景中,
|
|
6
6
|
* 自动滑动查找目标元素使其进入可见区域。
|
|
7
7
|
*
|
|
8
8
|
* 核心流程:
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Phase 1: 截图 → LLM 分析滑动区域/方向/目标
|
|
10
|
+
* 主循环: 截图 → LLM 判断(目标找到?内容变化?弹窗?) → 计算滑动距离 → 执行滑动 → 等待稳定 → 边界/区域检查
|
|
11
|
+
* 退出: 目标找到 或 达到最大步数
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.ScrollSearchAgent = exports.DEFAULT_SCROLL_CONFIG = void 0;
|
|
@@ -22,7 +22,7 @@ exports.DEFAULT_SCROLL_CONFIG = {
|
|
|
22
22
|
nearDistanceRatio: 0.4,
|
|
23
23
|
closeDistanceRatio: 0.15,
|
|
24
24
|
swipeDelayMs: 1000,
|
|
25
|
-
defaultDistanceRatio: 0.5, //
|
|
25
|
+
defaultDistanceRatio: 0.5, //
|
|
26
26
|
minDistanceRatio: 0.08,
|
|
27
27
|
swipeWaitMs: 800,
|
|
28
28
|
};
|
|
@@ -32,7 +32,7 @@ function opposite(dir) {
|
|
|
32
32
|
function isVertical(dir) {
|
|
33
33
|
return dir === 'up' || dir === 'down';
|
|
34
34
|
}
|
|
35
|
-
// ---- Prompts (copied from
|
|
35
|
+
// ---- Prompts (copied from tools/prompts.py) ----
|
|
36
36
|
const SYSTEM_PROMPT = `你是一个专业的移动端UI分析助手,专门辅助滑动查找任务。
|
|
37
37
|
你需要分析截图并返回严格的JSON格式结果,不要输出任何其他内容。`;
|
|
38
38
|
function initAnalysisPrompt(taskDesc, userDir) {
|
|
@@ -48,8 +48,24 @@ ${userDir || '(未指定,请自动判断)'}
|
|
|
48
48
|
## 要求
|
|
49
49
|
请分析截图,确定:
|
|
50
50
|
1. region_valid: 用户描述的物理区域是否在当前页面上可见(true/false)
|
|
51
|
+
- 示例:用户说"在搜索栏下方的导航栏滑动",只要搜索栏下方的导航栏在页面上可见,就返回 true
|
|
52
|
+
- 示例:用户说"在小时调节区域滑动",只要时间选择器/小时调节区域在页面上可见,就返回 true
|
|
53
|
+
- 示例:用户说"在推荐列表中查找",只要列表区域在页面上可见,就返回 true
|
|
54
|
+
- **宽泛描述**:用户说"主页面"、"当前页面"、"页面"、"屏幕"、"整个页面"等宽泛概念时,直接返回 true,bounding_box 使用 [0, 100, 1000, 900]
|
|
55
|
+
- **禁止**因为"该区域中没有目标元素"而返回 false
|
|
56
|
+
- **禁止**因为"该区域看起来不能滑动"而返回 false
|
|
57
|
+
- 只有当页面上确实不存在用户描述的区域时,才返回 false
|
|
51
58
|
2. failure_reason: 如果 region_valid 为 false,说明失败原因
|
|
52
59
|
3. bounding_box: 可滑动内容区域的边界框 [left, top, right, bottom](0-1000整数)
|
|
60
|
+
- **必须严格基于用户描述的区域来确定 bounding_box,不要自行推测或脑补其他区域**
|
|
61
|
+
- 如果用户明确指定了区域(如"在推荐列表中"、"在月份列"、"在搜索栏下方"),bounding_box 必须精确覆盖用户描述的该区域
|
|
62
|
+
- **日期/时间选择器(date/time picker)特别注意**:
|
|
63
|
+
- picker 通常由多列滚轮组成(如年/月/日、时/分)
|
|
64
|
+
- **bounding_box 必须只包含需要调节的那一列滚轮**,绝对不能包含整个 picker
|
|
65
|
+
- **错误示例**:把整个 picker(所有列)都框进来 → 滑动时会同时影响多列,结果完全错误
|
|
66
|
+
- **正确做法**:只框选目标列的左右边界,高度可以包含整列
|
|
67
|
+
- 如果是导航栏/tab栏,选择该导航栏的区域
|
|
68
|
+
- 如果 region_valid 为 false,返回 [0, 0, 0, 0]
|
|
53
69
|
4. direction: 初始滑动方向(up/down/left/right)
|
|
54
70
|
5. user_specified_direction: 用户是否明确指定了方向(true/false)
|
|
55
71
|
6. is_numeric_adjustment: 是否是数字调节场景(true/false)
|
|
@@ -81,7 +97,15 @@ ${dir}(手指移动方向)
|
|
|
81
97
|
|
|
82
98
|
## 判断要求
|
|
83
99
|
1. content_changed: 滑动后滑动区域内内容是否变化(true/false)
|
|
84
|
-
|
|
100
|
+
- 区域内的部分变化也算变化(如列表项滚动、标签位移、数字变化等)
|
|
101
|
+
- 如果只有区域外发生了变化而区域内没有变化,必须返回 false
|
|
102
|
+
2. target_found: 是否在第二张截图的**当前滑动区域内**已**完整看到**目标元素(true/false)
|
|
103
|
+
- **仅在上述 bounding_box 标记的滑动区域内查找目标**,区域外的元素即使与目标名称完全相同也不能算作找到
|
|
104
|
+
- **目标必须完全可见**:目标元素必须完整显示在 bounding_box 矩形范围内,不能被遮挡、裁剪或只显示一部分
|
|
105
|
+
- 不需要目标被精确选中、居中、高亮或可以直接点击,但目标本身必须完整可见
|
|
106
|
+
- 示例:在时间选择器年份列(bounding_box 范围内)查找1998,1998这个数字完整出现在滑动区域内(任何位置),就算找到了
|
|
107
|
+
- 示例:在列表中查找某张卡片,卡片必须完整显示在滑动区域内,只显示了顶部一小部分不算找到
|
|
108
|
+
- **反例**:如果 bounding_box 是小时列,即使分钟列中出现了目标数字,也必须返回 false
|
|
85
109
|
3. target_coords: 如果找到目标,返回目标坐标 [x, y](0-1000整数);未找到返回null
|
|
86
110
|
4. current_number: 数字调节场景返回当前选中数值;非数字场景返回null
|
|
87
111
|
5. blocking_popup: 是否有阻挡滑动的弹窗(true/false)
|
|
@@ -94,7 +118,12 @@ ${dir}(手指移动方向)
|
|
|
94
118
|
// ---- ScrollSearchAgent ----
|
|
95
119
|
class ScrollSearchAgent {
|
|
96
120
|
name = 'scroll_search';
|
|
97
|
-
description = '滑动查找目标使其进入可见区域,用于列表、导航栏、时间选择器等滚动场景。'
|
|
121
|
+
description = '滑动查找目标使其进入可见区域,用于列表、导航栏、时间选择器等滚动场景。'
|
|
122
|
+
+ '一次只能查找一个元素,如需查找多个目标请分多次调用。'
|
|
123
|
+
+ '命令形式: 在<区域>滑动查找<目标描述>。'
|
|
124
|
+
+ '子agent会自动分析并探索滑动方向,遇到边界自动切换方向。'
|
|
125
|
+
+ '注意:本工具只负责将目标元素滚动到可见区域,不返回元素坐标,'
|
|
126
|
+
+ '如需点击目标元素请在调用本工具后另行执行点击操作。';
|
|
98
127
|
_llmCaller;
|
|
99
128
|
_adapter;
|
|
100
129
|
_config;
|
|
@@ -284,7 +313,7 @@ class ScrollSearchAgent {
|
|
|
284
313
|
blockingPopupClose: pc ? [pc[0], pc[1]] : null,
|
|
285
314
|
};
|
|
286
315
|
}
|
|
287
|
-
// ---- Swipe calculation
|
|
316
|
+
// ---- Swipe calculation ----
|
|
288
317
|
_calculateSwipeDistance(init, dir, _step) {
|
|
289
318
|
// Default distance based on config
|
|
290
319
|
let ratio = this._config.defaultDistanceRatio;
|
|
@@ -310,7 +339,7 @@ class ScrollSearchAgent {
|
|
|
310
339
|
}
|
|
311
340
|
return { direction: dir };
|
|
312
341
|
}
|
|
313
|
-
// ---- Swipe execution
|
|
342
|
+
// ---- Swipe execution ----
|
|
314
343
|
async _executeSwipe(dir, bbox, distanceRatio) {
|
|
315
344
|
const [l, t, r, b] = bbox;
|
|
316
345
|
// Center of bounding box (0-1000 scale → 0-1 relative)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Subagent infrastructure
|
|
3
|
-
* hybrid_hooks.py register_subagent_hooks).
|
|
2
|
+
* Subagent infrastructure.
|
|
4
3
|
*
|
|
5
4
|
* SubagentManager allows the parent agent to delegate work to child agents
|
|
6
5
|
* via a `run_subagent` tool call. Child steps are offset from the parent's
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Subagent infrastructure
|
|
4
|
-
* hybrid_hooks.py register_subagent_hooks).
|
|
3
|
+
* Subagent infrastructure.
|
|
5
4
|
*
|
|
6
5
|
* SubagentManager allows the parent agent to delegate work to child agents
|
|
7
6
|
* via a `run_subagent` tool call. Child steps are offset from the parent's
|
|
@@ -63,7 +62,7 @@ class SubagentManager {
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
exports.SubagentManager = SubagentManager;
|
|
66
|
-
/** Singleton instance
|
|
65
|
+
/** Singleton instance. */
|
|
67
66
|
let _instance = null;
|
|
68
67
|
function getSubagentManager() {
|
|
69
68
|
if (!_instance) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ToolRecorderHook — cross-cutting hook that auto-records every tool call via
|
|
3
|
-
* the global HookManager
|
|
3
|
+
* the global HookManager.
|
|
4
4
|
*
|
|
5
5
|
* Register once at agent startup:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* const recorder = new ToolRecorder(taskId, storageDir);
|
|
7
|
+
* hookManager.register('tool_recorder', new ToolRecorderHook(recorder));
|
|
8
8
|
* Call finalize() at agent end to persist.
|
|
9
9
|
*/
|
|
10
10
|
import type { AgentHook, HookContext } from './hook_manager';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* ToolRecorderHook — cross-cutting hook that auto-records every tool call via
|
|
4
|
-
* the global HookManager
|
|
4
|
+
* the global HookManager.
|
|
5
5
|
*
|
|
6
6
|
* Register once at agent startup:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* const recorder = new ToolRecorder(taskId, storageDir);
|
|
8
|
+
* hookManager.register('tool_recorder', new ToolRecorderHook(recorder));
|
|
9
9
|
* Call finalize() at agent end to persist.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -137,7 +137,7 @@ exports.APP_PACKAGES = {
|
|
|
137
137
|
'\u7cfb\u7edf\u8bbe\u7f6e': 'com.huawei.hmos.settings',
|
|
138
138
|
AndroidSystemSettings: 'com.huawei.hmos.settings',
|
|
139
139
|
'Android System Settings': 'com.huawei.hmos.settings',
|
|
140
|
-
'Android
|
|
140
|
+
'Android System Settings': 'com.huawei.hmos.settings',
|
|
141
141
|
'Android-System-Settings': 'com.huawei.hmos.settings',
|
|
142
142
|
Settings: 'com.huawei.hmos.settings',
|
|
143
143
|
'\u5065\u5eb7': 'com.huawei.hmos.health',
|
|
@@ -50,7 +50,7 @@ export declare function home(driver: HdcDriver, delay?: number | null): Promise<
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function launchApp(driver: HdcDriver, appName: string, delay?: number | null): Promise<boolean>;
|
|
52
52
|
/**
|
|
53
|
-
* Reset the device to a clean home state
|
|
53
|
+
* Reset the device to a clean home state.
|
|
54
54
|
* Light flow: single home + clear recent tasks via aa dump/force-stop.
|
|
55
55
|
*/
|
|
56
56
|
export declare function resetDevice(driver: HdcDriver): Promise<void>;
|
|
@@ -179,7 +179,7 @@ async function launchApp(driver, appName, delay) {
|
|
|
179
179
|
return true;
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
|
-
* Reset the device to a clean home state
|
|
182
|
+
* Reset the device to a clean home state.
|
|
183
183
|
* Light flow: single home + clear recent tasks via aa dump/force-stop.
|
|
184
184
|
*/
|
|
185
185
|
async function resetDevice(driver) {
|
|
@@ -51,7 +51,7 @@ const DEFAULT_HEIGHT = 2400;
|
|
|
51
51
|
/**
|
|
52
52
|
* Minimal 16×16 black JPEG (base64). Returned on capture failure so the model
|
|
53
53
|
* still receives a valid (black) image frame and the report has something to
|
|
54
|
-
* render — matching the
|
|
54
|
+
* render — matching the hdc screenshot fallback which returns a real
|
|
55
55
|
* black image. Width/height reported as the screen defaults so downstream
|
|
56
56
|
* screen-size learning is not polluted by the tiny image's real dimensions.
|
|
57
57
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Device layer entry point
|
|
2
|
+
* Device layer entry point.
|
|
3
3
|
*
|
|
4
4
|
* Re-exports the device protocol types and provides a `createDevice` factory
|
|
5
5
|
* with a pluggable registry. `MockDevice` is available for offline/test runs.
|
|
@@ -40,7 +40,7 @@ export interface CreateDeviceOptions {
|
|
|
40
40
|
port?: number;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Create a device by implementation name
|
|
43
|
+
* Create a device by implementation name.
|
|
44
44
|
* 'MockDevice' returns an in-memory mock; real HDC devices are created via the
|
|
45
45
|
* MCP adapter factory (`createAdapterFromDeviceInfo`), which is the Node
|
|
46
46
|
* equivalent of HDCDevice.
|