infra-kit 0.1.67 → 0.1.71
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/cli.js +14 -14
- package/dist/cli.js.map +3 -3
- package/dist/mcp.js +14 -14
- package/dist/mcp.js.map +3 -3
- package/package.json +4 -4
- package/src/commands/gh-merge-dev/gh-merge-dev.ts +23 -4
- package/src/commands/gh-release-deliver/gh-release-deliver.ts +6 -4
- package/src/commands/gh-release-deploy-all/gh-release-deploy-all.ts +13 -8
- package/src/commands/gh-release-deploy-selected/gh-release-deploy-selected.ts +30 -14
- package/src/commands/gh-release-deploy-service/gh-release-deploy-service.ts +19 -12
- package/src/commands/gh-release-list/gh-release-list.ts +3 -1
- package/src/commands/release-create-batch/release-create-batch.ts +6 -2
- package/src/commands/worktrees-add/worktrees-add.ts +54 -9
- package/src/commands/worktrees-list/worktrees-list.ts +19 -5
- package/src/commands/worktrees-remove/worktrees-remove.ts +19 -4
- package/src/commands/worktrees-sync/worktrees-sync.ts +7 -2
- package/src/entry/cli.ts +2 -1
- package/src/integrations/gh/gh-release-prs/gh-release-prs.ts +4 -1
- package/src/integrations/jira/api.ts +8 -2
- package/src/lib/git-utils/git-utils.ts +3 -1
- package/src/lib/tool-handler/tool-handler.ts +16 -14
- package/src/lib/version-utils/version-utils.ts +1 -0
package/dist/mcp.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import{StdioServerTransport as
|
|
2
|
-
`).filter(Boolean),i={release:
|
|
1
|
+
import{StdioServerTransport as gt}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",Se=()=>{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},ir=()=>{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=ir();var Ce=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),i={release:nr,feature:ar};return s.map(i[e]).filter(o=>o!==null)},nr=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()||""}`},w=async()=>(await Ee`git rev-parse --show-toplevel`).stdout.trim();var K=async()=>{try{Pe.quiet=!0;let e=await w();cr({path:lr(e,".env"),quiet:!0}),t.info("Loaded .env file from git repository root")}catch{}finally{Pe.quiet=!1}};import{McpServer as ft}from"@modelcontextprotocol/sdk/server/mcp.js";var Ae=async e=>{};var Ie=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 Bt}from"zx";import Je 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..."),Je.exit(1));let s=r.map(i=>i.headRefName);return Y(s)}catch(e){t.error({error:e},"\u274C Error fetching release PRs"),Je.exit(1)}},F=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 pr=()=>{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=pr();var Oe=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 ur({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 dr({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`});s||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),fr.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 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}},
|
|
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 yr({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 wr({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 je 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"],j="-worktrees";var Me=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 je({message:"\u{1F33F} Select release branch",choices:o.map(u=>({name:u.replace("release/v",""),value:u}))}));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 je({message:"\u{1F9EA} Select environment",choices:C.map(u=>({name:u,value:u}))})),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 d={releaseBranch:l,version:l.replace("release/v",""),environment:p,skipTerraformDeploy:m,success:!0};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(u){t.error({error:u},"\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:Me};import Rr from"@inquirer/checkbox";import kr from"@inquirer/confirm";import Ne from"@inquirer/select";import xr from"node:fs/promises";import{resolve as $r}from"node:path";import D 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 Ne({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...`),D.exit(1));let m="";s?m=s:(n.setInteractive(),m=await Ne({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...`),D.exit(1));let u=await Sr(),d=[];i&&i.length>0?d=i:(n.setInteractive(),d=await Rr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:u.map(g=>({name:g,value:g}))})),n.addOption("--services",d),d.length===0&&(t.error("\u274C No services selected. Exiting..."),D.exit(1));let h=d.filter(g=>!u.includes(g));h.length>0&&(t.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${u.join(", ")}`),D.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=d.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: ${d.join(", ")}`),n.print();let xe={releaseBranch:a,version:a.replace("release/v",""),environment:m,services:d,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"),D.exit(1)}},Sr=async()=>{let e=await y(),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 u=await Ir(),d="";i?d=i:(n.setInteractive(),d=await le({message:"\u{1F680} Select service to deploy",choices:u.map(f=>({name:f,value:f}))})),n.addOption("--service",d),u.includes(d)||(t.error(`\u274C Invalid service: ${d}. Available services: ${u.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=${d} ${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: ${d}`),n.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:m,service:d,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 y(),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 de}from"zod";var Le=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!");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}},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 wr from"@inquirer/confirm";import br from"@inquirer/select";import te from"node:process";import{z as q}from"zod";import{$ as S}from"zx";import W 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}},hr=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}},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}},yr=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 vr(s,r);if(!i)throw t.error({versionName:s},"Jira version not found"),new Error(`Version "${s}" not found in Jira project`);return await yr({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}},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,i=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)"),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 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;n.start("release-deliver");let i=await v(),o="";r?o=`release/v${r}`:(n.setInteractive(),o=await br({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 wr({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: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 Rr from"@inquirer/confirm";import je from"@inquirer/select";import se from"node:process";import{z as A}from"zod";import{$ as ie}from"zx";var C=["dev","arthur","renana","roman","eliran","oriana"],j="-worktrees";var Me=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 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","");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 je({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 Rr({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: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 kr from"@inquirer/checkbox";import xr from"@inquirer/confirm";import De from"@inquirer/select";import $r from"node:fs/promises";import{resolve as Tr}from"node:path";import M from"node:process";import Sr from"yaml";import{z as R}from"zod";import{$ as ae}from"zx";var We=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 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","");n.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:(n.setInteractive(),m=await De({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...`),M.exit(1));let d=await Cr();d.length===0&&(t.error("\u274C No services found in workflow file. Exiting..."),M.exit(1));let u=[];i&&i.length>0?u=i:(n.setInteractive(),u=await kr({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..."),M.exit(1));let h=u.filter(g=>!d.includes(g));h.length>0&&(t.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${d.join(", ")}`),M.exit(1));let f=!1;typeof o<"u"?f=o:(n.setInteractive(),f=await xr({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),f&&n.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(", ")}`),n.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)}},Cr=async()=>{let e=await w(),r=Tr(e,".github/workflows/deploy-selected-services.yml"),s=await $r.readFile(r,"utf-8"),o=Sr.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 Er from"@inquirer/confirm";import le from"@inquirer/select";import Pr from"node:fs/promises";import{resolve as Ar}from"node:path";import G from"node:process";import Ir from"yaml";import{z as T}from"zod";import{$ as me}from"zx";var Be=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...`),G.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...`),G.exit(1));let d=await Jr(),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(", ")}`),G.exit(1));let h=!1;typeof o<"u"?h=o:(n.setInteractive(),h=await Er({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"),G.exit(1)}},Jr=async()=>{let e=await w(),r=Ar(e,".github/workflows/deploy-single-service.yml"),s=await Pr.readFile(r,"utf-8");return Ir.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 v()).map(i=>i.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}},
|
|
10
|
-
`)}catch(g){let
|
|
11
|
-
`)}let
|
|
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 I}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 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 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:i,checkout:o}=e;n.start("release-create");let c=r,l=s,a=o,p=await N();c||(n.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();n.addOption("--version",m),l===void 0&&(n.setInteractive(),l=await Ue("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&n.addOption("--description",l);let d=i?!0:await Ve({message:`Are you sure you want to create release branch for version ${m}?`});i||n.setInteractive(),d||(t.info("Operation cancelled. Exiting..."),_e.exit(0)),n.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&&(n.setInteractive(),a=await Ve({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:I.string().describe('Version to create (e.g., "1.2.5")'),description:I.string().optional().describe("Optional description for the Jira version"),checkout:I.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:I.string().describe("Version number"),branchName:I.string().describe("Release branch name"),prUrl:I.string().describe("GitHub PR URL"),jiraVersionUrl:I.string().describe("Jira version URL"),isCheckedOut:I.boolean().describe("Whether the branch was checked out")},handler:Fe};import Or from"@inquirer/confirm";import qe from"node:process";import{z as y}from"zod";import{question as Nr}from"zx";var Ge=async e=>{let{versions:r,description:s,confirmedCommand:i}=e;n.start("release-create-batch");let o=r,c=await N();o||(n.setInteractive(),o=await Nr("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 Or({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 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.`),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:Ge};import jr from"@inquirer/checkbox";import ze from"@inquirer/confirm";import{copyFileSync as Mr,existsSync as Dr}from"node:fs";import Wr from"node:process";import{z as _}from"zod";import{$ as ve}from"zx";var Br="feature",Lr="release",Vr="release/v",Ke=async e=>{let{confirmedCommand:r,all:s,cursor:i}=e;n.start("worktrees-add");try{let o=await $("release"),c=await w(),l=`${c}${j}`;await He(`${l}/${Lr}`),await He(`${l}/${Br}`);let a=await v();if(a.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 p=[];s?p=a:(n.setInteractive(),p=await jr({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?n.addOption("--all",!0):n.addOption("--branches",p);let d=r?!0:await ze({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),d||(t.info("Operation cancelled. Exiting..."),Wr.exit(0)),m&&n.addOption("--yes",!0);let u=i?!0:await ze({message:"Open created worktrees in Cursor?"});u||n.setInteractive(),u&&n.addOption("--cursor",!0);let{branchesToCreate:h}=_r({selectedReleaseBranches:p,currentWorktrees:o}),f=await Ur(h,l,c);if(Fr(f),u)for(let E of f)await ve`cursor ${l}/${E}`;n.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}`},_r=e=>{let{selectedReleaseBranches:r,currentWorktrees:s}=e,i=s.filter(c=>c.startsWith(Vr));return{branchesToCreate:r.filter(c=>!i.includes(c))}},Ur=async(e,r,s)=>{let i=[];for(let o of e)try{let c=`${r}/${o}`;await ve`git worktree add ${c} ${o}`;let l=`${s}/.env`;Dr(l)&&(Mr(l,`${c}/.env`),t.info("\u{1F4CB} Copied .env to worktree")),i.push(o)}catch(c){t.error({error:c,branch:o},`\u274C Failed to create worktree for ${o}`)}return i},Fr=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")},
|
|
14
|
-
`).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},
|
|
13
|
+
`)),t.info("")):t.info("\u2139\uFE0F No new worktrees to create")},ye={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 w(),i=await qr(e,r,s);Yr(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}},qr=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 Gr(c),m=await zr(a),d=await Hr(a),u=await Kr(a),h=await Xr(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))},Gr=async e=>{try{return(await U`git branch --show-current`).stdout.trim()===e}catch{return!1}},zr=async e=>{try{return(await U`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},Hr=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"}},Kr=async e=>{try{return(await U`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},Xr=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),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"}},Yr=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");
|
|
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("")},
|
|
18
|
-
${e}`),t.info("\u2500".repeat(50));for(let[s,i]of r.entries())
|
|
19
|
-
`)),t.info("")):t.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
20
|
-
`)),t.info("")):t.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
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 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("")},Xe=(e,r)=>{if(r.length!==0){t.info(`
|
|
18
|
+
${e}`),t.info("\u2500".repeat(50));for(let[s,i]of r.entries())Qr(i),s<r.length-1&&t.info("")}},Qr=e=>{let r=e.isCurrent?"\u{1F4CD}":" ",s=Zr(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}`)},Zr=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},we={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 et from"@inquirer/checkbox";import rt from"@inquirer/confirm";import tt from"node:process";import{z}from"zod";import{$ as ot}from"zx";var Qe=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()}${j}`,l=[];s?l=i:(n.setInteractive(),l=await et({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 rt({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),p||(t.info("Operation cancelled. Exiting..."),tt.exit(0)),a&&n.addOption("--yes",!0);let m=await st(l,c);it(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}},st=async(e,r)=>{let s=[];for(let i of e)try{let o=`${r}/${i}`;await ot`git worktree remove ${o}`,s.push(i)}catch(o){t.error({error:o,branch:i},`\u274C Failed to remove worktree for ${i}`)}return s},it=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 nt from"@inquirer/confirm";import at from"node:process";import{z as Re}from"zod";import{$ as ct}from"zx";var lt="release/v",Ze=async e=>{let{confirmedCommand:r}=e;n.start("worktrees-sync");try{let s=await $("release"),o=`${await w()}${j}`,c=await v(),l=r?!0:await nt({message:"Are you sure you want to proceed with these worktree changes?"});r||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),at.exit(0)),r||n.addOption("--yes",!0);let{branchesToRemove:a}=mt({releasePRsList:c,currentWorktrees:s}),p=await pt(a,o);ut(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}},mt=e=>{let{releasePRsList:r,currentWorktrees:s}=e;return{branchesToRemove:s.filter(c=>c.startsWith(lt)).filter(c=>!r.includes(c))}},pt=async(e,r)=>{let s=[];for(let i of e)try{let o=`${r}/${i}`;await ct`git worktree remove ${o}`,s.push(i)}catch(o){t.error({error:o,branch:i},`\u274C Failed to remove worktree for ${i}`)}return s},ut=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: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 dt=[Q,ge,he,oe,ne,ce,pe,de,ye,we,be,ke],er=async e=>{for(let r of dt)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 ft({name:"infra-kit",version:"0.1.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Ae(e),await Ie(e),await er(e),e}await K();var J=Se(),ht=async()=>{let e;try{e=await rr(),J.info("MCP Server instance created")}catch(r){J.error({err:r,msg:"Failed to create MCP server"}),J.error("Fatal error during server creation."),tr.exit(1)}try{let r=new gt;await e.connect(r),J.info({msg:"Server connected to transport. Ready."})}catch(r){J.error({err:r,msg:"Failed to initialize server"}),J.error("Fatal error during server transport init."),tr.exit(1)}};Ce(J);ht();
|
|
21
21
|
//# sourceMappingURL=mcp.js.map
|