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.
1 lines • 2.84 kB
JavaScript
import{r as e,s as t}from"./version.js";import n from"node:crypto";import r from"node:fs";import i from"node:path";const a=/(['"])(\.\.?\/[^'"]*)\1/g,o=/(['"])(@[^'"/\s]+\/[^'"\s]+)\1/g,s=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`];function c(){let e=process.argv[1];return e?u(e):`unknown`}function l(n=e()){return t(n)?`checkout`:`installed`}function u(t,n=e()){try{return g(d(t,n).files)}catch{return`unknown`}}function d(e,t){let n=h(t),i=[h(e)],a=new Set,o=[],s=new Set,c={root:n,packages:new Map,absentPaths:s,stamp:e=>{if(a.has(e))return!1;a.add(e);let t=r.statSync(e);if(!t.isFile())return!1;let i=m(n,e);return o.push([i,t.size,Math.trunc(t.mtimeMs)]),!0},follow:e=>{for(let t of e.missedCandidates)s.add(m(n,t));e.filePath&&i.push(e.filePath)}};for(;i.length>0;){let e=i.pop();if(e===void 0||a.has(e)||!c.stamp(e))continue;let t=r.readFileSync(e,`utf8`);for(let n of _(t))c.follow(w(e,n));f(t,c)}return{files:o,absentPaths:[...s]}}function f(e,t){for(let n of v(e)){let{name:e,subpath:r}=y(n),i=p(e,t);if(!i)continue;let a=S(i.manifest,r);a!==void 0&&t.follow(w(i.manifestPath,a))}}function p(e,t){let n=t.packages.get(e);if(n!==void 0)return n;let r=b(t.root,e,t.absentPaths);return t.packages.set(e,r),r&&t.stamp(r.manifestPath),r}function m(e,t){let n=i.resolve(t);return i.relative(i.resolve(e),n)||n}function h(e){try{return r.realpathSync.native(e)}catch{return i.resolve(e)}}function g(e){let t=e.map(([e,t,n])=>`${e}:${t}:${n}`).sort().join(`|`),r=n.createHash(`sha1`).update(t).digest(`hex`);return`graph:${e.length}:${r}`}function _(e){let t=new Set;a.lastIndex=0;let n=null;for(;(n=a.exec(e))!==null;)t.add(n[2]);return[...t]}function v(e){let t=new Set;o.lastIndex=0;let n=null;for(;(n=o.exec(e))!==null;)t.add(n[2]);return[...t]}function y(e){let t=e.split(`/`),n=t.slice(2).join(`/`);return{name:t.slice(0,2).join(`/`),subpath:n?`./${n}`:`.`}}function b(e,t,n){let a=i.join(e,`node_modules`,t,`package.json`);if(!E(a))return n.add(m(e,a)),null;let o=h(a);if(x(e,o))return null;try{return{manifestPath:o,manifest:JSON.parse(r.readFileSync(o,`utf8`))}}catch{return null}}function x(e,t){let n=i.relative(i.join(e,`node_modules`),t);return n!==``&&!n.startsWith(`..`)&&!i.isAbsolute(n)}function S(e,t){if(!e||typeof e!=`object`)return;let n=e.exports;if(!n||typeof n!=`object`)return;let r=n[t],i=typeof r==`string`?r:C(r);return typeof i==`string`&&i.startsWith(`.`)?i:void 0}function C(e){if(!(!e||typeof e!=`object`))return e.default}function w(e,t){let n=i.resolve(i.dirname(e),t),r=[];for(let e of T(n)){if(E(e))return{filePath:e,missedCandidates:r};r.push(e)}return{filePath:null,missedCandidates:r}}function*T(e){yield e;for(let t of s)yield`${e}${t}`;for(let t of s)yield i.join(e,`index${t}`)}function E(e){try{return r.statSync(e).isFile()}catch{return!1}}export{h as a,l as i,u as n,c as o,g as r,d as s,m as t};