@lmctl-ai/lmctl 0.2.432 → 0.2.433

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lmbee.js CHANGED
@@ -2176,7 +2176,7 @@ ${a}
2176
2176
  WHERE id = ? AND enabled = 1 AND revision = ? AND running_since_ts = ? AND running_systemd_unit = ?`).run("reconciled",s,t.id,t.revision,t.running_since_ts,t.running_systemd_unit),jw(e,t.id,"reconciled: command execution confirmed gone by systemd probe; no exit callback survived the restart");return}e.prepare("UPDATE cron_jobs SET last_fire_status = ?, updated_at = ? WHERE id = ? AND enabled = 1 AND revision = ? AND running_since_ts = ?").run("skipped_overlap",s,t.id,t.revision,t.running_since_ts);return}let p=t.last_checked_ts!==null?Date.parse(t.last_checked_ts):Date.parse(t.created_at);if(p>r){go(e,"UPDATE cron_jobs SET last_checked_ts = ?, last_fire_status = ?, last_fire_error = ?, updated_at = ?",[s,"error",`last_checked_ts (${t.last_checked_ts??t.created_at}) is after the current tick time -- checkpoint reset without firing`,s],t);return}let h=new Date(p),_=new Date(r);if(r-p>_ee){go(e,"UPDATE cron_jobs SET last_checked_ts = ?, last_fire_status = ?, updated_at = ?",[s,"skipped_stale",s],t);return}let g=t.timezone!==null?tD(h,t.timezone):h,w=t.timezone!==null?tD(_,t.timezone):_;if(!PO(m,g,w)){go(e,"UPDATE cron_jobs SET last_checked_ts = ?, updated_at = ?",[s,s],t);return}let y=ap(e,t.id);if(!(y===null||y.enabled===0||y.revision!==t.revision)){if(pee(t.action_kind)){Tee(e,t,s,l,u,d);return}if(t.action_kind==="enqueue")try{let T=JSON.parse(t.action_payload),v={from:T.from??"autopilot",dedupeKey:`cron:${t.id}:${h.toISOString()}`};e.transaction(()=>{let I=e.prepare("SELECT enabled, revision, last_checked_ts FROM cron_jobs WHERE id = ?").get(t.id);return I===void 0||I.enabled===0||I.revision!==t.revision||I.last_checked_ts!==t.last_checked_ts?!1:(o(e,n,T.to,T.prompt,v),e.prepare("UPDATE cron_jobs SET last_checked_ts = ?, last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?").run(s,s,"ok",s,t.id),!0)}).immediate()&&l.push(t.title)}catch(T){try{u?.(t.id,T)}catch{}try{go(e,"UPDATE cron_jobs SET last_fire_status = ?, last_fire_error = ?, updated_at = ?",["error",Fn(T),s],t)}catch{}}else{let T=s,v=`lmcron-job-${t.id}-${T.replace(/[:.]/g,"-")}.scope`;if(e.prepare(`UPDATE cron_jobs SET last_checked_ts = ?, last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, running_since_ts = ?, running_systemd_unit = ?, updated_at = ?
