@cachly-dev/mcp-server 0.10.152 → 0.10.153
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/handlers/share.js +14 -14
- package/glama.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import{safeJsonParse as T}from"../utils.js";import{STARTER_CORPUS as k,STARTER_CORPUS_SIZE as x}from"../starter-corpus.js";import{cachlyUrl as j}from"../cachly-url.js";const E=new Set(["brain_share","brain_import","brain_share_list","brain_unshare","brain_discover","brain_seed_starter"]);async function R(v,w){const y=[],$=v.scanStream({match:"cachly:lesson:best:*",count:200});await new Promise((s,h)=>{$.on("data",e=>y.push(...e)),$.on("end",s),$.on("error",h)});const o=[];for(const s of y.slice(0,500)){const h=await v.get(s);if(!h)continue;const e=T(h,null);!e||!e.topic||w&&w.length>0&&!w.some(
|
|
1
|
+
import{safeJsonParse as T}from"../utils.js";import{STARTER_CORPUS as k,STARTER_CORPUS_SIZE as x}from"../starter-corpus.js";import{cachlyUrl as j}from"../cachly-url.js";const E=new Set(["brain_share","brain_import","brain_share_list","brain_unshare","brain_discover","brain_seed_starter"]);async function R(v,w){const y=[],$=v.scanStream({match:"cachly:lesson:best:*",count:200});await new Promise((s,h)=>{$.on("data",e=>y.push(...e)),$.on("end",s),$.on("error",h)});const o=[];for(const s of y.slice(0,500)){const h=await v.get(s);if(!h)continue;const e=T(h,null);!e||!e.topic||w&&w.length>0&&!w.some(a=>e.topic.includes(a))||o.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 o}async function A(v,w,y,$){switch(v){case"brain_share":{const{instance_id:o,title:s="My Brain Snapshot",description:h="",topic_filter:e,visibility:t="unlisted",max_lessons:a=100,dry_run:r=!1}=w;if(!o)return"\u26A0\uFE0F `brain_share` requires `instance_id`.";const l=await y(o),c=Array.isArray(e)&&e.length>0?e:void 0,i=(await R(l,c)).slice(0,a);if(i.length===0)return["\u{1F4E4} **brain_share** \u2014 nothing to share yet","",`No lessons found in Brain \`${o}\`${c?` matching topics: ${c.join(", ")}`:""}.`,"",'Store lessons first with `learn_from_attempts(topic="...", what_worked="...")`.'].join(`
|
|
2
2
|
`);if(r){const u=i.slice(0,5).map(p=>` ${p.outcome==="success"?"\u2705":p.outcome==="failure"?"\u274C":"\u26A0\uFE0F"} \`${p.topic}\` \u2014 ${(p.what_worked??p.what_failed??"").slice(0,80)}`);return[`\u{1F4E4} **brain_share (DRY RUN)** \u2014 would share ${i.length} lesson${i.length!==1?"s":""}`,"",`**Title:** ${s}`,`**Visibility:** ${t}`,c?`**Topic filter:** ${c.join(", ")}`:"","","**Sample lessons (first 5):**",...u,i.length>5?` _...and ${i.length-5} more_`:"","","_Remove `dry_run=true` to create the public share._"].filter(p=>p!=="").join(`
|
|
3
|
-
`)}let
|
|
3
|
+
`)}let n=null,d=null;try{n=(await $("/api/v1/brains/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:s,description:h,visibility:t,lessons:i})})).share_id??null,n&&(d=j(`/brain/share/${n}`,"brain-share"))}catch(u){const p=u.message??"";if(p.includes("404")||p.includes("not found")||p.includes("ECONNREFUSED")){const f=JSON.stringify({title:s,description:h,visibility:t,lessons:i,exported_at:new Date().toISOString()},null,2);return[`\u{1F4E4} **brain_share** \u2014 exported ${i.length} lesson${i.length!==1?"s":""}`,"","\u26A0\uFE0F The public share API is not yet available. Here is your portable snapshot:","","```json",f.slice(0,3e3)+(f.length>3e3?`
|
|
4
4
|
... (truncated)`:""),"```","","_To import this on another Brain, use `brain_import` with the JSON payload._"].join(`
|
|
5
|
-
`)}return`\u274C brain_share failed: ${u.message}`}const b=i.slice(0,5).map(u=>` ${u.outcome==="success"?"\u2705":u.outcome==="failure"?"\u274C":"\u26A0\uFE0F"} \`${u.topic}\``);try{const u=JSON.stringify({share_id:
|
|
6
|
-
`)}case"brain_import":{const{instance_id:o,share_id:s,topic_prefix:h="",min_confidence:e=0,dry_run:t=!1,overwrite:
|
|
7
|
-
`):`\u274C brain_import failed: ${m.message}`}const c=l.lessons??[];if(c.length===0)return`\u26A0\uFE0F Share \`${r}\` exists but contains no lessons.`;const _=await y(o);let i=0,
|
|
5
|
+
`)}return`\u274C brain_share failed: ${u.message}`}const b=i.slice(0,5).map(u=>` ${u.outcome==="success"?"\u2705":u.outcome==="failure"?"\u274C":"\u26A0\uFE0F"} \`${u.topic}\``);try{const u=JSON.stringify({share_id:n,title:s,visibility:t,lesson_count:i.length,created_at:new Date().toISOString()});await l.rpush("cachly:brain:shares",u),await l.ltrim("cachly:brain:shares",-20,-1)}catch{}return[`\u{1F4E4} **brain_share** \u2014 ${i.length} lesson${i.length!==1?"s":""} shared`,"",`**Share ID:** \`${n}\``,`**URL:** ${d}`,`**Title:** ${s}`,`**Visible:** ${t}`,"","**Sample lessons:**",...b,i.length>5?` _...and ${i.length-5} more_`:"","","**Anyone can import this Brain with:**",`\`brain_import(instance_id="<their-id>", share_id="${n}")\``,"","_To list all your shares, run `brain_share_list`._"].filter(u=>u!=="").join(`
|
|
6
|
+
`)}case"brain_import":{const{instance_id:o,share_id:s,topic_prefix:h="",min_confidence:e=0,dry_run:t=!1,overwrite:a=!1}=w;if(!o)return"\u26A0\uFE0F `brain_import` requires `instance_id`.";if(!s)return"\u26A0\uFE0F `brain_import` requires `share_id`. Get one from `brain_share`.";const r=s.replace(/^.*\/brain\/share\//,"").trim();let l;try{l=await $(`/api/v1/brains/share/${r}`)}catch(m){const g=m.message??"";return g.includes("404")||g.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: ${m.message}`}const c=l.lessons??[];if(c.length===0)return`\u26A0\uFE0F Share \`${r}\` exists but contains no lessons.`;const _=await y(o);let i=0,n=0,d=0;const b=[];for(const m of c){if((m.confidence??1)<e){n++;continue}const g=h?`${h}:${m.topic}`:m.topic,N=`cachly:lesson:best:${g}`;if(!a&&await _.get(N)){d++;continue}const O=JSON.stringify({...m,topic:g,imported_from:r,imported_at:new Date().toISOString()});if(!t){await _.set(N,O);const S=`cachly:lessons:${g}`;await _.rpush(S,O),await _.ltrim(S,-100,-1),await _.expire(S,90*86400)}if(i++,b.length<6){const S=m.outcome==="success"?"\u2705":m.outcome==="failure"?"\u274C":"\u26A0\uFE0F";b.push(` ${S} \`${g}\` \u2014 ${(m.what_worked??m.what_failed??"").slice(0,80)}`)}}if(!t&&i>0)try{const m=JSON.stringify({share_id:r,title:l.title,imported:i,skipped:n,conflicts:d,topic_prefix:h,imported_at:new Date().toISOString()});await _.rpush("cachly:brain:imports",m),await _.ltrim("cachly:brain:imports",-20,-1)}catch{}const u=t?" (DRY RUN \u2014 no writes)":"",p=l.title??r,f=[`\u{1F4E5} **brain_import${u}** \u2014 from "${p}"`,"",`**Share ID:** \`${r}\``,`**Lessons imported:** ${i}`,...n>0?[`**Skipped (low confidence):** ${n}`]:[],...d>0?[`**Skipped (already exist):** ${d} _(pass \`overwrite=true\` to replace)_`]:[],""];return b.length>0&&(f.push("**Sample lessons imported:**",...b),i>6&&f.push(` _...and ${i-6} more_`)),i>0&&!t?f.push("",'\u2705 Brain updated \u2014 use `smart_recall(query="...")` to query the new knowledge.'):t?f.push("","_Remove `dry_run=true` to actually import these lessons._"):i===0&&d>0&&f.push("","\u2139\uFE0F All lessons already exist in your Brain. Pass `overwrite=true` to update them."),f.join(`
|
|
8
8
|
`)}case"brain_share_list":{const{instance_id:o}=w;if(!o)return"\u26A0\uFE0F `brain_share_list` requires `instance_id`.";const s=await y(o);let h=[];try{h=(await s.lrange("cachly:brain:shares",0,-1)).map(c=>{try{return JSON.parse(c)}catch{return null}}).filter(Boolean)}catch{}let e=[];try{e=(await $("/api/v1/brains/share")).shares??[]}catch{}const t=e.length>0?e:h;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="${o}", title="My Patterns")\``].join(`
|
|
9
|
-
`);const
|
|
10
|
-
`)}case"brain_unshare":{const{instance_id:o,share_id:s}=w;if(!o)return"\u26A0\uFE0F `brain_unshare` requires `instance_id`.";if(!s)return"\u26A0\uFE0F `brain_unshare` requires `share_id`.";try{await $(`/api/v1/brains/share/${s}`,{method:"DELETE"})}catch(e){const t=e.message??"";if(t.includes("404")||t.includes("not found"))return`\u274C Share \`${s}\` not found \u2014 it may have already been removed.`;if(t.includes("ECONNREFUSED")||t.includes("fetch failed")){const
|
|
11
|
-
`)}return`\u274C brain_unshare failed: ${t}`}const h=await y(o);try{const t=(await h.lrange("cachly:brain:shares",0,-1)).filter(
|
|
12
|
-
`)}case"brain_discover":{const{query:o="",topic:s="",limit:h=10}=w;let e=[];try{const
|
|
9
|
+
`);const a=[`\u{1F4E4} **Your Brain Shares** (${t.length})`,"","| # | Title | Lessons | Visibility | Created |","|---|-------|---------|------------|---------|"];for(const[l,c]of t.entries()){const _=new Date(c.created_at),i=isNaN(_.getTime())?c.created_at:_.toISOString().slice(0,10),n=c.visibility==="public"?"\u{1F310} public":"\u{1F517} unlisted";a.push(`| ${l+1} | ${c.title??"\u2014"} | ${c.lesson_count??"?"} | ${n} | ${i} |`)}const r=t[t.length-1];return a.push("",`**Import command:** \`brain_import(instance_id="<their-id>", share_id="${r?.share_id??"..."}")\``,`**Revoke:** \`brain_unshare(instance_id="${o}", share_id="<id>")\``),a.join(`
|
|
10
|
+
`)}case"brain_unshare":{const{instance_id:o,share_id:s}=w;if(!o)return"\u26A0\uFE0F `brain_unshare` requires `instance_id`.";if(!s)return"\u26A0\uFE0F `brain_unshare` requires `share_id`.";try{await $(`/api/v1/brains/share/${s}`,{method:"DELETE"})}catch(e){const t=e.message??"";if(t.includes("404")||t.includes("not found"))return`\u274C Share \`${s}\` not found \u2014 it may have already been removed.`;if(t.includes("ECONNREFUSED")||t.includes("fetch failed")){const a=await y(o);try{const l=(await a.lrange("cachly:brain:shares",0,-1)).filter(c=>{try{return JSON.parse(c).share_id!==s}catch{return!0}});await a.del("cachly:brain:shares");for(const c of l)await a.rpush("cachly:brain:shares",c)}catch{}return["\u26A0\uFE0F **brain_unshare** \u2014 removed from local log","",`API unreachable \u2014 removed \`${s}\` from your local share registry.`,"The public link may still be accessible until the API confirms deletion."].join(`
|
|
11
|
+
`)}return`\u274C brain_unshare failed: ${t}`}const h=await y(o);try{const t=(await h.lrange("cachly:brain:shares",0,-1)).filter(a=>{try{return JSON.parse(a).share_id!==s}catch{return!0}});await h.del("cachly:brain:shares");for(const a of t)await h.rpush("cachly:brain:shares",a)}catch{}return["\u{1F5D1}\uFE0F **brain_unshare** \u2014 share revoked","",`Share \`${s}\` has been deleted. The public link is no longer accessible.`,"","_Anyone who already imported this Brain keeps their local copy._"].join(`
|
|
12
|
+
`)}case"brain_discover":{const{query:o="",topic:s="",limit:h=10}=w;let e=[];try{const a=new URLSearchParams;o&&a.set("q",o),s&&a.set("topic",s),a.set("limit",String(h)),e=await $(`/api/v1/brains/discover?${a.toString()}`)}catch(a){const r=a.message??"";return r.includes("404")||r.includes("ECONNREFUSED")||r.includes("fetch failed")?["\u{1F50D} **brain_discover** \u2014 marketplace not yet live","","The public Brain marketplace is coming soon.","","**In the meantime:**",' \u2022 Share your Brain: `brain_share(instance_id="...", visibility="public")`',' \u2022 Import by ID: `brain_import(instance_id="...", share_id="<id>")`',` \u2022 Community index: ${j("/brains","brain-discover")}`].join(`
|
|
13
13
|
`):`\u274C brain_discover failed: ${r}`}if(e.length===0)return[`\u{1F50D} **brain_discover** \u2014 no public Brains found ${o?`matching "${o}"`:s?`in topic "${s}"`:""}`.trim(),"",'Be the first! `brain_share(instance_id="...", visibility="public")`'].join(`
|
|
14
|
-
`);const t=[`\u{1F50D} **brain_discover**${o?` \u2014 "${o}"`:""}${s?` \xB7 topic: ${s}`:""} (${e.length} result${e.length!==1?"s":""})`,""];for(const[
|
|
15
|
-
`)}case"brain_seed_starter":{const{instance_id:o,topic_filter:s,dry_run:h=!1,force:e=!1}=w;if(!o)return"\u26A0\uFE0F `brain_seed_starter` requires `instance_id`.";const t=await y(o),
|
|
16
|
-
`);const r=Array.isArray(s)&&s.length>0?s:void 0,l=r?k.filter(
|
|
17
|
-
`);if(h){const
|
|
18
|
-
`)}const c=new Date().toISOString();let _=0,i=0;for(const
|
|
14
|
+
`);const t=[`\u{1F50D} **brain_discover**${o?` \u2014 "${o}"`:""}${s?` \xB7 topic: ${s}`:""} (${e.length} result${e.length!==1?"s":""})`,""];for(const[a,r]of e.entries()){const l=new Date(r.created_at),c=isNaN(l.getTime())?"":` \xB7 ${l.toISOString().slice(0,10)}`,_=r.imports!=null?` \xB7 ${r.imports} imports`:"",i=r.topics?.length?` \xB7 topics: ${r.topics.slice(0,4).join(", ")}`:"",n=r.author?` by **${r.author}**`:"";t.push(`**${a+1}. ${r.title}**${n}`,` \u{1F4DA} ${r.lesson_count} lessons${i}${_}${c}`,r.description?` _${r.description.slice(0,120)}_`:"",` \`brain_import(instance_id="...", share_id="${r.share_id}")\``,"")}return t.push(`_Browse more at ${j("/brains","brain-discover")}_`),t.filter(a=>a!==" ").join(`
|
|
15
|
+
`)}case"brain_seed_starter":{const{instance_id:o,topic_filter:s,dry_run:h=!1,force:e=!1}=w;if(!o)return"\u26A0\uFE0F `brain_seed_starter` requires `instance_id`.";const t=await y(o),a=await t.get(`cachly:brain:starter_seeded:${o}`);if(a&&!e&&!h)return["\u{1F331} **brain_seed_starter** \u2014 already seeded","",`This Brain was seeded with the starter corpus on ${a}.`,"","Pass `force=true` to re-seed (existing starter lessons will be refreshed)."].join(`
|
|
16
|
+
`);const r=Array.isArray(s)&&s.length>0?s:void 0,l=r?k.filter(n=>r.some(d=>n.topic.includes(d)||n.tags.some(b=>b.includes(d)))):k;if(l.length===0)return["\u{1F331} **brain_seed_starter** \u2014 no matching starter lessons","",`No starter lessons match filter: ${r?.join(", ")}.`,`Available topics: ${k.map(n=>`\`${n.topic}\``).join(", ")}`].join(`
|
|
17
|
+
`);if(h){const n=l.slice(0,8).map(d=>` \u2705 \`${d.topic}\` \u2014 ${d.what_worked.slice(0,70)}\u2026`);return[`\u{1F331} **brain_seed_starter (DRY RUN)** \u2014 would seed ${l.length} lesson${l.length!==1?"s":""}`,"",...n,l.length>8?` _...and ${l.length-8} more_`:"","","_Remove `dry_run=true` to seed these into the Brain._"].filter(d=>d!=="").join(`
|
|
18
|
+
`)}const c=new Date().toISOString();let _=0,i=0;for(const n of l){const d=`cachly:lesson:best:${n.topic}`;if(!e){const p=await t.get(d);if(p){const f=T(p,null);if(f&&f.source!=="starter"){i++;continue}}}const b=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:c,verified_at:c,version:3});await t.set(d,b),await t.sadd("cachly:vek:nachtrag",n.topic).catch(()=>{});const u=`cachly:lessons:${n.topic}`;await t.rpush(u,b),await t.ltrim(u,-100,-1),await t.expire(u,90*86400),_++}return await t.set(`cachly:stats:born_at:${o}`,c,"EX",365*86400,"NX").catch(()=>{}),await t.set(`cachly:brain:starter_seeded:${o}`,c,"EX",365*86400),["\u{1F331} **brain_seed_starter** \u2014 Brain seeded","",`**${_}** universal engineering lesson${_!==1?"s":""} added${i>0?` (${i} 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
19
|
`)}default:return null}}export{E as SHARE_TOOL_NAMES,x as STARTER_CORPUS_SIZE,A as handleShareTool};
|
package/glama.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cachly-dev/mcp-server",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.153",
|
|
4
4
|
"mcpName": "io.github.cachly-dev/mcp-server",
|
|
5
5
|
"description": "Your AI forgets everything between sessions. cachly fixes that permanently: 123 MCP tools for Claude Code, Cursor, Copilot & Windsurf. Learns from every bug fix, commit and CI run. Arrives pre-briefed. Free tier forever, EU servers, GDPR.",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/cachly-dev/cachly-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.10.
|
|
9
|
+
"version": "0.10.153",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"name": "@cachly-dev/mcp-server",
|
|
14
14
|
"identifier": "@cachly-dev/mcp-server",
|
|
15
|
-
"version": "0.10.
|
|
15
|
+
"version": "0.10.153",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|