infra-kit 0.1.68 → 0.1.72

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,21 @@
1
- import{StdioServerTransport as dt}from"@modelcontextprotocol/sdk/server/stdio.js";import rr from"node:process";import E from"node:process";import $e from"node:process";import H from"pino";import or from"pino-pretty";var M="/tmp/mcp-infra-kit.log",Te=()=>{let e=$e.argv.includes("--debug")?"debug":"info",r=H({level:e},H.destination({dest:M}));return r.info(`Logger initialized with level: ${e}. Logging to: ${M}`),r},sr=()=>{let e=$e.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),H({level:e},or({ignore:r.join(","),colorize:!0}))},t=sr();var Se=e=>{E.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),E.exit(0)}),E.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),E.exit(0)}),E.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${M}. Shutting down...`),e.flush(),E.exit(1)}),E.on("unhandledRejection",(r,s)=>{e.fatal({reason:r,promise:s,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${M}. Shutting down...`),e.flush(),E.exit(1)})};import{config as ar}from"dotenv";import{resolve as cr}from"node:path";import{$ as Ee}from"zx";import{$ as Ce}from"zx";var $=async e=>{let s=(await Ce`git worktree list`).stdout.split(`
2
- `).filter(Boolean),i={release:ir,feature:nr};return s.map(i[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()||""}`},nr=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},w=async()=>(await Ce`git rev-parse --show-toplevel`).stdout.trim();var K=async()=>{try{Ee.quiet=!0;let e=await w();ar({path:cr(e,".env"),quiet:!0}),t.info("Loaded .env file from git repository root")}catch{}finally{Ee.quiet=!1}};import{McpServer as ut}from"@modelcontextprotocol/sdk/server/mcp.js";var Pe=async e=>{};var Ae=async e=>{};import pr from"@inquirer/checkbox";import ur from"@inquirer/confirm";import dr from"node:process";import{z as J}from"zod";import{$ as x}from"zx";import{$ as Dt}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[i,o,c]=X(r),[l,a,p]=X(s);return i!==l?(i??0)-(l??0):o!==a?(o??0)-(a??0):(c??0)-(p??0)});var v=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(i=>i.headRefName);return Y(s)}catch(e){t.error({error:e},"\u274C Error fetching release PRs"),Ie.exit(1)}},_=async e=>{let{version:r,jiraVersionUrl:s}=e,i=`release/v${r}`;try{k.quiet=!0,await k`git switch dev`,await k`git pull origin dev`,await k`git checkout -b ${i}`,await k`git push -u origin ${i}`,await k`git commit --allow-empty-message --allow-empty --message ''`,await k`git push origin ${i}`;let c=(await k`gh pr create --title "Release v${r}" --body "${s} \n" --base dev --head ${i}`).stdout.trim();return await k`git switch dev`,k.quiet=!1,{branchName:i,prUrl:c}}catch(o){throw t.error({error:o,branchName:i},`Error creating release branch ${i}`),o}};var mr=()=>{let e="",r=[],s=!1;return{start(i){e=i,r=[],s=!1},setInteractive(){s=!0},addOption(i,o){r.push({flag:i,value:o})},print(){if(!s||r.length===0)return;let i=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} ${i}`)},reset(){e="",r=[],s=!1}}},n=mr();var Je=async e=>{let{all:r,confirmedCommand:s}=e;n.start("merge-dev");let i=await v();if(i.length===0)return t.info("\u2139\uFE0F No open release branches found"),n.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=i:(n.setInteractive(),o=await pr({required:!0,message:"\u{1F33F} Select release branches",choices:i.map(m=>({name:m.replace("release/v",""),value:m}))}));let c=o.length===i.length;c?n.addOption("--all",!0):n.addOption("--branches",o);let l=s?!0:await ur({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`});s||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),dr.exit(0)),c&&n.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 fr(m)||a.push(m);if(x.quiet=!1,a.length>0){t.info(`
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(`
3
3
  \u26A0\uFE0F ${a.length} branch(es) failed to merge automatically.
4
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!");n.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}},fr=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:J.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:J.number().describe("Number of successful merges"),failedMerges:J.number().describe("Number of failed merges"),failedBranches:J.array(J.string()).describe("List of branches that failed to merge"),totalBranches:J.number().describe("Total number of branches processed")},handler:Je};import yr from"@inquirer/confirm";import wr from"@inquirer/select";import te from"node:process";import{z as U}from"zod";import{$ as S}from"zx";import D from"node:process";var Z=async(e,r)=>{try{let{baseUrl:s,token:i,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}:${i}`),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}},gr=async e=>{try{let{baseUrl:r,token:s,email:i,projectId:o}=e,c=`${r}/rest/api/3/project/${o}/versions`,l=btoa(`${i}:${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}},hr=async(e,r)=>{try{return(await gr(r)).find(o=>o.name===e)||null}catch(s){throw t.error({error:s,versionName:e},"Error finding Jira version by name"),s}},vr=async(e,r)=>{try{let{baseUrl:s,token:i,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}:${i}`),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,i=await hr(s,r);if(!i)throw t.error({versionName:s},"Jira version not found"),new Error(`Version "${s}" not found in Jira project`);return await vr({versionId:i.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(s){throw t.error({error:s},"Error delivering Jira release"),s}},O=async()=>{let e=D.env.JIRA_BASE_URL,r=D.env.JIRA_TOKEN||D.env.JIRA_API_TOKEN,s=D.env.JIRA_PROJECT_ID,i=D.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)"),i||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:i}},re=async()=>{try{return await O()}catch(e){return t.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var Oe=async e=>{let{version:r,confirmedCommand:s}=e;n.start("release-deliver");let i=await v(),o="";r?o=`release/v${r}`:(n.setInteractive(),o=await wr({message:"\u{1F33F} Select release branch",choices:i.map(a=>({name:a.replace("release/v",""),value:a}))}));let c=o.replace("release/v","");n.addOption("--version",c),i.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||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),te.exit(0)),n.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 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!`),n.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:U.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:U.string().describe("The release branch that was delivered"),version:U.string().describe("The version that was delivered"),success:U.boolean().describe("Whether the delivery was successful")},handler:Oe};import br from"@inquirer/confirm";import Ne from"@inquirer/select";import se from"node:process";import{z as P}from"zod";import{$ as ie}from"zx";var C=["dev","arthur","renana","roman","eliran","oriana"],N="-worktrees";var je=async e=>{let{version:r,env:s,skipTerraform:i}=e;n.start("release-deploy-all");let o=["dev"],c=await v();o.push(...c);let l="";r?l=r==="dev"?"dev":`release/v${r}`:(n.setInteractive(),l=await Ne({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","");n.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:(n.setInteractive(),p=await Ne({message:"\u{1F9EA} Select environment",choices:C.map(d=>({name:d,value:d}))})),n.addOption("--env",p),C.includes(p)||(t.error(`\u274C Invalid environment: ${p}. Exiting...`),se.exit(1));let m=!1;typeof i<"u"?m=i:(n.setInteractive(),m=await br({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),m&&n.addOption("--skip-terraform",!0);try{ie.quiet=!0,await ie`gh workflow run deploy-all.yml --ref ${l} -f environment=${p} ${m?["-f","skip_terraform_deploy=true"]:[]}`,ie.quiet=!1,t.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${p}`),n.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)}},ne={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:P.string().describe('Version to deploy (e.g., "1.2.5")'),env:P.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:P.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:P.string().describe("The release branch that was deployed"),version:P.string().describe("The version that was deployed"),environment:P.string().describe("The environment deployed to"),skipTerraformDeploy:P.boolean().describe("Whether terraform deployment was skipped"),success:P.boolean().describe("Whether the deployment was successful")},handler:je};import Rr from"@inquirer/checkbox";import kr from"@inquirer/confirm";import Me from"@inquirer/select";import xr from"node:fs/promises";import{resolve as $r}from"node:path";import j from"node:process";import Tr from"yaml";import{z as R}from"zod";import{$ as ae}from"zx";var De=async e=>{let{version:r,env:s,services:i,skipTerraform:o}=e;n.start("release-deploy-selected");let c=["dev"],l=await v();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(n.setInteractive(),a=await Me({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","");n.addOption("--version",p),c.includes(a)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),j.exit(1));let m="";s?m=s:(n.setInteractive(),m=await Me({message:"\u{1F9EA} Select environment",choices:C.map(g=>({name:g,value:g}))})),n.addOption("--env",m),C.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),j.exit(1));let d=await Sr();d.length===0&&(t.error("\u274C No services found in workflow file. Exiting..."),j.exit(1));let u=[];i&&i.length>0?u=i:(n.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}))})),n.addOption("--services",u),u.length===0&&(t.error("\u274C No services selected. Exiting..."),j.exit(1));let h=u.filter(g=>!d.includes(g));h.length>0&&(t.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${d.join(", ")}`),j.exit(1));let f=!1;typeof o<"u"?f=o:(n.setInteractive(),f=await kr({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),f&&n.addOption("--skip-terraform",!0);try{ae.quiet=!0;let g=u.flatMap(tr=>["-f",`${tr}=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(", ")}`),n.print();let xe={releaseBranch:a,version:a.replace("release/v",""),environment:m,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(xe,null,2)}],structuredContent:xe}}catch(g){t.error({error:g},"\u274C Error launching workflow"),j.exit(1)}},Sr=async()=>{let e=await w(),r=$r(e,".github/workflows/deploy-selected-services.yml"),s=await xr.readFile(r,"utf-8"),o=Tr.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:De};import Cr from"@inquirer/confirm";import le from"@inquirer/select";import Er from"node:fs/promises";import{resolve as Pr}from"node:path";import q from"node:process";import Ar from"yaml";import{z as T}from"zod";import{$ as me}from"zx";var We=async e=>{let{version:r,env:s,service:i,skipTerraform:o}=e;n.start("release-deploy-service");let c=["dev"],l=await v();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(n.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","");n.addOption("--version",p),c.includes(a)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),q.exit(1));let m="";s?m=s:(n.setInteractive(),m=await le({message:"\u{1F9EA} Select environment",choices:C.map(f=>({name:f,value:f}))})),n.addOption("--env",m),C.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),q.exit(1));let d=await Ir(),u="";i?u=i:(n.setInteractive(),u=await le({message:"\u{1F680} Select service to deploy",choices:d.map(f=>({name:f,value:f}))})),n.addOption("--service",u),d.includes(u)||(t.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),q.exit(1));let h=!1;typeof o<"u"?h=o:(n.setInteractive(),h=await Cr({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),h&&n.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} ${h?["-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}`),n.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:m,service:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){t.error({error:f},"\u274C Error launching workflow"),q.exit(1)}},Ir=async()=>{let e=await w(),r=Pr(e,".github/workflows/deploy-single-service.yml"),s=await Er.readFile(r,"utf-8");return Ar.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:We};import{z as ue}from"zod";var Be=async()=>{let r=(await v()).map(i=>i.replace("release/",""));t.info(`All release 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
7
  `),t.info(`
8
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:Be};import Le from"@inquirer/confirm";import Ve from"node:process";import{z as A}from"zod";import{$ as fe,question as _e}from"zx";import{$ as W}from"zx";var B=async()=>{W.quiet=!0,await W`git fetch origin`,await W`git switch dev`,await W`git pull origin dev`,W.quiet=!1},L=async(e,r,s)=>{let i=`v${e}`,o=await Z({name:i,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 _({version:e,jiraVersionUrl:c});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:c}};var Ue=async e=>{let{version:r,description:s,confirmedCommand:i,checkout:o}=e;n.start("release-create");let c=r,l=s,a=o,p=await O();c||(n.setInteractive(),c=await _e("Enter version (e.g. 1.2.5): ")),(!c||c.trim()==="")&&(t.error("No version provided. Exiting..."),Ve.exit(1));let m=c.trim();n.addOption("--version",m),l===void 0&&(n.setInteractive(),l=await _e("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&n.addOption("--description",l);let d=i?!0:await Le({message:`Are you sure you want to create release branch for version ${m}?`});i||n.setInteractive(),d||(t.info("Operation cancelled. Exiting..."),Ve.exit(0)),n.addOption("--yes",!0),await B();let u=await L(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&&(n.setInteractive(),a=await Le({message:`Do you want to checkout to the created branch ${u.branchName}?`,default:!0})),a||n.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}`)),n.print();let h={version:m,branchName:u.branchName,prUrl:u.prUrl,jiraVersionUrl:u.jiraVersionUrl,isCheckedOut:a};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}},ge={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:A.string().describe('Version to create (e.g., "1.2.5")'),description:A.string().optional().describe("Optional description for the Jira version"),checkout:A.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:A.string().describe("Version number"),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:Ue};import Jr from"@inquirer/confirm";import qe from"node:process";import{z as y}from"zod";import{question as Or}from"zx";var Fe=async e=>{let{versions:r,description:s,confirmedCommand:i}=e;n.start("release-create-batch");let o=r,c=await O();o||(n.setInteractive(),o=await Or("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=o.split(",").map(f=>f.trim());n.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=i?!0:await Jr({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});i||n.setInteractive(),a||(t.info("Operation cancelled. Exiting..."),qe.exit(0)),n.addOption("--yes",!0),s&&n.addOption("--description",s),await B();let p=[],m=[];for(let f of l)try{let g=await L(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 z=g instanceof Error?g.message:String(g);m.push({version:f,error:z}),t.error(`\u274C Failed to create release: v${f}`),t.error(` Error: ${z}
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.`),n.print();let h={createdBranches:p.map(f=>f.branchName),successCount:d,failureCount:u,releases:p,failedReleases:m};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}},he={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:y.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:y.string().optional().describe("Optional description for the Jira versions")},outputSchema:{createdBranches:y.array(y.string()).describe("List of created release branches"),successCount:y.number().describe("Number of releases created successfully"),failureCount:y.number().describe("Number of releases that failed"),releases:y.array(y.object({version:y.string().describe("Version number"),branchName:y.string().describe("Release branch name"),prUrl:y.string().describe("GitHub PR URL"),jiraVersionUrl:y.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:y.array(y.object({version:y.string().describe("Version number that failed"),error:y.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:Fe};import Nr from"@inquirer/checkbox";import jr from"@inquirer/confirm";import Mr from"node:process";import{z as F}from"zod";import{$ as ze}from"zx";var Dr="feature",Wr="release",Br="release/v",He=async e=>{let{confirmedCommand:r,all:s}=e;n.start("worktrees-add");try{let i=await $("release"),c=`${await w()}${N}`;await Ge(`${c}/${Wr}`),await Ge(`${c}/${Dr}`);let l=await v();if(l.length===0)return t.info("\u2139\uFE0F No open release branches found"),n.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};let a=[];s?a=l:(n.setInteractive(),a=await Nr({required:!0,message:"\u{1F33F} Select release branches",choices:l.map(f=>({name:f.replace("release/v",""),value:f}))}));let p=a.length===l.length;p?n.addOption("--all",!0):n.addOption("--branches",a);let m=r?!0:await jr({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),m||(t.info("Operation cancelled. Exiting..."),Mr.exit(0)),p&&n.addOption("--yes",!0);let{branchesToCreate:d}=Lr({selectedReleaseBranches:a,currentWorktrees:i}),u=await Vr(d,c);_r(u),n.print();let h={createdWorktrees:u,count:u.length};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(i){throw t.error({error:i},"\u274C Error managing worktrees"),i}},Ge=async e=>{await ze`mkdir -p ${e}`},Lr=e=>{let{selectedReleaseBranches:r,currentWorktrees:s}=e,i=s.filter(c=>c.startsWith(Br));return{branchesToCreate:r.filter(c=>!i.includes(c))}},Vr=async(e,r)=>{let s=[];for(let i of e)try{let o=`${r}/${i}`;await ze`git worktree add ${o} ${i}`,s.push(i)}catch(o){t.error({error:o,branch:i},`\u274C Failed to create worktree for ${i}`)}return s},_r=e=>{e.length>0?(t.info(`
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
12
  `),t.info("\u2705 Created worktrees:"),t.info(e.join(`
13
- `)),t.info("")):t.info("\u2139\uFE0F No new worktrees to create")},ve={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:F.boolean().describe("Add worktrees for all release branches without prompting")},outputSchema:{createdWorktrees:F.array(F.string()).describe("List of created worktree branches"),count:F.number().describe("Number of worktrees created")},handler:He};import{z as b}from"zod";import{$ as V}from"zx";var Xe=async()=>{try{let[e,r]=await Promise.all([$("release"),$("feature")]),s=await w(),i=await Ur(e,r,s);Kr(i);let o={worktrees:i,totalCount:i.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}},Ur=async(e,r,s)=>{let i=[...e.map(c=>({branch:c,type:"release"})),...r.map(c=>({branch:c,type:"feature"}))],o=[];for(let{branch:c,type:l}of i)try{let a=`${s}/${c}`,p=await qr(c),m=await Fr(a),d=await Gr(a),u=await zr(a),h=await Hr(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:h})}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))},qr=async e=>{try{return(await V`git branch --show-current`).stdout.trim()===e}catch{return!1}},Fr=async e=>{try{return(await V`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},Gr=async e=>{try{let s=(await V`cd ${e} && git status --porcelain`).stdout.trim().split(`
14
- `).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},zr=async e=>{try{return(await V`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},Hr=async e=>{try{let s=(await V`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),i=s[0]||0,o=s[1]||0;return o===0&&i===0?"up to date":o>0&&i===0?`\u2191${o} ahead`:i>0&&o===0?`\u2193${i} behind`:`\u2191${o} \u2193${i}`}catch{return"unknown"}},Kr=e=>{if(e.length===0){t.info(`
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
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");Ke("\u{1F680} Releases",r),s.length>0&&r.length>0&&t.info(""),Ke("\u2728 Features",s);let i=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)`),i&&t.info(`\u{1F4CD} Currently on: ${i.branch}`),t.info("")},Ke=(e,r)=>{if(r.length!==0){t.info(`
18
- ${e}`),t.info("\u2500".repeat(50));for(let[s,i]of r.entries())Xr(i),s<r.length-1&&t.info("")}},Xr=e=>{let r=e.isCurrent?"\u{1F4CD}":" ",s=Yr(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}`)},Yr=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:Xe};import Qr from"@inquirer/checkbox";import Zr from"@inquirer/confirm";import et from"node:process";import{z as G}from"zod";import{$ as rt}from"zx";var Ye=async e=>{let{confirmedCommand:r,all:s}=e;n.start("worktrees-remove");try{let i=await $("release");if(i.length===0)return t.info("\u2139\uFE0F No active worktrees to remove"),n.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let c=`${await w()}${N}`,l=[];s?l=i:(n.setInteractive(),l=await Qr({required:!0,message:"\u{1F33F} Select release branches",choices:i.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l.length===i.length;a?n.addOption("--all",!0):n.addOption("--branches",l);let p=r?!0:await Zr({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),p||(t.info("Operation cancelled. Exiting..."),et.exit(0)),a&&n.addOption("--yes",!0);let m=await tt(l,c);ot(m),n.print();let d={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(i){throw t.error({error:i},"\u274C Error managing worktrees"),i}},tt=async(e,r)=>{let s=[];for(let i of e)try{let o=`${r}/${i}`;await rt`git worktree remove ${o}`,s.push(i)}catch(o){t.error({error:o,branch:i},`\u274C Failed to remove worktree for ${i}`)}return s},ot=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")},we={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:G.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:G.array(G.string()).describe("List of removed worktree branches"),count:G.number().describe("Number of worktrees removed")},handler:Ye};import st from"@inquirer/confirm";import it from"node:process";import{z as be}from"zod";import{$ as nt}from"zx";var at="release/v",Qe=async e=>{let{confirmedCommand:r}=e;n.start("worktrees-sync");try{let s=await $("release"),o=`${await w()}${N}`,c=await v(),l=r?!0:await st({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),it.exit(0)),r||n.addOption("--yes",!0);let{branchesToRemove:a}=ct({releasePRsList:c,currentWorktrees:s}),p=await lt(a,o);mt(p),n.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}},ct=e=>{let{releasePRsList:r,currentWorktrees:s}=e;return{branchesToRemove:s.filter(c=>c.startsWith(at)).filter(c=>!r.includes(c))}},lt=async(e,r)=>{let s=[];for(let i of e)try{let o=`${r}/${i}`;await nt`git worktree remove ${o}`,s.push(i)}catch(o){t.error({error:o,branch:i},`\u274C Failed to remove worktree for ${i}`)}return s},mt=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")},Re={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:be.array(be.string()).describe("List of removed worktree branches"),count:be.number().describe("Number of worktrees removed during sync")},handler:Qe};var ke=e=>async r=>{let{toolName:s,handler:i}=e;t.info({msg:`Tool execution started: ${s}`,params:r});try{let o=await i({...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 pt=[Q,ge,he,oe,ne,ce,pe,de,ve,ye,we,Re],Ze=async e=>{for(let r of pt)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},ke({toolName:r.name,handler:r.handler}))};async function er(){let e=new ut({name:"infra-kit",version:"0.1.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Pe(e),await Ae(e),await Ze(e),e}await K();var I=Te(),ft=async()=>{let e;try{e=await er(),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."),rr.exit(1)}try{let r=new dt;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."),rr.exit(1)}};Se(I);ft();
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();
21
21
  //# sourceMappingURL=mcp.js.map