@cachly-dev/mcp-server 0.10.255 → 0.10.257
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/ambient-cli.js +2 -2
- package/dist/src/ambient-hook.js +3 -3
- package/dist/src/einblendung-kern.js +1 -1
- package/dist/src/einblendung.js +7 -7
- package/dist/src/prompt-herkunft.js +1 -0
- package/glama.json +1 -1
- package/hooks/cachly-ambient-einblendung.mjs +28 -28
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/src/ambient-cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{promptEinblendung as l,holeBestand as u,sitzungsKontext as a,hookAusgabe as s,estimateTokens as f}from"./einblendung.js";function m(e){const t=(e??"").trim();if(!t)return null;try{const o=JSON.parse(t);return o&&typeof o=="object"?o:null}catch{return null}}const
|
|
2
|
-
`).map(n=>n.trim()).filter(n=>n.length>0);return{action:(o.find(n=>c.test(n))??o[0]??t).slice(0,200),outcome:"success",details:t.slice(0,500),severity:"minor"}}function
|
|
1
|
+
import{promptEinblendung as l,holeBestand as u,sitzungsKontext as a,hookAusgabe as s,estimateTokens as f,frageAusPrompt as p}from"./einblendung.js";function m(e){const t=(e??"").trim();if(!t)return null;try{const o=JSON.parse(t);return o&&typeof o=="object"?o:null}catch{return null}}const g=new Set(["Edit","Write","MultiEdit","NotebookEdit"]);function h(e){const t=e.hook_event_name??"UserPromptSubmit";if(t==="SessionStart"||t==="Stop")return null;if(t==="PreToolUse"){if(e.tool_name&&!g.has(e.tool_name))return null;const r=e.tool_input?.file_path;if(typeof r!="string"||!r.trim())return null;const n=r.trim().replace(/\\/g,"/"),i=(e.cwd??"").replace(/\\/g,"/").replace(/\/+$/,"");return i&&n.toLowerCase().startsWith(i.toLowerCase()+"/")?n.slice(i.length+1):n}return p(e.prompt??"")||null}const c=/\b(fixed|resolved|behoben|gefixt|root cause (was|is|found)|the bug was|der fehler (lag|war)|ursache (war|gefunden)|now passes|tests? (are|is|sind) (green|grün)|deployed successfully)\b/i,d=/\b(could not|couldn't|cannot|can't|unable to|not (yet )?(fixed|resolved|working)|still (fail|red|broken|not|deadlock)\w*|unknown|unclear|gave up|nicht (behoben|gefixt|gel(ö|oe)st)|konnte (ich )?(\w+ )?nicht|noch nicht|weiterhin|unklar)\b/i;function k(e){const t=(e.last_assistant_message??"").trim();if(t.length<80||!c.test(t)||d.test(t))return null;const o=t.split(`
|
|
2
|
+
`).map(n=>n.trim()).filter(n=>n.length>0);return{action:(o.find(n=>c.test(n))??o[0]??t).slice(0,200),outcome:"success",details:t.slice(0,500),severity:"minor"}}function x(e){const t=e.action.toLowerCase().replace(/[^a-z0-9:\-_\s]/g,"").trim().split(/\s+/).slice(0,4).join("-");return{topic:t?t.includes(":")?t:`auto:${t}`:"auto:stop",outcome:e.outcome,what_worked:e.action,context:e.details,severity:e.severity,source:"ambient-stop",tags:["auto-learned"]}}const S=s,w=5e3;async function v(e,t){try{const o=m(e);if(!o)return"";const r=o.hook_event_name??"UserPromptSubmit";if(!t.cfg.jwt||!t.cfg.instanceId)return"";let n="";if(r==="SessionStart"){const{lessons:i}=await u(t.cfg,{force:!0,fetchFn:t.fetchFn});n=a(i)}else{const i=h(o);if(i===null)return"";n=(await l(i,t.cfg,{nebenlauf:t.nebenlauf,abrufMs:w,leser:r!=="PreToolUse",session:o.session_id??null,protokoll:t.protokoll,ereignis:r,editor:t.editor,fetchFn:t.fetchFn})).kontext}if(!n)return"";try{t.onInject?.(f(n),r)}catch{}return s(r,n)}catch{return""}}export{w as PROMPT_ABRUF_MS,S as buildHookOutput,m as parseHookPayload,h as recallQueryFor,v as runEinblendung,x as stopLernanfrage,k as stopObservation};
|
package/dist/src/ambient-hook.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{readFileSync as
|
|
1
|
+
import{readFileSync as K}from"node:fs";import{tmpdir as y}from"node:os";import{parseHookPayload as O,runEinblendung as j,stopLernanfrage as N,stopObservation as R}from"./ambient-cli.js";import{stopAntwort as M}from"./schreibbeleg.js";import{holeBestand as G,hookAusgabe as B,starteNebenlauf as U}from"./einblendung.js";import{STARTWISSEN_IMPORT as p,hookImportFuerAuftrag as Y,importiereStartwissen as $}from"./startwissen-hook.js";import{belohnungMelden as D}from"./lernen.js";import{appendLedgerEntry as J,reportLedgerEntry as V}from"./ambient-ledger.js";import{copilotHatHook as Q,cursorHatHook as W,findeInstanz as S,findeSchluessel as w,hookUmfeld as _,pluginVersion as X,projektHatHook as q}from"./hook-zugang.js";import{ABKUEHLUNG_HOOK_MS as Z,schreibeAuftrag as L,sichereKonto as tt,startwissenEingeschaltet as v}from"./konto-anlegen.js";import{istInstanzKennung as P,sofortTestHinweis as et}from"./zugang.js";import{CURSOR_FLAG as d,cursorEreignis as T,cursorHookAntwort as nt,cursorLeer as rt,istCursorNutzlast as E}from"./cursor-hook.js";import{COPILOT_FLAG as b,copilotEreignis as ot,copilotHookAntwort as it,istFremdeLaufzeit as F}from"./copilot-hook.js";import{CODEX_FLAG as z,codexHookAntwort as st}from"./codex-hook.js";import{GEMINI_FLAG as k,geminiEreignis as ct,geminiHookAntwort as at}from"./gemini-hook.js";const ut="https://api.cachly.dev",x=5e3,ft="ambient-auffrischen",C=new Set(["SessionStart","UserPromptSubmit","PreToolUse","Stop"]);async function lt(t,e){if(!t.args.includes(d)&&(T(e,t.args)!=="sessionStart"||W(t.umfeld)))return"";const o=t.args.filter(r=>r==="--plugin");return nt({payload:e,args:t.args,claudeLauf:(r,u)=>I({...t,raw:r,args:[u,...o]}),ablageOrdner:t.cursorAblage})}function pt(t,e){const n=(o,r)=>I({...t,raw:o,args:[r]});return t.args.includes(b)?it({payload:e,args:t.args,claudeLauf:n,ablageOrdner:t.copilotAblage}):t.args.includes(z)?st({payload:e,args:t.args,claudeLauf:n}):t.args.includes(k)?at({payload:e,args:t.args,claudeLauf:n}):null}function dt(t,e){return t.includes(d)||E(e)?"cursor":t.includes(b)?"copilot":t.includes(z)?"codex":t.includes(k)?"gemini":F(e)?"vscode":"claude"}async function mt(t){const e=await tt({apiUrl:t.apiUrl,version:X(t.umfeld),home:t.umfeld.heim,env:{...t.umfeld.env,CACHLY_QUELLE:"claude-code-plugin"},fristMs:x,anfrageMs:x,abkuehlungMs:Z,holen:t.fetchFn});if(e.art==="vorhanden")return{apiKey:e.apiKey,instanzId:e.instanzId,hinweis:""};if(e.art!=="angelegt")return null;if(v(t.umfeld.env)){const n={apiUrl:t.apiUrl,jwt:e.test.apiKey,instanceId:e.test.instanzId};t.selbst&&(t.nebenlauf??U)(n,[t.selbst,p,t.umfeld.projekt],{zweck:p,ordner:y()})||L({instanzId:e.test.instanzId,projekt:t.umfeld.projekt},{home:t.umfeld.heim})}return{apiKey:e.test.apiKey,instanzId:e.test.instanzId,hinweis:et(e.test)}}function gt(t,e){const n=e.replace(/^\s+/,"");if(!t)return B("SessionStart",n);try{const o=JSON.parse(t),r=o.hookSpecificOutput?.additionalContext;return!o.hookSpecificOutput||typeof r!="string"?t:(o.hookSpecificOutput.additionalContext=`${n}
|
|
2
2
|
|
|
3
|
-
${r}`,JSON.stringify(o))}catch{return t}}async function I(t){try{const e=
|
|
4
|
-
`);const i=
|
|
3
|
+
${r}`,JSON.stringify(o))}catch{return t}}async function I(t){try{const e=O(t.raw),n={...t,editor:t.editor??dt(t.args,e)};if(n.args.includes(d)||E(e))return await lt(n,e);const o=pt(n,e);if(o)return await o;const r=e?.hook_event_name??n.args.find(i=>C.has(i))??n.umfeld.env.CACHLY_HOOK_EVENT??"";if(F(e)&&(r!=="SessionStart"&&r!=="UserPromptSubmit"||Q(n.umfeld))||n.args.includes("--plugin")&&r&&q(r,n.umfeld))return"";let u=null;if(r==="Stop"&&e?.transcript_path)try{u=K(e.transcript_path,"utf-8").split(`
|
|
4
|
+
`);const i=M(u,e.stop_hook_active===!0);if(i)return i}catch{}let f=w(n.umfeld),c=S(n.umfeld),s="";if(!f&&r==="SessionStart"&&n.args.includes("--plugin")&&!P(c)){const i=await mt(n);i&&(f=i.apiKey,c=i.instanzId??c,s=i.hinweis)}if(!f||!c)return"";const a={apiUrl:n.apiUrl,jwt:f,instanceId:c};if(r==="Stop"){const i=e?R(e):null,h=i?(n.fetchFn??fetch)(`${a.apiUrl}/api/v1/instances/${a.instanceId}/learn`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.jwt}`},body:JSON.stringify(N(i)),signal:AbortSignal.timeout(8e3)}).catch(()=>{}):void 0,l=D(a,e?.session_id??null,u,{fetchFn:n.fetchFn});return await Promise.all([h,l]),""}let m;const g=await(n.einblenden??j)(n.raw,{cfg:a,nebenlauf:n.selbst?[n.selbst,ft]:void 0,editor:n.editor,fetchFn:n.fetchFn,onInject:(i,h)=>{const l={ts:new Date().toISOString(),event:h,injected:i,prevented:0,instanz:a.instanceId};J(l),m=V(a,l,n.fetchFn)}});return m&&await Promise.race([m,new Promise(i=>setTimeout(i,500))]),r==="SessionStart"&&!g&&!s&&n.selbst&&v(n.umfeld.env)&&(n.nebenlauf??U)(a,[n.selbst,p,n.umfeld.projekt],{zweck:p,ordner:y()}),s?gt(g,s):g}catch{return""}}async function ht(){if(process.stdin.isTTY)return"";const t=[];for await(const e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf-8")}function A(){return process.env.CACHLY_API_URL||ut}const H={SessionStart:25e3,UserPromptSubmit:8e3,PreToolUse:8e3,Stop:5e4,sessionStart:25e3,beforeSubmitPrompt:8e3,postToolUse:3e3,userPromptSubmitted:8e3,PostToolUse:3e3,BeforeAgent:8e3};function St(t,e){return t.includes(d)?rt(T(e,t)):t.includes(b)?ot(e,t)?"{}":"":t.includes(k)&&ct(e,t)?"{}":""}async function Ft(t,e){try{const n=await ht(),o=O(n),r=o?.hook_event_name??t.find(s=>C.has(s)||Object.hasOwn(H,s))??"",u=Number(process.env.CACHLY_HOOK_FRIST_MS)||H[r]||H.UserPromptSubmit,f=St(t,o),c=await Promise.race([I({args:t,raw:n,umfeld:_(),apiUrl:A(),selbst:e}),new Promise(s=>setTimeout(()=>s(f),u))]);c&&await new Promise(s=>process.stdout.write(c,()=>s()))}catch{}process.exit(0)}async function zt(){try{const t=_(),e=w(t),n=S(t);e&&n&&await G({apiUrl:A(),jwt:e,instanceId:n},{force:!0,lernen:!0})}catch{}process.exit(0)}async function xt(t){try{const e=_(),n=w(e),o=S(e);if(n&&P(o)){const r=await $({cfg:{apiUrl:A(),jwt:n,instanceId:o},projekt:t,env:e.env});r.art!=="aus"&&L({instanzId:o,projekt:t,vomHook:Y(r)},{home:e.heim})}}catch{}process.exit(0)}export{ft as AUFFRISCHEN,H as HOOK_FRIST_MS,x as KONTO_FRIST_MS,ut as STANDARD_API_URL,zt as auffrischenHauptlauf,dt as editorVon,I as hookAntwort,Ft as hookHauptlauf,xt as startwissenImportHauptlauf};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Seltenheit as f,inhaltsWoerter as c,grobStamm as p,spreizeImTopf as m}from"./rangfolge.js";import{lektionsText as w}from"./seltenheitsbestand.js";import{bestandAusDokumenten as g,keywordSearchMitBestand as k}from"./search.js";import{SINN_TOPF as E,EINBLENDUNG_DECKUNG as b,EINBLENDUNG_ZEUGE as N}from"./rangfolge-stellschrauben.js";import{istMarkiert as S}from"./verdacht-marke.js";import{istTeamweit as x}from"./utils.js";import{rahmeEin as
|
|
1
|
+
import{Seltenheit as f,inhaltsWoerter as c,grobStamm as p,spreizeImTopf as m}from"./rangfolge.js";import{lektionsText as w}from"./seltenheitsbestand.js";import{bestandAusDokumenten as g,keywordSearchMitBestand as k}from"./search.js";import{SINN_TOPF as E,EINBLENDUNG_DECKUNG as b,EINBLENDUNG_ZEUGE as N}from"./rangfolge-stellschrauben.js";import{istMarkiert as S}from"./verdacht-marke.js";import{istTeamweit as x}from"./utils.js";import{rahmeEin as j,entschaerfe as B,RAHMEN_ETIKETT as C,RAHMEN_HINWEIS as F}from"./einblendung-rahmen.js";import{stopAntwort as K}from"./schreibbeleg.js";import{frageAusPrompt as v}from"./prompt-herkunft.js";const _=E,T=["topic","outcome","what_worked","what_failed","severity","confidence","recall_count","ts","endorsements"],d=new Set("the a an and or but for to of in on at is are be do does did we you i it this that with without how what why when where can could would should please just get set use using make made need bitte und oder der die das ein eine f\xFCr mit ohne wie was warum kann soll noch mal auch von den dem ist weil wenn dann doch aber alle jede jeder jedes immer wieder wird werden wurde muss beim sehr nicht".split(/\s+/)),z=["ierungen","ierung","ieren","iert","ungen","ung","heit","keit","lich","isch","ing","ed","en","er","es","e","n","s"];function y(s){for(const e of z)if(s.length-e.length>=4&&s.endsWith(e))return s.slice(0,-e.length);return s}function I(s){return[...new Set(String(s).toLowerCase().split(/[^a-z0-9]+/).filter(e=>e.length>3&&!d.has(e)).map(y).filter(e=>!d.has(e)))]}function D(s,e){let i=0;for(const o of s)e.includes(o)&&i++;return i}class L{texte;wortmengen;heuhaufen;statistik;wortbestand;platzVonSchluessel=new Map;topf;lektionen;constructor(e,{topf:i=_}={}){const o=e.filter(t=>!S(t)&&x(t));this.lektionen=o,this.topf=i,this.texte=o.map(t=>w(t)),this.wortmengen=this.texte.map(t=>new Set([...c(t)].map(p))),this.heuhaufen=this.texte.map(t=>t.toLowerCase()),this.statistik=new f(this.texte);const h=o.map((t,a)=>{const u=`cachly:lesson:best:${String(t.topic??a)}`;this.platzVonSchluessel.set(u,a);const l={};for(const n of T)t[n]!==void 0&&(l[n]=t[n]);return{key:u,content:JSON.stringify(l)}});this.wortbestand=g(h)}get groesse(){return this.lektionen.length}sortiere(e){if(!this.wortbestand)return[];const i=k(this.wortbestand,e,this.topf),o=[],h=[];for(const n of i){const r=this.platzVonSchluessel.get(n.key);r!==void 0&&(o.push(r),h.push(n.score))}if(o.length===0)return[];const t=c(e),a=I(e),u=m(h),l=m(o.map(n=>this.statistik.besterZeuge(t,this.wortmengen[n])));return o.map((n,r)=>({lektion:this.lektionen[n],punkte:u[r]+b*this.statistik.deckung(t,this.wortmengen[n])+N*l[r],belege:D(a,this.heuhaufen[n])})).sort((n,r)=>r.punkte-n.punkte||Number(r.lektion.recall_count??0)-Number(n.lektion.recall_count??0))}}export{L as Einblendbestand,T as INDEX_FELDER,C as RAHMEN_ETIKETT,F as RAHMEN_HINWEIS,_ as WORT_TOPF,B as entschaerfe,v as frageAusPrompt,j as rahmeEin,y as stammKuerzen,K as stopAntwort,I as torWoerter,D as zaehleBelege};
|
package/dist/src/einblendung.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{readFileSync as
|
|
1
|
+
import{readFileSync as j,existsSync as C,writeFileSync as R,mkdirSync as F,statSync as W,appendFileSync as V}from"node:fs";import{dirname as $,join as _}from"node:path";import{tmpdir as b}from"node:os";import{createHash as X}from"node:crypto";import{spawn as Q}from"node:child_process";import{Einblendbestand as B,torWoerter as U}from"./einblendung-kern.js";import{rahmeEin as z,RAHMEN_HINWEIS as I}from"./einblendung-rahmen.js";import{istMarkiert as ee}from"./verdacht-marke.js";import{istTeamweit as te}from"./utils.js";import{istBlossesThema as re}from"./blosses-thema.js";import{leserText as ne}from"./seltenheitsbestand.js";import{mischeMitLeser as H}from"./leser.js";import{LeserSicherung as se,dateiSpeicher as oe,frageLeser as ie}from"./leser-sicherung.js";import{LESER_TIEFE_EINBLENDUNG as le,LESER_ZEITLIMIT_MS as ae}from"./rangfolge-stellschrauben.js";import{stufeEinblendungNachVersion as ce}from"./gueltigkeit-version.js";import{ARME as O,BASIS_MIN_BELEGE as ue,MERKMAL_KANDIDATEN as pe,OHNE_LERNEN as fe,entscheide as he,leseArmZaehlung as me,lernEinstellungen as de,lernenAuffrischen as ge,merkeEntscheidung as Ee,neuerSatz as _e,sitzungsKennung as be,zugKennung as ye}from"./lernen.js";export*from"./einblendung-kern.js";import{belohnungMelden as ht,lernenAuffrischen as mt,lernEinstellungen as dt,ARME as gt}from"./lernen.js";const Se=600*1e3,P=300*1e3,Ae=10*1e3,Ne=2e3,Ie=50,ve=60*1e3;function we(e,t){return t<P?{ttlMs:Ae,sofort:!0}:e<Ie?{ttlMs:ve,sofort:!1}:{ttlMs:Se,sofort:!1}}const D=8e3,ke=60*1e3,J=120,K=le,Me=1500,v=ae,Le=_(b(),"cachly-ambient-netlog.jsonl");function rt(e=process.cwd()){const t={apiUrl:process.env.CACHLY_API_URL||"https://api.cachly.dev",jwt:process.env.CACHLY_JWT||"",instanceId:process.env.CACHLY_BRAIN_INSTANCE_ID||""};if(t.jwt&&t.instanceId)return t;let r=e;for(let n=0;n<8;n++){const s=_(r,".mcp.json");if(C(s))try{const i=JSON.parse(j(s,"utf8"))?.mcpServers?.cachly?.env??{};if(t.apiUrl=t.apiUrl||i.CACHLY_API_URL||"https://api.cachly.dev",t.jwt=t.jwt||i.CACHLY_JWT||"",t.instanceId=t.instanceId||i.CACHLY_BRAIN_INSTANCE_ID||"",t.jwt&&t.instanceId)return t}catch{}const o=$(r);if(o===r)break;r=o}return t}function w(e){return X("sha1").update(e).digest("hex").slice(0,12)}function q(e){return _(b(),`cachly-ambient-bestand-${w(e)}.json`)}function xe(e){return _(b(),`cachly-leser-sicherung-${w(e)}.json`)}function Te(e,t="ambient-auffrischen"){return _(b(),`cachly-${t}-${w(e)}.lock`)}async function k(e,{fetchFn:t=fetch,zeitlimitMs:r=D}={}){try{const n=await t(`${e.apiUrl}/api/v1/instances/${e.instanceId}/export`,{headers:{Authorization:`Bearer ${e.jwt}`},signal:AbortSignal.timeout(r)});if(!n.ok)return null;const s=await n.json();return!Array.isArray(s?.lessons)||s.lessons.length===0&&typeof s.note=="string"&&s.note?null:s.lessons.map(o=>typeof o=="string"?je(o):o).filter(o=>!!o&&typeof o=="object")}catch{return null}}function je(e){try{return JSON.parse(e)}catch{return null}}function y(e,t,r="server"){const n=Date.now(),s=S(e),o=s?.seit??n;let i;r==="vorab"?i=t:r==="server"&&s?.vorab&&n-o<P&&(i=s.vorab);const c=r==="server"&&i?Ce(t,i):t;try{F($(e),{recursive:!0}),R(e,JSON.stringify({at:n,seit:o,lessons:c,...i?{vorab:i}:{}}),{mode:384})}catch{}return c}function Ce(e,t){const r=new Set(e.map(n=>n.topic));return[...e,...t.filter(n=>!r.has(n.topic))]}function nt(e,t){if(!e||t.length===0)return!1;const r=q(e);return(S(r)?.lessons.length??0)>0?!1:(y(r,t,"vorab"),!0)}function S(e){try{const t=JSON.parse(j(e,"utf8"));if(Array.isArray(t?.lessons)){const r=Number(t.at)||0;return{at:r,seit:Number(t.seit)||r,lessons:t.lessons,...Array.isArray(t.vorab)?{vorab:t.vorab}:{}}}}catch{}return null}function Re(e,t,{zweck:r,ordner:n}={}){const s=Te(e.instanceId,r);try{if(C(s)&&Date.now()-W(s).mtimeMs<ke)return!1;R(s,String(Date.now()),{mode:384})}catch{return!1}try{return Q(process.execPath,t,{detached:!0,stdio:"ignore",...n?{cwd:n}:{},env:{...process.env,CACHLY_API_URL:e.apiUrl,CACHLY_JWT:e.jwt,CACHLY_BRAIN_INSTANCE_ID:e.instanceId}}).unref(),!0}catch{return!1}}async function $e(e,{force:t=!1,nebenlauf:r,abrufMs:n=D,lernen:s=!1,vorabSchliessen:o=!1,fetchFn:i}={}){if(!e.jwt||!e.instanceId)return{lessons:[],quelle:"nicht-eingerichtet"};const c=q(e.instanceId);if(t){const[u]=await Promise.all([k(e,{fetchFn:i,zeitlimitMs:n}),s?ge(e,{fetchFn:i}):void 0]);if(u)return{lessons:y(c,u,o?"abschluss":"server"),quelle:"server"};const p=S(c);return p?{lessons:p.lessons,quelle:"platte-alt"}:{lessons:[],quelle:"server-nicht-erreichbar"}}const a=S(c);if(a){const u=Date.now(),p=we(a.lessons.length,u-a.seit);if(u-a.at<p.ttlMs)return{lessons:a.lessons,quelle:"platte"};if(p.sofort){const m=await k(e,{fetchFn:i,zeitlimitMs:Math.min(n,Ne)});return m?{lessons:y(c,m),quelle:"server"}:{lessons:a.lessons,quelle:"platte-alt"}}return r&&Re(e,r),{lessons:a.lessons,quelle:"platte-alt"}}const l=await k(e,{fetchFn:i,zeitlimitMs:n});return l?{lessons:y(c,l),quelle:"server"}:{lessons:[],quelle:"server-nicht-erreichbar"}}function M(e){return Math.ceil(String(e).length/4)}function L(e){const t=e.severity?`[${e.severity}] `:"",r=String(e.what_worked??"").replace(/\s+/g," ").trim(),n=r.length>J?`${r.slice(0,J)}\u2026`:r,s=typeof e.versionshinweis=="string"?` [${e.versionshinweis}]`:"";return`- ${t}${e.topic}${s}: ${n}`}const A={lessons:[],tokens:0,topScore:0,belege:0};function x(e,t,r){if(e.length===0)return{...A};const n=[];let s=0;e=ce(e);for(const{lektion:o}of e.slice(0,t)){const i=M(L(o));if(s+i>r)break;n.push(o),s+=i}return{lessons:n,tokens:s,topScore:Math.round(e[0].punkte*100)/100,belege:e[0].belege}}function st(e,t,{minBelege:r=2,topK:n=3,tokenBudget:s=600}={}){if(!Array.isArray(t)||t.length===0)return{...A};if(U(e).length===0)return{...A};const o=new B(t).sortiere(e).filter(i=>i.belege>=r);return o.length===0?{...A}:x(o,n,s)}function Be(e){return ne(e,Me)}async function G(e,t,r,{zeitlimitMs:n=v,fetchFn:s}={}){if(!e?.jwt||!e?.instanceId||r.length===0)return{art:"ohne"};if(["0","off","aus","false"].includes(String(process.env.CACHLY_LESER||"").toLowerCase()))return{art:"ohne"};const o=new se(oe(xe(e.instanceId)));return ie({url:`${e.apiUrl}/api/v1/rerank`,jwt:e.jwt,frage:t,texte:r,instanceId:e.instanceId,zeitlimitMs:n,fetchFn:s},o)}async function ot(e,t,r,n={}){const s=await G(e,t,r,n);return s.art==="punkte"?{scores:s.scores,provider:s.provider,ms:s.ms}:null}async function Y(e,t,r,{minBelege:n,tiefe:s,zeitlimitMs:o,fetchFn:i}){const c={sortiert:[],leser:"aus",leserMs:0};if(!Array.isArray(t)||t.length===0||U(e).length===0)return c;let a=new B(t).sortiere(e).filter(p=>p.belege>=n);if(a.length===0)return c;let l="aus",u=0;if(a.length>1&&s>0){const p=a.slice(0,s),d=a.slice(s),m=await G(r,e,p.map(E=>Be(E.lektion)),{zeitlimitMs:o,fetchFn:i});m.art==="punkte"?(a=[...H(p.map(h=>h.punkte),m.scores,1).map(h=>({...p[h],leser:m.scores[h]})),...d],l=m.provider,u=m.ms):m.art==="uebersprungen"&&(l="uebersprungen")}return{sortiert:a,leser:l,leserMs:u}}async function it(e,t,r,{minBelege:n=2,topK:s=3,tokenBudget:o=600,tiefe:i=K,zeitlimitMs:c=v,fetchFn:a}={}){const l=await Y(e,t,r,{minBelege:n,tiefe:i,zeitlimitMs:c,fetchFn:a});return{...x(l.sortiert,s,o),leser:l.leser,leserMs:l.leserMs}}function Ue(e){if(!e.lessons.length)return"";const t=e.lessons.map(L).join(`
|
|
2
2
|
`);return`\u{1F9E0} Cachly Brain \u2014 relevant lessons for this task (auto-recall, ${e.lessons.length}):
|
|
3
|
-
${
|
|
4
|
-
(ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const ze=5;function lt(e){const t=e.filter(l=>!ee(l)&&te(l));if(!t.length)return"";const r=t.filter(l=>{const
|
|
5
|
-
`),o=n.some(l=>(Number(l.recall_count)||0)>0),i=o?"Top by proven reuse":"Starter tips (not yet from your project)",a=o?
|
|
6
|
-
${
|
|
7
|
-
(Relevant lessons for each task are auto-injected per prompt. ~${
|
|
8
|
-
`)}catch{}return{kontext:N,auswahl:
|
|
3
|
+
${z(t)}
|
|
4
|
+
(ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const ze=5;function lt(e){const t=e.filter(l=>!ee(l)&&te(l));if(!t.length)return"";const r=t.filter(l=>{const u=String(l.topic??"");return!(/^auto:/.test(u)||re(u))}),n=[...r.length?r:t].sort((l,u)=>(Number(u.recall_count)||0)-(Number(l.recall_count)||0)).slice(0,ze),s=n.map(L).join(`
|
|
5
|
+
`),o=n.some(l=>(Number(l.recall_count)||0)>0),i=!o&&n.some(l=>l.source==="brain_from_git"||Array.isArray(l.tags)&&l.tags.includes("git-history")),c=o?"Top by proven reuse":i?"From this project's git history (not reused yet)":"Starter tips (not yet from your project)",a=o?I:i?I.replace("Stored notes from earlier sessions.","Notes drawn from this project's git history."):I.replace("Stored notes from earlier sessions.","General starter notes, not yet from your project.");return`\u{1F9E0} Cachly Brain \u2014 ambient recall active (${t.length} lessons). ${c}:
|
|
6
|
+
${z(s,a)}
|
|
7
|
+
(Relevant lessons for each task are auto-injected per prompt. ~${M(s)} tokens.)`}function at(e,t){return t?JSON.stringify({hookSpecificOutput:{hookEventName:e,additionalContext:t}}):""}function He(e,t){return e.map((r,n)=>({x:r,rang:n,gezeigt:t.includes(r.lektion)})).filter(({rang:r,gezeigt:n})=>r<pe||n).map(({x:r,rang:n,gezeigt:s})=>({thema:String(r.lektion.topic??""),rang:n,punkte:Math.round(r.punkte*1e3)/1e3,belege:r.belege,leser:typeof r.leser=="number"&&Number.isFinite(r.leser)?Math.round(r.leser*1e3)/1e3:null,gezeigt:s}))}async function ct(e,t,{nebenlauf:r,abrufMs:n,leser:s=!0,session:o=null,protokoll:i=!0,ereignis:c="UserPromptSubmit",editor:a="",lernen:l=!0,fetchFn:u}={}){const{lessons:p,quelle:d}=await $e(t,{nebenlauf:r,abrufMs:n,fetchFn:u}),m=de(),E=l&&m.aktiv&&c==="UserPromptSubmit"&&!!t.instanceId,h=E?he({instanceId:t.instanceId,sitzung:o,prompt:e,zaehlung:me(t.instanceId),einstellungen:m}):fe,T=O[h.arm]??O[0],g=await Y(e,p,t,{minBelege:ue,tiefe:s?K:0,zeitlimitMs:v,fetchFn:u}),f={...x(g.sortiert.filter(Z=>Z.belege>=T.minBelege),T.topK,600),leser:g.leser,leserMs:g.leserMs},N=h.kontrolle?"":Ue(f);if(E&&g.sortiert.length>0&&Ee(t.instanceId,o,_e({sitzung:be(o),zug:ye(e),ereignis:c,editor:a,arm:h.arm,kontrolle:h.kontrolle,erkundet:h.erkundet,ausgewaehlt:f.lessons.length,kandidatenZahl:g.sortiert.length,belege:f.belege,topScore:f.topScore,leser:f.leser,leserMs:f.leserMs,quelle:d,bestand:p.length,kandidaten:He(g.sortiert,f.lessons)})),i)try{V(Le,JSON.stringify({at:Date.now(),session:o,prompt_tokens:M(e),injected_tokens:N?f.tokens:0,matches:N?f.lessons.length:0,arm:h.arm,kontrolle:h.kontrolle,ausgewaehlt:f.lessons.length,top_score:f.topScore,belege:f.belege,leser:f.leser,leser_ms:f.leserMs,quelle:d,bestand:p.length})+`
|
|
8
|
+
`)}catch{}return{kontext:N,auswahl:f,quelle:d,bestand:p.length,entscheidung:h}}export{D as ABRUF_TIMEOUT_MS,J as ANZEIGE_ZEICHEN,gt as ARME,Ae as BESTAND_TTL_JUNG_MS,ve as BESTAND_TTL_KLEIN_MS,Se as BESTAND_TTL_MS,Ne as JUNG_ABRUF_MS,P as JUNG_FENSTER_MS,Ie as KLEIN_LEKTIONEN,v as LESER_HOOK_ZEITLIMIT_MS,Me as LESER_MAX_ZEICHEN,K as LESER_TIEFE,Le as NETZ_PROTOKOLL,ze as SITZUNG_TOP_N,ht as belohnungMelden,we as bestandFrist,q as bestandPfad,Ce as ergaenzeUmVorab,M as estimateTokens,$e as holeBestand,at as hookAusgabe,dt as lernEinstellungen,mt as lernenAuffrischen,G as leserAnfrageApi,ot as leserPunkteApi,Be as leserText,H as mischeMitLeser,ct as promptEinblendung,Ue as promptKontext,L as renderLesson,rt as resolveConfig,nt as schreibeVorabBestand,st as selectRelevant,it as selectRelevantMitLeser,xe as sicherungsPfad,lt as sitzungsKontext,Re as starteNebenlauf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=["task-notification","local-command-stdout","local-command-stderr","local-command-caveat","system-reminder"],n=new RegExp(`<(${o.join("|")})>[\\s\\S]*?</\\1>`,"g");function a(t){return String(t??"").replace(n," ").trim()}export{a as frageAusPrompt};
|