mobile-debug-mcp 0.33.0 → 0.35.0
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/.agents/skills/mcp-builder/SKILL.md +44 -64
- package/.agents/skills/mcp-builder/references/build-flags.md +44 -43
- package/.agents/skills/mcp-builder/references/diagnostics-schema.md +4 -1
- package/.agents/skills/mcp-builder/references/toolchain-details.md +49 -62
- package/.agents/skills/spec-review/references/spec-review-checklist.md +7 -0
- package/.agents/skills/test-authoring/SKILL.md +7 -6
- package/.agents/skills/test-authoring/references/repo-test-layout.md +3 -1
- package/.agents/skills/test-authoring/references/test-authoring-workflow.md +16 -7
- package/.agents/skills/test-authoring/references/test-quality-checklist.md +2 -1
- package/.github/copilot-instructions.md +14 -36
- package/.github/workflows/ci.yml +23 -2
- package/AGENTS.md +12 -3
- package/CONTRIBUTING.md +79 -0
- package/README.md +158 -124
- package/agent-plugin/.claude-plugin/plugin.json +2 -2
- package/agent-plugin/.codex-plugin/plugin.json +1 -1
- package/agent-plugin/.cursor-plugin/plugin.json +2 -2
- package/agent-plugin/.mcp.json +1 -1
- package/agent-plugin/README.md +20 -6
- package/agent-plugin/mcp.json +1 -1
- package/agent-plugin/plugin.json +1 -1
- package/agent-plugin/skills/mobile-debug-mcp/SKILL.md +113 -4
- package/dist/contracts/execution-controls.js +24 -0
- package/dist/contracts/selector.js +8 -0
- package/dist/contracts/target.js +15 -0
- package/dist/contracts/ui.js +1 -0
- package/dist/debugger/android.js +79 -0
- package/dist/debugger/diagnostics.js +54 -0
- package/dist/debugger/guard.js +30 -0
- package/dist/debugger/protocol.js +33 -0
- package/dist/debugger/sessions.js +304 -0
- package/dist/debugger/worker.js +176 -0
- package/dist/interact/adjustment/adjustment-context.js +41 -0
- package/dist/interact/adjustment/adjustment-gestures.js +55 -0
- package/dist/interact/adjustment/adjustment-plan.js +18 -0
- package/dist/interact/adjustment/adjustment-resolution.js +127 -0
- package/dist/interact/adjustment/adjustment-result.js +19 -0
- package/dist/interact/adjustment/adjustment-semantic.js +64 -0
- package/dist/interact/adjustment/adjustment-verification.js +35 -0
- package/dist/interact/adjustment/adjustment.js +52 -0
- package/dist/interact/adjustment/control-geometry.js +87 -0
- package/dist/interact/adjustment/control-values.js +136 -0
- package/dist/interact/adjustment/slider-labels.js +84 -0
- package/dist/interact/assertions/screen-assertion.js +37 -0
- package/dist/interact/assertions/state-assertion-context.js +35 -0
- package/dist/interact/assertions/state-assertion.js +76 -0
- package/dist/interact/assertions/state-comparison.js +141 -0
- package/dist/interact/assertions/visibility-assertion.js +34 -0
- package/dist/interact/conditional-action.js +12 -7
- package/dist/interact/index.js +65 -3074
- package/dist/interact/input-service.js +1 -0
- package/dist/interact/interaction-trace.js +21 -0
- package/dist/interact/model.js +1 -0
- package/dist/interact/observation.js +1 -0
- package/dist/interact/targeting/candidate-ancestor.js +58 -0
- package/dist/interact/targeting/candidate-result.js +23 -0
- package/dist/interact/targeting/candidate-scoring.js +50 -0
- package/dist/interact/targeting/element-helpers.js +216 -0
- package/dist/interact/targeting/find-element.js +65 -0
- package/dist/interact/targeting/nearby-control.js +56 -0
- package/dist/interact/targeting/resolved-elements.js +21 -0
- package/dist/interact/targeting/tap-target.js +17 -0
- package/dist/interact/targeting/target-scope.js +104 -0
- package/dist/interact/waits/legacy-log-wait.js +38 -0
- package/dist/interact/waits/legacy-wait-observations.js +103 -0
- package/dist/interact/waits/legacy-wait-state.js +34 -0
- package/dist/interact/waits/legacy-wait.js +48 -0
- package/dist/interact/waits/screen-wait.js +49 -0
- package/dist/interact/waits/ui-change-helpers.js +157 -0
- package/dist/interact/waits/ui-change-state.js +18 -0
- package/dist/interact/waits/ui-change-wait.js +77 -0
- package/dist/interact/waits/ui-wait-condition.js +56 -0
- package/dist/interact/waits/ui-wait-state.js +38 -0
- package/dist/interact/waits/ui-wait.js +106 -0
- package/dist/manage/android.js +55 -51
- package/dist/manage/index.js +38 -75
- package/dist/manage/ios/build-types.js +1 -0
- package/dist/manage/ios/build.js +210 -0
- package/dist/manage/ios/project-discovery.js +29 -0
- package/dist/manage/ios/scheme.js +18 -0
- package/dist/manage/ios.js +42 -256
- package/dist/observe/android/context.js +1 -0
- package/dist/observe/android/current-screen.js +55 -0
- package/dist/observe/android/fingerprint.js +13 -0
- package/dist/observe/android/log-stream.js +132 -0
- package/dist/observe/android/logs.js +107 -0
- package/dist/observe/android/screenshot.js +70 -0
- package/dist/observe/android/ui-tree.js +107 -0
- package/dist/observe/android.js +16 -520
- package/dist/observe/evidence.js +122 -76
- package/dist/observe/index.js +16 -263
- package/dist/observe/ios/context.js +16 -0
- package/dist/observe/ios/fingerprint.js +12 -0
- package/dist/observe/ios/log-stream.js +105 -0
- package/dist/observe/ios/logs.js +168 -0
- package/dist/observe/ios/screenshot.js +22 -0
- package/dist/observe/ios/ui-elements.js +241 -0
- package/dist/observe/ios/ui-tree.js +137 -0
- package/dist/observe/ios.js +17 -715
- package/dist/observe/logs/model.js +1 -0
- package/dist/{network → observe/network}/index.js +2 -2
- package/dist/observe/readiness-service.js +13 -2
- package/dist/observe/readiness.js +44 -18
- package/dist/observe/screenshot-encoding.js +41 -0
- package/dist/observe/snapshot-collection.js +79 -0
- package/dist/observe/snapshot-logs.js +30 -0
- package/dist/observe/snapshot-metadata.js +43 -31
- package/dist/observe/snapshot-semantic.js +115 -0
- package/dist/observe/system-trace-android.js +135 -0
- package/dist/observe/system-trace.js +294 -0
- package/dist/runtime/action-results.js +270 -0
- package/dist/runtime/clock.js +4 -0
- package/dist/server/common.js +1 -256
- package/dist/server/definitions/assert.js +162 -0
- package/dist/server/definitions/diagnostic.js +118 -0
- package/dist/server/definitions/input.js +274 -0
- package/dist/server/definitions/manage.js +194 -0
- package/dist/server/definitions/observe.js +149 -0
- package/dist/server/definitions/target.js +138 -0
- package/dist/server/definitions/wait.js +105 -0
- package/dist/server/handlers/action-execution.js +163 -0
- package/dist/server/handlers/correlation.js +23 -0
- package/dist/server/handlers/debugger-handlers.js +48 -0
- package/dist/server/handlers/debugger-response.js +9 -0
- package/dist/server/handlers/diagnostic.js +69 -0
- package/dist/server/handlers/handler-types.js +1 -0
- package/dist/server/handlers/input.js +154 -0
- package/dist/server/handlers/interact.js +113 -0
- package/dist/server/handlers/journey-assertions.js +35 -0
- package/dist/server/handlers/journey.js +147 -0
- package/dist/server/handlers/manage.js +119 -0
- package/dist/server/handlers/observe.js +95 -0
- package/dist/server/handlers/payload.js +4 -0
- package/dist/server/handlers/tool-handlers.js +160 -0
- package/dist/server/schemas/condition-schema.js +2 -0
- package/dist/server/schemas/debugger-schema.js +47 -0
- package/dist/server/{journey-schema.js → schemas/journey-schema.js} +8 -22
- package/dist/server/schemas/system-trace-schema.js +17 -0
- package/dist/server/tool-definitions.js +62 -1134
- package/dist/server-core.js +4 -4
- package/dist/server.js +34 -0
- package/dist/system/android-status.js +101 -0
- package/dist/system/android.js +37 -27
- package/dist/system/index.js +13 -438
- package/dist/system/ios-status.js +132 -0
- package/dist/system/ios.js +11 -8
- package/dist/system/model.js +1 -0
- package/dist/system/probes.js +105 -0
- package/dist/system/status-summary.js +43 -0
- package/dist/system/unsupported-status.js +52 -0
- package/dist/utils/android/commands.js +89 -0
- package/dist/utils/android/gradle.js +139 -0
- package/dist/utils/android/logs.js +103 -0
- package/dist/utils/android/ui-tree.js +233 -0
- package/dist/utils/android/utils.js +6 -564
- package/dist/utils/cli/idb/idb-helper.js +4 -6
- package/dist/utils/cli/idb/install-idb.js +13 -9
- package/dist/utils/cli/ios/preflight-ios.js +42 -38
- package/dist/utils/exec.js +2 -0
- package/dist/utils/ios/utils.js +45 -46
- package/dist/utils/java.js +75 -57
- package/dist/utils/operation-budget.js +2 -0
- package/dist/utils/resolve-device.js +6 -2
- package/dist/utils/ui/index.js +26 -26
- package/docs/CHANGELOG.md +48 -0
- package/docs/README.md +38 -0
- package/docs/benchmarks/README.md +18 -0
- package/docs/benchmarks/interaction-latency/README.md +14 -0
- package/docs/benchmarks/interaction-latency/final.md +4 -1
- package/docs/benchmarks/interaction-latency/ios-validation.md +2 -0
- package/docs/benchmarks/ui-tree-performance/README.md +24 -16
- package/docs/benchmarks/ui-tree-performance/comparison.md +11 -10
- package/docs/code-structure.md +118 -0
- package/docs/specs/001-state-verification/spec.md +16 -14
- package/docs/specs/002-richer-element-identity/spec.md +12 -10
- package/docs/specs/003-wait-and-synchronization-reliability/spec.md +12 -10
- package/docs/specs/004-action-verification-routing/spec.md +3 -3
- package/docs/specs/005-unified-action-execution-and-verification-model/spec.md +2 -0
- package/docs/specs/006-runtime-action-instrumentation-and-binding-layer/spec.md +2 -0
- package/docs/specs/007-actionability-resolution-and-executable-target-selection/spec.md +3 -1
- package/docs/specs/008-adjustable-control-support-and-semantic-value-manipulation/spec.md +3 -4
- package/docs/specs/009-semantic-control-modeling-for-custom-and-composite-controls/spec.md +2 -0
- package/docs/specs/010-verification-stabilization-and-temporal-convergence/spec.md +2 -2
- package/docs/specs/011-recovery-and-replanning-for-failed-or-ambiguous-interaction-flows/spec.md +2 -2
- package/docs/specs/011.1-recovery-contract-types-and-runtime-wiring-spec/spec.md +2 -0
- package/docs/specs/012-action-trace-and-xecution-observability/spec.md +2 -3
- package/docs/specs/013-wait-and-synchronization-reliability/spec.md +19 -19
- package/docs/specs/014-actionability-resolution/spec.md +20 -18
- package/docs/specs/015-adjustable-control-support/spec.md +17 -15
- package/docs/specs/016-environment-tools/spec.md +20 -20
- package/docs/specs/018-interaction-latency-and-batched-journeys/spec.md +2 -0
- package/docs/specs/019-ui-tree-observation-performance/spec.md +3 -1
- package/docs/specs/020-conditional-actions/intent.md +5 -3
- package/docs/specs/020-conditional-actions/plan.md +8 -9
- package/docs/specs/020-conditional-actions/spec.md +4 -2
- package/docs/specs/021-app-readiness-signals/intent.md +4 -2
- package/docs/specs/021-app-readiness-signals/plan.md +7 -6
- package/docs/specs/021-app-readiness-signals/spec.md +3 -1
- package/docs/specs/022-correlated-evidence/intent.md +4 -4
- package/docs/specs/022-correlated-evidence/plan.md +10 -11
- package/docs/specs/022-correlated-evidence/spec.md +3 -1
- package/docs/specs/023-android-system-traces/device-evidence.json +38 -0
- package/docs/specs/023-android-system-traces/emulator-recheck.json +38 -0
- package/docs/specs/023-android-system-traces/intent.md +41 -0
- package/docs/specs/023-android-system-traces/plan.md +115 -0
- package/docs/specs/023-android-system-traces/spec.md +122 -0
- package/docs/specs/024-android-heap-dump-capture/intent.md +41 -0
- package/docs/specs/025-android-runtime-debugger/intent.md +41 -0
- package/docs/specs/025-android-runtime-debugger/plan.md +106 -0
- package/docs/specs/025-android-runtime-debugger/spec.md +183 -0
- package/docs/specs/026-code-structure-and-quality-gates/health-plan.md +88 -0
- package/docs/specs/026-code-structure-and-quality-gates/intent.md +47 -0
- package/docs/specs/026-code-structure-and-quality-gates/plan.md +191 -0
- package/docs/specs/026-code-structure-and-quality-gates/spec.md +138 -0
- package/docs/specs/026-code-structure-and-quality-gates/verification-final.json +200 -0
- package/docs/specs/026-code-structure-and-quality-gates/verification-thin-facade.json +154 -0
- package/docs/specs/026-code-structure-and-quality-gates/verification.json +136 -0
- package/docs/specs/027-debugger-failure-diagnostics/intent.md +43 -0
- package/docs/specs/027-debugger-failure-diagnostics/plan.md +86 -0
- package/docs/specs/027-debugger-failure-diagnostics/spec.md +133 -0
- package/docs/specs/028-compact-debugger-responses/intent.md +41 -0
- package/docs/specs/028-compact-debugger-responses/plan.md +112 -0
- package/docs/specs/028-compact-debugger-responses/spec.md +108 -0
- package/docs/specs/029-kotlin-locals-validation/report.md +119 -0
- package/docs/specs/030-android-coroutine-validation/evidence.json +475 -0
- package/docs/specs/030-android-coroutine-validation/intent.md +47 -0
- package/docs/specs/030-android-coroutine-validation/plan.md +147 -0
- package/docs/specs/030-android-coroutine-validation/report.md +240 -0
- package/docs/specs/030-android-coroutine-validation/spec.md +107 -0
- package/docs/tools/TOOLS.md +31 -16
- package/docs/tools/{evidence.md → correlated-evidence.md} +14 -3
- package/docs/tools/debugger.md +180 -0
- package/docs/tools/interact.md +42 -20
- package/docs/tools/manage.md +25 -44
- package/docs/tools/observe.md +64 -25
- package/docs/tools/system-traces.md +134 -0
- package/docs/tools/system.md +12 -5
- package/package.json +11 -8
- package/scripts/architecture-graph.mjs +69 -0
- package/scripts/check-architecture.mjs +47 -0
- package/scripts/code-quality-baseline.json +1 -0
- package/scripts/code-quality.mjs +161 -0
- package/src/contracts/execution-controls.ts +26 -0
- package/src/contracts/selector.ts +17 -0
- package/src/contracts/target.ts +19 -0
- package/src/contracts/ui.ts +94 -0
- package/src/debugger/android.ts +66 -0
- package/src/debugger/diagnostics.ts +43 -0
- package/src/debugger/guard.ts +31 -0
- package/src/debugger/java/DebuggerWorker.java +166 -0
- package/src/debugger/protocol.ts +37 -0
- package/src/debugger/sessions.ts +327 -0
- package/src/debugger/worker.ts +135 -0
- package/src/interact/adjustment/adjustment-context.ts +83 -0
- package/src/interact/adjustment/adjustment-gestures.ts +48 -0
- package/src/interact/adjustment/adjustment-plan.ts +23 -0
- package/src/interact/adjustment/adjustment-resolution.ts +104 -0
- package/src/interact/adjustment/adjustment-result.ts +34 -0
- package/src/interact/adjustment/adjustment-semantic.ts +53 -0
- package/src/interact/adjustment/adjustment-verification.ts +60 -0
- package/src/interact/adjustment/adjustment.ts +49 -0
- package/src/interact/adjustment/control-geometry.ts +120 -0
- package/src/interact/adjustment/control-values.ts +141 -0
- package/src/interact/adjustment/slider-labels.ts +84 -0
- package/src/interact/assertions/screen-assertion.ts +39 -0
- package/src/interact/assertions/state-assertion-context.ts +48 -0
- package/src/interact/assertions/state-assertion.ts +64 -0
- package/src/interact/assertions/state-comparison.ts +168 -0
- package/src/interact/assertions/visibility-assertion.ts +41 -0
- package/src/interact/conditional-action.ts +18 -12
- package/src/interact/index.ts +76 -3491
- package/src/interact/input-service.ts +11 -0
- package/src/interact/interaction-trace.ts +36 -0
- package/src/interact/model.ts +109 -0
- package/src/interact/observation.ts +7 -0
- package/src/interact/targeting/candidate-ancestor.ts +49 -0
- package/src/interact/targeting/candidate-result.ts +24 -0
- package/src/interact/targeting/candidate-scoring.ts +42 -0
- package/src/interact/targeting/element-helpers.ts +243 -0
- package/src/interact/targeting/find-element.ts +47 -0
- package/src/interact/targeting/nearby-control.ts +46 -0
- package/src/interact/targeting/resolved-elements.ts +20 -0
- package/src/interact/targeting/tap-target.ts +22 -0
- package/src/interact/targeting/target-scope.ts +121 -0
- package/src/interact/waits/legacy-log-wait.ts +30 -0
- package/src/interact/waits/legacy-wait-observations.ts +55 -0
- package/src/interact/waits/legacy-wait-state.ts +48 -0
- package/src/interact/waits/legacy-wait.ts +34 -0
- package/src/interact/waits/screen-wait.ts +37 -0
- package/src/interact/waits/ui-change-helpers.ts +184 -0
- package/src/interact/waits/ui-change-state.ts +26 -0
- package/src/interact/waits/ui-change-wait.ts +59 -0
- package/src/interact/waits/ui-wait-condition.ts +52 -0
- package/src/interact/waits/ui-wait-state.ts +55 -0
- package/src/interact/waits/ui-wait.ts +84 -0
- package/src/manage/android.ts +56 -50
- package/src/manage/index.ts +63 -93
- package/src/manage/ios/build-types.ts +14 -0
- package/src/manage/ios/build.ts +230 -0
- package/src/manage/ios/project-discovery.ts +26 -0
- package/src/manage/ios/scheme.ts +16 -0
- package/src/manage/ios.ts +65 -298
- package/src/observe/android/context.ts +1 -0
- package/src/observe/android/current-screen.ts +63 -0
- package/src/observe/android/fingerprint.ts +13 -0
- package/src/observe/android/log-stream.ts +127 -0
- package/src/observe/android/logs.ts +110 -0
- package/src/observe/android/screenshot.ts +79 -0
- package/src/observe/android/ui-tree.ts +113 -0
- package/src/observe/android.ts +17 -531
- package/src/observe/evidence.ts +130 -71
- package/src/observe/index.ts +24 -286
- package/src/observe/ios/context.ts +22 -0
- package/src/observe/ios/fingerprint.ts +12 -0
- package/src/observe/ios/log-stream.ts +103 -0
- package/src/observe/ios/logs.ts +179 -0
- package/src/observe/ios/screenshot.ts +26 -0
- package/src/observe/ios/ui-elements.ts +266 -0
- package/src/observe/ios/ui-tree.ts +143 -0
- package/src/observe/ios.ts +18 -749
- package/src/observe/logs/model.ts +11 -0
- package/src/{network → observe/network}/index.ts +2 -2
- package/src/observe/readiness-service.ts +10 -3
- package/src/observe/readiness.ts +49 -22
- package/src/observe/screenshot-encoding.ts +32 -0
- package/src/observe/snapshot-collection.ts +69 -0
- package/src/observe/snapshot-logs.ts +26 -0
- package/src/observe/snapshot-metadata.ts +51 -31
- package/src/observe/snapshot-semantic.ts +153 -0
- package/src/observe/system-trace-android.ts +133 -0
- package/src/observe/system-trace.ts +227 -0
- package/src/runtime/action-results.ts +376 -0
- package/src/runtime/clock.ts +9 -0
- package/src/server/common.ts +9 -359
- package/src/server/definitions/assert.ts +164 -0
- package/src/server/definitions/diagnostic.ts +120 -0
- package/src/server/definitions/input.ts +276 -0
- package/src/server/definitions/manage.ts +196 -0
- package/src/server/definitions/observe.ts +151 -0
- package/src/server/definitions/target.ts +140 -0
- package/src/server/definitions/wait.ts +107 -0
- package/src/server/handlers/action-execution.ts +164 -0
- package/src/server/handlers/correlation.ts +20 -0
- package/src/server/handlers/debugger-handlers.ts +39 -0
- package/src/server/handlers/debugger-response.ts +7 -0
- package/src/server/handlers/diagnostic.ts +79 -0
- package/src/server/handlers/handler-types.ts +7 -0
- package/src/server/handlers/input.ts +173 -0
- package/src/server/handlers/interact.ts +135 -0
- package/src/server/handlers/journey-assertions.ts +39 -0
- package/src/server/handlers/journey.ts +132 -0
- package/src/server/handlers/manage.ts +141 -0
- package/src/server/handlers/observe.ts +116 -0
- package/src/server/handlers/payload.ts +36 -0
- package/src/server/handlers/tool-handlers.ts +159 -0
- package/src/server/schemas/condition-schema.ts +2 -0
- package/src/server/schemas/debugger-schema.ts +43 -0
- package/src/server/{journey-schema.ts → schemas/journey-schema.ts} +8 -22
- package/src/server/schemas/system-trace-schema.ts +17 -0
- package/src/server/tool-definitions.ts +69 -1140
- package/src/server-core.ts +4 -4
- package/src/server.ts +25 -1
- package/src/system/android-status.ts +124 -0
- package/src/system/android.ts +33 -21
- package/src/system/index.ts +21 -523
- package/src/system/ios-status.ts +147 -0
- package/src/system/ios.ts +14 -10
- package/src/system/model.ts +41 -0
- package/src/system/probes.ts +114 -0
- package/src/system/status-summary.ts +47 -0
- package/src/system/unsupported-status.ts +55 -0
- package/src/types.ts +16 -106
- package/src/utils/android/commands.ts +81 -0
- package/src/utils/android/gradle.ts +132 -0
- package/src/utils/android/logs.ts +103 -0
- package/src/utils/android/ui-tree.ts +239 -0
- package/src/utils/android/utils.ts +16 -556
- package/src/utils/cli/idb/check-idb.ts +4 -4
- package/src/utils/cli/idb/idb-helper.ts +6 -8
- package/src/utils/cli/idb/install-idb.ts +15 -9
- package/src/utils/cli/ios/preflight-ios.ts +39 -31
- package/src/utils/cli/ios/run-ios-ui-tree-tap.ts +4 -4
- package/src/utils/exec.ts +2 -0
- package/src/utils/ios/utils.ts +57 -61
- package/src/utils/java.ts +71 -51
- package/src/utils/operation-budget.ts +2 -0
- package/src/utils/resolve-device.ts +11 -6
- package/src/utils/ui/index.ts +28 -28
- package/test/device/automated/debugger/coroutine-lifecycle.ts +27 -0
- package/test/device/automated/debugger/coroutine-support.ts +140 -0
- package/test/device/automated/debugger/coroutine.android.test.ts +169 -0
- package/test/device/automated/debugger/kotlin.android.test.ts +127 -0
- package/test/device/automated/debugger/runtime.android.test.ts +219 -0
- package/test/device/automated/interact/interaction.android.test.ts +56 -0
- package/test/device/automated/observe/system-trace.smoke.ts +104 -0
- package/test/device/manual/interact/modul8_selector_tap.manual.ts +1 -1
- package/test/fixtures/contracts/tool-definitions.json +3536 -0
- package/test/fixtures/coroutine-app/MainActivity.kt +100 -0
- package/test/fixtures/coroutine-app/README.md +48 -0
- package/test/fixtures/coroutine-app/build.ts +35 -0
- package/test/fixtures/debugger-app/MainActivity.java +67 -0
- package/test/fixtures/debugger-app/MainActivity.kt +32 -0
- package/test/fixtures/debugger-app/NoLocals.java +7 -0
- package/test/fixtures/debugger-app/README.md +65 -0
- package/test/fixtures/debugger-app/build.ts +39 -0
- package/test/fixtures/latency-journey-app/README.md +2 -0
- package/test/fixtures/readiness-app/README.md +2 -0
- package/test/helpers/perfetto.ts +59 -0
- package/test/unit/debugger/coroutine-lifecycle.test.ts +43 -0
- package/test/unit/debugger/diagnostic-sessions.test.ts +67 -0
- package/test/unit/debugger/diagnostics.test.ts +80 -0
- package/test/unit/debugger/guards.test.ts +50 -0
- package/test/unit/debugger/native.test.ts +33 -0
- package/test/unit/debugger/preparation.test.ts +32 -0
- package/test/unit/debugger/protocol.test.ts +15 -0
- package/test/unit/debugger/sessions.test.ts +83 -0
- package/test/unit/interact/adjustment_service.test.ts +42 -0
- package/test/unit/interact/adjustment_verification.test.ts +35 -0
- package/test/unit/interact/clock_dependencies.test.ts +63 -0
- package/test/unit/interact/element_helpers.test.ts +19 -0
- package/test/unit/interact/legacy_wait_service.test.ts +17 -0
- package/test/unit/interact/state_comparison.test.ts +20 -0
- package/test/unit/interact/target_scope.test.ts +35 -0
- package/test/unit/network/get_network_activity.test.ts +1 -1
- package/test/unit/observe/readiness.test.ts +3 -1
- package/test/unit/observe/screenshot-encoding.test.ts +30 -0
- package/test/unit/observe/snapshot-logs.test.ts +14 -0
- package/test/unit/observe/system-trace-android.test.ts +52 -0
- package/test/unit/observe/system-trace.test.ts +166 -0
- package/test/unit/quality/architecture.test.ts +60 -0
- package/test/unit/quality/code-quality.test.ts +58 -0
- package/test/unit/quality/interaction_boundaries.test.ts +24 -0
- package/test/unit/server/conditional_actions.test.ts +1 -1
- package/test/unit/server/conditional_schema.test.ts +2 -2
- package/test/unit/server/debugger-response.test.ts +63 -0
- package/test/unit/server/system-trace.test.ts +64 -0
- package/test/unit/server/tool_definitions_parity.test.ts +8 -0
- package/dist/server/tool-handlers.js +0 -893
- package/docs/ROADMAP.md +0 -646
- package/docs/benchmarks/ui-tree-performance/bridge-probe.json +0 -29
- package/docs/benchmarks/ui-tree-performance/initial-baseline.json +0 -59560
- package/docs/specs/baseline-spec-v0.md +0 -312
- package/docs/specs/mcp-tooling-spec-v1.md +0 -446
- package/src/server/tool-handlers.ts +0 -923
- /package/dist/{server/condition-schema.js → contracts/condition.js} +0 -0
- /package/dist/server/{readiness-schema.js → schemas/readiness-schema.js} +0 -0
- /package/src/{server/condition-schema.ts → contracts/condition.ts} +0 -0
- /package/src/server/{readiness-schema.ts → schemas/readiness-schema.ts} +0 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { currentEvidenceActionId } from '../observe/evidence.js';
|
|
2
|
+
import { ToolsObserve } from '../observe/index.js';
|
|
3
|
+
import { isConditionBlocked } from '../interact/conditional-action.js';
|
|
4
|
+
export const DEFAULT_MAX_RECOVERY_ATTEMPTS = 3;
|
|
5
|
+
export const DEFAULT_MAX_RETRY_DEPTH = 3;
|
|
6
|
+
let actionSequence = 0;
|
|
7
|
+
export function nextActionId(actionType, timestamp) {
|
|
8
|
+
const current = currentEvidenceActionId();
|
|
9
|
+
if (current)
|
|
10
|
+
return current;
|
|
11
|
+
actionSequence += 1;
|
|
12
|
+
return `${actionType}_${timestamp}_${actionSequence}`;
|
|
13
|
+
}
|
|
14
|
+
export async function captureActionFingerprint(platform, deviceId) {
|
|
15
|
+
if (isConditionBlocked())
|
|
16
|
+
return null;
|
|
17
|
+
if (!platform)
|
|
18
|
+
return null;
|
|
19
|
+
try {
|
|
20
|
+
const result = await ToolsObserve.getScreenFingerprintHandler({ platform, deviceId });
|
|
21
|
+
return result?.fingerprint ?? null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createTraceStep({ stage, timestamp, result, attemptIndex, cycleId, metadata }) {
|
|
28
|
+
return {
|
|
29
|
+
stage,
|
|
30
|
+
timestamp,
|
|
31
|
+
result,
|
|
32
|
+
attempt_index: attemptIndex,
|
|
33
|
+
...(cycleId !== undefined ? { cycle_id: cycleId } : {}),
|
|
34
|
+
...(metadata ? { metadata } : {})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function buildActionTrace({ actionId, actionType, sourceModule, selector, resolved, success, failure, details, recovery, attempts = 1, steps }) {
|
|
38
|
+
if (steps && steps.length > 0) {
|
|
39
|
+
return {
|
|
40
|
+
action_id: actionId,
|
|
41
|
+
steps,
|
|
42
|
+
final_outcome: success ? 'success' : 'failure',
|
|
43
|
+
attempts: Math.max(1, Math.floor(attempts || steps.length))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
const builtSteps = [];
|
|
48
|
+
let attemptIndex = 0;
|
|
49
|
+
const totalAttempts = Math.max(1, Math.floor(attempts || 1));
|
|
50
|
+
if (selector || resolved) {
|
|
51
|
+
const stageResult = resolved ? 'success' : 'failure';
|
|
52
|
+
builtSteps.push(createTraceStep({
|
|
53
|
+
stage: 'resolve',
|
|
54
|
+
timestamp: start,
|
|
55
|
+
result: stageResult,
|
|
56
|
+
attemptIndex: attemptIndex++,
|
|
57
|
+
metadata: {
|
|
58
|
+
action_type: actionType,
|
|
59
|
+
source_module: sourceModule,
|
|
60
|
+
selector: selector ?? null,
|
|
61
|
+
resolved: resolved ? normalizeResolvedTarget(resolved) : null
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
builtSteps.push(createTraceStep({
|
|
66
|
+
stage: 'execute',
|
|
67
|
+
timestamp: Date.now(),
|
|
68
|
+
result: success ? 'success' : 'failure',
|
|
69
|
+
attemptIndex: attemptIndex++,
|
|
70
|
+
metadata: {
|
|
71
|
+
action_type: actionType,
|
|
72
|
+
source_module: sourceModule,
|
|
73
|
+
...(failure ? { failure_code: failure.failureCode, retryable: failure.retryable } : {})
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
appendObservationAndRecoverySteps({ builtSteps, attemptIndex, details, success, failure, recovery });
|
|
77
|
+
if (!builtSteps.length) {
|
|
78
|
+
builtSteps.push(createTraceStep({
|
|
79
|
+
stage: 'execute',
|
|
80
|
+
timestamp: start,
|
|
81
|
+
result: success ? 'success' : 'failure',
|
|
82
|
+
attemptIndex: 0,
|
|
83
|
+
metadata: { action_type: actionType, source_module: sourceModule }
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
action_id: actionId,
|
|
88
|
+
steps: builtSteps,
|
|
89
|
+
final_outcome: success ? 'success' : 'failure',
|
|
90
|
+
attempts: totalAttempts
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export function normalizeResolvedTarget(value = null) {
|
|
94
|
+
if (!value)
|
|
95
|
+
return null;
|
|
96
|
+
return {
|
|
97
|
+
elementId: value.elementId ?? null,
|
|
98
|
+
text: value.text ?? null,
|
|
99
|
+
resource_id: value.resource_id ?? null,
|
|
100
|
+
accessibility_id: value.accessibility_id ?? null,
|
|
101
|
+
class: value.class ?? null,
|
|
102
|
+
bounds: value.bounds ?? null,
|
|
103
|
+
index: value.index ?? null,
|
|
104
|
+
state: value.state ?? null
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function inferGenericFailure(message) {
|
|
108
|
+
if (message && /timeout/i.test(message))
|
|
109
|
+
return { failureCode: 'TIMEOUT', retryable: true };
|
|
110
|
+
if (message && /semantic mismatch/i.test(message))
|
|
111
|
+
return { failureCode: 'SEMANTIC_MISMATCH', retryable: false };
|
|
112
|
+
return { failureCode: 'UNKNOWN', retryable: false };
|
|
113
|
+
}
|
|
114
|
+
export function inferScrollFailure(message) {
|
|
115
|
+
if (message && /unchanged|no change|end of list/i.test(message))
|
|
116
|
+
return { failureCode: 'NAVIGATION_NO_CHANGE', retryable: true };
|
|
117
|
+
if (message && /timeout/i.test(message))
|
|
118
|
+
return { failureCode: 'TIMEOUT', retryable: true };
|
|
119
|
+
return { failureCode: 'UNKNOWN', retryable: false };
|
|
120
|
+
}
|
|
121
|
+
const ACTION_LIFECYCLE_STATE_BY_OUTCOME = {
|
|
122
|
+
success: 'pending_verification',
|
|
123
|
+
failure: 'failed'
|
|
124
|
+
};
|
|
125
|
+
export function determineActionLifecycleState({ success, failure }) {
|
|
126
|
+
if (failure)
|
|
127
|
+
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.failure;
|
|
128
|
+
if (success)
|
|
129
|
+
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.success;
|
|
130
|
+
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.success;
|
|
131
|
+
}
|
|
132
|
+
function mapFailureCodeToFailureClass(code) {
|
|
133
|
+
switch (code) {
|
|
134
|
+
case 'ELEMENT_NOT_FOUND':
|
|
135
|
+
case 'AMBIGUOUS_TARGET':
|
|
136
|
+
case 'STALE_REFERENCE':
|
|
137
|
+
return 'TargetResolutionFailure';
|
|
138
|
+
case 'ELEMENT_NOT_INTERACTABLE':
|
|
139
|
+
case 'PRECONDITION_FAILED':
|
|
140
|
+
case 'PRECONDITION_UNAVAILABLE':
|
|
141
|
+
case 'ACTION_TIMEOUT':
|
|
142
|
+
return 'ExecutionFailure';
|
|
143
|
+
case 'TIMEOUT':
|
|
144
|
+
case 'ACTION_REJECTED':
|
|
145
|
+
case 'NAVIGATION_NO_CHANGE':
|
|
146
|
+
case 'UNKNOWN':
|
|
147
|
+
return 'ExecutionFailure';
|
|
148
|
+
case 'VERIFICATION_FAILED':
|
|
149
|
+
case 'EXPECT_STATE_MISMATCH':
|
|
150
|
+
case 'ASSERTION_TIMEOUT':
|
|
151
|
+
return 'VerificationFailure';
|
|
152
|
+
case 'CONTROL_CONVERGENCE_FAILED':
|
|
153
|
+
return 'ControlConvergenceFailure';
|
|
154
|
+
case 'SEMANTIC_MISMATCH':
|
|
155
|
+
return 'SemanticMismatchFailure';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function buildRecoveryState(failureCode, retryable) {
|
|
159
|
+
return {
|
|
160
|
+
failure_class: mapFailureCodeToFailureClass(failureCode),
|
|
161
|
+
runtime_code: failureCode,
|
|
162
|
+
recovery_attempts: 0,
|
|
163
|
+
max_recovery_attempts: DEFAULT_MAX_RECOVERY_ATTEMPTS,
|
|
164
|
+
retry_depth: 0,
|
|
165
|
+
max_retry_depth: DEFAULT_MAX_RETRY_DEPTH,
|
|
166
|
+
is_terminal: false,
|
|
167
|
+
retry_allowed: retryable
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export function buildActionExecutionResult({ actionType, device, selector, resolved, success, uiFingerprintBefore, uiFingerprintAfter, failure, details, sourceModule, traceSteps }) {
|
|
171
|
+
const timestampMs = Date.now();
|
|
172
|
+
const timestamp = new Date(timestampMs).toISOString();
|
|
173
|
+
const actionId = nextActionId(actionType, timestampMs);
|
|
174
|
+
const recoveryState = failure ? buildRecoveryState(failure.failureCode, failure.retryable) : undefined;
|
|
175
|
+
const attempts = typeof details?.attempts === 'number' && Number.isFinite(details.attempts)
|
|
176
|
+
? Math.max(1, Math.floor(details.attempts))
|
|
177
|
+
: 1;
|
|
178
|
+
return {
|
|
179
|
+
action_id: actionId,
|
|
180
|
+
timestamp,
|
|
181
|
+
action_type: actionType,
|
|
182
|
+
lifecycle_state: determineActionLifecycleState({ success, failure }),
|
|
183
|
+
source_module: sourceModule,
|
|
184
|
+
...(device ? { device } : {}),
|
|
185
|
+
target: {
|
|
186
|
+
selector,
|
|
187
|
+
resolved: normalizeResolvedTarget(resolved)
|
|
188
|
+
},
|
|
189
|
+
success,
|
|
190
|
+
...(failure ? { failure_code: failure.failureCode, retryable: failure.retryable } : {}),
|
|
191
|
+
...(recoveryState ? { recovery: recoveryState } : {}),
|
|
192
|
+
trace: buildActionTrace({
|
|
193
|
+
actionId,
|
|
194
|
+
actionType,
|
|
195
|
+
sourceModule,
|
|
196
|
+
selector,
|
|
197
|
+
resolved,
|
|
198
|
+
success,
|
|
199
|
+
failure,
|
|
200
|
+
details,
|
|
201
|
+
recovery: recoveryState,
|
|
202
|
+
attempts,
|
|
203
|
+
steps: traceSteps
|
|
204
|
+
}),
|
|
205
|
+
ui_fingerprint_before: uiFingerprintBefore,
|
|
206
|
+
ui_fingerprint_after: uiFingerprintAfter,
|
|
207
|
+
...(details ? { details } : {})
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function appendObservationAndRecoverySteps(context) {
|
|
211
|
+
const attemptIndex = appendStabilizationStep(context);
|
|
212
|
+
const nextIndex = appendVerificationStep({ ...context, attemptIndex });
|
|
213
|
+
appendRecoveryStep({ ...context, attemptIndex: nextIndex });
|
|
214
|
+
}
|
|
215
|
+
function appendStabilizationStep({ builtSteps, attemptIndex, details, success }) {
|
|
216
|
+
const hasStabilizeDetails = Boolean(details && (Object.prototype.hasOwnProperty.call(details, 'stabilization_attempts') ||
|
|
217
|
+
Object.prototype.hasOwnProperty.call(details, 'stable_observation_count') ||
|
|
218
|
+
Object.prototype.hasOwnProperty.call(details, 'snapshot_freshness_ms')));
|
|
219
|
+
if (hasStabilizeDetails) {
|
|
220
|
+
builtSteps.push(createTraceStep({
|
|
221
|
+
stage: 'stabilize',
|
|
222
|
+
timestamp: Date.now(),
|
|
223
|
+
result: success ? 'success' : 'failure',
|
|
224
|
+
attemptIndex: attemptIndex++,
|
|
225
|
+
metadata: {
|
|
226
|
+
stabilization_attempts: details?.stabilization_attempts ?? null,
|
|
227
|
+
stable_observation_count: details?.stable_observation_count ?? null,
|
|
228
|
+
snapshot_freshness_ms: details?.snapshot_freshness_ms ?? null
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
return attemptIndex;
|
|
233
|
+
}
|
|
234
|
+
function appendVerificationStep({ builtSteps, attemptIndex, details, success }) {
|
|
235
|
+
const hasVerifyDetails = Boolean(details && (Object.prototype.hasOwnProperty.call(details, 'within_tolerance') ||
|
|
236
|
+
Object.prototype.hasOwnProperty.call(details, 'converged') ||
|
|
237
|
+
Object.prototype.hasOwnProperty.call(details, 'observed_state')));
|
|
238
|
+
if (hasVerifyDetails) {
|
|
239
|
+
builtSteps.push(createTraceStep({
|
|
240
|
+
stage: 'verify',
|
|
241
|
+
timestamp: Date.now(),
|
|
242
|
+
result: success ? 'success' : 'failure',
|
|
243
|
+
attemptIndex: attemptIndex++,
|
|
244
|
+
metadata: {
|
|
245
|
+
within_tolerance: details?.within_tolerance ?? null,
|
|
246
|
+
converged: details?.converged ?? null,
|
|
247
|
+
actual_state: details?.actual_state ?? null,
|
|
248
|
+
reason: details?.reason ?? null
|
|
249
|
+
}
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
return attemptIndex;
|
|
253
|
+
}
|
|
254
|
+
function appendRecoveryStep({ builtSteps, attemptIndex, failure, recovery }) {
|
|
255
|
+
if (failure) {
|
|
256
|
+
builtSteps.push(createTraceStep({
|
|
257
|
+
stage: 'recover',
|
|
258
|
+
timestamp: Date.now(),
|
|
259
|
+
result: failure.retryable ? 'retry' : 'failure',
|
|
260
|
+
attemptIndex: attemptIndex++,
|
|
261
|
+
metadata: {
|
|
262
|
+
failure_class: recovery?.failure_class ?? mapFailureCodeToFailureClass(failure.failureCode),
|
|
263
|
+
runtime_code: failure.failureCode,
|
|
264
|
+
retry_allowed: failure.retryable,
|
|
265
|
+
recovery_attempts: recovery?.recovery_attempts ?? 0,
|
|
266
|
+
retry_depth: recovery?.retry_depth ?? 0
|
|
267
|
+
}
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
}
|
package/dist/server/common.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { currentEvidenceActionId } from '../observe/evidence.js';
|
|
2
1
|
import { recordTiming } from '../utils/timing.js';
|
|
3
|
-
import { ToolsObserve } from '../observe/index.js';
|
|
4
|
-
import { isConditionBlocked } from '../interact/conditional-action.js';
|
|
5
|
-
export const DEFAULT_MAX_RECOVERY_ATTEMPTS = 3;
|
|
6
|
-
export const DEFAULT_MAX_RETRY_DEPTH = 3;
|
|
7
2
|
export function wrapResponse(data, includeSerializationTiming = true) {
|
|
8
3
|
const start = performance.now();
|
|
9
4
|
let text = JSON.stringify(data, null, 2);
|
|
@@ -62,257 +57,6 @@ export function getArrayArg(args, key) {
|
|
|
62
57
|
const value = args[key];
|
|
63
58
|
return Array.isArray(value) ? value : undefined;
|
|
64
59
|
}
|
|
65
|
-
let actionSequence = 0;
|
|
66
|
-
export function nextActionId(actionType, timestamp) {
|
|
67
|
-
const current = currentEvidenceActionId();
|
|
68
|
-
if (current)
|
|
69
|
-
return current;
|
|
70
|
-
actionSequence += 1;
|
|
71
|
-
return `${actionType}_${timestamp}_${actionSequence}`;
|
|
72
|
-
}
|
|
73
|
-
export async function captureActionFingerprint(platform, deviceId) {
|
|
74
|
-
if (isConditionBlocked())
|
|
75
|
-
return null;
|
|
76
|
-
if (!platform)
|
|
77
|
-
return null;
|
|
78
|
-
try {
|
|
79
|
-
const result = await ToolsObserve.getScreenFingerprintHandler({ platform, deviceId });
|
|
80
|
-
return result?.fingerprint ?? null;
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export function createTraceStep({ stage, timestamp, result, attemptIndex, cycleId, metadata }) {
|
|
87
|
-
return {
|
|
88
|
-
stage,
|
|
89
|
-
timestamp,
|
|
90
|
-
result,
|
|
91
|
-
attempt_index: attemptIndex,
|
|
92
|
-
...(cycleId !== undefined ? { cycle_id: cycleId } : {}),
|
|
93
|
-
...(metadata ? { metadata } : {})
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
export function buildActionTrace({ actionId, actionType, sourceModule, selector, resolved, success, failure, details, recovery, attempts = 1, steps }) {
|
|
97
|
-
if (steps && steps.length > 0) {
|
|
98
|
-
return {
|
|
99
|
-
action_id: actionId,
|
|
100
|
-
steps,
|
|
101
|
-
final_outcome: success ? 'success' : 'failure',
|
|
102
|
-
attempts: Math.max(1, Math.floor(attempts || steps.length))
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const start = Date.now();
|
|
106
|
-
const builtSteps = [];
|
|
107
|
-
let attemptIndex = 0;
|
|
108
|
-
const totalAttempts = Math.max(1, Math.floor(attempts || 1));
|
|
109
|
-
if (selector || resolved) {
|
|
110
|
-
const stageResult = resolved ? 'success' : 'failure';
|
|
111
|
-
builtSteps.push(createTraceStep({
|
|
112
|
-
stage: 'resolve',
|
|
113
|
-
timestamp: start,
|
|
114
|
-
result: stageResult,
|
|
115
|
-
attemptIndex: attemptIndex++,
|
|
116
|
-
metadata: {
|
|
117
|
-
action_type: actionType,
|
|
118
|
-
source_module: sourceModule,
|
|
119
|
-
selector: selector ?? null,
|
|
120
|
-
resolved: resolved ? normalizeResolvedTarget(resolved) : null
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
builtSteps.push(createTraceStep({
|
|
125
|
-
stage: 'execute',
|
|
126
|
-
timestamp: Date.now(),
|
|
127
|
-
result: success ? 'success' : 'failure',
|
|
128
|
-
attemptIndex: attemptIndex++,
|
|
129
|
-
metadata: {
|
|
130
|
-
action_type: actionType,
|
|
131
|
-
source_module: sourceModule,
|
|
132
|
-
...(failure ? { failure_code: failure.failureCode, retryable: failure.retryable } : {})
|
|
133
|
-
}
|
|
134
|
-
}));
|
|
135
|
-
const hasStabilizeDetails = Boolean(details && (Object.prototype.hasOwnProperty.call(details, 'stabilization_attempts') ||
|
|
136
|
-
Object.prototype.hasOwnProperty.call(details, 'stable_observation_count') ||
|
|
137
|
-
Object.prototype.hasOwnProperty.call(details, 'snapshot_freshness_ms')));
|
|
138
|
-
const hasVerifyDetails = Boolean(details && (Object.prototype.hasOwnProperty.call(details, 'within_tolerance') ||
|
|
139
|
-
Object.prototype.hasOwnProperty.call(details, 'converged') ||
|
|
140
|
-
Object.prototype.hasOwnProperty.call(details, 'observed_state')));
|
|
141
|
-
if (hasStabilizeDetails) {
|
|
142
|
-
builtSteps.push(createTraceStep({
|
|
143
|
-
stage: 'stabilize',
|
|
144
|
-
timestamp: Date.now(),
|
|
145
|
-
result: success ? 'success' : 'failure',
|
|
146
|
-
attemptIndex: attemptIndex++,
|
|
147
|
-
metadata: {
|
|
148
|
-
stabilization_attempts: details?.stabilization_attempts ?? null,
|
|
149
|
-
stable_observation_count: details?.stable_observation_count ?? null,
|
|
150
|
-
snapshot_freshness_ms: details?.snapshot_freshness_ms ?? null
|
|
151
|
-
}
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
if (hasVerifyDetails) {
|
|
155
|
-
builtSteps.push(createTraceStep({
|
|
156
|
-
stage: 'verify',
|
|
157
|
-
timestamp: Date.now(),
|
|
158
|
-
result: success ? 'success' : 'failure',
|
|
159
|
-
attemptIndex: attemptIndex++,
|
|
160
|
-
metadata: {
|
|
161
|
-
within_tolerance: details?.within_tolerance ?? null,
|
|
162
|
-
converged: details?.converged ?? null,
|
|
163
|
-
actual_state: details?.actual_state ?? null,
|
|
164
|
-
reason: details?.reason ?? null
|
|
165
|
-
}
|
|
166
|
-
}));
|
|
167
|
-
}
|
|
168
|
-
if (failure) {
|
|
169
|
-
builtSteps.push(createTraceStep({
|
|
170
|
-
stage: 'recover',
|
|
171
|
-
timestamp: Date.now(),
|
|
172
|
-
result: failure.retryable ? 'retry' : 'failure',
|
|
173
|
-
attemptIndex: attemptIndex++,
|
|
174
|
-
metadata: {
|
|
175
|
-
failure_class: recovery?.failure_class ?? mapFailureCodeToFailureClass(failure.failureCode),
|
|
176
|
-
runtime_code: failure.failureCode,
|
|
177
|
-
retry_allowed: failure.retryable,
|
|
178
|
-
recovery_attempts: recovery?.recovery_attempts ?? 0,
|
|
179
|
-
retry_depth: recovery?.retry_depth ?? 0
|
|
180
|
-
}
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
if (!builtSteps.length) {
|
|
184
|
-
builtSteps.push(createTraceStep({
|
|
185
|
-
stage: 'execute',
|
|
186
|
-
timestamp: start,
|
|
187
|
-
result: success ? 'success' : 'failure',
|
|
188
|
-
attemptIndex: 0,
|
|
189
|
-
metadata: { action_type: actionType, source_module: sourceModule }
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
action_id: actionId,
|
|
194
|
-
steps: builtSteps,
|
|
195
|
-
final_outcome: success ? 'success' : 'failure',
|
|
196
|
-
attempts: totalAttempts
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
export function normalizeResolvedTarget(value = null) {
|
|
200
|
-
if (!value)
|
|
201
|
-
return null;
|
|
202
|
-
return {
|
|
203
|
-
elementId: value.elementId ?? null,
|
|
204
|
-
text: value.text ?? null,
|
|
205
|
-
resource_id: value.resource_id ?? null,
|
|
206
|
-
accessibility_id: value.accessibility_id ?? null,
|
|
207
|
-
class: value.class ?? null,
|
|
208
|
-
bounds: value.bounds ?? null,
|
|
209
|
-
index: value.index ?? null,
|
|
210
|
-
state: value.state ?? null
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
export function inferGenericFailure(message) {
|
|
214
|
-
if (message && /timeout/i.test(message))
|
|
215
|
-
return { failureCode: 'TIMEOUT', retryable: true };
|
|
216
|
-
if (message && /semantic mismatch/i.test(message))
|
|
217
|
-
return { failureCode: 'SEMANTIC_MISMATCH', retryable: false };
|
|
218
|
-
return { failureCode: 'UNKNOWN', retryable: false };
|
|
219
|
-
}
|
|
220
|
-
export function inferScrollFailure(message) {
|
|
221
|
-
if (message && /unchanged|no change|end of list/i.test(message))
|
|
222
|
-
return { failureCode: 'NAVIGATION_NO_CHANGE', retryable: true };
|
|
223
|
-
if (message && /timeout/i.test(message))
|
|
224
|
-
return { failureCode: 'TIMEOUT', retryable: true };
|
|
225
|
-
return { failureCode: 'UNKNOWN', retryable: false };
|
|
226
|
-
}
|
|
227
|
-
const ACTION_LIFECYCLE_STATE_BY_OUTCOME = {
|
|
228
|
-
success: 'pending_verification',
|
|
229
|
-
failure: 'failed'
|
|
230
|
-
};
|
|
231
|
-
export function determineActionLifecycleState({ success, failure }) {
|
|
232
|
-
if (failure)
|
|
233
|
-
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.failure;
|
|
234
|
-
if (success)
|
|
235
|
-
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.success;
|
|
236
|
-
return ACTION_LIFECYCLE_STATE_BY_OUTCOME.success;
|
|
237
|
-
}
|
|
238
|
-
function mapFailureCodeToFailureClass(code) {
|
|
239
|
-
switch (code) {
|
|
240
|
-
case 'ELEMENT_NOT_FOUND':
|
|
241
|
-
case 'AMBIGUOUS_TARGET':
|
|
242
|
-
case 'STALE_REFERENCE':
|
|
243
|
-
return 'TargetResolutionFailure';
|
|
244
|
-
case 'ELEMENT_NOT_INTERACTABLE':
|
|
245
|
-
case 'PRECONDITION_FAILED':
|
|
246
|
-
case 'PRECONDITION_UNAVAILABLE':
|
|
247
|
-
case 'ACTION_TIMEOUT':
|
|
248
|
-
return 'ExecutionFailure';
|
|
249
|
-
case 'TIMEOUT':
|
|
250
|
-
case 'ACTION_REJECTED':
|
|
251
|
-
case 'NAVIGATION_NO_CHANGE':
|
|
252
|
-
case 'UNKNOWN':
|
|
253
|
-
return 'ExecutionFailure';
|
|
254
|
-
case 'VERIFICATION_FAILED':
|
|
255
|
-
case 'EXPECT_STATE_MISMATCH':
|
|
256
|
-
case 'ASSERTION_TIMEOUT':
|
|
257
|
-
return 'VerificationFailure';
|
|
258
|
-
case 'CONTROL_CONVERGENCE_FAILED':
|
|
259
|
-
return 'ControlConvergenceFailure';
|
|
260
|
-
case 'SEMANTIC_MISMATCH':
|
|
261
|
-
return 'SemanticMismatchFailure';
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function buildRecoveryState(failureCode, retryable) {
|
|
265
|
-
return {
|
|
266
|
-
failure_class: mapFailureCodeToFailureClass(failureCode),
|
|
267
|
-
runtime_code: failureCode,
|
|
268
|
-
recovery_attempts: 0,
|
|
269
|
-
max_recovery_attempts: DEFAULT_MAX_RECOVERY_ATTEMPTS,
|
|
270
|
-
retry_depth: 0,
|
|
271
|
-
max_retry_depth: DEFAULT_MAX_RETRY_DEPTH,
|
|
272
|
-
is_terminal: false,
|
|
273
|
-
retry_allowed: retryable
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
export function buildActionExecutionResult({ actionType, device, selector, resolved, success, uiFingerprintBefore, uiFingerprintAfter, failure, details, sourceModule, traceSteps }) {
|
|
277
|
-
const timestampMs = Date.now();
|
|
278
|
-
const timestamp = new Date(timestampMs).toISOString();
|
|
279
|
-
const actionId = nextActionId(actionType, timestampMs);
|
|
280
|
-
const recoveryState = failure ? buildRecoveryState(failure.failureCode, failure.retryable) : undefined;
|
|
281
|
-
const attempts = typeof details?.attempts === 'number' && Number.isFinite(details.attempts)
|
|
282
|
-
? Math.max(1, Math.floor(details.attempts))
|
|
283
|
-
: 1;
|
|
284
|
-
return {
|
|
285
|
-
action_id: actionId,
|
|
286
|
-
timestamp,
|
|
287
|
-
action_type: actionType,
|
|
288
|
-
lifecycle_state: determineActionLifecycleState({ success, failure }),
|
|
289
|
-
source_module: sourceModule,
|
|
290
|
-
...(device ? { device } : {}),
|
|
291
|
-
target: {
|
|
292
|
-
selector,
|
|
293
|
-
resolved: normalizeResolvedTarget(resolved)
|
|
294
|
-
},
|
|
295
|
-
success,
|
|
296
|
-
...(failure ? { failure_code: failure.failureCode, retryable: failure.retryable } : {}),
|
|
297
|
-
...(recoveryState ? { recovery: recoveryState } : {}),
|
|
298
|
-
trace: buildActionTrace({
|
|
299
|
-
actionId,
|
|
300
|
-
actionType,
|
|
301
|
-
sourceModule,
|
|
302
|
-
selector,
|
|
303
|
-
resolved,
|
|
304
|
-
success,
|
|
305
|
-
failure,
|
|
306
|
-
details,
|
|
307
|
-
recovery: recoveryState,
|
|
308
|
-
attempts,
|
|
309
|
-
steps: traceSteps
|
|
310
|
-
}),
|
|
311
|
-
ui_fingerprint_before: uiFingerprintBefore,
|
|
312
|
-
ui_fingerprint_after: uiFingerprintAfter,
|
|
313
|
-
...(details ? { details } : {})
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
60
|
export function wrapToolError(name, error) {
|
|
317
61
|
const message = error instanceof Error
|
|
318
62
|
? error.message
|
|
@@ -338,3 +82,4 @@ export function wrapToolError(name, error) {
|
|
|
338
82
|
}]
|
|
339
83
|
};
|
|
340
84
|
}
|
|
85
|
+
export { DEFAULT_MAX_RECOVERY_ATTEMPTS, DEFAULT_MAX_RETRY_DEPTH, nextActionId, captureActionFingerprint, createTraceStep, buildActionTrace, normalizeResolvedTarget, inferGenericFailure, inferScrollFailure, determineActionLifecycleState, buildActionExecutionResult } from '../runtime/action-results.js';
|