@autotest/agent 0.0.10 → 0.0.12
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 +64 -0
- package/dist/autotest-cli.js +1 -1
- package/dist/common/image_similarity.d.ts +15 -1
- package/dist/common/layout_parser.d.ts +18 -0
- package/dist/common/logger.d.ts +3 -0
- package/dist/core/agent/single_agent/agent.d.ts +9 -0
- package/dist/core/device/hdc/screen_recorder.d.ts +58 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +2 -1
- package/dist/core/mcp/verify_tool.d.ts +2 -2
- package/dist/core/prompt/templates/single/single_v2.0.md +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/reporter/html_template/index.d.ts +4 -0
- package/dist/tools/batch_runner.js +1 -1
- 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 +14 -2
- package/dist/.buildstamp +0 -1
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
export interface CropRegion {
|
|
2
|
+
left: number;
|
|
3
|
+
top: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface RegionHashes {
|
|
8
|
+
full: string | null;
|
|
9
|
+
top: string | null;
|
|
10
|
+
center: string | null;
|
|
11
|
+
bottom: string | null;
|
|
12
|
+
}
|
|
1
13
|
export declare function computeImageHash(imagePath: string): Promise<string>;
|
|
2
|
-
export declare function computeImageHashFromBase64(imageBase64: string, side?: number): Promise<string | null>;
|
|
14
|
+
export declare function computeImageHashFromBase64(imageBase64: string, side?: number, cropCenter?: boolean): Promise<string | null>;
|
|
3
15
|
export declare function hammingDistance(hash1: string, hash2: string): number;
|
|
16
|
+
export declare function computeRegionHashesFromBase64(imageBase64: string, side?: number): Promise<RegionHashes | null>;
|
|
17
|
+
export declare function maxHammingAcrossRegions(a: RegionHashes, b: RegionHashes): number;
|
|
4
18
|
export declare function computeImageSimilarity(image1Base64: string, image2Base64: string, side?: number): Promise<number | null>;
|
|
5
19
|
export declare function areImagesSimilar(hash1: string, hash2: string, threshold?: number): boolean;
|
|
6
20
|
export declare function expectedHashLength(): number;
|
|
@@ -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
|
+
};
|
package/dist/common/logger.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface LoggerConfig {
|
|
|
5
5
|
maxBytes: number;
|
|
6
6
|
backupCount: number;
|
|
7
7
|
}
|
|
8
|
+
export type LogLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
9
|
+
export type LogSink = (level: LogLevel, message: string, formatted: string) => void;
|
|
8
10
|
export declare const logger: {
|
|
9
11
|
debug: (message: string) => void;
|
|
10
12
|
info: (message: string) => void;
|
|
@@ -14,3 +16,4 @@ export declare const logger: {
|
|
|
14
16
|
};
|
|
15
17
|
export declare function configureLogger(config: Partial<LoggerConfig>): void;
|
|
16
18
|
export declare function setLogFile(logFile: string): void;
|
|
19
|
+
export declare function addLogSink(sink: LogSink): () => void;
|
|
@@ -15,6 +15,8 @@ export declare class SingleAgent {
|
|
|
15
15
|
private previousScreenshotB64;
|
|
16
16
|
private lastActionInfo;
|
|
17
17
|
fastScreenshotPath: string | null;
|
|
18
|
+
fastScreenshotPaths: string[];
|
|
19
|
+
private needsToastCapture;
|
|
18
20
|
private llmCaller;
|
|
19
21
|
private task;
|
|
20
22
|
private session;
|
|
@@ -27,6 +29,13 @@ export declare class SingleAgent {
|
|
|
27
29
|
private executeAction;
|
|
28
30
|
private shouldAbort;
|
|
29
31
|
private formatActionLog;
|
|
32
|
+
/**
|
|
33
|
+
* Select the frames most likely to contain a transient element (toast/refresh icon).
|
|
34
|
+
* Uses region-aware perceptual hashing and compares each frame to the LAST frame
|
|
35
|
+
* (proxy for settled state). Ranks by change magnitude, returns the top-3 (restored
|
|
36
|
+
* to temporal order so the LLM sees the motion sequence) plus the single peak frame.
|
|
37
|
+
*/
|
|
38
|
+
private selectBestFrame;
|
|
30
39
|
private callLLMStep;
|
|
31
40
|
private parseThinkingTags;
|
|
32
41
|
private parseJudgmentTags;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HarmonyOS screen recording via hdc.
|
|
3
|
+
* Uses the system screen recorder ability (com.huawei.hmos.screenrecorder)
|
|
4
|
+
* which runs in a separate process — does NOT block the UI thread.
|
|
5
|
+
*
|
|
6
|
+
* Flow:
|
|
7
|
+
* 1. startRecording() → aa start screenrecorder with custom filename
|
|
8
|
+
* 2. (execute click — UI thread is free)
|
|
9
|
+
* 3. stopRecording() → aa start screenrecorder again (toggles stop)
|
|
10
|
+
* 4. downloadVideo() → mediatool query + recv + file recv
|
|
11
|
+
* 5. extractFrames() → Python + OpenCV extracts JPEG frames from MP4
|
|
12
|
+
*/
|
|
13
|
+
export interface RecordingResult {
|
|
14
|
+
videoPath: string;
|
|
15
|
+
framePaths: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare class ScreenRecorder {
|
|
18
|
+
private hdcPath;
|
|
19
|
+
private videoName;
|
|
20
|
+
constructor(hdcPath?: string);
|
|
21
|
+
/** Start screen recording on the device. */
|
|
22
|
+
startRecording(): Promise<void>;
|
|
23
|
+
/** Force-stop the screen recorder process (idempotent, safe even if not running). */
|
|
24
|
+
forceStop(): Promise<void>;
|
|
25
|
+
/** Stop screen recording on the device. */
|
|
26
|
+
stopRecording(): Promise<void>;
|
|
27
|
+
/** Download the recorded video from the device to local filesystem.
|
|
28
|
+
* @param destDir Optional destination directory. Defaults to a temp dir.
|
|
29
|
+
* Pass a persistent dir (e.g. report screenPath) to keep the video. */
|
|
30
|
+
downloadVideo(destDir?: string): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Extract frames from MP4 video using @ffmpeg-installer/ffmpeg.
|
|
33
|
+
* Pure Node.js, no Python or external binary needed.
|
|
34
|
+
* Samples at ~10fps (every 100ms) to get manageable frame count.
|
|
35
|
+
*
|
|
36
|
+
* @param videoPath Path to the MP4 file
|
|
37
|
+
* @param outputDir Directory to save JPEG frames
|
|
38
|
+
* @param sampleFps Sampling rate (default 10 = every 100ms)
|
|
39
|
+
* @returns Array of frame file paths
|
|
40
|
+
*/
|
|
41
|
+
extractFrames(videoPath: string, outputDir: string, sampleFps?: number): Promise<string[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Full recording pipeline: start → click → stop → download → extract.
|
|
44
|
+
* Returns array of frame paths ready for selectBestFrame.
|
|
45
|
+
*/
|
|
46
|
+
recordAndExtract(durationMs?: number, sampleFps?: number): Promise<{
|
|
47
|
+
videoPath: string;
|
|
48
|
+
framePaths: string[];
|
|
49
|
+
}>;
|
|
50
|
+
/** Cleanup local temporary video and frame files. */
|
|
51
|
+
cleanup(videoPath: string, framePaths?: string[]): void;
|
|
52
|
+
/** Cleanup extracted frame files only — keeps the downloaded video file intact. */
|
|
53
|
+
cleanupFrames(frameDir: string): void;
|
|
54
|
+
/** Force-delete the recorded video on the device (idempotent safety net).
|
|
55
|
+
* Called regardless of whether downloadVideo succeeded, so the device file
|
|
56
|
+
* never piles up even if download/extract threw partway. No-op if already gone. */
|
|
57
|
+
cleanupDeviceVideo(): void;
|
|
58
|
+
}
|
|
@@ -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;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Verify tool — ported from Python
|
|
2
|
+
* Verify tool — ported from Python detect_impl.py + detect_assertions.py.
|
|
3
3
|
*
|
|
4
4
|
* Based on historical screenshots, uses a sub-LLM to:
|
|
5
5
|
* 1. Select the right assertion method (one_image_assert / multi_image_assert)
|
|
6
6
|
* 2. Execute the assertion (call LLM with 1 or 2 images)
|
|
7
|
-
* 3. Return {
|
|
7
|
+
* 3. Return {verified: bool, reason: string}
|
|
8
8
|
*
|
|
9
9
|
* No video_assert (Node.js has no screen recording).
|
|
10
10
|
* For toast/提示/弹出 keywords, uses multi_image_assert (before/after comparison).
|
|
@@ -308,12 +308,12 @@ y:0-0.20 │ (1,1) │ (1,2) │ (1,3) │ (1,4) │ (1,5) │
|
|
|
308
308
|
|
|
309
309
|
### verify 工具结果使用规则(严格遵守)
|
|
310
310
|
|
|
311
|
-
verify 工具返回 JSON:`{"
|
|
312
|
-
- **
|
|
313
|
-
- **
|
|
314
|
-
- **禁止**无视 verify 的
|
|
315
|
-
- **禁止**根据 verify 的 reason 文本自行解读是否通过,只看
|
|
316
|
-
- 如果
|
|
311
|
+
verify 工具返回 JSON:`{"verified": true/false, "reason": "..."}`
|
|
312
|
+
- **verified: true** 表示验证通过(检测到了预期元素),判定结果必须与 verify 一致
|
|
313
|
+
- **verified: false** 表示验证不通过(未检测到预期元素),判定结果必须与 verify 一致
|
|
314
|
+
- **禁止**无视 verify 的 verified 字段,仅凭自己的截图观察做判断
|
|
315
|
+
- **禁止**根据 verify 的 reason 文本自行解读是否通过,只看 verified 字段
|
|
316
|
+
- 如果 verified 为 true 但你在当前截图中看不到 toast,仍然判定为通过(toast 已消失是正常的)
|
|
317
317
|
|
|
318
318
|
## 【提醒】子agent调用规则
|
|
319
319
|
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export { ReportAnalyzerAgent, DataLoader, ReportWriter } from './core/agent/repo
|
|
|
27
27
|
export type { AnalyzerConfig as ReportAnalyzerConfig, ReportData as AgentReportData, } from './core/agent/report_analyzer_agent';
|
|
28
28
|
export { PromptCategory, load, clearCache, getAvailableVersions, getPromptVersions, listAllPrompts, DEFAULT_VERSIONS, } from './core/prompt/prompt_loader';
|
|
29
29
|
export { McpServerImpl } from './mcp-server/server';
|
|
30
|
-
export { logger, configureLogger, setLogFile, type LoggerConfig } from './common/logger';
|
|
30
|
+
export { logger, configureLogger, setLogFile, addLogSink, type LoggerConfig, type LogLevel, type LogSink } from './common/logger';
|
|
31
31
|
export { compressImageToBase64, compressBase64Image, compressImageBytes } from './common/image_helper';
|
|
32
32
|
export { TokenUsage, DashScopeTokenUsage, resolveTokenType } from './common/usage/token_usage';
|
|
33
33
|
export { McpServerToolName, TOOL_DESCRIPTIONS, ClickInputSchema, DoubleClickInputSchema, LongClickInputSchema, SwipeInputSchema, DragInputSchema, InputTextInputSchema, ClearTextInputSchema, GoBackInputSchema, GoHomeInputSchema, StartAppInputSchema, StopAppInputSchema, ClearAppDataInputSchema, WaitInputSchema, PressKeyInputSchema, ScreenOnInputSchema, ScreenOffInputSchema, UnlockScreenInputSchema, ClearRecentTaskInputSchema, EnterRecentTaskInputSchema, GetCurrentAppInputSchema, ScreenshotInputSchema, LayoutInputSchema, McpCleanUpInputSchema, OpenControlCenterInputSchema, OpenNotificationCenterInputSchema, PinchInInputSchema, PinchOutInputSchema, RotateGestureInputSchema, RotateScreenInputSchema, StopAllAppInputSchema, StartListenToastInputSchema, GetToastInputSchema, StartDataCollectInputSchema, StopDataCollectInputSchema, GenerateReportInputSchema, ListDevicesInputSchema, RunTaskInputSchema, GetTaskResultInputSchema, ResumeTaskInputSchema, AnalyzeFailureInputSchema, GetConfigInputSchema, UpdateConfigInputSchema, type McpServerConfig, type McpServerCapabilities, } from './mcp-server/types';
|
|
@@ -37,7 +37,7 @@ export { KnowledgeManager } from './core/knowledge/knowledge_manager';
|
|
|
37
37
|
export { CompressedSession, makeSessionInputFilter, compressContext, estimateTokens, Reflector, ToolRecorder, ToolPlayer, createSession, type CompressionConfig, type CompressionResult, type ReflectionConfig, type ToolCallRecord, type RecordingSession, type SessionType, } from './core/memory/memory_manager';
|
|
38
38
|
export { SkillManager } from './core/skill/skill_manager';
|
|
39
39
|
export { TaskSplitter, type TaskSplitResult, type StepDefinition } from './core/preprocessor/task_splitter';
|
|
40
|
-
export { computeImageHash, areImagesSimilar } from './common/image_similarity';
|
|
40
|
+
export { computeImageHash, areImagesSimilar, computeRegionHashesFromBase64, maxHammingAcrossRegions, type RegionHashes } from './common/image_similarity';
|
|
41
41
|
export { ImageCacher } from './common/image_cacher';
|
|
42
42
|
export { findProjectRoot, getReportBaseDir } from './common/path_utils';
|
|
43
43
|
export { CaseManager } from './common/case_manager';
|