@cachly-dev/mcp-server 0.10.213 → 0.10.215

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.
@@ -1,2 +1,2 @@
1
- const x="cachly:lesson:vec:",E="cachly:lesson:vecname:",v="cachly:lesson:vec2:",w="cachly:vek:nachtrag";function b(o){return o.replace(/[:_-]+/g," ").replace(/\s+/g," ").trim()}const f=1,c=7;function d(o){let e=0;for(const t of o){const n=Math.abs(t);n>e&&(e=n)}const i=e>0?e/127:1;let r=c+o.length;for(;r%4!==1;)r++;const s=Buffer.alloc(r);s.writeUInt8(f,0),s.writeUInt16LE(o.length,1),s.writeFloatLE(i,3);for(let t=0;t<o.length;t++){const n=Math.round(o[t]/i);s.writeInt8(n>127?127:n<-127?-127:n,c+t)}return s.toString("base64")}function k(o){try{const e=Buffer.from(o,"base64");if(e.byteLength===0)return null;if(e[0]===f&&e.byteLength%4===1&&e.byteLength>c){const r=e.readUInt16LE(1);if(r===0||c+r>e.byteLength)return null;const s=e.readFloatLE(3);if(!Number.isFinite(s))return null;const t=new Array(r);for(let n=0;n<r;n++)t[n]=e.readInt8(c+n)*s;return t}if(e.byteLength%4!==0)return null;const i=new Float32Array(e.buffer,e.byteOffset,e.byteLength/4);return Array.from(i)}catch{return null}}function u(o,e){if(o.length!==e.length)return-1;let i=0,r=0,s=0;for(let t=0;t<o.length;t++)i+=o[t]*e[t],r+=o[t]*o[t],s+=e[t]*e[t];return r&&s?i/Math.sqrt(r*s):0}function _(o){const e=i=>typeof i=="string"?i:"";return[e(o.topic),e(o.what_worked),e(o.what_failed)].filter(Boolean).join(`
2
- `).slice(0,2e3)}class T{frischeMs;praefix;vektoren=new Map;geladen=0;constructor(e=6e4,i=x){this.frischeMs=e,this.praefix=i}naehe(e,i){const r=this.vektoren.get(`${this.praefix}${i}`);return r?u(e,r):-2}rohvektor(e){return this.vektoren.get(`${this.praefix}${e}`)??null}get groesse(){return this.vektoren.size}hat(e){return this.vektoren.has(`${this.praefix}${e}`)}themen(){return[...this.vektoren.keys()].map(e=>e.slice(this.praefix.length))}async aktualisiere(e,i=Date.now()){if(this.vektoren.size>0&&i-this.geladen<this.frischeMs)return;const r=[];let s="0";do{const[n,a]=await e.scan(s,"MATCH",`${this.praefix}*`,"COUNT",500);s=n,r.push(...a)}while(s!=="0");const t=r.filter(n=>!this.vektoren.has(n));for(let n=0;n<t.length;n+=100){const a=t.slice(n,n+100),g=await e.mget(...a);for(const[p,h]of g.entries()){if(!h)continue;const l=k(h);l&&this.vektoren.set(a[p],l)}}if(r.length<this.vektoren.size){const n=new Set(r);for(const a of[...this.vektoren.keys()])n.has(a)||this.vektoren.delete(a)}this.geladen=i}aehnlichste(e,i){const r=[];for(const[s,t]of this.vektoren)r.push({topic:s.slice(this.praefix.length),naehe:u(e,t)});return r.sort((s,t)=>t.naehe-s.naehe),r.slice(0,i)}}const y=.1;function m(o,e,i=y,r=60){const s=new Map;return o.forEach((t,n)=>s.set(t,(s.get(t)??0)+i/(r+n+1))),e.forEach((t,n)=>s.set(t,(s.get(t)??0)+(1-i)/(r+n+1))),[...s.entries()].sort((t,n)=>n[1]-t[1]).map(([t])=>t)}export{E as NAME_VEKTOR_PRAEFIX,w as VEKTOR_NACHTRAG,x as VEKTOR_PRAEFIX,T as Vektorbestand,y as WORT_GEWICHT,v as ZWEIT_VEKTOR_PRAEFIX,k as entpacke,u as kosinus,m as mischeRangfolgen,d as packe,b as textFuerNamensVektor,_ as textFuerVektor};
1
+ const x="cachly:lesson:vec:",y="cachly:lesson:vecname:",v="cachly:lesson:vec2:",w="cachly:vek:nachtrag",T="cachly:vek:nachtrag:name",_="cachly:vek:nachtrag:zweit";function A(o){return o.replace(/[:_-]+/g," ").replace(/\s+/g," ").trim()}const f=1,c=7;function b(o){let e=0;for(const t of o){const n=Math.abs(t);n>e&&(e=n)}const i=e>0?e/127:1;let r=c+o.length;for(;r%4!==1;)r++;const s=Buffer.alloc(r);s.writeUInt8(f,0),s.writeUInt16LE(o.length,1),s.writeFloatLE(i,3);for(let t=0;t<o.length;t++){const n=Math.round(o[t]/i);s.writeInt8(n>127?127:n<-127?-127:n,c+t)}return s.toString("base64")}function k(o){try{const e=Buffer.from(o,"base64");if(e.byteLength===0)return null;if(e[0]===f&&e.byteLength%4===1&&e.byteLength>c){const r=e.readUInt16LE(1);if(r===0||c+r>e.byteLength)return null;const s=e.readFloatLE(3);if(!Number.isFinite(s))return null;const t=new Array(r);for(let n=0;n<r;n++)t[n]=e.readInt8(c+n)*s;return t}if(e.byteLength%4!==0)return null;const i=new Float32Array(e.buffer,e.byteOffset,e.byteLength/4);return Array.from(i)}catch{return null}}function u(o,e){if(o.length!==e.length)return-1;let i=0,r=0,s=0;for(let t=0;t<o.length;t++)i+=o[t]*e[t],r+=o[t]*o[t],s+=e[t]*e[t];return r&&s?i/Math.sqrt(r*s):0}function d(o){const e=i=>typeof i=="string"?i:"";return[e(o.topic),e(o.what_worked),e(o.what_failed)].filter(Boolean).join(`
2
+ `).slice(0,2e3)}class R{frischeMs;praefix;vektoren=new Map;geladen=0;constructor(e=6e4,i=x){this.frischeMs=e,this.praefix=i}naehe(e,i){const r=this.vektoren.get(`${this.praefix}${i}`);return r?u(e,r):-2}rohvektor(e){return this.vektoren.get(`${this.praefix}${e}`)??null}get groesse(){return this.vektoren.size}hat(e){return this.vektoren.has(`${this.praefix}${e}`)}themen(){return[...this.vektoren.keys()].map(e=>e.slice(this.praefix.length))}async aktualisiere(e,i=Date.now()){if(this.vektoren.size>0&&i-this.geladen<this.frischeMs)return;const r=[];let s="0";do{const[n,a]=await e.scan(s,"MATCH",`${this.praefix}*`,"COUNT",500);s=n,r.push(...a)}while(s!=="0");const t=r.filter(n=>!this.vektoren.has(n));for(let n=0;n<t.length;n+=100){const a=t.slice(n,n+100),g=await e.mget(...a);for(const[p,h]of g.entries()){if(!h)continue;const l=k(h);l&&this.vektoren.set(a[p],l)}}if(r.length<this.vektoren.size){const n=new Set(r);for(const a of[...this.vektoren.keys()])n.has(a)||this.vektoren.delete(a)}this.geladen=i}aehnlichste(e,i){const r=[];for(const[s,t]of this.vektoren)r.push({topic:s.slice(this.praefix.length),naehe:u(e,t)});return r.sort((s,t)=>t.naehe-s.naehe),r.slice(0,i)}}const E=.1;function m(o,e,i=E,r=60){const s=new Map;return o.forEach((t,n)=>s.set(t,(s.get(t)??0)+i/(r+n+1))),e.forEach((t,n)=>s.set(t,(s.get(t)??0)+(1-i)/(r+n+1))),[...s.entries()].sort((t,n)=>n[1]-t[1]).map(([t])=>t)}export{T as NAME_VEKTOR_NACHTRAG,y as NAME_VEKTOR_PRAEFIX,w as VEKTOR_NACHTRAG,x as VEKTOR_PRAEFIX,R as Vektorbestand,E as WORT_GEWICHT,_ as ZWEIT_VEKTOR_NACHTRAG,v as ZWEIT_VEKTOR_PRAEFIX,k as entpacke,u as kosinus,m as mischeRangfolgen,b as packe,A as textFuerNamensVektor,d as textFuerVektor};
@@ -2,7 +2,7 @@ import{ckgSlug as j}from"../ckg.js";import{safeJsonParse as x,darfHeraus as N}fr
2
2
  `)}case"brain_diff":{const{instance_id:l,since:g="7d",format:$="summary"}=S,m=await M(l);let w;const d=g.match(/^(\d+)([dhm])$/);if(d){const e=parseInt(d[1]),s=d[2],i=s==="d"?864e5:s==="h"?36e5:6e4;w=Date.now()-e*i}else w=new Date(g).getTime()||Date.now()-7*864e5;let u=0;const _=[];do{const[e,s]=await m.scan(u,"MATCH","cachly:lesson:best:*","COUNT",200);u=parseInt(e),_.push(...s)}while(u!==0);const c=[],y=[],f=[],k=_.length;for(const e of _){const s=await m.get(e);if(s){const i=x(s,null);if(!i)continue;if(new Date(i.ts).getTime()>=w){const T=`cachly:lesson:history:${i.topic}`;await m.llen(T)<=1?c.push(i):y.push(i)}(i.recall_count??0)>0&&f.push(i)}}const h=[`\u{1F4CA} **Brain Diff** \u2014 ${d?`last ${g}`:new Date(w).toLocaleDateString("de-DE")}`,"",`Total lessons in brain: **${k}**`,"",`\u2705 **New** (${c.length}):`,...c.slice(0,$==="detailed"?20:5).map(e=>` + \`${e.topic}\` \u2014 ${e.outcome} ${e.severity==="critical"?"\u{1F534}":e.severity==="major"?"\u{1F7E0}":"\u{1F7E2}"}`),c.length>5&&$==="summary"?` \u2026 and ${c.length-5} more`:"","",`\u{1F504} **Updated** (${y.length}):`,...y.slice(0,$==="detailed"?20:5).map(e=>` ~ \`${e.topic}\` \u2014 now: ${e.outcome}`),y.length>5&&$==="summary"?` \u2026 and ${y.length-5} more`:"","",`\u{1F50D} **Active** (recalled at least once): ${f.length}`,""].filter(e=>e!==""),v=[],t=m.scanStream({match:"cachly:ckg:node:resolution-*",count:100});await new Promise((e,s)=>{t.on("data",i=>v.push(...i)),t.on("end",e),t.on("error",s)});const o=[];for(const e of v){const s=await m.get(e);if(s){const i=x(s,null);i?.ts&&new Date(i.ts).getTime()>=w&&o.push({topic:i.topic??e,resolution:i.resolution??"unknown",ts:i.ts})}}if(o.length>0){h.push(`\u{1F5F3}\uFE0F **MADC Resolutions** (${o.length} contested beliefs resolved):`);for(const e of o.slice(0,5)){const s=e.resolution==="unanimous_success"?"\u2705":e.resolution==="unanimous_failure"?"\u274C":"\u26A0\uFE0F";h.push(` ${s} \`${e.topic}\` \u2192 ${e.resolution}`)}h.push("")}const a=new Set(y.concat(f).map(e=>e.topic.split(":")[0])),r=[...new Set(c.map(e=>e.topic.split(":")[0]))].filter(e=>!a.has(e));r.length>0&&h.push(`\u{1F331} **New domains bootstrapped:** ${r.map(e=>`\`${e}\``).join(", ")}`,"");const n=(await m.lrange("cachly:fedbrain:federations",-20,-1)).map(e=>x(e,null)).filter(e=>e!==null&&new Date(e.transferred_at).getTime()>=w);if(n.length>0){h.push(`\u{1F9E0} **FedBrain transfers received (${n.length}):**`);for(const e of n.slice(0,3))h.push(` \u{1F4E5} domain \`${e.domain}\` from \`${e.source.slice(0,16)}\u2026\` \u2014 ${e.nodes} nodes, ${e.edges} edges`);h.push("")}return h.push("\u{1F4A1} Run `memory_consolidate` to merge duplicates \xB7 `knowledge_decay` to see confidence scores."),h.join(`
3
3
  `)}case"causal_trace":{const{instance_id:l,problem:g,max_depth:$=5,tags:m=[]}=S,w=await W(l,L,`\u{1F50D} **Causal Trace: "${g}"**
4
4
 
5
- No matching lessons found in brain.`);if(w)return w;const d=await M(l),u=g.toLowerCase().replace(/[^a-z0-9\s\-_:]/g," ").split(/\s+/).filter(o=>o.length>2),_={critical:"\u{1F534}",major:"\u{1F7E0}",minor:"\u{1F7E1}"},c=[];try{for(const o of u.slice(0,4)){const a=await d.smembers(`cachly:ckg:idx:from:${j(o)}`),r=await d.smembers(`cachly:ckg:idx:to:${j(o)}`),p=[],n=d.scanStream({match:`cachly:ckg:node:*${o}*`,count:50});await new Promise((e,s)=>{n.on("data",i=>p.push(...i)),n.on("end",e),n.on("error",s)});for(const e of p.slice(0,10)){const s=await d.get(e);if(!s)continue;const i=x(s,null);if(!i)continue;const D=await d.smembers(`cachly:ckg:idx:from:${i.id}`);for(const T of D.slice(0,20)){const R=await d.get(T);if(!R)continue;const C=x(R,null);if(!C||C.edgeType!=="fixes"&&C.edgeType!=="requires")continue;const I=await d.get(`cachly:lesson:best:${C.from.replace(/-/g,":").replace(/^fix:/,"fix:")}`),E=I?x(I,null)??void 0:void 0;c.push({conceptId:i.id,edge:C,lesson:E&&B(E)?E:void 0})}}for(const e of[...a,...r].slice(0,20)){const s=await d.get(e);if(!s)continue;const i=x(s,null);if(!i)continue;const D=await d.get(`cachly:lesson:best:${i.from}`),T=D?x(D,null)??void 0:void 0;c.push({conceptId:i.from,edge:i,lesson:T&&B(T)?T:void 0})}}}catch{}const y=new Set,f=c.filter(o=>{const a=`${o.edge.from}:${o.edge.edgeType}:${o.edge.to}`;return y.has(a)?!1:(y.add(a),!0)}).sort((o,a)=>a.edge.confidence-o.edge.confidence).slice(0,$);let k=0;const b=[];do{const[o,a]=await d.scan(k,"MATCH","cachly:lesson:*","COUNT",200);k=parseInt(o),b.push(...a)}while(k!==0);const h=[];for(const o of b){const a=await d.get(o);if(a){const r=x(a,null);if(!r||!B(r)||m.length>0&&!(r.tags??[]).some(e=>m.includes(e)))continue;const p=[r.topic,r.what_failed??"",r.what_worked??"",r.context??""].join(" ").toLowerCase(),n=u.reduce((e,s)=>e+(p.includes(s)?1:0),0);n>0&&h.push({score:n,lesson:r,key:o})}}h.sort((o,a)=>a.score-o.score);const v=h.slice(0,$);if(v.length===0&&f.length===0)return[`\u{1F50D} **Causal Trace: "${g}"**`,"","No matching lessons found in brain.","","\u{1F4A1} After you solve this, call:","```","learn_from_attempts(",` instance_id = "${l}",`,` topic = "fix:${u[0]??"issue"}",`,' outcome = "success",',' what_worked = "...",',` what_failed = "${g}",`,")","```"].join(`
5
+ No matching lessons found in brain.`);if(w)return w;const d=await M(l),u=g.toLowerCase().replace(/[^a-z0-9\s\-_:]/g," ").split(/\s+/).filter(o=>o.length>2),_={critical:"\u{1F534}",major:"\u{1F7E0}",minor:"\u{1F7E1}"},c=[];try{for(const o of u.slice(0,4)){const a=await d.smembers(`cachly:ckg:idx:from:${j(o)}`),r=await d.smembers(`cachly:ckg:idx:to:${j(o)}`),p=[],n=d.scanStream({match:`cachly:ckg:node:*${o}*`,count:50});await new Promise((e,s)=>{n.on("data",i=>p.push(...i)),n.on("end",e),n.on("error",s)});for(const e of p.slice(0,10)){const s=await d.get(e);if(!s)continue;const i=x(s,null);if(!i)continue;const D=await d.smembers(`cachly:ckg:idx:from:${i.id}`);for(const T of D.slice(0,20)){const R=await d.get(T);if(!R)continue;const C=x(R,null);if(!C||C.edgeType!=="fixes"&&C.edgeType!=="requires")continue;const I=await d.get(`cachly:lesson:best:${C.from.replace(/-/g,":").replace(/^fix:/,"fix:")}`),E=I?x(I,null)??void 0:void 0;c.push({conceptId:i.id,edge:C,lesson:E&&B(E)?E:void 0})}}for(const e of[...a,...r].slice(0,20)){const s=await d.get(e);if(!s)continue;const i=x(s,null);if(!i)continue;const D=await d.get(`cachly:lesson:best:${i.from}`),T=D?x(D,null)??void 0:void 0;c.push({conceptId:i.from,edge:i,lesson:T&&B(T)?T:void 0})}}}catch{}const y=new Set,f=c.filter(o=>{const a=`${o.edge.from}:${o.edge.edgeType}:${o.edge.to}`;return y.has(a)?!1:(y.add(a),!0)}).sort((o,a)=>a.edge.confidence-o.edge.confidence).slice(0,$);let k=0;const b=[];do{const[o,a]=await d.scan(k,"MATCH","cachly:lesson:best:*","COUNT",200);k=parseInt(o),b.push(...a)}while(k!==0);const h=[];for(const o of b){const a=await d.get(o);if(a){const r=x(a,null);if(!r||!B(r)||m.length>0&&!(r.tags??[]).some(e=>m.includes(e)))continue;const p=[r.topic,r.what_failed??"",r.what_worked??"",r.context??""].join(" ").toLowerCase(),n=u.reduce((e,s)=>e+(p.includes(s)?1:0),0);n>0&&h.push({score:n,lesson:r,key:o})}}h.sort((o,a)=>a.score-o.score);const v=h.slice(0,$);if(v.length===0&&f.length===0)return[`\u{1F50D} **Causal Trace: "${g}"**`,"","No matching lessons found in brain.","","\u{1F4A1} After you solve this, call:","```","learn_from_attempts(",` instance_id = "${l}",`,` topic = "fix:${u[0]??"issue"}",`,' outcome = "success",',' what_worked = "...",',` what_failed = "${g}",`,")","```"].join(`
6
6
  `);const t=[`\u{1F50D} **Causal Trace: "${g}"**`,""];if(f.length>0){t.push("### \u{1F578}\uFE0F CKG Graph (confidence-ranked)");for(const o of f){const a=Math.round(o.edge.confidence*100),r="\u2593".repeat(Math.round(a/10))+"\u2591".repeat(10-Math.round(a/10));t.push(` ${o.edge.from} **\u2192[${o.edge.edgeType}]\u2192** ${o.edge.to}`),t.push(` ${r} ${a}% confidence (${o.edge.successes}/${o.edge.trials} confirmed)`),o.lesson?.what_worked&&t.push(` \u2705 Fix: ${o.lesson.what_worked.slice(0,150)}`),t.push("")}}if(v.length>0){t.push(f.length>0?`### \u{1F4DA} Text Search (${v.length} related lessons)`:`Found **${v.length}** related lessons. Reconstructed causal chain:`,"");const o=v.filter(p=>p.lesson.outcome!=="success"),a=v.filter(p=>p.lesson.outcome==="success");o.length>0&&(t.push("**Root causes & failure chain:**"),o.forEach((p,n)=>{const e=p.lesson,s=_[e.severity??"minor"]??"\u{1F7E1}";t.push(`${n===0?" Root:":" \u2192 :"} ${s} \`${e.topic}\``),e.what_failed&&t.push(` \u21B3 ${e.what_failed.slice(0,120)}`)}),t.push("")),a.length>0&&(t.push("**Solutions that worked before:**"),a.forEach((p,n)=>{const e=p.lesson,s=new Date(e.ts).toLocaleDateString("de-DE");t.push(` ${n+1}. \u2705 \`${e.topic}\` \u2014 ${s} \xB7 recalled ${e.recall_count??0}\xD7`),e.what_worked&&t.push(` ${e.what_worked.slice(0,200)}`)}),t.push(""));const r=a[0]?.lesson;if(r?.what_worked){t.push("**\u26A1 Most likely fix:**"),t.push("```"),t.push(r.what_worked.slice(0,500)),t.push("```"),t.push("");const p=F(r)?P(r,"trace"):0;p>0&&d.incrbyfloat(`cachly:stats:time_saved_mins:${l}`,p).catch(()=>{})}}return t.push(`\u{1F4A1} After applying: \`learn_from_attempts(topic="fix:${u[0]??"issue"}", outcome="success", ...)\``),f.length>0&&t.push(`\u{1F578}\uFE0F Explore graph: \`ckg_inspect(concept="${u[0]??"fix"}")\``),t.join(`
7
7
  `)}case"knowledge_decay":{let f=function(t){const o=Math.round(t/10);return"\u2588".repeat(o)+"\u2591".repeat(10-o)+` ${t}%`};const{instance_id:l,min_age_days:g=0,show_top:$=20}=S,m=await M(l),w=Date.now(),d=g*864e5;let u=0;const _=[];do{const[t,o]=await m.scan(u,"MATCH","cachly:lesson:best:*","COUNT",200);u=parseInt(t),_.push(...o)}while(u!==0);const c=[];for(const t of _){const o=await m.get(t);if(o){const a=x(o,null);if(!a)continue;const r=w-new Date(a.ts).getTime();if(r<d)continue;const p=Math.floor(r/864e5),n=a.recall_count??0,e=Math.max(0,p-7),s=Math.max(5,100-e),i=Math.min(50,n*5),D=a.outcome==="failure"?-20:0,T=Math.min(100,Math.max(0,s+i+D));c.push({topic:a.topic,confidence:T,age_days:p,recalls:n,outcome:a.outcome})}}c.sort((t,o)=>t.confidence-o.confidence);const y=c.slice(0,$),k=c.length>0?Math.round(c.reduce((t,o)=>t+o.confidence,0)/c.length):0,b=c.filter(t=>t.confidence<30).length,h=c.filter(t=>t.confidence>=70).length;return[`\u{1F9EA} **Knowledge Decay Report** \u2014 ${c.length} lessons`,"",`Average confidence: **${f(k)}**`,`\u{1F534} Critical (<30%): ${b} \u{1F7E2} Healthy (\u226570%): ${h}`,"","Lowest confidence lessons (fix these first):","",...y.map((t,o)=>`${(o+1).toString().padStart(2)}. \`${t.topic}\`
8
8
  ${f(t.confidence)} \xB7 ${t.age_days}d old \xB7 ${t.recalls} recalls \xB7 ${t.outcome}`),"",c.length>$?`\u2026 and ${c.length-$} more lessons`:"","",b>0?`\u26A0\uFE0F ${b} lessons are critically stale. Validate them and re-run \`learn_from_attempts\` with updated findings.`:"\u2705 Brain confidence is healthy overall.","","\u{1F4A1} Run `memory_consolidate` to prune stale entries \xB7 `causal_trace` to find root causes."].filter(t=>t!=="").join(`