@cachly-dev/mcp-server 0.10.257 → 0.10.259
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/README.md +52 -5
- package/dist/src/embeddings.js +4 -4
- package/dist/src/gueltigkeit-version.js +4 -4
- package/dist/src/handlers/brain.js +33 -33
- package/dist/src/herkunft.js +1 -1
- package/dist/src/index.js +178 -178
- package/dist/src/kostprobe.js +3 -3
- package/dist/src/leser.js +1 -1
- package/dist/src/projektdateien.js +6 -6
- package/dist/src/remote-zugang.js +2 -0
- package/dist/src/search.js +1 -1
- package/dist/src/uninstall.js +7 -7
- package/glama.json +1 -1
- package/hooks/cachly-ambient-einblendung.mjs +29 -28
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -29,8 +29,8 @@ Codex CLI · Gemini CLI · JetBrains IDEs
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
The first time cachly needs a key, it opens your browser once: sign in with GitHub, Google or
|
|
32
|
-
e-mail, and your Brain is ready on EU servers. A new account
|
|
33
|
-
|
|
32
|
+
e-mail, and your Brain is ready on EU servers. A new account starts on the Free plan and keeps
|
|
33
|
+
the same key if you upgrade later. Check it with
|
|
34
34
|
`claude mcp list`: you should see `plugin:cachly-brain:cachly … ✔ Connected`.
|
|
35
35
|
|
|
36
36
|
**Cursor, Windsurf, VS Code, Cline, Continue.dev, Zed, Codex CLI, Gemini CLI** — one command:
|
|
@@ -90,6 +90,54 @@ Gemini CLI also follow the server's own instructions; Cline, Continue and Zed re
|
|
|
90
90
|
rule file. You can also add the server by hand (see [Manual Setup](#manual-setup)).
|
|
91
91
|
</details>
|
|
92
92
|
|
|
93
|
+
## Remote MCP (HTTP)
|
|
94
|
+
|
|
95
|
+
`https://mcp.cachly.dev/mcp` opens **your own** Brain. Nothing to install. Send your API key
|
|
96
|
+
(`cky_...`, create one at https://cachly.dev/setup-ai) in the `Authorization` header.
|
|
97
|
+
|
|
98
|
+
**Claude Code**
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
claude mcp add --transport http cachly https://mcp.cachly.dev/mcp --header "Authorization: Bearer <key>"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Cursor** (`~/.cursor/mcp.json`)
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"mcpServers": {
|
|
109
|
+
"cachly": {
|
|
110
|
+
"url": "https://mcp.cachly.dev/mcp",
|
|
111
|
+
"headers": { "Authorization": "Bearer <key>" }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**VS Code** (`.vscode/mcp.json`; the `promptString` input keeps the key out of the file)
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"inputs": [{ "type": "promptString", "id": "cachly-key", "description": "cachly API key", "password": true }],
|
|
122
|
+
"servers": {
|
|
123
|
+
"cachly": {
|
|
124
|
+
"type": "http",
|
|
125
|
+
"url": "https://mcp.cachly.dev/mcp",
|
|
126
|
+
"headers": { "Authorization": "Bearer ${input:cachly-key}" }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- Several Brains in your account, or a key bound to one Brain? Add the header
|
|
133
|
+
`X-Cachly-Instance: <instance id>` (see https://cachly.dev/instances).
|
|
134
|
+
- The server never decides who may see a Brain: the cachly API checks your key on every new
|
|
135
|
+
connection (at least every 10 minutes). A revoked key stops working within 10 minutes.
|
|
136
|
+
- Only the core tools run remotely. `index_project`, `brain_from_git` and `autopilot` read files on
|
|
137
|
+
your machine and run only in the local package (`npx @cachly-dev/mcp-server@latest autopilot`).
|
|
138
|
+
- Without the header the server lists the tools (for directory checks) and answers tool calls with
|
|
139
|
+
these steps.
|
|
140
|
+
|
|
93
141
|
## What it looks like
|
|
94
142
|
|
|
95
143
|
Monday, your AI fixes a bug and keeps what worked (output shortened):
|
|
@@ -417,14 +465,13 @@ Manual snippets are in [Manual Setup](#manual-setup).
|
|
|
417
465
|
|---|---|---|---|---|
|
|
418
466
|
| **Claude Code** | yes | `.mcp.json` | with the plugin | Without a key: the first tool call opens the browser once to sign in |
|
|
419
467
|
| **Cursor** | yes, detected via `.cursor/` | `.cursor/mcp.json`, hooks in `.cursor/hooks.json` | no | Project-level; restart Cursor after setup. Lessons arrive with the first tool call of a turn |
|
|
420
|
-
| **Windsurf** | yes, detected via `.windsurf/` |
|
|
468
|
+
| **Windsurf** | yes, detected via `~/.codeium/windsurf` or `.windsurf/` | `~/.codeium/windsurf/mcp_config.json` | yes | The only file Windsurf reads MCP servers from; restart Windsurf after setup |
|
|
421
469
|
| **VS Code + Copilot** | yes, detected via `.vscode/` | `.vscode/mcp.json`, hooks in `.github/hooks/cachly-ambient.json` | no | Needs the VS Code MCP support or Copilot chat. Briefing at session start, lessons before each prompt |
|
|
422
470
|
| **Codex CLI** | yes, detected via `~/.codex` | `.codex/config.toml` (`[mcp_servers.cachly]`), hooks in `.codex/hooks.json` | no | Codex loads both once you trust the folder; confirm the hook once in `/hooks` |
|
|
423
471
|
| **Gemini CLI** | yes, detected via `~/.gemini` | `mcpServers.cachly` and `hooks` in `.gemini/settings.json` | no | Gemini loads both once you trust the folder. Lessons are appended to the prompt (`BeforeAgent`) |
|
|
424
|
-
| **Cline** | yes, detected via VS Code |
|
|
472
|
+
| **Cline** | yes, detected via Cline's own VS Code storage | `cline_mcp_settings.json` in VS Code's `globalStorage/saoudrizwan.claude-dev/settings/` | yes | Cline does not read `.vscode/mcp.json`; restart VS Code |
|
|
425
473
|
| **Continue.dev** | yes, detected via `.continue/` | `.continue/config.json` | no | Uses the `modelContextProtocolServers` key |
|
|
426
474
|
| **Zed** | yes, detected via `.zed/` | `.zed/settings.json` | no | Uses the `context_servers` key |
|
|
427
|
-
| **Windsurf (global)** | `autosetup --editor windsurf` | `~/.windsurf/mcp.json` | yes | Pass `--editor` to target the global config |
|
|
428
475
|
| **Any other MCP client** | `autosetup --editor claude` | `.mcp.json` | no | Standard `mcpServers` stdio format |
|
|
429
476
|
|
|
430
477
|
**Which sign-in path each case uses:**
|
package/dist/src/embeddings.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import{zeitpunkt as
|
|
1
|
+
import{zeitpunkt as g}from"./zeitmessung.js";import{istMehrmandant as _,mandantKontext as b}from"./remote-zugang.js";const c={apiUrl:process.env.CACHLY_API_URL??"https://api.cachly.dev",jwt:process.env.CACHLY_JWT??"",model:process.env.CACHLY_EMBED_MODEL??""};function h(){return _()?b()?.schluessel??"":c.jwt}function $(){d="cachly"}function j(t){c.jwt=t,t&&!S&&d==="none"&&(d="cachly")}const w=Number(process.env.CACHLY_EMBED_TIMEOUT_MS??8e3),y=Number(process.env.CACHLY_EMBED_TIMEOUT_MAX_MS??45e3),C=12;function M(t,e){return e==="kurz"?w:Math.min(y,w+t.length*C)}function P(){return process.env.CACHLY_JWT?"cachly":process.env.OLLAMA_BASE_URL?"ollama":"none"}const S=!!process.env.CACHLY_EMBED_PROVIDER;let d=(process.env.CACHLY_EMBED_PROVIDER??P()).toLowerCase();async function I(t,e,o){const i=M(t,e);switch(d){case"cachly":{if(!h())throw new Error(`CACHLY_JWT not set.
|
|
2
2
|
|
|
3
3
|
The "cachly" provider uses server-side embeddings via the Cachly API.
|
|
4
4
|
Set CACHLY_JWT, or use another provider via CACHLY_EMBED_PROVIDER:
|
|
5
5
|
openai \u2192 OPENAI_API_KEY
|
|
6
6
|
gemini \u2192 GEMINI_API_KEY
|
|
7
|
-
ollama \u2192 OLLAMA_BASE_URL (local, no key needed)`);const
|
|
7
|
+
ollama \u2192 OLLAMA_BASE_URL (local, no key needed)`);const r=`${c.apiUrl}/api/v1/embed`,s={text:t};(o??c.model)&&(s.model=o??c.model);const n=_()?"":process.env.CACHLY_ADMIN_KEY??"",a=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${h()}`,...n?{"X-Admin-Key":n}:{},"X-Cachly-Embed-Zweck":e==="kurz"?"suche":"schreiben"},body:JSON.stringify(s),signal:AbortSignal.timeout(i)});if(!a.ok){const A=await a.text();let m=null;const p=a.headers.get("retry-after"),E=p===null?NaN:Number(p);if(Number.isFinite(E)&&E>=0)m=E;else try{const u=JSON.parse(A);typeof u.retry_after=="number"&&u.retry_after>=0&&(m=u.retry_after)}catch{}throw Object.assign(new Error(`Cachly embed API error ${a.status}: ${A.slice(0,200)}`),{status:a.status,retryAfterSek:m})}return(await a.json()).embedding}case"mistral":{const r=process.env.MISTRAL_API_KEY;if(!r)throw new Error("MISTRAL_API_KEY not set");const s=c.model!=="text-embedding-3-small"?c.model:"mistral-embed",n=await fetch("https://api.mistral.ai/v1/embeddings",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:s,input:[t]}),signal:AbortSignal.timeout(i)});if(!n.ok)throw new Error(`Mistral embedding error: ${n.statusText}`);const a=await n.json();if(!a.data?.[0]?.embedding)throw new Error("Mistral returned empty embedding response");return a.data[0].embedding}case"cohere":{const r=process.env.COHERE_API_KEY;if(!r)throw new Error("COHERE_API_KEY not set");const s=c.model!=="text-embedding-3-small"?c.model:"embed-english-v3.0",n=await fetch("https://api.cohere.com/v2/embed",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:s,texts:[t],input_type:"search_query",embedding_types:["float"]}),signal:AbortSignal.timeout(i)});if(!n.ok)throw new Error(`Cohere embedding error: ${n.statusText}`);return(await n.json()).embeddings.float[0]}case"ollama":{const r=process.env.OLLAMA_BASE_URL??"http://localhost:11434",s=o??(c.model!=="text-embedding-3-small"?c.model:"nomic-embed-text"),n=await fetch(`${r}/api/embeddings`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,prompt:t}),signal:AbortSignal.timeout(i)});if(!n.ok)throw new Error(`Ollama embedding error: ${n.statusText}`);return(await n.json()).embedding}case"gemini":{const r=process.env.GEMINI_API_KEY;if(!r)throw new Error("GEMINI_API_KEY not set");const s=c.model!=="text-embedding-3-small"?c.model:"text-embedding-004",n=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${s}:embedContent?key=${r}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`models/${s}`,content:{parts:[{text:t}]}}),signal:AbortSignal.timeout(i)});if(!n.ok)throw new Error(`Gemini embedding error: ${n.statusText}`);return(await n.json()).embedding.values}case"openai":{const r=process.env.OPENAI_API_KEY;if(!r)throw new Error(`OPENAI_API_KEY not set.
|
|
8
8
|
|
|
9
9
|
Set OPENAI_API_KEY in your .env, or switch provider:
|
|
10
10
|
CACHLY_EMBED_PROVIDER=gemini (+ GEMINI_API_KEY)
|
|
11
11
|
CACHLY_EMBED_PROVIDER=ollama (local, free)
|
|
12
|
-
CACHLY_EMBED_PROVIDER=cachly (server-side, no key needed)`);const s=
|
|
13
|
-
Supported: cachly (default), openai, mistral, cohere, ollama, gemini`)}}const
|
|
12
|
+
CACHLY_EMBED_PROVIDER=cachly (server-side, no key needed)`);const s=c.model||"text-embedding-3-small",n=await fetch("https://api.openai.com/v1/embeddings",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:s,input:t}),signal:AbortSignal.timeout(i)});if(!n.ok)throw new Error(`OpenAI embedding error: ${n.statusText}`);const a=await n.json();if(!a.data?.[0]?.embedding)throw new Error("OpenAI returned empty embedding response");return a.data[0].embedding}default:throw new Error(`Unknown CACHLY_EMBED_PROVIDER="${d}".
|
|
13
|
+
Supported: cachly (default), openai, mistral, cohere, ollama, gemini`)}}const L=3,O=4;function v(t){const e=t;if(typeof e?.status=="number")return e.status===429||e.status>=500;if(e?.name==="TimeoutError"||e?.name==="AbortError")return!1;if(/fetch failed/i.test(String(e?.message??"")))return!0;const o=e?.cause?.code??"";return["ECONNRESET","ECONNREFUSED","ETIMEDOUT","EAI_AGAIN","EPIPE","UND_ERR_SOCKET"].includes(o)}function R(t,e,o){if(e>=(o==="lang"?O:L)||!v(t))return null;const r=t?.retryAfterSek;if(typeof r=="number"&&Number.isFinite(r)&&r>=0){const s=r*1e3;return o==="kurz"?s<=2e3?s:null:Math.min(s,61e3)}return o==="lang"?Math.min(1e3*2**(e-1),8e3):250*2**(e-1)}const T=Math.max(1,Number(process.env.CACHLY_EMBED_SCHREIB_PARALLEL??4)||4),f=new Map;async function N(t,e){let o=f.get(t);o||(o={laufend:0,warte:[]},f.set(t,o)),o.laufend<T?o.laufend++:await new Promise(i=>o.warte.push(i));try{return await e()}finally{const i=o.warte.shift();i?i():o.laufend--}}function x(t=""){const e=f.get(t);return{laufend:e?.laufend??0,wartend:e?.warte.length??0}}function U(t,e){const i=`${_()?b()?.schluesselHash??"-":""}\0${e?.modell??""}\0${e?.geduld??"kurz"}\0${t}`,r=Date.now(),s=l.get(i);if(s&&s.bis>r)return s.vektor;const n=H(t,e);if(l.set(i,{bis:r+Y,vektor:n}),l.size>k){const a=l.keys().next().value;a!==void 0&&l.delete(a)}return n.catch(()=>{l.get(i)?.vektor===n&&l.delete(i)}),n}const Y=6e4,k=200,l=new Map;function J(){l.clear()}async function H(t,e){const o=e?.geduld??"kurz";if(e?.modell&&d!=="cachly"&&d!=="ollama")throw new Error(`Anbieter "${d}" kann kein abweichendes Modell anfragen (verlangt: ${e.modell}).`);if(t.trim()==="")throw new Error("nothing to embed: empty text");let i=0;for(;;){i++;try{g(`einbettung: Anfang (${t.length} Zeichen, Versuch ${i})`);const r=o==="lang"?await N(e?.modell??"",()=>I(t,o,e?.modell)):await I(t,o,e?.modell);return g("einbettung: fertig"),r}catch(r){const s=R(r,i,o);if(s===null)throw r;await new Promise(n=>setTimeout(n,s))}}}function z(){switch(d){case"cachly":return!!h();case"mistral":return!!process.env.MISTRAL_API_KEY;case"cohere":return!!process.env.COHERE_API_KEY;case"ollama":return!0;case"gemini":return!!process.env.GEMINI_API_KEY;case"openai":return!!process.env.OPENAI_API_KEY;case"none":return!1;default:return!1}}function V(){const t={cachly:"CACHLY_JWT (server-side, no extra key needed)",openai:"OPENAI_API_KEY",mistral:"MISTRAL_API_KEY",cohere:"COHERE_API_KEY",ollama:"OLLAMA_BASE_URL (optional, default: http://localhost:11434)",gemini:"GEMINI_API_KEY"};if(d==="none")return"No embedding provider configured. Sign in (CACHLY_JWT) to use the EU-hosted cachly embeddings, or set OLLAMA_BASE_URL for a local model. Brain works without embedding.";const e=t[d]??"CACHLY_JWT";return`CACHLY_EMBED_PROVIDER=${d} \u2192 requires ${e}`}export{d as EMBED_PROVIDER,U as computeEmbedding,c as embedConfig,h as embedJwt,V as embedProviderHint,$ as erzwingeEmbedAnbieterRemote,z as hasEmbedProvider,v as istVoruebergehend,x as schreibSchlange,j as setEmbedJwt,J as vergissEinbettungen,R as wiederholungMs,M as zeitlimitMs};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createHash as K}from"node:crypto";import{existsSync as Y,readFileSync as T,renameSync as Q,statSync as
|
|
2
|
-
`)){const o=r.replace(/\/\/.*$/,"").trim();if(!o)continue;if(e){o===")"?e=!1:s(o);continue}const i=/^go\s+(\d+(?:\.\d+){0,2})\b/.exec(o);if(i){g(t,"go",{version:i[1],quelle:"go.mod",ab:!0});continue}if(/^require\s*\($/.test(o)){e=!0;continue}const c=/^require\s+(.+)$/.exec(o);c&&s(c[1])}}function Z(n,t,e){if(n.includes("://"))return;const s=n.split("#")[0].split(";")[0].trim(),r=/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*(?:\[[^\]]*\])?\s*(.*)$/.exec(s);if(!r||!r[2])return;const o=r[2].replace(/^\(|\)$/g,"").split(",").map(l=>l.trim()),i=N(r[1]),c=o.map(l=>/^===?\s*(\d+(?:\.\d+){0,2})(?:\.\*)?$/.exec(l)).find(Boolean),u=o.map(l=>/^(?:>=|~=|>)\s*(\d+(?:\.\d+){0,2})/.exec(l)).find(Boolean);c?g(t,i,{version:c[1],quelle:e}):u&&g(t,i,{version:u[1],quelle:e,ab:!0})}function
|
|
3
|
-
`)){const s=e.trim();!s||s.startsWith("#")||s.startsWith("-")||Z(s,t,"requirements.txt")}}function
|
|
4
|
-
`)){const i=o.trim();if(!i||i.startsWith("#"))continue;const c=/^\[\[?([^\]]+)\]\]?$/.exec(i);if(c){e=c[1].trim(),s=!1;continue}if((e==="project"?/^dependencies\s*=\s*\[/.test(i):e==="project.optional-dependencies"||e==="dependency-groups"?/^[\w.-]+\s*=\s*\[/.test(i):!1)||s){for(const l of r(i.replace(/^[\w.-]+\s*=\s*\[/,"")))Z(l,t,"pyproject.toml");s=!i.includes("]");continue}if(e==="project"){const l=/^requires-python\s*=\s*["']([^"']+)["']/.exec(i);l&&_(t,"python",l[1],"pyproject.toml");continue}if(/^tool\.poetry(?:\.group\.[^.]+)?\.(?:dev-)?dependencies$/.test(e)){const l=/^([A-Za-z0-9._-]+)\s*=\s*(.+)$/.exec(i);if(!l)continue;const f=l[2].trim(),p=/^["']/.test(f)?r(f)[0]:/version\s*=\s*["']([^"']+)["']/.exec(f)?.[1];_(t,N(l[1]),p,"pyproject.toml")}}}function X(){return{npm:{},go:{},python:{}}}const b=new Map;function
|
|
1
|
+
import{createHash as K}from"node:crypto";import{existsSync as Y,readFileSync as T,renameSync as Q,statSync as M,writeFileSync as ee}from"node:fs";import{tmpdir as P}from"node:os";import{dirname as $,join as m,resolve as d,sep as te}from"node:path";import{istMehrmandant as ne}from"./remote-zugang.js";const L=120,R=8;function j(n){const t=/^[vV=\s]*(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(String(n??""));return t?[Number(t[1]),Number(t[2]??0),Number(t[3]??0)]:null}function I(n,t){for(let e=0;e<3;e++)if(n[e]!==t[e])return n[e]<t[e]?-1:1;return 0}function x(n,t){return t<=1?[n[0]+1,0,0]:t===2?[n[0],n[1]+1,0]:[n[0],n[1],n[2]+1]}const A="(<=|>=|===|==|!=|~>|~=|<|>|=|~|\\^)",S=new RegExp(`^${A}?[vV]?(\\d+)(?:\\.(\\d+|[xX*]))?(?:\\.(\\d+|[xX*]))?((?:\\.\\d+)*)((?:[-+_.]?[A-Za-z]|[-+])[0-9A-Za-z.+_-]*)?$`),re=new RegExp(`^${A}?(\\*|[xX])$`);function w(n,t,e){const s=u=>u!==void 0&&/^\d+$/.test(u)?Number(u):null,r=Number(n),o=s(t),i=o===null?null:s(e);return{t:[r,o??0,i??0],n:o===null?1:i===null?2:3}}function se(n){const t=re.exec(n);if(t)return t[1]&&t[1]!=="="&&t[1]!=="=="?null:{};const e=S.exec(n);if(!e||/[xX*]/.test(`${e[3]??""}${e[4]??""}`)&&(e[5]||e[6]))return null;const s=e[1]??"",{t:r,n:o}=w(e[2],e[3],e[4]);switch(s){case"":case"=":case"==":case"===":return{von:r,bis:x(r,o)};case"!=":return{von:r,bis:x(r,o),nicht:!0};case"<":return{bis:r};case"<=":return{bis:x(r,o)};case">":return{von:x(r,o)};case">=":return{von:r};case"^":return r[0]>0?{von:r,bis:[r[0]+1,0,0]}:o===1?{von:r,bis:[1,0,0]}:r[1]>0?{von:r,bis:[0,r[1]+1,0]}:o===2?{von:r,bis:[0,1,0]}:{von:r,bis:[0,0,r[2]+1]};case"~":return{von:r,bis:o===1?[r[0]+1,0,0]:[r[0],r[1]+1,0]};case"~>":case"~=":return{von:r,bis:o===3?[r[0],r[1]+1,0]:[r[0]+1,0,0]};default:return null}}function oe(n){if(!n)return null;const t=/^(\S+)\s+-\s+(\S+)$/.exec(n);if(t){const o=S.exec(t[1]),i=S.exec(t[2]);if(!o||!i||o[1]||i[1])return null;const c=w(o[2],o[3],o[4]),u=w(i[2],i[3],i[4]);return[{von:c.t,bis:x(u.t,u.n)}]}const s=n.replace(/,/g," ").replace(new RegExp(`${A}\\s+`,"g"),"$1").trim().split(/\s+/);if(s.length>8)return null;const r=[];for(const o of s){const i=se(o);if(!i)return null;r.push(i)}return r}function D(n){if(typeof n!="string")return null;const t=n.trim();if(!t||t.length>L)return null;const e=[];for(const s of t.split("||")){const r=oe(s.trim());if(!r)return null;e.push(r)}return e}function ie(n,t){let e=!0;return t.von&&I(n,t.von)<0&&(e=!1),t.bis&&I(n,t.bis)>=0&&(e=!1),t.nicht?!e:e}function ce(n,t){const e=j(n),s=D(t);return!e||!s?null:s.some(r=>r.every(o=>ie(e,o)))}const ue={npm:"npm",go:"go",python:"python",pypi:"python",pip:"python"};function F(n){if(typeof n!="string")return{fehler:"keine Zeichenkette"};const t=n.replace(/\s+/g," ").trim();if(!t)return{fehler:"leer"};if(t.length>L+80)return{fehler:"zu lang"};let e=t,s=null;const r=/^(npm|go|python|pypi|pip):/i.exec(e);r&&(s=ue[r[1].toLowerCase()],e=e.slice(r[0].length));const o=e.indexOf("@",1);if(o<0)return{fehler:'es fehlt "@bereich" (Form: paket@bereich)'};const i=e.slice(0,o).trim(),c=e.slice(o+1).trim();return!i||!/^[@A-Za-z0-9._~/+-]+$/.test(i)?{fehler:"Paketname unlesbar"}:D(c)?{angabe:{text:t,oekosystem:s,paket:i,bereichText:c}}:{fehler:`Bereich "${c.slice(0,40)}" unlesbar`}}function q(n){const t=Array.isArray(n)?n:n==null?[]:[n],e=[],s=[];for(const r of t){const o=F(r);"fehler"in o?s.push(`"${String(r).slice(0,60)}": ${o.fehler}`):e.includes(o.angabe.text)||(e.length>=R?s.push(`"${o.angabe.text.slice(0,60)}": mehr als ${R} Angaben`):e.push(o.angabe.text))}return{angaben:e,fehler:s}}function Ve(n,t){if(n==null){const e=Array.isArray(t)?q(t).angaben:[];return{angaben:e,fehler:[],uebernommen:e.length>0}}return{...q(n),uebernommen:!1}}const y=["package.json","go.mod","pyproject.toml","requirements.txt","package-lock.json"],le={"package.json":1<<20,"go.mod":1<<19,"pyproject.toml":1<<19,"requirements.txt":1<<19,"package-lock.json":3<<20},ae=25,fe=600*1e3,pe=4e3,C=new WeakMap;function g(n,t,e,s=!1){if(t==="__proto__")return;const r=Object.hasOwn(n,t);if(!(r&&!s)){if(!r){const o=C.get(n)??0;if(o>=pe)return;C.set(n,o+1)}n[t]=e}}function E(n,t){return Object.hasOwn(n,t)?n[t]:null}function G(n,t){try{const e=M(n,{throwIfNoEntry:!1});return!e||!e.isFile()||e.size>t?null:T(n,"utf8").replace(/^\uFEFF/,"")}catch{return null}}function N(n){return n.toLowerCase().replace(/[-_.]+/g,"-")}function he(n){if(typeof n!="string")return null;const t=n.trim();if(!t||t.includes("||")||/[xX*]$/.test(t))return null;const e=/^(?:===?|=)?\s*v?(\d+(?:\.\d+){0,2})(?:[-+.]?[0-9A-Za-z.+_-]*)?$/.exec(t);if(e)return{version:e[1],ab:!1};const s=/(?:\^|~>|~=|~|>=|>)\s*v?(\d+(?:\.\d+){0,2})/.exec(t);return s?{version:s[1],ab:!0}:null}function _(n,t,e,s){const r=he(e);r&&g(n,t,{version:r.version,quelle:s,...r.ab?{ab:!0}:{}})}function de(n,t){let e;try{e=JSON.parse(n)}catch{return}if(!(!e||typeof e!="object"))for(const s of["dependencies","devDependencies","optionalDependencies"]){const r=e[s];if(!(!r||typeof r!="object"))for(const[o,i]of Object.entries(r))_(t,o.toLowerCase(),i,"package.json")}}function ge(n,t){let e;try{e=JSON.parse(n)}catch{return}if(!e||typeof e!="object")return;const s=(r,o)=>{typeof o!="string"||!j(o)||g(t,r.toLowerCase(),{version:o,quelle:"package-lock.json"},!0)};if(e.packages&&typeof e.packages=="object")for(const[r,o]of Object.entries(e.packages))!r.startsWith("node_modules/")||r.indexOf("node_modules/",13)>=0||s(r.slice(13),o?.version);else if(e.dependencies&&typeof e.dependencies=="object")for(const[r,o]of Object.entries(e.dependencies))s(r,o?.version)}function be(n,t){let e=!1;const s=r=>{const o=/^(\S+)\s+(v\d\S*)/.exec(r);o&&g(t,o[1],{version:o[2].replace(/^v/,""),quelle:"go.mod"})};for(const r of n.split(`
|
|
2
|
+
`)){const o=r.replace(/\/\/.*$/,"").trim();if(!o)continue;if(e){o===")"?e=!1:s(o);continue}const i=/^go\s+(\d+(?:\.\d+){0,2})\b/.exec(o);if(i){g(t,"go",{version:i[1],quelle:"go.mod",ab:!0});continue}if(/^require\s*\($/.test(o)){e=!0;continue}const c=/^require\s+(.+)$/.exec(o);c&&s(c[1])}}function Z(n,t,e){if(n.includes("://"))return;const s=n.split("#")[0].split(";")[0].trim(),r=/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*(?:\[[^\]]*\])?\s*(.*)$/.exec(s);if(!r||!r[2])return;const o=r[2].replace(/^\(|\)$/g,"").split(",").map(l=>l.trim()),i=N(r[1]),c=o.map(l=>/^===?\s*(\d+(?:\.\d+){0,2})(?:\.\*)?$/.exec(l)).find(Boolean),u=o.map(l=>/^(?:>=|~=|>)\s*(\d+(?:\.\d+){0,2})/.exec(l)).find(Boolean);c?g(t,i,{version:c[1],quelle:e}):u&&g(t,i,{version:u[1],quelle:e,ab:!0})}function me(n,t){for(const e of n.split(`
|
|
3
|
+
`)){const s=e.trim();!s||s.startsWith("#")||s.startsWith("-")||Z(s,t,"requirements.txt")}}function xe(n,t){let e="",s=!1;const r=o=>[...o.matchAll(/"([^"]+)"|'([^']+)'/g)].map(i=>i[1]??i[2]);for(const o of n.split(`
|
|
4
|
+
`)){const i=o.trim();if(!i||i.startsWith("#"))continue;const c=/^\[\[?([^\]]+)\]\]?$/.exec(i);if(c){e=c[1].trim(),s=!1;continue}if((e==="project"?/^dependencies\s*=\s*\[/.test(i):e==="project.optional-dependencies"||e==="dependency-groups"?/^[\w.-]+\s*=\s*\[/.test(i):!1)||s){for(const l of r(i.replace(/^[\w.-]+\s*=\s*\[/,"")))Z(l,t,"pyproject.toml");s=!i.includes("]");continue}if(e==="project"){const l=/^requires-python\s*=\s*["']([^"']+)["']/.exec(i);l&&_(t,"python",l[1],"pyproject.toml");continue}if(/^tool\.poetry(?:\.group\.[^.]+)?\.(?:dev-)?dependencies$/.test(e)){const l=/^([A-Za-z0-9._-]+)\s*=\s*(.+)$/.exec(i);if(!l)continue;const f=l[2].trim(),p=/^["']/.test(f)?r(f)[0]:/version\s*=\s*["']([^"']+)["']/.exec(f)?.[1];_(t,N(l[1]),p,"pyproject.toml")}}}function X(){return{npm:{},go:{},python:{}}}const b=new Map;function ye(n){const t={};for(const e of y)try{const s=M(m(n,e),{throwIfNoEntry:!1});t[e]=s?`${Math.round(s.mtimeMs)}:${s.size}`:"-"}catch{t[e]="-"}return t}function ve(n,t){return y.every(e=>n[e]===t[e])}function O(n,t){return m(n,`cachly-projektversionen-${K("sha1").update(t).digest("hex").slice(0,12)}.json`)}function ke(n,t){try{const e=JSON.parse(T(n,"utf8"));return e&&e.v===1&&e.ordner===t&&e.stand&&e.stempel?e:null}catch{return null}}function $e(n,t){try{const e=`${n}.${process.pid}.tmp`;ee(e,JSON.stringify(t),{mode:384}),Q(e,n)}catch{}}function je(n,t,e){const s=X(),r=e();let o=!1,i=!0;for(const c of y){if(!i&&e()-r>t){o=!0;break}const u=G(m(n,c),le[c]);if(u!==null)switch(i=!1,c){case"package.json":de(u,s.npm);break;case"package-lock.json":ge(u,s.npm);break;case"go.mod":be(u,s.go);break;case"pyproject.toml":xe(u,s.python);break;case"requirements.txt":me(u,s.python);break}}return{stand:s,unvollstaendig:o}}function Ae(n,t){if(!/^[@a-z0-9._~/-]+$/.test(t)||t.includes(".."))return null;let e=n;for(let s=0;s<4;s++){const r=G(m(e,"node_modules",t,"package.json"),262144);if(r!==null){try{const i=JSON.parse(r).version;if(typeof i=="string"&&j(i))return{version:i,quelle:"node_modules"}}catch{}return null}const o=$(e);if(o===e)break;e=o}return null}function Se(n,t){let e=d(n);const s=t?d(t):null;for(let r=0;s&&r<6;r++){if(y.some(i=>Y(m(e,i))))return e;if(e===s)break;const o=$(e);if(o===e)break;e=o}return d(n)}function B(){return process.env.CACHLY_WORKSPACE||process.env.CLAUDE_PROJECT_DIR||process.cwd()}function v(n=B(),t={}){if(ne())return{ordner:"",herkunft:"gebaut",unvollstaendig:!0,suche:()=>null};const e=Se(n,t.obergrenze),s=t.jetzt??(()=>performance.now()),r=t.ablageOrdner===void 0?P():t.ablageOrdner;let o="gebaut",i=X(),c=!1;try{const f=ye(e),p=a=>!!a&&ve(a.stempel,f)&&(!a.unvollstaendig||Date.now()-a.at<fe),h=b.get(e);if(p(h))({stand:i,unvollstaendig:c}=h),o="speicher";else{const a=r===null?null:ke(O(r,e),e);if(p(a))b.set(e,a),{stand:i,unvollstaendig:c}=a,o="platte";else{({stand:i,unvollstaendig:c}=je(e,t.budgetMs??ae,s));const V={v:1,ordner:e,stempel:f,stand:i,unvollstaendig:c,at:Date.now()};b.size>20&&b.clear(),b.set(e,V),r!==null&&$e(O(r,e),V)}}}catch{}const u=new Map;return{ordner:e,herkunft:o,unvollstaendig:c,suche:(f,p)=>{const h=`${f??"*"}:${p}`;if(u.has(h))return u.get(h)??null;let a=null;if(f===null||f==="npm"){const k=p.toLowerCase();a=Ae(e,k)??E(i.npm,k)}return!a&&(f===null||f==="python")&&(a=E(i.python,N(p))),!a&&(f===null||f==="go")&&(a=E(i.go,p)),u.set(h,a),a}}}function Te(n,t=P()){return O(t,d(n))}function Me(){b.clear()}function J(n){return n.ab?`ab ${n.version} laut ${n.quelle}`:n.version}function z(n){return Array.isArray(n)?n:typeof n=="string"&&n.trim()?[n]:[]}function W(n){return z(n).length>0}function H(n,t){const e=[],s=[];for(const r of z(n)){const o=F(r);if("fehler"in o)continue;const i=o.angabe,c=t.suche(i.oekosystem,i.paket);if(!c)continue;const u=ce(c.version,i.bereichText);u!==null&&(u?s.push({angabe:i.text,paket:i.paket,hier:J(c)}):e.push({angabe:i.text,hier:J(c)}))}return e.length>0?{art:"passtNicht",abweichungen:e,text:e.map(r=>`gilt fuer ${r.angabe}, hier ${r.hier}`).join("; ")}:s.length>0?{art:"passt",geprueft:s}:{art:"unbekannt"}}function U(n,t){const e=new Map,s=[],r=[];let o=null,i=!1;for(const c of n){const u=t.giltFuerVon(c);if(!W(u)){s.push(c);continue}if(!o&&!i)try{o=(t.leser??(()=>v()))()}catch{i=!0}const l=o?H(u,o):{art:"unbekannt"};l.art==="passtNicht"?(e.set(t.schluesselVon(c),l.text),r.push(c)):s.push(c)}return{treffer:r.length>0?[...s,...r]:[...s],hinweise:e}}function we(n){const t=d(B()),e=n.find(s=>typeof s=="string"&&s.length>0);if(e){const s=$(d(t,e));if(s===t||s.startsWith(t+te))return{start:s,obergrenze:t}}return{start:t}}function Pe(n,t=[],e={}){const s="cachly:lesson:best:",r=U(n,{giltFuerVon:o=>{if(!(!o.key.startsWith(s)||typeof o.content!="string"||!o.content.includes('"gilt_fuer"')))try{return JSON.parse(o.content).gilt_fuer}catch{return}},schluesselVon:o=>o.key,leser:()=>{const o=we(t);return v(o.start,{obergrenze:o.obergrenze,...e})}});return r.hinweise.size>0&&n.splice(0,n.length,...r.treffer),r.hinweise}function Le(n,t){const e=[];for(const s of n){const r=t.get(s.key);r&&e.push(`\u26A0\uFE0F \`${s.key.replace("cachly:lesson:best:","")}\` ${r} \u2014 passt nicht zu den Versionen dieses Projekts, steht deshalb hinter den passenden Treffern.`)}return e}function Re(n,t={}){if(!W(n))return"";let e;try{e=H(n,t.leser??v(void 0,t))}catch{e={art:"unbekannt"}}const s=z(n).filter(r=>typeof r=="string").join(", ");return e.art==="passtNicht"?`\u26A0\uFE0F **GILT NICHT FUER DIESEN STAND** \u2014 ${e.text}. Der Text unten bleibt lesbar, ist fuer diese Version aber nicht gesichert.`:e.art==="passt"?`\u{1F4E6} Gilt fuer ${s} \u2014 passt zu diesem Projekt (${e.geprueft.map(r=>`${r.paket} ${r.hier}`).join(", ")}).`:`\u{1F4E6} Gilt fuer ${s} \u2014 die Version in diesem Projekt ist nicht bekannt.`}function Ie(n,t={}){const e=U(n,{giltFuerVon:s=>s.lektion.gilt_fuer,schluesselVon:s=>String(s.lektion.topic??""),leser:t.leser??(()=>v(void 0,t))});return e.hinweise.size===0?n:e.treffer.map(s=>{const r=e.hinweise.get(String(s.lektion.topic??""));return r?{...s,lektion:{...s.lektion,versionshinweis:r}}:s})}export{L as BEREICH_MAX_ZEICHEN,R as GILT_FUER_MAX,ae as LESE_BUDGET_MS,fe as UNVOLLSTAENDIG_MS,Te as ablageDatei,B as arbeitsordner,H as beurteileGiltFuer,Se as findeProjektOrdner,Me as leereVersionsSpeicher,v as leseProjektVersionen,F as liesAngabe,D as liesBereich,j as liesVersion,Ve as loeseGiltFuerAuf,ce as passtVersion,q as pruefeGiltFuer,Ie as stufeEinblendungNachVersion,U as stufeNachVersion,Pe as stufeSucheNachProjektversion,W as traegtGiltFuer,Re as versionsBanner,Le as versionsNotizen};
|