@lmctl-ai/lmctl 0.2.203 → 0.2.204

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/build-info.json CHANGED
@@ -1 +1 @@
1
- {"sha": "92233dec6ebb739cefe19c2e8803ee55a57a0055", "dirty": false, "builtAt": "2026-10-10T17:08:10.000Z"}
1
+ {"sha": "5622cbd7e40b7be0bc77f44824cae5e7c4c799bc", "dirty": false, "builtAt": "2026-10-10T17:31:55.000Z"}
@@ -2400,7 +2400,7 @@ To experiment with it manually: https://lmctl.com/lmctl/docs/manual-invocation`}
2400
2400
  `).slice(-A2).join(`
2401
2401
  `)}function O2(t){return t.map(e=>`${e.code}${e.param?` '${e.param}'`:""}${e.suggestion?` (did you mean '${e.suggestion}'?)`:""}: ${e.message}`).join("; ")}function Hx(t,e={}){let n=Bh(t.text),r=t.alias??n.tool;if(!I2.test(r))throw Error(`namespace ${JSON.stringify(r)} is not an identifier`);let s=e.timeoutMs??$x,i=Ux(n,r);return{name:"schema:"+r,nativeNamespace:r,declarations:i,async activate(o){let a=Bh(t.text),l={};for(let c of a.operations){let u=r+"."+c.name,{positionals:d}=jx(a.tool,c);l[u]=async(...m)=>{let p=m[d.length+1]===!0,f=m[d.length]??{};if(!ba(f))throw Error(`${u}: options must be a map`);if(Object.hasOwn(f,"dryrun"))throw Error(`${u}: dryrun is supplied by the language; omit it`);let g=[],h=Object.create(null);for(let[C,N]of d.entries())m[C]!==void 0&&(h[N.name]=m[C]);for(let[C,N]of Object.entries(f)){if(Wh.includes(C)){if(typeof N!="boolean")throw Error(`${u}: option '${C}' must be boolean`);N&&g.push("--"+C);continue}if(Object.hasOwn(h,C))throw Error(`${u}: '${C}' given both positionally and as an option`);h[C]=N}if(p)return{status:"simulated",simulated:u};let y=$h(c,{...h},{form:"json"});if(!y.ok)return qr({code:"validation",message:`${u}: ${O2(y.issues)}`,issues:[...y.issues]});let E=o.platform??process.platform,_=Oy(a.tool,o.env.PATH,E,o.env.PATHEXT);if(!_)return qr({code:"launch",message:`${u}: ${a.tool} was not found on PATH (only absolute PATH entries are searched)`});let v=Ox(c,{...h}),w=[_,c.name,"--input-json",v,...g],A=()=>{};if(Buffer.byteLength(v)>Fx){let C=T2(Px(R2(),"lmscript-"+a.tool+"-")),N=Px(C,"input.json");A=()=>k2(C,{recursive:!0,force:!0});try{S2(N,v,{mode:384})}catch(b){throw A(),b}w=[_,c.name,"--input-file",N,...g]}let T;try{T=await Bi(w,s,E,o.signal,{cwd:o.cwd,env:o.env},e.maxOutputBytes===void 0?void 0:{maxOutputBytes:e.maxOutputBytes})}catch(C){let N=C;if(N?.code==="ERR_OUTPUT_LIMIT")return qr({code:"output_limit",message:`${u}: ${a.tool} ${N.message}`});if(N?.message==="Aborted")throw C;return qr({code:"launch",message:`${u}: cannot run ${a.tool}: ${N?.message??String(C)}`})}finally{A()}if(T.timed_out)return qr({code:"timeout",message:`${u}: ${a.tool} timed out after ${s} ms`,...T.stderr.trim()?{stderr_tail:Dx(T.stderr)}:{}});let I,x=!1;try{I=JSON.parse(T.stdout),x=!0}catch{}if(x&&ba(I)&&I.success===!1&&ba(I.error)){let C=I.error,N=ba(C.data)?C.data:{},b=ba(N.details)?N.details:N,S=Array.isArray(b.issues)?[...b.issues]:[],k=C.code==="VALIDATION_ERROR"?` (the input passed client validation; schema ${a.version??"unversioned"} may be stale)`:"";return qr({code:"envelope",message:`${u}: ${String(C.code??"ERROR")}: ${String(C.message??"")}${k}`,tool_code:String(C.code??"ERROR"),...S.length?{issues:S}:{},exit:T.code})}return T.code!==0||T.signal!==null?qr({code:"exit",message:`${u}: ${a.tool} exit ${T.code??"none"}${T.signal?` (signal ${T.signal})`:""}`,exit:T.code,signal:T.signal,...T.stderr.trim()?{stderr_tail:Dx(T.stderr)}:{}}):x?{status:"ok",result:I}:qr({code:"parse",message:`${u}: ${a.tool} ${c.name} printed invalid JSON${T.stdout.trim()?": "+T.stdout.trim().slice(0,200):" (empty stdout)"}`})}}return{functions:l,globals:{},dispose(){}}}}}function L2(t={}){return e=>Hx(e,t)}var Wh,I2,A2,Fx,$x,Xr,x2,C2,ba,qr,Wx=L(()=>{"use strict";Mx();Gi();Wh=["readonly","confirm"],I2=/^[A-Za-z_]\w*$/,A2=12,Fx=100*1024,$x=6e4;Xr=t=>t.occurs===void 0||t.occurs==="1"||t.occurs==="+",x2=t=>t.type==="array"||t.occurs==="+"||t.occurs==="*";C2={read:"Read operations",write:"Write operations",dynamic:"Dynamic operations"};ba=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);qr=t=>({status:"error",error:t})});function Pe(t){return{ok:!0,value:t}}function le(t,e,n={}){return{ok:!1,error:{code:t,message:e,...n},code:t,message:e,...n.file?{file:n.file}:{},...n.issues?{issues:n.issues}:{},...n.details?{details:n.details}:{}}}var qu=L(()=>{});function wa(t){if(typeof t!="string"||t.trim()==="")return le("SPEC_SYNTAX","Module spec must be a non-empty string");let e=t.indexOf("#");if(e!==-1){let a=t.slice(0,e),l=t.slice(e+1),c=qx.exec(a);if(!c)return le("SPEC_SYNTAX",`Invalid module spec syntax: "${t}" (expected @owner/repo[#(latest|dev)])`);let u=c[1],d=c[2];if(u==="."||u===".."||d==="."||d==="..")return le("SPEC_SYNTAX",`Invalid owner or repo name: "${t}"`);if(l!=="latest"&&l!=="dev")return le("SPEC_CHANNEL","only the latest and dev channels are supported");let m=l,p=`@${u}/${d}#${m}`;return Pe({owner:u,repo:d,channel:m,key:p,requested:t})}let n=qx.exec(t);if(!n)return le("SPEC_SYNTAX",`Invalid module spec syntax: "${t}" (expected @owner/repo[#(latest|dev)])`);let r=n[1],s=n[2];if(r==="."||r===".."||s==="."||s==="..")return le("SPEC_SYNTAX",`Invalid owner or repo name: "${t}"`);let i="latest",o=`@${r}/${s}#${i}`;return Pe({owner:r,repo:s,channel:i,key:o,requested:t})}var qx,qh=L(()=>{qu();qx=/^@([A-Za-z0-9][A-Za-z0-9._-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/});import{homedir as M2}from"node:os";import{isAbsolute as Xx,join as Gx,relative as Jx,resolve as Xh}from"node:path";function Ci(t=process.env){let e=t.LMCTL_HOME&&t.LMCTL_HOME.trim()!==""?t.LMCTL_HOME:Gx(t.HOME??M2(),".lmctl");return Gx(e,"modules")}function Gh(t,e){let n=Xh(t),r=Xh(n,"github.com"),s=Xh(r,e.owner,e.repo,e.channel),i=Jx(n,s),o=Jx(r,s);if(i.startsWith("..")||Xx(i)||o.startsWith("..")||Xx(o))throw new Error(`Path traversal detected: entry directory "${s}" escapes cache root "${n}"`);return s}function Xu(t){return`cli.schema.${t}.json`}var Jh=L(()=>{});import{createHash as Kx,randomUUID as Vh}from"node:crypto";import{existsSync as Vx,promises as Vt}from"node:fs";import{dirname as ise,isAbsolute as ose,join as rr,relative as ase,resolve as lse}from"node:path";function Yh(t){return typeof t=="string"?wa(t):Pe(t)}async function Gu(t,e){let n=Yh(t);if(!n.ok)return le(n.code,n.message);let r=n.value,s=e?.root??Ci(),i;try{i=Gh(s,r)}catch(f){return le("PATH_TRAVERSAL",f?.message??String(f))}let o=Xu(r.channel),a=rr(i,o),l=rr(i,"meta.json");if(!Vx(a)||!Vx(l))return le("NOT_INSTALLED",`Module ${r.key} is not installed`);let c,u;try{c=await Vt.readFile(a)}catch(f){return le("CACHE_CORRUPT",`Failed to read ${a}: ${f?.message??String(f)}; run: lmbee module install ${r.key} --force`,{file:a})}try{let f=await Vt.readFile(l,"utf-8");u=JSON.parse(f)}catch(f){return le("CACHE_CORRUPT",`Failed to read or parse ${l}: ${f?.message??String(f)}; run: lmbee module install ${r.key} --force`,{file:l})}let d=Kx("sha256").update(c).digest("hex");if(d!==u.sha256)return le("CACHE_CORRUPT",`Cached schema hash mismatch in ${a}: expected ${u.sha256}, got ${d}; run: lmbee module install ${r.key} --force`,{file:a});let m;try{m=JSON.parse(c.toString("utf-8"))}catch(f){return le("BAD_JSON",`Failed to parse ${a} as JSON: ${f?.message??String(f)}`,{file:a})}let p=Ea(m);return p.ok?Pe({spec:r,dir:i,path:a,sha256:d,fetchedAt:u.fetched_at,lastChecked:u.last_checked??u.fetched_at,etag:u.etag,channel:r.channel,tool:p.value.tool,version:p.value.version,document:p.value}):le("INVALID_SCHEMA",`Cached schema in ${a} is invalid: ${p.issues[0]?.message}`,{file:a,issues:p.issues})}async function Yx(t,e){let{timeoutMs:n,fetchImpl:r,etag:s}=e,i;try{let o=AbortSignal.timeout(n),a={};if(s&&(a["If-None-Match"]=s),i=await r(t,{signal:o,headers:a,redirect:"manual"}),i.status>=300&&i.status<400&&i.status!==304){let l=i.headers.get("location");if(!l)return le("FETCH_FAILED",`Redirect response from ${t} missing Location header`);let c=new URL(l,t);if(c.protocol!=="https:"||c.hostname!=="raw.githubusercontent.com")return le("FETCH_FAILED",`Cross-host or non-HTTPS redirect to "${l}" refused (must stay on raw.githubusercontent.com)`);i=await r(c.href,{signal:o,headers:a,redirect:"manual"})}}catch(o){return o?.name==="TimeoutError"||o?.name==="AbortError"?le("FETCH_FAILED",`Fetch timed out after ${n}ms for ${t}`):le("FETCH_FAILED",`Network error fetching ${t}: ${o?.message??String(o)}`)}return Pe(i)}async function Qx(t,e,n,r,s,i){let o;try{if(t.body&&typeof t.body.getReader=="function"){let u=t.body.getReader(),d=[],m=0;for(;;){let{done:p,value:f}=await u.read();if(p)break;if(m+=f.length,m>e)return await u.cancel(),le("OUTPUT_LIMIT",`Schema exceeds maximum size limit of ${e} bytes`);d.push(f)}o=Buffer.concat(d)}else{let u=await t.arrayBuffer();if(u.byteLength>e)return le("OUTPUT_LIMIT",`Schema exceeds maximum size limit of ${e} bytes`);o=Buffer.from(u)}}catch(u){return u?.name==="TimeoutError"||u?.name==="AbortError"?le("FETCH_FAILED",`Fetch stream timed out after ${n}ms`):le("FETCH_FAILED",`Error reading response stream: ${u?.message??String(u)}`)}let a;try{a=JSON.parse(o.toString("utf-8"))}catch(u){return le("BAD_JSON",`Failed to parse ${s} from ${i} as JSON: ${u?.message??String(u)}`)}let l=Ea(a);if(!l.ok){let u=l.issues[0]?.message??"Schema validation failed";return le("INVALID_SCHEMA",`Invalid schema for ${r}: ${u}`,{issues:l.issues})}let c=Kx("sha256").update(o).digest("hex");return Pe({buffer:o,sha256:c,schema:l.value})}async function Zx(t,e,n,r){await Vt.mkdir(t,{recursive:!0,mode:448});let s=rr(t,`.tmp.schema.${Date.now()}.${Vh()}`),i=rr(t,`.tmp.meta.${Date.now()}.${Vh()}`),o=rr(t,e),a=rr(t,"meta.json");try{await Vt.writeFile(s,n,{mode:384}),await Vt.rename(s,o),await Kh(o,384),await Vt.writeFile(i,JSON.stringify(r,null,2)+`
2402
2402
  `,{mode:384}),await Vt.rename(i,a),await Kh(a,384)}catch(l){return await zh(s),await zh(i),le("ATOMIC_WRITE_FAILED",`Failed to write cached module files: ${l?.message??String(l)}`)}return Pe(void 0)}async function D2(t,e){let n=rr(t,`.tmp.meta.${Date.now()}.${Vh()}`),r=rr(t,"meta.json");try{await Vt.writeFile(n,JSON.stringify(e,null,2)+`
2403
- `,{mode:384}),await Vt.rename(n,r),await Kh(r,384)}catch(s){return await zh(n),le("ATOMIC_WRITE_FAILED",`Failed to write meta.json: ${s?.message??String(s)}`)}return Pe(void 0)}async function eC(t,e){let n=Yh(t);if(!n.ok)return le(n.code,n.message);let r=n.value,s=e?.root??Ci(),i=e?.ttlMs??6*60*60*1e3,o=e?.now??(()=>new Date),a=e?.fetchImpl??globalThis.fetch,l=e?.install??!0,c=e?.update??!0,u=e?.timeoutMs??3e3,d=e?.maxBytes??1048576,m=await Gu(r,{root:s});if(!m.ok){if(m.code==="CACHE_CORRUPT")return m;if(m.code==="NOT_INSTALLED"){if(!l)return le("NOT_INSTALLED",`Module ${r.key} is not installed; run: lmbee module install ${r.key}`);let D=await F2(r,{root:s,fetchImpl:a,now:o,timeoutMs:u,maxBytes:d});return D.ok?Pe({module:D.value.entry,source:"installed"}):le(D.code,D.message,{file:D.file,issues:D.issues,details:D.details})}return m}let p=m.value,f=o().getTime(),g=p.lastChecked?new Date(p.lastChecked).getTime():NaN,h=!isNaN(g)&&g>f,y=isNaN(g),E=f-g;if(!y&&!h&&E>=0&&E<i||!c)return Pe({module:p,source:"cache"});let v=Xu(r.channel),w=`${zx}/${r.owner}/${r.repo}/HEAD/${v}`,A=await Yx(w,{timeoutMs:u,fetchImpl:a,etag:p.etag});if(!A.ok)return Pe({module:p,source:"stale-cache",warning:A.message});let T=A.value;if(T.status===304){let D=o().toISOString(),U=T.headers.get("etag")??T.headers.get("ETag")??p.etag,F=0;try{F=(await Vt.stat(p.path)).size}catch{F=0}let ee={spec:r.key,url:w,sha256:p.sha256,fetched_at:p.fetchedAt,last_checked:D,etag:U,channel:r.channel,tool:p.tool,version:p.version,bytes:F},q=await D2(p.dir,ee);if(!q.ok)return Pe({module:p,source:"stale-cache",warning:q.message});let z={...p,lastChecked:D,etag:U};return Pe({module:z,source:"network"})}if(T.status!==200)return Pe({module:p,source:"stale-cache",warning:`Failed to refresh ${r.key}: HTTP ${T.status} ${T.statusText}`});let I=await Qx(T,d,u,r.key,v,w);if(!I.ok)return Pe({module:p,source:"stale-cache",warning:I.message});let{buffer:x,sha256:C,schema:N}=I.value,b=T.headers.get("etag")??T.headers.get("ETag")??void 0,S=o().toISOString(),k=S,R={spec:r.key,url:w,sha256:C,fetched_at:S,last_checked:k,etag:b,channel:r.channel,tool:N.tool,version:N.version??"unknown",bytes:x.length},O=await Zx(p.dir,v,x,R);if(!O.ok)return Pe({module:p,source:"stale-cache",warning:O.message});let M={spec:r,dir:p.dir,path:p.path,sha256:C,fetchedAt:S,lastChecked:k,etag:b,channel:r.channel,tool:N.tool,version:N.version,document:N};return Pe({module:M,source:"network"})}async function F2(t,e){let n=Yh(t);if(!n.ok)return le(n.code,n.message);let r=n.value,s=e?.root??Ci(),i=e?.fetchImpl??globalThis.fetch,o=e?.now??(()=>new Date),a=e?.timeoutMs??1e4,l=e?.maxBytes??P2,c=e?.force??!1,u;try{u=Gh(s,r)}catch(C){return le("PATH_TRAVERSAL",C?.message??String(C))}let d=Xu(r.channel),m=`${zx}/${r.owner}/${r.repo}/HEAD/${d}`,p=await Gu(r,{root:s});if(!c&&p.ok)return Pe({action:"unchanged",entry:p.value});let f=await Yx(m,{timeoutMs:a,fetchImpl:i});if(!f.ok)return f;let g=f.value;if(g.status===404)return le("FETCH_FAILED",`Module ${r.key} not found: expected ${d} at the root of the default branch for ${r.owner}/${r.repo}`,{details:{status:404,url:m,file:d}});if(!g.ok)return le("FETCH_FAILED",`Failed to fetch ${m}: HTTP ${g.status} ${g.statusText}`,{details:{status:g.status,url:m}});let h=await Qx(g,l,a,r.key,d,m);if(!h.ok)return h;let{buffer:y,sha256:E,schema:_}=h.value;if(!c&&p.ok&&p.value.sha256===E)return Pe({action:"unchanged",entry:p.value});let v=g.headers.get("etag")??g.headers.get("ETag")??void 0,w=o().toISOString(),A=w,T={spec:r.key,url:m,sha256:E,fetched_at:w,last_checked:A,etag:v,channel:r.channel,tool:_.tool,version:_.version??"unknown",bytes:y.length},I=await Zx(u,d,y,T);if(!I.ok)return I;let x={spec:r,dir:u,path:rr(u,d),sha256:E,fetchedAt:w,lastChecked:A,etag:v,channel:r.channel,tool:_.tool,version:_.version,document:_};return Pe({action:p.ok?"replaced":"installed",entry:x})}async function Kh(t,e){try{await Vt.chmod(t,e)}catch{}}async function zh(t){try{await Vt.unlink(t)}catch{}}var zx,P2,tC=L(()=>{Hh();Jh();qh();qu();zx="https://raw.githubusercontent.com",P2=2*1024*1024});var nC=L(()=>{qu();qh();Jh();tC()});var oC={};Cn(oC,{createModuleResolver:()=>U2,isModuleSpecifier:()=>j2,normalizeModuleSpec:()=>sC,parseModuleOverrides:()=>iC});import{readFileSync as Qh}from"node:fs";import{resolve as $2}from"node:path";function j2(t){return t.startsWith("@")}function sC(t){let e=wa(t);if(!e.ok)throw Error(`${t}: ${e.message}`);return e.value.key}function iC(t,e){let n=new Map;for(let r of t){let s=r.indexOf("=");if(s<1||s===r.length-1)throw Error(`--module expects @owner/repo=<file> (a schema module override), got ${JSON.stringify(r)}; the retired --module NAME host-module loader no longer exists`);n.set(sC(r.slice(0,s)),$2(e,r.slice(s+1)))}return n}function rC(t,e,n){return{key:t.spec.key,channel:t.channel,origin:e,file:t.path,...t.version!==void 0?{version:t.version}:{},sha256:t.sha256,fetchedAt:t.fetchedAt,lastChecked:t.lastChecked,...n?{warning:n}:{}}}function U2(t){let e=iC(t.overrides??[],t.cwd??process.cwd()),n=t.root??Ci({...t.env}),r=new Map;return{resolve:async i=>{let o=wa(i);if(!o.ok)throw Error(`${i}: ${o.message}`);let a=o.value.key,l=e.get(a);if(l!==void 0){let u;try{u=Qh(l,"utf8")}catch(d){throw Error(`--module ${a}=${l}: ${d instanceof Error?d.message:String(d)}`)}return r.set(a,{key:a,channel:o.value.channel,origin:"override",file:l}),{key:a,source:u}}if(t.mode==="cache"){let u=await Gu(o.value,{root:n});if(!u.ok)throw u.code==="NOT_INSTALLED"?Error(`module ${a} is not installed; run the script once to install it`):Error(`module ${a}: ${u.message}`);return r.set(a,rC(u.value,"cache")),{key:a,source:Qh(u.value.path,"utf8")}}let c=await eC(o.value,{root:n,install:!0,update:!0,...t.fetchImpl?{fetchImpl:t.fetchImpl}:{},...t.now?{now:t.now}:{}});if(!c.ok)throw Error(`module ${a}: ${c.message}`);return r.set(a,rC(c.value.module,c.value.source,c.value.warning)),{key:a,source:Qh(c.value.module.path,"utf8")}},provenance:r}}var aC=L(()=>{"use strict";nC()});var Jy={};Cn(Jy,{runCli:()=>ey,stableDiagnostic:()=>Ta});import{readFileSync as lC,fstatSync as cC,writeSync as H2}from"node:fs";import{Socket as B2}from"node:net";import{resolve as Ju,dirname as W2}from"node:path";function Ta(t,e="<inline>"){return`${t.severity}:${t.file&&t.file!=="<main>"?t.file:e}:${t.line}:${t.column}: ${t.message}
2403
+ `,{mode:384}),await Vt.rename(n,r),await Kh(r,384)}catch(s){return await zh(n),le("ATOMIC_WRITE_FAILED",`Failed to write meta.json: ${s?.message??String(s)}`)}return Pe(void 0)}async function eC(t,e){let n=Yh(t);if(!n.ok)return le(n.code,n.message);let r=n.value,s=e?.root??Ci(),i=e?.ttlMs??6*60*60*1e3,o=e?.now??(()=>new Date),a=e?.fetchImpl??globalThis.fetch,l=e?.install??!0,c=e?.update??!0,u=e?.timeoutMs??3e3,d=e?.maxBytes??1048576,m=await Gu(r,{root:s});if(!m.ok){if(m.code==="CACHE_CORRUPT")return m;if(m.code==="NOT_INSTALLED"){if(!l)return le("NOT_INSTALLED",`Module ${r.key} is not installed; run: lmbee module install ${r.key}`);let D=await F2(r,{root:s,fetchImpl:a,now:o,timeoutMs:u,maxBytes:d});return D.ok?Pe({module:D.value.entry,source:"installed"}):le(D.code,D.message,{file:D.file,issues:D.issues,details:D.details})}return m}let p=m.value,f=o().getTime(),g=p.lastChecked?new Date(p.lastChecked).getTime():NaN,h=!isNaN(g)&&g>f,y=isNaN(g),E=f-g;if(!y&&!h&&E>=0&&E<i||!c)return Pe({module:p,source:"cache"});let v=Xu(r.channel),w=`${zx}/${r.owner}/${r.repo}/HEAD/${v}`,A=await Yx(w,{timeoutMs:u,fetchImpl:a,etag:p.etag});if(!A.ok)return Pe({module:p,source:"stale-cache",warning:A.message});let T=A.value;if(T.status===304){let D=o().toISOString(),U=T.headers.get("etag")??T.headers.get("ETag")??p.etag,F=0;try{F=(await Vt.stat(p.path)).size}catch{F=0}let ee={spec:r.key,url:w,sha256:p.sha256,fetched_at:p.fetchedAt,last_checked:D,etag:U,channel:r.channel,tool:p.tool,version:p.version,bytes:F},q=await D2(p.dir,ee);if(!q.ok)return Pe({module:p,source:"stale-cache",warning:q.message});let z={...p,lastChecked:D,etag:U};return Pe({module:z,source:"network"})}if(T.status!==200)return Pe({module:p,source:"stale-cache",warning:`Failed to refresh ${r.key}: HTTP ${T.status} ${T.statusText}`});let I=await Qx(T,d,u,r.key,v,w);if(!I.ok)return Pe({module:p,source:"stale-cache",warning:I.message});let{buffer:x,sha256:C,schema:N}=I.value,b=T.headers.get("etag")??T.headers.get("ETag")??void 0,S=o().toISOString(),k=S,R={spec:r.key,url:w,sha256:C,fetched_at:S,last_checked:k,etag:b,channel:r.channel,tool:N.tool,version:N.version??"unknown",bytes:x.length},O=await Zx(p.dir,v,x,R);if(!O.ok)return Pe({module:p,source:"stale-cache",warning:O.message});let M={spec:r,dir:p.dir,path:p.path,sha256:C,fetchedAt:S,lastChecked:k,etag:b,channel:r.channel,tool:N.tool,version:N.version,document:N};return Pe({module:M,source:"network"})}async function F2(t,e){let n=Yh(t);if(!n.ok)return le(n.code,n.message);let r=n.value,s=e?.root??Ci(),i=e?.fetchImpl??globalThis.fetch,o=e?.now??(()=>new Date),a=e?.timeoutMs??1e4,l=e?.maxBytes??P2,c=e?.force??!1,u;try{u=Gh(s,r)}catch(C){return le("PATH_TRAVERSAL",C?.message??String(C))}let d=Xu(r.channel),m=`${zx}/${r.owner}/${r.repo}/HEAD/${d}`,p=await Gu(r,{root:s});if(!c&&p.ok)return Pe({action:"unchanged",entry:p.value});let f=await Yx(m,{timeoutMs:a,fetchImpl:i});if(!f.ok)return f;let g=f.value;if(g.status===404)return le("FETCH_FAILED",`Module ${r.key} not found: expected ${d} at the root of the default branch for ${r.owner}/${r.repo}`,{details:{status:404,url:m,file:d}});if(!g.ok)return le("FETCH_FAILED",`Failed to fetch ${m}: HTTP ${g.status} ${g.statusText}`,{details:{status:g.status,url:m}});let h=await Qx(g,l,a,r.key,d,m);if(!h.ok)return h;let{buffer:y,sha256:E,schema:_}=h.value;if(!c&&p.ok&&p.value.sha256===E)return Pe({action:"unchanged",entry:p.value});let v=g.headers.get("etag")??g.headers.get("ETag")??void 0,w=o().toISOString(),A=w,T={spec:r.key,url:m,sha256:E,fetched_at:w,last_checked:A,etag:v,channel:r.channel,tool:_.tool,version:_.version??"unknown",bytes:y.length},I=await Zx(u,d,y,T);if(!I.ok)return I;let x={spec:r,dir:u,path:rr(u,d),sha256:E,fetchedAt:w,lastChecked:A,etag:v,channel:r.channel,tool:_.tool,version:_.version,document:_};return Pe({action:p.ok?"replaced":"installed",entry:x})}async function Kh(t,e){try{await Vt.chmod(t,e)}catch{}}async function zh(t){try{await Vt.unlink(t)}catch{}}var zx,P2,tC=L(()=>{Hh();Jh();qh();qu();zx="https://raw.githubusercontent.com",P2=2*1024*1024});var nC=L(()=>{qu();qh();Jh();tC()});var oC={};Cn(oC,{createModuleResolver:()=>U2,isModuleSpecifier:()=>j2,normalizeModuleSpec:()=>sC,parseModuleOverrides:()=>iC});import{readFileSync as Qh}from"node:fs";import{resolve as $2}from"node:path";function j2(t){return t.startsWith("@")}function sC(t){let e=wa(t);if(!e.ok)throw Error(`${t}: ${e.message}`);return e.value.key}function iC(t,e){let n=new Map;for(let r of t){let s=r.indexOf("=");if(s<1||s===r.length-1)throw Error(`--module expects @owner/repo=<file> (a schema module override), got ${JSON.stringify(r)}; the retired --module NAME host-module loader no longer exists`);n.set(sC(r.slice(0,s)),$2(e,r.slice(s+1)))}return n}function rC(t,e,n){return{key:t.spec.key,channel:t.channel,origin:e,file:t.path,...t.version!==void 0?{version:t.version}:{},sha256:t.sha256,fetchedAt:t.fetchedAt,lastChecked:t.lastChecked,...n?{warning:n}:{}}}function U2(t){let e=iC(t.overrides??[],t.cwd??process.cwd()),n=t.root??Ci({...t.env}),r=new Map;return{resolve:async i=>{let o=wa(i);if(!o.ok)throw Error(`${i}: ${o.message}`);let a=o.value.key,l=e.get(a);if(l!==void 0){let u;try{u=Qh(l,"utf8")}catch(d){throw Error(`--module ${a}=${l}: ${d instanceof Error?d.message:String(d)}`)}return r.set(a,{key:a,channel:o.value.channel,origin:"override",file:l}),{key:a,source:u}}if(t.mode==="cache"){let u=await Gu(o.value,{root:n});if(!u.ok)throw u.code==="NOT_INSTALLED"?Error(`module ${a} is not installed; run the script once to install it, or: lmbee module install @${o.value.owner}/${o.value.repo}${o.value.channel==="latest"?"":"#"+o.value.channel}`):Error(`module ${a}: ${u.message}`);return r.set(a,rC(u.value,"cache")),{key:a,source:Qh(u.value.path,"utf8")}}let c=await eC(o.value,{root:n,install:!0,update:!0,...t.fetchImpl?{fetchImpl:t.fetchImpl}:{},...t.now?{now:t.now}:{}});if(!c.ok)throw Error(`module ${a}: ${c.message}`);return r.set(a,rC(c.value.module,c.value.source,c.value.warning)),{key:a,source:Qh(c.value.module.path,"utf8")}},provenance:r}}var aC=L(()=>{"use strict";nC()});var Jy={};Cn(Jy,{runCli:()=>ey,stableDiagnostic:()=>Ta});import{readFileSync as lC,fstatSync as cC,writeSync as H2}from"node:fs";import{Socket as B2}from"node:net";import{resolve as Ju,dirname as W2}from"node:path";function Ta(t,e="<inline>"){return`${t.severity}:${t.file&&t.file!=="<main>"?t.file:e}:${t.line}:${t.column}: ${t.message}
2404
2404
  `}function q2(t){let e=Buffer.from(t),n=0,r;for(;n<e.length;)try{let s=H2(2,e,n,e.length-n);if(s===0)return;n+=s}catch(s){let i=s.code;if(i==="EPIPE"||i==="EBADF")return;if(i==="EINTR")continue;if(i==="EAGAIN"||i==="EWOULDBLOCK"){r??=new Int32Array(new SharedArrayBuffer(4)),Atomics.wait(r,0,0,1);continue}throw s}}async function ey(t,e={}){if(t.length===1&&["--version","-v"].includes(t[0]))return(e.stdout??($=>process.stdout.write($)))("lmscript "+Gy()+`
2405
2405
  `),0;let n=[...t],r=e.cwd??process.cwd(),s={...e.env??process.env},i=e.stdout??($=>process.stdout.write($)),o=e.stderr??q2,a=new Set,l=[],c=$=>{$.startsWith("error: ")&&l.push($);let K=$.match(/^error:.*:[0-9]+:[0-9]+: ([^\n]+)/);K&&a.add(K[1]),o($)},u,d=!1,m=!1,p,f,g=!1,h=!1,y,E,_="text",v=new Set,w=new Set(["--base-dir","--source-name","--resumepoint","--dry-loop-limit","--dryrun-timeout","--plan-format","--module"]),A=[],T=new Set(["--check","--dry-run","--lint","--check-files","--no-preflight",...w]);for(;n.length&&T.has(n[0]);){let $=n.shift();if(v.has($)&&$!=="--module")return c("error: "+$+` may be specified only once
2406
2406
  `),$==="--resumepoint"?2:1;v.add($);let K;if(w.has($)){if(K=n[0],K===void 0||K.startsWith("-"))return c("error: "+$+($==="--resumepoint"?` requires a path