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.3 kB
import{v as e}from"./sdk-contracts.js";import t from"node:fs";import n from"node:path";function r(e){return n.join(e,`repair-tombstone.json`)}function i(e,t){try{let n=o(e);return n?.owner===t&&n.expiresAt>Date.now()?n:void 0}catch{return}}function a(e,n){try{o(e)?.owner===n&&t.rmSync(e,{force:!0})}catch{}}function o(e){let n;try{n=t.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return;throw e}return s(n,e)}function s(t,n){try{let e=JSON.parse(t);if(!c(e))throw Error(`Invalid repair tombstone fields`);return e}catch(t){throw new e(`COMMAND_FAILED`,`Repair evidence could not be inspected.`,{reason:`repair_evidence_invalid`,path:n},t instanceof Error?t:void 0)}}function c(e){let t=e;return Number.isFinite(t?.reapedAt)&&Number.isFinite(t?.expiresAt)&&typeof t?.owner==`string`&&(t.sourcePath===void 0||typeof t.sourcePath==`string`)&&l(t.commitFailure)}function l(e){let t=e;return e===void 0||typeof t?.code==`string`&&typeof t?.message==`string`}function u(e){let i;try{i=t.readdirSync(e,{withFileTypes:!0})}catch(e){if(e.code===`ENOENT`)return;throw e}for(let t of i){if(!t.isDirectory())continue;let i=o(r(n.join(e,t.name)));if(i?.commitFailure&&i.expiresAt>Date.now())return{sessionName:t.name,tombstone:{...i,commitFailure:i.commitFailure}}}}export{r as i,u as n,i as r,a as t};