infra-kit 0.1.89 → 0.1.91
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/.eslintcache +1 -1
- package/.turbo/turbo-eslint-check.log +1 -1
- package/.turbo/turbo-prettier-check.log +1 -1
- package/.turbo/turbo-test.log +7 -6
- package/.turbo/turbo-ts-check.log +1 -1
- package/dist/cli.js +31 -30
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +24 -23
- package/dist/mcp.js.map +4 -4
- package/package.json +4 -4
- package/src/commands/env-clear/env-clear.ts +9 -17
- package/src/commands/env-list/env-list.ts +6 -5
- package/src/commands/env-load/__tests__/env-load.test.ts +132 -0
- package/src/commands/env-load/env-load.ts +95 -14
- package/src/commands/env-status/env-status.ts +8 -0
- package/src/commands/init/init.ts +8 -5
- package/src/commands/version/index.ts +1 -0
- package/src/commands/version/version.ts +38 -0
- package/src/commands/worktrees-add/worktrees-add.ts +36 -3
- package/src/entry/cli.ts +30 -3
- package/src/integrations/cmux/index.ts +1 -0
- package/src/integrations/cmux/open-workspace-with-layout.ts +41 -0
- package/src/integrations/doppler/doppler-cli-auth.ts +9 -11
- package/src/lib/__tests__/constants.test.ts +160 -0
- package/src/lib/__tests__/infra-kit-config.test.ts +129 -0
- package/src/lib/constants.ts +50 -11
- package/src/lib/git-utils/git-utils.ts +36 -0
- package/src/lib/git-utils/index.ts +1 -1
- package/src/lib/infra-kit-config.ts +33 -13
- package/src/mcp/tools/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +14 -11
package/dist/mcp.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import{StdioServerTransport as
|
|
2
|
-
`).
|
|
1
|
+
import{StdioServerTransport as co}from"@modelcontextprotocol/sdk/server/stdio.js";import Hr from"node:process";import _ from"node:process";import lr from"node:process";import Ie from"pino";import zr from"pino-pretty";var re="/tmp/mcp-infra-kit.log",pr=()=>{let e=lr.argv.includes("--debug")?"debug":"info",r=Ie({level:e},Ie.destination({dest:re}));return r.info(`Logger initialized with level: ${e}. Logging to: ${re}`),r},Yr=()=>{let e=lr.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),Ie({level:e},zr({destination:2,ignore:r.join(","),colorize:!0}))},n=Yr();var mr=e=>{_.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),_.exit(0)}),_.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),_.exit(0)}),_.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${re}. Shutting down...`),e.flush(),_.exit(1)}),_.on("unhandledRejection",(r,t)=>{e.fatal({reason:r,promise:t,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${re}. Shutting down...`),e.flush(),_.exit(1)})};import{McpServer as ao}from"@modelcontextprotocol/sdk/server/mcp.js";var ur=async e=>{};var fr=async e=>{};import Ne from"node:fs";import hr from"node:path";import Qr from"node:process";import{z as Re}from"zod";import te from"node:fs";import Xr from"node:os";import Se from"node:path";import Ae from"node:process";var V="env-load.sh",dr="env-clear.sh",ge="INFRA_KIT_SESSION",F="INFRA_KIT_ENV_CONFIG",W="INFRA_KIT_ENV_PROJECT",B="INFRA_KIT_ENV_LOADED_AT",ve=/^([A-Z_]\w*)=/i,ye=e=>{if(!te.existsSync(e))return[];let r=te.readFileSync(e,"utf-8"),t=[];for(let s of r.split(`
|
|
2
|
+
`)){let o=ve.exec(s);o&&t.push(o[1])}return t},Zr=()=>{let e=Ae.env.XDG_CACHE_HOME,r=e&&e.length>0?e:Se.join(Xr.homedir(),".cache");return Se.join(r,"infra-kit")},q=()=>{let e=Ae.env[ge];if(!e)throw new Error(`${ge} is not set. Run \`infra-kit init\` then \`source ~/.zshrc\`.`);return Se.join(Zr(),e)},we=(e,r,t)=>{let s=`${e}.tmp.${Ae.pid}`;te.writeFileSync(s,r,{mode:t});try{te.renameSync(s,e)}catch(o){throw te.rmSync(s,{force:!0}),o}},U="-worktrees";var gr=async()=>{let e=q(),r=hr.join(e,V);if(!Ne.existsSync(r))throw new Error("No loaded environment found. Run `env-load` first.");let t=ye(r),s=[...t.map(a=>`unset ${a}`),`unset ${F}`,`unset ${W}`,`unset ${B}`],o=hr.resolve(e,dr);Ne.mkdirSync(e,{recursive:!0,mode:448}),we(o,`${s.join(`
|
|
3
3
|
`)}
|
|
4
|
-
|
|
5
|
-
`),
|
|
6
|
-
`).filter(Boolean),
|
|
7
|
-
`),
|
|
8
|
-
pnpm exec infra-kit ${e} ${
|
|
9
|
-
`)},reset(){e="",r=[],t=!1}}},
|
|
4
|
+
`,384),Qr.stdout.write(`${o}
|
|
5
|
+
`),Ne.unlinkSync(r);let i={filePath:o,variableCount:t.length,unsetStatements:s};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Oe={name:"env-clear",description:'Generate a shell script that unsets every env var previously loaded by env-load for this session, plus the infra-kit session metadata vars. Does NOT mutate the calling process. When `infra-kit init` has installed the zsh shell integration, the user\'s terminal auto-sources the unset script on its next prompt (precmd hook) \u2014 so calling this via MCP will clear the vars in the shell that launched Claude Code automatically. Other callers must source "<filePath>" themselves or surface it to the user. Errors if no env is currently loaded.',inputSchema:{},outputSchema:{filePath:Re.string().describe("Path to the file that must be sourced to apply"),variableCount:Re.number().describe("Number of variables cleared"),unsetStatements:Re.array(Re.string()).describe("Unset statements generated")},handler:gr};import{z as Me}from"zod";import yr from"node:fs/promises";import ot from"node:path";import st from"yaml";import{z as $}from"zod";import et from"node:path";import{$ as vr}from"zx";var O=async e=>{let t=(await vr`git worktree list`).stdout.split(`
|
|
6
|
+
`).filter(Boolean),s={release:rt,feature:tt};return t.map(s[e]).filter(o=>o!==null)},rt=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("release/v")?null:`release/${r[0]?.split("/").pop()||""}`},tt=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},k=async()=>(await vr`git rev-parse --show-toplevel`).stdout.trim(),_e=async()=>{let e=await k();return et.basename(e)};var nt="infra-kit.yml",it=$.object({type:$.literal("jira"),baseUrl:$.string().url(),projectId:$.number().int().positive()}),at=$.object({dopplerProjectName:$.string().min(1),environments:$.array($.string().min(1)).min(1),taskManagerProvider:$.union([$.string(),$.literal(!1),it])}),oe=null,S=async()=>{let e=await k(),r=ot.join(e,nt),t;try{t=await yr.stat(r)}catch{throw oe=null,new Error(`infra-kit.yml not found at ${r}`)}if(oe&&oe.mtimeMs===t.mtimeMs)return oe.value;let s=await yr.readFile(r,"utf-8"),o=st.parse(s),i=at.safeParse(o);if(!i.success)throw new Error(`Invalid infra-kit.yml at ${r}: ${i.error.message}`);return oe={mtimeMs:t.mtimeMs,value:i.data},i.data};var se=async()=>{let{dopplerProjectName:e}=await S();return e};var wr=async()=>{let e=await se(),{environments:r}=await S();n.info(`Doppler project: ${e}
|
|
7
|
+
`),n.info("Available configs:");for(let s of r)n.info(` - ${s}`);let t={project:e,configs:r};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},De={name:"env-list",description:"List the environments the project is configured to support. Returns the `environments` list declared in infra-kit.yml at the project root (not a live fetch from Doppler) plus the Doppler project name resolved from the same file. Read-only.",inputSchema:{},outputSchema:{project:Me.string().describe("Detected Doppler project name"),configs:Me.array(Me.string()).describe("Available environment configs")},handler:wr};import lt from"@inquirer/select";import{Buffer as pt}from"node:buffer";import mt from"node:fs";import ut from"node:path";import br from"node:process";import{z as ie}from"zod";import{$ as be}from"zx";import{$ as Rr}from"zx";var ne=async()=>{try{await Rr`doppler --version`}catch(e){throw new Error("Doppler CLI is not installed. Install it from: https://docs.doppler.com/docs/install-cli",{cause:e})}try{await Rr`doppler me`}catch(e){throw new Error("Doppler CLI is not authenticated. Run: doppler login",{cause:e})}};var ct=()=>{let e="",r=[],t=!1;return{start(s){e=s,r=[],t=!1},setInteractive(){t=!0},addOption(s,o){r.push({flag:s,value:o})},print(){if(!t||r.length===0)return;let s=r.map(o=>typeof o.value=="boolean"?o.value?o.flag:"":Array.isArray(o.value)?`${o.flag} "${o.value.join(", ")}"`:`${o.flag} "${o.value}"`).filter(Boolean).join(" ");n.info(`\u{1F4DF} Equivalent command:
|
|
8
|
+
pnpm exec infra-kit ${e} ${s}
|
|
9
|
+
`)},reset(){e="",r=[],t=!1}}},c=ct();var kr=async e=>{await ne();let{config:r}=e;c.start("env-load");let t="";if(r)t=r;else{let{environments:f}=await S();c.setInteractive(),t=await lt({message:"Select environment config",choices:f.map(h=>({name:h,value:h}))},{output:br.stderr})}c.addOption("--config",t);let s=await se(),o=await dt(s,t);yt(o);let i=new Date().toISOString(),a=["set -a",o,`${F}=${Je(t)}`,`${W}=${Je(s)}`,`${B}=${Je(i)}`,"set +a"],p=q(),l=ut.resolve(p,V);mt.mkdirSync(p,{recursive:!0,mode:448}),we(l,`${a.join(`
|
|
10
10
|
`)}
|
|
11
|
-
|
|
12
|
-
`);let u=
|
|
13
|
-
`).filter(
|
|
14
|
-
`)}
|
|
15
|
-
`)
|
|
16
|
-
`);
|
|
17
|
-
\
|
|
18
|
-
|
|
11
|
+
`,384),br.stdout.write(`${l}
|
|
12
|
+
`),c.print();let m=gt(o),u={filePath:l,variableCount:m,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}},xr=1024*1024,ft=3e4,dt=async(e,r)=>{let t=be.quiet;be.quiet=!0;try{let s=await be`doppler secrets download --no-file --format env --project ${e} --config ${r}`.timeout(ft);return ht(s.stdout),s.stdout.trim()}finally{be.quiet=t}},ht=e=>{let r=pt.byteLength(e,"utf-8");if(r>xr)throw new Error(`doppler returned unexpectedly large output (${r} bytes > ${xr}) \u2014 refusing to write to disk`)},gt=e=>e.split(`
|
|
13
|
+
`).filter(r=>ve.test(r)).length,vt=new Set(["set -a","set +a"]),Je=e=>`'${e.replaceAll("'","'\\''")}'`,yt=e=>{if(e.trim().length===0)throw new Error("doppler returned empty output for env-load");for(let r of e.split(`
|
|
14
|
+
`)){let t=r.trim();if(!(t.length===0||vt.has(t))&&!ve.test(t))throw new Error(`doppler returned unexpected output for env-load (expected KEY=value lines, got: ${JSON.stringify(t.slice(0,80))})`)}},je={name:"env-load",description:'Download the env vars for a Doppler config and write them to a temporary shell script. Does NOT mutate the calling process \u2014 returns the path to a script that must be sourced ("source <filePath>") for the vars to take effect. The infra-kit shell wrapper auto-sources; direct MCP callers must handle sourcing themselves or surface filePath to the user. "config" is required when invoked via MCP (the CLI interactive picker is unreachable without a TTY).',inputSchema:{config:ie.string().describe('Doppler config / environment name to load (e.g. "dev", "arthur", "renana"). Required for MCP calls.')},outputSchema:{filePath:ie.string().describe("Path to the file that must be sourced to apply variables"),variableCount:ie.number().describe("Number of variables loaded"),project:ie.string().describe("Doppler project name"),config:ie.string().describe("Doppler config name")},handler:kr};import wt from"node:path";import ae from"node:process";import{z as G}from"zod";var Tr=async()=>{await ne(),n.info("Environment session status:");let e=q(),r=ae.env[ge],t=wt.join(e,V),s=0,o=0,i=ae.env[F]??null,a=ae.env[W]??null,p=ae.env[B]??null;if(i){let m=ye(t);m.length>0&&(o=m.length,s=m.filter(f=>f in ae.env).length);let u=p?.replace(/\.\d{3}Z$/,"")??null;if(n.info(` ${i}: ${s} of ${o} vars loaded (project: ${a}, loadedAt: ${u}, session: ${r})
|
|
15
|
+
`),o>0&&s<o){let f=o-s;n.warn(` ${f} cached var(s) are not present in the current process \u2014 env-load needs to be re-sourced, or vars were unset manually.`)}}else n.info(` Session ${r}: no env loaded
|
|
16
|
+
`);let l={sessionId:r,sessionLoadedCount:s,sessionTotalCount:o,sessionConfig:i,sessionProject:a,sessionLoadedAt:p};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},Le={name:"env-status",description:"Report which Doppler project/config is currently loaded in the terminal session, when it was loaded, and how many variables are cached. Read-only \u2014 use env-load / env-clear to change the terminal session.",inputSchema:{},outputSchema:{sessionId:G.string().describe("Current terminal session ID"),sessionLoadedCount:G.number().describe("Number of cached vars active in the current session"),sessionTotalCount:G.number().describe("Total number of cached var names"),sessionConfig:G.string().nullable().describe("Doppler config name of the loaded session (environment name)"),sessionProject:G.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:G.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:Tr};import kt from"@inquirer/checkbox";import Tt from"@inquirer/confirm";import Ct from"node:process";import{z}from"zod";import{$ as P}from"zx";import{$ as Os}from"zx";import $e from"node:process";import{$ as T}from"zx";import{$ as pe}from"zx";import ce from"node:process";var Ve=async(e,r)=>{try{let{baseUrl:t,token:s,email:o,projectId:i}=r,a={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released||!1,archived:e.archived||!1},p=`${t}/rest/api/3/version`,l=btoa(`${o}:${s}`),m=await fetch(p,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(a)});if(!m.ok){let f=await m.text();throw n.error({status:m.status,statusText:m.statusText,error:f},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(t){throw n.error({error:t},"Error creating Jira version"),t}},xe=async e=>{try{let{baseUrl:r,token:t,email:s,projectId:o}=e,i=`${r}/rest/api/3/project/${o}/versions`,a=btoa(`${s}:${t}`),p=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${a}`}});if(!p.ok){let m=await p.text();throw n.error({status:p.status,statusText:p.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return await p.json()}catch(r){throw n.error({error:r},"Error getting Jira project versions"),r}},bt=async(e,r)=>{try{return(await xe(r)).find(o=>o.name===e)||null}catch(t){throw n.error({error:t,versionName:e},"Error finding Jira version by name"),t}},xt=async(e,r)=>{try{let{baseUrl:t,token:s,email:o}=r,i={released:e.released??!0,archived:e.archived??!1};e.releaseDate?i.releaseDate=e.releaseDate:e.released!==!1&&(i.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(i.description=e.description);let a=`${t}/rest/api/3/version/${e.versionId}`,p=btoa(`${o}:${s}`),l=await fetch(a,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${p}`},body:JSON.stringify(i)});if(!l.ok){let u=await l.text();throw n.error({status:l.status,statusText:l.statusText,error:u},"Failed to update Jira version"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return{success:!0,version:await l.json()}}catch(t){throw n.error({error:t},"Error updating Jira version"),t}},Fe=async(e,r)=>{try{let{versionName:t}=e,s=await bt(t,r);if(!s)throw n.error({versionName:t},"Jira version not found"),new Error(`Version "${t}" not found in Jira project`);return await xt({versionId:s.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(t){throw n.error({error:t},"Error delivering Jira release"),t}},H=async()=>{let e=ce.env.JIRA_BASE_URL,r=ce.env.JIRA_TOKEN||ce.env.JIRA_API_TOKEN,t=ce.env.JIRA_PROJECT_ID,s=ce.env.JIRA_EMAIL,o=[];if(e||o.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),r||o.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),t||o.push("JIRA_PROJECT_ID (numeric project ID)"),s||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let a=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(p=>` - ${p}`),"","You can set these in your .env file or as environment variables."].join(`
|
|
17
|
+
`);throw new Error(a)}let i=Number.parseInt(t,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${t}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:i,email:s}},le=async()=>{try{return await H()}catch(e){return n.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var ke=e=>e==="hotfix"?"main":"dev",me=async(e="regular")=>{let r=ke(e);pe.quiet=!0,await pe`git fetch origin`,await pe`git switch ${r}`,await pe`git pull origin ${r}`,pe.quiet=!1},ue=async e=>{let{version:r,jiraConfig:t,description:s,type:o="regular"}=e,i=`v${r}`,a=await Ve({name:i,projectId:t.projectId,description:s||"",released:!1,archived:!1},t),p=`${t.baseUrl}/projects/${a.version.projectId}/versions/${a.version.id}/tab/release-report-all-issues`,l=await Te({version:r,jiraVersionUrl:p,type:o});return{version:r,type:o,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:p}},y=async()=>{let e=new Map,r=await le();if(!r)return e;try{let t=await xe(r);for(let s of t)s.description&&e.set(s.name,s.description)}catch{}return e},K=(e,r,t)=>{let s=t?" ".repeat(t-e.length+3):" ",o=`[${r}]`.padEnd(11);return`${e}${s}${o}`},g=e=>e.toLowerCase().startsWith("hotfix")?"hotfix":"regular",b=e=>{let{branches:r,descriptions:t,types:s}=e,o=r.map(a=>a.replace("release/v","")),i=Math.max(...o.map(a=>a.length));return r.map((a,p)=>{let l=o[p],m=s?s.get(a)||"regular":void 0,u=t.get(`v${l}`),f=" ".repeat(i-l.length+3),h=m?K(l,m,i):l;return u&&(h=m?`${h} ${u}`:`${l}${f}${u}`),{name:h,value:a}})};var We=e=>e.replace("release/","").slice(1).split(".").map(Number),Ce=e=>[...e].sort((r,t)=>{let[s,o,i]=We(r),[a,p,l]=We(t);return s!==a?(s??0)-(a??0):o!==p?(o??0)-(p??0):(i??0)-(l??0)});var Cr=async()=>{let e=await T`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=await T`gh pr list --search "Hotfix in:title" --base main --json number,title,headRefName,state,baseRefName`,t=[...JSON.parse(e.stdout),...JSON.parse(r.stdout)],s=new Set;return t.filter(o=>s.has(o.headRefName)?!1:(s.add(o.headRefName),!0))},Pe=async()=>{try{let e=await Cr();return e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),$e.exit(1)),Ce(e.map(r=>r.headRefName))}catch(e){n.error({error:e},"\u274C Error fetching release PRs"),$e.exit(1)}},v=async()=>{try{let e=await Cr();e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),$e.exit(1));let r=Ce(e.map(s=>s.headRefName)),t=new Map(e.map(s=>[s.headRefName,s]));return r.map(s=>({branch:s,title:t.get(s).title}))}catch(e){n.error({error:e},"\u274C Error fetching release PRs"),$e.exit(1)}},Te=async e=>{let{version:r,jiraVersionUrl:t,type:s}=e,o=s==="hotfix"?"Hotfix":"Release",i=ke(s),a=`release/v${r}`;try{T.quiet=!0,await T`git switch ${i}`,await T`git pull origin ${i}`,await T`git checkout -b ${a}`,await T`git push -u origin ${a}`,await T`git commit --allow-empty-message --allow-empty --message ''`,await T`git push origin ${a}`;let l=(await T`gh pr create --title "${o} v${r}" --body "${t} \n" --base ${i} --head ${a}`).stdout.trim();return await T`git switch ${i}`,T.quiet=!1,{branchName:a,prUrl:l}}catch(p){throw n.error({error:p,branchName:a},`Error creating release branch ${a}`),p}};var $r=async e=>{let{all:r,confirmedCommand:t}=e;c.start("merge-dev");let o=(await v()).filter(u=>g(u.title)==="regular").map(u=>u.branch);if(o.length===0)return n.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0},null,2)}],structuredContent:{successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0}};let i=[];if(r)i=o;else{c.setInteractive();let u=await y();i=await kt({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:o,descriptions:u})})}i.length===o.length?c.addOption("--all",!0):c.addOption("--versions",i.map(u=>u.replace("release/v","")));let p=t?!0:await Tt({message:`Are you sure you want to merge dev into these branches: ${i.join(", ")}?`});t||c.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),Ct.exit(0)),t||c.addOption("--yes",!0),P.quiet=!0,await P`git fetch origin`,await P`git switch dev`,await P`git pull origin dev`;let l=[];for(let u of i)await $t(u)||l.push(u);if(P.quiet=!1,l.length>0){n.info(`
|
|
18
|
+
\u26A0\uFE0F ${l.length} branch(es) failed to merge automatically.
|
|
19
|
+
`),n.info("\u{1F4CB} Manual merge script for failed branches:");for(let u of l)n.info(`# Merge dev into ${u} and resolve conflicts if any
|
|
19
20
|
|
|
20
21
|
git switch ${u} && git pull origin ${u} && git merge origin/dev
|
|
21
22
|
git push origin ${u} && git switch dev
|
|
22
|
-
`);
|
|
23
|
-
`);l.print();let m={successfulMerges:i.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:i.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},lt=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`,s.info(`Successfully merged dev into ${e}`),!0}catch(r){return s.error({error:r,branch:e},`Error merging dev into ${e}`),await $`git reset --merge HEAD~1`,!1}},Ne={name:"gh-merge-dev",description:"Merge origin/dev into every open regular (non-hotfix) release branch and push the result. Mutates local git state and the remote release branches. When invoked via MCP, pass all=true \u2014 the branch picker is unreachable without a TTY, and the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. Irreversible once pushed.",inputSchema:{all:H.boolean().optional().describe("Target every open regular release branch. Must be true for MCP calls (the interactive picker is unavailable without a TTY).")},outputSchema:{successfulMerges:H.number().describe("Number of successful merges"),failedMerges:H.number().describe("Number of failed merges"),failedBranches:H.array(H.string()).describe("List of branches that failed to merge"),totalBranches:H.number().describe("Total number of branches processed")},handler:gr};import pt from"@inquirer/confirm";import mt from"@inquirer/select";import Oe from"node:process";import{z as ae}from"zod";import{$ as b}from"zx";var vr=async e=>{let{version:r,confirmedCommand:t}=e;l.start("release-deliver");let n=await v(),o=n.map(f=>f.branch),i=new Map(n.map(f=>[f.branch,g(f.title)])),a="";if(r)a=`release/v${r}`;else{l.setInteractive();let f=await y();a=await mt({message:"\u{1F33F} Select release branch",choices:T({branches:o,descriptions:f,types:i})})}let p=a.replace("release/v","");l.addOption("--version",p);let c=n.find(f=>f.branch===a);c||(s.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),Oe.exit(1));let m=g(c.title),u=t?!0:await pt({message:`Are you sure you want to deliver version ${a} to production?`});t||l.setInteractive(),u||(s.info("Operation cancelled. Exiting..."),Oe.exit(0)),l.addOption("--yes",!0);try{b.quiet=!0,m==="hotfix"?(await b`gh pr merge ${a} --squash --admin --delete-branch`,b.quiet=!1,await b`gh workflow run deploy-all.yml --ref main -f environment=prod`,b.quiet=!0,await b`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await b`gh pr merge ${a} --squash --admin --delete-branch`,await b`gh pr create --base main --head dev --title "Release v${p} (RC)" --body ""`,await b`gh pr merge dev --squash --admin`,b.quiet=!1,await b`gh workflow run deploy-all.yml --ref main -f environment=prod`,b.quiet=!0,await b`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),b.quiet=!1;let f=await oe();if(f)try{let d=a.replace("release/","");await Se({versionName:d},f)}catch(d){s.error({error:d},"Failed to deliver Jira release (non-blocking)")}else s.info("\u{1F514} Jira is not configured, skipping Jira release delivery");s.info(`Successfully delivered ${a} to production!`),l.print();let h={releaseBranch:a,version:a.replace("release/v",""),type:m,success:!0};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(f){s.error({error:f},"\u274C Error merging release branch into dev"),Oe.exit(1)}},_e={name:"gh-release-deliver",description:'Deliver a release to production. For hotfixes: squash-merges the release branch to main and dispatches the deploy-all workflow. For regular releases: squash-merges to dev, opens an RC PR, merges dev into main, dispatches the deploy-all workflow, then syncs main back to dev. Also releases the matching Jira fix version if Jira is configured. Dispatches the deploy workflow fire-and-forget \u2014 the tool returns once the workflow is accepted by GitHub, not when the deployment finishes. Irreversible production operation: the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the picker is unreachable without a TTY).',inputSchema:{version:ae.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:ae.string().describe("The release branch that was delivered"),version:ae.string().describe("The version that was delivered"),type:ae.enum(["regular","hotfix"]).describe("Release type"),success:ae.boolean().describe("Whether the delivery was successful")},handler:vr};import yr from"@inquirer/select";import wr from"node:process";import{z as _}from"zod";import{$ as Me}from"zx";var Rr=async e=>{let{version:r,env:t,skipTerraform:n}=e;l.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let m=await v(),u=m.map(d=>d.branch),f=new Map(m.map(d=>[d.branch,g(d.title)])),h=await y();o=await yr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:u,descriptions:h,types:f})]})}let i=o==="dev"?"dev":o.replace("release/v","");l.addOption("--version",i);let{environments:a}=await E(),p="";t?p=t:(l.setInteractive(),p=await yr({message:"\u{1F9EA} Select environment",choices:a.map(m=>({name:m,value:m}))})),l.addOption("--env",p),a.includes(p)||(s.error(`\u274C Invalid environment: ${p}. Exiting...`),wr.exit(1));let c=n??!1;c&&l.addOption("--skip-terraform",!0);try{Me.quiet=!0,await Me`gh workflow run deploy-all.yml --ref ${o} -f environment=${p} ${c?["-f","skip_terraform_deploy=true"]:[]}`,Me.quiet=!1,s.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${p}`),l.print();let u={releaseBranch:o,version:o.replace("release/v",""),environment:p,skipTerraformDeploy:c,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){s.error({error:m},"\u274C Error launching workflow"),wr.exit(1)}},De={name:"gh-release-deploy-all",description:'Dispatch the deploy-all.yml GitHub Actions workflow to deploy every service from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Use gh-release-deploy-selected for a subset of services. Pass version="dev" to deploy from the dev branch instead of a release branch. Both "version" and "env" are required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:_.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:_.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:_.boolean().optional().describe("Skip the terraform deployment stage.")},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"),skipTerraformDeploy:_.boolean().describe("Whether terraform deployment was skipped"),success:_.boolean().describe("Whether the deployment was successful")},handler:Rr};import ut from"@inquirer/checkbox";import br from"@inquirer/select";import ft from"node:fs/promises";import{resolve as dt}from"node:path";import ce from"node:process";import ht from"yaml";import{z as C}from"zod";import{$ as Je}from"zx";var xr=async e=>{let{version:r,env:t,services:n,skipTerraform:o}=e;l.start("release-deploy-selected");let i="";if(r)i=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let d=await v(),x=d.map(N=>N.branch),I=new Map(d.map(N=>[N.branch,g(N.title)])),R=await y();i=await br({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:x,descriptions:R,types:I})]})}let a=i==="dev"?"dev":i.replace("release/v","");l.addOption("--version",a);let{environments:p}=await E(),c="";t?c=t:(l.setInteractive(),c=await br({message:"\u{1F9EA} Select environment",choices:p.map(d=>({name:d,value:d}))})),l.addOption("--env",c),p.includes(c)||(s.error(`\u274C Invalid environment: ${c}. Exiting...`),ce.exit(1));let m=await gt();m.length===0&&(s.error("\u274C No services found in workflow file. Exiting..."),ce.exit(1));let u=[];n&&n.length>0?u=n:(l.setInteractive(),u=await ut({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(d=>({name:d,value:d}))})),l.addOption("--services",u),u.length===0&&(s.error("\u274C No services selected. Exiting..."),ce.exit(1));let f=u.filter(d=>!m.includes(d));f.length>0&&(s.error(`\u274C Invalid services: ${f.join(", ")}. Available services: ${m.join(", ")}`),ce.exit(1));let h=o??!1;h&&l.addOption("--skip-terraform",!0);try{Je.quiet=!0;let d=u.flatMap(R=>["-f",`${R}=true`]);await Je`gh workflow run deploy-selected-services.yml --ref ${i} -f environment=${c} ${d} ${h?["-f","skip_terraform_deploy=true"]:[]}`,Je.quiet=!1,s.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${i}, environment: ${c}, services: ${u.join(", ")}`),l.print();let I={releaseBranch:i,version:i.replace("release/v",""),environment:c,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(I,null,2)}],structuredContent:I}}catch(d){s.error({error:d},"\u274C Error launching workflow"),ce.exit(1)}},gt=async()=>{let e=await P(),r=dt(e,".github/workflows/deploy-selected-services.yml"),t=await ft.readFile(r,"utf-8"),o=ht.parse(t).on.workflow_dispatch.inputs,i=[];for(let[a,p]of Object.entries(o))p.type==="boolean"&&a!=="skip_terraform_deploy"&&i.push(a);return i},je={name:"gh-release-deploy-selected",description:'Dispatch the deploy-selected-services.yml GitHub Actions workflow to deploy a chosen subset of services from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Service names are validated against the boolean inputs declared in the workflow. Use gh-release-deploy-all for every service. "version", "env", and "services" are all required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:C.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:C.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:C.array(C.string()).describe('Service names to deploy. Each must match a boolean input declared in .github/workflows/deploy-selected-services.yml (e.g. "client-be", "client-fe"). Required for MCP calls.'),skipTerraform:C.boolean().optional().describe("Skip the terraform deployment stage.")},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"),services:C.array(C.string()).describe("The services that were deployed"),skipTerraformDeploy:C.boolean().describe("Whether terraform deployment was skipped"),success:C.boolean().describe("Whether the deployment was successful")},handler:xr};import{z}from"zod";var Tr=async()=>{let r=(await v()).map(a=>({version:a.branch.replace("release/",""),type:g(a.title)})),t=await y(),n=Math.max(...r.map(a=>a.version.length)),o=r.map(a=>{let p=K(a.version,a.type,n),c=t.get(a.version);return c?`${p} ${c}`:p});s.info(`All release branches:
|
|
24
|
-
`),
|
|
23
|
+
`);n.info(`\u2705 ${i.length-l.length}/${i.length} merges completed successfully.`)}else n.info(`\u2705 All merges completed successfully!
|
|
24
|
+
`);c.print();let m={successfulMerges:i.length-l.length,failedMerges:l.length,failedBranches:l,totalBranches:i.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},$t=async e=>{try{return await P`git switch ${e}`,await P`git pull origin ${e}`,await P`git merge origin/dev --no-edit`,await P`git push origin ${e}`,await P`git switch dev`,n.info(`Successfully merged dev into ${e}`),!0}catch(r){return n.error({error:r,branch:e},`Error merging dev into ${e}`),await P`git reset --merge HEAD~1`,!1}},Be={name:"gh-merge-dev",description:"Merge origin/dev into every open regular (non-hotfix) release branch and push the result. Mutates local git state and the remote release branches. When invoked via MCP, pass all=true \u2014 the branch picker is unreachable without a TTY, and the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. Irreversible once pushed.",inputSchema:{all:z.boolean().optional().describe("Target every open regular release branch. Must be true for MCP calls (the interactive picker is unavailable without a TTY).")},outputSchema:{successfulMerges:z.number().describe("Number of successful merges"),failedMerges:z.number().describe("Number of failed merges"),failedBranches:z.array(z.string()).describe("List of branches that failed to merge"),totalBranches:z.number().describe("Total number of branches processed")},handler:$r};import Pt from"@inquirer/confirm";import Et from"@inquirer/select";import qe from"node:process";import{z as fe}from"zod";import{$ as R}from"zx";var Pr=async e=>{let{version:r,confirmedCommand:t}=e;c.start("release-deliver");let s=await v(),o=s.map(f=>f.branch),i=new Map(s.map(f=>[f.branch,g(f.title)])),a="";if(r)a=`release/v${r}`;else{c.setInteractive();let f=await y();a=await Et({message:"\u{1F33F} Select release branch",choices:b({branches:o,descriptions:f,types:i})})}let p=a.replace("release/v","");c.addOption("--version",p);let l=s.find(f=>f.branch===a);l||(n.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),qe.exit(1));let m=g(l.title),u=t?!0:await Pt({message:`Are you sure you want to deliver version ${a} to production?`});t||c.setInteractive(),u||(n.info("Operation cancelled. Exiting..."),qe.exit(0)),c.addOption("--yes",!0);try{R.quiet=!0,m==="hotfix"?(await R`gh pr merge ${a} --squash --admin --delete-branch`,R.quiet=!1,await R`gh workflow run deploy-all.yml --ref main -f environment=prod`,R.quiet=!0,await R`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await R`gh pr merge ${a} --squash --admin --delete-branch`,await R`gh pr create --base main --head dev --title "Release v${p} (RC)" --body ""`,await R`gh pr merge dev --squash --admin`,R.quiet=!1,await R`gh workflow run deploy-all.yml --ref main -f environment=prod`,R.quiet=!0,await R`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),R.quiet=!1;let f=await le();if(f)try{let d=a.replace("release/","");await Fe({versionName:d},f)}catch(d){n.error({error:d},"Failed to deliver Jira release (non-blocking)")}else n.info("\u{1F514} Jira is not configured, skipping Jira release delivery");n.info(`Successfully delivered ${a} to production!`),c.print();let h={releaseBranch:a,version:a.replace("release/v",""),type:m,success:!0};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(f){n.error({error:f},"\u274C Error merging release branch into dev"),qe.exit(1)}},Ue={name:"gh-release-deliver",description:'Deliver a release to production. For hotfixes: squash-merges the release branch to main and dispatches the deploy-all workflow. For regular releases: squash-merges to dev, opens an RC PR, merges dev into main, dispatches the deploy-all workflow, then syncs main back to dev. Also releases the matching Jira fix version if Jira is configured. Dispatches the deploy workflow fire-and-forget \u2014 the tool returns once the workflow is accepted by GitHub, not when the deployment finishes. Irreversible production operation: the confirmation prompt is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the picker is unreachable without a TTY).',inputSchema:{version:fe.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:fe.string().describe("The release branch that was delivered"),version:fe.string().describe("The version that was delivered"),type:fe.enum(["regular","hotfix"]).describe("Release type"),success:fe.boolean().describe("Whether the delivery was successful")},handler:Pr};import Er from"@inquirer/select";import Ir from"node:process";import{z as M}from"zod";import{$ as Ge}from"zx";var Sr=async e=>{let{version:r,env:t,skipTerraform:s}=e;c.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{c.setInteractive();let m=await v(),u=m.map(d=>d.branch),f=new Map(m.map(d=>[d.branch,g(d.title)])),h=await y();o=await Er({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...b({branches:u,descriptions:h,types:f})]})}let i=o==="dev"?"dev":o.replace("release/v","");c.addOption("--version",i);let{environments:a}=await S(),p="";t?p=t:(c.setInteractive(),p=await Er({message:"\u{1F9EA} Select environment",choices:a.map(m=>({name:m,value:m}))})),c.addOption("--env",p),a.includes(p)||(n.error(`\u274C Invalid environment: ${p}. Exiting...`),Ir.exit(1));let l=s??!1;l&&c.addOption("--skip-terraform",!0);try{Ge.quiet=!0,await Ge`gh workflow run deploy-all.yml --ref ${o} -f environment=${p} ${l?["-f","skip_terraform_deploy=true"]:[]}`,Ge.quiet=!1,n.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${p}`),c.print();let u={releaseBranch:o,version:o.replace("release/v",""),environment:p,skipTerraformDeploy:l,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){n.error({error:m},"\u274C Error launching workflow"),Ir.exit(1)}},He={name:"gh-release-deploy-all",description:'Dispatch the deploy-all.yml GitHub Actions workflow to deploy every service from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Use gh-release-deploy-selected for a subset of services. Pass version="dev" to deploy from the dev branch instead of a release branch. Both "version" and "env" are required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:M.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:M.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:M.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:M.string().describe("The release branch that was deployed"),version:M.string().describe("The version that was deployed"),environment:M.string().describe("The environment deployed to"),skipTerraformDeploy:M.boolean().describe("Whether terraform deployment was skipped"),success:M.boolean().describe("Whether the deployment was successful")},handler:Sr};import It from"@inquirer/checkbox";import Ar from"@inquirer/select";import St from"node:fs/promises";import{resolve as At}from"node:path";import de from"node:process";import Nt from"yaml";import{z as C}from"zod";import{$ as Ke}from"zx";var Nr=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;c.start("release-deploy-selected");let i="";if(r)i=r==="dev"?"dev":`release/v${r}`;else{c.setInteractive();let d=await v(),E=d.map(J=>J.branch),N=new Map(d.map(J=>[J.branch,g(J.title)])),I=await y();i=await Ar({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...b({branches:E,descriptions:I,types:N})]})}let a=i==="dev"?"dev":i.replace("release/v","");c.addOption("--version",a);let{environments:p}=await S(),l="";t?l=t:(c.setInteractive(),l=await Ar({message:"\u{1F9EA} Select environment",choices:p.map(d=>({name:d,value:d}))})),c.addOption("--env",l),p.includes(l)||(n.error(`\u274C Invalid environment: ${l}. Exiting...`),de.exit(1));let m=await Ot();m.length===0&&(n.error("\u274C No services found in workflow file. Exiting..."),de.exit(1));let u=[];s&&s.length>0?u=s:(c.setInteractive(),u=await It({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(d=>({name:d,value:d}))})),c.addOption("--services",u),u.length===0&&(n.error("\u274C No services selected. Exiting..."),de.exit(1));let f=u.filter(d=>!m.includes(d));f.length>0&&(n.error(`\u274C Invalid services: ${f.join(", ")}. Available services: ${m.join(", ")}`),de.exit(1));let h=o??!1;h&&c.addOption("--skip-terraform",!0);try{Ke.quiet=!0;let d=u.flatMap(I=>["-f",`${I}=true`]);await Ke`gh workflow run deploy-selected-services.yml --ref ${i} -f environment=${l} ${d} ${h?["-f","skip_terraform_deploy=true"]:[]}`,Ke.quiet=!1,n.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${i}, environment: ${l}, services: ${u.join(", ")}`),c.print();let N={releaseBranch:i,version:i.replace("release/v",""),environment:l,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(N,null,2)}],structuredContent:N}}catch(d){n.error({error:d},"\u274C Error launching workflow"),de.exit(1)}},Ot=async()=>{let e=await k(),r=At(e,".github/workflows/deploy-selected-services.yml"),t=await St.readFile(r,"utf-8"),o=Nt.parse(t).on.workflow_dispatch.inputs,i=[];for(let[a,p]of Object.entries(o))p.type==="boolean"&&a!=="skip_terraform_deploy"&&i.push(a);return i},ze={name:"gh-release-deploy-selected",description:'Dispatch the deploy-selected-services.yml GitHub Actions workflow to deploy a chosen subset of services from a release branch to the given environment. Fire-and-forget \u2014 returns once GitHub accepts the workflow_dispatch, NOT when the deployment finishes; watch the workflow run for completion status. Service names are validated against the boolean inputs declared in the workflow. Use gh-release-deploy-all for every service. "version", "env", and "services" are all required when invoked via MCP (interactive pickers are unavailable without a TTY).',inputSchema:{version:C.string().describe('Release version to deploy from (e.g. "1.2.5") \u2014 resolves to the release/vX.Y.Z branch. Pass "dev" to deploy from the dev branch instead. Required for MCP calls.'),env:C.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:C.array(C.string()).describe('Service names to deploy. Each must match a boolean input declared in .github/workflows/deploy-selected-services.yml (e.g. "client-be", "client-fe"). Required for MCP calls.'),skipTerraform:C.boolean().optional().describe("Skip the terraform deployment stage.")},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"),services:C.array(C.string()).describe("The services that were deployed"),skipTerraformDeploy:C.boolean().describe("Whether terraform deployment was skipped"),success:C.boolean().describe("Whether the deployment was successful")},handler:Nr};import{z as Y}from"zod";var Or=async()=>{let r=(await v()).map(a=>({version:a.branch.replace("release/",""),type:g(a.title)})),t=await y(),s=Math.max(...r.map(a=>a.version.length)),o=r.map(a=>{let p=K(a.version,a.type,s),l=t.get(a.version);return l?`${p} ${l}`:p});n.info(`All release branches:
|
|
25
|
+
`),n.info(`
|
|
25
26
|
${o.join(`
|
|
26
27
|
`)}
|
|
27
|
-
`);let i={releases:r.map(a=>({version:a.version,type:a.type,description:t.get(a.version)||null})),count:r.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},
|
|
28
|
-
`)}catch(u){let f=u instanceof Error?u.message:String(u);i.push({version:m,error:f}),
|
|
29
|
-
`)}let a=o.length,p=i.length;a===t.length?
|
|
28
|
+
`);let i={releases:r.map(a=>({version:a.version,type:a.type,description:t.get(a.version)||null})),count:r.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Ye={name:"gh-release-list",description:"List every open release PR with its version, type (regular / hotfix), and associated Jira fix-version description. Read-only; sourced from GitHub and Jira.",inputSchema:{},outputSchema:{releases:Y.array(Y.object({version:Y.string().describe("Release version"),type:Y.enum(["regular","hotfix"]).describe("Release type"),description:Y.string().nullable().describe("Jira version description")})).describe("List of all release branches"),count:Y.number().describe("Number of release branches")},handler:Or};import _r from"@inquirer/confirm";import _t from"@inquirer/select";import Mr from"node:process";import{z as A}from"zod";import{$ as Xe,question as Dr}from"zx";var Jr=async e=>{let{version:r,description:t,type:s,confirmedCommand:o,checkout:i}=e;c.start("release-create");let a=r,p=t,l=s||"regular",m=i,u=await H();a||(c.setInteractive(),a=await Dr("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(n.error("No version provided. Exiting..."),Mr.exit(1));let f=a.trim();c.addOption("--version",f),s||(c.setInteractive(),l=await _t({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),c.addOption("--type",l),p===void 0&&(c.setInteractive(),p=await Dr("Enter description (optional, press Enter to skip): "),p.trim()===""&&(p="")),p&&c.addOption("--description",p);let h=o?!0:await _r({message:`Are you sure you want to create release branch for version ${f}?`});o||c.setInteractive(),h||(n.info("Operation cancelled. Exiting..."),Mr.exit(0)),c.addOption("--yes",!0),await me(l);let d=await ue({version:f,jiraConfig:u,description:p,type:l});n.info(`\u2705 Successfully created release: v${f}`),n.info(`\u{1F517} GitHub PR: ${d.prUrl}`),n.info(`\u{1F517} Jira Version: ${d.jiraVersionUrl}`),m===void 0&&(c.setInteractive(),m=await _r({message:`Do you want to checkout to the created branch ${d.branchName}?`,default:!0})),m||c.addOption("--no-checkout",!0),m&&(Xe.quiet=!0,await Xe`git switch ${d.branchName}`,Xe.quiet=!1,n.info(`\u{1F504} Switched to branch ${d.branchName}`)),c.print();let E={version:f,type:l,branchName:d.branchName,prUrl:d.prUrl,jiraVersionUrl:d.jiraVersionUrl,isCheckedOut:m};return{content:[{type:"text",text:JSON.stringify(E,null,2)}],structuredContent:E}},Ze={name:"release-create",description:'Create a new release: cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub release PR, creates the matching Jira fix version, and optionally checks out to the new branch. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "version" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY); "type" / "description" / "checkout" default to regular / empty / true when omitted.',inputSchema:{version:A.string().describe('Version to create (e.g., "1.2.5"). Required for MCP calls.'),description:A.string().optional().describe("Optional description for the Jira version"),type:A.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")'),checkout:A.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:A.string().describe("Version number"),type:A.enum(["regular","hotfix"]).describe("Release type"),branchName:A.string().describe("Release branch name"),prUrl:A.string().describe("GitHub PR URL"),jiraVersionUrl:A.string().describe("Jira version URL"),isCheckedOut:A.boolean().describe("Whether the branch was checked out")},handler:Jr};import Mt from"@inquirer/confirm";import Dt from"@inquirer/select";import jr from"node:process";import{z as w}from"zod";import{question as Jt}from"zx";var jt=async e=>{let{versions:r,type:t,confirmedCommand:s}=e,o=r,i=t||"regular";o||(c.setInteractive(),o=await Jt("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let a=o.split(",").map(l=>l.trim()).filter(Boolean);c.addOption("--versions",a.join(", ")),a.length===0&&(n.error("No versions provided. Exiting..."),jr.exit(1)),t||(c.setInteractive(),i=await Dt({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),c.addOption("--type",i),a.length===1&&n.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let p=s?!0:await Mt({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`});return s||c.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),jr.exit(0)),c.addOption("--yes",!0),{versionsList:a,type:i}},Lr=async e=>{c.start("release-create-batch");let r=await H(),{versionsList:t,type:s}=await jt(e);await me(s);let o=[],i=[];for(let m of t)try{let u=await ue({version:m,jiraConfig:r,type:s});o.push(u),n.info(`\u2705 Successfully created release: v${m}`),n.info(`\u{1F517} GitHub PR: ${u.prUrl}`),n.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}
|
|
29
|
+
`)}catch(u){let f=u instanceof Error?u.message:String(u);i.push({version:m,error:f}),n.error(`\u274C Failed to create release: v${m}`),n.error(` Error: ${f}
|
|
30
|
+
`)}let a=o.length,p=i.length;a===t.length?n.info(`\u2705 All ${t.length} release branches were created successfully.`):a>0?(n.warn(`\u26A0\uFE0F ${a} of ${t.length} release branches were created successfully.`),n.warn(`\u274C ${p} release(s) failed.`)):n.error(`\u274C All ${t.length} release branches failed to create.`),c.print();let l={createdBranches:o.map(m=>m.branchName),successCount:a,failureCount:p,releases:o,failedReleases:i};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},Qe={name:"release-create-batch",description:'Create several releases in one pass: for each comma-separated version in "versions", cuts the release branch off the appropriate base (dev for regular releases, main for hotfixes), opens a GitHub PR, and creates the Jira fix version. Continues on per-version failure and reports which versions succeeded and which failed. Confirmation is auto-skipped for MCP calls, so the caller is responsible for gating. "versions" is required when invoked via MCP (the interactive input prompt is unreachable without a TTY). Use release-create for a single version with optional checkout.',inputSchema:{versions:w.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6"). Required for MCP calls.'),type:w.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")')},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"),type:w.enum(["regular","hotfix"]).describe("Release type"),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:Lr};import Vt from"@inquirer/checkbox";import Ee from"@inquirer/confirm";import Ft from"node:process";import{z as D}from"zod";import{$ as Z}from"zx";import{$ as X}from"zx";var er=async e=>{let{cwd:r,title:t}=e;await X`cmux new-workspace --cwd ${r}`;let s=(await X`cmux current-workspace`).stdout.trim(),o=(await X`cmux list-pane-surfaces --workspace ${s}`).stdout,i=Lt(o);await X`cmux new-split right --workspace ${s} --surface ${i}`,await X`cmux new-split down --workspace ${s} --surface ${i}`,t&&await X`cmux rename-workspace --workspace ${s} ${t}`},Lt=e=>{let r=e.match(/surface:\d+/);if(!r)throw new Error("cmux: could not locate initial surface in list-pane-surfaces output");return r[0]};var Wt="feature",Bt="release",qt="release/v",Fr=async e=>{let{confirmedCommand:r,all:t,versions:s,cursor:o,githubDesktop:i,cmux:a}=e;c.start("worktrees-add");try{let p=await O("release"),m=`${await k()}${U}`;await Vr(`${m}/${Bt}`),await Vr(`${m}/${Wt}`);let u=[];if(s)u=s.split(",").map(x=>`release/v${x.trim()}`);else{let x=await v(),L=x.map(ee=>ee.branch);if(L.length===0)return n.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};if(t)u=L;else{c.setInteractive();let ee=new Map(x.map(cr=>[cr.branch,g(cr.title)])),Kr=await y();u=await Vt({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:L,descriptions:Kr,types:ee})})}}t?c.addOption("--all",!0):c.addOption("--versions",u.map(x=>x.replace("release/v","")));let f=r?!0:await Ee({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),f||(n.info("Operation cancelled. Exiting..."),Ft.exit(0)),r||c.addOption("--yes",!0);let h=o??await Ee({message:"Open created worktrees in Cursor?"});typeof o>"u"&&c.setInteractive(),h?c.addOption("--cursor",!0):c.addOption("--no-cursor",!0);let d=i??await Ee({message:"Open created worktrees in GitHub Desktop?"});typeof i>"u"&&c.setInteractive(),d?c.addOption("--github-desktop",!0):c.addOption("--no-github-desktop",!0);let E=a??await Ee({message:"Open created worktrees in cmux?"});typeof a>"u"&&c.setInteractive(),E?c.addOption("--cmux",!0):c.addOption("--no-cmux",!0);let{branchesToCreate:N}=Ut({selectedReleaseBranches:u,currentWorktrees:p}),I=await Gt(N,m);if(Ht(I),h)for(let x of I)await Z`cursor ${m}/${x}`;if(d)for(let x of I)await Z`github ${m}/${x}`,await Z`sleep 5`;if(E){let x=await _e();for(let L of I){let ee=L.replace("release/","");await er({cwd:`${m}/${L}`,title:`${x} ${ee}`})}}c.print();let J={createdWorktrees:I,count:I.length};return{content:[{type:"text",text:JSON.stringify(J,null,2)}],structuredContent:J}}catch(p){throw n.error({error:p},"\u274C Error managing worktrees"),p}},Vr=async e=>{await Z`mkdir -p ${e}`},Ut=e=>{let{selectedReleaseBranches:r,currentWorktrees:t}=e,s=t.filter(i=>i.startsWith(qt));return{branchesToCreate:r.filter(i=>!s.includes(i))}},Gt=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let i=`${r}/${o}`;return await Z`git worktree add ${i} ${o}`,await Z({cwd:i})`pnpm install`,o})),s=[];for(let[o,i]of t.entries())if(i.status==="fulfilled")s.push(i.value);else{let a=e[o];n.error({error:i.reason},`\u274C Failed to create worktree for ${a}`)}return s},Ht=e=>{if(e.length>0){n.info("\u2705 Created git worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No new git worktrees to create")},rr={name:"worktrees-add",description:'Create local git worktrees for release branches under the worktrees directory and run "pnpm install" in each. Mutates the local filesystem. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker and "open in Cursor / GitHub Desktop / cmux" follow-up prompts are unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls.',inputSchema:{all:D.boolean().optional().describe('Add worktrees for every open release branch. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:D.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.'),cursor:D.boolean().optional().describe("Open each created worktree in Cursor. Defaults to false in MCP mode (the follow-up prompt is not shown)."),githubDesktop:D.boolean().optional().describe("Open each created worktree in GitHub Desktop. Defaults to false in MCP mode (the follow-up prompt is not shown)."),cmux:D.boolean().optional().describe("Open each created worktree in a new cmux workspace with a 3-pane layout (left-top, left-bottom, full-height right), all rooted at the worktree directory. Defaults to false in MCP mode (the follow-up prompt is not shown).")},outputSchema:{createdWorktrees:D.array(D.string()).describe("List of created git worktree branches"),count:D.number().describe("Number of git worktrees created")},handler:Fr};import{z as Q}from"zod";var Wr=async()=>{let e=await O("release");if(e.length===0)return n.info("\u2139\uFE0F No active worktrees found"),{content:[{type:"text",text:JSON.stringify({worktrees:[],count:0},null,2)}],structuredContent:{worktrees:[],count:0}};let[r,t]=await Promise.all([v(),y()]),s=new Map(r.map(l=>[l.branch,g(l.title)])),o=e.map(l=>{let m=l.replace("release/",""),u=s.get(l)||"regular",f=t.get(m)||null;return{version:m,type:u,description:f}}),i=Math.max(...o.map(l=>l.version.length)),a=o.map(l=>{let m=K(l.version,l.type,i);return l.description?`${m} ${l.description}`:m});n.info("\u{1F33F} Active worktrees:"),n.info(`
|
|
30
31
|
${a.join(`
|
|
31
32
|
`)}
|
|
32
|
-
`);let p={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},
|
|
33
|
+
`);let p={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},tr={name:"worktrees-list",description:"List existing release-branch worktrees with version, release type (regular / hotfix), and Jira fix-version description. Read-only.",inputSchema:{},outputSchema:{worktrees:Q.array(Q.object({version:Q.string().describe("Release version"),type:Q.enum(["regular","hotfix"]).describe("Release type"),description:Q.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:Q.number().describe("Number of worktrees")},handler:Wr};import Kt from"@inquirer/checkbox";import zt from"@inquirer/confirm";import Yt from"node:process";import{z as he}from"zod";import{$ as or}from"zx";var Br=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;c.start("worktrees-remove");try{let o=await O("release");if(o.length===0)return n.info("\u2139\uFE0F No active worktrees to remove"),c.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let a=`${await k()}${U}`,p=[];if(t)p=o;else if(s)p=s.split(",").map(h=>`release/v${h.trim()}`);else{c.setInteractive();let[h,d]=await Promise.all([y(),v()]),E=new Map(d.map(N=>[N.branch,g(N.title)]));p=await Kt({required:!0,message:"\u{1F33F} Select release branches",choices:b({branches:o,descriptions:h,types:E})})}p.length===o.length?c.addOption("--all",!0):c.addOption("--versions",p.map(h=>h.replace("release/v","")));let m=r?!0:await zt({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),m||(n.info("Operation cancelled. Exiting..."),Yt.exit(0)),r||c.addOption("--yes",!0);let u=await Xt(p,a);Zt(u),c.print();let f={removedWorktrees:u,count:u.length};return{content:[{type:"text",text:JSON.stringify(f,null,2)}],structuredContent:f}}catch(o){throw n.error({error:o},"\u274C Error managing worktrees"),o}},Xt=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let i=`${r}/${o}`;return await or`git worktree remove ${i}`,o})),s=[];for(let[o,i]of t.entries())if(i.status==="fulfilled")s.push(i.value);else{let a=e[o];n.error({error:i.reason},`\u274C Failed to remove worktree for ${a}`)}return s.length===e.length&&(await or`git worktree prune`,await or`rm -rf ${r}`,n.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${r}`),n.info("")),s},Zt=e=>{if(e.length>0){n.info("\u274C Removed worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No unused worktrees to remove")},sr={name:"worktrees-remove",description:'Remove local git worktrees for release branches. When everything is removed, also runs "git worktree prune" and deletes the worktrees directory. When invoked via MCP, pass either "versions" (comma-separated) or all=true \u2014 the branch picker is unreachable without a TTY, and the CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.',inputSchema:{all:he.boolean().optional().describe('Remove every existing worktree. Either "all" or "versions" must be provided for MCP calls (the interactive picker is unavailable without a TTY). Ignored if "versions" is provided.'),versions:he.string().optional().describe('Comma-separated release versions to target (e.g. "1.2.5, 1.2.6"). Either "versions" or all=true must be provided for MCP calls. Overrides "all" when set.')},outputSchema:{removedWorktrees:he.array(he.string()).describe("List of removed git worktree branches"),count:he.number().describe("Number of git worktrees removed")},handler:Br};import Qt from"@inquirer/confirm";import eo from"node:process";import{z as nr}from"zod";import{$ as ro}from"zx";var to="release/v",qr=async e=>{let{confirmedCommand:r}=e;c.start("worktrees-sync");try{let t=await O("release"),o=`${await k()}${U}`,i=await Pe(),a=r?!0:await Qt({message:"Are you sure you want to proceed with these worktree changes?"});r||c.setInteractive(),a||(n.info("Operation cancelled. Exiting..."),eo.exit(0)),r||c.addOption("--yes",!0);let{branchesToRemove:p}=oo({releasePRsList:i,currentWorktrees:t}),l=await so(p,o);no(l),c.print();let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(t){throw n.error({error:t},"\u274C Error managing worktrees"),t}},oo=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(i=>i.startsWith(to)).filter(i=>!r.includes(i))}},so=async(e,r)=>{let t=[];for(let s of e)try{let o=`${r}/${s}`;await ro`git worktree remove ${o}`,t.push(s)}catch(o){n.error({error:o,branch:s},`\u274C Failed to remove worktree for ${s}`)}return t},no=e=>{if(e.length>0){n.info("\u274C Removed worktrees:");for(let r of e)n.info(r);n.info("")}else n.info("\u2139\uFE0F No unused worktrees to remove")},ir={name:"worktrees-sync",description:"Remove worktrees whose release PR is no longer open (stale cleanup). Only removes \u2014 never creates; use worktrees-add to create worktrees for new releases. The CLI confirmation is auto-skipped for MCP calls, so the caller is responsible for gating.",inputSchema:{},outputSchema:{removedWorktrees:nr.array(nr.string()).describe("List of removed worktree branches"),count:nr.number().describe("Number of worktrees removed during sync")},handler:qr};var ar=e=>async r=>{let{toolName:t,handler:s}=e;n.info({msg:`Tool execution started: ${t}`,params:r});try{let o=await s({...r,confirmedCommand:!0});return n.info({msg:`Tool execution successful: ${t}`}),o}catch(o){throw n.error({err:o,params:r,msg:`Tool execution failed: ${t}`}),o}};var io=[Le,De,je,Oe,Be,Ze,Qe,Ue,He,ze,Ye,rr,tr,sr,ir],Ur=async e=>{for(let r of io)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},ar({toolName:r.name,handler:r.handler}))};async function Gr(){let e=new ao({name:"infra-kit",version:"1.0.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await ur(e),await fr(e),await Ur(e),e}var j=pr(),lo=async()=>{let e;try{e=await Gr(),j.info("MCP Server instance created")}catch(r){j.error({err:r,msg:"Failed to create MCP server"}),j.error("Fatal error during server creation."),Hr.exit(1)}try{let r=new co;await e.connect(r),j.info({msg:"Server connected to transport. Ready."})}catch(r){j.error({err:r,msg:"Failed to initialize server"}),j.error("Fatal error during server transport init."),Hr.exit(1)}};mr(j);lo();
|
|
33
34
|
//# sourceMappingURL=mcp.js.map
|