@cachly-dev/mcp-server 0.10.193 → 0.10.195

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 +1 @@
1
- import{closeSync as w,existsSync as x,mkdirSync as y,openSync as _,readFileSync as M,renameSync as I,statSync as R,unlinkSync as z,writeFileSync as K,writeSync as F}from"node:fs";import{dirname as f,join as c}from"node:path";import{credentialsPath as j,readInstanceId as L,readSavedApiKey as b,saveApiKey as O,saveInstanceId as $}from"./credentials.js";import{holeSofortTest as D,SOFORT_TEST_FRIST_MS as U}from"./sofort-test.js";const A=15e3,H=100,Q=600*1e3,N=1440*60*1e3,T="anlegen.lock",G="anlegen.fehler",h="startwissen-auftrag.json";function Z(e=process.env){return!/^(0|false|off|no|nein)$/i.test((e.CACHLY_STARTWISSEN??"").trim())}function o(e){return f(j(e))}const P=e=>new Promise(n=>setTimeout(n,e));function k(e){return{apiKey:b(e),instanzId:L(e)}}function C(e,n){try{y(f(e),{recursive:!0})}catch{return"kein-zugriff"}try{const t=_(e,"wx",384);try{F(t,`${process.pid} ${n}`)}finally{w(t)}return"ja"}catch(t){return t?.code==="EEXIST"?"belegt":"kein-zugriff"}}function g(e,n){try{return n-R(e).mtimeMs}catch{return null}}function p(e){try{z(e)}catch{}}function J(e,n=Date.now()){const t=g(c(o(e),T),n);return t!==null&&t<A}function V(e,n,t){if(n<=0)return!1;const r=g(e,t);return r!==null&&r>=0&&r<n}function W(e){try{y(f(e),{recursive:!0}),K(e,String(Date.now()),{mode:384})}catch{}}async function ee(e){const n=e.jetzt??Date.now,t=e.schlafen??P,r=n()+e.fristMs,i=o(e),s=c(i,T),l=c(i,G);try{for(;;){const a=k(e);if(a.apiKey&&(a.instanzId||!J(e,n())))return{art:"vorhanden",apiKey:a.apiKey,instanzId:a.instanzId};if(!a.apiKey){const m=C(s,n());if(m==="kein-zugriff")return{art:"gescheitert",grund:"kein-schreibzugriff"};if(m==="ja")try{const d=k(e);if(d.apiKey)return{art:"vorhanden",apiKey:d.apiKey,instanzId:d.instanzId};if(V(l,e.abkuehlungMs??0,n()))return{art:"gescheitert",grund:"abgekuehlt"};const E=Math.max(500,r-n()),u=await D({apiUrl:e.apiUrl,version:e.version,holen:e.holen,env:e.env,fristMs:Math.min(E,e.anfrageMs??U),speichern:v=>O(v,e)});return u?($(u.instanzId,{...e,apiKey:u.apiKey}),p(l),{art:"angelegt",test:u}):(W(l),{art:"gescheitert",grund:"kein-test"})}finally{p(s)}const S=g(s,n());S!==null&&S>=A&&p(s)}if(n()>=r)return a.apiKey?{art:"vorhanden",apiKey:a.apiKey,instanzId:a.instanzId}:{art:"gescheitert",grund:"sperre-belegt"};await t(H)}}catch{return{art:"gescheitert",grund:"kein-test"}}}function ne(e,n={}){try{const t=c(o(n),h);y(f(t),{recursive:!0});const r=`${t}.${process.pid}.tmp`;K(r,JSON.stringify({...e,am:new Date().toISOString()}),{mode:384}),I(r,t)}catch{}}function te(e={}){return x(c(o(e),h))}function re(e={},n=Date.now()){const t=c(o(e),h),r=`${t}.${process.pid}.genommen`;try{I(t,r)}catch{return null}try{const i=JSON.parse(M(r,"utf8")),s=Date.parse(String(i?.am??""));return!i||typeof i.instanzId!="string"||!i.instanzId||!Number.isFinite(s)||n-s>N?null:{instanzId:i.instanzId,projekt:typeof i.projekt=="string"?i.projekt:"",am:String(i.am)}}catch{return null}finally{try{z(r)}catch{}}}export{Q as ABKUEHLUNG_HOOK_MS,N as AUFTRAG_VERFAELLT_MS,A as SPERRE_VERALTET_MS,H as WARTE_TAKT_MS,te as auftragLiegt,re as nimmAuftrag,ne as schreibeAuftrag,ee as sichereKonto,J as sperreLiegt,Z as startwissenEingeschaltet};
1
+ import{closeSync as _,existsSync as b,mkdirSync as m,openSync as w,readFileSync as I,renameSync as k,statSync as F,unlinkSync as K,writeFileSync as v,writeSync as M}from"node:fs";import{dirname as l,join as o}from"node:path";import{credentialsPath as R,readInstanceId as L,readSavedApiKey as N,saveApiKey as j,saveInstanceId as H}from"./credentials.js";import{holeSofortTest as O,SOFORT_TEST_FRIST_MS as $}from"./sofort-test.js";const z=15e3,U=100,Z=600*1e3,D=1440*60*1e3,A="anlegen.lock",G="anlegen.fehler",y="startwissen-auftrag.json";function ee(e=process.env){return!/^(0|false|off|no|nein)$/i.test((e.CACHLY_STARTWISSEN??"").trim())}function u(e){return l(R(e))}const P=e=>new Promise(t=>setTimeout(t,e));function T(e){return{apiKey:N(e),instanzId:L(e)}}function C(e,t){try{m(l(e),{recursive:!0})}catch{return"kein-zugriff"}try{const n=w(e,"wx",384);try{M(n,`${process.pid} ${t}`)}finally{_(n)}return"ja"}catch(n){return n?.code==="EEXIST"?"belegt":"kein-zugriff"}}function h(e,t){try{return t-F(e).mtimeMs}catch{return null}}function g(e){try{K(e)}catch{}}function J(e,t=Date.now()){const n=h(o(u(e),A),t);return n!==null&&n<z}function V(e,t,n){if(t<=0)return!1;let i=null;try{const a=Number(I(e,"utf8").trim());Number.isFinite(a)&&a>0&&(i=a)}catch{}const r=i!==null?n-i:h(e,n);return r!==null&&r>=0&&r<t}function W(e,t){try{m(l(e),{recursive:!0}),v(e,String(t),{mode:384})}catch{}}async function te(e){const t=e.jetzt??Date.now,n=e.schlafen??P,i=t()+e.fristMs,r=u(e),a=o(r,A),c=o(r,G);try{for(;;){const s=T(e);if(s.apiKey&&(s.instanzId||!J(e,t())))return{art:"vorhanden",apiKey:s.apiKey,instanzId:s.instanzId};if(!s.apiKey){const p=C(a,t());if(p==="kein-zugriff")return{art:"gescheitert",grund:"kein-schreibzugriff"};if(p==="ja")try{const d=T(e);if(d.apiKey)return{art:"vorhanden",apiKey:d.apiKey,instanzId:d.instanzId};if(V(c,e.abkuehlungMs??0,t()))return{art:"gescheitert",grund:"abgekuehlt"};const E=Math.max(500,i-t()),f=await O({apiUrl:e.apiUrl,version:e.version,holen:e.holen,env:e.env,fristMs:Math.min(E,e.anfrageMs??$),speichern:x=>j(x,e)});return f?(H(f.instanzId,{...e,apiKey:f.apiKey}),g(c),{art:"angelegt",test:f}):(W(c,t()),{art:"gescheitert",grund:"kein-test"})}finally{g(a)}const S=h(a,t());S!==null&&S>=z&&g(a)}if(t()>=i)return s.apiKey?{art:"vorhanden",apiKey:s.apiKey,instanzId:s.instanzId}:{art:"gescheitert",grund:"sperre-belegt"};await n(U)}}catch{return{art:"gescheitert",grund:"kein-test"}}}function B(e){const t=e;if(!t||t.art!=="git"&&t.art!=="startvorrat")return;const n=Number(t.lektionen);return Number.isInteger(n)&&n>0?{art:t.art,lektionen:n}:void 0}function ne(e,t={}){try{const n=o(u(t),y);m(l(n),{recursive:!0});const i=`${n}.${process.pid}.tmp`;v(i,JSON.stringify({...e,am:new Date().toISOString()}),{mode:384}),k(i,n)}catch{}}function re(e={}){return b(o(u(e),y))}function ie(e={},t=Date.now()){const n=o(u(e),y),i=`${n}.${process.pid}.genommen`;try{k(n,i)}catch{return null}try{const r=JSON.parse(I(i,"utf8")),a=Date.parse(String(r?.am??""));if(!r||typeof r.instanzId!="string"||!r.instanzId||!Number.isFinite(a)||t-a>D)return null;const c=B(r.vomHook);return{instanzId:r.instanzId,projekt:typeof r.projekt=="string"?r.projekt:"",am:String(r.am),...c?{vomHook:c}:{}}}catch{return null}finally{try{K(i)}catch{}}}export{Z as ABKUEHLUNG_HOOK_MS,D as AUFTRAG_VERFAELLT_MS,z as SPERRE_VERALTET_MS,U as WARTE_TAKT_MS,re as auftragLiegt,ie as nimmAuftrag,ne as schreibeAuftrag,te as sichereKonto,J as sperreLiegt,ee as startwissenEingeschaltet};
@@ -0,0 +1 @@
1
+ import{resolve as u}from"node:path";import{STARTER_CORPUS as p}from"./starter-corpus.js";import{gitLesen as d}from"./git-ohne-shell.js";import{gitLogArgumente as w,leseCommits as _,lektionenJeThema as S}from"./git-lektionen.js";import{STARTWISSEN_COMMITS as A,ausschlussGrund as y,echteGitWurzel as T,startvorratErlaubt as E}from"./startwissen.js";import{startwissenEingeschaltet as k}from"./konto-anlegen.js";import{holeBestand as x}from"./einblendung.js";const O="startwissen-import",R=9e4,h=1e3,v=3,g=8e3,m=3,l=t=>new Promise(e=>setTimeout(e,t));function b(t){return S(t).map(e=>({topic:e.topic,outcome:e.outcome,what_worked:e.what_worked,what_failed:e.what_failed,context:e.context,severity:e.severity,tags:e.tags,commands:e.commands,file_paths:e.file_paths,source:"brain_from_git",...e.author?{author:e.author}:{}}))}function I(){return p.map(t=>({topic:t.topic,outcome:t.outcome,what_worked:t.what_worked,what_failed:t.what_failed,context:t.ctx,tags:t.tags,commands:[],file_paths:[],source:"starter"}))}function L(t){return d(t,w("HEAD",A),{timeoutMs:2e4})}async function M(t){const e=t.fetchFn??fetch,a=t.jetzt??Date.now,s=t.schlafen??l,r=a()+(t.bereitFristMs??R);for(;;){try{const n=await e(`${t.cfg.apiUrl}/api/v1/instances/${t.cfg.instanceId}/export`,{headers:{Authorization:`Bearer ${t.cfg.jwt}`},signal:AbortSignal.timeout(g)});if(n.status===401||n.status===403)return"nicht-bereit";if(n.ok){const o=await n.json();if(Array.isArray(o?.lessons)&&o.lessons.length>0)return"hat-lektionen";if(Array.isArray(o?.lessons)&&!o.note)return"leer"}}catch{}if(a()>=r)return"nicht-bereit";await s(h)}}async function j(t,e){const a=t.fetchFn??fetch,s=t.schlafen??l;let r=0,n=0;const o=async()=>{for(;r<e.length;){const c=e[r++];for(let i=1;i<=m;i++){try{const f=await a(`${t.cfg.apiUrl}/api/v1/instances/${t.cfg.instanceId}/learn`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.cfg.jwt}`},body:JSON.stringify(c),signal:AbortSignal.timeout(g)});if(f.ok){n++;break}if(f.status!==409&&f.status!==429&&f.status<500)break}catch{}i<m&&await s(h*i)}}};return await Promise.all(Array.from({length:Math.min(v,e.length)},o)),n}async function U(t){try{if(!k(t.env))return{art:"aus"};const e=u(t.projekt||"."),a=await(t.gitWurzel??T)(e);let s,r;if(a){const c=y(a,t.env);if(c)return{art:"ausgeschlossen",grund:c};s="git";let i="";try{i=(t.gitLog??L)(a)}catch{}if(r=b(_(i)),r.length===0)return{art:s,lektionen:0,gesendet:0}}else{if(!E(t.env))return{art:"kein-repo"};s="startvorrat",r=I()}const n=await M(t);if(n!=="leer")return{art:n};const o=await j(t,r);return o>0&&await x(t.cfg,{force:!0,fetchFn:t.fetchFn}),{art:s,lektionen:r.length,gesendet:o}}catch(e){return{art:"fehler",grund:e instanceof Error?e.message:String(e)}}}function W(t){if((t.art==="git"||t.art==="startvorrat")&&t.gesendet>0)return{art:t.art,lektionen:t.gesendet}}export{R as BEREIT_FRIST_MS,h as BEREIT_TAKT_MS,g as LERN_FRIST_MS,v as LERN_PARALLEL,m as LERN_VERSUCHE,O as STARTWISSEN_IMPORT,b as gitAnfragen,W as hookImportFuerAuftrag,U as importiereStartwissen,I as startvorratAnfragen};
@@ -1,17 +1,19 @@
1
- import{execFile as A}from"node:child_process";import{homedir as T}from"node:os";import{basename as k,isAbsolute as N,relative as z,resolve as d}from"node:path";import{safeJsonParse as v,scanKeys as m}from"./utils.js";import{STARTER_CORPUS_SIZE as P}from"./starter-corpus.js";import{NAME_VEKTOR_PRAEFIX as C,VEKTOR_NACHTRAG as $,VEKTOR_PRAEFIX as D,ZWEIT_VEKTOR_PRAEFIX as L,packe as S,textFuerNamensVektor as M,textFuerVektor as x}from"./bedeutung.js";const u="cachly:startwissen:git",E=30,I=1500,F=1e3,K=3,_=90*86400,B=P;function G(t=process.env){return!/^(0|false|off|no|nein)$/i.test((t.CACHLY_STARTVORRAT??"").trim())}const b=t=>new Promise(e=>setTimeout(e,t));function at(t){for(const n of t.wurzeln??[])if(n.uri.startsWith("file:"))try{return t.dateiPfad(n.uri)}catch{}const e=t.env??{};for(const n of["CLAUDE_PROJECT_DIR","CACHLY_WORKSPACE"]){const r=(e[n]??"").trim();if(r&&!r.includes("${"))return r}return t.cwd}function J(t,e){const n=z(e,t);return n===""||!n.startsWith("..")&&!N(n)}function X(t,e){return process.platform==="win32"?t.toLowerCase()===e.toLowerCase():t===e}function U(t,e=process.env){const n=d(t),r=(e.CLAUDE_PLUGIN_ROOT??"").trim();if(r&&!r.includes("${")&&J(n,d(r)))return"plugin-ordner";if(n.split(/[\\/]+/).some(c=>c==="node_modules"||c==="_npx"))return"paketordner";const s=e.HOME||e.USERPROFILE||T();return s&&X(n,d(s))?"heimordner":""}function V(t){return new Promise(e=>{try{A("git",["rev-parse","--show-toplevel"],{cwd:t,timeout:5e3,windowsHide:!0},(n,r)=>{const s=String(r??"").trim();e(n||!s?"":d(s))})}catch{e("")}})}function W(t,e){return["","","---",`\u2139\uFE0F **cachly:** this new Brain just learned ${t} lesson${t===1?"":"s"} from the git history of \`${k(e)}\` (last ${E} commits at most). \`smart_recall\` finds them now. Tell the user once.`].join(`
2
- `)}let w="";function ot(){const t=w;return w="",t}async function j(t){const e=t.protokoll??(r=>{process.stderr.write(r)}),n=t.env??process.env;try{const r=d(await t.projektOrdner()),s=await(t.gitWurzel??V)(r);if(!s)return e(`cachly: ${r} is not a git repository \u2014 the new Brain starts without git history.
3
- `),t.startvorrat&&G(n)?await Z(t,r,e):{art:"kein-repo",ordner:r};const c=U(s,n);if(c)return e(`cachly: ${s} is not a user project (${c}) \u2014 no import from git history.
4
- `),{art:"ausgeschlossen",ordner:s,grund:c};const o=await t.verbindung(t.instanzId);if((await m(o,"cachly:lesson:best:*",{max:1})).length>0)return e(`cachly: this Brain already has lessons \u2014 no import from git history.
5
- `),{art:"hat-lektionen"};if(await o.set(u,JSON.stringify({stand:"laeuft",seit:new Date().toISOString(),ordner:s}),"NX")!=="OK")return{art:"schon-erledigt"};e(`cachly: new Brain \u2014 learning from the last ${E} commits of ${s} in the background.
6
- `);const i=Date.now();try{await t.ausGit({instance_id:t.instanzId,repo_path:s,limit:E})}catch(h){const f=h instanceof Error?h.message:String(h);return await o.set(u,JSON.stringify({stand:"abgebrochen",am:new Date().toISOString(),grund:f.slice(0,200)})).catch(()=>{}),e(`cachly: import from git history failed: ${f}
7
- `),{art:"fehler",grund:f}}const a=[];for(const h of await m(o,"cachly:lesson:best:*",{max:1e3})){const f=v(await o.get(h),{});(Array.isArray(f.tags)?f.tags:[]).includes("brain_from_git")&&a.push({topic:h.slice(19),lektion:f})}await o.set(u,JSON.stringify({stand:"fertig",am:new Date().toISOString(),ordner:s,lektionen:a.length})).catch(()=>{});const g=((Date.now()-i)/1e3).toFixed(1);e(`cachly: learned ${a.length} lessons from git history in ${g} s.
8
- `),a.length>0&&(w=W(a.length,s));try{t.melde?.(a.length)}catch{}const p=await R(o,a,t,e);return{art:"fertig",ordner:s,lektionen:a.length,vektoren:p}}catch(r){const s=r instanceof Error?r.message:String(r);return e(`cachly: import from git history stopped: ${s}
9
- `),{art:"fehler",grund:s}}}function H(t){return["","","---",`\u2139\uFE0F **cachly:** the project folder is not a git repository, so this new Brain loaded ${t} starter lesson${t===1?"":"s"} (common engineering fixes, tagged \`source: "starter"\`; they never override own lessons). \`smart_recall\` finds them now. Tell the user once.`].join(`
10
- `)}async function Z(t,e,n){const r=t.startvorrat;if(!r)return{art:"kein-repo",ordner:e};const s=await t.verbindung(t.instanzId);if((await m(s,"cachly:lesson:best:*",{max:1})).length>0)return n(`cachly: this Brain already has lessons \u2014 no starter lessons.
11
- `),{art:"hat-lektionen"};if(await s.set(u,JSON.stringify({stand:"startvorrat",seit:new Date().toISOString(),ordner:e}),"NX")!=="OK")return{art:"schon-erledigt"};n(`cachly: new Brain without git history \u2014 loading ${B} starter lessons in the background.
12
- `);try{await r({instance_id:t.instanzId})}catch(i){const a=i instanceof Error?i.message:String(i);return await s.set(u,JSON.stringify({stand:"abgebrochen",am:new Date().toISOString(),grund:a.slice(0,200)})).catch(()=>{}),n(`cachly: loading starter lessons failed: ${a}
13
- `),{art:"fehler",grund:a}}const o=[];for(const i of await m(s,"cachly:lesson:best:*",{max:1e3})){const a=v(await s.get(i),{});a.source==="starter"&&o.push({topic:i.slice(19),lektion:a})}await s.set(u,JSON.stringify({stand:"fertig",am:new Date().toISOString(),ordner:e,startvorrat:o.length})).catch(()=>{}),n(`cachly: loaded ${o.length} starter lessons.
14
- `),o.length>0&&(w=H(o.length));try{t.meldeStartvorrat?.(o.length)}catch{}const l=await R(s,o,t,n);return{art:"startvorrat",ordner:e,lektionen:o.length,vektoren:l}}async function R(t,e,n,r){const s=n.einbetten;if(!s||e.length===0||!(n.hatEinbettung??(()=>!0))())return 0;for(const{topic:a}of e)await t.sadd($,a).catch(()=>{});const c=n.schlafen??b,o=n.pauseMs??I;let l=0,i=0;for(const{topic:a,lektion:g}of e)try{await c(o);const p=await s(x({...g,topic:a}));p?.length&&(await t.set(`${D}${a}`,S(p),"EX",_),await t.srem($,a),l++),await c(o);const h=await s(M(a));h?.length&&await t.set(`${C}${a}`,S(h),"EX",_),i=0}catch{if(i++,i>=K){r(`cachly: embedding service unavailable \u2014 ${e.length-l} lessons wait in the backlog; smart_recall fills them in later.
15
- `);break}}return r(`cachly: search vectors for git lessons: ${l}/${e.length}.
16
- `),l>0&&await Y(t,e,n,r),l}async function Y(t,e,n,r){const s=n.einbettenZweit;if(!s)return 0;const c=n.schlafen??b,o=n.pauseMs??I;let l=0;for(const{topic:i,lektion:a}of e)try{await c(o);const g=await s(x({...a,topic:i}));g?.length&&(await t.set(`${L}${i}`,S(g),"EX",_),l++)}catch{break}return r(`cachly: second-model vectors for git lessons: ${l}/${e.length}.
17
- `),l}const y=new Map,O=new Map;function it(t){return O.get(t)}function ct(t){const e=y.get(t.instanzId);if(e)return e;const n=(async()=>(await(t.schlafen??b)(t.anlaufMs??F),j(t)))().catch(r=>({art:"fehler",grund:r instanceof Error?r.message:String(r)})).then(r=>(O.set(t.instanzId,r.art),r));return y.set(t.instanzId,n),n}function lt(t){return y.has(t)}async function ht(t,e){return await t.set(u,JSON.stringify({stand:e,seit:new Date().toISOString()}),"NX")==="OK"}function ft(){y.clear(),O.clear(),w=""}export{F as ANLAUF_MS,I as EINBETT_PAUSE_MS,B as STARTVORRAT_LEKTIONEN,E as STARTWISSEN_COMMITS,u as STARTWISSEN_MARKE,ft as _startwissenZuruecksetzen,U as ausschlussGrund,ht as beanspruchStartwissen,V as echteGitWurzel,ot as holeStartwissenHinweis,j as lerneAusGitGeschichte,ct as starteStartwissen,G as startvorratErlaubt,H as startvorratSatz,it as startwissenAusgang,lt as startwissenGestartet,W as startwissenSatz,at as waehleProjektOrdner};
1
+ import{execFile as D}from"node:child_process";import{homedir as P}from"node:os";import{basename as C,isAbsolute as X,relative as K,resolve as p}from"node:path";import{safeJsonParse as S,scanKeys as m}from"./utils.js";import{STARTER_CORPUS_SIZE as L}from"./starter-corpus.js";import{NAME_VEKTOR_PRAEFIX as M,VEKTOR_NACHTRAG as E,VEKTOR_PRAEFIX as x,ZWEIT_VEKTOR_PRAEFIX as I,packe as b,textFuerNamensVektor as F,textFuerVektor as A}from"./bedeutung.js";const d="cachly:startwissen:git",$=30,R=1500,J=1e3,B=3,_=90*86400,G=L;function W(t=process.env){return!/^(0|false|off|no|nein)$/i.test((t.CACHLY_STARTVORRAT??"").trim())}const v=t=>new Promise(e=>setTimeout(e,t));function it(t){for(const r of t.wurzeln??[])if(r.uri.startsWith("file:"))try{return t.dateiPfad(r.uri)}catch{}const e=t.env??{};for(const r of["CLAUDE_PROJECT_DIR","CACHLY_WORKSPACE"]){const n=(e[r]??"").trim();if(n&&!n.includes("${"))return n}return t.cwd}function j(t,e){const r=K(e,t);return r===""||!r.startsWith("..")&&!X(r)}function H(t,e){return process.platform==="win32"?t.toLowerCase()===e.toLowerCase():t===e}function U(t,e=process.env){const r=p(t),n=(e.CLAUDE_PLUGIN_ROOT??"").trim();if(n&&!n.includes("${")&&j(r,p(n)))return"plugin-ordner";if(r.split(/[\\/]+/).some(c=>c==="node_modules"||c==="_npx"))return"paketordner";const s=e.HOME||e.USERPROFILE||P();return s&&H(r,p(s))?"heimordner":""}function N(t){return new Promise(e=>{try{D("git",["rev-parse","--show-toplevel"],{cwd:t,timeout:5e3,windowsHide:!0},(r,n)=>{const s=String(n??"").trim();e(r||!s?"":p(s))})}catch{e("")}})}function T(t,e){return["","","---",`\u2139\uFE0F **cachly:** this new Brain just learned ${t} lesson${t===1?"":"s"} from the git history of \`${C(e)}\` (last ${$} commits at most). \`smart_recall\` finds them now. Tell the user once.`].join(`
2
+ `)}let w="";function ot(){const t=w;return w="",t}async function V(t){const e=t.protokoll??(n=>{process.stderr.write(n)}),r=t.env??process.env;try{if(t.vomHook)return await Y(t,t.vomHook,e);const n=p(await t.projektOrdner()),s=await(t.gitWurzel??N)(n);if(!s)return e(`cachly: ${n} is not a git repository \u2014 the new Brain starts without git history.
3
+ `),t.startvorrat&&W(r)?await Z(t,n,e):{art:"kein-repo",ordner:n};const c=U(s,r);if(c)return e(`cachly: ${s} is not a user project (${c}) \u2014 no import from git history.
4
+ `),{art:"ausgeschlossen",ordner:s,grund:c};const i=await t.verbindung(t.instanzId);if((await m(i,"cachly:lesson:best:*",{max:1})).length>0)return e(`cachly: this Brain already has lessons \u2014 no import from git history.
5
+ `),{art:"hat-lektionen"};if(await i.set(d,JSON.stringify({stand:"laeuft",seit:new Date().toISOString(),ordner:s}),"NX")!=="OK")return{art:"schon-erledigt"};e(`cachly: new Brain \u2014 learning from the last ${$} commits of ${s} in the background.
6
+ `);const o=Date.now();try{await t.ausGit({instance_id:t.instanzId,repo_path:s,limit:$})}catch(h){const g=h instanceof Error?h.message:String(h);return await i.set(d,JSON.stringify({stand:"abgebrochen",am:new Date().toISOString(),grund:g.slice(0,200)})).catch(()=>{}),e(`cachly: import from git history failed: ${g}
7
+ `),{art:"fehler",grund:g}}const a=[];for(const h of await m(i,"cachly:lesson:best:*",{max:1e3})){const g=S(await i.get(h),{});(Array.isArray(g.tags)?g.tags:[]).includes("brain_from_git")&&a.push({topic:h.slice(19),lektion:g})}await i.set(d,JSON.stringify({stand:"fertig",am:new Date().toISOString(),ordner:s,lektionen:a.length})).catch(()=>{});const l=((Date.now()-o)/1e3).toFixed(1);e(`cachly: learned ${a.length} lessons from git history in ${l} s.
8
+ `),a.length>0&&(w=T(a.length,s));try{t.melde?.(a.length)}catch{}const u=await k(i,a,t,e);return{art:"fertig",ordner:s,lektionen:a.length,vektoren:u}}catch(n){const s=n instanceof Error?n.message:String(n);return e(`cachly: import from git history stopped: ${s}
9
+ `),{art:"fehler",grund:s}}}function z(t){return["","","---",`\u2139\uFE0F **cachly:** the project folder is not a git repository, so this new Brain loaded ${t} starter lesson${t===1?"":"s"} (common engineering fixes, tagged \`source: "starter"\`; they never override own lessons). \`smart_recall\` finds them now. Tell the user once.`].join(`
10
+ `)}async function Z(t,e,r){const n=t.startvorrat;if(!n)return{art:"kein-repo",ordner:e};const s=await t.verbindung(t.instanzId);if((await m(s,"cachly:lesson:best:*",{max:1})).length>0)return r(`cachly: this Brain already has lessons \u2014 no starter lessons.
11
+ `),{art:"hat-lektionen"};if(await s.set(d,JSON.stringify({stand:"startvorrat",seit:new Date().toISOString(),ordner:e}),"NX")!=="OK")return{art:"schon-erledigt"};r(`cachly: new Brain without git history \u2014 loading ${G} starter lessons in the background.
12
+ `);try{await n({instance_id:t.instanzId})}catch(o){const a=o instanceof Error?o.message:String(o);return await s.set(d,JSON.stringify({stand:"abgebrochen",am:new Date().toISOString(),grund:a.slice(0,200)})).catch(()=>{}),r(`cachly: loading starter lessons failed: ${a}
13
+ `),{art:"fehler",grund:a}}const i=[];for(const o of await m(s,"cachly:lesson:best:*",{max:1e3})){const a=S(await s.get(o),{});a.source==="starter"&&i.push({topic:o.slice(19),lektion:a})}await s.set(d,JSON.stringify({stand:"fertig",am:new Date().toISOString(),ordner:e,startvorrat:i.length})).catch(()=>{}),r(`cachly: loaded ${i.length} starter lessons.
14
+ `),i.length>0&&(w=z(i.length));try{t.meldeStartvorrat?.(i.length)}catch{}const f=await k(s,i,t,r);return{art:"startvorrat",ordner:e,lektionen:i.length,vektoren:f}}async function Y(t,e,r){const n=p(await t.projektOrdner()),s=e.art==="git",c=s&&await(t.gitWurzel??N)(n)||n,i=await t.verbindung(t.instanzId),f=new Date().toISOString();if(await i.set(d,JSON.stringify(s?{stand:"fertig",am:f,ordner:c,lektionen:e.lektionen,quelle:"hook"}:{stand:"fertig",am:f,ordner:n,startvorrat:e.lektionen,quelle:"hook"}),"NX")!=="OK")return{art:"schon-erledigt"};const a=[];for(const u of await m(i,"cachly:lesson:best:*",{max:1e3})){const h=S(await i.get(u),{});(s?Array.isArray(h.tags)&&h.tags.includes("brain_from_git"):h.source==="starter")&&a.push({topic:u.slice(19),lektion:h})}if(s){r(`cachly: the session hook learned ${a.length} lessons from the git history of ${c}.
15
+ `),a.length>0&&(w=T(a.length,c));try{t.melde?.(a.length)}catch{}}else{r(`cachly: the session hook loaded ${a.length} starter lessons.
16
+ `),await i.set(`cachly:stats:born_at:${t.instanzId}`,f,"EX",365*86400,"NX").catch(()=>{}),await i.set(`cachly:brain:starter_seeded:${t.instanzId}`,f,"EX",365*86400).catch(()=>{}),a.length>0&&(w=z(a.length));try{t.meldeStartvorrat?.(a.length)}catch{}}const l=await k(i,a,t,r,{nurFehlende:!0});return s?{art:"fertig",ordner:c,lektionen:a.length,vektoren:l}:{art:"startvorrat",ordner:n,lektionen:a.length,vektoren:l}}async function k(t,e,r,n,{nurFehlende:s=!1}={}){const c=r.einbetten;if(!c||e.length===0||!(r.hatEinbettung??(()=>!0))())return 0;for(const{topic:l}of e)await t.sadd(E,l).catch(()=>{});const i=r.schlafen??v,f=r.pauseMs??R;let o=0,a=0;for(const{topic:l,lektion:u}of e)try{if(await i(f),s&&await t.exists(`${x}${l}`)){await t.srem(E,l),o++,a=0;continue}const h=await c(A({...u,topic:l}));h?.length&&(await t.set(`${x}${l}`,b(h),"EX",_),await t.srem(E,l),o++),await i(f);const g=await c(F(l));g?.length&&await t.set(`${M}${l}`,b(g),"EX",_),a=0}catch{if(a++,a>=B){n(`cachly: embedding service unavailable \u2014 ${e.length-o} lessons wait in the backlog; smart_recall fills them in later.
17
+ `);break}}return n(`cachly: search vectors for git lessons: ${o}/${e.length}.
18
+ `),o>0&&await Q(t,e,r,n,s),o}async function Q(t,e,r,n,s=!1){const c=r.einbettenZweit;if(!c)return 0;const i=r.schlafen??v,f=r.pauseMs??R;let o=0;for(const{topic:a,lektion:l}of e)try{if(s&&await t.exists(`${I}${a}`)){o++;continue}await i(f);const u=await c(A({...l,topic:a}));u?.length&&(await t.set(`${I}${a}`,b(u),"EX",_),o++)}catch{break}return n(`cachly: second-model vectors for git lessons: ${o}/${e.length}.
19
+ `),o}const y=new Map,O=new Map;function ct(t){return O.get(t)}function lt(t){const e=y.get(t.instanzId);if(e)return e;const r=(async()=>(await(t.schlafen??v)(t.anlaufMs??J),V(t)))().catch(n=>({art:"fehler",grund:n instanceof Error?n.message:String(n)})).then(n=>(O.set(t.instanzId,n.art),n));return y.set(t.instanzId,r),r}function ht(t){return y.has(t)}async function ft(t,e){return await t.set(d,JSON.stringify({stand:e,seit:new Date().toISOString()}),"NX")==="OK"}function gt(){y.clear(),O.clear(),w=""}export{J as ANLAUF_MS,R as EINBETT_PAUSE_MS,G as STARTVORRAT_LEKTIONEN,$ as STARTWISSEN_COMMITS,d as STARTWISSEN_MARKE,gt as _startwissenZuruecksetzen,U as ausschlussGrund,ft as beanspruchStartwissen,N as echteGitWurzel,ot as holeStartwissenHinweis,V as lerneAusGitGeschichte,lt as starteStartwissen,W as startvorratErlaubt,z as startvorratSatz,ct as startwissenAusgang,ht as startwissenGestartet,T as startwissenSatz,it as waehleProjektOrdner};
package/glama.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://glama.ai/mcp/schemas/server.json",
3
- "version": "0.10.193",
3
+ "version": "0.10.195",
4
4
  "maintainers": [
5
5
  "HeinrichNebula"
6
6
  ],