@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.
Files changed (142) hide show
  1. package/README.md +648 -0
  2. package/dist/api/agent_api.d.ts +37 -0
  3. package/dist/api/autotest_agent.d.ts +60 -0
  4. package/dist/api/types.d.ts +86 -0
  5. package/dist/autotest-cli.d.ts +2 -0
  6. package/dist/common/case_manager.d.ts +10 -0
  7. package/dist/common/collect_case.d.ts +29 -0
  8. package/dist/common/common_errors.d.ts +30 -0
  9. package/dist/common/config/config.yaml +113 -0
  10. package/dist/common/config/config_validator.d.ts +8 -0
  11. package/dist/common/config/manager.d.ts +38 -0
  12. package/dist/common/config/output.d.ts +11 -0
  13. package/dist/common/config/types.d.ts +2963 -0
  14. package/dist/common/dfx/client_factory.d.ts +23 -0
  15. package/dist/common/dfx/context.d.ts +4 -0
  16. package/dist/common/dfx/index.d.ts +6 -0
  17. package/dist/common/dfx/recorder.d.ts +59 -0
  18. package/dist/common/dfx/recording_fetch.d.ts +4 -0
  19. package/dist/common/dfx/source.d.ts +9 -0
  20. package/dist/common/image_cacher.d.ts +10 -0
  21. package/dist/common/image_helper.d.ts +19 -0
  22. package/dist/common/image_similarity.d.ts +7 -0
  23. package/dist/common/llm_cache/cache_transport.d.ts +10 -0
  24. package/dist/common/logger.d.ts +17 -0
  25. package/dist/common/model/custom_model.d.ts +52 -0
  26. package/dist/common/model/index.d.ts +3 -0
  27. package/dist/common/path_utils.d.ts +11 -0
  28. package/dist/common/result_parser.d.ts +10 -0
  29. package/dist/common/usage/token_usage.d.ts +23 -0
  30. package/dist/common/utils.d.ts +44 -0
  31. package/dist/core/agent/layered_agent/ability_helper.d.ts +36 -0
  32. package/dist/core/agent/layered_agent/agent.d.ts +15 -0
  33. package/dist/core/agent/layered_agent/agent_registry.d.ts +34 -0
  34. package/dist/core/agent/layered_agent/decision.d.ts +82 -0
  35. package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +26 -0
  36. package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +24 -0
  37. package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +83 -0
  38. package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +33 -0
  39. package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +36 -0
  40. package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +26 -0
  41. package/dist/core/agent/layered_agent/execute_agent/index.d.ts +16 -0
  42. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +52 -0
  43. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +4 -0
  44. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +22 -0
  45. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +14 -0
  46. package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +7 -0
  47. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +17 -0
  48. package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +2 -0
  49. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +13 -0
  50. package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +6 -0
  51. package/dist/core/agent/report_analyzer_agent/agent.d.ts +22 -0
  52. package/dist/core/agent/report_analyzer_agent/config.d.ts +5 -0
  53. package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +26 -0
  54. package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +9 -0
  55. package/dist/core/agent/report_analyzer_agent/hooks.d.ts +6 -0
  56. package/dist/core/agent/report_analyzer_agent/index.d.ts +17 -0
  57. package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +9 -0
  58. package/dist/core/agent/report_analyzer_agent/mapping.d.ts +6 -0
  59. package/dist/core/agent/report_analyzer_agent/parse.d.ts +4 -0
  60. package/dist/core/agent/report_analyzer_agent/prompt.d.ts +2 -0
  61. package/dist/core/agent/report_analyzer_agent/prompts/main_agent.md +198 -0
  62. package/dist/core/agent/report_analyzer_agent/prompts/main_agent_v2.0.md +420 -0
  63. package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +8 -0
  64. package/dist/core/agent/report_analyzer_agent/tools.d.ts +26 -0
  65. package/dist/core/agent/report_analyzer_agent/types.d.ts +97 -0
  66. package/dist/core/agent/rewrite_agent/agent.d.ts +27 -0
  67. package/dist/core/agent/rewrite_agent/guardrails.d.ts +16 -0
  68. package/dist/core/agent/rewrite_agent/mapping.d.ts +25 -0
  69. package/dist/core/agent/rewrite_agent/parse.d.ts +14 -0
  70. package/dist/core/agent/rewrite_agent/prompts/rewriter_v1.0.md +168 -0
  71. package/dist/core/agent/rewrite_agent/types.d.ts +50 -0
  72. package/dist/core/agent/single_agent/agent.d.ts +43 -0
  73. package/dist/core/agent/single_agent/hook_manager.d.ts +43 -0
  74. package/dist/core/agent/single_agent/hooks.d.ts +23 -0
  75. package/dist/core/agent/single_agent/image_utils.d.ts +38 -0
  76. package/dist/core/agent/single_agent/scroll_search_agent.d.ts +58 -0
  77. package/dist/core/agent/single_agent/subagent_manager.d.ts +51 -0
  78. package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +20 -0
  79. package/dist/core/agent/types.d.ts +43 -0
  80. package/dist/core/agent/utils/message_builder.d.ts +38 -0
  81. package/dist/core/device/device_protocol.d.ts +3 -0
  82. package/dist/core/device/hdc/apps.d.ts +38 -0
  83. package/dist/core/device/hdc/device.d.ts +59 -0
  84. package/dist/core/device/hdc/index.d.ts +9 -0
  85. package/dist/core/device/hdc/input.d.ts +20 -0
  86. package/dist/core/device/hdc/screenshot.d.ts +19 -0
  87. package/dist/core/device/index.d.ts +49 -0
  88. package/dist/core/device/types.d.ts +37 -0
  89. package/dist/core/knowledge/knowledge_manager.d.ts +22 -0
  90. package/dist/core/knowledge/vectordb.d.ts +44 -0
  91. package/dist/core/mcp/adapter_factory.d.ts +10 -0
  92. package/dist/core/mcp/android_adapter.d.ts +30 -0
  93. package/dist/core/mcp/base_adapter.d.ts +26 -0
  94. package/dist/core/mcp/harmony_hdc_adapter.d.ts +49 -0
  95. package/dist/core/mcp/ios_adapter.d.ts +30 -0
  96. package/dist/core/mcp/local_tools.d.ts +20 -0
  97. package/dist/core/mcp/mcp_tools.d.ts +51 -0
  98. package/dist/core/mcp/types.d.ts +24 -0
  99. package/dist/core/memory/compressed_session.d.ts +46 -0
  100. package/dist/core/memory/context_compressor.d.ts +24 -0
  101. package/dist/core/memory/index.d.ts +7 -0
  102. package/dist/core/memory/memory_manager.d.ts +21 -0
  103. package/dist/core/memory/reflector.d.ts +20 -0
  104. package/dist/core/memory/session_factory.d.ts +17 -0
  105. package/dist/core/memory/tool_player.d.ts +82 -0
  106. package/dist/core/memory/tool_recorder.d.ts +33 -0
  107. package/dist/core/preprocessor/task_splitter.d.ts +26 -0
  108. package/dist/core/prompt/prompt_loader.d.ts +24 -0
  109. package/dist/core/prompt/templates/debug/planner/planner_v0.0.md +290 -0
  110. package/dist/core/prompt/templates/debug/planner/planner_v1.0.md +221 -0
  111. package/dist/core/prompt/templates/debug/planner/planner_v1.1-dy.md +74 -0
  112. package/dist/core/prompt/templates/debug/planner/planner_v2.0.md +319 -0
  113. package/dist/core/prompt/templates/fast_action/fast_action_v1.0.md +46 -0
  114. package/dist/core/prompt/templates/hypium/hypium_v1.0.md +33 -0
  115. package/dist/core/prompt/templates/hypium/hypium_v2.0.md +285 -0
  116. package/dist/core/prompt/templates/planner/planner_v2.0.md +319 -0
  117. package/dist/core/prompt/templates/single/single_v1.0.md +452 -0
  118. package/dist/core/prompt/templates/single/single_v2.0.md +306 -0
  119. package/dist/core/prompt/templates/single/single_v2.0_eco.md +313 -0
  120. package/dist/core/prompt/templates/single/single_v3.0.md +200 -0
  121. package/dist/core/prompt/templates/splitter/task_splitter_v1.0.md +141 -0
  122. package/dist/core/skill/skill_manager.d.ts +54 -0
  123. package/dist/data_types/action.d.ts +2 -0
  124. package/dist/data_types/agent.d.ts +2 -0
  125. package/dist/data_types/device.d.ts +2 -0
  126. package/dist/data_types/index.d.ts +6 -0
  127. package/dist/data_types/report.d.ts +2 -0
  128. package/dist/data_types/task.d.ts +2 -0
  129. package/dist/hypium_generator/generator.d.ts +38 -0
  130. package/dist/index.d.ts +46 -0
  131. package/dist/index.js +1 -0
  132. package/dist/loop/cli.d.ts +39 -0
  133. package/dist/loop/orchestrator.d.ts +47 -0
  134. package/dist/loop/result_writer.d.ts +12 -0
  135. package/dist/loop/types.d.ts +77 -0
  136. package/dist/mcp-server/server.d.ts +15 -0
  137. package/dist/mcp-server/types.d.ts +196 -0
  138. package/dist/reporter/batch_summary.d.ts +19 -0
  139. package/dist/reporter/generator.d.ts +46 -0
  140. package/dist/reporter/types.d.ts +88 -0
  141. package/dist/tools/batch_runner.d.ts +92 -0
  142. package/package.json +51 -0
