@cachly-dev/mcp-server 0.10.253 → 0.10.255
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 +16 -11
- package/dist/src/index.js +47 -47
- package/glama.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
> Every fix, decision and dead end becomes a lesson. Your AI finds it again when the same
|
|
6
6
|
> problem comes back, in the next session, in another editor, or on a teammate's machine.
|
|
7
7
|
|
|
8
|
+
**#1 on LoCoMo in the OmniMemEval comparison, 90.71 points**
|
|
9
|
+
([results](https://github.com/MemTensor/OmniMemEval/blob/main/docs/user_memory/results.md#locomo)).
|
|
10
|
+
|
|
8
11
|
[](https://www.npmjs.com/package/@cachly-dev/mcp-server)
|
|
9
12
|
[](./LICENSE)
|
|
10
13
|
[](https://registry.modelcontextprotocol.io/v0/servers?search=cachly)
|
|
@@ -25,8 +28,9 @@ Codex CLI · Gemini CLI · JetBrains IDEs
|
|
|
25
28
|
/plugin install cachly-brain@cachly
|
|
26
29
|
```
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
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 comes with 14 days of the Solo plan
|
|
33
|
+
and then continues on Free with the same key. Check it with
|
|
30
34
|
`claude mcp list`: you should see `plugin:cachly-brain:cachly … ✔ Connected`.
|
|
31
35
|
|
|
32
36
|
**Cursor, Windsurf, VS Code, Cline, Continue.dev, Zed, Codex CLI, Gemini CLI** — one command:
|
|
@@ -51,11 +55,11 @@ creates your Brain on first start. The [JetBrains plugin](https://plugins.jetbra
|
|
|
51
55
|
brings it to IntelliJ IDEA, PyCharm, GoLand, WebStorm and Rider
|
|
52
56
|
([guide](https://cachly.dev/docs/jetbrains)).
|
|
53
57
|
|
|
54
|
-
**
|
|
55
|
-
and the Brain moves into your account with all its lessons.
|
|
58
|
+
**Already have a test Brain?** Keep it with `npx @cachly-dev/mcp-server@latest claim`. You sign in
|
|
59
|
+
once, and the Brain moves into your account with all its lessons.
|
|
56
60
|
|
|
57
61
|
<details>
|
|
58
|
-
<summary><b>Claude Code in detail:</b> the three hooks, auto-update, and the
|
|
62
|
+
<summary><b>Claude Code in detail:</b> the three hooks, auto-update, and the sign-in</summary>
|
|
59
63
|
|
|
60
64
|
The plugin adds three Claude Code hooks:
|
|
61
65
|
|
|
@@ -70,8 +74,8 @@ Claude Code leaves it off for marketplaces outside Anthropic's own. The MCP serv
|
|
|
70
74
|
itself on every start; the hooks come with the plugin and update with it. If an update is
|
|
71
75
|
waiting, the first `session_start` of a session says so in one line.
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
Without a key, the first tool call opens your browser once to sign in (GitHub, Google or
|
|
78
|
+
e-mail). `claude mcp list` is the reliable check: `claude plugin details`
|
|
75
79
|
shows `MCP servers (0)` even while the server runs.
|
|
76
80
|
|
|
77
81
|
`claim` revokes every test key and stores a new key where your editor and hooks look for
|
|
@@ -411,7 +415,7 @@ Manual snippets are in [Manual Setup](#manual-setup).
|
|
|
411
415
|
|
|
412
416
|
| Editor / client | Auto-setup | Config file written | Global config | Notes |
|
|
413
417
|
|---|---|---|---|---|
|
|
414
|
-
| **Claude Code** | yes | `.mcp.json` | with the plugin | Without a key:
|
|
418
|
+
| **Claude Code** | yes | `.mcp.json` | with the plugin | Without a key: the first tool call opens the browser once to sign in |
|
|
415
419
|
| **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 |
|
|
416
420
|
| **Windsurf** | yes, detected via `.windsurf/` | `.windsurf/mcp.json` | no | Project-level; restart Windsurf after setup |
|
|
417
421
|
| **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 |
|
|
@@ -429,7 +433,7 @@ Manual snippets are in [Manual Setup](#manual-setup).
|
|
|
429
433
|
|---|---|
|
|
430
434
|
| `autosetup` or `autopilot` from a terminal (TTY) | OAuth device flow: one click in the browser, the API key is saved automatically |
|
|
431
435
|
| `autosetup` from a VS Code task or CI (no TTY) | Detects the non-interactive run, opens the browser with a step-by-step guide, prints the `CACHLY_JWT=... autosetup` command |
|
|
432
|
-
| First tool call without any key |
|
|
436
|
+
| First tool call without any key | Inline device flow: the browser opens once with a URL and a code; sign in with GitHub, Google or e-mail. The key is saved to `~/.cachly/credentials.json` |
|
|
433
437
|
| First tool call with `CACHLY_BRAIN_INSTANCE_ID` set but no key | Inline device flow. You already have a Brain, so no second account is created |
|
|
434
438
|
| `CACHLY_JWT=cky_live_xxx npx ... autosetup` | Skips the sign-in step and uses the key you pass |
|
|
435
439
|
|
|
@@ -455,8 +459,9 @@ For all your projects at once, use the plugin above, or
|
|
|
455
459
|
`claude mcp add -s user cachly -- npx -y @cachly-dev/mcp-server@latest`
|
|
456
460
|
(Claude Code stores that in `~/.claude.json`).
|
|
457
461
|
|
|
458
|
-
Without a key, the first tool call
|
|
459
|
-
|
|
462
|
+
Without a key, the first tool call opens your browser once to sign in (GitHub, Google or
|
|
463
|
+
e-mail). Or run `npx @cachly-dev/mcp-server@latest autopilot` first: it signs you in and
|
|
464
|
+
writes the config for every editor it finds.
|
|
460
465
|
</details>
|
|
461
466
|
|
|
462
467
|
<details>
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{setzeClientKennung as Wt}from"./herkunft.js";import{jwtExpiryMs as Jt,checkJwt as Ft,handleApiError as Yt,diagnoseAuth as Ie,planAuthHeal as We,readClientCredentialsFromEnv as Kt,buildClientCredentialsBody as qt,clientCredentialsTokenUrl as Gt}from"./auth.js";import{cachlyUrl as j}from"./cachly-url.js";import{nutzungsSchluessel as Vt}from"./werkzeug-nutzung.js";import{istLieferung as Zt,lieferSchluessel as Qt,tokenDerAntwort as Xt,hatTreffer as eo,trefferSchluessel as Je}from"./geliefert.js";import{notify as Fe}from"./notifier.js";import{fileURLToPath as Ye}from"node:url";import{createRequire as to}from"node:module";import{execFile as Ee}from"node:child_process";const oo=process.argv[1]!=null&&(process.argv[1]===Ye(import.meta.url)||process.argv[1].endsWith("/dist/index.js")||process.argv[1].endsWith("/src/index.ts"));import{Server as Ke}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as no}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as so}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{CallToolRequestSchema as qe,ErrorCode as ne,ListPromptsRequestSchema as Ge,ListResourceTemplatesRequestSchema as Ve,ListResourcesRequestSchema as Ze,ListToolsRequestSchema as Qe,McpError as Q}from"@modelcontextprotocol/sdk/types.js";import{Redis as Xe}from"ioredis";let x=process.env.CACHLY_API_URL??"https://api.cachly.dev",S=Oe()??"";ae(S);const ti=process.env.CACHLY_EMBED_MODEL??"",H=(()=>{try{const e=to(import.meta.url);for(const t of["../../package.json","../package.json"])try{const n=e(t);if(n.name==="@cachly-dev/mcp-server"&&n.version)return n.version}catch{}}catch{}return"0.10.100"})(),io=Number(process.env.CACHLY_PROVISION_TIMEOUT_MS??9e4);let N=$e(process.env.CACHLY_BRAIN_INSTANCE_ID);function G(){return S||Oe()||""}function z(){return $e(process.env.CACHLY_BRAIN_INSTANCE_ID)||_e()||""}let V=0,pe=null,et=!1;async function tt(){let e=[];try{K.getClientCapabilities()?.roots&&(e=(await K.listRoots(void 0,{timeout:3e3})).roots)}catch{}return Gn({wurzeln:e,env:process.env,cwd:process.cwd(),dateiPfad:Ye})}function se(){return et?yt(process.env):!1}function Re(e,t,n){!e||!se()||Fn({instanzId:e,vomHook:n,verbindung:O,ausGit:o=>Le("brain_from_git",o,O,L),projektOrdner:t?async()=>t:tt,einbetten:o=>st(o,{geduld:"lang"}),hatEinbettung:vo,einbettenZweit:o=>st(o,{geduld:"lang",modell:wo}),melde:o=>A("brain_from_git",{instance_id:e,total:o,auto:"startwissen"}),startvorrat:o=>Me("brain_seed_starter",o,O,L),meldeStartvorrat:o=>A("brain_seed_starter",{instance_id:e,auto:!0},{seeded_count:o,auto:!0})})}function je(){return se()&&Vn()}const ro=7e3,ao=12e3,co=18e4;let be=null;function Be(e){return be||(be=lo(e).finally(()=>{be=null})),be}async function lo(e){try{if(!S){const t=Date.now()+e;for(;!xe()&&On({})&&Date.now()<t;)await new Promise(s=>setTimeout(s,Nn));const n=xe();if(!n)return!1;S=n,ae(n);const o=_e();o&&!N&&(N=o,V=0),await me(n),o&&await ge(o),A("instant_trial_started",{tool:"sessionstart-hook",...o?{instance_id:o}:{}})}if(se()&&ft()){const t=Pn();t&&(He(t.instanzId,se(),je()),Re(t.instanzId,t.projekt||void 0,t.vomHook))}}catch{}return!!S}function uo(){if(!yt(process.env))return;const e=Date.now()+co,t=setInterval(()=>{if(Date.now()>e){clearInterval(t);return}S&&!ft()||Be(0)},500);t.unref(),Be(0)}async function po(){if(!S)return"";try{const e=await fetch(`${x}/api/v1/instances/auto`,{method:"POST",headers:{Authorization:`Bearer ${S}`,"Content-Type":"application/json"},signal:AbortSignal.timeout(12e3)});if(e.ok){const t=await e.json(),n=t.instance?.id??t.instance_id;if(n)return n}else fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`},body:JSON.stringify({event:"auto_provision_failed",status:e.status,version:H}),signal:AbortSignal.timeout(3e3)}).catch(()=>{})}catch{fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:"auto_provision_failed",status:0,reason:"network_error",version:H}),signal:AbortSignal.timeout(3e3)}).catch(()=>{})}return""}async function ot(){if(N)return N;if(!S)return"";if(pe)return pe;const e=Date.now();if(V>0&&e-V<3e4)return"";V=e,pe=(async()=>{try{const t=await fetch(`${x}/api/v1/instances`,{headers:{Authorization:`Bearer ${S}`,Accept:"application/json"},signal:AbortSignal.timeout(5e3)});if(t.ok){const o=(await t.json())?.data??[],s=o.find(a=>a.status==="running")??o.find(a=>a.status==="provisioning");if(s)return N=s.id,V=0,N;const i=await po();if(i)return N=i,V=0,He(i,se(),je()),ge(i),Re(i),N}}catch{}return""})();try{return await pe}finally{pe=null}}let Ne=0;const mo=6e4;let ie="";async function me(e){try{const{writeFile:t,readFile:n}=await import("node:fs/promises"),{existsSync:o}=await import("node:fs"),{resolve:s}=await import("node:path"),i=process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??"";if(!i)return;const a=[s(i,".claude","mcp.json"),s(i,".cursor","mcp.json"),s(i,".codeium","windsurf","mcp_config.json")];await Promise.allSettled(a.map(async r=>{if(o(r))try{const d=await n(r,"utf-8"),f=JSON.parse(d),l=f?.mcpServers?.cachly;l?.env&&(l.env.CACHLY_JWT=e,await t(r,JSON.stringify(f,null,2),"utf-8"))}catch{}}))}catch{}}async function ge(e){if(e){we(e,{apiKey:S});try{const{writeFile:t,readFile:n}=await import("node:fs/promises"),{existsSync:o}=await import("node:fs"),{resolve:s}=await import("node:path"),i=process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??"";if(!i)return;const a=[s(i,".claude","mcp.json"),s(i,".cursor","mcp.json"),s(i,".codeium","windsurf","mcp_config.json")];await Promise.allSettled(a.map(async r=>{if(o(r))try{const d=JSON.parse(await n(r,"utf-8")),f=d?.mcpServers?.cachly;f?.env&&(f.env.CACHLY_BRAIN_INSTANCE_ID=e,await t(r,JSON.stringify(d,null,2),"utf-8"))}catch{}}))}catch{}}}async function go(){try{const e=await fetch(`${x}/api/v1/api-keys`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`},body:JSON.stringify({name:"cachly-mcp-selfheal",scope:"read_write"}),signal:AbortSignal.timeout(8e3)});if(!e.ok)return!1;const t=await e.json();return t.key?(S=t.key,ae(t.key),me(t.key),A("auth_self_healed",{reason:"near_expiry_refresh"}),!0):!1}catch{return!1}}async function Pe(){const e=Ie(S),t=We(e);if(t==="none")return ie="",!0;if(t==="refresh"){const n=Date.now();return n-Ne>=mo&&(Ne=n,await go())?(ie="",!0):(ie=e.message,e.usable)}return ie=e.message,!1}function re(e,t){const n=(a,r)=>{try{t?.(a,r)}catch{}},o=a=>{a?n(!1,a.code??a.message):n(!0)},s=sn(e);if(!s){n(!1,"keine-http-adresse");return}const i=rn(s);try{process.platform==="win32"?Ee("cmd",["/c","start","",i],{windowsHide:!0},o):process.platform==="darwin"?Ee("open",[s],o):Ee("xdg-open",[s],o)}catch(a){n(!1,a instanceof Error?a.message:"unknown")}}let Y=null;async function ho(){try{const e=await fetch(`${x}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({}),signal:AbortSignal.timeout(8e3)});if(e.ok){const t=await e.json(),n=t.verification_uri||j("/device","ambient-signin"),o=`${n}${n.includes("?")?"&":"?"}code=${encodeURIComponent(t.user_code)}`;return{deviceCode:t.device_code,userCode:t.user_code,verifyUrl:o,pollInterval:(t.interval??5)*1e3,deadline:Date.now()+600*1e3,polling:!1}}}catch{}try{const t=await fetch("https://auth.cachly.dev/realms/cachly/protocol/openid-connect/auth/device",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"client_id=cachly-cli&scope=openid",signal:AbortSignal.timeout(8e3)});if(!t.ok)return null;const n=await t.json();return{deviceCode:n.device_code,userCode:n.user_code,verifyUrl:n.verification_uri_complete,pollInterval:(n.interval??5)*1e3,deadline:Date.now()+600*1e3,polling:!1}}catch{return null}}async function fo(e){if(Date.now()>e.deadline)return"expired";const t=async()=>{const o=await fetch(`${x}/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e.deviceCode}),signal:AbortSignal.timeout(8e3)});return o.ok?o.json():null},n=async()=>(await fetch("https://auth.cachly.dev/realms/cachly/protocol/openid-connect/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`client_id=cachly-cli&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=${e.deviceCode}`,signal:AbortSignal.timeout(8e3)})).json();try{let o=await t().catch(()=>null);if(o||(o=await n().catch(()=>null)),!o)return"pending";if(o.access_token){let s=o.access_token;try{const i=await fetch(`${x}/api/v1/api-keys`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({name:"cachly-mcp-smithery",scope:"read_write"}),signal:AbortSignal.timeout(8e3)});if(i.ok){const a=await i.json();a.key&&(s=a.key)}}catch{}return S=s,ae(s),Y=null,A("device_flow_completed"),me(s),ee(s),V=0,await ot(),N&&ge(N),"done"}return o.error==="slow_down"&&(e.pollInterval=Math.min(e.pollInterval+2e3,15e3)),"pending"}catch{return"pending"}}async function nt(e){if(e.polling)return"pending";e.polling=!0;try{return await fo(e)}finally{e.polling=!1}}function yo(e,t=nt,n=s=>Y===s,o=bo){const s=async()=>{if(!n(e))return;let i="pending";try{i=await t(e)}catch{}if(i!=="done"){if(i==="expired"){n(e)&&(Y=null);return}n(e)&&o(s,e.pollInterval)}};o(s,e.pollInterval)}function bo(e,t){const n=setTimeout(e,t);typeof n.unref=="function"&&n.unref()}import{setEmbedJwt as ae,computeEmbedding as st,hasEmbedProvider as vo,EMBED_PROVIDER as it}from"./embeddings.js";import{ZWEIT_MODELL as wo}from"./rangfolge-stellschrauben.js";import{tokenize as xo,splitMultiQuery as _o,levenshtein as $o,recencyBoost as ko,extractTimestamp as So,STOPWORDS as Ao,katakanaToRomaji as Co,arabicLightStem as To,expandCrossLingual as Io,CROSS_LINGUAL_MAP as Eo,ZERO_RESULTS_LOG as Ro,zeroResultsTotal as jo}from"./search.js";const X=new Map;function Bo(e){return e<=1?200:null}async function O(e){if(!e)throw new Q(ne.InvalidRequest,`\u23F3 Your Brain instance is still being set up.
|
|
2
|
+
import{setzeClientKennung as Wt}from"./herkunft.js";import{jwtExpiryMs as Jt,checkJwt as Ft,handleApiError as Yt,diagnoseAuth as Ie,planAuthHeal as We,readClientCredentialsFromEnv as Kt,buildClientCredentialsBody as qt,clientCredentialsTokenUrl as Gt}from"./auth.js";import{cachlyUrl as j}from"./cachly-url.js";import{nutzungsSchluessel as Vt}from"./werkzeug-nutzung.js";import{istLieferung as Zt,lieferSchluessel as Qt,tokenDerAntwort as Xt,hatTreffer as eo,trefferSchluessel as Je}from"./geliefert.js";import{notify as Fe}from"./notifier.js";import{fileURLToPath as Ye}from"node:url";import{createRequire as to}from"node:module";import{execFile as Ee}from"node:child_process";const oo=process.argv[1]!=null&&(process.argv[1]===Ye(import.meta.url)||process.argv[1].endsWith("/dist/index.js")||process.argv[1].endsWith("/src/index.ts"));import{Server as Ke}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as no}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as so}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{CallToolRequestSchema as qe,ErrorCode as ne,ListPromptsRequestSchema as Ge,ListResourceTemplatesRequestSchema as Ve,ListResourcesRequestSchema as Ze,ListToolsRequestSchema as Qe,McpError as Q}from"@modelcontextprotocol/sdk/types.js";import{Redis as Xe}from"ioredis";let x=process.env.CACHLY_API_URL??"https://api.cachly.dev",S=Oe()??"";ae(S);const ti=process.env.CACHLY_EMBED_MODEL??"",H=(()=>{try{const e=to(import.meta.url);for(const t of["../../package.json","../package.json"])try{const n=e(t);if(n.name==="@cachly-dev/mcp-server"&&n.version)return n.version}catch{}}catch{}return"0.10.100"})(),io=Number(process.env.CACHLY_PROVISION_TIMEOUT_MS??9e4);let N=$e(process.env.CACHLY_BRAIN_INSTANCE_ID);function G(){return S||Oe()||""}function z(){return $e(process.env.CACHLY_BRAIN_INSTANCE_ID)||_e()||""}let V=0,pe=null,et=!1;async function tt(){let e=[];try{K.getClientCapabilities()?.roots&&(e=(await K.listRoots(void 0,{timeout:3e3})).roots)}catch{}return Gn({wurzeln:e,env:process.env,cwd:process.cwd(),dateiPfad:Ye})}function se(){return et?yt(process.env):!1}function Re(e,t,n){!e||!se()||Fn({instanzId:e,vomHook:n,verbindung:O,ausGit:o=>Le("brain_from_git",o,O,L),projektOrdner:t?async()=>t:tt,einbetten:o=>st(o,{geduld:"lang"}),hatEinbettung:wo,einbettenZweit:o=>st(o,{geduld:"lang",modell:vo}),melde:o=>A("brain_from_git",{instance_id:e,total:o,auto:"startwissen"}),startvorrat:o=>Me("brain_seed_starter",o,O,L),meldeStartvorrat:o=>A("brain_seed_starter",{instance_id:e,auto:!0},{seeded_count:o,auto:!0})})}function je(){return se()&&Vn()}const ro=7e3,ao=12e3,co=18e4;let be=null;function Be(e){return be||(be=lo(e).finally(()=>{be=null})),be}async function lo(e){try{if(!S){const t=Date.now()+e;for(;!xe()&&On({})&&Date.now()<t;)await new Promise(s=>setTimeout(s,Nn));const n=xe();if(!n)return!1;S=n,ae(n);const o=_e();o&&!N&&(N=o,V=0),await me(n),o&&await ge(o),A("instant_trial_started",{tool:"sessionstart-hook",...o?{instance_id:o}:{}})}if(se()&&ft()){const t=Pn();t&&(He(t.instanzId,se(),je()),Re(t.instanzId,t.projekt||void 0,t.vomHook))}}catch{}return!!S}function uo(){if(!yt(process.env))return;const e=Date.now()+co,t=setInterval(()=>{if(Date.now()>e){clearInterval(t);return}S&&!ft()||Be(0)},500);t.unref(),Be(0)}async function po(){if(!S)return"";try{const e=await fetch(`${x}/api/v1/instances/auto`,{method:"POST",headers:{Authorization:`Bearer ${S}`,"Content-Type":"application/json"},signal:AbortSignal.timeout(12e3)});if(e.ok){const t=await e.json(),n=t.instance?.id??t.instance_id;if(n)return n}else fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`},body:JSON.stringify({event:"auto_provision_failed",status:e.status,version:H}),signal:AbortSignal.timeout(3e3)}).catch(()=>{})}catch{fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:"auto_provision_failed",status:0,reason:"network_error",version:H}),signal:AbortSignal.timeout(3e3)}).catch(()=>{})}return""}async function ot(){if(N)return N;if(!S)return"";if(pe)return pe;const e=Date.now();if(V>0&&e-V<3e4)return"";V=e,pe=(async()=>{try{const t=await fetch(`${x}/api/v1/instances`,{headers:{Authorization:`Bearer ${S}`,Accept:"application/json"},signal:AbortSignal.timeout(5e3)});if(t.ok){const o=(await t.json())?.data??[],s=o.find(a=>a.status==="running")??o.find(a=>a.status==="provisioning");if(s)return N=s.id,V=0,N;const i=await po();if(i)return N=i,V=0,He(i,se(),je()),ge(i),Re(i),N}}catch{}return""})();try{return await pe}finally{pe=null}}let Ne=0;const mo=6e4;let ie="";async function me(e){try{const{writeFile:t,readFile:n}=await import("node:fs/promises"),{existsSync:o}=await import("node:fs"),{resolve:s}=await import("node:path"),i=process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??"";if(!i)return;const a=[s(i,".claude","mcp.json"),s(i,".cursor","mcp.json"),s(i,".codeium","windsurf","mcp_config.json")];await Promise.allSettled(a.map(async r=>{if(o(r))try{const d=await n(r,"utf-8"),f=JSON.parse(d),l=f?.mcpServers?.cachly;l?.env&&(l.env.CACHLY_JWT=e,await t(r,JSON.stringify(f,null,2),"utf-8"))}catch{}}))}catch{}}async function ge(e){if(e){ve(e,{apiKey:S});try{const{writeFile:t,readFile:n}=await import("node:fs/promises"),{existsSync:o}=await import("node:fs"),{resolve:s}=await import("node:path"),i=process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??"";if(!i)return;const a=[s(i,".claude","mcp.json"),s(i,".cursor","mcp.json"),s(i,".codeium","windsurf","mcp_config.json")];await Promise.allSettled(a.map(async r=>{if(o(r))try{const d=JSON.parse(await n(r,"utf-8")),f=d?.mcpServers?.cachly;f?.env&&(f.env.CACHLY_BRAIN_INSTANCE_ID=e,await t(r,JSON.stringify(d,null,2),"utf-8"))}catch{}}))}catch{}}}async function go(){try{const e=await fetch(`${x}/api/v1/api-keys`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`},body:JSON.stringify({name:"cachly-mcp-selfheal",scope:"read_write"}),signal:AbortSignal.timeout(8e3)});if(!e.ok)return!1;const t=await e.json();return t.key?(S=t.key,ae(t.key),me(t.key),A("auth_self_healed",{reason:"near_expiry_refresh"}),!0):!1}catch{return!1}}async function Pe(){const e=Ie(S),t=We(e);if(t==="none")return ie="",!0;if(t==="refresh"){const n=Date.now();return n-Ne>=mo&&(Ne=n,await go())?(ie="",!0):(ie=e.message,e.usable)}return ie=e.message,!1}function re(e,t){const n=(a,r)=>{try{t?.(a,r)}catch{}},o=a=>{a?n(!1,a.code??a.message):n(!0)},s=sn(e);if(!s){n(!1,"keine-http-adresse");return}const i=rn(s);try{process.platform==="win32"?Ee("cmd",["/c","start","",i],{windowsHide:!0},o):process.platform==="darwin"?Ee("open",[s],o):Ee("xdg-open",[s],o)}catch(a){n(!1,a instanceof Error?a.message:"unknown")}}let Y=null;async function ho(){try{const e=await fetch(`${x}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({}),signal:AbortSignal.timeout(8e3)});if(e.ok){const t=await e.json(),n=t.verification_uri||j("/device","ambient-signin"),o=`${n}${n.includes("?")?"&":"?"}code=${encodeURIComponent(t.user_code)}`;return{deviceCode:t.device_code,userCode:t.user_code,verifyUrl:o,pollInterval:(t.interval??5)*1e3,deadline:Date.now()+600*1e3,polling:!1}}}catch{}try{const t=await fetch("https://auth.cachly.dev/realms/cachly/protocol/openid-connect/auth/device",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"client_id=cachly-cli&scope=openid",signal:AbortSignal.timeout(8e3)});if(!t.ok)return null;const n=await t.json();return{deviceCode:n.device_code,userCode:n.user_code,verifyUrl:n.verification_uri_complete,pollInterval:(n.interval??5)*1e3,deadline:Date.now()+600*1e3,polling:!1}}catch{return null}}async function fo(e){if(Date.now()>e.deadline)return"expired";const t=async()=>{const o=await fetch(`${x}/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e.deviceCode}),signal:AbortSignal.timeout(8e3)});return o.ok?o.json():null},n=async()=>(await fetch("https://auth.cachly.dev/realms/cachly/protocol/openid-connect/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`client_id=cachly-cli&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=${e.deviceCode}`,signal:AbortSignal.timeout(8e3)})).json();try{let o=await t().catch(()=>null);if(o||(o=await n().catch(()=>null)),!o)return"pending";if(o.access_token){let s=o.access_token;try{const i=await fetch(`${x}/api/v1/api-keys`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({name:"cachly-mcp-smithery",scope:"read_write"}),signal:AbortSignal.timeout(8e3)});if(i.ok){const a=await i.json();a.key&&(s=a.key)}}catch{}return S=s,ae(s),Y=null,A("device_flow_completed"),me(s),ee(s),V=0,await ot(),N&&ge(N),"done"}return o.error==="slow_down"&&(e.pollInterval=Math.min(e.pollInterval+2e3,15e3)),"pending"}catch{return"pending"}}async function nt(e){if(e.polling)return"pending";e.polling=!0;try{return await fo(e)}finally{e.polling=!1}}function yo(e,t=nt,n=s=>Y===s,o=bo){const s=async()=>{if(!n(e))return;let i="pending";try{i=await t(e)}catch{}if(i!=="done"){if(i==="expired"){n(e)&&(Y=null);return}n(e)&&o(s,e.pollInterval)}};o(s,e.pollInterval)}function bo(e,t){const n=setTimeout(e,t);typeof n.unref=="function"&&n.unref()}import{setEmbedJwt as ae,computeEmbedding as st,hasEmbedProvider as wo,EMBED_PROVIDER as it}from"./embeddings.js";import{ZWEIT_MODELL as vo}from"./rangfolge-stellschrauben.js";import{tokenize as xo,splitMultiQuery as _o,levenshtein as $o,recencyBoost as ko,extractTimestamp as So,STOPWORDS as Ao,katakanaToRomaji as Co,arabicLightStem as To,expandCrossLingual as Io,CROSS_LINGUAL_MAP as Eo,ZERO_RESULTS_LOG as Ro,zeroResultsTotal as jo}from"./search.js";const X=new Map;function Bo(e){return e<=1?200:null}async function O(e){if(!e)throw new Q(ne.InvalidRequest,`\u23F3 Your Brain instance is still being set up.
|
|
3
3
|
|
|
4
4
|
This usually resolves in a few seconds \u2014 just call the tool again and it will connect automatically.
|
|
5
5
|
|
|
@@ -22,7 +22,7 @@ Complete your checkout at: ${j("/instances","upgrade")}`:r=`Brain instance "${t.
|
|
|
22
22
|
|
|
23
23
|
\u2022 Check your network connection
|
|
24
24
|
\u2022 Run \`get_api_status\` to verify instance status
|
|
25
|
-
\u2022 Technical detail: ${d}`)}return X.set(e,i),F("verbindung: Valkey verbunden"),i}async function L(e,t={},n=!1){n||We(Ie(S))!=="none"&&await Pe(),Ft(S);const o=Number(process.env.CACHLY_API_TIMEOUT_MS??15e3),s=await fetch(`${x}${e}`,{...t,signal:AbortSignal.timeout(o),headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`,...t.headers}});if(!s.ok){if(s.status===401&&!n&&(Ne=0,await Pe()))return L(e,t,!0);const a=(await s.json().catch(()=>({error:s.statusText}))).error??s.statusText;Yt(s.status,a)}if(s.status!==204)return s.json()}import{handleBrainTool as Lo}from"./handlers/brain.js";import{handleContextTool as Oo}from"./handlers/context.js";import{handleInstanceTool as Ho}from"./handlers/instances.js";import{handleCacheTool as Mo}from"./handlers/cache.js";import{handleTeamTool as Do}from"./handlers/team.js";import{handleRoadmapTool as zo}from"./handlers/roadmap.js";import{handleAdvancedTool as Uo}from"./handlers/advanced.js";import{handleSyndicateTool as Wo}from"./handlers/syndicate.js";import{handleFedbrainTool as Le,_lastBrainFromGitCounts as
|
|
25
|
+
\u2022 Technical detail: ${d}`)}return X.set(e,i),F("verbindung: Valkey verbunden"),i}async function L(e,t={},n=!1){n||We(Ie(S))!=="none"&&await Pe(),Ft(S);const o=Number(process.env.CACHLY_API_TIMEOUT_MS??15e3),s=await fetch(`${x}${e}`,{...t,signal:AbortSignal.timeout(o),headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`,...t.headers}});if(!s.ok){if(s.status===401&&!n&&(Ne=0,await Pe()))return L(e,t,!0);const a=(await s.json().catch(()=>({error:s.statusText}))).error??s.statusText;Yt(s.status,a)}if(s.status!==204)return s.json()}import{handleBrainTool as Lo}from"./handlers/brain.js";import{handleContextTool as Oo}from"./handlers/context.js";import{handleInstanceTool as Ho}from"./handlers/instances.js";import{handleCacheTool as Mo}from"./handlers/cache.js";import{handleTeamTool as Do}from"./handlers/team.js";import{handleRoadmapTool as zo}from"./handlers/roadmap.js";import{handleAdvancedTool as Uo}from"./handlers/advanced.js";import{handleSyndicateTool as Wo}from"./handlers/syndicate.js";import{handleFedbrainTool as Le,_lastBrainFromGitCounts as we}from"./handlers/fedbrain.js";import{extractFirstRecallProof as Jo,extractTopHit as Fo,fuersTerminal as rt,renderFirstRecallProof as Yo}from"./first-recall-proof.js";import{aussetzerLeise as Ko}from"./aussetzer.js";import{gitHookOrdner as qo,installClsPostCommitHook as at,CLS_HOOK_VERSION as ct}from"./cls-hook.js";import{CLAUDE_MD_MARKER_START as Go,CLAUDE_MD_MARKER_END as Vo,EDITOR_FILES as ce,ANWEISUNGS_DATEIEN as Zo,buildClaudeMdBlock as lt,setzeAnweisungsblock as Qo,sollSchreiben as Xo}from"./projektdateien.js";import{klassiereArgument as en,leseFlag as dt,flagsOhneWert as tn,pruefeInitEingaben as on}from"./cli-argumente.js";import{uninstallBefehl as nn}from"./uninstall.js";import{gitLesen as ut}from"./git-ohne-shell.js";import{browserAdresse as sn,fuerCmd as rn}from"./browser-adresse.js";import{installAmbientHooks as pt,installCursorHooks as an,installCopilotHooks as cn,installCodexHooks as ln,installGeminiHooks as dn,AMBIENT_HOOK_VERSION as mt,COPILOT_HOOKS_DATEI as un,CODEX_HOOKS_DATEI as pn,GEMINI_SETTINGS_DATEI as mn}from"./ambient-hooks.js";import{hookHauptlauf as gn,auffrischenHauptlauf as hn,startwissenImportHauptlauf as fn}from"./ambient-hook.js";import{STARTWISSEN_IMPORT as yn}from"./startwissen-hook.js";import{rahmeAntwort as bn}from"./antwort-rahmen.js";import{appendLedgerEntry as wn,readLedger as gt,defaultLedgerPath as vn,reportLedgerEntry as xn,teileNachInstanz as _n}from"./ambient-ledger.js";import{installCodexMcp as $n,installGeminiMcp as kn}from"./editor-mcp-eintrag.js";import{resolveApiKey as Oe,saveApiKey as ee,saveInstanceId as ve,readSavedApiKey as xe,readInstanceId as _e}from"./credentials.js";import{KEYCLOAK_BASIS as ht,istTestSchluessel as Sn,waehleTestSchluessel as An,starteKeycloakAnmeldung as Cn,warteAufKeycloakAnmeldung as Tn,uebernimm as In,brainImKonto as En,erfolgsText as Rn,fehlerText as jn,ersetzeSchluessel as Bn}from"./uebernahme.js";import{WARTE_TAKT_MS as Nn,auftragLiegt as ft,nimmAuftrag as Pn,sichereKonto as Ln,sperreLiegt as On,startwissenEingeschaltet as yt}from"./konto-anlegen.js";import{sichereZugang as Hn,echterWert as $e}from"./zugang.js";import{zeitpunkt as F}from"./zeitmessung.js";import{autoSitzungsSchritt as Mn,SITZUNGS_WERKZEUGE as Dn}from"./auto-sitzung.js";import{warteAufLaufendeInstanz as zn,gemeinsamerAufbau as Un}from"./instanz-warten.js";import{merkeNeuesBrain as He,startetLautLetztemBlick as Wn,setzeCommitQuelle as Jn}from"./leeres-brain.js";import{starteStartwissen as Fn,startwissenGestartet as Yn,beanspruchStartwissen as Kn,holeStartwissenHinweis as qn,waehleProjektOrdner as Gn,startvorratErlaubt as Vn,projektCommits as Zn}from"./startwissen.js";import{eigeneFassung as Qn,pruefeNeueFassung as Xn,holeNeueFassungHinweis as es}from"./neue-fassung.js";import{beiStdinEnde as ts}from"./stdin-ende.js";import{merkeWerkzeugAufruf as os,starteBrandWachhund as ns}from"./brand-wachhund.js";import{sichtbareWerkzeuge as ss,VERTEILER as bt}from"./werkzeug-auswahl.js";import{fehlendePflichtfelder as is}from"./pflichtfelder.js";import{buildLessonsMarkdown as rs,buildLessonsJsonl as as,vonRohLektion as cs}from"./brain-export.js";import{detectEditor as ls}from"./editor.js";import{milestoneSent as wt,markMilestoneSent as vt}from"./funnel-milestones.js";import{meldeKopf as ds,meldeRumpf as us}from"./melde-weg.js";import{kostprobeUebrig as ps,kostprobeVerbrauchen as ms,kostprobeHinweis as gs,schrankeNachKostproben as hs}from"./kostprobe.js";import{netBalance as fs}from"./ambient-recall.js";import{handleShareTool as Me}from"./handlers/share.js";import{handleVizTool as ys}from"./handlers/viz.js";import{commitArt as bs,istRueckbau as ws,zaehleLektionen as vs}from"./commit-art.js";import{TOOLS as le}from"./tools.js";import{verbindungsWeg as xt}from"./brains-tls.js";let _t=!1,$t=!1,ke=!1;function kt(){return ls()}function A(e,t,n){process.env.CACHLY_NO_TELEMETRY!=="1"&&fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:ds(S),body:JSON.stringify(us({event:e,version:H,editor:kt()},t,n)),signal:AbortSignal.timeout(3e3)}).catch(()=>{})}function xs(e,t){return xn({apiUrl:x,jwt:S,instanceId:e},t)}async function _s(e){if(!_t&&process.env.CACHLY_NO_TELEMETRY!=="1"){_t=!0;try{await fetch(`${x}/api/v1/telemetry/mcp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:"first_call_no_jwt",version:H,editor:kt(),tool:e}),signal:AbortSignal.timeout(3e3)})}catch{}}}const $s=new Set(["causal_trace","brain_predict","brain_plan","brain_predict_failures","team_learn","team_confirm","team_recall","team_synthesize","team_crystallize","global_learn","global_recall"]),ks={causal_trace:"Causal root-cause tracing \u2014 follow the failure chain to the real cause, not just the symptom.",brain_predict:"Predictive risk \u2014 your Brain warns you what will break *before* you run it.",brain_plan:"Generative planning \u2014 turn a goal into an ordered, risk-aware plan from your own history.",brain_predict_failures:"Failure prediction \u2014 catch CI/build breakage before it happens.",team_learn:"Team Brain \u2014 one shared memory across your whole team.",team_confirm:"Team Brain \u2014 peer + senior review that raises lesson trust.",team_recall:"Team Brain \u2014 recall everything your teammates have already solved.",team_synthesize:"Team Brain \u2014 synthesize collective knowledge across authors.",team_crystallize:"Team Brain \u2014 compress your team's wisdom into a shareable crystal.",global_learn:"Team Brain \u2014 contribute to your organization's shared memory.",global_recall:"Team Brain \u2014 recall across your entire organization."},St=j("/billing","upgrade"),At=new Map;async function Ss(e){const t=At.get(e);if(t&&t.expiresAt>Date.now())return t.info;try{const o=((await L(`/api/v1/instances/${e}`))?.tier??"free").toLowerCase(),s={tier:o,isFree:o==="free"||o===""};return At.set(e,{info:s,expiresAt:Date.now()+6e4}),s}catch{return{tier:"unknown",isFree:!1}}}async function As(e,t){if(!$s.has(e)||!t)return null;const{isFree:n}=await Ss(t);if(!n)return null;const o=ks[e]??"A Premium intelligence feature.";if(ps(e)){const s=ms(e);return{kostprobe:gs(e,s,St)}}return{sperre:hs(e,o,St)}}async function Cs(e,t){try{await(await O(e)).hincrby(Vt(e),t,1)}catch{}}async function Ts(e,t,n){if(Zt(t))try{const o=await O(e),s=eo(n);await o.incrby(Qt(e),s?Xt(n):0),await o.hincrby(Je(e),"abrufe",1),s&&await o.hincrby(Je(e),"treffer",1)}catch{}}async function Is(e){const t=await ho();return t?(Y=t,A("device_flow_started",{tool:e}),re(t.verifyUrl,(n,o)=>{if(n){A("device_browser_opened",{stelle:"tool"});return}A("device_browser_failed",{reason:o??"unknown",stelle:"tool"}),process.stderr.write(`
|
|
26
26
|
cachly: could not open a browser (${o??"unknown"}).
|
|
27
27
|
cachly: open this yourself to finish signing in:
|
|
28
28
|
cachly: ${t.verifyUrl}
|
|
@@ -31,9 +31,9 @@ cachly: code ${t.userCode}
|
|
|
31
31
|
`)}),yo(t),["\u{1F9E0} **cachly AI Brain \u2014 the user must sign in once.**","","**Show the following link and code to the user verbatim \u2014 they cannot","continue without them.**","",`\u{1F449} **${t.verifyUrl}**`,"",`Code: **${t.userCode}**`,"","A browser may have opened automatically with the code pre-filled. If it","did not, the link above is the whole step.","","Once signed in, the Brain activates on its own \u2014 no further action, no","restart. The next request arrives brain-powered.","",`\u2728 ${le.length} MCP tools \xB7 GDPR \xB7 EU servers \xB7 free tier, no credit card`].join(`
|
|
32
32
|
`)):["\u{1F9E0} **cachly AI Brain \u2014 Setup required**","","Run the setup wizard once in your terminal:"," ```"," npx @cachly-dev/mcp-server@latest autopilot"," ```","",`Or get your API key at: ${j("/setup-ai","ambient-signin")}`,"","\u2728 Free tier includes: 1 Brain instance, persistent memory, semantic search."].join(`
|
|
33
33
|
`)}async function Es(e){if(!e)return!0;if(Yn(e))return!1;try{return await Kn(await O(e),"sitzungsstart")}catch{return!0}}async function J(e,t){if(!S&&await Be(ro))return J(e,t);if(!S){if(_s(e),Y){const c=await nt(Y);return c==="done"?J(e,t):c==="expired"?(A("device_flow_failed",{reason:"timeout"}),Y=null,"\u231B **Authentication timed out.** Please call any tool again to restart the sign-in flow."):["\u23F3 **Signing you in\u2026**","",`Finish in your browser: **${Y.verifyUrl}**`,`Code: **${Y.userCode}**`,"","This completes automatically once you sign in \u2014 no need to come back here."].join(`
|
|
34
|
-
`)}return Hn({schluessel:S,konfigurierteInstanz:N,aufrufInstanz:t.instance_id,werkzeugName:e,holeSofortTest:async()=>{F("sofort-test: Anfang");const c=await Ln({apiUrl:x,version:H,fristMs:ao}),p=c.art==="angelegt"?c.test:c.art==="vorhanden"&&c.instanzId?{apiKey:c.apiKey,instanzId:c.instanzId}:null;return F(`sofort-test: ${p?"Brain angelegt":"kein Test"}`),p&&He(p.instanzId,se(),je()),p},ablagen:{setzeSchluessel:c=>{S=c},setEmbedJwt:ae,saveApiKey:c=>ee(c),persistApiKeyToConfig:me,merkeInstanz:c=>{N=c,V=0},persistInstanceIdToConfig:ge},meldeEreignis:A,werkzeug:()=>J(e,t),anmelden:()=>Is(e),neuesBrain:Re})}if(!t.instance_id){const c=await ot();c&&(t={...t,instance_id:c})}const n=await As(e,t.instance_id);let o="";if(n!==null){if("sperre"in n)return A("premium_gate_hit",{tool:e,instance_id:t.instance_id??""}),n.sperre;o=n.kostprobe,A("premium_taste_used",{tool:e,instance_id:t.instance_id??""})}typeof t.instance_id=="string"&&t.instance_id&&Cs(t.instance_id,e),F(`werkzeug ${e}: Zugang und Tarif geklaert`);const s=await Lo(e,t,O,L);if(F(`werkzeug ${e}: Brain-Werkzeug fertig`),s!==null){typeof t.instance_id=="string"&&t.instance_id&&Ts(t.instance_id,e,String(s??"")),!ke&&S&&(ke=!0,
|
|
34
|
+
`)}return Hn({schluessel:S,konfigurierteInstanz:N,aufrufInstanz:t.instance_id,werkzeugName:e,holeSofortTest:async()=>{F("sofort-test: Anfang");const c=await Ln({apiUrl:x,version:H,fristMs:ao}),p=c.art==="angelegt"?c.test:c.art==="vorhanden"&&c.instanzId?{apiKey:c.apiKey,instanzId:c.instanzId}:null;return F(`sofort-test: ${p?"Brain angelegt":"kein Test"}`),p&&He(p.instanzId,se(),je()),p},ablagen:{setzeSchluessel:c=>{S=c},setEmbedJwt:ae,saveApiKey:c=>ee(c),persistApiKeyToConfig:me,merkeInstanz:c=>{N=c,V=0},persistInstanceIdToConfig:ge},meldeEreignis:A,werkzeug:()=>J(e,t),anmelden:()=>Is(e),neuesBrain:Re})}if(!t.instance_id){const c=await ot();c&&(t={...t,instance_id:c})}const n=await As(e,t.instance_id);let o="";if(n!==null){if("sperre"in n)return A("premium_gate_hit",{tool:e,instance_id:t.instance_id??""}),n.sperre;o=n.kostprobe,A("premium_taste_used",{tool:e,instance_id:t.instance_id??""})}typeof t.instance_id=="string"&&t.instance_id&&Cs(t.instance_id,e),F(`werkzeug ${e}: Zugang und Tarif geklaert`);const s=await Lo(e,t,O,L);if(F(`werkzeug ${e}: Brain-Werkzeug fertig`),s!==null){typeof t.instance_id=="string"&&t.instance_id&&Ts(t.instance_id,e,String(s??"")),!ke&&S&&(ke=!0,wt("first_call_success")||(vt("first_call_success"),A("first_call_success",{tool:e,instance_id:t.instance_id??N??""})));const c=t.instance_id??N??"",p={instance_id:c};if(e==="recall_best_solution")A("recall_best_solution",p);else if(e==="learn_from_attempts")A("learn_from_attempts",p);else if(e==="session_start"){A("session_start",p,{born_at:void 0,recalls_total:void 0,starter_seeded:!1});const g=typeof s=="object"&&s!==null&&"content"in s?JSON.stringify(s):String(s??""),C=g.includes("Welcome! Your AI Brain is live.");if(!Wn(c)){if(!C&&g.length>100)A("recall_best_solution",p);else if(C&&t.workspace_path&&await Es(c))try{const _=await Le("brain_from_git",{instance_id:c,repo_path:t.workspace_path,limit:50},O,L);if(_!==null){A("brain_from_git",{...p,...we??{}}),A("recall_best_solution",p);let I="";if((we?.total??0)===0)try{const M=await Me("brain_seed_starter",{instance_id:c},O,L);M&&(A("brain_seed_starter",{...p,auto:!0},{seeded_count:16,auto:!0}),I=`
|
|
35
35
|
---
|
|
36
|
-
`+String(M))}catch{}const E=String(_),$=
|
|
36
|
+
`+String(M))}catch{}const E=String(_),$=we?.total??0,R=$>0?`
|
|
37
37
|
\u2705 **Brain bootstrapped from git \u2014 ${$} lesson${$===1?"":"s"} loaded.** Your AI already knows your history.`:"";if(E||I||R)return String(s)+R+`
|
|
38
38
|
---
|
|
39
39
|
`+E+I}}catch(_){return A("brain_from_git_failed",{...p,reason:_ instanceof Error?_.message.slice(0,120):"unknown"}),String(s)+`
|
|
@@ -42,7 +42,7 @@ cachly: code ${t.userCode}
|
|
|
42
42
|
> Run \`brain_from_git(instance_id="`+c+'", repo_path="'+String(t.workspace_path)+'")` manually to seed it.\n> Or try `brain_seed_starter` to load 16 universal engineering lessons instantly.'}}}else if(e==="session_end")A("session_end",p);else if(e==="smart_recall"){const g=typeof s=="object"&&s!==null&&"content"in s?JSON.stringify(s):String(s??""),C=g.length>50&&!g.includes("No lessons found")&&!g.includes("no lessons")&&!g.includes("No matches found");if(A("smart_recall",p,{hit:C,topic:String(t.query??"").slice(0,80)}),C&&A("recall_best_solution",p),ie&&typeof s=="string")return`> \u26A0\uFE0F **Brain auth degraded** \u2014 ${ie.split(`
|
|
43
43
|
`)[0]}
|
|
44
44
|
|
|
45
|
-
${s}`}return s}const i=await Oo(e,t,O,L);if(i!==null)return!ke&&S&&(ke=!0,
|
|
45
|
+
${s}`}return s}const i=await Oo(e,t,O,L);if(i!==null)return!ke&&S&&(ke=!0,wt("first_call_success")||(vt("first_call_success"),A("first_call_success",{tool:e,instance_id:t.instance_id??N??""}))),i;const a=await Ho(e,t,O,L);if(a!==null)return a;const r=await Mo(e,t,O,L);if(r!==null)return r;const d=c=>o?c+o:c,f=await Do(e,t,O,L);if(f!==null)return d(f);const l=await zo(e,t,O,L);if(l!==null)return l;const u=await Uo(e,t,O,L);if(u!==null)return d(u);const y=await Wo(e,t,O,L);if(y!==null){if(e==="brain_predict"){const p={instance_id:t.instance_id??N??""};A("brain_predict",p)}return d(y)}const b=await Me(e,t,O,L);if(b!==null)return b;const v=await ys(e,t,O,L);if(v!==null)return v;const m=await Le(e,t,O,L);if(m!==null){const p={instance_id:t.instance_id??N??""};if(e==="brain_from_git"){const g=we;A("brain_from_git",{...p,...g??{}},g?{fixes:g.fixes,features:g.features,refactors:g.refactors,total:g.total}:void 0)}else e==="brain_predict_failures"&&A("brain_predict_failures",p);return m}switch(e){case"get_api_status":{let c="unknown";try{const _=await fetch(`${x}/health`,{signal:AbortSignal.timeout(8e3)});if(_.ok){const k=await _.json();c=`${k.status??"ok"} (db: ${k.db??"?"})`}else c=`HTTP ${_.status}`}catch(_){c=`unreachable: ${_.message}`}if(!S)return["\u{1F4E1} **cachly API Status**","",` \u{1F310} API: ${x}`,` \u{1F493} Health: ${c}`," \u{1F511} Auth: \u274C CACHLY_JWT not set","",`\u{1F4A1} Get your API token at ${j("/instances","api-status")} \u2192 Settings \u2192 API Token`].join(`
|
|
46
46
|
`);let p="\u274C invalid JWT format";try{const _=S.split(".");if(_.length===3){const k=JSON.parse(Buffer.from(_[1],"base64url").toString("utf-8")),I=k.sub??"(unknown)",E=k.iss??"(unknown)",$=E.includes("keycloak")?"Keycloak":"OIDC",R=k.exp?new Date(k.exp*1e3):null,M=R?R<new Date:!1;p=["\u2705 JWT decoded",` Sub (user ID): ${I}`,` Provider: ${$}`,` Issuer: ${E}`,` Expires: ${R?R.toISOString():"never"} ${M?"\u26A0\uFE0F EXPIRED \u2013 get a new token!":"\u2705"}`].join(`
|
|
47
47
|
`)}}catch{p="\u274C JWT decode failed \u2013 check CACHLY_JWT format"}let g="";try{const k=(await L("/api/v1/instances")).data??[];if(k.length===0)g=`
|
|
48
48
|
|
|
@@ -51,8 +51,8 @@ ${s}`}return s}const i=await Oo(e,t,O,L);if(i!==null)return!ke&&S&&(ke=!0,vt("fi
|
|
|
51
51
|
\u{1F9E0} **Brain Instances:**`];for(const E of k){const $=E.status==="running"?"\u{1F7E2}":E.status==="provisioning"?"\u{1F7E1}":"\u{1F534}",R=E.id===N?" \u2190 active":"";if(I.push(` ${$} **${E.name}** (\`${E.id}\`) \xB7 ${E.status}${R}`),E.status==="running"&&E.host){const M=X.get(E.id);if(M)try{await M.ping(),I.push(" \u{1F493} Redis: connected")}catch{I.push(" \u26A0\uFE0F Redis: pooled but ping failed \u2014 will reconnect on next use")}else I.push(" \u{1F4A4} Redis: not connected yet (connects on first tool use)")}else E.status==="provisioning"?I.push(" \u23F3 Still provisioning \u2014 check back in ~30 s"):E.status!=="running"&&I.push(` \u274C Not reachable (status: ${E.status})`)}g=I.join(`
|
|
52
52
|
`)}}catch(_){g=`
|
|
53
53
|
|
|
54
|
-
\u{1F9E0} **Brain Instances:** could not fetch \u2014 ${_.message}`}await Pe();const C=Ie(S),
|
|
55
|
-
`)[0]}`;return["\u{1F4E1} **cachly API Status**","",` \u{1F310} API: ${x}`,` \u{1F493} Health: ${c}`,` ${
|
|
54
|
+
\u{1F9E0} **Brain Instances:** could not fetch \u2014 ${_.message}`}await Pe();const C=Ie(S),w=C.state==="long_lived"?"\u{1F6E1}\uFE0F Self-healing: \u2705 long-lived API key (won't expire silently)":C.state==="healthy"?`\u{1F6E1}\uFE0F Self-healing: \u2705 token valid${C.expiresInMs?` (${Math.round(C.expiresInMs/36e5)}h left)`:""}`:C.state==="near_expiry"?"\u{1F6E1}\uFE0F Self-healing: \u267B\uFE0F token near expiry \u2014 auto-refresh attempted":`\u{1F6E1}\uFE0F Self-healing: \u26A0\uFE0F ${C.message.split(`
|
|
55
|
+
`)[0]}`;return["\u{1F4E1} **cachly API Status**","",` \u{1F310} API: ${x}`,` \u{1F493} Health: ${c}`,` ${w}`,"","\u{1F511} **Auth:**",p,g].join(`
|
|
56
56
|
`)}default:throw new Ct(`Unknown tool: ${e}`)}}class Ct extends Error{}const Tt=`REQUIRED FIRST STEP for every task in this project: before you read or edit any file, call the cachly tool smart_recall with one line describing the task (if it is not loaded yet, load it with your tool search first). It returns fixes, decisions and known traps from earlier sessions in THIS codebase. Do this even for small tasks.
|
|
57
57
|
|
|
58
58
|
This project has a Cachly AI Brain \u2014 persistent, cross-session memory of past fixes, decisions, and gotchas for THIS codebase.
|
|
@@ -66,12 +66,12 @@ You do not need to pass instance_id: the server uses CACHLY_BRAIN_INSTANCE_ID if
|
|
|
66
66
|
session_start gives a briefing at the start of a session; it does not replace smart_recall for a concrete task.`,It={tools:{},resources:{},prompts:{}},Et=async()=>{const{katalog:e,unbekannteKernnamen:t}=ss(le);return t.length>0&&console.error(`cachly: ${t.length} Kernwerkzeug(e) gibt es gar nicht: ${t.join(", ")}`),{tools:e}};async function Rt(){return{resources:[]}}async function jt(){return{resourceTemplates:[]}}async function Bt(){return{prompts:[]}}function Rs(e){e.setRequestHandler(Qe,Et),e.setRequestHandler(qe,Ot),e.setRequestHandler(Ze,Rt),e.setRequestHandler(Ve,jt),e.setRequestHandler(Ge,Bt)}function js(){const e=new Ke({name:"cachly-mcp",version:H},{capabilities:It,instructions:Tt});return Rs(e),Nt(e),e}function Nt(e){const t=e.oninitialized;e.oninitialized=()=>{let n;try{n=e.getClientVersion(),Wt(n?.name,n?.version)}catch{}$t||($t=!0,A("mcp_verbunden",{client:String(n?.name??"unbekannt").slice(0,60),client_version:String(n?.version??"").slice(0,30)})),t?.()}}const K=new Ke({name:"cachly-mcp",version:H},{capabilities:It,instructions:Tt});Nt(K),K.setRequestHandler(Qe,Et),K.setRequestHandler(Ze,Rt),K.setRequestHandler(Ve,jt),K.setRequestHandler(Ge,Bt);let Se=null,de=!1,te=null,Pt=0;async function Bs(e){if(!de){if(te){await te;return}te=(async()=>{de=!0,Se=e;try{await J("session_start",{instance_id:e,focus:"auto (MCP session)",workspace_path:process.cwd()})}catch{}finally{te=null}})(),await te,Lt(e)}}function Ns(e){de=!0,Se=e}function Lt(e){process.env.CACHLY_AUTO_INDEX!=="false"&&(async()=>{const t=await O(e),n=await t.get(`cachly:index:last_indexed:${e}`),o=1440*60*1e3;(!n||Date.now()-parseInt(n,10)>o)&&(await t.set(`cachly:index:last_indexed:${e}`,String(Date.now()),"EX",9e4),await J("index_project",{instance_id:e,dir:process.cwd(),max_files:150,ttl:86400*7,namespace:"cachly:sem:code",hintergrund:!0}))})().catch(()=>{})}async function De(){if(!(!de||!Se)){de=!1;try{await J("session_end",{instance_id:Se,summary:`Auto-ended after ${Pt} tool call(s). Session was started automatically.`,files_changed:[],lessons_learned:0})}catch{}}}const Ot=async e=>{let{name:t,arguments:n}=e.params;if(t===bt){const i=n??{},a=typeof i.tool=="string"?i.tool:"";if(!a)return{content:[{type:"text",text:'cachly_tool braucht das Feld "tool" \u2014 den Namen des Werkzeugs.'}],isError:!0};const r=le.find(d=>d.name===a);if(!r)return{content:[{type:"text",text:`Kein Werkzeug namens "${a}". Die Liste steht in der Beschreibung von ${bt}.`}],isError:!0};if(i.describe===!0)return{content:[{type:"text",text:JSON.stringify({name:r.name,description:r.description,inputSchema:r.inputSchema},null,2)}]};t=a,n=i.arguments??{}}if(!["learn_from_attempts","smart_recall","recall_feedback"].includes(t)){const i=le.find(r=>r.name===t),a=i?is(t,i.inputSchema,n??{}):null;if(a)return{content:[{type:"text",text:a}],isError:!0}}const o=$e(n?.instance_id)||N||$e(process.env.CACHLY_BRAIN_INSTANCE_ID)||"",s=Mn(t,{gestartet:de,startetGerade:te!==null,instanz:o});s==="starten"?await Bs(o).catch(()=>{}):s==="abwarten"?await te?.catch(()=>{}):s==="als-gestartet-merken"&&Ns(o),Dn.has(t)||Pt++;try{os(),F(`werkzeug ${t}: Anfang`);const i=await J(t,n??{});return F(`werkzeug ${t}: Antwort fertig`),s==="als-gestartet-merken"&&Lt(o),{content:[{type:"text",text:bn(t,i)+qn()+es(t)}]}}catch(i){if(i instanceof Ct)return{content:[{type:"text",text:i.message}],isError:!0};if(i instanceof Q)throw i;const a=i.message??String(i);throw Fe("cachly","tool_error",{tool:t,error:a}).catch(()=>{}),new Q(ne.InternalError,a)}};K.setRequestHandler(qe,Ot),process.on("SIGTERM",async()=>{await De().catch(()=>{});for(const[,e]of X)await e.quit().catch(()=>{});process.exit(0)}),process.on("SIGINT",async()=>{await De().catch(()=>{});for(const[,e]of X)await e.quit().catch(()=>{});process.exit(0)}),process.on("unhandledRejection",e=>{const t=e instanceof Error?e.message:String(e);process.stderr.write(`[cachly-mcp] unhandledRejection: ${t}
|
|
67
67
|
`)}),process.on("uncaughtException",e=>{process.stderr.write(`[cachly-mcp] uncaughtException: ${e?.stack??String(e)}
|
|
68
68
|
`)}),process.stdout.on("error",()=>{}),process.stdin.on("error",()=>{});function Ps(e,t){const n=Object.entries(t).map(([o,s])=>`${o}=${s}`);return e==="codex"?{befehl:`codex mcp add cachly ${n.map(o=>`--env ${o}`).join(" ")} -- npx -y @cachly-dev/mcp-server@latest`,wo:"~/.codex/config.toml"}:e==="gemini"?{befehl:`gemini mcp add -s project ${n.map(o=>`-e ${o}`).join(" ")} cachly npx -- -y @cachly-dev/mcp-server@latest`,wo:".gemini/settings.json"}:null}const Ht="https://api.cachly.dev";function Z(e,t,n={}){const o={CACHLY_BRAIN_INSTANCE_ID:t};return n.includeApiKey&&(o.CACHLY_JWT=e),x&&x!==Ht&&(o.CACHLY_API_URL=x),o}function Ls(e,t,n){return n==="continue"?JSON.stringify({experimental:{modelContextProtocolServers:[{transport:{type:"stdio",command:"npx",args:["-y","@cachly-dev/mcp-server@latest"]},env:Z(e,t)}]}},null,2):n==="zed"?JSON.stringify({context_servers:{cachly:{command:{path:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:Z(e,t)},settings:{}}}},null,2):Mt(n)?JSON.stringify({servers:{cachly:{type:"stdio",command:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:Z(e,t)}}},null,2):JSON.stringify({mcpServers:{cachly:{command:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:Z(e,t)}}},null,2)}function Mt(e){return ce[e]===".vscode/mcp.json"}function he(e,t){Sn(e)||ee(e,t)}async function Dt(e,t,n,o,s,i={}){const a={command:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:Z(t,n)};if(!s.existsSync(e))return Ls(t,n,o);let r={};try{r=JSON.parse(await s.readFile(e,"utf-8"))}catch{try{const{rename:u}=await import("node:fs/promises");await u(e,e+".bak"),process.stderr.write(`\u26A0\uFE0F ${e} was not valid JSON \u2014 backed up to ${e}.bak
|
|
69
|
-
`)}catch{}}if(o==="continue"){const u=r.experimental??{},y=u.modelContextProtocolServers??[];let b;for(const m of y){const c=m.env??{};if(c.CACHLY_JWT){b=c.CACHLY_JWT;break}}b&&he(b,i);const
|
|
69
|
+
`)}catch{}}if(o==="continue"){const u=r.experimental??{},y=u.modelContextProtocolServers??[];let b;for(const m of y){const c=m.env??{};if(c.CACHLY_JWT){b=c.CACHLY_JWT;break}}b&&he(b,i);const v=y.filter(m=>{const c=m.env??{};return!c.CACHLY_JWT&&!c.CACHLY_BRAIN_INSTANCE_ID});return v.push({transport:{type:"stdio",command:"npx",args:["-y","@cachly-dev/mcp-server@latest"]},env:a.env}),r.experimental={...u,modelContextProtocolServers:v},JSON.stringify(r,null,2)}if(o==="zed"){const u=r.context_servers??{},b=u.cachly?.command?.env?.CACHLY_JWT;return b&&he(b,i),u.cachly={command:{path:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:a.env},settings:{}},r.context_servers=u,JSON.stringify(r,null,2)}if(Mt(o)){const u=r.mcpServers??void 0,b=u?.cachly?.env?.CACHLY_JWT;b&&he(b,i),u&&"cachly"in u&&(delete u.cachly,Object.keys(u).length===0&&delete r.mcpServers);const v=r.servers??{},m=v.cachly,c=m?.env?.CACHLY_JWT;return c&&he(c,i),v.cachly=m?.envFile?{type:"stdio",...a,envFile:m.envFile}:{type:"stdio",...a},r.servers=v,JSON.stringify(r,null,2)}const d=r.mcpServers??{},l=d.cachly?.env?.CACHLY_JWT;return l&&he(l,i),d.cachly=a,r.mcpServers=d,JSON.stringify(r,null,2)}async function zt(e,t,n,o){const{existsSync:s}=await import("node:fs"),{resolve:i}=await import("node:path"),{homedir:a}=await import("node:os"),r=n??a(),d=Zo.filter(u=>Xo(u,e,r,s,i,o)).map(u=>({path:i(e,...u.pfad),prefix:u.prefix})),f=lt(t),l={};for(const{path:u,prefix:y}of d)try{l[u]=await Qo(u,f,y)}catch(b){l[u]=`failed:${b.message}`}return l}function Ut(e,t){return t.startsWith("failed:")?`\u26A0\uFE0F Could not write ${e}: ${t.slice(7)} (the rest of the setup continues)`:t==="unchanged"?`\u2713 Unchanged: ${e}`:`${t==="updated"?"\u2705 Updated":t==="appended"?"\u2705 Appended to":"\u2705 Written"}: ${e}`}if(process.argv[2]==="digest"){const e=G(),t=z();(!e||!t)&&(console.log(`
|
|
70
70
|
\u26A0\uFE0F No cachly key or Brain instance found (environment or ~/.cachly/credentials.json).`),console.log(` Run: npx @cachly-dev/mcp-server@latest autopilot
|
|
71
71
|
`),process.exit(1)),process.stdout.write(`
|
|
72
72
|
\u{1F9E0} Fetching your weekly Brain digest...
|
|
73
73
|
|
|
74
|
-
`);try{const n=await fetch(`${x}/api/v1/instances/${t}/memory`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)});if(!n.ok)throw new Error(`stats HTTP ${n.status}`);const o=await n.json(),s=o.lesson_count??0,i=o.total_recall_count??0,a=Math.round(o.iq_boost_pct??0),r=(o.top_lessons??[]).slice(0,5),d=o.team_authors??[],f=i*1200,l=s<10?"Junior Dev \u{1F527}":s<30?"Mid Dev \u26A1":s<60?"Senior Dev \u{1F9E0}":s<100?"Staff Eng \u{1F680}":"Principal Eng \u{1F3C6}",u=new Date,y=new Date(u);y.setDate(u.getDate()-7);const b=p=>p.toLocaleDateString("en-US",{month:"short",day:"numeric"});if(console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log(`\u2502 \x1B[1m\u{1F9E0} Brain Weekly Digest\x1B[0m \x1B[90m${b(y)} \u2013 ${b(u)}\x1B[0m \u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total lessons : \x1B[33m${String(s).padEnd(8)}\x1B[0m Brain level : \x1B[32m${l.padEnd(18)}\x1B[0m\u2502`),console.log(`\u2502 Total recalls : \x1B[36m${String(i).padEnd(8)}\x1B[0m Quality score: \x1B[32m${String(a).padEnd(3)}%\x1B[0m \u2502`),console.log(`\u2502 Tokens saved : \x1B[32m${("~"+Math.round(f/1e3)+"K (est.)").padEnd(42)}\x1B[0m\u2502`),d.length>0&&(console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 \x1B[36m\u{1F465} Team contributors:\x1B[0m ${d.slice(0,5).join(", ").slice(0,42).padEnd(42)} \u2502`)),r.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[33m\u{1F525} Most recalled lessons this week:\x1B[0m \u2502");for(const p of r){const g=`${p.topic}: ${p.what_worked}`.slice(0,57);console.log(`\u2502 \x1B[90m\u2022 ${g.padEnd(58)}\x1B[0m\u2502`)}}console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("");const
|
|
74
|
+
`);try{const n=await fetch(`${x}/api/v1/instances/${t}/memory`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)});if(!n.ok)throw new Error(`stats HTTP ${n.status}`);const o=await n.json(),s=o.lesson_count??0,i=o.total_recall_count??0,a=Math.round(o.iq_boost_pct??0),r=(o.top_lessons??[]).slice(0,5),d=o.team_authors??[],f=i*1200,l=s<10?"Junior Dev \u{1F527}":s<30?"Mid Dev \u26A1":s<60?"Senior Dev \u{1F9E0}":s<100?"Staff Eng \u{1F680}":"Principal Eng \u{1F3C6}",u=new Date,y=new Date(u);y.setDate(u.getDate()-7);const b=p=>p.toLocaleDateString("en-US",{month:"short",day:"numeric"});if(console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log(`\u2502 \x1B[1m\u{1F9E0} Brain Weekly Digest\x1B[0m \x1B[90m${b(y)} \u2013 ${b(u)}\x1B[0m \u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total lessons : \x1B[33m${String(s).padEnd(8)}\x1B[0m Brain level : \x1B[32m${l.padEnd(18)}\x1B[0m\u2502`),console.log(`\u2502 Total recalls : \x1B[36m${String(i).padEnd(8)}\x1B[0m Quality score: \x1B[32m${String(a).padEnd(3)}%\x1B[0m \u2502`),console.log(`\u2502 Tokens saved : \x1B[32m${("~"+Math.round(f/1e3)+"K (est.)").padEnd(42)}\x1B[0m\u2502`),d.length>0&&(console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 \x1B[36m\u{1F465} Team contributors:\x1B[0m ${d.slice(0,5).join(", ").slice(0,42).padEnd(42)} \u2502`)),r.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[33m\u{1F525} Most recalled lessons this week:\x1B[0m \u2502");for(const p of r){const g=`${p.topic}: ${p.what_worked}`.slice(0,57);console.log(`\u2502 \x1B[90m\u2022 ${g.padEnd(58)}\x1B[0m\u2502`)}}console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("");const v=r[0],m=[`\u{1F9E0} My AI Brain weekly digest (${b(y)} \u2013 ${b(u)}):`,"",` \u{1F4DA} ${s} lessons learned`,` \u{1F501} ${i} recalls \xB7 ~${Math.round(f/1e3)}K tokens saved`,` \u{1F3AF} Brain Level: ${l}`,v?` \u{1F525} Top lesson: "${v.topic}: ${v.what_worked.slice(0,60)}${v.what_worked.length>60?"\u2026":""}"`:"","","Built with @cachly_dev \u2014 AI that actually remembers \u{1F680}","cachly.dev"].filter(Boolean).join(`
|
|
75
75
|
`),c="https://twitter.com/intent/tweet?text="+encodeURIComponent(m);console.log("\x1B[1m\u{1F4E3} Share your digest:\x1B[0m"),console.log(""),console.log("\x1B[90m"+"\u2500".repeat(63)+"\x1B[0m");for(const p of m.split(`
|
|
76
76
|
`))console.log(` ${p}`);console.log("\x1B[90m"+"\u2500".repeat(63)+"\x1B[0m"),console.log(""),console.log(" \x1B[36m\u{1F426} Tweet this:\x1B[0m"),console.log(` \x1B[4m${c.slice(0,90)}...\x1B[0m`),console.log(""),console.log(" \x1B[2m\u{1F4A1} Invite your team: npx @cachly-dev/mcp-server@latest invite <email>\x1B[0m"),console.log(" \x1B[2m Cron: 0 9 * * 1 npx @cachly-dev/mcp-server@latest digest\x1B[0m"),console.log("")}catch(n){console.log(`
|
|
77
77
|
\u274C Could not fetch digest: ${n.message}
|
|
@@ -82,7 +82,7 @@ session_start gives a briefing at the start of a session; it does not replace sm
|
|
|
82
82
|
`),process.exit(1)),process.stdout.write(`
|
|
83
83
|
\u{1F4E4} Exporting your Brain...
|
|
84
84
|
|
|
85
|
-
`);try{let f=[],l="";const u=await fetch(`${x}/api/v1/instances/${d}/export`,{headers:{Authorization:`Bearer ${r}`},signal:AbortSignal.timeout(12e4)});if(u.ok){const b=await u.json();f=(b.lessons??[]).map(cs).filter(
|
|
85
|
+
`);try{let f=[],l="";const u=await fetch(`${x}/api/v1/instances/${d}/export`,{headers:{Authorization:`Bearer ${r}`},signal:AbortSignal.timeout(12e4)});if(u.ok){const b=await u.json();f=(b.lessons??[]).map(cs).filter(v=>v!==null),b.complete===!1?l=b.note??"the server reported an incomplete read":typeof b.lesson_count=="number"&&f.length<b.lesson_count&&(l=`the server counts ${b.lesson_count} lessons, but only ${f.length} could be read as lessons`)}else if(u.status===404){const b=await fetch(`${x}/api/v1/instances/${d}/memory`,{headers:{Authorization:`Bearer ${r}`},signal:AbortSignal.timeout(8e3)});if(!b.ok)throw new Error(`memory HTTP ${b.status}`);f=((await b.json()).top_lessons??[]).map(m=>({topic:m.topic,outcome:m.outcome,severity:m.severity,tags:m.tags,whatWorked:m.what_worked,ts:m.ts,author:m.author,recallCount:m.recall_count})),l="this server has no /export endpoint yet, so this is the DASHBOARD SUMMARY: at most 50 lessons, each shortened to 120 characters. Update the server for a full export."}else throw new Error(`export HTTP ${u.status}`);f.length===0&&(console.log(` No lessons in this Brain yet \u2014 nothing to export.
|
|
86
86
|
`),process.exit(0)),await t(a,{recursive:!0});const y=[];if(i==="md"||i==="both"){const b=n(a,"lessons.md");await e(b,rs(f),"utf-8"),y.push(`${f.length} lesson${f.length===1?"":"s"} \u2192 ${b}`)}if(i==="jsonl"||i==="both"){const b=n(a,"lessons.jsonl");await e(b,as(f),"utf-8"),y.push(`${f.length} lesson${f.length===1?"":"s"} \u2192 ${b}`)}l?(console.log("\u26A0\uFE0F Export INCOMPLETE \u2014 this is not your whole Brain:"),console.log(` ${l}`),console.log("")):console.log("\u2705 Export complete:");for(const b of y)console.log(` ${b}`);console.log("")}catch(f){console.log(`
|
|
87
87
|
\u274C Could not export your Brain: ${f.message}
|
|
88
88
|
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="invite"){const e=G(),t=(process.argv[3]??"").trim();(!t||t.startsWith("-"))&&(console.log(`
|
|
@@ -116,7 +116,7 @@ Try it free: ${o}
|
|
|
116
116
|
`),process.exit(1));let l=S;if(!l){console.log(`
|
|
117
117
|
No API key found \u2014 starting sign-in (10 seconds)...
|
|
118
118
|
`);try{const g=await fetch(`${x}/api/v1/auth/device/code`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:"cachly-mcp-cli"}),signal:AbortSignal.timeout(1e4)});if(g.ok){const C=await g.json();console.log(` \u{1F449} Open: \x1B[36m${C.verification_uri}\x1B[0m`),console.log(` Code: \x1B[1m${C.user_code}\x1B[0m
|
|
119
|
-
`);const
|
|
119
|
+
`);const w=(C.interval??5)*1e3;for(let _=0;_<24;_++){await new Promise(k=>setTimeout(k,w));try{const k=await fetch(`${x}/api/v1/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:C.device_code,client_id:"cachly-mcp-cli"}),signal:AbortSignal.timeout(8e3)});if(k.ok){const I=await k.json();if(I.access_token){l=I.access_token;break}}}catch{}}l||(console.log(`
|
|
120
120
|
\u274C Sign-in timed out. Run the command again.
|
|
121
121
|
`),process.exit(1)),console.log(` \u2705 Signed in!
|
|
122
122
|
`)}}catch(g){console.log(`
|
|
@@ -139,14 +139,14 @@ Try it free: ${o}
|
|
|
139
139
|
\u274C This old link type does not give access to the Brain.`),console.log(` Ask the owner for a new invitation: npx @cachly-dev/mcp-server@latest invite <your-email>
|
|
140
140
|
`)):(console.log(`
|
|
141
141
|
\u274C Could not accept the invitation: ${C}.`),console.log(` The token may be wrong, expired or already used. Ask for a new invitation.
|
|
142
|
-
`)),process.exit(1)}const
|
|
142
|
+
`)),process.exit(1)}const w=(g.instances??[]).filter(k=>k&&k.id);w.length===0&&(console.log(`
|
|
143
143
|
\u2705 Invitation accepted, but this organisation has no Brain yet.`),console.log(` When the owner adds one, connect it with: npx @cachly-dev/mcp-server@latest join --brain <instance-id>
|
|
144
|
-
`),process.exit(0));let _=
|
|
145
|
-
This organisation has several Brains:`),
|
|
144
|
+
`),process.exit(0));let _=w[0];if(w.length>1){console.log(`
|
|
145
|
+
This organisation has several Brains:`),w.forEach(($,R)=>console.log(` ${R+1}) ${$.name??$.id} (${$.id})`));const k=r({input:process.stdin,output:process.stdout}),I=await new Promise($=>{k.question(" Which one? [1] ",R=>{k.close(),$(R.trim()||"1")})}),E=Number.parseInt(I,10);(!Number.isInteger(E)||E<1||E>w.length)&&(console.log(`
|
|
146
146
|
Cancelled.
|
|
147
|
-
`),process.exit(1)),_=
|
|
147
|
+
`),process.exit(1)),_=w[E-1]}y=_.id,b=_.name??_.id,console.log(`
|
|
148
148
|
\u2705 Invitation accepted. Brain: \x1B[1m${b}\x1B[0m
|
|
149
|
-
`)}l!==S&&ee(l);const
|
|
149
|
+
`)}l!==S&&ee(l);const v=process.cwd(),m=a(),c=[{label:".mcp.json (Claude Code project)",path:s(v,".mcp.json")},{label:".cursor/mcp.json",path:s(v,".cursor","mcp.json")},{label:".windsurf/mcp.json",path:s(v,".windsurf","mcp.json")},{label:".vscode/mcp.json (Copilot/Cline)",path:s(v,".vscode","mcp.json")},{label:"~/.claude/mcp.json (global)",path:s(m,".claude","mcp.json"),global:!0}];let p=0;for(const{label:g,path:C,global:w}of c){const _=i(C);if(!(!w&&!o(_)&&!o(C)))try{await n(_,{recursive:!0});let k={};if(o(C))try{k=JSON.parse(await t(C,"utf-8"))}catch{try{await(await import("node:fs/promises")).rename(C,C+".bak")}catch{}}const I=k.mcpServers??{},E=I.cachly??{},$=E.env??{};$.CACHLY_BRAIN_INSTANCE_ID=y,l&&w&&!$.CACHLY_JWT&&($.CACHLY_JWT=l),x!==Ht&&($.CACHLY_API_URL=x),I.cachly={...E,command:"npx",args:["-y","@cachly-dev/mcp-server@latest"],env:$},k.mcpServers=I,await e(C,JSON.stringify(k,null,2),"utf-8"),console.log(` \u2705 ${g}`),p++}catch(k){k.code!=="ENOENT"&&console.log(` \u26A0\uFE0F ${g}: ${k.message}`)}}console.log(""),p===0?console.log(" \u26A0\uFE0F No editor configs found \u2014 run `cachly setup` first.\n"):(console.log(` \u{1F9E0} You're now sharing Brain: \x1B[1m${b}\x1B[0m`),console.log(` Restart your editor \u2014 your AI arrives pre-briefed from the team Brain.
|
|
150
150
|
`),console.log(" \u{1F4DB} Add the badge to your README:"),console.log(` npx @cachly-dev/mcp-server@latest badge
|
|
151
151
|
`)),process.exit(0)}if(process.argv[2]==="upgrade"){process.stdout.write(`
|
|
152
152
|
\u23F3 Checking for updates...
|
|
@@ -154,7 +154,7 @@ Try it free: ${o}
|
|
|
154
154
|
\u2705 Already on the latest version: \x1B[32mv${H}\x1B[0m
|
|
155
155
|
`):(console.log(""),console.log("\x1B[35m \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\x1B[0m"),console.log("\x1B[35m \u2551\x1B[0m \x1B[1m\u{1F9E0} cachly update available\x1B[0m \x1B[35m\u2551\x1B[0m"),console.log("\x1B[35m \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\x1B[0m"),console.log(""),console.log(` Current : \x1B[31mv${H}\x1B[0m`),console.log(` Latest : \x1B[32mv${n}\x1B[0m`),console.log(""),console.log(" Update your editor configs to pick up the new version:"),console.log(""),console.log(" \x1B[32m npx @cachly-dev/mcp-server@latest autopilot\x1B[0m"),console.log(""),console.log(" \x1B[2m(npx always fetches the latest when @latest is specified)\x1B[0m"),console.log(""))}catch(e){console.log(`
|
|
156
156
|
\u274C Could not check for updates: ${e.message}
|
|
157
|
-
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="bench"){const{fileURLToPath:e}=await import("node:url"),{dirname:t,resolve:n}=await import("node:path"),{loadExternalCorpus:o,runExternalBenchmark:s}=await import("./bench/external-corpus.js"),i=process.argv.includes("--json"),a=process.argv.slice(3).find(f=>!f.startsWith("--")),r=t(e(import.meta.url)),d=a?n(process.cwd(),a):n(r,"bench","external","sample-corpus.json");try{const f=await o(d),l=await s(f);i&&(console.log(JSON.stringify({corpus:f.name,lessons:l.corpusSize,queries:l.queryCount,cachly_p1:Math.round(l.cachly.precisionAt1*1e3)/10,flatfile_p1:Math.round(l.flatfile.precisionAt1*1e3)/10,cachly_mrr:Math.round(l.cachly.mrr*1e3)/10,flatfile_mrr:Math.round(l.flatfile.mrr*1e3)/10,p1_lift_vs_flatfile_pct:Math.round((l.cachly.precisionAt1-l.flatfile.precisionAt1)*1e3)/10,mrr_lift_vs_flatfile_pct:Math.round((l.cachly.mrr-l.flatfile.mrr)*1e3)/10},null,2)),process.exit(0));const u=((l.cachly.precisionAt1-l.flatfile.precisionAt1)*100).toFixed(1),y=((l.cachly.mrr-l.flatfile.mrr)*100).toFixed(1),b=((l.cachly.precisionAt1-l.baseline.precisionAt1)*100).toFixed(1),
|
|
157
|
+
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="bench"){const{fileURLToPath:e}=await import("node:url"),{dirname:t,resolve:n}=await import("node:path"),{loadExternalCorpus:o,runExternalBenchmark:s}=await import("./bench/external-corpus.js"),i=process.argv.includes("--json"),a=process.argv.slice(3).find(f=>!f.startsWith("--")),r=t(e(import.meta.url)),d=a?n(process.cwd(),a):n(r,"bench","external","sample-corpus.json");try{const f=await o(d),l=await s(f);i&&(console.log(JSON.stringify({corpus:f.name,lessons:l.corpusSize,queries:l.queryCount,cachly_p1:Math.round(l.cachly.precisionAt1*1e3)/10,flatfile_p1:Math.round(l.flatfile.precisionAt1*1e3)/10,cachly_mrr:Math.round(l.cachly.mrr*1e3)/10,flatfile_mrr:Math.round(l.flatfile.mrr*1e3)/10,p1_lift_vs_flatfile_pct:Math.round((l.cachly.precisionAt1-l.flatfile.precisionAt1)*1e3)/10,mrr_lift_vs_flatfile_pct:Math.round((l.cachly.mrr-l.flatfile.mrr)*1e3)/10},null,2)),process.exit(0));const u=((l.cachly.precisionAt1-l.flatfile.precisionAt1)*100).toFixed(1),y=((l.cachly.mrr-l.flatfile.mrr)*100).toFixed(1),b=((l.cachly.precisionAt1-l.baseline.precisionAt1)*100).toFixed(1),v=l.cachly.precisionAt1>=l.flatfile.precisionAt1?"\x1B[32m+":"\x1B[31m",m=l.cachly.mrr>=l.flatfile.mrr?"\x1B[32m+":"\x1B[31m";console.log(""),console.log("\x1B[35m \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\x1B[0m"),console.log("\x1B[35m \u2551\x1B[0m \x1B[1m\u{1F9E0} cachly recall quality benchmark\x1B[0m \x1B[35m\u2551\x1B[0m"),console.log("\x1B[35m \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\x1B[0m"),console.log(""),console.log(` Corpus : ${f.name??d}`),console.log(` Dataset: ${l.corpusSize} lessons \xB7 ${l.queryCount} queries \xB7 10 engineering domains`),console.log(" (k8s, DB, auth, CI, frontend, API, payments, observability, Node.js, infra)"),console.log(""),console.log(" \x1B[1mPrecision@1\x1B[0m (finds the right lesson at rank #1):"),console.log(` flat-file memory : \x1B[33m${(l.flatfile.precisionAt1*100).toFixed(1)}%\x1B[0m (naive keyword overlap \u2014 no quality signal)`),console.log(` raw BM25 : \x1B[33m${(l.baseline.precisionAt1*100).toFixed(1)}%\x1B[0m (keyword ranking)`),console.log(` cachly : \x1B[1m\x1B[32m${(l.cachly.precisionAt1*100).toFixed(1)}%\x1B[0m (BM25 + quality reranking)`),console.log(""),console.log(" \x1B[1mMean Reciprocal Rank\x1B[0m (average rank of the right answer):"),console.log(` flat-file memory : \x1B[33m${(l.flatfile.mrr*100).toFixed(1)}%\x1B[0m`),console.log(` raw BM25 : \x1B[33m${(l.baseline.mrr*100).toFixed(1)}%\x1B[0m`),console.log(` cachly : \x1B[1m\x1B[32m${(l.cachly.mrr*100).toFixed(1)}%\x1B[0m`),console.log(""),console.log(" \x1B[1mLift vs flat-file memory\x1B[0m (what you get by switching from plain memory files):"),console.log(` Precision@1 : ${v}${u}%\x1B[0m`),console.log(` MRR : ${m}${y}%\x1B[0m`),console.log(` vs BM25 : \x1B[32m+${b}%\x1B[0m Precision@1 (quality reranking on top of keyword search)`),console.log(""),console.log(" \x1B[2mFlat-file = lexical overlap over raw text files (how Anthropic/Claude Memory works).\x1B[0m"),console.log(" \x1B[2mAdversarial distractors included \u2014 failure lessons that share the exact query vocabulary.\x1B[0m"),console.log(" \x1B[2mcachly ignores them because they have low confidence / failed outcome.\x1B[0m"),console.log(""),console.log(" Share your results:"),console.log(` \x1B[36m"My Brain: Precision@1 ${(l.cachly.precisionAt1*100).toFixed(1)}% (${v}${u}% vs flat-file memory, ${l.queryCount} queries)"\x1B[0m`),console.log(""),console.log(" Run on a custom corpus:"),console.log(" \x1B[2m npx @cachly-dev/mcp-server@latest bench my-incidents.json\x1B[0m"),console.log(" \x1B[2m npx @cachly-dev/mcp-server@latest bench --json # machine-readable\x1B[0m"),console.log(""),console.log(" \x1B[1m\u2192 Give your AI this recall quality on your own work (free, 1\u20135 min):\x1B[0m"),console.log(" \x1B[32m$ npx @cachly-dev/mcp-server@latest autopilot\x1B[0m"),console.log(" \x1B[90m Signs in, configures every editor, bootstraps from your git history.\x1B[0m"),console.log(` \x1B[90m Or create your Brain at: \x1B[36m${j("/setup-ai","bench")}\x1B[0m`),console.log("")}catch(f){console.error(`
|
|
158
158
|
\u274C bench failed: ${f.message}
|
|
159
159
|
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="demo"){const{existsSync:e,readFileSync:t}=await import("node:fs"),{resolve:n,basename:o}=await import("node:path"),s=process.cwd();console.log(`
|
|
160
160
|
\x1B[35m\u{1F9E0} cachly Brain \u2014 Live Demo\x1B[0m`),console.log(`\x1B[90mNo account needed. Reading your git history...\x1B[0m
|
|
@@ -163,7 +163,7 @@ Try it free: ${o}
|
|
|
163
163
|
`),process.exit(0));let i="";try{i=ut(s,["config","user.name"]).trim().split(" ")[0]??""}catch{}let a=o(s);try{const $=JSON.parse(t(n(s,"package.json"),"utf-8"));$.name&&(a=$.name.replace(/^@[^/]+\//,""))}catch{}let r="";try{r=ut(s,["log","HEAD","--pretty=format:%H|||%s|||%ad|||%an","--date=short","--no-merges","-n","200"],{timeoutMs:3e4})}catch{console.log(`\u26A0\uFE0F Could not read git log. Make sure you have commits.
|
|
164
164
|
`),process.exit(0)}const d=r.trim().split(`
|
|
165
165
|
`).filter(Boolean).map($=>{const[R,M,Te,oe]=$.split("|||");return{sha:(R??"").trim().slice(0,8),subject:(M??"").trim(),date:(Te??"").trim(),author:(oe??"").trim()}});d.length===0&&(console.log(`\u26A0\uFE0F No commits found.
|
|
166
|
-
`),process.exit(0));const f=new Map,l=[],u=[],y=[],b=new Set;let
|
|
166
|
+
`),process.exit(0));const f=new Map,l=[],u=[],y=[],b=new Set;let v=0;for(const $ of d){const R=bs($.subject);f.set(R,(f.get(R)??0)+1),ws($.subject)&&v++,R==="fix"&&l.length<5&&l.push($.subject.slice(0,72)),R==="feat"&&u.length<5&&u.push($.subject.slice(0,72)),R==="security"&&y.length<3&&y.push($.subject.slice(0,72)),$.author&&b.add($.author)}const m=vs(d.map($=>$.subject)),c=`${d[d.length-1]?.date??"?"} \u2192 ${d[0]?.date??"?"}`,p=m>=501?"Oracle":m>=201?"Architect":m>=51?"Expert":m>=11?"Explorer":"Apprentice",C=`${i?`Hey ${i} \u2014 `:""}here's what your AI would know about ${a}`;process.stdout.write("\x1B[2K\r"),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log(`\u2502 \x1B[1m\u{1F9E0} ${C.slice(0,58).padEnd(58)}\x1B[0m\u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Commits analysed : \x1B[33m${String(d.length).padEnd(6)}\x1B[0m Date range: \x1B[90m${c.slice(0,23).padEnd(23)}\x1B[0m \u2502`),console.log(`\u2502 Lessons extracted: \x1B[32m${String(m).padEnd(6)}\x1B[0m Contributors: \x1B[36m${String(b.size).padEnd(20)}\x1B[0m\u2502`),console.log(`\u2502 Brain Level : \x1B[35m${p.padEnd(10)}\x1B[0m Reverts: \x1B[33m${String(v).padEnd(21)}\x1B[0m\u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524");const w=[...f.entries()].filter(([$])=>$!=="chore").sort(($,R)=>R[1]-$[1]),_=($,R)=>"\u2588".repeat(Math.round($/R*20)).padEnd(20),k=Math.max(...w.map(([,$])=>$),1);console.log("\u2502 \x1B[90mCategory breakdown:\x1B[0m \u2502");for(const[$,R]of w){const M={fix:"\u{1F527}",feat:"\u2728",perf:"\u26A1",security:"\u{1F512}",deploy:"\u{1F680}",refactor:"\u{1F504}"}[$]??"\u2022";console.log(`\u2502 ${M} \x1B[36m${$.padEnd(10)}\x1B[0m \x1B[35m${_(R,k)}\x1B[0m \x1B[33m${String(R).padStart(3)}\x1B[0m \u2502`)}if(y.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[31m\u{1F512} Security fixes your AI would know:\x1B[0m \u2502");for(const $ of y)console.log(`\u2502 \x1B[90m\u2022 ${$.slice(0,58).padEnd(58)}\x1B[0m \u2502`)}if(l.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[33m\u{1F527} Bug fixes your AI would never repeat:\x1B[0m \u2502");for(const $ of l.slice(0,4))console.log(`\u2502 \x1B[90m\u2022 ${$.slice(0,58).padEnd(58)}\x1B[0m \u2502`)}if(u.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[32m\u2728 Features & decisions it would recall:\x1B[0m \u2502");for(const $ of u.slice(0,3))console.log(`\u2502 \x1B[90m\u2022 ${$.slice(0,58).padEnd(58)}\x1B[0m \u2502`)}console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log("\u2502 \x1B[32m\u{1F4A1} With cachly, your AI arrives pre-briefed every session.\x1B[0m \u2502"),console.log("\u2502 \x1B[32m No more re-explaining. No more repeated mistakes.\x1B[0m \u2502"),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("");const I=new URLSearchParams({repo:a,commits:String(d.length),lessons:String(m),level:p,authors:String(b.size),reverts:String(v)}),E=j(`/preview?${I.toString()}`,"demo");console.log(" \x1B[1mMake this permanent (free, 1\u20135 minutes):\x1B[0m"),console.log(" \x1B[32m$ npx @cachly-dev/mcp-server@latest autopilot\x1B[0m"),console.log(""),console.log(` \x1B[90m\u{1F517} Shareable preview:\x1B[0m \x1B[36m${E}\x1B[0m`),console.log(""),console.log(" Works with: Claude Code \xB7 Cursor \xB7 Windsurf \xB7 Copilot \xB7 Cline \xB7 Zed"),console.log(" GDPR \xB7 German servers \xB7 free tier, no credit card"),console.log(""),process.exit(0)}if(process.argv[2]==="share"){const e=G(),t=z();(!e||!t)&&(console.log(`
|
|
167
167
|
\u26A0\uFE0F No cachly key or Brain instance found (environment or ~/.cachly/credentials.json).`),console.log(` Run: npx @cachly-dev/mcp-server@latest autopilot (takes 1\u20135 minutes)
|
|
168
168
|
`),process.exit(1)),process.stdout.write(`
|
|
169
169
|
\u{1F9E0} Fetching your Brain stats...
|
|
@@ -193,32 +193,32 @@ ${f}
|
|
|
193
193
|
\u26A0\uFE0F No Brain instance found (environment or ~/.cachly/credentials.json).`),console.log(` Run: npx @cachly-dev/mcp-server@latest autopilot (takes 1\u20135 minutes)
|
|
194
194
|
`),process.exit(1));const t=`${x}/api/v1/badge/${e}`,n=j("/","badge"),o=`[](${n})`,s=`<a href="${n}"><img src="${t}" alt="cachly Brain" /></a>`;console.log(""),console.log("\x1B[35m \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\x1B[0m"),console.log("\x1B[35m \u2551\x1B[0m \x1B[1m\u{1F9E0} cachly Brain Badge\x1B[0m \x1B[35m\u2551\x1B[0m"),console.log("\x1B[35m \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\x1B[0m"),console.log(""),console.log(" Paste into your README.md:"),console.log(""),console.log(` \x1B[32m${o}\x1B[0m`),console.log(""),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(" Or paste into HTML:"),console.log(""),console.log(` \x1B[36m${s}\x1B[0m`),console.log(""),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(" Badge URL (live, updates every hour):"),console.log(` \x1B[90m${t}\x1B[0m`),console.log(""),console.log(" \x1B[2mThe badge shows your current lesson count \u2014 no auth required,"),console.log(" safe to embed in public repos. Updates hourly.\x1B[0m"),console.log(""),process.exit(0)}const fe=en(process.argv[2],process.stdin.isTTY===!0&&process.stdout.isTTY===!0);if(fe==="version"&&(process.stdout.write(`${H}
|
|
195
195
|
`,()=>process.exit(0)),await new Promise(()=>{})),fe==="unbekannt"&&console.error(`
|
|
196
|
-
Unknown command: ${process.argv[2]}`),!process.argv[2]&&process.stdout.isTTY||fe==="hilfe"||fe==="unbekannt"){console.log(""),console.log("\x1B[35m \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\x1B[0m"),console.log("\x1B[35m \u2551\x1B[0m \x1B[1m\u{1F9E0} cachly \u2014 Persistent AI Memory for Developers\x1B[0m \x1B[35m\u2551\x1B[0m"),console.log("\x1B[35m \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\x1B[0m"),console.log(""),console.log(" Stop re-teaching your AI every morning."),console.log(" cachly gives it a permanent brain \u2014 pre-briefed every session."),console.log("");const e=(t,n)=>console.log(` \x1B[36m ${t.padEnd(22)}\x1B[0m ${n}`);console.log(" \x1B[1mStart:\x1B[0m \x1B[1m\x1B[32mnpx @cachly-dev/mcp-server@latest autopilot\x1B[0m \u2190 \x1B[1mOne command, fully ready\x1B[0m"),console.log(" Every command below runs as: npx @cachly-dev/mcp-server@latest <command>"),console.log(""),console.log(" \x1B[1mEvery day:\x1B[0m"),e("status","Lessons, recalls and team at a glance"),e("ambient-stats","Tokens injected vs saved \u2014 the honest net, even when negative"),e("doctor","Diagnose a broken or missing install"),e("health","Check key, API, editor configs and git hook"),e("digest","What your Brain learned this week"),console.log(" \x1B[1mSet up:\x1B[0m"),e("demo","Try it first (no account)"),e("setup","Interactive setup (pick editors)"),e("init","Write the config for one editor (flags)"),e("claim","Keep a test Brain in your own account"),e("upgrade","Check for updates"),e("uninstall","Take cachly out of this project (--dry-run first)"),console.log(" \x1B[1mYour data:\x1B[0m"),e("export","Write your lessons to disk (md / jsonl)"),e("index [dir]","Index a project into the Brain (CI)"),e("learn-git [repo]","Learn lessons from recent commits (CI)"),console.log(" \x1B[1mTeam & sharing:\x1B[0m"),e("invite <email>","Share your Brain with a teammate (sends an email)"),e("join <token>","Accept an invitation to a shared Brain"),e("join --brain <id>","Connect a Brain you already have access to"),e("refer","Your referral link for new users"),e("share","Share your Brain stats"),e("publish","Publish an importable Brain snapshot"),e("badge","README badge for your Brain"),console.log(" \x1B[1mMore:\x1B[0m"),e("bench","Recall quality vs flat-file memory"),e("tool-specs | openapi","Tool definitions for other agent frameworks"),console.log(""),console.log(" \x1B[90mWorks with: Claude Code \xB7 Cursor \xB7 Windsurf \xB7 GitHub Copilot \xB7 Cline \xB7 Zed\x1B[0m"),console.log(` \x1B[90mGDPR \xB7 German servers \xB7 ${le.length} MCP tools\x1B[0m`),console.log(""),process.exit(fe==="unbekannt"?1:0)}const Os={cursor:{datei:".cursor/hooks.json",name:"Cursor",wie:"session briefing, per-prompt recall after the first tool call"},copilot:{datei:un,name:"VS Code / Copilot",wie:"session briefing, per-prompt recall"},codex:{datei:pn,name:"Codex",wie:"session briefing, per-prompt recall; trust it once in /hooks"},gemini:{datei:mn,name:"Gemini CLI",wie:"session briefing, per-prompt recall"}};function Hs(e,t,n){if(!t)return;const{datei:o,name:s,wie:i}=Os[e];if(t.hooks==="skipped"){console.log(`\u26A0\uFE0F ${n}${o} ${t.grund??"is not valid JSON"} \u2014 left untouched, ${s} hooks not wired`);return}const a=t.hooks==="unchanged"?"\u2713 ":"\u2705 ",r=t.hooks==="written"?"Written":t.hooks==="merged"?"Merged":"Already wired";console.log(`${a}${n}${r}: ${o} (Ambient Recall for ${s} \u2014 ${i})`)}async function ze(e,t,n,o){const s=e==="codex"?"Codex":"Gemini CLI",i=await(e==="codex"?$n:kn)(t,n).catch(()=>null);if(!i||i.status==="skipped"){const d=Ps(e,n);console.log(`\u26A0\uFE0F ${o}${i?`${i.datei} ${i.grund??"could not be read"} \u2014 left untouched.`:`${s} MCP entry could not be written.`} Register cachly yourself:`),d&&console.log(` ${o}${d.befehl}`);return}const a=i.status==="unchanged"?"\u2713 ":"\u2705 ",r=i.status==="written"?"Written":i.status==="updated"?"Updated":"Already configured";console.log(`${a}${o}${r}: ${i.datei} (MCP server cachly for ${s} \u2014 it asks once to trust this folder; until then the server stays off)`)}async function ye(e,t,n,o){const s={cursor:an,copilot:cn,codex:ln,gemini:dn}[e];Hs(e,await s(t,n).catch(()=>null),o)}if(process.argv[2]==="init"){const e=Date.now(),{writeFile:t,mkdir:n,readFile:o}=await import("node:fs/promises"),{resolve:s,dirname:i,relative:a}=await import("node:path"),r=process.argv.slice(3),d=
|
|
197
|
-
Missing value for ${f.map(
|
|
198
|
-
`),process.exit(1));let l=d("instance-id")??process.env.CACHLY_BRAIN_INSTANCE_ID,u=d("api-key")??process.env.CACHLY_JWT;const y=(d("editor")??"claude").toLowerCase(),b=s(d("project-dir")??"."),
|
|
196
|
+
Unknown command: ${process.argv[2]}`),!process.argv[2]&&process.stdout.isTTY||fe==="hilfe"||fe==="unbekannt"){console.log(""),console.log("\x1B[35m \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\x1B[0m"),console.log("\x1B[35m \u2551\x1B[0m \x1B[1m\u{1F9E0} cachly \u2014 Persistent AI Memory for Developers\x1B[0m \x1B[35m\u2551\x1B[0m"),console.log("\x1B[35m \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\x1B[0m"),console.log(""),console.log(" Stop re-teaching your AI every morning."),console.log(" cachly gives it a permanent brain \u2014 pre-briefed every session."),console.log("");const e=(t,n)=>console.log(` \x1B[36m ${t.padEnd(22)}\x1B[0m ${n}`);console.log(" \x1B[1mStart:\x1B[0m \x1B[1m\x1B[32mnpx @cachly-dev/mcp-server@latest autopilot\x1B[0m \u2190 \x1B[1mOne command, fully ready\x1B[0m"),console.log(" Every command below runs as: npx @cachly-dev/mcp-server@latest <command>"),console.log(""),console.log(" \x1B[1mEvery day:\x1B[0m"),e("status","Lessons, recalls and team at a glance"),e("ambient-stats","Tokens injected vs saved \u2014 the honest net, even when negative"),e("doctor","Diagnose a broken or missing install"),e("health","Check key, API, editor configs and git hook"),e("digest","What your Brain learned this week"),console.log(" \x1B[1mSet up:\x1B[0m"),e("demo","Try it first (no account)"),e("setup","Interactive setup (pick editors)"),e("init","Write the config for one editor (flags)"),e("claim","Keep a test Brain in your own account"),e("upgrade","Check for updates"),e("uninstall","Take cachly out of this project (--dry-run first)"),console.log(" \x1B[1mYour data:\x1B[0m"),e("export","Write your lessons to disk (md / jsonl)"),e("index [dir]","Index a project into the Brain (CI)"),e("learn-git [repo]","Learn lessons from recent commits (CI)"),console.log(" \x1B[1mTeam & sharing:\x1B[0m"),e("invite <email>","Share your Brain with a teammate (sends an email)"),e("join <token>","Accept an invitation to a shared Brain"),e("join --brain <id>","Connect a Brain you already have access to"),e("refer","Your referral link for new users"),e("share","Share your Brain stats"),e("publish","Publish an importable Brain snapshot"),e("badge","README badge for your Brain"),console.log(" \x1B[1mMore:\x1B[0m"),e("bench","Recall quality vs flat-file memory"),e("tool-specs | openapi","Tool definitions for other agent frameworks"),console.log(""),console.log(" \x1B[90mWorks with: Claude Code \xB7 Cursor \xB7 Windsurf \xB7 GitHub Copilot \xB7 Cline \xB7 Zed\x1B[0m"),console.log(` \x1B[90mGDPR \xB7 German servers \xB7 ${le.length} MCP tools\x1B[0m`),console.log(""),process.exit(fe==="unbekannt"?1:0)}const Os={cursor:{datei:".cursor/hooks.json",name:"Cursor",wie:"session briefing, per-prompt recall after the first tool call"},copilot:{datei:un,name:"VS Code / Copilot",wie:"session briefing, per-prompt recall"},codex:{datei:pn,name:"Codex",wie:"session briefing, per-prompt recall; trust it once in /hooks"},gemini:{datei:mn,name:"Gemini CLI",wie:"session briefing, per-prompt recall"}};function Hs(e,t,n){if(!t)return;const{datei:o,name:s,wie:i}=Os[e];if(t.hooks==="skipped"){console.log(`\u26A0\uFE0F ${n}${o} ${t.grund??"is not valid JSON"} \u2014 left untouched, ${s} hooks not wired`);return}const a=t.hooks==="unchanged"?"\u2713 ":"\u2705 ",r=t.hooks==="written"?"Written":t.hooks==="merged"?"Merged":"Already wired";console.log(`${a}${n}${r}: ${o} (Ambient Recall for ${s} \u2014 ${i})`)}async function ze(e,t,n,o){const s=e==="codex"?"Codex":"Gemini CLI",i=await(e==="codex"?$n:kn)(t,n).catch(()=>null);if(!i||i.status==="skipped"){const d=Ps(e,n);console.log(`\u26A0\uFE0F ${o}${i?`${i.datei} ${i.grund??"could not be read"} \u2014 left untouched.`:`${s} MCP entry could not be written.`} Register cachly yourself:`),d&&console.log(` ${o}${d.befehl}`);return}const a=i.status==="unchanged"?"\u2713 ":"\u2705 ",r=i.status==="written"?"Written":i.status==="updated"?"Updated":"Already configured";console.log(`${a}${o}${r}: ${i.datei} (MCP server cachly for ${s} \u2014 it asks once to trust this folder; until then the server stays off)`)}async function ye(e,t,n,o){const s={cursor:an,copilot:cn,codex:ln,gemini:dn}[e];Hs(e,await s(t,n).catch(()=>null),o)}if(process.argv[2]==="init"){const e=Date.now(),{writeFile:t,mkdir:n,readFile:o}=await import("node:fs/promises"),{resolve:s,dirname:i,relative:a}=await import("node:path"),r=process.argv.slice(3),d=w=>dt(r,w),f=tn(r,["instance-id","api-key","editor","project-dir","api-url"]);f.length>0&&(console.error(`
|
|
197
|
+
Missing value for ${f.map(w=>`--${w}`).join(", ")}. Nothing was written.
|
|
198
|
+
`),process.exit(1));let l=d("instance-id")??process.env.CACHLY_BRAIN_INSTANCE_ID,u=d("api-key")??process.env.CACHLY_JWT;const y=(d("editor")??"claude").toLowerCase(),b=s(d("project-dir")??"."),v=d("api-url");if(v&&(x=v.replace(/\/+$/,"")),!l||!u){const w=xe(),_=_e();w&&_&&(u??=w,l??=_,u===w&&l===_&&console.log("\u2713 Reusing credentials from ~/.cachly/credentials.json (saved by a prior setup)"))}if(!l||!u)try{const{existsSync:w}=await import("node:fs"),_=process.env.HOME??process.env.USERPROFILE??"",k=_?s(_,".claude","mcp.json"):"";if(k&&w(k)){const E=JSON.parse(await o(k,"utf-8")).mcpServers?.cachly?.env??{};u??=E.CACHLY_JWT,l??=E.CACHLY_BRAIN_INSTANCE_ID,u&&l&&console.log("\u2713 Reusing credentials from ~/.claude/mcp.json (saved by a prior setup)")}}catch{}(!l||!u)&&(console.error(`
|
|
199
199
|
Usage: npx @cachly-dev/mcp-server@latest init --instance-id <uuid> --api-key <cky_live_...> [--editor claude|cursor|windsurf|copilot|continue|cline|zed|codex|gemini] [--all-editors] [--project-dir /path] [--api-url https://your-self-hosted-backend]
|
|
200
200
|
`),console.error(`First time? Run the zero-config wizard (signs you in, auto-provisions): npx @cachly-dev/mcp-server@latest autopilot
|
|
201
201
|
`),console.error(`Get your credentials from: ${j("/setup-ai","init")}
|
|
202
202
|
`),process.exit(1));const m=on({instanceId:l,apiKey:u,editor:y},[...Object.keys(ce),"codex","gemini"]);if(m.length>0){console.error(`
|
|
203
|
-
Nothing was written:`);for(const
|
|
204
|
-
The server does not accept this key and instance (HTTP ${
|
|
205
|
-
`),process.exit(1))}catch{console.log("\u26A0\uFE0F Could not reach the server to check the key \u2014 writing the config anyway.")}const c=()=>{ee(u),_e()||
|
|
206
|
-
\u2705 ${I?"Updated":"Written"}: ${
|
|
207
|
-
\u2713 Already configured: ${
|
|
203
|
+
Nothing was written:`);for(const w of m)console.error(` - ${w}`);console.error(""),process.exit(1)}try{const w=await fetch(`${x}/api/v1/instances/${l}/memory`,{headers:{Authorization:`Bearer ${u}`},signal:AbortSignal.timeout(8e3)});(w.status===401||w.status===403||w.status===404)&&(console.error(`
|
|
204
|
+
The server does not accept this key and instance (HTTP ${w.status}). Nothing was written.`),console.error(`Get your credentials from: ${j("/setup-ai","init")}
|
|
205
|
+
`),process.exit(1))}catch{console.log("\u26A0\uFE0F Could not reach the server to check the key \u2014 writing the config anyway.")}const c=()=>{ee(u),_e()||ve(l,{apiKey:u})};if(y==="codex"||y==="gemini")c(),console.log(""),await ze(y,b,Z(u,l),"");else{const w=ce[y]??".mcp.json",_=s(b,w);await n(i(_),{recursive:!0});const{existsSync:k}=await import("node:fs"),I=k(_),E=I?await o(_,"utf-8").catch(()=>""):"";c();const $=await Dt(_,u,l,y,{readFile:o,existsSync:k});$!==E?(await t(_,$,"utf-8"),console.log(`
|
|
206
|
+
\u2705 ${I?"Updated":"Written"}: ${w}`)):console.log(`
|
|
207
|
+
\u2713 Already configured: ${w} (no change)`)}const p=r.includes("--all-editors"),g=await zt(b,l,void 0,p?void 0:y);for(const[w,_]of Object.entries(g))console.log(Ut(w.split(/[\\/]/).pop()??w,_));try{const w=await at(b,l),_=a(b,s(qo(b),"post-commit")).replace(/\\/g,"/");w==="written"?console.log(`\u2705 Written: ${_} (CLS hook)`):w==="upgraded"?console.log(`\u2705 Upgraded: ${_} (CLS hook \u2192 ${ct})`):w==="appended"?console.log(`\u2705 Appended: ${_} (CLS hook)`):w==="unchanged"&&console.log(`\u2713 CLS hook already current in ${_}`)}catch{}if(y==="claude")try{const w=await pt(b,l);if(w.settings==="skipped")console.log(`\u26A0\uFE0F .claude/settings.json ${w.grund??"is not valid JSON"} \u2014 left untouched, Ambient Recall hooks not wired`);else{const _=w.scripts==="written"?"\u2705 Written":w.scripts==="upgraded"?`\u2705 Upgraded (\u2192 ${mt})`:"\u2713 Unchanged";console.log(`${_}: .claude/hooks/ (Ambient Recall \u2014 session briefing, per-prompt recall, file briefing, auto-learn)`),w.settings==="written"?console.log("\u2705 Written: .claude/settings.json (Ambient Recall hooks wired)"):w.settings==="merged"?console.log("\u2705 Merged: .claude/settings.json (Ambient Recall hooks wired)"):console.log("\u2713 Ambient Recall hooks already wired in .claude/settings.json")}}catch{}(y==="cursor"||y==="copilot"||y==="codex"||y==="gemini")&&await ye(y,b,l,"");const C=((Date.now()-e)/1e3).toFixed(1);console.log(`
|
|
208
208
|
\u{1F9E0} Cachly AI Brain configured for ${y==="claude"?"Claude Code":y}! (${C}s)`),console.log(y==="codex"||y==="gemini"?` Start ${y} in this folder and trust it when asked \u2014 the \`cachly\` MCP tools will appear.`:" Restart your editor \u2014 the `cachly` MCP tools will appear."),console.log(" Re-run `init` anytime \u2014 it's idempotent (only writes what changed)."),console.log(`
|
|
209
209
|
\u{1F4DB} Add a live badge to your README:`),console.log(` npx @cachly-dev/mcp-server@latest badge
|
|
210
210
|
`),process.exit(0)}if(process.argv[2]==="status"){const e=G(),t=z();(!e||!t)&&(console.log(`
|
|
211
211
|
\u26A0\uFE0F No cachly key or Brain instance found (environment or ~/.cachly/credentials.json).`),console.log(` Run: npx @cachly-dev/mcp-server@latest autopilot
|
|
212
|
-
`),process.exit(1));try{const[n,o]=await Promise.all([fetch(`${x}/api/v1/instances/${t}/memory`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)}),fetch(`${x}/api/v1/referral/me`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)})]);if(!n.ok)throw new Error(`stats HTTP ${n.status}`);const s=await n.json(),i=o.ok?await o.json():null,a=s.lesson_count??0,r=s.total_recall_count??0,d=Math.round(s.iq_boost_pct??0),f=s.team_authors??[],l=i?.referral_count??0,u=i?.url??"",y=a===0?"Intern \u{1F331}":a<10?"Junior Dev \u{1F527}":a<30?"Mid Dev \u26A1":a<60?"Senior Dev \u{1F9E0}":a<100?"Staff Eng \u{1F680}":"Principal Eng \u{1F3C6}",b=a>0?"\x1B[32m\u25CF\x1B[0m":"\x1B[33m\u25CF\x1B[0m";if(console.log(""),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log(`\u2502 ${b} \x1B[1mBrain status\x1B[0m \xB7 instance ${t.slice(0,8)}... \u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Lessons : \x1B[33m${String(a).padEnd(8)}\x1B[0m Level : \x1B[32m${y.padEnd(18)}\x1B[0m\u2502`),console.log(`\u2502 Recalls : \x1B[36m${String(r).padEnd(8)}\x1B[0m Quality score: \x1B[32m${String(d).padEnd(3)}%\x1B[0m \u2502`),f.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524");const
|
|
212
|
+
`),process.exit(1));try{const[n,o]=await Promise.all([fetch(`${x}/api/v1/instances/${t}/memory`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)}),fetch(`${x}/api/v1/referral/me`,{headers:{Authorization:`Bearer ${e}`},signal:AbortSignal.timeout(8e3)})]);if(!n.ok)throw new Error(`stats HTTP ${n.status}`);const s=await n.json(),i=o.ok?await o.json():null,a=s.lesson_count??0,r=s.total_recall_count??0,d=Math.round(s.iq_boost_pct??0),f=s.team_authors??[],l=i?.referral_count??0,u=i?.url??"",y=a===0?"Intern \u{1F331}":a<10?"Junior Dev \u{1F527}":a<30?"Mid Dev \u26A1":a<60?"Senior Dev \u{1F9E0}":a<100?"Staff Eng \u{1F680}":"Principal Eng \u{1F3C6}",b=a>0?"\x1B[32m\u25CF\x1B[0m":"\x1B[33m\u25CF\x1B[0m";if(console.log(""),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log(`\u2502 ${b} \x1B[1mBrain status\x1B[0m \xB7 instance ${t.slice(0,8)}... \u2502`),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Lessons : \x1B[33m${String(a).padEnd(8)}\x1B[0m Level : \x1B[32m${y.padEnd(18)}\x1B[0m\u2502`),console.log(`\u2502 Recalls : \x1B[36m${String(r).padEnd(8)}\x1B[0m Quality score: \x1B[32m${String(d).padEnd(3)}%\x1B[0m \u2502`),f.length>0){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524");const v=f.slice(0,4).join(", ");console.log(`\u2502 \x1B[36m\u{1F465} Team Brain\x1B[0m \xB7 ${String(f.length).padEnd(2)} developer${f.length===1?" ":"s"} sharing lessons${" ".repeat(Math.max(0,19-v.length))} \u2502`),console.log(`\u2502 ${v.slice(0,56).padEnd(56)} \u2502`)}if(u){console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524");const v=`${u.slice(0,44)}${u.length>44?"\u2026":""}`;console.log(`\u2502 \x1B[35m\u{1F517} Referral link\x1B[0m \xB7 ${l>0?`\x1B[32m${l} joined\x1B[0m`:"share to invite new users"}${" ".repeat(Math.max(0,35-String(l).length))} \u2502`),console.log(`\u2502 \x1B[2m${v.padEnd(56)}\x1B[0m \u2502`)}console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log(""),a===0&&(console.log(" \x1B[33m\u{1F4A1} No lessons yet.\x1B[0m Run a session with cachly connected to start learning."),console.log(""))}catch(n){console.log(`
|
|
213
213
|
\u274C Could not fetch status: ${n.message}
|
|
214
214
|
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="health"){const{existsSync:e}=await import("node:fs"),{readFile:t}=await import("node:fs/promises"),{resolve:n}=await import("node:path"),o=process.cwd();let s=0,i=0;const a=m=>{console.log(` \u2705 ${m}`),s++},r=m=>{console.log(` \u26A0\uFE0F ${m}`)},d=m=>{console.log(` \u274C ${m}`),i++};console.log(`
|
|
215
215
|
\u{1F9E0} cachly health check
|
|
216
216
|
`),console.log("\u{1F511} Auth token");const f=G();if(!f)d("No cachly key found (environment or ~/.cachly/credentials.json) \u2014 run: npx @cachly-dev/mcp-server@latest autopilot");else if(f.startsWith("cky_"))a("Long-lived API key set (cky_\u2026) \u2014 no client-side expiry");else try{const m=f.split(".");if(m.length!==3)throw new Error("not a JWT");const c=JSON.parse(Buffer.from(m[1],"base64url").toString("utf-8")),p=c.exp?c.exp*1e3:null,g=p?Math.floor((p-Date.now())/6e4):null;p&&p<Date.now()?d(`JWT expired ${Math.abs(g)} minute(s) ago \u2014 get a new one: ${j("/setup-ai","health")}`):g!==null&&g<30?r(`JWT expires in ${g} minute(s) \u2014 refresh soon at ${j("/setup-ai","health")}`):a(`JWT valid${g!==null?` (expires in ${Math.floor(g/60)}h ${g%60}m)`:""}`)}catch{d("CACHLY_JWT format invalid (expected a cky_ API key or a 3-part JWT)")}console.log(`
|
|
217
217
|
\u{1F310} Brain API`);const l=process.env.CACHLY_API_URL??"https://api.cachly.dev";try{const m=await fetch(`${l}/health`,{signal:AbortSignal.timeout(5e3)});if(m.ok){const c=await m.json();a(`${l} reachable (status: ${c.status??"ok"})`)}else m.status===401||m.status===403?a(`${l} reachable (auth required \u2014 expected)`):d(`${l}/health returned HTTP ${m.status}`)}catch(m){d(`${l} unreachable \u2014 ${m.message}`)}console.log(`
|
|
218
218
|
\u{1F9E0} Brain instance`);const u=z();if(!u)r("No Brain instance found (environment or ~/.cachly/credentials.json) \u2014 will auto-resolve on first tool call");else if(f)try{const m=await fetch(`${l}/api/v1/instances/${u}`,{headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},signal:AbortSignal.timeout(5e3)});if(m.ok){const c=await m.json();if(c.status==="running")if(a(`Instance "${c.name}" (${u.slice(0,8)}\u2026) is running`),console.log(`
|
|
219
|
-
\u{1F50C} Redis connectivity`),c.host&&c.port)try{let p,g;try{const k=await fetch(`${l}/api/v1/instances/${u}/connection`,{headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},signal:AbortSignal.timeout(5e3)});if(k.ok){const I=await k.json();p=I.password,g=I}}catch{}const C=xt({host:c.host,port:c.port,tls_enabled:c.tls_enabled},g),
|
|
219
|
+
\u{1F50C} Redis connectivity`),c.host&&c.port)try{let p,g;try{const k=await fetch(`${l}/api/v1/instances/${u}/connection`,{headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},signal:AbortSignal.timeout(5e3)});if(k.ok){const I=await k.json();p=I.password,g=I}}catch{}const C=xt({host:c.host,port:c.port,tls_enabled:c.tls_enabled},g),w=new Xe({host:C.host,port:C.port,password:p,...C.tls?{tls:C.tls}:{},lazyConnect:!0,connectTimeout:5e3,retryStrategy:()=>null});await w.connect();const _=await w.ping();w.disconnect(),_==="PONG"?a(`Redis PING \u2192 PONG (${C.host}:${C.port}, ${C.art==="klartext"?"unencrypted":"TLS"})`):r(`Redis responded but not PONG: ${_}`)}catch(p){d(`Redis unreachable \u2014 ${p.message}`)}else r("Instance has no host/port yet");else r(`Instance "${c.name}" status: ${c.status}`)}else d(`Instance ${u.slice(0,8)}\u2026 not found (HTTP ${m.status})`)}catch(m){d(`Could not check instance \u2014 ${m.message}`)}console.log(`
|
|
220
220
|
\u{1F6E0} Editor configs (project dir)`);const y=[{editor:"Claude Code",path:".mcp.json"},{editor:"Cursor",path:".cursor/mcp.json"},{editor:"Windsurf",path:".windsurf/mcp.json"},{editor:"Copilot / Cline",path:".vscode/mcp.json"},{editor:"Zed",path:".zed/settings.json"},{editor:"Continue.dev",path:".continue/config.json"},{editor:"Codex",path:".codex/config.toml"},{editor:"Gemini CLI",path:".gemini/settings.json"}];let b=0;for(const{editor:m,path:c}of y){const p=n(o,c);if(e(p))try{const g=await t(p,"utf-8");g.includes("@cachly-dev/mcp-server")||g.includes("cachly")?(a(`${m}: ${c}`),b++):r(`${m}: ${c} exists but cachly not found inside`)}catch{r(`${m}: ${c} exists but could not read`)}}b===0&&d("No editor MCP configs found in this folder \u2014 run: npx @cachly-dev/mcp-server@latest init (add --editor cursor|copilot|codex|gemini if needed)"),console.log(`
|
|
221
|
-
\u{1FA9D} Git hook (ambient learning)`);const
|
|
221
|
+
\u{1FA9D} Git hook (ambient learning)`);const v=n(o,".git","hooks","post-commit");if(!e(n(o,".git")))r("Not in a git repository \u2014 skip");else if(e(v))try{(await t(v,"utf-8")).includes("cachly")?a(".git/hooks/post-commit (cachly CLS hook present)"):r(".git/hooks/post-commit exists but cachly hook not found \u2014 run setup to add it")}catch{r(".git/hooks/post-commit exists but could not read")}else r(".git/hooks/post-commit not found \u2014 run: npx @cachly-dev/mcp-server@latest autopilot");console.log(`
|
|
222
222
|
\u{1F9EC} Embedding provider (semantic search)`);{const m=[["OPENAI_API_KEY","openai"],["GEMINI_API_KEY","gemini"],["MISTRAL_API_KEY","mistral"],["COHERE_API_KEY","cohere"],["OLLAMA_BASE_URL","ollama"]],c=(process.env.CACHLY_EMBED_PROVIDER??"").toLowerCase();if(c&&c!=="cachly"){const p=m.find(([,g])=>g===c)?.[0];p&&process.env[p]?a(`BYOK: ${c} (key present in ${p})`):r(`CACHLY_EMBED_PROVIDER=${c} but its key env var is not set \u2014 semantic search will fail`)}else{it==="ollama"?a("Local Ollama (OLLAMA_BASE_URL) \u2014 text stays on your machine"):it==="cachly"?a("Server-side embeddings (cachly, EU) \u2014 no key needed, uses your JWT"):r("No embedding provider active \u2014 sign in (CACHLY_JWT) for EU-hosted embeddings; search runs on words until then");for(const[p,g]of m)g!=="ollama"&&process.env[p]&&a(`${p} is set but not used \u2014 ${g} runs only if you name it with CACHLY_EMBED_PROVIDER=${g}`)}}console.log(`
|
|
223
223
|
${"\u2500".repeat(40)}`),i===0?console.log(`\u2705 All checks passed (${s} ok)
|
|
224
224
|
`):(console.log(`\u274C ${i} check(s) failed, ${s} passed
|
|
@@ -239,21 +239,21 @@ ${c.message}. Nothing was changed.
|
|
|
239
239
|
`)}catch(c){console.error(`
|
|
240
240
|
|
|
241
241
|
${jn(c)}
|
|
242
|
-
`),process.exit(1)}S=u.apiKey,ee(u.apiKey),
|
|
243
|
-
New key stored in ~/.cachly/credentials.json${
|
|
242
|
+
`),process.exit(1)}S=u.apiKey,ee(u.apiKey),ve(u.instanceId,{apiKey:u.apiKey}),await me(u.apiKey),await ge(u.instanceId);const y=s(),b=new Set([...Object.values(ce).map(c=>o(process.cwd(),c)),o(y,".claude.json"),o(y,".claude","mcp.json"),o(y,".cursor","mcp.json"),o(y,".codeium","windsurf","mcp_config.json")]);let v=0;for(const c of b)if(n(c))try{const p=Bn(await e(c,"utf-8"),d,u.apiKey);p.ersetzt&&(await t(c,p.text,"utf-8"),v++)}catch{}const m=await En(fetch,x,u.apiKey,u.instanceId);console.log(Rn(u,m)),console.log(`
|
|
243
|
+
New key stored in ~/.cachly/credentials.json${v?` and in ${v} editor config file(s) that held the test key`:""}.`),console.log(`Restart your editor (or reload its MCP servers) so it uses the new key.
|
|
244
244
|
`),process.exit(0)}const Ae=process.argv[2]==="autopilot";if(process.argv[2]==="autosetup"||process.argv[2]==="setup"||Ae){const{writeFile:e,mkdir:t,readFile:n}=await import("node:fs/promises"),{existsSync:o}=await import("node:fs"),{resolve:s,dirname:i}=await import("node:path"),{createInterface:a}=await import("node:readline"),r=Date.now(),d=Ae?"autopilot":"setup";Ko();const f=process.argv.indexOf("--api-url");f!==-1&&process.argv[f+1]&&(x=process.argv[f+1].replace(/\/+$/,""),console.log(`\u2139\uFE0F Using self-hosted backend: ${x}
|
|
245
245
|
`)),A("setup_started");const l=process.stdin.isTTY===!0,u=Ae||process.argv.includes("--yes")||process.argv.includes("-y")||!l;Ae?console.log(`\u{1F916} Autopilot \u2014 one-command setup (auth \u2192 instance \u2192 configs \u2192 Brain), zero prompts.
|
|
246
246
|
`):!l&&!process.argv.includes("--yes")&&!process.argv.includes("-y")&&console.log(`\u2139\uFE0F Non-interactive terminal detected \u2014 running in automatic mode (no prompts).
|
|
247
247
|
`);const y=a({input:process.stdin,output:process.stdout}),b=(h,T="")=>u?(console.log(`${h}${T}`),Promise.resolve(T)):new Promise(B=>y.question(h,U=>B(U.trim()||T)));console.log(`
|
|
248
248
|
\u{1F9E0} cachly AI Brain \u2014 Setup`),console.log(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
249
|
-
`);let
|
|
249
|
+
`);let v=process.env.CACHLY_JWT??"";if(v)console.log(`\u2713 Using token from CACHLY_JWT env var
|
|
250
250
|
`);else{console.log(`Step 1: Sign in to cachly (free, no credit card)
|
|
251
251
|
`),A("setup_auth_started");let h="",T="",B="",U=5e3,W=!1,ue="cachly";try{const q=await fetch(`${x}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({}),signal:AbortSignal.timeout(8e3)});if(q.ok){const P=await q.json();h=P.device_code,T=P.user_code;const D=P.verification_uri||j("/device",d);B=`${D}${D.includes("?")?"&":"?"}code=${encodeURIComponent(T)}`,U=(P.interval??5)*1e3,W=!!h}}catch{}if(!W)try{const P=await fetch("https://auth.cachly.dev/realms/cachly/protocol/openid-connect/auth/device",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"client_id=cachly-cli&scope=openid",signal:AbortSignal.timeout(8e3)});if(P.ok){const D=await P.json();h=D.device_code,T=D.user_code,B=D.verification_uri_complete,U=(D.interval??5)*1e3,W=!0,ue="keycloak"}}catch{}if(W&&h){console.log(` Code: \x1B[1;33m${T}\x1B[0m`),console.log(" Open this URL and confirm the code:"),console.log(`${B}
|
|
252
252
|
`),re(B,(P,D)=>{if(P){A("device_browser_opened",{stelle:"setup"});return}A("device_browser_failed",{reason:D??"unknown",stelle:"setup"}),console.log(` \u2139\uFE0F No browser could be opened here (${D??"unknown"}) \u2014 please open the URL yourself.
|
|
253
|
-
`)}),process.stdout.write(" Waiting for authorization");const q=Date.now()+600*1e3;for(;Date.now()<q;){await new Promise(P=>setTimeout(P,U)),process.stdout.write(".");try{let P=null;if(ue==="cachly")try{const D=await fetch(`${x}/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:h}),signal:AbortSignal.timeout(8e3)});D.status<500&&(P=await D.json())}catch{}else{const D="https://auth.cachly.dev/realms/cachly/protocol/openid-connect";try{P=await(await fetch(`${D}/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`client_id=cachly-cli&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=${h}`,signal:AbortSignal.timeout(8e3)})).json()}catch{}}if(P?.access_token){
|
|
253
|
+
`)}),process.stdout.write(" Waiting for authorization");const q=Date.now()+600*1e3;for(;Date.now()<q;){await new Promise(P=>setTimeout(P,U)),process.stdout.write(".");try{let P=null;if(ue==="cachly")try{const D=await fetch(`${x}/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:h}),signal:AbortSignal.timeout(8e3)});D.status<500&&(P=await D.json())}catch{}else{const D="https://auth.cachly.dev/realms/cachly/protocol/openid-connect";try{P=await(await fetch(`${D}/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`client_id=cachly-cli&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=${h}`,signal:AbortSignal.timeout(8e3)})).json()}catch{}}if(P?.access_token){v=P.access_token,console.log(` \x1B[32m\u2713 Authorized!\x1B[0m
|
|
254
254
|
`),A("setup_auth_completed"),A("device_flow_completed");break}P?.error==="slow_down"?U=Math.min(U+2e3,15e3):P?.error&&P.error!=="authorization_pending"&&(A("device_flow_failed",{reason:P.error}),console.error(`
|
|
255
255
|
Auth error: ${P.error}. Aborting.
|
|
256
|
-
`),y.close(),process.exit(1))}catch{}}
|
|
256
|
+
`),y.close(),process.exit(1))}catch{}}v||(A("device_flow_failed",{reason:"timeout"}),console.error(`
|
|
257
257
|
Timed out waiting for authorization. Aborting.
|
|
258
258
|
`),y.close(),process.exit(1)),console.log("")}else{A("device_flow_failed",{reason:"device_flow_unavailable"});const q=j("/setup-ai",d);console.log(` \u26A0\uFE0F Could not start automatic sign-in. Opening browser for web sign-in...
|
|
259
259
|
`),console.log(` URL: \x1B[36m${q}\x1B[0m`),console.log(" 1. Sign up / log in at the URL above"),console.log(" 2. Go to Settings \u2192 API Keys \u2192 Create new key"),console.log(` 3. Copy the key (starts with cky_live_...)
|
|
@@ -261,23 +261,23 @@ Timed out waiting for authorization. Aborting.
|
|
|
261
261
|
\u26A0\uFE0F This terminal is non-interactive, so the key cannot be pasted here.`),console.error(` Get your key at the URL above, then set it and re-run setup:
|
|
262
262
|
`),console.error(` \x1B[1mCACHLY_JWT=cky_live_xxx npx @cachly-dev/mcp-server@latest autopilot\x1B[0m
|
|
263
263
|
`),console.error(` Or add it to your editor's MCP config under env.CACHLY_JWT.
|
|
264
|
-
`),y.close(),process.exit(1)):(
|
|
264
|
+
`),y.close(),process.exit(1)):(v=await b(" Paste API key (cky_live_...): "),v||(console.error(`
|
|
265
265
|
API key is required. Aborting.
|
|
266
|
-
`),y.close(),process.exit(1)),A("setup_auth_completed"),console.log(""))}}if(
|
|
266
|
+
`),y.close(),process.exit(1)),A("setup_auth_completed"),console.log(""))}}if(v.startsWith("eyJ")){process.stdout.write("\u23F3 Generating your API key...");try{const h=await fetch(`${x}/api/v1/api-keys`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${v}`},body:JSON.stringify({name:"cachly-mcp-setup",scope:"read_write"})});if(!h.ok)throw new Error(`HTTP ${h.status}`);const T=await h.json();if(!T.key)throw new Error("no key in response");v=T.key,console.log(` \u2713
|
|
267
267
|
`)}catch{console.log(` (skipped)
|
|
268
|
-
`)}}process.stdout.write("\u23F3 Fetching your instances...");let m=[];try{const h=await fetch(`${x}/api/v1/instances`,{headers:{Authorization:`Bearer ${
|
|
268
|
+
`)}}process.stdout.write("\u23F3 Fetching your instances...");let m=[];try{const h=await fetch(`${x}/api/v1/instances`,{headers:{Authorization:`Bearer ${v}`}});if(!h.ok)throw new Error(`HTTP ${h.status}`);m=((await h.json()).data??[]).filter(B=>B.status==="running")}catch(h){const T=h.message;console.error(`
|
|
269
269
|
|
|
270
270
|
Failed to fetch instances: ${T}`),T.includes("401")&&(console.error(`Token rejected. Get a valid token at ${j("/setup-ai",d)}
|
|
271
271
|
`),re(j("/setup-ai",d))),y.close(),process.exit(1)}if(console.log(` found ${m.length}
|
|
272
|
-
`),m.length===0){process.stdout.write("\u23F3 Creating your free Brain instance...");try{const h=await fetch(`${x}/api/v1/instances/auto`,{method:"POST",headers:{Authorization:`Bearer ${
|
|
273
|
-
`),process.stdout.write("\u23F3 Waiting for instance to start");for(let U=0;U<45;U++){await new Promise(W=>setTimeout(W,3e3)),process.stdout.write(".");try{const W=await fetch(`${x}/api/v1/instances/${B}`,{headers:{Authorization:`Bearer ${
|
|
272
|
+
`),m.length===0){process.stdout.write("\u23F3 Creating your free Brain instance...");try{const h=await fetch(`${x}/api/v1/instances/auto`,{method:"POST",headers:{Authorization:`Bearer ${v}`,"Content-Type":"application/json"}});if(!h.ok)throw new Error(`HTTP ${h.status}`);const T=await h.json();if(T.instance)m=[T.instance];else if(T.instance_id){const B=T.instance_id;console.log(` \u2713 created (${B.slice(0,8)}\u2026)
|
|
273
|
+
`),process.stdout.write("\u23F3 Waiting for instance to start");for(let U=0;U<45;U++){await new Promise(W=>setTimeout(W,3e3)),process.stdout.write(".");try{const W=await fetch(`${x}/api/v1/instances/${B}`,{headers:{Authorization:`Bearer ${v}`}});if(W.ok){const ue=await W.json();if(ue.status==="running"){m=[ue];break}}}catch{}}console.log("")}}catch(h){console.log(` failed: ${h.message}
|
|
274
274
|
`)}m.length===0&&(console.error(`
|
|
275
275
|
Could not create an instance automatically. Opening ${j("/instances",d)} \u2026
|
|
276
276
|
`),re(j("/instances",d)),y.close(),process.exit(1))}const c=m[0];m.length>1&&(console.log(`\u2139\uFE0F Multiple instances found \u2014 using most recent: ${c.name}`),console.log(` (Run with --instance-id <id> to use a different one)
|
|
277
277
|
`)),console.log(`\u2713 Instance: ${c.name} (${c.id.slice(0,8)}\u2026)
|
|
278
|
-
`),A("setup_instance_ready",{instance_id:c.id});const p=process.cwd(),g=[],{homedir:C}=await import("node:os"),
|
|
279
|
-
`);const{existsSync:$}=await import("node:fs"),R=[];let M=0;ee(
|
|
280
|
-
`)[0].slice(0,160)})`);else{const T=h.match(/Ingested: \*\*(\d+)\*\*/);oe=T?parseInt(T[1],10):0,console.log(` \u2713 ${oe} lesson${oe===1?"":"s"} extracted from git history`);const B=Jo(h);B&&(console.log(""),console.log(rt(B)))}}catch(h){console.log(` (skipped: ${h.message.slice(0,80)})`)}}if(oe===0){process.stdout.write("\u{1F331} Seeding 16 universal engineering lessons (first recall works instantly)...");try{await J("brain_seed_starter",{instance_id:c.id}),console.log(" \u2713");try{const h=await J("smart_recall",{instance_id:c.id,query:"docker build slow"}),T=Fo(h);T&&(console.log(""),console.log(Yo(T.topic,T.what)))}catch{}}catch(h){console.log(` (skipped: ${h.message.slice(0,60)})`)}}try{const h=await fetch(`${x}/api/v1/instances/${c.id}/memory`,{headers:{Authorization:`Bearer ${
|
|
278
|
+
`),A("setup_instance_ready",{instance_id:c.id});const p=process.cwd(),g=[],{homedir:C}=await import("node:os"),w=C();g.push("claude"),o(s(p,".cursor"))&&g.push("cursor"),o(s(p,".windsurf"))&&g.push("windsurf"),o(s(p,".vscode"))&&g.push("copilot"),o(s(p,".continue"))&&g.push("continue");const _=process.platform==="darwin"?s(w,"Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev"):s(w,".vscode/extensions");(o(_)&&!g.includes("copilot")||o(_))&&g.push("cline");const k=process.platform==="darwin"?s(w,"Library/Application Support/Zed"):s(w,".config/zed");o(k)&&g.push("zed");const I=h=>({claude:"Claude Code",cursor:"Cursor",windsurf:"Windsurf",copilot:"GitHub Copilot",continue:"Continue.dev",cline:"Cline (VSCode)",zed:"Zed"})[h]??h,E=g;console.log(`\u{1F527} Configuring for: ${E.map(I).join(", ")}
|
|
279
|
+
`);const{existsSync:$}=await import("node:fs"),R=[];let M=0;ee(v),ve(c.id,{apiKey:v});for(const h of E){const T=ce[h]??".mcp.json",B=s(p,T);try{await t(i(B),{recursive:!0});const U=$(B),W=await Dt(B,v,c.id,h,{readFile:n,existsSync:$});await e(B,W,"utf-8"),console.log(`\u2705 ${U?"Updated":"Written"}: ${T}`),M++}catch(U){const W=U.message;console.log(`\u26A0\uFE0F Could not write ${T}: ${W}`),console.log(" Fix permissions or run with sudo, then re-run setup."),R.push({file:T,reason:W})}}const Te=await zt(p,c.id);for(const[h,T]of Object.entries(Te)){const{relative:B}=await import("node:path");console.log(Ut(B(p,h)||h,T))}S=v;let oe=0;if(o(s(p,".git"))){process.stdout.write("\u23F3 Bootstrapping Brain from git history (~10s)...");try{const h=await J("brain_from_git",{instance_id:c.id,repo_path:p,limit:100});if(h.startsWith("\u274C"))console.log(` (skipped: ${rt(h.replace(/^❌\s*/,"")).split(`
|
|
280
|
+
`)[0].slice(0,160)})`);else{const T=h.match(/Ingested: \*\*(\d+)\*\*/);oe=T?parseInt(T[1],10):0,console.log(` \u2713 ${oe} lesson${oe===1?"":"s"} extracted from git history`);const B=Jo(h);B&&(console.log(""),console.log(rt(B)))}}catch(h){console.log(` (skipped: ${h.message.slice(0,80)})`)}}if(oe===0){process.stdout.write("\u{1F331} Seeding 16 universal engineering lessons (first recall works instantly)...");try{await J("brain_seed_starter",{instance_id:c.id}),console.log(" \u2713");try{const h=await J("smart_recall",{instance_id:c.id,query:"docker build slow"}),T=Fo(h);T&&(console.log(""),console.log(Yo(T.topic,T.what)))}catch{}}catch(h){console.log(` (skipped: ${h.message.slice(0,60)})`)}}try{const h=await fetch(`${x}/api/v1/instances/${c.id}/memory`,{headers:{Authorization:`Bearer ${v}`},signal:AbortSignal.timeout(6e3)});if(h.ok){const B=(await h.json()).lesson_count??0;console.log(B===0?`
|
|
281
281
|
\u{1F9E0} Your Brain is empty. It learns from your fixes and commits from now on.`:`
|
|
282
282
|
\u{1F9E0} Your Brain now holds ${B} lesson${B===1?"":"s"}.`)}}catch{}if(!u)try{if(console.log(`
|
|
283
283
|
\u{1F451} Governance (optional \u2014 role model: admin \xB7 reviewer \xB7 contributor \xB7 viewer)`),console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),(await b(" Set yourself as the first admin? (y/N): ","N")).toLowerCase()==="y"){const T=await b(' Your handle (e.g. "alice"): ');T.trim()&&await J("team_assign_role",{instance_id:c.id,handle:T.trim(),role:"admin"}).catch(()=>"")&&(console.log(` \u2705 ${T.trim()} is now admin. Invite teammates:
|
|
@@ -287,10 +287,10 @@ Could not create an instance automatically. Opening ${j("/instances",d)} \u2026
|
|
|
287
287
|
`)}catch{}}try{const h=await at(process.cwd(),c.id);h==="written"?console.log(`
|
|
288
288
|
\u2705 CLS git hook installed \u2014 your brain will learn from every commit.`):h==="upgraded"?console.log(`
|
|
289
289
|
\u2705 CLS git hook upgraded to ${ct}.`):h==="appended"&&console.log(`
|
|
290
|
-
\u2705 CLS git hook appended to existing post-commit.`)}catch{}if(E.includes("claude"))try{const h=await pt(process.cwd(),c.id);if(h.settings==="skipped")console.log(`\u26A0\uFE0F .claude/settings.json ${h.grund??"is not valid JSON"} \u2014 left untouched, Ambient Recall hooks not wired`);else{const T=h.scripts==="written"?"\u2705 Written":h.scripts==="upgraded"?`\u2705 Upgraded (\u2192 ${mt})`:"\u2713 Unchanged";console.log(`${T}: .claude/hooks/ (Ambient Recall \u2014 session briefing, per-prompt recall, file briefing, auto-learn)`),h.settings==="written"?console.log("\u2705 Written: .claude/settings.json (Ambient Recall hooks wired)"):h.settings==="merged"?console.log("\u2705 Merged: .claude/settings.json (Ambient Recall hooks wired)"):console.log("\u2713 Ambient Recall hooks already wired in .claude/settings.json")}}catch{}E.includes("cursor")&&await ye("cursor",process.cwd(),c.id," "),E.includes("copilot")&&await ye("copilot",process.cwd(),c.id," "),(o(s(
|
|
290
|
+
\u2705 CLS git hook appended to existing post-commit.`)}catch{}if(E.includes("claude"))try{const h=await pt(process.cwd(),c.id);if(h.settings==="skipped")console.log(`\u26A0\uFE0F .claude/settings.json ${h.grund??"is not valid JSON"} \u2014 left untouched, Ambient Recall hooks not wired`);else{const T=h.scripts==="written"?"\u2705 Written":h.scripts==="upgraded"?`\u2705 Upgraded (\u2192 ${mt})`:"\u2713 Unchanged";console.log(`${T}: .claude/hooks/ (Ambient Recall \u2014 session briefing, per-prompt recall, file briefing, auto-learn)`),h.settings==="written"?console.log("\u2705 Written: .claude/settings.json (Ambient Recall hooks wired)"):h.settings==="merged"?console.log("\u2705 Merged: .claude/settings.json (Ambient Recall hooks wired)"):console.log("\u2713 Ambient Recall hooks already wired in .claude/settings.json")}}catch{}E.includes("cursor")&&await ye("cursor",process.cwd(),c.id," "),E.includes("copilot")&&await ye("copilot",process.cwd(),c.id," "),(o(s(w,".codex"))||o(s(p,".codex")))&&(await ye("codex",process.cwd(),c.id," "),await ze("codex",process.cwd(),Z("",c.id)," ")),(o(s(w,".gemini"))||o(s(p,".gemini")))&&(await ye("gemini",process.cwd(),c.id," "),await ze("gemini",process.cwd(),Z("",c.id)," ")),S=v;const Ue=Math.round((Date.now()-r)/1e3);if(R.length>0&&A("setup_config_write_failed",{instance_id:c.id,failed:R.length,succeeded:M}),A("setup_completed",{instance_id:c.id,elapsed_s:Ue,config_failures:R.length}),R.length>0&&M===0){console.log(`
|
|
291
291
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557`),console.log("\u2551 \u26A0\uFE0F Setup incomplete \u2014 no editor config was written \u2551"),console.log("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log(`
|
|
292
292
|
Your Brain instance exists, but no editor knows about it yet.`),console.log(" Failed writes:");for(const h of R)console.log(` \u2022 ${h.file} \u2014 ${h.reason}`);console.log(`
|
|
293
|
-
Fix the permissions above and re-run, or configure manually:`),console.log(` CACHLY_JWT=${
|
|
293
|
+
Fix the permissions above and re-run, or configure manually:`),console.log(` CACHLY_JWT=${v.slice(0,12)}\u2026 CACHLY_BRAIN_INSTANCE_ID=${c.id}`),console.log(` Docs: ${j("/docs/mcp",d)}
|
|
294
294
|
`),y.close(),await new Promise(h=>setTimeout(h,300)),process.exit(1)}if(console.log(`
|
|
295
295
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557`),console.log("\u2551 \u{1F680} Brain is ready. \u2551"),console.log(`\u2551 \u23F1\uFE0F Setup completed in ${(Ue+"s").padEnd(5)} \u2014 restart your editor \u2551`),console.log("\u2551 and your AI arrives pre-briefed every session. \u2551"),console.log("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),R.length>0){console.log(`
|
|
296
296
|
\u26A0\uFE0F Some editor configs could not be written (others succeeded):`);for(const h of R)console.log(` \u2022 ${h.file} \u2014 ${h.reason}`);console.log(" Fix the permissions above and re-run setup to configure them too.")}console.log(`
|
|
@@ -314,11 +314,11 @@ Could not create an instance automatically. Opening ${j("/instances",d)} \u2026
|
|
|
314
314
|
\u2705 Brain learned from your commits.
|
|
315
315
|
`),await new Promise(r=>setTimeout(r,300))}catch(a){console.error(`
|
|
316
316
|
\u274C learn-git failed: ${a.message}
|
|
317
|
-
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="ambient-recall"&&await gn(process.argv.slice(3),process.argv[1]),process.argv[2]==="ambient-auffrischen"&&await hn(),process.argv[2]===yn&&await fn(process.argv[3]??""),process.argv[2]==="ambient-credit"){try{const e=Math.round(Number(process.argv[3]));if(Number.isFinite(e)&&e>0){const t=Math.min(e,2e4),n=process.argv.slice(4).join(" ").slice(0,200)||void 0,o={ts:new Date().toISOString(),event:"credit",injected:0,prevented:t,note:n,instanz:z()||void 0};await
|
|
317
|
+
`),process.exit(1)}process.exit(0)}if(process.argv[2]==="ambient-recall"&&await gn(process.argv.slice(3),process.argv[1]),process.argv[2]==="ambient-auffrischen"&&await hn(),process.argv[2]===yn&&await fn(process.argv[3]??""),process.argv[2]==="ambient-credit"){try{const e=Math.round(Number(process.argv[3]));if(Number.isFinite(e)&&e>0){const t=Math.min(e,2e4),n=process.argv.slice(4).join(" ").slice(0,200)||void 0,o={ts:new Date().toISOString(),event:"credit",injected:0,prevented:t,note:n,instanz:z()||void 0};await wn(o),await xs(process.env.CACHLY_BRAIN_INSTANCE_ID??N,o),console.log(`\u2705 ambient credit recorded: ${t} tokens${n?` (${n})`:""}`)}else console.error("Usage: npx @cachly-dev/mcp-server@latest ambient-credit <tokens-saved> [note]")}catch{}process.exit(0)}if(process.argv[2]==="ambient-stats"){const e=z(),t=_n(await gt(),e||void 0),n=t.eigene,o=fs(n),s=n.slice(-5);if(console.log(`
|
|
318
318
|
\u{1F9E0} Ambient Recall \u2014 net-token ledger
|
|
319
319
|
`),console.log(` Instance: ${e?`${e.slice(0,8)}\u2026`:"(none set \u2014 showing every entry on this computer)"}`),console.log(` Turns recorded: ${n.length}`),console.log(` Injected tokens: ${o.injected}`),console.log(` Prevented tokens: ${o.prevented} (agent-reported via ambient-credit)`),console.log(` NET: ${o.net>=0?"+":""}${o.net} tokens`),s.length>0){console.log(`
|
|
320
320
|
Last entries:`);for(const i of s){const a=i.prevented>0?`+${i.prevented} prevented`:`-${i.injected} injected`;console.log(` \u2022 ${i.ts.slice(0,19)} ${i.event}: ${a}${i.note?` (${i.note})`:""}`)}}(t.ohneInstanz>0||t.andereInstanzen>0)&&(console.log(`
|
|
321
|
-
Not counted above:`),t.ohneInstanz>0&&console.log(` \u2022 ${t.ohneInstanz} older entries without an instance (before 0.10.207)`),t.andereInstanzen>0&&console.log(` \u2022 entries of ${t.andereInstanzen} other instance${t.andereInstanzen===1?"":"s"} on this computer`)),console.log(""),process.exit(0)}if(process.argv[2]==="uninstall"){const{homedir:e,tmpdir:t}=await import("node:os"),{resolve:n}=await import("node:path"),{createInterface:o}=await import("node:readline/promises"),s=process.argv.slice(3),a={projekt:n((r=>{const d=s.indexOf(`--${r}`);return d!==-1?s[d+1]:void 0})("project-dir")??"."),heim:process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??e(),tmp:t(),schluessel:G(),instanz:z(),apiUrl:x,istTty:process.stdin.isTTY===!0&&process.stdout.isTTY===!0,ausgabe:r=>console.log(r),frage:async r=>{const d=o({input:process.stdin,output:process.stdout});try{return/^(y|yes|j|ja)$/i.test((await d.question(r)).trim())}finally{d.close()}}};process.exit(await nn(s,a))}if(process.argv[2]==="doctor"){const{checkNodeVersion:e,checkCredential:t,checkApiReachable:n,checkAuthAccepted:o,checkInstance:s,checkVectorCoverage:i,inspectAmbientHooks:a,checkHooks:r,checkLedger:d,renderDoctorReport:f,doctorExitCode:l}=await import("./doctor.js"),u=[e(),t(S),await n(x),await o(x,S),s(z()||N),await i(x,S,z()||N),r(a(process.cwd())),d(await gt(),
|
|
321
|
+
Not counted above:`),t.ohneInstanz>0&&console.log(` \u2022 ${t.ohneInstanz} older entries without an instance (before 0.10.207)`),t.andereInstanzen>0&&console.log(` \u2022 entries of ${t.andereInstanzen} other instance${t.andereInstanzen===1?"":"s"} on this computer`)),console.log(""),process.exit(0)}if(process.argv[2]==="uninstall"){const{homedir:e,tmpdir:t}=await import("node:os"),{resolve:n}=await import("node:path"),{createInterface:o}=await import("node:readline/promises"),s=process.argv.slice(3),a={projekt:n((r=>{const d=s.indexOf(`--${r}`);return d!==-1?s[d+1]:void 0})("project-dir")??"."),heim:process.env.HOME??process.env.USERPROFILE??process.env.APPDATA??e(),tmp:t(),schluessel:G(),instanz:z(),apiUrl:x,istTty:process.stdin.isTTY===!0&&process.stdout.isTTY===!0,ausgabe:r=>console.log(r),frage:async r=>{const d=o({input:process.stdin,output:process.stdout});try{return/^(y|yes|j|ja)$/i.test((await d.question(r)).trim())}finally{d.close()}}};process.exit(await nn(s,a))}if(process.argv[2]==="doctor"){const{checkNodeVersion:e,checkCredential:t,checkApiReachable:n,checkAuthAccepted:o,checkInstance:s,checkVectorCoverage:i,inspectAmbientHooks:a,checkHooks:r,checkLedger:d,renderDoctorReport:f,doctorExitCode:l}=await import("./doctor.js"),u=[e(),t(S),await n(x),await o(x,S),s(z()||N),await i(x,S,z()||N),r(a(process.cwd())),d(await gt(),vn())];console.log(f(u)),process.exit(l(u))}if(process.argv[2]==="cls-ingest"){try{const e=process.argv[3];(!e||!S)&&process.exit(0);let t;try{t=JSON.parse(e)}catch{process.exit(0)}const n=t.instance_id??N;(!n||!t.source)&&process.exit(0),await J("cls_ingest",{instance_id:n,source:t.source,payload:t.payload??{}})}catch{}process.exit(0)}if(!S){const e=Kt();if(e)try{const t=await fetch(Gt(e),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:qt(e),signal:AbortSignal.timeout(8e3)});if(t.ok){const n=await t.json();n.access_token&&(S=n.access_token,ae(n.access_token),A("m2m_auth_completed",{grant:"client_credentials",client_id:e.clientId}),process.stderr.write(`\u{1F916} cachly: authenticated via client_credentials (M2M, headless).
|
|
322
322
|
`))}else process.stderr.write(`\u26A0\uFE0F cachly: client_credentials auth failed (${t.status}). Check CACHLY_CLIENT_ID / CACHLY_CLIENT_SECRET.
|
|
323
323
|
`),A("m2m_auth_failed",{status:t.status})}catch(t){process.stderr.write(`\u26A0\uFE0F cachly: client_credentials auth error: ${t.message}
|
|
324
324
|
`),A("m2m_auth_failed",{reason:"network"})}}const Ms=["demo","share","publish","health","autosetup","setup","autopilot","init","digest","invite","refer","badge","join","upgrade","bench","tool-specs","openapi","ambient-credit","ambient-stats","doctor","uninstall"];if(!S&&!Ms.includes(process.argv[2]??""))if(!process.argv[2]&&process.stdout.isTTY===!0&&oo){const o=`
|
|
@@ -338,7 +338,7 @@ Could not create an instance automatically. Opening ${j("/instances",d)} \u2026
|
|
|
338
338
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
339
339
|
|
|
340
340
|
`;process.stdout.write(o),process.exit(0)}else process.stderr.write(`
|
|
341
|
-
\u{1F9E0} cachly: no API key yet \u2014 the first cachly tool call
|
|
341
|
+
\u{1F9E0} cachly: no API key yet \u2014 the first cachly tool call opens the browser once to sign in (GitHub, Google or e-mail).
|
|
342
342
|
(Own account: npx @cachly-dev/mcp-server@latest autopilot)
|
|
343
343
|
|
|
344
344
|
`);else{const e=Jt(S);if(e!==null){const t=Math.floor((e-Date.now())/6e4);t<=0?process.stderr.write(`
|
package/glama.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cachly-dev/mcp-server",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.255",
|
|
4
4
|
"mcpName": "io.github.cachly-dev/mcp-server",
|
|
5
5
|
"description": "Memory for coding agents: your AI stores every fix and finds it again when the problem returns. MCP server for Claude Code, Cursor, Copilot, Windsurf, Codex and Gemini CLI, hosted in the EU.",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"url": "https://github.com/cachly-dev/cachly-mcp",
|
|
18
18
|
"source": "github"
|
|
19
19
|
},
|
|
20
|
-
"version": "0.10.
|
|
20
|
+
"version": "0.10.255",
|
|
21
21
|
"packages": [
|
|
22
22
|
{
|
|
23
23
|
"registryType": "npm",
|
|
24
24
|
"identifier": "@cachly-dev/mcp-server",
|
|
25
|
-
"version": "0.10.
|
|
25
|
+
"version": "0.10.255",
|
|
26
26
|
"runtimeHint": "npx",
|
|
27
27
|
"transport": {
|
|
28
28
|
"type": "stdio"
|