agent-device 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/src/50.js +1 -0
- package/dist/src/bin.js +31 -30
- package/dist/src/daemon.js +17 -16
- package/package.json +1 -1
- package/skills/agent-device/SKILL.md +45 -0
- package/skills/agent-device/references/batching.md +79 -0
- package/dist/src/797.js +0 -1
package/README.md
CHANGED
|
@@ -45,6 +45,52 @@ agent-device click @e3
|
|
|
45
45
|
agent-device close
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## Fast batching (JSON steps)
|
|
49
|
+
|
|
50
|
+
Use `batch` to execute multiple commands in a single daemon request.
|
|
51
|
+
|
|
52
|
+
CLI examples:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
agent-device batch \
|
|
56
|
+
--session sim \
|
|
57
|
+
--platform ios \
|
|
58
|
+
--udid 00008150-001849640CF8401C \
|
|
59
|
+
--steps-file /tmp/batch-steps.json \
|
|
60
|
+
--json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Small inline payloads are also supported:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
agent-device batch --steps '[{"command":"open","positionals":["settings"]},{"command":"wait","positionals":["100"]}]'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Batch payload format:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
[
|
|
73
|
+
{ "command": "open", "positionals": ["settings"], "flags": {} },
|
|
74
|
+
{ "command": "wait", "positionals": ["label=\"Privacy & Security\"", "3000"], "flags": {} },
|
|
75
|
+
{ "command": "click", "positionals": ["label=\"Privacy & Security\""], "flags": {} },
|
|
76
|
+
{ "command": "get", "positionals": ["text", "label=\"Tracking\""], "flags": {} }
|
|
77
|
+
]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Batch response includes:
|
|
81
|
+
|
|
82
|
+
- `total`, `executed`, `totalDurationMs`
|
|
83
|
+
- per-step `results[]` with `durationMs`
|
|
84
|
+
- failure context with failing `step` and `partialResults`
|
|
85
|
+
|
|
86
|
+
Agent usage guidelines:
|
|
87
|
+
|
|
88
|
+
- Keep each batch to one screen-local workflow.
|
|
89
|
+
- Add sync guards (`wait`, `is exists`) after mutating steps (`open`, `click`, `fill`, `swipe`).
|
|
90
|
+
- Treat refs/snapshot assumptions as stale after UI mutations.
|
|
91
|
+
- Prefer `--steps-file` over inline JSON for reliability.
|
|
92
|
+
- Keep batches moderate (about 5-20 steps) and stop on first error.
|
|
93
|
+
|
|
48
94
|
## CLI Usage
|
|
49
95
|
|
|
50
96
|
```bash
|
|
@@ -84,6 +130,7 @@ agent-device swipe 540 1500 540 500 120 --count 8 --pause-ms 30 --pattern ping-p
|
|
|
84
130
|
|
|
85
131
|
## Command Index
|
|
86
132
|
- `boot`, `open`, `close`, `reinstall`, `home`, `back`, `app-switcher`
|
|
133
|
+
- `batch`
|
|
87
134
|
- `snapshot`, `find`, `get`
|
|
88
135
|
- `click`, `focus`, `type`, `fill`, `press`, `long-press`, `swipe`, `scroll`, `scrollintoview`, `pinch`, `is`
|
|
89
136
|
- `alert`, `wait`, `screenshot`
|
|
@@ -114,6 +161,10 @@ Flags:
|
|
|
114
161
|
- `--pattern one-way|ping-pong` repeat pattern for `swipe`
|
|
115
162
|
- `--verbose` for daemon and runner logs
|
|
116
163
|
- `--json` for structured output
|
|
164
|
+
- `--steps <json>` batch: JSON array of steps
|
|
165
|
+
- `--steps-file <path>` batch: read step JSON from file
|
|
166
|
+
- `--on-error stop` batch: stop when a step fails
|
|
167
|
+
- `--max-steps <n>` batch: max allowed steps per request
|
|
117
168
|
|
|
118
169
|
Pinch:
|
|
119
170
|
- `pinch` is supported on iOS simulators.
|
|
@@ -147,7 +198,7 @@ Navigation helpers:
|
|
|
147
198
|
- `boot --platform ios|android` ensures the target is ready without launching an app.
|
|
148
199
|
- Use `boot` mainly when starting a new session and `open` fails because no booted simulator/emulator is available.
|
|
149
200
|
- `open [app|url] [url]` already boots/activates the selected target when needed.
|
|
150
|
-
- `reinstall <app> <path>` uninstalls and installs the app binary in one command (Android + iOS simulator).
|
|
201
|
+
- `reinstall <app> <path>` uninstalls and installs the app binary in one command (Android + iOS simulator/device).
|
|
151
202
|
- `reinstall` accepts package/bundle id style app names and supports `~` in paths.
|
|
152
203
|
|
|
153
204
|
Deep links:
|
|
@@ -242,7 +293,7 @@ Boot diagnostics:
|
|
|
242
293
|
|
|
243
294
|
## iOS notes
|
|
244
295
|
- Core runner commands: `snapshot`, `wait`, `click`, `fill`, `get`, `is`, `find`, `press`, `long-press`, `focus`, `type`, `scroll`, `scrollintoview`, `back`, `home`, `app-switcher`.
|
|
245
|
-
- Simulator-only commands: `alert`, `pinch`, `record`, `
|
|
296
|
+
- Simulator-only commands: `alert`, `pinch`, `record`, `settings`.
|
|
246
297
|
- iOS device runs require valid signing/provisioning (Automatic Signing recommended). Optional overrides: `AGENT_DEVICE_IOS_TEAM_ID`, `AGENT_DEVICE_IOS_SIGNING_IDENTITY`, `AGENT_DEVICE_IOS_PROVISIONING_PROFILE`.
|
|
247
298
|
|
|
248
299
|
## Testing
|
package/dist/src/50.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t,{promises as e}from"node:fs";import r from"node:path";import{fileURLToPath as n,pathToFileURL as o}from"node:url";import{spawn as i,spawnSync as s}from"node:child_process";class a extends Error{code;details;cause;constructor(t,e,r,n){super(e),this.code=t,this.details=r,this.cause=n}}function u(t){return t instanceof a?t:t instanceof Error?new a("UNKNOWN",t.message,void 0,t):new a("UNKNOWN","Unknown error",{err:t})}function d(){try{let e=l();return JSON.parse(t.readFileSync(r.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function l(){let e=r.dirname(n(import.meta.url)),o=e;for(let e=0;e<6;e+=1){let e=r.join(o,"package.json");if(t.existsSync(e))return o;o=r.dirname(o)}return e}async function c(t,e,r={}){return new Promise((n,o)=>{let s=i(t,e,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"]}),u="",d=r.binaryStdout?Buffer.alloc(0):void 0,l="",c=!1,f=A(r.timeoutMs),p=f?setTimeout(()=>{c=!0,s.kill("SIGKILL")},f):null;r.binaryStdout||s.stdout.setEncoding("utf8"),s.stderr.setEncoding("utf8"),void 0!==r.stdin&&s.stdin.write(r.stdin),s.stdin.end(),s.stdout.on("data",t=>{r.binaryStdout?d=Buffer.concat([d??Buffer.alloc(0),Buffer.isBuffer(t)?t:Buffer.from(t)]):u+=t}),s.stderr.on("data",t=>{l+=t}),s.on("error",r=>{(p&&clearTimeout(p),"ENOENT"===r.code)?o(new a("TOOL_MISSING",`${t} not found in PATH`,{cmd:t},r)):o(new a("COMMAND_FAILED",`Failed to run ${t}`,{cmd:t,args:e},r))}),s.on("close",i=>{p&&clearTimeout(p);let s=i??1;c&&f?o(new a("COMMAND_FAILED",`${t} timed out after ${f}ms`,{cmd:t,args:e,stdout:u,stderr:l,exitCode:s,timeoutMs:f})):0===s||r.allowFailure?n({stdout:u,stderr:l,exitCode:s,stdoutBuffer:d}):o(new a("COMMAND_FAILED",`${t} exited with code ${s}`,{cmd:t,args:e,stdout:u,stderr:l,exitCode:s}))})})}async function f(t){try{var e;let{shell:r,args:n}=(e=t,"win32"===process.platform?{shell:"cmd.exe",args:["/c","where",e]}:{shell:"bash",args:["-lc",`command -v ${e}`]}),o=await c(r,n,{allowFailure:!0});return 0===o.exitCode&&o.stdout.trim().length>0}catch{return!1}}function p(t,e,r={}){let n=s(t,e,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],encoding:r.binaryStdout?void 0:"utf8",input:r.stdin,timeout:A(r.timeoutMs)});if(n.error){let o=n.error.code;if("ETIMEDOUT"===o)throw new a("COMMAND_FAILED",`${t} timed out after ${A(r.timeoutMs)}ms`,{cmd:t,args:e,timeoutMs:A(r.timeoutMs)},n.error);if("ENOENT"===o)throw new a("TOOL_MISSING",`${t} not found in PATH`,{cmd:t},n.error);throw new a("COMMAND_FAILED",`Failed to run ${t}`,{cmd:t,args:e},n.error)}let o=r.binaryStdout?Buffer.isBuffer(n.stdout)?n.stdout:Buffer.from(n.stdout??""):void 0,i=r.binaryStdout?"":"string"==typeof n.stdout?n.stdout:(n.stdout??"").toString(),u="string"==typeof n.stderr?n.stderr:(n.stderr??"").toString(),d=n.status??1;if(0!==d&&!r.allowFailure)throw new a("COMMAND_FAILED",`${t} exited with code ${d}`,{cmd:t,args:e,stdout:i,stderr:u,exitCode:d});return{stdout:i,stderr:u,exitCode:d,stdoutBuffer:o}}function m(t,e,r={}){i(t,e,{cwd:r.cwd,env:r.env,stdio:"ignore",detached:!0}).unref()}async function w(t,e,r={}){return new Promise((n,o)=>{let s=i(t,e,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"]}),u="",d="",l=r.binaryStdout?Buffer.alloc(0):void 0;r.binaryStdout||s.stdout.setEncoding("utf8"),s.stderr.setEncoding("utf8"),void 0!==r.stdin&&s.stdin.write(r.stdin),s.stdin.end(),s.stdout.on("data",t=>{if(r.binaryStdout){l=Buffer.concat([l??Buffer.alloc(0),Buffer.isBuffer(t)?t:Buffer.from(t)]);return}let e=String(t);u+=e,r.onStdoutChunk?.(e)}),s.stderr.on("data",t=>{let e=String(t);d+=e,r.onStderrChunk?.(e)}),s.on("error",r=>{"ENOENT"===r.code?o(new a("TOOL_MISSING",`${t} not found in PATH`,{cmd:t},r)):o(new a("COMMAND_FAILED",`Failed to run ${t}`,{cmd:t,args:e},r))}),s.on("close",i=>{let s=i??1;0===s||r.allowFailure?n({stdout:u,stderr:d,exitCode:s,stdoutBuffer:l}):o(new a("COMMAND_FAILED",`${t} exited with code ${s}`,{cmd:t,args:e,stdout:u,stderr:d,exitCode:s}))})})}function h(t,e,r={}){let n=i(t,e,{cwd:r.cwd,env:r.env,stdio:["ignore","pipe","pipe"]}),o="",s="";n.stdout.setEncoding("utf8"),n.stderr.setEncoding("utf8"),n.stdout.on("data",t=>{o+=t}),n.stderr.on("data",t=>{s+=t});let u=new Promise((i,u)=>{n.on("error",r=>{"ENOENT"===r.code?u(new a("TOOL_MISSING",`${t} not found in PATH`,{cmd:t},r)):u(new a("COMMAND_FAILED",`Failed to run ${t}`,{cmd:t,args:e},r))}),n.on("close",n=>{let d=n??1;0===d||r.allowFailure?i({stdout:o,stderr:s,exitCode:d}):u(new a("COMMAND_FAILED",`${t} exited with code ${d}`,{cmd:t,args:e,stdout:o,stderr:s,exitCode:d}))})});return{child:n,wait:u}}function A(t){if(!Number.isFinite(t))return;let e=Math.floor(t);if(!(e<=0))return e}let S=[/(^|[\/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[\/\s"'=])src\/daemon\.ts($|[\s"'])/];function I(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(t){return"EPERM"===t.code}}function g(t){if(!Number.isInteger(t)||t<=0)return null;try{let e=p("ps",["-p",String(t),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==e.exitCode)return null;let r=e.stdout.trim();return r.length>0?r:null}catch{return null}}function N(t,e){let r;if(!I(t))return!1;if(e){let r=g(t);if(!r||r!==e)return!1}let n=function(t){if(!Number.isInteger(t)||t<=0)return null;try{let e=p("ps",["-p",String(t),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==e.exitCode)return null;let r=e.stdout.trim();return r.length>0?r:null}catch{return null}}(t);return!!n&&!!(r=n.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&S.some(t=>t.test(r))}function y(t,e){try{return process.kill(t,e),!0}catch(e){let t=e.code;if("ESRCH"===t||"EPERM"===t)return!1;throw e}}async function M(t,e){if(!I(t))return!0;let r=Date.now();for(;Date.now()-r<e;)if(await new Promise(t=>setTimeout(t,50)),!I(t))return!0;return!I(t)}async function E(t,e){!N(t,e.expectedStartTime)||!y(t,"SIGTERM")||await M(t,e.termTimeoutMs)||y(t,"SIGKILL")&&await M(t,e.killTimeoutMs)}let D=100,L=new Set(["batch","replay"]);function $(t){let e;try{e=JSON.parse(t)}catch{throw new a("INVALID_ARGS","Batch steps must be valid JSON.")}if(!Array.isArray(e)||0===e.length)throw new a("INVALID_ARGS","Batch steps must be a non-empty JSON array.");return e}function _(t,e){if(!Array.isArray(t)||0===t.length)throw new a("INVALID_ARGS","batch requires a non-empty batchSteps array.");if(t.length>e)throw new a("INVALID_ARGS",`batch has ${t.length} steps; max allowed is ${e}.`);let r=[];for(let e=0;e<t.length;e+=1){let n=t[e];if(!n||"object"!=typeof n)throw new a("INVALID_ARGS",`Invalid batch step at index ${e}.`);let o="string"==typeof n.command?n.command.trim().toLowerCase():"";if(!o)throw new a("INVALID_ARGS",`Batch step ${e+1} requires command.`);if(L.has(o))throw new a("INVALID_ARGS",`Batch step ${e+1} cannot run ${o}.`);if(void 0!==n.positionals&&!Array.isArray(n.positionals))throw new a("INVALID_ARGS",`Batch step ${e+1} positionals must be an array.`);let i=n.positionals??[];if(i.some(t=>"string"!=typeof t))throw new a("INVALID_ARGS",`Batch step ${e+1} positionals must contain only strings.`);if(void 0!==n.flags&&("object"!=typeof n.flags||Array.isArray(n.flags)||!n.flags))throw new a("INVALID_ARGS",`Batch step ${e+1} flags must be an object.`);r.push({command:o,positionals:i,flags:n.flags??{}})}return r}export{default as node_net}from"node:net";export{default as node_os}from"node:os";export{a as AppError,D as DEFAULT_BATCH_MAX_STEPS,u as asAppError,n as fileURLToPath,l as findProjectRoot,N as isAgentDeviceDaemonProcess,I as isProcessAlive,t as node_fs,r as node_path,$ as parseBatchStepsJson,o as pathToFileURL,e as promises,g as readProcessStartTime,d as readVersion,c as runCmd,h as runCmdBackground,m as runCmdDetached,w as runCmdStreaming,E as stopProcessForTakeover,_ as validateAndNormalizeBatchSteps,f as whichCmd};
|
package/dist/src/bin.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import{node_path as e,
|
|
1
|
+
import{node_path as e,parseBatchStepsJson as t,asAppError as s,isAgentDeviceDaemonProcess as a,runCmdDetached as i,node_fs as n,node_os as r,node_net as o,AppError as l,readVersion as p,findProjectRoot as c,stopProcessForTakeover as u,pathToFileURL as d}from"./50.js";let g=["snapshotDepth","snapshotScope","snapshotRaw"],m=[{key:"platform",names:["--platform"],type:"enum",enumValues:["ios","android"],usageLabel:"--platform ios|android",usageDescription:"Platform to target"},{key:"device",names:["--device"],type:"string",usageLabel:"--device <name>",usageDescription:"Device name to target"},{key:"udid",names:["--udid"],type:"string",usageLabel:"--udid <udid>",usageDescription:"iOS device UDID"},{key:"serial",names:["--serial"],type:"string",usageLabel:"--serial <serial>",usageDescription:"Android device serial"},{key:"activity",names:["--activity"],type:"string",usageLabel:"--activity <component>",usageDescription:"Android app launch activity (package/Activity); not for URL opens"},{key:"session",names:["--session"],type:"string",usageLabel:"--session <name>",usageDescription:"Named session"},{key:"count",names:["--count"],type:"int",min:1,max:200,usageLabel:"--count <n>",usageDescription:"Repeat count for press/swipe series"},{key:"intervalMs",names:["--interval-ms"],type:"int",min:0,max:1e4,usageLabel:"--interval-ms <ms>",usageDescription:"Delay between press iterations"},{key:"holdMs",names:["--hold-ms"],type:"int",min:0,max:1e4,usageLabel:"--hold-ms <ms>",usageDescription:"Press hold duration for each iteration"},{key:"jitterPx",names:["--jitter-px"],type:"int",min:0,max:100,usageLabel:"--jitter-px <n>",usageDescription:"Deterministic coordinate jitter radius for press"},{key:"pauseMs",names:["--pause-ms"],type:"int",min:0,max:1e4,usageLabel:"--pause-ms <ms>",usageDescription:"Delay between swipe iterations"},{key:"pattern",names:["--pattern"],type:"enum",enumValues:["one-way","ping-pong"],usageLabel:"--pattern one-way|ping-pong",usageDescription:"Swipe repeat pattern"},{key:"verbose",names:["--verbose","-v"],type:"boolean",usageLabel:"--verbose",usageDescription:"Stream daemon/runner logs"},{key:"json",names:["--json"],type:"boolean",usageLabel:"--json",usageDescription:"JSON output"},{key:"help",names:["--help","-h"],type:"boolean",usageLabel:"--help, -h",usageDescription:"Print help and exit"},{key:"version",names:["--version","-V"],type:"boolean",usageLabel:"--version, -V",usageDescription:"Print version and exit"},{key:"saveScript",names:["--save-script"],type:"booleanOrString",usageLabel:"--save-script [path]",usageDescription:"Save session script (.ad) on close; optional custom output path"},{key:"relaunch",names:["--relaunch"],type:"boolean",usageLabel:"--relaunch",usageDescription:"open: terminate app process before launching it"},{key:"noRecord",names:["--no-record"],type:"boolean",usageLabel:"--no-record",usageDescription:"Do not record this action"},{key:"replayUpdate",names:["--update","-u"],type:"boolean",usageLabel:"--update, -u",usageDescription:"Replay: update selectors and rewrite replay file in place"},{key:"steps",names:["--steps"],type:"string",usageLabel:"--steps <json>",usageDescription:"Batch: JSON array of steps"},{key:"stepsFile",names:["--steps-file"],type:"string",usageLabel:"--steps-file <path>",usageDescription:"Batch: read steps JSON from file"},{key:"batchOnError",names:["--on-error"],type:"enum",enumValues:["stop"],usageLabel:"--on-error stop",usageDescription:"Batch: stop when a step fails"},{key:"batchMaxSteps",names:["--max-steps"],type:"int",min:1,max:1e3,usageLabel:"--max-steps <n>",usageDescription:"Batch: maximum number of allowed steps"},{key:"appsFilter",names:["--user-installed"],type:"enum",setValue:"user-installed",usageLabel:"--user-installed",usageDescription:"Apps: list user-installed apps"},{key:"appsFilter",names:["--all"],type:"enum",setValue:"all",usageLabel:"--all",usageDescription:"Apps: list all apps (include system/default apps)"},{key:"snapshotInteractiveOnly",names:["-i"],type:"boolean",usageLabel:"-i",usageDescription:"Snapshot: interactive elements only"},{key:"snapshotCompact",names:["-c"],type:"boolean",usageLabel:"-c",usageDescription:"Snapshot: compact output (drop empty structure)"},{key:"snapshotDepth",names:["--depth","-d"],type:"int",min:0,usageLabel:"--depth, -d <depth>",usageDescription:"Snapshot: limit snapshot depth"},{key:"snapshotScope",names:["--scope","-s"],type:"string",usageLabel:"--scope, -s <scope>",usageDescription:"Snapshot: scope snapshot to label/identifier"},{key:"snapshotRaw",names:["--raw"],type:"boolean",usageLabel:"--raw",usageDescription:"Snapshot: raw node output"},{key:"out",names:["--out"],type:"string",usageLabel:"--out <path>",usageDescription:"Output path"}],f=new Set(["json","help","version","verbose","platform","device","udid","serial","session","noRecord"]),h={boot:{description:"Ensure target device/simulator is booted and ready",positionalArgs:[],allowedFlags:[]},open:{description:"Boot device/simulator; optionally launch app or deep link URL",positionalArgs:["appOrUrl?","url?"],allowedFlags:["activity","saveScript","relaunch"]},close:{description:"Close app or just end session",positionalArgs:["app?"],allowedFlags:["saveScript"]},reinstall:{description:"Uninstall + install app from binary path",positionalArgs:["app","path"],allowedFlags:[]},snapshot:{description:"Capture accessibility tree",positionalArgs:[],allowedFlags:["snapshotInteractiveOnly","snapshotCompact","snapshotDepth","snapshotScope","snapshotRaw"]},devices:{description:"List available devices",positionalArgs:[],allowedFlags:[],skipCapabilityCheck:!0},apps:{description:"List installed apps (includes default/system apps by default)",positionalArgs:[],allowedFlags:["appsFilter"],defaults:{appsFilter:"all"}},appstate:{description:"Show foreground app/activity",positionalArgs:[],allowedFlags:[],skipCapabilityCheck:!0},back:{description:"Navigate back (where supported)",positionalArgs:[],allowedFlags:[]},home:{description:"Go to home screen (where supported)",positionalArgs:[],allowedFlags:[]},"app-switcher":{description:"Open app switcher (where supported)",positionalArgs:[],allowedFlags:[]},wait:{usageOverride:"wait <ms>|text <text>|@ref|<selector> [timeoutMs]",description:"Wait for duration, text, ref, or selector to appear",positionalArgs:["durationOrSelector","timeoutMs?"],allowsExtraPositionals:!0,allowedFlags:[...g]},alert:{usageOverride:"alert [get|accept|dismiss|wait] [timeout]",description:"Inspect or handle alert (iOS simulator)",positionalArgs:["action?","timeout?"],allowedFlags:[]},click:{usageOverride:"click <@ref|selector>",description:"Click element by snapshot ref or selector",positionalArgs:["target"],allowedFlags:[...g]},get:{usageOverride:"get text|attrs <@ref|selector>",description:"Return element text/attributes by ref or selector",positionalArgs:["subcommand","target"],allowedFlags:[...g]},replay:{description:"Replay a recorded session",positionalArgs:["path"],allowedFlags:["replayUpdate"],skipCapabilityCheck:!0},batch:{usageOverride:"batch [--steps <json> | --steps-file <path>]",description:"Execute multiple commands in one daemon request",positionalArgs:[],allowedFlags:["steps","stepsFile","batchOnError","batchMaxSteps","out"],skipCapabilityCheck:!0},press:{description:"Tap/press at coordinates (supports repeated gesture series)",positionalArgs:["x","y"],allowedFlags:["count","intervalMs","holdMs","jitterPx"]},"long-press":{description:"Long press (where supported)",positionalArgs:["x","y","durationMs?"],allowedFlags:[]},swipe:{description:"Swipe coordinates with optional repeat pattern",positionalArgs:["x1","y1","x2","y2","durationMs?"],allowedFlags:["count","pauseMs","pattern"]},focus:{description:"Focus input at coordinates",positionalArgs:["x","y"],allowedFlags:[]},type:{description:"Type text in focused field",positionalArgs:["text"],allowsExtraPositionals:!0,allowedFlags:[]},fill:{usageOverride:"fill <x> <y> <text> | fill <@ref|selector> <text>",description:"Tap then type",positionalArgs:["targetOrX","yOrText","text?"],allowsExtraPositionals:!0,allowedFlags:[...g]},scroll:{description:"Scroll in direction (0-1 amount)",positionalArgs:["direction","amount?"],allowedFlags:[]},scrollintoview:{description:"Scroll until text appears",positionalArgs:["text"],allowedFlags:[]},pinch:{description:"Pinch/zoom gesture (iOS simulator)",positionalArgs:["scale","x?","y?"],allowedFlags:[]},screenshot:{description:"Capture screenshot",positionalArgs:["path?"],allowedFlags:["out"]},record:{usageOverride:"record start [path] | record stop",description:"Start/stop screen recording",positionalArgs:["start|stop","path?"],allowedFlags:[]},trace:{usageOverride:"trace start [path] | trace stop [path]",description:"Start/stop trace log capture",positionalArgs:["start|stop","path?"],allowedFlags:[],skipCapabilityCheck:!0},find:{usageOverride:"find <locator|text> <action> [value]",description:"Find by text/label/value/role/id and run action",positionalArgs:["query","action","value?"],allowsExtraPositionals:!0,allowedFlags:["snapshotDepth","snapshotRaw"]},is:{description:"Assert UI state (visible|hidden|exists|editable|selected|text)",positionalArgs:["predicate","selector","value?"],allowsExtraPositionals:!0,allowedFlags:[...g]},settings:{description:"Toggle OS settings (simulators)",positionalArgs:["setting","state"],allowedFlags:[]},session:{usageOverride:"session list",description:"List active sessions",positionalArgs:["list?"],allowedFlags:[],skipCapabilityCheck:!0}},y=new Map,w=new Map;for(let e of m){for(let t of e.names)y.set(t,e);let t=w.get(e.key);t?t.push(e):w.set(e.key,[e])}function v(e){if(e)return h[e]}function b(e){let t=e.endsWith("?"),s=t?e.slice(0,-1):e;return t?`[${s}]`:`<${s}>`}function x(e,t){return t.usageOverride?t.usageOverride:[e,...t.positionalArgs.map(b),...t.allowedFlags.flatMap(e=>(w.get(e)??[]).map(e=>e.usageLabel??e.names[0])).map(e=>`[${e}]`)].join(" ")}let $=function(){let e=`agent-device <command> [args] [--json]
|
|
2
2
|
|
|
3
3
|
CLI to control iOS and Android devices for AI agents.
|
|
4
|
-
`,t=Object.keys(
|
|
4
|
+
`,t=Object.keys(h).map(e=>{let t=h[e];if(!t)throw Error(`Missing command schema for ${e}`);return{name:e,schema:t,usage:x(e,t)}}),s=Math.max(...t.map(e=>e.usage.length))+2,a=["Commands:"];for(let e of t)a.push(` ${e.usage.padEnd(s)}${e.schema.description}`);let i=A("Flags:",m.filter(e=>e.usageLabel&&e.usageDescription));return`${e}
|
|
5
5
|
${a.join("\n")}
|
|
6
6
|
|
|
7
7
|
${i}
|
|
8
|
-
`}();function
|
|
9
|
-
(none)`;let s=Math.max(...t.map(e=>(e.usageLabel??"").length))+2,a=[e];for(let e of t)a.push(` ${(e.usageLabel??"").padEnd(s)}${e.usageDescription??""}`);return a.join("\n")}function
|
|
10
|
-
`)}function
|
|
8
|
+
`}();function k(e){return m.filter(t=>e.has(t.key)&&void 0!==t.usageLabel&&void 0!==t.usageDescription)}function A(e,t){if(0===t.length)return`${e}
|
|
9
|
+
(none)`;let s=Math.max(...t.map(e=>(e.usageLabel??"").length))+2,a=[e];for(let e of t)a.push(` ${(e.usageLabel??"").padEnd(s)}${e.usageDescription??""}`);return a.join("\n")}function S(e){let t=e.indexOf("=");return -1===t?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}function D(e){return e.replace(/^-+/,"")}function F(e){if(!e.startsWith("-")||"-"===e)return!1;let[t]=e.startsWith("--")?S(e):[e,void 0];return void 0!==y.get(t)}function L(e){process.stdout.write(`${JSON.stringify(e,null,2)}
|
|
10
|
+
`)}function I(e){let t=e.details?`
|
|
11
11
|
${JSON.stringify(e.details,null,2)}`:"";process.stderr.write(`Error (${e.code}): ${e.message}${t}
|
|
12
|
-
`)}function
|
|
13
|
-
`)}),n=setTimeout(()=>{i.destroy(),a(new
|
|
14
|
-
`);
|
|
15
|
-
`),process.exit(0));let
|
|
16
|
-
`),process.exit(0));let t=function(e){let t=
|
|
12
|
+
`)}function N(e,t,s){let a=O(e.type??"Element"),i=function(e,t){var s,a;let i=e.label?.trim(),n=e.value?.trim();if("text-field"===(s=t)||"text-view"===s||"search"===s){if(n)return n;if(i)return i}else if(i)return i;if(n)return n;let r=e.identifier?.trim();return!r||(a=r,/^[\w.]+:id\/[\w.-]+$/i.test(a)&&("group"===t||"image"===t||"list"===t||"collection"===t))?"":r}(e,a),n=" ".repeat(t),r=e.ref?`@${e.ref}`:"",o=[!1===e.enabled?"disabled":null].filter(Boolean).join(", "),l=o?` [${o}]`:"",p=i?` "${i}"`:"";return s?`${n}${r} [${a}]${l}`.trimEnd():`${n}${r} [${a}]${p}${l}`.trimEnd()}function O(e){let t=e.replace(/XCUIElementType/gi,"").toLowerCase(),s=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));switch(t.includes(".")&&(t=t.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,"")),t){case"application":return"application";case"navigationbar":return"navigation-bar";case"tabbar":return"tab-bar";case"button":case"imagebutton":return"button";case"link":return"link";case"cell":return"cell";case"statictext":case"checkedtextview":return"text";case"textfield":case"edittext":return"text-field";case"textview":return s?"text":"text-view";case"textarea":return"text-view";case"switch":return"switch";case"slider":return"slider";case"image":case"imageview":return"image";case"webview":return"webview";case"framelayout":case"linearlayout":case"relativelayout":case"constraintlayout":case"viewgroup":case"view":case"group":return"group";case"listview":case"recyclerview":return"list";case"collectionview":return"collection";case"searchfield":return"search";case"segmentedcontrol":return"segmented-control";case"window":return"window";case"checkbox":return"checkbox";case"radio":return"radio";case"menuitem":return"menu-item";case"toolbar":return"toolbar";case"scrollarea":case"scrollview":case"nestedscrollview":return"scroll-area";case"table":return"table";default:return t||"element"}}let j=e.join(r.homedir(),".agent-device"),E=e.join(j,"daemon.json"),M=e.join(j,"daemon.lock"),C=function(e=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if(!e)return 9e4;let t=Number(e);return Number.isFinite(t)?Math.max(1e3,Math.floor(t)):9e4}();async function _(e){let t=await T(),s={...e,token:t.token};return await K(t,s)}async function T(){var e;let t=G(),s=p(),i=!!t&&await q(t);if(t&&t.version===s&&i)return t;t&&(t.version!==s||!i)&&(await P(t),J(E)),function(){let e=W();if(!e.hasLock||e.hasInfo)return;let t=U();t&&a(t.pid,t.processStartTime)||J(M)}(),await z();let n=await R(5e3);if(n)return n;if(await V()){await z();let e=await R(5e3);if(e)return e}throw new l("COMMAND_FAILED","Failed to start daemon",{kind:"daemon_startup_failed",infoPath:E,lockPath:M,hint:(e=W()).hasLock&&!e.hasInfo?"Detected ~/.agent-device/daemon.lock without daemon.json. If no agent-device daemon process is running, delete ~/.agent-device/daemon.lock and retry.":e.hasLock&&e.hasInfo?"Daemon metadata may be stale. If no agent-device daemon process is running, delete ~/.agent-device/daemon.json and ~/.agent-device/daemon.lock, then retry.":"Daemon metadata is missing or stale. Delete ~/.agent-device/daemon.json if present and retry."})}async function R(e){let t=Date.now();for(;Date.now()-t<e;){let e=G();if(e&&await q(e))return e;await new Promise(e=>setTimeout(e,100))}return null}async function V(){let e=W();if(!e.hasLock||e.hasInfo)return!1;let t=U();return t&&a(t.pid,t.processStartTime)&&await u(t.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:t.processStartTime}),J(M),!0}async function P(e){await u(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}function G(){let e=B(E);return e&&e.port&&e.token?{...e,pid:Number.isInteger(e.pid)&&e.pid>0?e.pid:0}:null}function U(){let e=B(M);return e&&Number.isInteger(e.pid)&&!(e.pid<=0)?e:null}function W(){return{hasInfo:n.existsSync(E),hasLock:n.existsSync(M)}}function B(e){if(!n.existsSync(e))return null;try{return JSON.parse(n.readFileSync(e,"utf8"))}catch{return null}}function J(e){try{n.existsSync(e)&&n.unlinkSync(e)}catch{}}async function q(e){return new Promise(t=>{let s=o.createConnection({host:"127.0.0.1",port:e.port},()=>{s.destroy(),t(!0)});s.on("error",()=>{t(!1)})})}async function z(){let t=c(),s=e.join(t,"dist","src","daemon.js"),a=e.join(t,"src","daemon.ts"),r=n.existsSync(s),o=n.existsSync(a);if(!r&&!o)throw new l("COMMAND_FAILED","Daemon entry not found",{distPath:s,srcPath:a});let p=(process.execArgv.includes("--experimental-strip-types")?o:!r&&o)?["--experimental-strip-types",a]:[s];i(process.execPath,p)}async function K(e,t){return new Promise((s,a)=>{let i=o.createConnection({host:"127.0.0.1",port:e.port},()=>{i.write(`${JSON.stringify(t)}
|
|
13
|
+
`)}),n=setTimeout(()=>{i.destroy(),a(new l("COMMAND_FAILED","Daemon request timed out",{timeoutMs:C}))},C),r="";i.setEncoding("utf8"),i.on("data",e=>{let t=(r+=e).indexOf("\n");if(-1===t)return;let o=r.slice(0,t).trim();if(o)try{let e=JSON.parse(o);i.end(),clearTimeout(n),s(e)}catch(e){clearTimeout(n),a(e)}}),i.on("error",e=>{clearTimeout(n),a(e)})})}let X={sendToDaemon:_};async function Z(a,i=X){var o,c;let u=function(e,t){let s=(void 0)??function(e){if(!e)return!1;let t=e.trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}(process.env.AGENT_DEVICE_STRICT_FLAGS),a={json:!1,help:!1,version:!1},i=null,n=[],r=[],o=[],p=!0;for(let t=0;t<e.length;t+=1){let s=e[t];if(p&&"--"===s){p=!1;continue}if(!p){i?n.push(s):i=s;continue}let r=s.startsWith("--"),c=s.startsWith("-")&&s.length>1;if(!r&&!c){i?n.push(s):i=s;continue}let[u,d]=r?S(s):[s,void 0],g=y.get(u);if(!g){if(function(e,t,s){var a;if(a=s,!/^-\d+(\.\d+)?$/.test(a)||!e)return!1;let i=v(e);return!i||!!i.allowsExtraPositionals||0!==i.positionalArgs.length&&(t.length<i.positionalArgs.length||i.positionalArgs.some(e=>e.includes("?")))}(i,n,s)){i?n.push(s):i=s;continue}throw new l("INVALID_ARGS",`Unknown flag: ${u}`)}let m=function(e,t,s,a){if(void 0!==e.setValue){if(void 0!==s)throw new l("INVALID_ARGS",`Flag ${t} does not take a value.`);return{value:e.setValue,consumeNext:!1}}if("boolean"===e.type){if(void 0!==s)throw new l("INVALID_ARGS",`Flag ${t} does not take a value.`);return{value:!0,consumeNext:!1}}if("booleanOrString"===e.type){if(void 0!==s){if(0===s.trim().length)throw new l("INVALID_ARGS",`Flag ${t} requires a non-empty value when provided.`);return{value:s,consumeNext:!1}}return void 0===a||F(a)||!function(e){let t=e.trim();return!(!t||/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(t))&&!!(t.startsWith("./")||t.startsWith("../")||t.startsWith("~/")||t.startsWith("/")||t.includes("/")||t.includes("\\"))}(a)?{value:!0,consumeNext:!1}:{value:a,consumeNext:!0}}let i=s??a;if(void 0===i||void 0===s&&F(i))throw new l("INVALID_ARGS",`Flag ${t} requires a value.`);if("string"===e.type)return{value:i,consumeNext:void 0===s};if("enum"===e.type){if(!e.enumValues?.includes(i))throw new l("INVALID_ARGS",`Invalid ${D(t)}: ${i}`);return{value:i,consumeNext:void 0===s}}let n=Number(i);if(!Number.isFinite(n)||"number"==typeof e.min&&n<e.min||"number"==typeof e.max&&n>e.max)throw new l("INVALID_ARGS",`Invalid ${D(t)}: ${i}`);return{value:Math.floor(n),consumeNext:void 0===s}}(g,u,d,e[t+1]);m.consumeNext&&(t+=1),a[g.key]=m.value,o.push({key:g.key,token:u})}let c=v(i),u=new Set([...f,...c?.allowedFlags??[]]),d=o.filter(e=>!u.has(e.key));if(d.length>0){var g,m;let e=(g=i,m=d.map(e=>e.token),g?1===m.length?`Flag ${m[0]} is not supported for command ${g}.`:`Flags ${m.join(", ")} are not supported for command ${g}.`:1===m.length?`Flag ${m[0]} requires a command that supports it.`:`Flags ${m.join(", ")} require a command that supports them.`);if(s)throw new l("INVALID_ARGS",e);for(let t of(r.push(`${e} Enable AGENT_DEVICE_STRICT_FLAGS=1 to fail fast.`),d))delete a[t.key]}if(c?.defaults)for(let[e,t]of Object.entries(c.defaults))void 0===a[e]&&(a[e]=t);if("batch"===i&&1!=+!!a.steps+ +!!a.stepsFile)throw new l("INVALID_ARGS","batch requires exactly one step source: --steps or --steps-file.");return{command:i,positionals:n,flags:a,warnings:r}}(a);for(let e of u.warnings)process.stderr.write(`Warning: ${e}
|
|
14
|
+
`);u.flags.version&&(process.stdout.write(`${p()}
|
|
15
|
+
`),process.exit(0));let d="help"===u.command,g=u.flags.help;if(d||g){d&&u.positionals.length>1&&(I(new l("INVALID_ARGS","help accepts at most one command.")),process.exit(1));let e=d?u.positionals[0]:u.command;e||(process.stdout.write(`${$}
|
|
16
|
+
`),process.exit(0));let t=function(e){let t=v(e);if(!t)return null;let s=x(e,t),a=k(new Set(t.allowedFlags)),i=k(f),n=[];return a.length>0&&n.push(A("Command flags:",a)),n.push(A("Global flags:",i)),`agent-device ${s}
|
|
17
17
|
|
|
18
18
|
${t.description}
|
|
19
19
|
|
|
@@ -21,33 +21,34 @@ Usage:
|
|
|
21
21
|
agent-device ${s}
|
|
22
22
|
|
|
23
23
|
${n.join("\n\n")}
|
|
24
|
-
`}(e);t&&(process.stdout.write(t),process.exit(0)),
|
|
25
|
-
`),process.exit(1)}
|
|
26
|
-
`),process.exit(1));let{command:
|
|
27
|
-
`),
|
|
24
|
+
`}(e);t&&(process.stdout.write(t),process.exit(0)),I(new l("INVALID_ARGS",`Unknown command: ${e}`)),process.stdout.write(`${$}
|
|
25
|
+
`),process.exit(1)}u.command||(process.stdout.write(`${$}
|
|
26
|
+
`),process.exit(1));let{command:m,positionals:h,flags:w}=u,b=function(e){let{json:t,help:s,version:a,...i}=e;return i}(w),j=w.session??process.env.AGENT_DEVICE_SESSION??"default",E=w.verbose&&!w.json?function(){try{let t=e.join(r.homedir(),".agent-device","daemon.log"),s=0,a=!1,i=setInterval(()=>{if(!a&&n.existsSync(t))try{let e=n.statSync(t);if(e.size<s&&(s=0),e.size<=s)return;let a=n.openSync(t,"r");try{let t=Buffer.alloc(e.size-s);n.readSync(a,t,0,t.length,s),s=e.size,t.length>0&&process.stdout.write(t.toString("utf8"))}finally{n.closeSync(a)}}catch{}},200);return()=>{a=!0,clearInterval(i)}}catch{return null}}():null;try{if("batch"===m){let e,s,a;if(h.length>0)throw new l("INVALID_ARGS","batch does not accept positional arguments.");let r=function(e){let s="";if(e.steps)s=e.steps;else if(e.stepsFile)try{s=n.readFileSync(e.stepsFile,"utf8")}catch(s){let t=s instanceof Error?s.message:String(s);throw new l("INVALID_ARGS",`Failed to read --steps-file ${e.stepsFile}: ${t}`)}return t(s)}(w),p={...b,batchSteps:r};delete p.steps,delete p.stepsFile;let c=await i.sendToDaemon({session:j,command:"batch",positionals:h,flags:p});if(!c.ok)throw new l(c.error.code,c.error.message,c.error.details);w.json?L({success:!0,data:c.data??{}}):(o=c.data??{},e="number"==typeof o.total?o.total:0,s="number"==typeof o.executed?o.executed:0,a="number"==typeof o.totalDurationMs?o.totalDurationMs:void 0,process.stdout.write(`Batch completed: ${s}/${e} steps${void 0!==a?` in ${a}ms`:""}
|
|
27
|
+
`)),E&&E();return}if("session"===m){let e=h[0]??"list";if("list"!==e)throw new l("INVALID_ARGS","session only supports list");let t=await i.sendToDaemon({session:j,command:"session_list",positionals:[],flags:b});if(!t.ok)throw new l(t.error.code,t.error.message);w.json?L({success:!0,data:t.data??{}}):process.stdout.write(`${JSON.stringify(t.data??{},null,2)}
|
|
28
|
+
`),E&&E();return}let e=await i.sendToDaemon({session:j,command:m,positionals:h,flags:b});if(e.ok){if(w.json){L({success:!0,data:e.data??{}}),E&&E();return}if("snapshot"===m){process.stdout.write(function(e,t={}){let s=e.nodes,a=Array.isArray(s)?s:[],i=!!e.truncated,n="string"==typeof e.appName?e.appName:void 0,r="string"==typeof e.appBundleId?e.appBundleId:void 0,o=[];n&&o.push(`Page: ${n}`),r&&o.push(`App: ${r}`);let l=`Snapshot: ${a.length} nodes${i?" (truncated)":""}`,p=o.length>0?`${o.join("\n")}
|
|
28
29
|
`:"";if(0===a.length)return`${p}${l}
|
|
29
30
|
`;if(t.raw){let e=a.map(e=>JSON.stringify(e));return`${p}${l}
|
|
30
31
|
${e.join("\n")}
|
|
31
|
-
`}if(t.flatten){let e=a.map(e=>
|
|
32
|
+
`}if(t.flatten){let e=a.map(e=>N(e,0,!1));return`${p}${l}
|
|
32
33
|
${e.join("\n")}
|
|
33
|
-
`}let c=[],u=[];for(let e of a){let t=e.depth??0;for(;c.length>0&&t<=c[c.length-1];)c.pop();let s=e.label?.trim()||e.value?.trim()||e.identifier?.trim()||"",a="group"===
|
|
34
|
+
`}let c=[],u=[];for(let e of a){let t=e.depth??0;for(;c.length>0&&t<=c[c.length-1];)c.pop();let s=e.label?.trim()||e.value?.trim()||e.identifier?.trim()||"",a="group"===O(e.type??"Element")&&!s;a&&c.push(t);let i=a?t:Math.max(0,t-c.length);u.push(N(e,i,a))}return`${p}${l}
|
|
34
35
|
${u.join("\n")}
|
|
35
|
-
`}(e.data??{},{raw:
|
|
36
|
-
`),
|
|
37
|
-
`),
|
|
38
|
-
`),
|
|
39
|
-
`),
|
|
40
|
-
`),
|
|
41
|
-
`),
|
|
42
|
-
`),
|
|
43
|
-
`),
|
|
44
|
-
`),
|
|
45
|
-
`),
|
|
36
|
+
`}(e.data??{},{raw:w.snapshotRaw,flatten:w.snapshotInteractiveOnly})),E&&E();return}if("get"===m){let t=h[0];if("text"===t){let t=e.data?.text??"";process.stdout.write(`${t}
|
|
37
|
+
`),E&&E();return}if("attrs"===t){let t=e.data?.node??{};process.stdout.write(`${JSON.stringify(t,null,2)}
|
|
38
|
+
`),E&&E();return}}if("find"===m){let t=e.data;if("string"==typeof t?.text){process.stdout.write(`${t.text}
|
|
39
|
+
`),E&&E();return}if("boolean"==typeof t?.found){process.stdout.write(`Found: ${t.found}
|
|
40
|
+
`),E&&E();return}if(t?.node){process.stdout.write(`${JSON.stringify(t.node,null,2)}
|
|
41
|
+
`),E&&E();return}}if("is"===m){let t=e.data?.predicate??"assertion";process.stdout.write(`Passed: is ${t}
|
|
42
|
+
`),E&&E();return}if("boot"===m){let t=e.data?.platform??"unknown",s=e.data?.device??e.data?.id??"unknown";process.stdout.write(`Boot ready: ${s} (${t})
|
|
43
|
+
`),E&&E();return}if("click"===m){let t=e.data?.ref??"",s=e.data?.x,a=e.data?.y;t&&"number"==typeof s&&"number"==typeof a&&process.stdout.write(`Clicked @${t} (${s}, ${a})
|
|
44
|
+
`),E&&E();return}if(e.data&&"object"==typeof e.data){let t=e.data;if("devices"===m){let e=(Array.isArray(t.devices)?t.devices:[]).map(e=>{let t=e?.name??e?.id??"unknown",s=e?.platform??"unknown",a=e?.kind?` ${e.kind}`:"",i="boolean"==typeof e?.booted?` booted=${e.booted}`:"";return`${t} (${s}${a})${i}`});process.stdout.write(`${e.join("\n")}
|
|
45
|
+
`),E&&E();return}if("apps"===m){let e=(Array.isArray(t.apps)?t.apps:[]).map(e=>{if("string"==typeof e)return e;if(e&&"object"==typeof e){let t=e.bundleId??e.package,s=e.name??e.label;return s&&t?`${s} (${t})`:t?String(t):JSON.stringify(e)}return String(e)});process.stdout.write(`${e.join("\n")}
|
|
46
|
+
`),E&&E();return}if("appstate"===m){let e=t?.platform,s=t?.appBundleId,a=t?.appName,i=t?.source,n=t?.package,r=t?.activity;if("ios"===e){process.stdout.write(`Foreground app: ${a??s??"unknown"}
|
|
46
47
|
`),s&&process.stdout.write(`Bundle: ${s}
|
|
47
48
|
`),i&&process.stdout.write(`Source: ${i}
|
|
48
|
-
`),
|
|
49
|
+
`),E&&E();return}if("android"===e){process.stdout.write(`Foreground app: ${n??"unknown"}
|
|
49
50
|
`),r&&process.stdout.write(`Activity: ${r}
|
|
50
|
-
`),
|
|
51
|
+
`),E&&E();return}}}E&&E();return}throw new l(e.error.code,e.error.message,e.error.details)}catch(a){let t=s(a);if("close"===m&&"COMMAND_FAILED"===(c=t).code&&(c.details?.kind==="daemon_startup_failed"||c.message.toLowerCase().includes("failed to start daemon")&&("string"==typeof c.details?.infoPath||"string"==typeof c.details?.lockPath))){w.json&&L({success:!0,data:{closed:"session",source:"no-daemon"}}),E&&E();return}if(w.json)L({success:!1,error:{code:t.code,message:t.message,details:t.details}});else if(I(t),w.verbose)try{let t=e.join(r.homedir(),".agent-device","daemon.log");if(n.existsSync(t)){let e=n.readFileSync(t,"utf8").split("\n"),s=e.slice(Math.max(0,e.length-200)).join("\n");s.trim().length>0&&process.stderr.write(`
|
|
51
52
|
[daemon log]
|
|
52
53
|
${s}
|
|
53
|
-
`)}}catch{}
|
|
54
|
+
`)}}catch{}E&&E(),process.exit(1)}}d(process.argv[1]??"").href===import.meta.url&&Z(process.argv.slice(2)).catch(e=>{I(s(e)),process.exit(1)}),Z(process.argv.slice(2));
|