infra-kit 0.1.72 → 0.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.js CHANGED
@@ -1,21 +1,34 @@
1
- import{StdioServerTransport as ut}from"@modelcontextprotocol/sdk/server/stdio.js";import tr from"node:process";import P from"node:process";import Te from"node:process";import H from"pino";import sr from"pino-pretty";var D="/tmp/mcp-infra-kit.log",Ce=()=>{let e=Te.argv.includes("--debug")?"debug":"info",r=H({level:e},H.destination({dest:D}));return r.info(`Logger initialized with level: ${e}. Logging to: ${D}`),r},nr=()=>{let e=Te.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),H({level:e},sr({ignore:r.join(","),colorize:!0}))},t=nr();var Se=e=>{P.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),P.exit(0)}),P.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),P.exit(0)}),P.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${D}. Shutting down...`),e.flush(),P.exit(1)}),P.on("unhandledRejection",(r,s)=>{e.fatal({reason:r,promise:s,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${D}. Shutting down...`),e.flush(),P.exit(1)})};import{config as cr}from"dotenv";import{resolve as lr}from"node:path";import{$ as Pe}from"zx";import{$ as Ee}from"zx";var $=async e=>{let s=(await Ee`git worktree list`).stdout.split(`
2
- `).filter(Boolean),n={release:ir,feature:ar};return s.map(n[e]).filter(o=>o!==null)},ir=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("release/v")?null:`release/${r[0]?.split("/").pop()||""}`},ar=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},y=async()=>(await Ee`git rev-parse --show-toplevel`).stdout.trim();var K=async()=>{try{Pe.quiet=!0;let e=await y();cr({path:lr(e,".env"),quiet:!0}),t.info("Loaded .env file from git repository root")}catch{}finally{Pe.quiet=!1}};import{McpServer as pt}from"@modelcontextprotocol/sdk/server/mcp.js";var Ae=async e=>{};var Je=async e=>{};import ur from"@inquirer/checkbox";import dr from"@inquirer/confirm";import fr from"node:process";import{z as O}from"zod";import{$ as x}from"zx";import{$ as Mt}from"zx";import Ie from"node:process";import{$ as k}from"zx";var X=e=>e.replace("release/","").slice(1).split(".").map(Number),Y=e=>[...e].sort((r,s)=>{let[n,o,c]=X(r),[l,a,p]=X(s);return n!==l?(n??0)-(l??0):o!==a?(o??0)-(a??0):(c??0)-(p??0)});var h=async()=>{try{let e=await k`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=JSON.parse(e.stdout);r.length===0&&(t.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),Ie.exit(1));let s=r.map(n=>n.headRefName);return Y(s)}catch(e){t.error({error:e},"\u274C Error fetching release PRs"),Ie.exit(1)}},F=async e=>{let{version:r,jiraVersionUrl:s}=e,n=`release/v${r}`;try{k.quiet=!0,await k`git switch dev`,await k`git pull origin dev`,await k`git checkout -b ${n}`,await k`git push -u origin ${n}`,await k`git commit --allow-empty-message --allow-empty --message ''`,await k`git push origin ${n}`;let c=(await k`gh pr create --title "Release v${r}" --body "${s} \n" --base dev --head ${n}`).stdout.trim();return await k`git switch dev`,k.quiet=!1,{branchName:n,prUrl:c}}catch(o){throw t.error({error:o,branchName:n},`Error creating release branch ${n}`),o}};var pr=()=>{let e="",r=[],s=!1;return{start(n){e=n,r=[],s=!1},setInteractive(){s=!0},addOption(n,o){r.push({flag:n,value:o})},print(){if(!s||r.length===0)return;let n=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(" ");t.info(""),t.info("# Equivalent command:"),t.info(`pnpm exec infra-kit ${e} ${n}`)},reset(){e="",r=[],s=!1}}},i=pr();var Oe=async e=>{let{all:r,confirmedCommand:s}=e;i.start("merge-dev");let n=await h();if(n.length===0)return t.info("\u2139\uFE0F No open release branches found"),i.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 o=[];r?o=n:(i.setInteractive(),o=await ur({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(m=>({name:m.replace("release/v",""),value:m}))}));let c=o.length===n.length;c?i.addOption("--all",!0):i.addOption("--branches",o);let l=s?!0:await dr({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`});s||i.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),fr.exit(0)),c&&i.addOption("--yes",!0),x.quiet=!0,await x`git fetch origin`,await x`git switch dev`,await x`git pull origin dev`;let a=[];for(let m of o)await gr(m)||a.push(m);if(x.quiet=!1,a.length>0){t.info(`
1
+ import{StdioServerTransport as qt}from"@modelcontextprotocol/sdk/server/stdio.js";import Pr from"node:process";import P from"node:process";import qe from"node:process";import ie from"pino";import Nr from"pino-pretty";var z="/tmp/mcp-infra-kit.log",Ge=()=>{let e=qe.argv.includes("--debug")?"debug":"info",t=ie({level:e},ie.destination({dest:z}));return t.info(`Logger initialized with level: ${e}. Logging to: ${z}`),t},_r=()=>{let e=qe.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),ie({level:e},Nr({ignore:t.join(","),colorize:!0}))},r=_r();var ze=e=>{P.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),P.exit(0)}),P.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),P.exit(0)}),P.on("uncaughtException",t=>{e.fatal({err:t,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${z}. Shutting down...`),e.flush(),P.exit(1)}),P.on("unhandledRejection",(t,s)=>{e.fatal({reason:t,promise:s,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${z}. Shutting down...`),e.flush(),P.exit(1)})};import{config as Jr}from"dotenv";import{resolve as jr}from"node:path";import{$ as Ke}from"zx";import{$ as He}from"zx";var E=async e=>{let s=(await He`git worktree list`).stdout.split(`
2
+ `).filter(Boolean),n={release:Or,feature:Dr};return s.map(n[e]).filter(o=>o!==null)},Or=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Dr=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},v=async()=>(await He`git rev-parse --show-toplevel`).stdout.trim();var ae=async()=>{try{Ke.quiet=!0;let e=await v();Jr({path:jr(e,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{Ke.quiet=!1}};import{McpServer as Ut}from"@modelcontextprotocol/sdk/server/mcp.js";var Xe=async e=>{};var Ye=async e=>{};import le from"node:fs";import Vr from"node:path";import F from"node:process";import{z as pe}from"zod";var b=["dev","arthur","renana","roman","eliran","oriana"],ce={"hulyo-monorepo":"hulyo","travelist-monorepo":"travelist"},_="./node_modules/.cache/infra-kit",V="env-cache.json",O="INFRA_KIT_ENV_CONFIG",M="INFRA_KIT_ENV_PROJECT",L="INFRA_KIT_ENV_LOADED_AT",W="-worktrees";var Qe=async()=>{let e=Vr.join(_,V);if(!F.env[O])return r.error("No loaded environment found. Run `env-load` first."),{content:[{type:"text",text:"No loaded environment found. Run `env-load` first."}]};let n=JSON.parse(le.readFileSync(e,"utf-8")).varNames.filter(i=>i in F.env);if(n.length===0)return le.unlinkSync(e),r.info("Current session is clear, no environment variables to unset."),{content:[{type:"text",text:"Current session is clear, no environment variables to unset."}]};for(let i of n)F.stdout.write(`unset ${i}
3
+ `);F.stdout.write(`unset ${O}
4
+ `),F.stdout.write(`unset ${M}
5
+ `),F.stdout.write(`unset ${L}
6
+ `),le.unlinkSync(e),r.info(`Cleared ${n.length} environment variables`);let o={variableCount:n.length,unsetStatements:n.map(i=>`unset ${i}`)};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},me={name:"env-clear",description:"Clear previously loaded environment variables. Usage: source <(infra-kit env-clear)",inputSchema:{},outputSchema:{variableCount:pe.number().describe("Number of variables cleared"),unsetStatements:pe.array(pe.string()).describe("Unset statements generated")},handler:Qe};import{z as ue}from"zod";import Ze from"node:process";import{$ as er}from"zx";var D=async()=>{try{await er`doppler --version`}catch(e){r.error({error:e},"Error: Doppler CLI is not installed."),r.error("Please install it from: https://docs.doppler.com/docs/install-cli"),Ze.exit(1)}try{await er`doppler me`}catch(e){r.error({error:e},"Error: Doppler CLI is not authenticated."),r.error("Please authenticate by running: doppler login"),Ze.exit(1)}};import Mr from"node:path";var J=async()=>{let e=await v(),t=Mr.basename(e),s=ce[t];if(!s)throw new Error(`Could not determine Doppler project for directory "${t}". Expected one of: ${Object.keys(ce).join(", ")}`);return s};var rr=async()=>{await D();let e=await J();r.info(`Doppler Project: ${e}
7
+ `),r.info("Available Configs:");for(let s of b)r.info(` - ${s}`);let t={project:e,configs:b};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},de={name:"env-list",description:"List available Doppler configs for the detected project",inputSchema:{},outputSchema:{project:ue.string().describe("Detected Doppler project name"),configs:ue.array(ue.string()).describe("Available environment configs")},handler:rr};import tr from"node:fs";import Lr from"node:path";import B from"node:process";import{z as ee}from"zod";import{$ as Wr}from"zx";var or=async e=>{await D();let{config:t}=e,s=await J(),o=(await Wr`doppler secrets download --no-file --format env --project ${s} --config ${t}`).stdout.trim();B.stdout.write(`set -a
8
+ `),B.stdout.write(`${o}
9
+ `),B.stdout.write(`set +a
10
+ `),B.stdout.write(`export ${O}=${t}
11
+ `),B.stdout.write(`export ${M}=${s}
12
+ `),B.stdout.write(`export ${L}=${new Date().toISOString()}
13
+ `);let i=o.split(`
14
+ `).filter(p=>p.includes("=")).map(p=>p.split("=")[0]),l=Lr.join(_,V),a={config:t,loadedAt:new Date().toISOString(),varNames:i};tr.mkdirSync(_,{recursive:!0}),tr.writeFileSync(l,JSON.stringify(a,null,2)),r.info(`Loaded ${i.length} variables from ${s}/${t}`);let m={variableCount:i.length,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},fe={name:"env-load",description:"Load environment variables from Doppler for a given config. Usage: source <(infra-kit env-load -c dev)",inputSchema:{config:ee.string().describe("Environment config name to load (e.g. dev, arthur, renana)")},outputSchema:{variableCount:ee.number().describe("Number of variables loaded"),project:ee.string().describe("Doppler project name"),config:ee.string().describe("Doppler config name")},handler:or};import sr from"node:fs";import Fr from"node:path";import re from"node:process";import{z as T}from"zod";var nr=async()=>{await D();let e=await J();r.info(`Doppler Environment Status:
15
+ `),r.info(" Authenticated: yes"),r.info(` Detected Project: ${e}`),r.info(` Available Configs: ${b.join(", ")}`);let t=Fr.join(_,V),s=0,n=0,o=re.env[O]??null,i=re.env[M]??null,l=re.env[L]??null;if(o){if(sr.existsSync(t)){let m=JSON.parse(sr.readFileSync(t,"utf-8"));n=m.varNames.length,s=m.varNames.filter(p=>p in re.env).length}r.info(` Session: ${s} of ${n} vars loaded (project: ${i}, config: ${o}, loaded at: ${l})`)}else r.info(" Session: no env loaded");let a={authenticated:!0,project:e,configs:b,sessionLoadedCount:s,sessionTotalCount:n,sessionConfig:o,sessionProject:i,sessionLoadedAt:l};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}},ge={name:"env-status",description:"Show Doppler authentication status and detected project info",inputSchema:{},outputSchema:{authenticated:T.boolean().describe("Whether the user is authenticated"),project:T.string().describe("Detected Doppler project name"),configs:T.array(T.string()).describe("Available environment configs"),sessionLoadedCount:T.number().describe("Number of cached vars active in the current session"),sessionTotalCount:T.number().describe("Total number of cached var names"),sessionConfig:T.string().nullable().describe("Doppler config name of the loaded session"),sessionProject:T.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:T.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:nr};import qr from"@inquirer/checkbox";import Gr from"@inquirer/confirm";import zr from"node:process";import{z as U}from"zod";import{$ as C}from"zx";import{$ as fs}from"zx";import ir from"node:process";import{$ as k}from"zx";var he=e=>e.replace("release/","").slice(1).split(".").map(Number),ve=e=>[...e].sort((t,s)=>{let[n,o,i]=he(t),[l,a,m]=he(s);return n!==l?(n??0)-(l??0):o!==a?(o??0)-(a??0):(i??0)-(m??0)});var h=async()=>{try{let e=await k`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,t=JSON.parse(e.stdout);t.length===0&&(r.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),ir.exit(1));let s=t.map(n=>n.headRefName);return ve(s)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),ir.exit(1)}},te=async e=>{let{version:t,jiraVersionUrl:s}=e,n=`release/v${t}`;try{k.quiet=!0,await k`git switch dev`,await k`git pull origin dev`,await k`git checkout -b ${n}`,await k`git push -u origin ${n}`,await k`git commit --allow-empty-message --allow-empty --message ''`,await k`git push origin ${n}`;let i=(await k`gh pr create --title "Release v${t}" --body "${s} \n" --base dev --head ${n}`).stdout.trim();return await k`git switch dev`,k.quiet=!1,{branchName:n,prUrl:i}}catch(o){throw r.error({error:o,branchName:n},`Error creating release branch ${n}`),o}};var Ur=()=>{let e="",t=[],s=!1;return{start(n){e=n,t=[],s=!1},setInteractive(){s=!0},addOption(n,o){t.push({flag:n,value:o})},print(){if(!s||t.length===0)return;let n=t.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(" ");r.info(""),r.info("# Equivalent command:"),r.info(`pnpm exec infra-kit ${e} ${n}`)},reset(){e="",t=[],s=!1}}},c=Ur();var ar=async e=>{let{all:t,confirmedCommand:s}=e;c.start("merge-dev");let n=await h();if(n.length===0)return r.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 o=[];t?o=n:(c.setInteractive(),o=await qr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(p=>({name:p.replace("release/v",""),value:p}))}));let i=o.length===n.length;i?c.addOption("--all",!0):c.addOption("--branches",o);let l=s?!0:await Gr({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`});s||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),zr.exit(0)),i&&c.addOption("--yes",!0),C.quiet=!0,await C`git fetch origin`,await C`git switch dev`,await C`git pull origin dev`;let a=[];for(let p of o)await Hr(p)||a.push(p);if(C.quiet=!1,a.length>0){r.info(`
3
16
  \u26A0\uFE0F ${a.length} branch(es) failed to merge automatically.
4
- `),t.info(`\u{1F4CB} Manual merge script for failed branches:
5
- `),t.info("```bash");for(let m of a)t.info(`# Phase #1: Merge dev into ${m}`),t.info(`git switch ${m} && git pull origin ${m} && git merge origin/dev`),t.info("# Phase #2:Resolve conflicts if any, then:"),t.info(`git push origin ${m} && git switch dev`);t.info(`\u2705 ${o.length-a.length}/${o.length} merges completed successfully.`)}else t.info("\u2705 All merges completed successfully!");i.print();let p={successfulMerges:o.length-a.length,failedMerges:a.length,failedBranches:a,totalBranches:o.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},gr=async e=>{try{return await x`git switch ${e}`,await x`git pull origin ${e}`,await x`git merge origin/dev --no-edit`,await x`git push origin ${e}`,await x`git switch dev`,t.info(`Successfully merged dev into ${e}`),!0}catch(r){return t.error({error:r,branch:e},`Error merging dev into ${e}`),await x`git reset --merge HEAD~1`,!1}},Q={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:O.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:O.number().describe("Number of successful merges"),failedMerges:O.number().describe("Number of failed merges"),failedBranches:O.array(O.string()).describe("List of branches that failed to merge"),totalBranches:O.number().describe("Total number of branches processed")},handler:Oe};import yr from"@inquirer/confirm";import br from"@inquirer/select";import te from"node:process";import{z as q}from"zod";import{$ as C}from"zx";import W from"node:process";var Z=async(e,r)=>{try{let{baseUrl:s,token:n,email:o,projectId:c}=r,l={name:e.name,projectId:e.projectId||c,description:e.description||"",released:e.released||!1,archived:e.archived||!1},a=`${s}/rest/api/3/version`,p=btoa(`${o}:${n}`),m=await fetch(a,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${p}`},body:JSON.stringify(l)});if(!m.ok){let u=await m.text();throw t.error({status:m.status,statusText:m.statusText,error:u},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(s){throw t.error({error:s},"Error creating Jira version"),s}},hr=async e=>{try{let{baseUrl:r,token:s,email:n,projectId:o}=e,c=`${r}/rest/api/3/project/${o}/versions`,l=btoa(`${n}:${s}`),a=await fetch(c,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${l}`}});if(!a.ok){let m=await a.text();throw t.error({status:a.status,statusText:a.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${a.status}: ${a.statusText}`)}return await a.json()}catch(r){throw t.error({error:r},"Error getting Jira project versions"),r}},vr=async(e,r)=>{try{return(await hr(r)).find(o=>o.name===e)||null}catch(s){throw t.error({error:s,versionName:e},"Error finding Jira version by name"),s}},wr=async(e,r)=>{try{let{baseUrl:s,token:n,email:o}=r,c={released:e.released??!0,archived:e.archived??!1};e.releaseDate?c.releaseDate=e.releaseDate:e.released!==!1&&(c.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(c.description=e.description);let l=`${s}/rest/api/3/version/${e.versionId}`,a=btoa(`${o}:${n}`),p=await fetch(l,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${a}`},body:JSON.stringify(c)});if(!p.ok){let d=await p.text();throw t.error({status:p.status,statusText:p.statusText,error:d},"Failed to update Jira version"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return{success:!0,version:await p.json()}}catch(s){throw t.error({error:s},"Error updating Jira version"),s}},ee=async(e,r)=>{try{let{versionName:s}=e,n=await vr(s,r);if(!n)throw t.error({versionName:s},"Jira version not found"),new Error(`Version "${s}" not found in Jira project`);return await wr({versionId:n.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(s){throw t.error({error:s},"Error delivering Jira release"),s}},N=async()=>{let e=W.env.JIRA_BASE_URL,r=W.env.JIRA_TOKEN||W.env.JIRA_API_TOKEN,s=W.env.JIRA_PROJECT_ID,n=W.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)"),s||o.push("JIRA_PROJECT_ID (numeric project ID)"),n||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let l=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(a=>` - ${a}`),"","You can set these in your .env file or as environment variables."].join(`
6
- `);throw new Error(l)}let c=Number.parseInt(s,10);if(Number.isNaN(c))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${s}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:c,email:n}},re=async()=>{try{return await N()}catch(e){return t.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var Ne=async e=>{let{version:r,confirmedCommand:s}=e;i.start("release-deliver");let n=await h(),o="";r?o=`release/v${r}`:(i.setInteractive(),o=await br({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}));let c=o.replace("release/v","");i.addOption("--version",c),n.includes(o)||(t.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),te.exit(1));let l=s?!0:await yr({message:`Are you sure you want to deliver version ${o} to production?`});s||i.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),te.exit(0)),i.addOption("--yes",!0);try{C.quiet=!0,await C`gh pr merge ${o} --squash --admin --delete-branch`,await C`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (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 a=await re();if(a)try{let m=o.replace("release/","");await ee({versionName:m},a)}catch(m){t.error({error:m},"Failed to deliver Jira release (non-blocking)")}else t.info("\u{1F514} Jira is not configured, skipping Jira release delivery");t.info(`Successfully delivered ${o} to production!`),i.print();let p={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(a){t.error({error:a},"\u274C Error merging release branch into dev"),te.exit(1)}},oe={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:q.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:q.string().describe("The release branch that was delivered"),version:q.string().describe("The version that was delivered"),success:q.boolean().describe("Whether the delivery was successful")},handler:Ne};import je from"@inquirer/select";import se from"node:process";import{z as A}from"zod";import{$ as ne}from"zx";var S=["dev","arthur","renana","roman","eliran","oriana"],j="-worktrees";var Me=async e=>{let{version:r,env:s,skipTerraform:n}=e;i.start("release-deploy-all");let o=["dev"],c=await h();o.push(...c);let l="";r?l=r==="dev"?"dev":`release/v${r}`:(i.setInteractive(),l=await je({message:"\u{1F33F} Select release branch",choices:o.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l==="dev"?"dev":l.replace("release/v","");i.addOption("--version",a),o.includes(l)||(t.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),se.exit(1));let p="";s?p=s:(i.setInteractive(),p=await je({message:"\u{1F9EA} Select environment",choices:S.map(d=>({name:d,value:d}))})),i.addOption("--env",p),S.includes(p)||(t.error(`\u274C Invalid environment: ${p}. Exiting...`),se.exit(1));let m=n??!1;m&&i.addOption("--skip-terraform",!0);try{ne.quiet=!0,await ne`gh workflow run deploy-all.yml --ref ${l} -f environment=${p} ${m?["-f","skip_terraform_deploy=true"]:[]}`,ne.quiet=!1,t.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${p}`),i.print();let u={releaseBranch:l,version:l.replace("release/v",""),environment:p,skipTerraformDeploy:m,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(d){t.error({error:d},"\u274C Error launching workflow"),se.exit(1)}},ie={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:A.string().describe('Version to deploy (e.g., "1.2.5")'),env:A.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:A.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:A.string().describe("The release branch that was deployed"),version:A.string().describe("The version that was deployed"),environment:A.string().describe("The environment deployed to"),skipTerraformDeploy:A.boolean().describe("Whether terraform deployment was skipped"),success:A.boolean().describe("Whether the deployment was successful")},handler:Me};import Rr from"@inquirer/checkbox";import De from"@inquirer/select";import kr from"node:fs/promises";import{resolve as xr}from"node:path";import M from"node:process";import $r from"yaml";import{z as R}from"zod";import{$ as ae}from"zx";var We=async e=>{let{version:r,env:s,services:n,skipTerraform:o}=e;i.start("release-deploy-selected");let c=["dev"],l=await h();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(i.setInteractive(),a=await De({message:"\u{1F33F} Select release branch",choices:c.map(g=>({name:g.replace("release/v",""),value:g}))}));let p=a==="dev"?"dev":a.replace("release/v","");i.addOption("--version",p),c.includes(a)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),M.exit(1));let m="";s?m=s:(i.setInteractive(),m=await De({message:"\u{1F9EA} Select environment",choices:S.map(g=>({name:g,value:g}))})),i.addOption("--env",m),S.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),M.exit(1));let d=await Tr();d.length===0&&(t.error("\u274C No services found in workflow file. Exiting..."),M.exit(1));let u=[];n&&n.length>0?u=n:(i.setInteractive(),u=await Rr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:d.map(g=>({name:g,value:g}))})),i.addOption("--services",u),u.length===0&&(t.error("\u274C No services selected. Exiting..."),M.exit(1));let v=u.filter(g=>!d.includes(g));v.length>0&&(t.error(`\u274C Invalid services: ${v.join(", ")}. Available services: ${d.join(", ")}`),M.exit(1));let f=o??!1;f&&i.addOption("--skip-terraform",!0);try{ae.quiet=!0;let g=u.flatMap(or=>["-f",`${or}=true`]);await ae`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${m} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,ae.quiet=!1,t.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${m}, services: ${u.join(", ")}`),i.print();let $e={releaseBranch:a,version:a.replace("release/v",""),environment:m,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify($e,null,2)}],structuredContent:$e}}catch(g){t.error({error:g},"\u274C Error launching workflow"),M.exit(1)}},Tr=async()=>{let e=await y(),r=xr(e,".github/workflows/deploy-selected-services.yml"),s=await kr.readFile(r,"utf-8"),o=$r.parse(s).on.workflow_dispatch.inputs,c=[];for(let[l,a]of Object.entries(o))a.type==="boolean"&&l!=="skip_terraform_deploy"&&c.push(l);return c},ce={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:R.string().describe('Version to deploy (e.g., "1.2.5")'),env:R.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:R.array(R.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:R.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:R.string().describe("The release branch that was deployed"),version:R.string().describe("The version that was deployed"),environment:R.string().describe("The environment deployed to"),services:R.array(R.string()).describe("The services that were deployed"),skipTerraformDeploy:R.boolean().describe("Whether terraform deployment was skipped"),success:R.boolean().describe("Whether the deployment was successful")},handler:We};import le from"@inquirer/select";import Cr from"node:fs/promises";import{resolve as Sr}from"node:path";import G from"node:process";import Er from"yaml";import{z as T}from"zod";import{$ as me}from"zx";var Be=async e=>{let{version:r,env:s,service:n,skipTerraform:o}=e;i.start("release-deploy-service");let c=["dev"],l=await h();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(i.setInteractive(),a=await le({message:"\u{1F33F} Select release branch",choices:c.map(f=>({name:f.replace("release/v",""),value:f}))}));let p=a==="dev"?"dev":a.replace("release/v","");i.addOption("--version",p),c.includes(a)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),G.exit(1));let m="";s?m=s:(i.setInteractive(),m=await le({message:"\u{1F9EA} Select environment",choices:S.map(f=>({name:f,value:f}))})),i.addOption("--env",m),S.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),G.exit(1));let d=await Pr(),u="";n?u=n:(i.setInteractive(),u=await le({message:"\u{1F680} Select service to deploy",choices:d.map(f=>({name:f,value:f}))})),i.addOption("--service",u),d.includes(u)||(t.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),G.exit(1));let v=o??!1;v&&i.addOption("--skip-terraform",!0);try{me.quiet=!0,await me`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${m} -f service=${u} ${v?["-f","skip_terraform_deploy=true"]:[]}`,me.quiet=!1,t.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${m}, service: ${u}`),i.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:m,service:u,skipTerraformDeploy:v,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){t.error({error:f},"\u274C Error launching workflow"),G.exit(1)}},Pr=async()=>{let e=await y(),r=Sr(e,".github/workflows/deploy-single-service.yml"),s=await Cr.readFile(r,"utf-8");return Er.parse(s).on.workflow_dispatch.inputs.service.options},pe={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:T.string().describe('Version to deploy (e.g., "1.2.5")'),env:T.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:T.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:T.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:T.string().describe("The release branch that was deployed"),version:T.string().describe("The version that was deployed"),environment:T.string().describe("The environment deployed to"),service:T.string().describe("The service that was deployed"),skipTerraformDeploy:T.boolean().describe("Whether terraform deployment was skipped"),success:T.boolean().describe("Whether the deployment was successful")},handler:Be};import{z as ue}from"zod";var Le=async()=>{let r=(await h()).map(n=>n.replace("release/",""));t.info(`All release branches:
7
- `),t.info(`
8
- ${r.join(`
9
- `)}`);let s={releases:r,count:r.length};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}},de={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:ue.array(ue.string()).describe("List of all release branches"),count:ue.number().describe("Number of release branches")},handler:Le};import Ve from"@inquirer/confirm";import _e from"node:process";import{z as J}from"zod";import{$ as fe,question as Ue}from"zx";import{$ as B}from"zx";var L=async()=>{B.quiet=!0,await B`git fetch origin`,await B`git switch dev`,await B`git pull origin dev`,B.quiet=!1},V=async(e,r,s)=>{let n=`v${e}`,o=await Z({name:n,projectId:r.projectId,description:s||"",released:!1,archived:!1},r),c=`${r.baseUrl}/projects/${o.version.projectId}/versions/${o.version.id}/tab/release-report-all-issues`,l=await F({version:e,jiraVersionUrl:c});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:c}};var Fe=async e=>{let{version:r,description:s,confirmedCommand:n,checkout:o}=e;i.start("release-create");let c=r,l=s,a=o,p=await N();c||(i.setInteractive(),c=await Ue("Enter version (e.g. 1.2.5): ")),(!c||c.trim()==="")&&(t.error("No version provided. Exiting..."),_e.exit(1));let m=c.trim();i.addOption("--version",m),l===void 0&&(i.setInteractive(),l=await Ue("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&i.addOption("--description",l);let d=n?!0:await Ve({message:`Are you sure you want to create release branch for version ${m}?`});n||i.setInteractive(),d||(t.info("Operation cancelled. Exiting..."),_e.exit(0)),i.addOption("--yes",!0),await L();let u=await V(m,p,l);t.info(`\u2705 Successfully created release: v${m}`),t.info(`\u{1F517} GitHub PR: ${u.prUrl}`),t.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}`),a===void 0&&(i.setInteractive(),a=await Ve({message:`Do you want to checkout to the created branch ${u.branchName}?`,default:!0})),a||i.addOption("--no-checkout",!0),a&&(fe.quiet=!0,await fe`git switch ${u.branchName}`,fe.quiet=!1,t.info(`\u{1F504} Switched to branch ${u.branchName}`)),i.print();let v={version:m,branchName:u.branchName,prUrl:u.prUrl,jiraVersionUrl:u.jiraVersionUrl,isCheckedOut:a};return{content:[{type:"text",text:JSON.stringify(v,null,2)}],structuredContent:v}},ge={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:J.string().describe('Version to create (e.g., "1.2.5")'),description:J.string().optional().describe("Optional description for the Jira version"),checkout:J.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:J.string().describe("Version number"),branchName:J.string().describe("Release branch name"),prUrl:J.string().describe("GitHub PR URL"),jiraVersionUrl:J.string().describe("Jira version URL"),isCheckedOut:J.boolean().describe("Whether the branch was checked out")},handler:Fe};import Ar from"@inquirer/confirm";import qe from"node:process";import{z as w}from"zod";import{question as Jr}from"zx";var Ge=async e=>{let{versions:r,description:s,confirmedCommand:n}=e;i.start("release-create-batch");let o=r,c=await N();o||(i.setInteractive(),o=await Jr("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=o.split(",").map(f=>f.trim());i.addOption("--versions",l.join(", ")),l.length===0&&(t.error("No versions provided. Exiting..."),qe.exit(1)),l.length===1&&t.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let a=n?!0:await Ar({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});n||i.setInteractive(),a||(t.info("Operation cancelled. Exiting..."),qe.exit(0)),i.addOption("--yes",!0),s&&i.addOption("--description",s),await L();let p=[],m=[];for(let f of l)try{let g=await V(f,c,s);p.push(g),t.info(`\u2705 Successfully created release: v${f}`),t.info(`\u{1F517} GitHub PR: ${g.prUrl}`),t.info(`\u{1F517} Jira Version: ${g.jiraVersionUrl}
10
- `)}catch(g){let E=g instanceof Error?g.message:String(g);m.push({version:f,error:E}),t.error(`\u274C Failed to create release: v${f}`),t.error(` Error: ${E}
11
- `)}let d=p.length,u=m.length;d===l.length?t.info(`\u2705 All ${l.length} release branches were created successfully.`):d>0?(t.warn(`\u26A0\uFE0F ${d} of ${l.length} release branches were created successfully.`),t.warn(`\u274C ${u} release(s) failed.`)):t.error(`\u274C All ${l.length} release branches failed to create.`),i.print();let v={createdBranches:p.map(f=>f.branchName),successCount:d,failureCount:u,releases:p,failedReleases:m};return{content:[{type:"text",text:JSON.stringify(v,null,2)}],structuredContent:v}},he={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:w.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:w.string().optional().describe("Optional description for the Jira versions")},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"),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:Ge};import Ir from"@inquirer/checkbox";import ze from"@inquirer/confirm";import{copyFileSync as Or,existsSync as Nr}from"node:fs";import jr from"node:process";import{z as _}from"zod";import{$ as ve}from"zx";var Mr="feature",Dr="release",Wr="release/v",Ke=async e=>{let{confirmedCommand:r,all:s,cursor:n}=e;i.start("worktrees-add");try{let o=await $("release"),c=await y(),l=`${c}${j}`;await He(`${l}/${Dr}`),await He(`${l}/${Mr}`);let a=await h();if(a.length===0)return t.info("\u2139\uFE0F No open release branches found"),i.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};let p=[];s?p=a:(i.setInteractive(),p=await Ir({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(E=>({name:E.replace("release/v",""),value:E}))}));let m=p.length===a.length;m?i.addOption("--all",!0):i.addOption("--branches",p);let d=r?!0:await ze({message:"Are you sure you want to proceed with these worktree changes?"});r||i.setInteractive(),d||(t.info("Operation cancelled. Exiting..."),jr.exit(0)),m&&i.addOption("--yes",!0);let u=n?!0:await ze({message:"Open created worktrees in Cursor?"});u||i.setInteractive(),u&&i.addOption("--cursor",!0);let{branchesToCreate:v}=Br({selectedReleaseBranches:p,currentWorktrees:o}),f=await Lr(v,l,c);if(Vr(f),u)for(let E of f)await ve`cursor ${l}/${E}`;i.print();let g={createdWorktrees:f,count:f.length};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(o){throw t.error({error:o},"\u274C Error managing worktrees"),o}},He=async e=>{await ve`mkdir -p ${e}`},Br=e=>{let{selectedReleaseBranches:r,currentWorktrees:s}=e,n=s.filter(c=>c.startsWith(Wr));return{branchesToCreate:r.filter(c=>!n.includes(c))}},Lr=async(e,r,s)=>{let n=[];for(let o of e)try{let c=`${r}/${o}`;await ve`git worktree add ${c} ${o}`;let l=`${s}/.env`;Nr(l)&&(Or(l,`${c}/.env`),t.info("\u{1F4CB} Copied .env to worktree")),n.push(o)}catch(c){t.error({error:c,branch:o},`\u274C Failed to create worktree for ${o}`)}return n},Vr=e=>{e.length>0?(t.info(`
12
- `),t.info("\u2705 Created worktrees:"),t.info(e.join(`
13
- `)),t.info("")):t.info("\u2139\uFE0F No new worktrees to create")},we={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:_.boolean().describe("Add worktrees for all release branches without prompting"),cursor:_.boolean().optional().describe("Open created worktrees in Cursor")},outputSchema:{createdWorktrees:_.array(_.string()).describe("List of created worktree branches"),count:_.number().describe("Number of worktrees created")},handler:Ke};import{z as b}from"zod";import{$ as U}from"zx";var Ye=async()=>{try{let[e,r]=await Promise.all([$("release"),$("feature")]),s=await y(),n=await _r(e,r,s);Hr(n);let o={worktrees:n,totalCount:n.length,releaseCount:e.length,featureCount:r.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}}catch(e){throw t.error({error:e},"\u274C Error listing worktrees"),e}},_r=async(e,r,s)=>{let n=[...e.map(c=>({branch:c,type:"release"})),...r.map(c=>({branch:c,type:"feature"}))],o=[];for(let{branch:c,type:l}of n)try{let a=`${s}/${c}`,p=await Ur(c),m=await Fr(a),d=await qr(a),u=await Gr(a),v=await zr(a);o.push({branch:c,path:a,commit:m.substring(0,8),isCurrent:p,type:l,status:d,lastCommitMessage:u.substring(0,60)+(u.length>60?"...":""),aheadBehind:v})}catch(a){t.warn({error:a,branch:c},`\u26A0\uFE0F Could not process worktree ${c}`)}return o.sort((c,l)=>c.type!==l.type?c.type==="release"?-1:1:c.branch.localeCompare(l.branch))},Ur=async e=>{try{return(await U`git branch --show-current`).stdout.trim()===e}catch{return!1}},Fr=async e=>{try{return(await U`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},qr=async e=>{try{let s=(await U`cd ${e} && git status --porcelain`).stdout.trim().split(`
14
- `).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},Gr=async e=>{try{return(await U`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},zr=async e=>{try{let s=(await U`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),n=s[0]||0,o=s[1]||0;return o===0&&n===0?"up to date":o>0&&n===0?`\u2191${o} ahead`:n>0&&o===0?`\u2193${n} behind`:`\u2191${o} \u2193${n}`}catch{return"unknown"}},Hr=e=>{if(e.length===0){t.info(`
15
- \u{1F33F} Git Worktrees`),t.info("\u2500".repeat(80)),t.info("\u2139\uFE0F No worktrees found"),t.info("\u2500".repeat(80));return}t.info(`
16
- \u{1F33F} Git Worktrees`),t.info("\u2550".repeat(100));let r=e.filter(o=>o.type==="release"),s=e.filter(o=>o.type==="feature");Xe("\u{1F680} Releases",r),s.length>0&&r.length>0&&t.info(""),Xe("\u2728 Features",s);let n=e.find(o=>o.isCurrent);t.info(`
17
- ${"\u2550".repeat(100)}`),t.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${r.length} releases, ${s.length} features)`),n&&t.info(`\u{1F4CD} Currently on: ${n.branch}`),t.info("")},Xe=(e,r)=>{if(r.length!==0){t.info(`
18
- ${e}`),t.info("\u2500".repeat(50));for(let[s,n]of r.entries())Kr(n),s<r.length-1&&t.info("")}},Kr=e=>{let r=e.isCurrent?"\u{1F4CD}":" ",s=Xr(e.status),o=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;t.info(`${r} ${s} ${o}`);let c=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";t.info(` \u{1F4DD} ${e.commit}${c}`),t.info(` \u{1F4AC} ${e.lastCommitMessage}`);let l=e.path.split("/").slice(-2).join("/");t.info(` \u{1F4C1} ${l}`)},Xr=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},ye={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:b.array(b.object({branch:b.string(),path:b.string(),commit:b.string(),isCurrent:b.boolean(),type:b.enum(["release","feature"]),status:b.string(),lastCommitMessage:b.string(),aheadBehind:b.string()})).describe("List of all worktrees with details"),totalCount:b.number().describe("Total number of worktrees"),releaseCount:b.number().describe("Number of release worktrees"),featureCount:b.number().describe("Number of feature worktrees")},handler:Ye};import Yr from"@inquirer/checkbox";import Qr from"@inquirer/confirm";import Zr from"node:process";import{z}from"zod";import{$ as et}from"zx";var Qe=async e=>{let{confirmedCommand:r,all:s}=e;i.start("worktrees-remove");try{let n=await $("release");if(n.length===0)return t.info("\u2139\uFE0F No active worktrees to remove"),i.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let c=`${await y()}${j}`,l=[];s?l=n:(i.setInteractive(),l=await Yr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l.length===n.length;a?i.addOption("--all",!0):i.addOption("--branches",l);let p=r?!0:await Qr({message:"Are you sure you want to proceed with these worktree changes?"});r||i.setInteractive(),p||(t.info("Operation cancelled. Exiting..."),Zr.exit(0)),a&&i.addOption("--yes",!0);let m=await rt(l,c);tt(m),i.print();let d={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(n){throw t.error({error:n},"\u274C Error managing worktrees"),n}},rt=async(e,r)=>{let s=[];for(let n of e)try{let o=`${r}/${n}`;await et`git worktree remove ${o}`,s.push(n)}catch(o){t.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},tt=e=>{e.length>0?(t.info("\u274C Removed worktrees:"),t.info(e.join(`
19
- `)),t.info("")):t.info("\u2139\uFE0F No unused worktrees to remove")},be={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:z.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:z.array(z.string()).describe("List of removed worktree branches"),count:z.number().describe("Number of worktrees removed")},handler:Qe};import ot from"@inquirer/confirm";import st from"node:process";import{z as Re}from"zod";import{$ as nt}from"zx";var it="release/v",Ze=async e=>{let{confirmedCommand:r}=e;i.start("worktrees-sync");try{let s=await $("release"),o=`${await y()}${j}`,c=await h(),l=r?!0:await ot({message:"Are you sure you want to proceed with these worktree changes?"});r||i.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),st.exit(0)),r||i.addOption("--yes",!0);let{branchesToRemove:a}=at({releasePRsList:c,currentWorktrees:s}),p=await ct(a,o);lt(p),i.print();let m={removedWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(s){throw t.error({error:s},"\u274C Error managing worktrees"),s}},at=e=>{let{releasePRsList:r,currentWorktrees:s}=e;return{branchesToRemove:s.filter(c=>c.startsWith(it)).filter(c=>!r.includes(c))}},ct=async(e,r)=>{let s=[];for(let n of e)try{let o=`${r}/${n}`;await nt`git worktree remove ${o}`,s.push(n)}catch(o){t.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},lt=e=>{e.length>0?(t.info("\u274C Removed worktrees:"),t.info(e.join(`
20
- `)),t.info("")):t.info("\u2139\uFE0F No unused worktrees to remove")},ke={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:Re.array(Re.string()).describe("List of removed worktree branches"),count:Re.number().describe("Number of worktrees removed during sync")},handler:Ze};var xe=e=>async r=>{let{toolName:s,handler:n}=e;t.info({msg:`Tool execution started: ${s}`,params:r});try{let o=await n({...r,confirmedCommand:!0});return t.info({msg:`Tool execution successful: ${s}`}),o}catch(o){throw t.error({err:o,params:r,msg:`Tool execution failed: ${s}`}),o}};var mt=[Q,ge,he,oe,ie,ce,pe,de,we,ye,be,ke],er=async e=>{for(let r of mt)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},xe({toolName:r.name,handler:r.handler}))};async function rr(){let e=new pt({name:"infra-kit",version:"0.1.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Ae(e),await Je(e),await er(e),e}await K();var I=Ce(),dt=async()=>{let e;try{e=await rr(),I.info("MCP Server instance created")}catch(r){I.error({err:r,msg:"Failed to create MCP server"}),I.error("Fatal error during server creation."),tr.exit(1)}try{let r=new ut;await e.connect(r),I.info({msg:"Server connected to transport. Ready."})}catch(r){I.error({err:r,msg:"Failed to initialize server"}),I.error("Fatal error during server transport init."),tr.exit(1)}};Se(I);dt();
17
+ `),r.info(`\u{1F4CB} Manual merge script for failed branches:
18
+ `),r.info("```bash");for(let p of a)r.info(`# Phase #1: Merge dev into ${p}`),r.info(`git switch ${p} && git pull origin ${p} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${p} && git switch dev`);r.info(`\u2705 ${o.length-a.length}/${o.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");c.print();let m={successfulMerges:o.length-a.length,failedMerges:a.length,failedBranches:a,totalBranches:o.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Hr=async e=>{try{return await C`git switch ${e}`,await C`git pull origin ${e}`,await C`git merge origin/dev --no-edit`,await C`git push origin ${e}`,await C`git switch dev`,r.info(`Successfully merged dev into ${e}`),!0}catch(t){return r.error({error:t,branch:e},`Error merging dev into ${e}`),await C`git reset --merge HEAD~1`,!1}},ye={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:U.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:U.number().describe("Number of successful merges"),failedMerges:U.number().describe("Number of failed merges"),failedBranches:U.array(U.string()).describe("List of branches that failed to merge"),totalBranches:U.number().describe("Total number of branches processed")},handler:ar};import Qr from"@inquirer/confirm";import Zr from"@inquirer/select";import xe from"node:process";import{z as oe}from"zod";import{$ as S}from"zx";import H from"node:process";var we=async(e,t)=>{try{let{baseUrl:s,token:n,email:o,projectId:i}=t,l={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released||!1,archived:e.archived||!1},a=`${s}/rest/api/3/version`,m=btoa(`${o}:${n}`),p=await fetch(a,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${m}`},body:JSON.stringify(l)});if(!p.ok){let u=await p.text();throw r.error({status:p.status,statusText:p.statusText,error:u},"Failed to create Jira version"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return{success:!0,version:await p.json()}}catch(s){throw r.error({error:s},"Error creating Jira version"),s}},Kr=async e=>{try{let{baseUrl:t,token:s,email:n,projectId:o}=e,i=`${t}/rest/api/3/project/${o}/versions`,l=btoa(`${n}:${s}`),a=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${l}`}});if(!a.ok){let p=await a.text();throw r.error({status:a.status,statusText:a.statusText,error:p},"Failed to get Jira project versions"),new Error(`HTTP ${a.status}: ${a.statusText}`)}return await a.json()}catch(t){throw r.error({error:t},"Error getting Jira project versions"),t}},Xr=async(e,t)=>{try{return(await Kr(t)).find(o=>o.name===e)||null}catch(s){throw r.error({error:s,versionName:e},"Error finding Jira version by name"),s}},Yr=async(e,t)=>{try{let{baseUrl:s,token:n,email:o}=t,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 l=`${s}/rest/api/3/version/${e.versionId}`,a=btoa(`${o}:${n}`),m=await fetch(l,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${a}`},body:JSON.stringify(i)});if(!m.ok){let d=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:d},"Failed to update Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(s){throw r.error({error:s},"Error updating Jira version"),s}},be=async(e,t)=>{try{let{versionName:s}=e,n=await Xr(s,t);if(!n)throw r.error({versionName:s},"Jira version not found"),new Error(`Version "${s}" not found in Jira project`);return await Yr({versionId:n.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(s){throw r.error({error:s},"Error delivering Jira release"),s}},q=async()=>{let e=H.env.JIRA_BASE_URL,t=H.env.JIRA_TOKEN||H.env.JIRA_API_TOKEN,s=H.env.JIRA_PROJECT_ID,n=H.env.JIRA_EMAIL,o=[];if(e||o.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),t||o.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),s||o.push("JIRA_PROJECT_ID (numeric project ID)"),n||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let l=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(a=>` - ${a}`),"","You can set these in your .env file or as environment variables."].join(`
19
+ `);throw new Error(l)}let i=Number.parseInt(s,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${s}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:i,email:n}},Re=async()=>{try{return await q()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var cr=async e=>{let{version:t,confirmedCommand:s}=e;c.start("release-deliver");let n=await h(),o="";t?o=`release/v${t}`:(c.setInteractive(),o=await Zr({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}));let i=o.replace("release/v","");c.addOption("--version",i),n.includes(o)||(r.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),xe.exit(1));let l=s?!0:await Qr({message:`Are you sure you want to deliver version ${o} to production?`});s||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),xe.exit(0)),c.addOption("--yes",!0);try{S.quiet=!0,await S`gh pr merge ${o} --squash --admin --delete-branch`,await S`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (RC)" --body ""`,await S`gh pr merge dev --squash --admin`,S.quiet=!1,await S`gh workflow run deploy-all.yml --ref main -f environment=prod`,S.quiet=!0,await S`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,S.quiet=!1;let a=await Re();if(a)try{let p=o.replace("release/","");await be({versionName:p},a)}catch(p){r.error({error:p},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${o} to production!`),c.print();let m={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(a){r.error({error:a},"\u274C Error merging release branch into dev"),xe.exit(1)}},ke={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:oe.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:oe.string().describe("The release branch that was delivered"),version:oe.string().describe("The version that was delivered"),success:oe.boolean().describe("Whether the delivery was successful")},handler:cr};import lr from"@inquirer/select";import Ce from"node:process";import{z as I}from"zod";import{$ as Ee}from"zx";var pr=async e=>{let{version:t,env:s,skipTerraform:n}=e;c.start("release-deploy-all");let o=["dev"],i=await h();o.push(...i);let l="";t?l=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),l=await lr({message:"\u{1F33F} Select release branch",choices:o.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l==="dev"?"dev":l.replace("release/v","");c.addOption("--version",a),o.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),Ce.exit(1));let m="";s?m=s:(c.setInteractive(),m=await lr({message:"\u{1F9EA} Select environment",choices:b.map(d=>({name:d,value:d}))})),c.addOption("--env",m),b.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),Ce.exit(1));let p=n??!1;p&&c.addOption("--skip-terraform",!0);try{Ee.quiet=!0,await Ee`gh workflow run deploy-all.yml --ref ${l} -f environment=${m} ${p?["-f","skip_terraform_deploy=true"]:[]}`,Ee.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${m}`),c.print();let u={releaseBranch:l,version:l.replace("release/v",""),environment:m,skipTerraformDeploy:p,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(d){r.error({error:d},"\u274C Error launching workflow"),Ce.exit(1)}},$e={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:I.string().describe('Version to deploy (e.g., "1.2.5")'),env:I.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:I.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:I.string().describe("The release branch that was deployed"),version:I.string().describe("The version that was deployed"),environment:I.string().describe("The environment deployed to"),skipTerraformDeploy:I.boolean().describe("Whether terraform deployment was skipped"),success:I.boolean().describe("Whether the deployment was successful")},handler:pr};import et from"@inquirer/checkbox";import mr from"@inquirer/select";import rt from"node:fs/promises";import{resolve as tt}from"node:path";import G from"node:process";import ot from"yaml";import{z as x}from"zod";import{$ as Te}from"zx";var ur=async e=>{let{version:t,env:s,services:n,skipTerraform:o}=e;c.start("release-deploy-selected");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await mr({message:"\u{1F33F} Select release branch",choices:i.map(g=>({name:g.replace("release/v",""),value:g}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),G.exit(1));let p="";s?p=s:(c.setInteractive(),p=await mr({message:"\u{1F9EA} Select environment",choices:b.map(g=>({name:g,value:g}))})),c.addOption("--env",p),b.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),G.exit(1));let d=await st();d.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),G.exit(1));let u=[];n&&n.length>0?u=n:(c.setInteractive(),u=await et({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:d.map(g=>({name:g,value:g}))})),c.addOption("--services",u),u.length===0&&(r.error("\u274C No services selected. Exiting..."),G.exit(1));let y=u.filter(g=>!d.includes(g));y.length>0&&(r.error(`\u274C Invalid services: ${y.join(", ")}. Available services: ${d.join(", ")}`),G.exit(1));let f=o??!1;f&&c.addOption("--skip-terraform",!0);try{Te.quiet=!0;let g=u.flatMap(Ir=>["-f",`${Ir}=true`]);await Te`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${p} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,Te.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${p}, services: ${u.join(", ")}`),c.print();let Ue={releaseBranch:a,version:a.replace("release/v",""),environment:p,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Ue,null,2)}],structuredContent:Ue}}catch(g){r.error({error:g},"\u274C Error launching workflow"),G.exit(1)}},st=async()=>{let e=await v(),t=tt(e,".github/workflows/deploy-selected-services.yml"),s=await rt.readFile(t,"utf-8"),o=ot.parse(s).on.workflow_dispatch.inputs,i=[];for(let[l,a]of Object.entries(o))a.type==="boolean"&&l!=="skip_terraform_deploy"&&i.push(l);return i},Se={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:x.string().describe('Version to deploy (e.g., "1.2.5")'),env:x.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:x.array(x.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:x.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:x.string().describe("The release branch that was deployed"),version:x.string().describe("The version that was deployed"),environment:x.string().describe("The environment deployed to"),services:x.array(x.string()).describe("The services that were deployed"),skipTerraformDeploy:x.boolean().describe("Whether terraform deployment was skipped"),success:x.boolean().describe("Whether the deployment was successful")},handler:ur};import Ae from"@inquirer/select";import nt from"node:fs/promises";import{resolve as it}from"node:path";import se from"node:process";import at from"yaml";import{z as $}from"zod";import{$ as Pe}from"zx";var dr=async e=>{let{version:t,env:s,service:n,skipTerraform:o}=e;c.start("release-deploy-service");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await Ae({message:"\u{1F33F} Select release branch",choices:i.map(f=>({name:f.replace("release/v",""),value:f}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),se.exit(1));let p="";s?p=s:(c.setInteractive(),p=await Ae({message:"\u{1F9EA} Select environment",choices:b.map(f=>({name:f,value:f}))})),c.addOption("--env",p),b.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),se.exit(1));let d=await ct(),u="";n?u=n:(c.setInteractive(),u=await Ae({message:"\u{1F680} Select service to deploy",choices:d.map(f=>({name:f,value:f}))})),c.addOption("--service",u),d.includes(u)||(r.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),se.exit(1));let y=o??!1;y&&c.addOption("--skip-terraform",!0);try{Pe.quiet=!0,await Pe`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${p} -f service=${u} ${y?["-f","skip_terraform_deploy=true"]:[]}`,Pe.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${p}, service: ${u}`),c.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:p,service:u,skipTerraformDeploy:y,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){r.error({error:f},"\u274C Error launching workflow"),se.exit(1)}},ct=async()=>{let e=await v(),t=it(e,".github/workflows/deploy-single-service.yml"),s=await nt.readFile(t,"utf-8");return at.parse(s).on.workflow_dispatch.inputs.service.options},Ie={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:$.string().describe('Version to deploy (e.g., "1.2.5")'),env:$.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:$.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:$.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:$.string().describe("The release branch that was deployed"),version:$.string().describe("The version that was deployed"),environment:$.string().describe("The environment deployed to"),service:$.string().describe("The service that was deployed"),skipTerraformDeploy:$.boolean().describe("Whether terraform deployment was skipped"),success:$.boolean().describe("Whether the deployment was successful")},handler:dr};import{z as Ne}from"zod";var fr=async()=>{let t=(await h()).map(n=>n.replace("release/",""));r.info(`All release branches:
20
+ `),r.info(`
21
+ ${t.join(`
22
+ `)}`);let s={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}},_e={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:Ne.array(Ne.string()).describe("List of all release branches"),count:Ne.number().describe("Number of release branches")},handler:fr};import gr from"@inquirer/confirm";import hr from"node:process";import{z as N}from"zod";import{$ as Oe,question as vr}from"zx";import{$ as K}from"zx";var X=async()=>{K.quiet=!0,await K`git fetch origin`,await K`git switch dev`,await K`git pull origin dev`,K.quiet=!1},Y=async(e,t,s)=>{let n=`v${e}`,o=await we({name:n,projectId:t.projectId,description:s||"",released:!1,archived:!1},t),i=`${t.baseUrl}/projects/${o.version.projectId}/versions/${o.version.id}/tab/release-report-all-issues`,l=await te({version:e,jiraVersionUrl:i});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:i}};var yr=async e=>{let{version:t,description:s,confirmedCommand:n,checkout:o}=e;c.start("release-create");let i=t,l=s,a=o,m=await q();i||(c.setInteractive(),i=await vr("Enter version (e.g. 1.2.5): ")),(!i||i.trim()==="")&&(r.error("No version provided. Exiting..."),hr.exit(1));let p=i.trim();c.addOption("--version",p),l===void 0&&(c.setInteractive(),l=await vr("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&c.addOption("--description",l);let d=n?!0:await gr({message:`Are you sure you want to create release branch for version ${p}?`});n||c.setInteractive(),d||(r.info("Operation cancelled. Exiting..."),hr.exit(0)),c.addOption("--yes",!0),await X();let u=await Y(p,m,l);r.info(`\u2705 Successfully created release: v${p}`),r.info(`\u{1F517} GitHub PR: ${u.prUrl}`),r.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}`),a===void 0&&(c.setInteractive(),a=await gr({message:`Do you want to checkout to the created branch ${u.branchName}?`,default:!0})),a||c.addOption("--no-checkout",!0),a&&(Oe.quiet=!0,await Oe`git switch ${u.branchName}`,Oe.quiet=!1,r.info(`\u{1F504} Switched to branch ${u.branchName}`)),c.print();let y={version:p,branchName:u.branchName,prUrl:u.prUrl,jiraVersionUrl:u.jiraVersionUrl,isCheckedOut:a};return{content:[{type:"text",text:JSON.stringify(y,null,2)}],structuredContent:y}},De={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:N.string().describe('Version to create (e.g., "1.2.5")'),description:N.string().optional().describe("Optional description for the Jira version"),checkout:N.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:N.string().describe("Version number"),branchName:N.string().describe("Release branch name"),prUrl:N.string().describe("GitHub PR URL"),jiraVersionUrl:N.string().describe("Jira version URL"),isCheckedOut:N.boolean().describe("Whether the branch was checked out")},handler:yr};import lt from"@inquirer/confirm";import wr from"node:process";import{z as w}from"zod";import{question as pt}from"zx";var br=async e=>{let{versions:t,description:s,confirmedCommand:n}=e;c.start("release-create-batch");let o=t,i=await q();o||(c.setInteractive(),o=await pt("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=o.split(",").map(f=>f.trim());c.addOption("--versions",l.join(", ")),l.length===0&&(r.error("No versions provided. Exiting..."),wr.exit(1)),l.length===1&&r.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let a=n?!0:await lt({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});n||c.setInteractive(),a||(r.info("Operation cancelled. Exiting..."),wr.exit(0)),c.addOption("--yes",!0),s&&c.addOption("--description",s),await X();let m=[],p=[];for(let f of l)try{let g=await Y(f,i,s);m.push(g),r.info(`\u2705 Successfully created release: v${f}`),r.info(`\u{1F517} GitHub PR: ${g.prUrl}`),r.info(`\u{1F517} Jira Version: ${g.jiraVersionUrl}
23
+ `)}catch(g){let A=g instanceof Error?g.message:String(g);p.push({version:f,error:A}),r.error(`\u274C Failed to create release: v${f}`),r.error(` Error: ${A}
24
+ `)}let d=m.length,u=p.length;d===l.length?r.info(`\u2705 All ${l.length} release branches were created successfully.`):d>0?(r.warn(`\u26A0\uFE0F ${d} of ${l.length} release branches were created successfully.`),r.warn(`\u274C ${u} release(s) failed.`)):r.error(`\u274C All ${l.length} release branches failed to create.`),c.print();let y={createdBranches:m.map(f=>f.branchName),successCount:d,failureCount:u,releases:m,failedReleases:p};return{content:[{type:"text",text:JSON.stringify(y,null,2)}],structuredContent:y}},Je={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:w.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:w.string().optional().describe("Optional description for the Jira versions")},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"),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:br};import mt from"@inquirer/checkbox";import Rr from"@inquirer/confirm";import{copyFileSync as ut,existsSync as dt}from"node:fs";import ft from"node:process";import{z as Q}from"zod";import{$ as je}from"zx";var gt="feature",ht="release",vt="release/v",kr=async e=>{let{confirmedCommand:t,all:s,cursor:n}=e;c.start("worktrees-add");try{let o=await E("release"),i=await v(),l=`${i}${W}`;await xr(`${l}/${ht}`),await xr(`${l}/${gt}`);let a=await h();if(a.length===0)return r.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}};let m=[];s?m=a:(c.setInteractive(),m=await mt({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(A=>({name:A.replace("release/v",""),value:A}))}));let p=m.length===a.length;p?c.addOption("--all",!0):c.addOption("--branches",m);let d=t?!0:await Rr({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),d||(r.info("Operation cancelled. Exiting..."),ft.exit(0)),p&&c.addOption("--yes",!0);let u=n?!0:await Rr({message:"Open created worktrees in Cursor?"});u||c.setInteractive(),u&&c.addOption("--cursor",!0);let{branchesToCreate:y}=yt({selectedReleaseBranches:m,currentWorktrees:o}),f=await wt(y,l,i);if(bt(f),u)for(let A of f)await je`cursor ${l}/${A}`;c.print();let g={createdWorktrees:f,count:f.length};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},xr=async e=>{await je`mkdir -p ${e}`},yt=e=>{let{selectedReleaseBranches:t,currentWorktrees:s}=e,n=s.filter(i=>i.startsWith(vt));return{branchesToCreate:t.filter(i=>!n.includes(i))}},wt=async(e,t,s)=>{let n=[];for(let o of e)try{let i=`${t}/${o}`;await je`git worktree add ${i} ${o}`;let l=`${s}/.env`;dt(l)&&(ut(l,`${i}/.env`),r.info("\u{1F4CB} Copied .env to worktree")),n.push(o)}catch(i){r.error({error:i,branch:o},`\u274C Failed to create worktree for ${o}`)}return n},bt=e=>{e.length>0?(r.info(`
25
+ `),r.info("\u2705 Created worktrees:"),r.info(e.join(`
26
+ `)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},Ve={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:Q.boolean().describe("Add worktrees for all release branches without prompting"),cursor:Q.boolean().optional().describe("Open created worktrees in Cursor")},outputSchema:{createdWorktrees:Q.array(Q.string()).describe("List of created worktree branches"),count:Q.number().describe("Number of worktrees created")},handler:kr};import{z as R}from"zod";import{$ as Z}from"zx";var Er=async()=>{try{let[e,t]=await Promise.all([E("release"),E("feature")]),s=await v(),n=await Rt(e,t,s);Tt(n);let o={worktrees:n,totalCount:n.length,releaseCount:e.length,featureCount:t.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}}catch(e){throw r.error({error:e},"\u274C Error listing worktrees"),e}},Rt=async(e,t,s)=>{let n=[...e.map(i=>({branch:i,type:"release"})),...t.map(i=>({branch:i,type:"feature"}))],o=[];for(let{branch:i,type:l}of n)try{let a=`${s}/${i}`,m=await xt(i),p=await kt(a),d=await Ct(a),u=await Et(a),y=await $t(a);o.push({branch:i,path:a,commit:p.substring(0,8),isCurrent:m,type:l,status:d,lastCommitMessage:u.substring(0,60)+(u.length>60?"...":""),aheadBehind:y})}catch(a){r.warn({error:a,branch:i},`\u26A0\uFE0F Could not process worktree ${i}`)}return o.sort((i,l)=>i.type!==l.type?i.type==="release"?-1:1:i.branch.localeCompare(l.branch))},xt=async e=>{try{return(await Z`git branch --show-current`).stdout.trim()===e}catch{return!1}},kt=async e=>{try{return(await Z`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},Ct=async e=>{try{let s=(await Z`cd ${e} && git status --porcelain`).stdout.trim().split(`
27
+ `).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},Et=async e=>{try{return(await Z`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},$t=async e=>{try{let s=(await Z`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),n=s[0]||0,o=s[1]||0;return o===0&&n===0?"up to date":o>0&&n===0?`\u2191${o} ahead`:n>0&&o===0?`\u2193${n} behind`:`\u2191${o} \u2193${n}`}catch{return"unknown"}},Tt=e=>{if(e.length===0){r.info(`
28
+ \u{1F33F} Git Worktrees`),r.info("\u2500".repeat(80)),r.info("\u2139\uFE0F No worktrees found"),r.info("\u2500".repeat(80));return}r.info(`
29
+ \u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(o=>o.type==="release"),s=e.filter(o=>o.type==="feature");Cr("\u{1F680} Releases",t),s.length>0&&t.length>0&&r.info(""),Cr("\u2728 Features",s);let n=e.find(o=>o.isCurrent);r.info(`
30
+ ${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${s.length} features)`),n&&r.info(`\u{1F4CD} Currently on: ${n.branch}`),r.info("")},Cr=(e,t)=>{if(t.length!==0){r.info(`
31
+ ${e}`),r.info("\u2500".repeat(50));for(let[s,n]of t.entries())St(n),s<t.length-1&&r.info("")}},St=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",s=At(e.status),o=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${s} ${o}`);let i=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${i}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let l=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${l}`)},At=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},Me={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:R.array(R.object({branch:R.string(),path:R.string(),commit:R.string(),isCurrent:R.boolean(),type:R.enum(["release","feature"]),status:R.string(),lastCommitMessage:R.string(),aheadBehind:R.string()})).describe("List of all worktrees with details"),totalCount:R.number().describe("Total number of worktrees"),releaseCount:R.number().describe("Number of release worktrees"),featureCount:R.number().describe("Number of feature worktrees")},handler:Er};import Pt from"@inquirer/checkbox";import It from"@inquirer/confirm";import Nt from"node:process";import{z as ne}from"zod";import{$ as _t}from"zx";var $r=async e=>{let{confirmedCommand:t,all:s}=e;c.start("worktrees-remove");try{let n=await E("release");if(n.length===0)return r.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 i=`${await v()}${W}`,l=[];s?l=n:(c.setInteractive(),l=await Pt({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l.length===n.length;a?c.addOption("--all",!0):c.addOption("--branches",l);let m=t?!0:await It({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),m||(r.info("Operation cancelled. Exiting..."),Nt.exit(0)),a&&c.addOption("--yes",!0);let p=await Ot(l,i);Dt(p),c.print();let d={removedWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(n){throw r.error({error:n},"\u274C Error managing worktrees"),n}},Ot=async(e,t)=>{let s=[];for(let n of e)try{let o=`${t}/${n}`;await _t`git worktree remove ${o}`,s.push(n)}catch(o){r.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},Dt=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
32
+ `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Le={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:ne.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:ne.array(ne.string()).describe("List of removed worktree branches"),count:ne.number().describe("Number of worktrees removed")},handler:$r};import Jt from"@inquirer/confirm";import jt from"node:process";import{z as We}from"zod";import{$ as Vt}from"zx";var Mt="release/v",Tr=async e=>{let{confirmedCommand:t}=e;c.start("worktrees-sync");try{let s=await E("release"),o=`${await v()}${W}`,i=await h(),l=t?!0:await Jt({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),jt.exit(0)),t||c.addOption("--yes",!0);let{branchesToRemove:a}=Lt({releasePRsList:i,currentWorktrees:s}),m=await Wt(a,o);Ft(m),c.print();let p={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(s){throw r.error({error:s},"\u274C Error managing worktrees"),s}},Lt=e=>{let{releasePRsList:t,currentWorktrees:s}=e;return{branchesToRemove:s.filter(i=>i.startsWith(Mt)).filter(i=>!t.includes(i))}},Wt=async(e,t)=>{let s=[];for(let n of e)try{let o=`${t}/${n}`;await Vt`git worktree remove ${o}`,s.push(n)}catch(o){r.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},Ft=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
33
+ `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Fe={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:We.array(We.string()).describe("List of removed worktree branches"),count:We.number().describe("Number of worktrees removed during sync")},handler:Tr};var Be=e=>async t=>{let{toolName:s,handler:n}=e;r.info({msg:`Tool execution started: ${s}`,params:t});try{let o=await n({...t,confirmedCommand:!0});return r.info({msg:`Tool execution successful: ${s}`}),o}catch(o){throw r.error({err:o,params:t,msg:`Tool execution failed: ${s}`}),o}};var Bt=[ge,de,fe,me,ye,De,Je,ke,$e,Se,Ie,_e,Ve,Me,Le,Fe],Sr=async e=>{for(let t of Bt)e.registerTool(t.name,{description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema},Be({toolName:t.name,handler:t.handler}))};async function Ar(){let e=new Ut({name:"infra-kit",version:"0.1.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Xe(e),await Ye(e),await Sr(e),e}await ae();var j=Ge(),Gt=async()=>{let e;try{e=await Ar(),j.info("MCP Server instance created")}catch(t){j.error({err:t,msg:"Failed to create MCP server"}),j.error("Fatal error during server creation."),Pr.exit(1)}try{let t=new qt;await e.connect(t),j.info({msg:"Server connected to transport. Ready."})}catch(t){j.error({err:t,msg:"Failed to initialize server"}),j.error("Fatal error during server transport init."),Pr.exit(1)}};ze(j);Gt();
21
34
  //# sourceMappingURL=mcp.js.map