UNPKG

agent-device

Version:

Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.

3 lines • 1.24 kB
import{v as e}from"./sdk-contracts.js";import{n as t}from"./session-artifact-paths.js";import{t as n}from"./error.js";import{r,t as i}from"./args.js";import a from"node:fs";async function o(e,t={}){let r=t.command??(t.argv?c(t.argv):null),i=e.code===`INVALID_ARGS`&&r?await s(r):void 0,{summary:a,body:o}=n(e,{showDetails:t.debugTier,synopsis:i}),u=t.logTail?l(t.logTail):void 0,d=[a,...o,...u?[u]:[]];d.length>1&&d.push(a);for(let e of d)process.stderr.write(`${e}\n`)}async function s(e){let t=await i(e);if(t)return t.length<=160?t:`see agent-device help ${e}`}function c(t){for(let n=t.length;n>0;--n)try{return r(t.slice(0,n)).command}catch(t){if(!(t instanceof e))throw t}return null}function l(e){try{return e.daemonBaseUrl?e.record?u(`remote diagnostics`,t(e.daemonPaths.baseDir,e.record)):void 0:u(`daemon log`,e.daemonPaths.logPath)}catch{return}}function u(e,t){if(!a.existsSync(t))return;let n=d(t,64e3,200);return n.trim().length>0?`\n[${e}]\n${n.trimEnd()}`:void 0}function d(e,t,n){let r=a.openSync(e,`r`);try{let e=a.fstatSync(r).size,i=Math.min(e,t),o=Buffer.alloc(i);a.readSync(r,o,0,i,e-i);let s=o.toString(`utf8`).split(` `);return i<e&&s.shift(),s.slice(-n).join(` `)}finally{a.closeSync(r)}}export{o as printHumanError};