2177
2177
  WHERE id = ? AND enabled = 1 AND revision = ? AND (last_checked_ts IS ?) AND (running_since_ts IS ?)`).run(s,s,"ok",s,v,s,t.id,t.revision,t.last_checked_ts,t.running_since_ts).changes===0)return;let I=lD(e,t,t.action_kind,v,a),N={logDir:c,systemdUnitName:v,onExit:(x,R,k,O)=>{let D=x===0?"ok":"error",S=D==="ok"?null:R?Fn(R):`Command exited with code ${x} -- see ${c??ep()}/${t.id}/ for output`;if(R)try{u?.(t.id,R)}catch{}try{e.prepare("UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL, last_fire_status = ?, last_fire_error = ?, updated_at = ? WHERE id = ? AND running_since_ts = ?").run(D,S,new Date().toISOString(),t.id,T)}catch{}uD(e,I,x,R,k,O,v)}};try{i({id:t.id,action_payload:t.action_payload},N),l.push(t.title)}catch(x){try{u?.(t.id,x)}catch{}try{e.prepare("UPDATE cron_jobs SET last_fire_status = ?, last_fire_error = ?, running_since_ts = NULL, running_systemd_unit = NULL, updated_at = ? WHERE id = ? AND running_since_ts = ?").run("error",Fn(x),s,t.id,T)}catch{}dD(e,I,x)}}}}async function nD(e,t){for(;!e();)await new Promise(n=>setTimeout(n,t))}async function su(e,t,n,r={}){let s=r.enqueueImpl??De,o=r.spawnCommandImpl??Xl,i=r.isUnitStillRunningImpl??aD,a=r.executeRunImpl??Fw,c=r.logDir,l=r.pollMs??250,u=it(e,t);if(Pa(e,t)&&r.onDemand===void 0)return{kind:"skipped_overlap",job:u};if(u.enabled===0)throw new G("DISABLED",`Cron job ${t} is disabled -- enable it first (\`cron enable ${t}\`), or a manual trigger would silently exercise a job the operator turned off on purpose`,4);let d=ve();if(u.action_kind==="command"){if(u.running_since_ts!==null)return u.running_systemd_unit!==null&&i(u.running_systemd_unit)==="confirmed-gone"?(e.prepare(`UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL, last_fire_status = ?, last_fire_error = NULL, updated_at = ?
2178
2178
  WHERE id = ? AND revision = ? AND running_since_ts = ? AND running_systemd_unit = ?`).run("reconciled",d,u.id,u.revision,u.running_since_ts,u.running_systemd_unit),jw(e,u.id,"reconciled: command execution confirmed gone by systemd probe; no exit callback survived the restart"),await su(e,t,n,r)):{kind:"skipped_overlap",job:u};let p=d,h=`lmcron-job-${u.id}-${p.replace(/[:.]/g,"-")}-manual.scope`;if(e.prepare(`UPDATE cron_jobs SET last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, running_since_ts = ?, running_systemd_unit = ?, updated_at = ?
2179
- WHERE id = ? AND enabled = 1 AND revision = ? AND running_since_ts IS ?`).run(d,"ok",p,h,d,u.id,u.revision,u.running_since_ts).changes===0)return{kind:"skipped_overlap",job:it(e,t)};let g=lD(e,u,`${u.action_kind}:manual`,h,i),w={logDir:c,systemdUnitName:h,onExit:(E,y,T,v)=>{let A=E===0?"ok":"error",I=A==="ok"?null:y?Fn(y):`Command exited with code ${E} -- see ${c??ep()}/${u.id}/ for output`;try{e.prepare("UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL, last_fire_status = ?, last_fire_error = ?, updated_at = ? WHERE id = ? AND running_since_ts = ?").run(A,I,new Date().toISOString(),u.id,p)}catch{}uD(e,g,E,y,T,v,h)}};try{o({id:u.id,action_payload:u.action_payload},w)}catch(E){dD(e,g,E);try{e.prepare("UPDATE cron_jobs SET last_fire_status = ?, last_fire_error = ?, running_since_ts = NULL, running_systemd_unit = NULL, updated_at = ? WHERE id = ? AND running_since_ts = ?").run("error",Fn(E),d,u.id,p)}catch{}throw new G("SPAWN_FAILED",`manual trigger of job ${t} failed to spawn: ${Fn(E)}`,1)}return await nD(()=>it(e,t).running_since_ts!==p,l),{kind:"fired",job:it(e,t)}}if(u.action_kind==="enqueue"){let p=JSON.parse(u.action_payload);return s(e,n,p.to,p.prompt,{from:p.from??"autopilot"}),e.prepare("UPDATE cron_jobs SET last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?").run(d,"ok",d,u.id),{kind:"fired",job:it(e,t)}}let f=JSON.stringify({kind:u.action_kind,payload:u.action_payload,provider:u.provider,model:u.model,workingDirectory:u.working_directory,escalationOwner:u.escalation_owner}),m=e.transaction(()=>{let p=e.prepare("SELECT enabled, revision FROM cron_jobs WHERE id = ?").get(u.id);if(p===void 0||p.enabled===0||p.revision!==u.revision)return null;let h=zl(e,u.id,`${u.action_kind}:manual`,f);if(h.kind==="claimed"){r.onDemand!==void 0&&xO(e,u.id,h.run.id,r.onDemand);let _=r.disableOnClaim?"enabled = 0, ":"";e.prepare(`UPDATE cron_jobs SET ${_}last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?`).run(d,"ok",d,u.id)}return h}).immediate();if(m===null)throw new G("CONFLICT",`Cron job ${t} was modified concurrently -- re-run \`cron trigger ${t}\``,5);if(m.kind==="escalation")return{kind:"blocked_escalation",job:it(e,t)};if(m.kind==="overlap")return{kind:"skipped_overlap",job:it(e,t)};try{a({db:e,job:u,run:m.run,runToken:m.token,...r.onDemand!==void 0?{onDemand:r.onDemand}:{},...r.runSpawnPrefixes!==void 0?{spawnPrefixes:r.runSpawnPrefixes}:{},...r.sessionDir!==void 0?{sessionDir:r.sessionDir}:{},...r.runTimeoutMs!==void 0?{timeoutMs:r.runTimeoutMs}:{},...r.runSeedTimeoutMs!==void 0?{seedTimeoutMs:r.runSeedTimeoutMs}:{}})}catch(p){try{Ql(e,m.run.id,`worker dispatch threw: ${Fn(p)}`),kw(e,m.run.id,{ok:!1,summary:`worker dispatch error: ${Fn(p)}`})}catch{}throw new G("SPAWN_FAILED",`manual trigger of job ${t} failed to dispatch: ${Fn(p)}`,1)}if(r.waitForCompletion===!1){let p=u;try{p=it(e,t)}catch(h){console.warn(`[triggerCronJobNow] post-dispatch getCronJob read failed for job ${t}:`,h)}return{kind:"fired",job:p,runId:m.run.id}}return await nD(()=>{let p=xt(e,m.run.id);return p.status!=="pending"&&p.status!=="running"},l),{kind:"fired",job:it(e,t),runId:m.run.id}}function Tee(e,t,n,r,s,o){if(Pa(e,t.id))return;let i=JSON.stringify({kind:t.action_kind,payload:t.action_payload,provider:t.provider,model:t.model,workingDirectory:t.working_directory,escalationOwner:t.escalation_owner}),a=e.transaction(()=>{let c=e.prepare("SELECT enabled, revision, last_checked_ts FROM cron_jobs WHERE id = ?").get(t.id);if(c===void 0||c.enabled===0||c.revision!==t.revision||c.last_checked_ts!==t.last_checked_ts)return null;let l=zl(e,t.id,t.action_kind,i);return l.kind==="claimed"&&e.prepare("UPDATE cron_jobs SET last_checked_ts = ?, last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?").run(n,n,"ok",n,t.id),l}).immediate();if(a!==null){if(a.kind==="escalation"){go(e,"UPDATE cron_jobs SET last_fire_status = ?, updated_at = ?",["blocked_escalation",n],t);return}if(a.kind==="overlap"){go(e,"UPDATE cron_jobs SET last_fire_status = ?, updated_at = ?",["skipped_overlap",n],t);return}r.push(t.title);try{o.executeRunImpl({db:e,job:t,run:a.run,runToken:a.token,...o.runSpawnPrefixes!==void 0?{spawnPrefixes:o.runSpawnPrefixes}:{},...o.sessionDir!==void 0?{sessionDir:o.sessionDir}:{},...o.runTimeoutMs!==void 0?{timeoutMs:o.runTimeoutMs}:{},...o.runSeedTimeoutMs!==void 0?{seedTimeoutMs:o.runSeedTimeoutMs}:{}})}catch(c){try{Ql(e,a.run.id,`worker dispatch threw: ${Fn(c)}`),kw(e,a.run.id,{ok:!1,summary:`worker dispatch error: ${Fn(c)}`})}catch{}try{s?.(t.id,c)}catch{}}}}function go(e,t,n,r){e.prepare(`${t} WHERE id = ? AND enabled = 1 AND revision = ? AND (last_checked_ts IS ?)`).run(...n,r.id,r.revision,r.last_checked_ts)}function fD(e,t){let n=e.transaction(()=>{it(e,t);try{e.prepare("UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL WHERE id = ?").run(t)}catch(r){Ha(r)}return ip(e,t),it(e,t)});return ws(n)}import{execFileSync as vee}from"node:child_process";import{existsSync as See,readFileSync as mD}from"node:fs";import{homedir as pD}from"node:os";import{join as hD}from"node:path";function Wa(){return process.env.LMBEE_HEAVY_STATUS??hD(pD(),".lmbee","heavy.status")}function Ga(){return process.env.LMBEE_HEAVY_LOCK??hD(pD(),".lmbee","heavy.lock")}var Ba=class extends Error{};function bee(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.holder=="string"&&typeof t.pid=="number"&&typeof t.command=="string"&&typeof t.startedAt=="string"}function Aee(e){let t;try{t=mD(e,"utf8")}catch{return null}try{let n=JSON.parse(t);return bee(n)?n:null}catch{return null}}function Iee(e,t){return e===null||t===null?e===t:e.holder===t.holder&&e.pid===t.pid&&e.command===t.command&&e.startedAt===t.startedAt}function kee(e){try{let t=mD(`/proc/${e}/stat`,"utf8");return t.slice(t.lastIndexOf(")")+2).trim().split(/\s+/)[0]==="Z"}catch{return!1}}function Ree(e){try{process.kill(e,0)}catch(t){return t.code==="EPERM"}return!kee(e)}function Nee(e,t=vee){if(!See(e))return!1;try{return t("flock",["-n",e,"-c","true"],{stdio:"ignore"}),!1}catch(n){if((n&&typeof n=="object"?n.status:void 0)===1)return!0;let s=n instanceof Error?n.message:String(n);throw new Ba(`heavy-lock probe failed (flock did not run or exited abnormally): ${s}`)}}function Hw(e=Wa(),t=Ga(),n=Aee,r=Nee,s=Ree){for(let o=0;o<3;o++){let i=n(e),a=r(t),c=n(e);if(i!==null&&Iee(i,c)){if(!a)return{held:!1,holder:null};if(s(i.pid))return{held:!0,holder:i}}}return{held:r(t),holder:null}}function vn(e=Wa(),t=Ga(),n=Hw,r){try{return n(e,t)}catch(s){if(!(s instanceof Ba))throw s;return r?.(s),{held:!0,holder:null}}}var dp={observedAt:null,report:null,lastErrorAt:null,lastError:null};function _D(e,t){dp={observedAt:t,report:e,lastErrorAt:null,lastError:null}}function gD(e,t){dp={...dp,lastErrorAt:t,lastError:e}}function ou(){return dp}import{execFile as xee}from"node:child_process";import{promisify as Lee}from"node:util";function Ae(e){if(!Number.isFinite(e)||e<0)return"?";if(e<1e3)return"0s";if(e<6e4)return`${Math.floor(e/1e3)}s`;if(e<36e5)return`${Math.floor(e/6e4)}m`;if(e<864e5*2)return`${Math.floor(e/36e5)}h`;let t=Math.floor(e/864e5),n=Math.floor(e%864e5/36e5);return n===0?`${t}d`:`${t}d ${n}h`}function Le(e,t=Date.now()){let n=Date.parse(e);if(Number.isNaN(n))return"?";let r=t-n;return r<6e4?"just now":`${Ae(r)} ago`}var Cee=Lee(xee);function Oee(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e;return(typeof t.target=="string"||t.target===null)&&typeof t.from_identity=="string"}function Dee(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||!Array.isArray(t.running)||!Array.isArray(t.dead)||!Array.isArray(t.idle))throw new Error("unexpected `lmctl running --json` shape: missing running/dead/idle arrays");let n=t;for(let r of["running","dead","idle"])if(!n[r].every(Oee))throw new Error(`unexpected \`lmctl running --json\` shape: a malformed element (bad/missing target or from_identity) in \`${r}\``);return n}async function qe(e=3e4,t={}){let n=t.reconcile===!0?["running","--json","--reconcile"]:["running","--json"],{stdout:r}=await Cee("lmctl",n,{timeout:e});return Dee(r)}function qw(e,t=Date.now()){return{schema_version:e.schema_version,running:e.running.map(n=>({...n,running_for_human:Ae(n.running_for_ms),started_human:Le(n.started_at,t)})),dead:e.dead.map(n=>({...n,age_human:Ae(n.age_ms),started_human:Le(n.started_at,t)})),idle:e.idle.map(n=>({...n,ran_human:Ae(n.ran_ms)}))}}import{readFileSync as $ee}from"node:fs";import{randomUUID as Mee}from"node:crypto";var Bw={staleThresholdMs:2*60*6e4,escalationCooldownMs:60*6e4,digestTimeoutMs:9e4,leaseTimeoutMs:10*6e4,providerQuotaBackoffMs:24*60*6e4,operatorStaleThresholdMs:6e4,operatorEscalationCooldownMs:6e4};function Pee(e){return/usage limit/i.test(e)&&/quota/i.test(e)}function Uee(e){let t=[];for(let n of e)try{t.push({row:n,content:$ee(n.prompt_file,"utf8")})}catch{continue}return t}function Fee(e){let t=e.map(({row:n,content:r})=>`--- from "${n.from_id}", queued ${n.created_ts} ---
2179
+ WHERE id = ? AND enabled = 1 AND revision = ? AND running_since_ts IS ?`).run(d,"ok",p,h,d,u.id,u.revision,u.running_since_ts).changes===0)return{kind:"skipped_overlap",job:it(e,t)};let g=lD(e,u,`${u.action_kind}:manual`,h,i),w={logDir:c,systemdUnitName:h,onExit:(E,y,T,v)=>{let A=E===0?"ok":"error",I=A==="ok"?null:y?Fn(y):`Command exited with code ${E} -- see ${c??ep()}/${u.id}/ for output`;try{e.prepare("UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL, last_fire_status = ?, last_fire_error = ?, updated_at = ? WHERE id = ? AND running_since_ts = ?").run(A,I,new Date().toISOString(),u.id,p)}catch{}uD(e,g,E,y,T,v,h)}};try{o({id:u.id,action_payload:u.action_payload},w)}catch(E){dD(e,g,E);try{e.prepare("UPDATE cron_jobs SET last_fire_status = ?, last_fire_error = ?, running_since_ts = NULL, running_systemd_unit = NULL, updated_at = ? WHERE id = ? AND running_since_ts = ?").run("error",Fn(E),d,u.id,p)}catch{}throw new G("SPAWN_FAILED",`manual trigger of job ${t} failed to spawn: ${Fn(E)}`,1)}return await nD(()=>it(e,t).running_since_ts!==p,l),{kind:"fired",job:it(e,t)}}if(u.action_kind==="enqueue"){let p=JSON.parse(u.action_payload);return s(e,n,p.to,p.prompt,{from:p.from??"autopilot"}),e.prepare("UPDATE cron_jobs SET last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?").run(d,"ok",d,u.id),{kind:"fired",job:it(e,t)}}let f=JSON.stringify({kind:u.action_kind,payload:u.action_payload,provider:u.provider,model:u.model,workingDirectory:u.working_directory,escalationOwner:u.escalation_owner}),m=e.transaction(()=>{let p=e.prepare("SELECT enabled, revision FROM cron_jobs WHERE id = ?").get(u.id);if(p===void 0||p.enabled===0||p.revision!==u.revision)return null;let h=zl(e,u.id,`${u.action_kind}:manual`,f);if(h.kind==="claimed"){r.onDemand!==void 0&&xO(e,u.id,h.run.id,r.onDemand);let _=r.disableOnClaim?"enabled = 0, ":"";e.prepare(`UPDATE cron_jobs SET ${_}last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?`).run(d,"ok",d,u.id)}return h}).immediate();if(m===null)throw new G("CONFLICT",`Cron job ${t} was modified concurrently -- re-run \`cron trigger ${t}\``,5);if(m.kind==="escalation")return{kind:"blocked_escalation",job:it(e,t)};if(m.kind==="overlap")return{kind:"skipped_overlap",job:it(e,t)};try{a({db:e,job:u,run:m.run,runToken:m.token,...r.onDemand!==void 0?{onDemand:r.onDemand}:{},...r.runSpawnPrefixes!==void 0?{spawnPrefixes:r.runSpawnPrefixes}:{},...r.sessionDir!==void 0?{sessionDir:r.sessionDir}:{},...r.runTimeoutMs!==void 0?{timeoutMs:r.runTimeoutMs}:{},...r.runSeedTimeoutMs!==void 0?{seedTimeoutMs:r.runSeedTimeoutMs}:{}})}catch(p){try{Ql(e,m.run.id,`worker dispatch threw: ${Fn(p)}`),kw(e,m.run.id,{ok:!1,summary:`worker dispatch error: ${Fn(p)}`})}catch{}throw new G("SPAWN_FAILED",`manual trigger of job ${t} failed to dispatch: ${Fn(p)}`,1)}if(r.waitForCompletion===!1){let p=u;try{p=it(e,t)}catch(h){console.warn(`[triggerCronJobNow] post-dispatch getCronJob read failed for job ${t}:`,h)}return{kind:"fired",job:p,runId:m.run.id}}return await nD(()=>{let p=xt(e,m.run.id);return p.status!=="pending"&&p.status!=="running"},l),{kind:"fired",job:it(e,t),runId:m.run.id}}function Tee(e,t,n,r,s,o){if(Pa(e,t.id))return;let i=JSON.stringify({kind:t.action_kind,payload:t.action_payload,provider:t.provider,model:t.model,workingDirectory:t.working_directory,escalationOwner:t.escalation_owner}),a=e.transaction(()=>{let c=e.prepare("SELECT enabled, revision, last_checked_ts FROM cron_jobs WHERE id = ?").get(t.id);if(c===void 0||c.enabled===0||c.revision!==t.revision||c.last_checked_ts!==t.last_checked_ts)return null;let l=zl(e,t.id,t.action_kind,i);return l.kind==="claimed"&&e.prepare("UPDATE cron_jobs SET last_checked_ts = ?, last_fired_ts = ?, last_fire_status = ?, last_fire_error = NULL, updated_at = ? WHERE id = ?").run(n,n,"ok",n,t.id),l}).immediate();if(a!==null){if(a.kind==="escalation"){go(e,"UPDATE cron_jobs SET last_fire_status = ?, updated_at = ?",["blocked_escalation",n],t);return}if(a.kind==="overlap"){go(e,"UPDATE cron_jobs SET last_fire_status = ?, updated_at = ?",["skipped_overlap",n],t);return}r.push(t.title);try{o.executeRunImpl({db:e,job:t,run:a.run,runToken:a.token,...o.runSpawnPrefixes!==void 0?{spawnPrefixes:o.runSpawnPrefixes}:{},...o.sessionDir!==void 0?{sessionDir:o.sessionDir}:{},...o.runTimeoutMs!==void 0?{timeoutMs:o.runTimeoutMs}:{},...o.runSeedTimeoutMs!==void 0?{seedTimeoutMs:o.runSeedTimeoutMs}:{}})}catch(c){try{Ql(e,a.run.id,`worker dispatch threw: ${Fn(c)}`),kw(e,a.run.id,{ok:!1,summary:`worker dispatch error: ${Fn(c)}`})}catch{}try{s?.(t.id,c)}catch{}}}}function go(e,t,n,r){e.prepare(`${t} WHERE id = ? AND enabled = 1 AND revision = ? AND (last_checked_ts IS ?)`).run(...n,r.id,r.revision,r.last_checked_ts)}function fD(e,t){let n=e.transaction(()=>{it(e,t);try{e.prepare("UPDATE cron_jobs SET running_since_ts = NULL, running_systemd_unit = NULL WHERE id = ?").run(t)}catch(r){Ha(r)}return ip(e,t),it(e,t)});return ws(n)}import{execFileSync as vee}from"node:child_process";import{existsSync as See,readFileSync as mD}from"node:fs";import{homedir as pD}from"node:os";import{join as hD}from"node:path";function Wa(){return process.env.LMBEE_HEAVY_STATUS??hD(pD(),".lmbee","heavy.status")}function Ga(){return process.env.LMBEE_HEAVY_LOCK??hD(pD(),".lmbee","heavy.lock")}var Ba=class extends Error{};function bee(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.holder=="string"&&typeof t.pid=="number"&&typeof t.command=="string"&&typeof t.startedAt=="string"}function Aee(e){let t;try{t=mD(e,"utf8")}catch{return null}try{let n=JSON.parse(t);return bee(n)?n:null}catch{return null}}function Iee(e,t){return e===null||t===null?e===t:e.holder===t.holder&&e.pid===t.pid&&e.command===t.command&&e.startedAt===t.startedAt}function kee(e){try{let t=mD(`/proc/${e}/stat`,"utf8");return t.slice(t.lastIndexOf(")")+2).trim().split(/\s+/)[0]==="Z"}catch{return!1}}function Ree(e){try{process.kill(e,0)}catch(t){return t.code==="EPERM"}return!kee(e)}function Nee(e,t=vee){if(!See(e))return!1;try{return t("flock",["-n",e,"-c","true"],{stdio:"ignore"}),!1}catch(n){if((n&&typeof n=="object"?n.status:void 0)===1)return!0;let s=n instanceof Error?n.message:String(n);throw new Ba(`heavy-lock probe failed (flock did not run or exited abnormally): ${s}`)}}function Hw(e=Wa(),t=Ga(),n=Aee,r=Nee,s=Ree){for(let o=0;o<3;o++){let i=n(e),a=r(t),c=n(e);if(i!==null&&Iee(i,c)){if(!a)return{held:!1,holder:null};if(s(i.pid))return{held:!0,holder:i}}}return{held:r(t),holder:null}}function vn(e=Wa(),t=Ga(),n=Hw,r){try{return n(e,t)}catch(s){if(!(s instanceof Ba))throw s;return r?.(s),{held:!0,holder:null}}}var dp={observedAt:null,report:null,lastErrorAt:null,lastError:null};function _D(e,t){dp={observedAt:t,report:e,lastErrorAt:null,lastError:null}}function gD(e,t){dp={...dp,lastErrorAt:t,lastError:e}}function ou(){return dp}import{execFile as xee}from"node:child_process";import{promisify as Lee}from"node:util";function Ae(e){if(!Number.isFinite(e)||e<0)return"?";if(e<1e3)return"0s";if(e<6e4)return`${Math.floor(e/1e3)}s`;if(e<36e5)return`${Math.floor(e/6e4)}m`;if(e<864e5*2)return`${Math.floor(e/36e5)}h`;let t=Math.floor(e/864e5),n=Math.floor(e%864e5/36e5);return n===0?`${t}d`:`${t}d ${n}h`}function Le(e,t=Date.now()){let n=Date.parse(e);if(Number.isNaN(n))return"?";let r=t-n;return r<6e4?"just now":`${Ae(r)} ago`}var Cee=Lee(xee);function Oee(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e;return(typeof t.target=="string"||t.target===null)&&typeof t.from_identity=="string"}function Dee(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||!Array.isArray(t.running)||!Array.isArray(t.dead)||!Array.isArray(t.idle))throw new Error("unexpected `lmctl running --json` shape: missing running/dead/idle arrays");let n=t;for(let r of["running","dead","idle"])if(!n[r].every(Oee))throw new Error(`unexpected \`lmctl running --json\` shape: a malformed element (bad/missing target or from_identity) in \`${r}\``);return n}async function qe(e=3e4,t={}){let n=t.reconcile===!0?["running","--json-legacy","--reconcile"]:["running","--json-legacy"],{stdout:r}=await Cee("lmctl",n,{timeout:e});return Dee(r)}function qw(e,t=Date.now()){return{schema_version:e.schema_version,running:e.running.map(n=>({...n,running_for_human:Ae(n.running_for_ms),started_human:Le(n.started_at,t)})),dead:e.dead.map(n=>({...n,age_human:Ae(n.age_ms),started_human:Le(n.started_at,t)})),idle:e.idle.map(n=>({...n,ran_human:Ae(n.ran_ms)}))}}import{readFileSync as $ee}from"node:fs";import{randomUUID as Mee}from"node:crypto";var Bw={staleThresholdMs:2*60*6e4,escalationCooldownMs:60*6e4,digestTimeoutMs:9e4,leaseTimeoutMs:10*6e4,providerQuotaBackoffMs:24*60*6e4,operatorStaleThresholdMs:6e4,operatorEscalationCooldownMs:6e4};function Pee(e){return/usage limit/i.test(e)&&/quota/i.test(e)}function Uee(e){let t=[];for(let n of e)try{t.push({row:n,content:$ee(n.prompt_file,"utf8")})}catch{continue}return t}function Fee(e){let t=e.map(({row:n,content:r})=>`--- from "${n.from_id}", queued ${n.created_ts} ---
2180
2180
  ${r}`);return`You have ${e.length} queued message(s) that couldn't be delivered automatically (presence-gated for a while) -- bundled here as a digest:
2181
2181
 
2182
2182
  ${t.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmctl-ai/lmctl",
3
- "version": "0.2.432",
3
+ "version": "0.2.433",
4
4
  "description": "A provider-agnostic control plane for teams of AI coding agents — across providers, with independent review and durable memory.",
5
5
  "type": "module",
6
6
  "homepage": "https://lmctl.com",