@maind-dev/mcp-bridge 0.121.1 → 0.122.0
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 +3 -3
- package/build/meta.json +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -151,7 +151,7 @@ ${o}`};return JSON.stringify({jsonrpc:"2.0",id:e,result:i})}function hG(e,t){ret
|
|
|
151
151
|
`),null}async function UG(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 BG(e){return new Promise(t=>setTimeout(t,e))}function GG(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: ${dA(e.verification_uri,56)} \u2502`,` \u2502 Code: ${dA(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(`
|
|
152
152
|
`)+`
|
|
153
153
|
`)}function dA(e,t){return e.length>=t?e.slice(0,t):e+" ".repeat(t-e.length)}async function KG(e){let t,n;switch(HG()){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=FG(t,n,{stdio:"ignore",detached:!0});i.on("error",o),i.unref(),r()}catch(i){o(i)}})}var Bh=w(()=>{"use strict";ke();hi();s(gi,"runDeviceFlow");s(UG,"pollOnce");s(BG,"sleep");s(GG,"printAuthInstructions");s(dA,"pad");s(KG,"openExternalBrowser")});import{mkdirSync as WG,readFileSync as VG,renameSync as qG,writeFileSync as zG}from"node:fs";import{join as JG}from"node:path";function pA(e=Ht()){return JG(e,XG)}function QG(e){return e.replace(/mnd_[a-f0-9]{8}_[a-f0-9]{56}/gi,"mnd_\u2026").slice(0,ZG)}function co(e,t,n){try{let r=n.dir??Ht();WG(r,{recursive:!0,mode:448});let o={v:1,at:(n.now??new Date).toISOString(),outcome:e,detail:t===null?null:QG(t),bridge_version:n.version},i=pA(r),a=`${i}.${process.pid}.tmp`;zG(a,JSON.stringify(o)+`
|
|
154
|
-
`,{encoding:"utf8",mode:384}),qG(a,i)}catch{}}function fA(e=Ht()){try{let t=JSON.parse(VG(pA(e),"utf8"));return t.v!==1||typeof t.at!="string"||!YG.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 YG,XG,ZG,Gh=w(()=>{"use strict";ke();YG=["ok","paired","auth_failed","not_paired"],XG="connection-state.json",ZG=200;s(pA,"connectionStatePath");s(QG,"redactDetail");s(co,"writeConnectionState");s(fA,"readConnectionState")});var K,ze=w(()=>{"use strict";K="0.121.1"});import{execFileSync as mA}from"node:child_process";import{createHash as eK}from"node:crypto";function Kh(e){return eK("sha256").update(e).digest("hex")}function Wh(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 Zn(e){let t=Wh(e);return t?Kh(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&tK.test(e))return e;let t;try{t=mA("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Zn(t):null}function rt(e){let t;try{t=mA("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Zn(t):null}var tK,_e=w(()=>{"use strict";s(Kh,"sha256Hex");s(Wh,"normalizeRemoteUrl");s(Zn,"projectKeyFromRemote");tK=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(rt,"projectKeyForRepo")});import nK from"node:path";import{fileURLToPath as rK}from"node:url";function oK(e,t=nK.sep){return e.split(t).includes("_npx")}function xe(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",gA,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):oK(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 ae(){try{let e=rK(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function ot(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${hA(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:hA(n)).join(" ")}function At(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(gA)}function Bc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function hA(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var gA,mt=w(()=>{"use strict";gA="@maind-dev/mcp-bridge";s(oK,"isEphemeralEntry");s(xe,"resolveBridgeLaunch");s(ae,"currentBridgeEntry");s(ot,"launchToShellCommand");s(At,"isNpxForm");s(Bc,"isLegacyHookForm");s(hA,"shellQuote")});import{readFileSync as iK}from"node:fs";import*as H from"node:path";function bA(e){let t=e.launch??xe({entryPath:ae(),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 wA(e){return Vc(e,"Claude")}function aK(e){return H.join(wA(e),kA)}function Vc(e,t){switch(e.platform){case"darwin":return H.join(e.homeDir,"Library","Application Support",t);case"win32":{let n=e.appData??H.join(e.homeDir,"AppData","Roaming");return H.join(n,t)}default:{let n=e.xdgConfigHome??H.join(e.homeDir,".config");return H.join(n,t)}}}function lK(e){return H.join(Vc(e,"Code"),"User")}function Kc(e,t,n=[]){return{kind:"foreign-entries",dir:Vc(e,t),ours:["User",...n]}}function yA(e){return e.localAppData??H.join(e.homeDir,"AppData","Local")}function uK(e){let t=[{kind:"foreign-entries",dir:wA(e),ours:[kA]}];return e.platform==="darwin"?t.push({kind:"dir",path:H.join("/Applications","Claude.app")},{kind:"dir",path:H.join(e.homeDir,"Applications","Claude.app")}):e.platform==="win32"&&t.push({kind:"dir",path:H.join(yA(e),"AnthropicClaude")},{kind:"dir",path:H.join(yA(e),"Packages",cK)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function Tn(e){return{evidence:[Kc(e,"Cursor"),{kind:"foreign-entries",dir:H.join(e.homeDir,".cursor"),ours:["mcp.json","hooks.json"]}],skipDetail:"Cursor not found (no Cursor app data, nothing of Cursor's in ~/.cursor)"}}function vA(e){if(e.platform==="win32"){let t=e.appData??H.join(e.homeDir,"AppData","Roaming");return H.join(t,"devin")}return H.join(e.xdgConfigHome??H.join(e.homeDir,".config"),"devin")}function dK(e){return H.join(vA(e),"mcp_config.json")}function SA(e){return H.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function Wc(e){let t=[Kc(e,"Devin",["mcp_config.json"]),{kind:"dir",path:H.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:vA(e),ours:["mcp_config.json"]}),t.push(Kc(e,"Windsurf"),{kind:"foreign-entries",dir:H.dirname(SA(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 gK(e){return e===null?null:hK.exec(e)?.[1]??null}function EA(e,t){let n=xA.map(r=>H.join(e.homeDir,r.dataFolder,"extensions"));if(e.bundleAppRoot&&n.push(H.join(e.bundleAppRoot,"extensions")),e.platform==="darwin")for(let r of mK)for(let o of["/Applications",H.join(e.homeDir,"Applications")])n.push(H.join(o,`${r}.app`,"Contents","Resources","app","extensions"));return[...new Set(n)].map(r=>({kind:"extension",dir:r,id:t}))}function TA(e){return e.clineDataDir?e.clineDataDir:H.join(e.clineDir??H.join(e.homeDir,".cline"),"data")}function yK(e){return e.clineMcpSettingsPath??H.join(TA(e),"settings","cline_mcp_settings.json")}function Vh(e){return{evidence:[{kind:"foreign-entries",dir:TA(e),ours:["settings"]},...pK.map(t=>({kind:"dir",path:H.join(Vc(e,t),"User","globalStorage",_A)})),...EA(e,_A)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function qc(e){return e.continueGlobalDir??H.join(e.homeDir,".continue")}function _K(e){return H.join(qc(e),"mcpServers","maind.json")}function qh(e){return{evidence:[{kind:"foreign-entries",dir:qc(e),ours:["mcpServers","rules"]},...EA(e,fK)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function Qn(e){return e.codexHome??H.join(e.homeDir,".codex")}function uo(e){return H.join(Qn(e),"config.toml")}function _i(e){let t=Qn(e),n=H.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 AA(e){return H.join(e.geminiCliHome??e.homeDir,".gemini")}function bi(e){return H.join(AA(e),"settings.json")}function ki(e){let t=AA(e),n=H.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 oa(e){return{evidence:[Kc(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function bK(e){return H.join(lK(e),"mcp.json")}function ia(e){return[{key:"claude-code-project",label:"Claude Code (project-scoped .mcp.json)",clientFamilyEnv:"claude-code",scope:"project",path:H.join(e.projectRoot,".mcp.json"),kind:"json"},{key:"claude-code-user",label:"Claude Code (user-scoped ~/.claude.json)",clientFamilyEnv:"claude-code",scope:"user",path:H.join(e.homeDir,".claude.json"),kind:"json"},{key:"claude-desktop",label:"Claude Desktop",clientFamilyEnv:"claude-desktop",scope:"user",path:aK(e),kind:"json",presence:uK(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:H.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:Tn(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:dK(e),kind:"json",presence:Wc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:SA(e),kind:"json",presence:Wc(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:bK(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:oa(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:yK(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:Vh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:_K(e),kind:"json",presence:qh(e)},{key:"gemini-cli",label:"Gemini CLI (~/.gemini/settings.json)",clientFamilyEnv:"gemini-cli",scope:"user",path:bi(e),kind:"json",presence:ki(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:uo(e),kind:"toml",presence:_i(e)}]}function RA(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function CA(e){return e.jsonShape??sK}function IA(e){let{homeDir:t,platform:n,env:r}=e,o=H.join(t,"Documents");if(n==="win32"){let c=["OneDrive","OneDriveConsumer","OneDriveCommercial"].map(u=>r[u]?.trim()).filter(u=>typeof u=="string"&&u.length>0&&H.win32.isAbsolute(u)).map(u=>H.join(u,"Documents"));return[...new Set([o,...c])]}if(n==="darwin")return[o];let i=r.XDG_CONFIG_HOME?.trim()||H.join(t,".config"),a=e.readText?.(H.join(i,"user-dirs.dirs"))??null,l=a===null?null:NA(a,t);return l!==null&&l!==o?[l,o]:[o]}function NA(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 H.isAbsolute(o)&&o.length>1?H.normalize(o):null}return null}function An(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:Gc(e.env.XDG_CONFIG_HOME),appData:Gc(e.env.APPDATA),localAppData:Gc(e.env.LOCALAPPDATA),clineDir:yi(e.env.CLINE_DIR),clineDataDir:yi(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:yi(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:yi(e.env.CONTINUE_GLOBAL_DIR),codexHome:yi(e.env.CODEX_HOME),geminiCliHome:yi(e.env.GEMINI_CLI_HOME),bundleAppRoot:gK(e.bridgeEntry??null),documentsDirs:IA({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return iK(t,"utf8")}catch{return null}},"readText")})}}function Gc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function yi(e){let t=Gc(e);return t!==null&&H.isAbsolute(t)?t:null}var sK,kA,cK,xA,pK,_A,fK,mK,hK,zh,Je=w(()=>{"use strict";mt();sK={serversKey:"mcpServers"};s(bA,"buildMaindServerEntry");kA="claude_desktop_config.json";s(wA,"claudeDesktopAppDataDir");s(aK,"claudeDesktopConfigPath");s(Vc,"editorAppDataDir");s(lK,"vsCodeUserDir");s(Kc,"editorRan");s(yA,"localAppDataDir");cK="Claude_pzs8sxrjxfjjc";s(uK,"claudeDesktopPresence");s(Tn,"cursorPresence");s(vA,"devinConfigDir");s(dK,"devinMcpConfigPath");s(SA,"windsurfLegacyMcpConfigPath");s(Wc,"devinDesktopPresence");xA=[{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"}],pK=xA.map(e=>e.appData),_A="saoudrizwan.claude-dev",fK="continue.continue",mK=["AgentComposer"],hK=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(gK,"bundleAppRootOf");s(EA,"agentExtensionEvidence");s(TA,"clineDataDir");s(yK,"clineMcpSettingsPath");s(Vh,"clinePresence");s(qc,"continueGlobalDir");s(_K,"continueMcpConfigPath");s(qh,"continuePresence");s(Qn,"codexHomeDir");s(uo,"codexConfigPath");s(_i,"codexPresence");s(AA,"geminiDir");s(bi,"geminiSettingsPath");s(ki,"geminiPresence");s(oa,"vsCodePresence");s(bK,"vsCodeUserMcpPath");s(ia,"getClientTargets");s(RA,"filterTargetsByFamily");s(CA,"jsonShapeOf");zh=[...new Set(ia({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(IA,"documentsDirCandidates");s(NA,"parseXdgDocumentsDir");s(An,"makeDefaultContext");s(Gc,"nonEmpty");s(yi,"absoluteOrNull")});function Jh(){return zh.map(e=>{let t=Object.keys(zc).filter(n=>zc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function OA(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(kK),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 Rt("--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 Rt("--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 Rt("--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 Rt("--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 Rt(`--client requires a family argument (${Jh()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(zc,i)?zc[i]:i;if(!zh.includes(a))throw new Rt(`--client "${o}" is not a known client family. Known: ${Jh()}`);t.client=a,n++;break}default:throw new Rt(`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 Rt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function DA(){process.stdout.write(wK())}function wK(){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:",` ${Jh()}`," (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(`
|
|
154
|
+
`,{encoding:"utf8",mode:384}),qG(a,i)}catch{}}function fA(e=Ht()){try{let t=JSON.parse(VG(pA(e),"utf8"));return t.v!==1||typeof t.at!="string"||!YG.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 YG,XG,ZG,Gh=w(()=>{"use strict";ke();YG=["ok","paired","auth_failed","not_paired"],XG="connection-state.json",ZG=200;s(pA,"connectionStatePath");s(QG,"redactDetail");s(co,"writeConnectionState");s(fA,"readConnectionState")});var K,ze=w(()=>{"use strict";K="0.122.0"});import{execFileSync as mA}from"node:child_process";import{createHash as eK}from"node:crypto";function Kh(e){return eK("sha256").update(e).digest("hex")}function Wh(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 Zn(e){let t=Wh(e);return t?Kh(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&tK.test(e))return e;let t;try{t=mA("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Zn(t):null}function rt(e){let t;try{t=mA("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Zn(t):null}var tK,_e=w(()=>{"use strict";s(Kh,"sha256Hex");s(Wh,"normalizeRemoteUrl");s(Zn,"projectKeyFromRemote");tK=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(rt,"projectKeyForRepo")});import nK from"node:path";import{fileURLToPath as rK}from"node:url";function oK(e,t=nK.sep){return e.split(t).includes("_npx")}function xe(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",gA,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):oK(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 ae(){try{let e=rK(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function ot(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${hA(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:hA(n)).join(" ")}function At(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(gA)}function Bc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function hA(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var gA,mt=w(()=>{"use strict";gA="@maind-dev/mcp-bridge";s(oK,"isEphemeralEntry");s(xe,"resolveBridgeLaunch");s(ae,"currentBridgeEntry");s(ot,"launchToShellCommand");s(At,"isNpxForm");s(Bc,"isLegacyHookForm");s(hA,"shellQuote")});import{readFileSync as iK}from"node:fs";import*as H from"node:path";function bA(e){let t=e.launch??xe({entryPath:ae(),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 wA(e){return Vc(e,"Claude")}function aK(e){return H.join(wA(e),kA)}function Vc(e,t){switch(e.platform){case"darwin":return H.join(e.homeDir,"Library","Application Support",t);case"win32":{let n=e.appData??H.join(e.homeDir,"AppData","Roaming");return H.join(n,t)}default:{let n=e.xdgConfigHome??H.join(e.homeDir,".config");return H.join(n,t)}}}function lK(e){return H.join(Vc(e,"Code"),"User")}function Kc(e,t,n=[]){return{kind:"foreign-entries",dir:Vc(e,t),ours:["User",...n]}}function yA(e){return e.localAppData??H.join(e.homeDir,"AppData","Local")}function uK(e){let t=[{kind:"foreign-entries",dir:wA(e),ours:[kA]}];return e.platform==="darwin"?t.push({kind:"dir",path:H.join("/Applications","Claude.app")},{kind:"dir",path:H.join(e.homeDir,"Applications","Claude.app")}):e.platform==="win32"&&t.push({kind:"dir",path:H.join(yA(e),"AnthropicClaude")},{kind:"dir",path:H.join(yA(e),"Packages",cK)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function Tn(e){return{evidence:[Kc(e,"Cursor"),{kind:"foreign-entries",dir:H.join(e.homeDir,".cursor"),ours:["mcp.json","hooks.json"]}],skipDetail:"Cursor not found (no Cursor app data, nothing of Cursor's in ~/.cursor)"}}function vA(e){if(e.platform==="win32"){let t=e.appData??H.join(e.homeDir,"AppData","Roaming");return H.join(t,"devin")}return H.join(e.xdgConfigHome??H.join(e.homeDir,".config"),"devin")}function dK(e){return H.join(vA(e),"mcp_config.json")}function SA(e){return H.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function Wc(e){let t=[Kc(e,"Devin",["mcp_config.json"]),{kind:"dir",path:H.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:vA(e),ours:["mcp_config.json"]}),t.push(Kc(e,"Windsurf"),{kind:"foreign-entries",dir:H.dirname(SA(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 gK(e){return e===null?null:hK.exec(e)?.[1]??null}function EA(e,t){let n=xA.map(r=>H.join(e.homeDir,r.dataFolder,"extensions"));if(e.bundleAppRoot&&n.push(H.join(e.bundleAppRoot,"extensions")),e.platform==="darwin")for(let r of mK)for(let o of["/Applications",H.join(e.homeDir,"Applications")])n.push(H.join(o,`${r}.app`,"Contents","Resources","app","extensions"));return[...new Set(n)].map(r=>({kind:"extension",dir:r,id:t}))}function TA(e){return e.clineDataDir?e.clineDataDir:H.join(e.clineDir??H.join(e.homeDir,".cline"),"data")}function yK(e){return e.clineMcpSettingsPath??H.join(TA(e),"settings","cline_mcp_settings.json")}function Vh(e){return{evidence:[{kind:"foreign-entries",dir:TA(e),ours:["settings"]},...pK.map(t=>({kind:"dir",path:H.join(Vc(e,t),"User","globalStorage",_A)})),...EA(e,_A)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function qc(e){return e.continueGlobalDir??H.join(e.homeDir,".continue")}function _K(e){return H.join(qc(e),"mcpServers","maind.json")}function qh(e){return{evidence:[{kind:"foreign-entries",dir:qc(e),ours:["mcpServers","rules"]},...EA(e,fK)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function Qn(e){return e.codexHome??H.join(e.homeDir,".codex")}function uo(e){return H.join(Qn(e),"config.toml")}function _i(e){let t=Qn(e),n=H.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 AA(e){return H.join(e.geminiCliHome??e.homeDir,".gemini")}function bi(e){return H.join(AA(e),"settings.json")}function ki(e){let t=AA(e),n=H.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 oa(e){return{evidence:[Kc(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function bK(e){return H.join(lK(e),"mcp.json")}function ia(e){return[{key:"claude-code-project",label:"Claude Code (project-scoped .mcp.json)",clientFamilyEnv:"claude-code",scope:"project",path:H.join(e.projectRoot,".mcp.json"),kind:"json"},{key:"claude-code-user",label:"Claude Code (user-scoped ~/.claude.json)",clientFamilyEnv:"claude-code",scope:"user",path:H.join(e.homeDir,".claude.json"),kind:"json"},{key:"claude-desktop",label:"Claude Desktop",clientFamilyEnv:"claude-desktop",scope:"user",path:aK(e),kind:"json",presence:uK(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:H.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:Tn(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:dK(e),kind:"json",presence:Wc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:SA(e),kind:"json",presence:Wc(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:bK(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:oa(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:yK(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:Vh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:_K(e),kind:"json",presence:qh(e)},{key:"gemini-cli",label:"Gemini CLI (~/.gemini/settings.json)",clientFamilyEnv:"gemini-cli",scope:"user",path:bi(e),kind:"json",presence:ki(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:uo(e),kind:"toml",presence:_i(e)}]}function RA(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function CA(e){return e.jsonShape??sK}function IA(e){let{homeDir:t,platform:n,env:r}=e,o=H.join(t,"Documents");if(n==="win32"){let c=["OneDrive","OneDriveConsumer","OneDriveCommercial"].map(u=>r[u]?.trim()).filter(u=>typeof u=="string"&&u.length>0&&H.win32.isAbsolute(u)).map(u=>H.join(u,"Documents"));return[...new Set([o,...c])]}if(n==="darwin")return[o];let i=r.XDG_CONFIG_HOME?.trim()||H.join(t,".config"),a=e.readText?.(H.join(i,"user-dirs.dirs"))??null,l=a===null?null:NA(a,t);return l!==null&&l!==o?[l,o]:[o]}function NA(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 H.isAbsolute(o)&&o.length>1?H.normalize(o):null}return null}function An(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:Gc(e.env.XDG_CONFIG_HOME),appData:Gc(e.env.APPDATA),localAppData:Gc(e.env.LOCALAPPDATA),clineDir:yi(e.env.CLINE_DIR),clineDataDir:yi(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:yi(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:yi(e.env.CONTINUE_GLOBAL_DIR),codexHome:yi(e.env.CODEX_HOME),geminiCliHome:yi(e.env.GEMINI_CLI_HOME),bundleAppRoot:gK(e.bridgeEntry??null),documentsDirs:IA({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return iK(t,"utf8")}catch{return null}},"readText")})}}function Gc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function yi(e){let t=Gc(e);return t!==null&&H.isAbsolute(t)?t:null}var sK,kA,cK,xA,pK,_A,fK,mK,hK,zh,Je=w(()=>{"use strict";mt();sK={serversKey:"mcpServers"};s(bA,"buildMaindServerEntry");kA="claude_desktop_config.json";s(wA,"claudeDesktopAppDataDir");s(aK,"claudeDesktopConfigPath");s(Vc,"editorAppDataDir");s(lK,"vsCodeUserDir");s(Kc,"editorRan");s(yA,"localAppDataDir");cK="Claude_pzs8sxrjxfjjc";s(uK,"claudeDesktopPresence");s(Tn,"cursorPresence");s(vA,"devinConfigDir");s(dK,"devinMcpConfigPath");s(SA,"windsurfLegacyMcpConfigPath");s(Wc,"devinDesktopPresence");xA=[{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"}],pK=xA.map(e=>e.appData),_A="saoudrizwan.claude-dev",fK="continue.continue",mK=["AgentComposer"],hK=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(gK,"bundleAppRootOf");s(EA,"agentExtensionEvidence");s(TA,"clineDataDir");s(yK,"clineMcpSettingsPath");s(Vh,"clinePresence");s(qc,"continueGlobalDir");s(_K,"continueMcpConfigPath");s(qh,"continuePresence");s(Qn,"codexHomeDir");s(uo,"codexConfigPath");s(_i,"codexPresence");s(AA,"geminiDir");s(bi,"geminiSettingsPath");s(ki,"geminiPresence");s(oa,"vsCodePresence");s(bK,"vsCodeUserMcpPath");s(ia,"getClientTargets");s(RA,"filterTargetsByFamily");s(CA,"jsonShapeOf");zh=[...new Set(ia({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(IA,"documentsDirCandidates");s(NA,"parseXdgDocumentsDir");s(An,"makeDefaultContext");s(Gc,"nonEmpty");s(yi,"absoluteOrNull")});function Jh(){return zh.map(e=>{let t=Object.keys(zc).filter(n=>zc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function OA(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(kK),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 Rt("--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 Rt("--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 Rt("--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 Rt("--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 Rt(`--client requires a family argument (${Jh()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(zc,i)?zc[i]:i;if(!zh.includes(a))throw new Rt(`--client "${o}" is not a known client family. Known: ${Jh()}`);t.client=a,n++;break}default:throw new Rt(`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 Rt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function DA(){process.stdout.write(wK())}function wK(){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:",` ${Jh()}`," (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(`
|
|
155
155
|
`)}var zc,kK,Rt,PA=w(()=>{"use strict";Je();zc={devin:"windsurf"};s(Jh,"familyChoices");kK="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(OA,"parseInstallFlags");Rt=class extends Error{static{s(this,"InstallFlagError")}constructor(t){super(t),this.name="InstallFlagError"}};s(DA,"printInstallHelp");s(wK,"installHelpText")});var sa,MA=w(()=>{"use strict";sa=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_
|
|
156
156
|
`;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(`
|
|
157
157
|
`)+`
|
|
@@ -1231,12 +1231,12 @@ maind: sessions that are already running pick it up when their bridge restarts (
|
|
|
1231
1231
|
`)+`
|
|
1232
1232
|
`}var BZ,kk,yL=w(()=>{"use strict";dr();_e();Wb();vo();BZ=120*6e4,kk="A Claude Code session bound to exactly one work object then reports what its agent does to that object's activity panel: the todo list as the plan, actions as category counts (read, edit, run, test, search, git, web, other), its questions to you and its answers. Never paths, commands, file contents or tool output; the agent's own words only when your organization sets agent_activity_text = on.";s(GZ,"runActivity");s(hL,"statusText")});var Ak={};ee(Ak,{MAX_ENTRIES:()=>wk,TTL_MS:()=>xk,crossSessionDir:()=>Ek,decideCrossSession:()=>kL,parseSessionDb:()=>bL,pruneDb:()=>Tk,runGuardCrossCheck:()=>ZZ,runGuardCrossObserve:()=>XZ,staleReason:()=>vk});import{mkdir as KZ,readFile as WZ,readdir as VZ,stat as _L,unlink as qZ,writeFile as zZ}from"node:fs/promises";import{homedir as JZ}from"node:os";import{join as Sk}from"node:path";function Ek(){return Sk(JZ(),".maind","cross-session")}function bL(e){let t={files:{},warned:{}};if(typeof e!="object"||e===null)return t;let n=e,r={};if(typeof n.files=="object"&&n.files!==null)for(let[i,a]of Object.entries(n.files)){if(typeof a!="object"||a===null)continue;let l=a;typeof l.m!="number"||typeof l.t!="number"||!Number.isFinite(l.m)||!Number.isFinite(l.t)||(r[i]={m:l.m,t:l.t})}let o={};if(typeof n.warned=="object"&&n.warned!==null)for(let[i,a]of Object.entries(n.warned))typeof a=="number"&&Number.isFinite(a)&&(o[i]=a);return{files:r,warned:o}}function Tk(e,t){let n=Object.entries(e.files).filter(([,r])=>t-r.t<=xk);return n.length>wk&&(n=n.sort((r,o)=>r[1].t-o[1].t).slice(n.length-wk)),{files:Object.fromEntries(n),warned:e.warned}}function kL(e,t){return e===void 0||t===void 0?{kind:"allow"}:t>e?{kind:"stale",baseline:e,current:t}:{kind:"allow"}}function vk(e,t){return`Cross-session guard: '${e}' changed on disk after this session last read it (mtime ${Math.floor(t.current/1e3)} > recorded ${Math.floor(t.baseline/1e3)}). Likely a parallel session, an editor, or git (checkout/pull). Re-read the file, reconcile with the external change, then retry.`}async function wL(e){let t=Ek();return await KZ(t,{recursive:!0}),Sk(t,`${e}.json`)}async function vL(e,t){try{let n=await WZ(await wL(e),"utf8");return Tk(bL(JSON.parse(n)),t)}catch{return{files:{},warned:{}}}}async function SL(e,t){try{await zZ(await wL(e),JSON.stringify(t),{mode:384})}catch{}}async function YZ(e){try{let t=Ek();for(let n of await VZ(t)){if(!n.endsWith(".json"))continue;let r=Sk(t,n),o=await _L(r).catch(()=>null);o&&e-o.mtimeMs>xk&&await qZ(r).catch(()=>{})}}catch{}}async function xL(e){try{return(await _L(e)).mtimeMs}catch{return}}async function XZ(e,t=Date.now()){try{if(ve().mode==="off")return 0;let r=e??await ge();if(Le(r))return 0;let o=typeof r.session_id=="string"?r.session_id:"",i=ky(r);if(!o||!i)return 0;let a=await xL(i);if(a===void 0)return 0;let l=await vL(o,t);return l.files[i]={m:a,t},delete l.warned[i],await SL(o,Tk(l,t)),await YZ(t),0}catch{return 0}}async function ZZ(e,t=Date.now()){try{let n=ve();if(n.mode==="off")return 0;let r=e??await ge();if(Le(r))return 0;let o=typeof r.session_id=="string"?r.session_id:"",i=ky(r);if(!o||!i)return 0;let a=await vL(o,t),l=kL(a.files[i]?.m,await xL(i));return l.kind==="allow"?0:n.mode==="block"?(process.stdout.write(ln(vk(i,l))+`
|
|
1233
1233
|
`),await oe({event:"cross_session_deny",session_id:o,cwd:typeof r.cwd=="string"?r.cwd:void 0,detail:i}),0):(a.warned[i]===l.current||(process.stdout.write(Nn(vk(i,l))+`
|
|
1234
|
-
`),a.warned[i]=l.current,await SL(o,a),await oe({event:"cross_session_warn",session_id:o,cwd:typeof r.cwd=="string"?r.cwd:void 0,detail:i})),0)}catch{return 0}}var xk,wk,Rk=w(()=>{"use strict";Ke();Ie();$i();Vt();cn();xk=48*3600*1e3,wk=500;s(Ek,"crossSessionDir");s(bL,"parseSessionDb");s(Tk,"pruneDb");s(kL,"decideCrossSession");s(vk,"staleReason");s(wL,"dbPath");s(vL,"loadDb");s(SL,"saveDb");s(YZ,"sweepStaleSessionFiles");s(xL,"fileMtime");s(XZ,"runGuardCrossObserve");s(ZZ,"runGuardCrossCheck")});var OL={};ee(OL,{decideDocDutyReminder:()=>AL,decideLocally:()=>Ck,localDocFacts:()=>RL,readServerDocState:()=>NL,reminderStateDir:()=>IL,runDocDutyReminder:()=>u7,workTreeFor:()=>CL});import{execFileSync as QZ}from"node:child_process";import{existsSync as EL,mkdirSync as e7,readdirSync as t7,readFileSync as TL,writeFileSync as n7}from"node:fs";import{homedir as r7}from"node:os";import{join as wl,resolve as o7}from"node:path";function Ck(e){return e.standsDown?{remind:!1,why:"host"}:e.stopHookActive?{remind:!1,why:"stop_hook_active"}:e.object?e.alreadyReminded?{remind:!1,why:"already_reminded"}:e.ownTree?e.hasWork?e.locallySatisfied?{remind:!1,why:"locally_satisfied"}:null:{remind:!1,why:"no_work"}:{remind:!1,why:"no_own_tree"}:{remind:!1,why:"no_object"}}function AL(e){let t=Ck(e);if(t)return t;let n=e.object.key;if(e.server?.finished)return{remind:!1,why:"finished"};if(e.server?.docDuty==="off")return{remind:!1,why:"duty_off"};if(e.server?.heldByOther)return{remind:!1,why:"held_by_other"};if(e.server&&!e.server.docMissing)return{remind:!1,why:"documented_elsewhere"};let r=e.server?.docDuty==="require";return{remind:!0,reason:`[maind] Documentation duty for ${n} is still open: this work has no document that names ${n} and no recorded exception. Before you finish, either add or update a Markdown document (ADR, note, session note) that names ${n}, or \u2014 if none is needed \u2014 put a trailer in a commit: "Doc-Decision: none - <reason>" (or "Doc-Decision: elsewhere - <owner/repo#pr>").`+(r?" This organization requires it: `maind feature promote` refuses to merge without it.":"")+` This reminder comes once per session for ${n}.`}}function Yt(e,t){try{return QZ("git",[...t],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3,maxBuffer:8*1024*1024})}catch{return null}}function i7(e){let t=Yt(e,["symbolic-ref","--quiet","refs/remotes/origin/HEAD"])?.trim(),n=t?[t.replace(/^refs\/remotes\//,"")]:["origin/main","origin/master"];for(let r of n){let o=Yt(e,["merge-base",r,"HEAD"])?.trim();if(o)return o}return null}function RL(e,t){let n=i7(e),r=n?(Yt(e,["-c","core.quotepath=off","diff","--name-only",`${n}`,"HEAD"])??"").split(`
|
|
1234
|
+
`),a.warned[i]=l.current,await SL(o,a),await oe({event:"cross_session_warn",session_id:o,cwd:typeof r.cwd=="string"?r.cwd:void 0,detail:i})),0)}catch{return 0}}var xk,wk,Rk=w(()=>{"use strict";Ke();Ie();$i();Vt();cn();xk=48*3600*1e3,wk=500;s(Ek,"crossSessionDir");s(bL,"parseSessionDb");s(Tk,"pruneDb");s(kL,"decideCrossSession");s(vk,"staleReason");s(wL,"dbPath");s(vL,"loadDb");s(SL,"saveDb");s(YZ,"sweepStaleSessionFiles");s(xL,"fileMtime");s(XZ,"runGuardCrossObserve");s(ZZ,"runGuardCrossCheck")});var OL={};ee(OL,{decideDocDutyReminder:()=>AL,decideLocally:()=>Ck,localDocFacts:()=>RL,readServerDocState:()=>NL,reminderStateDir:()=>IL,runDocDutyReminder:()=>u7,workTreeFor:()=>CL});import{execFileSync as QZ}from"node:child_process";import{existsSync as EL,mkdirSync as e7,readdirSync as t7,readFileSync as TL,writeFileSync as n7}from"node:fs";import{homedir as r7}from"node:os";import{join as wl,resolve as o7}from"node:path";function Ck(e){return e.standsDown?{remind:!1,why:"host"}:e.stopHookActive?{remind:!1,why:"stop_hook_active"}:e.object?e.alreadyReminded?{remind:!1,why:"already_reminded"}:e.ownTree?e.hasWork?e.locallySatisfied?{remind:!1,why:"locally_satisfied"}:null:{remind:!1,why:"no_work"}:{remind:!1,why:"no_own_tree"}:{remind:!1,why:"no_object"}}function AL(e){let t=Ck(e);if(t)return t;let n=e.object.key;if(e.server?.finished)return{remind:!1,why:"finished"};if(e.server?.inReview)return{remind:!1,why:"in_review"};if(e.server?.docDuty==="off")return{remind:!1,why:"duty_off"};if(e.server?.heldByOther)return{remind:!1,why:"held_by_other"};if(e.server&&!e.server.docMissing)return{remind:!1,why:"documented_elsewhere"};let r=e.server?.docDuty==="require";return{remind:!0,reason:`[maind] Documentation duty for ${n} is still open: this work has no document that names ${n} and no recorded exception. Before you finish, either add or update a Markdown document (ADR, note, session note) that names ${n}, or \u2014 if none is needed \u2014 put a trailer in a commit: "Doc-Decision: none - <reason>" (or "Doc-Decision: elsewhere - <owner/repo#pr>").`+(r?" This organization requires it: `maind feature promote` refuses to merge without it.":"")+` This reminder comes once per session for ${n}.`}}function Yt(e,t){try{return QZ("git",[...t],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3,maxBuffer:8*1024*1024})}catch{return null}}function i7(e){let t=Yt(e,["symbolic-ref","--quiet","refs/remotes/origin/HEAD"])?.trim(),n=t?[t.replace(/^refs\/remotes\//,"")]:["origin/main","origin/master"];for(let r of n){let o=Yt(e,["merge-base",r,"HEAD"])?.trim();if(o)return o}return null}function RL(e,t){let n=i7(e),r=n?(Yt(e,["-c","core.quotepath=off","diff","--name-only",`${n}`,"HEAD"])??"").split(`
|
|
1235
1235
|
`):[],i=(Yt(e,["-c","core.quotepath=off","status","--porcelain","--untracked-files=all"])??"").split(`
|
|
1236
1236
|
`).filter(d=>d.length>3).map(d=>d.slice(3).replace(/^.* -> /,"").replace(/^"|"$/g,"")),a=[...new Set([...r,...i].map(d=>d.trim()).filter(Boolean))],l=a.length>0;if(!l)return{hasWork:l,locallySatisfied:!1};if(As(a.filter(Zo),d=>{try{return TL(wl(e,d),"utf8")}catch{return null}},t).length>0)return{hasWork:l,locallySatisfied:!0};let u=n?(Yt(e,["log","--reverse","--format=%B%x00",`${n}..HEAD`])??"").split("\0"):[];return{hasWork:l,locallySatisfied:Rs(u).kind==="ok"}}function CL(e,t){let n=Yt(e,["rev-parse","--show-toplevel"])?.trim();if(!n)return null;let r=Yt(e,["rev-parse","--abbrev-ref","HEAD"])?.trim();if(r&&Yt(e,["config","--get",`branch.${r}.maindObject`])?.trim()===t)return e;let o=new Set;for(let i of[n,...s7(n)]){let a=Yt(i,["rev-parse","--path-format=absolute","--git-common-dir"])?.trim();if(!a||o.has(a))continue;o.add(a);let l=a7(i,t);if(l)return l}return null}function s7(e){try{return t7(e,{withFileTypes:!0}).filter(t=>t.isDirectory()&&!t.name.startsWith(".")&&t.name!=="node_modules").map(t=>wl(e,t.name)).filter(t=>EL(wl(t,".git")))}catch{return[]}}function a7(e,t){let n=Yt(e,["config","--get-regexp","^branch\\..*\\.maindobject$"])??"",r=new Set(n.split(`
|
|
1237
1237
|
`).map(i=>/^branch\.(.+)\.maindobject\s+(\S+)$/.exec(i.trim())).filter(i=>i!==null&&i[2]===t).map(i=>i[1]));if(r.size===0)return null;let o=Yt(e,["worktree","list","--porcelain"])??"";for(let i of o.split(`
|
|
1238
1238
|
|
|
1239
|
-
`)){let a=/^worktree (.+)$/m.exec(i)?.[1],l=/^branch refs\/heads\/(.+)$/m.exec(i)?.[1];if(a&&l&&r.has(l))return o7(a)}return null}function IL(){return wl(r7(),".maind","doc-duty")}function l7(e){return e.replace(/[^A-Za-z0-9._-]/g,"_").slice(0,120)}function c7(e){try{let t=JSON.parse(TL(e,"utf8"));return Array.isArray(t.reminded)?t.reminded.filter(n=>typeof n=="string"):[]}catch{return[]}}function NL(e,t){if(!e)return null;try{let n=JSON.parse(e),o=(Array.isArray(n.resolved)?n.resolved:[]).find(u=>u?.key===t);if(!o)return null;let i=o.doc_duty;if(i!=="off"&&i!=="remind"&&i!=="require")return null;let a=typeof o.take=="object"&&o.take!==null?o.take:null,l=a!==null&&a.state==="held"&&a.by_this_session===!1,c=o.status==="passed"||o.status==="canceled";return{docDuty:i,docMissing:o.doc_missing===!0,...l?{heldByOther:l}:{},...c?{finished:c}:{}}}catch{return null}}async function u7(){try{let e=await ge(),t=typeof e.session_id=="string"&&e.session_id.trim()?e.session_id.trim():null,n=typeof e.cwd=="string"&&e.cwd.trim()?e.cwd:process.cwd(),r=Le(e),o=e.stop_hook_active===!0;if(r||o||t===null)return 0;let i=ne();if(i===null)return 0;let a=fr(an(e)||null,t),l=Wt(_t(i),{hostPids:dt(),cwd:n,selfId:a})?.snap;if(!l||l.announce_error)return 0;let c=Hi({branchObjectId:l.branch_object_id??null,boundObjects:l.bound_objects??null});if(c.objectId===null||!c.key)return 0;let u={id:c.objectId,key:c.key},d=IL(),p=wl(d,`${l7(t)}.json`),f=EL(p)?c7(p):[],m=CL(n,u.id),h=m===null?{hasWork:!1,locallySatisfied:!1}:RL(m,u.key);if(Ck({standsDown:r,stopHookActive:o,object:u,alreadyReminded:f.includes(u.id),ownTree:m!==null,...h}))return 0;let _=Z(),b=_?await qt("get_my_work_objects",{project_key:i,session_id:l.own_session_id,keys:[u.key]},{apiKey:_,deviceId:be(),projectKey:i,bridgeVersion:K,timeoutMs:3e3}):null,k=AL({standsDown:r,stopHookActive:o,object:u,alreadyReminded:!1,ownTree:!0,...h,server:NL(b,u.key)});return k.remind&&(e7(d,{recursive:!0}),n7(p,JSON.stringify({reminded:[...f,u.id]})),process.stdout.write(JSON.stringify({decision:"block",reason:k.reason}))),0}catch{return 0}}var DL=w(()=>{"use strict";kn();vo();ke();Pn();dr();ja();_e();ze();Bi();Ke();Ie();zt();s(Ck,"decideLocally");s(AL,"decideDocDutyReminder");s(Yt,"git");s(i7,"mergeBase");s(RL,"localDocFacts");s(CL,"workTreeFor");s(s7,"nestedCheckouts");s(a7,"boundWorktree");s(IL,"reminderStateDir");s(l7,"safeName");s(c7,"readReminded");s(NL,"readServerDocState");s(u7,"runDocDutyReminder")});import{randomUUID as d7}from"node:crypto";Pe();ea();import{createInterface as yG}from"node:readline";var zB=[["claude-code","claude-code"],["claude-cli","claude-code"],["claude-desktop","claude-desktop"],["claude.app","claude-desktop"],["openai-codex","codex"],["codex-cli","codex"],["codex","codex"],["github-copilot","copilot"],["vscode-copilot","copilot"],["copilot","copilot"],["cursor","cursor"],["windsurf","windsurf"],["codeium","windsurf"],["cline","cline"],["continue","continue"],["gemini-cli","gemini-cli"],["vscode-extension","vscode-extension"],["maind-vscode","vscode-extension"],["mcp-inspector","mcp-inspector"],["maind-cli","maind-cli"],["maind-mcp-bridge","mcp-bridge"]];function JB(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();if(t.length===0)return null;for(let[n,r]of zB)if(t.includes(n))return r;return null}s(JB,"mapClientInfoNameToFamily");function KT(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ah(t)||t.method!=="initialize")return null;let n=t.params;if(!Ah(n))return null;let r=n.clientInfo;if(!Ah(r))return null;let o=r.name,i=JB(typeof o=="string"?o:null);if(i===null)return null;let a=r.version,l=typeof a=="string"&&a.length>0?a.slice(0,64):null;return{family:i,version:l}}s(KT,"tryExtractInitializeClient");function Ah(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(Ah,"isRecord");import{fileURLToPath as YB}from"node:url";var Rh="maind-bridge-",XB=8,WT=8e3;function Yn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(Yn,"isRecord");function ZB(e){if(e===null)return!1;try{let t=JSON.parse(e);if(!Yn(t)||t.method!=="initialize"||!Yn(t.params))return!1;let n=t.params.capabilities;return Yn(n)&&Yn(n.roots)}catch{return!1}}s(ZB,"clientDeclaresRoots");function QB(e){if(!e.includes("notifications/initialized"))return!1;try{let t=JSON.parse(e);return t.method==="notifications/initialized"&&t.id===void 0}catch{return!1}}s(QB,"isInitializedNotification");function eG(e){if(!Yn(e)||!Yn(e.result))return null;let t=e.result.roots;if(!Array.isArray(t))return null;let n=[];for(let r of t){if(!Yn(r)||typeof r.uri!="string"||!r.uri.startsWith("file://"))continue;let o;try{o=YB(r.uri)}catch{continue}if(n.includes(o)||n.push(o),n.length>=XB)break}return n}s(eG,"rootPathsFrom");var Oc=class{constructor(t,n=!1){this.writeLine=t;this.initialized=n}static{s(this,"ClientRequestChannel")}initialized;closed=!1;waiters=[];pending=new Map;seq=0;observe(t){if(t.includes(Rh)){let n;try{n=JSON.parse(t)}catch{n=null}if(Yn(n)&&typeof n.id=="string"&&n.id.startsWith(Rh)&&n.method===void 0)return this.pending.get(n.id)?.settle(n),!0}if(!this.initialized&&QB(t)){this.initialized=!0;for(let n of this.waiters.splice(0))n(!0)}return!1}close(){if(!this.closed){this.closed=!0;for(let t of this.waiters.splice(0))t(!1);for(let t of[...this.pending.values()])t.settle(null)}}async request(t,n=WT){if(this.closed)return null;let r=Date.now()+n;if(!this.initialized&&(!await new Promise(l=>{let c=s(d=>{clearTimeout(u),this.waiters=this.waiters.filter(p=>p!==c),l(d)},"done"),u=setTimeout(()=>c(!1),n);this.waiters.push(c)})||this.closed))return null;let o=`${Rh}${t.replace(/[^a-z]/gi,"-")}-${++this.seq}`,i=new Promise(a=>{let l=s(u=>{clearTimeout(c),this.pending.delete(o),a(u)},"settle"),c=setTimeout(()=>l(null),Math.max(0,r-Date.now()));this.pending.set(o,{settle:l,timer:c})});return this.writeLine(JSON.stringify({jsonrpc:"2.0",id:o,method:t})),i}};async function VT(e,t,n=WT){return ZB(e)?eG(await t.request("roots/list",n)):null}s(VT,"listClientRoots");Oh();Dh();function Ph(e){let t=e.trim();if(t.length===0)return[];if(t.startsWith("{")||t.startsWith("["))try{let i=JSON.parse(t);return Array.isArray(i)?i:[i]}catch{return[]}let n=[],r=[],o=s(()=>{if(r.length===0)return;let i=r.join(`
|
|
1239
|
+
`)){let a=/^worktree (.+)$/m.exec(i)?.[1],l=/^branch refs\/heads\/(.+)$/m.exec(i)?.[1];if(a&&l&&r.has(l))return o7(a)}return null}function IL(){return wl(r7(),".maind","doc-duty")}function l7(e){return e.replace(/[^A-Za-z0-9._-]/g,"_").slice(0,120)}function c7(e){try{let t=JSON.parse(TL(e,"utf8"));return Array.isArray(t.reminded)?t.reminded.filter(n=>typeof n=="string"):[]}catch{return[]}}function NL(e,t){if(!e)return null;try{let n=JSON.parse(e),o=(Array.isArray(n.resolved)?n.resolved:[]).find(u=>u?.key===t);if(!o)return null;let i=o.doc_duty;if(i!=="off"&&i!=="remind"&&i!=="require")return null;let a=typeof o.take=="object"&&o.take!==null?o.take:null,l=a!==null&&a.state==="held"&&a.by_this_session===!1,c=o.status==="passed"||o.status==="canceled";return{docDuty:i,docMissing:o.doc_missing===!0,...l?{heldByOther:l}:{},...c?{finished:c}:{},...o.doc_in_review===!0?{inReview:!0}:{}}}catch{return null}}async function u7(){try{let e=await ge(),t=typeof e.session_id=="string"&&e.session_id.trim()?e.session_id.trim():null,n=typeof e.cwd=="string"&&e.cwd.trim()?e.cwd:process.cwd(),r=Le(e),o=e.stop_hook_active===!0;if(r||o||t===null)return 0;let i=ne();if(i===null)return 0;let a=fr(an(e)||null,t),l=Wt(_t(i),{hostPids:dt(),cwd:n,selfId:a})?.snap;if(!l||l.announce_error)return 0;let c=Hi({branchObjectId:l.branch_object_id??null,boundObjects:l.bound_objects??null});if(c.objectId===null||!c.key)return 0;let u={id:c.objectId,key:c.key},d=IL(),p=wl(d,`${l7(t)}.json`),f=EL(p)?c7(p):[],m=CL(n,u.id),h=m===null?{hasWork:!1,locallySatisfied:!1}:RL(m,u.key);if(Ck({standsDown:r,stopHookActive:o,object:u,alreadyReminded:f.includes(u.id),ownTree:m!==null,...h}))return 0;let _=Z(),b=_?await qt("get_my_work_objects",{project_key:i,session_id:l.own_session_id,keys:[u.key]},{apiKey:_,deviceId:be(),projectKey:i,bridgeVersion:K,timeoutMs:3e3}):null,k=AL({standsDown:r,stopHookActive:o,object:u,alreadyReminded:!1,ownTree:!0,...h,server:NL(b,u.key)});return k.remind&&(e7(d,{recursive:!0}),n7(p,JSON.stringify({reminded:[...f,u.id]})),process.stdout.write(JSON.stringify({decision:"block",reason:k.reason}))),0}catch{return 0}}var DL=w(()=>{"use strict";kn();vo();ke();Pn();dr();ja();_e();ze();Bi();Ke();Ie();zt();s(Ck,"decideLocally");s(AL,"decideDocDutyReminder");s(Yt,"git");s(i7,"mergeBase");s(RL,"localDocFacts");s(CL,"workTreeFor");s(s7,"nestedCheckouts");s(a7,"boundWorktree");s(IL,"reminderStateDir");s(l7,"safeName");s(c7,"readReminded");s(NL,"readServerDocState");s(u7,"runDocDutyReminder")});import{randomUUID as d7}from"node:crypto";Pe();ea();import{createInterface as yG}from"node:readline";var zB=[["claude-code","claude-code"],["claude-cli","claude-code"],["claude-desktop","claude-desktop"],["claude.app","claude-desktop"],["openai-codex","codex"],["codex-cli","codex"],["codex","codex"],["github-copilot","copilot"],["vscode-copilot","copilot"],["copilot","copilot"],["cursor","cursor"],["windsurf","windsurf"],["codeium","windsurf"],["cline","cline"],["continue","continue"],["gemini-cli","gemini-cli"],["vscode-extension","vscode-extension"],["maind-vscode","vscode-extension"],["mcp-inspector","mcp-inspector"],["maind-cli","maind-cli"],["maind-mcp-bridge","mcp-bridge"]];function JB(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();if(t.length===0)return null;for(let[n,r]of zB)if(t.includes(n))return r;return null}s(JB,"mapClientInfoNameToFamily");function KT(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ah(t)||t.method!=="initialize")return null;let n=t.params;if(!Ah(n))return null;let r=n.clientInfo;if(!Ah(r))return null;let o=r.name,i=JB(typeof o=="string"?o:null);if(i===null)return null;let a=r.version,l=typeof a=="string"&&a.length>0?a.slice(0,64):null;return{family:i,version:l}}s(KT,"tryExtractInitializeClient");function Ah(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(Ah,"isRecord");import{fileURLToPath as YB}from"node:url";var Rh="maind-bridge-",XB=8,WT=8e3;function Yn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(Yn,"isRecord");function ZB(e){if(e===null)return!1;try{let t=JSON.parse(e);if(!Yn(t)||t.method!=="initialize"||!Yn(t.params))return!1;let n=t.params.capabilities;return Yn(n)&&Yn(n.roots)}catch{return!1}}s(ZB,"clientDeclaresRoots");function QB(e){if(!e.includes("notifications/initialized"))return!1;try{let t=JSON.parse(e);return t.method==="notifications/initialized"&&t.id===void 0}catch{return!1}}s(QB,"isInitializedNotification");function eG(e){if(!Yn(e)||!Yn(e.result))return null;let t=e.result.roots;if(!Array.isArray(t))return null;let n=[];for(let r of t){if(!Yn(r)||typeof r.uri!="string"||!r.uri.startsWith("file://"))continue;let o;try{o=YB(r.uri)}catch{continue}if(n.includes(o)||n.push(o),n.length>=XB)break}return n}s(eG,"rootPathsFrom");var Oc=class{constructor(t,n=!1){this.writeLine=t;this.initialized=n}static{s(this,"ClientRequestChannel")}initialized;closed=!1;waiters=[];pending=new Map;seq=0;observe(t){if(t.includes(Rh)){let n;try{n=JSON.parse(t)}catch{n=null}if(Yn(n)&&typeof n.id=="string"&&n.id.startsWith(Rh)&&n.method===void 0)return this.pending.get(n.id)?.settle(n),!0}if(!this.initialized&&QB(t)){this.initialized=!0;for(let n of this.waiters.splice(0))n(!0)}return!1}close(){if(!this.closed){this.closed=!0;for(let t of this.waiters.splice(0))t(!1);for(let t of[...this.pending.values()])t.settle(null)}}async request(t,n=WT){if(this.closed)return null;let r=Date.now()+n;if(!this.initialized&&(!await new Promise(l=>{let c=s(d=>{clearTimeout(u),this.waiters=this.waiters.filter(p=>p!==c),l(d)},"done"),u=setTimeout(()=>c(!1),n);this.waiters.push(c)})||this.closed))return null;let o=`${Rh}${t.replace(/[^a-z]/gi,"-")}-${++this.seq}`,i=new Promise(a=>{let l=s(u=>{clearTimeout(c),this.pending.delete(o),a(u)},"settle"),c=setTimeout(()=>l(null),Math.max(0,r-Date.now()));this.pending.set(o,{settle:l,timer:c})});return this.writeLine(JSON.stringify({jsonrpc:"2.0",id:o,method:t})),i}};async function VT(e,t,n=WT){return ZB(e)?eG(await t.request("roots/list",n)):null}s(VT,"listClientRoots");Oh();Dh();function Ph(e){let t=e.trim();if(t.length===0)return[];if(t.startsWith("{")||t.startsWith("["))try{let i=JSON.parse(t);return Array.isArray(i)?i:[i]}catch{return[]}let n=[],r=[],o=s(()=>{if(r.length===0)return;let i=r.join(`
|
|
1240
1240
|
`).trim();if(r=[],i.length!==0)try{n.push(JSON.parse(i))}catch{}},"flush");for(let i of t.split(`
|
|
1241
1241
|
`)){let a=i.endsWith("\r")?i.slice(0,-1):i;if(a===""){o();continue}a.startsWith("data:")&&r.push(a.slice(5).replace(/^\s/,""))}return o(),n}s(Ph,"rpcMessagesOf");function QT(e,t){for(let n of Ph(e)){if(typeof n!="object"||n===null)continue;let r=n;if(r.id!==t)continue;if(typeof r.error=="object"&&r.error!==null){let l=r.error;return{kind:"rpc_error",code:typeof l.code=="number"?l.code:-32603,message:typeof l.message=="string"?l.message:""}}let o=typeof r.result=="object"&&r.result!==null?r.result:{},a=(Array.isArray(o.content)?o.content:[]).find(l=>typeof l=="object"&&l!==null&&l.type==="text"&&typeof l.text=="string");return{kind:"result",isError:o.isError===!0,text:a?.text??""}}return null}s(QT,"parseCloudToolResponse");Ft();var _G="https://mcp.maind.dev/mcp",ta=class extends Error{constructor(n){super(`re-authorization required: ${n}`);this.reason=n;this.name="BridgeReauthNeeded"}static{s(this,"BridgeReauthNeeded")}},Fc=class{static{s(this,"Forwarder")}mcpUrl;apiKey;deviceId;bridgeVersion;clientFamily;clientVersion;clientFamilyLocked;clientVersionLocked;projectKey;nestedProjectKeys;localRouter;presence;onConnectionOutcome;onSessionReady;assignedInbox;connectionOkRecorded=!1;presenceFrameId=0;cloudFrameId=0;sessionId=null;shaRepoRoot;stackHeader;initFrame=null;pendingFrame=null;clientChannel;replayFrame=null;terminated=!1;keyFp;repoRoot=null;constructor(t){this.apiKey=t.apiKey,this.keyFp=Xn(t.apiKey),this.deviceId=t.deviceId,this.bridgeVersion=t.bridgeVersion;let n=t.clientFamily??process.env.MAIND_CLIENT_FAMILY??null;this.clientFamily=bG(n),this.clientFamilyLocked=this.clientFamily!==null;let r=t.clientVersion??process.env.MAIND_CLIENT_VERSION??null;this.clientVersion=kG(r),this.clientVersionLocked=this.clientVersion!==null;let o=(t.projectKey??null)?.trim().toLowerCase()??null;this.projectKey=o&&/^[a-f0-9]{64}$/.test(o)?o:null;let i=t.nestedProjectKeys;this.nestedProjectKeys=()=>{try{return(i?.()??[]).filter(l=>/^[a-f0-9]{64}$/.test(l)&&l!==this.projectKey)}catch{return[]}},this.localRouter=t.localRouter??null,this.presence=t.presence??null,this.onConnectionOutcome=t.onConnectionOutcome??null,this.onSessionReady=t.onSessionReady??null,this.assignedInbox=t.assignedInbox??null;let a=t.carry??null;a!==null&&(this.initFrame=a.initFrame,this.clientFamily===null&&(this.clientFamily=a.clientFamily),this.clientVersion===null&&(this.clientVersion=a.clientVersion),this.replayFrame=a.pendingFrame),this.clientChannel=new Oc(l=>process.stdout.write(l+`
|
|
1242
1242
|
`),a!==null&&a.initFrame!==null&&(a.pendingFrame===null||!fi(a.pendingFrame))),this.shaRepoRoot=Dc(),this.mcpUrl=t.mcpUrl??process.env.MAIND_MCP_URL??_G,this.stackHeader=AG(this.mcpUrl)?null:RG(t.stack!==void 0?t.stack:En(this.shaRepoRoot??process.cwd()))}async run(t=jh()){if(this.replayFrame!==null){let n=this.replayFrame;this.replayFrame=null,await this.forwardFrame(n)}for(;;){if(this.terminated)return;let{value:n,done:r}=await t.next();if(r){this.clientChannel.close();return}let o=n.trim();o.length!==0&&await this.forwardFrame(o)}}listClientRoots(t){return VT(this.initFrame,this.clientChannel,t)}carryOver(){return{initFrame:this.initFrame,clientFamily:this.clientFamily,clientVersion:this.clientVersion,pendingFrame:this.pendingFrame}}async forwardFrame(t,n=!1){if(!n&&this.clientChannel.observe(t))return;if(!this.clientFamilyLocked&&this.clientFamily===null){let d=KT(t);d!==null&&(this.clientFamily=d.family,!this.clientVersionLocked&&this.clientVersion===null&&(this.clientVersion=d.version))}this.initFrame===null&&fi(t)&&(this.initFrame=t);let r=SG(t),o=null;if(r?.method==="tools/call"){this.presence?.onActivity();let d=Pc(t,this.shaRepoRoot);if(d.length>0){let p=d.find(m=>m.verdict==="fabricated"),f=p??d[0];if(p!==void 0&&XT(p)&&r.id!==null){let m=pi(p,!0);process.stderr.write(`[maind] ${m}
|