const e={confirmIncrement:10,contradictDecrement:20,weeklyDecay:2,implicitUseIncrement:3,staleThreshold:30,staleDays:21,decayFloor:10,autoArchiveDays:30,archiveThreshold:20},t=`lesson:auto-archive`;function n(t){return{confirmIncrement:Math.max(0,Math.trunc(t?.confirmIncrement??e.confirmIncrement)),contradictDecrement:Math.max(0,Math.trunc(t?.contradictDecrement??e.contradictDecrement)),weeklyDecay:Math.max(0,Math.trunc(t?.weeklyDecay??e.weeklyDecay)),implicitUseIncrement:Math.max(0,Math.trunc(t?.implicitUseIncrement??e.implicitUseIncrement)),staleThreshold:Math.min(100,Math.max(0,Math.trunc(t?.staleThreshold??e.staleThreshold))),staleDays:Math.max(1,Math.trunc(t?.staleDays??e.staleDays)),decayFloor:Math.min(100,Math.max(0,Math.trunc(t?.decayFloor??e.decayFloor))),autoArchiveDays:Math.max(1,Math.trunc(t?.autoArchiveDays??e.autoArchiveDays)),archiveThreshold:Math.min(100,Math.max(0,Math.trunc(t?.archiveThreshold??e.archiveThreshold)))}}function r(e){return[`## Lesson: ${e.title}`,``,`**Confidence:** ${e.confidence}/100`,``,`### Context`,e.context,``,`### Insight`,e.insight,``,`### Evidence`,e.evidence].join(`
`)}function i(e){let t=e.match(/^## Lesson:\s+(.+)$/m),n=e.match(/\*\*Confidence:\*\*\s+(\d+)\/100/),r=e.match(/### Context\r?\n([\s\S]*?)(?=\r?\n### |$)/),i=e.match(/### Insight\r?\n([\s\S]*?)(?=\r?\n### |$)/),a=e.match(/### Evidence\r?\n([\s\S]*?)(?=\r?\n### |$)/);return{title:t?.[1]?.trim(),confidence:n?Number(n[1]):void 0,context:r?.[1]?.trim(),insight:i?.[1]?.trim(),evidence:a?.[1]?.trim()}}function a(e,t){let n=Math.min(100,Math.max(0,Math.trunc(t)));return/\*\*Confidence:\*\*/.test(e)?e.replace(/\*\*Confidence:\*\*\s+\d+\/100/,`**Confidence:** ${n}/100`):e.match(/^(## Lesson:[^\r\n]*)(\r?\n)/)?e.replace(/^(## Lesson:[^\r\n]*)(\r?\n)/,`$1$2$2**Confidence:** ${n}/100$2$2`):`**Confidence:** ${n}/100\n\n${e}`}function o(t,r,i=e){let a=n(i);return r===`confirm`?Math.min(100,t+a.confirmIncrement):Math.max(0,t-a.contradictDecrement)}function s(t,r,i,a=e,o=Date.now()){let s=n(a),c=!!r,l=r?new Date(r):new Date(i),u=Math.max(0,o-l.getTime());c||(u=Math.min(u,336*60*60*1e3));let d=u/(10080*60*1e3),f=Math.floor(d)*s.weeklyDecay;return Math.max(s.decayFloor,t-f)}function c(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.staleThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.staleDays}function l(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.archiveThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.autoArchiveDays}const u={threshold:.7,maxCompare:50,autoThreshold:.95};function d(e){let t=Math.min(1,Math.max(0,e?.threshold??u.threshold)),n=Math.min(1,Math.max(t,e?.autoThreshold??u.autoThreshold));return{threshold:t,maxCompare:Math.max(1,Math.trunc(e?.maxCompare??u.maxCompare)),autoThreshold:n}}function f(e){let t=e.toLowerCase().match(/[a-z0-9]{2,}/g)??[];return new Set(t)}function p(e,t){let n=f(e),r=f(t);if(n.size===0&&r.size===0)return 1;if(n.size===0||r.size===0)return 0;let i=new Set([...n].filter(e=>r.has(e))),a=new Set([...n,...r]);return i.size/a.size}function m(e,t,n=u){let r=d(n);return t.slice(0,r.maxCompare).map(t=>({entryId:t.id,title:t.title,similarity:p(e,t.content),path:t.path})).filter(e=>e.similarity>=r.threshold).sort((e,t)=>t.similarity-e.similarity)}function h(e,t,n){e.memoryMetaCreate(t),e.memoryMetaSetSuperseded(t,n)}export{d as a,o as c,c as d,i as f,l as h,h as i,s as l,a as m,m as n,e as o,n as p,p as r,t as s,u as t,r as u};