agent-device 0.11.9 → 0.11.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -9
- package/dist/src/113.js +3 -0
- package/dist/src/320.js +1 -0
- package/dist/src/818.js +3 -0
- package/dist/src/957.js +2 -0
- package/dist/src/974.js +2 -0
- package/dist/src/995.js +1 -3
- package/dist/src/bin.js +64 -65
- package/dist/src/contracts.d.ts +79 -0
- package/dist/src/contracts.js +0 -0
- package/dist/src/daemon.js +43 -43
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +2 -3
- package/dist/src/metro-companion.js +1 -0
- package/dist/src/metro.d.ts +95 -0
- package/dist/src/metro.js +1 -0
- package/dist/src/remote-config.d.ts +49 -0
- package/dist/src/remote-config.js +1 -0
- package/dist/src/update-check-entry.js +1 -0
- package/package.json +13 -1
- package/skills/agent-device/SKILL.md +1 -0
- package/skills/agent-device/references/remote-tenancy.md +11 -30
package/dist/src/index.d.ts
CHANGED
|
@@ -477,6 +477,9 @@ declare type MetroPrepareOptions = {
|
|
|
477
477
|
publicBaseUrl: string;
|
|
478
478
|
proxyBaseUrl?: string;
|
|
479
479
|
bearerToken?: string;
|
|
480
|
+
launchUrl?: string;
|
|
481
|
+
companionProfileKey?: string;
|
|
482
|
+
companionConsumerKey?: string;
|
|
480
483
|
port?: number;
|
|
481
484
|
listenHost?: string;
|
|
482
485
|
statusHost?: string;
|
package/dist/src/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import e from"node:net";import t from"node:http";import r from"node:https";import n from"node:fs";import o from"node:path";import{AsyncLocalStorage as a}from"node:async_hooks";import i from"node:crypto";import s from"node:os";import"node:fs/promises";import{spawn as l,spawnSync as u}from"node:child_process";import{fileURLToPath as d}from"node:url";let c=new a,p=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key)/i,m=/(bearer\s+[a-z0-9._-]+|(?:api[_-]?key|token|secret|password)\s*[=:]\s*\S+)/i;function f(){return i.randomBytes(8).toString("hex")}function h(e){let t=c.getStore();if(!t)return;let r={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?function e(t,r,n){if(null==t)return t;if("string"==typeof t){var o=t,a=n;let e=o.trim();if(!e)return o;if(a&&p.test(a)||m.test(e))return"[REDACTED]";let r=function(e){try{let t=new URL(e);return t.search&&(t.search="?REDACTED"),(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED"),t.toString()}catch{return null}}(e);return r||(e.length>400?`${e.slice(0,200)}...<truncated>`:e)}if("object"!=typeof t)return t;if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.map(t=>e(t,r));let i={};for(let[n,o]of Object.entries(t)){if(p.test(n)){i[n]="[REDACTED]";continue}i[n]=e(o,r,n)}return i}(e.data,new WeakSet):void 0};if(t.events.push(r),!t.debug)return;let o=`[agent-device][diag] ${JSON.stringify(r)}
|
|
2
|
-
`;try{t.logPath&&n.appendFile(t.logPath,o,()=>{}),t.traceLogPath&&n.appendFile(t.traceLogPath,o,()=>{}),t.logPath||t.traceLogPath||process.stderr.write(o)}catch{}}async function g(e,t,r){let n=Date.now();try{let o=await t();return h({level:"info",phase:e,durationMs:Date.now()-n,data:r}),o}catch(t){throw h({level:"error",phase:e,durationMs:Date.now()-n,data:{...r??{},error:t instanceof Error?t.message:String(t)}}),t}}class w extends Error{code;details;cause;constructor(e,t,r,n){super(t),this.code=e,this.details=r,this.cause=n}}let y=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/;function I(e,t,r={}){let n=b(e),o=u(n,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],encoding:r.binaryStdout?void 0:"utf8",input:r.stdin,timeout:A(r.timeoutMs),shell:!1});if(o.error){let a=o.error.code;if("ETIMEDOUT"===a)throw new w("COMMAND_FAILED",`${n} timed out after ${A(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:A(r.timeoutMs)},o.error);if("ENOENT"===a)throw new w("TOOL_MISSING",`${n} not found in PATH`,{cmd:e},o.error);throw new w("COMMAND_FAILED",`Failed to run ${n}`,{cmd:e,args:t},o.error)}let a=r.binaryStdout?Buffer.isBuffer(o.stdout)?o.stdout:Buffer.from(o.stdout??""):void 0,i=r.binaryStdout?"":"string"==typeof o.stdout?o.stdout:(o.stdout??"").toString(),s="string"==typeof o.stderr?o.stderr:(o.stderr??"").toString(),l=o.status??1;if(0!==l&&!r.allowFailure)throw new w("COMMAND_FAILED",`${n} exited with code ${l}`,{cmd:e,args:t,stdout:i,stderr:s,exitCode:l,processExitError:!0});return{stdout:i,stderr:s,exitCode:l,stdoutBuffer:a}}function v(e,t,r={}){let n=l(b(e),t,{cwd:r.cwd,env:r.env,stdio:r.stdio??"ignore",detached:!0,shell:!1});return n.unref(),n.pid??0}function b(e){var t;let r,n=(t={allowRelativePath:!0},!(r=e.trim())||r.includes("\0")?null:o.isAbsolute(r)?r:r.includes("/")||r.includes("\\")?t.allowRelativePath?r:null:y.test(r)?r:null);if(!n)throw new w("INVALID_ARGS",`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e});return n}function A(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function E(){let e=o.dirname(d(import.meta.url)),t=e;for(let e=0;e<6;e+=1){let e=o.join(t,"package.json");if(n.existsSync(e))return t;t=o.dirname(t)}return e}let D=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function S(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"EPERM"===e.code}}function M(e,t){let r;if(!S(e))return!1;if(t){let r=function(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=I("ps",["-p",String(e),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}(e);if(!r||r!==t)return!1}let n=function(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=I("ps",["-p",String(e),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}(e);return!!n&&!!(r=n.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&D.some(e=>e.test(r))}function _(e,t){try{return process.kill(e,t),!0}catch(t){let e=t.code;if("ESRCH"===e||"EPERM"===e)return!1;throw t}}async function P(e,t){if(!S(e))return!0;let r=Date.now();for(;Date.now()-r<t;)if(await new Promise(e=>setTimeout(e,50)),!S(e))return!0;return!S(e)}async function k(e,t){!M(e,t.expectedStartTime)||!_(e,"SIGTERM")||await P(e,t.termTimeoutMs)||_(e,"SIGKILL")&&await P(e,t.killTimeoutMs)}function T(e){return e?.HOME?.trim()||s.homedir()}function N(e,t={}){return"~"===e?T(t.env):e.startsWith("~/")?o.join(T(t.env),e.slice(2)):e}function R(e,t={}){let r=N(e,t);return o.isAbsolute(r)?r:o.resolve(t.cwd??process.cwd(),r)}function x(e){let t,r=(t=(e??"").trim())?R(t):o.join(N("~"),".agent-device");return{baseDir:r,infoPath:o.join(r,"daemon.json"),lockPath:o.join(r,"daemon.lock"),logPath:o.join(r,"daemon.log"),sessionsDir:o.join(r,"sessions")}}async function U(e){let{localPath:a,baseUrl:i,token:s}=e,u=n.statSync(a).isDirectory(),d=o.basename(a),c=new URL("upload",i.endsWith("/")?i:`${i}/`),p="https:"===c.protocol?r:t,m={"x-artifact-type":u?"app-bundle":"file","x-artifact-filename":d,"transfer-encoding":"chunked"};return s&&(m.authorization=`Bearer ${s}`,m["x-agent-device-token"]=s),new Promise((e,t)=>{let r=p.request({protocol:c.protocol,host:c.hostname,port:c.port,method:"POST",path:c.pathname+c.search,headers:m},r=>{let n="";r.setEncoding("utf8"),r.on("data",e=>{n+=e}),r.on("end",()=>{clearTimeout(i);try{let r=JSON.parse(n);if(!r.ok||!r.uploadId)return void t(new w("COMMAND_FAILED",`Upload failed: ${n}`));e(r.uploadId)}catch{t(new w("COMMAND_FAILED",`Invalid upload response: ${n}`))}})}),i=setTimeout(()=>{r.destroy(),t(new w("COMMAND_FAILED","Artifact upload timed out",{timeoutMs:3e5,hint:"The upload to the remote daemon exceeded the 5-minute timeout."}))},3e5);if(r.on("error",e=>{clearTimeout(i),t(new w("COMMAND_FAILED","Failed to upload artifact to remote daemon",{hint:"Verify the remote daemon is reachable and supports artifact uploads."},e))}),u){let e=l("tar",["cf","-","-C",o.dirname(a),o.basename(a)],{stdio:["ignore","pipe","pipe"]});e.stdout.pipe(r),e.on("error",e=>{r.destroy(),t(new w("COMMAND_FAILED","Failed to create tar archive for app bundle",{},e))}),e.on("close",e=>{0!==e&&(r.destroy(),t(new w("COMMAND_FAILED",`tar failed with exit code ${e}`)))})}else{let e=n.createReadStream(a);e.pipe(r),e.on("error",e=>{r.destroy(),t(new w("COMMAND_FAILED","Failed to read local artifact",{},e))})}})}let O=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,C=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,L=[".ts",".tsx",".js",".jsx",".mjs",".cjs"];function $(e,t,r){t.lastIndex=0;let n=null;for(;null!==(n=t.exec(e));){let e=n[1]?.trim();e?.startsWith(".")&&r.add(e)}}function F(e){try{return n.statSync(e).isFile()?e:null}catch{return null}}let j=eI(),q=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}(),B=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}(),G=["xcodebuild .*AgentDeviceRunnerUITests/RunnerTests/testCommand","xcodebuild .*AgentDeviceRunner\\.env\\.session-","xcodebuild build-for-testing .*ios-runner/AgentDeviceRunner/AgentDeviceRunner\\.xcodeproj"];async function V(e){let t=e.meta?.requestId??f(),r=!!(e.meta?.debug||e.flags?.verbose),n=function(e){let t,r,n=e.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR,o=function(e){let t;if(e){try{t=new URL(e)}catch(t){throw new w("INVALID_ARGS","Invalid daemon base URL",{daemonBaseUrl:e},t instanceof Error?t:void 0)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new w("INVALID_ARGS","Daemon base URL must use http or https",{daemonBaseUrl:e});return t.toString().replace(/\/+$/,"")}}(e.flags?.daemonBaseUrl??process.env.AGENT_DEVICE_DAEMON_BASE_URL),a=e.flags?.daemonAuthToken??process.env.AGENT_DEVICE_DAEMON_AUTH_TOKEN,i=e.flags?.daemonTransport??process.env.AGENT_DEVICE_DAEMON_TRANSPORT,s="auto"===(t=(i??"").trim().toLowerCase())?"auto":"socket"===t?"socket":"http"===t?"http":"auto";if(o&&"socket"===s)throw new w("INVALID_ARGS","Remote daemon base URL only supports HTTP transport. Remove --daemon-transport socket.",{daemonBaseUrl:o});let l="http"===(r=(e.flags?.daemonServerMode??process.env.AGENT_DEVICE_DAEMON_SERVER_MODE??("dual"===i?"dual":void 0)??"").trim().toLowerCase())?"http":"dual"===r?"dual":"socket";return{paths:x(n),transportPreference:s,serverMode:l,remoteBaseUrl:o,remoteAuthToken:a}}(e),o=function(e,t=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if("test"!==e)return eI(t)}(e.command),a=await g("daemon_startup",async()=>await K(n),{requestId:t,session:e.session}),i=await z(e,a),s={...e,positionals:i.positionals,flags:i.flags,token:a.token,meta:{...e.meta??{},requestId:t,debug:r,cwd:e.meta?.cwd,tenantId:e.meta?.tenantId??e.flags?.tenant,runId:e.meta?.runId??e.flags?.runId,leaseId:e.meta?.leaseId??e.flags?.leaseId,sessionIsolation:e.meta?.sessionIsolation??e.flags?.sessionIsolation,lockPolicy:e.meta?.lockPolicy,lockPlatform:e.meta?.lockPlatform,...i.uploadedArtifactId?{uploadedArtifactId:i.uploadedArtifactId}:{},...i.clientArtifactPaths?{clientArtifactPaths:i.clientArtifactPaths}:{},...i.installSource?{installSource:i.installSource}:{}}};return h({level:"info",phase:"daemon_request_prepare",data:{requestId:t,command:e.command,session:e.session}}),await g("daemon_request",async()=>await el(a,s,n.transportPreference,o),{requestId:t,command:e.command})}async function z(e,t){let r,a=[...e.positionals??[]],i=e.flags?{...e.flags}:void 0,s=e.meta?.installSource,l={};if(eh(t)){let n=function(e,t){if("screenshot"===e.command){let r=J(e,"path",".png");return t[0]?{field:"path",localPath:r,positionalIndex:0,positionalPath:W("screenshot",".png")}:{field:"path",localPath:r,positionalIndex:0,flagPath:W("screenshot",".png")}}if("record"===e.command&&"start"===(t[0]??"").toLowerCase()){let t=J(e,"outPath",".mp4",1);return{field:"outPath",localPath:t,positionalIndex:1,positionalPath:W("recording",o.extname(t)||".mp4")}}return null}(e,a);n&&(void 0!==n.positionalPath&&(a[n.positionalIndex]=n.positionalPath),void 0!==n.flagPath&&((i??={}).out=n.flagPath),l[n.field]=n.localPath);let u=await H(e,t);u&&(s=u.installSource,r=u.uploadedArtifactId??r)}if(!eh(t)||"install"!==e.command&&"reinstall"!==e.command||a.length<2)return{positionals:a,flags:i,installSource:s,uploadedArtifactId:r,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let u=a[1];if(u.startsWith("remote:"))return a[1]=u.slice(7),{positionals:a,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let d=o.isAbsolute(u)?u:o.resolve(e.meta?.cwd??process.cwd(),u);return n.existsSync(d)?{positionals:a,flags:i,installSource:s,uploadedArtifactId:r=await U({localPath:d,baseUrl:t.baseUrl,token:t.token}),...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}:{positionals:a,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}}async function H(e,t){let r=e.meta?.installSource;if("install_source"!==e.command||!r||"path"!==r.kind)return null;let a=r.path.trim();if(!a)return{installSource:r};if(a.startsWith("remote:"))return{installSource:{...r,path:a.slice(7)}};let i=o.isAbsolute(a)?a:o.resolve(e.meta?.cwd??process.cwd(),a);if(!n.existsSync(i))return{installSource:{...r,path:i}};let s=await U({localPath:i,baseUrl:t.baseUrl,token:t.token});return{installSource:{...r,path:i},uploadedArtifactId:s}}function J(e,t,r,n=0){let a=e.positionals?.[n]??e.flags?.out,i=`${"path"===t?"screenshot":"recording"}-${Date.now()}${r}`,s=a&&a.trim().length>0?a:i;return o.isAbsolute(s)?s:o.resolve(e.meta?.cwd??process.cwd(),s)}function W(e,t){let r=t.startsWith(".")?t:`.${t}`;return o.posix.join("/tmp",`agent-device-${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}${r}`)}async function K(e){let t;if(e.remoteBaseUrl){let t={transport:"http",token:e.remoteAuthToken??"",pid:0,baseUrl:e.remoteBaseUrl};if(await ea(t,"http"))return t;throw new w("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 r=ee(e.paths.infoPath),a=function(){try{let e=E();return JSON.parse(n.readFileSync(o.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}(),s=function(e,t=E()){try{let r=o.resolve(t),a=[o.resolve(e)],s=new Set,l=[];for(;a.length>0;){let e=a.pop();if(!e||s.has(e))continue;s.add(e);let t=n.statSync(e);if(!t.isFile())continue;let i=o.relative(r,e)||e;l.push(`${i}:${t.size}:${Math.trunc(t.mtimeMs)}`);let u=n.readFileSync(e,"utf8");for(let t of function(e){let t=new Set;return $(e,O,t),$(e,C,t),[...t]}(u)){let r=function(e,t){let r=o.resolve(o.dirname(e),t),n=F(r);if(n)return n;for(let e of L){let t=F(`${r}${e}`);if(t)return t}for(let e of L){let t=F(o.join(r,`index${e}`));if(t)return t}return null}(e,t);r&&a.push(r)}}let u=l.sort().join("|"),d=i.createHash("sha1").update(u).digest("hex");return`graph:${l.length}:${d}`}catch{return"unknown"}}((t=es()).useSrc?t.srcPath:t.distPath,t.root),l=!!r&&await ea(r,e.transportPreference);if(r&&r.version===a&&r.codeSignature===s&&l)return r;r&&(r.version!==a||r.codeSignature!==s||!l)&&(await Q(r),eo(e.paths.infoPath)),function(e){let t=er(e);if(!t.hasLock||t.hasInfo)return;let r=et(e.lockPath);if(!r)return eo(e.lockPath);M(r.pid,r.processStartTime)||eo(e.lockPath)}(e.paths);let u=0;for(let t=1;t<=B;t+=1){await ei(e);let r=await Z(q,e);if(r)return r;if(await Y(e.paths)){u+=1;continue}let n=er(e.paths);if(!(t<B))break;if(!n.hasInfo&&!n.hasLock){await X(150);continue}}let d=er(e.paths);throw new w("COMMAND_FAILED","Failed to start daemon",{kind:"daemon_startup_failed",infoPath:e.paths.infoPath,lockPath:e.paths.lockPath,startupTimeoutMs:q,startupAttempts:B,lockRecoveryCount:u,metadataState:d,hint:function(e,t=x(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 Z(e,t){let r=Date.now();for(;Date.now()-r<e;){let e=ee(t.paths.infoPath);if(e&&await ea(e,t.transportPreference))return e;await new Promise(e=>setTimeout(e,100))}return null}async function X(e){await new Promise(t=>setTimeout(t,e))}async function Y(e){let t=er(e);if(!t.hasLock||t.hasInfo)return!1;let r=et(e.lockPath);return r&&M(r.pid,r.processStartTime)&&await k(r.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:r.processStartTime}),eo(e.lockPath),!0}async function Q(e){await k(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}function ee(e){let t=en(e);if(!t||"object"!=typeof t)return null;let r="string"==typeof t.token&&t.token.length>0?t.token:null;if(!r)return null;let n=Number.isInteger(t.port)&&Number(t.port)>0,o=Number.isInteger(t.httpPort)&&Number(t.httpPort)>0;if(!n&&!o)return null;let a=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,u=Number.isInteger(t.pid)&&Number(t.pid)>0;return{token:r,port:n?Number(t.port):void 0,httpPort:o?Number(t.httpPort):void 0,transport:"socket"===a||"http"===a||"dual"===a?a:void 0,pid:u?Number(t.pid):0,version:i,codeSignature:s,processStartTime:l}}function et(e){let t=en(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}function er(e){return{hasInfo:n.existsSync(e.infoPath),hasLock:n.existsSync(e.lockPath)}}function en(e){if(!n.existsSync(e))return null;try{return JSON.parse(n.readFileSync(e,"utf8"))}catch{return null}}function eo(e){try{n.existsSync(e)&&n.unlinkSync(e)}catch{}}async function ea(n,o){var a;return"http"===eu(n,o)?await function(e){let n=e.baseUrl?eg(e.baseUrl,"health"):e.httpPort?`http://127.0.0.1:${e.httpPort}/health`:null;if(!n)return Promise.resolve(!1);let o=new URL(n),a="https:"===o.protocol?r:t,i=e.baseUrl?3e3:500;return new Promise(e=>{let t=a.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()})}(n):await ((a=n.port)?new Promise(t=>{let r=e.createConnection({host:"127.0.0.1",port:a},()=>{r.destroy(),t(!0)});r.on("error",()=>{t(!1)})}):Promise.resolve(!1))}async function ei(e){let t=es(),r=t.useSrc?["--experimental-strip-types",t.srcPath]:[t.distPath],n={...process.env,AGENT_DEVICE_STATE_DIR:e.paths.baseDir,AGENT_DEVICE_DAEMON_SERVER_MODE:e.serverMode};v(process.execPath,r,{env:n})}function es(){let e=E(),t=o.join(e,"dist","src","daemon.js"),r=o.join(e,"src","daemon.ts"),a=n.existsSync(t),i=n.existsSync(r);if(!a&&!i)throw new w("COMMAND_FAILED","Daemon entry not found",{distPath:t,srcPath:r});return{root:e,distPath:t,srcPath:r,useSrc:process.execArgv.includes("--experimental-strip-types")?i:!a&&i}}async function el(e,t,r,n){return"http"===eu(e,r)?await ef(e,t,n):await em(e,t,n)}function eu(e,t){if(e.baseUrl){if("socket"===t)throw new w("COMMAND_FAILED","Remote daemon endpoint only supports HTTP transport",{daemonBaseUrl:e.baseUrl});return"http"}if("http"===t||"socket"===t){var r=e,n=t;if(ed(r,n))return n;throw new w("COMMAND_FAILED","http"===n?"Daemon HTTP endpoint is unavailable":"Daemon socket endpoint is unavailable")}let o=("socket"===e.transport||"dual"===e.transport?["socket","http"]:["http","socket"]).find(t=>ed(e,t));if(o)return o;throw new w("COMMAND_FAILED","Daemon metadata has no reachable transport")}function ed(e,t){return"http"===t?!!e.httpPort:!!e.port}function ec(e,t,r,n,o,a){let i=o?{terminated:0}:function(){let e=0;try{for(let t of G){let r=I("pkill",["-f",t],{allowFailure:!0});0===r.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 r=!1;try{M(e.pid,e.processStartTime)&&(process.kill(e.pid,"SIGKILL"),r=!0)}catch{k(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}finally{eo(t.infoPath),eo(t.lockPath)}return{forcedKill:r}}(e,t);return h({level:"error",phase:"daemon_request_timeout",data:{timeoutMs:a,requestId:r,command:n,timedOutRunnerPidsTerminated:i.terminated,timedOutRunnerCleanupError:i.error,daemonPidReset:o?void 0:e.pid,daemonPidForceKilled:o?void 0:s.forcedKill,daemonBaseUrl:e.baseUrl}}),new w("COMMAND_FAILED","Daemon request timed out",{timeoutMs:a,requestId:r,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 ep(e,t,r){return h({level:"error",phase:"daemon_request_socket_error",data:{requestId:t,message:e instanceof Error?e.message:String(e)}}),new w("COMMAND_FAILED","Failed to communicate with daemon",{requestId:t,hint:r?"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 em(t,r,n){let o=t.port;if(!o)throw new w("COMMAND_FAILED","Daemon socket endpoint is unavailable");return new Promise((a,i)=>{let s=e.createConnection({host:"127.0.0.1",port:o},()=>{s.write(`${JSON.stringify(r)}
|
|
3
|
-
`)}),l=x(r.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),u="number"==typeof n?setTimeout(()=>{s.destroy(),i(ec(t,l,r.meta?.requestId,r.command,!1,n))},n):void 0,d="";s.setEncoding("utf8"),s.on("data",e=>{let t=(d+=e).indexOf("\n");if(-1===t)return;let n=d.slice(0,t).trim();if(n)try{let e=JSON.parse(n);s.end(),u&&clearTimeout(u),a(e)}catch(e){u&&clearTimeout(u),i(new w("COMMAND_FAILED","Invalid daemon response",{requestId:r.meta?.requestId,line:n},e instanceof Error?e:void 0))}}),s.on("error",e=>{u&&clearTimeout(u),i(ep(e,r.meta?.requestId,!1))})})}async function ef(e,n,o){let a=e.baseUrl?new URL(eg(e.baseUrl,"rpc")):e.httpPort?new URL(`http://127.0.0.1:${e.httpPort}/rpc`):null;if(!a)throw new w("COMMAND_FAILED","Daemon HTTP endpoint is unavailable");let i=JSON.stringify({jsonrpc:"2.0",id:n.meta?.requestId??f(),method:"agent_device.command",params:n}),s={"content-type":"application/json","content-length":Buffer.byteLength(i)};return e.baseUrl&&e.token&&(s.authorization=`Bearer ${e.token}`,s["x-agent-device-token"]=e.token),await new Promise((l,u)=>{let d=x(n.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),c=("https:"===a.protocol?r:t).request({protocol:a.protocol,host:a.hostname,port:a.port,method:"POST",path:a.pathname+a.search,headers:s},t=>{let r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{m&&clearTimeout(m);try{let t=JSON.parse(r);if(t.error){let e=t.error.data??{};u(new w(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:n.meta?.requestId}));return}if(!t.result||"object"!=typeof t.result)return void u(new w("COMMAND_FAILED","Invalid daemon RPC response",{requestId:n.meta?.requestId}));if(e.baseUrl&&t.result.ok)return void ew(e,n,t.result).then(l).catch(u);l(t.result)}catch(e){m&&clearTimeout(m),u(new w("COMMAND_FAILED","Invalid daemon response",{requestId:n.meta?.requestId,line:r},e instanceof Error?e:void 0))}})}),p=eh(e),m="number"==typeof o?setTimeout(()=>{c.destroy(),u(ec(e,d,n.meta?.requestId,n.command,p,o))},o):void 0;c.on("error",e=>{m&&clearTimeout(m),u(ep(e,n.meta?.requestId,p))}),c.write(i),c.end()})}function eh(e){return"string"==typeof e.baseUrl&&e.baseUrl.length>0}function eg(e,t){return new URL(t,e.endsWith("/")?e:`${e}/`).toString()}async function ew(e,t,r){let n=Array.isArray(r.data?.artifacts)?r.data.artifacts:[];if(0===n.length||!e.baseUrl)return r;let a=r.data?{...r.data}:{},i=[];for(let r of n){if(!r||"object"!=typeof r||"string"!=typeof r.artifactId){i.push(r);continue}let n=function(e,t){if(e.localPath&&e.localPath.trim().length>0)return e.localPath;let r=e.fileName?.trim()||`${e.field}-${Date.now()}`;return o.resolve(t.meta?.cwd??process.cwd(),r)}(r,t);await ey({baseUrl:e.baseUrl,token:e.token,artifactId:r.artifactId,destinationPath:n,requestId:t.meta?.requestId}),a[r.field]=n,i.push({...r,localPath:n})}return a.artifacts=i,{ok:!0,data:a}}async function ey(e){var a,i;let s,l=new URL((a=e.baseUrl,i=e.artifactId,s=a.endsWith("/")?a:`${a}/`,new URL(`upload/${encodeURIComponent(i)}`,s).toString())),u="https:"===l.protocol?r:t;await n.promises.mkdir(o.dirname(e.destinationPath),{recursive:!0}),await new Promise((t,r)=>{let o=!1,a=e.timeoutMs??j,i=a=>{if(!o){if(o=!0,clearTimeout(d),a)return void n.promises.rm(e.destinationPath,{force:!0}).finally(()=>r(a));t()}},s=u.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 r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{i(new w("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,statusCode:t.statusCode,requestId:e.requestId,body:r}))});return}let r=n.createWriteStream(e.destinationPath);r.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 w("COMMAND_FAILED","Remote artifact download was interrupted",{artifactId:e.artifactId,requestId:e.requestId}))}),r.on("finish",()=>{r.close(()=>i())}),t.pipe(r)}),d=setTimeout(()=>{s.destroy(new w("COMMAND_FAILED","Remote artifact download timed out",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:a}))},a);s.on("error",t=>{t instanceof w?i(t):i(new w("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:a},t instanceof Error?t:void 0))}),s.end()})}function eI(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}function ev(e){return e.replace(/\/+$/,"")}function eb(e){return"string"==typeof e&&e.trim()?ev(e.trim()):""}function eA(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function eE(e,t,r){return R(e,{env:t,cwd:r})}function eD(e){try{return n.accessSync(e,n.constants.F_OK),!0}catch{return!1}}function eS(e,t,r){if(null==e||""===e)return t;let n=Number.parseInt(String(e),10);return Number.isInteger(n)?Math.max(n,r):t}function eM(e,t){let r;return{platform:t,bundleUrl:((r=new URL(`${ev(e)}/index.bundle`)).searchParams.set("platform",t),r.searchParams.set("dev","true"),r.searchParams.set("minify","false"),r.toString())}}function e_(e,t){return{platform:t,metroHost:eA(e?.metro_host),metroPort:e?.metro_port,bundleUrl:eA(e?.metro_bundle_url),launchUrl:eA(e?.launch_url)}}async function eP(e){await new Promise(t=>setTimeout(t,e))}async function ek(e,t,r={}){try{let n=await fetch(e,{headers:r,signal:AbortSignal.timeout(t)});return{ok:n.ok,status:n.status,body:await n.text()}}catch(r){if(r instanceof Error&&"TimeoutError"===r.name)throw Error(`Timed out fetching ${e} after ${t}ms`);throw r}}async function eT(e,t){try{let r=await ek(e,t);return r.ok&&r.body.includes("packager-status:running")}catch{return!1}}async function eN(e){var t,r,n;let o;try{o=await fetch(`${e.baseUrl}/api/metro/bridge`,{method:"POST",headers:(t=e.baseUrl,r=e.bearerToken,{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...t.includes("ngrok")?{"ngrok-skip-browser-warning":"1"}:{}}),body:JSON.stringify({ios_runtime:e.runtime,timeout_ms:e.timeoutMs}),signal:AbortSignal.timeout(e.timeoutMs)})}catch(t){if(t instanceof Error&&"TimeoutError"===t.name)throw Error(`/api/metro/bridge timed out after ${e.timeoutMs}ms calling ${e.baseUrl}/api/metro/bridge`);throw t}let a=await o.text(),i=a?JSON.parse(a):{};if(!o.ok)throw Error(`/api/metro/bridge failed (${o.status}): ${JSON.stringify(i)}`);return{enabled:(n=i.data??i).enabled,baseUrl:n.base_url,statusUrl:n.status_url,bundleUrl:n.bundle_url,iosRuntime:e_(n.ios_runtime,"ios"),androidRuntime:e_(n.android_runtime,"android"),upstream:{bundleUrl:n.upstream.bundle_url,host:n.upstream.host,port:n.upstream.port,statusUrl:n.upstream.status_url},probe:{reachable:n.probe.reachable,statusCode:n.probe.status_code,latencyMs:n.probe.latency_ms,detail:n.probe.detail}}}async function eR(e,t,r){let n=Date.now()+t;for(;Date.now()<n;){let t=Math.min(r,Math.max(n-Date.now(),1));if(await eT(e,t))return!0;let o=Math.min(500,Math.max(n-Date.now(),0));o>0&&await eP(o)}return!1}async function ex(e={}){let t=e.env??process.env,r=process.cwd(),a=eE(e.projectRoot??r,t,r),i=function(e,t){if("auto"!==t)return t;let r=function(e){let t=o.join(e,"package.json");if(!eD(t))throw new w("INVALID_ARGS",`package.json not found at ${t}`);return JSON.parse(n.readFileSync(t,"utf8"))}(e);return"string"==typeof({...r.dependencies??{},...r.devDependencies??{}}).expo?"expo":"react-native"}(a,e.kind??"auto"),s=function(e){if(null==e||""===e)return 8081;let t=Number.parseInt(String(e),10);if(!Number.isInteger(t)||t<1||t>65535)throw new w("INVALID_ARGS",`Invalid Metro port: ${String(e)}. Use 1-65535.`);return t}(e.metroPort??8081),l=eA(e.listenHost)??"0.0.0.0",u=eA(e.statusHost)??"127.0.0.1",d=eb(e.publicBaseUrl),c=eS(e.startupTimeoutMs,18e4,3e4),p=eS(e.probeTimeoutMs,1e4,1e3),m=e.reuseExisting??!0,f=e.installDependenciesIfNeeded??!0,h=e.runtimeFilePath?eE(e.runtimeFilePath,t,r):null,g=eE(e.logPath??o.join(a,".agent-device","metro.log"),t,r);if(!d)throw new w("INVALID_ARGS","metro prepare requires --public-base-url <url>.");let{proxyEnabled:y,proxyBaseUrl:b,proxyBearerToken:A}=function(e,t){if(e&&!t)throw new w("INVALID_ARGS","metro prepare requires proxy auth when --proxy-base-url is provided. Pass --bearer-token or set AGENT_DEVICE_PROXY_TOKEN.");if(!e&&t)throw new w("INVALID_ARGS","metro prepare requires --proxy-base-url when proxy auth is provided.");return{proxyEnabled:!!(e&&t),proxyBaseUrl:e,proxyBearerToken:t}}(eb(e.proxyBaseUrl),eA(e.proxyBearerToken)??""),E=f?function(e,t){if(function(e){try{return n.statSync(e).isDirectory()}catch{return!1}}(o.join(e,"node_modules")))return{installed:!1};let r=eD(o.join(e,"pnpm-lock.yaml"))?{command:"pnpm",installArgs:["install"]}:eD(o.join(e,"yarn.lock"))?{command:"yarn",installArgs:["install"]}:{command:"npm",installArgs:["install"]};return I(r.command,r.installArgs,{cwd:e,env:t}),{installed:!0,packageManager:r.command}}(a,t):{installed:!1},D=`http://${u}:${s}/status`,S=!1,M=!1,_=0;if(m&&await eT(D,p))M=!0;else if(S=!0,_=function(e,t,r,a,i,s){let l="expo"===t?{command:"npx",installArgs:["expo","start","--host","lan","--port",String(r)]}:{command:"npx",installArgs:["react-native","start","--host",a,"--port",String(r)]};n.mkdirSync(o.dirname(i),{recursive:!0});let u=n.openSync(i,"a"),d=0;try{d=v(l.command,l.installArgs,{cwd:e,env:s,stdio:["ignore",u,u]})}finally{n.closeSync(u)}if(!Number.isInteger(d)||d<=0)throw Error("Failed to start Metro. Expected a detached child PID.");return{pid:d}}(a,i,s,l,g,t).pid,!await eR(D,c,p))throw Error(`Metro did not become ready at ${D} within ${c}ms. Check ${g}.`);let P=eM(d,"ios"),k=eM(d,"android"),T=null,N=null;if(y)try{T=await eN({baseUrl:b,bearerToken:A,runtime:{metro_bundle_url:P.bundleUrl},timeoutMs:p})}catch(e){N=e instanceof Error?e.message:String(e)}if(y&&(!T||!1===T.probe.reachable)){var R,x;let e;throw Error((R=N,x=T,e=[`Metro bridge is required for this run but could not be configured via ${b}/api/metro/bridge.`],R&&e.push(`bridgeError=${R}`),x?.probe.reachable===!1&&e.push(`bridgeProbe=${x.probe.detail||`unreachable (status ${x.probe.statusCode||0})`}`),e.join(" ")))}let U=T?.iosRuntime??P,O=T?.androidRuntime??k,C={projectRoot:a,kind:i,dependenciesInstalled:E.installed,packageManager:E.packageManager??null,started:S,reused:M,pid:_,logPath:g,statusUrl:D,runtimeFilePath:h,iosRuntime:U,androidRuntime:O,bridge:T};return h&&(n.mkdirSync(o.dirname(h),{recursive:!0}),n.writeFileSync(h,JSON.stringify(C,null,2))),C}function eU(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function eO(e,t,r){return{deviceId:t,deviceName:r,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function eC(e,t,r,n){let o=r(e[t]);if(void 0===o)throw new w("COMMAND_FAILED",n,{response:e});return o}function eL(e,t){return eC(e,t,eG,`Daemon response is missing "${t}".`)}function e$(e,t){return eG(e[t])}function eF(e,t){var r;let n;return r=eG,null===(n=e[t])?null:r(n)}function ej(e,t){return eC(e,t,ez,`Daemon response has invalid "${t}".`)}function eq(e,t){return function(e){return"tv"===e||"mobile"===e||"desktop"===e?e:void 0}(e[t])??"mobile"}function eB(e,t){let r=e[t];if(!eW(r))return;let n="number"==typeof r.x?r.x:void 0,o="number"==typeof r.y?r.y:void 0,a="number"==typeof r.width?r.width:void 0,i="number"==typeof r.height?r.height:void 0;if(void 0!==n&&void 0!==o&&void 0!==a&&void 0!==i)return{x:n,y:o,width:a,height:i}}function eG(e){return"string"==typeof e&&e.length>0?e:void 0}function eV(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function ez(e){return"ios"===e||"macos"===e||"android"===e?e:void 0}function eH(e){return"simulator"===e||"emulator"===e||"device"===e?e:void 0}function eJ(e){if(!eW(e))throw new w("COMMAND_FAILED","Daemon returned an unexpected response shape.",{value:e});return e}function eW(e){return"object"==typeof e&&null!==e}function eK(e){let t={};for(let[r,n]of Object.entries(e))void 0!==n&&(t[r]=n);return t}function eZ(e,t){let r=e$(e,"bundleId"),n=e$(e,"package");return{app:eL(e,"app"),appPath:eL(e,"appPath"),platform:ej(e,"platform"),appId:r??n,bundleId:r,package:n,identifiers:eU({session:t,bundleId:r,packageName:n})}}function eX(e){let t=eJ(e),r=ej(t,"platform"),n=eL(t,"id"),o=eL(t,"name");return{platform:r,target:eq(t,"target"),kind:eC(t,"kind",eH,'Daemon response has invalid "kind".'),id:n,name:o,booted:"boolean"==typeof t.booted?t.booted:void 0,identifiers:eO(r,n,o),ios:"ios"===r?{udid:n}:void 0,android:"android"===r?{serial:n}:void 0}}function eY(e){let t=eJ(e),r=ej(t,"platform"),n=eL(t,"id"),o=eL(t,"name"),a=eq(t,"target"),i=eL(t,"device"),s={session:o,...eO(r,n,i)};return{name:o,createdAt:eC(t,"createdAt",eV,'Daemon response is missing numeric "createdAt".'),device:{platform:r,target:a,id:n,name:i,identifiers:s,ios:"ios"===r?{udid:n,simulatorSetPath:eF(t,"ios_simulator_device_set")}:void 0,android:"android"===r?{serial:n}:void 0},identifiers:s}}function eQ(e,t){return t??e??"default"}function e0(e={},t={}){let r=t.transport??V,n=async(t,n=[],o={})=>{let a={...e,...o},i=await r({session:eQ(e.session,o.session),command:t,positionals:n,flags:eK({stateDir:a.stateDir,daemonBaseUrl:a.daemonBaseUrl,daemonAuthToken:a.daemonAuthToken,daemonTransport:a.daemonTransport,daemonServerMode:a.daemonServerMode,tenant:a.tenant,sessionIsolation:a.sessionIsolation,runId:a.runId,leaseId:a.leaseId,platform:a.platform,target:a.target,device:a.device,udid:a.udid,serial:a.serial,iosSimulatorDeviceSet:a.iosSimulatorDeviceSet,androidDeviceAllowlist:a.androidDeviceAllowlist,runtime:a.simulatorRuntimeId,boot:a.boot,reuseExisting:a.reuseExisting,surface:a.surface,activity:a.activity,relaunch:a.relaunch,shutdown:a.shutdown,saveScript:a.saveScript,noRecord:a.noRecord,metroHost:a.metroHost,metroPort:a.metroPort,bundleUrl:a.bundleUrl,launchUrl:a.launchUrl,snapshotInteractiveOnly:a.interactiveOnly,snapshotCompact:a.compact,snapshotDepth:a.depth,snapshotScope:a.scope,snapshotRaw:a.raw,overlayRefs:a.overlayRefs,verbose:a.debug}),runtime:a.runtime,meta:eK({requestId:a.requestId,cwd:a.cwd,debug:a.debug,lockPolicy:a.lockPolicy,lockPlatform:a.lockPlatform,tenantId:a.tenant,runId:a.runId,leaseId:a.leaseId,sessionIsolation:a.sessionIsolation,installSource:a.installSource,retainMaterializedPaths:a.retainMaterializedPaths,materializedPathRetentionMs:a.materializedPathRetentionMs,materializationId:a.materializationId})});if(!i.ok)throw new w(i.error.code,i.error.message,{...i.error.details??{},hint:i.error.hint,diagnosticId:i.error.diagnosticId,logPath:i.error.logPath});return i.data??{}},o=async(e={})=>{let t=await n("session_list",[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(eY)};return{devices:{list:async(e={})=>{let t=await n("devices",[],e);return(Array.isArray(t.devices)?t.devices:[]).map(eX)}},sessions:{list:async(e={})=>await o(e),close:async(t={})=>{let r=eQ(e.session,t.session),o=(await n("close",[],t)).shutdown;return{session:r,shutdown:"object"==typeof o&&null!==o?o:void 0,identifiers:{session:r}}}},simulators:{ensure:async e=>{let{runtime:t,...r}=e,o=await n("ensure-simulator",[],{...r,simulatorRuntimeId:t}),a=eL(o,"udid"),i=eL(o,"device");return{udid:a,device:i,runtime:eL(o,"runtime"),created:!0===o.created,booted:!0===o.booted,iosSimulatorDeviceSet:eF(o,"ios_simulator_device_set"),identifiers:{deviceId:a,deviceName:i,udid:a}}}},apps:{install:async t=>eZ(await n("install",[t.app,t.appPath],t),eQ(e.session,t.session)),reinstall:async t=>eZ(await n("reinstall",[t.app,t.appPath],t),eQ(e.session,t.session)),installFromSource:async t=>(function(e,t){let r=e$(e,"bundleId"),n=e$(e,"packageName"),o=r??n??e$(e,"appId"),a=e$(e,"launchTarget")??n??r??o;if(!a)throw new w("COMMAND_FAILED",'Daemon response is missing "launchTarget".',{response:e});return{appName:e$(e,"appName"),appId:o,bundleId:r,packageName:n,launchTarget:a,installablePath:e$(e,"installablePath"),archivePath:e$(e,"archivePath"),materializationId:e$(e,"materializationId"),materializationExpiresAt:e$(e,"materializationExpiresAt"),identifiers:eU({session:t,bundleId:r,packageName:n,appId:o})}})(await n("install_source",[],{...t,installSource:t.source,retainMaterializedPaths:t.retainPaths,materializedPathRetentionMs:t.retentionMs}),eQ(e.session,t.session)),open:async t=>{let r=eQ(e.session,t.session),o=t.url?[t.app,t.url]:[t.app],a=await n("open",o,t),i=function(e){let t=e.platform,r=e$(e,"id"),n=e$(e,"device");if("ios"!==t&&"macos"!==t&&"android"!==t||!r||!n)return;let o=eq(e,"target"),a=eO(t,r,n);return{platform:t,target:o,id:r,name:n,identifiers:a,ios:"ios"===t?{udid:e$(e,"device_udid")??r,simulatorSetPath:eF(e,"ios_simulator_device_set")}:void 0,android:"android"===t?{serial:e$(e,"serial")??r}:void 0}}(a),s=e$(a,"appBundleId");return{session:r,appName:e$(a,"appName"),appBundleId:s,appId:s,startup:function(e){if(eW(e)&&"number"==typeof e.durationMs&&"string"==typeof e.measuredAt&&"string"==typeof e.method)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:e$(e,"appTarget"),appBundleId:e$(e,"appBundleId")}}(a.startup),runtime:function(e){if(!eW(e))return;let t=e.platform,r=e$(e,"metroHost"),n="number"==typeof e.metroPort?e.metroPort:void 0;return{platform:"ios"===t||"android"===t?t:void 0,metroHost:r,metroPort:n,bundleUrl:e$(e,"bundleUrl"),launchUrl:e$(e,"launchUrl")}}(a.runtime),device:i,identifiers:{session:r,deviceId:i?.id,deviceName:i?.name,udid:i?.ios?.udid,serial:i?.android?.serial,appId:s,appBundleId:s}}},close:async(t={})=>{let r=eQ(e.session,t.session),o=(await n("close",t.app?[t.app]:[],t)).shutdown;return{session:r,closedApp:t.app,shutdown:"object"==typeof o&&null!==o?o:void 0,identifiers:{session:r}}}},materializations:{release:async e=>{var t;return{released:!0===(t=await n("release_materialized_paths",[],{...e,materializationId:e.materializationId})).released,materializationId:eL(t,"materializationId"),identifiers:{}}}},metro:{prepare:async t=>await ex({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,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(t={})=>{var r;let o=eQ(e.session,t.session),a=await n("snapshot",[],t),i=e$(a,"appBundleId"),s="object"==typeof a.visibility&&null!==a.visibility?a.visibility:void 0;return{nodes:Array.isArray(r=a.nodes)?r:[],truncated:!0===a.truncated,appName:e$(a,"appName"),appBundleId:i,...s?{visibility:s}:{},warnings:Array.isArray(a.warnings)?a.warnings.filter(e=>"string"==typeof e):void 0,identifiers:{session:o,appId:i,appBundleId:i}}},screenshot:async(t={})=>{let r=eQ(e.session,t.session),o=await n("screenshot",t.path?[t.path]:[],t);return{path:eL(o,"path"),overlayRefs:function(e){let t=e.overlayRefs;if(!Array.isArray(t))return;let r=[];for(let e of t){if(!eW(e))continue;let t=e$(e,"ref"),n=eB(e,"rect"),o=eB(e,"overlayRect"),a=function(e,t){let r=e[t];if(!eW(r))return;let n="number"==typeof r.x?r.x:void 0,o="number"==typeof r.y?r.y:void 0;if(void 0!==n&&void 0!==o)return{x:n,y:o}}(e,"center");t&&n&&o&&a&&r.push({ref:t,label:e$(e,"label"),rect:n,overlayRect:o,center:a})}return r}(o),identifiers:{session:r}}}}}}export{e0 as createAgentDeviceClient,w as AppError};
|
|
1
|
+
import e from"node:net";import t from"node:http";import r from"node:https";import o from"node:fs";import n from"node:path";import{fileURLToPath as a}from"node:url";import{spawn as i}from"node:child_process";import s from"node:crypto";import{resolveUserPath as l,createRequestId as d,emitDiagnostic as u,withDiagnosticTimer as c,expandUserHomePath as p,AppError as m}from"./957.js";import{stopProcessForTakeover as f,prepareMetroRuntime as h,runCmdSync as I,isAgentDeviceDaemonProcess as v,runCmdDetached as y}from"./974.js";function w(){let e=n.dirname(a(import.meta.url)),t=e;for(let e=0;e<6;e+=1){let e=n.join(t,"package.json");if(o.existsSync(e))return t;t=n.dirname(t)}return e}function g(e){let t,r=(t=(e??"").trim())?l(t):n.join(p("~"),".agent-device");return{baseDir:r,infoPath:n.join(r,"daemon.json"),lockPath:n.join(r,"daemon.lock"),logPath:n.join(r,"daemon.log"),sessionsDir:n.join(r,"sessions")}}async function A(e){let{localPath:a,baseUrl:s,token:l}=e,d=o.statSync(a).isDirectory(),u=n.basename(a),c=new URL("upload",s.endsWith("/")?s:`${s}/`),p="https:"===c.protocol?r:t,f={"x-artifact-type":d?"app-bundle":"file","x-artifact-filename":u,"transfer-encoding":"chunked"};return l&&(f.authorization=`Bearer ${l}`,f["x-agent-device-token"]=l),new Promise((e,t)=>{let r=p.request({protocol:c.protocol,host:c.hostname,port:c.port,method:"POST",path:c.pathname+c.search,headers:f},r=>{let o="";r.setEncoding("utf8"),r.on("data",e=>{o+=e}),r.on("end",()=>{clearTimeout(s);try{let r=JSON.parse(o);if(!r.ok||!r.uploadId)return void t(new m("COMMAND_FAILED",`Upload failed: ${o}`));e(r.uploadId)}catch{t(new m("COMMAND_FAILED",`Invalid upload response: ${o}`))}})}),s=setTimeout(()=>{r.destroy(),t(new m("COMMAND_FAILED","Artifact upload timed out",{timeoutMs:3e5,hint:"The upload to the remote daemon exceeded the 5-minute timeout."}))},3e5);if(r.on("error",e=>{clearTimeout(s),t(new m("COMMAND_FAILED","Failed to upload artifact to remote daemon",{hint:"Verify the remote daemon is reachable and supports artifact uploads."},e))}),d){let e=i("tar",["cf","-","-C",n.dirname(a),n.basename(a)],{stdio:["ignore","pipe","pipe"]});e.stdout.pipe(r),e.on("error",e=>{r.destroy(),t(new m("COMMAND_FAILED","Failed to create tar archive for app bundle",{},e))}),e.on("close",e=>{0!==e&&(r.destroy(),t(new m("COMMAND_FAILED",`tar failed with exit code ${e}`)))})}else{let e=o.createReadStream(a);e.pipe(r),e.on("error",e=>{r.destroy(),t(new m("COMMAND_FAILED","Failed to read local artifact",{},e))})}})}let D=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,b=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,E=[".ts",".tsx",".js",".jsx",".mjs",".cjs"];function P(e,t,r){t.lastIndex=0;let o=null;for(;null!==(o=t.exec(e));){let e=o[1]?.trim();e?.startsWith(".")&&r.add(e)}}function _(e){try{return o.statSync(e).isFile()?e:null}catch{return null}}let S=es(),T=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}(),M=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}(),k=["xcodebuild .*AgentDeviceRunnerUITests/RunnerTests/testCommand","xcodebuild .*AgentDeviceRunner\\.env\\.session-","xcodebuild build-for-testing .*ios-runner/AgentDeviceRunner/AgentDeviceRunner\\.xcodeproj"],N=new e.BlockList;async function U(t){let r=t.meta?.requestId??d(),o=!!(t.meta?.debug||t.flags?.verbose),n=function(t){let r,o,n,a=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 m("INVALID_ARGS","Invalid daemon base URL",{daemonBaseUrl:e},t instanceof Error?t:void 0)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new m("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,d=s;if(!(!l||"localhost"===(r=new URL(l).hostname.trim().toLowerCase().replace(/^\[(.*)\]$/,"$1"))||(e.isIPv4(r)?N.check(r,"ipv4"):!!e.isIPv6(r)&&N.check(r,"ipv6")))&&("string"!=typeof d||!(d.trim().length>0)))throw new m("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 u=t.flags?.daemonTransport??process.env.AGENT_DEVICE_DAEMON_TRANSPORT,c="auto"===(o=(u??"").trim().toLowerCase())?"auto":"socket"===o?"socket":"http"===o?"http":"auto";if(i&&"socket"===c)throw new m("INVALID_ARGS","Remote daemon base URL only supports HTTP transport. Remove --daemon-transport socket.",{daemonBaseUrl:i});let p="http"===(n=(t.flags?.daemonServerMode??process.env.AGENT_DEVICE_DAEMON_SERVER_MODE??("dual"===u?"dual":void 0)??"").trim().toLowerCase())?"http":"dual"===n?"dual":"socket";return{paths:g(a),transportPreference:c,serverMode:p,remoteBaseUrl:i,remoteAuthToken:s}}(t),a=function(e,t=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if("test"!==e)return es(t)}(t.command),i=await c("daemon_startup",async()=>await x(n),{requestId:r,session:t.session}),s=await R(t,i),l={...t,positionals:s.positionals,flags:s.flags,token:i.token,meta:{...t.meta??{},requestId:r,debug:o,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:r,command:t.command,session:t.session}}),await c("daemon_request",async()=>await Q(i,l,n.transportPreference,a),{requestId:r,command:t.command})}async function R(e,t){let r,a=[...e.positionals??[]],i=e.flags?{...e.flags}:void 0,s=e.meta?.installSource,l={};if(eo(t)){let o=function(e,t){if("screenshot"===e.command){let r=O(e,"path",".png");return t[0]?{field:"path",localPath:r,positionalIndex:0,positionalPath:L("screenshot",".png")}:{field:"path",localPath:r,positionalIndex:0,flagPath:L("screenshot",".png")}}if("record"===e.command&&"start"===(t[0]??"").toLowerCase()){let t=O(e,"outPath",".mp4",1);return{field:"outPath",localPath:t,positionalIndex:1,positionalPath:L("recording",n.extname(t)||".mp4")}}return null}(e,a);o&&(void 0!==o.positionalPath&&(a[o.positionalIndex]=o.positionalPath),void 0!==o.flagPath&&((i??={}).out=o.flagPath),l[o.field]=o.localPath);let d=await C(e,t);d&&(s=d.installSource,r=d.uploadedArtifactId??r)}if(!eo(t)||"install"!==e.command&&"reinstall"!==e.command||a.length<2)return{positionals:a,flags:i,installSource:s,uploadedArtifactId:r,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let d=a[1];if(d.startsWith("remote:"))return a[1]=d.slice(7),{positionals:a,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}};let u=n.isAbsolute(d)?d:n.resolve(e.meta?.cwd??process.cwd(),d);return o.existsSync(u)?{positionals:a,flags:i,installSource:s,uploadedArtifactId:r=await A({localPath:u,baseUrl:t.baseUrl,token:t.token}),...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}:{positionals:a,flags:i,...Object.keys(l).length>0?{clientArtifactPaths:l}:{}}}async function C(e,t){let r=e.meta?.installSource;if("install_source"!==e.command||!r||"path"!==r.kind)return null;let a=r.path.trim();if(!a)return{installSource:r};if(a.startsWith("remote:"))return{installSource:{...r,path:a.slice(7)}};let i=n.isAbsolute(a)?a:n.resolve(e.meta?.cwd??process.cwd(),a);if(!o.existsSync(i))return{installSource:{...r,path:i}};let s=await A({localPath:i,baseUrl:t.baseUrl,token:t.token});return{installSource:{...r,path:i},uploadedArtifactId:s}}function O(e,t,r,o=0){let a=e.positionals?.[o]??e.flags?.out,i=`${"path"===t?"screenshot":"recording"}-${Date.now()}${r}`,s=a&&a.trim().length>0?a:i;return n.isAbsolute(s)?s:n.resolve(e.meta?.cwd??process.cwd(),s)}function L(e,t){let r=t.startsWith(".")?t:`.${t}`;return n.posix.join("/tmp",`agent-device-${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}${r}`)}async function x(e){let t;if(e.remoteBaseUrl){let t={transport:"http",token:e.remoteAuthToken??"",pid:0,baseUrl:e.remoteBaseUrl};if(await K(t,"http"))return t;throw new m("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 r=B(e.paths.infoPath),a=function(){try{let e=w();return JSON.parse(o.readFileSync(n.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}(),i=function(e,t=w()){try{let r=n.resolve(t),a=[n.resolve(e)],i=new Set,l=[];for(;a.length>0;){let e=a.pop();if(!e||i.has(e))continue;i.add(e);let t=o.statSync(e);if(!t.isFile())continue;let s=n.relative(r,e)||e;l.push(`${s}:${t.size}:${Math.trunc(t.mtimeMs)}`);let d=o.readFileSync(e,"utf8");for(let t of function(e){let t=new Set;return P(e,D,t),P(e,b,t),[...t]}(d)){let r=function(e,t){let r=n.resolve(n.dirname(e),t),o=_(r);if(o)return o;for(let e of E){let t=_(`${r}${e}`);if(t)return t}for(let e of E){let t=_(n.join(r,`index${e}`));if(t)return t}return null}(e,t);r&&a.push(r)}}let d=l.sort().join("|"),u=s.createHash("sha1").update(d).digest("hex");return`graph:${l.length}:${u}`}catch{return"unknown"}}((t=J()).useSrc?t.srcPath:t.distPath,t.root),l=!!r&&await K(r,e.transportPreference);if(r&&r.version===a&&r.codeSignature===i&&l)return r;r&&(r.version!==a||r.codeSignature!==i||!l)&&(await q(r),H(e.paths.infoPath)),function(e){let t=V(e);if(!t.hasLock||t.hasInfo)return;let r=G(e.lockPath);if(!r)return H(e.lockPath);v(r.pid,r.processStartTime)||H(e.lockPath)}(e.paths);let d=0;for(let t=1;t<=M;t+=1){await W(e);let r=await F(T,e);if(r)return r;if(await j(e.paths)){d+=1;continue}let o=V(e.paths);if(!(t<M))break;if(!o.hasInfo&&!o.hasLock){await $(150);continue}}let u=V(e.paths);throw new m("COMMAND_FAILED","Failed to start daemon",{kind:"daemon_startup_failed",infoPath:e.paths.infoPath,lockPath:e.paths.lockPath,startupTimeoutMs:T,startupAttempts:M,lockRecoveryCount:d,metadataState:u,hint:function(e,t=g(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.`}(u,e.paths)})}async function F(e,t){let r=Date.now();for(;Date.now()-r<e;){let e=B(t.paths.infoPath);if(e&&await K(e,t.transportPreference))return e;await new Promise(e=>setTimeout(e,100))}return null}async function $(e){await new Promise(t=>setTimeout(t,e))}async function j(e){let t=V(e);if(!t.hasLock||t.hasInfo)return!1;let r=G(e.lockPath);return r&&v(r.pid,r.processStartTime)&&await f(r.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:r.processStartTime}),H(e.lockPath),!0}async function q(e){await f(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}function B(e){let t=z(e);if(!t||"object"!=typeof t)return null;let r="string"==typeof t.token&&t.token.length>0?t.token:null;if(!r)return null;let o=Number.isInteger(t.port)&&Number(t.port)>0,n=Number.isInteger(t.httpPort)&&Number(t.httpPort)>0;if(!o&&!n)return null;let a=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,d=Number.isInteger(t.pid)&&Number(t.pid)>0;return{token:r,port:o?Number(t.port):void 0,httpPort:n?Number(t.httpPort):void 0,transport:"socket"===a||"http"===a||"dual"===a?a:void 0,pid:d?Number(t.pid):0,version:i,codeSignature:s,processStartTime:l}}function G(e){let t=z(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}N.addSubnet("127.0.0.0",8,"ipv4"),N.addAddress("::1","ipv6"),N.addSubnet("::ffff:127.0.0.0",104,"ipv6");function V(e){return{hasInfo:o.existsSync(e.infoPath),hasLock:o.existsSync(e.lockPath)}}function z(e){if(!o.existsSync(e))return null;try{return JSON.parse(o.readFileSync(e,"utf8"))}catch{return null}}function H(e){try{o.existsSync(e)&&o.unlinkSync(e)}catch{}}async function K(o,n){var a;return"http"===X(o,n)?await function(e){let o=e.baseUrl?en(e.baseUrl,"health"):e.httpPort?`http://127.0.0.1:${e.httpPort}/health`:null;if(!o)return Promise.resolve(!1);let n=new URL(o),a="https:"===n.protocol?r:t,i=e.baseUrl?3e3:500;return new Promise(e=>{let t=a.request({protocol:n.protocol,host:n.hostname,port:n.port,path:n.pathname+n.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()})}(o):await ((a=o.port)?new Promise(t=>{let r=e.createConnection({host:"127.0.0.1",port:a},()=>{r.destroy(),t(!0)});r.on("error",()=>{t(!1)})}):Promise.resolve(!1))}async function W(e){let t=J(),r=t.useSrc?["--experimental-strip-types",t.srcPath]:[t.distPath],o={...process.env,AGENT_DEVICE_STATE_DIR:e.paths.baseDir,AGENT_DEVICE_DAEMON_SERVER_MODE:e.serverMode};y(process.execPath,r,{env:o})}function J(){let e=w(),t=n.join(e,"dist","src","daemon.js"),r=n.join(e,"src","daemon.ts"),a=o.existsSync(t),i=o.existsSync(r);if(!a&&!i)throw new m("COMMAND_FAILED","Daemon entry not found",{distPath:t,srcPath:r});return{root:e,distPath:t,srcPath:r,useSrc:process.execArgv.includes("--experimental-strip-types")?i:!a&&i}}async function Q(e,t,r,o){return"http"===X(e,r)?await er(e,t,o):await et(e,t,o)}function X(e,t){if(e.baseUrl){if("socket"===t)throw new m("COMMAND_FAILED","Remote daemon endpoint only supports HTTP transport",{daemonBaseUrl:e.baseUrl});return"http"}if("http"===t||"socket"===t){var r=e,o=t;if(Y(r,o))return o;throw new m("COMMAND_FAILED","http"===o?"Daemon HTTP endpoint is unavailable":"Daemon socket endpoint is unavailable")}let n=("socket"===e.transport||"dual"===e.transport?["socket","http"]:["http","socket"]).find(t=>Y(e,t));if(n)return n;throw new m("COMMAND_FAILED","Daemon metadata has no reachable transport")}function Y(e,t){return"http"===t?!!e.httpPort:!!e.port}function Z(e,t,r,o,n,a){let i=n?{terminated:0}:function(){let e=0;try{for(let t of k){let r=I("pkill",["-f",t],{allowFailure:!0});0===r.exitCode&&(e+=1)}return{terminated:e}}catch(t){return{terminated:e,error:t instanceof Error?t.message:String(t)}}}(),s=n?{forcedKill:!1}:function(e,t){let r=!1;try{v(e.pid,e.processStartTime)&&(process.kill(e.pid,"SIGKILL"),r=!0)}catch{f(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}finally{H(t.infoPath),H(t.lockPath)}return{forcedKill:r}}(e,t);return u({level:"error",phase:"daemon_request_timeout",data:{timeoutMs:a,requestId:r,command:o,timedOutRunnerPidsTerminated:i.terminated,timedOutRunnerCleanupError:i.error,daemonPidReset:n?void 0:e.pid,daemonPidForceKilled:n?void 0:s.forcedKill,daemonBaseUrl:e.baseUrl}}),new m("COMMAND_FAILED","Daemon request timed out",{timeoutMs:a,requestId:r,hint:n?"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 ee(e,t,r){return u({level:"error",phase:"daemon_request_socket_error",data:{requestId:t,message:e instanceof Error?e.message:String(e)}}),new m("COMMAND_FAILED","Failed to communicate with daemon",{requestId:t,hint:r?"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 et(t,r,o){let n=t.port;if(!n)throw new m("COMMAND_FAILED","Daemon socket endpoint is unavailable");return new Promise((a,i)=>{let s=e.createConnection({host:"127.0.0.1",port:n},()=>{s.write(`${JSON.stringify(r)}
|
|
2
|
+
`)}),l=g(r.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),d="number"==typeof o?setTimeout(()=>{s.destroy(),i(Z(t,l,r.meta?.requestId,r.command,!1,o))},o):void 0,u="";s.setEncoding("utf8"),s.on("data",e=>{let t=(u+=e).indexOf("\n");if(-1===t)return;let o=u.slice(0,t).trim();if(o)try{let e=JSON.parse(o);s.end(),d&&clearTimeout(d),a(e)}catch(e){d&&clearTimeout(d),i(new m("COMMAND_FAILED","Invalid daemon response",{requestId:r.meta?.requestId,line:o},e instanceof Error?e:void 0))}}),s.on("error",e=>{d&&clearTimeout(d),i(ee(e,r.meta?.requestId,!1))})})}async function er(e,o,n){let a=e.baseUrl?new URL(en(e.baseUrl,"rpc")):e.httpPort?new URL(`http://127.0.0.1:${e.httpPort}/rpc`):null;if(!a)throw new m("COMMAND_FAILED","Daemon HTTP endpoint is unavailable");let i=JSON.stringify({jsonrpc:"2.0",id:o.meta?.requestId??d(),method:"agent_device.command",params:o}),s={"content-type":"application/json","content-length":Buffer.byteLength(i)};return e.baseUrl&&e.token&&(s.authorization=`Bearer ${e.token}`,s["x-agent-device-token"]=e.token),await new Promise((l,d)=>{let u=g(o.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),c=("https:"===a.protocol?r:t).request({protocol:a.protocol,host:a.hostname,port:a.port,method:"POST",path:a.pathname+a.search,headers:s},t=>{let r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{f&&clearTimeout(f);try{let t=JSON.parse(r);if(t.error){let e=t.error.data??{};d(new m(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:o.meta?.requestId}));return}if(!t.result||"object"!=typeof t.result)return void d(new m("COMMAND_FAILED","Invalid daemon RPC response",{requestId:o.meta?.requestId}));if(e.baseUrl&&t.result.ok)return void ea(e,o,t.result).then(l).catch(d);l(t.result)}catch(e){f&&clearTimeout(f),d(new m("COMMAND_FAILED","Invalid daemon response",{requestId:o.meta?.requestId,line:r},e instanceof Error?e:void 0))}})}),p=eo(e),f="number"==typeof n?setTimeout(()=>{c.destroy(),d(Z(e,u,o.meta?.requestId,o.command,p,n))},n):void 0;c.on("error",e=>{f&&clearTimeout(f),d(ee(e,o.meta?.requestId,p))}),c.write(i),c.end()})}function eo(e){return"string"==typeof e.baseUrl&&e.baseUrl.length>0}function en(e,t){return new URL(t,e.endsWith("/")?e:`${e}/`).toString()}async function ea(e,t,r){let o=Array.isArray(r.data?.artifacts)?r.data.artifacts:[];if(0===o.length||!e.baseUrl)return r;let a=r.data?{...r.data}:{},i=[];for(let r of o){if(!r||"object"!=typeof r||"string"!=typeof r.artifactId){i.push(r);continue}let o=function(e,t){if(e.localPath&&e.localPath.trim().length>0)return e.localPath;let r=e.fileName?.trim()||`${e.field}-${Date.now()}`;return n.resolve(t.meta?.cwd??process.cwd(),r)}(r,t);await ei({baseUrl:e.baseUrl,token:e.token,artifactId:r.artifactId,destinationPath:o,requestId:t.meta?.requestId}),a[r.field]=o,i.push({...r,localPath:o})}return a.artifacts=i,{ok:!0,data:a}}async function ei(e){var a,i;let s,l=new URL((a=e.baseUrl,i=e.artifactId,s=a.endsWith("/")?a:`${a}/`,new URL(`upload/${encodeURIComponent(i)}`,s).toString())),d="https:"===l.protocol?r:t;await o.promises.mkdir(n.dirname(e.destinationPath),{recursive:!0}),await new Promise((t,r)=>{let n=!1,a=e.timeoutMs??S,i=a=>{if(!n){if(n=!0,clearTimeout(u),a)return void o.promises.rm(e.destinationPath,{force:!0}).finally(()=>r(a));t()}},s=d.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 r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{i(new m("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,statusCode:t.statusCode,requestId:e.requestId,body:r}))});return}let r=o.createWriteStream(e.destinationPath);r.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 m("COMMAND_FAILED","Remote artifact download was interrupted",{artifactId:e.artifactId,requestId:e.requestId}))}),r.on("finish",()=>{r.close(()=>i())}),t.pipe(r)}),u=setTimeout(()=>{s.destroy(new m("COMMAND_FAILED","Remote artifact download timed out",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:a}))},a);s.on("error",t=>{t instanceof m?i(t):i(new m("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:a},t instanceof Error?t:void 0))}),s.end()})}function es(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}function el(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function ed(e,t,r){return{deviceId:t,deviceName:r,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function eu(e,t,r,o){let n=r(e[t]);if(void 0===n)throw new m("COMMAND_FAILED",o,{response:e});return n}function ec(e,t){return eu(e,t,ev,`Daemon response is missing "${t}".`)}function ep(e,t){return ev(e[t])}function em(e,t){var r;let o;return r=ev,null===(o=e[t])?null:r(o)}function ef(e,t){return eu(e,t,ew,`Daemon response has invalid "${t}".`)}function eh(e,t){return function(e){return"tv"===e||"mobile"===e||"desktop"===e?e:void 0}(e[t])??"mobile"}function eI(e,t){let r=e[t];if(!eD(r))return;let o="number"==typeof r.x?r.x:void 0,n="number"==typeof r.y?r.y:void 0,a="number"==typeof r.width?r.width:void 0,i="number"==typeof r.height?r.height:void 0;if(void 0!==o&&void 0!==n&&void 0!==a&&void 0!==i)return{x:o,y:n,width:a,height:i}}function ev(e){return"string"==typeof e&&e.length>0?e:void 0}function ey(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function ew(e){return"ios"===e||"macos"===e||"android"===e?e:void 0}function eg(e){return"simulator"===e||"emulator"===e||"device"===e?e:void 0}function eA(e){if(!eD(e))throw new m("COMMAND_FAILED","Daemon returned an unexpected response shape.",{value:e});return e}function eD(e){return"object"==typeof e&&null!==e}function eb(e){let t={};for(let[r,o]of Object.entries(e))void 0!==o&&(t[r]=o);return t}function eE(e,t){let r=ep(e,"bundleId"),o=ep(e,"package");return{app:ec(e,"app"),appPath:ec(e,"appPath"),platform:ef(e,"platform"),appId:r??o,bundleId:r,package:o,identifiers:el({session:t,bundleId:r,packageName:o})}}function eP(e){let t=eA(e),r=ef(t,"platform"),o=ec(t,"id"),n=ec(t,"name");return{platform:r,target:eh(t,"target"),kind:eu(t,"kind",eg,'Daemon response has invalid "kind".'),id:o,name:n,booted:"boolean"==typeof t.booted?t.booted:void 0,identifiers:ed(r,o,n),ios:"ios"===r?{udid:o}:void 0,android:"android"===r?{serial:o}:void 0}}function e_(e){let t=eA(e),r=ef(t,"platform"),o=ec(t,"id"),n=ec(t,"name"),a=eh(t,"target"),i=ec(t,"device"),s={session:n,...ed(r,o,i)};return{name:n,createdAt:eu(t,"createdAt",ey,'Daemon response is missing numeric "createdAt".'),device:{platform:r,target:a,id:o,name:i,identifiers:s,ios:"ios"===r?{udid:o,simulatorSetPath:em(t,"ios_simulator_device_set")}:void 0,android:"android"===r?{serial:o}:void 0},identifiers:s}}function eS(e,t){return t??e??"default"}function eT(e={},t={}){let r=t.transport??U,o=async(t,o=[],n={})=>{let a={...e,...n},i=await r({session:eS(e.session,n.session),command:t,positionals:o,flags:eb({stateDir:a.stateDir,daemonBaseUrl:a.daemonBaseUrl,daemonAuthToken:a.daemonAuthToken,daemonTransport:a.daemonTransport,daemonServerMode:a.daemonServerMode,tenant:a.tenant,sessionIsolation:a.sessionIsolation,runId:a.runId,leaseId:a.leaseId,platform:a.platform,target:a.target,device:a.device,udid:a.udid,serial:a.serial,iosSimulatorDeviceSet:a.iosSimulatorDeviceSet,androidDeviceAllowlist:a.androidDeviceAllowlist,runtime:a.simulatorRuntimeId,boot:a.boot,reuseExisting:a.reuseExisting,surface:a.surface,activity:a.activity,relaunch:a.relaunch,shutdown:a.shutdown,saveScript:a.saveScript,noRecord:a.noRecord,metroHost:a.metroHost,metroPort:a.metroPort,bundleUrl:a.bundleUrl,launchUrl:a.launchUrl,snapshotInteractiveOnly:a.interactiveOnly,snapshotCompact:a.compact,snapshotDepth:a.depth,snapshotScope:a.scope,snapshotRaw:a.raw,overlayRefs:a.overlayRefs,verbose:a.debug}),runtime:a.runtime,meta:eb({requestId:a.requestId,cwd:a.cwd,debug:a.debug,lockPolicy:a.lockPolicy,lockPlatform:a.lockPlatform,tenantId:a.tenant,runId:a.runId,leaseId:a.leaseId,sessionIsolation:a.sessionIsolation,installSource:a.installSource,retainMaterializedPaths:a.retainMaterializedPaths,materializedPathRetentionMs:a.materializedPathRetentionMs,materializationId:a.materializationId})});if(!i.ok)throw new m(i.error.code,i.error.message,{...i.error.details??{},hint:i.error.hint,diagnosticId:i.error.diagnosticId,logPath:i.error.logPath});return i.data??{}},n=async(e={})=>{let t=await o("session_list",[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(e_)};return{devices:{list:async(e={})=>{let t=await o("devices",[],e);return(Array.isArray(t.devices)?t.devices:[]).map(eP)}},sessions:{list:async(e={})=>await n(e),close:async(t={})=>{let r=eS(e.session,t.session),n=(await o("close",[],t)).shutdown;return{session:r,shutdown:"object"==typeof n&&null!==n?n:void 0,identifiers:{session:r}}}},simulators:{ensure:async e=>{let{runtime:t,...r}=e,n=await o("ensure-simulator",[],{...r,simulatorRuntimeId:t}),a=ec(n,"udid"),i=ec(n,"device");return{udid:a,device:i,runtime:ec(n,"runtime"),created:!0===n.created,booted:!0===n.booted,iosSimulatorDeviceSet:em(n,"ios_simulator_device_set"),identifiers:{deviceId:a,deviceName:i,udid:a}}}},apps:{install:async t=>eE(await o("install",[t.app,t.appPath],t),eS(e.session,t.session)),reinstall:async t=>eE(await o("reinstall",[t.app,t.appPath],t),eS(e.session,t.session)),installFromSource:async t=>(function(e,t){let r=ep(e,"bundleId"),o=ep(e,"packageName"),n=r??o??ep(e,"appId"),a=ep(e,"launchTarget")??o??r??n;if(!a)throw new m("COMMAND_FAILED",'Daemon response is missing "launchTarget".',{response:e});return{appName:ep(e,"appName"),appId:n,bundleId:r,packageName:o,launchTarget:a,installablePath:ep(e,"installablePath"),archivePath:ep(e,"archivePath"),materializationId:ep(e,"materializationId"),materializationExpiresAt:ep(e,"materializationExpiresAt"),identifiers:el({session:t,bundleId:r,packageName:o,appId:n})}})(await o("install_source",[],{...t,installSource:t.source,retainMaterializedPaths:t.retainPaths,materializedPathRetentionMs:t.retentionMs}),eS(e.session,t.session)),open:async t=>{let r=eS(e.session,t.session),n=t.url?[t.app,t.url]:[t.app],a=await o("open",n,t),i=function(e){let t=e.platform,r=ep(e,"id"),o=ep(e,"device");if("ios"!==t&&"macos"!==t&&"android"!==t||!r||!o)return;let n=eh(e,"target"),a=ed(t,r,o);return{platform:t,target:n,id:r,name:o,identifiers:a,ios:"ios"===t?{udid:ep(e,"device_udid")??r,simulatorSetPath:em(e,"ios_simulator_device_set")}:void 0,android:"android"===t?{serial:ep(e,"serial")??r}:void 0}}(a),s=ep(a,"appBundleId");return{session:r,appName:ep(a,"appName"),appBundleId:s,appId:s,startup:function(e){if(eD(e)&&"number"==typeof e.durationMs&&"string"==typeof e.measuredAt&&"string"==typeof e.method)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:ep(e,"appTarget"),appBundleId:ep(e,"appBundleId")}}(a.startup),runtime:function(e){if(!eD(e))return;let t=e.platform,r=ep(e,"metroHost"),o="number"==typeof e.metroPort?e.metroPort:void 0;return{platform:"ios"===t||"android"===t?t:void 0,metroHost:r,metroPort:o,bundleUrl:ep(e,"bundleUrl"),launchUrl:ep(e,"launchUrl")}}(a.runtime),device:i,identifiers:{session:r,deviceId:i?.id,deviceName:i?.name,udid:i?.ios?.udid,serial:i?.android?.serial,appId:s,appBundleId:s}}},close:async(t={})=>{let r=eS(e.session,t.session),n=(await o("close",t.app?[t.app]:[],t)).shutdown;return{session:r,closedApp:t.app,shutdown:"object"==typeof n&&null!==n?n:void 0,identifiers:{session:r}}}},materializations:{release:async e=>{var t;return{released:!0===(t=await o("release_materialized_paths",[],{...e,materializationId:e.materializationId})).released,materializationId:ec(t,"materializationId"),identifiers:{}}}},metro:{prepare:async t=>await h({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,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(t={})=>{var r;let n=eS(e.session,t.session),a=await o("snapshot",[],t),i=ep(a,"appBundleId"),s="object"==typeof a.visibility&&null!==a.visibility?a.visibility:void 0;return{nodes:Array.isArray(r=a.nodes)?r:[],truncated:!0===a.truncated,appName:ep(a,"appName"),appBundleId:i,...s?{visibility:s}:{},warnings:Array.isArray(a.warnings)?a.warnings.filter(e=>"string"==typeof e):void 0,identifiers:{session:n,appId:i,appBundleId:i}}},screenshot:async(t={})=>{let r=eS(e.session,t.session),n=await o("screenshot",t.path?[t.path]:[],t);return{path:ec(n,"path"),overlayRefs:function(e){let t=e.overlayRefs;if(!Array.isArray(t))return;let r=[];for(let e of t){if(!eD(e))continue;let t=ep(e,"ref"),o=eI(e,"rect"),n=eI(e,"overlayRect"),a=function(e,t){let r=e[t];if(!eD(r))return;let o="number"==typeof r.x?r.x:void 0,n="number"==typeof r.y?r.y:void 0;if(void 0!==o&&void 0!==n)return{x:o,y:n}}(e,"center");t&&o&&n&&a&&r.push({ref:t,label:ep(e,"label"),rect:o,overlayRect:n,center:a})}return r}(n),identifiers:{session:r}}}}}}export{AppError}from"./957.js";export{eT as createAgentDeviceClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setTimeout as e}from"node:timers/promises";import{normalizeBaseUrl as r,METRO_COMPANION_RUN_ARG as t,ENV_LAUNCH_URL as a,ENV_BEARER_TOKEN as s,ENV_SERVER_BASE_URL as n,ENV_LOCAL_BASE_URL as o}from"./320.js";async function i(e){var t,a;let s=await fetch(`${r(e.serverBaseUrl)}/api/metro/companion/register`,{method:"POST",headers:(t=e.serverBaseUrl,a=e.bearerToken,{authorization:`Bearer ${a}`,"content-type":"application/json",...t.includes("ngrok")?{"ngrok-skip-browser-warning":"1"}:{}}),body:JSON.stringify({local_base_url:r(e.localBaseUrl),...e.launchUrl?{launch_url:e.launchUrl}:{}})}),n=await s.json();if(!s.ok||!0!==n.ok||"string"!=typeof n.data?.ws_url)throw Error(`Failed to register Metro companion: ${JSON.stringify(n)}`);return{wsUrl:n.data.ws_url}}async function c(e){return"string"==typeof e?Buffer.from(e,"utf8"):e instanceof ArrayBuffer?Buffer.from(e):ArrayBuffer.isView(e)?Buffer.from(e.buffer,e.byteOffset,e.byteLength):"u">typeof Blob&&e instanceof Blob?Buffer.from(await e.arrayBuffer()):Buffer.from(String(e),"utf8")}async function f(e){return JSON.parse((await c(e.data)).toString("utf8"))}function d(e,r){1===e.readyState&&e.send(JSON.stringify(r))}async function l(e,r){1!==e.readyState&&await new Promise((t,a)=>{let s=()=>{i(),t()},n=()=>{i(),a(Error(`${r} WebSocket failed before opening.`))},o=()=>{i(),a(Error(`${r} WebSocket closed before opening.`))},i=()=>{e.removeEventListener("open",s),e.removeEventListener("error",n),e.removeEventListener("close",o)};e.addEventListener("open",s,{once:!0}),e.addEventListener("error",n,{once:!0}),e.addEventListener("close",o,{once:!0})})}async function u(e){e.readyState>=WebSocket.CLOSING||await new Promise(r=>{let t=()=>{a(),r()},a=()=>{e.removeEventListener("close",t),e.removeEventListener("error",t)};e.addEventListener("close",t,{once:!0}),e.addEventListener("error",t,{once:!0}),e.readyState>=WebSocket.CLOSING&&t()})}function m(e,r,t){try{e.close(r,t)}catch{}}async function p(e,t,a,s){var n,o;switch(t.type){case"ping":return void d(e,{type:"pong",timestamp:t.timestamp});case"http-request":try{let s=await fetch(new URL(t.path,`${r(a.localBaseUrl)}/`),{method:t.method,headers:t.headers,...t.bodyBase64?{body:Buffer.from(t.bodyBase64,"base64")}:{}}),n=Buffer.from(await s.arrayBuffer());d(e,{type:"http-response",requestId:t.requestId,status:s.status,headers:Object.fromEntries(s.headers.entries()),...n.length>0?{bodyBase64:n.toString("base64")}:{}})}catch(r){d(e,{type:"http-error",requestId:t.requestId,message:r instanceof Error?r.message:String(r)})}return;case"ws-open":{let o,i=new WebSocket((n=a.localBaseUrl,(o=new URL(t.path,`${r(n)}/`)).protocol="https:"===o.protocol?"wss:":"ws:",o.toString()));i.binaryType="arraybuffer";let f=!1;i.addEventListener("message",r=>{(async()=>{if(!f)return;let a=await c(r.data);d(e,{type:"ws-frame",streamId:t.streamId,dataBase64:a.toString("base64"),binary:"string"!=typeof r.data})})().catch(e=>{console.error(e instanceof Error?e.message:String(e))})}),i.addEventListener("close",r=>{s.delete(t.streamId),f&&d(e,{type:"ws-close",streamId:t.streamId,code:r.code,reason:r.reason})}),i.addEventListener("error",()=>{f&&d(e,{type:"ws-close",streamId:t.streamId,code:1011,reason:"Upstream WebSocket error."})}),s.set(t.streamId,i);try{await l(i,"Upstream"),f=!0,d(e,{type:"ws-open-result",streamId:t.streamId,success:!0,headers:{}})}catch(r){s.delete(t.streamId),m(i,1011,"open failed"),d(e,{type:"ws-open-result",streamId:t.streamId,success:!1,error:r instanceof Error?r.message:String(r)})}return}case"ws-frame":{let e=s.get(t.streamId);if(!e||1!==e.readyState)return;let r=Buffer.from(t.dataBase64,"base64");e.send(t.binary?r:r.toString("utf8"));return}case"ws-close":{let e=s.get(t.streamId);if(!e)return;s.delete(t.streamId),m(e,"number"==typeof(o=t.code)&&Number.isInteger(o)&&(1e3===o||o>=3e3&&o<=4999||o>=1001&&o<=1015&&1004!==o&&1005!==o&&1006!==o)?o:1011,t.reason??"bridge requested close");return}}}async function y(r){let t=new Map;for(;;){try{let e=await i(r),a=new WebSocket(e.wsUrl);a.binaryType="arraybuffer",await l(a,"Bridge"),a.addEventListener("message",e=>{(async()=>{let s=await f(e);await p(a,s,r,t)})().catch(e=>{console.error(e instanceof Error?e.message:String(e))})}),await u(a),t.forEach(e=>m(e,1012,"bridge disconnected")),t.clear()}catch(e){console.error(e instanceof Error?e.message:String(e))}await e(1e3)}}(async function(e,r){let i=function(e,r){if(e[0]!==t)return null;let i=r[n]?.trim(),c=r[s]?.trim(),f=r[o]?.trim();if(!i||!c||!f)throw Error("Metro companion worker is missing required environment configuration.");return{serverBaseUrl:i,bearerToken:c,localBaseUrl:f,launchUrl:r[a]?.trim()||void 0}}(e,r);return!!i&&(await y(i),!0)})(process.argv.slice(2),process.env).catch(e=>{if(e instanceof Error&&e.message.includes("missing required environment")){console.error(e.message),process.exitCode=1;return}console.error(e instanceof Error?e.stack??e.message:String(e)),process.exitCode=1});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export declare function buildAndroidRuntimeHints(baseUrl: string): MetroRuntimeHints;
|
|
2
|
+
|
|
3
|
+
export declare function buildIosRuntimeHints(baseUrl: string): MetroRuntimeHints;
|
|
4
|
+
|
|
5
|
+
export declare function ensureMetroTunnel(options: EnsureMetroTunnelOptions): Promise<EnsureMetroTunnelResult>;
|
|
6
|
+
|
|
7
|
+
export declare type EnsureMetroTunnelOptions = {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
serverBaseUrl: string;
|
|
10
|
+
bearerToken: string;
|
|
11
|
+
localBaseUrl: string;
|
|
12
|
+
launchUrl?: string;
|
|
13
|
+
profileKey?: string;
|
|
14
|
+
consumerKey?: string;
|
|
15
|
+
env?: EnvSource;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export declare type EnsureMetroTunnelResult = {
|
|
19
|
+
pid: number;
|
|
20
|
+
started: boolean;
|
|
21
|
+
logPath: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare type EnvSource = NodeJS.ProcessEnv | Record<string, string | undefined>;
|
|
25
|
+
|
|
26
|
+
export declare type MetroBridgeResult = {
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
statusUrl: string;
|
|
30
|
+
bundleUrl: string;
|
|
31
|
+
iosRuntime: MetroRuntimeHints;
|
|
32
|
+
androidRuntime: MetroRuntimeHints;
|
|
33
|
+
upstream: {
|
|
34
|
+
bundleUrl: string;
|
|
35
|
+
host: string;
|
|
36
|
+
port: number;
|
|
37
|
+
statusUrl: string;
|
|
38
|
+
};
|
|
39
|
+
probe: {
|
|
40
|
+
reachable: boolean;
|
|
41
|
+
statusCode: number;
|
|
42
|
+
latencyMs: number;
|
|
43
|
+
detail: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export declare type MetroRuntimeHints = {
|
|
48
|
+
platform?: 'ios' | 'android';
|
|
49
|
+
metroHost?: string;
|
|
50
|
+
metroPort?: number;
|
|
51
|
+
bundleUrl?: string;
|
|
52
|
+
launchUrl?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export declare function prepareRemoteMetro(options: PrepareRemoteMetroOptions): Promise<PrepareRemoteMetroResult>;
|
|
56
|
+
|
|
57
|
+
export declare type PrepareRemoteMetroOptions = {
|
|
58
|
+
projectRoot: string;
|
|
59
|
+
kind: 'auto' | 'react-native' | 'expo';
|
|
60
|
+
publicBaseUrl: string;
|
|
61
|
+
proxyBaseUrl?: string;
|
|
62
|
+
proxyBearerToken?: string;
|
|
63
|
+
launchUrl?: string;
|
|
64
|
+
profileKey?: string;
|
|
65
|
+
consumerKey?: string;
|
|
66
|
+
port?: number;
|
|
67
|
+
listenHost?: string;
|
|
68
|
+
statusHost?: string;
|
|
69
|
+
startupTimeoutMs?: number;
|
|
70
|
+
probeTimeoutMs?: number;
|
|
71
|
+
reuseExisting?: boolean;
|
|
72
|
+
installDependenciesIfNeeded?: boolean;
|
|
73
|
+
runtimeFilePath?: string;
|
|
74
|
+
logPath?: string;
|
|
75
|
+
env?: EnvSource;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export declare type PrepareRemoteMetroResult = {
|
|
79
|
+
iosRuntime: MetroRuntimeHints;
|
|
80
|
+
androidRuntime: MetroRuntimeHints;
|
|
81
|
+
bridge: MetroBridgeResult | null;
|
|
82
|
+
started: boolean;
|
|
83
|
+
reused: boolean;
|
|
84
|
+
logPath: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export declare function stopMetroTunnel(options: StopMetroTunnelOptions): Promise<void>;
|
|
88
|
+
|
|
89
|
+
export declare type StopMetroTunnelOptions = {
|
|
90
|
+
projectRoot: string;
|
|
91
|
+
profileKey?: string;
|
|
92
|
+
consumerKey?: string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{buildMetroRuntimeHints as e,ensureMetroCompanion as t,stopMetroCompanion as n,prepareMetroRuntime as o}from"./974.js";async function r(e){let t=await o({projectRoot:e.projectRoot,kind:e.kind,publicBaseUrl:e.publicBaseUrl,proxyBaseUrl:e.proxyBaseUrl,proxyBearerToken:e.proxyBearerToken,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 i(e){let n=await t(e);return{pid:n.pid,started:n.spawned,logPath:n.logPath}}async function s(e){await n(e)}function a(t){return e(t,"ios")}function u(t){return e(t,"android")}export{u as buildAndroidRuntimeHints,a as buildIosRuntimeHints,i as ensureMetroTunnel,r as prepareRemoteMetro,s as stopMetroTunnel};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare type RemoteConfigProfile = {
|
|
2
|
+
stateDir?: string;
|
|
3
|
+
daemonBaseUrl?: string;
|
|
4
|
+
daemonAuthToken?: string;
|
|
5
|
+
daemonTransport?: 'auto' | 'socket' | 'http';
|
|
6
|
+
daemonServerMode?: 'socket' | 'http' | 'dual';
|
|
7
|
+
tenant?: string;
|
|
8
|
+
sessionIsolation?: 'none' | 'tenant';
|
|
9
|
+
runId?: string;
|
|
10
|
+
leaseId?: string;
|
|
11
|
+
platform?: 'ios' | 'macos' | 'android' | 'linux' | 'apple';
|
|
12
|
+
target?: 'mobile' | 'tv' | 'desktop';
|
|
13
|
+
device?: string;
|
|
14
|
+
udid?: string;
|
|
15
|
+
serial?: string;
|
|
16
|
+
iosSimulatorDeviceSet?: string;
|
|
17
|
+
androidDeviceAllowlist?: string;
|
|
18
|
+
session?: string;
|
|
19
|
+
metroProjectRoot?: string;
|
|
20
|
+
metroKind?: 'auto' | 'react-native' | 'expo';
|
|
21
|
+
metroPublicBaseUrl?: string;
|
|
22
|
+
metroProxyBaseUrl?: string;
|
|
23
|
+
metroBearerToken?: string;
|
|
24
|
+
metroPreparePort?: number;
|
|
25
|
+
metroListenHost?: string;
|
|
26
|
+
metroStatusHost?: string;
|
|
27
|
+
metroStartupTimeoutMs?: number;
|
|
28
|
+
metroProbeTimeoutMs?: number;
|
|
29
|
+
metroRuntimeFile?: string;
|
|
30
|
+
metroNoReuseExisting?: boolean;
|
|
31
|
+
metroNoInstallDeps?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare type RemoteConfigProfileOptions = {
|
|
35
|
+
configPath: string;
|
|
36
|
+
cwd: string;
|
|
37
|
+
env?: Record<string, string | undefined>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export declare type ResolvedRemoteConfigProfile = {
|
|
41
|
+
resolvedPath: string;
|
|
42
|
+
profile: RemoteConfigProfile;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export declare function resolveRemoteConfigPath(options: RemoteConfigProfileOptions): string;
|
|
46
|
+
|
|
47
|
+
export declare function resolveRemoteConfigProfile(options: RemoteConfigProfileOptions): ResolvedRemoteConfigProfile;
|
|
48
|
+
|
|
49
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{resolveUserPath as n,AppError as r}from"./957.js";let o=new Set(["1","true","yes","on"]),i=new Set(["0","false","no","off"]);function a(e,t,n,o){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>a({...e,multiple:!1},t,n,o));if("boolean"===e.type){var i=t,s=n,f=o;if("boolean"==typeof i)return i;if("string"==typeof i){let e=l(i);if(void 0!==e)return e}throw new r("INVALID_ARGS",`Invalid value for "${f}" in ${s}. 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 r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Expected boolean or non-empty string.`)}if("string"===e.type){if("string"==typeof t&&t.trim().length>0)return t;throw new r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Expected non-empty string.`)}if("enum"===e.type){if(void 0!==e.setValue){var u=e,y=t,p=n,m=o;let i=u.setValue;if(y===i)return i;if("string"==typeof y){let e=y.trim();if(""===e||"true"===e||"1"===e)return i;if("false"===e||"0"===e)return}if(!0===y)return i;if(!1!==y)throw new r("INVALID_ARGS",`Invalid value for "${m}" in ${p}. Expected boolean-like value for enum flag.`);return}if("string"!=typeof t||!e.enumValues?.includes(t))throw new r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Expected one of: ${e.enumValues?.join(", ")}.`);return t}let g="number"==typeof t?t:"string"==typeof t?Number(t):NaN;if(!Number.isFinite(g)||!Number.isInteger(g))throw new r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Expected integer.`);if("number"==typeof e.min&&g<e.min)throw new r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Must be >= ${e.min}.`);if("number"==typeof e.max&&g>e.max)throw new r("INVALID_ARGS",`Invalid value for "${o}" in ${n}. Must be <= ${e.max}.`);return g}function l(e){let t=e.trim().toLowerCase();return!!o.has(t)||!i.has(t)&&void 0}let s=[{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:"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"}],f=new Map(s.map(e=>[e.key,e]));function u(e){let t=e.env??process.env;return n(e.configPath,{cwd:e.cwd,env:t})}function y(o){let i=function(o){let i,l,s=o.env??process.env,y=u(o);if(!e.existsSync(y))throw new r("INVALID_ARGS",`Remote config file not found: ${y}`);try{i=e.readFileSync(y,"utf8")}catch(e){throw new r("INVALID_ARGS",`Failed to read remote config file: ${y}`,{cause:e instanceof Error?e.message:String(e)})}try{l=JSON.parse(i)}catch(e){throw new r("INVALID_ARGS",`Invalid JSON in remote config file: ${y}`,{cause:e instanceof Error?e.message:String(e)})}if(!l||"object"!=typeof l||Array.isArray(l))throw new r("INVALID_ARGS",`Remote config file must contain a JSON object: ${y}`);let p={},m=l,g=t.dirname(y);for(let[e,t]of Object.entries(m)){let o=f.get(e);if(!o)throw new r("INVALID_ARGS",`Unsupported remote config key "${e}" in remote config file ${y}.`);let i=a(o,t,`remote config file ${y}`,e);p[o.key]="string"==typeof i&&"path"in o&&o.path?n(i,{cwd:g,env:s}):i}return{resolvedPath:y,profile:p}}(o);return{resolvedPath:i.resolvedPath,profile:function(...e){let t={};for(let n of e)if(n)for(let e of s){let r=n[e.key];void 0!==r&&(t[e.key]=r)}return t}(function(e=process.env){let t={};for(let n of s){let r=(function(e){let t=f.get(e);return[`AGENT_DEVICE_${e.replace(/([A-Z])/g,"_$1").replace(/[^A-Za-z0-9_]/g,"_").toUpperCase()}`,...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]=a(n,r.value,`environment variable ${r.name}`,r.name))}return t}(o.env),i.profile)}}export{u as resolveRemoteConfigPath,y as resolveRemoteConfigProfile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readUpdateCheckWorkerArgs as e,runUpdateCheckWorker as c}from"./113.js";let o=e(process.argv.slice(2));o&&c(o).catch(()=>{process.exitCode=0});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-device",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"description": "Unified control plane for physical and virtual devices via an agent-driven CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Callstack",
|
|
@@ -11,6 +11,18 @@
|
|
|
11
11
|
".": {
|
|
12
12
|
"import": "./dist/src/index.js",
|
|
13
13
|
"types": "./dist/src/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./metro": {
|
|
16
|
+
"import": "./dist/src/metro.js",
|
|
17
|
+
"types": "./dist/src/metro.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./remote-config": {
|
|
20
|
+
"import": "./dist/src/remote-config.js",
|
|
21
|
+
"types": "./dist/src/remote-config.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./contracts": {
|
|
24
|
+
"import": "./dist/src/contracts.js",
|
|
25
|
+
"types": "./dist/src/contracts.d.ts"
|
|
14
26
|
}
|
|
15
27
|
},
|
|
16
28
|
"engines": {
|
|
@@ -70,3 +70,4 @@ Use this skill as a router with mandatory defaults. Read this file first. For no
|
|
|
70
70
|
- Need screenshots, diff, recording, replay maintenance, or perf data: [references/verification.md](references/verification.md)
|
|
71
71
|
- Need desktop surfaces, menu bar behavior, or macOS-specific interaction rules: [references/macos-desktop.md](references/macos-desktop.md)
|
|
72
72
|
- Need remote HTTP transport, `--remote-config` launches, or tenant leases on a remote macOS host: [references/remote-tenancy.md](references/remote-tenancy.md)
|
|
73
|
+
This includes remote React Native runs where `agent-device` now prepares Metro locally and manages the local Metro companion tunnel automatically.
|
|
@@ -9,9 +9,6 @@ Open this file for remote daemon HTTP flows, including `--remote-config` launche
|
|
|
9
9
|
- `agent-device open <app> --remote-config <path> --relaunch`
|
|
10
10
|
- `AGENT_DEVICE_DAEMON_BASE_URL=...`
|
|
11
11
|
- `AGENT_DEVICE_DAEMON_AUTH_TOKEN=...`
|
|
12
|
-
- `curl ... agent_device.lease.allocate`
|
|
13
|
-
- `curl ... agent_device.lease.heartbeat`
|
|
14
|
-
- `curl ... agent_device.lease.release`
|
|
15
12
|
- `agent-device --tenant ... --session-isolation tenant --run-id ... --lease-id ...`
|
|
16
13
|
|
|
17
14
|
## Most common mistake to avoid
|
|
@@ -27,20 +24,17 @@ agent-device open com.example.myapp --remote-config ./agent-device.remote.json -
|
|
|
27
24
|
```
|
|
28
25
|
|
|
29
26
|
- This is the preferred remote launch path for sandbox or cloud agents.
|
|
27
|
+
- `agent-device` prepares local Metro and auto-starts the local Metro companion tunnel when the remote bridge needs a path back to the developer machine.
|
|
28
|
+
- `close --remote-config ...` cleans up the managed companion process for that project/profile, but leaves the developer’s Metro server running.
|
|
30
29
|
- For Android React Native relaunch flows, install or reinstall the APK first, then relaunch by installed package name.
|
|
31
30
|
- Do not use `open <apk|aab> --relaunch`; remote runtime hints are applied through the installed app sandbox.
|
|
32
31
|
|
|
33
32
|
## Lease flow example
|
|
34
33
|
|
|
35
34
|
```bash
|
|
36
|
-
export AGENT_DEVICE_DAEMON_BASE_URL
|
|
35
|
+
export AGENT_DEVICE_DAEMON_BASE_URL=<trusted-daemon-base-url>
|
|
37
36
|
export AGENT_DEVICE_DAEMON_AUTH_TOKEN=<token>
|
|
38
37
|
|
|
39
|
-
curl -sS "${AGENT_DEVICE_DAEMON_BASE_URL}/rpc" \
|
|
40
|
-
-H "content-type: application/json" \
|
|
41
|
-
-H "Authorization: Bearer <token>" \
|
|
42
|
-
-d '{"jsonrpc":"2.0","id":"alloc-1","method":"agent_device.lease.allocate","params":{"tenantId":"acme","runId":"run-123","ttlMs":60000}}'
|
|
43
|
-
|
|
44
38
|
agent-device \
|
|
45
39
|
--tenant acme \
|
|
46
40
|
--session-isolation tenant \
|
|
@@ -49,34 +43,20 @@ agent-device \
|
|
|
49
43
|
session list --json
|
|
50
44
|
```
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
Low-level lease operations exist for host-side automation, but do not point them at arbitrary hosts. The remote daemon executes device-control commands, so only use a trusted daemon base URL and an auth token managed by the same operator boundary.
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
curl -sS "${AGENT_DEVICE_DAEMON_BASE_URL}/rpc" \
|
|
56
|
-
-H "content-type: application/json" \
|
|
57
|
-
-H "Authorization: Bearer <token>" \
|
|
58
|
-
-d '{"jsonrpc":"2.0","id":"hb-1","method":"agent_device.lease.heartbeat","params":{"leaseId":"<lease-id>","ttlMs":60000}}'
|
|
59
|
-
|
|
60
|
-
curl -sS "${AGENT_DEVICE_DAEMON_BASE_URL}/rpc" \
|
|
61
|
-
-H "content-type: application/json" \
|
|
62
|
-
-H "Authorization: Bearer <token>" \
|
|
63
|
-
-d '{"jsonrpc":"2.0","id":"rel-1","method":"agent_device.lease.release","params":{"leaseId":"<lease-id>"}}'
|
|
64
|
-
```
|
|
48
|
+
Lease lifecycle methods exposed by the daemon:
|
|
65
49
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
-H "content-type: application/json" \
|
|
71
|
-
-H "Authorization: Bearer <token>" \
|
|
72
|
-
-d '{"jsonrpc":"2.0","id":"cmd-1","method":"agent_device.command","params":{"session":"qa-ios","command":"snapshot","positionals":[],"meta":{"lockPolicy":"reject","lockPlatform":"ios","tenantId":"acme","runId":"run-123","leaseId":"<lease-id>"}}}'
|
|
73
|
-
```
|
|
50
|
+
- `agent_device.lease.allocate`
|
|
51
|
+
- `agent_device.lease.heartbeat`
|
|
52
|
+
- `agent_device.lease.release`
|
|
53
|
+
- `agent_device.command`
|
|
74
54
|
|
|
75
55
|
## Transport prerequisites
|
|
76
56
|
|
|
77
57
|
- Start the daemon in HTTP mode with `AGENT_DEVICE_DAEMON_SERVER_MODE=http|dual`.
|
|
78
58
|
- Point the client at the remote host with `AGENT_DEVICE_DAEMON_BASE_URL=http(s)://host:port[/base-path]`.
|
|
79
|
-
-
|
|
59
|
+
- For non-loopback remote hosts, set `AGENT_DEVICE_DAEMON_AUTH_TOKEN` or `--daemon-auth-token`. The client rejects non-loopback remote daemon URLs without auth.
|
|
80
60
|
- Direct JSON-RPC callers can authenticate with request params, `Authorization: Bearer <token>`, or `x-agent-device-token`.
|
|
81
61
|
- Prefer an auth hook such as `AGENT_DEVICE_HTTP_AUTH_HOOK` when the host needs caller validation or tenant injection.
|
|
82
62
|
|
|
@@ -117,4 +97,5 @@ The CLI sends `AGENT_DEVICE_DAEMON_AUTH_TOKEN` in both the JSON-RPC request toke
|
|
|
117
97
|
- Missing tenant, run, or lease fields in tenant-isolation mode should fail as `INVALID_ARGS`.
|
|
118
98
|
- Inactive or scope-mismatched leases should fail as `UNAUTHORIZED`.
|
|
119
99
|
- Inspect logs on the remote host during remote debugging. Client-side `--debug` does not tail a local daemon log once `AGENT_DEVICE_DAEMON_BASE_URL` is set.
|
|
100
|
+
- Do not point `AGENT_DEVICE_DAEMON_BASE_URL` at untrusted hosts. Remote daemon requests can launch apps and execute interaction commands.
|
|
120
101
|
- Treat daemon auth tokens and lease identifiers as sensitive operational data.
|