@autotest/agent 0.0.9 → 0.0.11
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 +36 -0
- package/dist/.buildstamp +1 -1
- package/dist/api/autotest_agent.d.ts +1 -0
- package/dist/api/types.d.ts +2 -2
- package/dist/autotest-cli.js +1 -1
- package/dist/common/config/config.yaml +1 -0
- package/dist/common/config/types.d.ts +5 -0
- package/dist/common/image_similarity.d.ts +1 -1
- package/dist/common/layout_parser.d.ts +18 -0
- package/dist/core/agent/single_agent/agent.d.ts +53 -0
- package/dist/core/device/hdc/index.d.ts +1 -1
- package/dist/core/device/hdc/screenshot.d.ts +42 -0
- package/dist/core/mcp/detect_tool.d.ts +12 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +31 -1
- package/dist/core/mcp/mcp_tools.d.ts +4 -4
- package/dist/core/mcp/types.d.ts +32 -0
- package/dist/core/prompt/templates/debug/planner/planner_v3.0.md +20 -20
- package/dist/core/prompt/templates/single/single_v2.0.md +57 -34
- package/dist/index.js +1 -1
- package/dist/tools/batch_runner.d.ts +2 -2
- package/dist/tools/batch_runner.js +1 -1
- package/dist/tools/cache/clear_cache.d.ts +18 -0
- package/dist/tools/cache/clear_cache.js +1 -0
- package/dist/tools/case_runner/runner.js +1 -1
- package/dist/tools/config/config_tool.js +1 -1
- package/dist/tools/prompt_compare/compare_runner.js +1 -1
- package/package.json +4 -1
|
@@ -2277,6 +2277,7 @@ export declare const AppConfigSchema: z.ZodObject<{
|
|
|
2277
2277
|
appConfig: z.ZodDefault<z.ZodString>;
|
|
2278
2278
|
operationMode: z.ZodDefault<z.ZodEnum<["phone", "pc"]>>;
|
|
2279
2279
|
keepaliveProcessWhitelist: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
2280
|
+
skipClearProcess: z.ZodDefault<z.ZodBoolean>;
|
|
2280
2281
|
}, "strip", z.ZodTypeAny, {
|
|
2281
2282
|
deviceSn?: string;
|
|
2282
2283
|
ip?: string;
|
|
@@ -2288,6 +2289,7 @@ export declare const AppConfigSchema: z.ZodObject<{
|
|
|
2288
2289
|
appConfig?: string;
|
|
2289
2290
|
operationMode?: "phone" | "pc";
|
|
2290
2291
|
keepaliveProcessWhitelist?: string[];
|
|
2292
|
+
skipClearProcess?: boolean;
|
|
2291
2293
|
}, {
|
|
2292
2294
|
deviceSn?: string;
|
|
2293
2295
|
ip?: string;
|
|
@@ -2299,6 +2301,7 @@ export declare const AppConfigSchema: z.ZodObject<{
|
|
|
2299
2301
|
appConfig?: string;
|
|
2300
2302
|
operationMode?: "phone" | "pc";
|
|
2301
2303
|
keepaliveProcessWhitelist?: string[];
|
|
2304
|
+
skipClearProcess?: boolean;
|
|
2302
2305
|
}>>;
|
|
2303
2306
|
network: z.ZodDefault<z.ZodObject<{
|
|
2304
2307
|
timeout: z.ZodDefault<z.ZodNumber>;
|
|
@@ -2437,6 +2440,7 @@ export declare const AppConfigSchema: z.ZodObject<{
|
|
|
2437
2440
|
appConfig?: string;
|
|
2438
2441
|
operationMode?: "phone" | "pc";
|
|
2439
2442
|
keepaliveProcessWhitelist?: string[];
|
|
2443
|
+
skipClearProcess?: boolean;
|
|
2440
2444
|
};
|
|
2441
2445
|
reflection?: {
|
|
2442
2446
|
enabled?: boolean;
|
|
@@ -2719,6 +2723,7 @@ export declare const AppConfigSchema: z.ZodObject<{
|
|
|
2719
2723
|
appConfig?: string;
|
|
2720
2724
|
operationMode?: "phone" | "pc";
|
|
2721
2725
|
keepaliveProcessWhitelist?: string[];
|
|
2726
|
+
skipClearProcess?: boolean;
|
|
2722
2727
|
};
|
|
2723
2728
|
reflection?: {
|
|
2724
2729
|
enabled?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function computeImageHash(imagePath: string): Promise<string>;
|
|
2
|
-
export declare function computeImageHashFromBase64(imageBase64: string, side?: number): Promise<string | null>;
|
|
2
|
+
export declare function computeImageHashFromBase64(imageBase64: string, side?: number, cropCenter?: boolean): Promise<string | null>;
|
|
3
3
|
export declare function hammingDistance(hash1: string, hash2: string): number;
|
|
4
4
|
export declare function computeImageSimilarity(image1Base64: string, image2Base64: string, side?: number): Promise<number | null>;
|
|
5
5
|
export declare function areImagesSimilar(hash1: string, hash2: string, threshold?: number): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse HarmonyOS uitest dumpLayout JSON and provide coordinate snapping
|
|
3
|
+
* to the nearest clickable element. This prevents off-target clicks
|
|
4
|
+
* (e.g. clicking the video instead of the like button) without sending
|
|
5
|
+
* the full control tree to the LLM — zero extra tokens.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Snap a normalized (0-1) coordinate to the center of the nearest clickable
|
|
9
|
+
* element from the layout tree, if within `threshold` distance.
|
|
10
|
+
*
|
|
11
|
+
* @returns snapped [x, y] or the original [x, y] if no element is close enough.
|
|
12
|
+
*/
|
|
13
|
+
export declare function snapToNearestClickable(layoutData: string, screenWidth: number, screenHeight: number, x: number, y: number, threshold?: number): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
snapped: boolean;
|
|
17
|
+
dist: number;
|
|
18
|
+
};
|
|
@@ -15,6 +15,8 @@ export declare class SingleAgent {
|
|
|
15
15
|
private previousScreenshotB64;
|
|
16
16
|
private lastActionInfo;
|
|
17
17
|
fastScreenshotPath: string | null;
|
|
18
|
+
private detectCalled;
|
|
19
|
+
private fastScreenshotPairs;
|
|
18
20
|
private llmCaller;
|
|
19
21
|
private task;
|
|
20
22
|
private session;
|
|
@@ -24,14 +26,65 @@ export declare class SingleAgent {
|
|
|
24
26
|
run(args: SingleAgentArgs): Promise<AgentResult>;
|
|
25
27
|
private injectScreenshot;
|
|
26
28
|
private extractResult;
|
|
29
|
+
/**
|
|
30
|
+
* Auto-detect: if the Agent is about to FAIL but never called detect, and there
|
|
31
|
+
* are fast screenshots that differ from the settled screenshots, automatically
|
|
32
|
+
* run detect to catch transient elements (toast/popup) the Agent might have missed.
|
|
33
|
+
* Returns true if the FAIL should be overridden to PASS.
|
|
34
|
+
*/
|
|
35
|
+
private autoDetectIfNeeded;
|
|
36
|
+
/**
|
|
37
|
+
* Extract a verification description from the task's "预期" lines.
|
|
38
|
+
* Falls back to a generic description if no expected results found.
|
|
39
|
+
*/
|
|
40
|
+
private extractDetectDescription;
|
|
27
41
|
private executeAction;
|
|
28
42
|
private shouldAbort;
|
|
43
|
+
/**
|
|
44
|
+
* Capture multiple fast screenshots right after a click/swipe to catch
|
|
45
|
+
* transient UI elements (toast, refresh indicator, loading spinner).
|
|
46
|
+
*
|
|
47
|
+
* Uses **device-side burst capture** when available: a shell script runs on
|
|
48
|
+
* the device capturing N screenshots back-to-back with no USB overhead
|
|
49
|
+
* between frames, then all images are pulled to the host in one batch.
|
|
50
|
+
* This gives ~300 ms per frame (vs ~800 ms per getScreenshot call), so the
|
|
51
|
+
* first post-action frame arrives ~500 ms sooner.
|
|
52
|
+
*
|
|
53
|
+
* Falls back to the legacy approach (repeated getScreenshot with delays)
|
|
54
|
+
* when burst is not supported by the adapter.
|
|
55
|
+
*/
|
|
56
|
+
private captureBestFastScreenshot;
|
|
57
|
+
/**
|
|
58
|
+
* Select the burst frame most likely to contain a transient element (toast).
|
|
59
|
+
*
|
|
60
|
+
* Strategy: compare each frame to BOTH the pre-action reference and the
|
|
61
|
+
* LAST burst frame (proxy for the settled post-action state). Pick the
|
|
62
|
+
* frame with the highest distance from the last frame — that frame has
|
|
63
|
+
* something that DISAPPEARED by the end, i.e. a transient element.
|
|
64
|
+
*
|
|
65
|
+
* A frame with only a permanent change (button color) is similar to the
|
|
66
|
+
* last frame → low distance. A frame with a toast is different from the
|
|
67
|
+
* last frame → high distance.
|
|
68
|
+
*/
|
|
69
|
+
private selectBestFromBurst;
|
|
70
|
+
/**
|
|
71
|
+
* Legacy fast-screenshot approach: call getScreenshot() three times with
|
|
72
|
+
* fixed delays (100 ms, 300 ms, 500 ms). Each call incurs a full USB
|
|
73
|
+
* round-trip (~800 ms), so the first frame arrives ~500 ms later than
|
|
74
|
+
* the burst approach.
|
|
75
|
+
*/
|
|
76
|
+
private captureBestFastScreenshotLegacy;
|
|
29
77
|
private formatActionLog;
|
|
30
78
|
private callLLMStep;
|
|
31
79
|
private parseThinkingTags;
|
|
32
80
|
private parseJudgmentTags;
|
|
33
81
|
private getDeviceTools;
|
|
34
82
|
private parseTextAction;
|
|
83
|
+
/**
|
|
84
|
+
* Detect whether an LLM API error is caused by tool/function-calling schema issues.
|
|
85
|
+
* Triggers fallback to text-based parsing (no tools sent to API).
|
|
86
|
+
*/
|
|
87
|
+
private isToolSchemaError;
|
|
35
88
|
}
|
|
36
89
|
/**
|
|
37
90
|
* FastActionAgent — ≤5-step quick-execute mode. Applies fast defaults: maxSteps=5,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* HDC utilities for HarmonyOS device interaction.
|
|
3
3
|
*/
|
|
4
4
|
export type { HdcDriver } from './device';
|
|
5
|
-
export { getScreenshot } from './screenshot';
|
|
5
|
+
export { getScreenshot, burstScreenshot, prepareBurstScript, startBurstBackground, pushBurstScript, triggerBurstScript, collectBurstResults } from './screenshot';
|
|
6
6
|
export { inputText, typeText, clearText } from './input';
|
|
7
7
|
export { APP_PACKAGES, APP_ABILITIES, TOP_225_APP, BUNDLE_NAME_TO_APP_NAME, getPackageName, getAppName, listSupportedApps, } from './apps';
|
|
8
8
|
export { getAppDisplayName, getCurrentApp, tap, doubleTap, longPress, swipe, back, home, launchApp, resetDevice, } from './device';
|
|
@@ -16,3 +16,45 @@ import type { Screenshot } from '../types';
|
|
|
16
16
|
* @returns Screenshot object containing base64 data and dimensions.
|
|
17
17
|
*/
|
|
18
18
|
export declare function getScreenshot(driver: HdcDriver, withLayout?: boolean): Promise<Screenshot>;
|
|
19
|
+
/**
|
|
20
|
+
* Capture multiple screenshots rapidly on the device side, then pull them
|
|
21
|
+
* all at once. Unlike calling {@link getScreenshot} in a loop (which does a
|
|
22
|
+
* full USB round-trip for every frame), this pushes a small shell script to
|
|
23
|
+
* the device that captures N screenshots back-to-back with **no USB overhead
|
|
24
|
+
* between frames**. Only after the burst completes are the images pulled to
|
|
25
|
+
* the host in a batch.
|
|
26
|
+
*
|
|
27
|
+
* This is critical for capturing transient UI elements (toast, refresh
|
|
28
|
+
* indicator, loading spinner) that appear and disappear within ~1 second.
|
|
29
|
+
* Each device-side frame takes ~300 ms (vs ~800 ms per getScreenshot call),
|
|
30
|
+
* so the first post-action frame arrives ~500 ms sooner.
|
|
31
|
+
*
|
|
32
|
+
* @param driver The hdc driver instance.
|
|
33
|
+
* @param count Number of screenshots to capture (default 10).
|
|
34
|
+
* @returns Array of screenshots (base64 + dimensions), possibly fewer than
|
|
35
|
+
* `count` if some captures fail.
|
|
36
|
+
*/
|
|
37
|
+
export declare function burstScreenshot(driver: HdcDriver, count?: number): Promise<Array<{
|
|
38
|
+
base64Data: string;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
}>>;
|
|
42
|
+
/** Prepare the burst script and return metadata. Does NOT push or run it. */
|
|
43
|
+
export declare function prepareBurstScript(_driver: HdcDriver, count?: number): {
|
|
44
|
+
stamp: string;
|
|
45
|
+
remotePrefix: string;
|
|
46
|
+
localScript: string;
|
|
47
|
+
count: number;
|
|
48
|
+
};
|
|
49
|
+
/** Push the burst script to device without starting it. */
|
|
50
|
+
export declare function pushBurstScript(driver: HdcDriver, info: ReturnType<typeof prepareBurstScript>): Promise<void>;
|
|
51
|
+
/** Trigger the already-pushed burst script in background. Returns immediately. */
|
|
52
|
+
export declare function triggerBurstScript(driver: HdcDriver, info: ReturnType<typeof prepareBurstScript>): Promise<void>;
|
|
53
|
+
/** Push and start the burst script in background. Returns immediately. */
|
|
54
|
+
export declare function startBurstBackground(driver: HdcDriver, info: ReturnType<typeof prepareBurstScript>): Promise<void>;
|
|
55
|
+
/** Wait for the burst to complete and pull all frames. */
|
|
56
|
+
export declare function collectBurstResults(driver: HdcDriver, info: ReturnType<typeof prepareBurstScript>, count: number): Promise<Array<{
|
|
57
|
+
base64Data: string;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
}>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect tool — ported from Python verify_impl.py + verify_assertions.py.
|
|
3
|
+
*
|
|
4
|
+
* Based on historical screenshots, uses a sub-LLM to:
|
|
5
|
+
* 1. Select the right assertion method (one_image_assert / multi_image_assert)
|
|
6
|
+
* 2. Execute the assertion (call LLM with 1 or 2 images)
|
|
7
|
+
* 3. Return {result: bool, reason: string}
|
|
8
|
+
*
|
|
9
|
+
* No video_assert (Node.js has no screen recording).
|
|
10
|
+
* For toast/提示/弹出 keywords, uses multi_image_assert (before/after comparison).
|
|
11
|
+
*/
|
|
12
|
+
export declare function executeDetect(description: string, diffStep?: number): Promise<string>;
|
|
@@ -14,6 +14,8 @@ import type { Screenshot } from '../device/types';
|
|
|
14
14
|
import { ConfigManager } from '../../common/config/manager';
|
|
15
15
|
export declare class HarmonyHdcAdapter extends MCPDeviceAdapterBase {
|
|
16
16
|
readonly platform: DevicePlatform;
|
|
17
|
+
/** Callback invoked while finger is still down during long-press, to capture transient UI. */
|
|
18
|
+
onLongPressScreenshot: (() => Promise<void>) | null;
|
|
17
19
|
private readonly hdcPath;
|
|
18
20
|
private readonly driver;
|
|
19
21
|
private readonly ip;
|
|
@@ -25,7 +27,6 @@ export declare class HarmonyHdcAdapter extends MCPDeviceAdapterBase {
|
|
|
25
27
|
private readonly deviceScreenAlwaysOn;
|
|
26
28
|
private readonly deviceOperationMode;
|
|
27
29
|
private readonly keepaliveWhitelist;
|
|
28
|
-
onLongPressScreenshot: (() => Promise<void>) | null;
|
|
29
30
|
private toastListener;
|
|
30
31
|
private toastBuffer;
|
|
31
32
|
private toastListening;
|
|
@@ -39,6 +40,35 @@ export declare class HarmonyHdcAdapter extends MCPDeviceAdapterBase {
|
|
|
39
40
|
connect(): Promise<void>;
|
|
40
41
|
disconnect(): Promise<void>;
|
|
41
42
|
getScreenshot(saveDir?: string): Promise<Screenshot>;
|
|
43
|
+
burstScreenshot(count?: number): Promise<Array<{
|
|
44
|
+
base64Data: string;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}>>;
|
|
48
|
+
/** Start burst capture in background, return immediately. */
|
|
49
|
+
startBurst(count?: number): Promise<{
|
|
50
|
+
remotePrefix: string;
|
|
51
|
+
count: number;
|
|
52
|
+
}>;
|
|
53
|
+
/** Prepare (push) burst script to device without starting it. */
|
|
54
|
+
prepareBurst(count?: number): Promise<{
|
|
55
|
+
remotePrefix: string;
|
|
56
|
+
count: number;
|
|
57
|
+
}>;
|
|
58
|
+
/** Trigger an already-prepared burst script. Returns immediately. */
|
|
59
|
+
triggerBurst(burstInfo: {
|
|
60
|
+
remotePrefix: string;
|
|
61
|
+
count: number;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
/** Wait for burst to complete and pull all frames. */
|
|
64
|
+
collectBurst(burstInfo: {
|
|
65
|
+
remotePrefix: string;
|
|
66
|
+
count: number;
|
|
67
|
+
}): Promise<Array<{
|
|
68
|
+
base64Data: string;
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
}>>;
|
|
42
72
|
reset(): Promise<void>;
|
|
43
73
|
callTool(toolName: string, args?: Record<string, unknown>, _timeout?: number, _retryOnFailure?: boolean): Promise<unknown>;
|
|
44
74
|
private checkDeviceConnected;
|
|
@@ -62,15 +62,15 @@ export declare function getMainAbilityForBundle(bundleName: string): string;
|
|
|
62
62
|
*/
|
|
63
63
|
export declare const loadSkill: (skillName: string) => Promise<string>;
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param
|
|
65
|
+
* Detect the task result based on recent execution history (screenshots + logs).
|
|
66
|
+
* @param detectionDescription What to detect.
|
|
67
67
|
* @returns JSON with `verified` (boolean) and `reason` (string).
|
|
68
68
|
*/
|
|
69
|
-
export declare function
|
|
69
|
+
export declare function detect(detectionDescription: string): Promise<string>;
|
|
70
70
|
export interface JudgeResult {
|
|
71
71
|
passed: boolean;
|
|
72
72
|
shouldContinue: boolean;
|
|
73
73
|
reason: string;
|
|
74
74
|
}
|
|
75
75
|
export declare const judge: (conclusion: string) => Promise<string>;
|
|
76
|
-
export declare const
|
|
76
|
+
export declare const detect: (description: string) => Promise<string>;
|
package/dist/core/mcp/types.d.ts
CHANGED
|
@@ -10,6 +10,38 @@ export declare abstract class MCPDeviceAdapter {
|
|
|
10
10
|
abstract disconnect(): Promise<void>;
|
|
11
11
|
abstract callTool(toolName: string, args?: Record<string, unknown>, timeout?: number, retryOnFailure?: boolean): Promise<unknown>;
|
|
12
12
|
abstract getScreenshot(saveDir?: string): Promise<Screenshot>;
|
|
13
|
+
/**
|
|
14
|
+
* Capture multiple screenshots rapidly on the device side (no USB overhead
|
|
15
|
+
* between frames). Returns an empty array when not supported by the
|
|
16
|
+
* adapter, allowing callers to fall back to repeated getScreenshot() calls.
|
|
17
|
+
*/
|
|
18
|
+
burstScreenshot(count?: number): Promise<Array<{
|
|
19
|
+
base64Data: string;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}>>;
|
|
23
|
+
startBurst(count?: number): Promise<{
|
|
24
|
+
remotePrefix: string;
|
|
25
|
+
count: number;
|
|
26
|
+
}>;
|
|
27
|
+
/** Prepare (push) the burst script to device without starting it. */
|
|
28
|
+
prepareBurst(count?: number): Promise<{
|
|
29
|
+
remotePrefix: string;
|
|
30
|
+
count: number;
|
|
31
|
+
}>;
|
|
32
|
+
/** Trigger an already-prepared burst script. Returns immediately. */
|
|
33
|
+
triggerBurst(burstInfo: {
|
|
34
|
+
remotePrefix: string;
|
|
35
|
+
count: number;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
collectBurst(burstInfo: {
|
|
38
|
+
remotePrefix: string;
|
|
39
|
+
count: number;
|
|
40
|
+
}): Promise<Array<{
|
|
41
|
+
base64Data: string;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}>>;
|
|
13
45
|
abstract reset(): Promise<void>;
|
|
14
46
|
abstract getDefaultServerUrl(): string;
|
|
15
47
|
abstract getMcpServicePort(): number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# 规划层提示词 v3.0
|
|
1
|
+
# 规划层提示词 v3.0
|
|
2
2
|
|
|
3
3
|
> 版本: 3.0
|
|
4
4
|
> 更新日期: 2026-07-02
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
当任务完成或确定失败时, 必须在最终回复中明确给出结论:
|
|
47
47
|
1. **格式要求**: 必须包含文字 "任务结果: 通过" 或 "任务结果: 不通过"
|
|
48
48
|
2. **失败说明**: 如果是不通过, 请简要说明原因。
|
|
49
|
-
3. **预期结果断言优先 (Expected Assertion Results Are Authoritative)**: 如果任务包含预期结果,最终结论**必须严格以所有的 `
|
|
49
|
+
3. **预期结果断言优先 (Expected Assertion Results Are Authoritative)**: 如果任务包含预期结果,最终结论**必须严格以所有的 `detect` 断言结果汇总**为准:
|
|
50
50
|
- 单个预期结果只有一个断言:`result: true` -> 最终输出 "任务结果: 通过",`result: false` -> 最终输出 "任务结果: 不通过"
|
|
51
51
|
- 单个预期结果包含多个断言:必须汇总所有相关断言,只有全部 `result: true` 才能输出 "任务结果: 通过";任一 `result: false` 都必须输出 "任务结果: 不通过"
|
|
52
52
|
- 多个预期结果:必须分别验证并汇总判断,只有所有预期结果的所有断言均为 `result: true`,最终才算通过
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
- ✅ "向下滑动屏幕。"
|
|
62
62
|
- ✅ "打开微信。"
|
|
63
63
|
|
|
64
|
-
### 2. 如果你需要"验证/检查/断言" (To
|
|
65
|
-
**必须使用 `
|
|
66
|
-
- ✅ "我需要验证登录按钮正常显示。" -> `
|
|
67
|
-
- ✅ "检查点击后页面是否有变化" -> `
|
|
68
|
-
- ✅ "检查是否出现toast提示" -> `
|
|
69
|
-
- ✅ **有预期结果时必须验证:只要任务中有预期结果时,必须使用 `
|
|
70
|
-
- 预期结果:"登录成功" → `
|
|
71
|
-
- 预期结果:"视频内流无法下滑" → `
|
|
72
|
-
- ✅ 如果验证目标涉及文字描述、输入框占位符、提示语、toast、弹窗文案、错误提示等文案类内容,必须在 `
|
|
64
|
+
### 2. 如果你需要"验证/检查/断言" (To detect)
|
|
65
|
+
**必须使用 `detect` 工具进行动效判断**,而不是仅通过视觉观察直接下结论,执行描述必须包含清晰的验证目标和预期结果。
|
|
66
|
+
- ✅ "我需要验证登录按钮正常显示。" -> `detect("验证'登录'按钮正常显示在屏幕上")`
|
|
67
|
+
- ✅ "检查点击后页面是否有变化" -> `detect("检查点击后页面是否有变化")`
|
|
68
|
+
- ✅ "检查是否出现toast提示" -> `detect("检查是否出现toast提示")`
|
|
69
|
+
- ✅ **有预期结果时必须验证:只要任务中有预期结果时,必须使用 `detect` 工具验证预期结果是否满足,例如:
|
|
70
|
+
- 预期结果:"登录成功" → `detect("验证登录成功,页面显示登录后的状态")`
|
|
71
|
+
- 预期结果:"视频内流无法下滑" → `detect("验证下滑操作后,页面无刷新,视频未切换")`
|
|
72
|
+
- ✅ 如果验证目标涉及文字描述、输入框占位符、提示语、toast、弹窗文案、错误提示等文案类内容,必须在 `detect` 的执行描述中明确加入以下要求:
|
|
73
73
|
**这是文案类验证,按语义一致判断,不要求逐字完全一致;空格、换行、标点、轻微省略、同义改写、数字表达方式差异等不影响核心含义时,视为通过**
|
|
74
74
|
- 示例:
|
|
75
|
-
- `
|
|
76
|
-
- `
|
|
77
|
-
- ❌ **错误**: 直接说 "屏幕上显示的订单金额是25.5元。" 而不调用
|
|
78
|
-
- ❌ **错误**: 看到预期结果就直接下结论,不调用 `
|
|
75
|
+
- `detect("验证输入框中展示'请输入密码'。这是文案类验证,按语义一致判断,不要求逐字完全一致;空格、换行、标点、轻微省略、同义改写、数字表达方式差异等不影响核心含义时,视为通过")`
|
|
76
|
+
- `detect("验证页面展示'密码为8-20位,至少包含字母、数字、符号两种组合'。这是文案类验证,按语义一致判断,不要求逐字完全一致;空格、换行、标点、轻微省略、同义改写、数字表达方式差异等不影响核心含义时,视为通过")`
|
|
77
|
+
- ❌ **错误**: 直接说 "屏幕上显示的订单金额是25.5元。" 而不调用 detect 工具进行动效判断
|
|
78
|
+
- ❌ **错误**: 看到预期结果就直接下结论,不调用 `detect` 工具进行动效判断
|
|
79
79
|
|
|
80
80
|
### 3. 如果你需要"获取信息" (To Read/Extract)
|
|
81
81
|
对于信息获取类任务,你可以直接从图片中读取信息,或者让执行器辅助确认。
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
- 当前屏幕状态是什么?
|
|
115
115
|
- **是否有预置条件需要先执行?**
|
|
116
116
|
- 我需要做什么动作?
|
|
117
|
-
- **是否需要验证?** 如果任务涉及验证、检查或断言某个状态/条件,**必须**使用 `
|
|
117
|
+
- **是否需要验证?** 如果任务涉及验证、检查或断言某个状态/条件,**必须**使用 `detect` 工具,而不是仅凭视觉观察下结论。
|
|
118
118
|
- **检查是否有相关的技能 (Skills) 可用**:
|
|
119
119
|
- **强制要求**: 在执行任何预置任务(如"登录"、"清理"、"关注/取关")之前,**必须**先检查下方的【可用技能列表】。
|
|
120
120
|
- 如果列表中有相关的技能,**必须**优先调用 `load_skill` 加载其详细步骤,而不是自己尝试探索。
|
|
@@ -126,12 +126,12 @@
|
|
|
126
126
|
1. `execute(message)`: 向设备发送指令。
|
|
127
127
|
2. `get_package_name()`: 获取所有支持的app包名。
|
|
128
128
|
3. `load_skill(skill_name)`: 加载特定技能的详细步骤。
|
|
129
|
-
4. `
|
|
129
|
+
4. `detect(desc)`: 动效判断步骤,用于验证某个状态或条件是否成立(特别是 toast、弹窗、加载动画等瞬态元素)。
|
|
130
130
|
- 使用场景:当你需要验证任务结果、检查某个元素状态、确认某个条件是否满足时,**必须**使用此工具,而不是仅通过视觉观察直接下结论。
|
|
131
131
|
- 使用方式:传入详细的验证描述,系统会根据描述自动选择合适的验证方式:
|
|
132
|
-
- 单图验证:`
|
|
133
|
-
- 前后对比:`
|
|
134
|
-
- 视频验证:`
|
|
132
|
+
- 单图验证:`detect("检查'登录'按钮正常显示在屏幕上")`
|
|
133
|
+
- 前后对比:`detect("检查点击后页面是否有变化")`
|
|
134
|
+
- 视频验证:`detect("验证长按两倍速是否成功")` 或 `detect("检查是否出现toast提示")` 或 `detect("检查是否弹出提示")`
|
|
135
135
|
- 返回结果:会返回验证结果(true/false)和详细消息。
|
|
136
136
|
5. `summary(executed_tasks, current_blockers, next_plan)`: 总结当前执行进度,记录遇到的困难,并制定下一步计划。用于状态同步和打破死循环。
|
|
137
137
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# 单层Agent提示词 v2.0
|
|
1
|
+
# 单层Agent提示词 v2.0
|
|
2
2
|
|
|
3
3
|
> 版本: 2.2
|
|
4
4
|
> 更新日期: 2026-05-27
|
|
@@ -136,45 +136,67 @@
|
|
|
136
136
|
- x, y 均为相对坐标,范围 0.000-1.000(三位小数精度)
|
|
137
137
|
- (0.000, 0.000) 是屏幕左上角,(1.000, 1.000) 是右下角
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
**空间树定位法**(输出坐标前必须执行,逐层缩小范围):
|
|
140
|
+
|
|
141
|
+
**第一层:九宫格粗分区** — 将屏幕分为 3×3 共 9 个区域,确定目标在哪个区域:
|
|
140
142
|
```
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
0.20-0.40 │ (2,1) │ (2,2) │ (2,3) │ (2,4) │ (2,5) │
|
|
146
|
-
├──────────┼──────────┼──────────┼──────────┼──────────┤
|
|
147
|
-
0.40-0.60 │ (3,1) │ (3,2) │ (3,3) │ (3,4) │ (3,5) │
|
|
148
|
-
├──────────┼──────────┼──────────┼──────────┼──────────┤
|
|
149
|
-
0.60-0.80 │ (4,1) │ (4,2) │ (4,3) │ (4,4) │ (4,5) │
|
|
150
|
-
├──────────┼──────────┼──────────┼──────────┼──────────┤
|
|
151
|
-
0.80-1.00 │ (5,1) │ (5,2) │ (5,3) │ (5,4) │ (5,5) │
|
|
152
|
-
└──────────┴──────────┴──────────┴──────────┴──────────┘
|
|
143
|
+
左(0.00-0.33) 中(0.33-0.67) 右(0.67-1.00)
|
|
144
|
+
上(0.00-0.33) [A1] [A2] [A3]
|
|
145
|
+
中(0.33-0.67) [B1] [B2] [B3]
|
|
146
|
+
下(0.67-1.00) [C1] [C2] [C3]
|
|
153
147
|
```
|
|
154
|
-
|
|
148
|
+
先判断目标位于 A1-C3 中的哪个区域,记录该区域的坐标范围。
|
|
155
149
|
|
|
156
|
-
|
|
150
|
+
**第二层:区域内细分** — 在目标所在区域内,以可见的 UI 元素为参照,进一步缩小范围:
|
|
151
|
+
- 观察该区域内有哪些可见的 UI 元素(文字、图标、按钮、图片边界等)
|
|
152
|
+
- 确定目标相对于这些参照元素的位置(上方/下方/左侧/右侧/中间)
|
|
153
|
+
- 将目标缩小到一个更小的子区域(约屏幕的 10%×10% 范围)
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
**第三层:视觉边界精定位** — 观察目标元素本身的可见边界,估算其四条边:
|
|
156
|
+
- top(上边缘 y)、bottom(下边缘 y)、left(左边缘 x)、right(右边缘 x)
|
|
157
|
+
- 中心坐标 = ( (left+right)/2, (top+bottom)/2 )
|
|
158
|
+
- 此步骤将定位精确化到三位小数级别
|
|
159
|
+
|
|
160
|
+
**坐标决策流程**(reasoning 必须依次输出以下四步,缺一不可):
|
|
159
161
|
|
|
160
|
-
|
|
162
|
+
**① 空间树定位**:执行上述三层定位,输出每层结果
|
|
163
|
+
- 第一层:目标位于区域 [X#],坐标范围 (x1-x2, y1-y2)
|
|
164
|
+
- 第二层:在该区域内,目标位于 [描述位置],参照元素 [列出参照]
|
|
165
|
+
- 第三层:视觉边界 top≈?, bottom≈?, left≈?, right≈?
|
|
161
166
|
|
|
162
|
-
|
|
167
|
+
**② 中心计算**:基于第三层边界计算几何中心
|
|
168
|
+
- x = (left + right) / 2
|
|
169
|
+
- y = (top + bottom) / 2
|
|
163
170
|
|
|
164
|
-
|
|
171
|
+
**③ 自检**:检查计算结果是否落在第一层的区域范围内,不在则修正
|
|
165
172
|
|
|
166
173
|
**示例**:
|
|
167
174
|
```
|
|
168
|
-
目标:页面中部的「提交」按钮
|
|
169
|
-
|
|
170
|
-
|
|
175
|
+
目标:页面中部的「提交」按钮
|
|
176
|
+
第一层:区域 [B2] 中部居中,范围 x:0.33-0.67, y:0.33-0.67
|
|
177
|
+
第二层:在屏幕中部,表单底部下方,上方有标题文字,下方有取消按钮
|
|
178
|
+
第三层:视觉边界 top≈0.42, bottom≈0.48, left≈0.43, right≈0.57
|
|
179
|
+
中心:x=(0.43+0.57)/2=0.500, y=(0.42+0.48)/2=0.450
|
|
180
|
+
自检:x=0.500∈[0.33,0.67]✓ y=0.450∈[0.33,0.67]✓ → 通过
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**视频/图片区域定位示例**:
|
|
184
|
+
```
|
|
185
|
+
目标:视频播放区域中心(用于长按触发倍速)
|
|
186
|
+
第一层:区域 [A2]+[B2] 跨行,屏幕中上部,范围 x:0.00-1.00, y:0.00-0.67
|
|
187
|
+
第二层:视频区域上方有状态栏(y≈0.02-0.04),下方有评论和操作按钮(y≈0.55+),视频实际内容在两者之间
|
|
188
|
+
第三层:视觉边界 top≈0.25, bottom≈0.51, left≈0.00, right≈1.00
|
|
189
|
+
中心:x=(0.00+1.00)/2=0.500, y=(0.25+0.51)/2=0.380
|
|
190
|
+
注意:视频区域可能不充满整个屏幕,必须观察实际视频内容的边界(黑色边框、状态栏、底部导航栏都会占用空间)
|
|
171
191
|
```
|
|
172
192
|
|
|
173
193
|
**错误检测**:
|
|
174
194
|
```
|
|
175
|
-
坐标:x≈0.500, y≈0.850 →
|
|
176
|
-
|
|
177
|
-
|
|
195
|
+
坐标:x≈0.500, y≈0.850 → 第一层区域 [C2] 底部居中
|
|
196
|
+
但目标在屏幕中部 → 应为 [B2]
|
|
197
|
+
分析:y=0.850 属于底部区域,但目标在中部
|
|
198
|
+
修正:重新观察,y 应约为 0.450 → 区域 [B2] ✓
|
|
199
|
+
```
|
|
178
200
|
```
|
|
179
201
|
|
|
180
202
|
**定位要点**:
|
|
@@ -182,6 +204,7 @@ y:0-0.20 │ (1,1) │ (1,2) │ (1,3) │ (1,4) │ (1,5) │
|
|
|
182
204
|
- **容器元素**(按钮、卡片、列表项):选择元素中心位置(避免点击边缘)
|
|
183
205
|
- **文字元素**(标题、段落、标签项):选择文字本身所在的位置(避免点击到区域空白)
|
|
184
206
|
- **小图标/小按钮**(图标类元素):观察图标实际位置和大小,精确定位到图标中心(避免粗略估算)
|
|
207
|
+
- **视频/图片/媒体区域**:观察实际媒体内容的可见边界(不含黑边、状态栏、导航栏),计算媒体内容区域的几何中心。媒体区域经常不充满整个屏幕,上下左右可能有黑边或UI元素占用空间,直接用屏幕中心(0.5,0.5)往往会偏移,必须通过视觉边界估算确定实际中心。
|
|
185
208
|
|
|
186
209
|
**拖拽操作(重点强调)**:
|
|
187
210
|
1. **拖拽操作应一步完成**。当任务描述包含"长按并拖动"、"拖拽"、"拖动排序"等语义时,必须使用拖拽类工具一步完成,禁止拆分为长按+滑动两步操作。
|
|
@@ -303,16 +326,16 @@ y:0-0.20 │ (1,1) │ (1,2) │ (1,3) │ (1,4) │ (1,5) │
|
|
|
303
326
|
|
|
304
327
|
当任务需要验证 toast 提示、弹窗提示、短暂出现又消失的动态元素时(如"验证是否出现toast提示点赞成功"):
|
|
305
328
|
- **禁止**仅靠截图观察 toast(toast 显示时间极短,截图通常抓不到)
|
|
306
|
-
- **必须**调用
|
|
307
|
-
- 调用方式:
|
|
329
|
+
- **必须**调用 detect 工具进行动效判断,detect 会对比操作前后的截图(含200ms快照)来判断 toast/动效是否出现
|
|
330
|
+
- 调用方式:detect("验证是否出现toast提示点赞成功")
|
|
308
331
|
|
|
309
|
-
###
|
|
332
|
+
### detect 工具结果使用规则(严格遵守)
|
|
310
333
|
|
|
311
|
-
|
|
312
|
-
- **result: true**
|
|
313
|
-
- **result: false**
|
|
314
|
-
- **禁止**无视
|
|
315
|
-
- **禁止**根据
|
|
334
|
+
detect 工具(动效判断)返回 JSON:`{"result": true/false, "reason": "..."}`
|
|
335
|
+
- **result: true** 表示动效判断通过(检测到了预期元素),判定结果必须与 detect 一致
|
|
336
|
+
- **result: false** 表示动效判断不通过(未检测到预期元素),判定结果必须与 detect 一致
|
|
337
|
+
- **禁止**无视 detect 的 result 字段,仅凭自己的截图观察做判断
|
|
338
|
+
- **禁止**根据 detect 的 reason 文本自行解读是否通过,只看 result 字段
|
|
316
339
|
- 如果 result 为 true 但你在当前截图中看不到 toast,仍然判定为通过(toast 已消失是正常的)
|
|
317
340
|
|
|
318
341
|
## 【提醒】子agent调用规则
|