import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";import{i as n}from"./CX8DOZuw2.js";import{g as r,l as i,p as a,r as o,u as s}from"./DeO5NWhN.js";import{t as c}from"./2PQNgpBd.js";import{g as l}from"./B5XQZRTz.js";var u=e(t(),1),d=`2026.4.12`;function f(){let e=n(),t=(0,u.join)(e,`cleo.db`);if(!t.startsWith(e))throw Error(`BUG: getGlobalAgentRegistryDbPath() resolved to "${t}" which is NOT under getCleoHome() ("${e}"). The Agent Registry is global-only per ADR-037. This indicates a code path that bypasses path resolution — fix the caller, do not suppress this error.`);return t}function p(){return s(`drizzle-agent-registry`)}function m(e){let t=p();r(e,t,`_agent_registry_meta`,`agent-registry`,i(`drizzle-agent-registry`)),a(c({client:e,schema:l}),{migrationsFolder:t})}var h=null;function g(e){try{return e.prepare(`SELECT value FROM _agent_registry_meta WHERE key = 'schema_version'`).get()?.value??null}catch{return null}}function _(e){try{e.exec(`CREATE TABLE IF NOT EXISTS _agent_registry_meta (
         key TEXT PRIMARY KEY,
         value TEXT NOT NULL,
         updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
       );
       INSERT OR REPLACE INTO _agent_registry_meta (key, value, updated_at)
       VALUES ('schema_version', '${d}', strftime('%s', 'now'));`)}catch{}}async function v(){let e=f(),t=(0,u.existsSync)(e),n=(await o(`global`,e)).db.$client??null;if(!n)throw Error(`E6-L5: openDualScopeDb returned a handle without $client — cannot extract DatabaseSync for the Agent Registry ledger reconcile.`);let r=(()=>{try{return!!n.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='agent_registry_agents'`).get()}catch{return!1}})();return r&&g(n)===`2026.4.12`?(h=n,{action:`exists`,path:e}):(m(n),_(n),h=n,{action:t&&r?`exists`:`created`,path:e})}function y(){return h}export{p as a,y as i,v as n,f as r,d as t};