infra-kit 0.1.78 → 0.1.80

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