archik 0.12.24 → 0.12.25

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.
@@ -567,7 +567,7 @@ ${j}
567
567
  `)}catch{}},_5r);return{res:o,keepAlive:c}}function A5r(o,c){let d=`event: ${c}
568
568
  data: {}
569
569
 
570
- `;for(let g of o)try{g.res.write(d)}catch{}}async function P5r(o,c){for(let d=c;d<c+50;d++)if(!await new Promise(f=>{let b=iun();b.once("error",()=>{b.close(),f(!0)}),b.listen(d,o,()=>{b.close(()=>f(!1))})}))return d;throw new Error(`no free port found in [${c}, ${c+50})`)}async function cun(o){let c=qsn(o.docPath),d=qsn(o.uiDir),g=o.host??"127.0.0.1",f=o.port??5173;try{await d0t.access(Ate(d,"index.html"))}catch{throw new Error(`UI bundle missing at ${d}. Run \`npm run build\` from the archik checkout, or reinstall.`)}let b=await P5r(g,f),v=new Set,k=Zx(c),T=V1(c),N=iun((fe,ae)=>{let we=fe.url??"/";if(we===Gsn||we.startsWith(Gsn+"?")){u0t(c,T,fe,ae);return}if(we===Vsn||we.startsWith(Vsn+"?")){l0t(k,T,fe,ae);return}if(we===S5r){h0t(c,k,fe,ae);return}if(we===Wsn||we.startsWith(Wsn+"?")){jsn(c,k,ae);return}if(we===Jsn||we.startsWith(Jsn+"?")){let Oe=run(we);Dsn(T,Oe,fe,ae);return}if(we===Zsn||we.startsWith(Zsn+"?")){let Oe=run(we);Osn(T,Oe,fe,ae);return}if(we===Xsn||we.startsWith(Xsn+"?")){Rsn(T,c,fe,ae);return}if(we===Ksn||we.startsWith(Ksn+"?")){Fsn(T,fe,ae);return}if(we===Ysn||we.startsWith(Ysn+"?")){zsn(T,c,ae);return}if(we===Qsn||we.startsWith(Qsn+"?")){Bsn(T,fe,ae);return}if(we===eun||we.startsWith(eun+"?")){Hsn(T,fe,ae);return}if(we===tun||we.startsWith(tun+"?")){$sn(T,c,fe,ae);return}if(we===nun||we.startsWith(nun+"?")){Usn(T,c,fe,ae);return}if(we===x5r){let Oe=T5r(ae);v.add(Oe);let at=()=>{try{clearInterval(Oe.keepAlive)}catch{}v.delete(Oe)};fe.on("close",at),fe.on("error",at);return}E5r(d,we,ae)});await new Promise((fe,ae)=>{N.once("error",ae),N.listen(b,g,()=>{N.off("error",ae),fe()})});let j=[c,k,Ate(T,".archik")],B=JDe.watch(j,{ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:50,pollInterval:10}}),G=fe=>{let ae=fe.endsWith(".archik.suggested.yaml")?"archik:suggestion-changed":"archik:doc-changed";A5r(v,ae)};return B.on("change",G),B.on("add",G),B.on("unlink",G),{url:`http://${g==="0.0.0.0"?"localhost":g}:${b}/`,port:b,host:g,async close(){await B.close();for(let fe of v){clearInterval(fe.keepAlive);try{fe.res.end()}catch{}}v.clear(),await new Promise(fe=>N.close(()=>fe())),await M5r(10)}}}import{spawnSync as N5r}from"node:child_process";import{createHash as R5r}from"node:crypto";import{closeSync as D5r,existsSync as O5r,mkdirSync as F5r,openSync as z5r,readFileSync as j5r,realpathSync as B5r,unlinkSync as H5r,writeFileSync as $5r,writeSync as U5r}from"node:fs";import q5r from"node:os";import Pte from"node:path";function iOe(){return Pte.join(q5r.tmpdir(),"archik-cli")}function oOe(){let o=iOe();return F5r(o,{recursive:!0}),o}function G5r(o){try{return B5r(o)}catch{return Pte.resolve(o)}}function V5r(o){return R5r("sha256").update(G5r(o)).digest("hex").slice(0,12)}function DL(o){let c=iOe(),d=V5r(o);return{stateFile:Pte.join(c,`${d}.json`),logFile:Pte.join(c,`${d}.log`),readyFile:Pte.join(c,`${d}.ready`)}}function r6(o){if(!O5r(o))return null;try{return JSON.parse(j5r(o,"utf8"))}catch{return null}}function W5r(o,c){$5r(o,JSON.stringify(c,null,2))}function i6(o){try{H5r(o)}catch{}}function cOe(o){try{return process.kill(o,0),!0}catch{return!1}}function J5r(o){let c=N5r("ps",["-o","lstart=","-p",String(o)],{encoding:"utf8"});if(c.status!==0)return null;let d=c.stdout.trim();if(d.length===0)return null;let g=new Date(d);return Number.isFinite(g.getTime())?g:null}function o6(o){if(!cOe(o.pid))return!1;let c=J5r(o.pid);if(c===null)return!0;let d=new Date(o.startedAt);return Number.isFinite(d.getTime())?Math.abs(c.getTime()-d.getTime())<=3e4:!0}function Z5r(o){try{let c=new URL(o);if(c.protocol!=="http:"&&c.protocol!=="https:")return!1;let d=c.hostname;return d==="localhost"||d==="127.0.0.1"||d==="[::1]"||d==="::1"}catch{return!1}}async function X5r(o,c=1500){let d=new AbortController,g=setTimeout(()=>d.abort(),c);try{return await fetch(o,{method:"HEAD",signal:d.signal}),!0}catch{return!1}finally{clearTimeout(g)}}async function aun(o){if(!o6(o))return!1;let c=o.urls?.local?.[0];return!c||!Z5r(c)?!0:X5r(c)}function sun(o,c){for(let g=0;g<3;g++)try{let f=z5r(o,"wx");try{U5r(f,JSON.stringify(c,null,2))}finally{D5r(f)}return{ok:!0}}catch(f){if(f.code!=="EEXIST")throw f;let v=r6(o);if(v&&o6(v))return{ok:!1,existing:v};i6(o)}let d=r6(o);return d?{ok:!1,existing:d}:{ok:!0}}function uun(o,c){let d=r6(o);d&&W5r(o,{...d,...c})}async function hun(o){let c;try{c=await Lu(o._[0])}catch(fe){return console.error(`${Yr()} ${fe instanceof Error?fe.message:String(fe)}`),1}let d=lun.relative(process.cwd(),c)||c;try{await K5r(c)}catch{return console.error(`${Yr()} ${Mr(d)} not found in ${er(process.cwd())}`),console.error(` Run ${Mr("archik init")} to create one, then try again.`),1}oOe();let g=DL(c),f=sun(g.stateFile,{pid:process.pid,docPath:c,logFile:process.env.ARCHIK_LOG_FILE??"",startedAt:new Date().toISOString(),urls:{local:[],network:[]}});if(!f.ok){let fe=f.existing.urls.local[0]??"(unknown)";return console.error(`${Yr()} archik is already running for ${Mr(c)}`),console.error(` ${er("PID")} ${f.existing.pid} ${er("on")} ${ys(fe)}`),console.error(` Run ${Mr("archik stop")} first.`),1}let b=!1,v=()=>{b||(b=!0,i6(g.stateFile),qI(c).catch(()=>{}))};process.on("exit",v);let k=Zr(o,"port"),T=k!==void 0?Number.parseInt(k,10):void 0,N=Zr(o,"host"),j=lun.join(U5(),"dist","ui"),B;try{B=await cun({docPath:c,uiDir:j,...N!==void 0?{host:N}:{},...T!==void 0&&Number.isFinite(T)?{port:T}:{}})}catch(fe){throw v(),fe}uun(g.stateFile,{urls:{local:[B.url],network:[]}}),await kfe(c,{pid:process.pid,port:B.port,host:B.host,url:B.url,startedAt:new Date().toISOString()}),T!==void 0&&Number.isFinite(T)&&B.port!==T&&(console.log(""),console.log(` ${$f("!")} Port ${Mr(String(T))} was in use; bound to ${Mr(String(B.port))} instead.`),console.log(` ${er("Pass a different --port if you want a specific number.")}`)),!o["no-open"]&&Y5r(B.url);let K=G1("\u2500".repeat(56));return console.log(""),console.log(K),console.log(` ${Hl()} ${Mr("archik dev")} ${k9()} ${ys(Mr(B.url))}`),console.log(K),console.log(` ${er("editing")} ${Mr(c)}`),console.log(""),console.log(` ${er("Press Ctrl+C to stop.")}`),console.log(""),new Promise(fe=>{let ae=async()=>{try{await B.close()}finally{v(),fe(0)}};process.on("SIGINT",()=>{ae()}),process.on("SIGTERM",()=>{ae()})})}function Y5r(o){let c=process.platform,d=c==="darwin"?"open":c==="win32"?"cmd":"xdg-open",g=c==="win32"?["/c","start","",o]:[o];try{import("node:child_process").then(({spawn:f})=>{let b=f(d,g,{stdio:"ignore",detached:!0});b.unref(),b.on("error",()=>{})})}catch{}}async function dun(o){let c=Zr(o,"user")==="true"?"user":"project",d=Zr(o,"force")==="true",g=await xfe({scope:c,force:d});if(!g.ok)return g.reason==="missing-source"?console.error(`\u2717 Source commands not found at ${g.source}`):console.error(`\u2717 ${g.targetDir} already has ${g.existing.join(", ")}. Pass --force to overwrite.`),1;let f=g.scope==="user"?"user-wide":"this project";console.log(`\u2713 Installed ${g.copied.length} archik slash commands (${f}) \u2192 ${g.targetDir}`);for(let b of g.copied)console.log(` \u2022 /archik:${b.replace(/\.md$/,"")}`);return 0}var fun={init:`archik init \u2014 scaffold a starter .archik/main.archik.yaml
570
+ `;for(let g of o)try{g.res.write(d)}catch{}}async function P5r(o,c){for(let d=c;d<c+50;d++)if(!await new Promise(f=>{let b=iun();b.once("error",()=>{b.close(),f(!0)}),b.listen(d,o,()=>{b.close(()=>f(!1))})}))return d;throw new Error(`no free port found in [${c}, ${c+50})`)}async function cun(o){let c=qsn(o.docPath),d=qsn(o.uiDir),g=o.host??"127.0.0.1",f=o.port??5173;try{await d0t.access(Ate(d,"index.html"))}catch{throw new Error(`UI bundle missing at ${d}. Run \`npm run build\` from the archik checkout, or reinstall.`)}let b=await P5r(g,f),v=new Set,k=Zx(c),T=V1(c),N=iun((fe,ae)=>{let we=fe.url??"/";if(we===Gsn||we.startsWith(Gsn+"?")){u0t(c,T,fe,ae);return}if(we===Vsn||we.startsWith(Vsn+"?")){l0t(k,T,fe,ae);return}if(we===S5r){h0t(c,k,fe,ae);return}if(we===Wsn||we.startsWith(Wsn+"?")){jsn(c,k,ae);return}if(we===Jsn||we.startsWith(Jsn+"?")){let Oe=run(we);Dsn(T,Oe,fe,ae);return}if(we===Zsn||we.startsWith(Zsn+"?")){let Oe=run(we);Osn(T,Oe,fe,ae);return}if(we===Xsn||we.startsWith(Xsn+"?")){Rsn(T,c,fe,ae);return}if(we===Ksn||we.startsWith(Ksn+"?")){Fsn(T,fe,ae);return}if(we===Ysn||we.startsWith(Ysn+"?")){zsn(T,c,ae);return}if((we===Qsn||we.startsWith(Qsn+"?"))&&!(fe.headers.accept??"").includes("text/html")){Bsn(T,fe,ae);return}if(we===eun||we.startsWith(eun+"?")){Hsn(T,fe,ae);return}if(we===tun||we.startsWith(tun+"?")){$sn(T,c,fe,ae);return}if(we===nun||we.startsWith(nun+"?")){Usn(T,c,fe,ae);return}if(we===x5r){let Oe=T5r(ae);v.add(Oe);let at=()=>{try{clearInterval(Oe.keepAlive)}catch{}v.delete(Oe)};fe.on("close",at),fe.on("error",at);return}E5r(d,we,ae)});await new Promise((fe,ae)=>{N.once("error",ae),N.listen(b,g,()=>{N.off("error",ae),fe()})});let j=[c,k,Ate(T,".archik")],B=JDe.watch(j,{ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:50,pollInterval:10}}),G=fe=>{let ae=fe.endsWith(".archik.suggested.yaml")?"archik:suggestion-changed":"archik:doc-changed";A5r(v,ae)};return B.on("change",G),B.on("add",G),B.on("unlink",G),{url:`http://${g==="0.0.0.0"?"localhost":g}:${b}/`,port:b,host:g,async close(){await B.close();for(let fe of v){clearInterval(fe.keepAlive);try{fe.res.end()}catch{}}v.clear(),await new Promise(fe=>N.close(()=>fe())),await M5r(10)}}}import{spawnSync as N5r}from"node:child_process";import{createHash as R5r}from"node:crypto";import{closeSync as D5r,existsSync as O5r,mkdirSync as F5r,openSync as z5r,readFileSync as j5r,realpathSync as B5r,unlinkSync as H5r,writeFileSync as $5r,writeSync as U5r}from"node:fs";import q5r from"node:os";import Pte from"node:path";function iOe(){return Pte.join(q5r.tmpdir(),"archik-cli")}function oOe(){let o=iOe();return F5r(o,{recursive:!0}),o}function G5r(o){try{return B5r(o)}catch{return Pte.resolve(o)}}function V5r(o){return R5r("sha256").update(G5r(o)).digest("hex").slice(0,12)}function DL(o){let c=iOe(),d=V5r(o);return{stateFile:Pte.join(c,`${d}.json`),logFile:Pte.join(c,`${d}.log`),readyFile:Pte.join(c,`${d}.ready`)}}function r6(o){if(!O5r(o))return null;try{return JSON.parse(j5r(o,"utf8"))}catch{return null}}function W5r(o,c){$5r(o,JSON.stringify(c,null,2))}function i6(o){try{H5r(o)}catch{}}function cOe(o){try{return process.kill(o,0),!0}catch{return!1}}function J5r(o){let c=N5r("ps",["-o","lstart=","-p",String(o)],{encoding:"utf8"});if(c.status!==0)return null;let d=c.stdout.trim();if(d.length===0)return null;let g=new Date(d);return Number.isFinite(g.getTime())?g:null}function o6(o){if(!cOe(o.pid))return!1;let c=J5r(o.pid);if(c===null)return!0;let d=new Date(o.startedAt);return Number.isFinite(d.getTime())?Math.abs(c.getTime()-d.getTime())<=3e4:!0}function Z5r(o){try{let c=new URL(o);if(c.protocol!=="http:"&&c.protocol!=="https:")return!1;let d=c.hostname;return d==="localhost"||d==="127.0.0.1"||d==="[::1]"||d==="::1"}catch{return!1}}async function X5r(o,c=1500){let d=new AbortController,g=setTimeout(()=>d.abort(),c);try{return await fetch(o,{method:"HEAD",signal:d.signal}),!0}catch{return!1}finally{clearTimeout(g)}}async function aun(o){if(!o6(o))return!1;let c=o.urls?.local?.[0];return!c||!Z5r(c)?!0:X5r(c)}function sun(o,c){for(let g=0;g<3;g++)try{let f=z5r(o,"wx");try{U5r(f,JSON.stringify(c,null,2))}finally{D5r(f)}return{ok:!0}}catch(f){if(f.code!=="EEXIST")throw f;let v=r6(o);if(v&&o6(v))return{ok:!1,existing:v};i6(o)}let d=r6(o);return d?{ok:!1,existing:d}:{ok:!0}}function uun(o,c){let d=r6(o);d&&W5r(o,{...d,...c})}async function hun(o){let c;try{c=await Lu(o._[0])}catch(fe){return console.error(`${Yr()} ${fe instanceof Error?fe.message:String(fe)}`),1}let d=lun.relative(process.cwd(),c)||c;try{await K5r(c)}catch{return console.error(`${Yr()} ${Mr(d)} not found in ${er(process.cwd())}`),console.error(` Run ${Mr("archik init")} to create one, then try again.`),1}oOe();let g=DL(c),f=sun(g.stateFile,{pid:process.pid,docPath:c,logFile:process.env.ARCHIK_LOG_FILE??"",startedAt:new Date().toISOString(),urls:{local:[],network:[]}});if(!f.ok){let fe=f.existing.urls.local[0]??"(unknown)";return console.error(`${Yr()} archik is already running for ${Mr(c)}`),console.error(` ${er("PID")} ${f.existing.pid} ${er("on")} ${ys(fe)}`),console.error(` Run ${Mr("archik stop")} first.`),1}let b=!1,v=()=>{b||(b=!0,i6(g.stateFile),qI(c).catch(()=>{}))};process.on("exit",v);let k=Zr(o,"port"),T=k!==void 0?Number.parseInt(k,10):void 0,N=Zr(o,"host"),j=lun.join(U5(),"dist","ui"),B;try{B=await cun({docPath:c,uiDir:j,...N!==void 0?{host:N}:{},...T!==void 0&&Number.isFinite(T)?{port:T}:{}})}catch(fe){throw v(),fe}uun(g.stateFile,{urls:{local:[B.url],network:[]}}),await kfe(c,{pid:process.pid,port:B.port,host:B.host,url:B.url,startedAt:new Date().toISOString()}),T!==void 0&&Number.isFinite(T)&&B.port!==T&&(console.log(""),console.log(` ${$f("!")} Port ${Mr(String(T))} was in use; bound to ${Mr(String(B.port))} instead.`),console.log(` ${er("Pass a different --port if you want a specific number.")}`)),!o["no-open"]&&Y5r(B.url);let K=G1("\u2500".repeat(56));return console.log(""),console.log(K),console.log(` ${Hl()} ${Mr("archik dev")} ${k9()} ${ys(Mr(B.url))}`),console.log(K),console.log(` ${er("editing")} ${Mr(c)}`),console.log(""),console.log(` ${er("Press Ctrl+C to stop.")}`),console.log(""),new Promise(fe=>{let ae=async()=>{try{await B.close()}finally{v(),fe(0)}};process.on("SIGINT",()=>{ae()}),process.on("SIGTERM",()=>{ae()})})}function Y5r(o){let c=process.platform,d=c==="darwin"?"open":c==="win32"?"cmd":"xdg-open",g=c==="win32"?["/c","start","",o]:[o];try{import("node:child_process").then(({spawn:f})=>{let b=f(d,g,{stdio:"ignore",detached:!0});b.unref(),b.on("error",()=>{})})}catch{}}async function dun(o){let c=Zr(o,"user")==="true"?"user":"project",d=Zr(o,"force")==="true",g=await xfe({scope:c,force:d});if(!g.ok)return g.reason==="missing-source"?console.error(`\u2717 Source commands not found at ${g.source}`):console.error(`\u2717 ${g.targetDir} already has ${g.existing.join(", ")}. Pass --force to overwrite.`),1;let f=g.scope==="user"?"user-wide":"this project";console.log(`\u2713 Installed ${g.copied.length} archik slash commands (${f}) \u2192 ${g.targetDir}`);for(let b of g.copied)console.log(` \u2022 /archik:${b.replace(/\.md$/,"")}`);return 0}var fun={init:`archik init \u2014 scaffold a starter .archik/main.archik.yaml
571
571
 
572
572
  USAGE
573
573
  archik init [path]