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/cli.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
`);for(let t of e){let s=t.status==="pass"?"[PASS]":"[FAIL]";n.info(` ${s} ${t.name}: ${t.message}`)}let r={checks:e.map(t=>({name:t.name,status:t.status,message:t.message})),allPassed:e.every(t=>t.status==="pass")};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},
|
|
3
|
-
`).
|
|
1
|
+
import xo,{Separator as ee}from"@inquirer/select";import{Command as To,Option as Or}from"commander";import mr from"node:process";import{z as j}from"zod";import{$ as Fr}from"zx";import Dr from"node:process";import Mr from"pino";import Jr from"pino-pretty";var jr=()=>{let e=Dr.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),Mr({level:e},Jr({destination:2,ignore:r.join(","),colorize:!0}))},n=jr();var te=async(e,r,t,s)=>{try{return await Fr`${r}`,{name:e,status:"pass",message:t}}catch{return{name:e,status:"fail",message:s}}},ve=async()=>{let e=await Promise.all([te("gh installed",["gh","--version"],"GitHub CLI is installed","GitHub CLI is not installed. Install from: https://cli.github.com/"),te("gh authenticated",["gh","auth","status"],"GitHub CLI is authenticated","GitHub CLI is not authenticated. Run: gh auth login"),te("doppler installed",["doppler","--version"],"Doppler CLI is installed","Doppler CLI is not installed. Install from: https://docs.doppler.com/docs/install-cli"),te("doppler authenticated",["doppler","me"],"Doppler CLI is authenticated","Doppler CLI is not authenticated. Run: doppler login"),te("aws installed",["aws","--version"],"AWS CLI is installed","AWS CLI is not installed. Install from: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html")]);n.info(`Doctor check results:
|
|
2
|
+
`);for(let t of e){let s=t.status==="pass"?"[PASS]":"[FAIL]";n.info(` ${s} ${t.name}: ${t.message}`)}let r={checks:e.map(t=>({name:t.name,status:t.status,message:t.message})),allPassed:e.every(t=>t.status==="pass")};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},Vr={name:"doctor",description:"Check installation and authentication status of gh, doppler, and aws CLIs",inputSchema:{},outputSchema:{checks:j.array(j.object({name:j.string().describe("Name of the check"),status:j.enum(["pass","fail"]).describe("Check result"),message:j.string().describe("Details about the check result")})).describe("List of all check results"),allPassed:j.boolean().describe("Whether all checks passed")},handler:ve};import Ye from"node:fs";import fr from"node:path";import qr from"node:process";import{z as ke}from"zod";import oe from"node:fs";import Wr from"node:os";import Ue from"node:path";import He from"node:process";var F="env-load.sh",dr="env-clear.sh",ye="INFRA_KIT_SESSION",V="INFRA_KIT_ENV_CONFIG",W="INFRA_KIT_ENV_PROJECT",B="INFRA_KIT_ENV_LOADED_AT",we=/^([A-Z_]\w*)=/i,Re=e=>{if(!oe.existsSync(e))return[];let r=oe.readFileSync(e,"utf-8"),t=[];for(let s of r.split(`
|
|
3
|
+
`)){let o=we.exec(s);o&&t.push(o[1])}return t},Br=()=>{let e=He.env.XDG_CACHE_HOME,r=e&&e.length>0?e:Ue.join(Wr.homedir(),".cache");return Ue.join(r,"infra-kit")},q=()=>{let e=He.env[ye];if(!e)throw new Error(`${ye} is not set. Run \`infra-kit init\` then \`source ~/.zshrc\`.`);return Ue.join(Br(),e)},be=(e,r,t)=>{let s=`${e}.tmp.${He.pid}`;oe.writeFileSync(s,r,{mode:t});try{oe.renameSync(s,e)}catch(o){throw oe.rmSync(s,{force:!0}),o}},K="-worktrees";var xe=async()=>{let e=q(),r=fr.join(e,F);if(!Ye.existsSync(r))throw new Error("No loaded environment found. Run `env-load` first.");let t=Re(r),s=[...t.map(a=>`unset ${a}`),`unset ${V}`,`unset ${W}`,`unset ${B}`],o=fr.resolve(e,dr);Ye.mkdirSync(e,{recursive:!0,mode:448}),be(o,`${s.join(`
|
|
4
4
|
`)}
|
|
5
|
-
|
|
6
|
-
`),
|
|
7
|
-
`).filter(Boolean),s={release:
|
|
8
|
-
`),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}},
|
|
5
|
+
`,384),qr.stdout.write(`${o}
|
|
6
|
+
`),Ye.unlinkSync(r);let i={filePath:o,variableCount:t.length,unsetStatements:s};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Kr={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:ke.string().describe("Path to the file that must be sourced to apply"),variableCount:ke.number().describe("Number of variables cleared"),unsetStatements:ke.array(ke.string()).describe("Unset statements generated")},handler:xe};import{z as Ze}from"zod";import gr from"node:fs/promises";import Hr from"node:path";import Yr from"yaml";import{z as $}from"zod";import zr from"node:path";import{$ as hr}from"zx";var O=async e=>{let t=(await hr`git worktree list`).stdout.split(`
|
|
7
|
+
`).filter(Boolean),s={release:Gr,feature:Ur};return t.map(s[e]).filter(o=>o!==null)},Gr=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("release/v")?null:`release/${r[0]?.split("/").pop()||""}`},Ur=e=>{let r=e.split(" ").filter(Boolean);return r.length<3||!r[0]?.includes("feature/")?null:`feature/${r[0]?.split("/").pop()||""}`},T=async()=>(await hr`git rev-parse --show-toplevel`).stdout.trim(),Xe=async()=>{let e=await T();return zr.basename(e)};var Xr="infra-kit.yml",Zr=$.object({type:$.literal("jira"),baseUrl:$.string().url(),projectId:$.number().int().positive()}),Qr=$.object({dopplerProjectName:$.string().min(1),environments:$.array($.string().min(1)).min(1),taskManagerProvider:$.union([$.string(),$.literal(!1),Zr])}),se=null,A=async()=>{let e=await T(),r=Hr.join(e,Xr),t;try{t=await gr.stat(r)}catch{throw se=null,new Error(`infra-kit.yml not found at ${r}`)}if(se&&se.mtimeMs===t.mtimeMs)return se.value;let s=await gr.readFile(r,"utf-8"),o=Yr.parse(s),i=Qr.safeParse(o);if(!i.success)throw new Error(`Invalid infra-kit.yml at ${r}: ${i.error.message}`);return se={mtimeMs:t.mtimeMs,value:i.data},i.data};var ne=async()=>{let{dopplerProjectName:e}=await A();return e};var Te=async()=>{let e=await ne(),{environments:r}=await A();n.info(`Doppler project: ${e}
|
|
8
|
+
`),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}},et={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:Ze.string().describe("Detected Doppler project name"),configs:Ze.array(Ze.string()).describe("Available environment configs")},handler:Te};import tt from"@inquirer/select";import{Buffer as ot}from"node:buffer";import st from"node:fs";import nt from"node:path";import yr from"node:process";import{z as ae}from"zod";import{$ as Ce}from"zx";import{$ as vr}from"zx";var ie=async()=>{try{await vr`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 vr`doppler me`}catch(e){throw new Error("Doppler CLI is not authenticated. Run: doppler login",{cause:e})}};var rt=()=>{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:
|
|
9
9
|
pnpm exec infra-kit ${e} ${s}
|
|
10
|
-
`)},reset(){e="",r=[],t=!1}}},l=
|
|
10
|
+
`)},reset(){e="",r=[],t=!1}}},l=rt();var Ie=async e=>{await ie();let{config:r}=e;l.start("env-load");let t="";if(r)t=r;else{let{environments:d}=await A();l.setInteractive(),t=await tt({message:"Select environment config",choices:d.map(h=>({name:h,value:h}))},{output:yr.stderr})}l.addOption("--config",t);let s=await ne(),o=await at(s,t);mt(o);let i=new Date().toISOString(),a=["set -a",o,`${V}=${Qe(t)}`,`${W}=${Qe(s)}`,`${B}=${Qe(i)}`,"set +a"],p=q(),c=nt.resolve(p,F);st.mkdirSync(p,{recursive:!0,mode:448}),be(c,`${a.join(`
|
|
11
11
|
`)}
|
|
12
|
-
|
|
13
|
-
`);let
|
|
14
|
-
`).filter(
|
|
15
|
-
`)}
|
|
16
|
-
`)
|
|
17
|
-
`);
|
|
12
|
+
`,384),yr.stdout.write(`${c}
|
|
13
|
+
`),l.print();let m=lt(o),u={filePath:c,variableCount:m,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}},wr=1024*1024,it=3e4,at=async(e,r)=>{let t=Ce.quiet;Ce.quiet=!0;try{let s=await Ce`doppler secrets download --no-file --format env --project ${e} --config ${r}`.timeout(it);return ct(s.stdout),s.stdout.trim()}finally{Ce.quiet=t}},ct=e=>{let r=ot.byteLength(e,"utf-8");if(r>wr)throw new Error(`doppler returned unexpectedly large output (${r} bytes > ${wr}) \u2014 refusing to write to disk`)},lt=e=>e.split(`
|
|
14
|
+
`).filter(r=>we.test(r)).length,pt=new Set(["set -a","set +a"]),Qe=e=>`'${e.replaceAll("'","'\\''")}'`,mt=e=>{if(e.trim().length===0)throw new Error("doppler returned empty output for env-load");for(let r of e.split(`
|
|
15
|
+
`)){let t=r.trim();if(!(t.length===0||pt.has(t))&&!we.test(t))throw new Error(`doppler returned unexpected output for env-load (expected KEY=value lines, got: ${JSON.stringify(t.slice(0,80))})`)}},ut={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:ae.string().describe('Doppler config / environment name to load (e.g. "dev", "arthur", "renana"). Required for MCP calls.')},outputSchema:{filePath:ae.string().describe("Path to the file that must be sourced to apply variables"),variableCount:ae.number().describe("Number of variables loaded"),project:ae.string().describe("Doppler project name"),config:ae.string().describe("Doppler config name")},handler:Ie};import dt from"node:path";import ce from"node:process";import{z}from"zod";var $e=async()=>{await ie(),n.info("Environment session status:");let e=q(),r=ce.env[ye],t=dt.join(e,F),s=0,o=0,i=ce.env[V]??null,a=ce.env[W]??null,p=ce.env[B]??null;if(i){let m=Re(t);m.length>0&&(o=m.length,s=m.filter(d=>d in ce.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})
|
|
16
|
+
`),o>0&&s<o){let d=o-s;n.warn(` ${d} 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
|
|
17
|
+
`);let c={sessionId:r,sessionLoadedCount:s,sessionTotalCount:o,sessionConfig:i,sessionProject:a,sessionLoadedAt:p};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},ft={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:z.string().describe("Current terminal session ID"),sessionLoadedCount:z.number().describe("Number of cached vars active in the current session"),sessionTotalCount:z.number().describe("Total number of cached var names"),sessionConfig:z.string().nullable().describe("Doppler config name of the loaded session (environment name)"),sessionProject:z.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:z.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:$e};import yt from"@inquirer/checkbox";import wt from"@inquirer/confirm";import Rt from"node:process";import{z as H}from"zod";import{$ as E}from"zx";import{$ as Us}from"zx";import Pe from"node:process";import{$ as C}from"zx";import{$ as me}from"zx";import le from"node:process";var er=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`,c=btoa(`${o}:${s}`),m=await fetch(p,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${c}`},body:JSON.stringify(a)});if(!m.ok){let d=await m.text();throw n.error({status:m.status,statusText:m.statusText,error:d},"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}},Ee=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}},gt=async(e,r)=>{try{return(await Ee(r)).find(o=>o.name===e)||null}catch(t){throw n.error({error:t,versionName:e},"Error finding Jira version by name"),t}},vt=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}`),c=await fetch(a,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${p}`},body:JSON.stringify(i)});if(!c.ok){let u=await c.text();throw n.error({status:c.status,statusText:c.statusText,error:u},"Failed to update Jira version"),new Error(`HTTP ${c.status}: ${c.statusText}`)}return{success:!0,version:await c.json()}}catch(t){throw n.error({error:t},"Error updating Jira version"),t}},rr=async(e,r)=>{try{let{versionName:t}=e,s=await gt(t,r);if(!s)throw n.error({versionName:t},"Jira version not found"),new Error(`Version "${t}" not found in Jira project`);return await vt({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}},G=async()=>{let e=le.env.JIRA_BASE_URL,r=le.env.JIRA_TOKEN||le.env.JIRA_API_TOKEN,t=le.env.JIRA_PROJECT_ID,s=le.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(`
|
|
18
|
+
`);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}},pe=async()=>{try{return await G()}catch(e){return n.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var _e=e=>e==="hotfix"?"main":"dev",ue=async(e="regular")=>{let r=_e(e);me.quiet=!0,await me`git fetch origin`,await me`git switch ${r}`,await me`git pull origin ${r}`,me.quiet=!1},de=async e=>{let{version:r,jiraConfig:t,description:s,type:o="regular"}=e,i=`v${r}`,a=await er({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`,c=await Se({version:r,jiraVersionUrl:p,type:o});return{version:r,type:o,branchName:c.branchName,prUrl:c.prUrl,jiraVersionUrl:p}},w=async()=>{let e=new Map,r=await pe();if(!r)return e;try{let t=await Ee(r);for(let s of t)s.description&&e.set(s.name,s.description)}catch{}return e},U=(e,r,t)=>{let s=t?" ".repeat(t-e.length+3):" ",o=`[${r}]`.padEnd(11);return`${e}${s}${o}`},v=e=>e.toLowerCase().startsWith("hotfix")?"hotfix":"regular",k=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 c=o[p],m=s?s.get(a)||"regular":void 0,u=t.get(`v${c}`),d=" ".repeat(i-c.length+3),h=m?U(c,m,i):c;return u&&(h=m?`${h} ${u}`:`${c}${d}${u}`),{name:h,value:a}})};var tr=e=>e.replace("release/","").slice(1).split(".").map(Number),Ae=e=>[...e].sort((r,t)=>{let[s,o,i]=tr(r),[a,p,c]=tr(t);return s!==a?(s??0)-(a??0):o!==p?(o??0)-(p??0):(i??0)-(c??0)});var Rr=async()=>{let e=await C`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=await C`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))},Ne=async()=>{try{let e=await Rr();return e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),Pe.exit(1)),Ae(e.map(r=>r.headRefName))}catch(e){n.error({error:e},"\u274C Error fetching release PRs"),Pe.exit(1)}},y=async()=>{try{let e=await Rr();e.length===0&&(n.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),Pe.exit(1));let r=Ae(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"),Pe.exit(1)}},Se=async e=>{let{version:r,jiraVersionUrl:t,type:s}=e,o=s==="hotfix"?"Hotfix":"Release",i=_e(s),a=`release/v${r}`;try{C.quiet=!0,await C`git switch ${i}`,await C`git pull origin ${i}`,await C`git checkout -b ${a}`,await C`git push -u origin ${a}`,await C`git commit --allow-empty-message --allow-empty --message ''`,await C`git push origin ${a}`;let c=(await C`gh pr create --title "${o} v${r}" --body "${t} \n" --base ${i} --head ${a}`).stdout.trim();return await C`git switch ${i}`,C.quiet=!1,{branchName:a,prUrl:c}}catch(p){throw n.error({error:p,branchName:a},`Error creating release branch ${a}`),p}};var Oe=async e=>{let{all:r,confirmedCommand:t}=e;l.start("merge-dev");let o=(await y()).filter(u=>v(u.title)==="regular").map(u=>u.branch);if(o.length===0)return n.info("\u2139\uFE0F No open release branches found"),l.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{l.setInteractive();let u=await w();i=await yt({required:!0,message:"\u{1F33F} Select release branches",choices:k({branches:o,descriptions:u})})}i.length===o.length?l.addOption("--all",!0):l.addOption("--versions",i.map(u=>u.replace("release/v","")));let p=t?!0:await wt({message:`Are you sure you want to merge dev into these branches: ${i.join(", ")}?`});t||l.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),Rt.exit(0)),t||l.addOption("--yes",!0),E.quiet=!0,await E`git fetch origin`,await E`git switch dev`,await E`git pull origin dev`;let c=[];for(let u of i)await bt(u)||c.push(u);if(E.quiet=!1,c.length>0){n.info(`
|
|
18
19
|
\u26A0\uFE0F ${c.length} branch(es) failed to merge automatically.
|
|
19
|
-
`),n.info("\u{1F4CB} Manual merge script for failed branches:");for(let
|
|
20
|
+
`),n.info("\u{1F4CB} Manual merge script for failed branches:");for(let u of c)n.info(`# Merge dev into ${u} and resolve conflicts if any
|
|
20
21
|
|
|
21
|
-
git switch ${
|
|
22
|
-
git push origin ${
|
|
23
|
-
`);n.info(`\u2705 ${
|
|
24
|
-
`);l.print();let m={successfulMerges:a.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:a.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},rt=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`,n.info(`Successfully merged dev into ${e}`),!0}catch(r){return n.error({error:r,branch:e},`Error merging dev into ${e}`),await _`git reset --merge HEAD~1`,!1}},tt={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:U.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:U.number().describe("Number of successful merges"),failedMerges:U.number().describe("Number of failed merges"),failedBranches:U.array(U.string()).describe("List of branches that failed to merge"),totalBranches:U.number().describe("Total number of branches processed")},handler:Ce};import ot from"@inquirer/confirm";import st from"@inquirer/select";import qe from"node:process";import{z as ce}from"zod";import{$ as k}from"zx";var Ie=async e=>{let{version:r,confirmedCommand:t}=e;l.start("release-deliver");let s=await y(),o=s.map(u=>u.branch),a=new Map(s.map(u=>[u.branch,v(u.title)])),i="";if(r)i=`release/v${r}`;else{l.setInteractive();let u=await w();i=await st({message:"\u{1F33F} Select release branch",choices:T({branches:o,descriptions:u,types:a})})}let p=i.replace("release/v","");l.addOption("--version",p);let c=s.find(u=>u.branch===i);c||(n.error(`\u274C Release branch ${i} not found in open PRs. Exiting...`),qe.exit(1));let m=v(c.title),d=t?!0:await ot({message:`Are you sure you want to deliver version ${i} to production?`});t||l.setInteractive(),d||(n.info("Operation cancelled. Exiting..."),qe.exit(0)),l.addOption("--yes",!0);try{k.quiet=!0,m==="hotfix"?(await k`gh pr merge ${i} --squash --admin --delete-branch`,k.quiet=!1,await k`gh workflow run deploy-all.yml --ref main -f environment=prod`,k.quiet=!0,await k`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await k`gh pr merge ${i} --squash --admin --delete-branch`,await k`gh pr create --base main --head dev --title "Release v${p} (RC)" --body ""`,await k`gh pr merge dev --squash --admin`,k.quiet=!1,await k`gh workflow run deploy-all.yml --ref main -f environment=prod`,k.quiet=!0,await k`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),k.quiet=!1;let u=await se();if(u)try{let f=i.replace("release/","");await Be({versionName:f},u)}catch(f){n.error({error:f},"Failed to deliver Jira release (non-blocking)")}else n.info("\u{1F514} Jira is not configured, skipping Jira release delivery");n.info(`Successfully delivered ${i} to production!`),l.print();let h={releaseBranch:i,version:i.replace("release/v",""),type:m,success:!0};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(u){n.error({error:u},"\u274C Error merging release branch into dev"),qe.exit(1)}},nt={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:ce.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:ce.string().describe("The release branch that was delivered"),version:ce.string().describe("The version that was delivered"),type:ce.enum(["regular","hotfix"]).describe("Release type"),success:ce.boolean().describe("Whether the delivery was successful")},handler:Ie};import lr from"@inquirer/select";import pr from"node:process";import{z as O}from"zod";import{$ as Ge}from"zx";var $e=async e=>{let{version:r,env:t,skipTerraform:s}=e;l.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let m=await y(),d=m.map(f=>f.branch),u=new Map(m.map(f=>[f.branch,v(f.title)])),h=await w();o=await lr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:d,descriptions:h,types:u})]})}let a=o==="dev"?"dev":o.replace("release/v","");l.addOption("--version",a);let{environments:i}=await S(),p="";t?p=t:(l.setInteractive(),p=await lr({message:"\u{1F9EA} Select environment",choices:i.map(m=>({name:m,value:m}))})),l.addOption("--env",p),i.includes(p)||(n.error(`\u274C Invalid environment: ${p}. Exiting...`),pr.exit(1));let c=s??!1;c&&l.addOption("--skip-terraform",!0);try{Ge.quiet=!0,await Ge`gh workflow run deploy-all.yml --ref ${o} -f environment=${p} ${c?["-f","skip_terraform_deploy=true"]:[]}`,Ge.quiet=!1,n.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${p}`),l.print();let d={releaseBranch:o,version:o.replace("release/v",""),environment:p,skipTerraformDeploy:c,success:!0};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(m){n.error({error:m},"\u274C Error launching workflow"),pr.exit(1)}},it={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:O.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:O.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:O.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:O.string().describe("The release branch that was deployed"),version:O.string().describe("The version that was deployed"),environment:O.string().describe("The environment deployed to"),skipTerraformDeploy:O.boolean().describe("Whether terraform deployment was skipped"),success:O.boolean().describe("Whether the deployment was successful")},handler:$e};import at from"@inquirer/checkbox";import mr from"@inquirer/select";import ct from"node:fs/promises";import{resolve as lt}from"node:path";import le from"node:process";import pt from"yaml";import{z as I}from"zod";import{$ as ze}from"zx";var _e=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;l.start("release-deploy-selected");let a="";if(r)a=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let f=await y(),x=f.map(N=>N.branch),A=new Map(f.map(N=>[N.branch,v(N.title)])),b=await w();a=await mr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:x,descriptions:b,types:A})]})}let i=a==="dev"?"dev":a.replace("release/v","");l.addOption("--version",i);let{environments:p}=await S(),c="";t?c=t:(l.setInteractive(),c=await mr({message:"\u{1F9EA} Select environment",choices:p.map(f=>({name:f,value:f}))})),l.addOption("--env",c),p.includes(c)||(n.error(`\u274C Invalid environment: ${c}. Exiting...`),le.exit(1));let m=await mt();m.length===0&&(n.error("\u274C No services found in workflow file. Exiting..."),le.exit(1));let d=[];s&&s.length>0?d=s:(l.setInteractive(),d=await at({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),l.addOption("--services",d),d.length===0&&(n.error("\u274C No services selected. Exiting..."),le.exit(1));let u=d.filter(f=>!m.includes(f));u.length>0&&(n.error(`\u274C Invalid services: ${u.join(", ")}. Available services: ${m.join(", ")}`),le.exit(1));let h=o??!1;h&&l.addOption("--skip-terraform",!0);try{ze.quiet=!0;let f=d.flatMap(b=>["-f",`${b}=true`]);await ze`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${c} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,ze.quiet=!1,n.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${c}, services: ${d.join(", ")}`),l.print();let A={releaseBranch:a,version:a.replace("release/v",""),environment:c,services:d,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(A,null,2)}],structuredContent:A}}catch(f){n.error({error:f},"\u274C Error launching workflow"),le.exit(1)}},mt=async()=>{let e=await $(),r=lt(e,".github/workflows/deploy-selected-services.yml"),t=await ct.readFile(r,"utf-8"),o=pt.parse(t).on.workflow_dispatch.inputs,a=[];for(let[i,p]of Object.entries(o))p.type==="boolean"&&i!=="skip_terraform_deploy"&&a.push(i);return a},dt={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:I.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:I.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:I.array(I.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:I.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:I.string().describe("The release branch that was deployed"),version:I.string().describe("The version that was deployed"),environment:I.string().describe("The environment deployed to"),services:I.array(I.string()).describe("The services that were deployed"),skipTerraformDeploy:I.boolean().describe("Whether terraform deployment was skipped"),success:I.boolean().describe("Whether the deployment was successful")},handler:_e};import{z as H}from"zod";var Ae=async()=>{let r=(await y()).map(i=>({version:i.branch.replace("release/",""),type:v(i.title)})),t=await w(),s=Math.max(...r.map(i=>i.version.length)),o=r.map(i=>{let p=z(i.version,i.type,s),c=t.get(i.version);return c?`${p} ${c}`:p});n.info(`All release branches:
|
|
22
|
+
git switch ${u} && git pull origin ${u} && git merge origin/dev
|
|
23
|
+
git push origin ${u} && git switch dev
|
|
24
|
+
`);n.info(`\u2705 ${i.length-c.length}/${i.length} merges completed successfully.`)}else n.info(`\u2705 All merges completed successfully!
|
|
25
|
+
`);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}},bt=async e=>{try{return await E`git switch ${e}`,await E`git pull origin ${e}`,await E`git merge origin/dev --no-edit`,await E`git push origin ${e}`,await E`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 E`git reset --merge HEAD~1`,!1}},kt={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:Oe};import xt from"@inquirer/confirm";import Tt from"@inquirer/select";import or from"node:process";import{z as fe}from"zod";import{$ as b}from"zx";var Le=async e=>{let{version:r,confirmedCommand:t}=e;l.start("release-deliver");let s=await y(),o=s.map(d=>d.branch),i=new Map(s.map(d=>[d.branch,v(d.title)])),a="";if(r)a=`release/v${r}`;else{l.setInteractive();let d=await w();a=await Tt({message:"\u{1F33F} Select release branch",choices:k({branches:o,descriptions:d,types:i})})}let p=a.replace("release/v","");l.addOption("--version",p);let c=s.find(d=>d.branch===a);c||(n.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),or.exit(1));let m=v(c.title),u=t?!0:await xt({message:`Are you sure you want to deliver version ${a} to production?`});t||l.setInteractive(),u||(n.info("Operation cancelled. Exiting..."),or.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 d=await pe();if(d)try{let f=a.replace("release/","");await rr({versionName:f},d)}catch(f){n.error({error:f},"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!`),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(d){n.error({error:d},"\u274C Error merging release branch into dev"),or.exit(1)}},Ct={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:Le};import br from"@inquirer/select";import kr from"node:process";import{z as L}from"zod";import{$ as sr}from"zx";var De=async e=>{let{version:r,env:t,skipTerraform:s}=e;l.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let m=await y(),u=m.map(f=>f.branch),d=new Map(m.map(f=>[f.branch,v(f.title)])),h=await w();o=await br({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...k({branches:u,descriptions:h,types:d})]})}let i=o==="dev"?"dev":o.replace("release/v","");l.addOption("--version",i);let{environments:a}=await A(),p="";t?p=t:(l.setInteractive(),p=await br({message:"\u{1F9EA} Select environment",choices:a.map(m=>({name:m,value:m}))})),l.addOption("--env",p),a.includes(p)||(n.error(`\u274C Invalid environment: ${p}. Exiting...`),kr.exit(1));let c=s??!1;c&&l.addOption("--skip-terraform",!0);try{sr.quiet=!0,await sr`gh workflow run deploy-all.yml --ref ${o} -f environment=${p} ${c?["-f","skip_terraform_deploy=true"]:[]}`,sr.quiet=!1,n.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){n.error({error:m},"\u274C Error launching workflow"),kr.exit(1)}},It={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:L.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:L.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:L.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:L.string().describe("The release branch that was deployed"),version:L.string().describe("The version that was deployed"),environment:L.string().describe("The environment deployed to"),skipTerraformDeploy:L.boolean().describe("Whether terraform deployment was skipped"),success:L.boolean().describe("Whether the deployment was successful")},handler:De};import $t from"@inquirer/checkbox";import xr from"@inquirer/select";import Et from"node:fs/promises";import{resolve as _t}from"node:path";import he from"node:process";import St from"yaml";import{z as I}from"zod";import{$ as nr}from"zx";var Me=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;l.start("release-deploy-selected");let i="";if(r)i=r==="dev"?"dev":`release/v${r}`;else{l.setInteractive();let f=await y(),_=f.map(M=>M.branch),N=new Map(f.map(M=>[M.branch,v(M.title)])),S=await w();i=await xr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...k({branches:_,descriptions:S,types:N})]})}let a=i==="dev"?"dev":i.replace("release/v","");l.addOption("--version",a);let{environments:p}=await A(),c="";t?c=t:(l.setInteractive(),c=await xr({message:"\u{1F9EA} Select environment",choices:p.map(f=>({name:f,value:f}))})),l.addOption("--env",c),p.includes(c)||(n.error(`\u274C Invalid environment: ${c}. Exiting...`),he.exit(1));let m=await At();m.length===0&&(n.error("\u274C No services found in workflow file. Exiting..."),he.exit(1));let u=[];s&&s.length>0?u=s:(l.setInteractive(),u=await $t({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),l.addOption("--services",u),u.length===0&&(n.error("\u274C No services selected. Exiting..."),he.exit(1));let d=u.filter(f=>!m.includes(f));d.length>0&&(n.error(`\u274C Invalid services: ${d.join(", ")}. Available services: ${m.join(", ")}`),he.exit(1));let h=o??!1;h&&l.addOption("--skip-terraform",!0);try{nr.quiet=!0;let f=u.flatMap(S=>["-f",`${S}=true`]);await nr`gh workflow run deploy-selected-services.yml --ref ${i} -f environment=${c} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,nr.quiet=!1,n.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${i}, environment: ${c}, services: ${u.join(", ")}`),l.print();let N={releaseBranch:i,version:i.replace("release/v",""),environment:c,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(N,null,2)}],structuredContent:N}}catch(f){n.error({error:f},"\u274C Error launching workflow"),he.exit(1)}},At=async()=>{let e=await T(),r=_t(e,".github/workflows/deploy-selected-services.yml"),t=await Et.readFile(r,"utf-8"),o=St.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},Pt={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:I.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:I.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:I.array(I.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:I.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:I.string().describe("The release branch that was deployed"),version:I.string().describe("The version that was deployed"),environment:I.string().describe("The environment deployed to"),services:I.array(I.string()).describe("The services that were deployed"),skipTerraformDeploy:I.boolean().describe("Whether terraform deployment was skipped"),success:I.boolean().describe("Whether the deployment was successful")},handler:Me};import{z as Y}from"zod";var Je=async()=>{let r=(await y()).map(a=>({version:a.branch.replace("release/",""),type:v(a.title)})),t=await w(),s=Math.max(...r.map(a=>a.version.length)),o=r.map(a=>{let p=U(a.version,a.type,s),c=t.get(a.version);return c?`${p} ${c}`:p});n.info(`All release branches:
|
|
25
26
|
`),n.info(`
|
|
26
27
|
${o.join(`
|
|
27
28
|
`)}
|
|
28
|
-
`);let
|
|
29
|
+
`);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}},Nt={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:Je};import je from"node:fs";import Ot from"node:os";import Lt from"node:path";var Cr="# -- infra-kit:begin --",Ir="# -- infra-kit:end --",Dt=[["# region infra-kit","# endregion infra-kit"]],Mt="# infra-kit shell functions",ir=async()=>{let e=Lt.join(Ot.homedir(),".zshrc"),r=Ft();if(je.existsSync(e)){let t=je.readFileSync(e,"utf-8"),s=jt(t);je.writeFileSync(e,s)}je.appendFileSync(e,`
|
|
29
30
|
${r}
|
|
30
|
-
`),n.info(`Added infra-kit shell functions to ${e}`),n.info("Run `source ~/.zshrc` or open a new terminal to activate.")},
|
|
31
|
-
${
|
|
32
|
-
`),
|
|
33
|
-
`);return s+(
|
|
34
|
-
${
|
|
35
|
-
`)};import
|
|
36
|
-
`)}catch(
|
|
37
|
-
`)}let
|
|
38
|
-
${
|
|
31
|
+
`),n.info(`Added infra-kit shell functions to ${e}`),n.info("Run `source ~/.zshrc` or open a new terminal to activate.")},Jt=e=>e.startsWith("#")||e.startsWith("alias ")||e.startsWith("env-load")||e.startsWith("env-clear")||e.startsWith("env-status")||e.startsWith("if ")||e.startsWith(" export INFRA_KIT_SESSION")||e.startsWith("export _INFRA_KIT_")||e.startsWith(": ${_INFRA_KIT_")||e.startsWith("fi")||e.startsWith("zmodload ")||e.startsWith("autoload ")||e.startsWith("add-zsh-hook ")||e.startsWith("_infra_kit_autoload"),Tr=(e,r,t)=>{let s=e.indexOf(r),o=e.indexOf(t);if(s===-1||o===-1)return null;let i=e.slice(0,s).replace(/\n+$/,""),a=e.slice(o+t.length).replace(/^\n+/,"");return i+(a?`
|
|
32
|
+
${a}`:"")},jt=e=>{let r=Tr(e,Cr,Ir);if(r!==null)return r;for(let[p,c]of Dt){let m=Tr(e,p,c);if(m!==null)return m}let t=e.indexOf(Mt);if(t===-1)return e;let s=e.slice(0,t).replace(/\n+$/,""),o=e.slice(t).split(`
|
|
33
|
+
`),i=0;for(;i<o.length&&Jt(o[i]);)i++;let a=o.slice(i).join(`
|
|
34
|
+
`);return s+(a?`
|
|
35
|
+
${a}`:"")},Ft=()=>{let e="pnpm exec infra-kit";return[Cr,"zmodload zsh/stat 2>/dev/null","zmodload zsh/datetime 2>/dev/null",'if [[ -z "${INFRA_KIT_SESSION}" ]]; then'," export INFRA_KIT_SESSION=$(head -c 4 /dev/urandom | xxd -p)","fi",": ${_INFRA_KIT_LAST_LOAD_MTIME:=0}",": ${_INFRA_KIT_LAST_CLEAR_MTIME:=0}",": ${_INFRA_KIT_SHELL_STARTED:=${EPOCHSECONDS:-0}}","export _INFRA_KIT_LAST_LOAD_MTIME _INFRA_KIT_LAST_CLEAR_MTIME _INFRA_KIT_SHELL_STARTED",`env-load() { local f m; f=$(${e} env-load "$@") || return; m=$(zstat +mtime -- "$f" 2>/dev/null || echo 0); _INFRA_KIT_LAST_LOAD_MTIME=$m; source "$f"; ${e} env-status; }`,`env-clear() { local f m; f=$(${e} env-clear) || return; m=$(zstat +mtime -- "$f" 2>/dev/null || echo 0); _INFRA_KIT_LAST_CLEAR_MTIME=$m; source "$f"; ${e} env-status; }`,`env-status() { ${e} env-status; }`,`alias ik='${e}'`,"_infra_kit_autoload() {",' [[ -z "$INFRA_KIT_SESSION" ]] && return',' local cache_root="${XDG_CACHE_HOME:-$HOME/.cache}/infra-kit"',' local dir="$cache_root/$INFRA_KIT_SESSION"',' local load_file="$dir/env-load.sh"',' local clear_file="$dir/env-clear.sh"'," local mtime",' if [[ -f "$load_file" ]]; then',' mtime=$(zstat +mtime -- "$load_file" 2>/dev/null || echo 0)'," if (( mtime > _INFRA_KIT_LAST_LOAD_MTIME && mtime >= _INFRA_KIT_SHELL_STARTED )); then",' source "$load_file"'," _INFRA_KIT_LAST_LOAD_MTIME=$mtime",' print -u2 "infra-kit: auto-loaded vars for ${INFRA_KIT_ENV_CONFIG:-?}"'," fi"," fi",' if [[ -f "$clear_file" ]]; then',' mtime=$(zstat +mtime -- "$clear_file" 2>/dev/null || echo 0)'," if (( mtime > _INFRA_KIT_LAST_CLEAR_MTIME && mtime >= _INFRA_KIT_SHELL_STARTED )); then",' source "$clear_file"'," _INFRA_KIT_LAST_CLEAR_MTIME=$mtime",' print -u2 "infra-kit: auto-cleared env"'," fi"," fi","}","autoload -Uz add-zsh-hook","if (( _INFRA_KIT_SHELL_STARTED > 0 )); then"," add-zsh-hook precmd _infra_kit_autoload","fi",Ir].join(`
|
|
36
|
+
`)};import $r from"@inquirer/confirm";import Vt from"@inquirer/select";import Er from"node:process";import{z as P}from"zod";import{$ as ar,question as _r}from"zx";var Fe=async e=>{let{version:r,description:t,type:s,confirmedCommand:o,checkout:i}=e;l.start("release-create");let a=r,p=t,c=s||"regular",m=i,u=await G();a||(l.setInteractive(),a=await _r("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(n.error("No version provided. Exiting..."),Er.exit(1));let d=a.trim();l.addOption("--version",d),s||(l.setInteractive(),c=await Vt({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),l.addOption("--type",c),p===void 0&&(l.setInteractive(),p=await _r("Enter description (optional, press Enter to skip): "),p.trim()===""&&(p="")),p&&l.addOption("--description",p);let h=o?!0:await $r({message:`Are you sure you want to create release branch for version ${d}?`});o||l.setInteractive(),h||(n.info("Operation cancelled. Exiting..."),Er.exit(0)),l.addOption("--yes",!0),await ue(c);let f=await de({version:d,jiraConfig:u,description:p,type:c});n.info(`\u2705 Successfully created release: v${d}`),n.info(`\u{1F517} GitHub PR: ${f.prUrl}`),n.info(`\u{1F517} Jira Version: ${f.jiraVersionUrl}`),m===void 0&&(l.setInteractive(),m=await $r({message:`Do you want to checkout to the created branch ${f.branchName}?`,default:!0})),m||l.addOption("--no-checkout",!0),m&&(ar.quiet=!0,await ar`git switch ${f.branchName}`,ar.quiet=!1,n.info(`\u{1F504} Switched to branch ${f.branchName}`)),l.print();let _={version:d,type:c,branchName:f.branchName,prUrl:f.prUrl,jiraVersionUrl:f.jiraVersionUrl,isCheckedOut:m};return{content:[{type:"text",text:JSON.stringify(_,null,2)}],structuredContent:_}},Wt={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:P.string().describe('Version to create (e.g., "1.2.5"). Required for MCP calls.'),description:P.string().optional().describe("Optional description for the Jira version"),type:P.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")'),checkout:P.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:P.string().describe("Version number"),type:P.enum(["regular","hotfix"]).describe("Release type"),branchName:P.string().describe("Release branch name"),prUrl:P.string().describe("GitHub PR URL"),jiraVersionUrl:P.string().describe("Jira version URL"),isCheckedOut:P.boolean().describe("Whether the branch was checked out")},handler:Fe};import Bt from"@inquirer/confirm";import qt from"@inquirer/select";import Sr from"node:process";import{z as R}from"zod";import{question as Kt}from"zx";var zt=async e=>{let{versions:r,type:t,confirmedCommand:s}=e,o=r,i=t||"regular";o||(l.setInteractive(),o=await Kt("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let a=o.split(",").map(c=>c.trim()).filter(Boolean);l.addOption("--versions",a.join(", ")),a.length===0&&(n.error("No versions provided. Exiting..."),Sr.exit(1)),t||(l.setInteractive(),i=await qt({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),l.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 Bt({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`});return s||l.setInteractive(),p||(n.info("Operation cancelled. Exiting..."),Sr.exit(0)),l.addOption("--yes",!0),{versionsList:a,type:i}},Ve=async e=>{l.start("release-create-batch");let r=await G(),{versionsList:t,type:s}=await zt(e);await ue(s);let o=[],i=[];for(let m of t)try{let u=await de({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}
|
|
37
|
+
`)}catch(u){let d=u instanceof Error?u.message:String(u);i.push({version:m,error:d}),n.error(`\u274C Failed to create release: v${m}`),n.error(` Error: ${d}
|
|
38
|
+
`)}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.`),l.print();let c={createdBranches:o.map(m=>m.branchName),successCount:a,failureCount:p,releases:o,failedReleases:i};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},Gt={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:R.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6"). Required for MCP calls.'),type:R.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")')},outputSchema:{createdBranches:R.array(R.string()).describe("List of created release branches"),successCount:R.number().describe("Number of releases created successfully"),failureCount:R.number().describe("Number of releases that failed"),releases:R.array(R.object({version:R.string().describe("Version number"),type:R.enum(["regular","hotfix"]).describe("Release type"),branchName:R.string().describe("Release branch name"),prUrl:R.string().describe("GitHub PR URL"),jiraVersionUrl:R.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:R.array(R.object({version:R.string().describe("Version number that failed"),error:R.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:Ve};import{z as Ht}from"zod";var Ar={name:"infra-kit",type:"module",version:"0.1.91",description:"infra-kit",main:"dist/cli.js",module:"dist/cli.js",bin:{"infra-kit":"dist/cli.js",ik:"dist/cli.js"},engines:{node:">=24.x"},scripts:{inspector:"npx @modelcontextprotocol/inspector node ./dist/mcp.js --debug",build:"pnpm run clean-artifacts && node ./scripts/build.js","clean-artifacts":"rm -rf dist","clean-cache":"rm -rf node_modules/.cache .eslintcache tsconfig.tsbuildinfo .turbo .swc","prettier-fix":"pnpm exec prettier **/* --write --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","prettier-check":"pnpm exec prettier **/* --check --no-error-on-unmatched-pattern --log-level warn --ignore-path ../../../.prettierignore","eslint-check":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src","eslint-fix":"pnpm exec eslint --cache --quiet --report-unused-disable-directives ./src --fix","ts-check":"tsc --noEmit",test:"pnpm exec vitest run --reporter=dot","test-watch":"pnpm exec vitest --watch","test-ui":"pnpm exec vitest --ui","test-report":"pnpm exec vitest run --coverage",qa:"pnpm run prettier-check && pnpm run eslint-check && pnpm run ts-check && pnpm run test && echo \u2705 Success",fix:"pnpm run prettier-fix && pnpm run eslint-fix && pnpm run qa"},dependencies:{"@inquirer/checkbox":"^5.1.4","@inquirer/confirm":"^6.0.12","@inquirer/select":"^5.1.4","@modelcontextprotocol/sdk":"^1.29.0",commander:"^14.0.3",pino:"^10.3.1","pino-pretty":"^13.1.3",yaml:"^2.8.3",zod:"^3.25.76",zx:"^8.8.5"},devDependencies:{"@pkg/eslint-config":"workspace:*","@pkg/vitest-config":"workspace:*",esbuild:"^0.28.0",typescript:"^5.9.3"}};var We=async()=>{let e=Ar.version;n.info(e);let r={version:e};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},Yt={name:"version",description:"Print the installed infra-kit CLI version",inputSchema:{},outputSchema:{version:Ht.string().describe("Installed infra-kit CLI version (from package.json)")},handler:We};import Zt from"@inquirer/checkbox";import Be from"@inquirer/confirm";import Qt from"node:process";import{z as D}from"zod";import{$ as Z}from"zx";import{$ as X}from"zx";var cr=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=Xt(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}`},Xt=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 eo="feature",ro="release",to="release/v",qe=async e=>{let{confirmedCommand:r,all:t,versions:s,cursor:o,githubDesktop:i,cmux:a}=e;l.start("worktrees-add");try{let p=await O("release"),m=`${await T()}${K}`;await Pr(`${m}/${ro}`),await Pr(`${m}/${eo}`);let u=[];if(s)u=s.split(",").map(x=>`release/v${x.trim()}`);else{let x=await y(),J=x.map(re=>re.branch);if(J.length===0)return n.info("\u2139\uFE0F No open release branches found"),l.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};if(t)u=J;else{l.setInteractive();let re=new Map(x.map(ur=>[ur.branch,v(ur.title)])),Lr=await w();u=await Zt({required:!0,message:"\u{1F33F} Select release branches",choices:k({branches:J,descriptions:Lr,types:re})})}}t?l.addOption("--all",!0):l.addOption("--versions",u.map(x=>x.replace("release/v","")));let d=r?!0:await Be({message:"Are you sure you want to proceed with these worktree changes?"});r||l.setInteractive(),d||(n.info("Operation cancelled. Exiting..."),Qt.exit(0)),r||l.addOption("--yes",!0);let h=o??await Be({message:"Open created worktrees in Cursor?"});typeof o>"u"&&l.setInteractive(),h?l.addOption("--cursor",!0):l.addOption("--no-cursor",!0);let f=i??await Be({message:"Open created worktrees in GitHub Desktop?"});typeof i>"u"&&l.setInteractive(),f?l.addOption("--github-desktop",!0):l.addOption("--no-github-desktop",!0);let _=a??await Be({message:"Open created worktrees in cmux?"});typeof a>"u"&&l.setInteractive(),_?l.addOption("--cmux",!0):l.addOption("--no-cmux",!0);let{branchesToCreate:N}=oo({selectedReleaseBranches:u,currentWorktrees:p}),S=await so(N,m);if(no(S),h)for(let x of S)await Z`cursor ${m}/${x}`;if(f)for(let x of S)await Z`github ${m}/${x}`,await Z`sleep 5`;if(_){let x=await Xe();for(let J of S){let re=J.replace("release/","");await cr({cwd:`${m}/${J}`,title:`${x} ${re}`})}}l.print();let M={createdWorktrees:S,count:S.length};return{content:[{type:"text",text:JSON.stringify(M,null,2)}],structuredContent:M}}catch(p){throw n.error({error:p},"\u274C Error managing worktrees"),p}},Pr=async e=>{await Z`mkdir -p ${e}`},oo=e=>{let{selectedReleaseBranches:r,currentWorktrees:t}=e,s=t.filter(i=>i.startsWith(to));return{branchesToCreate:r.filter(i=>!s.includes(i))}},so=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},no=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")},io={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:qe};import{z as Q}from"zod";var Ke=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([y(),w()]),s=new Map(r.map(c=>[c.branch,v(c.title)])),o=e.map(c=>{let m=c.replace("release/",""),u=s.get(c)||"regular",d=t.get(m)||null;return{version:m,type:u,description:d}}),i=Math.max(...o.map(c=>c.version.length)),a=o.map(c=>{let m=U(c.version,c.type,i);return c.description?`${m} ${c.description}`:m});n.info("\u{1F33F} Active worktrees:"),n.info(`
|
|
39
|
+
${a.join(`
|
|
39
40
|
`)}
|
|
40
|
-
`);let p={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},Mt={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:X.array(X.object({version:X.string().describe("Release version"),type:X.enum(["regular","hotfix"]).describe("Release type"),description:X.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:X.number().describe("Number of worktrees")},handler:Oe};import Jt from"@inquirer/checkbox";import jt from"@inquirer/confirm";import Ft from"node:process";import{z as pe}from"zod";import{$ as Xe}from"zx";var De=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;l.start("worktrees-remove");try{let o=await P("release");if(o.length===0)return n.info("\u2139\uFE0F No active worktrees to remove"),l.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let i=`${await $()}${K}`,p=[];if(t)p=o;else if(s)p=s.split(",").map(h=>`release/v${h.trim()}`);else{l.setInteractive();let[h,f]=await Promise.all([w(),y()]),x=new Map(f.map(A=>[A.branch,v(A.title)]));p=await Jt({required:!0,message:"\u{1F33F} Select release branches",choices:T({branches:o,descriptions:h,types:x})})}p.length===o.length?l.addOption("--all",!0):l.addOption("--versions",p.map(h=>h.replace("release/v","")));let m=r?!0:await jt({message:"Are you sure you want to proceed with these worktree changes?"});r||l.setInteractive(),m||(n.info("Operation cancelled. Exiting..."),Ft.exit(0)),r||l.addOption("--yes",!0);let d=await Vt(p,i);Wt(d),l.print();let u={removedWorktrees:d,count:d.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(o){throw n.error({error:o},"\u274C Error managing worktrees"),o}},Vt=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let a=`${r}/${o}`;return await Xe`git worktree remove ${a}`,o})),s=[];for(let[o,a]of t.entries())if(a.status==="fulfilled")s.push(a.value);else{let i=e[o];n.error({error:a.reason},`\u274C Failed to remove worktree for ${i}`)}return s.length===e.length&&(await Xe`git worktree prune`,await Xe`rm -rf ${r}`,n.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${r}`),n.info("")),s},Wt=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")},Bt={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:pe.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:pe.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:pe.array(pe.string()).describe("List of removed git worktree branches"),count:pe.number().describe("Number of git worktrees removed")},handler:De};import Kt from"@inquirer/confirm";import qt from"node:process";import{z as Ze}from"zod";import{$ as Gt}from"zx";var zt="release/v",Le=async e=>{let{confirmedCommand:r}=e;l.start("worktrees-sync");try{let t=await P("release"),o=`${await $()}${K}`,a=await Te(),i=r?!0:await Kt({message:"Are you sure you want to proceed with these worktree changes?"});r||l.setInteractive(),i||(n.info("Operation cancelled. Exiting..."),qt.exit(0)),r||l.addOption("--yes",!0);let{branchesToRemove:p}=Ut({releasePRsList:a,currentWorktrees:t}),c=await Ht(p,o);Yt(c),l.print();let m={removedWorktrees:c,count:c.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}},Ut=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(a=>a.startsWith(zt)).filter(a=>!r.includes(a))}},Ht=async(e,r)=>{let t=[];for(let s of e)try{let o=`${r}/${s}`;await Gt`git worktree remove ${o}`,t.push(s)}catch(o){n.error({error:o,branch:s},`\u274C Failed to remove worktree for ${s}`)}return t},Yt=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")},Xt={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:Ze.array(Ze.string()).describe("List of removed worktree branches"),count:Ze.number().describe("Number of worktrees removed during sync")},handler:Le};var g=new Qt;g.command("merge-dev").description("Merge dev branch into every release branch").option("-a, --all","Select all active release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Ce({all:e.all,confirmedCommand:e.yes})});g.command("release-list").description("List all release branches").action(async()=>{await Ae()});g.command("release-create").description("Create a single release branch").option("-v, --version <version>","Specify the version to create, e.g. 1.2.5").option("-d, --description <description>","Optional description for the Jira version").addOption(new br("-t, --type <type>","Release type (default: regular)").choices(["regular","hotfix"])).option("-y, --yes","Skip confirmation prompt").option("--no-checkout","Do not checkout the created branch after creation (checkout is default)").action(async e=>{await Ee({version:e.version,description:e.description,type:e.type,confirmedCommand:e.yes,checkout:e.checkout})});g.command("release-create-batch").description("Create multiple release branches (batch operation)").option("-v, --versions <versions>","Specify the versions to create by comma, e.g. 1.2.5, 1.2.6").addOption(new br("-t, --type <type>","Release type (default: regular)").choices(["regular","hotfix"])).option("-y, --yes","Skip confirmation prompt").action(async e=>{await Pe({versions:e.versions,type:e.type,confirmedCommand:e.yes})});g.command("release-deploy-all").description("Deploy any release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await $e({version:e.version,env:e.env,skipTerraform:e.skipTerraform})});g.command("release-deploy-selected").description("Deploy selected services from release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("-s, --services <services...>","Specify services to deploy, e.g. client-be client-fe").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await _e({version:e.version,env:e.env,services:e.services,skipTerraform:e.skipTerraform})});g.command("release-deliver").description("Release a new version to production").option("-v, --version <version>","Specify the version to release, e.g. 1.2.5").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Ie({version:e.version,confirmedCommand:e.yes})});g.command("worktrees-sync").description("Remove release worktrees whose PRs are no longer open").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Le({confirmedCommand:e.yes})});g.command("worktrees-add").description("Add git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").option("-v, --versions <versions>","Specify versions by comma, e.g. 1.2.5, 1.2.6").option("-c, --cursor","Open created worktrees in Cursor").option("--no-cursor","Skip Cursor prompt").option("-g, --github-desktop","Open created worktrees in GitHub Desktop").option("--no-github-desktop","Skip GitHub Desktop prompt").action(async e=>{await Ne({confirmedCommand:e.yes,all:e.all,versions:e.versions,cursor:e.cursor,githubDesktop:e.githubDesktop})});g.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await Oe()});g.command("worktrees-remove").description("Remove git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").option("-v, --versions <versions>","Specify versions by comma, e.g. 1.2.5, 1.2.6").action(async e=>{await De({confirmedCommand:e.yes,all:e.all,versions:e.versions})});g.command("doctor").description("Check installation and authentication status of gh and doppler CLIs").action(async()=>{await me()});g.command("env-status").description("Show Doppler authentication status and detected project info").action(async()=>{await ye()});g.command("env-list").description("List available Doppler configs for the detected project").action(async()=>{await ge()});g.command("init").description("Inject shell integration into your profile .zshrc").action(async()=>{await Ue()});g.command("env-load").description("Load Doppler env vars for a config. Source the returned file path to apply.").option("-c, --config <config>","Environment config name to load (e.g. dev, arthur)").action(async e=>{await ve({config:e.config})});g.command("env-clear").description("Clear loaded env vars. Source the returned file path to apply.").action(async()=>{await he()});if(Rr.argv.length<=2){let e=["merge-dev","release-list","release-create","release-create-batch","release-deploy-all","release-deploy-selected","release-deliver"],r=["worktrees-add","worktrees-list","worktrees-remove","worktrees-sync"],t=["doctor","init","env-status","env-list","env-load","env-clear"],s=new Map(g.commands.map(c=>[c.name(),c])),o=[...e,...r,...t],a=Math.max(...o.map(c=>c.length)),i=c=>c.filter(m=>s.has(m)).map(m=>({name:`${m.padEnd(a)} ${s.get(m).description()}`,value:m})),p=await Zt({message:"Select a command to run",choices:[new Z(" "),new Z("\u2014 Release Management \u2014"),...i(e),new Z(" "),new Z("\u2014 Worktrees \u2014"),...i(r),new Z(" "),new Z("\u2014 Environment \u2014"),...i(t)]},{output:Rr.stderr});g.parse(["node","infra-kit",p])}else g.parse();
|
|
41
|
+
`);let p={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},ao={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:Ke};import co from"@inquirer/checkbox";import lo from"@inquirer/confirm";import po from"node:process";import{z as ge}from"zod";import{$ as lr}from"zx";var ze=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;l.start("worktrees-remove");try{let o=await O("release");if(o.length===0)return n.info("\u2139\uFE0F No active worktrees to remove"),l.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let a=`${await T()}${K}`,p=[];if(t)p=o;else if(s)p=s.split(",").map(h=>`release/v${h.trim()}`);else{l.setInteractive();let[h,f]=await Promise.all([w(),y()]),_=new Map(f.map(N=>[N.branch,v(N.title)]));p=await co({required:!0,message:"\u{1F33F} Select release branches",choices:k({branches:o,descriptions:h,types:_})})}p.length===o.length?l.addOption("--all",!0):l.addOption("--versions",p.map(h=>h.replace("release/v","")));let m=r?!0:await lo({message:"Are you sure you want to proceed with these worktree changes?"});r||l.setInteractive(),m||(n.info("Operation cancelled. Exiting..."),po.exit(0)),r||l.addOption("--yes",!0);let u=await mo(p,a);uo(u),l.print();let d={removedWorktrees:u,count:u.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(o){throw n.error({error:o},"\u274C Error managing worktrees"),o}},mo=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let i=`${r}/${o}`;return await lr`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 lr`git worktree prune`,await lr`rm -rf ${r}`,n.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${r}`),n.info("")),s},uo=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")},fo={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:ge.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:ge.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:ge.array(ge.string()).describe("List of removed git worktree branches"),count:ge.number().describe("Number of git worktrees removed")},handler:ze};import ho from"@inquirer/confirm";import go from"node:process";import{z as pr}from"zod";import{$ as vo}from"zx";var yo="release/v",Ge=async e=>{let{confirmedCommand:r}=e;l.start("worktrees-sync");try{let t=await O("release"),o=`${await T()}${K}`,i=await Ne(),a=r?!0:await ho({message:"Are you sure you want to proceed with these worktree changes?"});r||l.setInteractive(),a||(n.info("Operation cancelled. Exiting..."),go.exit(0)),r||l.addOption("--yes",!0);let{branchesToRemove:p}=wo({releasePRsList:i,currentWorktrees:t}),c=await Ro(p,o);bo(c),l.print();let m={removedWorktrees:c,count:c.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}},wo=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(i=>i.startsWith(yo)).filter(i=>!r.includes(i))}},Ro=async(e,r)=>{let t=[];for(let s of e)try{let o=`${r}/${s}`;await vo`git worktree remove ${o}`,t.push(s)}catch(o){n.error({error:o,branch:s},`\u274C Failed to remove worktree for ${s}`)}return t},bo=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")},ko={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:pr.array(pr.string()).describe("List of removed worktree branches"),count:pr.number().describe("Number of worktrees removed during sync")},handler:Ge};var g=new To,Nr=async e=>{try{e?await g.parseAsync(e):await g.parseAsync()}catch(r){let t=r instanceof Error?r.message:String(r);n.error(t),mr.exit(1)}};g.command("merge-dev").description("Merge dev branch into every release branch").option("-a, --all","Select all active release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Oe({all:e.all,confirmedCommand:e.yes})});g.command("release-list").description("List all release branches").action(async()=>{await Je()});g.command("release-create").description("Create a single release branch").option("-v, --version <version>","Specify the version to create, e.g. 1.2.5").option("-d, --description <description>","Optional description for the Jira version").addOption(new Or("-t, --type <type>","Release type (default: regular)").choices(["regular","hotfix"])).option("-y, --yes","Skip confirmation prompt").option("--no-checkout","Do not checkout the created branch after creation (checkout is default)").action(async e=>{await Fe({version:e.version,description:e.description,type:e.type,confirmedCommand:e.yes,checkout:e.checkout})});g.command("release-create-batch").description("Create multiple release branches (batch operation)").option("-v, --versions <versions>","Specify the versions to create by comma, e.g. 1.2.5, 1.2.6").addOption(new Or("-t, --type <type>","Release type (default: regular)").choices(["regular","hotfix"])).option("-y, --yes","Skip confirmation prompt").action(async e=>{await Ve({versions:e.versions,type:e.type,confirmedCommand:e.yes})});g.command("release-deploy-all").description("Deploy any release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await De({version:e.version,env:e.env,skipTerraform:e.skipTerraform})});g.command("release-deploy-selected").description("Deploy selected services from release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("-s, --services <services...>","Specify services to deploy, e.g. client-be client-fe").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await Me({version:e.version,env:e.env,services:e.services,skipTerraform:e.skipTerraform})});g.command("release-deliver").description("Release a new version to production").option("-v, --version <version>","Specify the version to release, e.g. 1.2.5").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Le({version:e.version,confirmedCommand:e.yes})});g.command("worktrees-sync").description("Remove release worktrees whose PRs are no longer open").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Ge({confirmedCommand:e.yes})});g.command("worktrees-add").description("Add git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").option("-v, --versions <versions>","Specify versions by comma, e.g. 1.2.5, 1.2.6").option("-c, --cursor","Open created worktrees in Cursor").option("--no-cursor","Skip Cursor prompt").option("-g, --github-desktop","Open created worktrees in GitHub Desktop").option("--no-github-desktop","Skip GitHub Desktop prompt").option("-m, --cmux","Open created worktrees in cmux (3-pane layout)").option("--no-cmux","Skip cmux prompt").action(async e=>{await qe({confirmedCommand:e.yes,all:e.all,versions:e.versions,cursor:e.cursor,githubDesktop:e.githubDesktop,cmux:e.cmux})});g.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await Ke()});g.command("worktrees-remove").description("Remove git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").option("-v, --versions <versions>","Specify versions by comma, e.g. 1.2.5, 1.2.6").action(async e=>{await ze({confirmedCommand:e.yes,all:e.all,versions:e.versions})});g.command("doctor").description("Check installation and authentication status of gh and doppler CLIs").action(async()=>{await ve()});g.command("version").description("Print the installed infra-kit CLI version").action(async()=>{await We()});g.command("env-status").description("Show Doppler authentication status and detected project info").action(async()=>{await $e()});g.command("env-list").description("List available Doppler configs for the detected project").action(async()=>{await Te()});g.command("init").description("Inject shell integration into your profile .zshrc").action(async()=>{await ir()});g.command("env-load").description("Load Doppler env vars for a config. Source the returned file path to apply.").option("-c, --config <config>","Environment config name to load (e.g. dev, arthur)").action(async e=>{await Ie({config:e.config})});g.command("env-clear").description("Clear loaded env vars. Source the returned file path to apply.").action(async()=>{await xe()});if(mr.argv.length<=2){let e=["merge-dev","release-list","release-create","release-create-batch","release-deploy-all","release-deploy-selected","release-deliver"],r=["worktrees-add","worktrees-list","worktrees-remove","worktrees-sync"],t=["doctor","init","version","env-status","env-list","env-load","env-clear"],s=new Map(g.commands.map(c=>[c.name(),c])),o=[...e,...r,...t],i=Math.max(...o.map(c=>c.length)),a=c=>c.filter(m=>s.has(m)).map(m=>({name:`${m.padEnd(i)} ${s.get(m).description()}`,value:m})),p=await xo({message:"Select a command to run",choices:[new ee(" "),new ee("\u2014 Release Management \u2014"),...a(e),new ee(" "),new ee("\u2014 Worktrees \u2014"),...a(r),new ee(" "),new ee("\u2014 Environment \u2014"),...a(t)]},{output:mr.stderr});await Nr(["node","infra-kit",p])}else await Nr();
|
|
41
42
|
//# sourceMappingURL=cli.js.map
|