@cachly-dev/mcp-server 0.10.245 → 0.10.247
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/dist/src/confidence.js +2 -2
- package/dist/src/handlers/brain.js +58 -57
- package/dist/src/handlers/share.js +4 -4
- package/dist/src/pruefung-melden.js +2 -2
- package/dist/src/search.js +1 -1
- package/dist/src/tools.js +2 -2
- package/glama.json +1 -1
- package/hooks/cachly-ambient-einblendung.mjs +24 -24
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{safeJsonParse as
|
|
1
|
+
import{safeJsonParse as D}from"../utils.js";import{STARTER_CORPUS as x,STARTER_CORPUS_SIZE as q}from"../starter-corpus.js";import{cachlyUrl as R}from"../cachly-url.js";import{VEKTOR_NACHTRAG as J}from"../bedeutung.js";import{schwaerze as P}from"../geheimnis-filter.js";import{fuerEigenenSpeicher as E,fuerWeitergabe as I,hinweise as U,istMarkiert as z,markiert as L,weitergabeHinweis as C,zaehlHinweise as K}from"../schreibtor.js";import{teamweitLesbar as M}from"./team.js";const F=new Set(["brain_share","brain_import","brain_share_list","brain_unshare","brain_discover","brain_seed_starter"]);async function Y(O,y){const g=[],$=O.scanStream({match:"cachly:lesson:best:*",count:200});await new Promise((a,u)=>{$.on("data",e=>g.push(...e)),$.on("end",a),$.on("error",u)});const i=[];for(const a of g.slice(0,500)){const u=await O.get(a);if(!u)continue;const e=M(u);!e||!e.topic||y&&y.length>0&&!y.some(s=>e.topic.includes(s))||i.push({topic:e.topic,outcome:e.outcome,...e.what_worked?{what_worked:e.what_worked}:{},...e.what_failed?{what_failed:e.what_failed}:{},...e.ctx?{ctx:e.ctx}:{},...e.tags?.length?{tags:e.tags}:{},...e.author?{author:e.author}:{},...e.service?{service:e.service}:{},confidence:e.confidence??1,ts:e.ts})}return i}async function ee(O,y,g,$){switch(O){case"brain_share":{const{instance_id:i,title:a="My Brain Snapshot",description:u="",topic_filter:e,visibility:t="unlisted",max_lessons:s=100,dry_run:r=!1}=y;if(!i)return"\u26A0\uFE0F `brain_share` requires `instance_id`.";const c=I({title:a,description:u},"the share");if(!c.ok)return c.meldung;const l=[...c.geschwaerzt],_=c.felder.title,f=c.felder.description,n=await g(i),p=Array.isArray(e)&&e.length>0?e:void 0,w=await Y(n,p),m=[],S=[];for(const o of w){if(S.length>=s)break;const d=P(o.topic).text;if(z(o)){m.push(`${d} (beim Speichern markiert)`);continue}const b=I(o,"the share");if(!b.ok){m.push(`${d} (${b.verdacht.join("; ")})`);continue}l.push(...b.geschwaerzt),S.push(b.felder)}const h=S,T=[C(l),m.length?`\u26D4 Tuersteher (security gate): ${m.length} lesson(s) NOT included in the share (instruction or dangerous command detected): ${m.slice(0,10).join(", ")}${m.length>10?", \u2026":""}. Check them and save them again one by one; the lessons in the Brain stay unchanged.`:""].filter(Boolean);if(h.length===0)return["\u{1F4E4} **brain_share** \u2014 nothing to share yet","",`No lessons found in Brain \`${i}\`${p?` matching topics: ${p.join(", ")}`:""}${m.length?" that can be shared":""}.`,"",'Store lessons first with `learn_from_attempts(topic="...", what_worked="...")`.',...T].join(`
|
|
2
2
|
`);if(r){const o=h.slice(0,5).map(d=>` ${d.outcome==="success"?"\u2705":d.outcome==="failure"?"\u274C":"\u26A0\uFE0F"} \`${d.topic}\` \u2014 ${(d.what_worked??d.what_failed??"").slice(0,80)}`);return[`\u{1F4E4} **brain_share (DRY RUN)** \u2014 would share ${h.length} lesson${h.length!==1?"s":""}`,"",`**Title:** ${_}`,`**Visibility:** ${t}`,p?`**Topic filter:** ${p.join(", ")}`:"","","**Sample lessons (first 5):**",...o,h.length>5?` _...and ${h.length-5} more_`:"","",...T,"_Remove `dry_run=true` to create the public share._"].filter(d=>d!=="").join(`
|
|
3
3
|
`)}let j=null,v=null;try{j=(await $("/api/v1/brains/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:_,description:f,visibility:t,lessons:h})})).share_id??null,j&&(v=R(`/brain/share/${j}`,"brain-share"))}catch(o){const d=o.message??"";if(d.includes("404")||d.includes("not found")||d.includes("ECONNREFUSED")){const b=JSON.stringify({title:_,description:f,visibility:t,lessons:h,exported_at:new Date().toISOString()},null,2);return[`\u{1F4E4} **brain_share** \u2014 exported ${h.length} lesson${h.length!==1?"s":""}`,"","\u26A0\uFE0F The public share API is not yet available. Here is your portable snapshot:","","```json",b.slice(0,3e3)+(b.length>3e3?`
|
|
4
4
|
... (truncated)`:""),"```","","_To import this on another Brain, use `brain_import` with the JSON payload._",...T].join(`
|
|
5
5
|
`)}return`\u274C brain_share failed: ${o.message}`}const k=h.slice(0,5).map(o=>` ${o.outcome==="success"?"\u2705":o.outcome==="failure"?"\u274C":"\u26A0\uFE0F"} \`${o.topic}\``);try{const o=JSON.stringify({share_id:j,title:_,visibility:t,lesson_count:h.length,created_at:new Date().toISOString()});await n.rpush("cachly:brain:shares",o),await n.ltrim("cachly:brain:shares",-20,-1)}catch{}return[`\u{1F4E4} **brain_share** \u2014 ${h.length} lesson${h.length!==1?"s":""} shared`,"",`**Share ID:** \`${j}\``,`**URL:** ${v}`,`**Title:** ${_}`,`**Visible:** ${t}`,"","**Sample lessons:**",...k,h.length>5?` _...and ${h.length-5} more_`:"","","**Anyone can import this Brain with:**",`\`brain_import(instance_id="<their-id>", share_id="${j}")\``,"","_To list all your shares, run `brain_share_list`._",...T.length?["",...T]:[]].filter(o=>o!=="").join(`
|
|
6
6
|
`)}case"brain_import":{const{instance_id:i,share_id:a,topic_prefix:u="",min_confidence:e=0,dry_run:t=!1,overwrite:s=!1}=y;if(!i)return"\u26A0\uFE0F `brain_import` requires `instance_id`.";if(!a)return"\u26A0\uFE0F `brain_import` requires `share_id`. Get one from `brain_share`.";const r=a.replace(/^.*\/brain\/share\//,"").trim();let c;try{c=await $(`/api/v1/brains/share/${r}`)}catch(k){const o=k.message??"";return o.includes("404")||o.includes("not found")?["\u274C **brain_import** \u2014 share not found","",`Share ID \`${r}\` does not exist or has been removed.`,"","Ask the Brain owner to re-run `brain_share` and share the new ID with you."].join(`
|
|
7
|
-
`):`\u274C brain_import failed: ${k.message}`}const l=c.lessons??[];if(l.length===0)return`\u26A0\uFE0F Share \`${r}\` exists but contains no lessons.`;const _=await g(i);let f=0,n=0,p=0;const w=[];let m=0,S=0;const h=
|
|
7
|
+
`):`\u274C brain_import failed: ${k.message}`}const l=c.lessons??[];if(l.length===0)return`\u26A0\uFE0F Share \`${r}\` exists but contains no lessons.`;const _=await g(i);let f=0,n=0,p=0;const w=[];let m=0,S=0;const h=E({title:c.title??""}),T=h.felder.title||r;for(const k of l){if((k.confidence??1)<e){n++;continue}const o=E(k);o.geschwaerzt.length&&m++,o.verdacht.length&&S++;const d=o.verdacht.length?{...o.felder,tags:L(o.felder.tags,o.verdacht)}:o.felder,b=u?`${u}:${d.topic}`:d.topic,B=`cachly:lesson:best:${b}`;if(!s&&await _.get(B)){p++;continue}const A=JSON.stringify({...d,topic:b,imported_from:r,imported_at:new Date().toISOString()});if(!t){await _.set(B,A);const N=`cachly:lessons:${b}`;await _.rpush(N,A),await _.ltrim(N,-100,-1),await _.expire(N,90*86400)}if(f++,w.length<6){const N=d.outcome==="success"?"\u2705":d.outcome==="failure"?"\u274C":"\u26A0\uFE0F";w.push(` ${N} \`${b}\` \u2014 ${(d.what_worked??d.what_failed??"").slice(0,80)}`)}}if(!t&&f>0)try{const k=JSON.stringify({share_id:r,title:h.felder.title||void 0,...h.verdacht.length?{verdacht:h.verdacht}:{},imported:f,skipped:n,conflicts:p,topic_prefix:u,imported_at:new Date().toISOString()});await _.rpush("cachly:brain:imports",k),await _.ltrim("cachly:brain:imports",-20,-1)}catch{}const v=[`\u{1F4E5} **brain_import${t?" (DRY RUN \u2014 no writes)":""}** \u2014 from "${T}"`,"",`**Share ID:** \`${r}\``,`**Lessons imported:** ${f}`,...n>0?[`**Skipped (low confidence):** ${n}`]:[],...p>0?[`**Skipped (already exist):** ${p} _(pass \`overwrite=true\` to replace)_`]:[],...K(m,S,`${l.length} entries`),...U(h,"notiz"),""];return w.length>0&&(v.push("**Sample lessons imported:**",...w),f>6&&v.push(` _...and ${f-6} more_`)),f>0&&!t?v.push("",'\u2705 Brain updated \u2014 use `smart_recall(query="...")` to query the new knowledge.'):t?v.push("","_Remove `dry_run=true` to actually import these lessons._"):f===0&&p>0&&v.push("","\u2139\uFE0F All lessons already exist in your Brain. Pass `overwrite=true` to update them."),v.join(`
|
|
8
8
|
`)}case"brain_share_list":{const{instance_id:i}=y;if(!i)return"\u26A0\uFE0F `brain_share_list` requires `instance_id`.";const a=await g(i);let u=[];try{u=(await a.lrange("cachly:brain:shares",0,-1)).map(l=>{try{return JSON.parse(l)}catch{return null}}).filter(Boolean)}catch{}let e=[];try{e=(await $("/api/v1/brains/share")).shares??[]}catch{}const t=e.length>0?e:u;if(t.length===0)return["\u{1F4E4} **brain_share_list** \u2014 no shares yet","","You haven't shared any Brain snapshots from this instance.","",`Create one with: \`brain_share(instance_id="${i}", title="My Patterns")\``].join(`
|
|
9
9
|
`);const s=[`\u{1F4E4} **Your Brain Shares** (${t.length})`,"","| # | Title | Lessons | Visibility | Created |","|---|-------|---------|------------|---------|"];for(const[c,l]of t.entries()){const _=new Date(l.created_at),f=isNaN(_.getTime())?l.created_at:_.toISOString().slice(0,10),n=l.visibility==="public"?"\u{1F310} public":"\u{1F517} unlisted";s.push(`| ${c+1} | ${l.title??"\u2014"} | ${l.lesson_count??"?"} | ${n} | ${f} |`)}const r=t[t.length-1];return s.push("",`**Import command:** \`brain_import(instance_id="<their-id>", share_id="${r?.share_id??"..."}")\``,`**Revoke:** \`brain_unshare(instance_id="${i}", share_id="<id>")\``),s.join(`
|
|
10
10
|
`)}case"brain_unshare":{const{instance_id:i,share_id:a}=y;if(!i)return"\u26A0\uFE0F `brain_unshare` requires `instance_id`.";if(!a)return"\u26A0\uFE0F `brain_unshare` requires `share_id`.";try{await $(`/api/v1/brains/share/${a}`,{method:"DELETE"})}catch(e){const t=e.message??"";if(t.includes("404")||t.includes("not found"))return`\u274C Share \`${a}\` not found \u2014 it may have already been removed.`;if(t.includes("ECONNREFUSED")||t.includes("fetch failed")){const s=await g(i);try{const c=(await s.lrange("cachly:brain:shares",0,-1)).filter(l=>{try{return JSON.parse(l).share_id!==a}catch{return!0}});await s.del("cachly:brain:shares");for(const l of c)await s.rpush("cachly:brain:shares",l)}catch{}return["\u26A0\uFE0F **brain_unshare** \u2014 removed from local log","",`API unreachable \u2014 removed \`${a}\` from your local share registry.`,"The public link may still be accessible until the API confirms deletion."].join(`
|
|
@@ -15,5 +15,5 @@ import{safeJsonParse as E}from"../utils.js";import{STARTER_CORPUS as x,STARTER_C
|
|
|
15
15
|
`)}case"brain_seed_starter":{const{instance_id:i,topic_filter:a,dry_run:u=!1,force:e=!1}=y;if(!i)return"\u26A0\uFE0F `brain_seed_starter` requires `instance_id`.";const t=await g(i),s=await t.get(`cachly:brain:starter_seeded:${i}`);if(s&&!e&&!u)return["\u{1F331} **brain_seed_starter** \u2014 already seeded","",`This Brain was seeded with the starter corpus on ${s}.`,"","Pass `force=true` to re-seed (existing starter lessons will be refreshed)."].join(`
|
|
16
16
|
`);const r=Array.isArray(a)&&a.length>0?a:void 0,c=r?x.filter(n=>r.some(p=>n.topic.includes(p)||n.tags.some(w=>w.includes(p)))):x;if(c.length===0)return["\u{1F331} **brain_seed_starter** \u2014 no matching starter lessons","",`No starter lessons match filter: ${r?.join(", ")}.`,`Available topics: ${x.map(n=>`\`${n.topic}\``).join(", ")}`].join(`
|
|
17
17
|
`);if(u){const n=c.slice(0,8).map(p=>` \u2705 \`${p.topic}\` \u2014 ${p.what_worked.slice(0,70)}\u2026`);return[`\u{1F331} **brain_seed_starter (DRY RUN)** \u2014 would seed ${c.length} lesson${c.length!==1?"s":""}`,"",...n,c.length>8?` _...and ${c.length-8} more_`:"","","_Remove `dry_run=true` to seed these into the Brain._"].filter(p=>p!=="").join(`
|
|
18
|
-
`)}const l=new Date().toISOString();let _=0,f=0;for(const n of c){const p=`cachly:lesson:best:${n.topic}`;if(!e){const S=await t.get(p);if(S){const h=
|
|
19
|
-
`)}default:return null}}export{
|
|
18
|
+
`)}const l=new Date().toISOString();let _=0,f=0;for(const n of c){const p=`cachly:lesson:best:${n.topic}`;if(!e){const S=await t.get(p);if(S){const h=D(S,null);if(h&&h.source!=="starter"){f++;continue}}}const w=JSON.stringify({topic:n.topic,outcome:n.outcome,what_worked:n.what_worked,what_failed:n.what_failed,ctx:n.ctx,tags:n.tags,confidence:n.confidence,recall_count:0,source:"starter",ts:l,verified_at:l,version:3});await t.set(p,w),await t.sadd(J,n.topic).catch(()=>{});const m=`cachly:lessons:${n.topic}`;await t.rpush(m,w),await t.ltrim(m,-100,-1),await t.expire(m,90*86400),_++}return await t.set(`cachly:stats:born_at:${i}`,l,"EX",365*86400,"NX").catch(()=>{}),await t.set(`cachly:brain:starter_seeded:${i}`,l,"EX",365*86400),["\u{1F331} **brain_seed_starter** \u2014 Brain seeded","",`**${_}** universal engineering lesson${_!==1?"s":""} added${f>0?` (${f} skipped \u2014 your own lessons take priority)`:""}.`,"","Your Brain now answers common questions out of the box:",' \u2022 `smart_recall(query="docker build slow")`',' \u2022 `smart_recall(query="pod OOMKilled")`',' \u2022 `smart_recall(query="jwt token rejected")`',"",'_Starter lessons are tagged `source: "starter"` and never override your own._',"_They're replaced as you learn project-specific lessons on the same topics._"].join(`
|
|
19
|
+
`)}default:return null}}export{F as SHARE_TOOL_NAMES,q as STARTER_CORPUS_SIZE,ee as handleShareTool};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
`))return{ok:!1,grund:"`geprueft_mit` muss EIN Befehl in einer Zeile sein."};const i=
|
|
1
|
+
const a=200,d=400;function g(n){return typeof n=="string"?n.trim():""}function h(n,u){const e=g(n.topic);if(!e)return{ok:!1,grund:"`topic` fehlt \u2014 welche Lektion wurde geprueft?"};if(typeof n.haelt!="boolean")return{ok:!1,grund:"`haelt` muss true oder false sein. Ohne diese Angabe waere die Meldung eine Vermutung: einmal geraten macht sie die Lektion frisch, andersherum markiert sie eine richtige Lektion als gefallen."};const t=n.haelt,f=g(n.geprueft_mit);if(f.length>200)return{ok:!1,grund:`\`geprueft_mit\` ist ${f.length} Zeichen lang, erlaubt sind 200. Der Befehl wird im Abruf angezeigt und hat dort ein Budget.`};if(f.includes(`
|
|
2
|
+
`))return{ok:!1,grund:"`geprueft_mit` muss EIN Befehl in einer Zeile sein."};const i=g(n.befund);if(i.length>400)return{ok:!1,grund:`\`befund\` ist ${i.length} Zeichen lang, erlaubt sind 400. Eine Zeile Klartext, kein Protokoll.`};if(!t&&!i)return{ok:!1,grund:"Ein Fehlschlag braucht `befund`: was hast du stattdessen gesehen? Eine Warnung ohne Inhalt ist Laerm, und die naechste Sitzung kann nichts damit anfangen."};const r=n.ursache;let l;if(r!=null&&r!==""){if(r!=="aussage"&&r!=="umgebung")return{ok:!1,grund:'`ursache` ist "aussage" (die Pruefung lief, die Behauptung haelt nicht) oder "umgebung" (die Pruefung kam nicht bis zur Behauptung: Zeitgrenze, Dienst aus, Lockfile hinkt).'};t||(l=r)}const s={topic:e,haelt:t,ts:u};return f&&(s.geprueft_mit=f),i&&(s.befund=i),l&&(s.ursache=l),{ok:!0,eintrag:s}}function o(n,u){const e={...n};u.haelt?(e.verified_at=u.ts,e.confidence=1,delete e.pruefung_gefallen_am,delete e.pruefung_befund,delete e.pruefung_umgebung_am,delete e.pruefung_umgebung_befund):u.ursache==="umgebung"?(e.pruefung_umgebung_am=u.ts,e.pruefung_umgebung_befund=u.befund):(e.pruefung_gefallen_am=u.ts,e.pruefung_befund=u.befund,delete e.pruefung_umgebung_am,delete e.pruefung_umgebung_befund);const t=Array.isArray(e.pruefspur)?[...e.pruefspur]:[];return t.push(u),e.pruefspur=t.slice(-20),e}export{a as BEFEHL_GRENZE,d as BEFUND_GRENZE,h as pruefeMeldung,o as wendeAn};
|