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.

1 lines • 1.89 kB
import{gt as e}from"./sdk-io.js";import"./file.js";import{a as t,r as n,s as r,t as i}from"./code-signature.js";import a from"node:crypto";import o from"node:fs";import s from"node:os";import c from"node:path";function l(e,a){let o=t(a),s=t(e),c=v(s,o),l=i(o,s),d=u(c,o,l);if(d)return n(d.files);let p;try{p=r(s,o)}catch{return`unknown`}return f(p.files,l)&&_(c,p),n(p.files)}function u(e,t,n){let r=p(e);if(!(!r||!f(r.files,n))){for(let[e,n,i]of r.files){let r=d(c.resolve(t,e));if(!r?.isFile()||r.size!==n||Math.trunc(r.mtimeMs)!==i)return}for(let e of r.absentPaths)if(d(c.resolve(t,e))?.isFile())return;return r}}function d(e){try{return o.statSync(e)}catch{return}}function f(e,t){return e.some(([e])=>e===t)}function p(e){let t=m(e);if(!t)return;let n=[];for(let e of t.files){let t=g(e);if(!t)return;n.push(t)}if(t.absent.every(e=>typeof e==`string`))return{files:n,absentPaths:t.absent}}function m(e){let t=h(e);if(t===void 0)return;let n;try{n=JSON.parse(t)}catch{return}if(!n||typeof n!=`object`)return;let r=n;if(r.version===2&&!(!Array.isArray(r.files)||!Array.isArray(r.absent)))return{files:r.files,absent:r.absent}}function h(e){let t;try{t=o.openSync(e,`r`)}catch{return}try{let e=process.getuid?.();return e!==void 0&&o.fstatSync(t).uid!==e?void 0:o.readFileSync(t,`utf8`)}catch{return}finally{o.closeSync(t)}}function g(e){if(!Array.isArray(e)||e.length!==3)return;let[t,n,r]=e;if(typeof t==`string`&&typeof n==`number`&&typeof r==`number`)return[t,n,r]}function _(t,n){let r={version:2,files:[...n.files],absent:[...n.absentPaths]};try{o.mkdirSync(c.dirname(t),{recursive:!0,mode:448}),e({destination:t,contents:JSON.stringify(r),mode:384})}catch{}}function v(e,t){let n=a.createHash(`sha1`).update(`${t} ${e}`).digest(`hex`),r=`agent-device-code-signature-${process.getuid?.()??`user`}`;return c.join(s.tmpdir(),r,`${n}.json`)}export{l as resolveCachedDaemonCodeSignature};