agent-device 0.20.9 → 0.20.10
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/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.apk → agent-device-android-ime-helper-0.20.10.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.10.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.manifest.json → agent-device-android-ime-helper-0.20.10.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.apk → agent-device-android-snapshot-helper-0.20.10.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.10.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.manifest.json → agent-device-android-snapshot-helper-0.20.10.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +6 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +4 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +94 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +22 -23
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +3 -23
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +10 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +30 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +8 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +133 -63
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +13 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentation.swift +183 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationTests.swift +0 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +20 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +19 -0
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.d.ts +61 -0
- package/dist/src/ai-sdk.js +1 -0
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apps.js +5 -5
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +30 -23
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +7 -7
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +1582 -0
- package/dist/src/command-tools.js +2 -0
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-shutdown-report.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/dispatch.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper-package-install.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/ime-lifecycle.js +1 -1
- package/dist/src/ime-recovery-marker.js +1 -1
- package/dist/src/index.d.ts +2 -1578
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions3.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-common.js +1 -1
- package/dist/src/interaction-runtime.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +2 -2
- package/dist/src/internal/daemon.js +4 -4
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun.d.ts +10 -2
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/{screenshot-geometry.js → mobile-snapshot-semantics.js} +1 -1
- package/dist/src/perf.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-resize.js +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/registry.js +27 -27
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay.js +2 -2
- package/dist/src/reporting.js +5 -5
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +3 -3
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screenshot-result.js +4 -4
- package/dist/src/screenshot.js +1 -1
- package/dist/src/script-source-bundle.js +16 -0
- package/dist/src/sdk-android-adb.d.ts +40 -40
- package/dist/src/sdk-android-adb.js +4 -4
- package/dist/src/sdk-batch-runner.js +3 -3
- package/dist/src/sdk-contracts.d.ts +122 -85
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-selectors.d.ts +89 -77
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +10 -3
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session2.js +7 -8
- package/dist/src/shared.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-scope.js +1 -0
- package/dist/src/snapshot.js +6 -6
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +1 -1
- package/dist/src/src3.js +1 -1
- package/dist/src/src4.js +1 -0
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -0
- package/dist/src/verified-file.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +21 -8
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +0 -1
- package/dist/src/cancel.js +0 -1
- package/dist/src/prepare-kind.js +0 -15
- package/dist/src/selector-vocabulary.js +0 -1
|
@@ -1,45 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as Rect, v as Point } from "./sdk-contracts.js";
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
3
|
import { StdioOptions, spawn } from "node:child_process";
|
|
4
|
-
//#region src/platforms/android/ime-helper-types.d.ts
|
|
5
|
-
type AndroidImeHelperManifest = {
|
|
6
|
-
name: 'android-ime-helper';
|
|
7
|
-
version: string;
|
|
8
|
-
assetName: string;
|
|
9
|
-
sha256: string;
|
|
10
|
-
packageName: string;
|
|
11
|
-
versionCode: number;
|
|
12
|
-
serviceComponent: string;
|
|
13
|
-
broadcastProtocol: 'android-ime-helper-v1';
|
|
14
|
-
};
|
|
15
|
-
type AndroidImeHelperArtifact = {
|
|
16
|
-
apkPath: string;
|
|
17
|
-
manifest: AndroidImeHelperManifest;
|
|
18
|
-
};
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/platforms/android/snapshot-helper-types.d.ts
|
|
21
|
-
type AndroidSnapshotHelperManifest = {
|
|
22
|
-
name: 'android-snapshot-helper';
|
|
23
|
-
version: string;
|
|
24
|
-
releaseTag?: string;
|
|
25
|
-
assetName?: string;
|
|
26
|
-
apkUrl: string | null;
|
|
27
|
-
sha256: string;
|
|
28
|
-
checksumName?: string;
|
|
29
|
-
packageName: string;
|
|
30
|
-
versionCode: number;
|
|
31
|
-
instrumentationRunner: string;
|
|
32
|
-
minSdk: number;
|
|
33
|
-
targetSdk?: number;
|
|
34
|
-
outputFormat: 'uiautomator-xml';
|
|
35
|
-
statusProtocol: 'android-snapshot-helper-v1';
|
|
36
|
-
installArgs: string[];
|
|
37
|
-
};
|
|
38
|
-
type AndroidSnapshotHelperArtifact = {
|
|
39
|
-
apkPath: string;
|
|
40
|
-
manifest: AndroidSnapshotHelperManifest;
|
|
41
|
-
};
|
|
42
|
-
//#endregion
|
|
43
4
|
//#region packages/contracts/src/scroll-gesture.d.ts
|
|
44
5
|
declare const SCROLL_INPUT_DIRECTIONS: readonly ['up', 'down', 'left', 'right', 'top', 'bottom'];
|
|
45
6
|
type ScrollInputDirection = (typeof SCROLL_INPUT_DIRECTIONS)[number];
|
|
@@ -92,6 +53,45 @@ type MultiTouchGesturePlan = {
|
|
|
92
53
|
};
|
|
93
54
|
type GesturePlan = SinglePointerGesturePlan | MultiTouchGesturePlan;
|
|
94
55
|
//#endregion
|
|
56
|
+
//#region src/platforms/android/ime-helper-types.d.ts
|
|
57
|
+
type AndroidImeHelperManifest = {
|
|
58
|
+
name: 'android-ime-helper';
|
|
59
|
+
version: string;
|
|
60
|
+
assetName: string;
|
|
61
|
+
sha256: string;
|
|
62
|
+
packageName: string;
|
|
63
|
+
versionCode: number;
|
|
64
|
+
serviceComponent: string;
|
|
65
|
+
broadcastProtocol: 'android-ime-helper-v1';
|
|
66
|
+
};
|
|
67
|
+
type AndroidImeHelperArtifact = {
|
|
68
|
+
apkPath: string;
|
|
69
|
+
manifest: AndroidImeHelperManifest;
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/platforms/android/snapshot-helper-types.d.ts
|
|
73
|
+
type AndroidSnapshotHelperManifest = {
|
|
74
|
+
name: 'android-snapshot-helper';
|
|
75
|
+
version: string;
|
|
76
|
+
releaseTag?: string;
|
|
77
|
+
assetName?: string;
|
|
78
|
+
apkUrl: string | null;
|
|
79
|
+
sha256: string;
|
|
80
|
+
checksumName?: string;
|
|
81
|
+
packageName: string;
|
|
82
|
+
versionCode: number;
|
|
83
|
+
instrumentationRunner: string;
|
|
84
|
+
minSdk: number;
|
|
85
|
+
targetSdk?: number;
|
|
86
|
+
outputFormat: 'uiautomator-xml';
|
|
87
|
+
statusProtocol: 'android-snapshot-helper-v1';
|
|
88
|
+
installArgs: string[];
|
|
89
|
+
};
|
|
90
|
+
type AndroidSnapshotHelperArtifact = {
|
|
91
|
+
apkPath: string;
|
|
92
|
+
manifest: AndroidSnapshotHelperManifest;
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
95
|
//#region src/platforms/android/touch-plan.d.ts
|
|
96
96
|
type AndroidLongPressTouchPlan = {
|
|
97
97
|
topology: 'single';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime.js";import{
|
|
2
|
-
`)}\n`)}let n=t.logPath;return t.events=[],t.liveWrittenEventCount=0,n}let e=
|
|
3
|
-
`)}\n`),t.events=[],s}catch{return null}}function b(e,n){return x(t(n),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function x(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>x(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,x(n,t)]))}function oe(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function S(e,t){o.mkdirSync(r.dirname(e),{recursive:!0}),o.appendFileSync(e,t,`utf8`)}const se=new Set([`1`,`true`,`yes`,`on`]),ce=new Set([`0`,`false`,`no`,`off`]);function le(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function ue(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>ue({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return de(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&C(t)!==void 0)return C(t);if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return fe(e,t,r,i);if(typeof t!=`string`||!e.enumValues?.includes(t))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return t}let a=typeof t==`number`?t:typeof t==`string`?Number(t):NaN;if(!Number.isFinite(a)||e.type===`int`&&!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected ${e.type===`int`?`integer`:`number`}.`);if(typeof e.min==`number`&&a<e.min)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function de(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=C(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function C(e){let t=e.trim().toLowerCase();if(se.has(t))return!0;if(ce.has(t))return!1}function fe(e,t,r,i){let a=e.setValue;if(t===a)return a;if(typeof t==`string`){let e=t.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(t===!0)return a;if(t!==!1)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}var pe=e({coerceExecResult:()=>O,execFailureDetails:()=>V,isExecutablePath:()=>H,requireExecSuccess:()=>we,resolveExecutableOverridePath:()=>A,resolveFileOverridePath:()=>ve,runCmd:()=>E,runCmdBackground:()=>P,runCmdDetached:()=>M,runCmdDetachedMonitored:()=>N,runCmdStreaming:()=>D,runCmdSync:()=>j,whichCmd:()=>_e,withCommandExecutorOverride:()=>ge,withoutCommandExecutorOverride:()=>T});const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],w=new a;async function ge(e,t){return e?await w.run(e,t):await t()}async function T(e){return await w.run(void 0,e)}async function E(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}async function D(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}function O(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function k(e,t,n={}){let r=L(e),i=F();return new Promise((a,o)=>{let s=p(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=U(n.timeoutMs),m=f?setTimeout(()=>{d=!0,W(s,n.detached)},f):null,h=Me(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),Ne(s,n.stdin).catch(i=>{h.didAbort||d||Pe(i)||(o(xe(r,e,t,i)),W(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t),o(Te(h,r,e,t,n))}),s.on(`close`,s=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t);let p=s??1;if(!h.didAbort&&d&&f){o(Se(r,e,t,f,p,c,u));return}let g=Ee(h,r,e,t,p,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:p,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function _e(e){let t=Oe(e);if(!t)return!1;if(r.isAbsolute(t))return H(t);let n=process.env.PATH;if(!n)return!1;let i=ke();for(let e of n.split(r.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,i))if(await H(r.join(n,e)))return!0}}return!1}async function A(e,t){let r=De(e,t,`executable`);if(r){if(!await H(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function ve(e,t){let r=De(e,t,`file`);if(r){if(!await je(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-file path: ${r}`,{envName:t,path:r});return r}}function j(e,t,r={}){let i=L(e),a=m(i,t,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:U(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new n(`COMMAND_FAILED`,`${i} timed out after ${U(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:U(r.timeoutMs)},a.error):o===`ENOENT`?R(i,e,a.error):z(i,e,t,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw Ce(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function M(e,t,n={}){return N(e,t,n).pid}function N(e,t,n={}){let r=p(L(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function P(e,t,n={}){let r=L(e),i=F(),a=p(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=Me(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(Te(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=Ee(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function F(){let e=v(),t=e.debug===!0,n=C(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return ye();n&&e.flushOnSuccess!==!0&&_({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,I({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{I({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,I({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function ye(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function I(e){let t=e.args.slice(0,6);y({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function L(e){let t=Oe(e);if(!t)throw new n(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return t}function be(e,t,n,r){return r.code===`ENOENT`?R(e,t,r):z(e,t,n,r)}function R(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function z(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function xe(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:t,args:r},i instanceof Error?i:void 0)}function B(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Se(e,t,r,i,a,o,s){return new n(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:t,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function Ce(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,V({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function we(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,V(e,typeof r==`function`?r(e):r))}function V(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function Te(e,t,n,r,i){return e.didAbort?B(t,n,r):be(t,n,r,i)}function Ee(e,t,n,r,i,a,o,s){return e.didAbort?B(t,n,r):i!==0&&!a?Ce(t,n,r,i,o,s):null}function De(e,t,i){let a=e?.trim();if(a){if(!r.isAbsolute(a)||a.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${i} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return a}}function Oe(e){let t=e.trim();return!t||t.includes(`\0`)?null:r.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:me.test(t)?t:null}function ke(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return he;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:he}function Ae(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function H(e){try{return await je(e)?(await d(e,process.platform===`win32`?s.F_OK:s.X_OK),!0):!1}catch{return!1}}async function je(e){try{return(await f(e)).isFile()}catch{return!1}}function U(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function Me(e,t){let n=!1,r=()=>{n=!0,W(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function W(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function Ne(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await l(u.from([t]),e.stdin)}}function Pe(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Fe=e({androidAdbResultError:()=>q,attachAdbFailureHint:()=>K,classifyAdbFailure:()=>Re,createAndroidPortReverseManager:()=>Ye,createDeviceAdbExecutor:()=>X,createLocalAndroidAdbProvider:()=>We,installAndroidAdbPackage:()=>Ze,pullAndroidAdbFile:()=>Xe,resolveAndroidAdbExecutor:()=>Ge,resolveAndroidAdbProvider:()=>Z,resolveAndroidTextInjector:()=>qe,resolveAndroidTouchProvider:()=>Je,resolveScopedAndroidAdbBackgroundTransport:()=>Ke,withAndroidAdbProvider:()=>Qe});const Ie=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Le=Object.freeze({reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`});function Re(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Ie)if(e.test(n)||t&&e.test(r))return i}const G=new a;function K(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=ze(e);return t&&(e.details={...e.details,adbFailure:t.reason,...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function ze(e){return typeof e.details?.timeoutMs==`number`?Le:Re(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function q(e,t,r){return K(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:V(t,r)))}function J(e){return async(...t)=>{try{return await e(...t)}catch(e){throw K(e)}}}const Be=new WeakSet;function Ve(e){if(Be.has(e))return e;let t={...e,exec:J(Y(e.exec)),...e.pull?{pull:J(Y(e.pull))}:{},...e.install?{install:J(Y(e.install))}:{},...e.installBundle?{installBundle:J(e.installBundle)}:{}};return Be.add(t),t}function Y(e){return async(...t)=>O(await e(...t))}function X(e){return He(e.id)}function He(e){return J(async(t,n)=>await T(async()=>await E(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Ue(e){return(t,n)=>{let r=P(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function We(e){let t=X(e);return{exec:t,spawn:Ue(e.id),reverse:nt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=at(n);return await t([`install`,...r,e],i)}}}function Ge(e,t){let n=G.getStore();return t||(n?.serial===e.id?n.provider.exec:X(e))}function Z(e,t){if(t)return Q(t);let n=G.getStore();return n?.serial===e.id?Q(n.provider):We(e)}function Ke(e){let t=G.getStore();return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:t.provider.spawn}:{}}:{mode:`local`}}function qe(e){let t=G.getStore();return t?.serial===e.id?t.provider.text:void 0}function Je(e){let t=G.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function Ye(e){let t=Q(e);if(t.reverse&&tt.has(t.reverse))return t.reverse;let r=t.reverse??nt(t.exec),i=new Map,a={async ensure(e,t){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new n(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,t),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return tt.add(a),a}function Q(e){return Ve(typeof e==`function`?{exec:e}:e)}async function Xe(e,t,r){let{device:i,provider:a,...o}=r??{},s=$(i,a),c=s?.pull;if(c)return await T(async()=>await c(e,t,o));let l=s?.exec;if(!l)throw new n(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await T(async()=>await l([`pull`,e,t],o))}async function Ze(e,t){let{device:r,provider:i,...a}=t??{},o=$(r,i),s=o?.install;if(s)return await T(async()=>await s(e,a));let c=o?.exec;if(!c)throw new n(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=at(a);return await T(async()=>await c([`install`,...l,e],u))}function $(e,t){if(t)return Q(t);if(e)return Z(e);let n=G.getStore();if(n)return Q(n.provider)}async function Qe(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=$e(r);return await G.run(r,async()=>await ge(i,n))}function $e(e){return(t,n,r)=>{if(t!==`adb`)return;let i=et(n,e.serial);if(i)return T(async()=>await e.provider.exec(i,r))}}function et(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const tt=new WeakSet;function nt(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!it(i.stdout,i.stderr))throw q(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?rt(r.stdout,t):[]}}}function rt(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
4
|
-
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function
|
|
1
|
+
import{n as e}from"./rolldown-runtime.js";import{_ as t,j as n,y as r}from"./sdk-contracts.js";import i from"node:path";import a from"node:crypto";import o,{constants as s}from"node:fs";import c from"node:os";import{AsyncLocalStorage as l}from"node:async_hooks";import{pipeline as u}from"node:stream/promises";import{Readable as d}from"node:stream";import{access as f,stat as p}from"node:fs/promises";import{spawn as m,spawnSync as h}from"node:child_process";const g=new l;function ee(){return a.randomBytes(8).toString(`hex`)}function te(){return`${Date.now().toString(36)}-${a.randomBytes(4).toString(`hex`)}`}async function ne(e,t){let n={...e,diagnosticId:te(),events:[],liveWrittenEventCount:0,phaseCounts:new Map,sensitiveValues:new Set};return await g.run(n,t)}function re(e){let t=g.getStore();t&&Object.assign(t,e)}function ie(){let e=g.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug,flushOnSuccess:e.flushOnSuccess}:{}}function ae(e){e&&g.getStore()?.sensitiveValues.add(e)}function oe(e){let t=g.getStore();if(!t)return 0;let n=0;for(let r of e)n+=t.phaseCounts.get(r)??0;return n}function _(e){let t=g.getStore();if(!t)return;let n={ts:new Date().toISOString(),level:e.level??`info`,phase:e.phase,session:t.session,requestId:t.requestId,command:t.command,durationMs:e.durationMs,data:e.data?v(t,e.data):void 0};if(t.events.push(n),t.phaseCounts.set(e.phase,(t.phaseCounts.get(e.phase)??0)+1),!t.debug&&!t.traceLogPath)return;let r=`${JSON.stringify(n)}\n`;try{t.debug&&t.logPath&&(b(t.logPath,r),t.liveWrittenEventCount=t.events.length),t.traceLogPath&&b(t.traceLogPath,r),t.debug&&!t.logPath&&!t.traceLogPath&&process.stderr.write(`[agent-device][diag] ${r}`)}catch{}}async function se(e,t,n){let r=Date.now();try{let i=await t();return _({level:`info`,phase:e,durationMs:Date.now()-r,data:n}),i}catch(t){throw _({level:`error`,phase:e,durationMs:Date.now()-r,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function ce(e={}){let t=g.getStore();if(!t||!e.force&&!t.debug&&!t.flushOnSuccess||t.events.length===0)return null;try{if(t.logPath){let e=t.events.slice(t.liveWrittenEventCount);if(e.length>0){let n=e.map(e=>JSON.stringify(v(t,e)));b(t.logPath,`${n.join(`
|
|
2
|
+
`)}\n`)}let n=t.logPath,r=t.logRecord;return t.events=[],t.liveWrittenEventCount=0,{path:n,...r?{ref:r}:{}}}let e=le(t.session??`default`),n=new Date().toISOString().slice(0,10),r=i.join(c.homedir(),`.agent-device`,`logs`,e,n);o.mkdirSync(r,{recursive:!0});let a=new Date().toISOString().replace(/[:.]/g,`-`),s=i.join(r,`${a}-${t.diagnosticId}.ndjson`),l=t.events.map(e=>JSON.stringify(v(t,e)));return o.writeFileSync(s,`${l.join(`
|
|
3
|
+
`)}\n`),t.events=[],{path:s}}catch{return null}}function v(e,t){return y(n(t),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function y(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>y(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,y(n,t)]))}function le(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function b(e,t){o.mkdirSync(i.dirname(e),{recursive:!0}),o.appendFileSync(e,t,`utf8`)}const ue=new Set([`1`,`true`,`yes`,`on`]),de=new Set([`0`,`false`,`no`,`off`]);function fe(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function pe(e,n,r,i){if(e.multiple)return(Array.isArray(n)?n:[n]).map(t=>pe({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return me(n,r,i);if(e.type===`booleanOrString`){if(typeof n==`boolean`)return n;if(typeof n==`string`&&x(n)!==void 0)return x(n);if(typeof n==`string`&&n.trim().length>0)return n;throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof n==`string`&&n.trim().length>0)return n;throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return he(e,n,r,i);if(typeof n!=`string`||!e.enumValues?.includes(n))throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return n}let a=typeof n==`number`?n:typeof n==`string`?Number(n):NaN;if(!Number.isFinite(a)||e.type===`int`&&!Number.isInteger(a))throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected ${e.type===`int`?`integer`:`number`}.`);if(typeof e.min==`number`&&a<e.min)throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function me(e,n,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=x(e);if(t!==void 0)return t}throw new t(`INVALID_ARGS`,`Invalid value for "${r}" in ${n}. Expected boolean.`)}function x(e){let t=e.trim().toLowerCase();if(ue.has(t))return!0;if(de.has(t))return!1}function he(e,n,r,i){let a=e.setValue;if(n===a)return a;if(typeof n==`string`){let e=n.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(n===!0)return a;if(n!==!1)throw new t(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}var ge=e({coerceExecResult:()=>E,execFailureDetails:()=>V,isExecutablePath:()=>H,requireExecSuccess:()=>Te,resolveExecutableOverridePath:()=>k,resolveFileOverridePath:()=>be,runCmd:()=>w,runCmdBackground:()=>N,runCmdDetached:()=>j,runCmdDetachedMonitored:()=>M,runCmdStreaming:()=>T,runCmdSync:()=>A,whichCmd:()=>O,withCommandExecutorOverride:()=>ye,withoutCommandExecutorOverride:()=>C});const _e=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,ve=[`.com`,`.exe`,`.bat`,`.cmd`],S=new l;async function ye(e,t){return e?await S.run(e,t):await t()}async function C(e){return await S.run(void 0,e)}async function w(e,t,n={}){let r=S.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}async function T(e,t,n={}){let r=S.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}function E(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function D(e,t,n={}){let r=I(e),i=P();return new Promise((a,o)=>{let s=m(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=U(n.timeoutMs),p=f?setTimeout(()=>{d=!0,W(s,n.detached)},f):null,h=Ne(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),Pe(s,n.stdin).catch(i=>{h.didAbort||d||Fe(i)||(o(Ce(r,e,t,i)),W(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{p&&clearTimeout(p),h.dispose(),i.emitForegroundCompletion(e,t),o(Ee(h,r,e,t,n))}),s.on(`close`,s=>{p&&clearTimeout(p),h.dispose(),i.emitForegroundCompletion(e,t);let m=s??1;if(!h.didAbort&&d&&f){o(we(r,e,t,f,m,c,u));return}let g=De(h,r,e,t,m,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:m,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function O(e){let t=ke(e);if(!t)return!1;if(i.isAbsolute(t))return H(t);let n=process.env.PATH;if(!n)return!1;let r=Ae();for(let e of n.split(i.delimiter)){let n=e.trim();if(n){for(let e of je(t,r))if(await H(i.join(n,e)))return!0}}return!1}async function k(e,n){let r=Oe(e,n,`executable`);if(r){if(!await H(r))throw new t(`TOOL_MISSING`,`${n} points to a missing or non-executable file: ${r}`,{envName:n,path:r});return r}}async function be(e,n){let r=Oe(e,n,`file`);if(r){if(!await Me(r))throw new t(`TOOL_MISSING`,`${n} points to a missing or non-file path: ${r}`,{envName:n,path:r});return r}}function A(e,n,r={}){let i=I(e),a=h(i,n,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:U(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new t(`COMMAND_FAILED`,`${i} timed out after ${U(r.timeoutMs)}ms`,{cmd:e,args:n,timeoutMs:U(r.timeoutMs)},a.error):o===`ENOENT`?L(i,e,a.error):R(i,e,n,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw B(i,e,n,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function j(e,t,n={}){return M(e,t,n).pid}function M(e,t,n={}){let r=m(I(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function N(e,t,n={}){let r=I(e),i=P(),a=m(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=Ne(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(Ee(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=De(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function P(){let e=ie(),t=e.debug===!0,n=x(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return xe();n&&e.flushOnSuccess!==!0&&re({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,F({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{F({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,F({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function xe(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function F(e){let t=e.args.slice(0,6);_({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function I(e){let n=ke(e);if(!n)throw new t(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return n}function Se(e,t,n,r){return r.code===`ENOENT`?L(e,t,r):R(e,t,n,r)}function L(e,n,r){return new t(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:n},r)}function R(e,n,r,i){return new t(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:n,args:r},i)}function Ce(e,n,r,i){return new t(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:n,args:r},i instanceof Error?i:void 0)}function z(e,t,n){return r({cmd:t,args:n,executable:e})}function we(e,n,r,i,a,o,s){return new t(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:n,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function B(e,n,r,i,a,o){return new t(`COMMAND_FAILED`,`${e} exited with code ${i}`,V({stdout:a,stderr:o,exitCode:i},{cmd:n,args:r}))}function Te(e,n,r){if(e.exitCode===0)return e;throw new t(`COMMAND_FAILED`,n,V(e,typeof r==`function`?r(e):r))}function V(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function Ee(e,t,n,r,i){return e.didAbort?z(t,n,r):Se(t,n,r,i)}function De(e,t,n,r,i,a,o,s){return e.didAbort?z(t,n,r):i!==0&&!a?B(t,n,r,i,o,s):null}function Oe(e,n,r){let a=e?.trim();if(a){if(!i.isAbsolute(a)||a.includes(`\0`))throw new t(`INVALID_ARGS`,`${n} must be an absolute ${r} path, not ${JSON.stringify(e)}`,{envName:n,path:e});return a}}function ke(e){let t=e.trim();return!t||t.includes(`\0`)?null:i.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:_e.test(t)?t:null}function Ae(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return ve;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:ve}function je(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function H(e){try{return await Me(e)?(await f(e,process.platform===`win32`?s.F_OK:s.X_OK),!0):!1}catch{return!1}}async function Me(e){try{return(await p(e)).isFile()}catch{return!1}}function U(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function Ne(e,t){let n=!1,r=()=>{n=!0,W(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function W(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function Pe(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await u(d.from([t]),e.stdin)}}function Fe(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Ie=e({androidAdbResultError:()=>q,attachAdbFailureHint:()=>K,classifyAdbFailure:()=>ze,createAndroidPortReverseManager:()=>Xe,createDeviceAdbExecutor:()=>X,createLocalAndroidAdbProvider:()=>Ge,installAndroidAdbPackage:()=>$,pullAndroidAdbFile:()=>Ze,resolveAndroidAdbExecutor:()=>Ke,resolveAndroidAdbProvider:()=>Z,resolveAndroidTextInjector:()=>Je,resolveAndroidTouchProvider:()=>Ye,resolveScopedAndroidAdbBackgroundTransport:()=>qe,withAndroidAdbProvider:()=>$e});const Le=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Re=Object.freeze({reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`});function ze(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Le)if(e.test(n)||t&&e.test(r))return i}const G=new l;function K(e){if(!(e instanceof t)||e.code!==`COMMAND_FAILED`)return e;let n=Be(e);return n&&(e.details={...e.details,adbFailure:n.reason,...typeof e.details?.hint==`string`?{}:{hint:n.hint},...n.retriable!==void 0&&e.details?.retriable===void 0?{retriable:n.retriable}:{}}),e}function Be(e){return typeof e.details?.timeoutMs==`number`?Re:ze(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function q(e,n,r){return K(new t(`COMMAND_FAILED`,e,n.exitCode===0?{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,...r}:V(n,r)))}function J(e){return async(...t)=>{try{return await e(...t)}catch(e){throw K(e)}}}const Ve=new WeakSet;function He(e){if(Ve.has(e))return e;let t={...e,exec:J(Y(e.exec)),...e.pull?{pull:J(Y(e.pull))}:{},...e.install?{install:J(Y(e.install))}:{},...e.installBundle?{installBundle:J(e.installBundle)}:{}};return Ve.add(t),t}function Y(e){return async(...t)=>E(await e(...t))}function X(e){return Ue(e.id)}function Ue(e){return J(async(t,n)=>await C(async()=>await w(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function We(e){return(t,n)=>{let r=N(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function Ge(e){let t=X(e);return{exec:t,spawn:We(e.id),reverse:rt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=ot(n);return await t([`install`,...r,e],i)}}}function Ke(e,t){let n=G.getStore();return t||(n?.serial===e.id?n.provider.exec:X(e))}function Z(e,t){if(t)return Q(t);let n=G.getStore();return n?.serial===e.id?Q(n.provider):Ge(e)}function qe(e){let t=G.getStore();return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:t.provider.spawn}:{}}:{mode:`local`}}function Je(e){let t=G.getStore();return t?.serial===e.id?t.provider.text:void 0}function Ye(e){let t=G.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function Xe(e){let n=Q(e);if(n.reverse&&nt.has(n.reverse))return n.reverse;let r=n.reverse??rt(n.exec),i=new Map,a={async ensure(e,n){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new t(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,n),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return nt.add(a),a}function Q(e){return He(typeof e==`function`?{exec:e}:e)}async function Ze(e,n,r){let{device:i,provider:a,...o}=r??{},s=Qe(i,a),c=s?.pull;if(c)return await C(async()=>await c(e,n,o));let l=s?.exec;if(!l)throw new t(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await C(async()=>await l([`pull`,e,n],o))}async function $(e,n){let{device:r,provider:i,...a}=n??{},o=Qe(r,i),s=o?.install;if(s)return await C(async()=>await s(e,a));let c=o?.exec;if(!c)throw new t(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=ot(a);return await C(async()=>await c([`install`,...l,e],u))}function Qe(e,t){if(t)return Q(t);if(e)return Z(e);let n=G.getStore();if(n)return Q(n.provider)}async function $e(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=et(r);return await G.run(r,async()=>await ye(i,n))}function et(e){return(t,n,r)=>{if(t!==`adb`)return;let i=tt(n,e.serial);if(i)return C(async()=>await e.provider.exec(i,r))}}function tt(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const nt=new WeakSet;function rt(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!at(i.stdout,i.stderr))throw q(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?it(r.stdout,t):[]}}}function it(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
4
|
+
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function at(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function ot(e){let{replace:t,allowTestPackages:n,allowDowngrade:r,grantPermissions:i,...a}=e??{},o=[];return t&&o.push(`-r`),n&&o.push(`-t`),r&&o.push(`-d`),i&&o.push(`-g`),{installArgs:o,execOptions:a}}export{_ as A,O as C,pe as D,x as E,se as F,ne as I,ie as M,ae as N,oe as O,re as P,A as S,fe as T,w as _,Ze as a,M as b,Je as c,E as d,V as f,k as g,Te as h,$ as i,ce as j,ee as k,Ye as l,H as m,q as n,Ke as o,ge as p,Xe as r,Z as s,Ie as t,$e as u,N as v,C as w,T as x,j as y};
|