minnimemory 1.0.0 → 1.2.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,54 +1,55 @@
1
1
  #!/usr/bin/env node
2
2
  /* MinniMemoryMCP (c) 2026 MinniAI. Licensed under the MinniMemoryMCP License, see LICENSE. */
3
- import{a as xe,d as Se,g as Oe,h as Ce,i as W}from"./chunks/chunk-QDDKAHAE.js";import{$ as we,A as E,B as J,C as ue,E as de,F as C,G as U,H as ce,J as R,K as pe,L as me,P as fe,Q as he,R as ge,S as ye,X as _,_ as N,b as O,ba as G,ca as ke,da as ve,ea as be,fa as $e,g as ne,ga as z,l as f,ma as Te,n as re,o as oe,oa as q,p as se,pa as Y,q as ie,qa as V,r as ae,ra as K,s as B,u as le,v as I}from"./chunks/chunk-QUL7N4BR.js";import{spawnSync as lt}from"node:child_process";import S from"node:fs";import ut from"node:os";import b from"node:path";import{fileURLToPath as dt}from"node:url";import{parseArgs as ct}from"node:util";import Ve from"node:fs";function Ke(e){return e.split(/\r?\n/).map(s=>s.trim()).filter(s=>s!==""&&!s.startsWith("#"))}function Me(e){let s;try{s=Ve.readFileSync(e,"utf8")}catch{throw new C(`cannot read workload file: ${e}`)}let t=Ke(s);if(t.length===0)throw new C(`workload file has no tasks: ${e}
4
- one task description per line, # for comments`);return t}function F(e){return`${e.onDemandFile}:${e.startLine}`}function Xe(e){return`${e.onDemandFile} > ${e.heading}`}function Qe(e,s){let t=O(e).flatMap(o=>re({name:o.name,file:o.file},ue(s,o.file)));return oe(t,new Map(O(e).map(o=>[o.name,o.triggers])))}function Ee(e,s,t={}){let o=t.root?Qe(e,t.root):void 0,r=o?"section":"file",u=new Set,p=new Map,n=new Map,i=new Map;for(let c of O(e))p.set(c.name,c.tokens),n.set(c.name,c.name),i.set(c.name,c.name);if(o)for(let c of o.units)p.set(F(c),c.tokens),n.set(F(c),Xe(c)),i.set(F(c),c.onDemandFile);let a=[],l=0;s.forEach((c,v)=>{let H=o?ie(se(o,c)).map(h=>F(h.unit)):ae(e,c).filter(h=>h.score>0).map(h=>h.name);H.length===0&&l++;let j=H.filter(h=>!u.has(h));for(let h of j)u.add(h);let D=[...u].reduce((h,Ye)=>h+(p.get(Ye)??0),0);a.push({turn:v+1,task:c,opened:j.map(h=>n.get(h)??h),carried:[...u].map(h=>n.get(h)??h),compiledTokens:e.prefix.after+D,baselineTokens:e.prefix.before})});let d=a.reduce((c,v)=>c+v.compiledTokens,0),m=a.reduce((c,v)=>c+v.baselineTokens,0),y=new Set([...u].map(c=>i.get(c)??c)),g=O(e).map(c=>c.name).filter(c=>y.has(c)),w=[...u].reduce((c,v)=>c+(p.get(v)??0),0),P=e.prefix.after+w,M=e.prefix.before-P,$=m-d,k;return $>=0?(k=a.findIndex((c,v)=>a.slice(0,v+1).reduce((j,D)=>j+D.baselineTokens-D.compiledTokens,0)>=0),k=k>=0?k+1:void 0):M>0&&(k=a.length+Math.ceil(-$/M)),{unit:r,turns:a,baselineTotal:m,compiledTotal:d,saving:$,savingPct:m===0?0:$/m*100,onDemandOpened:g,onDemandNeverOpened:O(e).map(c=>c.name).filter(c=>!y.has(c)),unroutedTurns:l,steadyStatePerTurn:P,steadyStateGainPerTurn:M,breakEvenTurn:k}}function Ze(e,s){return s===0?"0.0%":`${(e/s*100).toFixed(1)}%`}function X(e){return e>=0?`saves ${f(e)}`:`costs ${f(-e)} more`}function Q(e,s){let t=[""];return t.push(` exact, over ${f(e.turns)} turns. No workload, no assumptions.`),t.push(""),t.push(` original memory file ${f(e.baselinePerTurn).padStart(8)} tokens per turn`),t.push(` compiled always-loaded ${f(e.compiledPerTurn).padStart(8)} tokens per turn`),t.push(` OnDemandMemory, all of it ${f(e.totalOnDemandTokens).padStart(8)} tokens, on demand`),t.push(""),t.push(" best case, no OnDemandMemory file ever opened"),t.push(` ${f(e.baselineTotal)} -> ${f(e.bestCaseTotal)} tokens, ${X(e.bestCaseSaving)} (${Ze(e.bestCaseSaving,e.baselineTotal)})`),t.push(""),t.push(" worst case, every OnDemandMemory file opened on turn 1 and carried"),t.push(` ${f(e.baselineTotal)} -> ${f(e.worstCaseTotal)} tokens, ${X(e.worstCaseSaving)}`),t.push(""),t.push(` break-even: ${f(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: ${s}, an offline estimate`),t.push(""),t.join(`
5
- `)}function Ae(e,s){let t=[""],o=e.turns.length;if(t.push(` MODEL, not a measurement. ${f(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 ${f(e.baselineTotal)} -> ${f(e.compiledTotal)}`),t.push(` ${X(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(` ${f(e.steadyStatePerTurn)} vs ${f(e.turns[0]?.baselineTokens??0)} baseline, ${e.steadyStateGainPerTurn>=0?`saves ${f(e.steadyStateGainPerTurn)}`:`costs ${f(-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 ${f(-e.saving)} at turn ${f(e.turns.length)}, recovering ${f(e.steadyStateGainPerTurn)} per turn:`),t.push(` breaks even around turn ${f(e.breakEvenTurn)} if nothing further opens.`),t.push("")):e.saving>=0&&e.breakEvenTurn!==void 0&&(t.push(` ahead from turn ${f(e.breakEvenTurn)} onward.`),t.push("")),e.unroutedTurns>0&&(t.push(` ${f(e.unroutedTurns)} of ${f(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: ${s}, an offline estimate`),t.push(""),t.join(`
6
- `)}function Pe(){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 T from"node:fs";import A from"node:path";function Ie(e){return/[\s"]/.test(e)?`"${e.replace(/"/g,'\\"')}"`:e}function x(e){return e.map(Ie).join(" ")}function Re(e){return e.map(Ie)}function je(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 et(e){if(e==="cursor")return"~/.cursor/mcp.json";if(e==="windsurf")return"~/.codeium/windsurf/mcp_config.json"}function Ne(e,s){let t=[];e.write&&t.push("--allow-write"),e.autoMemory&&t.push("--include-auto-memory");let o=I(e.cliPath),r=o?["node",o,"mcp",...t]:["npx","-y","minnimemory","mcp",...t],u=["claude","mcp","add","minnimemory","-s",e.scope,"--",...r],p=["claude","mcp","remove","minnimemory","-s",e.scope],n=["claude","mcp","get","minnimemory"],i=["claude","--version"],a=x(u),l=JSON.stringify({mcpServers:{minnimemory:{command:"npx",args:["-y","minnimemory","mcp",...t]}}},null,2),d={scope:e.scope,servedFlags:t,servedArgv:r,...o?{servedDirect:o}:{},addArgv:u,removeArgv:p,getArgv:n,probeArgv:i,manualLine:a,jsonSnippet:l};if(e.host&&e.host!=="json"){let m=et(e.host);m&&(d.hostConfigPath=m)}return d}function Fe(e){return e.error!==void 0&&e.error.code==="ENOENT"}var ee="npx -y minnimemory drift";function tt(e){let s=I(e);return s?`node "${s}" drift`:ee}function nt(e,s){let t=r=>r.replace(/\\/g,"/").toLowerCase(),o=t(e);return s.servedDirect?o.includes(t(s.servedDirect)):o.includes("npx -y minnimemory mcp")}function rt(e){return typeof e=="string"&&(e===ee||/^node "[^"]+" drift$/.test(e))}var te="npx -y minnimemory loaded";function ot(e){let s=I(e);return s?`node "${s}" loaded`:te}function st(e){return typeof e=="string"&&(e===te||/^node "[^"]+" loaded$/.test(e))}function Le(e){return[{event:"UserPromptSubmit",command:tt(e),fallback:ee,isOurs:rt},{event:"InstructionsLoaded",command:ot(e),fallback:te,isOurs:st}]}function He(e,s){let t=s.cwd??process.cwd();return e==="user"?A.join(s.configDir??A.join(s.home,".claude"),"settings.json"):e==="project"?A.join(t,".claude","settings.json"):A.join(t,".claude","settings.local.json")}function Be(e,s){let t=[];for(let o of e){if(!o||typeof o!="object")continue;let r=o.hooks;if(Array.isArray(r))for(let u of r){let p=u&&typeof u=="object"?u.command:void 0;s(p)&&t.push(p)}}return t}function Je(e){if(!T.existsSync(e))return{};try{let s=JSON.parse(T.readFileSync(e,"utf8"));return!s||typeof s!="object"||Array.isArray(s)?void 0:s}catch{return}}function Ue(e){let s=e.hooks;return s&&typeof s=="object"&&!Array.isArray(s)?s:void 0}function it(e,s){let t=He(e.scope,s),o=Le(e.cliPath);if(e.dryRun)return{exitCode:0,output:o.map(i=>`would add the ${i.event} hook \`${i.command}\` to ${t}`).join(`
8
- `),path:t};let r=Je(t);if(!r)return{exitCode:1,output:`install --hook: ${t} is not valid JSON; not touched.`,path:t};let u=Ue(r)??{},p=[],n=!1;for(let i of o){let a=Array.isArray(u[i.event])?[...u[i.event]]:[],l=Be(a,i.isOurs);if(l.includes(i.command)){p.push(i.event==="UserPromptSubmit"?`hook: already present in ${t}`:`hook: ${i.event} already present in ${t}`);continue}if(l.length>0){for(let d of a){let m=d&&typeof d=="object"?d.hooks:void 0;if(Array.isArray(m))for(let y of m)y&&typeof y=="object"&&i.isOurs(y.command)&&(y.command=i.command)}p.push(`hook: updated \`${l[0]}\` -> \`${i.command}\` in ${t} (${i.event}). Restart Claude Code.`)}else{let d={hooks:[{type:"command",command:i.command}]};a.push(d),p.push(`hook: added \`${i.command}\` to ${t} (${i.event}). Restart Claude Code.`)}u[i.event]=a,n=!0}return n&&(r.hooks=u,T.mkdirSync(A.dirname(t),{recursive:!0}),T.writeFileSync(t,`${JSON.stringify(r,null,2)}
9
- `,"utf8")),{exitCode:0,output:p.join(`
10
- `),path:t}}function De(e,s){let t=He(e.scope,s),o=Le(e.cliPath);if(e.dryRun)return{exitCode:0,output:o.map(n=>`would remove the ${n.event} hook (\`${n.fallback}\` or its direct node form) from ${t}`).join(`
11
- `),path:t};if(!T.existsSync(t))return{exitCode:0,output:`hook: nothing to remove (${t} does not exist)`,path:t};let r=Je(t);if(!r)return{exitCode:1,output:`install --remove: ${t} is not valid JSON; not touched.`,path:t};let u=Ue(r),p=[];for(let n of o){let i=u&&Array.isArray(u[n.event])?u[n.event]:void 0,a=i?Be(i,n.isOurs):[];if(!u||!i||a.length===0)continue;let l=i.filter(d=>{if(!d||typeof d!="object")return!0;let m=d.hooks;if(!Array.isArray(m))return!0;let y=m.filter(g=>!(g&&typeof g=="object"&&n.isOurs(g.command)));return y.length===0?!1:(d.hooks=y,!0)});l.length===0?delete u[n.event]:u[n.event]=l,p.push(`hook: removed \`${a[0]}\` from ${t}`)}return p.length===0?{exitCode:0,output:`hook: nothing to remove in ${t}`,path:t}:(u&&Object.keys(u).length===0&&delete r.hooks,T.writeFileSync(t,`${JSON.stringify(r,null,2)}
12
- `,"utf8"),{exitCode:0,output:p.join(`
13
- `),path:t})}function _e(e,s,t){let o=Ne(e,s),r=[];if(e.dryRun){r.push(`would run: ${x(o.removeArgv)}`);let i=De({...e,dryRun:!0},s);return r.push(i.output),{exitCode:0,output:`${r.join(`
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(`
14
14
  `)}
15
- `}}let u=t(o.probeArgv[0],o.probeArgv.slice(1)),p=0;if(Fe(u))r.push("the claude CLI is not on PATH; skipping the MCP registration removal.");else{let i=t(o.removeArgv[0],o.removeArgv.slice(1));r.push(`ran: ${x(o.removeArgv)}`),i.code!==0?(r.push(i.stderr.trim()),p=1):i.stdout.trim()&&r.push(i.stdout.trim())}let n=De(e,s);return r.push(n.output),n.exitCode!==0&&(p=n.exitCode),{exitCode:p,output:`${r.join(`
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(`
16
16
  `)}
17
- `}}var at="next: restart Claude Code, then ask it to run minnimemory doctor on your memory; it calls doctor(), then apply().";function Z(e,s,t,o){if(e.hook){let r=it(e,s);t.push(r.output),r.exitCode!==0&&(o=r.exitCode)}return o===0&&t.push(at),{exitCode:o,output:`${t.join(`
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
18
  `)}
19
- `}}function Ge(e,s,t){let o=Ne(e,s),r=[];if(e.hook&&e.host)return{exitCode:2,output:`--hook only applies to Claude Code
20
- `};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(`
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(`
21
21
  `)}
22
- `};if(e.dryRun){e.force&&r.push(`would run: ${x(o.removeArgv)}`),r.push(`would run: ${x(o.addArgv)}`);let d=je(o);return d&&r.push(d),Z(e,s,r,0)}let u=t(o.probeArgv[0],o.probeArgv.slice(1));if(Fe(u))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(`
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
23
  `)}
24
- `};let p=t(o.getArgv[0],o.getArgv.slice(1)),n=p.code===0,i=n&&!nt(p.stdout,o);if(n&&!e.force&&!i)return r.push("minnimemory is already registered.",`to change it: ${x(["npx","-y","minnimemory","install","--force","--scope",e.scope,...e.write?["--write"]:[],...e.autoMemory?["--auto-memory"]:[]])}`),Z(e,s,r,0);if(n){i&&!e.force&&r.push("minnimemory is registered with a different command; repointing it at this copy.");let d=t(o.removeArgv[0],o.removeArgv.slice(1));if(d.code!==0)return r.push(`ran: ${x(o.removeArgv)}`,d.stderr.trim()),{exitCode:1,output:`${r.join(`
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
25
  `)}
26
- `}}let a=t(o.addArgv[0],o.addArgv.slice(1));if(r.push(`ran: ${x(o.addArgv)}`),a.code!==0)return r.push(a.stderr.trim()),{exitCode:1,output:`${r.join(`
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
27
  `)}
28
- `};a.stdout.trim()&&r.push(a.stdout.trim());let l=je(o);return l&&r.push(l),Z(e,s,r,0)}var pt=!1,L=`
29
- minnimemory ${K} the agent memory compiler
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
30
30
 
31
- usage: the four lifecycle verbs, the CLI and the MCP basic profile share (DESIGN.md 6.7, 6.9).
31
+ usage: the four lifecycle verbs, the CLI and the MCP basic profile share.
32
32
  The only difference is who writes: the CLI writes to disk itself, the MCP tools return the
33
33
  command that does (and the operations it performs) for the agent to run.
34
- minnimemory init [path] first time: the map of every file Claude Code loads for this
35
- project (when, whose, tokens), then the audit and the diff
36
- apply would write; changes nothing; ends with the apply
37
- command to run. --map prints only the map
38
- minnimemory doctor [path] the same preview, for a workspace you compiled before: the
39
- audit, drift since the last apply, the re-apply diff; exit 1
40
- at --fail-on for CI
41
- minnimemory apply [path] write what init/doctor showed: a compile, a re-apply, or
34
+ minnimemory init <folder> always first: takes where Claude Code loads from (--loaded,
35
+ --from-log, --memory-dir; the agent passes them over MCP),
36
+ checks and saves them, then the map, the audit and the diff
37
+ apply would write; writes only that record; ends with the
38
+ apply command to run. --map prints only the map
39
+ minnimemory doctor [folder] after init, never first: the audit, drift since the last
40
+ apply, the re-apply diff; no folder means the one init saved;
41
+ exit 1 at --fail-on for CI
42
+ minnimemory apply <folder> write what init/doctor showed: a compile, a re-apply, or
42
43
  "nothing to apply"
43
- minnimemory undo [path] restore the original memory files and remove .minnimemory/
44
+ minnimemory undo <folder> restore the original memory files and remove .minnimemory/
44
45
 
45
46
  more
46
47
  minnimemory no subcommand: serves mcp when stdin is not a terminal (how
47
48
  every MCP host launches it), prints this usage otherwise
48
- minnimemory mcp [path] start the MCP server. Serves doctor/init/apply/undo by
49
+ minnimemory mcp [path] start the MCP server. Serves init/doctor/apply/undo by
49
50
  default; --profile full serves the seven maintainer tools
50
51
  minnimemory install register minnimemory with the current host
51
- minnimemory bench [path] what the compiled shape costs over a session
52
+ minnimemory bench <folder> what the compiled shape costs over a session
52
53
  minnimemory recall <path> <query...>
53
54
  recall against a compiled workspace or a manifest-less memory
54
55
  directory (Layout B), whichever <path> is, change nothing
@@ -59,15 +60,21 @@ more
59
60
  minnimemory drift Claude Code UserPromptSubmit hook: prints a one-line notice when
60
61
  memory files changed since the last apply, once per change,
61
62
  nothing otherwise
63
+ minnimemory loaded Claude Code InstructionsLoaded hook: records which memory files
64
+ Claude Code loaded, for the map init prints; reads hook JSON
65
+ from stdin, prints nothing
62
66
 
63
67
  install options
64
68
  --scope <name> user, project or local, same meaning as claude mcp add (default user)
65
- --write append --allow-write to the served command
66
- --auto-memory append --include-auto-memory to the served command
69
+ --write serve the full profile with its write tools (--profile full
70
+ --allow-write); the default basic profile never writes
67
71
  --dry-run print the command without running it, exit 0
68
72
  --force remove an existing registration first, then re-add
69
- --no-hook skip the drift notice hook; on by default (DESIGN.md 6.12)
73
+ --no-hook skip the drift notice hook; on by default
70
74
  --remove remove the MCP registration and the drift hook install added
75
+ --host <name> cursor, windsurf or json: print the mcpServers snippet (and the
76
+ config file for cursor/windsurf) to paste, instead of registering
77
+ with Claude Code; no hook
71
78
  without the claude CLI on PATH: print the manual claude mcp add line and the JSON snippet,
72
79
  exit 2. If claude reports an error, print its stderr and exit 1. Already registered without
73
80
  --force: say so and print the command to change it, exit 0. Prints the next step in one line.
@@ -86,20 +93,27 @@ hook options
86
93
  init and doctor options
87
94
  Neither writes; pass --write or --update to init and it prints one line and exits instead.
88
95
  Run apply to actually compile or re-apply. A host file (CLAUDE.md and friends) is compiled
89
- into .minnimemory/; a memory folder (an index plus topic files, or the Claude Code
90
- auto-memory folder with --include-auto-memory) has its always-loaded files split in place,
91
- routed pieces beside them and a fenced list appended to the index (DESIGN.md 6.9).
92
- The CLI's four verbs always see the Claude Code auto-memory folder for this project and the
93
- user-level ~/.claude/CLAUDE.md with its imports (loaded on every turn too); the MCP server
94
- needs --include-auto-memory for that (install --auto-memory sets it).
96
+ into .minnimemory/; a memory folder (an index plus topic files, such as a Claude Code
97
+ memory folder under ~/.claude/projects/) has its always-loaded files split in place,
98
+ routed pieces beside them and a fenced list appended to the index.
99
+ Only the folder you name and the folders below it are read. A file outside it is read only
100
+ when it is reported as loaded (--loaded, --from-log, or by the agent over MCP); nothing outside
101
+ is searched for. apply on a memory folder needs that report, or --only-this-folder.
95
102
  --force on a compiled workspace with no drift, preview the re-apply plan
96
103
  anyway
97
- --budget <n> always-loaded token budget AlwaysOnMemory must fit (default 2000)
104
+ --loaded <path> a file Claude Code loads this session (repeatable); the only way a
105
+ file outside the named folder is read (--host-file still works)
106
+ --memory-dir <path> the auto memory folder Claude Code names; also the folder to use
107
+ --from-log take the loaded files from Claude Code's own load log for this folder
108
+ --only-this-folder apply to a memory folder with nothing reported, when nothing outside loads it
109
+ --diff <mode> summary: the plan and the operation list, no file diffs; full: every
110
+ diff too (default full)
111
+ --budget <n> always-loaded token budget AlwaysOnMemory must fit (default: 60% of the file, at least 2000)
98
112
  --profile <name> how much token-discipline guidance to embed (default auto)
99
- auto none under the budget, routing at or over it
113
+ auto same as none today, for every source
100
114
  none structure only, embed nothing
101
- routing the rules that make routing work, about 200 tokens
102
- full the complete set, about 690 tokens
115
+ routing the rules that make routing work, about 210 tokens
116
+ full the complete set, about 710 tokens
103
117
  --allow-secrets preview as if a credential-shaped source were allowed through
104
118
  --episodic-json plan episodic OnDemandMemory files (changelogs, logs) as JSON, not
105
119
  Markdown (O3)
@@ -109,12 +123,17 @@ apply options
109
123
  and drifted - re-applies it; compiled with no drift - "nothing to apply". Same backups
110
124
  (.minnimemory/original/, .minnimemory/previous/) and refusals as init previews.
111
125
  --force accept a compile that would not shrink the always-loaded prefix
112
- --budget <n> always-loaded token budget AlwaysOnMemory must fit (default 2000)
126
+ --loaded <path> a file Claude Code loads this session (repeatable); the only way a
127
+ file outside the named folder is read (--host-file still works)
128
+ --memory-dir <path> the auto memory folder Claude Code names; also the folder to use
129
+ --from-log take the loaded files from Claude Code's own load log for this folder
130
+ --only-this-folder apply to a memory folder with nothing reported, when nothing outside loads it
131
+ --budget <n> always-loaded token budget AlwaysOnMemory must fit (default: 60% of the file, at least 2000)
113
132
  --profile <name> how much token-discipline guidance to embed (default auto)
114
- auto none under the budget, routing at or over it
133
+ auto same as none today, for every source
115
134
  none structure only, embed nothing
116
- routing the rules that make routing work, about 200 tokens
117
- full the complete set, about 690 tokens
135
+ routing the rules that make routing work, about 210 tokens
136
+ full the complete set, about 710 tokens
118
137
  --allow-secrets compile even when the source holds a credential-shaped string
119
138
  --episodic-json write episodic OnDemandMemory files (changelogs, logs) as JSON, not
120
139
  Markdown (O3)
@@ -122,33 +141,25 @@ apply options
122
141
  undo options
123
142
  Restores the host memory file from .minnimemory/original/<name>.bak and removes
124
143
  .minnimemory/. "nothing to undo" when not compiled; a clear error when the original copy is
125
- missing (doctor reports that as a finding before it matters). No options.
144
+ missing (doctor reports that as a finding before it matters).
145
+ --force restore even after a re-apply; what changed since the first apply
146
+ is discarded (undo refuses without it and says so)
126
147
 
127
148
  mcp options
128
149
  Every tool definition is charged to the client's prefix on every turn, called or not, so the
129
150
  server only advertises the profile you asked for.
130
151
  --profile <name> basic (default) or full
131
- basic the one-time converter: doctor, init, apply, undo, always
152
+ basic the one-time converter: init, doctor, apply, undo, always
132
153
  registered, read-only. The server never writes your disk;
133
154
  apply and undo return files for you to write yourself
134
155
  full recall, modules, outline, doctor, plan, always registered;
135
- apply, update with --allow-write. Today's seven tools,
136
- unchanged - for maintainers
137
- --allow-write adds the full profile's write tools (apply, update).
156
+ apply with --allow-write. Six tools, for maintainers
157
+ --allow-write adds the full profile's write tool (apply).
138
158
  No effect on basic, which is read-only by construction; without
139
- --allow-write those tools are not registered at all on full: they
140
- are absent from tools/list, not present-and-refusing
141
- --follow-external-imports
142
- let doctor/plan (full) and doctor/init (basic) follow @path
143
- imports outside the server root. A launch flag, never a tool
144
- argument: a connected client must not be able to widen the server's
145
- reach by asking
146
- --include-auto-memory let doctor/plan/apply/update (full) and doctor/init (basic) see
147
- the operator's OS-level Claude Code auto-memory folder, and allow
148
- "auto-memory" as a target where that tool resolves one. Off by
149
- default and separate from --follow-external-imports: reading the
150
- operator's own memory and following an imported file's @path are
151
- different reaches. A launch flag, never a tool argument
159
+ --allow-write that tool is not registered at all on full: it
160
+ is absent from tools/list, not present-and-refusing
161
+ The server reads only inside its root (the folder it was started in, or [path]), and every
162
+ tool call names a folder inside it.
152
163
 
153
164
  bench options
154
165
  --turns <n> session length for the exact bounds (default 50)
@@ -161,142 +172,181 @@ bench options
161
172
  doctor options
162
173
  --json machine-readable output
163
174
  --ci terse output, no colour
164
- --follow-external-imports
165
- follow @path imports that resolve outside the target directory.
166
- Off by default: an @ line is content the scanned repo controls,
167
- and following one reads and reports files elsewhere on this machine
168
175
  --fail-on <sev> exit 1 at this severity or above: low, med, high (default high)
169
- --budget <n> always-loaded token budget for MM001 (default 2000)
176
+ --budget <n> always-loaded token budget for MM001 (default: the compiled budget, else 60% of the file, at least 2000)
177
+ --loaded <path> a file Claude Code loads this session (repeatable); the only way a
178
+ file outside the named folder is read (--host-file still works)
179
+ --memory-dir <path> the auto memory folder Claude Code names; also the folder to use
180
+ --from-log take the loaded files from Claude Code's own load log for this folder
181
+ --only-this-folder apply to a memory folder with nothing reported, when nothing outside loads it
170
182
  --only <ids> run only these rules, comma separated
171
183
  --ignore <ids> skip these rules, comma separated
172
184
  --rules list the rule set and exit
173
185
  -h, --help this message
174
186
  -v, --version print the version
175
187
 
176
- path defaults to the current directory. It may be a repo, a memory directory, or a single file.
177
- `;function mt(){let e=[""," rule set",""];for(let s of ce)e.push(` ${s.id.padEnd(8)}${s.severity.padEnd(6)}${s.title}`);return e.push(""),e.join(`
178
- `)}function ft(e,s){if(e===void 0)return s;if(e==="low"||e==="med"||e==="high")return e;throw new Error(`--fail-on must be one of low, med, high (got "${e}")`)}function ze(e){return e?e.split(",").map(s=>s.trim()).filter(Boolean):[]}function ht(e,s){return e.matches.length===0?`
179
- no match for "${e.query}"
188
+ <folder> is required: a repo, a memory directory, or a single file. With none, minnimemory asks
189
+ for it (in a terminal) or stops and says so. Type . for the current folder. An @import that
190
+ 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}"
180
194
 
181
- `:s?`${e.matches.map(t=>`${t.onDemandFile} > ${t.path.join(" > ")} (${t.tokens} tokens)`).join(`
195
+ `:r?`${t.matches.map(e=>`${e.onDemandFile} > ${e.path.join(" > ")} (${e.tokens} tokens)`).join(`
182
196
  `)}
183
- `:`${e.matches.map(t=>`## ${t.onDemandFile} > ${t.path.join(" > ")} (lines ${t.startLine}-${t.endLine}, ${t.tokens} tokens, score ${t.score})
197
+ `:`${t.matches.map(e=>`## ${e.onDemandFile} > ${e.path.join(" > ")} (lines ${e.startLine}-${e.endLine}, ${e.tokens} tokens, score ${e.score})
184
198
 
185
- ${t.content}`).join(`
199
+ ${e.content}`).join(`
186
200
 
187
201
  ---
188
202
 
189
203
  `)}
190
- `}function gt(e){return e.isTTY?"usage":"serve"}function We(){return(e,s)=>{let t=process.platform==="win32",o=lt(e,t?Re(s):s,{encoding:"utf8",shell:t});return{code:o.status,stdout:o.stdout??"",stderr:o.stderr??"",error:o.error}}}function yt(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 wt(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 qe(e){if(e===void 0)return;let s=Number(e);if(!Number.isFinite(s)||s<=0)throw new Error(`--budget must be a positive number (got "${e}")`);return Math.floor(s)}function kt(e,s){let t;try{if(t=b.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(`
191
- error: ${r.message}
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}
192
206
 
193
207
  `),2):(process.stderr.write(`
194
- unexpected error: ${r.stack??String(r)}
208
+ unexpected error: ${o.stack??String(o)}
195
209
 
196
- `),2)}let o=s.profile??"basic";return o!=="basic"&&o!=="full"?(process.stderr.write(`
197
- error: --profile must be one of basic, full (got "${o}")
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}")
198
212
 
199
- `),2):((async()=>{let[{StdioServerTransport:r},{createMcpServer:u}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-EWPP2F2F.js")]);await u(t,{profile:o,allowWrite:s["allow-write"]===!0,followExternalImports:s["follow-external-imports"]===!0,includeAutoMemory:s["include-auto-memory"]===!0}).connect(new r)})().catch(r=>{process.stderr.write(`
200
- mcp server failed: ${r.message??String(r)}
201
- `),process.exitCode=1}),0)}function vt(e){let s;try{s=ct({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"},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},"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(n){let i=n.message,a=/argument is ambiguous/.test(i)?`
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)
217
+
218
+ `);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}
222
+
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)?`
202
225
  (a value that starts with '-' must be written as --option=value; --budget must be positive anyway)`:"";return process.stderr.write(`
203
- error: ${i}${a}
204
- ${L}`),2}let{values:t,positionals:o}=s;if(t.help)return process.stdout.write(L),0;if(t.version)return process.stdout.write(`${K}
205
- `),0;if(t.rules)return process.stdout.write(mt()),0;let r;if(o[0]===void 0){if(gt({isTTY:process.stdin.isTTY===!0})==="usage")return process.stdout.write(L),0;r="mcp"}else r=o[0];let u=o[1]??".";if(r==="install"){let n;try{n={write:t.write===!0,autoMemory:t["auto-memory"]===!0,scope:yt(t.scope),dryRun:t["dry-run"]===!0,force:t.force===!0,host:wt(t.host),hook:t.host===void 0&&t["no-hook"]!==!0,cliPath:process.argv[1]?b.resolve(process.argv[1]):void 0}}catch(d){return process.stderr.write(`
206
- error: ${d.message}
207
-
208
- `),2}let i={home:ut.homedir(),platform:process.platform,cwd:process.cwd(),configDir:le()},a=t.remove===!0?_e(n,i,We()):Ge(n,i,We());return(a.exitCode===0?process.stdout:process.stderr).write(`
209
- ${a.output}
210
- `),a.exitCode}if(r==="init"||r==="apply"){if(r==="init"&&(t.write===!0||t.update===!0))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}"
231
+
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(`
233
+ 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
+
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}
237
+
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(`
211
241
  error: init never writes; use apply
212
242
 
213
- `),2;let n=t.profile??"auto";if(n!=="auto"&&!ne(n))return process.stderr.write(`
214
- error: --profile must be one of auto, none, routing, full (got "${n}")
243
+ `),2;let s=e.profile??"auto";if(s!=="auto"&&!ye(s))return process.stderr.write(`
244
+ error: --profile must be one of auto, none, routing, full (got "${s}")
215
245
 
216
- `),2;let i;try{i=qe(t.budget)}catch(g){return process.stderr.write(`
217
- error: ${g.message}
246
+ `),2;let d;try{d=bt(e.budget)}catch($){return process.stderr.write(`
247
+ error: ${$.message}
218
248
 
219
- `),2}let a=r==="apply",l=n==="auto"?void 0:n,d=t["episodic-json"]===!0,m=[...l?[`--profile ${l}`]:[],...d?["--episodic-json"]:[]],y={budget:i,force:t.force===!0,profileName:l,episodicJson:d,followExternalImports:t["follow-external-imports"]===!0,includeAutoMemory:!0};try{if(!a){let M=S.existsSync(u)&&S.statSync(u).isFile()?b.dirname(b.resolve(u)):b.resolve(u),$=$e(M,{machine:!0});if(t.map===!0)return process.stdout.write(t.json?`${JSON.stringify($,null,2)}
220
- `:z($)),0;t.json||process.stdout.write(z($));let k=q(u,y);return t.json?process.stdout.write(`${V(k,o[1],m)}
221
- `):process.stdout.write(Y(k,{color:!1,ci:t.ci===!0,target:o[1],flags:m})),0}let g=G(u,{followExternalImports:y.followExternalImports,includeAutoMemory:y.includeAutoMemory}),w=pe(g,{budget:i,profileName:l,episodicJson:d});if(t.plan!==void 0&&w.plan!==t.plan)return process.stderr.write(`
222
- error: the plan on disk no longer matches --plan ${t.plan} (now ${w.plan}); run doctor again
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}
223
252
 
224
- `),2;if(w.verdict==="nothing")return process.stdout.write(_(w,{write:!0})),0;if(w.verdict==="leave"&&t.force!==!0)return process.stderr.write(`
225
- error: the compile would not shrink the always-loaded prefix (${w.before} -> ${w.after} tokens; break-even ${w.bounds.breakEvenCarriedTokens} tokens of OnDemandMemory open all session)
253
+ `:` could not save the locations; pass them again to apply
254
+
255
+ `),0}let $=_(u,T);if($.shape==="memory-dir"&&!$.reported)return process.stderr.write(`
256
+ 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
+
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
260
+
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)
226
263
  Pass --force to write it anyway.
227
264
 
228
- `),2;let P=_(w,{write:!0,target:o[1]});return me(w,{allowSecrets:t["allow-secrets"]===!0}),process.stdout.write(P),0}catch(g){return g instanceof N||g instanceof R?(process.stderr.write(`
229
- error: ${g.message}
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}
230
267
 
231
268
  `),2):(process.stderr.write(`
232
- unexpected error: ${g.stack??String(g)}
269
+ unexpected error: ${$.stack??String($)}
233
270
 
234
- `),2)}}if(r==="undo")try{let n;try{n=G(u,{includeAutoMemory:!0}).folderRoot}catch(m){if(!(m instanceof N))throw m}if(!n)return process.stdout.write(`
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(`
235
272
  nothing to undo
236
273
 
237
- `),0;let i=ke(n),a=i?void 0:ve(n),l=a?ye(n,a):he(n,i);if(l.kind==="none")return process.stdout.write(`
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}
276
+
277
+ `),2):(process.stdout.write(`
238
278
  nothing to undo
239
279
 
240
- `),0;if(l.kind==="missing-original")return process.stderr.write(`
241
- error: no original copy under ${B}/original/ for: ${l.files.join(", ")}; run "minnimemory doctor" to check
280
+ `),0);if(a.kind==="kept-only")return process.stderr.write(`
281
+ error: undo has nothing left to restore here: ${Le(a.kept)}
242
282
 
243
- `),2;let d=t.force===!0?void 0:fe(l.plan);return d?(process.stderr.write(`
244
- error: ${d}
283
+ `),2;if(a.kind==="missing-original")return process.stderr.write(`
284
+ error: no original copy under ${Y}/original/ for: ${a.files.join(", ")}.
285
+ Backups stay on the machine that ran apply (they are gitignored); on a clone, the way back is git history.
245
286
 
246
- `),2):(ge(l.plan),process.stdout.write(`
247
- restored ${l.plan.operations.filter(m=>m.op==="write"||m.op==="move").length} file(s) in ${n}
248
- deleted: ${l.plan.operations.filter(m=>m.op==="delete").length} path(s), ${B}/ included
287
+ `),2;let i=Ee(a.plan);if(i&&e.force!==!0)return process.stderr.write(`
288
+ error: ${i}
249
289
 
250
- `),0)}catch(n){return n instanceof R?(process.stderr.write(`
251
- error: ${n.message}
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("/")}
296
+ `:"")+`
297
+ `),0}catch(s){return s instanceof H?(process.stderr.write(`
298
+ error: ${s.message}
252
299
 
253
300
  `),2):(process.stderr.write(`
254
- unexpected error: ${n.stack??String(n)}
301
+ unexpected error: ${s.stack??String(s)}
255
302
 
256
- `),2)}if(r==="mcp")return pt?((async()=>{let[{StdioServerTransport:n},{createDisabledMcpServer:i,DISABLED_MESSAGE:a}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-EWPP2F2F.js")]);process.stderr.write(`
257
- mcp: ${a}
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}
258
305
 
