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 • 3.7 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{c as t,i as n,n as r}from"./daemon-resolution.js";async function i(e){let t=e.observed;if(!t)return s();let{stopAndRetireDaemon:n}=await import(`./daemon-registration-owner.js`).then(e=>e.r),r=await n({paths:e.paths,observed:t,mode:`graceful`,termTimeoutMs:e.graceTimeoutMs??1e4,killTimeoutMs:e.killTimeoutMs??2e3});if(r.status===`retained`&&r.termination?.status===`not-running`)return s();if(r.status!==`retired`)throw o(t,r);return r.termination.mode===`already-exited`?s():r.termination.mode===`graceful`?{stopped:!0,mode:`graceful`,cleanupConfidence:`known`,claimsReleased:[],claimsOrphaned:[],claimsSuperseded:[],claimsUnattributable:[],providerReleases:{status:`completed`,released:[],pending:[]},warnings:[]}:{stopped:!0,mode:`forced`,cleanupConfidence:`unknown`,claimsReleased:[],claimsOrphaned:[],claimsSuperseded:[],claimsUnattributable:[],providerReleases:{status:`unknown`,released:[],pending:null},warnings:[`The daemon was force-killed before provider lease state could be finalized. Provider allocations may remain active.`]}}function a(e,i){return e===`embedded-owner`?{reason:r.ownerEmbedded,hint:t(i)}:{reason:n,hint:`Nothing was signaled. Check what owns that process, then repair the record: stop it by its own means and remove its daemon.json so a daemon can register again.`}}function o(t,n){let r=n.status===`retained`?n.termination:void 0,i=r?.status===`retained`?r:void 0,{hint:o,diagnosticId:s,logPath:c}=(n.status===`retained`?n.error:void 0)??{},l=n.status===`retained`&&(n.reason===`embedded-owner`||n.reason===`owner-unproven`)?a(n.reason,t.pid):void 0;return new e(`COMMAND_FAILED`,l?`The daemon was not stopped, because its owner ends it.`:`Daemon retirement could not be confirmed.`,{pid:t.pid,processStartTime:t.startTime,reason:l?.reason??(i?`daemon_exit_unconfirmed`:`daemon_retirement_unconfirmed`),terminationReason:i?.reason,signal:i?.signal,retirement:n,hint:o??l?.hint,diagnosticId:s,logPath:c})}function s(){return{stopped:!1,mode:`not-running`,cleanupConfidence:`known`,claimsReleased:[],claimsOrphaned:[],claimsSuperseded:[],claimsUnattributable:[],providerReleases:{status:`completed`,released:[],pending:[]},warnings:[]}}function c(e,t){return e.mode!==`graceful`||t?t?{...e,providerReleases:{status:`completed`,...t.providerReleases},claimsReleased:t.claims.released,claimsOrphaned:t.claims.orphaned,claimsSuperseded:t.claims.superseded,claimsUnattributable:t.claims.unattributable,warnings:[...e.warnings,...l(t.claims.superseded),...u(t.claims.orphaned),...d(t.claims.unattributable)]}:e:{...e,cleanupConfidence:`unknown`,providerReleases:{status:`unknown`,released:[],pending:null},warnings:[...e.warnings,`The graceful shutdown report is unavailable, so provider cleanup state is unknown. Provider allocations may remain active.`]}}function l(e){return e.length===0?[]:[`Another owner had already claimed ${e.map(e=>e.deviceId).join(`, `)} before this daemon released it, so those devices are now owned elsewhere.`]}function u(e){return e.length===0?[]:[`Ownership of ${e.map(e=>e.deviceId).join(`, `)} was not released cleanly; the claim now blocks other owners until it is settled. Inspect with: agent-device device status --stale, then release with: agent-device device release --stale.`]}function d(e){return e.length===0?[]:[`A claim for ${e.map(e=>e.deviceId).join(`, `)} remains whose owner could not be read, so this daemon cannot say whether those devices are free. No device release route settles it: --stale proves staleness from the recorded owner and refuses records that name none, and open refuses to overwrite them. Inspect with: agent-device device status.`]}export{a as n,i as r,c as t};