@@ -0,0 +1,97 @@
1
+ export declare const ANALYSIS_SUBDIR = "analysis";
2
+ export declare const CONSISTENCY_SEVERITY_INFO = "info";
3
+ export declare const CONSISTENCY_SEVERITY_WARNING = "warning";
4
+ export declare const CONSISTENCY_SEVERITY_ERROR = "error";
5
+ export declare const EVIDENCE_COMPLETE = "complete";
6
+ export declare const EVIDENCE_PARTIAL = "partial";
7
+ export declare const EVIDENCE_MISSING = "missing";
8
+ export declare const EVIDENCE_NONE = "none";
9
+ export declare enum RootCauseCategory {
10
+ APP_ISSUE = "Application Issue",
11
+ AGENT_ISSUE = "Agent Issue",
12
+ CASE_ISSUE = "Test Case Issue",
13
+ ENV_ISSUE = "Environment Issue",
14
+ NO_ISSUE = "No Issue"
15
+ }
16
+ export declare const ROOT_CAUSE_CATEGORY_LABELS: Record<string, string>;
17
+ export declare enum AccuracyVerdict {
18
+ CORRECT = "Correct",
19
+ MISJUDGED_PASS = "Misjudged Pass",
20
+ MISJUDGED_FAIL = "Misjudged Fail",
21
+ INCONCLUSIVE = "Inconclusive"
22
+ }
23
+ export declare const ROOT_CAUSE_SUB_CATEGORIES: Record<string, Record<string, string>>;
24
+ export declare const VALID_ACCURACY_VALUES: Set<string>;
25
+ export declare const ACCURACY_CN_TO_EN: Record<string, string>;
26
+ export declare const VALID_CATEGORY_LABELS: Set<string>;
27
+ export declare function resolveSubCategory(subText: string, catLabel: string): string;
28
+ export interface PendingImage {
29
+ role: string;
30
+ content: Array<Record<string, unknown>>;
31
+ }
32
+ export interface AnalyzerContext {
33
+ reportData: unknown;
34
+ screenshotCalls: number[];
35
+ config: unknown;
36
+ pendingImages: PendingImage[];
37
+ }
38
+ export declare function createAnalyzerContext(reportData: unknown, config?: unknown): AnalyzerContext;
39
+ export interface RootCauseResult {
40
+ rootCauseCategory: string;
41
+ rootCauseSubCategory: string;
42
+ rootCauseReason: string;
43
+ confidence: number;
44
+ accuracy: string;
45
+ evidence: string[];
46
+ checkpoints: Array<Record<string, unknown>>;
47
+ summary: string;
48
+ taskIntent: string;
49
+ improvementSuggestions: string[];
50
+ reverseVerification: string;
51
+ problems: string[];
52
+ }
53
+ export declare function createRootCauseResult(overrides?: Partial<RootCauseResult>): RootCauseResult;
54
+ export declare class RootCauseClassification {
55
+ category: RootCauseCategory;
56
+ subCategory: string;
57
+ reason: string;
58
+ confidence: number;
59
+ evidence: string[];
60
+ accuracy: string;
61
+ constructor(opts: {
62
+ category: RootCauseCategory;
63
+ subCategory: string;
64
+ reason: string;
65
+ confidence: number;
66
+ evidence?: string[];
67
+ accuracy?: string;
68
+ });
69
+ toDict(): Record<string, unknown>;
70
+ }
71
+ export declare class AnalyzerOutput {
72
+ taskDescription: string;
73
+ taskIntent: string;
74
+ taskResultStatus: string;
75
+ rootCause: RootCauseClassification | null;
76
+ summary: string;
77
+ improvementSuggestions: string[];
78
+ reverseVerification: string;
79
+ analysisTime: string;
80
+ modelUsed: string;
81
+ analysisDurationSeconds: number;
82
+ totalLlmCalls: number;
83
+ accuracy: string;
84
+ checkpoints: Array<Record<string, unknown>>;
85
+ problems: string[];
86
+ evidenceCompleteness: Record<string, unknown>;
87
+ consistencyNotes: Array<Record<string, string>>;
88
+ trace: Array<Record<string, unknown>>;
89
+ screenshotData: Array<Record<string, unknown>>;
90
+ constructor(opts: Partial<AnalyzerOutput> & {
91
+ taskDescription: string;
92
+ taskIntent: string;
93
+ taskResultStatus: string;
94
+ });
95
+ toDict(): Record<string, unknown>;
96
+ }
97
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * RewriteAgent — 测试用例改写 Agent — 移植自 python rewrite_agent/agent.py
3
+ *
4
+ * 二元门决策 + LLM 自决子动作:
5
+ * 1. decideAction 做二元门判定(NO_REWRITE / REWRITE)
6
+ * 2. NO_REWRITE 直接返回(不调 LLM)——保守终止安全门
7
+ * 3. REWRITE → runAgentWithRetry(max 3):LLMCaller.call → parseRewriteResult →
8
+ * validateRewriteOutput;guardrail 触发带原因重跑;重试超限降级 NO_REWRITE
9
+ *
10
+ * 仿 Node.js ReportAnalyzerAgent 的 LLM 调用模式(LLMCaller.call,无 tools 纯文本输出)。
11
+ */
12
+ import type { ModelConfig } from '../../../common/config/types';
13
+ import { type RewriteInput, type RewriteOutput } from './types';
14
+ import type { AnalyzerOutput } from '../report_analyzer_agent/types';
15
+ /** 裁剪 AnalyzerOutput 为 summary dict(移植自 python _summarize_analyzer_output)。
16
+ * 只含关键字段,喂给 rewriter 与写入 loop_result.json。不喂 trace/screenshot 等。
17
+ * 字段集与 python 对齐(snake_case),category 为 Node.js 分析器的英文标签。 */
18
+ export declare function summarizeAnalyzerOutput(output: AnalyzerOutput): Record<string, unknown>;
19
+ export declare class RewriteAgent {
20
+ private config;
21
+ constructor(config: ModelConfig);
22
+ run(input: RewriteInput): Promise<RewriteOutput>;
23
+ private runAgentWithRetry;
24
+ /** 构建 Agent instructions(填充占位符 + 重试 hint)。移植自 python _build_prompt。 */
25
+ private buildPrompt;
26
+ }
27
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 改写 Agent 输出校验 guardrail — 移植自 python rewrite_agent/guardrails.py
3
+ *
4
+ * validateRewriteOutput(output, originalTask) 校验 RewriteOutput 字段一致性和合理性。
5
+ * tripwireTriggered=true 表示校验失败,reason 含失败原因。
6
+ */
7
+ import { type RewriteOutput } from './types';
8
+ export interface RewriteGuardrailOutput {
9
+ tripwireTriggered: boolean;
10
+ outputInfo: {
11
+ reason?: string;
12
+ };
13
+ }
14
+ /** 校验 RewriteOutput 字段一致性和合理性。 */
15
+ export declare function validateRewriteOutput(output: RewriteOutput, originalTask: string): RewriteGuardrailOutput;
16
+ //# sourceMappingURL=guardrails.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 根因→改写决策的二元门判定 — 移植自 python/AutoTest/core/agent/rewrite_agent/mapping.py
3
+ *
4
+ * decideAction(rootCauseCategory, subCategory) -> RewriteDecision
5
+ * 根据归因 Agent 输出的一级根因,执行二元门判定:是否进入改写路径。
6
+ * 进入 REWRITE 侧后,由 LLM 自决子动作(rewrite_task/add_knowledge/both)。
7
+ *
8
+ * 二元门决策表:
9
+ * - 应用问题/环境问题/无问题 → NO_REWRITE(真 bug / 需人工介入 / 已通过)
10
+ * - 用例问题/Agent问题(任意 sub_category) → REWRITE(进入改写路径)
11
+ * - 未知 category / None / 空 → NO_REWRITE(保守终止安全门)
12
+ */
13
+ import { RewriteDecision } from './types';
14
+ /**
15
+ * 二元门:根因 → 改写决策(NO_REWRITE vs REWRITE)。
16
+ *
17
+ * 输入为 Node.js ReportAnalyzerAgent 的英文 category 标签。
18
+ * None-safe:所有输入统一 strip,null/空字符串均安全处理。
19
+ * 保守终止安全门:未知 category → NO_REWRITE,防止对未知根因盲目改写。
20
+ *
21
+ * @param rootCauseCategory 一级根因分类(英文标签:Application/Agent/Test Case/Environment Issue)
22
+ * @param _subCategory 二级根因分类(二元门不依赖此字段,保留以兼容调用方签名)
23
+ */
24
+ export declare function decideAction(rootCauseCategory: string | null | undefined, _subCategory?: string | null): RewriteDecision;
25
+ //# sourceMappingURL=mapping.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * LLM 文本输出 -> RewriteOutput 解析(内容驱动) — 移植自 python rewrite_agent/parse.py
3
+ *
4
+ * 从 LLM 的 Markdown 文本(## 分节)提取结构化数据并映射为 RewriteOutput。
5
+ * 动作由内容推断(非 LLM 显式声明):
6
+ * - rewritten_task 非空 + knowledge_text 非空 -> BOTH
7
+ * - 仅 rewritten_task 非空 -> REWRITE_TASK
8
+ * - 仅 knowledge_text 非空 -> ADD_KNOWLEDGE
9
+ * - 两者均空 -> null(无可用内容,解析失败触发重试)
10
+ */
11
+ import { type RewriteOutput } from './types';
12
+ /** 从 LLM Markdown 输出解析 RewriteOutput。失败返回 null(触发重试)。 */
13
+ export declare function parseRewriteResult(finalText: string): RewriteOutput | null;
14
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1,168 @@
1
+ # 测试用例改写 Agent v1.0
2
+
3
+ ## 核心定位
4
+
5
+ 你是测试用例改写 Agent。归因分析已判定本轮失败需要改写(二元门已过滤应用/环境/无问题/未知根因),你的职责是基于归因结果,对原始 task 做最小改动改写或补充知识,供 Agent 重跑时参考。
6
+
7
+ **核心目标**:
8
+ - 针对归因给出的根因做修正或补充,使 Agent 重跑能通过
9
+ - 最小改动:保留原始 task 原文,仅做必要的补充/修正/展开
10
+
11
+ ---
12
+
13
+ ## 核心原则
14
+
15
+ 1. **最小改动原则**:改写后的 task 应尽可能保留原始 task 原文,仅做必要的补充或修正。不得删除原始 task 中正确的内容,不得整段重写或语义等价的措辞替换
16
+ 2. **基于归因正向证据**:改写须针对归因给出的根因/证据/改进建议,不得臆造原因或补无关内容
17
+ 3. **只含 Agent 可执行的操作/判断**:不得生成 Agent 无法控制的物理或环境约束(如"必须拍摄明亮照片"、"确保环境光线充足"),应改为影响 Agent 判定逻辑的指导(如"当拍摄内容与原界面视觉相似、无法区分是否更新时,不应直接判定为失败")
18
+ 4. **按需产出内容**:二元门已判定需要改写,你须产出改写内容——若根因指向原始 task 本身需改,填「改写后的任务」;若根因指向 Agent 执行/理解需补经验,填「知识库文本」;两者兼有则都填。不适用项填 N/A,不得两项均填 N/A(须有实际改写内容)
19
+ 5. **不得改写预期结果与验证逻辑**:预期结果(如"验证X等于Y"中的预期值 Y)与验证逻辑(如何判定通过/失败)是测试核心,改写只细化**操作步骤**,不得改动预期值或验证方式——即使根因指向"预期不合理"也不改预期值(那非改写职责,改写仅能细化操作步骤若模糊)
20
+
21
+ ---
22
+
23
+ ## 输入信息
24
+
25
+ **原始任务**:{original_task}
26
+ **当前轮次**:第 {iteration} 轮
27
+ **任务执行状态**:{task_result_status}
28
+
29
+ ### 归因分析结果
30
+ - **一级根因**:{root_cause_category}
31
+ - **二级根因**:{root_cause_sub_category}
32
+ - **根本原因**:{root_cause_reason}
33
+ - **证据**:{root_cause_evidence}
34
+
35
+ ### 分析摘要
36
+ {analysis_summary}
37
+
38
+ ### 改进建议
39
+ {improvement_suggestions}
40
+
41
+ ### 反向验证
42
+ {reverse_verification}
43
+
44
+ ### 问题列表
45
+ {problems}
46
+
47
+ ---
48
+
49
+ ## 改写流程
50
+
51
+ **改写目标**:根据归因给出的问题,分析其中需要**细化的操作步骤**和**补充的知识**,让下次执行能**准确执行测试步骤**、**识别真正存在的问题**(不被步骤模糊或知识缺失掩盖)。分三阶段顺序推理,最终把结论落到「改写后的任务」和「知识库文本」两个产出字段上。
52
+
53
+ ### 阶段1:理解原始任务与归因问题
54
+
55
+ 先明确:
56
+ - **原始任务意图与步骤结构**:原始 task 要验证什么、关键预期、由哪些操作步骤构成
57
+ - **归因给出的问题**:分析摘要的叙述 + 一级/二级根因 + 证据 + 问题列表——本轮具体什么问题导致失败(步骤模糊/缺失?Agent 操作或理解错?还是两者兼有)
58
+
59
+ ### 阶段2:分析需细化什么、补充什么
60
+
61
+ 围绕"让下次准确执行 + 识别真问题"分析归因问题:
62
+ - **需细化的操作步骤**:归因指出步骤模糊/缺失/不可执行(用例问题)时,定位 task 哪一步模糊或缺失——补充细化操作路径、拆为可执行子步骤,使 Agent 下次能**准确执行到位**而非自由探索偏离。填「改写后的任务」
63
+ - **需补充的知识**:归因指出 Agent 执行/理解有误(操作错误/工具异常/操作滞后/理解错误/遗漏操作等)时,提炼操作性经验——Agent 下次如何避免同类错误、如何正确识别界面状态与判定结果,使下次执行**不被执行或理解错误掩盖真正的问题**。填「知识库文本」
64
+ - 两者兼有 → 既细化步骤又补知识
65
+
66
+ **约束**:细化只针对**操作步骤**,**不得改预期结果与验证逻辑**(预期值/验证方式逐字保留;即使根因=预期不合理也不改预期值——那不是改写能修的,改写仅让步骤更准确以暴露真问题)。
67
+
68
+ ### 阶段3:按最小改动产出
69
+
70
+ 按最小改动原则生成最终内容:
71
+ - **改写后的任务**(若需改 task):以原始 task 为基底,**默认逐字保留原始内容**,仅以下情况允许修改操作步骤——(1) 追加补充细化步骤(原文末尾追加,不改动原文);(2) 展开或重述模糊步骤为多个可执行子步骤(此情况仅需保留该步骤的原始意图,可不逐字保留该步骤原措辞,其余内容仍逐字保留)。**不得改写预期结果与验证逻辑**(预期值、验证方式逐字保留,即使根因指向预期不合理也不改)。禁止删除原始 task 中正确的内容。改写后的任务必须是完整可执行的自然语言 task(不是 diff/patch/补丁)
72
+ - **知识库文本**(若需补知识):操作性指导文本(>20 字的经验描述),直接追加到 task 末尾供 Agent 重跑参考
73
+
74
+ 不适用项填 N/A。两项均填 N/A 视为未产出改写内容(会被拒绝重试)。
75
+
76
+ ---
77
+
78
+ ## 输出格式
79
+
80
+ 严格按以下 4 个 Markdown section 输出,section 标题必须完全一致(含 `##` 和空格)。
81
+
82
+ ```
83
+ ## 改写后的任务
84
+ {完整改写后的 task 文本;或 N/A}
85
+
86
+ ## 知识库文本
87
+ {操作性指导文本,>20字,将追加到 task 末尾;或 N/A}
88
+
89
+ ## 改写理由
90
+ {≤200字,说明改写依据}
91
+
92
+ ## 置信度
93
+ {0.0-1.0 的浮点数}
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 示例
99
+
100
+ ### 示例 1:用例步骤模糊→改 task
101
+
102
+ 原始任务:打开抖音搜索美食
103
+
104
+ ```
105
+ ## 改写后的任务
106
+ 打开抖音搜索美食,等待首页加载完成,点击底部导航栏的放大镜图标进入搜索页面,在搜索框中输入"美食"关键词,点击搜索按钮
107
+
108
+ ## 知识库文本
109
+ N/A
110
+
111
+ ## 改写理由
112
+ 保留原始 task 原文,追加补充具体 UI 交互路径和操作步骤,使 Agent 可执行。
113
+
114
+ ## 置信度
115
+ 0.85
116
+ ```
117
+
118
+ ### 示例 2:Agent 执行性问题→补知识
119
+
120
+ ```
121
+ ## 改写后的任务
122
+ N/A
123
+
124
+ ## 知识库文本
125
+ 在 HarmonyOS 设备上,hdc shell input tap 命令的坐标参数是像素坐标而非百分比,需先通过 wm size 获取屏幕分辨率再换算。使用 hdc shell screencap 截图后需等待 500ms 再执行下一步操作,避免截图命令与后续操作冲突导致画面不一致。
126
+
127
+ ## 改写理由
128
+ Agent 对 HDC 工具坐标体系理解有误,补充设备操作经验知识,task 本身无需改写。
129
+
130
+ ## 置信度
131
+ 0.75
132
+ ```
133
+
134
+ ### 示例 3:Agent 理解性问题→改 task + 补知识
135
+
136
+ 原始任务:打开设置查看系统版本
137
+
138
+ ```
139
+ ## 改写后的任务
140
+ 打开设置查看系统版本,向下滑动找到"关于手机"选项并点击,在关于手机页面找到"版本号"行记录数值
141
+
142
+ ## 知识库文本
143
+ HarmonyOS 设置应用中,"关于手机"入口位于设置列表底部,需向下滑动 2-3 屏才能看到,不在首屏可见区域。
144
+
145
+ ## 改写理由
146
+ 保留原始 task 原文,追加补充滑动路径指引;同时补充 HarmonyOS 设置布局知识,帮助 Agent 正确定位"关于手机"入口。
147
+
148
+ ## 置信度
149
+ 0.9
150
+ ```
151
+
152
+ ### 示例 4:模糊步骤展开→改 task
153
+
154
+ 原始任务:打开地图搜索附近餐厅
155
+
156
+ ```
157
+ ## 改写后的任务
158
+ 打开地图,点击首页的搜索栏,输入附近餐厅,点击搜索按钮查看结果
159
+
160
+ ## 知识库文本
161
+ N/A
162
+
163
+ ## 改写理由
164
+ 原始 task 中"搜索附近餐厅"为模糊步骤,展开为具体 UI 交互子步骤(点击搜索栏→输入关键词→点击搜索按钮),保留步骤意图,使 Agent 可执行。
165
+
166
+ ## 置信度
167
+ 0.85
168
+ ```
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 改写 Agent 类型定义 — 移植自 python/AutoTest/core/agent/rewrite_agent/types.py
3
+ */
4
+ /** 二元门决策枚举(代码硬门,基于归因 category)。由 mapping.decideAction() 返回。 */
5
+ export declare enum RewriteDecision {
6
+ /** 不改写(应用问题/环境问题/无问题/未知 category/None/空) */
7
+ NO_REWRITE = "no_rewrite",
8
+ /** 需要改写(用例问题/Agent问题,任意 sub_category) */
9
+ REWRITE = "rewrite"
10
+ }
11
+ /** 改写动作枚举(由 LLM 在 REWRITE 路径自决)。 */
12
+ export declare enum RewriteAction {
13
+ /** 无需改写(二元门 early-return 路径使用) */
14
+ NO_REWRITE = "no_rewrite",
15
+ /** 改写 task 字符串(用例问题倾向) */
16
+ REWRITE_TASK = "rewrite_task",
17
+ /** 追加知识文本到 task(Agent 执行性问题倾向) */
18
+ ADD_KNOWLEDGE = "add_knowledge",
19
+ /** 同时改写 task + 追加知识文本(Agent 理解性问题倾向) */
20
+ BOTH = "both"
21
+ }
22
+ /** 改写 Agent 输入(由编排器构造,传入 RewriteAgent.run())。 */
23
+ export interface RewriteInput {
24
+ /** loop 入口保存的原始 task(重建基准) */
25
+ originalTask: string;
26
+ /** AnalyzerOutput 关键字段裁剪后的 dict */
27
+ analyzerOutputSummary: Record<string, unknown>;
28
+ /** 当前轮次(1-indexed) */
29
+ iteration: number;
30
+ /** 上一轮 reportDir(调试/日志用,不喂 LLM) */
31
+ lastReportDir?: string | null;
32
+ }
33
+ /** 改写 Agent 输出(由 RewriteAgent.run() 返回,编排器消费)。 */
34
+ export interface RewriteOutput {
35
+ /** 改写动作 */
36
+ action: RewriteAction;
37
+ /** 改写后的 task(REWRITE_TASK/BOTH 时非空) */
38
+ rewrittenTask?: string | null;
39
+ /** 知识文本(ADD_KNOWLEDGE/BOTH 时非空) */
40
+ knowledgeText?: string;
41
+ /** 改写理由(≤200 字) */
42
+ rewriteReason?: string;
43
+ /** 置信度(0.0-1.0) */
44
+ confidence?: number;
45
+ /** LLM 原始输出(调试用,不写入 LoopResult JSON) */
46
+ rawLlmOutput?: string;
47
+ }
48
+ /** 序列化 RewriteOutput 为普通对象(写入 LoopResult JSON,不含 rawLlmOutput)。 */
49
+ export declare function rewriteOutputToDict(out: RewriteOutput): Record<string, unknown>;
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,43 @@
1
+ import type { AgentResult, AgentHooks, SingleAgentArgs } from '../types';
2
+ import type { MCPDeviceAdapter } from '../../mcp/types';
3
+ import type { AppConfig } from '../../../common/config/types';
4
+ import type { ReportGenerator } from '../../../reporter/types';
5
+ import { LLMCaller } from '../../../common/model';
6
+ export declare class SingleAgent {
7
+ private adapter;
8
+ private config;
9
+ private hooks?;
10
+ private reportGenerator;
11
+ private stepNumber;
12
+ private maxSteps;
13
+ private maxResultRetries;
14
+ private lastScreenshot;
15
+ private previousScreenshotB64;
16
+ private lastActionInfo;
17
+ private llmCaller;
18
+ private task;
19
+ private session;
20
+ private historyActions;
21
+ private toolCount;
22
+ constructor(adapter: MCPDeviceAdapter, config: AppConfig, reportGenerator: ReportGenerator, hooks?: AgentHooks, llmCaller?: LLMCaller);
23
+ run(args: SingleAgentArgs): Promise<AgentResult>;
24
+ private injectScreenshot;
25
+ private extractResult;
26
+ private executeAction;
27
+ private shouldAbort;
28
+ private formatActionLog;
29
+ private callLLMStep;
30
+ private parseThinkingTags;
31
+ private parseJudgmentTags;
32
+ private getDeviceTools;
33
+ private parseTextAction;
34
+ }
35
+ /**
36
+ * FastActionAgent — ≤5-step quick-execute mode (aligned with python
37
+ * hybrid_agent/agent/fast_action.py). Applies fast defaults: maxSteps=5,
38
+ * no retries, no post-tool screenshots, minimal inject, FAST_ACTION prompt.
39
+ */
40
+ export declare class FastActionAgent extends SingleAgent {
41
+ constructor(adapter: MCPDeviceAdapter, config: AppConfig, reportGenerator: ReportGenerator, hooks?: AgentHooks, llmCaller?: LLMCaller);
42
+ }
43
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Global hook registry for cross-cutting agent hooks (aligned with python
3
+ * hybrid_agent/hooks/hook_manager.py).
4
+ *
5
+ * Unlike the per-agent `AgentHooks` interface (wired directly into an agent),
6
+ * HookManager is a process-wide singleton where cross-cutting hooks (e.g.
7
+ * ToolRecorderHook) register themselves and get fired on every agent's
8
+ * lifecycle events. Errors in one hook are isolated (logged, never crash the
9
+ * agent).
10
+ */
11
+ export interface AgentHook {
12
+ name?: string;
13
+ onAgentStart?: (ctx: HookContext) => void | Promise<void>;
14
+ onAgentEnd?: (ctx: HookContext) => void | Promise<void>;
15
+ onStepStart?: (ctx: HookContext) => void | Promise<void>;
16
+ onStepEnd?: (ctx: HookContext) => void | Promise<void>;
17
+ onLLMStart?: (ctx: HookContext) => void | Promise<void>;
18
+ onLLMEnd?: (ctx: HookContext) => void | Promise<void>;
19
+ onToolStart?: (ctx: HookContext) => void | Promise<void>;
20
+ onToolEnd?: (ctx: HookContext) => void | Promise<void>;
21
+ }
22
+ export interface HookContext {
23
+ agentName?: string;
24
+ step?: number;
25
+ toolName?: string;
26
+ toolArgs?: Record<string, unknown>;
27
+ result?: string;
28
+ [key: string]: unknown;
29
+ }
30
+ export type HookEvent = 'on_agent_start' | 'on_agent_end' | 'on_step_start' | 'on_step_end' | 'on_llm_start' | 'on_llm_end' | 'on_tool_start' | 'on_tool_end';
31
+ declare class HookManagerImpl {
32
+ private hooks;
33
+ register(name: string, hook: AgentHook): void;
34
+ unregister(name: string): void;
35
+ clear(): void;
36
+ listHooks(): string[];
37
+ /** Fire an event to all registered hooks. Errors are isolated (logged, never thrown). */
38
+ fireEvent(event: HookEvent, ctx?: HookContext): Promise<void>;
39
+ private _eventToMethod;
40
+ }
41
+ export declare const hookManager: HookManagerImpl;
42
+ export type { HookManagerImpl };
43
+ //# sourceMappingURL=hook_manager.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { TokenUsage } from '../../../common/usage/token_usage';
2
+ import { type ReportGenerator } from '../../../reporter/types';
3
+ import type { MCPDeviceAdapter } from '../../mcp/types';
4
+ import type { AgentConfig } from '../../../common/config/types';
5
+ import type { AgentHooks } from '../types';
6
+ export declare class SingleAgentHooks implements AgentHooks {
7
+ private adapter;
8
+ private reportGenerator;
9
+ private tokenType;
10
+ private toolCount;
11
+ private historyActions;
12
+ private stepStartTime;
13
+ private agentConfig;
14
+ constructor(adapter: MCPDeviceAdapter, reportGenerator?: ReportGenerator, tokenType?: typeof TokenUsage, agentConfig?: AgentConfig);
15
+ private static _stripVerdict;
16
+ onAgentStart(agentName: string): Promise<void>;
17
+ onAgentEnd(agentName: string, output: unknown): Promise<void>;
18
+ onLLMStart(agentName: string, stepNumber: number): Promise<void>;
19
+ onLLMEnd(agentName: string, stepNumber: number, response: unknown): Promise<void>;
20
+ onToolStart(agentName: string, toolName: string, args?: Record<string, unknown>): Promise<void>;
21
+ onToolEnd(agentName: string, toolName: string, result: string, stepNumber: number): Promise<void>;
22
+ }
23
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Screenshot injection + action markers (aligned with python
3
+ * hybrid_agent/hooks/image_utils.py inject_screenshots_and_history).
4
+ *
5
+ * Provides:
6
+ * - compressScreenshot: resize via sharp for LLM context window
7
+ * - drawActionMarker: overlay click dot / swipe arrow via SVG→sharp composite
8
+ * - injectScreenshotsAndHistory: build user message with prev+current+history
9
+ * - manageImageHistory: strip old images from session items
10
+ */
11
+ /** Compress a base64 screenshot to a target pixel count. */
12
+ export declare function compressScreenshot(base64Data: string, maxPixels?: number): Promise<string>;
13
+ /**
14
+ * Draw an action marker (click dot + crosshair, or swipe arrow) on a screenshot.
15
+ * Uses SVG → sharp composite for overlay drawing.
16
+ */
17
+ export declare function drawActionMarker(base64Data: string, action: {
18
+ type: 'click' | 'swipe';
19
+ point?: [number, number];
20
+ start?: [number, number];
21
+ end?: [number, number];
22
+ }): Promise<string>;
23
+ /**
24
+ * Build a user message with previous screenshot (with action marker) + current screenshot + progress history.
25
+ * Returns content blocks for the AI SDK user message.
26
+ */
27
+ export declare function injectScreenshotsAndHistory(prevScreenshot: string | null, currentScreenshot: string, historyActions: string[], lastActionInfo: {
28
+ type: 'click' | 'swipe';
29
+ point?: [number, number];
30
+ start?: [number, number];
31
+ end?: [number, number];
32
+ } | null): Array<Record<string, unknown>>;
33
+ /**
34
+ * Strip old image parts from session items, keeping only the most recent N images.
35
+ * Converts older image parts to text placeholders.
36
+ */
37
+ export declare function manageImageHistory(items: Array<Record<string, unknown>>, maxImages?: number): Array<Record<string, unknown>>;
38
+ //# sourceMappingURL=image_utils.d.ts.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * ScrollSearchAgent — 滚动查找子代理(对齐 python custom_scroll_search)。
3
+ *
4
+ * 在列表、导航栏、时间/日期/数字选择器等滚动场景中,
5
+ * 自动滑动查找目标元素使其进入可见区域。
6
+ *
7
+ * 核心流程:
8
+ * Phase 1: 截图 → LLM 分析滑动区域/方向/目标
9
+ * 主循环: 截图 → LLM 判断(目标找到?内容变化?弹窗?) → 计算滑动距离 → 执行滑动 → 等待稳定 → 边界/区域检查
10
+ * 退出: 目标找到 或 达到最大步数
11
+ */
12
+ import type { ModelConfig } from '../../../common/config/types';
13
+ import type { MCPDeviceAdapter } from '../../mcp/types';
14
+ import type { ReportGenerator } from '../../../reporter/types';
15
+ export interface ScrollConfig {
16
+ maxSteps: number;
17
+ screenshotMaxPixels: number;
18
+ farDistanceRatio: number;
19
+ nearDistanceRatio: number;
20
+ closeDistanceRatio: number;
21
+ swipeDelayMs: number;
22
+ defaultDistanceRatio: number;
23
+ minDistanceRatio: number;
24
+ swipeWaitMs: number;
25
+ }
26
+ export declare const DEFAULT_SCROLL_CONFIG: ScrollConfig;
27
+ export interface SearchResult {
28
+ success: boolean;
29
+ targetCoords: [number, number] | null;
30
+ totalSteps: number;
31
+ message: string;
32
+ summary: string;
33
+ }
34
+ export declare class ScrollSearchAgent {
35
+ readonly name = "scroll_search";
36
+ readonly description = "\u6ED1\u52A8\u67E5\u627E\u76EE\u6807\u4F7F\u5176\u8FDB\u5165\u53EF\u89C1\u533A\u57DF\uFF0C\u7528\u4E8E\u5217\u8868\u3001\u5BFC\u822A\u680F\u3001\u65F6\u95F4\u9009\u62E9\u5668\u7B49\u6EDA\u52A8\u573A\u666F\u3002";
37
+ private _llmCaller;
38
+ private _adapter;
39
+ private _config;
40
+ private _reportGenerator;
41
+ private _modelConfig;
42
+ private _noChangeCount;
43
+ constructor(adapter: MCPDeviceAdapter, modelConfig: ModelConfig, config?: Partial<ScrollConfig>, reportGenerator?: ReportGenerator);
44
+ run(taskDescription: string, userDirection?: string): Promise<SearchResult>;
45
+ private _vlmInitAnalysis;
46
+ private _vlmJudgment;
47
+ private _parseJson;
48
+ private _parseInitAnalysis;
49
+ private _parseStepJudgment;
50
+ private _calculateSwipeDistance;
51
+ private _adjustNumericSwipe;
52
+ private _executeSwipe;
53
+ private _takeScreenshot;
54
+ private _scaleFrom1000;
55
+ private _success;
56
+ private _sleep;
57
+ }
58
+ //# sourceMappingURL=scroll_search_agent.d.ts.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Subagent infrastructure (aligned with python hybrid_agent/agent/base.py +
3
+ * hybrid_hooks.py register_subagent_hooks).
4
+ *
5
+ * SubagentManager allows the parent agent to delegate work to child agents
6
+ * via a `run_subagent` tool call. Child steps are offset from the parent's
7
+ * step counter for correct numbering in reports.
8
+ *
9
+ * NOTE: Full event buffering (start_buffering/drain_buffer/attach_sub_events)
10
+ * is deferred — this version provides the registration + invocation + step
11
+ * offset infrastructure.
12
+ */
13
+ import type { ReportGenerator } from '../../../reporter/types';
14
+ export interface SubagentConfig {
15
+ name: string;
16
+ description: string;
17
+ taskDescription: string;
18
+ maxSteps?: number;
19
+ }
20
+ export interface SubagentResult {
21
+ name: string;
22
+ success: boolean;
23
+ output: string;
24
+ stepsUsed: number;
25
+ }
26
+ type SubagentRunner = (task: string, opts: {
27
+ stepOffset: number;
28
+ reportGenerator: ReportGenerator;
29
+ }) => Promise<SubagentResult>;
30
+ export declare class SubagentManager {
31
+ private _subagents;
32
+ private _parentStep;
33
+ /** Register a sub-agent by name with a runner function. */
34
+ register(name: string, description: string, runner: SubagentRunner, defaultTaskDescription?: string): void;
35
+ /** Unregister a sub-agent. */
36
+ unregister(name: string): void;
37
+ /** List registered sub-agent names + descriptions (for tool schema). */
38
+ listSubagents(): Array<{
39
+ name: string;
40
+ description: string;
41
+ }>;
42
+ /** Set the parent's current step (for step offset calculation). */
43
+ setParentStep(step: number): void;
44
+ /** Run a sub-agent by name. Step offset = parent step (child steps start from parent+1). */
45
+ runSubagent(name: string, task: string, reportGenerator: ReportGenerator): Promise<SubagentResult>;
46
+ /** Build a tool description string for the LLM (lists available sub-agents). */
47
+ getToolDescription(): string;
48
+ }
49
+ export declare function getSubagentManager(): SubagentManager;
50
+ export {};
51
+ //# sourceMappingURL=subagent_manager.d.ts.map