minnimemory 1.2.0 → 1.3.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/pkg/cli.js CHANGED
@@ -1,32 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  /* MinniMemoryMCP (c) 2026 MinniAI. Licensed under the MinniMemoryMCP License, see LICENSE. */
3
- import{$ as Be,A as Se,B as Oe,Ba as ze,E as Te,F as P,G as K,H as je,J as Me,Ja as qe,K as R,Ka as Ye,L as V,La as ne,M as De,O as H,Oa as Ke,P as Re,Q as Pe,Qa as oe,R as Ae,Ra as se,Sa as ie,Ta as Ve,Ua as Xe,V as Ee,Va as Qe,W as Ie,Wa as Ze,X as Ne,Xa as et,Y as Fe,Ya as ae,Z as Le,Za as de,_ as X,aa as He,b as D,fa as Ue,g as m,ha as Q,j as ye,ka as U,la as Z,ma as J,n as we,na as _,o as ke,oa as ee,p as ve,pa as te,q as be,qa as Je,r as $e,ra as _e,s as q,sa as re,t as Y,ta as We,v as xe,w as Ce,ya as Ge}from"./chunks/chunk-JPLA4NRD.js";import{spawnSync as Nt}from"node:child_process";import S from"node:fs";import Ft from"node:os";import O from"node:path";import{fileURLToPath as Lt}from"node:url";import{parseArgs as Bt}from"node:util";import $t from"node:fs";function xt(t){return t.split(/\r?\n/).map(r=>r.trim()).filter(r=>r!==""&&!r.startsWith("#"))}function tt(t){let r;try{r=$t.readFileSync(t,"utf8")}catch{throw new R(`cannot read workload file: ${t}`)}let e=xt(r);if(e.length===0)throw new R(`workload file has no tasks: ${t}
4
- one task description per line, # for comments`);return e}function W(t){return`${t.onDemandFile}:${t.startLine}`}function Ct(t){return`${t.onDemandFile} > ${t.heading}`}function St(t,r){let e=D(t).flatMap(n=>we({name:n.name,file:n.file},je(r,n.file)));return ke(e,new Map(D(t).map(n=>[n.name,n.triggers])))}function rt(t,r,e={}){let n=e.root?St(t,e.root):void 0,o=n?"section":"file",p=new Set,l=new Map,u=new Map,c=new Map;for(let i of D(t))l.set(i.name,i.tokens),u.set(i.name,i.name),c.set(i.name,i.name);if(n)for(let i of n.units)l.set(W(i),i.tokens),u.set(W(i),Ct(i)),c.set(W(i),i.onDemandFile);let h=[],v=0;r.forEach((i,b)=>{let C=n?be(ve(n,i)).map(k=>W(k.unit)):$e(t,i).filter(k=>k.score>0).map(k=>k.name);C.length===0&&v++;let $=C.filter(k=>!p.has(k));for(let k of $)p.add(k);let x=[...p].reduce((k,I)=>k+(l.get(I)??0),0);h.push({turn:b+1,task:i,opened:$.map(k=>u.get(k)??k),carried:[...p].map(k=>u.get(k)??k),compiledTokens:t.prefix.after+x,baselineTokens:t.prefix.before})});let y=h.reduce((i,b)=>i+b.compiledTokens,0),g=h.reduce((i,b)=>i+b.baselineTokens,0),w=new Set([...p].map(i=>c.get(i)??i)),T=D(t).map(i=>i.name).filter(i=>w.has(i)),E=[...p].reduce((i,b)=>i+(l.get(b)??0),0),s=t.prefix.after+E,d=t.prefix.before-s,f=g-y,a;return f>=0?(a=h.findIndex((i,b)=>h.slice(0,b+1).reduce(($,x)=>$+x.baselineTokens-x.compiledTokens,0)>=0),a=a>=0?a+1:void 0):d>0&&(a=h.length+Math.ceil(-f/d)),{unit:o,turns:h,baselineTotal:g,compiledTotal:y,saving:f,savingPct:g===0?0:f/g*100,onDemandOpened:T,onDemandNeverOpened:D(t).map(i=>i.name).filter(i=>!w.has(i)),unroutedTurns:v,steadyStatePerTurn:s,steadyStateGainPerTurn:d,breakEvenTurn:a}}function Ot(t,r){return r===0?"0.0%":`${(t/r*100).toFixed(1)}%`}function le(t){return t>=0?`saves ${m(t)}`:`costs ${m(-t)} more`}function ue(t,r){let e=[""];return e.push(` exact, over ${m(t.turns)} turns. No workload, no assumptions.`),e.push(""),e.push(` original memory file ${m(t.baselinePerTurn).padStart(8)} tokens per turn`),e.push(` compiled always-loaded ${m(t.compiledPerTurn).padStart(8)} tokens per turn`),e.push(` OnDemandMemory, all of it ${m(t.totalOnDemandTokens).padStart(8)} tokens, on demand`),e.push(""),e.push(" best case, no OnDemandMemory file ever opened"),e.push(` ${m(t.baselineTotal)} -> ${m(t.bestCaseTotal)} tokens, ${le(t.bestCaseSaving)} (${Ot(t.bestCaseSaving,t.baselineTotal)})`),e.push(""),e.push(" worst case, every OnDemandMemory file opened on turn 1 and carried"),e.push(` ${m(t.baselineTotal)} -> ${m(t.worstCaseTotal)} tokens, ${le(t.worstCaseSaving)}`),e.push(""),e.push(` break-even: ${m(t.breakEvenCarriedTokens)} tokens of OnDemandMemory can sit in`),e.push(" context from turn 1 to the end and come out even. Past that the compiled"),e.push(" shape costs more than the file it replaced."),e.push(""),e.push(` tokenizer: ${r}, an offline estimate`),e.push(""),e.join(`
5
- `)}function nt(t,r){let e=[""],n=t.turns.length;if(e.push(` MODEL, not a measurement. ${m(n)} turns from the workload you supplied.`),e.push(t.unit==="section"?" routed at section level, as recall() does: a hit carries the section, not the file.":" routed at file level, as an agent reading a whole file the OnDemandMemory list named would."),e.push(""),e.push(` memory tokens over the session ${m(t.baselineTotal)} -> ${m(t.compiledTotal)}`),e.push(` ${le(t.saving)}${t.saving>=0?` (${t.savingPct.toFixed(1)}%)`:""}`),e.push(""),t.onDemandOpened.length>0){e.push(` opened and carried (${t.onDemandOpened.length}):`);for(let o of t.onDemandOpened)e.push(` ${o}`);e.push("")}if(t.onDemandNeverOpened.length>0){e.push(` never opened (${t.onDemandNeverOpened.length}) - this is where the saving comes from:`);for(let o of t.onDemandNeverOpened)e.push(` ${o}`);e.push("")}return e.push(" one more turn, once everything this workload opens is in context:"),e.push(` ${m(t.steadyStatePerTurn)} vs ${m(t.turns[0]?.baselineTokens??0)} baseline, ${t.steadyStateGainPerTurn>=0?`saves ${m(t.steadyStateGainPerTurn)}`:`costs ${m(-t.steadyStateGainPerTurn)} more`} per turn`),e.push(""),t.saving<0&&t.steadyStateGainPerTurn<=0?(e.push(" this workload never breaks even. The OnDemandMemory files it opens are large enough that"),e.push(" carrying them costs more every turn than the original file did, so a longer"),e.push(" session loses more, not less. Splitting differently, or not compiling this"),e.push(" file at all, is the honest answer here."),e.push("")):t.saving<0&&t.breakEvenTurn!==void 0?(e.push(` behind by ${m(-t.saving)} at turn ${m(t.turns.length)}, recovering ${m(t.steadyStateGainPerTurn)} per turn:`),e.push(` breaks even around turn ${m(t.breakEvenTurn)} if nothing further opens.`),e.push("")):t.saving>=0&&t.breakEvenTurn!==void 0&&(e.push(` ahead from turn ${m(t.breakEvenTurn)} onward.`),e.push("")),t.unroutedTurns>0&&(e.push(` ${m(t.unroutedTurns)} of ${m(n)} turns matched no OnDemandMemory file at all.`),e.push(" Those turns are cheap here, but a real agent may have needed something and"),e.push(" not been routed to it. Check them before trusting the total."),e.push("")),e.push(" what this number is conditional on:"),e.push(" - your workload being what a real session looks like. It is your file;"),e.push(" the tool cannot tell whether it is representative."),t.unit==="section"?(e.push(" - every section recall() returns being carried for the rest of the session,"),e.push(" up to its token cap per turn. A real agent may widen with outline() or"),e.push(" read the whole file anyway.")):(e.push(" - every OnDemandMemory file whose triggers match being opened in full. A real"),e.push(" agent may read one and stop, or ignore one the list offered.")),e.push(" - memory tokens only. Reasoning, tool results and conversation are excluded"),e.push(" from both sides, so this ratio is not a session bill."),e.push(""),e.push(" For observed usage against a live agent, measure a real multi-turn session with"),e.push(" and without the compile. That is the only path allowed to call a number measured."),e.push(""),e.push(` tokenizer: ${r}, an offline estimate`),e.push(""),e.join(`
6
- `)}function ot(){return[""," No workload given, so only the exact bounds above are available.",""," A session number needs a workload: a file with one task description per line,"," describing what you actually do in this repo.",""," minnimemory bench --workload tasks.txt",""," minnimemory ships no default task list on purpose. A number produced from tasks"," the tool invented for itself would say more about the tool than about your repo.",""].join(`
7
- `)}import M from"node:fs";import A from"node:path";function G(t){let r=Ce(t);return r&&Se(r)?r:void 0}function at(t){return Oe(t)??`"${t.replace(/"/g,'\\"')}"`}function j(t){return t.map(at).join(" ")}function dt(t){return t.map(at)}function st(t){if(!(!t.servedDirect||!/\/_npx\//.test(t.servedDirect)))return"note: this copy lives in the npx cache, which `npm cache clean` or a newer version can remove; the registration and the hook would then stop starting. For a durable install: npm i -g minnimemory, then minnimemory install --force"}function Tt(t){if(t==="cursor")return"~/.cursor/mcp.json";if(t==="windsurf")return"~/.codeium/windsurf/mcp_config.json"}function lt(t,r){let e=[];t.write&&e.push("--profile","full","--allow-write");let n=G(t.cliPath),o=n?["node",n,"mcp",...e]:["npx","-y","minnimemory","mcp",...e],p=["claude","mcp","add","minnimemory","-s",t.scope,"--",...o],l=["claude","mcp","remove","minnimemory","-s",t.scope],u=["claude","mcp","get","minnimemory"],c=["claude","--version"],h=j(p),v=JSON.stringify({mcpServers:{minnimemory:{command:"npx",args:["-y","minnimemory","mcp",...e]}}},null,2),y={scope:t.scope,servedFlags:e,servedArgv:o,...n?{servedDirect:n}:{},addArgv:p,removeArgv:l,getArgv:u,probeArgv:c,manualLine:h,jsonSnippet:v};if(t.host&&t.host!=="json"){let g=Tt(t.host);g&&(y.hostConfigPath=g)}return y}function ut(t){return t.error!==void 0&&t.error.code==="ENOENT"}var pe="npx -y minnimemory drift";function jt(t){let r=G(t);return r?`node "${r}" drift`:pe}function Mt(t,r){let e=l=>l.replace(/\\/g,"/").toLowerCase(),n=/^\s*Command:\s*(.*)$/m.exec(t)?.[1]?.trim(),o=/^\s*Args:\s*(.*)$/m.exec(t)?.[1]?.trim(),p=e(n?`${n} ${o??""}
8
- ${t}`:t);return r.servedDirect?p.includes(e(r.servedDirect)):p.includes("npx -y minnimemory mcp")}function Dt(t){let r=/Scope:\s*(User|Project|Local)\b/i.exec(t);return r?r[1].toLowerCase():void 0}function Rt(t){return typeof t=="string"&&(t===pe||/^node "[^"]+" drift$/.test(t))}var fe="npx -y minnimemory loaded";function Pt(t){let r=G(t);return r?`node "${r}" loaded`:fe}function At(t){return typeof t=="string"&&(t===fe||/^node "[^"]+" loaded$/.test(t))}function ct(t){return[{event:"UserPromptSubmit",command:jt(t),fallback:pe,isOurs:Rt},{event:"InstructionsLoaded",command:Pt(t),fallback:fe,isOurs:At}]}function pt(t,r){let e=r.cwd??process.cwd();return t==="user"?A.join(r.configDir??A.join(r.home,".claude"),"settings.json"):t==="project"?A.join(e,".claude","settings.json"):A.join(e,".claude","settings.local.json")}function ft(t,r){let e=[];for(let n of t){if(!n||typeof n!="object")continue;let o=n.hooks;if(Array.isArray(o))for(let p of o){let l=p&&typeof p=="object"?p.command:void 0;r(l)&&e.push(l)}}return e}function mt(t){if(!M.existsSync(t))return{};try{let r=JSON.parse(M.readFileSync(t,"utf8"));return!r||typeof r!="object"||Array.isArray(r)?void 0:r}catch{return}}function ht(t,r){let e=`${JSON.stringify(r,null,2)}
9
- `,n=`${t}.minnimemory-${process.pid}.tmp`;M.writeFileSync(n,e,"utf8");try{M.renameSync(n,t)}catch{M.rmSync(n,{force:!0}),M.writeFileSync(t,e,"utf8")}}function gt(t){let r=t.hooks;return r&&typeof r=="object"&&!Array.isArray(r)?r:void 0}function Et(t,r){let e=pt(t.scope,r),n=ct(t.cliPath);if(t.dryRun)return{exitCode:0,output:n.map(c=>`would add the ${c.event} hook \`${c.command}\` to ${e}`).join(`
10
- `),path:e};let o=mt(e);if(!o)return{exitCode:1,output:`install --hook: ${e} is not valid JSON; not touched.`,path:e};let p=gt(o)??{},l=[],u=!1;for(let c of n){let h=Array.isArray(p[c.event])?[...p[c.event]]:[],v=ft(h,c.isOurs);if(v.includes(c.command)){l.push(c.event==="UserPromptSubmit"?`hook: already present in ${e}`:`hook: ${c.event} already present in ${e}`);continue}if(v.length>0){for(let y of h){let g=y&&typeof y=="object"?y.hooks:void 0;if(Array.isArray(g))for(let w of g)w&&typeof w=="object"&&c.isOurs(w.command)&&(w.command=c.command)}l.push(`hook: updated \`${v[0]}\` -> \`${c.command}\` in ${e} (${c.event}). Restart Claude Code.`)}else{let y={hooks:[{type:"command",command:c.command}]};h.push(y),l.push(`hook: added \`${c.command}\` to ${e} (${c.event}). Restart Claude Code.`)}p[c.event]=h,u=!0}return u&&(o.hooks=p,M.mkdirSync(A.dirname(e),{recursive:!0}),ht(e,o)),{exitCode:0,output:l.join(`
11
- `),path:e}}function it(t,r){let e=pt(t.scope,r),n=ct(t.cliPath);if(t.dryRun)return{exitCode:0,output:n.map(u=>`would remove the ${u.event} hook (\`${u.fallback}\` or its direct node form) from ${e}`).join(`
12
- `),path:e};if(!M.existsSync(e))return{exitCode:0,output:`hook: nothing to remove (${e} does not exist)`,path:e};let o=mt(e);if(!o)return{exitCode:1,output:`install --remove: ${e} is not valid JSON; not touched.`,path:e};let p=gt(o),l=[];for(let u of n){let c=p&&Array.isArray(p[u.event])?p[u.event]:void 0,h=c?ft(c,u.isOurs):[];if(!p||!c||h.length===0)continue;let v=c.filter(y=>{if(!y||typeof y!="object")return!0;let g=y.hooks;if(!Array.isArray(g))return!0;let w=g.filter(T=>!(T&&typeof T=="object"&&u.isOurs(T.command)));return w.length===0?!1:(y.hooks=w,!0)});v.length===0?delete p[u.event]:p[u.event]=v,l.push(`hook: removed \`${h[0]}\` from ${e}`)}return l.length===0?{exitCode:0,output:`hook: nothing to remove in ${e}`,path:e}:(p&&Object.keys(p).length===0&&delete o.hooks,ht(e,o),{exitCode:0,output:l.join(`
13
- `),path:e})}function yt(t,r,e){let n=lt(t,r),o=[];if(t.dryRun){o.push(`would run: ${j(n.removeArgv)}`);let c=it({...t,dryRun:!0},r);return o.push(c.output),{exitCode:0,output:`${o.join(`
3
+ import{$ as We,$a as dt,A as Re,Aa as W,B as Pe,Ba as nt,E as De,F as Ae,G as E,Ga as rt,H as V,I as Ee,Ja as ot,K as Ie,L as D,M as X,N as Ne,O as Q,P as Fe,Q as Le,R as Be,Ra as st,S as He,Sa as it,Ta as oe,U as H,V as Ue,W as Je,Wa as at,X as _e,Ya as se,Za as ie,_a as ae,aa as Ge,ab as lt,b as P,ba as qe,bb as ut,ca as ze,cb as ct,da as Ye,db as pt,ea as Z,eb as de,fa as Ke,fb as le,g,ga as Ve,j as $e,la as Xe,n as xe,na as ee,o as Ce,p as Se,q as Oe,qa as U,r as Me,ra as te,s as Y,sa as J,t as K,ta as _,ua as ne,v as je,va as re,w as Te,wa as Qe,xa as Ze,ya as et,za as tt}from"./chunks/chunk-AXISH7T3.js";import{spawnSync as Xt}from"node:child_process";import S from"node:fs";import Qt from"node:os";import x from"node:path";import{fileURLToPath as Zt}from"node:url";import{parseArgs as en}from"node:util";import Et from"node:fs";function It(e){return e.split(/\r?\n/).map(n=>n.trim()).filter(n=>n!==""&&!n.startsWith("#"))}function ft(e){let n;try{n=Et.readFileSync(e,"utf8")}catch{throw new D(`cannot read workload file: ${e}`)}let t=It(n);if(t.length===0)throw new D(`workload file has no tasks: ${e}
4
+ one task description per line, # for comments`);return t}function G(e){return`${e.onDemandFile}:${e.startLine}`}function Nt(e){return`${e.onDemandFile} > ${e.heading}`}function Ft(e,n){let t=P(e).flatMap(o=>xe({name:o.name,file:o.file},Ee(n,o.file)));return Ce(t,new Map(P(e).map(o=>[o.name,o.triggers])))}function mt(e,n,t={}){let o=t.root?Ft(e,t.root):void 0,r=o?"section":"file",c=new Set,u=new Map,d=new Map,l=new Map;for(let i of P(e))u.set(i.name,i.tokens),d.set(i.name,i.name),l.set(i.name,i.name);if(o)for(let i of o.units)u.set(G(i),i.tokens),d.set(G(i),Nt(i)),l.set(G(i),i.onDemandFile);let y=[],v=0;n.forEach((i,h)=>{let C=o?Oe(Se(o,i)).map(f=>G(f.unit)):Me(e,i).filter(f=>f.score>0).map(f=>f.name);C.length===0&&v++;let $=C.filter(f=>!c.has(f));for(let f of $)c.add(f);let b=[...c].reduce((f,z)=>f+(u.get(z)??0),0);y.push({turn:h+1,task:i,opened:$.map(f=>d.get(f)??f),carried:[...c].map(f=>d.get(f)??f),compiledTokens:e.prefix.after+b,baselineTokens:e.prefix.before})});let w=y.reduce((i,h)=>i+h.compiledTokens,0),m=y.reduce((i,h)=>i+h.baselineTokens,0),k=new Set([...c].map(i=>l.get(i)??i)),M=P(e).map(i=>i.name).filter(i=>k.has(i)),R=[...c].reduce((i,h)=>i+(u.get(h)??0),0),A=e.prefix.after+R,s=e.prefix.before-A,a=m-w,p;return a>=0?(p=y.findIndex((i,h)=>y.slice(0,h+1).reduce(($,b)=>$+b.baselineTokens-b.compiledTokens,0)>=0),p=p>=0?p+1:void 0):s>0&&(p=y.length+Math.ceil(-a/s)),{unit:r,turns:y,baselineTotal:m,compiledTotal:w,saving:a,savingPct:m===0?0:a/m*100,onDemandOpened:M,onDemandNeverOpened:P(e).map(i=>i.name).filter(i=>!k.has(i)),unroutedTurns:v,steadyStatePerTurn:A,steadyStateGainPerTurn:s,breakEvenTurn:p}}function Lt(e,n){return n===0?"0.0%":`${(e/n*100).toFixed(1)}%`}function ue(e){return e>=0?`saves ${g(e)}`:`costs ${g(-e)} more`}function ce(e,n){let t=[""];return t.push(` exact, over ${g(e.turns)} turns. No workload, no assumptions.`),t.push(""),t.push(` original memory file ${g(e.baselinePerTurn).padStart(8)} tokens per turn`),t.push(` compiled always-loaded ${g(e.compiledPerTurn).padStart(8)} tokens per turn`),t.push(` OnDemandMemory, all of it ${g(e.totalOnDemandTokens).padStart(8)} tokens, on demand`),t.push(""),t.push(" best case, no OnDemandMemory file ever opened"),t.push(` ${g(e.baselineTotal)} -> ${g(e.bestCaseTotal)} tokens, ${ue(e.bestCaseSaving)} (${Lt(e.bestCaseSaving,e.baselineTotal)})`),t.push(""),t.push(" worst case, every OnDemandMemory file opened on turn 1 and carried"),t.push(` ${g(e.baselineTotal)} -> ${g(e.worstCaseTotal)} tokens, ${ue(e.worstCaseSaving)}`),t.push(""),t.push(` break-even: ${g(e.breakEvenCarriedTokens)} tokens of OnDemandMemory can sit in`),t.push(" context from turn 1 to the end and come out even. Past that the compiled"),t.push(" shape costs more than the file it replaced."),t.push(""),t.push(` tokenizer: ${n}, an offline estimate`),t.push(""),t.join(`
5
+ `)}function ht(e,n){let t=[""],o=e.turns.length;if(t.push(` MODEL, not a measurement. ${g(o)} turns from the workload you supplied.`),t.push(e.unit==="section"?" routed at section level, as recall() does: a hit carries the section, not the file.":" routed at file level, as an agent reading a whole file the OnDemandMemory list named would."),t.push(""),t.push(` memory tokens over the session ${g(e.baselineTotal)} -> ${g(e.compiledTotal)}`),t.push(` ${ue(e.saving)}${e.saving>=0?` (${e.savingPct.toFixed(1)}%)`:""}`),t.push(""),e.onDemandOpened.length>0){t.push(` opened and carried (${e.onDemandOpened.length}):`);for(let r of e.onDemandOpened)t.push(` ${r}`);t.push("")}if(e.onDemandNeverOpened.length>0){t.push(` never opened (${e.onDemandNeverOpened.length}) - this is where the saving comes from:`);for(let r of e.onDemandNeverOpened)t.push(` ${r}`);t.push("")}return t.push(" one more turn, once everything this workload opens is in context:"),t.push(` ${g(e.steadyStatePerTurn)} vs ${g(e.turns[0]?.baselineTokens??0)} baseline, ${e.steadyStateGainPerTurn>=0?`saves ${g(e.steadyStateGainPerTurn)}`:`costs ${g(-e.steadyStateGainPerTurn)} more`} per turn`),t.push(""),e.saving<0&&e.steadyStateGainPerTurn<=0?(t.push(" this workload never breaks even. The OnDemandMemory files it opens are large enough that"),t.push(" carrying them costs more every turn than the original file did, so a longer"),t.push(" session loses more, not less. Splitting differently, or not compiling this"),t.push(" file at all, is the honest answer here."),t.push("")):e.saving<0&&e.breakEvenTurn!==void 0?(t.push(` behind by ${g(-e.saving)} at turn ${g(e.turns.length)}, recovering ${g(e.steadyStateGainPerTurn)} per turn:`),t.push(` breaks even around turn ${g(e.breakEvenTurn)} if nothing further opens.`),t.push("")):e.saving>=0&&e.breakEvenTurn!==void 0&&(t.push(` ahead from turn ${g(e.breakEvenTurn)} onward.`),t.push("")),e.unroutedTurns>0&&(t.push(` ${g(e.unroutedTurns)} of ${g(o)} turns matched no OnDemandMemory file at all.`),t.push(" Those turns are cheap here, but a real agent may have needed something and"),t.push(" not been routed to it. Check them before trusting the total."),t.push("")),t.push(" what this number is conditional on:"),t.push(" - your workload being what a real session looks like. It is your file;"),t.push(" the tool cannot tell whether it is representative."),e.unit==="section"?(t.push(" - every section recall() returns being carried for the rest of the session,"),t.push(" up to its token cap per turn. A real agent may widen with outline() or"),t.push(" read the whole file anyway.")):(t.push(" - every OnDemandMemory file whose triggers match being opened in full. A real"),t.push(" agent may read one and stop, or ignore one the list offered.")),t.push(" - memory tokens only. Reasoning, tool results and conversation are excluded"),t.push(" from both sides, so this ratio is not a session bill."),t.push(""),t.push(" For observed usage against a live agent, measure a real multi-turn session with"),t.push(" and without the compile. That is the only path allowed to call a number measured."),t.push(""),t.push(` tokenizer: ${n}, an offline estimate`),t.push(""),t.join(`
6
+ `)}function gt(){return[""," No workload given, so only the exact bounds above are available.",""," A session number needs a workload: a file with one task description per line,"," describing what you actually do in this repo.",""," minnimemory bench --workload tasks.txt",""," minnimemory ships no default task list on purpose. A number produced from tasks"," the tool invented for itself would say more about the tool than about your repo.",""].join(`
7
+ `)}import O from"node:fs";import T from"node:path";function I(e){let n=Te(e);return n&&Re(n)?n:void 0}function kt(e){return Pe(e)??`"${e.replace(/"/g,'\\"')}"`}function j(e){return e.map(kt).join(" ")}function vt(e){return e.map(kt)}function yt(e){if(!(!e.servedDirect||!/\/_npx\//.test(e.servedDirect)))return"note: this copy lives in the npx cache, which `npm cache clean` or a newer version can remove; the registration and the hook would then stop starting. For a durable install: npm i -g minnimemory, then minnimemory install --force"}function Bt(e){if(e==="cursor")return"~/.cursor/mcp.json";if(e==="windsurf")return"~/.codeium/windsurf/mcp_config.json"}function bt(e,n){let t=[];e.write&&t.push("--profile","full","--allow-write");let o=I(e.cliPath),r=o?["node",o,"mcp",...t]:["npx","-y","minnimemory","mcp",...t],c=["claude","mcp","add","minnimemory","-s",e.scope,"--",...r],u=["claude","mcp","remove","minnimemory","-s",e.scope],d=["claude","mcp","get","minnimemory"],l=["claude","--version"],y=j(c),v=JSON.stringify({mcpServers:{minnimemory:{command:"npx",args:["-y","minnimemory","mcp",...t]}}},null,2),w={scope:e.scope,servedFlags:t,servedArgv:r,...o?{servedDirect:o}:{},addArgv:c,removeArgv:u,getArgv:d,probeArgv:l,manualLine:y,jsonSnippet:v};if(e.host&&e.host!=="json"){let m=Bt(e.host);m&&(w.hostConfigPath=m)}return w}function $t(e){return e.error!==void 0&&e.error.code==="ENOENT"}var fe="npx -y minnimemory drift";function Ht(e){let n=I(e);return n?`node "${n}" drift`:fe}var me="npx -y minnimemory hook";function Ut(e){let n=I(e);return n?`node "${n}" hook`:me}function Jt(e){return typeof e=="string"&&(e===me||he(e,"hook"))}function _t(e,n){let t=u=>u.replace(/\\/g,"/").toLowerCase(),o=/^\s*Command:\s*(.*)$/m.exec(e)?.[1]?.trim(),r=/^\s*Args:\s*(.*)$/m.exec(e)?.[1]?.trim(),c=t(o?`${o} ${r??""}
8
+ ${e}`:e);return n.servedDirect?c.includes(t(n.servedDirect)):c.includes("npx -y minnimemory mcp")}function Wt(e){let n=/Scope:\s*(User|Project|Local)\b/i.exec(e);return n?n[1].toLowerCase():void 0}function he(e,n){let t=/^node "([^"]+)" (drift|loaded|hook)$/.exec(e);if(t===null||t[2]!==n)return!1;let o=t[1];return/minnimemory/i.test(o)||Gt(o)}function Gt(e){let n=T.dirname(e);for(let t=0;t<4;t++)try{return JSON.parse(O.readFileSync(T.join(n,"package.json"),"utf8")).name==="minnimemory"}catch{n=T.dirname(n)}return!1}function qt(e){return typeof e=="string"&&(e===fe||he(e,"drift"))}var ge="npx -y minnimemory loaded";function zt(e){let n=I(e);return n?`node "${n}" loaded`:ge}function Yt(e){return typeof e=="string"&&(e===ge||he(e,"loaded"))}function xt(e){let n=Ht(e),t=Ut(e),o=zt(e);return[{event:"UserPromptSubmit",command:n,fallback:fe,isOurs:r=>r===n||qt(r)},{event:"UserPromptSubmit",command:t,fallback:me,isOurs:r=>r===t||Jt(r)},{event:"InstructionsLoaded",command:o,fallback:ge,isOurs:r=>r===o||Yt(r)}]}function Ct(e,n){let t=n.cwd??process.cwd();return e==="user"?T.join(n.configDir??T.join(n.home,".claude"),"settings.json"):e==="project"?T.join(t,".claude","settings.json"):T.join(t,".claude","settings.local.json")}function St(e,n){let t=[];for(let o of e){if(!o||typeof o!="object")continue;let r=o.hooks;if(Array.isArray(r))for(let c of r){let u=c&&typeof c=="object"?c.command:void 0;n(u)&&t.push(u)}}return t}function Ot(e){if(!O.existsSync(e))return{};try{let n=JSON.parse(O.readFileSync(e,"utf8"));return!n||typeof n!="object"||Array.isArray(n)?void 0:n}catch{return}}function Mt(e,n){let t=`${JSON.stringify(n,null,2)}
9
+ `,o=`${e}.minnimemory-${process.pid}.tmp`;O.writeFileSync(o,t,"utf8");try{O.renameSync(o,e)}catch{O.rmSync(o,{force:!0}),O.writeFileSync(e,t,"utf8")}}function jt(e){let n=e.hooks;return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function Kt(e,n){let t=Ct(e.scope,n),o=xt(e.cliPath);if(e.dryRun)return{exitCode:0,output:o.map(l=>`would add the ${l.event} hook \`${l.command}\` to ${t}`).join(`
10
+ `),path:t};let r=Ot(t);if(!r)return{exitCode:1,output:`install --hook: ${t} is not valid JSON; not touched.`,path:t};let c=jt(r)??{},u=[],d=!1;for(let l of o){let y=Array.isArray(c[l.event])?[...c[l.event]]:[],v=St(y,l.isOurs);if(v.includes(l.command)){u.push(l.event==="UserPromptSubmit"?`hook: \`${l.fallback.split(" ").pop()}\` already present in ${t}`:`hook: ${l.event} already present in ${t}`);continue}if(v.length>0){for(let w of y){let m=w&&typeof w=="object"?w.hooks:void 0;if(Array.isArray(m))for(let k of m)k&&typeof k=="object"&&l.isOurs(k.command)&&(k.command=l.command)}u.push(`hook: updated \`${v[0]}\` -> \`${l.command}\` in ${t} (${l.event}). Restart Claude Code.`)}else{let w={hooks:[{type:"command",command:l.command}]};y.push(w),u.push(`hook: added \`${l.command}\` to ${t} (${l.event}). Restart Claude Code.`)}c[l.event]=y,d=!0}return d&&(r.hooks=c,O.mkdirSync(T.dirname(t),{recursive:!0}),Mt(t,r)),{exitCode:0,output:u.join(`
11
+ `),path:t}}function wt(e,n){let t=Ct(e.scope,n),o=xt(e.cliPath);if(e.dryRun)return{exitCode:0,output:o.map(d=>`would remove the ${d.event} hook (\`${d.fallback}\` or its direct node form) from ${t}`).join(`
12
+ `),path:t};if(!O.existsSync(t))return{exitCode:0,output:`hook: nothing to remove (${t} does not exist)`,path:t};let r=Ot(t);if(!r)return{exitCode:1,output:`install --remove: ${t} is not valid JSON; not touched.`,path:t};let c=jt(r),u=[];for(let d of o){let l=c&&Array.isArray(c[d.event])?c[d.event]:void 0,y=l?St(l,d.isOurs):[];if(!c||!l||y.length===0)continue;let v=l.filter(w=>{if(!w||typeof w!="object")return!0;let m=w.hooks;if(!Array.isArray(m))return!0;let k=m.filter(M=>!(M&&typeof M=="object"&&d.isOurs(M.command)));return k.length===0?!1:(w.hooks=k,!0)});v.length===0?delete c[d.event]:c[d.event]=v,u.push(`hook: removed \`${y[0]}\` from ${t}`)}return u.length===0?{exitCode:0,output:`hook: nothing to remove in ${t}`,path:t}:(c&&Object.keys(c).length===0&&delete r.hooks,Mt(t,r),{exitCode:0,output:u.join(`
13
+ `),path:t})}function Tt(e,n,t){let o=bt(e,n),r=[];if(e.dryRun){r.push(`would run: ${j(o.removeArgv)}`);let l=wt({...e,dryRun:!0},n);return r.push(l.output),{exitCode:0,output:`${r.join(`
14
14
  `)}
15
- `}}let p=e(n.probeArgv[0],n.probeArgv.slice(1)),l=0;if(ut(p))o.push("the claude CLI is not on PATH; skipping the MCP registration removal.");else{let c=e(n.removeArgv[0],n.removeArgv.slice(1));o.push(`ran: ${j(n.removeArgv)}`),c.code!==0?(o.push(c.stderr.trim()),l=1):c.stdout.trim()&&o.push(c.stdout.trim())}let u=it(t,r);return o.push(u.output),u.exitCode!==0&&(l=u.exitCode),{exitCode:l,output:`${o.join(`
15
+ `}}let c=t(o.probeArgv[0],o.probeArgv.slice(1)),u=0;if($t(c))r.push("the claude CLI is not on PATH; skipping the MCP registration removal.");else{let l=t(o.removeArgv[0],o.removeArgv.slice(1));r.push(`ran: ${j(o.removeArgv)}`),l.code!==0&&/no mcp server named/i.test(`${l.stdout}
16
+ ${l.stderr}`)?r.push(`nothing registered as minnimemory in ${e.scope} scope`):l.code!==0?(r.push(l.stderr.trim()),u=1):l.stdout.trim()&&r.push(l.stdout.trim())}let d=wt(e,n);return r.push(d.output),d.exitCode!==0&&(u=d.exitCode),{exitCode:u,output:`${r.join(`
16
17
  `)}
17
- `}}function It(t){let r=G(t);return`next: restart Claude Code, then ask it to clean up your memory with minnimemory; it starts with init. In a terminal: \`${r?`node "${r}" init`:"npx -y minnimemory init"} <folder> --from-log\` from your project.`}function ce(t,r,e,n){if(t.hook){let o=Et(t,r);e.push(o.output),o.exitCode!==0&&(n=o.exitCode)}return n===0&&e.push(It(t.cliPath)),{exitCode:n,output:`${e.join(`
18
+ `}}function Vt(e){let n=I(e);return`next: restart Claude Code, then ask it to clean up your memory with minnimemory; it starts with init. In a terminal: \`${n?`node "${n}" init`:"npx -y minnimemory init"} <folder> --from-log\` from your project.`}function pe(e,n,t,o){if(e.hook){let r=Kt(e,n);t.push(r.output),r.exitCode!==0&&(o=r.exitCode)}return o===0&&t.push(Vt(e.cliPath)),{exitCode:o,output:`${t.join(`
18
19
  `)}
19
- `}}function wt(t,r,e){let n=lt(t,r),o=[];if(t.hook&&t.host)return{exitCode:2,output:`--hook only applies to Claude Code
20
- `};if(t.host)return o.push(n.jsonSnippet),n.hostConfigPath?o.push("",`config file: ${n.hostConfigPath}`):o.push("",`add this under "mcpServers" in your host's MCP config file.`),{exitCode:0,output:`${o.join(`
20
+ `}}function Rt(e,n,t){let o=bt(e,n),r=[];if(e.hook&&e.host)return{exitCode:2,output:`--hook only applies to Claude Code
21
+ `};if(e.host)return r.push(o.jsonSnippet),o.hostConfigPath?r.push("",`config file: ${o.hostConfigPath}`):r.push("",`add this under "mcpServers" in your host's MCP config file.`),{exitCode:0,output:`${r.join(`
21
22
  `)}
22
- `};if(t.dryRun){t.force&&o.push(`would run: ${j(n.removeArgv)}`),o.push(`would run: ${j(n.addArgv)}`);let w=st(n);return w&&o.push(w),ce(t,r,o,0)}let p=e(n.probeArgv[0],n.probeArgv.slice(1));if(ut(p))return o.push("the claude CLI is not on PATH. Register minnimemory manually:","",` ${n.manualLine}`,"","or add this to another host's MCP config:","",n.jsonSnippet),{exitCode:2,output:`${o.join(`
23
+ `};if(e.dryRun){e.force&&r.push(`would run: ${j(o.removeArgv)}`),r.push(`would run: ${j(o.addArgv)}`);let k=yt(o);return k&&r.push(k),pe(e,n,r,0)}let c=t(o.probeArgv[0],o.probeArgv.slice(1));if($t(c))return r.push("the claude CLI is not on PATH. Register minnimemory manually:","",` ${o.manualLine}`,"","or add this to another host's MCP config:","",o.jsonSnippet),{exitCode:2,output:`${r.join(`
23
24
  `)}
24
- `};let l=e(n.getArgv[0],n.getArgv.slice(1)),u=l.code===0?Dt(l.stdout):void 0,c=u!==void 0&&u!==t.scope;c&&o.push(`minnimemory is also registered at ${u} scope; that registration is left as it is (Claude Code uses local, then project, then user).`);let h=l.code===0&&!c,v=h&&!Mt(l.stdout,n);if(h&&!t.force&&!v)return o.push("minnimemory is already registered.",`to change it: ${j(["npx","-y","minnimemory","install","--force","--scope",t.scope,...t.write?["--write"]:[]])}`),ce(t,r,o,0);if(h){v&&!t.force&&o.push("minnimemory is registered with a different command; repointing it at this copy.");let w=e(n.removeArgv[0],n.removeArgv.slice(1));if(w.code!==0)return o.push(`ran: ${j(n.removeArgv)}`,w.stderr.trim()),{exitCode:1,output:`${o.join(`
25
+ `};let u=t(o.getArgv[0],o.getArgv.slice(1)),d=u.code===0?Wt(u.stdout):void 0,l=d!==void 0&&d!==e.scope;l&&r.push(`minnimemory is also registered at ${d} scope; that registration is left as it is (Claude Code uses local, then project, then user).`);let y=u.code===0&&!l,v=y&&!_t(u.stdout,o);if(y&&!e.force&&!v)return r.push("minnimemory is already registered.",`to change it: ${j(["npx","-y","minnimemory","install","--force","--scope",e.scope,...e.write?["--write"]:[]])}`),pe(e,n,r,0);if(y){v&&!e.force&&r.push("minnimemory is registered with a different command; repointing it at this copy.");let k=t(o.removeArgv[0],o.removeArgv.slice(1));if(k.code!==0)return r.push(`ran: ${j(o.removeArgv)}`,k.stderr.trim()),{exitCode:1,output:`${r.join(`
25
26
  `)}
26
- `}}let y=e(n.addArgv[0],n.addArgv.slice(1));if(o.push(`ran: ${j(n.addArgv)}`),y.code!==0)return o.push(y.stderr.trim()),{exitCode:1,output:`${o.join(`
27
+ `}}let w=t(o.addArgv[0],o.addArgv.slice(1));if(r.push(`ran: ${j(o.addArgv)}`),w.code!==0)return r.push(w.stderr.trim()),{exitCode:1,output:`${r.join(`
27
28
  `)}
28
- `};y.stdout.trim()&&o.push(y.stdout.trim());let g=st(n);return g&&o.push(g),ce(t,r,o,0)}var Ht=!1,z=`
29
- minnimemory ${de} the agent memory compiler
29
+ `};w.stdout.trim()&&r.push(w.stdout.trim());let m=yt(o);return m&&r.push(m),pe(e,n,r,0)}var tn=!1,q=`
30
+ minnimemory ${le} the agent memory compiler
30
31
 
31
32
  usage: the four lifecycle verbs, the CLI and the MCP basic profile share.
32
33
  The only difference is who writes: the CLI writes to disk itself, the MCP tools return the
@@ -49,6 +50,8 @@ more
49
50
  minnimemory mcp [path] start the MCP server. Serves init/doctor/apply/undo by
50
51
  default; --profile full serves the seven maintainer tools
51
52
  minnimemory install register minnimemory with the current host
53
+ minnimemory uninstall remove the registration and the three hooks install added (same
54
+ as install --remove); lists folders still compiled, to undo first
52
55
  minnimemory bench <folder> what the compiled shape costs over a session
53
56
  minnimemory recall <path> <query...>
54
57
  recall against a compiled workspace or a manifest-less memory
@@ -70,8 +73,8 @@ install options
70
73
  --allow-write); the default basic profile never writes
71
74
  --dry-run print the command without running it, exit 0
72
75
  --force remove an existing registration first, then re-add
73
- --no-hook skip the drift notice hook; on by default
74
- --remove remove the MCP registration and the drift hook install added
76
+ --no-hook skip the three hooks (memory, drift notice, load log); on by default
77
+ --remove remove the MCP registration and the hooks install added (= uninstall)
75
78
  --host <name> cursor, windsurf or json: print the mcpServers snippet (and the
76
79
  config file for cursor/windsurf) to paste, instead of registering
77
80
  with Claude Code; no hook
@@ -174,6 +177,8 @@ doctor options
174
177
  --ci terse output, no colour
175
178
  --fail-on <sev> exit 1 at this severity or above: low, med, high (default high)
176
179
  --budget <n> always-loaded token budget for MM001 (default: the compiled budget, else 60% of the file, at least 2000)
180
+ --policy <file> a company rule pack (policy.json): adds MM020 required lines and MM021
181
+ banned text, and its always-loaded budget when --budget is not given
177
182
  --loaded <path> a file Claude Code loads this session (repeatable); the only way a
178
183
  file outside the named folder is read (--host-file still works)
179
184
  --memory-dir <path> the auto memory folder Claude Code names; also the folder to use
@@ -188,111 +193,118 @@ doctor options
188
193
  <folder> is required: a repo, a memory directory, or a single file. With none, minnimemory asks
189
194
  for it (in a terminal) or stops and says so. Type . for the current folder. An @import that
190
195
  points outside the folder is not read; the report names it.
191
- `;function Ut(){let t=[""," rule set",""];for(let r of De)t.push(` ${r.id.padEnd(8)}${r.severity.padEnd(6)}${r.title}`);return t.push(""),t.join(`
192
- `)}function Jt(t,r){if(t===void 0)return r;if(t==="low"||t==="med"||t==="high")return t;throw new Error(`--fail-on must be one of low, med, high (got "${t}")`)}function kt(t){return t?t.split(",").map(r=>r.trim()).filter(Boolean):[]}function _t(t,r){return t.matches.length===0?`
193
- no match for "${t.query}"
196
+ `;function nn(){let e=[""," rule set",""];for(let n of He)e.push(` ${n.id.padEnd(8)}${n.severity.padEnd(6)}${n.title}`);return e.push(""),e.join(`
197
+ `)}function rn(e,n){if(e===void 0)return n;if(e==="low"||e==="med"||e==="high")return e;throw new Error(`--fail-on must be one of low, med, high (got "${e}")`)}function Pt(e){return e?e.split(",").map(n=>n.trim()).filter(Boolean):[]}function on(e,n){return e.matches.length===0?`
198
+ no match for "${e.query}"
194
199
 
195
- `:r?`${t.matches.map(e=>`${e.onDemandFile} > ${e.path.join(" > ")} (${e.tokens} tokens)`).join(`
200
+ `:n?`${e.matches.map(t=>`${t.onDemandFile} > ${t.path.join(" > ")} (${t.tokens} tokens)`).join(`
196
201
  `)}
197
- `:`${t.matches.map(e=>`## ${e.onDemandFile} > ${e.path.join(" > ")} (lines ${e.startLine}-${e.endLine}, ${e.tokens} tokens, score ${e.score})
202
+ `:`${e.matches.map(t=>`## ${t.onDemandFile} > ${t.path.join(" > ")} (lines ${t.startLine}-${t.endLine}, ${t.tokens} tokens, score ${t.score})
198
203
 
199
- ${e.content}`).join(`
204
+ ${t.content}`).join(`
200
205
 
201
206
  ---
202
207
 
203
208
  `)}
204
- `}function Wt(t){return t.isTTY?"usage":"serve"}function vt(){return(t,r)=>{let e=process.platform==="win32",n=Nt(t,e?dt(r):r,{encoding:"utf8",shell:e});return{code:n.status,stdout:n.stdout??"",stderr:n.stderr??"",error:n.error}}}function Gt(t){if(t===void 0||t==="user")return"user";if(t==="project"||t==="local")return t;throw new Error(`--scope must be one of user, project, local (got "${t}")`)}function zt(t){if(t!==void 0){if(t==="cursor"||t==="windsurf"||t==="json")return t;throw new Error(`--host must be one of cursor, windsurf, json (got "${t}")`)}}function bt(t){if(t===void 0)return;let r=Number(t);if(!Number.isInteger(r)||r<=0||r>q)throw new Error(`--budget must be a whole number of tokens from 1 to ${q.toLocaleString("en-US")} (got "${t}")`);return Math.floor(r)}function qt(t,r){let e;try{if(e=O.resolve(t),!S.existsSync(e)||!S.statSync(e).isDirectory())throw new P(`not a directory: ${e}`)}catch(o){return o instanceof P?(process.stderr.write(`
205
- error: ${o.message}
209
+ `}function sn(e){return e.isTTY?"usage":"serve"}function Dt(){return(e,n)=>{let t=process.platform==="win32",o=Xt(e,t?vt(n):n,{encoding:"utf8",shell:t});return{code:o.status,stdout:o.stdout??"",stderr:o.stderr??"",error:o.error}}}function an(e){if(e===void 0||e==="user")return"user";if(e==="project"||e==="local")return e;throw new Error(`--scope must be one of user, project, local (got "${e}")`)}function dn(e){if(e!==void 0){if(e==="cursor"||e==="windsurf"||e==="json")return e;throw new Error(`--host must be one of cursor, windsurf, json (got "${e}")`)}}function At(e){if(e===void 0)return;let n=Number(e);if(!Number.isInteger(n)||n<=0||n>Y)throw new Error(`--budget must be a whole number of tokens from 1 to ${Y.toLocaleString("en-US")} (got "${e}")`);return Math.floor(n)}function ln(e,n){let t;try{if(t=x.resolve(e),!S.existsSync(t)||!S.statSync(t).isDirectory())throw new E(`not a directory: ${t}`)}catch(r){return r instanceof E?(process.stderr.write(`
210
+ error: ${r.message}
206
211
 
207
212
  `),2):(process.stderr.write(`
208
- unexpected error: ${o.stack??String(o)}
213
+ unexpected error: ${r.stack??String(r)}
209
214
 
210
- `),2)}let n=r.profile??"basic";return n!=="basic"&&n!=="full"?(process.stderr.write(`
211
- error: --profile must be one of basic, full (got "${n}")
215
+ `),2)}let o=n.profile??"basic";return o!=="basic"&&o!=="full"?(process.stderr.write(`
216
+ error: --profile must be one of basic, full (got "${o}")
212
217
 
213
- `),2):((async()=>{let[{StdioServerTransport:o},{createMcpServer:p}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-UJE52S2W.js")]);await p(e,{profile:n,allowWrite:r["allow-write"]===!0}).connect(new o)})().catch(o=>{process.stderr.write(`
214
- mcp server failed: ${o.message??String(o)}
215
- `),process.exitCode=1}),0)}var Yt=new Set(["init","doctor","apply","undo","bench"]);function Kt(t){if(re(process.cwd()))return!0;let r=O.resolve(t),e=S.existsSync(r)&&S.statSync(r).isFile()?O.dirname(r):r;return Z(e)==="compiled"||te(e)!==void 0}function Vt(t){let r=`minnimemory ${t} <folder>`;if(process.stdin.isTTY!==!0){process.stderr.write(`
216
- error: name the folder to read: ${r} (type . for the current folder)
218
+ `),2):((async()=>{let[{StdioServerTransport:r},{createMcpServer:c}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-V7GWYVQ6.js")]);await c(t,{profile:o,allowWrite:n["allow-write"]===!0}).connect(new r)})().catch(r=>{process.stderr.write(`
219
+ mcp server failed: ${r.message??String(r)}
220
+ `),process.exitCode=1}),0)}function un(){let e=tt(),n=[];if(e.length>0){n.push("still compiled (they keep working without minnimemory; to put the originals back, undo each one):");for(let t of e)n.push(` ${De(t)}`)}return n.push(`kept: ${x.dirname(Ze())} (init records, the load log, undo backups); delete it yourself once you have checked undo-backups/.`),n.push("restart Claude Code."),n.join(`
221
+ `)}var cn=new Set(["init","doctor","apply","undo","bench"]);function pn(e){if(W(process.cwd()))return!0;let n=ye(e);return te(n)==="compiled"||re(n)!==void 0||Q(n)!==void 0}function ye(e){let n=x.resolve(e);return S.existsSync(n)&&S.statSync(n).isFile()?x.dirname(n):n}function fn(e){if(W(process.cwd()))return;let n=ye(e);return Q(n)?Ne(n):void 0}function mn(e){let n=`minnimemory ${e} <folder>`;if(process.stdin.isTTY!==!0){process.stderr.write(`
222
+ error: name the folder to read: ${n} (type . for the current folder)
217
223
 
218
224
  `);return}process.stdout.write(`
219
- Which folder should minnimemory ${t} read? Only that folder and the folders below it are read.
220
- folder: `);let e=Xt().trim();if(e===""){process.stderr.write(`
221
- error: no folder given; run ${r}
225
+ Which folder should minnimemory ${e} read? Only that folder and the folders below it are read.
226
+ folder: `);let t=hn().trim();if(t===""){process.stderr.write(`
227
+ error: no folder given; run ${n}
222
228
 
223
- `);return}return e}function Xt(){let t=Buffer.alloc(1),r="";for(;;){let e;try{e=S.readSync(0,t,0,1,null)}catch{break}if(e===0)break;let n=t.toString("utf8");if(n===`
224
- `)break;n!=="\r"&&(r+=n)}return r}function Qt(t){let r;try{r=Bt({args:t,allowPositionals:!0,strict:!0,options:{json:{type:"boolean",default:!1},write:{type:"boolean",default:!1},force:{type:"boolean",default:!1},update:{type:"boolean",default:!1},"allow-secrets":{type:"boolean",default:!1},"episodic-json":{type:"boolean",default:!1},"allow-write":{type:"boolean",default:!1},"follow-external-imports":{type:"boolean",default:!1},"include-auto-memory":{type:"boolean",default:!1},scope:{type:"string"},"dry-run":{type:"boolean",default:!1},"auto-memory":{type:"boolean",default:!1},hook:{type:"boolean",default:!1},"no-hook":{type:"boolean",default:!1},remove:{type:"boolean",default:!1},host:{type:"string"},"host-file":{type:"string",multiple:!0},loaded:{type:"string",multiple:!0},"memory-dir":{type:"string"},"from-log":{type:"boolean",default:!1},"only-this-folder":{type:"boolean",default:!1},turns:{type:"string"},workload:{type:"string"},"whole-files":{type:"boolean",default:!1},"max-tokens":{type:"string"},headings:{type:"boolean",default:!1},dir:{type:"string"},profile:{type:"string"},plan:{type:"string"},ci:{type:"boolean",default:!1},rules:{type:"boolean",default:!1},map:{type:"boolean",default:!1},diff:{type:"string"},"fail-on":{type:"string"},budget:{type:"string"},only:{type:"string"},ignore:{type:"string"},help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",short:"v",default:!1}}})}catch(s){let d=s.message,f=/argument is ambiguous/.test(d)?`
229
+ `);return}return t}function hn(){let e=Buffer.alloc(1),n="";for(;;){let t;try{t=S.readSync(0,e,0,1,null)}catch{break}if(t===0)break;let o=e.toString("utf8");if(o===`
230
+ `)break;o!=="\r"&&(n+=o)}return n}function gn(e){let n;try{n=en({args:e,allowPositionals:!0,strict:!0,options:{json:{type:"boolean",default:!1},write:{type:"boolean",default:!1},force:{type:"boolean",default:!1},update:{type:"boolean",default:!1},"allow-secrets":{type:"boolean",default:!1},"episodic-json":{type:"boolean",default:!1},"allow-write":{type:"boolean",default:!1},"follow-external-imports":{type:"boolean",default:!1},"include-auto-memory":{type:"boolean",default:!1},scope:{type:"string"},"dry-run":{type:"boolean",default:!1},"auto-memory":{type:"boolean",default:!1},hook:{type:"boolean",default:!1},"no-hook":{type:"boolean",default:!1},remove:{type:"boolean",default:!1},host:{type:"string"},"host-file":{type:"string",multiple:!0},loaded:{type:"string",multiple:!0},"memory-dir":{type:"string"},"from-log":{type:"boolean",default:!1},"only-this-folder":{type:"boolean",default:!1},turns:{type:"string"},workload:{type:"string"},"whole-files":{type:"boolean",default:!1},"max-tokens":{type:"string"},headings:{type:"boolean",default:!1},dir:{type:"string"},profile:{type:"string"},plan:{type:"string"},ci:{type:"boolean",default:!1},rules:{type:"boolean",default:!1},map:{type:"boolean",default:!1},diff:{type:"string"},"fail-on":{type:"string"},budget:{type:"string"},policy:{type:"string"},only:{type:"string"},ignore:{type:"string"},help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",short:"v",default:!1}}})}catch(s){let a=s.message,p=/argument is ambiguous/.test(a)?`
225
231
  (a value that starts with '-' must be written as --option=value; --budget must be positive anyway)`:"";return process.stderr.write(`
226
- error: ${d}${f}
227
- ${z}`),2}let{values:e,positionals:n}=r;if(e.help)return process.stdout.write(z),0;if(e.version)return process.stdout.write(`${de}
228
- `),0;if(e.rules)return process.stdout.write(Ut()),0;let o;if(n[0]===void 0){if(Wt({isTTY:process.stdin.isTTY===!0})==="usage")return process.stdout.write(z),0;o="mcp"}else o=n[0];let p=["include-auto-memory","follow-external-imports","auto-memory"].filter(s=>e[s]===!0);p.length>0&&process.stderr.write(` note: ${p.map(s=>`--${s}`).join(", ")} no longer does anything: minnimemory reads only the folder you name
229
- `);let l=n[1]===void 0?void 0:/^~($|[\\/])/.test(n[1])?J(n[1]):n[1];if(l===void 0&&typeof e["memory-dir"]=="string"&&(l=e["memory-dir"]),l===void 0&&["doctor","apply","undo"].includes(o)){let s=re(process.cwd());s&&(l=s.target??s.memoryDir??s.project)}if(l===void 0&&Yt.has(o)&&(l=Vt(o),l===void 0))return 2;let u=l??".";if(e.diff!==void 0&&e.diff!=="summary"&&e.diff!=="full")return process.stderr.write(`
230
- error: --diff takes summary or full, not "${e.diff}"
232
+ error: ${a}${p}
233
+ ${q}`),2}let{values:t,positionals:o}=n;if(t.help)return process.stdout.write(q),0;if(t.version)return process.stdout.write(`${le}
234
+ `),0;if(t.rules)return process.stdout.write(nn()),0;let r;if(o[0]===void 0){if(sn({isTTY:process.stdin.isTTY===!0})==="usage")return process.stdout.write(q),0;r="mcp"}else r=o[0];let c=["include-auto-memory","follow-external-imports","auto-memory"].filter(s=>t[s]===!0);c.length>0&&process.stderr.write(` note: ${c.map(s=>`--${s}`).join(", ")} no longer does anything: minnimemory reads only the folder you name
235
+ `);let u=o[1]===void 0?void 0:/^~($|[\\/])/.test(o[1])?J(o[1]):o[1];if(u===void 0&&typeof t["memory-dir"]=="string"&&(u=t["memory-dir"]),u===void 0&&["doctor","apply","undo"].includes(r)){let s=W(process.cwd());s&&(u=s.target??s.memoryDir??s.project)}if(u===void 0&&cn.has(r)&&(u=mn(r),u===void 0))return 2;let d=u??".";if(t.policy!==void 0&&r!=="doctor")return process.stderr.write(`
236
+ error: --policy is a doctor option: \`minnimemory doctor <folder> --policy <file>\`
231
237
 
232
- `),2;let c=e.diff,h=[...e.loaded??[],...e["host-file"]??[]].map(s=>J(s));if(e["from-log"]===!0){let s=Ve(process.cwd());if(!s)return process.stderr.write(`
238
+ `),2;if(t.diff!==void 0&&t.diff!=="summary"&&t.diff!=="full")return process.stderr.write(`
239
+ error: --diff takes summary or full, not "${t.diff}"
240
+
241
+ `),2;let l=t.diff,y=[...t.loaded??[],...t["host-file"]??[]].map(s=>J(s));if(t["from-log"]===!0){let s=dt(process.cwd());if(!s)return process.stderr.write(`
233
242
  error: no load log for ${process.cwd()}: open Claude Code in this folder once (install adds the hook that writes it), then run this again
234
243
 
235
- `),2;for(let d of Object.keys(s.files))/\.md$/i.test(d)&&S.existsSync(d)&&h.push(O.resolve(d))}let v=typeof e["memory-dir"]=="string"?J(e["memory-dir"]):void 0,g=h.length>0||v!==void 0||e["only-this-folder"]===!0?{files:[...new Set(h)],...v?{memoryDir:v}:{},source:e["from-log"]===!0&&(e.loaded??[]).length===0?"log":"terminal",...e["only-this-folder"]===!0?{onlyThisFolder:!0}:{}}:void 0,w=g?void 0:We(process.cwd()),T={cwd:process.cwd(),...g?{reported:g}:w?{reported:w}:{}};if(o==="install"){let s;try{s={write:e.write===!0,scope:Gt(e.scope),dryRun:e["dry-run"]===!0,force:e.force===!0,host:zt(e.host),hook:e.host===void 0&&e["no-hook"]!==!0,cliPath:process.argv[1]?Zt(process.argv[1]):void 0}}catch(i){return process.stderr.write(`
236
- error: ${i.message}
244
+ `),2;for(let a of Object.keys(s.files))/\.md$/i.test(a)&&S.existsSync(a)&&y.push(x.resolve(a))}let v=typeof t["memory-dir"]=="string"?J(t["memory-dir"]):void 0,m=y.length>0||v!==void 0||t["only-this-folder"]===!0?{files:[...new Set(y)],...v?{memoryDir:v}:{},source:t["from-log"]===!0&&(t.loaded??[]).length===0?"log":"terminal",...t["only-this-folder"]===!0?{onlyThisFolder:!0}:{}}:void 0,k=m||!["doctor","apply"].includes(r)?void 0:fn(d),M=m?void 0:nt(process.cwd())??(k?Fe(ye(d)):void 0);k&&process.stderr.write(` note: this machine has no init record for this project, so ${r} uses the one in the repo: ${x.relative(process.cwd(),k).split(x.sep).join("/")||k}
245
+ `);let R={cwd:process.cwd(),...m?{reported:m}:M?{reported:M}:{}};if(r==="install"||r==="uninstall"){let s;try{s={write:t.write===!0,scope:an(t.scope),dryRun:t["dry-run"]===!0,force:t.force===!0,host:dn(t.host),hook:t.host===void 0&&t["no-hook"]!==!0,cliPath:process.argv[1]?yn(process.argv[1]):void 0}}catch(C){return process.stderr.write(`
246
+ error: ${C.message}
237
247
 
238
- `),2}let d={home:Ft.homedir(),platform:process.platform,cwd:process.cwd(),configDir:xe()},f=e.remove===!0?yt(s,d,vt()):wt(s,d,vt());return(f.exitCode===0?process.stdout:process.stderr).write(`
239
- ${f.output}
240
- `),f.exitCode}if(o==="init"||o==="apply"){if(o==="init"&&(e.write===!0||e.update===!0))return process.stderr.write(`
248
+ `),2}let a={home:Qt.homedir(),platform:process.platform,cwd:process.cwd(),configDir:je()},p=r==="uninstall"||t.remove===!0,i=p?Tt(s,a,Dt()):Rt(s,a,Dt()),h=i.exitCode===0?process.stdout:process.stderr;return h.write(`
249
+ ${i.output}
250
+ `),p&&h.write(`${un()}
251
+
252
+ `),i.exitCode}if(r==="init"||r==="apply"){if(r==="init"&&(t.write===!0||t.update===!0))return process.stderr.write(`
241
253
  error: init never writes; use apply
242
254
 
243
- `),2;let s=e.profile??"auto";if(s!=="auto"&&!ye(s))return process.stderr.write(`
255
+ `),2;let s=t.profile??"auto";if(s!=="auto"&&!$e(s))return process.stderr.write(`
244
256
  error: --profile must be one of auto, none, routing, full (got "${s}")
245
257
 
246
- `),2;let d;try{d=bt(e.budget)}catch($){return process.stderr.write(`
247
- error: ${$.message}
258
+ `),2;let a;try{a=At(t.budget)}catch(b){return process.stderr.write(`
259
+ error: ${b.message}
248
260
 
249
- `),2}let f=o==="apply",a=s==="auto"?void 0:s,i=e["episodic-json"]===!0,b=[...a?[`--profile ${a}`]:[],...i?["--episodic-json"]:[]],C={budget:d,force:e.force===!0,profileName:a,episodicJson:i,discover:T};try{if(!f){let I=S.existsSync(u)&&S.statSync(u).isFile()?O.dirname(O.resolve(u)):O.resolve(u),N;try{let B=_(u,T);B.shape==="memory-dir"&&(N=B)}catch{N=void 0}let F=N?et(N):Qe(I,{machine:!1,projectRoot:I});if(e.map===!0)return process.stdout.write(e.json?`${JSON.stringify(F,null,2)}
250
- `:ae(F)),0;e.json||process.stdout.write(ae(F));let L=oe(u,C);if(e.json){let B=JSON.parse(ie(L,l,b));process.stdout.write(`${JSON.stringify({map:Ze(F),...B},null,2)}
251
- `)}else process.stdout.write(se(L,{color:!1,ci:e.ci===!0,target:l,flags:b,diff:c}));let me=L.workspace.folderRoot??O.resolve(u),he=L.workspace.claudeMemoryFolder?me:void 0,ge=_e(process.cwd(),g?{...g,...g.memoryDir??he?{memoryDir:g.memoryDir??he}:{}}:void 0,me);return g&&!e.json&&process.stdout.write(ge?` saved what Claude Code loads here for apply, doctor and undo: ${ge}
261
+ `),2}let p=r==="apply",i=s==="auto"?void 0:s,h=t["episodic-json"]===!0,C=[...i?[`--profile ${i}`]:[],...h?["--episodic-json"]:[]],$={budget:a,force:t.force===!0,profileName:i,episodicJson:h,discover:R};try{if(!p){let we=S.existsSync(d)&&S.statSync(d).isFile()?x.dirname(x.resolve(d)):x.resolve(d),N;try{let B=_(d,R);B.shape==="memory-dir"&&(N=B)}catch{N=void 0}let F=N?pt(N):ut(we,{machine:!1,projectRoot:we});if(t.map===!0)return process.stdout.write(t.json?`${JSON.stringify(F,null,2)}
262
+ `:de(F)),0;t.json||process.stdout.write(de(F));let L=se(d,$);if(t.json){let B=JSON.parse(ae(L,u,C));process.stdout.write(`${JSON.stringify({map:ct(F),...B},null,2)}
263
+ `)}else process.stdout.write(ie(L,{color:!1,ci:t.ci===!0,target:u,flags:C,diff:l}));let ke=L.workspace.folderRoot??x.resolve(d),ve=L.workspace.claudeMemoryFolder?ke:void 0,be=et(process.cwd(),m?{...m,...m.memoryDir??ve?{memoryDir:m.memoryDir??ve}:{}}:void 0,ke);return m&&!t.json&&process.stdout.write(be?` saved what Claude Code loads here for apply, doctor and undo: ${be}
252
264
 
253
265
  `:` could not save the locations; pass them again to apply
254
266
 
255
- `),0}let $=_(u,T);if($.shape==="memory-dir"&&!$.reported)return process.stderr.write(`
267
+ `),0}let b=_(d,R);if(b.shape==="memory-dir"&&!b.reported)return process.stderr.write(`
256
268
  error: apply refused: nothing reported the files Claude Code loads, so an import of this folder's files from outside it could break. Run from Claude Code (the agent passes them), or add --from-log (Claude Code's own load log for this folder), or --loaded <path> for each file. If nothing outside this folder loads it, pass --only-this-folder. Nothing was changed.
257
269
 
258
- `),2;let x=Pe($,{budget:d??$.manifest?.budget,profileName:a,episodicJson:i});if(e.plan!==void 0&&x.plan!==e.plan)return process.stderr.write(`
259
- error: the plan on disk no longer matches --plan ${e.plan} (now ${x.plan}); run doctor again
270
+ `),2;let f=Je(b,{budget:a??b.manifest?.budget,profileName:i,episodicJson:h});if(t.plan!==void 0&&f.plan!==t.plan)return process.stderr.write(`
271
+ error: the plan on disk no longer matches --plan ${t.plan} (now ${f.plan}); run doctor again
260
272
 
261
- `),2;if(x.verdict==="nothing")return process.stdout.write(Q(x,{write:!0})),0;if(x.verdict==="leave"&&e.force!==!0)return process.stderr.write(`
262
- error: ${Ue(x)} (${x.before} -> ${x.after} tokens; break-even ${x.bounds.breakEvenCarriedTokens} tokens of OnDemandMemory open all session)
273
+ `),2;if(f.verdict==="nothing")return process.stdout.write(ee(f,{write:!0})),0;if(f.verdict==="leave"&&t.force!==!0)return process.stderr.write(`
274
+ error: ${Xe(f)} (${f.before} -> ${f.after} tokens; break-even ${f.bounds.breakEvenCarriedTokens} tokens of OnDemandMemory open all session)
263
275
  Pass --force to write it anyway.
264
276
 
265
- `),2;let k=Q(x,{write:!0,target:l});return Ae(x,{allowSecrets:e["allow-secrets"]===!0}),process.stdout.write(k),0}catch($){return $ instanceof U||$ instanceof H?(process.stderr.write(`
266
- error: ${$.message}
277
+ `),2;let z=ee(f,{write:!0,target:u});return _e(f,{allowSecrets:t["allow-secrets"]===!0}),process.stdout.write(z),0}catch(b){return b instanceof U||b instanceof H?(process.stderr.write(`
278
+ error: ${b.message}
267
279
 
268
280
  `),2):(process.stderr.write(`
269
- unexpected error: ${$.stack??String($)}
281
+ unexpected error: ${b.stack??String(b)}
270
282
 
271
- `),2)}}if(o==="undo")try{let s;try{s=_(u).folderRoot}catch(C){if(!(C instanceof U))throw C}if(!s)return process.stdout.write(`
283
+ `),2)}}if(r==="undo")try{let s;try{s=_(d).folderRoot}catch($){if(!($ instanceof U))throw $}if(!s)return process.stdout.write(`
272
284
  nothing to undo
273
285
 
274
- `),0;let d=te(s),f=d?void 0:Je(s),a=f?He(s,f):!d&&ee(s)?Fe(s):Ne(s,d);if(a.kind==="none")return!d&&ee(s)?(process.stderr.write(`
275
- error: ${Re}
286
+ `),0;let a=re(s),p=a?void 0:Qe(s),i=p?Ve(s,p):!a&&ne(s)?ze(s):qe(s,a);if(i.kind==="none")return!a&&ne(s)?(process.stderr.write(`
287
+ error: ${Ue(s)}
276
288
 
277
289
  `),2):(process.stdout.write(`
278
290
  nothing to undo
279
291
 
280
- `),0);if(a.kind==="kept-only")return process.stderr.write(`
281
- error: undo has nothing left to restore here: ${Le(a.kept)}
292
+ `),0);if(i.kind==="kept-only")return process.stderr.write(`
293
+ error: undo has nothing left to restore here: ${Ye(i.kept)}
282
294
 
283
- `),2;if(a.kind==="missing-original")return process.stderr.write(`
284
- error: no original copy under ${Y}/original/ for: ${a.files.join(", ")}.
295
+ `),2;if(i.kind==="missing-original")return process.stderr.write(`
296
+ error: no original copy under ${K}/original/ for: ${i.files.join(", ")}.
285
297
  Backups stay on the machine that ran apply (they are gitignored); on a clone, the way back is git history.
286
298
 
287
- `),2;let i=Ee(a.plan);if(i&&e.force!==!0)return process.stderr.write(`
288
- error: ${i}
299
+ `),2;let h=We(i.plan);if(h&&t.force!==!0)return process.stderr.write(`
300
+ error: ${h}
289
301
 
290
- `),2;let b=i?Ie(a.plan):void 0;return Be(a.plan),process.stdout.write(`
291
- restored ${a.plan.operations.filter(C=>C.op==="write"||C.op==="move").length} file(s) in ${s}
292
- deleted: ${a.plan.operations.filter(C=>C.op==="delete").length} path(s), ${Y}/ ${a.plan.keptBackups?.length?"kept":"included"}
293
- `+(X(a.plan)?` ${X(a.plan)}
294
- `:"")+(a.plan.left?.length?` left in place: ${a.plan.left.join(", ")} (without manifest.json undo cannot tell which files there it wrote)
295
- `:"")+(b?` the files as they were before this undo are copied to ${b.split(O.sep).join("/")}
302
+ `),2;let C=h?Ge(i.plan):void 0;return Ke(i.plan),process.stdout.write(`
303
+ restored ${i.plan.operations.filter($=>$.op==="write"||$.op==="move").length} file(s) in ${s}
304
+ deleted: ${i.plan.operations.filter($=>$.op==="delete").length} path(s), ${K}/ ${i.plan.keptBackups?.length?"kept":"included"}
305
+ `+(Z(i.plan)?` ${Z(i.plan)}
306
+ `:"")+(i.plan.left?.length?` left in place: ${i.plan.left.join(", ")} (without manifest.json undo cannot tell which files there it wrote)
307
+ `:"")+(C?` the files as they were before this undo are copied to ${C.split(x.sep).join("/")}
296
308
  `:"")+`
297
309
  `),0}catch(s){return s instanceof H?(process.stderr.write(`
298
310
  error: ${s.message}
@@ -300,53 +312,53 @@ ${f.output}
300
312
  `),2):(process.stderr.write(`
301
313
  unexpected error: ${s.stack??String(s)}
302
314
 
303
- `),2)}if(o==="mcp")return Ht?((async()=>{let[{StdioServerTransport:s},{createDisabledMcpServer:d,DISABLED_MESSAGE:f}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-UJE52S2W.js")]);process.stderr.write(`
304
- mcp: ${f}
315
+ `),2)}if(r==="mcp")return tn?((async()=>{let[{StdioServerTransport:s},{createDisabledMcpServer:a,DISABLED_MESSAGE:p}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-V7GWYVQ6.js")]);process.stderr.write(`
316
+ mcp: ${p}
305
317
 
306
- `),await d().connect(new s)})().catch(s=>{process.stderr.write(`
318
+ `),await a().connect(new s)})().catch(s=>{process.stderr.write(`
307
319
  mcp server failed: ${s.message??String(s)}
308
- `),process.exitCode=1}),0):qt(u,e);if(o==="recall"){let s=n.slice(2).join(" ").trim();if(!s)return process.stderr.write(`
320
+ `),process.exitCode=1}),0):ln(d,t);if(r==="recall"){let s=o.slice(2).join(" ").trim();if(!s)return process.stderr.write(`
309
321
  error: recall needs a query: minnimemory recall <path> <query...>
310
322
 
311
- `),2;let d;if(e["max-tokens"]!==void 0){let a=Number(e["max-tokens"]);if(!Number.isFinite(a)||a<=0)return process.stderr.write(`
312
- error: --max-tokens must be a positive number (got "${e["max-tokens"]}")
323
+ `),2;let a;if(t["max-tokens"]!==void 0){let i=Number(t["max-tokens"]);if(!Number.isFinite(i)||i<=0)return process.stderr.write(`
324
+ error: --max-tokens must be a positive number (got "${t["max-tokens"]}")
313
325
 
314
- `),2;d=Math.floor(a)}let f=O.resolve(u);try{let a=Z(f),i;if(a==="compiled")i=Me(f,K(f),s,{maxTokens:d});else if(a==="memory-dir")i=ze(f,s,{maxTokens:d});else return process.stderr.write(`
315
- error: ${f} is neither a compiled workspace (.minnimemory/manifest.json) nor a manifest-less memory directory (an index file plus topic files) - nothing for recall to query
326
+ `),2;a=Math.floor(i)}let p=x.resolve(d);try{let i=te(p),h;if(i==="compiled")h=Ie(p,V(p),s,{maxTokens:a});else if(i==="memory-dir")h=ot(p,s,{maxTokens:a});else return process.stderr.write(`
327
+ error: ${p} is neither a compiled workspace (.minnimemory/manifest.json) nor a manifest-less memory directory (an index file plus topic files) - nothing for recall to query
316
328
 
317
- `),2;return process.stdout.write(_t(i,e.headings===!0)),0}catch(a){return a instanceof P||a instanceof Ge?(process.stderr.write(`
318
- error: ${a.message}
329
+ `),2;return process.stdout.write(on(h,t.headings===!0)),0}catch(i){return i instanceof E||i instanceof rt?(process.stderr.write(`
330
+ error: ${i.message}
319
331
 
320
332
  `),2):(process.stderr.write(`
321
- unexpected error: ${a.stack??String(a)}
322
-
323
- `),2)}}if(o==="hook"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}let d;if(e["max-tokens"]!==void 0){let f=Number(e["max-tokens"]);Number.isFinite(f)&&f>0&&(d=Math.floor(f))}try{let f=ne(s),a=qe(f,{headings:e.headings===!0,maxTokens:d,dir:e.dir});a&&process.stdout.write(`${a}
324
- `)}catch(f){process.stderr.write(`
325
- hook: ${f.message??String(f)}
326
- `)}return 0}if(o==="loaded"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{Xe(JSON.parse(s))}catch{}return 0}if(o==="drift"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{let d=ne(s),f=Ye(d);f&&process.stdout.write(`${f}
327
- `)}catch(d){process.stderr.write(`
328
- drift: ${d.message??String(d)}
329
- `)}return 0}if(o==="bench")try{let s=O.resolve(u),d=K(s),f=e.turns===void 0?50:Number(e.turns);if(!Number.isFinite(f))throw new R(`--turns must be a positive whole number (got "${e.turns}")`);let a=V(d,f);if(e.workload===void 0)return e.json===!0?(process.stdout.write(`${JSON.stringify({bounds:a,tokenizer:d.tokenizer},null,2)}
330
- `),0):(process.stdout.write(ue(a,d.tokenizer)),process.stdout.write(ot()),0);let i=tt(e.workload),b=rt(d,i,e["whole-files"]===!0?{}:{root:s});return e.json===!0?(process.stdout.write(`${JSON.stringify({bounds:a,model:b,tokenizer:d.tokenizer},null,2)}
331
- `),0):(process.stdout.write(ue(a,d.tokenizer)),process.stdout.write(nt(b,d.tokenizer)),0)}catch(s){return s instanceof R||s instanceof P?(process.stderr.write(`
333
+ unexpected error: ${i.stack??String(i)}
334
+
335
+ `),2)}}if(r==="hook"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}let a;if(t["max-tokens"]!==void 0){let p=Number(t["max-tokens"]);Number.isFinite(p)&&p>0&&(a=Math.floor(p))}try{let p=oe(s),i=st(p,{headings:t.headings===!0,maxTokens:a,dir:t.dir});i&&process.stdout.write(`${i}
336
+ `)}catch(p){process.stderr.write(`
337
+ hook: ${p.message??String(p)}
338
+ `)}return 0}if(r==="loaded"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{lt(JSON.parse(s))}catch{}return 0}if(r==="drift"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{let a=oe(s),p=it(a);p&&process.stdout.write(`${p}
339
+ `)}catch(a){process.stderr.write(`
340
+ drift: ${a.message??String(a)}
341
+ `)}return 0}if(r==="bench")try{let s=x.resolve(d),a=V(s),p=t.turns===void 0?50:Number(t.turns);if(!Number.isFinite(p))throw new D(`--turns must be a positive whole number (got "${t.turns}")`);let i=X(a,p);if(t.workload===void 0)return t.json===!0?(process.stdout.write(`${JSON.stringify({bounds:i,tokenizer:a.tokenizer},null,2)}
342
+ `),0):(process.stdout.write(ce(i,a.tokenizer)),process.stdout.write(gt()),0);let h=ft(t.workload),C=mt(a,h,t["whole-files"]===!0?{}:{root:s});return t.json===!0?(process.stdout.write(`${JSON.stringify({bounds:i,model:C,tokenizer:a.tokenizer},null,2)}
343
+ `),0):(process.stdout.write(ce(i,a.tokenizer)),process.stdout.write(ht(C,a.tokenizer)),0)}catch(s){return s instanceof D||s instanceof E?(process.stderr.write(`
332
344
  error: ${s.message}
333
345
 
334
346
  `),2):(process.stderr.write(`
335
347
  unexpected error: ${s.stack??String(s)}
336
348
 
337
- `),2)}if(o!=="doctor")return process.stderr.write(`
338
- error: unknown command "${o}"
339
- ${z}`),2;if(!Kt(u))return process.stderr.write(`
340
- error: run init first: doctor checks memory init has already looked at, and init has no record for this project and ${u} has not been compiled. Run \`${Te(u)}\`.
349
+ `),2)}if(r!=="doctor")return process.stderr.write(`
350
+ error: unknown command "${r}"
351
+ ${q}`),2;if(!pn(d))return process.stderr.write(`
352
+ error: run init first: doctor checks memory init has already looked at, and init has no record for this project and ${d} has not been compiled. Run \`${Ae(d)}\`.
341
353
 
342
- `),2;let E;try{E={discover:T,budget:bt(e.budget),failOn:Jt(e["fail-on"],"high"),only:kt(e.only),ignore:kt(e.ignore),force:e.force===!0}}catch(s){return process.stderr.write(`
354
+ `),2;let A;try{let s;if(t.policy!==void 0)try{s=Be(t.policy)}catch(a){throw a instanceof Le?new Error(`--policy: ${a.message}`):a}A={discover:R,budget:At(t.budget)??s?.budgets.always_on_tokens,policy:s,failOn:rn(t["fail-on"],"high"),only:Pt(t.only),ignore:Pt(t.ignore),force:t.force===!0}}catch(s){return process.stderr.write(`
343
355
  error: ${s.message}
344
356
 
345
- `),2}try{let s=oe(u,E);if(e.json)process.stdout.write(`${ie(s,l)}
346
- `);else{let d=!e.ci&&!process.env.NO_COLOR&&process.stdout.isTTY===!0;process.stdout.write(se(s,{color:d,ci:e.ci===!0,target:l,diff:c}))}return Ke(s.audit.findings,s.config.failOn)}catch(s){return s instanceof U||s instanceof H?(process.stderr.write(`
357
+ `),2}try{let s=se(d,A);if(t.json)process.stdout.write(`${ae(s,u)}
358
+ `);else{let a=!t.ci&&!process.env.NO_COLOR&&process.stdout.isTTY===!0;process.stdout.write(ie(s,{color:a,ci:t.ci===!0,target:u,diff:l}))}return at(s.audit.findings,s.config.failOn)}catch(s){return s instanceof U||s instanceof H?(process.stderr.write(`
347
359
  error: ${s.message}
348
360
 
349
361
  `),2):(process.stderr.write(`
350
362
  unexpected error: ${s.stack??String(s)}
351
363
 
352
- `),2)}}function Zt(t){try{return S.realpathSync(t)}catch{return O.resolve(t)}}function er(){let t=process.argv[1];if(!t)return!1;try{return S.realpathSync(Lt(import.meta.url))===S.realpathSync(t)}catch{return!1}}er()&&(process.exitCode=Qt(process.argv.slice(2)));export{Ht as MCP_STASHED,Wt as defaultCommand,Qt as main};
364
+ `),2)}}function yn(e){try{return S.realpathSync(e)}catch{return x.resolve(e)}}function wn(){let e=process.argv[1];if(!e)return!1;try{return S.realpathSync(Zt(import.meta.url))===S.realpathSync(e)}catch{return!1}}wn()&&(process.exitCode=gn(process.argv.slice(2)));export{tn as MCP_STASHED,sn as defaultCommand,gn as main};
package/pkg/index.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- /**
2
- * The public type declaration for the npm package, hand-written and checked in (not generated by
3
- * tsc). pkg/index.js still runtime-exports everything src/index.ts does, but the published type
4
- * surface names only what a consumer (today, Suite/MinniMemoryMCPConnector's
5
- * `import { createMcpServer } from "minnimemory"`) actually needs. Copied by scripts/bundle.mjs
6
- * to pkg/index.d.ts on every bundle. Keep this in step with src/mcpServer.ts's real
7
- * `createMcpServer` signature and `McpServerOptions` interface by hand.
8
- */
9
-
10
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
-
12
- export interface McpServerOptions {
13
- /** "basic" (default) or "full": basic always registers doctor/init/apply/undo, read-only; full
14
- * registers the seven maintainer tools (recall, modules, outline, doctor, plan, and apply/update
15
- * behind allowWrite). */
16
- profile?: "basic" | "full";
17
- /** Adds the full profile's write tools (apply/update). No effect on basic, which is read-only
18
- * by construction. Default false. */
19
- allowWrite?: boolean;
20
- }
21
-
22
- export declare function createMcpServer(root: string, options?: McpServerOptions): McpServer;
1
+ /**
2
+ * The public type declaration for the npm package, hand-written and checked in (not generated by
3
+ * tsc). pkg/index.js still runtime-exports everything src/index.ts does, but the published type
4
+ * surface names only what an external consumer (`import { createMcpServer } from
5
+ * "minnimemory"`) actually needs. Copied by scripts/bundle.mjs
6
+ * to pkg/index.d.ts on every bundle. Keep this in step with src/mcpServer.ts's real
7
+ * `createMcpServer` signature and `McpServerOptions` interface by hand.
8
+ */
9
+
10
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
+
12
+ export interface McpServerOptions {
13
+ /** "basic" (default) or "full": basic always registers doctor/init/apply/undo, read-only; full
14
+ * registers the seven maintainer tools (recall, modules, outline, doctor, plan, and apply/update
15
+ * behind allowWrite). */
16
+ profile?: "basic" | "full";
17
+ /** Adds the full profile's write tools (apply/update). No effect on basic, which is read-only
18
+ * by construction. Default false. */
19
+ allowWrite?: boolean;
20
+ }
21
+
22
+ export declare function createMcpServer(root: string, options?: McpServerOptions): McpServer;
package/pkg/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /* MinniMemoryMCP (c) 2026 MinniAI. Licensed under the MinniMemoryMCP License, see LICENSE. */
2
- import{a as q,b as z,c as Q,d as X,e as $,m as ee,n as re,o as oe}from"./chunks/chunk-37XDFG6F.js";import{$ as D,Aa as W,Ba as g,Ca as h,Da as B,Ea as K,F as E,Fa as w,G as O,Ga as G,Ha as V,J as S,Ja as b,La as J,M as f,Ma as Y,N as c,Na as Z,O as m,Oa as j,Q as I,R as F,S as T,X as _,a as e,c as r,ca as x,d as o,e as t,f as p,g as l,h as n,ha as R,i as a,ia as L,j as i,ja as k,k as d,ka as u,l as y,la as C,na as P,pa as M,u as s,va as N,wa as H,xa as v,ya as A,za as U}from"./chunks/chunk-JPLA4NRD.js";export{X as BASIC_READ_TOOLS,$ as BASIC_WRITE_TOOLS,r as DEFAULT_CONFIG,re as DISABLED_MESSAGE,u as DiscoveryError,m as FolderError,G as HOOK_CLOSE_LINE,w as HOOK_OPEN_LINE,L as HOST_FILES,n as INSTRUCTIONS,k as LIST_FILE_NAMES,E as McpTargetError,f as RULES,A as RecallDirError,q as SERVE_TOOLS,z as SETUP_TOOLS,e as SEVERITY_ORDER,t as TOKENIZER_ID,Q as WRITE_TOOLS,o as alwaysLoaded,F as applyFolderPlan,D as applyFolderUndo,H as auditWorkspace,s as compile,oe as createDisabledMcpServer,ee as createMcpServer,d as defaultProfile,C as detectPhase,P as discover,v as doctor,p as estimateTokens,j as exitCodeFor,h as fenceCode,x as folderPlanSummary,l as formatTokens,U as getDirIndex,K as hookClose,B as hookOpen,i as isProfileName,W as listDirFiles,O as loadManifest,J as parseHookInput,I as planFolder,_ as planFolderUndo,a as profile,M as readFolderManifest,S as recall,g as recallDir,T as renderFolderFiles,R as renderFolderPlan,b as renderHook,Y as renderHuman,y as renderInstructions,Z as renderJson,N as resolveConfig,c as ruleById,V as unwrapHook};
2
+ import{a as q,b as z,c as Q,d as X,e as $,m as ee,n as re,o as oe}from"./chunks/chunk-5PBHKJLW.js";import{Da as N,Ea as H,Fa as v,G as E,Ga as A,H as O,Ha as U,Ia as W,Ja as g,K as S,Ka as h,La as B,Ma as K,Na as w,Oa as G,Pa as V,Ra as b,S as f,T as c,Ta as J,U as m,Ua as Y,Va as Z,W as I,Wa as j,X as F,Y as T,a as e,ba as _,c as r,d as o,e as t,f as p,fa as D,g as l,h as n,i as a,ia as x,j as i,k as d,l as y,na as R,oa as L,pa as k,qa as u,ra as C,ta as P,u as s,va as M}from"./chunks/chunk-AXISH7T3.js";export{X as BASIC_READ_TOOLS,$ as BASIC_WRITE_TOOLS,r as DEFAULT_CONFIG,re as DISABLED_MESSAGE,u as DiscoveryError,m as FolderError,G as HOOK_CLOSE_LINE,w as HOOK_OPEN_LINE,L as HOST_FILES,n as INSTRUCTIONS,k as LIST_FILE_NAMES,E as McpTargetError,f as RULES,A as RecallDirError,q as SERVE_TOOLS,z as SETUP_TOOLS,e as SEVERITY_ORDER,t as TOKENIZER_ID,Q as WRITE_TOOLS,o as alwaysLoaded,F as applyFolderPlan,D as applyFolderUndo,H as auditWorkspace,s as compile,oe as createDisabledMcpServer,ee as createMcpServer,d as defaultProfile,C as detectPhase,P as discover,v as doctor,p as estimateTokens,j as exitCodeFor,h as fenceCode,x as folderPlanSummary,l as formatTokens,U as getDirIndex,K as hookClose,B as hookOpen,i as isProfileName,W as listDirFiles,O as loadManifest,J as parseHookInput,I as planFolder,_ as planFolderUndo,a as profile,M as readFolderManifest,S as recall,g as recallDir,T as renderFolderFiles,R as renderFolderPlan,b as renderHook,Y as renderHuman,y as renderInstructions,Z as renderJson,N as resolveConfig,c as ruleById,V as unwrapHook};