infra-kit 0.1.93 → 0.1.95

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.
Files changed (45) hide show
  1. package/.eslintcache +1 -1
  2. package/.turbo/turbo-eslint-check.log +4 -5
  3. package/.turbo/turbo-prettier-check.log +7 -5
  4. package/.turbo/turbo-test.log +82 -18
  5. package/.turbo/turbo-ts-check.log +10 -5
  6. package/dist/cli.js +37 -34
  7. package/dist/cli.js.map +4 -4
  8. package/dist/mcp.js +30 -27
  9. package/dist/mcp.js.map +4 -4
  10. package/package.json +2 -2
  11. package/src/commands/doctor/doctor.ts +119 -1
  12. package/src/commands/env-clear/env-clear.ts +1 -1
  13. package/src/commands/env-list/env-list.ts +1 -1
  14. package/src/commands/env-load/env-load.ts +1 -1
  15. package/src/commands/env-status/env-status.ts +1 -1
  16. package/src/commands/gh-merge-dev/gh-merge-dev.ts +1 -1
  17. package/src/commands/gh-release-deliver/gh-release-deliver.ts +1 -1
  18. package/src/commands/gh-release-deploy-all/gh-release-deploy-all.ts +1 -1
  19. package/src/commands/gh-release-deploy-selected/gh-release-deploy-selected.ts +1 -1
  20. package/src/commands/gh-release-list/gh-release-list.ts +1 -1
  21. package/src/commands/init/init.ts +3 -3
  22. package/src/commands/release-create/release-create.ts +1 -1
  23. package/src/commands/release-create-batch/release-create-batch.ts +1 -1
  24. package/src/commands/version/version.ts +1 -1
  25. package/src/commands/worktrees-add/index.ts +2 -1
  26. package/src/commands/worktrees-add/worktrees-add.ts +55 -14
  27. package/src/commands/worktrees-list/worktrees-list.ts +1 -1
  28. package/src/commands/worktrees-remove/worktrees-remove.ts +68 -4
  29. package/src/commands/worktrees-sync/worktrees-sync.ts +69 -5
  30. package/src/entry/cli.ts +25 -4
  31. package/src/integrations/clickup/.gitkeep +0 -0
  32. package/src/integrations/cmux/close-workspace-by-title.ts +51 -0
  33. package/src/integrations/cmux/index.ts +2 -0
  34. package/src/integrations/cmux/workspace-title.ts +17 -0
  35. package/src/integrations/cursor/add-folders-to-workspace.ts +84 -0
  36. package/src/integrations/cursor/index.ts +3 -0
  37. package/src/integrations/cursor/remove-folders-from-workspace.ts +93 -0
  38. package/src/integrations/cursor/resolve-workspace-path.ts +13 -0
  39. package/src/integrations/doppler/doppler-project.ts +2 -2
  40. package/src/lib/__tests__/infra-kit-config.test.ts +64 -14
  41. package/src/lib/infra-kit-config/index.ts +2 -0
  42. package/src/lib/infra-kit-config/infra-kit-config.ts +143 -0
  43. package/tsconfig.json +3 -2
  44. package/tsconfig.tsbuildinfo +1 -1
  45. package/src/lib/infra-kit-config.ts +0 -69
