infra-kit 0.1.75 → 0.1.76
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 +28 -28
- package/dist/cli.js.map +3 -3
- package/dist/mcp.js +28 -28
- package/dist/mcp.js.map +3 -3
- package/package.json +1 -1
- package/src/commands/env-clear/env-clear.ts +4 -5
- package/src/commands/env-init/env-init.ts +5 -19
- package/src/commands/env-load/env-load.ts +17 -15
- package/src/commands/env-status/env-status.ts +2 -15
- package/src/entry/cli.ts +3 -4
- package/src/lib/constants.ts +7 -3
package/dist/mcp.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import{StdioServerTransport as Ht}from"@modelcontextprotocol/sdk/server/stdio.js";import
|
|
2
|
-
`).filter(
|
|
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(`
|
|
3
3
|
`)}
|
|
4
|
-
`),
|
|
5
|
-
`),
|
|
6
|
-
`).filter(Boolean),n={release:
|
|
7
|
-
`),
|
|
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(`
|
|
8
8
|
`)}
|
|
9
|
-
`),
|
|
10
|
-
`);let u=
|
|
11
|
-
`).filter(
|
|
12
|
-
`)
|
|
13
|
-
\u26A0\uFE0F ${
|
|
14
|
-
`),
|
|
15
|
-
`),
|
|
16
|
-
`);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:t,projectId:c,email:n}},Re=async()=>{try{return await B()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var lr=async e=>{let{version:t,confirmedCommand:s}=e;i.start("release-deliver");let n=await v(),o="";t?o=`release/v${t}`:(i.setInteractive(),o=await tt({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}));let c=o.replace("release/v","");i.addOption("--version",c),n.includes(o)||(r.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),xe.exit(1));let l=s?!0:await rt({message:`Are you sure you want to deliver version ${o} to production?`});s||i.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),xe.exit(0)),i.addOption("--yes",!0);try{S.quiet=!0,await S`gh pr merge ${o} --squash --admin --delete-branch`,await S`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (RC)" --body ""`,await S`gh pr merge dev --squash --admin`,S.quiet=!1,await S`gh workflow run deploy-all.yml --ref main -f environment=prod`,S.quiet=!0,await S`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,S.quiet=!1;let a=await Re();if(a)try{let p=o.replace("release/","");await be({versionName:p},a)}catch(p){r.error({error:p},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${o} to production!`),i.print();let m={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(a){r.error({error:a},"\u274C Error merging release branch into dev"),xe.exit(1)}},ke={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:oe.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:oe.string().describe("The release branch that was delivered"),version:oe.string().describe("The version that was delivered"),success:oe.boolean().describe("Whether the delivery was successful")},handler:lr};import pr from"@inquirer/select";import $e from"node:process";import{z as P}from"zod";import{$ as Ee}from"zx";var mr=async e=>{let{version:t,env:s,skipTerraform:n}=e;i.start("release-deploy-all");let o=["dev"],c=await v();o.push(...c);let l="";t?l=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),l=await pr({message:"\u{1F33F} Select release branch",choices:o.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l==="dev"?"dev":l.replace("release/v","");i.addOption("--version",a),o.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),$e.exit(1));let m="";s?m=s:(i.setInteractive(),m=await pr({message:"\u{1F9EA} Select environment",choices:y.map(d=>({name:d,value:d}))})),i.addOption("--env",m),y.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),$e.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,r.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){r.error({error:d},"\u274C Error launching workflow"),$e.exit(1)}},Te={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:mr};import ot from"@inquirer/checkbox";import ur from"@inquirer/select";import st from"node:fs/promises";import{resolve as nt}from"node:path";import U from"node:process";import it from"yaml";import{z as x}from"zod";import{$ as Ce}from"zx";var dr=async e=>{let{version:t,env:s,services:n,skipTerraform:o}=e;i.start("release-deploy-selected");let c=["dev"],l=await v();c.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),a=await ur({message:"\u{1F33F} Select release branch",choices:c.map(g=>({name:g.replace("release/v",""),value:g}))}));let m=a==="dev"?"dev":a.replace("release/v","");i.addOption("--version",m),c.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),U.exit(1));let p="";s?p=s:(i.setInteractive(),p=await ur({message:"\u{1F9EA} Select environment",choices:y.map(g=>({name:g,value:g}))})),i.addOption("--env",p),y.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),U.exit(1));let d=await at();d.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),U.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&&(r.error("\u274C No services selected. Exiting..."),U.exit(1));let h=u.filter(g=>!d.includes(g));h.length>0&&(r.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${d.join(", ")}`),U.exit(1));let f=o??!1;f&&i.addOption("--skip-terraform",!0);try{Ce.quiet=!0;let g=u.flatMap(Nr=>["-f",`${Nr}=true`]);await Ce`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${p} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,Ce.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${p}, services: ${u.join(", ")}`),i.print();let Ue={releaseBranch:a,version:a.replace("release/v",""),environment:p,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Ue,null,2)}],structuredContent:Ue}}catch(g){r.error({error:g},"\u274C Error launching workflow"),U.exit(1)}},at=async()=>{let e=await b(),t=nt(e,".github/workflows/deploy-selected-services.yml"),s=await st.readFile(t,"utf-8"),o=it.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},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:dr};import Ae from"@inquirer/select";import ct from"node:fs/promises";import{resolve as lt}from"node:path";import se from"node:process";import pt from"yaml";import{z as C}from"zod";import{$ as Ie}from"zx";var fr=async e=>{let{version:t,env:s,service:n,skipTerraform:o}=e;i.start("release-deploy-service");let c=["dev"],l=await v();c.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),a=await Ae({message:"\u{1F33F} Select release branch",choices:c.map(f=>({name:f.replace("release/v",""),value:f}))}));let m=a==="dev"?"dev":a.replace("release/v","");i.addOption("--version",m),c.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),se.exit(1));let p="";s?p=s:(i.setInteractive(),p=await Ae({message:"\u{1F9EA} Select environment",choices:y.map(f=>({name:f,value:f}))})),i.addOption("--env",p),y.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),se.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)||(r.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),se.exit(1));let h=o??!1;h&&i.addOption("--skip-terraform",!0);try{Ie.quiet=!0,await Ie`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${p} -f service=${u} ${h?["-f","skip_terraform_deploy=true"]:[]}`,Ie.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${p}, service: ${u}`),i.print();let g={releaseBranch:a,version:a.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){r.error({error:f},"\u274C Error launching workflow"),se.exit(1)}},mt=async()=>{let e=await b(),t=lt(e,".github/workflows/deploy-single-service.yml"),s=await ct.readFile(t,"utf-8");return pt.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:C.string().describe('Version to deploy (e.g., "1.2.5")'),env:C.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:C.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:C.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:C.string().describe("The release branch that was deployed"),version:C.string().describe("The version that was deployed"),environment:C.string().describe("The environment deployed to"),service:C.string().describe("The service that was deployed"),skipTerraformDeploy:C.boolean().describe("Whether terraform deployment was skipped"),success:C.boolean().describe("Whether the deployment was successful")},handler:fr};import{z as Ne}from"zod";var gr=async()=>{let t=(await v()).map(n=>n.replace("release/",""));r.info(`All release branches:
|
|
17
|
-
`),
|
|
18
|
-
${
|
|
19
|
-
`)}`);let
|
|
20
|
-
`)}catch(g){let
|
|
21
|
-
`)}let d=m.length,u=p.length;d===l.length?
|
|
22
|
-
`),
|
|
23
|
-
`)),
|
|
24
|
-
`).filter(Boolean);return
|
|
25
|
-
\u{1F33F} Git Worktrees`),
|
|
26
|
-
\u{1F33F} Git Worktrees`),
|
|
27
|
-
${"\u2550".repeat(100)}`),
|
|
28
|
-
${e}`),
|
|
29
|
-
`)),
|
|
30
|
-
`)),
|
|
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();
|
|
31
31
|
//# sourceMappingURL=mcp.js.map
|