@appetize/cli 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +10 -0
- package/THIRD_PARTY_LICENSES +24 -0
- package/cli.js +19 -0
- package/close-event-DSfV7BZf.js +2 -0
- package/daemon.js +2 -0
- package/package.json +37 -0
- package/skills/appetize/SKILL.md +259 -0
- package/skills/appetize/references/commands.md +366 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @appetize/cli
|
|
2
|
+
|
|
3
|
+
Command-line tool for running, inspecting and controlling iOS and Android apps on [Appetize](https://appetize.io) cloud devices. It ships with an agent skill that teaches coding agents to drive a device.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install -g @appetize/cli
|
|
7
|
+
appetize --help
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Release notes are in [CHANGELOG.md](./CHANGELOG.md), included in the published package.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
cbor-x 1.6.6
|
|
2
|
+
MIT
|
|
3
|
+
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2020 Kris Zyp
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/cli.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import Se from"sade";import{d as U,D as ve,p as m,a as p,f as $,b as xe,i as Ee,c as be,r as j,e as v,g as Oe,h as $e,s as Ie,j as C,k as Pe,l as Ae,m as J,n as Ne,o as Te,q as De,t as ke,u as Le,v as _e,w as Re}from"./close-event-DSfV7BZf.js";import{existsSync as M,openAsBlob as ze,openSync as Fe,closeSync as Ue}from"node:fs";import{basename as B,extname as je,resolve as G,dirname as Ce,join as w,relative as Je}from"node:path";import{writeFile as K,stat as Me,rm as Be,cp as Ge}from"node:fs/promises";import{spawn as Ke}from"node:child_process";import{fileURLToPath as q}from"node:url";import{humanId as qe}from"human-id";import{homedir as Xe}from"node:os";import Ze from"debug";import"stream";import"module";import"node:net";import"json-rpc-2.0";const X=["back","menu","unlock","volumeDown","volumeUp"],Z=["home","lock"],V=[...Z,...X],I=["down","left","right","up"];async function Ve(e,t={}){const o=await U(e,{signal:t.signal});return new ve(o,{...t,onClose:()=>{o.close(),t.onClose?.()}})}function W({appId:e,buildNumber:t,created:o,id:n,platform:i,versionName:s}){return{appId:e,buildNumber:t,created:o,id:n,platform:i,versionName:s}}const We=["app"],He=10;async function Ye(e){const t=m(e.app,"--app"),o=p(e.limit,"--limit")??He,n=p(e.page,"--page"),i={limit:String(o)};t!==void 0&&(i.appId=t),n!==void 0&&(i.page=String(n));const s=await $("/api/v2/builds",{commandOptions:e,query:i}),a={builds:s.builds.map(W),nextPage:s.nextPage,total:s.total};process.stdout.write(`${JSON.stringify(a,null,2)}
|
|
3
|
+
`)}const Qe=["note","tags"],H=12e4,et=2e3,P=[".apk",".apks",".zip",".tar.gz",".tgz"],tt={".apk":"android",".apks":"android",".tar.gz":"ios",".tgz":"ios",".zip":"ios"};async function ot(e,t){const o=rt(e),n=await at(e,o,t);console.error(`build uploaded with id: ${n.id}`);const i=t.wait===!0?await nt(n.id,t):n;process.stdout.write(`${JSON.stringify(W(i),null,2)}
|
|
4
|
+
`)}async function nt(e,t){const o=p(t.timeout,"--timeout")??H,n=Date.now()+o;for(;;){const i=await $(`/api/v2/builds/${e}`,{commandOptions:t});if(i.appId!==void 0)return i;if(Date.now()>=n)throw new Error(`Build ${e} is still being processed after ${String(o)}ms; find it with 'appetize build list'`);await it(et)}}function it(e){return new Promise(t=>setTimeout(t,e))}async function st(e){if(!M(e))throw new Error(`No build file at ${e}`);return await ze(e)}function rt(e){const t=e.toLowerCase(),o=P.find(n=>t.endsWith(n));if(o===void 0)throw new Error(`Cannot tell the platform of ${B(e)}; upload a ${P.join(", ")} file`);return tt[o]}async function at(e,t,o){const n=new FormData;n.set("platform",t);const i=m(o.note,"--note");i!==void 0&&n.set("note",i);const s=m(o.tags,"--tags");return s!==void 0&&n.set("tags",s),n.set("file",await st(e),B(e)),await $("/api/v2/builds",{body:n,commandOptions:o,method:"POST"})}const ct=["platform"];async function pt(e){const t=dt(e.platform),n={devices:(await xe(e)).filter(i=>t===void 0||i.platform===t).map(lt)};process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
5
|
+
`)}function dt(e){const t=m(e,"--platform");if(t!==void 0){if(!Ee(t))throw new Error(`--platform expects one of: ${be.join(", ")}`);return t}}function lt({id:e,name:t,osVersions:o,platform:n}){return{id:e,name:t,osVersions:o,platform:n}}function A(e,{extension:t,strict:o=!1}){const n=je(e);if(n==="")return`${e}${t}`;if(o&&n!==t)throw new Error(`The output must be a path ending in ${t}`);return e}const h=["text","testId"],d="select",y={testId:{help:"Test id to match by exact string",suffix:"test-id"},text:{help:'Text to match by exact string or regex (e.g., "Sign in" or "/sign in/i")',suffix:"text"}},N="index",x="position",T="x",D="y";function Y(e,{prefix:t=d}={}){return h.reduce((o,n)=>{const{help:i,suffix:s}=y[n];return o.option(`--${r(t,s)}`,i)},e).option(`--${r(t,N)}`,"Which match when multiple (0-based)")}function k(e,t={}){const{prefix:o=d}=t;return Y(e,t).option(`--${r(o,x)}`,"Screen position to use as x,y (0-1), e.g., 0.5,0.75").option(`--${r(o,T)}`,"Horizontal position within the element (0-1, outside allowed)").option(`--${r(o,D)}`,"Vertical position within the element (0-1, outside allowed)")}function Q(e,{prefix:t=d}={}){const o=_(e,t);if(o.length===0)throw new Error(`A selector is required: pass one of ${b(h,t)}`);if(o.length>1)throw new Error(`Only one selector may be given, got ${b(o,t)}`);const[n]=o,i=se(e,r(t,y[n].suffix)),s=p(e[r(t,N)],`--${r(t,N)}`);switch(n){case"testId":return{by:"testId",index:s,testId:i};case"text":return{by:"text",index:s,text:mt(i)}}}function ee(e){const t=p(e.timeout,"--timeout");return t===void 0?void 0:{timeout:t}}function ut(e,{prefix:t=d}={}){return ne(e,t)?Q(e,{prefix:t}):void 0}function E(e,{prefix:t=d}={}){return ne(e,t)?te(e,{prefix:t}):void 0}function te(e,{prefix:t=d}={}){const o=r(t,x),n=e[o],i=ie(e,r(t,T)),s=ie(e,r(t,D));if(n===void 0){if(_(e,t).length===0)throw new Error(`A selector is required: pass one of ${S({prefix:t})}`);return{...Q(e,{prefix:t}),x:i,y:s}}if(_(e,t).length>0)throw new Error(`--${o} may not be combined with ${b(h,t)}`);if(i!==void 0||s!==void 0)throw new Error(`--${o} may not be combined with --${r(t,T)} or --${r(t,D)}`);return ft(se(e,o),o)}function S(e={}){const{prefix:t=d}=e;return`${b(h,t)}, --${r(t,x)}`}function L(e={}){const{prefix:t=d}=e;return[...oe(e),r(t,x)]}function oe({prefix:e=d}={}){return h.map(t=>r(e,y[t].suffix))}function _(e,t){return h.filter(o=>e[r(t,y[o].suffix)]!==void 0)}function r(...e){return e.filter(Boolean).join("-")}function b(e,t){return e.map(o=>`--${r(t,y[o].suffix)}`).join(", ")}function ne(e,t){return Object.entries(e).some(([o,n])=>n!==void 0&&o.startsWith(`${t}-`))}function ie(e,t){return p(e[t],`--${t}`)}function ft(e,t){const o=e.split(",");if(o.length!==2)throw new Error(`--${t} expects x,y (0-1), e.g., 0.5,0.75`);const[n,i]=o.map(s=>Number(s.trim()));return{by:"position",x:j(n,`--${t}`),y:j(i,`--${t}`)}}function mt(e){const t=/^\/(.*)\/([a-z]*)$/s.exec(e);return t?new RegExp(t[1],t[2]):e}function se(e,t){return v(e[t],`--${t}`)}const wt=oe(),ht=async({device:e,options:t,positionals:[o]})=>{const n=gt(o),i=ut(t),s=await e.inspect(i,ee(t)),a=yt(s,t.pretty===!0);await K(n,a);const c={bytes:Buffer.byteLength(a),nodes:re(s.root),output:n};process.stdout.write(`${JSON.stringify(c,null,2)}
|
|
6
|
+
`)};function re(e){return e.children.reduce((t,o)=>t+re(o),1)}function gt(e="inspect"){return A(e,{extension:".json"})}function yt(e,t){return`${JSON.stringify(e,null,t?2:void 0)}
|
|
7
|
+
`}const St=new Set(V),vt=async({device:e,positionals:[t]})=>{if(!xt(t))throw new Error(`Button must be one of: ${V.join(", ")}`);await e.press(t),process.stdout.write(`${JSON.stringify({pressed:!0},null,2)}
|
|
8
|
+
`)};function xt(e){return typeof e=="string"&&St.has(e)}const Et=async({control:e,options:t,positionals:[o]})=>{const{path:n}=await e.recordStart({force:t.force===!0,path:Ot(o)});process.stdout.write(`${JSON.stringify({path:n,recording:!0},null,2)}
|
|
9
|
+
`)},bt=async({control:e})=>{const{path:t}=await e.recordStop();process.stdout.write(`${JSON.stringify({path:t,recording:!1},null,2)}
|
|
10
|
+
`)};function Ot(e){const t=G(A(e,{extension:".mp4",strict:!0})),o=Ce(t);if(!M(o))throw new Error(`No such directory: ${o}`);return t}const ae={landscapeLeft:!0,landscapeRight:!0,portrait:!0,upsideDown:!0},$t=async({device:e,positionals:[t]})=>{if(!It(t))throw new Error(`Orientation must be one of: ${Object.keys(ae).join(", ")}`);const o=await e.rotate(t);process.stdout.write(`${JSON.stringify(o,null,2)}
|
|
11
|
+
`)};function It(e){return typeof e=="string"&&Object.hasOwn(ae,e)}const Pt=async({device:e,positionals:[t]})=>{const o=await e.screenshot(),n=Nt(o.mimeType,t);await K(n,o.data),process.stdout.write(`${JSON.stringify({bytes:o.data.byteLength,mimeType:o.mimeType,output:n},null,2)}
|
|
12
|
+
`)};function At(e){const t=e.split("/").at(1);return`.${t==="jpeg"?"jpg":t??"png"}`}function Nt(e,t="screenshot"){return A(t,{extension:At(e)})}function Tt(e){const t=q(new URL("./daemon.js",import.meta.url)),o=Fe(Oe(e.sessionId),"a"),n=Ke(process.execPath,[t],{detached:!0,env:{...process.env,[$e]:Ie(e),DEBUG:Dt(process.env.DEBUG)},stdio:["ignore",o,o]});if(Ue(o),n.unref(),n.pid===void 0)throw new Error("Failed to spawn the session daemon");return n.pid}function Dt(e){return e?`${e},appetize:daemon`:"appetize:daemon"}const kt=/^[a-z0-9](?:[a-z0-9._-]{0,62}[a-z0-9])?$/i;function Lt(){return qe({capitalize:!1,separator:"-"})}function _t(e){if(!kt.test(e))throw new Error('--session-id must use letters, digits, ".", "-" or "_"');return e}const Rt=["device-os-version","proxy"],zt=150;async function Ft(e,{onPhase:t,signal:o}){let n;for(;;){const i=C(e),s=i?.state?.phase;if(s&&s!==n&&(n=s,t?.(s)),i&&s==="ready"&&i.controlSocket!==void 0)return{...i,controlSocket:i.controlSocket};if(s==="error")throw new Error(i?.endedReason??"The session failed to start");if(s==="ended")throw new Error(i?.endedReason??"The session ended");await Ct(zt,o)}}function Ut(e){if(!(e===void 0||e===!1)){if(e===""||e==="intercept")return"intercept";if(typeof e!="string"||!Jt(e))throw new Error("--proxy expects 'intercept' or an http:// url, e.g., http://proxy:8080");return e}}async function jt(e,t,o){const n=m(o["device-os-version"],"--device-os-version"),i=m(o["session-id"],"--session-id"),s=i===void 0?Lt():_t(i);if(C(s)!==void 0)throw new Error(`Session ${s} already exists`);const a={device:n===void 0?{id:e}:{id:e,osVersion:n},endpoint:Pe(o),proxy:Ut(o.proxy),sessionId:s,target:t};Tt(a),console.error(`session started with id: ${s}`);const c=Ae(s,a.proxy);if(o.wait===!1){process.stdout.write(`${JSON.stringify({logs:c,sessionId:s},null,2)}
|
|
13
|
+
`);return}const O=await Ft(s,{onPhase:ye=>{console.error(ye)},signal:J()}),ge={adbSerial:O.adbSerial,baseUrl:O.baseUrl,controlSocket:O.controlSocket,logs:c,sessionId:s};process.stdout.write(`${JSON.stringify(ge,null,2)}
|
|
14
|
+
`)}function Ct(e,t){return new Promise((o,n)=>{if(t.aborted){n(ce(t.reason));return}const i=()=>{clearTimeout(s),n(ce(t.reason))},s=setTimeout(()=>{t.removeEventListener("abort",i),o()},e);t.addEventListener("abort",i,{once:!0})})}function Jt(e){return e.startsWith("http://")}function ce(e){return e instanceof Error?e:new Error(String(e))}const Mt=async({record:{pid:e,sessionId:t}})=>{Ne(e)&&process.kill(e,"SIGTERM"),process.stdout.write(`${JSON.stringify({ended:!0,sessionId:t},null,2)}
|
|
15
|
+
`)},pe="appetize",Bt=q(new URL(`./skills/${pe}/`,import.meta.url)),R=["agents","claude","codex","copilot","cursor"],de=["project","user"],Gt={agents:".agents",claude:".claude",codex:".codex",copilot:".copilot",cursor:".cursor"},Kt=w(".agents","skills"),qt=["claude","agents"];function Xt(e){return R.some(t=>t===e)}function Zt(e){return de.some(t=>t===e)}async function Vt(e){const t=e.agents??await Wt(e),o=await Promise.all(t.map(n=>le(n,e)));return[...new Set(o.flat())]}async function le(e,t){const o=ue(e,t);if(e==="claude")return[w(o,"skills")];const n=w(t.root,Kt);return t.scope==="project"?[n]:await fe(o)?[n,w(o,"skills")]:[n]}function ue(e,t){if(e==="claude"&&t.scope==="user"){const o=process.env.CLAUDE_CONFIG_DIR?.trim();if(o)return G(o)}return w(t.root,Gt[e])}async function Wt(e){const o=(await Promise.all(R.map(async n=>await Ht(n,e)?n:void 0))).filter(n=>n!==void 0);return o.length>0?o:qt}async function Ht(e,t){const o=[ue(e,t),...await le(e,t)];return(await Promise.all(o.map(i=>fe(i)))).includes(!0)}async function fe(e){try{return(await Me(e)).isDirectory()}catch{return!1}}const Yt=["agent","scope"];async function Qt(e){const t=oo(e.scope),o=to(e.agent),n=t==="user"?Xe():process.cwd(),i=await Vt({agents:o,root:n,scope:t}),s=[];for(const a of i){const c=w(a,pe);await Be(c,{force:!0,recursive:!0}),await Ge(Bt,c,{recursive:!0}),s.push(t==="user"?c:Je(n,c))}process.stdout.write(`${JSON.stringify({installed:s},null,2)}
|
|
16
|
+
`)}function eo(e){const t=v(e,"--agent");if(!Xt(t))throw new Error(`--agent expects one of ${R.join(", ")}`);return t}function to(e){return e===void 0?void 0:(Array.isArray(e)?e:[e]).map(o=>eo(o))}function oo(e){if(e===void 0)return"project";const t=v(e,"--scope");if(!Zt(t))throw new Error(`--scope expects one of ${de.join(", ")}`);return t}const l="from",u="to",no=[...L({prefix:l}),...L({prefix:u})],io=async({device:e,options:t})=>{await e.swipe(co(t),lo(t)),process.stdout.write(`${JSON.stringify({swiped:!0},null,2)}
|
|
17
|
+
`)};function so(e){return I.some(t=>t===e)}function ro(e){if(e===void 0)return;const t=v(e,"--direction");if(!so(t))throw new Error(`--direction expects one of ${I.join(", ")}`);return t}function ao(e,t){const o=Te(e.distance,"--distance");if(E(e,{prefix:u})!==void 0)throw new Error(`--direction may not be combined with --${u}-*`);return{direction:t,distance:o,from:E(e,{prefix:l})}}function co(e){const t=ro(e.direction);return t===void 0?po(e):ao(e,t)}function po(e){if(e.distance!==void 0)throw new Error("--distance is only valid with --direction");return{from:me(E(e,{prefix:l}),l),to:me(E(e,{prefix:u}),u)}}function lo(e){const t=p(e.duration,"--duration"),o=p(e.timeout,"--timeout");return t===void 0&&o===void 0?void 0:{duration:t,timeout:o}}function me(e,t){if(e===void 0)throw new Error(`A swipe needs --direction, or both endpoints: pass one of ${S({prefix:t})}`);return e}const uo=L(),fo=async({device:e,options:t})=>{const o=te(t);await e.tap(o,ee(t)),process.stdout.write(`${JSON.stringify({tapped:!0},null,2)}
|
|
18
|
+
`)},mo=async({device:e,options:t,positionals:[o]})=>{await e.type(o,wo(t)),process.stdout.write(`${JSON.stringify({typed:!0},null,2)}
|
|
19
|
+
`)};function wo(e){const t=p(e.delay,"--delay");return t===void 0?void 0:{delay:t}}const z=Ze("appetize:cli");function ho(e,t){if(e.controlSocket===void 0)throw new Error("Session is not ready");return Ve(e.controlSocket,{baseUrl:e.baseUrl,signal:t})}async function go(e,t){if(e.controlSocket===void 0)throw new Error("Session is not ready");const o=await U(e.controlSocket,{signal:t}),{client:n}=De(o,{});return{close:()=>{o.close()},recordStart:async i=>await n.request("appetizeio.cli.record.start",i),recordStop:async()=>await n.request("appetizeio.cli.record.stop")}}function yo(e){return async(...t)=>{const{options:o,positionals:n}=Eo(t),i=o["session-id"],s=ke(typeof i=="string"?i:void 0),a=AbortSignal.any([J(),Le(s.pid)]);await e({options:o,positionals:n,record:s,signal:a})}}function So(e){return async({options:t,positionals:o,record:n,signal:i})=>{const s=await ho(n,i);try{await e({device:s,options:t,positionals:o,signal:i})}finally{s.close()}}}function vo(e){return async({options:t,positionals:o,record:n,signal:i})=>{const s=await go(n,i);try{await e({control:s,options:t,positionals:o,signal:i})}finally{s.close()}}}function xo(e){return typeof e=="object"&&e!==null}function Eo(e){const t=e.at(-1);return{options:xo(t)?t:{},positionals:e.slice(0,-1).filter(o=>typeof o=="string")}}const bo=["session-id",...We,...Qe,...ct,...wt,...Yt,...Rt,...no,...uo];function Oo(e){const t=Se("appetize").version(e);return g(t.command("session start <device-id> <target>").describe(["Start a device session and wait until it is ready","","Environment variables:","APPETIZE_API_TOKEN: Authorizes private APIs and session targets","APPETIZE_ENDPOINT: Appetize URL used when --endpoint is omitted"]).option("--device-os-version","Device OS version (e.g., 17 for iOS, 14 for Android)").option("--endpoint","Appetize URL (e.g., https://appetize.io); overrides APPETIZE_ENDPOINT").option("--no-wait","Return without waiting for the device session to be ready").option("--proxy","Route traffic through a proxy: 'intercept' to capture it, or an http url").option("--session-id","Session id; defaults to a generated 3-word id").example("session start iphone15pro app_a1b2c3").example("session start pixel7 app_a1b2c3 --device-os-version 14"),jt),F(t.command("session stop").describe("Stop a running device session"),Mt),g(t.command("build list").describe(["List uploaded builds, printing session start targets","","Environment variables:","APPETIZE_API_TOKEN: Authorizes the listing request","APPETIZE_ENDPOINT: Appetize URL used when --endpoint is omitted"]).option("--app","App id to filter by (bundle or package id)").option("--endpoint","Appetize URL (e.g., https://appetize.io); overrides APPETIZE_ENDPOINT").option("--limit","Builds per page (default 10, max 200)").option("--page","Page of results to fetch (default 1)").example("build list").example("build list --app com.example.app").example("build list --app com.example.app --page 2"),Ye),g(t.command("build upload <file>").describe([`Upload a build (${P.join(", ")}) as a session start target`,"","Environment variables:","APPETIZE_API_TOKEN: Authorizes the upload","APPETIZE_ENDPOINT: Appetize URL used when --endpoint is omitted"]).option("--endpoint","Appetize URL (e.g., https://appetize.io); overrides APPETIZE_ENDPOINT").option("--note","Note to store with the build").option("--tags","Comma separated tags to store with the build").option("--timeout",`Milliseconds to wait with --wait (default ${String(H)})`).option("--wait","Wait for the app id and version metadata to resolve").example("build upload ./app.apk").example("build upload ./app.zip").example("build upload ./app.apk --wait").example('build upload ./app.apk --tags beta,latest --note "PR 42"'),ot),g(t.command("device list").describe(["List device models and their supported OS versions","","Environment variables:","APPETIZE_ENDPOINT: Appetize URL used when --endpoint is omitted"]).option("--endpoint","Appetize URL (e.g., https://appetize.io); overrides APPETIZE_ENDPOINT").option("--platform","Platform to filter by: ios or android").example("device list").example("device list --platform ios"),pt),f(t.command("press <button>").describe(`Press a device button: ${Z.join(", ")}; Android only: ${X.join(", ")}`).example("press home").example("press volumeUp"),vt),f(t.command("rotate <orientation>").describe("Rotate the device to an orientation: portrait, landscapeLeft, landscapeRight or upsideDown").example("rotate portrait").example("rotate landscapeLeft"),$t),f(t.command("screenshot [output]").describe("Take a screenshot of the current device screen").example("screenshot").example("screenshot home-screen").example("screenshot ./shots/checkout.png"),Pt),f(k(t.command("tap").describe(["Tap an element matched by a selector, or a screen position","",`Pick one of: ${S()}`])).option("--timeout","Milliseconds to wait for the element").example("tap --select-text 'Log in'").example("tap --select-test-id save").example("tap --select-text '/^Item \\d+/i' --select-index 2").example("tap --select-position 0.5,0.75").example("tap --select-test-id slider --select-x 0.9").example("tap --select-test-id dialog --select-x=-0.1").example("tap --select-test-id row --select-y=1.2"),fo),f(k(k(t.command("swipe").describe(["Swipe in a direction, or along a path between two points","",`Pick a --direction with an optional --${l} starting point,`,`or both a --${l}-* and a --${u}-* point to form a path`,"",`Pick one per point: ${S({prefix:l})}`,` ${S({prefix:u})}`]).option("--direction",`Direction to travel: ${I.join(", ")}`).option("--distance","Travel as a fraction of the screen (0-1)"),{prefix:l}),{prefix:u}).option("--duration","Milliseconds the gesture travels for").option("--timeout",`Milliseconds to wait for any --${l}/--${u} elements`).example("swipe --direction up").example("swipe --direction up --distance 0.25").example("swipe --direction left --from-test-id card --from-index 1").example("swipe --from-position 0.5,0.75 --to-position 0.5,0.3").example("swipe --from-text 'Drag me' --from-y 0.9 --to-test-id drop-zone"),io),f(Y(t.command("inspect [output]").describe("Capture the view hierarchy of the screen, or of an element matched by a selector")).option("--timeout","Milliseconds to wait for the element").option("--pretty","Pretty-print the JSON",!1).example("inspect").example("inspect --select-text 'Log in'").example("inspect hierarchy.json --pretty"),ht),f(t.command("type <text>").describe(`Type text; {...} presses a named key: ${_e.join(", ")}`).option("--delay","Milliseconds to wait between steps").example("type 'hello{Enter}'").example("type '{Backspace>16/}'").example("type 'user@example.com{Tab}hunter2{Enter}' --delay 50"),mo),we(t.command("recording start <output>").describe("Start recording the device video to an mp4 file").option("--force","Overwrite the file if it already exists",!1).example("recording start login-flow").example("recording start ./captures/checkout.mp4").example("recording start login-flow --force"),Et),we(t.command("recording stop").describe("Stop recording the device video and close the file").example("recording stop"),bt),g(t.command("skill install").describe("Install the Appetize agent skill for coding agents").option("--agent","Agent to install for, repeatable; defaults to the agents detected").option("--scope","Install for the project (default) or the user").example("skill install").example("skill install --scope user").example("skill install --agent claude --agent cursor"),Qt),t}function g(e,t){return e.action(Io(t))}function F(e,t){return g(e.option("--session-id","Target session id; defaults to the sole active session"),yo(t))}function f(e,t){return F(e,So(t))}function we(e,t){return F(e,vo(t))}function he(e){return`${String(Date.now()-e)}ms`}async function $o(e,...t){const o=Date.now();z(`invoked: ${process.argv.slice(2).join(" ")}`);try{await e(...t),z(`ok in ${he(o)}`)}catch(n){const i=n instanceof Error?n.message:String(n);console.error(i),z(`failed after ${he(o)}:`,n),process.exitCode=1}}function Io(e){return(...t)=>{$o(e,...t)}}Re(),Oo("0.15.0").parse(process.argv,{string:bo});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Transform as Qt}from"stream";import{createRequire as er}from"module";import{connect as tr}from"node:net";import Be from"debug";import{JSONRPCServerAndClient as rr,JSONRPCServer as sr,JSONRPCClient as nr,JSONRPC as ir}from"json-rpc-2.0";import{writeFileSync as or,renameSync as ar,mkdirSync as pt,readFileSync as lr,readdirSync as cr}from"node:fs";import{homedir as fr}from"node:os";import{join as te}from"node:path";let Ne;try{Ne=new TextDecoder}catch{}let p,V,c=0;const De=[],ur=105,dr=57342,hr=57343,yt=57337,wt=6,fe={};let we=11281e4,Y=1681e4,re=De,be=0,O={},_,ge,me=0,se=0,B,q,N=[],Fe=[],K,j,Ee,bt={useRecords:!1,mapsAsObjects:!0},Se=!1,gt=2;try{new Function("")}catch{gt=1/0}class he{constructor(e){if(e&&((e.keyMap||e._keyMap)&&!e.useRecords&&(e.useRecords=!1,e.mapsAsObjects=!0),e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.getStructures&&(e.getShared=e.getStructures),e.getShared&&!e.structures&&((e.structures=[]).uninitialized=!0),e.keyMap)){this.mapKey=new Map;for(let[r,s]of Object.entries(e.keyMap))this.mapKey.set(s,r)}Object.assign(this,e)}decodeKey(e){return this.keyMap&&this.mapKey.get(e)||e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(e){if(!this._keyMap)return e;let r=new Map;for(let[s,n]of Object.entries(e))r.set(this._keyMap.hasOwnProperty(s)?this._keyMap[s]:s,n);return r}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[s,n]of Object.entries(this._keyMap))this._mapKey.set(n,s)}let r={};return e.forEach((s,n)=>r[J(this._mapKey.has(n)?this._mapKey.get(n):n)]=s),r}mapDecode(e,r){let s=this.decode(e);return this._keyMap&&s.constructor.name==="Array"?s.map(n=>this.decodeKeys(n)):s}decode(e,r){if(p)return Ot(()=>(Ke(),this?this.decode(e,r):he.prototype.decode.call(bt,e,r)));V=r>-1?r:e.length,c=0,be=0,se=0,ge=null,re=De,B=null,p=e;try{j=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(s){throw p=null,e instanceof Uint8Array?s:new Error("Source must be a Uint8Array or Buffer but was a "+(e&&typeof e=="object"?e.constructor.name:typeof e))}if(this instanceof he){if(O=this,K=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return _=this.structures,Oe();(!_||_.length>0)&&(_=[])}else O=bt,(!_||_.length>0)&&(_=[]),K=null;return Oe()}decodeMultiple(e,r){let s,n=0;try{let o=e.length;Se=!0;let f=this?this.decode(e,o):qe.decode(e,o);if(r){if(r(f)===!1)return;for(;c<o;)if(n=c,r(Oe())===!1)return}else{for(s=[f];c<o;)n=c,s.push(Oe());return s}}catch(o){throw o.lastPosition=n,o.values=s,o}finally{Se=!1,Ke()}}}function Oe(){try{let t=I();if(B){if(c>=B.postBundlePosition){let e=new Error("Unexpected bundle position");throw e.incomplete=!0,e}c=B.postBundlePosition,B=null}if(c==V)_=null,p=null,q&&(q=null);else if(c>V){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}else if(!Se)throw new Error("Data read, but end of buffer not reached");return t}catch(t){throw Ke(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer"))&&(t.incomplete=!0),t}}function ne(){let t=new Error("Unexpected end of CBOR data");return t.incomplete=!0,t}function I(){if(!(c<V))throw ne();let t=p[c++],e=t>>5;if(t=t&31,t>23)switch(t){case 24:if(c>=V)throw ne();t=p[c++];break;case 25:if(e==7)return br();t=j.getUint16(c),c+=2;break;case 26:if(e==7){let r=j.getFloat32(c);if(O.useFloat32>2){let s=$e[(p[c]&127)<<1|p[c+1]>>7];return c+=4,(s*r+(r>0?.5:-.5)>>0)/s}return c+=4,r}if(t=j.getUint32(c),c+=4,e===1)return-1-t;break;case 27:if(e==7){let r=j.getFloat64(c);return c+=8,r}if(e>1){if(j.getUint32(c)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");t=j.getUint32(c+4)}else O.int64AsNumber?(t=j.getUint32(c)*4294967296,t+=j.getUint32(c+4)):t=j.getBigUint64(c);c+=8;break;case 31:switch(e){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let r=[],s,n=0;for(;(s=I())!=fe;){if(n>=we)throw new Error(`Array length exceeds ${we}`);r[n++]=s}return e==4?r:e==3?r.join(""):Buffer.concat(r);case 5:let o;if(O.mapsAsObjects){let f={},b=0;if(O.keyMap)for(;(o=I())!=fe;){if(b++>=Y)throw new Error(`Property count exceeds ${Y}`);f[J(O.decodeKey(o))]=I()}else for(;(o=I())!=fe;){if(b++>=Y)throw new Error(`Property count exceeds ${Y}`);f[J(o)]=I()}return f}else{Ee&&(O.mapsAsObjects=!0,Ee=!1);let f=new Map;if(O.keyMap){let b=0;for(;(o=I())!=fe;){if(b++>=Y)throw new Error(`Map size exceeds ${Y}`);f.set(O.decodeKey(o),I())}}else{let b=0;for(;(o=I())!=fe;){if(b++>=Y)throw new Error(`Map size exceeds ${Y}`);f.set(o,I())}}return f}case 7:return fe;default:throw new Error("Invalid major type for indefinite length "+e)}default:throw new Error("Unknown token "+t)}switch(e){case 0:return t;case 1:return~t;case 2:return wr(t);case 3:if(se>=c)return ge.slice(c-me,(c+=t)-me);if(se==0&&V<140&&t<32){let n=t<16?St(t):yr(t);if(n!=null)return n}return Et(t);case 4:if(t>=we)throw new Error(`Array length exceeds ${we}`);if(t>V-c)throw ne();let r=new Array(t);for(let n=0;n<t;n++)r[n]=I();return r;case 5:if(t>=Y)throw new Error(`Map size exceeds ${we}`);if(t>(V-c)/2)throw ne();if(O.mapsAsObjects){let n={};if(O.keyMap)for(let o=0;o<t;o++)n[J(O.decodeKey(I()))]=I();else for(let o=0;o<t;o++)n[J(I())]=I();return n}else{Ee&&(O.mapsAsObjects=!0,Ee=!1);let n=new Map;if(O.keyMap)for(let o=0;o<t;o++)n.set(O.decodeKey(I()),I());else for(let o=0;o<t;o++)n.set(I(),I());return n}case 6:if(t>=yt){let n=_[t&8191];if(n)return n.read||(n.read=ze(n)),n.read();if(t<65536){if(t==hr){let o=de(),f=I(),b=I();je(f,b);let y={};if(O.keyMap)for(let v=2;v<o;v++){let m=O.decodeKey(b[v-2]);y[J(m)]=I()}else for(let v=2;v<o;v++){let m=b[v-2];y[J(m)]=I()}return y}else if(t==dr){let o=de(),f=I();for(let b=2;b<o;b++)je(f++,I());return I()}else if(t==yt)return Ar();if(O.getShared&&(Ve(),n=_[t&8191],n))return n.read||(n.read=ze(n)),n.read()}}let s=N[t];if(s)return s.handlesRead?s(I):s(I());{let n=I();for(let o=0;o<Fe.length;o++){let f=Fe[o](t,n);if(f!==void 0)return f}return new ie(n,t)}case 7:switch(t){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:let n=(K||oe())[t];if(n!==void 0)return n;throw new Error("Unknown token "+t)}default:throw isNaN(t)?ne():new Error("Unknown CBOR token "+t)}}const mt=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function ze(t){if(!t)throw new Error("Structure is required in record definition");function e(){let r=p[c++];if(r=r&31,r>23)switch(r){case 24:r=p[c++];break;case 25:r=j.getUint16(c),c+=2;break;case 26:r=j.getUint32(c),c+=4;break;default:throw new Error("Expected array header, but got "+p[c-1])}let s=this.compiledReader;for(;s;){if(s.propertyCount===r)return s(I);s=s.next}if(this.slowReads++>=gt){let o=this.length==r?this:this.slice(0,r);return s=O.keyMap?new Function("r","return {"+o.map(f=>O.decodeKey(f)).map(f=>mt.test(f)?J(f)+":r()":"["+JSON.stringify(f)+"]:r()").join(",")+"}"):new Function("r","return {"+o.map(f=>mt.test(f)?J(f)+":r()":"["+JSON.stringify(f)+"]:r()").join(",")+"}"),this.compiledReader&&(s.next=this.compiledReader),s.propertyCount=r,this.compiledReader=s,s(I)}let n={};if(O.keyMap)for(let o=0;o<r;o++)n[J(O.decodeKey(this[o]))]=I();else for(let o=0;o<r;o++)n[J(this[o])]=I();return n}return t.slowReads=0,e}function J(t){if(typeof t=="string")return t==="__proto__"?"__proto_":t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return t.toString();if(t==null)return t+"";throw new Error("Invalid property name type "+typeof t)}let Et=Ie;function pr(t){Et=e();function e(r){return function(n){let o=re[be++];if(o==null){if(B)return Ie(n);let b=t(c,V,n,p);if(typeof b=="string")o=b,re=De;else if(re=b,be=1,se=1,o=re[0],o===void 0)throw new Error("Unexpected end of buffer")}let f=o.length;return f<=n?(c+=n,o):(ge=o,me=c,se=c+f,c+=n,o.slice(0,n))}}}function Ie(t){let e;if(t<16&&(e=St(t)))return e;if(t>64&&Ne)return Ne.decode(p.subarray(c,c+=t));const r=c+t,s=[];for(e="";c<r;){const n=p[c++];if((n&128)===0)s.push(n);else if((n&224)===192)if(n<194||c>=r||(p[c]&192)!==128)s.push(65533);else{const o=p[c++]&63;s.push((n&31)<<6|o)}else if((n&240)===224){const o=c<r?p[c]:0;if(c>=r||(o&192)!==128||n===224&&o<160||n===237&&o>=160)s.push(65533);else if(c++,c>=r||(p[c]&192)!==128)s.push(65533);else{const f=p[c++]&63;s.push((n&31)<<12|(o&63)<<6|f)}}else if((n&248)===240){const o=c<r?p[c]:0;if(n>244||c>=r||(o&192)!==128||n===240&&o<144||n===244&&o>=144)s.push(65533);else if(c++,c>=r||(p[c]&192)!==128)s.push(65533);else{const f=p[c++]&63;if(c>=r||(p[c]&192)!==128)s.push(65533);else{const b=p[c++]&63;let y=(n&7)<<18|(o&63)<<12|f<<6|b;y-=65536,s.push(y>>>10&1023|55296),s.push(56320|y&1023)}}}else s.push(65533);s.length>=4096&&(e+=F.apply(String,s),s.length=0)}return s.length>0&&(e+=F.apply(String,s)),e}let F=String.fromCharCode;function yr(t){let e=c,r=new Array(t);for(let s=0;s<t;s++){const n=p[c++];if((n&128)>0){c=e;return}r[s]=n}return F.apply(String,r)}function St(t){if(t<4)if(t<2){if(t===0)return"";{let e=p[c++];if((e&128)>1){c-=1;return}return F(e)}}else{let e=p[c++],r=p[c++];if((e&128)>0||(r&128)>0){c-=2;return}if(t<3)return F(e,r);let s=p[c++];if((s&128)>0){c-=3;return}return F(e,r,s)}else{let e=p[c++],r=p[c++],s=p[c++],n=p[c++];if((e&128)>0||(r&128)>0||(s&128)>0||(n&128)>0){c-=4;return}if(t<6){if(t===4)return F(e,r,s,n);{let o=p[c++];if((o&128)>0){c-=5;return}return F(e,r,s,n,o)}}else if(t<8){let o=p[c++],f=p[c++];if((o&128)>0||(f&128)>0){c-=6;return}if(t<7)return F(e,r,s,n,o,f);let b=p[c++];if((b&128)>0){c-=7;return}return F(e,r,s,n,o,f,b)}else{let o=p[c++],f=p[c++],b=p[c++],y=p[c++];if((o&128)>0||(f&128)>0||(b&128)>0||(y&128)>0){c-=8;return}if(t<10){if(t===8)return F(e,r,s,n,o,f,b,y);{let v=p[c++];if((v&128)>0){c-=9;return}return F(e,r,s,n,o,f,b,y,v)}}else if(t<12){let v=p[c++],m=p[c++];if((v&128)>0||(m&128)>0){c-=10;return}if(t<11)return F(e,r,s,n,o,f,b,y,v,m);let x=p[c++];if((x&128)>0){c-=11;return}return F(e,r,s,n,o,f,b,y,v,m,x)}else{let v=p[c++],m=p[c++],x=p[c++],R=p[c++];if((v&128)>0||(m&128)>0||(x&128)>0||(R&128)>0){c-=12;return}if(t<14){if(t===12)return F(e,r,s,n,o,f,b,y,v,m,x,R);{let L=p[c++];if((L&128)>0){c-=13;return}return F(e,r,s,n,o,f,b,y,v,m,x,R,L)}}else{let L=p[c++],U=p[c++];if((L&128)>0||(U&128)>0){c-=14;return}if(t<15)return F(e,r,s,n,o,f,b,y,v,m,x,R,L,U);let P=p[c++];if((P&128)>0){c-=15;return}return F(e,r,s,n,o,f,b,y,v,m,x,R,L,U,P)}}}}}function wr(t){return O.copyBuffers?Uint8Array.prototype.slice.call(p,c,c+=t):p.subarray(c,c+=t)}let vt=new Float32Array(1),Me=new Uint8Array(vt.buffer,0,4);function br(){let t=p[c++],e=p[c++],r=(t&127)>>2;if(r===31)return e||t&3?NaN:t&128?-1/0:1/0;if(r===0){let s=((t&3)<<8|e)/16777216;return t&128?-s:s}return Me[3]=t&128|(r>>1)+56,Me[2]=(t&7)<<5|e>>3,Me[1]=e<<5,Me[0]=0,vt[0]}new Array(4096);class ie{constructor(e,r){this.value=e,this.tag=r}}N[0]=t=>new Date(t),N[1]=t=>new Date(Math.round(t*1e3)),N[2]=t=>{let e=BigInt(0);for(let r=0,s=t.byteLength;r<s;r++)e=BigInt(t[r])+(e<<BigInt(8));return e},N[3]=t=>BigInt(-1)-N[2](t),N[4]=t=>+(t[1]+"e"+t[0]),N[5]=t=>t[1]*Math.exp(t[0]*Math.log(2));const je=(t,e)=>{t=t-57344;let r=_[t];r&&r.isShared&&((_.restoreStructures||(_.restoreStructures=[]))[t]=r),_[t]=e,e.read=ze(e)};N[ur]=t=>{let e=t.length,r=t[1];je(t[0],r);let s={};for(let n=2;n<e;n++){let o=r[n-2];s[J(o)]=t[n]}return s},N[14]=t=>B?B[0].slice(B.position0,B.position0+=t):new ie(t,14),N[15]=t=>B?B[1].slice(B.position1,B.position1+=t):new ie(t,15);let gr={Error,RegExp};N[27]=t=>(gr[t[0]]||Error)(t[1],t[2]);const At=t=>{if(p[c++]!=132){let r=new Error("Packed values structure must be followed by a 4 element array");throw p.length<c&&(r.incomplete=!0),r}let e=t();if(!e||!e.length){let r=new Error("Packed values structure must be followed by a 4 element array");throw r.incomplete=!0,r}return K=K?e.concat(K.slice(e.length)):e,K.prefixes=t(),K.suffixes=t(),t()};At.handlesRead=!0,N[51]=At,N[wt]=t=>{if(!K)if(O.getShared)Ve();else return new ie(t,wt);if(typeof t=="number")return K[16+(t>=0?2*t:-2*t-1)];let e=new Error("No support for non-integer packed references yet");throw t===void 0&&(e.incomplete=!0),e},N[28]=t=>{q||(q=new Map,q.id=0);let e=q.id++,r=c,s=p[c],n;s>>5==4?n=[]:n={};let o={target:n};q.set(e,o);let f=t();return o.used?(Object.getPrototypeOf(n)!==Object.getPrototypeOf(f)&&(c=r,n=f,q.set(e,{target:n}),f=t()),Object.assign(n,f)):(o.target=f,f)},N[28].handlesRead=!0,N[29]=t=>{let e=q.get(t);return e.used=!0,e.target},N[258]=t=>new Set(t),(N[259]=t=>(O.mapsAsObjects&&(O.mapsAsObjects=!1,Ee=!0),t())).handlesRead=!0;function ue(t,e){return typeof t=="string"?t+e:t instanceof Array?t.concat(e):Object.assign({},t,e)}function oe(){if(!K)if(O.getShared)Ve();else throw new Error("No packed values available");return K}const mr=1399353956;Fe.push((t,e)=>{if(t>=225&&t<=255)return ue(oe().prefixes[t-224],e);if(t>=28704&&t<=32767)return ue(oe().prefixes[t-28672],e);if(t>=1879052288&&t<=2147483647)return ue(oe().prefixes[t-1879048192],e);if(t>=216&&t<=223)return ue(e,oe().suffixes[t-216]);if(t>=27647&&t<=28671)return ue(e,oe().suffixes[t-27639]);if(t>=1811940352&&t<=1879048191)return ue(e,oe().suffixes[t-1811939328]);if(t==mr)return{packedValues:K,structures:_.slice(0),version:e};if(t==55799)return e});const Er=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,kt=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],Sr=[64,68,69,70,71,72,77,78,79,85,86];for(let t=0;t<kt.length;t++)vr(kt[t],Sr[t]);function vr(t,e){let r="get"+t.name.slice(0,-5),s;typeof t=="function"?s=t.BYTES_PER_ELEMENT:t=null;for(let n=0;n<2;n++){if(!n&&s==1)continue;let o=s==2?1:s==4?2:s==8?3:0;N[n?e:e-4]=s==1||n==Er?f=>{if(!t)throw new Error("Could not find typed array for code "+e);return!O.copyBuffers&&(s===1||s===2&&!(f.byteOffset&1)||s===4&&!(f.byteOffset&3)||s===8&&!(f.byteOffset&7))?new t(f.buffer,f.byteOffset,f.byteLength>>o):new t(Uint8Array.prototype.slice.call(f,0).buffer)}:f=>{if(!t)throw new Error("Could not find typed array for code "+e);let b=new DataView(f.buffer,f.byteOffset,f.byteLength),y=f.length>>o,v=new t(y),m=b[r];for(let x=0;x<y;x++)v[x]=m.call(b,x<<o,n);return v}}}function Ar(){let t=de(),e=c+I();for(let s=2;s<t;s++){let n=de();c+=n}let r=c;return c=e,B=[Ie(de()),Ie(de())],B.position0=0,B.position1=0,B.postBundlePosition=c,c=r,I()}function de(){if(!(c<V))throw ne();let t=p[c++]&31;if(t>23)switch(t){case 24:if(c>=V)throw ne();t=p[c++];break;case 25:t=j.getUint16(c),c+=2;break;case 26:t=j.getUint32(c),c+=4;break}return t}function Ve(){if(O.getShared){let t=Ot(()=>(p=null,O.getShared()))||{},e=t.structures||[];O.sharedVersion=t.version,K=O.sharedValues=t.packedValues,_===!0?O.structures=_=e:_.splice.apply(_,[0,e.length].concat(e))}}function Ot(t){let e=V,r=c,s=be,n=me,o=se,f=ge,b=re,y=q,v=B,m=new Uint8Array(p.slice(0,V)),x=_,R=O,L=Se,U=t();return V=e,c=r,be=s,me=n,se=o,ge=f,re=b,q=y,B=v,p=m,Se=L,_=x,O=R,j=new DataView(p.buffer,p.byteOffset,p.byteLength),U}function Ke(){p=null,q=null,_=null}const $e=new Array(147);for(let t=0;t<256;t++)$e[t]=+("1e"+Math.floor(45.15-t*.30103));let qe=new he({useRecords:!1});const kr=qe.decode;qe.decodeMultiple;let xe;try{xe=new TextEncoder}catch{}let Je,It;const Re=typeof globalThis=="object"&&globalThis.Buffer,ve=typeof Re<"u",We=ve?Re.allocUnsafeSlow:Uint8Array,Mt=ve?Re:Uint8Array,xt=256,Rt=ve?4294967296:2144337920;let He,l,C,i=0,Q,D=null;const Or=61440,Ir=/[\u0080-\uFFFF]/,$=Symbol("record-id");class Tt extends he{constructor(e){super(e),this.offset=0;let r,s,n,o,f;e=e||{};let b=Mt.prototype.utf8Write?function(a,w){return l.utf8Write(a,w,l.byteLength-w)}:xe&&xe.encodeInto?function(a,w){return xe.encodeInto(a,l.subarray(w)).written}:!1,y=this,v=e.structures||e.saveStructures,m=e.maxSharedStructures;if(m==null&&(m=v?128:0),m>8190)throw new Error("Maximum maxSharedStructure is 8190");let x=e.sequential;x&&(m=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let R,L,U=e.sharedValues,P;if(U){P=Object.create(null);for(let a=0,w=U.length;a<w;a++)P[U[a]]=a}let W=[],pe=0,H=0;this.mapEncode=function(a,w){return this._keyMap&&!this._mapped&&a.constructor.name==="Array"&&(a=a.map(d=>this.encodeKeys(d))),this.encode(a,w)},this.encode=function(a,w){if(l||(l=new We(8192),C=new DataView(l.buffer,0,8192),i=0),Q=l.length-10,Q-i<2048?(l=new We(l.length),C=new DataView(l.buffer,0,l.length),Q=l.length-10,i=0):w===Lt&&(i=i+7&2147483640),r=i,y.useSelfDescribedHeader&&(C.setUint32(i,3654940416),i+=3),f=y.structuredClone?new Map:null,y.bundleStrings&&typeof a!="string"?(D=[],D.size=1/0):D=null,s=y.structures,s){if(s.uninitialized){let h=y.getShared()||{};y.structures=s=h.structures||[],y.sharedVersion=h.version;let u=y.sharedValues=h.packedValues;if(u){P={};for(let g=0,E=u.length;g<E;g++)P[u[g]]=g}}let d=s.length;if(d>m&&!x&&(d=m),!s.transitions){s.transitions=Object.create(null);for(let h=0;h<d;h++){let u=s[h];if(!u)continue;let g,E=s.transitions;for(let S=0,A=u.length;S<A;S++){E[$]===void 0&&(E[$]=h);let M=u[S];g=E[M],g||(g=E[M]=Object.create(null)),E=g}E[$]=h|1048576}}x||(s.nextId=d)}if(n&&(n=!1),o=s||[],L=P,e.pack){let d=new Map;if(d.values=[],d.encoder=y,d.maxValues=e.maxPrivatePackedValues||(P?16:1/0),d.objectMap=P||!1,d.samplingPackedValues=R,Te(a,d),d.values.length>0){l[i++]=216,l[i++]=51,G(4);let h=d.values;k(h),G(0),G(0),L=Object.create(P||null);for(let u=0,g=h.length;u<g;u++)L[h[u]]=u}}He=w&Xe;try{if(He)return;if(k(a),D&&Ut(r,k),y.offset=i,f&&f.idsToInsert){i+=f.idsToInsert.length*2,i>Q&&le(i),y.offset=i;let d=Rr(l.subarray(r,i),f.idsToInsert);return f=null,d}return w&Lt?(l.start=r,l.end=i,l):l.subarray(r,i)}finally{if(s){if(H<10&&H++,s.length>m&&(s.length=m),pe>1e4)s.transitions=null,H=0,pe=0,W.length>0&&(W=[]);else if(W.length>0&&!x){for(let d=0,h=W.length;d<h;d++)W[d][$]=void 0;W=[]}}if(n&&y.saveShared){y.structures.length>m&&(y.structures=y.structures.slice(0,m));let d=l.subarray(r,i);return y.updateSharedData()===!1?y.encode(a):d}w&Cr&&(i=r)}},this.findCommonStringsToPack=()=>(R=new Map,P||(P=Object.create(null)),a=>{let w=a&&a.threshold||4,d=this.pack?a.maxPrivatePackedValues||16:0;U||(U=this.sharedValues=[]);for(let[h,u]of R)u.count>w&&(P[h]=d++,U.push(h),n=!0);for(;this.saveShared&&this.updateSharedData()===!1;);R=null});const k=a=>{i>Q&&(l=le(i));var w=typeof a,d;if(w==="string"){if(L){let E=L[a];if(E>=0){E<16?l[i++]=E+224:(l[i++]=198,E&1?k(15-E>>1):k(E-16>>1));return}else if(R&&!e.pack){let S=R.get(a);S?S.count++:R.set(a,{count:1})}}let h=a.length;if(D&&h>=4&&h<1024){if((D.size+=h)>Or){let S,A=(D[0]?D[0].length*3+D[1].length:0)+10;i+A>Q&&(l=le(i+A)),l[i++]=217,l[i++]=223,l[i++]=249,l[i++]=D.position?132:130,l[i++]=26,S=i-r,i+=4,D.position&&Ut(r,k),D=["",""],D.size=0,D.position=S}let E=Ir.test(a);D[E?0:1]+=a,l[i++]=E?206:207,k(h);return}let u;h<32?u=1:h<256?u=2:h<65536?u=3:u=5;let g=h*3;if(i+g>Q&&(l=le(i+g)),h<64||!b){let E,S,A,M=i+u;for(E=0;E<h;E++)S=a.charCodeAt(E),S<128?l[M++]=S:S<2048?(l[M++]=S>>6|192,l[M++]=S&63|128):(S&64512)===55296&&((A=a.charCodeAt(E+1))&64512)===56320?(S=65536+((S&1023)<<10)+(A&1023),E++,l[M++]=S>>18|240,l[M++]=S>>12&63|128,l[M++]=S>>6&63|128,l[M++]=S&63|128):(l[M++]=S>>12|224,l[M++]=S>>6&63|128,l[M++]=S&63|128);d=M-i-u}else d=b(a,i+u,g);d<24?l[i++]=96|d:d<256?(u<2&&l.copyWithin(i+2,i+1,i+1+d),l[i++]=120,l[i++]=d):d<65536?(u<3&&l.copyWithin(i+3,i+2,i+2+d),l[i++]=121,l[i++]=d>>8,l[i++]=d&255):(u<5&&l.copyWithin(i+5,i+3,i+3+d),l[i++]=122,C.setUint32(i,d),i+=4),i+=d}else if(w==="number")if(!this.alwaysUseFloat&&a>>>0===a)a<24?l[i++]=a:a<256?(l[i++]=24,l[i++]=a):a<65536?(l[i++]=25,l[i++]=a>>8,l[i++]=a&255):(l[i++]=26,C.setUint32(i,a),i+=4);else if(!this.alwaysUseFloat&&a>>0===a)a>=-24?l[i++]=31-a:a>=-256?(l[i++]=56,l[i++]=~a):a>=-65536?(l[i++]=57,C.setUint16(i,~a),i+=2):(l[i++]=58,C.setUint32(i,~a),i+=4);else if(!this.alwaysUseFloat&&a<0&&a>=-4294967296&&Math.floor(a)===a)l[i++]=58,C.setUint32(i,-1-a),i+=4;else{let h;if((h=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){l[i++]=250,C.setFloat32(i,a);let u;if(h<4||(u=a*$e[(l[i]&127)<<1|l[i+1]>>7])>>0===u){i+=4;return}else i--}l[i++]=251,C.setFloat64(i,a),i+=8}else if(w==="object")if(!a)l[i++]=246;else{if(f){let u=f.get(a);if(u){if(l[i++]=216,l[i++]=29,l[i++]=25,!u.references){let g=f.idsToInsert||(f.idsToInsert=[]);u.references=[],g.push(u)}u.references.push(i-r),i+=2;return}else f.set(a,{offset:i-r})}let h=a.constructor;if(h===Object)this.skipFunction===!0&&(a=Object.fromEntries([...Object.keys(a).filter(u=>typeof a[u]!="function").map(u=>[u,a[u]])])),z(a);else if(h===Array){d=a.length,d<24?l[i++]=128|d:G(d);for(let u=0;u<d;u++)k(a[u])}else if(h===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(l[i++]=217,l[i++]=1,l[i++]=3),d=a.size,d<24?l[i++]=160|d:d<256?(l[i++]=184,l[i++]=d):d<65536?(l[i++]=185,l[i++]=d>>8,l[i++]=d&255):(l[i++]=186,C.setUint32(i,d),i+=4),y.keyMap)for(let[u,g]of a)k(y.encodeKey(u)),k(g);else for(let[u,g]of a)k(u),k(g);else{for(let u=0,g=Je.length;u<g;u++){let E=It[u];if(a instanceof E){let S=Je[u],A=S.tag;A==null&&(A=S.getTag&&S.getTag.call(this,a)),A<24?l[i++]=192|A:A<256?(l[i++]=216,l[i++]=A):A<65536?(l[i++]=217,l[i++]=A>>8,l[i++]=A&255):A>-1&&(l[i++]=218,C.setUint32(i,A),i+=4),S.encode.call(this,a,k,le);return}}if(a[Symbol.iterator]){if(He){let u=new Error("Iterable should be serialized as iterator");throw u.iteratorNotHandled=!0,u}l[i++]=159;for(let u of a)k(u);l[i++]=255;return}if(a[Symbol.asyncIterator]||Ge(a)){let u=new Error("Iterable/blob should be serialized as iterator");throw u.iteratorNotHandled=!0,u}if(this.useToJSON&&a.toJSON){const u=a.toJSON();if(u!==a)return k(u)}z(a)}}else if(w==="boolean")l[i++]=a?245:244;else if(w==="bigint"){if(a<BigInt(1)<<BigInt(64)&&a>=0)l[i++]=27,C.setBigUint64(i,a);else if(a>-(BigInt(1)<<BigInt(64))&&a<0)l[i++]=59,C.setBigUint64(i,-a-BigInt(1));else if(this.largeBigIntToFloat)l[i++]=251,C.setFloat64(i,Number(a));else{a>=BigInt(0)?l[i++]=194:(l[i++]=195,a=BigInt(-1)-a);let h=[];for(;a;)h.push(Number(a&BigInt(255))),a>>=BigInt(8);Ze(new Uint8Array(h.reverse()),le);return}i+=8}else if(w==="undefined")l[i++]=247;else throw new Error("Unknown type: "+w)},z=this.useRecords===!1?this.variableMapSize?a=>{let w=Object.keys(a),d=Object.values(a),h=w.length;if(h<24?l[i++]=160|h:h<256?(l[i++]=184,l[i++]=h):h<65536?(l[i++]=185,l[i++]=h>>8,l[i++]=h&255):(l[i++]=186,C.setUint32(i,h),i+=4),y.keyMap)for(let u=0;u<h;u++)k(y.encodeKey(w[u])),k(d[u]);else for(let u=0;u<h;u++)k(w[u]),k(d[u])}:a=>{l[i++]=185;let w=i-r;i+=2;let d=0;if(y.keyMap)for(let h in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(h))&&(k(y.encodeKey(h)),k(a[h]),d++);else for(let h in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(h))&&(k(h),k(a[h]),d++);l[w+++r]=d>>8,l[w+r]=d&255}:(a,w)=>{let d,h=o.transitions||(o.transitions=Object.create(null)),u=0,g=0,E,S;if(this.keyMap){S=Object.keys(a).map(M=>this.encodeKey(M)),g=S.length;for(let M=0;M<g;M++){let ht=S[M];d=h[ht],d||(d=h[ht]=Object.create(null),u++),h=d}}else for(let M in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(M))&&(d=h[M],d||(h[$]&1048576&&(E=h[$]&65535),d=h[M]=Object.create(null),u++),h=d,g++);let A=h[$];if(A!==void 0)A&=65535,l[i++]=217,l[i++]=A>>8|224,l[i++]=A&255;else if(S||(S=h.__keys__||(h.__keys__=Object.keys(a))),E===void 0?(A=o.nextId++,A||(A=0,o.nextId=1),A>=xt&&(o.nextId=(A=m)+1)):A=E,o[A]=S,A<m){l[i++]=217,l[i++]=A>>8|224,l[i++]=A&255,h=o.transitions;for(let M=0;M<g;M++)(h[$]===void 0||h[$]&1048576)&&(h[$]=A),h=h[S[M]];h[$]=A|1048576,n=!0}else{if(h[$]=A,C.setUint32(i,3655335680),i+=3,u&&(pe+=H*u),W.length>=xt-m&&(W.shift()[$]=void 0),W.push(h),G(g+2),k(57344+A),k(S),w)return;for(let M in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(M))&&k(a[M]);return}if(g<24?l[i++]=128|g:G(g),!w)for(let M in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(M))&&k(a[M])},le=a=>{let w;if(a>16777216){if(a-r>Rt)throw new Error("Encoded buffer would be larger than maximum buffer size");w=Math.min(Rt,Math.round(Math.max((a-r)*(a>67108864?1.25:2),4194304)/4096)*4096)}else w=(Math.max(a-r<<2,l.length-1)>>12)+1<<12;let d=new We(w);return C=new DataView(d.buffer,0,w),l.copy?l.copy(d,0,r,a):d.set(l.slice(r,a)),i-=r,r=0,Q=d.length-10,l=d};let ee=100,ft=1e3;this.encodeAsIterable=function(a,w){return ut(a,w,ce)},this.encodeAsAsyncIterable=function(a,w){return ut(a,w,dt)};function*ce(a,w,d){let h=a.constructor;if(h===Object){let u=y.useRecords!==!1;u?z(a,!0):Ct(Object.keys(a).length,160);for(let g in a){let E=a[g];u||k(g),E&&typeof E=="object"?w[g]?yield*ce(E,w[g]):yield*_e(E,w,g):k(E)}}else if(h===Array){let u=a.length;G(u);for(let g=0;g<u;g++){let E=a[g];E&&(typeof E=="object"||i-r>ee)?w.element?yield*ce(E,w.element):yield*_e(E,w,"element"):k(E)}}else if(a[Symbol.iterator]&&!a.buffer){l[i++]=159;for(let u of a)u&&(typeof u=="object"||i-r>ee)?w.element?yield*ce(u,w.element):yield*_e(u,w,"element"):k(u);l[i++]=255}else Ge(a)?(Ct(a.size,64),yield l.subarray(r,i),yield a,ye()):a[Symbol.asyncIterator]?(l[i++]=159,yield l.subarray(r,i),yield a,ye(),l[i++]=255):k(a);d&&i>r?yield l.subarray(r,i):i-r>ee&&(yield l.subarray(r,i),ye())}function*_e(a,w,d){let h=i-r;try{k(a),i-r>ee&&(yield l.subarray(r,i),ye())}catch(u){if(u.iteratorNotHandled)w[d]={},i=r+h,yield*ce.call(this,a,w[d]);else throw u}}function ye(){ee=ft,y.encode(null,Xe)}function ut(a,w,d){return w&&w.chunkThreshold?ee=ft=w.chunkThreshold:ee=100,a&&typeof a=="object"?(y.encode(null,Xe),d(a,y.iterateProperties||(y.iterateProperties={}),!0)):[y.encode(a)]}async function*dt(a,w){for(let d of ce(a,w,!0)){let h=d.constructor;if(h===Mt||h===Uint8Array)yield d;else if(Ge(d)){let u=d.stream().getReader(),g;for(;!(g=await u.read()).done;)yield g.value}else if(d[Symbol.asyncIterator])for await(let u of d)ye(),u?yield*dt(u,w.async||(w.async={})):yield y.encode(u);else yield d}}}useBuffer(e){l=e,C=new DataView(l.buffer,l.byteOffset,l.byteLength),i=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let e=this.sharedVersion||0;this.sharedVersion=e+1;let r=this.structures.slice(0),s=new Pt(r,this.sharedValues,this.sharedVersion),n=this.saveShared(s,o=>(o&&o.version||0)==e);return n===!1?(s=this.getShared()||{},this.structures=s.structures||[],this.sharedValues=s.packedValues,this.sharedVersion=s.version,this.structures.nextId=this.structures.length):r.forEach((o,f)=>this.structures[f]=o),n}}function Ct(t,e){t<24?l[i++]=e|t:t<256?(l[i++]=e|24,l[i++]=t):t<65536?(l[i++]=e|25,l[i++]=t>>8,l[i++]=t&255):(l[i++]=e|26,C.setUint32(i,t),i+=4)}class Pt{constructor(e,r,s){this.structures=e,this.packedValues=r,this.version=s}}function G(t){t<24?l[i++]=128|t:t<256?(l[i++]=152,l[i++]=t):t<65536?(l[i++]=153,l[i++]=t>>8,l[i++]=t&255):(l[i++]=154,C.setUint32(i,t),i+=4)}const Mr=typeof Blob>"u"?function(){}:Blob;function Ge(t){if(t instanceof Mr)return!0;let e=t[Symbol.toStringTag];return e==="Blob"||e==="File"}function Te(t,e){switch(typeof t){case"string":if(t.length>3){if(e.objectMap[t]>-1||e.values.length>=e.maxValues)return;let s=e.get(t);if(s)++s.count==2&&e.values.push(t);else if(e.set(t,{count:1}),e.samplingPackedValues){let n=e.samplingPackedValues.get(t);n?n.count++:e.samplingPackedValues.set(t,{count:1})}}break;case"object":if(t)if(t instanceof Array)for(let s=0,n=t.length;s<n;s++)Te(t[s],e);else{let s=!e.encoder.useRecords;for(var r in t)t.hasOwnProperty(r)&&(s&&Te(r,e),Te(t[r],e))}break;case"function":console.log(t)}}const xr=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;It=[Date,Set,Error,RegExp,ie,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,Pt],Je=[{tag:1,encode(t,e){let r=t.getTime()/1e3;(this.useTimestamp32||t.getMilliseconds()===0)&&r>=0&&r<4294967296?(l[i++]=26,C.setUint32(i,r),i+=4):(l[i++]=251,C.setFloat64(i,r),i+=8)}},{tag:258,encode(t,e){let r=Array.from(t);e(r)}},{tag:27,encode(t,e){e([t.name,t.message])}},{tag:27,encode(t,e){e(["RegExp",t.source,t.flags])}},{getTag(t){return t.tag},encode(t,e){e(t.value)}},{encode(t,e,r){Ze(t,r)}},{getTag(t){if(t.constructor===Uint8Array&&(this.tagUint8Array||ve&&this.tagUint8Array!==!1))return 64},encode(t,e,r){Ze(t,r)}},Z(68,1),Z(69,2),Z(70,4),Z(71,8),Z(72,1),Z(77,2),Z(78,4),Z(79,8),Z(85,4),Z(86,8),{encode(t,e){let r=t.packedValues||[],s=t.structures||[];if(r.values.length>0){l[i++]=216,l[i++]=51,G(4);let n=r.values;e(n),G(0),G(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let o=0,f=n.length;o<f;o++)packedObjectMap[n[o]]=o}if(s){C.setUint32(i,3655335424),i+=3;let n=s.slice(0);n.unshift(57344),n.push(new ie(t.version,1399353956)),e(n)}else e(new ie(t.version,1399353956))}}];function Z(t,e){return!xr&&e>1&&(t-=4),{tag:t,encode:function(s,n){let o=s.byteLength,f=s.byteOffset||0,b=s.buffer||s;n(ve?Re.from(b,f,o):new Uint8Array(b,f,o))}}}function Ze(t,e){let r=t.byteLength;r<24?l[i++]=64+r:r<256?(l[i++]=88,l[i++]=r):r<65536?(l[i++]=89,l[i++]=r>>8,l[i++]=r&255):(l[i++]=90,C.setUint32(i,r),i+=4),i+r>=l.length&&e(i+r),l.set(t.buffer?t:new Uint8Array(t),i),i+=r}function Rr(t,e){let r,s=e.length*2,n=t.length-s;e.sort((o,f)=>o.offset>f.offset?1:-1);for(let o=0;o<e.length;o++){let f=e[o];f.id=o;for(let b of f.references)t[b++]=o>>8,t[b]=o&255}for(;r=e.pop();){let o=r.offset;t.copyWithin(o+s,o,n),s-=2;let f=o+s;t[f++]=216,t[f++]=28,n=o}return t}function Ut(t,e){C.setUint32(D.position+t,i-D.position-t+1);let r=D;D=null,e(r[0]),e(r[1])}let Ye=new Tt({useRecords:!1});const Tr=Ye.encode;Ye.encodeAsIterable,Ye.encodeAsAsyncIterable;const Lt=512,Cr=1024,Xe=2048;class Pr extends Qt{constructor(e){e||(e={}),e.objectMode=!0,super(e),e.structures=[],this.decoder=e.decoder||new he(e)}_transform(e,r,s){this.incompleteBuffer&&(e=Buffer.concat([this.incompleteBuffer,e]),this.incompleteBuffer=null);let n;try{n=this.decoder.decodeMultiple(e)}catch(o){if(o.incomplete)this.incompleteBuffer=e.slice(o.lastPosition),n=o.values;else return s(o)}finally{for(let o of n||[])o===null&&(o=this.getNullValue()),this.push(o)}s()}getNullValue(){return Symbol.for(null)}}const Ur=process.env.CBOR_NATIVE_ACCELERATION_DISABLED!==void 0&&process.env.CBOR_NATIVE_ACCELERATION_DISABLED.toLowerCase()==="true";if(!Ur){let t;try{typeof require=="function"?t=require("cbor-extract"):t=er(import.meta.url)("cbor-extract"),t&&pr(t.extractStrings)}catch{}}class Lr{#e=new EventTarget;addEventListener(e,r,s){return this.#e.addEventListener(e,r,s),()=>{this.#e.removeEventListener(e,r,s)}}removeEventListener(e,r,s){this.#e.removeEventListener(e,r,s)}dispatchEvent(e){return this.#e.dispatchEvent(e)}}const T=Symbol.for("@appetizeio/rpc:rpcMethods");class _r extends Lr{send;constructor(e){super(),this.send=e}dispatchClose(e){return this.dispatchEvent(new CloseEvent("close",e))}dispatchMessage(e){return this.dispatchEvent(new CustomEvent("message",{detail:e}))}}function Qe(t){return!!t&&typeof t=="object"&&"jsonrpc"in t}function Br(){let t,e;return{promise:new Promise((s,n)=>{e=s,t=n}),reject:t,resolve:e}}class Ae{closed=!1;[T];#e;constructor(e,{signal:r}={}){this[T]=new _r(e),this.#e=r,this.#e?.addEventListener("abort",this.#t)}close(e={}){this.closed||(this.closed=!0,this.handleClose(e))}handleClose(e){this.#e?.removeEventListener("abort",this.#t),this[T].dispatchClose(e)}#t=()=>{this.close({code:1e3,reason:String(this.#e?.reason)})}}const _t={useRecords:!1},Nr=new Tt(_t);class Bt extends Ae{#e=[];#t;constructor(e,{signal:r}={}){super(async f=>{this.#t.write(Nr.encode(f))},{signal:r}),this.#t=e;const s=new Pr(_t);s.on("data",f=>{Qe(f)&&this[T].dispatchMessage(f)}),s.on("error",()=>{this.close()});const n=f=>{s.write(f)},o=()=>{this.close()};e.on("data",n),e.once("close",o),e.once("error",o),this.#e.push(()=>{e.off("data",n),e.off("close",o),e.off("error",o),s.destroy()})}handleClose(e){for(const r of this.#e.splice(0))r();super.handleClose(e)}}function Dr(t,e){const{promise:r,reject:s,resolve:n}=Br(),o=tr(t),f=e?.signal,b=()=>{o.off("connect",m),o.off("error",x),f?.removeEventListener("abort",v)},y=R=>{b(),o.destroy(),s(R)},v=()=>{y(new Error("The connection was aborted"))},m=()=>{b();const R=new Bt(o,e);R[T].addEventListener("close",()=>{o.destroy()},{once:!0}),n(R)},x=R=>{y(R)};return f?.aborted?(y(new Error("The connection was aborted")),r):(o.once("connect",m),o.once("error",x),f?.addEventListener("abort",v,{once:!0}),r)}const Nt=Be("appetize.io:error:rpc");function et(t,e){const r=new rr(new sr({errorListener:Nt}),Fr(t),{errorListener:Nt}),s=t[T].addEventListener("message",({detail:o})=>{r.receiveAndSend(o)}),n=t[T].addEventListener("close",()=>{s(),r.rejectAllPendingRequests("Transport closed")},{once:!0});for(const o in e){const f=e[o];f&&r.addMethod(o,f.bind(e))}return{rpc:r,unsub:()=>{s(),n()}}}function Dt(t,e){const{rpc:r,unsub:s}=et(t,e);return{client:r.client,unsub:s}}function Ce(t,e){const r=t[T].addEventListener("message",({detail:n})=>{if("method"in n)try{e({method:n.method,param:n.params})}catch{}}),s=t[T].addEventListener("close",r,{once:!0});return()=>{r(),s()}}function Fr(t){return new nr(t[T].send.bind(t[T]),()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)+1)}function tt(t,e,{leftEffects:r=()=>({}),notifiesLeft:s,notifiesRight:n,rightEffects:o=()=>({})}={}){const f=et(t,{}),b=et(e,{}),y=[()=>{f.unsub(),b.unsub()}],v=()=>{for(const U of y)try{U()}catch{}},m=b.rpc.client,x=f.rpc.client;y.push(t[T].addEventListener("close",()=>{v()},{once:!0}),e[T].addEventListener("close",()=>{v()},{once:!0}));const R=r(m,x);for(const U in R){const P=R[U];P&&f.rpc.addMethod(U,P)}const L=o(x,m);for(const U in L){const P=L[U];P&&b.rpc.addMethod(U,P)}return Ft(f.rpc,b.rpc,{notifies:s}),Ft(b.rpc,f.rpc,{notifies:n}),v}function Ft(t,e,{notifies:r}={}){t.applyServerMiddleware(async(s,n)=>{const o=r?.();if(o){const{id:b,...y}=n;o[T].send(y)}if(t.hasMethod(n.method))return await s(n);if(!n.id)return e.notify(n.method,n.params),null;const f=await e.request(n.method,n.params);return{id:n.id,jsonrpc:ir,result:f}})}function X(t,...e){t.notify(e[0],e[1],e[2])}const zr=(...t)=>Dt(...t),rt=["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Backspace","Enter","Tab"];function st(){const t=new Ae(async r=>{e[T].dispatchMessage(r)}),e=new Ae(async r=>{t[T].dispatchMessage(r)});return t[T].addEventListener("close",()=>{e.close()},{once:!0}),e[T].addEventListener("close",()=>{t.close()},{once:!0}),[t,e]}function zt(t,e){const r=[],s=()=>{for(const n of r)n()};r.push(t[T].addEventListener("message",n=>e[T].send(n.detail))),r.push(t[T].addEventListener("close",s,{once:!0})),r.push(e[T].addEventListener("message",n=>t[T].send(n.detail))),r.push(e[T].addEventListener("close",s,{once:!0}))}const ae=Be("appetize.io:trace:transport:iframe");class jt extends Ae{onmessage;#e;#t;constructor(e,{origin:r="*",signal:s}={}){super(async n=>{e.postMessage(n,this.#e)},{signal:s}),this.#t=e,this.#e=r,window.addEventListener("message",this.#r)}postMessage(e,r,s){ae("postMessage(legacy)",{message:e,targetOrigin:r,transfer:s}),this.#t.postMessage(e,r??this.#e,s)}handleClose(e){ae("close()"),window.removeEventListener("message",this.#r),super.handleClose(e)}#r=async e=>{if(ae("handleMessage()",e),e.source!==this.#t||(ae("handleMessage() -> source ok"),this.#e!=="*"&&e.origin!==this.#e))return;ae("handleMessage() -> origin ok");const r=e.data;if(!Qe(r)){ae("handleMessage() -> legacy"),this.onmessage?.(e);return}ae("handleMessage() -> jsonrpc"),this[T].dispatchMessage(r)}}function Pe(){let t,e;return{promise:new Promise((s,n)=>{e=s,t=n}),reject:t,resolve:e}}const jr=2*1024*1024,Vt=Be("appetize:client:acked-writable-stream");class Vr{unacked=0;#e;#t;#r;#s;#n=[];#i;constructor(e){this.#r=e,this.#i=e.window??jr}abort(e){this.#a(e),this.#r.onAbort?.(e)}async close(){await this.#l(()=>this.unacked===0),this.#r.onClose?.()}fail(e){this.#a(e)&&this.#r.onError?.(e)}start(e){this.#e=e}write(e){const r=e.byteLength;return this.unacked+=r,this.#r.send(e).then(()=>{this.unacked-=r,this.#s&&(this.#s.acked+=r),this.#o()},s=>{this.fail(s)}),this.unacked>=this.#i&&!this.#s&&(this.#s={acked:0,at:performance.now()},Vt("window full: %d bytes unacked, writes stalled",this.unacked)),this.#l(()=>this.unacked<this.#i)}#o(){if(this.#s&&this.unacked<=this.#i/2){const e=performance.now()-this.#s.at;Vt("pressure relieved after %dms: %d bytes acked, %s MB/s",Math.round(e),this.#s.acked,(this.#s.acked/Math.max(e,1)/1e3).toFixed(2)),this.#s=void 0}this.#n=this.#n.filter(e=>e.until()?(e.resolve(void 0),!1):!0)}#a(e){if(this.#t)return!1;this.#t={reason:e},this.#e.error(e);const r=this.#n;this.#n=[];for(const s of r)s.reject(e);return!0}#l(e){if(e())return Promise.resolve();const r={...Pe(),until:e};return this.#n.push(r),r.promise}}class Kr extends WritableStream{get unacked(){return this.#e.unacked}#e;constructor(e){const r=new Vr(e);super({abort:s=>{r.abort(s)},close:()=>r.close(),start:s=>{r.start(s)},write:s=>r.write(s)}),this.#e=r}fail(e){this.#e.fail(e)}}const $r=1024*1024;class qr{#e;#t=!1;#r;#s;constructor(e){this.#r=e}cancel(e){this.#n(),this.#r?.(e)}close(){this.#n()&&this.#e.close()}error(e){this.#n()&&this.#e.error(e)}pull(){const e=this.#s;this.#s=void 0,e?.resolve(void 0)}async push(e){if(this.#t)return;this.#s??=Pe();const{promise:r}=this.#s;this.#e.enqueue(e),await r}start(e){this.#e=e}#n(){return this.#t?!1:(this.#t=!0,this.pull(),!0)}}class Jr extends ReadableStream{#e;constructor({highWaterMark:e=$r,onCancel:r}={}){const s=new qr(r);super({cancel:n=>{s.cancel(n)},pull:()=>{s.pull()},start:n=>{s.start(n)}},new ByteLengthQueuingStrategy({highWaterMark:e})),this.#e=s}close(){this.#e.close()}error(e){this.#e.error(e)}push(e){return this.#e.push(e)}}class Wr{closed;readable;writable;#e=[];#t;#r;#s;#n;#i;#o="starting";constructor(e,{onClose:r,receiveBuffer:s,sendWindow:n,signal:o}){if(this.#i=e,this.#t=Pe(),this.closed=this.#t.promise,this.closed.catch(Hr),this.#s=new Jr({highWaterMark:s,onCancel:()=>{this.#a(void 0)}}),this.readable=this.#s,this.#n=new Kr({onAbort:()=>{this.#a(void 0)},onClose:()=>{this.#a(void 0)},onError:f=>{this.#a(f)},send:f=>e.request("appetizeio.device.server.debug.adbTunnel.data",{data:f}),window:n}),this.writable=this.#n,o){const f=()=>{this.#a(o.reason)};o.addEventListener("abort",f,{once:!0}),this.#e.push(()=>{o.removeEventListener("abort",f)})}this.#e.push(()=>{r(this)})}close=()=>{this.#a(void 0)};detach(){this.#a(void 0,{notifyServer:!1})}async handleData(e){this.#o==="open"&&await this.#s.push(e)}handleStopped({error:e}){this.#o==="open"&&this.#a(e?new Error(e):void 0)}async start(){try{await this.#i.request("appetizeio.device.server.debug.adbTunnel.start",void 0)}catch(e){throw this.#a(e),e}if(this.#o==="closed")throw this.#r?this.#r:new Error("The adb tunnel closed before it started");this.#o="open"}async[Symbol.asyncDispose](){this.close();try{await this.closed}catch{}}#a(e,{notifyServer:r=!0}={}){if(this.#o!=="closed"){this.#o="closed",this.#r=e,r&&X(this.#i,"appetizeio.device.server.debug.adbTunnel.stop",void 0),e?(this.#s.error(e),this.#n.fail(e)):(this.#s.close(),this.#n.fail(new Error("The adb tunnel has stopped")));for(const s of this.#e)s();e?this.#t.reject(e):this.#t.resolve(void 0)}}}function Hr(){}class Gr{readable;ready;#e=[];#t=!1;#r;#s;#n;constructor({label:e,onClose:r,signal:s}){this.#s=e,this.ready=new Promise((o,f)=>{this.#n={reject:f,resolve:o}});let n;if(this.readable=new ReadableStream({cancel:()=>{this.#o()},start:o=>{n=o}}),!n)throw new Error("ReadableStream controller was not initialized");if(this.#r=n,s){const o=()=>{this.fail(s.reason)};s.addEventListener("abort",o,{once:!0}),this.#e.push(()=>{s.removeEventListener("abort",o)})}this.#e.push(()=>{r(this)})}close=()=>{this.#i()};fail(e){this.#i(e)}handleItem(e){this.#r.enqueue(e)}markReady(){if(!this.#n)return;const{resolve:e}=this.#n;this.#n=void 0,e(this)}async*[Symbol.asyncIterator](){const e=this.readable.getReader();try{for(let r=await e.read();!r.done;r=await e.read())yield r.value}finally{await e.cancel()}}#i(e){this.#t||(this.#r.close(),this.#o(e))}#o(e){this.#t=!0;for(const r of this.#e)r();this.#n?.reject(e??new Error(`${this.#s} closed before it started`)),this.#n=void 0}}class Zr{get subscribers(){return this.#r}#e;#t;#r=new Set;constructor(e){this.#e=e}close(){this.#t=void 0;for(const e of[...this.#r])e.close();this.#r.clear()}add(e){this.#r.add(e)}ensureStarted(){return this.#t||(this.#t=(async()=>{try{return await this.#e.start()}catch(e){throw this.#t=void 0,e}})()),this.#t}release(e){this.#r.delete(e),!(this.#r.size>0||!this.#t)&&(this.#t=void 0,this.#e.stop())}}class Kt extends Zr{#e;constructor(e){super({start:e.start,stop:e.stop}),this.#e=e.label}async createStream({signal:e}={}){e?.throwIfAborted();const r=new Gr({label:this.#e,onClose:s=>{this.release(s)},signal:e});this.add(r);try{await this.ensureStarted(),r.markReady()}catch(s){r.fail(s)}return await r.ready}handleNotification(e){for(const r of this.subscribers)r.handleItem(e)}}class Yr{#e;#t;#r;#s;constructor(e){this.#s=e,this.#t=new Kt({label:"Log stream",start:()=>e.request("appetizeio.device.server.debug.log.start"),stop:()=>{X(e,"appetizeio.device.server.debug.log.stop",void 0)}}),this.#r=new Kt({label:"Proxy intercept stream",start:()=>e.request("appetizeio.device.server.debug.proxyIntercept.start"),stop:()=>{X(e,"appetizeio.device.server.debug.proxyIntercept.stop",void 0)}})}close(){this.#e?.detach(),this.#t.close(),this.#r.close()}async createAdbTunnel({signal:e}={}){e?.throwIfAborted(),this.#e?.close();const r=new Wr(this.#s,{onClose:()=>{this.#e=void 0},signal:e});return this.#e=r,await r.start(),r}async createLogStream(e){return await this.#t.createStream(e)}async createProxyInterceptStream(e){return await this.#r.createStream(e)}async handleAdbTunnelData({data:e}){await this.#e?.handleData(e)}handleAdbTunnelStopped(e){this.#e?.handleStopped(e)}handleLogEntry(e){this.#t.handleNotification(e)}handleProxyInterceptEvent(e){this.#r.handleNotification(e)}}function nt(t){return{...Xr(t),index:t.index,within:t.within?nt(t.within):void 0}}function Xr(t){switch(t.by){case"testId":return{by:"testId",testId:t.testId};case"text":return{by:"text",text:Qr(t.text)}}}function Qr(t){return typeof t=="string"?{kind:"exact",value:t}:{flags:t.flags,kind:"regex",source:t.source}}function es(t){return{press:e=>{X(t,"appetizeio.device.server.keyboard.press",{key:e})}}}function ts({onRequest:t,parent:e,proxyInlet:r,signal:s}){const n=new jt(e,{signal:s}),o=[()=>{n.close()}];return zt(n,r),t&&o.push(Ce(n,f=>{t(f,{source:"parent"})})),{cleanup:()=>{for(const f of o)f()},notifies:()=>e===globalThis.window?void 0:n}}const rs="@appetizeio/rpc:playwrightAdapter",Ue=Symbol.for(rs);function ss(t){window[Ue]&&console.warn("playwright exposed more than once, overwriting previous adapter");const e={send(r){t[T].send(r)},subscribe(r){return t[T].addEventListener("message",s=>{r(s.detail)})}};return window[Ue]=e,()=>{window[Ue]===e&&delete window[Ue]}}function ns({onRequest:t,proxyInlet:e}){const[r,s]=st(),o=[ss(s),()=>{r.close()}];return zt(r,e),t&&o.push(Ce(r,f=>{t(f,{source:"parent"})})),{cleanup:()=>{for(const f of o)f()},notifies:()=>r}}function Le(t){return t.by==="position"?{by:"position",x:t.x,y:t.y}:{...nt(t),x:t.x,y:t.y}}function is(t){return"to"in t?{from:Le(t.from),kind:"path",to:Le(t.to)}:{direction:t.direction,distance:t.distance,from:t.from?Le(t.from):void 0,kind:"direction"}}function os(t){return{down:(e,r)=>{X(t,"appetizeio.device.server.touch.down",{x:e,y:r})},move:(e,r)=>{X(t,"appetizeio.device.server.touch.move",{x:e,y:r})},up:(e,r)=>{X(t,"appetizeio.device.server.touch.up",{x:e,y:r})}}}const as=new Set(rt),ls=/^(?<key>[A-Za-z]+)>(?<repeat>\d+)\/$/u,cs=/(\{\{|\{[^{}]*\})/u;function fs(t){const e=[];let r="";function s(){r.length>0&&(e.push({kind:"text",text:r}),r="")}for(const[n,o]of t.split(cs).entries())if(n%2===0){if(o.includes("{"))throw new Error(`Unclosed "{" in ${JSON.stringify(t)}`);r+=o}else o==="{{"?r+="{":(s(),e.push(ds(o.slice(1,-1))));return s(),e}function us(t,e){if(!as.has(t))throw e.endsWith(">")?new Error(`Holding a key is not supported: {${e}}`):e.startsWith("/")?new Error(`Releasing a key is not supported: {${e}}`):new Error(`{${e}} does not name a supported key. Supported: ${rt.join(", ")}. Type characters as text, and escape a literal "{" as "{{".`)}function ds(t){const e=ls.exec(t)?.groups,r=e?.key??t;if(us(r,t),!e)return{key:r,kind:"press"};const s=Number(e.repeat);if(s<1)throw new Error(`Repeat for {${t}} must be at least 1`);return{key:r,kind:"press",repeat:s}}const hs=Symbol("@appetizeio/client:v1Compat");function $t(t){return t?.[hs]}class ps{readable;ready;get dimensions(){return this.#s}#e=[];#t=!1;#r;#s;#n;#i;constructor({onClose:e,requestKeyFrame:r,signal:s}){this.#n=r,this.ready=new Promise((o,f)=>{this.#i={reject:f,resolve:o}});let n;if(this.readable=new ReadableStream({cancel:()=>{this.#a()},start:o=>{n=o}}),!n)throw new Error("ReadableStream controller was not initialized");if(this.#r=n,s){const o=()=>{this.fail(s.reason)};s.addEventListener("abort",o,{once:!0}),this.#e.push(()=>{s.removeEventListener("abort",o)})}this.#e.push(()=>{e(this)})}close=()=>{this.#o()};fail(e){this.#o(e)}handleChunk(e){if(this.#i){if(e.type!=="key")return;const{resolve:r}=this.#i;this.#i=void 0,this.#s={height:e.height,width:e.width},r(this)}else e.type==="key"&&(this.#s={height:e.height,width:e.width});this.#r.enqueue(e)}requestKeyFrame=()=>{this.#t||this.#n()};async*[Symbol.asyncIterator](){const e=this.readable.getReader();try{for(let r=await e.read();!r.done;r=await e.read())yield r.value}finally{await e.cancel()}}#o(e){this.#t||(this.#r.close(),this.#a(e))}#a(e){this.#t=!0;for(const r of this.#e)r();this.#i?.reject(e??new Error("Video stream closed before the first key chunk")),this.#i=void 0}}class ys{#e=!1;#t;#r;#s=new Set;constructor(e){this.#t=e}close(){this.#r=void 0;for(const e of[...this.#s])e.close()}async createStream({signal:e}={}){e?.throwIfAborted();const r=new ps({onClose:s=>{this.#i(s)},requestKeyFrame:()=>{this.#o()},signal:e});this.#s.add(r);try{await this.#n()}catch(s){r.fail(s)}return await r.ready}handleChunk(e){e.type==="key"&&(this.#e=!1);for(const r of this.#s)r.handleChunk(e)}#n(){return this.#r?(this.#o(),this.#r):(this.#e=!0,this.#r=(async()=>{try{await this.#t.request("appetizeio.device.server.video.start")}catch(e){throw this.#r=void 0,e}})(),this.#r)}#i(e){this.#s.delete(e),!(this.#s.size>0||!this.#r)&&(this.#r=void 0,X(this.#t,"appetizeio.device.server.video.stop",void 0))}#o(){this.#e||(this.#e=!0,X(this.#t,"appetizeio.device.server.video.requestKeyFrame",void 0))}}class ws{debug;keyboard;touch;video;#e;#t=[];#r;constructor(e,r={}){const s=$t(r)??{},{baseUrl:n,onClose:o,signal:f}=r;this.#e=n?bs(n):void 0;const{onRequest:b,parent:y,proxyRequest:v}=s,m=gs(b);f?.addEventListener("abort",this.close);const[x,R]=st(),[L,U]=st();this.#t.push(()=>{x.close(),R.close(),L.close(),U.close()}),this.#t.push(tt(U,e,{leftEffects:v}));const P=y==="playwright"?ns({onRequest:m,proxyInlet:L}):y?ts({onRequest:m,parent:y,proxyInlet:L,signal:f}):void 0;P&&this.#t.push(P.cleanup),this.#t.push(tt(R,L,{notifiesLeft:P?.notifies}));const{client:W,unsub:pe}=zr(x,{"appetizeio.device.client.debug.adbTunnel.data":z=>H.handleAdbTunnelData(z),"appetizeio.device.client.debug.adbTunnel.stopped":async z=>{H.handleAdbTunnelStopped(z)},"appetizeio.device.client.debug.log.entry":async z=>{H.handleLogEntry(z)},"appetizeio.device.client.debug.proxyIntercept.event":async z=>{H.handleProxyInterceptEvent(z)},"appetizeio.device.client.video.chunk":async z=>{k.handleChunk(z)}});this.#r=W,this.#t.push(pe);const H=new Yr(this.#r);this.#t.push(()=>{H.close()});const k=new ys(this.#r);this.#t.push(()=>{k.close()}),this.debug=H,this.keyboard=es(this.#r),this.touch=os(this.#r),this.video=k,m&&(this.#t.push(Ce(R,z=>{m(z,{source:"self"})})),e instanceof jt&&this.#t.push(Ce(e,z=>{m(z,{source:"iframe"})}))),this.#t.push(()=>o?.())}close=()=>{for(const e of this.#t)try{e()}catch(r){console.error("Device cleanup error:",r)}};async inspect(e,r){return await this.#r.request("appetizeio.device.server.inspect",{options:r,selector:e?nt(e):void 0})}async press(e){await this.#r.request("appetizeio.device.server.press",{action:e})}async rotate(e){return await this.#r.request("appetizeio.device.server.rotate",{orientation:e})}async screenshot(){const e=await this.#r.request("appetizeio.device.server.screenshot"),r=this.#e?new URL(e.url,this.#e).href:e.url,s=await fetch(r);if(!s.ok)throw new Error(`Screenshot download failed: ${String(s.status)} ${s.statusText}`);const n=s.headers.get("content-type")??"application/octet-stream";return{data:new Uint8Array(await s.arrayBuffer()),mimeType:n}}async swipe(e,r){await this.#r.request("appetizeio.device.server.swipe",{gesture:is(e),options:r})}async tap(e,r){await this.#r.request("appetizeio.device.server.tap",{options:r,selector:Le(e)})}async type(e,r){await this.#r.request("appetizeio.device.server.type",{options:r,steps:fs(e)})}}function bs(t){const e=new URL(t);return e.protocol==="ws:"?e.protocol="http:":e.protocol==="wss:"&&(e.protocol="https:"),e.href}const gs=t=>{if(t)return(e,r)=>{e.method.startsWith("appetizeio.device.server.")&&t(e,r)}};function ms(t,e){const r=qt(t,e);return r===void 0?void 0:Jt(r,e)}function qt(t,e){if(t===void 0)return;const r=typeof t=="boolean"?Number.NaN:Number(t);if(!Number.isFinite(r))throw new Error(`${e} expects a number, e.g., ${e}=-0.1`);return r}function it(t,e){if(t!==void 0){if(typeof t!="string"||t==="")throw new Error(`${e} needs a value`);return t}}function Jt(t,e){if(!(t>=0&&t<=1))throw new Error(`${e} expects a number between 0 and 1`);return t}function Es(t,e){const r=it(t,e);if(r===void 0)throw new Error(`${e} needs a value`);return r}function Ss(){const t=process.env.APPETIZE_API_TOKEN;if(!t)throw new Error("APPETIZE_API_TOKEN must be set");return t}function Wt(t){return it(t.endpoint,"--endpoint")??vs()}function vs(){const t=process.env.APPETIZE_ENDPOINT?.trim();return t===""?void 0:t}const As="https://appetize.io";async function Ht(t,{authorize:e=!0,commandOptions:r={},query:s={},...n}={}){const o=new URL(t,Wt(r)??As);for(const[y,v]of Object.entries(s))o.searchParams.set(y,v);const f=new Headers(n.headers);e&&f.set("x-api-key",Ss());const b=await fetch(o,{...n,headers:f});if(!b.ok)throw new Error(`The webserver rejected the request (${String(b.status)})`);return await b.json()}const Gt=["android","ios"];function Zt(t={}){return Ht("/api/v2/service/devices",{authorize:!1,commandOptions:t})}function ks(t){return Gt.includes(t)}async function Os(t,e={}){return(await Zt(e)).find(s=>s.id===t)?.platform}function ot(t){try{return process.kill(t,0),!0}catch{return!1}}function Is(t){let e={...t,updatedAt:new Date().toISOString()};return{path:lt(e.sessionId),save:r=>(e={...e,...r,updatedAt:new Date().toISOString()},Ls(e),e)}}function Ms(){const t=Xt();return pt(t,{recursive:!0}),cr(t).map(e=>at(e)).filter(e=>e!==void 0)}function xs(t){if(t!==void 0){const r=at(t);if(!r)throw new Error(`No session found for id ${t}`);return r}const e=Ms().filter(Us);if(e.length===0)throw new Error("No active sessions");if(e.length>1)throw new Error("Multiple active sessions; specify --session-id");return e[0]}function at(t){try{return JSON.parse(lr(lt(t),"utf8"))}catch{return}}function Rs(t){return te(ke(t),"control.sock")}function Yt(t){return te(ke(t),"daemon.log")}function Ts(t){return te(ke(t),"device.log.jsonl")}function Cs(t,e){return{daemon:Yt(t),device:Ts(t),...e==="intercept"?{network:Ps(t)}:void 0}}function Ps(t){return te(ke(t),"network.jsonl")}function ke(t){const e=te(Xt(),t);return pt(e,{recursive:!0}),e}function lt(t){return te(ke(t),"state.json")}function Xt(){return process.env.APPETIZE_CLI_HOME??te(fr(),".appetize","cli","sessions")}function Us(t){const e=t.state?.phase;return e==="ended"||e==="error"?!1:ot(t.pid)}function Ls(t){const e=lt(t.sessionId),r=`${e}.tmp`;or(r,`${JSON.stringify(t,null,2)}
|
|
2
|
+
`),ar(r,e)}const ct="APPETIZE_DAEMON_CONFIG";function _s(){const t=process.env[ct];if(!t)throw new Error(`${ct} is not set`);return JSON.parse(t)}function Bs(t){return JSON.stringify(t)}const Ns=["SIGINT","SIGTERM"],Ds=150;function Fs(t){const e=new AbortController,r=setInterval(()=>{ot(t)||(clearInterval(r),e.abort(new Error("The device session exited")))},Ds);return r.unref(),e.signal}function zs(){const t=new AbortController;for(const e of Ns)process.once(e,()=>{t.abort(new Error(`Received ${e}`))});return t.signal}function js(){"CloseEvent"in globalThis||(globalThis.CloseEvent=class extends Event{code;reason;wasClean;constructor(e,r={}){super(e,r),this.code=r.code??0,this.reason=r.reason??"",this.wasClean=r.wasClean??!1}})}export{Qe as A,$t as B,Pe as C,ws as D,_s as E,Is as F,Os as G,tt as H,Rs as I,Bt as S,Ae as T,qt as a,Zt as b,Gt as c,Dr as d,Es as e,Ht as f,Yt as g,ct as h,ks as i,at as j,Wt as k,Cs as l,zs as m,ot as n,ms as o,it as p,Dt as q,Jt as r,Bs as s,xs as t,Fs as u,rt as v,js as w,Tr as x,T as y,kr as z};
|
package/daemon.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{T as W,x as T,y as U,z as b,A as M,D as O,B as _,C as z,E as F,l as V,F as N,G as j,S as Q,H as J,I as G,m as H,w as K}from"./close-event-DSfV7BZf.js";import S from"debug";import{createServer as k}from"node:net";import{pipeline as L}from"node:stream";import{rm as B}from"node:fs/promises";import{createWriteStream as Z,existsSync as X,rmSync as Y}from"node:fs";import{pipeline as ee}from"node:stream/promises";import{EncodedVideoPacketSource as te,Output as ne,FilePathTarget as re,Mp4OutputFormat as oe,EncodedPacket as se}from"mediabunny";import"stream";import"module";import"json-rpc-2.0";import"node:os";import"node:path";const ie=S("appetize.io:transport:ws-ping"),ae=3e4;function ce(e){let t=!0;const n=()=>{t=!0};e.on("pong",n);const r=setInterval(()=>{if(!t){clearInterval(r),ie("liveness ping went unanswered, terminating"),e.terminate();return}e.readyState===e.OPEN&&(t=!1,e.ping())},ae);return{destroy(){clearInterval(r),e.off("pong",n)},pong:n}}const g=S("appetize.io:trace:transport:websocket");class A extends W{constructor(t,{signal:n}={}){super(async o=>{this.#e.send(T(o))},{signal:n}),this.wsOrUrl=t,typeof t=="string"?(this.#e=new WebSocket(t),this.#e.binaryType="arraybuffer"):this.#e=t;const r=this.#e;if(r instanceof WebSocket?(r.addEventListener("open",this.#s),r.addEventListener("message",this.#o),r.addEventListener("error",this.#r),r.addEventListener("close",this.#n),this.#t.push(()=>{r.removeEventListener("open",this.#s),r.removeEventListener("message",this.#o),r.removeEventListener("error",this.#r),r.removeEventListener("close",this.#n)})):(r.addEventListener("open",this.#s),r.addEventListener("message",this.#o),r.addEventListener("error",this.#r),r.addEventListener("close",this.#n),this.#t.push(()=>{r.removeEventListener("open",this.#s),r.removeEventListener("message",this.#o),r.removeEventListener("error",this.#r),r.removeEventListener("close",this.#n)})),this.send=r.send.bind(r),"ping"in r){const{destroy:o,pong:s}=ce(r);this.#c=s,this.#t.push(o)}}wsOrUrl;onclose;onerror;onmessage;onopen;send;get bufferedAmount(){return this.#e.bufferedAmount}get readyState(){return this.#e.readyState}#t=[];#i=!1;#a=!1;#c;#e;close({destroyWs:t=!1,...n}={}){this.closed||(this.#i=t,super.close(n))}handleClose(t){g("close()");for(const n of this.#t.splice(0))n();if((typeof this.wsOrUrl=="string"||this.#i)&&(this.#e.close(t.code,t.reason),"terminate"in this.#e)){const n=this.#e;setTimeout(()=>{n.terminate()},100)}this.#d(),super.handleClose(t)}#d(t){this.#a||(this.#a=!0,this.onclose?.(t))}#n=t=>{g("handleWebSocketClose()",t);try{this.#d(t)}finally{this.close()}};#r=t=>{g("handleWebSocketError()",t),this.onerror?.(t)};#o=async t=>{g("handleWebSocketMessage()",t),this.#c?.();const n=this.#u(t);if(!n){g("handleWebSocketMessage() -> legacy"),this.onmessage?.(t);return}g("handleWebSocketMessage() -> jsonrpc",n),this[U].dispatchMessage(n)};#s=t=>{g("handleWebSocketOpen()",t),this.onopen?.(t)};#u(t){try{const n=b(new Uint8Array(t.data));return M(n)?n:null}catch{return null}}}function v(e){return typeof e=="object"&&e!==null}function R(e){try{const t=b(new Uint8Array(e.data));if(v(t)&&typeof t.name=="string")return{name:t.name,payload:"payload"in t?t.payload:void 0}}catch{}}async function de(e,t={}){const n=t.baseUrl??(typeof e=="string"?new URL(e).origin:void 0),r=typeof e=="string"?new A(e,{signal:t.signal}):e,o=new O(r,{...t,baseUrl:n});return typeof e=="string"&&await ue(r,o,t),o}function ue(e,t,n){const r=_(n)?.onLegacyMessage;return new Promise((o,s)=>{e.onopen=()=>{o()},e.onclose=()=>{t.close(),n.signal?.aborted?s(n.signal.reason):s(new Error("The websocket was closed before the device connection was established"))},e.onerror=s,e.onmessage=i=>{const c=R(i);c&&r?.(c)}})}async function le(e,{device:t,onStateChange:n,signal:r}){r?.throwIfAborted(),n?.({device:t,phase:"starting"}),await new Promise((o,s)=>{const i=()=>{c(),s(r?.reason)},c=()=>{e.onmessage=void 0,e.onclose=void 0,r?.removeEventListener("abort",i)};e.onmessage=a=>{const d=fe(R(a),t);d&&(n?.(d),d.phase==="ready"&&(c(),o()))},e.onclose=()=>{c(),s(new Error("The device closed before it was ready"))},r?.addEventListener("abort",i,{once:!0})})}function fe(e,t){if(!e)return;if(e.name==="ready")return{device:t,phase:"ready"};if(e.name!=="launchStatus")return;switch(v(e.payload)&&typeof e.payload.status=="string"?e.payload.status:void 0){case"downloadingApp":return{device:t,phase:"downloadingApp"};case"installingApp":return{device:t,phase:"installingApp"};case"launchingApp":return{device:t,phase:"launchingApp"};default:return}}function pe(){return typeof process>"u"?void 0:process}function he(e){return{deviceType:e.id,osVersion:e.osVersion}}function we(e){return e==="intercept"?"interceptOnDemand":e}class y extends Error{code;constructor(t,n){super(n),this.name="SessionRequestError",this.code=t}}function ge(e,{onClose:t,onEvent:n,signal:r}={}){return new Promise((o,s)=>{const i=new WebSocket(e);i.binaryType="arraybuffer",i.onopen=()=>{$(i,{capabilities:{},t:"handshake"})},i.onmessage=c=>{ye(i,c,{onEvent:n,onHandshake:a=>{o({close:()=>{i.close()},id:a})}})},i.onclose=()=>{s(new y("disconnected",`The connection to ${e} closed`)),t?.()},r?.addEventListener("abort",()=>{s(r.reason),i.close()},{once:!0})})}function ye(e,t,n){const r=b(new Uint8Array(t.data));v(r)&&(r.t==="handshake"&&typeof r.id=="string"?n.onHandshake(r.id):r.name==="ping"?$(e,{name:"pong"}):typeof r.name=="string"&&n.onEvent?.(r.name,r.payload))}function $(e,t){e.send(T(t))}async function ve(e,t,{apiToken:n,onQueue:r,signal:o}={}){const s=z();Ee(s.reject,o);const i=await ge(Te(e),{onClose:()=>{s.reject(me())},onEvent:(c,a)=>{be(c,a,s,r)},signal:o});return Se(e,{apiToken:n,data:t,socketid:i.id},o).catch(s.reject),await s.promise.finally(()=>{i.close()})}function me(){return new y("disconnected","The webserver connection closed before a session was granted")}function P(e,t){return v(e)?e[t]:void 0}function be(e,t,n,r){if(e==="queue"||e==="concurrentQueue"){const o=e==="queue"?Le(t):Ae(t);o&&r?.(o)}else e==="newSession"?ke(n,t):e==="userError"&&n.reject(new y("denied",Re(t)))}function q(e,t){const n=P(e,t);return typeof n=="number"?n:void 0}function m(e,t){const n=P(e,t);return typeof n=="string"?n:void 0}async function Se(e,t,n){const r=await fetch(new URL("/api/session/request",e),{body:JSON.stringify(t),headers:{"content-type":"application/json"},method:"POST",signal:n});if(!r.ok)throw new y("denied",`The webserver rejected the session request (${String(r.status)})`)}function Ee(e,t){t?.addEventListener("abort",()=>{e(t.reason)},{once:!0})}function Te(e){const t=new URL("/client",e);return t.protocol=t.protocol==="http:"?"ws:":"wss:",t.href}function ke(e,t){const n=m(t,"path"),r=m(t,"sessionToken");n!==void 0&&r!==void 0?e.resolve({path:n,sessionToken:r}):e.reject(new y("denied","The granted session is missing its address"))}function Le(e){const t=q(e,"position");return t===void 0?void 0:{position:t,reason:"capacity"}}function Ae(e){const t=q(e,"position");if(t!==void 0)return{limit:m(e,"name")??"Queue",position:t,reason:"concurrency"}}function Re(e){return m(e,"message")??"The session request was denied"}async function $e({apiToken:e=Pe(),codec:t="h264",device:n,endpoint:r="https://appetize.io",onStateChange:o,proxy:s,signal:i,target:c}){if(i?.throwIfAborted(),!c)throw new TypeError("target is required");if(!n.id)throw new TypeError("device.id is required");o?.({phase:"requesting"});const a=await ve(r,{codec:t,noVideo:!0,proxy:we(s),publicKey:c,...he(n)},{apiToken:e,onQueue:d=>{o?.({phase:"queued",queue:d})},signal:i});return{baseUrl:new URL(a.path).origin,url:qe(a)}}function Pe(){return pe()?.env.APPETIZE_API_TOKEN}function qe(e){const t=new URL("/client",e.path);return t.protocol=t.protocol==="http:"?"ws:":"wss:",t.searchParams.set("sessionToken",e.sessionToken),t.href}const Ie=S("appetize:daemon");function u(e){Ie(e)}function Ce(e,{message:t="The operation timed out"}={}){const n=new AbortController,r=setTimeout(()=>{n.abort(new Error(t))},e),o=()=>{clearTimeout(r)};return{cancel:o,signal:n.signal,[Symbol.dispose]:o}}var xe=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),I=e=>{throw TypeError(e)},De=(e,t,n)=>{if(t!=null){typeof t!="object"&&typeof t!="function"&&I("Object expected");var r,o;r===void 0&&(r=t[xe("dispose")]),typeof r!="function"&&I("Object not disposable"),o&&(r=function(){try{o.call(this)}catch(s){return Promise.reject(s)}}),e.push([n,r,t])}return t},We=(e,t,n)=>{var r=typeof SuppressedError=="function"?SuppressedError:function(i,c,a,d){return d=Error(a),d.name="SuppressedError",d.error=i,d.suppressed=c,d},o=i=>t=n?new r(i,t,"An error was suppressed during disposal"):(n=!0,i),s=i=>{for(;i=e.pop();)try{var c=i[1]&&i[1].call(i[2]);if(i[0])return Promise.resolve(c).then(s,a=>(o(a),s()))}catch(a){o(a)}if(n)throw t};return s()};const Ue=1e4;async function Me(e,t,{onClose:n,signal:r}={}){var o=[];try{const c=De(o,Ce(Ue,{message:"Timed out waiting for session request state"})),a=AbortSignal.any([r,c.signal].filter(w=>!!w)),d=w=>{t.save({state:w}),u(w.phase),w.phase!=="requesting"&&c.cancel()},{baseUrl:f,url:p}=await $e({device:e.device,endpoint:e.endpoint,onStateChange:d,proxy:e.proxy,signal:a,target:e.target});t.save({baseUrl:f});const l=new A(p,{signal:a});return await le(l,{device:e.device,onStateChange:d,signal:a}),l.onclose=()=>{n?.("The device connection closed")},{device:await de(l,{baseUrl:f,signal:a}),transport:l}}catch(c){var s=c,i=!0}finally{We(o,s,i)}}function Oe(){const e=F(),t=V(e.sessionId,e.proxy),n=N({device:e.device,endpoint:e.endpoint,pid:process.pid,proxy:e.proxy,sessionId:e.sessionId,startedAt:new Date().toISOString(),target:e.target});return n.save({logs:t}),{config:e,logs:t,store:n}}async function _e(e,{host:t="127.0.0.1",onError:n,port:r=0,signal:o}={}){o?.throwIfAborted();let s;const i=()=>{const p=s;s=void 0,p&&(p.tunnel?.close(),p.socket.destroy())},c=async p=>{const{socket:l}=p;try{const h=await e.debug.createAdbTunnel();if(l.destroyed){h.close();return}p.tunnel=h,h.closed.catch(w=>{n?.(w)}),ze(l,h)}catch(h){l.destroyed||n?.(h),l.destroy()}},a=k(p=>{i();const l={socket:p};s=l,p.once("close",()=>{s===l&&(s=void 0)}),c(l)}),d=()=>{o?.removeEventListener("abort",d),i(),a.close()};o?.addEventListener("abort",d,{once:!0});const f=await Fe(a,t,r);return{close:d,url:new URL(`adb://${f.address}:${String(f.port)}`)}}function ze(e,t){L(t.readable,e,C),L(e,async n=>{const r=t.writable.getWriter();try{for await(const o of n)await r.write(o);await r.close()}catch(o){throw await r.abort(o),o}},C)}function C(){}function Fe(e,t,n){return new Promise((r,o)=>{e.once("error",o),e.listen({host:t,port:n},()=>{e.off("error",o);const s=e.address();if(s===null||typeof s=="string"){o(new Error("The listener has no tcp address"));return}r(s)})})}async function Ve(e,t,n,{signal:r}={}){try{if(!await Ne(t))return;const o=await _e(e,{onError:s=>{u(`adb endpoint error: ${x(s)}`)},signal:r});n.save({adbSerial:o.url.host}),u(`adb endpoint listening at ${o.url.host}`)}catch(o){u(`adb endpoint unavailable: ${x(o)}`)}}async function Ne(e){return await j(e.device.id,{endpoint:e.endpoint})==="android"}function x(e){return e instanceof Error?e.message:String(e)}async function je(e,t,{methods:n={},signal:r}={}){await B(t,{force:!0});const o=new Set,s=k(i=>{u("control client connected"),o.add(i),i.once("close",()=>{o.delete(i)});const c=new Q(i,{signal:r});J(c,e,{leftEffects:()=>n})});r?.addEventListener("abort",()=>{for(const i of o)i.destroy()},{once:!0}),await new Promise((i,c)=>{s.once("error",c),s.listen({path:t,signal:r},()=>{s.off("error",c),i()})})}async function Qe(e,t,n,{recorder:r,signal:o}){const s=G(n);return await je(e,s,{methods:{"appetizeio.cli.record.start":async i=>await r.start(i),"appetizeio.cli.record.stop":async()=>await r.stop()},signal:o}),t.save({controlSocket:s}),s}function Je(e){const t=new AbortController,n=Ge(e,t),r=H();return r.addEventListener("abort",()=>{const{reason:o}=r;n(o instanceof Error?o.message:String(o))},{once:!0}),{shutdown:n,signal:t.signal}}function Ge(e,t){let n=!1;return r=>{n||(n=!0,e.save({endedAt:new Date().toISOString(),endedReason:r,state:{phase:"ended"}}),u(r),t.abort())}}async function D(e,t,{label:n,signal:r}){try{const o=await e();await ee(o.readable.pipeThrough(He()),Z(t,{flags:"a"}))}catch(o){if(r?.aborted)return;const s=o instanceof Error?o.message:String(o);u(`${n} ended with an error: ${s}`)}}function He(){return new TransformStream({transform:(e,t)=>{t.enqueue(`${JSON.stringify(e)}
|
|
2
|
+
`)}})}async function Ke(e,t,{signal:n}={}){await D(async()=>await e.debug.createLogStream({signal:n}),t,{label:"log capture",signal:n})}async function Be(e,t,{signal:n}={}){await D(async()=>await e.debug.createProxyInterceptStream({signal:n}),t,{label:"network capture",signal:n})}const E=30;async function Ze(e,t){await e.pipeTo(Ye(t))}function Xe(e){return{decoderConfig:{codec:"avc1.640028",codedHeight:e.height,codedWidth:e.width}}}function Ye(e){let t;const n=async()=>{await t?.output.finalize()};return new WritableStream({abort:n,close:n,write:async r=>{r.data.byteLength!==0&&(t??=await et(nt(r),e),tt(t,r),await rt(t,r))}})}async function et(e,t){const n=new te("avc"),r=new ne({format:new oe({fastStart:"fragmented"}),target:new re(t,{chunked:!1})});return r.addVideoTrack(n,{frameRate:E}),await r.start(),{frame:0,output:r,seen:{height:e.height,width:e.width},size:{height:e.height,width:e.width},source:n}}function tt(e,t){if(t.type!=="key")return;const{seen:n,size:r}=e;t.width===n.width&&t.height===n.height||(e.seen={height:t.height,width:t.width},u(`video resized to ${String(t.width)}x${String(t.height)}; keeping ${String(r.width)}x${String(r.height)}`))}function nt(e){if(e.type!=="key")throw new Error("Video stream started without a key chunk");return e}async function rt(e,t){const n=new se(t.data,t.type,e.frame/E,1/E);e.frame+=1,await e.source.add(n,Xe(e.size))}function ot(e,t,{signal:n}={}){let r,o;const s=async(a,{force:d=!1}={})=>{if(X(a)){if(!d)throw new Error(`A recording already exists at ${a}; pass --force to overwrite`);Y(a)}const f=await e.video.createStream({signal:n});return r={done:st(f,a),path:a,stream:f},t.save({video:{path:a,recording:!0}}),u(`recording video to ${a}`),{path:a}},i=async a=>{a.stream.close();try{await a.done,t.save({video:{path:a.path,recording:!1}})}finally{r=void 0,o=void 0}},c=async()=>{if(!r)return;const{path:a}=r;await i(r),u(`closed the video recording: ${a}`)};return n?.addEventListener("abort",()=>{c()},{once:!0}),{start:async({force:a=!1,path:d})=>{const f=r?.path??o;if(f!==void 0)throw new Error(`Already recording to ${f}`);o=d;try{return await s(d,{force:a})}finally{o=void 0}},stop:async()=>{if(!r)throw new Error("No video recording in progress");const{path:a}=r;return await i(r),{path:a}}}}async function st(e,t){try{await Ze(e.readable,t)}catch(n){u(`video capture ended with an error: ${String(n)}`)}}async function it(){const{config:e,logs:t,store:n}=Oe();u(`recording to ${n.path}`);const{shutdown:r,signal:o}=Je(n);try{const{device:s,transport:i}=await Me(e,n,{onClose:r,signal:o}),c=ot(s,n,{signal:o});await Ve(s,e,n,{signal:o});const a=await Qe(i,n,e.sessionId,{recorder:c,signal:o});u(`control socket listening at ${a}`),Ke(s,t.device,{signal:o}),u(`recording device logs to ${t.device}`),t.network&&(Be(s,t.network,{signal:o}),u(`recording network events to ${t.network}`))}catch(s){if(o.aborted)return;const i=s instanceof Error?s.message:String(s);n.save({endedAt:new Date().toISOString(),endedReason:i,state:{message:i,phase:"error"}}),u(`error: ${i}`),process.exitCode=1}}K(),it();
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appetize/cli",
|
|
3
|
+
"version": "0.15.0",
|
|
4
|
+
"description": "Run, inspect and control iOS and Android apps on Appetize cloud devices",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"homepage": "https://appetize.io",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://appetize.io/support-request"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"appetize",
|
|
12
|
+
"cli",
|
|
13
|
+
"ios",
|
|
14
|
+
"android",
|
|
15
|
+
"simulator",
|
|
16
|
+
"emulator",
|
|
17
|
+
"agent",
|
|
18
|
+
"skill"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"appetize": "cli.js"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"debug": "^4.4.3",
|
|
32
|
+
"human-id": "^4.2.1",
|
|
33
|
+
"json-rpc-2.0": "^1.7.1",
|
|
34
|
+
"mediabunny": "^1.55.3",
|
|
35
|
+
"sade": "^1.8.1"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: appetize
|
|
3
|
+
description: >-
|
|
4
|
+
Run, inspect and control iOS/Android apps on Appetize cloud devices via the
|
|
5
|
+
appetize CLI. Use when running, testing or debugging a mobile app build
|
|
6
|
+
(.app/.apk) on a simulator/emulator — starting sessions, tapping/typing via
|
|
7
|
+
selectors, taking screenshots. Reach for this whenever a task means exercising
|
|
8
|
+
a mobile app on a real device rather than reading its source: verifying a UI
|
|
9
|
+
change, reproducing a bug report, walking through a signup or checkout flow,
|
|
10
|
+
or answering what is currently on screen — even if Appetize is not mentioned
|
|
11
|
+
by name.
|
|
12
|
+
metadata:
|
|
13
|
+
cli-version: '0.15.0'
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Appetize
|
|
17
|
+
|
|
18
|
+
Drive an iOS or Android app on a cloud device with the `appetize` CLI. You get a
|
|
19
|
+
real simulator or emulator: you can see the view hierarchy, act on it, and
|
|
20
|
+
screenshot the result.
|
|
21
|
+
|
|
22
|
+
The single most important habit: **look before you act, and verify after**. You
|
|
23
|
+
cannot see the screen directly, so `inspect` and `screenshot` are your eyes.
|
|
24
|
+
Acting blind on remembered coordinates is the main way these sessions go wrong.
|
|
25
|
+
|
|
26
|
+
## Prereqs
|
|
27
|
+
|
|
28
|
+
Confirm the CLI is installed and note the version:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
appetize --version
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`APPETIZE_API_TOKEN` must be set for private APIs and session targets. A target
|
|
35
|
+
is an uploaded build's public key, e.g. `app_a1b2c3`. Discover one with
|
|
36
|
+
`appetize build list`, filtering with `--app <appId>` when you know the bundle
|
|
37
|
+
or package id.
|
|
38
|
+
|
|
39
|
+
Put a local `.apk`, `.zip` or `.tar.gz` on the platform with
|
|
40
|
+
`appetize build upload ./app.apk`. The extension tells Appetize which platform
|
|
41
|
+
the build targets, and the `id` it prints is a target you can start a session
|
|
42
|
+
against immediately.
|
|
43
|
+
|
|
44
|
+
A device id names a model, e.g. `iphone15pro`. Discover valid ids and the OS
|
|
45
|
+
versions each supports with `appetize device list`, filtering with
|
|
46
|
+
`--platform ios` or `--platform android`.
|
|
47
|
+
|
|
48
|
+
`APPETIZE_ENDPOINT` sets the Appetize URL, so a non-production environment is
|
|
49
|
+
configured once rather than flagged on every session.
|
|
50
|
+
|
|
51
|
+
## Session lifecycle
|
|
52
|
+
|
|
53
|
+
Start a session, naming a device and a target:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
appetize session start iphone15pro app_a1b2c3
|
|
57
|
+
appetize session start pixel7 app_a1b2c3 --device-os-version 14
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This blocks until the device is ready, then prints the session:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"adbSerial": "127.0.0.1:44555",
|
|
65
|
+
"baseUrl": "https://lax4b-android-9.appetize.io",
|
|
66
|
+
"controlSocket": "/home/you/.appetize/cli/sessions/tidy-pandas-jump/control.sock",
|
|
67
|
+
"logs": {
|
|
68
|
+
"daemon": "/home/you/.appetize/cli/sessions/tidy-pandas-jump/daemon.log",
|
|
69
|
+
"device": "/home/you/.appetize/cli/sessions/tidy-pandas-jump/device.log.jsonl"
|
|
70
|
+
},
|
|
71
|
+
"sessionId": "tidy-pandas-jump"
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- `sessionId` — what every later command takes
|
|
76
|
+
- `adbSerial` — Android only; `adb connect` it to use adb
|
|
77
|
+
- `baseUrl` — the streaming host serving the session
|
|
78
|
+
- `controlSocket` — where the daemon listens
|
|
79
|
+
- `logs.device` — the device's own logs; `logs.daemon` is the CLI's
|
|
80
|
+
|
|
81
|
+
A background daemon holds the session open.
|
|
82
|
+
|
|
83
|
+
With one session running, the other commands find it automatically — you do not
|
|
84
|
+
need to pass anything. If you start several, pass `--session-id <id>` to pick
|
|
85
|
+
one, or name them yourself by passing `--session-id` to `session start`.
|
|
86
|
+
`--no-wait` returns immediately with just `sessionId` and `logs`, useful when you
|
|
87
|
+
want to do other work while the device boots.
|
|
88
|
+
|
|
89
|
+
The daemon streams device logs as JSONL to `logs.device`. Read or `tail -f` it
|
|
90
|
+
when you need to see what the app itself is reporting — a crash, a failed
|
|
91
|
+
request, a log line your change was supposed to emit.
|
|
92
|
+
|
|
93
|
+
Starting with `--proxy` also captures the app's network traffic as JSONL to
|
|
94
|
+
`logs.network`. Each line is a request, response or error
|
|
95
|
+
event, so it answers what the app actually sent and what the server actually
|
|
96
|
+
returned — useful when the app's own logs do not say:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
jq 'select(.type == "response") | "\(.response.status) \(.request.method) \(.request.url)"' network.jsonl
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Stop the session when you are done, so the device is released:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
appetize session stop
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Session state lives in `~/.appetize/cli/sessions/<session-id>/state.json` (or under
|
|
109
|
+
`$APPETIZE_CLI_HOME`). Reading it is a good way to see what a session is doing
|
|
110
|
+
without disturbing it. `logs.daemon` holds the daemon's own output — read that
|
|
111
|
+
when the session itself misbehaves, rather than the app.
|
|
112
|
+
|
|
113
|
+
## Recording the screen
|
|
114
|
+
|
|
115
|
+
Video is not captured unless you ask for it — nothing streams from the device
|
|
116
|
+
until you start:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
appetize recording start login-flow
|
|
120
|
+
appetize recording stop
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`recording start` has the daemon open the video stream and write it to the file
|
|
124
|
+
you name, printing the path. The name is required; `.mp4` is added if you omit
|
|
125
|
+
it, and the directory must already exist. `recording stop` closes the stream and
|
|
126
|
+
the file. Starting again while one is already running fails, whatever path you
|
|
127
|
+
name, so a recording always begins where you asked it to. Ending the session
|
|
128
|
+
while recording closes the file cleanly. Recording over an existing file fails unless
|
|
129
|
+
you pass `--force`, so name a new file to record again in the same session.
|
|
130
|
+
|
|
131
|
+
Any player opens it. A session that dies unexpectedly still leaves the file
|
|
132
|
+
playable, losing at most the last second.
|
|
133
|
+
|
|
134
|
+
Playback is a constant 30fps, so it does not track real time.
|
|
135
|
+
|
|
136
|
+
## The loop
|
|
137
|
+
|
|
138
|
+
### 1. Inspect first
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
appetize inspect --select-test-id login-form
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`inspect` writes the view hierarchy as JSON to `inspect.json` by default (name
|
|
145
|
+
a path to choose another, `--pretty` to indent) and prints a summary — byte
|
|
146
|
+
count, node count, output path — so you know what you got.
|
|
147
|
+
|
|
148
|
+
Scope it with a selector and read the file rather than dumping it to the
|
|
149
|
+
terminal. An unscoped hierarchy on an ordinary screen runs past 100 KB, which
|
|
150
|
+
buries the thing you were looking for and wastes most of your context.
|
|
151
|
+
|
|
152
|
+
The tree contains **only what is currently on screen**. An element that is
|
|
153
|
+
scrolled away or covered is not in it — absence means "not visible right now",
|
|
154
|
+
not "does not exist".
|
|
155
|
+
|
|
156
|
+
### 2. Act through selectors
|
|
157
|
+
|
|
158
|
+
Prefer matching what an element _is_ over where it happens to sit:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
appetize tap --select-test-id save
|
|
162
|
+
appetize tap --select-text 'Log in'
|
|
163
|
+
appetize tap --select-text '/^item \d+/i' --select-index 2
|
|
164
|
+
appetize type 'user@example.com{Tab}hunter2{Enter}'
|
|
165
|
+
appetize swipe --direction up
|
|
166
|
+
appetize swipe --from-test-id card-3 --to-test-id archive-bin
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`swipe` comes in two shapes. A `--direction` scrolls the screen (add
|
|
170
|
+
`--distance` for a fraction of it), while a `--from-*`/`--to-*` pair drags along
|
|
171
|
+
a path between two points — which is how you reorder a list or drop something on
|
|
172
|
+
a target. Both ends take the same selectors as `tap`, so a drag can name its
|
|
173
|
+
endpoints instead of guessing coordinates:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
appetize swipe --direction left --from-test-id card --from-index 1
|
|
177
|
+
appetize swipe --from-text 'Drag me' --from-y 0.9 --to-test-id drop-zone
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`--select-test-id` is the most durable, then `--select-text` (an exact string,
|
|
181
|
+
or `/regex/flags`). `--select-index` picks among multiple matches, 0-based.
|
|
182
|
+
Coordinates (`--select-position 0.5,0.75`) still work and are the right tool for
|
|
183
|
+
canvases, maps and sliders — but a selector survives layout changes and a
|
|
184
|
+
coordinate does not.
|
|
185
|
+
|
|
186
|
+
In `type`, `{...}` names a key: `{Enter}`, `{Tab}`, `{Backspace}`, the arrows.
|
|
187
|
+
`{Backspace>16/}` repeats one 16 times, and `{{` types a literal `{`.
|
|
188
|
+
|
|
189
|
+
### 3. Verify
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
appetize screenshot after-login
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Screenshot after each meaningful step. A tap that "succeeded" only means the
|
|
196
|
+
gesture was delivered — the app may still have shown an error, stayed put, or
|
|
197
|
+
navigated somewhere unexpected. The name is optional and the extension is added
|
|
198
|
+
for you.
|
|
199
|
+
|
|
200
|
+
### 4. Wait by inspecting, not by sleeping
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
appetize inspect --select-test-id home-feed --timeout 5000
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`--timeout <ms>` makes the command wait for the element and fail with a non-zero
|
|
207
|
+
exit if it never appears. That is your wait primitive: it returns the moment the
|
|
208
|
+
element is there, and it tells you clearly when it is not. Sleeping guesses, and
|
|
209
|
+
guesses are either slow or flaky.
|
|
210
|
+
|
|
211
|
+
## Troubleshooting
|
|
212
|
+
|
|
213
|
+
| What you see | What it means |
|
|
214
|
+
| ------------------------------------------------ | ------------------------------------------------------------- |
|
|
215
|
+
| `No active sessions` | Nothing is running — `session start` first. |
|
|
216
|
+
| `Multiple active sessions; specify --session-id` | Pass the `sessionId` of the one you want. |
|
|
217
|
+
| `No session found for id X` | That session ended, or the id is wrong. |
|
|
218
|
+
| Element not found | Re-inspect. It is off screen, covered, or the screen changed. |
|
|
219
|
+
| App fails only on network calls | If you started with `--proxy`, retry without it. |
|
|
220
|
+
|
|
221
|
+
A session moves through phases while starting: `requesting`, `queued`,
|
|
222
|
+
`starting`, `downloadingApp`, `installingApp`, `launchingApp`, `ready`. If
|
|
223
|
+
`session start` is taking a while, that sequence tells you whether you are
|
|
224
|
+
queued for capacity or waiting on an install.
|
|
225
|
+
|
|
226
|
+
## Dismissing the soft keyboard
|
|
227
|
+
|
|
228
|
+
There is no `hideKeyboard` command, so the keyboard is dismissed differently on
|
|
229
|
+
each platform. Tapping an inert element does **not** work: it only clears focus
|
|
230
|
+
if the app wired that up, and many apps do not.
|
|
231
|
+
|
|
232
|
+
**iOS** — press the return key:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
appetize type '{Enter}'
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Android** — press the back button; while the keyboard is up it dismisses
|
|
239
|
+
the keyboard instead of navigating back:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
appetize press back
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Both leave you on the same screen with the field still focused. Confirm from
|
|
246
|
+
`inspect`: on Android the IME contributes nodes with `inputmethod`, `ime` or
|
|
247
|
+
`latin` in their identifiers, and on iOS its keys appear as nodes labelled `q`,
|
|
248
|
+
`space` and `return`. When those are gone, the keyboard is down. Since the tree
|
|
249
|
+
holds only what is visible, a field the keyboard covers simply is not there,
|
|
250
|
+
which is the symptom that sends you here.
|
|
251
|
+
|
|
252
|
+
Resist the urge to make this easier by changing the app under test — adding a
|
|
253
|
+
test id or a dismiss button changes the thing you are supposed to be verifying.
|
|
254
|
+
|
|
255
|
+
## Full command reference
|
|
256
|
+
|
|
257
|
+
`references/commands.md` has every command, flag, output shape and exit
|
|
258
|
+
behaviour. Read it when you need a flag this page does not cover, or run
|
|
259
|
+
`appetize <command> --help`.
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# Command reference
|
|
2
|
+
|
|
3
|
+
Every command, flag and output shape. `appetize <command> --help` prints the
|
|
4
|
+
same flags at the terminal.
|
|
5
|
+
|
|
6
|
+
- [Global](#global)
|
|
7
|
+
- [session start](#session-start)
|
|
8
|
+
- [session stop](#session-stop)
|
|
9
|
+
- [build list](#build-list)
|
|
10
|
+
- [build upload](#build-upload)
|
|
11
|
+
- [device list](#device-list)
|
|
12
|
+
- [inspect](#inspect)
|
|
13
|
+
- [tap](#tap)
|
|
14
|
+
- [swipe](#swipe)
|
|
15
|
+
- [type](#type)
|
|
16
|
+
- [press](#press)
|
|
17
|
+
- [rotate](#rotate)
|
|
18
|
+
- [screenshot](#screenshot)
|
|
19
|
+
- [recording start](#recording-start)
|
|
20
|
+
- [recording stop](#recording-stop)
|
|
21
|
+
- [skill install](#skill-install)
|
|
22
|
+
- [Selectors](#selectors)
|
|
23
|
+
- [Environment](#environment)
|
|
24
|
+
- [Exit codes and output streams](#exit-codes-and-output-streams)
|
|
25
|
+
|
|
26
|
+
## Global
|
|
27
|
+
|
|
28
|
+
`--session-id <id>` is accepted by every command except those marked "Takes
|
|
29
|
+
no session". On
|
|
30
|
+
`session start` it names the session being created; everywhere else it picks
|
|
31
|
+
which existing session to act on, defaulting to the sole active one, so pass it
|
|
32
|
+
only when several are running.
|
|
33
|
+
|
|
34
|
+
## session start
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
appetize session start <device-id> <target> [options]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Flag | Meaning |
|
|
41
|
+
| --------------------- | ------------------------------------------------------ |
|
|
42
|
+
| `--device-os-version` | Device OS version, e.g. `17` for iOS, `14` for Android |
|
|
43
|
+
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
44
|
+
| `--no-wait` | Return without waiting for the device to be ready |
|
|
45
|
+
| `--proxy` | Proxy traffic: `intercept`, or a custom `http://` url |
|
|
46
|
+
| `--session-id` | Name the session; defaults to a generated 3-word id |
|
|
47
|
+
|
|
48
|
+
Spawns a daemon that holds the session open and prints JSON on stdout. Waiting
|
|
49
|
+
(the default) prints `{ adbSerial, baseUrl, controlSocket, logs, sessionId }`
|
|
50
|
+
once the device is ready; `--no-wait` prints `{ logs, sessionId }` immediately.
|
|
51
|
+
`adbSerial` is present only for an Android session, and only while adb is
|
|
52
|
+
available to it: `adb connect <adbSerial>` attaches to the device until the
|
|
53
|
+
session ends. `logs`
|
|
54
|
+
carries a `device` and a `daemon` path, plus a `network` path — the JSONL capture
|
|
55
|
+
of the app's traffic — when started with `--proxy` (or `--proxy intercept`). Progress phases are logged to stderr:
|
|
56
|
+
`requesting`, `queued`, `starting`, `downloadingApp`, `installingApp`,
|
|
57
|
+
`launchingApp`, `ready`.
|
|
58
|
+
|
|
59
|
+
Network traffic can be proxied or intercepted for debugging. `--proxy` (or
|
|
60
|
+
`--proxy intercept`) provisions the intercepting proxy so traffic can be
|
|
61
|
+
captured; `--proxy http://host:port` routes through a proxy of your own, and the
|
|
62
|
+
streaming server rejects any other scheme. Interception rewrites TLS, so an app
|
|
63
|
+
that pins certificates may not work under it.
|
|
64
|
+
|
|
65
|
+
`sessionId` is what every other command takes. A generated one looks like
|
|
66
|
+
`tidy-pandas-jump`; a name you pass may use letters, digits, `.`, `-` and `_`,
|
|
67
|
+
and starting a session with an id already in use fails.
|
|
68
|
+
|
|
69
|
+
## session stop
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
appetize session stop
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Signals the daemon to shut down and prints `{ ended: true, sessionId }`. Reports
|
|
76
|
+
the id even if the daemon had already exited, so it is safe to call twice.
|
|
77
|
+
|
|
78
|
+
## build list
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
appetize build list [options]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Flag | Meaning |
|
|
85
|
+
| ------------ | ------------------------------------------- |
|
|
86
|
+
| `--app` | App id to filter by (bundle or package id) |
|
|
87
|
+
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
88
|
+
| `--limit` | Builds per page (default 10, max 200) |
|
|
89
|
+
| `--page` | Page of results to fetch (default 1) |
|
|
90
|
+
|
|
91
|
+
Lists one page of the account's uploaded builds, newest first, printing
|
|
92
|
+
`{ builds, nextPage, total }` on stdout. Each build's `id` is a target
|
|
93
|
+
`session start` takes, alongside `appId`, `platform`, `versionName`,
|
|
94
|
+
`buildNumber` and `created`. Pass a non-null `nextPage` back as `--page` to
|
|
95
|
+
continue. Requires `APPETIZE_API_TOKEN`. Takes no session.
|
|
96
|
+
|
|
97
|
+
## build upload
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
appetize build upload <file> [options]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Flag | Meaning |
|
|
104
|
+
| ------------ | --------------------------------------------------- |
|
|
105
|
+
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
106
|
+
| `--note` | Note to store with the build |
|
|
107
|
+
| `--tags` | Comma separated tags to store with the build |
|
|
108
|
+
| `--timeout` | Milliseconds to wait with `--wait` (default 120000) |
|
|
109
|
+
| `--wait` | Wait for the app id and version metadata to resolve |
|
|
110
|
+
|
|
111
|
+
Uploads a `.apk`, `.apks`, `.zip` or `.tar.gz` and prints
|
|
112
|
+
`{ created, id, platform }` on stdout, where `id` is a target `session start`
|
|
113
|
+
takes. The id is also logged to stderr as soon as the upload lands.
|
|
114
|
+
|
|
115
|
+
The extension decides the platform — `.apk` and `.apks` are Android, `.zip`,
|
|
116
|
+
`.tar.gz` and `.tgz` are iOS — and any other file is refused before uploading.
|
|
117
|
+
|
|
118
|
+
Appetize fills in `appId`, `versionName` and `buildNumber` by processing the
|
|
119
|
+
file after the upload responds, which takes a few seconds and is not needed to
|
|
120
|
+
start a session. `--wait` polls until they appear and prints the full
|
|
121
|
+
`build list` shape, failing once `--timeout` elapses.
|
|
122
|
+
|
|
123
|
+
Requires `APPETIZE_API_TOKEN`. Takes no session.
|
|
124
|
+
|
|
125
|
+
## device list
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
appetize device list [options]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
| Flag | Meaning |
|
|
132
|
+
| ------------ | ------------------------------------------- |
|
|
133
|
+
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
134
|
+
| `--platform` | Platform to filter by: `ios` or `android` |
|
|
135
|
+
|
|
136
|
+
Lists available device models, printing `{ devices }` on stdout. Each device's
|
|
137
|
+
`id` is the `<device-id>` `session start` takes, alongside `name`, `platform`
|
|
138
|
+
and `osVersions` — the values `--device-os-version` accepts. Needs no
|
|
139
|
+
`APPETIZE_API_TOKEN`. Takes no session.
|
|
140
|
+
|
|
141
|
+
## inspect
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
appetize inspect [output] [options]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| Flag | Meaning |
|
|
148
|
+
| ----------------------------------------------------- | -------------------------------------------------- |
|
|
149
|
+
| `--select-text`, `--select-test-id`, `--select-index` | Scope to one element — see [Selectors](#selectors) |
|
|
150
|
+
| `--timeout` | Milliseconds to wait for the element |
|
|
151
|
+
| `--pretty` | Indent the JSON |
|
|
152
|
+
|
|
153
|
+
`output` defaults to `inspect.json`; `.json` is added if you omit an extension.
|
|
154
|
+
Writes the hierarchy to that file and prints `{ bytes, nodes, output }` on stdout.
|
|
155
|
+
The JSON is `{ platform, root }`, where each node carries `attributes`, `bounds`
|
|
156
|
+
and `children`. Only currently visible elements appear.
|
|
157
|
+
|
|
158
|
+
Unscoped output on an ordinary screen exceeds 100 KB, so prefer a selector and
|
|
159
|
+
read the file.
|
|
160
|
+
|
|
161
|
+
## tap
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
appetize tap [options]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
| Flag | Meaning |
|
|
168
|
+
| ------------ | -------------------------------------------------------- |
|
|
169
|
+
| `--select-*` | Element or position to tap — see [Selectors](#selectors) |
|
|
170
|
+
| `--timeout` | Milliseconds to wait for the element |
|
|
171
|
+
|
|
172
|
+
Prints `{ tapped: true }`. Combining an element selector with `--select-x` /
|
|
173
|
+
`--select-y` taps a point within that element, and values outside `0-1` are
|
|
174
|
+
allowed to reach just beyond its edge (e.g. `--select-x=-0.1`).
|
|
175
|
+
|
|
176
|
+
## swipe
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
appetize swipe [options]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
| Flag | Meaning |
|
|
183
|
+
| ------------- | ------------------------------------------------------ |
|
|
184
|
+
| `--direction` | `down`, `left`, `right` or `up` |
|
|
185
|
+
| `--distance` | Travel as a fraction of the screen (0-1) |
|
|
186
|
+
| `--from-*` | Where the gesture starts — see [Selectors](#selectors) |
|
|
187
|
+
| `--to-*` | Where the gesture ends — see [Selectors](#selectors) |
|
|
188
|
+
| `--duration` | Milliseconds the gesture travels for |
|
|
189
|
+
| `--timeout` | Milliseconds to wait for any `--from`/`--to` elements |
|
|
190
|
+
|
|
191
|
+
Prints `{ swiped: true }`. Two shapes are valid: a `--direction` with an
|
|
192
|
+
optional `--from-*` starting point, or both a `--from-*` and a `--to-*` point to
|
|
193
|
+
form a path. Mixing `--direction` with `--to-*` is an error, as is `--distance`
|
|
194
|
+
without `--direction`.
|
|
195
|
+
|
|
196
|
+
## type
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
appetize type <text> [options]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
| Flag | Meaning |
|
|
203
|
+
| --------- | ---------------------------------- |
|
|
204
|
+
| `--delay` | Milliseconds to wait between steps |
|
|
205
|
+
|
|
206
|
+
Prints `{ typed: true }`. Bare text is delivered as a string; `{...}` names a
|
|
207
|
+
key delivered as a keystroke. Supported keys: `ArrowDown`, `ArrowLeft`,
|
|
208
|
+
`ArrowRight`, `ArrowUp`, `Backspace`, `Enter`, `Tab`. A token may carry a repeat
|
|
209
|
+
count as in `{Backspace>16/}`, and `{{` types a literal `{`. An unclosed token
|
|
210
|
+
or an unsupported key name fails without typing anything.
|
|
211
|
+
|
|
212
|
+
Typing does not focus a field — tap it first.
|
|
213
|
+
|
|
214
|
+
## press
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
appetize press <button>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Prints `{ pressed: true }`. Buttons: `home` and `lock` on both platforms;
|
|
221
|
+
`back`, `menu`, `unlock`, `volumeUp` and `volumeDown` on Android only. Calling
|
|
222
|
+
an Android-only button on iOS fails.
|
|
223
|
+
|
|
224
|
+
There is no keyboard-dismiss action. To dismiss the soft keyboard, see the
|
|
225
|
+
main page.
|
|
226
|
+
|
|
227
|
+
## rotate
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
appetize rotate <orientation>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Prints the resulting orientation. Orientations: `portrait`, `landscapeLeft`,
|
|
234
|
+
`landscapeRight`, `upsideDown`.
|
|
235
|
+
|
|
236
|
+
## screenshot
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
appetize screenshot [output]
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`output` defaults to `screenshot`, and an extension matching the image is added
|
|
243
|
+
if you omit one. Writes a PNG and prints `{ bytes, mimeType, output }`.
|
|
244
|
+
|
|
245
|
+
## recording start
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
appetize recording start <output> [options]
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
| Flag | Meaning |
|
|
252
|
+
| --------- | --------------------------------------- |
|
|
253
|
+
| `--force` | Overwrite the file if it already exists |
|
|
254
|
+
|
|
255
|
+
Asks the daemon to open the device video stream and capture it to `output`,
|
|
256
|
+
printing `{ path, recording: true }`. Capture is opt-in — video is lazy
|
|
257
|
+
device-side, so nothing streams until this runs.
|
|
258
|
+
|
|
259
|
+
`output` is required. `.mp4` is added if you omit an extension, any other
|
|
260
|
+
extension is refused, and the directory must already exist. A relative path
|
|
261
|
+
resolves against your shell rather than the daemon's.
|
|
262
|
+
|
|
263
|
+
Starting while a recording is already running fails, whatever path you name —
|
|
264
|
+
adopting it would hand you a file that began whenever the first call did.
|
|
265
|
+
|
|
266
|
+
The daemon owns the stream and the file, so the command returns as soon as
|
|
267
|
+
capture is running.
|
|
268
|
+
|
|
269
|
+
## recording stop
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
appetize recording stop
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Closes the stream and the file, printing `{ path, recording: false }`. Fails
|
|
276
|
+
with `No video recording in progress` when nothing is recording. Ending the
|
|
277
|
+
session while recording closes the file too, noting it in `daemon.log`.
|
|
278
|
+
|
|
279
|
+
A session that dies unexpectedly still leaves the file playable, losing at most
|
|
280
|
+
the last second.
|
|
281
|
+
|
|
282
|
+
Every frame is written at a constant 30fps, so playback does not track real
|
|
283
|
+
time. A rotation keeps the original dimensions and is noted in `daemon.log`.
|
|
284
|
+
|
|
285
|
+
Recording over an existing file fails unless you pass `--force`, so name a new
|
|
286
|
+
file to record more than once in a session.
|
|
287
|
+
|
|
288
|
+
`output` is resolved and checked by the CLI, so a bad path fails before the
|
|
289
|
+
daemon is contacted.
|
|
290
|
+
|
|
291
|
+
A write failure is reported once the recording stops, not when it happens.
|
|
292
|
+
|
|
293
|
+
## skill install
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
appetize skill install [options]
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
| Flag | Meaning |
|
|
300
|
+
| --------- | -------------------------------------------------------------- |
|
|
301
|
+
| `--agent` | `agents`, `claude`, `codex`, `copilot` or `cursor`; repeatable |
|
|
302
|
+
| `--scope` | `project` (default), or `user` for your home directory |
|
|
303
|
+
|
|
304
|
+
Installs this skill for each agent whose directory is already present — Claude
|
|
305
|
+
Code reads `.claude/skills`, the others `.agents/skills` — and into both when
|
|
306
|
+
none is found. `--agent` names agents directly instead. Takes no session.
|
|
307
|
+
|
|
308
|
+
## Selectors
|
|
309
|
+
|
|
310
|
+
Selector flags come as a prefix naming which point is being selected, plus a
|
|
311
|
+
suffix naming how. The prefixes:
|
|
312
|
+
|
|
313
|
+
- `inspect --select-*`
|
|
314
|
+
- `tap --select-*`
|
|
315
|
+
- `swipe --from-*` and `swipe --to-*`
|
|
316
|
+
|
|
317
|
+
Element suffixes, identical under every prefix:
|
|
318
|
+
|
|
319
|
+
| Flag | Meaning |
|
|
320
|
+
| -------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
321
|
+
| `--<prefix>-text` | Exact string, or `/regex/flags` such as `/sign in/i` |
|
|
322
|
+
| `--<prefix>-test-id` | Exact match — on Android the whole `resource-id` or the part after its last `/`, on iOS the `accessibilityIdentifier` |
|
|
323
|
+
| `--<prefix>-index` | Which match when several, 0-based |
|
|
324
|
+
|
|
325
|
+
So `inspect --select-text 'Log in'`, `tap --select-test-id save` and
|
|
326
|
+
`swipe --from-test-id card --to-test-id bin` all name elements the same way.
|
|
327
|
+
|
|
328
|
+
Position suffixes, accepted by `tap` and `swipe` (not `inspect`):
|
|
329
|
+
|
|
330
|
+
| Flag | Meaning |
|
|
331
|
+
| ------------------------------ | -------------------------------------------------------------------------------------------- |
|
|
332
|
+
| `--<prefix>-position` | Screen position as `x,y`, each 0-1, e.g. `0.5,0.75` |
|
|
333
|
+
| `--<prefix>-x`, `--<prefix>-y` | Position within the matched element (0-1, negative/>1 to reach outside the selected element) |
|
|
334
|
+
|
|
335
|
+
Pick one kind of match per point. Prefer a test id, then text; reach for a
|
|
336
|
+
position when the target has no identity of its own, such as a canvas or a
|
|
337
|
+
slider track.
|
|
338
|
+
|
|
339
|
+
## Environment
|
|
340
|
+
|
|
341
|
+
| Variable | Meaning |
|
|
342
|
+
| -------------------- | ---------------------------------------------- |
|
|
343
|
+
| `APPETIZE_API_TOKEN` | Authorizes private APIs and session targets |
|
|
344
|
+
| `APPETIZE_ENDPOINT` | Appetize URL used when `--endpoint` is omitted |
|
|
345
|
+
| `APPETIZE_CLI_HOME` | Overrides the session state directory |
|
|
346
|
+
|
|
347
|
+
Session state is written to `~/.appetize/cli/sessions/<session-id>/state.json`.
|
|
348
|
+
Device logs stream as JSONL to `device.log.jsonl` beside it, and the daemon's
|
|
349
|
+
own output goes to `daemon.log`.
|
|
350
|
+
|
|
351
|
+
## Exit codes and output streams
|
|
352
|
+
|
|
353
|
+
Commands exit `0` on success and non-zero on failure, printing the message to
|
|
354
|
+
stderr. A selector `--timeout` that expires is a failure, which is what makes it
|
|
355
|
+
usable as a wait.
|
|
356
|
+
|
|
357
|
+
Machine-readable results go to stdout as JSON. Progress and errors are always
|
|
358
|
+
stderr.
|
|
359
|
+
|
|
360
|
+
Common failures:
|
|
361
|
+
|
|
362
|
+
| Message | What to check |
|
|
363
|
+
| --------------------------- | --------------------------------------------------------------------------------- |
|
|
364
|
+
| `No active sessions` | `session start` first; if one should be live, its `daemon.log` says why it exited |
|
|
365
|
+
| `No session found for id X` | `endedReason` in the session's `state.json` |
|
|
366
|
+
| `Session is not ready` | `state.phase` in `state.json` says how far it got |
|