@maind-dev/mcp-bridge 0.62.0 → 0.63.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 +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var gs=Object.defineProperty;var s=(e,t)=>gs(e,"name",{value:t,configurable:!0})
|
|
|
3
3
|
|
|
4
4
|
${i}`};return JSON.stringify({jsonrpc:"2.0",id:e,result:o})}function gf(e,t){return`NOTE (MAIND cache fallback): the MAIND MCP server was unreachable, so these project conventions were served from a local snapshot taken ${yf(e,t)}. They may be stale, and MAIND tools are unavailable until the server is reachable again.`}function yf(e,t){let n=Date.parse(e);if(Number.isNaN(n))return"at an unknown time";let r=t.getTime()-n,i=Math.floor(r/6e4);if(i<1)return"just now";if(i<60)return`${i} minute${i===1?"":"s"} ago`;let o=Math.floor(i/60);if(o<24)return`${o} hour${o===1?"":"s"} ago`;let a=Math.floor(o/24);return`${a} day${a===1?"":"s"} ago`}var Hr,hf,qe=_(()=>{"use strict";Hr=1,hf=Ss(".maind","conventions-cache.json");s(ae,"resolveRepoRoot");s(fn,"keyFingerprint");s(mn,"cachePath");s(Es,"hasInstructions");s(xs,"writeConventionsCache");s(Rs,"readConventionsCache");s(Ts,"buildCachedInitializeResponse");s(gf,"fallbackMarker");s(yf,"relativeAge")});import{existsSync as _n,mkdirSync as If,readFileSync as As,writeFileSync as Kr,chmodSync as Is}from"node:fs";import{homedir as Cf,hostname as Nf,platform as Gr,release as Pf}from"node:os";import{randomUUID as Of}from"node:crypto";import{join as Se}from"node:path";function Tt(){let e=Cf(),t=process.env;if(Gr()==="darwin")return Se(e,"Library","Application Support","maind");if(Gr()==="win32"){let r=t.APPDATA&&t.APPDATA.length>0?t.APPDATA:Se(e,"AppData","Roaming");return Se(r,"maind")}let n=t.XDG_CONFIG_HOME&&t.XDG_CONFIG_HOME.length>0?t.XDG_CONFIG_HOME:Se(e,".config");return Se(n,"maind")}function Cs(e){_n(e)||If(e,{recursive:!0,mode:448})}function U(){let e=Tt();Cs(e);let t=Se(e,Df);if(_n(t)){let r=As(t,"utf8").trim();if(Lf(r))return r}let n=Of();Kr(t,n+`
|
|
5
5
|
`,{encoding:"utf8",mode:384});try{Is(t,384)}catch{}return n}function Lf(e){return Ff.test(e)}function Br(){return Se(Tt(),Mf)}function Ee(e){let t=Tt();Cs(t);let n=Br();Kr(n,e+`
|
|
6
|
-
`,{encoding:"utf8",mode:384});try{Is(n,384)}catch{}}function O(){let e=Br();if(!_n(e))return null;let t=As(e,"utf8").trim();return t.length>0?t:null}function At(){let e=Br();_n(e)&&Kr(e,"",{encoding:"utf8",mode:384})}function Ns(){try{return`mcp-bridge-${Nf()}`}catch{return"mcp-bridge"}}function wn(e){return{os:`${Gr()} ${Pf()}`,ide:"mcp-bridge",ext_version:e,device_id:U()}}var Df,Mf,Ff,B=_(()=>{"use strict";s(Tt,"configDir");s(Cs,"ensureDir");Df="device-id",Mf="api-key";s(U,"ensureDeviceId");Ff=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;s(Lf,"isUuid");s(Br,"apiKeyPath");s(Ee,"writeApiKey");s(O,"readApiKey");s(At,"clearApiKey");s(Ns,"bridgeLabel");s(wn,"clientMeta")});var P,xe=_(()=>{"use strict";P="0.62.0"});import{execFileSync as Vf}from"node:child_process";import{createHash as qf}from"node:crypto";function Jf(e){return qf("sha256").update(e).digest("hex")}function zf(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 Yf(e){let t=zf(e);return t?Jf(t):null}function D(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&Xf.test(e))return e;let t;try{t=Vf("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Yf(t):null}var Xf,ge=_(()=>{"use strict";s(Jf,"sha256Hex");s(zf,"normalizeRemoteUrl");s(Yf,"projectKeyFromRemote");Xf=/^[a-f0-9]{64}$/;s(D,"computeProjectKey")});import Zf from"node:path";import{fileURLToPath as em}from"node:url";function tm(e,t=Zf.sep){return e.split(t).includes("_npx")}function ee(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",Gs,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):tm(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 te(){try{let e=em(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function ze(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${Us(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:Us(n)).join(" ")}function vn(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(Gs)}function Sn(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function Us(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var Gs,Ye=_(()=>{"use strict";Gs="@maind-dev/mcp-bridge";s(tm,"isEphemeralEntry");s(ee,"resolveBridgeLaunch");s(te,"currentBridgeEntry");s(ze,"launchToShellCommand");s(vn,"isNpxForm");s(Sn,"isLegacyHookForm");s(Us,"shellQuote")});import*as M from"node:fs/promises";import*as En from"node:path";async function G(e){try{return await M.readFile(e,"utf8")}catch(t){if(rm(t))return null;throw t}}async function Wr(e){await M.mkdir(e,{recursive:!0})}async function F(e,t,n){let r=En.dirname(e);await Wr(r);let i=En.join(r,`.maind-install-${process.pid}-${Date.now()}.tmp`);await M.writeFile(i,t,{encoding:"utf8",mode:n});try{await M.rename(i,e)}catch(o){if(im(o))try{await M.copyFile(i,e),await M.unlink(i).catch(()=>{}),n!==void 0&&await M.chmod(e,n).catch(()=>{});return}catch(a){throw await M.unlink(i).catch(()=>{}),a}throw await M.unlink(i).catch(()=>{}),o}}async function Js(e,t){let n=await G(e);return n===null?!1:n.split(/\r?\n/).some(i=>i.startsWith(t))}function rm(e){return zs(e)&&e.code==="ENOENT"}function im(e){return!zs(e)||process.platform!=="win32"?!1:e.code==="EEXIST"||e.code==="EPERM"||e.code==="EACCES"}function zs(e){return typeof e=="object"&&e!==null&&"code"in e}var ce=_(()=>{"use strict";s(G,"readFileSafe");s(Wr,"ensureDir");s(F,"atomicWriteFile");s(Js,"hasLinePrefix");s(rm,"isNoEnt");s(im,"isWindowsRenameFailure");s(zs,"isNodeError")});import{existsSync as km}from"node:fs";import*as ta from"node:path";function Pt(e,t={},n=zr){let r=t.fileExists??km,i=t.expectedCommand??vm,o={};if(e!==null&&e.trim().length>0)try{let a=JSON.parse(e);Jr(a)&&(o=a)}catch{}return n.map(a=>{let c={event:a.event,subcommand:a.subcommand},l=Sm(o,a.event,a.subcommand);if(l===null)return{...c,status:"missing",command:null,remedy:"run-install",detail:`${a.label} is not wired \u2014 this bridge can run '${a.subcommand}', but nothing calls it.`};let u=` Replace its command with: ${i(a.subcommand)}`;if(Sn(l))return{...c,status:"legacy",command:l,remedy:"edit-command",detail:`${a.label} still runs the retired @maind/claude-code-hook, which was folded into the bridge and is not published.`+u};if(vn(l))return{...c,status:"npx",command:l,remedy:"edit-command",detail:`${a.label} runs through 'npx' \u2014 PATH and npm's per-Node-version globals decide which bridge that is.`+u};let d=Em(l);return d!==null&&!r(d)?{...c,status:"broken",command:l,remedy:"edit-command",detail:`${a.label} points at ${d}, which does not exist \u2014 the hook fails silently on every run.`+u}:{...c,status:"ok",command:l,remedy:"none",detail:`${a.label} is wired.`}})}function Yr(e){return e.some(t=>t.status!=="ok")}function Tn(e){return e.some(t=>t.remedy==="run-install")}function vm(e){return ze(ee({entryPath:te(),nodePath:process.execPath,extraArgs:[e],isElectron:process.versions.electron!==void 0}))}function Sm(e,t,n){let r=e.hooks?.[t];if(!Array.isArray(r))return null;for(let i of r){if(!Jr(i))continue;let o=i.hooks;if(Array.isArray(o))for(let a of o){if(!Jr(a))continue;let c=a.command;if(typeof c=="string"&&c.includes(n))return c}}return null}function Em(e){for(let t of xm(e))if(t.endsWith(".js")||t.endsWith(".mjs")||t.endsWith(".cjs"))return ta.isAbsolute(t)?t:null;return null}function xm(e){let t=[],n="",r=!1;for(let i of e){if(i==="'"){r=!r;continue}if(!r&&/\s/.test(i)){n.length>0&&t.push(n),n="";continue}n+=i}return n.length>0&&t.push(n),t}function Jr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var zr,Rn,Ot=_(()=>{"use strict";Ye();zr=[{event:"SessionStart",subcommand:"on-session-start",label:"SessionStart hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-session-start' \u2014 opens a tracked session so duration and tool-call counts can be measured. Writes only to ~/.maind/state.json; nothing leaves the machine here."},{event:"PreToolUse",subcommand:"on-tool-use",label:"PreToolUse hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-tool-use' before every tool call \u2014 counts calls, and warns you on stderr when the session's token usage crosses your handoff thresholds (ADR-039). Only the tool NAME is read, never its arguments."},{event:"PreToolUse",subcommand:"on-file-write",label:"PreToolUse write-guard hook",timeout:5,matcher:"Write",consentDescription:"It runs 'maind-mcp-bridge on-file-write' before the Write tool creates a file, and before that tool only. It reads the target file PATH \u2014 never the file's contents, never any other tool's arguments \u2014 to check whether a numbered filename (ADR-262-\u2026, 0001-\u2026, RFC-12-\u2026) would claim a number a sibling branch or worktree already holds, and blocks that one Write while naming the next free number (ADR-263). Runs entirely on this machine (git + fs); nothing is uploaded. This is a SEPARATE hook from on-tool-use precisely because it reads an argument, which that one promises not to."},{event:"PreToolUse",subcommand:"on-file-edit",label:"PreToolUse edit-guard hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-file-edit' before the Edit and Write tools, and before those only. It reads the target file PATH \u2014 never the file's contents \u2014 and compares it LOCALLY against the cached peer view from this machine's own presence announces (~/.maind/presence/): when another of your sessions holds a claim or works on the same directory, it INFORMS the agent with who/where/how-fresh. The path never leaves the machine; the hook never blocks a tool call (advisory only, ADR-277). This is a SEPARATE hook from on-file-write because that one's consent covers Write alone and may deny; this one covers Edit+Write and never does."},{event:"PreToolUse",subcommand:"on-repo-health",label:"PreToolUse repo-health hook",timeout:10,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-repo-health' before the Edit and Write tools, and before those only \u2014 at most ONCE per session and repository, not on every call. It reads the target file PATH (never the file's contents) to find which repository you are editing, then inspects THAT repository with git and the filesystem: is a machine-local tooling file present in the main checkout but missing in this worktree, were dependencies never installed here, is a build older than its source, are you mid-rebase, on a detached HEAD, editing the shared base tree, or are checked-in git hooks not actually wired? Everything stays on this machine; no network call, and no file contents are read or stored. It only ever adds a note for the model and NEVER blocks a tool call. Separately consented from the other Edit/Write hooks because it inspects the repository, not just the path."},{event:"PostToolUse",subcommand:"on-write-health",label:"PostToolUse write-health hook",timeout:10,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-write-health' AFTER the Edit and Write tools, and after those only. It reads the target file PATH to decide which checks that path makes relevant, and then \u2014 this is the wider promise, which is why it is consented separately \u2014 READS THE REPOSITORY'S TRACKED SOURCE FILES FROM DISK to run them: is a registry still consistent with the design artefact it implements (only if this repo declares such a contract in .maind/spec-contracts.json), does a Tailwind class point at a theme token that does not exist (only if this repo declares theme tokens), does a new Supabase migration leave default grants in place (only if this repo has migrations). A repository without those things stays silent. File contents are read, parsed and discarded; nothing is stored and nothing is uploaded. Each finding is reported to the model at most ONCE per session, only for findings THIS branch introduces, and the hook can never block or undo an edit \u2014 PostToolUse fires after the tool has already run."},{event:"Stop",subcommand:"on-session-end",label:"Stop hook",timeout:10,consentDescription:"It runs 'maind-mcp-bridge on-session-end' \u2014 derives session communication analytics (momentum + reactions) from the transcript at session end, and flushes the session's Tier-3 counters. Gated by Tier-3 consent server-side."},{event:"Stop",subcommand:"on-index-refresh",label:"Stop index-refresh hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-index-refresh' at the end of a turn, and refreshes this repository's local code index so codebase search, trace, map, history and review answer from the current tree instead of a stale snapshot. This one READS YOUR SOURCE FILES \u2014 the ones git reports as changed \u2014 parses them, and writes symbol names and line spans to .maind/code-index.sqlite inside the repository. That is a wider promise than the other hooks make, which is why it is consented separately. Everything stays on this machine; nothing is uploaded, and no file contents are stored. It returns immediately (the work runs detached), holds one run per repository at a time, and only refreshes an index that already exists \u2014 the first build stays an explicit 'codebase_index' call."}],Rn=[{event:"SessionStart",subcommand:"guard-inject",label:"Guard inject hook",timeout:10,consentDescription:"It runs 'maind-mcp-bridge guard-inject' when a session starts (ADR-284 guard). UNLIKE every other hook, this one talks to the maind server: it fetches your session briefing from mcp.maind.dev \u2014 sending your API key, device id, project key, and the client family 'claude-code'; never file contents, never paths \u2014 and injects the result into the session context, so the briefing no longer depends on the model remembering to ask. Cache-first (~12h), so most session starts add no network call. Inactive (exit 0, no output) while guard mode is off."},{event:"PreToolUse",subcommand:"guard-gate",label:"Guard gate hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-gate' before the Edit and Write tools, and before those only. It reads the tool NAME and the session id \u2014 never the tool's arguments, never file contents \u2014 and checks LOCALLY whether this session has been briefed (injection or a maind consultation call). Warn mode (default) adds one reminder line for the model and never blocks; block mode (explicit opt-in via 'guard mode block') may DENY an un-briefed edit, naming the reason and a logged override command. Inactive while guard mode is off."},{event:"Stop",subcommand:"guard-stop",label:"Guard stop hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge guard-stop' when the session tries to finish. Only with the strict stop-gate enabled ('guard_stop_gate': true \u2014 off by default) and edits made without a review_changes run, it blocks the FIRST stop attempt with a reason so the review can happen; it never blocks twice. Reads only local state; nothing leaves the machine. Inactive while guard mode is off."},{event:"PostToolUse",subcommand:"guard-cross-observe",label:"Guard cross-session observe hook",timeout:5,matcher:"Read|Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-cross-observe' after the Read, Edit and Write tools, and after those only. It reads the target file PATH \u2014 never the file's contents \u2014 stats its modification time, and records it as this session's baseline in ~/.maind/cross-session/ (local file, TTL-pruned). That baseline is what lets the check hook detect when a parallel session, an editor, or git changes a file under you. Nothing leaves the machine. Inactive while guard mode is off."},{event:"PreToolUse",subcommand:"guard-cross-check",label:"Guard cross-session check hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-cross-check' before the Edit and Write tools, and before those only. It reads the target file PATH \u2014 never the file's contents \u2014 and compares the file's current modification time against the baseline this session last observed. If the file changed outside the session (parallel session, editor, git checkout/pull), warn mode adds one advisory telling the model to re-read and reconcile; block mode ('guard mode block') DENIES that one edit with the same instruction. Runs entirely on this machine. Inactive while guard mode is off."}];s(Pt,"inspectHookWiring");s(Yr,"hasWiringDrift");s(Tn,"needsInstallRun");s(vm,"defaultExpectedCommand");s(Sm,"findCommand");s(Em,"extractScriptPath");s(xm,"tokenize");s(Jr,"isObject")});import*as Zr from"node:path";import*as ra from"node:readline";async function ia(e,t){let n=Zr.join(e.homeDir,".claude","settings.json"),r=t.targetKey;if(e.skip)return{target:r,action:"skip",status:"skipped",detail:"--no-hook"};let i;try{i=await G(n)}catch(f){return{target:r,action:"merge",status:"failed",detail:`read: ${Xr(f)}`}}let o,a="create";if(i===null||i.trim().length===0)o={};else{a="merge";try{let f=JSON.parse(i);if(!Qr(f))return{target:r,action:"merge",status:"failed",detail:"existing settings.json is not a JSON object"};o=f}catch(f){return{target:r,action:"merge",status:"failed",detail:`parse: ${Xr(f)}`}}}let c=Tm(o,t.event,t.matchPattern);if(c!==null)return{target:r,action:"skip",status:"skipped",detail:t.skipDetail(c)};if(!e.full){if(!e.isInteractive)return{target:r,action:"skip",status:"skipped",detail:"consent-required: pass --full to write the hook non-interactively"};if(e.dryRun)return{target:r,action:"merge",status:a==="create"?"would-create":"would-merge",detail:`${n} (would prompt for consent in real run)`};if(!await Am(e.out,`
|
|
6
|
+
`,{encoding:"utf8",mode:384});try{Is(n,384)}catch{}}function O(){let e=Br();if(!_n(e))return null;let t=As(e,"utf8").trim();return t.length>0?t:null}function At(){let e=Br();_n(e)&&Kr(e,"",{encoding:"utf8",mode:384})}function Ns(){try{return`mcp-bridge-${Nf()}`}catch{return"mcp-bridge"}}function wn(e){return{os:`${Gr()} ${Pf()}`,ide:"mcp-bridge",ext_version:e,device_id:U()}}var Df,Mf,Ff,B=_(()=>{"use strict";s(Tt,"configDir");s(Cs,"ensureDir");Df="device-id",Mf="api-key";s(U,"ensureDeviceId");Ff=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;s(Lf,"isUuid");s(Br,"apiKeyPath");s(Ee,"writeApiKey");s(O,"readApiKey");s(At,"clearApiKey");s(Ns,"bridgeLabel");s(wn,"clientMeta")});var P,xe=_(()=>{"use strict";P="0.63.0"});import{execFileSync as Vf}from"node:child_process";import{createHash as qf}from"node:crypto";function Jf(e){return qf("sha256").update(e).digest("hex")}function zf(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 Yf(e){let t=zf(e);return t?Jf(t):null}function D(){let e=process.env.MAIND_PROJECT_KEY?.trim().toLowerCase();if(e&&Xf.test(e))return e;let t;try{t=Vf("git",["config","--get","remote.origin.url"],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}return t?Yf(t):null}var Xf,ge=_(()=>{"use strict";s(Jf,"sha256Hex");s(zf,"normalizeRemoteUrl");s(Yf,"projectKeyFromRemote");Xf=/^[a-f0-9]{64}$/;s(D,"computeProjectKey")});import Zf from"node:path";import{fileURLToPath as em}from"node:url";function tm(e,t=Zf.sep){return e.split(t).includes("_npx")}function ee(e){let t=e.extraArgs??[],n=s(r=>({command:"npx",args:["-y",Gs,...t],env:{},fallbackReason:r}),"npx");return e.entryPath===null?n("bridge entry path could not be resolved"):tm(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 te(){try{let e=em(import.meta.url);return e.endsWith(".js")?e:null}catch{return null}}function ze(e){let t=Object.entries(e.env).map(([n,r])=>`${n}=${Us(r)}`);return[...t,e.command,...e.args].map((n,r)=>r<t.length?n:Us(n)).join(" ")}function vn(e){return/(^|\s)npx(\s|$)/.test(e)&&e.includes(Gs)}function Sn(e){return/(^|[\s/])maind-hook(\s|$)/.test(e)?!0:/claude-code-hook[/\\]build[/\\]/.test(e)}function Us(e){return/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}var Gs,Ye=_(()=>{"use strict";Gs="@maind-dev/mcp-bridge";s(tm,"isEphemeralEntry");s(ee,"resolveBridgeLaunch");s(te,"currentBridgeEntry");s(ze,"launchToShellCommand");s(vn,"isNpxForm");s(Sn,"isLegacyHookForm");s(Us,"shellQuote")});import*as M from"node:fs/promises";import*as En from"node:path";async function G(e){try{return await M.readFile(e,"utf8")}catch(t){if(rm(t))return null;throw t}}async function Wr(e){await M.mkdir(e,{recursive:!0})}async function F(e,t,n){let r=En.dirname(e);await Wr(r);let i=En.join(r,`.maind-install-${process.pid}-${Date.now()}.tmp`);await M.writeFile(i,t,{encoding:"utf8",mode:n});try{await M.rename(i,e)}catch(o){if(im(o))try{await M.copyFile(i,e),await M.unlink(i).catch(()=>{}),n!==void 0&&await M.chmod(e,n).catch(()=>{});return}catch(a){throw await M.unlink(i).catch(()=>{}),a}throw await M.unlink(i).catch(()=>{}),o}}async function Js(e,t){let n=await G(e);return n===null?!1:n.split(/\r?\n/).some(i=>i.startsWith(t))}function rm(e){return zs(e)&&e.code==="ENOENT"}function im(e){return!zs(e)||process.platform!=="win32"?!1:e.code==="EEXIST"||e.code==="EPERM"||e.code==="EACCES"}function zs(e){return typeof e=="object"&&e!==null&&"code"in e}var ce=_(()=>{"use strict";s(G,"readFileSafe");s(Wr,"ensureDir");s(F,"atomicWriteFile");s(Js,"hasLinePrefix");s(rm,"isNoEnt");s(im,"isWindowsRenameFailure");s(zs,"isNodeError")});import{existsSync as km}from"node:fs";import*as ta from"node:path";function Pt(e,t={},n=zr){let r=t.fileExists??km,i=t.expectedCommand??vm,o={};if(e!==null&&e.trim().length>0)try{let a=JSON.parse(e);Jr(a)&&(o=a)}catch{}return n.map(a=>{let c={event:a.event,subcommand:a.subcommand},l=Sm(o,a.event,a.subcommand);if(l===null)return{...c,status:"missing",command:null,remedy:"run-install",detail:`${a.label} is not wired \u2014 this bridge can run '${a.subcommand}', but nothing calls it.`};let u=` Replace its command with: ${i(a.subcommand)}`;if(Sn(l))return{...c,status:"legacy",command:l,remedy:"edit-command",detail:`${a.label} still runs the retired @maind/claude-code-hook, which was folded into the bridge and is not published.`+u};if(vn(l))return{...c,status:"npx",command:l,remedy:"edit-command",detail:`${a.label} runs through 'npx' \u2014 PATH and npm's per-Node-version globals decide which bridge that is.`+u};let d=Em(l);return d!==null&&!r(d)?{...c,status:"broken",command:l,remedy:"edit-command",detail:`${a.label} points at ${d}, which does not exist \u2014 the hook fails silently on every run.`+u}:{...c,status:"ok",command:l,remedy:"none",detail:`${a.label} is wired.`}})}function Yr(e){return e.some(t=>t.status!=="ok")}function Tn(e){return e.some(t=>t.remedy==="run-install")}function vm(e){return ze(ee({entryPath:te(),nodePath:process.execPath,extraArgs:[e],isElectron:process.versions.electron!==void 0}))}function Sm(e,t,n){let r=e.hooks?.[t];if(!Array.isArray(r))return null;for(let i of r){if(!Jr(i))continue;let o=i.hooks;if(Array.isArray(o))for(let a of o){if(!Jr(a))continue;let c=a.command;if(typeof c=="string"&&c.includes(n))return c}}return null}function Em(e){for(let t of xm(e))if(t.endsWith(".js")||t.endsWith(".mjs")||t.endsWith(".cjs"))return ta.isAbsolute(t)?t:null;return null}function xm(e){let t=[],n="",r=!1;for(let i of e){if(i==="'"){r=!r;continue}if(!r&&/\s/.test(i)){n.length>0&&t.push(n),n="";continue}n+=i}return n.length>0&&t.push(n),t}function Jr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var zr,Rn,Ot=_(()=>{"use strict";Ye();zr=[{event:"SessionStart",subcommand:"on-session-start",label:"SessionStart hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-session-start' \u2014 opens a tracked session so duration and tool-call counts can be measured. Writes only to ~/.maind/state.json; nothing leaves the machine here."},{event:"PreToolUse",subcommand:"on-tool-use",label:"PreToolUse hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-tool-use' before every tool call \u2014 counts calls, and warns you on stderr when the session's token usage crosses your handoff thresholds (ADR-039). Only the tool NAME is read, never its arguments."},{event:"PreToolUse",subcommand:"on-file-write",label:"PreToolUse write-guard hook",timeout:5,matcher:"Write",consentDescription:"It runs 'maind-mcp-bridge on-file-write' before the Write tool creates a file, and before that tool only. It reads the target file PATH \u2014 never the file's contents, never any other tool's arguments \u2014 to check whether a numbered filename (ADR-262-\u2026, 0001-\u2026, RFC-12-\u2026) would claim a number a sibling branch or worktree already holds, and blocks that one Write while naming the next free number (ADR-263). Runs entirely on this machine (git + fs); nothing is uploaded. This is a SEPARATE hook from on-tool-use precisely because it reads an argument, which that one promises not to."},{event:"PreToolUse",subcommand:"on-file-edit",label:"PreToolUse edit-guard hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-file-edit' before the Edit and Write tools, and before those only. It reads the target file PATH \u2014 never the file's contents \u2014 and compares it LOCALLY against the cached peer view from this machine's own presence announces (~/.maind/presence/): when another of your sessions holds a claim or works on the same directory, it INFORMS the agent with who/where/how-fresh. The path never leaves the machine; the hook never blocks a tool call (advisory only, ADR-277). This is a SEPARATE hook from on-file-write because that one's consent covers Write alone and may deny; this one covers Edit+Write and never does."},{event:"PreToolUse",subcommand:"on-repo-health",label:"PreToolUse repo-health hook",timeout:10,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-repo-health' before the Edit and Write tools, and before those only \u2014 at most ONCE per session and repository, not on every call. It reads the target file PATH (never the file's contents) to find which repository you are editing, then inspects THAT repository with git and the filesystem: is a machine-local tooling file present in the main checkout but missing in this worktree, were dependencies never installed here, is a build older than its source, are you mid-rebase, on a detached HEAD, editing the shared base tree, or are checked-in git hooks not actually wired? Everything stays on this machine; no network call, and no file contents are read or stored. It only ever adds a note for the model and NEVER blocks a tool call. Separately consented from the other Edit/Write hooks because it inspects the repository, not just the path."},{event:"PostToolUse",subcommand:"on-write-health",label:"PostToolUse write-health hook",timeout:10,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge on-write-health' AFTER the Edit and Write tools, and after those only. It reads the target file PATH to decide which checks that path makes relevant, and then \u2014 this is the wider promise, which is why it is consented separately \u2014 READS THE REPOSITORY'S TRACKED SOURCE FILES FROM DISK to run them: is a registry still consistent with the design artefact it implements (only if this repo declares such a contract in .maind/spec-contracts.json), does a Tailwind class point at a theme token that does not exist (only if this repo declares theme tokens), does a new Supabase migration leave default grants in place (only if this repo has migrations). A repository without those things stays silent. File contents are read, parsed and discarded; nothing is stored and nothing is uploaded. Each finding is reported to the model at most ONCE per session, only for findings THIS branch introduces, and the hook can never block or undo an edit \u2014 PostToolUse fires after the tool has already run."},{event:"Stop",subcommand:"on-session-end",label:"Stop hook",timeout:10,consentDescription:"It runs 'maind-mcp-bridge on-session-end' \u2014 derives session communication analytics (momentum + reactions) from the transcript at session end, and flushes the session's Tier-3 counters. Gated by Tier-3 consent server-side."},{event:"Stop",subcommand:"on-index-refresh",label:"Stop index-refresh hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge on-index-refresh' at the end of a turn, and refreshes this repository's local code index so codebase search, trace, map, history and review answer from the current tree instead of a stale snapshot. This one READS YOUR SOURCE FILES \u2014 the ones git reports as changed \u2014 parses them, and writes symbol names and line spans to .maind/code-index.sqlite inside the repository. That is a wider promise than the other hooks make, which is why it is consented separately. Everything stays on this machine; nothing is uploaded, and no file contents are stored. It returns immediately (the work runs detached), holds one run per repository at a time, and only refreshes an index that already exists \u2014 the first build stays an explicit 'codebase_index' call."}],Rn=[{event:"SessionStart",subcommand:"guard-inject",label:"Guard inject hook",timeout:10,consentDescription:"It runs 'maind-mcp-bridge guard-inject' when a session starts (ADR-284 guard). UNLIKE every other hook, this one talks to the maind server: it fetches your session briefing from mcp.maind.dev \u2014 sending your API key, device id, project key, and the client family 'claude-code'; never file contents, never paths \u2014 and injects the result into the session context, so the briefing no longer depends on the model remembering to ask. Cache-first (~12h), so most session starts add no network call. Inactive (exit 0, no output) while guard mode is off."},{event:"PreToolUse",subcommand:"guard-gate",label:"Guard gate hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-gate' before the Edit and Write tools, and before those only. It reads the tool NAME and the session id \u2014 never the tool's arguments, never file contents \u2014 and checks LOCALLY whether this session has been briefed (injection or a maind consultation call). Warn mode (default) adds one reminder line for the model and never blocks; block mode (explicit opt-in via 'guard mode block') may DENY an un-briefed edit, naming the reason and a logged override command. Inactive while guard mode is off."},{event:"Stop",subcommand:"guard-stop",label:"Guard stop hook",timeout:5,consentDescription:"It runs 'maind-mcp-bridge guard-stop' when the session tries to finish. Only with the strict stop-gate enabled ('guard_stop_gate': true \u2014 off by default) and edits made without a review_changes run, it blocks the FIRST stop attempt with a reason so the review can happen; it never blocks twice. Reads only local state; nothing leaves the machine. Inactive while guard mode is off."},{event:"PostToolUse",subcommand:"guard-cross-observe",label:"Guard cross-session observe hook",timeout:5,matcher:"Read|Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-cross-observe' after the Read, Edit and Write tools, and after those only. It reads the target file PATH \u2014 never the file's contents \u2014 stats its modification time, and records it as this session's baseline in ~/.maind/cross-session/ (local file, TTL-pruned). That baseline is what lets the check hook detect when a parallel session, an editor, or git changes a file under you. Nothing leaves the machine. Inactive while guard mode is off."},{event:"PreToolUse",subcommand:"guard-cross-check",label:"Guard cross-session check hook",timeout:5,matcher:"Edit|Write",consentDescription:"It runs 'maind-mcp-bridge guard-cross-check' before the Edit and Write tools, and before those only. It reads the target file PATH \u2014 never the file's contents \u2014 and compares the file's current modification time against the baseline this session last observed. If the file changed outside the session (parallel session, editor, git checkout/pull), warn mode adds one advisory telling the model to re-read and reconcile; block mode ('guard mode block') DENIES that one edit with the same instruction. Runs entirely on this machine. Inactive while guard mode is off."}];s(Pt,"inspectHookWiring");s(Yr,"hasWiringDrift");s(Tn,"needsInstallRun");s(vm,"defaultExpectedCommand");s(Sm,"findCommand");s(Em,"extractScriptPath");s(xm,"tokenize");s(Jr,"isObject")});import*as Zr from"node:path";import*as ra from"node:readline";async function ia(e,t){let n=Zr.join(e.homeDir,".claude","settings.json"),r=t.targetKey;if(e.skip)return{target:r,action:"skip",status:"skipped",detail:"--no-hook"};let i;try{i=await G(n)}catch(f){return{target:r,action:"merge",status:"failed",detail:`read: ${Xr(f)}`}}let o,a="create";if(i===null||i.trim().length===0)o={};else{a="merge";try{let f=JSON.parse(i);if(!Qr(f))return{target:r,action:"merge",status:"failed",detail:"existing settings.json is not a JSON object"};o=f}catch(f){return{target:r,action:"merge",status:"failed",detail:`parse: ${Xr(f)}`}}}let c=Tm(o,t.event,t.matchPattern);if(c!==null)return{target:r,action:"skip",status:"skipped",detail:t.skipDetail(c)};if(!e.full){if(!e.isInteractive)return{target:r,action:"skip",status:"skipped",detail:"consent-required: pass --full to write the hook non-interactively"};if(e.dryRun)return{target:r,action:"merge",status:a==="create"?"would-create":"would-merge",detail:`${n} (would prompt for consent in real run)`};if(!await Am(e.out,`
|
|
7
7
|
Merge a ${t.event} hook into ${n}?
|
|
8
8
|
${t.consentDescription}
|
|
9
9
|
[Y/n]: `))return{target:r,action:"skip",status:"skipped",detail:"user declined"}}let l={...t.matcher===void 0?{}:{matcher:t.matcher},hooks:[{type:"command",command:t.command,timeout:t.timeout}]},u=o.hooks?.[t.event]??[],d={...o,hooks:{...o.hooks??{},[t.event]:[...u,l]}},p=JSON.stringify(d,null,2)+`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maind-dev/mcp-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Local MCP bridge for maind.dev — wraps any MCP-compatible client (Claude Code, Cursor, Windsurf) and pins your API key to a single device via the maind device authorization flow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|