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