package/dist/mcp.js CHANGED
@@ -1,37 +1,40 @@
1
- import{StdioServerTransport as ho}from"@modelcontextprotocol/sdk/server/stdio.js";import Yr from"node:process";import _ from"node:process";import pr from"node:process";import Ie from"pino";import Zr from"pino-pretty";var ee="/tmp/mcp-infra-kit.log",mr=()=>{let e=pr.argv.includes("--debug")?"debug":"info",r=Ie({level:e},Ie.destination({dest:ee}));return r.info(`Logger initialized with level: ${e}. Logging to: ${ee}`),r},Qr=()=>{let e=pr.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),Ie({level:e},Zr({destination:2,ignore:r.join(","),colorize:!0}))},n=Qr();var ur=e=>{_.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),_.exit(0)}),_.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),_.exit(0)}),_.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${ee}. Shutting down...`),e.flush(),_.exit(1)}),_.on("unhandledRejection",(r,o)=>{e.fatal({reason:r,promise:o,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${ee}. Shutting down...`),e.flush(),_.exit(1)})};import{McpServer as fo}from"@modelcontextprotocol/sdk/server/mcp.js";var dr=async e=>{};var fr=async e=>{};import Ne from"node:fs";import gr from"node:path";import tt from"node:process";import{z as Re}from"zod";import re from"node:fs";import et from"node:os";import Se from"node:path";import Ae from"node:process";var V="env-load.sh",hr="env-clear.sh",ge="INFRA_KIT_SESSION",F="INFRA_KIT_ENV_CONFIG",W="INFRA_KIT_ENV_PROJECT",B="INFRA_KIT_ENV_LOADED_AT",ve=/^([A-Z_]\w*)=/i,ye=e=>{if(!re.existsSync(e))return[];let r=re.readFileSync(e,"utf-8"),o=[];for(let s of r.split(`
2
- `)){let t=ve.exec(s);t&&o.push(t[1])}return o},rt=()=>{let e=Ae.env.XDG_CACHE_HOME,r=e&&e.length>0?e:Se.join(et.homedir(),".cache");return Se.join(r,"infra-kit")},q=()=>{let e=Ae.env[ge];if(!e)throw new Error(`${ge} is not set. Run \`infra-kit init\` then \`source ~/.zshrc\`.`);return Se.join(rt(),e)},we=(e,r,o)=>{let s=`${e}.tmp.${Ae.pid}`;re.writeFileSync(s,r,{mode:o});try{re.renameSync(s,e)}catch(t){throw re.rmSync(s,{force:!0}),t}},U="-worktrees";var vr=async()=>{let e=q(),r=gr.join(e,V);if(!Ne.existsSync(r))throw new Error("No loaded environment found. Run `env-load` first.");let o=ye(r),s=[...o.map(a=>`unset ${a}`),`unset ${F}`,`unset ${W}`,`unset ${B}`],t=gr.resolve(e,hr);Ne.mkdirSync(e,{recursive:!0,mode:448}),we(t,`${s.join(`
1
+ import{StdioServerTransport as Bo}from"@modelcontextprotocol/sdk/server/stdio.js";import dt from"node:process";import D from"node:process";import Rr from"node:process";import je from"pino";import gt from"pino-pretty";var se="/tmp/mcp-infra-kit.log",br=()=>{let e=Rr.argv.includes("--debug")?"debug":"info",r=je({level:e},je.destination({dest:se}));return r.info(`Logger initialized with level: ${e}. Logging to: ${se}`),r},vt=()=>{let e=Rr.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),je({level:e},gt({destination:2,ignore:r.join(","),colorize:!0}))},a=vt();var kr=e=>{D.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),D.exit(0)}),D.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),D.exit(0)}),D.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${se}. Shutting down...`),e.flush(),D.exit(1)}),D.on("unhandledRejection",(r,t)=>{e.fatal({reason:r,promise:t,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${se}. Shutting down...`),e.flush(),D.exit(1)})};import{McpServer as Vo}from"@modelcontextprotocol/sdk/server/mcp.js";var xr=async e=>{};var Cr=async e=>{};import Le from"node:fs";import Pr from"node:path";import Rt from"node:process";import{z as Pe}from"zod/v4";import ne from"node:fs";import wt from"node:os";import We from"node:path";import Fe from"node:process";var U="env-load.sh",Tr="env-clear.sh",ke="INFRA_KIT_SESSION",G="INFRA_KIT_ENV_CONFIG",K="INFRA_KIT_ENV_PROJECT",z="INFRA_KIT_ENV_LOADED_AT",xe=/^([A-Z_]\w*)=/i,Ce=e=>{if(!ne.existsSync(e))return[];let r=ne.readFileSync(e,"utf-8"),t=[];for(let s of r.split(`
2
+ `)){let o=xe.exec(s);o&&t.push(o[1])}return t},yt=()=>{let e=Fe.env.XDG_CACHE_HOME,r=e&&e.length>0?e:We.join(wt.homedir(),".cache");return We.join(r,"infra-kit")},H=()=>{let e=Fe.env[ke];if(!e)throw new Error(`${ke} is not set. Run \`infra-kit init\` then \`source ~/.zshrc\`.`);return We.join(yt(),e)},Te=(e,r,t)=>{let s=`${e}.tmp.${Fe.pid}`;ne.writeFileSync(s,r,{mode:t});try{ne.renameSync(s,e)}catch(o){throw ne.rmSync(s,{force:!0}),o}},Y="-worktrees";var $r=async()=>{let e=H(),r=Pr.join(e,U);if(!Le.existsSync(r))throw new Error("No loaded environment found. Run `env-load` first.");let t=Ce(r),s=[...t.map(i=>`unset ${i}`),`unset ${G}`,`unset ${K}`,`unset ${z}`],o=Pr.resolve(e,Tr);Le.mkdirSync(e,{recursive:!0,mode:448}),Te(o,`${s.join(`
3
3
  `)}
4
- `,384),tt.stdout.write(`${t}
5
- `),Ne.unlinkSync(r);let i={filePath:t,variableCount:o.length,unsetStatements:s};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Oe={name:"env-clear",description:'Generate a shell script that unsets every env var previously loaded by env-load for this session, plus the infra-kit session metadata vars. Does NOT mutate the calling process. When `infra-kit init` has installed the zsh shell integration, the user\'s terminal auto-sources the unset script on its next prompt (precmd hook) \u2014 so calling this via MCP will clear the vars in the shell that launched Claude Code automatically. Other callers must source "<filePath>" themselves or surface it to the user. Errors if no env is currently loaded.',inputSchema:{},outputSchema:{filePath:Re.string().describe("Path to the file that must be sourced to apply"),variableCount:Re.number().describe("Number of variables cleared"),unsetStatements:Re.array(Re.string()).describe("Unset statements generated")},handler:vr};import{z as Me}from"zod";import wr from"node:fs/promises";import it from"node:path";import at from"yaml";import{z as $}from"zod";import ot from"node:path";import{$ as yr}from"zx";var O=async e=>{let o=(await yr`git worktree list`).stdout.split(`
6
- `).filter(Boolean),s={release:st,feature:nt};return o.map(s[e]).filter(t=>t!==null)},st=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("release/v")?null:`release/${r[0]?.split("/").pop()||""}`},nt=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},k=async()=>(await yr`git rev-parse --show-toplevel`).stdout.trim(),_e=async()=>{let e=await k();return ot.basename(e)};var ct="infra-kit.yml",lt=$.object({type:$.literal("jira"),baseUrl:$.string().url(),projectId:$.number().int().positive()}),pt=$.object({dopplerProjectName:$.string().min(1),environments:$.array($.string().min(1)).min(1),taskManagerProvider:$.union([$.string(),$.literal(!1),lt])}),te=null,S=async()=>{let e=await k(),r=it.join(e,ct),o;try{o=await wr.stat(r)}catch{throw te=null,new Error(`infra-kit.yml not found at ${r}`)}if(te&&te.mtimeMs===o.mtimeMs)return te.value;let s=await wr.readFile(r,"utf-8"),t=at.parse(s),i=pt.safeParse(t);if(!i.success)throw new Error(`Invalid infra-kit.yml at ${r}: ${i.error.message}`);return te={mtimeMs:o.mtimeMs,value:i.data},i.data};var oe=async()=>{let{dopplerProjectName:e}=await S();return e};var Rr=async()=>{let e=await oe(),{environments:r}=await S();n.info(`Doppler project: ${e}
7
- `),n.info("Available configs:");for(let s of r)n.info(` - ${s}`);let o={project:e,configs:r};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},De={name:"env-list",description:"List the environments the project is configured to support. Returns the `environments` list declared in infra-kit.yml at the project root (not a live fetch from Doppler) plus the Doppler project name resolved from the same file. Read-only.",inputSchema:{},outputSchema:{project:Me.string().describe("Detected Doppler project name"),configs:Me.array(Me.string()).describe("Available environment configs")},handler:Rr};import ut from"@inquirer/select";import{Buffer as dt}from"node:buffer";import ft from"node:fs";import ht from"node:path";import xr from"node:process";import{z as ne}from"zod";import{$ as be}from"zx";import{$ as br}from"zx";var se=async()=>{try{await br`doppler --version`}catch(e){throw new Error("Doppler CLI is not installed. Install it from: https://docs.doppler.com/docs/install-cli",{cause:e})}try{await br`doppler me`}catch(e){throw new Error("Doppler CLI is not authenticated. Run: doppler login",{cause:e})}};var mt=()=>{let e="",r=[],o=!1;return{start(s){e=s,r=[],o=!1},setInteractive(){o=!0},addOption(s,t){r.push({flag:s,value:t})},print(){if(!o||r.length===0)return;let s=r.map(t=>typeof t.value=="boolean"?t.value?t.flag:"":Array.isArray(t.value)?`${t.flag} "${t.value.join(", ")}"`:`${t.flag} "${t.value}"`).filter(Boolean).join(" ");n.info(`\u{1F4DF} Equivalent command:
4
+ `,384),Rt.stdout.write(`${o}
5
+ `),Le.unlinkSync(r);let n={filePath:o,variableCount:t.length,unsetStatements:s};return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}},Ve={name:"env-clear",description:'Generate a shell script that unsets every env var previously loaded by env-load for this session, plus the infra-kit session metadata vars. Does NOT mutate the calling process. When `infra-kit init` has installed the zsh shell integration, the user\'s terminal auto-sources the unset script on its next prompt (precmd hook) \u2014 so calling this via MCP will clear the vars in the shell that launched Claude Code automatically. Other callers must source "<filePath>" themselves or surface it to the user. Errors if no env is currently loaded.',inputSchema:{},outputSchema:{filePath:Pe.string().describe("Path to the file that must be sourced to apply"),variableCount:Pe.number().describe("Number of variables cleared"),unsetStatements:Pe.array(Pe.string()).describe("Unset statements generated")},handler:$r};import{z as Be}from"zod/v4";import $e from"node:fs/promises";import Sr from"node:path";import Ar from"yaml";import{z as g}from"zod/v4";import bt from"node:path";import{$ as Er}from"zx";var M=async e=>{let t=(await Er`git worktree list`).stdout.split(`
6
+ `).filter(Boolean),s={release:kt,feature:xt};return t.map(s[e]).filter(o=>o!==null)},kt=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("release/v")?null:`release/${r[0]?.split("/").pop()||""}`},xt=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},P=async()=>(await Er`git rev-parse --show-toplevel`).stdout.trim(),F=async()=>{let e=await P();return bt.basename(e)};var Ct="infra-kit.yml",Tt="infra-kit.local.yml",Pt=g.object({provider:g.literal("doppler"),config:g.object({name:g.string().min(1)})}),$t=g.discriminatedUnion("provider",[Pt]),Et=g.object({mode:g.enum(["workspace","windows"]).default("workspace"),workspaceConfigPath:g.string().min(1).optional()}).refine(e=>e.mode!=="workspace"||!!e.workspaceConfigPath,{message:'workspaceConfigPath is required when mode is "workspace"',path:["workspaceConfigPath"]}),St=g.object({provider:g.literal("cursor"),config:Et}),At=g.discriminatedUnion("provider",[St]),It=g.object({provider:g.literal("jira"),config:g.object({baseUrl:g.string().url(),projectId:g.number().int().positive()})}),Nt=g.discriminatedUnion("provider",[It]),Ir=g.object({environments:g.array(g.string().min(1)).min(1),envManagement:$t,ide:At.optional(),taskManager:Nt.optional()}),Ot=Ir.partial(),X=null,y=async()=>{let e=await P(),r=Sr.join(e,Ct),t=Sr.join(e,Tt),s;try{s=await $e.stat(r)}catch{throw X=null,new Error(`infra-kit.yml not found at ${r}`)}let o=await Mt(t),n=Number(s.mtimeMs),i=o?Number(o.mtimeMs):null;if(X&&X.mainMtimeMs===n&&X.localMtimeMs===i)return X.value;let l=await $e.readFile(r,"utf-8"),c=Ar.parse(l),m=c;if(o){let d=await $e.readFile(t,"utf-8"),h=Ar.parse(d)??{},f=Ot.safeParse(h);if(!f.success)throw new Error(`Invalid infra-kit.local.yml at ${t}: ${g.prettifyError(f.error)}`);m={...c,...f.data}}let u=Ir.safeParse(m);if(!u.success)throw new Error(`Invalid infra-kit.yml at ${r}: ${g.prettifyError(u.error)}`);return X={mainMtimeMs:n,localMtimeMs:i,value:u.data},u.data};var Mt=async e=>{try{return await $e.stat(e)}catch{return null}};var ie=async()=>{let{envManagement:e}=await y();return e.config.name};var Nr=async()=>{let e=await ie(),{environments:r}=await y();a.info(`Doppler project: ${e}
7
+ `),a.info("Available configs:");for(let s of r)a.info(` - ${s}`);let t={project:e,configs:r};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},qe={name:"env-list",description:"List the environments the project is configured to support. Returns the `environments` list declared in infra-kit.yml at the project root (not a live fetch from Doppler) plus the Doppler project name resolved from the same file. Read-only.",inputSchema:{},outputSchema:{project:Be.string().describe("Detected Doppler project name"),configs:Be.array(Be.string()).describe("Available environment configs")},handler:Nr};import Dt from"@inquirer/select";import{Buffer as Jt}from"node:buffer";import jt from"node:fs";import Wt from"node:path";import Mr from"node:process";import{z as ce}from"zod/v4";import{$ as Ee}from"zx";import{$ as Or}from"zx";var ae=async()=>{try{await Or`doppler --version`}catch(e){throw new Error("Doppler CLI is not installed. Install it from: https://docs.doppler.com/docs/install-cli",{cause:e})}try{await Or`doppler me`}catch(e){throw new Error("Doppler CLI is not authenticated. Run: doppler login",{cause:e})}};var _t=()=>{let e="",r=[],t=!1;return{start(s){e=s,r=[],t=!1},setInteractive(){t=!0},addOption(s,o){r.push({flag:s,value:o})},print(){if(!t||r.length===0)return;let s=r.map(o=>typeof o.value=="boolean"?o.value?o.flag:"":Array.isArray(o.value)?`${o.flag} "${o.value.join(", ")}"`:`${o.flag} "${o.value}"`).filter(Boolean).join(" ");a.info(`\u{1F4DF} Equivalent command:
8
8
  pnpm exec infra-kit ${e} ${s}
9
- `)},reset(){e="",r=[],o=!1}}},c=mt();var Tr=async e=>{await se();let{config:r}=e;c.start("env-load");let o="";if(r)o=r;else{let{environments:d}=await S();c.setInteractive(),o=await ut({message:"Select environment config",choices:d.map(h=>({name:h,value:h}))},{output:xr.stderr})}c.addOption("--config",o);let s=await oe(),t=await vt(s,o);bt(t);let i=new Date().toISOString(),a=["set -a",t,`${F}=${je(o)}`,`${W}=${je(s)}`,`${B}=${je(i)}`,"set +a"],p=q(),l=ht.resolve(p,V);ft.mkdirSync(p,{recursive:!0,mode:448}),we(l,`${a.join(`
9
+ `)},reset(){e="",r=[],t=!1}}},p=_t();var Dr=async e=>{await ae();let{config:r}=e;p.start("env-load");let t="";if(r)t=r;else{let{environments:d}=await y();p.setInteractive(),t=await Dt({message:"Select environment config",choices:d.map(h=>({name:h,value:h}))},{output:Mr.stderr})}p.addOption("--config",t);let s=await ie(),o=await Lt(s,t);Ut(o);let n=new Date().toISOString(),i=["set -a",o,`${G}=${Ue(t)}`,`${K}=${Ue(s)}`,`${z}=${Ue(n)}`,"set +a"],l=H(),c=Wt.resolve(l,U);jt.mkdirSync(l,{recursive:!0,mode:448}),Te(c,`${i.join(`
10
10
  `)}
11
- `,384),xr.stdout.write(`${l}
12
- `),c.print();let m=wt(t),u={filePath:l,variableCount:m,project:s,config:o};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}},kr=1024*1024,gt=3e4,vt=async(e,r)=>{let o=be.quiet;be.quiet=!0;try{let s=await be`doppler secrets download --no-file --format env --project ${e} --config ${r}`.timeout(gt);return yt(s.stdout),s.stdout.trim()}finally{be.quiet=o}},yt=e=>{let r=dt.byteLength(e,"utf-8");if(r>kr)throw new Error(`doppler returned unexpectedly large output (${r} bytes > ${kr}) \u2014 refusing to write to disk`)},wt=e=>e.split(`
13
- `).filter(r=>ve.test(r)).length,Rt=new Set(["set -a","set +a"]),je=e=>`'${e.replaceAll("'","'\\''")}'`,bt=e=>{if(e.trim().length===0)throw new Error("doppler returned empty output for env-load");for(let r of e.split(`
14
- `)){let o=r.trim();if(!(o.length===0||Rt.has(o))&&!ve.test(o))throw new Error(`doppler returned unexpected output for env-load (expected KEY=value lines, got: ${JSON.stringify(o.slice(0,80))})`)}},Je={name:"env-load",description:'Download the env vars for a Doppler config and write them to a temporary shell script. Does NOT mutate the calling process \u2014 returns the path to a script that must be sourced ("source <filePath>") for the vars to take effect. The infra-kit shell wrapper auto-sources; direct MCP callers must handle sourcing themselves or surface filePath to the user. "config" is required when invoked via MCP (the CLI interactive picker is unreachable without a TTY).',inputSchema:{config:ne.string().describe('Doppler config / environment name to load (e.g. "dev", "arthur", "renana"). Required for MCP calls.')},outputSchema:{filePath:ne.string().describe("Path to the file that must be sourced to apply variables"),variableCount:ne.number().describe("Number of variables loaded"),project:ne.string().describe("Doppler project name"),config:ne.string().describe("Doppler config name")},handler:Tr};import xt from"node:path";import ie from"node:process";import{z as G}from"zod";var Cr=async()=>{await se(),n.info("Environment session status:");let e=q(),r=ie.env[ge],o=xt.join(e,V),s=0,t=0,i=ie.env[F]??null,a=ie.env[W]??null,p=ie.env[B]??null;if(i){let m=ye(o);m.length>0&&(t=m.length,s=m.filter(d=>d in ie.env).length);let u=p?.replace(/\.\d{3}Z$/,"")??null;if(n.info(` ${i}: ${s} of ${t} vars loaded (project: ${a}, loadedAt: ${u}, session: ${r})
15
- `),t>0&&s<t){let d=t-s;n.warn(` ${d} cached var(s) are not present in the current process \u2014 env-load needs to be re-sourced, or vars were unset manually.`)}}else n.info(` Session ${r}: no env loaded
16
- `);let l={sessionId:r,sessionLoadedCount:s,sessionTotalCount:t,sessionConfig:i,sessionProject:a,sessionLoadedAt:p};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},Le={name:"env-status",description:"Report which Doppler project/config is currently loaded in the terminal session, when it was loaded, and how many variables are cached. Read-only \u2014 use env-load / env-clear to change the terminal session.",inputSchema:{},outputSchema:{sessionId:G.string().describe("Current terminal session ID"),sessionLoadedCount:G.number().describe("Number of cached vars active in the current session"),sessionTotalCount:G.number().describe("Total number of cached var names"),sessionConfig:G.string().nullable().describe("Doppler config name of the loaded session (environment name)"),sessionProject:G.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:G.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:Cr};import $t from"@inquirer/checkbox";import Et from"@inquirer/confirm";import Pt from"node:process";import{z as K}from"zod";import{$ as E}from"zx";import{$ as Ls}from"zx";import $e from"node:process";import{$ as T}from"zx";import{$ as le}from"zx";import ae from"node:process";var Ve=async(e,r)=>{try{let{baseUrl:o,token:s,email:t,projectId:i}=r,a={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released||!1,archived:e.archived||!1},p=`${o}/rest/api/3/version`,l=btoa(`${t}:${s}`),m=await fetch(p,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(a)});if(!m.ok){let d=await m.text();throw n.error({status:m.status,statusText:m.statusText,error:d},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(o){throw n.error({error:o},"Error creating Jira version"),o}},xe=async e=>{try{let{baseUrl:r,token:o,email:s,projectId:t}=e,i=`${r}/rest/api/3/project/${t}/versions`,a=btoa(`${s}:${o}`),p=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${a}`}});if(!p.ok){let m=await p.text();throw n.error({status:p.status,statusText:p.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return await p.json()}catch(r){throw n.error({error:r},"Error getting Jira project versions"),r}},Tt=async(e,r)=>{try{return(await xe(r)).find(t=>t.name===e)||null}catch(o){throw n.error({error:o,versionName:e},"Error finding Jira version by name"),o}},Ct=async(e,r)=>{try{let{baseUrl:o,token:s,email:t}=r,i={released:e.released??!0,archived:e.archived??!1};e.releaseDate?i.releaseDate=e.releaseDate:e.released!==!1&&(i.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(i.description=e.description);let a=`${o}/rest/api/3/version/${e.versionId}`,p=btoa(`${t}:${s}`),l=await fetch(a,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${p}`},body:JSON.stringify(i)});if(!l.ok){let u=await l.text();throw n.error({status:l.status,statusText:l.statusText,error:u},"Failed to update Jira version"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return{success:!0,version:await l.json()}}catch(o){throw n.error({error:o},"Error updating Jira version"),o}},Fe=async(e,r)=>{try{let{versionName:o}=e,s=await Tt(o,r);if(!s)throw n.error({versionName:o},"Jira version not found"),new Error(`Version "${o}" not found in Jira project`);return await Ct({versionId:s.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(o){throw n.error({error:o},"Error delivering Jira release"),o}},z=async()=>{let e=ae.env.JIRA_BASE_URL,r=ae.env.JIRA_TOKEN||ae.env.JIRA_API_TOKEN,o=ae.env.JIRA_PROJECT_ID,s=ae.env.JIRA_EMAIL,t=[];if(e||t.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),r||t.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),o||t.push("JIRA_PROJECT_ID (numeric project ID)"),s||t.push("JIRA_EMAIL (your Jira email address)"),t.length>0){let a=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...t.map(p=>` - ${p}`),"","You can set these in your .env file or as environment variables."].join(`
17
- `);throw new Error(a)}let i=Number.parseInt(o,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${o}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:i,email:s}},ce=async()=>{try{return await z()}catch(e){return n.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var ke=e=>e==="hotfix"?"main":"dev",pe=async(e="regular")=>{let r=ke(e);le.quiet=!0,await le`git fetch origin`,await le`git switch ${r}`,await le`git pull origin ${r}`,le.quiet=!1},me=async e=>{let{version:r,jiraConfig:o,description:s,type:t="regular"}=e,i=`v${r}`,a=await Ve({name:i,projectId:o.projectId,description:s||"",released:!1,archived:!1},o),p=`${o.baseUrl}/projects/${a.version.projectId}/versions/${a.version.id}/tab/release-report-all-issues`,l=await Te({version:r,jiraVersionUrl:p,type:t,description:s});return{version:r,type:t,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:p}},y=async()=>{let e=new Map,r=await ce();if(!r)return e;try{let o=await xe(r);for(let s of o)s.description&&e.set(s.name,s.description)}catch{}return e},H=(e,r,o)=>{let s=o?" ".repeat(o-e.length+3):" ",t=`[${r}]`.padEnd(11);return`${e}${s}${t}`},g=e=>e.toLowerCase().startsWith("hotfix")?"hotfix":"regular",b=e=>{let{branches:r,descriptions:o,types:s}=e,t=r.map(a=>a.replace("release/v","")),i=Math.max(...t.map(a=>a.length));return r.map((a,p)=>{let l=t[p],m=s?s.get(a)||"regular":void 0,u=o.get(`v${l}`),d=" ".repeat(i-l.length+3),h=m?H(l,m,i):l;return u&&(h=m?`${h} ${u}`:`${l}${d}${u}`),{name:h,value:a}})};var We=e=>e.replace("release/","").slice(1).split(".").map(Number),Ce=e=>[...e].sort((r,o)=>{let[s,t,i]=We(r),[a,p,l]=We(o);return s!==a?(s??0)-(a??0):t!==p?(t??0)-(p??0):(i??0)-(l??0)});var $r=async()=>{let e=await T`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=await T`gh pr list --search "Hotfix in:title" --base main --json number,title,headRefName,state,baseRefName`,o=[...JSON.parse(e.stdout),...JSON.parse(r.stdout)],s=new Set;return o.filter(t=>s.has(t.headRefName)?!1:(s.add(t.headRefName),!0))},Ee=async()=>{try{let e=await $r();return e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),$e.exit(1)),Ce(e.map(r=>r.headRefName))}catch(e){n.error({error:e},"\u274C Error fetching release PRs"),$e.exit(1)}},v=async()=>{try{let e=await $r();e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),$e.exit(1));let r=Ce(e.map(s=>s.headRefName)),o=new Map(e.map(s=>[s.headRefName,s]));return r.map(s=>({branch:s,title:o.get(s).title}))}catch(e){n.error({error:e},"\u274C Error fetching release PRs"),$e.exit(1)}},Te=async e=>{let{version:r,jiraVersionUrl:o,type:s,description:t}=e,i=s==="hotfix"?"Hotfix":"Release",a=ke(s),p=`release/v${r}`,l=t&&t.trim()!==""?`${o}
11
+ `,384),Mr.stdout.write(`${c}
12
+ `),p.print();let m=Bt(o),u={filePath:c,variableCount:m,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}},_r=1024*1024,Ft=3e4,Lt=async(e,r)=>{let t=Ee.quiet;Ee.quiet=!0;try{let s=await Ee`doppler secrets download --no-file --format env --project ${e} --config ${r}`.timeout(Ft);return Vt(s.stdout),s.stdout.trim()}finally{Ee.quiet=t}},Vt=e=>{let r=Jt.byteLength(e,"utf-8");if(r>_r)throw new Error(`doppler returned unexpectedly large output (${r} bytes > ${_r}) \u2014 refusing to write to disk`)},Bt=e=>e.split(`
13
+ `).filter(r=>xe.test(r)).length,qt=new Set(["set -a","set +a"]),Ue=e=>`'${e.replaceAll("'","'\\''")}'`,Ut=e=>{if(e.trim().length===0)throw new Error("doppler returned empty output for env-load");for(let r of e.split(`
14
+ `)){let t=r.trim();if(!(t.length===0||qt.has(t))&&!xe.test(t))throw new Error(`doppler returned unexpected output for env-load (expected KEY=value lines, got: ${JSON.stringify(t.slice(0,80))})`)}},Ge={name:"env-load",description:'Download the env vars for a Doppler config and write them to a temporary shell script. Does NOT mutate the calling process \u2014 returns the path to a script that must be sourced ("source <filePath>") for the vars to take effect. The infra-kit shell wrapper auto-sources; direct MCP callers must handle sourcing themselves or surface filePath to the user. "config" is required when invoked via MCP (the CLI interactive picker is unreachable without a TTY).',inputSchema:{config:ce.string().describe('Doppler config / environment name to load (e.g. "dev", "arthur", "renana"). Required for MCP calls.')},outputSchema:{filePath:ce.string().describe("Path to the file that must be sourced to apply variables"),variableCount:ce.number().describe("Number of variables loaded"),project:ce.string().describe("Doppler project name"),config:ce.string().describe("Doppler config name")},handler:Dr};import Gt from"node:path";import le from"node:process";import{z as Z}from"zod/v4";var Jr=async()=>{await ae(),a.info("Environment session status:");let e=H(),r=le.env[ke],t=Gt.join(e,U),s=0,o=0,n=le.env[G]??null,i=le.env[K]??null,l=le.env[z]??null;if(n){let m=Ce(t);m.length>0&&(o=m.length,s=m.filter(d=>d in le.env).length);let u=l?.replace(/\.\d{3}Z$/,"")??null;if(a.info(` ${n}: ${s} of ${o} vars loaded (project: ${i}, loadedAt: ${u}, session: ${r})
15
+ `),o>0&&s<o){let d=o-s;a.warn(` ${d} cached var(s) are not present in the current process \u2014 env-load needs to be re-sourced, or vars were unset manually.`)}}else a.info(` Session ${r}: no env loaded
16
+ `);let c={sessionId:r,sessionLoadedCount:s,sessionTotalCount:o,sessionConfig:n,sessionProject:i,sessionLoadedAt:l};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},Ke={name:"env-status",description:"Report which Doppler project/config is currently loaded in the terminal session, when it was loaded, and how many variables are cached. Read-only \u2014 use env-load / env-clear to change the terminal session.",inputSchema:{},outputSchema:{sessionId:Z.string().describe("Current terminal session ID"),sessionLoadedCount:Z.number().describe("Number of cached vars active in the current session"),sessionTotalCount:Z.number().describe("Total number of cached var names"),sessionConfig:Z.string().nullable().describe("Doppler config name of the loaded session (environment name)"),sessionProject:Z.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:Z.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:Jr};import Yt from"@inquirer/checkbox";import Xt from"@inquirer/confirm";import Zt from"node:process";import{z as re}from"zod/v4";import{$ as S}from"zx";import{$ as vn}from"zx";import Oe from"node:process";import{$}from"zx";import{$ as ue}from"zx";import pe from"node:process";var ze=async(e,r)=>{try{let{baseUrl:t,token:s,email:o,projectId:n}=r,i={name:e.name,projectId:e.projectId||n,description:e.description||"",released:e.released||!1,archived:e.archived||!1},l=`${t}/rest/api/3/version`,c=btoa(`${o}:${s}`),m=await fetch(l,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${c}`},body:JSON.stringify(i)});if(!m.ok){let d=await m.text();throw a.error({status:m.status,statusText:m.statusText,error:d},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(t){throw a.error({error:t},"Error creating Jira version"),t}},Se=async e=>{try{let{baseUrl:r,token:t,email:s,projectId:o}=e,n=`${r}/rest/api/3/project/${o}/versions`,i=btoa(`${s}:${t}`),l=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${i}`}});if(!l.ok){let m=await l.text();throw a.error({status:l.status,statusText:l.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return await l.json()}catch(r){throw a.error({error:r},"Error getting Jira project versions"),r}},zt=async(e,r)=>{try{return(await Se(r)).find(o=>o.name===e)||null}catch(t){throw a.error({error:t,versionName:e},"Error finding Jira version by name"),t}},Ht=async(e,r)=>{try{let{baseUrl:t,token:s,email:o}=r,n={released:e.released??!0,archived:e.archived??!1};e.releaseDate?n.releaseDate=e.releaseDate:e.released!==!1&&(n.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(n.description=e.description);let i=`${t}/rest/api/3/version/${e.versionId}`,l=btoa(`${o}:${s}`),c=await fetch(i,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(n)});if(!c.ok){let u=await c.text();throw a.error({status:c.status,statusText:c.statusText,error:u},"Failed to update Jira version"),new Error(`HTTP ${c.status}: ${c.statusText}`)}return{success:!0,version:await c.json()}}catch(t){throw a.error({error:t},"Error updating Jira version"),t}},He=async(e,r)=>{try{let{versionName:t}=e,s=await zt(t,r);if(!s)throw a.error({versionName:t},"Jira version not found"),new Error(`Version "${t}" not found in Jira project`);return await Ht({versionId:s.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(t){throw a.error({error:t},"Error delivering Jira release"),t}},Q=async()=>{let e=pe.env.JIRA_BASE_URL,r=pe.env.JIRA_TOKEN||pe.env.JIRA_API_TOKEN,t=pe.env.JIRA_PROJECT_ID,s=pe.env.JIRA_EMAIL,o=[];if(e||o.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),r||o.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),t||o.push("JIRA_PROJECT_ID (numeric project ID)"),s||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let i=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(l=>` - ${l}`),"","You can set these in your .env file or as environment variables."].join(`
17
+ `);throw new Error(i)}let n=Number.parseInt(t,10);if(Number.isNaN(n))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${t}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:n,email:s}},me=async()=>{try{return await Q()}catch(e){return a.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var Ae=e=>e==="hotfix"?"main":"dev",de=async(e="regular")=>{let r=Ae(e);ue.quiet=!0,await ue`git fetch origin`,await ue`git switch ${r}`,await ue`git pull origin ${r}`,ue.quiet=!1},fe=async e=>{let{version:r,jiraConfig:t,description:s,type:o="regular"}=e,n=`v${r}`,i=await ze({name:n,projectId:t.projectId,description:s||"",released:!1,archived:!1},t),l=`${t.baseUrl}/projects/${i.version.projectId}/versions/${i.version.id}/tab/release-report-all-issues`,c=await Ie({version:r,jiraVersionUrl:l,type:o,description:s});return{version:r,type:o,branchName:c.branchName,prUrl:c.prUrl,jiraVersionUrl:l}},R=async()=>{let e=new Map,r=await me();if(!r)return e;try{let t=await Se(r);for(let s of t)s.description&&e.set(s.name,s.description)}catch{}return e},ee=(e,r,t)=>{let s=t?" ".repeat(t-e.length+3):" ",o=`[${r}]`.padEnd(11);return`${e}${s}${o}`},v=e=>e.toLowerCase().startsWith("hotfix")?"hotfix":"regular",T=e=>{let{branches:r,descriptions:t,types:s}=e,o=r.map(i=>i.replace("release/v","")),n=Math.max(...o.map(i=>i.length));return r.map((i,l)=>{let c=o[l],m=s?s.get(i)||"regular":void 0,u=t.get(`v${c}`),d=" ".repeat(n-c.length+3),h=m?ee(c,m,n):c;return u&&(h=m?`${h} ${u}`:`${c}${d}${u}`),{name:h,value:i}})};var Ye=e=>e.replace("release/","").slice(1).split(".").map(Number),Ne=e=>[...e].sort((r,t)=>{let[s,o,n]=Ye(r),[i,l,c]=Ye(t);return s!==i?(s??0)-(i??0):o!==l?(o??0)-(l??0):(n??0)-(c??0)});var jr=async()=>{let e=await $`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=await $`gh pr list --search "Hotfix in:title" --base main --json number,title,headRefName,state,baseRefName`,t=[...JSON.parse(e.stdout),...JSON.parse(r.stdout)],s=new Set;return t.filter(o=>s.has(o.headRefName)?!1:(s.add(o.headRefName),!0))},Me=async()=>{try{let e=await jr();return e.length===0&&(a.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),Oe.exit(1)),Ne(e.map(r=>r.headRefName))}catch(e){a.error({error:e},"\u274C Error fetching release PRs"),Oe.exit(1)}},w=async()=>{try{let e=await jr();e.length===0&&(a.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),Oe.exit(1));let r=Ne(e.map(s=>s.headRefName)),t=new Map(e.map(s=>[s.headRefName,s]));return r.map(s=>({branch:s,title:t.get(s).title}))}catch(e){a.error({error:e},"\u274C Error fetching release PRs"),Oe.exit(1)}},Ie=async e=>{let{version:r,jiraVersionUrl:t,type:s,description:o}=e,n=s==="hotfix"?"Hotfix":"Release",i=Ae(s),l=`release/v${r}`,c=o&&o.trim()!==""?`${t}
18
18
 
19
- ${t}`:`${o}
20
- `;try{T.quiet=!0,await T`git switch ${a}`,await T`git pull origin ${a}`,await T`git checkout -b ${p}`,await T`git push -u origin ${p}`,await T`git commit --allow-empty-message --allow-empty --message ''`,await T`git push origin ${p}`;let u=(await T`gh pr create --title "${i} v${r}" --body ${l} --base ${a} --head ${p}`).stdout.trim();return await T`git switch ${a}`,T.quiet=!1,{branchName:p,prUrl:u}}catch(m){throw n.error({error:m,branchName:p},`Error creating release branch ${p}`),m}};var Er=async e=>{let{all:r,confirmedCommand:o}=e;c.start("merge-dev");let t=(await v()).filter(u=>g(u.title)==="regular").map(u=>u.branch);if(t.length===0)return n.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0},null,2)}],structuredContent:{successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0}};let i=[];if(r)i=t;else{c.setInteractive();let u=await y();i=await $t({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:t,descriptions:u})})}i.length===t.length?c.addOption("--all",!0):c.addOption("--versions",i.map(u=>u.replace("release/v","")));let p=o?!0:await Et({message:`Are you sure you want to merge dev into these branches: ${i.join(", ")}?`});o||c.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),Pt.exit(0)),o||c.addOption("--yes",!0),E.quiet=!0,await E`git fetch origin`,await E`git switch dev`,await E`git pull origin dev`;let l=[];for(let u of i)await It(u)||l.push(u);if(E.quiet=!1,l.length>0){n.info(`
21
- \u26A0\uFE0F ${l.length} branch(es) failed to merge automatically.
22
- `),n.info("\u{1F4CB} Manual merge script for failed branches:");for(let u of l)n.info(`# Merge dev into ${u} and resolve conflicts if any
19
+ ${o}`:`${t}
20
+ `;try{$.quiet=!0,await $`git switch ${i}`,await $`git pull origin ${i}`,await $`git checkout -b ${l}`,await $`git push -u origin ${l}`,await $`git commit --allow-empty-message --allow-empty --message ''`,await $`git push origin ${l}`;let u=(await $`gh pr create --title "${n} v${r}" --body ${c} --base ${i} --head ${l}`).stdout.trim();return await $`git switch ${i}`,$.quiet=!1,{branchName:l,prUrl:u}}catch(m){throw a.error({error:m,branchName:l},`Error creating release branch ${l}`),m}};var Wr=async e=>{let{all:r,confirmedCommand:t}=e;p.start("merge-dev");let o=(await w()).filter(u=>v(u.title)==="regular").map(u=>u.branch);if(o.length===0)return a.info("\u2139\uFE0F No open release branches found"),p.print(),{content:[{type:"text",text:JSON.stringify({successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0},null,2)}],structuredContent:{successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0}};let n=[];if(r)n=o;else{p.setInteractive();let u=await R();n=await Yt({required:!0,message:"\u{1F33F} Select release branches",choices:T({branches:o,descriptions:u})})}n.length===o.length?p.addOption("--all",!0):p.addOption("--versions",n.map(u=>u.replace("release/v","")));let l=t?!0:await Xt({message:`Are you sure you want to merge dev into these branches: ${n.join(", ")}?`});t||p.setInteractive(),l||(a.info("Operation cancelled. Exiting..."),Zt.exit(0)),t||p.addOption("--yes",!0),S.quiet=!0,await S`git fetch origin`,await S`git switch dev`,await S`git pull origin dev`;let c=[];for(let u of n)await Qt(u)||c.push(u);if(S.quiet=!1,c.length>0){a.info(`
21
+ \u26A0\uFE0F ${c.length} branch(es) failed to merge automatically.
22
+ `),a.info("\u{1F4CB} Manual merge script for failed branches:");for(let u of c)a.info(`# Merge dev into ${u} and resolve conflicts if any
23
23
 
24
24
  git switch ${u} && git pull origin ${u} && git merge origin/dev
25
25
  git push origin ${u} && git switch dev
26
- `);n.info(`\u2705 ${i.length-l.length}/${i.length} merges completed successfully.`)}else n.info(`\u2705 All merges completed successfully!
27
- `);c.print();let m={successfulMerges:i.length-l.length,failedMerges:l.length,failedBranches:l,totalBranches:i.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},It=async e=>{try{return await E`git switch ${e}`,await E`git pull origin ${e}`,await E`git merge origin/dev --no-edit`,await E`git push origin ${e}`,await E`git switch dev`,n.info(`Successfully merged dev into ${e}`),!0}catch(r){return n.error({error:r,branch:e},`Error merging dev into ${e}`),await E`git reset --merge HEAD~1`,!1}},Be={name:"gh-merge-dev",description:"Merge origin/dev into every open regular (non-hotfix) release branch and push the result. Mutates local git state and the remote release branches. When invoked via MCP, pass all=true \u2014 the branch picker is unreachable without a TTY, and the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. Irreversible once pushed.",inputSchema:{all:K.boolean().optional().describe("Target every open regular release branch. Must be true for MCP calls (the interactive picker is unavailable without a TTY).")},outputSchema:{successfulMerges:K.number().describe("Number of successful merges"),failedMerges:K.number().describe("Number of failed merges"),failedBranches:K.array(K.string()).describe("List of branches that failed to merge"),totalBranches:K.number().describe("Total number of branches processed")},handler:Er};import St from"@inquirer/confirm";import At from"@inquirer/select";import qe from"node:process";import{z as ue}from"zod";import{$ as R}from"zx";var Pr=async e=>{let{version:r,confirmedCommand:o}=e;c.start("release-deliver");let s=await v(),t=s.map(d=>d.branch),i=new Map(s.map(d=>[d.branch,g(d.title)])),a="";if(r)a=`release/v${r}`;else{c.setInteractive();let d=await y();a=await At({message:"\u{1F33F} Select release branch",choices:b({branches:t,descriptions:d,types:i})})}let p=a.replace("release/v","");c.addOption("--version",p);let l=s.find(d=>d.branch===a);l||(n.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),qe.exit(1));let m=g(l.title),u=o?!0:await St({message:`Are you sure you want to deliver version ${a} to production?`});o||c.setInteractive(),u||(n.info("Operation cancelled. Exiting..."),qe.exit(0)),c.addOption("--yes",!0);try{R.quiet=!0,m==="hotfix"?(await R`gh pr merge ${a} --squash --admin --delete-branch`,R.quiet=!1,await R`gh workflow run deploy-all.yml --ref main -f environment=prod`,R.quiet=!0,await R`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await R`gh pr merge ${a} --squash --admin --delete-branch`,await R`gh pr create --base main --head dev --title "Release v${p} (RC)" --body ""`,await R`gh pr merge dev --squash --admin`,R.quiet=!1,await R`gh workflow run deploy-all.yml --ref main -f environment=prod`,R.quiet=!0,await R`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),R.quiet=!1;let d=await ce();if(d)try{let f=a.replace("release/","");await Fe({versionName:f},d)}catch(f){n.error({error:f},"Failed to deliver Jira release (non-blocking)")}else n.info("\u{1F514} Jira is not configured, skipping Jira release delivery");n.info(`Successfully delivered ${a} to production!`),c.print();let h={releaseBranch:a,version:a.replace("release/v",""),type:m,success:!0};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(d){n.error({error:d},"\u274C Error merging release branch into dev"),qe.exit(1)}},Ue={name:"gh-release-deliver",description:'Deliver a release to production. For hotfixes: squash-merges the release branch to main and dispatches the deploy-all workflow. For regular releases: squash-merges to dev, opens an RC PR, merges dev into main, dispatches the deploy-all workflow, then syncs main back to dev. Also releases the matching Jira fix version if Jira is configured. Dispatches the deploy workflow fire-and-forget \u2014 the tool returns once the workflow is accepted by GitHub, not when the deployment finishes. Irreversible production operation: the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the picker is unreachable without a TTY).',inputSchema:{version:ue.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:ue.string().describe("The release branch that was delivered"),version:ue.string().describe("The version that was delivered"),type:ue.enum(["regular","hotfix"]).describe("Release type"),success:ue.boolean().describe("Whether the delivery was successful")},handler:Pr};import Ir from"@inquirer/select";import Sr from"node:process";import{z as M}from"zod";import{$ as Ge}from"zx";var Ar=async e=>{let{version:r,env:o,skipTerraform:s}=e;c.start("release-deploy-all");let t="";if(r)t=r==="dev"?"dev":`release/v${r}`;else{c.setInteractive();let m=await v(),u=m.map(f=>f.branch),d=new Map(m.map(f=>[f.branch,g(f.title)])),h=await y();t=await Ir({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...b({branches:u,descriptions:h,types:d})]})}let i=t==="dev"?"dev":t.replace("release/v","");c.addOption("--version",i);let{environments:a}=await S(),p="";o?p=o:(c.setInteractive(),p=await Ir({message:"\u{1F9EA} Select environment",choices:a.map(m=>({name:m,value:m}))})),c.addOption("--env",p),a.includes(p)||(n.error(`\u274C Invalid environment: ${p}. Exiting...`),Sr.exit(1));let l=s??!1;l&&c.addOption("--skip-terraform",!0);try{Ge.quiet=!0,await Ge`gh workflow run deploy-all.yml --ref ${t} -f environment=${p} ${l?["-f","skip_terraform_deploy=true"]:[]}`,Ge.quiet=!1,n.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${t} and environment: ${p}`),c.print();let u={releaseBranch:t,version:t.replace("release/v",""),environment:p,skipTerraformDeploy:l,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){n.error({error:m},"\u274C Error launching workflow"),Sr.exit(1)}},ze={name:"gh-release-deploy-all",description:'Dispatch the deploy-all.yml GitHub Actions workflow to deploy every service from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Use gh-release-deploy-selected for a subset of services. Pass version="dev" to deploy from the dev branch instead of a release branch. Both "version" and "env" are required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:M.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:M.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:M.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:M.string().describe("The release branch that was deployed"),version:M.string().describe("The version that was deployed"),environment:M.string().describe("The environment deployed to"),skipTerraformDeploy:M.boolean().describe("Whether terraform deployment was skipped"),success:M.boolean().describe("Whether the deployment was successful")},handler:Ar};import Nt from"@inquirer/checkbox";import Nr from"@inquirer/select";import Ot from"node:fs/promises";import{resolve as _t}from"node:path";import de from"node:process";import Mt from"yaml";import{z as C}from"zod";import{$ as He}from"zx";var Or=async e=>{let{version:r,env:o,services:s,skipTerraform:t}=e;c.start("release-deploy-selected");let i="";if(r)i=r==="dev"?"dev":`release/v${r}`;else{c.setInteractive();let f=await v(),P=f.map(j=>j.branch),N=new Map(f.map(j=>[j.branch,g(j.title)])),I=await y();i=await Nr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...b({branches:P,descriptions:I,types:N})]})}let a=i==="dev"?"dev":i.replace("release/v","");c.addOption("--version",a);let{environments:p}=await S(),l="";o?l=o:(c.setInteractive(),l=await Nr({message:"\u{1F9EA} Select environment",choices:p.map(f=>({name:f,value:f}))})),c.addOption("--env",l),p.includes(l)||(n.error(`\u274C Invalid environment: ${l}. Exiting...`),de.exit(1));let m=await Dt();m.length===0&&(n.error("\u274C No services found in workflow file. Exiting..."),de.exit(1));let u=[];s&&s.length>0?u=s:(c.setInteractive(),u=await Nt({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),c.addOption("--services",u),u.length===0&&(n.error("\u274C No services selected. Exiting..."),de.exit(1));let d=u.filter(f=>!m.includes(f));d.length>0&&(n.error(`\u274C Invalid services: ${d.join(", ")}. Available services: ${m.join(", ")}`),de.exit(1));let h=t??!1;h&&c.addOption("--skip-terraform",!0);try{He.quiet=!0;let f=u.flatMap(I=>["-f",`${I}=true`]);await He`gh workflow run deploy-selected-services.yml --ref ${i} -f environment=${l} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,He.quiet=!1,n.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${i}, environment: ${l}, services: ${u.join(", ")}`),c.print();let N={releaseBranch:i,version:i.replace("release/v",""),environment:l,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(N,null,2)}],structuredContent:N}}catch(f){n.error({error:f},"\u274C Error launching workflow"),de.exit(1)}},Dt=async()=>{let e=await k(),r=_t(e,".github/workflows/deploy-selected-services.yml"),o=await Ot.readFile(r,"utf-8"),t=Mt.parse(o).on.workflow_dispatch.inputs,i=[];for(let[a,p]of Object.entries(t))p.type==="boolean"&&a!=="skip_terraform_deploy"&&i.push(a);return i},Ke={name:"gh-release-deploy-selected",description:'Dispatch the deploy-selected-services.yml GitHub Actions workflow to deploy a chosen subset of services from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Service names are validated against the boolean inputs declared in the workflow. Use gh-release-deploy-all for every service. "version", "env", and "services" are all required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:C.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:C.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:C.array(C.string()).describe('Service names to deploy. Each must match a boolean input declared in .github/workflows/deploy-selected-services.yml (e.g. "client-be", "client-fe"). Required for MCP calls.'),skipTerraform:C.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:C.string().describe("The release branch that was deployed"),version:C.string().describe("The version that was deployed"),environment:C.string().describe("The environment deployed to"),services:C.array(C.string()).describe("The services that were deployed"),skipTerraformDeploy:C.boolean().describe("Whether terraform deployment was skipped"),success:C.boolean().describe("Whether the deployment was successful")},handler:Or};import{z as Y}from"zod";var _r=async()=>{let r=(await v()).map(a=>({version:a.branch.replace("release/",""),type:g(a.title)})),o=await y(),s=Math.max(...r.map(a=>a.version.length)),t=r.map(a=>{let p=H(a.version,a.type,s),l=o.get(a.version);return l?`${p} ${l}`:p});n.info(`All release branches:
28
- `),n.info(`
29
- ${t.join(`
26
+ `);a.info(`\u2705 ${n.length-c.length}/${n.length} merges completed successfully.`)}else a.info(`\u2705 All merges completed successfully!
27
+ `);p.print();let m={successfulMerges:n.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:n.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Qt=async e=>{try{return await S`git switch ${e}`,await S`git pull origin ${e}`,await S`git merge origin/dev --no-edit`,await S`git push origin ${e}`,await S`git switch dev`,a.info(`Successfully merged dev into ${e}`),!0}catch(r){return a.error({error:r,branch:e},`Error merging dev into ${e}`),await S`git reset --merge HEAD~1`,!1}},Xe={name:"gh-merge-dev",description:"Merge origin/dev into every open regular (non-hotfix) release branch and push the result. Mutates local git state and the remote release branches. When invoked via MCP, pass all=true \u2014 the branch picker is unreachable without a TTY, and the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. Irreversible once pushed.",inputSchema:{all:re.boolean().optional().describe("Target every open regular release branch. Must be true for MCP calls (the interactive picker is unavailable without a TTY).")},outputSchema:{successfulMerges:re.number().describe("Number of successful merges"),failedMerges:re.number().describe("Number of failed merges"),failedBranches:re.array(re.string()).describe("List of branches that failed to merge"),totalBranches:re.number().describe("Total number of branches processed")},handler:Wr};import eo from"@inquirer/confirm";import ro from"@inquirer/select";import Ze from"node:process";import{z as he}from"zod/v4";import{$ as C}from"zx";var Fr=async e=>{let{version:r,confirmedCommand:t}=e;p.start("release-deliver");let s=await w(),o=s.map(d=>d.branch),n=new Map(s.map(d=>[d.branch,v(d.title)])),i="";if(r)i=`release/v${r}`;else{p.setInteractive();let d=await R();i=await ro({message:"\u{1F33F} Select release branch",choices:T({branches:o,descriptions:d,types:n})})}let l=i.replace("release/v","");p.addOption("--version",l);let c=s.find(d=>d.branch===i);c||(a.error(`\u274C Release branch ${i} not found in open PRs. Exiting...`),Ze.exit(1));let m=v(c.title),u=t?!0:await eo({message:`Are you sure you want to deliver version ${i} to production?`});t||p.setInteractive(),u||(a.info("Operation cancelled. Exiting..."),Ze.exit(0)),p.addOption("--yes",!0);try{C.quiet=!0,m==="hotfix"?(await C`gh pr merge ${i} --squash --admin --delete-branch`,C.quiet=!1,await C`gh workflow run deploy-all.yml --ref main -f environment=prod`,C.quiet=!0,await C`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await C`gh pr merge ${i} --squash --admin --delete-branch`,await C`gh pr create --base main --head dev --title "Release v${l} (RC)" --body ""`,await C`gh pr merge dev --squash --admin`,C.quiet=!1,await C`gh workflow run deploy-all.yml --ref main -f environment=prod`,C.quiet=!0,await C`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),C.quiet=!1;let d=await me();if(d)try{let f=i.replace("release/","");await He({versionName:f},d)}catch(f){a.error({error:f},"Failed to deliver Jira release (non-blocking)")}else a.info("\u{1F514} Jira is not configured, skipping Jira release delivery");a.info(`Successfully delivered ${i} to production!`),p.print();let h={releaseBranch:i,version:i.replace("release/v",""),type:m,success:!0};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(d){a.error({error:d},"\u274C Error merging release branch into dev"),Ze.exit(1)}},Qe={name:"gh-release-deliver",description:'Deliver a release to production. For hotfixes: squash-merges the release branch to main and dispatches the deploy-all workflow. For regular releases: squash-merges to dev, opens an RC PR, merges dev into main, dispatches the deploy-all workflow, then syncs main back to dev. Also releases the matching Jira fix version if Jira is configured. Dispatches the deploy workflow fire-and-forget \u2014 the tool returns once the workflow is accepted by GitHub, not when the deployment finishes. Irreversible production operation: the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the picker is unreachable without a TTY).',inputSchema:{version:he.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:he.string().describe("The release branch that was delivered"),version:he.string().describe("The version that was delivered"),type:he.enum(["regular","hotfix"]).describe("Release type"),success:he.boolean().describe("Whether the delivery was successful")},handler:Fr};import Lr from"@inquirer/select";import Vr from"node:process";import{z as J}from"zod/v4";import{$ as er}from"zx";var Br=async e=>{let{version:r,env:t,skipTerraform:s}=e;p.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let m=await w(),u=m.map(f=>f.branch),d=new Map(m.map(f=>[f.branch,v(f.title)])),h=await R();o=await Lr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:u,descriptions:h,types:d})]})}let n=o==="dev"?"dev":o.replace("release/v","");p.addOption("--version",n);let{environments:i}=await y(),l="";t?l=t:(p.setInteractive(),l=await Lr({message:"\u{1F9EA} Select environment",choices:i.map(m=>({name:m,value:m}))})),p.addOption("--env",l),i.includes(l)||(a.error(`\u274C Invalid environment: ${l}. Exiting...`),Vr.exit(1));let c=s??!1;c&&p.addOption("--skip-terraform",!0);try{er.quiet=!0,await er`gh workflow run deploy-all.yml --ref ${o} -f environment=${l} ${c?["-f","skip_terraform_deploy=true"]:[]}`,er.quiet=!1,a.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${l}`),p.print();let u={releaseBranch:o,version:o.replace("release/v",""),environment:l,skipTerraformDeploy:c,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){a.error({error:m},"\u274C Error launching workflow"),Vr.exit(1)}},rr={name:"gh-release-deploy-all",description:'Dispatch the deploy-all.yml GitHub Actions workflow to deploy every service from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Use gh-release-deploy-selected for a subset of services. Pass version="dev" to deploy from the dev branch instead of a release branch. Both "version" and "env" are required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:J.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:J.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:J.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:J.string().describe("The release branch that was deployed"),version:J.string().describe("The version that was deployed"),environment:J.string().describe("The environment deployed to"),skipTerraformDeploy:J.boolean().describe("Whether terraform deployment was skipped"),success:J.boolean().describe("Whether the deployment was successful")},handler:Br};import to from"@inquirer/checkbox";import qr from"@inquirer/select";import oo from"node:fs/promises";import{resolve as so}from"node:path";import ge from"node:process";import no from"yaml";import{z as E}from"zod/v4";import{$ as tr}from"zx";var Ur=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;p.start("release-deploy-selected");let n="";if(r)n=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let f=await w(),A=f.map(W=>W.branch),_=new Map(f.map(W=>[W.branch,v(W.title)])),x=await R();n=await qr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:A,descriptions:x,types:_})]})}let i=n==="dev"?"dev":n.replace("release/v","");p.addOption("--version",i);let{environments:l}=await y(),c="";t?c=t:(p.setInteractive(),c=await qr({message:"\u{1F9EA} Select environment",choices:l.map(f=>({name:f,value:f}))})),p.addOption("--env",c),l.includes(c)||(a.error(`\u274C Invalid environment: ${c}. Exiting...`),ge.exit(1));let m=await io();m.length===0&&(a.error("\u274C No services found in workflow file. Exiting..."),ge.exit(1));let u=[];s&&s.length>0?u=s:(p.setInteractive(),u=await to({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),p.addOption("--services",u),u.length===0&&(a.error("\u274C No services selected. Exiting..."),ge.exit(1));let d=u.filter(f=>!m.includes(f));d.length>0&&(a.error(`\u274C Invalid services: ${d.join(", ")}. Available services: ${m.join(", ")}`),ge.exit(1));let h=o??!1;h&&p.addOption("--skip-terraform",!0);try{tr.quiet=!0;let f=u.flatMap(x=>["-f",`${x}=true`]);await tr`gh workflow run deploy-selected-services.yml --ref ${n} -f environment=${c} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,tr.quiet=!1,a.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${n}, environment: ${c}, services: ${u.join(", ")}`),p.print();let _={releaseBranch:n,version:n.replace("release/v",""),environment:c,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(_,null,2)}],structuredContent:_}}catch(f){a.error({error:f},"\u274C Error launching workflow"),ge.exit(1)}},io=async()=>{let e=await P(),r=so(e,".github/workflows/deploy-selected-services.yml"),t=await oo.readFile(r,"utf-8"),o=no.parse(t).on.workflow_dispatch.inputs,n=[];for(let[i,l]of Object.entries(o))l.type==="boolean"&&i!=="skip_terraform_deploy"&&n.push(i);return n},or={name:"gh-release-deploy-selected",description:'Dispatch the deploy-selected-services.yml GitHub Actions workflow to deploy a chosen subset of services from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Service names are validated against the boolean inputs declared in the workflow. Use gh-release-deploy-all for every service. "version", "env", and "services" are all required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:E.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:E.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:E.array(E.string()).describe('Service names to deploy. Each must match a boolean input declared in .github/workflows/deploy-selected-services.yml (e.g. "client-be", "client-fe"). Required for MCP calls.'),skipTerraform:E.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:E.string().describe("The release branch that was deployed"),version:E.string().describe("The version that was deployed"),environment:E.string().describe("The environment deployed to"),services:E.array(E.string()).describe("The services that were deployed"),skipTerraformDeploy:E.boolean().describe("Whether terraform deployment was skipped"),success:E.boolean().describe("Whether the deployment was successful")},handler:Ur};import{z as te}from"zod/v4";var Gr=async()=>{let r=(await w()).map(i=>({version:i.branch.replace("release/",""),type:v(i.title)})),t=await R(),s=Math.max(...r.map(i=>i.version.length)),o=r.map(i=>{let l=ee(i.version,i.type,s),c=t.get(i.version);return c?`${l} ${c}`:l});a.info(`All release branches:
28
+ `),a.info(`
29
+ ${o.join(`
30
30
  `)}
31
- `);let i={releases:r.map(a=>({version:a.version,type:a.type,description:o.get(a.version)||null})),count:r.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Ye={name:"gh-release-list",description:"List every open release PR with its version, type (regular / hotfix), and associated Jira fix-version description. Read-only; sourced from GitHub and Jira.",inputSchema:{},outputSchema:{releases:Y.array(Y.object({version:Y.string().describe("Release version"),type:Y.enum(["regular","hotfix"]).describe("Release type"),description:Y.string().nullable().describe("Jira version description")})).describe("List of all release branches"),count:Y.number().describe("Number of release branches")},handler:_r};import Mr from"@inquirer/confirm";import jt from"@inquirer/select";import Dr from"node:process";import{z as A}from"zod";import{$ as Xe,question as jr}from"zx";var Jr=async e=>{let{version:r,description:o,type:s,confirmedCommand:t,checkout:i}=e;c.start("release-create");let a=r,p=o,l=s||"regular",m=i,u=await z();a||(c.setInteractive(),a=await jr("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(n.error("No version provided. Exiting..."),Dr.exit(1));let d=a.trim();c.addOption("--version",d),s||(c.setInteractive(),l=await jt({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),c.addOption("--type",l),p===void 0&&(c.setInteractive(),p=await jr("Enter description (optional, press Enter to skip): "),p.trim()===""&&(p="")),p&&c.addOption("--description",p);let h=t?!0:await Mr({message:`Are you sure you want to create release branch for version ${d}?`});t||c.setInteractive(),h||(n.info("Operation cancelled. Exiting..."),Dr.exit(0)),c.addOption("--yes",!0),await pe(l);let f=await me({version:d,jiraConfig:u,description:p,type:l});n.info(`\u2705 Successfully created release: v${d}`),n.info(`\u{1F517} GitHub PR: ${f.prUrl}`),n.info(`\u{1F517} Jira Version: ${f.jiraVersionUrl}`),m===void 0&&(c.setInteractive(),m=await Mr({message:`Do you want to checkout to the created branch ${f.branchName}?`,default:!0})),m||c.addOption("--no-checkout",!0),m&&(Xe.quiet=!0,await Xe`git switch ${f.branchName}`,Xe.quiet=!1,n.info(`\u{1F504} Switched to branch ${f.branchName}`)),c.print();let P={version:d,type:l,branchName:f.branchName,prUrl:f.prUrl,jiraVersionUrl:f.jiraVersionUrl,isCheckedOut:m};return{content:[{type:"text",text:JSON.stringify(P,null,2)}],structuredContent:P}},Ze={name:"release-create",description:'Create a new release: cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub release PR, creates the matching Jira fix version, and optionally checks out to the new branch. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY); "type" / "description" / "checkout" default to regular / empty / true when omitted.',inputSchema:{version:A.string().describe('Version to create (e.g., "1.2.5"). Required for MCP calls.'),description:A.string().optional().describe("Optional description for the Jira version"),type:A.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")'),checkout:A.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:A.string().describe("Version number"),type:A.enum(["regular","hotfix"]).describe("Release type"),branchName:A.string().describe("Release branch name"),prUrl:A.string().describe("GitHub PR URL"),jiraVersionUrl:A.string().describe("Jira version URL"),isCheckedOut:A.boolean().describe("Whether the branch was checked out")},handler:Jr};import Jt from"@inquirer/confirm";import Lt from"@inquirer/select";import Lr from"node:process";import{z as w}from"zod";import{question as Vt}from"zx";var Ft=async e=>{let{versions:r,type:o,confirmedCommand:s}=e,t=r,i=o||"regular";t||(c.setInteractive(),t=await Vt("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let a=t.split(",").map(l=>l.trim()).filter(Boolean);c.addOption("--versions",a.join(", ")),a.length===0&&(n.error("No versions provided. Exiting..."),Lr.exit(1)),o||(c.setInteractive(),i=await Lt({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),c.addOption("--type",i),a.length===1&&n.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let p=s?!0:await Jt({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`});return s||c.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),Lr.exit(0)),c.addOption("--yes",!0),{versionsList:a,type:i}},Vr=async e=>{c.start("release-create-batch");let r=await z(),{versionsList:o,type:s}=await Ft(e);await pe(s);let t=[],i=[];for(let m of o)try{let u=await me({version:m,jiraConfig:r,type:s});t.push(u),n.info(`\u2705 Successfully created release: v${m}`),n.info(`\u{1F517} GitHub PR: ${u.prUrl}`),n.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}
32
- `)}catch(u){let d=u instanceof Error?u.message:String(u);i.push({version:m,error:d}),n.error(`\u274C Failed to create release: v${m}`),n.error(` Error: ${d}
33
- `)}let a=t.length,p=i.length;a===o.length?n.info(`\u2705 All ${o.length} release branches were created successfully.`):a>0?(n.warn(`\u26A0\uFE0F ${a} of ${o.length} release branches were created successfully.`),n.warn(`\u274C ${p} release(s) failed.`)):n.error(`\u274C All ${o.length} release branches failed to create.`),c.print();let l={createdBranches:t.map(m=>m.branchName),successCount:a,failureCount:p,releases:t,failedReleases:i};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},Qe={name:"release-create-batch",description:'Create several releases in one pass: for each comma-separated version in "versions", cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub PR, and creates the Jira fix version. Continues on per-version failure and reports which versions succeeded and which failed. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "versions" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY). Use release-create for a single version with optional checkout.',inputSchema:{versions:w.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6"). Required for MCP calls.'),type:w.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")')},outputSchema:{createdBranches:w.array(w.string()).describe("List of created release branches"),successCount:w.number().describe("Number of releases created successfully"),failureCount:w.number().describe("Number of releases that failed"),releases:w.array(w.object({version:w.string().describe("Version number"),type:w.enum(["regular","hotfix"]).describe("Release type"),branchName:w.string().describe("Release branch name"),prUrl:w.string().describe("GitHub PR URL"),jiraVersionUrl:w.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:w.array(w.object({version:w.string().describe("Version number that failed"),error:w.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:Vr};import{z as Bt}from"zod";var Fr={name:"infra-kit",type:"module",version:"0.1.93",description:"infra-kit",main:"dist/cli.js",module:"dist/cli.js",bin:{"infra-kit":"dist/cli.js",ik:"dist/cli.js"},engines:{node:">=24.x"},scripts:{inspector:"npx @modelcontextprotocol/inspector node ./dist/mcp.js --debug",build:"pnpm run clean-artifacts && node ./scripts/build.js","clean-artifacts":"rm -rf dist","clean-cache":"rm -rf node_modules/.cache .eslintcache tsconfig.tsbuildinfo .turbo .swc","prettier-fix":"pnpm exec prettier **/* --write --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","prettier-check":"pnpm exec prettier **/* --check --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","eslint-check":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src","eslint-fix":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src --fix","ts-check":"tsc --noEmit",test:"pnpm exec vitest run --reporter=dot","test-watch":"pnpm exec vitest --watch","test-ui":"pnpm exec vitest --ui","test-report":"pnpm exec vitest run --coverage",qa:"pnpm run prettier-check && pnpm run eslint-check && pnpm run ts-check && pnpm run test && echo \u2705 Success",fix:"pnpm run prettier-fix && pnpm run eslint-fix && pnpm run qa"},dependencies:{"@inquirer/checkbox":"^5.1.4","@inquirer/confirm":"^6.0.12","@inquirer/select":"^5.1.4","@modelcontextprotocol/sdk":"^1.29.0",commander:"^14.0.3",pino:"^10.3.1","pino-pretty":"^13.1.3",yaml:"^2.8.3",zod:"^3.25.76",zx:"^8.8.5"},devDependencies:{"@pkg/eslint-config":"workspace:*","@pkg/vitest-config":"workspace:*",esbuild:"^0.28.0",typescript:"^5.9.3"}};var Wr=async()=>{let e=Fr.version;n.info(e);let r={version:e};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},er={name:"version",description:"Print the installed infra-kit CLI version",inputSchema:{},outputSchema:{version:Bt.string().describe("Installed infra-kit CLI version (from package.json)")},handler:Wr};import Gt from"@inquirer/checkbox";import Pe from"@inquirer/confirm";import zt from"node:process";import{z as D}from"zod";import{$ as X}from"zx";import{$ as fe}from"zx";var rr=async e=>{let{cwd:r,title:o}=e,s=(await fe`cmux new-workspace --cwd ${r}`).stdout,t=Ut(s),i=(await fe`cmux list-pane-surfaces --workspace ${t}`).stdout,a=qt(i);await fe`cmux new-split right --workspace ${t} --surface ${a}`,await fe`cmux new-split down --workspace ${t} --surface ${a}`,o&&await fe`cmux rename-workspace --workspace ${t} ${o}`},qt=e=>{let r=e.match(/surface:\d+/);if(!r)throw new Error("cmux: could not locate initial surface in list-pane-surfaces output");return r[0]},Ut=e=>{let r=e.match(/workspace:\d+/);if(!r)throw new Error("cmux: could not locate workspace ref in new-workspace output");return r[0]};var Ht="feature",Kt="release",Yt="release/v",qr=async e=>{let{confirmedCommand:r,all:o,versions:s,cursor:t,githubDesktop:i,cmux:a}=e;c.start("worktrees-add");try{let p=await O("release"),m=`${await k()}${U}`;await Br(`${m}/${Kt}`),await Br(`${m}/${Ht}`);let u=[];if(s)u=s.split(",").map(x=>`release/v${x.trim()}`);else{let x=await v(),L=x.map(Q=>Q.branch);if(L.length===0)return n.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};if(o)u=L;else{c.setInteractive();let Q=new Map(x.map(lr=>[lr.branch,g(lr.title)])),Xr=await y();u=await Gt({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:L,descriptions:Xr,types:Q})})}}o?c.addOption("--all",!0):c.addOption("--versions",u.map(x=>x.replace("release/v","")));let d=r?!0:await Pe({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),d||(n.info("Operation cancelled. Exiting..."),zt.exit(0)),r||c.addOption("--yes",!0);let h=t??await Pe({message:"Open created worktrees in Cursor?"});typeof t>"u"&&c.setInteractive(),h?c.addOption("--cursor",!0):c.addOption("--no-cursor",!0);let f=i??await Pe({message:"Open created worktrees in GitHub Desktop?"});typeof i>"u"&&c.setInteractive(),f?c.addOption("--github-desktop",!0):c.addOption("--no-github-desktop",!0);let P=a??await Pe({message:"Open created worktrees in cmux?"});typeof a>"u"&&c.setInteractive(),P?c.addOption("--cmux",!0):c.addOption("--no-cmux",!0);let{branchesToCreate:N}=Xt({selectedReleaseBranches:u,currentWorktrees:p}),I=await Zt(N,m);if(Qt(I),h)for(let x of I)await X`cursor ${m}/${x}`;if(f)for(let x of I)await X`github ${m}/${x}`,await X`sleep 5`;if(P){let x=await _e();for(let L of I){let Q=L.replace("release/","");await rr({cwd:`${m}/${L}`,title:`${x} ${Q}`})}}c.print();let j={createdWorktrees:I,count:I.length};return{content:[{type:"text",text:JSON.stringify(j,null,2)}],structuredContent:j}}catch(p){throw n.error({error:p},"\u274C Error managing worktrees"),p}},Br=async e=>{await X`mkdir -p ${e}`},Xt=e=>{let{selectedReleaseBranches:r,currentWorktrees:o}=e,s=o.filter(i=>i.startsWith(Yt));return{branchesToCreate:r.filter(i=>!s.includes(i))}},Zt=async(e,r)=>{let o=await Promise.allSettled(e.map(async t=>{let i=`${r}/${t}`;return await X`git worktree add ${i} ${t}`,await X({cwd:i})`pnpm install`,t})),s=[];for(let[t,i]of o.entries())if(i.status==="fulfilled")s.push(i.value);else{let a=e[t];n.error({error:i.reason},`\u274C Failed to create worktree for ${a}`)}return s},Qt=e=>{if(e.length>0){n.info("\u2705 Created git worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No new git worktrees to create")},tr={name:"worktrees-add",description:'Create local git worktrees for release branches under the worktrees directory and run "pnpm install" in each. Mutates the local filesystem. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker and "open in Cursor / GitHub Desktop / cmux" follow-up prompts are unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls.',inputSchema:{all:D.boolean().optional().describe('Add worktrees for every open release branch. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:D.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.'),cursor:D.boolean().optional().describe("Open each created worktree in Cursor. Defaults to false in MCP mode (the follow-up prompt is not shown)."),githubDesktop:D.boolean().optional().describe("Open each created worktree in GitHub Desktop. Defaults to false in MCP mode (the follow-up prompt is not shown)."),cmux:D.boolean().optional().describe("Open each created worktree in a new cmux workspace with a 3-pane layout (left-top, left-bottom, full-height right), all rooted at the worktree directory. Defaults to false in MCP mode (the follow-up prompt is not shown).")},outputSchema:{createdWorktrees:D.array(D.string()).describe("List of created git worktree branches"),count:D.number().describe("Number of git worktrees created")},handler:qr};import{z as Z}from"zod";var Ur=async()=>{let e=await O("release");if(e.length===0)return n.info("\u2139\uFE0F No active worktrees found"),{content:[{type:"text",text:JSON.stringify({worktrees:[],count:0},null,2)}],structuredContent:{worktrees:[],count:0}};let[r,o]=await Promise.all([v(),y()]),s=new Map(r.map(l=>[l.branch,g(l.title)])),t=e.map(l=>{let m=l.replace("release/",""),u=s.get(l)||"regular",d=o.get(m)||null;return{version:m,type:u,description:d}}),i=Math.max(...t.map(l=>l.version.length)),a=t.map(l=>{let m=H(l.version,l.type,i);return l.description?`${m} ${l.description}`:m});n.info("\u{1F33F} Active worktrees:"),n.info(`
34
- ${a.join(`
31
+ `);let n={releases:r.map(i=>({version:i.version,type:i.type,description:t.get(i.version)||null})),count:r.length};return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}},sr={name:"gh-release-list",description:"List every open release PR with its version, type (regular / hotfix), and associated Jira fix-version description. Read-only; sourced from GitHub and Jira.",inputSchema:{},outputSchema:{releases:te.array(te.object({version:te.string().describe("Release version"),type:te.enum(["regular","hotfix"]).describe("Release type"),description:te.string().nullable().describe("Jira version description")})).describe("List of all release branches"),count:te.number().describe("Number of release branches")},handler:Gr};import Kr from"@inquirer/confirm";import ao from"@inquirer/select";import zr from"node:process";import{z as I}from"zod/v4";import{$ as nr,question as Hr}from"zx";var Yr=async e=>{let{version:r,description:t,type:s,confirmedCommand:o,checkout:n}=e;p.start("release-create");let i=r,l=t,c=s||"regular",m=n,u=await Q();i||(p.setInteractive(),i=await Hr("Enter version (e.g. 1.2.5): ")),(!i||i.trim()==="")&&(a.error("No version provided. Exiting..."),zr.exit(1));let d=i.trim();p.addOption("--version",d),s||(p.setInteractive(),c=await ao({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),p.addOption("--type",c),l===void 0&&(p.setInteractive(),l=await Hr("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&p.addOption("--description",l);let h=o?!0:await Kr({message:`Are you sure you want to create release branch for version ${d}?`});o||p.setInteractive(),h||(a.info("Operation cancelled. Exiting..."),zr.exit(0)),p.addOption("--yes",!0),await de(c);let f=await fe({version:d,jiraConfig:u,description:l,type:c});a.info(`\u2705 Successfully created release: v${d}`),a.info(`\u{1F517} GitHub PR: ${f.prUrl}`),a.info(`\u{1F517} Jira Version: ${f.jiraVersionUrl}`),m===void 0&&(p.setInteractive(),m=await Kr({message:`Do you want to checkout to the created branch ${f.branchName}?`,default:!0})),m||p.addOption("--no-checkout",!0),m&&(nr.quiet=!0,await nr`git switch ${f.branchName}`,nr.quiet=!1,a.info(`\u{1F504} Switched to branch ${f.branchName}`)),p.print();let A={version:d,type:c,branchName:f.branchName,prUrl:f.prUrl,jiraVersionUrl:f.jiraVersionUrl,isCheckedOut:m};return{content:[{type:"text",text:JSON.stringify(A,null,2)}],structuredContent:A}},ir={name:"release-create",description:'Create a new release: cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub release PR, creates the matching Jira fix version, and optionally checks out to the new branch. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY); "type" / "description" / "checkout" default to regular / empty / true when omitted.',inputSchema:{version:I.string().describe('Version to create (e.g., "1.2.5"). Required for MCP calls.'),description:I.string().optional().describe("Optional description for the Jira version"),type:I.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")'),checkout:I.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:I.string().describe("Version number"),type:I.enum(["regular","hotfix"]).describe("Release type"),branchName:I.string().describe("Release branch name"),prUrl:I.string().describe("GitHub PR URL"),jiraVersionUrl:I.string().describe("Jira version URL"),isCheckedOut:I.boolean().describe("Whether the branch was checked out")},handler:Yr};import co from"@inquirer/confirm";import lo from"@inquirer/select";import Xr from"node:process";import{z as b}from"zod/v4";import{question as po}from"zx";var mo=async e=>{let{versions:r,type:t,confirmedCommand:s}=e,o=r,n=t||"regular";o||(p.setInteractive(),o=await po("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let i=o.split(",").map(c=>c.trim()).filter(Boolean);p.addOption("--versions",i.join(", ")),i.length===0&&(a.error("No versions provided. Exiting..."),Xr.exit(1)),t||(p.setInteractive(),n=await lo({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),p.addOption("--type",n),i.length===1&&a.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let l=s?!0:await co({message:`Are you sure you want to create release branches for these versions: ${i.join(", ")}?`});return s||p.setInteractive(),l||(a.info("Operation cancelled. Exiting..."),Xr.exit(0)),p.addOption("--yes",!0),{versionsList:i,type:n}},Zr=async e=>{p.start("release-create-batch");let r=await Q(),{versionsList:t,type:s}=await mo(e);await de(s);let o=[],n=[];for(let m of t)try{let u=await fe({version:m,jiraConfig:r,type:s});o.push(u),a.info(`\u2705 Successfully created release: v${m}`),a.info(`\u{1F517} GitHub PR: ${u.prUrl}`),a.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}
32
+ `)}catch(u){let d=u instanceof Error?u.message:String(u);n.push({version:m,error:d}),a.error(`\u274C Failed to create release: v${m}`),a.error(` Error: ${d}
33
+ `)}let i=o.length,l=n.length;i===t.length?a.info(`\u2705 All ${t.length} release branches were created successfully.`):i>0?(a.warn(`\u26A0\uFE0F ${i} of ${t.length} release branches were created successfully.`),a.warn(`\u274C ${l} release(s) failed.`)):a.error(`\u274C All ${t.length} release branches failed to create.`),p.print();let c={createdBranches:o.map(m=>m.branchName),successCount:i,failureCount:l,releases:o,failedReleases:n};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},ar={name:"release-create-batch",description:'Create several releases in one pass: for each comma-separated version in "versions", cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub PR, and creates the Jira fix version. Continues on per-version failure and reports which versions succeeded and which failed. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "versions" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY). Use release-create for a single version with optional checkout.',inputSchema:{versions:b.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6"). Required for MCP calls.'),type:b.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")')},outputSchema:{createdBranches:b.array(b.string()).describe("List of created release branches"),successCount:b.number().describe("Number of releases created successfully"),failureCount:b.number().describe("Number of releases that failed"),releases:b.array(b.object({version:b.string().describe("Version number"),type:b.enum(["regular","hotfix"]).describe("Release type"),branchName:b.string().describe("Release branch name"),prUrl:b.string().describe("GitHub PR URL"),jiraVersionUrl:b.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:b.array(b.object({version:b.string().describe("Version number that failed"),error:b.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:Zr};import{z as fo}from"zod/v4";var Qr={name:"infra-kit",type:"module",version:"0.1.95",description:"infra-kit",main:"dist/cli.js",module:"dist/cli.js",bin:{"infra-kit":"dist/cli.js",ik:"dist/cli.js"},engines:{node:">=24.x"},scripts:{inspector:"npx @modelcontextprotocol/inspector node ./dist/mcp.js --debug",build:"pnpm run clean-artifacts && node ./scripts/build.js","clean-artifacts":"rm -rf dist","clean-cache":"rm -rf node_modules/.cache .eslintcache tsconfig.tsbuildinfo .turbo .swc","prettier-fix":"pnpm exec prettier **/* --write --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","prettier-check":"pnpm exec prettier **/* --check --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","eslint-check":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src","eslint-fix":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src --fix","ts-check":"tsc --noEmit",test:"pnpm exec vitest run --reporter=dot","test-watch":"pnpm exec vitest --watch","test-ui":"pnpm exec vitest --ui","test-report":"pnpm exec vitest run --coverage",qa:"pnpm run prettier-check && pnpm run eslint-check && pnpm run ts-check && pnpm run test && echo \u2705 Success",fix:"pnpm run prettier-fix && pnpm run eslint-fix && pnpm run qa"},dependencies:{"@inquirer/checkbox":"^5.1.4","@inquirer/confirm":"^6.0.12","@inquirer/select":"^5.1.4","@modelcontextprotocol/sdk":"^1.29.0",commander:"^14.0.3",pino:"^10.3.1","pino-pretty":"^13.1.3",yaml:"^2.8.3",zod:"^3.25.76",zx:"^8.8.5"},devDependencies:{"@pkg/eslint-config":"workspace:*","@pkg/vitest-config":"workspace:*",esbuild:"^0.28.0",typescript:"catalog:"}};var et=async()=>{let e=Qr.version;a.info(e);let r={version:e};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},cr={name:"version",description:"Print the installed infra-kit CLI version",inputSchema:{},outputSchema:{version:fo.string().describe("Installed infra-kit CLI version (from package.json)")},handler:et};import wo from"@inquirer/checkbox";import mr from"@inquirer/confirm";import yo from"@inquirer/select";import Ro from"node:process";import{z as j}from"zod/v4";import{$ as B}from"zx";import{$ as rt}from"zx";var ve=async e=>{try{let r=(await rt`cmux list-workspaces`.quiet()).stdout,t=ho(r,e);if(!t)return;await rt`cmux close-workspace --workspace ${t}`.quiet()}catch(r){a.debug({error:r,title:e},"cmux: skipped closing workspace")}},ho=(e,r)=>{for(let t of e.split(`
34
+ `)){let s=t.match(/^[* ]\s*(workspace:\d+)\s+(.+?)(?:\s+\[selected\])?\s*$/);if(!s)continue;let o=s[1];if((s[2]?.trim()??"")===r)return o}};import{$ as we}from"zx";var lr=async e=>{let{cwd:r,title:t}=e,s=(await we`cmux new-workspace --cwd ${r}`).stdout,o=vo(s),n=(await we`cmux list-pane-surfaces --workspace ${o}`).stdout,i=go(n);await we`cmux new-split right --workspace ${o} --surface ${i}`,await we`cmux new-split down --workspace ${o} --surface ${i}`,t&&await we`cmux rename-workspace --workspace ${o} ${t}`},go=e=>{let r=e.match(/surface:\d+/);if(!r)throw new Error("cmux: could not locate initial surface in list-pane-surfaces output");return r[0]},vo=e=>{let r=e.match(/workspace:\d+/);if(!r)throw new Error("cmux: could not locate workspace ref in new-workspace output");return r[0]};var L=e=>{let{repoName:r,branch:t}=e,s=t.replace("release/","");return`${r} ${s}`};import tt from"node:fs/promises";import _e from"node:path";var pr=async e=>{let{workspacePath:r,folderPaths:t}=e,s=_e.dirname(r),o;try{o=await tt.readFile(r,"utf-8")}catch(u){throw new Error(`Cursor workspace file not found at ${r}: ${u.message}`)}let n;try{n=JSON.parse(o)}catch(u){throw new Error(`Failed to parse ${r} as JSON. Comments (JSONC) are not supported. ${u.message}`)}let i=n.folders??[],l=new Set(i.map(u=>_e.resolve(s,u.path))),c=[],m=[];for(let u of t){let d=_e.resolve(u);if(l.has(d)){m.push(u);continue}let h=_e.relative(s,d);i.push({path:h}),l.add(d),c.push(u)}return n.folders=i,await tt.writeFile(r,`${JSON.stringify(n,null,2)}
35
+ `,"utf-8"),{added:c,skipped:m}};import ot from"node:fs/promises";import De from"node:path";var ye=async e=>{let{workspacePath:r,folderPaths:t}=e,s=De.dirname(r),o;try{o=await ot.readFile(r,"utf-8")}catch(h){throw new Error(`Cursor workspace file not found at ${r}: ${h.message}`)}let n;try{n=JSON.parse(o)}catch(h){throw new Error(`Failed to parse ${r} as JSON. Comments (JSONC) are not supported. ${h.message}`)}let i=n.folders??[],l=new Set(t.map(h=>De.resolve(h))),c=new Set,m=i.filter(h=>{let f=De.resolve(s,h.path);return l.has(f)?(c.add(f),!1):!0});n.folders=m,await ot.writeFile(r,`${JSON.stringify(n,null,2)}
36
+ `,"utf-8");let u=[],d=[];for(let h of t){let f=De.resolve(h);c.has(f)?u.push(h):d.push(h)}return{removed:u,notFound:d}};import st from"node:path";var V=(e,r)=>st.isAbsolute(e)?e:st.resolve(r,e);var bo="feature",ko="release",xo="release/v",it=["workspace","windows","none"],at=async e=>{let{confirmedCommand:r,all:t,versions:s,cursor:o,githubDesktop:n,cmux:i}=e;p.start("worktrees-add");try{let l=await M("release"),c=await P(),m=`${c}${Y}`;await nt(`${m}/${ko}`),await nt(`${m}/${bo}`);let u=[];if(s)u=s.split(",").map(k=>`release/v${k.trim()}`);else{let k=await w(),N=k.map(O=>O.branch);if(N.length===0)return a.info("\u2139\uFE0F No open release branches found"),p.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};if(t)u=N;else{p.setInteractive();let O=new Map(k.map(be=>[be.branch,v(be.title)])),Je=await R();u=await wo({required:!0,message:"\u{1F33F} Select release branches",choices:T({branches:N,descriptions:Je,types:O})})}}t?p.addOption("--all",!0):p.addOption("--versions",u.map(k=>k.replace("release/v","")));let d=r?!0:await mr({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),d||(a.info("Operation cancelled. Exiting..."),Ro.exit(0)),r||p.addOption("--yes",!0);let h=o??await yo({message:"Cursor mode for created worktrees?",default:"workspace",choices:[{name:"Add to workspace file",value:"workspace",description:"Append each worktree as a folder in ide.config.workspaceConfigPath, then open the workspace"},{name:"Open separate windows",value:"windows",description:"Open each created worktree in its own Cursor window"},{name:"Skip",value:"none",description:"Do not open Cursor"}]});typeof o>"u"&&p.setInteractive(),p.addOption("--cursor",h);let f=n??await mr({message:"Open created worktrees in GitHub Desktop?"});typeof n>"u"&&p.setInteractive(),f?p.addOption("--github-desktop",!0):p.addOption("--no-github-desktop",!0);let A=i??await mr({message:"Open created worktrees in cmux?"});typeof i>"u"&&p.setInteractive(),A?p.addOption("--cmux",!0):p.addOption("--no-cmux",!0);let{branchesToCreate:_}=Co({selectedReleaseBranches:u,currentWorktrees:l}),x=await To(_,m);if(Po(x),h==="workspace"){let k=await y(),N=k.ide?.provider==="cursor"?k.ide.config:void 0;if(!N?.workspaceConfigPath)a.warn("\u26A0\uFE0F Skipping Cursor: ide.config.workspaceConfigPath is not set in infra-kit.yml");else{let O=V(N.workspaceConfigPath,c),Je=x.map(ht=>`${m}/${ht}`),{added:be,skipped:yr}=await pr({workspacePath:O,folderPaths:Je}),ft=yr.length>0?` (${yr.length} already present)`:"";a.info(`\u2705 Added ${be.length} folder(s) to ${O}${ft}`),await B`cursor ${O}`}}else if(h==="windows")for(let k of x)await B`cursor ${m}/${k}`;if(f)for(let k of x)await B`github ${m}/${k}`,await B`sleep 5`;if(A){let k=await F();for(let N of x){let O=L({repoName:k,branch:N});await lr({cwd:`${m}/${N}`,title:O})}}p.print();let W={createdWorktrees:x,count:x.length};return{content:[{type:"text",text:JSON.stringify(W,null,2)}],structuredContent:W}}catch(l){throw a.error({error:l},"\u274C Error managing worktrees"),l}},nt=async e=>{await B`mkdir -p ${e}`},Co=e=>{let{selectedReleaseBranches:r,currentWorktrees:t}=e,s=t.filter(n=>n.startsWith(xo));return{branchesToCreate:r.filter(n=>!s.includes(n))}},To=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let n=`${r}/${o}`;return await B`git worktree add ${n} ${o}`,await B({cwd:n})`pnpm install`,o})),s=[];for(let[o,n]of t.entries())if(n.status==="fulfilled")s.push(n.value);else{let i=e[o];a.error({error:n.reason},`\u274C Failed to create worktree for ${i}`)}return s},Po=e=>{if(e.length>0){a.info("\u2705 Created git worktrees:");for(let r of e)a.info(r);a.info("")}else a.info("\u2139\uFE0F No new git worktrees to create")},ur={name:"worktrees-add",description:'Create local git worktrees for release branches under the worktrees directory and run "pnpm install" in each. Mutates the local filesystem. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker and "open in Cursor / GitHub Desktop / cmux" follow-up prompts are unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls.',inputSchema:{all:j.boolean().optional().describe('Add worktrees for every open release branch. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:j.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.'),cursor:j.enum(it).optional().describe('Cursor open mode for created worktrees. "workspace" (default behavior when set interactively) appends each worktree as a folder to "ide.config.workspaceConfigPath" in infra-kit.yml and opens the workspace. "windows" opens each worktree in its own Cursor window. "none" skips Cursor. Defaults to "none" in MCP mode (the follow-up prompt is not shown).'),githubDesktop:j.boolean().optional().describe("Open each created worktree in GitHub Desktop. Defaults to false in MCP mode (the follow-up prompt is not shown)."),cmux:j.boolean().optional().describe("Open each created worktree in a new cmux workspace with a 3-pane layout (left-top, left-bottom, full-height right), all rooted at the worktree directory. Defaults to false in MCP mode (the follow-up prompt is not shown).")},outputSchema:{createdWorktrees:j.array(j.string()).describe("List of created git worktree branches"),count:j.number().describe("Number of git worktrees created")},handler:at};import{z as oe}from"zod/v4";var ct=async()=>{let e=await M("release");if(e.length===0)return a.info("\u2139\uFE0F No active worktrees found"),{content:[{type:"text",text:JSON.stringify({worktrees:[],count:0},null,2)}],structuredContent:{worktrees:[],count:0}};let[r,t]=await Promise.all([w(),R()]),s=new Map(r.map(c=>[c.branch,v(c.title)])),o=e.map(c=>{let m=c.replace("release/",""),u=s.get(c)||"regular",d=t.get(m)||null;return{version:m,type:u,description:d}}),n=Math.max(...o.map(c=>c.version.length)),i=o.map(c=>{let m=ee(c.version,c.type,n);return c.description?`${m} ${c.description}`:m});a.info("\u{1F33F} Active worktrees:"),a.info(`
37
+ ${i.join(`
35
38
  `)}
36
- `);let p={worktrees:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},or={name:"worktrees-list",description:"List existing release-branch worktrees with version, release type (regular / hotfix), and Jira fix-version description. Read-only.",inputSchema:{},outputSchema:{worktrees:Z.array(Z.object({version:Z.string().describe("Release version"),type:Z.enum(["regular","hotfix"]).describe("Release type"),description:Z.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:Z.number().describe("Number of worktrees")},handler:Ur};import eo from"@inquirer/checkbox";import ro from"@inquirer/confirm";import to from"node:process";import{z as he}from"zod";import{$ as sr}from"zx";var Gr=async e=>{let{confirmedCommand:r,all:o,versions:s}=e;c.start("worktrees-remove");try{let t=await O("release");if(t.length===0)return n.info("\u2139\uFE0F No active worktrees to remove"),c.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let a=`${await k()}${U}`,p=[];if(o)p=t;else if(s)p=s.split(",").map(h=>`release/v${h.trim()}`);else{c.setInteractive();let[h,f]=await Promise.all([y(),v()]),P=new Map(f.map(N=>[N.branch,g(N.title)]));p=await eo({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:t,descriptions:h,types:P})})}p.length===t.length?c.addOption("--all",!0):c.addOption("--versions",p.map(h=>h.replace("release/v","")));let m=r?!0:await ro({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),m||(n.info("Operation cancelled. Exiting..."),to.exit(0)),r||c.addOption("--yes",!0);let u=await oo(p,a);so(u),c.print();let d={removedWorktrees:u,count:u.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(t){throw n.error({error:t},"\u274C Error managing worktrees"),t}},oo=async(e,r)=>{let o=await Promise.allSettled(e.map(async t=>{let i=`${r}/${t}`;return await sr`git worktree remove ${i}`,t})),s=[];for(let[t,i]of o.entries())if(i.status==="fulfilled")s.push(i.value);else{let a=e[t];n.error({error:i.reason},`\u274C Failed to remove worktree for ${a}`)}return s.length===e.length&&(await sr`git worktree prune`,await sr`rm -rf ${r}`,n.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${r}`),n.info("")),s},so=e=>{if(e.length>0){n.info("\u274C Removed worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No unused worktrees to remove")},nr={name:"worktrees-remove",description:'Remove local git worktrees for release branches. When everything is removed, also runs "git worktree prune" and deletes the worktrees directory. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker is unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.',inputSchema:{all:he.boolean().optional().describe('Remove every existing worktree. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:he.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.')},outputSchema:{removedWorktrees:he.array(he.string()).describe("List of removed git worktree branches"),count:he.number().describe("Number of git worktrees removed")},handler:Gr};import no from"@inquirer/confirm";import io from"node:process";import{z as ir}from"zod";import{$ as ao}from"zx";var co="release/v",zr=async e=>{let{confirmedCommand:r}=e;c.start("worktrees-sync");try{let o=await O("release"),t=`${await k()}${U}`,i=await Ee(),a=r?!0:await no({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),a||(n.info("Operation cancelled. Exiting..."),io.exit(0)),r||c.addOption("--yes",!0);let{branchesToRemove:p}=lo({releasePRsList:i,currentWorktrees:o}),l=await po(p,t);mo(l),c.print();let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(o){throw n.error({error:o},"\u274C Error managing worktrees"),o}},lo=e=>{let{releasePRsList:r,currentWorktrees:o}=e;return{branchesToRemove:o.filter(i=>i.startsWith(co)).filter(i=>!r.includes(i))}},po=async(e,r)=>{let o=[];for(let s of e)try{let t=`${r}/${s}`;await ao`git worktree remove ${t}`,o.push(s)}catch(t){n.error({error:t,branch:s},`\u274C Failed to remove worktree for ${s}`)}return o},mo=e=>{if(e.length>0){n.info("\u274C Removed worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No unused worktrees to remove")},ar={name:"worktrees-sync",description:"Remove worktrees whose release PR is no longer open (stale cleanup). Only removes \u2014 never creates; use worktrees-add to create worktrees for new releases. The CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.",inputSchema:{},outputSchema:{removedWorktrees:ir.array(ir.string()).describe("List of removed worktree branches"),count:ir.number().describe("Number of worktrees removed during sync")},handler:zr};var cr=e=>async r=>{let{toolName:o,handler:s}=e;n.info({msg:`Tool execution started: ${o}`,params:r});try{let t=await s({...r,confirmedCommand:!0});return n.info({msg:`Tool execution successful: ${o}`}),t}catch(t){throw n.error({err:t,params:r,msg:`Tool execution failed: ${o}`}),t}};var uo=[Le,De,Je,Oe,Be,Ze,Qe,Ue,ze,Ke,Ye,er,tr,or,nr,ar],Hr=async e=>{for(let r of uo)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},cr({toolName:r.name,handler:r.handler}))};async function Kr(){let e=new fo({name:"infra-kit",version:"1.0.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await dr(e),await fr(e),await Hr(e),e}var J=mr(),go=async()=>{let e;try{e=await Kr(),J.info("MCP Server instance created")}catch(r){J.error({err:r,msg:"Failed to create MCP server"}),J.error("Fatal error during server creation."),Yr.exit(1)}try{let r=new ho;await e.connect(r),J.info({msg:"Server connected to transport. Ready."})}catch(r){J.error({err:r,msg:"Failed to initialize server"}),J.error("Fatal error during server transport init."),Yr.exit(1)}};ur(J);go();
39
+ `);let l={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},dr={name:"worktrees-list",description:"List existing release-branch worktrees with version, release type (regular / hotfix), and Jira fix-version description. Read-only.",inputSchema:{},outputSchema:{worktrees:oe.array(oe.object({version:oe.string().describe("Release version"),type:oe.enum(["regular","hotfix"]).describe("Release type"),description:oe.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:oe.number().describe("Number of worktrees")},handler:ct};import $o from"@inquirer/checkbox";import Eo from"@inquirer/confirm";import So from"node:process";import{z as Re}from"zod/v4";import{$ as fr}from"zx";var lt=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;p.start("worktrees-remove");try{let o=await M("release");if(o.length===0)return a.info("\u2139\uFE0F No active worktrees to remove"),p.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let n=await P(),i=`${n}${Y}`,l=[];if(t)l=o;else if(s)l=s.split(",").map(f=>`release/v${f.trim()}`);else{p.setInteractive();let[f,A]=await Promise.all([R(),w()]),_=new Map(A.map(x=>[x.branch,v(x.title)]));l=await $o({required:!0,message:"\u{1F33F} Select release branches",choices:T({branches:o,descriptions:f,types:_})})}l.length===o.length?p.addOption("--all",!0):p.addOption("--versions",l.map(f=>f.replace("release/v","")));let m=r?!0:await Eo({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),m||(a.info("Operation cancelled. Exiting..."),So.exit(0)),r||p.addOption("--yes",!0);let u=await F(),d=await Ao({branches:l,worktreeDir:i,repoName:u});await Io({removedWorktrees:d,worktreeDir:i,projectRoot:n}),No(d),p.print();let h={removedWorktrees:d,count:d.length};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(o){throw a.error({error:o},"\u274C Error managing worktrees"),o}},Ao=async e=>{let{branches:r,worktreeDir:t,repoName:s}=e,o=await Promise.allSettled(r.map(async i=>{let l=`${t}/${i}`,c=L({repoName:s,branch:i});return await ve(c),await fr`git worktree remove ${l}`,i})),n=[];for(let[i,l]of o.entries())if(l.status==="fulfilled")n.push(l.value);else{let c=r[i];a.error({error:l.reason},`\u274C Failed to remove worktree for ${c}`)}return n.length===r.length&&(await fr`git worktree prune`,await fr`rm -rf ${t}`,a.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${t}`),a.info("")),n},Io=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await y(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let i=V(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await ye({workspacePath:i,folderPaths:l});c.length>0&&a.info(`\u2705 Removed ${c.length} folder(s) from ${i}`)}catch(c){a.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${i}`)}},No=e=>{if(e.length>0){a.info("\u274C Removed worktrees:");for(let r of e)a.info(r);a.info("")}else a.info("\u2139\uFE0F No unused worktrees to remove")},hr={name:"worktrees-remove",description:'Remove local git worktrees for release branches. When everything is removed, also runs "git worktree prune" and deletes the worktrees directory. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker is unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.',inputSchema:{all:Re.boolean().optional().describe('Remove every existing worktree. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:Re.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.')},outputSchema:{removedWorktrees:Re.array(Re.string()).describe("List of removed git worktree branches"),count:Re.number().describe("Number of git worktrees removed")},handler:lt};import Oo from"@inquirer/confirm";import Mo from"node:process";import{z as gr}from"zod/v4";import{$ as _o}from"zx";var Do="release/v",pt=async e=>{let{confirmedCommand:r}=e;p.start("worktrees-sync");try{let t=await M("release"),s=await P(),o=`${s}${Y}`,n=await Me(),i=r?!0:await Oo({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),i||(a.info("Operation cancelled. Exiting..."),Mo.exit(0)),r||p.addOption("--yes",!0);let{branchesToRemove:l}=Jo({releasePRsList:n,currentWorktrees:t}),c=await F(),m=await jo({branches:l,worktreeDir:o,repoName:c});await Wo({removedWorktrees:m,worktreeDir:o,projectRoot:s}),Fo(m),p.print();let u={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(t){throw a.error({error:t},"\u274C Error managing worktrees"),t}},Jo=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(n=>n.startsWith(Do)).filter(n=>!r.includes(n))}},jo=async e=>{let{branches:r,worktreeDir:t,repoName:s}=e,o=[];for(let n of r)try{let i=`${t}/${n}`,l=L({repoName:s,branch:n});await ve(l),await _o`git worktree remove ${i}`,o.push(n)}catch(i){a.error({error:i,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Wo=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await y(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let i=V(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await ye({workspacePath:i,folderPaths:l});c.length>0&&a.info(`\u2705 Removed ${c.length} folder(s) from ${i}`)}catch(c){a.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${i}`)}},Fo=e=>{if(e.length>0){a.info("\u274C Removed worktrees:");for(let r of e)a.info(r);a.info("")}else a.info("\u2139\uFE0F No unused worktrees to remove")},vr={name:"worktrees-sync",description:"Remove worktrees whose release PR is no longer open (stale cleanup). Only removes \u2014 never creates; use worktrees-add to create worktrees for new releases. The CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.",inputSchema:{},outputSchema:{removedWorktrees:gr.array(gr.string()).describe("List of removed worktree branches"),count:gr.number().describe("Number of worktrees removed during sync")},handler:pt};var wr=e=>async r=>{let{toolName:t,handler:s}=e;a.info({msg:`Tool execution started: ${t}`,params:r});try{let o=await s({...r,confirmedCommand:!0});return a.info({msg:`Tool execution successful: ${t}`}),o}catch(o){throw a.error({err:o,params:r,msg:`Tool execution failed: ${t}`}),o}};var Lo=[Ke,qe,Ge,Ve,Xe,ir,ar,Qe,rr,or,sr,cr,ur,dr,hr,vr],mt=async e=>{for(let r of Lo)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},wr({toolName:r.name,handler:r.handler}))};async function ut(){let e=new Vo({name:"infra-kit",version:"1.0.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await xr(e),await Cr(e),await mt(e),e}var q=br(),qo=async()=>{let e;try{e=await ut(),q.info("MCP Server instance created")}catch(r){q.error({err:r,msg:"Failed to create MCP server"}),q.error("Fatal error during server creation."),dt.exit(1)}try{let r=new Bo;await e.connect(r),q.info({msg:"Server connected to transport. Ready."})}catch(r){q.error({err:r,msg:"Failed to initialize server"}),q.error("Fatal error during server transport init."),dt.exit(1)}};kr(q);qo();
37
40
  //# sourceMappingURL=mcp.js.map