@maind-dev/mcp-bridge 0.116.2 → 0.116.3

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/build/index.js CHANGED
@@ -148,7 +148,7 @@ ${o}`};return JSON.stringify({jsonrpc:"2.0",id:e,result:i})}function OU(e,t){ret
148
148
  `),null}async function oB(e,t){let n=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_code:t})});if(!n.ok){let r=await n.text();throw new Error(`poll ${n.status}: ${r}`)}return await n.json()}function iB(e){return new Promise(t=>setTimeout(t,e))}function sB(e,t){let n=[""," \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"," \u2502 \u2502"," \u2502 maind-mcp-bridge \u2014 first-time setup \u2502"," \u2502 \u2502"," \u2502 Approve this bridge to bind it to your maind account: \u2502"," \u2502 \u2502",` \u2502 Open: ${nT(e.verification_uri,56)} \u2502`,` \u2502 Code: ${nT(e.user_code,56)} \u2502`," \u2502 \u2502",` \u2502 (expires in ${Math.round(e.expires_in/60)} minutes)`.padEnd(67)+"\u2502"," \u2502 \u2502"," \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518",""];t.write(n.join(`
149
149
  `)+`
150
150
  `)}function nT(e,t){return e.length>=t?e.slice(0,t):e+" ".repeat(t-e.length)}async function aB(e){let t,n;switch(rB()){case"darwin":t="open",n=[e];break;case"win32":t="cmd",n=["/c","start","",e];break;default:t="xdg-open",n=[e];break}return new Promise((r,o)=>{try{let i=nB(t,n,{stdio:"ignore",detached:!0});i.on("error",o),i.unref(),r()}catch(i){o(i)}})}var uh=w(()=>{"use strict";ye();oi();s(ii,"runDeviceFlow");s(oB,"pollOnce");s(iB,"sleep");s(sB,"printAuthInstructions");s(nT,"pad");s(aB,"openExternalBrowser")});import{mkdirSync as lB,readFileSync as cB,renameSync as uB,writeFileSync as dB}from"node:fs";import{join as pB}from"node:path";function rT(e=Ot()){return pB(e,mB)}function gB(e){return e.replace(/mnd_[a-f0-9]{8}_[a-f0-9]{56}/gi,"mnd_\u2026").slice(0,hB)}function Xr(e,t,n){try{let r=n.dir??Ot();lB(r,{recursive:!0,mode:448});let o={v:1,at:(n.now??new Date).toISOString(),outcome:e,detail:t===null?null:gB(t),bridge_version:n.version},i=rT(r),a=`${i}.${process.pid}.tmp`;dB(a,JSON.stringify(o)+`
151
- `,{encoding:"utf8",mode:384}),uB(a,i)}catch{}}function oT(e=Ot()){try{let t=JSON.parse(cB(rT(e),"utf8"));return t.v!==1||typeof t.at!="string"||!fB.includes(t.outcome)?null:{v:1,at:t.at,outcome:t.outcome,detail:typeof t.detail=="string"?t.detail:null,bridge_version:typeof t.bridge_version=="string"?t.bridge_version:"?"}}catch{return null}}var fB,mB,hB,dh=w(()=>{"use strict";ye();fB=["ok","paired","auth_failed","not_paired"],mB="connection-state.json",hB=200;s(rT,"connectionStatePath");s(gB,"redactDetail");s(Xr,"writeConnectionState");s(oT,"readConnectionState")});var G,We=w(()=>{"use strict";G="0.116.2"});import{execFileSync as iT}from"node:child_process";import{createHash as yB}from"node:crypto";function ph(e){return yB("sha256").update(e).digest("hex")}function fh(e){let t=e.trim();if(!t)return null;let n=/^[a-z][a-z0-9+.-]*:\/\//i.exec(t);if(n)t=t.slice(n[0].length),t=t.replace(/^[^@/]+@/,""),t=t.replace(/^([^/:]+):\d+(?=\/)/,"$1");else{t=t.replace(/^[^@/]+@/,"");let r=t.indexOf(":");r>=0&&(t=`${t.slice(0,r)}/${t.slice(r+1)}`)}return t=t.replace(/\.git$/i,"").replace(/\/+$/,"").toLowerCase(),t.length>0?t:null}function qn(e){let t=fh(e);return t?ph(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&_B.test(e))return e;let t;try{t=iT("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?qn(t):null}function Qe(e){let t;try{t=iT("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?qn(t):null}var _B,he=w(()=>{"use strict";s(ph,"sha256Hex");s(fh,"normalizeRemoteUrl");s(qn,"projectKeyFromRemote");_B=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(Qe,"projectKeyForRepo")});import bB from"node:path";import{fileURLToPath as kB}from"node:url";function wB(e,t=bB.sep){return e.split(t).includes("_npx")}function we(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",aT,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):wB(e.entryPath,e.sep)?n("bridge is running from the npx cache (install it globally to pin a path)"):e.nodePath?{command:e.nodePath,args:[e.entryPath,...t],env:e.isElectron?{ELECTRON_RUN_AS_NODE:"1"}:{},fallbackReason:null}:n("node executable path unavailable")}function ie(){try{let e=kB(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function et(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${sT(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:sT(n)).join(" ")}function _t(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(aT)}function Tc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function sT(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var aT,lt=w(()=>{"use strict";aT="@maind-dev/mcp-bridge";s(wB,"isEphemeralEntry");s(we,"resolveBridgeLaunch");s(ie,"currentBridgeEntry");s(et,"launchToShellCommand");s(_t,"isNpxForm");s(Tc,"isLegacyHookForm");s(sT,"shellQuote")});import{readFileSync as vB}from"node:fs";import*as F from"node:path";function uT(e){let t=e.launch??we({entryPath:ie(),nodePath:process.execPath,isElectron:process.versions.electron!==void 0});return{command:t.command,args:t.args,env:{...t.env,MAIND_CLIENT_FAMILY:e.clientFamily,MAIND_MCP_URL:e.mcpUrl}}}function pT(e){return Ic(e,"Claude")}function SB(e){return F.join(pT(e),dT)}function Ic(e,t){switch(e.platform){case"darwin":return F.join(e.homeDir,"Library","Application Support",t);case"win32":{let n=e.appData??F.join(e.homeDir,"AppData","Roaming");return F.join(n,t)}default:{let n=e.xdgConfigHome??F.join(e.homeDir,".config");return F.join(n,t)}}}function EB(e){return F.join(Ic(e,"Code"),"User")}function Ac(e,t,n=[]){return{kind:"foreign-entries",dir:Ic(e,t),ours:["User",...n]}}function lT(e){return e.localAppData??F.join(e.homeDir,"AppData","Local")}function CB(e){let t=[{kind:"foreign-entries",dir:pT(e),ours:[dT]}];return e.platform==="darwin"?t.push({kind:"dir",path:F.join("/Applications","Claude.app")},{kind:"dir",path:F.join(e.homeDir,"Applications","Claude.app")}):e.platform==="win32"&&t.push({kind:"dir",path:F.join(lT(e),"AnthropicClaude")},{kind:"dir",path:F.join(lT(e),"Packages",TB)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function wn(e){return{evidence:[Ac(e,"Cursor"),{kind:"foreign-entries",dir:F.join(e.homeDir,".cursor"),ours:["mcp.json","hooks.json"]}],skipDetail:"Cursor not found (no Cursor app data, nothing of Cursor's in ~/.cursor)"}}function fT(e){if(e.platform==="win32"){let t=e.appData??F.join(e.homeDir,"AppData","Roaming");return F.join(t,"devin")}return F.join(e.xdgConfigHome??F.join(e.homeDir,".config"),"devin")}function AB(e){return F.join(fT(e),"mcp_config.json")}function mT(e){return F.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function Rc(e){let t=[Ac(e,"Devin",["mcp_config.json"]),{kind:"dir",path:F.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:fT(e),ours:["mcp_config.json"]}),t.push(Ac(e,"Windsurf"),{kind:"foreign-entries",dir:F.dirname(mT(e)),ours:["mcp_config.json"]}),{evidence:t,skipDetail:"Devin Desktop (formerly Windsurf) not found (no Devin or Windsurf app data, nothing of theirs in ~/.devin, Devin's config dir or ~/.codeium/windsurf)"}}function DB(e){return e===null?null:OB.exec(e)?.[1]??null}function gT(e,t){let n=hT.map(r=>F.join(e.homeDir,r.dataFolder,"extensions"));if(e.bundleAppRoot&&n.push(F.join(e.bundleAppRoot,"extensions")),e.platform==="darwin")for(let r of NB)for(let o of["/Applications",F.join(e.homeDir,"Applications")])n.push(F.join(o,`${r}.app`,"Contents","Resources","app","extensions"));return[...new Set(n)].map(r=>({kind:"extension",dir:r,id:t}))}function yT(e){return e.clineDataDir?e.clineDataDir:F.join(e.clineDir??F.join(e.homeDir,".cline"),"data")}function PB(e){return e.clineMcpSettingsPath??F.join(yT(e),"settings","cline_mcp_settings.json")}function mh(e){return{evidence:[{kind:"foreign-entries",dir:yT(e),ours:["settings"]},...RB.map(t=>({kind:"dir",path:F.join(Ic(e,t),"User","globalStorage",cT)})),...gT(e,cT)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function Nc(e){return e.continueGlobalDir??F.join(e.homeDir,".continue")}function MB(e){return F.join(Nc(e),"mcpServers","maind.json")}function hh(e){return{evidence:[{kind:"foreign-entries",dir:Nc(e),ours:["mcpServers","rules"]},...gT(e,IB)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function zn(e){return e.codexHome??F.join(e.homeDir,".codex")}function Zr(e){return F.join(zn(e),"config.toml")}function ai(e){let t=zn(e),n=F.join(e.homeDir,".codex"),r=[{kind:"foreign-entries",dir:t,ours:["config.toml"]}];return t!==n&&r.push({kind:"foreign-entries",dir:n,ours:["config.toml"]}),{evidence:r,skipDetail:t===n?"Codex not found (nothing of Codex's in ~/.codex)":"Codex not found (nothing of Codex's in $CODEX_HOME or ~/.codex)"}}function _T(e){return F.join(e.geminiCliHome??e.homeDir,".gemini")}function li(e){return F.join(_T(e),"settings.json")}function ci(e){let t=_T(e),n=F.join(e.homeDir,".gemini"),r=[{kind:"foreign-entries",dir:t,ours:["settings.json"]}];return t!==n&&r.push({kind:"foreign-entries",dir:n,ours:["settings.json"]}),{evidence:r,skipDetail:t===n?"Gemini CLI not found (nothing of Gemini's in ~/.gemini)":"Gemini CLI not found (nothing of Gemini's in $GEMINI_CLI_HOME/.gemini or ~/.gemini)"}}function qs(e){return{evidence:[Ac(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function $B(e){return F.join(EB(e),"mcp.json")}function zs(e){return[{key:"claude-code-project",label:"Claude Code (project-scoped .mcp.json)",clientFamilyEnv:"claude-code",scope:"project",path:F.join(e.projectRoot,".mcp.json"),kind:"json"},{key:"claude-code-user",label:"Claude Code (user-scoped ~/.claude.json)",clientFamilyEnv:"claude-code",scope:"user",path:F.join(e.homeDir,".claude.json"),kind:"json"},{key:"claude-desktop",label:"Claude Desktop",clientFamilyEnv:"claude-desktop",scope:"user",path:SB(e),kind:"json",presence:CB(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:F.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:wn(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:AB(e),kind:"json",presence:Rc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:mT(e),kind:"json",presence:Rc(e),refreshOnly:{skipDetail:"no maind entry here to keep current \u2014 Devin Desktop's own file is the windsurf row"}},{key:"vscode-copilot",label:"GitHub Copilot (VS Code user mcp.json)",clientFamilyEnv:"copilot",scope:"user",path:$B(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:qs(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:PB(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:mh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:MB(e),kind:"json",presence:hh(e)},{key:"gemini-cli",label:"Gemini CLI (~/.gemini/settings.json)",clientFamilyEnv:"gemini-cli",scope:"user",path:li(e),kind:"json",presence:ci(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:Zr(e),kind:"toml",presence:ai(e)}]}function bT(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function kT(e){return e.jsonShape??xB}function wT(e){let{homeDir:t,platform:n,env:r}=e,o=F.join(t,"Documents");if(n==="win32"){let c=["OneDrive","OneDriveConsumer","OneDriveCommercial"].map(u=>r[u]?.trim()).filter(u=>typeof u=="string"&&u.length>0&&F.win32.isAbsolute(u)).map(u=>F.join(u,"Documents"));return[...new Set([o,...c])]}if(n==="darwin")return[o];let i=r.XDG_CONFIG_HOME?.trim()||F.join(t,".config"),a=e.readText?.(F.join(i,"user-dirs.dirs"))??null,l=a===null?null:vT(a,t);return l!==null&&l!==o?[l,o]:[o]}function vT(e,t){for(let n of e.split(/\r?\n/)){let r=/^\s*XDG_DOCUMENTS_DIR\s*=\s*"?([^"]*)"?\s*$/.exec(n);if(!r)continue;let o=r[1].replace(/^\$HOME(?=\/|$)/,t).replace(/^\$\{HOME\}(?=\/|$)/,t);return F.isAbsolute(o)&&o.length>1?F.normalize(o):null}return null}function vn(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:Cc(e.env.XDG_CONFIG_HOME),appData:Cc(e.env.APPDATA),localAppData:Cc(e.env.LOCALAPPDATA),clineDir:si(e.env.CLINE_DIR),clineDataDir:si(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:si(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:si(e.env.CONTINUE_GLOBAL_DIR),codexHome:si(e.env.CODEX_HOME),geminiCliHome:si(e.env.GEMINI_CLI_HOME),bundleAppRoot:DB(e.bridgeEntry??null),documentsDirs:wT({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return vB(t,"utf8")}catch{return null}},"readText")})}}function Cc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function si(e){let t=Cc(e);return t!==null&&F.isAbsolute(t)?t:null}var xB,dT,TB,hT,RB,cT,IB,NB,OB,gh,Ke=w(()=>{"use strict";lt();xB={serversKey:"mcpServers"};s(uT,"buildMaindServerEntry");dT="claude_desktop_config.json";s(pT,"claudeDesktopAppDataDir");s(SB,"claudeDesktopConfigPath");s(Ic,"editorAppDataDir");s(EB,"vsCodeUserDir");s(Ac,"editorRan");s(lT,"localAppDataDir");TB="Claude_pzs8sxrjxfjjc";s(CB,"claudeDesktopPresence");s(wn,"cursorPresence");s(fT,"devinConfigDir");s(AB,"devinMcpConfigPath");s(mT,"windsurfLegacyMcpConfigPath");s(Rc,"devinDesktopPresence");hT=[{appData:"Code",dataFolder:".vscode"},{appData:"Code - Insiders",dataFolder:".vscode-insiders"},{appData:"Cursor",dataFolder:".cursor"},{appData:"VSCodium",dataFolder:".vscode-oss"},{appData:"Windsurf",dataFolder:".windsurf"},{appData:"Devin",dataFolder:".devin"},{appData:"AgentComposer",dataFolder:".agentcomposer"}],RB=hT.map(e=>e.appData),cT="saoudrizwan.claude-dev",IB="continue.continue",NB=["AgentComposer"],OB=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(DB,"bundleAppRootOf");s(gT,"agentExtensionEvidence");s(yT,"clineDataDir");s(PB,"clineMcpSettingsPath");s(mh,"clinePresence");s(Nc,"continueGlobalDir");s(MB,"continueMcpConfigPath");s(hh,"continuePresence");s(zn,"codexHomeDir");s(Zr,"codexConfigPath");s(ai,"codexPresence");s(_T,"geminiDir");s(li,"geminiSettingsPath");s(ci,"geminiPresence");s(qs,"vsCodePresence");s($B,"vsCodeUserMcpPath");s(zs,"getClientTargets");s(bT,"filterTargetsByFamily");s(kT,"jsonShapeOf");gh=[...new Set(zs({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(wT,"documentsDirCandidates");s(vT,"parseXdgDocumentsDir");s(vn,"makeDefaultContext");s(Cc,"nonEmpty");s(si,"absoluteOrNull")});function yh(){return gh.map(e=>{let t=Object.keys(Oc).filter(n=>Oc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function xT(e){let t={projectRoot:null,full:!1,team:!1,noRules:!1,noPreamble:!1,noHook:!1,nonInteractive:!1,token:null,oneClickToken:null,oneClickExchangeUrl:null,telemetry:!1,client:null,skipCodex:!1,dryRun:!1,autoWorkingPaths:!1,agentActivity:!1,hooksOnly:!1,help:!1,notices:[]};for(let n=0;n<e.length;n++){let r=e[n];switch(r){case"-h":case"--help":t.help=!0;break;case"--full":t.full=!0;break;case"--team":t.team=!0;break;case"--no-rules":t.noRules=!0;break;case"--no-preamble":t.noPreamble||t.notices.push(LB),t.noPreamble=!0;break;case"--no-hook":t.noHook=!0;break;case"--non-interactive":t.nonInteractive=!0;break;case"--telemetry":t.telemetry=!0;break;case"--skip-codex":t.skipCodex=!0;break;case"--dry-run":t.dryRun=!0;break;case"--auto-working-paths":t.autoWorkingPaths=!0;break;case"--agent-activity":t.agentActivity=!0;break;case"--hooks-only":t.hooksOnly=!0;break;case"--project-root":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--project-root requires a path argument");t.projectRoot=o,n++;break}case"--token":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--token requires a token argument");t.token=o,n++;break}case"--one-click-token":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--one-click-token requires a token argument");t.oneClickToken=o,n++;break}case"--one-click-exchange-url":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--one-click-exchange-url requires a URL argument");t.oneClickExchangeUrl=o,n++;break}case"--client":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt(`--client requires a family argument (${yh()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(Oc,i)?Oc[i]:i;if(!gh.includes(a))throw new bt(`--client "${o}" is not a known client family. Known: ${yh()}`);t.client=a,n++;break}default:throw new bt(`Unknown flag: ${r} \u2014 run \`install --help\` for supported flags`)}}if(t.full&&(t.nonInteractive=!0),t.hooksOnly){let n=[t.noHook&&"--no-hook",t.projectRoot!==null&&"--project-root",t.team&&"--team",t.token!==null&&"--token",t.oneClickToken!==null&&"--one-click-token",t.oneClickExchangeUrl!==null&&"--one-click-exchange-url",t.client!==null&&"--client",t.skipCodex&&"--skip-codex",t.telemetry&&"--telemetry",t.autoWorkingPaths&&"--auto-working-paths",t.agentActivity&&"--agent-activity"].filter(r=>typeof r=="string");if(n.length>0)throw new bt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function ST(){process.stdout.write(jB())}function jB(){return["","@maind-dev/mcp-bridge install \u2014 one-shot setup for the MAIND MCP server.","","Pairs this device with MAIND and merges the MCP-server entry into every","supported AI-client config it finds (user level). Then it sets up the","channels that bring the MAIND hint and your project conventions into each","session \u2014 each with its own consent, only for clients that are installed:","hooks for Claude Code (~/.claude/settings.json), Cursor (~/.cursor/hooks.json)","and Codex (config.toml), user-level rule files for GitHub Copilot, Cline and","Continue. It writes nothing into your repository unless you pass --team.","Idempotent \u2014 re-running is safe.","","Usage:"," npx -y @maind-dev/mcp-bridge install [flags]","","Common flags:"," --project-root <path> Override project-root detection (default: walk up from cwd)"," --full Non-interactive full setup (consents to the hooks and rule files)"," --team Also write into the repository, deliberately: the conventions"," block in AGENTS.md (kept current by the bridge) and the project"," .mcp.json \u2014 for teams whose colleagues should get the rules with"," the repository; recommended for teams that work mostly in Cursor"," --no-hook Never write hooks (Claude Code, Cursor, Codex; overrides --full)"," --no-rules Never write the user-level rule files (Copilot, Cline, Continue)"," --non-interactive Skip every TTY prompt (used by CI / Dashboard-One-Click)"," --token <key> Use a pre-issued mnd_ api-key instead of browser pairing"," --one-click-token <jwt> Exchange the dashboard one-click token for a device-bound"," key \u2014 no browser (needs --one-click-exchange-url; ADR-267)"," --one-click-exchange-url <url> Exchange endpoint (set by the launcher scripts)"," --client <family> Install only for one client family \u2014 one of:",` ${yh()}`," (windsurf = Devin Desktop, formerly Windsurf)"," --skip-codex Skip Codex (its config.toml and hook) even where Codex is installed",' --dry-run Compute the plan but do not write anything (status "would-\u2026")'," --hooks-only Only the user-level channels: the hooks (Claude Code; Cursor and"," Codex where installed) and the rule files (Copilot, Cline,"," Continue where installed) \u2014 no pairing, no MCP configs; adds"," what an existing install is missing; with --full, without prompts"," --agent-activity Opt-in: Claude Code sessions bound to one work object report their"," agent activity (plan, action counts, questions, answers) to it \u2014"," never paths or commands; not implied by --full"," --telemetry Opt-in: post anonymous install_completed event"," --no-preamble No effect since 0.100.0 (accepted for old scripts)"," -h, --help Show this help text","","Examples:"," npx -y @maind-dev/mcp-bridge install # interactive default"," npx -y @maind-dev/mcp-bridge install --dry-run # preview without writing anything"," npx -y @maind-dev/mcp-bridge install --full --telemetry # full setup, opt-in telemetry"," npx -y @maind-dev/mcp-bridge install --team # also AGENTS.md + .mcp.json in the repo"," npx -y @maind-dev/mcp-bridge install --client cursor # only Cursor target","","Blocks earlier versions wrote into a repository (CLAUDE.md, AGENTS.md, \u2026) stay","until you remove them: maind-mcp-bridge doctor --migrate-repo-blocks lists them.","","After it finishes, restart your MCP client so the new server entry takes effect.",""].join(`
151
+ `,{encoding:"utf8",mode:384}),uB(a,i)}catch{}}function oT(e=Ot()){try{let t=JSON.parse(cB(rT(e),"utf8"));return t.v!==1||typeof t.at!="string"||!fB.includes(t.outcome)?null:{v:1,at:t.at,outcome:t.outcome,detail:typeof t.detail=="string"?t.detail:null,bridge_version:typeof t.bridge_version=="string"?t.bridge_version:"?"}}catch{return null}}var fB,mB,hB,dh=w(()=>{"use strict";ye();fB=["ok","paired","auth_failed","not_paired"],mB="connection-state.json",hB=200;s(rT,"connectionStatePath");s(gB,"redactDetail");s(Xr,"writeConnectionState");s(oT,"readConnectionState")});var G,We=w(()=>{"use strict";G="0.116.3"});import{execFileSync as iT}from"node:child_process";import{createHash as yB}from"node:crypto";function ph(e){return yB("sha256").update(e).digest("hex")}function fh(e){let t=e.trim();if(!t)return null;let n=/^[a-z][a-z0-9+.-]*:\/\//i.exec(t);if(n)t=t.slice(n[0].length),t=t.replace(/^[^@/]+@/,""),t=t.replace(/^([^/:]+):\d+(?=\/)/,"$1");else{t=t.replace(/^[^@/]+@/,"");let r=t.indexOf(":");r>=0&&(t=`${t.slice(0,r)}/${t.slice(r+1)}`)}return t=t.replace(/\.git$/i,"").replace(/\/+$/,"").toLowerCase(),t.length>0?t:null}function qn(e){let t=fh(e);return t?ph(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&_B.test(e))return e;let t;try{t=iT("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?qn(t):null}function Qe(e){let t;try{t=iT("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?qn(t):null}var _B,he=w(()=>{"use strict";s(ph,"sha256Hex");s(fh,"normalizeRemoteUrl");s(qn,"projectKeyFromRemote");_B=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(Qe,"projectKeyForRepo")});import bB from"node:path";import{fileURLToPath as kB}from"node:url";function wB(e,t=bB.sep){return e.split(t).includes("_npx")}function we(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",aT,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):wB(e.entryPath,e.sep)?n("bridge is running from the npx cache (install it globally to pin a path)"):e.nodePath?{command:e.nodePath,args:[e.entryPath,...t],env:e.isElectron?{ELECTRON_RUN_AS_NODE:"1"}:{},fallbackReason:null}:n("node executable path unavailable")}function ie(){try{let e=kB(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function et(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${sT(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:sT(n)).join(" ")}function _t(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(aT)}function Tc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function sT(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var aT,lt=w(()=>{"use strict";aT="@maind-dev/mcp-bridge";s(wB,"isEphemeralEntry");s(we,"resolveBridgeLaunch");s(ie,"currentBridgeEntry");s(et,"launchToShellCommand");s(_t,"isNpxForm");s(Tc,"isLegacyHookForm");s(sT,"shellQuote")});import{readFileSync as vB}from"node:fs";import*as F from"node:path";function uT(e){let t=e.launch??we({entryPath:ie(),nodePath:process.execPath,isElectron:process.versions.electron!==void 0});return{command:t.command,args:t.args,env:{...t.env,MAIND_CLIENT_FAMILY:e.clientFamily,MAIND_MCP_URL:e.mcpUrl}}}function pT(e){return Ic(e,"Claude")}function SB(e){return F.join(pT(e),dT)}function Ic(e,t){switch(e.platform){case"darwin":return F.join(e.homeDir,"Library","Application Support",t);case"win32":{let n=e.appData??F.join(e.homeDir,"AppData","Roaming");return F.join(n,t)}default:{let n=e.xdgConfigHome??F.join(e.homeDir,".config");return F.join(n,t)}}}function EB(e){return F.join(Ic(e,"Code"),"User")}function Ac(e,t,n=[]){return{kind:"foreign-entries",dir:Ic(e,t),ours:["User",...n]}}function lT(e){return e.localAppData??F.join(e.homeDir,"AppData","Local")}function CB(e){let t=[{kind:"foreign-entries",dir:pT(e),ours:[dT]}];return e.platform==="darwin"?t.push({kind:"dir",path:F.join("/Applications","Claude.app")},{kind:"dir",path:F.join(e.homeDir,"Applications","Claude.app")}):e.platform==="win32"&&t.push({kind:"dir",path:F.join(lT(e),"AnthropicClaude")},{kind:"dir",path:F.join(lT(e),"Packages",TB)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function wn(e){return{evidence:[Ac(e,"Cursor"),{kind:"foreign-entries",dir:F.join(e.homeDir,".cursor"),ours:["mcp.json","hooks.json"]}],skipDetail:"Cursor not found (no Cursor app data, nothing of Cursor's in ~/.cursor)"}}function fT(e){if(e.platform==="win32"){let t=e.appData??F.join(e.homeDir,"AppData","Roaming");return F.join(t,"devin")}return F.join(e.xdgConfigHome??F.join(e.homeDir,".config"),"devin")}function AB(e){return F.join(fT(e),"mcp_config.json")}function mT(e){return F.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function Rc(e){let t=[Ac(e,"Devin",["mcp_config.json"]),{kind:"dir",path:F.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:fT(e),ours:["mcp_config.json"]}),t.push(Ac(e,"Windsurf"),{kind:"foreign-entries",dir:F.dirname(mT(e)),ours:["mcp_config.json"]}),{evidence:t,skipDetail:"Devin Desktop (formerly Windsurf) not found (no Devin or Windsurf app data, nothing of theirs in ~/.devin, Devin's config dir or ~/.codeium/windsurf)"}}function DB(e){return e===null?null:OB.exec(e)?.[1]??null}function gT(e,t){let n=hT.map(r=>F.join(e.homeDir,r.dataFolder,"extensions"));if(e.bundleAppRoot&&n.push(F.join(e.bundleAppRoot,"extensions")),e.platform==="darwin")for(let r of NB)for(let o of["/Applications",F.join(e.homeDir,"Applications")])n.push(F.join(o,`${r}.app`,"Contents","Resources","app","extensions"));return[...new Set(n)].map(r=>({kind:"extension",dir:r,id:t}))}function yT(e){return e.clineDataDir?e.clineDataDir:F.join(e.clineDir??F.join(e.homeDir,".cline"),"data")}function PB(e){return e.clineMcpSettingsPath??F.join(yT(e),"settings","cline_mcp_settings.json")}function mh(e){return{evidence:[{kind:"foreign-entries",dir:yT(e),ours:["settings"]},...RB.map(t=>({kind:"dir",path:F.join(Ic(e,t),"User","globalStorage",cT)})),...gT(e,cT)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function Nc(e){return e.continueGlobalDir??F.join(e.homeDir,".continue")}function MB(e){return F.join(Nc(e),"mcpServers","maind.json")}function hh(e){return{evidence:[{kind:"foreign-entries",dir:Nc(e),ours:["mcpServers","rules"]},...gT(e,IB)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function zn(e){return e.codexHome??F.join(e.homeDir,".codex")}function Zr(e){return F.join(zn(e),"config.toml")}function ai(e){let t=zn(e),n=F.join(e.homeDir,".codex"),r=[{kind:"foreign-entries",dir:t,ours:["config.toml"]}];return t!==n&&r.push({kind:"foreign-entries",dir:n,ours:["config.toml"]}),{evidence:r,skipDetail:t===n?"Codex not found (nothing of Codex's in ~/.codex)":"Codex not found (nothing of Codex's in $CODEX_HOME or ~/.codex)"}}function _T(e){return F.join(e.geminiCliHome??e.homeDir,".gemini")}function li(e){return F.join(_T(e),"settings.json")}function ci(e){let t=_T(e),n=F.join(e.homeDir,".gemini"),r=[{kind:"foreign-entries",dir:t,ours:["settings.json"]}];return t!==n&&r.push({kind:"foreign-entries",dir:n,ours:["settings.json"]}),{evidence:r,skipDetail:t===n?"Gemini CLI not found (nothing of Gemini's in ~/.gemini)":"Gemini CLI not found (nothing of Gemini's in $GEMINI_CLI_HOME/.gemini or ~/.gemini)"}}function qs(e){return{evidence:[Ac(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function $B(e){return F.join(EB(e),"mcp.json")}function zs(e){return[{key:"claude-code-project",label:"Claude Code (project-scoped .mcp.json)",clientFamilyEnv:"claude-code",scope:"project",path:F.join(e.projectRoot,".mcp.json"),kind:"json"},{key:"claude-code-user",label:"Claude Code (user-scoped ~/.claude.json)",clientFamilyEnv:"claude-code",scope:"user",path:F.join(e.homeDir,".claude.json"),kind:"json"},{key:"claude-desktop",label:"Claude Desktop",clientFamilyEnv:"claude-desktop",scope:"user",path:SB(e),kind:"json",presence:CB(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:F.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:wn(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:AB(e),kind:"json",presence:Rc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:mT(e),kind:"json",presence:Rc(e),refreshOnly:{skipDetail:"no maind entry here to keep current \u2014 Devin Desktop's own file is the windsurf row"}},{key:"vscode-copilot",label:"GitHub Copilot (VS Code user mcp.json)",clientFamilyEnv:"copilot",scope:"user",path:$B(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:qs(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:PB(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:mh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:MB(e),kind:"json",presence:hh(e)},{key:"gemini-cli",label:"Gemini CLI (~/.gemini/settings.json)",clientFamilyEnv:"gemini-cli",scope:"user",path:li(e),kind:"json",presence:ci(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:Zr(e),kind:"toml",presence:ai(e)}]}function bT(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function kT(e){return e.jsonShape??xB}function wT(e){let{homeDir:t,platform:n,env:r}=e,o=F.join(t,"Documents");if(n==="win32"){let c=["OneDrive","OneDriveConsumer","OneDriveCommercial"].map(u=>r[u]?.trim()).filter(u=>typeof u=="string"&&u.length>0&&F.win32.isAbsolute(u)).map(u=>F.join(u,"Documents"));return[...new Set([o,...c])]}if(n==="darwin")return[o];let i=r.XDG_CONFIG_HOME?.trim()||F.join(t,".config"),a=e.readText?.(F.join(i,"user-dirs.dirs"))??null,l=a===null?null:vT(a,t);return l!==null&&l!==o?[l,o]:[o]}function vT(e,t){for(let n of e.split(/\r?\n/)){let r=/^\s*XDG_DOCUMENTS_DIR\s*=\s*"?([^"]*)"?\s*$/.exec(n);if(!r)continue;let o=r[1].replace(/^\$HOME(?=\/|$)/,t).replace(/^\$\{HOME\}(?=\/|$)/,t);return F.isAbsolute(o)&&o.length>1?F.normalize(o):null}return null}function vn(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:Cc(e.env.XDG_CONFIG_HOME),appData:Cc(e.env.APPDATA),localAppData:Cc(e.env.LOCALAPPDATA),clineDir:si(e.env.CLINE_DIR),clineDataDir:si(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:si(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:si(e.env.CONTINUE_GLOBAL_DIR),codexHome:si(e.env.CODEX_HOME),geminiCliHome:si(e.env.GEMINI_CLI_HOME),bundleAppRoot:DB(e.bridgeEntry??null),documentsDirs:wT({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return vB(t,"utf8")}catch{return null}},"readText")})}}function Cc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function si(e){let t=Cc(e);return t!==null&&F.isAbsolute(t)?t:null}var xB,dT,TB,hT,RB,cT,IB,NB,OB,gh,Ke=w(()=>{"use strict";lt();xB={serversKey:"mcpServers"};s(uT,"buildMaindServerEntry");dT="claude_desktop_config.json";s(pT,"claudeDesktopAppDataDir");s(SB,"claudeDesktopConfigPath");s(Ic,"editorAppDataDir");s(EB,"vsCodeUserDir");s(Ac,"editorRan");s(lT,"localAppDataDir");TB="Claude_pzs8sxrjxfjjc";s(CB,"claudeDesktopPresence");s(wn,"cursorPresence");s(fT,"devinConfigDir");s(AB,"devinMcpConfigPath");s(mT,"windsurfLegacyMcpConfigPath");s(Rc,"devinDesktopPresence");hT=[{appData:"Code",dataFolder:".vscode"},{appData:"Code - Insiders",dataFolder:".vscode-insiders"},{appData:"Cursor",dataFolder:".cursor"},{appData:"VSCodium",dataFolder:".vscode-oss"},{appData:"Windsurf",dataFolder:".windsurf"},{appData:"Devin",dataFolder:".devin"},{appData:"AgentComposer",dataFolder:".agentcomposer"}],RB=hT.map(e=>e.appData),cT="saoudrizwan.claude-dev",IB="continue.continue",NB=["AgentComposer"],OB=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(DB,"bundleAppRootOf");s(gT,"agentExtensionEvidence");s(yT,"clineDataDir");s(PB,"clineMcpSettingsPath");s(mh,"clinePresence");s(Nc,"continueGlobalDir");s(MB,"continueMcpConfigPath");s(hh,"continuePresence");s(zn,"codexHomeDir");s(Zr,"codexConfigPath");s(ai,"codexPresence");s(_T,"geminiDir");s(li,"geminiSettingsPath");s(ci,"geminiPresence");s(qs,"vsCodePresence");s($B,"vsCodeUserMcpPath");s(zs,"getClientTargets");s(bT,"filterTargetsByFamily");s(kT,"jsonShapeOf");gh=[...new Set(zs({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(wT,"documentsDirCandidates");s(vT,"parseXdgDocumentsDir");s(vn,"makeDefaultContext");s(Cc,"nonEmpty");s(si,"absoluteOrNull")});function yh(){return gh.map(e=>{let t=Object.keys(Oc).filter(n=>Oc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function xT(e){let t={projectRoot:null,full:!1,team:!1,noRules:!1,noPreamble:!1,noHook:!1,nonInteractive:!1,token:null,oneClickToken:null,oneClickExchangeUrl:null,telemetry:!1,client:null,skipCodex:!1,dryRun:!1,autoWorkingPaths:!1,agentActivity:!1,hooksOnly:!1,help:!1,notices:[]};for(let n=0;n<e.length;n++){let r=e[n];switch(r){case"-h":case"--help":t.help=!0;break;case"--full":t.full=!0;break;case"--team":t.team=!0;break;case"--no-rules":t.noRules=!0;break;case"--no-preamble":t.noPreamble||t.notices.push(LB),t.noPreamble=!0;break;case"--no-hook":t.noHook=!0;break;case"--non-interactive":t.nonInteractive=!0;break;case"--telemetry":t.telemetry=!0;break;case"--skip-codex":t.skipCodex=!0;break;case"--dry-run":t.dryRun=!0;break;case"--auto-working-paths":t.autoWorkingPaths=!0;break;case"--agent-activity":t.agentActivity=!0;break;case"--hooks-only":t.hooksOnly=!0;break;case"--project-root":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--project-root requires a path argument");t.projectRoot=o,n++;break}case"--token":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--token requires a token argument");t.token=o,n++;break}case"--one-click-token":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--one-click-token requires a token argument");t.oneClickToken=o,n++;break}case"--one-click-exchange-url":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt("--one-click-exchange-url requires a URL argument");t.oneClickExchangeUrl=o,n++;break}case"--client":{let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new bt(`--client requires a family argument (${yh()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(Oc,i)?Oc[i]:i;if(!gh.includes(a))throw new bt(`--client "${o}" is not a known client family. Known: ${yh()}`);t.client=a,n++;break}default:throw new bt(`Unknown flag: ${r} \u2014 run \`install --help\` for supported flags`)}}if(t.full&&(t.nonInteractive=!0),t.hooksOnly){let n=[t.noHook&&"--no-hook",t.projectRoot!==null&&"--project-root",t.team&&"--team",t.token!==null&&"--token",t.oneClickToken!==null&&"--one-click-token",t.oneClickExchangeUrl!==null&&"--one-click-exchange-url",t.client!==null&&"--client",t.skipCodex&&"--skip-codex",t.telemetry&&"--telemetry",t.autoWorkingPaths&&"--auto-working-paths",t.agentActivity&&"--agent-activity"].filter(r=>typeof r=="string");if(n.length>0)throw new bt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function ST(){process.stdout.write(jB())}function jB(){return["","@maind-dev/mcp-bridge install \u2014 one-shot setup for the MAIND MCP server.","","Pairs this device with MAIND and merges the MCP-server entry into every","supported AI-client config it finds (user level). Then it sets up the","channels that bring the MAIND hint and your project conventions into each","session \u2014 each with its own consent, only for clients that are installed:","hooks for Claude Code (~/.claude/settings.json), Cursor (~/.cursor/hooks.json)","and Codex (config.toml), user-level rule files for GitHub Copilot, Cline and","Continue. It writes nothing into your repository unless you pass --team.","Idempotent \u2014 re-running is safe.","","Usage:"," npx -y @maind-dev/mcp-bridge install [flags]","","Common flags:"," --project-root <path> Override project-root detection (default: walk up from cwd)"," --full Non-interactive full setup (consents to the hooks and rule files)"," --team Also write into the repository, deliberately: the conventions"," block in AGENTS.md (kept current by the bridge) and the project"," .mcp.json \u2014 for teams whose colleagues should get the rules with"," the repository; recommended for teams that work mostly in Cursor"," --no-hook Never write hooks (Claude Code, Cursor, Codex; overrides --full)"," --no-rules Never write the user-level rule files (Copilot, Cline, Continue)"," --non-interactive Skip every TTY prompt (used by CI / Dashboard-One-Click)"," --token <key> Use a pre-issued mnd_ api-key instead of browser pairing"," --one-click-token <jwt> Exchange the dashboard one-click token for a device-bound"," key \u2014 no browser (needs --one-click-exchange-url; ADR-267)"," --one-click-exchange-url <url> Exchange endpoint (set by the launcher scripts)"," --client <family> Install only for one client family \u2014 one of:",` ${yh()}`," (windsurf = Devin Desktop, formerly Windsurf)"," --skip-codex Skip Codex (its config.toml and hook) even where Codex is installed",' --dry-run Compute the plan but do not write anything (status "would-\u2026")'," --hooks-only Only the user-level channels: the hooks (Claude Code; Cursor and"," Codex where installed) and the rule files (Copilot, Cline,"," Continue where installed) \u2014 no pairing, no MCP configs; adds"," what an existing install is missing; with --full, without prompts"," --agent-activity Opt-in: Claude Code sessions bound to one work object report their"," agent activity (plan, action counts, questions, answers) to it \u2014"," never paths or commands; not implied by --full"," --telemetry Opt-in: post anonymous install_completed event"," --no-preamble No effect since 0.100.0 (accepted for old scripts)"," -h, --help Show this help text","","Examples:"," npx -y @maind-dev/mcp-bridge install # interactive default"," npx -y @maind-dev/mcp-bridge install --dry-run # preview without writing anything"," npx -y @maind-dev/mcp-bridge install --full --telemetry # full setup, opt-in telemetry"," npx -y @maind-dev/mcp-bridge install --team # also AGENTS.md + .mcp.json in the repo"," npx -y @maind-dev/mcp-bridge install --client cursor # only Cursor target","","Blocks earlier versions wrote into a repository (CLAUDE.md, AGENTS.md, \u2026) stay","until you remove them: maind-mcp-bridge doctor --migrate-repo-blocks lists them.","","After it finishes, restart your MCP client so the new server entry takes effect.",""].join(`
152
152
  `)}var Oc,LB,bt,ET=w(()=>{"use strict";Ke();Oc={devin:"windsurf"};s(yh,"familyChoices");LB="note: --no-preamble has no effect since bridge 0.100.0 \u2014 install writes no preamble files into the repository any more (ADR-364).";s(xT,"parseInstallFlags");bt=class extends Error{static{s(this,"InstallFlagError")}constructor(t){super(t),this.name="InstallFlagError"}};s(ST,"printInstallHelp");s(jB,"installHelpText")});var Js,TT=w(()=>{"use strict";Js=class{static{s(this,"InstallReport")}results=[];add(t){this.results.push(t)}results_(){return this.results}summary(){let t=0,n=0,r=0;for(let o of this.results)o.status==="created"||o.status==="merged"||o.status==="skipped"||o.status==="would-create"||o.status==="would-merge"||o.status==="would-pair"?t++:o.status==="needs-user-decision"?n++:o.status==="failed"&&r++;return{total:this.results.length,ok:t,needsDecision:n,failed:r}}hasFailures(){return this.results.some(t=>t.status==="failed")}hasUserDecisionPending(){return this.results.some(t=>t.status==="needs-user-decision")}exitCode(){return this.hasFailures()||this.hasUserDecisionPending()?1:0}toMarkdownTable(){if(this.results.length===0)return`_no steps were attempted_
153
153
  `;let t=["Target","Action","Status","Detail"],n=Math.max(t[0].length,...this.results.map(u=>u.target.length)),r=Math.max(t[1].length,...this.results.map(u=>u.action.length)),o=Math.max(t[2].length,...this.results.map(u=>u.status.length)),i=Math.max(t[3].length,...this.results.map(u=>(u.detail??"").length)),a=s((u,d)=>u+" ".repeat(Math.max(0,d-u.length)),"pad"),l=`| ${"-".repeat(n)} | ${"-".repeat(r)} | ${"-".repeat(o)} | ${"-".repeat(i)} |`,c=[];c.push(`| ${a(t[0],n)} | ${a(t[1],r)} | ${a(t[2],o)} | ${a(t[3],i)} |`),c.push(l);for(let u of this.results)c.push(`| ${a(u.target,n)} | ${a(u.action,r)} | ${a(u.status,o)} | ${a(u.detail??"",i)} |`);return c.join(`
154
154
  `)+`
@@ -848,7 +848,7 @@ ${u.title}`;if(vu(l+d)>a){c=!1;break}l+=d;for(let p=0;p<u.lines.length;p++){let
848
848
  ${u.lines[p]}`;if(vu(l+f)<=a){l+=f;continue}c=!1;let m=`
849
849
  (+${u.lines.length-p} more \u2014 via ${u.more})`;vu(l+m)<=r&&(l+=m);break}if(!c)break}if(!c){let u=`
850
850
  \u2026 budget reached \u2014 the rest via get_session_briefing / get_conventions.`;vu(l+u)<=r&&(l+=u)}return{text:l+`
851
- `,complete:c}}var vu,WA=w(()=>{"use strict";vu=s(e=>Buffer.byteLength(e,"utf8"),"bytes");s(xi,"extractConventionsBlock");s(Hg,"briefingSections");s(Si,"composeInjection")});function xu(e){return typeof e=="string"&&e.includes(KA)}function Ug(e){let t=[];for(let n of e.split(/\r?\n/)){let r=/^\*\*\* (Add File|Update File|Delete File|Move to): (.+)$/.exec(n.trimEnd());if(r===null)continue;let o=r[2].trim();o.length!==0&&t.push({path:o,act:r[1]==="Add File"||r[1]==="Move to"?"write":"edit"})}return t}var KA,VA=w(()=>{"use strict";KA="*** Begin Patch";s(xu,"looksLikePatch");s(Ug,"patchFiles")});var wt=w(()=>{"use strict";kg();jA();Ag();Ng();UA();GA();WA();VA()});function JA(e){try{let t=Buffer.concat(e).toString("utf-8").trim();if(!t)return{};let n=JSON.parse(t);return n!==null&&typeof n=="object"&&!Array.isArray(n)?n:{}}catch{return{}}}async function me(){let e=process.stdin;if(e.isTTY)return{};let t=[],n=0;return await new Promise(r=>{let o=!1,i,a=s(c=>{o||(o=!0,clearTimeout(i),r(c))},"settle"),l=s(c=>{clearTimeout(i),i=setTimeout(()=>{let u=n;setImmediate(()=>{o||n!==u||a(JA(t))})},c)},"arm");l(p2),e.on("data",c=>{o||(t.push(typeof c=="string"?Buffer.from(c,"utf-8"):c),n+=1,l(f2))}),e.on("end",()=>a(JA(t))),e.on("error",()=>a({}))})}function lo(e){return typeof e.transcript_path=="string"?e.transcript_path:""}function Bg(e){let t=e.tool_input;if(t===null||typeof t!="object")return"";let n=t.file_path;return typeof n=="string"?n:""}function YA(e){return Ug(e)}function XA(e){if(typeof e=="string")return xu(e)?e:null;if(e===null||typeof e!="object")return null;let t=e;for(let n of["command","input","patch"]){let r=Pt(t[n]);if(xu(r))return r}return null}function Mt(e){let t=typeof e.tool_name=="string"?e.tool_name:"",n=e.tool_input,r=n!==null&&typeof n=="object"?n:{},o=s((i,a)=>i===null?[]:[{path:i,act:a}],"one");switch(t){case"Write":return o(Pt(r.file_path)??Pt(r.path),"write");case"Read":return o(Pt(r.file_path)??Pt(r.path),"read");case"Edit":{let i=XA(n);return i!==null?YA(i):o(Pt(r.file_path)??Pt(r.path),"edit")}case"create_file":return o(Pt(r.filePath),"write");case"read_file":return o(Pt(r.filePath),"read");case"multi_replace_string_in_file":{let i=Array.isArray(r.replacements)?r.replacements:[],a=new Set,l=[];for(let c of i){let u=c!==null&&typeof c=="object"?Pt(c.filePath):null;u!==null&&!a.has(u)&&(a.add(u),l.push({path:u,act:"edit"}))}return l}case"apply_patch":{let i=XA(n);return i===null?[]:YA(i)}default:return m2.has(t)?o(Pt(r.filePath),"edit"):[]}}var p2,f2,Pt,m2,He=w(()=>{"use strict";wt();p2=1e3,f2=200;s(JA,"parsePayload");s(me,"readHookInput");s(lo,"transcriptPathOf");s(Bg,"toolFilePathOf");Pt=s(e=>typeof e=="string"&&e.length>0?e:null,"str"),m2=new Set(["replace_string_in_file","insert_edit_into_file","edit_notebook_file"]);s(YA,"patchFiles");s(XA,"patchTextOf");s(Mt,"toolFilesOf")});function en(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}})}function Tn(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:e}})}function ka(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PostToolUse",additionalContext:e}})}function Su(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PostToolUseFailure",additionalContext:e}})}function Gg(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:e}})}var Ei=w(()=>{"use strict";s(en,"denyPayload");s(Tn,"advisoryPayload");s(ka,"postAdvisoryPayload");s(Su,"postFailureAdvisoryPayload");s(Gg,"promptAdvisoryPayload")});function h2(e){return Ue(e)&&/[\\/]\.claude[^\\/]*[\\/]projects[\\/]/.test(e)}function Wg(e){return Ue(e)&&/[\\/]sessions[\\/]\d{4}[\\/]\d{2}[\\/]\d{2}[\\/]rollout-[^\\/]+\.jsonl$/.test(e)}function g2(e){return Ue(e)&&/[\\/]GitHub\.copilot-chat[\\/]transcripts[\\/][^\\/]+\.jsonl$/i.test(e)}function Kg(e){for(let t of e){if(t==="--host=codex")return"codex";if(t==="--host=copilot")return"copilot";if(t==="--host=gemini")return"gemini"}return null}function Ti(e,t=process.env,n=null){return n==="codex"||n==="copilot"||n==="gemini"?n:Ue(e.cursor_version)?"cursor":h2(e.transcript_path)?"claude-code":Wg(e.transcript_path)?"codex":g2(e.transcript_path)?"copilot":Ue(t.CURSOR_VERSION)?"cursor":Ue(t.DEVIN_PROJECT_DIR)?"devin":Ue(t.GEMINI_SESSION_ID)?"gemini":Ue(t.COPILOT_PROJECT_DIR)?"copilot":Ue(t.CLAUDE_PROJECT_DIR)||t.CLAUDECODE==="1"?"claude-code":Ue(e.timestamp)&&!Number.isNaN(Date.parse(e.timestamp))&&Ue(e.hook_event_name)?"copilot":"unknown"}function ZA(e,t=process.env){return Ti(e,t)==="cursor"}function co(e){return e==="cursor"||e==="devin"||e==="codex"||e==="copilot"||e==="gemini"}function Oe(e,t=process.env){return co(Ti(e,t))}function y2(e=process.env,t=null){let n=e.MAIND_DEVIN_HOOK_OUTPUT?.trim().toLowerCase();return n==="off"?!1:n==="on"?!0:t?.devin_hook_output!==!1}function Cn(e,t=process.env,n=te,r=Kg(process.argv.slice(2))){let o=Ti(e,t,r);return{host:o,devinOutput:o==="devin"?y2(t,n()):!1}}function QA(e){switch(e.kind){case"text":return e.text;case"deny":return en(e.reason);case"context":switch(e.event){case"UserPromptSubmit":return Gg(e.text);case"PreToolUse":return Tn(e.text);case"PostToolUse":return ka(e.text);case"PostToolUseFailure":return Su(e.text)}}}function _2(e){return e.kind==="deny"?JSON.stringify({permission:"deny",user_message:e.reason,agent_message:e.reason}):null}function b2(e){switch(e.kind){case"text":return JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:e.text.replace(/\s+$/,"")}});case"deny":return JSON.stringify({decision:"block",reason:e.reason});case"context":return e.event==="UserPromptSubmit"?Gg(e.text):e.event==="PostToolUse"?ka(e.text):null}}function e0(e){return{hookEventName:"SessionStart",additionalContext:e.replace(/\s+$/,"")}}function k2(e){switch(e.kind){case"text":return JSON.stringify({hookSpecificOutput:e0(e.text)});case"deny":return en(e.reason);case"context":return e.event==="PostToolUseFailure"?null:QA(e)}}function w2(e){switch(e.kind){case"text":{let t=e0(e.text);return JSON.stringify({additionalContext:t.additionalContext,hookSpecificOutput:t})}case"deny":return JSON.stringify({permissionDecision:"deny",permissionDecisionReason:e.reason,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e.reason}});case"context":return e.event==="PostToolUseFailure"?null:JSON.stringify({additionalContext:e.text,hookSpecificOutput:{hookEventName:e.event,additionalContext:e.text}})}}function v2(e){return e.kind==="text"?JSON.stringify({hookSpecificOutput:{additionalContext:e.text.replace(/\s+$/,"")}}):e.kind==="context"&&e.event==="UserPromptSubmit"?JSON.stringify({hookSpecificOutput:{additionalContext:e.text}}):null}function t0(e){return e.host==="gemini"}function uo(e,t){switch(e.host){case"claude-code":case"unknown":return QA(t);case"cursor":return _2(t);case"devin":return e.devinOutput?b2(t):null;case"codex":return k2(t);case"copilot":return w2(t);case"gemini":return v2(t)}}function Te(e,t){let n=t.kind==="deny"?{kind:"deny",reason:"x"}:{...t,text:"x"};return uo(e,n)!==null}function wa(e){return new Promise(t=>{process.stdout.write(e,()=>t())})}function Ci(e,t=process.env){return e.host==="devin"&&Ue(t.DEVIN_PROJECT_DIR)?t.DEVIN_PROJECT_DIR.trim():e.host==="cursor"&&Ue(t.CURSOR_PROJECT_DIR)?t.CURSOR_PROJECT_DIR.trim():e.host==="copilot"&&Ue(t.COPILOT_PROJECT_DIR)?t.COPILOT_PROJECT_DIR.trim():e.host==="gemini"&&Ue(t.GEMINI_PROJECT_DIR)?t.GEMINI_PROJECT_DIR.trim():null}function ot(e,t,n=process.env){return Ue(e.cwd)?e.cwd:Ci(t,n)??process.cwd()}var Ue,Ce=w(()=>{"use strict";Ee();Ei();Ue=s(e=>typeof e=="string"&&e.trim().length>0,"filled");s(h2,"isClaudeCodeTranscript");s(Wg,"isCodexTranscript");s(g2,"isCopilotTranscript");s(Kg,"hostHintFromArgv");s(Ti,"detectHookHost");s(ZA,"runsUnderCursor");s(co,"isForeignHost");s(Oe,"guardStandsDown");s(y2,"devinOutputEnabled");s(Cn,"resolveHookTarget");s(QA,"claudeCodeBytes");s(_2,"cursorBytes");s(b2,"devinBytes");s(e0,"sessionStartContext");s(k2,"codexBytes");s(w2,"copilotBytes");s(v2,"geminiBytes");s(t0,"hostNeedsJsonAnswer");s(uo,"renderHookOutput");s(Te,"hostDelivers");s(wa,"writeHookStdout");s(Ci,"hostProjectDir");s(ot,"sessionCwd")});var Vg={};Z(Vg,{deliverSessionReminder:()=>x2,runOnSessionReminder:()=>E2,sessionReminderCore:()=>S2});import{readFile as n0}from"node:fs/promises";import{homedir as r0}from"node:os";import{join as o0}from"node:path";async function x2(e,t={}){let n=t.target??Cn(e);if(!Te(n,{kind:"text",event:"SessionStart"}))return 0;let r;try{r=await n0(o0(t.homeDir??r0(),fi),"utf8")}catch{return 0}if(r.length===0)return 0;let o=uo(n,{kind:"text",event:"SessionStart",text:r});return o!==null&&await(t.write??wa)(o),0}async function S2(e,t,n=r0()){if(!Te(t,{kind:"text",event:"SessionStart"}))return null;let r;try{r=await n0(o0(n,fi),"utf8")}catch{return null}return r.length===0?null:{kind:"text",event:"SessionStart",text:r}}async function E2(){return _e(["on-session-reminder"])}var qg=w(()=>{"use strict";Ne();ze();Ce();s(x2,"deliverSessionReminder");s(S2,"sessionReminderCore");s(E2,"runOnSessionReminder")});import{existsSync as i0}from"node:fs";import{mkdir as T2,readFile as C2,readdir as A2,rename as R2,stat as I2,unlink as N2,writeFile as O2}from"node:fs/promises";import{join as Ai}from"node:path";function s0(e){return Ai(Jg,e.replace(/[^a-zA-Z0-9._-]/g,"_")+".json")}async function $t(e){try{let t=s0(e);if(!i0(t))return{};let n=JSON.parse(await C2(t,"utf8"));return typeof n=="object"&&n!==null&&!Array.isArray(n)?n:{}}catch{return{}}}async function it(e,t){await T2(Jg,{recursive:!0,mode:448});let n=s0(e),r=`${n}.tmp`;await O2(r,JSON.stringify({...t,updated_at:new Date().toISOString()},null,2),{mode:384}),await R2(r,n)}async function a0(e=7*24*60*60*1e3,t=Date.now()){await zg(Jg,".json",e,t),await zg(Yg,".jsonl",e,t),await zg(Ai(ue,"consult"),".json",e,t)}async function zg(e,t,n,r){try{if(!i0(e))return;for(let o of await A2(e)){if(!o.endsWith(t))continue;let i=Ai(e,o);try{let a=await I2(i);r-a.mtimeMs>n&&await N2(i)}catch{}}}catch{}}var ue,Jg,Yg,Be=w(()=>{"use strict";rt();ue=Ai(qe,"guard"),Jg=Ai(ue,"sessions"),Yg=Ai(ue,"triggers");s(s0,"sessionFile");s($t,"loadGuardSession");s(it,"saveGuardSession");s(a0,"sweepOldGuardSessions");s(zg,"sweepDir")});import{existsSync as D2}from"node:fs";import{appendFile as P2,mkdir as M2,open as $2}from"node:fs/promises";import{join as L2}from"node:path";async function re(e){try{await M2(ue,{recursive:!0,mode:448});let t=JSON.stringify({ts:new Date().toISOString(),...e})+`
851
+ `,complete:c}}var vu,WA=w(()=>{"use strict";vu=s(e=>Buffer.byteLength(e,"utf8"),"bytes");s(xi,"extractConventionsBlock");s(Hg,"briefingSections");s(Si,"composeInjection")});function xu(e){return typeof e=="string"&&e.includes(KA)}function Ug(e){let t=[];for(let n of e.split(/\r?\n/)){let r=/^\*\*\* (Add File|Update File|Delete File|Move to): (.+)$/.exec(n.trimEnd());if(r===null)continue;let o=r[2].trim();o.length!==0&&t.push({path:o,act:r[1]==="Add File"||r[1]==="Move to"?"write":"edit"})}return t}var KA,VA=w(()=>{"use strict";KA="*** Begin Patch";s(xu,"looksLikePatch");s(Ug,"patchFiles")});var wt=w(()=>{"use strict";kg();jA();Ag();Ng();UA();GA();WA();VA()});function JA(e){try{let t=Buffer.concat(e).toString("utf-8").trim();if(!t)return{};let n=JSON.parse(t);return n!==null&&typeof n=="object"&&!Array.isArray(n)?n:{}}catch{return{}}}async function me(){let e=process.stdin;if(e.isTTY)return{};let t=[],n=0;return await new Promise(r=>{let o=!1,i,a=s(p=>{o||(o=!0,clearTimeout(i),e.removeListener("data",c),e.removeListener("end",u),e.removeListener("error",d),e.pause(),e.unref?.(),r(p))},"settle"),l=s(p=>{clearTimeout(i),i=setTimeout(()=>{let f=n;setImmediate(()=>{o||n!==f||a(JA(t))})},p)},"arm");function c(p){o||(t.push(typeof p=="string"?Buffer.from(p,"utf-8"):p),n+=1,l(f2))}s(c,"onData");function u(){a(JA(t))}s(u,"onEnd");function d(){a({})}s(d,"onError"),l(p2),e.on("data",c),e.on("end",u),e.on("error",d)})}function lo(e){return typeof e.transcript_path=="string"?e.transcript_path:""}function Bg(e){let t=e.tool_input;if(t===null||typeof t!="object")return"";let n=t.file_path;return typeof n=="string"?n:""}function YA(e){return Ug(e)}function XA(e){if(typeof e=="string")return xu(e)?e:null;if(e===null||typeof e!="object")return null;let t=e;for(let n of["command","input","patch"]){let r=Pt(t[n]);if(xu(r))return r}return null}function Mt(e){let t=typeof e.tool_name=="string"?e.tool_name:"",n=e.tool_input,r=n!==null&&typeof n=="object"?n:{},o=s((i,a)=>i===null?[]:[{path:i,act:a}],"one");switch(t){case"Write":return o(Pt(r.file_path)??Pt(r.path),"write");case"Read":return o(Pt(r.file_path)??Pt(r.path),"read");case"Edit":{let i=XA(n);return i!==null?YA(i):o(Pt(r.file_path)??Pt(r.path),"edit")}case"create_file":return o(Pt(r.filePath),"write");case"read_file":return o(Pt(r.filePath),"read");case"multi_replace_string_in_file":{let i=Array.isArray(r.replacements)?r.replacements:[],a=new Set,l=[];for(let c of i){let u=c!==null&&typeof c=="object"?Pt(c.filePath):null;u!==null&&!a.has(u)&&(a.add(u),l.push({path:u,act:"edit"}))}return l}case"apply_patch":{let i=XA(n);return i===null?[]:YA(i)}default:return m2.has(t)?o(Pt(r.filePath),"edit"):[]}}var p2,f2,Pt,m2,He=w(()=>{"use strict";wt();p2=1e3,f2=200;s(JA,"parsePayload");s(me,"readHookInput");s(lo,"transcriptPathOf");s(Bg,"toolFilePathOf");Pt=s(e=>typeof e=="string"&&e.length>0?e:null,"str"),m2=new Set(["replace_string_in_file","insert_edit_into_file","edit_notebook_file"]);s(YA,"patchFiles");s(XA,"patchTextOf");s(Mt,"toolFilesOf")});function en(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}})}function Tn(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:e}})}function ka(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PostToolUse",additionalContext:e}})}function Su(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PostToolUseFailure",additionalContext:e}})}function Gg(e){return JSON.stringify({hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:e}})}var Ei=w(()=>{"use strict";s(en,"denyPayload");s(Tn,"advisoryPayload");s(ka,"postAdvisoryPayload");s(Su,"postFailureAdvisoryPayload");s(Gg,"promptAdvisoryPayload")});function h2(e){return Ue(e)&&/[\\/]\.claude[^\\/]*[\\/]projects[\\/]/.test(e)}function Wg(e){return Ue(e)&&/[\\/]sessions[\\/]\d{4}[\\/]\d{2}[\\/]\d{2}[\\/]rollout-[^\\/]+\.jsonl$/.test(e)}function g2(e){return Ue(e)&&/[\\/]GitHub\.copilot-chat[\\/]transcripts[\\/][^\\/]+\.jsonl$/i.test(e)}function Kg(e){for(let t of e){if(t==="--host=codex")return"codex";if(t==="--host=copilot")return"copilot";if(t==="--host=gemini")return"gemini"}return null}function Ti(e,t=process.env,n=null){return n==="codex"||n==="copilot"||n==="gemini"?n:Ue(e.cursor_version)?"cursor":h2(e.transcript_path)?"claude-code":Wg(e.transcript_path)?"codex":g2(e.transcript_path)?"copilot":Ue(t.CURSOR_VERSION)?"cursor":Ue(t.DEVIN_PROJECT_DIR)?"devin":Ue(t.GEMINI_SESSION_ID)?"gemini":Ue(t.COPILOT_PROJECT_DIR)?"copilot":Ue(t.CLAUDE_PROJECT_DIR)||t.CLAUDECODE==="1"?"claude-code":Ue(e.timestamp)&&!Number.isNaN(Date.parse(e.timestamp))&&Ue(e.hook_event_name)?"copilot":"unknown"}function ZA(e,t=process.env){return Ti(e,t)==="cursor"}function co(e){return e==="cursor"||e==="devin"||e==="codex"||e==="copilot"||e==="gemini"}function Oe(e,t=process.env){return co(Ti(e,t))}function y2(e=process.env,t=null){let n=e.MAIND_DEVIN_HOOK_OUTPUT?.trim().toLowerCase();return n==="off"?!1:n==="on"?!0:t?.devin_hook_output!==!1}function Cn(e,t=process.env,n=te,r=Kg(process.argv.slice(2))){let o=Ti(e,t,r);return{host:o,devinOutput:o==="devin"?y2(t,n()):!1}}function QA(e){switch(e.kind){case"text":return e.text;case"deny":return en(e.reason);case"context":switch(e.event){case"UserPromptSubmit":return Gg(e.text);case"PreToolUse":return Tn(e.text);case"PostToolUse":return ka(e.text);case"PostToolUseFailure":return Su(e.text)}}}function _2(e){return e.kind==="deny"?JSON.stringify({permission:"deny",user_message:e.reason,agent_message:e.reason}):null}function b2(e){switch(e.kind){case"text":return JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:e.text.replace(/\s+$/,"")}});case"deny":return JSON.stringify({decision:"block",reason:e.reason});case"context":return e.event==="UserPromptSubmit"?Gg(e.text):e.event==="PostToolUse"?ka(e.text):null}}function e0(e){return{hookEventName:"SessionStart",additionalContext:e.replace(/\s+$/,"")}}function k2(e){switch(e.kind){case"text":return JSON.stringify({hookSpecificOutput:e0(e.text)});case"deny":return en(e.reason);case"context":return e.event==="PostToolUseFailure"?null:QA(e)}}function w2(e){switch(e.kind){case"text":{let t=e0(e.text);return JSON.stringify({additionalContext:t.additionalContext,hookSpecificOutput:t})}case"deny":return JSON.stringify({permissionDecision:"deny",permissionDecisionReason:e.reason,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e.reason}});case"context":return e.event==="PostToolUseFailure"?null:JSON.stringify({additionalContext:e.text,hookSpecificOutput:{hookEventName:e.event,additionalContext:e.text}})}}function v2(e){return e.kind==="text"?JSON.stringify({hookSpecificOutput:{additionalContext:e.text.replace(/\s+$/,"")}}):e.kind==="context"&&e.event==="UserPromptSubmit"?JSON.stringify({hookSpecificOutput:{additionalContext:e.text}}):null}function t0(e){return e.host==="gemini"}function uo(e,t){switch(e.host){case"claude-code":case"unknown":return QA(t);case"cursor":return _2(t);case"devin":return e.devinOutput?b2(t):null;case"codex":return k2(t);case"copilot":return w2(t);case"gemini":return v2(t)}}function Te(e,t){let n=t.kind==="deny"?{kind:"deny",reason:"x"}:{...t,text:"x"};return uo(e,n)!==null}function wa(e){return new Promise(t=>{process.stdout.write(e,()=>t())})}function Ci(e,t=process.env){return e.host==="devin"&&Ue(t.DEVIN_PROJECT_DIR)?t.DEVIN_PROJECT_DIR.trim():e.host==="cursor"&&Ue(t.CURSOR_PROJECT_DIR)?t.CURSOR_PROJECT_DIR.trim():e.host==="copilot"&&Ue(t.COPILOT_PROJECT_DIR)?t.COPILOT_PROJECT_DIR.trim():e.host==="gemini"&&Ue(t.GEMINI_PROJECT_DIR)?t.GEMINI_PROJECT_DIR.trim():null}function ot(e,t,n=process.env){return Ue(e.cwd)?e.cwd:Ci(t,n)??process.cwd()}var Ue,Ce=w(()=>{"use strict";Ee();Ei();Ue=s(e=>typeof e=="string"&&e.trim().length>0,"filled");s(h2,"isClaudeCodeTranscript");s(Wg,"isCodexTranscript");s(g2,"isCopilotTranscript");s(Kg,"hostHintFromArgv");s(Ti,"detectHookHost");s(ZA,"runsUnderCursor");s(co,"isForeignHost");s(Oe,"guardStandsDown");s(y2,"devinOutputEnabled");s(Cn,"resolveHookTarget");s(QA,"claudeCodeBytes");s(_2,"cursorBytes");s(b2,"devinBytes");s(e0,"sessionStartContext");s(k2,"codexBytes");s(w2,"copilotBytes");s(v2,"geminiBytes");s(t0,"hostNeedsJsonAnswer");s(uo,"renderHookOutput");s(Te,"hostDelivers");s(wa,"writeHookStdout");s(Ci,"hostProjectDir");s(ot,"sessionCwd")});var Vg={};Z(Vg,{deliverSessionReminder:()=>x2,runOnSessionReminder:()=>E2,sessionReminderCore:()=>S2});import{readFile as n0}from"node:fs/promises";import{homedir as r0}from"node:os";import{join as o0}from"node:path";async function x2(e,t={}){let n=t.target??Cn(e);if(!Te(n,{kind:"text",event:"SessionStart"}))return 0;let r;try{r=await n0(o0(t.homeDir??r0(),fi),"utf8")}catch{return 0}if(r.length===0)return 0;let o=uo(n,{kind:"text",event:"SessionStart",text:r});return o!==null&&await(t.write??wa)(o),0}async function S2(e,t,n=r0()){if(!Te(t,{kind:"text",event:"SessionStart"}))return null;let r;try{r=await n0(o0(n,fi),"utf8")}catch{return null}return r.length===0?null:{kind:"text",event:"SessionStart",text:r}}async function E2(){return _e(["on-session-reminder"])}var qg=w(()=>{"use strict";Ne();ze();Ce();s(x2,"deliverSessionReminder");s(S2,"sessionReminderCore");s(E2,"runOnSessionReminder")});import{existsSync as i0}from"node:fs";import{mkdir as T2,readFile as C2,readdir as A2,rename as R2,stat as I2,unlink as N2,writeFile as O2}from"node:fs/promises";import{join as Ai}from"node:path";function s0(e){return Ai(Jg,e.replace(/[^a-zA-Z0-9._-]/g,"_")+".json")}async function $t(e){try{let t=s0(e);if(!i0(t))return{};let n=JSON.parse(await C2(t,"utf8"));return typeof n=="object"&&n!==null&&!Array.isArray(n)?n:{}}catch{return{}}}async function it(e,t){await T2(Jg,{recursive:!0,mode:448});let n=s0(e),r=`${n}.tmp`;await O2(r,JSON.stringify({...t,updated_at:new Date().toISOString()},null,2),{mode:384}),await R2(r,n)}async function a0(e=7*24*60*60*1e3,t=Date.now()){await zg(Jg,".json",e,t),await zg(Yg,".jsonl",e,t),await zg(Ai(ue,"consult"),".json",e,t)}async function zg(e,t,n,r){try{if(!i0(e))return;for(let o of await A2(e)){if(!o.endsWith(t))continue;let i=Ai(e,o);try{let a=await I2(i);r-a.mtimeMs>n&&await N2(i)}catch{}}}catch{}}var ue,Jg,Yg,Be=w(()=>{"use strict";rt();ue=Ai(qe,"guard"),Jg=Ai(ue,"sessions"),Yg=Ai(ue,"triggers");s(s0,"sessionFile");s($t,"loadGuardSession");s(it,"saveGuardSession");s(a0,"sweepOldGuardSessions");s(zg,"sweepDir")});import{existsSync as D2}from"node:fs";import{appendFile as P2,mkdir as M2,open as $2}from"node:fs/promises";import{join as L2}from"node:path";async function re(e){try{await M2(ue,{recursive:!0,mode:448});let t=JSON.stringify({ts:new Date().toISOString(),...e})+`
852
852
  `;await P2(or,t,{mode:384})}catch{}}async function l0(e=256*1024){let t={inject_ok:0,inject_fail:0,warn:0,deny:0,override:0,stop_block:0,gate_override:0,cross_session_warn:0,cross_session_deny:0,difficulty_nudge:0,difficulty_deny:0,difficulty_resolved:0,capture_prompt:0,capture_taken:0,consult_warn:0,consult_deny:0,consult_resolved:0,consult_unresolved:0};try{if(!D2(or))return t;let n=await $2(or,"r");try{let r=(await n.stat()).size,o=Math.max(0,r-e),i=Buffer.alloc(r-o);await n.read(i,0,i.length,o);let l=i.toString("utf8").split(`
853
853
  `);for(let c of o>0?l.slice(1):l)if(c.trim())try{let u=JSON.parse(c);typeof u.event=="string"&&u.event in t&&(t[u.event]+=1)}catch{}}finally{await n.close()}}catch{}return t}var or,tn=w(()=>{"use strict";Be();or=L2(ue,"events.jsonl");s(re,"appendGuardEvent");s(l0,"readGuardEventCounts")});function F2(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function va(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!F2(n)||typeof n.id!="string")continue;let r=n.id.trim().toLowerCase();!j2.test(r)||t.some(o=>o.id===r)||t.push({id:r,key:typeof n.key=="string"&&n.key.length>0?n.key:null,title:typeof n.title=="string"&&n.title.length>0?n.title:null})}return t}function Ri(e){let t=e.boundObjects;if(t===null)return{objectId:null,reason:"not_announced",bound:0};let n=e.branchObjectId?.trim().toLowerCase()??null,r=n!==null?t.find(o=>o.id===n):void 0;if(r)return{objectId:r.id,key:r.key,title:r.title,source:"branch"};if(t.length===1){let o=t[0];return{objectId:o.id,key:o.key,title:o.title,source:"single_binding"}}return{objectId:null,reason:t.length===0?"no_binding":"ambiguous",bound:t.length}}function xa(e){if(e.objectId!==null){let t=e.key??e.objectId;return e.source==="branch"?`${t} (the branch's work object)`:`${t} (the session's only bound work object)`}return e.reason==="not_announced"?"no presence answer yet":e.reason==="no_binding"?"the session is bound to no work object":`the session is bound to ${e.bound} work objects and none is the branch's`}var j2,po=w(()=>{"use strict";j2=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;s(F2,"isRecord");s(va,"parseBoundObjects");s(Ri,"resolveActivityTarget");s(xa,"describeTarget")});import{mkdirSync as Xg,readdirSync as c0,readFileSync as H2,renameSync as Zg,statSync as U2,unlinkSync as Eu,writeFileSync as Qg}from"node:fs";import{homedir as B2}from"node:os";import{join as fo}from"node:path";function u0(){return fo(B2(),".maind","presence")}function ty(e,t){return fo(e,t)}function d0(e){let t=e.baseDir??u0(),n=ty(t,e.projectKey),r=e.pid??process.pid,o=e.ppid??process.ppid,i=e.cwd??process.cwd(),a=e.now??Date.now,l=null,c=s(p=>{if(l!==null&&l!==p)try{Eu(l)}catch{}l=p},"replaceOwn"),u=null,d=s(p=>{if(u!==null&&u!==p)try{Eu(u)}catch{}u=p},"replaceWork");return{write(p,f){try{if(typeof p!="object"||p===null)return;let m=p;if(m.ok!==!0)return;let h={v:1,written_at:new Date(a()).toISOString(),project_key:e.projectKey,own_session_id:f.sessionId,own_pid:r,own_ppid:o,cwd:i,branch:f.branch,peers:Array.isArray(m.peers)?m.peers:[],conflicts:Array.isArray(m.conflicts)?m.conflicts:[],...(()=>{let b=hc(m.assigned_to_you);return b.length>0?{assigned_to_you:b}:{}})(),bound_objects:va(m.bound_objects),...f.branchObjectId?{branch_object_id:f.branchObjectId}:{}};Xg(n,{recursive:!0,mode:448});let y=fo(n,`${f.sessionId}.json`),_=`${y}.tmp-${r}`;Qg(_,JSON.stringify(h),{mode:384}),Zg(_,y),c(y),ey(n,a(),y)}catch{}},endSession(){try{l&&Eu(l)}catch{}d(null)},writeWork(p,f){try{if(typeof p!="object"||p===null)return;let m=p,h=typeof m.project_key=="string"&&/^[a-f0-9]{64}$/.test(m.project_key)?m.project_key:null;if(h===null||h===e.projectKey)return;let y={v:1,written_at:new Date(a()).toISOString(),project_key:h,own_session_id:f.sessionId,own_pid:r,own_ppid:o,cwd:i,branch:f.branch,peers:Array.isArray(m.peers)?m.peers:[],conflicts:[]},_=ty(t,h);Xg(_,{recursive:!0,mode:448});let b=fo(_,`${f.sessionId}.json`),k=`${b}.tmp-${r}`;Qg(k,JSON.stringify(y),{mode:384}),Zg(k,b),d(b),ey(_,a(),b)}catch{}},clearWork(){d(null)},markFailed(p,f){try{let m={v:1,written_at:new Date(a()).toISOString(),project_key:e.projectKey,own_session_id:f.sessionId,own_pid:r,own_ppid:o,cwd:i,branch:f.branch,peers:[],conflicts:[],announce_error:p};Xg(n,{recursive:!0,mode:448});let h=fo(n,`${f.sessionId}.json`),y=`${h}.tmp-${r}`;Qg(y,JSON.stringify(m),{mode:384}),Zg(y,h),c(h),ey(n,a(),h)}catch{}}}}function ey(e,t,n){try{for(let r of c0(e)){if(!r.endsWith(".json"))continue;let o=fo(e,r);if(o!==n)try{t-U2(o).mtimeMs>G2&&Eu(o)}catch{}}}catch{}}function Lt(e,t=u0()){try{let n=ty(t,e),r=[];for(let o of c0(n))if(o.endsWith(".json"))try{let i=JSON.parse(H2(fo(n,o),"utf8")),a=W2(i);a&&r.push(a)}catch{}return r.sort((o,i)=>i.written_at.localeCompare(o.written_at)),r}catch{return[]}}function W2(e){if(typeof e!="object"||e===null)return null;let t=e;return t.v!==1||typeof t.written_at!="string"||typeof t.project_key!="string"||typeof t.own_session_id!="string"||typeof t.own_pid!="number"||typeof t.own_ppid!="number"||typeof t.cwd!="string"?null:{v:1,written_at:t.written_at,project_key:t.project_key,own_session_id:t.own_session_id,own_pid:t.own_pid,own_ppid:t.own_ppid,cwd:t.cwd,branch:typeof t.branch=="string"?t.branch:null,peers:Array.isArray(t.peers)?t.peers:[],conflicts:Array.isArray(t.conflicts)?t.conflicts:[],...typeof t.announce_error=="string"?{announce_error:t.announce_error}:{},...(()=>{let n=hc(t.assigned_to_you);return n.length>0?{assigned_to_you:n}:{}})(),...Array.isArray(t.bound_objects)?{bound_objects:va(t.bound_objects)}:{},...typeof t.branch_object_id=="string"?{branch_object_id:t.branch_object_id}:{}}}var G2,mo=w(()=>{"use strict";po();Gs();G2=120*6e4;s(u0,"presenceSnapshotBaseDir");s(ty,"projectDir");s(d0,"createSnapshotStore");s(ey,"pruneStale");s(Lt,"readSnapshots");s(W2,"parseSnapshot")});function p0(e,t){return e===t||e===""||t===""?!0:e.startsWith(t+"/")||t.startsWith(e+"/")}function m0(e,t){let n=[];for(let r of e.peers){if(typeof r!="object"||r===null)continue;let o=r,i=Array.isArray(o.active_claims)?o.active_claims:[],a=[];for(let l of i){if(typeof l!="object"||l===null)continue;let c=l;if(typeof c.path_prefix!="string"||typeof c.project_key=="string"&&c.project_key!==e.project_key)continue;let d=(typeof c.expires_in_seconds=="number"?c.expires_in_seconds:0)-t;d<=0||a.push({path_prefix:c.path_prefix,note:typeof c.note=="string"?c.note:null,remaining_seconds:Math.round(d)})}n.push({session_id_short:typeof o.session_id_short=="string"?o.session_id_short:"?",is_own_user:o.is_own_user===!0,branch:typeof o.branch=="string"?o.branch:null,focus:typeof o.focus=="string"?o.focus:null,title:typeof o.title=="string"?o.title:null,bound_objects:Array.isArray(o.bound_objects)?o.bound_objects.flatMap(l=>{if(typeof l!="object"||l===null)return[];let c=l;return typeof c.key=="string"?[{key:c.key,title:typeof c.title=="string"?c.title:null}]:[]}):[],machine_label:typeof o.machine_label=="string"?o.machine_label:null,last_seen_seconds:typeof o.last_seen_seconds=="number"?o.last_seen_seconds:0,claims:a,working_paths:Array.isArray(o.working_paths)&&!(typeof o.working_paths_project_key=="string"&&o.working_paths_project_key!==e.project_key)?o.working_paths.filter(l=>typeof l=="string"):[]})}return n}function An(e,t){if(t.hostPids.length>0){let r=e.find(o=>t.hostPids.includes(o.own_ppid));if(r)return{snap:r,via:"ppid"}}let n=e.find(r=>r.cwd===t.cwd);return n?{snap:n,via:"cwd"}:null}function Ii(e){return e<90?`${Math.max(1,Math.round(e))}s`:`${Math.round(e/60)}m`}function h0(e,t,n){let r=n.maxAgeMs??f0,o=n.nowMs-Date.parse(e.written_at);if(!Number.isFinite(o)||o<0||o>r)return null;let i=o/1e3,a=m0(e,i),l=[];for(let c of a)if(!(n.via==="cwd"&&(n.currentBranch===null||c.branch===null||c.branch===n.currentBranch))){for(let u of c.claims)p0(t,u.path_prefix)&&l.push(`'${u.path_prefix}' is CLAIMED by peer session ${c.session_id_short}${c.branch?` (branch ${c.branch}`:" ("}${c.machine_label?`, ${c.machine_label}`:""}${c.focus?`, focus: "${c.focus}"`:""}, last seen ${Ii(c.last_seen_seconds+i)} ago)${u.note?` \u2014 note: "${u.note}"`:""}, claim expires in ${Ii(u.remaining_seconds)}`);if(n.via==="ppid"&&c.is_own_user){for(let u of c.working_paths)if(p0(t,u)){l.push(`'${u}' has recent changes by your own peer session ${c.session_id_short}${c.branch?` (branch ${c.branch})`:""}, last seen ${Ii(c.last_seen_seconds+i)} ago`);break}}}return l.length===0?null:`[maind coordination] Editing '${t}' overlaps parallel work (view as of ${Ii(i)} ago, advisory \u2014 never a lock):
854
854
  `+l.map(c=>` \u2022 ${c}`).join(`