infra-kit 0.11.12 → 0.11.15

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.
@@ -1,4 +1,4 @@
1
- import{P as f,l as G,oa as $,r as F}from"./chunk-666XR52E.js";import{execFile as ne,execFileSync as ae}from"node:child_process";import b from"node:process";var se=5e3,ie=100,W=2e3,J="/bin/ps",ce=1e3,B=["-eo","pid=,ppid=,pgid=,lstart="],V=8<<20,H=e=>e.split(`
1
+ import{P as f,l as G,oa as $,r as F}from"./chunk-GVWC7K7X.js";import{execFile as ne,execFileSync as ae}from"node:child_process";import b from"node:process";var se=5e3,ie=100,W=2e3,J="/bin/ps",ce=1e3,B=["-eo","pid=,ppid=,pgid=,lstart="],V=8<<20,H=e=>e.split(`
2
2
  `).flatMap(r=>{let[t,o,n,...a]=r.trim().split(/\s+/);if(t==null||o==null||n==null)return[];let c=Number(t),s=Number(o),l=Number(n);return!Number.isInteger(c)||!Number.isInteger(s)||!Number.isInteger(l)?[]:[{pid:c,ppid:s,pgid:l,lstart:a.join(" ")}]}),j=e=>{let r=new Map;for(let t of e)t.pid===t.pgid&&r.set(t.pgid,t.lstart);return r},le=(e,r,t)=>{let o=j(r);return q(e,r,t).flatMap(n=>{let a=o.get(n);return a==null||a===""?[]:[{pgid:n,leaderStart:a}]})},K=(e,r)=>{let t=j(r);return e.flatMap(({pgid:o,leaderStart:n})=>t.get(o)===n?[o]:[])},U=(e,r)=>K(e,r).flatMap(t=>{try{b.kill(-t,"SIGKILL")}catch{return[]}return[t]}),q=(e,r,t)=>{let o=new Map;for(let s of r){let l=o.get(s.ppid);l?l.push(s):o.set(s.ppid,[s])}let n=new Set([e]),a=new Set([e]),c=[e];for(let s=0;s<c.length;s+=1)for(let l of o.get(c[s]??-1)??[])a.has(l.pid)||(a.add(l.pid),n.add(l.pgid),c.push(l.pid));return[...n].filter(s=>s>1&&s!==t)},L=()=>{try{return H(ae(J,[...B],{encoding:"utf8",maxBuffer:V}))}catch{return[]}},ue=async()=>new Promise(e=>{ne(J,[...B],{encoding:"utf8",maxBuffer:V},(r,t)=>{e(r?[]:H(t))})}),pe=(e,r,t)=>t.some(o=>o.pid===e&&o.ppid===r),A=(e,r)=>{let t=r.find(o=>o.pid===b.pid)?.pgid;return q(e,r,t)},z=e=>{try{return b.kill(-e,0),!0}catch{return!1}},C=(e,r)=>{for(let t of e)try{b.kill(-t,r)}catch{}},P=new Set,de=(e,r,t)=>{let o=A(e,r),n=t.flatMap(a=>K(a,r));return[...new Set([...o,...n])]},X=()=>{let e=L(),r=[...P].map(t=>t());C(de(b.pid,e,r),"SIGKILL")},me=async e=>new Promise(r=>{setTimeout(r,e)}),_=async(e,r)=>{let t=Date.now()+r,o=e;for(;o.length>0&&Date.now()<t&&(o=o.filter(z),o.length!==0);)await me(ie);return o};function ur(e,r=se,t,o=L){e.unref();let n=!1,a=!1,c=[],s=null,l=()=>c;P.add(l);let m=()=>{s&&clearInterval(s),s=null},w=async()=>{await _(c.map(i=>i.pgid),W),P.delete(l)},y=i=>{let u=e.pid;if(u==null||a||n||i.length===0)return;let T=i.find(v=>v.pid===b.pid)?.pgid,S=le(u,i,T);S.length>0&&(c=S)},h=async()=>{e.pid==null||a||n||y(await ue())};y(L()),s=setInterval(()=>{h()},ce),s.unref();let R=i=>{n||t?.(i)};return e.on("exit",(i,u)=>{a=!0,m(),n||(U(c,o()),w()),R(`exited unexpectedly (code=${i??"null"}, signal=${u??"null"})`)}),e.on("error",i=>{R(`failed to spawn: ${i.message}`)}),{kill:async()=>{n=!0,m();let i=e.pid;if(i==null){P.delete(l);return}if(e.exitCode!==null||e.signalCode!==null){U(c,o()),await w();return}let u=o();if(u.length>0&&!pe(i,b.pid,u))return;let T=A(i,u);C(T,"SIGTERM");let S=await _(T,r);if(S.length===0){P.delete(l);return}let v=A(i,o()),D=[...new Set([...S,...v])].filter(z);C(D,"SIGKILL"),await _(D,W),P.delete(l)}}}import{constants as fe}from"node:os";import k from"node:process";var ge=["SIGINT","SIGTERM","SIGHUP"],Oe=fe.signals,be=2,N=e=>128+(Oe[e]??be),we=2e4,ye=e=>{k.exit(e)},he=(e,r)=>{k.on(e,r)},Pe=(e,r)=>{k.off(e,r)},xe=(e,r)=>{let t=setTimeout(e,r);return t.unref(),()=>{clearTimeout(t)}},I=e=>{try{k.stderr.write(e)}catch{}},Se=(e,r)=>{let t=r instanceof Error?`${r.message}
3
3
  ${r.stack??"(no stack)"}`:String(r);I(`
4
4
  \u2717 Teardown failed while handling ${e}: ${t}
@@ -7,4 +7,4 @@ ${r.stack??"(no stack)"}`:String(r);I(`
7
7
  `),w?.(),n(),h(),r(N(i));return}m=i,w=c(()=>{let u=`
8
8
  \u26A0 Teardown deadline exceeded at stage=${s()} after ${a}ms \u2014 force-quitting.
9
9
  `;I(u),l(u),n(),h(),r(N(i))},a),(async()=>{try{await e(i)}catch(u){Se(i,u)}finally{w?.(),h(),r(N(i))}})()};for(let i of ge){let u=()=>R(i);y.set(i,u),t(i,u)}return h};var Re=new Set(["ExitPromptError","AbortPromptError","PromptCancelledError"]),Y=e=>e instanceof Error&&Re.has(e.name),br=e=>{if(Y(e))return!0;let r=e?.cause;return Y(r)};import{loadDev as Te}from"@slip-stream-kit/config/internal";import ke from"node:path";var Ee=(e,r)=>{let t=new Set;for(let o of Object.values(e))for(let n of Object.keys($(o,r).proxy))t.add(n);return[...t]},ve=async(e,r)=>{let t={},o=[];return await Promise.all(r.map(async n=>{try{let c=(await Te(ke.join(e,"apps",n,"ui")))?.proxy?.routes;if(!c)return;t[n]=Object.fromEntries(Object.entries(c).map(([s,l])=>[s,l.packageName]))}catch(a){o.push({app:n,message:a instanceof Error?a.message:String(a)})}})),{routePkg:(n,a)=>t[n]?.[a],loadErrors:o}},xr=async(e,r,t,o)=>{let{routePkg:n,loadErrors:a}=await ve(e,Ee(r,t));return{ctx:{discovered:t,apiPkgByApp:Object.fromEntries(o.map(c=>[c.name,c.packageName])),routePkg:n},loadErrors:a}};import{$ as _e}from"zx";var d=class extends Error{code;data;constructor(r){super(r.message),this.name="OrcaError",this.code=r.code,this.data=r.data}},x=class extends Error{exitCode;stderrTail;constructor(r,t){super(`orca: stdout is not a JSON envelope (exit ${r??"signal"})`),this.name="OrcaMalformedError",this.exitCode=r,this.stderrTail=t}},g=class extends Error{constructor(){super("orca: command not found \u2014 the CLI is registered from Orca \u2192 Settings \u2192 Experimental \u2192 CLI"),this.name="OrcaAbsentError"}},Le=400,Ae=127,Ce=e=>typeof e=="object"&&e!==null&&e.code==="ENOENT",Ne=async e=>{try{return await _e({nothrow:!0,quiet:!0})`orca ${e} --json`}catch(r){throw Ce(r)?new g:r}},Ie=e=>{try{let r=JSON.parse(e);return typeof r=="object"&&r!==null&&typeof r.ok=="boolean"?r:null}catch{return null}},p=async e=>{let r=await Ne(e),t=Ie(r.stdout);if(f.debug({argv:e,ok:t?.ok,code:t?.error?.code,exitCode:r.exitCode},"orca"),!t)throw r.exitCode===Ae?new g:new x(r.exitCode,r.stderr.slice(-Le));if(!t.ok)throw new d(t.error??{code:"unknown",message:"orca: ok:false without an error payload"});return t.result};var Me=async()=>{try{let e=await p(["status"]);return f.debug({appVersion:e.runtime?.appVersion},"orca: status"),e.app?.running===!0&&e.runtime?.reachable===!0?"ready":"unreachable"}catch(e){return e instanceof g?"absent":(f.debug({error:e},"orca: status probe failed"),"unreachable")}};import{realpath as De}from"node:fs/promises";var O=async e=>{try{return await De(e)}catch{return e}};var Ge=async e=>{let[{repos:r=[]},t]=await Promise.all([p(["repo","list"]),O(e)]);for(let o of r)if(await O(o.path)===t)return{registered:!0,visibility:o.externalWorktreeVisibility};return{registered:!1}},Fe=async e=>{let{repo:r}=await p(["repo","add","--path",e]);return{visibility:r?.externalWorktreeVisibility}};var $e="500",We=async(e,r)=>{let[{worktrees:t=[]},o]=await Promise.all([p(["worktree","list","--repo",`path:${e}`,"--limit",$e]),O(r)]);for(let n of t)if(await O(n.path)===o)return!0;return!1};import Ue from"node:process";var Q="::",Je=e=>{let r=e.ORCA_WORKTREE_ID;if(!r)return null;let t=r.indexOf(Q);if(t<0)return null;let o=r.slice(t+Q.length);return o.length>0?o:null},Be=async(e,r=Ue.env)=>{let t=Je(r);if(t===null)return null;let o=await O(t);for(let n of e)if(await O(n)===o)return n;return null};var Z="200",M=async e=>{try{let r=await p(["terminal","list","--worktree",`path:${e}`,"--limit",Z]),t=r.truncated===!0;return t&&f.debug({cwd:e,limit:Z},"orca: terminal list truncated"),{terminals:r.terminals??[],truncated:t}}catch(r){if(r instanceof d&&r.code==="selector_not_found")return{terminals:[],truncated:!1};throw r}};var Ve=async e=>{try{return await p(["terminal","close","--worktree",`path:${e}`,"--all"]),"retired"}catch(r){if(r instanceof d&&r.code==="selector_not_found")return"not_found";if(r instanceof d&&r.code==="terminal_close_incomplete")return f.debug({cwd:e,error:r},"orca: surfaces not retired"),"retired";throw r}},He=async e=>{let{terminals:r}=await M(e);for(let o of r)await p(["terminal","close","--terminal",o.handle]);let t=await Ve(e);return r.length===0&&t==="not_found"?{closed:!1,skipped:"not_found"}:{closed:!0,count:r.length}},je=(e,r)=>r instanceof g?{closed:!1,skipped:"absent"}:r instanceof d?{closed:!1,error:r}:r instanceof x?{closed:!1,error:new d({code:"orca_malformed_output",message:r.message,data:{exitCode:r.exitCode,stderrTail:r.stderrTail}})}:(f.debug({cwd:e,error:r},"orca: close failed outside the Orca contract"),{closed:!1,error:new d({code:"orca_close_failed",message:r instanceof Error?r.message:String(r)})}),Ke=async(e,r)=>{if(r!=="ready")return{closed:!1,skipped:r};try{return await He(e)}catch(t){return je(e,t)}};import{setTimeout as qe}from"node:timers/promises";var ze=3,Xe=300,re=(e={})=>({attempts:e.attempts??ze,delayMs:e.delayMs??Xe,exhausted:!1}),Ye=async e=>{try{return{created:await p(e)}}catch(r){if(r instanceof d&&r.code==="selector_not_found")return{notSelectable:r};throw r}},Qe=async(e,r,t)=>{let o=t.exhausted?1:t.attempts,n=Array.from({length:o},(c,s)=>s+1),a;for(let c of n){let s=await Ye(e);if("created"in s)return s.created.terminal.handle;a=s.notSelectable,c<o&&await qe(t.delayMs)}throw t.exhausted=!0,new d({code:"orca_worktree_not_selectable",message:`orca: worktree ${r} is not selectable after ${o} attempt(s): ${a?.message??""}`,data:{cwd:r,attempts:o,cause:a?.data}})},ee=async(e,r)=>(await p(["terminal","split","--terminal",e,"--direction",r])).split.handle,Ze=async e=>{let{cwd:r,title:t,focus:o,layout:n,panes:a,poll:c=re()}=e,s=["terminal","create","--worktree",`path:${r}`,"--title",t,...o?["--focus"]:[]],l=await Qe(s,r,c),m=[l];return n==="full"&&(m.push(await ee(l,"horizontal")),a==="three-pane"&&m.push(await ee(l,"vertical"))),{handles:m,layout:n}};var er=e=>{let{branch:r}=e,t=G(r);return t?F(t):r};var lt=e=>typeof e=="object",E=async e=>(await e.body?.cancel(),{kind:"foreign",status:e.status,contentType:e.headers.get("content-type")}),ut=(e,r)=>{let t=r.contentType?.split(";")[0]?.trim(),o=t==null||t===""?`${r.status}`:`${r.status} ${t}`;return`port ${e} answered ${o}, not vite's ping \u2014 liveness cannot be verified`};var te={accept:"text/x-vite-ping"},rr=e=>e.kind==="api"?`http://127.0.0.1:${e.port}/__health`:`http://127.0.0.1:${e.port}/`,tr=(e,r)=>{try{return new URL(e,r)}catch{return null}},or=async(e,r)=>{let t=await fetch(e,{signal:r});return t.ok?(await t.body?.cancel(),"ok"):E(t)},nr=async(e,r)=>{let t=await fetch(e,{headers:te,redirect:"manual",signal:r});if(t.status===204)return"ok";if(t.status<300||t.status>=400)return E(t);let o=t.headers.get("location"),n=o==null?null:tr(o,e);if(n==null||n.origin!==new URL(e).origin)return E(t);await t.body?.cancel();let a=await fetch(n,{headers:te,redirect:"manual",signal:r});return a.status!==204?E(a):(await a.body?.cancel(),"ok")},pt=async e=>{let r=rr(e),t=AbortSignal.timeout(1500);try{return e.kind==="api"?await or(r,t):await nr(r,t)}catch{return"refused"}};import{DEFAULT_RELEASE_SLUG as oe,slugifyRelease as ar}from"@slip-stream-kit/config/internal";import{execFileSync as sr}from"node:child_process";var ir=e=>{try{let r=sr("git",["rev-parse","--abbrev-ref","HEAD"],{cwd:e,encoding:"utf-8"}).trim(),t=ar(r);return t===""?oe:t}catch{return oe}};export{xr as a,X as b,ur as c,N as d,gr as e,d as f,p as g,Me as h,Be as i,M as j,Ke as k,Ge as l,Fe as m,We as n,re as o,Ze as p,er as q,lt as r,ut as s,pt as t,ir as u,br as v};
10
- //# sourceMappingURL=chunk-RD556L3P.js.map
10
+ //# sourceMappingURL=chunk-EARHBKGG.js.map
@@ -1,12 +1,12 @@
1
- import{a as pe}from"./chunk-MFAFQVTW.js";import{a as ce}from"./chunk-SBD7FT5C.js";import{d as _,p as se,q as ae}from"./chunk-QSTGO43H.js";import Ue from"node:process";import qe from"pino";import He from"pino-pretty";var Je=["token","*.token","serviceToken","*.serviceToken","DOPPLER_TOKEN","*.DOPPLER_TOKEN","INFRA_KIT_ENV_TOKEN","*.INFRA_KIT_ENV_TOKEN"],Xe=()=>{let e=Ue.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),qe({level:e,redact:Je},He({destination:2,ignore:t.join(","),colorize:!0,sync:!0}))},L=Xe();import ne from"node:fs/promises";import $e from"node:os";import A from"node:path";import Bt from"node:process";import{z as i}from"zod";import Qe from"node:process";import Ye from"node:process";var $={enabled:!1},Ze=(e,t=r=>{Ye.stdout.write(r)})=>($.enabled&&e&&e.structuredContent!=null&&t(`${JSON.stringify(e.structuredContent,null,2)}
2
- `),e),ue=e=>{e.options.some(r=>r.long==="--json")||e.option("--json","Output the structured result as JSON on stdout (human logs stay on stderr)"),e.commands.forEach(ue)};var le={source:null},P=()=>le.source!==null,et=()=>P()||$.enabled,K=()=>!!Qe.env.CI,tt=({env:e,stdinIsTTY:t,flag:r})=>{if(r)return"flag";let n=e.INFRA_KIT_AGENT;return n==="1"||e.CLAUDECODE!==void 0&&!t&&n!=="0"?"env":null};var F=e=>{throw new Error(`Unexpected value: ${JSON.stringify(e)}`)};var w=(e,t)=>Object.fromEntries(Object.entries(e).filter(([r])=>r!==t));var S=({key:e,id:t,note:r})=>({id:t,note:r,apply:n=>e in n?{changed:!0,result:w(n,e)}:{changed:!1,result:n}});var de=S({key:"devProxy",id:"drop-dev-proxy-key",note:'the retired "devProxy" key (dev URLs are port-free https://<release>.<package>.localhost)'});var me=S({key:"envAutoLoad",id:"drop-env-auto-load-key",note:'the retired "envAutoLoad" key (env auto-load is gone \u2014 run `env-load -c <config>` in the terminal)'});var ge=S({key:"environments",id:"drop-environments-key",note:`the retired "environments" key (deploy targets now come from each workflow's workflow_dispatch options, auth from the token store)`});var rt=e=>{let t=e.ide;if(t===null||typeof t!="object")return{changed:!1,result:e};let r=!1,n=s=>{if(s===null||typeof s!="object"||!("config"in s))return s;let a=s.config;return a===null||typeof a!="object"||!("mode"in a)?s:(r=!0,{...s,config:w(a,"mode")})},o=Array.isArray(t)?t.map(n):n(t);return r?{changed:!0,result:{...e,ide:o}}:{changed:!1,result:e}},fe={id:"strip-legacy-ide-mode",note:'legacy "mode"',apply:rt};var nt="zed",he=e=>e!==null&&typeof e=="object"&&e.provider===nt,ot=e=>{let t=e.ide;if(Array.isArray(t)){let r=t.filter(n=>!he(n));return r.length===t.length?{changed:!1,result:e}:{changed:!0,result:r.length>0?{...e,ide:r}:w(e,"ide")}}return he(t)?{changed:!0,result:w(e,"ide")}:{changed:!1,result:e}},ye={id:"strip-retired-zed-ide",note:'the retired "zed" provider',apply:ot};var W=[fe,ye,ge,de,me];var C=e=>W.reduce((t,r)=>{let n=r.apply(t.result);return n.changed?{changed:!0,result:n.result,notes:[...t.notes,r.note]}:t},{changed:!1,result:e,notes:[]});import it from"node:fs/promises";import st from"node:os";var at=async e=>{try{return await it.access(e),!0}catch{return!1}},G=e=>{let t=st.homedir();return e.startsWith(t)?`~${e.slice(t.length)}`:e};import{randomBytes as ct}from"node:crypto";import v from"node:fs/promises";import B from"node:path";import pt from"node:process";var D=class extends Error{constructor(t){super(`${t} changed on disk since it was read`),this.name="ConfigFileChangedError"}},ut=2,lt=e=>/^([ \t]+)\S/m.exec(e)?.[1]??ut,dt=4095,O=async({path:e,raw:t,migrated:r,expectedMtimeMs:n})=>{let o=await v.realpath(e),s=B.dirname(o),a=B.basename(o),p=B.join(s,`.${a}.${pt.pid}.${ct(4).toString("hex")}.tmp`),l=`${JSON.stringify(r,null,lt(t))}
3
- `;try{await v.writeFile(p,l,"utf8");let d=await v.stat(o);if(d.mtimeMs!==n)throw new D(e);await v.chmod(p,d.mode&dt),await v.rename(p,o)}catch(d){throw await v.rm(p,{force:!0}),d}},mt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),gt=async e=>{let t=await v.stat(e),r=await v.readFile(e,"utf8");if(r.trim()==="")return{changed:!1,result:{},notes:[],path:e};let n=JSON.parse(r);if(!mt(n))return{changed:!1,result:{},notes:[],path:e};let o=C(n);return o.changed&&await O({path:e,raw:r,migrated:o.result,expectedMtimeMs:t.mtimeMs}),{...o,path:e}};var V=async(e,t,r,{schema:n})=>{if(e.autoMigrate==="off")return{kind:"not-applicable"};let o=C(t);if(!o.changed)return{kind:"not-applicable"};let s=n.safeParse(o.result);if(!s.success)return{kind:"not-applicable"};if(e.required&&K())return{kind:"ci-gated"};try{await O({path:e.path,raw:r,migrated:o.result,expectedMtimeMs:e.mtimeMs})}catch(a){return L.debug(a,`auto-migration could not rewrite ${e.path}`),{kind:"not-applicable"}}return L.warn(`Migrated ${G(e.path)}: removed ${o.notes.join(" and ")} (retired by infra-kit ${ce.version})`),{kind:"migrated",data:s.data}};import E from"node:path";import Re from"node:process";import{$ as m}from"zx";var I=e=>{let t=new Set,r=e;for(;r!==null&&typeof r=="object"&&!t.has(r);){t.add(r);let{stderr:n,stderrExcerpt:o}=r;if(typeof n=="string"&&n.length>0)return n;if(typeof o=="string"&&o.length>0)return o;r=r.cause}},ft=(e,t)=>{let r=t.stderrExcerpt??I(e),n=[`failed to ${t.operation}`];return r&&n.push(`stderr: ${r.slice(0,200).trim()}`),t.remediation&&n.push(`try: ${t.remediation}`),n.join(" \u2014 ")},g=class extends Error{operation;remediation;stderrExcerpt;constructor(t,r){super(ft(t,r),{cause:t}),this.name="OperationError",this.operation=r.operation,this.remediation=r.remediation,this.stderrExcerpt=r.stderrExcerpt??I(t)}};var ht=/^v?(\d+)\.(\d+)\.(\d+)$/,yt=/^(\d+)\.(\d+)\.(\d+)$/,vt=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,T="release/",z="release/v",ve="refs/heads/",kt="next";var ke=new Set(["dev","main","next","hotfix","regular","release"]),x=class extends Error{constructor(t){super(t),this.name="InvalidReleaseNameError"}},b=class extends Error{constructor(t){super(t),this.name="InvalidReleaseRefError"}},xe=e=>e.startsWith(ve)?e.slice(ve.length):e,be=(e,t,r)=>({kind:"version",semver:{major:e,minor:t,patch:r},raw:`${e}.${t}.${r}`}),U=e=>{if(e.length===0)throw new x('Release name is empty. Provide a kebab-case name like "checkout-redesign".');if(e.length>50)throw new x(`Release name "${e}" is ${e.length} characters; the maximum is 50.`);if(!vt.test(e))throw new x(`Release name "${e}" is not kebab-case. Use lowercase letters, digits, and single hyphens, e.g. "checkout-redesign".`);if(ke.has(e))throw new x(`Release name "${e}" is reserved. Reserved names: ${[...ke].join(", ")}.`)},q=e=>{let t=xe(e.trim());if(!t.startsWith(T))return null;if(t.startsWith(z)){let n=t.slice(z.length),o=yt.exec(n);if(o)return be(Number(o[1]),Number(o[2]),Number(o[3]))}let r=t.slice(T.length);try{U(r)}catch{return null}return{kind:"name",name:r,raw:r}},wt=e=>{let t=e.trim();if(xe(t).startsWith(T)){let o=q(t);if(!o)throw new b(`"${e}" looks like a release branch but is not a valid release/v<semver> or release/<name> ref.`);return o}let n=ht.exec(t);if(n)return be(Number(n[1]),Number(n[2]),Number(n[3]));if(t.toLowerCase()===kt)throw new b('The "next" token must be resolved to a concrete version (via computeNextVersion) before parsing a release ref.');if(t.includes("@"))throw new b(`Cannot parse "${e}" as a release ref: the \`@date\` suffix belongs to \`release create\`; pass the version alone here and use \`--release-date\` on \`release edit\``);try{U(t)}catch(o){let s=o instanceof Error?o.message:String(o);throw new b(`Cannot parse "${e}" as a release ref: ${s}`)}return{kind:"name",name:t,raw:t}},xt=e=>e.kind==="version"?`${z}${e.raw}`:`${T}${e.name}`,bt=(e,t)=>{let r=t==="hotfix"?"Hotfix":"Release";return e.kind==="version"?`${r} v${e.raw}`:`${r} ${e.name}`},Rt=e=>e.kind==="version"?`Release v${e.raw} (RC)`:`Release ${e.name} (RC)`,Pt=e=>e.kind==="version"?`v${e.raw}`:e.name,St=e=>e.raw,H=e=>e==null?!1:q(e)!==null,we=e=>{if(e===void 0)return null;let t=e instanceof Date?e.getTime():new Date(e).getTime();return Number.isNaN(t)?null:t},Et=(e,t,r)=>{if(e.kind==="version"&&t.kind==="version")return e.semver.major!==t.semver.major?e.semver.major-t.semver.major:e.semver.minor!==t.semver.minor?e.semver.minor-t.semver.minor:e.semver.patch-t.semver.patch;if(e.kind==="version")return-1;if(t.kind==="version")return 1;let n=we(r?.a),o=we(r?.b);return n!==null&&o!==null&&n!==o?n-o:e.name<t.name?-1:e.name>t.name?1:0};var Pe=async e=>{let t=await m({cwd:e})`git worktree list --porcelain`,r=[],n=null;for(let o of t.stdout.split(`
4
- `)){if(o.startsWith("worktree ")){n&&r.push(n),n={path:o.slice(9),branch:null,detached:!1,bare:!1,prunable:!1,locked:!1};continue}n&&(o.startsWith("branch ")?n.branch=o.slice(7).replace(/^refs\/heads\//,""):o==="detached"?n.detached=!0:o==="bare"?n.bare=!0:o==="locked"||o.startsWith("locked ")?n.locked=!0:(o==="prunable"||o.startsWith("prunable "))&&(n.prunable=!0))}return n&&r.push(n),r},Ct=async e=>{let t=await Pe(Re.cwd()),r=n=>e==="release"?H(n):n.startsWith("feature/");return t.map(n=>n.branch).filter(n=>n!==null&&r(n))},It=e=>{let t=I(e);return t&&/not a git repository/i.test(t)?"not a git repository":void 0},Mt=({hasStderr:e})=>{if(P())return"infra-kit resolves its project from the working directory; run it from inside an infra-kit project repo (or one of its git worktrees), or pass `-C <dir>` naming one";let t="run infra-kit from inside an infra-kit project repo (or one of its git worktrees)";return e?`${t}; if you are already in one, the stderr in this message is the real cause`:t},M=async()=>{try{return(await m({quiet:!0})`git rev-parse --show-toplevel`).stdout.trim()}catch(e){let t=It(e)??I(e);throw new g(e,{operation:`resolve the project root from ${Re.cwd()}`,stderrExcerpt:t,remediation:Mt({hasStderr:t!==void 0})})}},J=async e=>{let t=e??await M(),r=(await m({cwd:t,quiet:!0})`git rev-parse --git-common-dir`).stdout.trim(),n=E.resolve(t,r);return n.includes(`${E.sep}.git${E.sep}modules${E.sep}`)?t:E.dirname(n)},Se=async()=>(await m`git rev-parse --abbrev-ref HEAD`).stdout.trim(),Ee=async()=>(await m`git status --porcelain`).stdout.split(`
5
- `).map(t=>t.trimEnd()).filter(t=>t.trim().length>0),jt=async()=>(await Ee()).length===0,At=async()=>{let e=await M(),[t,r]=await Promise.all([m({cwd:e})`git rev-parse --absolute-git-dir`,m({cwd:e})`git rev-parse --git-common-dir`]),n=t.stdout.trim(),o=E.resolve(e,r.stdout.trim());return n!==o};var $t=async e=>(await m`git branch --list ${e}`).stdout.trim().length>0,Dt=async e=>{(await m`git branch --list ${e}`).stdout.trim().length!==0&&await Se()!==e&&await m`git branch -D ${e}`},Ot=async e=>{(await m`git ls-remote --heads origin ${e}`).stdout.trim().length!==0&&await m`git push origin --delete ${e}`};import{$ as N}from"zx";var Tt=async(e,t)=>{let r=`${t}^{commit}`;try{return(await N({cwd:e,quiet:!0})`git rev-parse --verify --quiet ${r}`).stdout.trim()||null}catch{return null}},Nt=async(e,t,r)=>{try{return await N({cwd:e,quiet:!0})`git merge-base --is-ancestor ${t} ${r}`,!0}catch(n){if(n.exitCode===1)return!1;throw new g(n,{operation:`test whether ${t} is contained in ${r}`,remediation:"both refs must exist \u2014 verify them with rev-parse first"})}},_t=async(e,t)=>{let n=(await N({cwd:e,quiet:!0})`git ls-remote --heads origin ${t}`).stdout.trim().split(`
6
- `)[0];return n?n.split(/\s+/)[0]??null:null},Lt=async(e,t)=>{let r=t.map(n=>`${n.sha}:refs/heads/${n.branch}`);if(r.length===0)return{refspecs:r,pushed:!1};try{return await N({cwd:e,quiet:!0})`git push --atomic origin ${r}`,{refspecs:r,pushed:!0}}catch(n){return{refspecs:r,pushed:!1,stderr:n.stderr}}};import Y from"node:path";import X from"node:process";import{$ as h}from"zx";var Ce=async e=>{let t=e??X.cwd(),r=(await h({cwd:t,quiet:!0})`git rev-parse --git-common-dir`).stdout.trim(),n=X.env.INFRA_KIT_SESSION||String(X.pid);return Y.join(Y.resolve(t,r),"infra-kit",`merge-dev-${n}`)},Ie=e=>e.replace(/[^\w-]+/g,"-"),Kt=(e,t)=>Y.join(`${e}${se}`,ae.mergeDev,Ie(t)),Z=async e=>{try{return await h({cwd:e,quiet:!0})`git rev-parse -q --verify MERGE_HEAD`,!0}catch{return!1}},Ft=async e=>{if(await Z(e))throw new g(void 0,{operation:"reuse the scratch worktree",stderrExcerpt:"a merge is still in progress in the scratch worktree",remediation:"this is an infra-kit bug \u2014 the previous branch iteration did not clean up"});let t=(await h({cwd:e,quiet:!0})`git status --porcelain`).stdout.trim();if(t.length>0)throw new g(void 0,{operation:"reuse the scratch worktree",stderrExcerpt:`scratch worktree is dirty: ${t.split(`
7
- `)[0]}`,remediation:"this is an infra-kit bug \u2014 the previous branch iteration did not clean up"})},Wt=async e=>{let t=async r=>{try{await r()}catch{}};await Z(e)&&await t(()=>h({cwd:e,quiet:!0})`git merge --abort`),await t(()=>h({cwd:e,quiet:!0})`git reset --hard`),await t(()=>h({cwd:e,quiet:!0})`git clean -fd`)},Gt=async(e,t)=>{let{cwd:r,anchor:n="origin/dev"}=e,o=await Ce(r),s=async()=>{await h({cwd:r,quiet:!0})`git worktree add --detach ${o} ${n}`};try{await s()}catch(p){try{await h({cwd:r,quiet:!0})`git worktree prune`,await s()}catch{throw new g(p,{operation:"create the scratch worktree for the merge",remediation:`remove any stale checkout at ${o}, then retry`})}}let a={path:o,remove:async()=>{try{await h({cwd:r,quiet:!0})`git worktree remove --force ${o}`}catch{}}};try{return await t(a)}finally{await a.remove()}};var Me="infra-kit.json";var Vt="infra-kit.json",zt="projects",Ut=i.object({provider:i.literal("doppler"),config:i.object({name:i.string().min(1)})}),qt=i.discriminatedUnion("provider",[Ut]),Ht=i.object({workspaceConfigPath:i.string().min(1)}).strict(),Jt=i.object({provider:i.literal("cursor"),config:Ht}).strict(),je=i.discriminatedUnion("provider",[Jt]),Xt=i.union([je,i.array(je).min(1)]),Yt=i.object({provider:i.literal("jira"),config:i.object({baseUrl:i.string().url(),projectId:i.number().int().positive()})}),Zt=i.discriminatedUnion("provider",[Yt]),Qt=["two-columns","three-pane"],er=i.object({layout:i.enum(Qt).optional()}).strict(),tr=i.object({openInGithubDesktop:i.boolean().optional(),openInOrca:i.boolean().optional(),orca:er.optional()}).strict(),rr=i.object({port:i.number().int().positive().optional(),prefixUrl:i.string().min(1).optional()}).strict(),nr=i.record(i.string().min(1),rr),or=i.enum(["local","cloud"]),ir=i.object({watchDeps:i.boolean().optional(),proxy:i.record(i.string().min(1),or).optional()}).strict(),sr=i.object({apps:i.record(i.string().min(1),ir).optional(),orca:i.boolean().optional()}).strict(),ar=i.record(i.string().min(1),sr),cr=i.enum(["disallow","allow","cli-only"]),Ae=i.string().regex(/^[A-Z_]\w*$/i,"must be a POSIX environment-variable name"),pr=i.object({command:i.string().min(1),args:i.array(i.string()).default([]),env:i.array(Ae).min(1),unset:i.array(Ae).default([])}).strict().superRefine((e,t)=>{for(let r of e.env)pe.has(r)&&t.addIssue({code:"custom",path:["env"],message:`"${r}" is process plumbing the proxy never strips or injects \u2014 it cannot be a credential name`})}),ur=i.record(i.string().regex(/^[a-z][a-z0-9-]*$/,"must be lowercase letters, digits and hyphens, starting with a letter").refine(e=>!e.includes("infra-kit"),{message:'"infra-kit" is reserved: it is the .mcp.json key of the retired infra-kit MCP server \u2014 pick another name'}),pr),te=i.string().min(1).superRefine((e,t)=>{if(e.startsWith("/")||e.startsWith("\\")||/^[a-z]:/i.test(e)){t.addIssue({code:"custom",message:`"${e}" must be relative to the repository root`});return}let r=e.split(/[/\\]/).filter(o=>o!==""&&o!==".");r.includes("..")&&t.addIssue({code:"custom",message:`"${e}" must not contain a ".." segment`}),r[0]===".git"&&t.addIssue({code:"custom",message:`"${e}" must not be .git or a path inside it`}),e.includes("\\")&&t.addIssue({code:"custom",message:`"${e}" must use "/" as the separator, not "\\"`});let n=e.split("/");n.includes("")&&t.addIssue({code:"custom",message:`"${e}" must not have a trailing or doubled "/"`}),n.includes(".")&&t.addIssue({code:"custom",message:`"${e}" must not contain a "." segment; write it from the repository root, e.g. "vendor/configs"`})}),lr=i.object({path:te,target:te.optional()}).strict(),De=i.object({copy:i.array(lr).min(1),exclude:i.array(i.string().regex(/^[^/\\]+$/,'must be a single path segment, without "/"')).optional(),legacyCleanup:i.array(te).optional()}).strict(),oe=i.object({envManagement:qt,ide:Xt.optional(),taskManager:Zt.optional(),worktrees:tr.optional(),dev:nr.optional(),devServersPresets:ar.optional(),protectedEnvs:cr.optional(),mcp:ur.optional(),vendorSource:De.nullable().optional()}).strict(),dr=443,Oe=oe.superRefine((e,t)=>{if(!Array.isArray(e.ide))return;let r=new Set;for(let n of e.ide){if(r.has(n.provider)){t.addIssue({code:"custom",message:"each IDE provider may appear at most once",path:["ide"]});return}r.add(n.provider)}}),re=oe.partial(),mr=e=>{let t=e.ide;return t?Array.isArray(t)?t:[t]:[]},Te="two-columns",gr=e=>e.worktrees?.orca?.layout??Te,k=null,j=null,Ne=()=>`${Bt.cwd()} ${$e.homedir()}`,_e=()=>A.join($e.homedir(),_),Le=()=>A.join(_e(),Vt),Ke=async()=>{let e=Ne();if(j&&j.key===e)return j.value;let t=await M(),r=await J(t),n=A.basename(r),o={main:A.join(t,Me),userGlobal:Le(),userProject:A.join(_e(),zt,n,Me),projectName:n};return j={key:e,value:o},o},fr=async(e={})=>{let t=e.autoMigrate??"write",r=Ne(),n=await Ke(),o;try{o=await ne.stat(n.main)}catch{k=null;let y=n.main.replace(/\.json$/,".yml");throw await Q(y)?new Error(`infra-kit.json not found at ${n.main}. A legacy infra-kit.yml exists \u2014 run \`infra-kit setup --skip-tools\` to convert it.`):new Error(P()?`infra-kit.json not found at ${n.main} \u2014 the working directory is not an infra-kit project. Run infra-kit from inside an infra-kit project repo, or pass \`-C <dir>\` naming one.`:`infra-kit.json not found at ${n.main} \u2014 this git repo is not an infra-kit project. Run \`infra-kit setup --skip-tools\` here to create it, cd into an infra-kit project repo, or check out a branch that has infra-kit.json.`)}let[s,a]=await Promise.all([Q(n.userGlobal),Q(n.userProject)]),p={main:Number(o.mtimeMs),userGlobal:s?Number(s.mtimeMs):null,userProject:a?Number(a.mtimeMs):null};if(k&&k.key===r&&kr(k.mtimes,p))return k.value;let l=[{label:"infra-kit.json",path:n.main,required:!0,autoMigrate:t,mtimeMs:p.main},{label:"~/.infra-kit/infra-kit.json",path:n.userGlobal,required:!1,autoMigrate:t,mtimeMs:p.userGlobal},{label:`~/.infra-kit/projects/${n.projectName}/infra-kit.json`,path:n.userProject,required:!1,autoMigrate:t,mtimeMs:p.userProject}],d={};for(let y of l){let R=await wr(y);R!==null&&(d={...d,...R})}let f=Oe.safeParse(d);if(!f.success)throw new Error(`Invalid merged infra-kit config: ${i.prettifyError(f.error)}`);return k={key:r,mtimes:p,value:f.data},f.data},hr=()=>{k=null},yr=()=>{k=null,j=null},Q=async e=>{try{return await ne.stat(e)}catch{return null}},vr=async e=>{try{return await ne.readFile(e,"utf-8")}catch{return null}},kr=(e,t)=>{let r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(n=>e[n]===t[n])},Fe=e=>new Error(`${e.message}
8
- A retired key on this branch \u2014 run \`infra-kit setup --skip-tools\` in this checkout and commit infra-kit.json.`),wr=async e=>{let t=await vr(e.path);if(t===null){if(e.required)throw new Error(`${e.label} not found at ${e.path}`);return null}let r;try{r=t.trim()===""?{}:JSON.parse(t)}catch(a){throw new Error(`Invalid JSON in ${e.label} at ${e.path}: ${a.message}`)}if(ee(r)&&"envTokens"in r)throw new Error(Sr(e));!e.required&&ee(r)&&Pr(e,r);let n=re.safeParse(r);if(n.success)return n.data;let o=new Error(`Invalid ${e.label} at ${e.path}: ${i.prettifyError(n.error)}`);if(!ee(r)||e.mtimeMs===null)throw o;let s=await V({...e,mtimeMs:e.mtimeMs},r,t,{schema:re});switch(s.kind){case"migrated":return s.data;case"ci-gated":throw Fe(o);case"not-applicable":throw o;default:return F(s)}},xr=e=>[`"mcp" is not allowed in ${e.label} (${e.path}): it feeds the committed .mcp.json, so a per-machine copy would replace the project's servers for everyone.`,"Move the block to the project infra-kit.json and run `infra-kit setup`.","For a machine-only override of one server (e.g. a local fork), use Claude Code directly:"," claude mcp add --scope local <name> -- ik-mcp --name <name> --env <VAR> ... -- <command> <args>","(local scope shadows the project entry by name; `claude mcp list` will show a same-name conflict warning, which is expected)."].join(`
1
+ import{a as ce}from"./chunk-MFAFQVTW.js";import{a as ae}from"./chunk-SLBZUXXO.js";import{d as _,p as ie,q as se}from"./chunk-QSTGO43H.js";import Ue from"node:process";import qe from"pino";import He from"pino-pretty";var Je=["token","*.token","serviceToken","*.serviceToken","DOPPLER_TOKEN","*.DOPPLER_TOKEN","INFRA_KIT_ENV_TOKEN","*.INFRA_KIT_ENV_TOKEN"],Xe=()=>{let e=Ue.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),qe({level:e,redact:Je},He({destination:2,ignore:t.join(","),colorize:!0,sync:!0}))},L=Xe();import re from"node:fs/promises";import $e from"node:os";import A from"node:path";import Bt from"node:process";import{z as i}from"zod";import Qe from"node:process";import Ye from"node:process";var $={enabled:!1},Ze=(e,t=r=>{Ye.stdout.write(r)})=>($.enabled&&e&&e.structuredContent!=null&&t(`${JSON.stringify(e.structuredContent,null,2)}
2
+ `),e),pe=e=>{e.options.some(r=>r.long==="--json")||e.option("--json","Output the structured result as JSON on stdout (human logs stay on stderr)"),e.commands.forEach(pe)};var ue={source:null},P=()=>ue.source!==null,et=()=>P()||$.enabled,K=()=>!!Qe.env.CI,tt=({env:e,stdinIsTTY:t,flag:r})=>{if(r)return"flag";let n=e.INFRA_KIT_AGENT;return n==="1"||e.CLAUDECODE!==void 0&&!t&&n!=="0"?"env":null};var F=e=>{throw new Error(`Unexpected value: ${JSON.stringify(e)}`)};var w=(e,t)=>Object.fromEntries(Object.entries(e).filter(([r])=>r!==t));var S=({key:e,id:t,note:r})=>({id:t,note:r,apply:n=>e in n?{changed:!0,result:w(n,e)}:{changed:!1,result:n}});var le=S({key:"devProxy",id:"drop-dev-proxy-key",note:'the retired "devProxy" key (dev URLs are port-free https://<release>.<package>.localhost)'});var de=S({key:"envAutoLoad",id:"drop-env-auto-load-key",note:'the retired "envAutoLoad" key (env auto-load is gone \u2014 run `env-load -c <config>` in the terminal)'});var me=S({key:"environments",id:"drop-environments-key",note:`the retired "environments" key (deploy targets now come from each workflow's workflow_dispatch options, auth from the token store)`});var rt=e=>{let t=e.ide;if(t===null||typeof t!="object")return{changed:!1,result:e};let r=!1,n=s=>{if(s===null||typeof s!="object"||!("config"in s))return s;let a=s.config;return a===null||typeof a!="object"||!("mode"in a)?s:(r=!0,{...s,config:w(a,"mode")})},o=Array.isArray(t)?t.map(n):n(t);return r?{changed:!0,result:{...e,ide:o}}:{changed:!1,result:e}},ge={id:"strip-legacy-ide-mode",note:'legacy "mode"',apply:rt};var nt="zed",fe=e=>e!==null&&typeof e=="object"&&e.provider===nt,ot=e=>{let t=e.ide;if(Array.isArray(t)){let r=t.filter(n=>!fe(n));return r.length===t.length?{changed:!1,result:e}:{changed:!0,result:r.length>0?{...e,ide:r}:w(e,"ide")}}return fe(t)?{changed:!0,result:w(e,"ide")}:{changed:!1,result:e}},he={id:"strip-retired-zed-ide",note:'the retired "zed" provider',apply:ot};var W=[ge,he,me,le,de];var C=e=>W.reduce((t,r)=>{let n=r.apply(t.result);return n.changed?{changed:!0,result:n.result,notes:[...t.notes,r.note]}:t},{changed:!1,result:e,notes:[]});import it from"node:fs/promises";import st from"node:os";var at=async e=>{try{return await it.access(e),!0}catch{return!1}},G=e=>{let t=st.homedir();return e.startsWith(t)?`~${e.slice(t.length)}`:e};import{randomBytes as ct}from"node:crypto";import v from"node:fs/promises";import B from"node:path";import pt from"node:process";var D=class extends Error{constructor(t){super(`${t} changed on disk since it was read`),this.name="ConfigFileChangedError"}},ut=2,lt=e=>/^([ \t]+)\S/m.exec(e)?.[1]??ut,dt=4095,O=async({path:e,raw:t,migrated:r,expectedMtimeMs:n})=>{let o=await v.realpath(e),s=B.dirname(o),a=B.basename(o),p=B.join(s,`.${a}.${pt.pid}.${ct(4).toString("hex")}.tmp`),l=`${JSON.stringify(r,null,lt(t))}
3
+ `;try{await v.writeFile(p,l,"utf8");let d=await v.stat(o);if(d.mtimeMs!==n)throw new D(e);await v.chmod(p,d.mode&dt),await v.rename(p,o)}catch(d){throw await v.rm(p,{force:!0}),d}},mt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),gt=async e=>{let t=await v.stat(e),r=await v.readFile(e,"utf8");if(r.trim()==="")return{changed:!1,result:{},notes:[],path:e};let n=JSON.parse(r);if(!mt(n))return{changed:!1,result:{},notes:[],path:e};let o=C(n);return o.changed&&await O({path:e,raw:r,migrated:o.result,expectedMtimeMs:t.mtimeMs}),{...o,path:e}};var V=async(e,t,r,{schema:n})=>{if(e.autoMigrate==="off")return{kind:"not-applicable"};let o=C(t);if(!o.changed)return{kind:"not-applicable"};let s=n.safeParse(o.result);if(!s.success)return{kind:"not-applicable"};if(e.required&&K())return{kind:"ci-gated"};try{await O({path:e.path,raw:r,migrated:o.result,expectedMtimeMs:e.mtimeMs})}catch(a){return L.debug(a,`auto-migration could not rewrite ${e.path}`),{kind:"not-applicable"}}return L.warn(`Migrated ${G(e.path)}: removed ${o.notes.join(" and ")} (retired by infra-kit ${ae.version})`),{kind:"migrated",data:s.data}};import E from"node:path";import be from"node:process";import{$ as m}from"zx";var I=e=>{let t=new Set,r=e;for(;r!==null&&typeof r=="object"&&!t.has(r);){t.add(r);let{stderr:n,stderrExcerpt:o}=r;if(typeof n=="string"&&n.length>0)return n;if(typeof o=="string"&&o.length>0)return o;r=r.cause}},ft=(e,t)=>{let r=t.stderrExcerpt??I(e),n=[`failed to ${t.operation}`];return r&&n.push(`stderr: ${r.slice(0,200).trim()}`),t.remediation&&n.push(`try: ${t.remediation}`),n.join(" \u2014 ")},g=class extends Error{operation;remediation;stderrExcerpt;constructor(t,r){super(ft(t,r),{cause:t}),this.name="OperationError",this.operation=r.operation,this.remediation=r.remediation,this.stderrExcerpt=r.stderrExcerpt??I(t)}};var ht=/^v?(\d+)\.(\d+)\.(\d+)$/,yt=/^(\d+)\.(\d+)\.(\d+)$/,vt=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,T="release/",z="release/v",ye="refs/heads/",kt="next";var ve=new Set(["dev","main","next","hotfix","regular","release"]),x=class extends Error{constructor(t){super(t),this.name="InvalidReleaseNameError"}},b=class extends Error{constructor(t){super(t),this.name="InvalidReleaseRefError"}},we=e=>e.startsWith(ye)?e.slice(ye.length):e,xe=(e,t,r)=>({kind:"version",semver:{major:e,minor:t,patch:r},raw:`${e}.${t}.${r}`}),U=e=>{if(e.length===0)throw new x('Release name is empty. Provide a kebab-case name like "checkout-redesign".');if(e.length>50)throw new x(`Release name "${e}" is ${e.length} characters; the maximum is 50.`);if(!vt.test(e))throw new x(`Release name "${e}" is not kebab-case. Use lowercase letters, digits, and single hyphens, e.g. "checkout-redesign".`);if(ve.has(e))throw new x(`Release name "${e}" is reserved. Reserved names: ${[...ve].join(", ")}.`)},q=e=>{let t=we(e.trim());if(!t.startsWith(T))return null;if(t.startsWith(z)){let n=t.slice(z.length),o=yt.exec(n);if(o)return xe(Number(o[1]),Number(o[2]),Number(o[3]))}let r=t.slice(T.length);try{U(r)}catch{return null}return{kind:"name",name:r,raw:r}},wt=e=>{let t=e.trim();if(we(t).startsWith(T)){let o=q(t);if(!o)throw new b(`"${e}" looks like a release branch but is not a valid release/v<semver> or release/<name> ref.`);return o}let n=ht.exec(t);if(n)return xe(Number(n[1]),Number(n[2]),Number(n[3]));if(t.toLowerCase()===kt)throw new b('The "next" token must be resolved to a concrete version (via computeNextVersion) before parsing a release ref.');if(t.includes("@"))throw new b(`Cannot parse "${e}" as a release ref: the \`@date\` suffix belongs to \`release create\`; pass the version alone here and use \`--release-date\` on \`release edit\``);try{U(t)}catch(o){let s=o instanceof Error?o.message:String(o);throw new b(`Cannot parse "${e}" as a release ref: ${s}`)}return{kind:"name",name:t,raw:t}},xt=e=>e.kind==="version"?`${z}${e.raw}`:`${T}${e.name}`,bt=(e,t)=>{let r=t==="hotfix"?"Hotfix":"Release";return e.kind==="version"?`${r} v${e.raw}`:`${r} ${e.name}`},Rt=e=>e.kind==="version"?`Release v${e.raw} (RC)`:`Release ${e.name} (RC)`,Pt=e=>e.kind==="version"?`v${e.raw}`:e.name,St=e=>e.raw,H=e=>e==null?!1:q(e)!==null,ke=e=>{if(e===void 0)return null;let t=e instanceof Date?e.getTime():new Date(e).getTime();return Number.isNaN(t)?null:t},Et=(e,t,r)=>{if(e.kind==="version"&&t.kind==="version")return e.semver.major!==t.semver.major?e.semver.major-t.semver.major:e.semver.minor!==t.semver.minor?e.semver.minor-t.semver.minor:e.semver.patch-t.semver.patch;if(e.kind==="version")return-1;if(t.kind==="version")return 1;let n=ke(r?.a),o=ke(r?.b);return n!==null&&o!==null&&n!==o?n-o:e.name<t.name?-1:e.name>t.name?1:0};var Re=async e=>{let t=await m({cwd:e})`git worktree list --porcelain`,r=[],n=null;for(let o of t.stdout.split(`
4
+ `)){if(o.startsWith("worktree ")){n&&r.push(n),n={path:o.slice(9),branch:null,detached:!1,bare:!1,prunable:!1,locked:!1};continue}n&&(o.startsWith("branch ")?n.branch=o.slice(7).replace(/^refs\/heads\//,""):o==="detached"?n.detached=!0:o==="bare"?n.bare=!0:o==="locked"||o.startsWith("locked ")?n.locked=!0:(o==="prunable"||o.startsWith("prunable "))&&(n.prunable=!0))}return n&&r.push(n),r},Ct=async e=>{let t=await Re(be.cwd()),r=n=>e==="release"?H(n):n.startsWith("feature/");return t.map(n=>n.branch).filter(n=>n!==null&&r(n))},It=e=>{let t=I(e);return t&&/not a git repository/i.test(t)?"not a git repository":void 0},Mt=({hasStderr:e})=>{if(P())return"infra-kit resolves its project from the working directory; run it from inside an infra-kit project repo (or one of its git worktrees), or pass `-C <dir>` naming one";let t="run infra-kit from inside an infra-kit project repo (or one of its git worktrees)";return e?`${t}; if you are already in one, the stderr in this message is the real cause`:t},M=async()=>{try{return(await m({quiet:!0})`git rev-parse --show-toplevel`).stdout.trim()}catch(e){let t=It(e)??I(e);throw new g(e,{operation:`resolve the project root from ${be.cwd()}`,stderrExcerpt:t,remediation:Mt({hasStderr:t!==void 0})})}},J=async e=>{let t=e??await M(),r=(await m({cwd:t,quiet:!0})`git rev-parse --git-common-dir`).stdout.trim(),n=E.resolve(t,r);return n.includes(`${E.sep}.git${E.sep}modules${E.sep}`)?t:E.dirname(n)},Pe=async()=>(await m`git rev-parse --abbrev-ref HEAD`).stdout.trim(),Se=async()=>(await m`git status --porcelain`).stdout.split(`
5
+ `).map(t=>t.trimEnd()).filter(t=>t.trim().length>0),jt=async()=>(await Se()).length===0,At=async()=>{let e=await M(),[t,r]=await Promise.all([m({cwd:e})`git rev-parse --absolute-git-dir`,m({cwd:e})`git rev-parse --git-common-dir`]),n=t.stdout.trim(),o=E.resolve(e,r.stdout.trim());return n!==o};var $t=async e=>(await m`git branch --list ${e}`).stdout.trim().length>0,Dt=async e=>{(await m`git branch --list ${e}`).stdout.trim().length!==0&&await Pe()!==e&&await m`git branch -D ${e}`},Ot=async e=>{(await m`git ls-remote --heads origin ${e}`).stdout.trim().length!==0&&await m`git push origin --delete ${e}`};import{$ as N}from"zx";var Tt=async(e,t)=>{let r=`${t}^{commit}`;try{return(await N({cwd:e,quiet:!0})`git rev-parse --verify --quiet ${r}`).stdout.trim()||null}catch{return null}},Nt=async(e,t,r)=>{try{return await N({cwd:e,quiet:!0})`git merge-base --is-ancestor ${t} ${r}`,!0}catch(n){if(n.exitCode===1)return!1;throw new g(n,{operation:`test whether ${t} is contained in ${r}`,remediation:"both refs must exist \u2014 verify them with rev-parse first"})}},_t=async(e,t)=>{let n=(await N({cwd:e,quiet:!0})`git ls-remote --heads origin ${t}`).stdout.trim().split(`
6
+ `)[0];return n?n.split(/\s+/)[0]??null:null},Lt=async(e,t)=>{let r=t.map(n=>`${n.sha}:refs/heads/${n.branch}`);if(r.length===0)return{refspecs:r,pushed:!1};try{return await N({cwd:e,quiet:!0})`git push --atomic origin ${r}`,{refspecs:r,pushed:!0}}catch(n){return{refspecs:r,pushed:!1,stderr:n.stderr}}};import Y from"node:path";import X from"node:process";import{$ as h}from"zx";var Ee=async e=>{let t=e??X.cwd(),r=(await h({cwd:t,quiet:!0})`git rev-parse --git-common-dir`).stdout.trim(),n=X.env.INFRA_KIT_SESSION||String(X.pid);return Y.join(Y.resolve(t,r),"infra-kit",`merge-dev-${n}`)},Ce=e=>e.replace(/[^\w-]+/g,"-"),Kt=(e,t)=>Y.join(`${e}${ie}`,se.mergeDev,Ce(t)),Z=async e=>{try{return await h({cwd:e,quiet:!0})`git rev-parse -q --verify MERGE_HEAD`,!0}catch{return!1}},Ft=async e=>{if(await Z(e))throw new g(void 0,{operation:"reuse the scratch worktree",stderrExcerpt:"a merge is still in progress in the scratch worktree",remediation:"this is an infra-kit bug \u2014 the previous branch iteration did not clean up"});let t=(await h({cwd:e,quiet:!0})`git status --porcelain`).stdout.trim();if(t.length>0)throw new g(void 0,{operation:"reuse the scratch worktree",stderrExcerpt:`scratch worktree is dirty: ${t.split(`
7
+ `)[0]}`,remediation:"this is an infra-kit bug \u2014 the previous branch iteration did not clean up"})},Wt=async e=>{let t=async r=>{try{await r()}catch{}};await Z(e)&&await t(()=>h({cwd:e,quiet:!0})`git merge --abort`),await t(()=>h({cwd:e,quiet:!0})`git reset --hard`),await t(()=>h({cwd:e,quiet:!0})`git clean -fd`)},Gt=async(e,t)=>{let{cwd:r,anchor:n="origin/dev"}=e,o=await Ee(r),s=async()=>{await h({cwd:r,quiet:!0})`git worktree add --detach ${o} ${n}`};try{await s()}catch(p){try{await h({cwd:r,quiet:!0})`git worktree prune`,await s()}catch{throw new g(p,{operation:"create the scratch worktree for the merge",remediation:`remove any stale checkout at ${o}, then retry`})}}let a={path:o,remove:async()=>{try{await h({cwd:r,quiet:!0})`git worktree remove --force ${o}`}catch{}}};try{return await t(a)}finally{await a.remove()}};var Ie="infra-kit.json";var Vt="infra-kit.json",zt="projects",Ut=i.object({provider:i.literal("doppler"),config:i.object({name:i.string().min(1)})}),qt=i.discriminatedUnion("provider",[Ut]),Ht=i.object({workspaceConfigPath:i.string().min(1)}).strict(),Jt=i.object({provider:i.literal("cursor"),config:Ht}).strict(),Me=i.discriminatedUnion("provider",[Jt]),Xt=i.union([Me,i.array(Me).min(1)]),Yt=i.object({provider:i.literal("jira"),config:i.object({baseUrl:i.string().url(),projectId:i.number().int().positive()})}),Zt=i.discriminatedUnion("provider",[Yt]),Qt=["two-columns","three-pane"],er=i.object({layout:i.enum(Qt).optional()}).strict(),tr=i.object({openInGithubDesktop:i.boolean().optional(),openInOrca:i.boolean().optional(),orca:er.optional()}).strict(),rr=i.object({port:i.number().int().positive().optional(),prefixUrl:i.string().min(1).optional()}).strict(),nr=i.record(i.string().min(1),rr),or=i.enum(["local","cloud"]),ir=i.object({watchDeps:i.boolean().optional(),proxy:i.record(i.string().min(1),or).optional()}).strict(),sr=i.object({apps:i.record(i.string().min(1),ir).optional(),orca:i.boolean().optional()}).strict(),ar=i.record(i.string().min(1),sr),cr=i.enum(["disallow","allow","cli-only"]),je=i.string().regex(/^[A-Z_]\w*$/i,"must be a POSIX environment-variable name"),pr=i.object({command:i.string().min(1),args:i.array(i.string()).default([]),env:i.array(je).min(1),unset:i.array(je).default([])}).strict().superRefine((e,t)=>{for(let r of e.env)ce.has(r)&&t.addIssue({code:"custom",path:["env"],message:`"${r}" is process plumbing the proxy never strips or injects \u2014 it cannot be a credential name`})}),ur=i.record(i.string().regex(/^[a-z][a-z0-9-]*$/,"must be lowercase letters, digits and hyphens, starting with a letter").refine(e=>!e.includes("infra-kit"),{message:'"infra-kit" is reserved: it is the .mcp.json key of the retired infra-kit MCP server \u2014 pick another name'}),pr),Ae=i.string().min(1).superRefine((e,t)=>{if(e.startsWith("/")||e.startsWith("\\")||/^[a-z]:/i.test(e)){t.addIssue({code:"custom",message:`"${e}" must be relative to the repository root`});return}let r=e.split(/[/\\]/).filter(o=>o!==""&&o!==".");r.includes("..")&&t.addIssue({code:"custom",message:`"${e}" must not contain a ".." segment`}),r[0]===".git"&&t.addIssue({code:"custom",message:`"${e}" must not be .git or a path inside it`}),e.includes("\\")&&t.addIssue({code:"custom",message:`"${e}" must use "/" as the separator, not "\\"`});let n=e.split("/");n.includes("")&&t.addIssue({code:"custom",message:`"${e}" must not have a trailing or doubled "/"`}),n.includes(".")&&t.addIssue({code:"custom",message:`"${e}" must not contain a "." segment; write it from the repository root, e.g. "vendor/configs"`})}),lr=i.object({path:Ae,target:Ae.optional()}).strict(),De=i.object({copy:i.array(lr).min(1),exclude:i.array(i.string().regex(/^[^/\\]+$/,'must be a single path segment, without "/"')).optional()}).strict(),ne=i.object({envManagement:qt,ide:Xt.optional(),taskManager:Zt.optional(),worktrees:tr.optional(),dev:nr.optional(),devServersPresets:ar.optional(),protectedEnvs:cr.optional(),mcp:ur.optional(),vendorSource:De.nullable().optional()}).strict(),dr=443,Oe=ne.superRefine((e,t)=>{if(!Array.isArray(e.ide))return;let r=new Set;for(let n of e.ide){if(r.has(n.provider)){t.addIssue({code:"custom",message:"each IDE provider may appear at most once",path:["ide"]});return}r.add(n.provider)}}),te=ne.partial(),mr=e=>{let t=e.ide;return t?Array.isArray(t)?t:[t]:[]},Te="two-columns",gr=e=>e.worktrees?.orca?.layout??Te,k=null,j=null,Ne=()=>`${Bt.cwd()} ${$e.homedir()}`,_e=()=>A.join($e.homedir(),_),Le=()=>A.join(_e(),Vt),Ke=async()=>{let e=Ne();if(j&&j.key===e)return j.value;let t=await M(),r=await J(t),n=A.basename(r),o={main:A.join(t,Ie),userGlobal:Le(),userProject:A.join(_e(),zt,n,Ie),projectName:n};return j={key:e,value:o},o},fr=async(e={})=>{let t=e.autoMigrate??"write",r=Ne(),n=await Ke(),o;try{o=await re.stat(n.main)}catch{k=null;let y=n.main.replace(/\.json$/,".yml");throw await Q(y)?new Error(`infra-kit.json not found at ${n.main}. A legacy infra-kit.yml exists \u2014 run \`infra-kit setup --skip-tools\` to convert it.`):new Error(P()?`infra-kit.json not found at ${n.main} \u2014 the working directory is not an infra-kit project. Run infra-kit from inside an infra-kit project repo, or pass \`-C <dir>\` naming one.`:`infra-kit.json not found at ${n.main} \u2014 this git repo is not an infra-kit project. Run \`infra-kit setup --skip-tools\` here to create it, cd into an infra-kit project repo, or check out a branch that has infra-kit.json.`)}let[s,a]=await Promise.all([Q(n.userGlobal),Q(n.userProject)]),p={main:Number(o.mtimeMs),userGlobal:s?Number(s.mtimeMs):null,userProject:a?Number(a.mtimeMs):null};if(k&&k.key===r&&kr(k.mtimes,p))return k.value;let l=[{label:"infra-kit.json",path:n.main,required:!0,autoMigrate:t,mtimeMs:p.main},{label:"~/.infra-kit/infra-kit.json",path:n.userGlobal,required:!1,autoMigrate:t,mtimeMs:p.userGlobal},{label:`~/.infra-kit/projects/${n.projectName}/infra-kit.json`,path:n.userProject,required:!1,autoMigrate:t,mtimeMs:p.userProject}],d={};for(let y of l){let R=await wr(y);R!==null&&(d={...d,...R})}let f=Oe.safeParse(d);if(!f.success)throw new Error(`Invalid merged infra-kit config: ${i.prettifyError(f.error)}`);return k={key:r,mtimes:p,value:f.data},f.data},hr=()=>{k=null},yr=()=>{k=null,j=null},Q=async e=>{try{return await re.stat(e)}catch{return null}},vr=async e=>{try{return await re.readFile(e,"utf-8")}catch{return null}},kr=(e,t)=>{let r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(n=>e[n]===t[n])},Fe=e=>new Error(`${e.message}
8
+ A retired key on this branch \u2014 run \`infra-kit setup --skip-tools\` in this checkout and commit infra-kit.json.`),wr=async e=>{let t=await vr(e.path);if(t===null){if(e.required)throw new Error(`${e.label} not found at ${e.path}`);return null}let r;try{r=t.trim()===""?{}:JSON.parse(t)}catch(a){throw new Error(`Invalid JSON in ${e.label} at ${e.path}: ${a.message}`)}if(ee(r)&&"envTokens"in r)throw new Error(Sr(e));!e.required&&ee(r)&&Pr(e,r);let n=te.safeParse(r);if(n.success)return n.data;let o=new Error(`Invalid ${e.label} at ${e.path}: ${i.prettifyError(n.error)}`);if(!ee(r)||e.mtimeMs===null)throw o;let s=await V({...e,mtimeMs:e.mtimeMs},r,t,{schema:te});switch(s.kind){case"migrated":return s.data;case"ci-gated":throw Fe(o);case"not-applicable":throw o;default:return F(s)}},xr=e=>[`"mcp" is not allowed in ${e.label} (${e.path}): it feeds the committed .mcp.json, so a per-machine copy would replace the project's servers for everyone.`,"Move the block to the project infra-kit.json and run `infra-kit setup`.","For a machine-only override of one server (e.g. a local fork), use Claude Code directly:"," claude mcp add --scope local <name> -- ik-mcp --name <name> --env <VAR> ... -- <command> <args>","(local scope shadows the project entry by name; `claude mcp list` will show a same-name conflict warning, which is expected)."].join(`
9
9
  `),br=e=>[`"vendorSource" is not allowed in ${e.label} (${e.path}): only the committed project file may mark a repository as the \`vendor sync\` source. In the machine-wide file it would make every repository on this machine a source; in a per-project override it would make this machine disagree with every other clone.`,"Move the block to the source repository's own infra-kit.json and commit it there."].join(`
10
10
  `),Rr={mcp:xr,vendorSource:br},Pr=(e,t)=>{for(let[r,n]of Object.entries(Rr))if(r in t)throw new Error(n(e))},ee=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Sr=e=>[`Refusing to load ${e.label} \u2014 \`envTokens\` is not a config key.`,"A service token in a config file can be committed, backed up by your editor, or shared."," 1. REVOKE the token in Doppler now \u2014 treat it as compromised.",` 2. Remove the \`envTokens\` key from ${e.path}.`," 3. Re-add it privately: `infra-kit env-token-set <env>`"," (it is written to ~/.infra-kit/projects/<repo>/tokens.json, mode 0600, never to the repo)."].join(`
11
- `);import*as u from"node:fs";import*as c from"node:path";function Er(e){let t=e;for(let r=0;r<10;r++){let n=c.join(t,"pnpm-workspace.yaml");if(u.existsSync(n))return t;t=c.dirname(t)}throw new Error("Could not find monorepo root (pnpm-workspace.yaml)")}function Ge(e,t){let r=c.join(e,"package.json");if(!u.existsSync(r))return t;try{let n=JSON.parse(u.readFileSync(r,"utf-8"));return typeof n.name=="string"?n.name:t}catch{return t}}function Oo(e){let t=c.join(e,"apps"),r=[];if(!u.existsSync(t))throw new Error(`Apps directory not found: ${t}`);let n=u.readdirSync(t,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);for(let o of n){let s=c.join(t,o,"api"),a=c.join(s,"serverless.yml");u.existsSync(a)&&r.push({name:o,packageName:Ge(s,o),path:s})}return r}var Be=["vite.config.ts","vite.config.mts","vite.config.cts","vite.config.js","vite.config.mjs","vite.config.cjs"],Cr=["@slip-stream-kit/vite","@slip-stream-kit/config/vite","infra-kit/vite"];function Ir(e){for(let t of Be){let r=c.join(e,t);if(u.existsSync(r))try{let n=u.readFileSync(r,"utf-8");return Cr.some(o=>n.includes(o))}catch{return!1}}return!1}function To(e){for(let t of Be){let r=c.join(e,t);if(u.existsSync(r))try{return u.readFileSync(r,"utf-8").includes("infraKit(")}catch{return!1}}return!1}function Mr(e){let t=c.join(e,"package.json");if(!u.existsSync(t))return!1;try{let r=JSON.parse(u.readFileSync(t,"utf-8"));return typeof r.scripts?.dev=="string"&&r.scripts.dev.length>0}catch{return!1}}function No(e){let t=c.join(e,"apps"),r=[];if(!u.existsSync(t))return r;let n=u.readdirSync(t,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);for(let o of n){let s=c.join(t,o,"ui");u.existsSync(s)&&Mr(s)&&r.push({name:o,packageName:Ge(s,o),path:s,managedPort:Ir(s)})}return r}function _o(e){let t=e?.filter(Boolean)??[];return t.length>0?t:null}function Lo(e){let t=Er(e),r=c.relative(c.join(t,"apps"),e),n=r.split(c.sep)[0];if(r===""||r.startsWith("..")||c.isAbsolute(r)||!n)throw new Error(`--self: not inside an apps/<app> directory (cwd: ${e}). Run from an app folder or use --app=<name>.`);return n}var jr=new Set(["api","ui"]),We=e=>{let t=c.join(e,"dist");return u.existsSync(t)&&u.statSync(t).isDirectory()?t:void 0},ie=e=>u.existsSync(e)?u.readdirSync(e,{withFileTypes:!0}).filter(t=>t.isDirectory()).map(t=>t.name):[];function Ko(e){let t=[];for(let n of ie(c.join(e,"packages"))){let o=We(c.join(e,"packages",n));o!==void 0&&t.push(o)}let r=c.join(e,"apps");for(let n of ie(r))for(let o of ie(c.join(r,n))){if(jr.has(o))continue;let s=c.join(r,n,o);if(!u.existsSync(c.join(s,"package.json")))continue;let a=We(s);a!==void 0&&t.push(a)}return t}function Fo(e){return e.map(t=>c.join(t.path,"dist")).filter(t=>u.existsSync(t))}function Wo(e,t,r){let n=c.normalize(e),o=p=>{let l=c.normalize(p);return n===l||n.startsWith(l+c.sep)},s=r.find(o);return s?{kind:"package",packageDir:s}:{kind:"app",app:t.find(o)}}var Ar={"*/api":{},"*/ui":{}},ze=e=>{let t=e.split("/"),[r,n]=t;return t.length!==2||!r?`devServersPresets: invalid target "${e}" (expected "<app>/api" or "<app>/ui")`:n!=="api"&&n!=="ui"?`devServersPresets: invalid target part "${n}" in "${e}" (expected "api" or "ui")`:null},$r=e=>{let t=ze(e);if(t)throw new Error(t);let[r,n]=e.split("/");return{appGlob:r,part:n}},Bo=e=>{let t=[];for(let[r,n]of Object.entries(e))for(let o of Object.keys(n.apps??{})){let s=ze(o);s&&t.push({preset:r,key:o,message:`preset "${r}": ${s}`})}return t},Dr=(e,t)=>t==="api"?e.api:e.ui,Or=e=>[...new Set([...e.api,...e.ui])].sort(),Ve=(e,t)=>`${e}/${t}`,Tr=e=>e?0:1,Nr=(e,t)=>t.watchDeps===void 0?e??{watchDeps:!0,rank:t.rank,explicitValue:!1}:!e||!e.explicitValue?{watchDeps:t.watchDeps,rank:t.rank,explicitValue:!0}:t.rank>e.rank?{watchDeps:t.watchDeps,rank:t.rank,explicitValue:!0}:e,_r=(e,t,r)=>{let{app:n,part:o,watchDeps:s,isGlob:a}=r;if(!Dr(t,o).includes(n)){a||e.unmatched.push(Ve(n,o));return}let p=Ve(n,o),l=Nr(e.targets.get(p),{watchDeps:s,rank:Tr(a)});e.targets.set(p,{app:n,part:o,...l})},Lr=(e,t)=>{let r=Object.entries(e.apps??Ar),n={targets:new Map,proxy:{},unmatched:[]};for(let[a,p]of r){let{appGlob:l,part:d}=$r(a),f=l==="*",y=f?Or(t):[l];for(let R of y)_r(n,t,{app:R,part:d,watchDeps:p.watchDeps,isGlob:f}),p.proxy&&(n.proxy[R]={...n.proxy[R]??{},...p.proxy})}let o=[...n.targets.values()].map(({app:a,part:p,watchDeps:l})=>({app:a,part:p,watchDeps:l})),s=[...new Set(o.filter(a=>a.part==="api").map(a=>a.app))];return{targets:o,orca:e.orca??!1,proxy:n.proxy,localApps:s,unmatched:n.unmatched}},Vo=e=>{if(e.preset!=null)return e.preset;if(e.running.length===0)return"nothing";let t=new Set(e.running);return e.discovered.every(n=>t.has(n))?"*":[...t].sort().join(" + ")},Kr=(e,t)=>Object.keys(e).find(r=>e[r]===t),Fr=({preset:e,app:t,route:r,launchedPkgs:n,ctx:o})=>{let s=o.routePkg(t,r);if(s===void 0)return{preset:e,app:t,route:r,kind:"unknown-route",message:`preset "${e}": proxy override "${r}" on "${t}" names a route not declared in ${t}'s infra-kit.config.ts dev.proxy.routes`};if(n.has(s))return null;let a=Kr(o.apiPkgByApp,s),p=a?`add "${a}/api" to the preset`:`launch the api whose package is "${s}"`;return{preset:e,app:t,route:r,pkg:s,kind:"backend-not-launched",message:`preset "${e}": proxy override "${r}" \u2192 "local" requires backend "${s}" to run locally, but the preset does not launch it \u2014 ${p}, or set "${r}" to "cloud"`}},zo=(e,t)=>{let r=[];for(let[n,o]of Object.entries(e)){let s=Lr(o,t.discovered),a=new Set(s.localApps.map(p=>t.apiPkgByApp[p]).filter(p=>p!==void 0));for(let[p,l]of Object.entries(s.proxy))for(let[d,f]of Object.entries(l)){if(f!=="local")continue;let y=Fr({preset:n,app:p,route:d,launchedPkgs:a,ctx:t});y&&r.push(y)}}return r};export{$ as a,Ze as b,ue as c,le as d,P as e,et as f,tt as g,I as h,g as i,x as j,U as k,q as l,wt as m,xt as n,bt as o,Rt as p,Pt as q,St as r,H as s,Et as t,Pe as u,Ct as v,M as w,J as x,Se as y,Ee as z,jt as A,At as B,$t as C,Dt as D,Ot as E,Tt as F,Nt as G,_t as H,Lt as I,Ie as J,Kt as K,Z as L,Ft as M,Wt as N,Gt as O,L as P,F as Q,at as R,G as S,D as T,gt as U,dr as V,Oe as W,re as X,mr as Y,gr as Z,Le as _,Ke as $,fr as aa,hr as ba,yr as ca,Er as da,Oo as ea,To as fa,No as ga,_o as ha,Lo as ia,Ko as ja,Fo as ka,Wo as la,ze as ma,Bo as na,Lr as oa,Vo as pa,zo as qa};
12
- //# sourceMappingURL=chunk-666XR52E.js.map
11
+ `);import*as u from"node:fs";import*as c from"node:path";function Er(e){let t=e;for(let r=0;r<10;r++){let n=c.join(t,"pnpm-workspace.yaml");if(u.existsSync(n))return t;t=c.dirname(t)}throw new Error("Could not find monorepo root (pnpm-workspace.yaml)")}function Ge(e,t){let r=c.join(e,"package.json");if(!u.existsSync(r))return t;try{let n=JSON.parse(u.readFileSync(r,"utf-8"));return typeof n.name=="string"?n.name:t}catch{return t}}function Oo(e){let t=c.join(e,"apps"),r=[];if(!u.existsSync(t))throw new Error(`Apps directory not found: ${t}`);let n=u.readdirSync(t,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);for(let o of n){let s=c.join(t,o,"api"),a=c.join(s,"serverless.yml");u.existsSync(a)&&r.push({name:o,packageName:Ge(s,o),path:s})}return r}var Be=["vite.config.ts","vite.config.mts","vite.config.cts","vite.config.js","vite.config.mjs","vite.config.cjs"],Cr=["@slip-stream-kit/vite","@slip-stream-kit/config/vite","infra-kit/vite"];function Ir(e){for(let t of Be){let r=c.join(e,t);if(u.existsSync(r))try{let n=u.readFileSync(r,"utf-8");return Cr.some(o=>n.includes(o))}catch{return!1}}return!1}function To(e){for(let t of Be){let r=c.join(e,t);if(u.existsSync(r))try{return u.readFileSync(r,"utf-8").includes("infraKit(")}catch{return!1}}return!1}function Mr(e){let t=c.join(e,"package.json");if(!u.existsSync(t))return!1;try{let r=JSON.parse(u.readFileSync(t,"utf-8"));return typeof r.scripts?.dev=="string"&&r.scripts.dev.length>0}catch{return!1}}function No(e){let t=c.join(e,"apps"),r=[];if(!u.existsSync(t))return r;let n=u.readdirSync(t,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);for(let o of n){let s=c.join(t,o,"ui");u.existsSync(s)&&Mr(s)&&r.push({name:o,packageName:Ge(s,o),path:s,managedPort:Ir(s)})}return r}function _o(e){let t=e?.filter(Boolean)??[];return t.length>0?t:null}function Lo(e){let t=Er(e),r=c.relative(c.join(t,"apps"),e),n=r.split(c.sep)[0];if(r===""||r.startsWith("..")||c.isAbsolute(r)||!n)throw new Error(`--self: not inside an apps/<app> directory (cwd: ${e}). Run from an app folder or use --app=<name>.`);return n}var jr=new Set(["api","ui"]),We=e=>{let t=c.join(e,"dist");return u.existsSync(t)&&u.statSync(t).isDirectory()?t:void 0},oe=e=>u.existsSync(e)?u.readdirSync(e,{withFileTypes:!0}).filter(t=>t.isDirectory()).map(t=>t.name):[];function Ko(e){let t=[];for(let n of oe(c.join(e,"packages"))){let o=We(c.join(e,"packages",n));o!==void 0&&t.push(o)}let r=c.join(e,"apps");for(let n of oe(r))for(let o of oe(c.join(r,n))){if(jr.has(o))continue;let s=c.join(r,n,o);if(!u.existsSync(c.join(s,"package.json")))continue;let a=We(s);a!==void 0&&t.push(a)}return t}function Fo(e){return e.map(t=>c.join(t.path,"dist")).filter(t=>u.existsSync(t))}function Wo(e,t,r){let n=c.normalize(e),o=p=>{let l=c.normalize(p);return n===l||n.startsWith(l+c.sep)},s=r.find(o);return s?{kind:"package",packageDir:s}:{kind:"app",app:t.find(o)}}var Ar={"*/api":{},"*/ui":{}},ze=e=>{let t=e.split("/"),[r,n]=t;return t.length!==2||!r?`devServersPresets: invalid target "${e}" (expected "<app>/api" or "<app>/ui")`:n!=="api"&&n!=="ui"?`devServersPresets: invalid target part "${n}" in "${e}" (expected "api" or "ui")`:null},$r=e=>{let t=ze(e);if(t)throw new Error(t);let[r,n]=e.split("/");return{appGlob:r,part:n}},Bo=e=>{let t=[];for(let[r,n]of Object.entries(e))for(let o of Object.keys(n.apps??{})){let s=ze(o);s&&t.push({preset:r,key:o,message:`preset "${r}": ${s}`})}return t},Dr=(e,t)=>t==="api"?e.api:e.ui,Or=e=>[...new Set([...e.api,...e.ui])].sort(),Ve=(e,t)=>`${e}/${t}`,Tr=e=>e?0:1,Nr=(e,t)=>t.watchDeps===void 0?e??{watchDeps:!0,rank:t.rank,explicitValue:!1}:!e||!e.explicitValue?{watchDeps:t.watchDeps,rank:t.rank,explicitValue:!0}:t.rank>e.rank?{watchDeps:t.watchDeps,rank:t.rank,explicitValue:!0}:e,_r=(e,t,r)=>{let{app:n,part:o,watchDeps:s,isGlob:a}=r;if(!Dr(t,o).includes(n)){a||e.unmatched.push(Ve(n,o));return}let p=Ve(n,o),l=Nr(e.targets.get(p),{watchDeps:s,rank:Tr(a)});e.targets.set(p,{app:n,part:o,...l})},Lr=(e,t)=>{let r=Object.entries(e.apps??Ar),n={targets:new Map,proxy:{},unmatched:[]};for(let[a,p]of r){let{appGlob:l,part:d}=$r(a),f=l==="*",y=f?Or(t):[l];for(let R of y)_r(n,t,{app:R,part:d,watchDeps:p.watchDeps,isGlob:f}),p.proxy&&(n.proxy[R]={...n.proxy[R]??{},...p.proxy})}let o=[...n.targets.values()].map(({app:a,part:p,watchDeps:l})=>({app:a,part:p,watchDeps:l})),s=[...new Set(o.filter(a=>a.part==="api").map(a=>a.app))];return{targets:o,orca:e.orca??!1,proxy:n.proxy,localApps:s,unmatched:n.unmatched}},Vo=e=>{if(e.preset!=null)return e.preset;if(e.running.length===0)return"nothing";let t=new Set(e.running);return e.discovered.every(n=>t.has(n))?"*":[...t].sort().join(" + ")},Kr=(e,t)=>Object.keys(e).find(r=>e[r]===t),Fr=({preset:e,app:t,route:r,launchedPkgs:n,ctx:o})=>{let s=o.routePkg(t,r);if(s===void 0)return{preset:e,app:t,route:r,kind:"unknown-route",message:`preset "${e}": proxy override "${r}" on "${t}" names a route not declared in ${t}'s infra-kit.config.ts dev.proxy.routes`};if(n.has(s))return null;let a=Kr(o.apiPkgByApp,s),p=a?`add "${a}/api" to the preset`:`launch the api whose package is "${s}"`;return{preset:e,app:t,route:r,pkg:s,kind:"backend-not-launched",message:`preset "${e}": proxy override "${r}" \u2192 "local" requires backend "${s}" to run locally, but the preset does not launch it \u2014 ${p}, or set "${r}" to "cloud"`}},zo=(e,t)=>{let r=[];for(let[n,o]of Object.entries(e)){let s=Lr(o,t.discovered),a=new Set(s.localApps.map(p=>t.apiPkgByApp[p]).filter(p=>p!==void 0));for(let[p,l]of Object.entries(s.proxy))for(let[d,f]of Object.entries(l)){if(f!=="local")continue;let y=Fr({preset:n,app:p,route:d,launchedPkgs:a,ctx:t});y&&r.push(y)}}return r};export{$ as a,Ze as b,pe as c,ue as d,P as e,et as f,tt as g,I as h,g as i,x as j,U as k,q as l,wt as m,xt as n,bt as o,Rt as p,Pt as q,St as r,H as s,Et as t,Re as u,Ct as v,M as w,J as x,Pe as y,Se as z,jt as A,At as B,$t as C,Dt as D,Ot as E,Tt as F,Nt as G,_t as H,Lt as I,Ce as J,Kt as K,Z as L,Ft as M,Wt as N,Gt as O,L as P,F as Q,at as R,G as S,D as T,gt as U,dr as V,Oe as W,te as X,mr as Y,gr as Z,Le as _,Ke as $,fr as aa,hr as ba,yr as ca,Er as da,Oo as ea,To as fa,No as ga,_o as ha,Lo as ia,Ko as ja,Fo as ka,Wo as la,ze as ma,Bo as na,Lr as oa,Vo as pa,zo as qa};
12
+ //# sourceMappingURL=chunk-GVWC7K7X.js.map