minnimemory 1.1.0 → 1.2.1

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