@cachly-dev/mcp-server 0.10.265 → 0.10.266

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,4 +1,4 @@
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}
1
+ import{readFileSync as B}from"node:fs";import{tmpdir as O}from"node:os";import{parseHookPayload as L,runEinblendung as Y,stopLernanfrage as $,stopObservation as D}from"./ambient-cli.js";import{stopAntwort as J}from"./schreibbeleg.js";import{lernRueckfrage as V,lernaufrufImProtokollEnde as Q,frageIstFrisch as W,meldeAutoLernen as X}from"./lern-rueckfrage.js";import{holeBestand as q,hookAusgabe as Z,starteNebenlauf as P}from"./einblendung.js";import{STARTWISSEN_IMPORT as m,hookImportFuerAuftrag as ee,importiereStartwissen as te}from"./startwissen-hook.js";import{belohnungMelden as ne}from"./lernen.js";import{appendLedgerEntry as re,reportLedgerEntry as oe}from"./ambient-ledger.js";import{copilotHatHook as ie,cursorHatHook as se,findeInstanz as w,findeSchluessel as _,hookUmfeld as k,pluginVersion as F,projektHatHook as ce}from"./hook-zugang.js";import{ABKUEHLUNG_HOOK_MS as ae,schreibeAuftrag as T,sichereKonto as ue,startwissenEingeschaltet as E}from"./konto-anlegen.js";import{istInstanzKennung as z,sofortTestHinweis as le}from"./zugang.js";import{CURSOR_FLAG as h,cursorEreignis as j,cursorHookAntwort as fe,cursorLeer as de,istCursorNutzlast as x}from"./cursor-hook.js";import{COPILOT_FLAG as I,copilotEreignis as pe,copilotHookAntwort as me,istFremdeLaufzeit as C}from"./copilot-hook.js";import{CODEX_FLAG as K,codexHookAntwort as he}from"./codex-hook.js";import{GEMINI_FLAG as b,geminiEreignis as ge,geminiHookAntwort as Se}from"./gemini-hook.js";const we="https://api.cachly.dev",N=5e3,_e="ambient-auffrischen",R=new Set(["SessionStart","UserPromptSubmit","PreToolUse","Stop"]);async function ke(e,t){if(!e.args.includes(h)&&(j(t,e.args)!=="sessionStart"||se(e.umfeld)))return"";const o=e.args.filter(r=>r==="--plugin");return fe({payload:t,args:e.args,claudeLauf:(r,s)=>A({...e,raw:r,args:[s,...o]}),ablageOrdner:e.cursorAblage})}function Ie(e,t){const n=(o,r)=>A({...e,raw:o,args:[r]});return e.args.includes(I)?me({payload:t,args:e.args,claudeLauf:n,ablageOrdner:e.copilotAblage}):e.args.includes(K)?he({payload:t,args:e.args,claudeLauf:n}):e.args.includes(b)?Se({payload:t,args:e.args,claudeLauf:n}):null}function be(e,t){return e.includes(h)||x(t)?"cursor":e.includes(I)?"copilot":e.includes(K)?"codex":e.includes(b)?"gemini":C(t)?"vscode":"claude"}async function Ae(e){const t=await ue({apiUrl:e.apiUrl,version:F(e.umfeld),home:e.umfeld.heim,env:{...e.umfeld.env,CACHLY_QUELLE:"claude-code-plugin"},fristMs:N,anfrageMs:N,abkuehlungMs:ae,holen:e.fetchFn});if(t.art==="vorhanden")return{apiKey:t.apiKey,instanzId:t.instanzId,hinweis:""};if(t.art!=="angelegt")return null;if(E(e.umfeld.env)){const n={apiUrl:e.apiUrl,jwt:t.test.apiKey,instanceId:t.test.instanzId};e.selbst&&(e.nebenlauf??P)(n,[e.selbst,m,e.umfeld.projekt],{zweck:m,ordner:O()})||T({instanzId:t.test.instanzId,projekt:e.umfeld.projekt},{home:e.umfeld.heim})}return{apiKey:t.test.apiKey,instanzId:t.test.instanzId,hinweis:le(t.test)}}function He(e,t){const n=t.replace(/^\s+/,"");if(!e)return Z("SessionStart",n);try{const o=JSON.parse(e),r=o.hookSpecificOutput?.additionalContext;return!o.hookSpecificOutput||typeof r!="string"?e:(o.hookSpecificOutput.additionalContext=`${n}
2
2
 
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};
3
+ ${r}`,JSON.stringify(o))}catch{return e}}async function A(e){try{const t=L(e.raw),n={...e,editor:e.editor??be(e.args,t)};if(n.args.includes(h)||x(t))return await ke(n,t);const o=Ie(n,t);if(o)return await o;const r=t?.hook_event_name??n.args.find(i=>R.has(i))??n.umfeld.env.CACHLY_HOOK_EVENT??"";if(C(t)&&(r!=="SessionStart"&&r!=="UserPromptSubmit"||ie(n.umfeld))||n.args.includes("--plugin")&&r&&ce(r,n.umfeld))return"";let s=null;if(r==="Stop"&&t?.transcript_path)try{s=B(t.transcript_path,"utf-8").split(`
4
+ `);const i=J(s,t.stop_hook_active===!0);if(i)return i}catch{}let l=_(n.umfeld),u=w(n.umfeld),c="";if(!l&&r==="SessionStart"&&n.args.includes("--plugin")&&!z(u)){const i=await Ae(n);i&&(l=i.apiKey,u=i.instanzId??u,c=i.hinweis)}if(!l||!u)return"";const a={apiUrl:n.apiUrl,jwt:l,instanceId:u};if(r==="Stop"){const i=t?.stop_hook_active===!0,d=p=>X(p,{apiUrl:a.apiUrl,jwt:a.jwt,instanceId:a.instanceId,version:F(n.umfeld),env:n.umfeld.env,fetchFn:n.fetchFn}),f=ne(a,t?.session_id??null,s,{fetchFn:n.fetchFn}),y=n.editor==="claude"&&s?V({zeilen:s,sessionId:t?.session_id??null,stopHookAktiv:i,heim:n.umfeld.heim,env:n.umfeld.env}):null;if(y)return await Promise.all([f,d("auto_learn_asked")]),y;const M=!!s&&(Q(s)||i&&W(n.umfeld.heim,t?.session_id??"")),U=t&&!M?D(t):null,G=U?(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($(U)),signal:AbortSignal.timeout(8e3)}).then(p=>p&&p.ok?d("auto_learn_saved"):void 0).catch(()=>{}):void 0;return await Promise.all([G,f]),""}let g;const S=await(n.einblenden??Y)(n.raw,{cfg:a,nebenlauf:n.selbst?[n.selbst,_e]:void 0,editor:n.editor,fetchFn:n.fetchFn,onInject:(i,d)=>{const f={ts:new Date().toISOString(),event:d,injected:i,prevented:0,instanz:a.instanceId};re(f),g=oe(a,f,n.fetchFn)}});return g&&await Promise.race([g,new Promise(i=>setTimeout(i,500))]),r==="SessionStart"&&!S&&!c&&n.selbst&&E(n.umfeld.env)&&(n.nebenlauf??P)(a,[n.selbst,m,n.umfeld.projekt],{zweck:m,ordner:O()}),c?He(S,c):S}catch{return""}}async function ve(){if(process.stdin.isTTY)return"";const e=[];for await(const t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}function H(){return process.env.CACHLY_API_URL||we}const v={SessionStart:25e3,UserPromptSubmit:8e3,PreToolUse:8e3,Stop:5e4,sessionStart:25e3,beforeSubmitPrompt:8e3,postToolUse:3e3,userPromptSubmitted:8e3,PostToolUse:3e3,BeforeAgent:8e3};function ye(e,t){return e.includes(h)?de(j(t,e)):e.includes(I)?pe(t,e)?"{}":"":e.includes(b)&&ge(t,e)?"{}":""}async function Be(e,t){try{const n=await ve(),o=L(n),r=o?.hook_event_name??e.find(c=>R.has(c)||Object.hasOwn(v,c))??"",s=Number(process.env.CACHLY_HOOK_FRIST_MS)||v[r]||v.UserPromptSubmit,l=ye(e,o),u=await Promise.race([A({args:e,raw:n,umfeld:k(),apiUrl:H(),selbst:t}),new Promise(c=>setTimeout(()=>c(l),s))]);u&&await new Promise(c=>process.stdout.write(u,()=>c()))}catch{}process.exit(0)}async function Ye(){try{const e=k(),t=_(e),n=w(e);t&&n&&await q({apiUrl:H(),jwt:t,instanceId:n},{force:!0,lernen:!0})}catch{}process.exit(0)}async function $e(e){try{const t=k(),n=_(t),o=w(t);if(n&&z(o)){const r=await te({cfg:{apiUrl:H(),jwt:n,instanceId:o},projekt:e,env:t.env});r.art!=="aus"&&T({instanzId:o,projekt:e,vomHook:ee(r)},{home:t.heim})}}catch{}process.exit(0)}export{_e as AUFFRISCHEN,v as HOOK_FRIST_MS,N as KONTO_FRIST_MS,we as STANDARD_API_URL,Ye as auffrischenHauptlauf,be as editorVon,A as hookAntwort,Be as hookHauptlauf,$e as startwissenImportHauptlauf};