@maind-dev/mcp-bridge 0.114.1 → 0.114.2
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 +2 -2
- package/build/meta.json +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -148,7 +148,7 @@ ${o}`};return JSON.stringify({jsonrpc:"2.0",id:e,result:i})}function sU(e,t){ret
|
|
|
148
148
|
`),null}async function OU(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 DU(e){return new Promise(t=>setTimeout(t,e))}function PU(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: ${WE(e.verification_uri,56)} \u2502`,` \u2502 Code: ${WE(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 WE(e,t){return e.length>=t?e.slice(0,t):e+" ".repeat(t-e.length)}async function MU(e){let t,n;switch(NU()){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=IU(t,n,{stdio:"ignore",detached:!0});i.on("error",o),i.unref(),r()}catch(i){o(i)}})}var nh=w(()=>{"use strict";ge();ti();s(ni,"runDeviceFlow");s(OU,"pollOnce");s(DU,"sleep");s(PU,"printAuthInstructions");s(WE,"pad");s(MU,"openExternalBrowser")});import{mkdirSync as $U,readFileSync as LU,renameSync as jU,writeFileSync as FU}from"node:fs";import{join as HU}from"node:path";function KE(e=Rt()){return HU(e,BU)}function KU(e){return e.replace(/mnd_[a-f0-9]{8}_[a-f0-9]{56}/gi,"mnd_\u2026").slice(0,WU)}function qr(e,t,n){try{let r=n.dir??Rt();$U(r,{recursive:!0,mode:448});let o={v:1,at:(n.now??new Date).toISOString(),outcome:e,detail:t===null?null:KU(t),bridge_version:n.version},i=KE(r),a=`${i}.${process.pid}.tmp`;FU(a,JSON.stringify(o)+`
|
|
151
|
-
`,{encoding:"utf8",mode:384}),jU(a,i)}catch{}}function GE(e=Rt()){try{let t=JSON.parse(LU(KE(e),"utf8"));return t.v!==1||typeof t.at!="string"||!UU.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 UU,BU,WU,rh=w(()=>{"use strict";ge();UU=["ok","paired","auth_failed","not_paired"],BU="connection-state.json",WU=200;s(KE,"connectionStatePath");s(KU,"redactDetail");s(qr,"writeConnectionState");s(GE,"readConnectionState")});var B,Be=w(()=>{"use strict";B="0.114.1"});import{execFileSync as VE}from"node:child_process";import{createHash as GU}from"node:crypto";function oh(e){return GU("sha256").update(e).digest("hex")}function ih(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 Wn(e){let t=ih(e);return t?oh(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&VU.test(e))return e;let t;try{t=VE("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Wn(t):null}function Ye(e){let t;try{t=VE("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Wn(t):null}var VU,fe=w(()=>{"use strict";s(oh,"sha256Hex");s(ih,"normalizeRemoteUrl");s(Wn,"projectKeyFromRemote");VU=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(Ye,"projectKeyForRepo")});import qU from"node:path";import{fileURLToPath as zU}from"node:url";function JU(e,t=qU.sep){return e.split(t).includes("_npx")}function Ee(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",zE,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):JU(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 me(){try{let e=zU(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function Xe(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${qE(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:qE(n)).join(" ")}function Yt(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(zE)}function yc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function qE(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var zE,It=w(()=>{"use strict";zE="@maind-dev/mcp-bridge";s(JU,"isEphemeralEntry");s(Ee,"resolveBridgeLaunch");s(me,"currentBridgeEntry");s(Xe,"launchToShellCommand");s(Yt,"isNpxForm");s(yc,"isLegacyHookForm");s(qE,"shellQuote")});import{readFileSync as YU}from"node:fs";import*as H from"node:path";function XE(e){let t=e.launch??Ee({entryPath:me(),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 QE(e){return wc(e,"Claude")}function ZU(e){return H.join(QE(e),ZE)}function wc(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 QU(e){return H.join(wc(e,"Code"),"User")}function bc(e,t,n=[]){return{kind:"foreign-entries",dir:wc(e,t),ours:["User",...n]}}function JE(e){return e.localAppData??H.join(e.homeDir,"AppData","Local")}function tB(e){let t=[{kind:"foreign-entries",dir:QE(e),ours:[ZE]}];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(JE(e),"AnthropicClaude")},{kind:"dir",path:H.join(JE(e),"Packages",eB)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function _n(e){return{evidence:[bc(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 eT(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 nB(e){return H.join(eT(e),"mcp_config.json")}function tT(e){return H.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function kc(e){let t=[bc(e,"Devin",["mcp_config.json"]),{kind:"dir",path:H.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:eT(e),ours:["mcp_config.json"]}),t.push(bc(e,"Windsurf"),{kind:"foreign-entries",dir:H.dirname(tT(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 aB(e){return e===null?null:sB.exec(e)?.[1]??null}function rT(e,t){let n=nT.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 iB)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 oT(e){return e.clineDataDir?e.clineDataDir:H.join(e.clineDir??H.join(e.homeDir,".cline"),"data")}function lB(e){return e.clineMcpSettingsPath??H.join(oT(e),"settings","cline_mcp_settings.json")}function sh(e){return{evidence:[{kind:"foreign-entries",dir:oT(e),ours:["settings"]},...rB.map(t=>({kind:"dir",path:H.join(wc(e,t),"User","globalStorage",YE)})),...rT(e,YE)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function vc(e){return e.continueGlobalDir??H.join(e.homeDir,".continue")}function cB(e){return H.join(vc(e),"mcpServers","maind.json")}function ah(e){return{evidence:[{kind:"foreign-entries",dir:vc(e),ours:["mcpServers","rules"]},...rT(e,oB)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function Kn(e){return e.codexHome??H.join(e.homeDir,".codex")}function zr(e){return H.join(Kn(e),"config.toml")}function ri(e){let t=Kn(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 Hs(e){return{evidence:[bc(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function uB(e){return H.join(QU(e),"mcp.json")}function Us(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:ZU(e),kind:"json",presence:tB(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:H.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:_n(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:nB(e),kind:"json",presence:kc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:tT(e),kind:"json",presence:kc(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:uB(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:Hs(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:lB(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:sh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:cB(e),kind:"json",presence:ah(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:zr(e),kind:"toml",presence:ri(e)}]}function iT(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function sT(e){return e.jsonShape??XU}function aT(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:lT(a,t);return l!==null&&l!==o?[l,o]:[o]}function lT(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 bn(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:_c(e.env.XDG_CONFIG_HOME),appData:_c(e.env.APPDATA),localAppData:_c(e.env.LOCALAPPDATA),clineDir:Fs(e.env.CLINE_DIR),clineDataDir:Fs(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:Fs(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:Fs(e.env.CONTINUE_GLOBAL_DIR),codexHome:Fs(e.env.CODEX_HOME),bundleAppRoot:aB(e.bridgeEntry??null),documentsDirs:aT({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return YU(t,"utf8")}catch{return null}},"readText")})}}function _c(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Fs(e){let t=_c(e);return t!==null&&H.isAbsolute(t)?t:null}var XU,ZE,eB,nT,rB,YE,oB,iB,sB,lh,Ze=w(()=>{"use strict";It();XU={serversKey:"mcpServers"};s(XE,"buildMaindServerEntry");ZE="claude_desktop_config.json";s(QE,"claudeDesktopAppDataDir");s(ZU,"claudeDesktopConfigPath");s(wc,"editorAppDataDir");s(QU,"vsCodeUserDir");s(bc,"editorRan");s(JE,"localAppDataDir");eB="Claude_pzs8sxrjxfjjc";s(tB,"claudeDesktopPresence");s(_n,"cursorPresence");s(eT,"devinConfigDir");s(nB,"devinMcpConfigPath");s(tT,"windsurfLegacyMcpConfigPath");s(kc,"devinDesktopPresence");nT=[{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=nT.map(e=>e.appData),YE="saoudrizwan.claude-dev",oB="continue.continue",iB=["AgentComposer"],sB=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(aB,"bundleAppRootOf");s(rT,"agentExtensionEvidence");s(oT,"clineDataDir");s(lB,"clineMcpSettingsPath");s(sh,"clinePresence");s(vc,"continueGlobalDir");s(cB,"continueMcpConfigPath");s(ah,"continuePresence");s(Kn,"codexHomeDir");s(zr,"codexConfigPath");s(ri,"codexPresence");s(Hs,"vsCodePresence");s(uB,"vsCodeUserMcpPath");s(Us,"getClientTargets");s(iT,"filterTargetsByFamily");s(sT,"jsonShapeOf");lh=[...new Set(Us({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(aT,"documentsDirCandidates");s(lT,"parseXdgDocumentsDir");s(bn,"makeDefaultContext");s(_c,"nonEmpty");s(Fs,"absoluteOrNull")});function ch(){return lh.map(e=>{let t=Object.keys(xc).filter(n=>xc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function cT(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(dB),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 yt("--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 yt("--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 yt("--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 yt("--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 yt(`--client requires a family argument (${ch()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(xc,i)?xc[i]:i;if(!lh.includes(a))throw new yt(`--client "${o}" is not a known client family. Known: ${ch()}`);t.client=a,n++;break}default:throw new yt(`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 yt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function uT(){process.stdout.write(pB())}function pB(){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:",` ${ch()}`," (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}),jU(a,i)}catch{}}function GE(e=Rt()){try{let t=JSON.parse(LU(KE(e),"utf8"));return t.v!==1||typeof t.at!="string"||!UU.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 UU,BU,WU,rh=w(()=>{"use strict";ge();UU=["ok","paired","auth_failed","not_paired"],BU="connection-state.json",WU=200;s(KE,"connectionStatePath");s(KU,"redactDetail");s(qr,"writeConnectionState");s(GE,"readConnectionState")});var B,Be=w(()=>{"use strict";B="0.114.2"});import{execFileSync as VE}from"node:child_process";import{createHash as GU}from"node:crypto";function oh(e){return GU("sha256").update(e).digest("hex")}function ih(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 Wn(e){let t=ih(e);return t?oh(t):null}function ne(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&VU.test(e))return e;let t;try{t=VE("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Wn(t):null}function Ye(e){let t;try{t=VE("git",["config","--get","remote.origin.url"],{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Wn(t):null}var VU,fe=w(()=>{"use strict";s(oh,"sha256Hex");s(ih,"normalizeRemoteUrl");s(Wn,"projectKeyFromRemote");VU=/^[a-f0-9]{64}$/;s(ne,"computeProjectKey");s(Ye,"projectKeyForRepo")});import qU from"node:path";import{fileURLToPath as zU}from"node:url";function JU(e,t=qU.sep){return e.split(t).includes("_npx")}function Ee(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",zE,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):JU(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 me(){try{let e=zU(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function Xe(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${qE(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:qE(n)).join(" ")}function Yt(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(zE)}function yc(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function qE(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var zE,It=w(()=>{"use strict";zE="@maind-dev/mcp-bridge";s(JU,"isEphemeralEntry");s(Ee,"resolveBridgeLaunch");s(me,"currentBridgeEntry");s(Xe,"launchToShellCommand");s(Yt,"isNpxForm");s(yc,"isLegacyHookForm");s(qE,"shellQuote")});import{readFileSync as YU}from"node:fs";import*as H from"node:path";function XE(e){let t=e.launch??Ee({entryPath:me(),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 QE(e){return wc(e,"Claude")}function ZU(e){return H.join(QE(e),ZE)}function wc(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 QU(e){return H.join(wc(e,"Code"),"User")}function bc(e,t,n=[]){return{kind:"foreign-entries",dir:wc(e,t),ours:["User",...n]}}function JE(e){return e.localAppData??H.join(e.homeDir,"AppData","Local")}function tB(e){let t=[{kind:"foreign-entries",dir:QE(e),ours:[ZE]}];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(JE(e),"AnthropicClaude")},{kind:"dir",path:H.join(JE(e),"Packages",eB)}),{evidence:t,skipDetail:"Claude Desktop not found (no Claude app, no Claude Desktop app data beyond our config file)"}}function _n(e){return{evidence:[bc(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 eT(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 nB(e){return H.join(eT(e),"mcp_config.json")}function tT(e){return H.join(e.homeDir,".codeium","windsurf","mcp_config.json")}function kc(e){let t=[bc(e,"Devin",["mcp_config.json"]),{kind:"dir",path:H.join(e.homeDir,".devin")}];return e.platform!=="win32"&&t.push({kind:"foreign-entries",dir:eT(e),ours:["mcp_config.json"]}),t.push(bc(e,"Windsurf"),{kind:"foreign-entries",dir:H.dirname(tT(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 aB(e){return e===null?null:sB.exec(e)?.[1]??null}function rT(e,t){let n=nT.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 iB)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 oT(e){return e.clineDataDir?e.clineDataDir:H.join(e.clineDir??H.join(e.homeDir,".cline"),"data")}function lB(e){return e.clineMcpSettingsPath??H.join(oT(e),"settings","cline_mcp_settings.json")}function sh(e){return{evidence:[{kind:"foreign-entries",dir:oT(e),ours:["settings"]},...rB.map(t=>({kind:"dir",path:H.join(wc(e,t),"User","globalStorage",YE)})),...rT(e,YE)],skipDetail:"Cline not found (no Cline data in ~/.cline, no Cline extension or storage in any editor)"}}function vc(e){return e.continueGlobalDir??H.join(e.homeDir,".continue")}function cB(e){return H.join(vc(e),"mcpServers","maind.json")}function ah(e){return{evidence:[{kind:"foreign-entries",dir:vc(e),ours:["mcpServers","rules"]},...rT(e,oB)],skipDetail:"Continue not found (nothing of Continue's in ~/.continue, no Continue extension in any editor)"}}function Kn(e){return e.codexHome??H.join(e.homeDir,".codex")}function zr(e){return H.join(Kn(e),"config.toml")}function ri(e){let t=Kn(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 Hs(e){return{evidence:[bc(e,"Code")],skipDetail:"VS Code not found (no VS Code app data)"}}function uB(e){return H.join(QU(e),"mcp.json")}function Us(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:ZU(e),kind:"json",presence:tB(e)},{key:"cursor",label:"Cursor (~/.cursor/mcp.json)",clientFamilyEnv:"cursor",scope:"user",path:H.join(e.homeDir,".cursor","mcp.json"),kind:"json",presence:_n(e)},{key:"windsurf",label:"Devin Desktop (formerly Windsurf)",clientFamilyEnv:"windsurf",scope:"user",path:nB(e),kind:"json",presence:kc(e)},{key:"windsurf-legacy",label:"Devin Desktop (formerly Windsurf), legacy ~/.codeium/windsurf/mcp_config.json",clientFamilyEnv:"windsurf",scope:"user",path:tT(e),kind:"json",presence:kc(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:uB(e),kind:"json",jsonShape:{serversKey:"servers",entryType:"stdio"},presence:Hs(e)},{key:"cline",label:"Cline (~/.cline/data/settings/cline_mcp_settings.json)",clientFamilyEnv:"cline",scope:"user",path:lB(e),kind:"json",jsonShape:{serversKey:"mcpServers",clientKeys:{defaults:{disabled:!1},drop:["transport","type","transportType","url","headers"]}},presence:sh(e)},{key:"continue",label:"Continue (~/.continue/mcpServers/maind.json)",clientFamilyEnv:"continue",scope:"user",path:cB(e),kind:"json",presence:ah(e)},{key:"codex-cli",label:"Codex CLI (~/.codex/config.toml)",clientFamilyEnv:"codex",scope:"user",path:zr(e),kind:"toml",presence:ri(e)}]}function iT(e,t){return t===null?e:e.filter(n=>n.clientFamilyEnv===t)}function sT(e){return e.jsonShape??XU}function aT(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:lT(a,t);return l!==null&&l!==o?[l,o]:[o]}function lT(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 bn(e){return{projectRoot:e.projectRoot,homeDir:e.homeDir,platform:e.platform,xdgConfigHome:_c(e.env.XDG_CONFIG_HOME),appData:_c(e.env.APPDATA),localAppData:_c(e.env.LOCALAPPDATA),clineDir:Fs(e.env.CLINE_DIR),clineDataDir:Fs(e.env.CLINE_DATA_DIR),clineMcpSettingsPath:Fs(e.env.CLINE_MCP_SETTINGS_PATH),continueGlobalDir:Fs(e.env.CONTINUE_GLOBAL_DIR),codexHome:Fs(e.env.CODEX_HOME),bundleAppRoot:aB(e.bridgeEntry??null),documentsDirs:aT({homeDir:e.homeDir,platform:e.platform,env:e.env,readText:s(t=>{try{return YU(t,"utf8")}catch{return null}},"readText")})}}function _c(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Fs(e){let t=_c(e);return t!==null&&H.isAbsolute(t)?t:null}var XU,ZE,eB,nT,rB,YE,oB,iB,sB,lh,Ze=w(()=>{"use strict";It();XU={serversKey:"mcpServers"};s(XE,"buildMaindServerEntry");ZE="claude_desktop_config.json";s(QE,"claudeDesktopAppDataDir");s(ZU,"claudeDesktopConfigPath");s(wc,"editorAppDataDir");s(QU,"vsCodeUserDir");s(bc,"editorRan");s(JE,"localAppDataDir");eB="Claude_pzs8sxrjxfjjc";s(tB,"claudeDesktopPresence");s(_n,"cursorPresence");s(eT,"devinConfigDir");s(nB,"devinMcpConfigPath");s(tT,"windsurfLegacyMcpConfigPath");s(kc,"devinDesktopPresence");nT=[{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=nT.map(e=>e.appData),YE="saoudrizwan.claude-dev",oB="continue.continue",iB=["AgentComposer"],sB=/^(.+)[\\/]maind-bridge[\\/]node_modules[\\/]@maind-dev[\\/]mcp-bridge[\\/]build[\\/]index\.js$/;s(aB,"bundleAppRootOf");s(rT,"agentExtensionEvidence");s(oT,"clineDataDir");s(lB,"clineMcpSettingsPath");s(sh,"clinePresence");s(vc,"continueGlobalDir");s(cB,"continueMcpConfigPath");s(ah,"continuePresence");s(Kn,"codexHomeDir");s(zr,"codexConfigPath");s(ri,"codexPresence");s(Hs,"vsCodePresence");s(uB,"vsCodeUserMcpPath");s(Us,"getClientTargets");s(iT,"filterTargetsByFamily");s(sT,"jsonShapeOf");lh=[...new Set(Us({projectRoot:"/",homeDir:"/",platform:"linux",xdgConfigHome:null,appData:null}).map(e=>e.clientFamilyEnv))];s(aT,"documentsDirCandidates");s(lT,"parseXdgDocumentsDir");s(bn,"makeDefaultContext");s(_c,"nonEmpty");s(Fs,"absoluteOrNull")});function ch(){return lh.map(e=>{let t=Object.keys(xc).filter(n=>xc[n]===e);return t.length>0?`${e} (or ${t.join(", ")})`:e}).join(", ")}function cT(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(dB),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 yt("--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 yt("--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 yt("--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 yt("--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 yt(`--client requires a family argument (${ch()})`);let i=o.trim().toLowerCase(),a=Object.hasOwn(xc,i)?xc[i]:i;if(!lh.includes(a))throw new yt(`--client "${o}" is not a known client family. Known: ${ch()}`);t.client=a,n++;break}default:throw new yt(`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 yt(`--hooks-only sets up the user-level channels and nothing else \u2014 drop ${n.join(", ")}`)}return t}function uT(){process.stdout.write(pB())}function pB(){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:",` ${ch()}`," (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 xc,dB,yt,dT=w(()=>{"use strict";Ze();xc={devin:"windsurf"};s(ch,"familyChoices");dB="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(cT,"parseInstallFlags");yt=class extends Error{static{s(this,"InstallFlagError")}constructor(t){super(t),this.name="InstallFlagError"}};s(uT,"printInstallHelp");s(pB,"installHelpText")});var Bs,pT=w(()=>{"use strict";Bs=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
|
`)+`
|
|
@@ -866,7 +866,7 @@ ${y}`:y}function _2(e,t){let n=e.replace(/\s+/g," ").trim();return n.length<=t?n
|
|
|
866
866
|
`:`
|
|
867
867
|
`}),n=r+1}return t}function _V(e){let t=ty(e),n=[],r=null;for(let o=0;o<t.length;o++){if(!t[o].text.startsWith(Zr))continue;let i=gV.find(a=>o+a.lines<=t.length&&SC(t.slice(o,o+a.lines).map(l=>l.text).join(`
|
|
868
868
|
`))===a.sha256);if(i===void 0){r=`a "${Zr}" section (line ${o+1}) that is not a block the installer wrote \u2014 edited by hand, or an unknown variant`;continue}n.push({kind:"preamble",from:o,to:o+i.lines-1}),o+=i.lines-1}for(let o=0;o<t.length;o++){if(t[o].text.trim()!==$c)continue;let i=t.findIndex((l,c)=>c>o&&l.text.trim()===Lc);if(i<0){r=`a conventions block without its end marker (line ${o+1})`;break}let a=t.slice(o+1,i).some(l=>l.text.trim().startsWith(Xs));n.push({kind:a?"team-conventions":"conventions",from:o,to:i}),o=i}return n.sort((o,i)=>o.from-i.from),{blocks:n,manual:r}}function bV(e,t){let n=ty(e),r=new Array(n.length).fill(!1);for(let a of t)if(a.kind!=="team-conventions"){for(let l=a.from;l<=a.to;l++)r[l]=!0;for(let l=a.from-1;l>=0&&!r[l]&&wu(n[l]);l--)r[l]=!0}let o=0;for(;o<n.length&&r[o];)o++;if(o>0)for(;o<n.length&&wu(n[o]);o++)r[o]=!0;let i=n.filter((a,l)=>!r[l]);return i.every(wu)?null:i.map(a=>a.text+a.eol).join("")}function EC(e,t,n){let r=_V(n);if(r.blocks.length===0&&r.manual===null)return null;let o=s(p=>`${kV[p.kind]} (lines ${p.from+1}\u2013${p.to+1})`,"describe"),i=r.blocks.filter(p=>p.kind!=="team-conventions"),a=r.blocks.filter(p=>p.kind==="team-conventions");if(r.manual!==null)return{rel:e,path:t,raw:n,action:"manual",next:null,removes:[],keeps:[r.manual]};if(i.length===0)return{rel:e,path:t,raw:n,action:"keep",next:null,removes:[],keeps:a.map(o)};let l=bV(n,r.blocks),c=i.map(o);if(l===null)return{rel:e,path:t,raw:n,action:"delete",next:null,removes:c,keeps:[]};let u=ty(l).filter(p=>!wu(p)).length-a.reduce((p,f)=>p+(f.to-f.from+1),0),d=[...a.map(o),...u>0?[`${u} line${u===1?"":"s"} of yours`]:[]];return{rel:e,path:t,raw:n,action:"edit",next:l,removes:c,keeps:d}}function po(e){return e.some(t=>t.action==="edit"||t.action==="delete"||t.action==="manual")}function vu(e){return e.filter(t=>t.action!=="keep").map(t=>{if(t.action==="manual")return`${t.rel} (by hand)`;let n=[...new Set(t.removes.map(r=>r.replace(/ \(lines.*$/,"")))];return`${t.rel} (${n.join(" + ")})`}).join(", ")}var xC,SC,hV,gV,wu,kV,va=w(()=>{"use strict";Mc();si();xC=["CLAUDE.md","AGENTS.md",".github/copilot-instructions.md",".cursorrules",".windsurfrules"],SC=s(e=>mV("sha256").update(e).digest("hex"),"sha256"),hV={lines:70,sha256:"2c7687dc2fd58b7c96d7f31c7b530c06c3fffe8710c6404a7e421ca7c8bf7714"},gV=yV([{lines:Xt.split(`
|
|
869
|
-
`).length,sha256:SC(Xt)},hV,{lines:57,sha256:"72f5d6423e98eb01b2854b44dff290f2d8be1af1c8995f059dba5118530aafce"},{lines:56,sha256:"bf77aeeed9e96b8d0bfcba1feee0592256e2d49d64b53977bbd8f5b8323e5387"},{lines:21,sha256:"afdaf4a151cfd6fc9258392d86593e0604dae7518ffa8918cfc92bab9d5fd41b"}]);s(yV,"dedupe");s(ty,"splitLines");wu=s(e=>e.text.trim()==="","isBlank");s(_V,"scanRepoFile");s(bV,"cutBlocks");kV={preamble:"maind preamble",conventions:"conventions block","team-conventions":"team conventions block (install --team)"};s(EC,"planRepoFile");s(po,"hasMigratableBlocks");s(vu,"summarizeRepoBlocks")});import{parse as wV}from"jsonc-parser";function ny(e,t){let n=e.split(/[.+-]/).slice(0,3).map(o=>Number.parseInt(o,10)||0),r=t.split(/[.+-]/).slice(0,3).map(o=>Number.parseInt(o,10)||0);for(let o=0;o<3;o++)if(n[o]!==r[o])return n[o]-r[o];return 0}function oy(e){if(e.raw===null)return null;if(e.kind==="toml"){let a=_t(e.raw);if("value"in a){let d=wn(a.value,["mcp_servers","maind"]);if(!ee(d)||typeof d.command!="string")return null;let p=Array.isArray(d.args)?d.args.filter(f=>typeof f=="string"):[];return{command:d.command,args:p}}let l=/\[mcp_servers\.maind\]([\s\S]*?)(?=\n\[|$)/.exec(e.raw);if(!l)return null;let c=/^\s*command\s*=\s*"([^"]*)"/m.exec(l[1]),u=/^\s*args\s*=\s*\[([^\]]*)\]/m.exec(l[1]);return c?{command:c[1],args:u?[...u[1].matchAll(/"([^"]*)"/g)].map(d=>d[1]):[]}:null}let t=[],n=wV(e.raw,t,{allowTrailingComma:!0});if(t.length>0||typeof n!="object"||n===null)return null;let r=n,o=r.servers?.maind??r.mcpServers?.maind,i=o?.transport??o;return!i||typeof i.command!="string"?null:{command:i.command,args:Array.isArray(i.args)?i.args.filter(a=>typeof a=="string"):[]}}function Ti(e,t){let n=`npm i -g ${Tn}@${e}`;return t?`nvm use ${t} && ${n}`:n}function xu(e){let t=[],n=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`),r=[e.runningVersion,...e.nodeTrees.map(y=>y.bridgeVersion).filter(y=>y!==null)],o=e.latestVersion??r.sort(ny).at(-1)??e.runningVersion;e.latestVersion===null&&t.push({check:"version",level:"info",message:`doctor ${e.runningVersion}; the npm registry was not reachable, so "published" is unknown and installs are not compared.`});let i=e.nodeTrees.filter(y=>y.bridgeVersion!==null);if(e.nodeTrees.length>0){let y=e.pathWinner?.node??null,_=e.nodeTrees.find(k=>k.node===y);if(e.pathWinner===null?t.push({check:"node-trees",level:"info",message:"no `maind-mcp-bridge` on PATH \u2014 only a client configured with the bare command needs it (see client-config)."}):_&&t.push({check:"node-trees",level:"ok",message:`PATH resolves maind-mcp-bridge to the ${_.node} tree (${_.bridgeVersion??"?"}).`}),e.nvmDefault!==null){let k=e.nodeTrees.find(v=>v.node===e.nvmDefault);k&&k.bridgeVersion===null&&t.push({check:"node-trees",level:"warn",message:`the nvm default ${k.node} has no bridge installed \u2014 after \`nvm use default\` (or in a fresh shell) the bin is gone.`,fix:Ti(o,k.node)})}if(new Set(i.map(k=>k.bridgeVersion)).size>1)for(let k of i.filter(v=>ny(v.bridgeVersion,o)<0))t.push({check:"node-trees",level:"warn",message:`${k.node} carries bridge ${k.bridgeVersion}, others carry a newer one \u2014 which one runs depends on PATH order, and \`npm ls -g\` only ever shows one.`,fix:Ti(o,k.node)})}let a=!1,l=new Map,c=s((y,_)=>{let b=l.get(y)??{version:e.installVersionOf(y),clients:[]};b.clients.push(_),l.set(y,b)},"noteInstall");for(let y of e.clientConfigs){let _=oy(y);if(_===null)continue;if(y.present===!1){t.push({check:"client-config",level:"warn",message:`${y.label}: ${y.path} names maind, but the client is not installed \u2014 nothing reads this file (a leftover of an earlier install).`,fix:"maind-mcp-bridge doctor --remove-phantoms"});continue}if(a=!0,/(^|\/)npx(\.cmd)?$/.test(_.command)&&_.args.some(v=>v.includes(Tn))){t.push({check:"client-config",level:"warn",message:`${y.label} starts the bridge through npx \u2014 every cold start rebuilds better-sqlite3 and races the client's connect timeout.`,fix:`${Ti(o)}, then set "command": "maind-mcp-bridge" (no args) in ${y.path}`});continue}let k=/(^|[\\/])node(\.exe)?$/.test(_.command);if(k&&_.args.length>0){let v=_.args[0];if(!e.fileExists(v)){t.push({check:"client-config",level:"error",message:`${y.label} runs ${v}, which does not exist.`,fix:`re-run \`npx -y ${Tn}@${o} install\` to rewrite the entry`});continue}c(v,y.label)}else if(_.command.includes("/")||_.command.includes("\\")){if(!e.fileExists(_.command)){t.push({check:"client-config",level:"error",message:`${y.label} points at ${_.command}, which does not exist.`,fix:`set "command": "maind-mcp-bridge" in ${y.path} (after ${Ti(o)})`});continue}}else if(_.command==="maind-mcp-bridge"&&e.pathWinner===null){t.push({check:"client-config",level:"error",message:`${y.label} runs \`maind-mcp-bridge\`, but nothing on PATH answers to it.`,fix:Ti(o,e.nvmDefault)});continue}k||(_.command.includes("/")||_.command.includes("\\")?c(_.command,y.label):_.command==="maind-mcp-bridge"&&e.pathWinner&&c(e.pathWinner.path,y.label)),t.push({check:"client-config",level:"ok",message:`${y.label}: ${[_.command,..._.args].join(" ")}`})}if(!a&&e.plugin?.enabled!==!0&&t.push({check:"client-config",level:"warn",message:"no installed MCP client's config names a `maind` server.",fix:`npx -y ${Tn} install`}),e.latestVersion!==null)for(let[y,_]of l){let b=_.clients.join(", ");if(_.version===null)t.push({check:"version",level:"info",message:`${b}: cannot tell which bridge version ${y} is.`});else if(ny(_.version,e.latestVersion)<0){let k=/[\\/]versions[\\/]node[\\/](v[^\\/]+)[\\/]/.exec(y)?.[1]??null;t.push({check:"version",level:"warn",message:`${b} run bridge ${_.version} (${y}); published is ${e.latestVersion}. An installed bridge never updates itself.`,fix:k?Ti(e.latestVersion,k):`npx -y ${Tn}@${e.latestVersion} install`})}else t.push({check:"version",level:"ok",message:`${b} run bridge ${_.version} (published: ${e.latestVersion}).`})}for(let{dir:y,maind:_}of e.npxStaleDirs)t.push({check:"npx-cache",level:_?"error":"info",message:_?`a half-built better-sqlite3 was left in ${y} \u2014 every npx start of this maind entry now fails with ENOTEMPTY.`:`a half-built better-sqlite3 was left in ${y} (another tool's npx entry, not maind's).`,fix:`rm -rf '${y.replace(/'/g,"'\\''")}'`});let u=e.envApiKey??e.apiKey;(e.deviceId===null||!TC.test(e.deviceId))&&t.push({check:"credentials",level:"error",message:"no valid device id \u2014 the server binds keys to a device, so every call ends in 401 invalid_or_device_required.",fix:"maind-mcp-bridge --reauth"}),u===null?t.push({check:"credentials",level:"error",message:"no API key stored and none in MAIND_API_KEY.",fix:"maind-mcp-bridge --reauth"}):xV.test(u)?t.push({check:"credentials",level:e.deviceId!==null&&TC.test(e.deviceId)?"ok":"info",message:`key ${u.slice(0,12)}\u2026 present${e.envApiKey?" (from MAIND_API_KEY)":""}. Whether the server still binds it to this device only the server can say \u2014 a 401 invalid_or_device_required means re-pair.`}):t.push({check:"credentials",level:"error",message:`the ${e.envApiKey?"MAIND_API_KEY value":"stored key"} is not a maind key (mnd_<8 hex>_<56 hex>).`,fix:e.envApiKey?"fix or remove MAIND_API_KEY in the client config":"maind-mcp-bridge --reauth"});let d=e.connection;d===null?t.push({check:"connection",level:"info",message:"no connection outcome recorded yet (bridges before 0.75.0 did not record one)."}):d.outcome==="ok"||d.outcome==="paired"?t.push({check:"connection",level:"ok",message:`last connection ${d.outcome==="ok"?"succeeded":"was paired"} at ${d.at} (bridge ${d.bridge_version}).`}):t.push({check:"connection",level:"error",message:d.outcome==="auth_failed"?`the server rejected the last connection (${d.at}${d.detail?`: ${d.detail}`:""}) \u2014 maind is not reachable until this device is paired again.`:`the bridge could not sign in (${d.at}${d.detail?`: ${d.detail}`:""}) \u2014 without a key nothing reaches maind.`,fix:"run `maind-mcp-bridge --reauth` in a terminal (it opens the browser), then restart the MCP client"});let p=e.plugin?.enabled===!0;if(e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(k=>e.fileExists(k),"fileExists")}),_=e.pathWinner?e.installVersionOf(e.pathWinner.path):null,b=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`);for(let k of y){if(k.status==="missing"){if(p||k.subcommand===ie)continue;let S=(e.declinedHooks??[]).includes(k.subcommand);t.push(S?{check:"hooks",level:"info",message:`${k.event}/${k.subcommand} was declined at install and stays off \u2014 \`install --hooks-only\` asks again.`}:{check:"hooks",level:"warn",message:`${k.detail} Updating the bridge replaces the binary and never adds a hook entry (install is append-only).`,fix:`${b} install --hooks-only (adds what is missing, asks consent per hook)`});continue}if(k.status==="superseded")continue;if(k.status!=="ok"){t.push({check:"hooks",level:k.status==="broken"?"error":"warn",message:k.detail});continue}let v=k.command?/(\S+\/build\/index\.js)/.exec(k.command)?.[1]??null:null,x=v?e.installVersionOf(v):null;x!==null&&_!==null&&x!==_&&t.push({check:"hooks",level:"warn",message:`${k.event}/${k.subcommand} runs bridge ${x}, the MCP server runs ${_} \u2014 writer and reader of the presence snapshot must be the same install.`,fix:`point the hook at the same install as the server: ${e.pathWinner?.path??"maind-mcp-bridge"} ${k.subcommand}`})}t.some(k=>k.check==="hooks"&&k.level!=="info")||t.push({check:"hooks",level:"ok",message:"every wired bridge hook points at an existing install."})}if(p){let y=(e.declinedHooks??[]).includes(ie),_=e.guardMode??"off",b=y&&e.claudeSettings!==null&&wa(e.claudeSettings,{guardMode:_,fileExists:s(S=>e.fileExists(S),"fileExists")}).channel==="guard";t.push(y?b?{check:"session-start",level:"info",message:`the briefing reaches Claude Code through the guard's guard-inject (guard mode ${_}): ${ie} was declined at install, and the maind plugin keeps it off too.`}:{check:"session-start",level:"info",message:`no session-start briefing \u2014 ${ie} was declined at install, and the maind plugin keeps it off too, so Claude Code sessions see only the MCP instructions, which it cuts after ~2,000 characters.`}:{check:"session-start",level:"ok",message:`Claude Code sessions receive the briefing and the project conventions at session start from the maind plugin (${ie}).`});let k=e.plugin?.file?` (${e.plugin.file})`:"",v=e.clientConfigs.find(S=>S.key==="claude-code-user");v!==void 0&&Qg(v.raw).length>0&&t.push({check:"claude-plugin",level:"warn",message:`the maind plugin is enabled${k} and brings its own MCP server, and ${v.path} still registers a \`maind\` server \u2014 Claude Code starts both, so every maind tool is listed twice.`,fix:`${n} doctor --remove-duplicate-mcp (lists it; --yes removes exactly that entry \u2014 with Claude Code closed)`});let x=e.claudeSettings===null?[]:et(e.claudeSettings,{fileExists:s(S=>e.fileExists(S),"fileExists")}).filter(S=>S.status!=="missing"&&S.status!=="broken");x.length>0&&t.push({check:"claude-plugin",level:"info",message:`the maind plugin is enabled${k}, and ~/.claude/settings.json still wires the bridge's own hooks (${x.map(S=>S.subcommand).join(", ")}) \u2014 nothing runs twice (the plugin's copy stands down for them), but these run from settings.json, pinned to that install, instead of updating with the plugin.`,fix:`${n} doctor --remove-duplicate-hooks (lists them; --yes removes exactly those entries from settings.json)`})}if(e.claudeSettings!==null&&!p){let y=e.guardMode??"off",_=wa(e.claudeSettings,{guardMode:y,fileExists:s(x=>e.fileExists(x),"fileExists")}),k=`${e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`)} install --hooks-only`,v=(e.declinedHooks??[]).includes(ie);_.channel==="core"?t.push({check:"session-start",level:"ok",message:`Claude Code sessions receive the briefing and the project conventions at session start (${ie} hook).`}):_.core.status==="broken"?t.push({check:"session-start",level:"warn",message:`the ${ie} hook is wired, but its script is gone \u2014 sessions start without the project conventions (see the hooks finding for the fix).`}):_.channel==="guard"?t.push({check:"session-start",level:"info",message:`the briefing reaches Claude Code through the guard's guard-inject (guard mode ${y}); without the core ${ie} hook it stops when the guard is switched off.`,fix:k}):v?t.push({check:"session-start",level:"info",message:`no session-start briefing \u2014 the ${ie} hook was declined at install, so Claude Code sessions see only the MCP instructions, which it cuts after ~2,000 characters.`,fix:k}):t.push({check:"session-start",level:"warn",message:`no session-start briefing hook is wired (${ie}) \u2014 Claude Code sessions start without the project conventions; the MCP instructions that do arrive are cut after ~2,000 characters.`,fix:k})}if(e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(_=>e.fileExists(_),"fileExists")},[vV])[0];if(y.status==="superseded"){let _=e.foreignHookHosts??[],b=_.includes("cursor"),k=(e.declinedHooks??[]).includes(vn),v=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`),x=y.remedy==="run-install"?`${v} install --hooks-only`:`replace that command in ~/.claude/settings.json with: ${v} ${vn}`,S=b?`Cursor, installed here, imports it from ~/.claude/settings.json and takes only JSON at session start \u2014 it gets plain text it cannot parse${_.includes("devin")?"; Devin Local gets text whose handling it does not document":""}`:_.includes("devin")?"Devin Local, installed here, runs it too and documents only JSON context for hooks":"it is fine in Claude Code, but Cursor and Devin Local, which import the same hooks, would get plain text";t.push({check:"hook-hosts",level:b&&!k?"warn":"info",message:`the SessionStart reminder hook still runs \`${y.command}\` \u2014 ${S}. ${vn} prints the same text in Claude Code and the right form, or nothing, everywhere else.`,fix:x})}}let f=e.repoBlocks??null,m=f?.plans.find(y=>y.keeps.some(_=>_.startsWith("team conventions block")))??null;f!==null&&po(f.plans)&&t.push({check:"repo-blocks",level:"info",message:`${f.root} still carries the maind blocks an earlier install wrote into the repository \u2014 ${vu(f.plans)}. The bridge no longer writes them (ADR-364): hooks and user-level rule files carry the same content. They stay until you remove them.`,fix:`${n} doctor --migrate-repo-blocks (lists them and changes nothing; --yes removes exactly the listed blocks)`}),m!==null&&t.push({check:"repo-blocks",level:"ok",message:`${m.rel} carries the team conventions block (install --team); the bridge keeps it current.`}),f!==null&&f.inRepo&&m===null&&(e.foreignHookHosts??[]).includes("cursor")&&t.push({check:"team-option",level:"info",message:`Cursor is installed here, and its sessionStart hook can drop the briefing in a race Cursor confirms. For teams that work mostly in Cursor, the team option puts the conventions into ${f.root}'s AGENTS.md, which Cursor reads reliably.`,fix:`${n} install --team (writes the AGENTS.md conventions block and the project .mcp.json)`});for(let y of e.channels??[]){let _=y.hooks&&y.hooks.gaps.length>0?` (not available there: ${y.hooks.gaps.join(", ")})`:"";y.state==="ok"&&y.hooks&&y.hooks.missing.length>0?t.push({check:"channels",level:"info",message:`${y.label}: ${y.hooks.wired.length} of ${y.hooks.wired.length+y.hooks.missing.length} wired \u2014 not yet: ${y.hooks.missing.join(", ")}${_}.`,fix:`${n} install --hooks-only (asks consent per hook)`}):y.state==="ok"?t.push({check:"channels",level:"ok",message:`${y.label}: ${y.path}${_}`}):y.state==="foreign"?t.push({check:"channels",level:"info",message:`${y.label}: ${y.path} is not the bridge's (no maind marker) \u2014 left as it is, so ${y.client} gets no conventions from MAIND there.`}):t.push({check:"channels",level:"info",message:`${y.label} is not set up \u2014 ${y.client} sessions get the project conventions only from the MCP instructions${f!==null&&po(f.plans)?" and the repository's old maind blocks":""}.`,fix:`${n} install --hooks-only (asks consent per hook and file)`})}let g=e.context??null;if(g!==null&&e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(_=>e.fileExists(_),"fileExists")}).filter(_=>(_.subcommand==="on-prompt-context"||_.subcommand==="on-read-context")&&_.status!=="missing").map(_=>_.subcommand);if(y.length>0){let _=t.length;g.sqlite.ok?g.repoRoot!==null&&!g.indexPresent&&t.push({check:"context",level:"info",message:`${g.repoRoot} has no code index \u2014 on-read-context stays silent there, and on-prompt-context can only match conventions.`,fix:"ask your agent to run codebase_index once (or run `maind index` in the repo); the Stop hook keeps it fresh after that"}):t.push({check:"context",level:"warn",message:`${y.join(" and ")} cannot read the local code index here \u2014 no SQLite backend loads (${g.sqlite.reason}). They stay silent.`,fix:"update Node to >= 22.16 (builtin SQLite), or run `npm rebuild better-sqlite3` in the bridge's install prefix"}),y.includes("on-prompt-context")&&g.repoRoot!==null&&!g.conventionsCached&&t.push({check:"context",level:"info",message:`no conventions are cached for ${g.repoRoot} yet \u2014 on-prompt-context matches them once the MAIND MCP server has started in this repo.`}),t.length===_&&t.push({check:"context",level:"ok",message:`${y.join(" and ")}: code index and cached conventions present${g.repoRoot?` for ${g.repoRoot}`:""}.`})}}return t}function AC(e){let t=e.filter(o=>o.level==="error"&&ry.includes(o.check)).sort((o,i)=>ry.indexOf(o.check)-ry.indexOf(i.check)),n=t[0];if(n===void 0)return SV(e);let r=t.length>1?` ${t.length-1} more finding(s).`:"";return`[maind] setup problem \u2014 ${n.message}`+(n.fix?` Fix: ${n.fix}.`:"")+r+" All findings with fixes: `maind-mcp-bridge doctor` (or `npx -y @maind-dev/mcp-bridge doctor`)."}function SV(e){let t=e.find(n=>n.check==="session-start"&&n.level==="warn");return t===void 0?EV(e):`[maind] setup gap \u2014 ${t.message} Call get_session_briefing now to load them.`+(t.fix?` To add the hook, run in a terminal (append-only, asks consent per hook): ${t.fix}`:"")}function EV(e){let t=e.find(n=>n.check==="hook-hosts"&&n.level==="warn");return t===void 0?TV(e):`[maind] setup gap \u2014 ${t.message}`+(t.fix?` To switch to it, run in a terminal (asks consent, replaces only that entry): ${t.fix}`:"")}function TV(e){let t=e.find(n=>n.check==="claude-plugin"&&n.level==="warn");return t===void 0?null:`[maind] setup note \u2014 ${t.message}`+(t.fix?` To fix, run in a terminal: ${t.fix}`:"")}function CC(e){let t={error:"\u2717",warn:"!",info:"\xB7",ok:"\u2713"},n={error:0,warn:1,info:2,ok:3},r=[...e].sort((a,l)=>n[a.level]-n[l.level]).flatMap(a=>[`${t[a.level]} [${a.check}] ${a.message}`,...a.fix?[` fix: ${a.fix}`]:[]]),o=e.filter(a=>a.level==="error").length,i=e.filter(a=>a.level==="warn").length;return r.push("",o+i===0?"maind-mcp-bridge doctor: nothing to fix.":`maind-mcp-bridge doctor: ${o} error(s), ${i} warning(s).`),r.push("A running MCP client does not reload its servers \u2014 restart it after a fix."),r.join(`
|
|
869
|
+
`).length,sha256:SC(Xt)},hV,{lines:57,sha256:"72f5d6423e98eb01b2854b44dff290f2d8be1af1c8995f059dba5118530aafce"},{lines:56,sha256:"bf77aeeed9e96b8d0bfcba1feee0592256e2d49d64b53977bbd8f5b8323e5387"},{lines:21,sha256:"afdaf4a151cfd6fc9258392d86593e0604dae7518ffa8918cfc92bab9d5fd41b"}]);s(yV,"dedupe");s(ty,"splitLines");wu=s(e=>e.text.trim()==="","isBlank");s(_V,"scanRepoFile");s(bV,"cutBlocks");kV={preamble:"maind preamble",conventions:"conventions block","team-conventions":"team conventions block (install --team)"};s(EC,"planRepoFile");s(po,"hasMigratableBlocks");s(vu,"summarizeRepoBlocks")});import{parse as wV}from"jsonc-parser";function ny(e,t){let n=e.split(/[.+-]/).slice(0,3).map(o=>Number.parseInt(o,10)||0),r=t.split(/[.+-]/).slice(0,3).map(o=>Number.parseInt(o,10)||0);for(let o=0;o<3;o++)if(n[o]!==r[o])return n[o]-r[o];return 0}function oy(e){if(e.raw===null)return null;if(e.kind==="toml"){let a=_t(e.raw);if("value"in a){let d=wn(a.value,["mcp_servers","maind"]);if(!ee(d)||typeof d.command!="string")return null;let p=Array.isArray(d.args)?d.args.filter(f=>typeof f=="string"):[];return{command:d.command,args:p}}let l=/\[mcp_servers\.maind\]([\s\S]*?)(?=\n\[|$)/.exec(e.raw);if(!l)return null;let c=/^\s*command\s*=\s*"([^"]*)"/m.exec(l[1]),u=/^\s*args\s*=\s*\[([^\]]*)\]/m.exec(l[1]);return c?{command:c[1],args:u?[...u[1].matchAll(/"([^"]*)"/g)].map(d=>d[1]):[]}:null}let t=[],n=wV(e.raw,t,{allowTrailingComma:!0});if(t.length>0||typeof n!="object"||n===null)return null;let r=n,o=r.servers?.maind??r.mcpServers?.maind,i=o?.transport??o;return!i||typeof i.command!="string"?null:{command:i.command,args:Array.isArray(i.args)?i.args.filter(a=>typeof a=="string"):[]}}function Ti(e,t){let n=`npm i -g ${Tn}@${e}`;return t?`nvm use ${t} && ${n}`:n}function xu(e){let t=[],n=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`),r=[e.runningVersion,...e.nodeTrees.map(y=>y.bridgeVersion).filter(y=>y!==null)],o=e.latestVersion??r.sort(ny).at(-1)??e.runningVersion;e.latestVersion===null&&t.push({check:"version",level:"info",message:`doctor ${e.runningVersion}; the npm registry was not reachable, so "published" is unknown and installs are not compared.`});let i=e.nodeTrees.filter(y=>y.bridgeVersion!==null);if(e.nodeTrees.length>0){let y=e.pathWinner?.node??null,_=e.nodeTrees.find(k=>k.node===y);if(e.pathWinner===null?t.push({check:"node-trees",level:"info",message:"no `maind-mcp-bridge` on PATH \u2014 only a client configured with the bare command needs it (see client-config)."}):_&&t.push({check:"node-trees",level:"ok",message:`PATH resolves maind-mcp-bridge to the ${_.node} tree (${_.bridgeVersion??"?"}).`}),e.nvmDefault!==null){let k=e.nodeTrees.find(v=>v.node===e.nvmDefault);k&&k.bridgeVersion===null&&t.push({check:"node-trees",level:"warn",message:`the nvm default ${k.node} has no bridge installed \u2014 after \`nvm use default\` (or in a fresh shell) the bin is gone.`,fix:Ti(o,k.node)})}if(new Set(i.map(k=>k.bridgeVersion)).size>1)for(let k of i.filter(v=>ny(v.bridgeVersion,o)<0))t.push({check:"node-trees",level:"warn",message:`${k.node} carries bridge ${k.bridgeVersion}, others carry a newer one \u2014 which one runs depends on PATH order, and \`npm ls -g\` only ever shows one.`,fix:Ti(o,k.node)})}let a=!1,l=new Map,c=s((y,_)=>{let b=l.get(y)??{version:e.installVersionOf(y),clients:[]};b.clients.push(_),l.set(y,b)},"noteInstall");for(let y of e.clientConfigs){let _=oy(y);if(_===null)continue;if(y.present===!1){t.push({check:"client-config",level:"warn",message:`${y.label}: ${y.path} names maind, but the client is not installed \u2014 nothing reads this file (a leftover of an earlier install).`,fix:"maind-mcp-bridge doctor --remove-phantoms"});continue}if(a=!0,/(^|\/)npx(\.cmd)?$/.test(_.command)&&_.args.some(v=>v.includes(Tn))){t.push({check:"client-config",level:"warn",message:`${y.label} starts the bridge through npx \u2014 every cold start rebuilds better-sqlite3 and races the client's connect timeout.`,fix:`${Ti(o)}, then set "command": "maind-mcp-bridge" (no args) in ${y.path}`});continue}let k=/(^|[\\/])node(\.exe)?$/.test(_.command);if(k&&_.args.length>0){let v=_.args[0];if(!e.fileExists(v)){t.push({check:"client-config",level:"error",message:`${y.label} runs ${v}, which does not exist.`,fix:`re-run \`npx -y ${Tn}@${o} install\` to rewrite the entry`});continue}c(v,y.label)}else if(_.command.includes("/")||_.command.includes("\\")){if(!e.fileExists(_.command)){t.push({check:"client-config",level:"error",message:`${y.label} points at ${_.command}, which does not exist.`,fix:`set "command": "maind-mcp-bridge" in ${y.path} (after ${Ti(o)})`});continue}}else if(_.command==="maind-mcp-bridge"&&e.pathWinner===null){t.push({check:"client-config",level:"error",message:`${y.label} runs \`maind-mcp-bridge\`, but nothing on PATH answers to it.`,fix:Ti(o,e.nvmDefault)});continue}k||(_.command.includes("/")||_.command.includes("\\")?c(_.command,y.label):_.command==="maind-mcp-bridge"&&e.pathWinner&&c(e.pathWinner.path,y.label)),t.push({check:"client-config",level:"ok",message:`${y.label}: ${[_.command,..._.args].join(" ")}`})}if(!a&&e.plugin?.enabled!==!0&&t.push({check:"client-config",level:"warn",message:"no installed MCP client's config names a `maind` server.",fix:`npx -y ${Tn} install`}),e.latestVersion!==null)for(let[y,_]of l){let b=_.clients.join(", ");if(_.version===null)t.push({check:"version",level:"info",message:`${b}: cannot tell which bridge version ${y} is.`});else if(ny(_.version,e.latestVersion)<0){let k=/[\\/]versions[\\/]node[\\/](v[^\\/]+)[\\/]/.exec(y)?.[1]??null;t.push({check:"version",level:"warn",message:`${b} run bridge ${_.version} (${y}); published is ${e.latestVersion}. An installed bridge never updates itself. After the update, run \`maind-mcp-bridge install --hooks-only\` for hooks the new version brings (asks consent per hook).`,fix:k?Ti(e.latestVersion,k):`npx -y ${Tn}@${e.latestVersion} install`})}else t.push({check:"version",level:"ok",message:`${b} run bridge ${_.version} (published: ${e.latestVersion}).`})}for(let{dir:y,maind:_}of e.npxStaleDirs)t.push({check:"npx-cache",level:_?"error":"info",message:_?`a half-built better-sqlite3 was left in ${y} \u2014 every npx start of this maind entry now fails with ENOTEMPTY.`:`a half-built better-sqlite3 was left in ${y} (another tool's npx entry, not maind's).`,fix:`rm -rf '${y.replace(/'/g,"'\\''")}'`});let u=e.envApiKey??e.apiKey;(e.deviceId===null||!TC.test(e.deviceId))&&t.push({check:"credentials",level:"error",message:"no valid device id \u2014 the server binds keys to a device, so every call ends in 401 invalid_or_device_required.",fix:"maind-mcp-bridge --reauth"}),u===null?t.push({check:"credentials",level:"error",message:"no API key stored and none in MAIND_API_KEY.",fix:"maind-mcp-bridge --reauth"}):xV.test(u)?t.push({check:"credentials",level:e.deviceId!==null&&TC.test(e.deviceId)?"ok":"info",message:`key ${u.slice(0,12)}\u2026 present${e.envApiKey?" (from MAIND_API_KEY)":""}. Whether the server still binds it to this device only the server can say \u2014 a 401 invalid_or_device_required means re-pair.`}):t.push({check:"credentials",level:"error",message:`the ${e.envApiKey?"MAIND_API_KEY value":"stored key"} is not a maind key (mnd_<8 hex>_<56 hex>).`,fix:e.envApiKey?"fix or remove MAIND_API_KEY in the client config":"maind-mcp-bridge --reauth"});let d=e.connection;d===null?t.push({check:"connection",level:"info",message:"no connection outcome recorded yet (bridges before 0.75.0 did not record one)."}):d.outcome==="ok"||d.outcome==="paired"?t.push({check:"connection",level:"ok",message:`last connection ${d.outcome==="ok"?"succeeded":"was paired"} at ${d.at} (bridge ${d.bridge_version}).`}):t.push({check:"connection",level:"error",message:d.outcome==="auth_failed"?`the server rejected the last connection (${d.at}${d.detail?`: ${d.detail}`:""}) \u2014 maind is not reachable until this device is paired again.`:`the bridge could not sign in (${d.at}${d.detail?`: ${d.detail}`:""}) \u2014 without a key nothing reaches maind.`,fix:"run `maind-mcp-bridge --reauth` in a terminal (it opens the browser), then restart the MCP client"});let p=e.plugin?.enabled===!0;if(e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(k=>e.fileExists(k),"fileExists")}),_=e.pathWinner?e.installVersionOf(e.pathWinner.path):null,b=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`);for(let k of y){if(k.status==="missing"){if(p||k.subcommand===ie)continue;let S=(e.declinedHooks??[]).includes(k.subcommand);t.push(S?{check:"hooks",level:"info",message:`${k.event}/${k.subcommand} was declined at install and stays off \u2014 \`install --hooks-only\` asks again.`}:{check:"hooks",level:"warn",message:`${k.detail} Updating the bridge replaces the binary and never adds a hook entry (install is append-only).`,fix:`${b} install --hooks-only (adds what is missing, asks consent per hook)`});continue}if(k.status==="superseded")continue;if(k.status!=="ok"){t.push({check:"hooks",level:k.status==="broken"?"error":"warn",message:k.detail});continue}let v=k.command?/(\S+\/build\/index\.js)/.exec(k.command)?.[1]??null:null,x=v?e.installVersionOf(v):null;x!==null&&_!==null&&x!==_&&t.push({check:"hooks",level:"warn",message:`${k.event}/${k.subcommand} runs bridge ${x}, the MCP server runs ${_} \u2014 writer and reader of the presence snapshot must be the same install.`,fix:`point the hook at the same install as the server: ${e.pathWinner?.path??"maind-mcp-bridge"} ${k.subcommand}`})}t.some(k=>k.check==="hooks"&&k.level!=="info")||t.push({check:"hooks",level:"ok",message:"every wired bridge hook points at an existing install."})}if(p){let y=(e.declinedHooks??[]).includes(ie),_=e.guardMode??"off",b=y&&e.claudeSettings!==null&&wa(e.claudeSettings,{guardMode:_,fileExists:s(S=>e.fileExists(S),"fileExists")}).channel==="guard";t.push(y?b?{check:"session-start",level:"info",message:`the briefing reaches Claude Code through the guard's guard-inject (guard mode ${_}): ${ie} was declined at install, and the maind plugin keeps it off too.`}:{check:"session-start",level:"info",message:`no session-start briefing \u2014 ${ie} was declined at install, and the maind plugin keeps it off too, so Claude Code sessions see only the MCP instructions, which it cuts after ~2,000 characters.`}:{check:"session-start",level:"ok",message:`Claude Code sessions receive the briefing and the project conventions at session start from the maind plugin (${ie}).`});let k=e.plugin?.file?` (${e.plugin.file})`:"",v=e.clientConfigs.find(S=>S.key==="claude-code-user");v!==void 0&&Qg(v.raw).length>0&&t.push({check:"claude-plugin",level:"warn",message:`the maind plugin is enabled${k} and brings its own MCP server, and ${v.path} still registers a \`maind\` server \u2014 Claude Code starts both, so every maind tool is listed twice.`,fix:`${n} doctor --remove-duplicate-mcp (lists it; --yes removes exactly that entry \u2014 with Claude Code closed)`});let x=e.claudeSettings===null?[]:et(e.claudeSettings,{fileExists:s(S=>e.fileExists(S),"fileExists")}).filter(S=>S.status!=="missing"&&S.status!=="broken");x.length>0&&t.push({check:"claude-plugin",level:"info",message:`the maind plugin is enabled${k}, and ~/.claude/settings.json still wires the bridge's own hooks (${x.map(S=>S.subcommand).join(", ")}) \u2014 nothing runs twice (the plugin's copy stands down for them), but these run from settings.json, pinned to that install, instead of updating with the plugin.`,fix:`${n} doctor --remove-duplicate-hooks (lists them; --yes removes exactly those entries from settings.json)`})}if(e.claudeSettings!==null&&!p){let y=e.guardMode??"off",_=wa(e.claudeSettings,{guardMode:y,fileExists:s(x=>e.fileExists(x),"fileExists")}),k=`${e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`)} install --hooks-only`,v=(e.declinedHooks??[]).includes(ie);_.channel==="core"?t.push({check:"session-start",level:"ok",message:`Claude Code sessions receive the briefing and the project conventions at session start (${ie} hook).`}):_.core.status==="broken"?t.push({check:"session-start",level:"warn",message:`the ${ie} hook is wired, but its script is gone \u2014 sessions start without the project conventions (see the hooks finding for the fix).`}):_.channel==="guard"?t.push({check:"session-start",level:"info",message:`the briefing reaches Claude Code through the guard's guard-inject (guard mode ${y}); without the core ${ie} hook it stops when the guard is switched off.`,fix:k}):v?t.push({check:"session-start",level:"info",message:`no session-start briefing \u2014 the ${ie} hook was declined at install, so Claude Code sessions see only the MCP instructions, which it cuts after ~2,000 characters.`,fix:k}):t.push({check:"session-start",level:"warn",message:`no session-start briefing hook is wired (${ie}) \u2014 Claude Code sessions start without the project conventions; the MCP instructions that do arrive are cut after ~2,000 characters.`,fix:k})}if(e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(_=>e.fileExists(_),"fileExists")},[vV])[0];if(y.status==="superseded"){let _=e.foreignHookHosts??[],b=_.includes("cursor"),k=(e.declinedHooks??[]).includes(vn),v=e.bridgeCommand??(e.pathWinner?"maind-mcp-bridge":`npx -y ${Tn}`),x=y.remedy==="run-install"?`${v} install --hooks-only`:`replace that command in ~/.claude/settings.json with: ${v} ${vn}`,S=b?`Cursor, installed here, imports it from ~/.claude/settings.json and takes only JSON at session start \u2014 it gets plain text it cannot parse${_.includes("devin")?"; Devin Local gets text whose handling it does not document":""}`:_.includes("devin")?"Devin Local, installed here, runs it too and documents only JSON context for hooks":"it is fine in Claude Code, but Cursor and Devin Local, which import the same hooks, would get plain text";t.push({check:"hook-hosts",level:b&&!k?"warn":"info",message:`the SessionStart reminder hook still runs \`${y.command}\` \u2014 ${S}. ${vn} prints the same text in Claude Code and the right form, or nothing, everywhere else.`,fix:x})}}let f=e.repoBlocks??null,m=f?.plans.find(y=>y.keeps.some(_=>_.startsWith("team conventions block")))??null;f!==null&&po(f.plans)&&t.push({check:"repo-blocks",level:"info",message:`${f.root} still carries the maind blocks an earlier install wrote into the repository \u2014 ${vu(f.plans)}. The bridge no longer writes them (ADR-364): hooks and user-level rule files carry the same content. They stay until you remove them.`,fix:`${n} doctor --migrate-repo-blocks (lists them and changes nothing; --yes removes exactly the listed blocks)`}),m!==null&&t.push({check:"repo-blocks",level:"ok",message:`${m.rel} carries the team conventions block (install --team); the bridge keeps it current.`}),f!==null&&f.inRepo&&m===null&&(e.foreignHookHosts??[]).includes("cursor")&&t.push({check:"team-option",level:"info",message:`Cursor is installed here, and its sessionStart hook can drop the briefing in a race Cursor confirms. For teams that work mostly in Cursor, the team option puts the conventions into ${f.root}'s AGENTS.md, which Cursor reads reliably.`,fix:`${n} install --team (writes the AGENTS.md conventions block and the project .mcp.json)`});for(let y of e.channels??[]){let _=y.hooks&&y.hooks.gaps.length>0?` (not available there: ${y.hooks.gaps.join(", ")})`:"";y.state==="ok"&&y.hooks&&y.hooks.missing.length>0?t.push({check:"channels",level:"info",message:`${y.label}: ${y.hooks.wired.length} of ${y.hooks.wired.length+y.hooks.missing.length} wired \u2014 not yet: ${y.hooks.missing.join(", ")}${_}.`,fix:`${n} install --hooks-only (asks consent per hook)`}):y.state==="ok"?t.push({check:"channels",level:"ok",message:`${y.label}: ${y.path}${_}`}):y.state==="foreign"?t.push({check:"channels",level:"info",message:`${y.label}: ${y.path} is not the bridge's (no maind marker) \u2014 left as it is, so ${y.client} gets no conventions from MAIND there.`}):t.push({check:"channels",level:"info",message:`${y.label} is not set up \u2014 ${y.client} sessions get the project conventions only from the MCP instructions${f!==null&&po(f.plans)?" and the repository's old maind blocks":""}.`,fix:`${n} install --hooks-only (asks consent per hook and file)`})}let g=e.context??null;if(g!==null&&e.claudeSettings!==null){let y=et(e.claudeSettings,{fileExists:s(_=>e.fileExists(_),"fileExists")}).filter(_=>(_.subcommand==="on-prompt-context"||_.subcommand==="on-read-context")&&_.status!=="missing").map(_=>_.subcommand);if(y.length>0){let _=t.length;g.sqlite.ok?g.repoRoot!==null&&!g.indexPresent&&t.push({check:"context",level:"info",message:`${g.repoRoot} has no code index \u2014 on-read-context stays silent there, and on-prompt-context can only match conventions.`,fix:"ask your agent to run codebase_index once (or run `maind index` in the repo); the Stop hook keeps it fresh after that"}):t.push({check:"context",level:"warn",message:`${y.join(" and ")} cannot read the local code index here \u2014 no SQLite backend loads (${g.sqlite.reason}). They stay silent.`,fix:"update Node to >= 22.16 (builtin SQLite), or run `npm rebuild better-sqlite3` in the bridge's install prefix"}),y.includes("on-prompt-context")&&g.repoRoot!==null&&!g.conventionsCached&&t.push({check:"context",level:"info",message:`no conventions are cached for ${g.repoRoot} yet \u2014 on-prompt-context matches them once the MAIND MCP server has started in this repo.`}),t.length===_&&t.push({check:"context",level:"ok",message:`${y.join(" and ")}: code index and cached conventions present${g.repoRoot?` for ${g.repoRoot}`:""}.`})}}return t}function AC(e){let t=e.filter(o=>o.level==="error"&&ry.includes(o.check)).sort((o,i)=>ry.indexOf(o.check)-ry.indexOf(i.check)),n=t[0];if(n===void 0)return SV(e);let r=t.length>1?` ${t.length-1} more finding(s).`:"";return`[maind] setup problem \u2014 ${n.message}`+(n.fix?` Fix: ${n.fix}.`:"")+r+" All findings with fixes: `maind-mcp-bridge doctor` (or `npx -y @maind-dev/mcp-bridge doctor`)."}function SV(e){let t=e.find(n=>n.check==="session-start"&&n.level==="warn");return t===void 0?EV(e):`[maind] setup gap \u2014 ${t.message} Call get_session_briefing now to load them.`+(t.fix?` To add the hook, run in a terminal (append-only, asks consent per hook): ${t.fix}`:"")}function EV(e){let t=e.find(n=>n.check==="hook-hosts"&&n.level==="warn");return t===void 0?TV(e):`[maind] setup gap \u2014 ${t.message}`+(t.fix?` To switch to it, run in a terminal (asks consent, replaces only that entry): ${t.fix}`:"")}function TV(e){let t=e.find(n=>n.check==="claude-plugin"&&n.level==="warn");return t===void 0?null:`[maind] setup note \u2014 ${t.message}`+(t.fix?` To fix, run in a terminal: ${t.fix}`:"")}function CC(e){let t={error:"\u2717",warn:"!",info:"\xB7",ok:"\u2713"},n={error:0,warn:1,info:2,ok:3},r=[...e].sort((a,l)=>n[a.level]-n[l.level]).flatMap(a=>[`${t[a.level]} [${a.check}] ${a.message}`,...a.fix?[` fix: ${a.fix}`]:[]]),o=e.filter(a=>a.level==="error").length,i=e.filter(a=>a.level==="warn").length;return r.push("",o+i===0?"maind-mcp-bridge doctor: nothing to fix.":`maind-mcp-bridge doctor: ${o} error(s), ${i} warning(s).`),r.push("A running MCP client does not reload its servers \u2014 restart it after a fix."),r.join(`
|
|
870
870
|
`)+`
|
|
871
871
|
`}var Tn,vV,xV,TC,ry,Su=w(()=>{"use strict";ku();Ys();Dc();ey();va();Ne();Tn="@maind-dev/mcp-bridge",vV=Ie.find(e=>e.subcommand===vn),xV=/^mnd_[a-f0-9]{8}_[a-f0-9]{56}$/,TC=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;s(ny,"compareVersions");s(oy,"maindEntry");s(Ti,"installFix");s(xu,"diagnose");ry=["connection","client-config","npx-cache","hooks"];s(AC,"sessionStartLine");s(SV,"briefingGapLine");s(EV,"hookHostsGapLine");s(TV,"pluginDuplicateLine");s(CC,"renderFindings")});function iy(e){return e==="on"?!0:e==="off"?!1:null}function be(e=process.env,t=te()){let n=e.MAIND_GUARD;return{mode:n==="off"||n==="warn"||n==="block"?n:t?.guard_mode??"off",stopGate:t?.guard_stop_gate===!0,difficulty:iy(e.MAIND_GUARD_DIFFICULTY)??t?.guard_difficulty!==!1,capture:iy(e.MAIND_GUARD_CAPTURE)??t?.guard_capture!==!1,consult:iy(e.MAIND_GUARD_CONSULT)??t?.guard_consult!==!1}}async function fo(e,t=ve()){let n={};try{let o=await K(t);if(o!==null&&o.trim().length>0){let i=JSON.parse(o);typeof i=="object"&&i!==null&&!Array.isArray(i)&&(n=i)}}catch{}let r={...n,...e};await W(t,JSON.stringify(r,null,2)+`
|
|
872
872
|
`,384)}var Lt=w(()=>{"use strict";xe();ce();s(iy,"envSwitch");s(be,"resolveGuardConfig");s(fo,"writeGuardConfig")});var Eu=w(()=>{"use strict";Pt()});function IC(e){return[e&&CV.has(e)?e:"claude-code"]}function NC(e){return IC(e)[0]??"claude-code"}async function Ai(e){let t=e.stack??null;return jt("get_session_briefing",{tools:IC(e.clientFamily),...t&&t.languages.length>0?{languages:t.languages}:{},...t&&t.platforms.length>0?{platforms:t.platforms}:{}},e)}async function jt(e,t,n){let r=n.mcpUrl??process.env.MAIND_MCP_URL??xa,o=new AbortController,i=setTimeout(()=>o.abort(),n.timeoutMs??3e3);try{let a={"content-type":"application/json",accept:"application/json, text/event-stream",authorization:`Bearer ${n.apiKey}`,"x-maind-client-family":n.clientFamily??"claude-code","x-maind-client-version":n.bridgeVersion,"x-maind-bridge-version":n.bridgeVersion};n.deviceId&&(a["x-maind-device-id"]=n.deviceId),n.projectKey&&(a["x-maind-project-key"]=n.projectKey);let l=n.stack?Kr(n.stack):[];l.length>0&&(a["x-maind-stack"]=l.join(","));let c=await fetch(r,{method:"POST",headers:a,signal:o.signal,body:JSON.stringify({jsonrpc:"2.0",id:"guard-init",method:"initialize",params:{protocolVersion:AV,capabilities:{},clientInfo:{name:"maind-mcp-bridge-guard",version:n.bridgeVersion}}})}),u=c.headers.get("mcp-session-id"),d=(c.headers.get("content-type")??"").startsWith("text/event-stream")?await RC(c).catch(()=>""):await c.text().catch(()=>"");if(n.onInitialize){let b=null;try{let k=JSON.parse(d);typeof k.result?.instructions=="string"&&(b=k.result.instructions)}catch{b=null}n.onInitialize(b)}if(!c.ok||!u)return null;let p={...a,"mcp-session-id":u};await fetch(r,{method:"POST",headers:p,signal:o.signal,body:JSON.stringify({jsonrpc:"2.0",method:"notifications/initialized"})}).then(b=>b.text().catch(()=>"")).catch(()=>"");let f=await fetch(r,{method:"POST",headers:p,signal:o.signal,body:JSON.stringify({jsonrpc:"2.0",id:"guard-briefing",method:"tools/call",params:{name:e,arguments:t}})});if(!f.ok)return null;let g=(f.headers.get("content-type")??"").startsWith("text/event-stream")?await RC(f):await f.text();if(g.trim().length===0)return null;let y=JSON.parse(g);if(y.error||y.result?.isError)return null;let _=y.result?.content?.find(b=>b.type==="text"&&typeof b.text=="string")?.text;return typeof _=="string"&&_.trim().length>0?_:null}catch{return null}finally{clearTimeout(i)}}async function RC(e){if(!e.body)return"";let t=e.body.getReader(),n=new TextDecoder,r="",o=[],i="",a=s(()=>{if(o.length===0)return;let l=o.join(`
|