infra-kit 0.1.95 → 0.1.97
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 +5 -4
- package/.turbo/turbo-prettier-check.log +5 -7
- package/.turbo/turbo-test.log +18 -82
- package/.turbo/turbo-ts-check.log +5 -10
- package/dist/cli.js +28 -27
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +28 -27
- package/dist/mcp.js.map +4 -4
- package/package.json +2 -2
- package/src/commands/worktrees-open/index.ts +1 -0
- package/src/commands/worktrees-open/worktrees-open.ts +197 -0
- package/src/commands/worktrees-remove/worktrees-remove.ts +4 -2
- package/src/entry/cli.ts +9 -1
- package/src/integrations/cmux/index.ts +1 -0
- package/src/integrations/cmux/list-workspace-titles.ts +42 -0
- package/src/integrations/cursor/index.ts +1 -0
- package/src/integrations/cursor/reconcile-workspace-folders.ts +90 -0
- package/src/lib/git-utils/git-utils.ts +27 -8
- package/src/mcp/tools/index.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/mcp.js
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import{StdioServerTransport as
|
|
2
|
-
`)){let o=
|
|
1
|
+
import{StdioServerTransport as ts}from"@modelcontextprotocol/sdk/server/stdio.js";import kt from"node:process";import j from"node:process";import Tr from"node:process";import Ve from"pino";import xt from"pino-pretty";var ie="/tmp/mcp-infra-kit.log",Pr=()=>{let e=Tr.argv.includes("--debug")?"debug":"info",r=Ve({level:e},Ve.destination({dest:ie}));return r.info(`Logger initialized with level: ${e}. Logging to: ${ie}`),r},Ct=()=>{let e=Tr.argv.includes("--debug")?"debug":"info",r=["time","pid","hostname"];return e==="debug"&&r.push("level"),Ve({level:e},xt({destination:2,ignore:r.join(","),colorize:!0}))},i=Ct();var $r=e=>{j.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),j.exit(0)}),j.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),j.exit(0)}),j.on("uncaughtException",r=>{e.fatal({err:r,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${ie}. Shutting down...`),e.flush(),j.exit(1)}),j.on("unhandledRejection",(r,t)=>{e.fatal({reason:r,promise:t,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${ie}. Shutting down...`),e.flush(),j.exit(1)})};import{McpServer as rs}from"@modelcontextprotocol/sdk/server/mcp.js";var Er=async e=>{};var Sr=async e=>{};import Ue from"node:fs";import Ir from"node:path";import $t from"node:process";import{z as Se}from"zod/v4";import ae from"node:fs";import Tt from"node:os";import Be from"node:path";import qe from"node:process";var K="env-load.sh",Ar="env-clear.sh",Te="INFRA_KIT_SESSION",z="INFRA_KIT_ENV_CONFIG",H="INFRA_KIT_ENV_PROJECT",Y="INFRA_KIT_ENV_LOADED_AT",Pe=/^([A-Z_]\w*)=/i,$e=e=>{if(!ae.existsSync(e))return[];let r=ae.readFileSync(e,"utf-8"),t=[];for(let s of r.split(`
|
|
2
|
+
`)){let o=Pe.exec(s);o&&t.push(o[1])}return t},Pt=()=>{let e=qe.env.XDG_CACHE_HOME,r=e&&e.length>0?e:Be.join(Tt.homedir(),".cache");return Be.join(r,"infra-kit")},X=()=>{let e=qe.env[Te];if(!e)throw new Error(`${Te} is not set. Run \`infra-kit init\` then \`source ~/.zshrc\`.`);return Be.join(Pt(),e)},Ee=(e,r,t)=>{let s=`${e}.tmp.${qe.pid}`;ae.writeFileSync(s,r,{mode:t});try{ae.renameSync(s,e)}catch(o){throw ae.rmSync(s,{force:!0}),o}},J="-worktrees";var Or=async()=>{let e=X(),r=Ir.join(e,K);if(!Ue.existsSync(r))throw new Error("No loaded environment found. Run `env-load` first.");let t=$e(r),s=[...t.map(a=>`unset ${a}`),`unset ${z}`,`unset ${H}`,`unset ${Y}`],o=Ir.resolve(e,Ar);Ue.mkdirSync(e,{recursive:!0,mode:448}),Ee(o,`${s.join(`
|
|
3
3
|
`)}
|
|
4
|
-
`,384)
|
|
5
|
-
`),
|
|
6
|
-
`).filter(Boolean),s={release:
|
|
7
|
-
`),
|
|
4
|
+
`,384),$t.stdout.write(`${o}
|
|
5
|
+
`),Ue.unlinkSync(r);let n={filePath:o,variableCount:t.length,unsetStatements:s};return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}},Ge={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:Se.string().describe("Path to the file that must be sourced to apply"),variableCount:Se.number().describe("Number of variables cleared"),unsetStatements:Se.array(Se.string()).describe("Unset statements generated")},handler:Or};import{z as Ke}from"zod/v4";import Ae from"node:fs/promises";import Fr from"node:path";import Wr from"yaml";import{z as g}from"zod/v4";import Et from"node:path";import{$ as Nr}from"zx";var I=async e=>{let t=(await Nr`git worktree list`).stdout.split(`
|
|
6
|
+
`).filter(Boolean),s={release:St,feature:At};return t.map(s[e]).filter(o=>o!==null)},Mr=e=>{let r=e.trimEnd();if(!r.endsWith("]"))return null;let t=r.lastIndexOf("[");if(t===-1)return null;let s=r.slice(t+1,-1);return s.length>0?s:null},St=e=>{let r=Mr(e);return r?.startsWith("release/v")?r:null},At=e=>{let r=Mr(e);return r?.startsWith("feature/")?r:null},T=async()=>(await Nr`git rev-parse --show-toplevel`).stdout.trim(),W=async()=>{let e=await T();return Et.basename(e)};var It="infra-kit.yml",Ot="infra-kit.local.yml",Nt=g.object({provider:g.literal("doppler"),config:g.object({name:g.string().min(1)})}),Mt=g.discriminatedUnion("provider",[Nt]),Ft=g.object({mode:g.enum(["workspace","windows"]).default("workspace"),workspaceConfigPath:g.string().min(1).optional()}).refine(e=>e.mode!=="workspace"||!!e.workspaceConfigPath,{message:'workspaceConfigPath is required when mode is "workspace"',path:["workspaceConfigPath"]}),Wt=g.object({provider:g.literal("cursor"),config:Ft}),Dt=g.discriminatedUnion("provider",[Wt]),_t=g.object({provider:g.literal("jira"),config:g.object({baseUrl:g.string().url(),projectId:g.number().int().positive()})}),jt=g.discriminatedUnion("provider",[_t]),Dr=g.object({environments:g.array(g.string().min(1)).min(1),envManagement:Mt,ide:Dt.optional(),taskManager:jt.optional()}),Jt=Dr.partial(),Z=null,v=async()=>{let e=await T(),r=Fr.join(e,It),t=Fr.join(e,Ot),s;try{s=await Ae.stat(r)}catch{throw Z=null,new Error(`infra-kit.yml not found at ${r}`)}let o=await Lt(t),n=Number(s.mtimeMs),a=o?Number(o.mtimeMs):null;if(Z&&Z.mainMtimeMs===n&&Z.localMtimeMs===a)return Z.value;let l=await Ae.readFile(r,"utf-8"),c=Wr.parse(l),m=c;if(o){let d=await Ae.readFile(t,"utf-8"),h=Wr.parse(d)??{},f=Jt.safeParse(h);if(!f.success)throw new Error(`Invalid infra-kit.local.yml at ${t}: ${g.prettifyError(f.error)}`);m={...c,...f.data}}let u=Dr.safeParse(m);if(!u.success)throw new Error(`Invalid infra-kit.yml at ${r}: ${g.prettifyError(u.error)}`);return Z={mainMtimeMs:n,localMtimeMs:a,value:u.data},u.data};var Lt=async e=>{try{return await Ae.stat(e)}catch{return null}};var ce=async()=>{let{envManagement:e}=await v();return e.config.name};var _r=async()=>{let e=await ce(),{environments:r}=await v();i.info(`Doppler project: ${e}
|
|
7
|
+
`),i.info("Available configs:");for(let s of r)i.info(` - ${s}`);let t={project:e,configs:r};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},ze={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:Ke.string().describe("Detected Doppler project name"),configs:Ke.array(Ke.string()).describe("Available environment configs")},handler:_r};import Bt from"@inquirer/select";import{Buffer as qt}from"node:buffer";import Ut from"node:fs";import Gt from"node:path";import Jr from"node:process";import{z as pe}from"zod/v4";import{$ as Ie}from"zx";import{$ as jr}from"zx";var le=async()=>{try{await jr`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 jr`doppler me`}catch(e){throw new Error("Doppler CLI is not authenticated. Run: doppler login",{cause:e})}};var Vt=()=>{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(" ");i.info(`\u{1F4DF} Equivalent command:
|
|
8
8
|
pnpm exec infra-kit ${e} ${s}
|
|
9
|
-
`)},reset(){e="",r=[],t=!1}}},p=
|
|
9
|
+
`)},reset(){e="",r=[],t=!1}}},p=Vt();var Vr=async e=>{await le();let{config:r}=e;p.start("env-load");let t="";if(r)t=r;else{let{environments:d}=await v();p.setInteractive(),t=await Bt({message:"Select environment config",choices:d.map(h=>({name:h,value:h}))},{output:Jr.stderr})}p.addOption("--config",t);let s=await ce(),o=await zt(s,t);Zt(o);let n=new Date().toISOString(),a=["set -a",o,`${z}=${He(t)}`,`${H}=${He(s)}`,`${Y}=${He(n)}`,"set +a"],l=X(),c=Gt.resolve(l,K);Ut.mkdirSync(l,{recursive:!0,mode:448}),Ee(c,`${a.join(`
|
|
10
10
|
`)}
|
|
11
|
-
`,384),
|
|
12
|
-
`),p.print();let m=
|
|
13
|
-
`).filter(r=>
|
|
14
|
-
`)){let t=r.trim();if(!(t.length===0||
|
|
15
|
-
`),o>0&&s<o){let d=o-s;
|
|
16
|
-
`);let c={sessionId:r,sessionLoadedCount:s,sessionTotalCount:o,sessionConfig:n,sessionProject:
|
|
17
|
-
`);throw new Error(
|
|
11
|
+
`,384),Jr.stdout.write(`${c}
|
|
12
|
+
`),p.print();let m=Yt(o),u={filePath:c,variableCount:m,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}},Lr=1024*1024,Kt=3e4,zt=async(e,r)=>{let t=Ie.quiet;Ie.quiet=!0;try{let s=await Ie`doppler secrets download --no-file --format env --project ${e} --config ${r}`.timeout(Kt);return Ht(s.stdout),s.stdout.trim()}finally{Ie.quiet=t}},Ht=e=>{let r=qt.byteLength(e,"utf-8");if(r>Lr)throw new Error(`doppler returned unexpectedly large output (${r} bytes > ${Lr}) \u2014 refusing to write to disk`)},Yt=e=>e.split(`
|
|
13
|
+
`).filter(r=>Pe.test(r)).length,Xt=new Set(["set -a","set +a"]),He=e=>`'${e.replaceAll("'","'\\''")}'`,Zt=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||Xt.has(t))&&!Pe.test(t))throw new Error(`doppler returned unexpected output for env-load (expected KEY=value lines, got: ${JSON.stringify(t.slice(0,80))})`)}},Ye={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:pe.string().describe('Doppler config / environment name to load (e.g. "dev", "arthur", "renana"). Required for MCP calls.')},outputSchema:{filePath:pe.string().describe("Path to the file that must be sourced to apply variables"),variableCount:pe.number().describe("Number of variables loaded"),project:pe.string().describe("Doppler project name"),config:pe.string().describe("Doppler config name")},handler:Vr};import Qt from"node:path";import me from"node:process";import{z as Q}from"zod/v4";var Br=async()=>{await le(),i.info("Environment session status:");let e=X(),r=me.env[Te],t=Qt.join(e,K),s=0,o=0,n=me.env[z]??null,a=me.env[H]??null,l=me.env[Y]??null;if(n){let m=$e(t);m.length>0&&(o=m.length,s=m.filter(d=>d in me.env).length);let u=l?.replace(/\.\d{3}Z$/,"")??null;if(i.info(` ${n}: ${s} of ${o} vars loaded (project: ${a}, loadedAt: ${u}, session: ${r})
|
|
15
|
+
`),o>0&&s<o){let d=o-s;i.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 i.info(` Session ${r}: no env loaded
|
|
16
|
+
`);let c={sessionId:r,sessionLoadedCount:s,sessionTotalCount:o,sessionConfig:n,sessionProject:a,sessionLoadedAt:l};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},Xe={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:Q.string().describe("Current terminal session ID"),sessionLoadedCount:Q.number().describe("Number of cached vars active in the current session"),sessionTotalCount:Q.number().describe("Total number of cached var names"),sessionConfig:Q.string().nullable().describe("Doppler config name of the loaded session (environment name)"),sessionProject:Q.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:Q.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:Br};import oo from"@inquirer/checkbox";import so from"@inquirer/confirm";import no from"node:process";import{z as te}from"zod/v4";import{$ as O}from"zx";import{$ as An}from"zx";import We from"node:process";import{$ as S}from"zx";import{$ as fe}from"zx";import ue from"node:process";var Ze=async(e,r)=>{try{let{baseUrl:t,token:s,email:o,projectId:n}=r,a={name:e.name,projectId:e.projectId||n,description:e.description||"",released:e.released||!1,archived:e.archived||!1},l=`${t}/rest/api/3/version`,c=btoa(`${o}:${s}`),m=await fetch(l,{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 i.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 i.error({error:t},"Error creating Jira version"),t}},Oe=async e=>{try{let{baseUrl:r,token:t,email:s,projectId:o}=e,n=`${r}/rest/api/3/project/${o}/versions`,a=btoa(`${s}:${t}`),l=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${a}`}});if(!l.ok){let m=await l.text();throw i.error({status:l.status,statusText:l.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return await l.json()}catch(r){throw i.error({error:r},"Error getting Jira project versions"),r}},ro=async(e,r)=>{try{return(await Oe(r)).find(o=>o.name===e)||null}catch(t){throw i.error({error:t,versionName:e},"Error finding Jira version by name"),t}},to=async(e,r)=>{try{let{baseUrl:t,token:s,email:o}=r,n={released:e.released??!0,archived:e.archived??!1};e.releaseDate?n.releaseDate=e.releaseDate:e.released!==!1&&(n.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(n.description=e.description);let a=`${t}/rest/api/3/version/${e.versionId}`,l=btoa(`${o}:${s}`),c=await fetch(a,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(n)});if(!c.ok){let u=await c.text();throw i.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 i.error({error:t},"Error updating Jira version"),t}},Qe=async(e,r)=>{try{let{versionName:t}=e,s=await ro(t,r);if(!s)throw i.error({versionName:t},"Jira version not found"),new Error(`Version "${t}" not found in Jira project`);return await to({versionId:s.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},r)}catch(t){throw i.error({error:t},"Error delivering Jira release"),t}},ee=async()=>{let e=ue.env.JIRA_BASE_URL,r=ue.env.JIRA_TOKEN||ue.env.JIRA_API_TOKEN,t=ue.env.JIRA_PROJECT_ID,s=ue.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(l=>` - ${l}`),"","You can set these in your .env file or as environment variables."].join(`
|
|
17
|
+
`);throw new Error(a)}let n=Number.parseInt(t,10);if(Number.isNaN(n))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${t}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:n,email:s}},de=async()=>{try{return await ee()}catch(e){return i.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var Ne=e=>e==="hotfix"?"main":"dev",he=async(e="regular")=>{let r=Ne(e);fe.quiet=!0,await fe`git fetch origin`,await fe`git switch ${r}`,await fe`git pull origin ${r}`,fe.quiet=!1},ge=async e=>{let{version:r,jiraConfig:t,description:s,type:o="regular"}=e,n=`v${r}`,a=await Ze({name:n,projectId:t.projectId,description:s||"",released:!1,archived:!1},t),l=`${t.baseUrl}/projects/${a.version.projectId}/versions/${a.version.id}/tab/release-report-all-issues`,c=await Me({version:r,jiraVersionUrl:l,type:o,description:s});return{version:r,type:o,branchName:c.branchName,prUrl:c.prUrl,jiraVersionUrl:l}},R=async()=>{let e=new Map,r=await de();if(!r)return e;try{let t=await Oe(r);for(let s of t)s.description&&e.set(s.name,s.description)}catch{}return e},re=(e,r,t)=>{let s=t?" ".repeat(t-e.length+3):" ",o=`[${r}]`.padEnd(11);return`${e}${s}${o}`},w=e=>e.toLowerCase().startsWith("hotfix")?"hotfix":"regular",E=e=>{let{branches:r,descriptions:t,types:s}=e,o=r.map(a=>a.replace("release/v","")),n=Math.max(...o.map(a=>a.length));return r.map((a,l)=>{let c=o[l],m=s?s.get(a)||"regular":void 0,u=t.get(`v${c}`),d=" ".repeat(n-c.length+3),h=m?re(c,m,n):c;return u&&(h=m?`${h} ${u}`:`${c}${d}${u}`),{name:h,value:a}})};var er=e=>e.replace("release/","").slice(1).split(".").map(Number),Fe=e=>[...e].sort((r,t)=>{let[s,o,n]=er(r),[a,l,c]=er(t);return s!==a?(s??0)-(a??0):o!==l?(o??0)-(l??0):(n??0)-(c??0)});var qr=async()=>{let e=await S`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,r=await S`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))},De=async()=>{try{let e=await qr();return e.length===0&&(i.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),We.exit(1)),Fe(e.map(r=>r.headRefName))}catch(e){i.error({error:e},"\u274C Error fetching release PRs"),We.exit(1)}},y=async()=>{try{let e=await qr();e.length===0&&(i.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),We.exit(1));let r=Fe(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){i.error({error:e},"\u274C Error fetching release PRs"),We.exit(1)}},Me=async e=>{let{version:r,jiraVersionUrl:t,type:s,description:o}=e,n=s==="hotfix"?"Hotfix":"Release",a=Ne(s),l=`release/v${r}`,c=o&&o.trim()!==""?`${t}
|
|
18
18
|
|
|
19
19
|
${o}`:`${t}
|
|
20
|
-
`;try{
|
|
20
|
+
`;try{S.quiet=!0,await S`git switch ${a}`,await S`git pull origin ${a}`,await S`git checkout -b ${l}`,await S`git push -u origin ${l}`,await S`git commit --allow-empty-message --allow-empty --message ''`,await S`git push origin ${l}`;let u=(await S`gh pr create --title "${n} v${r}" --body ${c} --base ${a} --head ${l}`).stdout.trim();return await S`git switch ${a}`,S.quiet=!1,{branchName:l,prUrl:u}}catch(m){throw i.error({error:m,branchName:l},`Error creating release branch ${l}`),m}};var Ur=async e=>{let{all:r,confirmedCommand:t}=e;p.start("merge-dev");let o=(await y()).filter(u=>w(u.title)==="regular").map(u=>u.branch);if(o.length===0)return i.info("\u2139\uFE0F No open release branches found"),p.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 n=[];if(r)n=o;else{p.setInteractive();let u=await R();n=await oo({required:!0,message:"\u{1F33F} Select release branches",choices:E({branches:o,descriptions:u})})}n.length===o.length?p.addOption("--all",!0):p.addOption("--versions",n.map(u=>u.replace("release/v","")));let l=t?!0:await so({message:`Are you sure you want to merge dev into these branches: ${n.join(", ")}?`});t||p.setInteractive(),l||(i.info("Operation cancelled. Exiting..."),no.exit(0)),t||p.addOption("--yes",!0),O.quiet=!0,await O`git fetch origin`,await O`git switch dev`,await O`git pull origin dev`;let c=[];for(let u of n)await io(u)||c.push(u);if(O.quiet=!1,c.length>0){i.info(`
|
|
21
21
|
\u26A0\uFE0F ${c.length} branch(es) failed to merge automatically.
|
|
22
|
-
`),
|
|
22
|
+
`),i.info("\u{1F4CB} Manual merge script for failed branches:");for(let u of c)i.info(`# Merge dev into ${u} and resolve conflicts if any
|
|
23
23
|
|
|
24
24
|
git switch ${u} && git pull origin ${u} && git merge origin/dev
|
|
25
25
|
git push origin ${u} && git switch dev
|
|
26
|
-
`);
|
|
27
|
-
`);p.print();let m={successfulMerges:n.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:n.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Qt=async e=>{try{return await S`git switch ${e}`,await S`git pull origin ${e}`,await S`git merge origin/dev --no-edit`,await S`git push origin ${e}`,await S`git switch dev`,a.info(`Successfully merged dev into ${e}`),!0}catch(r){return a.error({error:r,branch:e},`Error merging dev into ${e}`),await S`git reset --merge HEAD~1`,!1}},Xe={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:re.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:re.number().describe("Number of successful merges"),failedMerges:re.number().describe("Number of failed merges"),failedBranches:re.array(re.string()).describe("List of branches that failed to merge"),totalBranches:re.number().describe("Total number of branches processed")},handler:Wr};import eo from"@inquirer/confirm";import ro from"@inquirer/select";import Ze from"node:process";import{z as he}from"zod/v4";import{$ as C}from"zx";var Fr=async e=>{let{version:r,confirmedCommand:t}=e;p.start("release-deliver");let s=await w(),o=s.map(d=>d.branch),n=new Map(s.map(d=>[d.branch,v(d.title)])),i="";if(r)i=`release/v${r}`;else{p.setInteractive();let d=await R();i=await ro({message:"\u{1F33F} Select release branch",choices:T({branches:o,descriptions:d,types:n})})}let l=i.replace("release/v","");p.addOption("--version",l);let c=s.find(d=>d.branch===i);c||(a.error(`\u274C Release branch ${i} not found in open PRs. Exiting...`),Ze.exit(1));let m=v(c.title),u=t?!0:await eo({message:`Are you sure you want to deliver version ${i} to production?`});t||p.setInteractive(),u||(a.info("Operation cancelled. Exiting..."),Ze.exit(0)),p.addOption("--yes",!0);try{C.quiet=!0,m==="hotfix"?(await C`gh pr merge ${i} --squash --admin --delete-branch`,C.quiet=!1,await C`gh workflow run deploy-all.yml --ref main -f environment=prod`,C.quiet=!0,await C`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await C`gh pr merge ${i} --squash --admin --delete-branch`,await C`gh pr create --base main --head dev --title "Release v${l} (RC)" --body ""`,await C`gh pr merge dev --squash --admin`,C.quiet=!1,await C`gh workflow run deploy-all.yml --ref main -f environment=prod`,C.quiet=!0,await C`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),C.quiet=!1;let d=await me();if(d)try{let f=i.replace("release/","");await He({versionName:f},d)}catch(f){a.error({error:f},"Failed to deliver Jira release (non-blocking)")}else a.info("\u{1F514} Jira is not configured, skipping Jira release delivery");a.info(`Successfully delivered ${i} to production!`),p.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(d){a.error({error:d},"\u274C Error merging release branch into dev"),Ze.exit(1)}},Qe={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:he.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:he.string().describe("The release branch that was delivered"),version:he.string().describe("The version that was delivered"),type:he.enum(["regular","hotfix"]).describe("Release type"),success:he.boolean().describe("Whether the delivery was successful")},handler:Fr};import Lr from"@inquirer/select";import Vr from"node:process";import{z as J}from"zod/v4";import{$ as er}from"zx";var Br=async e=>{let{version:r,env:t,skipTerraform:s}=e;p.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let m=await w(),u=m.map(f=>f.branch),d=new Map(m.map(f=>[f.branch,v(f.title)])),h=await R();o=await Lr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:u,descriptions:h,types:d})]})}let n=o==="dev"?"dev":o.replace("release/v","");p.addOption("--version",n);let{environments:i}=await y(),l="";t?l=t:(p.setInteractive(),l=await Lr({message:"\u{1F9EA} Select environment",choices:i.map(m=>({name:m,value:m}))})),p.addOption("--env",l),i.includes(l)||(a.error(`\u274C Invalid environment: ${l}. Exiting...`),Vr.exit(1));let c=s??!1;c&&p.addOption("--skip-terraform",!0);try{er.quiet=!0,await er`gh workflow run deploy-all.yml --ref ${o} -f environment=${l} ${c?["-f","skip_terraform_deploy=true"]:[]}`,er.quiet=!1,a.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${l}`),p.print();let u={releaseBranch:o,version:o.replace("release/v",""),environment:l,skipTerraformDeploy:c,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){a.error({error:m},"\u274C Error launching workflow"),Vr.exit(1)}},rr={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:J.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:J.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),skipTerraform:J.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:J.string().describe("The release branch that was deployed"),version:J.string().describe("The version that was deployed"),environment:J.string().describe("The environment deployed to"),skipTerraformDeploy:J.boolean().describe("Whether terraform deployment was skipped"),success:J.boolean().describe("Whether the deployment was successful")},handler:Br};import to from"@inquirer/checkbox";import qr from"@inquirer/select";import oo from"node:fs/promises";import{resolve as so}from"node:path";import ge from"node:process";import no from"yaml";import{z as E}from"zod/v4";import{$ as tr}from"zx";var Ur=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;p.start("release-deploy-selected");let n="";if(r)n=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let f=await w(),A=f.map(W=>W.branch),_=new Map(f.map(W=>[W.branch,v(W.title)])),x=await R();n=await qr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...T({branches:A,descriptions:x,types:_})]})}let i=n==="dev"?"dev":n.replace("release/v","");p.addOption("--version",i);let{environments:l}=await y(),c="";t?c=t:(p.setInteractive(),c=await qr({message:"\u{1F9EA} Select environment",choices:l.map(f=>({name:f,value:f}))})),p.addOption("--env",c),l.includes(c)||(a.error(`\u274C Invalid environment: ${c}. Exiting...`),ge.exit(1));let m=await io();m.length===0&&(a.error("\u274C No services found in workflow file. Exiting..."),ge.exit(1));let u=[];s&&s.length>0?u=s:(p.setInteractive(),u=await to({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),p.addOption("--services",u),u.length===0&&(a.error("\u274C No services selected. Exiting..."),ge.exit(1));let d=u.filter(f=>!m.includes(f));d.length>0&&(a.error(`\u274C Invalid services: ${d.join(", ")}. Available services: ${m.join(", ")}`),ge.exit(1));let h=o??!1;h&&p.addOption("--skip-terraform",!0);try{tr.quiet=!0;let f=u.flatMap(x=>["-f",`${x}=true`]);await tr`gh workflow run deploy-selected-services.yml --ref ${n} -f environment=${c} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,tr.quiet=!1,a.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${n}, environment: ${c}, services: ${u.join(", ")}`),p.print();let _={releaseBranch:n,version:n.replace("release/v",""),environment:c,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(_,null,2)}],structuredContent:_}}catch(f){a.error({error:f},"\u274C Error launching workflow"),ge.exit(1)}},io=async()=>{let e=await P(),r=so(e,".github/workflows/deploy-selected-services.yml"),t=await oo.readFile(r,"utf-8"),o=no.parse(t).on.workflow_dispatch.inputs,n=[];for(let[i,l]of Object.entries(o))l.type==="boolean"&&i!=="skip_terraform_deploy"&&n.push(i);return n},or={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:E.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:E.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:E.array(E.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:E.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:E.string().describe("The release branch that was deployed"),version:E.string().describe("The version that was deployed"),environment:E.string().describe("The environment deployed to"),services:E.array(E.string()).describe("The services that were deployed"),skipTerraformDeploy:E.boolean().describe("Whether terraform deployment was skipped"),success:E.boolean().describe("Whether the deployment was successful")},handler:Ur};import{z as te}from"zod/v4";var Gr=async()=>{let r=(await w()).map(i=>({version:i.branch.replace("release/",""),type:v(i.title)})),t=await R(),s=Math.max(...r.map(i=>i.version.length)),o=r.map(i=>{let l=ee(i.version,i.type,s),c=t.get(i.version);return c?`${l} ${c}`:l});a.info(`All release branches:
|
|
28
|
-
`),
|
|
26
|
+
`);i.info(`\u2705 ${n.length-c.length}/${n.length} merges completed successfully.`)}else i.info(`\u2705 All merges completed successfully!
|
|
27
|
+
`);p.print();let m={successfulMerges:n.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:n.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},io=async e=>{try{return await O`git switch ${e}`,await O`git pull origin ${e}`,await O`git merge origin/dev --no-edit`,await O`git push origin ${e}`,await O`git switch dev`,i.info(`Successfully merged dev into ${e}`),!0}catch(r){return i.error({error:r,branch:e},`Error merging dev into ${e}`),await O`git reset --merge HEAD~1`,!1}},rr={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:te.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:te.number().describe("Number of successful merges"),failedMerges:te.number().describe("Number of failed merges"),failedBranches:te.array(te.string()).describe("List of branches that failed to merge"),totalBranches:te.number().describe("Total number of branches processed")},handler:Ur};import ao from"@inquirer/confirm";import co from"@inquirer/select";import tr from"node:process";import{z as ve}from"zod/v4";import{$ as P}from"zx";var Gr=async e=>{let{version:r,confirmedCommand:t}=e;p.start("release-deliver");let s=await y(),o=s.map(d=>d.branch),n=new Map(s.map(d=>[d.branch,w(d.title)])),a="";if(r)a=`release/v${r}`;else{p.setInteractive();let d=await R();a=await co({message:"\u{1F33F} Select release branch",choices:E({branches:o,descriptions:d,types:n})})}let l=a.replace("release/v","");p.addOption("--version",l);let c=s.find(d=>d.branch===a);c||(i.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),tr.exit(1));let m=w(c.title),u=t?!0:await ao({message:`Are you sure you want to deliver version ${a} to production?`});t||p.setInteractive(),u||(i.info("Operation cancelled. Exiting..."),tr.exit(0)),p.addOption("--yes",!0);try{P.quiet=!0,m==="hotfix"?(await P`gh pr merge ${a} --squash --admin --delete-branch`,P.quiet=!1,await P`gh workflow run deploy-all.yml --ref main -f environment=prod`,P.quiet=!0,await P`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`):(await P`gh pr merge ${a} --squash --admin --delete-branch`,await P`gh pr create --base main --head dev --title "Release v${l} (RC)" --body ""`,await P`gh pr merge dev --squash --admin`,P.quiet=!1,await P`gh workflow run deploy-all.yml --ref main -f environment=prod`,P.quiet=!0,await P`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`),P.quiet=!1;let d=await de();if(d)try{let f=a.replace("release/","");await Qe({versionName:f},d)}catch(f){i.error({error:f},"Failed to deliver Jira release (non-blocking)")}else i.info("\u{1F514} Jira is not configured, skipping Jira release delivery");i.info(`Successfully delivered ${a} to production!`),p.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){i.error({error:d},"\u274C Error merging release branch into dev"),tr.exit(1)}},or={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:ve.string().describe('Release version to deliver to production (e.g., "1.2.5"). Required for MCP calls.')},outputSchema:{releaseBranch:ve.string().describe("The release branch that was delivered"),version:ve.string().describe("The version that was delivered"),type:ve.enum(["regular","hotfix"]).describe("Release type"),success:ve.boolean().describe("Whether the delivery was successful")},handler:Gr};import Kr from"@inquirer/select";import zr from"node:process";import{z as L}from"zod/v4";import{$ as sr}from"zx";var Hr=async e=>{let{version:r,env:t,skipTerraform:s}=e;p.start("release-deploy-all");let o="";if(r)o=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let m=await y(),u=m.map(f=>f.branch),d=new Map(m.map(f=>[f.branch,w(f.title)])),h=await R();o=await Kr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...E({branches:u,descriptions:h,types:d})]})}let n=o==="dev"?"dev":o.replace("release/v","");p.addOption("--version",n);let{environments:a}=await v(),l="";t?l=t:(p.setInteractive(),l=await Kr({message:"\u{1F9EA} Select environment",choices:a.map(m=>({name:m,value:m}))})),p.addOption("--env",l),a.includes(l)||(i.error(`\u274C Invalid environment: ${l}. Exiting...`),zr.exit(1));let c=s??!1;c&&p.addOption("--skip-terraform",!0);try{sr.quiet=!0,await sr`gh workflow run deploy-all.yml --ref ${o} -f environment=${l} ${c?["-f","skip_terraform_deploy=true"]:[]}`,sr.quiet=!1,i.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${o} and environment: ${l}`),p.print();let u={releaseBranch:o,version:o.replace("release/v",""),environment:l,skipTerraformDeploy:c,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(m){i.error({error:m},"\u274C Error launching workflow"),zr.exit(1)}},nr={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:Hr};import lo from"@inquirer/checkbox";import Yr from"@inquirer/select";import po from"node:fs/promises";import{resolve as mo}from"node:path";import we from"node:process";import uo from"yaml";import{z as A}from"zod/v4";import{$ as ir}from"zx";var Xr=async e=>{let{version:r,env:t,services:s,skipTerraform:o}=e;p.start("release-deploy-selected");let n="";if(r)n=r==="dev"?"dev":`release/v${r}`;else{p.setInteractive();let f=await y(),k=f.map(B=>B.branch),$=new Map(f.map(B=>[B.branch,w(B.title)])),x=await R();n=await Yr({message:"\u{1F33F} Select release branch",choices:[{name:"dev",value:"dev"},...E({branches:k,descriptions:x,types:$})]})}let a=n==="dev"?"dev":n.replace("release/v","");p.addOption("--version",a);let{environments:l}=await v(),c="";t?c=t:(p.setInteractive(),c=await Yr({message:"\u{1F9EA} Select environment",choices:l.map(f=>({name:f,value:f}))})),p.addOption("--env",c),l.includes(c)||(i.error(`\u274C Invalid environment: ${c}. Exiting...`),we.exit(1));let m=await fo();m.length===0&&(i.error("\u274C No services found in workflow file. Exiting..."),we.exit(1));let u=[];s&&s.length>0?u=s:(p.setInteractive(),u=await lo({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:m.map(f=>({name:f,value:f}))})),p.addOption("--services",u),u.length===0&&(i.error("\u274C No services selected. Exiting..."),we.exit(1));let d=u.filter(f=>!m.includes(f));d.length>0&&(i.error(`\u274C Invalid services: ${d.join(", ")}. Available services: ${m.join(", ")}`),we.exit(1));let h=o??!1;h&&p.addOption("--skip-terraform",!0);try{ir.quiet=!0;let f=u.flatMap(x=>["-f",`${x}=true`]);await ir`gh workflow run deploy-selected-services.yml --ref ${n} -f environment=${c} ${f} ${h?["-f","skip_terraform_deploy=true"]:[]}`,ir.quiet=!1,i.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${n}, environment: ${c}, services: ${u.join(", ")}`),p.print();let $={releaseBranch:n,version:n.replace("release/v",""),environment:c,services:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify($,null,2)}],structuredContent:$}}catch(f){i.error({error:f},"\u274C Error launching workflow"),we.exit(1)}},fo=async()=>{let e=await T(),r=mo(e,".github/workflows/deploy-selected-services.yml"),t=await po.readFile(r,"utf-8"),o=uo.parse(t).on.workflow_dispatch.inputs,n=[];for(let[a,l]of Object.entries(o))l.type==="boolean"&&a!=="skip_terraform_deploy"&&n.push(a);return n},ar={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:A.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:A.string().describe('Target environment name \u2014 must match an env configured for the project (e.g. "dev", "renana", "oriana"). Required for MCP calls.'),services:A.array(A.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:A.boolean().optional().describe("Skip the terraform deployment stage.")},outputSchema:{releaseBranch:A.string().describe("The release branch that was deployed"),version:A.string().describe("The version that was deployed"),environment:A.string().describe("The environment deployed to"),services:A.array(A.string()).describe("The services that were deployed"),skipTerraformDeploy:A.boolean().describe("Whether terraform deployment was skipped"),success:A.boolean().describe("Whether the deployment was successful")},handler:Xr};import{z as oe}from"zod/v4";var Zr=async()=>{let r=(await y()).map(a=>({version:a.branch.replace("release/",""),type:w(a.title)})),t=await R(),s=Math.max(...r.map(a=>a.version.length)),o=r.map(a=>{let l=re(a.version,a.type,s),c=t.get(a.version);return c?`${l} ${c}`:l});i.info(`All release branches:
|
|
28
|
+
`),i.info(`
|
|
29
29
|
${o.join(`
|
|
30
30
|
`)}
|
|
31
|
-
`);let n={releases:r.map(
|
|
32
|
-
`)}catch(u){let d=u instanceof Error?u.message:String(u);n.push({version:m,error:d}),
|
|
33
|
-
`)}let
|
|
34
|
-
`)){let s=t.match(/^[* ]\s*(workspace:\d+)\s+(.+?)(?:\s+\[selected\])?\s*$/);if(!s)continue;let o=s[1];if((s[2]?.trim()??"")===r)return o}};import{$ as
|
|
35
|
-
`,"
|
|
36
|
-
`,"utf-8")
|
|
37
|
-
${i.
|
|
31
|
+
`);let n={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(n,null,2)}],structuredContent:n}},cr={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:oe.array(oe.object({version:oe.string().describe("Release version"),type:oe.enum(["regular","hotfix"]).describe("Release type"),description:oe.string().nullable().describe("Jira version description")})).describe("List of all release branches"),count:oe.number().describe("Number of release branches")},handler:Zr};import Qr from"@inquirer/confirm";import ho from"@inquirer/select";import et from"node:process";import{z as N}from"zod/v4";import{$ as lr,question as rt}from"zx";var tt=async e=>{let{version:r,description:t,type:s,confirmedCommand:o,checkout:n}=e;p.start("release-create");let a=r,l=t,c=s||"regular",m=n,u=await ee();a||(p.setInteractive(),a=await rt("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(i.error("No version provided. Exiting..."),et.exit(1));let d=a.trim();p.addOption("--version",d),s||(p.setInteractive(),c=await ho({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),p.addOption("--type",c),l===void 0&&(p.setInteractive(),l=await rt("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&p.addOption("--description",l);let h=o?!0:await Qr({message:`Are you sure you want to create release branch for version ${d}?`});o||p.setInteractive(),h||(i.info("Operation cancelled. Exiting..."),et.exit(0)),p.addOption("--yes",!0),await he(c);let f=await ge({version:d,jiraConfig:u,description:l,type:c});i.info(`\u2705 Successfully created release: v${d}`),i.info(`\u{1F517} GitHub PR: ${f.prUrl}`),i.info(`\u{1F517} Jira Version: ${f.jiraVersionUrl}`),m===void 0&&(p.setInteractive(),m=await Qr({message:`Do you want to checkout to the created branch ${f.branchName}?`,default:!0})),m||p.addOption("--no-checkout",!0),m&&(lr.quiet=!0,await lr`git switch ${f.branchName}`,lr.quiet=!1,i.info(`\u{1F504} Switched to branch ${f.branchName}`)),p.print();let k={version:d,type:c,branchName:f.branchName,prUrl:f.prUrl,jiraVersionUrl:f.jiraVersionUrl,isCheckedOut:m};return{content:[{type:"text",text:JSON.stringify(k,null,2)}],structuredContent:k}},pr={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:N.string().describe('Version to create (e.g., "1.2.5"). Required for MCP calls.'),description:N.string().optional().describe("Optional description for the Jira version"),type:N.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")'),checkout:N.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:N.string().describe("Version number"),type:N.enum(["regular","hotfix"]).describe("Release type"),branchName:N.string().describe("Release branch name"),prUrl:N.string().describe("GitHub PR URL"),jiraVersionUrl:N.string().describe("Jira version URL"),isCheckedOut:N.boolean().describe("Whether the branch was checked out")},handler:tt};import go from"@inquirer/confirm";import vo from"@inquirer/select";import ot from"node:process";import{z as b}from"zod/v4";import{question as wo}from"zx";var yo=async e=>{let{versions:r,type:t,confirmedCommand:s}=e,o=r,n=t||"regular";o||(p.setInteractive(),o=await wo("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let a=o.split(",").map(c=>c.trim()).filter(Boolean);p.addOption("--versions",a.join(", ")),a.length===0&&(i.error("No versions provided. Exiting..."),ot.exit(1)),t||(p.setInteractive(),n=await vo({message:"Select release type:",choices:[{name:"regular",value:"regular"},{name:"hotfix",value:"hotfix"}],default:"regular"})),p.addOption("--type",n),a.length===1&&i.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let l=s?!0:await go({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`});return s||p.setInteractive(),l||(i.info("Operation cancelled. Exiting..."),ot.exit(0)),p.addOption("--yes",!0),{versionsList:a,type:n}},st=async e=>{p.start("release-create-batch");let r=await ee(),{versionsList:t,type:s}=await yo(e);await he(s);let o=[],n=[];for(let m of t)try{let u=await ge({version:m,jiraConfig:r,type:s});o.push(u),i.info(`\u2705 Successfully created release: v${m}`),i.info(`\u{1F517} GitHub PR: ${u.prUrl}`),i.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}
|
|
32
|
+
`)}catch(u){let d=u instanceof Error?u.message:String(u);n.push({version:m,error:d}),i.error(`\u274C Failed to create release: v${m}`),i.error(` Error: ${d}
|
|
33
|
+
`)}let a=o.length,l=n.length;a===t.length?i.info(`\u2705 All ${t.length} release branches were created successfully.`):a>0?(i.warn(`\u26A0\uFE0F ${a} of ${t.length} release branches were created successfully.`),i.warn(`\u274C ${l} release(s) failed.`)):i.error(`\u274C All ${t.length} release branches failed to create.`),p.print();let c={createdBranches:o.map(m=>m.branchName),successCount:a,failureCount:l,releases:o,failedReleases:n};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},mr={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:b.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6"). Required for MCP calls.'),type:b.enum(["regular","hotfix"]).optional().default("regular").describe('Release type: "regular" or "hotfix" (default: "regular")')},outputSchema:{createdBranches:b.array(b.string()).describe("List of created release branches"),successCount:b.number().describe("Number of releases created successfully"),failureCount:b.number().describe("Number of releases that failed"),releases:b.array(b.object({version:b.string().describe("Version number"),type:b.enum(["regular","hotfix"]).describe("Release type"),branchName:b.string().describe("Release branch name"),prUrl:b.string().describe("GitHub PR URL"),jiraVersionUrl:b.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:b.array(b.object({version:b.string().describe("Version number that failed"),error:b.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:st};import{z as Ro}from"zod/v4";var nt={name:"infra-kit",type:"module",version:"0.1.97",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.4",zod:"^3.25.76",zx:"^8.8.5"},devDependencies:{"@pkg/eslint-config":"workspace:*","@pkg/vitest-config":"workspace:*",esbuild:"^0.28.0",typescript:"catalog:"}};var it=async()=>{let e=nt.version;i.info(e);let r={version:e};return{content:[{type:"text",text:JSON.stringify(r,null,2)}],structuredContent:r}},ur={name:"version",description:"Print the installed infra-kit CLI version",inputSchema:{},outputSchema:{version:Ro.string().describe("Installed infra-kit CLI version (from package.json)")},handler:it};import $o from"@inquirer/checkbox";import hr from"@inquirer/confirm";import Eo from"@inquirer/select";import So from"node:process";import{z as V}from"zod/v4";import{$ as U}from"zx";import{$ as at}from"zx";var ye=async e=>{try{let r=(await at`cmux list-workspaces`.quiet()).stdout,t=bo(r,e);if(!t)return;await at`cmux close-workspace --workspace ${t}`.quiet()}catch(r){i.debug({error:r,title:e},"cmux: skipped closing workspace")}},bo=(e,r)=>{for(let t of e.split(`
|
|
34
|
+
`)){let s=t.match(/^[* ]\s*(workspace:\d+)\s+(.+?)(?:\s+\[selected\])?\s*$/);if(!s)continue;let o=s[1];if((s[2]?.trim()??"")===r)return o}};import{$ as xo}from"zx";var dr=async()=>{try{let e=(await xo`cmux list-workspaces`.quiet()).stdout,r=new Set;for(let t of e.split(`
|
|
35
|
+
`)){let s=t.match(/^[* ]\s*workspace:\d+\s+(.+?)(?:\s+\[selected\])?\s*$/);if(!s)continue;let o=s[1]?.trim();o&&r.add(o)}return r}catch(e){return i.debug({error:e},"cmux: skipped listing workspace titles"),new Set}};import{$ as ke}from"zx";var Re=async e=>{let{cwd:r,title:t}=e,s=(await ke`cmux new-workspace --cwd ${r}`).stdout,o=To(s),n=(await ke`cmux list-pane-surfaces --workspace ${o}`).stdout,a=Co(n);await ke`cmux new-split right --workspace ${o} --surface ${a}`,await ke`cmux new-split down --workspace ${o} --surface ${a}`,t&&await ke`cmux rename-workspace --workspace ${o} ${t}`},Co=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]},To=e=>{let r=e.match(/workspace:\d+/);if(!r)throw new Error("cmux: could not locate workspace ref in new-workspace output");return r[0]};var D=e=>{let{repoName:r,branch:t}=e,s=t.replace("release/","");return`${r} ${s}`};import ct from"node:fs/promises";import _e from"node:path";var be=async e=>{let{workspacePath:r,folderPaths:t}=e,s=_e.dirname(r),o;try{o=await ct.readFile(r,"utf-8")}catch(u){throw new Error(`Cursor workspace file not found at ${r}: ${u.message}`)}let n;try{n=JSON.parse(o)}catch(u){throw new Error(`Failed to parse ${r} as JSON. Comments (JSONC) are not supported. ${u.message}`)}let a=n.folders??[],l=new Set(a.map(u=>_e.resolve(s,u.path))),c=[],m=[];for(let u of t){let d=_e.resolve(u);if(l.has(d)){m.push(u);continue}let h=_e.relative(s,d);a.push({path:h}),l.add(d),c.push(u)}return n.folders=a,await ct.writeFile(r,`${JSON.stringify(n,null,2)}
|
|
36
|
+
`,"utf-8"),{added:c,skipped:m}};import Po from"node:fs/promises";import Je from"node:path";import lt from"node:fs/promises";import je from"node:path";var q=async e=>{let{workspacePath:r,folderPaths:t}=e,s=je.dirname(r),o;try{o=await lt.readFile(r,"utf-8")}catch(h){throw new Error(`Cursor workspace file not found at ${r}: ${h.message}`)}let n;try{n=JSON.parse(o)}catch(h){throw new Error(`Failed to parse ${r} as JSON. Comments (JSONC) are not supported. ${h.message}`)}let a=n.folders??[],l=new Set(t.map(h=>je.resolve(h))),c=new Set,m=a.filter(h=>{let f=je.resolve(s,h.path);return l.has(f)?(c.add(f),!1):!0});n.folders=m,await lt.writeFile(r,`${JSON.stringify(n,null,2)}
|
|
37
|
+
`,"utf-8");let u=[],d=[];for(let h of t){let f=je.resolve(h);c.has(f)?u.push(h):d.push(h)}return{removed:u,notFound:d}};var fr=async e=>{let{workspacePath:r,worktreeDir:t,currentBranches:s}=e,o=Je.dirname(r),n=Je.resolve(`${t}/release`),a=await Po.readFile(r,"utf-8"),c=JSON.parse(a).folders??[],m=new Set(s.map(k=>Je.resolve(`${t}/${k}`))),u=[];for(let k of c){let $=Je.resolve(o,k.path);($===n||$.startsWith(`${n}/`))&&!m.has($)&&u.push($)}let d=[];u.length>0&&(d=(await q({workspacePath:r,folderPaths:u})).removed);let h=s.map(k=>`${t}/${k}`),{added:f}=h.length>0?await be({workspacePath:r,folderPaths:h}):{added:[]};return{added:f,removed:d}};import pt from"node:path";var _=(e,r)=>pt.isAbsolute(e)?e:pt.resolve(r,e);var Ao="feature",Io="release",Oo="release/v",ut=["workspace","windows","none"],dt=async e=>{let{confirmedCommand:r,all:t,versions:s,cursor:o,githubDesktop:n,cmux:a}=e;p.start("worktrees-add");try{let l=await I("release"),c=await T(),m=`${c}${J}`;await mt(`${m}/${Io}`),await mt(`${m}/${Ao}`);let u=[];if(s)u=s.split(",").map(C=>`release/v${C.trim()}`);else{let C=await y(),M=C.map(F=>F.branch);if(M.length===0)return i.info("\u2139\uFE0F No open release branches found"),p.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};if(t)u=M;else{p.setInteractive();let F=new Map(C.map(Ce=>[Ce.branch,w(Ce.title)])),Le=await R();u=await $o({required:!0,message:"\u{1F33F} Select release branches",choices:E({branches:M,descriptions:Le,types:F})})}}t?p.addOption("--all",!0):p.addOption("--versions",u.map(C=>C.replace("release/v","")));let d=r?!0:await hr({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),d||(i.info("Operation cancelled. Exiting..."),So.exit(0)),r||p.addOption("--yes",!0);let h=o??await Eo({message:"Cursor mode for created worktrees?",default:"workspace",choices:[{name:"Add to workspace file",value:"workspace",description:"Append each worktree as a folder in ide.config.workspaceConfigPath, then open the workspace"},{name:"Open separate windows",value:"windows",description:"Open each created worktree in its own Cursor window"},{name:"Skip",value:"none",description:"Do not open Cursor"}]});typeof o>"u"&&p.setInteractive(),p.addOption("--cursor",h);let f=n??await hr({message:"Open created worktrees in GitHub Desktop?"});typeof n>"u"&&p.setInteractive(),f?p.addOption("--github-desktop",!0):p.addOption("--no-github-desktop",!0);let k=a??await hr({message:"Open created worktrees in cmux?"});typeof a>"u"&&p.setInteractive(),k?p.addOption("--cmux",!0):p.addOption("--no-cmux",!0);let{branchesToCreate:$}=No({selectedReleaseBranches:u,currentWorktrees:l}),x=await Mo($,m);if(Fo(x),h==="workspace"){let C=await v(),M=C.ide?.provider==="cursor"?C.ide.config:void 0;if(!M?.workspaceConfigPath)i.warn("\u26A0\uFE0F Skipping Cursor: ide.config.workspaceConfigPath is not set in infra-kit.yml");else{let F=_(M.workspaceConfigPath,c),Le=x.map(bt=>`${m}/${bt}`),{added:Ce,skipped:Cr}=await be({workspacePath:F,folderPaths:Le}),Rt=Cr.length>0?` (${Cr.length} already present)`:"";i.info(`\u2705 Added ${Ce.length} folder(s) to ${F}${Rt}`),await U`cursor ${F}`}}else if(h==="windows")for(let C of x)await U`cursor ${m}/${C}`;if(f)for(let C of x)await U`github ${m}/${C}`,await U`sleep 5`;if(k){let C=await W();for(let M of x){let F=D({repoName:C,branch:M});await Re({cwd:`${m}/${M}`,title:F})}}p.print();let B={createdWorktrees:x,count:x.length};return{content:[{type:"text",text:JSON.stringify(B,null,2)}],structuredContent:B}}catch(l){throw i.error({error:l},"\u274C Error managing worktrees"),l}},mt=async e=>{await U`mkdir -p ${e}`},No=e=>{let{selectedReleaseBranches:r,currentWorktrees:t}=e,s=t.filter(n=>n.startsWith(Oo));return{branchesToCreate:r.filter(n=>!s.includes(n))}},Mo=async(e,r)=>{let t=await Promise.allSettled(e.map(async o=>{let n=`${r}/${o}`;return await U`git worktree add ${n} ${o}`,await U({cwd:n})`pnpm install`,o})),s=[];for(let[o,n]of t.entries())if(n.status==="fulfilled")s.push(n.value);else{let a=e[o];i.error({error:n.reason},`\u274C Failed to create worktree for ${a}`)}return s},Fo=e=>{if(e.length>0){i.info("\u2705 Created git worktrees:");for(let r of e)i.info(r);i.info("")}else i.info("\u2139\uFE0F No new git worktrees to create")},gr={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:V.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:V.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:V.enum(ut).optional().describe('Cursor open mode for created worktrees. "workspace" (default behavior when set interactively) appends each worktree as a folder to "ide.config.workspaceConfigPath" in infra-kit.yml and opens the workspace. "windows" opens each worktree in its own Cursor window. "none" skips Cursor. Defaults to "none" in MCP mode (the follow-up prompt is not shown).'),githubDesktop:V.boolean().optional().describe("Open each created worktree in GitHub Desktop. Defaults to false in MCP mode (the follow-up prompt is not shown)."),cmux:V.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:V.array(V.string()).describe("List of created git worktree branches"),count:V.number().describe("Number of git worktrees created")},handler:dt};import{z as se}from"zod/v4";var ft=async()=>{let e=await I("release");if(e.length===0)return i.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(),R()]),s=new Map(r.map(c=>[c.branch,w(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}}),n=Math.max(...o.map(c=>c.version.length)),a=o.map(c=>{let m=re(c.version,c.type,n);return c.description?`${m} ${c.description}`:m});i.info("\u{1F33F} Active worktrees:"),i.info(`
|
|
38
|
+
${a.join(`
|
|
38
39
|
`)}
|
|
39
|
-
`);let l={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},dr={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:oe.array(oe.object({version:oe.string().describe("Release version"),type:oe.enum(["regular","hotfix"]).describe("Release type"),description:oe.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:oe.number().describe("Number of worktrees")},handler:ct};import $o from"@inquirer/checkbox";import Eo from"@inquirer/confirm";import So from"node:process";import{z as Re}from"zod/v4";import{$ as fr}from"zx";var lt=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;p.start("worktrees-remove");try{let o=await M("release");if(o.length===0)return a.info("\u2139\uFE0F No active worktrees to remove"),p.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let n=await P(),i=`${n}${Y}`,l=[];if(t)l=o;else if(s)l=s.split(",").map(f=>`release/v${f.trim()}`);else{p.setInteractive();let[f,A]=await Promise.all([R(),w()]),_=new Map(A.map(x=>[x.branch,v(x.title)]));l=await $o({required:!0,message:"\u{1F33F} Select release branches",choices:T({branches:o,descriptions:f,types:_})})}l.length===o.length?p.addOption("--all",!0):p.addOption("--versions",l.map(f=>f.replace("release/v","")));let m=r?!0:await Eo({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),m||(a.info("Operation cancelled. Exiting..."),So.exit(0)),r||p.addOption("--yes",!0);let u=await F(),d=await Ao({branches:l,worktreeDir:i,repoName:u});await Io({removedWorktrees:d,worktreeDir:i,projectRoot:n}),No(d),p.print();let h={removedWorktrees:d,count:d.length};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(o){throw a.error({error:o},"\u274C Error managing worktrees"),o}},Ao=async e=>{let{branches:r,worktreeDir:t,repoName:s}=e,o=await Promise.allSettled(r.map(async i=>{let l=`${t}/${i}`,c=L({repoName:s,branch:i});return await ve(c),await fr`git worktree remove ${l}`,i})),n=[];for(let[i,l]of o.entries())if(l.status==="fulfilled")n.push(l.value);else{let c=r[i];a.error({error:l.reason},`\u274C Failed to remove worktree for ${c}`)}return n.length===r.length&&(await fr`git worktree prune`,await fr`rm -rf ${t}`,a.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${t}`),a.info("")),n},Io=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await y(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let i=V(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await ye({workspacePath:i,folderPaths:l});c.length>0&&a.info(`\u2705 Removed ${c.length} folder(s) from ${i}`)}catch(c){a.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${i}`)}},No=e=>{if(e.length>0){a.info("\u274C Removed worktrees:");for(let r of e)a.info(r);a.info("")}else a.info("\u2139\uFE0F No unused worktrees to remove")},hr={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:Re.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:Re.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:Re.array(Re.string()).describe("List of removed git worktree branches"),count:Re.number().describe("Number of git worktrees removed")},handler:lt};import Oo from"@inquirer/confirm";import Mo from"node:process";import{z as gr}from"zod/v4";import{$ as _o}from"zx";var Do="release/v",pt=async e=>{let{confirmedCommand:r}=e;p.start("worktrees-sync");try{let t=await M("release"),s=await P(),o=`${s}${Y}`,n=await Me(),i=r?!0:await Oo({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),i||(a.info("Operation cancelled. Exiting..."),Mo.exit(0)),r||p.addOption("--yes",!0);let{branchesToRemove:l}=Jo({releasePRsList:n,currentWorktrees:t}),c=await F(),m=await jo({branches:l,worktreeDir:o,repoName:c});await Wo({removedWorktrees:m,worktreeDir:o,projectRoot:s}),Fo(m),p.print();let u={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(t){throw a.error({error:t},"\u274C Error managing worktrees"),t}},Jo=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(n=>n.startsWith(Do)).filter(n=>!r.includes(n))}},jo=async e=>{let{branches:r,worktreeDir:t,repoName:s}=e,o=[];for(let n of r)try{let i=`${t}/${n}`,l=L({repoName:s,branch:n});await ve(l),await _o`git worktree remove ${i}`,o.push(n)}catch(i){a.error({error:i,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Wo=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await y(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let i=V(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await ye({workspacePath:i,folderPaths:l});c.length>0&&a.info(`\u2705 Removed ${c.length} folder(s) from ${i}`)}catch(c){a.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${i}`)}},Fo=e=>{if(e.length>0){a.info("\u274C Removed worktrees:");for(let r of e)a.info(r);a.info("")}else a.info("\u2139\uFE0F No unused worktrees to remove")},vr={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:gr.array(gr.string()).describe("List of removed worktree branches"),count:gr.number().describe("Number of worktrees removed during sync")},handler:pt};var wr=e=>async r=>{let{toolName:t,handler:s}=e;a.info({msg:`Tool execution started: ${t}`,params:r});try{let o=await s({...r,confirmedCommand:!0});return a.info({msg:`Tool execution successful: ${t}`}),o}catch(o){throw a.error({err:o,params:r,msg:`Tool execution failed: ${t}`}),o}};var Lo=[Ke,qe,Ge,Ve,Xe,ir,ar,Qe,rr,or,sr,cr,ur,dr,hr,vr],mt=async e=>{for(let r of Lo)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},wr({toolName:r.name,handler:r.handler}))};async function ut(){let e=new Vo({name:"infra-kit",version:"1.0.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await xr(e),await Cr(e),await mt(e),e}var q=br(),qo=async()=>{let e;try{e=await ut(),q.info("MCP Server instance created")}catch(r){q.error({err:r,msg:"Failed to create MCP server"}),q.error("Fatal error during server creation."),dt.exit(1)}try{let r=new Bo;await e.connect(r),q.info({msg:"Server connected to transport. Ready."})}catch(r){q.error({err:r,msg:"Failed to initialize server"}),q.error("Fatal error during server transport init."),dt.exit(1)}};kr(q);qo();
|
|
40
|
+
`);let l={worktrees:o,count:o.length};return{content:[{type:"text",text:JSON.stringify(l,null,2)}],structuredContent:l}},vr={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:se.array(se.object({version:se.string().describe("Release version"),type:se.enum(["regular","hotfix"]).describe("Release type"),description:se.string().nullable().describe("Jira version description")})).describe("List of all worktrees with details"),count:se.number().describe("Number of worktrees")},handler:ft};import{z as ne}from"zod/v4";import{$ as Wo}from"zx";var ht=async()=>{p.start("worktrees-open");try{let e=await T(),r=`${e}${J}`,t=await I("release"),s=await Do({projectRoot:e,worktreeDir:r,currentBranches:t}),o=await _o({worktreeDir:r,currentBranches:t}),n={openedCmux:o.opened,skippedCmux:o.skipped,cursorFoldersAdded:s.added,cursorFoldersRemoved:s.removed};return jo(n,{cursorRan:s.ran,cmuxRan:o.ran}),p.print(),{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:{...n}}}catch(e){throw i.error({error:e},"\u274C Error opening worktrees"),e}},Do=async e=>{let{projectRoot:r,worktreeDir:t,currentBranches:s}=e,o=await v(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return i.warn('\u26A0\uFE0F Skipping Cursor: ide.provider must be "cursor", mode "workspace", and workspaceConfigPath set.'),{ran:!1,added:0,removed:0};let a=_(n.workspaceConfigPath,r);try{let{added:l,removed:c}=await fr({workspacePath:a,worktreeDir:t,currentBranches:s});return await Wo`cursor ${a}`,{ran:!0,added:l.length,removed:c.length}}catch(l){return i.warn({error:l},`\u26A0\uFE0F Failed to reconcile/open Cursor workspace at ${a}`),{ran:!1,added:0,removed:0}}},_o=async e=>{let{worktreeDir:r,currentBranches:t}=e;if(t.length===0)return{ran:!0,opened:[],skipped:[]};let s=await W(),o=await dr(),n=[],a=[];for(let l of t){let c=D({repoName:s,branch:l});if(o.has(c)){a.push(c);continue}try{await Re({cwd:`${r}/${l}`,title:c}),n.push(c)}catch(m){i.warn({error:m,title:c},`\u26A0\uFE0F Failed to open cmux workspace for ${l}`)}}return{ran:!0,opened:n,skipped:a}},jo=(e,r)=>{if(r.cursorRan&&(e.cursorFoldersAdded>0&&i.info(`\u2705 Added ${e.cursorFoldersAdded} folder(s) to Cursor workspace`),e.cursorFoldersRemoved>0&&i.info(`\u{1F9F9} Removed ${e.cursorFoldersRemoved} dangling folder(s) from Cursor workspace`)),e.openedCmux.length>0){i.info("\u2705 Opened cmux workspaces:");for(let t of e.openedCmux)i.info(t)}e.skippedCmux.length>0&&i.info(`\u2139\uFE0F Skipped ${e.skippedCmux.length} cmux workspace(s) already open`),!r.cursorRan&&e.openedCmux.length===0&&e.skippedCmux.length===0&&e.cursorFoldersAdded===0&&e.cursorFoldersRemoved===0&&i.info("\u2139\uFE0F Nothing to open")},wr={name:"worktrees-open",description:"Open Cursor against the configured workspace file and ensure a cmux workspace exists for each existing release worktree. Idempotent and additive \u2014 never removes worktrees, never recreates running cmux workspaces. Use after a cold start (Cursor + cmux closed). For stale-worktree cleanup, use worktrees-sync.",inputSchema:{},outputSchema:{openedCmux:ne.array(ne.string()).describe("Titles of cmux workspaces opened during this run"),skippedCmux:ne.array(ne.string()).describe("Titles of cmux workspaces that were already open"),cursorFoldersAdded:ne.number().describe("Number of worktree folders added to the Cursor workspace file"),cursorFoldersRemoved:ne.number().describe("Number of dangling worktree folders removed from the Cursor workspace file")},handler:ht};import Jo from"@inquirer/checkbox";import Lo from"@inquirer/confirm";import Vo from"node:process";import{z as xe}from"zod/v4";import{$ as yr}from"zx";var gt=async e=>{let{confirmedCommand:r,all:t,versions:s}=e;p.start("worktrees-remove");try{let o=await I("release");if(o.length===0)return i.info("\u2139\uFE0F No active worktrees to remove"),p.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let n=await T(),a=`${n}${J}`,l=[];if(t)l=o;else if(s)l=s.split(",").map(f=>`release/v${f.trim()}`);else{p.setInteractive();let[f,k]=await Promise.all([R(),y()]),$=new Map(k.map(x=>[x.branch,w(x.title)]));l=await Jo({required:!0,message:"\u{1F33F} Select release branches",choices:E({branches:o,descriptions:f,types:$})})}let c=l.length===o.length;c?p.addOption("--all",!0):p.addOption("--versions",l.map(f=>f.replace("release/v","")));let m=r?!0:await Lo({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),m||(i.info("Operation cancelled. Exiting..."),Vo.exit(0)),r||p.addOption("--yes",!0);let u=await W(),d=await Bo({branches:l,worktreeDir:a,repoName:u,allSelected:c});await qo({removedWorktrees:d,worktreeDir:a,projectRoot:n}),Uo(d),p.print();let h={removedWorktrees:d,count:d.length};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}}catch(o){throw i.error({error:o},"\u274C Error managing worktrees"),o}},Bo=async e=>{let{branches:r,worktreeDir:t,repoName:s,allSelected:o}=e,n=await Promise.allSettled(r.map(async l=>{let c=`${t}/${l}`,m=D({repoName:s,branch:l});return await ye(m),await yr`git worktree remove ${c}`,l})),a=[];for(let[l,c]of n.entries())if(c.status==="fulfilled")a.push(c.value);else{let m=r[l];i.error({error:c.reason},`\u274C Failed to remove worktree for ${m}`)}return o&&a.length===r.length&&(await yr`git worktree prune`,await yr`rm -rf ${t}`,i.info(`\u{1F5D1}\uFE0F Removed worktree folder: ${t}`),i.info("")),a},qo=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await v(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let a=_(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await q({workspacePath:a,folderPaths:l});c.length>0&&i.info(`\u2705 Removed ${c.length} folder(s) from ${a}`)}catch(c){i.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${a}`)}},Uo=e=>{if(e.length>0){i.info("\u274C Removed worktrees:");for(let r of e)i.info(r);i.info("")}else i.info("\u2139\uFE0F No unused worktrees to remove")},kr={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:xe.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:xe.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:xe.array(xe.string()).describe("List of removed git worktree branches"),count:xe.number().describe("Number of git worktrees removed")},handler:gt};import Go from"@inquirer/confirm";import Ko from"node:process";import{z as Rr}from"zod/v4";import{$ as zo}from"zx";var Ho="release/v",vt=async e=>{let{confirmedCommand:r}=e;p.start("worktrees-sync");try{let t=await I("release"),s=await T(),o=`${s}${J}`,n=await De(),a=r?!0:await Go({message:"Are you sure you want to proceed with these worktree changes?"});r||p.setInteractive(),a||(i.info("Operation cancelled. Exiting..."),Ko.exit(0)),r||p.addOption("--yes",!0);let{branchesToRemove:l}=Yo({releasePRsList:n,currentWorktrees:t}),c=await W(),m=await Xo({branches:l,worktreeDir:o,repoName:c});await Zo({removedWorktrees:m,worktreeDir:o,projectRoot:s}),Qo(m),p.print();let u={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(t){throw i.error({error:t},"\u274C Error managing worktrees"),t}},Yo=e=>{let{releasePRsList:r,currentWorktrees:t}=e;return{branchesToRemove:t.filter(n=>n.startsWith(Ho)).filter(n=>!r.includes(n))}},Xo=async e=>{let{branches:r,worktreeDir:t,repoName:s}=e,o=[];for(let n of r)try{let a=`${t}/${n}`,l=D({repoName:s,branch:n});await ye(l),await zo`git worktree remove ${a}`,o.push(n)}catch(a){i.error({error:a,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Zo=async e=>{let{removedWorktrees:r,worktreeDir:t,projectRoot:s}=e;if(r.length===0)return;let o=await v(),n=o.ide?.provider==="cursor"?o.ide.config:void 0;if(!n||n.mode!=="workspace"||!n.workspaceConfigPath)return;let a=_(n.workspaceConfigPath,s),l=r.map(c=>`${t}/${c}`);try{let{removed:c}=await q({workspacePath:a,folderPaths:l});c.length>0&&i.info(`\u2705 Removed ${c.length} folder(s) from ${a}`)}catch(c){i.warn({error:c},`\u26A0\uFE0F Failed to update Cursor workspace at ${a}`)}},Qo=e=>{if(e.length>0){i.info("\u274C Removed worktrees:");for(let r of e)i.info(r);i.info("")}else i.info("\u2139\uFE0F No unused worktrees to remove")},br={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:Rr.array(Rr.string()).describe("List of removed worktree branches"),count:Rr.number().describe("Number of worktrees removed during sync")},handler:vt};var xr=e=>async r=>{let{toolName:t,handler:s}=e;i.info({msg:`Tool execution started: ${t}`,params:r});try{let o=await s({...r,confirmedCommand:!0});return i.info({msg:`Tool execution successful: ${t}`}),o}catch(o){throw i.error({err:o,params:r,msg:`Tool execution failed: ${t}`}),o}};var es=[Xe,ze,Ye,Ge,rr,pr,mr,or,nr,ar,cr,ur,gr,vr,wr,kr,br],wt=async e=>{for(let r of es)e.registerTool(r.name,{description:r.description,inputSchema:r.inputSchema,outputSchema:r.outputSchema},xr({toolName:r.name,handler:r.handler}))};async function yt(){let e=new rs({name:"infra-kit",version:"1.0.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Er(e),await Sr(e),await wt(e),e}var G=Pr(),os=async()=>{let e;try{e=await yt(),G.info("MCP Server instance created")}catch(r){G.error({err:r,msg:"Failed to create MCP server"}),G.error("Fatal error during server creation."),kt.exit(1)}try{let r=new ts;await e.connect(r),G.info({msg:"Server connected to transport. Ready."})}catch(r){G.error({err:r,msg:"Failed to initialize server"}),G.error("Fatal error during server transport init."),kt.exit(1)}};$r(G);os();
|
|
40
41
|
//# sourceMappingURL=mcp.js.map
|