minnimemory 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/pkg/cli.js CHANGED
@@ -1,46 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
  /* MinniMemoryMCP (c) 2026 MinniAI. Licensed under the MinniMemoryMCP License, see LICENSE. */
3
- import{$ as Qe,$a as vo,A as _e,Aa as ce,B as Fe,Ba as ue,C as Le,Ca as co,Da as uo,Ea as po,Fa as fo,G as Be,Ga as mo,H as Je,Ha as q,Ia as ho,K as Ue,L as Ge,M as H,N as re,Na as go,O as We,Q as Xe,Qa as yo,R as P,S as se,T as qe,U as ie,V as ze,W as Ye,X as Ke,Y as Ve,Ya as wo,Za as ko,_ as U,_a as pe,aa as Ze,ab as bo,b as R,ba as eo,bb as xo,cb as $o,db as Co,eb as So,fa as oo,fb as Oo,g,ga as to,gb as jo,ha as no,hb as Mo,ia as ro,j as Ee,ja as so,ka as ae,kb as Eo,la as io,ma as ao,mb as fe,n as Te,nb as me,o as De,ob as he,p as Ae,pb as ge,q as Re,r as Pe,ra as lo,s as te,t as ne,ta as de,v as Ie,w as B,wa as G,x as J,xa as le,y as Ne,ya as W,z as He,za as X}from"./chunks/chunk-K7XLQMXJ.js";import{spawnSync as bt}from"node:child_process";import S from"node:fs";import Yo from"node:os";import $ from"node:path";import{fileURLToPath as xt}from"node:url";import{parseArgs as $t}from"node:util";import et from"node:fs";function ot(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t!==""&&!t.startsWith("#"))}function To(e){let t;try{t=et.readFileSync(e,"utf8")}catch{throw new P(`cannot read workload file: ${e}`)}let o=ot(t);if(o.length===0)throw new P(`workload file has no tasks: ${e}
4
- one task description per line, # for comments`);return o}function z(e){return`${e.onDemandFile}:${e.startLine}`}function tt(e){return`${e.onDemandFile} > ${e.heading}`}function nt(e,t){let o=R(e).flatMap(n=>Te({name:n.name,file:n.file},We(t,n.file)));return De(o,new Map(R(e).map(n=>[n.name,n.triggers])))}function Do(e,t,o={}){let n=o.root?nt(e,o.root):void 0,r=n?"section":"file",u=new Set,a=new Map,d=new Map,c=new Map;for(let i of R(e))a.set(i.name,i.tokens),d.set(i.name,i.name),c.set(i.name,i.name);if(n)for(let i of n.units)a.set(z(i),i.tokens),d.set(z(i),tt(i)),c.set(z(i),i.onDemandFile);let f=[],v=0;t.forEach((i,h)=>{let C=n?Re(Ae(n,i)).map(m=>z(m.unit)):Pe(e,i).filter(m=>m.score>0).map(m=>m.name);C.length===0&&v++;let x=C.filter(m=>!u.has(m));for(let m of x)u.add(m);let b=[...u].reduce((m,Q)=>m+(a.get(Q)??0),0);f.push({turn:h+1,task:i,opened:x.map(m=>d.get(m)??m),carried:[...u].map(m=>d.get(m)??m),compiledTokens:e.prefix.after+b,baselineTokens:e.prefix.before})});let k=f.reduce((i,h)=>i+h.compiledTokens,0),y=f.reduce((i,h)=>i+h.baselineTokens,0),w=new Set([...u].map(i=>c.get(i)??i)),M=R(e).map(i=>i.name).filter(i=>w.has(i)),D=[...u].reduce((i,h)=>i+(a.get(h)??0),0),E=e.prefix.after+D,s=e.prefix.before-E,l=y-k,p;return l>=0?(p=f.findIndex((i,h)=>f.slice(0,h+1).reduce((x,b)=>x+b.baselineTokens-b.compiledTokens,0)>=0),p=p>=0?p+1:void 0):s>0&&(p=f.length+Math.ceil(-l/s)),{unit:r,turns:f,baselineTotal:y,compiledTotal:k,saving:l,savingPct:y===0?0:l/y*100,onDemandOpened:M,onDemandNeverOpened:R(e).map(i=>i.name).filter(i=>!w.has(i)),unroutedTurns:v,steadyStatePerTurn:E,steadyStateGainPerTurn:s,breakEvenTurn:p}}function rt(e,t){return t===0?"0.0%":`${(e/t*100).toFixed(1)}%`}function ye(e){return e>=0?`saves ${g(e)}`:`costs ${g(-e)} more`}function we(e,t){let o=[""];return o.push(` exact, over ${g(e.turns)} turns. No workload, no assumptions.`),o.push(""),o.push(` original memory file ${g(e.baselinePerTurn).padStart(8)} tokens per turn`),o.push(` compiled always-loaded ${g(e.compiledPerTurn).padStart(8)} tokens per turn`),o.push(` OnDemandMemory, all of it ${g(e.totalOnDemandTokens).padStart(8)} tokens, on demand`),o.push(""),o.push(" best case, no OnDemandMemory file ever opened"),o.push(` ${g(e.baselineTotal)} -> ${g(e.bestCaseTotal)} tokens, ${ye(e.bestCaseSaving)} (${rt(e.bestCaseSaving,e.baselineTotal)})`),o.push(""),o.push(" worst case, every OnDemandMemory file opened on turn 1 and carried"),o.push(` ${g(e.baselineTotal)} -> ${g(e.worstCaseTotal)} tokens, ${ye(e.worstCaseSaving)}`),o.push(""),o.push(` break-even: ${g(e.breakEvenCarriedTokens)} tokens of OnDemandMemory can sit in`),o.push(" context from turn 1 to the end and come out even. Past that the compiled"),o.push(" shape costs more than the file it replaced."),o.push(""),o.push(` tokenizer: ${t}, an offline estimate`),o.push(""),o.join(`
5
- `)}function Ao(e,t){let o=[""],n=e.turns.length;if(o.push(` MODEL, not a measurement. ${g(n)} turns from the workload you supplied.`),o.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."),o.push(""),o.push(` memory tokens over the session ${g(e.baselineTotal)} -> ${g(e.compiledTotal)}`),o.push(` ${ye(e.saving)}${e.saving>=0?` (${e.savingPct.toFixed(1)}%)`:""}`),o.push(""),e.onDemandOpened.length>0){o.push(` opened and carried (${e.onDemandOpened.length}):`);for(let r of e.onDemandOpened)o.push(` ${r}`);o.push("")}if(e.onDemandNeverOpened.length>0){o.push(` never opened (${e.onDemandNeverOpened.length}) - this is where the saving comes from:`);for(let r of e.onDemandNeverOpened)o.push(` ${r}`);o.push("")}return o.push(" one more turn, once everything this workload opens is in context:"),o.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`),o.push(""),e.saving<0&&e.steadyStateGainPerTurn<=0?(o.push(" this workload never breaks even. The OnDemandMemory files it opens are large enough that"),o.push(" carrying them costs more every turn than the original file did, so a longer"),o.push(" session loses more, not less. Splitting differently, or not compiling this"),o.push(" file at all, is the honest answer here."),o.push("")):e.saving<0&&e.breakEvenTurn!==void 0?(o.push(` behind by ${g(-e.saving)} at turn ${g(e.turns.length)}, recovering ${g(e.steadyStateGainPerTurn)} per turn:`),o.push(` breaks even around turn ${g(e.breakEvenTurn)} if nothing further opens.`),o.push("")):e.saving>=0&&e.breakEvenTurn!==void 0&&(o.push(` ahead from turn ${g(e.breakEvenTurn)} onward.`),o.push("")),e.unroutedTurns>0&&(o.push(` ${g(e.unroutedTurns)} of ${g(n)} turns matched no OnDemandMemory file at all.`),o.push(" Those turns are cheap here, but a real agent may have needed something and"),o.push(" not been routed to it. Check them before trusting the total."),o.push("")),o.push(" what this number is conditional on:"),o.push(" - your workload being what a real session looks like. It is your file;"),o.push(" the tool cannot tell whether it is representative."),e.unit==="section"?(o.push(" - every section recall() returns being carried for the rest of the session,"),o.push(" up to its token cap per turn. A real agent may widen with outline() or"),o.push(" read the whole file anyway.")):(o.push(" - every OnDemandMemory file whose triggers match being opened in full. A real"),o.push(" agent may read one and stop, or ignore one the list offered.")),o.push(" - memory tokens only. Reasoning, tool results and conversation are excluded"),o.push(" from both sides, so this ratio is not a session bill."),o.push(""),o.push(" For observed usage against a live agent, measure a real multi-turn session with"),o.push(" and without the compile. That is the only path allowed to call a number measured."),o.push(""),o.push(` tokenizer: ${t}, an offline estimate`),o.push(""),o.join(`
6
- `)}function Ro(){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 O from"node:path";function _(e){let t=Le(e);return t&&Be(t)?t:void 0}function st(e){return e===void 0||e==="codex"}var Y=" --host codex";function No(e){return Je(e)??`"${e.replace(/"/g,'\\"')}"`}function j(e){return e.map(No).join(" ")}function Ho(e){return e.map(No)}function K(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 it(e){if(e==="cursor")return"~/.cursor/mcp.json";if(e==="windsurf")return"~/.codeium/windsurf/mcp_config.json";if(e==="codex")return"~/.codex/config.toml"}function _o(e){return e.codexConfigDir??O.join(e.home,".codex")}function at(e){try{return/^\s*\[mcp_servers\.minnimemory\]\s*$/m.test(T.readFileSync(O.join(_o(e),"config.toml"),"utf8"))}catch{return!1}}function Fo(e,t){let o=[];e.write&&o.push("--profile","full","--allow-write");let n=e.host==="codex";n&&o.push("--host","codex");let r=_(e.cliPath),u=r?["node",r,"mcp",...o]:["npx","-y","minnimemory","mcp",...o],a=n&&t.codexHome?t.codexHome:void 0,d=a?["--env",`CODEX_HOME=${a}`]:[],c=n?["codex","mcp","add","minnimemory",...d,"--",...u]:["claude","mcp","add","minnimemory","-s",e.scope,"--",...u],f=n?["codex","mcp","remove","minnimemory"]:["claude","mcp","remove","minnimemory","-s",e.scope],v=n?["codex","mcp","get","minnimemory"]:["claude","mcp","get","minnimemory"],k=n?["codex","--version"]:["claude","--version"],y=j(c),w=n?["[mcp_servers.minnimemory]",`command = ${JSON.stringify(u[0])}`,`args = [${u.slice(1).map(E=>JSON.stringify(E)).join(", ")}]`,...a?[`env = { CODEX_HOME = ${JSON.stringify(a)} }`]:[]].join(`
8
- `):void 0,M=JSON.stringify({mcpServers:{minnimemory:{command:"npx",args:["-y","minnimemory","mcp",...o]}}},null,2),D={scope:e.scope,servedFlags:o,servedArgv:u,...r?{servedDirect:r}:{},addArgv:c,removeArgv:f,getArgv:v,probeArgv:k,manualLine:y,jsonSnippet:M,...w?{tomlSnippet:w}:{}};if(e.host&&e.host!=="json"){let E=it(e.host);E&&(D.hostConfigPath=E)}return D}function ke(e){return e.error!==void 0&&e.error.code==="ENOENT"}var ve="npx -y minnimemory drift";function dt(e,t){let o=_(e);return(o?`node "${o}" drift`:ve)+(t==="codex"?Y:"")}var be="npx -y minnimemory hook";function lt(e,t){let o=_(e);return(o?`node "${o}" hook`:be)+(t==="codex"?Y:"")}function Lo(e){return e.endsWith(Y)?e.slice(0,-Y.length):e}function ct(e){if(typeof e!="string")return!1;let t=Lo(e);return t===be||xe(t,"hook")}function ut(e,t){let o=a=>a.replace(/\\/g,"/").toLowerCase(),n=/^\s*Command:\s*(.*)$/m.exec(e)?.[1]?.trim(),r=/^\s*Args:\s*(.*)$/m.exec(e)?.[1]?.trim(),u=o(n?`${n} ${r??""}
9
- ${e}`:e);return t.servedDirect?u.includes(o(t.servedDirect)):u.includes("npx -y minnimemory mcp")}function pt(e){let t=/Scope:\s*(User|Project|Local)\b/i.exec(e);return t?t[1].toLowerCase():void 0}function xe(e,t){let o=/^node "([^"]+)" (drift|loaded|hook)$/.exec(e);if(o===null||o[2]!==t)return!1;let n=o[1];return/minnimemory/i.test(n)||ft(n)}function ft(e){if(!O.isAbsolute(e))return!1;let t=O.dirname(e);for(let o=0;o<4;o++)try{return JSON.parse(T.readFileSync(O.join(t,"package.json"),"utf8")).name==="minnimemory"}catch{let n=O.dirname(t);if(n===t)return!1;t=n}return!1}function mt(e){if(typeof e!="string")return!1;let t=Lo(e);return t===ve||xe(t,"drift")}var $e="npx -y minnimemory loaded";function ht(e){let t=_(e);return t?`node "${t}" loaded`:$e}function gt(e){return typeof e=="string"&&(e===$e||xe(e,"loaded"))}function Bo(e,t){let o=dt(e,t),n=lt(e,t),r=ht(e),u=[{event:"UserPromptSubmit",command:o,fallback:ve,isOurs:a=>a===o||mt(a)},{event:"UserPromptSubmit",command:n,fallback:be,isOurs:a=>a===n||ct(a)}];return t==="codex"?u:[...u,{event:"InstructionsLoaded",command:r,fallback:$e,isOurs:a=>a===r||gt(a)}]}function Jo(e,t,o){let n=t.cwd??process.cwd();return o==="codex"?e==="user"?O.join(_o(t),"hooks.json"):O.join(n,".codex","hooks.json"):e==="user"?O.join(t.configDir??O.join(t.home,".claude"),"settings.json"):e==="project"?O.join(n,".claude","settings.json"):O.join(n,".claude","settings.local.json")}function Po(e){return e==="codex"?"Restart Codex.":"Restart Claude Code."}var yt="then run /hooks inside Codex once to trust the two minnimemory hooks (Codex skips an untrusted hook)";function Uo(e,t){let o=[];for(let n of e){if(!n||typeof n!="object")continue;let r=n.hooks;if(Array.isArray(r))for(let u of r){let a=u&&typeof u=="object"?u.command:void 0;t(a)&&o.push(a)}}return o}function Go(e){if(!T.existsSync(e))return{};try{let t=JSON.parse(T.readFileSync(e,"utf8"));return!t||typeof t!="object"||Array.isArray(t)?void 0:t}catch{return}}function Wo(e,t){let o=`${JSON.stringify(t,null,2)}
10
- `,n=`${e}.minnimemory-${process.pid}.tmp`;T.writeFileSync(n,o,"utf8");try{T.renameSync(n,e)}catch{T.rmSync(n,{force:!0}),T.writeFileSync(e,o,"utf8")}}function Xo(e){let t=e.hooks;return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function wt(e,t){if(e.host==="codex"&&e.scope==="local")return{exitCode:2,output:"install --hook: Codex has no local scope; use --scope user or --scope project.",path:""};let o=Jo(e.scope,t,e.host),n=Bo(e.cliPath,e.host);if(e.dryRun)return{exitCode:0,output:n.map(c=>`would add the ${c.event} hook \`${c.command}\` to ${o}`).join(`
11
- `),path:o};let r=Go(o);if(!r)return{exitCode:1,output:`install --hook: ${o} is not valid JSON; not touched.`,path:o};let u=Xo(r)??{},a=[],d=!1;for(let c of n){let f=Array.isArray(u[c.event])?[...u[c.event]]:[],v=Uo(f,c.isOurs);if(v.includes(c.command)){a.push(c.event==="UserPromptSubmit"?`hook: \`${c.fallback.split(" ").pop()}\` already present in ${o}`:`hook: ${c.event} already present in ${o}`);continue}if(v.length>0){for(let k of f){let y=k&&typeof k=="object"?k.hooks:void 0;if(Array.isArray(y))for(let w of y)w&&typeof w=="object"&&c.isOurs(w.command)&&(w.command=c.command)}a.push(`hook: updated \`${v[0]}\` -> \`${c.command}\` in ${o} (${c.event}). ${Po(e.host)}`)}else{let k={hooks:[{type:"command",command:c.command}]};f.push(k),a.push(`hook: added \`${c.command}\` to ${o} (${c.event}). ${Po(e.host)}`)}u[c.event]=f,d=!0}return d&&(r.hooks=u,T.mkdirSync(O.dirname(o),{recursive:!0}),Wo(o,r)),{exitCode:0,output:a.join(`
12
- `),path:o}}function Io(e,t){let o=Jo(e.scope,t,e.host),n=Bo(e.cliPath,e.host);if(e.dryRun)return{exitCode:0,output:n.map(d=>`would remove the ${d.event} hook (\`${d.fallback}\` or its direct node form) from ${o}`).join(`
13
- `),path:o};if(!T.existsSync(o))return{exitCode:0,output:`hook: nothing to remove (${o} does not exist)`,path:o};let r=Go(o);if(!r)return{exitCode:1,output:`install --remove: ${o} is not valid JSON; not touched.`,path:o};let u=Xo(r),a=[];for(let d of n){let c=u&&Array.isArray(u[d.event])?u[d.event]:void 0,f=c?Uo(c,d.isOurs):[];if(!u||!c||f.length===0)continue;let v=c.filter(k=>{if(!k||typeof k!="object")return!0;let y=k.hooks;if(!Array.isArray(y))return!0;let w=y.filter(M=>!(M&&typeof M=="object"&&d.isOurs(M.command)));return w.length===0?!1:(k.hooks=w,!0)});v.length===0?delete u[d.event]:u[d.event]=v,a.push(`hook: removed \`${f[0]}\` from ${o}`)}return a.length===0?{exitCode:0,output:`hook: nothing to remove in ${o}`,path:o}:(u&&Object.keys(u).length===0&&delete r.hooks,Wo(o,r),{exitCode:0,output:a.join(`
14
- `),path:o})}function qo(e,t,o){let n=Fo(e,t),r=[];if(e.dryRun){r.push(`would run: ${j(n.removeArgv)}`);let c=Io({...e,dryRun:!0},t);return r.push(c.output),{exitCode:0,output:`${r.join(`
15
- `)}
16
- `}}let u=o(n.probeArgv[0],n.probeArgv.slice(1)),a=0;if(ke(u))r.push(`the ${e.host==="codex"?"codex":"claude"} CLI is not on PATH; skipping the MCP registration removal.`);else{let c=o(n.removeArgv[0],n.removeArgv.slice(1));r.push(`ran: ${j(n.removeArgv)}`),c.code!==0&&/no mcp server named/i.test(`${c.stdout}
17
- ${c.stderr}`)?r.push(`nothing registered as minnimemory in ${e.scope} scope`):c.code!==0?(r.push(c.stderr.trim()),a=1):c.stdout.trim()&&r.push(c.stdout.trim())}let d=Io(e,t);return r.push(d.output),d.exitCode!==0&&(a=d.exitCode),{exitCode:a,output:`${r.join(`
18
- `)}
19
- `}}function kt(e,t){let o=_(e),n=o?`node "${o}" init`:"npx -y minnimemory init";return t==="codex"?`next: restart Codex, ${yt}, then ask it to clean up your memory with minnimemory; it starts with init. In a terminal: \`${n} <folder> --host codex\` from your project (Codex's load set needs no --from-log).`:`next: restart Claude Code, then ask it to clean up your memory with minnimemory; it starts with init. In a terminal: \`${n} <folder> --from-log\` from your project.`}function I(e,t,o,n){if(e.hook){let r=wt(e,t);o.push(r.output),r.exitCode!==0&&(n=r.exitCode)}return n===0&&o.push(kt(e.cliPath,e.host)),{exitCode:n,output:`${o.join(`
20
- `)}
21
- `}}function vt(e,t,o,n){let r=[];if(e.dryRun){e.force&&r.push(`would run: ${j(n.removeArgv)}`),r.push(`would run: ${j(n.addArgv)}`);let f=K(n);return f&&r.push(f),I(e,t,r,0)}let u=o(n.probeArgv[0],n.probeArgv.slice(1));if(ke(u))return r.push("the codex CLI is not on PATH. Register minnimemory manually:","",` ${n.manualLine}`,"",`or add this to ${n.hostConfigPath??"~/.codex/config.toml"}:`,"",n.tomlSnippet??""),{exitCode:2,output:`${r.join(`
22
- `)}
23
- `};let a=at(t);if(a&&!e.force)return r.push("minnimemory is already registered with Codex.",`to change it: ${j(["npx","-y","minnimemory","install","--host","codex","--force",...e.write?["--write"]:[]])}`),I(e,t,r,0);if(a){let f=o(n.removeArgv[0],n.removeArgv.slice(1));if(f.code!==0)return r.push(`ran: ${j(n.removeArgv)}`,f.stderr.trim()),{exitCode:1,output:`${r.join(`
24
- `)}
25
- `}}let d=o(n.addArgv[0],n.addArgv.slice(1));if(r.push(`ran: ${j(n.addArgv)}`),d.code!==0)return r.push(d.stderr.trim()),{exitCode:1,output:`${r.join(`
26
- `)}
27
- `};d.stdout.trim()&&r.push(d.stdout.trim());let c=K(n);return c&&r.push(c),I(e,t,r,0)}function zo(e,t,o){let n=Fo(e,t),r=[];if(e.hook&&!st(e.host))return{exitCode:2,output:`--hook only applies to Claude Code and Codex
28
- `};if(e.host==="codex")return vt(e,t,o,n);if(e.host)return r.push(n.jsonSnippet),n.hostConfigPath?r.push("",`config file: ${n.hostConfigPath}`):r.push("",`add this under "mcpServers" in your host's MCP config file.`),{exitCode:0,output:`${r.join(`
29
- `)}
30
- `};if(e.dryRun){e.force&&r.push(`would run: ${j(n.removeArgv)}`),r.push(`would run: ${j(n.addArgv)}`);let w=K(n);return w&&r.push(w),I(e,t,r,0)}let u=o(n.probeArgv[0],n.probeArgv.slice(1));if(ke(u))return r.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:`${r.join(`
31
- `)}
32
- `};let a=o(n.getArgv[0],n.getArgv.slice(1)),d=a.code===0?pt(a.stdout):void 0,c=d!==void 0&&d!==e.scope;c&&r.push(`minnimemory is also registered at ${d} scope; that registration is left as it is (Claude Code uses local, then project, then user).`);let f=a.code===0&&!c,v=f&&!ut(a.stdout,n);if(f&&!e.force&&!v)return r.push("minnimemory is already registered.",`to change it: ${j(["npx","-y","minnimemory","install","--force","--scope",e.scope,...e.write?["--write"]:[]])}`),I(e,t,r,0);if(f){v&&!e.force&&r.push("minnimemory is registered with a different command; repointing it at this copy.");let w=o(n.removeArgv[0],n.removeArgv.slice(1));if(w.code!==0)return r.push(`ran: ${j(n.removeArgv)}`,w.stderr.trim()),{exitCode:1,output:`${r.join(`
33
- `)}
34
- `}}let k=o(n.addArgv[0],n.addArgv.slice(1));if(r.push(`ran: ${j(n.addArgv)}`),k.code!==0)return r.push(k.stderr.trim()),{exitCode:1,output:`${r.join(`
3
+ import{$ as Ge,$a as yt,A as se,B as Pe,Ba as q,Bb as ye,C as je,Ca as pe,Cb as ge,D as ie,Da as Y,Db as we,Ea as K,Eb as ke,Fa as nt,Ia as st,J as Ne,Ja as fe,K as Le,Ka as me,L as B,La as it,M as ae,Ma as at,N as _e,Na as dt,Oa as lt,P as Fe,Pa as ut,Q as _,Qa as V,R as de,Ra as ct,S as Ie,Sa as pt,T as le,Ta as ft,U as Ae,W as Be,Xa as mt,Y as Ue,Z as He,_ as Je,_a as ht,aa as ze,b as L,ba as We,da as X,ea as Xe,f as Te,fa as qe,g as p,ga as Ye,hb as gt,ib as wt,j as Oe,jb as he,ka as Ke,kb as kt,la as Ve,lb as bt,ma as Qe,mb as vt,n as I,na as Ze,nb as $t,o as J,oa as et,ob as xt,p as G,pa as ue,pb as Ct,q as z,qa as tt,qb as St,r as Ee,ra as ot,rb as Mt,s as Re,sb as Tt,t as re,tb as Ot,u as ne,ub as Et,vb as Rt,w as De,wa as rt,wb as Dt,x as A,y as P,ya as ce,z as W,zb as Pt}from"./chunks/chunk-Z7KWUKEZ.js";import{spawnSync as oo}from"node:child_process";import w from"node:fs";import At from"node:os";import y from"node:path";import{fileURLToPath as ro}from"node:url";import{parseArgs as no}from"node:util";import zt from"node:fs";function Wt(t){return t.split(/\r?\n/).map(n=>n.trim()).filter(n=>n!==""&&!n.startsWith("#"))}function jt(t){let n;try{n=zt.readFileSync(t,"utf8")}catch{throw new _(`cannot read workload file: ${t}`)}let e=Wt(n);if(e.length===0)throw new _(`workload file has no tasks: ${t}
4
+ one task description per line, # for comments`);return e}function Q(t){return`${t.onDemandFile}:${t.startLine}`}function Xt(t){return`${t.onDemandFile} > ${t.heading}`}function qt(t,n){let e=L(t).flatMap(d=>J({name:d.name,file:d.file},_e(n,d.file)));return G(e,new Map(L(t).map(d=>[d.name,d.triggers])))}function Nt(t,n,e={}){let d=e.root?qt(t,e.root):void 0,s=d?"section":"file",h=new Set,u=new Map,l=new Map,T=new Map;for(let o of L(t))u.set(o.name,o.tokens),l.set(o.name,o.name),T.set(o.name,o.name);if(d)for(let o of d.units)u.set(Q(o),o.tokens),l.set(Q(o),Xt(o)),T.set(Q(o),o.onDemandFile);let b=[],v=0;n.forEach((o,i)=>{let a=d?Ee(z(d,o)).map(c=>Q(c.unit)):Re(t,o).filter(c=>c.score>0).map(c=>c.name);a.length===0&&v++;let f=a.filter(c=>!h.has(c));for(let c of f)h.add(c);let g=[...h].reduce((c,k)=>c+(u.get(k)??0),0);b.push({turn:i+1,task:o,opened:f.map(c=>l.get(c)??c),carried:[...h].map(c=>l.get(c)??c),compiledTokens:t.prefix.after+g,baselineTokens:t.prefix.before})});let $=b.reduce((o,i)=>o+i.compiledTokens,0),m=b.reduce((o,i)=>o+i.baselineTokens,0),C=new Set([...h].map(o=>T.get(o)??o)),j=L(t).map(o=>o.name).filter(o=>C.has(o)),O=[...h].reduce((o,i)=>o+(u.get(i)??0),0),S=t.prefix.after+O,D=t.prefix.before-S,M=m-$,r;return M>=0?(r=b.findIndex((o,i)=>b.slice(0,i+1).reduce((f,g)=>f+g.baselineTokens-g.compiledTokens,0)>=0),r=r>=0?r+1:void 0):D>0&&(r=b.length+Math.ceil(-M/D)),{unit:s,turns:b,baselineTotal:m,compiledTotal:$,saving:M,savingPct:m===0?0:M/m*100,onDemandOpened:j,onDemandNeverOpened:L(t).map(o=>o.name).filter(o=>!C.has(o)),unroutedTurns:v,steadyStatePerTurn:S,steadyStateGainPerTurn:D,breakEvenTurn:r}}function Yt(t,n){return n===0?"0.0%":`${(t/n*100).toFixed(1)}%`}function be(t){return t>=0?`saves ${p(t)}`:`costs ${p(-t)} more`}function ve(t,n){let e=[""];return e.push(` exact, over ${p(t.turns)} turns. No workload, no assumptions.`),e.push(""),e.push(` original memory file ${p(t.baselinePerTurn).padStart(8)} tokens per turn`),e.push(` compiled always-loaded ${p(t.compiledPerTurn).padStart(8)} tokens per turn`),e.push(` OnDemandMemory, all of it ${p(t.totalOnDemandTokens).padStart(8)} tokens, on demand`),e.push(""),e.push(" best case, no OnDemandMemory file ever opened"),e.push(` ${p(t.baselineTotal)} -> ${p(t.bestCaseTotal)} tokens, ${be(t.bestCaseSaving)} (${Yt(t.bestCaseSaving,t.baselineTotal)})`),e.push(""),e.push(" worst case, every OnDemandMemory file opened on turn 1 and carried"),e.push(` ${p(t.baselineTotal)} -> ${p(t.worstCaseTotal)} tokens, ${be(t.worstCaseSaving)}`),e.push(""),e.push(` break-even: ${p(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: ${n}, an offline estimate`),e.push(""),e.join(`
5
+ `)}function Lt(t,n){let e=[""],d=t.turns.length;if(e.push(` MODEL, not a measurement. ${p(d)} 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 ${p(t.baselineTotal)} -> ${p(t.compiledTotal)}`),e.push(` ${be(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 s of t.onDemandOpened)e.push(` ${s}`);e.push("")}if(t.onDemandNeverOpened.length>0){e.push(` never opened (${t.onDemandNeverOpened.length}) - this is where the saving comes from:`);for(let s of t.onDemandNeverOpened)e.push(` ${s}`);e.push("")}return e.push(" one more turn, once everything this workload opens is in context:"),e.push(` ${p(t.steadyStatePerTurn)} vs ${p(t.turns[0]?.baselineTokens??0)} baseline, ${t.steadyStateGainPerTurn>=0?`saves ${p(t.steadyStateGainPerTurn)}`:`costs ${p(-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 ${p(-t.saving)} at turn ${p(t.turns.length)}, recovering ${p(t.steadyStateGainPerTurn)} per turn:`),e.push(` breaks even around turn ${p(t.breakEvenTurn)} if nothing further opens.`),e.push("")):t.saving>=0&&t.breakEvenTurn!==void 0&&(e.push(` ahead from turn ${p(t.breakEvenTurn)} onward.`),e.push("")),t.unroutedTurns>0&&(e.push(` ${p(t.unroutedTurns)} of ${p(d)} 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: ${n}, an offline estimate`),e.push(""),e.join(`
6
+ `)}function _t(){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 U from"node:fs";import R from"node:path";var Kt=800,Vt=1200,Ft=1024*1024;function Qt(t){try{let n=JSON.parse(t);if(n.type!=="user"||n.isMeta===!0||n.message?.role!=="user")return;let e=n.message.content;return typeof e=="string"?e.trim()||void 0:!Array.isArray(e)||e.some(s=>s?.type==="tool_result")?void 0:e.filter(s=>s?.type==="text"&&typeof s.text=="string").map(s=>s.text).join(`
8
+ `).trim()||void 0}catch{return}}function Zt(t){if(t)try{let n=U.statSync(t).size;for(let e of n>Ft?[n-Ft,0]:[0]){let d=U.openSync(t,"r"),s;try{let u=Buffer.alloc(n-e);U.readSync(d,u,0,u.length,e),s=u.toString("utf8")}finally{U.closeSync(d)}let h=s.split(`
9
+ `);for(let u=h.length-1;u>=(e>0?1:0);u--){let l=Qt(h[u]);if(l)return l}}}catch{}}function eo(t,n){if(!n)return;let e=ft(R.resolve(n));if(!e)return;let d=R.resolve(t);if(ie(R.dirname(d))!==ie(R.resolve(e)))return;let s=R.basename(d);if(!(!/\.md$/i.test(s)||/^MEMORY\.md$/i.test(s)))return{root:R.resolve(e),rel:s}}function to(t){if(!t||typeof t!="object")return;let n=t,e=n.file;if(!(n.type!=="text"||!e||typeof e.content!="string"||typeof e.filePath!="string"))return t}function It(t){try{if(t.toolName!=="Read"||!t.filePath||!t.sessionId||t.offset!==void 0||t.limit!==void 0)return"";let n=to(t.response);if(!n||n.file.startLine>1)return"";let e=Je(t.filePath)??eo(t.filePath,t.cwd);if(!e)return"";let d=U.readFileSync(R.join(e.root,e.rel),"utf8");if(Te(d)<Kt)return"";let s=Zt(t.transcriptPath);if(!s)return"";let h=new Set(I(s)).size,u=Math.min(h,Math.max(2,Math.ceil(h/2))),l=J({name:R.basename(e.rel).replace(/\.md$/i,""),file:e.rel},d),T=z(G(l),s,l.length).map(o=>({...o.unit,score:o.score,matched:o.matched})),b=l.map(o=>new Set(I(o.content))),v=[...new Set(I(s))].filter(o=>{let i=b.filter(a=>a.has(o)).length;return i>0&&i<=Math.floor(l.length/2)});if(v.length===0)return"";let $=[],m=0;for(let o of T){let i=new Set(I(o.content));if(!(o.matched<u||!v.some(a=>i.has(a)))&&!$.some(a=>o.startLine<=a.endLine&&o.endLine>=a.startLine)){if(m+o.tokens>Vt&&$.length>0)break;$.push(o),m+=o.tokens}}if($.length===0)return"";$.sort((o,i)=>o.startLine-i.startLine);let C=d.split(/\r?\n/),j=$.map(o=>`--- lines ${o.startLine}-${o.endLine} of ${C.length} ---
10
+ ${C.slice(o.startLine-1,o.endLine).join(`
11
+ `)}`),O=l.filter(o=>o.kind==="section"&&o.path.length<=2&&!$.some(i=>o.startLine<=i.endLine&&o.endLine>=i.startLine)),S=[...new Map(O.map(o=>[`${o.startLine}-${o.endLine}`,`${o.path.join(" > ")} (lines ${o.startLine}-${o.endLine})`])).values()],M=`${`minnimemory: this Read shows the ${$.length} section(s) of ${e.rel} that match the current prompt.`+(S.length?` Not shown: ${S.join("; ")}. Read with offset and limit to see one.`:" Read with offset and limit to see the rest.")}
12
+
13
+ ${j.join(`
14
+
35
15
  `)}
36
- `};k.stdout.trim()&&r.push(k.stdout.trim());let y=K(n);return y&&r.push(y),I(e,t,r,0)}var Ct=!1,V=`
37
- minnimemory ${ge} the agent memory compiler
16
+ `,r={...n,file:{...n.file,content:M,numLines:M.split(`
17
+ `).length,startLine:1}};return JSON.stringify({hookSpecificOutput:{hookEventName:"PostToolUse",updatedToolOutput:r}})}catch{return""}}var so=!1,Z=`
18
+ minnimemory ${ke} the agent memory compiler
38
19
 
39
20
  usage: the four lifecycle verbs, the CLI and the MCP basic profile share.
40
21
  The only difference is who writes: the CLI writes to disk itself, the MCP tools return the
41
22
  command that does (and the operations it performs) for the agent to run.
42
- minnimemory init <folder> always first: takes where Claude Code loads from (--loaded,
43
- --from-log, --memory-dir; the agent passes them over MCP),
23
+ minnimemory init <folder> always first: takes where the host loads from (Claude Code:
24
+ --loaded, --from-log, --memory-dir, or the agent over MCP;
25
+ Codex: its own load rules, the agent's report over MCP),
44
26
  checks and saves them, then the map, the audit and the diff
45
27
  apply would write; writes only that record; ends with the
46
28
  apply command to run. --map prints only the map
@@ -57,22 +39,28 @@ more
57
39
  minnimemory mcp [path] start the MCP server. Serves init/doctor/apply/undo by
58
40
  default; --profile full serves the seven maintainer tools
59
41
  minnimemory install register minnimemory with the current host
60
- minnimemory uninstall remove the registration and the three hooks install added (same
61
- as install --remove); lists folders still compiled, to undo first
42
+ minnimemory uninstall remove the registration and the hooks install added (four on
43
+ Claude Code, two on Codex; same as install --remove); lists
44
+ folders still compiled, to undo first
62
45
  minnimemory bench <folder> what the compiled shape costs over a session
63
46
  minnimemory recall <path> <query...>
64
47
  recall against a compiled workspace or a manifest-less memory
65
48
  directory (Layout B), whichever <path> is, change nothing
66
- minnimemory hook Claude Code UserPromptSubmit hook: reads hook JSON from stdin,
49
+ minnimemory hook UserPromptSubmit hook (Claude Code, Codex): reads hook JSON from stdin,
67
50
  prints a fenced memory block to stdout, or nothing on no hit.
68
51
  Experimental: measured offline only, not yet in a
69
52
  live session
70
- minnimemory drift Claude Code UserPromptSubmit hook: prints a one-line notice when
53
+ minnimemory drift UserPromptSubmit hook (Claude Code, Codex): prints a one-line notice when
71
54
  memory files changed since the last apply, once per change,
72
55
  nothing otherwise
73
- minnimemory loaded Claude Code InstructionsLoaded hook: records which memory files
56
+ minnimemory loaded Claude Code only, InstructionsLoaded hook: records which memory files
74
57
  Claude Code loaded, for the map init prints; reads hook JSON
75
58
  from stdin, prints nothing
59
+ minnimemory read Claude Code only, PostToolUse hook on Read: logs which
60
+ OnDemandMemory files sessions open, for doctor's MM024; prints
61
+ nothing. --precise (install --precise-reads, off by default):
62
+ a whole-file Read of a large OnDemandMemory file returns only
63
+ the sections the prompt needs
76
64
 
77
65
  install options
78
66
  --scope <name> user, project or local, same meaning as claude mcp add (default user)
@@ -80,7 +68,10 @@ install options
80
68
  --allow-write); the default basic profile never writes
81
69
  --dry-run print the command without running it, exit 0
82
70
  --force remove an existing registration first, then re-add
83
- --no-hook skip the three hooks (memory, drift notice, load log); on by default
71
+ --no-hook skip the hooks (memory, drift notice, and on Claude Code the load
72
+ log and the Read usage log); on by default
73
+ --precise-reads the Read hook also trims a whole-file Read of a large OnDemandMemory
74
+ file to the sections the prompt needs; off by default (unproven live)
84
75
  --remove remove the MCP registration and the hooks install added (= uninstall)
85
76
  --host <name> codex: register with Codex (codex mcp add) and write the two
86
77
  UserPromptSubmit hooks to ~/.codex/hooks.json (--scope user) or
@@ -135,6 +126,7 @@ init and doctor options
135
126
  auto same as none today, for every source
136
127
  none structure only, embed nothing
137
128
  routing the rules that make routing work, about 210 tokens
129
+ output the answer-length rules alone, about 230 tokens
138
130
  full the complete set, about 710 tokens
139
131
  --allow-secrets preview as if a credential-shaped source were allowed through
140
132
  --episodic-json plan episodic OnDemandMemory files (changelogs, logs) as JSON, not
@@ -163,6 +155,7 @@ apply options
163
155
  auto same as none today, for every source
164
156
  none structure only, embed nothing
165
157
  routing the rules that make routing work, about 210 tokens
158
+ output the answer-length rules alone, about 230 tokens
166
159
  full the complete set, about 710 tokens
167
160
  --allow-secrets compile even when the source holds a credential-shaped string
168
161
  --episodic-json write episodic OnDemandMemory files (changelogs, logs) as JSON, not
@@ -228,177 +221,185 @@ doctor options
228
221
  <folder> is required: a repo, a memory directory, or a single file. With none, minnimemory asks
229
222
  for it (in a terminal) or stops and says so. Type . for the current folder. An @import that
230
223
  points outside the folder is not read; the report names it.
231
- `;function St(){let e=[""," rule set",""];for(let t of Ve)e.push(` ${t.id.padEnd(8)}${t.severity.padEnd(6)}${t.title}`);return e.push(""),e.join(`
232
- `)}function Ot(e,t){if(e===void 0)return t;if(e==="low"||e==="med"||e==="high")return e;throw new Error(`--fail-on must be one of low, med, high (got "${e}")`)}function Ko(e){return e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function jt(e,t){return e.matches.length===0?`
233
- no match for "${e.query}"
224
+ `;function io(){let t=[""," rule set",""];for(let n of We)t.push(` ${n.id.padEnd(8)}${n.severity.padEnd(6)}${n.title}`);return t.push(""),t.join(`
225
+ `)}function ao(t,n){if(t===void 0)return n;if(t==="low"||t==="med"||t==="high")return t;throw new Error(`--fail-on must be one of low, med, high (got "${t}")`)}function Bt(t){return t?t.split(",").map(n=>n.trim()).filter(Boolean):[]}function lo(t,n){return t.matches.length===0?`
226
+ no match for "${t.query}"
234
227
 
235
- `:t?`${e.matches.map(o=>`${o.onDemandFile} > ${o.path.join(" > ")} (${o.tokens} tokens)`).join(`
228
+ `:n?`${t.matches.map(e=>`${e.onDemandFile} > ${e.path.join(" > ")} (${e.tokens} tokens)`).join(`
236
229
  `)}
237
- `:`${e.matches.map(o=>`## ${o.onDemandFile} > ${o.path.join(" > ")} (lines ${o.startLine}-${o.endLine}, ${o.tokens} tokens, score ${o.score})
230
+ `:`${t.matches.map(e=>`## ${e.onDemandFile} > ${e.path.join(" > ")} (lines ${e.startLine}-${e.endLine}, ${e.tokens} tokens, score ${e.score})
238
231
 
239
- ${o.content}`).join(`
232
+ ${e.content}`).join(`
240
233
 
241
234
  ---
242
235
 
243
236
  `)}
244
- `}function Mt(e){return e.isTTY?"usage":"serve"}function Vo(){return(e,t)=>{let o=process.platform==="win32",n=bt(e,o?Ho(t):t,{encoding:"utf8",shell:o});return{code:n.status,stdout:n.stdout??"",stderr:n.stderr??"",error:n.error}}}function Et(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 Tt(e){if(e!==void 0){if(e==="cursor"||e==="windsurf"||e==="json"||e==="codex")return e;throw new Error(`--host must be one of codex, cursor, windsurf, json (got "${e}")`)}}function Qo(e){if(e===void 0)return;let t=Number(e);if(!Number.isInteger(t)||t<=0||t>te)throw new Error(`--budget must be a whole number of tokens from 1 to ${te.toLocaleString("en-US")} (got "${e}")`);return Math.floor(t)}function Dt(e,t){let o;try{if(o=$.resolve(e),!S.existsSync(o)||!S.statSync(o).isDirectory())throw new H(`not a directory: ${o}`)}catch(r){return r instanceof H?(process.stderr.write(`
245
- error: ${r.message}
237
+ `}function uo(t){return t.isTTY?"usage":"serve"}function Ut(){return(t,n)=>{let e=process.platform==="win32",d=oo(t,e?St(n):n,{encoding:"utf8",shell:e});return{code:d.status,stdout:d.stdout??"",stderr:d.stderr??"",error:d.error}}}function co(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 po(t){if(t!==void 0){if(t==="cursor"||t==="windsurf"||t==="json"||t==="codex")return t;throw new Error(`--host must be one of codex, cursor, windsurf, json (got "${t}")`)}}function Ht(t){if(t===void 0)return;let n=Number(t);if(!Number.isInteger(n)||n<=0||n>re)throw new Error(`--budget must be a whole number of tokens from 1 to ${re.toLocaleString("en-US")} (got "${t}")`);return Math.floor(n)}function fo(t,n){let e;try{if(e=y.resolve(t),!w.existsSync(e)||!w.statSync(e).isDirectory())throw new B(`not a directory: ${e}`)}catch(s){return s instanceof B?(process.stderr.write(`
238
+ error: ${s.message}
246
239
 
247
240
  `),2):(process.stderr.write(`
248
- unexpected error: ${r.stack??String(r)}
241
+ unexpected error: ${s.stack??String(s)}
249
242
 
250
- `),2)}let n=t.profile??"basic";return n!=="basic"&&n!=="full"?(process.stderr.write(`
251
- error: --profile must be one of basic, full (got "${n}")
243
+ `),2)}let d=n.profile??"basic";return d!=="basic"&&d!=="full"?(process.stderr.write(`
244
+ error: --profile must be one of basic, full (got "${d}")
252
245
 
253
- `),2):((async()=>{let[{StdioServerTransport:r},{createMcpServer:u}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-6J4GLXHP.js")]);await u(o,{profile:n,allowWrite:t["allow-write"]===!0,host:J()}).connect(new r)})().catch(r=>{process.stderr.write(`
254
- mcp server failed: ${r.message??String(r)}
255
- `),process.exitCode=1}),0)}function At(){let e=mo(),t=[];if(e.length>0){t.push("still compiled (they keep working without minnimemory; to put the originals back, undo each one):");for(let o of e)t.push(` ${Ue(o)}`)}return t.push(`kept: ${$.dirname(uo())} (init records, the load log, undo backups); delete it yourself once you have checked undo-backups/.`),t.push("restart Claude Code."),t.join(`
256
- `)}var Rt=new Set(["init","doctor","apply","undo","bench"]);function Pt(e){if(q(process.cwd()))return!0;let t=Ce(e);return le(t)==="compiled"||ue(t)!==void 0||ie(t)!==void 0}function Ce(e){let t=$.resolve(e);return S.existsSync(t)&&S.statSync(t).isFile()?$.dirname(t):t}function It(e){if(q(process.cwd()))return;let t=Ce(e);return ie(t)?qe(t):void 0}function Nt(e){let t=`minnimemory ${e} <folder>`;if(process.stdin.isTTY!==!0){process.stderr.write(`
257
- error: name the folder to read: ${t} (type . for the current folder)
246
+ `),2):((async()=>{let[{StdioServerTransport:s},{createMcpServer:h}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-HEZQUR7M.js")]);await h(e,{profile:d,allowWrite:n["allow-write"]===!0,host:P()}).connect(new s)})().catch(s=>{process.stderr.write(`
247
+ mcp server failed: ${s.message??String(s)}
248
+ `),process.exitCode=1}),0)}function mo(){let t=ut(),n=[];if(t.length>0){n.push("still compiled (they keep working without minnimemory; to put the originals back, undo each one):");for(let d of t)n.push(` ${Ne(d)}`)}let e=P()==="codex";return n.push(`kept: ${y.dirname(at())} (init records, ${e?"":"the load log, the usage log, "}undo backups); delete it yourself once you have checked undo-backups/.`),n.push(`restart ${se()}.`),n.join(`
249
+ `)}var ho=new Set(["init","doctor","apply","undo","bench"]);function yo(t){if(V(process.cwd()))return!0;let n=$e(t);return pe(n)==="compiled"||me(n)!==void 0||le(n)!==void 0}function $e(t){let n=y.resolve(t);return w.existsSync(n)&&w.statSync(n).isFile()?y.dirname(n):n}function go(t){if(V(process.cwd()))return;let n=$e(t);return le(n)?Ie(n):void 0}function wo(t){let n=`minnimemory ${t} <folder>`;if(process.stdin.isTTY!==!0){process.stderr.write(`
250
+ error: name the folder to read: ${n} (type . for the current folder)
258
251
 
259
252
  `);return}process.stdout.write(`
260
- Which folder should minnimemory ${e} read? Only that folder and the folders below it are read.
261
- folder: `);let o=Ht().trim();if(o===""){process.stderr.write(`
262
- error: no folder given; run ${t}
253
+ Which folder should minnimemory ${t} read? Only that folder and the folders below it are read.
254
+ folder: `);let e=ko().trim();if(e===""){process.stderr.write(`
255
+ error: no folder given; run ${n}
263
256
 
264
- `);return}return o}function Ht(){let e=Buffer.alloc(1),t="";for(;;){let o;try{o=S.readSync(0,e,0,1,null)}catch{break}if(o===0)break;let n=e.toString("utf8");if(n===`
265
- `)break;n!=="\r"&&(t+=n)}return t}function _t(e){let t;try{t=$t({args:e,allowPositionals:!0,strict:!0,options:{json:{type:"boolean",default:!1},write:{type:"boolean",default:!1},force:{type:"boolean",default:!1},update:{type:"boolean",default:!1},"allow-secrets":{type:"boolean",default:!1},"episodic-json":{type:"boolean",default:!1},"allow-write":{type:"boolean",default:!1},"follow-external-imports":{type:"boolean",default:!1},"include-auto-memory":{type:"boolean",default:!1},scope:{type:"string"},"dry-run":{type:"boolean",default:!1},"auto-memory":{type:"boolean",default:!1},hook:{type:"boolean",default:!1},"no-hook":{type:"boolean",default:!1},remove:{type:"boolean",default:!1},host:{type:"string"},"host-file":{type:"string",multiple:!0},loaded:{type:"string",multiple:!0},"memory-dir":{type:"string"},"from-log":{type:"boolean",default:!1},"only-this-folder":{type:"boolean",default:!1},turns:{type:"string"},workload:{type:"string"},"whole-files":{type:"boolean",default:!1},"max-tokens":{type:"string"},headings:{type:"boolean",default:!1},dir:{type:"string"},profile:{type:"string"},plan:{type:"string"},ci:{type:"boolean",default:!1},rules:{type:"boolean",default:!1},map:{type:"boolean",default:!1},diff:{type:"string"},"fail-on":{type:"string"},budget:{type:"string"},policy:{type:"string"},only:{type:"string"},ignore:{type:"string"},help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",short:"v",default:!1}}})}catch(s){let l=s.message,p=/argument is ambiguous/.test(l)?`
257
+ `);return}return e}function ko(){let t=Buffer.alloc(1),n="";for(;;){let e;try{e=w.readSync(0,t,0,1,null)}catch{break}if(e===0)break;let d=t.toString("utf8");if(d===`
258
+ `)break;d!=="\r"&&(n+=d)}return n}function bo(t){let n;try{n=no({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},"precise-reads":{type:"boolean",default:!1},precise:{type:"boolean",default:!1},remove:{type:"boolean",default:!1},host:{type:"string"},"host-file":{type:"string",multiple:!0},loaded:{type:"string",multiple:!0},"memory-dir":{type:"string"},"from-log":{type:"boolean",default:!1},"only-this-folder":{type:"boolean",default:!1},turns:{type:"string"},workload:{type:"string"},"whole-files":{type:"boolean",default:!1},"max-tokens":{type:"string"},headings:{type:"boolean",default:!1},dir:{type:"string"},profile:{type:"string"},plan:{type:"string"},ci:{type:"boolean",default:!1},rules:{type:"boolean",default:!1},map:{type:"boolean",default:!1},diff:{type:"string"},"fail-on":{type:"string"},budget:{type:"string"},policy:{type:"string"},only:{type:"string"},ignore:{type:"string"},help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",short:"v",default:!1}}})}catch(r){let o=r.message,i=/argument is ambiguous/.test(o)?`
266
259
  (a value that starts with '-' must be written as --option=value; --budget must be positive anyway)`:"";return process.stderr.write(`
267
- error: ${l}${p}
268
- ${V}`),2}let{values:o,positionals:n}=t;if(o.help)return process.stdout.write(V),0;if(o.version)return process.stdout.write(`${ge}
269
- `),0;if(o.rules)return process.stdout.write(St()),0;let r;if(n[0]===void 0){if(Mt({isTTY:process.stdin.isTTY===!0})==="usage")return process.stdout.write(V),0;r="mcp"}else r=n[0];let u=["include-auto-memory","follow-external-imports","auto-memory"].filter(s=>o[s]===!0);u.length>0&&process.stderr.write(` note: ${u.map(s=>`--${s}`).join(", ")} no longer does anything: minnimemory reads only the folder you name
270
- `);let a=n[1]===void 0?void 0:/^~($|[\\/])/.test(n[1])?W(n[1]):n[1];if(a===void 0&&typeof o["memory-dir"]=="string"&&(a=o["memory-dir"]),a===void 0&&["doctor","apply","undo"].includes(r)){let s=q(process.cwd());s&&(a=s.target??s.memoryDir??s.project)}if(a===void 0&&Rt.has(r)&&(a=Nt(r),a===void 0))return 2;let d=a??".";if(r!=="install"&&r!=="uninstall")if(o.host!==void 0){if(!Ie(o.host))return process.stderr.write(`
271
- error: --host must be claude or codex for ${r} (got "${o.host}")
260
+ error: ${o}${i}
261
+ ${Z}`),2}let{values:e,positionals:d}=n;if(e.help)return process.stdout.write(Z),0;if(e.version)return process.stdout.write(`${ke}
262
+ `),0;if(e.rules)return process.stdout.write(io()),0;let s;if(d[0]===void 0){if(uo({isTTY:process.stdin.isTTY===!0})==="usage")return process.stdout.write(Z),0;s="mcp"}else s=d[0];let h=["include-auto-memory","follow-external-imports","auto-memory"].filter(r=>e[r]===!0);h.length>0&&process.stderr.write(` note: ${h.map(r=>`--${r}`).join(", ")} no longer does anything: minnimemory reads only the folder you name
263
+ `);let u=d[1]===void 0?void 0:/^~($|[\\/])/.test(d[1])?Y(d[1]):d[1];if(u===void 0&&typeof e["memory-dir"]=="string"&&(u=e["memory-dir"]),u===void 0&&["doctor","apply","undo"].includes(s)){let r=V(process.cwd());r&&(u=r.target??r.memoryDir??r.project)}if(u===void 0&&ho.has(s)&&(u=wo(s),u===void 0))return 2;let l=u??".";if(s!=="install"&&s!=="uninstall")if(e.host!==void 0){if(!De(e.host))return process.stderr.write(`
264
+ error: --host must be claude or codex for ${s} (got "${e.host}")
272
265
 
273
- `),2;B(o.host)}else["init","doctor","apply","undo","mcp"].includes(r)?B(_e({env:process.env,home:Yo.homedir(),cwd:process.cwd()})):B("claude");if(o.policy!==void 0&&r!=="doctor")return process.stderr.write(`
266
+ `),2;A(e.host)}else["init","doctor","apply","undo","mcp"].includes(s)?A(Pe({env:process.env,home:At.homedir(),cwd:process.cwd()})):A("claude");if(e.policy!==void 0&&s!=="doctor")return process.stderr.write(`
274
267
  error: --policy is a doctor option: \`minnimemory doctor <folder> --policy <file>\`
275
268
 
276
- `),2;if(o.diff!==void 0&&o.diff!=="summary"&&o.diff!=="full")return process.stderr.write(`
277
- error: --diff takes summary or full, not "${o.diff}"
269
+ `),2;if(e.diff!==void 0&&e.diff!=="summary"&&e.diff!=="full")return process.stderr.write(`
270
+ error: --diff takes summary or full, not "${e.diff}"
278
271
 
279
- `),2;let c=o.diff,f=[...o.loaded??[],...o["host-file"]??[]].map(s=>W(s));if(o["from-log"]===!0){let s=vo(process.cwd());if(!s)return process.stderr.write(`
272
+ `),2;let T=e.diff,b=[...e.loaded??[],...e["host-file"]??[]].map(r=>Y(r));if(e["from-log"]===!0){let r=kt(process.cwd());if(!r)return process.stderr.write(`
280
273
  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
281
274
 
282
- `),2;for(let l of Object.keys(s.files))/\.md$/i.test(l)&&S.existsSync(l)&&f.push($.resolve(l))}let v=typeof o["memory-dir"]=="string"?W(o["memory-dir"]):void 0,y=f.length>0||v!==void 0||o["only-this-folder"]===!0?{files:[...new Set(f)],...v?{memoryDir:v}:{},source:o["from-log"]===!0&&(o.loaded??[]).length===0?"log":"terminal",...o["only-this-folder"]===!0?{onlyThisFolder:!0}:{}}:void 0,w=y||!["doctor","apply"].includes(r)?void 0:It(d),M=y?void 0:ho(process.cwd())??(w?ze(Ce(d)):void 0);w&&process.stderr.write(` note: this machine has no init record for this project, so ${r} uses the one in the repo: ${$.relative(process.cwd(),w).split($.sep).join("/")||w}
283
- `);let D={cwd:process.cwd(),...y?{reported:y}:M?{reported:M}:{}};if(r==="install"||r==="uninstall"){let s;try{s={write:o.write===!0,scope:Et(o.scope),dryRun:o["dry-run"]===!0,force:o.force===!0,host:Tt(o.host),hook:(o.host===void 0||o.host==="codex")&&o["no-hook"]!==!0,cliPath:process.argv[1]?Ft(process.argv[1]):void 0}}catch(C){return process.stderr.write(`
284
- error: ${C.message}
275
+ `),2;for(let o of Object.keys(r.files))/\.md$/i.test(o)&&w.existsSync(o)&&b.push(y.resolve(o))}let v=typeof e["memory-dir"]=="string"?Y(e["memory-dir"]):void 0;if(v&&P()==="codex"&&Be(W("codex"),v))return process.stderr.write(`
276
+ error: ${v.split(y.sep).join("/")} is Codex's own memories folder: Codex generates and rewrites it, so minnimemory lists it in the map and never compiles it. Run init on the project; Codex's AGENTS.md files are what it works on.
277
+
278
+ `),2;let m=b.length>0||v!==void 0||e["only-this-folder"]===!0?{files:[...new Set(b)],...v?{memoryDir:v}:{},source:e["from-log"]===!0&&(e.loaded??[]).length===0?"log":"terminal",...e["only-this-folder"]===!0?{onlyThisFolder:!0}:{}}:void 0,C=m||!["doctor","apply"].includes(s)?void 0:go(l),j=m?void 0:ct(process.cwd())??(C?Ae($e(l)):void 0);C&&process.stderr.write(` note: this machine has no init record for this project, so ${s} uses the one in the repo: ${y.relative(process.cwd(),C).split(y.sep).join("/")||C}
279
+ `);let O={cwd:process.cwd(),...m?{reported:m}:j?{reported:j}:{}},S,D;if(["init","doctor","apply","undo"].includes(s)){let r=nt(l,{reported:m});r&&(S=st(l,r),D=y.resolve(l),l=r.dir,u=r.dir,s!=="init"&&e.json!==!0&&process.stdout.write(`
280
+ ${S}
281
+ `))}if(s==="install"||s==="uninstall"){let r;try{r={write:e.write===!0,scope:co(e.scope),dryRun:e["dry-run"]===!0,force:e.force===!0,host:po(e.host),hook:(e.host===void 0||e.host==="codex")&&e["no-hook"]!==!0,preciseReads:e["precise-reads"]===!0,cliPath:process.argv[1]?vo(process.argv[1]):void 0}}catch(g){return process.stderr.write(`
282
+ error: ${g.message}
285
283
 
286
- `),2}let l={home:Yo.homedir(),platform:process.platform,cwd:process.cwd(),configDir:Fe(),codexConfigDir:Ne("codex"),...process.env.CODEX_HOME?{codexHome:process.env.CODEX_HOME}:{}},p=r==="uninstall"||o.remove===!0,i=p?qo(s,l,Vo()):zo(s,l,Vo()),h=i.exitCode===0?process.stdout:process.stderr;return h.write(`
287
- ${i.output}
288
- `),p&&h.write(`${At()}
284
+ `),2}let o={home:At.homedir(),platform:process.platform,cwd:process.cwd(),configDir:je(),codexConfigDir:W("codex"),...process.env.CODEX_HOME?{codexHome:process.env.CODEX_HOME}:{}},i=s==="uninstall"||e.remove===!0;i&&r.host==="codex"&&A("codex");let a=i?Mt(r,o,Ut()):Tt(r,o,Ut()),f=a.exitCode===0?process.stdout:process.stderr;return f.write(`
285
+ ${a.output}
286
+ `),i&&f.write(`${mo()}
289
287
 
290
- `),i.exitCode}if(r==="init"||r==="apply"){if(r==="init"&&(o.write===!0||o.update===!0))return process.stderr.write(`
288
+ `),a.exitCode}if(s==="init"||s==="apply"){if(s==="init"&&(e.write===!0||e.update===!0))return process.stderr.write(`
291
289
  error: init never writes; use apply
292
290
 
293
- `),2;let s=o.profile??"auto";if(s!=="auto"&&!Ee(s))return process.stderr.write(`
294
- error: --profile must be one of auto, none, routing, full (got "${s}")
291
+ `),2;let r=e.profile??"auto";if(r!=="auto"&&!Oe(r))return process.stderr.write(`
292
+ error: --profile must be one of auto, none, routing, output, full (got "${r}")
295
293
 
296
- `),2;let l;try{l=Qo(o.budget)}catch(b){return process.stderr.write(`
297
- error: ${b.message}
294
+ `),2;let o;try{o=Ht(e.budget)}catch(k){return process.stderr.write(`
295
+ error: ${k.message}
298
296
 
299
- `),2}let p=r==="apply",i=s==="auto"?void 0:s,h=o["episodic-json"]===!0,C=[...J()==="codex"?["--host codex"]:[],...i?[`--profile ${i}`]:[],...h?["--episodic-json"]:[],...o["only-this-folder"]===!0?["--only-this-folder"]:[]],x={budget:l,force:o.force===!0,profileName:i,episodicJson:h,discover:D};try{if(!p){let Z=S.existsSync(d)&&S.statSync(d).isFile()?$.dirname($.resolve(d)):$.resolve(d),N;try{let L=X(d,D);L.shape==="memory-dir"&&(N=L)}catch{N=void 0}let A=!N&&J()==="codex"?Oo(process.cwd(),{projectRoot:Z}):void 0,ee=A?void 0:N?Co(N):xo(Z,{machine:!1,projectRoot:Z}),Se=A?jo(A):So(ee),Zo=()=>A?Mo(A):$o(ee);if(o.map===!0)return process.stdout.write(o.json?`${JSON.stringify(A??ee,null,2)}
300
- `:Se),0;o.json||process.stdout.write(Se);let F=fe(d,x);if(o.json){let L=JSON.parse(he(F,a,C));process.stdout.write(`${JSON.stringify({map:Zo(),...L},null,2)}
301
- `)}else process.stdout.write(me(F,{color:!1,ci:o.ci===!0,target:a,flags:C,diff:c}));let oe=F.workspace.folderRoot??$.resolve(d),Oe=F.workspace.claudeMemoryFolder?oe:void 0,je=po(process.cwd(),y?{...y,...y.memoryDir??Oe?{memoryDir:y.memoryDir??Oe}:{}}:void 0,oe);y&&!o.json&&process.stdout.write(je?` saved what ${He()} loads here for apply, doctor and undo: ${je}
297
+ `),2}let i=s==="apply",a=r==="auto"?void 0:r,f=e["episodic-json"]===!0,g=[...P()==="codex"?["--host codex"]:[],...a?[`--profile ${a}`]:[],...f?["--episodic-json"]:[],...e["only-this-folder"]===!0?["--only-this-folder"]:[]],c={budget:o,force:e.force===!0,profileName:a,episodicJson:f,discover:O};try{if(!i){let ee=w.existsSync(l)&&w.statSync(l).isFile()?y.dirname(y.resolve(l)):y.resolve(l),F;try{let N=K(l,O);N.shape==="memory-dir"&&(F=N)}catch{F=void 0}let E=!F&&P()==="codex"?Et(process.cwd(),{projectRoot:D??ee}):void 0,te=E?void 0:F?xt(F):vt(ee,{machine:!1,projectRoot:ee}),xe=E?Rt(E):Ct(te),Gt=()=>E?Dt(E):$t(te);if(e.map===!0)return process.stdout.write(e.json?`${JSON.stringify(E??te,null,2)}
298
+ `:xe),0;e.json||process.stdout.write(xe),S&&!e.json&&process.stdout.write(` ${S}
299
+
300
+ `);let H=ye(l,c);if(e.json){let N=JSON.parse(we(H,u,g));process.stdout.write(`${JSON.stringify({map:Gt(),...N},null,2)}
301
+ `)}else process.stdout.write(ge(H,{color:!1,ci:e.ci===!0,target:u,flags:g,diff:T}));let oe=H.workspace.folderRoot??y.resolve(l),Ce=H.workspace.claudeMemoryFolder?oe:void 0,Se=dt(process.cwd(),m?{...m,...m.memoryDir??Ce?{memoryDir:m.memoryDir??Ce}:{}}:void 0,oe);!m&&E&&pt(process.cwd(),E.chain.map(N=>N.abs)),m&&!e.json&&process.stdout.write(Se?` saved what ${se()} loads here for apply, doctor and undo: ${Se}
302
302
 
303
303
  `:` could not save the locations; pass them again to apply
304
304
 
305
- `);let Me=fo(process.cwd(),oe);return Me&&process.stderr.write(` ${Me}
305
+ `);let Me=lt(process.cwd(),oe);return Me&&process.stderr.write(` ${Me}
306
306
 
307
- `),0}let b=X(d,D);if(b.shape==="memory-dir"&&!b.reported)return process.stderr.write(`
307
+ `),0}let k=K(l,O);if(k.shape==="memory-dir"&&!k.reported)return process.stderr.write(`
308
308
  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.
309
309
 
310
- `),2;let m=Ze(b,{budget:l??b.manifest?.budget,profileName:i,episodicJson:h,sortAnyway:o.force===!0});if(o.plan!==void 0&&m.plan!==o.plan)return process.stderr.write(`
311
- error: the plan on disk no longer matches --plan ${o.plan} (now ${m.plan}); run doctor again
310
+ `),2;let x=qe(k,{budget:o??k.manifest?.budget,profileName:a,episodicJson:f,sortAnyway:e.force===!0});if(e.plan!==void 0&&x.plan!==e.plan)return process.stderr.write(`
311
+ error: the plan on disk no longer matches --plan ${e.plan} (now ${x.plan}); run doctor again
312
312
 
313
- `),2;if(m.verdict==="nothing")return process.stdout.write(de(m,{write:!0})),0;if(m.verdict==="leave"&&o.force!==!0)return process.stderr.write(`
314
- error: ${lo(m)} (${m.before} -> ${m.after} tokens; break-even ${m.bounds.breakEvenCarriedTokens} tokens of OnDemandMemory open all session)
313
+ `),2;if(x.verdict==="nothing")return process.stdout.write(ce(x,{write:!0})),0;if(x.verdict==="leave"&&e.force!==!0)return process.stderr.write(`
314
+ error: ${rt(x)} (${x.before} -> ${x.after} tokens; break-even ${x.bounds.breakEvenCarriedTokens} tokens of OnDemandMemory open all session)
315
315
  Pass --force to write it anyway.
316
316
 
317
- `),2;let Q=de(m,{write:!0,target:a});return eo(m,{allowSecrets:o["allow-secrets"]===!0}),process.stdout.write(Q),0}catch(b){return b instanceof G||b instanceof U?(process.stderr.write(`
318
- error: ${b.message}
317
+ `),2;let Jt=ce(x,{write:!0,target:u});return Ye(x,{allowSecrets:e["allow-secrets"]===!0}),process.stdout.write(Jt),0}catch(k){return k instanceof q||k instanceof X?(process.stderr.write(`
318
+ error: ${k.message}
319
319
 
320
320
  `),2):(process.stderr.write(`
321
- unexpected error: ${b.stack??String(b)}
321
+ unexpected error: ${k.stack??String(k)}
322
322
 
323
- `),2)}}if(r==="undo")try{let s;try{s=X(d).folderRoot}catch(x){if(!(x instanceof G))throw x}if(!s)return process.stdout.write(`
323
+ `),2)}}if(s==="undo")try{let r;try{r=K(l).folderRoot}catch(c){if(!(c instanceof q))throw c}if(!r)return process.stdout.write(`
324
324
  nothing to undo
325
325
 
326
- `),0;let l=ue(s),p=l?void 0:co(s),i=p?ao(s,p):!l&&ce(s)?ro(s):no(s,l);if(i.kind==="none")return!l&&ce(s)?(process.stderr.write(`
327
- error: ${Qe(s)}
326
+ `),0;let o=me(r),i=o?void 0:it(r),a=i?ot(r,i):!o&&fe(r)?Ze(r):Qe(r,o);if(a.kind==="none")return!o&&fe(r)?(process.stderr.write(`
327
+ error: ${Xe(r)}
328
328
 
329
329
  `),2):(process.stdout.write(`
330
330
  nothing to undo
331
331
 
332
- `),0);if(i.kind==="kept-only")return process.stderr.write(`
333
- error: undo has nothing left to restore here: ${so(i.kept)}
332
+ `),0);if(a.kind==="kept-only")return process.stderr.write(`
333
+ error: undo has nothing left to restore here: ${et(a.kept)}
334
334
 
335
- `),2;if(i.kind==="missing-original")return process.stderr.write(`
336
- error: no original copy under ${ne}/original/ for: ${i.files.join(", ")}.
335
+ `),2;if(a.kind==="missing-original")return process.stderr.write(`
336
+ error: no original copy under ${ne}/original/ for: ${a.files.join(", ")}.
337
337
  Backups stay on the machine that ran apply (they are gitignored), and a clone that re-applied backs up the compiled file, not the original; on a clone, the way back is git history.
338
338
 
339
- `),2;let h=oo(i.plan);if(h&&o.force!==!0)return process.stderr.write(`
340
- error: ${h}
339
+ `),2;let f=Ke(a.plan);if(f&&e.force!==!0)return process.stderr.write(`
340
+ error: ${f}
341
341
 
342
- `),2;let C=h?to(i.plan):void 0;return io(i.plan),process.stdout.write(`
343
- restored ${i.plan.operations.filter(x=>x.op==="write"||x.op==="move").length} file(s) in ${s}
344
- deleted: ${i.plan.operations.filter(x=>x.op==="delete").length} path(s), ${ne}/ ${i.plan.keptBackups?.length?"kept":"included"}
345
- `+(ae(i.plan)?` ${ae(i.plan)}
346
- `:"")+(i.plan.left?.length?` left in place: ${i.plan.left.join(", ")} (without manifest.json undo cannot tell which files there it wrote)
347
- `:"")+(C?` the files as they were before this undo are copied to ${C.split($.sep).join("/")}
342
+ `),2;let g=f?Ve(a.plan):void 0;return tt(a.plan),process.stdout.write(`
343
+ restored ${a.plan.operations.filter(c=>c.op==="write"||c.op==="move").length} file(s) in ${r}
344
+ deleted: ${a.plan.operations.filter(c=>c.op==="delete").length} path(s), ${ne}/ ${a.plan.keptBackups?.length?"kept":"included"}
345
+ `+(ue(a.plan)?` ${ue(a.plan)}
346
+ `:"")+(a.plan.left?.length?` left in place: ${a.plan.left.join(", ")} (without manifest.json undo cannot tell which files there it wrote)
347
+ `:"")+(g?` the files as they were before this undo are copied to ${g.split(y.sep).join("/")}
348
348
  `:"")+`
349
- `),0}catch(s){return s instanceof U?(process.stderr.write(`
350
- error: ${s.message}
349
+ `),0}catch(r){return r instanceof X?(process.stderr.write(`
350
+ error: ${r.message}
351
351
 
352
352
  `),2):(process.stderr.write(`
353
- unexpected error: ${s.stack??String(s)}
353
+ unexpected error: ${r.stack??String(r)}
354
354
 
355
- `),2)}if(r==="mcp")return Ct?((async()=>{let[{StdioServerTransport:s},{createDisabledMcpServer:l,DISABLED_MESSAGE:p}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-6J4GLXHP.js")]);process.stderr.write(`
356
- mcp: ${p}
355
+ `),2)}if(s==="mcp")return so?((async()=>{let[{StdioServerTransport:r},{createDisabledMcpServer:o,DISABLED_MESSAGE:i}]=await Promise.all([import("@modelcontextprotocol/sdk/server/stdio.js"),import("./chunks/mcpServer-HEZQUR7M.js")]);process.stderr.write(`
356
+ mcp: ${i}
357
357
 
358
- `),await l().connect(new s)})().catch(s=>{process.stderr.write(`
359
- mcp server failed: ${s.message??String(s)}
360
- `),process.exitCode=1}),0):Dt(d,o);if(r==="recall"){let s=n.slice(2).join(" ").trim();if(!s)return process.stderr.write(`
358
+ `),await o().connect(new r)})().catch(r=>{process.stderr.write(`
359
+ mcp server failed: ${r.message??String(r)}
360
+ `),process.exitCode=1}),0):fo(l,e);if(s==="recall"){let r=d.slice(2).join(" ").trim();if(!r)return process.stderr.write(`
361
361
  error: recall needs a query: minnimemory recall <path> <query...>
362
362
 
363
- `),2;let l;if(o["max-tokens"]!==void 0){let i=Number(o["max-tokens"]);if(!Number.isFinite(i)||i<=0)return process.stderr.write(`
364
- error: --max-tokens must be a positive number (got "${o["max-tokens"]}")
363
+ `),2;let o;if(e["max-tokens"]!==void 0){let a=Number(e["max-tokens"]);if(!Number.isFinite(a)||a<=0)return process.stderr.write(`
364
+ error: --max-tokens must be a positive number (got "${e["max-tokens"]}")
365
365
 
366
- `),2;l=Math.floor(i)}let p=$.resolve(d);try{let i=le(p),h;if(i==="compiled")h=Xe(p,re(p),s,{maxTokens:l});else if(i==="memory-dir")h=yo(p,s,{maxTokens:l});else return process.stderr.write(`
367
- 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
366
+ `),2;o=Math.floor(a)}let i=y.resolve(l);try{let a=pe(i),f;if(a==="compiled")f=Fe(i,ae(i),r,{maxTokens:o});else if(a==="memory-dir")f=ht(i,r,{maxTokens:o});else return process.stderr.write(`
367
+ error: ${i} 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
368
368
 
369
- `),2;return process.stdout.write(jt(h,o.headings===!0)),0}catch(i){return i instanceof H||i instanceof go?(process.stderr.write(`
370
- error: ${i.message}
369
+ `),2;return process.stdout.write(lo(f,e.headings===!0)),0}catch(a){return a instanceof B||a instanceof mt?(process.stderr.write(`
370
+ error: ${a.message}
371
371
 
372
372
  `),2):(process.stderr.write(`
373
- unexpected error: ${i.stack??String(i)}
374
-
375
- `),2)}}if(r==="hook"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}let l;if(o["max-tokens"]!==void 0){let p=Number(o["max-tokens"]);Number.isFinite(p)&&p>0&&(l=Math.floor(p))}try{let p=pe(s),i=wo(p,{headings:o.headings===!0,maxTokens:l,dir:o.dir});i&&process.stdout.write(`${i}
376
- `)}catch(p){process.stderr.write(`
377
- hook: ${p.message??String(p)}
378
- `)}return 0}if(r==="loaded"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{bo(JSON.parse(s))}catch{}return 0}if(r==="drift"){let s="";try{s=S.readFileSync(0,"utf8")}catch{s=""}try{let l=pe(s),p=ko(l);p&&process.stdout.write(`${p}
379
- `)}catch(l){process.stderr.write(`
380
- drift: ${l.message??String(l)}
381
- `)}return 0}if(r==="bench")try{let s=$.resolve(d),l=re(s),p=o.turns===void 0?50:Number(o.turns);if(!Number.isFinite(p))throw new P(`--turns must be a positive whole number (got "${o.turns}")`);let i=se(l,p);if(o.workload===void 0)return o.json===!0?(process.stdout.write(`${JSON.stringify({bounds:i,tokenizer:l.tokenizer},null,2)}
382
- `),0):(process.stdout.write(we(i,l.tokenizer)),process.stdout.write(Ro()),0);let h=To(o.workload),C=Do(l,h,o["whole-files"]===!0?{}:{root:s});return o.json===!0?(process.stdout.write(`${JSON.stringify({bounds:i,model:C,tokenizer:l.tokenizer},null,2)}
383
- `),0):(process.stdout.write(we(i,l.tokenizer)),process.stdout.write(Ao(C,l.tokenizer)),0)}catch(s){return s instanceof P||s instanceof H?(process.stderr.write(`
384
- error: ${s.message}
373
+ unexpected error: ${a.stack??String(a)}
374
+
375
+ `),2)}}if(s==="hook"){let r="";try{r=w.readFileSync(0,"utf8")}catch{r=""}let o;if(e["max-tokens"]!==void 0){let i=Number(e["max-tokens"]);Number.isFinite(i)&&i>0&&(o=Math.floor(i))}try{let i=he(r);if(P()==="codex")try{Ot(W("codex"),i.cwd??process.cwd())}catch{}let a=gt(i,{headings:e.headings===!0,maxTokens:o,dir:e.dir});a&&process.stdout.write(`${a}
376
+ `)}catch(i){process.stderr.write(`
377
+ hook: ${i.message??String(i)}
378
+ `)}return 0}if(s==="loaded"){let r="";try{r=w.readFileSync(0,"utf8")}catch{r=""}try{let o=JSON.parse(r);bt(o),o.load_reason==="compact"&&typeof o.session_id=="string"&&yt(o.session_id)}catch{}return 0}if(s==="read"){let r="";try{r=w.readFileSync(0,"utf8")}catch{r=""}let o=Ge(r);if(ze(o),e.precise===!0){let i=It(o);i&&process.stdout.write(`${i}
379
+ `)}return 0}if(s==="drift"){let r="";try{r=w.readFileSync(0,"utf8")}catch{r=""}try{let o=he(r),i=wt(o);i&&process.stdout.write(`${i}
380
+ `)}catch(o){process.stderr.write(`
381
+ drift: ${o.message??String(o)}
382
+ `)}return 0}if(s==="bench")try{let r=y.resolve(l),o=ae(r),i=e.turns===void 0?50:Number(e.turns);if(!Number.isFinite(i))throw new _(`--turns must be a positive whole number (got "${e.turns}")`);let a=de(o,i);if(e.workload===void 0)return e.json===!0?(process.stdout.write(`${JSON.stringify({bounds:a,tokenizer:o.tokenizer},null,2)}
383
+ `),0):(process.stdout.write(ve(a,o.tokenizer)),process.stdout.write(_t()),0);let f=jt(e.workload),g=Nt(o,f,e["whole-files"]===!0?{}:{root:r});return e.json===!0?(process.stdout.write(`${JSON.stringify({bounds:a,model:g,tokenizer:o.tokenizer},null,2)}
384
+ `),0):(process.stdout.write(ve(a,o.tokenizer)),process.stdout.write(Lt(g,o.tokenizer)),0)}catch(r){return r instanceof _||r instanceof B?(process.stderr.write(`
385
+ error: ${r.message}
385
386
 
386
387
  `),2):(process.stderr.write(`
387
- unexpected error: ${s.stack??String(s)}
388
+ unexpected error: ${r.stack??String(r)}
388
389
 
389
- `),2)}if(r!=="doctor")return process.stderr.write(`
390
- error: unknown command "${r}"
391
- ${V}`),2;if(!Pt(d))return process.stderr.write(`
392
- 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 \`${Ge(d)}\`.
390
+ `),2)}if(s!=="doctor")return process.stderr.write(`
391
+ error: unknown command "${s}"
392
+ ${Z}`),2;if(!yo(l))return process.stderr.write(`
393
+ error: run init first: doctor checks memory init has already looked at, and init has no record for this project and ${l} has not been compiled. Run \`${Le(l)}\`.
393
394
 
394
- `),2;let E;try{let s;if(o.policy!==void 0)try{s=Ke(o.policy)}catch(l){throw l instanceof Ye?new Error(`--policy: ${l.message}`):l}E={discover:D,budget:Qo(o.budget)??s?.budgets.always_on_tokens,budgetFromPolicy:o.budget===void 0&&s?.budgets.always_on_tokens!==void 0,policy:s,failOn:Ot(o["fail-on"],"high"),only:Ko(o.only),ignore:Ko(o.ignore),force:o.force===!0}}catch(s){return process.stderr.write(`
395
- error: ${s.message}
395
+ `),2;let M;try{let r;if(e.policy!==void 0)try{r=He(e.policy)}catch(o){throw o instanceof Ue?new Error(`--policy: ${o.message}`):o}M={discover:O,budget:Ht(e.budget)??r?.budgets.always_on_tokens,budgetFromPolicy:e.budget===void 0&&r?.budgets.always_on_tokens!==void 0,policy:r,failOn:ao(e["fail-on"],"high"),only:Bt(e.only),ignore:Bt(e.ignore),force:e.force===!0}}catch(r){return process.stderr.write(`
396
+ error: ${r.message}
396
397
 
397
- `),2}try{let s=fe(d,E);if(o.json)process.stdout.write(`${he(s,a)}
398
- `);else{let l=!o.ci&&!process.env.NO_COLOR&&process.stdout.isTTY===!0;process.stdout.write(me(s,{color:l,ci:o.ci===!0,target:a,diff:c}))}return Eo(s.audit.findings,s.config.failOn)}catch(s){return s instanceof G||s instanceof U?(process.stderr.write(`
399
- error: ${s.message}
398
+ `),2}try{let r=ye(l,M);if(e.json)process.stdout.write(`${we(r,u)}
399
+ `);else{let o=!e.ci&&!process.env.NO_COLOR&&process.stdout.isTTY===!0;process.stdout.write(ge(r,{color:o,ci:e.ci===!0,target:u,diff:T}))}return Pt(r.audit.findings,r.config.failOn)}catch(r){return r instanceof q||r instanceof X?(process.stderr.write(`
400
+ error: ${r.message}
400
401
 
401
402
  `),2):(process.stderr.write(`
402
- unexpected error: ${s.stack??String(s)}
403
+ unexpected error: ${r.stack??String(r)}
403
404
 
404
- `),2)}}function Ft(e){try{return S.realpathSync(e)}catch{return $.resolve(e)}}function Lt(){let e=process.argv[1];if(!e)return!1;try{return S.realpathSync(xt(import.meta.url))===S.realpathSync(e)}catch{return!1}}Lt()&&(process.exitCode=_t(process.argv.slice(2)));export{Ct as MCP_STASHED,Mt as defaultCommand,_t as main};
405
+ `),2)}}function vo(t){try{return w.realpathSync(t)}catch{return y.resolve(t)}}function $o(){let t=process.argv[1];if(!t)return!1;try{return w.realpathSync(ro(import.meta.url))===w.realpathSync(t)}catch{return!1}}$o()&&(process.exitCode=bo(process.argv.slice(2)));export{so as MCP_STASHED,uo as defaultCommand,bo as main};