agent-device 0.12.6 → 0.12.8
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/dist/src/113.js +1 -1
- package/dist/src/1974.js +2 -0
- package/dist/src/3883.js +1 -0
- package/dist/src/3918.js +32 -0
- package/dist/src/4057.js +1 -0
- package/dist/src/7556.js +1 -0
- package/dist/src/7651.js +1 -0
- package/dist/src/7847.js +1 -0
- package/dist/src/8164.js +1 -0
- package/dist/src/8564.js +3 -0
- package/dist/src/9076.js +1 -0
- package/dist/src/9323.js +5 -0
- package/dist/src/9366.js +1 -0
- package/dist/src/9542.js +2 -0
- package/dist/src/9818.js +1 -0
- package/dist/src/989.js +1 -0
- package/dist/src/android-apps.js +1 -1
- package/dist/src/artifacts.js +1 -1
- package/dist/src/bin.d.ts +1 -0
- package/dist/src/bin.js +68 -70
- package/dist/src/commands/index.js +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon.d.ts +1 -0
- package/dist/src/daemon.js +15 -15
- package/dist/src/finders.js +1 -1
- package/dist/src/index.js +1 -3
- package/dist/src/install-source.js +1 -1
- package/dist/src/io.js +1 -1
- package/dist/src/metro-companion.d.ts +1 -0
- package/dist/src/metro.js +1 -1
- package/dist/src/remote-config.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/testing/conformance.js +1 -1
- package/dist/src/update-check-entry.d.ts +1 -0
- package/package.json +1 -1
- package/skills/agent-device/references/bootstrap-install.md +5 -3
- package/skills/agent-device/references/remote-tenancy.md +53 -13
- package/dist/src/164.js +0 -1
- package/dist/src/556.js +0 -1
- package/dist/src/57.js +0 -1
- package/dist/src/641.js +0 -38
- package/dist/src/818.js +0 -1
- package/dist/src/974.js +0 -2
- /package/dist/src/{267.js → 3267.js} +0 -0
- /package/dist/src/{152.js → 9152.js} +0 -0
- /package/dist/src/{1~rslib-runtime.js → rslib-runtime.js} +0 -0
package/dist/src/finders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findBestMatchesByLocator as e}from"./
|
|
1
|
+
import{findBestMatchesByLocator as e}from"./7556.js";function o(o,r,t,_){return e(o,r,t,"boolean"==typeof _?{requireRect:_}:_)}export{normalizeRole,normalizeText,parseFindArgs}from"./7556.js";export{o as findBestMatchesByLocator};
|
package/dist/src/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`;try{t.logPath&&r.appendFile(t.logPath,o,()=>{}),t.traceLogPath&&r.appendFile(t.traceLogPath,o,()=>{}),t.logPath||t.traceLogPath||process.stderr.write(o)}catch{}}async function R(e,t,a){let r=Date.now();try{let o=await t();return U({level:"info",phase:e,durationMs:Date.now()-r,data:a}),o}catch(t){throw U({level:"error",phase:e,durationMs:Date.now()-r,data:{...a??{},error:t instanceof Error?t.message:String(t)}}),t}}function O(e){let t,a=(t=(e??"").trim())?y(t):o.join(w("~"),".agent-device");return{baseDir:a,infoPath:o.join(a,"daemon.json"),lockPath:o.join(a,"daemon.lock"),logPath:o.join(a,"daemon.log"),sessionsDir:o.join(a,"sessions")}}let L="sha256";async function F(e){let t=await B(e.localPath,e.platform),a=e.baseUrl.endsWith("/")?e.baseUrl:`${e.baseUrl}/`;try{let r=await z({normalizedBase:a,token:e.token,artifact:t});if(r?.kind==="cache-hit")return r.uploadId;if(r?.kind==="direct-upload")try{return await H(t.payloadPath,r),await G({normalizedBase:a,token:e.token,uploadId:r.uploadId})}catch{}return await q({normalizedBase:a,token:e.token,artifact:t})}finally{t.cleanup()}}async function B(e,t){var a,n,i;let s,l=r.statSync(e),c=o.basename(e),d=l.isDirectory(),u=("ios"===(a=t)||"android"===a?a:void 0)??(n=e,i=l,s=n.toLowerCase(),i.isDirectory()&&s.endsWith(".app")||s.endsWith(".ipa")?"ios":s.endsWith(".apk")||s.endsWith(".aab")?"android":void 0),p=[];try{let t=d?await j(e,p):e,a=r.statSync(t);return{payloadPath:t,fileName:c,artifactType:d?"app-bundle":"file",platform:u,contentType:d?"application/gzip":"application/octet-stream",sha256:await V(t),sizeBytes:a.size,cleanup:()=>$(p)}}catch(e){throw $(p),e}}async function j(e,t){let a=r.mkdtempSync(o.join(d.tmpdir(),`agent-device-upload-${c()}-`));t.push(a);let n=o.join(a,`${o.basename(e)}.tar.gz`);return await v("tar",["czf",n,"-C",o.dirname(e),o.basename(e)]),n}function $(e){for(let t of e)r.rmSync(t,{recursive:!0,force:!0})}async function q(e){let{normalizedBase:t,token:a,artifact:r}=e,o=new URL("upload",t),n={"content-type":r.contentType,"x-artifact-type":r.artifactType,"x-artifact-filename":r.fileName,"x-artifact-hash":r.sha256,"x-artifact-hash-algorithm":L,"transfer-encoding":"chunked"};a&&(n.authorization=`Bearer ${a}`,n["x-agent-device-token"]=a);let i=await K({url:o,method:"POST",headers:n,payloadPath:r.payloadPath,timeoutMessage:"Artifact upload timed out",timeoutHint:"The upload to the remote daemon exceeded the 5-minute timeout.",errorMessage:"Failed to upload artifact to remote daemon",errorHint:"Verify the remote daemon is reachable and supports artifact uploads."});try{let e=JSON.parse(i.body);if(!e.ok||!e.uploadId)throw new p("COMMAND_FAILED",`Upload failed: ${i.body}`);return e.uploadId}catch(e){if(e instanceof p)throw e;throw new p("COMMAND_FAILED",`Invalid upload response: ${i.body}`)}}async function z(e){let t=new URL("upload/preflight",e.normalizedBase),a={"content-type":"application/json"};e.token&&(a.authorization=`Bearer ${e.token}`,a["x-agent-device-token"]=e.token);let r=await fetch(t,{method:"POST",headers:a,signal:AbortSignal.timeout(3e4),body:JSON.stringify({sha256:e.artifact.sha256,fileName:e.artifact.fileName,sizeBytes:e.artifact.sizeBytes,artifactType:e.artifact.artifactType,...e.artifact.platform?{platform:e.artifact.platform}:{},contentType:e.artifact.contentType})}).catch(()=>void 0);if(r?.ok)return function(e){var t;if(!e||"object"!=typeof e||!0!==e.ok||"string"!=typeof e.uploadId)return;if(!0===e.cacheHit)return{kind:"cache-hit",uploadId:e.uploadId};let a=e.upload;if(!a||"string"!=typeof a.url)return;let r=a.headers??{};if(!(!(t=r)||"object"!=typeof t||Array.isArray(t))&&Object.values(t).every(e=>"string"==typeof e))return{kind:"direct-upload",uploadId:e.uploadId,url:a.url,headers:r}}(await r.json().catch(()=>void 0))}async function H(e,t){let a=await K({url:new URL(t.url),method:"PUT",headers:t.headers,payloadPath:e,timeoutMessage:"Direct artifact upload timed out",timeoutHint:"The direct upload ticket did not accept the artifact within the timeout.",errorMessage:"Failed to upload artifact with direct upload ticket"});if(a.statusCode<200||a.statusCode>=300)throw new p("COMMAND_FAILED","Direct artifact upload failed",{statusCode:a.statusCode,statusMessage:a.statusMessage})}async function K(e){let o="https:"===e.url.protocol?a:t;return await new Promise((t,a)=>{let n=o.request({protocol:e.url.protocol,host:e.url.hostname,port:e.url.port,method:e.method,path:e.url.pathname+e.url.search,headers:e.headers},e=>{let a="";e.setEncoding("utf8"),e.on("data",e=>{a+=e}),e.on("end",()=>{clearTimeout(i),t({statusCode:e.statusCode??500,statusMessage:e.statusMessage,body:a})})}),i=setTimeout(()=>{n.destroy(),a(new p("COMMAND_FAILED",e.timeoutMessage,{timeoutMs:3e5,...e.timeoutHint?{hint:e.timeoutHint}:{}}))},3e5);n.on("error",t=>{clearTimeout(i),a(new p("COMMAND_FAILED",e.errorMessage,e.errorHint?{hint:e.errorHint}:{},t))}),n.on("close",()=>clearTimeout(i));let s=r.createReadStream(e.payloadPath);s.pipe(n),s.on("error",e=>{n.destroy(),a(new p("COMMAND_FAILED","Failed to read local artifact",{},e))})})}async function G(e){let t=new URL("upload/finalize",e.normalizedBase),a={"content-type":"application/json"};e.token&&(a.authorization=`Bearer ${e.token}`,a["x-agent-device-token"]=e.token);let r=await fetch(t,{method:"POST",headers:a,signal:AbortSignal.timeout(3e4),body:JSON.stringify({uploadId:e.uploadId})}).catch(e=>{throw new p("COMMAND_FAILED","Failed to finalize direct artifact upload",{},e)});if(!r.ok)throw new p("COMMAND_FAILED","Direct artifact upload finalize failed",{status:r.status,statusText:r.statusText});let o=await r.json().catch(()=>void 0);if(!o?.ok||!o.uploadId)throw new p("COMMAND_FAILED","Invalid upload finalize response");return o.uploadId}async function V(e){let t=l(L);return await new Promise((a,o)=>{r.createReadStream(e).on("data",e=>t.update(e)).on("error",e=>{o(new p("COMMAND_FAILED","Failed to read local artifact",{},e))}).on("end",a)}),t.digest("hex")}let J=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,W=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,Q=[".ts",".tsx",".js",".jsx",".mjs",".cjs"];function X(e,t,a){t.lastIndex=0;let r=null;for(;null!==(r=t.exec(e));){let e=r[1]?.trim();e?.startsWith(".")&&a.add(e)}}function Y(e){try{return r.statSync(e).isFile()?e:null}catch{return null}}let Z=eC(),ee=function(e=process.env.AGENT_DEVICE_DAEMON_STARTUP_TIMEOUT_MS){if(!e)return 15e3;let t=Number(e);return Number.isFinite(t)?Math.max(1e3,Math.floor(t)):15e3}(),et=function(e=process.env.AGENT_DEVICE_DAEMON_STARTUP_ATTEMPTS){if(!e)return 2;let t=Number(e);return Number.isFinite(t)?Math.min(5,Math.max(1,Math.floor(t))):2}(),ea=["xcodebuild .*AgentDeviceRunnerUITests/RunnerTests/testCommand","xcodebuild .*AgentDeviceRunner\\.env\\.session-","xcodebuild build-for-testing .*ios-runner/AgentDeviceRunner/AgentDeviceRunner\\.xcodeproj"],er=new e.BlockList;async function eo(t){let a=t.meta?.requestId??C(),r=!!(t.meta?.debug||t.flags?.verbose),o=function(t){let a,r,o,n=t.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR,i=function(e){let t;if(e){try{t=new URL(e)}catch(t){throw new p("INVALID_ARGS","Invalid daemon base URL",{daemonBaseUrl:e},t instanceof Error?t:void 0)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new p("INVALID_ARGS","Daemon base URL must use http or https",{daemonBaseUrl:e});return t.toString().replace(/\/+$/,"")}}(t.flags?.daemonBaseUrl??process.env.AGENT_DEVICE_DAEMON_BASE_URL),s=t.flags?.daemonAuthToken??process.env.AGENT_DEVICE_DAEMON_AUTH_TOKEN;var l=i,c=s;if(!(!l||"localhost"===(a=new URL(l).hostname.trim().toLowerCase().replace(/^\[(.*)\]$/,"$1"))||(e.isIPv4(a)?er.check(a,"ipv4"):!!e.isIPv6(a)&&er.check(a,"ipv6")))&&("string"!=typeof c||!(c.trim().length>0)))throw new p("INVALID_ARGS","Remote daemon base URL for non-loopback hosts requires daemon authentication",{daemonBaseUrl:l,hint:"Provide --daemon-auth-token or AGENT_DEVICE_DAEMON_AUTH_TOKEN when using a non-loopback remote daemon URL."});let d=t.flags?.daemonTransport??process.env.AGENT_DEVICE_DAEMON_TRANSPORT,u="auto"===(r=(d??"").trim().toLowerCase())?"auto":"socket"===r?"socket":"http"===r?"http":"auto";if(i&&"socket"===u)throw new p("INVALID_ARGS","Remote daemon base URL only supports HTTP transport. Remove --daemon-transport socket.",{daemonBaseUrl:i});let m="http"===(o=(t.flags?.daemonServerMode??process.env.AGENT_DEVICE_DAEMON_SERVER_MODE??("dual"===d?"dual":void 0)??"").trim().toLowerCase())?"http":"dual"===o?"dual":"socket";return{paths:O(n),transportPreference:u,serverMode:m,remoteBaseUrl:i,remoteAuthToken:s}}(t),n=function(e,t=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if("test"!==e)return eC(t)}(t.command),i=await R("daemon_startup",async()=>await ec(o),{requestId:a,session:t.session}),s=await en(t,i),l={...t,positionals:s.positionals,flags:s.flags,token:i.token,meta:{...t.meta??{},requestId:a,debug:r,cwd:t.meta?.cwd,tenantId:t.meta?.tenantId??t.flags?.tenant,runId:t.meta?.runId??t.flags?.runId,leaseId:t.meta?.leaseId??t.flags?.leaseId,sessionIsolation:t.meta?.sessionIsolation??t.flags?.sessionIsolation,lockPolicy:t.meta?.lockPolicy,lockPlatform:t.meta?.lockPlatform,...s.uploadedArtifactId?{uploadedArtifactId:s.uploadedArtifactId}:{},...s.clientArtifactPaths?{clientArtifactPaths:s.clientArtifactPaths}:{},...s.installSource?{installSource:s.installSource}:{}}};return U({level:"info",phase:"daemon_request_prepare",data:{requestId:a,command:t.command,session:t.session}}),await R("daemon_request",async()=>await eA(i,l,o.transportPreference,n),{requestId:a,command:t.command})}async function en(e,t){let a,n=[...e.positionals??[]],i=e.flags?{...e.flags}:void 0,s=e.meta?.installSource,l={};if(eE(t)){let r=function(e,t){if("screenshot"===e.command){let a=es(e,"path",".png");return t[0]?{field:"path",localPath:a,positionalIndex:0,positionalPath:el("screenshot",".png")}:{field:"path",localPath:a,positionalIndex:0,flagPath:el("screenshot",".png")}}if("record"===e.command&&"start"===(t[0]??"").toLowerCase()){let t=es(e,"outPath",".mp4",1);return{field:"outPath",localPath:t,positionalIndex:1,positionalPath:el("recording",o.extname(t)||".mp4")}}return null}(e,n);r&&(void 0!==r.positionalPath&&(n[r.positionalIndex]=r.positionalPath),void 0!==r.flagPath&&((i??={}).out=r.flagPath),l[r.field]=r.localPath);let c=await ei(e,t);c&&(s=c.installSource,a=c.uploadedArtifactId??a)}if(!eE(t)||"install"!==e.command&&"reinstall"!==e.command||n.length<2)return{positionals:n,flags:i,installSource:s,uploadedArtifactId:a,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let c=n[1];if(c.startsWith("remote:"))return n[1]=c.slice(7),{positionals:n,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let d=o.isAbsolute(c)?c:o.resolve(e.meta?.cwd??process.cwd(),c);return r.existsSync(d)?{positionals:n,flags:i,installSource:s,uploadedArtifactId:a=await F({localPath:d,baseUrl:t.baseUrl,token:t.token,platform:e.flags?.platform}),...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}:{positionals:n,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}}async function ei(e,t){let a=e.meta?.installSource;if("install_source"!==e.command||!a||"path"!==a.kind)return null;let n=a.path.trim();if(!n)return{installSource:a};if(n.startsWith("remote:"))return{installSource:{...a,path:n.slice(7)}};let i=o.isAbsolute(n)?n:o.resolve(e.meta?.cwd??process.cwd(),n);if(!r.existsSync(i))return{installSource:{...a,path:i}};let s=await F({localPath:i,baseUrl:t.baseUrl,token:t.token,platform:e.flags?.platform});return{installSource:{...a,path:i},uploadedArtifactId:s}}function es(e,t,a,r=0){let n=e.positionals?.[r]??e.flags?.out,i=`${"path"===t?"screenshot":"recording"}-${Date.now()}${a}`,s=n&&n.trim().length>0?n:i;return o.isAbsolute(s)?s:o.resolve(e.meta?.cwd??process.cwd(),s)}function el(e,t){let a=t.startsWith(".")?t:`.${t}`;return o.posix.join("/tmp",`agent-device-${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}${a}`)}async function ec(e){let t;if(e.remoteBaseUrl){let t={transport:"http",token:e.remoteAuthToken??"",pid:0,baseUrl:e.remoteBaseUrl};if(await ev(t,"http"))return t;throw new p("COMMAND_FAILED","Remote daemon is unavailable",{daemonBaseUrl:e.remoteBaseUrl,hint:"Verify AGENT_DEVICE_DAEMON_BASE_URL points to a reachable daemon with GET /health and POST /rpc."})}let a=ef(e.paths.infoPath),n=function(){try{let e=N();return JSON.parse(r.readFileSync(o.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}(),i=function(e,t=N()){try{let a=o.resolve(t),n=[o.resolve(e)],i=new Set,l=[];for(;n.length>0;){let e=n.pop();if(!e||i.has(e))continue;i.add(e);let t=r.statSync(e);if(!t.isFile())continue;let s=o.relative(a,e)||e;l.push(`${s}:${t.size}:${Math.trunc(t.mtimeMs)}`);let c=r.readFileSync(e,"utf8");for(let t of function(e){let t=new Set;return X(e,J,t),X(e,W,t),[...t]}(c)){let a=function(e,t){let a=o.resolve(o.dirname(e),t),r=Y(a);if(r)return r;for(let e of Q){let t=Y(`${a}${e}`);if(t)return t}for(let e of Q){let t=Y(o.join(a,`index${e}`));if(t)return t}return null}(e,t);a&&n.push(a)}}let c=l.sort().join("|"),d=s.createHash("sha1").update(c).digest("hex");return`graph:${l.length}:${d}`}catch{return"unknown"}}((t=eb()).useSrc?t.srcPath:t.distPath,t.root),l=!!a&&await ev(a,e.transportPreference);if(a&&a.version===n&&a.codeSignature===i&&l)return a;a&&(a.version!==n||a.codeSignature!==i||!l)&&(await em(a),eg(e.paths.infoPath)),function(e){let t=ey(e);if(!t.hasLock||t.hasInfo)return;let a=eh(e.lockPath);if(!a)return eg(e.lockPath);A(a.pid,a.processStartTime)||eg(e.lockPath)}(e.paths);let c=0;for(let t=1;t<=et;t+=1){await eI(e);let a=await ed(ee,e);if(a)return a;if(await ep(e.paths)){c+=1;continue}let r=ey(e.paths);if(!(t<et))break;if(!r.hasInfo&&!r.hasLock){await eu(150);continue}}let d=ey(e.paths);throw new p("COMMAND_FAILED","Failed to start daemon",{kind:"daemon_startup_failed",infoPath:e.paths.infoPath,lockPath:e.paths.lockPath,startupTimeoutMs:ee,startupAttempts:et,lockRecoveryCount:c,metadataState:d,hint:function(e,t=O(process.env.AGENT_DEVICE_STATE_DIR)){return e.hasLock&&!e.hasInfo?`Detected ${t.lockPath} without ${t.infoPath}. If no agent-device daemon process is running, delete ${t.lockPath} and retry.`:e.hasLock&&e.hasInfo?`Daemon metadata may be stale. If no agent-device daemon process is running, delete ${t.infoPath} and ${t.lockPath}, then retry.`:`Daemon metadata is missing or stale. Delete ${t.infoPath} if present and retry.`}(d,e.paths)})}async function ed(e,t){let a=Date.now();for(;Date.now()-a<e;){let e=ef(t.paths.infoPath);if(e&&await ev(e,t.transportPreference))return e;await new Promise(e=>setTimeout(e,100))}return null}async function eu(e){await new Promise(t=>setTimeout(t,e))}async function ep(e){let t=ey(e);if(!t.hasLock||t.hasInfo)return!1;let a=eh(e.lockPath);return a&&A(a.pid,a.processStartTime)&&await _(a.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:a.processStartTime}),eg(e.lockPath),!0}async function em(e){await _(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}function ef(e){let t=ew(e);if(!t||"object"!=typeof t)return null;let a="string"==typeof t.token&&t.token.length>0?t.token:null;if(!a)return null;let r=Number.isInteger(t.port)&&Number(t.port)>0,o=Number.isInteger(t.httpPort)&&Number(t.httpPort)>0;if(!r&&!o)return null;let n=t.transport,i="string"==typeof t.version?t.version:void 0,s="string"==typeof t.codeSignature?t.codeSignature:void 0,l="string"==typeof t.processStartTime?t.processStartTime:void 0,c=Number.isInteger(t.pid)&&Number(t.pid)>0;return{token:a,port:r?Number(t.port):void 0,httpPort:o?Number(t.httpPort):void 0,transport:"socket"===n||"http"===n||"dual"===n?n:void 0,pid:c?Number(t.pid):0,version:i,codeSignature:s,processStartTime:l}}function eh(e){let t=ew(e);return t&&"object"==typeof t&&Number.isInteger(t.pid)&&Number(t.pid)>0?{pid:Number(t.pid),processStartTime:"string"==typeof t.processStartTime?t.processStartTime:void 0,startedAt:"number"==typeof t.startedAt?t.startedAt:void 0}:null}er.addSubnet("127.0.0.0",8,"ipv4"),er.addAddress("::1","ipv6"),er.addSubnet("::ffff:127.0.0.0",104,"ipv6");function ey(e){return{hasInfo:r.existsSync(e.infoPath),hasLock:r.existsSync(e.lockPath)}}function ew(e){if(!r.existsSync(e))return null;try{return JSON.parse(r.readFileSync(e,"utf8"))}catch{return null}}function eg(e){try{r.existsSync(e)&&r.unlinkSync(e)}catch{}}async function ev(r,o){var n;return"http"===e_(r,o)?await function(e){let r=e.baseUrl?eT(e.baseUrl,"health"):e.httpPort?`http://127.0.0.1:${e.httpPort}/health`:null;if(!r)return Promise.resolve(!1);let o=new URL(r),n="https:"===o.protocol?a:t,i=e.baseUrl?3e3:500;return new Promise(e=>{let t=n.request({protocol:o.protocol,host:o.hostname,port:o.port,path:o.pathname+o.search,method:"GET",timeout:i},t=>{t.resume(),e((t.statusCode??500)<500)});t.on("timeout",()=>{t.destroy(),e(!1)}),t.on("error",()=>{e(!1)}),t.end()})}(r):await ((n=r.port)?new Promise(t=>{let a=e.createConnection({host:"127.0.0.1",port:n},()=>{a.destroy(),t(!0)});a.on("error",()=>{t(!1)})}):Promise.resolve(!1))}async function eI(e){let t=eb(),a=t.useSrc?["--experimental-strip-types",t.srcPath]:[t.distPath],r={...process.env,AGENT_DEVICE_STATE_DIR:e.paths.baseDir,AGENT_DEVICE_DAEMON_SERVER_MODE:e.serverMode};I(process.execPath,a,{env:r})}function eb(){let e=N(),t=o.join(e,"dist","src","daemon.js"),a=o.join(e,"src","daemon.ts"),n=r.existsSync(t),i=r.existsSync(a);if(!n&&!i)throw new p("COMMAND_FAILED","Daemon entry not found",{distPath:t,srcPath:a});return{root:e,distPath:t,srcPath:a,useSrc:process.execArgv.includes("--experimental-strip-types")?i:!n&&i}}async function eA(e,t,a,r){return"http"===e_(e,a)?await eD(e,t,r):await eP(e,t,r)}function e_(e,t){if(e.baseUrl){if("socket"===t)throw new p("COMMAND_FAILED","Remote daemon endpoint only supports HTTP transport",{daemonBaseUrl:e.baseUrl});return"http"}if("http"===t||"socket"===t){var a=e,r=t;if(eS(a,r))return r;throw new p("COMMAND_FAILED","http"===r?"Daemon HTTP endpoint is unavailable":"Daemon socket endpoint is unavailable")}let o=("socket"===e.transport||"dual"===e.transport?["socket","http"]:["http","socket"]).find(t=>eS(e,t));if(o)return o;throw new p("COMMAND_FAILED","Daemon metadata has no reachable transport")}function eS(e,t){return"http"===t?!!e.httpPort:!!e.port}function ek(e,t,a,r,o,n){let i=o?{terminated:0}:function(){let e=0;try{for(let t of ea){let a=g("pkill",["-f",t],{allowFailure:!0});0===a.exitCode&&(e+=1)}return{terminated:e}}catch(t){return{terminated:e,error:t instanceof Error?t.message:String(t)}}}(),s=o?{forcedKill:!1}:function(e,t){let a=!1;try{A(e.pid,e.processStartTime)&&(process.kill(e.pid,"SIGKILL"),a=!0)}catch{_(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}finally{eg(t.infoPath),eg(t.lockPath)}return{forcedKill:a}}(e,t);return U({level:"error",phase:"daemon_request_timeout",data:{timeoutMs:n,requestId:a,command:r,timedOutRunnerPidsTerminated:i.terminated,timedOutRunnerCleanupError:i.error,daemonPidReset:o?void 0:e.pid,daemonPidForceKilled:o?void 0:s.forcedKill,daemonBaseUrl:e.baseUrl}}),new p("COMMAND_FAILED","Daemon request timed out",{timeoutMs:n,requestId:a,hint:o?"Retry with --debug and verify the remote daemon URL, auth token, and remote host logs.":"Retry with --debug and check daemon diagnostics logs. Timed-out iOS runner xcodebuild processes were terminated when detected."})}function eM(e,t,a){return U({level:"error",phase:"daemon_request_socket_error",data:{requestId:t,message:e instanceof Error?e.message:String(e)}}),new p("COMMAND_FAILED","Failed to communicate with daemon",{requestId:t,hint:a?"Retry command. If this persists, verify the remote daemon URL, auth token, and remote host reachability.":"Retry command. If this persists, clean stale daemon metadata and start a fresh session."},e instanceof Error?e:void 0)}async function eP(t,a,r){let o=t.port;if(!o)throw new p("COMMAND_FAILED","Daemon socket endpoint is unavailable");return new Promise((n,i)=>{let s=e.createConnection({host:"127.0.0.1",port:o},()=>{s.write(`${JSON.stringify(a)}
|
|
3
|
-
`)}),l=O(a.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),c="number"==typeof r?setTimeout(()=>{s.destroy(),i(ek(t,l,a.meta?.requestId,a.command,!1,r))},r):void 0,d="";s.setEncoding("utf8"),s.on("data",e=>{let t=(d+=e).indexOf("\n");if(-1===t)return;let r=d.slice(0,t).trim();if(r)try{let e=JSON.parse(r);s.end(),c&&clearTimeout(c),n(e)}catch(e){c&&clearTimeout(c),i(new p("COMMAND_FAILED","Invalid daemon response",{requestId:a.meta?.requestId,line:r},e instanceof Error?e:void 0))}}),s.on("error",e=>{c&&clearTimeout(c),i(eM(e,a.meta?.requestId,!1))})})}async function eD(e,r,o){var n,i,s;let l,c=e.baseUrl?new URL(eT(e.baseUrl,"rpc")):e.httpPort?new URL(`http://127.0.0.1:${e.httpPort}/rpc`):null;if(!c)throw new p("COMMAND_FAILED","Daemon HTTP endpoint is unavailable");let d=JSON.stringify((n=r,i={includeTokenParam:!e.baseUrl},l=n.meta?.requestId??C(),"lease_allocate"!==(s=n.command)&&"lease_heartbeat"!==s&&"lease_release"!==s?{jsonrpc:"2.0",id:l,method:"agent_device.command",params:n}:{jsonrpc:"2.0",id:l,method:function(e){switch(e){case"lease_allocate":return"agent_device.lease.allocate";case"lease_heartbeat":return"agent_device.lease.heartbeat";case"lease_release":return"agent_device.lease.release"}}(n.command),params:function(e,t,a){let r={...a.includeTokenParam?{token:e.token}:{},session:e.session,tenantId:e.meta?.tenantId,runId:e.meta?.runId};switch(t){case"lease_allocate":return{...r,ttlMs:e.meta?.leaseTtlMs,backend:e.meta?.leaseBackend};case"lease_heartbeat":return{...r,leaseId:e.meta?.leaseId,ttlMs:e.meta?.leaseTtlMs};case"lease_release":return{...r,leaseId:e.meta?.leaseId}}}(n,n.command,i)})),u={"content-type":"application/json","content-length":Buffer.byteLength(d)};return e.baseUrl&&e.token&&(u.authorization=`Bearer ${e.token}`,u["x-agent-device-token"]=e.token),await new Promise((n,i)=>{let s=O(r.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),l=("https:"===c.protocol?a:t).request({protocol:c.protocol,host:c.hostname,port:c.port,method:"POST",path:c.pathname+c.search,headers:u},t=>{let a="";t.setEncoding("utf8"),t.on("data",e=>{a+=e}),t.on("end",()=>{f&&clearTimeout(f);try{let t=JSON.parse(a);if(t.error){let e=t.error.data??{};i(new p(String(e.code??"COMMAND_FAILED"),String(e.message??t.error.message??"Daemon RPC request failed"),{..."object"==typeof e.details&&e.details?e.details:{},hint:"string"==typeof e.hint?e.hint:void 0,diagnosticId:"string"==typeof e.diagnosticId?e.diagnosticId:void 0,logPath:"string"==typeof e.logPath?e.logPath:void 0,requestId:r.meta?.requestId}));return}if(!t.result||"object"!=typeof t.result)return void i(new p("COMMAND_FAILED","Invalid daemon RPC response",{requestId:r.meta?.requestId}));if(e.baseUrl&&t.result.ok)return void eN(e,r,t.result).then(n).catch(i);n(t.result)}catch(e){f&&clearTimeout(f),i(new p("COMMAND_FAILED","Invalid daemon response",{requestId:r.meta?.requestId,line:a},e instanceof Error?e:void 0))}})}),m=eE(e),f="number"==typeof o?setTimeout(()=>{l.destroy(),i(ek(e,s,r.meta?.requestId,r.command,m,o))},o):void 0;l.on("error",e=>{f&&clearTimeout(f),i(eM(e,r.meta?.requestId,m))}),l.write(d),l.end()})}function eE(e){return"string"==typeof e.baseUrl&&e.baseUrl.length>0}function eT(e,t){return new URL(t,e.endsWith("/")?e:`${e}/`).toString()}async function eN(e,t,a){let r=Array.isArray(a.data?.artifacts)?a.data.artifacts:[];if(0===r.length||!e.baseUrl)return a;let n=a.data?{...a.data}:{},i=[];for(let a of r){if(!a||"object"!=typeof a||"string"!=typeof a.artifactId){i.push(a);continue}let r=function(e,t){if(e.localPath&&e.localPath.trim().length>0)return e.localPath;let a=e.fileName?.trim()||`${e.field}-${Date.now()}`;return o.resolve(t.meta?.cwd??process.cwd(),a)}(a,t);await ex({baseUrl:e.baseUrl,token:e.token,artifactId:a.artifactId,destinationPath:r,requestId:t.meta?.requestId}),n[a.field]=r,i.push({...a,localPath:r})}return n.artifacts=i,{ok:!0,data:n}}async function ex(e){var n,i;let s,l=new URL((n=e.baseUrl,i=e.artifactId,s=n.endsWith("/")?n:`${n}/`,new URL(`upload/${encodeURIComponent(i)}`,s).toString())),c="https:"===l.protocol?a:t;await r.promises.mkdir(o.dirname(e.destinationPath),{recursive:!0}),await new Promise((t,a)=>{let o=!1,n=e.timeoutMs??Z,i=n=>{if(!o){if(o=!0,clearTimeout(d),n)return void r.promises.rm(e.destinationPath,{force:!0}).finally(()=>a(n));t()}},s=c.request({protocol:l.protocol,host:l.hostname,port:l.port,method:"GET",path:l.pathname+l.search,headers:e.token?{authorization:`Bearer ${e.token}`,"x-agent-device-token":e.token}:void 0},t=>{if((t.statusCode??500)>=400){let a="";t.setEncoding("utf8"),t.on("data",e=>{a+=e}),t.on("end",()=>{i(new p("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,statusCode:t.statusCode,requestId:e.requestId,body:a}))});return}let a=r.createWriteStream(e.destinationPath);a.on("error",e=>{i(e instanceof Error?e:Error(String(e)))}),t.on("error",e=>{i(e instanceof Error?e:Error(String(e)))}),t.on("aborted",()=>{i(new p("COMMAND_FAILED","Remote artifact download was interrupted",{artifactId:e.artifactId,requestId:e.requestId}))}),a.on("finish",()=>{a.close(()=>i())}),t.pipe(a)}),d=setTimeout(()=>{s.destroy(new p("COMMAND_FAILED","Remote artifact download timed out",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:n}))},n);s.on("error",t=>{t instanceof p?i(t):i(new p("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:n},t instanceof Error?t:void 0))}),s.end()})}function eC(e=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if(!e)return 9e4;let t=Number(e);return Number.isFinite(t)?Math.max(1e3,Math.floor(t)):9e4}let eU="clipboard",eR="wait";function eO(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function eL(e,t,a){return{deviceId:t,deviceName:a,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function eF(e,t,a,r){let o=a(e[t]);if(void 0===o)throw new p("COMMAND_FAILED",r,{response:e});return o}function eB(e,t){return eF(e,t,eK,`Daemon response is missing "${t}".`)}function ej(e,t){return eK(e[t])}function e$(e,t){var a;let r;return a=eK,null===(r=e[t])?null:a(r)}function eq(e,t){return eF(e,t,eV,`Daemon response has invalid "${t}".`)}function ez(e,t){return function(e){return"tv"===e||"mobile"===e||"desktop"===e?e:void 0}(e[t])??"mobile"}function eH(e,t){let a=e[t];if(!eQ(a))return;let r="number"==typeof a.x?a.x:void 0,o="number"==typeof a.y?a.y:void 0,n="number"==typeof a.width?a.width:void 0,i="number"==typeof a.height?a.height:void 0;if(void 0!==r&&void 0!==o&&void 0!==n&&void 0!==i)return{x:r,y:o,width:n,height:i}}function eK(e){return"string"==typeof e&&e.length>0?e:void 0}function eG(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function eV(e){return"ios"===e||"macos"===e||"android"===e?e:void 0}function eJ(e){return"simulator"===e||"emulator"===e||"device"===e?e:void 0}function eW(e){if(!eQ(e))throw new p("COMMAND_FAILED","Daemon returned an unexpected response shape.",{value:e});return e}function eQ(e){return"object"==typeof e&&null!==e}function eX(e){let t={};for(let[a,r]of Object.entries(e))void 0!==r&&(t[a]=r);return t}function eY(e,t){let a=ej(e,"bundleId"),r=ej(e,"package");return{app:eB(e,"app"),appPath:eB(e,"appPath"),platform:eq(e,"platform"),appId:a??r,bundleId:a,package:r,identifiers:eO({session:t,bundleId:a,packageName:r})}}function eZ(e){let t=eW(e),a=eq(t,"platform"),r=eB(t,"id"),o=eB(t,"name");return{platform:a,target:ez(t,"target"),kind:eF(t,"kind",eJ,'Daemon response has invalid "kind".'),id:r,name:o,booted:"boolean"==typeof t.booted?t.booted:void 0,identifiers:eL(a,r,o),ios:"ios"===a?{udid:r}:void 0,android:"android"===a?{serial:r}:void 0}}function e0(e){let t=eW(e),a=eq(t,"platform"),r=eB(t,"id"),o=eB(t,"name"),n=ez(t,"target"),i=eB(t,"device"),s={session:o,...eL(a,r,i)};return{name:o,createdAt:eF(t,"createdAt",eG,'Daemon response is missing numeric "createdAt".'),device:{platform:a,target:n,id:r,name:i,identifiers:s,ios:"ios"===a?{udid:r,simulatorSetPath:e$(t,"ios_simulator_device_set")}:void 0,android:"android"===a?{serial:r}:void 0},identifiers:s}}function e1(e){return e??"default"}function e2(e={},t={}){var a;let r,o=t.transport??eo,n=async(t,a=[],r={})=>{var n,i;let s=(n=e,i=r,{...n,...i}),l=await o({session:e1(s.session),command:t,positionals:a,flags:eX({stateDir:s.stateDir,daemonBaseUrl:s.daemonBaseUrl,daemonAuthToken:s.daemonAuthToken,daemonTransport:s.daemonTransport,daemonServerMode:s.daemonServerMode,tenant:s.tenant,sessionIsolation:s.sessionIsolation,runId:s.runId,leaseId:s.leaseId,leaseBackend:s.leaseBackend,platform:s.platform,target:s.target,device:s.device,udid:s.udid,serial:s.serial,iosSimulatorDeviceSet:s.iosSimulatorDeviceSet,androidDeviceAllowlist:s.androidDeviceAllowlist,runtime:s.simulatorRuntimeId,boot:s.boot,reuseExisting:s.reuseExisting,surface:s.surface,activity:s.activity,relaunch:s.relaunch,shutdown:s.shutdown,saveScript:s.saveScript,noRecord:s.noRecord,backMode:s.backMode,metroHost:s.metroHost,metroPort:s.metroPort,bundleUrl:s.bundleUrl,launchUrl:s.launchUrl,snapshotInteractiveOnly:s.interactiveOnly,snapshotCompact:s.compact,snapshotDepth:s.depth,snapshotScope:s.scope,snapshotRaw:s.raw,screenshotFullscreen:s.screenshotFullscreen,overlayRefs:s.overlayRefs,appsFilter:s.appsFilter,out:s.out,count:s.count,fps:s.fps,quality:s.quality,hideTouches:s.hideTouches,intervalMs:s.intervalMs,delayMs:s.delayMs,holdMs:s.holdMs,jitterPx:s.jitterPx,pixels:s.pixels,doubleTap:s.doubleTap,clickButton:s.clickButton,pauseMs:s.pauseMs,pattern:s.pattern,headless:s.headless,restart:s.restart,replayUpdate:s.replayUpdate,failFast:s.failFast,timeoutMs:s.timeoutMs,retries:s.retries,artifactsDir:s.artifactsDir,reportJunit:s.reportJunit,findFirst:s.findFirst,findLast:s.findLast,networkInclude:s.networkInclude,batchOnError:s.batchOnError,batchMaxSteps:s.batchMaxSteps,batchSteps:s.batchSteps,verbose:s.debug}),runtime:s.runtime,meta:eX({requestId:s.requestId,cwd:s.cwd,debug:s.debug,lockPolicy:s.lockPolicy,lockPlatform:s.lockPlatform,tenantId:s.tenant,runId:s.runId,leaseId:s.leaseId,leaseBackend:s.leaseBackend,leaseTtlMs:s.leaseTtlMs,sessionIsolation:s.sessionIsolation,installSource:s.installSource,retainMaterializedPaths:s.retainMaterializedPaths,materializedPathRetentionMs:s.materializedPathRetentionMs,materializationId:s.materializationId})});return l.ok||function(e){throw new p(e.code,e.message,{...e.details??{},hint:e.hint,diagnosticId:e.diagnosticId,logPath:e.logPath})}(l.error),l.data??{}},i=async(e={})=>{let t=await n("session_list",[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(e0)},s=async(e,t=[],a={})=>await n(e,t,a),l=(t={})=>{var a,r;return e1((a=e,r=t,{...a,...r}).session)};return{command:(a=async e=>await n(e.command,e.positionals,e.options),r=async e=>await a(e),{wait:async e=>await r(function(e){if(1!==[void 0!==e.durationMs?"durationMs":void 0,void 0!==e.text?"text":void 0,void 0!==e.ref?"ref":void 0,void 0!==e.selector?"selector":void 0].filter(Boolean).length)throw new p("INVALID_ARGS","wait command requires exactly one of durationMs, text, ref, or selector.");if(void 0!==e.durationMs)return{command:eR,positionals:[String(e.durationMs)],options:e};let t=void 0!==e.timeoutMs?[String(e.timeoutMs)]:[];if(void 0!==e.text)return{command:eR,positionals:["text",e.text,...t],options:e};if(void 0!==e.ref)return{command:eR,positionals:[e.ref,...t],options:e};let a=e.selector;return function(e){if(!S(e))throw new p("INVALID_ARGS",`Invalid wait selector: ${e}`)}(a),{command:eR,positionals:[a,...t],options:e}}(e)),alert:async(e={})=>{var t;return await r({command:"alert",positionals:[(t=e).action??"get",...void 0!==t.timeoutMs?[String(t.timeoutMs)]:[]],options:t})},appState:async(e={})=>await r({command:"appstate",positionals:[],options:e}),back:async(e={})=>await r({command:"back",positionals:[],options:{...e,backMode:e.mode}}),home:async(e={})=>await r({command:"home",positionals:[],options:e}),rotate:async e=>await r({command:"rotate",positionals:[e.orientation],options:e}),appSwitcher:async(e={})=>await r({command:"app-switcher",positionals:[],options:e}),keyboard:async(e={})=>await r({command:"keyboard",positionals:e.action?[e.action]:[],options:e}),clipboard:async e=>{var t;return await r("read"===(t=e).action?{command:eU,positionals:["read"],options:t}:{command:eU,positionals:["write",t.text],options:t})}}),devices:{list:async(e={})=>{let t=await n("devices",[],e);return(Array.isArray(t.devices)?t.devices:[]).map(eZ)},boot:async(e={})=>await s("boot",[],e)},sessions:{list:async(e={})=>await i(e),close:async(e={})=>{let t=l(e),a=(await n("close",[],e)).shutdown;return{session:t,shutdown:"object"==typeof a&&null!==a?a:void 0,identifiers:{session:t}}}},simulators:{ensure:async e=>{let{runtime:t,...a}=e,r=await n("ensure-simulator",[],{...a,simulatorRuntimeId:t}),o=eB(r,"udid"),i=eB(r,"device");return{udid:o,device:i,runtime:eB(r,"runtime"),created:!0===r.created,booted:!0===r.booted,iosSimulatorDeviceSet:e$(r,"ios_simulator_device_set"),identifiers:{deviceId:o,deviceName:i,udid:o}}}},apps:{install:async e=>eY(await n("install",[e.app,e.appPath],e),l(e)),reinstall:async e=>eY(await n("reinstall",[e.app,e.appPath],e),l(e)),installFromSource:async e=>(function(e,t){let a=ej(e,"bundleId"),r=ej(e,"packageName"),o=a??r??ej(e,"appId"),n=ej(e,"launchTarget")??r??a??o;if(!n)throw new p("COMMAND_FAILED",'Daemon response is missing "launchTarget".',{response:e});return{appName:ej(e,"appName"),appId:o,bundleId:a,packageName:r,launchTarget:n,installablePath:ej(e,"installablePath"),archivePath:ej(e,"archivePath"),materializationId:ej(e,"materializationId"),materializationExpiresAt:ej(e,"materializationExpiresAt"),identifiers:eO({session:t,bundleId:a,packageName:r,appId:o})}})(await n("install_source",[],{...e,installSource:e.source,retainMaterializedPaths:e.retainPaths,materializedPathRetentionMs:e.retentionMs}),l(e)),list:async(e={})=>{let t=await n("apps",[],e);return Array.isArray(t.apps)?t.apps.filter(e=>"string"==typeof e):[]},open:async e=>{let t=l(e),a=e.app?e.url?[e.app,e.url]:[e.app]:[],r=await n("open",a,e),o=function(e){let t=e.platform,a=ej(e,"id"),r=ej(e,"device");if("ios"!==t&&"macos"!==t&&"android"!==t||!a||!r)return;let o=ez(e,"target"),n=eL(t,a,r);return{platform:t,target:o,id:a,name:r,identifiers:n,ios:"ios"===t?{udid:ej(e,"device_udid")??a,simulatorSetPath:e$(e,"ios_simulator_device_set")}:void 0,android:"android"===t?{serial:ej(e,"serial")??a}:void 0}}(r),i=ej(r,"appBundleId");return{session:t,appName:ej(r,"appName"),appBundleId:i,appId:i,startup:function(e){if(eQ(e)&&"number"==typeof e.durationMs&&"string"==typeof e.measuredAt&&"string"==typeof e.method)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:ej(e,"appTarget"),appBundleId:ej(e,"appBundleId")}}(r.startup),runtime:function(e){if(!eQ(e))return;let t=e.platform,a=ej(e,"metroHost"),r="number"==typeof e.metroPort?e.metroPort:void 0;return{platform:"ios"===t||"android"===t?t:void 0,metroHost:a,metroPort:r,bundleUrl:ej(e,"bundleUrl"),launchUrl:ej(e,"launchUrl")}}(r.runtime),device:o,identifiers:{session:t,deviceId:o?.id,deviceName:o?.name,udid:o?.ios?.udid,serial:o?.android?.serial,appId:i,appBundleId:i}}},close:async(e={})=>{let t=l(e),a=(await n("close",e.app?[e.app]:[],e)).shutdown;return{session:t,closedApp:e.app,shutdown:"object"==typeof a&&null!==a?a:void 0,identifiers:{session:t}}},push:async e=>{var t;return await s("push",[e.app,"string"==typeof(t=e.payload)?t:JSON.stringify(t)],e)},triggerEvent:async e=>{var t;return await s("trigger-app-event",[(t=e).event,...t.payload?[JSON.stringify(t.payload)]:[]],e)}},materializations:{release:async e=>{var t;return{released:!0===(t=await n("release_materialized_paths",[],{...e,materializationId:e.materializationId})).released,materializationId:eB(t,"materializationId"),identifiers:{}}}},leases:{allocate:async e=>e6(await n("lease_allocate",[],{...e,leaseId:void 0,leaseTtlMs:e.ttlMs})),heartbeat:async e=>e6(await n("lease_heartbeat",[],{...e,leaseTtlMs:e.ttlMs})),release:async e=>({released:!0===(await n("lease_release",[],e)).released})},metro:{prepare:async t=>await b({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,bridgeScope:t.bridgeScope,launchUrl:t.launchUrl,companionProfileKey:t.companionProfileKey,companionConsumerKey:t.companionConsumerKey,metroPort:t.port,listenHost:t.listenHost,statusHost:t.statusHost,startupTimeoutMs:t.startupTimeoutMs,probeTimeoutMs:t.probeTimeoutMs,reuseExisting:t.reuseExisting,installDependenciesIfNeeded:t.installDependenciesIfNeeded,runtimeFilePath:t.runtimeFilePath,logPath:t.logPath})},capture:{snapshot:async(e={})=>{var t;let a=l(e),r=await n("snapshot",[],e),o=ej(r,"appBundleId"),i="object"==typeof r.visibility&&null!==r.visibility?r.visibility:void 0;return{nodes:Array.isArray(t=r.nodes)?t:[],truncated:!0===r.truncated,appName:ej(r,"appName"),appBundleId:o,...i?{visibility:i}:{},warnings:Array.isArray(r.warnings)?r.warnings.filter(e=>"string"==typeof e):void 0,identifiers:{session:a,appId:o,appBundleId:o}}},screenshot:async(e={})=>{let t=l(e),a=await n("screenshot",e.path?[e.path]:[],{...e,screenshotFullscreen:e.fullscreen});return{path:eB(a,"path"),overlayRefs:function(e){let t=e.overlayRefs;if(!Array.isArray(t))return;let a=[];for(let e of t){if(!eQ(e))continue;let t=ej(e,"ref"),r=eH(e,"rect"),o=eH(e,"overlayRect"),n=function(e,t){let a=e[t];if(!eQ(a))return;let r="number"==typeof a.x?a.x:void 0,o="number"==typeof a.y?a.y:void 0;if(void 0!==r&&void 0!==o)return{x:r,y:o}}(e,"center");t&&r&&o&&n&&a.push({ref:t,label:ej(e,"label"),rect:r,overlayRect:o,center:n})}return a}(a),identifiers:{session:t}}},diff:async e=>await s("diff",[e.kind],{...e,interactiveOnly:e.interactiveOnly,compact:e.compact,depth:e.depth,scope:e.scope,raw:e.raw})},interactions:{click:async e=>await s("click",e3(e),{...e,clickButton:e.button}),press:async e=>await s("press",e3(e),e),longPress:async e=>await s("longpress",[String(e.x),String(e.y),...e8(e.durationMs)],e),swipe:async e=>await s("swipe",[String(e.from.x),String(e.from.y),String(e.to.x),String(e.to.y),...e8(e.durationMs)],e),focus:async e=>await s("focus",[String(e.x),String(e.y)],e),type:async e=>await s("type",[e.text],e),fill:async e=>await s("fill",[...e3(e),e.text],e),scroll:async e=>await s("scroll",[e.direction,...e8(e.amount)],e),pinch:async e=>await s("pinch",[String(e.scale),...e8(e.x),...e8(e.y)],e),get:async e=>{var t;return await s("get",[e.format,...void 0!==(t=e).ref?[t.ref,...e5(t.label)]:[t.selector]],e)},is:async e=>await s("is",[e.predicate,e.selector,..."text"===e.predicate?[e.value]:[]],e),find:async e=>await s("find",function(e){let t=e.locator&&"any"!==e.locator?[e.locator,e.query]:[e.query];switch(e.action){case void 0:case"click":case"focus":case"exists":return e.action?[...t,e.action]:t;case"getText":return[...t,"get","text"];case"getAttrs":return[...t,"get","attrs"];case"wait":return[...t,"wait",...e8(e.timeoutMs)];case"fill":case"type":return[...t,e.action,e.value]}}(e),{...e,findFirst:e.first,findLast:e.last})},replay:{run:async e=>await s("replay",[e.path],{...e,replayUpdate:e.update}),test:async e=>await s("test",e.paths,{...e,replayUpdate:e.update})},batch:{run:async e=>await s("batch",[],{...e,batchSteps:e.steps,batchOnError:e.onError,batchMaxSteps:e.maxSteps})},observability:{perf:async(e={})=>await s("perf",[],e),logs:async(e={})=>{var t;return await s("logs",[(t=e).action??"path",...e5(t.message)],e)},network:async(e={})=>{var t;return await s("network",[...(t=e).action?[t.action]:[],...e8(t.limit)],{...e,networkInclude:e.include})}},recording:{record:async e=>await s("record",[e.action,...e5(e.path)],e),trace:async e=>await s("trace",[e.action,...e5(e.path)],e)},settings:{update:async e=>await s("settings",[e.setting,e.state,..."permission"in e?[e.permission]:[],..."mode"in e&&e.mode?[e.mode]:[]],e)}}}function e3(e){return void 0!==e.ref?[e.ref,...e5(e.label)]:void 0!==e.selector?[e.selector]:[String(e.x),String(e.y)]}function e5(e){return void 0===e?[]:[e]}function e8(e){return void 0===e?[]:[String(e)]}function e6(e){let t=e.lease;if(!t||"object"!=typeof t||Array.isArray(t))throw Error("Invalid lease response from daemon");return{leaseId:eB(t,"leaseId"),tenantId:eB(t,"tenantId"),runId:eB(t,"runId"),backend:eB(t,"backend"),createdAt:"number"==typeof t.createdAt?t.createdAt:void 0,heartbeatAt:"number"==typeof t.heartbeatAt?t.heartbeatAt:void 0,expiresAt:"number"==typeof t.expiresAt?t.expiresAt:void 0}}export{AppError,isAgentDeviceError,normalizeAgentDeviceError}from"./152.js";export{centerOfRect}from"./57.js";export{commandCatalog,commands,createCommandRouter,ref,selector}from"./commands/index.js";export{createLocalArtifactAdapter}from"./io.js";export{T as assertBackendCapabilityAllowed,k as createAgentDevice,e2 as createAgentDeviceClient,M as createMemorySessionStore,D as localCommandPolicy,E as restrictedCommandPolicy};
|
|
1
|
+
export{AppError,isAgentDeviceError,normalizeAgentDeviceError}from"./9152.js";export{assertBackendCapabilityAllowed,createAgentDevice,createMemorySessionStore,localCommandPolicy,restrictedCommandPolicy}from"./8564.js";export{centerOfRect}from"./4057.js";export{commandCatalog,commands,createCommandRouter,ref,selector}from"./9076.js";export{createAgentDeviceClient}from"./9542.js";export{createLocalArtifactAdapter}from"./io.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{ARCHIVE_EXTENSIONS,isBlockedIpAddress,isBlockedSourceHostname,isTrustedInstallSourceUrl,materializeInstallablePath,validateDownloadSourceUrl}from"./989.js";
|
package/dist/src/io.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{promises as t}from"node:fs";import e from"node:os";import i from"node:path";import{AppError as a}from"./
|
|
1
|
+
import{promises as t}from"node:fs";import e from"node:os";import i from"node:path";import{AppError as a}from"./9152.js";function r(n={}){let l=n.cwd??process.cwd(),c=n.tempDir??e.tmpdir(),p=n.rootDir?o(n.rootDir,l):void 0;return{resolveInput:async t=>{if("uploadedArtifact"===t.kind)throw new a("UNSUPPORTED_OPERATION","Uploaded artifact inputs require a custom artifact adapter");return{path:o(t.path,l,p)}},reserveOutput:async(e,a)=>{let r,n=a.visibility??"client-visible",d=e?.kind==="path"?o(e.path,l,p):i.join(r=await t.mkdtemp(i.join(c,`agent-device-${a.field}-`)),`${a.field}${a.ext}`);return await t.mkdir(i.dirname(d),{recursive:!0}),{path:d,visibility:n,...r?{cleanup:async()=>{await t.rm(r,{recursive:!0,force:!0})}}:{},publish:async()=>e?.kind==="downloadableArtifact"?{kind:"localPath",field:a.field,path:d,fileName:e.fileName??i.basename(e.clientPath??d)}:void 0}},createTempFile:async e=>{let a=await t.mkdtemp(i.join(c,`${e.prefix}-`));return{path:i.join(a,`file${e.ext}`),visibility:"internal",cleanup:async()=>{await t.rm(a,{recursive:!0,force:!0})}}}}}function o(t,e,r){var o,n;let l,c=i.isAbsolute(t)?t:i.resolve(e,t);if(r&&(o=c,n=r,""!==(l=i.relative(n,o))&&(l.startsWith("..")||i.isAbsolute(l))))throw new a("INVALID_ARGS","Local path is outside the artifact adapter root",{path:c,rootDir:r});return c}export{r as createLocalArtifactAdapter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
package/dist/src/metro.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{buildMetroRuntimeHints as e,ensureMetroCompanion as t,stopMetroCompanion as r,prepareMetroRuntime as o}from"./1974.js";import{resolveRuntimeTransportHints as n}from"./9323.js";function i(e){return n(e)}async function s(e){let t=await o({projectRoot:e.projectRoot,kind:e.kind,publicBaseUrl:e.publicBaseUrl,proxyBaseUrl:e.proxyBaseUrl,proxyBearerToken:e.proxyBearerToken,bridgeScope:e.bridgeScope,launchUrl:e.launchUrl,companionProfileKey:e.profileKey,companionConsumerKey:e.consumerKey,metroPort:e.port,listenHost:e.listenHost,statusHost:e.statusHost,startupTimeoutMs:e.startupTimeoutMs,probeTimeoutMs:e.probeTimeoutMs,reuseExisting:e.reuseExisting,installDependenciesIfNeeded:e.installDependenciesIfNeeded,runtimeFilePath:e.runtimeFilePath,logPath:e.logPath,env:e.env});return{iosRuntime:t.iosRuntime,androidRuntime:t.androidRuntime,bridge:t.bridge,started:t.started,reused:t.reused,logPath:t.logPath}}async function u(e){let r=await t(e);return{pid:r.pid,started:r.spawned,logPath:r.logPath}}async function a(e){await r(e)}function l(t){return e(t,"ios")}function d(t){return e(t,"android")}export{buildBundleUrl,normalizeBaseUrl}from"./320.js";export{d as buildAndroidRuntimeHints,l as buildIosRuntimeHints,u as ensureMetroTunnel,s as prepareRemoteMetro,i as resolveRuntimeTransport,a as stopMetroTunnel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import{AppError as n}from"./
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{AppError as n}from"./9152.js";import{resolveUserPath as r}from"./3267.js";let o=new Set(["1","true","yes","on"]),i=new Set(["0","false","no","off"]);function a(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,"_$1").replace(/[^A-Za-z0-9_]/g,"_").toUpperCase()}`}function s(e,t,r,o){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>s({...e,multiple:!1},t,r,o));if("boolean"===e.type){var i=t,a=r,u=o;if("boolean"==typeof i)return i;if("string"==typeof i){let e=l(i);if(void 0!==e)return e}throw new n("INVALID_ARGS",`Invalid value for "${u}" in ${a}. Expected boolean.`)}if("booleanOrString"===e.type){if("boolean"==typeof t)return t;if("string"==typeof t&&void 0!==l(t))return l(t);if("string"==typeof t&&t.trim().length>0)return t;throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected boolean or non-empty string.`)}if("string"===e.type){if("string"==typeof t&&t.trim().length>0)return t;throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected non-empty string.`)}if("enum"===e.type){if(void 0!==e.setValue){var y=e,f=t,m=r,p=o;let i=y.setValue;if(f===i)return i;if("string"==typeof f){let e=f.trim();if(""===e||"true"===e||"1"===e)return i;if("false"===e||"0"===e)return}if(!0===f)return i;if(!1!==f)throw new n("INVALID_ARGS",`Invalid value for "${p}" in ${m}. Expected boolean-like value for enum flag.`);return}if("string"!=typeof t||!e.enumValues?.includes(t))throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected one of: ${e.enumValues?.join(", ")}.`);return t}let c="number"==typeof t?t:"string"==typeof t?Number(t):NaN;if(!Number.isFinite(c)||!Number.isInteger(c))throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected integer.`);if("number"==typeof e.min&&c<e.min)throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Must be >= ${e.min}.`);if("number"==typeof e.max&&c>e.max)throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Must be <= ${e.max}.`);return c}function l(e){let t=e.trim().toLowerCase();return!!o.has(t)||!i.has(t)&&void 0}let u=[{key:"stateDir",type:"string",path:!0},{key:"daemonBaseUrl",type:"string"},{key:"daemonAuthToken",type:"string"},{key:"daemonTransport",type:"enum",enumValues:["auto","socket","http"]},{key:"daemonServerMode",type:"enum",enumValues:["socket","http","dual"]},{key:"tenant",type:"string"},{key:"sessionIsolation",type:"enum",enumValues:["none","tenant"]},{key:"runId",type:"string"},{key:"leaseId",type:"string"},{key:"leaseBackend",type:"enum",enumValues:["ios-simulator","ios-instance","android-instance"]},{key:"platform",type:"enum",enumValues:["ios","macos","android","linux","apple"]},{key:"target",type:"enum",enumValues:["mobile","tv","desktop"]},{key:"device",type:"string"},{key:"udid",type:"string"},{key:"serial",type:"string"},{key:"iosSimulatorDeviceSet",type:"string",path:!0,legacyEnvNames:["IOS_SIMULATOR_DEVICE_SET"]},{key:"androidDeviceAllowlist",type:"string",legacyEnvNames:["ANDROID_DEVICE_ALLOWLIST"]},{key:"session",type:"string"},{key:"metroProjectRoot",type:"string",path:!0},{key:"metroKind",type:"enum",enumValues:["auto","react-native","expo"]},{key:"metroPublicBaseUrl",type:"string"},{key:"metroProxyBaseUrl",type:"string"},{key:"metroBearerToken",type:"string",legacyEnvNames:["AGENT_DEVICE_PROXY_TOKEN"]},{key:"metroPreparePort",type:"int",min:1,max:65535},{key:"metroListenHost",type:"string"},{key:"metroStatusHost",type:"string"},{key:"metroStartupTimeoutMs",type:"int",min:1},{key:"metroProbeTimeoutMs",type:"int",min:1},{key:"metroRuntimeFile",type:"string",path:!0},{key:"metroNoReuseExisting",type:"boolean"},{key:"metroNoInstallDeps",type:"boolean"}],y=new Map(u.map(e=>[e.key,e]));function f(e){let t=e.env??process.env;return r(e.configPath,{cwd:e.cwd,env:t})}function m(o){let i=function(o){let i,a,l=o.env??process.env,u=f(o);if(!e.existsSync(u))throw new n("INVALID_ARGS",`Remote config file not found: ${u}`);try{i=e.readFileSync(u,"utf8")}catch(e){throw new n("INVALID_ARGS",`Failed to read remote config file: ${u}`,{cause:e instanceof Error?e.message:String(e)})}try{a=JSON.parse(i)}catch(e){throw new n("INVALID_ARGS",`Invalid JSON in remote config file: ${u}`,{cause:e instanceof Error?e.message:String(e)})}if(!a||"object"!=typeof a||Array.isArray(a))throw new n("INVALID_ARGS",`Remote config file must contain a JSON object: ${u}`);let m={},p=a,c=t.dirname(u);for(let[e,t]of Object.entries(p)){let o=y.get(e);if(!o)throw new n("INVALID_ARGS",`Unsupported remote config key "${e}" in remote config file ${u}.`);let i=s(o,t,`remote config file ${u}`,e);m[o.key]="string"==typeof i&&"path"in o&&o.path?r(i,{cwd:c,env:l}):i}return{resolvedPath:u,profile:m}}(o);return{resolvedPath:i.resolvedPath,profile:function(...e){let t={};for(let n of e)if(n)for(let e of u){let r=n[e.key];void 0!==r&&(t[e.key]=r)}return t}(function(e=process.env){let t={};for(let n of u){let r=(function(e){let t=y.get(e);return[a(e),...t?.legacyEnvNames??[]]})(n.key).map(t=>({name:t,value:e[t]})).find(e=>"string"==typeof e.value&&e.value.trim().length>0);r&&(t[n.key]=s(n,r.value,`environment variable ${r.name}`,r.name))}return t}(o.env),i.profile)}}export{u as REMOTE_CONFIG_FIELD_SPECS,a as buildPrimaryEnvVarName,s as parseSourceValue,f as resolveRemoteConfigPath,m as resolveRemoteConfigProfile};
|
package/dist/src/selectors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{findSelectorChainMatch,formatSelectorFailure,isNodeEditable,isNodeVisible,isSelectorToken,parseSelectorChain,resolveSelectorChain,tryParseSelectorChain}from"./7847.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:assert/strict";import{commands as a,selector as s}from"../
|
|
1
|
+
import e from"node:assert/strict";import{commands as a,selector as s}from"../9076.js";let t={session:"default",app:"com.example.app",installSourcePath:"/tmp/example.app",appEventName:"example.ready",appPushPayload:{aps:{alert:"hello"}},visibleSelector:"label=Continue",visibleText:"Continue",editableTarget:s("label=Email"),fillText:"hello@example.com",point:{x:4,y:8},swipeTo:{x:24,y:28}},n=w({name:"capture",cases:[{name:"captures screenshots through the backend primitive",command:"capture.screenshot",run:async(s,t)=>{let n=await a.capture.screenshot(s,{session:t.session});e.equal(typeof n.path,"string"),e.ok(n.path.length>0)}},{name:"captures snapshots with nodes",command:"capture.snapshot",run:async(s,t)=>{let n=await a.capture.snapshot(s,{session:t.session});e.ok(Array.isArray(n.nodes))}}]}),i=w({name:"selectors",cases:[{name:"finds visible text",command:"selectors.find",run:async(s,t)=>{let n=await a.selectors.find(s,{session:t.session,query:t.visibleText,action:"exists"});e.equal(n.kind,"found"),e.equal(n.found,!0)}},{name:"reads text from a selector",command:"selectors.getText",run:async(t,n)=>{let i=await a.selectors.getText(t,{session:n.session,target:s(n.visibleSelector)});e.equal(i.kind,"text"),e.equal(i.text,n.visibleText)}},{name:"checks selector visibility",command:"selectors.isVisible",run:async(t,n)=>{let i=await a.selectors.isVisible(t,{session:n.session,target:s(n.visibleSelector)});e.equal(i.pass,!0)}},{name:"waits for visible text",command:"selectors.waitForText",run:async(s,t)=>{let n=await a.selectors.waitForText(s,{session:t.session,text:t.visibleText,timeoutMs:1});e.equal(n.kind,"text"),e.equal(n.text,t.visibleText)}}]}),o=w({name:"interactions",cases:[{name:"clicks selector targets",command:"interactions.click",run:async(t,n)=>{let i=await a.interactions.click(t,{session:n.session,target:s(n.visibleSelector)});e.equal(i.kind,"selector")}},{name:"presses explicit points",command:"interactions.press",run:async(s,t)=>{let n=await a.interactions.press(s,{session:t.session,target:{kind:"point",...t.point}});e.deepEqual(n.point,t.point)}},{name:"fills editable targets",command:"interactions.fill",run:async(s,t)=>{let n=await a.interactions.fill(s,{session:t.session,target:t.editableTarget,text:t.fillText});e.equal(n.text,t.fillText)}},{name:"types text without a target",command:"interactions.typeText",run:async(s,t)=>{let n=await a.interactions.typeText(s,{session:t.session,text:t.fillText});e.equal(n.text,t.fillText)}},{name:"focuses selector targets",command:"interactions.focus",run:async(t,n)=>{let i=await a.interactions.focus(t,{session:n.session,target:s(n.visibleSelector)});e.equal(i.kind,"selector")}},{name:"long presses selector targets",command:"interactions.longPress",run:async(t,n)=>{let i=await a.interactions.longPress(t,{session:n.session,target:s(n.visibleSelector),durationMs:500});e.equal(i.kind,"selector")}},{name:"swipes explicit points",command:"interactions.swipe",run:async(s,t)=>{let n=await a.interactions.swipe(s,{session:t.session,from:t.point,to:t.swipeTo});e.deepEqual(n.from,t.point)}},{name:"scrolls viewport targets",command:"interactions.scroll",run:async(s,t)=>{let n=await a.interactions.scroll(s,{session:t.session,target:{kind:"viewport"},direction:"down"});e.equal(n.kind,"viewport")}},{name:"pinches through the backend primitive",command:"interactions.pinch",run:async s=>{let t=await a.interactions.pinch(s,{scale:1.1});e.equal(t.kind,"pinch")}}]}),r=w({name:"system",cases:[{name:"presses back",command:"system.back",run:async(s,t)=>{let n=await a.system.back(s,{session:t.session,mode:"in-app"});e.equal(n.kind,"systemBack")}},{name:"presses home",command:"system.home",run:async(s,t)=>{let n=await a.system.home(s,{session:t.session});e.equal(n.kind,"systemHome")}},{name:"rotates devices",command:"system.rotate",run:async(s,t)=>{let n=await a.system.rotate(s,{session:t.session,orientation:"portrait"});e.equal(n.orientation,"portrait")}},{name:"reads keyboard state",command:"system.keyboard",run:async(s,t)=>{let n=await a.system.keyboard(s,{session:t.session,action:"status"});e.equal(n.kind,"keyboardState")}},{name:"reads clipboard text",command:"system.clipboard",run:async(s,t)=>{let n=await a.system.clipboard(s,{session:t.session,action:"read"});e.equal(n.kind,"clipboardText")}},{name:"opens settings",command:"system.settings",run:async(s,t)=>{let n=await a.system.settings(s,{session:t.session});e.equal(n.kind,"settingsOpened")}},{name:"reads alert state",command:"system.alert",run:async(s,t)=>{let n=await a.system.alert(s,{session:t.session,action:"get"});e.equal(n.kind,"alertStatus")}},{name:"opens app switcher",command:"system.appSwitcher",run:async(s,t)=>{let n=await a.system.appSwitcher(s,{session:t.session});e.equal(n.kind,"appSwitcherOpened")}}]}),c=w({name:"apps",cases:[{name:"opens apps by id",command:"apps.open",run:async(s,t)=>{let n=await a.apps.open(s,{session:t.session,app:t.app});e.equal(n.kind,"appOpened"),e.equal(n.target.app,t.app)}},{name:"closes apps by id",command:"apps.close",run:async(s,t)=>{let n=await a.apps.close(s,{session:t.session,app:t.app});e.equal(n.kind,"appClosed"),e.equal(n.app,t.app)}},{name:"lists apps",command:"apps.list",run:async s=>{let t=await a.apps.list(s,{filter:"all"});e.equal(t.kind,"appsList"),e.ok(Array.isArray(t.apps))}},{name:"reads app state",command:"apps.state",run:async(s,t)=>{let n=await a.apps.state(s,{session:t.session,app:t.app});e.equal(n.kind,"appState"),e.equal(n.app,t.app)}},{name:"pushes app payloads",command:"apps.push",run:async(s,t)=>{let n=await a.apps.push(s,{session:t.session,app:t.app,input:{kind:"json",payload:t.appPushPayload}});e.equal(n.kind,"appPushed"),e.equal(n.inputKind,"json")}},{name:"triggers app events",command:"apps.triggerEvent",run:async(s,t)=>{let n=await a.apps.triggerEvent(s,{session:t.session,name:t.appEventName});e.equal(n.kind,"appEventTriggered"),e.equal(n.name,t.appEventName)}}]}),l=w({name:"admin",cases:[{name:"lists devices",command:"admin.devices",run:async s=>{let t=await a.admin.devices(s,{});e.equal(t.kind,"adminDevices"),e.ok(Array.isArray(t.devices))}},{name:"boots devices",command:"admin.boot",run:async s=>{let t=await a.admin.boot(s,{});e.equal(t.kind,"deviceBooted")}},{name:"ensures simulators",command:"admin.ensureSimulator",run:async s=>{let t=await a.admin.ensureSimulator(s,{device:"iPhone 16",runtime:"iOS 18"});e.equal(t.kind,"simulatorEnsured")}},{name:"installs apps from structured sources",command:"admin.install",run:async(s,t)=>{let n=await a.admin.install(s,{app:t.app,source:{kind:"path",path:t.installSourcePath}});e.equal(n.kind,"appInstalled")}},{name:"reinstalls apps from structured sources",command:"admin.reinstall",run:async(s,t)=>{let n=await a.admin.reinstall(s,{app:t.app,source:{kind:"path",path:t.installSourcePath}});e.equal(n.kind,"appReinstalled")}},{name:"installs apps from source resolver",command:"admin.installFromSource",run:async(s,t)=>{let n=await a.admin.installFromSource(s,{source:{kind:"path",path:t.installSourcePath}});e.equal(n.kind,"appInstalledFromSource")}}]}),m=w({name:"recording",cases:[{name:"starts recording",command:"record",run:async s=>{let t=await a.recording.record(s,{action:"start"});e.equal(t.kind,"recordingStarted")}},{name:"stops traces",command:"trace",run:async s=>{let t=await a.recording.trace(s,{action:"stop"});e.equal(t.kind,"traceStopped")}}]}),p=w({name:"diagnostics",cases:[{name:"reads paginated logs",command:"diagnostics.logs",run:async s=>{let t=await a.diagnostics.logs(s,{limit:10});e.equal(t.kind,"diagnosticsLogs"),e.ok(Array.isArray(t.entries))}},{name:"dumps structured network entries",command:"diagnostics.network",run:async s=>{let t=await a.diagnostics.network(s,{limit:10,include:"summary"});e.equal(t.kind,"diagnosticsNetwork"),e.ok(Array.isArray(t.entries))}},{name:"measures perf metrics",command:"diagnostics.perf",run:async s=>{let t=await a.diagnostics.perf(s,{sampleMs:100});e.equal(t.kind,"diagnosticsPerf"),e.ok(Array.isArray(t.metrics))}}]}),d=[n,i,o,r,c,l,m,p];async function u(e,a={}){let s=a.suites??d,t=[];for(let a of s)t.push(await a.run(e));let n=t.flatMap(e=>e.failures);return{target:e.name,passed:t.reduce((e,a)=>e+a.passed,0),failed:t.reduce((e,a)=>e+a.failed,0),failures:n,suites:t}}async function y(e,a={}){let s=await u(e,a);if(s.failed>0)throw AggregateError(s.failures.map(e=>e.error),`${e.name} failed ${s.failed} agent-device conformance case${1===s.failed?"":"s"}`);return s}function w(e){return{name:e.name,cases:e.cases,run:async a=>{let s={...t,...a.fixtures},n=[],i=0;for(let t of e.cases){let o={suite:e.name,caseName:t.name,fixtures:s};try{await a.beforeEach?.(o);let e=await a.createRuntime();await t.run(e,s),i+=1}catch(a){n.push({suite:e.name,caseName:t.name,command:t.command,error:a})}finally{await a.afterEach?.(o)}}return{suite:e.name,passed:i,failed:n.length,failures:n}}}}export{l as adminConformanceSuite,c as appsConformanceSuite,y as assertCommandConformance,n as captureConformanceSuite,d as commandConformanceSuites,t as defaultCommandConformanceFixtures,p as diagnosticsConformanceSuite,o as interactionConformanceSuite,m as recordingConformanceSuite,u as runCommandConformance,i as selectorConformanceSuite,r as systemConformanceSuite};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
package/package.json
CHANGED
|
@@ -62,15 +62,17 @@ agent-device install com.example.app ./build/MyApp.app --platform ios --device "
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
|
-
|
|
66
|
-
agent-device install-from-source
|
|
65
|
+
ARTIFACT_URL="<trusted-artifact-url>"
|
|
66
|
+
agent-device install-from-source "$ARTIFACT_URL" --platform android
|
|
67
|
+
GITHUB_ARTIFACT_URL="<trusted-github-actions-artifact-api-url>"
|
|
68
|
+
agent-device install-from-source "$GITHUB_ARTIFACT_URL" --platform ios --header "authorization: Bearer TOKEN"
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
## Install guidance
|
|
70
72
|
|
|
71
73
|
- Use `install <app> <path>` when the app may already be installed and you do not need a fresh-state reset.
|
|
72
74
|
- Use `reinstall <app> <path>` when you explicitly need uninstall plus install as one deterministic step.
|
|
73
|
-
- Use `install-from-source <url>` when an existing artifact URL is
|
|
75
|
+
- Use `install-from-source <url>` only when an existing artifact URL is trusted, operator-approved, and reachable by the daemon.
|
|
74
76
|
- Local `.apk`, `.aab`, `.app`, and `.ipa` paths go through `install` or `reinstall`; existing reachable URLs go through `install-from-source`.
|
|
75
77
|
- Do not download, re-zip, publish temporary GitHub releases, or move CI artifacts elsewhere just to make an install command work.
|
|
76
78
|
- Keep install and open as separate phases. Do not turn them into one default command flow.
|
|
@@ -7,47 +7,87 @@ Open this file for remote daemon HTTP flows that let an agent running in a Linux
|
|
|
7
7
|
## Main commands to reach for first
|
|
8
8
|
|
|
9
9
|
- `agent-device connect --remote-config <path>`
|
|
10
|
+
- `agent-device install-from-source <url> --remote-config <path> --platform android`
|
|
11
|
+
- `agent-device open <package> --remote-config <path> --relaunch`
|
|
12
|
+
- `agent-device snapshot --remote-config <path> -i`
|
|
13
|
+
- `agent-device disconnect --remote-config <path>`
|
|
10
14
|
- `agent-device connection status`
|
|
11
|
-
- `agent-device disconnect`
|
|
12
15
|
- `AGENT_DEVICE_DAEMON_AUTH_TOKEN=...`
|
|
13
16
|
|
|
14
17
|
## Most common mistake to avoid
|
|
15
18
|
|
|
16
|
-
Do not
|
|
19
|
+
Do not mix an arbitrary `--session` plus ad-hoc daemon, tenant, run, or lease flags. That can bypass saved Metro runtime hints. Use one of these patterns instead:
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
- Interactive flow: run `connect --remote-config <path>` once, then normal commands, then `disconnect`.
|
|
22
|
+
- Script flow: pass the same `--remote-config <path>` to every command, including `disconnect`.
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
## Choose one flow
|
|
25
|
+
|
|
26
|
+
### Interactive flow
|
|
27
|
+
|
|
28
|
+
Use this when the agent will run several commands in one session.
|
|
21
29
|
|
|
22
30
|
```bash
|
|
23
31
|
export AGENT_DEVICE_DAEMON_AUTH_TOKEN="YOUR_TOKEN"
|
|
24
32
|
export AGENT_DEVICE_PROXY_TOKEN="$AGENT_DEVICE_DAEMON_AUTH_TOKEN"
|
|
25
33
|
|
|
26
|
-
agent-device connect
|
|
27
|
-
--remote-config ./remote-config.json
|
|
34
|
+
agent-device connect --remote-config ./remote-config.json
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
agent-device install-from-source
|
|
36
|
+
ARTIFACT_URL="<trusted-artifact-url>"
|
|
37
|
+
agent-device install-from-source "$ARTIFACT_URL" --platform android
|
|
31
38
|
agent-device open com.example.app --relaunch
|
|
32
39
|
agent-device snapshot -i
|
|
33
40
|
agent-device fill @e3 "test@example.com"
|
|
34
41
|
agent-device disconnect
|
|
35
42
|
```
|
|
36
43
|
|
|
37
|
-
`connect
|
|
44
|
+
After `connect`, normal commands use the active remote connection. End with `disconnect` to release the lease and stop the owned Metro companion.
|
|
45
|
+
|
|
46
|
+
### Self-contained script flow
|
|
47
|
+
|
|
48
|
+
Use this when each command must be explicit and repeatable. Pass the same `--remote-config` to each step.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
ARTIFACT_URL="<trusted-artifact-url>"
|
|
52
|
+
|
|
53
|
+
agent-device install-from-source "$ARTIFACT_URL" \
|
|
54
|
+
--remote-config ./remote-config.json \
|
|
55
|
+
--platform android
|
|
56
|
+
|
|
57
|
+
agent-device open com.example.app \
|
|
58
|
+
--remote-config ./remote-config.json \
|
|
59
|
+
--relaunch
|
|
60
|
+
|
|
61
|
+
agent-device snapshot \
|
|
62
|
+
--remote-config ./remote-config.json \
|
|
63
|
+
-i
|
|
64
|
+
|
|
65
|
+
agent-device disconnect \
|
|
66
|
+
--remote-config ./remote-config.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The first command that needs a lease or Metro runtime prepares and persists it. Later commands with the same `--remote-config` reuse that state. End with `disconnect --remote-config <path>` to release the lease and stop the owned Metro companion.
|
|
70
|
+
|
|
71
|
+
## Behavior summary
|
|
38
72
|
|
|
39
|
-
|
|
73
|
+
- `connect` stores local non-secret connection state and defers tenant lease allocation plus Metro preparation until a later command needs them.
|
|
74
|
+
- Commands such as `install-from-source`, `open`, `snapshot`, and `apps` allocate or refresh the lease when needed.
|
|
75
|
+
- `open` prepares Metro runtime hints when the remote profile has Metro fields and no compatible runtime is already saved.
|
|
76
|
+
- `batch` also prepares Metro when any step opens an app and that step does not provide its own runtime.
|
|
77
|
+
- `disconnect` closes the session when possible, stops the Metro companion owned by the connection, releases the lease when one was allocated, and removes local connection state.
|
|
40
78
|
|
|
41
79
|
Remote install examples:
|
|
42
80
|
|
|
43
81
|
```bash
|
|
44
82
|
agent-device install com.example.app ./app.apk
|
|
45
|
-
|
|
46
|
-
agent-device install-from-source
|
|
83
|
+
ARTIFACT_URL="<trusted-artifact-url>"
|
|
84
|
+
agent-device install-from-source "$ARTIFACT_URL" --platform android
|
|
85
|
+
GITHUB_ARTIFACT_URL="<trusted-github-actions-artifact-api-url>"
|
|
86
|
+
agent-device install-from-source "$GITHUB_ARTIFACT_URL" --platform ios --header "authorization: Bearer TOKEN"
|
|
47
87
|
```
|
|
48
88
|
|
|
49
89
|
- Use `install` or `reinstall` for local paths; remote daemons upload local artifacts automatically.
|
|
50
|
-
- Use `install-from-source` for artifact URLs the remote daemon can reach.
|
|
90
|
+
- Use `install-from-source` only for trusted, operator-approved artifact URLs the remote daemon can reach. Do not fetch arbitrary user-supplied URLs.
|
|
51
91
|
- For local-path versus URL artifact rules, follow [bootstrap-install.md](bootstrap-install.md).
|
|
52
92
|
|
|
53
93
|
Use `agent-device connection status --session adc-android` to inspect the active connection without reading JSON state manually. Status output must not include auth tokens.
|
package/dist/src/164.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"node:fs";import o from"node:os";import t from"node:path";function e(n=process.env){let r=n.ANDROID_SDK_ROOT?.trim(),i=n.ANDROID_HOME?.trim(),d=n.HOME?.trim()||o.homedir();return function(o){let t=new Set,e=[];for(let n of o){let o=n.trim();!o||t.has(o)||(t.add(o),e.push(o))}return e}([r??"",i??"",d?t.join(d,"Android","Sdk"):""])}t.join("cmdline-tools","latest","bin"),t.join("cmdline-tools","tools","bin");export{e as resolveAndroidSdkRoots};
|
package/dist/src/556.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{AppError as e}from"./152.js";function t(e,l,o,u={}){let c=i(o);if(!c)return{matches:[],score:0};let a=0,s=[];for(let t of e){if(u.requireRect&&!t.rect)continue;let e=function(e,t,i){switch(t){case"role":return function(e,t){let r=n(e??"");return r?r===t?2:+!!r.includes(t):0}(e.type,i);case"label":return r(e.label,i);case"value":return r(e.value,i);case"id":return r(e.identifier,i);default:return Math.max(r(e.label,i),r(e.value,i),r(e.identifier,i))}}(t,l,c);if(!(e<=0)){if(e>a){a=e,s.length=0,s.push(t);continue}e===a&&s.push(t)}}return{matches:s,score:a}}function r(e,t){let r=i(e??"");return r?r===t?2:+!!r.includes(t):0}function i(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function n(e){let t=e.trim();return t?t=(t.split(".").pop()??t).replace(/XCUIElementType/gi,"").toLowerCase():""}function l(t){let r="any",i=0;["text","label","value","role","id"].includes(t[0])&&(r=t[0],i=1);let n=t[i]??"",l=t.slice(i+1);if(0===l.length)return{locator:r,query:n,action:"click"};let o=l[0].toLowerCase();if("get"===o){let t=l[1]?.toLowerCase();if("text"===t)return{locator:r,query:n,action:"get_text"};if("attrs"===t)return{locator:r,query:n,action:"get_attrs"};throw new e("INVALID_ARGS","find get only supports text or attrs")}if("wait"===o)return{locator:r,query:n,action:"wait",timeoutMs:function(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}(l[1])??void 0};if("exists"===o)return{locator:r,query:n,action:"exists"};if("click"===o)return{locator:r,query:n,action:"click"};if("focus"===o)return{locator:r,query:n,action:"focus"};if("fill"===o)return{locator:r,query:n,action:"fill",value:l.slice(1).join(" ")};if("type"===o)return{locator:r,query:n,action:"type",value:l.slice(1).join(" ")};throw new e("INVALID_ARGS",`Unsupported find action: ${l[0]}`)}export{t as findBestMatchesByLocator,n as normalizeRole,i as normalizeText,l as parseFindArgs};
|
package/dist/src/57.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t){let n=t.trim();return n.startsWith("@")?n.slice(1)||null:n.startsWith("e")?n:null}function n(t,n){return t.find(t=>t.ref===n)??null}function e(t){return{x:Math.round(t.x+t.width/2),y:Math.round(t.y+t.height/2)}}export{e as centerOfRect,n as findNodeByRef,t as normalizeRef};
|