259
- `),await i().connect(new n)})().catch(n=>{process.stderr.write(`
260
- mcp server failed: ${n.message??String(n)}
261
- `),process.exitCode=1}),0):kt(u,t);if(r==="recall"){let n=o.slice(2).join(" ").trim();if(!n)return process.stderr.write(`
306
+ `),await d().connect(new s)})().catch(s=>{process.stderr.write(`
307
+ 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(`
262
309
  error: recall needs a query: minnimemory recall <path> <query...>
263
310
 
264
- `),2;let i;if(t["max-tokens"]!==void 0){let l=Number(t["max-tokens"]);if(!Number.isFinite(l)||l<=0)return process.stderr.write(`
265
- error: --max-tokens must be a positive number (got "${t["max-tokens"]}")
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"]}")
266
313
 
267
- `),2;i=Math.floor(l)}let a=b.resolve(u);try{let l=we(a),d;if(l==="compiled")d=de(a,J(a),n,{maxTokens:i});else if(l==="memory-dir")d=Se(a,n,{maxTokens:i});else return process.stderr.write(`
268
- error: ${a} 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
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
269
316
 
270
- `),2;return process.stdout.write(ht(d,t.headings===!0)),0}catch(l){return l instanceof E||l instanceof xe?(process.stderr.write(`
271
- error: ${l.message}
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}
272
319
 
273
320
  `),2):(process.stderr.write(`
274
- unexpected error: ${l.stack??String(l)}
275
-
276
- `),2)}}if(r==="hook"){let n="";try{n=S.readFileSync(0,"utf8")}catch{n=""}let i;if(t["max-tokens"]!==void 0){let a=Number(t["max-tokens"]);Number.isFinite(a)&&a>0&&(i=Math.floor(a))}try{let a=W(n),l=Oe(a,{headings:t.headings===!0,maxTokens:i,dir:t.dir});l&&process.stdout.write(`${l}
277
- `)}catch(a){process.stderr.write(`
278
- hook: ${a.message??String(a)}
279
- `)}return 0}if(r==="loaded"){let n="";try{n=S.readFileSync(0,"utf8")}catch{n=""}try{be(JSON.parse(n))}catch{}return 0}if(r==="drift"){let n="";try{n=S.readFileSync(0,"utf8")}catch{n=""}try{let i=W(n),a=Ce(i);a&&process.stdout.write(`${a}
280
- `)}catch(i){process.stderr.write(`
281
- drift: ${i.message??String(i)}
282
- `)}return 0}if(r==="bench")try{let n=b.resolve(u),i=J(n),a=t.turns===void 0?50:Number(t.turns);if(!Number.isFinite(a))throw new C(`--turns must be a positive whole number (got "${t.turns}")`);let l=U(i,a);if(t.workload===void 0)return t.json===!0?(process.stdout.write(`${JSON.stringify({bounds:l,tokenizer:i.tokenizer},null,2)}
283
- `),0):(process.stdout.write(Q(l,i.tokenizer)),process.stdout.write(Pe()),0);let d=Me(t.workload),m=Ee(i,d,t["whole-files"]===!0?{}:{root:n});return t.json===!0?(process.stdout.write(`${JSON.stringify({bounds:l,model:m,tokenizer:i.tokenizer},null,2)}
284
- `),0):(process.stdout.write(Q(l,i.tokenizer)),process.stdout.write(Ae(m,i.tokenizer)),0)}catch(n){return n instanceof C||n instanceof E?(process.stderr.write(`
285
- error: ${n.message}
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(`
332
+ error: ${s.message}
286
333
 
287
334
  `),2):(process.stderr.write(`
288
- unexpected error: ${n.stack??String(n)}
335
+ unexpected error: ${s.stack??String(s)}
336
+
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)}\`.
289
341
 
290
- `),2)}if(r!=="doctor")return process.stderr.write(`
291
- error: unknown command "${r}"
292
- ${L}`),2;let p;try{p={budget:qe(t.budget),failOn:ft(t["fail-on"],"high"),only:ze(t.only),ignore:ze(t.ignore),followExternalImports:t["follow-external-imports"]===!0,includeAutoMemory:!0,force:t.force===!0}}catch(n){return process.stderr.write(`
293
- error: ${n.message}
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(`
343
+ error: ${s.message}
294
344
 
295
- `),2}try{let n=q(u,p);if(t.json)process.stdout.write(`${V(n,o[1])}
296
- `);else{let i=!t.ci&&!process.env.NO_COLOR&&process.stdout.isTTY===!0;process.stdout.write(Y(n,{color:i,ci:t.ci===!0,target:o[1]}))}return Te(n.audit.findings,n.config.failOn)}catch(n){return n instanceof N||n instanceof R?(process.stderr.write(`
297
- error: ${n.message}
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(`
347
+ error: ${s.message}
298
348
 
299
349
  `),2):(process.stderr.write(`
300
- unexpected error: ${n.stack??String(n)}
350
+ unexpected error: ${s.stack??String(s)}
301
351
 
302
- `),2)}}function bt(){let e=process.argv[1];if(!e)return!1;try{return b.resolve(dt(import.meta.url))===b.resolve(e)}catch{return!1}}bt()&&(process.exitCode=vt(process.argv.slice(2)));export{pt as MCP_STASHED,gt as defaultCommand,vt as main};
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};