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.02 kB
import{t as e}from"./runner-cache-metadata.js";import{isPathInsideDirectory as t}from"./runner-artifact-manifest.js";import n from"node:fs";import r from"node:path";async function i(e,t,n){if(!a(e,n))return[];let r=o(e,t);return r?await c(e,e,r):[]}function a(e,t){try{let i=r.join(n.realpathSync(r.dirname(t)),r.basename(t));return n.realpathSync(e)===i}catch{return!1}}function o(i,a){let o=new Set([e]);try{let e=n.realpathSync(i);for(let c of a){let a=n.realpathSync(c);if(!t(c,i)||!t(a,e))return null;o.add(s(r.relative(i,c))),o.add(s(r.relative(e,a)))}}catch{return null}return o}function s(e){let t=e.split(r.sep);return t.slice(0,t[0]===`Build`?2:1).join(r.sep)}async function c(e,t,i){let a=[];for(let o of await n.promises.readdir(t,{withFileTypes:!0})){let s=r.join(t,o.name),l=r.relative(e,s);if(!i.has(l)){if(o.isDirectory()&&[...i].some(e=>e.startsWith(`${l}${r.sep}`))){a.push(...await c(e,s,i));continue}await n.promises.rm(s,{recursive:!0,force:!0}),a.push(l)}}return a}export{i as trimRunnerBuildScratch};